Revert "Bug 4450 Use more consistent error returns in C4/Creators/*"
[srvgit] / acqui / supplier.pl
index b3ed949..c3a5db4 100755 (executable)
@@ -17,9 +17,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
 
@@ -41,10 +41,13 @@ To know the bookseller this script has to display details.
 =cut
 
 use strict;
+use warnings;
 use C4::Auth;
 use C4::Acquisition;
+use C4::Contract;
 use C4::Biblio;
 use C4::Output;
+use C4::Dates qw/format_date /;
 use CGI;
 
 use C4::Bookseller;
@@ -64,10 +67,28 @@ my ($template, $loggedinuser, $cookie) = get_template_and_user(
                debug           => 1,
        }
 );
-my $GST = $booksellers[0]->{'gstrate'} || C4::Context->preference("gist");
+my $seller_gstrate = $booksellers[0]->{'gstrate'};
+# A perl-ism: '0'==false, '0.000'==true, but 0=='0.000' - this accounts for that
+undef $seller_gstrate if ($seller_gstrate == 0);
+my $GST = $seller_gstrate || C4::Context->preference("gist");
 $GST *= 100;
+
+my @contracts = GetContracts($id);
+my $contractcount = scalar(@contracts);
+$template->param(hascontracts => 1) if ($contractcount > 0);
+
 #build array for currencies
 if ($op eq "display") {
+
+    # get contracts
+    my @contracts = @{GetContract( { booksellerid => $id } )};
+
+    # format dates
+    for ( @contracts ) {
+        $$_{contractstartdate} = format_date($$_{contractstartdate});
+        $$_{contractenddate}   = format_date($$_{contractenddate});
+    }
+
        $template->param(
                id            => $id,
                name          => $booksellers[0]->{'name'},
@@ -88,16 +109,16 @@ if ($op eq "display") {
                contnotes     => $booksellers[0]->{'contnotes'},
                notes         => $booksellers[0]->{'notes'},
                active        => $booksellers[0]->{'active'},
-               specialty     => $booksellers[0]->{'specialty'},
                gstreg        => $booksellers[0]->{'gstreg'},
                listincgst    => $booksellers[0]->{'listincgst'},
                invoiceincgst => $booksellers[0]->{'invoiceincgst'},
-               gstrate                 => $booksellers[0]->{'gstrate'},
+               gstrate       => $booksellers[0]->{'gstrate'}*100,
                discount      => $booksellers[0]->{'discount'},
                invoiceprice  => $booksellers[0]->{'invoiceprice'},
                listprice     => $booksellers[0]->{'listprice'},
                GST           => $GST,
                basketcount   => $booksellers[0]->{'basketcount'},
+               contracts     => \@contracts
        );
 }
 elsif ($op eq 'delete') {
@@ -122,8 +143,6 @@ elsif ($op eq 'delete') {
             push @loop_invoicecurrency, { currency => "<option value=\"$currencies[$i]->{'currency'}\">$currencies[$i]->{'currency'}</option>"};
         }
     }
-    my $GST = $booksellers[0]->{'gstrate'} || C4::Context->preference("gist");
-    $GST *= 100;
        $template->param(
                id                   => $id,
                name                 => $booksellers[0]->{'name'},
@@ -143,12 +162,11 @@ elsif ($op eq 'delete') {
                contemail            => $booksellers[0]->{'contemail'},
                contnotes            => $booksellers[0]->{'contnotes'},
                notes                => $booksellers[0]->{'notes'},
-               active               => $booksellers[0]->{'active'},
-               specialty            => $booksellers[0]->{'specialty'},
+               active               => $id?$booksellers[0]->{'active'}:1, # set active ON by default for supplier add (id empty for add)
                gstreg               => $booksellers[0]->{'gstreg'},
                listincgst           => $booksellers[0]->{'listincgst'},
                invoiceincgst        => $booksellers[0]->{'invoiceincgst'},
-               gstrate                 => $booksellers[0]->{'gstrate'},
+               gstrate              => $booksellers[0]->{'gstrate'}*100,
                discount             => $booksellers[0]->{'discount'},
                loop_pricescurrency  => \@loop_pricescurrency,
                loop_invoicecurrency => \@loop_invoicecurrency,
@@ -156,4 +174,7 @@ elsif ($op eq 'delete') {
                enter                => 1,
        );
 }
+
+
+
 output_html_with_http_headers $query, $cookie, $template->output;