-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.php
More file actions
44 lines (39 loc) · 1.8 KB
/
Copy pathapi.php
File metadata and controls
44 lines (39 loc) · 1.8 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
<?php
header("Content-Type: application/json"); // Set the content type to JSON
if ($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['KodeBarang'])) {
// Retrieve the value from the GET parameter
$KodeBarang = $_GET['KodeBarang'];
// Connect to the database
$serverName = "MODESERVER";
$connectionOptions = array("Database" => "MODECENTRE", "Uid" => "sa", "PWD" => "mode1234ABC");
$conn = sqlsrv_connect($serverName, $connectionOptions);
if ($conn) {
$sql = "SELECT T_STOK.ID, T_BARANG.KODEBRG, T_BARANG.NAMABRG, T_BARANG.ARTIKELBRG, T_BARANG.HGJUAL, T_BARANG.DISC, T_STOK.ST01, T_STOK.ST03
FROM T_BARANG
JOIN T_STOK ON T_BARANG.id = T_STOK.id
WHERE T_BARANG.KODEBRG = ?";
$stmt = sqlsrv_prepare($conn, $sql, array($KodeBarang));
if ($stmt) {
if (sqlsrv_execute($stmt)) {
$result = [];
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
$hargaNetto = $row['HGJUAL'] - ($row['HGJUAL'] * ($row['DISC'] / 100));
$row['HargaNetto'] = $hargaNetto;
$result[] = $row;
}
echo json_encode(["status" => "success", "data" => $result]);
} else {
echo json_encode(["status" => "error", "message" => "Error executing the SQL statement"]);
}
sqlsrv_free_stmt($stmt);
} else {
echo json_encode(["status" => "error", "message" => "Error preparing the SQL statement"]);
}
sqlsrv_close($conn);
} else {
echo json_encode(["status" => "error", "message" => "Error: Unable to connect to the database."]);
}
} else {
echo json_encode(["status" => "error", "message" => "Invalid request"]);
}
?>