forked from webERP-team/webERP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZ_ChangeSupplierCode.php
121 lines (104 loc) · 4.39 KB
/
Z_ChangeSupplierCode.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
/* This script is an utility to change a supplier code. */
include ('includes/session.php');
$Title = _('UTILITY PAGE To Changes A Supplier Code In All Tables');// Screen identificator.
$ViewTopic = 'SpecialUtilities'; // Filename's id in ManualContents.php's TOC.
$BookMark = 'Z_ChangeSupplierCode'; // Anchor's id in the manual's html document
include('includes/header.php');
echo '<p class="page_title_text"><img alt="" src="'.$RootPath.'/css/'.$Theme.
'/images/supplier.png" title="' .
_('Change A Supplier Code') . '" /> ' .// Icon title.
_('Change A Supplier Code') . '</p>';// Page title.
if (isset($_POST['ProcessSupplierChange']))
ProcessSupplier($_POST['OldSupplierNo'], $_POST['NewSupplierNo']);
echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '" method="post">';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
echo '
<div class="centre">
<table>
<tr><td>' . _('Existing Supplier Code') . ':</td>
<td><input type="text" name="OldSupplierNo" size="20" maxlength="20" /></td>
</tr>
<tr><td> ' . _('New Supplier Code') . ':</td>
<td><input type="text" name="NewSupplierNo" size="20" maxlength="20" /></td>
</tr>
</table>
<button type="submit" name="ProcessSupplierChange">' . _('Process') . '</button>
<div>
</form>';
include('includes/footer.php');
exit();
function ProcessSupplier($oldCode, $newCode) {
$table_key= array (
'grns' => 'supplierid',
'offers'=>'supplierid',
'purchdata'=>'supplierno',
'purchorders'=>'supplierno',
'shipments'=>'supplierid',
'suppliercontacts'=>'supplierid',
'supptrans'=>'supplierno',
'www_users'=>'supplierid');
// First check the Supplier code exists
if (!checkSupplierExist($oldCode)) {
prnMsg ('<br /><br />' . _('The Supplier code') . ': ' . $oldCode . ' ' .
_('does not currently exist as a supplier code in the system'),'error');
return;
}
$newCode = trim($newCode);
if (checkNewCode($newCode)) {
// Now check that the new code doesn't already exist
if (checkSupplierExist($newCode)) {
prnMsg(_('The replacement supplier code') .': ' .
$newCode . ' ' . _('already exists as a supplier code in the system') . ' - ' . _('a unique supplier code must be entered for the new code'),'error');
return;
}
} else {
return;
}
$result = DB_Txn_Begin();
prnMsg(_('Inserting the new supplier record'),'info');
$sql = "INSERT INTO suppliers (`supplierid`,
`suppname`, `address1`, `address2`, `address3`,
`address4`, `address5`, `address6`, `supptype`, `lat`, `lng`,
`currcode`, `suppliersince`, `paymentterms`, `lastpaid`,
`lastpaiddate`, `bankact`, `bankref`, `bankpartics`,
`remittance`, `taxgroupid`, `factorcompanyid`, `taxref`,
`phn`, `port`, `email`, `fax`, `telephone`)
SELECT '" . $newCode . "',
`suppname`, `address1`, `address2`, `address3`,
`address4`, `address5`, `address6`, `supptype`, `lat`, `lng`,
`currcode`, `suppliersince`, `paymentterms`, `lastpaid`,
`lastpaiddate`, `bankact`, `bankref`, `bankpartics`,
`remittance`, `taxgroupid`, `factorcompanyid`, `taxref`,
`phn`, `port`, `email`, `fax`, `telephone`
FROM suppliers WHERE supplierid='" . $oldCode . "'";
$DbgMsg =_('The SQL that failed was');
$ErrMsg = _('The SQL to insert the new suppliers master record failed') . ', ' . _('the SQL statement was');
$result = DB_query($sql,$ErrMsg,$DbgMsg,true);
foreach ($table_key as $table=>$key) {
prnMsg(_('Changing').' '. $table.' ' . _('records'),'info');
$sql = "UPDATE " . $table . " SET $key='" . $newCode . "' WHERE $key='" . $oldCode . "'";
$ErrMsg = _('The SQL to update') . ' ' . $table . ' ' . _('records failed');
$result = DB_query($sql,$ErrMsg,$DbgMsg,true);
}
prnMsg(_('Deleting the supplier code from the suppliers master table'),'info');
$sql = "DELETE FROM suppliers WHERE supplierid='" . $oldCode . "'";
$ErrMsg = _('The SQL to delete the old supplier record failed');
$result = DB_query($sql,$ErrMsg,$DbgMsg,true);
$result = DB_Txn_Commit();
}
function checkSupplierExist($codeSupplier) {
$result=DB_query("SELECT supplierid FROM suppliers WHERE supplierid='" . $codeSupplier . "'");
if (DB_num_rows($result)==0) return false;
return true;
}
function checkNewCode($code) {
$tmp = str_replace(' ','',$code);
if ($tmp != $code) {
prnMsg ('<br /><br />' . _('The New supplier code') . ': ' . $code . ' ' .
_('must be not empty nor with spaces'),'error');
return false;
}
return true;
}
?>