forked from timschofield/webERP-Medical
/
Z_ChangeStockCategory.php
101 lines (93 loc) · 4.57 KB
/
Z_ChangeStockCategory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/* $Id$ */
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'] . '</p>';
}
echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '" method="post">';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
echo '<br /><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"><button type="submit" name="ProcessStockChange">' . _('Process') . '</button></div>';
echo '</form>';
include ('includes/footer.inc');
?>