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

(-)a/C4/Accounts.pm (-39 / +38 lines)
Lines 27-32 use C4::Circulation qw(ReturnLostItem); Link Here
27
use C4::Log qw(logaction);
27
use C4::Log qw(logaction);
28
use Koha::Account;
28
use Koha::Account;
29
use Koha::Account::Lines;
29
use Koha::Account::Lines;
30
use Koha::Items;
30
31
31
use Data::Dumper qw(Dumper);
32
use Data::Dumper qw(Dumper);
32
33
Lines 125-165 sub chargelostitem{ Link Here
125
# FIXME : if no replacement price, borrower just doesn't get charged?
126
# FIXME : if no replacement price, borrower just doesn't get charged?
126
    my $dbh = C4::Context->dbh();
127
    my $dbh = C4::Context->dbh();
127
    my ($borrowernumber, $itemnumber, $amount, $description) = @_;
128
    my ($borrowernumber, $itemnumber, $amount, $description) = @_;
128
129
    my $itype = Koha::ItemTypes->find({ itemtype => Koha::Items->find($itemnumber)->effective_itemtype() });
130
    my $replacementprice = $amount;
131
    my $defaultreplacecost = $itype->defaultreplacecost;
132
    my $processfee = $itype->processfee;
133
    my $usedefaultreplacementcost = C4::Context->preference("useDefaultReplacementCost");
134
    my $processingfeenote = C4::Context->preference("ProcessingFeeNote");
135
    if ($usedefaultreplacementcost && $amount == 0 && $defaultreplacecost){
136
        $replacementprice = $defaultreplacecost;
137
    }
129
    # first make sure the borrower hasn't already been charged for this item
138
    # first make sure the borrower hasn't already been charged for this item
130
    my $sth1=$dbh->prepare("SELECT * from accountlines
139
    my $sth1=$dbh->prepare("SELECT * from accountlines
131
    WHERE borrowernumber=? AND itemnumber=? and accounttype='L'");
140
    WHERE borrowernumber=? AND itemnumber=? and accounttype='L'");
132
    $sth1->execute($borrowernumber,$itemnumber);
141
    $sth1->execute($borrowernumber,$itemnumber);
133
    my $existing_charge_hashref=$sth1->fetchrow_hashref();
142
    my $existing_charge_hashref=$sth1->fetchrow_hashref();
134
135
    # OK, they haven't
143
    # OK, they haven't
136
    unless ($existing_charge_hashref) {
144
    unless ($existing_charge_hashref) {
137
        my $manager_id = 0;
138
        $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
139
        # This item is on issue ... add replacement cost to the borrower's record and mark it returned
140
        #  Note that we add this to the account even if there's no replacement price, allowing some other
141
        #  process (or person) to update it, since we don't handle any defaults for replacement prices.
142
        my $accountno = getnextacctno($borrowernumber);
143
        my $sth2=$dbh->prepare("INSERT INTO accountlines
144
        (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber,manager_id)
145
        VALUES (?,?,now(),?,?,'L',?,?,?)");
146
        $sth2->execute($borrowernumber,$accountno,$amount,
147
        $description,$amount,$itemnumber,$manager_id);
148
149
        if ( C4::Context->preference("FinesLog") ) {
150
            logaction("FINES", 'CREATE', $borrowernumber, Dumper({
151
                action            => 'create_fee',
152
                borrowernumber    => $borrowernumber,
153
                accountno         => $accountno,
154
                amount            => $amount,
155
                amountoutstanding => $amount,
156
                description       => $description,
157
                accounttype       => 'L',
158
                itemnumber        => $itemnumber,
159
                manager_id        => $manager_id,
160
            }));
161
        }
162
145
146
        #add processing fee
147
        if ($processfee && $processfee > 0){
148
            manualinvoice($borrowernumber, $itemnumber, $description, 'PF', $processfee, $processingfeenote, 1);
149
        }
150
        #add replace cost
151
        if ($replacementprice > 0){
152
            manualinvoice($borrowernumber, $itemnumber, $description, 'L', $replacementprice, undef, 1);
153
        }
163
    }
154
    }
164
}
155
}
165
156
Lines 190-196 should be the empty string. Link Here
190
#
181
#
191
182
192
sub manualinvoice {
183
sub manualinvoice {
193
    my ( $borrowernumber, $itemnum, $desc, $type, $amount, $note ) = @_;
184
    my ( $borrowernumber, $itemnum, $desc, $type, $amount, $note, $skip_notify ) = @_;
194
    my $manager_id = 0;
185
    my $manager_id = 0;
195
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
186
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
196
    my $dbh      = C4::Context->dbh;
187
    my $dbh      = C4::Context->dbh;
Lines 198-203 sub manualinvoice { Link Here
198
    my $insert;
189
    my $insert;
199
    my $accountno  = getnextacctno($borrowernumber);
190
    my $accountno  = getnextacctno($borrowernumber);
200
    my $amountleft = $amount;
191
    my $amountleft = $amount;
192
    $skip_notify //= 0;
201
193
202
    if (   ( $type eq 'L' )
194
    if (   ( $type eq 'L' )
203
        or ( $type eq 'F' )
195
        or ( $type eq 'F' )
Lines 205-211 sub manualinvoice { Link Here
205
        or ( $type eq 'N' )
197
        or ( $type eq 'N' )
206
        or ( $type eq 'M' ) )
198
        or ( $type eq 'M' ) )
207
    {
199
    {
208
        $notifyid = 1;
200
        $notifyid = 1 unless $skip_notify;
209
    }
201
    }
210
202
211
    if ( $itemnum ) {
203
    if ( $itemnum ) {
Lines 244-262 sub manualinvoice { Link Here
244
}
236
}
245
237
246
sub getcharges {
238
sub getcharges {
247
	my ( $borrowerno, $timestamp, $accountno ) = @_;
239
    my ( $borrowerno, $accountno ) = @_;
248
	my $dbh        = C4::Context->dbh;
240
    my $dbh = C4::Context->dbh;
249
	my $timestamp2 = $timestamp - 1;
241
250
	my $query      = "";
242
    my @params;
251
	my $sth = $dbh->prepare(
243
252
			"SELECT * FROM accountlines WHERE borrowernumber=? AND accountno = ?"
244
    my $query = "SELECT * FROM accountlines WHERE borrowernumber = ?";
253
          );
245
    push( @params, $borrowerno );
254
	$sth->execute( $borrowerno, $accountno );
246
247
    if ( $accountno ) {
248
        $query .= " AND accountno = ?";
249
        push( @params, $accountno );
250
    }
251
252
    my $sth = $dbh->prepare( $query );
253
    $sth->execute( @params );
255
	
254
	
256
    my @results;
255
    my @results;
257
    while ( my $data = $sth->fetchrow_hashref ) {
256
    while ( my $data = $sth->fetchrow_hashref ) {
258
		push @results,$data;
257
        push @results,$data;
259
	}
258
    }
260
    return (@results);
259
    return (@results);
261
}
260
}
262
261
(-)a/C4/Circulation.pm (-3 / +3 lines)
Lines 3621-3629 sub LostItem{ Link Here
3621
    my ($itemnumber, $mark_returned) = @_;
3621
    my ($itemnumber, $mark_returned) = @_;
3622
3622
3623
    my $dbh = C4::Context->dbh();
3623
    my $dbh = C4::Context->dbh();
3624
    my $sth=$dbh->prepare("SELECT issues.*,items.*,biblio.title 
3624
    my $sth=$dbh->prepare("SELECT issues.*,items.*,biblio.title
3625
                           FROM issues 
3625
                           FROM issues
3626
                           JOIN items USING (itemnumber) 
3626
                           JOIN items USING (itemnumber)
3627
                           JOIN biblio USING (biblionumber)
3627
                           JOIN biblio USING (biblionumber)
3628
                           WHERE issues.itemnumber=?");
3628
                           WHERE issues.itemnumber=?");
3629
    $sth->execute($itemnumber);
3629
    $sth->execute($itemnumber);
(-)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 478-480 subtest 'balance' => sub { Link Here
478
    $patron->delete;
479
    $patron->delete;
479
};
480
};
480
481
482
subtest "Koha::Account::chargelostitem tests" => sub {
483
    plan tests => 32;
484
485
    my $lostfine;
486
    my $procfee;
487
488
    my $itype_no_replace_no_fee = $builder->build({ source => 'Itemtype', value => {
489
            rentalcharge => 0,
490
            defaultreplacecost => undef,
491
            processfee => undef,
492
    }});
493
    my $itype_replace_no_fee = $builder->build({ source => 'Itemtype', value => {
494
            rentalcharge => 0,
495
            defaultreplacecost => 16.32,
496
            processfee => undef,
497
    }});
498
    my $itype_no_replace_fee = $builder->build({ source => 'Itemtype', value => {
499
            rentalcharge => 0,
500
            defaultreplacecost => undef,
501
            processfee => 8.16,
502
    }});
503
    my $itype_replace_fee = $builder->build({ source => 'Itemtype', value => {
504
            rentalcharge => 0,
505
            defaultreplacecost => 4.08,
506
            processfee => 2.04,
507
    }});
508
    my $cli_borrowernumber = $builder->build({ source => 'Borrower' })->{'borrowernumber'};
509
    my $cli_itemnumber1 = $builder->build({ source => 'Item', value => { itype => $itype_no_replace_no_fee->{itemtype} } })->{'itemnumber'};
510
    my $cli_itemnumber2 = $builder->build({ source => 'Item', value => { itype => $itype_replace_no_fee->{itemtype} } })->{'itemnumber'};
511
    my $cli_itemnumber3 = $builder->build({ source => 'Item', value => { itype => $itype_no_replace_fee->{itemtype} } })->{'itemnumber'};
512
    my $cli_itemnumber4 = $builder->build({ source => 'Item', value => { itype => $itype_replace_fee->{itemtype} } })->{'itemnumber'};
513
    my $duck = Koha::Items->find({itemnumber=>$cli_itemnumber1});
514
515
    t::lib::Mocks::mock_preference('item-level_itypes', '1');
516
    t::lib::Mocks::mock_preference('useDefaultReplacementCost', '0');
517
518
    C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 0, "Perdedor");
519
    $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'L' });
520
    $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'PF' });
521
    ok( !$lostfine, "No lost fine if no replacementcost or default when pref off");
522
    ok( !$procfee,  "No processing fee if no processing fee");
523
    C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 6.12, "Perdedor");
524
    $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'L' });
525
    $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'PF' });
526
    ok( $lostfine->amount == 6.12, "Lost fine equals replacementcost when pref off and no default set");
527
    ok( !$procfee,  "No processing fee if no processing fee");
528
    $lostfine->delete();
529
530
    C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 0, "Perdedor");
531
    $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'L' });
532
    $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'PF' });
533
    ok( !$lostfine, "No lost fine if no replacementcost but default set when pref off");
534
    ok( !$procfee,  "No processing fee if no processing fee");
535
    C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 6.12, "Perdedor");
536
    $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'L' });
537
    $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'PF' });
538
    ok( $lostfine->amount == 6.12 , "Lost fine equals replacementcost when pref off and default set");
539
    ok( !$procfee,  "No processing fee if no processing fee");
540
    $lostfine->delete();
541
542
    C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 0, "Perdedor");
543
    $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'L' });
544
    $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'PF' });
545
    ok( !$lostfine, "No lost fine if no replacementcost and no default set when pref off");
546
    ok( $procfee->amount == 8.16,  "Processing fee if processing fee");
547
    $procfee->delete();
548
    C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 6.12, "Perdedor");
549
    $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'L' });
550
    $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'PF' });
551
    ok( $lostfine->amount == 6.12 , "Lost fine equals replacementcost when pref off and no default set");
552
    ok( $procfee->amount == 8.16,  "Processing fee if processing fee");
553
    $lostfine->delete();
554
    $procfee->delete();
555
556
    C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 0, "Perdedor");
557
    $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'L' });
558
    $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' });
559
    ok( !$lostfine, "No lost fine if no replacementcost but default set when pref off");
560
    ok( $procfee->amount == 2.04,  "Processing fee if processing fee");
561
    $procfee->delete();
562
    C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 6.12, "Perdedor");
563
    $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'L' });
564
    $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' });
565
    ok( $lostfine->amount == 6.12 , "Lost fine equals replacementcost when pref off and default set");
566
    ok( $procfee->amount == 2.04,  "Processing fee if processing fee");
567
    $lostfine->delete();
568
    $procfee->delete();
569
570
    t::lib::Mocks::mock_preference('useDefaultReplacementCost', '1');
571
572
    C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 0, "Perdedor");
573
    $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'L' });
574
    $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'PF' });
575
    ok( !$lostfine, "No lost fine if no replacementcost or default when pref on");
576
    ok( !$procfee,  "No processing fee if no processing fee");
577
    C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 6.12, "Perdedor");
578
    $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'L' });
579
    $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'PF' });
580
    is( $lostfine->amount, "6.120000", "Lost fine equals replacementcost when pref on and no default set");
581
    ok( !$procfee,  "No processing fee if no processing fee");
582
583
    C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 0, "Perdedor");
584
    $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'L' });
585
    $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'PF' });
586
    is( $lostfine->amount(), "16.320000", "Lost fine is default if no replacementcost but default set when pref on");
587
    ok( !$procfee,  "No processing fee if no processing fee");
588
    $lostfine->delete();
589
    C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 6.12, "Perdedor");
590
    $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'L' });
591
    $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'PF' });
592
    is( $lostfine->amount, "6.120000" , "Lost fine equals replacementcost when pref on and default set");
593
    ok( !$procfee,  "No processing fee if no processing fee");
594
595
    C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 0, "Perdedor");
596
    $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'L' });
597
    $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'PF' });
598
    ok( !$lostfine, "No lost fine if no replacementcost and default not set when pref on");
599
    is( $procfee->amount, "8.160000",  "Processing fee if processing fee");
600
    $procfee->delete();
601
    C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 6.12, "Perdedor");
602
    $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'L' });
603
    $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'PF' });
604
    is( $lostfine->amount, "6.120000", "Lost fine equals replacementcost when pref on and no default set");
605
    is( $procfee->amount, "8.160000",  "Processing fee if processing fee");
606
607
    C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 0, "Perdedor");
608
    $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'L' });
609
    $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' });
610
    is( $lostfine->amount, "4.080000", "Lost fine is default if no replacementcost but default set when pref on");
611
    is( $procfee->amount, "2.040000",  "Processing fee if processing fee");
612
    $lostfine->delete();
613
    $procfee->delete();
614
    C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 6.12, "Perdedor");
615
    $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'L' });
616
    $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' });
617
    is( $lostfine->amount, "6.120000", "Lost fine equals replacementcost when pref on and default set");
618
    is( $procfee->amount, "2.040000",  "Processing fee if processing fee");
619
};
620
621
1;
(-)a/t/db_dependent/Circulation.t (-1 / +2 lines)
Lines 57-63 my $library2 = $builder->build({ Link Here
57
});
57
});
58
my $itemtype = $builder->build(
58
my $itemtype = $builder->build(
59
    {   source => 'Itemtype',
59
    {   source => 'Itemtype',
60
        value  => { notforloan => undef, rentalcharge => 0 }
60
        value  => { notforloan => undef, rentalcharge => 0, defaultreplacecost => undef, processfee => undef }
61
    }
61
    }
62
)->{itemtype};
62
)->{itemtype};
63
my $patron_category = $builder->build({ source => 'Category', value => { categorycode => 'NOT_X', category_type => 'P', enrolmentfee => 0 } });
63
my $patron_category = $builder->build({ source => 'Category', value => { categorycode => 'NOT_X', category_type => 'P', enrolmentfee => 0 } });
Lines 767-772 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
767
        }
767
        }
768
    );
768
    );
769
769
770
    ModItem({ itype => 'BK' }, $biblionumber, $itemnumber, 1);
770
    LostItem( $itemnumber, 1 );
771
    LostItem( $itemnumber, 1 );
771
772
772
    my $item = Koha::Database->new()->schema()->resultset('Item')->find($itemnumber);
773
    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