[Patches] [PATCH] bug_3966: Update items on receive

koha-patchbot at kohaaloha.com koha-patchbot at kohaaloha.com
Fri Nov 4 19:55:53 NZDT 2011


From: Srdjan Jankovic <srdjan at catalyst.net.nz>
Date: Tue, 1 Nov 2011 20:25:31 +1300
Subject: [PATCH] bug_3966: Update items on receive

Changed AddItem() and ModItem() interface so now they return item
record.
AddItemFromMarc() looks for itemnumber, and calls ModItem() if one is
found.
---
 C4/Acquisition.pm                                  |   50 +++------
 C4/Biblio.pm                                       |    6 +-
 C4/ImportBatch.pm                                  |    4 +-
 C4/Items.pm                                        |   19 ++-
 acqui/addorder.pl                                  |    5 +-
 acqui/addorderiso2709.pl                           |    4 +-
 acqui/booksellers.pl                               |    7 +-
 acqui/finishreceive.pl                             |  125 ++++++++++----------
 acqui/orderreceive.pl                              |   63 +++++------
 cataloguing/additem.pl                             |    8 +-
 .../prog/en/modules/acqui/orderreceive.tt          |   36 +++---
 t/db_dependent/lib/KohaTest.pm                     |   16 +--
 .../lib/KohaTest/Acquisition/GetParcel.pm          |   17 +--
 .../lib/KohaTest/Acquisition/GetParcels.pm         |   18 +--
 t/db_dependent/lib/KohaTest/Biblio/ModBiblio.pm    |    6 +-
 15 files changed, 173 insertions(+), 211 deletions(-)

diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm
index 19c4f08..c9525c1 100644
--- a/C4/Acquisition.pm
+++ b/C4/Acquisition.pm
@@ -1048,16 +1048,14 @@ sub ModOrderBiblioitemNumber {
 
 =head3 ModReceiveOrder
 
-  &ModReceiveOrder($biblionumber, $ordernumber, $quantityreceived, $user,
-    $unitprice, $booksellerinvoicenumber, $biblioitemnumber,
-    $freight, $bookfund, $rrp);
+  &ModReceiveOrder($biblionumber, $ordernumber, $quantityreceived, $receiveditems);
 
 Updates an order, to reflect the fact that it was received, at least
-in part. All arguments not mentioned below update the fields with the
-same name in the aqorders table of the Koha database.
+in part.
 
 If a partial order is received, splits the order into two.  The received
-portion must have a booksellerinvoicenumber.
+portion must have a booksellerinvoicenumber. If $receiveditems are supplied,
+the rest of the items will be moved to the new order.
 
 Updates the order with bibilionumber C<$biblionumber> and ordernumber
 C<$ordernumber>.
@@ -1066,16 +1064,11 @@ C<$ordernumber>.
 
 
 sub ModReceiveOrder {
-    my (
-        $biblionumber,    $ordernumber,  $quantrec, $user, $cost,
-        $invoiceno, $freight, $rrp, $budget_id, $datereceived
-    )
-    = @_;
+    my ( $biblionumber, $ordernumber,  $quantrec, $receiveditems ) = @_;
     my $dbh = C4::Context->dbh;
 #     warn "DATE BEFORE : $daterecieved";
 #    $daterecieved=POSIX::strftime("%Y-%m-%d",CORE::localtime) unless $daterecieved;
 #     warn "DATE REC : $daterecieved";
-    $datereceived = C4::Dates->output('iso') unless $datereceived;
     my $suggestionid = GetSuggestionFromBiblionumber( $dbh, $biblionumber );
     if ($suggestionid) {
         ModSuggestion( {suggestionid=>$suggestionid,
@@ -1093,36 +1086,23 @@ sub ModReceiveOrder {
     $sth->finish();
 
     if ( $order->{quantity} > $quantrec ) {
-        $sth=$dbh->prepare("
-            UPDATE aqorders
-            SET quantityreceived=?
-                , datereceived=?
-                , booksellerinvoicenumber=?
-                , unitprice=?
-                , freight=?
-                , rrp=?
-                , quantity=?
-            WHERE biblionumber=? AND ordernumber=?");
-
-        $sth->execute($quantrec,$datereceived,$invoiceno,$cost,$freight,$rrp,$quantrec,$biblionumber,$ordernumber);
-        $sth->finish;
-
         # create a new order for the remaining items, and set its bookfund.
         foreach my $orderkey ( "linenumber", "allocation" ) {
             delete($order->{'$orderkey'});
         }
         $order->{'quantity'} -= $quantrec;
         $order->{'quantityreceived'} = 0;
-        my $newOrder = NewOrder($order);
-} else {
-        $sth=$dbh->prepare("update aqorders
-                            set quantityreceived=?,datereceived=?,booksellerinvoicenumber=?,
-                                unitprice=?,freight=?,rrp=?
-                            where biblionumber=? and ordernumber=?");
-        $sth->execute($quantrec,$datereceived,$invoiceno,$cost,$freight,$rrp,$biblionumber,$ordernumber);
-        $sth->finish;
+        my (undef, $newOrder) = NewOrder($order);
+
+        if ($receiveditems && @$receiveditems) {
+            my $sql = "
+                UPDATE aqorders_items
+                SET ordernumber = ?
+                WHERE ordernumber = ?
+                AND itemnumber NOT IN (".join(",", map "?", @$receiveditems).")";
+            $dbh->do($sql, undef, $newOrder, $ordernumber, @$receiveditems);
+        }
     }
-    return $datereceived;
 }
 #------------------------------------------------------------#
 
diff --git a/C4/Biblio.pm b/C4/Biblio.pm
index 4a9735f..9f1d275 100644
--- a/C4/Biblio.pm
+++ b/C4/Biblio.pm
@@ -2471,7 +2471,7 @@ sub TransformMarcToKohaOneField {
 
 =head2 PrepareItemrecordDisplay
 
-  PrepareItemrecordDisplay($itemrecord,$bibnum,$itemumber,$frameworkcode);
+  PrepareItemrecordDisplay($bibnum,$itemumber,$defaultvalues,$frameworkcode);
 
 Returns a hash with all the fields for Display a given item data in a template
 
@@ -2650,14 +2650,14 @@ sub PrepareItemrecordDisplay {
                             $subfield_data{random}     = int(rand(1000000));    # why do we need 2 different randoms?
                             my $index_subfield = int(rand(1000000));
                             $subfield_data{id} = "tag_".$tag."_subfield_".$subfield."_".$index_subfield;
-                            $subfield_data{marc_value} = qq[<input tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="67" maxlength="255"
+                            $subfield_data{marc_value} = qq[<input tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="67" maxlength="255" value="$defaultvalue"
                                 onfocus="Focus$function_name($subfield_data{random}, '$subfield_data{id}');"
                                  onblur=" Blur$function_name($subfield_data{random}, '$subfield_data{id}');" />
                                 <a href="#" class="buttonDot" onclick="Clic$function_name('$subfield_data{id}'); return false;" title="Tag Editor">...</a>
                                 $javascript];
                         } else {
                             warn "Plugin Failed: $plugin";
-                            $subfield_data{marc_value} = qq(<input tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="67" maxlength="255" />); # supply default input form
+                            $subfield_data{marc_value} = qq(<input tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="67" maxlength="255" value="$defaultvalue" />); # supply default input form
                         }
                 }
                 elsif ( $tag eq '' ) {       # it's an hidden field
diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm
index b6db406..a121d08 100644
--- a/C4/ImportBatch.pm
+++ b/C4/ImportBatch.pm
@@ -547,10 +547,10 @@ sub BatchCommitItems {
             $updsth->execute();
             $num_items_errored++;
         } else {
-            my ($item_biblionumber, $biblioitemnumber, $itemnumber) = AddItemFromMarc($item_marc, $biblionumber);
+            my $item = AddItemFromMarc($item_marc, $biblionumber);
             my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ? WHERE import_items_id = ?");
             $updsth->bind_param(1, 'imported');
-            $updsth->bind_param(2, $itemnumber);
+            $updsth->bind_param(2, $item->{itemnumber});
             $updsth->bind_param(3, $row->{'import_items_id'});
             $updsth->execute();
             $updsth->finish();
diff --git a/C4/Items.pm b/C4/Items.pm
index 4915884..8ff79ec 100644
--- a/C4/Items.pm
+++ b/C4/Items.pm
@@ -194,11 +194,11 @@ sub CartToShelf {
 
 =head2 AddItemFromMarc
 
-  my ($biblionumber, $biblioitemnumber, $itemnumber) 
-      = AddItemFromMarc($source_item_marc, $biblionumber);
+  my $item = AddItemFromMarc($source_item_marc, $biblionumber);
 
 Given a MARC::Record object containing an embedded item
-record and a biblionumber, create a new item record.
+record and a biblionumber, create a new item record or update
+existing one.
 
 =cut
 
@@ -214,13 +214,15 @@ sub AddItemFromMarc {
 	$localitemmarc->append_fields($source_item_marc->field($itemtag));
     my $item = &TransformMarcToKoha( $dbh, $localitemmarc, $frameworkcode ,'items');
     my $unlinked_item_subfields = _get_unlinked_item_subfields($localitemmarc, $frameworkcode);
+    if (my $itemnumber = $item->{itemnumber}) {
+        return ModItem($item, $biblionumber, $itemnumber, $dbh, $frameworkcode, $unlinked_item_subfields);
+    }
     return AddItem($item, $biblionumber, $dbh, $frameworkcode, $unlinked_item_subfields);
 }
 
 =head2 AddItem
 
-  my ($biblionumber, $biblioitemnumber, $itemnumber) 
-      = AddItem($item, $biblionumber[, $dbh, $frameworkcode, $unlinked_item_subfields]);
+  my $item = AddItem($item, $biblionumber[, $dbh, $frameworkcode, $unlinked_item_subfields]);
 
 Given a hash containing item column names as keys,
 create a new Koha item record.
@@ -272,7 +274,7 @@ sub AddItem {
    
     logaction("CATALOGUING", "ADD", $itemnumber, "item") if C4::Context->preference("CataloguingLog");
     
-    return ($item->{biblionumber}, $item->{biblioitemnumber}, $itemnumber);
+    return $item;
 }
 
 =head2 AddItemBatchFromMarc
@@ -451,6 +453,7 @@ sub ModItemFromMarc {
         $item->{$item_field} = $default_values_for_mod_from_marc{$item_field} unless (exists $item->{$item_field});
     }
     my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode );
+    $itemnumber ||= $item->{itemnumber};
 
     ModItem($item, $biblionumber, $itemnumber, $dbh, $frameworkcode, $unlinked_item_subfields); 
     return $item;
@@ -458,7 +461,7 @@ sub ModItemFromMarc {
 
 =head2 ModItem
 
-  ModItem({ column => $newvalue }, $biblionumber, 
+  my $item = ModItem({ column => $newvalue }, $biblionumber, 
                   $itemnumber[, $original_item_marc]);
 
 Change one or more columns in an item record and update
@@ -522,6 +525,8 @@ sub ModItem {
     ModZebra( $biblionumber, "specialUpdate", "biblioserver", undef, undef );
 
     logaction("CATALOGUING", "MODIFY", $itemnumber, Dumper($item)) if C4::Context->preference("CataloguingLog");
+
+    return $item;
 }
 
 =head2 ModItemTransfer
diff --git a/acqui/addorder.pl b/acqui/addorder.pl
index d7f7e96..8a14562 100755
--- a/acqui/addorder.pl
+++ b/acqui/addorder.pl
@@ -261,9 +261,8 @@ if ( $orderinfo->{quantity} ne '0' ) {
                                     $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});
-
+            my $item = AddItemFromMarc($record,$$orderinfo{biblionumber});
+            NewOrderItem($item->{itemnumber}, $$orderinfo{ordernumber});
         }
     }
 
diff --git a/acqui/addorderiso2709.pl b/acqui/addorderiso2709.pl
index bbfd3b7..3bc82f2 100755
--- a/acqui/addorderiso2709.pl
+++ b/acqui/addorderiso2709.pl
@@ -260,8 +260,8 @@ if ($op eq ""){
             my $xml = TransformHtmlToXml( \@tags, \@subfields, \@field_values, \@ind_tag, \@indicator );
             my $record = MARC::Record::new_from_xml( $xml, 'UTF-8' );
             for (my $qtyloop=1;$qtyloop <=$quantity;$qtyloop++) {
-                my ( $biblionumber, $bibitemnum, $itemnumber ) = AddItemFromMarc( $record, $biblionumber );
-                NewOrderItem( $itemnumber, $ordernumber );
+                my $item = AddItemFromMarc( $record, $biblionumber );
+                NewOrderItem( $item->{itemnumber}, $ordernumber );
             }
         } else {
             SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' );
diff --git a/acqui/booksellers.pl b/acqui/booksellers.pl
index 2b16fe4..875a240 100755
--- a/acqui/booksellers.pl
+++ b/acqui/booksellers.pl
@@ -111,13 +111,14 @@ for my $vendor (@suppliers) {
     
     for my $basket ( @{$baskets} ) {
         my $authorisedby = $basket->{authorisedby};
-        my $basketbranch = GetMember( borrowernumber => $authorisedby )->{branchcode};
+        my $basketbranch = '';
+        $basketbranch = GetMember( borrowernumber => $authorisedby )->{branchcode} if $authorisedby;
         
         if ($userenv->{'flags'} & 1 || #user is superlibrarian
                (haspermission( $uid, { acquisition => q{*} } ) && #user has acq permissions and
                    ($viewbaskets eq 'all' || #user is allowed to see all baskets
-                   ($viewbaskets eq 'branch' && $authorisedby && $userbranch eq $basketbranch) || #basket belongs to user's branch
-                   ($basket->{authorisedby} &&  $viewbaskets == 'user' && $authorisedby == $loggedinuser) #user created this basket
+                   ($viewbaskets eq 'branch' && $userbranch eq $basketbranch) || #basket belongs to user's branch
+                   ($basket->{authorisedby} &&  $viewbaskets == 'user' && $authorisedby eq $loggedinuser) #user created this basket
                    ) 
                 ) 
            ) { 
diff --git a/acqui/finishreceive.pl b/acqui/finishreceive.pl
index 71b13d6..9c9a808 100755
--- a/acqui/finishreceive.pl
+++ b/acqui/finishreceive.pl
@@ -26,10 +26,10 @@ use CGI;
 use C4::Auth;
 use C4::Output;
 use C4::Context;
+use C4::Dates;
 use C4::Acquisition;
 use C4::Biblio;
 use C4::Items;
-use C4::Search;
 use List::MoreUtils qw/any/;
 
 my $input=new CGI;
@@ -42,76 +42,77 @@ my $ordernumber=$input->param('ordernumber');
 my $origquantityrec=$input->param('origquantityrec');
 my $quantityrec=$input->param('quantityrec');
 my $quantity=$input->param('quantity');
-my $unitprice=$input->param('cost');
 my $invoiceno=$input->param('invoice');
-my $datereceived=$input->param('datereceived');
-my $replacement=$input->param('rrp');
+my $datereceived=$input->param('datereceived') || C4::Dates->output('iso');
 my $gst=$input->param('gst');
 my $freight=$input->param('freight');
 my $supplierid = $input->param('supplierid');
 my $cnt=0;
-my $error_url_str;
-my $ecost = $input->param('ecost');
-my $note = $input->param("note");
+my $error_url_str = '';
 
-my %tplorder = ( 'quantity'                  =>     $input->param('quantity') || '',
-                             'quantityreceived'   =>     $input->param('quantityrec') || '',
-                             'notes'                      =>      $input->param("note") || '',
-                             'rrp'                          =>      $input->param('rrp') || '',
-                             'ecost'                      =>      $input->param('ecost') || '',
-                             'unitprice'                =>      $input->param('cost') || '',
-                     );
 my $order = GetOrder($ordernumber);
-if ( any { $order->{$_} ne $tplorder{$_} } qw(quantity quantityreceived notes rrp ecost unitprice) ) {
-    $order->{quantity} = $tplorder{quantity} if $tplorder{quantity};
-    $order->{quantityreceived} = $tplorder{quantityreceived} if $tplorder{quantityreceived};
-    $order->{notes} = $tplorder{notes} if $tplorder{notes};
-    $order->{rrp} = $tplorder{rrp} if $tplorder{rrp};
-    $order->{ecost} = $tplorder{ecost} if $tplorder{ecost};
-    $order->{unitprice} = $tplorder{unitprice} if $tplorder{unitprice};
-    ModOrder($order);
-}
+$order->{booksellerinvoicenumber} = $invoiceno;
+$order->{datereceived} = $datereceived;
+$order->{freight} = $freight;
+$order->{quantity} = $quantity;
+$order->{quantityreceived} = $quantityrec;
+$order->{notes} = $input->param("note");
+$order->{rrp} = $input->param('rrp');
+$order->{ecost} = $input->param('ecost');
+$order->{unitprice} = $input->param('cost');
+ModOrder($order);
 
 #need old recievedate if we update the order, parcel.pl only shows the right parcel this way FIXME
-if ($quantityrec > $origquantityrec ) {
-    # now, add items if applicable
-    if (C4::Context->preference('AcqCreateItem') eq 'receiving') {
-        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,$biblionumber);
-        }
+
+# now, add or update items if applicable
+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];
+}
+my $error;
+my %itemnumbers = map { $_ => 1 } GetItemnumbersFromOrder($ordernumber);
+my @received;
+foreach my $id (keys %itemhash){
+    my $xml = TransformHtmlToXml( $itemhash{$id}->{'tags'},
+                                  $itemhash{$id}->{'subfields'},
+                                  $itemhash{$id}->{'field_values'},
+                                  $itemhash{$id}->{'ind_tag'},
+                                  $itemhash{$id}->{'indicator'},'ITEM');
+    my $record=MARC::Record::new_from_xml($xml, 'UTF-8');
+    my $item = AddItemFromMarc($record,$biblionumber);
+    my $itemnumber = $item ? $item->{itemnumber} : undef;
+    if ($itemnumber) {
+        push @received, $itemnumber;
+        NewOrderItem($itemnumber, $ordernumber) unless $itemnumbers{$itemnumber};
+    } else {
+        $error++;
     }
-    
+}
+
+if ($error) {
+    $error_url_str = "&error=Datbase+write+error";
+}
+elsif ($quantityrec != $origquantityrec ) {
     # save the quantity received.
-	if( $quantityrec > 0 ) {
-    	$datereceived = ModReceiveOrder($biblionumber,$ordernumber, $quantityrec ,$user,$unitprice,$invoiceno,$freight,$replacement,undef,$datereceived);
-	}
+    ModReceiveOrder($biblionumber,$ordernumber, $quantityrec, \@received);
 }
-    print $input->redirect("/cgi-bin/koha/acqui/parcel.pl?invoice=$invoiceno&supplierid=$supplierid&freight=$freight&gst=$gst&datereceived=$datereceived$error_url_str");
+
+print $input->redirect("/cgi-bin/koha/acqui/parcel.pl?invoice=$invoiceno&supplierid=$supplierid&freight=$freight&gst=$gst&datereceived=$datereceived$error_url_str");
diff --git a/acqui/orderreceive.pl b/acqui/orderreceive.pl
index 98ba544..26ca81f 100755
--- a/acqui/orderreceive.pl
+++ b/acqui/orderreceive.pl
@@ -85,21 +85,13 @@ my $search       = $input->param('receive');
 my $invoice      = $input->param('invoice');
 my $freight      = $input->param('freight');
 my $datereceived = $input->param('datereceived');
-
-
 $datereceived = $datereceived ? C4::Dates->new($datereceived, 'iso') : C4::Dates->new();
 
 my $bookseller = GetBookSellerFromId($supplierid);
 my $input_gst = ($input->param('gst') eq '' ? undef : $input->param('gst'));
 my $gst= $input_gst // $bookseller->{gstrate} // C4::Context->preference("gist") // 0;
 my $results = SearchOrder($ordernumber,$search);
-
-
 my $count   = scalar @$results;
-my $order 	= GetOrder($ordernumber);
-
-
-my $date = @$results[0]->{'entrydate'};
 
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     {
@@ -114,47 +106,50 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
 
 # prepare the form for receiving
 if ( $count == 1 ) {
-    if (C4::Context->preference('AcqCreateItem') eq 'receiving') {
+    my $order 	= GetOrder($results->[0]->{ordernumber});
+    my $biblionumber = $order->{biblionumber};
+
+    my @itemloop;
+    if ( my @itemnumbers = GetItemnumbersFromOrder($ordernumber) ) {
+        @itemloop = map PrepareItemrecordDisplay($biblionumber,$_), @itemnumbers;
+    }
+    elsif (C4::Context->preference('AcqCreateItem') eq 'receiving') {
         # prepare empty item form
         my $cell = PrepareItemrecordDisplay('','','','ACQ');
         unless ($cell) {
             $cell = PrepareItemrecordDisplay('','','','');
             $template->param('NoACQframework' => 1);
         }
-        my @itemloop;
         push @itemloop,$cell;
-        
-        $template->param(items => \@itemloop);
     }
+        
+    $template->param(items => \@itemloop) if @itemloop;
 
-    if ( @$results[0]->{'quantityreceived'} == 0 ) {
-        @$results[0]->{'quantityreceived'} = '';
-    }
-    if ( @$results[0]->{'unitprice'} == 0 ) {
-        @$results[0]->{'unitprice'} = '';
+    if ( $order->{'unitprice'} == 0 ) {
+        $order->{'unitprice'} = '';
     }
     $template->param(
         count                 => 1,
-        biblionumber          => @$results[0]->{'biblionumber'},
-        ordernumber           => @$results[0]->{'ordernumber'},
-        biblioitemnumber      => @$results[0]->{'biblioitemnumber'},
-        supplierid            => @$results[0]->{'booksellerid'},
+        biblionumber          => $biblionumber,
+        ordernumber           => $order->{'ordernumber'},
+        biblioitemnumber      => $order->{'biblioitemnumber'},
+        supplierid            => $supplierid,
         freight               => $freight,
         gst                   => $gst,
         name                  => $bookseller->{'name'},
-        date                  => format_date($date),
-        title                 => @$results[0]->{'title'},
-        author                => @$results[0]->{'author'},
-        copyrightdate         => @$results[0]->{'copyrightdate'},
-        isbn                  => @$results[0]->{'isbn'},
-        seriestitle           => @$results[0]->{'seriestitle'},
-        bookfund              => @$results[0]->{'bookfundid'},
-        quantity              => @$results[0]->{'quantity'},
-        quantityreceivedplus1 => @$results[0]->{'quantityreceived'} + 1,
-        quantityreceived      => @$results[0]->{'quantityreceived'},
-        rrp                   => @$results[0]->{'rrp'},
-        ecost                 => @$results[0]->{'ecost'},
-        unitprice             => @$results[0]->{'unitprice'},
+        date                  => format_date($order->{'entrydate'}),
+        title                 => $order->{'title'},
+        author                => $order->{'author'},
+        copyrightdate         => $order->{'copyrightdate'},
+        isbn                  => $order->{'isbn'},
+        seriestitle           => $order->{'seriestitle'},
+        bookfund              => $order->{'bookfundid'},
+        quantity              => $order->{'quantity'},
+        quantityreceived      => scalar(@itemloop) || 1,
+        origquantityrec       => $order->{'quantityreceived'},
+        rrp                   => $order->{'rrp'},
+        ecost                 => $order->{'ecost'},
+        unitprice             => $order->{'unitprice'},
         invoice               => $invoice,
         datereceived          => $datereceived->output(),
         datereceived_iso          => $datereceived->output('iso'),
diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl
index 4442ed3..bbf2c74 100755
--- a/cataloguing/additem.pl
+++ b/cataloguing/additem.pl
@@ -347,8 +347,8 @@ if ($op eq "additem") {
 	push @errors,"barcode_not_unique" if($exist_itemnumber);
 	# if barcode exists, don't create, but report The problem.
     unless ($exist_itemnumber) {
-	    my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = AddItemFromMarc($record,$biblionumber);
-        set_item_default_location($oldbibitemnum);
+	    my $item = AddItemFromMarc($record,$biblionumber);
+        set_item_default_location($item->{biblioitemnumber});
     }
 	$nextop = "additem";
 	if ($exist_itemnumber) {
@@ -414,8 +414,8 @@ if ($op eq "additem") {
 
 		# Adding the item
         if (!$exist_itemnumber) {
-            my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = AddItemFromMarc($record,$biblionumber);
-            set_item_default_location($oldbibitemnum);
+	        my $item = AddItemFromMarc($record,$biblionumber);
+            set_item_default_location($item->{biblioitemnumber});
 
             # We count the item only if it was really added
             # That way, all items are added, even if there was some already existing barcodes
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt
index 7147b19..fff26bd 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt
@@ -42,15 +42,15 @@
             <p class="required">No ACQ framework, using default. You should create a framework with code ACQ, the items framework would be used</p>
         [% END %]
 
+        [% itemid = 1 %]
         [% FOREACH item IN items %]
-        <div id="outeritemblock">
-        <div id="itemblock">
+        <div id="itemblock[% itemid %]">
             <ol>[% FOREACH iteminformatio IN item.iteminformation %]<li style="[% iteminformatio.hidden %];">
                 <div class="subfield_line" id="subfield[% iteminformatio.serialid %][% iteminformatio.countitems %][% iteminformatio.subfield %][% iteminformatio.random %]">
                                 
                     <label>[% iteminformatio.subfield %] - [% IF ( iteminformatio.mandatory ) %]<b>[% END %][% iteminformatio.marc_lib %][% IF ( iteminformatio.mandatory ) %] *</b>[% END %]</label>
                     [% iteminformatio.marc_value %]
-                    <input type="hidden" name="itemid" value="1" />
+                    <input type="hidden" name="itemid" value="[% itemid %]" />
                     <input type="hidden" name="kohafield" value="[% iteminformatio.kohafield %]" />
                     <input type="hidden" name="tag" value="[% iteminformatio.tag %]" />
                     <input type="hidden" name="subfield" value="[% iteminformatio.subfield %]" />
@@ -62,18 +62,18 @@
                 </div></li>
             [% END %]
             </ol>
-            <a style="cursor: pointer; color: grey; font-size: 180%;" onclick="cloneItemBlock('itemblock[% item.itemBlockIndex %]')">+</a>
-            <a style="display:none; cursor: pointer; color: grey; font-size: 180%;" onclick="deleteItemBlock('itemblock[% item.itemBlockIndex %]')">-</a>
+            <a style="cursor: pointer; color: grey; font-size: 180%;" onclick="cloneItemBlock('itemblock[% itemid %]')">+</a> 
+            <a style="cursor: pointer; color: grey; font-size: 180%;" onclick="deleteItemBlock('itemblock[% itemid %]')">-</a>
+
+            <input type="hidden" name="moditem" value="" /> 
+            <input type="hidden" name="tag" value="[% item.itemtagfield %]" />
+            <input type="hidden" name="subfield" value="[% item.itemtagsubfield %]" />
+            <input type="hidden" name="serial" value="[% item.serialid %]" />
+            <input type="hidden" name="bibnum" value="[% item.biblionumber %]" />
+            <input type="hidden" name="itemid" value="[% itemid %]" />
+            <input type="hidden" name="field_value" value="[% item.itemnumber %]" />
         </div><!-- /iteminformation -->
-        </div>
-        
-        <input type="hidden" name="moditem" value="" /> 
-        <input type="hidden" name="tag" value="[% item.itemtagfield %]" />
-        <input type="hidden" name="subfield" value="[% item.itemtagsubfield %]" />
-        <input type="hidden" name="serial" value="[% item.serialid %]" />
-        <input type="hidden" name="bibnum" value="[% item.biblionumber %]" />
-        <input type="hidden" name="itemid" value="1" />
-        <input type="hidden" name="field_value" value="[% item.itemnumber %]" />
+        [% itemid = itemid + 1 %]
         [% END %] <!-- /items -->
     </fieldset>
     [% END %] <!-- items -->
@@ -101,14 +101,12 @@
             [% IF ( quantityreceived ) %]
                 [% IF ( edit ) %]
                     <input type="text" size="20" name="quantityrec" id="quantity" value="[% quantityreceived %]" />
-                    <input id="origquantityrec" READONLY type="hidden" name="origquantityrec" value="[% quantityreceived %]" />
                 [% ELSE %]
                 [% IF ( items ) %]
-                    <input READONLY type="text" size="20" name="quantityrec" id="quantity" value="[% quantityreceivedplus1 %]" />
+                    <input READONLY type="text" size="20" name="quantityrec" id="quantity" value="[% quantityreceived %]" />
                 [% ELSE %]
-                    <input type="text" size="20" name="quantityrec" id="quantity" value="[% quantityreceivedplus1 %]" />
+                    <input type="text" size="20" name="quantityrec" id="quantity" value="[% quantityreceived %]" />
                 [% END %]
-                <input id="origquantityrec" READONLY type="hidden" name="origquantityrec" value="[% quantityreceived %]" />
                 [% END %]
             [% ELSE %]
                 [% IF ( items ) %]
@@ -116,8 +114,8 @@
                 [% ELSE %]
                     <input type="text" size="20" id="quantity" name="quantityrec" value="1" />
                 [% END %]
-                <input id="origquantityrec" READONLY type="hidden" name="origquantityrec" value="0" />
             [% END %]
+            <input id="origquantityrec" type="hidden" name="origquantityrec" value="[% origquantityrec %]" />
 		</li>
         <li><label for="rrp">Replacement cost: </label><input type="text" size="20" name="rrp" id="rrp" value="[% rrp %]" /></li>
         <li><label for="ecost">Budgeted cost: </label><input type="text" size="20" name="ecost" id="ecost" value="[% ecost %]" /></li>
diff --git a/t/db_dependent/lib/KohaTest.pm b/t/db_dependent/lib/KohaTest.pm
index 70c963d..77e91d1 100644
--- a/t/db_dependent/lib/KohaTest.pm
+++ b/t/db_dependent/lib/KohaTest.pm
@@ -572,16 +572,12 @@ sub add_biblios {
         ok( $biblionumber, "the biblionumber is $biblionumber" );
         ok( $biblioitemnumber, "the biblioitemnumber is $biblioitemnumber" );
         if ( $param{'add_items'} ) {
-            # my @iteminfo = AddItem( {}, $biblionumber );
-            my @iteminfo = AddItemFromMarc( $marcrecord, $biblionumber );
-            is( $iteminfo[0], $biblionumber,     "biblionumber is $biblionumber" );
-            is( $iteminfo[1], $biblioitemnumber, "biblioitemnumber is $biblioitemnumber" );
-            ok( $iteminfo[2], "itemnumber is $iteminfo[2]" );
-        push @{ $self->{'items'} },
-          { biblionumber     => $iteminfo[0],
-            biblioitemnumber => $iteminfo[1],
-            itemnumber       => $iteminfo[2],
-          };
+            # my $item = AddItem( {}, $biblionumber );
+            my $item = AddItemFromMarc( $marcrecord, $biblionumber );
+            is( $item->{biblionumber},     "biblionumber is $biblionumber" );
+            is( $item->{biblioitemnumber}, "biblioitemnumber is $biblioitemnumber" );
+            ok( $item->{itemnumber}, "itemnumber is $item->{itemnumber}" );
+            push @{ $self->{'items'} }, $item;
         }
         push @{$self->{'biblios'}}, $biblionumber;
     }
diff --git a/t/db_dependent/lib/KohaTest/Acquisition/GetParcel.pm b/t/db_dependent/lib/KohaTest/Acquisition/GetParcel.pm
index c26e5f2..b42ea9c 100644
--- a/t/db_dependent/lib/KohaTest/Acquisition/GetParcel.pm
+++ b/t/db_dependent/lib/KohaTest/Acquisition/GetParcel.pm
@@ -43,18 +43,11 @@ sub one_parcel : Test( 17 ) {
     
     ok( $basketno, "my basket number is $basketno" );
     ok( $ordernumber,   "my order number is $ordernumber" );
-    my $datereceived = ModReceiveOrder( $self->{'biblios'}[0],             # biblionumber
-                                        $ordernumber,       # $ordernumber,
-                                        undef,         # $quantrec,
-                                        undef,         # $user,
-                                        undef,         # $cost,
-                                        $invoice,         # $invoiceno,
-                                        undef,         # $freight,
-                                        undef,         # $rrp,
-                                        $self->{'bookfundid'},         # $bookfund,
-                                        $today,         # $datereceived
-                                   );
-    is( $datereceived, $today, "the parcel was received on $datereceived" );
+    ModReceiveOrder( $self->{'biblios'}[0],             # biblionumber
+                     $ordernumber,       # $ordernumber,
+                     1,         # $quantrec,
+                   );
+    pass( "the parcel was received" );
 
     my @parcel = GetParcel( $self->{'booksellerid'}, $invoice, $today );
     is( scalar @parcel, 1, 'we found one (1) parcel.' )
diff --git a/t/db_dependent/lib/KohaTest/Acquisition/GetParcels.pm b/t/db_dependent/lib/KohaTest/Acquisition/GetParcels.pm
index fd3ad0f..b14095f 100644
--- a/t/db_dependent/lib/KohaTest/Acquisition/GetParcels.pm
+++ b/t/db_dependent/lib/KohaTest/Acquisition/GetParcels.pm
@@ -271,18 +271,12 @@ sub create_order {
 
     my ( $basketno, $ordernumber ) = $self->create_new_basket( %param );
 
-    my $datereceived = ModReceiveOrder( $self->{'biblios'}[0],             # biblionumber
-                                        $ordernumber,       # $ordernumber,
-                                        undef,         # $quantrec,
-                                        undef,         # $user,
-                                        undef,         # $cost,
-                                        $param{'invoice'},         # $invoiceno,
-                                        undef,         # $freight,
-                                        undef,         # $rrp,
-                                        $self->{'bookfundid'},         # $bookfund,
-                                        $param{'date'},         # $datereceived
-                                   );
-    is( $datereceived, $param{'date'}, "the parcel was received on $datereceived" );
+    ModReceiveOrder( $self->{'biblios'}[0],             # biblionumber
+                     $ordernumber,       # $ordernumber,
+                     1,         # $quantrec,
+                   );
+    # XXX Needs proper tests for partial receiving
+    pass( "the parcel was received" );
 
 }
 
diff --git a/t/db_dependent/lib/KohaTest/Biblio/ModBiblio.pm b/t/db_dependent/lib/KohaTest/Biblio/ModBiblio.pm
index 5b29ea8..8a83268 100644
--- a/t/db_dependent/lib/KohaTest/Biblio/ModBiblio.pm
+++ b/t/db_dependent/lib/KohaTest/Biblio/ModBiblio.pm
@@ -31,10 +31,10 @@ sub add_bib_to_modify : Test( startup => 3 ) {
     $self->{'bib_to_modify'} = $bibnum;
 
     # add an item
-    my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL' } , $bibnum);
+    my $item = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL' } , $bibnum);
 
-    cmp_ok($item_bibnum, '==', $bibnum, "new item is linked to correct biblionumber"); 
-    cmp_ok($item_bibitemnum, '==', $bibitemnum, "new item is linked to correct biblioitemnumber"); 
+    cmp_ok($item->{biblionumber}, '==', $bibnum, "new item is linked to correct biblionumber"); 
+    cmp_ok($item->{biblioitemnumber}, '==', $bibitemnum, "new item is linked to correct biblioitemnumber"); 
 
     $self->reindex_marc(); 
 
-- 
1.6.5




More information about the Patches mailing list