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 output_pref );
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');
65 $shipmentdatefrom and $shipmentdatefrom = eval { dt_from_string( $shipmentdatefrom ) };
66 $shipmentdateto and $shipmentdateto = eval { dt_from_string( $shipmentdateto ) };
67 $billingdatefrom and $billingdatefrom = eval { dt_from_string( $billingdatefrom ) };
68 $billingdateto and $billingdateto = eval { dt_from_string( $billingdateto ) };
71 if ( $op and $op eq 'do_search' ) {
72 @{$invoices} = GetInvoices(
73 invoicenumber => $invoicenumber,
74 supplierid => $supplierid,
75 shipmentdatefrom => $shipmentdatefrom ? output_pref( { str => $shipmentdatefrom, dateformat => 'iso' } ) : undef,
76 shipmentdateto => $shipmentdateto ? output_pref( { str => $shipmentdateto, dateformat => 'iso' } ) : undef,
77 billingdatefrom => $billingdatefrom ? output_pref( { str => $billingdatefrom, dateformat => 'iso' } ) : undef,
78 billingdateto => $billingdateto ? output_pref( { str => $billingdateto, dateformat => 'iso' } ) : undef,
79 isbneanissn => $isbneanissn,
82 publisher => $publisher,
83 publicationyear => $publicationyear,
84 branchcode => $branch,
85 message_id => $message_id,
89 # Build suppliers list
90 my @suppliers = Koha::Acquisition::Booksellers->search( undef, { order_by => { -asc => 'name' } } );
91 my $suppliers_loop = [];
93 foreach (@suppliers) {
95 if ($supplierid && $supplierid == $_->id ) {
97 $suppliername = $_->name;
99 push @{$suppliers_loop},
101 suppliername => $_->name,
102 booksellerid => $_->id,
103 selected => $selected,
107 my $budgets = GetBudgets();
109 foreach my $budget (@$budgets) {
110 push @budgets_loop, $budget if CanUserUseBudget( $loggedinuser, $budget, $flags );
113 my (@openedinvoices, @closedinvoices);
114 for my $sub ( @{$invoices} ) {
115 unless ( $sub->{closedate} ) {
116 push @openedinvoices, $sub
118 push @closedinvoices, $sub
122 $template->{'VARS'}->{'budgets_loop'} = \@budgets_loop;
125 openedinvoices => \@openedinvoices,
126 closedinvoices => \@closedinvoices,
127 do_search => ( $op and $op eq 'do_search' ) ? 1 : 0,
128 invoices => $invoices,
129 invoicenumber => $invoicenumber,
130 booksellerid => $supplierid,
131 suppliername => $suppliername,
132 shipmentdatefrom => $shipmentdatefrom,
133 shipmentdateto => $shipmentdateto,
134 billingdatefrom => $billingdatefrom,
135 billingdateto => $billingdateto,
136 isbneanissn => $isbneanissn,
139 publisher => $publisher,
140 publicationyear => $publicationyear,
142 suppliers_loop => $suppliers_loop,
145 output_html_with_http_headers $input, $cookie, $template->output;