]> wagnertech.de Git - mfinanz.git/blobdiff - bin/mozilla/ir.pl
Änderungen zum vorherigen Commit, um die Funktionen rouster zu machen.
[mfinanz.git] / bin / mozilla / ir.pl
index f7dcd6af5538f89407bee08ee3de01dd615dabe4..f43ed775ca9db27ac4b98b03fc3d15c493448eb2 100644 (file)
@@ -145,6 +145,12 @@ sub invoice_links {
 
   $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
 
+  # build vendor/customer drop down comatibility... don't ask
+  if (@{ $form->{"all_vendor"} || [] }) {
+    $form->{"selectvendor"} = 1;
+    $form->{vendor}         = qq|$form->{vendor}--$form->{vendor_id}|;
+  }
+
   # departments
   if ($form->{all_departments}) {
     $form->{selectdepartment} = "<option>\n";
@@ -153,7 +159,7 @@ sub invoice_links {
     map {
       $form->{selectdepartment} .=
         "<option>$_->{description}--$_->{id}\n"
-    } (@{ $form->{all_departments} });
+    } (@{ $form->{all_departments} || [] });
   }
 
   # forex
@@ -166,6 +172,8 @@ sub invoice_links {
       $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
     }
 
+    next unless $form->{acc_trans}{$key};
+
     if ($key eq "AP_paid") {
       for my $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
         $form->{"AP_paid_$i"} =
@@ -1134,6 +1142,19 @@ sub post_payment {
   $main::lxdebug->leave_sub();
 }
 
+sub _max_datepaid {
+  my $form  =  $main::form;
+
+  my @dates = sort { $b->[1] cmp $a->[1] }
+              map  { [ $_, $main::locale->reformat_date(\%main::myconfig, $_, 'yyyy-mm-dd') ] }
+              grep { $_ }
+              map  { $form->{"datepaid_${_}"} }
+              (1..$form->{rowcount});
+
+  return @dates ? $dates[0]->[0] : undef;
+}
+
+
 sub post {
   $main::lxdebug->enter_sub();
 
@@ -1160,16 +1181,16 @@ sub post {
 
   &validate_items;
 
-  my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
-  my $invdate  = $form->datetonum($form->{invdate},  \%myconfig);
-  my $i        = $form->{rowcount};
+  my $closedto     = $form->datetonum($form->{closedto}, \%myconfig);
+  my $invdate      = $form->datetonum($form->{invdate},  \%myconfig);
+  my $max_datepaid = _max_datepaid();
 
-  $form->error($locale->text('Cannot post invoice for a closed period!'))
-    if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
+  $form->error($locale->text('Cannot post invoice for a closed period!')) if $max_datepaid && $form->date_closed($max_datepaid, \%myconfig);
 
   $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
     if ($form->{currency} ne $form->{defaultcurrency});
 
+  my $i;
   for $i (1 .. $form->{paidaccounts}) {
     if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
       my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);