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

(-)a/C4/Accounts.pm (-28 / +49 lines)
Lines 353-395 sub chargelostitem{ Link Here
353
# a charge has been added
353
# a charge has been added
354
# FIXME : if no replacement price, borrower just doesn't get charged?
354
# FIXME : if no replacement price, borrower just doesn't get charged?
355
    my $dbh = C4::Context->dbh();
355
    my $dbh = C4::Context->dbh();
356
    my ($borrowernumber, $itemnumber, $amount, $description) = @_;
356
    my ($issues, $description) = @_;
357
357
    my $borrowernumber = $issues->{'borrowernumber'};
358
    my $itemnumber = $issues->{'itemnumber'};
359
    my $replacementprice = $issues->{'replacementprice'};
360
    my $defaultreplacecost = $issues->{'defaultreplacecost'};
361
    my $processfee = $issues->{'processfee'};
362
    my $usedefaultreplacementcost = C4::Context->preference("useDefaultReplacementCost");
363
    my $processingfeenote = C4::Context->preference("ProcessingFeeNote");
364
365
    if ($usedefaultreplacementcost && $replacementprice == 0){
366
        $replacementprice = $defaultreplacecost;
367
    }
358
    # first make sure the borrower hasn't already been charged for this item
368
    # first make sure the borrower hasn't already been charged for this item
359
    my $sth1=$dbh->prepare("SELECT * from accountlines
369
    my $sth1=$dbh->prepare("SELECT * from accountlines
360
    WHERE borrowernumber=? AND itemnumber=? and accounttype='L'");
370
    WHERE borrowernumber=? AND itemnumber=? and accounttype='L'");
361
    $sth1->execute($borrowernumber,$itemnumber);
371
    $sth1->execute($borrowernumber,$itemnumber);
362
    my $existing_charge_hashref=$sth1->fetchrow_hashref();
372
    my $existing_charge_hashref=$sth1->fetchrow_hashref();
363
364
    # OK, they haven't
373
    # OK, they haven't
374
    my $accountline;
365
    unless ($existing_charge_hashref) {
375
    unless ($existing_charge_hashref) {
366
        my $manager_id = 0;
367
        $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
368
        # This item is on issue ... add replacement cost to the borrower's record and mark it returned
369
        #  Note that we add this to the account even if there's no replacement price, allowing some other
370
        #  process (or person) to update it, since we don't handle any defaults for replacement prices.
371
        my $accountno = getnextacctno($borrowernumber);
372
        my $sth2=$dbh->prepare("INSERT INTO accountlines
373
        (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber,manager_id)
374
        VALUES (?,?,now(),?,?,'L',?,?,?)");
375
        $sth2->execute($borrowernumber,$accountno,$amount,
376
        $description,$amount,$itemnumber,$manager_id);
377
376
378
        if ( C4::Context->preference("FinesLog") ) {
377
        #add processing fee
379
            logaction("FINES", 'CREATE', $borrowernumber, Dumper({
378
        if ($processfee > 0){
380
                action            => 'create_fee',
379
            $accountline = _insert_accontlines($borrowernumber, $processfee, $description, $itemnumber, $processingfeenote, 'PF');
381
                borrowernumber    => $borrowernumber,
380
        }
382
                accountno         => $accountno,
381
        #add replace cost
383
                amount            => $amount,
382
        if ($replacementprice > 0){
384
                amountoutstanding => $amount,
383
           $accountline = _insert_accontlines($borrowernumber, $replacementprice, $description, $itemnumber, undef, 'L');
385
                description       => $description,
386
                accounttype       => 'L',
387
                itemnumber        => $itemnumber,
388
                manager_id        => $manager_id,
389
            }));
390
        }
384
        }
385
    }
386
    return $accountline;
387
}
391
388
389
sub _insert_accontlines {
390
    my ($borrowernumber, $amount, $description, $itemnumber, $note, $accounttype) = @_;
391
    my $manager_id = 0;
392
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
393
    my $accountno = getnextacctno($borrowernumber);
394
    my $dbh = C4::Context->dbh();
395
    my $sth2=$dbh->prepare("INSERT INTO accountlines
396
    (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber,manager_id, note)
397
    VALUES (?,?,now(),?,?,?,?,?,?,?)");
398
    $sth2->execute($borrowernumber,$accountno,$amount,
399
    $description,$accounttype, $amount,$itemnumber,$manager_id,$note);
400
401
    if ( C4::Context->preference("FinesLog") ) {
402
       logaction("FINES", 'CREATE', $borrowernumber, Dumper({
403
            action            => 'create_fee',
404
            borrowernumber    => $borrowernumber,
405
            accountno         => $accountno,
406
            amount            => $amount,
407
            amountoutstanding => $amount,
408
            description       => $description,
409
            accounttype       => $accounttype,
410
             itemnumber        => $itemnumber,
411
             manager_id        => $manager_id,
412
        }));
392
    }
413
    }
414
    return $accountno;
393
}
415
}
394
416
395
=head2 manualinvoice
417
=head2 manualinvoice
Lines 473-481 sub manualinvoice { Link Here
473
}
495
}
474
496
475
sub getcharges {
497
sub getcharges {
476
	my ( $borrowerno, $timestamp, $accountno ) = @_;
498
	my ( $borrowerno, $accountno ) = @_;
477
	my $dbh        = C4::Context->dbh;
499
	my $dbh        = C4::Context->dbh;
478
	my $timestamp2 = $timestamp - 1;
479
	my $query      = "";
500
	my $query      = "";
480
	my $sth = $dbh->prepare(
501
	my $sth = $dbh->prepare(
481
			"SELECT * FROM accountlines WHERE borrowernumber=? AND accountno = ?"
502
			"SELECT * FROM accountlines WHERE borrowernumber=? AND accountno = ?"
(-)a/C4/Circulation.pm (-2 / +3 lines)
Lines 3602-3611 sub LostItem{ Link Here
3602
    my ($itemnumber, $mark_returned) = @_;
3602
    my ($itemnumber, $mark_returned) = @_;
3603
3603
3604
    my $dbh = C4::Context->dbh();
3604
    my $dbh = C4::Context->dbh();
3605
    my $sth=$dbh->prepare("SELECT issues.*,items.*,biblio.title 
3605
    my $sth=$dbh->prepare("SELECT issues.*,items.*,biblio.title,itemtypes.defaultreplacecost, itemtypes.processfee
3606
                           FROM issues 
3606
                           FROM issues 
3607
                           JOIN items USING (itemnumber) 
3607
                           JOIN items USING (itemnumber) 
3608
                           JOIN biblio USING (biblionumber)
3608
                           JOIN biblio USING (biblionumber)
3609
                           JOIN itemtypes on items.itype = itemtypes.itemtype
3609
                           WHERE issues.itemnumber=?");
3610
                           WHERE issues.itemnumber=?");
3610
    $sth->execute($itemnumber);
3611
    $sth->execute($itemnumber);
3611
    my $issues=$sth->fetchrow_hashref();
3612
    my $issues=$sth->fetchrow_hashref();
Lines 3619-3625 sub LostItem{ Link Here
3619
            defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $itemnumber...) failed!";  # zero is OK, check defined
3620
            defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $itemnumber...) failed!";  # zero is OK, check defined
3620
        }
3621
        }
3621
        if (C4::Context->preference('WhenLostChargeReplacementFee')){
3622
        if (C4::Context->preference('WhenLostChargeReplacementFee')){
3622
            C4::Accounts::chargelostitem($borrowernumber, $itemnumber, $issues->{'replacementprice'}, "Lost Item $issues->{'title'} $issues->{'barcode'}");
3623
            C4::Accounts::chargelostitem($issues, "Lost Item $issues->{'title'} $issues->{'barcode'}");
3623
            #FIXME : Should probably have a way to distinguish this from an item that really was returned.
3624
            #FIXME : Should probably have a way to distinguish this from an item that really was returned.
3624
            #warn " $issues->{'borrowernumber'}  /  $itemnumber ";
3625
            #warn " $issues->{'borrowernumber'}  /  $itemnumber ";
3625
        }
3626
        }
(-)a/admin/itemtypes.pl (-3 / +13 lines)
Lines 116-121 if ( $op eq 'add_form' ) { Link Here
116
        itemtype        => $itemtype,
116
        itemtype        => $itemtype,
117
        description     => $data->{'description'},
117
        description     => $data->{'description'},
118
        rentalcharge    => sprintf( "%.2f", $data->{'rentalcharge'} ),
118
        rentalcharge    => sprintf( "%.2f", $data->{'rentalcharge'} ),
119
        defaultreplacecost     => sprintf( "%.2f", $data->{'defaultreplacecost'} ),
120
        processfee     => sprintf( "%.2f", $data->{'processfee'} ),
119
        notforloan      => $data->{'notforloan'},
121
        notforloan      => $data->{'notforloan'},
120
        imageurl        => $data->{'imageurl'},
122
        imageurl        => $data->{'imageurl'},
121
        template        => C4::Context->preference('template'),
123
        template        => C4::Context->preference('template'),
Lines 144-149 elsif ( $op eq 'add_validate' ) { Link Here
144
            UPDATE itemtypes
146
            UPDATE itemtypes
145
            SET    description = ?
147
            SET    description = ?
146
                 , rentalcharge = ?
148
                 , rentalcharge = ?
149
                 , defaultreplacecost = ?
150
                 , processfee = ?
147
                 , notforloan = ?
151
                 , notforloan = ?
148
                 , imageurl = ?
152
                 , imageurl = ?
149
                 , summary = ?
153
                 , summary = ?
Lines 156-161 elsif ( $op eq 'add_validate' ) { Link Here
156
        $sth->execute(
160
        $sth->execute(
157
            $input->param('description'),
161
            $input->param('description'),
158
            $input->param('rentalcharge'),
162
            $input->param('rentalcharge'),
163
            $input->param('defaultreplacecost'),
164
            $input->param('processfee'),
159
            ( $input->param('notforloan') ? 1 : 0 ),
165
            ( $input->param('notforloan') ? 1 : 0 ),
160
            (
166
            (
161
                $input->param('image') eq 'removeImage' ? '' : (
167
                $input->param('image') eq 'removeImage' ? '' : (
Lines 168-182 elsif ( $op eq 'add_validate' ) { Link Here
168
            $input->param('checkinmsg'),
174
            $input->param('checkinmsg'),
169
            $input->param('checkinmsgtype'),
175
            $input->param('checkinmsgtype'),
170
            $sip_media_type,
176
            $sip_media_type,
171
            $input->param('itemtype')
177
            $input->param('itemtype'),
172
        );
178
        );
173
    }
179
    }
174
    else {    # add a new itemtype & not modif an old
180
    else {    # add a new itemtype & not modif an old
175
        my $query = "
181
        my $query = "
176
            INSERT INTO itemtypes
182
            INSERT INTO itemtypes
177
                (itemtype,description,rentalcharge, notforloan, imageurl, summary, checkinmsg, checkinmsgtype, sip_media_type)
183
                (itemtype,description, rentalcharge, defaultreplacecost, processfee, notforloan, imageurl, summary, checkinmsg, checkinmsgtype, sip_media_type)
178
            VALUES
184
            VALUES
179
                (?,?,?,?,?,?,?,?,?);
185
                (?,?,?,?,?,?,?,?,?,?,?);
180
            ";
186
            ";
181
        my $sth = $dbh->prepare($query);
187
        my $sth = $dbh->prepare($query);
182
		my $image = $input->param('image');
188
		my $image = $input->param('image');
Lines 184-189 elsif ( $op eq 'add_validate' ) { Link Here
184
            $input->param('itemtype'),
190
            $input->param('itemtype'),
185
            $input->param('description'),
191
            $input->param('description'),
186
            $input->param('rentalcharge'),
192
            $input->param('rentalcharge'),
193
            $input->param('defaultreplacecost'),
194
            $input->param('processfee'),
187
            $input->param('notforloan') ? 1 : 0,
195
            $input->param('notforloan') ? 1 : 0,
188
            $image eq 'removeImage' ?           ''                 :
196
            $image eq 'removeImage' ?           ''                 :
189
            $image eq 'remoteImage' ? $input->param('remoteImage') :
197
            $image eq 'remoteImage' ? $input->param('remoteImage') :
Lines 250-255 else { # DEFAULT Link Here
250
    foreach my $itemtype ( @{$results} ) {
258
    foreach my $itemtype ( @{$results} ) {
251
        $itemtype->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtype->{imageurl} );
259
        $itemtype->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtype->{imageurl} );
252
        $itemtype->{rentalcharge} = sprintf( '%.2f', $itemtype->{rentalcharge} );
260
        $itemtype->{rentalcharge} = sprintf( '%.2f', $itemtype->{rentalcharge} );
261
        $itemtype->{defaultreplacecost} = sprintf( '%.2f', $itemtype->{defaultreplacecost} );
262
        $itemtype->{processfee} = sprintf( '%.2f', $itemtype->{processfee} );
253
        push( @loop, $itemtype );
263
        push( @loop, $itemtype );
254
    }
264
    }
255
265
(-)a/installer/data/mysql/kohastructure.sql (+2 lines)
Lines 1270-1275 CREATE TABLE `itemtypes` ( -- defines the item types Link Here
1270
  itemtype varchar(10) NOT NULL default '', -- unique key, a code associated with the item type
1270
  itemtype varchar(10) NOT NULL default '', -- unique key, a code associated with the item type
1271
  description mediumtext, -- a plain text explanation of the item type
1271
  description mediumtext, -- a plain text explanation of the item type
1272
  rentalcharge double(16,4) default NULL, -- the amount charged when this item is checked out/issued
1272
  rentalcharge double(16,4) default NULL, -- the amount charged when this item is checked out/issued
1273
  defaultreplacecost double(16,4) default NULL, -- default replacement cost
1274
  processfee double(16,4) default NULL, -- default text be recorded in the column note when the processing fee is applied
1273
  notforloan smallint(6) default NULL, -- 1 if the item is not for loan, 0 if the item is available for loan
1275
  notforloan smallint(6) default NULL, -- 1 if the item is not for loan, 0 if the item is available for loan
1274
  imageurl varchar(200) default NULL, -- URL for the item type icon
1276
  imageurl varchar(200) default NULL, -- URL for the item type icon
1275
  summary text, -- information from the summary field, may include HTML
1277
  summary text, -- information from the summary field, may include HTML
(-)a/installer/data/mysql/sysprefs.sql (+2 lines)
Lines 340-345 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
340
('previousIssuesDefaultSortOrder','asc','asc|desc','Specify the sort order of Previous Issues on the circulation page','Choice'),
340
('previousIssuesDefaultSortOrder','asc','asc|desc','Specify the sort order of Previous Issues on the circulation page','Choice'),
341
('printcirculationslips','1','','If ON, enable printing circulation receipts','YesNo'),
341
('printcirculationslips','1','','If ON, enable printing circulation receipts','YesNo'),
342
('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'),
342
('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'),
343
('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'),
343
('QueryAutoTruncate','1',NULL,'If ON, query truncation is enabled by default','YesNo'),
344
('QueryAutoTruncate','1',NULL,'If ON, query truncation is enabled by default','YesNo'),
344
('QueryFuzzy','1',NULL,'If ON, enables fuzzy option for searches','YesNo'),
345
('QueryFuzzy','1',NULL,'If ON, enables fuzzy option for searches','YesNo'),
345
('QueryStemming','1',NULL,'If ON, enables query stemming','YesNo'),
346
('QueryStemming','1',NULL,'If ON, enables query stemming','YesNo'),
Lines 455-460 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
455
('UseControlNumber','0','','If ON, record control number (w subfields) and control number (001) are used for linking of bibliographic records.','YesNo'),
456
('UseControlNumber','0','','If ON, record control number (w subfields) and control number (001) are used for linking of bibliographic records.','YesNo'),
456
('UseCourseReserves','0',NULL,'Enable the course reserves feature.','YesNo'),
457
('UseCourseReserves','0',NULL,'Enable the course reserves feature.','YesNo'),
457
('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'),
458
('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'),
459
('useDefaultReplacementCost', '0', NULL, 'default replacement cost defined in item type', 'YesNo'),
458
('UseICU','0','1','Tell Koha if ICU indexing is in use for Zebra or not.','YesNo'),
460
('UseICU','0','1','Tell Koha if ICU indexing is in use for Zebra or not.','YesNo'),
459
('UseKohaPlugins','0','','Enable or disable the ability to use Koha Plugins.','YesNo'),
461
('UseKohaPlugins','0','','Enable or disable the ability to use Koha Plugins.','YesNo'),
460
('UseQueryParser','0',NULL,'If enabled, try to use QueryParser for queries.','YesNo'),
462
('UseQueryParser','0',NULL,'If enabled, try to use QueryParser for queries.','YesNo'),
(-)a/installer/data/mysql/updatedatabase.pl (+10 lines)
Lines 9585-9590 if ( CheckVersion($DBversion) ) { Link Here
9585
    SetVersion ($DBversion);
9585
    SetVersion ($DBversion);
9586
}
9586
}
9587
9587
9588
$DBversion = 'XXX';
9589
if ( CheckVersion($DBversion) ) {
9590
    $dbh->do("ALTER TABLE  `itemtypes` ADD  `defaultreplacecost` DOUBLE( 16, 4 ) NULL DEFAULT NULL AFTER  `rentalcharge`");
9591
    $dbh->do("ALTER TABLE  `itemtypes` ADD  `processfee` DOUBLE( 16, 4 ) NULL DEFAULT NULL AFTER  `defaultreplacecost`");
9592
    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,type) VALUES('useDefaultReplacementCost',0,'default replacement cost defined in item type','YesNo')");
9593
    $dbh->do("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')");
9594
    print "Upgrade to $DBversion done (Bug 12768 - Replacement cost and processing fee management)\n";
9595
    SetVersion($DBversion);
9596
}
9597
9588
=head1 FUNCTIONS
9598
=head1 FUNCTIONS
9589
9599
9590
=head2 TableExists($table)
9600
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css (+4 lines)
Lines 591-596 fieldset.rows fieldset { Link Here
591
	width: 9em;  
591
	width: 9em;  
592
}
592
}
593
593
594
.yui-b fieldset.rows ol.oladditemtype label, .yui-b fieldset.rows ol.oladditemtype span.label {
595
    width: 13em;
596
}
597
594
.yui-b fieldset.rows div.hint {
598
.yui-b fieldset.rows div.hint {
595
	margin-left : 10.5em;
599
	margin-left : 10.5em;
596
}
600
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt (-2 / +14 lines)
Lines 162-168 Item types administration Link Here
162
</div>
162
</div>
163
</div>
163
</div>
164
[% END %]
164
[% END %]
165
<ol>
165
<ol class="oladditemtype">
166
      <li>
166
      <li>
167
          <label for="notforloan">Not for loan: </label>   [% IF ( notforloan ) %]
167
          <label for="notforloan">Not for loan: </label>   [% IF ( notforloan ) %]
168
                <input type="checkbox" id="notforloan" name="notforloan" checked="checked" value="1" />
168
                <input type="checkbox" id="notforloan" name="notforloan" checked="checked" value="1" />
Lines 175-181 Item types administration Link Here
175
      <li>
175
      <li>
176
          <label for="rentalcharge">Rental charge: </label>
176
          <label for="rentalcharge">Rental charge: </label>
177
		  <input type="text" id="rentalcharge" name="rentalcharge" size="10" value="[% rentalcharge %]" />
177
		  <input type="text" id="rentalcharge" name="rentalcharge" size="10" value="[% rentalcharge %]" />
178
         </li>
178
      </li>
179
      <li>
180
          <label for="defaultreplacecost">Default replacement cost: </label>
181
          <input type="text" id="defaultreplacecost" name="defaultreplacecost" size="10" value="[% defaultreplacecost %]" />
182
      </li>
183
      <li>
184
          <label for="processfee">Processing fee (when lost): </label>
185
          <input type="text" id="processfee" name="processfee" size="10" value="[% processfee %]" />
186
      </li>
179
      <li>
187
      <li>
180
          <label for="checkinmsg">Checkin message: </label>
188
          <label for="checkinmsg">Checkin message: </label>
181
          <textarea id="checkinmsg" name="checkinmsg" cols="55" rows="5">[% checkinmsg %]</textarea>
189
          <textarea id="checkinmsg" name="checkinmsg" cols="55" rows="5">[% checkinmsg %]</textarea>
Lines 262-267 Item types administration Link Here
262
    <th>Description</th>
270
    <th>Description</th>
263
    <th>Not for loan</th>
271
    <th>Not for loan</th>
264
    <th>Charge</th>
272
    <th>Charge</th>
273
    <th>Default replacement cost</th>
274
    <th>Processing fee (when lost)</th>
265
    <th>Checkin message</th>
275
    <th>Checkin message</th>
266
    <th>Actions</th>
276
    <th>Actions</th>
267
  </thead>
277
  </thead>
Lines 280-285 Item types administration Link Here
280
      [% loo.rentalcharge %]
290
      [% loo.rentalcharge %]
281
    [% END %]
291
    [% END %]
282
    </td>
292
    </td>
293
    <td>[% loo.defaultreplacecost %]</td>
294
    <td>[% loo.processfee %]</td>
283
    <td>[% loo.checkinmsg | html_line_break %]</td>
295
    <td>[% loo.checkinmsg | html_line_break %]</td>
284
    <td>
296
    <td>
285
      <a href="[% loo.script_name %]?op=add_form&amp;itemtype=[% loo.itemtype |html %]">Edit</a>
297
      <a href="[% loo.script_name %]?op=add_form&amp;itemtype=[% loo.itemtype |html %]">Edit</a>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref (+12 lines)
Lines 632-637 Circulation: Link Here
632
                  yes: Charge
632
                  yes: Charge
633
                  no: "Don't Charge"
633
                  no: "Don't Charge"
634
            - the replacement price when a patron loses an item.
634
            - the replacement price when a patron loses an item.
635
        -
636
            - pref: useDefaultReplacementCost
637
              choices:
638
                  yes: use
639
                  no: "Don't use"
640
            - the default replacement cost defined in item type.
641
        -
642
            - "Set the text to be recorded in the column 'note', table 'accountlines' when the processing fee (defined in item type) is applied."
643
            - pref: ProcessingFeeNote
644
              type: textarea
645
              class: code
646
635
    Self Checkout:
647
    Self Checkout:
636
        -
648
        -
637
            - "Include the following JavaScript on all pages in the web-based self checkout:"
649
            - "Include the following JavaScript on all pages in the web-based self checkout:"
(-)a/t/db_dependent/Circulation/Chargelostitem.t (-1 / +89 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
#
3
# This Koha test module is a stub!
4
# Add more tests here!!!
5
6
use strict;
7
use warnings;
8
use Modern::Perl;
9
10
use Test::MockModule;
11
use C4::Biblio;
12
use C4::Items;
13
use C4::Members;
14
use C4::Branch;
15
use C4::Category;
16
use C4::Circulation;
17
use MARC::Record;
18
use Test::More tests => 7;
19
20
BEGIN {
21
    use_ok('C4::Accounts');
22
}
23
24
my $dbh = C4::Context->dbh;
25
$dbh->{AutoCommit} = 0;
26
$dbh->{RaiseError} = 1;
27
$dbh->do(q|DELETE FROM accountlines|);
28
29
my $branchcode;
30
my $branch_created;
31
my @branches = keys %{ GetBranches() };
32
if (@branches) {
33
    $branchcode = $branches[0];
34
} else {
35
    $branchcode = 'B';
36
    ModBranch({ add => 1, branchcode => $branchcode, branchname => 'Branch' });
37
    $branch_created = 1;
38
}
39
40
my %item_branch_infos = (
41
    homebranch => $branchcode,
42
    holdingbranch => $branchcode,
43
);
44
45
my ($biblionumber1) = AddBiblio(MARC::Record->new, '');
46
my $itemnumber1 = AddItem({ barcode => '0101', %item_branch_infos }, $biblionumber1);
47
my $itemnumber2 = AddItem({ barcode => '0102', %item_branch_infos }, $biblionumber1);
48
49
my ($biblionumber2) = AddBiblio(MARC::Record->new, '');
50
my $itemnumber3 = AddItem({ barcode => '0203', %item_branch_infos }, $biblionumber2);
51
52
my $categorycode;
53
my $category_created;
54
my @categories = C4::Category->all;
55
if (@categories) {
56
    $categorycode = $categories[0]->{categorycode}
57
} else {
58
    $categorycode = 'C';
59
    C4::Context->dbh->do(
60
        "INSERT INTO categories(categorycode) VALUES(?)", undef, $categorycode);
61
    $category_created = 1;
62
}
63
64
my $borrowernumber = AddMember(categorycode => $categorycode, branchcode => $branchcode);
65
my $borrower = GetMember(borrowernumber => $borrowernumber);
66
67
# Need to mock userenv for AddIssue
68
my $module = new Test::MockModule('C4::Context');
69
$module->mock('userenv', sub { { branch => $branchcode } });
70
AddIssue($borrower, '0101');
71
AddIssue($borrower, '0203');
72
73
# Begin tests...
74
my $processfee = 10;
75
my $issues;
76
$issues = C4::Circulation::GetIssues({biblionumber => $biblionumber1});
77
my $issue=$issues->[0];
78
$issue->{'processfee'} = $processfee;
79
my $accountlineId = C4::Accounts::chargelostitem($issue, 'test');
80
81
my @accountline = C4::Accounts::getcharges($borrowernumber, $accountlineId);
82
83
is( scalar(@accountline), 1, 'accountline should have 1 row' );
84
is( int($accountline[0]->{amount}), $processfee, "The accountline amount should be precessfee value " );
85
is( $accountline[0]->{accounttype}, 'PF', "The accountline accounttype should be PF " );
86
is( $accountline[0]->{borrowernumber}, $borrowernumber, "The accountline borrowernumber should be the exemple borrownumber" );
87
my $itemnumber = C4::Items::GetItemnumberFromBarcode('0101');
88
is( $accountline[0]->{itemnumber}, $itemnumber, "The accountline itemnumber should the linked with barcode '0101'" );
89
is( $accountline[0]->{description}, 'test', "The accountline description should be 'test'" );

Return to bug 12768