From: <dai...@us...> - 2014-01-24 09:27:50
|
Revision: 6548 http://sourceforge.net/p/web-erp/reponame/6548 Author: daintree Date: 2014-01-24 09:27:46 +0000 (Fri, 24 Jan 2014) Log Message: ----------- fixed error traps on customers and branches as per Ricards report Modified Paths: -------------- trunk/CustomerBranches.php trunk/Customers.php trunk/doc/Change.log Modified: trunk/CustomerBranches.php =================================================================== --- trunk/CustomerBranches.php 2014-01-24 08:52:53 UTC (rev 6547) +++ trunk/CustomerBranches.php 2014-01-24 09:27:46 UTC (rev 6548) @@ -53,7 +53,7 @@ if ($_SESSION['SalesmanLogin'] != '') { $_POST['Salesman'] = $_SESSION['SalesmanLogin']; } - if (ContainsIllegalCharacters($_POST['BranchCode']) OR mb_strstr($_POST['BranchCode'],' ') OR mb_strstr($_POST['BranchCode'],'-')) { + if (ContainsIllegalCharacters($_POST['BranchCode']) OR mb_strstr($_POST['BranchCode'],' ')) { $InputError = 1; prnMsg(_('The Branch code cannot contain any of the following characters')." - & \' < >",'error'); $Errors[$i] = 'BranchCode'; @@ -340,15 +340,25 @@ prnMsg(_('Cannot delete this branch because contract have been created that refer to it') . '. ' . _('Purge old contracts first'),'warn'); echo '<br />' . _('There are') . ' ' . $myrow[0] . ' '._('contracts referring to this branch/customer'); } else { - $SQL="DELETE FROM custbranch WHERE branchcode='" . $SelectedBranch . "' AND debtorno='" . $DebtorNo . "'"; - if ($_SESSION['SalesmanLogin'] != '') { - $SQL .= " AND custbranch.salesman='" . $_SESSION['SalesmanLogin'] . "'"; + //check if this it the last customer branch - don't allow deletion of the last branch + $SQL = "SELECT COUNT(*) FROM custbranch WHERE debtorno='" . $DebtorNo . "'"; + + $result = DB_query($SQL,$db); + $myrow = DB_fetch_row($result); + + if ($myrow[0]==1) { + prnMsg(_('Cannot delete this branch because it is the only branch defined for this customer.'),'warn'); + } else { + $SQL="DELETE FROM custbranch WHERE branchcode='" . $SelectedBranch . "' AND debtorno='" . $DebtorNo . "'"; + if ($_SESSION['SalesmanLogin'] != '') { + $SQL .= " AND custbranch.salesman='" . $_SESSION['SalesmanLogin'] . "'"; + } + $ErrMsg = _('The branch record could not be deleted') . ' - ' . _('the SQL server returned the following message'); + $result = DB_query($SQL,$db,$ErrMsg); + if (DB_error_no($db)==0){ + prnMsg(_('Branch Deleted'),'success'); + } } - $ErrMsg = _('The branch record could not be deleted') . ' - ' . _('the SQL server returned the following message'); - $result = DB_query($SQL,$db,$ErrMsg); - if (DB_error_no($db)==0){ - prnMsg(_('Branch Deleted'),'success'); - } } } } @@ -394,16 +404,16 @@ ' . ' ' . _('Branches defined for'). ' '. $DebtorNo . ' - ' . $myrow[0] . '</p>'; echo '<table class="selection"> <tr> - <th>' . _('Code') . '</th> - <th>' . _('Name') . '</th> - <th>' . _('Branch Contact') . '</th> - <th>' . _('Salesman') . '</th> - <th>' . _('Area') . '</th> - <th>' . _('Phone No') . '</th> - <th>' . _('Fax No') . '</th> - <th>' . _('Email') . '</th> - <th>' . _('Tax Group') . '</th> - <th>' . _('Enabled?') . '</th> + <th class="ascending">' . _('Code') . '</th> + <th class="ascending">' . _('Name') . '</th> + <th class="ascending">' . _('Branch Contact') . '</th> + <th class="ascending">' . _('Salesman') . '</th> + <th class="ascending">' . _('Area') . '</th> + <th class="ascending">' . _('Phone No') . '</th> + <th class="ascending">' . _('Fax No') . '</th> + <th class="ascending">' . _('Email') . '</th> + <th class="ascending">' . _('Tax Group') . '</th> + <th class="ascending">' . _('Enabled?') . '</th> </tr>'; $k=0; Modified: trunk/Customers.php =================================================================== --- trunk/Customers.php 2014-01-24 08:52:53 UTC (rev 6547) +++ trunk/Customers.php 2014-01-24 09:27:46 UTC (rev 6548) @@ -312,24 +312,40 @@ prnMsg( _('Cannot delete this customer record because sales analysis records exist for it'),'warn'); echo '<br /> ' . _('There are') . ' ' . $myrow[0] . ' ' . _('sales analysis records against this customer'); } else { - $sql= "SELECT COUNT(*) FROM custbranch WHERE debtorno='" . $_POST['DebtorNo'] . "'"; - $result = DB_query($sql,$db); + + // Check if there are any users that refer to this CUSTOMER code + $SQL= "SELECT COUNT(*) FROM www_users WHERE www_users.customerid = '" . $_POST['DebtorNo'] . "'"; + + $result = DB_query($SQL,$db); $myrow = DB_fetch_row($result); + if ($myrow[0]>0) { - $CancelDelete = 1; - prnMsg(_('Cannot delete this customer because there are branch records set up against it'),'warn'); - echo '<br /> ' . _('There are') . ' ' . $myrow[0] . ' ' . _('branch records relating to this customer'); + prnMsg(_('Cannot delete this customer because users exist that refer to it') . '. ' . _('Purge old users first'),'warn'); + echo '<br />' . _('There are') . ' ' . $myrow[0] . ' '._('users referring to this Branch/customer'); + } else { + // Check if there are any contract that refer to this branch code + $SQL = "SELECT COUNT(*) FROM contracts WHERE contracts.debtorno = '" . $_POST['DebtorNo'] . "'"; + + $result = DB_query($SQL,$db); + $myrow = DB_fetch_row($result); + + if ($myrow[0]>0) { + prnMsg(_('Cannot delete this customer because contracts have been created that refer to it') . '. ' . _('Purge old contracts first'),'warn'); + echo '<br />' . _('There are') . ' ' . $myrow[0] . ' '._('contracts referring to this customer'); + } } } } } if ($CancelDelete==0) { //ie not cancelled the delete as a result of above tests + $SQL="DELETE FROM custbranch WHERE debtorno='" . $_POST['DebtorNo'] . "'"; + $result = DB_query($SQL,$db,$ErrMsg); $sql="DELETE FROM custcontacts WHERE debtorno='" . $_POST['DebtorNo'] . "'"; $result = DB_query($sql,$db); $sql="DELETE FROM debtorsmaster WHERE debtorno='" . $_POST['DebtorNo'] . "'"; $result = DB_query($sql,$db); - prnMsg( _('Customer') . ' ' . $_POST['DebtorNo'] . ' ' . _('has been deleted - together with all the associated contacts') . ' !','success'); + prnMsg( _('Customer') . ' ' . $_POST['DebtorNo'] . ' ' . _('has been deleted - together with all the associated branches and contacts'),'success'); include('includes/footer.inc'); unset($_SESSION['CustomerID']); exit; Modified: trunk/doc/Change.log =================================================================== --- trunk/doc/Change.log 2014-01-24 08:52:53 UTC (rev 6547) +++ trunk/doc/Change.log 2014-01-24 09:27:46 UTC (rev 6548) @@ -1,4 +1,6 @@ webERP Change Log + +23/1/14 Phil: Fixed incompatible error traps on hyphens between new customers and new branches. Now both allow hyphens. Also prevented deletion of the last customer branch. Customer branches are now deleted when a customer is attempted to be deleted provided there are no dependent records. 19/01/14 Exson: Add sales man login control and modify the PDF to download to harmony with other files and solve backward failure problem in PrintCustStatements.php. 18/01/14 Paul T: Change property name value to uppercase to match use in the script. [causing input loss] 16/01/14 Exson: Fixed sql strict mode failure problem in StockTransfers.php by adding a '' to qualitytext fields. |