3 # Copyright 2019 PTFS Europe
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
31 use Koha
::Cash
::Registers
;
34 my ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
36 template_name
=> 'admin/cash_registers.tt',
39 flagsrequired
=> { parameters
=> 'manage_cash_registers' },
43 my $op = $cgi->param('op') || 'list';
44 my $registerid = $cgi->param('id'); # update/archive
45 my $dbh = C4
::Context
->dbh;
47 if ( $op eq 'add_form' ) {
49 my $cash_register = Koha
::Cash
::Registers
->find($registerid);
50 $template->param( cash_register
=> $cash_register );
53 Koha
::Libraries
->search( {}, { order_by
=> ['branchcode'] }, );
55 branch_list
=> $libraries,
59 elsif ( $op eq 'add_validate' ) {
60 my $name = $cgi->param('name');
62 my $description = $cgi->param('description');
64 my $branch = $cgi->param('branch');
65 my $float = $cgi->param('starting_float') // 0;
68 my $cash_register = Koha
::Cash
::Registers
->find($registerid);
72 description
=> $description,
74 starting_float
=> $float
77 push @messages, { code
=> 'success_on_update', type
=> 'message' };
80 push @messages, { code
=> 'error_on_update', type
=> 'alert' };
85 my $cash_register = Koha
::Cash
::Register
->new(
88 description
=> $description,
90 starting_float
=> $float,
93 push @messages, { code
=> 'success_on_insert', type
=> 'message' };
96 push @messages, { code
=> 'error_on_insert', type
=> 'alert' };
102 elsif ( $op eq 'archive' ) {
105 my $cash_register = Koha
::Cash
::Registers
->find($registerid);
106 $cash_register->archived(1)->store();
107 push @messages, { code
=> 'success_on_archive', type
=> 'message' };
110 push @messages, { code
=> 'error_on_archive', type
=> 'alert' };
116 elsif ( $op eq 'unarchive' ) {
119 my $cash_register = Koha
::Cash
::Registers
->find($registerid);
120 $cash_register->archived(0)->store();
121 push @messages, { code
=> 'success_on_restore', type
=> 'message' };
124 push @messages, { code
=> 'error_on_restore', type
=> 'alert' };
130 elsif ( $op eq 'make_default' ) {
133 my $cash_register = Koha
::Cash
::Registers
->find($registerid);
134 $cash_register->make_default;
135 push @messages, { code
=> 'success_on_default', type
=> 'message' };
138 push @messages, { code
=> 'error_on_default', type
=> 'alert' };
143 elsif ( $op eq 'drop_default' ) {
146 my $cash_register = Koha
::Cash
::Registers
->find($registerid);
147 $cash_register->drop_default;
148 push @messages, { code
=> 'success_on_default', type
=> 'message' };
151 push @messages, { code
=> 'error_on_default', type
=> 'alert' };
158 if ( $op eq 'list' ) {
160 Koha
::Cash
::Registers
->search( {},
161 { prefetch
=> 'branch', order_by
=> { -asc
=> [qw
/branch name/] } } );
162 $template->param( cash_registers
=> $cash_registers, );
165 $template->param( op
=> $op, messages
=> \
@messages );
167 output_html_with_http_headers
$cgi, $cookie, $template->output;