Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 96308c59

Von Kivitendo Admin vor fast 8 Jahren hinzugefügt

  • ID 96308c59e72ec3f4fd911c48bcd7c137f523a706
  • Vorgänger 45981e33
  • Nachfolger c6d47254

SL::Dev::Payment eingeführt

Neue Funktionen zur Datenerstellung für Tests rund um Zahlungen.

create_bank_transaction aus Payment Helper nach SL::Dev verschoben.
neue Funktionen create_payment_terms und create_bank_account

Unterschiede anzeigen:

SL/DB/Helper/Payment.pm
4 4

  
5 5
use parent qw(Exporter);
6 6
our @EXPORT = qw(pay_invoice);
7
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 exchangerate forex);
7
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 exchangerate forex);
8 8
our %EXPORT_TAGS = (
9 9
  "ALL" => [@EXPORT, @EXPORT_OK],
10 10
);
......
723 723
  return 1;
724 724
}
725 725

  
726
sub create_bank_transaction {
727
  my ($self, %params) = @_;
728

  
729
  require SL::DB::Chart;
730
  require SL::DB::BankAccount;
731

  
732
  my $bank_chart;
733
  if ( $params{chart_id} ) {
734
    $bank_chart = SL::DB::Manager::Chart->find_by(chart_id => $params{chart_id}) or die "Can't find bank chart";
735
  } elsif ( $::instance_conf->get_ar_paid_accno_id ) {
736
    $bank_chart   = SL::DB::Manager::Chart->find_by(id => $::instance_conf->get_ar_paid_accno_id);
737
  } else {
738
    $bank_chart = SL::DB::Manager::Chart->find_by(description => 'Bank') or die "Can't find bank chart";
739
  };
740
  my $bank_account = SL::DB::Manager::BankAccount->find_by(chart_id => $bank_chart->id) or die "Can't find bank account for chart";
741

  
742
  my $multiplier = $self->is_sales ? 1 : -1;
743
  my $amount = ($params{amount} || $self->amount) * $multiplier;
744

  
745
  my $transdate = $params{transdate} || DateTime->today;
746

  
747
  my $bt = SL::DB::BankTransaction->new(
748
    local_bank_account_id => $bank_account->id,
749
    remote_bank_code      => $self->customervendor->bank_code,
750
    remote_account_number => $self->customervendor->account_number,
751
    transdate             => $transdate,
752
    valutadate            => $transdate,
753
    amount                => $::form->round_amount($amount, 2),
754
    currency              => $self->currency->id,
755
    remote_name           => $self->customervendor->depositor,
756
    purpose               => $params{purpose} || $self->invnumber
757
  )->save;
758
};
759

  
760

  
761 726
sub forex {
762 727
  my ($self) = @_;
763 728
  $self->currency_id == $::instance_conf->get_currency_id ? return 0 : return 1;
......
1110 1075
without_skonto and with_skonto_pt if payment date is within skonto_date,
1111 1076
preselect with_skonto_pt, otherwise preselect without skonto.
1112 1077

  
1113
=item C<create_bank_transaction %params>
1114

  
1115
Method used for testing purposes, allows you to quickly create bank
1116
transactions from invoices to have something to test payments against.
1117

  
1118
 my $ap = SL::DB::Manager::Invoice->find_by(id => 41);
1119
 $ap->create_bank_transaction(amount => $ap->amount/2, transdate => DateTime->today->add(days => 5));
1120

  
1121
To create a payment for 3 invoices that were all paid together, all with skonto:
1122
 my $ar1 = SL::DB::Manager::Invoice->find_by(invnumber=>'20');
1123
 my $ar2 = SL::DB::Manager::Invoice->find_by(invnumber=>'21');
1124
 my $ar3 = SL::DB::Manager::Invoice->find_by(invnumber=>'22');
1125
 $ar1->create_bank_transaction(amount  => ($ar1->amount_less_skonto + $ar2->amount_less_skonto + $ar2->amount_less_skonto),
1126
                               purpose => 'Rechnungen 20, 21, 22',
1127
                              );
1128

  
1129
Amount is always relative to the absolute amount of the invoice, use positive
1130
values for sales and purchases.
1131

  
1132
The following params can be passed to override the defaults:
1133

  
1134
=over 2
1135

  
1136
=item * amount
1137

  
1138
=item * purpose
1139

  
1140
=item * chart_id (the chart the amount is to be paid to)
1141

  
1142
=item * transdate
1143

  
1144
=back
1145

  
1146 1078
=item C<exchangerate>
1147 1079

  
1148 1080
Returns 1 immediately if the record uses the default currency.
SL/Dev/ALL.pm
6 6
use SL::Dev::CustomerVendor;
7 7
use SL::Dev::Inventory;
8 8
use SL::Dev::Record;
9
use SL::Dev::Payment;
9 10

  
10 11
1;
11 12

  
SL/Dev/Payment.pm
1
package SL::Dev::Payment;
2

  
3
use strict;
4
use base qw(Exporter);
5
our @EXPORT = qw(create_payment_terms create_bank_account create_bank_transaction);
6

  
7
use SL::DB::PaymentTerm;
8
use SL::DB::BankAccount;
9
use SL::DB::Chart;
10
use DateTime;
11

  
12
sub create_payment_terms {
13
  my (%params) = @_;
14

  
15
  my $payment_terms =  SL::DB::PaymentTerm->new(
16
    description      => 'payment',
17
    description_long => 'payment',
18
    terms_netto      => '30',
19
    terms_skonto     => '5',
20
    percent_skonto   => '0.05',
21
    auto_calculation => 1,
22
  );
23
  $payment_terms->assign_attributes(%params) if %params;
24
  $payment_terms->save;
25
}
26

  
27
sub create_bank_account {
28
  my (%params) = @_;
29
  my $bank_account = SL::DB::BankAccount->new(
30
    iban           => 'DE12500105170648489890',
31
    account_number => '0648489890',
32
    bank           => 'Testbank',
33
    chart_id       => delete $params{chart_id} // $::instance_conf->get_ar_paid_accno_id,
34
    name           => 'Test bank account',
35
    bic            => 'BANK1234',
36
    bank_code      => '50010517'
37
  );
38
  $bank_account->assign_attributes(%params) if %params;
39
  $bank_account->save;
40
}
41

  
42
sub create_bank_transaction {
43
 my (%params) = @_;
44

  
45
 my $record = delete $params{record};
46
 die "bank_transactions can only be created for invoices" unless ref($record) eq 'SL::DB::Invoice' or ref($record) eq 'SL::DB::PurchaseInvoice';
47

  
48
 my $multiplier = $record->is_sales ? 1 : -1;
49
 my $amount = (delete $params{amount} || $record->amount) * $multiplier;
50

  
51
 my $bank_chart;
52
 if ( $params{chart_id} ) {
53
   $bank_chart = SL::DB::Manager::Chart->find_by(chart_id => $params{chart_id}) or die "Can't find bank chart";
54
 } elsif ( $::instance_conf->get_ar_paid_accno_id ) {
55
   $bank_chart   = SL::DB::Manager::Chart->find_by(id => $::instance_conf->get_ar_paid_accno_id);
56
 } else {
57
   $bank_chart = SL::DB::Manager::Chart->find_by(description => 'Bank') or die "Can't find bank chart";
58
 }
59
 my $bank_account = SL::DB::Manager::BankAccount->find_by( chart_id => $bank_chart->id );
60

  
61
 my $bt = SL::DB::BankTransaction->new(
62
   local_bank_account_id => $bank_account->id,
63
   remote_bank_code      => $record->customervendor->bank_code,
64
   remote_account_number => $record->customervendor->account_number,
65
   transdate             => DateTime->today,
66
   valutadate            => DateTime->today,
67
   amount                => $amount,
68
   currency              => $record->currency->id,
69
   remote_name           => $record->customervendor->depositor,
70
   purpose               => $record->invnumber
71
 );
72
 $bt->assign_attributes(%params) if %params;
73
 $bt->save;
74
}
75

  
76
1;
77

  
78
__END__
79

  
80
=head1 NAME
81

  
82
SL::Dev::Payment - create objects for payment-related testing, with minimal defaults
83

  
84
=head1 FUNCTIONS
85

  
86
=head2 C<create_payment_terms %PARAMS>
87

  
88
Create payment terms.
89

  
90
Minimal example with default values (30days, 5% skonto within 5 days):
91
  my $payment_terms = SL::Dev::Record::create_payment_terms;
92

  
93
=head2 C<create_bank_account %PARAMS>
94

  
95
Required params: chart_id
96

  
97
Example:
98
  my $bank_account = SL::Dev::Record::create_bank_account(chart_id => SL::DB::Manager::Chart->find_by(description => 'Bank')->id);
99

  
100
=head2 C<create_bank_transaction %PARAMS>
101

  
102
Required params: record  (an SL::DB::Invoice or SL::DB::PurchaseInvoice object)
103

  
104

  
105
$params{amount} should always be relative to the absolute amount of the invoice, i.e. use positive
106
values for sales and purchases.
107

  
108
Create a bank transaction that matches an existing invoice record, e.g. to be able to
109
test the point system.
110

  
111
Example:
112
  my $payment_terms = SL::Dev::Record::create_payment_terms;
113
  my $bank_chart    = SL::DB::Manager::Chart->find_by(description => 'Bank');
114
  my $bank_account  = SL::Dev::Record::create_bank_account(chart_id => $bank_chart->id);
115
  my $customer      = SL::Dev::CustomerVendor::create_customer(iban           => 'DE12500105170648489890',
116
                                                               bank_code      => 'abc',
117
                                                               account_number => '44444',
118
                                                               bank           => 'Testbank',
119
                                                               bic            => 'foobar',
120
                                                               depositor      => 'Name')->save;
121
  my $sales_invoice = SL::Dev::Record::create_sales_invoice(customer      => $customer,
122
                                                            payment_terms => $payment_terms,
123
                                                           );
124
  my $bt            = SL::Dev::Payment::create_bank_transaction(record        => $sales_invoice,
125
                                                                amount        => $sales_invoice->amount_less_skonto,
126
                                                                transdate     => DateTime->today->add(days => 10),
127
                                                                bank_chart_id => $bank_chart->id
128
                                                               );
129
  my ($agreement, $rule_matches) = $bt->get_agreement_with_invoice($sales_invoice);
130
  # 14, 'remote_account_number(3) skonto_exact_amount(5) cust_vend_number_in_purpose(1) depositor_matches(2) payment_within_30_days(1) datebonus14(2)'
131

  
132
To create a payment for 3 invoices that were all paid together, all with skonto:
133
  my $ar1 = SL::DB::Manager::Invoice->find_by(invnumber=>'20');
134
  my $ar2 = SL::DB::Manager::Invoice->find_by(invnumber=>'21');
135
  my $ar3 = SL::DB::Manager::Invoice->find_by(invnumber=>'22');
136
  SL::Dev::Payment::create_bank_transaction(record  => $ar1
137
                                            amount  => ($ar1->amount_less_skonto + $ar2->amount_less_skonto + $ar2->amount_less_skonto),
138
                                            purpose => 'Rechnungen 20, 21, 22',
139
                                           );
140
=head1 TODO
141

  
142
=head1 BUGS
143

  
144
Nothing here yet.
145

  
146
=head1 AUTHOR
147

  
148
G. Richardson E<lt>grichardson@kivitendo-premium.deE<gt>
149

  
150
=cut

Auch abrufbar als: Unified diff