Bug 18256: Koha::Items - Remove GetItemsCount
[koha.git] / C4 / Acquisition.pm
index 3b255b4..3fca9eb 100644 (file)
@@ -29,7 +29,8 @@ use C4::Debug;
 use C4::Templates qw(gettemplate);
 use Koha::DateUtils qw( dt_from_string output_pref );
 use Koha::Acquisition::Order;
-use Koha::Acquisition::Bookseller;
+use Koha::Acquisition::Booksellers;
+use Koha::Biblios;
 use Koha::Number::Price;
 use Koha::Libraries;
 
@@ -351,13 +352,13 @@ sub GetBasketGroupAsCSV {
         my $contract   = GetContract({
             contractnumber => $basket->{contractnumber}
         });
-        my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $basket->{booksellerid} });
+        my $bookseller = Koha::Acquisition::Booksellers->find( $basket->{booksellerid} );
         my $basketgroup = GetBasketgroup( $$basket{basketgroupid} );
 
         foreach my $order (@orders) {
             my $bd = GetBiblioData( $order->{'biblionumber'} );
             my $row = {
-                clientnumber => $bookseller->{accountnumber},
+                clientnumber => $bookseller->accountnumber,
                 basketname => $basket->{basketname},
                 ordernumber => $order->{ordernumber},
                 author => $bd->{author},
@@ -369,14 +370,14 @@ sub GetBasketGroupAsCSV {
                 quantity => $order->{quantity},
                 rrp_tax_included => $order->{rrp_tax_included},
                 rrp_tax_excluded => $order->{rrp_tax_excluded},
-                discount => $bookseller->{discount},
+                discount => $bookseller->discount,
                 ecost_tax_included => $order->{ecost_tax_included},
                 ecost_tax_excluded => $order->{ecost_tax_excluded},
                 notes => $order->{order_vendornote},
                 entrydate => $order->{entrydate},
-                booksellername => $bookseller->{name},
-                bookselleraddress => $bookseller->{address1},
-                booksellerpostal => $bookseller->{postal},
+                booksellername => $bookseller->name,
+                bookselleraddress => $bookseller->address1,
+                booksellerpostal => $bookseller->postal,
                 contractnumber => $contract->{contractnumber},
                 contractname => $contract->{contractname},
             };
@@ -1419,6 +1420,10 @@ sub ModReceiveOrder {
         $order->{budget_id} = ( $budget_id || $order->{budget_id} );
         $order->{quantity} = $quantrec;
         $order->{quantityreceived} = $quantrec;
+        $order->{ecost_tax_excluded} //= 0;
+        $order->{tax_rate_on_ordering} //= 0;
+        $order->{unitprice_tax_excluded} //= 0;
+        $order->{tax_rate_on_receiving} //= 0;
         $order->{tax_value_on_ordering} = $order->{quantity} * $order->{ecost_tax_excluded} * $order->{tax_rate_on_ordering};
         $order->{tax_value_on_receiving} = $order->{quantity} * $order->{unitprice_tax_excluded} * $order->{tax_rate_on_receiving};
         $order->{datereceived} = $datereceived;
@@ -1847,7 +1852,8 @@ sub DelOrder {
 
     if($delete_biblio) {
         # We get the number of remaining items
-        my $itemcount = C4::Items::GetItemsCount($bibnum);
+        my $biblio = Koha::Biblios->find( $bibnum );
+        my $itemcount = $biblio->items->count;
 
         # If there are no items left,
         if ( $itemcount == 0 ) {
@@ -2864,7 +2870,7 @@ sub populate_order_with_prices {
     my $booksellerid = $params->{booksellerid};
     return unless $booksellerid;
 
-    my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
+    my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid );
 
     my $receiving = $params->{receiving};
     my $ordering  = $params->{ordering};
@@ -2873,7 +2879,7 @@ sub populate_order_with_prices {
 
     if ($ordering) {
         $order->{tax_rate_on_ordering} //= $order->{tax_rate};
-        if ( $bookseller->{listincgst} ) {
+        if ( $bookseller->listincgst ) {
             # The user entered the rrp tax included
             $order->{rrp_tax_included} = $order->{rrp};
 
@@ -2910,7 +2916,7 @@ sub populate_order_with_prices {
 
     if ($receiving) {
         $order->{tax_rate_on_receiving} //= $order->{tax_rate};
-        if ( $bookseller->{invoiceincgst} ) {
+        if ( $bookseller->invoiceincgst ) {
             # Trick for unitprice. If the unit price rounded value is the same as the ecost rounded value
             # we need to keep the exact ecost value
             if ( Koha::Number::Price->new( $order->{unitprice} )->round == Koha::Number::Price->new( $order->{ecost_tax_included} )->round ) {