auf Original-Version zurückgesetzt
[kivitendo-erp.git] / SL / Dev / Payment.pm
index bce5c0f..a093ed4 100644 (file)
@@ -2,7 +2,8 @@ package SL::Dev::Payment;
 
 use strict;
 use base qw(Exporter);
-our @EXPORT = qw(create_payment_terms create_bank_account create_bank_transaction);
+our @EXPORT_OK = qw(create_payment_terms create_bank_account create_bank_transaction create_sepa_export create_sepa_export_item);
+our %EXPORT_TAGS = (ALL => \@EXPORT_OK);
 
 use SL::DB::PaymentTerm;
 use SL::DB::BankAccount;
@@ -39,6 +40,30 @@ sub create_bank_account {
   $bank_account->save;
 }
 
+sub create_sepa_export {
+  my (%params) = @_;
+  my $sepa_export = SL::DB::SepaExport->new(
+    closed       => 0,
+    employee_id  => $params{employee_id} // SL::DB::Manager::Employee->current->id,
+    executed     => 0,
+    vc           => 'customer',
+  );
+  $sepa_export->assign_attributes(%params) if %params;
+  $sepa_export->save;
+}
+
+sub create_sepa_export_item {
+  my (%params) = @_;
+  my $sepa_exportitem = SL::DB::SepaExportItem->new(
+    chart_id     => delete $params{chart_id} // $::instance_conf->get_ar_paid_accno_id,
+    payment_type => 'without_skonto',
+    our_bic      => 'BANK1234',
+    our_iban     => 'DE12500105170648489890',
+  );
+  $sepa_exportitem->assign_attributes(%params) if %params;
+  $sepa_exportitem->save;
+}
+
 sub create_bank_transaction {
  my (%params) = @_;
 
@@ -49,14 +74,15 @@ sub create_bank_transaction {
  my $amount = (delete $params{amount} || $record->amount) * $multiplier;
 
  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";
+ if ( $params{bank_chart_id} ) {
+   $bank_chart = SL::DB::Manager::Chart->find_by(id => delete $params{bank_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 );
+ die "bank account missing" unless $bank_account;
 
  my $bt = SL::DB::BankTransaction->new(
    local_bank_account_id => $bank_account->id,
@@ -88,30 +114,36 @@ SL::Dev::Payment - create objects for payment-related testing, with minimal defa
 Create payment terms.
 
 Minimal example with default values (30days, 5% skonto within 5 days):
-  my $payment_terms = SL::Dev::Record::create_payment_terms;
+  my $payment_terms = SL::Dev::Payment::create_payment_terms;
 
 =head2 C<create_bank_account %PARAMS>
 
 Required params: chart_id
 
 Example:
-  my $bank_account = SL::Dev::Record::create_bank_account(chart_id => SL::DB::Manager::Chart->find_by(description => 'Bank')->id);
+  my $bank_account = SL::Dev::Payment::create_bank_account(chart_id => SL::DB::Manager::Chart->find_by(description => 'Bank')->id);
 
 =head2 C<create_bank_transaction %PARAMS>
 
+Create a bank transaction that matches an existing invoice record, e.g. to be able to
+test the point system.
+
 Required params: record  (an SL::DB::Invoice or SL::DB::PurchaseInvoice object)
 
+Optional params: bank_chart_id : the chart id of a configured bank account
+                 amount        : the amount of the bank transaction
 
-$params{amount} should always be relative to the absolute amount of the invoice, i.e. use positive
-values for sales and purchases.
+If no bank_chart_id is given, it tries to find a chart via defaults
+(ar_paid_accno_id) or by searching for the chart named "Bank". The chart must
+be connected to an existing BankAccount.
 
-Create a bank transaction that matches an existing invoice record, e.g. to be able to
-test the point system.
+Param amount should always be relative to the absolute amount of the invoice, i.e. use positive
+values for sales and purchases.
 
 Example:
-  my $payment_terms = SL::Dev::Record::create_payment_terms;
+  my $payment_terms = SL::Dev::Payment::create_payment_terms;
   my $bank_chart    = SL::DB::Manager::Chart->find_by(description => 'Bank');
-  my $bank_account  = SL::Dev::Record::create_bank_account(chart_id => $bank_chart->id);
+  my $bank_account  = SL::Dev::Payment::create_bank_account(chart_id => $bank_chart->id);
   my $customer      = SL::Dev::CustomerVendor::create_customer(iban           => 'DE12500105170648489890',
                                                                bank_code      => 'abc',
                                                                account_number => '44444',
@@ -137,8 +169,11 @@ To create a payment for 3 invoices that were all paid together, all with skonto:
                                             amount  => ($ar1->amount_less_skonto + $ar2->amount_less_skonto + $ar2->amount_less_skonto),
                                             purpose => 'Rechnungen 20, 21, 22',
                                            );
+
 =head1 TODO
 
+Nothing here yet.
+
 =head1 BUGS
 
 Nothing here yet.