1 package Koha::Cash::Register::Cashup;
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
24 use base qw(Koha::Cash::Register::Action);
28 Koha::Cash::Register::Actions - Koha Cash Register Action Object set class
36 my $cashup = Koha::Cash::Register::Actions::Cashup->search( $where, $attr );
38 Returns a list of cash register cashup.
43 my ( $self, $where, $attr ) = @_;
45 $where->{code} = 'CASHUP';
47 unless ( exists $attr->{order_by} ) {
49 [ { '-asc' => 'register_id' }, { '-desc' => 'timestamp' } ];
52 return $self->SUPER::search( $where, $attr );
57 my $summary = $cashup->summary;
59 Return a hashref containing a summary of transactions that make up this cashup.
66 my $prior_cashup = Koha::Cash::Register::Cashups->search(
68 'timestamp' => { '<' => $self->timestamp },
69 register_id => $self->register_id
72 order_by => { '-desc' => [ 'timestamp', 'id' ] },
77 my $previous = $prior_cashup->single;
84 [ $previous->_result->get_column('timestamp'), $self->timestamp ]
87 : { 'date' => { '<' => $self->timestamp } };
89 my $payout_transactions = $self->register->accountlines->search(
90 { %{$conditions}, credit_type_code => undef },
92 my $income_transactions = $self->register->accountlines->search(
93 { %{$conditions}, debit_type_code => undef },
96 my $income_summary = Koha::Account::Offsets->search(
99 '-in' => $income_transactions->_resultset->get_column(
100 'accountlines_id')->as_query
102 'me.debit_id' => { '!=' => undef }
105 join => { 'debit' => 'debit_type_code' },
107 [ 'debit.debit_type_code', 'debit_type_code.description' ],
109 { sum => 'me.amount' }, 'debit.debit_type_code',
110 'debit_type_code.description'
112 'as' => [ 'total', 'debit_type_code', 'debit_description' ],
113 order_by => { '-asc' => 'debit_type_code.description' },
117 my $payout_summary = Koha::Account::Offsets->search(
120 '-in' => $payout_transactions->_resultset->get_column(
121 'accountlines_id')->as_query
123 'me.credit_id' => { '!=' => undef }
126 join => { 'credit' => 'credit_type_code' },
128 [ 'credit.credit_type_code', 'credit_type_code.description' ],
130 { sum => 'me.amount' }, 'credit.credit_type_code',
131 'credit_type_code.description'
133 'as' => [ 'total', 'credit_type_code', 'credit_description' ],
134 order_by => { '-asc' => 'credit_type_code.description' },
140 total => $_->get_column('total') * -1,
141 debit_type_code => $_->get_column('debit_type_code'),
142 debit_type => { description => $_->get_column('debit_description') }
144 } $income_summary->as_list;
147 total => $_->get_column('total') * -1,
148 credit_type_code => $_->get_column('credit_type_code'),
150 { description => $_->get_column('credit_description') }
152 } $payout_summary->as_list;
154 my $income_total = $income_transactions->total;
155 my $payout_total = $payout_transactions->total;
156 my $total = ( $income_total + $payout_total );
158 my $payment_types = Koha::AuthorisedValues->search(
160 category => 'PAYMENT_TYPE'
168 for my $type ( $payment_types->as_list ) {
169 my $typed_income = $income_transactions->total( { payment_type => $type->authorised_value } );
170 my $typed_payout = $payout_transactions->total( { payment_type => $type->authorised_value } );
171 my $typed_total = ( $typed_income + $typed_payout );
172 push @total_grouped, { payment_type => $type->lib, total => $typed_total };
176 from_date => $previous ? $previous->timestamp : undef,
177 to_date => $self->timestamp,
178 income_grouped => \@income,
179 income_total => abs($income_total),
180 payout_grouped => \@payout,
181 payout_total => abs($payout_total),
182 total => $total * -1,
183 total_grouped => \@total_grouped
189 =head3 to_api_mapping
191 This method returns the mapping for representing a Koha::Cash::Regiser::Cashup object
199 register_id => 'cash_register_id',
208 Martin Renvoize <martin.renvoize@ptfs-europe.com>