-
Notifications
You must be signed in to change notification settings - Fork 0
/
createOrder.php
73 lines (55 loc) · 2.92 KB
/
createOrder.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
<?php
//ALTER TABLE `orders` ADD `payment_place` INT NOT NULL AFTER `payment_status`;
//TER TABLE `orders` ADD `gstn` VARCHAR(255) NOT NULL AFTER `payment_place`;
require_once 'core.php';
$valid['success'] = array('success' => false, 'messages' => array(), 'order_id' => '');
// print_r($valid);
if($_POST) {
$orderDate = date('Y-m-d', strtotime($_POST['orderDate']));
$clientName = $_POST['clientName'];
$clientContact = $_POST['clientContact'];
$subTotalValue = $_POST['subTotalValue'];
$vatValue = $_POST['vatValue'];
$totalAmountValue = $_POST['totalAmountValue'];
$discount = $_POST['discount'];
$grandTotalValue = $_POST['grandTotalValue'];
$paid = $_POST['paid'];
$dueValue = $_POST['dueValue'];
$paymentType = $_POST['paymentType'];
$paymentStatus = $_POST['paymentStatus'];
$paymentPlace = $_POST['paymentPlace'];
$gstn = $_POST['gstn'];
$userid = $_SESSION['userId'];
$sql = "INSERT INTO orders (order_date, client_name, client_contact, sub_total, vat, total_amount, discount, grand_total, paid, due, payment_type, payment_status,payment_place, gstn,order_status,user_id) VALUES ('$orderDate', '$clientName', '$clientContact', '$subTotalValue', '$vatValue', '$totalAmountValue', '$discount', '$grandTotalValue', '$paid', '$dueValue', $paymentType, $paymentStatus,$paymentPlace,$gstn, 1,$userid)";
$order_id;
$orderStatus = false;
if($connect->query($sql) === true) {
$order_id = $connect->insert_id;
$valid['order_id'] = $order_id;
$orderStatus = true;
}
// echo $_POST['productName'];
$orderItemStatus = false;
for($x = 0; $x < count($_POST['productName']); $x++) {
$updateProductQuantitySql = "SELECT product.quantity FROM product WHERE product.product_id = ".$_POST['productName'][$x]."";
$updateProductQuantityData = $connect->query($updateProductQuantitySql);
while ($updateProductQuantityResult = $updateProductQuantityData->fetch_row()) {
$updateQuantity[$x] = $updateProductQuantityResult[0] - $_POST['quantity'][$x];
// update product table
$updateProductTable = "UPDATE product SET quantity = '".$updateQuantity[$x]."' WHERE product_id = ".$_POST['productName'][$x]."";
$connect->query($updateProductTable);
// add into order_item
$orderItemSql = "INSERT INTO order_item (order_id, product_id, quantity, rate, total, order_item_status)
VALUES ('$order_id', '".$_POST['productName'][$x]."', '".$_POST['quantity'][$x]."', '".$_POST['rateValue'][$x]."', '".$_POST['totalValue'][$x]."', 1)";
$connect->query($orderItemSql);
if($x == count($_POST['productName'])) {
$orderItemStatus = true;
}
} // while
} // /for quantity
$valid['success'] = true;
$valid['messages'] = "Successfully Added";
$connect->close();
echo json_encode($valid);
} // /if $_POST
// echo json_encode($valid);