Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision a46027e7

Von G. Richardson vor mehr als 4 Jahren hinzugefügt

  • ID a46027e742761ba5a013adef5e67142b28ec64d9
  • Vorgänger b3346748
  • Nachfolger ae7f661a

Payment Helper Test nutzt create_ap_transaction

create_ap_transaction benutzen, statt per acc_trans-Einträge manuell
zusammenzubauen. Außerdem purchase_invoice in ap_transaction umbenannt.

Unterschiede anzeigen:

t/db_helper/payment.t
11 11
use Test::Exception;
12 12
use List::Util qw(sum);
13 13

  
14
use SL::Dev::Record qw(create_invoice_item create_sales_invoice create_credit_note);
14
use SL::Dev::Record qw(create_invoice_item create_sales_invoice create_credit_note create_ap_transaction);
15 15
use SL::Dev::CustomerVendor qw(new_customer new_vendor);
16 16
use SL::Dev::Part qw(new_part);
17 17
use SL::DB::Buchungsgruppe;
......
33 33
my ($transdate1, $transdate2, $transdate3, $transdate4, $currency, $exchangerate, $exchangerate2, $exchangerate3, $exchangerate4);
34 34
my ($ar_chart,$bank,$ar_amount_chart, $ap_chart, $ap_amount_chart, $fxloss_chart, $fxgain_chart);
35 35

  
36
my $purchase_invoice_counter = 0; # used for generating purchase invnumber
36
my $ap_transaction_counter = 0; # used for generating purchase invnumber
37 37

  
38 38
Support::TestSetup::login();
39 39

  
......
45 45
test_default_invoice_two_items_19_7_without_skonto();
46 46
test_default_invoice_two_items_19_7_without_skonto_incomplete_payment();
47 47
test_default_invoice_two_items_19_7_tax_without_skonto_multiple_payments();
48
test_default_purchase_invoice_two_charts_19_7_without_skonto();
49
test_default_purchase_invoice_two_charts_19_7_tax_partial_unrounded_payment_without_skonto();
48
test_default_ap_transaction_two_charts_19_7_without_skonto();
49
test_default_ap_transaction_two_charts_19_7_tax_partial_unrounded_payment_without_skonto();
50 50
test_default_invoice_one_item_19_without_skonto_overpaid();
51 51
test_credit_note_two_items_19_7_tax_tax_not_included();
52 52

  
......
56 56
test_default_invoice_two_items_19_7_tax_without_skonto_multiple_payments_final_difference_as_skonto_2cent();
57 57
test_default_invoice_one_item_19_multiple_payment_final_difference_as_skonto();
58 58
test_default_invoice_one_item_19_multiple_payment_final_difference_as_skonto_1cent();
59
test_default_purchase_invoice_two_charts_19_7_tax_without_skonto_multiple_payments_final_difference_as_skonto();
59
test_default_ap_transaction_two_charts_19_7_tax_without_skonto_multiple_payments_final_difference_as_skonto();
60 60

  
61 61
# test cases: with_skonto_pt
62 62
test_default_invoice_two_items_19_7_tax_with_skonto_50_50();
63 63
test_default_invoice_four_items_19_7_tax_with_skonto_4x_25();
64 64
test_default_invoice_four_items_19_7_tax_with_skonto_4x_25_multiple();
65
test_default_purchase_invoice_two_charts_19_7_with_skonto();
65
test_default_ap_transaction_two_charts_19_7_with_skonto();
66 66
test_default_invoice_four_items_19_7_tax_with_skonto_4x_25_tax_included();
67 67
test_default_invoice_two_items_19_7_tax_with_skonto_tax_included();
68 68

  
......
238 238
  $ap_amount_chart = SL::DB::Manager::Chart->find_by( accno => '3400' ); # Wareneingang 19%
239 239
}
240 240

  
241
sub new_purchase_invoice {
242
  # my %params  = @_;
243
  # manually create a Kreditorenbuchung from scratch, ap + acc_trans bookings, as no helper exists yet, like $invoice->post.
244
  # arap-Booking must come last in the acc_trans order
245
  $purchase_invoice_counter++;
241
sub new_ap_transaction {
242
  $ap_transaction_counter++;
246 243

  
247
  my $purchase_invoice = SL::DB::PurchaseInvoice->new(
248
    vendor_id   => $vendor->id,
249
    invnumber   => 'newap ' . $purchase_invoice_counter ,
250
    currency_id => $currency_id,
251
    employee_id => $employee->id,
252
    gldate      => $transdate1,
253
    taxzone_id  => $taxzone->id,
254
    transdate   => $transdate1,
255
    invoice     => 0,
256
    type        => 'invoice',
244
  my $ap_transaction = create_ap_transaction(
245
    vendor      => $vendor,
246
    invnumber   => 'newap ' . $ap_transaction_counter,
257 247
    taxincluded => 0,
258 248
    amount      => '226',
259 249
    netamount   => '200',
260
    paid        => '0',
261
    # %params,
262
  )->save;
263

  
264
  my $expense_chart  = SL::DB::Manager::Chart->find_by(accno => '3400');
265
  my $expense_chart_booking= SL::DB::AccTransaction->new(
266
                                        trans_id   => $purchase_invoice->id,
267
                                        chart_id   => $expense_chart->id,
268
                                        chart_link => $expense_chart->link,
269
                                        amount     => '-100',
270
                                        transdate  => $transdate1,
271
                                        source     => '',
272
                                        taxkey     => 9,
273
                                        tax_id     => SL::DB::Manager::Tax->find_by(taxkey => 9)->id);
274
  $expense_chart_booking->save;
275

  
276
  my $tax_chart  = SL::DB::Manager::Chart->find_by(accno => '1576');
277
  my $tax_chart_booking= SL::DB::AccTransaction->new(
278
                                        trans_id   => $purchase_invoice->id,
279
                                        chart_id   => $tax_chart->id,
280
                                        chart_link => $tax_chart->link,
281
                                        amount     => '-19',
282
                                        transdate  => $transdate1,
283
                                        source     => '',
284
                                        taxkey     => 0,
285
                                        tax_id     => SL::DB::Manager::Tax->find_by(taxkey => 9)->id);
286
  $tax_chart_booking->save;
287
  $expense_chart  = SL::DB::Manager::Chart->find_by(accno => '3300');
288
  $expense_chart_booking= SL::DB::AccTransaction->new(
289
                                        trans_id   => $purchase_invoice->id,
290
                                        chart_id   => $expense_chart->id,
291
                                        chart_link => $expense_chart->link,
292
                                        amount     => '-100',
293
                                        transdate  => $transdate1,
294
                                        source     => '',
295
                                        taxkey     => 8,
296
                                        tax_id     => SL::DB::Manager::Tax->find_by(taxkey => 8)->id);
297
  $expense_chart_booking->save;
298

  
299

  
300
  $tax_chart  = SL::DB::Manager::Chart->find_by(accno => '1571');
301
  $tax_chart_booking= SL::DB::AccTransaction->new(
302
                                         trans_id   => $purchase_invoice->id,
303
                                         chart_id   => $tax_chart->id,
304
                                         chart_link => $tax_chart->link,
305
                                         amount     => '-7',
306
                                         transdate  => $transdate1,
307
                                         source     => '',
308
                                         taxkey     => 0,
309
                                         tax_id     => SL::DB::Manager::Tax->find_by(taxkey => 8)->id);
310
  $tax_chart_booking->save;
311
  my $arap_chart  = SL::DB::Manager::Chart->find_by(accno => '1600');
312
  my $arap_booking= SL::DB::AccTransaction->new(trans_id   => $purchase_invoice->id,
313
                                                chart_id   => $arap_chart->id,
314
                                                chart_link => $arap_chart->link,
315
                                                amount     => '226',
316
                                                transdate  => $transdate1,
317
                                                source     => '',
318
                                                taxkey     => 0,
319
                                                tax_id     => SL::DB::Manager::Tax->find_by(taxkey => 0)->id);
320
  $arap_booking->save;
321

  
322
  return $purchase_invoice;
250
    gldate      => $transdate1,
251
    taxzone_id  => $taxzone->id,
252
    transdate   => $transdate1,
253
    bookings    => [
254
                     {
255
                       chart => SL::DB::Manager::Chart->find_by(accno => '3400'),
256
                       amount => 100,
257
                     },
258
                     {
259
                       chart => SL::DB::Manager::Chart->find_by(accno => '3300'),
260
                       amount => 100,
261
                     },
262
                   ],
263
 );
264

  
265
  return $ap_transaction;
323 266
}
324 267

  
325 268
sub number_of_payments {
......
331 274
    if ( $transaction->chart_link =~ /(AR_paid|AP_paid)/ ) {
332 275
      $paid_amount += $transaction->amount ;
333 276
      $number_of_payments++;
334
    };
277
    }
335 278
  };
336 279
  return ($number_of_payments, $paid_amount);
337 280
};
......
356 299
    payment_id   => $payment_terms->id,
357 300
  );
358 301

  
359
  my $purchase_invoice = new_purchase_invoice();
302
  my $ap_transaction = new_ap_transaction();
360 303

  
361 304
  # default values
362 305
  my %params = ( chart_id => $bank_account->chart_id,
......
390 333
    payment_id   => $payment_terms->id,
391 334
  );
392 335

  
393
  my $purchase_invoice = new_purchase_invoice();
336
  my $ap_transaction = new_ap_transaction();
394 337

  
395 338

  
396 339
  # default values
......
772 715
}
773 716

  
774 717
# test 3 : two items, without skonto
775
sub test_default_purchase_invoice_two_charts_19_7_without_skonto {
718
sub test_default_ap_transaction_two_charts_19_7_without_skonto {
776 719
  my $title = 'default invoice, two items, 19/7% tax without skonto';
777 720

  
778
  my $purchase_invoice = new_purchase_invoice();
721
  my $ap_transaction = new_ap_transaction();
779 722

  
780 723
  my %params = ( chart_id => $bank_account->chart_id,
781 724
                 transdate => DateTime->today_local->to_kivitendo
......
784 727
  $params{amount} = '226'; # pass full amount
785 728
  $params{payment_type} = 'without_skonto';
786 729

  
787
  $purchase_invoice->pay_invoice( %params );
730
  $ap_transaction->pay_invoice( %params );
788 731

  
789
  my ($number_of_payments, $paid_amount) = number_of_payments($purchase_invoice);
790
  my $total = total_amount($purchase_invoice);
732
  my ($number_of_payments, $paid_amount) = number_of_payments($ap_transaction);
733
  my $total = total_amount($ap_transaction);
791 734

  
792 735
  is($paid_amount,         226,     "${title}: paid amount");
793 736
  is($number_of_payments,    1,     "${title}: 1 AP_paid bookings");
......
795 738

  
796 739
}
797 740

  
798
sub test_default_purchase_invoice_two_charts_19_7_with_skonto {
741
sub test_default_ap_transaction_two_charts_19_7_with_skonto {
799 742
  my $title = 'default invoice, two items, 19/7% tax without skonto';
800 743

  
801
  my $purchase_invoice = new_purchase_invoice();
744
  my $ap_transaction = new_ap_transaction();
802 745

  
803 746
  my %params = ( chart_id => $bank_account->chart_id,
804 747
                 transdate => DateTime->today_local->to_kivitendo
......
807 750
  # $params{amount} = '226'; # pass full amount
808 751
  $params{payment_type} = 'with_skonto_pt';
809 752

  
810
  $purchase_invoice->pay_invoice( %params );
753
  $ap_transaction->pay_invoice( %params );
811 754

  
812
  my ($number_of_payments, $paid_amount) = number_of_payments($purchase_invoice);
813
  my $total = total_amount($purchase_invoice);
755
  my ($number_of_payments, $paid_amount) = number_of_payments($ap_transaction);
756
  my $total = total_amount($ap_transaction);
814 757

  
815 758
  is($paid_amount,         226,     "${title}: paid amount");
816 759
  is($number_of_payments,    3,     "${title}: 1 AP_paid bookings");
......
818 761

  
819 762
}
820 763

  
821
sub test_default_purchase_invoice_two_charts_19_7_tax_partial_unrounded_payment_without_skonto {
822
  my $title = 'default purchase_invoice, two charts, 19/7% tax multiple payments with final difference as skonto';
764
sub test_default_ap_transaction_two_charts_19_7_tax_partial_unrounded_payment_without_skonto {
765
  my $title = 'default ap_transaction, two charts, 19/7% tax multiple payments with final difference as skonto';
823 766

  
824 767
  # check whether unrounded amounts passed via $params{amount} are rounded for without_skonto case
825
  my $purchase_invoice = new_purchase_invoice();
826
  $purchase_invoice->pay_invoice(
827
                          amount       => ( $purchase_invoice->amount / 3 * 2),
768
  my $ap_transaction = new_ap_transaction();
769
  $ap_transaction->pay_invoice(
770
                          amount       => ( $ap_transaction->amount / 3 * 2),
828 771
                          payment_type => 'without_skonto',
829 772
                          chart_id     => $bank_account->chart_id,
830 773
                          transdate    => DateTime->today_local->to_kivitendo
831 774
                         );
832
  my ($number_of_payments, $paid_amount) = number_of_payments($purchase_invoice);
833
  my $total = total_amount($purchase_invoice);
775
  my ($number_of_payments, $paid_amount) = number_of_payments($ap_transaction);
776
  my $total = total_amount($ap_transaction);
834 777

  
835 778
  is($paid_amount,         150.67,   "${title}: paid amount");
836 779
  is($number_of_payments,       1,   "${title}: 1 AP_paid bookings");
......
838 781
};
839 782

  
840 783

  
841
sub test_default_purchase_invoice_two_charts_19_7_tax_without_skonto_multiple_payments_final_difference_as_skonto {
842
  my $title = 'default purchase_invoice, two charts, 19/7% tax multiple payments with final difference as skonto';
784
sub test_default_ap_transaction_two_charts_19_7_tax_without_skonto_multiple_payments_final_difference_as_skonto {
785
  my $title = 'default ap_transaction, two charts, 19/7% tax multiple payments with final difference as skonto';
843 786

  
844
  my $purchase_invoice = new_purchase_invoice();
787
  my $ap_transaction = new_ap_transaction();
845 788

  
846 789
  # pay 2/3 and 1/5, leaves 3.83% to be used as Skonto
847
  $purchase_invoice->pay_invoice(
848
                          amount       => ( $purchase_invoice->amount / 3 * 2),
790
  $ap_transaction->pay_invoice(
791
                          amount       => ( $ap_transaction->amount / 3 * 2),
849 792
                          payment_type => 'without_skonto',
850 793
                          chart_id     => $bank_account->chart_id,
851 794
                          transdate    => DateTime->today_local->to_kivitendo
852 795
                         );
853
  $purchase_invoice->pay_invoice(
854
                          amount       => ( $purchase_invoice->amount / 5 ),
796
  $ap_transaction->pay_invoice(
797
                          amount       => ( $ap_transaction->amount / 5 ),
855 798
                          payment_type => 'without_skonto',
856 799
                          chart_id     => $bank_account->chart_id,
857 800
                          transdate    => DateTime->today_local->to_kivitendo
858 801
                         );
859
  $purchase_invoice->pay_invoice(
802
  $ap_transaction->pay_invoice(
860 803
                          payment_type => 'difference_as_skonto',
861 804
                          chart_id     => $bank_account->chart_id,
862 805
                          transdate    => DateTime->today_local->to_kivitendo
863 806
                         );
864 807

  
865
  my ($number_of_payments, $paid_amount) = number_of_payments($purchase_invoice);
866
  my $total = total_amount($purchase_invoice);
808
  my ($number_of_payments, $paid_amount) = number_of_payments($ap_transaction);
809
  my $total = total_amount($ap_transaction);
867 810

  
868 811
  is($paid_amount,         226, "${title}: paid amount");
869 812
  is($number_of_payments,    4, "${title}: 1 AP_paid bookings");

Auch abrufbar als: Unified diff