|
From: <te...@us...> - 2013-05-23 04:22:06
|
Revision: 5982
http://sourceforge.net/p/web-erp/reponame/5982
Author: tehonu
Date: 2013-05-23 04:22:02 +0000 (Thu, 23 May 2013)
Log Message:
-----------
Pak Ricard: Simplify code and reuse of ChangeFieldInTable();
Modified Paths:
--------------
trunk/Z_ChangeGLAccountCode.php
trunk/Z_ChangeStockCode.php
trunk/includes/MiscFunctions.php
Modified: trunk/Z_ChangeGLAccountCode.php
===================================================================
--- trunk/Z_ChangeGLAccountCode.php 2013-05-22 09:25:31 UTC (rev 5981)
+++ trunk/Z_ChangeGLAccountCode.php 2013-05-23 04:22:02 UTC (rev 5982)
@@ -148,13 +148,5 @@
include('includes/footer.inc');
-function ChangeFieldInTable($TableName, $FieldName, $OldValue, $NewValue, $db){
- echo '<br />' . _('Changing') . ' ' . $TableName . ' ' . _('records');
- $sql = "UPDATE " . $TableName . " SET " . $FieldName . " ='" . $NewValue . "' WHERE " . $FieldName . "='" . $OldValue . "'";
- $DbgMsg = _('The SQL statement that failed was');
- $ErrMsg = _('The SQL to update' . ' ' . $TableName . ' ' . _('records failed'));
- $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
- echo ' ... ' . _('completed');
-}
?>
\ No newline at end of file
Modified: trunk/Z_ChangeStockCode.php
===================================================================
--- trunk/Z_ChangeStockCode.php 2013-05-22 09:25:31 UTC (rev 5981)
+++ trunk/Z_ChangeStockCode.php 2013-05-23 04:22:02 UTC (rev 5982)
@@ -2,8 +2,6 @@
/* $Id$*/
-/*Script to Delete all sales transactions*/
-
include ('includes/session.inc');
$Title = _('UTILITY PAGE Change A Stock Code');
include('includes/header.inc');
@@ -44,7 +42,6 @@
if ($InputError ==0){ // no input errors
$result = DB_Txn_Begin($db);
-
echo '<br />' . _('Adding the new stock master record');
$sql = "INSERT INTO stockmaster (stockid,
categoryid,
@@ -106,146 +103,44 @@
$result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
echo ' ... ' . _('completed');
- echo '<br />' . _('Changing stock location records');
- $sql = "UPDATE locstock SET stockid='" . $_POST['NewStockID'] . "' WHERE stockid='" . $_POST['OldStockID'] . "'";
- $ErrMsg = _('The SQL to update stock location records failed');
- $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
- echo ' ... ' . _('completed');
+ ChangeFieldInTable("locstock", "stockid", $_POST['OldStockID'], $_POST['NewStockID'], $db);
+ ChangeFieldInTable("stockmoves", "stockid", $_POST['OldStockID'], $_POST['NewStockID'], $db);
+ ChangeFieldInTable("loctransfers", "stockid", $_POST['OldStockID'], $_POST['NewStockID'], $db);
+ ChangeFieldInTable("mrpdemands", "stockid", $_POST['OldStockID'], $_POST['NewStockID'], $db);
- echo '<br />' . _('Changing stock movement records');
- $sql = "UPDATE stockmoves SET stockid='" . $_POST['NewStockID'] . "' WHERE stockid='" . $_POST['OldStockID'] . "'";
- $ErrMsg = _('The SQL to update stock movement transaction records failed');
- $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
- echo ' ... ' . _('completed');
-
- echo '<br />' . _('Changing location transfer information');
-
- $sql = "UPDATE loctransfers SET stockid='" . $_POST['NewStockID'] . "' WHERE stockid='" . $_POST['OldStockID'] . "'";
- $ErrMsg = _('The SQL to update the loctransfers records failed');
- $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
- echo ' ... ' . _('completed');
-
- echo '<br />' . _('Changing MRP demands information');
- $sql = "UPDATE mrpdemands SET stockid='" . $_POST['NewStockID'] . "' WHERE stockid='" . $_POST['OldStockID'] . "'";
- $ErrMsg = _('The SQL to update the mrpdemands records failed');
- $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
- echo ' ... ' . _('completed');
-
//check if MRP tables exist before assuming
$result = DB_query("SELECT COUNT(*) FROM mrpplannedorders",$db,'','',false,false);
if (DB_error_no($db)==0) {
- echo '<br />' . _('Changing MRP planned orders information');
- $sql = "UPDATE mrpplannedorders SET part='" . $_POST['NewStockID'] . "' WHERE part='" . $_POST['OldStockID'] . "'";
- $ErrMsg = _('The SQL to update the mrpplannedorders records failed');
- $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
- echo ' ... ' . _('completed');
+ ChangeFieldInTable("mrpplannedorders", "part", $_POST['OldStockID'], $_POST['NewStockID'], $db);
}
$result = DB_query("SELECT * FROM mrprequirements" , $db,'','',false,false);
if (DB_error_no($db)==0){
- echo '<br />' . _('Changing MRP requirements information');
- $sql = "UPDATE mrprequirements SET part='" . $_POST['NewStockID'] . "' WHERE part='" . $_POST['OldStockID'] . "'";
- $ErrMsg = _('The SQL to update the mrprequirements records failed');
- $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
- echo ' ... ' . _('completed');
+ ChangeFieldInTable("mrprequirements", "part", $_POST['OldStockID'], $_POST['NewStockID'], $db);
}
+
$result = DB_query("SELECT * FROM mrpsupplies" , $db,'','',false,false);
if (DB_error_no($db)==0){
- echo '<br />' . _('Changing MRP supplies information');
- $sql = "UPDATE mrpsupplies SET part='" . $_POST['NewStockID'] . "' WHERE part='" . $_POST['OldStockID'] . "'";
- $ErrMsg = _('The SQL to update the mrpsupplies records failed');
- $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
- echo ' ... ' . _('completed');
+ ChangeFieldInTable("mrpsupplies", "part", $_POST['OldStockID'], $_POST['NewStockID'], $db);
}
- echo '<br />' . _('Changing sales analysis records');
- $sql = "UPDATE salesanalysis SET stockid='" . $_POST['NewStockID'] . "' WHERE stockid='" . $_POST['OldStockID'] . "'";
- $ErrMsg = _('The SQL to update Sales Analysis records failed');
- $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
- echo ' ... ' . _('completed');
+ ChangeFieldInTable("salesanalysis", "stockid", $_POST['OldStockID'], $_POST['NewStockID'], $db);
+ ChangeFieldInTable("orderdeliverydifferenceslog", "stockid", $_POST['OldStockID'], $_POST['NewStockID'], $db);
+ ChangeFieldInTable("prices", "stockid", $_POST['OldStockID'], $_POST['NewStockID'], $db);
+ ChangeFieldInTable("salesorderdetails", "stkcode", $_POST['OldStockID'], $_POST['NewStockID'], $db);
+ ChangeFieldInTable("purchorderdetails", "itemcode", $_POST['OldStockID'], $_POST['NewStockID'], $db);
+ ChangeFieldInTable("purchdata", "stockid", $_POST['OldStockID'], $_POST['NewStockID'], $db);
+ ChangeFieldInTable("shipmentcharges", "stockid", $_POST['OldStockID'], $_POST['NewStockID'], $db);
+ ChangeFieldInTable("stockcheckfreeze", "stockid", $_POST['OldStockID'], $_POST['NewStockID'], $db);
+ ChangeFieldInTable("stockcounts", "stockid", $_POST['OldStockID'], $_POST['NewStockID'], $db);
+ ChangeFieldInTable("grns", "itemcode", $_POST['OldStockID'], $_POST['NewStockID'], $db);
+ ChangeFieldInTable("contractbom", "stockid", $_POST['OldStockID'], $_POST['NewStockID'], $db);
+ ChangeFieldInTable("bom", "component", $_POST['OldStockID'], $_POST['NewStockID'], $db);
-
- echo '<br />' . _('Changing order delivery differences records');
- $sql = "UPDATE orderdeliverydifferenceslog SET stockid='" . $_POST['NewStockID'] . "' WHERE stockid='" . $_POST['OldStockID'] . "'";
- $ErrMsg = _('The SQL to update order delivery differences records failed');
- $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
- echo ' ... ' . _('completed');
-
-
- echo '<br />' . _('Changing pricing records');
- $sql = "UPDATE prices SET stockid='" . $_POST['NewStockID'] . "' WHERE stockid='" . $_POST['OldStockID'] . "'";
- $ErrMsg = _('The SQL to update the pricing records failed');
- $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
- echo ' ... ' . _('completed');
-
-
- echo '<br />' . _('Changing sales orders detail records');
- $sql = "UPDATE salesorderdetails SET stkcode='" . $_POST['NewStockID'] . "' WHERE stkcode='" . $_POST['OldStockID'] . "'";
- $ErrMsg = _('The SQL to update the sales order header records failed');
- $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
- echo ' ... ' . _('completed');
-
-
- echo '<br />' . _('Changing purchase order details records');
- $sql = "UPDATE purchorderdetails SET itemcode='" . $_POST['NewStockID'] . "' WHERE itemcode='" . $_POST['OldStockID'] . "'";
- $ErrMsg = _('The SQL to update the purchase order detail records failed');
- $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
- echo ' ... ' . _('completed');
-
-
- echo '<br />' . _('Changing purchasing data records');
- $sql = "UPDATE purchdata SET stockid='" . $_POST['NewStockID'] . "' WHERE stockid='" . $_POST['OldStockID'] . "'";
- $ErrMsg = _('The SQL to update the purchasing data records failed');
- $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
- echo ' ... ' . _('completed');
-
- echo '<br />' . _('Changing the stock code in shipment charges records');
- $sql = "UPDATE shipmentcharges SET stockid='" . $_POST['NewStockID'] . "' WHERE stockid='" . $_POST['OldStockID'] . "'";
- $ErrMsg = _('The SQL to update Shipment Charges records failed');
- $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
- echo ' ... ' . _('completed');
-
- echo '<br />' . _('Changing the stock check freeze file records');
- $sql = "UPDATE stockcheckfreeze SET stockid='" . $_POST['NewStockID'] . "' WHERE stockid='" . $_POST['OldStockID'] . "'";
- $ErrMsg = _('The SQL to update stock check freeze records failed');
- $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
- echo ' ... ' . _('completed');
-
- echo '<br />' . _('Changing the stock counts table records');
- $sql = "UPDATE stockcounts SET stockid='" . $_POST['NewStockID'] . "' WHERE stockid='" . $_POST['OldStockID'] . "'";
- $ErrMsg = _('The SQL to update stock counts records failed');
- $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
- echo ' ... ' . _('completed');
-
-
- echo '<br />' . _('Changing the GRNs table records');
- $sql = "UPDATE grns SET itemcode='" . $_POST['NewStockID'] . "' WHERE itemcode='" . $_POST['OldStockID'] . "'";
- $ErrMsg = _('The SQL to update GRN records failed');
- $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
- echo ' ... ' . _('completed');
-
-
- echo '<br />' . _('Changing the contract BOM table records');
- $sql = "UPDATE contractbom SET stockid='" . $_POST['NewStockID'] . "' WHERE stockid='" . $_POST['OldStockID'] . "'";
- $ErrMsg = _('The SQL to update the contract BOM records failed');
- $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
- echo ' ... ' . _('completed');
-
-
- echo '<br />' . _('Changing the BOM table records') . ' - ' . _('components');
- $sql = "UPDATE bom SET component='" . $_POST['NewStockID'] . "' WHERE component='" . $_POST['OldStockID'] . "'";
- $ErrMsg = _('The SQL to update the BOM records failed');
- $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
- echo ' ... ' . _('completed');
-
DB_IgnoreForeignKeys($db);
- echo '<br />' . _('Changing the BOM table records') . ' - ' . _('parents');
- $sql = "UPDATE bom SET parent='" . $_POST['NewStockID'] . "' WHERE parent='" . $_POST['OldStockID'] . "'";
- $ErrMsg = _('The SQL to update the BOM parent records failed');
- $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
- echo ' ... ' . _('completed');
+ ChangeFieldInTable("bom", "parent", $_POST['OldStockID'], $_POST['NewStockID'], $db);
echo '<br />' . _('Changing any image files');
if (file_exists($_SESSION['part_pics_dir'] . '/' .$_POST['OldStockID'].'.jpg')){
@@ -259,63 +154,16 @@
echo ' .... ' . _('no image to rename');
}
- echo '<br />' . _('Changing the item properties table records') . ' - ' . _('parents');
- $sql = "UPDATE stockitemproperties SET stockid='" . $_POST['NewStockID'] . "' WHERE stockid='" . $_POST['OldStockID'] . "'";
- $ErrMsg = _('The SQL to update the item properties records failed');
- $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
- echo ' ... ' . _('completed');
+ ChangeFieldInTable("stockitemproperties", "stockid", $_POST['OldStockID'], $_POST['NewStockID'], $db);
+ ChangeFieldInTable("worequirements", "stockid", $_POST['OldStockID'], $_POST['NewStockID'], $db);
+ ChangeFieldInTable("worequirements", "parentstockid", $_POST['OldStockID'], $_POST['NewStockID'], $db);
+ ChangeFieldInTable("woitems", "stockid", $_POST['OldStockID'], $_POST['NewStockID'], $db);
+ ChangeFieldInTable("salescatprod", "stockid", $_POST['OldStockID'], $_POST['NewStockID'], $db);
+ ChangeFieldInTable("stockserialitems", "stockid", $_POST['OldStockID'], $_POST['NewStockID'], $db);
+ ChangeFieldInTable("stockserialmoves", "stockid", $_POST['OldStockID'], $_POST['NewStockID'], $db);
+ ChangeFieldInTable("offers", "stockid", $_POST['OldStockID'], $_POST['NewStockID'], $db);
+ ChangeFieldInTable("tenderitems", "stockid", $_POST['OldStockID'], $_POST['NewStockID'], $db);
-
- echo '<br />' . _('Changing work order requirements information');
-
- $sql = "UPDATE worequirements SET stockid='" . $_POST['NewStockID'] . "' WHERE stockid='" . $_POST['OldStockID'] . "'";
- $ErrMsg = _('The SQL to update the stockid worequirements records failed');
- $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
- echo ' ... ' . _('completed');
-
- $sql = "UPDATE worequirements SET parentstockid='" . $_POST['NewStockID'] . "' WHERE parentstockid='" . $_POST['OldStockID'] . "'";
- $ErrMsg = _('The SQL to update the parent stockid worequirements records failed');
- $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
- echo ' ... ' . _('completed');
-
- echo '<br />' . _('Changing work order information');
-
- $sql = "UPDATE woitems SET stockid='" . $_POST['NewStockID'] . "' WHERE stockid='" . $_POST['OldStockID'] . "'";
- $ErrMsg = _('The SQL to update the woitem records failed');
- $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
- echo ' ... ' . _('completed');
-
- echo '<br />' . _('Changing sales category information');
- $sql = "UPDATE salescatprod SET stockid='" . $_POST['NewStockID'] . "' WHERE stockid='" . $_POST['OldStockID'] . "'";
- $ErrMsg = _('The SQL to update the sales category records failed');
- $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
- echo ' ... ' . _('completed');
-
-
- echo '<br />' . _('Changing any serialised item information');
-
-
- $sql = "UPDATE stockserialitems SET stockid='" . $_POST['NewStockID'] . "' WHERE stockid='" . $_POST['OldStockID'] . "'";
- $ErrMsg = _('The SQL to update the stockserialitem records failed');
- $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
- $sql = "UPDATE stockserialmoves SET stockid='" . $_POST['NewStockID'] . "' WHERE stockid='" . $_POST['OldStockID'] . "'";
- $ErrMsg = _('The SQL to update the stockserialitem records failed');
- $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
- echo ' ... ' . _('completed');
-
- echo '<br />' . _('Changing offers table');
- $sql = "UPDATE offers SET stockid='" . $_POST['NewStockID'] . "' WHERE stockid='" . $_POST['OldStockID'] . "'";
- $ErrMsg = _('The SQL to update the offer records failed');
- $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
- echo ' ... ' . _('completed');
-
-
- echo '<br />' . _('Changing tender items table');
- $sql = "UPDATE tenderitems SET stockid='" . $_POST['NewStockID'] . "' WHERE stockid='" . $_POST['OldStockID'] . "'";
- $ErrMsg = _('The SQL to update the tender records failed');
- $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
- echo ' ... ' . _('completed');
-
DB_ReinstateForeignKeys($db);
$result = DB_Txn_Commit($db);
@@ -326,10 +174,8 @@
$result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
echo ' ... ' . _('completed');
-
echo '<p>' . _('Stock Code') . ': ' . $_POST['OldStockID'] . ' ' . _('was successfully changed to') . ' : ' . $_POST['NewStockID'];
} //only do the stuff above if $InputError==0
-
}
echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '" method="post">';
@@ -353,4 +199,5 @@
</form>';
include('includes/footer.inc');
+
?>
\ No newline at end of file
Modified: trunk/includes/MiscFunctions.php
===================================================================
--- trunk/includes/MiscFunctions.php 2013-05-22 09:25:31 UTC (rev 5981)
+++ trunk/includes/MiscFunctions.php 2013-05-23 04:22:02 UTC (rev 5982)
@@ -438,4 +438,16 @@
return $ToList;
}
+function ChangeFieldInTable($TableName, $FieldName, $OldValue, $NewValue, $db){
+ /* Used in Z_ scripts to change one field across the table.
+ */
+ echo '<br />' . _('Changing') . ' ' . $TableName . ' ' . _('records');
+ $sql = "UPDATE " . $TableName . " SET " . $FieldName . " ='" . $NewValue . "' WHERE " . $FieldName . "='" . $OldValue . "'";
+ $DbgMsg = _('The SQL statement that failed was');
+ $ErrMsg = _('The SQL to update' . ' ' . $TableName . ' ' . _('records failed'));
+ $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true);
+ echo ' ... ' . _('completed');
+}
+
+
?>
|