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 return Koha
::Library
->_new_from_dbic($self->_result->branch);
54 Return a set of cashup actions linked to this cash register
59 my ( $self, $conditions, $attrs ) = @_;
61 my $local_conditions = { code
=> 'CASHUP' };
63 my $merged_conditions = { %{$conditions}, %{$local_conditions} };
66 $self->_result->search_related( 'cash_register_actions',
67 $merged_conditions, $attrs );
69 return Koha
::Cash
::Register
::Actions
->_new_from_dbic($rs);
74 Return a set of cashup actions linked to this cash register
79 my ( $self, $conditions, $attrs ) = @_;
81 my $rs = $self->_result->search_related(
82 'cash_register_actions',
84 { order_by
=> { '-desc' => [ 'timestamp', 'id' ] }, rows
=> 1 }
88 return Koha
::Cash
::Register
::Action
->_new_from_dbic($rs);
93 Return a set of accountlines linked to this cash register
100 my $rs = $self->_result->accountlines;
101 return Koha
::Account
::Lines
->_new_from_dbic($rs);
104 =head3 outstanding_accountlines
106 my $lines = Koha::Cash::Registers->find($id)->outstanding_accountlines;
108 Return a set of accountlines linked to this cash register since the last cashup action
112 sub outstanding_accountlines
{
113 my ( $self, $conditions, $attrs ) = @_;
115 my $since = $self->_result->search_related(
116 'cash_register_actions',
117 { 'code' => 'CASHUP' },
119 order_by
=> { '-desc' => [ 'timestamp', 'id' ] },
124 my $local_conditions =
126 ?
{ 'date' => { '>' => $since->get_column('timestamp')->as_query } }
128 my $merged_conditions =
130 ?
{ %{$conditions}, %{$local_conditions} }
134 $self->_result->search_related( 'accountlines', $merged_conditions,
137 return Koha
::Account
::Lines
->_new_from_dbic($rs);
142 Local store method to prevent direct manipulation of the 'branch_default' field
149 $self->_result->result_source->schema->txn_do(
151 if ( $self->_result->is_column_changed('branch_default') ) {
152 Koha
::Exceptions
::Object
::ReadOnlyProperty
->throw(
153 property
=> 'branch_default' );
156 if ( $self->_result->is_column_changed('branch')
157 && $self->branch_default )
160 $self = $self->SUPER::store
;
170 Set the current cash register as the branch default
177 $self->_result->result_source->schema->txn_do(
180 Koha
::Cash
::Registers
->search( { branch
=> $self->branch } );
181 $registers->update( { branch_default
=> 0 }, { no_triggers
=> 1 } );
182 $self->set( { branch_default
=> 1 } );
192 Drop the current cash register as the branch default
199 $self->_result->result_source->schema->txn_do(
201 $self->set( { branch_default
=> 0 } );
211 my $action = $cash_register->add_cashup(
213 manager_id => $logged_in_user->id,
214 amount => $cash_register->outstanding_accountlines->total
218 Add a new cashup action to the till, returns the added action.
223 my ( $self, $params ) = @_;
225 my $rs = $self->_result->add_to_cash_register_actions(
228 manager_id
=> $params->{manager_id
},
229 amount
=> $params->{amount
}
233 return Koha
::Cash
::Register
::Action
->_new_from_dbic($rs);
236 =head2 Internal methods
245 return 'CashRegister';
252 Martin Renvoize <martin.renvoize@ptfs-europe.com>