-
+
Rechungsemails versenden
+
+
+
BMD-Export
+
+
Personenkonten
+
+
+ Letzter Export: =($bmd_export["person"]) ? date("d.m.Y H:i:s", $bmd_export["person"]) : ""?>
+
+
+
Rechnungsdaten
+
+
+ Letzter Export: =($bmd_export["invoice"]) ? date("d.m.Y H:i:s", $bmd_export["invoice"]) : ""?>
+
+
+
@@ -152,7 +173,7 @@ $pagination_entity_name = "Rechnungen";
Netto |
Ust. |
Brutto |
-
Zustellung |
+
Versendet |
Erstellt |
diff --git a/application/Linework/LineworkController.php b/application/Linework/LineworkController.php
index 102b98336..b03e5e236 100644
--- a/application/Linework/LineworkController.php
+++ b/application/Linework/LineworkController.php
@@ -326,6 +326,16 @@ class LineworkController extends mfBaseController {
$termination->save();
}
}
+ if(!$r->isset("linework_enabled") && $this->me->is(["Admin", "pipeplanner", "lineplanner"])) {
+ if($termination->linework_enabled == 1) {
+ $termination->linework_enabled = 0;
+ $termination->linework_enabled_date = 0;
+ if($termination->status_id == 3) {
+ $termination->status_id = 1;
+ }
+ $termination->save();
+ }
+ }
if($this->me->is(["Admin", "netowner"])) {
if($r->linework_doku_delay == 1 && $termination->linework_doku_delay != 1) {
diff --git a/application/Pipework/PipeworkController.php b/application/Pipework/PipeworkController.php
index 86294b368..7d0d922a9 100644
--- a/application/Pipework/PipeworkController.php
+++ b/application/Pipework/PipeworkController.php
@@ -317,7 +317,15 @@ class PipeworkController extends mfBaseController {
$building->pipework_enabled_by = $this->me->id;
$building->save();
}
-
+ }
+
+ if(!$r->isset("pipework_enabled") && $this->me->is(["Admin", "pipeplanner"])) {
+ if($building->pipework_enabled == 1) {
+ $building->pipework_enabled = 0;
+ $building->pipework_enabled_date = date('U');
+ $building->pipework_enabled_by = $this->me->id;
+ $building->save();
+ }
}
if($building->workflow_comment != $r->workflow_comment) {
diff --git a/application/PreorderBilling/PreorderBillingController.php b/application/PreorderBilling/PreorderBillingController.php
index c96e65615..4c8a7875c 100644
--- a/application/PreorderBilling/PreorderBillingController.php
+++ b/application/PreorderBilling/PreorderBillingController.php
@@ -141,7 +141,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-03-13");
$today->setTime(2,0,0);
$today->setTimezone(new DateTimeZone("Europe/Vienna"));
@@ -380,7 +380,7 @@ class PreorderBillingController extends mfBaseController {
// Endkunde Setup Gebühr
if($status_244_change_date < $earliest_bill_date) {
- $this->log->debug(__METHOD__.": Not billing enduser_setup for preorder ".$preorder->id." because status change date ".$status_244_change_date->format("Y-m-d")." is before earliest_bill_date ".$earliest_bill_date->format("Y-m-d"));
+ $this->log->debug(__METHOD__.": Not billing enduser_setup for preorder ".$preorder->id." because status 244 change date ".$status_244_change_date->format("Y-m-d")." is before earliest_bill_date ".$earliest_bill_date->format("Y-m-d"));
return true;
}
@@ -448,7 +448,7 @@ class PreorderBillingController extends mfBaseController {
$billing_data["end_date"] = $status_change_date->format("Y-m-d");
}
- if(!$status_change_date) {
+ if(!$change_to_active) {
$status_change_date = $status_244_change_date;
}
@@ -481,10 +481,6 @@ 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()) {
@@ -568,7 +564,7 @@ class PreorderBillingController extends mfBaseController {
}
if($status_change_date->format("Ymd") > $latest_bill_date->format("Ymd")) {
- $this->log->debug(__METHOD__.": Skipping setup for preorder ".$preorder->id." because billing date (status change date) ".$status_change_date->format("Y-m-d")." is after latest_bill_date ".$latest_bill_date->format("Y-m-d"));
+ $this->log->debug(__METHOD__.": Skipping usage for preorder ".$preorder->id." because billing date (status change date) ".$status_change_date->format("Y-m-d")." is after latest_bill_date ".$latest_bill_date->format("Y-m-d"));
return true;
}
@@ -722,6 +718,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" => $start_date->format("Y-m-d"),
"end_date" => $end_date->format("Y-m-d"),
diff --git a/application/PreorderBillingCustomer/PreorderBillingCustomer.php b/application/PreorderBillingCustomer/PreorderBillingCustomer.php
index 3bc68d68f..000c80430 100644
--- a/application/PreorderBillingCustomer/PreorderBillingCustomer.php
+++ b/application/PreorderBillingCustomer/PreorderBillingCustomer.php
@@ -145,8 +145,8 @@ class PreorderBillingCustomer extends mfBaseModel
$where = self::getSqlFilter($filter);
$sql = "SELECT COUNT(*) as cnt FROM PreorderBillingCustomer
WHERE $where";
-
- //mfLoghandler::singleton()->debug($sql);
+ //var_dump($filter);exit;
+ mfLoghandler::singleton()->debug($sql);
$res = $db->query($sql);
if($db->num_rows($res)) {
@@ -276,6 +276,20 @@ class PreorderBillingCustomer extends mfBaseModel
}
}
+ if(array_key_exists("edit", $filter)) {
+ $edit = $filter["edit"];
+ if(is_numeric($edit)) {
+ $where .= " AND edit=$edit";
+ }
+ }
+
+ if(array_key_exists("edit>", $filter)) {
+ $edit = $filter["edit>"];
+ if(is_numeric($edit)) {
+ $where .= " AND edit > $edit";
+ }
+ }
+
if(array_key_exists("add-where", $filter)) {
$where .= " ".$filter['add-where'];
diff --git a/application/PreorderBillingInvoice/PreorderBillingInvoice.php b/application/PreorderBillingInvoice/PreorderBillingInvoice.php
index 2b60286d3..8c04df858 100644
--- a/application/PreorderBillingInvoice/PreorderBillingInvoice.php
+++ b/application/PreorderBillingInvoice/PreorderBillingInvoice.php
@@ -575,6 +575,17 @@ RML Infrastruktur GmbH";
}
}
+ if(array_key_exists("bmd_export_date", $filter)) {
+ $bmd_export_date = $filter['bmd_export_date'];
+ if($bmd_export_date === null || $bmd_export_date === false) {
+ $where .= " AND (PreorderBillingInvoice.bmd_export_date IS NULL OR PreorderBillingInvoice.bmd_export_date=0)";
+ } elseif($bmd_export_date === true) {
+ $where .= " AND (PreorderBillingInvoice.bmd_export_date IS NOT NULL AND PreorderBillingInvoice.bmd_export_date > 0)";
+ } elseif(is_numeric($bmd_export_date)) {
+ $where .= " AND PreorderBillingInvoice.bmd_export_date=$bmd_export_date";
+ }
+ }
+
if(array_key_exists("add-where", $filter)) {
$where .= " ".$filter['add-where'];
}
diff --git a/application/PreorderBillingInvoice/PreorderBillingInvoiceController.php b/application/PreorderBillingInvoice/PreorderBillingInvoiceController.php
index af809bbab..0a0658eec 100644
--- a/application/PreorderBillingInvoice/PreorderBillingInvoiceController.php
+++ b/application/PreorderBillingInvoice/PreorderBillingInvoiceController.php
@@ -58,11 +58,55 @@ class PreorderBillingInvoiceController extends mfBaseController {
$email_jobs = InvoiceJobModel::search(["task" => "send-preorder-invoice-email", "to_date>=" => $now->format("Y-m-d")]);
$this->layout()->set("email_jobs", $email_jobs);
+ $netoperators = [];
+ foreach(PreordercampaignModel::search(["owner_id" => $this->me->address_id]) as $campaign) {
+ foreach($campaign->active_operators as $op) {
+ if(!array_key_exists($op->operator_id, $netoperators)) {
+ $nop = new Address($op->operator_id);
+ if($nop->id) {
+ $netoperators[$nop->id] = $nop;
+ }
+
+ }
+ }
+ foreach($campaign->passive_operators as $op) {
+ if(!array_key_exists($op->operator_id, $netoperators)) {
+ $nop = new Address($op->operator_id);
+ if($nop->id) {
+ $netoperators[$nop->id] = $nop;
+ }
+ }
+ }
+ }
+
+ $this->layout()->set("netoperators", $netoperators);
+
+ // get last BMD export dates
+ $bmd_export_date_invoice = new mfConfig("preorder.invoice.bmd.export.invoice.ts.".$this->me->address_id);
+ $bmd_export_date_persion = new mfConfig("preorder.invoice.bmd.export.person.ts.".$this->me->address_id);
+
+ $bmd_export = [
+ "invoice" => $bmd_export_date_invoice->value(),
+ "person" => $bmd_export_date_persion->value(),
+ ];
+
+ $this->layout()->set("bmd_export", $bmd_export);
+
}
private function getPreparedFilter($filter) {
$new_filter = [];
+ if(array_key_exists("name", $filter)) {
+ if (array_key_exists("name", $filter)) {
+ if (array_key_exists("name", $filter) && $filter["name"]) {
+ $kunde = $this->db()->escape(trim($filter['name']));
+ if (!array_key_exists("add-where", $new_filter)) $new_filter["add-where"] = "";
+ $new_filter['add-where'] .= " AND (company like '%$kunde%' OR firstname like '%$kunde%' OR lastname like '%$kunde%' OR concat(firstname, ' ', lastname) like '%$kunde%' OR concat(lastname, ' ', firstname) like '%$kunde%')";
+ }
+ }
+ }
+
if(array_key_exists("start_date_from", $filter)) {
if($filter["start_date_from"]) {
try {
@@ -679,6 +723,207 @@ class PreorderBillingInvoiceController extends mfBaseController {
return ["sent" => $sent, "defer" => $defer];
}
+
+ protected function bmdExportPerson() {
+ $netowner_id = $this->me->address_id;
+ $netowner_config = TT_PREORDER_BILLING[$netowner_id];
+ if(!$netowner_config) {
+ $this->layout()->setFlash("Interner Fehler", "error");
+ $this->redirect("PreorderBillingInvoice");
+ }
+
+ $last_export = new mfConfig("preorder.invoice.bmd.export.person.ts.".$this->me->address_id);
+ $last_export_date = $last_export->value();
+
+ $csv = "\u{FEFF}Konto;Vorname;Nachname;Straße;Postleitzahl;Ort;Land;Telefon;Mail;UID\n";
+
+ if(!PreorderBillingCustomer::count(["edit>" => $last_export_date])) {
+ $this->layout()->setFlash("Keine neuen Personendaten zum Exportieren vorhanden", "info");
+ $this->redirect("PreorderBillingInvoice");
+ }
+
+ foreach(PreorderBillingCustomer::search(["edit>" => $last_export_date]) as $person) {
+ $konto = $person->fibu_account_number;
+ if($person->company) {
+ $vorname = "";
+ $nachname = $person->company;
+ } else {
+ $vorname = $person->firstname;
+ $nachname = $person->lastname;
+ }
+ $strasse = $person->street;
+ $plz = $person->zip;
+ $ort = $person->city;
+ $land = $person->country;
+ $telefon = $person->phone;
+ $mail = $person->email;
+ $uid = $person->uid;
+
+ if($konto) {
+ $csv .= "$konto;$vorname;$nachname;$strasse;$plz;$ort;$land;$telefon;$mail;$uid\n";
+ }
+ }
+
+ $subfolder = $netowner_config["subfolder"];
+ $today = new DateTime();
+
+ $csv_path = MFUPLOAD_FILE_SAVE_PATH."/$subfolder";
+ if(!file_exists($csv_path)) {
+ mkdir($csv_path, 0777, true);
+ }
+ $filename = "thetool-bmd-person-export-".$today->format("Y-m-d_H-i-s").".csv";
+ $filepath = "$csv_path/$filename";
+ if(file_put_contents($filepath, $csv) === false) {
+ $this->layout()->setFlash("Fehler beim Erstellen des BMD-Exports", "error");
+ $this->redirect("PreorderBillingInvoice");
+ }
+
+ $file = FileModel::create([
+ "name" => $filename,
+ "filename" => $filename,
+ "subfolder" => $subfolder,
+ "store_filename" => $filename,
+ "orig_filename" => $filename,
+ ]);
+ $file->save();
+
+ // copy csv file to bmd export transfer directory
+ $transfer_path = $netowner_config["bmd-export-transfer-path"];
+ $transfer_file = "$transfer_path/$filename";
+ $this->log->debug(__METHOD__.": Copying $filepath to $transfer_file");
+ if(!copy($filepath, $transfer_file)) {
+ $this->layout()->setFlash("Fehler beim Kopieren des BMD-Exports", "error");
+ $this->redirect("PreorderBillingInvoice");
+ }
+
+ $last_export->value(date("U"));
+ $last_export->save();
+
+ $this->layout()->setFlash("Personenexport erfolgreich erstellt", "success");
+ $this->redirect("PreorderBillingInvoice");
+
+ }
+
+ protected function bmdExport() {
+ $type = $this->request->type;
+ $netowner_id = $this->me->address_id;
+ $netowner_config = TT_PREORDER_BILLING[$netowner_id];
+ if(!$netowner_config) {
+ $this->layout()->setFlash("Interner Fehler", "error");
+ $this->redirect("PreorderBillingInvoice");
+ }
+
+ if($type != "addresses" && $type != "invoice") {
+ $this->layout()->setFlash("Ungültiger Export-Typ", "error");
+ $this->redirect("PreorderBillingInvoice");
+ }
+
+ if($type == "addresses") {
+ return $this->bmdExportPerson();
+ }
+
+ $satzart = 0;
+ $buchsymbol = "ABR";
+ $buchcode = "1";
+ $prozent = 20;
+ $steuercode = 1;
+
+ $csv = "\u{FEFF}satzart;konto;gkonto;belegnr;belegdatum;buchsymbol;buchcode;prozent;steuercode;betrag;steuer;text;kost;kotraeger;kobetrag\n";
+
+ $invoices = [];
+
+ if(!PreorderBillingInvoice::count(["netowner_id" => $netowner_id, "bmd_export_date" => null])) {
+ $this->layout()->setFlash("Keine neuen Rechnungen zum exportieren vorhanden", "info");
+ $this->redirect("PreorderBillingInvoice");
+ }
+
+ foreach(PreorderBillingInvoice::search(["netowner_id" => $netowner_id, "bmd_export_date" => null]) as $invoice) {
+ $invoice->bmd_export_date = date("U");
+ $invoices[] = $invoice;
+
+ $kostentraeger = [];
+ foreach($invoice->positions as $position) {
+ if(!array_key_exists($position->article_number, $kostentraeger)) {
+ $kostentraeger[$position->article_number] = 0;
+ }
+ $kostentraeger[$position->article_number] += $position->price_gross;
+ }
+
+ $invoice_date = new DateTime($invoice->invoice_date);
+
+ $konto = $invoice->customer_number;
+ $gkonto = $invoice->fibu_revenue_code;
+ $belegnr = $invoice->invoice_number;
+ $belegdatum = $invoice_date->format("d.m.Y");
+ $betrag = number_format($invoice->total_gross, 2, ",", "");
+ $steuer = number_format(($invoice->total_gross - $invoice->total) * -1, 2, ",", "");
+ $text = ($invoice->company ?: $invoice->firstname." ".$invoice->lastname)." $belegnr";
+ $text = str_replace(["\r","\n", '"'], [" "," ",'""'], $text);
+ $kost = $invoice->fibu_cost_account;
+
+ if(count($kostentraeger) < 2) {
+ $csv_line = "$satzart;$konto;$gkonto;$belegnr;$belegdatum;$buchsymbol;$buchcode;$prozent;$steuercode;$betrag;$steuer;\"$text\";$kost";
+ } else {
+ $csv_line = "$satzart;$konto;$gkonto;$belegnr;$belegdatum;$buchsymbol;$buchcode;$prozent;$steuercode;$betrag;$steuer;\"$text\";;";
+ foreach($kostentraeger as $kotraeger => $kobetrag) {
+ $kobetrag_text = number_format($kobetrag, 2, ",", "");
+ $csv_line .= "\n1;;;;;;;;;;;;$kost;$kotraeger;$kobetrag_text";
+ }
+ }
+
+
+ $csv .= "$csv_line\n";
+ }
+
+ /*echo $csv;
+ exit;*/
+
+ $subfolder = $netowner_config["subfolder"];
+ $today = new DateTime();
+
+ $csv_path = MFUPLOAD_FILE_SAVE_PATH."/$subfolder";
+ if(!file_exists($csv_path)) {
+ mkdir($csv_path, 0777, true);
+ }
+ $filename = "thetool-bmd-invoice-export-".$today->format("Y-m-d_H-i-s").".csv";
+ $filepath = "$csv_path/$filename";
+ if(file_put_contents($filepath, $csv) === false) {
+ $this->layout()->setFlash("Fehler beim Erstellen des BMD-Exports", "error");
+ $this->redirect("PreorderBillingInvoice");
+ }
+
+ $file = FileModel::create([
+ "name" => $filename,
+ "filename" => $filename,
+ "subfolder" => $subfolder,
+ "store_filename" => $filename,
+ "orig_filename" => $filename,
+ ]);
+ $file->save();
+
+ // copy csv file to bmd export transfer directory
+ $transfer_path = $netowner_config["bmd-export-transfer-path"];
+ $transfer_file = "$transfer_path/$filename";
+ $this->log->debug(__METHOD__.": Copying $filepath to $transfer_file");
+ if(!copy($filepath, $transfer_file)) {
+ $this->layout()->setFlash("Fehler beim Kopieren des BMD-Exports", "error");
+ $this->redirect("PreorderBillingInvoice");
+ }
+
+ $bmd_export_date = new mfConfig("preorder.invoice.bmd.export.invoice.ts.".$this->me->address_id);
+ $bmd_export_date->value(date("U"));
+ $bmd_export_date->save();
+
+ foreach($invoices as $invoice) {
+ $invoice->save();
+ }
+
+ $this->layout()->setFlash("Rechnungsexport erfolgreich erstellt", "success");
+ $this->redirect("PreorderBillingInvoice");
+
+ }
+
+
protected function apiAction() {
$do = $this->request->do;
$data = [];