Beim Erneuern der Einkaufs- und Verkaufsmasken sowie direkt vor dem Speichern/Buchen...
authorMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 12 Dec 2006 11:58:18 +0000 (11:58 +0000)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 12 Dec 2006 11:58:18 +0000 (11:58 +0000)
12 files changed:
SL/IC.pm
bin/mozilla/io.pl
bin/mozilla/ir.pl
bin/mozilla/is.pl
bin/mozilla/oe.pl
locale/de/cn
locale/de/dn
locale/de/ic
locale/de/io
locale/de/ir
locale/de/is
locale/de/oe

index 7f07607..6707102 100644 (file)
--- a/SL/IC.pm
+++ b/SL/IC.pm
@@ -1733,4 +1733,110 @@ sub retrieve_languages {
 
 }
 
+sub retrieve_taxaccounts {
+  $main::lxdebug->enter_sub();
+
+  my ($self, $myconfig, $form, $parts_id, $index, $copy_accnos) = @_;
+
+  my ($query, $sth, $dbh);
+
+  return $main::lxdebug->leave_sub() if (!defined($form->{"taxzone_id"}));
+
+  $dbh = $form->dbconnect($myconfig);
+
+  my $transdate = "";
+  if ($form->{type} eq "invoice") {
+    if (($form->{vc} eq "vendor") || !$form->{deliverydate}) {
+      $transdate = $form->{invdate};
+    } else {
+      $transdate = $form->{deliverydate};
+    }
+  } else {
+    $transdate = $form->{transdate};
+  }
+
+  if ($transdate eq "") {
+    $transdate = "current_date";
+  } else {
+    $transdate = $dbh->quote($transdate);
+  }
+
+  my $inc_exp = $form->{vc} eq "customer" ? "income" : "expense";
+
+  my $accno_str = "${inc_exp}_accno_id_$form->{taxzone_id}";
+
+  $query =
+    "SELECT bg.$accno_str AS accno_id, c.accno " .
+    "FROM buchungsgruppen bg " .
+    "LEFT JOIN chart c ON bg.$accno_str = c.id " .
+    "WHERE bg.id = (SELECT p.buchungsgruppen_id FROM parts p WHERE p.id = ?)";
+  $sth = $dbh->prepare($query);
+  $sth->execute($parts_id) || $form->dberror($query . " ($parts_id)");
+  my $ref = $sth->fetchrow_hashref();
+  $sth->finish();
+
+  if (!$ref) {
+    $dbh->disconnect();
+    return $lxdebug->leave_sub();
+  }
+
+  my ($accno_id, $accno) = ($ref->{"accno_id"}, $ref->{"accno"});
+  my ($old_accno_id, $old_accno) = ($ref->{"accno_id"}, $ref->{"accno"});
+
+  my @visited_accno_ids = ($accno_id);
+
+  $query =
+    "SELECT c.new_chart_id, date($transdate) >= c.valid_from AS is_valid, " .
+    "  cnew.accno " .
+    "FROM chart c " .
+    "LEFT JOIN chart cnew ON c.new_chart_id = cnew.id " .
+    "WHERE (c.id = ?) AND NOT c.new_chart_id ISNULL AND (c.new_chart_id > 0)";
+  $sth = $dbh->prepare($query);
+
+  while (1) {
+    $sth->execute($accno_id) || $form->dberror($query . " ($accno_id)");
+    $ref = $sth->fetchrow_hashref();
+    last unless ($ref && $ref->{"is_valid"} &&
+                 !grep({ $_ == $ref->{"new_chart_id"} } @visited_accno_ids));
+    $accno_id = $ref->{"new_chart_id"};
+    $accno = $ref->{"accno"};
+    push(@visited_accno_ids, $accno_id);
+  }
+
+#   $main::lxdebug->message(0, "found final accno_id $accno_id accno $accno for old accno_id $old_accno_id accno $old_accno");
+
+  $query =
+    "SELECT c.accno, t.taxdescription AS description, t.rate, t.taxnumber " .
+    "FROM tax t " .
+    "LEFT JOIN chart c ON c.id = t.chart_id " .
+    "WHERE t.id IN " .
+    "  (SELECT tk.tax_id " .
+    "   FROM taxkeys tk " .
+    "   WHERE tk.chart_id = $accno_id AND startdate <= $transdate " .
+    "   ORDER BY startdate DESC LIMIT 1) ";
+  $sth = $dbh->prepare($query);
+  $sth->execute() || $form->dberror($query);
+  $ref = $sth->fetchrow_hashref();
+  $sth->finish();
+  $dbh->disconnect();
+
+  return $lxdebug->leave_sub() unless ($ref);
+
+  $form->{"taxaccounts_$index"} = $ref->{"accno"};
+  if ($form->{"taxaccounts"} !~ /$ref->{accno}/) {
+    $form->{"taxaccounts"} .= "$ref->{accno} ";
+  }
+  map({ $form->{"$ref->{accno}_${_}"} = $ref->{$_}; }
+      qw(rate description taxnumber));
+
+#   $main::lxdebug->message(0, "formvars: rate " . $form->{"$ref->{accno}_rate"} .
+#                           " description " . $form->{"$ref->{accno}_description"} .
+#                           " taxnumber " . $form->{"$ref->{accno}_taxnumber"} .
+#                           " || taxaccounts_$index " . $form->{"taxaccounts_$index"} .
+#                           " || taxaccounts " . $form->{"taxaccounts"});
+
+  $sth->finish();
+
+  $main::lxdebug->leave_sub();
+}
 1;
index 478932b..cdc0302 100644 (file)
@@ -33,6 +33,8 @@
 #
 #######################################################################
 
+use SL::IC;
+
 # any custom scripts for this one
 if (-f "$form->{path}/custom_io.pl") {
   eval { require "$form->{path}/custom_io.pl"; };
@@ -843,6 +845,9 @@ sub new_item {
 
 sub display_form {
   $lxdebug->enter_sub();
+
+  relink_accounts();
+
   $form->language_payment(\%myconfig);
 
   # if we have a display_form
@@ -2119,3 +2124,21 @@ sub new_license {
   $lxdebug->leave_sub();
 }
 
+sub relink_accounts {
+  $lxdebug->enter_sub();
+
+  $form->{"taxaccounts"} =~ s/\s*$//;
+  $form->{"taxaccounts"} =~ s/^\s*//;
+  foreach my $accno (split(/\s*/, $form->{"taxaccounts"})) {
+    map({ delete($form->{"${accno}_${_}"}); } qw(rate description taxnumber));
+  }
+  $form->{"taxaccounts"} = "";
+
+  for ($i = 1; $i <= $form->{"rowcount"}; $i++) {
+    if ($form->{"id_$i"}) {
+      IC->retrieve_taxaccounts(\%myconfig, $form, $form->{"id_$i"}, $i, 1);
+    }
+  }
+
+  $lxdebug->leave_sub();
+}
index 03f377d..6038276 100644 (file)
@@ -1006,6 +1006,7 @@ sub post {
     $form->{invnumber} = $form->update_defaults(\%myconfig, "invnumber");
   }
 
+  relink_accounts();
   $form->redirect(  $locale->text('Invoice')
                   . " $form->{invnumber} "
                   . $locale->text('posted!'))
index 857e604..db2d4b4 100644 (file)
@@ -1343,6 +1343,7 @@ sub post_payment {
 
   ($form->{AR})      = split /--/, $form->{AR};
   ($form->{AR_paid}) = split /--/, $form->{AR_paid};
+  relink_accounts();
   $form->redirect($locale->text(' Payment posted!'))
       if (IS->post_payment(\%myconfig, \%$form));
     $form->error($locale->text('Cannot post payment!'));
@@ -1409,6 +1410,7 @@ sub post {
       $form->{invnumber} = $form->update_defaults(\%myconfig, "invnumber");
     }
   }
+  relink_accounts();
   if ($print_post) {
     if (!(IS->post_invoice(\%myconfig, \%$form))) {
       $form->error($locale->text('Cannot post invoice!'));
index 6301e24..cfd55a4 100644 (file)
@@ -1968,6 +1968,8 @@ sub save_and_close {
     $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld);
   }
 
+  relink_accounts();
+
   $form->redirect(
             $form->{label} . " $form->{$ordnumber} " . $locale->text('saved!'))
     if (OE->save(\%myconfig, \%$form));
@@ -2040,6 +2042,7 @@ sub save {
   $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld)
     unless $form->{$ordnumber};
 
+  relink_accounts();
 
   OE->save(\%myconfig, \%$form);
   $form->{simple_save} = 1;
@@ -2165,6 +2168,7 @@ sub invoice {
   # if not it's most likely a collective order, which can't be saved back
   # so they just have to be closed
   if (($form->{ordnumber} ne '') || ($form->{quonumber} ne '')) {
+    relink_accounts();
     OE->save(\%myconfig, \%$form);
   } else {
     OE->close_orders(\%myconfig, \%$form);
@@ -2389,6 +2393,8 @@ sub create_backorder {
     } qw(sellprice discount);
   }
 
+  relink_accounts();
+
   OE->save(\%myconfig, \%$form);
 
   # rebuild rows for invoice
@@ -2430,6 +2436,7 @@ sub purchase_order {
   if (   $form->{type} eq 'sales_quotation'
       || $form->{type} eq 'request_quotation') {
     $form->{closed} = 1;
+    relink_accounts();
     OE->save(\%myconfig, \%$form);
   }
 
@@ -2450,6 +2457,7 @@ sub sales_order {
   if (   $form->{type} eq 'sales_quotation'
       || $form->{type} eq 'request_quotation') {
     $form->{closed} = 1;
+    relink_accounts();
     OE->save(\%myconfig, \%$form);
   }
 
index 9470f5b..b8d19da 100644 (file)
@@ -220,6 +220,7 @@ $self->{subs} = {
   'print_options'               => 'print_options',
   'project_selected'            => 'project_selected',
   'quotation'                   => 'quotation',
+  'relink_accounts'             => 'relink_accounts',
   'sales_invoice'               => 'sales_invoice',
   'section_menu'                => 'section_menu',
   'select_item'                 => 'select_item',
index 96738b8..61fcc3a 100644 (file)
@@ -203,6 +203,7 @@ $self->{subs} = {
   'print_options'               => 'print_options',
   'project_selected'            => 'project_selected',
   'quotation'                   => 'quotation',
+  'relink_accounts'             => 'relink_accounts',
   'sales_invoice'               => 'sales_invoice',
   'save'                        => 'save',
   'save_dunning'                => 'save_dunning',
index a5d26cd..c43f974 100644 (file)
@@ -258,6 +258,7 @@ $self->{subs} = {
   'print_form'                  => 'print_form',
   'print_options'               => 'print_options',
   'quotation'                   => 'quotation',
+  'relink_accounts'             => 'relink_accounts',
   'restock_assemblies'          => 'restock_assemblies',
   'save'                        => 'save',
   'save_as_new'                 => 'save_as_new',
index 35a95f7..95a2ee4 100644 (file)
@@ -133,6 +133,7 @@ $self->{subs} = {
   'print_form'                  => 'print_form',
   'print_options'               => 'print_options',
   'quotation'                   => 'quotation',
+  'relink_accounts'             => 'relink_accounts',
   'select_item'                 => 'select_item',
   'send_email'                  => 'send_email',
   'set_pricegroup'              => 'set_pricegroup',
index 732a948..1aa66e3 100644 (file)
@@ -210,6 +210,7 @@ $self->{subs} = {
   'print_options'               => 'print_options',
   'project_selected'            => 'project_selected',
   'quotation'                   => 'quotation',
+  'relink_accounts'             => 'relink_accounts',
   'sales_invoice'               => 'sales_invoice',
   'section_menu'                => 'section_menu',
   'select_item'                 => 'select_item',
index 9835f47..6fc005c 100644 (file)
@@ -238,6 +238,7 @@ $self->{subs} = {
   'print_options'               => 'print_options',
   'project_selected'            => 'project_selected',
   'quotation'                   => 'quotation',
+  'relink_accounts'             => 'relink_accounts',
   'sales_invoice'               => 'sales_invoice',
   'section_menu'                => 'section_menu',
   'select_item'                 => 'select_item',
index 124ad05..998940f 100644 (file)
@@ -279,6 +279,7 @@ $self->{subs} = {
   'project_selected'            => 'project_selected',
   'purchase_order'              => 'purchase_order',
   'quotation'                   => 'quotation',
+  'relink_accounts'             => 'relink_accounts',
   'sales_invoice'               => 'sales_invoice',
   'sales_order'                 => 'sales_order',
   'save'                        => 'save',