PreorderBilling
This commit is contained in:
@@ -5,6 +5,8 @@ class PreorderBilling extends mfBaseModel {
|
||||
private $preorder;
|
||||
private $invoice;
|
||||
private $adb_wohneinheit;
|
||||
private $creator;
|
||||
private $editor;
|
||||
|
||||
public static $earliest_bill_date = "2025-01-01";
|
||||
|
||||
@@ -84,9 +86,10 @@ class PreorderBilling extends mfBaseModel {
|
||||
$model = new PreorderBilling();
|
||||
|
||||
$table_fields = [
|
||||
"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",
|
||||
"netowner_id","invoice_id", "preorder_id", "product_type", "oaid", "adb_wohneinheit_id", "extref", "order_date", "start_date", "end_date", "preorderbillingcustomer_id",
|
||||
"owner_id", "billingaddress_id", "fibu_account_number", "fibu_cost_account", "fibu_revenue_account", "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"
|
||||
];
|
||||
|
||||
|
||||
@@ -230,6 +230,19 @@ class PreorderBillingController extends mfBaseController {
|
||||
}
|
||||
$netoperator_config = $netowner_config["netoperators"][$netoperator->id];
|
||||
|
||||
$fibu_cost_code = TT_PREORDER_BILLING[$netowner_id]["fibu-cost-code"];
|
||||
if($fibu_cost_code == "=from-campaign") {
|
||||
$campaign_cost_code = $preorder->campaign->netowner_fibu_cost_code;
|
||||
if(!$campaign_cost_code) {
|
||||
die("campaign cost_code not found for preorder ".$preorder->id." campaign ".$preorder->campaign->id);
|
||||
}
|
||||
$fibu_cost_code = $campaign_cost_code;
|
||||
}
|
||||
//var_dump($fibu_cost_code);exit;
|
||||
if(!$fibu_cost_code) {
|
||||
die("fibu_cost_code not found for preorder ".$preorder->id);
|
||||
}
|
||||
|
||||
$bill_params = [
|
||||
"netowner" => $netowner,
|
||||
"netowner_config" => $netowner_config,
|
||||
@@ -240,7 +253,8 @@ class PreorderBillingController extends mfBaseController {
|
||||
"bill_date" => $bill_date,
|
||||
"earliest_bill_date" => $earliest_bill_date,
|
||||
"latest_bill_date" => $latest_bill_date,
|
||||
"latest_quarter_bill_date" => $latest_quarter_bill_date
|
||||
"latest_quarter_bill_date" => $latest_quarter_bill_date,
|
||||
"fibu_cost_code" => $fibu_cost_code,
|
||||
];
|
||||
|
||||
if($preorder->status->code >= 241) {
|
||||
@@ -260,6 +274,9 @@ class PreorderBillingController extends mfBaseController {
|
||||
|
||||
}
|
||||
|
||||
/*********************************
|
||||
* Enduser Setup & Netoperator Setup Billing
|
||||
*/
|
||||
private function billSetup($preorder, $type, $options) {
|
||||
$netowner = $options['netowner'];
|
||||
$netowner_config = $options['netowner_config'];
|
||||
@@ -271,6 +288,7 @@ class PreorderBillingController extends mfBaseController {
|
||||
$latest_bill_date = $options['latest_bill_date'];
|
||||
$earliest_bill_date = $options['earliest_bill_date'];
|
||||
$latest_quarter_bill_date = $options["latest_quarter_bill_date"];
|
||||
$fibu_cost_code = $options['fibu_cost_code'];
|
||||
|
||||
$this->log->debug(__METHOD__.": bill $type Preorder ".$preorder->id);
|
||||
|
||||
@@ -338,6 +356,7 @@ class PreorderBillingController extends mfBaseController {
|
||||
"preorder_id" => $preorder->id,
|
||||
"oaid" => $preorder->oaid,
|
||||
"adb_wohneinheit_id" => $preorder->adb_wohneinheit_id,
|
||||
"extref" => ($preorder->extref) ?: null,
|
||||
"order_date" => $order_date->format("Y-m-d"),
|
||||
"start_date" => $status_change_date->format("Y-m-d"),
|
||||
"end_date" => $status_change_date->format("Y-m-d"),
|
||||
@@ -352,11 +371,19 @@ class PreorderBillingController extends mfBaseController {
|
||||
"price_setup" => round($price->price_setup, 2),
|
||||
"vatrate" => 20,
|
||||
"billing_period" => 0,
|
||||
"fibu_cost_account" => $fibu_cost_code,
|
||||
];
|
||||
|
||||
$fibu_revenue_code = "";
|
||||
|
||||
if($type == "enduser_setup") {
|
||||
// Endkunde Setup Gebühr
|
||||
|
||||
$fibu_revenue_code = $netowner_config["fibu-revenue-code"];
|
||||
if(!$fibu_revenue_code) {
|
||||
die("fibu_revenue_code not found for preorder ".$preorder->id);
|
||||
}
|
||||
|
||||
if($order_date->format("Ymd") < $earliest_bill_date->format("Ymd")) {
|
||||
return true;
|
||||
}
|
||||
@@ -394,13 +421,21 @@ class PreorderBillingController extends mfBaseController {
|
||||
$billing_data[$key] = $value;
|
||||
}
|
||||
|
||||
$address = $preorder->adb_hausnummer->strasse->name." ".$preorder->adb_hausnummer->hausnummer." ".($preorder->adb_hausnummer->stiege ? "/".$preorder->adb_hausnummer->stiege : "").", ".$preorder->adb_hausnummer->plz->plz." ".$preorder->adb_hausnummer->ortschaft->name;
|
||||
$address = $preorder->adb_hausnummer->strasse->name." ".$preorder->adb_hausnummer->hausnummer.($preorder->adb_hausnummer->stiege ? " /".$preorder->adb_hausnummer->stiege : "").", ".$preorder->adb_hausnummer->plz->plz." ".$preorder->adb_hausnummer->ortschaft->name;
|
||||
$billing_data["preorderbillingcustomer_id"] = $customer->id;
|
||||
$billing_data["fibu_account_number"] = $customer->fibu_account_number;
|
||||
$billing_data["fibu_revenue_account"] = $fibu_revenue_code;
|
||||
$billing_data["product_name"] = "Herstellungsentgelt Glasfaser-Internetanschluss";
|
||||
$billing_data["product_info"] = $address;
|
||||
|
||||
} elseif($type == "operator_setup") {
|
||||
if(array_key_exists("fibu-revenue-code", $netoperator_config) && $netoperator_config["fibu-revenue-code"]) {
|
||||
$fibu_revenue_code = $netoperator_config["fibu-revenue-code"];
|
||||
}
|
||||
if(!$fibu_revenue_code) {
|
||||
die("fibu_revenue code not found for preorder ".$preorder->id);
|
||||
}
|
||||
|
||||
$change_to_active = PreorderHistoryModel::getFirstStatusChangeTo($preorder->id, 500);
|
||||
if($change_to_active) {
|
||||
$status_change_date = new DateTime("@".$change_to_active->changed);
|
||||
@@ -423,6 +458,7 @@ class PreorderBillingController extends mfBaseController {
|
||||
$billing_data["owner_id"] = $netoperator->id;
|
||||
$billing_data["billingaddress_id"] = $netoperator->id;
|
||||
$billing_data["fibu_account_number"] = $netoperator->attributes['rml-fibu-account']->value;
|
||||
$billing_data["fibu_revenue_account"] = $fibu_revenue_code;
|
||||
$billing_data["company"] = trim($netoperator->company);
|
||||
$billing_data["firstname"] = trim($netoperator->firstname);
|
||||
$billing_data["lastname"] = trim($netoperator->lastname);
|
||||
@@ -451,6 +487,9 @@ class PreorderBillingController extends mfBaseController {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*********************************
|
||||
* Usage Billing
|
||||
*/
|
||||
private function billOperatorPeriodic($preorder, $options) {
|
||||
$netowner = $options['netowner'];
|
||||
$netowner_config = $options['netowner_config'];
|
||||
@@ -462,12 +501,24 @@ class PreorderBillingController extends mfBaseController {
|
||||
$latest_bill_date = $options['latest_bill_date'];
|
||||
$earliest_bill_date = $options['earliest_bill_date'];
|
||||
$latest_quarter_bill_date = $options["latest_quarter_bill_date"];
|
||||
$fibu_cost_code = $options['fibu_cost_code'];
|
||||
|
||||
$cancel_date = false;
|
||||
|
||||
|
||||
$campaign = new PreorderCampaign($preorder->preordercampaign_id);
|
||||
if(!$campaign) {
|
||||
die("Campaign ".$preorder->preordercampaign_id." not found!");
|
||||
}
|
||||
|
||||
$fibu_revenue_code = "";
|
||||
if(array_key_exists("fibu-revenue-code", $netoperator_config) && $netoperator_config["fibu-revenue-code"]) {
|
||||
$fibu_revenue_code = $netoperator_config["fibu-revenue-code"];
|
||||
}
|
||||
if(!$fibu_revenue_code) {
|
||||
die("fibu_revenue code not found for preorder ".$preorder->id);
|
||||
}
|
||||
|
||||
if(!array_key_exists($campaign->id, $this->marketshare)) {
|
||||
$this->marketshare[$campaign->id] = [];
|
||||
$this->marketshare[$campaign->id]["max"] = $campaign->getUnitCount();
|
||||
@@ -479,12 +530,6 @@ class PreorderBillingController extends mfBaseController {
|
||||
$this->marketshare[$campaign->id]["netops"][$netoperator->id]["bracket_price"] = [];
|
||||
}
|
||||
|
||||
if($preorder->status->code >= 899) {
|
||||
$this->log->debug(__METHOD__.": Preorder ".$preorder->id." / ".$preorder->oaid." is cancelled");
|
||||
// TODO: is cancelled, so determine if refund is necessary
|
||||
return true;
|
||||
}
|
||||
|
||||
// get price_setup
|
||||
$product = PreorderProduct::getFirst(["type" => "operator_usage"]);
|
||||
if(!$product) {
|
||||
@@ -518,6 +563,22 @@ class PreorderBillingController extends mfBaseController {
|
||||
return true;
|
||||
}
|
||||
|
||||
if($preorder->status->code >= 899) {
|
||||
$this->log->debug(__METHOD__.": Preorder ".$preorder->id." / ".$preorder->oaid." is cancelled");
|
||||
// get cancel date
|
||||
|
||||
if(!$status_change) {
|
||||
$this->log->debug(__METHOD__.": But was never 500, so skipping");
|
||||
return true;
|
||||
}
|
||||
|
||||
$cancel_change = PreorderHistoryModel::getLastStatusChangeToOrHigher($preorder->id, 899);
|
||||
if(!$cancel_change) {
|
||||
die("Preorder ".$preorder->oaid." gekündigt (Status ".$preorder->status->code."), aber kein Cancel date gefunden");
|
||||
}
|
||||
$cancel_date = new DateTime("@".$cancel_change->changed);
|
||||
}
|
||||
|
||||
$first_bill_date = clone $status_change_date;
|
||||
|
||||
|
||||
@@ -581,6 +642,9 @@ class PreorderBillingController extends mfBaseController {
|
||||
$end_date->modify("+1 months");
|
||||
$end_date->modify("-1 day");
|
||||
|
||||
if($cancel_date && $cancel_date->format("Ym") == $start_date->format("Ym")) {
|
||||
$end_date = clone $cancel_date;
|
||||
}
|
||||
|
||||
$sday = $start_date->format("d");
|
||||
$eday = $end_date->format("d");
|
||||
@@ -622,7 +686,7 @@ class PreorderBillingController extends mfBaseController {
|
||||
|
||||
$bill_price = $base_price;
|
||||
|
||||
if ($base_price && ($sday > 1)) {
|
||||
if ($base_price && ($sday > 1 || $cancel_date)) {
|
||||
// Aliquoten Preis errechnen
|
||||
$first_of_period = clone $start_date;
|
||||
$first_of_period->modify("first day of this month");
|
||||
@@ -667,6 +731,8 @@ class PreorderBillingController extends mfBaseController {
|
||||
"owner_id" => $netoperator->id,
|
||||
"billingaddress_id" => $netoperator->id,
|
||||
"fibu_account_number" => $netoperator->attributes['rml-fibu-account']->value,
|
||||
"fibu_cost_account" => $fibu_cost_code,
|
||||
"fibu_revenue_account" => $fibu_revenue_code,
|
||||
"company" => trim($netoperator->company),
|
||||
"firstname" => trim($netoperator->firstname),
|
||||
"lastname" => trim($netoperator->lastname),
|
||||
@@ -685,6 +751,9 @@ class PreorderBillingController extends mfBaseController {
|
||||
}
|
||||
|
||||
$ms_bill_month = $start_date->format("Ym");
|
||||
if(!array_key_exists("billed-$ms_bill_month", $this->marketshare[$campaign->id]["netops"][$netoperator->id])) {
|
||||
$this->marketshare[$campaign->id]["netops"][$netoperator->id]["billed-$ms_bill_month"] = 0;
|
||||
}
|
||||
$this->marketshare[$campaign->id]["netops"][$netoperator->id]["billed-$ms_bill_month"]++;
|
||||
//$this->marketshare[$campaign->id]["netops"][$netoperator->id]["billed-$ms_bill_month"]
|
||||
}
|
||||
|
||||
@@ -10,6 +10,9 @@ class PreorderBillingInvoice extends mfBaseModel {
|
||||
private $pdf;
|
||||
private $csv;
|
||||
|
||||
private $creator;
|
||||
private $editor;
|
||||
|
||||
|
||||
public static function getNextInvoiceNumber($netowner_id) {
|
||||
$last_invoice_num = self::getLastInvoiceNumber($netowner_id);
|
||||
@@ -135,7 +138,87 @@ RML Infrastruktur GmbH";
|
||||
return (new QRCode)->render($epc);
|
||||
}
|
||||
|
||||
public function sendByEmail($to_email = false) {
|
||||
if(!$this->id) return false;
|
||||
|
||||
// get pdf file
|
||||
$ifile = PreorderBillingInvoiceFile::createFromInvoice($this);
|
||||
if(!$ifile) {
|
||||
$this->layout()->setFlash("Fehler beim PDF erstellen");
|
||||
$this->redirect("PreorderBillingInvoice");
|
||||
}
|
||||
$pdf = $ifile->file;
|
||||
|
||||
$pdf_filename = false;
|
||||
try {
|
||||
$pdf_filename = $pdf->getFullPath();
|
||||
} catch(\Exception $e) {
|
||||
$this->log->error("PDF-File for Invoice ".$this->id." not found");
|
||||
}
|
||||
if(!$pdf_filename || !file_exists($pdf_filename)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// get csv file
|
||||
$csv_filename = false;
|
||||
$csv = $this->getProperty("csv");
|
||||
if($csv) {
|
||||
try {
|
||||
$csv_filename = $csv->getFullPath();
|
||||
} catch (\Exception $e) {
|
||||
$this->log->error("CSV-File for Invoice " . $this->id . " not found");
|
||||
}
|
||||
}
|
||||
|
||||
$tpl = new Layout();
|
||||
$tpl->setTemplate("Emailtemplates/preorder-invoice/rml/invoice-email");
|
||||
|
||||
$pdf_vars = [
|
||||
"invoice" => $this
|
||||
];
|
||||
|
||||
foreach($pdf_vars as $name => $val) {
|
||||
$tpl->set($name, $val);
|
||||
}
|
||||
|
||||
$body = $tpl->render();
|
||||
$values = $tpl->getReturnedValue();
|
||||
|
||||
$subject = $values['subject'];
|
||||
$from = $values['from_email'];
|
||||
$from_name = $values['from_email_name'];
|
||||
if($to_email) {
|
||||
$to = $to_email;
|
||||
} else {
|
||||
$to = trim($this->email);
|
||||
}
|
||||
|
||||
if(!$to) {
|
||||
$this->log->error(__METHOD__.": Invoice ".$this->invoice_number." missing email");
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(!$subject || !$from || !$from_name || !$to) {
|
||||
$this->log->warn(__METHOD__.": Invoice ".$this->invoice_number." could not be sent. Values missing. (subject: '$subject', from: '$from_name', from_email: '$from', to: '$to')");
|
||||
return false;
|
||||
} else {
|
||||
$email = new Emailnotification();
|
||||
$email->setSubject($subject);
|
||||
$email->setBody($body);
|
||||
$email->setFrom($from, $from_name);
|
||||
$email->setTo($to);
|
||||
$email->setHeader("X-".MFAPPNAME."-Iid", $this->id);
|
||||
$email->addAttachment($pdf_filename, null, $pdf->filename, "application/pdf");
|
||||
if($csv_filename) {
|
||||
$email->addAttachment($csv_filename, null, $csv->filename, "text/csv");
|
||||
}
|
||||
$email->send();
|
||||
$this->log->info(__METHOD__.": Sending Preorder Invoice ".$this->invoice_number." to $to");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
@@ -147,7 +230,7 @@ RML Infrastruktur GmbH";
|
||||
}
|
||||
|
||||
if($name == "pdf") {
|
||||
$ifile = PreorderBillingInvoiceFile::getFirst(["invoice_id" => $this->id]);
|
||||
$ifile = PreorderBillingInvoiceFile::getFirst(["invoice_id" => $this->id, "name" => "%.pdf"]);
|
||||
if(!$ifile) return null;
|
||||
|
||||
$file = $ifile->file;
|
||||
@@ -481,6 +564,16 @@ RML Infrastruktur GmbH";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("date_delivered", $filter)) {
|
||||
$date_delivered = $filter['date_delivered'];
|
||||
if($date_delivered === null || $date_delivered === false) {
|
||||
$where .= " AND (PreorderBillingInvoice.date_delivered IS NULL OR PreorderBillingInvoice.date_delivered=0)";
|
||||
} elseif($date_delivered === true) {
|
||||
$where .= " AND (PreorderBillingInvoice.date_delivered IS NOT NULL AND PreorderBillingInvoice.date_delivered > 0)";
|
||||
} elseif(is_numeric($date_delivered)) {
|
||||
$where .= " AND PreorderBillingInvoice.date_delivered=$date_delivered";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("add-where", $filter)) {
|
||||
$where .= " ".$filter['add-where'];
|
||||
|
||||
@@ -12,7 +12,7 @@ class PreorderBillingInvoiceController extends mfBaseController {
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me", $me);
|
||||
|
||||
if(!$me->can(["preorderbilling", "preorderbillingReadonly"])) {
|
||||
if(!$me->can(["preorderbilling", "preorderbillingReadonly"]) && (!defined("MFBASE_BYPASS_LOGIN") || !MFBASE_BYPASS_LOGIN)) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,10 @@ class PreorderBillingInvoiceController extends mfBaseController {
|
||||
$this->layout()->set("invoices", $invoices);
|
||||
$this->layout()->set("pagination", $pagination);
|
||||
|
||||
$now = new DateTime("now");
|
||||
$email_jobs = InvoiceJobModel::search(["task" => "send-preorder-invoice-email", "to_date>=" => $now->format("Y-m-d")]);
|
||||
$this->layout()->set("email_jobs", $email_jobs);
|
||||
|
||||
}
|
||||
|
||||
private function getPreparedFilter($filter) {
|
||||
@@ -165,6 +169,47 @@ class PreorderBillingInvoiceController extends mfBaseController {
|
||||
exit;
|
||||
}
|
||||
|
||||
protected function createJob() {
|
||||
$r = $this->request;
|
||||
//var_dump($r->get());exit;
|
||||
|
||||
$task = $r->task;
|
||||
if($task != "send-preorder-invoice-email") {
|
||||
$this->layout()->setFlash("Ungültiger Task", "error");
|
||||
$this->redirect("PreorderBillingInvoice");
|
||||
}
|
||||
|
||||
if(!$r->from_date) {
|
||||
$this->layout()->setFlash("Startdatum wird benötigt", "error");
|
||||
$this->redirect("PreorderBillingInvoice");
|
||||
}
|
||||
|
||||
try {
|
||||
$from_date = DateTime::createFromFormat("d.m.Y", $r->from_date, new DateTimeZone("Europe/Vienna"));
|
||||
$from_date->setTime(0,0,0);
|
||||
|
||||
$to_date = clone $from_date;
|
||||
$to_date->modify("+7 days");
|
||||
$to_date->setTime(23,59,59);
|
||||
} catch(Exception $e) {
|
||||
$this->layout()->setFlash("Von- oder Bisdatum ungültig", "error");
|
||||
$this->redirect("PreorderBillingInvoice");
|
||||
}
|
||||
|
||||
$job = InvoiceJobModel::create([
|
||||
"task" => $task,
|
||||
"from_date" => $from_date->format("Y-m-d"),
|
||||
"to_date" => $to_date->format("Y-m-d"),
|
||||
]);
|
||||
if(!$job->save()) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern", "error");
|
||||
$this->redirect("PreorderBillingInvoice");
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Task erfolgreich gespeichert", "success");
|
||||
$this->redirect("PreorderBillingInvoice");
|
||||
}
|
||||
|
||||
protected function createAction() {
|
||||
$netowner_id = $this->me->address_id;
|
||||
$today = new DateTime();
|
||||
@@ -266,6 +311,7 @@ class PreorderBillingInvoiceController extends mfBaseController {
|
||||
"company" => ($bill->company) ?: $bill->firstname . " " . $bill->lastname,
|
||||
"network_name" => $campaign_name,
|
||||
"oaid" => $bill->oaid,
|
||||
"extref" => trim($bill->extref),
|
||||
"order_date" => $bill->order_date,
|
||||
"start_date" => $start_date->format("Y-m-d"),
|
||||
"end_date" => $end_date->format("Y-m-d"),
|
||||
@@ -286,11 +332,13 @@ class PreorderBillingInvoiceController extends mfBaseController {
|
||||
$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;
|
||||
$position_data["article_info"] = $bill->product_info;
|
||||
$position_data["total"] = round($price, 2);
|
||||
$position_data["total_gross"] = round($price_gross, 2);
|
||||
$position_data["vatrate"] = $bill->vatrate;
|
||||
$position_data["billing_id"] = $bill->id;
|
||||
$position_data["fibu_cost_account"] = $bill->fibu_cost_account;
|
||||
$position_data["fibu_revenue_account"] = $bill->fibu_revenue_account;
|
||||
|
||||
if (!array_key_exists($bill->product_id, $invoice_positions)) {
|
||||
$invoice_positions[$bill->product_id] = [];
|
||||
@@ -327,6 +375,9 @@ class PreorderBillingInvoiceController extends mfBaseController {
|
||||
$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["article_info"] = $position["article_info"];
|
||||
$new_pos_data["fibu_cost_account"] = $position["fibu_cost_account"];
|
||||
$new_pos_data["fibu_revenue_account"] = $position["fibu_revenue_account"];
|
||||
$new_pos_data["preorder_billings"][] = $position["billing_id"];
|
||||
|
||||
$positions_count++;
|
||||
@@ -340,6 +391,8 @@ class PreorderBillingInvoiceController extends mfBaseController {
|
||||
$new_position = PreorderBillingInvoiceposition::create($new_pos_data);
|
||||
$new_position->preorder_billings = $new_pos_data["preorder_billings"];
|
||||
$new_position->count = $new_pos_data["count"];
|
||||
$new_position->fibu_cost_account = $new_pos_data["fibu_cost_account"];
|
||||
$new_position->fibu_revenue_account = $new_pos_data["fibu_revenue_account"];
|
||||
|
||||
$sort_key = round(3 / $product_id)."-".$year_month;
|
||||
$positions_to_sort[$sort_key] = $new_position;
|
||||
@@ -365,14 +418,14 @@ class PreorderBillingInvoiceController extends mfBaseController {
|
||||
//exit;
|
||||
|
||||
|
||||
|
||||
|
||||
$invoice_data = [];
|
||||
$invoice_data["netowner_id"] = $netowner_id;
|
||||
$invoice_data["preorderbillingcustomer_id"] = $bill->preorderbillingcustomer_id;
|
||||
$invoice_data["owner_id"] = $bill->owner_id;
|
||||
$invoice_data["billingaddress_id"] = $bill->billingaddress_id;
|
||||
$invoice_data["fibu_account_number"] = $bill->fibu_account_number;
|
||||
$invoice_data["fibu_cost_account"] = TT_PREORDER_BILLING[$netowner_id]["fibu-cost-code"];
|
||||
$invoice_data["fibu_revenue_account"] = TT_PREORDER_BILLING[$netowner_id]["fibu-revenue-code"];
|
||||
$invoice_data["fibu_tax_code"] = 1;
|
||||
$invoice_data["tax_text"] = null;
|
||||
$invoice_data["head_text"] = null;
|
||||
@@ -403,7 +456,8 @@ class PreorderBillingInvoiceController extends mfBaseController {
|
||||
|
||||
$total_net = 0;
|
||||
$total_gross = 0;
|
||||
|
||||
$fibu_cost_account = "";
|
||||
$fibu_revenue_account = "";
|
||||
foreach($sorted_positions as $position) {
|
||||
//var_dump($position);
|
||||
$this->log->debug(__METHOD__.": count: ".$position->count);
|
||||
@@ -412,6 +466,11 @@ class PreorderBillingInvoiceController extends mfBaseController {
|
||||
unset($position->preorder_billings);
|
||||
unset($position->count);
|
||||
|
||||
$fibu_cost_account = $position->fibu_cost_account;
|
||||
$fibu_revenue_account = $position->fibu_revenue_account;
|
||||
unset($position->fibu_cost_account);
|
||||
unset($position->fibu_revenue_account);
|
||||
|
||||
|
||||
if($position->product_type != "enduser_setup") {
|
||||
if(array_key_exists($netoperator_id, TT_PREORDER_BILLING[$netowner_id]["netoperators"]) && TT_PREORDER_BILLING[$netowner_id]["netoperators"][$netoperator_id]["billing-period"] == "quarterly") {
|
||||
@@ -469,6 +528,8 @@ class PreorderBillingInvoiceController extends mfBaseController {
|
||||
$invoice->total_gross = $total_gross;
|
||||
$invoice->invoice_number = $new_num;
|
||||
$invoice->invoice_date = $today->format("Y-m-d");
|
||||
$invoice->fibu_cost_account = $fibu_cost_account;
|
||||
$invoice->fibu_revenue_account = $fibu_revenue_account;
|
||||
|
||||
// voicenumbers
|
||||
//var_dump($invoice_voicenumbers);exit;
|
||||
@@ -494,7 +555,7 @@ class PreorderBillingInvoiceController extends mfBaseController {
|
||||
if(count($invoice_detail_data)) {
|
||||
// create CSV file
|
||||
//var_dump($invoice_detail_data);exit;
|
||||
$csv = "\u{FEFF}Netzbetreiber;Rechungsnummer;Rechnungsdateum;Netzgebiet;OAID;Bestelldatum;Periode von;Periode bis;Artikelnummer;Produkt;Anzahl;Preis Netto\n";
|
||||
$csv = "\u{FEFF}Netzbetreiber;Rechungsnummer;Rechnungsdateum;Netzgebiet;OAID;Extref;Bestelldatum;Periode von;Periode bis;Artikelnummer;Produkt;Anzahl;Preis Netto\n";
|
||||
foreach ($invoice_detail_data as $detail) {
|
||||
//var_dump($detail);
|
||||
//exit;
|
||||
@@ -504,6 +565,7 @@ class PreorderBillingInvoiceController extends mfBaseController {
|
||||
$csv .= '"'.$invoice->invoice_date.'";';
|
||||
$csv .= '"'.str_replace('"','""',$detail["network_name"]).'";';
|
||||
$csv .= '"'.$detail["oaid"].'";';
|
||||
$csv .= '"'.str_replace('"','""',$detail["extref"]).'";';
|
||||
$csv .= '"'.$detail["order_date"].'";';
|
||||
$csv .= '"'.$detail["start_date"].'";';
|
||||
$csv .= '"'.$detail["end_date"].'";';
|
||||
@@ -559,4 +621,94 @@ class PreorderBillingInvoiceController extends mfBaseController {
|
||||
$this->layout()->setFlash("$invoice_count Rechnungen erstellt", "success");
|
||||
$this->redirect("PreorderBillingInvoice");
|
||||
}
|
||||
|
||||
public function _sendEmailInvoices($limit = false) {
|
||||
$sent = 0;
|
||||
$defer = 0;
|
||||
$invoices = PreorderBillingInvoice::search(["billing_delivery" => "email", "date_delivered" => false]);
|
||||
foreach($invoices as $invoice) {
|
||||
if($limit && $sent >= $limit) {
|
||||
return ["sent" => $sent, "defer" => $defer];
|
||||
}
|
||||
|
||||
/*$pdf = $invoice->pdf;
|
||||
$pdf = false;
|
||||
|
||||
if(!$pdf || !$pdf->name) {
|
||||
$ifile = PreorderBillingInvoiceFile::createFromInvoice($invoice);
|
||||
if(!$ifile) {
|
||||
$this->layout()->setFlash("Fehler beim PDF erstellen");
|
||||
$this->redirect("PreorderBillingInvoice");
|
||||
}
|
||||
$pdf = $ifile->file;
|
||||
}
|
||||
|
||||
$pdf_file = false;
|
||||
try {
|
||||
$pdf_file = $pdf->getFullPath();
|
||||
} catch (Exception $e) {
|
||||
$this->log->error(__METHOD__.": File for Invoice ".$invoice->id." not found");
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!file_exists($pdf_file)) {
|
||||
$this->log->error(__METHOD__.": Datei ".$pdf->filename." nicht gefunden");
|
||||
continue;
|
||||
}
|
||||
|
||||
if($invoice->total == 0) {
|
||||
$this->log->info(__METHOD__.": Skipping ".$invoice->invoice_number." because total is zero");
|
||||
$invoice->date_delivered = date("U");
|
||||
$invoice->save();
|
||||
continue;
|
||||
}
|
||||
*/
|
||||
if(!$invoice->sendByEmail()) {
|
||||
$this->log->warning(__METHOD__.": Error sending ".$invoice->invoice_number." to ".$invoice->email);
|
||||
$invoice->date_delivered = date("U");
|
||||
$invoice->save();
|
||||
continue;
|
||||
}
|
||||
|
||||
$invoice->date_delivered = date("U");
|
||||
$invoice->save();
|
||||
|
||||
$sent++;
|
||||
|
||||
}
|
||||
|
||||
return ["sent" => $sent, "defer" => $defer];
|
||||
}
|
||||
protected function apiAction() {
|
||||
$do = $this->request->do;
|
||||
$data = [];
|
||||
|
||||
switch($do) {
|
||||
case "getActiveJobs":
|
||||
$return = $this->getActiveJobsApi();
|
||||
break;
|
||||
default:
|
||||
$return = false;
|
||||
}
|
||||
|
||||
if(!is_array($return) || !count($return)) {
|
||||
$data = ["status" => "error"];
|
||||
$this->returnJson($data);
|
||||
}
|
||||
$data['status'] = "OK";
|
||||
$data['result'] = $return;
|
||||
$this->returnJson($data);
|
||||
}
|
||||
|
||||
private function getActiveJobsApi() {
|
||||
$now = new DateTime("now");
|
||||
$jobs = [];
|
||||
foreach(InvoiceJobModel::search(["to_date>=" => $now->format("Y-m-d")]) as $job) {
|
||||
if(!str_contains($job->task,"preorder")) continue;
|
||||
$j = $job->data;
|
||||
$j->id = $job->id;
|
||||
$jobs[] = $j;
|
||||
}
|
||||
return ["jobs" => $jobs];
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,7 @@ class PreorderHistoryModel {
|
||||
} else {
|
||||
$sql .= " ORDER BY `create` DESC LIMIT 1";
|
||||
}
|
||||
//mfLoghandler::singleton()->debug($sql);
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
$res = FronkDB::singleton()->query($sql);
|
||||
if(FronkDB::singleton()->num_rows($res)) {
|
||||
$data = FronkDB::singleton()->fetch_object($res);
|
||||
@@ -72,7 +72,7 @@ class PreorderHistoryModel {
|
||||
foreach(PreorderstatusModel::getAll() as $status) {
|
||||
if($status->code < $status_code) continue;
|
||||
|
||||
$change = self::getStatusChange("first", $preorder_id, $status_code);
|
||||
$change = self::getStatusChange("first", $preorder_id, $status->code);
|
||||
if($change) return $change;
|
||||
}
|
||||
|
||||
@@ -80,10 +80,11 @@ class PreorderHistoryModel {
|
||||
}
|
||||
|
||||
public static function getLastStatusChangeToOrHigher($preorder_id, $status_code) {
|
||||
foreach(PreorderstatusModel::getAll() as $status) {
|
||||
$codes = PreorderstatusModel::getAll();
|
||||
foreach($codes as $status) {
|
||||
if($status->code < $status_code) continue;
|
||||
|
||||
$change = self::getStatusChange("last", $preorder_id, $status_code);
|
||||
$change = self::getStatusChange("last", $preorder_id, $status->code);
|
||||
if($change) return $change;
|
||||
}
|
||||
|
||||
|
||||
@@ -220,6 +220,7 @@ class PreordercampaignController extends mfBaseController {
|
||||
$data["cifcableurl"] = trim($r->cifcableurl);
|
||||
$data["from_email_name"] = trim($r->from_email_name);
|
||||
$data["from_email"] = trim($r->from_email);
|
||||
$data["netowner_fibu_cost_code"] = trim($r->netowner_fibu_cost_code);
|
||||
|
||||
if($r->from) {
|
||||
$data['from'] = self::dateToTimestamp($r->from);
|
||||
|
||||
@@ -17,6 +17,7 @@ class PreordercampaignModel {
|
||||
public $exist_is_error;
|
||||
public $require_connectiontype;
|
||||
public $allow_unit_update;
|
||||
public $netowner_fibu_cost_code;
|
||||
public $cifurl;
|
||||
public $cifcableurl;
|
||||
public $from_email_name;
|
||||
|
||||
Reference in New Issue
Block a user