From: <tim...@us...> - 2010-01-12 13:44:15
|
Revision: 3294 http://web-erp.svn.sourceforge.net/web-erp/?rev=3294&view=rev Author: tim_schofield Date: 2010-01-12 13:44:08 +0000 (Tue, 12 Jan 2010) Log Message: ----------- New script to change a stock category code Modified Paths: -------------- trunk/doc/Change.log.html Added Paths: ----------- trunk/Z_ChangeStockCategory.php Added: trunk/Z_ChangeStockCategory.php =================================================================== --- trunk/Z_ChangeStockCategory.php (rev 0) +++ trunk/Z_ChangeStockCategory.php 2010-01-12 13:44:08 UTC (rev 3294) @@ -0,0 +1,101 @@ +<?php + +/* $Id$ */ +$PageSecurity = 15; +include ('includes/session.inc'); +$title = _('UTILITY PAGE Change A Stock Category'); +include ('includes/header.inc'); +include ('includes/SQL_CommonFunctions.inc'); + +if (isset($_POST['ProcessStockChange'])) { + $_POST['NewStockCategory'] = strtoupper($_POST['NewStockCategory']); + + /*First check the stock code exists */ + $result = DB_query("SELECT categoryid FROM stockcategory WHERE categoryid='" . $_POST['OldStockCategory'] . "'", $db); + + if (DB_num_rows($result) == 0) { + prnMsg(_('The stock Category') . ': ' . $_POST['OldStockCategory'] . ' ' . _('does not currently exist as a stock category in the system'), 'error'); + include ('includes/footer.inc'); + exit; + } + + if (ContainsIllegalCharacters($_POST['NewStockCategory'])) { + prnMsg(_('The new stock code to change the old code to contains illegal characters - no changes will be made'), 'error'); + include ('includes/footer.inc'); + exit; + } + + if ($_POST['NewStockCategory'] == '') { + prnMsg(_('The new stock code to change the old code to must be entered as well'), 'error'); + include ('includes/footer.inc'); + exit; + } + + /*Now check that the new code doesn't already exist */ + $result = DB_query("SELECT categoryid FROM stockcategory WHERE categoryid='" . $_POST['NewStockCategory'] . "'", $db); + + if (DB_num_rows($result) != 0) { + echo '<br><br>'; + prnMsg(_('The replacement stock category') . ': ' . $_POST['NewStockCategory'] . ' ' . _('already exists as a stock category in the system') . ' - ' . _('a unique stock category must be entered for the new stock category'), 'error'); + include ('includes/footer.inc'); + exit; + } + $result = DB_Txn_Begin($db); + echo '<br>' . _('Adding the new stock Category record'); + $sql = "INSERT INTO stockcategory (categoryid, + categorydescription, + stocktype, + stockact, + adjglact, + purchpricevaract, + materialuseagevarac, + wipact) + SELECT '" . $_POST['NewStockCategory'] . "', + categorydescription, + stocktype, + stockact, + adjglact, + purchpricevaract, + materialuseagevarac, + wipact + FROM stockcategory + WHERE categoryid='" . $_POST['OldStockCategory'] . "'"; + $DbgMsg = _('The SQL statement that failed was'); + $ErrMsg = _('The SQL to insert the new stock category record failed'); + $result = DB_query($sql, $db, $ErrMsg, $DbgMsg, true); + echo ' ... ' . _('completed'); + echo '<br>' . _('Changing stock properties'); + $sql = "UPDATE stockcatproperties SET categoryid='" . $_POST['NewStockCategory'] . "' WHERE categoryid='" . $_POST['OldStockCategory'] . "'"; + $ErrMsg = _('The SQL to update stock properties records failed'); + $result = DB_query($sql, $db, $ErrMsg, $DbgMsg, true); + echo ' ... ' . _('completed'); + echo '<br>' . _('Changing stock master records'); + $sql = "UPDATE stockmaster SET categoryid='" . $_POST['NewStockCategory'] . "' WHERE categoryid='" . $_POST['OldStockCategory'] . "'"; + $ErrMsg = _('The SQL to update stock master transaction records failed'); + $result = DB_query($sql, $db, $ErrMsg, $DbgMsg, true); + echo ' ... ' . _('completed'); + echo '<br>' . _('Changing sales analysis records'); + $sql = "UPDATE salesanalysis SET stkcategory='" . $_POST['NewStockID'] . "' WHERE stkcategory='" . $_POST['OldStockCategory'] . "'"; + $ErrMsg = _('The SQL to update Sales Analysis records failed'); + $result = DB_query($sql, $db, $ErrMsg, $DbgMsg, true); + echo ' ... ' . _('completed'); + $sql = 'SET FOREIGN_KEY_CHECKS=1'; + $result = DB_query($sql, $db, $ErrMsg, $DbgMsg, true); + $result = DB_Txn_Commit($db); + echo '<br>' . _('Deleting the old stock category record'); + $sql = "DELETE FROM stockcategory WHERE categoryid='" . $_POST['OldStockCategory'] . "'"; + $ErrMsg = _('The SQL to delete the old stock category record failed'); + $result = DB_query($sql, $db, $ErrMsg, $DbgMsg, true); + echo ' ... ' . _('completed'); + echo '<p>' . _('Stock Code') . ': ' . $_POST['OldStockCategory'] . ' ' . _('was successfully changed to') . ' : ' . $_POST['NewStockCategory']; +} +echo "<form action='" . $_SERVER['PHP_SELF'] . "?=" . $SID . "' method=post>"; +echo '<p><table> + <tr><td>' . _('Existing Inventory Category Code') . ":</td> + <td><input type=Text name='OldStockCategory' size=20 maxlength=20></td></tr>"; +echo '<tr><td>' . _('New Inventory Category Code') . ":</td><td><input type=Text name='NewStockCategory' size=20 maxlength=20></td></tr>"; +echo '</table>'; +echo "<div class='centre'><input type=submit name='ProcessStockChange' VALUE='" . _('Process') . "'></div>"; +echo '</form>'; +include ('includes/footer.inc'); +?> \ No newline at end of file Property changes on: trunk/Z_ChangeStockCategory.php ___________________________________________________________________ Added: svn:keywords + Id Modified: trunk/doc/Change.log.html =================================================================== --- trunk/doc/Change.log.html 2010-01-12 11:02:25 UTC (rev 3293) +++ trunk/doc/Change.log.html 2010-01-12 13:44:08 UTC (rev 3294) @@ -1,5 +1,7 @@ <p><font SIZE=4 COLOR=BLUE><b>webERP Change Log</b></font></p> <p> +<p>12/01/10 Pak Ricard: Z_ChangeStockCategory.php - New script to change a stock category code</p> +<p>12/01/10 Chris Franks: PDFGrn.php - Show the date in the correct format</p> <p>12/01/10 Tim: Z_ChangeStockCode.php - Check thast mrpplannedorders table exists before trying to alter it</p> <p>10/01/10 Tim: StockTransfers.php - Correctly show stockid in links to ther functions.</p> <p>10/01/10 Bryan Nielsen: BOMs.php - syntax error includes() was used not include()</p> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |