use Data::Dumper;
use SL::DBUtils;
+use SL::IO;
use SL::MoreCommon;
use strict;
-our (%myconfig, $form);
-
sub post_transaction {
$main::lxdebug->enter_sub();
($null, $form->{department_id}) = split(/--/, $form->{department});
$form->{department_id} *= 1;
- # record last payment date in ar table
- $form->{datepaid} ||= $form->{transdate} ;
- my $datepaid = ($form->{paid} != 0) ? $form->{datepaid} : undef;
-
# amount for AR account
$form->{receivables} = $form->round_amount($form->{amount}, 2) * -1;
$query =
qq|UPDATE ar set
invnumber = ?, ordnumber = ?, transdate = ?, customer_id = ?,
- taxincluded = ?, amount = ?, duedate = ?, paid = ?, datepaid = ?,
+ taxincluded = ?, amount = ?, duedate = ?, paid = ?,
netamount = ?, curr = ?, notes = ?, department_id = ?,
employee_id = ?, storno = ?, storno_id = ?
WHERE id = ?|;
my @values = ($form->{invnumber}, $form->{ordnumber}, conv_date($form->{transdate}), conv_i($form->{customer_id}), $form->{taxincluded} ? 't' : 'f', $form->{amount},
- conv_date($form->{duedate}), $form->{paid}, conv_date($datepaid), $form->{netamount}, $form->{currency}, $form->{notes}, conv_i($form->{department_id}),
+ conv_date($form->{duedate}), $form->{paid}, $form->{netamount}, $form->{currency}, $form->{notes}, conv_i($form->{department_id}),
conv_i($form->{employee_id}), $form->{storno} ? 't' : 'f', $form->{storno_id}, conv_i($form->{id}));
do_query($form, $dbh, $query, @values);
}
}
+ IO->set_datepaid(table => 'ar', id => $form->{id}, dbh => $dbh);
+
my $rc = 1;
if (!$provided_dbh) {
$rc = $dbh->commit();
my ($self, $form) = @_;
- my ($exchangerate, $key, $akey, $i, $j, $k, $index, $taxamount, $totaltax, $taxrate, $diff, $totalwithholding, $withholdingrate,
+ my ($exchangerate, $akey, $j, $k, $index, $taxamount, $totaltax, $taxrate, $diff, $totalwithholding, $withholdingrate,
$totalamount, $taxincluded, $tax);
# forex
$form->{forex} = $form->{exchangerate};
$exchangerate = $form->{exchangerate} ? $form->{exchangerate} : 1;
- foreach $key (keys %{ $form->{AR_links} }) {
+ foreach my $key (keys %{ $form->{AR_links} }) {
# if there is a value we have an old entry
$j = 0;
$k = 0;
- for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
+ next unless $form->{acc_trans}{$key};
+
+ for my $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
if ($key eq "AR_paid") {
$j++;
$form->{"AR_paid_$j"} = $form->{acc_trans}{$key}->[$i-1]->{accno};
if ($form->{taxincluded} && $form->{taxrate} && $totalamount) {
# add tax to amounts and invtotal
- for $i (1 .. $form->{rowcount}) {
+ for my $i (1 .. $form->{rowcount}) {
$taxamount = ($totaltax + $totalwithholding) * $form->{"amount_$i"} / $totalamount;
$tax = $form->round_amount($taxamount, 2);
$diff += ($taxamount - $tax);
do_query($form, $dbh, $query, (values %$row));
}
+ map { IO->set_datepaid(table => 'ap', id => $_, dbh => $dbh) } ($id, $new_id);
+
$dbh->commit;
$main::lxdebug->leave_sub();