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
13 # under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 3 of the License, or
15 # (at your option) any later version.
17 # Koha is distributed in the hope that it will be useful, but
18 # WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with Koha; if not, see <http://www.gnu.org/licenses>.
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 it 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.
77 use Koha
::Acquisition
::Booksellers
;
78 use Koha
::DateUtils
qw( output_pref dt_from_string );
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.tt',
96 flagsrequired
=> { acquisition
=> 'order_receive' },
101 my $invoicenumber = $input->param('invoice');
102 my $shipmentcost = $input->param('shipmentcost');
103 my $shipmentcost_budgetid = $input->param('shipmentcost_budgetid');
104 my $shipmentdate = $input->param('shipmentdate');
105 $shipmentdate and $shipmentdate = output_pref
({ str
=> $shipmentdate, dateformat
=> 'iso', dateonly
=> 1 });
107 if ( $op and $op eq 'new' ) {
108 if ( C4
::Context
->preference('AcqWarnOnDuplicateInvoice') ) {
109 my @invoices = GetInvoices
(
110 supplierid
=> $booksellerid,
111 invoicenumber
=> $invoicenumber,
113 if ( scalar @invoices > 0 ) {
114 $template->{'VARS'}->{'duplicate_invoices'} = \
@invoices;
115 $template->{'VARS'}->{'invoicenumber'} = $invoicenumber;
116 $template->{'VARS'}->{'shipmentdate'} = $shipmentdate;
117 $template->{'VARS'}->{'shipmentcost'} = $shipmentcost;
118 $template->{'VARS'}->{'shipmentcost_budgetid'} =
119 $shipmentcost_budgetid;
122 $op = 'confirm' unless $template->{'VARS'}->{'duplicate_invoices'};
124 if ($op and $op eq 'confirm') {
125 my $invoiceid = AddInvoice
(
126 invoicenumber
=> $invoicenumber,
127 booksellerid
=> $booksellerid,
128 shipmentdate
=> $shipmentdate,
129 shipmentcost
=> $shipmentcost,
130 shipmentcost_budgetid
=> $shipmentcost_budgetid,
132 if(defined $invoiceid) {
134 print $input->redirect("/cgi-bin/koha/acqui/parcel.pl?invoiceid=$invoiceid");
137 $template->param(error_failed_to_create_invoice
=> 1);
141 my $bookseller = Koha
::Acquisition
::Booksellers
->find( $booksellerid );
142 my @parcels = GetInvoices
(
143 supplierid
=> $booksellerid,
144 invoicenumber
=> $code,
145 ( $datefrom ?
( shipmentdatefrom
=> output_pref
({ dt
=> dt_from_string
($datefrom), dateformat
=> 'iso' }) ) : () ),
146 ( $dateto ?
( shipmentdateto
=> output_pref
({ dt
=> dt_from_string
($dateto), dateformat
=> 'iso' }) ) : () ),
149 my $count_parcels = @parcels;
151 # multi page display gestion
153 if ( $count_parcels > $resultsperpage ) {
154 set_page_navigation
( $count_parcels, $startfrom, $resultsperpage );
158 my $next_page_start = $startfrom + $resultsperpage;
159 my $last_row = ( $next_page_start < $count_parcels ) ?
$next_page_start - 1 : $count_parcels - 1;
160 for my $i ( $startfrom .. $last_row) {
161 my $p = $parcels[$i];
165 invoiceid
=> $p->{invoiceid
},
166 code
=> $p->{invoicenumber
},
167 nullcode
=> $p->{invoicenumber
} eq 'NULL',
168 emptycode
=> $p->{invoicenumber
} eq q{},
169 raw_datereceived
=> $p->{shipmentdate
},
170 datereceived
=> $p->{shipmentdate
},
171 bibcount
=> $p->{receivedbiblios
} || 0,
172 reccount
=> $p->{receiveditems
} || 0,
173 itemcount
=> $p->{itemsexpected
} || 0,
176 if ($count_parcels) {
177 $template->param( searchresults
=> $loopres, count
=> $count_parcels );
181 my $budget_loop = [];
182 my $budgets = GetBudgetHierarchy
;
183 foreach my $r (@
{$budgets}) {
184 next unless (CanUserUseBudget
($loggedinuser, $r, $flags));
185 push @
{$budget_loop}, {
186 b_id
=> $r->{budget_id
},
187 b_txt
=> $r->{budget_name
},
188 b_active
=> $r->{budget_period_active
},
193 sort { uc( $a->{b_txt
}) cmp uc( $b->{b_txt
}) } @
{$budget_loop};
199 datefrom
=> $datefrom,
201 resultsperpage
=> $resultsperpage,
202 name
=> $bookseller->name,
203 shipmentdate_today
=> dt_from_string
,
204 booksellerid
=> $booksellerid,
205 GST
=> C4
::Context
->preference('gist'),
206 budgets
=> $budget_loop,
209 output_html_with_http_headers
$input, $cookie, $template->output;
211 sub set_page_navigation
{
212 my ( $total_rows, $startfrom, $resultsperpage ) = @_;
214 my $displayprev = $startfrom;
215 my $next_row = $startfrom + $resultsperpage;
216 my $prev_row = $startfrom - $resultsperpage;
218 if ( $total_rows - $next_row > 0 ) {
222 # set up index numbers for paging
224 if ( $total_rows > $resultsperpage ) {
225 my $pages = $total_rows / $resultsperpage;
226 if ( $total_rows % $resultsperpage ) {
230 # set up page indexes for at max 15 pages
231 my $max_idx = ( $pages < 15 ) ?
$pages : 15;
232 my $current_page = ( $startfrom / $resultsperpage ) - 1;
233 for my $idx ( 1 .. $max_idx ) {
236 startfrom
=> ( $idx - 1 ) * $resultsperpage,
237 highlight
=> ( $idx == $current_page ),
244 displaynext
=> $displaynext,
245 displayprev
=> $displayprev,
246 nextstartfrom
=> ( ( $next_row < $total_rows ) ?
$next_row : $total_rows ),
247 prevstartfrom
=> ( ( $prev_row > 0 ) ?
$prev_row : 0 )