3 # Copyright 2020 PTFS-Europe Ltd
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>.
23 use JSON qw( from_json );
25 use C4::Auth qw/:DEFAULT get_session/;
29 use Koha::Account::DebitTypes;
30 use Koha::AuthorisedValues;
31 use Koha::Cash::Registers;
32 use Koha::Charges::Sales;
36 my $input = CGI->new();
37 my $sessionID = $input->cookie('CGISESSID');
38 my $session = get_session($sessionID);
40 my ( $template, $loggedinuser, $cookie, $user_flags ) = get_template_and_user(
42 template_name => 'pos/pay.tt',
45 flagsrequired => { cash_management => 'takepayment' },
48 my $logged_in_user = Koha::Patrons->find($loggedinuser) or die "Not logged in";
50 my $library_id = C4::Context->userenv->{'branch'};
51 my $registerid = $input->param('registerid');
54 Koha::Account::DebitTypes->search_with_library_limits(
55 { can_be_sold => 1, archived => 0 },
57 $template->param( invoice_types => $invoice_types );
59 my $total_paid = $input->param('paid');
60 if ( $total_paid and $total_paid ne '0.00' ) {
61 my $cash_register = Koha::Cash::Registers->find( { id => $registerid } );
62 my $payment_type = $input->param('payment_type');
63 my $sale = Koha::Charges::Sales->new(
65 cash_register => $cash_register,
66 staff_id => $logged_in_user->id
70 my @sales = $input->multi_param('sales');
71 for my $item (@sales) {
72 $item = from_json $item;
73 $sale->add_item($item);
76 my $payment = $sale->purchase( { payment_type => $payment_type } );
79 payment_id => $payment->accountlines_id,
80 collected => scalar $input->param('collected'),
81 change => scalar $input->param('change')
85 output_html_with_http_headers( $input, $cookie, $template->output );