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
::Bookseller qw
/ GetBookSellerFromId /;
72 use C4
::Budgets qw
/ GetBudget GetBudgetHierarchy CanUserUseBudget GetBudgetPeriods /;
74 use C4
::Branch
; # GetBranches
82 my $dbh = C4
::Context
->dbh;
83 my $invoiceid = $input->param('invoiceid');
84 my $invoice = GetInvoice
($invoiceid);
85 my $booksellerid = $invoice->{booksellerid
};
86 my $freight = $invoice->{shipmentcost
};
87 my $datereceived = $invoice->{shipmentdate
};
88 my $ordernumber = $input->param('ordernumber');
90 $datereceived = $datereceived ? C4
::Dates
->new($datereceived, 'iso') : C4
::Dates
->new();
92 my $bookseller = GetBookSellerFromId
($booksellerid);
94 $results = SearchOrders
({
95 ordernumber
=> $ordernumber
98 my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user
(
100 template_name
=> "acqui/orderreceive.tmpl",
103 authnotrequired
=> 0,
104 flagsrequired
=> {acquisition
=> 'order_receive'},
109 unless ( $results and @
$results) {
110 output_html_with_http_headers
$input, $cookie, $template->output;
114 # prepare the form for receiving
115 my $order = $results->[0];
117 # Check if ACQ framework exists
118 my $acq_fw = GetMarcStructure
(1, 'ACQ');
120 $template->param('NoACQframework' => 1);
123 my $AcqCreateItem = C4
::Context
->preference('AcqCreateItem');
124 if ($AcqCreateItem eq 'receiving') {
126 AcqCreateItemReceiving
=> 1,
127 UniqueItemFields
=> C4
::Context
->preference('UniqueItemFields'),
129 } elsif ($AcqCreateItem eq 'ordering') {
130 my $fw = ($acq_fw) ?
'ACQ' : '';
131 my @itemnumbers = GetItemnumbersFromOrder
($order->{ordernumber
});
133 foreach (@itemnumbers) {
134 my $item = GetItem
($_);
135 if($item->{homebranch
}) {
136 $item->{homebranchname
} = GetBranchName
($item->{homebranch
});
138 if($item->{holdingbranch
}) {
139 $item->{holdingbranchname
} = GetBranchName
($item->{holdingbranch
});
141 if(my $code = GetAuthValCode
("items.notforloan", $fw)) {
142 $item->{notforloan
} = GetKohaAuthorisedValueLib
($code, $item->{notforloan
});
144 if(my $code = GetAuthValCode
("items.restricted", $fw)) {
145 $item->{restricted
} = GetKohaAuthorisedValueLib
($code, $item->{restricted
});
147 if(my $code = GetAuthValCode
("items.location", $fw)) {
148 $item->{location
} = GetKohaAuthorisedValueLib
($code, $item->{location
});
150 if(my $code = GetAuthValCode
("items.ccode", $fw)) {
151 $item->{collection
} = GetKohaAuthorisedValueLib
($code, $item->{ccode
});
153 if(my $code = GetAuthValCode
("items.materials", $fw)) {
154 $item->{materials
} = GetKohaAuthorisedValueLib
($code, $item->{materials
});
156 my $itemtype = getitemtypeinfo
($item->{itype
});
157 $item->{itemtype
} = $itemtype->{description
};
160 $template->param(items
=> \
@items);
163 $order->{quantityreceived
} = '' if $order->{quantityreceived
} == 0;
164 $order->{unitprice
} = '' if $order->{unitprice
} == 0;
169 if ( $bookseller->{listincgst
} ) {
170 if ( $bookseller->{invoiceincgst
} ) {
171 $rrp = $order->{rrp
};
172 $ecost = $order->{ecost
};
173 $unitprice = $order->{unitprice
};
175 $rrp = $order->{rrp
} / ( 1 + $order->{gstrate
} );
176 $ecost = $order->{ecost
} / ( 1 + $order->{gstrate
} );
177 $unitprice = $order->{unitprice
} / ( 1 + $order->{gstrate
} );
180 if ( $bookseller->{invoiceincgst
} ) {
181 $rrp = $order->{rrp
} * ( 1 + $order->{gstrate
} );
182 $ecost = $order->{ecost
} * ( 1 + $order->{gstrate
} );
183 $unitprice = $order->{unitprice
} * ( 1 + $order->{gstrate
} );
185 $rrp = $order->{rrp
};
186 $ecost = $order->{ecost
};
187 $unitprice = $order->{unitprice
};
191 my $suggestion = GetSuggestionInfoFromBiblionumber
($order->{biblionumber
});
193 my $authorisedby = $order->{authorisedby
};
194 my $member = GetMember
( borrowernumber
=> $authorisedby );
196 my $budget = GetBudget
( $order->{budget_id
} );
199 AcqCreateItem
=> $AcqCreateItem,
201 biblionumber
=> $order->{'biblionumber'},
202 ordernumber
=> $order->{'ordernumber'},
203 subscriptionid
=> $order->{subscriptionid
},
204 booksellerid
=> $order->{'booksellerid'},
206 name
=> $bookseller->{'name'},
207 date
=> format_date
($order->{entrydate
}),
208 title
=> $order->{'title'},
209 author
=> $order->{'author'},
210 copyrightdate
=> $order->{'copyrightdate'},
211 isbn
=> $order->{'isbn'},
212 seriestitle
=> $order->{'seriestitle'},
213 bookfund
=> $budget->{budget_name
},
214 quantity
=> $order->{'quantity'},
215 quantityreceivedplus1
=> $order->{'quantityreceived'} + 1,
216 quantityreceived
=> $order->{'quantityreceived'},
217 rrp
=> sprintf( "%.2f", $rrp ),
218 ecost
=> sprintf( "%.2f", $ecost ),
219 memberfirstname
=> $member->{firstname
} || "",
220 membersurname
=> $member->{surname
} || "",
221 invoiceid
=> $invoice->{invoiceid
},
222 invoice
=> $invoice->{invoicenumber
},
223 datereceived
=> $datereceived->output(),
224 datereceived_iso
=> $datereceived->output('iso'),
225 notes
=> $order->{notes
},
226 suggestionid
=> $suggestion->{suggestionid
},
227 surnamesuggestedby
=> $suggestion->{surnamesuggestedby
},
228 firstnamesuggestedby
=> $suggestion->{firstnamesuggestedby
},
231 my $borrower = GetMember
( 'borrowernumber' => $loggedinuser );
233 my $periods = GetBudgetPeriods
( );
234 foreach my $period (@
$periods) {
235 if ($period->{'budget_period_id'} == $budget->{'budget_period_id'}) {
236 $template->{'VARS'}->{'budget_period_description'} = $period->{'budget_period_description'};
238 next if $period->{'budget_period_locked'} || !$period->{'budget_period_description'};
239 my $budget_hierarchy = GetBudgetHierarchy
( $period->{'budget_period_id'} );
241 foreach my $r ( @
{$budget_hierarchy} ) {
242 next unless ( CanUserUseBudget
( $borrower, $r, $userflags ) );
243 if ( !defined $r->{budget_amount
} || $r->{budget_amount
} == 0 ) {
248 b_id
=> $r->{budget_id
},
249 b_txt
=> $r->{budget_name
},
250 b_sel
=> ( $r->{budget_id
} == $order->{budget_id
} ) ?
1 : 0,
254 @funds = sort { uc( $a->{b_txt
} ) cmp uc( $b->{b_txt
} ) } @funds;
258 'id' => $period->{'budget_period_id'},
259 'description' => $period->{'budget_period_description'},
264 $template->{'VARS'}->{'budget_loop'} = \
@budget_loop;
266 # regardless of the content of $unitprice e.g 0 or '' or any string will return in these cases 0.00
267 # and the 'IF' in the .tt will show 0.00 and not 'ecost' (see BZ 7129)
268 # So if $unitprice == 0 we don't create unitprice
269 if ( $unitprice != 0) {
271 unitprice
=> sprintf( "%.2f", $unitprice),
275 my $op = $input->param('op');
276 if ($op and $op eq 'edit'){
277 $template->param(edit
=> 1);
279 output_html_with_http_headers
$input, $cookie, $template->output;