Bug 12671: Refactor GetNextDate
[koha.git] / acqui / invoices.pl
blob4909b78b4f89422f54dc89c52640099b0cac59a7
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;
40 my $input = CGI->new;
41 my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
43 template_name => 'acqui/invoices.tt',
44 query => $input,
45 type => 'intranet',
46 authnotrequired => 0,
47 flagsrequired => { 'acquisition' => '*' },
48 debug => 1,
52 my $invoicenumber = $input->param('invoicenumber');
53 my $supplierid = $input->param('supplierid');
54 my $shipmentdatefrom = $input->param('shipmentdatefrom');
55 my $shipmentdateto = $input->param('shipmentdateto');
56 my $billingdatefrom = $input->param('billingdatefrom');
57 my $billingdateto = $input->param('billingdateto');
58 my $isbneanissn = $input->param('isbneanissn');
59 my $title = $input->param('title');
60 my $author = $input->param('author');
61 my $publisher = $input->param('publisher');
62 my $publicationyear = $input->param('publicationyear');
63 my $branch = $input->param('branch');
64 my $op = $input->param('op');
66 my $invoices = [];
67 if ( $op and $op eq 'do_search' ) {
68 my $shipmentdatefrom_iso = C4::Dates->new($shipmentdatefrom)->output('iso');
69 my $shipmentdateto_iso = C4::Dates->new($shipmentdateto)->output('iso');
70 my $billingdatefrom_iso = C4::Dates->new($billingdatefrom)->output('iso');
71 my $billingdateto_iso = C4::Dates->new($billingdateto)->output('iso');
72 @{$invoices} = GetInvoices(
73 invoicenumber => $invoicenumber,
74 supplierid => $supplierid,
75 shipmentdatefrom => $shipmentdatefrom_iso,
76 shipmentdateto => $shipmentdateto_iso,
77 billingdatefrom => $billingdatefrom_iso,
78 billingdateto => $billingdateto_iso,
79 isbneanissn => $isbneanissn,
80 title => $title,
81 author => $author,
82 publisher => $publisher,
83 publicationyear => $publicationyear,
84 branchcode => $branch
88 # Build suppliers list
89 my @suppliers = Koha::Acquisition::Bookseller->search;
90 my $suppliers_loop = [];
91 my $suppliername;
92 foreach (@suppliers) {
93 my $selected = 0;
94 if ($supplierid && $supplierid == $_->{id} ) {
95 $selected = 1;
96 $suppliername = $_->{name};
98 push @{$suppliers_loop},
100 suppliername => $_->{name},
101 booksellerid => $_->{id},
102 selected => $selected,
106 # Build branches list
107 my $branches = GetBranches();
108 my $branches_loop = [];
109 my $branchname;
110 foreach ( sort keys %$branches ) {
111 my $selected = 0;
112 if ( $branch && $branch eq $_ ) {
113 $selected = 1;
114 $branchname = $branches->{$_}->{'branchname'};
116 push @{$branches_loop},
118 branchcode => $_,
119 branchname => $branches->{$_}->{branchname},
120 selected => $selected,
124 my $budgets = GetBudgets();
125 my @budgets_loop;
126 foreach my $budget (@$budgets) {
127 push @budgets_loop, $budget if CanUserUseBudget( $loggedinuser, $budget, $flags );
130 $template->{'VARS'}->{'budgets_loop'} = \@budgets_loop;
132 $template->param(
133 do_search => ( $op and $op eq 'do_search' ) ? 1 : 0,
134 invoices => $invoices,
135 invoicenumber => $invoicenumber,
136 booksellerid => $supplierid,
137 suppliername => $suppliername,
138 billingdatefrom => $billingdatefrom,
139 billingdateto => $billingdateto,
140 isbneanissn => $isbneanissn,
141 title => $title,
142 author => $author,
143 publisher => $publisher,
144 publicationyear => $publicationyear,
145 branch => $branch,
146 branchname => $branchname,
147 suppliers_loop => $suppliers_loop,
148 branches_loop => $branches_loop,
151 output_html_with_http_headers $input, $cookie, $template->output;