ordersprinter/webapp/php/utilities/basedb.php

847 lines
25 KiB
PHP
Raw Normal View History

2020-11-19 22:47:44 +01:00
<?php
class Checks {
private function checkwriteaccessconfigfolder() {
return (is_writable("../php"));
}
private function checkwriteaccessconfigfile() {
if (file_exists("../php/config.php")) {
return (is_writable("../php/config.php"));
} else {
return (is_writable("../php"));
}
}
private function checkwriteaccessprivkey() {
if (file_exists("../php/privkey.pem")) {
return (is_writable("../php/privkey.pem"));
} else {
return (is_writable("../php"));
}
}
private function checkwriteaccesspubkey() {
if (file_exists("../php/cert.pem")) {
return (is_writable("../php/cert.pem"));
} else {
return (is_writable("../php"));
}
}
private function checkwritecustomerfolder() {
return (is_writable("../customer"));
}
private function checkwritespeisekarte() {
if (file_exists("../customer/speisekarte.txt")) {
return (is_writable("../customer/speisekarte.txt"));
} else {
return (is_writable("../customer"));
}
}
function checkWriteAccess() {
$retArray = array(
"configfolder" => $this->checkwriteaccessconfigfolder(),
"configfile" => $this->checkwriteaccessconfigfile(),
"customerfolder" => $this->checkwritecustomerfolder(),
"speisekarte" => $this->checkwritespeisekarte()
);
echo json_encode($retArray);
}
function checkWriteAccessNoJson() {
return(array(
"configfolder" => $this->checkwriteaccessconfigfolder(),
"configfile" => $this->checkwriteaccessconfigfile(),
"customerfolder" => $this->checkwritecustomerfolder(),
"speisekarte" => $this->checkwritespeisekarte(),
"privkey" => $this->checkwriteaccessprivkey(),
"pubkey" => $this->checkwriteaccesspubkey()
));
}
}
class Basedb {
var $prefix = "";
var $timezone = "Europe/Berlin";
function setPrefix($pre) {
$this->prefix = $pre;
}
function setTimeZone($zone) {
$this->timezone = $zone;
}
function doSQL($pdo,$sql) {
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
$stmt->execute();
}
function doSQLcatch($pdo,$sql) {
try {
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
$stmt->execute();
} catch (Exception $e) {
// nothing - table not present or whatever...
}
}
function resolveTablenamesInSqlString($sqlString) {
2020-11-19 23:02:12 +01:00
return DbUtils::substTableAliasCore($sqlString, $this->prefix);
2020-11-19 22:47:44 +01:00
}
function dropTables($pdo) {
2020-11-19 23:00:58 +01:00
$this->doSQLcatch($pdo, "DROP TABLE `%hsout%`");
$this->doSQLcatch($pdo, "DROP TABLE `%hsin%`");
2020-11-19 22:47:44 +01:00
$this->doSQLcatch($pdo, "DROP TABLE `%comments%`");
$this->doSQLcatch($pdo, "DROP TABLE `%reservations%`");
$this->doSQLcatch($pdo, "DROP TABLE `%work%`");
$this->doSQLcatch($pdo, "DROP TABLE `%hist%`");
$this->doSQLcatch($pdo, "DROP TABLE `%histprod%`");
$this->doSQLcatch($pdo, "DROP TABLE `%histconfig%`");
$this->doSQLcatch($pdo, "DROP TABLE `%histuser%`");
$this->doSQLcatch($pdo, "DROP TABLE `%histactions%`");
$this->doSQLcatch($pdo, "drop TABLE `%queueextras%`");
$this->doSQLcatch($pdo, "drop TABLE `%extrasprods%`");
$this->doSQLcatch($pdo, "drop TABLE `%extras%`");
$this->doSQLcatch($pdo, "drop TABLE `%billproducts%`");
$this->doSQLcatch($pdo, "drop TABLE `%queue%`");
$this->doSQLcatch($pdo, "drop TABLE `%printjobs%`");
2020-11-19 23:02:12 +01:00
$this->doSQLcatch($pdo, "drop TABLE `%customerlog%`");
2020-11-19 22:47:44 +01:00
$this->doSQLcatch($pdo, "drop TABLE `%bill%`");
$this->doSQLcatch($pdo, "drop TABLE `%ratings%`");
$this->doSQLcatch($pdo, "drop TABLE `%user%`");
$this->doSQLcatch($pdo, "drop TABLE `%closing%`");
$this->doSQLcatch($pdo, "drop TABLE `%config%`");
$this->doSQLcatch($pdo, "drop TABLE `%products%`");
$this->doSQLcatch($pdo, "drop TABLE `%prodtype%`");
$this->doSQLcatch($pdo, "drop TABLE `%pricelevel%`");
$this->doSQLcatch($pdo, "drop TABLE `%tablepos%`");
$this->doSQLcatch($pdo, "drop TABLE `%tablemaps%`");
$this->doSQLcatch($pdo, "drop TABLE `%resttables%`");
$this->doSQLcatch($pdo, "drop TABLE `%room%`");
$this->doSQLcatch($pdo, "drop TABLE `%payment%`");
2020-11-19 23:02:08 +01:00
$this->doSQLcatch($pdo, "drop TABLE `%groupcustomer%`");
$this->doSQLcatch($pdo, "drop TABLE `%vacations%`");
$this->doSQLcatch($pdo, "drop TABLE `%groups%`");
$this->doSQLcatch($pdo, "drop TABLE `%customers%`");
2020-11-19 22:47:44 +01:00
$this->doSQLcatch($pdo, "drop TABLE `%logo%`");
2020-11-19 23:00:18 +01:00
$this->doSQLcatch($pdo, "drop TABLE `%log%`");
2020-11-19 22:47:44 +01:00
}
2020-11-19 23:02:12 +01:00
2020-11-19 22:47:44 +01:00
2020-11-19 23:02:12 +01:00
function createCustomerLogTable($pdo) {
$sql = "
CREATE TABLE `%customerlog%` (
`id` INT (3) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`date` DATETIME NULL,
`customerid` INT(10) NULL,
`billid` INT(10) NULL,
`action` INT(2) NULL,
`userid` INT(3) NULL,
`remark` VARCHAR ( 500 ) NULL,
FOREIGN KEY (billid) REFERENCES %bill%(id),
FOREIGN KEY (customerid) REFERENCES %customers%(id),
FOREIGN KEY (userid) REFERENCES %user%(id)
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb
";
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
$stmt->execute();
2020-11-19 23:00:18 +01:00
}
function createLogTable($pdo) {
$sql = "
CREATE TABLE `%log%` (
`id` INT (3) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`date` DATETIME NULL,
`component` VARCHAR ( 20 ) NULL,
`message` VARCHAR ( 500 ) NULL
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb
";
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
$stmt->execute();
2020-11-19 22:47:44 +01:00
}
function createPaymentTable($pdo) {
$sql = "
CREATE TABLE `%payment%` (
`id` INT (3) NOT NULL UNIQUE,
`name` VARCHAR ( 20 ) NOT NULL,
`name_en` VARCHAR ( 20 ) NOT NULL,
`name_esp` VARCHAR ( 20 ) NOT NULL
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb
";
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
$stmt->execute();
}
function createUserTable($pdo)
{
$sql = "
CREATE TABLE `%user%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`username` VARCHAR ( 150 ) NOT NULL,
`userpassword` VARCHAR ( 150 ) NOT NULL,
`is_admin` INT (1) NOT NULL,
`right_waiter` INT (1) NOT NULL,
`right_kitchen` INT (1) NOT NULL,
`right_bar` INT (1) NOT NULL,
`right_supply` INT (1) NOT NULL,
`right_paydesk` INT (1) NOT NULL,
`right_statistics` INT (1) NOT NULL,
`right_bill` INT (1) NOT NULL,
`right_products` INT (1) NOT NULL,
`right_manager` INT (1) NOT NULL,
2020-11-19 22:59:47 +01:00
`right_closing` INT (1) NOT NULL,
2020-11-19 22:47:44 +01:00
`right_reservation` INT (1) NOT NULL,
`right_rating` INT (1) NOT NULL,
`right_changeprice` INT (1) NOT NULL,
2020-11-19 23:02:08 +01:00
`right_customers` INT (1) NOT NULL,
2020-11-19 22:47:44 +01:00
`lastmodule` VARCHAR ( 30 ) NULL,
`ordervolume` INT (2) NULL,
`language` INT (2) NULL,
2020-11-19 23:02:42 +01:00
`mobiletheme` INT(2) NULL,
2020-11-19 22:47:44 +01:00
`receiptprinter` INT (1) NULL,
`roombtnsize` INT(1) NULL,
`tablebtnsize` INT(1) NULL,
`prodbtnsize` INT(1) NULL,
`prefertablemap` INT(1) NULL,
2020-11-19 22:48:24 +01:00
`keeptypelevel` INT(1) NOT NULL,
2020-11-19 22:53:50 +01:00
`extrasapplybtnpos` INT(1) NOT NULL,
2020-11-19 23:02:49 +01:00
`failedlogins` VARCHAR(20) NULL,
2020-11-19 22:47:44 +01:00
`active` INT (2) NOT NULL
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$this->doSQL($pdo,$sql);
}
function createRoomTable($pdo)
{
$sql = "
CREATE TABLE `%room%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`roomname` VARCHAR ( 150 ) NOT NULL,
2020-11-19 22:55:09 +01:00
`abbreviation` VARCHAR (10) NULL,
2020-11-19 22:47:44 +01:00
`printer` INT(2) NULL,
`removed` INT(2) NULL,
`sorting` INT(2) NULL
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
$stmt->execute();
}
function createTableMapsTable($pdo)
{
$sql = "
CREATE TABLE `%tablemaps%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`roomid` INT (10) NOT NULL,
`img` MEDIUMBLOB,
`sizex` INT(4) NULL,
`sizey` INT(4) NULL,
FOREIGN KEY (roomid) REFERENCES %room%(id)
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
}
function createTablePosTable($pdo)
{
$sql = "
CREATE TABLE `%tablepos%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`tableid` INT (10) NOT NULL,
`x` INT(4) NULL,
`y` INT(4) NULL,
FOREIGN KEY (tableid) REFERENCES %resttables%(id)
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
}
function createRestTables($pdo)
{
$sql = "
CREATE TABLE `%resttables%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`tableno` VARCHAR ( 150 ) NOT NULL,
`roomid` INT ( 10 ) NOT NULL,
`removed` INT(2) NULL,
`sorting` INT(2) NULL,
FOREIGN KEY (roomid) REFERENCES %room%(id)
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
$stmt->execute();
}
function createConfigTable($pdo) {
$sql = "
CREATE TABLE `%config%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR ( 1000 ) ,
`setting` VARCHAR ( 10000 )
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
$stmt->execute();
}
function createLogoTable($pdo) {
$sql = "
CREATE TABLE `%logo%` (
`id` INT (2) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR ( 100 ) ,
`setting` BLOB
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
$stmt->execute();
}
function createProdTypeTable($pdo)
{
$sql = "
CREATE TABLE `%prodtype%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR ( 150 ) NOT NULL,
`usekitchen` INT(1) NOT NULL,
`usesupplydesk` INT(1) NOT NULL,
`kind` INT(2) NOT NULL,
`printer` INT(2) NULL,
`sorting` INT(2) NULL,
`reference` INT (10) NULL,
`removed` INT(1) NULL,
FOREIGN KEY (reference) REFERENCES %prodtype%(id)
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$this->doSQL($pdo,$sql);
}
function createExtrasTable($pdo) {
$sql = "
CREATE TABLE `%extras%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR ( 150 ) NOT NULL,
2020-11-19 23:00:58 +01:00
`price` " . DECIMALSMALL . " NOT NULL,
2020-11-19 22:47:44 +01:00
`removed` INT(1) NULL
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$this->doSQL($pdo,$sql);
}
function createExtrasprodsTable($pdo) {
$sql = "
CREATE TABLE `%extrasprods%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`extraid` INT (10) NOT NULL,
`prodid` INT (10) NOT NULL,
FOREIGN KEY (extraid) REFERENCES %extras%(id),
FOREIGN KEY (prodid) REFERENCES %products%(id)
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$this->doSQL($pdo,$sql);
}
function createQueueExtrasTable($pdo) {
$sql = "
CREATE TABLE `%queueextras%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`queueid` INT (10) NOT NULL,
`extraid` INT (10) NOT NULL,
`name` VARCHAR (200) NOT NULL,
FOREIGN KEY (extraid) REFERENCES %extras%(id),
FOREIGN KEY (queueid) REFERENCES %queue%(id)
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$this->doSQL($pdo,$sql);
}
function createProductTable($pdo)
{
$sql = "
CREATE TABLE `%products%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`shortname` VARCHAR ( 150 ) NOT NULL,
`longname` VARCHAR ( 150 ) NOT NULL,
2020-11-19 23:00:05 +01:00
`priceA` " . DECIMALSMALL . " NULL,
`priceB` " . DECIMALSMALL . " NULL,
`priceC` " .DECIMALSMALL . " NULL,
2020-11-19 23:02:49 +01:00
`unit` INT(2) NULL,
`days` VARCHAR(20) NULL,
2020-11-19 23:00:05 +01:00
`tax` " . DECIMALSMALL . " NULL,
2020-11-19 23:00:31 +01:00
`taxaustria` INT(1) NULL,
`amount` INT(5) NULL,
2020-11-19 22:47:44 +01:00
`category` INT(3) NULL,
`favorite` INT(1) NULL,
`sorting` INT(2) NULL,
`available` INT(2) NOT NULL,
`audio` VARCHAR ( 150 ) NULL,
`removed` INT(1) NULL,
FOREIGN KEY (category) REFERENCES %prodtype%(id)
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$this->doSQL($pdo,$sql);
}
function createPriceLevelTable($pdo) {
$sql = "
CREATE TABLE `%pricelevel%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR ( 1000 ) ,
`info` VARCHAR ( 1000 ),
`info_en` VARCHAR ( 1000 ) ,
`info_esp` VARCHAR ( 1000 )
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
$stmt->execute();
}
function createClosingTable($pdo) {
$sql = "
CREATE TABLE `%closing%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`closingdate` DATETIME NOT NULL ,
`billcount` INT(5) NOT NULL ,
2020-11-19 23:00:05 +01:00
`billsum` " . DECIMALBIG . " NOT NULL ,
2020-11-19 22:58:23 +01:00
`signature` blob NULL,
2020-11-19 22:47:44 +01:00
`remark` VARCHAR ( 1000 )
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
$stmt->execute();
}
function createRatingsTable($pdo) {
$sql = "
CREATE TABLE `%ratings%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`date` DATETIME NOT NULL ,
`service` INT(2) NULL,
`kitchen` INT(2) NULL,
`remark` VARCHAR ( 200 ) NULL
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
$stmt->execute();
}
function createBillTable($pdo)
{
$sql = "
CREATE TABLE `%bill%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`billdate` DATETIME NOT NULL ,
2020-11-19 23:00:05 +01:00
`brutto` " . DECIMALMIDDLE . " NULL,
`netto` " . DECIMALMIDDLE . " NULL,
`prevbrutto` " . DECIMALBIG . " NULL,
`prevnetto` " . DECIMALBIG . " NULL,
2020-11-19 22:47:44 +01:00
`tableid` VARCHAR ( 150 ) NOT NULL,
`closingid` INT(4) NULL,
`status` VARCHAR(2) NULL,
`paymentid` INT(2) NULL,
`userid` INT(3) NULL,
`ref` INT(10) NULL,
2020-11-19 23:00:05 +01:00
`tax` " . DECIMALSMALL . " NULL,
2020-11-19 22:47:44 +01:00
`host` INT(2) NULL,
2020-11-19 22:52:25 +01:00
`reason` VARCHAR ( 150 ) NULL,
2020-11-19 23:00:58 +01:00
`reservationid` VARCHAR( 30 ) NULL,
`guestinfo` VARCHAR( 30 ) NULL,
2020-11-19 23:02:08 +01:00
`intguestid` INT(10) NULL,
`intguestpaid` INT(2) NULL,
2020-11-19 22:58:23 +01:00
`signature`blob NULL,
2020-11-19 23:00:58 +01:00
FOREIGN KEY (closingid) REFERENCES %closing%(id),
2020-11-19 22:47:44 +01:00
FOREIGN KEY (paymentid) REFERENCES %payment%(id),
FOREIGN KEY (userid) REFERENCES %user%(id),
2020-11-19 23:02:08 +01:00
FOREIGN KEY (ref) REFERENCES %bill%(id),
FOREIGN KEY (intguestid) REFERENCES %customers%(id)
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
$stmt->execute();
}
function createCustomersTable($pdo)
{
$sql = "
CREATE TABLE `%customers%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR(50) NULL,
`address` VARCHAR(200) NULL,
`email` VARCHAR(50) NULL,
`phone` VARCHAR(30) NULL,
`mobil` VARCHAR(30) NULL,
`www` VARCHAR(50) NULL,
2020-11-19 23:02:19 +01:00
`hello` VARCHAR(100) NULL,
`regards` VARCHAR(100) NULL,
2020-11-19 23:02:08 +01:00
`remark` VARCHAR(500) NULL,
`created` DATETIME NULL,
`lastmodified` DATETIME NULL
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
$stmt->execute();
}
function createGroupsTable($pdo)
{
$sql = "
CREATE TABLE `%groups%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR(50) NULL,
`remark` VARCHAR(200) NULL,
`created` DATETIME NULL
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
$stmt->execute();
}
function createGroupCustomerTable($pdo)
{
$sql = "
CREATE TABLE `%groupcustomer%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`groupid` INT(10) NOT NULL,
`customerid` INT(10) NOT NULL,
FOREIGN KEY (groupid) REFERENCES %groups%(id),
FOREIGN KEY (customerid) REFERENCES %customers%(id)
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
$stmt->execute();
}
function createVacationsTable($pdo)
{
$sql = "
CREATE TABLE `%vacations%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`customerid` INT(10) NOT NULL,
`checkin` DATE NULL,
`checkout` DATE NULL,
`room` VARCHAR(50) NULL,
`remark` VARCHAR(200) NULL,
FOREIGN KEY (customerid) REFERENCES %customers%(id)
2020-11-19 22:47:44 +01:00
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
$stmt->execute();
}
/*
* Create the queue table:
* action: P=Pay, S=Storno
*/
function createQueueTable($pdo)
{
$sql = "
CREATE TABLE `%queue%` (
`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`tablenr` INT( 3 ) NULL ,
`productid` INT( 10 ) NULL ,
`pricelevel` INT( 3 ) NOT NULL ,
2020-11-19 23:00:05 +01:00
`price` " . DECIMALSMALL . " NOT NULL,
`tax` " . DECIMALSMALL . " NOT NULL,
2020-11-19 23:00:31 +01:00
`taxaustria` INT(1) NULL,
2020-11-19 22:47:44 +01:00
`productname` VARCHAR( 150 ) NULL,
`ordertime` DATETIME NULL ,
`orderuser` INT(10) NOT NULL ,
`anoption` VARCHAR( 150 ) NULL ,
2020-11-19 22:55:20 +01:00
`pricechanged` INT(1) NULL ,
`togo` INT(1) NULL ,
2020-11-19 23:00:46 +01:00
`readytime` DATETIME NULL,
2020-11-19 22:47:44 +01:00
`delivertime` DATETIME NULL,
`paidtime` DATETIME NULL,
`billid` INT(10),
`toremove` INT(3) NOT NULL,
`cooking` INT(10) NULL,
`workprinted` INT(2) NOT NULL,
2020-11-19 22:50:09 +01:00
`isclosed` INT(1) NULL,
2020-11-19 22:47:44 +01:00
FOREIGN KEY (tablenr) REFERENCES %resttables%(id),
FOREIGN KEY (pricelevel) REFERENCES %pricelevel%(id),
FOREIGN KEY (productid) REFERENCES %products%(id),
2020-11-19 23:00:58 +01:00
FOREIGN KEY (billid) REFERENCES %bill%(id),
2020-11-19 22:47:44 +01:00
FOREIGN KEY (cooking) REFERENCES %user%(id),
FOREIGN KEY (orderuser) REFERENCES %user%(id)
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$this->doSQL($pdo,$sql);
}
function createBillProductsTable($pdo) {
$sql = "
CREATE TABLE `%billproducts%` (
`queueid` INT( 10 ) NOT NULL,
`billid` INT(10) NOT NULL,
FOREIGN KEY (queueid) REFERENCES %queue%(id),
2020-11-19 23:00:58 +01:00
FOREIGN KEY (billid) REFERENCES %bill%(id)
2020-11-19 22:47:44 +01:00
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$this->doSQL($pdo,$sql);
}
function createHistTables($pdo) {
$sql = "
CREATE TABLE `%hist%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`date` DATETIME NOT NULL ,
`action` INT ( 2 ) NOT NULL,
`refid` INT (10) NULL
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb
";
$this->doSQL($pdo,$sql);
$sql = "
CREATE TABLE `%histprod%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`prodid` INT (10) NOT NULL,
`shortname` VARCHAR ( 150 ) NOT NULL,
`longname` VARCHAR ( 150 ) NOT NULL,
2020-11-19 23:00:05 +01:00
`priceA` " . DECIMALSMALL . " NULL,
`priceB` " . DECIMALSMALL . " NULL,
`priceC` " . DECIMALSMALL . " NULL,
2020-11-19 23:02:49 +01:00
`unit` INT(2) NULL,
`days` VARCHAR(20) NULL,
2020-11-19 23:00:05 +01:00
`tax` " . DECIMALSMALL . " NULL,
2020-11-19 23:00:31 +01:00
`taxaustria` INT(1) NULL,
2020-11-19 22:47:44 +01:00
`sorting` INT(2) NULL,
`available` INT(2) NOT NULL,
`favorite` INT(1) NULL,
`audio` VARCHAR ( 150 ) NULL,
2020-11-19 23:00:35 +01:00
`extras` VARCHAR ( 300 ) NULL,
2020-11-19 22:47:44 +01:00
FOREIGN KEY (prodid) REFERENCES %products%(id)
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb
";
$this->doSQL($pdo,$sql);
$sql = "
CREATE TABLE `%histconfig%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`configid` INT (10) ,
`setting` VARCHAR ( 10000 ),
FOREIGN KEY (configid) REFERENCES %config%(id)
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb
";
$this->doSQL($pdo,$sql);
$sql = "
CREATE TABLE `%histuser%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`userid` INT (10) ,
`username` VARCHAR ( 150 ) NOT NULL,
`is_admin` INT (1) NOT NULL,
`right_waiter` INT (1) NOT NULL,
`right_kitchen` INT (1) NOT NULL,
`right_bar` INT (1) NOT NULL,
`right_supply` INT (1) NOT NULL,
`right_paydesk` INT (1) NOT NULL,
`right_statistics` INT (1) NOT NULL,
`right_bill` INT (1) NOT NULL,
`right_products` INT (1) NOT NULL,
`right_manager` INT (1) NOT NULL,
2020-11-19 22:59:47 +01:00
`right_closing` INT (1) NOT NULL,
2020-11-19 22:47:44 +01:00
`right_reservation` INT (1) NOT NULL,
`right_rating` INT (1) NOT NULL,
`right_changeprice` INT (1) NOT NULL,
2020-11-19 23:02:08 +01:00
`right_customers` INT (1) NOT NULL,
2020-11-19 22:47:44 +01:00
`active` INT (2) NOT NULL,
FOREIGN KEY (userid) REFERENCES %user%(id)
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb
";
$this->doSQL($pdo,$sql);
$sql = "
CREATE TABLE `%histactions%` (
`id` INT (3) NOT NULL,
`name` VARCHAR ( 20 ) NOT NULL,
`description` VARCHAR ( 150 ) NULL
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb
";
$this->doSQL($pdo,$sql);
}
function createPrintJobsTable($pdo) {
$sql = "
CREATE TABLE `%printjobs%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`content` TEXT NOT NULL ,
`type` INT (2) NOT NULL ,
`printer` INT(2) NULL
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
$stmt->execute();
}
function createWorkTable($pdo) {
$sql = "
CREATE TABLE `%work%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`item` VARCHAR ( 20 ) NOT NULL ,
`value` VARCHAR ( 20 ) NOT NULL ,
2020-11-19 22:58:23 +01:00
`signature` blob NULL
2020-11-19 22:47:44 +01:00
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
$stmt->execute();
}
function getPrivkey($pdo) {
$sql = "SELECT signature FROM %work% WHERE item=?";
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
$stmt->execute(array("privkey"));
$row = $stmt->fetchObject();
$privkey = $row->signature;
return(openssl_get_privatekey($privkey));
}
function signLastBillid($pdo) {
$sql = "SELECT MAX(id) as maxbillid FROM %bill%";
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
$stmt->execute();
$row =$stmt->fetchObject();
if ($row != null) {
$lastBillId = $row->maxbillid;
} else {
$lastBillId = 0;
}
$pkeyid = $this->getPrivkey($pdo);
$lastBillId = intval($lastBillId);
openssl_sign("B($lastBillId)", $signature, $pkeyid);
openssl_free_key($pkeyid);
$signature = base64_encode($signature);
$sql = "SELECT id FROM %work% WHERE item=?";
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
$stmt->execute(array("lastbillid"));
if ($stmt->rowCount() > 0) {
$sql = "UPDATE %work% SET value=?, signature=? WHERE item=?";
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
$stmt->execute(array($lastBillId,$signature,"lastbillid"));
} else {
$sql = "INSERT INTO `%work%` (`id` , `item`,`value`,`signature`) VALUES ( NULL,?,?,?)";
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
$stmt->execute(array("lastbillid",$lastBillId,$signature));
}
}
2020-11-19 23:00:58 +01:00
function createHsinTable($pdo) {
$sql = "
CREATE TABLE `%hsin%` (
`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`reservationid` VARCHAR( 30 ) NULL ,
`billid` INT(10) NULL,
`date` VARCHAR( 10 ) NULL,
`time` VARCHAR( 5 ) NULL,
`number` INT(10) NULL,
`prodid` INT(10) NULL,
`prodname` VARCHAR( 100 ) NULL,
`tax` VARCHAR( 50 ) NULL,
`brutto` " . DECIMALSMALL . " NOT NULL,
`total` " . DECIMALSMALL . " NOT NULL,
`currency` VARCHAR( 5 ) NULL,
`waiterid` VARCHAR( 20 ) NULL,
`waitername` VARCHAR( 20 ) NULL
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$this->doSQL($pdo,$sql);
}
function createHsoutTable($pdo) {
$sql = "
CREATE TABLE `%hsout%` (
`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`reservationid` VARCHAR( 50 ) NULL ,
`object` VARCHAR( 50 ) NULL ,
`guest` VARCHAR( 100 ) NULL
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$this->doSQL($pdo,$sql);
}
2020-11-19 22:47:44 +01:00
function createCommentsTable($pdo) {
$sql = "
CREATE TABLE `%comments%` (
`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`comment` VARCHAR( 150 ) NULL ,
`prodid` INT (10) NULL ,
`sorting` INT(2) NULL,
`active` INT (2) NOT NULL,
FOREIGN KEY (prodid) REFERENCES %products%(id)
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$this->doSQL($pdo,$sql);
}
function createReservationsTable($pdo) {
$sql = "
CREATE TABLE `%reservations%` (
`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`creator` INT (10) NOT NULL,
`creationdate` DATETIME NOT NULL,
`scheduledate` DATETIME NOT NULL,
`name` VARCHAR( 100 ) NULL,
`email` VARCHAR( 100 ) NULL,
`starttime` INT (3) NOT NULL,
`duration` INT (3) NOT NULL,
`persons` INT (10) NULL,
`phone` VARCHAR( 40 ) NULL,
`remark` VARCHAR( 400 ) NULL,
FOREIGN KEY (creator) REFERENCES %user%(id)
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$this->doSQL($pdo,$sql);
}
function createEmptyTables($pdo)
{
2020-11-19 23:00:18 +01:00
$this->createLogTable($pdo);
2020-11-19 22:47:44 +01:00
$this->createPaymentTable($pdo);
$this->createUserTable($pdo);
$this->createRoomTable($pdo);
$this->createRestTables($pdo);
$this->createTableMapsTable($pdo);
$this->createTablePosTable($pdo);
$this->createConfigTable($pdo);
$this->createProdTypeTable($pdo);
$this->createProductTable($pdo);
$this->createPriceLevelTable($pdo);
$this->createClosingTable($pdo);
$this->createRatingsTable($pdo);
2020-11-19 23:02:08 +01:00
$this->createCustomersTable($pdo);
$this->createGroupsTable($pdo);
$this->createGroupCustomerTable($pdo);
$this->createVacationsTable($pdo);
2020-11-19 22:47:44 +01:00
$this->createBillTable($pdo);
2020-11-19 23:02:12 +01:00
$this->createCustomerLogTable($pdo);
2020-11-19 22:47:44 +01:00
$this->createQueueTable($pdo);
$this->createBillProductsTable($pdo);
$this->createHistTables($pdo);
$this->createPrintJobsTable($pdo);
$this->createWorkTable($pdo);
$this->createCommentsTable($pdo);
2020-11-19 23:00:58 +01:00
$this->createHsinTable($pdo);
$this->createHsoutTable($pdo);
2020-11-19 22:47:44 +01:00
$this->createReservationsTable($pdo);
$this->createLogoTable($pdo);
$this->createExtrasTable($pdo);
$this->createExtrasprodsTable($pdo);
$this->createQueueExtrasTable($pdo);
2020-11-19 23:02:08 +01:00
2020-11-19 22:47:44 +01:00
}
}
?>