WIP Preorderlogistcs: qr done, plog saving done, Preorder status change

done
This commit is contained in:
Frank Schubert
2023-11-23 13:51:53 +01:00
parent 7ed9b3d612
commit a94c3cc8db
11 changed files with 317 additions and 149 deletions
@@ -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;