4 #script to show display basket of orders
7 # Copyright 2000-2002 Katipo Communications
8 # Copyright 2008-2009 BibLibre SARL
10 # This file is part of Koha.
12 # Koha is free software; you can redistribute it and/or modify it under the
13 # terms of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2 of the License, or (at your option) any later
17 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
18 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
19 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License along
22 # with Koha; if not, write to the Free Software Foundation, Inc.,
23 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 This script shows all orders/parcels receipt or pending for a given supplier.
32 It allows to write an order/parcels as 'received' when he arrives.
40 To know the supplier this script has to show orders.
44 sort list of order by 'orderby'.
45 Orderby can be equals to
46 * datereceived desc (default value)
63 To know how many results have to be display / page.
75 use C4
::Dates qw
/format_date/;
77 use C4
::Bookseller qw
/ GetBookSellerFromId /;
81 my $booksellerid = $input->param('booksellerid');
82 my $order = $input->param('orderby') || 'shipmentdate desc';
83 my $startfrom = $input->param('startfrom');
84 my $code = $input->param('filter');
85 my $datefrom = $input->param('datefrom');
86 my $dateto = $input->param('dateto');
87 my $resultsperpage = $input->param('resultsperpage');
88 my $op = $input->param('op');
89 $resultsperpage ||= 20;
91 our ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user
(
92 { template_name
=> 'acqui/parcels.tmpl',
96 flagsrequired
=> { acquisition
=> 'order_receive' },
101 my $invoicenumber = $input->param('invoice');
102 my $shipmentdate = $input->param('shipmentdate');
103 my $shipmentcost = $input->param('shipmentcost');
104 my $shipmentcost_budgetid = $input->param('shipmentcost_budgetid');
106 $shipmentdate = C4
::Dates
->new($shipmentdate)->output('iso');
109 if ( $op and $op eq 'new' ) {
110 if ( C4
::Context
->preference('AcqWarnOnDuplicateInvoice') ) {
111 my @invoices = GetInvoices
(
112 supplierid
=> $booksellerid,
113 invoicenumber
=> $invoicenumber,
115 if ( scalar @invoices > 0 ) {
116 $template->{'VARS'}->{'duplicate_invoices'} = \
@invoices;
117 $template->{'VARS'}->{'invoicenumber'} = $invoicenumber;
118 $template->{'VARS'}->{'shipmentdate'} = $shipmentdate;
119 $template->{'VARS'}->{'shipmentcost'} = $shipmentcost;
120 $template->{'VARS'}->{'shipmentcost_budgetid'} =
121 $shipmentcost_budgetid;
124 $op = 'confirm' unless $template->{'VARS'}->{'duplicate_invoices'};
126 if ($op and $op eq 'confirm') {
127 my $invoiceid = AddInvoice
(
128 invoicenumber
=> $invoicenumber,
129 booksellerid
=> $booksellerid,
130 shipmentdate
=> $shipmentdate,
131 shipmentcost
=> $shipmentcost,
132 shipmentcost_budgetid
=> $shipmentcost_budgetid,
134 if(defined $invoiceid) {
136 print $input->redirect("/cgi-bin/koha/acqui/parcel.pl?invoiceid=$invoiceid");
139 $template->param(error_failed_to_create_invoice
=> 1);
143 my $bookseller = GetBookSellerFromId
($booksellerid);
144 my @parcels = GetInvoices
(
145 supplierid
=> $booksellerid,
146 invoicenumber
=> $code,
147 shipmentdatefrom
=> $datefrom,
148 shipmentdateto
=> $dateto,
151 my $count_parcels = @parcels;
153 # multi page display gestion
155 if ( $count_parcels > $resultsperpage ) {
156 set_page_navigation
( $count_parcels, $startfrom, $resultsperpage );
160 my $next_page_start = $startfrom + $resultsperpage;
161 my $last_row = ( $next_page_start < $count_parcels ) ?
$next_page_start - 1 : $count_parcels - 1;
162 for my $i ( $startfrom .. $last_row) {
163 my $p = $parcels[$i];
167 invoiceid
=> $p->{invoiceid
},
168 code
=> $p->{invoicenumber
},
169 nullcode
=> $p->{invoicenumber
} eq 'NULL',
170 emptycode
=> $p->{invoicenumber
} eq q{},
171 raw_datereceived
=> $p->{shipmentdate
},
172 datereceived
=> format_date
( $p->{shipmentdate
} ),
173 bibcount
=> $p->{receivedbiblios
} || 0,
174 reccount
=> $p->{receiveditems
} || 0,
175 itemcount
=> $p->{itemsexpected
} || 0,
178 if ($count_parcels) {
179 $template->param( searchresults
=> $loopres, count
=> $count_parcels );
183 my $budget_loop = [];
184 my $budgets = GetBudgetHierarchy
;
185 foreach my $r (@
{$budgets}) {
186 next unless (CanUserUseBudget
($loggedinuser, $r, $flags));
187 if (!defined $r->{budget_amount
} || $r->{budget_amount
} == 0) {
190 push @
{$budget_loop}, {
191 b_id
=> $r->{budget_id
},
192 b_txt
=> $r->{budget_name
},
193 b_active
=> $r->{budget_period_active
},
198 sort { uc( $a->{b_txt
}) cmp uc( $b->{b_txt
}) } @
{$budget_loop};
204 datefrom
=> $datefrom,
206 resultsperpage
=> $resultsperpage,
207 name
=> $bookseller->{'name'},
208 shipmentdate_today
=> C4
::Dates
->new()->output(),
209 booksellerid
=> $booksellerid,
210 GST
=> C4
::Context
->preference('gist'),
211 budgets
=> $budget_loop,
214 output_html_with_http_headers
$input, $cookie, $template->output;
216 sub set_page_navigation
{
217 my ( $total_rows, $startfrom, $resultsperpage ) = @_;
219 my $displayprev = $startfrom;
220 my $next_row = $startfrom + $resultsperpage;
221 my $prev_row = $startfrom - $resultsperpage;
223 if ( $total_rows - $next_row > 0 ) {
227 # set up index numbers for paging
229 if ( $total_rows > $resultsperpage ) {
230 my $pages = $total_rows / $resultsperpage;
231 if ( $total_rows % $resultsperpage ) {
235 # set up page indexes for at max 15 pages
236 my $max_idx = ( $pages < 15 ) ?
$pages : 15;
237 my $current_page = ( $startfrom / $resultsperpage ) - 1;
238 for my $idx ( 1 .. $max_idx ) {
241 startfrom
=> ( $idx - 1 ) * $resultsperpage,
242 highlight
=> ( $idx == $current_page ),
249 displaynext
=> $displaynext,
250 displayprev
=> $displayprev,
251 nextstartfrom
=> ( ( $next_row < $total_rows ) ?
$next_row : $total_rows ),
252 prevstartfrom
=> ( ( $prev_row > 0 ) ?
$prev_row : 0 )