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

(-)a/C4/Circulation.pm (-7 / +9 lines)
Lines 1406-1412 sub AddIssue { Link Here
1406
           # If it costs to borrow this book, charge it to the patron's account.
1406
           # If it costs to borrow this book, charge it to the patron's account.
1407
            my ( $charge, $itemtype ) = GetIssuingCharges( $item->{'itemnumber'}, $borrower->{'borrowernumber'} );
1407
            my ( $charge, $itemtype ) = GetIssuingCharges( $item->{'itemnumber'}, $borrower->{'borrowernumber'} );
1408
            if ( $charge > 0 ) {
1408
            if ( $charge > 0 ) {
1409
                AddIssuingCharge( $item->{'itemnumber'}, $borrower->{'borrowernumber'}, $issue->id, $charge );
1409
                AddIssuingCharge( $issue, $charge );
1410
                $item->{'charge'} = $charge;
1410
                $item->{'charge'} = $charge;
1411
            }
1411
            }
1412
1412
Lines 3165-3187 sub _get_discount_from_rule { Link Here
3165
3165
3166
=head2 AddIssuingCharge
3166
=head2 AddIssuingCharge
3167
3167
3168
  &AddIssuingCharge( $itemno, $borrowernumber, $issue_id, $charge )
3168
  &AddIssuingCharge( $checkout, $charge )
3169
3169
3170
=cut
3170
=cut
3171
3171
3172
sub AddIssuingCharge {
3172
sub AddIssuingCharge {
3173
    my ( $itemnumber, $borrowernumber, $issue_id, $charge ) = @_;
3173
    my ( $checkout, $charge ) = @_;
3174
3174
3175
    my $nextaccntno = getnextacctno($borrowernumber);
3175
    # FIXME What if checkout does not exist?
3176
3177
    my $nextaccntno = getnextacctno($checkout->borrowernumber);
3176
3178
3177
    my $manager_id  = 0;
3179
    my $manager_id  = 0;
3178
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
3180
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
3179
3181
3180
    my $accountline = Koha::Account::Line->new(
3182
    my $accountline = Koha::Account::Line->new(
3181
        {
3183
        {
3182
            borrowernumber    => $borrowernumber,
3184
            borrowernumber    => $checkout->borrowernumber,
3183
            itemnumber        => $itemnumber,
3185
            itemnumber        => $checkout->itemnumber,
3184
            issue_id          => $issue_id,
3186
            issue_id          => $checkout->issue_id,
3185
            accountno         => $nextaccntno,
3187
            accountno         => $nextaccntno,
3186
            amount            => $charge,
3188
            amount            => $charge,
3187
            amountoutstanding => $charge,
3189
            amountoutstanding => $charge,
(-)a/t/db_dependent/Circulation/issue.t (-4 / +4 lines)
Lines 29-34 use C4::Context; Link Here
29
use C4::Items;
29
use C4::Items;
30
use C4::Members;
30
use C4::Members;
31
use C4::Reserves;
31
use C4::Reserves;
32
use Koha::Checkouts;
32
use Koha::Database;
33
use Koha::Database;
33
use Koha::DateUtils;
34
use Koha::DateUtils;
34
use Koha::Holds;
35
use Koha::Holds;
Lines 191-201 like( Link Here
191
    qr/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/,
192
    qr/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/,
192
    "Koha::Schema::Result::Issue->date_due() returns a date"
193
    "Koha::Schema::Result::Issue->date_due() returns a date"
193
);
194
);
194
my $issue_id1 = $dbh->last_insert_id( undef, undef, 'issues', undef );
195
my $issue_id1 = $issue1->issue_id;
195
196
196
my $issue2 = C4::Circulation::AddIssue( $borrower_1, 'nonexistent_barcode' );
197
my $issue2 = C4::Circulation::AddIssue( $borrower_1, 'nonexistent_barcode' );
197
is( $issue2, undef, "AddIssue returns undef if no datedue is specified" );
198
is( $issue2, undef, "AddIssue returns undef if no datedue is specified" );
198
my $issue_id2 = $dbh->last_insert_id( undef, undef, 'issues', undef );
199
199
200
$sth->execute;
200
$sth->execute;
201
$countissue = $sth -> fetchrow_array;
201
$countissue = $sth -> fetchrow_array;
Lines 207-213 $sth = $dbh->prepare($query); Link Here
207
$sth->execute;
207
$sth->execute;
208
my $countaccount = $sth -> fetchrow_array;
208
my $countaccount = $sth -> fetchrow_array;
209
is ($countaccount,0,"0 accountline exists");
209
is ($countaccount,0,"0 accountline exists");
210
my $offset = C4::Circulation::AddIssuingCharge( $item_id1, $borrower_id1, $issue_id1, 10 );
210
my $checkout = Koha::Checkouts->find( $issue_id1 );
211
my $offset = C4::Circulation::AddIssuingCharge( $checkout, 10 );
211
is( ref( $offset ), 'Koha::Account::Offset', "An issuing charge has been added" );
212
is( ref( $offset ), 'Koha::Account::Offset', "An issuing charge has been added" );
212
my $charge = Koha::Account::Lines->find( $offset->debit_id );
213
my $charge = Koha::Account::Lines->find( $offset->debit_id );
213
is( $charge->issue_id, $issue_id1, 'Issue id is set correctly for issuing charge' );
214
is( $charge->issue_id, $issue_id1, 'Issue id is set correctly for issuing charge' );
214
- 

Return to bug 20562