Bug 5356: delivery place and billing place centralised in basket management
authorJonathan Druart <jonathan.druart@biblibre.com>
Wed, 25 Jul 2012 08:25:16 +0000 (10:25 +0200)
committerPaul Poulain <paul.poulain@biblibre.com>
Mon, 24 Sep 2012 18:46:39 +0000 (20:46 +0200)
- adding 2 select option in basdketheader.tmpl (delivery and billing
   place)
- adding 2 more fields in basket csv export

Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Tested together with patches for bug 7302.

C4/Acquisition.pm
acqui/basket.pl
acqui/basketgroup.pl
acqui/basketheader.pl
installer/data/mysql/kohastructure.sql
installer/data/mysql/updatedatabase.pl
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tt
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketheader.tt

index 05cae14..42b52ba 100644 (file)
@@ -173,7 +173,7 @@ sub GetBasket {
 =head3 NewBasket
 
   $basket = &NewBasket( $booksellerid, $authorizedby, $basketname, 
-      $basketnote, $basketbooksellernote, $basketcontractnumber );
+      $basketnote, $basketbooksellernote, $basketcontractnumber, $deliveryplace, $billingplace );
 
 Create a new basket in aqbasket table
 
@@ -189,10 +189,8 @@ The other parameters are optional, see ModBasketHeader for more info on them.
 
 =cut
 
-# FIXME : this function seems to be unused.
-
 sub NewBasket {
-    my ( $booksellerid, $authorisedby, $basketname, $basketnote, $basketbooksellernote, $basketcontractnumber ) = @_;
+    my ( $booksellerid, $authorisedby, $basketname, $basketnote, $basketbooksellernote, $basketcontractnumber, $deliveryplace, $billingplace ) = @_;
     my $dbh = C4::Context->dbh;
     my $query = "
         INSERT INTO aqbasket
@@ -203,7 +201,7 @@ sub NewBasket {
     $dbh->do($query);
 #find & return basketno MYSQL dependant, but $dbh->last_insert_id always returns null :-(
     my $basket = $dbh->{'mysql_insertid'};
-    ModBasketHeader($basket, $basketname || '', $basketnote || '', $basketbooksellernote || '', $basketcontractnumber || undef, $booksellerid);
+    ModBasketHeader($basket, $basketname || '', $basketnote || '', $basketbooksellernote || '', $basketcontractnumber || undef, $booksellerid, $deliveryplace || undef, $billingplace || undef );
     return $basket;
 }
 
@@ -265,8 +263,8 @@ sub GetBasketAsCSV {
             notes => $order->{'notes'},
             quantity => $order->{'quantity'},
             rrp => $order->{'rrp'},
-            deliveryplace => $basket->{'deliveryplace'},
-            billingplace => $basket->{'billingplace'}
+            deliveryplace => C4::Branch::GetBranchName( $basket->{'deliveryplace'} ),
+            billingplace => C4::Branch::GetBranchName( $basket->{'billingplace'} ),
         };
         foreach(qw(
             contractname author title publishercode collectiontitle notes
@@ -315,6 +313,7 @@ sub GetBasketGroupAsCSV {
         my @orders     = GetOrders( $$basket{basketno} );
         my $contract   = GetContract( $$basket{contractnumber} );
         my $bookseller = GetBookSellerFromId( $$basket{booksellerid} );
+        my $basketgroup = GetBasketgroup( $$basket{basketgroupid} );
 
         foreach my $order (@orders) {
             my $bd = GetBiblioData( $order->{'biblionumber'} );
@@ -339,6 +338,10 @@ sub GetBasketGroupAsCSV {
                 booksellerpostal => $bookseller->{postal},
                 contractnumber => $contract->{contractnumber},
                 contractname => $contract->{contractname},
+                basketgroupdeliveryplace => C4::Branch::GetBranchName( $basketgroup->{deliveryplace} ) || C4::Branch::GetBranchName( $basketgroup->{freedeliveryplace} ),
+                basketgroupbillingplace => C4::Branch::GetBranchName( $basketgroup->{billingplace} ),
+                basketdeliveryplace => C4::Branch::GetBranchName( $basket->{deliveryplace} ),
+                basketbillingplace => C4::Branch::GetBranchName( $basket->{billingplace} ),
             };
             foreach(qw(
                 basketname author title publishercode collectiontitle notes
@@ -486,17 +489,25 @@ Modifies a basket's header.
 
 =item C<$booksellerid> is the id (foreign) key in the "aqbooksellers" table for the vendor.
 
+=item C<$deliveryplace> is the "deliveryplace" field in the aqbasket table.
+
+=item C<$billingplace> is the "billingplace" field in the aqbasket table.
+
 =back
 
 =cut
 
 sub ModBasketHeader {
-    my ($basketno, $basketname, $note, $booksellernote, $contractnumber, $booksellerid) = @_;
+    my ($basketno, $basketname, $note, $booksellernote, $contractnumber, $booksellerid, $deliveryplace, $billingplace) = @_;
+    my $query = qq{
+        UPDATE aqbasket
+        SET basketname=?, note=?, booksellernote=?, booksellerid=?, deliveryplace=?, billingplace=?
+        WHERE basketno=?
+    };
 
-    my $query = "UPDATE aqbasket SET basketname=?, note=?, booksellernote=?, booksellerid=? WHERE basketno=?";
     my $dbh = C4::Context->dbh;
     my $sth = $dbh->prepare($query);
-    $sth->execute($basketname,$note,$booksellernote,$booksellerid,$basketno);
+    $sth->execute($basketname, $note, $booksellernote, $booksellerid, $deliveryplace, $billingplace, $basketno);
 
     if ( $contractnumber ) {
         my $query2 ="UPDATE aqbasket SET contractnumber=? WHERE basketno=?";
index 4b7566b..ace6b63 100755 (executable)
@@ -130,6 +130,8 @@ if ( $op eq 'delete_confirm' ) {
         authorisedby         => $basket->{authorisedby},
         authorisedbyname     => $basket->{authorisedbyname},
         closedate            => $basket->{closedate},
+        deliveryplace        => $basket->{deliveryplace},
+        billingplace         => $basket->{billingplace},
         active               => $bookseller->{'active'},
         booksellerid         => $bookseller->{'id'},
         name                 => $bookseller->{'name'},
@@ -283,6 +285,15 @@ if ( $op eq 'delete_confirm' ) {
     my $contract = &GetContract($basket->{contractnumber});
     my @orders = GetOrders($basketno);
 
+    if ($basket->{basketgroupid}){
+        my $basketgroup = GetBasketgroup($basket->{basketgroupid});
+        for my $key (keys %$basketgroup ){
+            $basketgroup->{"basketgroup$key"} = delete $basketgroup->{$key};
+        }
+        $basketgroup->{basketgroupdeliveryplace} = C4::Branch::GetBranchName( $basketgroup->{basketgroupdeliveryplace} );
+        $basketgroup->{basketgroupbillingplace} = C4::Branch::GetBranchName( $basketgroup->{basketgroupbillingplace} );
+        $template->param(%$basketgroup);
+    }
     my $borrower= GetMember('borrowernumber' => $loggedinuser);
     my $budgets = GetBudgetHierarchy;
     my $has_budgets = 0;
@@ -313,6 +324,8 @@ if ( $op eq 'delete_confirm' ) {
         authorisedbyname     => $basket->{authorisedbyname},
         closedate            => $basket->{closedate},
         estimateddeliverydate=> $estimateddeliverydate,
+        deliveryplace        => C4::Branch::GetBranchName( $basket->{deliveryplace} ),
+        billingplace         => C4::Branch::GetBranchName( $basket->{billingplace} ),
         active               => $bookseller->{'active'},
         booksellerid         => $bookseller->{'id'},
         name                 => $bookseller->{'name'},
index ac0672c..6b7e5bf 100755 (executable)
@@ -328,30 +328,11 @@ if ( $op eq "add" ) {
         my $borrower = GetMember( ( 'borrowernumber' => $loggedinuser ) );
         $billingplace  = $billingplace  || $borrower->{'branchcode'};
         $deliveryplace = $deliveryplace || $borrower->{'branchcode'};
-        
-        my $branches = GetBranches;
-        
-        # Build the combobox to select the billing place
-        my @billingplaceloop;
-        for (sort keys %$branches) {
-            push @billingplaceloop, {
-                value      => $_,
-                selected   => $_ eq $billingplace,
-                branchname => $branches->{$_}->{branchname},
-            };
-        }
-        $template->param( billingplaceloop => \@billingplaceloop );
-        
-        # Build the combobox to select the delivery place
-        my @deliveryplaceloop;
-        for (sort keys %$branches) {
-            push @deliveryplaceloop, {
-                value      => $_,
-                selected   => $_ eq $deliveryplace,
-                branchname => $branches->{$_}->{branchname},
-            };
-        }
-        $template->param( deliveryplaceloop => \@deliveryplaceloop );
+
+        my $branches = C4::Branch::GetBranchesLoop( $billingplace );
+        $template->param( billingplaceloop => $branches );
+        $branches = C4::Branch::GetBranchesLoop( $deliveryplace );
+        $template->param( deliveryplaceloop => $branches );
 
         $template->param( booksellerid => $booksellerid );
     }
index 08b38eb..8f75f40 100755 (executable)
@@ -50,6 +50,7 @@ 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 GetBookSeller/;
@@ -70,6 +71,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
 #parameters:
 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');
@@ -100,7 +102,7 @@ if ( $op eq 'add_form' ) {
         $template->param(contractloop => \@contractloop,
                          basketcontractnumber => $basket->{'contractnumber'});
     }
-    my @booksellers = GetBookSeller();
+    my @booksellers = C4::Bookseller::GetBookSeller();
     $template->param( add_form => 1,
                     basketname => $basket->{'basketname'},
                     basketnote => $basket->{'note'},
@@ -109,16 +111,47 @@ if ( $op eq 'add_form' ) {
                     booksellerid => $booksellerid,
                     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
-    my $basketno;
     if ( $is_an_edit ) {
-        $basketno = $input->param('basketno');
-        ModBasketHeader( $input->param('basketno'), $input->param('basketname'), $input->param('basketnote'), $input->param('basketbooksellernote'), $input->param('basketcontractnumber') || undef, $input->param('basketbooksellerid') );
+        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
-        $basketno = NewBasket($booksellerid, $loggedinuser, $input->param('basketname'), $input->param('basketnote'), $input->param('basketbooksellernote'), $input->param('basketcontractnumber'));
+        $basketno = NewBasket(
+            $booksellerid,
+            $loggedinuser,
+            $input->param('basketname'),
+            $input->param('basketnote'),
+            $input->param('basketbooksellernote'),
+            $input->param('basketcontractnumber') || undef,
+            undef,
+            $input->param('deliveryplace'),
+            $input->param('billingplace'),
+        );
     }
     print $input->redirect('basket.pl?basketno='.$basketno);
     exit 0;
index 4f70587..39857b7 100644 (file)
@@ -2594,6 +2594,8 @@ CREATE TABLE `aqbasket` ( -- stores data about baskets in acquisitions
   `authorisedby` varchar(10) default NULL, -- the borrowernumber of the person who created the basket
   `booksellerinvoicenumber` mediumtext, -- appears to always be NULL
   `basketgroupid` int(11), -- links this basket to its group (aqbasketgroups.id)
+  `deliveryplace` varchar(10) default NULL, -- basket delivery place
+  `billingplace` varchar(10) default NULL, -- basket billing place
   PRIMARY KEY  (`basketno`),
   KEY `booksellerid` (`booksellerid`),
   KEY `basketgroupid` (`basketgroupid`),
index 4d47a59..9444577 100755 (executable)
@@ -5974,6 +5974,14 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
 }
 
 
+$DBversion = "3.09.00.XXX";
+if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
+    $dbh->do("ALTER TABLE aqbasket ADD deliveryplace VARCHAR(10) default NULL AFTER basketgroupid;");
+    $dbh->do("ALTER TABLE aqbasket ADD billingplace VARCHAR(10) default NULL AFTER deliveryplace;");
+    print "Upgrade to $DBversion done (Added billingplace, deliveryplace to the aqbasket table)\n";
+    SetVersion($DBversion);
+}
+
 =head1 FUNCTIONS
 
 =head2 TableExists($table)
index ca92fac..bd9d145 100644 (file)
                         // YUI Toolbar Functions
                         function yuiToolbar() {
                             new YAHOO.widget.Button("reopenbutton");
+                            new YAHOO.widget.Button("exportbutton");
                         }
                         //]]>
                     </script>
                         <ul id="toolbar-list" class="toolbar">
                             <li><a href="javascript:confirm_reopen([% skip_confirm_reopen %]);" class="button" id="reopenbutton">Reopen this basket</a></li>
+                            <li><a href="[% script_name %]?op=export&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="button" id="exportbutton">Export this basket as CSV</a></li>
                         </ul>
                 </div>
                 [% END %]
                 [% IF ( basketcontractno ) %]
                     <li><span class="label">Contract name:</span> <a href="../admin/aqcontract.pl?op=add_form&amp;contractnumber=[% basketcontractno %]&amp;booksellerid=[% booksellerid %]">[% basketcontractname %]</a></li>
                 [% END %]
+                [% IF ( deliveryplace ) %]<li><span class="label">Delivery place:</span> [% deliveryplace %]</li>[% END %]
+                [% IF ( billingplace ) %]<li><span class="label">Billing place:</span> [% billingplace %]</li>[% END %]
                 [% IF ( authorisedbyname ) %]<li><span class="label">Managed by:</span>  [% authorisedbyname %]</li>[% END %]
                 [% IF ( creationdate ) %]<li><span class="label">Opened on:</span>  [% creationdate | $KohaDates %]</li>[% END %]
                 [% IF ( closedate ) %]<li><span class="label">Closed on:</span> [% closedate | $KohaDates %]</li>[% END %]
                         <input type="submit" value="Change basket group" /></p>
 
                     </form>
+                    [% IF ( basketgroupdeliveryplace ) %]<p>Basketgroup Delivery place: [% basketgroupdeliveryplace %]</p>[% END %]
+                    [% IF ( basketgroupbillingplace ) %]<p>Basketgroup Billing place: [% basketgroupbillingplace %]</p>[% END %]
                 </div>
                 [% END %]
             </div>
index d02202c..65d3e6e 100644 (file)
@@ -203,6 +203,7 @@ function yuiToolbar() {
                                                        <input type="text" name="basketgroupname" id="basketgroupname" value="[% name %]" /></li>
                         <li><label for="billingplace">Billing place:</label>
                                                        <select name="billingplace" id="billingplace" style="width:13em;">
+                                <option value="">--</option>
                                                                [% FOREACH billingplaceloo IN billingplaceloop %]
                                        [% IF ( billingplaceloo.selected ) %]<option value="[% billingplaceloo.value %]" selected="selected">[% billingplaceloo.branchname %]</option>
                                        [% ELSE %]<option value="[% billingplaceloo.value %]">[% billingplaceloo.branchname %]</option>[% END%]
index 068171e..8b7849d 100644 (file)
@@ -124,6 +124,28 @@ li.list2 {
                 <li>
                     <label for="basketname" class="required">Basket name</label> &nbsp;
                         <input type="text" name="basketname" id="basketname" size="40" maxlength="80" value="[% basketname %]" />
+                </li>
+                 <li>
+                    <label for="billingplace">Billing Place:</label>
+                    <select name="billingplace" id="billingplace">
+                        <option value="">--</option>
+                        [% FOREACH billingplace IN billingplaceloop %]
+                            <option value="[% billingplace.value %]"[% IF ( billingplace.selected ) %] selected="selected"[% END %]>
+                                [% billingplace.branchname %]
+                            </option>
+                        [% END %]
+                    </select>
+                </li>
+                <li>
+                    <label for="deliveryplace">Delivery  Place:</label>
+                    <select name="deliveryplace" id="deliveryplace">
+                        <option value="">--</option>
+                        [% FOREACH deliveryplace IN deliveryplaceloop %]
+                            <option value="[% deliveryplace.value %]"[% IF ( deliveryplace.selected ) %] selected="selected"[% END %]>
+                                [% deliveryplace.branchname %]
+                            </option>
+                        [% END %]
+                    </select>
                 </li>
                 <li>
                     <label for="basketbooksellerid">Vendor</label> &nbsp;