X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=reporting%2Frep709.php;h=471343dc1939ae3a6482776b84ac805f397a17ae;hb=b17df731b4bb055c2fdd568bc4be9e5caa0ee07b;hp=6f0139a1ff769f94b0bee02f5bbd34c5a3091515;hpb=218cf521781f112cf4afadc572ad43983ca2edd0;p=fa-stable.git diff --git a/reporting/rep709.php b/reporting/rep709.php index 6f0139a1..471343dc 100644 --- a/reporting/rep709.php +++ b/reporting/rep709.php @@ -1,5 +1,14 @@ . +***********************************************************************/ $page_security = 2; // ---------------------------------------------------------------- // $ Revision: 2.0 $ @@ -89,7 +98,7 @@ function getSuppTransactions($from, $to) function getTaxTypes() { - $sql = "SELECT id FROM ".TB_PREF."tax_types ORDER BY id"; + $sql = "SELECT * FROM ".TB_PREF."tax_types ORDER BY id"; return db_query($sql,"No transactions were returned"); } @@ -187,9 +196,9 @@ function print_tax_report() $cols = array(0, 80, 130, 190, 290, 370, 435, 500, 565); $headers = array(_('Trans Type'), _('#'), _('Date'), _('Name'), _('Branch Name'), - _('Net'), _('Tax')); + _('Net'), _('Tax'), ''); - $aligns = array('left', 'left', 'left', 'left', 'left', 'right', 'right'); + $aligns = array('left', 'left', 'left', 'left', 'left', 'right', 'right', 'right'); $params = array( 0 => $comments, 1 => array('text' => _('Period'), 'from' => $from, 'to' => $to), @@ -389,58 +398,68 @@ function print_tax_report() $rep->Line($rep->row - 4); $rep->row -= 16; - $rep->TextCol(0, 5, _("General Ledger")); + $rep->Font('italic'); + $rep->TextCol(0, 1, _("General Ledger")); + $rep->aligns[1] = 'left'; + $rep->TextCol(1, 3, _("Description")); + $rep->TextCol(3, 4, _("Amount")); + $rep->Font(); $rep->Line($rep->row - 6); $rep->row -= 22; + + $taxes = getTaxTypes(); + $total = 0; + $bdate = date2sql($from); + $edate = date2sql($to); - $trow = $rep->row; - - $idcounter = count($taxes); - $i = 0; - for ($j = 0; $j < $idcounter; $j++) - { - $tx = getTaxInfo($taxes[$j]); - $str = $tx['name'] . " " . number_format2($tx['rate'], $dec) . "%"; - $rep->TextCol($i, $i + 1, $str); - $rep->NewLine(); - } - $i++; - $rep->row = $trow; - for ($j = 0; $j < $idcounter; $j++) + while ($tx = db_fetch($taxes)) { - $tx = getTaxInfo($taxes[$j]); - $acc = get_gl_account($tx['sales_gl_code']); - $rep->TextCol($i, $i + 1, $acc['account_code']." ".$acc['account_name']); - $rep->NewLine(); - } - $i++; - $rep->row = $trow; - for ($j = 0; $j < $idcounter; $j++) - { - $tx = getTaxInfo($taxes[$j]); - $amount = get_gl_trans_from_to($from, $to, $tx['sales_gl_code']); - $rep->TextCol($i, $i + 1,number_format2(-$amount, $dec)); + if ($tx['sales_gl_code'] == $tx['purchasing_gl_code']) + { + $sql = "SELECT SUM(IF(amount >= 0, amount, 0)) AS payable, SUM(IF(amount < 0, -amount, 0)) AS collectible + FROM ".TB_PREF."gl_trans WHERE account = '".$tx['sales_gl_code']."' AND tran_date >= '$bdate' AND tran_date <= '$edate'"; + $result = db_query($sql, "Error retrieving tax inquiry"); + $row = db_fetch($result); + $payable = -$row['payable']; + $collectible.= -$row['collectible']; + } + else + { + $sql = "SELECT SUM(amount) AS collectible + FROM ".TB_PREF."gl_trans WHERE account = '".$tx['sales_gl_code']."' AND tran_date >= '$bdate' AND tran_date <= '$edate'"; + $result = db_query($sql, "Error retrieving tax inquiry"); + $row = db_fetch($result); + $collectible = -$row['collectible']; + $sql = "SELECT SUM(amount) AS payable + FROM ".TB_PREF."gl_trans WHERE account = '".$tx['purchasing_gl_code']."' AND tran_date >= '$bdate' AND tran_date <= '$edate'"; + $result = db_query($sql, "Error retrieving tax inquiry"); + $row = db_fetch($result); + $payable = -$row['payable']; + } + $net = $collectible + $payable; + $total += $net; + $rep->TextCol(0, 1, $tx['name'] . " " . $tx['rate'] . "%"); + $rep->TextCol(1, 3, _("Charged on sales") . " (" . _("Output Tax")."):"); + $rep->TextCol(3, 4, number_format2($collectible, $dec)); $rep->NewLine(); - } - $i++; - $rep->row = $trow; - for ($j = 0; $j < $idcounter; $j++) - { - $tx = getTaxInfo($taxes[$j]); - $acc = get_gl_account($tx['purchasing_gl_code']); - $rep->TextCol($i, $i + 1, $acc['account_code']." ".$acc['account_name']); + $rep->TextCol(0, 1, $tx['name'] . " " . $tx['rate'] . "%"); + $rep->TextCol(1, 3, _("Paid on purchases") . " (" . _("Input Tax")."):"); + $rep->TextCol(3, 4, number_format2($payable, $dec)); $rep->NewLine(); - } - $i++; - $rep->row = $trow; - for ($j = 0; $j < $idcounter; $j++) - { - $tx = getTaxInfo($taxes[$j]); - $amount = get_gl_trans_from_to($from, $to, $tx['purchasing_gl_code']); - $rep->TextCol($i, $i + 1,number_format2($amount, $dec)); + $rep->Font('bold'); + $rep->TextCol(0, 1, $tx['name'] . " " . $tx['rate'] . "%"); + $rep->TextCol(1, 3, _("Net payable or collectible")); + $rep->TextCol(3, 4, number_format2($net, $dec)); + $rep->Font(); $rep->NewLine(); } + $rep->Font('bold'); + $rep->TextCol(1, 3, _("Total payable or refund")); + $rep->TextCol(3, 4, number_format2($total, $dec)); + $rep->Font(); + $rep->NewLine(); + $rep->Line($rep->row - 4); $locale = $path_to_root . "lang/" . $_SESSION['language']->code . "/locale.inc";