Bei Kreditoren- und Debitorenbuchungen eine Funktion zum spaeteren Buchen eines Zahlu...
authorPhilip Reetz <p.reetz@linet-services.de>
Thu, 1 Feb 2007 11:05:22 +0000 (11:05 +0000)
committerPhilip Reetz <p.reetz@linet-services.de>
Thu, 1 Feb 2007 11:05:22 +0000 (11:05 +0000)
hinzugefuegt

SL/AP.pm
SL/AR.pm
bin/mozilla/ap.pl
bin/mozilla/ar.pl
locale/de/all
locale/de/ap
locale/de/ar

index 072c665..5dfe236 100644 (file)
--- a/SL/AP.pm
+++ b/SL/AP.pm
@@ -490,5 +490,144 @@ sub get_transdate {
   $main::lxdebug->leave_sub();
 }
 
+
+sub post_payment {
+  $main::lxdebug->enter_sub();
+
+  my ($self, $myconfig, $form, $locale) = @_;
+
+  # connect to database, turn off autocommit
+  my $dbh = $form->dbconnect_noauto($myconfig);
+
+  $form->{datepaid} = $form->{invdate};
+
+  # total payments, don't move we need it here
+  for my $i (1 .. $form->{paidaccounts}) {
+    $form->{"paid_$i"} = $form->parse_amount($myconfig, $form->{"paid_$i"});
+    $form->{paid} += $form->{"paid_$i"};
+    $form->{datepaid} = $form->{"datepaid_$i"} if ($form->{"datepaid_$i"});
+  }
+
+  $form->{exchangerate} =
+      $form->get_exchangerate($dbh, $form->{currency}, $form->{invdate},
+                              "buy");
+
+  # record payments and offsetting AP
+  for my $i (1 .. $form->{paidaccounts}) {
+
+    if ($form->{"paid_$i"} != 0) {
+      my ($accno) = split /--/, $form->{"AP_paid_$i"};
+      $form->{"datepaid_$i"} = $form->{invdate}
+        unless ($form->{"datepaid_$i"});
+      $form->{datepaid} = $form->{"datepaid_$i"};
+
+      $exchangerate = 0;
+      if (($form->{currency} eq $form->{defaultcurrency}) || ($form->{defaultcurrency} eq "")) {
+        $form->{"exchangerate_$i"} = 1;
+      } else {
+        $exchangerate =
+          $form->check_exchangerate($myconfig, $form->{currency},
+                                    $form->{"datepaid_$i"}, 'buy');
+
+        $form->{"exchangerate_$i"} =
+          ($exchangerate)
+          ? $exchangerate
+          : $form->parse_amount($myconfig, $form->{"exchangerate_$i"});
+      }
+
+      # record AP
+      $amount =
+        $form->round_amount($form->{"paid_$i"} * $form->{"exchangerate"},
+                            2) * -1;
+
+
+      $query = qq|DELETE FROM acc_trans WHERE trans_id=$form->{id} AND chart_id=(SELECT c.id FROM chart c
+                                      WHERE c.accno = '$form->{AP}') AND amount=$amount AND transdate='$form->{"datepaid_$i"}'|;
+      $dbh->do($query) || $form->dberror($query);
+
+      $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount,
+                  transdate)
+                  VALUES ($form->{id}, (SELECT c.id FROM chart c
+                                      WHERE c.accno = '$form->{AP}'),
+                  $amount, '$form->{"datepaid_$i"}')|;
+      $dbh->do($query) || $form->dberror($query);
+
+
+
+      $query = qq|DELETE FROM acc_trans WHERE trans_id=$form->{id} AND chart_id=(SELECT c.id FROM chart c
+                                      WHERE c.accno = '$accno') AND amount=$form->{"paid_$i"} AND transdate='$form->{"datepaid_$i"}' AND source='$form->{"source_$i"}' AND memo='$form->{"memo_$i"}'|;
+      $dbh->do($query) || $form->dberror($query);
+
+      $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate,
+                  source, memo)
+                  VALUES ($form->{id}, (SELECT c.id FROM chart c
+                                     WHERE c.accno = '$accno'),
+                 $form->{"paid_$i"}, '$form->{"datepaid_$i"}',
+                 '$form->{"source_$i"}', '$form->{"memo_$i"}')|;
+      $dbh->do($query) || $form->dberror($query);
+
+
+      # gain/loss
+      $amount =
+        $form->{"paid_$i"} * $form->{exchangerate} - $form->{"paid_$i"} *
+        $form->{"exchangerate_$i"};
+      if ($amount > 0) {
+        $form->{fx}{ $form->{fxgain_accno} }{ $form->{"datepaid_$i"} } +=
+          $amount;
+      } else {
+        $form->{fx}{ $form->{fxloss_accno} }{ $form->{"datepaid_$i"} } +=
+          $amount;
+      }
+
+      $diff = 0;
+
+      # update exchange rate
+      if (($form->{currency} ne $form->{defaultcurrency}) && !$exchangerate) {
+        $form->update_exchangerate($dbh, $form->{currency},
+                                   $form->{"datepaid_$i"},
+                                   $form->{"exchangerate_$i"}, 0);
+      }
+    }
+  }
+
+  # record exchange rate differences and gains/losses
+  foreach my $accno (keys %{ $form->{fx} }) {
+    foreach my $transdate (keys %{ $form->{fx}{$accno} }) {
+      if (
+          ($form->{fx}{$accno}{$transdate} =
+           $form->round_amount($form->{fx}{$accno}{$transdate}, 2)
+          ) != 0
+        ) {
+        $query = qq|DELETE FROM acc_trans WHERE trans_id=$form->{id} AND chart_id=(SELECT c.id FROM chart c
+                                        WHERE c.accno = '$accno') AND amount=$form->{fx}{$accno}{$transdate} AND transdate='$transdate' AND cleared='0' AND fx_transaction='1'|;
+        $dbh->do($query) || $form->dberror($query);
+        $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount,
+                   transdate, cleared, fx_transaction)
+                   VALUES ($form->{id},
+                          (SELECT c.id FROM chart c
+                           WHERE c.accno = '$accno'),
+                   $form->{fx}{$accno}{$transdate}, '$transdate', '0', '1')|;
+        $dbh->do($query) || $form->dberror($query);
+      }
+    }
+  }
+  my $datepaid = ($form->{paid})    ? qq|'$form->{datepaid}'| : "NULL";
+
+  # save AP record
+  my $query = qq|UPDATE ap set
+              paid = $form->{paid},
+             datepaid = $datepaid
+              WHERE id=$form->{id}|;
+
+  $dbh->do($query) || $form->dberror($query);
+
+  my $rc = $dbh->commit;
+  $dbh->disconnect;
+
+  $main::lxdebug->leave_sub();
+
+  return $rc;
+}
+
 1;
 
index 5edd416..65eb3f0 100644 (file)
--- a/SL/AR.pm
+++ b/SL/AR.pm
@@ -377,6 +377,150 @@ sub post_transaction {
   return $rc;
 }
 
+sub post_payment {
+  $main::lxdebug->enter_sub();
+
+  my ($self, $myconfig, $form, $locale) = @_;
+
+  # connect to database, turn off autocommit
+  my $dbh = $form->dbconnect_noauto($myconfig);
+
+  $form->{datepaid} = $form->{invdate};
+
+  # total payments, don't move we need it here
+  for my $i (1 .. $form->{paidaccounts}) {
+    if ($form->{type} eq "credit_note") {
+      $form->{"paid_$i"} = $form->parse_amount($myconfig, $form->{"paid_$i"}) * -1;
+    } else {
+      $form->{"paid_$i"} = $form->parse_amount($myconfig, $form->{"paid_$i"});
+    } 
+    $form->{paid} += $form->{"paid_$i"};
+    $form->{datepaid} = $form->{"datepaid_$i"} if ($form->{"datepaid_$i"});
+  }
+
+  $form->{exchangerate} =
+      $form->get_exchangerate($dbh, $form->{currency}, $form->{invdate},
+                              "buy");
+
+  # record payments and offsetting AR
+  for my $i (1 .. $form->{paidaccounts}) {
+
+    if ($form->{"paid_$i"} != 0) {
+      my ($accno) = split /--/, $form->{"AR_paid_$i"};
+      $form->{"datepaid_$i"} = $form->{invdate}
+        unless ($form->{"datepaid_$i"});
+      $form->{datepaid} = $form->{"datepaid_$i"};
+
+      $exchangerate = 0;
+      if (($form->{currency} eq $form->{defaultcurrency}) || ($form->{defaultcurrency} eq "")) {
+        $form->{"exchangerate_$i"} = 1;
+      } else {
+        $exchangerate =
+          $form->check_exchangerate($myconfig, $form->{currency},
+                                    $form->{"datepaid_$i"}, 'buy');
+
+        $form->{"exchangerate_$i"} =
+          ($exchangerate)
+          ? $exchangerate
+          : $form->parse_amount($myconfig, $form->{"exchangerate_$i"});
+      }
+
+      # record AR
+      $amount =
+        $form->round_amount($form->{"paid_$i"} * $form->{"exchangerate"},
+                            2);
+
+
+      $query = qq|DELETE FROM acc_trans WHERE trans_id=$form->{id} AND chart_id=(SELECT c.id FROM chart c
+                                      WHERE c.accno = '$form->{AR}') AND amount=$amount AND transdate='$form->{"datepaid_$i"}'|;
+      $dbh->do($query) || $form->dberror($query);
+
+      $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount,
+                  transdate)
+                  VALUES ($form->{id}, (SELECT c.id FROM chart c
+                                      WHERE c.accno = '$form->{AR}'),
+                  $amount, '$form->{"datepaid_$i"}')|;
+      $dbh->do($query) || $form->dberror($query);
+
+
+      # record payment
+      $form->{"paid_$i"} *= -1;
+
+      $query = qq|DELETE FROM acc_trans WHERE trans_id=$form->{id} AND chart_id=(SELECT c.id FROM chart c
+                                      WHERE c.accno = '$accno') AND amount=$form->{"paid_$i"} AND transdate='$form->{"datepaid_$i"}' AND source='$form->{"source_$i"}' AND memo='$form->{"memo_$i"}'|;
+      $dbh->do($query) || $form->dberror($query);
+
+      $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate,
+                  source, memo)
+                  VALUES ($form->{id}, (SELECT c.id FROM chart c
+                                     WHERE c.accno = '$accno'),
+                 $form->{"paid_$i"}, '$form->{"datepaid_$i"}',
+                 '$form->{"source_$i"}', '$form->{"memo_$i"}')|;
+      $dbh->do($query) || $form->dberror($query);
+
+
+      # gain/loss
+      $amount =
+        $form->{"paid_$i"} * $form->{exchangerate} - $form->{"paid_$i"} *
+        $form->{"exchangerate_$i"};
+      if ($amount > 0) {
+        $form->{fx}{ $form->{fxgain_accno} }{ $form->{"datepaid_$i"} } +=
+          $amount;
+      } else {
+        $form->{fx}{ $form->{fxloss_accno} }{ $form->{"datepaid_$i"} } +=
+          $amount;
+      }
+
+      $diff = 0;
+
+      # update exchange rate
+      if (($form->{currency} ne $form->{defaultcurrency}) && !$exchangerate) {
+        $form->update_exchangerate($dbh, $form->{currency},
+                                   $form->{"datepaid_$i"},
+                                   $form->{"exchangerate_$i"}, 0);
+      }
+    }
+  }
+
+  # record exchange rate differences and gains/losses
+  foreach my $accno (keys %{ $form->{fx} }) {
+    foreach my $transdate (keys %{ $form->{fx}{$accno} }) {
+      if (
+          ($form->{fx}{$accno}{$transdate} =
+           $form->round_amount($form->{fx}{$accno}{$transdate}, 2)
+          ) != 0
+        ) {
+        $query = qq|DELETE FROM acc_trans WHERE trans_id=$form->{id} AND chart_id=(SELECT c.id FROM chart c
+                                        WHERE c.accno = '$accno') AND amount=$form->{fx}{$accno}{$transdate} AND transdate='$transdate' AND cleared='0' AND fx_transaction='1'|;
+        $dbh->do($query) || $form->dberror($query);
+        $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount,
+                   transdate, cleared, fx_transaction)
+                   VALUES ($form->{id},
+                          (SELECT c.id FROM chart c
+                           WHERE c.accno = '$accno'),
+                   $form->{fx}{$accno}{$transdate}, '$transdate', '0', '1')|;
+        $dbh->do($query) || $form->dberror($query);
+      }
+    }
+  }
+  my $datepaid = ($form->{paid})    ? qq|'$form->{datepaid}'| : "NULL";
+
+  # save AR record
+  my $query = qq|UPDATE ar set
+              paid = $form->{paid},
+             datepaid = $datepaid
+              WHERE id=$form->{id}|;
+
+  $dbh->do($query) || $form->dberror($query);
+
+  my $rc = $dbh->commit;
+  $dbh->disconnect;
+
+  $main::lxdebug->leave_sub();
+
+  return $rc;
+}
+
 sub delete_transaction {
   $main::lxdebug->enter_sub();
 
index 7b09f2f..5a633e1 100644 (file)
@@ -748,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="|
@@ -875,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();
 
index 5b0273e..90294c1 100644 (file)
@@ -771,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) {
@@ -900,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();
 
index 6e15be2..ef1d70f 100644 (file)
@@ -923,6 +923,7 @@ gestartet',
   'Step 2 of 3: Services'       => 'Schritt 2 von 3: Dienstleistungen',
   'Step 3 of 3: Assemblies'     => 'Schritt 3 von 3: Erzeugnisse',
   'Step 3 of 3: Default units'  => 'Schritt 3 von 3: Standardeinheiten',
+  'Steuernummer'                => '',
   'Steuersatz'                  => 'Steuersatz',
   'Stock'                       => 'einlagern',
   'Stock Assembly'              => 'Erzeugnis einlagern',
@@ -969,6 +970,7 @@ gestartet',
   'The database update/creation did not succeed. The file <TMPL_VAR file ESCAPE=HTML> contained the following error:' => 'Die Datenbankaktualisierung/erstellung schlug fehl. Die Datei <TMPL_VAR file ESCAPE=HTML> enthielt den folgenden Fehler:',
   'The database upgrade for the introduction of Buchungsgruppen is now complete.' => 'Das Datenbankupgrade f&uuml;r die Einf&uuml;hrung von Buchungsgruppen ist jetzt beendet.',
   'The database upgrade for the introduction of units is now complete.' => 'Das Datenbankupgrade zwecks Einf&uuml;hrung von Einheiten ist nun beendet.',
+  'The dunning process is started' => '',
   'The dunning process started' => 'Der Mahnprozess ist gestartet.',
   'The factor is missing in row %d.' => 'Der Faktor fehlt in Zeile %d.',
   'The factor is missing.'      => 'Der Faktor fehlt.',
@@ -1117,6 +1119,7 @@ gestartet',
   'Warehouses'                  => 'Lager',
   'Warnings during template upgrade' => 'Warnungen bei Aktualisierung der Dokumentenvorlagen',
   'Weight'                      => 'Gewicht',
+  'Weight Unit'                 => '',
   'What type of item is this?'  => 'Was ist dieser Artikel?',
   'With Extension Of Time'      => 'mit Dauerfristverlängerung',
   'Workflow purchase_order'     => 'Workflow Lieferantenauftrag',
index 54a296e..194ece4 100644 (file)
@@ -1,4 +1,5 @@
 $self->{texts} = {
+  ' Payment posted!'            => 'Zahlung gebucht!',
   'AP Transaction'              => 'Kreditorenbuchung',
   'AP Transactions'             => 'Kreditorenbuchungen',
   'Account'                     => 'Konto',
@@ -14,6 +15,7 @@ $self->{texts} = {
   'Bis'                         => 'bis',
   'Cannot delete transaction!'  => 'Buchung kann nicht gelöscht werden!',
   'Cannot post payment for a closed period!' => 'Es können keine Zahlungen für abgeschlossene Bücher gebucht werden!',
+  'Cannot post payment!'        => 'Zahlung kann nicht gebucht werden!',
   'Cannot post transaction for a closed period!' => 'Für einen bereits abgeschlossenen Zeitraum kann keine Buchung angelegt werden!',
   'Cannot post transaction!'    => 'Rechnung kann nicht gebucht werden!',
   'Closed'                      => 'Geschlossen',
@@ -71,6 +73,7 @@ $self->{texts} = {
   'Payment date missing!'       => 'Tag der Zahlung fehlt!',
   'Payments'                    => 'Zahlungsausgänge',
   'Post'                        => 'Buchen',
+  'Post Payment'                => 'Zahlung buchen',
   'Project'                     => 'Projekt',
   'Project not on file!'        => 'Dieses Projekt ist nicht in der Datenbank!',
   'Remaining'                   => 'Rest',
@@ -116,6 +119,7 @@ $self->{subs} = {
   'name_selected'               => 'name_selected',
   'post'                        => 'post',
   'post_as_new'                 => 'post_as_new',
+  'post_payment'                => 'post_payment',
   'project_selected'            => 'project_selected',
   'sales_invoice'               => 'sales_invoice',
   'search'                      => 'search',
@@ -131,6 +135,7 @@ $self->{subs} = {
   'löschen'                     => 'delete',
   'kreditorenbuchung_bearbeiten' => 'edit_accounts_payables_transaction',
   'buchen'                      => 'post',
+  'zahlung_buchen'              => 'post_payment',
   'erneuern'                    => 'update',
   'als_vorlage_verwenden'       => 'use_as_template',
   'einkaufsrechnung'            => 'vendor_invoice',
index f4a1b5c..11f3bc2 100644 (file)
@@ -1,4 +1,5 @@
 $self->{texts} = {
+  ' Payment posted!'            => 'Zahlung gebucht!',
   'AR Transaction'              => 'Debitorenbuchung',
   'AR Transactions'             => 'Debitorenbuchungen',
   'Account'                     => 'Konto',
@@ -14,6 +15,7 @@ $self->{texts} = {
   'Bis'                         => 'bis',
   'Cannot delete transaction!'  => 'Buchung kann nicht gelöscht werden!',
   'Cannot post payment for a closed period!' => 'Es können keine Zahlungen für abgeschlossene Bücher gebucht werden!',
+  'Cannot post payment!'        => 'Zahlung kann nicht gebucht werden!',
   'Cannot post transaction for a closed period!' => 'Für einen bereits abgeschlossenen Zeitraum kann keine Buchung angelegt werden!',
   'Cannot post transaction!'    => 'Rechnung kann nicht gebucht werden!',
   'Closed'                      => 'Geschlossen',
@@ -74,6 +76,7 @@ $self->{texts} = {
   'Paid'                        => 'bezahlt',
   'Payment date missing!'       => 'Tag der Zahlung fehlt!',
   'Post'                        => 'Buchen',
+  'Post Payment'                => 'Zahlung buchen',
   'Project'                     => 'Projekt',
   'Project not on file!'        => 'Dieses Projekt ist nicht in der Datenbank!',
   'Remaining'                   => 'Rest',
@@ -122,6 +125,7 @@ $self->{subs} = {
   'name_selected'               => 'name_selected',
   'post'                        => 'post',
   'post_as_new'                 => 'post_as_new',
+  'post_payment'                => 'post_payment',
   'project_selected'            => 'project_selected',
   'sales_invoice'               => 'sales_invoice',
   'search'                      => 'search',
@@ -135,6 +139,7 @@ $self->{subs} = {
   'weiter'                      => 'continue',
   'löschen'                     => 'delete',
   'buchen'                      => 'post',
+  'zahlung_buchen'              => 'post_payment',
   'rechnung'                    => 'sales_invoice',
   'erneuern'                    => 'update',
   'als_vorlage_verwenden'       => 'use_as_template',