Debugmeldungen...
[kivitendo-erp.git] / bin / mozilla / ar.pl
index 3b45404..4634cb1 100644 (file)
@@ -79,6 +79,7 @@ sub add {
     unless $form->{callback};
 
   &create_links;
+  AR->get_transdate(\%myconfig, $form);
   &display_form;
 
   $lxdebug->leave_sub();
@@ -291,6 +292,8 @@ sub create_links {
     ($form->datetonum($form->{transdate}, \%myconfig) <=
      $form->datetonum($form->{closedto}, \%myconfig));
 
+  $form->{"ARselected"} = $form->{"AR_1"};
+
   $lxdebug->leave_sub();
 }
 
@@ -330,6 +333,11 @@ sub form_header {
     ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
   $readonly = ($form->{radier}) ? "" : $readonly;
 
+  my $ARselected_quoted = quotemeta($form->{"ARselected"});
+  $form->{selectAR} = $form->{AR};
+  $form->{selectAR} =~
+    s/value=\"${ARselected_quoted}\"/value=\"$form->{ARselected}\" selected/;
+
   # set option selected
   foreach $item (qw(customer currency department employee)) {
     $form->{"select$item"} =~ s/ selected//;
@@ -654,6 +662,7 @@ $jsscript
         </tr>
 ";
 
+  my @triggers = ();
   $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
   for $i (1 .. $form->{paidaccounts}) {
     print "
@@ -693,7 +702,8 @@ $jsscript
       qq|<td align=center><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
     $column_data{exchangerate} = qq|<td align=center>$exchangerate</td>|;
     $column_data{datepaid}     =
-      qq|<td align=center><input name="datepaid_$i" size=11 value=$form->{"datepaid_$i"}></td>|;
+      qq|<td align=center><input name="datepaid_$i" id="datepaid_$i" size=11 value=$form->{"datepaid_$i"}>
+         <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
     $column_data{source} =
       qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
     $column_data{memo} =
@@ -704,9 +714,12 @@ $jsscript
     print "
         </tr>
 ";
+    push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
   }
   map { $form->{$_} =~ s/\"/&quot;/g } qw(selectAR_paid);
-  print qq|
+
+  print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
+    qq|
 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
 <input type=hidden name=selectAR_paid value="$form->{selectAR_paid}">
 
@@ -758,6 +771,10 @@ sub form_footer {
           . $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) {
@@ -768,11 +785,6 @@ sub form_footer {
     }
   }
 
-  if ($form->{menubar}) {
-    require "$form->{path}/menu.pl";
-    &menubar;
-  }
-
   print "
 </form>
 
@@ -798,11 +810,6 @@ sub update {
   #   $form->{selectAR_amount} =~
   #     s/value=\"$form->{AR_amountselected}\"/value=\"$form->{AR_amountselected}\" selected/;
 
-  $form->{selectAR} = $form->{AR};
-
-  $form->{selectAR} =~
-    s/value=\"$form->{ARselected}\"/value=\"$form->{ARselected}\" selected/;
-
   ($AR_amountaccno, $AR_amounttaxkey) =
     split(/--/, $form->{AR_amountselected});
   $form->{selecttaxchart} = $form->{taxchart};
@@ -897,6 +904,36 @@ 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->{AR})      = split /--/, $form->{AR};
+  ($form->{AR_paid}) = split /--/, $form->{AR_paid};
+  $form->redirect($locale->text(' Payment posted!'))
+      if (AR->post_payment(\%myconfig, \%$form));
+    $form->error($locale->text('Cannot post payment!'));
+
+
+  $lxdebug->leave_sub();
+}
+
 sub post {
   $lxdebug->enter_sub();
 
@@ -1535,14 +1572,8 @@ sub ar_transactions {
 <input class=submit type=submit name=action value="|
     . $locale->text('AR Transaction') . qq|">
 <input class=submit type=submit name=action value="|
-    . $locale->text('Sales Invoice') . qq|">|;
+    . $locale->text('Sales Invoice') . qq|">
 
-  if ($form->{menubar}) {
-    require "$form->{path}/menu.pl";
-    &menubar;
-  }
-
-  print qq|
 </form>
 
 </body>