From 3af5e2e0647403c1e6ee9b860d6a56d393e6e6f5 Mon Sep 17 00:00:00 2001 From: Niclas Zimmermann Date: Fri, 22 Feb 2013 13:36:05 +0100 Subject: [PATCH] chart.link in der acc_trans MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Enthält noch einige Ergänzungen zu commit d1408ca13458a782cbde2b768cdd7abdbdcb9348. Es werden jetzt auch periodisch erzeugte Rechnungen berücksichtigt und SEPA-Überweisungen funktionieren wieder. Weiterhin werden noch einige Syntax-Fehler behoben. --- SL/AP.pm | 4 ++-- SL/DB/Invoice.pm | 7 ++++++- SL/DB/MetaSetup/AccTransaction.pm | 6 ++++++ SL/GL.pm | 6 +++++- SL/SEPA.pm | 9 +++++---- 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/SL/AP.pm b/SL/AP.pm index 985505c98..54abcd17e 100644 --- a/SL/AP.pm +++ b/SL/AP.pm @@ -211,7 +211,7 @@ sub post_transaction { qq|INSERT INTO acc_trans | . 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}), @@ -225,7 +225,7 @@ sub post_transaction { qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, | . 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}), diff --git a/SL/DB/Invoice.pm b/SL/DB/Invoice.pm index dd26532e0..77d6769a8 100644 --- a/SL/DB/Invoice.pm +++ b/SL/DB/Invoice.pm @@ -170,16 +170,21 @@ sub _post_add_acctrans { my ($self, $entries) = @_; my $default_tax_id = SL::DB::Manager::Tax->find_by(taxkey => 0)->id; + my $chart_link; while (my ($chart_id, $spec) = each %{ $entries }) { $spec = { taxkey => 0, tax_id => $default_tax_id, amount => $spec } unless ref $spec; + $chart_link = SL::DB::Manager::Chart->find_by(id => $chart_id)->{'link'}; + $chart_link ||= ''; + SL::DB::AccTransaction->new(trans_id => $self->id, chart_id => $chart_id, amount => $spec->{amount}, tax_id => $spec->{tax_id}, taxkey => $spec->{taxkey}, project_id => $self->globalproject_id, - transdate => $self->transdate)->save; + transdate => $self->transdate, + chart_link => $chart_link)->save; } } diff --git a/SL/DB/MetaSetup/AccTransaction.pm b/SL/DB/MetaSetup/AccTransaction.pm index 29d5c3534..db89491cf 100644 --- a/SL/DB/MetaSetup/AccTransaction.pm +++ b/SL/DB/MetaSetup/AccTransaction.pm @@ -27,6 +27,7 @@ __PACKAGE__->meta->setup( itime => { type => 'timestamp', default => 'now()' }, mtime => { type => 'timestamp' }, tax_id => { type => 'integer', not_null => 1 }, + chart_link => { type => 'text', not_null => 1 }, ], primary_key_columns => [ 'acc_trans_id' ], @@ -41,6 +42,11 @@ __PACKAGE__->meta->setup( class => 'SL::DB::Project', key_columns => { project_id => 'id' }, }, + + tax => { + class => 'SL::DB::Tax', + key_columns => { tax_id => 'id' }, + }, ], ); diff --git a/SL/GL.pm b/SL/GL.pm index ade1948ba..fb7b534e5 100644 --- a/SL/GL.pm +++ b/SL/GL.pm @@ -171,7 +171,11 @@ sub post_transaction { qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, source, memo, project_id, taxkey, tax_id, chart_link) VALUES (?, (SELECT chart_id FROM tax WHERE id = ?), - ?, ?, ?, ?, ?, ?, ?, (SELECT link FROM chart WHERE accno = ?))|; + ?, ?, ?, ?, ?, ?, ?, (SELECT link + FROM chart + WHERE id = (SELECT chart_id + FROM tax + WHERE id = ?)))|; @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"}), conv_i($form->{"tax_id_$i"})); diff --git a/SL/SEPA.pm b/SL/SEPA.pm index ea3531291..73a333030 100644 --- a/SL/SEPA.pm +++ b/SL/SEPA.pm @@ -357,8 +357,8 @@ sub post_payment { AND ((c.link LIKE '%:${ARAP}') OR (c.link LIKE '${ARAP}:%') OR (c.link = '${ARAP}')) LIMIT 1| ], - 'add_acc_trans' => [ qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, taxkey, tax_id) - VALUES (?, ?, ?, ?, current_date, ?, '', 0, (SELECT id FROM tax WHERE taxkey=0 LIMIT 1))| ], + 'add_acc_trans' => [ qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, taxkey, tax_id , chart_link) + VALUES (?, ?, ?, ?, current_date, ?, '', 0, (SELECT id FROM tax WHERE taxkey=0 LIMIT 1), (SELECT link FROM chart WHERE id=?))| ], 'update_arap' => [ qq|UPDATE ${arap} SET paid = paid + ? @@ -397,8 +397,9 @@ sub post_payment { my ($arap_chart_id) = $handles{get_arap}->[0]->fetchrow_array(); # Record the payment in acc_trans offsetting AR/AP. - do_statement($form, @{ $handles{add_acc_trans} }, $orig_item->{"${arap}_id"}, $arap_chart_id, -1 * $mult * $orig_item->{amount}, $item->{execution_date}, ''); - do_statement($form, @{ $handles{add_acc_trans} }, $orig_item->{"${arap}_id"}, $orig_item->{chart_id}, $mult * $orig_item->{amount}, $item->{execution_date}, $orig_item->{reference}); + do_statement($form, @{ $handles{add_acc_trans} }, $orig_item->{"${arap}_id"}, $arap_chart_id, -1 * $mult * $orig_item->{amount}, $item->{execution_date}, '', $arap_chart_id); + do_statement($form, @{ $handles{add_acc_trans} }, $orig_item->{"${arap}_id"}, $orig_item->{chart_id}, $mult * $orig_item->{amount}, $item->{execution_date}, $orig_item->{reference}, + $orig_item->{chart_id}); # Update the invoice to reflect the new paid amount. do_statement($form, @{ $handles{update_arap} }, $orig_item->{amount}, $orig_item->{"${arap}_id"}); -- 2.20.1