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>.
23 use base qw(Koha::Cash::Register::Action);
27 Koha::Cash::Register::Actions - Koha Cash Register Action Object set class
35 my $cashup = Koha::Cash::Register::Actions::Cashup->search( $where, $attr );
37 Returns a list of cash register cashup.
42 my ( $self, $where, $attr ) = @_;
44 $where->{code} = 'CASHUP';
46 unless ( exists $attr->{order_by} ) {
48 [ { '-asc' => 'register_id' }, { '-desc' => 'timestamp' } ];
51 return $self->SUPER::search( $where, $attr );
56 my $summary = $cashup->summary;
58 Return a hashref containing a summary of transactions that make up this cashup.
65 my $prior_cashup = Koha::Cash::Register::Cashups->search(
67 'timestamp' => { '<' => $self->timestamp },
68 register_id => $self->register_id
71 order_by => { '-desc' => [ 'timestamp', 'id' ] },
76 my $previous = $prior_cashup->single;
83 [ $previous->_result->get_column('timestamp'), $self->timestamp ]
86 : { 'date' => { '<' => $self->timestamp } };
88 my $payout_transactions = $self->register->accountlines->search(
89 { %{$conditions}, credit_type_code => undef },
91 my $income_transactions = $self->register->accountlines->search(
92 { %{$conditions}, debit_type_code => undef },
95 my $income_summary = Koha::Account::Offsets->search(
98 '-in' => $income_transactions->_resultset->get_column(
99 'accountlines_id')->as_query
101 'me.debit_id' => { '!=' => undef }
104 join => { 'debit' => 'debit_type_code' },
106 [ 'debit.debit_type_code', 'debit_type_code.description' ],
108 { sum => 'me.amount' }, 'debit.debit_type_code',
109 'debit_type_code.description'
111 'as' => [ 'total', 'debit_type_code', 'debit_description' ],
112 order_by => { '-asc' => 'debit_type_code.description' },
116 my $payout_summary = Koha::Account::Offsets->search(
119 '-in' => $payout_transactions->_resultset->get_column(
120 'accountlines_id')->as_query
122 'me.credit_id' => { '!=' => undef }
125 join => { 'credit' => 'credit_type_code' },
127 [ 'credit.credit_type_code', 'credit_type_code.description' ],
129 { sum => 'me.amount' }, 'credit.credit_type_code',
130 'credit_type_code.description'
132 'as' => [ 'total', 'credit_type_code', 'credit_description' ],
133 order_by => { '-asc' => 'credit_type_code.description' },
139 total => $_->get_column('total') * -1,
140 debit_type_code => $_->get_column('debit_type_code'),
141 debit_type => { description => $_->get_column('debit_description') }
143 } $income_summary->as_list;
146 total => $_->get_column('total') * -1,
147 credit_type_code => $_->get_column('credit_type_code'),
149 { description => $_->get_column('credit_description') }
151 } $payout_summary->as_list;
153 my $income_total = $income_transactions->total;
154 my $payout_total = $payout_transactions->total;
155 my $total = ( $income_total + $payout_total );
157 my $payment_types = Koha::AuthorisedValues->search(
159 category => 'PAYMENT_TYPE'
167 for my $type ( $payment_types->as_list ) {
168 my $typed_income = $income_transactions->total( { payment_type => $type->authorised_value } );
169 my $typed_payout = $payout_transactions->total( { payment_type => $type->authorised_value } );
170 my $typed_total = ( $typed_income + $typed_payout );
171 push @total_grouped, { payment_type => $type->lib, total => $typed_total };
175 from_date => $previous ? $previous->timestamp : undef,
176 to_date => $self->timestamp,
177 income_grouped => \@income,
178 income_total => abs($income_total),
179 payout_grouped => \@payout,
180 payout_total => abs($payout_total),
181 total => $total * -1,
182 total_grouped => \@total_grouped
188 =head3 to_api_mapping
190 This method returns the mapping for representing a Koha::Cash::Regiser::Cashup object
198 register_id => 'cash_register_id',
207 Martin Renvoize <martin.renvoize@ptfs-europe.com>