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',
40 flagsrequired => { parameters => 'manage_cash_registers' },
44 my $op = $cgi->param('op') || 'list';
45 my $registerid = $cgi->param('id'); # update/archive
46 my $dbh = C4::Context->dbh;
48 if ( $op eq 'add_form' ) {
50 my $cash_register = Koha::Cash::Registers->find($registerid);
51 $template->param( cash_register => $cash_register );
54 Koha::Libraries->search( {}, { order_by => ['branchcode'] }, );
56 branch_list => $libraries,
60 elsif ( $op eq 'add_validate' ) {
61 my $name = $cgi->param('name');
63 my $description = $cgi->param('description');
65 my $branch = $cgi->param('branch');
66 my $float = $cgi->param('starting_float') // 0;
69 my $cash_register = Koha::Cash::Registers->find($registerid);
73 description => $description,
75 starting_float => $float
78 push @messages, { code => 'success_on_update', type => 'message' };
81 push @messages, { code => 'error_on_update', type => 'alert' };
86 my $cash_register = Koha::Cash::Register->new(
89 description => $description,
91 starting_float => $float,
94 push @messages, { code => 'success_on_insert', type => 'message' };
97 push @messages, { code => 'error_on_insert', type => 'alert' };
103 elsif ( $op eq 'archive' ) {
106 my $cash_register = Koha::Cash::Registers->find($registerid);
107 $cash_register->archived(1)->store();
108 push @messages, { code => 'success_on_archive', type => 'message' };
111 push @messages, { code => 'error_on_archive', type => 'alert' };
117 elsif ( $op eq 'unarchive' ) {
120 my $cash_register = Koha::Cash::Registers->find($registerid);
121 $cash_register->archived(0)->store();
122 push @messages, { code => 'success_on_restore', type => 'message' };
125 push @messages, { code => 'error_on_restore', type => 'alert' };
131 elsif ( $op eq 'make_default' ) {
134 my $cash_register = Koha::Cash::Registers->find($registerid);
135 $cash_register->make_default;
136 push @messages, { code => 'success_on_default', type => 'message' };
139 push @messages, { code => 'error_on_default', type => 'alert' };
144 elsif ( $op eq 'drop_default' ) {
147 my $cash_register = Koha::Cash::Registers->find($registerid);
148 $cash_register->drop_default;
149 push @messages, { code => 'success_on_default', type => 'message' };
152 push @messages, { code => 'error_on_default', type => 'alert' };
159 if ( $op eq 'list' ) {
161 Koha::Cash::Registers->search( {},
162 { prefetch => 'branch', order_by => { -asc => [qw/branch name/] } } );
163 $template->param( cash_registers => $cash_registers, );
166 $template->param( op => $op, messages => \@messages );
168 output_html_with_http_headers $cgi, $cookie, $template->output;