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 /;
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 = SearchOrder
($ordernumber) if $ordernumber;
96 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
98 template_name
=> "acqui/orderreceive.tmpl",
101 authnotrequired
=> 0,
102 flagsrequired
=> {acquisition
=> 'order_receive'},
107 unless ( $results and @
$results) {
108 output_html_with_http_headers
$input, $cookie, $template->output;
112 # prepare the form for receiving
113 my $order = $results->[0];
115 # Check if ACQ framework exists
116 my $acq_fw = GetMarcStructure
(1, 'ACQ');
118 $template->param('NoACQframework' => 1);
121 my $AcqCreateItem = C4
::Context
->preference('AcqCreateItem');
122 if ($AcqCreateItem eq 'receiving') {
124 AcqCreateItemReceiving
=> 1,
125 UniqueItemFields
=> C4
::Context
->preference('UniqueItemFields'),
127 } elsif ($AcqCreateItem eq 'ordering') {
128 my $fw = ($acq_fw) ?
'ACQ' : '';
129 my @itemnumbers = GetItemnumbersFromOrder
($order->{ordernumber
});
131 foreach (@itemnumbers) {
132 my $item = GetItem
($_);
133 if($item->{homebranch
}) {
134 $item->{homebranchname
} = GetBranchName
($item->{homebranch
});
136 if($item->{holdingbranch
}) {
137 $item->{holdingbranchname
} = GetBranchName
($item->{holdingbranch
});
139 if(my $code = GetAuthValCode
("items.notforloan", $fw)) {
140 $item->{notforloan
} = GetKohaAuthorisedValueLib
($code, $item->{notforloan
});
142 if(my $code = GetAuthValCode
("items.restricted", $fw)) {
143 $item->{restricted
} = GetKohaAuthorisedValueLib
($code, $item->{restricted
});
145 if(my $code = GetAuthValCode
("items.location", $fw)) {
146 $item->{location
} = GetKohaAuthorisedValueLib
($code, $item->{location
});
148 if(my $code = GetAuthValCode
("items.ccode", $fw)) {
149 $item->{collection
} = GetKohaAuthorisedValueLib
($code, $item->{ccode
});
151 if(my $code = GetAuthValCode
("items.materials", $fw)) {
152 $item->{materials
} = GetKohaAuthorisedValueLib
($code, $item->{materials
});
154 my $itemtype = getitemtypeinfo
($item->{itype
});
155 $item->{itemtype
} = $itemtype->{description
};
158 $template->param(items
=> \
@items);
161 $order->{quantityreceived
} = '' if $order->{quantityreceived
} == 0;
162 $order->{unitprice
} = '' if $order->{unitprice
} == 0;
167 if ( $bookseller->{listincgst
} ) {
168 if ( $bookseller->{invoiceincgst
} ) {
169 $rrp = $order->{rrp
};
170 $ecost = $order->{ecost
};
171 $unitprice = $order->{unitprice
};
173 $rrp = $order->{rrp
} / ( 1 + $order->{gstrate
} );
174 $ecost = $order->{ecost
} / ( 1 + $order->{gstrate
} );
175 $unitprice = $order->{unitprice
} / ( 1 + $order->{gstrate
} );
178 if ( $bookseller->{invoiceincgst
} ) {
179 $rrp = $order->{rrp
} * ( 1 + $order->{gstrate
} );
180 $ecost = $order->{ecost
} * ( 1 + $order->{gstrate
} );
181 $unitprice = $order->{unitprice
} * ( 1 + $order->{gstrate
} );
183 $rrp = $order->{rrp
};
184 $ecost = $order->{ecost
};
185 $unitprice = $order->{unitprice
};
189 my $suggestion = GetSuggestionInfoFromBiblionumber
($order->{biblionumber
});
191 my $authorisedby = $order->{authorisedby
};
192 my $member = GetMember
( borrowernumber
=> $authorisedby );
194 my $budget = GetBudget
( $order->{budget_id
} );
197 AcqCreateItem
=> $AcqCreateItem,
199 biblionumber
=> $order->{'biblionumber'},
200 ordernumber
=> $order->{'ordernumber'},
201 biblioitemnumber
=> $order->{'biblioitemnumber'},
202 subscriptionid
=> $order->{subscriptionid
},
203 booksellerid
=> $order->{'booksellerid'},
205 name
=> $bookseller->{'name'},
206 date
=> format_date
($order->{entrydate
}),
207 title
=> $order->{'title'},
208 author
=> $order->{'author'},
209 copyrightdate
=> $order->{'copyrightdate'},
210 isbn
=> $order->{'isbn'},
211 seriestitle
=> $order->{'seriestitle'},
212 bookfund
=> $budget->{budget_name
},
213 quantity
=> $order->{'quantity'},
214 quantityreceivedplus1
=> $order->{'quantityreceived'} + 1,
215 quantityreceived
=> $order->{'quantityreceived'},
216 rrp
=> sprintf( "%.2f", $rrp ),
217 ecost
=> sprintf( "%.2f", $ecost ),
218 memberfirstname
=> $member->{firstname
} || "",
219 membersurname
=> $member->{surname
} || "",
220 invoiceid
=> $invoice->{invoiceid
},
221 invoice
=> $invoice->{invoicenumber
},
222 datereceived
=> $datereceived->output(),
223 datereceived_iso
=> $datereceived->output('iso'),
224 notes
=> $order->{notes
},
225 suggestionid
=> $suggestion->{suggestionid
},
226 surnamesuggestedby
=> $suggestion->{surnamesuggestedby
},
227 firstnamesuggestedby
=> $suggestion->{firstnamesuggestedby
},
230 # regardless of the content of $unitprice e.g 0 or '' or any string will return in these cases 0.00
231 # and the 'IF' in the .tt will show 0.00 and not 'ecost' (see BZ 7129)
232 # So if $unitprice == 0 we don't create unitprice
233 if ( $unitprice != 0) {
235 unitprice
=> sprintf( "%.2f", $unitprice),
239 my $op = $input->param('op');
240 if ($op and $op eq 'edit'){
241 $template->param(edit
=> 1);
243 output_html_with_http_headers
$input, $cookie, $template->output;