-my $rrp=$input->param('rrp');
-my $ecost=$input->param('ecost');
-my $gst=$input->param('GST');
-my $orderexists=$input->param('orderexists');
-my $budget=$input->param('budget');
-my $cost=$input->param('cost');
-my $sub=$input->param('sub');
-my $invoice=$input->param('invoice');
-my $publishercode = $input->param('publishercode');
-if ($quantity ne '0'){
- #check to see if biblio exists
- if ($existing eq 'no'){
- #if it doesnt create it
- $bibnum = &newbiblio({ title => $title?$title:"",
- author => $author?$author:"",
- copyrightdate => $copyrightdate?$copyrightdate:"",
- series => $series?$series:"",
- });
- $bibitemnum = &newbiblioitem({ biblionumber => $bibnum,
- itemtype => $itemtype?$itemtype:"",
- isbn => $isbn?$isbn:"",
- publishercode => $publishercode?$publishercode:"",
- });
- if ($title) {
- newsubtitle($bibnum,$title);
- }
- } else {
- $bibnum=$input->param('biblio');
- $bibitemnum=$input->param('bibitemnum');
- my $oldtype=$input->param('oldtype');
- if ($bibitemnum eq '' || $itemtype ne $oldtype){
- $bibitemnum= &newbiblioitem({ biblionumber => $bibnum,
- itemtype => $itemtype?$itemtype:"",
- isbn => $isbn?$isbn:"" ,
- publishercode => $publishercode?$publishercode:"",
- });
- } else {
- &modbibitem({biblioitemnumber => $bibitemnum,
- isbn => $isbn,
- publishercode => $publishercode,
- });
- }
- &modbiblio({
- biblionumber => $bibnum,
- title => $title?$title:"",
- author => $author?$author:"",
- copyrightdate => $copyrightdate?$copyrightdate:"",
- series => $series?$series:"" },
- );
- }
- if ($orderexists ne '') {
- modorder($title,$ordnum,$quantity,$listprice,$bibnum,$basketno,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst,$budget,$cost,$sub,$invoice,$sort1,$sort2);
- }else {
- neworder($bibnum,$title,$ordnum,$basketno,$quantity,$listprice,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst,$budget,$cost,$sub,$invoice,$sort1,$sort2);
- }
-} else {
- $bibnum=$input->param('biblio');
- delorder($bibnum,$ordnum);
+if ( $orderinfo->{quantity} ne '0' ) {
+ #TODO:check to see if biblio exists
+ unless ( $$orderinfo{biblionumber} ) {
+ #if it doesnt create it
+ my $record = TransformKohaToMarc(
+ {
+ "biblio.title" => "$$orderinfo{title}",
+ "biblio.author" => $$orderinfo{author} ? $$orderinfo{author} : "",
+ "biblio.seriestitle" => $$orderinfo{series} ? $$orderinfo{series} : "",
+ "biblioitems.isbn" => $$orderinfo{isbn} ? $$orderinfo{isbn} : "",
+ "biblioitems.ean" => $$orderinfo{ean} ? $$orderinfo{ean} : "",
+ "biblioitems.publishercode" => $$orderinfo{publishercode} ? $$orderinfo{publishercode} : "",
+ "biblioitems.publicationyear" => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear}: "",
+ "biblio.copyrightdate" => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear}: "",
+ "biblioitems.itemtype" => $$orderinfo{itemtype} ? $$orderinfo{itemtype} : "",
+ "biblioitems.editionstatement"=> $$orderinfo{editionstatement} ? $$orderinfo{editionstatement} : "",
+ "aqorders.branchcode" => $$orderinfo{branchcode} ? $$orderinfo{branchcode} : "",
+ "aqorders.quantity" => $$orderinfo{quantity} ? $$orderinfo{quantity} : "",
+ "aqorders.listprice" => $$orderinfo{listprice} ? $$orderinfo{listprice} : "",
+ "aqorders.uncertainprice" => $$orderinfo{uncertainprice} ? $$orderinfo{uncertainprice} : "",
+ "aqorders.rrp" => $$orderinfo{rrp} ? $$orderinfo{rrp} : "",
+ "aqorders.ecost" => $$orderinfo{ecost} ? $$orderinfo{ecost} : "",
+ "aqorders.discount" => $$orderinfo{discount} ? $$orderinfo{discount} : "",
+ });
+
+ # create the record in catalogue, with framework ''
+ my ($biblionumber,$bibitemnum) = AddBiblio($record,'');
+ # change suggestion status if applicable
+ if ($$orderinfo{suggestionid}) {
+ ModSuggestion( {suggestionid=>$$orderinfo{suggestionid}, STATUS=>'ORDERED', biblionumber=>$biblionumber} );
+ }
+ $orderinfo->{biblioitemnumber}=$bibitemnum;
+ $orderinfo->{biblionumber}=$biblionumber;
+ }
+
+ $orderinfo->{unitprice} = $orderinfo->{ecost} if not defined $orderinfo->{unitprice} or $orderinfo->{unitprice} eq '';
+
+ # if we already have $ordernumber, then it's an ordermodif
+ if ($$orderinfo{ordernumber}) {
+ ModOrder( $orderinfo);
+ }
+ else { # else, it's a new line
+ @$orderinfo{qw(basketno ordernumber )} = NewOrder($orderinfo);
+ }
+
+ # now, add items if applicable
+ if (C4::Context->preference('AcqCreateItem') eq 'ordering') {
+
+ my @tags = $input->param('tag');
+ my @subfields = $input->param('subfield');
+ my @field_values = $input->param('field_value');
+ my @serials = $input->param('serial');
+ my @itemid = $input->param('itemid');
+ my @ind_tag = $input->param('ind_tag');
+ my @indicator = $input->param('indicator');
+ #Rebuilding ALL the data for items into a hash
+ # parting them on $itemid.
+
+ my %itemhash;
+ my $countdistinct;
+ my $range=scalar(@itemid);
+ for (my $i=0; $i<$range; $i++){
+ unless ($itemhash{$itemid[$i]}){
+ $countdistinct++;
+ }
+ push @{$itemhash{$itemid[$i]}->{'tags'}},$tags[$i];
+ push @{$itemhash{$itemid[$i]}->{'subfields'}},$subfields[$i];
+ push @{$itemhash{$itemid[$i]}->{'field_values'}},$field_values[$i];
+ push @{$itemhash{$itemid[$i]}->{'ind_tag'}},$ind_tag[$i];
+ push @{$itemhash{$itemid[$i]}->{'indicator'}},$indicator[$i];
+ }
+ foreach my $item (keys %itemhash){
+
+ my $xml = TransformHtmlToXml( $itemhash{$item}->{'tags'},
+ $itemhash{$item}->{'subfields'},
+ $itemhash{$item}->{'field_values'},
+ $itemhash{$item}->{'ind_tag'},
+ $itemhash{$item}->{'indicator'},
+ 'ITEM');
+ my $record=MARC::Record::new_from_xml($xml, 'UTF-8');
+ my ($biblionumber,$bibitemnum,$itemnumber) = AddItemFromMarc($record,$$orderinfo{biblionumber});
+ NewOrderItem($itemnumber, $$orderinfo{ordernumber});
+
+ }
+ }
+