Kundennotizen auflisten und ändern
authorThomas Heck <theck@linet-services.de>
Fri, 8 Nov 2013 13:22:24 +0000 (14:22 +0100)
committerThomas Heck <theck@linet-services.de>
Fri, 8 Nov 2013 13:28:20 +0000 (14:28 +0100)
fixt #2388

SL/Controller/CustomerVendor.pm
templates/webpages/customer_vendor/tabs/vcnotes.html

index 46270bc..f2e4ff6 100644 (file)
@@ -147,6 +147,19 @@ sub _save {
       employee_id => SL::DB::Manager::Employee->current->id,
       addition => 'SAVED',
     )->save();
+
+    if ( $::form->{delete_notes} ) {
+      foreach my $note_id (@{ $::form->{delete_notes} }) {
+        my $note = SL::DB::Note->new(id => $note_id)->load();
+        if ( $note->follow_up ) {
+          if ( $note->follow_up->follow_up_link ) {
+            $note->follow_up->follow_up_link->delete(cascade => 'delete');
+          }
+          $note->follow_up->delete(cascade => 'delete');
+        }
+        $note->delete(cascade => 'delete');
+      }
+    }
   }) || die($db->error);
 
 }
@@ -622,17 +635,8 @@ sub _instantiate_args {
 
   if ( $::form->{note}->{id} ) {
     $self->{note} = SL::DB::Note->new(id => $::form->{note}->{id})->load();
-
-    $self->{note_followup_link} = SL::DB::Manager::FollowUpLink->get_all(
-      query => [
-        'follow_up.note_id' => $self->{note}->id,
-        trans_id => $self->{cv}->id,
-        trans_type => ($self->is_vendor() ? 'vendor' : 'customer'),
-      ],
-      with_objects => ['follow_up'],
-    )->[0];
-
-    $self->{note_followup} = $self->{note_followup_link}->follow_up;
+    $self->{note_followup} = $self->{note}->follow_up;
+    $self->{note_followup_link} = $self->{note_followup}->follow_up_link;
   } else {
     $self->{note} = SL::DB::Note->new();
     $self->{note_followup} = SL::DB::FollowUp->new();
@@ -687,17 +691,8 @@ sub _load_customer_vendor {
 
   if ( $::form->{note_id} ) {
     $self->{note} = SL::DB::Note->new(id => $::form->{note_id})->load();
-
-    $self->{note_followup_link} = SL::DB::Manager::FollowUpLink->get_all(
-      query => [
-        'follow_up.note_id' => $self->{note}->id,
-        trans_id => $self->{cv}->id,
-        trans_type => ($self->is_vendor() ? 'vendor' : 'customer'),
-      ],
-      with_objects => ['follow_up'],
-    )->[0];
-
-    $self->{note_followup} = $self->{note_followup_link}->follow_up;
+    $self->{note_followup} = $self->{note}->follow_up;
+    $self->{note_followup_link} = $self->{note_followup}->follow_up_link;
   } else {
     $self->{note} = SL::DB::Note->new();
     $self->{note_followup} = SL::DB::FollowUp->new();
@@ -832,6 +827,14 @@ sub _pre_render {
   $self->{shiptos} = $self->{cv}->shipto;
   $self->{shiptos} ||= [];
 
+  $self->{notes} = SL::DB::Manager::Note->get_all(
+    query => [
+      trans_id => $self->{cv}->id,
+      trans_module => 'ct',
+    ],
+    with_objects => ['follow_up'],
+  );
+
   $self->{template_args} ||= {};
 
   $::request->{layout}->add_javascripts('autocomplete_customer.js');
index 04bf951..403b0ff 100644 (file)
@@ -3,7 +3,7 @@
 [%- USE L %]
 
 <div id="vcnotes">
-   [% IF ( NOTES && NOTES.size ) %]
+  [% IF ( SELF.notes && SELF.notes.size ) %]
      <p>
        <table>
         <tr>
         [%- FOREACH row = SELF.notes %]
           <tr class="listrow[% loop.count % 2 %]">
             <td>
-              [% L.hidden_tag('notes[+].id', row.id) %]
-              [% IF ( !NOTE_id || (NOTE_id != row.id) ) %]
-                [% L.checkbox_tag('notes[].delete', 0) %]
+              [% IF ( !SELF.note || SELF.note.id != row.id ) %]
+                [% L.checkbox_tag('delete_notes[]', value = row.id) %]
               [% END %]
             </td>
 
             <td>
-              <a href="ct.pl?action=edit&db=[% HTML.url(db) %]&id=[% HTML.url(id) %]&edit_note_id=[% HTML.url(row.id) %]">[% HTML.escape(row.subject) %]</a>
+              <a href="controller.pl?action=CustomerVendor/edit&db=[% SELF.is_vendor() ? 'vendor' : 'customer' %]&id=[% HTML.url(SELF.cv.id) %]&note_id=[% HTML.url(row.id) %]">[% HTML.escape(row.subject) %]</a>
             </td>
 
             <td>
-              [% HTML.escape(row.created_on) %]
+              [% row.itime.to_kivitendo | html %]
             </td>
 
             <td>
-              [% IF ( row.created_by_name ) %]
-                [% HTML.escape(row.created_by_name) %]
-              [% ELSE %]
-                [% HTML.escape(row.created_by_login) %]
-              [% END %]
+              [% row.employee.safe_name | html %]
             </td>
 
             <td>
-              [% HTML.escape(row.follow_up_date) %]
+              [% row.follow_up.follow_up_date.to_kivitendo | html %]
             </td>
 
             <td>
-              [% IF ( row.created_for_name ) %]
-                [% HTML.escape(row.created_for_name) %]
-              [% ELSE %]
-                [% HTML.escape(row.created_for_login) %]
-              [% END %]
+              [% row.follow_up.created_for.safe_name | html %]
             </td>
 
             <td>
-              [% IF ( row.follow_up_date ) %]
-                [% IF ( row.follow_up_done ) %]
+              [% IF ( row.follow_up.follow_up_date ) %]
+                [% IF ( row.follow_up.done ) %]
                   [% 'Yes' | $T8 %]
                 [% ELSE %]
                   [% 'No' | $T8 %]
@@ -68,8 +59,9 @@
     </p>
   [% END %]
 
+
   <div class="listtop">
-    [% IF ( NOTE_id ) %]
+    [% IF ( SELF.note.id ) %]
       [% 'Edit note' | $T8 %]
     [% ELSE %]
       [% 'Add note' | $T8 %]