Bug 25553: Make date columns sortable on the edit items table
[koha.git] / pos / pay.pl
blobacee17d3c905ff759bd5c62cde6d7fdd0e16dfb2
1 #!/usr/bin/perl
3 use Modern::Perl;
5 use CGI;
6 use JSON qw( from_json );
8 use C4::Auth qw/:DEFAULT get_session/;
9 use C4::Output;
10 use C4::Context;
12 use Koha::Account::DebitTypes;
13 use Koha::AuthorisedValues;
14 use Koha::Cash::Registers;
15 use Koha::Charges::Sales;
16 use Koha::Database;
17 use Koha::Libraries;
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',
26 query => $input,
27 type => 'intranet',
28 authnotrequired => 0,
29 flagsrequired => { cash_management => 'takepayment' },
32 my $logged_in_user = Koha::Patrons->find($loggedinuser) or die "Not logged in";
34 my $library_id = C4::Context->userenv->{'branch'};
35 my $registerid = $input->param('registerid');
36 my $default_registerid = $input->param('default_register');
37 my $registers = Koha::Cash::Registers->search(
38 { branch => $library_id, archived => 0 },
39 { order_by => { '-asc' => 'name' } }
42 if ( !$registers->count ) {
43 $template->param( error_registers => 1 );
45 else {
46 if ( !$default_registerid ) {
47 my $default_register = Koha::Cash::Registers->find(
48 { branch => $library_id, branch_default => 1 } );
49 $default_registerid =
50 $default_register ? $default_register->id : $registers->next->id;
53 $template->param(
54 default_register => $default_registerid,
55 registers => $registers,
59 my $invoice_types =
60 Koha::Account::DebitTypes->search_with_library_limits( { can_be_sold => 1 },
61 {}, $library_id );
62 $template->param( invoice_types => $invoice_types );
64 my $total_paid = $input->param('paid');
65 if ( $total_paid and $total_paid ne '0.00' ) {
66 my $cash_register = Koha::Cash::Registers->find( { id => $registerid } );
67 my $payment_type = $input->param('payment_type');
68 my $sale = Koha::Charges::Sales->new(
70 cash_register => $cash_register,
71 staff_id => $logged_in_user->id
75 my @sales = $input->multi_param('sales');
76 for my $item (@sales) {
77 $item = from_json $item;
78 $sale->add_item($item);
81 my $payment = $sale->purchase( { payment_type => $payment_type } );
83 $template->param(
84 payment_id => $payment->accountlines_id,
85 collected => scalar $input->param('collected'),
86 change => scalar $input->param('change')
90 output_html_with_http_headers( $input, $cookie, $template->output );