View | Details | Raw Unified | Return to bug 12768
Collapse All | Expand All

(-)a/C4/Accounts.pm (-13 / +38 lines)
Lines 28-33 use C4::Log qw(logaction); Link Here
28
use Koha::Account;
28
use Koha::Account;
29
use Koha::Account::Lines;
29
use Koha::Account::Lines;
30
use Koha::Account::Offsets;
30
use Koha::Account::Offsets;
31
use Koha::Items;
31
32
32
use Data::Dumper qw(Dumper);
33
use Data::Dumper qw(Dumper);
33
34
Lines 134-140 FIXME : if no replacement price, borrower just doesn't get charged? Link Here
134
sub chargelostitem{
135
sub chargelostitem{
135
    my $dbh = C4::Context->dbh();
136
    my $dbh = C4::Context->dbh();
136
    my ($borrowernumber, $itemnumber, $amount, $description) = @_;
137
    my ($borrowernumber, $itemnumber, $amount, $description) = @_;
137
138
    my $itype = Koha::ItemTypes->find({ itemtype => Koha::Items->find($itemnumber)->effective_itemtype() });
139
    my $replacementprice = $amount;
140
    my $defaultreplacecost = $itype->defaultreplacecost;
141
    my $processfee = $itype->processfee;
142
    my $usedefaultreplacementcost = C4::Context->preference("useDefaultReplacementCost");
143
    my $processingfeenote = C4::Context->preference("ProcessingFeeNote");
144
    if ($usedefaultreplacementcost && $amount == 0 && $defaultreplacecost){
145
        $replacementprice = $defaultreplacecost;
146
    }
138
    # first make sure the borrower hasn't already been charged for this item
147
    # first make sure the borrower hasn't already been charged for this item
139
    my $existing_charges = Koha::Account::Lines->search(
148
    my $existing_charges = Koha::Account::Lines->search(
140
        {
149
        {
Lines 189-194 sub chargelostitem{ Link Here
189
            }));
198
            }));
190
        }
199
        }
191
200
201
        #add processing fee
202
        if ($processfee && $processfee > 0){
203
            manualinvoice($borrowernumber, $itemnumber, $description, 'PF', $processfee, $processingfeenote, 1);
204
        }
205
        #add replace cost
206
        if ($replacementprice > 0){
207
            manualinvoice($borrowernumber, $itemnumber, $description, 'L', $replacementprice, undef, 1);
208
        }
192
    }
209
    }
193
}
210
}
194
211
Lines 219-225 should be the empty string. Link Here
219
#
236
#
220
237
221
sub manualinvoice {
238
sub manualinvoice {
222
    my ( $borrowernumber, $itemnum, $desc, $type, $amount, $note ) = @_;
239
    my ( $borrowernumber, $itemnum, $desc, $type, $amount, $note, $skip_notify ) = @_;
223
    my $manager_id = 0;
240
    my $manager_id = 0;
224
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
241
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
225
    my $dbh      = C4::Context->dbh;
242
    my $dbh      = C4::Context->dbh;
Lines 227-232 sub manualinvoice { Link Here
227
    my $insert;
244
    my $insert;
228
    my $accountno  = getnextacctno($borrowernumber);
245
    my $accountno  = getnextacctno($borrowernumber);
229
    my $amountleft = $amount;
246
    my $amountleft = $amount;
247
    $skip_notify //= 0;
230
248
231
    if (   ( $type eq 'L' )
249
    if (   ( $type eq 'L' )
232
        or ( $type eq 'F' )
250
        or ( $type eq 'F' )
Lines 234-240 sub manualinvoice { Link Here
234
        or ( $type eq 'N' )
252
        or ( $type eq 'N' )
235
        or ( $type eq 'M' ) )
253
        or ( $type eq 'M' ) )
236
    {
254
    {
237
        $notifyid = 1;
255
        $notifyid = 1 unless $skip_notify;
238
    }
256
    }
239
257
240
    my $accountline = Koha::Account::Line->new(
258
    my $accountline = Koha::Account::Line->new(
Lines 281-299 sub manualinvoice { Link Here
281
}
299
}
282
300
283
sub getcharges {
301
sub getcharges {
284
	my ( $borrowerno, $timestamp, $accountno ) = @_;
302
    my ( $borrowerno, $accountno ) = @_;
285
	my $dbh        = C4::Context->dbh;
303
    my $dbh = C4::Context->dbh;
286
	my $timestamp2 = $timestamp - 1;
304
287
	my $query      = "";
305
    my @params;
288
	my $sth = $dbh->prepare(
306
289
			"SELECT * FROM accountlines WHERE borrowernumber=? AND accountno = ?"
307
    my $query = "SELECT * FROM accountlines WHERE borrowernumber = ?";
290
          );
308
    push( @params, $borrowerno );
291
	$sth->execute( $borrowerno, $accountno );
309
310
    if ( $accountno ) {
311
        $query .= " AND accountno = ?";
312
        push( @params, $accountno );
313
    }
314
315
    my $sth = $dbh->prepare( $query );
316
    $sth->execute( @params );
292
	
317
	
293
    my @results;
318
    my @results;
294
    while ( my $data = $sth->fetchrow_hashref ) {
319
    while ( my $data = $sth->fetchrow_hashref ) {
295
		push @results,$data;
320
        push @results,$data;
296
	}
321
    }
297
    return (@results);
322
    return (@results);
298
}
323
}
299
324
(-)a/admin/itemtypes.pl (-11 / +17 lines)
Lines 72-77 if ( $op eq 'add_form' ) { Link Here
72
    my $itemtype     = Koha::ItemTypes->find($itemtype_code);
72
    my $itemtype     = Koha::ItemTypes->find($itemtype_code);
73
    my $description  = $input->param('description');
73
    my $description  = $input->param('description');
74
    my $rentalcharge = $input->param('rentalcharge');
74
    my $rentalcharge = $input->param('rentalcharge');
75
    my $defaultreplacecost = $input->param('defaultreplacecost');
76
    my $processfee = $input->param('processfee');
75
    my $image = $input->param('image') || q||;
77
    my $image = $input->param('image') || q||;
76
78
77
    my $notforloan = $input->param('notforloan') ? 1 : 0;
79
    my $notforloan = $input->param('notforloan') ? 1 : 0;
Lines 90-95 if ( $op eq 'add_form' ) { Link Here
90
    if ( $itemtype and $is_a_modif ) {    # it's a modification
92
    if ( $itemtype and $is_a_modif ) {    # it's a modification
91
        $itemtype->description($description);
93
        $itemtype->description($description);
92
        $itemtype->rentalcharge($rentalcharge);
94
        $itemtype->rentalcharge($rentalcharge);
95
        $itemtype->defaultreplacecost($defaultreplacecost);
96
        $itemtype->processfee($processfee);
93
        $itemtype->notforloan($notforloan);
97
        $itemtype->notforloan($notforloan);
94
        $itemtype->imageurl($imageurl);
98
        $itemtype->imageurl($imageurl);
95
        $itemtype->summary($summary);
99
        $itemtype->summary($summary);
Lines 108-124 if ( $op eq 'add_form' ) { Link Here
108
        }
112
        }
109
    } elsif ( not $itemtype and not $is_a_modif ) {
113
    } elsif ( not $itemtype and not $is_a_modif ) {
110
        my $itemtype = Koha::ItemType->new(
114
        my $itemtype = Koha::ItemType->new(
111
            {   itemtype       => $itemtype_code,
115
            {   itemtype           => $itemtype_code,
112
                description    => $description,
116
                description        => $description,
113
                rentalcharge   => $rentalcharge,
117
                rentalcharge       => $rentalcharge,
114
                notforloan     => $notforloan,
118
                defaultreplacecost => $defaultreplacecost,
115
                imageurl       => $imageurl,
119
                processfee         => $processfee,
116
                summary        => $summary,
120
                notforloan         => $notforloan,
117
                checkinmsg     => $checkinmsg,
121
                imageurl           => $imageurl,
118
                checkinmsgtype => $checkinmsgtype,
122
                summary            => $summary,
119
                sip_media_type => $sip_media_type,
123
                checkinmsg         => $checkinmsg,
120
                hideinopac     => $hideinopac,
124
                checkinmsgtype     => $checkinmsgtype,
121
                searchcategory => $searchcategory,
125
                sip_media_type     => $sip_media_type,
126
                hideinopac         => $hideinopac,
127
                searchcategory     => $searchcategory,
122
            }
128
            }
123
        );
129
        );
124
        eval { $itemtype->store; };
130
        eval { $itemtype->store; };
(-)a/installer/data/mysql/atomicupdate/bug_12768-replacement_cost_processing_fee_management.sql (+2 lines)
Line 0 Link Here
1
INSERT INTO systempreferences (variable,value,explanation,type) VALUES ('useDefaultReplacementCost',0,'default replacement cost defined in item type','YesNo');
2
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');
(-)a/installer/data/mysql/sysprefs.sql (+2 lines)
Lines 433-438 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
433
('previousIssuesDefaultSortOrder','asc','asc|desc','Specify the sort order of Previous Issues on the circulation page','Choice'),
433
('previousIssuesDefaultSortOrder','asc','asc|desc','Specify the sort order of Previous Issues on the circulation page','Choice'),
434
('printcirculationslips','1','','If ON, enable printing circulation receipts','YesNo'),
434
('printcirculationslips','1','','If ON, enable printing circulation receipts','YesNo'),
435
('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'),
435
('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'),
436
('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'),
436
('QueryAutoTruncate','1',NULL,'If ON, query truncation is enabled by default','YesNo'),
437
('QueryAutoTruncate','1',NULL,'If ON, query truncation is enabled by default','YesNo'),
437
('QueryFuzzy','1',NULL,'If ON, enables fuzzy option for searches','YesNo'),
438
('QueryFuzzy','1',NULL,'If ON, enables fuzzy option for searches','YesNo'),
438
('QueryStemming','1',NULL,'If ON, enables query stemming','YesNo'),
439
('QueryStemming','1',NULL,'If ON, enables query stemming','YesNo'),
Lines 570-575 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
570
('UseControlNumber','0','','If ON, record control number (w subfields) and control number (001) are used for linking of bibliographic records.','YesNo'),
571
('UseControlNumber','0','','If ON, record control number (w subfields) and control number (001) are used for linking of bibliographic records.','YesNo'),
571
('UseCourseReserves','0',NULL,'Enable the course reserves feature.','YesNo'),
572
('UseCourseReserves','0',NULL,'Enable the course reserves feature.','YesNo'),
572
('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'),
573
('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'),
574
('useDefaultReplacementCost', '0', NULL, 'default replacement cost defined in item type', 'YesNo'),
573
('useDischarge','','','Allows librarians to discharge borrowers and borrowers to request a discharge','YesNo'),
575
('useDischarge','','','Allows librarians to discharge borrowers and borrowers to request a discharge','YesNo'),
574
('UseICU','0','1','Tell Koha if ICU indexing is in use for Zebra or not.','YesNo'),
576
('UseICU','0','1','Tell Koha if ICU indexing is in use for Zebra or not.','YesNo'),
575
('UseKohaPlugins','0','','Enable or disable the ability to use Koha Plugins.','YesNo'),
577
('UseKohaPlugins','0','','Enable or disable the ability to use Koha Plugins.','YesNo'),
(-)a/koha-tmpl/intranet-tmpl/prog/css/staff-global.css (+3 lines)
Lines 687-692 fieldset.rows fieldset { Link Here
687
.yui-b fieldset.rows td label, .yui-b fieldset.rows td span.label {
687
.yui-b fieldset.rows td label, .yui-b fieldset.rows td span.label {
688
        width: auto;
688
        width: auto;
689
}
689
}
690
.yui-b fieldset.rows ol.oladditemtype label, .yui-b fieldset.rows ol.oladditemtype span.label {
691
    width: 13em;
692
}
690
693
691
.yui-b fieldset.rows div.hint {
694
.yui-b fieldset.rows div.hint {
692
	margin-left : 10.5em;
695
	margin-left : 10.5em;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt (-1 / +13 lines)
Lines 235-241 Item types administration Link Here
235
                    </div>
235
                    </div>
236
                </div>
236
                </div>
237
            [% END %]
237
            [% END %]
238
            <ol>
238
            <ol class="oladditemtype">
239
                <li>
239
                <li>
240
                    <label for="hideinopac">Hide in OPAC: </label>
240
                    <label for="hideinopac">Hide in OPAC: </label>
241
                    [% IF ( itemtype.hideinopac ) %]
241
                    [% IF ( itemtype.hideinopac ) %]
Lines 259-264 Item types administration Link Here
259
                    <input type="text" id="rentalcharge" name="rentalcharge" size="10" value="[% itemtype.rentalcharge %]" />
259
                    <input type="text" id="rentalcharge" name="rentalcharge" size="10" value="[% itemtype.rentalcharge %]" />
260
                </li>
260
                </li>
261
                <li>
261
                <li>
262
                    <label for="defaultreplacecost">Default replacement cost: </label>
263
                    <input type="text" id="defaultreplacecost" name="defaultreplacecost" size="10" value="[% defaultreplacecost %]" />
264
                </li>
265
                <li>
266
                    <label for="processfee">Processing fee (when lost): </label>
267
                    <input type="text" id="processfee" name="processfee" size="10" value="[% processfee %]" />
268
                </li>
269
                <li>
262
                    <label for="checkinmsg">Checkin message: </label>
270
                    <label for="checkinmsg">Checkin message: </label>
263
                    <textarea id="checkinmsg" name="checkinmsg" cols="55" rows="5">[% itemtype.checkinmsg %]</textarea>
271
                    <textarea id="checkinmsg" name="checkinmsg" cols="55" rows="5">[% itemtype.checkinmsg %]</textarea>
264
                </li>
272
                </li>
Lines 348-353 Item types administration Link Here
348
            <th>Not for loan</th>
356
            <th>Not for loan</th>
349
            <th>Hide in OPAC</th>
357
            <th>Hide in OPAC</th>
350
            <th>Charge</th>
358
            <th>Charge</th>
359
            <th>Default replacement cost</th>
360
            <th>Processing fee (when lost)</th>
351
            <th>Checkin message</th>
361
            <th>Checkin message</th>
352
            <th>Actions</th>
362
            <th>Actions</th>
353
          </thead>
363
          </thead>
Lines 387-392 Item types administration Link Here
387
              [% itemtype.rentalcharge | $Price %]
397
              [% itemtype.rentalcharge | $Price %]
388
            [% END %]
398
            [% END %]
389
            </td>
399
            </td>
400
            <td>[% itemtype.defaultreplacecost | $Price %]</td>
401
            <td>[% itemtype.processfee | $Price %]</td>
390
            <td>[% itemtype.checkinmsg | html | html_line_break %]</td>
402
            <td>[% itemtype.checkinmsg | html | html_line_break %]</td>
391
            <td class="actions">
403
            <td class="actions">
392
              <a href="/cgi-bin/koha/admin/itemtypes.pl?op=add_form&amp;itemtype=[% itemtype.itemtype |html %]" class="btn btn-default btn-xs"><i class="fa fa-pencil"></i> Edit</a>
404
              <a href="/cgi-bin/koha/admin/itemtypes.pl?op=add_form&amp;itemtype=[% itemtype.itemtype |html %]" class="btn btn-default btn-xs"><i class="fa fa-pencil"></i> Edit</a>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref (+11 lines)
Lines 740-745 Circulation: Link Here
740
                  any_time_is_placed: "any time a hold is placed."
740
                  any_time_is_placed: "any time a hold is placed."
741
                  not_always: "only if all items are checked out and the record has at least one hold already."
741
                  not_always: "only if all items are checked out and the record has at least one hold already."
742
                  any_time_is_collected: "any time a hold is collected."
742
                  any_time_is_collected: "any time a hold is collected."
743
            - pref: useDefaultReplacementCost
744
              choices:
745
                  yes: use
746
                  no: "Don't use"
747
            - the default replacement cost defined in item type.
748
        -
749
            - "Set the text to be recorded in the column 'note', table 'accountlines' when the processing fee (defined in item type) is applied."
750
            - pref: ProcessingFeeNote
751
              type: textarea
752
              class: code
753
743
    Self Checkout:
754
    Self Checkout:
744
        -
755
        -
745
            - "Include the following JavaScript on all pages in the web-based self checkout:"
756
            - "Include the following JavaScript on all pages in the web-based self checkout:"
(-)a/t/db_dependent/Accounts.t (-1 / +142 lines)
Lines 18-28 Link Here
18
18
19
use Modern::Perl;
19
use Modern::Perl;
20
20
21
use Test::More tests => 22;
21
use Test::More tests => 23;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
24
25
use t::lib::TestBuilder;
25
use t::lib::TestBuilder;
26
use t::lib::Mocks;
26
27
27
use Koha::Account;
28
use Koha::Account;
28
use Koha::Account::Lines;
29
use Koha::Account::Lines;
Lines 487-489 subtest 'balance' => sub { Link Here
487
    $patron->delete;
488
    $patron->delete;
488
};
489
};
489
490
491
subtest "Koha::Account::chargelostitem tests" => sub {
492
    plan tests => 32;
493
494
    my $lostfine;
495
    my $procfee;
496
497
    my $itype_no_replace_no_fee = $builder->build({ source => 'Itemtype', value => {
498
            rentalcharge => 0,
499
            defaultreplacecost => undef,
500
            processfee => undef,
501
    }});
502
    my $itype_replace_no_fee = $builder->build({ source => 'Itemtype', value => {
503
            rentalcharge => 0,
504
            defaultreplacecost => 16.32,
505
            processfee => undef,
506
    }});
507
    my $itype_no_replace_fee = $builder->build({ source => 'Itemtype', value => {
508
            rentalcharge => 0,
509
            defaultreplacecost => undef,
510
            processfee => 8.16,
511
    }});
512
    my $itype_replace_fee = $builder->build({ source => 'Itemtype', value => {
513
            rentalcharge => 0,
514
            defaultreplacecost => 4.08,
515
            processfee => 2.04,
516
    }});
517
    my $cli_borrowernumber = $builder->build({ source => 'Borrower' })->{'borrowernumber'};
518
    my $cli_itemnumber1 = $builder->build({ source => 'Item', value => { itype => $itype_no_replace_no_fee->{itemtype} } })->{'itemnumber'};
519
    my $cli_itemnumber2 = $builder->build({ source => 'Item', value => { itype => $itype_replace_no_fee->{itemtype} } })->{'itemnumber'};
520
    my $cli_itemnumber3 = $builder->build({ source => 'Item', value => { itype => $itype_no_replace_fee->{itemtype} } })->{'itemnumber'};
521
    my $cli_itemnumber4 = $builder->build({ source => 'Item', value => { itype => $itype_replace_fee->{itemtype} } })->{'itemnumber'};
522
    my $duck = Koha::Items->find({itemnumber=>$cli_itemnumber1});
523
524
    t::lib::Mocks::mock_preference('item-level_itypes', '1');
525
    t::lib::Mocks::mock_preference('useDefaultReplacementCost', '0');
526
527
    C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 0, "Perdedor");
528
    $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'L' });
529
    $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'PF' });
530
    ok( !$lostfine, "No lost fine if no replacementcost or default when pref off");
531
    ok( !$procfee,  "No processing fee if no processing fee");
532
    C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 6.12, "Perdedor");
533
    $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'L' });
534
    $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'PF' });
535
    ok( $lostfine->amount == 6.12, "Lost fine equals replacementcost when pref off and no default set");
536
    ok( !$procfee,  "No processing fee if no processing fee");
537
    $lostfine->delete();
538
539
    C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 0, "Perdedor");
540
    $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'L' });
541
    $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'PF' });
542
    ok( !$lostfine, "No lost fine if no replacementcost but default set when pref off");
543
    ok( !$procfee,  "No processing fee if no processing fee");
544
    C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 6.12, "Perdedor");
545
    $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'L' });
546
    $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'PF' });
547
    ok( $lostfine->amount == 6.12 , "Lost fine equals replacementcost when pref off and default set");
548
    ok( !$procfee,  "No processing fee if no processing fee");
549
    $lostfine->delete();
550
551
    C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 0, "Perdedor");
552
    $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'L' });
553
    $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'PF' });
554
    ok( !$lostfine, "No lost fine if no replacementcost and no default set when pref off");
555
    ok( $procfee->amount == 8.16,  "Processing fee if processing fee");
556
    $procfee->delete();
557
    C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 6.12, "Perdedor");
558
    $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'L' });
559
    $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'PF' });
560
    ok( $lostfine->amount == 6.12 , "Lost fine equals replacementcost when pref off and no default set");
561
    ok( $procfee->amount == 8.16,  "Processing fee if processing fee");
562
    $lostfine->delete();
563
    $procfee->delete();
564
565
    C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 0, "Perdedor");
566
    $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'L' });
567
    $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' });
568
    ok( !$lostfine, "No lost fine if no replacementcost but default set when pref off");
569
    ok( $procfee->amount == 2.04,  "Processing fee if processing fee");
570
    $procfee->delete();
571
    C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 6.12, "Perdedor");
572
    $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'L' });
573
    $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' });
574
    ok( $lostfine->amount == 6.12 , "Lost fine equals replacementcost when pref off and default set");
575
    ok( $procfee->amount == 2.04,  "Processing fee if processing fee");
576
    $lostfine->delete();
577
    $procfee->delete();
578
579
    t::lib::Mocks::mock_preference('useDefaultReplacementCost', '1');
580
581
    C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 0, "Perdedor");
582
    $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'L' });
583
    $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'PF' });
584
    ok( !$lostfine, "No lost fine if no replacementcost or default when pref on");
585
    ok( !$procfee,  "No processing fee if no processing fee");
586
    C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 6.12, "Perdedor");
587
    $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'L' });
588
    $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'PF' });
589
    is( $lostfine->amount, "6.120000", "Lost fine equals replacementcost when pref on and no default set");
590
    ok( !$procfee,  "No processing fee if no processing fee");
591
592
    C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 0, "Perdedor");
593
    $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'L' });
594
    $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'PF' });
595
    is( $lostfine->amount(), "16.320000", "Lost fine is default if no replacementcost but default set when pref on");
596
    ok( !$procfee,  "No processing fee if no processing fee");
597
    $lostfine->delete();
598
    C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 6.12, "Perdedor");
599
    $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'L' });
600
    $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'PF' });
601
    is( $lostfine->amount, "6.120000" , "Lost fine equals replacementcost when pref on and default set");
602
    ok( !$procfee,  "No processing fee if no processing fee");
603
604
    C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 0, "Perdedor");
605
    $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'L' });
606
    $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'PF' });
607
    ok( !$lostfine, "No lost fine if no replacementcost and default not set when pref on");
608
    is( $procfee->amount, "8.160000",  "Processing fee if processing fee");
609
    $procfee->delete();
610
    C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 6.12, "Perdedor");
611
    $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'L' });
612
    $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'PF' });
613
    is( $lostfine->amount, "6.120000", "Lost fine equals replacementcost when pref on and no default set");
614
    is( $procfee->amount, "8.160000",  "Processing fee if processing fee");
615
616
    C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 0, "Perdedor");
617
    $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'L' });
618
    $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' });
619
    is( $lostfine->amount, "4.080000", "Lost fine is default if no replacementcost but default set when pref on");
620
    is( $procfee->amount, "2.040000",  "Processing fee if processing fee");
621
    $lostfine->delete();
622
    $procfee->delete();
623
    C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 6.12, "Perdedor");
624
    $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'L' });
625
    $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' });
626
    is( $lostfine->amount, "6.120000", "Lost fine equals replacementcost when pref on and default set");
627
    is( $procfee->amount, "2.040000",  "Processing fee if processing fee");
628
};
629
630
1;
(-)a/t/db_dependent/Circulation.t (-1 / +2 lines)
Lines 60-66 my $library2 = $builder->build({ Link Here
60
});
60
});
61
my $itemtype = $builder->build(
61
my $itemtype = $builder->build(
62
    {   source => 'Itemtype',
62
    {   source => 'Itemtype',
63
        value  => { notforloan => undef, rentalcharge => 0 }
63
        value  => { notforloan => undef, rentalcharge => 0, defaultreplacecost => undef, processfee => undef }
64
    }
64
    }
65
)->{itemtype};
65
)->{itemtype};
66
my $patron_category = $builder->build({ source => 'Category', value => { categorycode => 'NOT_X', category_type => 'P', enrolmentfee => 0 } });
66
my $patron_category = $builder->build({ source => 'Category', value => { categorycode => 'NOT_X', category_type => 'P', enrolmentfee => 0 } });
Lines 778-783 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
778
    is( $offset->type, 'Fine', 'Account offset type is Fine' );
778
    is( $offset->type, 'Fine', 'Account offset type is Fine' );
779
    is( $offset->amount, '15.000000', 'Account offset amount is 15.00' );
779
    is( $offset->amount, '15.000000', 'Account offset amount is 15.00' );
780
780
781
    ModItem({ itype => 'BK' }, $biblionumber, $itemnumber, 1);
781
    LostItem( $itemnumber, 1 );
782
    LostItem( $itemnumber, 1 );
782
783
783
    my $item = Koha::Database->new()->schema()->resultset('Item')->find($itemnumber);
784
    my $item = Koha::Database->new()->schema()->resultset('Item')->find($itemnumber);
(-)a/t/db_dependent/Circulation/Chargelostitem.t (-1 / +84 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
5
use Test::MockModule;
6
use C4::Biblio;
7
use C4::Items;
8
use C4::Members;
9
use C4::Branch;
10
use C4::Category;
11
use C4::Circulation;
12
use MARC::Record;
13
use Test::More tests => 7;
14
15
BEGIN {
16
    use_ok('C4::Accounts');
17
}
18
19
my $dbh = C4::Context->dbh;
20
$dbh->{AutoCommit} = 0;
21
$dbh->{RaiseError} = 1;
22
$dbh->do(q|DELETE FROM accountlines|);
23
24
my $branchcode;
25
my $branch_created;
26
my @branches = keys %{ GetBranches() };
27
if (@branches) {
28
    $branchcode = $branches[0];
29
} else {
30
    $branchcode = 'B';
31
    ModBranch({ add => 1, branchcode => $branchcode, branchname => 'Branch' });
32
    $branch_created = 1;
33
}
34
35
my %item_branch_infos = (
36
    homebranch => $branchcode,
37
    holdingbranch => $branchcode,
38
);
39
40
my ($biblionumber1) = AddBiblio(MARC::Record->new, '');
41
my $itemnumber1 = AddItem({ barcode => '0101', %item_branch_infos }, $biblionumber1);
42
my $itemnumber2 = AddItem({ barcode => '0102', %item_branch_infos }, $biblionumber1);
43
44
my ($biblionumber2) = AddBiblio(MARC::Record->new, '');
45
my $itemnumber3 = AddItem({ barcode => '0203', %item_branch_infos }, $biblionumber2);
46
47
my $categorycode;
48
my $category_created;
49
my @categories = C4::Category->all;
50
if (@categories) {
51
    $categorycode = $categories[0]->{categorycode}
52
} else {
53
    $categorycode = 'C';
54
    $dbh->do(
55
        "INSERT INTO categories(categorycode) VALUES(?)", undef, $categorycode);
56
    $category_created = 1;
57
}
58
59
my $borrowernumber = AddMember(categorycode => $categorycode, branchcode => $branchcode);
60
my $borrower = GetMember(borrowernumber => $borrowernumber);
61
62
# Need to mock userenv for AddIssue
63
my $module = new Test::MockModule('C4::Context');
64
$module->mock('userenv', sub { { branch => $branchcode } });
65
AddIssue($borrower, '0101');
66
AddIssue($borrower, '0203');
67
68
# Begin tests...
69
my $processfee = 10;
70
my $issues;
71
$issues = C4::Circulation::GetIssues({biblionumber => $biblionumber1});
72
my $issue=$issues->[0];
73
$issue->{'processfee'} = $processfee;
74
C4::Accounts::chargelostitem($issue, 'test');
75
76
my @accountline = C4::Accounts::getcharges($borrowernumber);
77
78
is( scalar(@accountline), 1, 'accountline should have 1 row' );
79
is( int($accountline[0]->{amount}), $processfee, "The accountline amount should be precessfee value " );
80
is( $accountline[0]->{accounttype}, 'PF', "The accountline accounttype should be PF " );
81
is( $accountline[0]->{borrowernumber}, $borrowernumber, "The accountline borrowernumber should be the example borrowernumber" );
82
my $itemnumber = C4::Items::GetItemnumberFromBarcode('0101');
83
is( $accountline[0]->{itemnumber}, $itemnumber, "The accountline itemnumber should the linked with barcode '0101'" );
84
is( $accountline[0]->{description}, 'test ' . $issue->{itemnumber}, "The accountline description should be 'test'" );

Return to bug 12768