<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[FrontAccounting forum — Customer Ledger as Inquiry]]></title>
	<link rel="self" href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=7994&amp;type=atom" />
	<updated>2019-02-13T05:57:01Z</updated>
	<generator>PunBB</generator>
	<id>https://frontaccounting.com/punbb/viewtopic.php?id=7994</id>
		<entry>
			<title type="html"><![CDATA[Customer Ledger as Inquiry]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=34228#p34228" />
			<content type="html"><![CDATA[<p>Here is the Code for Customer Ledger as Inquiry. For quick review of Customer&#039;s Ledger this is useful.</p><p><a href="https://prnt.sc/mkds90">Here</a> is the screen shot</p><div class="codebox"><pre><code>&lt;?php
/**********************************************************************
    Copyright (C) FrontAccounting, 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_GLTRANSVIEW&#039;;
$path_to_root = &quot;../..&quot;;
include_once($path_to_root . &quot;/includes/session.inc&quot;);

include($path_to_root . &quot;/includes/db_pager.inc&quot;);

include_once($path_to_root . &quot;/admin/db/fiscalyears_db.inc&quot;);
include_once($path_to_root . &quot;/includes/date_functions.inc&quot;);
include_once($path_to_root . &quot;/includes/ui.inc&quot;);
include_once($path_to_root . &quot;/includes/data_checks.inc&quot;);
include_once($path_to_root . &quot;/modules/party_ledger/includes/addon.inc&quot;);// added by faisal

include_once($path_to_root . &quot;/gl/includes/gl_db.inc&quot;);

$js = &#039;&#039;;
set_focus(&#039;account&#039;);
if ($SysPrefs-&gt;use_popup_windows)
    $js .= get_js_open_window(800, 500);
if (user_use_date_picker())
    $js .= get_js_date_picker();

page(_($help_context = &quot;General Ledger Inquiry&quot;), false, false, &#039;&#039;, $js);

//----------------------------------------------------------------------------------------------------
// Ajax updates
//
if (get_post(&#039;Show&#039;))
{
    $Ajax-&gt;activate(&#039;trans_tbl&#039;);
}

if (isset($_GET[&quot;account&quot;]))
    $_POST[&quot;account&quot;] = $_GET[&quot;account&quot;];
if (isset($_GET[&quot;TransFromDate&quot;]))
    $_POST[&quot;TransFromDate&quot;] = $_GET[&quot;TransFromDate&quot;];
if (isset($_GET[&quot;TransToDate&quot;]))
    $_POST[&quot;TransToDate&quot;] = $_GET[&quot;TransToDate&quot;];
if (isset($_GET[&quot;Dimension&quot;]))
    $_POST[&quot;Dimension&quot;] = $_GET[&quot;Dimension&quot;];
if (isset($_GET[&quot;Dimension2&quot;]))
    $_POST[&quot;Dimension2&quot;] = $_GET[&quot;Dimension2&quot;];
if (isset($_GET[&quot;amount_min&quot;]))
    $_POST[&quot;amount_min&quot;] = $_GET[&quot;amount_min&quot;];
if (isset($_GET[&quot;amount_max&quot;]))
    $_POST[&quot;amount_max&quot;] = $_GET[&quot;amount_max&quot;];

if (!isset($_POST[&quot;amount_min&quot;]))
    $_POST[&quot;amount_min&quot;] = price_format(0);
if (!isset($_POST[&quot;amount_max&quot;]))
    $_POST[&quot;amount_max&quot;] = price_format(0);

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

function gl_inquiry_controls()
{
    $dim = get_company_pref(&#039;use_dimension&#039;);
    start_form();

    start_table(TABLESTYLE_NOBORDER);
    start_row();
    //modified below by faisal
    // gl_all_accounts_list_cells(_(&quot;Account:&quot;), &#039;account&#039;, null, false, false, _(&quot;All Accounts&quot;));
    customer_list_cells(_(&#039;Select customer&#039;), &#039;customer_id&#039;, null, false, true); //Edited by Phuong(Flat theme)
    hidden(&#039;account&#039;, get_company_pref(&#039;debtors_act&#039;));
    //faisal modification ends
    date_cells(_(&quot;from:&quot;), &#039;TransFromDate&#039;, &#039;&#039;, null, -user_transaction_days());
    date_cells(_(&quot;to:&quot;), &#039;TransToDate&#039;);
    end_row();
    end_table();

    start_table(TABLESTYLE_NOBORDER);
    start_row();
    if ($dim &gt;= 1)
        dimensions_list_cells(_(&quot;Dimension&quot;).&quot; 1:&quot;, &#039;Dimension&#039;, null, true, &quot; &quot;, false, 1);
    if ($dim &gt; 1)
        dimensions_list_cells(_(&quot;Dimension&quot;).&quot; 2:&quot;, &#039;Dimension2&#039;, null, true, &quot; &quot;, false, 2);

    ref_cells(_(&quot;Memo:&quot;), &#039;Memo&#039;, &#039;&#039;,null, _(&#039;Enter memo fragment or leave empty&#039;));
    small_amount_cells(_(&quot;Amount min:&quot;), &#039;amount_min&#039;, null, &quot; &quot;);
    small_amount_cells(_(&quot;Amount max:&quot;), &#039;amount_max&#039;, null, &quot; &quot;);
    check_cells( _(&quot;By Entry Date:&quot;), &#039;ByEntryDate&#039;, null);//added by faisal for Search by Entry Date

    submit_cells(&#039;Show&#039;,_(&quot;Show&quot;),&#039;&#039;,&#039;&#039;, &#039;default&#039;);
    end_row();
    end_table();

    echo &#039;&lt;hr&gt;&#039;;
    end_form();
}

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

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

    if (!isset($_POST[&quot;account&quot;]))
        $_POST[&quot;account&quot;] = null;

    $act_name = $_POST[&quot;account&quot;] ? get_gl_account_name($_POST[&quot;account&quot;]) : &quot;&quot;;
    $dim = get_company_pref(&#039;use_dimension&#039;);

    /*Now get the transactions  */
    if (!isset($_POST[&#039;Dimension&#039;]))
        $_POST[&#039;Dimension&#039;] = 0;
    if (!isset($_POST[&#039;Dimension2&#039;]))
        $_POST[&#039;Dimension2&#039;] = 0;
            $result = get_gl_transactions($_POST[&#039;TransFromDate&#039;], $_POST[&#039;TransToDate&#039;], -1,
                $_POST[&quot;account&quot;], $_POST[&#039;Dimension&#039;], $_POST[&#039;Dimension2&#039;], null,
                input_num(&#039;amount_min&#039;), input_num(&#039;amount_max&#039;),PT_CUSTOMER, $_POST[&#039;customer_id&#039;], $_POST[&#039;Memo&#039;], check_value(&#039;ByEntryDate&#039;)); //modified by faisal


            $colspan = ($dim == 2 ? &quot;8&quot; : ($dim == 1 ? &quot;5&quot; : &quot;4&quot;)); //modified by faisal to accommodate entrydate

    if ($_POST[&quot;account&quot;] != null)
        display_heading($_POST[&quot;account&quot;]. &quot;   &quot;.$act_name);

    // Only show balances if an account is specified AND we&#039;re not filtering by amounts
    $show_balances = $_POST[&quot;account&quot;] != null &amp;&amp;
                     input_num(&quot;amount_min&quot;) == 0 &amp;&amp;
                     input_num(&quot;amount_max&quot;) == 0;

    start_table(TABLESTYLE);

    $first_cols = array(_(&quot;Type&quot;), _(&quot;#&quot;),_(&quot;Reference&quot;), _(&quot;Date&quot;), _(&quot;Entry Date&quot;));

    if ($_POST[&quot;account&quot;] == null)
        $account_col = array(_(&quot;Account&quot;));
    else
        $account_col = array();

    if ($dim == 2)
        $dim_cols = array(_(&quot;Dimension&quot;).&quot; 1&quot;, _(&quot;Dimension&quot;).&quot; 2&quot;);
    elseif ($dim == 1)
        $dim_cols = array(_(&quot;Dimension&quot;));
    else
        $dim_cols = array();

    if ($show_balances)
        $remaining_cols = array(_(&quot;Person/Item&quot;), _(&quot;Debit&quot;), _(&quot;Credit&quot;), _(&quot;Balance&quot;), _(&quot;Memo&quot;), &quot;&quot;);
    else
        $remaining_cols = array(_(&quot;Person/Item&quot;), _(&quot;Debit&quot;), _(&quot;Credit&quot;), _(&quot;Memo&quot;), &quot;&quot;);

    $th = array_merge($first_cols, $account_col, $dim_cols, $remaining_cols);

    table_header($th);
    if ($_POST[&quot;account&quot;] != null &amp;&amp; is_account_balancesheet($_POST[&quot;account&quot;]))
        $begin = &quot;&quot;;
    else
    {
        $begin = get_fiscalyear_begin_for_date($_POST[&#039;TransFromDate&#039;]);
        if (date1_greater_date2($begin, $_POST[&#039;TransFromDate&#039;]))
            $begin = $_POST[&#039;TransFromDate&#039;];
        $begin = add_days($begin, -1);
    }

    $bfw = 0;
    if ($show_balances) {
        $bfw = bx_get_gl_balance_from_to($begin, $_POST[&#039;TransFromDate&#039;], $_POST[&quot;account&quot;], $_POST[&#039;Dimension&#039;], $_POST[&#039;Dimension2&#039;], $_POST[&#039;customer_id&#039;]); //modified by faisal
        start_row(&quot;class=&#039;inquirybg&#039;&quot;);
        label_cell(&quot;&lt;b&gt;&quot;._(&quot;Opening Balance&quot;).&quot; - &quot;.$_POST[&#039;TransFromDate&#039;].&quot;&lt;/b&gt;&quot;, &quot;colspan=$colspan&quot;);
        display_debit_or_credit_cells($bfw, true);
            //below block added by faisal
            if ($bfw&gt;0)
        {
            $debit_total += $bfw;
        }
        else
        {
            $credit_total += ABS($bfw);
        }
        label_cell(&quot;&quot;);
        label_cell(&quot;&quot;);
        end_row();
    }

    $running_total = $bfw;
    $j = 1;
    $k = 0; //row colour counter
    $debit_total = 0; //added by faisal
    $credit_total =0;


    while ($myrow = db_fetch($result))
    {

        alt_table_row_color($k);

        $running_total += $myrow[&quot;amount&quot;];

            //below block added by faisal
            if ($myrow[&quot;amount&quot;]&gt;0)
        {
            $debit_total += $myrow[&quot;amount&quot;];
        }
        else
        {
            $credit_total += ABS($myrow[&quot;amount&quot;]);
        }

        $trandate = sql2date($myrow[&quot;tran_date&quot;]);
            $entrydate = sql2date($myrow[&quot;stamp&quot;]); //added by faisal


        label_cell($systypes_array[$myrow[&quot;type&quot;]]);
        label_cell(get_gl_view_str($myrow[&quot;type&quot;], $myrow[&quot;type_no&quot;], $myrow[&quot;type_no&quot;], true));
        label_cell(get_trans_view_str($myrow[&quot;type&quot;],$myrow[&quot;type_no&quot;],$myrow[&#039;reference&#039;]));
        label_cell($trandate);
            label_cell($entrydate); //added by faisal


        if ($_POST[&quot;account&quot;] == null)
            label_cell($myrow[&quot;account&quot;] . &#039; &#039; . get_gl_account_name($myrow[&quot;account&quot;]));

        if ($dim &gt;= 1)
            label_cell(get_dimension_string($myrow[&#039;dimension_id&#039;], true));
        if ($dim &gt; 1)
            label_cell(get_dimension_string($myrow[&#039;dimension2_id&#039;], true));
        label_cell(payment_person_name($myrow[&quot;person_type_id&quot;],$myrow[&quot;person_id&quot;]));
        display_debit_or_credit_cells($myrow[&quot;amount&quot;]);
        if ($show_balances)
            amount_cell($running_total);
        if ($myrow[&#039;memo_&#039;] == &quot;&quot;)
            $myrow[&#039;memo_&#039;] = get_comments_string($myrow[&#039;type&#039;], $myrow[&#039;type_no&#039;]);
        label_cell($myrow[&#039;memo_&#039;]);
        if ($myrow[&quot;type&quot;] == ST_JOURNAL)
            echo &quot;&lt;td&gt;&quot; . trans_editor_link( $myrow[&quot;type&quot;], $myrow[&quot;type_no&quot;]) . &quot;&lt;/td&gt;&quot;;
        else
            label_cell(&quot;&quot;);
        end_row();

        $j++;
        if ($j == 12)
        {
            $j = 1;
            table_header($th);
        }
    }
    //end of while loop

    if ($show_balances) {
        start_row(&quot;class=&#039;inquirybg&#039;&quot;);
        label_cell(&quot;&lt;b&gt;&quot; . _(&quot;Ending Balance&quot;) .&quot; - &quot;.$_POST[&#039;TransToDate&#039;]. &quot;&lt;/b&gt;&quot;, &quot;colspan=$colspan&quot;);
            amount_cell($debit_total);
            amount_cell($credit_total); //Added to display Debit and Creidt Total by Faisal
             // display_debit_or_credit_cells($running_total, true); //commented by faisal
        label_cell(&quot;&quot;);
        label_cell(&quot;&quot;);
        end_row();
    }

    end_table(2);
    if (db_num_rows($result) == 0)
        display_note(_(&quot;No general ledger transactions have been created for the specified criteria.&quot;), 0, 1);

}

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

gl_inquiry_controls();

div_start(&#039;trans_tbl&#039;);

if (get_post(&#039;Show&#039;) || get_post(&#039;account&#039;))
    show_results();

div_end();

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

end_page();</code></pre></div><p>This page uses following function </p><div class="codebox"><pre><code>function bx_get_gl_balance_from_to($from_date, $to_date, $account, $dimension=0, $dimension2=0, $person_id=null)
{
    $from = date2sql($from_date);
    $to = date2sql($to_date);

    $sql = &quot;SELECT SUM(amount) FROM &quot;.TB_PREF.&quot;gl_trans
        WHERE account=&#039;$account&#039;&quot;;
    if ($from_date != &quot;&quot;)
        $sql .= &quot;  AND tran_date &gt; &#039;$from&#039;&quot;;
    if ($to_date != &quot;&quot;)
        $sql .= &quot;  AND tran_date &lt; &#039;$to&#039;&quot;;
    if ($dimension != 0)
          $sql .= &quot; AND dimension_id = &quot;.($dimension&lt;0 ? 0 : db_escape($dimension));
    if ($dimension2 != 0)
          $sql .= &quot; AND dimension2_id = &quot;.($dimension2&lt;0 ? 0 : db_escape($dimension2));

        if ($person_id)
                $sql .= &quot; AND person_id=&quot;.db_escape($person_id);

    $result = db_query($sql, &quot;The starting balance for account $account could not be calculated&quot;);

    $row = db_fetch_row($result);
    return $row[0];
}</code></pre></div><p>core Function <strong>get_gl_transactions</strong> is customized to view ledger ByEntryDate. Sometimes it is needed for Audit purpose. If you dont&#039; want to update core then rename it and use for this Inquiry module.</p><div class="codebox"><pre><code>function get_gl_transactions($from_date, $to_date, $trans_no=0,
    $account=null, $dimension=0, $dimension2=0, $filter_type=null,
    $amount_min=null, $amount_max=null,$person_type=null, $person_id=null, $memo = &#039;&#039;, $byentrydate=0) //argument added by faisal
{
    global $SysPrefs;

    $from = date2sql($from_date);
    $to = date2sql($to_date);

//added a.stamp by faisal

if ($byentrydate == false)
{
                $sql = &quot;SELECT gl.*, a.stamp, j.event_date, j.doc_date, a.gl_seq, u.user_id, st.supp_reference, gl.person_id subcode,
                        IFNULL(IFNULL(sup.supp_name, debt.name), bt.person_id) as person_name,
                        IFNULL(gl.person_id, IFNULL(sup.supplier_id, IFNULL(debt.debtor_no, bt.person_id))) as person_id,
            IF(gl.person_id, gl.person_type_id, IF(sup.supplier_id,&quot;.  PT_SUPPLIER . &quot;,&quot; .  &quot;IF(debt.debtor_no,&quot; . PT_CUSTOMER . &quot;,&quot; .
            &quot;IF(bt.person_id != &#039;&#039; AND !ISNULL(bt.person_id), bt.person_type_id, -1)))) as person_type_id,
                        IFNULL(st.tran_date, IFNULL(dt.tran_date, IFNULL(bt.trans_date, IFNULL(grn.delivery_date, gl.tran_date)))) as doc_date,
                        coa.account_name, ref.reference, IF(ISNULL(c.memo_), gl.memo_, CONCAT(gl.memo_,&#039; &#039;,c.memo_)) AS memo
                         FROM &quot;
                        .TB_PREF.&quot;gl_trans gl
                        LEFT JOIN &quot;.TB_PREF.&quot;voided v ON gl.type_no=v.id AND v.type=gl.type

                        LEFT JOIN &quot;.TB_PREF.&quot;supp_trans st ON gl.type_no=st.trans_no AND st.type=gl.type AND (gl.type NOT IN (&quot;.ST_JOURNAL.&quot;,&quot;.ST_BULKDEPOSIT.&quot;) OR gl.person_id=st.supplier_id)
                        LEFT JOIN &quot;.TB_PREF.&quot;grn_batch grn ON grn.id=gl.type_no AND gl.type=&quot;.ST_SUPPRECEIVE.&quot;
                        LEFT JOIN &quot;.TB_PREF.&quot;debtor_trans dt ON gl.type_no=dt.trans_no AND dt.type=gl.type AND (gl.type NOT IN (&quot;.ST_JOURNAL.&quot;,&quot;.ST_BULKDEPOSIT.&quot;) OR gl.person_id=dt.debtor_no)

                        LEFT JOIN &quot;.TB_PREF.&quot;suppliers sup ON st.supplier_id=sup.supplier_id
                        LEFT JOIN &quot;.TB_PREF.&quot;cust_branch branch ON dt.branch_code=branch.branch_code
                        LEFT JOIN &quot;.TB_PREF.&quot;debtors_master debt ON dt.debtor_no=debt.debtor_no

                        LEFT JOIN &quot;.TB_PREF.&quot;bank_trans bt ON bt.type=gl.type AND bt.trans_no=gl.type_no AND bt.amount!=0
                        AND (bt.person_id != &#039;&#039; AND !ISNULL(bt.person_id))

                        LEFT JOIN &quot;.TB_PREF.&quot;journal j ON j.type=gl.type AND j.trans_no=gl.type_no
                        LEFT JOIN &quot;.TB_PREF.&quot;audit_trail a ON a.type=gl.type AND a.trans_no=gl.type_no AND NOT ISNULL(gl_seq)
                        LEFT JOIN &quot;.TB_PREF.&quot;users u ON a.user=u.id
                        LEFT JOIN &quot;.TB_PREF.&quot;comments c ON c.id=gl.type_no AND c.type=gl.type

                        LEFT JOIN &quot;.TB_PREF.&quot;refs ref ON ref.type=gl.type AND ref.id=gl.type_no,&quot;
                    .TB_PREF.&quot;chart_master coa
                    WHERE coa.account_code=gl.account
                    AND ISNULL(v.date_)
                    AND gl.tran_date &gt;= &#039;$from&#039;
                    AND gl.tran_date &lt;= &#039;$to&#039;
                     AND gl.amount &lt;&gt; 0&quot;;

                    if ($trans_no &gt; 0)
            $sql .= &quot; AND gl.type_no LIKE &quot;.db_escape(&#039;%&#039;.$trans_no);;
        if ($account != null)
            $sql .= &quot; AND gl.account = &quot;.db_escape($account);
        if ($dimension != 0)
            $sql .= &quot; AND gl.dimension_id = &quot;.($dimension&lt;0 ? 0 : db_escape($dimension));
        if ($dimension2 != 0)
            $sql .= &quot; AND gl.dimension2_id = &quot;.($dimension2&lt;0 ? 0 : db_escape($dimension2));
        if ($filter_type != null)
            $sql .= &quot; AND gl.type IN (&quot; . $filter_type .&quot;)&quot;;
        if ($amount_min != null)
            $sql .= &quot; AND ABS(gl.amount) &gt;= ABS(&quot;.db_escape($amount_min).&quot;)&quot;;

        if ($amount_max != null)
            $sql .= &quot; AND ABS(gl.amount) &lt;= ABS(&quot;.db_escape($amount_max).&quot;)&quot;;
        if ($memo)
            $sql .= &quot; AND (gl.memo_ LIKE &quot;. db_escape(&quot;%$memo%&quot;) . &quot; OR c.memo_ LIKE &quot; . db_escape(&quot;%$memo%&quot;) . &quot;)&quot;;
        $sql .= &quot; GROUP BY counter&quot;;
        $sql .= &quot; HAVING TRUE&quot;;
        if ($person_type != 0)
                $sql .= &quot; AND person_type_id=&quot;.db_escape($person_type);
        if ($person_id != 0)
                $sql .= &quot; AND person_id=&quot;.db_escape($person_id);
        $sql .= &quot; ORDER BY tran_date, counter&quot;;
}
else {
                $sql = &quot;SELECT gl.*, a.stamp, j.event_date, j.doc_date, a.gl_seq, u.user_id, st.supp_reference, gl.person_id subcode,
                        IFNULL(IFNULL(sup.supp_name, debt.name), bt.person_id) as person_name,
                        IFNULL(gl.person_id, IFNULL(sup.supplier_id, IFNULL(debt.debtor_no, bt.person_id))) as person_id,
            IF(gl.person_id, gl.person_type_id, IF(sup.supplier_id,&quot;.  PT_SUPPLIER . &quot;,&quot; .  &quot;IF(debt.debtor_no,&quot; . PT_CUSTOMER . &quot;,&quot; .
            &quot;IF(bt.person_id != &#039;&#039; AND !ISNULL(bt.person_id), bt.person_type_id, -1)))) as person_type_id,
                        IFNULL(st.tran_date, IFNULL(dt.tran_date, IFNULL(bt.trans_date, IFNULL(grn.delivery_date, gl.tran_date)))) as doc_date,
                        coa.account_name, ref.reference, IF(ISNULL(c.memo_), gl.memo_, CONCAT(gl.memo_,&#039; &#039;,c.memo_)) AS memo
                         FROM &quot;
                        .TB_PREF.&quot;gl_trans gl
                        LEFT JOIN &quot;.TB_PREF.&quot;voided v ON gl.type_no=v.id AND v.type=gl.type

                        LEFT JOIN &quot;.TB_PREF.&quot;supp_trans st ON gl.type_no=st.trans_no AND st.type=gl.type AND (gl.type NOT IN (&quot;.ST_JOURNAL.&quot;,&quot;.ST_BULKDEPOSIT.&quot;) OR gl.person_id=st.supplier_id)
                        LEFT JOIN &quot;.TB_PREF.&quot;grn_batch grn ON grn.id=gl.type_no AND gl.type=&quot;.ST_SUPPRECEIVE.&quot; AND gl.person_id=grn.supplier_id
                        LEFT JOIN &quot;.TB_PREF.&quot;debtor_trans dt ON gl.type_no=dt.trans_no AND dt.type=gl.type AND (gl.type NOT IN (&quot;.ST_JOURNAL.&quot;,&quot;.ST_BULKDEPOSIT.&quot;) OR gl.person_id=dt.debtor_no)

                        LEFT JOIN &quot;.TB_PREF.&quot;suppliers sup ON st.supplier_id=sup.supplier_id OR grn.supplier_id=sup.supplier_id
                        LEFT JOIN &quot;.TB_PREF.&quot;cust_branch branch ON dt.branch_code=branch.branch_code
                        LEFT JOIN &quot;.TB_PREF.&quot;debtors_master debt ON dt.debtor_no=debt.debtor_no

                        LEFT JOIN &quot;.TB_PREF.&quot;bank_trans bt ON bt.type=gl.type AND bt.trans_no=gl.type_no AND bt.amount!=0
                             AND bt.person_type_id=gl.person_type_id AND bt.person_id=gl.person_id

                        LEFT JOIN &quot;.TB_PREF.&quot;journal j ON j.type=gl.type AND j.trans_no=gl.type_no
                        LEFT JOIN &quot;.TB_PREF.&quot;audit_trail a ON a.type=gl.type AND a.trans_no=gl.type_no AND NOT ISNULL(gl_seq)
                        LEFT JOIN &quot;.TB_PREF.&quot;users u ON a.user=u.id
                     LEFT JOIN &quot;.TB_PREF.&quot;comments c ON c.id=gl.type_no AND c.type=gl.type

                        LEFT JOIN &quot;.TB_PREF.&quot;refs ref ON ref.type=gl.type AND ref.id=gl.type_no,&quot;
                    .TB_PREF.&quot;chart_master coa
                    WHERE coa.account_code=gl.account
                    AND ISNULL(v.date_)
                    AND a.stamp &gt;= &#039;$from&#039;
                    AND a.stamp &lt;= &#039;$to&#039;
                     AND gl.amount &lt;&gt; 0&quot;;

                    if ($trans_no &gt; 0)
                $sql .= &quot; AND gl.type_no LIKE &quot;.db_escape(&#039;%&#039;.$trans_no);;
            if ($account != null)
                $sql .= &quot; AND gl.account = &quot;.db_escape($account);
            if ($dimension != 0)
                $sql .= &quot; AND gl.dimension_id = &quot;.($dimension&lt;0 ? 0 : db_escape($dimension));
            if ($dimension2 != 0)
                $sql .= &quot; AND gl.dimension2_id = &quot;.($dimension2&lt;0 ? 0 : db_escape($dimension2));
            if ($filter_type != null)
                $sql .= &quot; AND gl.type IN (&quot; . $filter_type .&quot;)&quot;;
            if ($amount_min != null)
                $sql .= &quot; AND ABS(gl.amount) &gt;= ABS(&quot;.db_escape($amount_min).&quot;)&quot;;

            if ($amount_max != null)
                $sql .= &quot; AND ABS(gl.amount) &lt;= ABS(&quot;.db_escape($amount_max).&quot;)&quot;;
            if ($memo)
                $sql .= &quot; AND (gl.memo_ LIKE &quot;. db_escape(&quot;%$memo%&quot;) . &quot; OR c.memo_ LIKE &quot; . db_escape(&quot;%$memo%&quot;) . &quot;)&quot;;
            $sql .= &quot; GROUP BY counter&quot;;
            $sql .= &quot; HAVING TRUE&quot;;
            if ($person_type != 0)
                    $sql .= &quot; AND person_type_id=&quot;.db_escape($person_type);
            if ($person_id != 0)
                    $sql .= &quot; AND person_id=&quot;.db_escape($person_id);
            $sql .= &quot; ORDER BY tran_date, counter&quot;;
            return db_query($sql, &quot;The transactions for could not be retrieved&quot;);
}

    return db_query($sql, &quot;The transactions for could not be retrieved&quot;);
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[boxygen]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=20175</uri>
			</author>
			<updated>2019-02-13T05:57:01Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=34228#p34228</id>
		</entry>
</feed>
