From: Philip Reetz
Date: Thu, 1 Feb 2007 11:05:22 +0000 (+0000)
Subject: Bei Kreditoren- und Debitorenbuchungen eine Funktion zum spaeteren Buchen eines Zahlu...
X-Git-Tag: release-2.4.2~190
X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=bdaa8c2f669c9ddcc2f0c8989fed52559d59be43;p=kivitendo-erp.git
Bei Kreditoren- und Debitorenbuchungen eine Funktion zum spaeteren Buchen eines Zahlungseingangs
hinzugefuegt
---
diff --git a/SL/AP.pm b/SL/AP.pm
index 072c66529..5dfe2362d 100644
--- 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;
diff --git a/SL/AR.pm b/SL/AR.pm
index 5edd4161a..65eb3f03c 100644
--- 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();
diff --git a/bin/mozilla/ap.pl b/bin/mozilla/ap.pl
index 7b09f2f0a..5a633e1eb 100644
--- a/bin/mozilla/ap.pl
+++ b/bin/mozilla/ap.pl
@@ -748,7 +748,10 @@ sub form_footer {
|;
-
+ print qq|
+
+|;
} else {
if (($transdate > $closedto) && !$form->{id}) {
print qq|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();
diff --git a/bin/mozilla/ar.pl b/bin/mozilla/ar.pl
index 5b0273eed..90294c146 100644
--- a/bin/mozilla/ar.pl
+++ b/bin/mozilla/ar.pl
@@ -771,6 +771,10 @@ sub form_footer {
. $locale->text('Use As Template') . qq|">
|;
}
+ print 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();
diff --git a/locale/de/all b/locale/de/all
index 6e15be25b..ef1d70f70 100644
--- a/locale/de/all
+++ b/locale/de/all
@@ -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 contained the following error:' => 'Die Datenbankaktualisierung/erstellung schlug fehl. Die Datei enthielt den folgenden Fehler:',
'The database upgrade for the introduction of Buchungsgruppen is now complete.' => 'Das Datenbankupgrade für die Einführung von Buchungsgruppen ist jetzt beendet.',
'The database upgrade for the introduction of units is now complete.' => 'Das Datenbankupgrade zwecks Einfü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',
diff --git a/locale/de/ap b/locale/de/ap
index 54a296e4f..194ece44c 100644
--- a/locale/de/ap
+++ b/locale/de/ap
@@ -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',
diff --git a/locale/de/ar b/locale/de/ar
index f4a1b5c86..11f3bc202 100644
--- a/locale/de/ar
+++ b/locale/de/ar
@@ -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',