Bug 15629: Koha::Libraries - Remove GetBranchDetail
[koha.git] / acqui / pdfformat / layout3pages.pm
index 5640a1c..ffec723 100644 (file)
@@ -7,30 +7,33 @@
 #
 # This file is part of Koha.
 #
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
 #
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY 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.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 #you can use any PDF::API2 module, all you need to do is return the stringifyed pdf object from the printpdf sub.
 package pdfformat::layout3pages;
 use vars qw($VERSION @ISA @EXPORT);
-use Number::Format qw(format_price);
 use MIME::Base64;
 use List::MoreUtils qw/uniq/;
 use strict;
 use warnings;
 use utf8;
 
-use C4::Branch qw(GetBranchDetail GetBranchName);
+use C4::Branch qw(GetBranchName);
+
+use Koha::Number::Price;
+use Koha::DateUtils;
+use Koha::Libraries;
 
 BEGIN {
          use Exporter   ();
@@ -43,7 +46,7 @@ BEGIN {
 
 
 #be careful, all the sizes (height, width, etc...) are in mm, not PostScript points (the default measurment of PDF::API2).
-#The constants exported tranform that into PostScript points (/mm for milimeter, /in for inch, pt is postscript point, and as so is there only to show what is happening.
+#The constants exported transform that into PostScript points (/mm for milimeter, /in for inch, pt is postscript point, and as so is there only to show what is happening.
 use constant mm => 25.4 / 72;
 use constant in => 1 / 72;
 use constant pt => 1;
@@ -57,24 +60,6 @@ sub printorders {
     my ($pdf, $basketgroup, $baskets, $orders) = @_;
     
     my $cur_format = C4::Context->preference("CurrencyFormat");
-    my $num;
-    
-    if ( $cur_format eq 'FR' ) {
-        $num = new Number::Format(
-            'decimal_fill'      => '2',
-            'decimal_point'     => ',',
-            'int_curr_symbol'   => '',
-            'mon_thousands_sep' => ' ',
-            'thousands_sep'     => ' ',
-            'mon_decimal_point' => ','
-        );
-    } else {  # US by default..
-        $num = new Number::Format(
-            'int_curr_symbol'   => '',
-            'mon_thousands_sep' => ',',
-            'mon_decimal_point' => '.'
-        );
-    }
 
     $pdf->mediabox($height/mm, $width/mm);
     my $number = 3;
@@ -134,13 +119,13 @@ sub printorders {
             push( @$arrbasket,
                 $titleinfo. ($line->{order_vendornote} ? "\n----------------\nNote for vendor : " . $line->{order_vendornote} : '' ),
                 $line->{quantity},
-                $num->format_price($line->{rrpgste}),
-                $num->format_price($line->{rrpgsti}),
-                $num->format_price($line->{discount}).'%',
-                $num->format_price($line->{rrpgste} - $line->{ecostgste}),
-                $num->format_price($line->{gstrate} * 100).'%',
-                $num->format_price($line->{totalgste}),
-                $num->format_price($line->{totalgsti}),
+                Koha::Number::Price->new( $line->{rrpgste} )->format,
+                Koha::Number::Price->new( $line->{rrpgsti} )->format,
+                Koha::Number::Price->new( $line->{discount} )->format . '%',
+                Koha::Number::Price->new( $line->{rrpgste} - $line->{ecostgste})->format,
+                Koha::Number::Price->new( $line->{gstrate} * 100 )->format . '%',
+                Koha::Number::Price->new( $line->{totalgste} )->format,
+                Koha::Number::Price->new( $line->{totalgsti} )->format,
             );
             push(@$abaskets, $arrbasket);
         }
@@ -204,25 +189,7 @@ sub printbaskets {
     my $libraryname = C4::Context->preference("LibraryName");
     
     my $cur_format = C4::Context->preference("CurrencyFormat");
-    my $num;
-    
-    if ( $cur_format eq 'FR' ) {
-        $num = new Number::Format(
-            'decimal_fill'      => '2',
-            'decimal_point'     => ',',
-            'int_curr_symbol'   => '',
-            'mon_thousands_sep' => ' ',
-            'thousands_sep'     => ' ',
-            'mon_decimal_point' => ','
-        );
-    } else {  # US by default..
-        $num = new Number::Format(
-            'int_curr_symbol'   => '',
-            'mon_thousands_sep' => ',',
-            'mon_decimal_point' => '.'
-        );
-    }
-    
+
     $pdf->mediabox($width/mm, $height/mm);
     my $page = $pdf->openpage(2);
     # create a text
@@ -263,31 +230,39 @@ sub printbaskets {
             push @gst, $ord->{gstrate};
         }
         @gst = uniq map { $_ * 100 } @gst;
-        $totalgsti = $num->round($totalgsti);
-        $totalgste = $num->round($totalgste);
         $grandtotalrrpgste += $totalrrpgste;
         $grandtotalrrpgsti += $totalrrpgsti;
         $grandtotalgsti += $totalgsti;
         $grandtotalgste += $totalgste;
         $grandtotalgstvalue += $totalgstvalue;
         $grandtotaldiscount += $totaldiscount;
-        my @gst_string = map{$num->format_price( $_ ) . '%'} @gst;
+        my @gst_string =
+          map { Koha::Number::Price->new($_)->format . '%' } @gst;
         push(@$arrbasket,
             $basket->{contractname},
             $basket->{basketname} . ' (No. ' . $basket->{basketno} . ')',
-            $num->format_price($totalrrpgste),
-            $num->format_price($totalrrpgsti),
+            Koha::Number::Price->new( $totalrrpgste )->format,
+            Koha::Number::Price->new( $totalrrpgsti )->format,
             "@gst_string",
-            $num->format_price($totalgstvalue),
-            $num->format_price($totaldiscount),
-            $num->format_price($totalgste),
-            $num->format_price($totalgsti)
+            Koha::Number::Price->new( $totalgstvalue )->format,
+            Koha::Number::Price->new( $totaldiscount )->format,
+            Koha::Number::Price->new( $totalgste )->format,
+            Koha::Number::Price->new( $totalgsti )->format,
         );
         push(@$abaskets, $arrbasket);
     }
     # now, push total
     undef $arrbasket;
-    push @$arrbasket,'','Total', $num->format_price($grandtotalrrpgste), $num->format_price($grandtotalrrpgsti), '', $num->format_price($grandtotalgstvalue), $num->format_price($grandtotaldiscount), $num->format_price($grandtotalgste), $num->format_price($grandtotalgsti);
+    push @$arrbasket,
+      '',
+      'Total',
+      Koha::Number::Price->new( $grandtotalrrpgste )->format,
+      Koha::Number::Price->new( $grandtotalrrpgsti )->format,
+      '',
+      Koha::Number::Price->new( $grandtotalgstvalue )->format,
+      Koha::Number::Price->new( $grandtotaldiscount )->format,
+      Koha::Number::Price->new( $grandtotalgste )->format,
+      Koha::Number::Price->new( $grandtotalgsti )->format;
     push @$abaskets,$arrbasket;
     # height is width and width is height in this function, as the pdf is in landscape mode for the Tables.
 
@@ -337,9 +312,8 @@ sub printhead {
 
     # get library name
     my $libraryname = C4::Context->preference("LibraryName");
-    # get branch details
-    my $billingdetails  = GetBranchDetail( $basketgroup->{billingplace} );
-    my $deliverydetails = GetBranchDetail( $basketgroup->{deliveryplace} );
+    my $billing_library  = Koha::Libraries->find( $basketgroup->{billingplace} );
+    my $delivery_library = Koha::Libraries->find( $basketgroup->{deliveryplace} );
     my $freedeliveryplace = $basketgroup->{freedeliveryplace};
     # get the subject
     my $subject;
@@ -361,7 +335,7 @@ sub printhead {
     $text->text($basketgroup->{'id'});
     
     # print the date
-    my $today = C4::Dates->today();
+    my $today = output_pref({ dt => dt_from_string, dateonly => 1 });
     $text->translate(130/mm,  ($height-5-48)/mm);
     $text->text($today);
     
@@ -371,21 +345,21 @@ sub printhead {
     $text->translate(100/mm,  ($height-86)/mm);
     $text->text($libraryname);
     $text->translate(100/mm,  ($height-97)/mm);
-    $text->text($billingdetails->{branchname});
+    $text->text($billing_library->branchname);
     $text->translate(100/mm,  ($height-108.5)/mm);
-    $text->text($billingdetails->{branchphone});
+    $text->text($billing_library->branchphone);
     $text->translate(100/mm,  ($height-115.5)/mm);
-    $text->text($billingdetails->{branchfax});
+    $text->text($billing_library->branchfax);
     $text->translate(100/mm,  ($height-122.5)/mm);
-    $text->text($billingdetails->{branchaddress1});
+    $text->text($billing_library->branchaddress1);
     $text->translate(100/mm,  ($height-127.5)/mm);
-    $text->text($billingdetails->{branchaddress2});
+    $text->text($billing_library->branchaddress2);
     $text->translate(100/mm,  ($height-132.5)/mm);
-    $text->text($billingdetails->{branchaddress3});
+    $text->text($billing_library->branchaddress3);
     $text->translate(100/mm,  ($height-137.5)/mm);
-    $text->text(join(' ', $billingdetails->{branchzip}, $billingdetails->{branchcity}, $billingdetails->{branchcountry}));
+    $text->text(join(' ', $billing_library->branchzip, $billing_library->branchcity, $billing_library->branchcountry));
     $text->translate(100/mm,  ($height-147.5)/mm);
-    $text->text($billingdetails->{branchemail});
+    $text->text($billing_library->branchemail);
     
     # print subject
     $text->translate(100/mm,  ($height-145.5)/mm);
@@ -417,13 +391,13 @@ sub printhead {
             $start += 5;
         }
     } else {
-        $text->text($deliverydetails->{branchaddress1});
+        $text->text($delivery_library->branchaddress1);
         $text->translate(50/mm,  ($height-242)/mm);
-        $text->text($deliverydetails->{branchaddress2});
+        $text->text($delivery_library->branchaddress2);
         $text->translate(50/mm,  ($height-247)/mm);
-        $text->text($deliverydetails->{branchaddress3});
+        $text->text($delivery_library->branchaddress3);
         $text->translate(50/mm,  ($height-252)/mm);
-        $text->text(join(' ', $deliverydetails->{branchzip}, $deliverydetails->{branchcity}, $deliverydetails->{branchcountry}));
+        $text->text(join(' ', $delivery_library->branchzip, $delivery_library->branchcity, $delivery_library->branchcountry));
     }
     $text->translate(50/mm,  ($height-262)/mm);
     $text->text($basketgroup->{deliverycomment});