itemnumber => $itemnum || undef,
note => $note,
manager_id => $manager_id,
+ interface => C4::Context->interface,
branchcode => $branchcode,
}
)->store();
branch => $branchcode,
};
});
+$context->mock( 'interface', sub { return "commandline" } );
my $userenv_branchcode = $branchcode;
# Test manualinvoice
borrowernumber,
amountoutstanding,
date,
- description
+ description,
+ interface
)
- VALUES ( ?, ?, (select date_sub(CURRENT_DATE, INTERVAL ? DAY) ), ? )"
+ VALUES ( ?, ?, (select date_sub(CURRENT_DATE, INTERVAL ? DAY) ), ?, ? )"
);
my $days = 5;
my $borrower = Koha::Patron->new( { firstname => 'Test', surname => 'Patron', categorycode => $categorycode, branchcode => $branchcode } )->store();
for my $data ( @test_data ) {
- $sth->execute($borrower->borrowernumber, $data->{amount}, $data->{days_ago}, $data->{description});
+ $sth->execute($borrower->borrowernumber, $data->{amount}, $data->{days_ago}, $data->{description}, 'commandline');
}
purge_zero_balance_fees( $days );
my $account = Koha::Account->new({ patron_id => $borrower->id });
- my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 100 })->store();
- my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 200 })->store();
+ my $line1 = $account->add_debit({ type => 'account', amount => 100, interface => 'commandline' });
+ my $line2 = $account->add_debit({ type => 'account', amount => 200, interface => 'commandline' });
$sth = $dbh->prepare("SELECT count(*) FROM accountlines");
$sth->execute;
$note = $sth->fetchrow_array;
is($note,'$200.00 payment note', '$200.00 payment note is registered');
- my $line3 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 42, accounttype => 'TEST' })->store();
+ my $line3 = $account->add_debit({ type => 'account', amount => 42, interface => 'commandline' });
my $payment_id = $account->pay( { lines => [$line3], amount => 42 } );
my $payment = Koha::Account::Lines->find( $payment_id );
is( $payment->amount(), '-42.000000', "Payment paid the specified fine" );
my $account = Koha::Account->new({ patron_id => $borrower->id });
- my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 1 })->store();
- my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 2 })->store();
- my $line3 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 3 })->store();
- my $line4 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 4 })->store();
+ my $line1 = $account->add_debit({ type => 'account', amount => 1, interface => 'commandline' });
+ my $line2 = $account->add_debit({ type => 'account', amount => 2, interface => 'commandline' });
+ my $line3 = $account->add_debit({ type => 'account', amount => 3, interface => 'commandline' });
+ my $line4 = $account->add_debit({ type => 'account', amount => 4, interface => 'commandline' });
is( $account->balance(), 10, "Account balance is 10" );
my $account = Koha::Account->new({ patron_id => $borrower->id });
- my $line = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 42 })->store();
+ my $line = $account->add_debit({ type => 'account', amount => 42, interface => 'commandline' });
is( $account->balance(), 42, "Account balance is 42" );
plan tests => 21;
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;
- Koha::Account::Line->new(
+ $account->add_debit(
{
- borrowernumber => $patron->borrowernumber,
- date => $today,
- description => 'a Res fee',
- accounttype => 'Res',
- amountoutstanding => $res,
+ description => 'a Res fee',
+ type => 'reserve',
+ amount => $res,
+ interface => 'commandline'
}
- )->store;
- Koha::Account::Line->new(
+ );
+ $account->add_debit(
{
- borrowernumber => $patron->borrowernumber,
- date => $today,
- description => 'a Rental fee',
- accounttype => 'Rent',
- amountoutstanding => $rent,
+ description => 'a Rental fee',
+ type => 'rent',
+ amount => $rent,
+ interface => 'commandline'
}
- )->store;
+ );
Koha::Account::Line->new(
{
borrowernumber => $patron->borrowernumber,
description => 'a Manual invoice fee',
accounttype => 'Copie',
amountoutstanding => $manual,
+ interface => 'commandline'
}
)->store;
Koha::AuthorisedValue->new(
}
)->store;
- my $account = $patron->account;
t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', 0 );
t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 0 );
}
);
- my $debit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 0 })->store();
- my $credit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => -5 })->store();
+ my $debit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 0, interface => 'commandline' })->store();
+ my $credit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => -5, interface => 'commandline' })->store();
my $offset = Koha::Account::Offset->new({ credit_id => $credit->id, debit_id => $debit->id, type => 'Payment', amount => 0 })->store();
purge_zero_balance_fees( 1 );
my $debit_2 = Koha::Account::Lines->find( $debit->id );
ok( $credit_2, 'Credit was correctly not deleted when credit has balance' );
is( Koha::Account::Lines->count({ borrowernumber => $patron->id }), 2, "The 2 account lines still exists" );
- $debit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 5 })->store();
- $credit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 0 })->store();
+ $debit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 5, interface => 'commanline' })->store();
+ $credit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 0, interface => 'commandline' })->store();
$offset = Koha::Account::Offset->new({ credit_id => $credit->id, debit_id => $debit->id, type => 'Payment', amount => 0 })->store();
purge_zero_balance_fees( 1 );
$debit_2 = $credit_2 = undef;
ok( $credit_2, 'Credit was correctly not deleted when debit has balance' );
is( Koha::Account::Lines->count({ borrowernumber => $patron->id }), 2 + 2, "The 2 + 2 account lines still exists" );
- $debit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 0 })->store();
- $credit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 0 })->store();
+ $debit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 0, interface => 'commandline' })->store();
+ $credit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 0, interface => 'commandline' })->store();
$offset = Koha::Account::Offset->new({ credit_id => $credit->id, debit_id => $debit->id, type => 'Payment', amount => 0 })->store();
purge_zero_balance_fees( 1 );
$debit_2 = Koha::Account::Lines->find( $debit->id );
my $account = Koha::Account->new({ patron_id => $borrower->id });
- my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 10, amountoutstanding => 10 })->store();
- my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 20, amountoutstanding => 20 })->store();
+ my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 10, amountoutstanding => 10, interface => 'commandline' })->store();
+ my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 20, amountoutstanding => 20, interface => 'commandline' })->store();
is( $account->balance(), 30, "Account balance is 30" );
is( $line1->amountoutstanding, 10, 'First fee has amount outstanding of 10' );
my $account = Koha::Account->new({ patron_id => $borrower->id });
- my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 10, amountoutstanding => 10 })->store();
- my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 20, amountoutstanding => 20 })->store();
+ my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 10, amountoutstanding => 10, interface => 'commandline' })->store();
+ my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 20, amountoutstanding => 20, interface => 'commandline' })->store();
my $id = $account->pay(
{
});
my $account = Koha::Account->new({ patron_id => $borrower->id });
- my $line = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 27 })->store();
+ my $line = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 27, interface => 'commandline' })->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.');
$account->add_debit(
{
amount => $fines_amount,
+ interface => 'test',
type => 'fine',
item_id => $item_to_auto_renew->{itemnumber},
description => "Some fines"
$account->add_debit(
{
amount => $fines_amount,
+ interface => 'test',
type => 'fine',
item_id => $item_to_auto_renew->{itemnumber},
description => "Some fines"
$account->add_debit(
{
amount => $fines_amount,
+ interface => 'test',
type => 'fine',
item_id => $item_to_auto_renew->{itemnumber},
description => "Some fines"
# Write off the debt
my $credit = $account->add_credit(
{ amount => $account->balance,
- type => 'writeoff'
+ type => 'writeoff',
+ interface => 'test',
}
);
$credit->apply( { debits => $debts, offset_type => 'Writeoff' } );
# Write off the debt
my $credit = $account->add_credit(
{ amount => $account->balance,
- type => 'payment'
+ type => 'payment',
+ interface => 'test',
}
);
$credit->apply( { debits => $debts, offset_type => 'Payment' } );
my $payment_amount = 27;
my $payment = $account->add_credit(
{ amount => $payment_amount,
- type => 'payment'
+ type => 'payment',
+ interface => 'test',
}
);
my $write_off_amount = 25;
my $write_off = $account->add_credit(
{ amount => $write_off_amount,
- type => 'writeoff'
+ type => 'writeoff',
+ interface => 'test',
}
);
$write_off->apply( { debits => $lost_fee_lines->reset, offset_type => 'Writeoff' } );
my $payment_amount = 27;
my $payment = $account->add_credit(
{ amount => $payment_amount,
- type => 'payment'
+ type => 'payment',
+ interface => 'test',
}
);
$payment->apply({ debits => $lost_fee_lines->reset, offset_type => 'Payment' });
);
my $manual_debit_amount = 80;
- $account->add_debit( { amount => $manual_debit_amount, type => 'fine' } );
+ $account->add_debit( { amount => $manual_debit_amount, type => 'fine', interface =>'test' } );
is( $account->balance, $manual_debit_amount + $replacement_amount - $payment_amount, 'Manual debit applied' );
itemnumber => $item->itemnumber,
amount => 99.00,
amountoutstanding => 99.00,
+ interface => 'test',
}
)->store();
is( $issuingimpossible->{DEBT_GUARANTEES}, undef, "Patron can check out item" );
my $account = Koha::Account->new( { patron_id => $guarantee->{borrowernumber} } );
-$account->add_debit({ amount => 10.00, type => 'lost_item' });
+$account->add_debit({ amount => 10.00, type => 'lost_item', interface => 'test' });
( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->{barcode} );
is( $issuingimpossible->{DEBT_GUARANTEES} + 0, '10.00' + 0, "Patron cannot check out item due to debt for guarantee" );
my $schema = Koha::Database->new->schema;
my $builder = t::lib::TestBuilder->new;
+C4::Context->interface('commandline');
subtest 'new' => sub {
my $account = $patron->account;
my @generated_lines;
- push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1 })->store;
- push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2 })->store;
- push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3 })->store;
- push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4 })->store;
+ push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1, interface => 'commandline' })->store;
+ push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2, interface => 'commandline' })->store;
+ push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3, interface => 'commandline' })->store;
+ push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4, interface => 'commandline' })->store;
my $lines = $account->outstanding_debits();
my @lines_arr = $account->outstanding_debits();
$i++;
}
my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' });
- Koha::Account::Line->new({ borrowernumber => $patron_2->id, amountoutstanding => -2 })->store;
- my $just_one = Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => 3, amountoutstanding => 3 })->store;
- Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => -6, amountoutstanding => -6 })->store;
+ Koha::Account::Line->new({ borrowernumber => $patron_2->id, amountoutstanding => -2, interface => 'commandline' })->store;
+ my $just_one = Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => 3, amountoutstanding => 3, interface => 'commandline' })->store;
+ Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => -6, amountoutstanding => -6, interface => 'commandline' })->store;
$lines = $patron_2->account->outstanding_debits();
is( $lines->total_outstanding, 3, "Total if some outstanding debits and some credits is only debits" );
is( $lines->count, 1, "With 1 outstanding debits, we get back a Lines object with 1 lines" );
is_deeply( $the_line->unblessed, $lines->next->unblessed, "We get back the one correct line");
my $patron_3 = $builder->build_object({ class => 'Koha::Patrons' });
- Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => -2, amountoutstanding => -2 })->store;
- Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => -20, amountoutstanding => -20 })->store;
- Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => -200, amountoutstanding => -200 })->store;
+ Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => -2, amountoutstanding => -2, interface => 'commandline' })->store;
+ Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => -20, amountoutstanding => -20, interface => 'commandline' })->store;
+ Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => -200, amountoutstanding => -200, interface => 'commandline' })->store;
$lines = $patron_3->account->outstanding_debits();
is( $lines->total_outstanding, 0, "Total if no outstanding debits total is 0" );
is( $lines->count, 0, "With 0 outstanding debits, we get back a Lines object with 0 lines" );
is( $lines->count, 0, "With no outstanding debits, we get back a Lines object with 0 lines" );
# create a pathological credit with amountoutstanding > 0 (BZ 14591)
- Koha::Account::Line->new({ borrowernumber => $patron_4->id, amount => -3, amountoutstanding => 3 })->store();
+ Koha::Account::Line->new({ borrowernumber => $patron_4->id, amount => -3, amountoutstanding => 3, interface => 'commandline' })->store();
$lines = $account_4->outstanding_debits();
is( $lines->count, 0, 'No credits are confused with debits because of the amountoutstanding value' );
my $account = $patron->account;
my @generated_lines;
- push @generated_lines, $account->add_credit({ amount => 1 });
- push @generated_lines, $account->add_credit({ amount => 2 });
- push @generated_lines, $account->add_credit({ amount => 3 });
- push @generated_lines, $account->add_credit({ amount => 4 });
+ push @generated_lines, $account->add_credit({ amount => 1, interface => 'commandline' });
+ push @generated_lines, $account->add_credit({ amount => 2, interface => 'commandline' });
+ push @generated_lines, $account->add_credit({ amount => 3, interface => 'commandline' });
+ push @generated_lines, $account->add_credit({ amount => 4, interface => 'commandline' });
my $lines = $account->outstanding_credits();
my @lines_arr = $account->outstanding_credits();
is( $lines->count, 0, "With no outstanding credits, we get back a Lines object with 0 lines" );
# create a pathological debit with amountoutstanding < 0 (BZ 14591)
- Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => 2, amountoutstanding => -3 })->store();
+ Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => 2, amountoutstanding => -3, interface => 'commandline' })->store();
$lines = $account->outstanding_credits();
is( $lines->count, 0, 'No debits are confused with credits because of the amountoutstanding value' );
library_id => $patron->branchcode,
note => 'not really important',
type => 'payment',
- user_id => $patron->id
+ user_id => $patron->id,
+ interface => 'commandline'
}
);
library_id => $patron->branchcode,
note => 'not really important',
user_id => $patron->id,
- sip => $sip_code
+ sip => $sip_code,
+ interface => 'commandline'
}
);
description => 'Manual credit applied',
library_id => $patron->branchcode,
user_id => $patron->id,
- type => 'forgiven'
+ type => 'forgiven',
+ interface => 'commandline'
}
);
library_id => $patron->branchcode,
note => 'this should fail anyway',
type => 'rent',
- user_id => $patron->id
+ user_id => $patron->id,
+ interface => 'commandline'
}
); } 'Koha::Exceptions::Account::AmountNotPositive', 'Expected validation exception thrown (amount)';
library_id => $patron->branchcode,
note => 'this should fail anyway',
type => 'failure',
- user_id => $patron->id
+ user_id => $patron->id,
+ interface => 'commandline'
}
); } 'Koha::Exceptions::Account::UnrecognisedType', 'Expected validation exception thrown (type)';
library_id => $patron->branchcode,
note => 'not really important',
type => 'rent',
- user_id => $patron->id
+ user_id => $patron->id,
+ interface => 'commandline'
}
);
note => 'not really important',
type => 'rent',
user_id => $patron->id,
+ interface => 'commandline'
}
);
my @generated_lines;
# Add Credits
- push @generated_lines, $account->add_credit({ amount => 1 });
- push @generated_lines, $account->add_credit({ amount => 2 });
- push @generated_lines, $account->add_credit({ amount => 3 });
- push @generated_lines, $account->add_credit({ amount => 4 });
+ push @generated_lines, $account->add_credit({ amount => 1, interface => 'commandline' });
+ push @generated_lines, $account->add_credit({ amount => 2, interface => 'commandline' });
+ push @generated_lines, $account->add_credit({ amount => 3, interface => 'commandline' });
+ push @generated_lines, $account->add_credit({ amount => 4, interface => 'commandline' });
# Add Debits
- push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 1 })->store;
- push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 2 })->store;
- push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 3 })->store;
- push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 4 })->store;
+ push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 1, interface => 'commandline' })->store;
+ push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 2, interface => 'commandline' })->store;
+ push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 3, interface => 'commandline' })->store;
+ push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 4, interface => 'commandline' })->store;
# Paid Off
- push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 0 })->store;
- push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 0 })->store;
+ push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 0, interface => 'commandline' })->store;
+ push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 0, interface => 'commandline' })->store;
my $lines = $account->lines;
is( $lines->_resultset->count, 10, "All accountlines (debits, credits and paid off) were fetched");
my $account = $patron->account;
# Add Credits
- $account->add_credit({ amount => 1 });
- $account->add_credit({ amount => 2 });
- $account->add_credit({ amount => 3 });
- $account->add_credit({ amount => 4 });
- $account->add_credit({ amount => 5 });
+ $account->add_credit({ amount => 1, interface => 'commandline' });
+ $account->add_credit({ amount => 2, interface => 'commandline' });
+ $account->add_credit({ amount => 3, interface => 'commandline' });
+ $account->add_credit({ amount => 4, interface => 'commandline' });
+ $account->add_credit({ amount => 5, interface => 'commandline' });
# Add Debits TODO: replace for calls to add_debit when time comes
- Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1 })->store;
- Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2 })->store;
- Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3 })->store;
- Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4 })->store;
+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1, interface => 'commandline' })->store;
+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2, interface => 'commandline' })->store;
+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3, interface => 'commandline' })->store;
+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4, interface => 'commandline' })->store;
# Paid Off
- Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0 })->store;
- Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0 })->store;
+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0, interface => 'commandline' })->store;
+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0, interface => 'commandline' })->store;
is( $account->balance(), -5, "Account balance is -5" );
is( $account->outstanding_debits->total_outstanding, 10, 'Outstanding debits sum 10' );
my $account = $patron->account;
# Add Credits
- $account->add_credit({ amount => 1 });
- $account->add_credit({ amount => 2 });
- $account->add_credit({ amount => 3 });
- $account->add_credit({ amount => 4 });
+ $account->add_credit({ amount => 1, interface => 'commandline' });
+ $account->add_credit({ amount => 2, interface => 'commandline' });
+ $account->add_credit({ amount => 3, interface => 'commandline' });
+ $account->add_credit({ amount => 4, interface => 'commandline' });
# Add Debits TODO: replace for calls to add_debit when time comes
- Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1 })->store;
- Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2 })->store;
- Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3 })->store;
- Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4 })->store;
+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1, interface => 'commandline' })->store;
+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2, interface => 'commandline' })->store;
+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3, interface => 'commandline' })->store;
+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4, interface => 'commandline' })->store;
# Paid Off
- Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0 })->store;
- Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0 })->store;
+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0, interface => 'commandline' })->store;
+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0, interface => 'commandline' })->store;
is( $account->balance(), 0, "Account balance is 0" );
is( $account->outstanding_debits->total_outstanding, 10, 'Outstanding debits sum 10' );
my $account = $patron->account;
# Add Credits
- $account->add_credit({ amount => 1 });
- $account->add_credit({ amount => 2 });
- $account->add_credit({ amount => 3 });
- $account->add_credit({ amount => 4 });
+ $account->add_credit({ amount => 1, interface => 'commandline' });
+ $account->add_credit({ amount => 2, interface => 'commandline' });
+ $account->add_credit({ amount => 3, interface => 'commandline' });
+ $account->add_credit({ amount => 4, interface => 'commandline' });
# Add Debits TODO: replace for calls to add_debit when time comes
- Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1 })->store;
- Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2 })->store;
- Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3 })->store;
- Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4 })->store;
- Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 5, amountoutstanding => 5 })->store;
+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1, interface => 'commandline' })->store;
+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2, interface => 'commandline' })->store;
+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3, interface => 'commandline' })->store;
+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4, interface => 'commandline' })->store;
+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 5, amountoutstanding => 5, interface => 'commandline' })->store;
# Paid Off
- Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0 })->store;
- Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0 })->store;
+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0, interface => 'commandline' })->store;
+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0, interface => 'commandline' })->store;
is( $account->balance(), 5, "Account balance is 5" );
is( $account->outstanding_debits->total_outstanding, 15, 'Outstanding debits sum 15' );
my $account = $patron->account;
# Add Credits
- $account->add_credit({ amount => 1 });
- $account->add_credit({ amount => 3 });
+ $account->add_credit({ amount => 1, interface => 'commandline' });
+ $account->add_credit({ amount => 3, interface => 'commandline' });
# Add Debits TODO: replace for calls to add_debit when time comes
- my $debit_1 = Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1 })->store;
- my $debit_2 = Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2 })->store;
- my $debit_3 = Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3 })->store;
+ my $debit_1 = Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1, interface => 'commandline' })->store;
+ my $debit_2 = Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2, interface => 'commandline' })->store;
+ my $debit_3 = Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3, interface => 'commandline' })->store;
is( $account->balance(), 2, "Account balance is 2" );
is( $account->outstanding_debits->total_outstanding, 6, 'Outstanding debits sum 6' );
itemnumber => $item->itemnumber,
accounttype => "F",
amount => 10,
+ interface => 'commandline',
})->store;
my $account_line_item = $line->item;
{ borrowernumber => $patron->id,
accounttype => "F",
amount => 10,
- amountoutstanding => 10
+ amountoutstanding => 10,
+ interface => 'commandline',
}
)->store;
{ borrowernumber => $patron->id,
accounttype => "F",
amount => 10,
- amountoutstanding => 10
+ amountoutstanding => 10,
+ interface => 'commandline',
}
)->store;
{ borrowernumber => $patron->id,
accounttype => "F",
amount => -10,
- amountoutstanding => -10
+ amountoutstanding => -10,
+ interface => 'commandline',
}
)->store;
{ borrowernumber => $patron->id,
accounttype => "F",
amount => -10,
- amountoutstanding => -10
+ amountoutstanding => -10,
+ interface => 'commandline',
}
)->store;
{ borrowernumber => $patron->id,
accounttype => "F",
amount => -100,
- amountoutstanding => -100
+ amountoutstanding => -100,
+ interface => 'commandline',
}
)->store;
my $patron = $builder->build_object({ class => 'Koha::Patrons' });
my $account = $patron->account;
- my $credit = $account->add_credit({ amount => 100, user_id => $patron->id });
+ my $credit = $account->add_credit({ amount => 100, user_id => $patron->id, interface => 'commandline' });
ok( $credit->is_credit, 'is_credit detects credits' );
ok( !$credit->is_debit, 'is_debit detects credits' );
borrowernumber => $patron->id,
accounttype => "F",
amount => 10,
+ interface => 'commandline',
})->store;
ok( !$debit->is_credit, 'is_credit detects debits' );
my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
my $account = $patron->account;
- my $credit = $account->add_credit( { amount => 100, user_id => $patron->id } );
+ my $credit = $account->add_credit( { amount => 100, user_id => $patron->id, interface => 'commandline' } );
my $debit_1 = Koha::Account::Line->new(
{ borrowernumber => $patron->id,
accounttype => "F",
amount => 10,
- amountoutstanding => 10
+ amountoutstanding => 10,
+ interface => 'commandline',
}
)->store;
{ borrowernumber => $patron->id,
accounttype => "F",
amount => 100,
- amountoutstanding => 100
+ amountoutstanding => 100,
+ interface => 'commandline',
}
)->store;
'->apply() can only be used with credits';
$debits = Koha::Account::Lines->search({ accountlines_id => $credit->id });
- my $credit_3 = $account->add_credit({ amount => 1 });
+ my $credit_3 = $account->add_credit({ amount => 1, interface => 'commandline' });
throws_ok
{ $credit_3->apply({ debits => $debits }); }
'Koha::Exceptions::Account::IsNotDebit',
'->apply() can only be applied to credits';
- my $credit_2 = $account->add_credit({ amount => 20 });
+ my $credit_2 = $account->add_credit({ amount => 20, interface => 'commandline' });
my $debit_3 = Koha::Account::Line->new(
{ borrowernumber => $patron->id,
accounttype => "F",
amount => 100,
- amountoutstanding => 100
+ amountoutstanding => 100,
+ interface => 'commandline',
}
)->store;
itemnumber => $item->itemnumber,
accounttype => "F",
amount => 10,
+ interface => 'commandline',
})->store;
$issue->delete;
{ borrowernumber => $patron->id,
accounttype => "F",
amount => 10,
- amountoutstanding => 10
+ amountoutstanding => 10,
+ interface => 'commandline',
}
)->store;
{ borrowernumber => $patron->id,
accounttype => "FU",
amount => 100,
- amountoutstanding => 100
+ amountoutstanding => 100,
+ interface => 'commandline'
}
)->store;
- my $credit = $account->add_credit( { amount => 40, user_id => $patron->id } );
+ my $credit = $account->add_credit( { amount => 40, user_id => $patron->id, interface => 'commandline' } );
- throws_ok { $debit_1->adjust( { amount => 50, type => 'bad' } ) }
+ throws_ok { $debit_1->adjust( { amount => 50, type => 'bad', interface => 'commandline' } ) }
qr/Update type not recognised/, 'Exception thrown for unrecognised type';
- throws_ok { $debit_1->adjust( { amount => 50, type => 'fine_update' } ) }
+ throws_ok { $debit_1->adjust( { amount => 50, type => 'fine_update', interface => 'commandline' } ) }
qr/Update type not allowed on this accounttype/,
'Exception thrown for type conflict';
# Increment an unpaid fine
- $debit_2->adjust( { amount => 150, type => 'fine_update' } )->discard_changes;
+ $debit_2->adjust( { amount => 150, type => 'fine_update', interface => 'commandline' } )->discard_changes;
is( $debit_2->amount * 1, 150, 'Fine amount was updated in full' );
is( $debit_2->amountoutstanding * 1, 150, 'Fine amountoutstanding was update in full' );
t::lib::Mocks::mock_preference( 'FinesLog', 1 );
# Increment the partially paid fine
- $debit_2->adjust( { amount => 160, type => 'fine_update' } )->discard_changes;
+ $debit_2->adjust( { amount => 160, type => 'fine_update', interface => 'commandline' } )->discard_changes;
is( $debit_2->amount * 1, 160, 'Fine amount was updated in full' );
is( $debit_2->amountoutstanding * 1, 120, 'Fine amountoutstanding was updated by difference' );
is( $schema->resultset('ActionLog')->count(), $action_logs + 1, 'Log was added' );
# Decrement the partially paid fine, less than what was paid
- $debit_2->adjust( { amount => 50, type => 'fine_update' } )->discard_changes;
+ $debit_2->adjust( { amount => 50, type => 'fine_update', interface => 'commandline' } )->discard_changes;
is( $debit_2->amount * 1, 50, 'Fine amount was updated in full' );
is( $debit_2->amountoutstanding * 1, 10, 'Fine amountoutstanding was updated by difference' );
is( $THIS_offset->type, 'fine_decrease', 'Adjust type stored correctly' );
# Decrement the partially paid fine, more than what was paid
- $debit_2->adjust( { amount => 30, type => 'fine_update' } )->discard_changes;
+ $debit_2->adjust( { amount => 30, type => 'fine_update', interface => 'commandline' } )->discard_changes;
is( $debit_2->amount * 1, 30, 'Fine amount was updated in full' );
is( $debit_2->amountoutstanding * 1, 0, 'Fine amountoutstanding was zeroed (payment was 40)' );
my $checkout = AddIssue( $patron->unblessed, $item->barcode );
my $line = $account->add_debit({
- amount => 10,
- item_id => $item->itemnumber,
- issue_id => $checkout->issue_id,
- type => 'fine',
+ amount => 10,
+ interface => 'commandline',
+ item_id => $item->itemnumber,
+ issue_id => $checkout->issue_id,
+ type => 'fine',
});
my $line_checkout = $line->checkout;
accounttype => "N", # New card
amountoutstanding => 50,
manager_id => $patron->borrowernumber,
- branchcode => $library->id
+ branchcode => $library->id,
+ interface => 'test',
}
)->store();
$account_line_1->discard_changes;
accounttype => "N", # New card
amountoutstanding => 50.01,
manager_id => $patron->borrowernumber,
- branchcode => $library->id
+ branchcode => $library->id,
+ interface => 'test',
}
)->store();
$account_line_2->discard_changes;
# add a credit
my $credit_line = $account->add_credit(
- { amount => 10, user_id => $patron->id, library_id => $library->id } );
+ { amount => 10, user_id => $patron->id, library_id => $library->id, interface => 'test' } );
# re-read from the DB
$credit_line->discard_changes;
$tx = $t->ua->build_tx( GET => "/api/v1/patrons/$patron_id/account" );
accounttype => "N", # New card
amountoutstanding => 10,
manager_id => $patron->borrowernumber,
+ interface => 'test',
}
)->store();
my $debit_2 = Koha::Account::Line->new(
accounttype => "N", # New card
amountoutstanding => 15,
manager_id => $patron->borrowernumber,
+ interface => 'test',
}
)->store();
accounttype => "N", # New card
amountoutstanding => 100,
manager_id => $patron->borrowernumber,
+ interface => 'test',
}
)->store();