Add functionality to delete transaction from db when editing, close #21
This commit is contained in:
parent
a4c9966c3f
commit
819ce856a4
46
action.php
46
action.php
@ -312,6 +312,52 @@ switch ($VARS['action']) {
|
|||||||
exit(json_encode(["status" => "OK", "txid" => $oktx]));
|
exit(json_encode(["status" => "OK", "txid" => $oktx]));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "delete_transaction":
|
||||||
|
header("Content-Type: application/json");
|
||||||
|
$error = null;
|
||||||
|
if (isset($VARS['txid']) && $database->has('transactions', ['txid' => $VARS['txid']])) {
|
||||||
|
$txid = $VARS['txid'];
|
||||||
|
$cashid = $database->get('transactions', 'cashid', ['txid' => $txid]);
|
||||||
|
if (!$database->has('cash_drawer', ['AND' => ['cashid' => $cashid, 'close' => null]])) {
|
||||||
|
$error = lang("cash already closed", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
$database->action(function ($database) {
|
||||||
|
global $VARS, $binstack, $error, $txid;
|
||||||
|
|
||||||
|
// Delete payments
|
||||||
|
$payments = $database->select('payments', ['payid', 'amount', 'type', 'certid'], ['txid' => $txid]);
|
||||||
|
foreach ($payments as $p) {
|
||||||
|
// Reset gift card balances
|
||||||
|
if (!is_null($p['certid'])) {
|
||||||
|
$database->update('certificates', ['amount[+]' => $p['amount']], ['certid' => $p['certid']]);
|
||||||
|
}
|
||||||
|
$database->delete('payments', ['payid' => $p['payid']]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete items/lines
|
||||||
|
$items = $database->select('lines', ['itemid (id)', 'qty', 'lineid'], ['txid' => $txid]);
|
||||||
|
foreach ($items as $i) {
|
||||||
|
$database->delete('lines', ['lineid' => $i['lineid']]);
|
||||||
|
$binstack->update('items', [
|
||||||
|
'qty[+]' => $i['qty']
|
||||||
|
], [
|
||||||
|
'itemid' => $i['id']
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete transaction
|
||||||
|
$database->delete('transactions', ['txid' => $txid, 'LIMIT' => 1]);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$error = lang("invalid parameters", false);
|
||||||
|
}
|
||||||
|
if (!is_null($error)) {
|
||||||
|
exit(json_encode(["status" => "ERROR", "message" => $error]));
|
||||||
|
} else {
|
||||||
|
exit(json_encode(["status" => "OK"]));
|
||||||
|
}
|
||||||
|
break;
|
||||||
case "getreceipt":
|
case "getreceipt":
|
||||||
require_once __DIR__ . "/lib/generatereceipt.php";
|
require_once __DIR__ . "/lib/generatereceipt.php";
|
||||||
$format = "html";
|
$format = "html";
|
||||||
|
@ -58,7 +58,24 @@ function recalculate() {
|
|||||||
|
|
||||||
$("#deletetxbtn").click(function () {
|
$("#deletetxbtn").click(function () {
|
||||||
bsalert("Confirm", "Really delete transaction?", "Yes", "No", function () {
|
bsalert("Confirm", "Really delete transaction?", "Yes", "No", function () {
|
||||||
window.location.href = "app.php?page=pos";
|
if ($("#txid").length) {
|
||||||
|
$.post("action.php", {
|
||||||
|
action: "delete_transaction",
|
||||||
|
txid: $("#txid").val()
|
||||||
|
}, function (data) {
|
||||||
|
console.log(data);
|
||||||
|
console.log(data.status == "OK");
|
||||||
|
if (data.status == "OK") {
|
||||||
|
window.location.href = "app.php?page=pos";
|
||||||
|
} else {
|
||||||
|
bsalert("Error", data.message);
|
||||||
|
}
|
||||||
|
}).fail(function () {
|
||||||
|
bsalert("Error", "An unknown error occurred.");
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
window.location.href = "app.php?page=pos";
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user