6 use JSON
qw( from_json );
8 use C4
::Auth qw
/:DEFAULT get_session/;
12 use Koha
::Account
::DebitTypes
;
13 use Koha
::AuthorisedValues
;
14 use Koha
::Cash
::Registers
;
15 use Koha
::Charges
::Sales
;
19 my $input = CGI
->new();
20 my $sessionID = $input->cookie('CGISESSID');
21 my $session = get_session
($sessionID);
23 my ( $template, $loggedinuser, $cookie, $user_flags ) = get_template_and_user
(
25 template_name
=> 'pos/pay.tt',
28 flagsrequired
=> { cash_management
=> 'takepayment' },
31 my $logged_in_user = Koha
::Patrons
->find($loggedinuser) or die "Not logged in";
33 my $library_id = C4
::Context
->userenv->{'branch'};
34 my $registerid = $input->param('registerid');
37 Koha
::Account
::DebitTypes
->search_with_library_limits( { can_be_sold
=> 1 },
39 $template->param( invoice_types
=> $invoice_types );
41 my $total_paid = $input->param('paid');
42 if ( $total_paid and $total_paid ne '0.00' ) {
43 my $cash_register = Koha
::Cash
::Registers
->find( { id
=> $registerid } );
44 my $payment_type = $input->param('payment_type');
45 my $sale = Koha
::Charges
::Sales
->new(
47 cash_register
=> $cash_register,
48 staff_id
=> $logged_in_user->id
52 my @sales = $input->multi_param('sales');
53 for my $item (@sales) {
54 $item = from_json
$item;
55 $sale->add_item($item);
58 my $payment = $sale->purchase( { payment_type
=> $payment_type } );
61 payment_id
=> $payment->accountlines_id,
62 collected
=> scalar $input->param('collected'),
63 change
=> scalar $input->param('change')
67 output_html_with_http_headers
( $input, $cookie, $template->output );