WIP PreorderBilling 2025-03-26

This commit is contained in:
Frank Schubert
2025-03-26 14:06:23 +01:00
parent c73c2e2a86
commit e3a6d494ef
10 changed files with 195 additions and 10 deletions
+13
View File
@@ -53,6 +53,19 @@ class Address extends mfBaseModel {
return $data;
}
public function hasPreorderBilling() {
if(!defined("TT_PREORDER_BILLING") || !is_array(TT_PREORDER_BILLING)) {
return false;
}
foreach(TT_PREORDER_BILLING as $conf) {
if(array_key_exists($this->id, $conf["netoperators"])) {
return true;
}
}
return false;
}
public function getCoords() {
$update_needed = false;
if($this->id) {
@@ -1067,6 +1067,9 @@ class PreorderController extends mfBaseController {
case "saveActivationdate":
$return = $this->saveActivationdateApi();
break;
case "setBilled":
$return = $this->setBilledApi();
break;
default:
$return = false;
}
@@ -1080,6 +1083,27 @@ class PreorderController extends mfBaseController {
$this->returnJson($data);
}
private function setBilledApi() {
$preorder_id = $this->request->id;
$preorder = new Preorder($preorder_id);
if(!$preorder->id) {
return false;
}
if(!$preorder->adb_wohneinheit_id) {
return false;
}
$today = new DateTime();
$today->setTimezone(new DateTimeZone("Europe/Vienna"));
$preorder->adb_wohneinheit->enduser_setup_invoice_date = $today->format("Y-m-d");
$preorder->adb_wohneinheit->save();
return ["message" => "Billed status updated", "pid" => $preorder_id, "date" => $today->format("Y-m-d")];
}
private function saveOrderdateApi() {
$preorder_id = $this->request->id;
$order_date = $this->request->order_date;
@@ -4,7 +4,7 @@ class PreorderBilling extends mfBaseModel {
protected $forcestr = ["product_name","product_info","matchcode"];
private $preorder;
private $invoice;
private $vatgroup;
private $adb_wohneinheit;
public static $earliest_bill_date = "2025-01-01";
@@ -21,6 +21,13 @@ class PreorderBilling extends mfBaseModel {
return null;
}
if($name == "adb_wohneinheit") {
if(!$this->preorder_id) return null;
$preorder = $this->getProperty("preorder");
if(!$preorder || !$preorder->adb_wohneinheit_id) return null;
return $preorder->adb_wohneinheit;
}
if($name == "creator") {
$creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
if($creator) {
@@ -77,9 +84,9 @@ class PreorderBilling extends mfBaseModel {
$model = new PreorderBilling();
$table_fields = [
"netowner_id","invoice_id", "preorder_id", "oaid", "adb_wohneinheit_id", "order_date", "start_date", "end_date", "preorderbillingcustomer_id", "owner_id",
"billingaddress_id", "fibu_account_number", "company", "firstname", "lastname", "street", "zip", "city", "country", "email", "uid",
"billing_delivery", "product_id", "product_name", "product_info", "article_number", "amount", "unit", "price", "price_setup", "vatrate", "billing_period",
"netowner_id","invoice_id", "preorder_id", "product_type", "oaid", "adb_wohneinheit_id", "order_date", "start_date", "end_date", "preorderbillingcustomer_id",
"owner_id", "billingaddress_id", "fibu_account_number", "company", "firstname", "lastname", "street", "zip", "city", "country", "email", "uid", "billing_delivery",
"product_id", "product_type", "product_name", "product_info", "article_number", "amount", "unit", "price", "price_setup", "vatrate", "billing_period",
"create_by","edit_by","create","edit"
];
@@ -148,7 +148,7 @@ class PreorderBillingController extends mfBaseController {
$now_day = date("d");
$today = new DateTime("$now_year-$now_month-$now_day");
$today = new DateTime("2025-04-13");
//$today = new DateTime("2025-04-13");
$today->setTime(2,0,0);
$today->setTimezone(new DateTimeZone("Europe/Vienna"));
@@ -339,6 +339,7 @@ class PreorderBillingController extends mfBaseController {
"end_date" => $status_change_date->format("Y-m-d"),
"billing_delivery" => "email",
"product_id" => $product->id,
"product_type" => $product->type,
"product_info" => "",
"article_number" => $article_number,
"amount" => 1,
@@ -425,6 +426,11 @@ class PreorderBillingController extends mfBaseController {
die("Unknown billing type $type");
}
if(!$billing_data["unit"]) {
var_dump($billing_data);exit;
}
$billing = PreorderBilling::create($billing_data);
if(!$billing->save()) {
die("Billing record could not be saved!");
@@ -632,6 +638,7 @@ class PreorderBillingController extends mfBaseController {
"end_date" => $end_date->format("Y-m-d"),
"billing_delivery" => "email",
"product_id" => $product->id,
"product_type" => $product->type,
"product_info" => "",
"article_number" => $article_number,
"amount" => 1,
@@ -267,6 +267,7 @@ class PreorderBillingInvoiceController extends mfBaseController {
$position_data = [];
$position_data["product_id"] = $bill->product_id;
$position_data["product_type"] = $bill->product_type;
$position_data["article_number"] = $bill->article_number;
$position_data["product_name"] = $bill->product_name;
$position_data["product_info"] = $bill->product_info;
@@ -307,6 +308,7 @@ class PreorderBillingInvoiceController extends mfBaseController {
$new_pos_data["price_gross"] += $position["total_gross"];
$new_pos_data["vatrate"] = $position_data["vatrate"];
$new_pos_data["product_id"] = $position["product_id"];
$new_pos_data["product_type"] = $position["product_type"];
$new_pos_data["article_number"] = $position["article_number"];
$new_pos_data["article_name"] = $position["product_name"];
$new_pos_data["preorder_billings"][] = $position["billing_id"];
@@ -420,8 +422,20 @@ class PreorderBillingInvoiceController extends mfBaseController {
$invoice->rollbackTransaction();
die("Bill for Invoiceposition not found");
}
$pbill->invoice_id = $invoice->id;
if($position->product_type == "enduser_setup") {
if(!$pbill->adb_wohneinheit) {
$invoice->rollbackTransaction();
die("Keine Wohneinheit für Preorder " . $pbill->preorder_id . " / bill " . $pbill->id);
}
$pbill->adb_wohneinheit->enduser_setup_invoice_date = $today->format("Y-m-d");
if(!$pbill->adb_wohneinheit->save()) {
$invoice->rollbackTransaction();
die("Error saving enduser_setup_invoice_date");
}
}
$pbill->invoice_id = $invoice->id;
if (!$pbill->save()) {
$invoice->rollbackTransaction();
die("error saving invoice_id to bill");
@@ -72,7 +72,7 @@ class PreorderBillingInvoiceposition extends mfBaseModel {
$model = new PreorderBillingInvoiceposition();
$table_fields = [
"invoice_id", "billing_id", "start_date", "end_date", "product_id", "article_number", "article_name", "article_info",
"invoice_id", "billing_id", "start_date", "end_date", "product_id", "product_type", "article_number", "article_name", "article_info",
"amount", "unit", "price", "price_total", "price_gross", "vatrate", "billing_period",
"create_by","edit_by","create","edit"
];