Notiz nach dem Speichern nicht wieder öffnen
[kivitendo-erp.git] / SL / Controller / CustomerVendor.pm
index 6f253ad..46270bc 100644 (file)
@@ -18,6 +18,7 @@ use SL::DB::PaymentTerm;
 use SL::DB::Pricegroup;
 use SL::DB::Contact;
 use SL::DB::FollowUp;
+use SL::DB::FollowUpLink;
 use SL::DB::History;
 use SL::DB::Currency;
 
@@ -124,12 +125,14 @@ sub _save {
 
       $self->{note}->trans_id($self->{cv}->id);
       $self->{note}->save();
+
       $self->{note_followup}->save();
 
-      SL::Helper::Flash::flash_later('info', $::locale->text('Follow-Up saved.'));
+      $self->{note_followup_link}->follow_up_id($self->{note_followup}->id);
+      $self->{note_followup_link}->trans_id($self->{cv}->id);
+      $self->{note_followup_link}->save();
 
-      $self->{note} = SL::DB::Note->new();
-      $self->{note_followup} = SL::DB::FollowUp->new();
+      SL::Helper::Flash::flash_later('info', $::locale->text('Follow-Up saved.'));
     }
 
     $self->{shipto}->trans_id($self->{cv}->id);
@@ -348,13 +351,17 @@ sub action_delete_shipto {
 sub action_search {
   my ($self) = @_;
 
-  my $url = 'ct.pl?action=search&db='. ($self->is_vendor() ? 'vendor' : 'customer');
+  my @url_params = (
+    controller => 'ct.pl',
+    action => 'search',
+    db => $self->is_vendor() ? 'vendor' : 'customer',
+  );
 
   if ( $::form->{callback} ) {
-    $url .= '&callback='. $::from->escape($::form->{callback});
+    push(@url_params, callback => $::form->{callback});
   }
 
-  print $::form->redirect_header($url);
+  $self->redirect_to(@url_params);
 }
 
 
@@ -364,7 +371,7 @@ sub action_search_contact {
   my $url = 'ct.pl?action=search_contact&db=customer';
 
   if ( $::form->{callback} ) {
-    $url .= '&callback='. $::from->escape($::form->{callback});
+    $url .= '&callback='. $::form->escape($::form->{callback});
   }
 
   print $::form->redirect_header($url);
@@ -615,18 +622,34 @@ 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}->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();
   } else {
@@ -662,8 +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();
+  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();