Bug 14931: (qa followu-up) small improvements
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 28 Oct 2015 08:41:19 +0000 (08:41 +0000)
committerTomas Cohen Arazi <tomascohen@theke.io>
Thu, 29 Oct 2015 15:00:42 +0000 (12:00 -0300)
- Avoid 1 call to dt_from_string in some cases
- Do not use $_

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
admin/aqcontract.pl

index 8f6bf30..a191cd8 100755 (executable)
@@ -94,10 +94,12 @@ elsif ( $op eq 'add_validate' ) {
     my $is_a_modif = $input->param("is_a_modif");
 
     my $contractstart_dt = eval { dt_from_string( $input->param('contractstartdate') ); };
-    $contractstart_dt = dt_from_string if ( ! $contractstart_dt );
-
     my $contractend_dt = eval { dt_from_string( $input->param('contractenddate') ); };
-    $contractend_dt = dt_from_string if ( ! $contractend_dt );
+    unless ( $contractstart_dt and $contractend_dt ) {
+        my $today = dt_from_string;
+        $contractstart_dt ||= $today;
+        $contractend_dt   ||= $today;
+    }
 
     if ( $is_a_modif ) {
         ModContract({
@@ -161,9 +163,9 @@ if ( $op eq 'list' ) {
     my @contracts = @{GetContracts( { booksellerid => $booksellerid } )};
 
     # format dates
-    for ( @contracts ) {
-        $$_{contractstartdate} =  output_pref({ dt => dt_from_string( $$_{contractstartdate} ), dateonly => 1 });
-        $$_{contractenddate}   =  output_pref({ dt => dt_from_string( $$_{contractenddate} ), dateonly => 1 }),
+    for my $contract ( @contracts ) {
+        $contract->{contractstartdate} =  output_pref({ dt => dt_from_string( $contract->{contractstartdate} ), dateonly => 1 });
+        $contract->{contractenddate}   =  output_pref({ dt => dt_from_string( $contract->{contractenddate} ), dateonly => 1 }),
     }
 
     $template->param(loop => \@contracts);