Bug 12674: GetMarcISSN should not return empty ISSN
[srvgit] / C4 / Acquisition.pm
index 7904cbe..5fc45c7 100644 (file)
@@ -18,8 +18,7 @@ package C4::Acquisition;
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 
-use strict;
-use warnings;
+use Modern::Perl;
 use Carp;
 use C4::Context;
 use C4::Debug;
@@ -27,8 +26,8 @@ use C4::Dates qw(format_date format_date_in_iso);
 use MARC::Record;
 use C4::Suggestions;
 use C4::Biblio;
+use C4::Contract;
 use C4::Debug;
-use C4::SQLHelper qw(InsertInTable UpdateInTable);
 use C4::Bookseller qw(GetBookSellerFromId);
 use C4::Templates qw(gettemplate);
 
@@ -65,7 +64,6 @@ BEGIN {
         &NewOrderItem &ModItemOrder
 
         &GetParcels &GetParcel
-        &GetContracts &GetContract
 
         &GetInvoices
         &GetInvoice
@@ -293,7 +291,9 @@ sub GetBasketAsCSV {
     my ($basketno, $cgi) = @_;
     my $basket = GetBasket($basketno);
     my @orders = GetOrders($basketno);
-    my $contract = GetContract($basket->{'contractnumber'});
+    my $contract = GetContract({
+        contractnumber => $basket->{'contractnumber'}
+    });
 
     my $template = C4::Templates::gettemplate("acqui/csv/basket.tt", "intranet", $cgi);
 
@@ -360,8 +360,10 @@ sub GetBasketGroupAsCSV {
 
     my @rows;
     for my $basket (@$baskets) {
-        my @orders     = GetOrders( $$basket{basketno} );
-        my $contract   = GetContract( $$basket{contractnumber} );
+        my @orders     = GetOrders( $basket->{basketno} );
+        my $contract   = GetContract({
+            contractnumber => $basket->{contractnumber}
+        });
         my $bookseller = GetBookSellerFromId( $$basket{booksellerid} );
         my $basketgroup = GetBasketgroup( $$basket{basketgroupid} );
 
@@ -1270,18 +1272,19 @@ sub NewOrder {
         croak "Mandatory parameter $key missing" unless $orderinfo->{$key};
     }
 
-    if ( defined $orderinfo->{subscription} && $orderinfo->{'subscription'} eq 'yes' ) {
-        $orderinfo->{'subscription'} = 1;
-    } else {
-        $orderinfo->{'subscription'} = 0;
-    }
     $orderinfo->{'entrydate'} ||= C4::Dates->new()->output("iso");
     if (!$orderinfo->{quantityreceived}) {
         $orderinfo->{quantityreceived} = 0;
     }
 
-    my $ordernumber=InsertInTable("aqorders",$orderinfo);
-    if (not $orderinfo->{parent_ordernumber}) {
+    # get only the columns of Aqorder
+    my $schema = Koha::Database->new()->schema;
+    my $columns = ' '.join(' ', $schema->source('Aqorder')->columns).' ';
+    my $new_order = { map { $columns =~ / $_ / ? ($_ => $orderinfo->{$_}) : () } keys(%$orderinfo) };
+
+    my $rs = $schema->resultset('Aqorder');
+    my $ordernumber = $rs->create($new_order)->id;
+    if (not $new_order->{parent_ordernumber}) {
         my $sth = $dbh->prepare("
             UPDATE aqorders
             SET parent_ordernumber = ordernumber
@@ -1289,7 +1292,7 @@ sub NewOrder {
         ");
         $sth->execute($ordernumber);
     }
-    return ( $orderinfo->{'basketno'}, $ordernumber );
+    return ( $new_order->{'basketno'}, $ordernumber );
 }
 
 
@@ -1861,7 +1864,12 @@ sub DelOrder {
     $sth->execute( $bibnum, $ordernumber );
     my @itemnumbers = GetItemnumbersFromOrder( $ordernumber );
     foreach my $itemnumber (@itemnumbers){
-        C4::Items::DelItem( $dbh, $bibnum, $itemnumber );
+        C4::Items::DelItem(
+            {
+                biblionumber => $bibnum,
+                itemnumber   => $itemnumber
+            }
+        );
     }
     return;
 }
@@ -2466,72 +2474,8 @@ sub GetRecentAcqui {
     return $results;
 }
 
-=head3 GetContracts
-
-  $contractlist = &GetContracts($booksellerid, $activeonly);
-
-Looks up the contracts that belong to a bookseller
-
-Returns a list of contracts
-
-=over
-
-=item C<$booksellerid> is the "id" field in the "aqbooksellers" table.
-
-=item C<$activeonly> if exists get only contracts that are still active.
-
-=back
-
-=cut
-
-sub GetContracts {
-    my ( $booksellerid, $activeonly ) = @_;
-    my $dbh = C4::Context->dbh;
-    my $query;
-    if (! $activeonly) {
-        $query = "
-            SELECT *
-            FROM   aqcontract
-            WHERE  booksellerid=?
-        ";
-    } else {
-        $query = "SELECT *
-            FROM aqcontract
-            WHERE booksellerid=?
-                AND contractenddate >= CURDATE( )";
-    }
-    my $result_set =
-      $dbh->selectall_arrayref( $query, { Slice => {} }, $booksellerid );
-    return @{$result_set};
-}
-
 #------------------------------------------------------------#
 
-=head3 GetContract
-
-  $contract = &GetContract($contractID);
-
-Looks up the contract that has PRIMKEY (contractnumber) value $contractID
-
-Returns a contract
-
-=cut
-
-sub GetContract {
-    my ( $contractno ) = @_;
-    my $dbh = C4::Context->dbh;
-    my $query = "
-        SELECT *
-        FROM   aqcontract
-        WHERE  contractnumber=?
-        ";
-
-    my $sth = $dbh->prepare($query);
-    $sth->execute( $contractno );
-    my $result = $sth->fetchrow_hashref;
-    return $result;
-}
-
 =head3 AddClaim
 
 =over