$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;
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();
<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="|
$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();
. $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) {
$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();
'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',
'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ü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.',
'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',
$self->{texts} = {
+ ' Payment posted!' => 'Zahlung gebucht!',
'AP Transaction' => 'Kreditorenbuchung',
'AP Transactions' => 'Kreditorenbuchungen',
'Account' => 'Konto',
'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',
'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',
'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',
'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',
$self->{texts} = {
+ ' Payment posted!' => 'Zahlung gebucht!',
'AR Transaction' => 'Debitorenbuchung',
'AR Transactions' => 'Debitorenbuchungen',
'Account' => 'Konto',
'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',
'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',
'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',
'weiter' => 'continue',
'löschen' => 'delete',
'buchen' => 'post',
+ 'zahlung_buchen' => 'post_payment',
'rechnung' => 'sales_invoice',
'erneuern' => 'update',
'als_vorlage_verwenden' => 'use_as_template',