WIP PreorderPrice 2025-02-21

This commit is contained in:
Frank Schubert
2025-02-24 12:37:33 +01:00
parent fdd6ed7ebb
commit 99bdbd3b39
12 changed files with 1329 additions and 135 deletions

View File

@@ -4,6 +4,7 @@ class PreorderProductPrice extends mfBaseModel {
private $preorderprduct;
private $netowner;
private $preordercampaign;
private $campaigns;
private $campaign;
private $creator;
private $editor;
@@ -39,6 +40,19 @@ class PreorderProductPrice extends mfBaseModel {
return $this->preordercampaign;
}
if($name == "campaigns") {
$ccount = PreorderProductPriceCampaign::count(["preorderproductprice_id" => $this->id]);
$this->log->debug("Counted $ccount Campaigns for Price ".$this->id);
if(!$ccount) return [];
$this->campaigns = [];
foreach(PreorderProductPriceCampaign::search(["preorderproductprice_id" => $this->id]) as $pppc) {
$campaign = $pppc->campaign;
if(!$campaign || !$campaign->id) continue;
$this->campaigns[$campaign->id] = new PreorderCampaign($campaign->id);
}
return $this->campaigns;
}
if($name == "creator") {
$creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
@@ -97,7 +111,7 @@ class PreorderProductPrice extends mfBaseModel {
$table_fields = [
"preorderproduct_id", "netowner_id", "netoperator_id", "preordercampaign_id", "description",
"start_date", "end_date", "price_inet", "price_inet_tv", "price_catv", "price_passive",
"billing_delay", "billing_period", "contract_term", "note",
"billing_delay", "billing_period", "contract_term", "description", "note",
"create_by","edit_by","create","edit"
];
@@ -125,7 +139,12 @@ class PreorderProductPrice extends mfBaseModel {
$db = FronkDB::singleton();
$res = $db->select("PreorderProductPrice", "*", "1 = 1 ORDER BY start_date");
$sql = "SELECT PreorderProductPrice.* FROM PreorderProductPrice
LEFT OUTER JOIN (SELECT COUNT(*) as cnt, preorderproductprice_id, preordercampaign_id as preordercampaign_id FROM PreorderProductPriceCampaign GROUP BY PreorderProductPriceCampaign.preorderproductprice_id, PreorderProductPriceCampaign.preordercampaign_id) pppc ON PreorderProductPrice.id = pppc.preorderproductprice_id
GROUP BY PreorderProductPrice.id
ORDER BY start_date";
$res = $db->query($sql);
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new PreorderProductPrice($data);
@@ -143,8 +162,10 @@ class PreorderProductPrice extends mfBaseModel {
}
$where = self::getSqlFilter($filter);
$sql = "SELECT * FROM PreorderProductPrice
WHERE $where
$sql = "SELECT PreorderProductPrice.* FROM PreorderProductPrice
LEFT OUTER JOIN (SELECT COUNT(*) as cnt, preorderproductprice_id, preordercampaign_id as preordercampaign_id FROM PreorderProductPriceCampaign GROUP BY PreorderProductPriceCampaign.preorderproductprice_id, PreorderProductPriceCampaign.preordercampaign_id) pppc ON PreorderProductPrice.id = pppc.preorderproductprice_id
WHERE $where
GROUP BY PreorderProductPrice.id
ORDER BY $order LIMIT 1";
mfLoghandler::singleton()->debug($sql);
@@ -167,7 +188,9 @@ class PreorderProductPrice extends mfBaseModel {
$where = self::getSqlFilter($filter);
$sql = "SELECT COUNT(*) as cnt FROM PreorderProductPrice
WHERE $where";
LEFT OUTER JOIN (SELECT COUNT(*) as cnt, preorderproductprice_id, preordercampaign_id as preordercampaign_id FROM PreorderProductPriceCampaign GROUP BY PreorderProductPriceCampaign.preorderproductprice_id, PreorderProductPriceCampaign.preordercampaign_id) pppc ON PreorderProductPrice.id = pppc.preorderproductprice_id
WHERE $where
GROUP BY PreorderProductPrice.id";
//mfLoghandler::singleton()->debug($sql);
@@ -190,8 +213,10 @@ class PreorderProductPrice extends mfBaseModel {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT * FROM PreorderProductPrice
$sql = "SELECT PreorderProductPrice.* FROM PreorderProductPrice
LEFT OUTER JOIN (SELECT COUNT(*) as cnt, preorderproductprice_id, preordercampaign_id as preordercampaign_id FROM PreorderProductPriceCampaign GROUP BY PreorderProductPriceCampaign.preorderproductprice_id, PreorderProductPriceCampaign.preordercampaign_id) pppc ON PreorderProductPrice.id = pppc.preorderproductprice_id
WHERE $where
GROUP BY PreorderProductPrice.id
ORDER BY $order";
if(is_array($limit) && count($limit)) {
@@ -233,15 +258,28 @@ class PreorderProductPrice extends mfBaseModel {
if(array_key_exists("netoperator_id", $filter)) {
$netoperator_id = $filter['netoperator_id'];
if(is_numeric($netoperator_id)) {
if($netoperator_id === null || $netoperator_id === false) {
$where .= " AND PreorderProductPrice.netoperator_id IS NULL";
} elseif(is_numeric($netoperator_id)) {
$where .= " AND PreorderProductPrice.netoperator_id=$netoperator_id";
}
}
if(array_key_exists("preordercampaign_id", $filter)) {
$preordercampaign_id = $filter['preordercampaign_id'];
if(is_numeric($preordercampaign_id)) {
$where .= " AND PreorderProductPrice.preordercampaign_id=$preordercampaign_id";
if($preordercampaign_id === null || $preordercampaign_id === false) {
$where .= " AND (pppc.cnt IS NULL OR pppc.cnt = 0)";
} elseif(is_numeric($preordercampaign_id)) {
$where .= " AND pppc.preordercampaign_id=$preordercampaign_id";
}
}
if(array_key_exists("campaign_id", $filter)) {
$preordercampaign_id = $filter['campaign_id'];
if($preordercampaign_id === null || $preordercampaign_id === false) {
$where .= " AND (pppc.cnt IS NULL OR pppc.cnt = 0)";
} elseif(is_numeric($preordercampaign_id)) {
$where .= " AND pppc.preordercampaign_id=$preordercampaign_id";
}
}