Beim Umwandeln von Angeboten/Preisanfragen in Aufträge die IDs in record_links speich...
authorMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 1 Jul 2008 12:25:50 +0000 (12:25 +0000)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 1 Jul 2008 12:25:50 +0000 (12:25 +0000)
SL/DO.pm
SL/IR.pm
SL/IS.pm
SL/OE.pm
SL/RecordLinks.pm
bin/mozilla/do.pl
bin/mozilla/ir.pl
bin/mozilla/is.pl
bin/mozilla/oe.pl
templates/webpages/oe/form_header_de.html
templates/webpages/oe/form_header_master.html

index eea2372..3f623ec 100644 (file)
--- a/SL/DO.pm
+++ b/SL/DO.pm
@@ -345,7 +345,7 @@ sub save {
 
   # Link this delivery order to the quotations it was created from.
   RecordLinks->create_links('dbh'        => $dbh,
-                            'mode'       => 'string',
+                            'mode'       => 'ids',
                             'from_table' => 'oe',
                             'from_ids'   => $form->{convert_from_oe_ids},
                             'to_table'   => 'delivery_orders',
index b8f22cd..f3c2674 100644 (file)
--- a/SL/IR.pm
+++ b/SL/IR.pm
@@ -539,10 +539,28 @@ sub post_invoice {
 
   Common::webdav_folder($form) if ($main::webdav);
 
-  my @close_do_ids = map { $_ * 1 } grep { $_ } split m/\s+/, $form->{close_do_ids};
-  if (scalar @close_do_ids) {
+  # Link this record to the records it was created from.
+  RecordLinks->create_links('dbh'        => $dbh,
+                            'mode'       => 'ids',
+                            'from_table' => 'oe',
+                            'from_ids'   => $form->{convert_from_oe_ids},
+                            'to_table'   => 'ap',
+                            'to_id'      => $form->{id},
+    );
+  delete $form->{convert_from_oe_ids};
+
+  my @convert_from_do_ids = map { $_ * 1 } grep { $_ } split m/\s+/, $form->{convert_from_do_ids};
+  if (scalar @convert_from_do_ids) {
     DO->close_orders('dbh' => $dbh,
-                     'ids' => \@close_do_ids);
+                     'ids' => \@convert_from_do_ids);
+
+    RecordLinks->create_links('dbh'        => $dbh,
+                              'mode'       => 'ids',
+                              'from_table' => 'delivery_orders',
+                              'from_ids'   => \@convert_from_do_ids,
+                              'to_table'   => 'ap',
+                              'to_id'      => $form->{id},
+      );
   }
 
   my $rc = 1;
index ca43fd8..c4e2a7f 100644 (file)
--- a/SL/IS.pm
+++ b/SL/IS.pm
@@ -970,11 +970,29 @@ sub post_invoice {
 
   Common::webdav_folder($form) if ($main::webdav);
 
-  my @close_do_ids = map { $_ * 1 } grep { $_ } split m/\s+/, $form->{close_do_ids};
-
-  if (scalar @close_do_ids) {
+  # Link this record to the records it was created from.
+  RecordLinks->create_links('dbh'        => $dbh,
+                            'mode'       => 'ids',
+                            'from_table' => 'oe',
+                            'from_ids'   => $form->{convert_from_oe_ids},
+                            'to_table'   => 'ar',
+                            'to_id'      => $form->{id},
+    );
+  delete $form->{convert_from_oe_ids};
+
+  my @convert_from_do_ids = map { $_ * 1 } grep { $_ } split m/\s+/, $form->{convert_from_do_ids};
+
+  if (scalar @convert_from_do_ids) {
     DO->close_orders('dbh' => $dbh,
-                     'ids' => \@close_do_ids);
+                     'ids' => \@convert_from_do_ids);
+
+    RecordLinks->create_links('dbh'        => $dbh,
+                              'mode'       => 'ids',
+                              'from_table' => 'delivery_orders',
+                              'from_ids'   => \@convert_from_do_ids,
+                              'to_table'   => 'ar',
+                              'to_id'      => $form->{id},
+      );
   }
 
   my $rc = 1;
index e279e4a..3dd83b7 100644 (file)
--- a/SL/OE.pm
+++ b/SL/OE.pm
@@ -465,6 +465,16 @@ sub save {
   # save printed, emailed, queued
   $form->save_status($dbh);
 
+  # Link this record to the records it was created from.
+  RecordLinks->create_links('dbh'        => $dbh,
+                            'mode'       => 'ids',
+                            'from_table' => 'oe',
+                            'from_ids'   => $form->{convert_from_oe_ids},
+                            'to_table'   => 'oe',
+                            'to_id'      => $form->{id},
+    );
+  delete $form->{convert_from_oe_ids};
+
   if (($form->{currency} ne $form->{defaultcurrency}) && !$exchangerate) {
     if ($form->{vc} eq 'customer') {
       $form->update_exchangerate($dbh, $form->{currency}, $form->{transdate}, $form->{exchangerate}, 0);
@@ -600,6 +610,10 @@ sub retrieve {
       if ($form->{"multi_id_$_"} and $form->{"trans_id_$_"})
   } (1 .. $form->{"rowcount"});
 
+  if ($form->{rowcount} && scalar @ids) {
+    $form->{convert_from_oe_ids} = join ' ', @ids;
+  }
+
   # if called in multi id mode, and still only got one id, switch back to single id
   if ($form->{"rowcount"} and $#ids == 0) {
     $form->{"id"} = $ids[0];
index fb451a8..8dfbac6 100644 (file)
@@ -9,7 +9,7 @@ sub create_links {
   my $self     = shift;
   my %params   = @_;
 
-  if ($params{mode} && ($params{mode} eq 'string')) {
+  if ($params{mode} && ($params{mode} eq 'ids')) {
     Common::check_params_x(\%params, [ qw(from_ids to_ids) ]);
 
   } else {
@@ -19,9 +19,15 @@ sub create_links {
 
   my @links;
 
-  if ($params{mode} && ($params{mode} eq 'string')) {
+  if ($params{mode} && ($params{mode} eq 'ids')) {
     my ($from_to, $to_from) = $params{from_ids} ? qw(from to) : qw(to from);
-    my %ids                 = ( $from_to => [ grep { $_ } map { $_ * 1 } split m/\s+/, $params{"${from_to}_ids"} ] );
+    my %ids;
+
+    if ('ARRAY' eq ref $params{"${from_to}_ids"}) {
+      $ids{$from_to} = $params{"${from_to}_ids"};
+    } else {
+      $ids{$from_to} = [ grep { $_ } map { $_ * 1 } split m/\s+/, $params{"${from_to}_ids"} ];
+    }
 
     if (my $num = scalar @{ $ids{$from_to} }) {
       $main::lxdebug->message(0, "3");
index 228b8e6..c88f3b0 100644 (file)
@@ -648,17 +648,15 @@ sub invoice {
   check_do_access();
   $auth->assert($form->{type} eq 'purchase_delivery_order' ? 'vendor_invoice_edit' : 'invoice_edit');
 
-  $form->{close_do_ids} = $form->{id};
+  $form->{convert_from_do_ids} = $form->{id};
+  $form->{deliverydate}        = $form->{transdate};
+  $form->{transdate}           = $form->{invdate} = $form->current_date(\%myconfig);
+  $form->{duedate}             = $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
+  $form->{defaultcurrency}     = $form->get_default_currency(\%myconfig);
 
-  $form->{deliverydate} = $form->{transdate};
-  $form->{transdate}    = $form->{invdate} = $form->current_date(\%myconfig);
-  $form->{duedate}      = $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
-
-  $form->{id}     = '';
-  $form->{closed} = 0;
   $form->{rowcount}--;
 
-  $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
+  delete @{$form}{qw(id closed delivered)};
 
   if ($form->{type} eq 'purchase_delivery_order') {
     $form->{title}  = $locale->text('Add Vendor Invoice');
@@ -742,13 +740,13 @@ sub invoice_multi {
                               'back_button' => 1);
   }
 
-  $form->{close_do_ids}    = join ' ', @do_ids;
-  $form->{deliverydate}    = $form->{transdate};
-  $form->{transdate}       = $form->current_date(\%myconfig);
-  $form->{duedate}         = $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
-  $form->{type}            = "invoice";
-  $form->{closed}          = 0;
-  $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
+  $form->{convert_from_do_ids} = join ' ', @do_ids;
+  $form->{deliverydate}        = $form->{transdate};
+  $form->{transdate}           = $form->current_date(\%myconfig);
+  $form->{duedate}             = $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
+  $form->{type}                = "invoice";
+  $form->{closed}              = 0;
+  $form->{defaultcurrency}     = $form->get_default_currency(\%myconfig);
 
   my $buysell;
   if ($form->{type} eq 'purchase_delivery_order') {
index d5a36ca..ce28fff 100644 (file)
@@ -424,7 +424,8 @@ sub form_header {
 
   $form->hide_form(qw(id title vc type level creditlimit creditremaining closedto locked shippted storno storno_id
                       max_dunning_level dunning_amount vendor_id oldvendor selectvendor taxaccounts
-                      fxgain_accno fxloss_accno taxpart taxservice cursor_fokus),
+                      fxgain_accno fxloss_accno taxpart taxservice cursor_fokus
+                      convert_from_oe_ids convert_from_do_ids),
                       map { $_.'_rate', $_.'_description' } split / /, $form->{taxaccounts} );
 
   print qq|<p>$form->{saved_message}</p>| if $form->{saved_message};
@@ -806,7 +807,7 @@ sub form_footer {
   </tr>
 </table>
 <br>
-| . $cgi->hidden('-name' => 'close_do_ids', '-default' => [$form->{close_do_ids}]);
+|;
 
   $invdate  = $form->datetonum($form->{invdate},  \%myconfig);
   $closedto = $form->datetonum($form->{closedto}, \%myconfig);
index a6cdff2..933602f 100644 (file)
@@ -614,7 +614,8 @@ sub form_header {
                       creditlimit creditremaining tradediscount business closedto locked shipped storno storno_id
                       max_dunning_level dunning_amount
                       shiptoname shiptostreet shiptozipcode shiptocity shiptocountry  shiptocontact shiptophone shiptofax 
-                      shiptoemail shiptodepartment_1 shiptodepartment_2 message email subject cc bcc taxaccounts cursor_fokus),
+                      shiptoemail shiptodepartment_1 shiptodepartment_2 message email subject cc bcc taxaccounts cursor_fokus
+                      convert_from_do_ids convert_from_oe_ids),
                       map { $_.'_rate', $_.'_description', $_.'_taxnumber' } split / /, $form->{taxaccounts} );
    
   print qq|<p>$form->{saved_message}</p>| if $form->{saved_message};
@@ -1192,7 +1193,6 @@ if ($form->{type} eq "credit_note") {
 $cgi->hidden("-name" => "callback", "-value" => $form->{callback})
 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
-. $cgi->hidden('-name' => 'close_do_ids', '-default' => [$form->{close_do_ids}])
 . qq|
 </form>
 
index a56557d..bc4cc45 100644 (file)
@@ -234,7 +234,9 @@ sub order_links {
     $form->{"select$form->{vc}"} = 1;
     $form->{$form->{vc}}         = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
   }
-  $form->{"old$form->{vc}"}    = $form->{$form->{vc}};
+
+  $form->{"old$form->{vc}"}  = $form->{$form->{vc}};
+  $form->{"old$form->{vc}"} .= qq|--$form->{"$form->{vc}_id"}| unless ($form->{"old$form->{vc}"} =~ m/--\d+$/);
 
   $lxdebug->leave_sub();
 }
@@ -1455,15 +1457,14 @@ sub invoice {
     OE->close_orders(\%myconfig, \%$form);
   }
 
-  $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
-  $form->{duedate}   = $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
+  $form->{convert_from_oe_ids} = $form->{id};
+  $form->{transdate}           = $form->{invdate} = $form->current_date(\%myconfig);
+  $form->{duedate}             = $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
+  $form->{shipto}              = 1;
+  $form->{defaultcurrency}     = $form->get_default_currency(\%myconfig);
 
-  $form->{id}     = '';
-  $form->{closed} = 0;
+  delete @{$form}{qw(id closed)};
   $form->{rowcount}--;
-  $form->{shipto} = 1;
-
-  $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
 
   if ($form->{type} =~ /_order$/) {
     $form->{exchangerate} = $exchangerate;
@@ -1814,12 +1815,11 @@ sub sales_order {
     delete($form->{ordnumber});
   }
 
-  $form->{cp_id}               *= 1;
-  $form->{convert_from_oe_ids}  = $form->{id};
+  $form->{cp_id} *= 1;
 
-  $form->{title}                = $locale->text('Add Sales Order');
-  $form->{vc}                   = "customer";
-  $form->{type}                 = "sales_order";
+  $form->{title}  = $locale->text('Add Sales Order');
+  $form->{vc}     = "customer";
+  $form->{type}   = "sales_order";
 
   &poso;
 
@@ -1835,13 +1835,14 @@ sub poso {
   $form->{transdate} = $form->current_date(\%myconfig);
   delete $form->{duedate};
 
-  $form->{closed}          = 0;
+  $form->{convert_from_oe_ids} = $form->{id};
+  $form->{closed}              = 0;
 
-  $form->{old_employee_id} = $form->{employee_id};
-  $form->{old_salesman_id} = $form->{salesman_id};
+  $form->{old_employee_id}     = $form->{employee_id};
+  $form->{old_salesman_id}     = $form->{salesman_id};
 
   # reset
-  map { delete $form->{$_} } qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal);
+  map { delete $form->{$_} } qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal delivered);
 
   for $i (1 .. $form->{rowcount}) {
     map { $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig, $form->{"${_}_${i}"}) if ($form->{"${_}_${i}"}) } qw(ship qty sellprice listprice basefactor);
index c09c8f0..064908a 100644 (file)
@@ -15,6 +15,8 @@
    <input type="hidden" name="[% HTML.escape(row.name) %]" value="[% HTML.escape(row.value) %]" >
 [%- END %]
 
+    <input type="hidden" name="convert_from_oe_ids" value="[% HTML.escape(convert_from_oe_ids) %]">
+
     <input type="hidden" name="follow_up_trans_id_1" value="[% HTML.escape(id) %]">
     <input type="hidden" name="follow_up_trans_type_1" value="[% HTML.escape(type) %]">
     <input type="hidden" name="follow_up_trans_info_1" value="[% HTML.escape(follow_up_trans_info) %]">
index 939915d..6521c6f 100644 (file)
@@ -15,6 +15,8 @@
    <input type="hidden" name="[% HTML.escape(row.name) %]" value="[% HTML.escape(row.value) %]" >
 [%- END %]
 
+    <input type="hidden" name="convert_from_oe_ids" value="[% HTML.escape(convert_from_oe_ids) %]">
+
     <input type="hidden" name="follow_up_trans_id_1" value="[% HTML.escape(id) %]">
     <input type="hidden" name="follow_up_trans_type_1" value="[% HTML.escape(type) %]">
     <input type="hidden" name="follow_up_trans_info_1" value="[% HTML.escape(follow_up_trans_info) %]">