Syntaxhighlighting für Emacs.
[kivitendo-erp.git] / bin / mozilla / ap.pl
index 2f31a59..2cfff88 100644 (file)
@@ -279,6 +279,8 @@ sub create_links {
     ($form->datetonum($form->{transdate}, \%myconfig) <=
      $form->datetonum($form->{closedto}, \%myconfig));
 
+  $form->{"APselected"} = $form->{"AP_1"};
+
   $lxdebug->leave_sub();
 }
 
@@ -321,6 +323,11 @@ sub form_header {
   }
   $readonly = ($form->{id}) ? "readonly" : "";
 
+  my $APselected_quoted = quotemeta($form->{"APselected"});
+  $form->{selectAP} = $form->{AP};
+  $form->{selectAP} =~
+    s/value=\"${APselected_quoted}\"/value=\"$form->{APselected}\" selected/;
+
   $form->{radier} =
     ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
   $readonly                 = ($form->{radier}) ? "" : $readonly;
@@ -675,7 +682,7 @@ $jsscript
       qq|<td align=center><select name="AP_paid_$i">$form->{"selectAP_paid_$i"}</select></td>|;
     $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
     $column_data{"datepaid_$i"}     =
-      qq|<td align=center><input name="datepaid_$i" size=11 title="($myconfig{'dateformat'})" value=$form->{"datepaid_$i"}>
+      qq|<td align=center><input name="datepaid_$i" id="datepaid_$i" size=11 title="($myconfig{'dateformat'})" value=$form->{"datepaid_$i"}>
          <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
     $column_data{"source_$i"} =
       qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
@@ -741,7 +748,10 @@ sub form_footer {
 <input class=submit type=submit name=action value="|
         . $locale->text('Use As Template') . qq|">
 |;
+      print qq|
+<input class=submit type=submit name=action value="|
+        . $locale->text('Post Payment') . qq|">
+|;
   } else {
     if (($transdate > $closedto) && !$form->{id}) {
       print qq|<input class=submit type=submit name=action value="|
@@ -776,10 +786,6 @@ sub update {
   #   $form->{selectAP_amount} =~
   #     s/value=\"$form->{AP_amountselected}\"/value=\"$form->{AP_amountselected}\" selected/;
 
-  $form->{selectAP} = $form->{AP};
-  $form->{selectAP} =~
-    s/value=\"$form->{APselected}\"/value=\"$form->{APselected}\" selected/;
-
   ($AP_amountaccno, $AP_amounttaxkey) =
     split(/--/, $form->{AP_amountselected});
   $form->{selecttaxchart} = $form->{taxchart};
@@ -872,6 +878,38 @@ sub update {
   $lxdebug->leave_sub();
 }
 
+
+sub post_payment {
+  $lxdebug->enter_sub();
+  for $i (1 .. $form->{paidaccounts}) {
+    if ($form->{"paid_$i"}) {
+      $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
+
+      $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
+
+      $form->error($locale->text('Cannot post payment for a closed period!'))
+        if ($datepaid <= $closedto);
+
+      if ($form->{currency} ne $form->{defaultcurrency}) {
+        $form->{"exchangerate_$i"} = $form->{exchangerate}
+          if ($invdate == $datepaid);
+        $form->isblank("exchangerate_$i",
+                       $locale->text('Exchangerate for payment missing!'));
+      }
+    }
+  }
+
+  ($form->{AP})      = split /--/, $form->{AP};
+  ($form->{AP_paid}) = split /--/, $form->{AP_paid};
+  $form->redirect($locale->text(' Payment posted!'))
+      if (AP->post_payment(\%myconfig, \%$form));
+    $form->error($locale->text('Cannot post payment!'));
+
+
+  $lxdebug->leave_sub();
+}
+
+
 sub post {
   $lxdebug->enter_sub();