Bug 24492: Add branch details page
[koha.git] / pos / registers.pl
1 #!/usr/bin/perl
2 #
3 # c 2020 PTFS-Europe Ltd
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA  02111-1307 USA
19 #
20
21 use Modern::Perl;
22 use CGI;
23 use C4::Auth;
24 use C4::Output;
25 use C4::Context;
26
27 use Koha::Cash::Registers;
28 use Koha::Database;
29
30 my $input = CGI->new();
31
32 my ( $template, $loggedinuser, $cookie, $user_flags ) = get_template_and_user(
33     {
34         template_name   => 'pos/registers.tt',
35         query           => $input,
36         type            => 'intranet',
37         authnotrequired => 0,
38     }
39 );
40 my $logged_in_user = Koha::Patrons->find($loggedinuser) or die "Not logged in";
41
42 my $library = Koha::Libraries->find( C4::Context->userenv->{'branch'} );
43 $template->param( library => $library );
44
45 my $registers = Koha::Cash::Registers->search(
46     { branch   => $library->id, archived => 0 },
47     { order_by => { '-asc' => 'name' } }
48 );
49
50 if ( !$registers->count ) {
51     $template->param( error_registers => 1 );
52 }
53 else {
54     $template->param( registers => $registers );
55 }
56
57 my $op = $input->param('op') // '';
58 if ( $op eq 'cashup' ) {
59     for my $register ( $registers->as_list ) {
60         $register->add_cashup(
61             {
62                 user_id => $logged_in_user->id,
63                 amount  => $register->outstanding_accountlines->total
64             }
65         );
66     }
67 }
68
69 output_html_with_http_headers( $input, $cookie, $template->output );