forked from KwaMoja/KwaMoja
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathDefineWarehouse.php
520 lines (481 loc) · 17.3 KB
/
DefineWarehouse.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
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
<?php
include ('includes/session.php');
if (!isset($_POST['Parent'])) {
$_POST['Parent'] = '';
}
if (isset($_GET['Location'])) {
/* If the location code is sent as part of the
* $_GET array
*/
$LocationCode = $_GET['Location'];
} else if (isset($_POST['Location'])) {
/* If the location code is sent as part of the
* $_POST array
*/
$LocationCode = $_POST['Location'];
} else {
/* If no stock location has been chosen then
* show a selection form for the user to choose one
*/
$Title = _('Select Warehouse to Define');
include ('includes/header.php');
echo '<p class="page_title_text">
<img src="', $RootPath, '/css/', $_SESSION['Theme'], '/images/supplier.png" title="', _('Warehouse'), '" alt="" />', $Title, '
</p>';
echo '<form method="post" action="', htmlspecialchars(basename(__FILE__), ENT_QUOTES, 'UTF-8'), '">';
echo '<input type="hidden" name="FormID" value="', $_SESSION['FormID'], '" />';
$SQL = "SELECT loccode,
locationname
FROM locations";
$Result = DB_query($SQL);
echo '<fieldset>
<legend>', _('Select Warehouse to Define'), '</legend
<field>
<label for="Location">', _('Location of warehouse'), '</label>
<select name="Location" autofocus="autofocus">';
while ($MyRow = DB_fetch_array($Result)) {
echo '<option value="', $MyRow['loccode'], '">', $MyRow['locationname'], '</option>';
}
echo '</select>
<fieldhelp>', _('Select the location of the warehouse to be defined.'), '</fieldhelp>
</field>
</fieldset>';
echo '<div class="centre">
<input type="submit" name="Submit" value="Select" />
</div>';
echo '</form>';
include ('includes/footer.php');
exit;
}
if (isset($_POST['Insert']) or isset($_POST['Update'])) {
$Errors = 0;
if (mb_strlen($_POST['ID']) == 0) {
prnMsg(_('The container identifier code must contain at least one character'), 'error');
$Errors++;
}
if (mb_strlen($_POST['ID']) > 10) {
prnMsg(_('The container identifier code must be ten charcters or less'), 'error');
$Errors++;
}
if (mb_strlen($_POST['Description']) == 0) {
prnMsg(_('The container description must contain at least one character'), 'error');
$Errors++;
}
if (mb_strlen($_POST['ID']) > 10) {
prnMsg(_('The container description must be fifty charcters or less'), 'error');
$Errors++;
}
$LocationSQL = "SELECT loccode FROM locations WHERE loccode='" . $LocationCode . "'";
$LocationResult = DB_query($LocationSQL);
if (DB_num_rows($LocationResult) == 0) {
prnMsg(_('You have not chosen a valid location code'), 'error');
$Errors++;
}
$ParentSQL = "SELECT id FROM container WHERE id='" . $_POST['Parent'] . "'";
$ParentResult = DB_query($ParentSQL);
if (DB_num_rows($ParentResult) == 0 and $_POST['Parent'] != '') {
prnMsg(_('You have not chosen a valid parent container'), 'error');
$Errors++;
}
if (!is_numeric($_POST['X']) or !is_numeric($_POST['Y']) or !is_numeric($_POST['Z'])) {
prnMsg(_('The positional co-ordinates of the container must be numbers'), 'error');
$Errors++;
}
if (!is_numeric($_POST['Width']) or !is_numeric($_POST['Length']) or !is_numeric($_POST['Height'])) {
prnMsg(_('The dimensions of the container must be numbers'), 'error');
$Errors++;
}
if ($Errors == 0 and isset($_POST['Insert'])) {
$k = 0;
for ($i = 1;$i <= $_POST['NoWide'];$i++) {
for ($j = 1;$j <= $_POST['NoLong'];$j++) {
$InsertSQL = "INSERT INTO container (id,
name,
location,
parentid,
xcoord,
ycoord,
zcoord,
width,
length,
height,
sequence,
putaway,
picking,
replenishment,
quarantine
) VALUES (
'" . $_POST['ID'] . ($k) . "',
'" . $_POST['Description'] . $i . 'x' . $j . "',
'" . $LocationCode . "',
'" . $_POST['Parent'] . "',
'" . ($_POST['X'] + ($_POST['Width'] * $i)) . "',
'" . ($_POST['Y'] + ($_POST['Length'] * $j)) . "',
'" . $_POST['Z'] . "',
'" . $_POST['Width'] . "',
'" . $_POST['Length'] . "',
'" . $_POST['Height'] . "',
'" . ($_POST['Sequence'] + $k) . "',
'" . $_POST['Putaway'] . "',
'" . $_POST['Picking'] . "',
'" . $_POST['Replenishment'] . "',
'" . $_POST['Quarantine'] . "'
)";
$ErrMsg = _('An error occurred inserting the container detaails');
$DbgMsg = _('The SQL used to insert the container record was');
$Result = DB_query($InsertSQL, $ErrMsg, $DbgMsg);
if (DB_error_no() == 0) {
prnMsg(_('The container') . ' ' . $_POST['Description'] . $i . 'x' . $j . ' ' . _('has been successfully created in') . ' ' . $_POST['Parent'], 'success');
}
++$k;
}
}
}
if ($Errors == 0 and isset($_POST['Update'])) {
$UpdateSQL = "UPDATE container set name='" . $_POST['Description'] . "',
location='" . $LocationCode . "',
parentid='" . $_POST['Parent'] . "',
xcoord='" . $_POST['X'] . "',
ycoord='" . $_POST['Y'] . "',
zcoord='" . $_POST['Z'] . "',
width='" . $_POST['Width'] . "',
length='" . $_POST['Length'] . "',
height='" . $_POST['Height'] . "',
sequence='" . $_POST['Sequence'] . "',
putaway='" . $_POST['Putaway'] . "',
picking='" . $_POST['Picking'] . "',
replenishment='" . $_POST['Replenishment'] . "',
quarantine='" . $_POST['Quarantine'] . "'
WHERE id='" . $_POST['ID'] . "'";
$ErrMsg = _('An error occurred updating the container detaails');
$DbgMsg = _('The SQL used to update the container record was');
$Result = DB_query($UpdateSQL, $ErrMsg, $DbgMsg);
}
}
/* Get the location name */
$SQL = "SELECT locationname FROM locations WHERE loccode='" . $LocationCode . "'";
$Result = DB_query($SQL);
$LocationRow = DB_fetch_array($Result);
$Title = _('Define Warehouse at') . ' ' . $LocationRow['locationname'];
include ('includes/header.php');
echo '<p class="page_title_text">
<img src="', $RootPath, '/css/', $_SESSION['Theme'], '/images/supplier.png" title="', _('Inventory'), '" alt="" />', $Title, '
</p>';
if (!isset($_GET['Edit'])) {
function display_children($parent, $level, $LocationCode) {
// retrieve all children of $parent
$ContainerSQL = "SELECT id,
name,
parentid,
sequence,
putaway,
picking,
replenishment,
quarantine,
xcoord,
ycoord,
zcoord,
width,
length,
height
FROM container
WHERE location='" . $LocationCode . "'
AND parentid='" . $parent . "'
ORDER BY parentid, sequence";
$ContainerResult = DB_query($ContainerSQL);
// display each child
while ($ContainerRow = DB_fetch_array($ContainerResult)) {
// indent and display the title of this child
if ($ContainerRow['putaway'] == 1) {
$ContainerRow['putaway'] = _('Yes');
} else {
$ContainerRow['putaway'] = _('No');
}
if ($ContainerRow['picking'] == 1) {
$ContainerRow['picking'] = _('Yes');
} else {
$ContainerRow['picking'] = _('No');
}
if ($ContainerRow['replenishment'] == 1) {
$ContainerRow['replenishment'] = _('Yes');
} else {
$ContainerRow['replenishment'] = _('No');
}
if ($ContainerRow['quarantine'] == 1) {
$ContainerRow['quarantine'] = _('Yes');
} else {
$ContainerRow['quarantine'] = _('No');
}
$ChildrenSQL = "SELECT COUNT(id) as children
FROM container
WHERE parentid='" . $ContainerRow['id'] . "'";
$ChildrenResult = DB_query($ChildrenSQL);
$ChildrenRow = DB_fetch_array($ChildrenResult);
$NumberOfChildren = $ChildrenRow['children'];
if ($NumberOfChildren > 0) {
$Style = ' onClick="expandTable(this)" style="cursor:pointer" ';
} else {
$Style = '';
}
if ($ContainerRow['parentid'] == '') {
echo '<tr class="visible striped_row" ', $Style, ' data-title="Click here to view the sub-containers"><td style="display:none">', $ContainerRow['id'], '</td>';
} else {
echo '<tr class="invisible" ', $Style, '><td style="display:none">', $ContainerRow['id'], '</td>';
}
echo '<td>', str_repeat(' ', $level), $ContainerRow['id'], '</td>
<td>', $ContainerRow['name'], '</td>
<td>', $ContainerRow['parentid'], '</td>
<td class="number">', $ContainerRow['sequence'], '</td>
<td>', $ContainerRow['putaway'], '</td>
<td>', $ContainerRow['picking'], '</td>
<td>', $ContainerRow['replenishment'], '</td>
<td>', $ContainerRow['quarantine'], '</td>
<td class="number">', $ContainerRow['xcoord'], '</td>
<td class="number">', $ContainerRow['ycoord'], '</td>
<td class="number">', $ContainerRow['zcoord'], '</td>
<td class="number">', $ContainerRow['width'], '</td>
<td class="number">', $ContainerRow['length'], '</td>
<td class="number">', $ContainerRow['height'], '</td>
<td><a onclick="return true" href="', htmlspecialchars(basename(__FILE__), ENT_QUOTES, 'UTF-8'), '?Edit=', $ContainerRow['id'], '&Location=', $LocationCode, '">', _('Edit'), '</a></td>
</tr>';
// call this function again to display this
// child's children
display_children($ContainerRow['id'], $level + 1, $LocationCode);
}
}
echo '<table id="Containers">
<tr>
<th rowspan="2">', _('Container'), '</th>
<th rowspan="2">', _('Container Name'), '</th>
<th rowspan="2">', _('Parent'), '</th>
<th rowspan="2">', _('Sequence'), '</th>
<th rowspan="2">', _('Allow Putaway'), '</th>
<th rowspan="2">', _('Allow Picking'), '</th>
<th rowspan="2">', _('Allow Replenishment'), '</th>
<th rowspan="2">', _('Quarantine Area'), '</th>
<th colspan="3">', _('Position'), '</th>
<th colspan="3">', _('Dimensions'), '</th>
</tr>
<tr>
<th>X</th>
<th>Y</th>
<th>Z</th>
<th>', _('Width'), '</th>
<th>', _('Length'), '</th>
<th>', _('Height'), '</th>
</tr>';
display_children('', 0, $LocationCode);
echo '</table>';
}
if (isset($_GET['Edit'])) {
$SQL = "SELECT id,
name,
parentid,
xcoord,
ycoord,
zcoord,
width,
length,
height,
sequence,
putaway,
picking,
replenishment,
quarantine
FROM container
WHERE id='" . $_GET['Edit'] . "'";
$Result = DB_query($SQL);
}
if (DB_num_rows($Result) != 0) {
$MyRow = DB_fetch_array($Result);
$_POST['ID'] = $MyRow['id'];
$_POST['Description'] = $MyRow['name'];
$_POST['Parent'] = $MyRow['parentid'];
$_POST['X'] = $MyRow['xcoord'];
$_POST['Y'] = $MyRow['ycoord'];
$_POST['Z'] = $MyRow['zcoord'];
$_POST['Width'] = $MyRow['width'];
$_POST['Length'] = $MyRow['length'];
$_POST['Height'] = $MyRow['height'];
$_POST['Sequence'] = $MyRow['sequence'];
$_POST['Putaway'] = $MyRow['putaway'];
$_POST['Picking'] = $MyRow['picking'];
$_POST['Replenishment'] = $MyRow['replenishment'];
$_POST['Quarantine'] = $MyRow['quarantine'];
} else {
$_POST['ID'] = '';
$_POST['Description'] = '';
$_POST['Parent'] = '';
$_POST['X'] = 0;
$_POST['Y'] = 0;
$_POST['Z'] = 0;
$_POST['Width'] = 0;
$_POST['Length'] = 0;
$_POST['Height'] = 0;
$_POST['Sequence'] = 0;
$_POST['Putaway'] = 1;
$_POST['Picking'] = 1;
$_POST['Replenishment'] = 1;
$_POST['Quarantine'] = 0;
}
echo '<form method="post" action="', htmlspecialchars(basename(__FILE__), ENT_QUOTES, 'UTF-8'), '">';
echo '<input type="hidden" name="FormID" value="', $_SESSION['FormID'], '" />';
echo '<input type="hidden" name="Location" value="', $LocationCode, '" />';
if (isset($_GET['Edit'])) {
echo '<fieldset>
<legend>', _('Edit container details'), '</legend>
<field>
<label for="ID">', _('Container ID'), '</label>
<div class="fieldtext">', $_POST['ID'], '</div>
</field>';
echo '<input type="hidden" name="ID" value="', $_POST['ID'], '" />';
} else {
echo '<fieldset>
<legend>', _('Create container details'), '</legend>
<field>
<label for="ID">', _('Container ID'), '</label>
<input type="text" autofocus="autofocus" size="5" maxlength="6" name="ID" value="', $_POST['ID'], '" />
<fieldhelp>', _('Enter an Id by which this container will be referred to. The ID can have up to 6 characters.'), '</fieldhelp>
</field>';
}
echo '<field>
<label for="Description">', _('Description'), '</label>
<input type="text" size="25" name="Description" value="', $_POST['Description'], '" />
<fieldhelp>', _('Enter a description of this container. The description can have up to 50 characters.'), '</fieldhelp>
</field>';
echo '<field>
<label for="Parent">', _('Parent Container'), '</label>
<select name="Parent">';
$ParentSQL = "SELECT id,
name
FROM container
WHERE location='" . $LocationCode . "'";
$ParentResult = DB_query($ParentSQL);
echo '<option value="">', _('None'), '</option>';
while ($ParentRow = DB_fetch_array($ParentResult)) {
if ($_POST['Parent'] == $ParentRow['id']) {
echo '<option selected="selected" value="', $ParentRow['id'], '">', $ParentRow['name'], '</option>';
} else {
echo '<option value="', $ParentRow['id'], '">', $ParentRow['name'], '</option>';
}
}
echo '</select>
<fieldhelp>', _('Select the parent container (if any) that this container belongs to.'), '</fieldhelp>
</field>';
echo '<field>
<label for="Sequence">', _('Sequence'), '</label>
<input type="text" size="5" class="number" name="Sequence" value="', $_POST['Sequence'], '" />
<fieldhelp>', _('Enter the sequence number for this container.'), '</fieldhelp>
</field>';
if ($_POST['Putaway'] == 0) {
$Selected = 'selected="selected"';
} else {
$Selected = '';
}
echo '<field>
<label for="Putaway">', _('Allow Putaway'), '</label>
<select name="Putaway">
<option value="1">', _('Yes'), '</option>
<option ', $Selected, ' value="0">', _('No'), '</option>
</select>
<fieldhelp>', _('Select Yes if this container can be used for directed put aways. Otherwise select No'), '</fieldhelp>
</field>';
if ($_POST['Picking'] == 0) {
$Selected = 'selected="selected"';
} else {
$Selected = '';
}
echo '<field>
<label for="Picking">', _('Allow Picking'), '</label>
<select name="Picking">
<option value="1">', _('Yes'), '</option>
<option ', $Selected, ' value="0">', _('No'), '</option>
</select>
<fieldhelp>', _('Select Yes if this container can be used for directed picking. Otherwise select No'), '</fieldhelp>
</field>';
if ($_POST['Replenishment'] == 0) {
$Selected = 'selected="selected"';
} else {
$Selected = '';
}
echo '<field>
<label for="Replenishment">', _('Allow Replenishment'), '</label>
<select name="Replenishment">
<option value="1">', _('Yes'), '</option>
<option ', $Selected, ' value="0">', _('No'), '</option>
</select>
<fieldhelp>', _('Select Yes if this container can be replenished. Otherwise select No'), '</fieldhelp>
</field>';
if ($_POST['Quarantine'] == 0) {
$Selected = 'selected="selected"';
} else {
$Selected = '';
}
echo '<field>
<label for="">', _('Quarantine Area'), '</label>
<select name="Quarantine">
<option value="1">', _('Yes'), '</option>
<option ', $Selected, ' value="0">', _('No'), '</option>
</select>
<fieldhelp>', _('Select Yes if this container is designated as a quarantine rea. Otherwise select No'), '</fieldhelp>
</field>';
echo '<fieldset>
<legend>', _('Position in Parent Container') . ':</legend>
<field>
<label for="X">x : ', '</label>
<input type="text" size="5" class="number" name="X" value="', $_POST['X'], '" />
<fieldhelp>', _('The x co-ordinate of the location within the parent container'), '</fieldhelp>
</field>
<field>
<label for="Y">y : ' . '</label>
<input type="text" size="5" class="number" name="Y" value="', $_POST['Y'], '" />
<fieldhelp>', _('The y co-ordinate of the location within the parent container'), '</fieldhelp>
</field>
<field>
<label for="Z">z : ' . '</label>
<input type="text" size="5" class="number" name="Z" value="', $_POST['Z'], '" />
<fieldhelp>', _('The z co-ordinate of the location within the parent container'), '</fieldhelp>
</field>
</fieldset><br />';
echo '<fieldset>
<legend>', _('Size of Container'), ': </legend>
<field>
<label for="Width">', _('width'), ':</label>
<input type="text" size="5" class="number" name="Width" value="', $_POST['Width'], '" />
<fieldhelp>', _('The width of this container.'), '</fieldhelp>
</field>
<field>
<label for="Length">', _('length'), ':</label>
<input type="text" size="5" class="number" name="Length" value="', $_POST['Length'], '" />
<fieldhelp>', _('The length of this container.'), '</fieldhelp>
</field>
<field>
<label for="Height">', _('height'), ':</label>
<input type="text" size="5" class="number" name="Height" value="', $_POST['Height'], '" />
<fieldhelp>', _('The height of this container.'), '</fieldhelp>
</field>
</fieldset><br />';
if (!isset($_GET['Edit'])) {
if (!isset($_POST['NoWide'])) {
$_POST['NoWide'] = 1;
$_POST['NoLong'] = 1;
}
echo '<field>
<label>', _('Create a Block of Containers'), ':</label>
<input type="text" size="5" class="number" name="NoWide" value="' . $_POST['NoWide'] . '" /> X
<input type="text" size="5" class="number" name="NoLong" value="' . $_POST['NoLong'] . '" />
</field>';
}
echo '</fieldset>';
if (!isset($_GET['Edit'])) {
echo '<div class="centre">
<input type="submit" name="Insert" value="' . _('Define Container') . '" />
</div>';
} else {
echo '<div class="centre">
<input type="submit" name="Update" value="' . _('Update Container Definition') . '" />
</div>';
}
echo '</form>';
include ('includes/footer.php');
?>