Bug 5339: Invoices management improvement
[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     template_name   => 'acqui/invoices.tmpl',
43     query           => $input,
44     type            => 'intranet',
45     authnotrequired => 0,
46     flagsrequired   => { 'acquisition' => '*' },
47     debug           => 1,
48 } );
49
50 my $invoicenumber   = $input->param('invoicenumber');
51 my $supplier        = $input->param('supplier');
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 $op              = $input->param('op');
63
64 my @results_loop = ();
65 if($op and $op eq "do_search") {
66     my $shipmentdatefrom_iso = C4::Dates->new($shipmentdatefrom)->output("iso");
67     my $shipmentdateto_iso = C4::Dates->new($shipmentdateto)->output("iso");
68     my $billingdatefrom_iso = C4::Dates->new($billingdatefrom)->output("iso");
69     my $billingdateto_iso = C4::Dates->new($billingdateto)->output("iso");
70     my @invoices = GetInvoices(
71         invoicenumber => $invoicenumber,
72         suppliername => $supplier,
73         shipmentdatefrom => $shipmentdatefrom_iso,
74         shipmentdateto => $shipmentdateto_iso,
75         billingdatefrom => $billingdatefrom_iso,
76         billingdateto => $billingdateto_iso,
77         isbneanissn => $isbneanissn,
78         title => $title,
79         author => $author,
80         publisher => $publisher,
81         publicationyear => $publicationyear,
82         branchcode => $branch
83     );
84     foreach (@invoices) {
85         my %row = (
86             invoiceid       => $_->{invoiceid},
87             billingdate     => $_->{billingdate},
88             invoicenumber   => $_->{invoicenumber},
89             suppliername    => $_->{suppliername},
90             receivedbiblios => $_->{receivedbiblios},
91             receiveditems   => $_->{receiveditems},
92             subscriptionid  => $_->{subscriptionid},
93             closedate => $_->{closedate},
94         );
95         push @results_loop, \%row;
96     }
97 }
98
99
100 # Build suppliers list
101 my @suppliers = GetBookSeller(undef);
102 my @suppliers_loop = ();
103 my $suppliername;
104 foreach (@suppliers) {
105     my $selected = 0;
106     if ($supplier && $supplier == $_->{'id'}) {
107         $selected = 1;
108         $suppliername = $_->{'name'};
109     }
110     my %row = (
111         suppliername => $_->{'name'},
112         supplierid   => $_->{'id'},
113         selected     => $selected,
114     );
115     push @suppliers_loop, \%row;
116 }
117
118 # Build branches list
119 my $branches = GetBranches();
120 my @branches_loop = ();
121 my $branchname;
122 foreach (sort keys %$branches) {
123     my $selected = 0;
124     if ($branch && $branch eq $_) {
125         $selected = 1;
126         $branchname = $branches->{$_}->{'branchname'};
127     }
128     my %row = (
129         branchcode => $_,
130         branchname => $branches->{$_}->{'branchname'},
131         selected   => $selected,
132     );
133     push @branches_loop, \%row;
134 }
135
136 $template->param(
137     do_search       => ($op and $op eq "do_search") ? 1 : 0,
138     results_loop    => \@results_loop,
139     invoicenumber   => $invoicenumber,
140     supplier        => $supplier,
141     suppliername    => $suppliername,
142     billingdatefrom => $billingdatefrom,
143     billingdateto   => $billingdateto,
144     isbneanissn     => $isbneanissn,
145     title           => $title,
146     author          => $author,
147     publisher       => $publisher,
148     publicationyear => $publicationyear,
149     branch          => $branch,
150     branchname      => $branchname,
151     suppliers_loop  => \@suppliers_loop,
152     branches_loop   => \@branches_loop,
153     DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
154 );
155
156 output_html_with_http_headers $input, $cookie, $template->output;