From: Moritz Bunkus Date: Tue, 12 Dec 2006 11:58:18 +0000 (+0000) Subject: Beim Erneuern der Einkaufs- und Verkaufsmasken sowie direkt vor dem Speichern/Buchen... X-Git-Tag: release-2.4.0^2~69 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=b3501bdfd1971fd17d06e47cdf994c7545c3c13c;p=kivitendo-erp.git Beim Erneuern der Einkaufs- und Verkaufsmasken sowie direkt vor dem Speichern/Buchen werden die Steuerkonten für alle Positionen neu aus der Datenbank ausgelesen. Dadurch werden auch Änderungen des Rechnungs-/Lieferdatums berücksichtigt. Umwandlungen von einem Formular in ein anderes sind ebenfalls abgedeckt. --- diff --git a/SL/IC.pm b/SL/IC.pm index 7f076072a..670710224 100644 --- 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; diff --git a/bin/mozilla/io.pl b/bin/mozilla/io.pl index 478932b69..cdc030297 100644 --- a/bin/mozilla/io.pl +++ b/bin/mozilla/io.pl @@ -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(); +} diff --git a/bin/mozilla/ir.pl b/bin/mozilla/ir.pl index 03f377d24..6038276b6 100644 --- a/bin/mozilla/ir.pl +++ b/bin/mozilla/ir.pl @@ -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!')) diff --git a/bin/mozilla/is.pl b/bin/mozilla/is.pl index 857e60409..db2d4b43e 100644 --- a/bin/mozilla/is.pl +++ b/bin/mozilla/is.pl @@ -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!')); diff --git a/bin/mozilla/oe.pl b/bin/mozilla/oe.pl index 6301e2469..cfd55a404 100644 --- a/bin/mozilla/oe.pl +++ b/bin/mozilla/oe.pl @@ -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); } diff --git a/locale/de/cn b/locale/de/cn index 9470f5bc7..b8d19dacb 100644 --- a/locale/de/cn +++ b/locale/de/cn @@ -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', diff --git a/locale/de/dn b/locale/de/dn index 96738b8d1..61fcc3aae 100644 --- a/locale/de/dn +++ b/locale/de/dn @@ -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', diff --git a/locale/de/ic b/locale/de/ic index a5d26cd51..c43f9742e 100644 --- a/locale/de/ic +++ b/locale/de/ic @@ -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', diff --git a/locale/de/io b/locale/de/io index 35a95f784..95a2ee49d 100644 --- a/locale/de/io +++ b/locale/de/io @@ -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', diff --git a/locale/de/ir b/locale/de/ir index 732a94890..1aa66e30b 100644 --- a/locale/de/ir +++ b/locale/de/ir @@ -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', diff --git a/locale/de/is b/locale/de/is index 9835f472b..6fc005c3b 100644 --- a/locale/de/is +++ b/locale/de/is @@ -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', diff --git a/locale/de/oe b/locale/de/oe index 124ad0508..998940fcb 100644 --- a/locale/de/oe +++ b/locale/de/oe @@ -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',