CustomerVendor: Ă„ndern von Wiedervorlagen erlauben
authorThomas Heck <theck@linet-services.de>
Mon, 5 Aug 2013 14:09:52 +0000 (16:09 +0200)
committerThomas Heck <theck@linet-services.de>
Mon, 5 Aug 2013 14:09:52 +0000 (16:09 +0200)
SL/Controller/CustomerVendor.pm

index 767ffa5..1002a2e 100644 (file)
@@ -133,10 +133,6 @@ sub _save {
       $self->{note_followup_link}->save();
 
       SL::Helper::Flash::flash_later('info', $::locale->text('Follow-Up saved.'));
-
-      $self->{note} = SL::DB::Note->new();
-      $self->{note_followup} = SL::DB::FollowUp->new();
-      $self->{note_followup_link} = SL::DB::FollowUpLink->new();
     }
 
     $self->{shipto}->trans_id($self->{cv}->id);
@@ -174,6 +170,10 @@ sub action_save {
     push(@redirect_params, shipto_id => $self->{shipto}->shipto_id);
   }
 
+  if ( $self->{note}->id ) {
+    push(@redirect_params, note_id => $self->{note}->id);
+  }
+
   $self->redirect_to(@redirect_params);
 }
 
@@ -622,22 +622,33 @@ 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;
   } else {
     $self->{note} = SL::DB::Note->new();
+    $self->{note_followup} = SL::DB::FollowUp->new();
+    $self->{note_followup_link} = SL::DB::FollowUpLink->new();
   }
+
   $self->{note}->assign_attributes(%{$::form->{note}});
   $self->{note}->created_by($curr_employee->id);
   $self->{note}->trans_module('ct');
 
-  $self->{note_followup} = SL::DB::FollowUp->new();
   $self->{note_followup}->assign_attributes(%{$::form->{note_followup}});
   $self->{note_followup}->note($self->{note});
   $self->{note_followup}->created_by($curr_employee->id);
 
-  $self->{note_followup_link} = SL::DB::FollowUpLink->new(
-    trans_type => ($self->is_vendor() ? 'vendor' : 'customer'),
-    trans_info => $self->{cv}->name
-  );
+  $self->{note_followup_link}->trans_type($self->is_vendor() ? 'vendor' : 'customer');
+  $self->{note_followup_link}->trans_info($self->{cv}->name);
 
   if ( $::form->{shipto}->{shipto_id} ) {
     $self->{shipto} = SL::DB::Shipto->new(shipto_id => $::form->{shipto}->{shipto_id})->load();
@@ -674,9 +685,24 @@ sub _load_customer_vendor {
     $self->{cv} = SL::DB::Customer->new(id => $::form->{id})->load();
   }
 
-  $self->{note} = SL::DB::Note->new();
-  $self->{note_followup} = SL::DB::FollowUp->new();
-  $self->{note_followup_link} = SL::DB::FollowUpLink->new();
+  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;
+  } else {
+    $self->{note} = SL::DB::Note->new();
+    $self->{note_followup} = SL::DB::FollowUp->new();
+    $self->{note_followup_link} = SL::DB::FollowUpLink->new();
+  }
 
   if ( $::form->{shipto_id} ) {
     $self->{shipto} = SL::DB::Shipto->new(shipto_id => $::form->{shipto_id})->load();