Skip to content

Commit

Permalink
Paul Becker (PaulT commit): Z_ChangeSalesmanCode.php: New script to c…
Browse files Browse the repository at this point in the history
…hange a salesman code. (Forum contribution: http://www.weberp.org/forum/showthread.php?tid=8094)

Signed-off-by: Paul Thursby <pthursby2@gmail.com>
  • Loading branch information
Paul Becker authored and timschofield committed Feb 27, 2018
1 parent 3e220cf commit e840b53
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 7 deletions.
142 changes: 142 additions & 0 deletions Z_ChangeSalesmanCode.php
@@ -0,0 +1,142 @@
<?php
/* $Id: Z_ChangeSalesmanCode.php 7751 2017-04-13 16:34:26Z rchacon $*/
/* This script is an utility to change a salesman code. */

include ('includes/session.php');

$Title = _('UTILITY PAGE To Change A Salesman Code In All Tables');// Screen identificator.
$ViewTopic = 'SpecialUtilities'; // Filename's id in ManualContents.php's TOC.
$BookMark = 'Z_ChangeSalesmanCode'; // Anchor's id in the manual's html document.

include('includes/header.php');

echo '<p class="page_title_text">
<img alt="" src="', $RootPath, '/css/', $_SESSION['Theme'], '/images/salesman.png" title="', _('Change A Salesman Code'), '" /> ', _('Change A Salesman Code'),
'</p>';

if (isset($_POST['ProcessSalesmanChange'])){

if ($_POST['OldSalesmanCode']==''){
prnMsg(_('An existing salesman code entry must be provided'), 'error');
include('includes/footer.php');
exit;
}

/*First check the salesman code exists */
$result=DB_query("SELECT salesmancode FROM salesman WHERE salesmancode='" . $_POST['OldSalesmanCode'] . "'");
if (DB_num_rows($result) == 0){
prnMsg('<br /><br />' . _('The salesman code') . ': ' . $_POST['OldSalesmanCode'] . ' ' . _('does not currently exist as a salesman code in the system'), 'error');
include('includes/footer.php');
exit;
}

if ($_POST['NewSalesmanCode']==''){
prnMsg(_('A new salesman code entry must be provided'), 'error');
include('includes/footer.php');
exit;
}
else if (ContainsIllegalCharacters($_POST['NewSalesmanCode'])) {
prnMsg(_('The new salesman code to change the old code to contains illegal characters - no changes will be made'), 'error');
include ('includes/footer.php');
exit;
}

$_POST['NewSalesmanCode'] = mb_strtoupper($_POST['NewSalesmanCode']);

/*Now check that the new code doesn't already exist */
$result=DB_query("SELECT salesmancode FROM salesman WHERE salesmancode='" . $_POST['NewSalesmanCode'] . "'");
if (DB_num_rows($result)!=0){
prnMsg(_('The replacement salesman code') .': ' . $_POST['NewSalesmanCode'] . ' ' . _('already exists as a salesman code in the system') . ' - ' . _('a unique salesman code must be entered for the new code'), 'error');
include('includes/footer.php');
exit;
}

$result = DB_Txn_Begin();

prnMsg(_('Inserting the new salesman master record'), 'info');
$sql = "INSERT INTO salesman (`salesmancode`,
`salesmanname`,
`commissionrate1`,
`commissionrate2`,
`breakpoint`,
`smantel`,
`smanfax`,
`current`)
SELECT '" . $_POST['NewSalesmanCode'] . "',
`salesmanname`,
`commissionrate1`,
`commissionrate2`,
`breakpoint`,
`smantel`,
`smanfax`,
`current`
FROM salesman
WHERE salesmancode='" . $_POST['OldSalesmanCode'] . "'";

$DbgMsg =_('The SQL that failed was');
$ErrMsg = _('The SQL to insert the new salesman master record failed') . ', ' . _('the SQL statement was');
$result = DB_query($sql,$ErrMsg,$DbgMsg,true);

prnMsg(_('Changing debtor branch records'), 'info');
$sql = "UPDATE custbranch SET salesman='" . $_POST['NewSalesmanCode'] . "' WHERE salesman='" . $_POST['OldSalesmanCode'] . "'";

$ErrMsg = _('The SQL to update debtor branch records failed');
$result = DB_query($sql,$ErrMsg,$DbgMsg,true);

prnMsg(_('Changing debtor transaction records'), 'info');
$sql = "UPDATE debtortrans SET salesperson='" . $_POST['NewSalesmanCode'] . "' WHERE salesperson='" . $_POST['OldSalesmanCode'] . "'";

$ErrMsg = _('The SQL to update debtor transaction records failed');
$result = DB_query($sql,$ErrMsg,$DbgMsg,true);

prnMsg(_('Changing sales analysis records'), 'info');
$sql = "UPDATE salesanalysis SET salesperson='" . $_POST['NewSalesmanCode'] . "' WHERE salesperson='" . $_POST['OldSalesmanCode'] . "'";

$ErrMsg = _('The SQL to update Sales Analysis records failed');
$result = DB_query($sql,$ErrMsg,$DbgMsg,true);

prnMsg(_('Changing sales orders records'), 'info');
$sql = "UPDATE salesorders SET salesperson='" . $_POST['NewSalesmanCode'] . "' WHERE salesperson='" . $_POST['OldSalesmanCode'] . "'";

$ErrMsg = _('The SQL to update the sales order header records failed');
$result = DB_query($sql,$ErrMsg,$DbgMsg,true);

prnMsg(_('Changing user salesman records'), 'info');
$sql = "UPDATE www_users SET salesman='" . $_POST['NewSalesmanCode'] . "' WHERE salesman='" . $_POST['OldSalesmanCode'] . "'";

$ErrMsg = _('The SQL to update the user records failed');
$result = DB_query($sql,$ErrMsg,$DbgMsg,true);

$result = DB_IgnoreForeignKeys();

prnMsg(_('Deleting the salesman code from the Salesman table'), 'info');
$sql = "DELETE FROM salesman WHERE salesmancode='" . $_POST['OldSalesmanCode'] . "'";

$ErrMsg = _('The SQL to delete the old salesman record failed');
$result = DB_query($sql,$ErrMsg,$DbgMsg,true);

$result = DB_Txn_Commit();
$result = DB_ReinstateForeignKeys();
}

echo '<form action="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '" method="post">
<div class="centre">
<input type="hidden" name="FormID" value="', $_SESSION['FormID'], '" />
<br />
<table>
<tr>
<td>', _('Existing Salesman Code'), ':</td>
<td><input type="text" name="OldSalesmanCode" size="4" maxlength="4" required="required" /></td>
</tr>
<tr>
<td> ', _('New Salesman Code'), ':</td>
<td><input type="text" name="NewSalesmanCode" size="4" maxlength="4" required="required"/></td>
</tr>
</table>
<input type="submit" name="ProcessSalesmanChange" value="', _('Process'), '" />
</div>
</form>';

include('includes/footer.php');
?>
3 changes: 2 additions & 1 deletion doc/Change.log
@@ -1,6 +1,7 @@
webERP Change Log

13/2/18 Paul Becker (PaulT commit): Minor change to remove number from input field committed with 7946, and add attributes on two input fields. (Reported in forums: http://www.weberp.org/forum/showthread.php?tid=8089&pid=14266#pid14266)
16/2/18 Paul Becker (PaulT commit): Z_ChangeSalesmanCode.php: New script to change a salesman code. (Forum contribution: http://www.weberp.org/forum/showthread.php?tid=8094)
13/2/18 Paul Becker (PaulT commit): InternalStockRequestFulfill.php: Minor change to remove number from input field committed with 7946, and add attributes on two input fields. (Reported in forums: http://www.weberp.org/forum/showthread.php?tid=8089&pid=14266#pid14266)
12/2/18 PaulT: Remove $db parameter from PeriodExists(), CreatePeriod(), CalcFreightCost(), CheckForRecursiveBOM(), DisplayBOMItems() and a few other functions.
12/2/18 PaulT: InternalStockRequest.php: Address a few issues reported by Paul B: Fix Previous/Next handling, table sorting, wrong on-order quantities, and apply the user's display records max. Change also removes unused code and other minor improvements. (Reported in forums: http://www.weberp.org/forum/showthread.php?tid=8089)
12/2/18 Tim (PaulT commit): StockMovements.php, StockLocMovements.php: Correct stock movements that have more than one serial number as part of it, then the item will appear multiple times in the movements script with the total quantity in each line. For example, if I enter a quantity adjustment for a controlled item, and assign 3 serial numbers to this movement and then run the inquiries, there will be 3 separate lines with a quantity of 3 against each one.
Expand Down
14 changes: 8 additions & 6 deletions includes/MainMenuLinksArray.php
Expand Up @@ -585,11 +585,12 @@

$MenuItems['Utilities']['Transactions']['Caption'] = array( _('Change A Customer Code'),
_('Change A Customer Branch Code'),
_('Change A Supplier Code'),
_('Change A Stock Category Code'),
_('Change An Inventory Item Code'),
_('Change A GL Account Code'),
_('Change An Inventory Item Code'),
_('Change A Location Code'),
_('Change A Salesman Code'),
_('Change A Stock Category Code'),
_('Change A Supplier Code'),
_('Translate Item Descriptions'),
_('Update costs for all BOM items, from the bottom up'),
_('Re-apply costs to Sales Analysis'),
Expand All @@ -600,11 +601,12 @@

$MenuItems['Utilities']['Transactions']['URL'] = array( '/Z_ChangeCustomerCode.php',
'/Z_ChangeBranchCode.php',
'/Z_ChangeSupplierCode.php',
'/Z_ChangeStockCategory.php',
'/Z_ChangeStockCode.php',
'/Z_ChangeGLAccountCode.php',
'/Z_ChangeStockCode.php',
'/Z_ChangeLocationCode.php',
'/Z_ChangeSalesmanCode.php',
'/Z_ChangeStockCategory.php',
'/Z_ChangeSupplierCode.php',
'/AutomaticTranslationDescriptions.php',
'/Z_BottomUpCosts.php',
'/Z_ReApplyCostToSA.php',
Expand Down

0 comments on commit e840b53

Please sign in to comment.