Merge remote-tracking branch 'origin/new/bug_6448'
[koha.git] / acqui / invoices.pl
1 #!/usr/bin/perl
2
3 # Copyright 2011 BibLibre SARL
4 # This file is part of Koha.
5 #
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.
10 #
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.
14 #
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.
18
19 =head1 NAME
20
21 invoices.pl
22
23 =head1 DESCRIPTION
24
25 Search for invoices
26
27 =cut
28
29 use strict;
30 use warnings;
31
32 use CGI;
33 use C4::Auth;
34 use C4::Output;
35
36 use C4::Acquisition;
37 use C4::Bookseller qw/GetBookSeller/;
38 use C4::Branch;
39
40 my $input = new CGI;
41 my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
42     {
43         template_name   => 'acqui/invoices.tmpl',
44         query           => $input,
45         type            => 'intranet',
46         authnotrequired => 0,
47         flagsrequired   => { 'acquisition' => '*' },
48         debug           => 1,
49     }
50 );
51
52 my $invoicenumber    = $input->param('invoicenumber');
53 my $supplier         = $input->param('supplier');
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');
65
66 my @results_loop = ();
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     my @invoices             = GetInvoices(
73         invoicenumber    => $invoicenumber,
74         suppliername     => $supplier,
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
85     );
86     foreach (@invoices) {
87         my %row = (
88             invoiceid       => $_->{invoiceid},
89             billingdate     => $_->{billingdate},
90             invoicenumber   => $_->{invoicenumber},
91             suppliername    => $_->{suppliername},
92             receivedbiblios => $_->{receivedbiblios},
93             receiveditems   => $_->{receiveditems},
94             subscriptionid  => $_->{subscriptionid},
95             closedate       => $_->{closedate},
96         );
97         push @results_loop, \%row;
98     }
99 }
100
101 # Build suppliers list
102 my @suppliers      = GetBookSeller(undef);
103 my @suppliers_loop = ();
104 my $suppliername;
105 foreach (@suppliers) {
106     my $selected = 0;
107     if ( $supplier && $supplier == $_->{'id'} ) {
108         $selected     = 1;
109         $suppliername = $_->{'name'};
110     }
111     my %row = (
112         suppliername => $_->{'name'},
113         supplierid   => $_->{'id'},
114         selected     => $selected,
115     );
116     push @suppliers_loop, \%row;
117 }
118
119 # Build branches list
120 my $branches      = GetBranches();
121 my @branches_loop = ();
122 my $branchname;
123 foreach ( sort keys %$branches ) {
124     my $selected = 0;
125     if ( $branch && $branch eq $_ ) {
126         $selected   = 1;
127         $branchname = $branches->{$_}->{'branchname'};
128     }
129     my %row = (
130         branchcode => $_,
131         branchname => $branches->{$_}->{'branchname'},
132         selected   => $selected,
133     );
134     push @branches_loop, \%row;
135 }
136
137 $template->param(
138     do_search => ( $op and $op eq "do_search" ) ? 1 : 0,
139     results_loop             => \@results_loop,
140     invoicenumber            => $invoicenumber,
141     supplier                 => $supplier,
142     suppliername             => $suppliername,
143     billingdatefrom          => $billingdatefrom,
144     billingdateto            => $billingdateto,
145     isbneanissn              => $isbneanissn,
146     title                    => $title,
147     author                   => $author,
148     publisher                => $publisher,
149     publicationyear          => $publicationyear,
150     branch                   => $branch,
151     branchname               => $branchname,
152     suppliers_loop           => \@suppliers_loop,
153     branches_loop            => \@branches_loop,
154     DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
155 );
156
157 output_html_with_http_headers $input, $cookie, $template->output;