Bug 13042 - Move budget action links into menu
[koha.git] / acqui / invoices.pl
blob23cd2ac134458448c4bd81a10cd3a964b6b64411
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 under the
7 # terms of the GNU General Public License as published by the Free Software
8 # Foundation; either version 2 of the License, or (at your option) any later
9 # version.
11 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with Koha; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 =head1 NAME
21 invoices.pl
23 =head1 DESCRIPTION
25 Search for invoices
27 =cut
29 use strict;
30 use warnings;
32 use CGI;
33 use C4::Auth;
34 use C4::Output;
36 use C4::Acquisition qw/GetInvoices/;
37 use C4::Bookseller qw/GetBookSeller/;
38 use C4::Branch qw/GetBranches/;
39 use C4::Budgets;
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 my $invoices = [];
68 if ( $op and $op eq 'do_search' ) {
69 my $shipmentdatefrom_iso = C4::Dates->new($shipmentdatefrom)->output('iso');
70 my $shipmentdateto_iso = C4::Dates->new($shipmentdateto)->output('iso');
71 my $billingdatefrom_iso = C4::Dates->new($billingdatefrom)->output('iso');
72 my $billingdateto_iso = C4::Dates->new($billingdateto)->output('iso');
73 @{$invoices} = GetInvoices(
74 invoicenumber => $invoicenumber,
75 supplierid => $supplierid,
76 shipmentdatefrom => $shipmentdatefrom_iso,
77 shipmentdateto => $shipmentdateto_iso,
78 billingdatefrom => $billingdatefrom_iso,
79 billingdateto => $billingdateto_iso,
80 isbneanissn => $isbneanissn,
81 title => $title,
82 author => $author,
83 publisher => $publisher,
84 publicationyear => $publicationyear,
85 branchcode => $branch
89 # Build suppliers list
90 my @suppliers = GetBookSeller(undef);
91 my $suppliers_loop = [];
92 my $suppliername;
93 foreach (@suppliers) {
94 my $selected = 0;
95 if ($supplierid && $supplierid == $_->{id} ) {
96 $selected = 1;
97 $suppliername = $_->{name};
99 push @{$suppliers_loop},
101 suppliername => $_->{name},
102 booksellerid => $_->{id},
103 selected => $selected,
107 # Build branches list
108 my $branches = GetBranches();
109 my $branches_loop = [];
110 my $branchname;
111 foreach ( sort keys %$branches ) {
112 my $selected = 0;
113 if ( $branch && $branch eq $_ ) {
114 $selected = 1;
115 $branchname = $branches->{$_}->{'branchname'};
117 push @{$branches_loop},
119 branchcode => $_,
120 branchname => $branches->{$_}->{branchname},
121 selected => $selected,
125 my $budgets = GetBudgets();
126 my @budgets_loop;
127 foreach my $budget (@$budgets) {
128 push @budgets_loop, $budget if CanUserUseBudget( $loggedinuser, $budget, $flags );
131 $template->{'VARS'}->{'budgets_loop'} = \@budgets_loop;
133 $template->param(
134 do_search => ( $op and $op eq 'do_search' ) ? 1 : 0,
135 invoices => $invoices,
136 invoicenumber => $invoicenumber,
137 booksellerid => $supplierid,
138 suppliername => $suppliername,
139 billingdatefrom => $billingdatefrom,
140 billingdateto => $billingdateto,
141 isbneanissn => $isbneanissn,
142 title => $title,
143 author => $author,
144 publisher => $publisher,
145 publicationyear => $publicationyear,
146 branch => $branch,
147 branchname => $branchname,
148 suppliers_loop => $suppliers_loop,
149 branches_loop => $branches_loop,
152 output_html_with_http_headers $input, $cookie, $template->output;