[3.2.x](bug #3624) Per-basketgroup delivery place
authorJean-André Santoni <jeanandre.santoni@biblibre.com>
Sun, 1 Nov 2009 13:03:09 +0000 (14:03 +0100)
committerHenri-Damien LAURENT <henridamien.laurent@biblibre.com>
Mon, 2 Nov 2009 16:02:02 +0000 (17:02 +0100)
Librarian are now able to select a different delivery place for each basketgroup. They can choose one from the branch list or manualy using a textarea.
Database schema and PDF generation have been modified to reflect these changes.

C4/Acquisition.pm
acqui/basketgroup.pl
acqui/pdfformat/example.odt
acqui/pdfformat/example.pdf
acqui/pdfformat/example.pm
installer/data/mysql/updatedatabase.pl
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tmpl
kohaversion.pl

index 89f7423..e33b27c 100644 (file)
@@ -480,6 +480,10 @@ $hashref->{'name'} is the 'name' field of the basketgroup in the aqbasketgroups
 
 $hashref->{'basketlist'} is a list reference of the 'id's of the baskets that belong to this group,
 
+$hashref->{'deliveryplace'} is the 'deliveryplace' field of the basketgroup in the aqbasketgroups table,
+
+$hashref->{'deliverycomment'} is the 'deliverycomment' field of the basketgroup in the aqbasketgroups table,
+
 $hashref->{'closed'} is the 'closed' field of the aqbasketgroups table, it is false if 0, true otherwise.
 
 =back
@@ -493,7 +497,7 @@ sub NewBasketgroup {
     die "booksellerid is required to create a basketgroup" unless $basketgroupinfo->{'booksellerid'};
     my $query = "INSERT INTO aqbasketgroups (";
     my @params;
-    foreach my $field ('name', 'closed') {
+    foreach my $field ('name', 'deliveryplace', 'deliverycomment', 'closed') {
         if ( $basketgroupinfo->{$field} ) {
             $query .= "$field, ";
             push(@params, $basketgroupinfo->{$field});
@@ -537,6 +541,10 @@ $hashref->{'name'} is the 'name' field of the basketgroup in the aqbasketgroups
 
 $hashref->{'basketlist'} is a list reference of the 'id's of the baskets that belong to this group,
 
+$hashref->{'deliveryplace'} is the 'deliveryplace' field of the basketgroup in the aqbasketgroups table,
+
+$hashref->{'deliverycomment'} is the 'deliverycomment' field of the basketgroup in the aqbasketgroups table,
+
 $hashref->{'closed'} is the 'closed' field of the aqbasketgroups table, it is false if 0, true otherwise.
 
 =back
@@ -551,7 +559,7 @@ sub ModBasketgroup {
     my $dbh = C4::Context->dbh;
     my $query = "UPDATE aqbasketgroups SET ";
     my @params;
-    foreach my $field (qw(name closed)) {
+    foreach my $field (qw(name deliveryplace deliverycomment closed)) {
         if ( $basketgroupinfo->{$field} ne undef) {
             $query .= "$field=?, ";
             push(@params, $basketgroupinfo->{$field});
index 9baa172..17d8948 100755 (executable)
@@ -53,6 +53,8 @@ use CGI;
 use C4::Bookseller qw/GetBookSellerFromId/;
 use C4::Acquisition qw/CloseBasketgroup ReOpenBasketgroup GetOrders GetBasketsByBasketgroup GetBasketsByBookseller ModBasketgroup NewBasketgroup DelBasketgroup GetBasketgroups ModBasket GetBasketgroup GetBasket/;
 use C4::Bookseller qw/GetBookSellerFromId/;
+use C4::Branch qw/GetBranches/;
+use C4::Members qw/GetMember/;
 
 my $input=new CGI;
 
@@ -268,14 +270,41 @@ if ( $op eq "add" ) {
         }
     } else {
         my $basketgroupid = $input->param('basketgroupid');
-        if($basketgroupid){
+        my $branchcode;
+        if ( $basketgroupid ) {
+            # Get the selected baskets in the basketgroup to display them
             my $selecteds = GetBasketsByBasketgroup($basketgroupid);
             foreach (@{$selecteds}){
                 $_->{total} = BasketTotal($_->{basketno}, $_);
             }
             $template->param(basketgroupid => $basketgroupid,
                              selectedbaskets => $selecteds);
+
+            # Get general informations about the basket group to prefill the form
+            my $basketgroup = GetBasketgroup($basketgroupid);
+            $template->param(
+                name            => $basketgroup->{name},
+                deliverycomment => $basketgroup->{deliverycomment},
+            );
+            $branchcode = $basketgroup->{deliveryplace};
+        }
+
+        # Build the combobox to select the delivery place
+        my $borrower = GetMember( ( 'borrowernumber' => $loggedinuser ) );
+        my $branch   = $branchcode || $borrower->{'branchcode'};
+        my $branches = GetBranches;
+        my @branchloop;
+        foreach my $thisbranch (sort keys %$branches) {
+            my $selected = 1 if $thisbranch eq $branch;
+            my %row = (
+                value      => $thisbranch,
+                selected   => $selected,
+                branchname => $branches->{$thisbranch}->{branchname},
+            );
+            push @branchloop, \%row;
         }
+        $template->param( branchloop => \@branchloop );
+
         $template->param( booksellerid => $booksellerid );
     }
     $template->param(grouping => 1);
@@ -362,14 +391,18 @@ if ( $op eq "add" ) {
     my $basketgroupid   = $input->param('basketgroupid');
     my $basketgroupname = $input->param('basketgroupname');
     my $booksellerid    = $input->param('booksellerid');
+    my $deliveryplace   = $input->param('deliveryplace');
+    my $deliverycomment = $input->param('deliverycomment');
     my $close           = $input->param('close') ? 1 : 0;
     # If we got a basketgroupname, we create a basketgroup
     if ($basketgroupid) {
         $basketgroup = {
-              name => $basketgroupname,
-              id => $basketgroupid,
-              basketlist => \@baskets,
-              closed      => $close,
+              name            => $basketgroupname,
+              id              => $basketgroupid,
+              basketlist      => \@baskets,
+              deliveryplace   => $deliveryplace,
+              deliverycomment => $deliverycomment,
+              closed          => $close,
         };
         ModBasketgroup($basketgroup);
         if($close){
@@ -377,10 +410,12 @@ if ( $op eq "add" ) {
         }
     }else{
         $basketgroup = {
-            name         => $basketgroupname,
-            booksellerid => $booksellerid,
-            basketlist   => \@baskets,
-            closed        => $close,
+            name            => $basketgroupname,
+            booksellerid    => $booksellerid,
+            basketlist      => \@baskets,
+            deliveryplace   => $deliveryplace,
+            deliverycomment => $deliverycomment,
+            closed          => $close,
         };
         $basketgroupid = NewBasketgroup($basketgroup);
     }
index edd860d..cf1d850 100644 (file)
Binary files a/acqui/pdfformat/example.odt and b/acqui/pdfformat/example.odt differ
index 83e2575..03a3a9b 100644 (file)
Binary files a/acqui/pdfformat/example.pdf and b/acqui/pdfformat/example.pdf differ
index 6a5f292..34f3b05 100644 (file)
@@ -28,6 +28,8 @@ use strict;
 use warnings;
 use utf8;
 
+use C4::Branch qw(GetBranchDetail);
+
 BEGIN {
          use Exporter   ();
          our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
@@ -267,6 +269,10 @@ sub printbaskets {
 
 sub printhead {
     my ($pdf, $basketgroup, $bookseller, $branch) = @_;
+
+    # get branch details
+    my $branchdetails = GetBranchDetail( $basketgroup->{'deliveryplace'} );
+
     # open 1st page (with the header)
     my $page = $pdf->openpage(1);
     
@@ -294,6 +300,16 @@ sub printhead {
     $text->text($bookseller->{address2});
     $text->translate(110/mm,  ($height-190)/mm);
     $text->text($bookseller->{address3});
+    # print delivery infos
+    $text->font( $pdf->corefont("Times-Bold", -encoding => "utf8"), 4/mm );
+    $text->translate(50/mm,  ($height-230)/mm);
+    $text->text($branchdetails->{branchaddress1});
+    $text->translate(50/mm,  ($height-235)/mm);
+    $text->text($branchdetails->{branchaddress2});
+    $text->translate(50/mm,  ($height-240)/mm);
+    $text->text($branchdetails->{branchaddress3});
+    $text->translate(50/mm,  ($height-245)/mm);
+    $text->text($basketgroup->{'deliverycomment'});
 }
 
 sub printfooters {
index 7055fab..d70b344 100755 (executable)
@@ -3147,6 +3147,17 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     SetVersion ($DBversion);
 }
 
+$DBversion = "3.01.00.123";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+       $dbh->do(qq{
+       ALTER TABLE aqbasketgroups ADD deliveryplace VARCHAR(10), deliverycomment VARCHAR(255);
+       });
+       
+    print "Upgrade to $DBversion done (isbd updated)\n";
+    SetVersion ($DBversion);
+}
+
+
 =item DropAllForeignKeys($table)
 
   Drop all foreign keys of the table $table
index 15238d4..cbfad5c 100755 (executable)
@@ -205,8 +205,17 @@ fieldset.various li {
                    <div class="yui-u grouping"> 
                        <form action="" method="post">
                                        <fieldset id="various" class='various' >
-                               <h3><label for="basketgroupname">Basketgroup Name:</label></h3>
-                               <input type="text" name="basketgroupname" id="basketgroupname" />
+                                               <h3><label for="basketgroupname">Basketgroup Name:</label></h3>
+                                               <input type="text" name="basketgroupname" id="basketgroupname" value="<!-- TMPL_VAR NAME="name" -->" />
+                                               <h3><label for="deliveryplace">Delivery Place:</label></h3>
+                                               <select name="deliveryplace" id="deliveryplace">
+                                                       <option value="">--</option>
+                                                       <!-- TMPL_LOOP name="branchloop" -->
+                                                       <option value="<!-- TMPL_VAR name="value" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="branchname" --></option>
+                                                       <!-- /TMPL_LOOP -->
+                                               </select>
+                                               <h3><label for="deliverycomment">Delivery comment:</label></h3>
+                                               <textarea cols="26" name="deliverycomment" id="deliverycomment"><!-- TMPL_VAR NAME="deliverycomment" --></textarea>
                                        <div class="workarea">
                                                        <h3>Grouping</h3>
                                                        <ul class="draglist" id="bg">
index a9ec93a..4238fa0 100644 (file)
@@ -10,7 +10,7 @@
 use strict;
 
 sub kohaversion {
-    our $VERSION = '3.01.00.122';
+    our $VERSION = '3.01.00.123';
     # version needs to be set this way
     # so that it can be picked up by Makefile.PL
     # during install