1 package Koha::Cash::Register;
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>.
22 use Koha::Account::Lines;
23 use Koha::Account::Offsets;
24 use Koha::Cash::Register::Actions;
25 use Koha::Cash::Register::Cashups;
28 use base qw(Koha::Object);
34 Koha::Cash::Register - Koha cashregister Object class
44 Return the library linked to this cash register
50 return Koha::Library->_new_from_dbic($self->_result->branch);
55 Return a set of cashup actions linked to this cash register
60 my ( $self, $conditions, $attrs ) = @_;
62 my $local_conditions = { code => 'CASHUP' };
64 my $merged_conditions = { %{$conditions}, %{$local_conditions} };
67 $self->_result->search_related( 'cash_register_actions',
68 $merged_conditions, $attrs );
70 return Koha::Cash::Register::Cashups->_new_from_dbic($rs);
75 Return a set of cashup actions linked to this cash register
80 my ( $self, $conditions, $attrs ) = @_;
82 my $rs = $self->_result->search_related(
83 'cash_register_actions',
85 { order_by => { '-desc' => [ 'timestamp', 'id' ] }, rows => 1 }
89 return Koha::Cash::Register::Cashup->_new_from_dbic($rs);
94 Return a set of accountlines linked to this cash register
101 my $rs = $self->_result->accountlines;
102 return Koha::Account::Lines->_new_from_dbic($rs);
105 =head3 outstanding_accountlines
107 my $lines = Koha::Cash::Registers->find($id)->outstanding_accountlines;
109 Return a set of accountlines linked to this cash register since the last cashup action
113 sub outstanding_accountlines {
114 my ( $self, $conditions, $attrs ) = @_;
116 my $since = $self->_result->search_related(
117 'cash_register_actions',
118 { 'code' => 'CASHUP' },
120 order_by => { '-desc' => [ 'timestamp', 'id' ] },
125 my $local_conditions =
127 ? { 'date' => { '>' => $since->get_column('timestamp')->as_query } }
129 my $merged_conditions =
131 ? { %{$conditions}, %{$local_conditions} }
135 $self->_result->search_related( 'accountlines', $merged_conditions,
138 return Koha::Account::Lines->_new_from_dbic($rs);
143 Local store method to prevent direct manipulation of the 'branch_default' field
150 $self->_result->result_source->schema->txn_do(
152 if ( $self->_result->is_column_changed('branch_default') ) {
153 Koha::Exceptions::Object::ReadOnlyProperty->throw(
154 property => 'branch_default' );
157 if ( $self->_result->is_column_changed('branch')
158 && $self->branch_default )
161 $self = $self->SUPER::store;
171 Set the current cash register as the branch default
178 $self->_result->result_source->schema->txn_do(
181 Koha::Cash::Registers->search( { branch => $self->branch } );
182 $registers->update( { branch_default => 0 }, { no_triggers => 1 } );
183 $self->set( { branch_default => 1 } );
193 Drop the current cash register as the branch default
200 $self->_result->result_source->schema->txn_do(
202 $self->set( { branch_default => 0 } );
212 my $cashup = $cash_register->add_cashup(
214 manager_id => $logged_in_user->id,
215 amount => $cash_register->outstanding_accountlines->total
219 Add a new cashup action to the till, returns the added action.
224 my ( $self, $params ) = @_;
226 my $rs = $self->_result->add_to_cash_register_actions(
229 manager_id => $params->{manager_id},
230 amount => $params->{amount}
234 return Koha::Cash::Register::Cashup->_new_from_dbic($rs);
237 =head2 Internal methods
246 return 'CashRegister';
253 Martin Renvoize <martin.renvoize@ptfs-europe.com>