2020-11-19 22:47:44 +01:00
< ? php
require_once ( 'dbutils.php' );
require_once ( 'products.php' );
require_once ( 'commonutils.php' );
require_once ( 'printqueue.php' );
require_once ( 'utilities/userrights.php' );
class QueueContent {
var $dbutils ;
var $commonUtils ;
var $userrights ;
public static $lastSettingOfDisplayMode = 'all' ;
function __construct () {
$this -> dbutils = new DbUtils ();
$this -> commonUtils = new CommonUtils ();
$this -> userrights = new Userrights ();
}
function handleCommand ( $command ) {
2020-11-19 22:59:47 +01:00
header ( " Cache-Control: no-store, no-cache, must-revalidate, max-age=0 " );
header ( " Cache-Control: post-check=0, pre-check=0 " , false );
header ( " Pragma: no-cache " );
2020-11-19 22:47:44 +01:00
if ( $command == " getJsonTableNameFromId " ) {
$this -> getJsonTableNameFromId ( $_GET [ 'tableid' ]);
return ;
}
// these command are only allowed for user with supply rights
2020-11-19 22:59:47 +01:00
$cmdArray = array ( 'getJsonAllPreparedProducts' , 'getJsonLastDeliveredProducts' , 'declareProductBeDelivered' , 'declareMultipleProductsDelivered' , 'declareProductNotBeDelivered' );
2020-11-19 22:47:44 +01:00
if ( in_array ( $command , $cmdArray )) {
if ( ! ( $this -> userrights -> hasCurrentUserRight ( 'right_supply' ))) {
echo " Benutzerrechte nicht ausreichend! " ;
return false ;
}
}
// these command are only allowed for user with kitchen or bar rights
$cmdArray = array ( 'declareProductBeCookingOrCooked' , 'declareProductNOTBeCooked' );
2020-11-19 22:59:47 +01:00
if ( in_array ( $command , $cmdArray )) {
if ( ! ( $this -> userrights -> hasCurrentUserRight ( 'right_kitchen' )) && ! ( $this -> userrights -> hasCurrentUserRight ( 'right_bar' ))) {
echo " Benutzerrechte nicht ausreichend! " ;
return false ;
}
2020-11-19 22:47:44 +01:00
}
// these command are only allowed for user with waiter rights
2020-11-19 22:59:47 +01:00
$cmdArray = array ( 'addProductListToQueue' , 'removeProductFromQueue' , 'changeTable' , 'getProdsForTableChange' );
if ( in_array ( $command , $cmdArray )) {
if ( ! ( $this -> userrights -> hasCurrentUserRight ( 'right_waiter' ))) {
echo " Benutzerrechte nicht ausreichend! " ;
return false ;
}
2020-11-19 22:47:44 +01:00
}
2020-11-19 22:59:47 +01:00
// these command are only allowed for user with paydesk rights
$cmdArray = array ( 'getJsonProductsOfTableToPay' , 'declarePaidCreateBillReturnBillId' );
if ( in_array ( $command , $cmdArray )) {
2020-11-19 22:47:44 +01:00
if ( ! ( $this -> userrights -> hasCurrentUserRight ( 'right_paydesk' ))) {
2020-11-19 22:59:47 +01:00
echo json_encode ( array ( " status " => " ERROR " , " code " => ERROR_PAYDESK_NOT_AUTHOTRIZED , " msg " => ERROR_PAYDESK_NOT_AUTHOTRIZED_MSG ));
return false ;
}
2020-11-19 22:47:44 +01:00
}
if ( $command == 'addProductListToQueue' ) {
$this -> addProductListToQueue ( $_POST [ " tableid " ], $_POST [ " prods " ], $_POST [ " print " ], $_POST [ " payprinttype " ]);
} else if ( $command == 'kitchenToCook' ) {
$this -> kitchenToCook ();
} else if ( $command == 'declareProductBeCookingOrCooked' ) {
$this -> declareProductBeCookingOrCooked ( $_POST [ 'queueid' ], $_POST [ 'action' ]);
} else if ( $command == 'declareProductNotBeCooked' ) {
$this -> declareProductNotBeCooked ( $_POST [ 'queueid' ]);
} else if ( $command == 'showProductsOfTableToPay' ) {
$this -> showProductsOfTableToPay ( $_GET [ 'tableid' ]);
} else if ( $command == 'getJsonAllPreparedProducts' ) {
$this -> getJsonAllPreparedProducts ();
} else if ( $command == 'declareProductBeDelivered' ) {
$this -> declareProductBeDelivered ( $_POST [ 'queueid' ]);
} else if ( $command == 'declareMultipleProductsDelivered' ) {
$this -> declareMultipleProductsDelivered ( $_POST [ 'queueids' ]);
} else if ( $command == 'declareProductNotBeDelivered' ) {
$this -> declareProductNotBeDelivered ( $_POST [ 'queueid' ]);
} else if ( $command == 'getJsonLongNamesOfProdsForTableNotDelivered' ) {
$this -> getJsonLongNamesOfProdsForTableNotDelivered ( $_GET [ " tableid " ]);
2020-11-19 22:55:43 +01:00
} else if ( $command == 'getUnpaidTables' ) {
$this -> getUnpaidTables ();
2020-11-19 22:50:09 +01:00
} else if ( $command == 'getProdsForTableChange' ) {
$this -> getProdsForTableChange ( $_GET [ 'tableId' ]);
2020-11-19 22:47:44 +01:00
} else if ( $command == 'changeTable' ) {
2020-11-19 22:50:09 +01:00
$this -> changeTable ( $_POST [ 'fromTableId' ], $_POST [ 'toTableId' ], $_POST [ 'queueids' ]);
2020-11-19 22:47:44 +01:00
} else if ( $command == 'removeProductFromQueue' ) {
$this -> removeProductFromQueue ( $_POST [ " queueid " ], $_POST [ " isPaid " ], $_POST [ " isCooking " ], $_POST [ " isReady " ]);
} else if ( $command == 'getJsonAllQueueItemsToMake' ) {
$this -> getJsonAllQueueItemsToMake ( intval ( $_GET [ " kind " ]));
} else if ( $command == 'getJsonLastMadeItems' ) {
$this -> getJsonLastMadeItems ( intval ( $_GET [ " kind " ]));
} else if ( $command == 'getJsonLastDeliveredProducts' ) {
$this -> getJsonLastDeliveredProducts ();
} else if ( $command == 'getJsonProductsOfTableToPay' ) {
$this -> getJsonProductsOfTableToPay ( $_GET [ 'tableid' ]);
} else if ( $command == 'declarePaidCreateBillReturnBillId' ) {
2020-11-19 23:00:55 +01:00
$pdo = DbUtils :: openDbAndReturnPdoStatic ();
2020-11-19 23:00:58 +01:00
$this -> declarePaidCreateBillReturnBillId ( $pdo , $_POST [ 'ids' ], $_POST [ 'tableid' ], $_POST [ 'paymentid' ], $_POST [ 'declareready' ], $_POST [ 'host' ], false , $_POST [ 'reservationid' ], $_POST [ 'guestinfo' ]);
2020-11-19 22:47:44 +01:00
} else {
echo " Command not supported. " ;
2020-11-19 22:59:47 +01:00
}
2020-11-19 22:47:44 +01:00
}
2020-11-19 23:00:58 +01:00
2020-11-19 23:00:55 +01:00
private static function setNewProductsToServe ( $pdo , $val ) {
$sql = " SELECT count(id) as countid FROM %work% WHERE item=? " ;
$row = CommonUtils :: getRowSqlObject ( $pdo , $sql , array ( " newproductstoserve " ));
if ( $row -> countid == 0 ) {
$sql = " INSERT INTO %work% (item,value,signature) VALUES (?,?,?) " ;
CommonUtils :: execSql ( $pdo , $sql , array ( " newproductstoserve " , $val , null ));
} else {
$sql = " UPDATE %work% SET value=? WHERE item=? " ;
CommonUtils :: execSql ( $pdo , $sql , array ( $val , " newproductstoserve " ));
}
}
private static function getNewProductsToServe ( $pdo ) {
$sql = " SELECT count(id) as countid FROM %work% WHERE item=? " ;
$row = CommonUtils :: getRowSqlObject ( $pdo , $sql , array ( " newproductstoserve " ));
if ( $row -> countid == 0 ) {
return 0 ;
} else {
$sql = " SELECT value FROM %work% WHERE item=? " ;
$row = CommonUtils :: getRowSqlObject ( $pdo , $sql , array ( " newproductstoserve " ));
return $row -> value ;
}
}
2020-11-19 22:47:44 +01:00
function getJsonTableNameFromId ( $tableid ) {
2020-11-19 22:54:51 +01:00
$pdo = DbUtils :: openDbAndReturnPdoStatic ();
$commonUtils = new CommonUtils ();
echo json_encode ( $commonUtils -> getTableNameFromId ( $pdo , $tableid ));
2020-11-19 22:47:44 +01:00
}
function getUserName ( $userid ) {
2020-11-19 22:59:47 +01:00
$pdo = $this -> dbutils -> openDbAndReturnPdo ();
$sql = " SELECT username FROM %user% WHERE id=? " ;
2020-11-19 23:00:55 +01:00
$row = CommonUtils :: getRowSqlObject ( $pdo , $sql , array ( $userid ));
2020-11-19 22:59:47 +01:00
if ( $row != null ) {
2020-11-19 22:47:44 +01:00
return ( $row -> username );
} else {
return " " ;
}
}
private function areBillExisting ( $pdo ) {
$sql = " SELECT count(id) as countid FROM %bill% " ;
2020-11-19 23:00:55 +01:00
$row = CommonUtils :: getRowSqlObject ( $pdo , $sql , null );
2020-11-19 22:47:44 +01:00
$count = intval ( $row -> countid );
if ( $count > 0 ) {
return true ;
} else {
return false ;
}
}
/*
* Get the queue items for the kitchen view that have to be still be cooked
* as a json element array
*
* 1. It is sorted for ordertime
* 2. From this ordertime search for the distinct tables
* 3. Sort it that way that tables are grouped together
*
* $kind = 0 -> return only food elements , = 1 -> return drinks
*/
private function getJsonAllQueueItemsToMake ( $kind ) {
2020-11-19 22:59:47 +01:00
// current time
date_default_timezone_set ( DbUtils :: getTimeZone ());
2020-11-19 22:47:44 +01:00
$currentTime = date ( 'Y-m-d H:i:s' );
$pdo = $this -> dbutils -> openDbAndReturnPdo ();
// first sort all non-ready products ordered by ordertime
if ( $this -> areBillExisting ( $pdo )) {
$sql = " SELECT DISTINCT %queue%.id as id,%resttables%.id as tableid,tablenr,longname,anoption,tableno,date_format(ordertime,'%Y-%m-%d %H:%i:00') as ordertime,cooking,TIMESTAMPDIFF(MINUTE,ordertime,?) AS waittime FROM %queue%,%products%,%prodtype%,%resttables%,%bill% " ;
} else {
$sql = " SELECT DISTINCT %queue%.id as id,%resttables%.id as tableid,tablenr,longname,anoption,tableno,date_format(ordertime,'%Y-%m-%d %H:%i:00') as ordertime,cooking,TIMESTAMPDIFF(MINUTE,ordertime,?) AS waittime FROM %queue%,%products%,%prodtype%,%resttables% " ;
}
2020-11-19 23:00:46 +01:00
$sql .= " WHERE (readytime IS NULL AND " ;
2020-11-19 22:47:44 +01:00
$sql .= " ordertime is not null AND " ;
$sql .= " %queue%.productid=%products%.id AND " ;
$sql .= " %queue%.tablenr = %resttables%.id AND " ;
$sql .= " %products%.category=%prodtype%.id AND " ;
$sql .= " %prodtype%.kind=? AND " ;
2020-11-19 22:50:09 +01:00
$sql .= " %queue%.isclosed is null AND " ;
2020-11-19 22:47:44 +01:00
$sql .= " %queue%.workprinted='0') " ;
if ( $this -> areBillExisting ( $pdo )) {
// now remove closed items
$sql .= " AND (%queue%.billid is null OR ( " ;
$sql .= " %queue%.billid=%bill%.id AND %bill%.closingid is null)) " ;
}
$sql .= " ORDER BY ordertime,longname,anoption,cooking DESC,%queue%.id " ;
$stmt = $pdo -> prepare ( DbUtils :: substTableAlias ( $sql ));
$stmt -> execute ( array ( $currentTime , $kind ));
$result1 = $stmt -> fetchAll ();
2020-11-19 23:00:05 +01:00
$sql = " SELECT DISTINCT q.id as id,'-' as tableid,'-' as tablenr,longname,anoption,'-' as tableno,date_format(ordertime,'%Y-%m-%d %H:%i:00') as ordertime,cooking,TIMESTAMPDIFF(MINUTE,ordertime,?) AS waittime FROM %products%,%prodtype%,%resttables%, %queue% q LEFT OUTER JOIN %bill% b " ;
$sql .= " ON q.billid=b.id " ;
2020-11-19 23:00:46 +01:00
$sql .= " WHERE (readytime IS NULL AND " ;
2020-11-19 22:47:44 +01:00
$sql .= " ordertime is not null AND " ;
2020-11-19 23:00:05 +01:00
$sql .= " q.productid=%products%.id AND " ;
$sql .= " q.tablenr is null AND " ;
2020-11-19 22:47:44 +01:00
$sql .= " %products%.category=%prodtype%.id AND " ;
$sql .= " %prodtype%.kind=? AND " ;
2020-11-19 23:00:05 +01:00
$sql .= " q.isclosed is null AND " ;
$sql .= " q.workprinted='0') " ;
$sql .= " AND (q.billid is null OR ( " ;
$sql .= " b.closingid is null)) " ;
2020-11-19 22:47:44 +01:00
$sql .= " ORDER BY ordertime,longname,anoption,cooking DESC " ;
$stmt = $pdo -> prepare ( DbUtils :: substTableAlias ( $sql ));
$stmt -> execute ( array ( $currentTime , $kind ));
$result2 = $stmt -> fetchAll ();
$result = array_merge ( $result1 , $result2 );
$resultarray = array ();
foreach ( $result as $zeile ) {
$waitTime = $zeile [ 'waittime' ];
$cook = $zeile [ 'cooking' ];
if ( is_null ( $cook )) {
$cook = 0 ;
}
$arr = array ( " id " => $zeile [ 'id' ],
" tableid " => $zeile [ 'tableid' ],
" tablenr " => $zeile [ 'tableno' ],
" longname " => $zeile [ 'longname' ],
" option " => $zeile [ 'anoption' ],
" cooking " => $cook ,
" waittime " => $waitTime
);
$resultarray [] = $arr ;
}
$tablearray = array ();
$insertedTables = array ();
$table = ( - 1 );
if ( count ( $resultarray ) <> 0 ) {
for ( $queue_index = 0 ; $queue_index < count ( $resultarray ); $queue_index ++ ) {
$aTable = $resultarray [ $queue_index ][ 'tablenr' ];
if (( $table <> $aTable ) && ! in_array ( $aTable , $insertedTables )) {
// sort all entries for this table
$table = $aTable ;
$tableid = $resultarray [ $queue_index ][ 'tableid' ];
$maxWaitTime = $resultarray [ $queue_index ][ 'waittime' ];
$tableArr = array ();
for ( $i = 0 ; $i < count ( $resultarray ); $i ++ ) {
if ( $resultarray [ $i ][ 'tablenr' ] == $table ) {
$foundItem = $resultarray [ $i ];
$waittimeofentry = intval ( $foundItem [ 'waittime' ]);
// icons of waittime
// 1-20 in 1 min steps
// 25,30,40,50,60min
$waitIconMinStep = 1 ;
if ( $waittimeofentry <= 1 ) {
$waitIconMinStep = 1 ;
} else if ( $waittimeofentry <= 20 ) {
$waitIconMinStep = strval ( $waittimeofentry );
} else if ( $waittimeofentry <= 25 ) {
$waitIconMinStep = 25 ;
} else if ( $waittimeofentry <= 30 ) {
$waitIconMinStep = 30 ;
} else if ( $waittimeofentry <= 40 ) {
$waitIconMinStep = 40 ;
} else if ( $waittimeofentry <= 50 ) {
$waitIconMinStep = 50 ;
} else {
$waitIconMinStep = 60 ;
}
$waitIconMinStep = $waitIconMinStep . 'min.png' ;
$extras = $this -> getExtrasOfQueueItem ( $pdo , $foundItem [ 'id' ]);
$anEntryForThisTable = array ( " id " => $foundItem [ 'id' ],
" longname " => $foundItem [ 'longname' ],
" option " => $foundItem [ 'option' ],
" extras " => $extras ,
" cooking " => $this -> getUserName ( $foundItem [ 'cooking' ]),
" waiticon " => $waitIconMinStep ,
" waittime " => $waittimeofentry
);
$tableArr [] = $anEntryForThisTable ;
}
}
// Now fit max wait time of table to entry wait time steps:
if (( $maxWaitTime > 20 ) && ( $maxWaitTime < 60 )) {
if ( $maxWaitTime >= 50 ) {
$maxWaitTime = " > 50 " ;
} else if ( $maxWaitTime >= 40 ) {
$maxWaitTime = " > 40 " ;
} else if ( $maxWaitTime >= 30 ) {
$maxWaitTime = " > 30 " ;
} else if ( $maxWaitTime >= 25 ) {
$maxWaitTime = " > 25 " ;
} else {
$maxWaitTime = " > 20 " ;
}
} else if ( $maxWaitTime <= 1 ) {
$maxWaitTime = " 1 " ;
}
$tablearray [] = array ( " table " => $table , " tableid " => $tableid , " count " => count ( $tableArr ), " queueitems " => $tableArr , " maxwaittime " => $maxWaitTime );
$insertedTables [] = $aTable ;
}
}
}
echo json_encode ( $tablearray );
}
private function getExtrasOfQueueItem ( $pdo , $queueid ) {
if ( is_null ( $pdo )) {
$pdo = $this -> dbutils -> openDbAndReturnPdo ();
}
$sql = " SELECT name FROM %queueextras% WHERE queueid=? " ;
$stmt = $pdo -> prepare ( $this -> dbutils -> resolveTablenamesInSqlString ( $sql ));
$stmt -> execute ( array ( $queueid ));
$extras = $stmt -> fetchAll ();
$extrasarr = array ();
foreach ( $extras as $anExtra ) {
$extrasarr [] = $anExtra [ " name " ];
}
return $extrasarr ;
}
2020-11-19 22:58:27 +01:00
private function getExtrasWithIdsOfQueueItem ( $pdo , $queueid ) {
if ( is_null ( $pdo )) {
$pdo = $this -> dbutils -> openDbAndReturnPdo ();
}
$sql = " SELECT name,extraid FROM %queueextras% WHERE queueid=? " ;
$stmt = $pdo -> prepare ( $this -> dbutils -> resolveTablenamesInSqlString ( $sql ));
$stmt -> execute ( array ( $queueid ));
$extras = $stmt -> fetchAll ();
$extrasnames = array ();
$extrasids = array ();
foreach ( $extras as $anExtra ) {
$extrasnames [] = $anExtra [ " name " ];
$extrasids [] = $anExtra [ " extraid " ];
}
return array ( " extrasnames " => $extrasnames , " extrasids " => $extrasids );
}
2020-11-19 22:47:44 +01:00
private function getJobsToPrint ( $pdo , $kind , $printer , $queueIds ) {
if ( is_null ( $queueIds ) || ( count ( $queueIds ) == 0 )) {
return array ();
}
$queueStr = implode ( ',' , $queueIds );
2020-11-19 22:53:50 +01:00
$sql = " SELECT setting FROM %config% where name=? " ;
2020-11-19 23:00:55 +01:00
$row = CommonUtils :: getRowSqlObject ( $pdo , $sql , array ( 'groupworkitems' ));
2020-11-19 22:53:50 +01:00
$groupworkitems = $row -> setting ;
if ( is_null ( $groupworkitems )) {
$groupworkitems = 1 ;
}
2020-11-19 23:00:52 +01:00
$sql = " SELECT %queue%.id as id,%queue%.tablenr as tableid, %queue%.productid,%queue%.productname as longname,anoption,%prodtype%.kind as kind,%prodtype%.printer as printer FROM %queue%,%products%,%prodtype% WHERE %prodtype%.kind=? AND %queue%.id IN ( $queueStr ) AND productid=%products%.id AND %products%.category=%prodtype%.id ORDER BY longname " ;
2020-11-19 22:47:44 +01:00
$stmt = $pdo -> prepare ( DbUtils :: substTableAlias ( $sql ));
$stmt -> execute ( array ( $kind ));
$queueItems = $stmt -> fetchAll ();
$jobs = array ();
foreach ( $queueItems as $aQueueItem ) {
// is the job for that printer?
$thePrinter = $aQueueItem [ " printer " ];
$queueid = $aQueueItem [ " id " ];
$tableid = $aQueueItem [ " tableid " ];
if ( ! is_null ( $tableid ) && ( $tableid != 0 )) {
$sql = " SELECT DISTINCT %room%.printer as printer FROM %queue%,%resttables%,%room% WHERE %resttables%.id=? AND %resttables%.roomid=%room%.id LIMIT 1 " ;
2020-11-19 23:00:55 +01:00
$row = CommonUtils :: getRowSqlObject ( $pdo , $sql , array ( $tableid ));
2020-11-19 22:47:44 +01:00
$roomPrinter = $row -> printer ;
if ( ! is_null ( $roomPrinter )) {
$thePrinter = $roomPrinter ;
}
}
if ( $thePrinter == $printer ) {
$extras = $this -> getExtrasOfQueueItem ( $pdo , $queueid );
$theEntry = array (
" id " => $queueid ,
" productid " => $aQueueItem [ " productid " ],
" longname " => $aQueueItem [ " longname " ],
" anoption " => $aQueueItem [ " anoption " ],
" kind " => $aQueueItem [ " kind " ],
" printer " => $aQueueItem [ " printer " ],
" extras " => $extras
);
2020-11-19 22:53:50 +01:00
if ( $groupworkitems ) {
$this -> grouping ( $jobs , $theEntry );
} else {
$jobs [] = $theEntry ;
}
}
}
if ( $groupworkitems ) {
2020-11-19 23:00:55 +01:00
// now put the count number into the longname
2020-11-19 22:53:50 +01:00
foreach ( $jobs as & $aJob ) {
$cnt = $aJob [ " count " ];
2020-11-19 23:00:55 +01:00
$aJob [ " longname " ] = $cnt . " x " . $aJob [ " longname " ];
2020-11-19 22:47:44 +01:00
}
}
return $jobs ;
}
2020-11-19 22:53:50 +01:00
private function grouping ( & $collection , $entry ) {
$extrasTxt = join ( " , " , $entry [ " extras " ]);
$found = false ;
foreach ( $collection as & $anEntry ) {
if (( $anEntry [ " longname " ] == $entry [ " longname " ]) && ( $anEntry [ " anoption " ] == $entry [ " anoption " ]) && ( join ( " , " , $anEntry [ " extras " ]) == $extrasTxt )) {
$found = true ;
$anEntry [ " count " ] = $anEntry [ " count " ] + 1 ;
}
}
if ( ! $found ) {
$collection [] = array ( " id " => $entry [ " id " ],
" productid " => $entry [ " productid " ],
" longname " => $entry [ " longname " ],
" printer " => $entry [ " printer " ],
" anoption " => $entry [ " anoption " ],
" kind " => $entry [ " kind " ],
" extras " => $entry [ " extras " ],
" count " => 1
);
}
}
2020-11-19 23:00:05 +01:00
private function doWorkPrint ( $pdo , $theTableid , $insertedQueueIds , $username , $payPrintType , $lang , $declareReadyDelivered = true ) {
$oneProdForEachWorkRec = CommonUtils :: getConfigValue ( $pdo , 'oneprodworkreceipts' , 0 );
if (( $payPrintType != " s " ) || ( $oneProdForEachWorkRec == 0 )) {
return ( $this -> doWorkPrintCore ( $pdo , $theTableid , $insertedQueueIds , $username , $payPrintType , $lang , $declareReadyDelivered ));
}
$oneProdForEachWorkRec = CommonUtils :: getConfigValue ( $pdo , 'oneprodworkreceipts' , 0 );
if ( $oneProdForEachWorkRec == 1 ) {
foreach ( $insertedQueueIds as $aQueueId ) {
$this -> doWorkPrintCore ( $pdo , $theTableid , array ( $aQueueId ), $username , $payPrintType , $lang , $declareReadyDelivered );
}
}
}
2020-11-19 22:53:50 +01:00
2020-11-19 23:00:05 +01:00
private function doWorkPrintCore ( $pdo , $theTableid , $insertedQueueIds , $username , $payPrintType , $lang , $declareReadyDelivered = true ) {
2020-11-19 22:47:44 +01:00
// is it server or local print?
2020-11-19 22:56:12 +01:00
2020-11-19 22:47:44 +01:00
$foodJobsPrinter1 = $this -> getJobsToPrint ( $pdo , 0 , 1 , $insertedQueueIds );
$foodJobsPrinter2 = $this -> getJobsToPrint ( $pdo , 0 , 2 , $insertedQueueIds );
$drinkJobsPrinter1 = $this -> getJobsToPrint ( $pdo , 1 , 1 , $insertedQueueIds );
$drinkJobsPrinter2 = $this -> getJobsToPrint ( $pdo , 1 , 2 , $insertedQueueIds );
2020-11-19 23:00:05 +01:00
if ( $payPrintType == " s " ) {
2020-11-19 22:47:44 +01:00
$this -> createAWorkReceiptAndQueueWorkPrint ( $pdo , $foodJobsPrinter1 , $theTableid , 0 , 1 , $username , $lang );
$this -> createAWorkReceiptAndQueueWorkPrint ( $pdo , $foodJobsPrinter2 , $theTableid , 0 , 2 , $username , $lang );
$this -> createAWorkReceiptAndQueueWorkPrint ( $pdo , $drinkJobsPrinter1 , $theTableid , 1 , 1 , $username , $lang );
2020-11-19 23:00:39 +01:00
$this -> createAWorkReceiptAndQueueWorkPrint ( $pdo , $drinkJobsPrinter2 , $theTableid , 1 , 2 , $username , $lang );
2020-11-19 22:47:44 +01:00
}
2020-11-19 23:00:05 +01:00
if ( $declareReadyDelivered ) {
2020-11-19 23:00:55 +01:00
$printAndQueueJobs = CommonUtils :: getConfigValue ( $pdo , " printandqueuejobs " , 0 );
if ( $printAndQueueJobs == 0 ) {
$this -> declareReadyAndDelivered ( $pdo , $insertedQueueIds );
}
2020-11-19 23:00:05 +01:00
}
2020-11-19 22:56:12 +01:00
2020-11-19 22:47:44 +01:00
$result = array_merge ( $foodJobsPrinter1 , $foodJobsPrinter2 , $drinkJobsPrinter1 , $drinkJobsPrinter2 );
return $result ;
}
2020-11-19 22:56:12 +01:00
private function declareReadyAndDelivered ( $pdo , $queueids ) {
date_default_timezone_set ( DbUtils :: getTimeZone ());
$now = date ( 'Y-m-d H:i:s' );
$germanTime = date ( 'H:i' );
$sql = " UPDATE %queue% SET workprinted='1',readytime=?,delivertime=? WHERE id=? " ;
$stmt = $pdo -> prepare ( DbUtils :: substTableAlias ( $sql ));
foreach ( $queueids as $anId ) {
$stmt -> execute ( array ( $now , $now , $anId ));
}
}
2020-11-19 22:47:44 +01:00
private function createAWorkReceiptAndQueueWorkPrint ( $pdo , $jobs , $theTableid , $kind , $printer , $user , $lang ) {
if ( count ( $jobs ) < 1 ) {
return ;
}
date_default_timezone_set ( DbUtils :: getTimeZone ());
$germanTime = date ( 'H:i' );
$resultarray = array ();
foreach ( $jobs as $aJob ) {
$queueId = $aJob [ " id " ];
$extras = $this -> getExtrasOfQueueItem ( $pdo , $queueId );
$arr = array ( " id " => $queueId ,
" longname " => $aJob [ 'longname' ],
" option " => $aJob [ 'anoption' ],
" extras " => $extras ,
" ordertime " => $germanTime ,
" kind " => $kind ,
" printer " => $printer
);
$resultarray [] = $arr ;
}
if ( is_null ( $theTableid ) || ( $theTableid == 0 )) {
$takeAwayStr = array ( " Zum Mitnehmen " , " Take away " , " Para llevar " );
$tablename = $takeAwayStr [ $lang ];
} else {
2020-11-19 22:55:09 +01:00
$sql = " SELECT tableno,%room%.abbreviation FROM %resttables%,%room% WHERE %resttables%.id=? AND %resttables%.roomid=%room%.id " ;
2020-11-19 23:00:55 +01:00
$row = CommonUtils :: getRowSqlObject ( $pdo , $sql , array ( $theTableid ));
2020-11-19 22:47:44 +01:00
2020-11-19 22:55:09 +01:00
if ( is_null ( $row -> abbreviation )) {
$tablename = $row -> tableno ;
} else {
$tablename = $row -> abbreviation . " - " . $row -> tableno ;
}
2020-11-19 22:47:44 +01:00
}
PrintQueue :: queueWorkPrintJob ( $pdo , $tablename , $germanTime , $resultarray , $kind , $printer , $user );
}
private function getJsonLastMadeItems ( $kind ) {
2020-11-19 22:59:47 +01:00
$pdo = DbUtils :: openDbAndReturnPdoStatic ();
2020-11-19 22:47:44 +01:00
// first sort all non-ready products ordered by ordertime
2020-11-19 22:59:47 +01:00
if ( $this -> areBillExisting ( $pdo )) {
$sql = " SELECT DISTINCT %queue%.id as id,tablenr,longname,anoption,tableno,readytime,%products%.id as prodid FROM %queue%,%products%,%prodtype%,%resttables%,%bill% " ;
2020-11-19 22:47:44 +01:00
} else {
$sql = " SELECT DISTINCT %queue%.id as id,tablenr,longname,anoption,tableno,readytime,%products%.id as prodid FROM %queue%,%products%,%prodtype%,%resttables% " ;
}
2020-11-19 23:00:46 +01:00
$sql .= " WHERE (readytime IS NOT NULL AND " ;
$sql .= " delivertime IS NULL AND " ;
2020-11-19 22:59:47 +01:00
$sql .= " ordertime is not null AND " ;
$sql .= " %queue%.productid=%products%.id AND " ;
2020-11-19 22:47:44 +01:00
$sql .= " %queue%.tablenr = %resttables%.id AND " ;
$sql .= " %products%.category=%prodtype%.id AND " ;
$sql .= " %prodtype%.kind=? AND " ;
2020-11-19 22:50:09 +01:00
$sql .= " %queue%.isclosed is null AND " ;
2020-11-19 22:47:44 +01:00
$sql .= " %queue%.workprinted='0') " ;
if ( $this -> areBillExisting ( $pdo )) {
2020-11-19 22:59:47 +01:00
// now remove closed items
$sql .= " AND (%queue%.billid is null OR ( " ;
2020-11-19 22:47:44 +01:00
$sql .= " %queue%.billid=%bill%.id AND %bill%.closingid is null)) " ;
2020-11-19 22:59:47 +01:00
}
2020-11-19 22:47:44 +01:00
$sql .= " ORDER BY readytime DESC LIMIT 10; " ;
$stmt = $pdo -> prepare ( DbUtils :: substTableAlias ( $sql ));
2020-11-19 22:59:47 +01:00
$stmt -> execute ( array ( $kind ));
2020-11-19 22:47:44 +01:00
$result1 = $stmt -> fetchAll ();
if ( $this -> areBillExisting ( $pdo )) {
$sql = " SELECT DISTINCT %queue%.id as id,0 as tablenr,longname,anoption,'-' as tableno,readytime,%products%.id as prodid FROM %queue%,%products%,%prodtype%,%resttables%,%bill% " ;
} else {
$sql = " SELECT DISTINCT %queue%.id as id,0 as tablenr,longname,anoption,'-' as tableno,readytime,%products%.id as prodid FROM %queue%,%products%,%prodtype%,%resttables% " ;
}
2020-11-19 23:00:46 +01:00
$sql .= " WHERE (readytime IS NOT NULL AND " ;
$sql .= " delivertime IS NULL AND " ;
2020-11-19 22:47:44 +01:00
$sql .= " ordertime is not null AND " ;
$sql .= " %queue%.productid=%products%.id AND " ;
$sql .= " %queue%.tablenr is null AND " ;
$sql .= " %products%.category=%prodtype%.id AND " ;
$sql .= " %prodtype%.kind=? AND " ;
2020-11-19 22:50:09 +01:00
$sql .= " %queue%.isclosed is null AND " ;
2020-11-19 22:47:44 +01:00
$sql .= " %queue%.workprinted='0') " ;
if ( $this -> areBillExisting ( $pdo )) {
// now remove closed items
$sql .= " AND (%queue%.billid is null OR ( " ;
$sql .= " %queue%.billid=%bill%.id AND %bill%.closingid is null)) " ;
}
$sql .= " ORDER BY readytime DESC LIMIT 10; " ;
$stmt = $pdo -> prepare ( DbUtils :: substTableAlias ( $sql ));
$stmt -> execute ( array ( $kind ));
$result2 = $stmt -> fetchAll ();
$result = array_merge ( $result1 , $result2 );
2020-11-19 22:59:47 +01:00
2020-11-19 22:47:44 +01:00
$resultarray = array ();
foreach ( $result as $zeile ) {
$extras = $this -> getExtrasOfQueueItem ( $pdo , $zeile [ 'id' ]);
$productid = $zeile [ 'prodid' ];
2020-11-19 22:54:51 +01:00
$useConditions = $this -> getUseKitchenAndSupplyForProd ( $pdo , $productid );
2020-11-19 22:47:44 +01:00
if ( $useConditions [ " usekitchen " ] == 1 ) {
2020-11-19 22:59:47 +01:00
// yes, display it in kitchen view as cooked
$arr = array ( " id " => $zeile [ 'id' ],
" tablename " => $zeile [ 'tableno' ],
" longname " => $zeile [ 'longname' ],
2020-11-19 22:47:44 +01:00
" option " => $zeile [ 'anoption' ],
2020-11-19 22:59:47 +01:00
" extras " => $extras ,
" readytime " => $zeile [ 'readytime' ]
);
2020-11-19 22:47:44 +01:00
$resultarray [] = $arr ;
2020-11-19 22:59:47 +01:00
}
2020-11-19 22:47:44 +01:00
}
// now look for items that are made and auto-delivered
// They must appear if:
// a) in category autosupply yes
// b) they have the right kind
// c) they shall appear in bar/kitchen module at all
$resultarray = $this -> appendProdsForBarKitchenAndAutoDelivery ( $pdo , $kind , $resultarray );
echo json_encode ( $resultarray );
}
2020-11-19 22:59:47 +01:00
private function appendProdsForBarKitchenAndAutoDelivery ( $pdo , $kind , $resultarray ) {
$sql = " SELECT DISTINCT %queue%.id as id,tableno,longname,delivertime,anoption,%products%.id as prodid " ;
$sql .= " FROM %queue%,%resttables%,%products%,%bill%,%prodtype% " ;
$sql .= " WHERE (%queue%.productid=%products%.id " ;
2020-11-19 22:47:44 +01:00
$sql .= " AND %queue%.tablenr=%resttables%.id " ;
2020-11-19 23:00:46 +01:00
$sql .= " AND %queue%.readytime IS NOT NULL " ;
2020-11-19 22:59:47 +01:00
$sql .= " AND toremove <> '1' AND " ;
2020-11-19 22:47:44 +01:00
$sql .= " ordertime is not null AND " ;
2020-11-19 22:59:47 +01:00
$sql .= " (%queue%.productid = %products%.id AND %products%.category = %prodtype%.id AND %prodtype%.kind=? AND %prodtype%.usesupplydesk='0' AND %prodtype%.usekitchen='1') AND " ;
$sql .= " %queue%.workprinted='0') " ;
// now remove closed items
$sql .= " AND (%queue%.billid is null OR ( " ;
$sql .= " %queue%.billid=%bill%.id AND %bill%.closingid is null)) " ;
2020-11-19 22:47:44 +01:00
$sql = $sql . " ORDER BY delivertime DESC LIMIT 10 " ;
2020-11-19 22:54:51 +01:00
$stmt = $pdo -> prepare ( DbUtils :: substTableAlias ( $sql ));
$stmt -> execute ( array ( $kind ));
$result = $stmt -> fetchAll ();
2020-11-19 22:59:47 +01:00
foreach ( $result as $zeile ) {
2020-11-19 22:47:44 +01:00
$productid = $zeile [ 'prodid' ];
2020-11-19 22:59:47 +01:00
$extras = $this -> getExtrasOfQueueItem ( $pdo , $zeile [ 'id' ]);
$deliveredProd = array (
2020-11-19 22:47:44 +01:00
" id " => $zeile [ 'id' ],
2020-11-19 22:59:47 +01:00
" tablename " => $zeile [ 'tableno' ],
" longname " => $zeile [ 'longname' ],
2020-11-19 22:47:44 +01:00
" option " => $zeile [ 'anoption' ],
2020-11-19 22:59:47 +01:00
" extras " => $extras ,
" readytime " => $zeile [ 'delivertime' ]
);
$resultarray [] = $deliveredProd ;
}
return ( $resultarray );
2020-11-19 22:47:44 +01:00
}
2020-11-19 23:00:05 +01:00
function getTableIdOfQueue ( $pdo , $queueid ) {
$sql = " SELECT tablenr as tableid FROM %queue% WHERE id=? " ;
2020-11-19 23:00:55 +01:00
$row = CommonUtils :: getRowSqlObject ( $pdo , $sql , array ( $queueid ));
2020-11-19 23:00:05 +01:00
return $row -> tableid ;
}
2020-11-19 22:47:44 +01:00
/*
* Kitchen can delare a product as being cooked
*/
function declareProductBeCookingOrCooked ( $queueid , $action ) {
if ( is_numeric ( $queueid )) {
2020-11-19 22:59:47 +01:00
$pdo = $this -> dbutils -> openDbAndReturnPdo ();
2020-11-19 22:47:44 +01:00
$pdo -> beginTransaction ();
// is product already cooking or will it be set to cooking?
$sql = " SELECT cooking,productid FROM %queue% WHERE id=? " ;
2020-11-19 23:00:55 +01:00
$row = CommonUtils :: getRowSqlObject ( $pdo , $sql , array ( $queueid ));
2020-11-19 22:59:47 +01:00
if ( $row != null ) {
2020-11-19 22:47:44 +01:00
$cooking = $row -> cooking ;
2020-11-19 22:59:47 +01:00
$productid = $row -> productid ;
2020-11-19 22:47:44 +01:00
if ( $action == 'r' ) {
// product shall be declared ready
if ( is_null ( $cooking )) {
// a product must be cooking before it can be ready!
$pdo -> rollBack ();
echo json_encode ( array ( " status " => " ERROR " , " code " => ERROR_DB_PAR_ACCESS , " msg " => ERROR_DB_PAR_ACCESS_MSG ));
} else {
2020-11-19 22:59:47 +01:00
$this -> reallyDeclareAsCooked ( $pdo , $queueid );
$useConditions = $this -> getUseKitchenAndSupplyForProd ( $pdo , $productid );
if ( $useConditions [ " usesupply " ] == 0 ) {
// can bypass the supplydesk
$this -> declareProductBeDeliveredWithGivenPdo ( $pdo , $queueid );
2020-11-19 23:00:55 +01:00
} else {
self :: setNewProductsToServe ( $pdo , 1 );
2020-11-19 22:47:44 +01:00
}
2020-11-19 23:00:05 +01:00
$payprinttype = CommonUtils :: getConfigValue ( $pdo , 'payprinttype' , " l " );
$digiprintwork = CommonUtils :: getConfigValue ( $pdo , 'digiprintwork' , 1 );
if (( $payprinttype === 's' ) && ( $digiprintwork == 1 )) {
$theTableid = $this -> getTableIdOfQueue ( $pdo , $queueid );
if ( is_null ( $theTableid )) {
$theTableid = 0 ;
}
$this -> doWorkPrint ( $pdo , $theTableid , array ( $queueid ), $_SESSION [ 'currentuser' ], $payprinttype , $_SESSION [ 'language' ], false );
}
2020-11-19 22:47:44 +01:00
$pdo -> commit ();
echo json_encode ( array ( " status " => " OK " ));
}
} else if ( $action == 'c' ) {
// product shall be declared as cooking (in progress)
if ( ! is_null ( $cooking )) {
// a product must not be cooking before it can becomes cooking
2020-11-19 22:59:47 +01:00
$pdo -> rollBack ();
2020-11-19 22:47:44 +01:00
echo json_encode ( array ( " status " => " ERROR " , " code " => ERROR_DB_PAR_ACCESS , " msg " => ERROR_DB_PAR_ACCESS_MSG ));
} else {
$userid = $this -> getUserId ();
$updSql = " UPDATE %queue% SET cooking=? WHERE id=? " ;
2020-11-19 22:59:47 +01:00
$stmt = $pdo -> prepare ( $this -> dbutils -> resolveTablenamesInSqlString ( $updSql ));
2020-11-19 22:47:44 +01:00
$stmt -> execute ( array ( $userid , $queueid ));
$pdo -> commit ();
echo json_encode ( array ( " status " => " OK " ));
}
2020-11-19 22:59:47 +01:00
}
2020-11-19 22:47:44 +01:00
} else {
$pdo -> rollBack ();
}
} else {
echo json_encode ( array ( " status " => " ERROR " , " code " => ERROR_GENERAL_ID_TYPE , " msg " => ERROR_GENERAL_ID_TYPE_MSG ));
2020-11-19 22:59:47 +01:00
}
2020-11-19 22:47:44 +01:00
}
private function reallyDeclareAsCooked ( $pdo , $queueid ) {
2020-11-19 22:59:47 +01:00
date_default_timezone_set ( DbUtils :: getTimeZone ());
$readytime = date ( 'Y-m-d H:i:s' );
2020-11-19 22:47:44 +01:00
$insertSql = " UPDATE %queue% SET readytime=? WHERE id=? " ;
2020-11-19 22:59:47 +01:00
$stmt = $pdo -> prepare ( $this -> dbutils -> resolveTablenamesInSqlString ( $insertSql ));
2020-11-19 22:47:44 +01:00
$stmt -> execute ( array ( $readytime , $queueid ));
}
/*
* Product is not cooked ( undo of kitchen )
*/
function declareProductNotBeCooked ( $queueid ) {
if ( is_numeric ( $queueid )) {
2020-11-19 22:59:47 +01:00
$pdo = $this -> dbutils -> openDbAndReturnPdo ();
2020-11-19 22:47:44 +01:00
$pdo -> beginTransaction ();
// first: is the product still declared as delivered?
2020-11-19 23:00:46 +01:00
$sql = " SELECT id FROM %queue% WHERE id=? AND readytime IS NOT NULL " ;
2020-11-19 23:00:55 +01:00
$row = CommonUtils :: getRowSqlObject ( $pdo , $sql , array ( $queueid ));
2020-11-19 22:59:47 +01:00
if ( $row != null ) {
2020-11-19 22:47:44 +01:00
$foundid = $row -> id ;
if ( $foundid == $queueid ) {
2020-11-19 23:00:46 +01:00
$sql = " UPDATE %queue% SET readytime=?, delivertime=?, cooking=NULL WHERE id=? " ;
2020-11-19 22:47:44 +01:00
$stmt = $pdo -> prepare ( $this -> dbutils -> resolveTablenamesInSqlString ( $sql ));
2020-11-19 23:00:46 +01:00
$stmt -> execute ( array ( null , null , $queueid ));
2020-11-19 22:47:44 +01:00
$pdo -> commit ();
echo json_encode ( array ( " status " => " OK " ));
} else {
echo json_encode ( array ( " status " => " ERROR " , " code " => ERROR_DB_PAR_ACCESS , " msg " => ERROR_DB_PAR_ACCESS_MSG ));
$pdo -> rollBack ();
}
} else {
$pdo -> rollBack ();
echo json_encode ( array ( " status " => " ERROR " , " code " => ERROR_DB_PAR_ACCESS , " msg " => ERROR_DB_PAR_ACCESS_MSG ));
2020-11-19 22:59:47 +01:00
}
2020-11-19 22:47:44 +01:00
} else {
echo json_encode ( array ( " status " => " ERROR " , " code " => ERROR_GENERAL_ID_TYPE , " msg " => ERROR_GENERAL_ID_TYPE_MSG ));
}
}
2020-11-19 22:54:51 +01:00
private function findCategoryOfProd ( $pdo , $prodid ) {
$sql = " SELECT category FROM %products% WHERE id=? " ;
2020-11-19 23:00:55 +01:00
$row = CommonUtils :: getRowSqlObject ( $pdo , $sql , array ( $prodid ));
2020-11-19 22:54:51 +01:00
return $row -> category ;
2020-11-19 22:47:44 +01:00
}
2020-11-19 22:54:51 +01:00
private function getUseKitchenAndSupplyForProdInCat ( $pdo , $catid ) {
$sql = " SELECT usekitchen, usesupplydesk FROM %prodtype% WHERE id=? " ;
2020-11-19 23:00:55 +01:00
$row = CommonUtils :: getRowSqlObject ( $pdo , $sql , array ( $catid ));
2020-11-19 22:54:51 +01:00
return array ( " usekitchen " => $row -> usekitchen , " usesupply " => $row -> usesupplydesk );
2020-11-19 22:47:44 +01:00
}
2020-11-19 22:54:51 +01:00
private function getUseKitchenAndSupplyForProd ( $pdo , $prodid ) {
$catid = $this -> findCategoryOfProd ( $pdo , $prodid );
return $this -> getUseKitchenAndSupplyForProdInCat ( $pdo , $catid );
2020-11-19 22:47:44 +01:00
}
private function getUseKitchenAndSupplyForProdWithPdo ( $pdo , $prodid ) {
2020-11-19 22:59:47 +01:00
$sql = " SELECT usekitchen, usesupplydesk FROM %prodtype%,%products% WHERE %products%.category=%prodtype%.id AND %products%.id=? " ;
2020-11-19 23:00:55 +01:00
$row = CommonUtils :: getRowSqlObject ( $pdo , $sql , array ( $prodid ));
2020-11-19 22:47:44 +01:00
if ( $row != null ) {
return array ( " usekitchen " => $row -> usekitchen , " usesupply " => $row -> usesupplydesk );
} else {
return array ( " usekitchen " => " 1 " , " usesupply " => " 1 " );
}
}
2020-11-19 22:59:47 +01:00
/*
* Add a product list to the queue as if it was ordered by the waiter .
* The ordertime is set by the time that this method is invoked .
*
* If product shall not be run over kitchen or supplydesk this is
* managed here as well
2020-11-19 22:47:44 +01:00
*/
function addProductListToQueue ( $theTableid , $prods , $doPrint , $payprinttype ) {
2020-11-19 23:00:55 +01:00
2020-11-19 22:47:44 +01:00
if ( intval ( $theTableid ) == 0 ) {
$theTableid = null ; // togo room
}
if ( session_id () == '' ) {
session_start ();
}
2020-11-19 23:00:55 +01:00
date_default_timezone_set ( DbUtils :: getTimeZone ());
$ordertime = date ( 'Y-m-d H:i:s' );
2020-11-19 22:47:44 +01:00
$pdo = $this -> dbutils -> openDbAndReturnPdo ();
2020-11-19 23:00:55 +01:00
$printAndQueueJobs = CommonUtils :: getConfigValue ( $pdo , " printandqueuejobs " , 0 );
if ( $printAndQueueJobs == 1 ) {
$doPrint = 1 ;
}
2020-11-19 22:47:44 +01:00
$pdo -> beginTransaction ();
2020-11-19 23:00:31 +01:00
$togotax = CommonUtils :: getExistingConfigValue ( $pdo , 'togotax' );
$normaltax = CommonUtils :: getExistingConfigValue ( $pdo , 'tax' );
$workflowconfig = CommonUtils :: getExistingConfigValue ( $pdo , 'workflowconfig' );
$austria = CommonUtils :: getExistingConfigValue ( $pdo , 'austria' );
2020-11-19 22:59:47 +01:00
// get current pricelevel
$currentPriceLevel = $this -> commonUtils -> getCurrentPriceLevel ( $pdo );
$currentPriceLevelId = $currentPriceLevel [ " id " ];
2020-11-19 22:47:44 +01:00
$insertedQueueIds = array ();
$i = 0 ;
for ( $i = 0 ; $i < count ( $prods ); $i ++ ) {
$aProd = $prods [ $i ];
$productid = intval ( $aProd [ " prodid " ]);
$theOption = $aProd [ " option " ];
$theChangedPrice = $aProd [ " changedPrice " ];
$theChangedPrice = str_replace ( ',' , '.' , $theChangedPrice );
2020-11-19 22:59:47 +01:00
// now get the price for this pricelevel
2020-11-19 23:00:31 +01:00
$getPriceSql = " SELECT priceA,priceB,priceC,longname,tax,taxaustria,amount FROM %products% where id=? " ;
2020-11-19 23:00:55 +01:00
$row = CommonUtils :: getRowSqlObject ( $pdo , $getPriceSql , array ( $productid ));
2020-11-19 22:59:47 +01:00
if ( $row == null ) {
echo " Fehler: Preise nicht vorhanden " ; // error
return ;
2020-11-19 22:47:44 +01:00
}
2020-11-19 23:00:31 +01:00
if ( ! is_null ( $row -> amount )) {
$amount = max (( $row -> amount - 1 ), 0 );
$sql = " UPDATE %products% SET amount=? WHERE id=? " ;
$stmt = $pdo -> prepare ( DbUtils :: substTableAlias ( $sql ));
$stmt -> execute ( array ( $amount , $productid ));
}
2020-11-19 22:59:47 +01:00
2020-11-19 22:47:44 +01:00
$productname = $row -> longname ;
2020-11-19 22:59:47 +01:00
if (( $theChangedPrice == " NO " ) || ( ! is_numeric ( $theChangedPrice ))) {
$price_for_level_A = $row -> priceA ;
$price_for_level_B = $row -> priceB ;
$price_for_level_C = $row -> priceC ;
$price = $price_for_level_A ; // default - levl 1
if ( $currentPriceLevelId == 2 ) {
$price = $price_for_level_B ;
} else if ( $currentPriceLevelId == 3 ) {
$price = $price_for_level_C ;
} // else: use default price A
2020-11-19 22:47:44 +01:00
} else {
$price = $theChangedPrice ;
}
2020-11-19 22:55:20 +01:00
// now check if the product is a togo article that might have been booked on a table
$togo = $aProd [ " togo " ];
2020-11-19 22:47:44 +01:00
$tax = $normaltax ;
if ( is_null ( $theTableid )) {
$tax = $togotax ;
}
2020-11-19 22:55:20 +01:00
if ( $togo == 1 ) {
$tax = $togotax ;
}
2020-11-19 23:00:31 +01:00
if ( $austria == 1 ) {
$taxaustrianumber = $row -> taxaustria ;
$configItem = " " ;
switch ( $taxaustrianumber ) {
case 1 :
$configItem = " taxaustrianormal " ;
break ;
case 2 :
$configItem = " taxaustriaerm1 " ;
break ;
case 3 :
$configItem = " taxaustriaerm2 " ;
break ;
case 4 :
$configItem = " taxaustriaspecial " ;
break ;
default :
$configItem = " taxaustrianormal " ;
}
$tax = CommonUtils :: getExistingConfigValue ( $pdo , $configItem );
} else {
$taxaustrianumber = null ;
if ( ! is_null ( $row -> tax )) {
$tax = $row -> tax ;
}
2020-11-19 22:47:44 +01:00
}
$extras = null ;
if ( array_key_exists ( " extras " , $aProd )) {
$extras = $aProd [ " extras " ];
}
if ( ! is_null ( $extras ) && ( $extras != " " )) {
for ( $j = 0 ; $j < count ( $extras ); $j ++ ) {
$anExtra = $extras [ $j ];
$extraid = $anExtra [ " id " ];
$extraname = $anExtra [ " name " ];
$sql = " SELECT price FROM %extras% WHERE id=? " ;
2020-11-19 23:00:55 +01:00
$row = CommonUtils :: getRowSqlObject ( $pdo , $sql , array ( $extraid ));
2020-11-19 22:47:44 +01:00
$price += floatval ( $row -> price );
}
}
2020-11-19 22:59:47 +01:00
if ( is_null ( $theTableid ) || ( is_numeric ( $theTableid ) && is_numeric ( $productid ))) {
// first get category of product
$useConditions = $this -> getUseKitchenAndSupplyForProdWithPdo ( $pdo , $productid );
$insertSql = " INSERT INTO `%queue%` (
2020-11-19 23:00:31 +01:00
`id` , `tablenr` , `productid` , `pricelevel` , `price` , `tax` , `taxaustria` , `productname` , `ordertime` , `orderuser` , `anoption` , `pricechanged` , `togo` , `readytime` , `delivertime` , `paidtime` , `billid` , `toremove` , `cooking` , `workprinted` )
2020-11-19 22:59:47 +01:00
VALUES (
2020-11-19 23:00:46 +01:00
NULL , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , null , null , NULL , NULL , '0' , NULL , '0' ); " ;
2020-11-19 22:59:47 +01:00
2020-11-19 22:55:30 +01:00
$stmt = $pdo -> prepare ( DbUtils :: substTableAlias ( $insertSql ));
2020-11-19 23:00:31 +01:00
$stmt -> execute ( array ( $theTableid , $productid , $currentPriceLevelId , $price , $tax , $taxaustrianumber , $productname , $ordertime , $_SESSION [ 'userid' ], $theOption ,( $theChangedPrice == " NO " ? 0 : 1 ), $togo ));
2020-11-19 22:47:44 +01:00
$queueid = $pdo -> lastInsertId ();
2020-11-19 22:55:20 +01:00
2020-11-19 22:47:44 +01:00
if ( ! is_null ( $extras ) && ( $extras != " " )) {
for ( $j = 0 ; $j < count ( $extras ); $j ++ ) {
$anExtra = $extras [ $j ];
$extraid = $anExtra [ " id " ];
$extraname = $anExtra [ " name " ];
$sql = " INSERT INTO %queueextras% (`id`,`queueid`,`extraid`,`name`) VALUES(NULL,?,?,?) " ;
$stmt = $pdo -> prepare ( $this -> dbutils -> resolveTablenamesInSqlString ( $sql ));
$stmt -> execute ( array ( $queueid , $extraid , $extraname ));
2020-11-19 22:59:47 +01:00
}
2020-11-19 22:47:44 +01:00
}
2020-11-19 22:55:30 +01:00
if (( $workflowconfig == 3 ) && ( $doPrint == 0 )) {
$this -> reallyDeclareAsCooked ( $pdo , $queueid );
$this -> declareProductBeDeliveredWithGivenPdo ( $pdo , $queueid );
2020-11-19 22:47:44 +01:00
} else {
2020-11-19 22:59:47 +01:00
if ( $useConditions [ " usekitchen " ] == 0 ) {
// no - can bypass the kitchen
$this -> reallyDeclareAsCooked ( $pdo , $queueid );
// then also look for supplydesk, since kitchen action won't do this!
if ( $useConditions [ " usesupply " ] == 0 ) {
// can bypass the supplydesk
$this -> declareProductBeDeliveredWithGivenPdo ( $pdo , $queueid );
// THIS autop declares as "prepared" (cooked)!!!
}
2020-11-19 22:55:30 +01:00
} else {
$insertedQueueIds [] = $queueid ;
}
2020-11-19 22:59:47 +01:00
}
2020-11-19 22:47:44 +01:00
}
}
2020-11-19 23:00:55 +01:00
$cashenabled = CommonUtils :: getConfigValue ( $pdo , " cashenabled " , 1 );
if ( $cashenabled == 0 ) {
$idStr = join ( ',' , $insertedQueueIds );
$this -> declarePaidCreateBillReturnBillId ( $pdo , $idStr , $theTableid , 1 , 0 , 0 , true );
}
2020-11-19 22:47:44 +01:00
if ( $doPrint == 1 ) {
if ( $payprinttype == " s " ) {
$this -> doWorkPrint ( $pdo , $theTableid , $insertedQueueIds , $_SESSION [ 'currentuser' ], $payprinttype , $_SESSION [ 'language' ]);
echo json_encode ( array ( " status " => " OK " ));
} else {
$result = $this -> doWorkPrint ( $pdo , $theTableid , $insertedQueueIds , $_SESSION [ 'currentuser' ], $payprinttype , $_SESSION [ 'language' ]);
echo json_encode ( array ( " status " => " OK " , " msg " => $result ));
}
} else {
echo json_encode ( array ( " status " => " OK " ));
}
$pdo -> commit ();
}
/*
* Do as if the product would have been removed from queue - but don ' t do it exactly ,
* because then it would not appear in the reports any more . Instead declare the
* ordertime = null ( was never ordered ... )
*/
function removeProductFromQueue ( $queueid , $isPaid , $isCooking , $isReady ) {
if ( is_numeric ( $queueid )) {
2020-11-19 22:59:47 +01:00
$pdo = $this -> dbutils -> openDbAndReturnPdo ();
2020-11-19 22:47:44 +01:00
$sql = " SELECT count(id) as countid FROM %bill% " ;
2020-11-19 23:00:55 +01:00
$row = CommonUtils :: getRowSqlObject ( $pdo , $sql , null );
2020-11-19 22:47:44 +01:00
$hasBills = ( $row -> countid > 0 ? true : false );
2020-11-19 22:59:47 +01:00
if ( $hasBills ) {
2020-11-19 22:47:44 +01:00
$sql = " UPDATE %queue%,%bill% " ;
} else {
$sql = " UPDATE %queue% " ;
}
2020-11-19 23:00:46 +01:00
$sql .= " SET ordertime=null WHERE %queue%.id=? AND ordertime IS NOT NULL " ;
2020-11-19 22:47:44 +01:00
if ( $isPaid == '1' ) {
2020-11-19 23:00:46 +01:00
$sql .= " AND paidtime IS NOT NULL " ;
2020-11-19 22:47:44 +01:00
} else {
2020-11-19 23:00:46 +01:00
$sql .= " AND (paidtime IS NULL or paidtime is null) " ;
2020-11-19 22:47:44 +01:00
}
if ( $isCooking == '1' ) {
$sql .= " AND cooking is not null " ;
} else {
$sql .= " AND cooking is null " ;
}
if ( $isReady == '1' ) {
2020-11-19 23:00:46 +01:00
$sql .= " AND readytime IS NOT NULL " ;
2020-11-19 22:47:44 +01:00
} else {
2020-11-19 23:00:46 +01:00
$sql .= " AND (readytime IS NULL or readytime is null) " ;
2020-11-19 22:47:44 +01:00
}
// and not in a closing:
if ( $hasBills ) {
$sql .= " AND (billid is null OR ( " ;
$sql .= " billid = %bill%.id AND %bill%.closingid is null)) " ;
}
$stmt = $pdo -> prepare ( $this -> dbutils -> resolveTablenamesInSqlString ( $sql ));
2020-11-19 22:59:47 +01:00
2020-11-19 22:47:44 +01:00
$stmt -> execute ( array ( $queueid ));
2020-11-19 22:59:47 +01:00
$rowsAffected = $stmt -> rowCount ();
2020-11-19 22:47:44 +01:00
if ( $rowsAffected == 1 ) {
echo json_encode ( array ( " status " => " OK " ));
} else {
echo json_encode ( array ( " status " => " Failed " , " msg " => " Affected rows: $rowsAffected " ));
}
}
}
2020-11-19 22:55:43 +01:00
function getUnpaidTables () {
$pdo = DbUtils :: openDbAndReturnPdoStatic ();
2020-11-19 22:58:33 +01:00
$sql = " SELECT DISTINCT %resttables%.tableno as tablename FROM %queue%,%resttables% WHERE paidtime is null AND ordertime is not null and tablenr=%resttables%.id AND isclosed is null " ;
2020-11-19 22:55:43 +01:00
$stmt = $pdo -> prepare ( DbUtils :: substTableAlias ( $sql ));
$stmt -> execute ();
$result = $stmt -> fetchAll ();
$unpaidTables = array ();
foreach ( $result as $anUnpaidTable ) {
$unpaidTables [] = $anUnpaidTable [ " tablename " ];
}
echo json_encode ( array ( " status " => " OK " , " msg " => join ( " , " , $unpaidTables )));
}
2020-11-19 22:47:44 +01:00
/*
* Return as JSON structure all products that are assigned to a specified table , with the
* specification that they are not delivered yet .
*
* ordertime must not be null , because = null means that is is paid but was cancelled later
* by the waiter ! ( in a previous version such entries were deleted from queue , but then
* they won ' t appear in reports any more )
*
* Return is : [
* { " queueid " : " 2 " , " longname " : " EL Greco 1 Person " , " isReady " : " 1 " },
* { " queueid " : " 5 " , " longname " : " Souvlaki " , " isReady " : " 0 " }]
* ( a sample )
*
*/
function getJsonLongNamesOfProdsForTableNotDelivered ( $tableid ) {
if ( is_numeric ( $tableid )) {
2020-11-19 22:59:47 +01:00
$prods = array ();
2020-11-19 22:47:44 +01:00
$pdo = DbUtils :: openDbAndReturnPdoStatic ();
$sql = " SELECT count(id) as countid FROM %bill% " ;
2020-11-19 23:00:55 +01:00
$row = CommonUtils :: getRowSqlObject ( $pdo , $sql , null );
2020-11-19 22:47:44 +01:00
if ( $row -> countid == 0 ) {
2020-11-19 23:00:52 +01:00
$sql = " SELECT DISTINCT %queue%.id as quid, ordertime FROM %queue% WHERE ordertime is not null AND isclosed is null AND " ;
2020-11-19 22:47:44 +01:00
} else {
2020-11-19 23:00:52 +01:00
$sql = " SELECT DISTINCT %queue%.id as quid, ordertime FROM %queue%,%bill% WHERE ordertime is not null AND isclosed is null AND ((%queue%.billid is null AND %queue%.paidtime is null) OR (%queue%.billid=%bill%.id AND %bill%.closingid is null)) AND " ;
2020-11-19 22:47:44 +01:00
}
if ( $tableid == 0 ) {
2020-11-19 23:00:14 +01:00
$sql .= " %queue%.tablenr is null ORDER BY ordertime, quid " ;
2020-11-19 22:47:44 +01:00
$stmt = $pdo -> prepare ( DbUtils :: substTableAlias ( $sql ));
$stmt -> execute ();
} else {
2020-11-19 23:00:14 +01:00
$sql .= " %queue%.tablenr=? ORDER BY ordertime, quid " ;
2020-11-19 22:47:44 +01:00
$stmt = $pdo -> prepare ( DbUtils :: substTableAlias ( $sql ));
$stmt -> execute ( array ( $tableid ));
}
$allNotClosedQueueIds = $stmt -> fetchAll ();
$resultids = array ();
2020-11-19 23:00:46 +01:00
$sql = " SELECT count(id) as countid FROM %queue% WHERE %queue%.id=? AND (%queue%.delivertime IS NULL " ;
$sql .= " OR %queue%.readytime IS NULL " ;
2020-11-19 22:47:44 +01:00
$sql .= " OR (%queue%.billid is null AND %queue%.paidtime is null)) " ;
$stmt = $pdo -> prepare ( DbUtils :: substTableAlias ( $sql ));
foreach ( $allNotClosedQueueIds as $aQueueId ) { #
$aQId = $aQueueId [ " quid " ];
$stmt -> execute ( array ( $aQId ));
$row = $stmt -> fetchObject ();
if ( $row -> countid > 0 ) {
$resultids [] = $aQId ;
}
}
$prods = array ();
2020-11-19 23:00:14 +01:00
$sql = " SELECT productid,readytime,paidtime,cooking,productname,anoption,productname,togo,pricechanged,price FROM %queue% WHERE id=? ORDER BY productid " ;
2020-11-19 22:47:44 +01:00
$stmt = $pdo -> prepare ( DbUtils :: substTableAlias ( $sql ));
foreach ( $resultids as $anId ) {
$stmt -> execute ( array ( $anId ));
$row = $stmt -> fetchObject ();
$isReady = " 1 " ;
$isDelivered = " 1 " ;
$isPaid = " 1 " ;
$isCooking = '1' ;
2020-11-19 23:00:46 +01:00
if ( $row -> readytime == null ) {
2020-11-19 22:47:44 +01:00
$isReady = " 0 " ; // not yet prepared by the kitchen
}
if ( $row -> paidtime == null ) {
$isPaid = " 0 " ; // not yet paid
}
if ( is_null ( $row -> cooking )) {
$isCooking = '0' ;
}
2020-11-19 22:58:27 +01:00
$extras = $this -> getExtrasWithIdsOfQueueItem ( $pdo , $anId );
2020-11-19 22:47:44 +01:00
$prodEntry = array (
2020-11-19 22:55:09 +01:00
" id " => $anId ,
2020-11-19 22:58:27 +01:00
" prodid " => $row -> productid ,
2020-11-19 22:47:44 +01:00
" longname " => $row -> productname ,
" option " => $row -> anoption ,
2020-11-19 22:55:20 +01:00
" pricechanged " => $row -> pricechanged ,
" togo " => $row -> togo ,
" price " => $row -> price ,
2020-11-19 22:58:27 +01:00
" extras " => $extras [ " extrasnames " ],
" extrasids " => $extras [ " extrasids " ],
2020-11-19 22:47:44 +01:00
" isready " => $isReady ,
" isPaid " => $isPaid ,
" isCooking " => $isCooking );
$prods [] = $prodEntry ;
}
echo json_encode ( $prods );
2020-11-19 22:59:47 +01:00
}
2020-11-19 22:47:44 +01:00
}
2020-11-19 22:50:09 +01:00
function getProdsForTableChange ( $tableid ) {
$pdo = DbUtils :: openDbAndReturnPdoStatic ();
2020-11-19 22:47:44 +01:00
2020-11-19 22:50:09 +01:00
if ( $tableid == 0 ) {
$tableid = null ;
2020-11-19 22:47:44 +01:00
}
2020-11-19 22:59:47 +01:00
$sql = " SELECT %queue%.id as queueid,productname FROM " ;
2020-11-19 22:50:09 +01:00
$sql .= " %queue% WHERE " ;
$sql .= " (tablenr=? OR (tablenr IS NULL AND ? IS NULL)) AND ordertime is not null AND isclosed is null AND billid is null " ;
$stmt = $pdo -> prepare ( DbUtils :: substTableAlias ( $sql ));
$stmt -> execute ( array ( $tableid , $tableid ));
2020-11-19 22:59:47 +01:00
$unpaidresultungrouped = $stmt -> fetchAll ();
$sql = " SELECT %queue%.id as queueid,productname FROM " ;
2020-11-19 22:50:09 +01:00
$sql .= " %queue% LEFT OUTER JOIN %bill% ON %queue%.billid=%bill%.id WHERE " ;
$sql .= " (tablenr=? OR (tablenr IS NULL AND ? IS NULL)) AND ordertime is not null AND isclosed is null AND billid is null AND ( " ;
2020-11-19 23:00:46 +01:00
$sql .= " %queue%.delivertime IS NULL OR " ;
$sql .= " (%queue%.delivertime IS NOT NULL AND workprinted='1')) " ;
2020-11-19 22:50:09 +01:00
$stmt = $pdo -> prepare ( DbUtils :: substTableAlias ( $sql ));
$stmt -> execute ( array ( $tableid , $tableid ));
2020-11-19 22:59:47 +01:00
$undeliveredresultungrouped = $stmt -> fetchAll ();
$merged = array ();
foreach ( $unpaidresultungrouped as $entry ) {
$qid = $entry [ " queueid " ];
$prodname = $entry [ " productname " ];
$status = " unpaid " ;
if ( $this -> isQueueIdInList ( $qid , $undeliveredresultungrouped )) {
$status = " unpaid_undelivered " ;
}
$merged [] = array ( " queueid " => $qid , " productname " => $prodname , " status " => $status );
}
2020-11-19 22:47:44 +01:00
2020-11-19 22:59:47 +01:00
echo json_encode ( array ( " status " => " OK " , " msg " => $merged ));
}
function isQueueIdInList ( $queueid , $list ) {
foreach ( $list as $entry ) {
if ( $entry [ 'queueid' ] == $queueid ) {
return true ;
}
}
return false ;
2020-11-19 22:50:09 +01:00
}
function changeTable ( $fromTableId , $toTableId , $queueids ) {
$ids = explode ( " , " , $queueids );
foreach ( $ids as $id ) {
if ( ! is_numeric ( $id )) {
echo json_encode ( array ( " status " => " ERROR " , " code " => NUMBERFORMAT_ERROR , " msg " => NUMBERFORMAT_ERROR_MSG ));
return ;
2020-11-19 22:47:44 +01:00
}
}
2020-11-19 22:50:09 +01:00
$pdo = $this -> dbutils -> openDbAndReturnPdo ();
$pdo -> beginTransaction ();
$sql = " UPDATE %queue% SET tablenr=? WHERE id IN( $queueids ) AND tablenr=? " ;
$stmt = $pdo -> prepare ( DbUtils :: substTableAlias ( $sql ));
$stmt -> execute ( array ( $toTableId , $fromTableId ));
2020-11-19 22:47:44 +01:00
$pdo -> commit ();
echo json_encode ( array ( " status " => " OK " ));
}
function getJsonProductsOfTableToPay ( $tableid ) {
2020-11-19 22:54:51 +01:00
$pdo = DbUtils :: openDbAndReturnPdoStatic ();
2020-11-19 23:00:52 +01:00
$sql = " SELECT %queue%.id as id,longname,%queue%.price as price,%queue%.tax,%pricelevel%.name as pricelevelname,%products%.id as prodid,%queue%.togo as togo, ordertime
2020-11-19 22:59:47 +01:00
FROM % queue %
2020-11-19 22:47:44 +01:00
INNER JOIN % products % ON % queue %. productid = % products %. id
INNER JOIN % pricelevel % ON % queue %. pricelevel = % pricelevel %. id " ;
if ( $tableid == 0 ) {
$sql .= " WHERE tablenr is null " ;
2020-11-19 22:59:47 +01:00
} else {
2020-11-19 22:47:44 +01:00
$sql .= " WHERE tablenr = $tableid " ;
}
2020-11-19 23:00:14 +01:00
$sql .= " AND paidtime is null AND toremove <> '1' AND ordertime is not null AND isclosed is null ORDER BY ordertime, id; " ;
2020-11-19 22:47:44 +01:00
2020-11-19 22:54:51 +01:00
$stmt = $pdo -> prepare ( DbUtils :: substTableAlias ( $sql ));
$stmt -> execute ();
$result = $stmt -> fetchAll ();
2020-11-19 22:55:09 +01:00
$prodsToPay = array ();
2020-11-19 22:59:47 +01:00
foreach ( $result as $zeile ) {
2020-11-19 22:47:44 +01:00
$thePrice = $zeile [ 'price' ];
$theTax = $zeile [ 'tax' ];
2020-11-19 22:59:47 +01:00
$thePriceLevelName = $zeile [ 'pricelevelname' ];
2020-11-19 22:47:44 +01:00
$longName = $zeile [ 'longname' ];
2020-11-19 22:55:20 +01:00
$togo = $zeile [ " togo " ];
2020-11-19 22:47:44 +01:00
$queueid = $zeile [ 'id' ];
2020-11-19 22:54:51 +01:00
$extras = $this -> getExtrasOfQueueItem ( $pdo , $queueid );
2020-11-19 22:47:44 +01:00
$prodId = $zeile [ 'prodid' ];
2020-11-19 22:55:20 +01:00
$prodsToPay [] = array ( " id " => $queueid , " prodid " => $prodId , " longname " => $longName , " pricelevelname " => $thePriceLevelName , " price " => $thePrice , " tax " => $theTax , " togo " => $togo , " extras " => $extras );
2020-11-19 22:47:44 +01:00
}
echo json_encode ( array ( " status " => " OK " , " msg " => $prodsToPay ));
}
// This function gets the items to pay and creates a table, in which these items
// are listed up. It can be used as a receipt to print later
function displayBill ( $billtableitems , $totalPrice ) {
$currency = $this -> commonUtils -> getCurrency ();
2020-11-19 22:59:47 +01:00
$numberOfItemsToPay = count ( $billtableitems );
if ( $numberOfItemsToPay > 0 ) {
echo " <br><br><table id=bill class=billtable> " ;
echo " <tr><th>Speise/Getränk<th id=pricecolheader>Preis ( $currency )</tr> " ;
for ( $i = 0 ; $i < $numberOfItemsToPay ; $i ++ ) {
$aProductToPay = $billtableitems [ $i ];
echo " <tr> " ;
echo " <td> " . $aProductToPay [ 'textOfButton' ] . " <td id=pricecol> " . $aProductToPay [ 'price' ] . " </tr> " ;
}
echo " <tr><td id=totalprice colspan=2>Gesamtpreis: " . $totalPrice . " $currency </tr> " ;
}
2020-11-19 22:47:44 +01:00
echo " </table> " ;
}
2020-11-19 22:59:47 +01:00
// **********************************
// * Bereitstellung *
2020-11-19 22:47:44 +01:00
// **********************************
function declareProductBeDeliveredWithGivenPdo ( $pdo , $queueid ) {
if ( is_numeric ( $queueid )) {
date_default_timezone_set ( DbUtils :: getTimeZone ());
$delivertime = date ( 'Y-m-d H:i:s' );
$updateSql = " UPDATE %queue% SET delivertime=? WHERE id=? " ;
2020-11-19 22:59:47 +01:00
$stmt = $pdo -> prepare ( $this -> dbutils -> resolveTablenamesInSqlString ( $updateSql ));
$stmt -> execute ( array ( $delivertime , $queueid ));
2020-11-19 22:47:44 +01:00
// then it was probably already prepared
$updateSql = " UPDATE %queue% SET readytime=? WHERE id=? " ;
$stmt = $pdo -> prepare ( $this -> dbutils -> resolveTablenamesInSqlString ( $updateSql ));
$stmt -> execute ( array ( $delivertime , $queueid ));
}
}
function declareProductBeDelivered ( $queueid ) {
if ( is_numeric ( $queueid )) {
$pdo = $this -> dbutils -> openDbAndReturnPdo ();
$this -> declareProductBeDeliveredWithGivenPdo ( $pdo , $queueid );
2020-11-19 22:59:47 +01:00
}
2020-11-19 22:47:44 +01:00
}
function declareMultipleProductsDelivered ( $queueids ) {
$ids = explode ( " , " , $queueids );
2020-11-19 22:59:47 +01:00
$pdo = DbUtils :: openDbAndReturnPdoStatic ();
2020-11-19 22:47:44 +01:00
$pdo -> beginTransaction ();
for ( $i = 0 ; $i < count ( $ids ); $i ++ ) {
$aQueueId = $ids [ $i ];
if ( is_numeric ( $aQueueId )) {
$this -> declareProductBeDeliveredWithGivenPdo ( $pdo , $aQueueId );
}
}
$pdo -> commit ();
echo json_encode ( array ( " status " => " OK " ));
}
function declareProductNotBeDelivered ( $queueid ) {
2020-11-19 22:54:51 +01:00
$pdo = DbUtils :: openDbAndReturnPdoStatic ();
2020-11-19 22:59:47 +01:00
if ( is_numeric ( $queueid )) {
date_default_timezone_set ( DbUtils :: getTimeZone ());
$delivertime = date ( 'Y-m-d H:i:s' );
2020-11-19 23:00:49 +01:00
$updateSql = " UPDATE %queue% SET delivertime=? WHERE id=? " ;
2020-11-19 22:54:51 +01:00
$stmt = $pdo -> prepare ( DbUtils :: substTableAlias ( $updateSql ));
2020-11-19 23:00:49 +01:00
$stmt -> execute ( array ( null , $queueid ));
2020-11-19 22:47:44 +01:00
}
}
public function getAllPreparedProductsForTableidAsArray ( $pdo , $tableid ) {
if ( ! is_null ( $tableid )) {
$sql = " SELECT DISTINCT %queue%.id as id,tableno,longname,anoption,readytime " ;
if ( $this -> areBillExisting ( $pdo )) {
$sql .= " FROM %queue%,%products%,%resttables%,%bill% " ;
} else {
$sql .= " FROM %queue%,%products%,%resttables% " ;
}
2020-11-19 23:00:46 +01:00
$sql .= " WHERE (readytime IS NOT NULL and delivertime IS NULL " ;
2020-11-19 22:47:44 +01:00
$sql .= " AND %queue%.productid=%products%.id " ;
$sql .= " AND %queue%.tablenr=%resttables%.id " ;
2020-11-19 22:50:09 +01:00
$sql .= " AND %queue%.isclosed is null " ;
2020-11-19 22:47:44 +01:00
$sql .= " AND ordertime is not null " ;
$sql .= " AND %resttables%.id= " . $tableid . " " ;
$sql .= " AND toremove <> '1') " ;
if ( $this -> areBillExisting ( $pdo )) {
// now remove closed items
$sql .= " AND (%queue%.billid is null OR ( " ;
$sql .= " %queue%.billid=%bill%.id AND %bill%.closingid is null)) " ;
}
$sql .= " ORDER BY tableno " ;
} else {
// togo
$sql = " SELECT DISTINCT %queue%.id as id,'' as tableno,longname,anoption,readytime " ;
if ( $this -> areBillExisting ( $pdo )) {
$sql .= " FROM %queue%,%products%,%resttables%,%bill% " ;
} else {
$sql .= " FROM %queue%,%products%,%resttables% " ;
}
2020-11-19 23:00:46 +01:00
$sql .= " WHERE (readytime IS NOT NULL and delivertime IS NULL " ;
2020-11-19 22:47:44 +01:00
$sql .= " AND %queue%.productid=%products%.id " ;
$sql .= " AND %queue%.tablenr is null " ;
$sql .= " AND ordertime is not null " ;
2020-11-19 22:50:09 +01:00
$sql .= " AND %queue%.isclosed is null " ;
2020-11-19 22:47:44 +01:00
$sql .= " AND toremove <> '1') " ;
if ( $this -> areBillExisting ( $pdo )) {
$sql .= " AND (%queue%.billid is null OR ( " ;
$sql .= " %queue%.billid=%bill%.id AND %bill%.closingid is null)) " ;
}
$sql = $sql . " ORDER BY tableno " ;
}
$stmt = $pdo -> prepare ( DbUtils :: substTableAlias ( $sql ));
$stmt -> execute ();
$dbresult = $stmt -> fetchAll ();
2020-11-19 22:59:47 +01:00
// create a table that is optimal (sqrt-like size)
$numberOfIcons = count ( $dbresult );
2020-11-19 22:47:44 +01:00
$arrayOfProdsForTable = array ();
$idsProdsOfTable = '' ; // this is a hack! All queueids of a table redundant for "Deliver all"
2020-11-19 22:59:47 +01:00
foreach ( $dbresult as $zeile ) {
2020-11-19 22:47:44 +01:00
$theAction = " deliver " ;
$longname = $zeile [ 'longname' ];
$extras = $this -> getExtrasOfQueueItem ( null , $zeile [ 'id' ]);
$anProdElem = array (
" id " => $zeile [ 'id' ],
" longname " => $zeile [ 'longname' ],
" option " => $zeile [ 'anoption' ],
" extras " => $extras ,
2020-11-19 22:59:47 +01:00
" status " => " ready_to_deliver " );
2020-11-19 22:47:44 +01:00
$arrayOfProdsForTable [] = $anProdElem ;
if ( $idsProdsOfTable == '' ) {
$idsProdsOfTable = $idsProdsOfTable . $zeile [ 'id' ];
} else {
$idsProdsOfTable = $idsProdsOfTable . ',' . $zeile [ 'id' ];
2020-11-19 22:59:47 +01:00
}
}
2020-11-19 22:47:44 +01:00
return array ( " prods " => $arrayOfProdsForTable , " ids " => $idsProdsOfTable );
}
// total number of products for table
// can later be used for color indication if products can be delivered completly for a table
public function numberOfProductsForTableNotDelivered ( $pdo , $tableid ) {
$sql = " SELECT DISTINCT %queue%.id as id " ;
if ( ! is_null ( $tableid )) {
// not togo
$sql .= " FROM %queue%,%resttables% " ;
} else {
$sql .= " FROM %queue% " ;
}
2020-11-19 23:00:46 +01:00
$sql .= " WHERE delivertime IS NULL " ;
2020-11-19 22:47:44 +01:00
$sql .= " AND ordertime is not null " ;
2020-11-19 22:50:09 +01:00
$sql .= " AND %queue%.isclosed is null " ;
2020-11-19 22:47:44 +01:00
$sql .= " AND workprinted='0' " ;
$sql .= " AND toremove <> '1' " ;
if ( ! is_null ( $tableid )) {
// not togo
$sql .= " AND %queue%.tablenr=%resttables%.id " ;
$sql .= " AND %resttables%.id= " . $tableid ;
} else {
$sql .= " AND %queue%.tablenr is null " ;
}
$stmt = $pdo -> prepare ( DbUtils :: substTableAlias ( $sql ));
$stmt -> execute ();
$dbresult = $stmt -> fetchAll ();
$numberOfProducts = count ( $dbresult );
return $numberOfProducts ;
}
function getJsonAllPreparedProducts () {
$pdo = DbUtils :: openDbAndReturnPdoStatic ();
// find out the tables that are relevant
$sql = " SELECT DISTINCT tablenr " ;
if ( $this -> areBillExisting ( $pdo )) {
$sql .= " FROM %queue%,%resttables%,%bill% " ;
} else {
$sql .= " FROM %queue%,%resttables% " ;
}
2020-11-19 23:00:46 +01:00
$sql .= " WHERE (readytime IS NOT NULL and delivertime IS NULL " ;
2020-11-19 22:47:44 +01:00
$sql .= " AND toremove <> '1' " ;
$sql .= " AND %queue%.tablenr=%resttables%.id AND " ;
$sql .= " ordertime is not null AND " ;
2020-11-19 22:50:09 +01:00
$sql .= " %queue%.isclosed is null AND " ;
2020-11-19 22:47:44 +01:00
$sql .= " %queue%.workprinted='0') " ;
if ( $this -> areBillExisting ( $pdo )) {
2020-11-19 22:59:47 +01:00
// now remove closed items
$sql .= " AND (%queue%.billid is null OR ( " ;
2020-11-19 22:47:44 +01:00
$sql .= " %queue%.billid=%bill%.id AND %bill%.closingid is null)) " ;
}
$sql .= " ORDER BY tablenr " ;
$stmt = $pdo -> prepare ( DbUtils :: substTableAlias ( $sql ));
$stmt -> execute ();
$result1 = $stmt -> fetchAll ();
$sql = " SELECT DISTINCT tablenr " ;
if ( $this -> areBillExisting ( $pdo )) {
$sql .= " FROM %queue%,%bill% " ;
} else {
$sql .= " FROM %queue% " ;
}
2020-11-19 23:00:46 +01:00
$sql .= " WHERE (readytime IS NOT NULL and delivertime IS NULL " ;
2020-11-19 22:47:44 +01:00
$sql .= " AND toremove <> '1' " ;
$sql .= " AND %queue%.tablenr is null AND " ;
$sql .= " ordertime is not null AND " ;
2020-11-19 22:50:09 +01:00
$sql .= " %queue%.isclosed is null AND " ;
2020-11-19 22:47:44 +01:00
$sql .= " %queue%.workprinted='0') " ;
if ( $this -> areBillExisting ( $pdo )) {
$sql .= " AND (%queue%.billid is null OR ( " ;
$sql .= " %queue%.billid=%bill%.id AND %bill%.closingid is null)) " ;
}
$stmt = $pdo -> prepare ( DbUtils :: substTableAlias ( $sql ));
$stmt -> execute ();
$result2 = $stmt -> fetchAll ();
$result = array_merge ( $result1 , $result2 );
$tablesToServe = array ();
foreach ( $result as $zeile ) {
$tablesToServe [] = $zeile [ 'tablenr' ];
}
// to sort complete prepared tables use two arrays:
$preparedProds_incomplete_tables = array ();
$preparedProds = array ();
$commonUtils = new CommonUtils ();
foreach ( $tablesToServe as $tableid ) {
$arrayOfProdsAndIdsOfATable = $this -> getAllPreparedProductsForTableidAsArray ( $pdo , $tableid );
$arrayOfProdsOfATable = $arrayOfProdsAndIdsOfATable [ 'prods' ];
$numberOfProductsTotalToServe = $this -> numberOfProductsForTableNotDelivered ( $pdo , $tableid );
$numberOfReadyProducts = count ( $arrayOfProdsOfATable );
if ( $numberOfReadyProducts >= $numberOfProductsTotalToServe ) {
$tablestatus = " complete " ;
2020-11-19 22:54:51 +01:00
$tableheadeline = $commonUtils -> getTableNameFromId ( $pdo , $tableid );
2020-11-19 22:47:44 +01:00
$preparedProds [] = array (
" tableheadline " => $tableheadeline ,
2020-11-19 22:59:47 +01:00
" tableid " => $tableid ,
2020-11-19 22:47:44 +01:00
" tablestatus " => $tablestatus ,
2020-11-19 22:59:47 +01:00
" ids " => $arrayOfProdsAndIdsOfATable [ 'ids' ],
2020-11-19 22:47:44 +01:00
" prodsOfTable " => $arrayOfProdsOfATable );
} else {
$tablestatus = " incomplete " ;
2020-11-19 22:54:51 +01:00
$tableheadeline = " Tisch: " . $commonUtils -> getTableNameFromId ( $pdo , $tableid );
2020-11-19 22:47:44 +01:00
$preparedProds_incomplete_tables [] = array (
" tableheadline " => $tableheadeline ,
2020-11-19 22:59:47 +01:00
" tableid " => $tableid ,
2020-11-19 22:47:44 +01:00
" tablestatus " => $tablestatus ,
2020-11-19 22:59:47 +01:00
" ids " => $arrayOfProdsAndIdsOfATable [ 'ids' ],
2020-11-19 22:47:44 +01:00
" prodsOfTable " => $arrayOfProdsOfATable );
}
}
2020-11-19 23:00:55 +01:00
$newProdsToServe = self :: getNewProductsToServe ( $pdo );
self :: setNewProductsToServe ( $pdo , 0 );
$items = array_merge ( $preparedProds , $preparedProds_incomplete_tables );
echo json_encode ( array ( " items " => $items , " newproductstoserve " => $newProdsToServe ));
2020-11-19 22:47:44 +01:00
}
/*
* Return as JSON object a list of max 10 entries of products that
* have been delivered to a table
*/
function getJsonLastDeliveredProducts () {
$pdo = DbUtils :: openDbAndReturnPdoStatic ();
// 1. no togo products
$sql = " SELECT DISTINCT %queue%.id as id,tableno,longname,delivertime,anoption,%products%.id as prodid " ;
if ( $this -> areBillExisting ( $pdo )) {
$sql .= " FROM %queue%,%resttables%,%products%,%bill% " ;
} else {
$sql .= " FROM %queue%,%resttables%,%products% " ;
}
2020-11-19 23:00:46 +01:00
$sql .= " WHERE (delivertime IS NOT NULL " ;
2020-11-19 22:59:47 +01:00
$sql .= " AND %queue%.productid=%products%.id " ;
2020-11-19 22:47:44 +01:00
$sql .= " AND %queue%.tablenr=%resttables%.id " ;
$sql .= " AND toremove <> '1' AND " ;
$sql .= " ordertime is not null AND " ;
2020-11-19 22:50:09 +01:00
$sql .= " %queue%.isclosed is null AND " ;
2020-11-19 22:47:44 +01:00
$sql .= " %queue%.workprinted='0') " ;
if ( $this -> areBillExisting ( $pdo )) {
2020-11-19 22:59:47 +01:00
// now remove closed items
$sql .= " AND (%queue%.billid is null OR ( " ;
2020-11-19 22:47:44 +01:00
$sql .= " %queue%.billid=%bill%.id AND %bill%.closingid is null)) " ;
}
$sql = $sql . " ORDER BY delivertime DESC LIMIT 10 " ;
$stmt = $pdo -> prepare ( DbUtils :: substTableAlias ( $sql ));
$stmt -> execute ();
$result1 = $stmt -> fetchAll ();
// 2.togo products
$sql = " SELECT DISTINCT %queue%.id as id,'' as tableno,longname,delivertime,anoption,%products%.id as prodid " ;
if ( $this -> areBillExisting ( $pdo )) {
$sql .= " FROM %queue%,%resttables%,%products%,%bill% " ;
} else {
$sql .= " FROM %queue%,%resttables%,%products% " ;
}
2020-11-19 23:00:46 +01:00
$sql .= " WHERE (delivertime IS NOT NULL " ;
2020-11-19 22:47:44 +01:00
$sql .= " AND %queue%.productid=%products%.id " ;
$sql .= " AND %queue%.tablenr is null " ;
$sql .= " AND toremove <> '1' AND " ;
$sql .= " ordertime is not null AND " ;
2020-11-19 22:50:09 +01:00
$sql .= " %queue%.isclosed is null AND " ;
2020-11-19 22:47:44 +01:00
$sql .= " %queue%.workprinted='0') " ;
if ( $this -> areBillExisting ( $pdo )) {
$sql .= " AND (%queue%.billid is null OR ( " ;
$sql .= " %queue%.billid=%bill%.id AND %bill%.closingid is null)) " ;
}
$sql = $sql . " ORDER BY delivertime DESC LIMIT 10 " ;
$stmt = $pdo -> prepare ( DbUtils :: substTableAlias ( $sql ));
$stmt -> execute ();
$result2 = $stmt -> fetchAll ();
$result = array_merge ( $result1 , $result2 );
$lastDeliveredProds = array ();
foreach ( $result as $zeile ) {
2020-11-19 22:59:47 +01:00
$productid = $zeile [ 'prodid' ];
$useConditions = $this -> getUseKitchenAndSupplyForProd ( $pdo , $productid );
if ( $useConditions [ " usesupply " ] == 1 ) {
2020-11-19 22:47:44 +01:00
// yes, display it in supplydesk view as cooked
$extras = $this -> getExtrasOfQueueItem ( null , $zeile [ 'id' ]);
$deliveredProd = array (
" id " => $zeile [ 'id' ],
" longname " => $zeile [ 'longname' ],
" option " => $zeile [ 'anoption' ],
" extras " => $extras ,
" delivertime " => $zeile [ 'delivertime' ],
2020-11-19 22:59:47 +01:00
" tablename " => $zeile [ 'tableno' ]);
2020-11-19 22:47:44 +01:00
$lastDeliveredProds [] = $deliveredProd ;
2020-11-19 22:59:47 +01:00
}
2020-11-19 22:47:44 +01:00
}
echo json_encode ( $lastDeliveredProds );
}
2020-11-19 22:59:47 +01:00
// **********************************
// * Kasse *
// **********************************
2020-11-19 22:47:44 +01:00
/*
* Test if all queue items with the given ids are not paid
* -> if there are paid items --> report error by return negative value
*
* Set paid column with the given date
* Create bill
* Return a bill id
*/
2020-11-19 23:00:58 +01:00
function declarePaidCreateBillReturnBillId ( $pdo , $ids , $tableid , $paymentId , $declareready , $host , $calledInternally = false , $reservationid , $guestinfo ) {
if ( $reservationid != " " ) {
$reservationid = substr ( $reservationid , 0 , 30 );
}
if ( $guestinfo != " " ) {
$guestinfo = substr ( $guestinfo , 0 , 30 );
}
2020-11-19 22:47:44 +01:00
$userid = $this -> getUserId ();
2020-11-19 23:00:55 +01:00
$ids = trim ( $ids , " , " );
2020-11-19 22:47:44 +01:00
2020-11-19 23:00:55 +01:00
$ids_array = explode ( ',' , $ids );
2020-11-19 23:00:05 +01:00
if ( CommonUtils :: callPlugin ( $pdo , " createBill " , " replace " )) {
return ;
}
CommonUtils :: callPlugin ( $pdo , " createBill " , " before " );
2020-11-19 23:00:55 +01:00
if ( ! $calledInternally ) {
$pdo -> beginTransaction ();
}
2020-11-19 22:47:44 +01:00
2020-11-19 23:00:55 +01:00
// check if all items are not paid yet! Also get rid of empty entries
2020-11-19 22:47:44 +01:00
$allNotPaid = true ;
for ( $i = 0 ; $i < count ( $ids_array ); $i ++ ) {
$anId = $ids_array [ $i ];
if ( is_numeric ( $anId )) {
$sql = " SELECT count(id) as countid FROM %queue% WHERE paidtime is not null AND id=? " ;
2020-11-19 23:00:55 +01:00
$row = CommonUtils :: getRowSqlObject ( $pdo , $sql , array ( $anId ));
2020-11-19 22:59:47 +01:00
if ( $row != null ) {
2020-11-19 22:47:44 +01:00
$aCount = $row -> countid ;
if (( $aCount != null ) && ( $aCount == 1 )) {
$allNotPaid = false ;
}
}
2020-11-19 23:00:55 +01:00
} else {
$allNotPaid = false ;
2020-11-19 22:47:44 +01:00
}
}
2020-11-19 22:59:47 +01:00
// current time
date_default_timezone_set ( DbUtils :: getTimeZone ());
2020-11-19 22:47:44 +01:00
$currentTime = date ( 'Y-m-d H:i:s' );
$billid = ( - 1 );
if ( $allNotPaid == true ) {
$billid = - 1 ;
$sql = " SELECT id from %bill% ORDER BY id DESC " ;
2020-11-19 22:59:47 +01:00
$stmt = $pdo -> prepare ( $this -> dbutils -> resolveTablenamesInSqlString ( $sql ));
2020-11-19 22:47:44 +01:00
$stmt -> execute ();
$numberOfIds = $stmt -> rowCount ();
2020-11-19 22:58:20 +01:00
$newprevbrutto = 0 ;
$newprevnetto = 0 ;
2020-11-19 22:47:44 +01:00
if ( $numberOfIds > 0 ) {
2020-11-19 22:59:47 +01:00
$row = $stmt -> fetchObject ();
2020-11-19 22:47:44 +01:00
if ( $row != null ) {
$billid = intval ( $row -> id ) + 1 ;
2020-11-19 22:58:20 +01:00
$sql = " SELECT brutto,netto,prevbrutto,prevnetto FROM %bill% WHERE id=? " ;
2020-11-19 23:00:55 +01:00
$row = CommonUtils :: getRowSqlObject ( $pdo , $sql , array ( $row -> id ));
2020-11-19 22:58:20 +01:00
$newprevbrutto = $row -> prevbrutto + $row -> brutto ;
$newprevnetto = $row -> prevnetto + $row -> netto ;
2020-11-19 22:47:44 +01:00
} else {
2020-11-19 23:00:55 +01:00
if ( ! $calledInternally ) {
echo " - row ist null - " ;
$pdo -> rollBack ();
}
2020-11-19 22:47:44 +01:00
return ;
}
} else {
$billid = 1 ;
}
// Test if it is allowed to use this billid or if manipulation has happened
if ( ! $this -> commonUtils -> verifyLastBillId ( $pdo , $billid )) {
2020-11-19 23:00:55 +01:00
if ( ! $calledInternally ) {
echo json_encode ( array ( " status " => " ERROR " , " code " => ERROR_INCONSISTENT_DB , " msg " => ERROR_INCONSISTENT_DB_MSG ));
$pdo -> rollBack ();
}
2020-11-19 22:47:44 +01:00
return ;
} else {
// ok - then increment that last id in the work table
$this -> commonUtils -> setLastBillIdInWorkTable ( $pdo , $billid );
}
if ( is_null ( $tableid )) {
$tableid = 0 ;
}
2020-11-19 23:00:55 +01:00
$idlist = join ( " ',' " , $ids_array );
$sql = " SELECT SUM(price) as brutto,ROUND(SUM(price)/(1 + %queue%.tax/100.0),2) as netto FROM %queue% WHERE id IN (' $idlist ') " ;
$row = CommonUtils :: getRowSqlObject ( $pdo , $sql , null );
$brutto = $row -> brutto ;
$netto = $row -> netto ;
2020-11-19 22:47:44 +01:00
// now calculate the signature for the bill entry
$signature = $this -> commonUtils -> calcSignatureForBill ( $pdo , $currentTime , $brutto , $netto , '0.00' , $userid );
2020-11-19 23:00:58 +01:00
$billInsertSql = " INSERT INTO `%bill%` (`id` , `billdate`,`brutto`,`netto`,`prevbrutto`,`prevnetto`,`tableid`,`paymentid`,`userid`,`ref`,`tax`,`host`,`reservationid`,`guestinfo`,`signature`) VALUES (?,?,?,?,?,?,?,?,?,NULL,NULL,?,?,?,?) " ;
2020-11-19 22:47:44 +01:00
$stmt = $pdo -> prepare ( $this -> dbutils -> resolveTablenamesInSqlString ( $billInsertSql ));
2020-11-19 23:00:58 +01:00
$stmt -> execute ( array ( $billid , $currentTime , $brutto , $netto , $newprevbrutto , $newprevnetto , $tableid , $paymentId , $userid , $host , $reservationid , $guestinfo , $signature ));
2020-11-19 22:47:44 +01:00
// now declare them all to be paid:
2020-11-19 22:59:47 +01:00
for ( $i = 0 ; $i < count ( $ids_array ); $i ++ ) {
$queueid = $ids_array [ $i ];
2020-11-19 22:47:44 +01:00
if ( is_numeric ( $queueid )) {
if ( $declareready == 0 ) {
2020-11-19 22:59:47 +01:00
$updateSql = " UPDATE %queue% SET paidtime=?, billid=? WHERE id=? " ;
2020-11-19 22:47:44 +01:00
$stmt = $pdo -> prepare ( DbUtils :: substTableAlias ( $updateSql ));
$stmt -> execute ( array ( $currentTime , $billid , $queueid ));
} else {
$updateSql = " UPDATE %queue% SET paidtime=?, billid=?,readytime=?,delivertime=? WHERE id=? " ;
$stmt = $pdo -> prepare ( DbUtils :: substTableAlias ( $updateSql ));
$stmt -> execute ( array ( $currentTime , $billid , $currentTime , $currentTime , $queueid ));
}
$billProdsSql = " INSERT INTO `%billproducts%` (`queueid`,`billid`) VALUES ( ?,?) " ;
2020-11-19 22:59:47 +01:00
$stmt = $pdo -> prepare ( $this -> dbutils -> resolveTablenamesInSqlString ( $billProdsSql ));
2020-11-19 22:47:44 +01:00
$stmt -> execute ( array ( $queueid , $billid ));
}
}
2020-11-19 23:00:58 +01:00
Hotelinterface :: insertIntoHsin ( $pdo , $billid );
2020-11-19 22:47:44 +01:00
}
2020-11-19 23:00:55 +01:00
if ( ! $calledInternally ) {
$pdo -> commit ();
}
2020-11-19 22:47:44 +01:00
$billInfo = array ( " billid " => $billid , " date " => $currentTime );
2020-11-19 23:00:05 +01:00
CommonUtils :: callPlugin ( $pdo , " createBill " , " after " );
2020-11-19 23:00:18 +01:00
CommonUtils :: log ( $pdo , " QUEUE " , " Created bill with id= $billid from user $userid " );
2020-11-19 23:00:55 +01:00
if ( ! $calledInternally ) {
echo json_encode ( array ( " status " => " OK " , " msg " => $billInfo ));
}
2020-11-19 22:47:44 +01:00
}
2020-11-19 22:59:47 +01:00
private function getUserId () {
if ( session_id () == '' ) {
session_start ();
}
return $_SESSION [ 'userid' ];
2020-11-19 22:47:44 +01:00
}
}
?>