4 #script to recieve orders
5 #written by chris@katipo.co.nz 24/2/2000
7 # Copyright 2000-2002 Katipo Communications
9 # This file is part of Koha.
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License along
21 # with Koha; if not, write to the Free Software Foundation, Inc.,
22 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 This script shows all order already receive and all pendings orders.
31 It permit to write a new order as 'received'.
39 to know on what supplier this script has to display receive order.
43 the id of this invoice.
49 The biblionumber of this order.
66 use C4
::Koha
; # GetKohaAuthorisedValues GetItemTypes
70 use C4
::Dates qw
/format_date/;
71 use C4
::Budgets qw
/ GetBudget GetBudgetHierarchy CanUserUseBudget GetBudgetPeriods /;
73 use C4
::Branch
; # GetBranches
78 use Koha
::Acquisition
::Bookseller
;
83 my $dbh = C4
::Context
->dbh;
84 my $invoiceid = $input->param('invoiceid');
85 my $invoice = GetInvoice
($invoiceid);
86 my $booksellerid = $invoice->{booksellerid
};
87 my $freight = $invoice->{shipmentcost
};
88 my $datereceived = $invoice->{shipmentdate
};
89 my $ordernumber = $input->param('ordernumber');
91 $datereceived = $datereceived ? C4
::Dates
->new($datereceived, 'iso') : C4
::Dates
->new();
93 my $bookseller = Koha
::Acquisition
::Bookseller
->fetch({ id
=> $booksellerid });
95 $results = SearchOrders
({
96 ordernumber
=> $ordernumber
99 my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user
(
101 template_name
=> "acqui/orderreceive.tt",
104 authnotrequired
=> 0,
105 flagsrequired
=> {acquisition
=> 'order_receive'},
110 unless ( $results and @
$results) {
111 output_html_with_http_headers
$input, $cookie, $template->output;
115 # prepare the form for receiving
116 my $order = $results->[0];
118 # Check if ACQ framework exists
119 my $acq_fw = GetMarcStructure
(1, 'ACQ');
121 $template->param('NoACQframework' => 1);
124 my $AcqCreateItem = C4
::Context
->preference('AcqCreateItem');
125 if ($AcqCreateItem eq 'receiving') {
127 AcqCreateItemReceiving
=> 1,
128 UniqueItemFields
=> C4
::Context
->preference('UniqueItemFields'),
130 } elsif ($AcqCreateItem eq 'ordering') {
131 my $fw = ($acq_fw) ?
'ACQ' : '';
132 my @itemnumbers = GetItemnumbersFromOrder
($order->{ordernumber
});
134 foreach (@itemnumbers) {
135 my $item = GetItem
($_);
136 if($item->{homebranch
}) {
137 $item->{homebranchname
} = GetBranchName
($item->{homebranch
});
139 if($item->{holdingbranch
}) {
140 $item->{holdingbranchname
} = GetBranchName
($item->{holdingbranch
});
142 if(my $code = GetAuthValCode
("items.notforloan", $fw)) {
143 $item->{notforloan
} = GetKohaAuthorisedValueLib
($code, $item->{notforloan
});
145 if(my $code = GetAuthValCode
("items.restricted", $fw)) {
146 $item->{restricted
} = GetKohaAuthorisedValueLib
($code, $item->{restricted
});
148 if(my $code = GetAuthValCode
("items.location", $fw)) {
149 $item->{location
} = GetKohaAuthorisedValueLib
($code, $item->{location
});
151 if(my $code = GetAuthValCode
("items.ccode", $fw)) {
152 $item->{collection
} = GetKohaAuthorisedValueLib
($code, $item->{ccode
});
154 if(my $code = GetAuthValCode
("items.materials", $fw)) {
155 $item->{materials
} = GetKohaAuthorisedValueLib
($code, $item->{materials
});
157 my $itemtype = getitemtypeinfo
($item->{itype
});
158 $item->{itemtype
} = $itemtype->{description
};
161 $template->param(items
=> \
@items);
164 $order->{quantityreceived
} = '' if $order->{quantityreceived
} == 0;
165 $order->{unitprice
} = '' if $order->{unitprice
} == 0;
170 if ( $bookseller->{listincgst
} ) {
171 if ( $bookseller->{invoiceincgst
} ) {
172 $rrp = $order->{rrp
};
173 $ecost = $order->{ecost
};
174 $unitprice = $order->{unitprice
};
176 $rrp = $order->{rrp
} / ( 1 + $order->{gstrate
} );
177 $ecost = $order->{ecost
} / ( 1 + $order->{gstrate
} );
178 $unitprice = $order->{unitprice
} / ( 1 + $order->{gstrate
} );
181 if ( $bookseller->{invoiceincgst
} ) {
182 $rrp = $order->{rrp
} * ( 1 + $order->{gstrate
} );
183 $ecost = $order->{ecost
} * ( 1 + $order->{gstrate
} );
184 $unitprice = $order->{unitprice
} * ( 1 + $order->{gstrate
} );
186 $rrp = $order->{rrp
};
187 $ecost = $order->{ecost
};
188 $unitprice = $order->{unitprice
};
192 my $suggestion = GetSuggestionInfoFromBiblionumber
($order->{biblionumber
});
194 my $authorisedby = $order->{authorisedby
};
195 my $member = GetMember
( borrowernumber
=> $authorisedby );
197 my $budget = GetBudget
( $order->{budget_id
} );
200 AcqCreateItem
=> $AcqCreateItem,
202 biblionumber
=> $order->{'biblionumber'},
203 ordernumber
=> $order->{'ordernumber'},
204 subscriptionid
=> $order->{subscriptionid
},
205 booksellerid
=> $order->{'booksellerid'},
207 name
=> $bookseller->{'name'},
208 date
=> format_date
($order->{entrydate
}),
209 title
=> $order->{'title'},
210 author
=> $order->{'author'},
211 copyrightdate
=> $order->{'copyrightdate'},
212 isbn
=> $order->{'isbn'},
213 seriestitle
=> $order->{'seriestitle'},
214 bookfund
=> $budget->{budget_name
},
215 quantity
=> $order->{'quantity'},
216 quantityreceivedplus1
=> $order->{'quantityreceived'} + 1,
217 quantityreceived
=> $order->{'quantityreceived'},
218 rrp
=> sprintf( "%.2f", $rrp ),
219 ecost
=> sprintf( "%.2f", $ecost ),
220 memberfirstname
=> $member->{firstname
} || "",
221 membersurname
=> $member->{surname
} || "",
222 invoiceid
=> $invoice->{invoiceid
},
223 invoice
=> $invoice->{invoicenumber
},
224 datereceived
=> $datereceived->output(),
225 datereceived_iso
=> $datereceived->output('iso'),
226 order_internalnote
=> $order->{order_internalnote
},
227 order_vendornote
=> $order->{order_vendornote
},
228 suggestionid
=> $suggestion->{suggestionid
},
229 surnamesuggestedby
=> $suggestion->{surnamesuggestedby
},
230 firstnamesuggestedby
=> $suggestion->{firstnamesuggestedby
},
233 my $borrower = GetMember
( 'borrowernumber' => $loggedinuser );
235 my $periods = GetBudgetPeriods
( );
236 foreach my $period (@
$periods) {
237 if ($period->{'budget_period_id'} == $budget->{'budget_period_id'}) {
238 $template->{'VARS'}->{'budget_period_description'} = $period->{'budget_period_description'};
240 next if $period->{'budget_period_locked'} || !$period->{'budget_period_description'};
241 my $budget_hierarchy = GetBudgetHierarchy
( $period->{'budget_period_id'} );
243 foreach my $r ( @
{$budget_hierarchy} ) {
244 next unless ( CanUserUseBudget
( $borrower, $r, $userflags ) );
245 if ( !defined $r->{budget_amount
} || $r->{budget_amount
} == 0 ) {
250 b_id
=> $r->{budget_id
},
251 b_txt
=> $r->{budget_name
},
252 b_sel
=> ( $r->{budget_id
} == $order->{budget_id
} ) ?
1 : 0,
256 @funds = sort { uc( $a->{b_txt
} ) cmp uc( $b->{b_txt
} ) } @funds;
260 'id' => $period->{'budget_period_id'},
261 'description' => $period->{'budget_period_description'},
266 $template->{'VARS'}->{'budget_loop'} = \
@budget_loop;
268 # regardless of the content of $unitprice e.g 0 or '' or any string will return in these cases 0.00
269 # and the 'IF' in the .tt will show 0.00 and not 'ecost' (see BZ 7129)
270 # So if $unitprice == 0 we don't create unitprice
271 if ( $unitprice != 0) {
273 unitprice
=> sprintf( "%.2f", $unitprice),
277 my $op = $input->param('op');
278 if ($op and $op eq 'edit'){
279 $template->param(edit
=> 1);
281 output_html_with_http_headers
$input, $cookie, $template->output;