From: Niclas Zimmermann Date: Fri, 22 Feb 2013 10:01:31 +0000 (+0100) Subject: chart_link in acc_trans X-Git-Tag: release-3.1.0beta1~604^2~2 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=d1408ca13458a782cbde2b768cdd7abdbdcb9348;p=kivitendo-erp.git chart_link in acc_trans Erstellt ein neues Pflichtfeld chart_link in der Tabelle acc_trans. Wird bisher nur beschrieben und noch an keiner Stelle ausgelesen. Conflicts: SL/AP.pm SL/AR.pm SL/IR.pm SL/IS.pm --- diff --git a/SL/AP.pm b/SL/AP.pm index 03a21e3c6..985505c98 100644 --- a/SL/AP.pm +++ b/SL/AP.pm @@ -209,24 +209,28 @@ sub post_transaction { # insert detail records in acc_trans $query = qq|INSERT INTO acc_trans | . - qq| (trans_id, chart_id, amount, transdate, project_id, taxkey, tax_id)| . + qq| (trans_id, chart_id, amount, transdate, project_id, taxkey, tax_id, chart_link)| . qq|VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), | . - qq| ?, ?, ?, ?, ?)|; + qq| ?, ?, ?, ?, ?| . + qq| (SELECT c.link FROM chart c WHERE c.accno = ?))|; @values = ($form->{id}, $form->{AP_amounts}{"amount_$i"}, $form->{"amount_$i"}, conv_date($form->{transdate}), - $project_id, $form->{"taxkey_$i"}, conv_i($form->{"tax_id_$i"})); + $project_id, $form->{"taxkey_$i"}, conv_i($form->{"tax_id_$i"}), + $form->{AP_amounts}{"amount_$i"}); do_query($form, $dbh, $query, @values); if ($form->{"tax_$i"} != 0) { # insert detail records in acc_trans $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, | . - qq| project_id, taxkey, tax_id) | . + qq| project_id, taxkey, tax_id, chart_link) | . qq|VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), | . - qq| ?, ?, ?, ?, ?)|; + qq| ?, ?, ?, ?, ?)| . + qq| (SELECT c.link FROM chart c WHERE c.accno = ?))|; @values = ($form->{id}, $form->{AP_amounts}{"tax_$i"}, $form->{"tax_$i"}, conv_date($form->{transdate}), - $project_id, $form->{"taxkey_$i"}, conv_i($form->{"tax_id_$i"})); + $project_id, $form->{"taxkey_$i"}, conv_i($form->{"tax_id_$i"}), + $form->{AP_amounts}{"tax_$i"}); do_query($form, $dbh, $query, @values); } @@ -235,7 +239,7 @@ sub post_transaction { # add payables $query = - qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, tax_id) | . + qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, tax_id, chart_link) | . qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, | . qq| (SELECT taxkey_id FROM chart WHERE accno = ?),| . qq| (SELECT tax_id| . @@ -244,9 +248,11 @@ sub post_transaction { qq| FROM chart| . qq| WHERE accno = ?)| . qq| AND startdate <= ?| . - qq| ORDER BY startdate DESC LIMIT 1))|; + qq| ORDER BY startdate DESC LIMIT 1),| . + qq| (SELECT c.link FROM chart c WHERE c.accno = ?))|; @values = ($form->{id}, $form->{AP_amounts}{payables}, $form->{payables}, - conv_date($form->{transdate}), $form->{AP_amounts}{payables}, $form->{AP_amounts}{payables}, conv_date($form->{transdate})); + conv_date($form->{transdate}), $form->{AP_amounts}{payables}, $form->{AP_amounts}{payables}, conv_date($form->{transdate}), + $form->{AP_amounts}{payables}); do_query($form, $dbh, $query, @values); } @@ -290,7 +296,7 @@ sub post_transaction { 2); if ($form->{payables}) { $query = - qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey, tax_id) | . + qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey, tax_id, chart_link) | . qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, | . qq| (SELECT taxkey_id FROM chart WHERE accno = ?),| . qq| (SELECT tax_id| . @@ -299,10 +305,12 @@ sub post_transaction { qq| FROM chart| . qq| WHERE accno = ?)| . qq| AND startdate <= ?| . - qq| ORDER BY startdate DESC LIMIT 1))|; + qq| ORDER BY startdate DESC LIMIT 1),| . + qq| (SELECT c.link FROM chart c WHERE c.accno = ?))|; @values = ($form->{id}, $form->{AP_payables}, $amount, conv_date($form->{"datepaid_$i"}), $project_id, - $form->{AP_payables}, $form->{AP_payables}, conv_date($form->{"datepaid_$i"})); + $form->{AP_payables}, $form->{AP_payables}, conv_date($form->{"datepaid_$i"}), + $form->{AP_payables}); do_query($form, $dbh, $query, @values); } $form->{payables} = $amount; @@ -310,7 +318,7 @@ sub post_transaction { # add payment my $gldate = (conv_date($form->{"gldate_$i"}))? conv_date($form->{"gldate_$i"}) : conv_date($form->current_date($myconfig)); $query = - qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, project_id, taxkey, tax_id) | . + qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, project_id, taxkey, tax_id, chart_link) | . qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?, ?, | . qq| (SELECT taxkey_id FROM chart WHERE accno = ?), | . qq| (SELECT tax_id| . @@ -319,11 +327,13 @@ sub post_transaction { qq| FROM chart| . qq| WHERE accno = ?)| . qq| AND startdate <= ?| . - qq| ORDER BY startdate DESC LIMIT 1))|; + qq| ORDER BY startdate DESC LIMIT 1),| . + qq| (SELECT c.link FROM chart c WHERE c.accno = ?))|; @values = ($form->{id}, $form->{"AP_paid_account_$i"}, $form->{"paid_$i"}, conv_date($form->{"datepaid_$i"}), $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $project_id, $form->{"AP_paid_account_$i"}, - $form->{"AP_paid_account_$i"}, conv_date($form->{"datepaid_$i"})); + $form->{"AP_paid_account_$i"}, conv_date($form->{"datepaid_$i"}), + $form->{"AP_paid_account_$i"}); do_query($form, $dbh, $query, @values); # add exchange rate difference @@ -332,7 +342,7 @@ sub post_transaction { ($form->{"exchangerate_$i"} - 1), 2); if ($amount != 0) { $query = - qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey, tax_id) | . + qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey, tax_id, chart_link) | . qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 't', 'f', ?, | . qq| (SELECT taxkey_id FROM chart WHERE accno = ?), | . qq| (SELECT tax_id| . @@ -341,11 +351,13 @@ sub post_transaction { qq| FROM chart| . qq| WHERE accno = ?)| . qq| AND startdate <= ?| . - qq| ORDER BY startdate DESC LIMIT 1))|; + qq| ORDER BY startdate DESC LIMIT 1),| . + qq| (SELECT c.link FROM chart c WHERE c.accno = ?))|; @values = ($form->{id}, $form->{"AP_paid_account_$i"}, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $form->{"AP_paid_account_$i"}, - $form->{"AP_paid_account_$i"}, conv_date($form->{"datepaid_$i"})); + $form->{"AP_paid_account_$i"}, conv_date($form->{"datepaid_$i"}), + $form->{"AP_paid_account_$i"}); do_query($form, $dbh, $query, @values); } @@ -357,7 +369,7 @@ sub post_transaction { if ($amount != 0) { $query = - qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey, tax_id) | . + qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey, tax_id, chart_link) | . qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 't', 'f', ?, | . qq| (SELECT taxkey_id FROM chart WHERE accno = ?)| . qq| (SELECT tax_id| . @@ -366,13 +378,14 @@ sub post_transaction { qq| FROM chart| . qq| WHERE accno = ?)| . qq| AND startdate <= ?| . - qq| ORDER BY startdate DESC LIMIT 1))|; - @values = ($form->{id}, ($amount > 0) ? - $form->{fxgain_accno} : $form->{fxloss_accno}, + qq| ORDER BY startdate DESC LIMIT 1),| . + qq| (SELECT c.link FROM chart c WHERE c.accno = ?))|; + @values = ($form->{id}, + ($amount > 0) ? $form->{fxgain_accno} : $form->{fxloss_accno}, $amount, conv_date($form->{"datepaid_$i"}), $project_id, - ($amount > 0) ? - $form->{fxgain_accno} : $form->{fxloss_accno}, - ($amount > 0) ? $form->{fxgain_accno} : $form->{fxloss_accno}, conv_date($form->{"datepaid_$i"})); + ($amount > 0) ? $form->{fxgain_accno} : $form->{fxloss_accno}, + ($amount > 0) ? $form->{fxgain_accno} : $form->{fxloss_accno}, conv_date($form->{"datepaid_$i"}), + ($amount > 0) ? $form->{fxgain_accno} : $form->{fxloss_accno}); do_query($form, $dbh, $query, @values); } diff --git a/SL/AR.pm b/SL/AR.pm index a953af44b..795849583 100644 --- a/SL/AR.pm +++ b/SL/AR.pm @@ -172,25 +172,25 @@ sub post_transaction { my $project_id = conv_i($form->{"project_id_$i"}); # insert detail records in acc_trans - $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey, tax_id) - VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, ?, ?, ?)|; + $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey, tax_id, chart_link) + VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, ?, ?, ?, (SELECT c.link FROM chart c WHERE c.accno = ?))|; @values = (conv_i($form->{id}), $form->{AR_amounts}{"amount_$i"}, conv_i($form->{"amount_$i"}), conv_date($form->{transdate}), $project_id, - conv_i($form->{"taxkey_$i"}), conv_i($form->{"tax_id_$i"})); + conv_i($form->{"taxkey_$i"}), conv_i($form->{"tax_id_$i"}), $form->{AR_amounts}{"amount_$i"}); do_query($form, $dbh, $query, @values); if ($form->{"tax_$i"} != 0) { # insert detail records in acc_trans - $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey, tax_id) - VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, ?, ?, ?)|; + $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey, tax_id, chart_link) + VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, ?, ?, ?, (SELECT c.link FROM chart c WHERE c.accno = ?))|; @values = (conv_i($form->{id}), $form->{AR_amounts}{"tax_$i"}, conv_i($form->{"tax_$i"}), conv_date($form->{transdate}), $project_id, - conv_i($form->{"taxkey_$i"}), conv_i($form->{"tax_id_$i"})); + conv_i($form->{"taxkey_$i"}), conv_i($form->{"tax_id_$i"}), $form->{AR_amounts}{"tax_$i"}); do_query($form, $dbh, $query, @values); } } } # add recievables - $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, tax_id) + $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, tax_id, chart_link) VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, (SELECT taxkey_id FROM chart WHERE accno = ?), (SELECT tax_id FROM taxkeys @@ -198,9 +198,10 @@ sub post_transaction { FROM chart WHERE accno = ?) AND startdate <= ? - ORDER BY startdate DESC LIMIT 1))|; + ORDER BY startdate DESC LIMIT 1), + (SELECT c.link FROM chart c WHERE c.accno = ?))|; @values = (conv_i($form->{id}), $form->{AR_amounts}{receivables}, conv_i($form->{receivables}), conv_date($form->{transdate}), - $form->{AR_amounts}{receivables}, $form->{AR_amounts}{receivables}, conv_date($form->{transdate})); + $form->{AR_amounts}{receivables}, $form->{AR_amounts}{receivables}, conv_date($form->{transdate}), $form->{AR_amounts}{receivables}); do_query($form, $dbh, $query, @values); } else { @@ -237,7 +238,7 @@ sub post_transaction { if ($amount != 0) { # add receivable - $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey, tax_id) + $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey, tax_id, chart_link) VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, (SELECT taxkey_id FROM chart WHERE accno = ?), (SELECT tax_id FROM taxkeys @@ -245,8 +246,11 @@ sub post_transaction { FROM chart WHERE accno = ?) AND startdate <= ? - ORDER BY startdate DESC LIMIT 1))|; - @values = (conv_i($form->{id}), $form->{AR}{receivables}, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $form->{AR}{receivables}, $form->{AR}{receivables}, conv_date($form->{"datepaid_$i"})); + ORDER BY startdate DESC LIMIT 1), + (SELECT c.link FROM chart c WHERE c.accno = ?))|; + @values = (conv_i($form->{id}), $form->{AR}{receivables}, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $form->{AR}{receivables}, $form->{AR}{receivables}, conv_date($form->{"datepaid_$i"}), + $form->{AR}{receivables}); + do_query($form, $dbh, $query, @values); } @@ -255,7 +259,7 @@ sub post_transaction { my $project_id = conv_i($form->{"paid_project_id_$i"}); my $gldate = (conv_date($form->{"gldate_$i"}))? conv_date($form->{"gldate_$i"}) : conv_date($form->current_date($myconfig)); $amount = $form->{"paid_$i"} * -1; - $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, project_id, taxkey, tax_id) + $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, project_id, taxkey, tax_id, chart_link) VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?, ?, (SELECT taxkey_id FROM chart WHERE accno = ?), (SELECT tax_id FROM taxkeys @@ -263,16 +267,17 @@ sub post_transaction { FROM chart WHERE accno = ?) AND startdate <= ? - ORDER BY startdate DESC LIMIT 1))|; + ORDER BY startdate DESC LIMIT 1), + (SELECT c.link FROM chart c WHERE c.accno = ?))|; @values = (conv_i($form->{id}), $form->{AR}{"paid_$i"}, $amount, conv_date($form->{"datepaid_$i"}), $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $project_id, $form->{AR}{"paid_$i"}, - $form->{AR}{"paid_$i"}, conv_date($form->{"datepaid_$i"})); + $form->{AR}{"paid_$i"}, conv_date($form->{"datepaid_$i"}), $form->{AR}{"paid_$i"}); do_query($form, $dbh, $query, @values); # exchangerate difference for payment $amount = $form->round_amount( $form->{"paid_$i"} * ($form->{"exchangerate_$i"} - 1) * -1, 2); if ($amount != 0) { - $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey, tax_id) + $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey, tax_id, chart_link) VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 't', 'f', ?, (SELECT taxkey_id FROM chart WHERE accno = ?), (SELECT tax_id FROM taxkeys @@ -280,9 +285,10 @@ sub post_transaction { FROM chart WHERE accno = ?) AND startdate <= ? - ORDER BY startdate DESC LIMIT 1))|; + ORDER BY startdate DESC LIMIT 1), + (SELECT c.link FROM chart c WHERE c.accno = ?))|; @values = (conv_i($form->{id}), $form->{AR}{"paid_$i"}, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $form->{AR}{"paid_$i"}, - $form->{AR}{"paid_$i"}, conv_date($form->{"datepaid_$i"})); + $form->{AR}{"paid_$i"}, conv_date($form->{"datepaid_$i"}), $form->{AR}{"paid_$i"}); do_query($form, $dbh, $query, @values); } @@ -291,7 +297,7 @@ sub post_transaction { if ($amount != 0) { my $accno = ($amount > 0) ? $form->{fxgain_accno} : $form->{fxloss_accno}; - $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey, tax_id) + $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey, tax_id, chart_link) VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 't', 'f', ?, (SELECT taxkey_id FROM chart WHERE accno = ?), (SELECT tax_id FROM taxkeys @@ -299,8 +305,9 @@ sub post_transaction { FROM chart WHERE accno = ?) AND startdate <= ? - ORDER BY startdate DESC LIMIT 1))|; - @values = (conv_i($form->{id}), $accno, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $accno, $accno, conv_date($form->{"datepaid_$i"})); + ORDER BY startdate DESC LIMIT 1), + (SELECT c.link FROM chart c WHERE c.accno = ?))|; + @values = (conv_i($form->{id}), $accno, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $accno, $accno, conv_date($form->{"datepaid_$i"}), $accno); do_query($form, $dbh, $query, @values); } } diff --git a/SL/GL.pm b/SL/GL.pm index 5783fbfd3..ade1948ba 100644 --- a/SL/GL.pm +++ b/SL/GL.pm @@ -157,11 +157,11 @@ sub post_transaction { if ($amount != 0) { $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, - source, memo, project_id, taxkey, ob_transaction, cb_transaction, tax_id) + source, memo, project_id, taxkey, ob_transaction, cb_transaction, tax_id, chart_link) VALUES (?, (SELECT id FROM chart WHERE accno = ?), - ?, ?, ?, ?, ?, ?, ?, ?, ?)|; + ?, ?, ?, ?, ?, ?, ?, ?, ?, (SELECT link FROM chart WHERE accno = ?))|; @values = (conv_i($form->{id}), $accno, $amount, conv_date($form->{transdate}), - $form->{"source_$i"}, $form->{"memo_$i"}, $project_id, $taxkey, $form->{ob_transaction} ? 't' : 'f', $form->{cb_transaction} ? 't' : 'f', conv_i($form->{"tax_id_$i"})); + $form->{"source_$i"}, $form->{"memo_$i"}, $project_id, $taxkey, $form->{ob_transaction} ? 't' : 'f', $form->{cb_transaction} ? 't' : 'f', conv_i($form->{"tax_id_$i"}), $accno); do_query($form, $dbh, $query, @values); } @@ -169,12 +169,12 @@ sub post_transaction { # add taxentry $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, - source, memo, project_id, taxkey, tax_id) + source, memo, project_id, taxkey, tax_id, chart_link) VALUES (?, (SELECT chart_id FROM tax WHERE id = ?), - ?, ?, ?, ?, ?, ?, ?)|; + ?, ?, ?, ?, ?, ?, ?, (SELECT link FROM chart WHERE accno = ?))|; @values = (conv_i($form->{id}), conv_i($form->{"tax_id_$i"}), $tax, conv_date($form->{transdate}), $form->{"source_$i"}, - $form->{"memo_$i"}, $project_id, $taxkey, conv_i($form->{"tax_id_$i"})); + $form->{"memo_$i"}, $project_id, $taxkey, conv_i($form->{"tax_id_$i"}), conv_i($form->{"tax_id_$i"})); do_query($form, $dbh, $query, @values); } } diff --git a/SL/IR.pm b/SL/IR.pm index bd8bd591d..11c69de8c 100644 --- a/SL/IR.pm +++ b/SL/IR.pm @@ -270,14 +270,15 @@ 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 = ?), - (SELECT tax_id + (SELECT tax_id FROM taxkeys WHERE chart_id= (SELECT id FROM chart WHERE accno = ?) AND startdate <= ? - ORDER BY startdate DESC LIMIT 1))|; - @values = ($ref->{trans_id}, $ref->{inventory_accno_id}, $linetotal, $ref->{transdate}, $ref->{inventory_accno_id}, $ref->{inventory_accno_id}, $ref->{transdate}); + 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}); do_query($form, $dbh, $query, @values); # add expense @@ -288,8 +289,9 @@ sub post_invoice { FROM chart WHERE accno = ?) AND startdate <= ? - ORDER BY startdate DESC LIMIT 1))|; - @values = ($ref->{trans_id}, $ref->{expense_accno_id}, ($linetotal * -1), $ref->{transdate}, $ref->{expense_accno_id}, $ref->{expense_accno_id}, $ref->{transdate}); + 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}); do_query($form, $dbh, $query, @values); } }; @@ -492,7 +494,7 @@ sub post_invoice { next if $payments_only || !$form->{amount}{$trans_id}{$accno}; - $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id, tax_id) + $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 tax_id @@ -501,9 +503,10 @@ sub post_invoice { FROM chart WHERE accno = ?) AND startdate <= ? - ORDER BY startdate DESC LIMIT 1))|; + 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})); + conv_date($form->{invdate}), $accno, $project_id, $accno, conv_date($form->{invdate}), $accno); do_query($form, $dbh, $query, @values); } } @@ -538,7 +541,7 @@ sub post_invoice { # record AP 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) + $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 tax_id @@ -547,9 +550,10 @@ sub post_invoice { FROM chart WHERE accno = ?) AND startdate <= ? - ORDER BY startdate DESC LIMIT 1))|; + 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->{"datepaid_$i"}, $form->{AP}, $project_id, $form->{AP}, conv_date($form->{"datepaid_$i"}), $form->{AP}); do_query($form, $dbh, $query, @values); } @@ -557,7 +561,7 @@ sub post_invoice { my $gldate = (conv_date($form->{"gldate_$i"}))? conv_date($form->{"gldate_$i"}) : conv_date($form->current_date($myconfig)); $query = - qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, taxkey, project_id, tax_id) + 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 tax_id @@ -565,9 +569,10 @@ sub post_invoice { WHERE chart_id= (SELECT id FROM chart WHERE accno = ?) AND startdate <= ? - ORDER BY startdate DESC LIMIT 1))|; + 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"})); + $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $accno, $project_id, $accno, conv_date($form->{"datepaid_$i"}), $accno); do_query($form, $dbh, $query, @values); $exchangerate = 0; @@ -605,7 +610,7 @@ sub post_invoice { $form->{fx}{$accno}{$transdate} = $form->round_amount($form->{fx}{$accno}{$transdate}, 2); next if ($form->{fx}{$accno}{$transdate} == 0); - $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, cleared, fx_transaction, taxkey, project_id, tax_id) + $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 @@ -613,8 +618,9 @@ sub post_invoice { FROM chart WHERE accno = ?) AND startdate <= ? - ORDER BY startdate DESC LIMIT 1))|; - @values = (conv_i($form->{id}), $accno, $form->{fx}{$accno}{$transdate}, conv_date($transdate), $project_id, $accno, $form->{fx}{$accno}{$transdate}); + 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), $project_id, $accno, $form->{fx}{$accno}{$transdate}, $accno); do_query($form, $dbh, $query, @values); } } diff --git a/SL/IS.pm b/SL/IS.pm index 196d6dff2..45accda4b 100644 --- a/SL/IS.pm +++ b/SL/IS.pm @@ -832,9 +832,9 @@ sub post_invoice { if (!$payments_only && ($form->{amount_cogs}{$trans_id}{$accno} != 0)) { $query = - qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, tax_id, taxkey, project_id) - VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, (SELECT id FROM tax WHERE taxkey=0), 0, ?)|; - @values = (conv_i($trans_id), $accno, $form->{amount_cogs}{$trans_id}{$accno}, conv_date($form->{invdate}), conv_i($project_id)); + qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, tax_id, taxkey, project_id, chart_link) + VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, (SELECT id FROM tax WHERE taxkey=0), 0, ?, (SELECT link FROM chart WHERE accno = ?))|; + @values = (conv_i($trans_id), $accno, $form->{amount_cogs}{$trans_id}{$accno}, conv_date($form->{invdate}), conv_i($project_id), $accno); do_query($form, $dbh, $query, @values); $form->{amount_cogs}{$trans_id}{$accno} = 0; } @@ -845,9 +845,9 @@ sub post_invoice { if (!$payments_only && ($form->{amount_cogs}{$trans_id}{$accno} != 0)) { $query = - qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, tax_id, taxkey, project_id) - VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, (SELECT id FROM tax WHERE taxkey=0), 0, ?)|; - @values = (conv_i($trans_id), $accno, $form->{amount_cogs}{$trans_id}{$accno}, conv_date($form->{invdate}), conv_i($project_id)); + qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, tax_id, taxkey, project_id, chart_link) + VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, (SELECT id FROM tax WHERE taxkey=0), 0, ?, (SELECT link FROM chart WHERE accno = ?))|; + @values = (conv_i($trans_id), $accno, $form->{amount_cogs}{$trans_id}{$accno}, conv_date($form->{invdate}), conv_i($project_id), $accno); do_query($form, $dbh, $query, @values); } } @@ -861,7 +861,7 @@ sub post_invoice { if (!$payments_only && ($form->{amount}{$trans_id}{$accno} != 0)) { $query = - qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, tax_id, taxkey, project_id) + qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, tax_id, taxkey, project_id, chart_link) VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, (SELECT tax_id FROM taxkeys @@ -870,8 +870,9 @@ sub post_invoice { WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1), - (SELECT taxkey_id 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)); + (SELECT taxkey_id FROM chart WHERE accno = ?), ?, + (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); do_query($form, $dbh, $query, @values); $form->{amount}{$trans_id}{$accno} = 0; } @@ -882,7 +883,7 @@ sub post_invoice { if (!$payments_only && ($form->{amount}{$trans_id}{$accno} != 0)) { $query = - qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, tax_id, taxkey, project_id) + qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, tax_id, taxkey, project_id, chart_link) VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, (SELECT tax_id FROM taxkeys @@ -891,8 +892,9 @@ sub post_invoice { WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1), - (SELECT taxkey_id 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)); + (SELECT taxkey_id FROM chart WHERE accno = ?), ?, + (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); do_query($form, $dbh, $query, @values); } } @@ -938,7 +940,7 @@ sub post_invoice { if ($form->{amount}{ $form->{id} }{ $form->{AR} } != 0) { $query = - qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, tax_id, taxkey, project_id) + qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, tax_id, taxkey, project_id, chart_link) VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, (SELECT tax_id FROM taxkeys @@ -947,8 +949,9 @@ sub post_invoice { WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1), - (SELECT taxkey_id FROM chart WHERE accno = ?), ?)|; - @values = (conv_i($form->{"id"}), $form->{AR}, $amount, $form->{"datepaid_$i"}, $form->{AR}, conv_date($taxdate), $form->{AR}, $project_id); + (SELECT taxkey_id FROM chart WHERE accno = ?), ?, + (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}); do_query($form, $dbh, $query, @values); } @@ -957,7 +960,7 @@ sub post_invoice { my $gldate = (conv_date($form->{"gldate_$i"}))? conv_date($form->{"gldate_$i"}) : conv_date($form->current_date($myconfig)); $query = - qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, tax_id, taxkey, project_id) + qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, tax_id, taxkey, project_id, chart_link) VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?, (SELECT tax_id FROM taxkeys @@ -966,9 +969,10 @@ sub post_invoice { WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1), - (SELECT taxkey_id FROM chart WHERE accno = ?), ?)|; + (SELECT taxkey_id FROM chart WHERE accno = ?), ?, + (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); + $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $accno, conv_date($taxdate), $accno, $project_id, $accno); do_query($form, $dbh, $query, @values); # exchangerate difference @@ -1008,7 +1012,7 @@ sub post_invoice { if ( $form->{fx}{$accno}{$transdate} != 0 ) { $query = - qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, cleared, fx_transaction, tax_id, taxkey, project_id) + qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, cleared, fx_transaction, tax_id, taxkey, project_id, chart_link) VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, '0', '1', (SELECT tax_id FROM taxkeys @@ -1017,8 +1021,9 @@ sub post_invoice { WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1), - (SELECT taxkey_id 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)); + (SELECT taxkey_id FROM chart WHERE accno = ?), ?, + (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); do_query($form, $dbh, $query, @values); } } diff --git a/sql/Pg-upgrade2/add_chart_link_to_acc_trans.sql b/sql/Pg-upgrade2/add_chart_link_to_acc_trans.sql new file mode 100644 index 000000000..4eb187ff9 --- /dev/null +++ b/sql/Pg-upgrade2/add_chart_link_to_acc_trans.sql @@ -0,0 +1,12 @@ +-- @tag: add_chart_link_to_acc_trans +-- @description: Neue Spalte chart_link in der acc_trans +-- @depends: release_3_0_0 + +--neue Spalte hinzufügen: +ALTER TABLE acc_trans ADD COLUMN chart_link text; + +--Spalte mit Werten füllen: +UPDATE acc_trans SET chart_link = (SELECT link FROM chart WHERE id=chart_id); + +--Spalte als Pflichtfeld definieren: +ALTER TABLE acc_trans ALTER chart_link SET NOT NULL;