From: Niclas Zimmermann Date: Fri, 22 Feb 2013 16:38:14 +0000 (+0100) Subject: Bugfix von chart_link und tax_id in acc_trans X-Git-Tag: release-3.1.0beta1~604^2 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=dceb9f20c37fca889bb722293833a81cb876ac17;p=kivitendo-erp.git Bugfix von chart_link und tax_id in acc_trans Es gab noch einige Bugs bei VK- und EK-Rechnungen. 1. Der Steuerschlüssel wurde nicht richtig geschrieben. 2. tax_id war noch an einigen Stellen NULL. --- diff --git a/SL/IR.pm b/SL/IR.pm index 11c69de8c..48c5134fa 100644 --- a/SL/IR.pm +++ b/SL/IR.pm @@ -269,29 +269,37 @@ sub post_invoice { # allocated >= 0 # add entry for inventory, this one is for the sold item - $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, tax_id) VALUES (?, ?, ?, ?, (SELECT taxkey_id FROM chart WHERE id = ?), + $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, tax_id) VALUES (?, ?, ?, ?, + (SELECT taxkey_id + FROM taxkeys + WHERE chart_id= ? + AND startdate <= ? + ORDER BY startdate DESC LIMIT 1), (SELECT tax_id FROM taxkeys - WHERE chart_id= (SELECT id - FROM chart - WHERE accno = ?) + WHERE chart_id= ? AND startdate <= ? ORDER BY startdate DESC LIMIT 1), (SELECT chart_link FROM chart WHERE id = ?))|; - @values = ($ref->{trans_id}, $ref->{inventory_accno_id}, $linetotal, $ref->{transdate}, $ref->{inventory_accno_id}, $ref->{inventory_accno_id}, $ref->{transdate}, $ref->{inventory_accno_id}); + @values = ($ref->{trans_id}, $ref->{inventory_accno_id}, $linetotal, $ref->{transdate}, $ref->{inventory_accno_id}, $ref->{transdate}, $ref->{inventory_accno_id}, $ref->{transdate}, + $ref->{inventory_accno_id}); do_query($form, $dbh, $query, @values); # add expense - $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, tax_id) VALUES (?, ?, ?, ?, (SELECT taxkey from tax WHERE chart_id = ?), + $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, tax_id) VALUES (?, ?, ?, ?, + (SELECT taxkey_id + FROM taxkeys + WHERE chart_id= ? + AND startdate <= ? + ORDER BY startdate DESC LIMIT 1), (SELECT tax_id FROM taxkeys - WHERE chart_id= (SELECT id - FROM chart - WHERE accno = ?) + WHERE chart_id= ? AND startdate <= ? ORDER BY startdate DESC LIMIT 1), (SELECT chart_link FROM chart WHERE id = ?))|; - @values = ($ref->{trans_id}, $ref->{expense_accno_id}, ($linetotal * -1), $ref->{transdate}, $ref->{expense_accno_id}, $ref->{expense_accno_id}, $ref->{transdate}, $ref->{expense_accno_id}); + @values = ($ref->{trans_id}, $ref->{expense_accno_id}, ($linetotal * -1), $ref->{transdate}, $ref->{expense_accno_id}, $ref->{transdate}, $ref->{expense_accno_id}, $ref->{transdate}, + $ref->{expense_accno_id}); do_query($form, $dbh, $query, @values); } }; @@ -496,7 +504,14 @@ sub post_invoice { $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id, tax_id, chart_link) VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, - (SELECT taxkey_id FROM chart WHERE accno = ?), ?, + (SELECT taxkey_id + FROM taxkeys + WHERE chart_id= (SELECT id + FROM chart + WHERE accno = ?) + AND startdate <= ? + ORDER BY startdate DESC LIMIT 1), + ?, (SELECT tax_id FROM taxkeys WHERE chart_id= (SELECT id @@ -506,7 +521,7 @@ sub post_invoice { ORDER BY startdate DESC LIMIT 1), (SELECT link FROM chart WHERE accno = ?))|; @values = ($trans_id, $accno, $form->{amount}{$trans_id}{$accno}, - conv_date($form->{invdate}), $accno, $project_id, $accno, conv_date($form->{invdate}), $accno); + conv_date($form->{invdate}), $accno, conv_date($form->{invdate}), $project_id, $accno, conv_date($form->{invdate}), $accno); do_query($form, $dbh, $query, @values); } } @@ -543,7 +558,14 @@ sub post_invoice { if ($form->{amount}{ $form->{id} }{ $form->{AP} } != 0) { $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id, tax_id, chart_link) VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, - (SELECT taxkey_id FROM chart WHERE accno = ?), ?, + (SELECT taxkey_id + FROM taxkeys + WHERE chart_id= (SELECT id + FROM chart + WHERE accno = ?) + AND startdate <= ? + ORDER BY startdate DESC LIMIT 1), + ?, (SELECT tax_id FROM taxkeys WHERE chart_id= (SELECT id @@ -553,7 +575,7 @@ sub post_invoice { ORDER BY startdate DESC LIMIT 1), (SELECT link FROM chart WHERE accno = ?))|; @values = (conv_i($form->{id}), $form->{AP}, $amount, - $form->{"datepaid_$i"}, $form->{AP}, $project_id, $form->{AP}, conv_date($form->{"datepaid_$i"}), $form->{AP}); + $form->{"datepaid_$i"}, $form->{AP}, conv_date($form->{"datepaid_$i"}), $project_id, $form->{AP}, conv_date($form->{"datepaid_$i"}), $form->{AP}); do_query($form, $dbh, $query, @values); } @@ -563,7 +585,13 @@ sub post_invoice { $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, taxkey, project_id, tax_id, chart_link) VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?, - (SELECT taxkey_id FROM chart WHERE accno = ?), ?, + (SELECT taxkey_id + FROM taxkeys + WHERE chart_id= (SELECT id + FROM chart WHERE accno = ?) + AND startdate <= ? + ORDER BY startdate DESC LIMIT 1), + ?, (SELECT tax_id FROM taxkeys WHERE chart_id= (SELECT id @@ -572,7 +600,7 @@ sub post_invoice { ORDER BY startdate DESC LIMIT 1), (SELECT link FROM chart WHERE accno = ?))|; @values = (conv_i($form->{id}), $accno, $form->{"paid_$i"}, $form->{"datepaid_$i"}, - $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $accno, $project_id, $accno, conv_date($form->{"datepaid_$i"}), $accno); + $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $accno, conv_date($form->{"datepaid_$i"}), $project_id, $accno, conv_date($form->{"datepaid_$i"}), $accno); do_query($form, $dbh, $query, @values); $exchangerate = 0; @@ -612,15 +640,9 @@ sub post_invoice { $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, cleared, fx_transaction, taxkey, project_id, tax_id, chart_link) VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, '0', '1', 0, ?, - (SELECT tax_id - FROM taxkeys - WHERE chart_id= (SELECT id - FROM chart - WHERE accno = ?) - AND startdate <= ? - ORDER BY startdate DESC LIMIT 1), + (SELECT id FROM tax WHERE taxkey=0 LIMIT 1), (SELECT link FROM chart WHERE accno = ?))|; - @values = (conv_i($form->{id}), $accno, $form->{fx}{$accno}{$transdate}, conv_date($transdate), $project_id, $accno, $form->{fx}{$accno}{$transdate}, $accno); + @values = (conv_i($form->{id}), $accno, $form->{fx}{$accno}{$transdate}, conv_date($transdate), $project_id, $accno); do_query($form, $dbh, $query, @values); } } diff --git a/SL/IS.pm b/SL/IS.pm index 45accda4b..052dcfd3f 100644 --- a/SL/IS.pm +++ b/SL/IS.pm @@ -870,9 +870,16 @@ sub post_invoice { WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1), - (SELECT taxkey_id FROM chart WHERE accno = ?), ?, + (SELECT taxkey_id + FROM taxkeys + WHERE chart_id= (SELECT id + FROM chart + WHERE accno = ?) + AND startdate <= ? + ORDER BY startdate DESC LIMIT 1), + ?, (SELECT link FROM chart WHERE accno = ?))|; - @values = (conv_i($trans_id), $accno, $form->{amount}{$trans_id}{$accno}, conv_date($form->{invdate}), $accno, conv_date($taxdate), $accno, conv_i($project_id), $accno); + @values = (conv_i($trans_id), $accno, $form->{amount}{$trans_id}{$accno}, conv_date($form->{invdate}), $accno, conv_date($taxdate), $accno, conv_date($taxdate), conv_i($project_id), $accno); do_query($form, $dbh, $query, @values); $form->{amount}{$trans_id}{$accno} = 0; } @@ -892,9 +899,16 @@ sub post_invoice { WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1), - (SELECT taxkey_id FROM chart WHERE accno = ?), ?, + (SELECT taxkey_id + FROM taxkeys + WHERE chart_id= (SELECT id + FROM chart + WHERE accno = ?) + AND startdate <= ? + ORDER BY startdate DESC LIMIT 1), + ?, (SELECT link FROM chart WHERE accno = ?))|; - @values = (conv_i($trans_id), $accno, $form->{amount}{$trans_id}{$accno}, conv_date($form->{invdate}), $accno, conv_date($taxdate), $accno, conv_i($project_id), $accno); + @values = (conv_i($trans_id), $accno, $form->{amount}{$trans_id}{$accno}, conv_date($form->{invdate}), $accno, conv_date($taxdate), $accno, conv_date($taxdate), conv_i($project_id), $accno); do_query($form, $dbh, $query, @values); } } @@ -949,9 +963,16 @@ sub post_invoice { WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1), - (SELECT taxkey_id FROM chart WHERE accno = ?), ?, + (SELECT taxkey_id + FROM taxkeys + WHERE chart_id= (SELECT id + FROM chart + WHERE accno = ?) + AND startdate <= ? + ORDER BY startdate DESC LIMIT 1), + ?, (SELECT link FROM chart WHERE accno = ?))|; - @values = (conv_i($form->{"id"}), $form->{AR}, $amount, $form->{"datepaid_$i"}, $form->{AR}, conv_date($taxdate), $form->{AR}, $project_id, $form->{AR}); + @values = (conv_i($form->{"id"}), $form->{AR}, $amount, $form->{"datepaid_$i"}, $form->{AR}, conv_date($taxdate), $form->{AR}, conv_date($taxdate), $project_id, $form->{AR}); do_query($form, $dbh, $query, @values); } @@ -969,10 +990,17 @@ sub post_invoice { WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1), - (SELECT taxkey_id FROM chart WHERE accno = ?), ?, + (SELECT taxkey_id + FROM taxkeys + WHERE chart_id= (SELECT id + FROM chart + WHERE accno = ?) + AND startdate <= ? + ORDER BY startdate DESC LIMIT 1), + ?, (SELECT link FROM chart WHERE accno = ?))|; @values = (conv_i($form->{"id"}), $accno, $form->{"paid_$i"}, $form->{"datepaid_$i"}, - $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $accno, conv_date($taxdate), $accno, $project_id, $accno); + $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $accno, conv_date($taxdate), $accno, conv_date($taxdate), $project_id, $accno); do_query($form, $dbh, $query, @values); # exchangerate difference @@ -1021,9 +1049,16 @@ sub post_invoice { WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1), - (SELECT taxkey_id FROM chart WHERE accno = ?), ?, + (SELECT taxkey_id + FROM taxkeys + WHERE chart_id= (SELECT id + FROM chart + WHERE accno = ?) + AND startdate <= ? + ORDER BY startdate DESC LIMIT 1), + ?, (SELECT link FROM chart WHERE accno = ?))|; - @values = (conv_i($form->{"id"}), $accno, $form->{fx}{$accno}{$transdate}, conv_date($transdate), $accno, conv_date($taxdate), $accno, conv_i($project_id), $accno); + @values = (conv_i($form->{"id"}), $accno, $form->{fx}{$accno}{$transdate}, conv_date($transdate), $accno, conv_date($taxdate), $accno, conv_date($taxdate), conv_i($project_id), $accno); do_query($form, $dbh, $query, @values); } }