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>.
32 use C4::Auth qw( get_template_and_user );
33 use C4::Output qw( output_html_with_http_headers );
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;
41 my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
43 template_name => 'acqui/invoices.tt',
46 flagsrequired => { 'acquisition' => '*' },
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');
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,
77 publisher => $publisher,
78 publicationyear => $publicationyear,
79 branchcode => $branch,
80 message_id => $message_id,
84 # Build suppliers list
85 my @suppliers = Koha::Acquisition::Booksellers->search( undef, { order_by => { -asc => 'name' } } )->as_list;
86 my $suppliers_loop = [];
88 foreach (@suppliers) {
90 if ($supplierid && $supplierid == $_->id ) {
92 $suppliername = $_->name;
94 push @{$suppliers_loop},
96 suppliername => $_->name,
97 booksellerid => $_->id,
98 selected => $selected,
102 my $budgets = GetBudgets();
104 foreach my $budget (@$budgets) {
105 push @budgets_loop, $budget if CanUserUseBudget( $loggedinuser, $budget, $flags );
108 my (@openedinvoices, @closedinvoices);
109 for my $sub ( @{$invoices} ) {
110 unless ( $sub->{closedate} ) {
111 push @openedinvoices, $sub
113 push @closedinvoices, $sub
117 $template->{'VARS'}->{'budgets_loop'} = \@budgets_loop;
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,
134 publisher => $publisher,
135 publicationyear => $publicationyear,
137 suppliers_loop => $suppliers_loop,
140 output_html_with_http_headers $input, $cookie, $template->output;