From 00ce6f4ffb00599aad723eb2cce759be61f236b4 Mon Sep 17 00:00:00 2001 From: "G. Richardson" Date: Fri, 17 Jul 2015 11:07:59 +0200 Subject: [PATCH] Neue PaymentHelper Funktion create_bank_transaction MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Simuliert den MT940-Import und erstellt gültige Kontoauszugsimportzeilen für Rechnungen, mit denen man z.B. den "Kontoauszug verbuchen" testen kann. Ist also v.A. für Tests oder beim Entwickeln nützlich. Beispiele finden sich im POD. --- SL/DB/Helper/Payment.pm | 48 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/SL/DB/Helper/Payment.pm b/SL/DB/Helper/Payment.pm index 654eb41fa..6ab869116 100644 --- a/SL/DB/Helper/Payment.pm +++ b/SL/DB/Helper/Payment.pm @@ -4,7 +4,7 @@ use strict; use parent qw(Exporter); our @EXPORT = qw(pay_invoice); -our @EXPORT_OK = qw(skonto_date skonto_charts amount_less_skonto within_skonto_period percent_skonto reference_account reference_amount open_amount open_percent remaining_skonto_days skonto_amount check_skonto_configuration valid_skonto_amount get_payment_suggestions validate_payment_type open_sepa_transfer_amount get_payment_select_options_for_bank_transaction); +our @EXPORT_OK = qw(skonto_date skonto_charts amount_less_skonto within_skonto_period percent_skonto reference_account reference_amount open_amount open_percent remaining_skonto_days skonto_amount check_skonto_configuration valid_skonto_amount get_payment_suggestions validate_payment_type open_sepa_transfer_amount get_payment_select_options_for_bank_transaction create_bank_transaction); our %EXPORT_TAGS = ( "ALL" => [@EXPORT, @EXPORT_OK], ); @@ -624,6 +624,41 @@ sub validate_payment_type { return 1; } +sub create_bank_transaction { + my ($self, %params) = @_; + + require SL::DB::Chart; + require SL::DB::BankAccount; + + my $bank_chart; + if ( $params{chart_id} ) { + $bank_chart = SL::DB::Manager::Chart->find_by(chart_id => $params{chart_id}) or die "Can't find bank chart"; + } elsif ( $::instance_conf->get_ar_paid_accno_id ) { + $bank_chart = SL::DB::Manager::Chart->find_by(id => $::instance_conf->get_ar_paid_accno_id); + } else { + $bank_chart = SL::DB::Manager::Chart->find_by(description => 'Bank') or die "Can't find bank chart"; + }; + my $bank_account = SL::DB::Manager::BankAccount->find_by(chart_id => $bank_chart->id) or die "Can't find bank account for chart"; + + my $multiplier = $self->is_sales ? 1 : -1; + my $amount = ($params{amount} || $self->amount) * $multiplier; + + my $transdate = $params{transdate} || DateTime->today; + + my $bt = SL::DB::BankTransaction->new( + local_bank_account_id => $bank_account->id, + remote_bank_code => $self->customervendor->bank_code, + remote_account_number => $self->customervendor->account_number, + transdate => $transdate, + valutadate => $transdate, + amount => $::form->round_amount($amount, 2), + currency => $self->currency->id, + remote_name => $self->customervendor->depositor, + purpose => $self->invnumber + )->save; +}; + + sub _round { my $value = shift; my $num_dec = 2; @@ -955,6 +990,17 @@ If skonto is possible (skonto_date exists), add two possibilities: without_skonto and with_skonto_pt if payment date is within skonto_date, preselect with_skonto_pt, otherwise preselect without skonto. +=item C + +Method used for testing purposes, allows you to quickly create bank +transactions from invoices to have something to test payments against. + + my $ap = SL::DB::Manager::Invoice->find_by(id => 41); + $ap->create_bank_transaction(amount => $ap->amount/2, transdate => DateTime->today->add(days => 5)); + +Amount is always relative to the absolute amount of the invoice, use positive +values for sales and purchases. + =back =head1 TODO AND CAVEATS -- 2.20.1