Bug 10468: (followup) fix indentation
[koha.git] / acqui / invoices.pl
blob48adb80686f9e56fc3d6bbe254ec31e9c7cacf51
1 #!/usr/bin/perl
3 # Copyright 2011 BibLibre SARL
4 # This file is part of Koha.
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.
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.
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>.
19 =head1 NAME
21 invoices.pl
23 =head1 DESCRIPTION
25 Search for invoices
27 =cut
29 use strict;
30 use warnings;
32 use CGI qw ( -utf8 );
33 use C4::Auth;
34 use C4::Output;
36 use C4::Acquisition qw/GetInvoices/;
37 use C4::Branch qw/GetBranches/;
38 use C4::Budgets;
39 use Koha::DateUtils;
41 my $input = CGI->new;
42 my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
44 template_name => 'acqui/invoices.tt',
45 query => $input,
46 type => 'intranet',
47 authnotrequired => 0,
48 flagsrequired => { 'acquisition' => '*' },
49 debug => 1,
53 my $invoicenumber = $input->param('invoicenumber');
54 my $supplierid = $input->param('supplierid');
55 my $shipmentdatefrom = $input->param('shipmentdatefrom');
56 my $shipmentdateto = $input->param('shipmentdateto');
57 my $billingdatefrom = $input->param('billingdatefrom');
58 my $billingdateto = $input->param('billingdateto');
59 my $isbneanissn = $input->param('isbneanissn');
60 my $title = $input->param('title');
61 my $author = $input->param('author');
62 my $publisher = $input->param('publisher');
63 my $publicationyear = $input->param('publicationyear');
64 my $branch = $input->param('branch');
65 my $op = $input->param('op');
67 $shipmentdatefrom and $shipmentdatefrom = eval { dt_from_string( $shipmentdatefrom ) };
68 $shipmentdateto and $shipmentdateto = eval { dt_from_string( $shipmentdateto ) };
69 $billingdatefrom and $billingdatefrom = eval { dt_from_string( $billingdatefrom ) };
70 $billingdateto and $billingdateto = eval { dt_from_string( $billingdateto ) };
72 my $invoices = [];
73 if ( $op and $op eq 'do_search' ) {
74 @{$invoices} = GetInvoices(
75 invoicenumber => $invoicenumber,
76 supplierid => $supplierid,
77 shipmentdatefrom => $shipmentdatefrom ? output_pref( { str => $shipmentdatefrom, dateformat => 'iso' } ) : undef,
78 shipmentdateto => $shipmentdateto ? output_pref( { str => $shipmentdateto, dateformat => 'iso' } ) : undef,
79 billingdatefrom => $billingdatefrom ? output_pref( { str => $billingdatefrom, dateformat => 'iso' } ) : undef,
80 billingdateto => $billingdateto ? output_pref( { str => $billingdateto, dateformat => 'iso' } ) : undef,
81 isbneanissn => $isbneanissn,
82 title => $title,
83 author => $author,
84 publisher => $publisher,
85 publicationyear => $publicationyear,
86 branchcode => $branch
90 # Build suppliers list
91 my @suppliers = Koha::Acquisition::Bookseller->search;
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};
100 push @{$suppliers_loop},
102 suppliername => $_->{name},
103 booksellerid => $_->{id},
104 selected => $selected,
108 # Build branches list
109 my $branches = GetBranches();
110 my $branches_loop = [];
111 my $branchname;
112 foreach ( sort keys %$branches ) {
113 my $selected = 0;
114 if ( $branch && $branch eq $_ ) {
115 $selected = 1;
116 $branchname = $branches->{$_}->{'branchname'};
118 push @{$branches_loop},
120 branchcode => $_,
121 branchname => $branches->{$_}->{branchname},
122 selected => $selected,
126 my $budgets = GetBudgets();
127 my @budgets_loop;
128 foreach my $budget (@$budgets) {
129 push @budgets_loop, $budget if CanUserUseBudget( $loggedinuser, $budget, $flags );
132 $template->{'VARS'}->{'budgets_loop'} = \@budgets_loop;
134 $template->param(
135 do_search => ( $op and $op eq 'do_search' ) ? 1 : 0,
136 invoices => $invoices,
137 invoicenumber => $invoicenumber,
138 booksellerid => $supplierid,
139 suppliername => $suppliername,
140 shipmentdatefrom => $shipmentdatefrom,
141 shipmentdateto => $shipmentdateto,
142 billingdatefrom => $billingdatefrom,
143 billingdateto => $billingdateto,
144 isbneanissn => $isbneanissn,
145 title => $title,
146 author => $author,
147 publisher => $publisher,
148 publicationyear => $publicationyear,
149 branch => $branch,
150 branchname => $branchname,
151 suppliers_loop => $suppliers_loop,
152 branches_loop => $branches_loop,
155 output_html_with_http_headers $input, $cookie, $template->output;