<?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 Can I Merge Customers?]]></title>
		<link>https://frontaccounting.com/punbb/viewtopic.php?id=6961</link>
		<atom:link href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=6961&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in How Can I Merge Customers?.]]></description>
		<lastBuildDate>Fri, 05 Jul 2019 19:15:59 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: How Can I Merge Customers?]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=35384#p35384</link>
			<description><![CDATA[<p>thanks for this, seems to have worked for me.</p><p>For the next person figuring out how to use it; unpack the zip file so that the merge_customers.php file is in your sales directory, then call it from your browser like so:</p><p>http://url.foryour.fa/sales/merge_customers.php</p>]]></description>
			<author><![CDATA[null@example.com (bobloblian)]]></author>
			<pubDate>Fri, 05 Jul 2019 19:15:59 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=35384#p35384</guid>
		</item>
		<item>
			<title><![CDATA[Re: How Can I Merge Customers?]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=28776#p28776</link>
			<description><![CDATA[<p>There are many GL Accounts and Types and any merge will affect a different subset of tables.</p><p>The location redirection does not yet seem to work for the success status message to be displayed and the customer lists to be updated.</p>]]></description>
			<author><![CDATA[null@example.com (apmuthu)]]></author>
			<pubDate>Fri, 29 Sep 2017 06:46:21 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=28776#p28776</guid>
		</item>
		<item>
			<title><![CDATA[Re: How Can I Merge Customers?]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=28772#p28772</link>
			<description><![CDATA[<p>@Apmuthu I have checked it. It is not giving error but Once merged it shall give some message that customers are now merged etc. </p><p>Still I would request to have GL Accounts Merge routine</p>]]></description>
			<author><![CDATA[null@example.com (boxygen)]]></author>
			<pubDate>Fri, 29 Sep 2017 03:17:28 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=28772#p28772</guid>
		</item>
		<item>
			<title><![CDATA[Re: How Can I Merge Customers?]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=28765#p28765</link>
			<description><![CDATA[<p>@boxygen: nice catch.</p><p><a href="https://github.com/apmuthu/frontac24/commit/c286f5915fe2a384b00e369714ef0abd12368bcd">Committed</a> fix in my repo.</p>]]></description>
			<author><![CDATA[null@example.com (apmuthu)]]></author>
			<pubDate>Thu, 28 Sep 2017 13:20:40 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=28765#p28765</guid>
		</item>
		<item>
			<title><![CDATA[Re: How Can I Merge Customers?]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=28758#p28758</link>
			<description><![CDATA[<p>While Merging Customers I got following error</p><p>DATABASE ERROR : An error occured<br />error code : 1054<br />error message : Unknown column &#039;type&#039; in &#039;where clause&#039;<br />sql that failed was : DELETE FROM 0_crm_persons WHERE type = &#039;customer&#039; AND id = (SELECT person_id from 0_crm_contacts WHERE type = &#039;customer&#039; AND entity_id = 4 LIMIT 1)</p>]]></description>
			<author><![CDATA[null@example.com (boxygen)]]></author>
			<pubDate>Thu, 28 Sep 2017 05:47:10 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=28758#p28758</guid>
		</item>
		<item>
			<title><![CDATA[Re: How Can I Merge Customers?]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=28757#p28757</link>
			<description><![CDATA[<p>Can we have something similar to this like Merge GL Accounts?</p>]]></description>
			<author><![CDATA[null@example.com (boxygen)]]></author>
			<pubDate>Thu, 28 Sep 2017 05:38:36 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=28757#p28757</guid>
		</item>
		<item>
			<title><![CDATA[Re: How Can I Merge Customers?]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=28681#p28681</link>
			<description><![CDATA[<p>Revision 2 of the <strong>sales/merge_customers.php</strong> is attached herewith and committed to <a href="https://github.com/apmuthu/frontac24/blob/d59bd008e19883594bd43d43aa3a73293bb7e243/FA24Mods/sales/merge_customers.php">my FA24mods repo</a>.</p><p>Addresses the missing fields listed in 1 by @itronics except the field <strong>gl_trans.person_id</strong> - for some transaction where <strong>person_type_id</strong> is set to PT_CUSTOMER (2).</p><p>Security escalated to <strong>Company Admin</strong>.</p><p>All <em>echo</em> statements replaced by <strong>wrappers</strong>.</p><p>On Merging Customers, the page does not re-compute the select boxes though the merge has been successful - purge cache?</p><p>The additional confirmation message is just displayed since there is no separate select window as in Void Transactions page. Someone can enhance it if necessary.</p><p>Anyone game to make it into a module?</p>]]></description>
			<author><![CDATA[null@example.com (apmuthu)]]></author>
			<pubDate>Thu, 21 Sep 2017 05:01:44 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=28681#p28681</guid>
		</item>
		<item>
			<title><![CDATA[Re: How Can I Merge Customers?]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=28680#p28680</link>
			<description><![CDATA[<p>To the extent possible, I have cleaned up the code and attached it in the 7th post in this thread.</p><p>@itronics: please provide the additions to cover the fields stated.</p><p>As far as the raw echo statements are concerned, it was only a means to illustrate the actual intent by following the <a href="https://en.wikipedia.org/wiki/KISS_principle">KISS principle</a>.</p><p>If there are any security considerations for access levels, then it can be exclusively allotted to the Company Administrator for keeping it in the core.</p>]]></description>
			<author><![CDATA[null@example.com (apmuthu)]]></author>
			<pubDate>Thu, 21 Sep 2017 02:18:27 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=28680#p28680</guid>
		</item>
		<item>
			<title><![CDATA[Re: How Can I Merge Customers?]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=28676#p28676</link>
			<description><![CDATA[<p>The file cannot be included into sources in current form for a couple of reasons:</p><p>1. Some fields in database are not updated leaving it in inconsistent state:<br /> recurrent_invoices.debtor_no<br /> sales_orders.debtor_no, sales_orders.branch_code<br /> gl_trans.person_id - for some transaction where person_type_id is set to PT_CUSTOMER</p><p>2. For security reasons additional access to this feature should be restricted to users with special rights (company admin), so additional access level have to be defined in access_levels.inc and included in sql files. If the file is to be distributed as extension module, this can be defined in module.</p><p>3. Due to potentially disastrous effects, the warning displayed on the page is not enough. Additional confirmation step should be used before customer merging is done. this mechanism is used e.g. in Setup|Void Transaction page, and can be reused here.</p><p>4. The code should be at least roughly consistent with those used in the rest of application (e.g. using defined output helpers instead of raw html echo, or sanitizing sql with db_escape() function). These requirements have kept the code maintainable so far, and we want to continue this in near future.</p><p>Beside that, the feature looks interesting indeed, especially for novice users or in multi-salesman setup, where multiply customer records are not so rare.</p><p>Janusz</p>]]></description>
			<author><![CDATA[null@example.com (itronics)]]></author>
			<pubDate>Wed, 20 Sep 2017 17:54:48 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=28676#p28676</guid>
		</item>
		<item>
			<title><![CDATA[Re: How Can I Merge Customers?]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=28646#p28646</link>
			<description><![CDATA[<p>This is good feature if it comes within core , as like clone, we need an option to merge customers.</p>]]></description>
			<author><![CDATA[null@example.com (kvvaradha)]]></author>
			<pubDate>Sun, 17 Sep 2017 07:50:28 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=28646#p28646</guid>
		</item>
		<item>
			<title><![CDATA[Re: How Can I Merge Customers?]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=28645#p28645</link>
			<description><![CDATA[<p>The <strong>sales/merge_customers.php</strong> file has been updated with TB_PREF and sql_injection protection.</p><p>@joe: can include in core with appropriate menu entry and role permission.</p><p>The same can be done for suppliers and items as well.</p>]]></description>
			<author><![CDATA[null@example.com (apmuthu)]]></author>
			<pubDate>Sun, 17 Sep 2017 03:44:24 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=28645#p28645</guid>
		</item>
		<item>
			<title><![CDATA[Re: How Can I Merge Customers?]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=28615#p28615</link>
			<description><![CDATA[<p>Thanks @apmuthu and @cambell. I&#039;ll update and repost. </p><p>I notice that Journal Entries with 1200 Account Receivables, the customer must be selected. When this customer is merged into another, the transaction is correctly transferred but clicking the ref # of that journal Entry in the new customer, the customer name doesn&#039;t display. Any ideas?</p>]]></description>
			<author><![CDATA[null@example.com (davidkumi)]]></author>
			<pubDate>Wed, 13 Sep 2017 11:33:08 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=28615#p28615</guid>
		</item>
		<item>
			<title><![CDATA[Re: How Can I Merge Customers?]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=28611#p28611</link>
			<description><![CDATA[<p>To avoid sql injection where we know the 2 POST variables are integers, just use:<br /></p><div class="codebox"><pre><code>        $deletecustomer = $_POST[&#039;deletecustomer&#039;]+0;
        $keepcustomer = $_POST[&#039;keepcustomer&#039;]+0;</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (apmuthu)]]></author>
			<pubDate>Tue, 12 Sep 2017 16:21:15 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=28611#p28611</guid>
		</item>
		<item>
			<title><![CDATA[Re: How Can I Merge Customers?]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=28609#p28609</link>
			<description><![CDATA[<p>@davidkumi Well done. :-)&nbsp; Thanks for sharing.&nbsp; Here&#039;s some comments that would make it even better:</p><p>- Instead of &quot;if $keep &amp;&amp; $delete&quot; you could do &quot;if !$keep error if !$delete error&quot;&nbsp; That keeps the error handling consistent and near the top of the module effectively saying &#039;if the input is bad, error out early before proceeding&#039;.</p><p>- There&#039;s no checking on the input data, so you can easily do sql injection here.&nbsp; But, for a one of use, not to worry about that.</p><p>- $result isn&#039;t used in the UPDATE or DELETE queries, so you don&#039;t need it.&nbsp; Just call db_query(...).</p><p>Its not too far off a plugin.&nbsp; Just need to add the menu location and a bit of plugin boiler plate and it would be a plugin.</p>]]></description>
			<author><![CDATA[null@example.com (cambell)]]></author>
			<pubDate>Tue, 12 Sep 2017 15:24:57 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=28609#p28609</guid>
		</item>
		<item>
			<title><![CDATA[Re: How Can I Merge Customers?]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=28608#p28608</link>
			<description><![CDATA[<p>I looked at how it&#039;s done in Quickbooks on youtube and I didn&#039;t like it - copying name of customer you want and pasting over the one you want to merge and delete. So I did it differently. I created the file sales/merge.php and the code as follows:</p><div class="codebox"><pre><code>&lt;?php

$path_to_root = &quot;..&quot;;
$page_security = &#039;SA_CUSTOMER&#039;;

include_once($path_to_root . &quot;/sales/includes/cart_class.inc&quot;);
include_once($path_to_root . &quot;/includes/session.inc&quot;);
include_once($path_to_root . &quot;/sales/includes/sales_ui.inc&quot;);
include_once($path_to_root . &quot;/sales/includes/ui/sales_order_ui.inc&quot;);
include_once($path_to_root . &quot;/sales/includes/sales_db.inc&quot;);
include_once($path_to_root . &quot;/sales/includes/db/sales_types_db.inc&quot;);
include_once($path_to_root . &quot;/reporting/includes/reporting.inc&quot;);
include_once($path_to_root . &quot;/includes/ui/ui_controls.inc&quot;);
include_once($path_to_root . &quot;/includes/date_functions.inc&quot;);
include_once($path_to_root . &quot;/includes/data_checks.inc&quot;);
include_once($path_to_root . &quot;/gl/includes/gl_db.inc&quot;);
include_once($path_to_root . &quot;/sales/includes/db/customers_db.inc&quot;);

$js = &#039;&#039;;

page(&quot;Merge Customers&quot;, false, false, &quot;&quot;, $js);

        $deletecustomer = $_POST[&#039;deletecustomer&#039;];
        $keepcustomer = $_POST[&#039;keepcustomer&#039;];
        
        
        if ($keepcustomer  &amp;&amp; $deletecustomer){                
        
        if ($keepcustomer == $deletecustomer) 
            die(&quot;&lt;center&gt;You chose the same customer in both selections. Cannot merge a customer with himself/herself. &lt;br /&gt;&lt;br /&gt;&lt;a href=\&quot;merge.php\&quot;&gt;Reload&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&quot;);
        $sql = &quot;UPDATE 0_debtor_trans SET `debtor_no` = $keepcustomer, branch_code = (select branch_code from 0_cust_branch where debtor_no = $keepcustomer limit 1) WHERE `debtor_no` = $deletecustomer&quot;;
        $result = db_query($sql, &quot;An error occured&quot;);

        $sql = &quot;UPDATE 0_sales_orders SET `debtor_no` = $keepcustomer, delivery_address = &#039;&#039;, contact_phone = &#039;&#039;, deliver_to = &#039;&#039;, branch_code = (select branch_code from 0_cust_branch where debtor_no = $keepcustomer limit 1) WHERE `debtor_no` = $deletecustomer&quot;;
        $result = db_query($sql, &quot;An error occured&quot;);

        $sql = &quot;UPDATE 0_cust_allocations SET `person_id` = $keepcustomer WHERE `person_id` = $deletecustomer&quot;;
        $result = db_query($sql, &quot;An error occured&quot;);

        $sql = &quot;DELETE FROM 0_debtors_master where debtor_no = $deletecustomer&quot;; 
        $result = db_query($sql, &quot;An error occured&quot;);

        $sql = &quot;DELETE FROM 0_cust_branch where debtor_no = $deletecustomer&quot;; 
        $result = db_query($sql, &quot;An error occured&quot;);

        $sql = &quot;DELETE FROM 0_crm_contacts where type = &#039;customer&#039; AND entity_id = $deletecustomer&quot;; 
        $result = db_query($sql, &quot;An error occured&quot;);

        $sql = &quot;DELETE FROM 0_crm_contacts where type = &#039;cust_branch&#039; AND entity_id = (select branch_code from 0_cust_branch where debtor_no = $deletecustomer)&quot;; 
        $result = db_query($sql, &quot;An error occured&quot;);

        $sql = &quot;DELETE FROM 0_crm_persons where type = &#039;customer&#039; AND id = (select person_id from 0_crm_contacts where type = &#039;customer&#039; AND entity_id = $deletecustomer limit 1)&quot;; 
        $result = db_query($sql, &quot;An error occured&quot;);
        
    header(&quot;Location: ..&quot;);
        }

    $sql = &quot;SELECT  debtor_no,  name FROM  `0_debtors_master`  ORDER BY &#039;name&#039; ASC &quot;;
    $result = db_query($sql, &quot;An error occured&quot;);
echo &quot;&lt;form method=\&quot;post\&quot;&gt;&quot;;
echo &quot;&lt;center&gt;&lt;br /&gt;&lt;br /&gt;&lt;b class=\&quot;headingtext\&quot;&gt;NOTE: THIS ACTION IS IRREVOCABLE&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;table style= \&quot;width:70% \&quot;&gt;  &lt;tr&gt;  &lt;td colspan= \&quot;6 \&quot;&gt;Merge &amp; Delete this customer&lt;/td&gt;  &lt;th&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;  &lt;/th&gt;  &lt;td colspan= \&quot;6 \&quot;&gt;Keep this customer&lt;/td&gt;   &lt;/tr&gt;  &lt;tr&gt;  &lt;td colspan= \&quot;6 \&quot;&gt;&lt;select id= \&quot;deletecustomer\&quot; name= \&quot;deletecustomer\&quot; class= \&quot;combo2 \&quot; title= \&quot;Merge &amp; Delete customer \&quot; _last= \&quot;14 \&quot;&gt;&quot;;

    while ($myrow = db_fetch($result))
    {
        echo &quot;&lt;option value= \&quot;&quot; . $myrow[&#039;debtor_no&#039;] . &quot; \&quot;&gt;&quot; . $myrow[&#039;name&#039;] . &quot; &lt;/option&gt;&quot;; 
    }

    echo &quot;&lt;/select&gt;&lt;/td&gt;  &lt;td colspan= \&quot;2 \&quot;&gt;&lt;font size= \&quot;6 \&quot;&gt; &amp;nbsp; &amp;nbsp; &amp;rArr; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/font&gt; &lt;/td&gt;&lt;td colspan= \&quot;6 \&quot;&gt;&lt;select id= \&quot;keepcustomer\&quot; name= \&quot;keepcustomer\&quot; class= \&quot;combo2 \&quot; title= \&quot;Merge &amp; keep customer \&quot; _last= \&quot;14 \&quot;&gt;&quot;;
    
    
    $sql = &quot;SELECT  debtor_no,  name FROM  `0_debtors_master`  ORDER BY &#039;name&#039; ASC &quot;;
    $result = db_query($sql, &quot;An error occured&quot;);
        while ($myrow = db_fetch($result))
    {
        //echo $myrow[&#039;debtor_no&#039;] . &quot; &quot; . $myrow[&#039;name&#039;] . &quot;&lt;br /&gt;&quot;;
        echo &quot;&lt;option value= \&quot;&quot; . $myrow[&#039;debtor_no&#039;] . &quot; \&quot;&gt;&quot; . $myrow[&#039;name&#039;] . &quot; &lt;/option&gt;&quot;; 
    }
    
    echo &quot;&lt;/select&gt;&lt;/td&gt;  &lt;/tr&gt;&quot;;


echo &quot;&lt;/table&gt;&quot;;

echo &quot;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;input type=\&quot;submit\&quot; value=\&quot; Merge Customers \&quot;&gt; &amp;nbsp; &amp;nbsp; &lt;input type=\&quot;submit\&quot; formaction=\&quot;..\&quot; value=\&quot; Cancel \&quot; &gt; &lt;/center&gt;&quot;;
//&amp;nbsp; &amp;nbsp; &lt;input type=\&quot;submit\&quot; formaction=\&quot;..\&quot; value=\&quot; Cancel \&quot; &gt;
echo &quot;&lt;/form&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&quot;;

end_page();</code></pre></div><p>As much as I can see, it works fine. Any Comments?</p>]]></description>
			<author><![CDATA[null@example.com (davidkumi)]]></author>
			<pubDate>Tue, 12 Sep 2017 14:29:02 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=28608#p28608</guid>
		</item>
	</channel>
</rss>
