This repository has been archived by the owner on Jan 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
internal_transaction.php
497 lines (334 loc) · 17 KB
/
internal_transaction.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
<?php
include("config.php");
session_start();
include ('userheader.php');
?>
<style>
.topnav {
background-color: #3C8DBC;
overflow: hidden;
}
/* Style the links inside the navigation bar */
.topnav a {
float: left;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
/* Change the color of links on hover */
.topnav a:hover {
background-color: #ddd;
color: black;
}
/* Add a color to the active/current link */
.topnav a.active {
background-color: #4CAF50;
color: white;
}
</style>
<section class="content-header">
<h1> <div class="topnav">
<a href="external_sales.php">External Shipment</a>
<a href="internal_transaction.php">Internal Shipment</a>
<a href="convert_transaction_out.php">Conversion OUT</a>
<a href="convert_transaction_in.php">Conversion IN</a>
</div> </h1>
<ol class="breadcrumb">
<li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
<li><a href="createtransaction.php">Create Transaction</a></li>
</ol>
</section>
<!-- Main content -->
<section class="content">
<div class="row">
<div class="col-sm-12">
<!-- Profile Image -->
<div class="box box-primary">
<div class="box-body box-profile">
<div class="col-sm-2"></div>
<div class="col-sm-8">
<center>
<H4 align = "center">Welcome <?php echo $_SESSION['login_user']?></H4>
<!-- <h3>THe session level: <?php echo $_SESSION['sessionlevel']?></h3> -->
</p>
<div class="createtransactionbox">
<form action = "" method = "post">
<center>
<label><H3 align = "center">Transaction Details</H3></label>
<fieldset>
<!-- <legend>-->
<p>
Enter ItemName<input type="text" list="itemdrop" name = "itemlist" id="itemlist" autocomplete="off" placeholder="Enter Item Name" onchange="validate();" class="box"/><a id="item_error" style="color:red;"></a>
<datalist id="itemdrop">
<?php
$itemnamesql = mysqli_query($db_con, "SELECT DISTINCT itemname FROM item_t");
while($itemnamerow = $itemnamesql->fetch_assoc()){
?>
<option value="<?php echo $itemnamerow['itemname'];?>"><?php echo $itemnamerow['itemname']; ?></option>
<?php
}
?>
</datalist>
<!-- onchange="validate(); autofill(this.value); -->
<!-- Put them all like that and check if they are the same before running autofill -->
</p>
<p>
Confirm ItemName<input type="text" list="confirmdrop" name = "confirmlist" id="confirmlist" autocomplete="off" placeholder="Confirm Item Name" onchange="validate(); autofill(this.value);" class="box"/>
<datalist id="confirmdrop">
<?php
$itemnamesql = mysqli_query($db_con, "SELECT DISTINCT itemname FROM item_t");
while($itemnamerow = $itemnamesql->fetch_assoc()){
?>
<option value="<?php echo $itemnamerow['itemname'];?>"><?php echo $itemnamerow['itemname']; ?></option>
<?php
}
?>
</datalist>
</p>
<p>
Enter ItemID<input type="text" list="productdrop" name = "itemIDlist" id="itemIDlist" autocomplete="off" placeholder="Enter Item ID" class="box"/>
<datalist id=productdrop>
<option>Please Select the Product ID</option>
<?php
$itemsql = mysqli_query($db_con, "SELECT DISTINCT itemid FROM item_t");
while($itemrow = $itemsql->fetch_assoc()){
?>
<option value="<?php echo $itemrow['itemid'];?>"><?php echo $itemrow['itemid'];?></option>
<?php
}
?>
</datalist>
</p>
<p>
Enter Warehouse Out<input type="text" list="regiondrop" name = "regionlist" id="regionlist" autocomplete="off" placeholder="Enter Warehouse to move from" class="box"/>
<datalist id="regiondrop">
<?php
$regionsql = mysqli_query($db_con, "SELECT DISTINCT warehousename FROM warehouse_t");
while($regionrow = $regionsql->fetch_assoc()){
?>
<option value="<?php echo $regionrow['warehousename'];?>"><?php echo $regionrow['warehousename']; ?></option>
<?php
}
?>
</datalist>
</p>
<p>
Enter Warehouse In<input type="text" list="destinationdrop" name = "destinationlist" id="destinationlist" placeholder="Enter Warehouse to receive Item" onchange = "validatewarehouse(this.value);" class="box"/> <a id="warehouse_error" style="color:red;"></a>
<datalist id="destinationdrop">
<?php
$regionsql = mysqli_query($db_con, "SELECT DISTINCT warehousename FROM warehouse_t");
while($regionrow = $regionsql->fetch_assoc()){
?>
<option value="<?php echo $regionrow['warehousename'];?>"><?php echo $regionrow['warehousename']; ?></option>
<?php
}
?>
</datalist>
</p>
Enter Unit <input type="text" name="quantitylist" id="quantitylist" placeholder="Enter Item Unit" onchange="validateunit();" class="box"/> <a id="unit_error" style="color:red;"></a> <br>
Confirm Unit Again <input type="text" name="quantityconfirmlist" id="quantityconfirmlist" placeholder="Enter Item Unit" onchange="validateunit();" class="box"/> <br>
<p>
Select Unit size
<select name = "unitlist" id="unitlist" class="box"/>
<option> </option>
<option value="Sachet">Sachet</option>
<option value="Single Item">Single Item</option>
<option value="Pack">Pack</option>
<option value="Bag">Bag</option>
<option value="Bottle">Bottle</option>
</select>
</p>
Enter S&D Phone Number <input type="text" name="sdname1" placeholder="Enter S&D Phone Number (eg. +2348000000000)" class="box"/> <br>
Confirm S&D Phone Number <input type="text" name="sdname2" placeholder="Confirm S&D Phone Number (eg. +2348000000000)" class="box"/> <br>
SD Personnel Name <input type="text" name="sdpersonlist" id="sdpersonlist" placeholder="Enter the Name of the SD Personnel Handling this Transaction" class="box"/> <br>
Comments <input type="text" name="commentlist" id="commentlist" placeholder="Enter Comments" class="box"/> <br>
<input type = "submit" name = 'create' value = "Create Shipment" /><br/>
</center>
</form>
</div>
</div>
<div class="col-sm-2"></div>
</div>
</div>
</div>
</div>
<!-- /.post -->
</div>
<!-- /.post -->
</div>
<!-- /.tab-pane -->
</div>
<!-- /.tab-content -->
</div>
<!-- /.nav-tabs-custom -->
</div>
<!-- /.col -->
</div>
<!-- /.row -->
<!-- /.content -->
</div>
<!-- /.content-wrapper -->
<div class="footer">
<?php
//print "Today's date is " .date("Y-m-d");
?>
<!--
<h5><a href="logout.php" >Sign Out</a></h5>
</div>-->
<script>
function autofill(stringName){
var confirmname = document.getElementById('confirmlist').value;
var itemname = document.getElementById('itemlist').value;
if(confirmname == itemname){
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4){
document.getElementById('itemIDlist').value = xmlhttp.responseText;
}
}
xmlhttp.open("GET", "autofill.php?value=" +stringName, true);
xmlhttp.send();
}
}
function validate(){
var item = document.getElementById('itemlist');
var confirm = document.getElementById('confirmlist');
if(item.value != confirm.value){
document.getElementById('item_error').innerHTML = "Error: Item Names dont match";
//document.getElementById('confirm_error').innerHTML = "Error: Item Names dont match";
}else{
document.getElementById('item_error').innerHTML = "";
}
}
function autofillcustomer(stringClient){
var customer1 = document.getElementById('customerlist').value;
var customer2 = document.getElementById('customerconfirmlist').value;
if(customer1 == customer2){
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4){
document.getElementById('clientidlist').value = xmlhttp.responseText;
}
}
xmlhttp.open("GET", "autofillclient.php?client=" +stringClient, true);
xmlhttp.send();
}
}
function validateclient(){
var customer1 = document.getElementById('customerlist');
var customer2 = document.getElementById('customerconfirmlist');
if(customer1.value != customer2.value){
document.getElementById('client_error').innerHTML = "Error: Client Names dont match";
}else{
document.getElementById('client_error').innerHTML = "";
}
}
function validateunit(){
var unit1 = document.getElementById('quantitylist');
var unit2 = document.getElementById('quantityconfirmlist');
if(unit1.value != unit2.value){
document.getElementById('unit_error').innerHTML = "Error: Units don't match";
}else{
document.getElementById('unit_error').innerHTML = "";
}
}
function validatewarehouse(warehousename){
var warehousevalue = document.getElementById('destinationlist').value;
//document.getElementById('warehouse_error').innerHTML = "We have been run";
if("1" == "1"){
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4){
document.getElementById('warehouse_error').innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", "warehousevalidate.php?warehouse=" +warehousevalue, true);
xmlhttp.send();
}
}
</script>
<?php
if(isset($_POST['create'])){
$itemsql = mysqli_query($db_con, "SELECT * FROM transactions_preloaded ORDER BY RAND() LIMIT 1");
$itemrow = $itemsql->fetch_assoc();
$uniqueID = $itemrow['transaction_id'];
//echo "the unique: " .$uniqueID;
$myitemID = mysqli_real_escape_string($db_con, $_POST['itemIDlist']);
$myitem = mysqli_real_escape_string($db_con,$_POST['itemlist']);
$myconfirm = mysqli_real_escape_string($db_con,$_POST['confirmlist']);
$myregion = mysqli_real_escape_string($db_con,$_POST['regionlist']);
$mydestination = mysqli_real_escape_string($db_con,$_POST['destinationlist']);
$myunit = mysqli_real_escape_string($db_con,$_POST['unitlist']);
$myquantity = mysqli_real_escape_string($db_con,$_POST['quantitylist']);
$mysdpersonnel = mysqli_real_escape_string($db_con,$_POST['sdpersonlist']);
$mycomment = mysqli_real_escape_string($db_con,$_POST['commentlist']);
$mydate = date("Y-m-d");
$mystatus = 'pending';
$mysync = 'no';
$numbersql = mysqli_query($db_con, "SELECT pc_number FROM warehouse_t WHERE warehousename = '" .$mydestination. "'");
$numberrow = $numbersql->fetch_assoc();
$lessnumber = $numberrow['pc_number'];
$pcnumber = "+".$lessnumber;
//echo $pcnumber;
if(empty($_POST['itemIDlist']) || empty($_POST['itemlist']) || empty($_POST['confirmlist']) || empty($_POST['regionlist']) || empty($_POST['destinationlist']) || empty($_POST['unitlist']) || empty($_POST['quantitylist'])){
?>
<script type="text/javascript">
window.alert("Error: All inputs must be filled");
</script>
<?php
}else{
if($myitem != $myconfirm){
?>
<script type="text/javascript">
window.alert("Error: Both Item names must be the same");
</script>
<?php
}else{
$sql_insert = "INSERT INTO web_transactions (transactionID,itemId,item,region,destination,unit,quantity,date,personnelName,status,sdstatus,sdpersonnel,pcstatus,transaction_type,comments,sync) VALUES ('$uniqueID','$myitemID','$myitem','$myregion','$mydestination','$myunit','$myquantity','$mydate','".$_SESSION['login_user']."','$mystatus','pending','$mysdpersonnel','pending','Internal Shipment','$mycomment','$mysync')";
$result_insert = mysqli_query($db_con,$sql_insert);
if($result_insert){
$curl = curl_init();
$number = mysqli_real_escape_string($db_con, $_POST['sdname2']);
$from = "Inventory";
$text = "Internal Shipment,".$uniqueID.",".$myregion.",".$mydestination.",".$myitem.",".$myquantity.",".$myunit;
$url = "http://ngn.rmlconnect.net:8080/bulksms/bulksms?username=BabbanGona&password=K6kRuXKS&type=5&dlr=0&destination=".urlencode($number)."&source=".urlencode($from)."&message=".urlencode($text)."";
//$url = "https://www.example.com/file.php?phone=".urlencode($phone)."&message=".urlencode($message)."";
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
//echo $result;
curl_close($curl);
//Send text to the PC official.
$pc_curl = curl_init();
$from = "Inventory";
$text = "Internal Shipment,".$uniqueID.",".$myregion.",".$mydestination.",".$myitem.",".$myquantity.",".$myunit;
$url = "http://ngn.rmlconnect.net:8080/bulksms/bulksms?username=BabbanGona&password=K6kRuXKS&type=5&dlr=0&destination=".urlencode($pcnumber)."&source=".urlencode($from)."&message=".urlencode($text)."";
//$url = "https://www.example.com/file.php?phone=".urlencode($phone)."&message=".urlencode($message)."";
curl_setopt($pc_curl, CURLOPT_URL, $url);
curl_setopt($pc_curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($pc_curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($pc_curl);
//echo $result;
curl_close($pc_curl);
?>
<script type="text/javascript">
window.alert("Transaction has been created");
</script>
<?php
}
}
}
$deletesql = mysqli_query($db_con, "DELETE FROM transactions_preloaded WHERE transaction_id = '" .$uniqueID. "'");
if(!$deletesql){
die("Error: " .mysqli_error());
}else{
//print "They've been deleted" .$uniqueID;
}
}
?>
<?php
include 'adminfooter.php';
?>