Bug 10572: Add phone to message_transport_types table for new installs
[koha.git] / acqui / basketheader.pl
index 56f2483..93bd7f8 100755 (executable)
@@ -16,9 +16,9 @@
 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along with
-# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
-# Suite 330, Boston, MA  02111-1307 USA
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 =head1 NAME
 
@@ -33,9 +33,9 @@ notes to the supplier, local notes, and the contractnumber, which identifies the
 
 =over 4
 
-=item supplierid
+=item booksellerid
 
-C<$supplierid> is the id of the supplier we add the basket to.
+C<$booksellerid> is the id of the supplier we add the basket to.
 
 =item basketid
 
@@ -50,9 +50,10 @@ use warnings;
 use CGI;
 use C4::Context;
 use C4::Auth;
+use C4::Branch;
 use C4::Output;
 use C4::Acquisition qw/GetBasket NewBasket GetContracts ModBasketHeader/;
-use C4::Bookseller qw/GetBookSellerFromId/;
+use C4::Bookseller qw/GetBookSellerFromId GetBookSeller/;
 
 
 my $input = new CGI;
@@ -68,9 +69,9 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
 );
 
 #parameters:
-my $booksellerid;
-$booksellerid = $input->param('booksellerid');
+my $booksellerid = $input->param('booksellerid');
 my $basketno = $input->param('basketno');
+my $branches = GetBranches;
 my $basket;
 my $op = $input ->param('op');
 my $is_an_edit= $input ->param('is_an_edit');
@@ -99,26 +100,59 @@ if ( $op eq 'add_form' ) {
     my $count = scalar @contractloop;
     if ( $count > 0) {
         $template->param(contractloop => \@contractloop,
-                                           basketcontractnumber => $basket->{'contractnumber'});
+                         basketcontractnumber => $basket->{'contractnumber'});
     }
+    my @booksellers = C4::Bookseller::GetBookSeller();
     $template->param( add_form => 1,
                     basketname => $basket->{'basketname'},
                     basketnote => $basket->{'note'},
                     basketbooksellernote => $basket->{'booksellernote'},
                     booksellername => $bookseller->{'name'},
                     booksellerid => $booksellerid,
-                    basketno => $basketno
-       );
+                    basketno => $basketno,
+                    booksellers => \@booksellers,
+                    deliveryplace => $basket->{deliveryplace},
+                    billingplace => $basket->{billingplace},
+    );
+
+    my $billingplace = $basket->{'billingplace'} || C4::Context->userenv->{"branch"};
+    my $deliveryplace = $basket->{'deliveryplace'} || C4::Context->userenv->{"branch"};
+
+    # Build the combobox to select the billing place
+    my @billingplaceloop;
+
+    my $branches = C4::Branch::GetBranchesLoop( $billingplace );
+    $template->param( billingplaceloop => $branches );
+    $branches = C4::Branch::GetBranchesLoop( $deliveryplace );
+    $template->param( deliveryplaceloop => $branches );
+
 #End Edit
 } elsif ( $op eq 'add_validate' ) {
 #we are confirming the changes, save the basket
-    $template->param(add_validate => 1);
     if ( $is_an_edit ) {
-        ModBasketHeader($input->param('basketno'),$input->param('basketname'),$input->param('basketnote'),$input->param('basketbooksellernote'),$input->param('basketcontractnumber'));
-        $template->param( basketno => $basketno );
+        ModBasketHeader(
+            $basketno,
+            $input->param('basketname'),
+            $input->param('basketnote'),
+            $input->param('basketbooksellernote'),
+            $input->param('basketcontractnumber') || undef,
+            $input->param('basketbooksellerid'),
+            $input->param('deliveryplace'),
+            $input->param('billingplace'),
+        );
     } else { #New basket
-        my $basketno = NewBasket($booksellerid, $loggedinuser, $input->param('basketname'), $input->param('basketnote'), $input->param('basketbooksellernote'), $input->param('basketcontractnumber'));
-        $template->param( basketno => $basketno );
+        $basketno = NewBasket(
+            $booksellerid,
+            $loggedinuser,
+            $input->param('basketname'),
+            $input->param('basketnote'),
+            $input->param('basketbooksellernote'),
+            $input->param('basketcontractnumber') || undef,
+            $input->param('deliveryplace'),
+            $input->param('billingplace'),
+        );
     }
+    print $input->redirect('basket.pl?basketno='.$basketno);
+    exit 0;
 }
 output_html_with_http_headers $input, $cookie, $template->output;