ordersprinter/webapp/php/workreceipts.php

97 lines
2.9 KiB
PHP
Raw Normal View History

2020-11-19 23:03:48 +01:00
<?php
class Workreceipts {
public static function getNextWorkReceiptId($pdo) {
$sql = "SELECT value from %work% WHERE item=?";
$result = CommonUtils::fetchSqlAll($pdo, $sql, array('workid'));
$workid = 0;
if (count($result) == 0) {
$sql = "INSERT INTO %work% (item,value,signature) VALUES(?,?,?)";
CommonUtils::execSql($pdo, $sql, array("workid",0,null));
} else {
$workid = $result[0]['value'];
}
$nextid = intval($workid) + 1;
$sql = "UPDATE %work% SET value=? WHERE item=?";
CommonUtils::execSql($pdo, $sql, array($nextid,'workid'));
return $nextid;
}
public static function resetWorkReceiptId($pdo) {
$sql = "UPDATE %queue% SET printjobid=?";
CommonUtils::execSql($pdo, $sql, array(null));
$sql = "DELETE FROM %work% WHERE item=?";
CommonUtils::execSql($pdo, $sql, array('workid'));
}
public static function createCancelWorkReceipt($pdo,$queueid) {
$sql = "SELECT printjobid FROM %queue% WHERE id=?";
$result = CommonUtils::fetchSqlAll($pdo, $sql, array($queueid));
if (count($result) == 1) {
try {
$workid = Workreceipts::getNextWorkReceiptId($pdo);
$printjobid = $result[0]["printjobid"];
if (!is_null($printjobid)) {
$sql = "SELECT content,printer FROM %printjobs% WHERE id=?";
$row = CommonUtils::getRowSqlObject($pdo, $sql, array($printjobid));
$origJobJson = $row->content;
$printer = $row->printer;
$origJob = json_decode($origJobJson, true);
$refworkid = $origJob["workid"];
$table = $origJob["table"];
$time = $origJob["time"];
$products = $origJob["products"];
foreach ($products as $prod) {
$id = $prod["id"];
if ($id == $queueid) {
$kind = $prod["kind"];
$longname = $prod["longname"];
2020-11-19 23:10:35 +01:00
if (isset($prod["singleprod"])) {
$longname = $prod["singleprod"];
}
2020-11-19 23:03:48 +01:00
$price = $prod["price"];
$extrasArr = $prod["extras"];
$extrasStr = implode(",", $extrasArr);
$cancelJob = array(
"workid" => $workid,
"refworkid" => $refworkid,
"table" => $table,
"time" => $time,
"longname" => $longname,
"kind" => $kind,
"price" => $price,
"extras" => $extrasStr);
$cancelJobJson = json_encode($cancelJob);
$printInsertSql = "INSERT INTO `%printjobs%` (`id` , `content`,`type`,`printer`) VALUES ( NULL,?,?,?)";
$stmt = $pdo->prepare(DbUtils::substTableAlias($printInsertSql));
$type = PrintQueue::$CANCELFOOD;
if ($kind == 1) {
$type = PrintQueue::$CANCELDRINK;
}
$stmt->execute(array($cancelJobJson,$type,$printer));
$idOfWorkJob = $pdo->lastInsertId();
CommonUtils::log($pdo,"QUEUE","Create cancel work job with id=$idOfWorkJob for tableid $table of kind $kind for printer=$printer");
}
}
}
} catch (Exception $ex) {
$msg = $ex->getMessage();
return;
}
}
}
}