From 5466ed842b0b1dddb524f8dd3633fb81d3b3e6fd Mon Sep 17 00:00:00 2001 From: charles Date: Wed, 22 Apr 2015 15:54:04 -0400 Subject: [PATCH] Bug 12768 - Replacement cost and processing fee management Signed-off-by: Eivin Giske Skaaren Signed-off-by: Kyle M Hall --- C4/Accounts.pm | 77 ++++++----- C4/Circulation.pm | 6 +- admin/itemtypes.pl | 28 ++-- ...-replacement_cost_processing_fee_management.sql | 2 + installer/data/mysql/sysprefs.sql | 2 + koha-tmpl/intranet-tmpl/prog/css/staff-global.css | 3 + .../prog/en/modules/admin/itemtypes.tt | 14 +- .../en/modules/admin/preferences/circulation.pref | 11 ++ t/db_dependent/Accounts.t | 143 ++++++++++++++++++++- t/db_dependent/Circulation.t | 3 +- t/db_dependent/Circulation/Chargelostitem.t | 84 ++++++++++++ 11 files changed, 317 insertions(+), 56 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_12768-replacement_cost_processing_fee_management.sql create mode 100644 t/db_dependent/Circulation/Chargelostitem.t diff --git a/C4/Accounts.pm b/C4/Accounts.pm index c7b8191..df679a8 100644 --- a/C4/Accounts.pm +++ b/C4/Accounts.pm @@ -27,6 +27,7 @@ use C4::Circulation qw(ReturnLostItem); use C4::Log qw(logaction); use Koha::Account; use Koha::Account::Lines; +use Koha::Items; use Data::Dumper qw(Dumper); @@ -125,41 +126,31 @@ sub chargelostitem{ # FIXME : if no replacement price, borrower just doesn't get charged? my $dbh = C4::Context->dbh(); my ($borrowernumber, $itemnumber, $amount, $description) = @_; - + my $itype = Koha::ItemTypes->find({ itemtype => Koha::Items->find($itemnumber)->effective_itemtype() }); + my $replacementprice = $amount; + my $defaultreplacecost = $itype->defaultreplacecost; + my $processfee = $itype->processfee; + my $usedefaultreplacementcost = C4::Context->preference("useDefaultReplacementCost"); + my $processingfeenote = C4::Context->preference("ProcessingFeeNote"); + if ($usedefaultreplacementcost && $amount == 0 && $defaultreplacecost){ + $replacementprice = $defaultreplacecost; + } # first make sure the borrower hasn't already been charged for this item my $sth1=$dbh->prepare("SELECT * from accountlines WHERE borrowernumber=? AND itemnumber=? and accounttype='L'"); $sth1->execute($borrowernumber,$itemnumber); my $existing_charge_hashref=$sth1->fetchrow_hashref(); - # OK, they haven't unless ($existing_charge_hashref) { - my $manager_id = 0; - $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; - # This item is on issue ... add replacement cost to the borrower's record and mark it returned - # Note that we add this to the account even if there's no replacement price, allowing some other - # process (or person) to update it, since we don't handle any defaults for replacement prices. - my $accountno = getnextacctno($borrowernumber); - my $sth2=$dbh->prepare("INSERT INTO accountlines - (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber,manager_id) - VALUES (?,?,now(),?,?,'L',?,?,?)"); - $sth2->execute($borrowernumber,$accountno,$amount, - $description,$amount,$itemnumber,$manager_id); - - if ( C4::Context->preference("FinesLog") ) { - logaction("FINES", 'CREATE', $borrowernumber, Dumper({ - action => 'create_fee', - borrowernumber => $borrowernumber, - accountno => $accountno, - amount => $amount, - amountoutstanding => $amount, - description => $description, - accounttype => 'L', - itemnumber => $itemnumber, - manager_id => $manager_id, - })); - } + #add processing fee + if ($processfee && $processfee > 0){ + manualinvoice($borrowernumber, $itemnumber, $description, 'PF', $processfee, $processingfeenote, 1); + } + #add replace cost + if ($replacementprice > 0){ + manualinvoice($borrowernumber, $itemnumber, $description, 'L', $replacementprice, undef, 1); + } } } @@ -190,7 +181,7 @@ should be the empty string. # sub manualinvoice { - my ( $borrowernumber, $itemnum, $desc, $type, $amount, $note ) = @_; + my ( $borrowernumber, $itemnum, $desc, $type, $amount, $note, $skip_notify ) = @_; my $manager_id = 0; $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; my $dbh = C4::Context->dbh; @@ -198,6 +189,7 @@ sub manualinvoice { my $insert; my $accountno = getnextacctno($borrowernumber); my $amountleft = $amount; + $skip_notify //= 0; if ( ( $type eq 'L' ) or ( $type eq 'F' ) @@ -205,7 +197,7 @@ sub manualinvoice { or ( $type eq 'N' ) or ( $type eq 'M' ) ) { - $notifyid = 1; + $notifyid = 1 unless $skip_notify; } if ( $itemnum ) { @@ -244,19 +236,26 @@ sub manualinvoice { } sub getcharges { - my ( $borrowerno, $timestamp, $accountno ) = @_; - my $dbh = C4::Context->dbh; - my $timestamp2 = $timestamp - 1; - my $query = ""; - my $sth = $dbh->prepare( - "SELECT * FROM accountlines WHERE borrowernumber=? AND accountno = ?" - ); - $sth->execute( $borrowerno, $accountno ); + my ( $borrowerno, $accountno ) = @_; + my $dbh = C4::Context->dbh; + + my @params; + + my $query = "SELECT * FROM accountlines WHERE borrowernumber = ?"; + push( @params, $borrowerno ); + + if ( $accountno ) { + $query .= " AND accountno = ?"; + push( @params, $accountno ); + } + + my $sth = $dbh->prepare( $query ); + $sth->execute( @params ); my @results; while ( my $data = $sth->fetchrow_hashref ) { - push @results,$data; - } + push @results,$data; + } return (@results); } diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 75c3814..230b9eb 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -3617,9 +3617,9 @@ sub LostItem{ my ($itemnumber, $mark_returned) = @_; my $dbh = C4::Context->dbh(); - my $sth=$dbh->prepare("SELECT issues.*,items.*,biblio.title - FROM issues - JOIN items USING (itemnumber) + my $sth=$dbh->prepare("SELECT issues.*,items.*,biblio.title + FROM issues + JOIN items USING (itemnumber) JOIN biblio USING (biblionumber) WHERE issues.itemnumber=?"); $sth->execute($itemnumber); diff --git a/admin/itemtypes.pl b/admin/itemtypes.pl index 09e564e..cc790df 100755 --- a/admin/itemtypes.pl +++ b/admin/itemtypes.pl @@ -72,6 +72,8 @@ if ( $op eq 'add_form' ) { my $itemtype = Koha::ItemTypes->find($itemtype_code); my $description = $input->param('description'); my $rentalcharge = $input->param('rentalcharge'); + my $defaultreplacecost = $input->param('defaultreplacecost'); + my $processfee = $input->param('processfee'); my $image = $input->param('image') || q||; my $notforloan = $input->param('notforloan') ? 1 : 0; @@ -90,6 +92,8 @@ if ( $op eq 'add_form' ) { if ( $itemtype and $is_a_modif ) { # it's a modification $itemtype->description($description); $itemtype->rentalcharge($rentalcharge); + $itemtype->defaultreplacecost($defaultreplacecost); + $itemtype->processfee($processfee); $itemtype->notforloan($notforloan); $itemtype->imageurl($imageurl); $itemtype->summary($summary); @@ -108,17 +112,19 @@ if ( $op eq 'add_form' ) { } } elsif ( not $itemtype and not $is_a_modif ) { my $itemtype = Koha::ItemType->new( - { itemtype => $itemtype_code, - description => $description, - rentalcharge => $rentalcharge, - notforloan => $notforloan, - imageurl => $imageurl, - summary => $summary, - checkinmsg => $checkinmsg, - checkinmsgtype => $checkinmsgtype, - sip_media_type => $sip_media_type, - hideinopac => $hideinopac, - searchcategory => $searchcategory, + { itemtype => $itemtype_code, + description => $description, + rentalcharge => $rentalcharge, + defaultreplacecost => $defaultreplacecost, + processfee => $processfee, + notforloan => $notforloan, + imageurl => $imageurl, + summary => $summary, + checkinmsg => $checkinmsg, + checkinmsgtype => $checkinmsgtype, + sip_media_type => $sip_media_type, + hideinopac => $hideinopac, + searchcategory => $searchcategory, } ); eval { $itemtype->store; }; diff --git a/installer/data/mysql/atomicupdate/bug_12768-replacement_cost_processing_fee_management.sql b/installer/data/mysql/atomicupdate/bug_12768-replacement_cost_processing_fee_management.sql new file mode 100644 index 0000000..9b27966 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_12768-replacement_cost_processing_fee_management.sql @@ -0,0 +1,2 @@ +INSERT INTO systempreferences (variable,value,explanation,type) VALUES ('useDefaultReplacementCost',0,'default replacement cost defined in item type','YesNo'); +INSERT INTO systempreferences (variable,value,explanation,type) VALUES ('ProcessingFeeNote','','Set the text to be recorded in the column note, table accountlines when the processing fee (defined in item type) is applied','textarea'); diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 5155fe7..b80e6e1 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -432,6 +432,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('previousIssuesDefaultSortOrder','asc','asc|desc','Specify the sort order of Previous Issues on the circulation page','Choice'), ('printcirculationslips','1','','If ON, enable printing circulation receipts','YesNo'), ('PrintNoticesMaxLines','0','','If greater than 0, sets the maximum number of lines an overdue notice will print. If the number of items is greater than this number, the notice will end with a warning asking the borrower to check their online account for a full list of overdue items.','Integer'), +('ProcessingFeeNote', '', NULL, 'Set the text to be recorded in the column note, table accountlines when the processing fee (defined in item type) is applied', 'textarea'), ('QueryAutoTruncate','1',NULL,'If ON, query truncation is enabled by default','YesNo'), ('QueryFuzzy','1',NULL,'If ON, enables fuzzy option for searches','YesNo'), ('QueryStemming','1',NULL,'If ON, enables query stemming','YesNo'), @@ -569,6 +570,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('UseControlNumber','0','','If ON, record control number (w subfields) and control number (001) are used for linking of bibliographic records.','YesNo'), ('UseCourseReserves','0',NULL,'Enable the course reserves feature.','YesNo'), ('useDaysMode','Calendar','Calendar|Days|Datedue','Choose the method for calculating due date: select Calendar to use the holidays module, and Days to ignore the holidays module','Choice'), +('useDefaultReplacementCost', '0', NULL, 'default replacement cost defined in item type', 'YesNo'), ('useDischarge','','','Allows librarians to discharge borrowers and borrowers to request a discharge','YesNo'), ('UseICU','0','1','Tell Koha if ICU indexing is in use for Zebra or not.','YesNo'), ('UseKohaPlugins','0','','Enable or disable the ability to use Koha Plugins.','YesNo'), diff --git a/koha-tmpl/intranet-tmpl/prog/css/staff-global.css b/koha-tmpl/intranet-tmpl/prog/css/staff-global.css index fb09d51..128b7fa 100644 --- a/koha-tmpl/intranet-tmpl/prog/css/staff-global.css +++ b/koha-tmpl/intranet-tmpl/prog/css/staff-global.css @@ -687,6 +687,9 @@ fieldset.rows fieldset { .yui-b fieldset.rows td label, .yui-b fieldset.rows td span.label { width: auto; } +.yui-b fieldset.rows ol.oladditemtype label, .yui-b fieldset.rows ol.oladditemtype span.label { + width: 13em; +} .yui-b fieldset.rows div.hint { margin-left : 10.5em; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt index 0d07187..a622428 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt @@ -235,7 +235,7 @@ Item types administration [% END %] -
    +
    1. [% IF ( itemtype.hideinopac ) %] @@ -259,6 +259,14 @@ Item types administration
    2. + + +
    3. +
    4. + + +
    5. +
    6. @@ -348,6 +356,8 @@ Item types administration Not for loan Hide in OPAC Charge + Default replacement cost + Processing fee (when lost) Checkin message Actions @@ -387,6 +397,8 @@ Item types administration [% itemtype.rentalcharge | $Price %] [% END %] + [% itemtype.defaultreplacecost | $Price %] + [% itemtype.processfee | $Price %] [% itemtype.checkinmsg | html_line_break %] Edit diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref index 90b2844..9f847c5 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref @@ -740,6 +740,17 @@ Circulation: any_time_is_placed: "any time a hold is placed." not_always: "only if all items are checked out and the record has at least one hold already." any_time_is_collected: "any time a hold is collected." + - pref: useDefaultReplacementCost + choices: + yes: use + no: "Don't use" + - the default replacement cost defined in item type. + - + - "Set the text to be recorded in the column 'note', table 'accountlines' when the processing fee (defined in item type) is applied." + - pref: ProcessingFeeNote + type: textarea + class: code + Self Checkout: - - "Include the following JavaScript on all pages in the web-based self checkout:" diff --git a/t/db_dependent/Accounts.t b/t/db_dependent/Accounts.t index be2b265..6bc1c20 100644 --- a/t/db_dependent/Accounts.t +++ b/t/db_dependent/Accounts.t @@ -18,11 +18,12 @@ use Modern::Perl; -use Test::More tests => 22; +use Test::More tests => 23; use Test::MockModule; use Test::Warn; use t::lib::TestBuilder; +use t::lib::Mocks; use Koha::Account; use Koha::Account::Lines; @@ -478,3 +479,143 @@ subtest 'balance' => sub { $patron->delete; }; +subtest "Koha::Account::chargelostitem tests" => sub { + plan tests => 32; + + my $lostfine; + my $procfee; + + my $itype_no_replace_no_fee = $builder->build({ source => 'Itemtype', value => { + rentalcharge => 0, + defaultreplacecost => undef, + processfee => undef, + }}); + my $itype_replace_no_fee = $builder->build({ source => 'Itemtype', value => { + rentalcharge => 0, + defaultreplacecost => 16.32, + processfee => undef, + }}); + my $itype_no_replace_fee = $builder->build({ source => 'Itemtype', value => { + rentalcharge => 0, + defaultreplacecost => undef, + processfee => 8.16, + }}); + my $itype_replace_fee = $builder->build({ source => 'Itemtype', value => { + rentalcharge => 0, + defaultreplacecost => 4.08, + 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 $duck = Koha::Items->find({itemnumber=>$cli_itemnumber1}); + + t::lib::Mocks::mock_preference('item-level_itypes', '1'); + t::lib::Mocks::mock_preference('useDefaultReplacementCost', '0'); + + C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 0, "Perdedor"); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'L' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'PF' }); + ok( !$lostfine, "No lost fine if no replacementcost or default when pref off"); + ok( !$procfee, "No processing fee if no processing fee"); + C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 6.12, "Perdedor"); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'L' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'PF' }); + ok( $lostfine->amount == 6.12, "Lost fine equals replacementcost when pref off and no default set"); + ok( !$procfee, "No processing fee if no processing fee"); + $lostfine->delete(); + + C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 0, "Perdedor"); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'L' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'PF' }); + ok( !$lostfine, "No lost fine if no replacementcost but default set when pref off"); + ok( !$procfee, "No processing fee if no processing fee"); + C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 6.12, "Perdedor"); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'L' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'PF' }); + ok( $lostfine->amount == 6.12 , "Lost fine equals replacementcost when pref off and default set"); + ok( !$procfee, "No processing fee if no processing fee"); + $lostfine->delete(); + + C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 0, "Perdedor"); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'L' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'PF' }); + ok( !$lostfine, "No lost fine if no replacementcost and no default set when pref off"); + ok( $procfee->amount == 8.16, "Processing fee if processing fee"); + $procfee->delete(); + C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 6.12, "Perdedor"); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'L' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'PF' }); + ok( $lostfine->amount == 6.12 , "Lost fine equals replacementcost when pref off and no default set"); + ok( $procfee->amount == 8.16, "Processing fee if processing fee"); + $lostfine->delete(); + $procfee->delete(); + + C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 0, "Perdedor"); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'L' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' }); + ok( !$lostfine, "No lost fine if no replacementcost but default set when pref off"); + ok( $procfee->amount == 2.04, "Processing fee if processing fee"); + $procfee->delete(); + C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 6.12, "Perdedor"); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'L' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' }); + ok( $lostfine->amount == 6.12 , "Lost fine equals replacementcost when pref off and default set"); + ok( $procfee->amount == 2.04, "Processing fee if processing fee"); + $lostfine->delete(); + $procfee->delete(); + + t::lib::Mocks::mock_preference('useDefaultReplacementCost', '1'); + + C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 0, "Perdedor"); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'L' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'PF' }); + ok( !$lostfine, "No lost fine if no replacementcost or default when pref on"); + ok( !$procfee, "No processing fee if no processing fee"); + C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 6.12, "Perdedor"); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'L' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'PF' }); + is( $lostfine->amount, "6.120000", "Lost fine equals replacementcost when pref on and no default set"); + ok( !$procfee, "No processing fee if no processing fee"); + + C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 0, "Perdedor"); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'L' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'PF' }); + is( $lostfine->amount(), "16.320000", "Lost fine is default if no replacementcost but default set when pref on"); + ok( !$procfee, "No processing fee if no processing fee"); + $lostfine->delete(); + C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 6.12, "Perdedor"); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'L' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'PF' }); + is( $lostfine->amount, "6.120000" , "Lost fine equals replacementcost when pref on and default set"); + ok( !$procfee, "No processing fee if no processing fee"); + + C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 0, "Perdedor"); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'L' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'PF' }); + ok( !$lostfine, "No lost fine if no replacementcost and default not set when pref on"); + is( $procfee->amount, "8.160000", "Processing fee if processing fee"); + $procfee->delete(); + C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 6.12, "Perdedor"); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'L' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'PF' }); + is( $lostfine->amount, "6.120000", "Lost fine equals replacementcost when pref on and no default set"); + is( $procfee->amount, "8.160000", "Processing fee if processing fee"); + + C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 0, "Perdedor"); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'L' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' }); + is( $lostfine->amount, "4.080000", "Lost fine is default if no replacementcost but default set when pref on"); + is( $procfee->amount, "2.040000", "Processing fee if processing fee"); + $lostfine->delete(); + $procfee->delete(); + C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 6.12, "Perdedor"); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'L' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' }); + is( $lostfine->amount, "6.120000", "Lost fine equals replacementcost when pref on and default set"); + is( $procfee->amount, "2.040000", "Processing fee if processing fee"); +}; + +1; diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 7f85ad6..49b8019 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -57,7 +57,7 @@ my $library2 = $builder->build({ }); my $itemtype = $builder->build( { source => 'Itemtype', - value => { notforloan => undef, rentalcharge => 0 } + value => { notforloan => undef, rentalcharge => 0, defaultreplacecost => undef, processfee => undef } } )->{itemtype}; my $patron_category = $builder->build({ source => 'Category', value => { enrolmentfee => 0 } }); @@ -767,6 +767,7 @@ C4::Context->dbh->do("DELETE FROM accountlines"); } ); + ModItem({ itype => 'BK' }, $biblionumber, $itemnumber, 1); LostItem( $itemnumber, 1 ); my $item = Koha::Database->new()->schema()->resultset('Item')->find($itemnumber); diff --git a/t/db_dependent/Circulation/Chargelostitem.t b/t/db_dependent/Circulation/Chargelostitem.t new file mode 100644 index 0000000..b19386a --- /dev/null +++ b/t/db_dependent/Circulation/Chargelostitem.t @@ -0,0 +1,84 @@ +#!/usr/bin/perl + +use Modern::Perl; + +use Test::MockModule; +use C4::Biblio; +use C4::Items; +use C4::Members; +use C4::Branch; +use C4::Category; +use C4::Circulation; +use MARC::Record; +use Test::More tests => 7; + +BEGIN { + use_ok('C4::Accounts'); +} + +my $dbh = C4::Context->dbh; +$dbh->{AutoCommit} = 0; +$dbh->{RaiseError} = 1; +$dbh->do(q|DELETE FROM accountlines|); + +my $branchcode; +my $branch_created; +my @branches = keys %{ GetBranches() }; +if (@branches) { + $branchcode = $branches[0]; +} else { + $branchcode = 'B'; + ModBranch({ add => 1, branchcode => $branchcode, branchname => 'Branch' }); + $branch_created = 1; +} + +my %item_branch_infos = ( + homebranch => $branchcode, + holdingbranch => $branchcode, +); + +my ($biblionumber1) = AddBiblio(MARC::Record->new, ''); +my $itemnumber1 = AddItem({ barcode => '0101', %item_branch_infos }, $biblionumber1); +my $itemnumber2 = AddItem({ barcode => '0102', %item_branch_infos }, $biblionumber1); + +my ($biblionumber2) = AddBiblio(MARC::Record->new, ''); +my $itemnumber3 = AddItem({ barcode => '0203', %item_branch_infos }, $biblionumber2); + +my $categorycode; +my $category_created; +my @categories = C4::Category->all; +if (@categories) { + $categorycode = $categories[0]->{categorycode} +} else { + $categorycode = 'C'; + $dbh->do( + "INSERT INTO categories(categorycode) VALUES(?)", undef, $categorycode); + $category_created = 1; +} + +my $borrowernumber = AddMember(categorycode => $categorycode, branchcode => $branchcode); +my $borrower = GetMember(borrowernumber => $borrowernumber); + +# Need to mock userenv for AddIssue +my $module = new Test::MockModule('C4::Context'); +$module->mock('userenv', sub { { branch => $branchcode } }); +AddIssue($borrower, '0101'); +AddIssue($borrower, '0203'); + +# Begin tests... +my $processfee = 10; +my $issues; +$issues = C4::Circulation::GetIssues({biblionumber => $biblionumber1}); +my $issue=$issues->[0]; +$issue->{'processfee'} = $processfee; +C4::Accounts::chargelostitem($issue, 'test'); + +my @accountline = C4::Accounts::getcharges($borrowernumber); + +is( scalar(@accountline), 1, 'accountline should have 1 row' ); +is( int($accountline[0]->{amount}), $processfee, "The accountline amount should be precessfee value " ); +is( $accountline[0]->{accounttype}, 'PF', "The accountline accounttype should be PF " ); +is( $accountline[0]->{borrowernumber}, $borrowernumber, "The accountline borrowernumber should be the example borrowernumber" ); +my $itemnumber = C4::Items::GetItemnumberFromBarcode('0101'); +is( $accountline[0]->{itemnumber}, $itemnumber, "The accountline itemnumber should the linked with barcode '0101'" ); +is( $accountline[0]->{description}, 'test ' . $issue->{itemnumber}, "The accountline description should be 'test'" ); -- 2.10.2