Bug 26384: Fix executable flags
[koha-ffzg.git] / t / db_dependent / Accounts.t
old mode 100644 (file)
new mode 100755 (executable)
index c7e21ab..12e11f5
@@ -61,7 +61,6 @@ $dbh->do(q|DELETE FROM issues|);
 $dbh->do(q|DELETE FROM borrowers|);
 
 my $branchcode = $library->{branchcode};
-my $borrower_number;
 
 my $context = new Test::MockModule('C4::Context');
 $context->mock( 'userenv', sub {
@@ -76,15 +75,15 @@ my $userenv_branchcode = $branchcode;
 
 # Test manualinvoice
 my $itemtype = $builder->build( { source => 'Itemtype' } );
-my $item   = $builder->build( { source => 'Item', value => { itype => $itemtype->{itemtype} } } );
+my $item   = $builder->build_sample_item( { itype => $itemtype->{itemtype} } );
 my $patron = $builder->build( { source => 'Borrower' } );
-my $amount = '5.000000';
+my $amount = 5;
 my $description = "Test fee!";
 my $type = 'LOST';
 my $note = 'Test note!';
 warning_like {
     C4::Accounts::manualinvoice( $patron->{borrowernumber},
-        $item->{itemnumber}, $description, $type, $amount, $note )
+        $item->itemnumber, $description, $type, $amount, $note )
 }
 qr/C4::Accounts::manualinvoice is deprecated in favor of Koha::Account->add_debit/,
   "deprecation warning received for manualinvoice";
@@ -94,7 +93,7 @@ my ($accountline) = Koha::Account::Lines->search(
     }
 );
 is( $accountline->debit_type_code, $type, 'Debit type set correctly for manualinvoice' );
-is( $accountline->amount, $amount, 'Accountline amount set correctly for manualinvoice' );
+is( $accountline->amount+0, $amount, 'Accountline amount set correctly for manualinvoice' );
 ok( $accountline->description =~ /^$description/, 'Accountline description set correctly for manualinvoice' );
 is( $accountline->note, $note, 'Accountline note set correctly for manualinvoice' );
 is( $accountline->branchcode, $branchcode, 'Accountline branchcode set correctly for manualinvoice' );
@@ -214,7 +213,7 @@ subtest "Koha::Account::pay tests" => sub {
     my $borrowernumber = $borrower->borrowernumber;
     my $data = '20.00';
     my $payment_note = '$20.00 payment note';
-    my $id = $account->pay( { amount => $data, note => $payment_note, payment_type => "TEST_TYPE" } );
+    my $id = $account->pay( { amount => $data, note => $payment_note, payment_type => "TEST_TYPE" } )->{payment_id};
 
     my $accountline = Koha::Account::Lines->find( $id );
     is( $accountline->payment_type, "TEST_TYPE", "Payment type passed into pay is set in account line correctly" );
@@ -294,11 +293,11 @@ subtest "Koha::Account::pay tests" => sub {
     is($note,'$200.00 payment note', '$200.00 payment note is registered');
 
     my $line3 = $account->add_debit({ type => 'ACCOUNT', amount => 42, interface => 'commandline' });
-    my $payment_id = $account->pay( { lines => [$line3], amount => 42 } );
+    my $payment_id = $account->pay( { lines => [$line3], amount => 42 } )->{payment_id};
     my $payment = Koha::Account::Lines->find( $payment_id );
-    is( $payment->amount(), '-42.000000', "Payment paid the specified fine" );
+    is( $payment->amount()+0, -42, "Payment paid the specified fine" );
     $line3 = Koha::Account::Lines->find( $line3->id );
-    is( $line3->amountoutstanding, '0.000000', "Specified fine is paid" );
+    is( $line3->amountoutstanding+0, 0, "Specified fine is paid" );
     is( $payment->branchcode, undef, 'branchcode passed, then undef' );
 };
 
@@ -338,13 +337,13 @@ subtest "Koha::Account::pay particular line tests" => sub {
     $_->_result->discard_changes foreach ( $line1, $line2, $line3, $line4 );
 
     # Line1 is not paid at all, as it was not passed in the lines param
-    is( $line1->amountoutstanding, "1.000000", "Line 1 was not paid" );
+    is( $line1->amountoutstanding+0, 1, "Line 1 was not paid" );
     # Line2 was paid in full, as it was the first in the lines list
-    is( $line2->amountoutstanding, "0.000000", "Line 2 was paid in full" );
+    is( $line2->amountoutstanding+0, 0, "Line 2 was paid in full" );
     # Line3 was paid partially, as the remaining balance did not cover it entirely
-    is( $line3->amountoutstanding, "1.000000", "Line 3 was paid to 1.00" );
+    is( $line3->amountoutstanding+0, 1, "Line 3 was paid to 1.00" );
     # Line4 was not paid at all, as the payment was all used up by that point
-    is( $line4->amountoutstanding, "4.000000", "Line 4 was not paid" );
+    is( $line4->amountoutstanding+0, 4, "Line 4 was not paid" );
 };
 
 subtest "Koha::Account::pay writeoff tests" => sub {
@@ -376,17 +375,17 @@ subtest "Koha::Account::pay writeoff tests" => sub {
             amount => 42,
             type   => 'WRITEOFF',
         }
-    );
+    )->{payment_id};
 
     $line->_result->discard_changes();
 
-    is( $line->amountoutstanding, "0.000000", "Line was written off" );
+    is( $line->amountoutstanding+0, 0, "Line was written off" );
 
     my $writeoff = Koha::Account::Lines->find( $id );
 
     is( $writeoff->credit_type_code, 'WRITEOFF', 'Type is correct for WRITEOFF' );
     is( $writeoff->description, 'Writeoff', 'Description is correct' );
-    is( $writeoff->amount, '-42.000000', 'Amount is correct' );
+    is( $writeoff->amount+0, -42, 'Amount is correct' );
 };
 
 subtest "More Koha::Account::pay tests" => sub {
@@ -428,7 +427,7 @@ subtest "More Koha::Account::pay tests" => sub {
     $account->pay({ lines => [$line], amount => $amount, library_id => $branch, note => 'A payment note' });
 
     my $offset = Koha::Account::Offsets->search({ debit_id => $accountline->{accountlines_id} })->next();
-    is( $offset->amount(), '-100.000000', 'Offset amount is -100.00' );
+    is( $offset->amount+0, -100, 'Offset amount is -100.00' );
     is( $offset->type(), 'Payment', 'Offset type is Payment' );
 
     my $stat = $schema->resultset('Statistic')->search({
@@ -488,7 +487,7 @@ subtest "Even more Koha::Account::pay tests" => sub {
     $account->pay({ lines => [$line], amount => $partialamount, library_id => $branch, note => 'A payment note' });
 
     my $offset = Koha::Account::Offsets->search( { debit_id => $accountline->{ accountlines_id } } )->next();
-    is( $offset->amount, '-60.000000', 'Offset amount is -60.00' );
+    is( $offset->amount+0, -60, 'Offset amount is -60.00' );
     is( $offset->type, 'Payment', 'Offset type is payment' );
 
     my $stat = $schema->resultset('Statistic')->search({
@@ -587,10 +586,10 @@ subtest "C4::Accounts::chargelostitem tests" => sub {
             processfee => 2.04,
     }});
     my $cli_borrowernumber = $builder->build({ source => 'Borrower' })->{'borrowernumber'};
-    my $cli_itemnumber1 = $builder->build({ source => 'Item', value => { itype => $itype_no_replace_no_fee->{itemtype} } })->{'itemnumber'};
-    my $cli_itemnumber2 = $builder->build({ source => 'Item', value => { itype => $itype_replace_no_fee->{itemtype} } })->{'itemnumber'};
-    my $cli_itemnumber3 = $builder->build({ source => 'Item', value => { itype => $itype_no_replace_fee->{itemtype} } })->{'itemnumber'};
-    my $cli_itemnumber4 = $builder->build({ source => 'Item', value => { itype => $itype_replace_fee->{itemtype} } })->{'itemnumber'};
+    my $cli_itemnumber1 = $builder->build_sample_item({ itype => $itype_no_replace_no_fee->{itemtype} })->itemnumber;
+    my $cli_itemnumber2 = $builder->build_sample_item({ itype => $itype_replace_no_fee->{itemtype} })->itemnumber;
+    my $cli_itemnumber3 = $builder->build_sample_item({ itype => $itype_no_replace_fee->{itemtype} })->itemnumber;
+    my $cli_itemnumber4 = $builder->build_sample_item({ itype => $itype_replace_fee->{itemtype} })->itemnumber;
 
     my $cli_issue_id_1 = $builder->build({ source => 'Issue', value => { borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1 } })->{issue_id};
     my $cli_issue_id_2 = $builder->build({ source => 'Issue', value => { borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2 } })->{issue_id};
@@ -791,7 +790,6 @@ subtest "Koha::Account::non_issues_charges tests" => sub {
     my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
     my $account = $patron->account;
 
-    my $today  = dt_from_string;
     my $res    = 3;
     my $rent   = 5;
     my $manual = 7;
@@ -821,7 +819,6 @@ subtest "Koha::Account::non_issues_charges tests" => sub {
     Koha::Account::Line->new(
         {
             borrowernumber    => $patron->borrowernumber,
-            date              => $today,
             description       => 'a Manual invoice fee',
             debit_type_code   => 'Copie',
             amountoutstanding => $manual,
@@ -969,7 +966,7 @@ subtest "Koha::Account::non_issues_charges tests" => sub {
     my $debit = Koha::Account::Line->new(
         {
             borrowernumber    => $patron->id,
-            date              => '1900-01-01',
+            date              => '1970-01-01 00:00:01',
             amountoutstanding => 0,
             interface         => 'commandline',
             debit_type_code   => 'LOST'
@@ -978,7 +975,7 @@ subtest "Koha::Account::non_issues_charges tests" => sub {
     my $credit = Koha::Account::Line->new(
         {
             borrowernumber    => $patron->id,
-            date              => '1900-01-01',
+            date              => '1970-01-01 00:00:01',
             amountoutstanding => -5,
             interface         => 'commandline',
             credit_type_code  => 'PAYMENT'
@@ -1002,7 +999,7 @@ subtest "Koha::Account::non_issues_charges tests" => sub {
     $debit = Koha::Account::Line->new(
         {
             borrowernumber    => $patron->id,
-            date              => '1900-01-01',
+            date              => '1970-01-01 00:00:01',
             amountoutstanding => 5,
             interface         => 'commanline',
             debit_type_code   => 'LOST'
@@ -1011,7 +1008,7 @@ subtest "Koha::Account::non_issues_charges tests" => sub {
     $credit = Koha::Account::Line->new(
         {
             borrowernumber    => $patron->id,
-            date              => '1900-01-01',
+            date              => '1970-01-01 00:00:01',
             amountoutstanding => 0,
             interface         => 'commandline',
             credit_type_code  => 'PAYMENT'
@@ -1036,7 +1033,7 @@ subtest "Koha::Account::non_issues_charges tests" => sub {
     $debit = Koha::Account::Line->new(
         {
             borrowernumber    => $patron->id,
-            date              => '1900-01-01',
+            date              => '1970-01-01 00:00:01',
             amountoutstanding => 0,
             interface         => 'commandline',
             debit_type_code   => 'LOST'
@@ -1045,7 +1042,7 @@ subtest "Koha::Account::non_issues_charges tests" => sub {
     $credit = Koha::Account::Line->new(
         {
             borrowernumber    => $patron->id,
-            date              => '1900-01-01',
+            date              => '1970-01-01 00:00:01',
             amountoutstanding => 0,
             interface         => 'commandline',
             credit_type_code  => 'PAYMENT'
@@ -1111,7 +1108,7 @@ subtest "Koha::Account::Offset credit & debit tests" => sub {
             lines  => [$line1, $line2],
             amount => 30,
         }
-    );
+    )->{payment_id};
 
     # Test debit and credit methods for Koha::Account::Offset
     my $account_offset = Koha::Account::Offsets->find( { credit_id => $id, debit_id => $line1->id } );
@@ -1173,34 +1170,34 @@ subtest "Payment notice tests" => sub {
     )->store();
 
     my $letter = Koha::Notice::Templates->find( { code => 'ACCOUNT_PAYMENT' } );
-    $letter->content('[%- USE Price -%]A payment of [% credit.amount * -1 | $Price %] has been applied to your account.');
+    $letter->content('[%- USE Price -%]A payment of [% credit.amount * -1 | $Price %] has been applied to your account. Your [% branch.branchcode %]');
     $letter->store();
 
     t::lib::Mocks::mock_preference('UseEmailReceipts', '0');
-    my $id = $account->pay( { amount => 1 } );
+    my $id = $account->pay( { amount => 1 } )->{payment_id};
     is( Koha::Notice::Messages->search()->count(), 0, 'Notice for payment not sent if UseEmailReceipts is disabled' );
 
-    $id = $account->pay( { amount => 1, type => 'WRITEOFF' } );
+    $id = $account->pay( { amount => 1, type => 'WRITEOFF' } )->{payment_id};
     is( Koha::Notice::Messages->search()->count(), 0, 'Notice for writeoff not sent if UseEmailReceipts is disabled' );
 
     t::lib::Mocks::mock_preference('UseEmailReceipts', '1');
 
-    $id = $account->pay( { amount => 12 } );
+    $id = $account->pay( { amount => 12, library_id => $branchcode } )->{payment_id};
     my $notice = Koha::Notice::Messages->search()->next();
     is( $notice->subject, 'Account payment', 'Notice subject is correct for payment' );
     is( $notice->letter_code, 'ACCOUNT_PAYMENT', 'Notice letter code is correct for payment' );
-    is( $notice->content, 'A payment of 12.00 has been applied to your account.', 'Notice content is correct for payment' );
+    is( $notice->content, "A payment of 12.00 has been applied to your account. Your $branchcode", 'Notice content is correct for payment' );
     $notice->delete();
 
     $letter = Koha::Notice::Templates->find( { code => 'ACCOUNT_WRITEOFF' } );
-    $letter->content('[%- USE Price -%]A writeoff of [% credit.amount * -1 | $Price %] has been applied to your account.');
+    $letter->content('[%- USE Price -%]A writeoff of [% credit.amount * -1 | $Price %] has been applied to your account. Your [% branch.branchcode %]');
     $letter->store();
 
-    $id = $account->pay( { amount => 13, type => 'WRITEOFF' } );
+    $id = $account->pay( { amount => 13, type => 'WRITEOFF', library_id => $branchcode  } )->{payment_id};
     $notice = Koha::Notice::Messages->search()->next();
     is( $notice->subject, 'Account writeoff', 'Notice subject is correct for payment' );
     is( $notice->letter_code, 'ACCOUNT_WRITEOFF', 'Notice letter code is correct for writeoff' );
-    is( $notice->content, 'A writeoff of 13.00 has been applied to your account.', 'Notice content is correct for writeoff' );
+    is( $notice->content, "A writeoff of 13.00 has been applied to your account. Your $branchcode", 'Notice content is correct for writeoff' );
 };
 
 1;