format('Y-m-d'); $previousmonth = date("Y-m", strtotime("first day of previous month")) . "-01"; $secondDayOfPreviosMonth = date("Y-m", strtotime("first day of previous month")) . "-02"; $thirdDayOfPreviosMonth = date("Y-m", strtotime("first day of previous month")) . "-03"; $sql = "SELECT id,priceA as price FROM %products% WHERE available='1' AND unit is NULL AND removed is null ORDER BY id LIMIT 40"; $prods = CommonUtils::fetchSqlAll($pdo, $sql); if (count($prods) == 0) { echo json_encode(array("status" => "ERROR","msg" => "Keine bestellbaren Produkte vorhanden")); return; } $sql = "SELECT id from %resttables% WHERE active='1' AND removed is null ORDER BY roomid,sorting LIMIT 18"; $tablesCore = CommonUtils::fetchSqlAll($pdo, $sql); if (count($tablesCore) == 0) { echo json_encode(array("status" => "ERROR","msg" => "Keine aktiven Tische angelegt")); return; } $sql = "SELECT id FROM %user% WHERE active=1 ORDER BY id"; $users = CommonUtils::fetchSqlAll($pdo, $sql); if (count($users) == 0) { echo json_encode(array("status" => "ERROR","msg" => "Keine aktiven Benutzer angelegt")); return; } $tables = self::createDemoForADate($pdo, $previousmonth, $users, $prods, $tablesCore); $tables = self::createSomeBills($pdo, $tables, $users, $secondDayOfPreviosMonth); // TODO: cash insert! Bill::doCashActionCore(123.45, "Bareinlage 1", $previousmonth . " 18:31:00", $users[0]["id"]); if (count($users) > 1) { Bill::doCashActionCore(234.56, "Bareinlage 2", $previousmonth . " 18:42:00", $users[1]["id"]); } $billModule = new Bill(); $ok = $billModule->cancelBill($pdo, $tables[0]["billid"], "", "Demo-Storno", false, false, false, 0, $thirdDayOfPreviosMonth . " 22:10:00"); if (count($tables) > 1) { $ok = $billModule->cancelBill($pdo, $tables[2]["billid"], "", "Demo-Storno", false, false, false, 1, $thirdDayOfPreviosMonth . " 22:12:20"); } $dateOfClosing = $thirdDayOfPreviosMonth . " 23:55:00"; $sql = "SELECT closingdate FROM %closing% ORDER BY closingdate DESC LIMIT 1"; $result = CommonUtils::fetchSqlAll($pdo, $sql); if (count($result) > 0) { $dateOfClosing = $result[0]["closingdate"]; } $closing = new Closing(); $result = $closing->createClosingCore($pdo, "Tageserfassung letzten Monat", 0, $dateOfClosing, false); $sql = "SELECT closingdate FROM %closing% WHERE DATE(closingdate) >= DATE(NOW() - INTERVAL 2 DAY)"; $result = CommonUtils::fetchSqlAll($pdo, $sql); if (count($result) == 0) { $tables = self::createDemoForADate($pdo, $yesterday, $users, $prods, $tablesCore); $tables = self::createSomeBills($pdo, $tables, $users, $yesterday); // TODO: cash insert! Bill::doCashActionCore(200.45, "Bareinlage 1", $today . " 18:30:00", $users[0]["id"]); if (count($users) > 1) { Bill::doCashActionCore(400, "Bareinlage 2", $today . " 18:35:00", $users[1]["id"]); } $result = $closing->createClosingCore($pdo, "Tageserfassung diesen Monat", 0, $yesterday . " 22:00:00", false); $tables = self::createDemoForADate($pdo, $today, $users, $prods, $tablesCore); $tables = self::createSomeBills($pdo, $tables, $users, $today); } // reateNewCustomer($pdo,$name,$email,$addr,$remark,$phone,$mobil,$www,$hello,$regards,$checkin,$checkout,$room) $customersModule = new Customers(); $customersModule->createNewCustomer($pdo, "Max Mustermann", "max@nospam.de", '', '', '', '', '', 'Herr', '', $previousmonth, null, "1"); $customersModule->createNewCustomer($pdo, "Silke Musterfrau", "silke@nospam.de", '', '', '', '', '', 'Frau', '', $previousmonth, null, "2"); $customersModule->createNewCustomer($pdo, "Donald Duck", "donald@nospam.de", '', '', '', '', '', 'Herr', '', $yesterday, null, "3"); $customersModule->createNewCustomer($pdo, "Harry Potter", "harry@nospam.de", '', '', '', '', '', 'Herr', '', $yesterday, null, "4"); $customersModule->createNewCustomer($pdo, "Jack Smith", "jack@nospam.de", '', '', '', '', '', 'Mr', '', $previousmonth, $yesterday, "5"); echo json_encode(array("status" => "OK")); } catch (Exception $ex) { echo json_encode(array("status" => "ERROR","msg" => $ex->getMessage())); } } private static function createDemoForADate($pdo,$dateStr,$users,$prods,$tables) { $prodindex = 0; $userindex = 0; for ($hour = 0; $hour < 18; $hour++, $hour++) { $tableindex = 0; while ($tableindex < count($tables)) { $tableid = $tables[$tableindex]["id"]; $prod = $prods[$prodindex]; $prodElement = array( "changedPrice" => "NO", "extras" => "", "option" => "", "price" => $prod["price"], "prodid" => $prod["id"], "togo" => 0, "unit" => 0, "unitamount" => 1); $prodArr = array($prodElement); $userid = $users[$userindex]["id"]; $time = $dateStr . " " . self::leadingzeronumber($hour) . ":05:20"; $ret = QueueContent::addProductListToQueueCore($pdo, $time, $tableid, $prodArr, 0, 's', $userid); if ($ret["status"] != "OK") { echo json_encode($ret); return; } if (!isset($tables[$tableindex]["queueids"])) { $tables[$tableindex]["queueids"] = []; } $tables[$tableindex]["queueids"] = array_merge($tables[$tableindex]["queueids"], $ret['queueids']); $prodindex = ($prodindex + 1) % count($prods); $userindex = ($userindex + 1) % count($users); $tableindex += 2; } } return $tables; } private static function createSomeBills($pdo,$tables,$users,$date) { $queue = new QueueContent; $tables[0]["billid"] = self::createBillOfTable($pdo, $queue, join(',', $tables[0]["queueids"]), $tables[0]["id"], 1, $users[0 % count($users)]["id"], $date . " 19:14:15"); if (count($tables) >= 3) { $tables[2]["billid"] = self::createBillOfTable($pdo, $queue, join(',', $tables[2]["queueids"]), $tables[2]["id"], 2, $users[1 % count($users)]["id"], $date . " 19:14:25"); } if (count($tables) >= 5) { $tables[4]["billid"] = self::createBillOfTable($pdo, $queue, join(',', $tables[4]["queueids"]), $tables[4]["id"], 3, $users[2 % count($users)]["id"], $date . " 19:15:15"); } if (count($tables) >= 7) { $tables[6]["billid"] = self::createBillOfTable($pdo, $queue, join(',', $tables[6]["queueids"]), $tables[6]["id"], 1, $users[3 % count($users)]["id"], $date . " 20:15:15"); } if (count($tables) >= 8) { $tables[7]["billid"] = self::createBillOfTable($pdo, $queue, join(',', $tables[7]["queueids"]), $tables[7]["id"], 1, $users[4 % count($users)]["id"], $date . " 20:15:15"); } if (count($tables) >= 10) { $tables[9]["billid"] = self::createBillOfTable($pdo, $queue, join(',', $tables[9]["queueids"]), $tables[9]["id"], 1, $users[5 % count($users)]["id"], $date . " 21:10:00"); } return $tables; } private static function createBillOfTable($pdo,$queue,$tablequeueids,$tableid,$paymentid,$userid,$datetime) { $billid = $queue->declarePaidCreateBillReturnBillId($pdo,$tablequeueids,$tableid,$paymentid,1,0,true,'','','',$userid,$datetime); return $billid; } private static function leadingzeronumber($number) { $number = intval($number); if ($number < 10) { $number = "0" . $number; } return number; } public static function handleCommand($command) { if (!self::checkRights($command)) { return false; } if ($command == 'insertdemodata') { self::insertdemodata(); } } private static function checkRights($command) { if (session_id() == '') { session_start(); } if (!isset($_SESSION['angemeldet']) || !$_SESSION['angemeldet']) { echo json_encode(array("status" => "ERROR", "code" => ERROR_NOT_AUTHOTRIZED, "msg" => ERROR_NOT_AUTHOTRIZED_MSG)); return false; } if ($command == 'insertdemodata') { if ($_SESSION['is_admin'] == false) { echo json_encode(array("status" => "ERROR", "code" => ERROR_COMMAND_NOT_ADMIN, "msg" => ERROR_COMMAND_NOT_ADMIN_MSG)); return false; } else { return true; } } return false; } }