<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[FrontAccounting forum — close_transactions() silently overwrites audit_trail.stamp]]></title>
	<link rel="self" href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=10725&amp;type=atom" />
	<updated>2026-05-12T15:22:50Z</updated>
	<generator>PunBB</generator>
	<id>https://frontaccounting.com/punbb/viewtopic.php?id=10725</id>
		<entry>
			<title type="html"><![CDATA[close_transactions() silently overwrites audit_trail.stamp]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=43865#p43865" />
			<content type="html"><![CDATA[<p>After closing an old fiscal year, I noticed `0_audit_trail.stamp` had been rewritten to &quot;now&quot; for every row whose `gl_seq` was updated by the close routine. Rows the close didn&#039;t touch kept their original stamps. This destroys the historical creation timestamp for every GL transaction in the closing year, and breaks any report that relies on `audit_trail.stamp`.</p><p>Two innocent pieces interacting:</p><p>1. `0_audit_trail.stamp` is defined as `TIMESTAMP ... ON UPDATE CURRENT_TIMESTAMP` (FA default, used to track edit time).<br />2.&nbsp; close_transactions() in `includes/db/audit_trail_db.inc` runs `UPDATE 0_audit_trail SET gl_seq=$seq WHERE id=...</p><p>The UPDATE only sets `gl_seq`, but MySQL auto-refreshes `stamp` as a side effect of the `ON UPDATE` clause. The `if ($row[&#039;gl_seq&#039;] != $seq)` guard is why only some rows get hit — exactly the ones being re-sequenced.</p><p>I tried fixing it with the following change</p><p>$sql2 = &quot;UPDATE &quot;.TB_PREF.&quot;audit_trail SET&quot;<br />&nbsp; &nbsp; . &quot; gl_seq=$seq&quot;<br />&nbsp; &nbsp; . &quot; WHERE id=&quot;.$row[&#039;id&#039;];</p><p>to:</p><p>$sql2 = &quot;UPDATE &quot;.TB_PREF.&quot;audit_trail SET&quot;<br />&nbsp; &nbsp; . &quot; gl_seq=$seq,&quot;<br />&nbsp; &nbsp; . &quot; stamp=stamp&quot; // preserve original timestamp<br />&nbsp; &nbsp; . &quot; WHERE id=&quot;.$row[&#039;id&#039;];</p><p>Explicitly listing `stamp` in the SET clause suppresses the `ON UPDATE CURRENT_TIMESTAMP` auto-refresh in MySQL. No schema change needed, and normal `add_audit_trail()` edits are unaffected since they already set `stamp` explicitly.</p><p>Has anyone else hit this? Kindly share your experience.</p><p>Thanks</p>]]></content>
			<author>
				<name><![CDATA[dz]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=44997</uri>
			</author>
			<updated>2026-05-12T15:22:50Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=43865#p43865</id>
		</entry>
</feed>
