package AR;
use Data::Dumper;
+use SL::DBUtils;
sub post_transaction {
$main::lxdebug->enter_sub();
my $exchangerate = 0;
my $i;
+ my @values;
+
my $dbh = $form->dbconnect_noauto($myconfig);
if ($form->{currency} eq $form->{defaultcurrency}) {
# add individual transactions for AR, amount and taxes
for $i (1 .. $form->{rowcount}) {
if ($form->{"amount_$i"} != 0) {
- $project_id = 'NULL';
- if ("amount_$i" =~ /amount_/) {
- if ($form->{"project_id_$i"} && $form->{"projectnumber_$i"}) {
- $project_id = $form->{"project_id_$i"};
- }
- }
- if ("amount_$i" =~ /amount/) {
- $taxkey = $form->{AR_amounts}{"amount_$i"}{taxkey};
- }
+ my $project_id = undef;
+ $project_id = conv_i($form->{"project_id_$i"});
+ $taxkey = $form->{AR_amounts}{"amount_$i"}{taxkey};
+ @values = ($project_id);
# insert detail records in acc_trans
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate,
project_id, taxkey)
VALUES ($form->{id}, (SELECT c.id FROM chart c
WHERE c.accno = '$form->{AR_amounts}{"amount_$i"}'),
- $form->{"amount_$i"}, '$form->{transdate}', $project_id, '$taxkey')|;
- $dbh->do($query) || $form->dberror($query);
+ $form->{"amount_$i"}, '$form->{transdate}', ?, '$taxkey')|;
+ do_query($form, $dbh, $query, @values);
if ($form->{"tax_$i"} != 0) {
+ @values = ($project_id);
# insert detail records in acc_trans
$query =
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate,
project_id, taxkey)
VALUES ($form->{id}, (SELECT c.id FROM chart c
WHERE c.accno = '$form->{AR_amounts}{"tax_$i"}'),
- $form->{"tax_$i"}, '$form->{transdate}', $project_id, '$taxkey')|;
- $dbh->do($query) || $form->dberror($query);
+ $form->{"tax_$i"}, '$form->{transdate}', ?, '$taxkey')|;
+ do_query($form, $dbh, $query, @values);
}
}
}
# add recievables
- $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate,
- project_id)
+ $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_amounts}{receivables}'),
- $form->{receivables}, '$form->{transdate}', $project_id)|;
+ $form->{receivables}, '$form->{transdate}')|;
$dbh->do($query) || $form->dberror($query);
# add paid transactions
# add receivable
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount,
- transdate)
+ transdate, project_id)
VALUES ($form->{id},
(SELECT c.id FROM chart c
WHERE c.accno = '$form->{AR}{receivables}'),
- $amount, '$form->{"datepaid_$i"}')|;
- $dbh->do($query) || $form->dberror($query);
+ $amount, '$form->{"datepaid_$i"}', ?)|;
+ do_query($form, $dbh, $query, $project_id);
}
$form->{receivables} = $amount;
$form->{"memo_$i"} =~ s/\'/\'\'/g;
if ($form->{"paid_$i"} != 0) {
-
+ my $project_id = conv_i($form->{"paid_project_id_$i"});
# add payment
$amount = $form->{"paid_$i"} * -1;
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount,
- transdate, source, memo)
+ transdate, source, memo, project_id)
VALUES ($form->{id},
(SELECT c.id FROM chart c
WHERE c.accno = '$form->{AR}{"paid_$i"}'),
$amount, '$form->{"datepaid_$i"}',
- '$form->{"source_$i"}', '$form->{"memo_$i"}')|;
- $dbh->do($query) || $form->dberror($query);
+ '$form->{"source_$i"}', '$form->{"memo_$i"}', ?)|;
+ do_query($form, $dbh, $query, $project_id);
# exchangerate difference for payment
$amount =
if ($amount != 0) {
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount,
- transdate, fx_transaction, cleared)
+ transdate, fx_transaction, cleared, project_id)
VALUES ($form->{id},
(SELECT c.id FROM chart c
WHERE c.accno = '$form->{AR}{"paid_$i"}'),
- $amount, '$form->{"datepaid_$i"}', '1', '0')|;
- $dbh->do($query) || $form->dberror($query);
+ $amount, '$form->{"datepaid_$i"}', '1', '0', ?)|;
+ do_query($form, $dbh, $query, $project_id);
}
# exchangerate gain/loss
$accno =
($amount > 0) ? $form->{fxgain_accno} : $form->{fxloss_accno};
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount,
- transdate, fx_transaction, cleared)
+ transdate, fx_transaction, cleared, project_id)
VALUES ($form->{id}, (SELECT c.id FROM chart c
WHERE c.accno = '$accno'),
- $amount, '$form->{"datepaid_$i"}', '1', '0')|;
- $dbh->do($query) || $form->dberror($query);
+ $amount, '$form->{"datepaid_$i"}', '1', '0', ?)|;
+ do_query($form, $dbh, $query, $project_id);
}
}
for my $i (1 .. $form->{paidaccounts}) {
if ($form->{"paid_$i"} != 0) {
+ my $project_id = conv_i($form->{"paid_project_id_$i"});
+
my ($accno) = split /--/, $form->{"AR_paid_$i"};
$form->{"datepaid_$i"} = $form->{invdate}
unless ($form->{"datepaid_$i"});
$dbh->do($query) || $form->dberror($query);
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount,
- transdate)
+ transdate, project_id)
VALUES ($form->{id}, (SELECT c.id FROM chart c
WHERE c.accno = '$form->{AR}'),
- $amount, '$form->{"datepaid_$i"}')|;
- $dbh->do($query) || $form->dberror($query);
+ $amount, '$form->{"datepaid_$i"}', ?)|;
+ do_query($form, $dbh, $query, $project_id);
# record payment
$dbh->do($query) || $form->dberror($query);
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate,
- source, memo)
+ source, memo, project_id)
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);
+ '$form->{"source_$i"}', '$form->{"memo_$i"}', ?)|;
+ do_query($form, $dbh, $query, $project_id);
# gain/loss
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)
+ transdate, cleared, fx_transaction, project_id)
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);
+ $form->{fx}{$accno}{$transdate}, '$transdate', '0', '1', ?)|;
+ do_query($form, $dbh, $query, $project_id);
}
}
}