WIP 2025-03-14 Preorder Billing
This commit is contained in:
@@ -25,6 +25,7 @@ class AddressdbApicontroller extends mfBaseApicontroller {
|
||||
$this->addRoute("/addressdb/findDistrict", "findDistrict", "GET");
|
||||
$this->addRoute("/addressdb/findDistrict", "findDistrict", "POST");
|
||||
$this->addRoute("/addressdb/fullexport", "exportAddresses", "GET");
|
||||
$this->addRoute("/addressdb/:oaid/pricing", "getAddressPricing", "GET");
|
||||
|
||||
$this->allowMissingOrigin = true;
|
||||
}
|
||||
@@ -884,6 +885,74 @@ class AddressdbApicontroller extends mfBaseApicontroller {
|
||||
return mfResponse::Ok(['addresses' => $addresses]);
|
||||
}
|
||||
|
||||
protected function getAddressPricing($oaid) {
|
||||
if(!$oaid) {
|
||||
return mfResponse::BadRequest(['message' => "OAID missing"]);
|
||||
}
|
||||
|
||||
$unit = ADBWohneinheitModel::getFirst(["oaid" => $oaid]);
|
||||
if($unit) {
|
||||
$hausnummer = $unit->hausnummer;
|
||||
} else {
|
||||
$hausnummer = ADBHausnummerModel::getFirst(["oaid" => $oaid]);
|
||||
}
|
||||
|
||||
if(!$hausnummer) {
|
||||
return mfResponse::NotFound(['message' => "Address not found"]);
|
||||
}
|
||||
|
||||
$network = NetworkModel::getFirst(["adb_netzgebiet_id" => $hausnummer->netzgebiet_id]);
|
||||
$netowner_id = $network->owner_id;
|
||||
|
||||
$campaign = PreordercampaignModel::getFirst(["network_id" => $network->id]);
|
||||
$netop = PreordercampaignOperatorModel::getFirst(["isp_id" => $this->me->address_id, "preordercampaign_id" => $campaign->id]);
|
||||
|
||||
if(!$netop) {
|
||||
$netop = PreordercampaignOperatorModel::getFirst(["operator_id" => $this->me->address_id, "preordercampaign_id" => $campaign->id]);
|
||||
}
|
||||
if(!$netop) {
|
||||
return mfResponse::Unauthorized();
|
||||
}
|
||||
|
||||
$netoperator = $netop->operator;
|
||||
|
||||
$prices = [];
|
||||
$enduser_setup_product_id = false;
|
||||
foreach(PreorderProduct::getWithTypes() as $product) {
|
||||
if($product->type == "enduser_setup") {
|
||||
$enduser_setup_product_id = $product->id;
|
||||
}
|
||||
$product->setNetownerId($netowner_id);
|
||||
$product->setNetoperatorId($netoperator->id);
|
||||
|
||||
$prices[$product->type] = $product->getCampaignPrice($campaign->id);
|
||||
}
|
||||
|
||||
$prices_return = [
|
||||
"price_inet" => (float)$prices["operator_usage"]->price_inet,
|
||||
"price_inet_tv" => (float)$prices["operator_usage"]->price_inet_tv,
|
||||
"price_catv" => (float)$prices["operator_usage"]->price_catv,
|
||||
|
||||
"operator_setup_price" => (float)$prices["operator_setup"]->price_setup,
|
||||
"operator_setup_info" => $prices["operator_setup"]->description,
|
||||
"operator_setup_valid_until" => $prices["operator_setup"]->end_date,
|
||||
|
||||
"enduser_setup_price" => (float)$prices["enduser_setup"]->price_setup,
|
||||
"enduser_setup_info" => $prices["enduser_setup"]->description,
|
||||
"enduser_setup_valid_until" => $prices["enduser_setup"]->end_date,
|
||||
|
||||
"vatrate" => 20,
|
||||
];
|
||||
|
||||
if(PreorderBilling::getFirst(["adb_wohneinheit_id" => $unit->id, "product_id" => $enduser_setup_product_id])) {
|
||||
$prices_return["enduser_setup_price"] = 0;
|
||||
$prices_return["enduser_setup_info"] = "paid";
|
||||
$prices_return["enduser_setup_valid_until"] = null;
|
||||
}
|
||||
|
||||
return mfResponse::Ok(['oaid' => $oaid, 'prices' => $prices_return]);
|
||||
}
|
||||
|
||||
protected function exportAddresses() {
|
||||
//if($this->me->username != 'r.eschner@rmlinfrastruktur.at') {
|
||||
// return mfResponse::Forbidden();
|
||||
|
||||
Reference in New Issue
Block a user