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

(-)a/Koha/Charges/Sales.pm (-2 / +3 lines)
Lines 20-25 package Koha::Charges::Sales; Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Koha::Account::Lines;
22
use Koha::Account::Lines;
23
use Koha::Account::DebitTypes;
23
use Koha::Account::Offsets;
24
use Koha::Account::Offsets;
24
use Koha::DateUtils qw( dt_from_string );
25
use Koha::DateUtils qw( dt_from_string );
25
use Koha::Exceptions;
26
use Koha::Exceptions;
Lines 210-216 sub purchase { Link Here
210
                my $debit = Koha::Account::Line->new(
211
                my $debit = Koha::Account::Line->new(
211
                    {
212
                    {
212
                        amount            => $amount,
213
                        amount            => $amount,
213
                        accounttype       => $item->{code},
214
                        debit_type_code   => $item->{code},
214
                        amountoutstanding => 0,
215
                        amountoutstanding => 0,
215
                        note              => $item->{quantity},
216
                        note              => $item->{quantity},
216
                        manager_id        => $self->{staff_id},
217
                        manager_id        => $self->{staff_id},
Lines 235-241 sub purchase { Link Here
235
            $credit = Koha::Account::Line->new(
236
            $credit = Koha::Account::Line->new(
236
                {
237
                {
237
                    amount            => 0 - $total_owed,
238
                    amount            => 0 - $total_owed,
238
                    accounttype       => 'Purchase',
239
                    credit_type_code  => 'PURCHASE',
239
                    payment_type      => $self->{payment_type},
240
                    payment_type      => $self->{payment_type},
240
                    amountoutstanding => 0,
241
                    amountoutstanding => 0,
241
                    manager_id        => $self->{staff_id},
242
                    manager_id        => $self->{staff_id},
(-)a/installer/data/mysql/account_credit_types.sql (-1 / +2 lines)
Lines 4-9 INSERT INTO account_credit_types ( code, description, can_be_added_manually, is_ Link Here
4
('FORGIVEN', 'Forgiven', 1, 1),
4
('FORGIVEN', 'Forgiven', 1, 1),
5
('CREDIT', 'Credit', 1, 1),
5
('CREDIT', 'Credit', 1, 1),
6
('REFUND', 'A refund applied to a patrons fine', 0, 1),
6
('REFUND', 'A refund applied to a patrons fine', 0, 1),
7
('LOST_RETURN', 'Lost item fee refund', 0, 1);
7
('LOST_RETURN', 'Lost item fee refund', 0, 1),
8
('PURCHASE', 'Purchase', 0, 1);
8
9
9
INSERT INTO authorised_values (category,authorised_value,lib) VALUES ('PAYMENT_TYPE','CASH','Cash');
10
INSERT INTO authorised_values (category,authorised_value,lib) VALUES ('PAYMENT_TYPE','CASH','Cash');
(-)a/installer/data/mysql/atomicupdate/bug_23354.perl (-2 / +8 lines)
Lines 5-10 if( CheckVersion( $DBversion ) ) { Link Here
5
        INSERT IGNORE INTO account_offset_types ( type ) VALUES ( 'Purchase' );
5
        INSERT IGNORE INTO account_offset_types ( type ) VALUES ( 'Purchase' );
6
    });
6
    });
7
7
8
    $dbh->do(q{
9
        INSERT INTO account_credit_types ( code, description, can_be_added_manually, is_system )
10
        VALUES ('PURCHASE', 'Purchase', 0, 1);
11
    });
12
8
    my $sth = $dbh->prepare(q{
13
    my $sth = $dbh->prepare(q{
9
        SELECT COUNT(*) FROM authorised_values WHERE category = 'PAYMENT_TYPE' AND authorised_value = 'CASH'
14
        SELECT COUNT(*) FROM authorised_values WHERE category = 'PAYMENT_TYPE' AND authorised_value = 'CASH'
10
    });
15
    });
Lines 40-46 if( CheckVersion( $DBversion ) ) { Link Here
40
45
41
    $dbh->do(q{
46
    $dbh->do(q{
42
INSERT IGNORE INTO `letter` (`module`, `code`, `branchcode`, `name`, `is_html`, `title`, `content`, `message_transport_type`, `lang`) VALUES
47
INSERT IGNORE INTO `letter` (`module`, `code`, `branchcode`, `name`, `is_html`, `title`, `content`, `message_transport_type`, `lang`) VALUES
43
('pos', 'RECEIPT', '', 'Point of sale receipt', 0, 'Receipt', '<table>
48
('pos', 'RECEIPT', '', 'Point of sale receipt', 0, 'Receipt', '[% PROCESS "accounts.inc" %]
49
<table>
44
[% IF ( LibraryName ) %]
50
[% IF ( LibraryName ) %]
45
 <tr>
51
 <tr>
46
    <th colspan="2" class="centerednames">
52
    <th colspan="2" class="centerednames">
Lines 83-89 INSERT IGNORE INTO `letter` (`module`, `code`, `branchcode`, `name`, `is_html`, Link Here
83
89
84
  [% FOREACH offset IN offsets %]
90
  [% FOREACH offset IN offsets %]
85
    <tr>
91
    <tr>
86
        <td>[% offset.debit.accounttype %]</td>
92
        <td>[% PROCESS account_type_description account=offset.debit %]</td>
87
        <td>[% offset.amount * -1 | $Price %]</td>
93
        <td>[% offset.amount * -1 | $Price %]</td>
88
    </tr>
94
    </tr>
89
  [% END %]
95
  [% END %]
(-)a/installer/data/mysql/en/mandatory/sample_notices.sql (-2 / +3 lines)
Lines 318-324 INSERT INTO `letter` (`module`, `code`, `branchcode`, `name`, `is_html`, `title` Link Here
318
('circulation', 'SR_SLIP', '', 'Stock rotation slip', 0, 'Stock rotation report', 'Stock rotation report for [% branch.name %]:\r\n\r\n[% IF branch.items.size %][% branch.items.size %] items to be processed for this branch.\r\n[% ELSE %]No items to be processed for this branch\r\n[% END %][% FOREACH item IN branch.items %][% IF item.reason != \'in-demand\' %]Title: [% item.title %]\r\nAuthor: [% item.author %]\r\nCallnumber: [% item.callnumber %]\r\nLocation: [% item.location %]\r\nBarcode: [% item.barcode %]\r\nOn loan?: [% item.onloan %]\r\nStatus: [% item.reason %]\r\nCurrent library: [% item.branch.branchname %] [% item.branch.branchcode %]\r\n\r\n[% END %][% END %]', 'email');
318
('circulation', 'SR_SLIP', '', 'Stock rotation slip', 0, 'Stock rotation report', 'Stock rotation report for [% branch.name %]:\r\n\r\n[% IF branch.items.size %][% branch.items.size %] items to be processed for this branch.\r\n[% ELSE %]No items to be processed for this branch\r\n[% END %][% FOREACH item IN branch.items %][% IF item.reason != \'in-demand\' %]Title: [% item.title %]\r\nAuthor: [% item.author %]\r\nCallnumber: [% item.callnumber %]\r\nLocation: [% item.location %]\r\nBarcode: [% item.barcode %]\r\nOn loan?: [% item.onloan %]\r\nStatus: [% item.reason %]\r\nCurrent library: [% item.branch.branchname %] [% item.branch.branchcode %]\r\n\r\n[% END %][% END %]', 'email');
319
319
320
INSERT IGNORE INTO `letter` (`module`, `code`, `branchcode`, `name`, `is_html`, `title`, `content`, `message_transport_type`, `lang`) VALUES
320
INSERT IGNORE INTO `letter` (`module`, `code`, `branchcode`, `name`, `is_html`, `title`, `content`, `message_transport_type`, `lang`) VALUES
321
('pos', 'RECEIPT', '', 'Point of sale receipt', 0, 'Receipt', '<table>
321
('pos', 'RECEIPT', '', 'Point of sale receipt', 0, 'Receipt', '[% PROCESS "accounts.inc" %]
322
<table>
322
[% IF ( LibraryName ) %]
323
[% IF ( LibraryName ) %]
323
 <tr>
324
 <tr>
324
    <th colspan="2" class="centerednames">
325
    <th colspan="2" class="centerednames">
Lines 361-367 INSERT IGNORE INTO `letter` (`module`, `code`, `branchcode`, `name`, `is_html`, Link Here
361
362
362
  [% FOREACH offset IN offsets %]
363
  [% FOREACH offset IN offsets %]
363
    <tr>
364
    <tr>
364
        <td>[% offset.debit.accounttype %]</td>
365
        <td>[% PROCESS account_type_description account=offset.debit %]</td>
365
        <td>[% offset.amount * -1 | $Price %]</td>
366
        <td>[% offset.amount * -1 | $Price %]</td>
366
    </tr>
367
    </tr>
367
  [% END %]
368
  [% END %]
(-)a/t/db_dependent/Koha/Charges/Sales.pm (-20 / +13 lines)
Lines 138-158 subtest 'add_item (_get_valid_items) tests' => sub { Link Here
138
      'Exception thrown if `code` parameter is missing';
138
      'Exception thrown if `code` parameter is missing';
139
139
140
    my $library2 = $builder->build_object( { class => 'Koha::Libraries' } );
140
    my $library2 = $builder->build_object( { class => 'Koha::Libraries' } );
141
    my $av = Koha::AuthorisedValue->new(
141
    my $dt = Koha::Account::DebitType->new(
142
        {
142
        {
143
            category         => 'MANUAL_INV',
143
            code        => 'BOBBYRANDOM',
144
            authorised_value => 'BOBBYRANDOM',
144
            description => 'Test bobbyrandom',
145
            lib              => 'Test bobbyrandom',
146
            lib_opac         => 'Test bobbyrandom',
147
        }
145
        }
148
    )->store;
146
    )->store;
149
    $av->replace_library_limits( [ $library2->branchcode ] );
147
    $dt->replace_library_limits( [ $library2->branchcode ] );
150
148
151
    throws_ok { $sale->add_item( { code => 'BOBBYRANDOM' } ) }
149
    throws_ok { $sale->add_item( { code => 'BOBBYRANDOM' } ) }
152
    'Koha::Exceptions::Account::UnrecognisedType',
150
    'Koha::Exceptions::Account::UnrecognisedType',
153
'Exception thrown if passed an item code that is not valid for the cash registers branch';
151
'Exception thrown if passed an item code that is not valid for the cash registers branch';
154
152
155
    $av->replace_library_limits();
153
    $dt->replace_library_limits();
156
    $sale->{valid_items} = undef;    # Flush object cache for 'valid_items'
154
    $sale->{valid_items} = undef;    # Flush object cache for 'valid_items'
157
155
158
    throws_ok {
156
    throws_ok {
Lines 205-224 subtest 'purchase tests' => sub { Link Here
205
        }
203
        }
206
    )->store;
204
    )->store;
207
205
208
    my $item1 = Koha::AuthorisedValue->new(
206
    my $item1 = Koha::Account::DebitType->new(
209
        {
207
        {
210
            category         => 'MANUAL_INV',
208
            code        => 'COPYRANDOM',
211
            authorised_value => 'COPYRANDOM',
209
            description => 'Copier fee',
212
            lib              => 'Copier fee',
213
            lib_opac         => 'Copier fee',
214
        }
210
        }
215
    )->store;
211
    )->store;
216
    my $item2 = Koha::AuthorisedValue->new(
212
    my $item2 = Koha::Account::DebitType->new(
217
        {
213
        {
218
            category         => 'MANUAL_INV',
214
            code        => 'CARDRANDOM',
219
            authorised_value => 'CARDRANDOM',
215
            description => 'New card fee',
220
            lib              => 'New card fee',
221
            lib_opac         => 'New card fee',
222
        }
216
        }
223
    )->store;
217
    )->store;
224
218
Lines 250-256 subtest 'purchase tests' => sub { Link Here
250
244
251
    is(ref($credit), 'Koha::Account::Line', "Koha::Account::Line returned");
245
    is(ref($credit), 'Koha::Account::Line', "Koha::Account::Line returned");
252
    ok($credit->is_credit, "return is a credit for payment");
246
    ok($credit->is_credit, "return is a credit for payment");
253
    is($credit->accounttype, 'Purchase', "accounttype set correctly to 'Purchase' for payment");
247
    is($credit->credit_type_code, 'PURCHASE', "credit_type_code set correctly to 'PURCHASE' for payment");
254
    is($credit->amount, -5.00, "amount is calculated correctly for payment");
248
    is($credit->amount, -5.00, "amount is calculated correctly for payment");
255
    is($credit->amountoutstanding, 0.00, "amountoutstanding is set to zero for payment");
249
    is($credit->amountoutstanding, 0.00, "amountoutstanding is set to zero for payment");
256
    is($credit->manager_id, $staff->borrowernumber, "manager_id set correctionly for payment");
250
    is($credit->manager_id, $staff->borrowernumber, "manager_id set correctionly for payment");
Lines 258-264 subtest 'purchase tests' => sub { Link Here
258
    is($credit->payment_type, 'CASH', "payment_type set correctly for payment");
252
    is($credit->payment_type, 'CASH', "payment_type set correctly for payment");
259
253
260
    my $offsets = Koha::Account::Offsets->search({credit_id => $credit->accountlines_id});
254
    my $offsets = Koha::Account::Offsets->search({credit_id => $credit->accountlines_id});
261
    is($offsets->count, 2, "One offset was added for each item added");
255
    is($offsets->count, 3, "One offset was added for each item added"); # 2 items + 1 purchase
262
256
263
#ensure relevant fields are set
257
#ensure relevant fields are set
264
#ensure register_id is only ever set with a corresponding payment_type having been set
258
#ensure register_id is only ever set with a corresponding payment_type having been set
265
- 

Return to bug 23354