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;
39 use Koha::AdditionalFields;
42 my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
44 template_name => 'acqui/invoices.tt',
47 flagsrequired => { 'acquisition' => '*' },
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');
66 my @additional_fields = Koha::AdditionalFields->search(
67 { tablename => 'aqinvoices',
71 my @additional_field_filters;
72 for my $field (@additional_fields) {
73 my $value = $input->param( 'additional_field_' . $field->id );
74 if ( defined $value and $value ne '' ) {
75 push @additional_field_filters,
83 if ( $op and $op eq 'cud-do_search' ) {
84 @{$invoices} = GetInvoices(
85 invoicenumber => $invoicenumber,
86 supplierid => $supplierid,
87 shipmentdatefrom => $shipmentdatefrom,
88 shipmentdateto => $shipmentdateto,
89 billingdatefrom => $billingdatefrom,
90 billingdateto => $billingdateto,
91 isbneanissn => $isbneanissn,
94 publisher => $publisher,
95 publicationyear => $publicationyear,
96 branchcode => $branch,
97 message_id => $message_id,
98 additional_fields => \@additional_field_filters,
103 additional_field_filters => { map { $_->{id} => $_->{value} } @additional_field_filters },
104 additional_fields_for_invoice => \@additional_fields,
107 # Build suppliers list
108 my @suppliers = Koha::Acquisition::Booksellers->search( undef, { order_by => { -asc => 'name' } } )->as_list;
109 my $suppliers_loop = [];
111 foreach (@suppliers) {
113 if ($supplierid && $supplierid == $_->id ) {
115 $suppliername = $_->name;
117 push @{$suppliers_loop},
119 suppliername => $_->name,
120 booksellerid => $_->id,
121 selected => $selected,
125 my $budgets = GetBudgets();
127 foreach my $budget (@$budgets) {
128 push @budgets_loop, $budget if CanUserUseBudget( $loggedinuser, $budget, $flags );
131 my (@openedinvoices, @closedinvoices);
132 for my $sub ( @{$invoices} ) {
133 unless ( $sub->{closedate} ) {
134 push @openedinvoices, $sub
136 push @closedinvoices, $sub
140 $template->{'VARS'}->{'budgets_loop'} = \@budgets_loop;
143 openedinvoices => \@openedinvoices,
144 closedinvoices => \@closedinvoices,
145 do_search => ( $op and $op eq 'cud-do_search' ) ? 1 : 0,
146 invoices => $invoices,
147 invoicenumber => $invoicenumber,
148 booksellerid => $supplierid,
149 suppliername => $suppliername,
150 shipmentdatefrom => $shipmentdatefrom,
151 shipmentdateto => $shipmentdateto,
152 billingdatefrom => $billingdatefrom,
153 billingdateto => $billingdateto,
154 isbneanissn => $isbneanissn,
157 publisher => $publisher,
158 publicationyear => $publicationyear,
160 suppliers_loop => $suppliers_loop,
163 output_html_with_http_headers $input, $cookie, $template->output;