diff --git a/Layout/default/Preorder/Index.php b/Layout/default/Preorder/Index.php index 561a37a11..dc08e6ca6 100644 --- a/Layout/default/Preorder/Index.php +++ b/Layout/default/Preorder/Index.php @@ -35,17 +35,17 @@ is("preorderfront")): ?>
- + " />
- + " />
- + " />
diff --git a/Layout/default/Preorderlogistics/Index.php b/Layout/default/Preorderlogistics/Index.php index 307d3a3d9..b0914cb97 100644 --- a/Layout/default/Preorderlogistics/Index.php +++ b/Layout/default/Preorderlogistics/Index.php @@ -42,6 +42,15 @@ " />
+
+ + +
+
" /> @@ -52,6 +61,7 @@ " />
+ @@ -99,7 +109,11 @@ - + adb_hausnummer_id): ?> @@ -150,6 +164,32 @@ w.print(); } + function saveSent(id) { + if(!id) return; + var checked = $("#sent-" + id).is(":checked"); + console.log(checked); + + if(checked) { + var sent = 1; + } else { + var sent = 0; + } + + $.post("", { + do: "saveSent", + id: id, + sent: sent + }, + function(success) { + console.log(success); + if(success.status == "OK") { + $("#sent-label-" + success.result.preorder_id).show(); + } + }, + "json" + ); + } + diff --git a/Layout/default/Preorderlogistics/Print.php b/Layout/default/Preorderlogistics/Print.php index b21bbd85f..13c085d3f 100644 --- a/Layout/default/Preorderlogistics/Print.php +++ b/Layout/default/Preorderlogistics/Print.php @@ -61,7 +61,7 @@
- +
@@ -75,7 +75,7 @@

Mit besten Grüßen,

-

RML Infrastruktur Liezen

+

campaign->network->owner->getCompanyOrName()?>

diff --git a/application/Preorder/Preorder.php b/application/Preorder/Preorder.php index 06802ea1d..8685229d4 100644 --- a/application/Preorder/Preorder.php +++ b/application/Preorder/Preorder.php @@ -15,7 +15,7 @@ class Preorder extends mfBaseModel { private $creator; private $editor; private $attribute = []; - + private $logistics; public function afterLoad() { if($this->uid === "string") { @@ -552,6 +552,12 @@ class Preorder extends mfBaseModel { return null; } + if($name == "logistics") { + $logistics = PreorderlogisticsModel::getFirst(["preorder_id" => $this->id]); + $this->logistics = $logistics; + return $this->logistics; + } + if($name == "attribute") { if(!$this->attributes) { return null; diff --git a/application/Preorder/PreorderController.php b/application/Preorder/PreorderController.php index 8563aabe7..eb09b2bc0 100644 --- a/application/Preorder/PreorderController.php +++ b/application/Preorder/PreorderController.php @@ -73,6 +73,8 @@ class PreorderController extends mfBaseController { $my_campaigns = []; $my_campaign_ids = []; + $this->layout()->set("campaign", new Preordercampaign()); + if($this->me->is("Admin")) { if($filter['preordercampaign_id']) { $this->layout()->set("campaign", new Preordercampaign($filter['preordercampaign_id'])); diff --git a/application/Preorder/PreorderModel.php b/application/Preorder/PreorderModel.php index 468b64778..8794fb408 100644 --- a/application/Preorder/PreorderModel.php +++ b/application/Preorder/PreorderModel.php @@ -165,6 +165,75 @@ class PreorderModel { return null; } + public static function countWithLogistics($filter) { + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + $sql = "SELECT COUNT(*) as cnt FROM `".FRONKDB_DBNAME."`.Preorder tt_preorder + LEFT JOIN `".FRONKDB_DBNAME."`.Preorderstatus tt_preorderstatus ON (tt_preorder.status_id = tt_preorderstatus.id) + LEFT JOIN `".ADDRESSDB_DBNAME."`.view_hausnummer as adb_hausnummer ON (tt_preorder.adb_hausnummer_id = adb_hausnummer.hausnummer_id) + LEFT JOIN `".ADDRESSDB_DBNAME."`.Wohneinheit as adb_wohneinheit ON (tt_preorder.adb_wohneinheit_id = adb_wohneinheit.id) + LEFT OUTER JOIN (SELECT adb_wohneinheit_id, count(*) cnt FROM `".FRONKDB_DBNAME."`.RimoWorkorder GROUP BY adb_wohneinheit_id) wocount ON adb_wohneinheit.id = wocount.adb_wohneinheit_id + LEFT JOIN Preorderlogistics ON (Preorderlogistics.preorder_id = tt_preorder.id) + WHERE $where + "; + + mfLoghandler::singleton()->debug($sql); + + $res = $db->query($sql); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + return $data->cnt; + } + return 0; + } + + public static function searchWithLogistics($filter, $limit = false, $returnDBRessource = false) { + $items = []; + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + + $sql = "SELECT tt_preorder.* FROM `".FRONKDB_DBNAME."`.Preorder tt_preorder + LEFT JOIN `".FRONKDB_DBNAME."`.Preorderstatus tt_preorderstatus ON (tt_preorder.status_id = tt_preorderstatus.id) + LEFT JOIN `".ADDRESSDB_DBNAME."`.view_hausnummer as adb_hausnummer ON (tt_preorder.adb_hausnummer_id = adb_hausnummer.hausnummer_id) + LEFT JOIN `".ADDRESSDB_DBNAME."`.Wohneinheit as adb_wohneinheit ON (tt_preorder.adb_wohneinheit_id = adb_wohneinheit.id) + LEFT OUTER JOIN (SELECT adb_wohneinheit_id, count(*) cnt FROM `".FRONKDB_DBNAME."`.RimoWorkorder GROUP BY adb_wohneinheit_id) wocount ON adb_wohneinheit.id = wocount.adb_wohneinheit_id + LEFT JOIN Preorderlogistics ON (Preorderlogistics.preorder_id = tt_preorder.id) + WHERE $where + ORDER BY lastname, firstname + "; + /*$sql = "SELECT tt_preorder.* FROM `".FRONKDB_DBNAME."`.Preorder tt_preorder + LEFT JOIN `".FRONKDB_DBNAME."`.Preorderstatus tt_preorderstatus ON (tt_preorder.status_id = tt_preorderstatus.id) + LEFT JOIN `".ADDRESSDB_DBNAME."`.view_hausnummer as adb_hausnummer ON (tt_preorder.adb_hausnummer_id = adb_hausnummer.hausnummer_id) + WHERE $where + ORDER BY lastname, firstname";*/ + + if(is_array($limit) && count($limit)) { + if(is_numeric($limit['start']) && is_numeric($limit['count'])) { + $sql .= " LIMIT ".$limit['start'].", ".$limit['count']; + } elseif(is_numeric($count)) { + $sql .= " LIMIT ".$limit['count']; + } + } + + mfLoghandler::singleton()->debug($sql); + + $res = $db->query($sql); + if($db->num_rows($res)) { + + // hack for Preorder::exportAction + if($returnDBRessource) { + return $res; + } + + while($data = $db->fetch_object($res)) { + $items[] = new Preorder($data); + } + } + return $items; + } + public static function countOrderedAddonservices($filter) { $db = FronkDB::singleton(); @@ -557,6 +626,14 @@ class PreorderModel { } } + if(array_key_exists("sent", $filter)) { + $sent = $filter['sent']; + if($sent) { + $where .= " AND sent > 0"; + } else { + $where .= " AND (sent = 0 OR sent IS NULL)"; + } + } if(array_key_exists("attributes", $filter)) { $attributes = FronkDB::singleton()->escape($filter['attributes']); diff --git a/application/Preorderlogistics/Preorderlogistics.php b/application/Preorderlogistics/Preorderlogistics.php index 9907b1d7a..8986fbaaf 100644 --- a/application/Preorderlogistics/Preorderlogistics.php +++ b/application/Preorderlogistics/Preorderlogistics.php @@ -1,16 +1,34 @@ getProperty("qrfilename"); + if(!$filename) { + return false; + } + + $qrpath = MFUPLOAD_FILE_SAVE_PATH."/".TT_PREORDER_CIF_QR_SUBFOLDER."/$filename"; + var_dump($qrpath);*/ + $img = $this->generateCifQrFile($content); + + return $img; + } + + public function generateCifQrFile($content) { $qr_opts = new QROptions(); $qr_opts->outputType = QROutputInterface::GDIMAGE_PNG; $qr = new QRCode($qr_opts); try { - $png_data = $qr->render("https://fronk.at/"); + $png_data = $qr->render($content); } catch (Exception $ex) { throw $ex; } @@ -18,9 +36,49 @@ class Preorderlogistics extends mfBaseModel { if(!$png_data) { echo "Kein png data!";exit; } + /* + $filename = $this->getProperty("qrfilename"); + $qrpath = MFUPLOAD_FILE_SAVE_PATH."/".TT_PREORDER_CIF_QR_SUBFOLDER."/$filename"; + + $data_parts = explode(",", $png_data); + file_put_contents($qrpath, base64_decode($data_parts[1])); + */ + return $png_data; - var_dump($png_data); - exit; } + + public function getProperty($name) { + if($this->$name == null) { + + if($name == "qrfilename") { + $preorder = $this->getProperty("preorder"); + + if(!$this->preorder_id || !$preorder || !$preorder->ucode) { + return false; + } + + $filename = "preorder-cif-".$preorder->ucode.".png"; + $this->qrfilename = $filename; + return $this->qrfilename; + } + + if($name == "sender") { + $this->sender = new User($this->sent_by); + return $this->sender; + } + + $classname = ucfirst($name); + $idfield = $name."_id"; + $this->$name = new $classname($this->$idfield); + + if($this->$name->id) { + return $this->$name; + } else { + return null; + } + } + + return $this->$name; + } } \ No newline at end of file diff --git a/application/Preorderlogistics/PreorderlogisticsController.php b/application/Preorderlogistics/PreorderlogisticsController.php index 8a5eebfad..b9e0508db 100644 --- a/application/Preorderlogistics/PreorderlogisticsController.php +++ b/application/Preorderlogistics/PreorderlogisticsController.php @@ -64,7 +64,7 @@ class PreorderlogisticsController extends mfBaseController { //var_dump($my_network_ids,$my_campaign_ids);exit; $this->layout()->set("my_campaigns", $my_campaigns); - if($filter['preordercampaign_id'] && in_array($filter['preordercampaign_id'], $my_campaign_ids)) { + if(array_key_exists("preordercampaign_id", $filter) && $filter['preordercampaign_id'] && in_array($filter['preordercampaign_id'], $my_campaign_ids)) { $campaign_id = $filter['preordercampaign_id']; if(is_numeric($campaign_id) && $campaign_id > 0) { $campaign = new Preordercampaign($campaign_id); @@ -79,8 +79,8 @@ class PreorderlogisticsController extends mfBaseController { $filter[">status_code"] = 139; $filter["layout()->set("pagination", $pagination); $this->layout()->set("preorders", $preorders); @@ -135,6 +135,20 @@ class PreorderlogisticsController extends mfBaseController { unset($filter['oaid']); } + $new_filter["sent"] = false; + if(array_key_exists("sent", $filter)) { + if($filter['sent'] == "yes") { + $new_filter["sent"] = true; + } + if($filter['sent'] == "no") { + $new_filter["sent"] = false; + } + if($filter['sent'] == "all") { + unset($new_filter["sent"]); + } + unset($filter['sent']); + } + $new_filter['deleted'] = 0; @@ -178,14 +192,17 @@ class PreorderlogisticsController extends mfBaseController { $this->redirect("Preorderlogistics"); } + /* * generate QR code */ if(!$preorder->ciftoken) { $preorder->createCiftoken(); + $preorder->cifurl = "https://pro.ichwillglasfaser.at/ClientSubmit/finishedInstallationWork?c=".$preorder->ciftoken; $preorder->save(); } + $plog = PreorderlogisticsModel::getFirst(["preorder_id" => $preorder->id]); if(!$plog) { $plog = PreorderlogisticsModel::create([ @@ -197,16 +214,84 @@ class PreorderlogisticsController extends mfBaseController { } } + $qrimg = $plog->getCifQrPng($preorder->cifurl); - - - + $this->layout()->set("qr_url", $qrimg); $this->layout()->set("preorder", $preorder); } - - private function setSentApi() { + protected function apiAction() { + if(!$this->me->is(["Preorderlogistics"])) { + $this->redirect("Dashboard"); + } + $do = $this->request->do; + $data = []; + switch($do) { + case "saveSent": + $return = $this->saveSentApi(); + break; + default: + $return = false; + } + + if(!is_array($return) || !count($return)) { + $data = ["status" => "error"]; + $this->returnJson($data); + } + $data['status'] = "OK"; + $data['result'] = $return; + $this->returnJson($data); + } + + + private function saveSentApi() { + if(!$this->me->is(["Preorderlogistics"])) { + return false; + } + + $preorder_id = $this->request->id; + if(!is_numeric($preorder_id) || $preorder_id < 1) { + return false; + } + + $preorder = new Preorder($preorder_id); + if(!$preorder->id) return false; + + $plog = PreorderlogisticsModel::getFirst(["preorder_id" => $preorder->id]); + if(!$plog) { + $plog = PreorderlogisticsModel::create([ + "preorder_id" => $preorder->id, + "sent" => 0 + ]); + + } + + $sent = intval($this->request->sent); + if($sent < 0 || $sent > 1) return false; + + if($sent) { + $plog->sent_by = $this->me->id; + $plog->sent = date('U'); + + $new_status = PreorderstatusModel::getFirst(["code" => 260]); + + if($preorder->status->code < 260) { + $plog->prev_status_code = $preorder->status->code; + $preorder->status_id = $new_status->id; + $preorder->save(); + } + } else { + $plog->sent_by = null; + $plog->sent = 0; + + + } + if(!$plog->save()) { + return false; + } + + return ["preorder_id" => $preorder->id]; } } \ No newline at end of file diff --git a/application/Preorderlogistics/PreorderlogisticsModel.php b/application/Preorderlogistics/PreorderlogisticsModel.php index ff2661f54..3c1f977dd 100644 --- a/application/Preorderlogistics/PreorderlogisticsModel.php +++ b/application/Preorderlogistics/PreorderlogisticsModel.php @@ -4,6 +4,7 @@ class PreorderlogisticsModel { public $preorder_id; public $sent; + public $sent_by; public $create_by = null; public $edit_by = null; @@ -11,7 +12,7 @@ class PreorderlogisticsModel { public $edit = null; public static function create(Array $data) { - $model = new Building(); + $model = new Preorderlogistics(); foreach ($data as $field => $value) { if (property_exists(get_called_class(), $field)) { @@ -40,10 +41,10 @@ class PreorderlogisticsModel { $db = FronkDB::singleton(); $where = self::getSqlFilter($filter); - $res = $db->select("Building", "*", "$where ORDER BY network_id,pop_id,street,zip,city LIMIT 1"); + $res = $db->select("Preorderlogistics", "*", "$where ORDER BY preorder_id LIMIT 1"); if ($db->num_rows($res)) { $data = $db->fetch_object($res); - $item = new Building($data); + $item = new Preorderlogistics($data); if ($item->id) { return $item; } else { @@ -58,10 +59,10 @@ class PreorderlogisticsModel { $db = FronkDB::singleton(); - $res = $db->select("Building", "*", "1=1 ORDER BY network_id,pop_id,street,zip,city"); + $res = $db->select("Preorderlogistics", "*", "1=1 ORDER BY preorder_id"); if ($db->num_rows($res)) { while ($data = $db->fetch_object($res)) { - $items[] = new Building($data); + $items[] = new Preorderlogistics($data); } } return $items; @@ -71,9 +72,7 @@ class PreorderlogisticsModel { $db = FronkDB::singleton(); $where = self::getSqlFilter($filter); - $sql = "SELECT COUNT(*) as cnt FROM Building - LEFT JOIN Buildingtype ON (Buildingtype.id = Building.type_id) - LEFT JOIN Buildingstatus ON (Buildingstatus.id = Building.status_id) + $sql = "SELECT COUNT(*) as cnt FROM Preorderlogistics WHERE $where "; @@ -90,11 +89,9 @@ class PreorderlogisticsModel { $db = FronkDB::singleton(); $where = self::getSqlFilter($filter); - $sql = "SELECT Building.* FROM Building - LEFT JOIN Buildingtype ON (Buildingtype.id = Building.type_id) - LEFT JOIN Buildingstatus ON (Buildingstatus.id = Building.status_id) + $sql = "SELECT * FROM Preorderlogistics WHERE $where - ORDER BY network_id, pop_id, street, zip, city"; + ORDER BY preorder_id"; mfLoghandler::singleton()->debug($sql); if (is_array($limit) && count($limit)) { @@ -108,7 +105,7 @@ class PreorderlogisticsModel { $res = $db->query($sql); if ($db->num_rows($res)) { while ($data = $db->fetch_object($res)) { - $items[] = new Building($data); + $items[] = new Preorderlogistics($data); } } return $items; @@ -117,130 +114,32 @@ class PreorderlogisticsModel { private static function getSqlFilter($filter) { $where = "1=1 "; - if (array_key_exists("network_id", $filter)) { - $network_id = $filter['network_id']; - if (is_numeric($network_id)) { - $where .= " AND Building.network_id=$network_id"; - } elseif (is_array($network_id) && count($network_id)) { - $where .= " AND Building.network_id IN (" . implode(",", $network_id) . ")"; + + + if (array_key_exists("preorder_id", $filter)) { + $preorder_id = $filter['preorder_id']; + if (is_numeric($preorder_id)) { + $where .= " AND Preorderlogistics.preorder_id=$preorder_id"; } } - - if (array_key_exists("networksection_id", $filter)) { - $networksection_id = $filter['networksection_id']; - if (is_numeric($networksection_id)) { - $where .= " AND Building.networksection_id=$networksection_id"; + + if (array_key_exists("sent", $filter)) { + $sent = $filter['sent']; + if ($sent === true) { + $where .= " AND Preorderlogistics.sent > 0"; + } elseif($sent === false) { + $where .= " AND (Preorderlogistics.sent = 0 OR Preorderlogistics.sent IS NULL)"; } } - - if (array_key_exists("status_id", $filter)) { - $status_id = $filter['status_id']; - if (is_numeric($status_id)) { - $where .= " AND Building.status_id=$status_id"; - } - } - - if (array_key_exists("pipeworker_id", $filter)) { - $pipeworker_id = $filter['pipeworker_id']; - if (is_numeric($pipeworker_id)) { - $where .= " AND Building.pipeworker_id=$pipeworker_id"; - } - } - - if (array_key_exists("type", $filter) && is_array($filter['type']) && count($filter['type'])) { - $ot = $filter['type']; - $in = []; - foreach ($ot as $type) { - $type = FronkDB::singleton()->escape($type); - $in[] = "Buildingtype.name = '$type'"; - } - - $or = ""; - if (count($in)) { - $or = implode(" OR ", $in); - $where .= " AND ( $or )"; - } - } - - if (array_key_exists("status", $filter)) { - if (in_array(substr($filter['status'], 1, 2), ["<=", ">="])) { - $op = substr($filter['status'], 1, 2); - $status = substr($filter['status'], 3); - } elseif (in_array(substr($filter['status'], 1, 1), ["<", ">"])) { - $op = substr($filter['status'], 1, 1); - $status = substr($filter['status'], 2); - } else { - $op = "="; - $status = $filter['status']; - } - - if (is_numeric($status)) { - $where .= " AND Buildingstatus.code $op $status"; - } else { - // get code of statusname - $code = Buildingstatus::getOne(["name" => $status]); - if ($code) { - $status = FronkDB::singleton()->escape($status); - $where .= " AND Buildingstatus.code $op '$status'"; - } - } - } - - if (array_key_exists("code", $filter)) { - $code = FronkDB::singleton()->escape($filter['code']); - if ($code) { - $where .= " AND Building.`code` like '%$code%'"; - } - } - - if (array_key_exists("oaid", $filter)) { - $oaid = FronkDB::singleton()->escape($filter['oaid']); - if ($oaid) { - $where .= " AND Building.`oaid` like '%$oaid%'"; - } - } - - if (array_key_exists("street", $filter)) { - $street = FronkDB::singleton()->escape($filter["street"]); - if ($street) { - $where .= " AND street like '%$street%'"; - } - } - - if (array_key_exists("=street", $filter)) { - $street = FronkDB::singleton()->escape($filter["=street"]); - if ($street) { - $where .= " AND street like '$street'"; - } - } - - if (array_key_exists("zip", $filter)) { - $zip = FronkDB::singleton()->escape($filter["zip"]); - if ($zip) { - $where .= " AND zip like '%$zip%'"; - } - } - - if (array_key_exists("=zip", $filter)) { - $zip = FronkDB::singleton()->escape($filter["=zip"]); - if ($zip) { - $where .= " AND zip like '$zip'"; - } - } - - if (array_key_exists("city", $filter)) { - $city = FronkDB::singleton()->escape($filter["city"]); - if ($city) { - $where .= " AND city like '%$city%'"; - } - } - + + + /* if (array_key_exists("=city", $filter)) { $city = FronkDB::singleton()->escape($filter["=city"]); if ($city) { $where .= " AND city like '$city'"; } - } + }*/ //var_dump($filter, $where);exit; return $where; diff --git a/composer.json b/composer.json index 914a45e84..e4bb66219 100644 --- a/composer.json +++ b/composer.json @@ -3,6 +3,6 @@ "phpoffice/phpspreadsheet": "^1.23", "robmorgan/phinx": "^0.13.4", "textalk/websocket": "^1.6", - "chillerlan/php-qrcode": "^4.3" + "chillerlan/php-qrcode": "dev-main" } } diff --git a/db/migrations/20231120124014_create_preorderlogistics_table.php b/db/migrations/20231120124014_create_preorderlogistics_table.php index 1ab4bd038..1cb004b80 100644 --- a/db/migrations/20231120124014_create_preorderlogistics_table.php +++ b/db/migrations/20231120124014_create_preorderlogistics_table.php @@ -12,6 +12,7 @@ final class CreatePreorderlogisticsTable extends AbstractMigration $table->addColumn("preorder_id", "integer", ["null" => false]); $table->addColumn("sent", "integer", ["null" => false, "default" => 0]); $table->addColumn("sent_by", "integer", ["null" => true, "default" => null]); + $table->addColumn("prev_status_code", "string", ["null" => true, "default" => null, "limit" => 64]); $table->addColumn("create_by", "integer", ["null" => false]); $table->addColumn("edit_by", "integer", ["null" => false]); $table->addColumn("create", "integer", ["null" => false]);