<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[FrontAccounting forum — Better sql construct in sales/includes/db/sales_order_db.inc]]></title>
	<link rel="self" href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=10393&amp;type=atom" />
	<updated>2023-11-18T20:59:20Z</updated>
	<generator>PunBB</generator>
	<id>https://frontaccounting.com/punbb/viewtopic.php?id=10393</id>
		<entry>
			<title type="html"><![CDATA[Re: Better sql construct in sales/includes/db/sales_order_db.inc]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=42713#p42713" />
			<content type="html"><![CDATA[<p>It doesn&#039;t appear to have been pushed into the GitHub repo yet <strong><a href="https://github.com/FrontAccountingERP/FA/blob/master/sales/includes/db/sales_order_db.inc">here.</a></strong> but is available in the <a href="https://sourceforge.net/p/frontaccounting/git/ci/6c40a3be4a79826087d7abbdd11b483f19decc2a/tree/sales/includes/db/sales_order_db.inc?diff=0b44975d1b3c8f3e3fb28d24d8b45b1a6f71d12c">SF.net repo</a>. Hope the GitHub repo gets synched correctly in time.</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2023-11-18T20:59:20Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=42713#p42713</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Better sql construct in sales/includes/db/sales_order_db.inc]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=42694#p42694" />
			<content type="html"><![CDATA[<p>This has been pushed to stable repo. Thanks.</p><p>Joe</p>]]></content>
			<author>
				<name><![CDATA[joe]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=3</uri>
			</author>
			<updated>2023-11-15T09:10:34Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=42694#p42694</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Better sql construct in sales/includes/db/sales_order_db.inc]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=42692#p42692" />
			<content type="html"><![CDATA[<p>Thanks</p>]]></content>
			<author>
				<name><![CDATA[boxygen]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=20175</uri>
			</author>
			<updated>2023-11-15T04:04:05Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=42692#p42692</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Better sql construct in sales/includes/db/sales_order_db.inc]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=42633#p42633" />
			<content type="html"><![CDATA[<p>At the end of the file <strong>sales/includes/db/sales_order_db.inc</strong> we have:<br /></p><div class="codebox"><pre><code>function last_sales_order_detail($order, $field)
{
        $sql = &quot;SELECT $field
            FROM &quot;.TB_PREF.&quot;sales_order_details d
            WHERE order_no =
            (SELECT order_no FROM &quot;.TB_PREF.&quot;sales_orders o
            WHERE debtor_no=&quot; . db_escape($order-&gt;customer_id) . &quot;
            ORDER BY order_no DESC LIMIT 1)
            ORDER BY d.id DESC LIMIT 1&quot;;        

        $last_query=db_query($sql, &quot;Could not retrieve last order detail&quot;);
        $row = db_fetch_row($last_query);
        return $row == false ? false : $row[0];
}</code></pre></div><p>Kindly change it to:</p><div class="codebox"><pre><code>function last_sales_order_detail($order, $field)
{
        $sql = &quot;SELECT $field
            FROM &quot;.TB_PREF.&quot;sales_order_details d
            LEFT JOIN &quot; .TB_PREF.&quot;sales_orders o on d.order_no=o.order_no
            WHERE debtor_no=&quot; . db_escape($order-&gt;customer_id) . &quot;
            ORDER BY d.id DESC LIMIT 1&quot;;

        $last_query=db_query($sql, &quot;Could not retrieve last order detail&quot;);
        $row = db_fetch_row($last_query);
        return $row == false ? false : $row[0];
}</code></pre></div><p>It uses a left join instead of a secondary select.</p><p>The <strong>on d.order_no=o.order_no</strong> can become <strong>USING (order_no)</strong> to further optimise it.</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2023-10-27T18:47:39Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=42633#p42633</id>
		</entry>
</feed>
