<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[FrontAccounting forum — Utility to clear the transaction tables while testing - here's how]]></title>
	<link rel="self" href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=426&amp;type=atom" />
	<updated>2010-01-26T16:40:22Z</updated>
	<generator>PunBB</generator>
	<id>https://frontaccounting.com/punbb/viewtopic.php?id=426</id>
		<entry>
			<title type="html"><![CDATA[Re: Utility to clear the transaction tables while testing - here's how]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=4558#p4558" />
			<content type="html"><![CDATA[<p>Thanks P2409! Saved me a lot of time and effort using your script. Thought I would post an update to your work. I&#039;m using version 2.2.4 so I&#039;ve added a few tables to your list and corrected some errors (including the use of the wrong password variable in the connection function). </p><p>&lt;?php</p><p>// Clear out all frontaccounting transactions<br />// Leaves customers/bank accounts alone, but removes all transaction items<br />// BE CAREFUL YOU WILL LOSE YOUR TRANSACTION DATA IF YOU RUN THIS SCRIPT<br />// BACKUP BEFORE YOU RUN IT!!!<br />// IF YOU DON&#039;T KNOW EXACTLY WHAT YOUR ARE DOING, DON&#039;T RUN THIS SCRIPT</p><br /><p>// ask for input<br />fwrite(STDOUT, &quot;Enter your MySQL FrontAccounting database name: &quot;);<br />// get input<br />$db = trim(fgets(STDIN));</p><p>fwrite(STDOUT, &quot;Enter your Company Number eg. 1, 2 etc: &quot;);<br />// get input<br />$company_number = trim(fgets(STDIN));</p><p>// ask for input<br />fwrite(STDOUT, &quot;Enter your MySQL host (usually localhost): &quot;);<br />// get input<br />$host = trim(fgets(STDIN));</p><p>fwrite(STDOUT, &quot;Enter your MySQL user id: &quot;);<br />// get input<br />$userid = trim(fgets(STDIN));</p><p>fwrite(STDOUT, &quot;Enter your MySQL password: &quot;);<br />// get input<br />$pword = trim(fgets(STDIN));</p><p>// Confirmation - must be Y in capitals, or I stop right here.<br />fwrite(STDOUT, &quot;You are going to clear the FrontAccounting transactions for database : $db company number : $company_number\n&quot; . &quot;Are you absolutely sure you want to do this? (Y/N)&quot;);<br />$confirm = trim(fgets(STDIN));<br />if ($confirm!=&quot;Y&quot;) {<br />&nbsp; &nbsp; echo &quot;OK...aborting\n&quot;;<br />&nbsp; &nbsp; exit();<br />}</p><p>$conn = mysql_connect($host,$userid,$pword); //&lt;---enter your host, user id and password for MySQL here<br />if ($conn==null) {<br />&nbsp; &nbsp; echo &quot;Could not connect to MySQL with the host/username/password you provided. Try again.\n&quot;;<br />&nbsp; &nbsp; exit();<br />}<br />$tbllist = array();<br />// Here&#039;s the magic - read the end of this file into an array that contains the table names<br />// you want to clear.<br />$tbllist = split(&quot;\n&quot;,file_get_contents(__FILE__, NULL, NULL,&nbsp; __COMPILER_HALT_OFFSET__));</p><p>// Remove first entry - it&#039;s just a carriage return.<br />unset($tbllist[0]);</p><p>// Process each table clearing it.<br />foreach ($tbllist as $tbl) {<br />&nbsp; &nbsp; if (substr($tbl,0,1)!=&quot;#&quot;) run_delete_qry($tbl);<br />}<br />echo &quot;Finished clearing transaction tables\n&quot;;<br />exit();<br />// A function to clear data from a table you specify<br />function run_delete_qry($tblname) {<br />&nbsp; &nbsp; global $db;<br />&nbsp; &nbsp; global $conn;<br />&nbsp; &nbsp; global $company_number;<br />&nbsp; &nbsp; $sql = &quot;delete from &quot; . $company_number . &quot;_&quot; . $tblname ;<br />&nbsp; &nbsp; $result = mysql_db_query($db,$sql);<br />&nbsp; &nbsp; if ($result!=1) {<br />&nbsp; &nbsp; &nbsp; &nbsp; echo &quot;Warning: SQL statement &quot; . $sql . &quot; failed\n&quot;;<br />&nbsp; &nbsp; &nbsp; &nbsp; echo &quot;with an error message of &quot; . mysql_errno() . mysql_error(mysql_errno());<br />//&nbsp; &nbsp; &nbsp; &nbsp; mysql_close($conn);<br />&nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; return;<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; echo &quot;Cleared &quot; . $company_number . &quot;_&quot; . $tblname . &quot;\n&quot;;<br />}<br />__HALT_COMPILER();<br /># Tables you want to clear go here<br /># Comments start with the pound sign<br />gl_trans<br />bank_trans<br />debtor_trans<br />debtor_trans_details<br />trans_tax_details<br />purch_orders<br />purch_order_details<br />sales_orders<br />sales_order_details<br />wo_issues<br />wo_issue_items<br />wo_manufacture<br />wo_requirements<br />supp_invoice_items<br />trans_tax_details<br />supp_allocations<br />grn_batch<br />grn_items<br />audit_trail<br />voided<br />refs<br />comments</p>]]></content>
			<author>
				<name><![CDATA[rtoddsullivan]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=622</uri>
			</author>
			<updated>2010-01-26T16:40:22Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=4558#p4558</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Utility to clear the transaction tables while testing - here's how]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=1938#p1938" />
			<content type="html"><![CDATA[<p>Hi p2409,</p><p>I tried using your script to clear up the transactions but I get an error:</p><p>&quot;Parse error: parse error in E:\inetpub\path..to..script.php on line 79&quot;</p><p>Line 79 is in the section with the table list.</p><p>We&#039;re using 2.1 beta and php 4</p><p>Just wondering if there&#039;s I can do to solve this because it would be a handy script.</p><p>Thanks!</p>]]></content>
			<author>
				<name><![CDATA[MozMan]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=247</uri>
			</author>
			<updated>2009-03-10T02:14:21Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=1938#p1938</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Utility to clear the transaction tables while testing - here's how]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=1595#p1595" />
			<content type="html"><![CDATA[<p>Nice, thanks for sharing. For this purpose I&#039;ve been restoring a clean database but this is a good idea as an alternative.</p><p>Kind regards.</p>]]></content>
			<author>
				<name><![CDATA[MozMan]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=247</uri>
			</author>
			<updated>2008-12-31T04:06:11Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=1595#p1595</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Utility to clear the transaction tables while testing - here's how]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=1508#p1508" />
			<content type="html"><![CDATA[<p>Hi Guys<br />I wrote this little PHP script to delete transaction data (only) from my company while I setup FrontAccounting. It leaves you customers, chart of accounts intact, but does remove all transactional info. I&#039;ve tried to pick the most relevant table, if you know of others that should be cleared, post them here and I&#039;ll update. If you want to do this yourself, just add them to the end of the script file.</p><br /><p>WARNING WARNING WARNING!!!<br />Know what you are doing before you run this script. It will permanently delete transaction data!!!! If you don&#039;t know what this means, or what it&#039;s for DON&#039;T run it.</p><p>Here&#039;s the PHP file - save it with an ending .php and run from command line.</p><p>// START CODE<br />&lt;?php</p><p>// Clear out all frontaccounting transactions<br />// Leaves customers/bank accounts alone, but removes all transaction items<br />// BE CAREFUL YOU WILL LOSE YOUR TRANSACTION DATA IF YOU RUN THIS SCRIPT<br />// BACKUP BEFORE YOU RUN IT!!!<br />// IF YOU DON&#039;T KNOW EXACTLY WHAT YOUR ARE DOING, DON&#039;T RUN THIS SCRIPT</p><br /><p>// ask for input<br />fwrite(STDOUT, &quot;Enter your MySQL FrontAccounting database name: &quot;);<br />// get input<br />$db = trim(fgets(STDIN));</p><p>fwrite(STDOUT, &quot;Enter your Company Number eg. 1, 2 etc: &quot;);<br />// get input<br />$company_number = trim(fgets(STDIN));</p><p>// ask for input<br />fwrite(STDOUT, &quot;Enter your MySQL host (usually localhost): &quot;);<br />// get input<br />$host = trim(fgets(STDIN));</p><p>fwrite(STDOUT, &quot;Enter your MySQL user id: &quot;);<br />// get input<br />$userid = trim(fgets(STDIN));</p><p>fwrite(STDOUT, &quot;Enter your MySQL password: &quot;);<br />// get input<br />$pword = trim(fgets(STDIN));</p><p>// Confirmation - must be Y in capitals, or I stop right here.<br />fwrite(STDOUT, &quot;You are going to clear the FrontAccounting transactions for database : $db company number : $company_number\n&quot; . &quot;Are you absolutely sure you want to do this? (Y/N)&quot;);<br />$confirm = trim(fgets(STDIN));<br />if ($confirm!=&quot;Y&quot;) {<br />&nbsp; &nbsp; echo &quot;OK...aborting\n&quot;;<br />&nbsp; &nbsp; exit();<br />}</p><p>$conn = mysql_connect($host,$userid,$password); //&lt;---enter your host, user id and password for MySQL here<br />if ($conn==null) {<br />&nbsp; &nbsp; echo &quot;Could not connect to MySQL with the host/username/password you provided. Try again.\n&quot;;<br />&nbsp; &nbsp; exit();<br />}<br />$tbllist = array();<br />// Here&#039;s the magic - read the end of this file into an array that contains the table names<br />// you want to clear.<br />$tbllist = split(&quot;\n&quot;,file_get_contents(__FILE__, NULL, NULL,&nbsp; __COMPILER_HALT_OFFSET__));</p><p>// Remove first entry - it&#039;s just a carriage return.<br />unset($tbllist[0]);</p><p>// Process each table clearing it.<br />foreach ($tbllist as $tbl) {<br />&nbsp; &nbsp; if (substr($tbl,0,1)!=&quot;#&quot;) run_delete_qry($tbl);<br />}<br />echo &quot;Finished clearing transaction tables\n&quot;;<br />exit();<br />// A function to clear data from a table you specify<br />function run_delete_qry($tblname) {<br />&nbsp; &nbsp; global $db;<br />&nbsp; &nbsp; global $conn;<br />&nbsp; &nbsp; global $company_number;<br />&nbsp; &nbsp; $sql = &quot;delete from &quot; . $company_number . &quot;_&quot; . $tblname ;<br />&nbsp; &nbsp; $result = mysql_db_query($db,$sql);<br />&nbsp; &nbsp; if ($result!=1) {<br />&nbsp; &nbsp; &nbsp; &nbsp; echo &quot;Warning: SQL statement &quot; . $sql . &quot; failed\n&quot;;<br />&nbsp; &nbsp; &nbsp; &nbsp; echo &quot;with an error message of &quot; . mysql_errno() . mysql_error(mysql_errno());<br />&nbsp; &nbsp; &nbsp; &nbsp; mysql_close($conn);<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; return;<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; echo &quot;Cleared &quot; . $company_number . &quot;_&quot; . $tblname . &quot;\n&quot;;<br />}<br />__HALT_COMPILER();<br /># Tables you want to clear go here<br /># Comments start with the pound sign<br />gl_trans<br />bank_trans<br />debtor_trans<br />debtor_trans_details<br />debtor_trans_tax_details<br />purch_orders<br />purch_order_details<br />sales_orders<br />sales_order_details<br />wo_issues<br />wo_issue_items<br />wo_manufacture<br />wo_requirements<br />supp_invoice_items<br />supp_invoice_tax_items<br />supp_allocations<br />grn_batch<br />grn_items</p>]]></content>
			<author>
				<name><![CDATA[p2409]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=267</uri>
			</author>
			<updated>2008-12-17T06:36:08Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=1508#p1508</id>
		</entry>
</feed>
