[go: up one dir, main page]

Menu

[95b4ce]: / Stocks.php  Maximize  Restore  History

Download this file

1592 lines (1430 with data), 66.1 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
 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
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
<?php
include('includes/session.inc');
$Title = _('Item Maintenance');
/* Manual links before header.inc */
$ViewTopic = 'Inventory';
$BookMark = 'InventoryAddingItems';
include('includes/header.inc');
include('includes/SQL_CommonFunctions.inc');
/*If this form is called with the StockID then it is assumed that the stock item is to be modified */
if (isset($_GET['StockID'])) {
$StockId = trim(mb_strtoupper($_GET['StockID']));
} elseif (isset($_POST['StockID'])) {
$StockId = trim(mb_strtoupper($_POST['StockID']));
} else {
$StockId = '';
}
$ItemDescriptionLanguagesArray = explode(',',$_SESSION['ItemDescriptionLanguages']);//WARNING: if the last character is a ",", there are n+1 languages.
if (isset($_POST['NextItem_x'])) {
$Result = DB_query("SELECT stockid FROM stockmaster WHERE stockid>'" . $StockId . "' ORDER BY stockid ASC LIMIT 1");
$NextItemRow = DB_fetch_row($Result);
$StockId = $NextItemRow[0];
foreach ($ItemDescriptionLanguagesArray as $LanguageId) {
unset($_POST['Description_' . str_replace('.', '_', $LanguageId)]);
}
}
if (isset($_POST['PreviousItem_x'])) {
$Result = DB_query("SELECT stockid FROM stockmaster WHERE stockid<'" . $StockId . "' ORDER BY stockid DESC LIMIT 1");
$PreviousItemRow = DB_fetch_row($Result);
$StockId = $PreviousItemRow[0];
foreach ($ItemDescriptionLanguagesArray as $LanguageId) {
unset($_POST['Description_' . str_replace('.', '_', $LanguageId)]);
}
}
if (isset($StockId) and !isset($_POST['UpdateCategories'])) {
$SQL = "SELECT COUNT(stockid)
FROM stockmaster
WHERE stockid='" . $StockId . "'
GROUP BY stockid";
$Result = DB_query($SQL);
$MyRow = DB_fetch_row($Result);
if ($MyRow[0] == 0) {
$New = 1;
} else {
$New = 0;
}
}
if (isset($_POST['New'])) {
$New = $_POST['New'];
}
echo '<div class="toplink">
<a href="' . $RootPath . '/SelectProduct.php">' . _('Back to Items') . '</a>
</div>
<p class="page_title_text" >
<img src="' . $RootPath . '/css/' . $_SESSION['Theme'] . '/images/inventory.png" title="' . _('Stock') . '" alt="" />' . ' ' . $Title . '
</p>';
$SupportedImgExt = array('png', 'jpg', 'jpeg');
if (isset($_FILES['ItemPicture']) and $_FILES['ItemPicture']['name'] != '') {
$ImgExt = pathinfo($_FILES['ItemPicture']['name'], PATHINFO_EXTENSION);
$Result = $_FILES['ItemPicture']['error'];
$UploadTheFile = 'Yes'; //Assume all is well to start off with
$FileName = $_SESSION['part_pics_dir'] . '/' . $StockID . '.' . $ImgExt;
//But check for the worst
if (!in_array ($ImgExt, $SupportedImgExt)) {
prnMsg(_('Only ' . implode(", ", $SupportedImgExt) . ' files are supported - a file extension of ' . implode(", ", $SupportedImgExt) . ' is expected'),'warn');
$UploadTheFile = 'No';
} elseif ($_FILES['ItemPicture']['size'] > ($_SESSION['MaxImageSize'] * 1024)) { //File Size Check
prnMsg(_('The file size is over the maximum allowed. The maximum size allowed in KB is') . ' ' . $_SESSION['MaxImageSize'], 'warn');
$UploadTheFile = 'No';
} elseif ($_FILES['ItemPicture']['type'] == 'text/plain') { //File Type Check
prnMsg(_('Only graphics files can be uploaded'), 'warn');
$UploadTheFile = 'No';
} elseif ($_FILES['ItemPicture']['error'] == 6 ) { //upload temp directory check
prnMsg( _('No tmp directory set. You must have a tmp directory set in your PHP for upload of files.'), 'warn');
$UploadTheFile ='No';
}
foreach ($SupportedImgExt as $ext) {
$File = $_SESSION['part_pics_dir'] . '/' . $StockID . '.' . $ext;
if (file_exists ($File) ) {
$Result = unlink($File);
if (!$Result){
prnMsg(_('The existing image could not be removed'), 'error');
$UploadTheFile ='No';
}
}
}
if ($UploadTheFile == 'Yes') {
$Result = move_uploaded_file($_FILES['ItemPicture']['tmp_name'], $FileName);
$Message = ($Result) ? _('File url') . '<a href="' . $FileName . '">' . $FileName . '</a>' : _('Something is wrong with uploading a file');
}
}
if (isset($Errors)) {
unset($Errors);
}
$Errors = array();
$InputError = 0;
if (isset($_POST['submit'])) {
//initialise no input errors assumed initially before we test
/* actions to take once the user has clicked the submit button
ie the page has called itself with some user input */
//first off validate inputs sensible
$i = 1;
if (!isset($_POST['Description']) or mb_strlen($_POST['Description']) > 50 or mb_strlen($_POST['Description']) == 0) {
$InputError = 1;
prnMsg(_('The stock item description must be entered and be fifty characters or less long') . '. ' . _('It cannot be a zero length string either') . ' - ' . _('a description is required'), 'error');
$Errors[$i] = 'Description';
$i++;
}
if (mb_strlen($_POST['LongDescription']) == 0) {
$InputError = 1;
prnMsg(_('The stock item description cannot be a zero length string') . ' - ' . _('a long description is required'), 'error');
$Errors[$i] = 'LongDescription';
$i++;
}
if (mb_strlen($StockId) == 0) {
$InputError = 1;
prnMsg(_('The Stock Item code cannot be empty'), 'error');
$Errors[$i] = 'StockID';
$i++;
}
if (ContainsIllegalCharacters($StockId) or mb_strpos($StockId, ' ')) {
$InputError = 1;
prnMsg(_('The stock item code cannot contain any of the following characters') . " - ' &amp; + \" \\ ." . _('or a space'), 'error');
$Errors[$i] = 'StockID';
$i++;
$StockId = '';
}
if (mb_strlen($_POST['Units']) > 20) {
$InputError = 1;
prnMsg(_('The unit of measure must be 20 characters or less long'), 'error');
$Errors[$i] = 'Units';
$i++;
}
if (mb_strlen($_POST['BarCode']) > 20) {
$InputError = 1;
prnMsg(_('The barcode must be 20 characters or less long'), 'error');
$Errors[$i] = 'BarCode';
$i++;
}
if (!is_numeric(filter_number_format($_POST['Volume']))) {
$InputError = 1;
prnMsg(_('The volume of the packaged item in cubic metres must be numeric'), 'error');
$Errors[$i] = 'Volume';
$i++;
}
if (filter_number_format($_POST['Volume']) < 0) {
$InputError = 1;
prnMsg(_('The volume of the packaged item must be a positive number'), 'error');
$Errors[$i] = 'Volume';
$i++;
}
if (!is_numeric(filter_number_format($_POST['GrossWeight']))) {
$InputError = 1;
prnMsg(_('The weight of the packaged item in KGs must be numeric'), 'error');
$Errors[$i] = 'KGS';
$i++;
}
if (filter_number_format($_POST['GrossWeight']) < 0) {
$InputError = 1;
prnMsg(_('The weight of the packaged item must be a positive number'), 'error');
$Errors[$i] = 'KGS';
$i++;
}
if (!is_numeric(filter_number_format($_POST['NetWeight']))) {
$InputError = 1;
prnMsg(_('The net weight of the item in Net Weight must be numeric'),'error');
$Errors[$i] = 'NetWeight';
$i++;
}
if (filter_number_format($_POST['NetWeight'])<0) {
$InputError = 1;
prnMsg(_('The net weight of the item must be a positive number'),'error');
$Errors[$i] = 'NetWeight';
$i++;
}
if (!is_numeric(filter_number_format($_POST['EOQ']))) {
$InputError = 1;
prnMsg(_('The economic order quantity must be numeric'), 'error');
$Errors[$i] = 'EOQ';
$i++;
}
if (filter_number_format($_POST['EOQ']) < 0) {
$InputError = 1;
prnMsg(_('The economic order quantity must be a positive number'), 'error');
$Errors[$i] = 'EOQ';
$i++;
}
if ($_POST['Controlled'] == 0 and $_POST['Serialised'] == 1) {
$InputError = 1;
prnMsg(_('The item can only be serialised if there is lot control enabled already') . '. ' . _('Batch control') . ' - ' . _('with any number of items in a lot/bundle/roll is enabled when controlled is enabled') . '. ' . _('Serialised control requires that only one item is in the batch') . '. ' . _('For serialised control') . ', ' . _('both controlled and serialised must be enabled'), 'error');
$Errors[$i] = 'Serialised';
$i++;
}
if ($_POST['NextSerialNo'] != 0 and $_POST['Serialised'] == 0) {
$InputError = 1;
prnMsg(_('The item can only have automatically generated serial numbers if it is a serialised item'), 'error');
$Errors[$i] = 'NextSerialNo';
$i++;
}
if ($_POST['NextSerialNo'] != 0 and $_POST['MBFlag'] != 'M') {
$InputError = 1;
prnMsg(_('The item can only have automatically generated serial numbers if it is a manufactured item'), 'error');
$Errors[$i] = 'NextSerialNo';
$i++;
}
if (($_POST['MBFlag'] == 'A' or $_POST['MBFlag'] == 'K' or $_POST['MBFlag'] == 'D' or $_POST['MBFlag'] == 'G') and $_POST['Controlled'] == 1) {
$InputError = 1;
prnMsg(_('Assembly/Kitset/Phantom/Service/Labour items cannot also be controlled items') . '. ' . _('Assemblies/Dummies/Phantom and Kitsets are not physical items and batch/serial control is therefore not appropriate'), 'error');
$Errors[$i] = 'Controlled';
$i++;
}
if (trim($_POST['CategoryID']) == '') {
$InputError = 1;
prnMsg(_('There are no inventory categories defined. All inventory items must belong to a valid inventory category,'), 'error');
$Errors[$i] = 'CategoryID';
$i++;
}
if (!is_numeric(filter_number_format($_POST['Pansize']))) {
$InputError = 1;
prnMsg(_('Pansize quantity must be numeric'), 'error');
$Errors[$i] = 'Pansize';
$i++;
}
if (!is_numeric(filter_number_format($_POST['ShrinkFactor']))) {
$InputError = 1;
prnMsg(_('Shrinkage factor quantity must be numeric'), 'error');
$Errors[$i] = 'ShrinkFactor';
$i++;
}
if ($InputError != 1) {
if ($_POST['Serialised'] == 1) {
/*Not appropriate to have several dp on serial items */
$_POST['DecimalPlaces'] = 0;
}
if ($New == 0) {
/*so its an existing one */
/*first check on the changes being made we must disallow:
- changes from manufactured or purchased to Service, Assembly or Kitset if there is stock - changes from manufactured, kitset or assembly where a BOM exists
*/
$SQL = "SELECT mbflag,
controlled,
serialised,
stockcosts.materialcost+stockcosts.labourcost+stockcosts.overheadcost AS itemcost,
stockcategory.stockact,
stockcategory.wipact,
description,
longdescription
FROM stockmaster
INNER JOIN stockcategory
ON stockmaster.categoryid=stockcategory.categoryid
LEFT JOIN stockcosts
ON stockmaster.stockid=stockcosts.stockid
AND succeeded=0
WHERE stockmaster.stockid = '" . $StockId . "'";
$MBFlagResult = DB_query($SQL);
$MyRow = DB_fetch_row($MBFlagResult);
$OldMBFlag = $MyRow[0];
$OldControlled = $MyRow[1];
$OldSerialised = $MyRow[2];
$UnitCost = $MyRow[3];
$OldStockAccount = $MyRow[4];
$OldWIPAccount = $MyRow[5];
$OldDescription = $MyRow[6];
$OldLongDescription = $MyRow[7];
$SQL = "SELECT SUM(locstock.quantity)
FROM locstock
WHERE stockid='" . $StockId . "'
GROUP BY stockid";
$Result = DB_query($SQL);
$StockQtyRow = DB_fetch_row($Result);
/*Now check the GL account of the new category to see if it is different to the old stock gl account */
$Result = DB_query("SELECT stockact,
wipact
FROM stockcategory
WHERE categoryid='" . $_POST['CategoryID'] . "'");
$NewStockActRow = DB_fetch_array($Result);
$NewStockAct = $NewStockActRow['stockact'];
$NewWIPAct = $NewStockActRow['wipact'];
if ($OldMBFlag != $_POST['MBFlag']) {
if (($OldMBFlag == 'M' or $OldMBFlag == 'B') and ($_POST['MBFlag'] == 'A' or $_POST['MBFlag'] == 'K' or $_POST['MBFlag'] == 'D' or $_POST['MBFlag'] == 'G')) {
/*then need to check that there is no stock holding first */
/* stock holding OK for phantom (ghost) items */
if ($StockQtyRow[0] != 0 and $OldMBFlag != 'G') {
$InputError = 1;
prnMsg(_('The make or buy flag cannot be changed from') . ' ' . $OldMBFlag . ' ' . _('to') . ' ' . $_POST['MBFlag'] . ' ' . _('where there is a quantity of stock on hand at any location') . '. ' . _('Currently there are') . ' ' . $StockQtyRow[0] . ' ' . _('on hand'), 'errror');
}
/* don't allow controlled/serialized */
if ($_POST['Controlled'] == 1) {
$InputError = 1;
prnMsg(_('The make or buy flag cannot be changed from') . ' ' . $OldMBFlag . ' ' . _('to') . ' ' . $_POST['MBFlag'] . ' ' . _('where the item is to be lot controlled') . '. ' . _('Kitset, phantom, dummy and assembly items cannot be lot controlled'), 'error');
}
}
/*now check that if the item is being changed to a kitset, there are no items on sales orders or purchase orders*/
if ($_POST['MBFlag'] == 'K') {
$SQL = "SELECT quantity-qtyinvoiced
FROM salesorderdetails
WHERE stkcode = '" . $StockId . "'
AND completed=0";
$Result = DB_query($SQL);
$ChkSalesOrds = DB_fetch_row($Result);
if ($ChkSalesOrds[0] != 0) {
$InputError = 1;
prnMsg(_('The make or buy flag cannot be changed to a kitset where there is a quantity outstanding to be delivered on sales orders') . '. ' . _('Currently there are') . ' ' . $ChkSalesOrds[0] . ' ' . _('outstanding'), 'error');
}
}
/*now check that if it is to be a kitset or assembly or dummy there is no quantity on purchase orders outstanding*/
if ($_POST['MBFlag'] == 'K' or $_POST['MBFlag'] == 'A' or $_POST['MBFlag'] == 'D') {
$SQL = "SELECT quantityord-quantityrecd
FROM purchorderdetails INNER JOIN purchorders
ON purchorders.orderno=purchorderdetails.orderno
WHERE itemcode = '" . $StockId . "'
AND purchorderdetails.completed=0
AND purchorders.status<>'Cancelled'
AND purchorders.status<>'Completed'
AND purchorders.status<>'Rejected'";
$Result = DB_query($SQL);
$ChkPurchOrds = DB_fetch_row($Result);
if ($ChkPurchOrds[0] != 0) {
$InputError = 1;
prnMsg(_('The make or buy flag cannot be changed to') . ' ' . $_POST['MBFlag'] . ' ' . _('where there is a quantity outstanding to be received on purchase orders') . '. ' . _('Currently there are') . ' ' . $ChkPurchOrds[0] . ' ' . _('yet to be received') . 'error');
}
}
/*now check that if it was a Manufactured, Kitset, Phantom or Assembly and is being changed to a purchased or dummy - that no BOM exists */
if (($OldMBFlag == 'M' or $OldMBFlag == 'K' or $OldMBFlag == 'A' or $OldMBFlag == 'G') and ($_POST['MBFlag'] == 'B' or $_POST['MBFlag'] == 'D')) {
$SQL = "SELECT COUNT(*)
FROM bom
WHERE parent = '" . $StockId . "'
GROUP BY parent";
$Result = DB_query($SQL);
$ChkBOM = DB_fetch_row($Result);
if ($ChkBOM[0] != 0) {
$InputError = 1;
prnMsg(_('The make or buy flag cannot be changed from manufactured, kitset or assembly to') . ' ' . $_POST['MBFlag'] . ' ' . _('where there is a bill of material set up for the item') . '. ' . _('Bills of material are not appropriate for purchased or dummy items'), 'error');
}
}
/*now check that if it was Manufac, Phantom or Purchased and is being changed to assembly or kitset, it is not a component on an existing BOM */
if (($OldMBFlag == 'M' or $OldMBFlag == 'B' or $OldMBFlag == 'D' or $OldMBFlag == 'G') and ($_POST['MBFlag'] == 'A' or $_POST['MBFlag'] == 'K')) {
$SQL = "SELECT COUNT(*)
FROM bom
WHERE component = '" . $StockId . "'
GROUP BY component";
$Result = DB_query($SQL);
$ChkBOM = DB_fetch_row($Result);
if ($ChkBOM[0] != 0) {
$InputError = 1;
prnMsg(_('The make or buy flag cannot be changed from manufactured, purchased or dummy to a kitset or assembly where the item is a component in a bill of material') . '. ' . _('Assembly and kitset items are not appropriate as components in a bill of materials'), 'error');
}
}
}
/* Do some checks for changes in the Serial & Controlled setups */
if ($OldControlled != $_POST['Controlled'] and $StockQtyRow[0] != 0) {
$InputError = 1;
prnMsg(_('You can not change a Non-Controlled Item to Controlled (or back from Controlled to non-controlled when there is currently stock on hand for the item'), 'error');
}
if ($OldSerialised != $_POST['Serialised'] and $StockQtyRow[0] != 0) {
$InputError = 1;
prnMsg(_('You can not change a Serialised Item to Non-Serialised (or vice-versa) when there is a quantity on hand for the item'), 'error');
}
/* Do some check for property input */
for ($i = 0; $i < $_POST['PropertyCounter']; $i++) {
if ($_POST['PropNumeric' . $i] == 1) {
if (filter_number_format($_POST['PropValue' . $i]) < $_POST['PropMin' . $i] or filter_number_format($_POST['PropValue' . $i]) > $_POST['PropMax' . $i]) {
$InputError = 1;
prnMsg(_('The property value should between') . ' ' . $_POST['PropMin' . $i] . ' ' . _('and') . $_POST['PropMax' . $i], 'error');
}
}
}
if ($InputError == 0) {
DB_Txn_Begin();
$SQL = "UPDATE stockmaster
SET longdescription='" . $_POST['LongDescription'] . "',
description='" . $_POST['Description'] . "',
discontinued='" . $_POST['Discontinued'] . "',
controlled='" . $_POST['Controlled'] . "',
serialised='" . $_POST['Serialised'] . "',
perishable='" . $_POST['Perishable'] . "',
categoryid='" . $_POST['CategoryID'] . "',
units='" . $_POST['Units'] . "',
mbflag='" . $_POST['MBFlag'] . "',
eoq='" . filter_number_format($_POST['EOQ']) . "',
volume='" . filter_number_format($_POST['Volume']) . "',
grossweight='" . filter_number_format($_POST['GrossWeight']) . "',
netweight='" . filter_number_format($_POST['NetWeight']) . "',
barcode='" . $_POST['BarCode'] . "',
discountcategory='" . $_POST['DiscountCategory'] . "',
taxcatid='" . $_POST['TaxCat'] . "',
decimalplaces='" . $_POST['DecimalPlaces'] . "',
shrinkfactor='" . filter_number_format($_POST['ShrinkFactor']) . "',
pansize='" . filter_number_format($_POST['Pansize']) . "',
nextserialno='" . $_POST['NextSerialNo'] . "'
WHERE stockid='" . $StockId . "'";
$ErrMsg = _('The stock item could not be updated because');
$DbgMsg = _('The SQL that was used to update the stock item and failed was');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
if (in_array($_SESSION['PageSecurityArray']['StockCostUpdate.php'], $_SESSION['AllowedPageSecurityTokens'])) {
/*We need to update the costs for the item */
$NewCost = $_POST['MaterialCost'] + $_POST['LabourCost'] + $_POST['OverheadCost'];
ItemCostUpdateGL($StockId, $NewCost);
$ErrMsg = _('The old cost details for the stock item could not be updated because');
$DbgMsg = _('The SQL that failed was');
$SQL = "UPDATE stockcosts SET succeeded=1 WHERE stockid='" . $StockId . "'";
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
$SQL = "INSERT INTO stockcosts VALUES('" . $StockId . "',
'" . filter_number_format($_POST['MaterialCost']) . "',
'" . filter_number_format($_POST['LabourCost']) . "',
'" . filter_number_format($_POST['OverheadCost']) . "',
CURRENT_TIMESTAMP,
0)";
$ErrMsg = _('The new cost details for the stock item could not be inserted because');
$DbgMsg = _('The SQL that failed was');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
$SQL = "UPDATE stockmaster SET lastcostupdate=CURRENT_DATE WHERE stockid='" . $StockId . "'";
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
UpdateCost($StockId); //Update any affected BOMs
/* End of cost updates */
}
$ErrMsg = _('Could not update the language description because');
$DbgMsg = _('The SQL that was used to update the language description and failed was');
if (count($ItemDescriptionLanguagesArray) > 0) {
foreach ($ItemDescriptionLanguagesArray as $LanguageId) {
if ($LanguageId != '') {
$Result = DB_query("DELETE FROM stockdescriptiontranslations WHERE stockid='" . $StockId . "' AND language_id='" . $LanguageId . "'", $ErrMsg, $DbgMsg, true);
$Result = DB_query("INSERT INTO stockdescriptiontranslations VALUES('" . $StockId . "','" . $LanguageId . "', '" . $_POST['Description_' . str_replace('.', '_', $LanguageId)] . "', '0')", $ErrMsg, $DbgMsg, true);
$Result = DB_query("DELETE FROM stocklongdescriptiontranslations WHERE stockid='" . $StockId . "' AND language_id='" . $LanguageId . "'", $ErrMsg, $DbgMsg, true);
$Result = DB_query("INSERT INTO stocklongdescriptiontranslations VALUES('" . $StockId . "','" . $LanguageId . "', '" . $_POST['LongDescription_' . str_replace('.', '_', $LanguageId)] . "', '0')", $ErrMsg, $DbgMsg, true);
}
}
/*
foreach ($ItemDescriptionLanguagesArray as $LanguageId) {
$DescriptionTranslation = $_POST['Description_' . str_replace('.', '_', $LanguageId)];
//WARNING: It DOES NOT update if database row DOES NOT exist.
$SQL = "UPDATE stockdescriptiontranslations " .
"SET descriptiontranslation='" . $DescriptionTranslation . "' " .
"WHERE stockid='" . $StockId . "' AND (language_id='" . $LanguageId. "')";
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
}
*/
}
/* Activate the needs revision flag for translations for modified descriptions */
if ($OldDescription != $_POST['Description'] or $OldLongDescription != $_POST['LongDescription']) {
$SQL = "UPDATE stockdescriptiontranslations
SET needsrevision = '0'
WHERE stockid='" . $StockID . "'";
$ErrMsg = _('The stock description translations could not be updated because');
$DbgMsg = _('The SQL that was used to set the flag for translation revision failed was');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
$SQL = "UPDATE stocklongdescriptiontranslations
SET needsrevision = '0'
WHERE stockid='" . $StockID . "'";
$ErrMsg = _('The stock description translations could not be updated because');
$DbgMsg = _('The SQL that was used to set the flag for translation revision failed was');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
$SQL = "UPDATE stockdescriptiontranslations SET descriptiontranslation='" . $_POST['Description'] . "'
WHERE stockid='" . $StockID . "'
AND language_id='" . $_SESSION['DefaultLanguage'] . "'";
$ErrMsg = _('The stock description translations could not be updated because');
$DbgMsg = _('The SQL that was used to set the flag for translation revision failed was');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
$SQL = "UPDATE stocklongdescriptiontranslations SET longdescriptiontranslation='" . $_POST['LongDescription'] . "'
WHERE stockid='" . $StockID . "'
AND language_id='" . $_SESSION['DefaultLanguage'] . "'";
$ErrMsg = _('The stock description translations could not be updated because');
$DbgMsg = _('The SQL that was used to set the flag for translation revision failed was');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
}
//delete any properties for the item no longer relevant with the change of category
$Result = DB_query("DELETE FROM stockitemproperties
WHERE stockid ='" . $StockId . "'", $ErrMsg, $DbgMsg, true);
//now insert any item properties
for ($i = 0; $i < $_POST['PropertyCounter']; $i++) {
if ($_POST['PropType' . $i] == 2) {
if ($_POST['PropValue' . $i] == 'on') {
$_POST['PropValue' . $i] = 1;
} else {
$_POST['PropValue' . $i] = 0;
}
}
if ($_POST['PropNumeric' . $i] == 1) {
$_POST['PropValue' . $i] = filter_number_format($_POST['PropValue' . $i]);
} else {
$_POST['PropValue' . $i] = $_POST['PropValue' . $i];
}
$Result = DB_query("INSERT INTO stockitemproperties (stockid,
stkcatpropid,
value)
VALUES ('" . $StockId . "',
'" . $_POST['PropID' . $i] . "',
'" . $_POST['PropValue' . $i] . "')", $ErrMsg, $DbgMsg, true);
} //end of loop around properties defined for the category
if ($OldStockAccount != $NewStockAct and $_SESSION['CompanyRecord']['gllink_stock'] == 1) {
/*Then we need to make a journal to transfer the cost to the new stock account */
$JournalNo = GetNextTransNo(0); //enter as a journal
$SQL = "INSERT INTO gltrans (type,
typeno,
trandate,
periodno,
account,
narrative,
amount)
VALUES ( 0,
'" . $JournalNo . "',
CURRENT_DATE,
'" . GetPeriod(Date($_SESSION['DefaultDateFormat']), true) . "',
'" . $NewStockAct . "',
'" . $StockId . ' ' . _('Change stock category') . "',
'" . ($UnitCost * $StockQtyRow[0]) . "')";
$ErrMsg = _('The stock cost journal could not be inserted because');
$DbgMsg = _('The SQL that was used to create the stock cost journal and failed was');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
$SQL = "INSERT INTO gltrans (type,
typeno,
trandate,
periodno,
account,
narrative,
amount)
VALUES ( 0,
'" . $JournalNo . "',
CURRENT_DATE,
'" . GetPeriod(Date($_SESSION['DefaultDateFormat']), true) . "',
'" . $OldStockAccount . "',
'" . $StockId . ' ' . _('Change stock category') . "',
'" . (-$UnitCost * $StockQtyRow[0]) . "')";
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
}
/* end if the stock category changed and forced a change in stock cost account */
if ($OldWIPAccount != $NewWIPAct and $_SESSION['CompanyRecord']['gllink_stock'] == 1) {
/*Then we need to make a journal to transfer the cost of WIP to the new WIP account */
/*First get the total cost of WIP for this category */
$WOCostsResult = DB_query("SELECT workorders.costissued,
SUM(woitems.qtyreqd * woitems.stdcost) AS costrecd
FROM woitems INNER JOIN workorders
ON woitems.wo = workorders.wo
INNER JOIN stockmaster
ON woitems.stockid=stockmaster.stockid
WHERE stockmaster.stockid='" . $StockId . "'
AND workorders.closed=0
GROUP BY workorders.costissued", _('Error retrieving value of finished goods received and cost issued against work orders for this item'));
$WIPValue = 0;
while ($WIPRow = DB_fetch_array($WOCostsResult)) {
$WIPValue += ($WIPRow['costissued'] - $WIPRow['costrecd']);
}
if ($WIPValue != 0) {
$JournalNo = GetNextTransNo(0); //enter as a journal
$SQL = "INSERT INTO gltrans (type,
typeno,
trandate,
periodno,
account,
narrative,
amount)
VALUES ( 0,
'" . $JournalNo . "',
CURRENT_DATE,
'" . GetPeriod(Date($_SESSION['DefaultDateFormat']), true) . "',
'" . $NewWIPAct . "',
'" . $StockId . ' ' . _('Change stock category') . "',
'" . $WIPValue . "')";
$ErrMsg = _('The WIP cost journal could not be inserted because');
$DbgMsg = _('The SQL that was used to create the WIP cost journal and failed was');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
$SQL = "INSERT INTO gltrans (type,
typeno,
trandate,
periodno,
account,
narrative,
amount)
VALUES ( 0,
'" . $JournalNo . "',
CURRENT_DATE,
'" . GetPeriod(Date($_SESSION['DefaultDateFormat']), true) . "',
'" . $OldWIPAccount . "',
'" . $StockId . ' ' . _('Change stock category') . "',
'" . (-$WIPValue) . "')";
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
}
}
/* end if the stock category changed and forced a change in WIP account */
DB_Txn_Commit();
prnMsg(_('Stock Item') . ' ' . $StockId . ' ' . _('has been updated'), 'success');
}
if (DB_error_no() != 0){
$Result = DB_Txn_Rollback();
}
} else { //it is a NEW part
//but lets be really sure here
$Result = DB_query("SELECT stockid
FROM stockmaster
WHERE stockid='" . $StockId . "'");
if (DB_num_rows($Result) == 1) {
prnMsg(_('The stock code entered is already in the database - duplicate stock codes are prohibited by the system. Try choosing an alternative stock code'), 'error');
$InputError = 1;
$Errors[$i] = 'StockID';
$i++;
} else {
DB_Txn_Begin();
$SQL = "INSERT INTO stockmaster (stockid,
description,
longdescription,
categoryid,
units,
mbflag,
eoq,
discontinued,
controlled,
serialised,
perishable,
volume,
grossweight,
netweight,
barcode,
discountcategory,
taxcatid,
decimalplaces,
shrinkfactor,
pansize)
VALUES ('" . $StockId . "',
'" . $_POST['Description'] . "',
'" . $_POST['LongDescription'] . "',
'" . $_POST['CategoryID'] . "',
'" . $_POST['Units'] . "',
'" . $_POST['MBFlag'] . "',
'" . filter_number_format($_POST['EOQ']) . "',
'" . $_POST['Discontinued'] . "',
'" . $_POST['Controlled'] . "',
'" . $_POST['Serialised'] . "',
'" . $_POST['Perishable'] . "',
'" . filter_number_format($_POST['Volume']) . "',
'" . filter_number_format($_POST['GrossWeight']) . "',
'" . filter_number_format($_POST['NetWeight']) . "',
'" . $_POST['BarCode'] . "',
'" . $_POST['DiscountCategory'] . "',
'" . $_POST['TaxCat'] . "',
'" . $_POST['DecimalPlaces'] . "',
'" . filter_number_format($_POST['ShrinkFactor']) . "',
'" . filter_number_format($_POST['Pansize']) . "')";
$ErrMsg = _('The item could not be added because');
$DbgMsg = _('The SQL that was used to add the item failed was');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
if (in_array($_SESSION['PageSecurityArray']['StockCostUpdate.php'], $_SESSION['AllowedPageSecurityTokens'])) {
$SQL = "INSERT INTO stockcosts VALUES('" . $StockId . "',
'" . filter_number_format($_POST['MaterialCost']) . "',
'" . filter_number_format($_POST['LabourCost']) . "',
'" . filter_number_format($_POST['OverheadCost']) . "',
CURRENT_TIMESTAMP,
0)";
$ErrMsg = _('The new cost details for the stock item could not be inserted because');
$DbgMsg = _('The SQL that failed was');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
/* End of cost updates */
} else {
$SQL = "INSERT INTO stockcosts VALUES('" . $StockId . "',
0,
0,
0,
CURRENT_TIMESTAMP,
0)";
$ErrMsg = _('The new cost details for the stock item could not be inserted because');
$DbgMsg = _('The SQL that failed was');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
/* End of cost updates */
}
if (DB_error_no() == 0) {
//now insert the language descriptions
$ErrMsg = _('Could not update the language description because');
$DbgMsg = _('The SQL that was used to update the language description and failed was');
if (count($ItemDescriptionLanguagesArray) > 0) {
foreach ($ItemDescriptionLanguagesArray as $LanguageId) {
if ($LanguageId != '' and $_POST['Description_' . str_replace('.', '_', $LanguageId)] != '') {
$SQL = "INSERT INTO stockdescriptiontranslations VALUES('" . $StockId . "','" . $LanguageId . "', '" . $_POST['Description_' . str_replace('.', '_', $LanguageId)] . "', 0)";
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
$SQL = "INSERT INTO stocklongdescriptiontranslations VALUES('" . $StockId . "','" . $LanguageId . "', '" . $_POST['LongDescription_' . str_replace('.', '_', $LanguageId)] . "', 0)";
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
}
}
}
/* Insert the default language descriptions into the translations table */
$SQL = "INSERT INTO stockdescriptiontranslations VALUES('" . $StockId . "','" . $_SESSION['DefaultLanguage'] . "', '" . $_POST['Description'] . "', 0)";
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
$SQL = "INSERT INTO stocklongdescriptiontranslations VALUES('" . $StockId . "','" . $_SESSION['DefaultLanguage'] . "', '" . $_POST['LongDescription'] . "', 0)";
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
/* End default language descriptions */
//now insert any item properties
for ($i = 0; $i < $_POST['PropertyCounter']; $i++) {
if ($_POST['PropType' . $i] == 2) {
if ($_POST['PropValue' . $i] == 'on') {
$_POST['PropValue' . $i] = 1;
} else {
$_POST['PropValue' . $i] = 0;
}
}
if ($_POST['PropNumeric' . $i] == 1) {
$_POST['PropValue' . $i] = filter_number_format($_POST['PropValue' . $i]);
} else {
$_POST['PropValue' . $i] = $_POST['PropValue' . $i];
}
$Result = DB_query("INSERT INTO stockitemproperties (stockid,
stkcatpropid,
value)
VALUES ('" . $StockId . "',
'" . $_POST['PropID' . $i] . "',
'" . $_POST['PropValue' . $i] . "')", $ErrMsg, $DbgMsg, true);
} //end of loop around properties defined for the category
//Add data to locstock
$SQL = "INSERT INTO locstock (loccode,
stockid)
SELECT locations.loccode,
'" . $StockId . "'
FROM locations";
$ErrMsg = _('The locations for the item') . ' ' . $StockId . ' ' . _('could not be added because');
$DbgMsg = _('NB Locations records can be added by opening the utility page') . ' <i>Z_MakeStockLocns.php</i> ' . _('The SQL that was used to add the location records that failed was');
$InsResult = DB_query($SQL, $ErrMsg, $DbgMsg, true);
DB_Txn_Commit();
if (DB_error_no() == 0) {
prnMsg(_('New Item') . ' ' . '
<a href="SelectProduct.php?StockID=' . urlencode($StockId) . '">' . $StockId . '</a> ' . _('has been added to the database') . '<br />' . _('NB: The item cost and pricing must also be setup') . '<br />' . '<a target="_blank" href="StockCostUpdate.php?StockID=' . $StockId . '">' . _('Enter Item Cost') . '</a>
<br />' . '<a target="_blank" href="Prices.php?Item=' . urlencode($StockId) . '">' . _('Enter Item Prices') . '</a> ', 'success');
echo '<br />';
unset($_POST['Description']);
unset($_POST['LongDescription']);
unset($_POST['EOQ']);
// Leave Category ID set for ease of batch entry
// unset($_POST['CategoryID']);
unset($_POST['Units']);
unset($_POST['MBFlag']);
unset($_POST['Discontinued']);
unset($_POST['Controlled']);
unset($_POST['Serialised']);
unset($_POST['Perishable']);
unset($_POST['Volume']);
unset($_POST['GrossWeight']);
unset($_POST['NetWeight']);
unset($_POST['BarCode']);
unset($_POST['ReorderLevel']);
unset($_POST['DiscountCategory']);
unset($_POST['DecimalPlaces']);
unset($_POST['ShrinkFactor']);
unset($_POST['Pansize']);
unset($StockId);
foreach ($ItemDescriptionLanguagesArray as $LanguageId) {
unset($_POST['Description_' . str_replace('.', '_', $LanguageId)]);
}
$New = 1;
} else {
$InsResult = DB_Txn_Rollback();
}
} //THE INSERT OF THE NEW CODE WORKED SO BANG IN THE STOCK LOCATION RECORDS TOO
} //END CHECK FOR ALREADY EXISTING ITEM OF THE SAME CODE
}
} else {
echo '<br />' . "\n";
prnMsg(_('Validation failed, no updates or deletes took place'), 'error');
}
} else if (isset($_POST['delete']) and mb_strlen($_POST['delete']) > 1) {
//the button to delete a selected record was clicked instead of the submit button
$CancelDelete = 0;
// PREVENT DELETES IF DEPENDENT RECORDS IN 'StockMoves'
$SQL = "SELECT COUNT(*) FROM stockmoves WHERE stockid='" . $StockId . "' GROUP BY stockid";
$Result = DB_query($SQL);
$MyRow = DB_fetch_row($Result);
if ($MyRow[0] > 0) {
$CancelDelete = 1;
prnMsg(_('Cannot delete this stock item because there are stock movements that refer to this item'), 'warn');
echo '<br />' . _('There are') . ' ' . $MyRow[0] . ' ' . _('stock movements that refer to this item');
} else {
$SQL = "SELECT COUNT(*) FROM bom WHERE component='" . $StockId . "' GROUP BY component";
$Result = DB_query($SQL);
$MyRow = DB_fetch_row($Result);
if ($MyRow[0] > 0) {
$CancelDelete = 1;
prnMsg(_('Cannot delete this item record because there are bills of material that require this part as a component'), 'warn');
echo '<br />' . _('There are') . ' ' . $MyRow[0] . ' ' . _('bills of material that require this part as a component');
} else {
$SQL = "SELECT COUNT(*) FROM salesorderdetails WHERE stkcode='" . $StockId . "' GROUP BY stkcode";
$Result = DB_query($SQL);
$MyRow = DB_fetch_row($Result);
if ($MyRow[0] > 0) {
$CancelDelete = 1;
prnMsg(_('Cannot delete this item record because there are existing sales orders for this part'), 'warn');
echo '<br />' . _('There are') . ' ' . $MyRow[0] . ' ' . _('sales order items against this part');
} else {
$SQL = "SELECT COUNT(*) FROM salesanalysis WHERE stockid='" . $StockId . "' GROUP BY stockid";
$Result = DB_query($SQL);
$MyRow = DB_fetch_row($Result);
if ($MyRow[0] > 0) {
$CancelDelete = 1;
prnMsg(_('Cannot delete this item because sales analysis records exist for it'), 'warn');
echo '<br />' . _('There are') . ' ' . $MyRow[0] . ' ' . _('sales analysis records against this part');
} else {
$SQL = "SELECT COUNT(*) FROM purchorderdetails WHERE itemcode='" . $StockId . "' GROUP BY itemcode";
$Result = DB_query($SQL);
$MyRow = DB_fetch_row($Result);
if ($MyRow[0] > 0) {
$CancelDelete = 1;
prnMsg(_('Cannot delete this item because there are existing purchase order items for it'), 'warn');
echo '<br />' . _('There are') . ' ' . $MyRow[0] . ' ' . _('purchase order item record relating to this part');
} else {
$SQL = "SELECT SUM(quantity) AS qoh FROM locstock WHERE stockid='" . $StockId . "' GROUP BY stockid";
$Result = DB_query($SQL);
$MyRow = DB_fetch_row($Result);
if ($MyRow[0] != 0) {
$CancelDelete = 1;
prnMsg(_('Cannot delete this item because there is currently some stock on hand'), 'warn');
echo '<br />' . _('There are') . ' ' . $MyRow[0] . ' ' . _('on hand for this part');
} else {
$SQL = "SELECT COUNT(*) FROM offers WHERE stockid='" . $StockId . "' GROUP BY stockid";
$Result = DB_query($SQL);
$MyRow = DB_fetch_row($Result);
if ($MyRow[0] != 0) {
$CancelDelete = 1;
prnMsg(_('Cannot delete this item because there are offers for this item'), 'warn');
echo '<br />' . _('There are') . ' ' . $MyRow[0] . ' ' . _('offers from suppliers for this part');
} else {
$SQL = "SELECT COUNT(*) FROM tenderitems WHERE stockid='" . $StockId . "' GROUP BY stockid";
$Result = DB_query($SQL);
$MyRow = DB_fetch_row($Result);
if ($MyRow[0] != 0) {
$CancelDelete = 1;
prnMsg(_('Cannot delete this item because there are tenders for this item'), 'warn');
echo '<br />' . _('There are') . ' ' . $MyRow[0] . ' ' . _('tenders from suppliers for this part');
}
}
}
}
}
}
}
}
if ($CancelDelete == 0) {
$Result = DB_Txn_Begin();
/*Deletes LocStock records*/
$SQL = "DELETE FROM locstock WHERE stockid='" . $StockId . "'";
$Result = DB_query($SQL, _('Could not delete the location stock records because'), '', true);
/*Deletes Price records*/
$SQL = "DELETE FROM prices WHERE stockid='" . $StockId . "'";
$Result = DB_query($SQL, _('Could not delete the prices for this stock record because'), '', true);
/*and cascade deletes in PurchData */
$SQL = "DELETE FROM purchdata WHERE stockid='" . $StockId . "'";
$Result = DB_query($SQL, _('Could not delete the purchasing data because'), '', true);
/*and cascade delete the bill of material if any */
$SQL = "DELETE FROM bom WHERE parent='" . $StockId . "'";
$Result = DB_query($SQL, _('Could not delete the bill of material because'), '', true);
//and cascade delete the item properties
$SQL = "DELETE FROM stockitemproperties WHERE stockid='" . $StockId . "'";
$Result = DB_query($SQL, _('Could not delete the item properties'), '', true);
//and cascade delete the item descriptions in other languages
$SQL = "DELETE FROM stockdescriptiontranslations WHERE stockid='" . $StockId . "'";
$Result = DB_query($SQL, _('Could not delete the item language descriptions'), '', true);
$SQL = "DELETE FROM stocklongdescriptiontranslations WHERE stockid='" . $StockId . "'";
$Result = DB_query($SQL, _('Could not delete the item language descriptions'), '', true);
//and finally remove the stockmaster
$SQL = "DELETE FROM stockmaster WHERE stockid='" . $StockId . "'";
$Result = DB_query($SQL, _('Could not delete the item record'), '', true);
$Result = DB_Txn_Commit();
prnMsg(_('Deleted the stock master record for') . ' ' . $StockId . '....' . '<br />. . ' . _('and all the location stock records set up for the part') . '<br />. . .' . _('and any bill of material that may have been set up for the part') . '<br /> . . . .' . _('and any purchasing data that may have been set up for the part') . '<br /> . . . . .' . _('and any prices that may have been set up for the part'), 'success');
echo '<br />';
unset($_POST['LongDescription']);
unset($_POST['Description']);
unset($_POST['EOQ']);
unset($_POST['CategoryID']);
unset($_POST['Units']);
unset($_POST['MBFlag']);
unset($_POST['Discontinued']);
unset($_POST['Controlled']);
unset($_POST['Serialised']);
unset($_POST['Perishable']);
unset($_POST['Volume']);
unset($_POST['GrossWeight']);
unset($_POST['NetWeight']);
unset($_POST['BarCode']);
unset($_POST['ReorderLevel']);
unset($_POST['DiscountCategory']);
unset($_POST['TaxCat']);
unset($_POST['DecimalPlaces']);
unset($_SESSION['SelectedStockItem']);
foreach ($ItemDescriptionLanguagesArray as $LanguageId) {
unset($_POST['Description_' . str_replace('.', '_', $LanguageId)]);
}
unset($StockId);
$New = 1;
} //end if Delete Part
}
echo '<form id="ItemForm" enctype="multipart/form-data" method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '">';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />
<input type="hidden" name="New" value="' . $New . '" />
<table class="selection">';
if (isset($StockId) and $StockId != '') {
echo '<table width="100%">
<tr>
<td><input class="image" src="css/' . $_SESSION['Theme'] . '/images/previous.png" type="image" name="PreviousItem" title="' . _('Previous Item') . '" value="" /></td>
<td><label>' . _('Navigate Items') . '</label></td>
<td><input class="image" src="css/' . $_SESSION['Theme'] . '/images/next.png" type="image" name="NextItem" title="' . _('Next Item') . '" value="" /></td>
</tr>';
}
echo '<input type="hidden" name="New" value="' . $New . '" />';
echo '<table class="selection">';
if (!isset($StockId) or $StockId == '' or isset($_POST['UpdateCategories'])) {
/*If the page was called without $StockId passed to page then assume a new stock item is to be entered show a form with a part Code field other wise the form showing the fields with the existing entries against the part will show for editing with only a hidden StockID field. New is set to flag that the page may have called itself and still be entering a new part, in which case the page needs to know not to go looking up details for an existing part*/
if (!isset($StockId)) {
$StockId = '';
}
if ($New == 1) {
echo '<tr>
<td>' . _('Item Code') . ':</td>
<td><input type="text" value="' . $StockId . '" name="StockID" size="21" required="required" maxlength="20" /></td>
</tr>';
} else {
echo '<tr>
<td>' . _('Item Code') . ':</td>
<td>' . $StockId . '<input type="hidden" name ="StockID" value="' . $StockId . '" /></td>
</tr>';
}
} elseif (!isset($_POST['UpdateCategories']) and $InputError != 1) { // Must be modifying an existing item and no changes made yet
$SQL = "SELECT stockmaster.stockid,
description,
longdescription,
categoryid,
units,
mbflag,
discontinued,
controlled,
serialised,
perishable,
eoq,
volume,
grossweight,
netweight,
barcode,
discountcategory,
taxcatid,
decimalplaces,
nextserialno,
pansize,
shrinkfactor,
stockcosts.materialcost,
stockcosts.labourcost,
stockcosts.overheadcost
FROM stockmaster
LEFT JOIN stockcosts
ON stockmaster.stockid = stockcosts.stockid
AND stockcosts.succeeded=0
WHERE stockmaster.stockid = '" . $StockId . "'";
$Result = DB_query($SQL);
$MyRow = DB_fetch_array($Result);
$_POST['LongDescription'] = $MyRow['longdescription'];
$_POST['Description'] = $MyRow['description'];
$_POST['EOQ'] = $MyRow['eoq'];
$_POST['CategoryID'] = $MyRow['categoryid'];
$_POST['Units'] = $MyRow['units'];
$_POST['MBFlag'] = $MyRow['mbflag'];
$_POST['Discontinued'] = $MyRow['discontinued'];
$_POST['Controlled'] = $MyRow['controlled'];
$_POST['Serialised'] = $MyRow['serialised'];
$_POST['Perishable'] = $MyRow['perishable'];
$_POST['Volume'] = $MyRow['volume'];
$_POST['GrossWeight'] = $MyRow['grossweight'];
$_POST['NetWeight'] = $MyRow['netweight'];
$_POST['BarCode'] = $MyRow['barcode'];
$_POST['DiscountCategory'] = $MyRow['discountcategory'];
$_POST['TaxCat'] = $MyRow['taxcatid'];
$_POST['DecimalPlaces'] = $MyRow['decimalplaces'];
$_POST['NextSerialNo'] = $MyRow['nextserialno'];
$_POST['Pansize'] = $MyRow['pansize'];
$_POST['ShrinkFactor'] = $MyRow['shrinkfactor'];
$_POST['MaterialCost'] = $MyRow['materialcost'];
$_POST['LabourCost'] = $MyRow['labourcost'];
$_POST['OverheadCost'] = $MyRow['overheadcost'];
$SQL = "SELECT descriptiontranslation, language_id FROM stockdescriptiontranslations WHERE stockid='" . $StockId . "' AND (";
foreach ($ItemDescriptionLanguagesArray as $LanguageId) {
$SQL .= "language_id='" . $LanguageId . "' OR ";
}
$SQL = mb_substr($SQL, 0, mb_strlen($SQL) - 3) . ')';
$Result = DB_query($SQL);
while ($MyRow = DB_fetch_array($Result)) {
$_POST['Description_' . str_replace('.', '_', $MyRow['language_id'])] = $MyRow['descriptiontranslation'];
}
$SQL = "SELECT longdescriptiontranslation, language_id FROM stocklongdescriptiontranslations WHERE stockid='" . $StockId . "' AND (";
foreach ($ItemDescriptionLanguagesArray as $LanguageId) {
$SQL .= "language_id='" . $LanguageId . "' OR ";
}
$SQL = mb_substr($SQL, 0, mb_strlen($SQL) - 3) . ')';
$Result = DB_query($SQL);
while ($MyRow = DB_fetch_array($Result)) {
$_POST['LongDescription_' . str_replace('.', '_', $MyRow['language_id'])] = $MyRow['longdescriptiontranslation'];
}
echo '<tr>
<td>' . _('Item Code') . ':</td>
<td>' . $StockId . '<input type="hidden" name="StockID" value="' . $StockId . '" /></td>
</tr>';
} else { // some changes were made to the data so don't re-set form variables to DB ie the code above
echo '<tr>
<td>' . _('Item Code') . ':</td>
<td>' . $StockId . '<input type="hidden" name="StockID" value="' . $StockId . '" /></td>
</tr>';
}
if (isset($_POST['Description'])) {
$Description = $_POST['Description'];
} else {
$Description = '';
}
echo '<tr>
<td>' . _('Part Description') . ' (' . _('short') . '):</td>
<td><input type="text" name="Description" size="52" required="required" maxlength="50" value="' . stripslashes($Description) . '" /></td>
</tr>';
if (isset($_POST['LongDescription'])) {
$LongDescription = AddCarriageReturns($_POST['LongDescription']);
} else {
$LongDescription = '';
}
echo '<tr>
<td>' . _('Part Description') . ' (' . _('long') . '):</td>
<td><textarea required="required" name="LongDescription" cols="40" rows="3">' . stripslashes($LongDescription) . '</textarea></td>
</tr>';
foreach ($ItemDescriptionLanguagesArray as $LanguageId) {
if ($LanguageId != '') {
//unfortunately cannot have points in POST variables so have to mess with the language id
$PostVariableName = 'Description_' . str_replace('.', '_', $LanguageId);
if (!isset($_POST[$PostVariableName])) {
$_POST[$PostVariableName] = '';
}
echo '<tr>
<td>' . $LanguagesArray[$LanguageId]['LanguageName'] . ' ' . _('Description') . ':</td>
<td><input type="text" name="' . $PostVariableName . '" size="52" maxlength="50" value="' . $_POST[$PostVariableName] . '" /></td>
</tr>';
if (!isset($_POST['Long' . $PostVariableName])) {
$_POST['Long' . $PostVariableName] = '';
}
echo '<tr>
<td>' . $LanguagesArray[$LanguageId]['LanguageName'] . ' ' . _('Long Description') . ':</td>
<td><textarea name="Long' . $PostVariableName . '" cols="40" rows="3">' . $_POST['Long' . $PostVariableName] . '</textarea></td>
</tr>';
}
}
echo '<tr>
<td>' . _('Image File (' . implode(", ", $SupportedImgExt) . ')') . ':</td>
<td><input type="file" id="ItemPicture" name="ItemPicture" />
<br /><input type="checkbox" name="ClearImage" id="ClearImage" value="1" > '._('Clear Image').'
</td>';
$ImageFile = reset((glob($_SESSION['part_pics_dir'] . '/' . $StockID . '.{' . implode(",", $SupportedImgExt) . '}', GLOB_BRACE)));
if (extension_loaded('gd') and function_exists('gd_info') and isset($StockID) and !empty($StockID)) {
$StockImgLink = '<img src="GetStockImage.php?automake=1&amp;textcolor=FFFFFF&amp;bgcolor=CCCCCC' . '&amp;StockID=' . urlencode($StockId) . '&amp;text=' . '&amp;width=64' . '&amp;height=64' . '" alt="" />';
} else if (file_exists ($ImageFile)) {
$StockImgLink = '<img src="' . $ImageFile . '" height="64" width="64" />';
} else {
$StockImgLink = _('No Image');
}
if ($StockImgLink != _('No Image')) {
echo '<td>' . _('Image') . '<br />' . $StockImgLink . '</td>';
}
if (isset($_POST['ClearImage'])) {
foreach ($SupportedImgExt as $ext) {
$File = $_SESSION['part_pics_dir'] . '/' . $StockID . '.' . $ext;
if (file_exists($File) ) {
//workaround for many variations of permission issues that could cause unlink fail
@unlink($File);
if (is_file($ImageFile)) {
prnMsg(_('You do not have access to delete this item image file.'), 'error');
} else {
$StockImgLink = _('No Image');
}
}
}
}
echo '</tr>';
echo '<tr>
<td>' . _('Category') . ':</td>
<td><select required="required" name="CategoryID" >;
$SQL = "SELECT categoryid, categorydescription FROM stockcategory";
$ErrMsg = _('The stock categories could not be retrieved because');
$DbgMsg = _('The SQL used to retrieve stock categories and failed was');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg);
while ($MyRow = DB_fetch_array($Result)) {
if (!isset($_POST['CategoryID']) or $MyRow['categoryid'] == $_POST['CategoryID']) {
echo '<option selected="selected" value="' . $MyRow['categoryid'] . '">' . $MyRow['categorydescription'] . '</option>';
} else {
echo '<option value="' . $MyRow['categoryid'] . '">' . $MyRow['categorydescription'] . '</option>';
}
$Category = $MyRow['categoryid'];
}
if (!isset($_POST['CategoryID'])) {
$_POST['CategoryID'] = $Category;
}
echo '</select><a target="_blank" href="' . $RootPath . '/StockCategories.php">' . _('Add or Modify Stock Categories') . '</a></td>
</tr>';
if (!isset($_POST['EOQ']) or $_POST['EOQ'] == '') {
$_POST['EOQ'] = 0;
}
if (!isset($_POST['Volume']) or $_POST['Volume'] == '') {
$_POST['Volume'] = 0;
}
if (!isset($_POST['GrossWeight']) or $_POST['GrossWeight'] == '') {
$_POST['GrossWeight'] = 0;
}
if (!isset($_POST['NetWeight']) or $_POST['NetWeight']==''){
$_POST['NetWeight'] = 0;
}
if (!isset($_POST['Controlled']) or $_POST['Controlled'] == '') {
$_POST['Controlled'] = 0;
}
if (!isset($_POST['Serialised']) or $_POST['Serialised'] == '' or $_POST['Controlled'] == 0) {
$_POST['Serialised'] = 0;
}
if (!isset($_POST['DecimalPlaces']) or $_POST['DecimalPlaces'] == '') {
$_POST['DecimalPlaces'] = 0;
}
if (!isset($_POST['Discontinued']) or $_POST['Discontinued'] == '') {
$_POST['Discontinued'] = 0;
}
if (!isset($_POST['Pansize'])) {
$_POST['Pansize'] = 0;
}
if (!isset($_POST['ShrinkFactor'])) {
$_POST['ShrinkFactor'] = 0;
}
if (!isset($_POST['NextSerialNo'])) {
$_POST['NextSerialNo'] = 0;
}
if (!isset($_POST['MaterialCost'])) {
$_POST['MaterialCost'] = 0;
}
if (!isset($_POST['LabourCost'])) {
$_POST['LabourCost'] = 0;
}
if (!isset($_POST['OverheadCost'])) {
$_POST['OverheadCost'] = 0;
}
echo '<tr>
<td>' . _('Economic Order Quantity') . ':</td>
<td><input type="text" class="number" name="EOQ" size="12" maxlength="10" value="' . locale_number_format($_POST['EOQ'], 'Variable') . '" /></td></tr>';
echo '<tr>
<td>' . _('Packaged Volume (metres cubed)') . ':</td>
<td><input type="text" class="number" name="Volume" size="12" maxlength="10" value="' . locale_number_format($_POST['Volume'], 'Variable') . '" /></td>
</tr>';
echo '<tr>
<td>' . _('Packaged Weight (KGs)') . ':</td><td><input type="text" class="number" name="GrossWeight" size="12" maxlength="10" value="' . locale_number_format($_POST['GrossWeight'], 'Variable') . '" /></td>
</tr>';
echo '<tr>
<td>' . _('Net Weight (KGs)') . ':</td><td><input type="text" class="number" name="NetWeight" size="12" maxlength="10" value="' . locale_number_format($_POST['NetWeight'],'Variable') . '" /></td>
</tr>';
echo '<tr>
<td>' . _('Units of Measure') . ':</td>
<td><select name="Units">';
$SQL = "SELECT unitname FROM unitsofmeasure ORDER by unitname";
$UOMResult = DB_query($SQL);
if (!isset($_POST['Units'])) {
$UOMrow['unitname'] = _('each');
}
while ($UOMrow = DB_fetch_array($UOMResult)) {
if (isset($_POST['Units']) and $_POST['Units'] == $UOMrow['unitname']) {
echo '<option selected="selected" value="' . $UOMrow['unitname'] . '">' . $UOMrow['unitname'] . '</option>';
} else {
echo '<option value="' . $UOMrow['unitname'] . '">' . $UOMrow['unitname'] . '</option>';
}
}
echo '</select></td>
</tr>';
echo '<tr>
<td>' . _('Assembly, Kit, Manufactured or Service/Labour') . ':</td>
<td><select name="MBFlag">';
if (!isset($_POST['MBFlag']) or $_POST['MBFlag'] == 'A') {
echo '<option selected="selected" value="A">' . _('Assembly') . '</option>';
} else {
echo '<option value="A">' . _('Assembly') . '</option>';
}
if (!isset($_POST['MBFlag']) or $_POST['MBFlag'] == 'K') {
echo '<option selected="selected" value="K">' . _('Kit') . '</option>';
} else {
echo '<option value="K">' . _('Kit') . '</option>';
}
if (!isset($_POST['MBFlag']) or $_POST['MBFlag'] == 'M') {
echo '<option selected="selected" value="M">' . _('Manufactured') . '</option>';
} else {
echo '<option value="M">' . _('Manufactured') . '</option>';
}
if (!isset($_POST['MBFlag']) or $_POST['MBFlag'] == 'G' or !isset($_POST['MBFlag']) or $_POST['MBFlag'] == '') {
echo '<option selected="selected" value="G">' . _('Phantom') . '</option>';
} else {
echo '<option value="G">' . _('Phantom') . '</option>';
}
if (!isset($_POST['MBFlag']) or $_POST['MBFlag'] == 'B' or !isset($_POST['MBFlag']) or $_POST['MBFlag'] == '') {
echo '<option selected="selected" value="B">' . _('Purchased') . '</option>';
} else {
echo '<option value="B">' . _('Purchased') . '</option>';
}
if (isset($_POST['MBFlag']) and $_POST['MBFlag'] == 'D') {
echo '<option selected="selected" value="D">' . _('Service/Labour') . '</option>';
} else {
echo '<option value="D">' . _('Service/Labour') . '</option>';
}
echo '</select></td>
</tr>';
echo '<tr>
<td>' . _('Current or Obsolete') . ':</td>
<td><select name="Discontinued">';
if ($_POST['Discontinued'] == 0) {
echo '<option selected="selected" value="0">' . _('Current') . '</option>';
} else {
echo '<option value="0">' . _('Current') . '</option>';
}
if ($_POST['Discontinued'] == 1) {
echo '<option selected="selected" value="1">' . _('Obsolete') . '</option>';
} else {
echo '<option value="1">' . _('Obsolete') . '</option>';
}
echo '</select></td>
</tr>';
echo '<tr>
<td>' . _('Batch, Serial or Lot Control') . ':</td>
<td><select name="Controlled">';
if ($_POST['Controlled'] == 0) {
echo '<option selected="selected" value="0">' . _('No Control') . '</option>';
} else {
echo '<option value="0">' . _('No Control') . '</option>';
}
if ($_POST['Controlled'] == 1) {
echo '<option selected="selected" value="1">' . _('Controlled') . '</option>';
} else {
echo '<option value="1">' . _('Controlled') . '</option>';
}
echo '</select></td></tr>';
echo '<tr><td>' . _('Serialised') . ':</td><td><select name="Serialised">';
if ($_POST['Serialised'] == 0) {
echo '<option selected="selected" value="0">' . _('No') . '</option>';
} else {
echo '<option value="0">' . _('No') . '</option>';
}
if ($_POST['Serialised'] == 1) {
echo '<option selected="selected" value="1">' . _('Yes') . '</option>';
} else {
echo '<option value="1">' . _('Yes') . '</option>';
}
echo '</select><i>' . _('Note') . ', ' . _('this has no effect if the item is not Controlled') . '</i></td>
</tr>';
if ($_POST['Serialised'] == 1 and $_POST['MBFlag'] == 'M') {
echo '<tr>
<td>' . _('Next Serial No (Greater than zero for auto numbering)') . ':</td>
<td><input type="text" name="NextSerialNo" size="15" maxlength="15" value="' . $_POST['NextSerialNo'] . '" /></td></tr>';
} else {
echo '<tr><td><input type="hidden" name="NextSerialNo" value="0" /></td></tr>';
}
echo '<tr>
<td>' . _('Perishable') . ':</td>
<td><select name="Perishable">';
if (!isset($_POST['Perishable']) or $_POST['Perishable'] == 0) {
echo '<option selected="selected" value="0">' . _('No') . '</option>';
} else {
echo '<option value="0">' . _('No') . '</option>';
}
if (isset($_POST['Perishable']) and $_POST['Perishable'] == 1) {
echo '<option selected="selected" value="1">' . _('Yes') . '</option>';
} else {
echo '<option value="1">' . _('Yes') . '</option>';
}
echo '</select></td></tr>';
echo '<tr>
<td>' . _('Decimal Places for display Quantity') . ':</td>
<td><input type="text" class="number" name="DecimalPlaces" size="1" maxlength="1" value="' . $_POST['DecimalPlaces'] . '" /></td>
</tr>';
if (isset($_POST['BarCode'])) {
$BarCode = $_POST['BarCode'];
} else {
$BarCode = '';
}
echo '<tr>
<td>' . _('Bar Code') . ':</td>
<td><input type="text" name="BarCode" size="22" maxlength="20" value="' . $BarCode . '" /></td>
</tr>';
if (isset($_POST['DiscountCategory'])) {
$DiscountCategory = $_POST['DiscountCategory'];
} else {
$DiscountCategory = '';
}
echo '<tr>
<td>' . _('Discount Category') . ':</td>
<td><input type="text" name="DiscountCategory" size="2" maxlength="2" value="' . $DiscountCategory . '" /></td>
</tr>';
echo '<tr>
<td>' . _('Tax Category') . ':</td>
<td><select name="TaxCat">';
$SQL = "SELECT taxcatid, taxcatname FROM taxcategories ORDER BY taxcatname";
$Result = DB_query($SQL);
if (!isset($_POST['TaxCat'])) {
$_POST['TaxCat'] = $_SESSION['DefaultTaxCategory'];
}
while ($MyRow = DB_fetch_array($Result)) {
if ($_POST['TaxCat'] == $MyRow['taxcatid']) {
echo '<option selected="selected" value="' . $MyRow['taxcatid'] . '">' . $MyRow['taxcatname'] . '</option>';
} else {
echo '<option value="' . $MyRow['taxcatid'] . '">' . $MyRow['taxcatname'] . '</option>';
}
} //end while loop
echo '</select></td>
</tr>';
echo '<tr>
<td>' . _('Pan Size') . ':</td>
<td><input type="text" class="number" name="Pansize" size="6" maxlength="6" value="' . locale_number_format($_POST['Pansize'], 0) . '" /></td>
</tr>
<tr>
<td>' . _('Shrinkage Factor') . ':</td>
<td><input type="text" class="number" name="ShrinkFactor" size="6" maxlength="6" value="' . locale_number_format($_POST['ShrinkFactor'], 0) . '" /></td>
</tr>';
if (in_array($_SESSION['PageSecurityArray']['StockCostUpdate.php'], $_SESSION['AllowedPageSecurityTokens'])) {
echo '<tr>
<td>' . _('Material Cost') . ':</td>
<td><input type="text" class="number" name="MaterialCost" size="6" maxlength="12" value="' . locale_number_format($_POST['MaterialCost'], $_SESSION['StandardCostDecimalPlaces']) . '" /></td>
</tr>
<tr>
<td>' . _('Labour Cost') . ':</td>
<td><input type="text" class="number" name="LabourCost" size="6" maxlength="12" value="' . locale_number_format($_POST['LabourCost'], $_SESSION['StandardCostDecimalPlaces']) . '" /></td>
</tr>
<tr>
<td>' . _('Overhead Cost') . ':</td>
<td><input type="text" class="number" name="OverheadCost" size="6" maxlength="12" value="' . locale_number_format($_POST['OverheadCost'], $_SESSION['StandardCostDecimalPlaces']) . '" /></td>
</tr>';
} else {
echo '<tr>
<td>' . _('Material Cost') . ':</td>
<td>' . locale_number_format($_POST['MaterialCost'], $_SESSION['StandardCostDecimalPlaces']) . '</td>
<input type="hidden" name="MaterialCost" value="' . $_POST['MaterialCost'] . '" />
</tr>
<tr>
<td>' . _('Labour Cost') . ':</td>
<td>' . locale_number_format($_POST['LabourCost'], $_SESSION['StandardCostDecimalPlaces']) . '</td>
<input type="hidden" name="LabourCost" value="' . $_POST['LabourCost'] . '" />
</tr>
<tr>
<td>' . _('Overhead Cost') . ':</td>
<td>' . locale_number_format($_POST['OverheadCost'], $_SESSION['StandardCostDecimalPlaces']) . '</td>
<input type="hidden" name="OverheadCost" value="' . $_POST['OverheadCost'] . '" />
</tr>';
}
echo '</table>
<div class="centre">';
if (!isset($_POST['CategoryID'])) {
$_POST['CategoryID'] = '';
}
$SQL = "SELECT stkcatpropid,
label,
controltype,
defaultvalue,
numericvalue,
minimumvalue,
maximumvalue
FROM stockcatproperties
WHERE categoryid ='" . $_POST['CategoryID'] . "'
AND reqatsalesorder =0
ORDER BY stkcatpropid";
$PropertiesResult = DB_query($SQL);
$PropertyCounter = 0;
$PropertyWidth = array();
if (DB_num_rows($PropertiesResult) > 0) {
echo '<br />
<table class="selection">';
echo '<tr>
<th colspan="2">' . _('Item Category Properties') . '</th>
</tr>';
while ($PropertyRow = DB_fetch_array($PropertiesResult)) {
if (isset($StockId)) {
$PropValResult = DB_query("SELECT value FROM
stockitemproperties
WHERE stockid='" . $StockId . "'
AND stkcatpropid ='" . $PropertyRow['stkcatpropid'] . "'");
$PropValRow = DB_fetch_row($PropValResult);
$PropertyValue = $PropValRow[0];
} else {
$PropertyValue = '';
}
echo '<tr>
<td>';
echo '<input type="hidden" name="PropID' . $PropertyCounter . '" value="' . $PropertyRow['stkcatpropid'] . '" />';
echo '<input type="hidden" name="PropNumeric' . $PropertyCounter . '" value="' . $PropertyRow['numericvalue'] . '" />';
echo $PropertyRow['label'] . '</td>
<td>';
switch ($PropertyRow['controltype']) {
case 0; //textbox
if ($PropertyRow['numericvalue'] == 1) {
echo '<input type="hidden" name="PropMin' . $PropertyCounter . '" value="' . $PropertyRow['minimumvalue'] . '" />';
echo '<input type="hidden" name="PropMax' . $PropertyCounter . '" value="' . $PropertyRow['maximumvalue'] . '" />';
echo '<input type="text" class="number" name="PropValue' . $PropertyCounter . '" size="20" maxlength="100" value="' . locale_number_format($PropertyValue, 'Variable') . '" />';
echo _('A number between') . ' ' . locale_number_format($PropertyRow['minimumvalue'], 'Variable') . ' ' . _('and') . ' ' . locale_number_format($PropertyRow['maximumvalue'], 'Variable') . ' ' . _('is expected');
} else {
echo '<input type="text" name="PropValue' . $PropertyCounter . '" size="20" maxlength="100" value="' . $PropertyValue . '" />';
}
break;
case 1; //select box
$OptionValues = explode(',', $PropertyRow['defaultvalue']);
echo '<select name="PropValue' . $PropertyCounter . '">';
foreach ($OptionValues as $PropertyOptionValue) {
if ($PropertyOptionValue == $PropertyValue) {
echo '<option selected="selected" value="' . $PropertyOptionValue . '">' . $PropertyOptionValue . '</option>';
} else {
echo '<option value="' . $PropertyOptionValue . '">' . $PropertyOptionValue . '</option>';
}
}
echo '</select>';
break;
case 2; //checkbox
echo '<input type="checkbox" name="PropValue' . $PropertyCounter . '"';
if ($PropertyValue == 1) {
echo 'checked';
}
echo ' />';
break;
} //end switch
echo '<input type="hidden" name="PropType' . $PropertyCounter . '" value="' . $PropertyRow['controltype'] . '" />';
echo '</td></tr>';
$PropertyCounter++;
} //end loop round properties for the item category
unset($StockId);
echo '</table>';
}
echo '<input type="hidden" name="PropertyCounter" value="' . $PropertyCounter . '" />';
echo '<br />';
if ($New == 1) {
echo '<input type="submit" name="submit" value="' . _('Insert New Item') . '" />';
echo '<input type="submit" name="UpdateCategories" style="visibility:hidden;width:1px" value="' . _('Categories') . '" />';
} else {
// Now the form to enter the item properties
echo '<input type="submit" name="submit" value="' . _('Update') . '" />';
echo '<input type="submit" name="UpdateCategories" style="visibility:hidden;width:1px" value="' . _('Categories') . '" />';
echo '<br />';
prnMsg(_('Only click the Delete button if you are sure you wish to delete the item!') . _('Checks will be made to ensure that there are no stock movements, sales analysis records, sales order items or purchase order items for the item') . '. ' . _('No deletions will be allowed if they exist'), 'warn', _('WARNING'));
echo '<br />
<br />
<input type="submit" name="delete" value="' . _('Delete This Item') . '" MakeConfirm(\'' . _('Are You Sure?') . '\');" />';
}
echo '</div>
</form>';
include('includes/footer.inc');
?>