package GL;
use Data::Dumper;
+use SL::DBUtils;
sub delete_transaction {
my ($self, $myconfig, $form) = @_;
$posted = 0;
}
+ $project_id = conv_i($form->{"project_id_$i"});
+
# if there is an amount, add the record
if ($amount != 0) {
- $project_id =
- ($form->{"project_id_$i"}) ? $form->{"project_id_$i"} : 'NULL';
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate,
source, memo, project_id, taxkey)
VALUES
$amount, '$form->{transdate}', |
. $dbh->quote($form->{"source_$i"}) . qq|, |
. $dbh->quote($form->{"memo_$i"}) . qq|,
- $project_id, $taxkey)|;
+ ?, $taxkey)|;
- $dbh->do($query) || $form->dberror($query);
+ do_query($form, $dbh, $query, $project_id);
}
if ($tax != 0) {
-
# add taxentry
- $amount = $tax;
-
- $project_id =
- ($form->{"project_id_$i"}) ? $form->{"project_id_$i"} : 'NULL';
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate,
- source, memo, project_id, taxkey)
+ source, memo, taxkey)
VALUES
($form->{id}, (SELECT t.chart_id
FROM tax t
WHERE t.id = $form->{"tax_id_$i"}),
- $amount, '$form->{transdate}', |
+ $tax, '$form->{transdate}', |
. $dbh->quote($form->{"source_$i"}) . qq|, |
- . $dbh->quote($form->{"memo_$i"}) . qq|,
- $project_id, $taxkey)|;
+ . $dbh->quote($form->{"memo_$i"}) . qq|, ?, $taxkey)|;
- $dbh->do($query) || $form->dberror($query);
+ do_query($form, $dbh, $query, $project_id);
}
}
$ref->{debit}{$k} = $ref->{amount} * -1;
$ref->{debit_accno}{$k} = $ref->{accno};
$ref->{debit_taxkey}{$k} = $ref->{taxkey};
+ $ref->{transdate}{$k} = $ref->{transdate};
} else {
$ref->{credit}{$l} = $ref->{amount} * 1;
$ref->{credit_accno}{$l} = $ref->{accno};
$ref->{credit_taxkey}{$l} = $ref->{taxkey};
+ $ref->{transdate}{$l} = $ref->{transdate};
}
$ref->{debit}{$k} = $ref2->{amount} * - 1;
$ref->{debit_accno}{$k} = $ref2->{accno};
$ref->{debit_taxkey}{$k} = $ref2->{taxkey};
+ $ref->{transdate}{$k} = $ref2->{transdate};
} else {
if ($ref->{credit_accno}{$l} ne "") {
$l++;
$ref->{credit}{$l} = $ref2->{amount};
$ref->{credit_accno}{$l} = $ref2->{accno};
$ref->{credit_taxkey}{$l} = $ref2->{taxkey};
+ $ref->{transdate}{$l} = $ref2->{transdate};
}
}
}
$sth->finish;
} else {
- $query = "SELECT current_date AS transdate, closedto, revtrans
- FROM defaults";
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- ($form->{transdate}, $form->{closedto}, $form->{revtrans}) =
- $sth->fetchrow_array;
+ $query = "SELECT closedto, revtrans FROM defaults";
+ ($form->{closedto}, $form->{revtrans}) = $dbh->selectrow_array($query);
+ $query =
+ "SELECT COALESCE(" .
+ " (SELECT transdate FROM gl WHERE id = " .
+ " (SELECT MAX(id) FROM gl) LIMIT 1), " .
+ " current_date)";
+ ($form->{transdate}) = $dbh->selectrow_array($query);
# get tax description
$query = qq| SELECT * FROM tax t order by t.taxkey|;