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;
27 use base qw(Koha::Object);
33 Koha::Cash::Register - Koha cashregister Object class
43 Return the library linked to this cash register
49 my $rs = $self->_result->branch;
51 return Koha::Library->_new_from_dbic($rs);
56 Return a set of cashup actions linked to this cash register
61 my ( $self, $conditions, $attrs ) = @_;
63 my $local_conditions = { code => 'CASHUP' };
65 my $merged_conditions = { %{$conditions}, %{$local_conditions} };
68 $self->_result->search_related( 'cash_register_actions',
69 $merged_conditions, $attrs );
71 return Koha::Cash::Register::Actions->_new_from_dbic($rs);
76 Return a set of cashup actions linked to this cash register
81 my ( $self, $conditions, $attrs ) = @_;
83 my $rs = $self->_result->search_related(
84 'cash_register_actions',
86 { order_by => { '-desc' => [ 'timestamp', 'id' ] }, rows => 1 }
90 return Koha::Cash::Register::Action->_new_from_dbic($rs);
95 Return a set of accountlines linked to this cash register
102 my $rs = $self->_result->accountlines;
104 return Koha::Account::Lines->_new_from_dbic($rs);
107 =head3 outstanding_accountlines
109 my $lines = Koha::Cash::Registers->find($id)->outstanding_accountlines;
111 Return a set of accountlines linked to this cash register since the last cashup action
115 sub outstanding_accountlines {
116 my ( $self, $conditions, $attrs ) = @_;
118 my $since = $self->_result->search_related(
119 'cash_register_actions',
120 { 'code' => 'CASHUP' },
122 order_by => { '-desc' => [ 'timestamp', 'id' ] },
127 my $local_conditions =
129 ? { 'date' => { '>' => $since->get_column('timestamp')->as_query } }
131 my $merged_conditions =
133 ? { %{$conditions}, %{$local_conditions} }
137 $self->_result->search_related( 'accountlines', $merged_conditions,
140 return Koha::Account::Lines->_new_from_dbic($rs);
145 Local store method to prevent direct manipulation of the 'branch_default' field
151 $self->_result->result_source->schema->txn_do(
153 if ( $self->_result->is_column_changed('branch_default') ) {
154 Koha::Exceptions::Object::ReadOnlyProperty->throw(
155 property => 'branch_default' );
158 if ( $self->_result->is_column_changed('branch')
159 && $self->branch_default )
162 $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 } );
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 $action = $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::Action->_new_from_dbic($rs);
237 =head2 Internal methods
246 return 'CashRegister';
253 Martin Renvoize <martin.renvoize@ptfs-europe.com>