Bug 5970: Adds the ability to use a free delivery address for basket
[koha.git] / acqui / pdfformat / layout2pages.pm
index 78ca0c4..148394a 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.
 
 #you can use any PDF::API2 module, all you need to do is return the stringifyed pdf object from the printpdf sub.
 package pdfformat::layout2pages;
@@ -146,6 +146,7 @@ sub printhead {
     # get branch details
     my $billingdetails  = GetBranchDetail( $basketgroup->{billingplace} );
     my $deliverydetails = GetBranchDetail( $basketgroup->{deliveryplace} );
+    my $freedeliveryplace = $basketgroup->{freedeliveryplace};
     # get the subject
     my $subject;
 
@@ -211,13 +212,23 @@ sub printhead {
     # print delivery infos
     $text->font( $pdf->corefont("Times-Bold", -encoding => "utf8"), 4/mm );
     $text->translate(50/mm, ($height-237)/mm);
-    $text->text($deliverydetails->{branchaddress1});
-    $text->translate(50/mm, ($height-242)/mm);
-    $text->text($deliverydetails->{branchaddress2});
-    $text->translate(50/mm, ($height-247)/mm);
-    $text->text($deliverydetails->{branchaddress3});
-    $text->translate(50/mm, ($height-252)/mm);
-    $text->text(join(' ', $deliverydetails->{branchzip}, $deliverydetails->{branchcity}, $deliverydetails->{branchcountry}));
+    if ($freedeliveryplace) {
+        my $start = 242;
+        my @fdp = split('\n', $freedeliveryplace);
+        foreach (@fdp) {
+            $text->text($_);
+            $text->translate( 50 / mm, ( $height - $start ) / mm );
+            $start += 5;
+        }
+    } else {
+        $text->text( $deliverydetails->{branchaddress1} );
+        $text->translate( 50 / mm, ( $height - 242 ) / mm );
+        $text->text( $deliverydetails->{branchaddress2} );
+        $text->translate( 50 / mm, ( $height - 247 ) / mm );
+        $text->text( $deliverydetails->{branchaddress3} );
+        $text->translate( 50 / mm, ( $height - 252 ) / mm );
+        $text->text( join( ' ', $deliverydetails->{branchzip}, $deliverydetails->{branchcity}, $deliverydetails->{branchcountry} ) );
+    }
     $text->translate(50/mm, ($height-262)/mm);
     $text->text($basketgroup->{deliverycomment});
 }
@@ -236,9 +247,8 @@ sub printfooters {
 sub printpdf {
     my ($basketgroup, $bookseller, $baskets, $orders, $GST) = @_;
     # open the default PDF that will be used for base (1st page already filled)
-    my $template = C4::Context->preference("OrderPdfTemplate");
-    $template = decode_base64($template);
-    my $pdf = PDF::API2->openScalar($template);
+    my $pdf_template = C4::Context->config('intrahtdocs') . '/' . C4::Context->preference('template') . '/pdf/layout2pages.pdf';
+    my $pdf = PDF::API2->open($pdf_template);
     $pdf->pageLabel( 0, {
         -style => 'roman',
     } ); # start with roman numbering