ソースを参照

Add functionality to delete transaction from db when editing, close #21

master
Skylar Ittner 1年前
コミット
819ce856a4
2個のファイルの変更64行の追加1行の削除
  1. 46
    0
      action.php
  2. 18
    1
      static/js/pos.js

+ 46
- 0
action.php ファイルの表示

@@ -312,6 +312,52 @@ switch ($VARS['action']) {
exit(json_encode(["status" => "OK", "txid" => $oktx]));
}
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":
require_once __DIR__ . "/lib/generatereceipt.php";
$format = "html";

+ 18
- 1
static/js/pos.js ファイルの表示

@@ -58,7 +58,24 @@ function recalculate() {

$("#deletetxbtn").click(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";
}
});
});


読み込み中…
キャンセル
保存