-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.php
More file actions
116 lines (90 loc) · 3.63 KB
/
api.php
File metadata and controls
116 lines (90 loc) · 3.63 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
<?php
include('configTrumbullIndustries.php');
if (isset($_GET["getall"]) && $_SERVER['REQUEST_METHOD'] === 'GET') {
$sql = "SELECT * FROM `sample-data`";
$result = mysqli_query($conn, $sql);
$data = array();
while ($row = mysqli_fetch_assoc($result)) {
$data[] = $row;
}
echo json_encode($data);
}
if (isset($_GET["getbydate"]) && $_SERVER['REQUEST_METHOD'] === 'GET') {
$date = $_GET["getbydate"];
$sql = "SELECT * FROM `sample-data` where `INSTOCK LEADTIME` = '$date' ";
$result = mysqli_query($conn, $sql);
$data = array();
while ($row = mysqli_fetch_assoc($result)) {
$data[] = $row;
}
echo json_encode($data);
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Takes raw data from the request
$json = file_get_contents('php://input');
// Converts it into a PHP object
$data = json_decode($json, true);
$sku = $data['SKU'];
$tsi = $data['TSI'];
$vendor = $data['VENDOR'];
$brand = $data['BRAND'];
$shipping_template = $data['SHIPPING_TEMPLATE'];
$template_code = $data['TEMPLATE_CODE'];
$instock_leadtime = $data['INSTOCK_LEADTIME'];
$nostock_leadtime = $data['NOSTOCK_LEADTIME'];
$quantity = $data['QUANTITY'];
$obsolete = $data['OBSOLETE'];
$is_updated = $data['IS_UPDATED'];
$sql = "insert into `sample-data` (SKU,TSI,VENDOR,BRAND,`SHIPPING TEMPLATE`,`TEMPLATE CODE`,`INSTOCK LEADTIME`,
`NOSTOCK LEADTIME`,QUANTITY,OBSOLETE,`IS UPDATED`) values
('$sku','$tsi','$vendor','$brand','$shipping_template','$template_code','$instock_leadtime'
,'$nostock_leadtime','$quantity','$obsolete','$is_updated')";
mysqli_query($conn, $sql);
$id = mysqli_insert_id($conn);
$data["ID"] = $id;
echo json_encode($data);
}
if ($_SERVER['REQUEST_METHOD'] === 'PUT') {
// Takes raw data from the request
$json = file_get_contents('php://input');
// Converts it into a PHP object
$data = json_decode($json, true);
$id = $data['ID'];
$sku = $data['SKU'];
$tsi = $data['TSI'];
$vendor = $data['VENDOR'];
$brand = $data['BRAND'];
$shipping_template = $data['SHIPPING_TEMPLATE'];
$template_code = $data['TEMPLATE_CODE'];
$instock_leadtime = $data['INSTOCK_LEADTIME'];
$nostock_leadtime = $data['NOSTOCK_LEADTIME'];
$quantity = $data['QUANTITY'];
$obsolete = $data['OBSOLETE'];
$is_updated = $data['IS_UPDATED'];
$sql = "update `sample-data` set
SKU='$sku',
TSI='$tsi',
VENDOR='$vendor',
BRAND='$brand',
`SHIPPING TEMPLATE`='$shipping_template',
`TEMPLATE CODE`='$template_code',
`INSTOCK LEADTIME`='$instock_leadtime',
`NOSTOCK LEADTIME`='$nostock_leadtime',
QUANTITY='$quantity',
OBSOLETE='$obsolete',
`IS UPDATED`='$is_updated'
where ID='$id'";
mysqli_query($conn, $sql);
echo json_encode($data);
}
if ($_SERVER['REQUEST_METHOD'] === 'DELETE') {
// Takes raw data from the request
$json = file_get_contents('php://input');
// Converts it into a PHP object
$data = json_decode($json, true);
$id = $data['ID'];
include('configTrumbullIndustries.php');
$sql = "delete from `sample-data` where ID='$id'";
mysqli_query($conn, $sql);
echo json_encode($data);
}