Bug 28704: Library MARCOrgCode field needs maxlength attribute
[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;
33 use C4::Output;
34
35 use C4::Acquisition qw/GetInvoices/;
36 use C4::Budgets;
37 use Koha::DateUtils;
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         debug           => 1,
48     }
49 );
50
51 my $invoicenumber    = $input->param('invoicenumber');
52 my $supplierid       = $input->param('supplierid');
53 my $shipmentdatefrom = $input->param('shipmentdatefrom');
54 my $shipmentdateto   = $input->param('shipmentdateto');
55 my $billingdatefrom  = $input->param('billingdatefrom');
56 my $billingdateto    = $input->param('billingdateto');
57 my $isbneanissn      = $input->param('isbneanissn');
58 my $title            = $input->param('title');
59 my $author           = $input->param('author');
60 my $publisher        = $input->param('publisher');
61 my $publicationyear  = $input->param('publicationyear');
62 my $branch           = $input->param('branch');
63 my $message_id       = $input->param('message_id');
64 my $op               = $input->param('op');
65
66 $shipmentdatefrom and $shipmentdatefrom = eval { dt_from_string( $shipmentdatefrom ) };
67 $shipmentdateto   and $shipmentdateto   = eval { dt_from_string( $shipmentdateto ) };
68 $billingdatefrom  and $billingdatefrom  = eval { dt_from_string( $billingdatefrom ) };
69 $billingdateto    and $billingdateto    = eval { dt_from_string( $billingdateto ) };
70
71 my $invoices = [];
72 if ( $op and $op eq 'do_search' ) {
73     @{$invoices} = GetInvoices(
74         invoicenumber    => $invoicenumber,
75         supplierid       => $supplierid,
76         shipmentdatefrom => $shipmentdatefrom ? output_pref( { str => $shipmentdatefrom, dateformat => 'iso' } ) : undef,
77         shipmentdateto   => $shipmentdateto   ? output_pref( { str => $shipmentdateto,   dateformat => 'iso' } ) : undef,
78         billingdatefrom  => $billingdatefrom  ? output_pref( { str => $billingdatefrom,  dateformat => 'iso' } ) : undef,
79         billingdateto    => $billingdateto    ? output_pref( { str => $billingdateto,    dateformat => 'iso' } ) : undef,
80         isbneanissn      => $isbneanissn,
81         title            => $title,
82         author           => $author,
83         publisher        => $publisher,
84         publicationyear  => $publicationyear,
85         branchcode       => $branch,
86         message_id       => $message_id,
87     );
88 }
89
90 # Build suppliers list
91 my @suppliers      = Koha::Acquisition::Booksellers->search( undef, { order_by => { -asc => 'name' } } );
92 my $suppliers_loop = [];
93 my $suppliername;
94 foreach (@suppliers) {
95     my $selected = 0;
96     if ($supplierid && $supplierid == $_->id ) {
97         $selected = 1;
98         $suppliername = $_->name;
99     }
100     push @{$suppliers_loop},
101       {
102         suppliername => $_->name,
103         booksellerid   => $_->id,
104         selected     => $selected,
105       };
106 }
107
108 my $budgets = GetBudgets();
109 my @budgets_loop;
110 foreach my $budget (@$budgets) {
111     push @budgets_loop, $budget if CanUserUseBudget( $loggedinuser, $budget, $flags );
112 }
113
114 my (@openedinvoices, @closedinvoices);
115 for my $sub ( @{$invoices} ) {
116     unless ( $sub->{closedate} ) {
117         push @openedinvoices, $sub
118     } else {
119         push @closedinvoices, $sub
120     }
121 }
122
123 $template->{'VARS'}->{'budgets_loop'} = \@budgets_loop;
124
125 $template->param(
126     openedinvoices => \@openedinvoices,
127     closedinvoices => \@closedinvoices,
128     do_search => ( $op and $op eq 'do_search' ) ? 1 : 0,
129     invoices => $invoices,
130     invoicenumber   => $invoicenumber,
131     booksellerid    => $supplierid,
132     suppliername    => $suppliername,
133     shipmentdatefrom => $shipmentdatefrom,
134     shipmentdateto   => $shipmentdateto,
135     billingdatefrom => $billingdatefrom,
136     billingdateto   => $billingdateto,
137     isbneanissn     => $isbneanissn,
138     title           => $title,
139     author          => $author,
140     publisher       => $publisher,
141     publicationyear => $publicationyear,
142     branch          => $branch,
143     suppliers_loop  => $suppliers_loop,
144 );
145
146 output_html_with_http_headers $input, $cookie, $template->output;