<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[FrontAccounting forum — The get_balance function needs to adjusted to eliminate voided entries]]></title>
		<link>https://frontaccounting.com/punbb/viewtopic.php?id=8456</link>
		<atom:link href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=8456&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in The get_balance function needs to adjusted to eliminate voided entries.]]></description>
		<lastBuildDate>Thu, 17 Oct 2019 17:41:41 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: The get_balance function needs to adjusted to eliminate voided entries]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=36281#p36281</link>
			<description><![CDATA[<p>I just wonder if this will calculate faster with this sophisticated statement.<br />The voided amounts are 0 so the results are the same. Just a thought.</p><p>Joe</p>]]></description>
			<author><![CDATA[null@example.com (joe)]]></author>
			<pubDate>Thu, 17 Oct 2019 17:41:41 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=36281#p36281</guid>
		</item>
		<item>
			<title><![CDATA[Re: The get_balance function needs to adjusted to eliminate voided entries]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=36274#p36274</link>
			<description><![CDATA[<p>@joe and @itronics, check this with existing core.</p>]]></description>
			<author><![CDATA[null@example.com (kvvaradha)]]></author>
			<pubDate>Thu, 17 Oct 2019 05:53:51 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=36274#p36274</guid>
		</item>
		<item>
			<title><![CDATA[The get_balance function needs to adjusted to eliminate voided entries]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=36270#p36270</link>
			<description><![CDATA[<p>The get_balance function also includes the voided payment or edited payment. Its better, we have to include the voided table to exclude the entries of voided amount.</p><p>here is my adjusted code.</p><div class="codebox"><pre><code>//----------------------------------------------------------------------------------------------------
function get_balance($account, $dimension, $dimension2, $from, $to, $from_incl=true, $to_incl=true) 
{
    $from_date = date2sql($from);
    $to_date = date2sql($to);

    $sql = &quot;SELECT    SUM(IF(amount &gt;= 0, amount, 0)) as debit, 
                    SUM(IF(amount &lt; 0, -amount, 0)) as credit,
                    SUM(amount) as balance 
        FROM &quot;.TB_PREF.&quot;gl_trans trans  LEFT JOIN &quot;.TB_PREF.&quot;voided AS vd ON trans.type = vd.type AND trans.type_no = vd.id,&quot;
            .TB_PREF.&quot;chart_master coa,&quot;
            .TB_PREF.&quot;chart_types act_type, &quot;
            .TB_PREF.&quot;chart_class act_class
        WHERE trans.account=coa.account_code  AND ISNULL(vd.id)
            AND coa.account_type=act_type.id 
        AND act_type.class_id=act_class.cid&quot;
        .&quot; AND &quot;.($from_incl ? &quot;tran_date &gt;= &#039;$from_date&#039;&quot; : &quot;tran_date &gt; IF(ctype&gt;0 AND ctype&lt;&quot;.CL_INCOME.&quot;, &#039;0000-00-00&#039;, &#039;$from_date&#039;)&quot;)
        .&quot; AND &quot;.($to_incl ? &quot;tran_date &lt;= &#039;$to_date&#039;&quot; : &quot;tran_date &lt; &#039;$to_date&#039;&quot;)
        .($account == null ? &#039;&#039; : &quot; AND account=&quot;.db_escape($account))
        .($dimension == 0 ? &#039;&#039;  : &quot; AND dimension_id = &quot;.($dimension&lt;0 ? 0 : db_escape($dimension)))
        .($dimension2 == 0 ? &#039;&#039; : &quot; AND dimension2_id = &quot;.($dimension2&lt;0 ? 0 : db_escape($dimension2)));

    $result = db_query($sql,&quot;No general ledger accounts were returned&quot;);

    return db_fetch($result);
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (kvvaradha)]]></author>
			<pubDate>Wed, 16 Oct 2019 07:56:20 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=36270#p36270</guid>
		</item>
	</channel>
</rss>
