Lines 122-131
if it is an order from an existing suggestion : the id of this suggestion.
Link Here
|
122 |
use strict; |
122 |
use strict; |
123 |
use warnings; |
123 |
use warnings; |
124 |
use CGI; |
124 |
use CGI; |
125 |
use C4::Auth; # get_template_and_user |
125 |
use C4::Auth; # get_template_and_user |
126 |
use C4::Acquisition; # NewOrder DelOrder ModOrder |
126 |
use C4::Acquisition; # NewOrder DelOrder ModOrder |
127 |
use C4::Suggestions; # ModStatus |
127 |
use C4::Suggestions; # ModStatus |
128 |
use C4::Biblio; # AddBiblio TransformKohaToMarc |
128 |
use C4::Biblio; # AddBiblio TransformKohaToMarc |
|
|
129 |
use C4::Bookseller qw/GetBookSellerFromId/; |
129 |
use C4::Items; |
130 |
use C4::Items; |
130 |
use C4::Output; |
131 |
use C4::Output; |
131 |
|
132 |
|
Lines 150-156
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
Link Here
|
150 |
); |
151 |
); |
151 |
|
152 |
|
152 |
# get CGI parameters |
153 |
# get CGI parameters |
153 |
my $orderinfo = $input->Vars; |
154 |
my $orderinfo = $input->Vars; |
154 |
$orderinfo->{'list_price'} ||= 0; |
155 |
$orderinfo->{'list_price'} ||= 0; |
155 |
$orderinfo->{'uncertainprice'} ||= 0; |
156 |
$orderinfo->{'uncertainprice'} ||= 0; |
156 |
|
157 |
|
Lines 163-214
my $user = $input->remote_user;
Link Here
|
163 |
# delete biblio if delbiblio has been set to 1 by the librarian |
164 |
# delete biblio if delbiblio has been set to 1 by the librarian |
164 |
my $bibitemnum; |
165 |
my $bibitemnum; |
165 |
if ( $orderinfo->{quantity} ne '0' ) { |
166 |
if ( $orderinfo->{quantity} ne '0' ) { |
|
|
167 |
|
168 |
# Getting bookseller's name |
169 |
if ($orderinfo->{booksellerid}) { |
170 |
my $bookseller = GetBookSellerFromId($orderinfo->{booksellerid}); |
171 |
$orderinfo->{supplierreference} = $bookseller->{name}; |
172 |
} |
173 |
|
174 |
# Do we have to add order informations to the marc record? |
175 |
my ($ordertag, $ordersubtag) = GetMarcFromKohaField('aqorders.ordernumber', 'ACQ'); |
176 |
my $record; |
177 |
my $existingbiblio; # Was the order made on an existing biblio? |
178 |
my $ordermodif; # Is this an order modification? |
179 |
|
166 |
#TODO:check to see if biblio exists |
180 |
#TODO:check to see if biblio exists |
167 |
unless ( $$orderinfo{biblionumber} ) { |
181 |
unless ( $orderinfo->{biblionumber} ) { |
168 |
#if it doesnt create it |
182 |
#if it doesnt create it |
169 |
my $record = TransformKohaToMarc( |
183 |
my $tmprecord = TransformKohaToMarc( |
170 |
{ |
184 |
{ "biblio.title" => "$$orderinfo{title}", |
171 |
"biblio.title" => "$$orderinfo{title}", |
185 |
"biblio.author" => $$orderinfo{author} ? $$orderinfo{author} : "", |
172 |
"biblio.author" => $$orderinfo{author} ? $$orderinfo{author} : "", |
186 |
"biblio.seriestitle" => $$orderinfo{series} ? $$orderinfo{series} : "", |
173 |
"biblio.seriestitle" => $$orderinfo{series} ? $$orderinfo{series} : "", |
187 |
"biblio.copyrightdate" => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear} : "", |
174 |
"biblioitems.isbn" => $$orderinfo{isbn} ? $$orderinfo{isbn} : "", |
188 |
"biblioitems.isbn" => $$orderinfo{isbn} ? $$orderinfo{isbn} : "", |
175 |
"biblioitems.ean" => $$orderinfo{ean} ? $$orderinfo{ean} : "", |
189 |
"biblioitems.ean" => $$orderinfo{ean} ? $$orderinfo{ean} : "", |
176 |
"biblioitems.publishercode" => $$orderinfo{publishercode} ? $$orderinfo{publishercode} : "", |
190 |
"biblioitems.publishercode" => $$orderinfo{publishercode} ? $$orderinfo{publishercode} : "", |
177 |
"biblioitems.publicationyear" => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear}: "", |
191 |
"biblioitems.publicationyear" => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear} : "", |
178 |
"biblio.copyrightdate" => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear}: "", |
192 |
"biblioitems.itemtype" => $$orderinfo{itemtype} ? $$orderinfo{itemtype} : "", |
179 |
"biblioitems.itemtype" => $$orderinfo{itemtype} ? $$orderinfo{itemtype} : "", |
193 |
"biblioitems.editionstatement"=> $$orderinfo{editionstatement}? $$orderinfo{editionstatement}: "", |
180 |
"biblioitems.editionstatement"=> $$orderinfo{editionstatement} ? $$orderinfo{editionstatement} : "", |
194 |
"aqorders.branchcode" => $$orderinfo{branchcode} ? $$orderinfo{branchcode} : "", |
181 |
"aqorders.branchcode" => $$orderinfo{branchcode} ? $$orderinfo{branchcode} : "", |
195 |
"aqorders.quantity" => $$orderinfo{quantity} ? $$orderinfo{quantity} : "", |
182 |
"aqorders.quantity" => $$orderinfo{quantity} ? $$orderinfo{quantity} : "", |
196 |
"aqorders.listprice" => $$orderinfo{listprice} ? $$orderinfo{listprice} : "", |
183 |
"aqorders.listprice" => $$orderinfo{listprice} ? $$orderinfo{listprice} : "", |
197 |
"aqorders.uncertainprice" => $$orderinfo{uncertainprice} ? $$orderinfo{uncertainprice} : "", |
184 |
"aqorders.uncertainprice" => $$orderinfo{uncertainprice} ? $$orderinfo{uncertainprice} : "", |
198 |
"aqorders.rrp" => $$orderinfo{rrp} ? $$orderinfo{rrp} : "", |
185 |
"aqorders.rrp" => $$orderinfo{rrp} ? $$orderinfo{rrp} : "", |
199 |
"aqorders.ecost" => $$orderinfo{ecost} ? $$orderinfo{ecost} : "", |
186 |
"aqorders.ecost" => $$orderinfo{ecost} ? $$orderinfo{ecost} : "", |
200 |
"aqorders.discount" => $$orderinfo{discount} ? $$orderinfo{discount} : "", |
187 |
"aqorders.discount" => $$orderinfo{discount} ? $$orderinfo{discount} : "", |
201 |
"aqorders.notes" => $$orderinfo{notes} ? $$orderinfo{notes} : "", |
188 |
}); |
202 |
"aqorders.supplierreference" => $$orderinfo{supplierreference}?$$orderinfo{supplierreference}:"", |
|
|
203 |
"aqorders.sort1" => $$orderinfo{sort1} ? $$orderinfo{sort1} : "", |
204 |
"aqorders.sort2" => $$orderinfo{sort2} ? $$orderinfo{sort2} : "" |
205 |
} |
206 |
); |
189 |
|
207 |
|
190 |
# create the record in catalogue, with framework '' |
208 |
# create the record in catalogue, with framework '' |
191 |
my ($biblionumber,$bibitemnum) = AddBiblio($record,''); |
209 |
my ( $biblionumber, $bibitemnum ) = AddBiblio( $tmprecord, '' ); |
|
|
210 |
|
192 |
# change suggestion status if applicable |
211 |
# change suggestion status if applicable |
193 |
if ($$orderinfo{suggestionid}) { |
212 |
if ($$orderinfo{suggestionid}) { |
194 |
ModSuggestion( {suggestionid=>$$orderinfo{suggestionid}, STATUS=>'ORDERED', biblionumber=>$biblionumber} ); |
213 |
ModSuggestion( {suggestionid=>$$orderinfo{suggestionid}, STATUS=>'ORDERED', biblionumber=>$biblionumber} ); |
195 |
} |
214 |
} |
196 |
$orderinfo->{biblioitemnumber}=$bibitemnum; |
215 |
$orderinfo->{biblioitemnumber} = $bibitemnum; |
197 |
$orderinfo->{biblionumber}=$biblionumber; |
216 |
$orderinfo->{biblionumber} = $biblionumber; |
|
|
217 |
} else { |
218 |
$existingbiblio = 1; |
198 |
} |
219 |
} |
199 |
|
220 |
|
200 |
$orderinfo->{unitprice} = $orderinfo->{ecost} if not defined $orderinfo->{unitprice} or $orderinfo->{unitprice} eq ''; |
221 |
$orderinfo->{unitprice} = $orderinfo->{ecost} if not defined $orderinfo->{unitprice} or $orderinfo->{unitprice} eq ''; |
201 |
|
222 |
|
202 |
# if we already have $ordernumber, then it's an ordermodif |
223 |
# Getting record |
203 |
if ($$orderinfo{ordernumber}) { |
224 |
$record = GetMarcBiblio($orderinfo->{biblionumber}); |
204 |
ModOrder( $orderinfo); |
225 |
|
205 |
} |
226 |
|
206 |
else { # else, it's a new line |
227 |
|
|
|
228 |
# if we already have $ordernumber, then it's an ordermodif |
229 |
if ( $orderinfo->{ordernumber} ) { |
230 |
ModOrder($orderinfo); |
231 |
$ordermodif = 1; |
232 |
|
233 |
} else { # else, it's a new line |
207 |
@$orderinfo{qw(basketno ordernumber )} = NewOrder($orderinfo); |
234 |
@$orderinfo{qw(basketno ordernumber )} = NewOrder($orderinfo); |
|
|
235 |
|
236 |
# We have to add the ordernumber in the designated subfield |
237 |
if ($ordertag && $record && !$ordermodif) { |
238 |
|
239 |
# If it's a new line, but we don't have any $ordertag field yet, |
240 |
if (!$record->field($ordertag)) { |
241 |
# We add a new $ordertag field, with the ordernumber as subfield (other fields will be populated later) |
242 |
$record->insert_fields_ordered(new MARC::Field($ordertag, '', '', $ordersubtag => $orderinfo->{ordernumber})) if (!$record->field($ordertag)); |
243 |
} else { |
244 |
# Else, it's a new line, and we already have a $ordertag field |
245 |
foreach ($record->field($ordertag)) { |
246 |
# If there's a $ordertag field without ordernumber, we create it |
247 |
if (!$_->subfield($ordersubtag)) { |
248 |
$_->update($ordersubtag, $orderinfo->{ordernumber}); |
249 |
} |
250 |
} |
251 |
} |
252 |
ModBiblio($record, $orderinfo->{biblionumber}, 'ACQ'); |
253 |
} |
254 |
|
255 |
|
208 |
} |
256 |
} |
209 |
|
257 |
|
210 |
# now, add items if applicable |
258 |
if ($record) { |
211 |
if (C4::Context->preference('AcqCreateItem') eq 'ordering') { |
259 |
|
|
|
260 |
# If we have to add order infos to the marc record |
261 |
if ($ordertag) { |
262 |
|
263 |
# If the order was made on an existing biblio and it is not a modification, we add the field |
264 |
$record->insert_fields_ordered(new MARC::Field($ordertag, '', '', $ordersubtag => $$orderinfo{ordernumber})) if (!$ordermodif && $existingbiblio); |
265 |
|
266 |
foreach ($record->field($ordertag)) { |
267 |
# Looking for the matching one |
268 |
if ($_->subfield($ordersubtag) eq $orderinfo->{ordernumber}) { |
269 |
|
270 |
# Replacing or creating subfields |
271 |
my ($t, $st); |
272 |
for my $tablefield (qw/branchcode quantity listprice uncertainprice rrp ecost notes supplierreference sort1 sort2/) { |
273 |
($t, $st) = GetMarcFromKohaField("aqorders.$tablefield", 'ACQ'); |
274 |
$_->update($st, $orderinfo->{$tablefield}) if ($orderinfo->{$tablefield} and $st); |
275 |
} |
276 |
ModBiblio($record, $orderinfo->{biblionumber}, 'ACQ'); |
277 |
} |
278 |
} |
279 |
|
280 |
} |
281 |
|
282 |
} |
283 |
|
284 |
|
285 |
# now, add items if applicable |
286 |
if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) { |
212 |
|
287 |
|
213 |
my @tags = $input->param('tag'); |
288 |
my @tags = $input->param('tag'); |
214 |
my @subfields = $input->param('subfield'); |
289 |
my @subfields = $input->param('subfield'); |