Bug 30718: Use flatpickr's altInput
[koha.git] / acqui / invoices.pl
1 #!/usr/bin/perl
2
3 # Copyright 2011 BibLibre SARL
4 # This file is part of Koha.
5 #
6 # Koha is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # Koha is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with Koha; if not, see <http://www.gnu.org/licenses>.
18
19 =head1 NAME
20
21 invoices.pl
22
23 =head1 DESCRIPTION
24
25 Search for invoices
26
27 =cut
28
29 use Modern::Perl;
30
31 use CGI qw ( -utf8 );
32 use C4::Auth qw( get_template_and_user );
33 use C4::Output qw( output_html_with_http_headers );
34
35 use C4::Acquisition qw( GetInvoices GetInvoice );
36 use C4::Budgets qw( GetBudget GetBudgets CanUserUseBudget );
37 use Koha::DateUtils qw( dt_from_string );
38 use Koha::Acquisition::Booksellers;
39
40 my $input = CGI->new;
41 my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
42     {
43         template_name   => 'acqui/invoices.tt',
44         query           => $input,
45         type            => 'intranet',
46         flagsrequired   => { 'acquisition' => '*' },
47     }
48 );
49
50 my $invoicenumber    = $input->param('invoicenumber');
51 my $supplierid       = $input->param('supplierid');
52 my $shipmentdatefrom = $input->param('shipmentdatefrom');
53 my $shipmentdateto   = $input->param('shipmentdateto');
54 my $billingdatefrom  = $input->param('billingdatefrom');
55 my $billingdateto    = $input->param('billingdateto');
56 my $isbneanissn      = $input->param('isbneanissn');
57 my $title            = $input->param('title');
58 my $author           = $input->param('author');
59 my $publisher        = $input->param('publisher');
60 my $publicationyear  = $input->param('publicationyear');
61 my $branch           = $input->param('branch');
62 my $message_id       = $input->param('message_id');
63 my $op               = $input->param('op');
64
65 my $invoices = [];
66 if ( $op and $op eq 'do_search' ) {
67     @{$invoices} = GetInvoices(
68         invoicenumber    => $invoicenumber,
69         supplierid       => $supplierid,
70         shipmentdatefrom => $shipmentdatefrom,
71         shipmentdateto   => $shipmentdateto,
72         billingdatefrom  => $billingdatefrom,
73         billingdateto    => $billingdateto,
74         isbneanissn      => $isbneanissn,
75         title            => $title,
76         author           => $author,
77         publisher        => $publisher,
78         publicationyear  => $publicationyear,
79         branchcode       => $branch,
80         message_id       => $message_id,
81     );
82 }
83
84 # Build suppliers list
85 my @suppliers      = Koha::Acquisition::Booksellers->search( undef, { order_by => { -asc => 'name' } } )->as_list;
86 my $suppliers_loop = [];
87 my $suppliername;
88 foreach (@suppliers) {
89     my $selected = 0;
90     if ($supplierid && $supplierid == $_->id ) {
91         $selected = 1;
92         $suppliername = $_->name;
93     }
94     push @{$suppliers_loop},
95       {
96         suppliername => $_->name,
97         booksellerid   => $_->id,
98         selected     => $selected,
99       };
100 }
101
102 my $budgets = GetBudgets();
103 my @budgets_loop;
104 foreach my $budget (@$budgets) {
105     push @budgets_loop, $budget if CanUserUseBudget( $loggedinuser, $budget, $flags );
106 }
107
108 my (@openedinvoices, @closedinvoices);
109 for my $sub ( @{$invoices} ) {
110     unless ( $sub->{closedate} ) {
111         push @openedinvoices, $sub
112     } else {
113         push @closedinvoices, $sub
114     }
115 }
116
117 $template->{'VARS'}->{'budgets_loop'} = \@budgets_loop;
118
119 $template->param(
120     openedinvoices => \@openedinvoices,
121     closedinvoices => \@closedinvoices,
122     do_search => ( $op and $op eq 'do_search' ) ? 1 : 0,
123     invoices => $invoices,
124     invoicenumber   => $invoicenumber,
125     booksellerid    => $supplierid,
126     suppliername    => $suppliername,
127     shipmentdatefrom => $shipmentdatefrom,
128     shipmentdateto   => $shipmentdateto,
129     billingdatefrom => $billingdatefrom,
130     billingdateto   => $billingdateto,
131     isbneanissn     => $isbneanissn,
132     title           => $title,
133     author          => $author,
134     publisher       => $publisher,
135     publicationyear => $publicationyear,
136     branch          => $branch,
137     suppliers_loop  => $suppliers_loop,
138 );
139
140 output_html_with_http_headers $input, $cookie, $template->output;