<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[FrontAccounting forum — How to run the final SQL query]]></title>
		<link>https://frontaccounting.com/punbb/viewtopic.php?id=7399</link>
		<atom:link href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=7399&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in How to run the final SQL query.]]></description>
		<lastBuildDate>Wed, 14 Mar 2018 15:00:45 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: How to run the final SQL query]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=31116#p31116</link>
			<description><![CDATA[<p>The TB_PREF is a constant defined as the value of the <strong>tbpref</strong> array element in the appropriate company# in the <strong>config_db.php</strong> file. It is the table prefix for your database instance used for the company under reference, generally: 0_, 1_, etc.</p><p>All <strong>PT_*</strong> and <strong>ST_*</strong> constants among others are defined in <strong>includes/types.inc</strong> file.</p><p>The hard coded date and other parts of the sql are generally taken from the SysPrefs object or from various form fields the scripts interact with.</p>]]></description>
			<author><![CDATA[null@example.com (apmuthu)]]></author>
			<pubDate>Wed, 14 Mar 2018 15:00:45 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=31116#p31116</guid>
		</item>
		<item>
			<title><![CDATA[How to run the final SQL query]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=31114#p31114</link>
			<description><![CDATA[<p>I&#039;m new to FA, and have some information about PHP and SQL. Now I want to run the SQL query in my FA database but have some problems. In the following query what are the TB_PREF, PT_SUPPLIER, PT_CUSTOMER and other constants? And in case if I want to have them replaced, what are the values?<br /></p><div class="codebox"><pre><code>SELECT gl.*, 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, debt.debtor_no)) 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;, -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
             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!=&quot;.ST_JOURNAL.&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!=&quot;.ST_JOURNAL.&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;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;01.14.2018&#039;
        AND gl.tran_date &lt;= &#039;02.14.2018&#039;
        AND gl.amount &lt;&gt; 0&quot;</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (nashmil.b)]]></author>
			<pubDate>Wed, 14 Mar 2018 11:27:34 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=31114#p31114</guid>
		</item>
	</channel>
</rss>
