Bug 6871 - add schema and sql library reports to guided reports sidebar
[koha.git] / acqui / basket.pl
index 8ea2929..70fb39c 100755 (executable)
@@ -90,6 +90,9 @@ if (!defined $op) {
     $op = q{};
 }
 
+my $confirm_pref= C4::Context->preference("BasketConfirmations") || '1';
+$template->param( skip_confirm_reopen => 1) if $confirm_pref eq '2';
+
 if ( $op eq 'delete_confirm' ) {
     my $basketno = $query->param('basketno');
     DelBasket($basketno);
@@ -133,7 +136,7 @@ if ( $op eq 'delete_confirm' ) {
         address3             => $bookseller->{'address3'},
         address4             => $bookseller->{'address4'},
       );
-} elsif ($op eq 'attachbasket' && $template->{'param_map'}->{'CAN_user_acquisition_group_manage'} == 1) {
+} elsif ($op eq 'attachbasket' && $template->{'VARS'}->{'CAN_user_acquisition_group_manage'} == 1) {
       print $query->redirect('/cgi-bin/koha/acqui/basketgroup.pl?basketno=' . $basket->{'basketno'} . '&op=attachbasket&booksellerid=' . $booksellerid);
     # check if we have to "close" a basket before building page
 } elsif ($op eq 'export') {
@@ -144,7 +147,7 @@ if ( $op eq 'delete_confirm' ) {
     print GetBasketAsCSV($query->param('basketno'));
     exit;
 } elsif ($op eq 'close') {
-    my $confirm = $query->param('confirm');
+    my $confirm = $query->param('confirm') || $confirm_pref eq '2';
     if ($confirm) {
         my $basketno = $query->param('basketno');
         my $booksellerid = $query->param('booksellerid');
@@ -194,10 +197,10 @@ if ( $op eq 'delete_confirm' ) {
 #if the basket is closed,and the user has the permission to edit basketgroups, display a list of basketgroups
     my $basketgroups;
     my $member = GetMember(borrowernumber => $loggedinuser);
-    if ($basket->{closedate} && haspermission({ flagsrequired   => { acquisition => 'group_manage'} })) {
+    if ($basket->{closedate} && haspermission({ acquisition => 'group_manage'} )) {
         $basketgroups = GetBasketgroups($basket->{booksellerid});
         for my $bg ( @{$basketgroups} ) {
-            if ($basket->{basketgroupid} == $bg->{id}){
+            if ($basket->{basketgroupid} && $basket->{basketgroupid} == $bg->{id}){
                 $bg->{default} = 1;
             }
         }
@@ -217,6 +220,10 @@ if ( $op eq 'delete_confirm' ) {
       "loggedinuser: $loggedinuser; creationdate: %s; authorisedby: %s",
       $basket->{creationdate}, $basket->{authorisedby};
 
+       #to get active currency
+       my $cur = GetCurrency();
+
+
     my @results = GetOrders( $basketno );
     
        my $gist = $bookseller->{gstrate} // C4::Context->preference("gist") // 0;
@@ -287,6 +294,18 @@ if ( $op eq 'delete_confirm' ) {
 
     my $contract = &GetContract($basket->{contractnumber});
     my @orders = GetOrders($basketno);
+
+    my $borrower= GetMember('borrowernumber' => $loggedinuser);
+    my $budgets = GetBudgetHierarchy(q{},$borrower->{branchcode},$borrower->{borrowernumber});
+    my $has_budgets = 0;
+    foreach my $r (@{$budgets}) {
+        if (!defined $r->{budget_amount} || $r->{budget_amount} == 0) {
+            next;
+        }
+        $has_budgets = 1;
+        last;
+    }
+
     $template->param(
         basketno             => $basketno,
         basketname           => $basket->{'basketname'},
@@ -310,12 +329,14 @@ if ( $op eq 'delete_confirm' ) {
         gist_rrp             => sprintf( "%.2f", $gist_rrp ),        
         total_rrp_gsti       => sprintf( "%.2f", $total_rrp_gsti ),
         total_est_gsti       => sprintf( "%.2f", $total_est_gsti ),
-        currency             => $bookseller->{'listprice'},
+#        currency             => $bookseller->{'listprice'},
+       currency                => $cur->{'currency'},
         qty_total            => $qty_total,
         GST                  => $gist,
         basketgroups         => $basketgroups,
         grouped              => $basket->{basketgroupid},
         unclosable           => @orders ? 0 : 1, 
+        has_budgets          => $has_budgets,
     );
 }