Bug 12830: Move the order-related code into Koha::Acquisition::Order
[koha-ffzg.git] / acqui / addorderiso2709.pl
index ad028b6..15c83ea 100755 (executable)
@@ -45,9 +45,12 @@ use C4::Suggestions;    # GetSuggestion
 use C4::Branch;         # GetBranches
 use C4::Members;
 
+use Koha::Number::Price;
+use Koha::Acquisition::Order;
+
 my $input = new CGI;
 my ($template, $loggedinuser, $cookie, $userflags) = get_template_and_user({
-    template_name => "acqui/addorderiso2709.tmpl",
+    template_name => "acqui/addorderiso2709.tt",
     query => $input,
     type => "intranet",
     authnotrequired => 0,
@@ -141,7 +144,6 @@ if ($op eq ""){
 # 3rd step = import the records
 #
 } elsif ( $op eq 'import_records' ) {
-    my $num=FormatNumber();
 #import selected lines
     $template->param('basketno' => $cgiparams->{'basketno'});
 # Budget_id is mandatory for adding an order, we just add a default, the user needs to modify this aftewards
@@ -227,7 +229,7 @@ if ($op eq ""){
             # in France, the cents separator is the , but sometimes, ppl use a .
             # in this case, the price will be x100 when unformatted ! Replace the . by a , to get a proper price calculation
             $price =~ s/\./,/ if C4::Context->preference("CurrencyFormat") eq "FR";
-            $price = $num->unformat_number($price);
+            $price = Koha::Number::Price->new($price)->unformat;
             $orderinfo{gstrate} = $bookseller->{gstrate};
             my $c = $c_discount ? $c_discount : $bookseller->{discount} / 100;
             if ( $bookseller->{listincgst} ) {
@@ -256,7 +258,7 @@ if ($op eq ""){
 
         # remove uncertainprice flag if we have found a price in the MARC record
         $orderinfo{uncertainprice} = 0 if $orderinfo{listprice};
-        my ( $basketno, $ordernumber ) = NewOrder( \%orderinfo );
+        my $order = Koha::Acquisition::Order->new( \%orderinfo )->insert;
 
         # 4th, add items if applicable
         # parse the item sent by the form, and create an item just for the import_record_id we are dealing with
@@ -278,7 +280,7 @@ if ($op eq ""){
             my $record = MARC::Record::new_from_xml( $xml, 'UTF-8' );
             for (my $qtyloop=1;$qtyloop <= $c_quantity;$qtyloop++) {
                 my ( $biblionumber, $bibitemnum, $itemnumber ) = AddItemFromMarc( $record, $biblionumber );
-                NewOrderItem( $itemnumber, $ordernumber );
+                $order->add_item( $itemnumber );
             }
         } else {
             SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' );
@@ -334,7 +336,7 @@ sub import_batches_list {
             if (scalar @$stagedList) {
                 push @list, {
                         import_batch_id => $batch->{'import_batch_id'},
-                        num_biblios => $batch->{'num_records'},
+                        num_records => $batch->{'num_records'},
                         num_items => $batch->{'num_items'},
                         staged_date => $batch->{'upload_timestamp'},
                         import_status => $batch->{'import_status'},
@@ -404,12 +406,12 @@ sub import_biblios_list {
 
         push @list, \%cellrecord;
     }
-    my $num_biblios = $batch->{'num_records'};
+    my $num_records = $batch->{'num_records'};
     my $overlay_action = GetImportBatchOverlayAction($import_batch_id);
     my $nomatch_action = GetImportBatchNoMatchAction($import_batch_id);
     my $item_action = GetImportBatchItemAction($import_batch_id);
     $template->param(biblio_list => \@list,
-                        num_results => $num_biblios,
+                        num_results => $num_records,
                         import_batch_id => $import_batch_id,
                         "overlay_action_${overlay_action}" => 1,
                         overlay_action => $overlay_action,
@@ -428,7 +430,7 @@ sub batch_info {
                                           comments => $batch->{'comments'},
                                           import_status => $batch->{'import_status'},
                                           upload_timestamp => $batch->{'upload_timestamp'},
-                                          num_biblios => $batch->{'num_records'},
+                                          num_records => $batch->{'num_records'},
                                           num_items => $batch->{'num_items'});
     if ($batch->{'num_records'} > 0) {
         if ($batch->{'import_status'} eq 'staged' or $batch->{'import_status'} eq 'reverted') {