forked from KwaMoja/KwaMoja
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathABCRankingGroups.php
More file actions
220 lines (202 loc) · 7.92 KB
/
ABCRankingGroups.php
File metadata and controls
220 lines (202 loc) · 7.92 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<?php
include ('includes/session.php');
$Title = _('Maintain ABC ranking groups');
include ('includes/header.php');
echo '<p class="page_title_text" >
<img src="', $RootPath, '/css/', $_SESSION['Theme'], '/images/maintenance.png" title="', $Title, '" alt="', $Title, '" />', ' ', $Title, '
</p>';
if (isset($_GET['Delete'])) {
$CheckSQL = "SELECT groupid FROM abcstock WHERE groupid='" . $_GET['SelectedGroupID'] . "'";
$CheckResult = DB_query($CheckSQL);
if (DB_num_rows($CheckResult) == 0) {
$SQL = "DELETE FROM abcgroups WHERE groupid='" . $_GET['SelectedGroupID'] . "'";
$Result = DB_query($SQL);
prnMsg(_('ABC Ranking group number') . ' ' . $_GET['SelectedGroupID'] . ' ' . _('has been deleted'), 'success');
echo '<div class="centre">
<a href="', htmlspecialchars(basename(__FILE__), ENT_QUOTES, 'UTF-8'), '">', _('View all the ranking groups'), '</a>
</div>';
include ('includes/footer.php');
exit;
} else {
prnMsg(_('ABC Ranking group number') . ' ' . $_GET['SelectedMethodID'] . ' ' . _('cannot be deleted as it already has been run'), 'error');
}
}
if (isset($_POST['Submit'])) {
$InputError = 0;
if ($_POST['GroupID'] == '') {
$InputError++;
prnMsg(_('The group id field cannot be left empty'), 'error');
}
if (!filter_var($_POST['GroupID'], FILTER_VALIDATE_INT)) {
$InputError++;
prnMsg(_('The group id field must be numeric'), 'error');
}
if ($_POST['GroupName'] == '') {
$InputError++;
prnMsg(_('The group name field cannot be left empty'), 'error');
}
if (mb_strlen($_POST['GroupName']) > 40) {
$_POST['GroupName'] = substr($_POST['GroupName'], 0, 40);
prnMsg(_('The group name cannot be more than 40 characters long, it has been shortened to') . ' ' . $_POST['GroupName'], 'info');
}
if ($_POST['MethodID'] == '') {
$InputError++;
prnMsg(_('You must select a ranking method.'), 'error');
}
if (!filter_var($_POST['APercent'], FILTER_VALIDATE_INT)) {
$InputError++;
prnMsg(_('The A percentage field must be numeric'), 'error');
}
if (!filter_var($_POST['BPercent'], FILTER_VALIDATE_INT)) {
$InputError++;
prnMsg(_('The B percentage field must be numeric'), 'error');
}
if (!filter_var($_POST['CPercent'], FILTER_VALIDATE_INT)) {
$InputError++;
prnMsg(_('The C percentage field must be numeric'), 'error');
}
if (($_POST['APercent'] + $_POST['BPercent'] + $_POST['CPercent']) != 100) {
$InputError++;
prnMsg(_('The percentage fields must add up to 100'), 'error');
}
if (!filter_var($_POST['Months'], FILTER_VALIDATE_INT)) {
$InputError++;
prnMsg(_('The number of months field must be numeric'), 'error');
}
if ($InputError == 0) {
$SQL = "INSERT INTO abcgroups ( groupid,
groupname,
methodid,
apercentage,
bpercentage,
cpercentage,
zerousage,
months
) VALUES (
'" . $_POST['GroupID'] . "',
'" . $_POST['GroupName'] . "',
'" . $_POST['MethodID'] . "',
'" . $_POST['APercent'] . "',
'" . $_POST['BPercent'] . "',
'" . $_POST['CPercent'] . "',
'" . $_POST['ZeroUsage'] . "',
'" . $_POST['Months'] . "'
)";
$InputResult = DB_query($SQL);
prnMsg(_('The ranking group has been successfully saved to the database'), 'success');
echo '<div class="centre">
<a href="', htmlspecialchars(basename(__FILE__), ENT_QUOTES, 'UTF-8'), '">', _('View all the ranking groups'), '</a>
</div>';
include ('includes/footer.php');
exit;
}
} else {
$SQL = "SELECT groupid,
groupname,
methodname,
apercentage,
bpercentage,
cpercentage,
zerousage,
months
FROM abcgroups
INNER JOIN abcmethods
ON abcgroups.methodid=abcmethods.methodid";
$Result = DB_query($SQL);
echo '<table summary="', _('List of ABC Ranking Methods'), '">
<tr>
<th colspan="10">
<h3>', _('List of ABC Ranking Groups'), '
<img src="', $RootPath, '/css/', $_SESSION['Theme'], '/images/printer.png" class="PrintIcon" title="', _('Print'), '" alt="', _('Print'), '" onclick="window.print();" />
</h3>
</th>
</tr>
<tr>
<th>', _('ID'), '</th>
<th>', _('Group Name'), '</th>
<th>', _('Method name'), '</th>
<th>', _('% in A category'), '</th>
<th>', _('% in B category'), '</th>
<th>', _('% in C category'), '</th>
<th>', _('If Zero Usage'), '</th>
<th>', _('Months in calculation'), '</th>
<th></th>
</tr>';
while ($MyRow = DB_fetch_array($Result)) {
echo '<tr class="striped_row">
<td>', $MyRow['groupid'], '</td>
<td>', $MyRow['groupname'], '</td>
<td>', $MyRow['methodname'], '</td>
<td>', $MyRow['apercentage'], '</td>
<td>', $MyRow['bpercentage'], '</td>
<td>', $MyRow['cpercentage'], '</td>
<td>', $MyRow['zerousage'], '</td>
<td>', $MyRow['months'], '</td>
<td><a href="', htmlspecialchars(basename(__FILE__), ENT_QUOTES, 'UTF-8'), '?SelectedGroupID=', urlencode($MyRow['groupid']), '&Delete=1" onclick="return MakeConfirm(\'' . _('Are you sure you wish to delete this ranking group?') . '\', \'Confirm Delete\', this);">', _('Delete'), '</a></td>
</tr>';
}
echo '</table>';
echo '<form action="', htmlspecialchars(basename(__FILE__), ENT_QUOTES, 'UTF-8'), '" method="post" id="ABCMethods">';
echo '<input type="hidden" name="FormID" value="', $_SESSION['FormID'], '" />';
echo '<fieldset>
<legend>', _('Ranking Group Details'), '</legend>
<field>
<label for="GroupID">', _('Group ID'), '</label>
<input type="text" autofocus="autofocus" size="3" required="required" class="number" name="GroupID" />
<fieldhelp>', _('The ID of the group being created.'), '</fieldhelp>
</field>
<field>
<label for="GroupName">', _('Group Description'), '</label>
<input type="text" size="30" maxlength="40" name="GroupName" value="" />
<fieldhelp>', _('The name by which this group will be known.'), '</fieldhelp>
</field>';
$SQL = "SELECT methodid,
methodname
FROM abcmethods";
$Result = DB_query($SQL);
echo '<field>
<label for="MethodID">', _('Ranking method'), '</label>
<select required="required" name="MethodID">
<option value=""></option>';
while ($MyRow = DB_fetch_array($Result)) {
echo '<option value="', $MyRow['methodid'], '">', $MyRow['methodname'], '</option>';
}
echo '</select>
<fieldhelp>', _('Select the method used to calculate the group this stock item belongs to.'), '</fieldhelp>
</field>';
echo '<field>
<label for="APercent">', _('Percentage in A Category'), '</label>
<input required="required" type="text" size="3" class="number" name="APercent" value="10" />
<fieldhelp>', _('The percentage of items to place in the A category.'), '</fieldhelp>
</field>
<field>
<label for="BPercent">', _('Percentage in B Category'), '</label>
<input required="required" type="text" size="3" class="number" name="BPercent" value="30" />
<fieldhelp>', _('The percentage of items to place in the B category.'), '</fieldhelp>
</field>
<field>
<label for="CPercent">', _('Percentage in C Category'), '</label>
<input required="required" type="text" size="3" class="number" name="CPercent" value="60" />
<fieldhelp>', _('The percentage of items to place in the C category.'), '</fieldhelp>
</field>
<field>
<label for="ZeroUsage">', _('If zero movement in period put items in'), '</label>
<select name="ZeroUsage">
<option value="C">C</option>
<option value="D">D</option>
</select>
<fieldhelp>', _('Select the category to place items that have zero movement in the included period.'), '</fieldhelp>
</field>
<field>
<label for="Months">', _('Months of Movement to include'), '</label>
<input required="required" type="text" size="3" class="number" name="Months" value="12" />
<fieldhelp>', _('The number of months stock movement to analyse.'), '</fieldhelp>
</field>';
echo '</fieldset>';
echo '<div class="centre">
<input type="submit" name="Submit" value="', _('Save'), '" />
</div>';
echo '</form>';
}
include ('includes/footer.php');
?>