<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[FrontAccounting forum — Error when trying to edit Journal Entry]]></title>
	<link rel="self" href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=5686&amp;type=atom" />
	<updated>2015-04-24T00:55:51Z</updated>
	<generator>PunBB</generator>
	<id>https://frontaccounting.com/punbb/viewtopic.php?id=5686</id>
		<entry>
			<title type="html"><![CDATA[Re: Error when trying to edit Journal Entry]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=23330#p23330" />
			<content type="html"><![CDATA[<p>Changes in config file values to reflect in FA may need a logout and login again if session variables are depended upon.</p><p>Your workaround could be useful for others till the dev fixes it. Thanks.</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2015-04-24T00:55:51Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=23330#p23330</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Error when trying to edit Journal Entry]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=23295#p23295" />
			<content type="html"><![CDATA[<p>Hi apmuthu,</p><p>I&#039;ve applied the patch you suggested, still no luck.<br />My <strong>config.php</strong> has <strong>$go_debug = 0</strong> however the error still shows up.<br />You&#039;re right, the import failed to create entries in the <strong>debtor_trans</strong> table so that&#039;s why when I click the edit button it fails to bring the edit screen up.</p><p>In the mean time I have upgraded to FA 2.3.24 and now the window that pops up instead of showing the error shows a blank page! I can only get the error from the <strong>error.log</strong> file.</p><p>What I ended up doing is update the entries in the <strong>bank_trans</strong> table and changed the <strong>person_type_id</strong> from 2 to 0 for these transactions.<br />Ion</p>]]></content>
			<author>
				<name><![CDATA[ion]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=18154</uri>
			</author>
			<updated>2015-04-15T13:56:33Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=23295#p23295</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Error when trying to edit Journal Entry]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=23195#p23195" />
			<content type="html"><![CDATA[<p>It is possible that you imported your customer without an entry in the debtors_master table or more likely your debtor_trans table&#039;s import did not go well.</p><p>Your SQL has been reformatted for execution in the en_US-demo CoA as Company 1:<br /></p><div class="codebox"><pre><code>SELECT trans.*
      ,ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount AS Total
      ,cust.name AS DebtorName
      , cust.address
      , cust.curr_code
      , cust.tax_id
      , com.memo_
      , bank_act
      , bank_accounts.bank_name
      , bank_accounts.bank_account_name
      , bank_accounts.account_type AS BankTransType
      , bank_accounts.bank_curr_code
      , bank_trans.amount AS bank_amount 
FROM 1_debtor_trans trans 
    LEFT JOIN 1_comments com ON trans.type=com.type AND trans.trans_no=com.id 
    LEFT JOIN 1_shippers shippers ON shippers.shipper_id=trans.ship_via
    , 1_debtors_master cust
    , 1_bank_trans bank_trans
    , 1_bank_accounts bank_accounts
WHERE trans.trans_no=&#039;360&#039; 
  AND trans.type=&#039;2&#039; 
  AND trans.debtor_no=cust.debtor_no 
  AND bank_trans.trans_no =&#039;360&#039; 
  AND bank_trans.type=2 
  AND bank_trans.amount != 0 
  AND bank_accounts.id=bank_trans.bank_act;</code></pre></div><p>The source of this SQL is in the file <strong>core/sales/includes/db/cust_trans_db.inc</strong> in <strong>function get_customer_trans($trans_id, $trans_type)</strong>. The said error comes up only when <strong>$go_debug = 1</strong> is set in <strong>config.php</strong>.</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2015-04-09T14:29:02Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=23195#p23195</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Error when trying to edit Journal Entry]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=23181#p23181" />
			<content type="html"><![CDATA[<p>The following is the main fix for the journal inquiry issue since we need to remove NULLs in the SQLs:<br /></p><div class="codebox"><pre><code>--- gl/includes/db/gl_db_trans.inc    Fri Jan 16 08:56:28 1970
+++ gl/includes/db/gl_db_trans.inc    Fri Jan 16 08:56:28 1970
@@ -605,14 +605,14 @@
 function get_sql_for_journal_inquiry($filter, $from, $to, $ref=&#039;&#039;, $memo=&#039;&#039;, $alsoclosed=false)
 {
 
-    $sql = &quot;SELECT    IF(ISNULL(a.gl_seq),0,a.gl_seq) as gl_seq,
+    $sql = &quot;SELECT    COALESCE(a.gl_seq,0) as gl_seq,
         gl.tran_date,
         gl.type,
         gl.type_no,
-        refs.reference,
+        COALESCE(refs.reference,&#039;&#039;) AS reference,
         SUM(IF(gl.amount&gt;0, gl.amount,0)) as amount,
-        com.memo_,
-        IF(ISNULL(u.user_id),&#039;&#039;,u.user_id) as user_id
+        COALESCE(com.memo_,&#039;&#039;) AS memo_,
+        COALESCE(u.user_id,&#039;&#039;) as user_id
         FROM &quot;.TB_PREF.&quot;gl_trans as gl
          LEFT JOIN &quot;.TB_PREF.&quot;audit_trail as a ON
             (gl.type=a.type AND gl.type_no=a.trans_no)
@@ -625,11 +625,11 @@
         WHERE gl.tran_date &gt;= &#039;&quot; . date2sql($from) . &quot;&#039;
         AND gl.tran_date &lt;= &#039;&quot; . date2sql($to) . &quot;&#039;
         AND gl.amount!=0&quot;;
-    if ($ref) {
-        $sql .= &quot; AND reference LIKE &quot;. db_escape(&quot;%$ref%&quot;);
+    if (!empty($ref)) {
+        $sql .= &quot; AND refs.reference LIKE &#039;%&quot;. db_escape($ref) . &quot;%&#039;&quot;;
     }
-    if ($memo) {
-        $sql .= &quot; AND com.memo_ LIKE &quot;. db_escape(&quot;%$memo%&quot;);
+    if (!empty($memo)) {
+        $sql .= &quot; AND com.memo_ LIKE &#039;%&quot;. db_escape($memo) . &quot;%&#039;&quot;;
     }
     if ($filter != -1) {
         $sql .= &quot; AND gl.type=&quot;.db_escape($filter);</code></pre></div><p>Now we also need to tolerate NULLs in fields in GROUP BY statements which otherwise evaluate to a count of 0 records in the db_pager.inc and make sure that no negative LIMIT is part of the SELECT clause since the first value of the page is 0 and on deducting 1 for previous page will return a negative number causing the sql to end in <strong>LIMIT -10, 10</strong>:<br /></p><div class="codebox"><pre><code>--- includes/db_pager.inc    Fri Jan 16 08:56:28 1970
+++ includes/db_pager.inc    Fri Jan 16 08:56:28 1970
@@ -325,6 +325,7 @@
 
         $page_len = $this-&gt;page_len;
         $offset = ($this-&gt;curr_page - 1) * $page_len;
+        $offset = ($offset &lt; 0 ? 0 : $offset);
 
         $sql .= &quot; LIMIT $offset, $page_len&quot;;
 
@@ -345,11 +346,19 @@
                 return false;
             $row = db_fetch_row($result);
             $this-&gt;rec_count = $row[0];
+             // 2015-04-09 apmuthu: try original sql since count = 0 if group by clause has NULLs
+            if (!$row[0] &amp;&amp; !empty($this-&gt;group)) {
+                $sql = $this-&gt;_sql_gen(false);
+                $result = db_query($sql, &#039;Error reading record set&#039;);
+                if ($result == false) 
+                    return false;
+                $this-&gt;rec_count = db_num_rows($result);
+            }
               $this-&gt;max_page = $this-&gt;page_len ?
                 ceil($this-&gt;rec_count/$this-&gt;page_len) : 0;
         
             if ($go_debug) { // FIX - need column name parsing, but for now:
-                // check if field names are set explicite in col def
+                // check if field names are set explicitly in col def
                 // for all initially ordered columns
                 foreach ($this-&gt;columns as $col) {
                        if (isset($col[&#039;ord&#039;]) &amp;&amp; $col[&#039;ord&#039;] != &#039;&#039; </code></pre></div>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2015-04-08T23:17:37Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=23181#p23181</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Error when trying to edit Journal Entry]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=23178#p23178" />
			<content type="html"><![CDATA[<p>Under &#039;Banking and General Ledger/Journal Inquiry&#039; I have a list of journal entries. For most of the entries, when I select the edit icon a new window opens that allows me to edit the entry.</p><p>However, I have a couple of entries for which the windows that comes up shows the following error:<br /></p><div class="quotebox"><blockquote><p>DATABASE ERROR : no debtor trans found for given params<br />sql that failed was : SELECT trans.*,ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount AS Total,cust.name AS DebtorName, cust.address, cust.curr_code, cust.tax_id, com.memo_,bank_act,bank_accounts.bank_name, bank_accounts.bank_account_name, bank_accounts.account_type AS BankTransType, bank_accounts.bank_curr_code, bank_trans.amount as bank_amount FROM debtor_trans trans LEFT JOIN comments com ON trans.type=com.type AND trans.trans_no=com.id LEFT JOIN shippers ON shippers.shipper_id=trans.ship_via, debtors_master cust, bank_trans, bank_accounts WHERE trans.trans_no=&#039;360&#039; AND trans.type=&#039;2&#039; AND trans.debtor_no=cust.debtor_no AND bank_trans.trans_no =&#039;360&#039; AND bank_trans.type=2 AND bank_trans.amount != 0 AND bank_accounts.id=bank_trans.bank_act</p></blockquote></div><p>I checked the debtor_trans table and it&#039;s empty.<br />Any suggestion on how to fix this?</p><p>At least one of the transactions was entered with the import transaction module (I don&#039;t know if this makes a difference).<br />I am using FA 2.3.22.<br />Any input would be appreciated.<br />Thanks,<br />Ion</p>]]></content>
			<author>
				<name><![CDATA[ion]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=18154</uri>
			</author>
			<updated>2015-04-08T20:36:39Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=23178#p23178</id>
		</entry>
</feed>
