<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[FrontAccounting forum — Supplier >> Supplier Balances and Supplier Trial Balances]]></title>
	<link rel="self" href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=10331&amp;type=atom" />
	<updated>2023-07-26T06:49:24Z</updated>
	<generator>PunBB</generator>
	<id>https://frontaccounting.com/punbb/viewtopic.php?id=10331</id>
		<entry>
			<title type="html"><![CDATA[Re: Supplier >> Supplier Balances and Supplier Trial Balances]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=42462#p42462" />
			<content type="html"><![CDATA[<p>Please note my repo is very much customized.<br />I have tested this in core repo and it is working<br />But you need to recheck with core and remove my customization if any</p>]]></content>
			<author>
				<name><![CDATA[boxygen]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=20175</uri>
			</author>
			<updated>2023-07-26T06:49:24Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=42462#p42462</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Supplier >> Supplier Balances and Supplier Trial Balances]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=42461#p42461" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>&lt;?php
/**********************************************************************
    Copyright (C) Boxygen, LLC.
    Released under the terms of the GNU General Public License, GPL,
    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 &lt;http://www.gnu.org/licenses/gpl-3.0.html&gt;.
***********************************************************************/
$page_security = &#039;SA_SUPPLIERANALYTIC&#039;;
// ----------------------------------------------------------------
// $ Revision:    2.0 $
// Creator:    Joe Hunt
// date_:    2005-05-19
// Title:    Supplier Balances
// ----------------------------------------------------------------
// $path_to_root=&quot;..&quot;; //Fro Cron

//include_once($path_to_root . &quot;/includes/session.inc&quot;); //For Cron
include_once($path_to_root . &quot;/includes/date_functions.inc&quot;);
include_once($path_to_root . &quot;/includes/data_checks.inc&quot;);
include_once($path_to_root . &quot;/gl/includes/gl_db.inc&quot;);

//----------------------------------------------------------------------------------------------------

print_supplier_balances();

function get_open_balance($supplier_id, $to)
{
    if($to)
        $to = date2sql($to);

        $sql = &quot;SELECT SUM(IF(t.type = &quot;.ST_SUPPINVOICE.&quot; OR (t.type IN (&quot;.ST_JOURNAL.&quot; , &quot;.ST_BANKDEPOSIT.&quot;, &quot;.ST_BANKDEPOSIT.&quot;) AND t.ov_amount&gt;0),
                        -abs(t.ov_amount + t.ov_gst + t.ov_discount), 0)) AS charges,&quot;;

 $sql .= &quot;SUM(IF(t.type != &quot;.ST_SUPPINVOICE.&quot; AND NOT(t.type IN (&quot;.ST_JOURNAL.&quot; , &quot;.ST_BANKDEPOSIT.&quot;, &quot;.ST_BANKDEPOSIT.&quot;) AND t.ov_amount&gt;0),
                        abs(t.ov_amount + t.ov_gst + t.ov_discount) * -1, 0)) AS credits,&quot;;

     $sql .= &quot;SUM(IF(t.type != &quot;.ST_SUPPINVOICE.&quot; AND NOT(t.type IN (&quot;.ST_JOURNAL.&quot; , &quot;.ST_BANKDEPOSIT.&quot; , &quot;.ST_BANKDEPOSIT.&quot;)), t.alloc * -1, t.alloc)) AS Allocated,&quot;;

     $sql .=    &quot;SUM(IF(t.type = &quot;.ST_SUPPINVOICE.&quot;, 1, -1) *
             (abs(t.ov_amount + t.ov_gst + t.ov_discount) - abs(t.alloc))) AS OutStanding
        FROM &quot;.TB_PREF.&quot;supp_trans t
        WHERE t.supplier_id = &quot;.db_escape($supplier_id);
    if ($to)
        $sql .= &quot; AND t.tran_date &lt; &#039;$to&#039;&quot;;
    $sql .= &quot; GROUP BY supplier_id&quot;;

    $result = db_query($sql,&quot;No transactions were returned&quot;);
    return db_fetch($result);
}


function getTransactions($supplier_id, $from, $to)
{
    $from = date2sql($from);
    $to = date2sql($to);
//memo added by faisal
    $sql = &quot;SELECT &quot;.TB_PREF.&quot;supp_trans.*, comments.memo_,
                (&quot;.TB_PREF.&quot;supp_trans.ov_amount + &quot;.TB_PREF.&quot;supp_trans.ov_gst + &quot;.TB_PREF.&quot;supp_trans.ov_discount)
                AS TotalAmount, &quot;.TB_PREF.&quot;supp_trans.alloc AS Allocated,
                ((&quot;.TB_PREF.&quot;supp_trans.type = &quot;.ST_SUPPINVOICE.&quot;)
                    AND &quot;.TB_PREF.&quot;supp_trans.due_date &lt; &#039;$to&#039;) AS OverDue
                FROM &quot;.TB_PREF.&quot;supp_trans
                    LEFT JOIN &quot;.TB_PREF.&quot;comments comments ON &quot;.TB_PREF.&quot;supp_trans.type=comments.type AND &quot;.TB_PREF.&quot;supp_trans.trans_no=comments.id
                     WHERE &quot;.TB_PREF.&quot;supp_trans.tran_date &gt;= &#039;$from&#039; AND &quot;.TB_PREF.&quot;supp_trans.tran_date &lt;= &#039;$to&#039;
                AND &quot;.TB_PREF.&quot;supp_trans.supplier_id = &#039;$supplier_id&#039; AND &quot;.TB_PREF.&quot;supp_trans.ov_amount!=0
                    ORDER BY &quot;.TB_PREF.&quot;supp_trans.tran_date&quot;;

    $TransResult = db_query($sql,&quot;No transactions were returned&quot;);

    return $TransResult;
}


//----------------------------------------------------------------------------------------------------

function print_supplier_balances()
{
        global $path_to_root, $systypes_array;

        $from = $_POST[&#039;PARAM_0&#039;];
        $to = $_POST[&#039;PARAM_1&#039;];
        $fromsupp = $_POST[&#039;PARAM_2&#039;];
        $show_balance = $_POST[&#039;PARAM_3&#039;];
        $currency = $_POST[&#039;PARAM_4&#039;];
        $no_zeros = $_POST[&#039;PARAM_5&#039;];
        $comments = $_POST[&#039;PARAM_6&#039;];
    $orientation = $_POST[&#039;PARAM_7&#039;];
    $destination = $_POST[&#039;PARAM_8&#039;];
    if ($destination)
        include_once($path_to_root . &quot;/reporting/includes/excel_report.inc&quot;);
    else
        include_once($path_to_root . &quot;/reporting/includes/pdf_report.inc&quot;);

    $orientation = ($orientation ? &#039;L&#039; : &#039;P&#039;);
    if ($fromsupp == ALL_TEXT)
        $supp = _(&#039;All&#039;);
    else
        $supp = get_supplier_name($fromsupp);
        $dec = user_price_dec();

    if ($currency == ALL_TEXT)
    {
        $convert = true;
        $currency = _(&#039;Balances in Home currency&#039;);
    }
    else
        $convert = false;

    if ($no_zeros) $nozeros = _(&#039;Yes&#039;);
    else $nozeros = _(&#039;No&#039;);

    $cols = array(0, 80, 130, 190,    250, 320, 385, 450,    515);

    $headers = array(_(&#039;Trans Type&#039;), _(&#039;#&#039;), _(&#039;Date&#039;), _(&#039;Due Date&#039;), _(&#039;Debit&#039;),
        _(&#039;Credit&#039;), _(&#039;Allocated&#039;), _(&#039;Outstanding&#039;));

    if ($show_balance)
        $headers[7] = _(&#039;Balance&#039;);
    $aligns = array(&#039;left&#039;,    &#039;left&#039;,    &#039;left&#039;,    &#039;left&#039;,    &#039;right&#039;, &#039;right&#039;, &#039;right&#039;, &#039;right&#039;);

    $params =   array(     0 =&gt; $comments,
                1 =&gt; array(&#039;text&#039; =&gt; _(&#039;Period&#039;), &#039;from&#039; =&gt; $from, &#039;to&#039; =&gt; $to),
                2 =&gt; array(&#039;text&#039; =&gt; _(&#039;Supplier&#039;), &#039;from&#039; =&gt; $supp, &#039;to&#039; =&gt; &#039;&#039;),
                3 =&gt; array(  &#039;text&#039; =&gt; _(&#039;Currency&#039;),&#039;from&#039; =&gt; $currency, &#039;to&#039; =&gt; &#039;&#039;),
            4 =&gt; array(&#039;text&#039; =&gt; _(&#039;Suppress Zeros&#039;), &#039;from&#039; =&gt; $nozeros, &#039;to&#039; =&gt; &#039;&#039;));

    $rep = new FrontReport(_(&#039;Supplier Ledger&#039;), &quot;SupplierBalances&quot;, user_pagesize(), 8, $orientation);
    if ($orientation == &#039;L&#039;)
        recalculate_cols($cols);

    $rep-&gt;Font();
    $rep-&gt;Info($params, $cols, $headers, $aligns);
    $rep-&gt;NewPage();

    $total = array();
    $grandtotal = array(0,0,0,0);

    $sql = &quot;SELECT supplier_id, supp_name AS name, curr_code FROM &quot;.TB_PREF.&quot;suppliers&quot;;
    if ($fromsupp != ALL_TEXT)
        $sql .= &quot; WHERE supplier_id=&quot;.db_escape($fromsupp);
    $sql .= &quot; ORDER BY supp_name&quot;;
    $result = db_query($sql, &quot;The customers could not be retrieved&quot;);

    while ($myrow=db_fetch($result))
    {
        if (!$convert &amp;&amp; $currency != $myrow[&#039;curr_code&#039;])
            continue;
        $accumulate = 0;
        $rate = $convert ? get_exchange_rate_from_home_currency($myrow[&#039;curr_code&#039;], Today()) : 1;
        $bal = get_open_balance($myrow[&#039;supplier_id&#039;], $from);
        $init[0] = $init[1] = 0.0;
        $init[0] = round2(abs($bal[&#039;charges&#039;]*$rate), $dec);
        $init[1] = round2(Abs($bal[&#039;credits&#039;]*$rate), $dec);
        $init[2] = round2($bal[&#039;Allocated&#039;]*$rate, $dec);
        if ($show_balance)
        {
            $init[3] = $init[1] - $init[0];
            $accumulate += $init[3];
        }
        else
            $init[3] = round2($bal[&#039;OutStanding&#039;]*$rate, $dec);
        $res = getTransactions($myrow[&#039;supplier_id&#039;], $from, $to);
        if ($no_zeros &amp;&amp; db_num_rows($res) == 0) continue;

        $rep-&gt;fontSize += 2;
        $rep-&gt;TextCol(0, 2, $myrow[&#039;name&#039;]);
        if ($convert) $rep-&gt;TextCol(2, 3,    $myrow[&#039;curr_code&#039;]);
        $rep-&gt;fontSize -= 2;
        $rep-&gt;TextCol(3, 4,    _(&quot;Open Balance&quot;));
        $rep-&gt;AmountCol(5, 6, $init[0], $dec);
        $rep-&gt;AmountCol(4, 5, $init[1], $dec);
        $rep-&gt;AmountCol(6, 7, $init[2], $dec);
        $rep-&gt;AmountCol(7, 8, $init[3], $dec);
        $total = array(0,0,0,0);
        for ($i = 0; $i &lt; 4; $i++)
        {
            $total[$i] += $init[$i];
            $grandtotal[$i] += $init[$i];
        }
        $rep-&gt;NewLine(1, 2);
        $rep-&gt;Line($rep-&gt;row + 4);
        if (db_num_rows($res)==0) {
            $rep-&gt;NewLine(1, 2);
            continue;
        }
        while ($trans=db_fetch($res))
        {
            if ($no_zeros &amp;&amp; floatcmp(abs($trans[&#039;TotalAmount&#039;]), $trans[&#039;Allocated&#039;]) == 0) continue;
            $rep-&gt;NewLine(1, 2);
            $rep-&gt;TextCol(0, 1, $systypes_array[$trans[&#039;type&#039;]]);
            $rep-&gt;TextCol(1, 2,    $trans[&#039;reference&#039;]);
            $rep-&gt;DateCol(2, 3,    $trans[&#039;tran_date&#039;], true);
            if ($trans[&#039;type&#039;] == ST_SUPPINVOICE)
                $rep-&gt;DateCol(3, 4,    $trans[&#039;due_date&#039;], true);
            $item[0] = $item[1] = 0.0;
            if ($trans[&#039;TotalAmount&#039;] &gt; 0.0)
            {
                $item[0] = round2(abs($trans[&#039;TotalAmount&#039;]) * $rate, $dec);
                $rep-&gt;AmountCol(5, 6, $item[0], $dec);
                $accumulate -= $item[0];
            }
            else
            {
                $item[1] = round2(abs($trans[&#039;TotalAmount&#039;]) * $rate, $dec);
                $rep-&gt;AmountCol(4, 5, $item[1], $dec);
                $accumulate += $item[1];
            }
            $item[2] = round2($trans[&#039;Allocated&#039;] * $rate, $dec);
            $rep-&gt;AmountCol(6, 7, $item[2], $dec);
            if ($trans[&#039;TotalAmount&#039;] &gt; 0.0)
                $item[3] = $item[2] - $item[0];
            else
                $item[3] = ($item[2] - $item[1]) * -1;
            if ($show_balance)
                $rep-&gt;AmountCol(7, 8, $accumulate, $dec);
            else
                $rep-&gt;AmountCol(7, 8, $item[3], $dec);
            for ($i = 0; $i &lt; 4; $i++)
            {
                $total[$i] += $item[$i];
                $grandtotal[$i] += $item[$i];
            }
            if ($show_balance)
                $total[3] = $total[1] - $total[0];

                // $gl_memo = get_gl_memo($trans[&#039;type&#039;], -round2($trans[&#039;TotalAmount&#039;] * $rate, $dec), $trans[&#039;trans_no&#039;], null, $myrow[&#039;supplier_id&#039;], PT_SUPPLIER);
                $memo = $gl_memo != &quot;&quot; ? $gl_memo : $trans[&#039;memo_&#039;];

                if ($memo &lt;&gt; &quot;&quot;)
                {
                        $rep-&gt;NewLine(1, 2);
                        $rep-&gt;fontSize -= 2;
                        $rep-&gt;TextCol(1, 8,    $memo); // added by faisal
                        $rep-&gt;fontSize += 2;

                }
                $rep-&gt;Line($rep-&gt;row - 2);

        }
        $rep-&gt;Line($rep-&gt;row - 8);

        $rep-&gt;NewLine(2);

        $rep-&gt;TextCol(0, 1, _(&#039;Total Activity&#039;));
        // $rep-&gt;TextCol(2, 6, $myrow[&#039;name&#039;]);
        $rep-&gt;AmountCol(5, 6, $total[0] - $init[0], $dec);
        $rep-&gt;AmountCol(4, 5, $total[1] - $init[1], $dec);

        $rep-&gt;NewLine(2);
        $rep-&gt;TextCol(0, 3,    _(&#039;Total&#039;));
        $rep-&gt;AmountCol(5, 6, $total[0], $dec);
        $rep-&gt;AmountCol(4, 5, $total[1], $dec);

        for ($i = 2; $i &lt; 4; $i++)
        {
            $rep-&gt;AmountCol($i + 4, $i + 5, $total[$i], $dec);
            $total[$i] = 0.0;
        }
        $rep-&gt;Line($rep-&gt;row  - 4);
        $rep-&gt;NewLine(2);
    }
    $rep-&gt;fontSize += 2;
    $rep-&gt;TextCol(0, 3,    _(&#039;Grand Total&#039;));
    $rep-&gt;fontSize -= 2;
    if ($show_balance)
        $grandtotal[3] = $grandtotal[1] - $grandtotal[0];
$rep-&gt;AmountCol(4,  5,$grandtotal[1], $dec);
$rep-&gt;AmountCol(5,  6,$grandtotal[0], $dec);

    for ($i = 2; $i &lt; 4; $i++)
        $rep-&gt;AmountCol($i + 4, $i + 5,$grandtotal[$i], $dec);
    $rep-&gt;Line($rep-&gt;row  - 4);
    $rep-&gt;NewLine();
    $rep-&gt;End();
}

?&gt;</code></pre></div>]]></content>
			<author>
				<name><![CDATA[boxygen]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=20175</uri>
			</author>
			<updated>2023-07-26T06:48:13Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=42461#p42461</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Supplier >> Supplier Balances and Supplier Trial Balances]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=42460#p42460" />
			<content type="html"><![CDATA[<p>after comment that line same error Report cant show.<br />plz can u copy code again with function.</p><p>i aslo checked Charges and Credits balance in frontaccounting website demo.wrong balance showing..<br />plz can u verify from ur side? </p><p>Thx for supports</p>]]></content>
			<author>
				<name><![CDATA[muzammal83]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=20613</uri>
			</author>
			<updated>2023-07-26T06:36:42Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=42460#p42460</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Supplier >> Supplier Balances and Supplier Trial Balances]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=42459#p42459" />
			<content type="html"><![CDATA[<p>You can comment that line</p>]]></content>
			<author>
				<name><![CDATA[boxygen]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=20175</uri>
			</author>
			<updated>2023-07-26T06:07:06Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=42459#p42459</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Supplier >> Supplier Balances and Supplier Trial Balances]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=42458#p42458" />
			<content type="html"><![CDATA[<p>thx for help and sharing code...<br />i m using&nbsp; Release 2.4.16 updated version.<br />i cant change any customization in this.debit word only use in msg i know its charges word.u can check attachment files.</p><p>I Run ur code but its error because get_gl_memo function.<br />Plz can u send me get_gl_memo function code.</p><p>Again thx lot for help....</p>]]></content>
			<author>
				<name><![CDATA[muzammal83]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=20613</uri>
			</author>
			<updated>2023-07-26T05:32:33Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=42458#p42458</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Supplier >> Supplier Balances and Supplier Trial Balances]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=42451#p42451" />
			<content type="html"><![CDATA[<p>Your supplier balances report is not same as core. You have done customization.<br />In Core The Column Names are Charges and Credits.<br />Charges is what you means as Credit<br />Credits is what you mean as Debit.<br />I have a Customized Supplier Ledger Report given below. I hope that works for your repo.</p><div class="codebox"><pre><code>&lt;?php

$page_security = &#039;SA_SUPPLIERANALYTIC&#039;;
// ----------------------------------------------------------------
// $ Revision:    2.0 $
// Creator:    Joe Hunt
// date_:    2005-05-19
// Title:    Supplier Balances
// ----------------------------------------------------------------
// $path_to_root=&quot;..&quot;; //Fro Cron

//include_once($path_to_root . &quot;/includes/session.inc&quot;); //For Cron
include_once($path_to_root . &quot;/includes/date_functions.inc&quot;);
include_once($path_to_root . &quot;/includes/data_checks.inc&quot;);
include_once($path_to_root . &quot;/gl/includes/gl_db.inc&quot;);

//----------------------------------------------------------------------------------------------------

print_supplier_balances();

function get_open_balance($supplier_id, $to)
{
    if($to)
        $to = date2sql($to);

        $sql = &quot;SELECT SUM(IF(t.type = &quot;.ST_SUPPINVOICE.&quot; OR (t.type IN (&quot;.ST_JOURNAL.&quot; , &quot;.ST_BANKDEPOSIT.&quot;, &quot;.ST_CASHDEPOSIT.&quot;) AND t.ov_amount&gt;0),
                        -abs(t.ov_amount + t.ov_gst + t.ov_discount), 0)) AS charges,&quot;;

 $sql .= &quot;SUM(IF(t.type != &quot;.ST_SUPPINVOICE.&quot; AND NOT(t.type IN (&quot;.ST_JOURNAL.&quot; , &quot;.ST_BANKDEPOSIT.&quot;, &quot;.ST_CASHDEPOSIT.&quot;) AND t.ov_amount&gt;0),
                        abs(t.ov_amount + t.ov_gst + t.ov_discount) * -1, 0)) AS credits,&quot;;

     $sql .= &quot;SUM(IF(t.type != &quot;.ST_SUPPINVOICE.&quot; AND NOT(t.type IN (&quot;.ST_JOURNAL.&quot; , &quot;.ST_BANKDEPOSIT.&quot; , &quot;.ST_CASHDEPOSIT.&quot;)), t.alloc * -1, t.alloc)) AS Allocated,&quot;;

     $sql .=    &quot;SUM(IF(t.type = &quot;.ST_SUPPINVOICE.&quot;, 1, -1) *
             (abs(t.ov_amount + t.ov_gst + t.ov_discount) - abs(t.alloc))) AS OutStanding
        FROM &quot;.TB_PREF.&quot;supp_trans t
        WHERE t.supplier_id = &quot;.db_escape($supplier_id);
    if ($to)
        $sql .= &quot; AND t.tran_date &lt; &#039;$to&#039;&quot;;
    $sql .= &quot; GROUP BY supplier_id&quot;;

    $result = db_query($sql,&quot;No transactions were returned&quot;);
    return db_fetch($result);
}


function getTransactions($supplier_id, $from, $to)
{
    $from = date2sql($from);
    $to = date2sql($to);
//memo added by faisal
    $sql = &quot;SELECT &quot;.TB_PREF.&quot;supp_trans.*, comments.memo_,
                (&quot;.TB_PREF.&quot;supp_trans.ov_amount + &quot;.TB_PREF.&quot;supp_trans.ov_gst + &quot;.TB_PREF.&quot;supp_trans.ov_discount)
                AS TotalAmount, &quot;.TB_PREF.&quot;supp_trans.alloc AS Allocated,
                ((&quot;.TB_PREF.&quot;supp_trans.type = &quot;.ST_SUPPINVOICE.&quot;)
                    AND &quot;.TB_PREF.&quot;supp_trans.due_date &lt; &#039;$to&#039;) AS OverDue
                FROM &quot;.TB_PREF.&quot;supp_trans
                    LEFT JOIN &quot;.TB_PREF.&quot;comments comments ON &quot;.TB_PREF.&quot;supp_trans.type=comments.type AND &quot;.TB_PREF.&quot;supp_trans.trans_no=comments.id
                     WHERE &quot;.TB_PREF.&quot;supp_trans.tran_date &gt;= &#039;$from&#039; AND &quot;.TB_PREF.&quot;supp_trans.tran_date &lt;= &#039;$to&#039;
                AND &quot;.TB_PREF.&quot;supp_trans.supplier_id = &#039;$supplier_id&#039; AND &quot;.TB_PREF.&quot;supp_trans.ov_amount!=0
                    ORDER BY &quot;.TB_PREF.&quot;supp_trans.tran_date&quot;;

    $TransResult = db_query($sql,&quot;No transactions were returned&quot;);

    return $TransResult;
}


//----------------------------------------------------------------------------------------------------

function print_supplier_balances()
{
        global $path_to_root, $systypes_array;

        $from = $_POST[&#039;PARAM_0&#039;];
        $to = $_POST[&#039;PARAM_1&#039;];
        $fromsupp = $_POST[&#039;PARAM_2&#039;];
        $show_balance = $_POST[&#039;PARAM_3&#039;];
        $currency = $_POST[&#039;PARAM_4&#039;];
        $no_zeros = $_POST[&#039;PARAM_5&#039;];
        $comments = $_POST[&#039;PARAM_6&#039;];
    $orientation = $_POST[&#039;PARAM_7&#039;];
    $destination = $_POST[&#039;PARAM_8&#039;];
    if ($destination)
        include_once($path_to_root . &quot;/reporting/includes/excel_report.inc&quot;);
    else
        include_once($path_to_root . &quot;/reporting/includes/pdf_report.inc&quot;);

    $orientation = ($orientation ? &#039;L&#039; : &#039;P&#039;);
    if ($fromsupp == ALL_TEXT)
        $supp = _(&#039;All&#039;);
    else
        $supp = get_supplier_name($fromsupp);
        $dec = user_price_dec();

    if ($currency == ALL_TEXT)
    {
        $convert = true;
        $currency = _(&#039;Balances in Home currency&#039;);
    }
    else
        $convert = false;

    if ($no_zeros) $nozeros = _(&#039;Yes&#039;);
    else $nozeros = _(&#039;No&#039;);

    $cols = array(0, 80, 130, 190,    250, 320, 385, 450,    515);

    $headers = array(_(&#039;Trans Type&#039;), _(&#039;#&#039;), _(&#039;Date&#039;), _(&#039;Due Date&#039;), _(&#039;Debit&#039;),
        _(&#039;Credit&#039;), _(&#039;Allocated&#039;), _(&#039;Outstanding&#039;));

    if ($show_balance)
        $headers[7] = _(&#039;Balance&#039;);
    $aligns = array(&#039;left&#039;,    &#039;left&#039;,    &#039;left&#039;,    &#039;left&#039;,    &#039;right&#039;, &#039;right&#039;, &#039;right&#039;, &#039;right&#039;);

    $params =   array(     0 =&gt; $comments,
                1 =&gt; array(&#039;text&#039; =&gt; _(&#039;Period&#039;), &#039;from&#039; =&gt; $from, &#039;to&#039; =&gt; $to),
                2 =&gt; array(&#039;text&#039; =&gt; _(&#039;Supplier&#039;), &#039;from&#039; =&gt; $supp, &#039;to&#039; =&gt; &#039;&#039;),
                3 =&gt; array(  &#039;text&#039; =&gt; _(&#039;Currency&#039;),&#039;from&#039; =&gt; $currency, &#039;to&#039; =&gt; &#039;&#039;),
            4 =&gt; array(&#039;text&#039; =&gt; _(&#039;Suppress Zeros&#039;), &#039;from&#039; =&gt; $nozeros, &#039;to&#039; =&gt; &#039;&#039;));

    $rep = new FrontReport(_(&#039;Supplier Ledger&#039;), &quot;SupplierBalances&quot;, user_pagesize(), 8, $orientation);
    if ($orientation == &#039;L&#039;)
        recalculate_cols($cols);

    $rep-&gt;Font();
    $rep-&gt;Info($params, $cols, $headers, $aligns);
    $rep-&gt;NewPage();

    $total = array();
    $grandtotal = array(0,0,0,0);

    $sql = &quot;SELECT supplier_id, supp_name AS name, curr_code FROM &quot;.TB_PREF.&quot;suppliers&quot;;
    if ($fromsupp != ALL_TEXT)
        $sql .= &quot; WHERE supplier_id=&quot;.db_escape($fromsupp);
    $sql .= &quot; ORDER BY supp_name&quot;;
    $result = db_query($sql, &quot;The customers could not be retrieved&quot;);

    while ($myrow=db_fetch($result))
    {
        if (!$convert &amp;&amp; $currency != $myrow[&#039;curr_code&#039;])
            continue;
        $accumulate = 0;
        $rate = $convert ? get_exchange_rate_from_home_currency($myrow[&#039;curr_code&#039;], Today()) : 1;
        $bal = get_open_balance($myrow[&#039;supplier_id&#039;], $from);
        $init[0] = $init[1] = 0.0;
        $init[0] = round2(abs($bal[&#039;charges&#039;]*$rate), $dec);
        $init[1] = round2(Abs($bal[&#039;credits&#039;]*$rate), $dec);
        $init[2] = round2($bal[&#039;Allocated&#039;]*$rate, $dec);
        if ($show_balance)
        {
            $init[3] = $init[1] - $init[0];
            $accumulate += $init[3];
        }
        else
            $init[3] = round2($bal[&#039;OutStanding&#039;]*$rate, $dec);
        $res = getTransactions($myrow[&#039;supplier_id&#039;], $from, $to);
        if ($no_zeros &amp;&amp; db_num_rows($res) == 0) continue;

        $rep-&gt;fontSize += 2;
        $rep-&gt;TextCol(0, 2, $myrow[&#039;name&#039;]);
        if ($convert) $rep-&gt;TextCol(2, 3,    $myrow[&#039;curr_code&#039;]);
        $rep-&gt;fontSize -= 2;
        $rep-&gt;TextCol(3, 4,    _(&quot;Open Balance&quot;));
        $rep-&gt;AmountCol(5, 6, $init[0], $dec);
        $rep-&gt;AmountCol(4, 5, $init[1], $dec);
        $rep-&gt;AmountCol(6, 7, $init[2], $dec);
        $rep-&gt;AmountCol(7, 8, $init[3], $dec);
        $total = array(0,0,0,0);
        for ($i = 0; $i &lt; 4; $i++)
        {
            $total[$i] += $init[$i];
            $grandtotal[$i] += $init[$i];
        }
        $rep-&gt;NewLine(1, 2);
        $rep-&gt;Line($rep-&gt;row + 4);
        if (db_num_rows($res)==0) {
            $rep-&gt;NewLine(1, 2);
            continue;
        }
        while ($trans=db_fetch($res))
        {
            if ($no_zeros &amp;&amp; floatcmp(abs($trans[&#039;TotalAmount&#039;]), $trans[&#039;Allocated&#039;]) == 0) continue;
            $rep-&gt;NewLine(1, 2);
            $rep-&gt;TextCol(0, 1, $systypes_array[$trans[&#039;type&#039;]]);
            $rep-&gt;TextCol(1, 2,    $trans[&#039;reference&#039;]);
            $rep-&gt;DateCol(2, 3,    $trans[&#039;tran_date&#039;], true);
            if ($trans[&#039;type&#039;] == ST_SUPPINVOICE)
                $rep-&gt;DateCol(3, 4,    $trans[&#039;due_date&#039;], true);
            $item[0] = $item[1] = 0.0;
            if ($trans[&#039;TotalAmount&#039;] &gt; 0.0)
            {
                $item[0] = round2(abs($trans[&#039;TotalAmount&#039;]) * $rate, $dec);
                $rep-&gt;AmountCol(5, 6, $item[0], $dec);
                $accumulate -= $item[0];
            }
            else
            {
                $item[1] = round2(abs($trans[&#039;TotalAmount&#039;]) * $rate, $dec);
                $rep-&gt;AmountCol(4, 5, $item[1], $dec);
                $accumulate += $item[1];
            }
            $item[2] = round2($trans[&#039;Allocated&#039;] * $rate, $dec);
            $rep-&gt;AmountCol(6, 7, $item[2], $dec);
            if ($trans[&#039;TotalAmount&#039;] &gt; 0.0)
                $item[3] = $item[2] - $item[0];
            else
                $item[3] = ($item[2] - $item[1]) * -1;
            if ($show_balance)
                $rep-&gt;AmountCol(7, 8, $accumulate, $dec);
            else
                $rep-&gt;AmountCol(7, 8, $item[3], $dec);
            for ($i = 0; $i &lt; 4; $i++)
            {
                $total[$i] += $item[$i];
                $grandtotal[$i] += $item[$i];
            }
            if ($show_balance)
                $total[3] = $total[1] - $total[0];

                $gl_memo = get_gl_memo($trans[&#039;type&#039;], -round2($trans[&#039;TotalAmount&#039;] * $rate, $dec), $trans[&#039;trans_no&#039;], null, $myrow[&#039;supplier_id&#039;], PT_SUPPLIER);
                $memo = $gl_memo != &quot;&quot; ? $gl_memo : $trans[&#039;memo_&#039;];

                if ($memo &lt;&gt; &quot;&quot;)
                {
                        $rep-&gt;NewLine(1, 2);
                        $rep-&gt;fontSize -= 2;
                        $rep-&gt;TextCol(1, 8,    $memo); // added by faisal
                        $rep-&gt;fontSize += 2;

                }
                $rep-&gt;Line($rep-&gt;row - 2);

        }
        $rep-&gt;Line($rep-&gt;row - 8);

        $rep-&gt;NewLine(2);

        $rep-&gt;TextCol(0, 1, _(&#039;Total Activity&#039;));
        // $rep-&gt;TextCol(2, 6, $myrow[&#039;name&#039;]);
        $rep-&gt;AmountCol(5, 6, $total[0] - $init[0], $dec);
        $rep-&gt;AmountCol(4, 5, $total[1] - $init[1], $dec);

        $rep-&gt;NewLine(2);
        $rep-&gt;TextCol(0, 3,    _(&#039;Total&#039;));
        $rep-&gt;AmountCol(5, 6, $total[0], $dec);
        $rep-&gt;AmountCol(4, 5, $total[1], $dec);

        for ($i = 2; $i &lt; 4; $i++)
        {
            $rep-&gt;AmountCol($i + 4, $i + 5, $total[$i], $dec);
            $total[$i] = 0.0;
        }
        $rep-&gt;Line($rep-&gt;row  - 4);
        $rep-&gt;NewLine(2);
    }
    $rep-&gt;fontSize += 2;
    $rep-&gt;TextCol(0, 3,    _(&#039;Grand Total&#039;));
    $rep-&gt;fontSize -= 2;
    if ($show_balance)
        $grandtotal[3] = $grandtotal[1] - $grandtotal[0];
$rep-&gt;AmountCol(4,  5,$grandtotal[1], $dec);
$rep-&gt;AmountCol(5,  6,$grandtotal[0], $dec);

    for ($i = 2; $i &lt; 4; $i++)
        $rep-&gt;AmountCol($i + 4, $i + 5,$grandtotal[$i], $dec);
    $rep-&gt;Line($rep-&gt;row  - 4);
    $rep-&gt;NewLine();
    $rep-&gt;End();
}

?&gt;</code></pre></div>]]></content>
			<author>
				<name><![CDATA[boxygen]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=20175</uri>
			</author>
			<updated>2023-07-26T02:51:48Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=42451#p42451</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Supplier >> Supplier Balances and Supplier Trial Balances]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=42450#p42450" />
			<content type="html"><![CDATA[<p>Plz check attachment files</p>]]></content>
			<author>
				<name><![CDATA[muzammal83]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=20613</uri>
			</author>
			<updated>2023-07-25T06:47:50Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=42450#p42450</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Supplier >> Supplier Balances and Supplier Trial Balances]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=42449#p42449" />
			<content type="html"><![CDATA[<p>why Debit and Credit Balance difference in Supplier Balances and Supplier Trial Balances Reports</p><p>In Supplier Balances&nbsp; Debit is 565,000 and Credit is 200,000 and Balance is 365,000<br />In Supplier Trial Balances Debit is 200,000 and Credit is 565,000 and balance is -365,000</p><p>plz any one guild me why both report can&#039;t match </p><p>also also check attachment files</p>]]></content>
			<author>
				<name><![CDATA[muzammal83]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=20613</uri>
			</author>
			<updated>2023-07-24T18:38:01Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=42449#p42449</id>
		</entry>
</feed>
