<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[FrontAccounting forum — email single invoice to multiple recipients]]></title>
	<link rel="self" href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=5258&amp;type=atom" />
	<updated>2015-02-09T11:59:56Z</updated>
	<generator>PunBB</generator>
	<id>https://frontaccounting.com/punbb/viewtopic.php?id=5258</id>
		<entry>
			<title type="html"><![CDATA[Re: email single invoice to multiple recipients]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22459#p22459" />
			<content type="html"><![CDATA[<p>Just tested out the multiple contacts availability by setting the last parameter $default=false in the get_branch_contacts() function call in rep107.php. Did a dump of the $contacts array before the function call and the $rep-&gt;contactData property after the function call with the $default parameter set to true (single) and false (multiple) and attached the outputs herein.</p><p>Hence set the last parameter in <strong>get_branch_contacts()</strong> to <span class="bbu">false</span> if you want multiple mailing and leave it at <span class="bbu">true</span> for single email.</p><p>The sequence of customer and branch creation is as follows:<br />1. Sales =&gt; Add and Manage Customers =&gt; Added New Customer with email id.<br />2. Customer Branches =&gt; Select Customer =&gt; Edit Customer Branch =&gt; Contacts =&gt; Add 2 New Contacts For Branch<br /> =&gt; Invoice and General Type with email id<br /> =&gt; Invoice and Orders Type with email id<br />3. Sales =&gt; Direct Invoice =&gt; Make an invoice for the customer branch.<br />4. Sales =&gt; Customer and Sales Reports =&gt; Print Invoices =. Choose to email customers and select the newly created invoice and Display Print Invoice (after setting rep107.php last parameter in get_branch_contacts() to false).</p><p>Works as expected - emails to 3 different recipients but separate emails.</p><p>@joe: Your logic is sound. Tested it out as well and it corroborates well - the NewPage is the one that actually gives effect to&nbsp; the Tmpl setting and it&#039;s sequence anywhere prior to it is immaterial.</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2015-02-09T11:59:56Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22459#p22459</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: email single invoice to multiple recipients]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22453#p22453" />
			<content type="html"><![CDATA[<p>@apmuthu</p><p>Hello again.</p><p>The member function Header2() is called in the member function NewPage on line 944 in pdf_report.inc.</p><p>Therefore it doesn&#039;t matter if the SetHeaderType member function is placed Before or after the SetCommonData member function.</p><p>/Joe</p>]]></content>
			<author>
				<name><![CDATA[joe]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=3</uri>
			</author>
			<updated>2015-02-09T10:12:37Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22453#p22453</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: email single invoice to multiple recipients]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22451#p22451" />
			<content type="html"><![CDATA[<p>@joe: I stand corrected that the Tmpl inclusion is needed for other reasons. The <strong>$rep-&gt;SetHeaderType(&#039;Header2&#039;)</strong> &quot;includes&quot; the <strong>header2.inc</strong> and <strong>doctext.inc</strong> files. These included files <a href="https://frontaccounting.com/punbb/viewtopic.php?id=5428">refer to data obtained in SetCommonData()</a> which is useful for including non field db data as illustrated in the <a href="https://frontaccounting.com/fawiki/index.php?n=Help.BinLocationsInPackingList">wiki for Bin Location</a> type of functionality. </p><p>In this instance in rep107.php (Invoicing), $contacts is populated with data from the get_branch_contacts() function and is passed on as an argument into the $rep-&gt;SetCommonData() method which in turn populates the $this-&gt;formData and $this-&gt;contactData properties which in turn is used to get the contacts to email the reports to. In fact the SetCommonData() method makes even a single email id into an array, ie., $this-&gt;contactData.</p><p>Will investigate further....</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2015-02-09T09:02:58Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22451#p22451</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: email single invoice to multiple recipients]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22450#p22450" />
			<content type="html"><![CDATA[<p>@apmuthu</p><p>Why are we moving the SetHeaderTmpl to be after SetCommonData? As I can see in the code there is no call to Header2() before a NewPage is initiated. The SetHeaderTmpl is only setting the HeaderTmpl.</p><p>The NewPage call is after the SetCommonData.</p><p>So in my Point of view this is not necessary. I guess this was not necessary in 2.4 either, although it does not harm anything.</p><p>/Joe</p>]]></content>
			<author>
				<name><![CDATA[joe]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=3</uri>
			</author>
			<updated>2015-02-09T08:08:44Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22450#p22450</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: email single invoice to multiple recipients]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22446#p22446" />
			<content type="html"><![CDATA[<p>@bobloblian: Let&#039;s see what line 978 onwards in reporting/includes/pdf_report.inc has:<br /></p><div class="codebox"><pre><code>                $contactData = array();
                if ($this-&gt;contactData)
                    foreach($this-&gt;contactData as $contact)
                        if (!empty($contact[&#039;email&#039;]))
                            $contactData[] = $contact;

                if(!count($contactData)) {
                    $this-&gt;SetLang(user_language());
                    display_warning(sprintf(_(&quot;You have no email contact defined for this type of document for &#039;%s&#039;.&quot;), $this-&gt;formData[&#039;recipient_name&#039;]));
                } else {
                    $sent = $try = 0;</code></pre></div><p>Only if there was no email available would you get the error stated<br /></p><div class="quotebox"><blockquote><p>You have no email contact defined for this type of document for &#039;Computerisms&#039;.</p></blockquote></div><p>Therefore in the incoming <strong>$this-&gt;contactData</strong> itself, there would be no such record with email contact details and that narrows it down to the output of the <strong>get_branch_contacts()</strong> function. A check on with and without the last parameter being <strong>false</strong> will reveal that when it is true, the defaults have kicked in and not the appropriate contact for the specified action type. Try adding more than one contact to the branch where you choose it to be of <strong>invoice</strong> type (rep107.php) and then see what happens on making the last parameter <strong>false</strong>.</p><p><s>Please note that you will need to<a href="http://https:/sourceforge.net/p/frontaccounting/mercurial/ci/be33f6596e36a6ee7dcbad9f9b224c4a4c2197c4/tree/reporting/rep107.php?diff=6cfd2b4fb655cf3c37093aeb0fe752bd35a7a110">backport</a>some report fixes from FA 2.4 since the SetCommonData() method needs to precede the Header2() call in reports that call it. This is necessary because the property $this-&gt;contactData is assigned from the $contact in line 409 and the latter comes from the said method SetCommonData() which in turn gets it from the get_branch_contacts() function call in rep107.php a couple of lines earlier.</s></p><p><s>@joe: the backports of the repXXX.php files done on 2015-01-21 is hence necessary.</s></p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2015-02-09T06:01:19Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22446#p22446</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: email single invoice to multiple recipients]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22443#p22443" />
			<content type="html"><![CDATA[<p>Even if it did work - and I have no idea if it does - it would still send one message to each recipient. </p><p>Message creation (in reporting/includes/pdf_report.inc) needs to be moved out of the foreach loop, with the approriate headers (&quot;to&quot; and/or &quot;cc&quot;) being added as the script loops over the contacts array.</p>]]></content>
			<author>
				<name><![CDATA[tm]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=17873</uri>
			</author>
			<updated>2015-02-08T23:17:52Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22443#p22443</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: email single invoice to multiple recipients]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22442#p22442" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>apmuthu wrote:</cite><blockquote><p><span class="bbu">Hence currently, no code change is required except for setting the last parameter as <strong>false</strong> in reports that need to be emailed to multiple entities!</span></p></blockquote></div><p>Either I am misunderstanding what this means, or this is not the case.</p><p>I think this means that in rep107.php if I change this line:</p><p>$contacts = get_branch_contacts($branch[&#039;branch_code&#039;], &#039;invoice&#039;, $branch[&#039;debtor_no&#039;], true);</p><p>to this:</p><p>$contacts = get_branch_contacts($branch[&#039;branch_code&#039;], &#039;invoice&#039;, $branch[&#039;debtor_no&#039;], false);</p><p>the mail should send to both contacts.&nbsp; I had actually tried this before, based on the content of one of the posts you pointed me at earlier.&nbsp; If I put the sales/includes/db/branches_db.inc file back to how it was originally and change true to false as described above, it throws this error on the screen when I send an email:</p><p>You have no email contact defined for this type of document for &#039;Computerisms&#039;.</p><p>If I am misunderstanding, can you please clarify?</p>]]></content>
			<author>
				<name><![CDATA[bobloblian]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=19664</uri>
			</author>
			<updated>2015-02-08T22:12:50Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22442#p22442</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: email single invoice to multiple recipients]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22439#p22439" />
			<content type="html"><![CDATA[<p>It&#039;s probably cleaner to have separate functions for single and multiple contacts. In particular, it will establish which contact is the &quot;primary&quot; one and future developers won&#039;t have to guess.</p>]]></content>
			<author>
				<name><![CDATA[tm]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=17873</uri>
			</author>
			<updated>2015-02-08T12:32:02Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22439#p22439</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: email single invoice to multiple recipients]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22437#p22437" />
			<content type="html"><![CDATA[<p>Whilst getting all contacts and using it for emailing (To, Cc, Bcc, etc) is fine, getting only one contact is important for report printing and for use in the FA user interface screens.</p><p>Currently, the <em>function <strong>get_branch_contacts</strong></em> is used in:<br /></p><div class="codebox"><pre><code>sales/includes/ui/sales_order_ui.inc
repXXX.php
where XXX in 103 (commented out), 107 (Invoice), 108 (commented out), 109  through to 113.</code></pre></div><p>In the extensions, rep_email_customers calls it in <a href="http://devel.frontaccounting.com/git/?p=email_customers.git;a=blob;f=reporting/rep_email_customers.php;h=1e9716aed3566d13fe6361b3d96b689038233733;hb=refs/heads/master">modules/reporting/rep_email_customers/includes/customer_emailer.inc</a> with the last parameter as <strong>false</strong> (no defaults). Also, when the second parameter ($action) is set to null as in this file, all contacts accrue.</p><p>In <strong>sales/includes/ui/sales_order_ui.inc</strong> the following construct in lines 112-114:<br /></p><div class="codebox"><pre><code>    $contact = get_branch_contacts($branch_id, &#039;order&#039;, $customer_id);
    $order-&gt;set_branch($branch_id, $myrow[&quot;tax_group_id&quot;],
    $myrow[&quot;tax_group_name&quot;], @$contact[&quot;phone&quot;], @$contact[&quot;email&quot;]);</code></pre></div><p>expect to have defaults (missing last parameter assumed $default as true) and restricted to the &#039;orders&#039; type alone and is used as a <strong>single contact</strong> for populating the branch details alone.</p><p>The standard repXXX.php listed above use the following constructs:<br /></p><div class="codebox"><pre><code>rep107.php:
$contacts = get_branch_contacts($branch[&#039;branch_code&#039;], &#039;invoice&#039;, $branch[&#039;debtor_no&#039;], true);

rep109.php:
$contacts = get_branch_contacts($branch[&#039;branch_code&#039;], &#039;order&#039;, $branch[&#039;debtor_no&#039;], true);

rep110.php:
$contacts = get_branch_contacts($branch[&#039;branch_code&#039;], &#039;delivery&#039;, $branch[&#039;debtor_no&#039;], true);

rep111.php:
$contacts = get_branch_contacts($branch[&#039;branch_code&#039;], &#039;order&#039;, $branch[&#039;debtor_no&#039;], true);

rep112.php:
$contacts = get_branch_contacts($myrow[&#039;branch_code&#039;], &#039;invoice&#039;, $myrow[&#039;debtor_no&#039;]);

rep113.php:
$contacts = get_branch_contacts($branch[&#039;branch_code&#039;], &#039;invoice&#039;, $branch[&#039;debtor_no&#039;], true);</code></pre></div><p>which makes last parameter $default to be true but allows for (but currently does not obtain) multiple contacts in subsequent emailing usage alone.</p><p>Either we determine it to be a single contact (count elements in array), or choose only the first one for the <strong>sales/includes/ui/sales_order_ui.inc</strong> and all other places we need single contacts or make a new function called <strong>get_branch_contact</strong> (singular) with the current code in it and make new content for the existing function <strong>get_branch_contacts</strong> (plural) for usage where multiple contacts are needed.</p><p>As far as emailing is concerned, we can make the first contact as the &quot;To&quot; recipient and all others as the &quot;Cc&quot; recipients if they exist!</p><p>Way forward is to be decided - all your thoughts on this is welcome before a patch is forwarded to @joe.</p><p><span class="bbu">Hence currently, no code change is required except for setting the last parameter as <strong>false</strong> in reports that need to be emailed to multiple entities!</span></p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2015-02-08T10:30:10Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22437#p22437</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: email single invoice to multiple recipients]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22436#p22436" />
			<content type="html"><![CDATA[<p>Fair enough. But then you&#039;d have a problem if there were ONLY &quot;CC&quot; recipients... </p><p>Fortunately, in a small business it should be obvious to those concerned why they got the message. And it&#039;s quite clear who else got it, so they can always work it out between themselves if necessary.</p>]]></content>
			<author>
				<name><![CDATA[tm]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=17873</uri>
			</author>
			<updated>2015-02-08T09:09:04Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22436#p22436</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: email single invoice to multiple recipients]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22435#p22435" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>tm wrote:</cite><blockquote><p>I would suggest reorganising that bit to first create the message and then loop over the recipients while adding the &quot;To&quot; headers.</p><p>(CC is probably best avoided here, as it implies &quot;FYI&quot; rather than &quot;Here&#039;s a message for you. Please do something with it&quot;. So, who is the &quot;real&quot; recipient, and who gets CC&#039;ed?)</p></blockquote></div><p>While multiple To headers would work just fine, CC would actually be more appropriate in most of my cases for the exact reason you state.&nbsp; Most of my customers are small businesses, so I send the invoice to the accounting person/department, who need to do something about it, but need to send a copy of the invoice to the manager/owner so they are informed.</p><p>Maybe having a CC check box in the contacts section or something would be cool.</p><p>But really, To vs CC is minutia when compared to getting every thing bundled into a single mail...</p>]]></content>
			<author>
				<name><![CDATA[bobloblian]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=19664</uri>
			</author>
			<updated>2015-02-08T08:37:14Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22435#p22435</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: email single invoice to multiple recipients]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22434#p22434" />
			<content type="html"><![CDATA[<p>About Bob&#039;s second question, </p><p>When I looked at the code, it seemed that the mail was generated and sent to each recipient (which was of course of little consequence, as there was never more than one).</p><p>I would suggest reorganising that bit to first create the message and then loop over the recipients while adding the &quot;To&quot; headers.</p><p>(CC is probably best avoided here, as it implies &quot;FYI&quot; rather than &quot;Here&#039;s a message for you. Please do something with it&quot;. So, who is the &quot;real&quot; recipient, and who gets CC&#039;ed?)</p>]]></content>
			<author>
				<name><![CDATA[tm]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=17873</uri>
			</author>
			<updated>2015-02-08T07:18:35Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22434#p22434</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: email single invoice to multiple recipients]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22433#p22433" />
			<content type="html"><![CDATA[<p>@apmuthu</p><p>I am quite busy at present. Will you send me a patch to fix this in release 2.3. Release 2.4 will then be updated when the final merge is done.</p><p>Thanks in advance.</p><p>/Joe</p>]]></content>
			<author>
				<name><![CDATA[joe]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=3</uri>
			</author>
			<updated>2015-02-08T07:04:39Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22433#p22433</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: email single invoice to multiple recipients]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22432#p22432" />
			<content type="html"><![CDATA[<p>while it is unfortunate there is a bug in the code, I can&#039;t say how happy I am to know that it wasn&#039;t stupid-user syndrome.&nbsp; I am also super-happy that I was able to find it and point it out.&nbsp; Thanks again for your guidance on that apmuthu.</p><p>I have two follow-up questions:</p><p>1.&nbsp; I have tried commenting each part(s) of the stanza in the get_branch_contacts function but seems I have to comment the whole thing for email to work.&nbsp; Can I make a change there to fix this properly, or am I to understand from your reply that the problem is more involved than that?</p><p>2.&nbsp; There is a CC function in class.mail.inc, but I don&#039;t find any way to use it.&nbsp; it seems when a mail is sent to multiple contacts, it make a separate mail for each individual, such that nobody can see if the other recipients got it.&nbsp; Can this be adjusted?&nbsp; I have one client who says I need to send by snailmail if it can&#039;t, and I am not sure if I remember how to use a stamp <img src="https://frontaccounting.com/punbb/img/smilies/wink.png" width="15" height="15" alt="wink" /></p>]]></content>
			<author>
				<name><![CDATA[bobloblian]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=19664</uri>
			</author>
			<updated>2015-02-08T06:36:20Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22432#p22432</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: email single invoice to multiple recipients]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22431#p22431" />
			<content type="html"><![CDATA[<p>In <strong>includes/current_user.inc</strong>, the following function is defined:<br /></p><div class="codebox"><pre><code>//
//    Search $needle in $haystack or in $haystack[][$valuekey]
//    returns $needle found or null.
//
function array_search_value($needle, $haystack, $valuekey=null)
{
    foreach($haystack as $key =&gt; $value) {
        $val = isset($valuekey) ? @$value[$valuekey] : $value;
        if ($needle == $val){
            return $value;
        }
    }
    return null;
}</code></pre></div><p>This function is used by <em>function <strong>get_branch_contacts</strong></em> in <strong>sales/includes/db/branches_db.inc</strong> (this file has another similarly named function prefixed with an underscore that is neither used in the FA core nor in any extension).</p><p>At the very end of the <em>function <strong>get_branch_contacts</strong></em> we find that only one element is returned because of a return within the loop:<br /></p><div class="codebox"><pre><code>    foreach($defs as $type) {

        if ($n = array_search_value($type, $results, &#039;ext_type&#039;))

            return $n;
    
    }</code></pre></div><p>If this value is captured in a separate array if it is not empty, then that array would have all the necessary contacts. </p><p>This is clearly a bug.</p><p>@joe: please update accordingly in FA 2.3 and into FA 2.4.</p><p>PS: The error in <strong>includes/ui/simple_crud_class.inc</strong> is tolerated because of the &quot;<strong>@</strong>&quot; prefixing the assignment. A check for the variable&#039;s existence before assignment would remedy it and it is needed in more than one place in the same function!</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2015-02-08T04:42:03Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22431#p22431</id>
		</entry>
</feed>
