Bug 12495 - Include streetnumber in hold alert address
[koha_fer] / acqui / addorderiso2709.pl
index e966a4c..91c0a4c 100755 (executable)
@@ -160,7 +160,6 @@ if ($op eq ""){
     my @quantities = $input->param('quantity');
     my @prices = $input->param('price');
     my @budgets_id = $input->param('budget_id');
-    my @rrp = $input->param('rrp');
     my @discount = $input->param('discount');
     my @sort1 = $input->param('sort1');
     my @sort2 = $input->param('sort2');
@@ -174,9 +173,8 @@ if ($op eq ""){
         my $biblionumber=$#$match > -1?$match->[0]->{'biblionumber'}:0;
         my $c_quantity = shift( @quantities ) || GetMarcQuantity($marcrecord, C4::Context->preference('marcflavour') ) || 1;
         my $c_budget_id = shift( @budgets_id ) || $input->param('all_budget_id') || $budget_id;
-        my $c_rrp = shift( @rrp ); # rrp include tax
         my $c_discount = shift ( @discount);
-        $c_discount = $c_discount / 100 if $c_discount > 100;
+        $c_discount = $c_discount / 100 if $c_discount > 1;
         my $c_sort1 = shift( @sort1 ) || $input->param('all_sort1') || '';
         my $c_sort2 = shift( @sort2 ) || $input->param('all_sort2') || '';
 
@@ -197,6 +195,7 @@ if ($op eq ""){
                 }
             }
             ( $biblionumber, $bibitemnum ) = AddBiblio( $marcrecord, $cgiparams->{'frameworkcode'} || '' );
+            SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' );
             # 2nd add authorities if applicable
             if (C4::Context->preference("BiblioAddsAuthorities")){
                 my $headings_linked =BiblioAutoLink($marcrecord, $cgiparams->{'frameworkcode'});
@@ -230,7 +229,7 @@ if ($op eq ""){
             $price =~ s/\./,/ if C4::Context->preference("CurrencyFormat") eq "FR";
             $price = $num->unformat_number($price);
             $orderinfo{gstrate} = $bookseller->{gstrate};
-            my $c = $c_discount ? $c_discount / 100 : $bookseller->{discount} / 100;
+            my $c = $c_discount ? $c_discount : $bookseller->{discount} / 100;
             if ( $bookseller->{listincgst} ) {
                 if ( $c_discount ) {
                     $orderinfo{ecost} = $price;
@@ -281,6 +280,8 @@ if ($op eq ""){
                 my ( $biblionumber, $bibitemnum, $itemnumber ) = AddItemFromMarc( $record, $biblionumber );
                 NewOrderItem( $itemnumber, $ordernumber );
             }
+        } else {
+            SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' );
         }
     }
     # go to basket page
@@ -308,41 +309,15 @@ foreach my $r ( @{$budgets_hierarchy} ) {
         b_txt => $r->{budget_name},
         b_sort1_authcat => $r->{'sort1_authcat'},
         b_sort2_authcat => $r->{'sort2_authcat'},
+        b_active => $r->{budget_period_active},
         b_sel => ( $r->{budget_id} == $budget_id ) ? 1 : 0,
       };
 }
-$template->param( budget_loop    => $budget_loop,);
 
-my $CGIsort1;
-if ($budget) {    # its a mod ..
-    if ( defined $budget->{'sort1_authcat'} ) {    # with custom  Asort* planning values
-        $CGIsort1 = GetAuthvalueDropbox(  $budget->{'sort1_authcat'}, $data->{'sort1'} );
-    }
-} elsif ( scalar(@$budgets) ) {
-} elsif ( scalar(@$budgets_hierarchy) ) {
-    $CGIsort1 = GetAuthvalueDropbox( @$budgets_hierarchy[0]->{'sort1_authcat'}, '' );
-}
-# if CGIsort is successfully fetched, the use it
-# else - failback to plain input-field
-if ($CGIsort1) {
-    $template->param( CGIsort1 => $CGIsort1 );
-} else {
-    $template->param( sort1 => $data->{'sort1'} );
-}
+@{$budget_loop} =
+  sort { uc( $a->{b_txt}) cmp uc( $b->{b_txt}) } @{$budget_loop};
 
-my $CGIsort2;
-if ($budget) {
-    if ( defined $budget->{'sort2_authcat'} ) {
-        $CGIsort2 = GetAuthvalueDropbox(  $budget->{'sort2_authcat'}, $data->{'sort2'} );
-    }
-} elsif ( scalar(@$budgets_hierarchy) ) {
-    $CGIsort2 = GetAuthvalueDropbox( @$budgets_hierarchy[0]->{sort2_authcat}, '' );
-}
-if ($CGIsort2) {
-    $template->param( CGIsort2 => $CGIsort2 );
-} else {
-    $template->param( sort2 => $data->{'sort2'} );
-}
+$template->param( budget_loop    => $budget_loop,);
 
 output_html_with_http_headers $input, $cookie, $template->output;
 
@@ -355,11 +330,11 @@ sub import_batches_list {
     foreach my $batch (@$batches) {
         if ( $batch->{'import_status'} =~ /^staged$|^reverted$/ ) {
             # check if there is at least 1 line still staged
-            my $stagedList=GetImportRecordsRange($batch->{'import_batch_id'}, undef, undef, $batch->{import_status});
+            my $stagedList=GetImportRecordsRange($batch->{'import_batch_id'}, undef, undef, $batch->{import_status}, { order_by_direction => 'ASC' });
             if (scalar @$stagedList) {
                 push @list, {
                         import_batch_id => $batch->{'import_batch_id'},
-                        num_biblios => $batch->{'num_biblios'},
+                        num_records => $batch->{'num_records'},
                         num_items => $batch->{'num_items'},
                         staged_date => $batch->{'upload_timestamp'},
                         import_status => $batch->{'import_status'},
@@ -406,11 +381,10 @@ sub import_biblios_list {
         );
         my ( $marcblob, $encoding ) = GetImportRecordMarc( $biblio->{'import_record_id'} );
         my $marcrecord = MARC::Record->new_from_usmarc($marcblob) || die "couldn't translate marc information";
-        my $infos = get_infos_syspref($marcrecord, ['price', 'quantity', 'budget_code', 'rrp', 'discount', 'sort1', 'sort2']);
+        my $infos = get_infos_syspref($marcrecord, ['price', 'quantity', 'budget_code', 'discount', 'sort1', 'sort2']);
         my $price = $infos->{price};
         my $quantity = $infos->{quantity};
         my $budget_code = $infos->{budget_code};
-        my $rrp = $infos->{rrp};
         my $discount = $infos->{discount};
         my $sort1 = $infos->{sort1};
         my $sort2 = $infos->{sort2};
@@ -424,19 +398,18 @@ sub import_biblios_list {
         $cellrecord{price} = $price || '';
         $cellrecord{quantity} = $quantity || '';
         $cellrecord{budget_id} = $budget_id || '';
-        $cellrecord{rrp} = $rrp || '';
         $cellrecord{discount} = $discount || '';
         $cellrecord{sort1} = $sort1 || '';
         $cellrecord{sort2} = $sort2 || '';
 
         push @list, \%cellrecord;
     }
-    my $num_biblios = $batch->{'num_biblios'};
+    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,
@@ -455,9 +428,9 @@ sub batch_info {
                                           comments => $batch->{'comments'},
                                           import_status => $batch->{'import_status'},
                                           upload_timestamp => $batch->{'upload_timestamp'},
-                                          num_biblios => $batch->{'num_biblios'},
-                                          num_items => $batch->{'num_biblios'});
-    if ($batch->{'num_biblios'} > 0) {
+                                          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') {
             $template->param(can_commit => 1);
         }