From: <dai...@us...> - 2016-05-28 03:45:58
|
Revision: 7542 http://sourceforge.net/p/web-erp/reponame/7542 Author: daintree Date: 2016-05-28 03:45:56 +0000 (Sat, 28 May 2016) Log Message: ----------- CustStatement email capability Modified Paths: -------------- trunk/AddCustomerContacts.php trunk/PrintCustStatements.php trunk/SelectCustomer.php trunk/doc/Change.log trunk/doc/Manual/ManualAccountsReceivable.html trunk/sql/mysql/upgrade4.12.3-4.13.sql Removed Paths: ------------- trunk/EmailCustStatements.php Modified: trunk/AddCustomerContacts.php =================================================================== --- trunk/AddCustomerContacts.php 2016-05-23 07:40:48 UTC (rev 7541) +++ trunk/AddCustomerContacts.php 2016-05-28 03:45:56 UTC (rev 7542) @@ -56,7 +56,8 @@ role='" . $_POST['ContactRole'] . "', phoneno='" . $_POST['ContactPhone'] . "', notes='" . $_POST['ContactNotes'] . "', - email='" . $_POST['ContactEmail'] . "' + email='" . $_POST['ContactEmail'] . "', + statement='" . $_POST['StatementAddress'] . "' WHERE debtorno ='".$DebtorNo."' AND contid='".$Id."'"; $msg = _('Customer Contacts') . ' ' . $DebtorNo . ' ' . _('has been updated'); @@ -67,13 +68,15 @@ role, phoneno, notes, - email) + email, + statement) VALUES ('" . $DebtorNo. "', '" . $_POST['ContactName'] . "', '" . $_POST['ContactRole'] . "', '" . $_POST['ContactPhone'] . "', '" . $_POST['ContactNotes'] . "', - '" . $_POST['ContactEmail'] . "')"; + '" . $_POST['ContactEmail'] . "', + '" . $_POST['StatementAddress'] . "')"; $msg = _('The contact record has been added'); } @@ -116,6 +119,7 @@ contactname, role, phoneno, + statement, notes, email FROM custcontacts @@ -130,6 +134,7 @@ <th class="text">', _('Role'), '</th> <th class="text">', _('Phone no'), '</th> <th class="text">', _('Email'), '</th> + <th class="text">', _('Statement'), '</th> <th class="text">', _('Notes'), '</th> <th class="noprint" colspan="2"> </th> </tr>'; @@ -149,6 +154,7 @@ <td class="text">%s</td> <td class="text"><a href="mailto:%s">%s</a></td> <td class="text">%s</td> + <td class="text">%s</td> <td class="noprint"><a href="%sId=%s&DebtorNo=%s">' . _('Edit') . '</a></td> <td class="noprint"><a href="%sId=%s&DebtorNo=%s&delete=1" onclick="return confirm(\'' . _('Are you sure you wish to delete this contact?') . '\');">' . _('Delete'). '</a></td></tr>', $myrow['contactname'], @@ -156,6 +162,7 @@ $myrow['phoneno'], $myrow['email'], $myrow['email'], + ($myrow['statement']==0) ? _('No') : _('Yes'), $myrow['notes'], htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '?', $myrow['contid'], @@ -226,7 +233,7 @@ } // Contact name: echo '<tr> - <td>', _('Contact Name'), '</td> + <td>', _('Contact Name'), ':</td> <td><input maxlength="40" name="ContactName" required="required" size="35" type="text" '; if( isset($_POST['ContactName']) ) { echo 'autofocus="autofocus" value="', $_POST['ContactName'], '" '; @@ -235,7 +242,7 @@ </tr>'; // Role: echo '<tr> - <td>', _('Role'), '</td> + <td>', _('Role'), ':</td> <td><input maxlength="40" name="ContactRole" size="35" type="text" '; if( isset($_POST['ContactRole']) ) { echo 'value="', $_POST['ContactRole'], '" '; @@ -244,7 +251,7 @@ </tr>'; // Phone: echo '<tr> - <td>', _('Phone'), '</td> + <td>', _('Phone'), ':</td> <td><input maxlength="40" name="ContactPhone" size="35" type="tel" '; if( isset($_POST['ContactPhone']) ) { echo 'value="', $_POST['ContactPhone'], '" '; @@ -253,13 +260,30 @@ </tr>'; // Email: echo '<tr> - <td>', _('Email'), '</td> + <td>', _('Email'), ':</td> <td><input maxlength="55" name="ContactEmail" size="55" type="email" '; if( isset($_POST['ContactEmail']) ) { echo 'value="', $_POST['ContactEmail'], '" '; } echo '/></td> </tr>'; + echo '<tr> + <td>', _('Send Statement'), ':</td> + <td><select name="StatementAddress" title="' , _('This flag identifies the contact as one who should receive an email cusstomer statement') , '" >'; + if( !isset($_POST['StatementAddress']) ) { + echo '<option selected="selected" value="0">', _('No') , '</option> + <option value="1">', _('Yes') , '</option>'; + } else { + if ($_POST['StatementAddress']==0) { + echo '<option selected="selected" value="0">', _('No') , '</option> + <option value="1">', _('Yes') , '</option>'; + } else { + echo '<option value="0">', _('No') , '</option> + <option selected="selected" value="1">', _('Yes') , '</option>'; + } + } + echo '</select></td> + </tr>'; // Notes: echo '<tr> <td>', _('Notes'), '</td> Deleted: trunk/EmailCustStatements.php =================================================================== --- trunk/EmailCustStatements.php 2016-05-23 07:40:48 UTC (rev 7541) +++ trunk/EmailCustStatements.php 2016-05-28 03:45:56 UTC (rev 7542) @@ -1,51 +0,0 @@ -<?php - -/* $Id: EmailCustTrans.php 6310 2013-08-29 10:42:50Z daintree $*/ - -include ('includes/session.inc'); -include ('includes/SQL_CommonFunctions.inc'); -if (!isset($_GET['FromCust'])) { - $_GET['FromCust'] = $_SESSION['CustomerID']; -} -$Title=_('Email Customer Statement For Customer No.') . ' ' . $_GET['FromCust']; - -if (isset($_POST['DoIt']) AND IsEmailAddress($_POST['EmailAddr'])){ - echo '<meta http-equiv="Refresh" content="0; url=' . $RootPath . '/PrintCustStatements.php?FromCust=' . $_SESSION['CustomerID'] . '&ToCust='.$_SESSION['CustomerID'] . '&PrintPDF=Yes&Email=' . $_POST['EmailAddr'] . '">'; - prnMsg(_('The customer statement should have been emailed off') . '. ' . _('If this does not happen') . ' (' . _('if the browser does not support META Refresh') . ')' . '<a href="' . $RootPath . '/PrintCustStatements.php?FromCust=' . $_SESSION['CustomerID'] . '&PrintPDF=Yes&Email=' . $_POST['EmailAddr'] . '">' . _('click here') . '</a> ' . _('to email the customer statement'),'success'); - exit; -} elseif (isset($_POST['DoIt'])) { - prnMsg(_('The email address does not appear to be a valid email address. The statement was not emailed'),'warn'); -} -include ('includes/header.inc'); - -echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '" method="post">'; -echo '<div>'; -echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />'; -echo '<br /><table>'; - -$SQL = "SELECT custbranch.email as email - FROM custbranch INNER JOIN debtorsmaster - ON custbranch.debtorno= debtorsmaster.debtorno - WHERE debtorsmaster.debtorno='" .$_SESSION['CustomerID'] . "' LIMIT 1"; - -$ErrMsg = _('There was a problem retrieving the contact details for the customer'); -$ContactResult=DB_query($SQL,$db,$ErrMsg); - -if (DB_num_rows($ContactResult)>0){ - $EmailAddrRow = DB_fetch_row($ContactResult); - $EmailAddress = $EmailAddrRow[0]; -} else { - $EmailAddress =''; -} - -echo '<tr><td>' . _('Email to') . ':</td> - <td><input type="email" name="EmailAddr" autofocus="autofocus" maxlength="60" size="60" value="' . $EmailAddress . '" /></td> - </tr> - </table>'; - -echo '<br /><div class="centre"><input type="submit" name="DoIt" value="' . _('OK') . '" />'; -echo '</div> - </div> - </form>'; -include ('includes/footer.inc'); -?> Modified: trunk/PrintCustStatements.php =================================================================== --- trunk/PrintCustStatements.php 2016-05-23 07:40:48 UTC (rev 7541) +++ trunk/PrintCustStatements.php 2016-05-28 03:45:56 UTC (rev 7542) @@ -4,7 +4,7 @@ include('includes/session.inc'); include('includes/SQL_CommonFunctions.inc'); - +include ('includes/htmlMimeMail.php'); $ViewTopic = 'ARReports'; $BookMark = 'CustomerStatements'; $Title = _('Print Customer Statements'); @@ -37,37 +37,12 @@ $_POST['FromCust'] = mb_strtoupper($_POST['FromCust']); If (!isset($_POST['ToCust'])){ - $_POST['ToCust'] = $_POST['FromCust']; + $_POST['ToCust'] = $_POST['FromCust']; } else { $_POST['ToCust'] = mb_strtoupper($_POST['ToCust']); } - include('includes/PDFStarter.php'); - $pdf->addInfo('Title', _('Customer Statements') ); - $pdf->addInfo('Subject', _('Statements from') . ' ' . $_POST['FromCust'] . ' ' . _('to') . ' ' . $_POST['ToCust']); - $PageNumber = 1; - $line_height=16; - $FirstStatement = True; - - // check if the user has set a default bank account for invoices, if not leave it blank - $sql = "SELECT bankaccounts.invoice, - bankaccounts.bankaccountnumber, - bankaccounts.bankaccountcode - FROM bankaccounts - WHERE bankaccounts.invoice = '1'"; - $result=DB_query($sql,'','',false,false); - if (DB_error_no()!=1) { - if (DB_num_rows($result)==1){ - $myrow = DB_fetch_array($result); - $DefaultBankAccountNumber = $myrow['bankaccountnumber']; - } else { - $DefaultBankAccountNumber = ''; - } - } else { - $DefaultBankAccountNumber = ''; - } - /* Do a quick tidy up to settle any transactions that should have been settled at the time of allocation but for whatever reason weren't */ $ErrMsg = _('There was a problem settling the old transactions.'); $DbgMsg = _('The SQL used to settle outstanding transactions was'); @@ -105,373 +80,427 @@ echo '<p class="page_title_text"><img src="'.$RootPath.'/css/'.$Theme.'/images/printer.png" title="' . _('Print') . '" alt="" />' . ' ' . _('Print Customer Account Statements') . '</p>'; prnMsg( _('There were no Customers matching your selection of '). $_POST['FromCust']. ' - '. $_POST['ToCust'].'.' , 'error'); -// echo '</div>'; include('includes/footer.inc'); exit(); } + //Start the statement if there are any in the range and we are printing the whole lot + if ($_POST['EmailOrPrint']=='print') { + include('includes/PDFStarter.php'); + $pdf->addInfo('Title', _('Customer Statements') ); + $pdf->addInfo('Subject', _('Statements from') . ' ' . $_POST['FromCust'] . ' ' . _('to') . ' ' . $_POST['ToCust']); + $PageNumber = 1; + } else { + $Title = _('Email Customer Statements'); + include('includes/header.inc'); + echo '<p class="page_title_text"><img src="'.$RootPath.'/css/'.$Theme.'/images/email.png" title="' . _('Email') . '" alt="" />' . ' ' . _('Emailing Customer Account Statements') . '</p>'; + + echo '<table class="selection"> + <tr> + <th class="text">', _('Account #'), '</th> + <th class="text">', _('Customer Name'), '</th> + <th class="text">', _('Recipients'), '</th> + </tr>'; + } + $FirstStatement = True; + // check if the user has set a default bank account for invoices, if not leave it blank + $sql = "SELECT bankaccounts.invoice, + bankaccounts.bankaccountnumber, + bankaccounts.bankaccountcode + FROM bankaccounts + WHERE bankaccounts.invoice = '1'"; + $result=DB_query($sql,'','',false,false); + if (DB_error_no()!=1) { + if (DB_num_rows($result)==1){ + $myrow = DB_fetch_array($result); + $DefaultBankAccountNumber = $myrow['bankaccountnumber']; + } else { + $DefaultBankAccountNumber = ''; + } + } else { + $DefaultBankAccountNumber = ''; + } + while ($StmtHeader=DB_fetch_array($StatementResults)){ /*loop through all the customers returned */ - /*now get all the outstanding transaction ie Settled=0 */ - $ErrMsg = _('There was a problem retrieving the outstanding transactions for') . ' ' . $StmtHeader['name'] . ' '. _('from the database') . '.'; - $sql = "SELECT systypes.typename, - debtortrans.transno, - debtortrans.trandate, - debtortrans.ovamount+debtortrans.ovdiscount+debtortrans.ovfreight+debtortrans.ovgst as total, - debtortrans.alloc, - debtortrans.ovamount+debtortrans.ovdiscount+debtortrans.ovfreight+debtortrans.ovgst-debtortrans.alloc as ostdg - FROM debtortrans INNER JOIN systypes - ON debtortrans.type=systypes.typeid - WHERE debtortrans.debtorno='" . $StmtHeader['debtorno'] . "' - AND debtortrans.settled=0"; - - if ($_SESSION['SalesmanLogin'] != '') { - $sql .= " AND debtortrans.salesperson='" . $_SESSION['SalesmanLogin'] . "'"; + if ($_POST['EmailOrPrint']=='email'){ + if (isset($RecipientArray)) { + unset($RecipientArray); + } + $RecipientArray = array(); + include('includes/PDFStarter.php'); + $pdf->addInfo('Title', $_SESSION['CompanyRecord']['coyname'] . ' - ' . _('Customer Statement') ); + $pdf->addInfo('Subject', _('For customer') . ': ' . $StmtHeader['name']); + $PageNumber = 1; + $RecipientsResult = DB_query("SELECT email FROM custcontacts WHERE statement=1 AND debtorno='" . $StmtHeader['debtorno'] . "'"); + while ($RecipientRow = DB_fetch_row($RecipientsResult)){ + if (IsEmailAddress($RecipientRow[0])){ + $RecipientArray[] = $RecipientRow[0]; + } } - $sql .= " ORDER BY debtortrans.id"; + if ($_POST['EmailOrPrint']=='print' OR + ($_POST['EmailOrPrint']=='email' AND count($RecipientArray)>0) ){ - $OstdgTrans=DB_query($sql, $ErrMsg); + $line_height=16; - $NumberOfRecordsReturned = DB_num_rows($OstdgTrans); + /*now get all the outstanding transaction ie Settled=0 */ + $ErrMsg = _('There was a problem retrieving the outstanding transactions for') . ' ' . $StmtHeader['name'] . ' '. _('from the database') . '.'; + $sql = "SELECT systypes.typename, + debtortrans.transno, + debtortrans.trandate, + debtortrans.ovamount+debtortrans.ovdiscount+debtortrans.ovfreight+debtortrans.ovgst as total, + debtortrans.alloc, + debtortrans.ovamount+debtortrans.ovdiscount+debtortrans.ovfreight+debtortrans.ovgst-debtortrans.alloc as ostdg + FROM debtortrans INNER JOIN systypes + ON debtortrans.type=systypes.typeid + WHERE debtortrans.debtorno='" . $StmtHeader['debtorno'] . "' + AND debtortrans.settled=0"; -/*now get all the settled transactions which were allocated this month */ - $ErrMsg = _('There was a problem retrieving the transactions that were settled over the course of the last month for'). ' ' . $StmtHeader['name'] . ' ' . _('from the database'); - if ($_SESSION['Show_Settled_LastMonth']==1){ - $sql = "SELECT DISTINCT debtortrans.id, - systypes.typename, - debtortrans.transno, - debtortrans.trandate, - debtortrans.ovamount+debtortrans.ovdiscount+debtortrans.ovfreight+debtortrans.ovgst AS total, - debtortrans.alloc, - debtortrans.ovamount+debtortrans.ovdiscount+debtortrans.ovfreight+debtortrans.ovgst-debtortrans.alloc AS ostdg - FROM debtortrans INNER JOIN systypes - ON debtortrans.type=systypes.typeid - INNER JOIN custallocns - ON (debtortrans.id=custallocns.transid_allocfrom - OR debtortrans.id=custallocns.transid_allocto) - WHERE custallocns.datealloc >='" . - Date('Y-m-d',Mktime(0,0,0,Date('m')-1,Date('d'),Date('y'))) . "' - AND debtortrans.debtorno='" . $StmtHeader['debtorno'] . "' - AND debtortrans.settled=1"; - if ($_SESSION['SalesmanLogin'] != '') { $sql .= " AND debtortrans.salesperson='" . $_SESSION['SalesmanLogin'] . "'"; } $sql .= " ORDER BY debtortrans.id"; - $SetldTrans=DB_query($sql, $ErrMsg); - $NumberOfRecordsReturned += DB_num_rows($SetldTrans); + $OstdgTrans=DB_query($sql, $ErrMsg); - } + $NumberOfRecordsReturned = DB_num_rows($OstdgTrans); - if ( $NumberOfRecordsReturned >=1){ + /*now get all the settled transactions which were allocated this month */ + $ErrMsg = _('There was a problem retrieving the transactions that were settled over the course of the last month for'). ' ' . $StmtHeader['name'] . ' ' . _('from the database'); + if ($_SESSION['Show_Settled_LastMonth']==1){ + $sql = "SELECT DISTINCT debtortrans.id, + systypes.typename, + debtortrans.transno, + debtortrans.trandate, + debtortrans.ovamount+debtortrans.ovdiscount+debtortrans.ovfreight+debtortrans.ovgst AS total, + debtortrans.alloc, + debtortrans.ovamount+debtortrans.ovdiscount+debtortrans.ovfreight+debtortrans.ovgst-debtortrans.alloc AS ostdg + FROM debtortrans INNER JOIN systypes + ON debtortrans.type=systypes.typeid + INNER JOIN custallocns + ON (debtortrans.id=custallocns.transid_allocfrom + OR debtortrans.id=custallocns.transid_allocto) + WHERE custallocns.datealloc >='" . + Date('Y-m-d',Mktime(0,0,0,Date('m')-1,Date('d'),Date('y'))) . "' + AND debtortrans.debtorno='" . $StmtHeader['debtorno'] . "' + AND debtortrans.settled=1"; - /* Then there's a statement to print. So print out the statement header from the company record */ + if ($_SESSION['SalesmanLogin'] != '') { + $sql .= " AND debtortrans.salesperson='" . $_SESSION['SalesmanLogin'] . "'"; + } - $PageNumber =1; + $sql .= " ORDER BY debtortrans.id"; - if ($FirstStatement==True){ - $FirstStatement=False; - } else { - $pdf->newPage(); - } + $SetldTrans=DB_query($sql, $ErrMsg); + $NumberOfRecordsReturned += DB_num_rows($SetldTrans); - include('includes/PDFStatementPageHeader.inc'); + } - $Cust_Name = $StmtHeader['name']; - $Cust_No = $StmtHeader['debtorno']; + if ( $NumberOfRecordsReturned >=1){ - if ($_SESSION['Show_Settled_LastMonth']==1){ - if (DB_num_rows($SetldTrans)>=1) { + /* Then there's a statement to print. So print out the statement header from the company record */ - $FontSize=12; - $pdf->addText($Left_Margin+1,$YPos+5,$FontSize, _('Settled Transactions')); + $PageNumber =1; - $YPos -= (2*$line_height); + if ($FirstStatement==True){ + $FirstStatement=False; + } else { + $pdf->newPage(); + } - $FontSize=10; + include('includes/PDFStatementPageHeader.inc'); - while ($myrow=DB_fetch_array($SetldTrans)){ + $Cust_Name = $StmtHeader['name']; + $Cust_No = $StmtHeader['debtorno']; - $DisplayAlloc = locale_number_format($myrow['alloc'],$StmtHeader['currdecimalplaces']); - $DisplayOutstanding = locale_number_format($myrow['ostdg'],$StmtHeader['currdecimalplaces']); + if ($_SESSION['Show_Settled_LastMonth']==1){ + if (DB_num_rows($SetldTrans)>=1) { - $FontSize=9; + $FontSize=12; + $pdf->addText($Left_Margin+1,$YPos+5,$FontSize, _('Settled Transactions')); - $LeftOvers = $pdf->addTextWrap($Left_Margin+1,$YPos,60,$FontSize, _($myrow['typename']), 'left'); - $LeftOvers = $pdf->addTextWrap($Left_Margin+110,$YPos,50,$FontSize,$myrow['transno'], 'left'); - $LeftOvers = $pdf->addTextWrap($Left_Margin+211,$YPos,55,$FontSize,ConvertSQLDate($myrow['trandate']), 'left'); + $YPos -= (2*$line_height); $FontSize=10; - if ($myrow['total']>0){ - $DisplayTotal = locale_number_format($myrow['total'],$StmtHeader['currdecimalplaces']); - $LeftOvers = $pdf->addTextWrap($Left_Margin+300,$YPos,60,$FontSize,$DisplayTotal, 'right'); - } else { - $DisplayTotal = locale_number_format(-$myrow['total'],$StmtHeader['currdecimalplaces']); - $LeftOvers = $pdf->addTextWrap($Left_Margin+382,$YPos,60,$FontSize,$DisplayTotal, 'right'); - } - $LeftOvers = $pdf->addTextWrap($Left_Margin+459,$YPos,60,$FontSize,$DisplayAlloc, 'right'); - $LeftOvers = $pdf->addTextWrap($Left_Margin+536,$YPos,60,$FontSize,$DisplayOutstanding, 'right'); - if ($YPos-$line_height <= $Bottom_Margin){ - /* head up a new statement page */ + while ($myrow=DB_fetch_array($SetldTrans)){ - $PageNumber++; - $pdf->newPage(); - include ('includes/PDFStatementPageHeader.inc'); - } //end if need a new page headed up + $DisplayAlloc = locale_number_format($myrow['alloc'],$StmtHeader['currdecimalplaces']); + $DisplayOutstanding = locale_number_format($myrow['ostdg'],$StmtHeader['currdecimalplaces']); - /*increment a line down for the next line item */ - $YPos -= ($line_height); + $FontSize=9; - } //end while there transactions settled this month to print out - } - } // end of if there are transaction that were settled this month + $LeftOvers = $pdf->addTextWrap($Left_Margin+1,$YPos,60,$FontSize, _($myrow['typename']), 'left'); + $LeftOvers = $pdf->addTextWrap($Left_Margin+110,$YPos,50,$FontSize,$myrow['transno'], 'left'); + $LeftOvers = $pdf->addTextWrap($Left_Margin+211,$YPos,55,$FontSize,ConvertSQLDate($myrow['trandate']), 'left'); - if (DB_num_rows($OstdgTrans)>=1){ + $FontSize=10; + if ($myrow['total']>0){ + $DisplayTotal = locale_number_format($myrow['total'],$StmtHeader['currdecimalplaces']); + $LeftOvers = $pdf->addTextWrap($Left_Margin+300,$YPos,60,$FontSize,$DisplayTotal, 'right'); + } else { + $DisplayTotal = locale_number_format(-$myrow['total'],$StmtHeader['currdecimalplaces']); + $LeftOvers = $pdf->addTextWrap($Left_Margin+382,$YPos,60,$FontSize,$DisplayTotal, 'right'); + } + $LeftOvers = $pdf->addTextWrap($Left_Margin+459,$YPos,60,$FontSize,$DisplayAlloc, 'right'); + $LeftOvers = $pdf->addTextWrap($Left_Margin+536,$YPos,60,$FontSize,$DisplayOutstanding, 'right'); - $YPos -= ($line_height); - if ($YPos-(2 * $line_height) <= $Bottom_Margin){ - $PageNumber++; - $pdf->newPage(); - include ('includes/PDFStatementPageHeader.inc'); - } - /*Now the same again for outstanding transactions */ + if ($YPos-$line_height <= $Bottom_Margin){ + /* head up a new statement page */ - $FontSize=12; - $pdf->addText($Left_Margin+1,$YPos+20,$FontSize, _('Outstanding Transactions') ); - $YPos -= $line_height; + $PageNumber++; + $pdf->newPage(); + include ('includes/PDFStatementPageHeader.inc'); + } //end if need a new page headed up - while ($myrow=DB_fetch_array($OstdgTrans)){ + /*increment a line down for the next line item */ + $YPos -= ($line_height); - $DisplayAlloc = locale_number_format($myrow['alloc'],$StmtHeader['currdecimalplaces']); - $DisplayOutstanding = locale_number_format($myrow['ostdg'],$StmtHeader['currdecimalplaces']); + } //end while there transactions settled this month to print out + } + } // end of if there are transaction that were settled this month - $FontSize=9; - $LeftOvers = $pdf->addTextWrap($Left_Margin+1,$YPos,60,$FontSize, _($myrow['typename']), 'left'); - $LeftOvers = $pdf->addTextWrap($Left_Margin+110,$YPos,50,$FontSize,$myrow['transno'], 'left'); - $LeftOvers = $pdf->addTextWrap($Left_Margin+211,$YPos,55,$FontSize,ConvertSQLDate($myrow['trandate']), 'left'); + if (DB_num_rows($OstdgTrans)>=1){ - $FontSize=10; - if ($myrow['total']>0){ - $DisplayTotal = locale_number_format($myrow['total'],$StmtHeader['currdecimalplaces']); - $LeftOvers = $pdf->addTextWrap($Left_Margin+300,$YPos,55,$FontSize,$DisplayTotal, 'right'); - } else { - $DisplayTotal = locale_number_format(-$myrow['total'],$StmtHeader['currdecimalplaces']); - $LeftOvers = $pdf->addTextWrap($Left_Margin+382,$YPos,55,$FontSize,$DisplayTotal, 'right'); - } + $YPos -= ($line_height); + if ($YPos-(2 * $line_height) <= $Bottom_Margin){ + $PageNumber++; + $pdf->newPage(); + include ('includes/PDFStatementPageHeader.inc'); + } + /*Now the same again for outstanding transactions */ - $LeftOvers = $pdf->addTextWrap($Left_Margin+459,$YPos,59,$FontSize,$DisplayAlloc, 'right'); - $LeftOvers = $pdf->addTextWrap($Left_Margin+536,$YPos,60,$FontSize,$DisplayOutstanding, 'right'); + $FontSize=12; + $pdf->addText($Left_Margin+1,$YPos+20,$FontSize, _('Outstanding Transactions') ); + $YPos -= $line_height; - /*Now show also in the remittance advice sectin */ - $FontSize=8; - $LeftOvers = $pdf->addTextWrap($Perforation+10,$YPos,30,$FontSize, _($myrow['typename']), 'left'); - $LeftOvers = $pdf->addTextWrap($Perforation+75,$YPos,30,$FontSize,$myrow['transno'], 'left'); - $LeftOvers = $pdf->addTextWrap($Perforation+90,$YPos,60,$FontSize,$DisplayOutstanding, 'right'); + while ($myrow=DB_fetch_array($OstdgTrans)){ - if ($YPos-$line_height <= $Bottom_Margin){ - /* head up a new statement page */ + $DisplayAlloc = locale_number_format($myrow['alloc'],$StmtHeader['currdecimalplaces']); + $DisplayOutstanding = locale_number_format($myrow['ostdg'],$StmtHeader['currdecimalplaces']); - $PageNumber++; - $pdf->newPage(); - include ('includes/PDFStatementPageHeader.inc'); - } //end if need a new page headed up + $FontSize=9; + $LeftOvers = $pdf->addTextWrap($Left_Margin+1,$YPos,60,$FontSize, _($myrow['typename']), 'left'); + $LeftOvers = $pdf->addTextWrap($Left_Margin+110,$YPos,50,$FontSize,$myrow['transno'], 'left'); + $LeftOvers = $pdf->addTextWrap($Left_Margin+211,$YPos,55,$FontSize,ConvertSQLDate($myrow['trandate']), 'left'); - /*increment a line down for the next line item */ - $YPos -= ($line_height); + $FontSize=10; + if ($myrow['total']>0){ + $DisplayTotal = locale_number_format($myrow['total'],$StmtHeader['currdecimalplaces']); + $LeftOvers = $pdf->addTextWrap($Left_Margin+300,$YPos,55,$FontSize,$DisplayTotal, 'right'); + } else { + $DisplayTotal = locale_number_format(-$myrow['total'],$StmtHeader['currdecimalplaces']); + $LeftOvers = $pdf->addTextWrap($Left_Margin+382,$YPos,55,$FontSize,$DisplayTotal, 'right'); + } - } //end while there are outstanding transaction to print - } // end if there are outstanding transaction to print + $LeftOvers = $pdf->addTextWrap($Left_Margin+459,$YPos,59,$FontSize,$DisplayAlloc, 'right'); + $LeftOvers = $pdf->addTextWrap($Left_Margin+536,$YPos,60,$FontSize,$DisplayOutstanding, 'right'); + /*Now show also in the remittance advice sectin */ + $FontSize=8; + $LeftOvers = $pdf->addTextWrap($Perforation+10,$YPos,30,$FontSize, _($myrow['typename']), 'left'); + $LeftOvers = $pdf->addTextWrap($Perforation+75,$YPos,30,$FontSize,$myrow['transno'], 'left'); + $LeftOvers = $pdf->addTextWrap($Perforation+90,$YPos,60,$FontSize,$DisplayOutstanding, 'right'); - /* check to see enough space left to print the totals/footer - which is made up of 2 ruled lines, the totals/aging another 2 lines - and details of the last payment made - in all 6 lines */ - if (($YPos-$Bottom_Margin)<(4*$line_height)){ + if ($YPos-$line_height <= $Bottom_Margin){ + /* head up a new statement page */ - /* head up a new statement/credit note page */ - $PageNumber++; - $pdf->newPage(); - include ('includes/PDFStatementPageHeader.inc'); - } - /*Now figure out the aged analysis for the customer under review */ + $PageNumber++; + $pdf->newPage(); + include ('includes/PDFStatementPageHeader.inc'); + } //end if need a new page headed up - $SQL = "SELECT debtorsmaster.name, - currencies.currency, - paymentterms.terms, - debtorsmaster.creditlimit, - holdreasons.dissallowinvoices, - holdreasons.reasondescription, - SUM(debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + - debtortrans.ovdiscount - debtortrans.alloc) AS balance, - SUM(CASE WHEN paymentterms.daysbeforedue > 0 THEN - CASE WHEN (TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate)) >= - paymentterms.daysbeforedue - THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + - debtortrans.ovdiscount - debtortrans.alloc - ELSE 0 END - ELSE - CASE WHEN TO_DAYS(Now()) - TO_DAYS(DATE_ADD(DATE_ADD(debtortrans.trandate, " . interval('1', 'MONTH') . "), " . interval('(paymentterms.dayinfollowingmonth - DAYOFMONTH(debtortrans.trandate))','DAY') . ")) >= 0 - THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + - debtortrans.ovdiscount - debtortrans.alloc - ELSE 0 END - END) AS due, - Sum(CASE WHEN paymentterms.daysbeforedue > 0 THEN - CASE WHEN TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate) > paymentterms.daysbeforedue - AND TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate) >= - (paymentterms.daysbeforedue + " . $_SESSION['PastDueDays1'] . ") - THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + - debtortrans.ovdiscount - debtortrans.alloc - ELSE 0 END - ELSE - CASE WHEN (TO_DAYS(Now()) - TO_DAYS(DATE_ADD(DATE_ADD(debtortrans.trandate, " . interval('1','MONTH') . "), " . interval('(paymentterms.dayinfollowingmonth - DAYOFMONTH(debtortrans.trandate))','DAY') .")) >= " . $_SESSION['PastDueDays1'] . ") - THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + - debtortrans.ovdiscount - debtortrans.alloc - ELSE 0 END - END) AS overdue1, - Sum(CASE WHEN paymentterms.daysbeforedue > 0 THEN - CASE WHEN TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate) > paymentterms.daysbeforedue - AND TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate) >= (paymentterms.daysbeforedue + - " . $_SESSION['PastDueDays2'] . ") - THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + - debtortrans.ovdiscount - debtortrans.alloc - ELSE 0 END - ELSE - CASE WHEN (TO_DAYS(Now()) - TO_DAYS(DATE_ADD(DATE_ADD(debtortrans.trandate, " . interval('1','MONTH') . "), " . - interval('(paymentterms.dayinfollowingmonth - DAYOFMONTH(debtortrans.trandate))','DAY') . ")) - >= " . $_SESSION['PastDueDays2'] . ") - THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + - debtortrans.ovdiscount - debtortrans.alloc - ELSE 0 END - END) AS overdue2 - FROM debtorsmaster INNER JOIN paymentterms - ON debtorsmaster.paymentterms = paymentterms.termsindicator - INNER JOIN currencies - ON debtorsmaster.currcode = currencies.currabrev - INNER JOIN holdreasons - ON debtorsmaster.holdreason = holdreasons.reasoncode - INNER JOIN debtortrans - ON debtorsmaster.debtorno = debtortrans.debtorno - WHERE - debtorsmaster.debtorno = '" . $StmtHeader['debtorno'] . "'"; + /*increment a line down for the next line item */ + $YPos -= ($line_height); - if ($_SESSION['SalesmanLogin'] != '') { - $sql .= " AND debtortrans.salesperson='" . $_SESSION['SalesmanLogin'] . "'"; - } + } //end while there are outstanding transaction to print + } // end if there are outstanding transaction to print - $sql .= " GROUP BY - debtorsmaster.name, - currencies.currency, - paymentterms.terms, - paymentterms.daysbeforedue, - paymentterms.dayinfollowingmonth, - debtorsmaster.creditlimit, - holdreasons.dissallowinvoices, - holdreasons.reasondescription"; - $ErrMsg = 'The customer details could not be retrieved by the SQL because'; - $CustomerResult = DB_query($SQL); + /* check to see enough space left to print the totals/footer + which is made up of 2 ruled lines, the totals/aging another 2 lines + and details of the last payment made - in all 6 lines */ + if (($YPos-$Bottom_Margin)<(4*$line_height)){ - /*there should be only one record returned ?? */ - $AgedAnalysis = DB_fetch_array($CustomerResult,$db); + /* head up a new statement page */ + $PageNumber++; + $pdf->newPage(); + include ('includes/PDFStatementPageHeader.inc'); + } + /*Now figure out the aged analysis for the customer under review */ + $SQL = "SELECT debtorsmaster.name, + currencies.currency, + paymentterms.terms, + debtorsmaster.creditlimit, + holdreasons.dissallowinvoices, + holdreasons.reasondescription, + SUM(debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + + debtortrans.ovdiscount - debtortrans.alloc) AS balance, + SUM(CASE WHEN paymentterms.daysbeforedue > 0 THEN + CASE WHEN (TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate)) >= + paymentterms.daysbeforedue + THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + + debtortrans.ovdiscount - debtortrans.alloc + ELSE 0 END + ELSE + CASE WHEN TO_DAYS(Now()) - TO_DAYS(DATE_ADD(DATE_ADD(debtortrans.trandate, " . interval('1', 'MONTH') . "), " . interval('(paymentterms.dayinfollowingmonth - DAYOFMONTH(debtortrans.trandate))','DAY') . ")) >= 0 + THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + + debtortrans.ovdiscount - debtortrans.alloc + ELSE 0 END + END) AS due, + Sum(CASE WHEN paymentterms.daysbeforedue > 0 THEN + CASE WHEN TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate) > paymentterms.daysbeforedue + AND TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate) >= + (paymentterms.daysbeforedue + " . $_SESSION['PastDueDays1'] . ") + THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + + debtortrans.ovdiscount - debtortrans.alloc + ELSE 0 END + ELSE + CASE WHEN (TO_DAYS(Now()) - TO_DAYS(DATE_ADD(DATE_ADD(debtortrans.trandate, " . interval('1','MONTH') . "), " . interval('(paymentterms.dayinfollowingmonth - DAYOFMONTH(debtortrans.trandate))','DAY') .")) >= " . $_SESSION['PastDueDays1'] . ") + THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + + debtortrans.ovdiscount - debtortrans.alloc + ELSE 0 END + END) AS overdue1, + Sum(CASE WHEN paymentterms.daysbeforedue > 0 THEN + CASE WHEN TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate) > paymentterms.daysbeforedue + AND TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate) >= (paymentterms.daysbeforedue + + " . $_SESSION['PastDueDays2'] . ") + THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + + debtortrans.ovdiscount - debtortrans.alloc + ELSE 0 END + ELSE + CASE WHEN (TO_DAYS(Now()) - TO_DAYS(DATE_ADD(DATE_ADD(debtortrans.trandate, " . interval('1','MONTH') . "), " . + interval('(paymentterms.dayinfollowingmonth - DAYOFMONTH(debtortrans.trandate))','DAY') . ")) + >= " . $_SESSION['PastDueDays2'] . ") + THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + + debtortrans.ovdiscount - debtortrans.alloc + ELSE 0 END + END) AS overdue2 + FROM debtorsmaster INNER JOIN paymentterms + ON debtorsmaster.paymentterms = paymentterms.termsindicator + INNER JOIN currencies + ON debtorsmaster.currcode = currencies.currabrev + INNER JOIN holdreasons + ON debtorsmaster.holdreason = holdreasons.reasoncode + INNER JOIN debtortrans + ON debtorsmaster.debtorno = debtortrans.debtorno + WHERE + debtorsmaster.debtorno = '" . $StmtHeader['debtorno'] . "'"; - /*Now print out the footer and totals */ + if ($_SESSION['SalesmanLogin'] != '') { + $sql .= " AND debtortrans.salesperson='" . $_SESSION['SalesmanLogin'] . "'"; + } - $DisplayDue = locale_number_format($AgedAnalysis['due']-$AgedAnalysis['overdue1'],$StmtHeader['currdecimalplaces']); - $DisplayCurrent = locale_number_format($AgedAnalysis['balance']-$AgedAnalysis['due'],$StmtHeader['currdecimalplaces']); - $DisplayBalance = locale_number_format($AgedAnalysis['balance'],$StmtHeader['currdecimalplaces']); - $DisplayOverdue1 = locale_number_format($AgedAnalysis['overdue1']-$AgedAnalysis['overdue2'],$StmtHeader['currdecimalplaces']); - $DisplayOverdue2 = locale_number_format($AgedAnalysis['overdue2'],$StmtHeader['currdecimalplaces']); + $sql .= " GROUP BY + debtorsmaster.name, + currencies.currency, + paymentterms.terms, + paymentterms.daysbeforedue, + paymentterms.dayinfollowingmonth, + debtorsmaster.creditlimit, + holdreasons.dissallowinvoices, + holdreasons.reasondescription"; + $ErrMsg = 'The customer details could not be retrieved by the SQL because'; + $CustomerResult = DB_query($SQL); - $pdf->line($Page_Width-$Right_Margin, $Bottom_Margin+(4*$line_height),$Left_Margin,$Bottom_Margin+(4*$line_height)); + /*there should be only one record returned ?? */ + $AgedAnalysis = DB_fetch_array($CustomerResult,$db); - $FontSize=10; + /*Now print out the footer and totals */ - $pdf->addText($Left_Margin+75, ($Bottom_Margin+10)+(3*$line_height)+4, $FontSize, _('Current'). ' '); - $pdf->addText($Left_Margin+158, ($Bottom_Margin+10)+(3*$line_height)+4, $FontSize, _('Past Due').' '); - $pdf->addText($Left_Margin+242, ($Bottom_Margin+10)+(3*$line_height)+4, $FontSize, $_SESSION['PastDueDays1'] . '-' . $_SESSION['PastDueDays2'] . ' ' . _('days') ); - $pdf->addText($Left_Margin+315, ($Bottom_Margin+10)+(3*$line_height)+4, $FontSize, _('Over').' ' . $_SESSION['PastDueDays2'] . ' '. _('days')); - $pdf->addText($Left_Margin+442, ($Bottom_Margin+10)+(3*$line_height)+4, $FontSize, _('Total Balance') ); + $DisplayDue = locale_number_format($AgedAnalysis['due']-$AgedAnalysis['overdue1'],$StmtHeader['currdecimalplaces']); + $DisplayCurrent = locale_number_format($AgedAnalysis['balance']-$AgedAnalysis['due'],$StmtHeader['currdecimalplaces']); + $DisplayBalance = locale_number_format($AgedAnalysis['balance'],$StmtHeader['currdecimalplaces']); + $DisplayOverdue1 = locale_number_format($AgedAnalysis['overdue1']-$AgedAnalysis['overdue2'],$StmtHeader['currdecimalplaces']); + $DisplayOverdue2 = locale_number_format($AgedAnalysis['overdue2'],$StmtHeader['currdecimalplaces']); - $LeftOvers = $pdf->addTextWrap($Left_Margin+37, $Bottom_Margin+(2*$line_height)+8,70,$FontSize,$DisplayCurrent, 'right'); - $LeftOvers = $pdf->addTextWrap($Left_Margin+130, $Bottom_Margin+(2*$line_height)+8,70,$FontSize,$DisplayDue, 'right'); - $LeftOvers = $pdf->addTextWrap($Left_Margin+222, $Bottom_Margin+(2*$line_height)+8,70,$FontSize,$DisplayOverdue1, 'right'); - $LeftOvers = $pdf->addTextWrap($Left_Margin+305, $Bottom_Margin+(2*$line_height)+8,70,$FontSize,$DisplayOverdue2, 'right'); + $pdf->line($Page_Width-$Right_Margin, $Bottom_Margin+(4*$line_height),$Left_Margin,$Bottom_Margin+(4*$line_height)); - $LeftOvers = $pdf->addTextWrap($Left_Margin+432, $Bottom_Margin+(2*$line_height)+8,70,$FontSize,$DisplayBalance, 'right'); + $FontSize=10; - /*draw a line under the balance info */ - $YPos = $Bottom_Margin+(2*$line_height); - $pdf->line($Left_Margin, $YPos,$Perforation,$YPos); + $pdf->addText($Left_Margin+75, ($Bottom_Margin+10)+(3*$line_height)+4, $FontSize, _('Current'). ' '); + $pdf->addText($Left_Margin+158, ($Bottom_Margin+10)+(3*$line_height)+4, $FontSize, _('Past Due').' '); + $pdf->addText($Left_Margin+242, ($Bottom_Margin+10)+(3*$line_height)+4, $FontSize, $_SESSION['PastDueDays1'] . '-' . $_SESSION['PastDueDays2'] . ' ' . _('days') ); + $pdf->addText($Left_Margin+315, ($Bottom_Margin+10)+(3*$line_height)+4, $FontSize, _('Over').' ' . $_SESSION['PastDueDays2'] . ' '. _('days')); + $pdf->addText($Left_Margin+442, ($Bottom_Margin+10)+(3*$line_height)+4, $FontSize, _('Total Balance') ); + $LeftOvers = $pdf->addTextWrap($Left_Margin+37, $Bottom_Margin+(2*$line_height)+8,70,$FontSize,$DisplayCurrent, 'right'); + $LeftOvers = $pdf->addTextWrap($Left_Margin+130, $Bottom_Margin+(2*$line_height)+8,70,$FontSize,$DisplayDue, 'right'); + $LeftOvers = $pdf->addTextWrap($Left_Margin+222, $Bottom_Margin+(2*$line_height)+8,70,$FontSize,$DisplayOverdue1, 'right'); - if (mb_strlen($StmtHeader['lastpaiddate'])>1 AND $StmtHeader['lastpaid']!=0){ - $pdf->addText($Left_Margin+5, $Bottom_Margin+13, $FontSize, _('Last payment received').' ' . ConvertSQLDate($StmtHeader['lastpaiddate']) . - ' ' . _('Amount received was').' ' . locale_number_format($StmtHeader['lastpaid'],$StmtHeader['currdecimalplaces'])); + $LeftOvers = $pdf->addTextWrap($Left_Margin+305, $Bottom_Margin+(2*$line_height)+8,70,$FontSize,$DisplayOverdue2, 'right'); - } + $LeftOvers = $pdf->addTextWrap($Left_Margin+432, $Bottom_Margin+(2*$line_height)+8,70,$FontSize,$DisplayBalance, 'right'); - /* Show the bank account details */ - $pdf->addText($Perforation-250, $Bottom_Margin+32, $FontSize, _('Please make payments to our account:') . ' ' . $DefaultBankAccountNumber); - $pdf->addText($Perforation-250, $Bottom_Margin+32-$line_height, $FontSize, _('Quoting your account reference') . ' ' . $StmtHeader['debtorno'] ); - /*also show the total due in the remittance section */ - if ($AgedAnalysis['balance']>0){ /*No point showing a negative balance for payment! */ - $FontSize=8; - $LeftOvers = $pdf->addTextWrap($Perforation+2, $Bottom_Margin+(2*$line_height)+8,40,$FontSize, _('Payment'), 'left'); - $LeftOvers = $pdf->addTextWrap($Page_Width-$Right_Margin-90, $Bottom_Margin+(2*$line_height)+8,88,$FontSize,$DisplayBalance, 'right'); + /*draw a line under the balance info */ + $YPos = $Bottom_Margin+(2*$line_height); + $pdf->line($Left_Margin, $YPos,$Perforation,$YPos); - } - } /* end of check to see that there were statement transactons to print */ + if (mb_strlen($StmtHeader['lastpaiddate'])>1 AND $StmtHeader['lastpaid']!=0){ + $pdf->addText($Left_Margin+5, $Bottom_Margin+13, $FontSize, _('Last payment received').' ' . ConvertSQLDate($StmtHeader['lastpaiddate']) . + ' ' . _('Amount received was').' ' . locale_number_format($StmtHeader['lastpaid'],$StmtHeader['currdecimalplaces'])); - } /* end loop to print statements */ + } - if (isset($pdf)){ - if (isset($_GET['Email'])){ //email the invoice to address supplied - include ('includes/htmlMimeMail.php'); - $FileName = 'XXX_' . 'Statement_' . $Cust_No . '_' . $Cust_Name . '.pdf'; - $pdf->Output($FileName,'F'); - $mail = new htmlMimeMail(); + /* Show the bank account details */ + $pdf->addText($Perforation-250, $Bottom_Margin+32, $FontSize, _('Please make payments to our account:') . ' ' . $DefaultBankAccountNumber); + $pdf->addText($Perforation-250, $Bottom_Margin+32-$line_height, $FontSize, _('Quoting your account reference') . ' ' . $StmtHeader['debtorno'] ); - $Attachment = $mail->getFile($FileName); - $mail->setText(_('Please find attached Statements') ); - $mail->SetSubject('Your Statement From XXX'); - $mail->addAttachment($Attachment, $FileName, 'application/pdf'); - if($_SESSION['SmtpSetting'] == 0){ - $mail->setFrom($_SESSION['CompanyRecord']['coyname'] . ' <' . $_SESSION['CompanyRecord']['email'] . '>'); - $result = $mail->send(array($_GET['Email'])); - }else{ - $result = SendmailBySmtp($mail,array($_GET['Email'])); - } + /*also show the total due in the remittance section */ + if ($AgedAnalysis['balance']>0){ /*No point showing a negative balance for payment! */ + $FontSize=8; + $LeftOvers = $pdf->addTextWrap($Perforation+2, $Bottom_Margin+(2*$line_height)+8,40,$FontSize, _('Payment'), 'left'); + $LeftOvers = $pdf->addTextWrap($Page_Width-$Right_Margin-90, $Bottom_Margin+(2*$line_height)+8,88,$FontSize,$DisplayBalance, 'right'); - unlink($FileName); //delete the temporary file + } - $Title = _('Emailing customer statements'); - include('includes/header.inc'); - echo '<p>' . _(' Customer statements has been emailed to') . ' ' . $_GET['Email']; - include('includes/footer.inc'); - exit; + } /* end of check to see that there were statement transactons to print */ + if ($_POST['EmailOrPrint']=='email'){ + $FileName = 'Statement_Account_' . $StmtHeader['debtorno'] . '.pdf'; + $pdf->Output($FileName,'F'); + $mail = new htmlMimeMail(); + $Attachment = $mail->getFile($FileName); + $mail->setText(_('Please find a statement or your account attached') ); + $mail->SetSubject($_SESSION['CompanyRecord']['coyname'] . ' ' . _('Customer Account Statement')); + $mail->addAttachment($Attachment, $FileName, 'application/pdf'); + if($_SESSION['SmtpSetting'] == 0){ + $mail->setFrom($_SESSION['CompanyRecord']['coyname'] . ' <' . $_SESSION['CompanyRecord']['email'] . '>'); + $result = $mail->send($RecipientArray); + } else{ + $result = SendmailBySmtp($mail,array($RecipientArray)); + } + echo '<tr> + <td>' , $StmtHeader['debtorno'], '</td> + <td>' , $StmtHeader['name'], '</td> + <td>'; + $i=0; + foreach ($RecipientArray as $Recipient) { + if ($i>0) { + echo '<br />'; + } + echo $Recipient; + $i++; + } + echo '</td></tr>'; + unlink($FileName); //delete the temporary file + $pdf->__destruct(); + } + } /* end if we are printing or if we are emailing and there are recipients to email */ + } /* end loop to print statements */ - - } else { //its not an email just print the invoice to PDF - + if (isset($pdf) AND $_POST['EmailOrPrint']=='print'){ $pdf->OutputD($_SESSION['DatabaseName'] . '_CustStatements_' . date('Y-m-d') . '.pdf'); - - - } - - $pdf->__destruct(); - - } else { + $pdf->__destruct(); + } elseif (!isset($pdf)) { $Title = _('Print Statements') . ' - ' . _('No Statements Found'); include('includes/header.inc'); echo '<br /><br /><br />' . prnMsg( _('There were no statements to print') ); @@ -493,13 +522,23 @@ echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />'; echo '<table class="selection">'; - echo '<tr><td>' . _('Starting Customer statement to print (Customer code)'). ' - </td><td><input type="text" maxlength="10" size="8" name="FromCust" value="0" /></td></tr> - <tr><td>' . _('Ending Customer statement to print (Customer code)') . '</td><td> - <input type="text" maxlength="10" size="8" name="ToCust" value="zzzzzz" /></td></tr></table> + echo '<tr> + <td>' , _('Starting Customer statement to print (Customer code)') , '</td> + <td><input type="text" maxlength="10" size="8" name="FromCust" value="0" /></td></tr> + <tr> + <td>' , _('Ending Customer statement to print (Customer code)') , '</td> + <td><input type="text" maxlength="10" size="8" name="ToCust" value="zzzzzz" /></td> + </tr> + <tr> + <td>' , _('Print Or Email to flagged customer contacts') , '</td> + <td><select name="EmailOrPrint"> + <option selected="selected" value="print">', _('Print') , '</option> + <option value="email">', _('Email to flagged customer contacts') , '</option> + </select></td> + </table> <br /><div class="centre"> <input type="submit" name="PrintPDF" value="' . - _('Print All Statements in the Range Selected').'" /> + _('Print (or Email) All Statements in the Range Selected').'" /> </div>'; echo '</div> </form>'; Modified: trunk/SelectCustomer.php =================================================================== --- trunk/SelectCustomer.php 2016-05-23 07:40:48 UTC (rev 7541) +++ trunk/SelectCustomer.php 2016-05-28 03:45:56 UTC (rev 7542) @@ -729,6 +729,7 @@ <th class="ascending">' . _('Role') . '</th> <th class="ascending">' . _('Phone Number') . '</th> <th class="ascending">' . _('Email') . '</th> + <th class="text">' . _('Statement') . '</th> <th class="text">', _('Notes'), '</th> <th class="noprint">', _('Edit'), '</th> <th class="noprint">' . _('Delete') . '</th> @@ -750,13 +751,14 @@ echo '<tr class="EvenTableRows">'; $k = 1; } - echo '<td>' . $myrow[2] . '</td> - <td>' . $myrow[3] . '</td> - <td>' . $myrow[4] . '</td> - <td><a href="mailto:' . $myrow[6] . '">' . $myrow[6] . '</a></td> - <td>' . $myrow[5] . '</td> - <td><a href="AddCustomerContacts.php?Id=' . $myrow[0] . '&DebtorNo=' . $myrow[1] . '">' . _('Edit') . '</a></td> - <td><a href="AddCustomerContacts.php?Id=' . $myrow[0] . '&DebtorNo=' . $myrow[1] . '&delete=1">' . _('Delete') . '</a></td> + echo '<td>' , $myrow[2] , '</td> + <td>' , $myrow[3] , '</td> + <td>' , $myrow[4] , '</td> + <td><a href="mailto:' , $myrow[6] , '">' , $myrow[6] . '</a></td> + <td>' , ($myrow[7]==0) ? _('No') : _('Yes'), '</td> + <td>' , $myrow[5] , '</td> + <td><a href="AddCustomerContacts.php?Id=' , $myrow[0] , '&DebtorNo=' , $myrow[1] , '">' , _('Edit') , '</a></td> + <td><a href="AddCustomerContacts.php?Id=' , $myrow[0] , '&DebtorNo=' , $myrow[1] , '&delete=1">' , _('Delete') , '</a></td> </tr>'; }// END WHILE LIST LOOP Modified: trunk/doc/Change.log =================================================================== --- trunk/doc/Change.log 2016-05-23 07:40:48 UTC (rev 7541) +++ trunk/doc/Change.log 2016-05-28 03:45:56 UTC (rev 7542) @@ -2,7 +2,8 @@ 22/5/16 Release 4.13 -23/5/16 Phil: PrintCustomerStatement.php now shows all the date. +28/5/16 Phil: PrintCustStatement.php now has an option to email the statement and uses the customer contacts email addresses defined as wanting a statement and sends individual statements to each of the customer contacts for their customer statement and lists the customers and the recipients they have been sent to. The existing emailcustomerstatement script had too much potential to send statement for other customers to another customer by mistake - so I've removed it! +23/5/16 Phil: PrintCustStatement.php now shows all the date. 23/5/16 Phil: Credit_Invoice.php now adds correct tax authorities - correcting bug that resulted in foreign key errors when adding taxauthorities as per fix to SelectCreditItems.php on 13/1/16 20/5/16 Phil: POS upload file now includes assembly items 20/5/16 RChacon: Insert missing script as an utility. Modified: trunk/doc/Manual/ManualAccountsReceivable.html =================================================================== --- trunk/doc/Manual/ManualAccountsReceivable.html 2016-05-23 07:40:48 UTC (rev 7541) +++ trunk/doc/Manual/ManualAccountsReceivable.html 2016-05-28 03:45:56 UTC (rev 7542) @@ -22,6 +22,8 @@ <li>Any number of branch - delivery addresses can be added serviced by different sales people with different tax authorities and different areas for sales analysis purposes.</li> <li>Unlimited free form notes can be maintained for each customer and an unlimited number of contacts can be stored against each customer></li> + + <li>Email of customer statements to multiple customer contacts</li> </ul><!-- Help Begin: Customers --> <div class="floatright"> @@ -179,9 +181,13 @@ <li>Changing the payment terms impacts immediately on the aged analysis since this is recalculated each time it is run or a statement is produced.</li> <li>Changing the currency of the customer needs care since the exchange rate is recorded against each transaction. Allocations of one currency against another at different rates will produce differences on exchange. The system will not be able to distinguish at the transactions level which was in what currency only the rate against the functional currency.</li> -</ul><!-- Help End: Customers --> -<!-- Help Begin: Shippers --> +</ul> +<h2><a id="CustomerStatements">Customer Statements</a></h2> + +<p>Customer statements can either be printed or emailed directly to all the customers in the selected range, that have a contact defined as receiving a statement. If there are no contacts defined for the customer that have the statement flag set to yes then their statement will not be emailed to them. If the customer has many contacts with several of them having the statement flag set to yes then all those contacts will receive a copy of the pdf statement.</p> + + <div class="floatright"> <a class="minitext" href="#top">⬆ Top</a> </div> @@ -189,7 +195,8 @@ <h2><a id="CustomerNotes">Customer Notes</a></h2> <p>Customer notes containing any text - a web-link if required and a date can be entered from the Select Customer screen - for the selected customer. The notes are displayed in sequence of priority - so pressing issues appear at the top of the list. These notes might contain information about recent contact with the customer or disputes. There is no checking on the content of the notes and no limit to either the number of notes nor the number of characters that can be used.</p> - +<!-- Help End: Customers --> +<!-- Help Begin: Shippers --> <h2>Shippers</h2> <p>This table is only used as a reference to the method of transportation that the invoice delivery was effected by. The shippers name is what is used in the look ups and the code is a system maintained counter which is stored in the database to reference the freight company used. The consignment note reference can be stored against the transaction in the reference field. In this way a full proof of delivery trail can be maintained.</p> Modified: trunk/sql/mysql/upgrade4.12.3-4.13.sql =================================================================== --- trunk/sql/mysql/upgrade4.12.3-4.13.sql 2016-05-23 07:40:48 UTC (rev 7541) +++ trunk/sql/mysql/upgrade4.12.3-4.13.sql 2016-05-28 03:45:56 UTC (rev 7542) @@ -58,7 +58,7 @@ ALTER table pctabs CHANGE assigner assigner varchar(100); INSERT INTO securitytokens VALUES(18,'Cost authority'); ALTER table bom ADD digitals int(11) NOT NULL DEFAULT 0; +ALTER table custcontacts ADD statement tinyint(4) NOT NULL DEFAULT 0; - -- Update version number: UPDATE config SET confvalue='4.13' WHERE confname='VersionNumber'; |