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

(-)a/Koha/Charges/Sales.pm (-21 / +13 lines)
Lines 196-202 sub purchase { Link Here
196
    my $schema     = Koha::Database->new->schema;
196
    my $schema     = Koha::Database->new->schema;
197
    my $dt         = dt_from_string();
197
    my $dt         = dt_from_string();
198
    my $total_owed = 0;
198
    my $total_owed = 0;
199
    my $credit;
199
    my $payment;
200
200
201
    $schema->txn_do(
201
    $schema->txn_do(
202
        sub {
202
        sub {
Lines 213-219 sub purchase { Link Here
213
                    {
213
                    {
214
                        amount            => $amount,
214
                        amount            => $amount,
215
                        debit_type_code   => $item->{code},
215
                        debit_type_code   => $item->{code},
216
                        amountoutstanding => 0,
216
                        amountoutstanding => $amount,
217
                        note              => $item->{quantity},
217
                        note              => $item->{quantity},
218
                        manager_id        => $self->{staff_id},
218
                        manager_id        => $self->{staff_id},
219
                        interface         => 'intranet',
219
                        interface         => 'intranet',
Lines 227-245 sub purchase { Link Here
227
                my $account_offset = Koha::Account::Offset->new(
227
                my $account_offset = Koha::Account::Offset->new(
228
                    {
228
                    {
229
                        debit_id => $debit->id,
229
                        debit_id => $debit->id,
230
                        type     => 'Purchase',
230
                        type     => 'CREATE',
231
                        amount   => $amount
231
                        amount   => $amount
232
                    }
232
                    }
233
                )->store();
233
                )->store();
234
            }
234
            }
235
235
236
            # Add accountline for payment
236
            # Add accountline for payment
237
            $credit = Koha::Account::Line->new(
237
            $payment = Koha::Account::Line->new(
238
                {
238
                {
239
                    amount            => 0 - $total_owed,
239
                    amount            => 0 - $total_owed,
240
                    credit_type_code  => 'PURCHASE',
240
                    credit_type_code  => 'PURCHASE',
241
                    payment_type      => $self->{payment_type},
241
                    payment_type      => $self->{payment_type},
242
                    amountoutstanding => 0,
242
                    amountoutstanding => 0 - $total_owed,
243
                    manager_id        => $self->{staff_id},
243
                    manager_id        => $self->{staff_id},
244
                    interface         => 'intranet',
244
                    interface         => 'intranet',
245
                    branchcode        => $self->{cash_register}->branch,
245
                    branchcode        => $self->{cash_register}->branch,
Lines 250-278 sub purchase { Link Here
250
            )->store();
250
            )->store();
251
251
252
            # Record the account offset
252
            # Record the account offset
253
            my $credit_offset = Koha::Account::Offset->new(
253
            my $payment_offset = Koha::Account::Offset->new(
254
                {
254
                {
255
                    credit_id => $credit->id,
255
                    credit_id => $payment->id,
256
                    type      => 'Purchase',
256
                    type      => 'CREATE',
257
                    amount    => $credit->amount
257
                    amount    => $payment->amount
258
                }
258
                }
259
            )->store();
259
            )->store();
260
260
261
            # Link payment to debits
261
            # Link payment to charges
262
            for my $debit ( @{$debits} ) {
262
            $payment->apply( { debits => $debits } );
263
                Koha::Account::Offset->new(
263
            $payment->discard_changes;
264
                    {
265
                        credit_id => $credit->accountlines_id,
266
                        debit_id  => $debit->id,
267
                        amount    => $debit->amount * -1,
268
                        type      => 'Payment',
269
                    }
270
                )->store();
271
            }
272
        }
264
        }
273
    );
265
    );
274
266
275
    return $credit;
267
    return $payment;
276
}
268
}
277
269
278
=head1 AUTHOR
270
=head1 AUTHOR
(-)a/t/db_dependent/Koha/Charges/Sales.t (-3 / +2 lines)
Lines 236-243 subtest 'purchase tests' => sub { Link Here
236
    is(ref($credit), 'Koha::Account::Line', "Koha::Account::Line returned");
236
    is(ref($credit), 'Koha::Account::Line', "Koha::Account::Line returned");
237
    ok($credit->is_credit, "return is a credit for payment");
237
    ok($credit->is_credit, "return is a credit for payment");
238
    is($credit->credit_type_code, 'PURCHASE', "credit_type_code set correctly to 'PURCHASE' for payment");
238
    is($credit->credit_type_code, 'PURCHASE', "credit_type_code set correctly to 'PURCHASE' for payment");
239
    is($credit->amount, -5.00, "amount is calculated correctly for payment");
239
    is($credit->amount * 1, -5, "amount is calculated correctly for payment");
240
    is($credit->amountoutstanding, 0.00, "amountoutstanding is set to zero for payment");
240
    is($credit->amountoutstanding * 1, 0, "amountoutstanding is set to zero for payment");
241
    is($credit->manager_id, $staff->borrowernumber, "manager_id set correctionly for payment");
241
    is($credit->manager_id, $staff->borrowernumber, "manager_id set correctionly for payment");
242
    is($credit->register_id, $cash_register->id, "register_id set correctly for payment");
242
    is($credit->register_id, $cash_register->id, "register_id set correctly for payment");
243
    is($credit->payment_type, 'CASH', "payment_type set correctly for payment");
243
    is($credit->payment_type, 'CASH', "payment_type set correctly for payment");
244
- 

Return to bug 22435