Merge commit 'biblibre/3.2_biblibre' into to-push
[koha_fer] / acqui / basketgroup.pl
index 17d8948..e8273a9 100755 (executable)
@@ -182,7 +182,7 @@ sub displaybasketgroups {
 sub printbasketgrouppdf{
     my ($basketgroupid) = @_;
     
-    my $pdfformat = C4::Context->preference("pdfformat");
+    my $pdfformat = C4::Context->preference("OrderPdfFormat");
     eval "use $pdfformat" ;
     warn @_;
     eval "use C4::Branch";
@@ -239,10 +239,8 @@ sub printbasketgrouppdf{
         }
         %orders->{$basket->{basketno}}=\@ba_orders;
     }
-    print $input->header( -type => 'application/pdf', -attachment => 'basketgroup.pdf' );
-    my $branch = GetBranchInfo(GetBranch($input, GetBranches()));
-    $branch = @$branch[0];
-    my $pdf = printpdf($basketgroup, $bookseller, $baskets, $branch, \%orders, $bookseller->{gstrate} || C4::Context->preference("gist")) || die "pdf generation failed";
+    print $input->header( -type => 'application/pdf', -attachment => $basketgroup->{name}.'.pdf' );
+    my $pdf = printpdf($basketgroup, $bookseller, $baskets, \%orders, $bookseller->{gstrate} || C4::Context->preference("gist")) || die "pdf generation failed";
     print $pdf;
     exit;
 }
@@ -270,7 +268,8 @@ if ( $op eq "add" ) {
         }
     } else {
         my $basketgroupid = $input->param('basketgroupid');
-        my $branchcode;
+        my $billingplace;
+        my $deliveryplace;
         if ( $basketgroupid ) {
             # Get the selected baskets in the basketgroup to display them
             my $selecteds = GetBasketsByBasketgroup($basketgroupid);
@@ -286,24 +285,42 @@ if ( $op eq "add" ) {
                 name            => $basketgroup->{name},
                 deliverycomment => $basketgroup->{deliverycomment},
             );
-            $branchcode = $basketgroup->{deliveryplace};
+            $billingplace  = $basketgroup->{billingplace};
+            $deliveryplace = $basketgroup->{deliveryplace};
         }
 
-        # Build the combobox to select the delivery place
+        # determine default billing and delivery places depending on librarian homebranch and existing basketgroup data
         my $borrower = GetMember( ( 'borrowernumber' => $loggedinuser ) );
-        my $branch   = $branchcode || $borrower->{'branchcode'};
+        $billingplace  = $billingplace  || $borrower->{'branchcode'};
+        $deliveryplace = $deliveryplace || $borrower->{'branchcode'};
+        
         my $branches = GetBranches;
-        my @branchloop;
-        foreach my $thisbranch (sort keys %$branches) {
-            my $selected = 1 if $thisbranch eq $branch;
+        
+        # Build the combobox to select the billing place
+        my @billingplaceloop;
+        for (sort keys %$branches) {
+            my $selected = 1 if $_ eq $billingplace;
+            my %row = (
+                value      => $_,
+                selected   => $selected,
+                branchname => $branches->{$_}->{branchname},
+            );
+            push @billingplaceloop, \%row;
+        }
+        $template->param( billingplaceloop => \@billingplaceloop );
+        
+        # Build the combobox to select the delivery place
+        my @deliveryplaceloop;
+        for (sort keys %$branches) {
+            my $selected = 1 if $_ eq $deliveryplace;
             my %row = (
-                value      => $thisbranch,
+                value      => $_,
                 selected   => $selected,
-                branchname => $branches->{$thisbranch}->{branchname},
+                branchname => $branches->{$_}->{branchname},
             );
-            push @branchloop, \%row;
+            push @deliveryplaceloop, \%row;
         }
-        $template->param( branchloop => \@branchloop );
+        $template->param( deliveryplaceloop => \@deliveryplaceloop );
 
         $template->param( booksellerid => $booksellerid );
     }
@@ -386,11 +403,11 @@ if ( $op eq "add" ) {
     
     # Getting parameters
     my $basketgroup = {};
-    
     my @baskets         = $input->param('basket');
     my $basketgroupid   = $input->param('basketgroupid');
     my $basketgroupname = $input->param('basketgroupname');
     my $booksellerid    = $input->param('booksellerid');
+    my $billingplace    = $input->param('billingplace');
     my $deliveryplace   = $input->param('deliveryplace');
     my $deliverycomment = $input->param('deliverycomment');
     my $close           = $input->param('close') ? 1 : 0;
@@ -400,6 +417,7 @@ if ( $op eq "add" ) {
               name            => $basketgroupname,
               id              => $basketgroupid,
               basketlist      => \@baskets,
+              billingplace    => $billingplace,
               deliveryplace   => $deliveryplace,
               deliverycomment => $deliverycomment,
               closed          => $close,
@@ -419,8 +437,10 @@ if ( $op eq "add" ) {
         };
         $basketgroupid = NewBasketgroup($basketgroup);
     }
-    
-    print $input->redirect('/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' . $booksellerid);
+   
+    my $url = '/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' . $booksellerid;
+    $url .= "&closed=1" if ($input->param("closed")); 
+    print $input->redirect($url);
     
 }else{
     my $basketgroups = &GetBasketgroups($booksellerid);
@@ -429,5 +449,6 @@ if ( $op eq "add" ) {
 
     displaybasketgroups($basketgroups, $bookseller, $baskets);
 }
+$template->param(closed => $input->param("closed"));
 #prolly won't use all these, maybe just use print, the rest can be done inside validate
 output_html_with_http_headers $input, $cookie, $template->output;