$app = \Slim\Slim::getInstance();
$app->response()->header("Content-Type", "application/json");
$req = $app->request();
$reason = $req->params('reason');
$item = $req->params('item');
$pouchSKU = $req->params('pouchSKU');
$username = $req->params('username');
$bpSKU = $req->params('bpSKU');
//$req = $app->request();
//$body = json_decode($req->getBody());
if($item == "Pouch") {
$sql="
INSERT INTO health_ostomy_appliance_change (ChangeDate, Reason, ItemsChanged, PouchSKU,DateEntered,WhoEntered )
VALUES (DATE_ADD(NOW(),INTERVAL 3 HOUR), :reason, :item, pouchSKU,DATE_ADD(NOW(),INTERVAL 3 HOUR), :username);
INSERT INTO health_ostomy_stock (ProductSKU,ProductUnits,
DateEntered,WhoEntered )
VALUES (:pouchSKU,-1,DATE_ADD(NOW(),INTERVAL 3 HOUR),:username);
";
}
else {
$sql="
INSERT INTO health_ostomy_appliance_change (ChangeDate, Reason, ItemsChanged, BasePlateSKU, PouchSKU,DateEntered,WhoEntered )
VALUES (DATE_ADD(NOW(),INTERVAL 3 HOUR),:reason,:item,:bpSKU,:pouchSKU,DATE_ADD(NOW(),INTERVAL 3 HOUR),:username);
INSERT INTO health_ostomy_stock (ProductSKU,ProductUnits,
DateEntered,WhoEntered )
VALUES (:bpSKU,-1,DATE_ADD(NOW(),INTERVAL 3 HOUR),:username);
INSERT INTO health_ostomy_stock (ProductSKU,ProductUnits,
DateEntered,WhoEntered )
VALUES (:pouchSKU,-1,DATE_ADD(NOW(),INTERVAL 3 HOUR),:username);
";
}
echo $sql;
try {
$db = getConnection();
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
$stmt = $db->prepare($sql);
$stmt->bindParam("reason", $reason);
$stmt->bindParam("item", $item);
$stmt->bindParam("pouchSKU", $pouchSKU);
$stmt->bindParam("username", $username);
$stmt->bindParam("bpSKU", $bpSKU);
$result = $stmt->execute();
$dbCon = null;
// check if row inserted or not
if ($result) {
// successfully inserted into database
$response["success"] = 1;
$response["message"] = "Rows inserted successfully.";
// echoing JSON response
echo json_encode($response);
} else {
// failed to insert row
$response["success"] = 0;
$response["message"] = "Bad news bears. Rows inserted unsuccessfully";
// echoing JSON response
echo json_encode($response);
}
}
catch(PDOException $e) {
echo '{"error":{"text":'. $e->getMessage() .'}}';
}
}