|
|
|
@ -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";
|
|
|
|
|