WIP 2025-03-14 Preorder Billing

This commit is contained in:
Frank Schubert
2025-03-17 12:22:03 +01:00
parent 094da4e7cf
commit 361fc5ee9a
21 changed files with 1782 additions and 146 deletions

View File

@@ -53,6 +53,29 @@ class PreorderProduct extends mfBaseModel {
return $this->today_date;
}
public function getDefaultArticlenumber() {
$prices = PreorderProductPrice::search([
"article_number" => true,
"netowner_id" => $this->filter_netowner_id,
"netoperator_id" => $this->filter_netoperator_id,
"preorderproduct_id" => $this->id
]);
foreach($prices as $price) {
if($price->article_number) return $price->article_number;
}
$prices = PreorderProductPrice::search([
"article_number" => true,
"netowner_id" => $this->filter_netowner_id,
"preorderproduct_id" => $this->id
]);
foreach($prices as $price) {
if($price->article_number) return $price->article_number;
}
return "";
}
public function getCampaignFirstPrice($campaign_id, $date = null) {
if(!$date) $date = date("Y-m-d");
@@ -90,7 +113,7 @@ class PreorderProduct extends mfBaseModel {
return $price;
//return $this->current_campaign_regular_price;
} else {
$this->log->debug(__METHOD__.": TRY FIRST PRICE");
//$this->log->debug(__METHOD__.": TRY FIRST PRICE");
return $this->getCampaignFirstPrice($campaign_id, $date);
}
return null;
@@ -130,23 +153,23 @@ class PreorderProduct extends mfBaseModel {
$this->log->debug("=== in ".__METHOD__);
if(!$date) $date = date("Y-m-d");
$this->log->debug(__METHOD__.": TRY CURRENT PRICE");
//$this->log->debug(__METHOD__.": TRY CURRENT PRICE");
$price = $this->getCampaignCurrentPrice($campaign_id, $date);
if(!$price) {
$this->log->debug(__METHOD__.": TRY CURRENT REGULAR PRICE");
//$this->log->debug(__METHOD__.": TRY CURRENT REGULAR PRICE");
$price = $this->getCampaignCurrentRegularPrice($campaign_id, $date);
}
if(!$price) {
$this->log->debug(__METHOD__.": TRY FIRST PRICE");
//$this->log->debug(__METHOD__.": TRY FIRST PRICE");
$price = $this->getCampaignFirstPrice($campaign_id, $date);
}
if(!$price) {
$this->log->debug(__METHOD__.": No Campaign price found. GET NETOP CURRENT PRICE");
//$this->log->debug(__METHOD__.": No Campaign price found. GET NETOP CURRENT PRICE");
$price = $this->getPrice();
}
if($price) {
$this->log->debug("=== done in ".__METHOD__);
//$this->log->debug("=== done in ".__METHOD__);
return $price;
}
return null;
@@ -191,7 +214,7 @@ class PreorderProduct extends mfBaseModel {
], "start_date DESC, `create` DESC");
if(!$price && $allowCascading) {
$this->log->debug(__METHOD__.": Cascading to getFirstPrice()");
//$this->log->debug(__METHOD__.": Cascading to getFirstPrice()");
return $this->getFirstPrice($date, true);
}
return $price;
@@ -230,7 +253,7 @@ class PreorderProduct extends mfBaseModel {
}
if(!$price && $allowCascading) {
$this->log->debug(__METHOD__.": Cascading to getCurrentRegularPrice()");
//$this->log->debug(__METHOD__.": Cascading to getCurrentRegularPrice()");
return $this->getCurrentRegularPrice($date, true);
}
return $price;
@@ -239,23 +262,23 @@ class PreorderProduct extends mfBaseModel {
public function getPrice($date = null) {
if(!$date) $date = date("Y-m-d");
$this->log->debug("=== in ".__METHOD__);
$this->log->debug(__METHOD__.": TRY CURRENT PRICE");
//$this->log->debug("=== in ".__METHOD__);
//$this->log->debug(__METHOD__.": TRY CURRENT PRICE");
$price = $this->getCurrentPrice($date);
if(!$price) {
$this->log->debug(__METHOD__.": TRY CURRENT REGULAR PRICE");
//$this->log->debug(__METHOD__.": TRY CURRENT REGULAR PRICE");
$price = $this->getCurrentRegularPrice($date);
}
if(!$price) {
$this->log->debug(__METHOD__.": TRY FIRST PRICE");
//$this->log->debug(__METHOD__.": TRY FIRST PRICE");
$price = $this->getFirstPrice($date);
}
if(!$price) {
$this->log->error(__METHOD__.": Unable to find price! netowner_id: ".$this->filter_netowner_id, " netoperator_id: ".$this->filter_netoperator_id." date: $date");
//$this->log->error(__METHOD__.": Unable to find price! netowner_id: ".$this->filter_netowner_id, " netoperator_id: ".$this->filter_netoperator_id." date: $date");
return null;
}
$this->log->debug("=== done in ".__METHOD__);
//$this->log->debug("=== done in ".__METHOD__);
return $price;
}
@@ -608,7 +631,7 @@ class PreorderProduct extends mfBaseModel {
}
}
mfLoghandler::singleton()->debug($sql);
//mfLoghandler::singleton()->debug($sql);
$res = $db->query($sql);
if($db->num_rows($res)) {
@@ -623,101 +646,11 @@ class PreorderProduct extends mfBaseModel {
private static function getSqlFilter($filter) {
$where = "1=1 ";
if(array_key_exists("project_id", $filter)) {
$project_id = $filter['project_id'];
if(is_numeric($project_id)) {
$where .= " AND PreorderProduct.preorderProductproject_id=$project_id";
}
}
if(array_key_exists("preorderProductproject_id", $filter)) {
$preorderProductproject_id = $filter['preorderProductproject_id'];
if(is_numeric($preorderProductproject_id)) {
$where .= " AND PreorderProduct.preorderProductproject_id=$preorderProductproject_id";
}
}
if(array_key_exists("adb_wohneinheit_id", $filter)) {
$adb_wohneinheit_id = $filter['adb_wohneinheit_id'];
if(is_numeric($adb_wohneinheit_id)) {
$where .= " AND PreorderProduct.adb_wohneinheit_id=$adb_wohneinheit_id";
}
}
if(array_key_exists("termination_id", $filter)) {
$termination_id = $filter['termination_id'];
if(is_numeric($termination_id)) {
$where .= " AND PreorderProduct.termination_id=$termination_id";
}
}
if(array_key_exists("object_type", $filter)) {
$object_type = FronkDB::singleton()->escape($filter["object_type"]);
if($object_type) {
$where .= " AND object_type='$object_type'";
}
}
if(array_key_exists("ez", $filter)) {
$ez = FronkDB::singleton()->escape($filter["ez"]);
if($ez) {
$where .= " AND ez='$ez'";
}
}
if(array_key_exists("status", $filter)) {
$status = FronkDB::singleton()->escape($filter["status"]);
if($status) {
$where .= " AND status='$status'";
}
}
if(array_key_exists("result", $filter)) {
$result = FronkDB::singleton()->escape($filter["result"]);
if($result) {
$where .= " AND result='$result'";
}
}
if(array_key_exists("owner_name", $filter)) {
$owner_name = FronkDB::singleton()->escape($filter["owner_name"]);
if($owner_name) {
$where .= " AND owner_name like '%$owner_name%'";
}
}
if(array_key_exists("owner_street", $filter)) {
$owner_street = FronkDB::singleton()->escape($filter["owner_street"]);
if($owner_street) {
$where .= " AND owner_street like '%$owner_street%'";
}
}
if(array_key_exists("owner_zip", $filter)) {
$owner_zip = FronkDB::singleton()->escape($filter["owner_zip"]);
if($owner_zip) {
$where .= " AND owner_zip like '%$owner_zip%'";
}
}
if(array_key_exists("owner_city", $filter)) {
$owner_city = FronkDB::singleton()->escape($filter["owner_city"]);
if($owner_city) {
$where .= " AND owner_city like '%$owner_city%'";
}
}
if(array_key_exists("owner_country", $filter)) {
$owner_country = FronkDB::singleton()->escape($filter["owner_country"]);
if($owner_country) {
$where .= " AND owner_country like '%$owner_country%'";
}
}
if(array_key_exists("network", $filter)) {
$network = FronkDB::singleton()->escape($filter["network"]);
if($network) {
$where .= " AND view_hausnummer.netzgebiet_id=$network";
if(array_key_exists("type", $filter)) {
$type = FronkDB::singleton()->escape($filter["type"]);
if($type) {
$where .= " AND type='$type'";
}
}

View File

@@ -9,7 +9,7 @@ class PreorderProductController extends mfBaseController {
$this->me = $me;
$this->layout()->set("me",$me);
if(!$me->is(["Admin", "netowner", "salespartner"]) && !$me->can("Preorder")) {
if(!$me->can(["preorderpricing", "preorderpricingReadonly", "preorderbilling", "preorderbillingReadonly"])) {
$this->redirect("Dashboard");
}
}
@@ -17,7 +17,7 @@ class PreorderProductController extends mfBaseController {
protected function indexAction() {
$this->layout()->setTemplate("PreorderProduct/Index");
$netowner_id = 4807; // $this->me->address_id;
$netowner_id = $this->me->address_id; // 4807 == rml
$netowner = new Address($netowner_id);
$products = PreorderProduct::getWithTypes($netowner_id);
@@ -62,7 +62,7 @@ class PreorderProductController extends mfBaseController {
$r = $this->request;
//var_dump($r->get());exit;
$netowner_id = 4807; // $this->me->address_id;
$netowner_id = $this->me->address_id; // 4807 == rml
foreach($r->netoperators as $netoperator_id => $product_data) {
$netoperator = new Address($netoperator_id);
@@ -83,6 +83,7 @@ class PreorderProductController extends mfBaseController {
"netowner_id" => $netowner_id,
"preorderproduct_id" => $product->id,
"netoperator_id" => $netoperator_id,
"article_number" => $price_data["article_number"],
]);
if($price_data["description"]) $price->description = trim($price_data["description"]);
@@ -127,7 +128,9 @@ class PreorderProductController extends mfBaseController {
if(array_key_exists("marketshareprice", $price_data) && is_array($price_data["marketshareprice"])) {
foreach($price_data["marketshareprice"] as $msbracket => $msprice) {
if(!is_numeric($msbracket)) continue;
if(!$msbracket) continue; // dont save 0
if(!$msbracket) continue; // dont save bracket 0 - 15%
if(empty(trim($msprice["inet"])) && empty(trim($msprice["inet_tv"])) && empty(trim($msprice["catv"])) && empty(trim($msprice["passive"]))) continue;
$msp = PreorderProductMarketshareDiscount::create([
"preorderproductprice_id" => $price->id,