$project = qq| AND (ac.project_id = | . conv_i($form->{project_id}, 'NULL') . qq|) |;
}
+ my $acc_cash_where = "";
+ my $ar_cash_where = "";
+ my $ap_cash_where = "";
+
+
+ if ($form->{method} eq "cash") {
+ $acc_cash_where = qq| AND (ac.trans_id IN (SELECT id FROM ar WHERE datepaid>='$form->{fromdate}' AND datepaid<='$form->{todate}' UNION SELECT id FROM ap WHERE datepaid>='$form->{fromdate}' AND datepaid<='$form->{todate}' UNION SELECT id FROM gl WHERE transdate>='$form->{fromdate}' AND transdate<='$form->{todate}')) |;
+ $ar_ap_cash_where = qq| AND (a.datepaid>='$form->{fromdate}' AND a.datepaid<='$form->{todate}') |;
+ }
+
# get beginning balances
$query =
qq|SELECT c.accno, c.category, SUM(ac.amount) AS amount, c.description
FROM acc_trans ac
- JOIN chart c ON (ac.chart_id = c.id)
+ LEFT JOIN chart c ON (ac.chart_id = c.id)
$dpt_join
- WHERE ((select date_trunc('year', ac.transdate::date)) = (select date_trunc('year', ?::date))) AND ac.ob_transaction
+ WHERE ((select date_trunc('year', ac.transdate::date)) = (select date_trunc('year', ?::date))) AND ac.ob_transaction $acc_cash_where
$dpt_where
$project
GROUP BY c.accno, c.category, c.description |;
if ($ref->{amount} != 0 || $form->{all_accounts}) {
$trb{ $ref->{accno} }{description} = $ref->{description};
$trb{ $ref->{accno} }{charttype} = 'A';
- if ($ref->{category} ne "I" && $ref->{category} ne "E") {
- if ($ref->{amount} > 0) {
- $trb{ $ref->{accno} }{haben_eb} = $ref->{amount};
- } else {
- $trb{ $ref->{accno} }{soll_eb} = $ref->{amount} * -1;
- }
+
+ if ($ref->{amount} > 0) {
+ $trb{ $ref->{accno} }{haben_eb} = $ref->{amount};
+ } else {
+ $trb{ $ref->{accno} }{soll_eb} = $ref->{amount} * -1;
}
$trb{ $ref->{accno} }{category} = $ref->{category};
}
$form->{todate} = $form->current_date($myconfig) unless ($form->{todate});
my $todate = conv_dateq($form->{todate});
+ my $fromdate = conv_dateq($form->{fromdate});
+
+ my $fromwhere = ($form->{fromdate} ne "") ? " AND (transdate >= (date $fromdate)) " : "";
my $where = " 1 = 1 ";
my ($name, $null);
AND (${arap}.storno IS FALSE)
AND (${arap}.${ct}_id = ${ct}.id)
AND (${ct}.id = ?)
- AND (transdate <= (date $todate))
+ AND (transdate <= (date $todate) $fromwhere )
ORDER BY ctid, transdate, invnumber |;
$dpt_join
WHERE $where
AND (a.${ct_id} = ct.id)
- AND (a.paid != a.amount)
- AND (a.transdate <= $todate)
+ AND ((a.paid != a.amount) OR ((a.datepaid > $todate) AND (datepaid is NOT NULL)))
+ AND (a.transdate <= $todate $fromwhere)
ORDER BY ct.name|;
my $sth = prepare_execute_query($form, $dbh, $query);