<?php
-
+/**********************************************************************
+ Copyright (C) FrontAccounting, LLC.
+ Released under the terms of the GNU Affero General Public License,
+ AGPL, as published by the Free Software Foundation, either version
+ 3 of the License, or (at your option) any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the License here <http://www.gnu.org/licenses/agpl-3.0.html>.
+***********************************************************************/
$page_security = 2;
// ----------------------------------------------------------------
// $ Revision: 2.0 $
function getTax($tno, $tpe)
{
- $sql = "SELECT amount, included_in_price FROM ".TB_PREF."debtor_trans_tax_details
- WHERE ".TB_PREF."debtor_trans_tax_details.debtor_trans_no=$tno
- AND ".TB_PREF."debtor_trans_tax_details.debtor_trans_type=$tpe
- AND ".TB_PREF."debtor_trans_tax_details.amount <> 0";
+ // GROUP BY debtor_trans_type, debtor_trans_no";
+ $sql = "SELECT SUM(amount) AS Amount, MAX(included_in_price) AS Included FROM ".TB_PREF."debtor_trans_tax_details
+ WHERE debtor_trans_no=$tno
+ AND debtor_trans_type=$tpe
+ AND amount <> 0";
$result = db_query($sql,"No transactions were returned");
return db_fetch($result);
$todate = date2sql($to);
$netamount = "IF(".TB_PREF."debtor_trans.type=11,-(ov_amount+ov_freight+ov_discount),ov_amount+ov_freight+ov_discount)*".TB_PREF."debtor_trans.rate";
- // IF(".TB_PREF."debtor_trans.type=11,-(ov_amount+ov_freight+ov_discount),ov_amount+ov_freight+ov_discount)*rate AS NetAmount,
- // IF(".TB_PREF."debtor_trans.type=11,-(ov_gst+ov_freight_tax),ov_gst+ov_freight_tax)*rate AS Tax
$sql = "SELECT ".TB_PREF."debtor_trans.reference,
".TB_PREF."debtor_trans.trans_no,
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");
}
$todate = date2sql($to);
$amount = "IF(".TB_PREF."debtor_trans_tax_details.debtor_trans_type=11,-amount,amount)*".TB_PREF."debtor_trans.rate";
$mamount = "IF(".TB_PREF."debtor_trans_tax_details.included_in_price=0, 0, $amount)";
- $netamount = "IF(".TB_PREF."debtor_trans.type=11,-(ov_amount+ov_freight+ov_discount),ov_amount+ov_freight+ov_discount)*".TB_PREF."debtor_trans.rate-$mamount";
+ $netamount = "IF(".TB_PREF."debtor_trans.type=11,-quantity,quantity)*unit_price*".TB_PREF."debtor_trans.rate-$mamount";
$sql = "SELECT SUM($netamount),
SUM($amount)
- FROM ".TB_PREF."debtor_trans_tax_details, ".TB_PREF."debtor_trans
+ FROM ".TB_PREF."debtor_trans_details, ".TB_PREF."debtor_trans_tax_details, ".TB_PREF."debtor_trans
WHERE ".TB_PREF."debtor_trans.type>=10
AND ".TB_PREF."debtor_trans.type<=11
+ AND ".TB_PREF."debtor_trans_details.debtor_trans_no=".TB_PREF."debtor_trans.trans_no
+ AND ".TB_PREF."debtor_trans_details.debtor_trans_type=".TB_PREF."debtor_trans.type
AND ".TB_PREF."debtor_trans.trans_no=".TB_PREF."debtor_trans_tax_details.debtor_trans_no
AND ".TB_PREF."debtor_trans.type=".TB_PREF."debtor_trans_tax_details.debtor_trans_type
AND ".TB_PREF."debtor_trans_tax_details.amount <> 0
{
$fromdate = date2sql($from);
$todate = date2sql($to);
- $sql = "SELECT SUM((ov_amount+ov_discount) * ".TB_PREF."supp_trans.rate), SUM(amount*".TB_PREF."supp_trans.rate)
- FROM ".TB_PREF."supp_invoice_tax_items, ".TB_PREF."supp_trans
+ $sql = "SELECT SUM(unit_price * quantity * ".TB_PREF."supp_trans.rate), SUM(amount*".TB_PREF."supp_trans.rate)
+ FROM ".TB_PREF."supp_invoice_items, ".TB_PREF."supp_invoice_tax_items, ".TB_PREF."supp_trans
WHERE ".TB_PREF."supp_trans.type>=20
AND ".TB_PREF."supp_trans.type<=21
AND ".TB_PREF."supp_trans.trans_no=".TB_PREF."supp_invoice_tax_items.supp_trans_no
AND ".TB_PREF."supp_trans.type=".TB_PREF."supp_invoice_tax_items.supp_trans_type
+ AND ".TB_PREF."supp_invoice_items.supp_trans_no=".TB_PREF."supp_trans.trans_no
+ AND ".TB_PREF."supp_invoice_items.supp_trans_type=".TB_PREF."supp_trans.type
AND ".TB_PREF."supp_invoice_tax_items.tax_type_id=$taxtype
AND ".TB_PREF."supp_invoice_tax_items.amount <> 0
AND ".TB_PREF."supp_trans.tran_date >= '$fromdate'
$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),
$tax_amt = 0;
else
{
- $tx['amount'] *= $trans['rate'];
+ $tx['Amount'] *= $trans['rate'];
if ($trans['type'] == 11)
- $tx['amount'] *= -1;
- if ($tx['included_in_price'])
- $trans['NetAmount'] -= $tx['amount'];
- $tax_amt = $tx['amount'];
+ $tx['Amount'] *= -1;
+ if ($tx['Included'] > 0)
+ $trans['NetAmount'] -= $tx['Amount'];
+ $tax_amt = $tx['Amount'];
}
if (!$summaryOnly)
{
}
$rep->Line($rep->row - 4);
+ $rep->row -= 16;
+ $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);
+
+ while ($tx = db_fetch($taxes))
+ {
+ 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();
+ $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();
+ $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";
if (file_exists($locale))
{