diff --git a/application/Billing/BillingController.php b/application/Billing/BillingController.php index eee5bb9bf..8a3512115 100644 --- a/application/Billing/BillingController.php +++ b/application/Billing/BillingController.php @@ -164,6 +164,14 @@ class BillingController extends mfBaseController { //$now_month = 11; //$now_day = 3; + $locked = new mfConfig("billing.running"); + if($locked->value()) { + $this->layout()->setFlash("Läuft schon seit ".date("d.m.Y H:i", $locked->edit)); + $this->redirect("Billing"); + } + $locked->value(1); + $locked->save(); + // XXX only for 1st Billing after IVT Import // Locking to July 2024 and keeping it for now $yearly_not_before = new DateTime("2024-07-01"); @@ -467,6 +475,12 @@ class BillingController extends mfBaseController { $data["billingaddress_id"] = ($contract->billingaddress_id) ? $contract->billingaddress_id : $contract->owner_id; $data["customer_number"] = $contract->owner->customer_number; $data["fibu_account_number"] = $fibu_account_num; + + // TODO: Zahlungsziel / Skonto muss in Zukuft vom Contract übernommen werden + $data["fibu_payment_due"] = $owner->fibu_payment_due ?: TT_ADDRESS_DEFAULT_PAYMENT_DUE; + $data["fibu_payment_skonto"] = $owner->fibu_payment_skonto ?: 0; + $data["fibu_payment_skonto_rate"] = $owner->fibu_payment_skonto_rate ?: 0; + $data["company"] = $billingaddress->company; $data["firstname"] = $billingaddress->firstname; $data["lastname"] = $billingaddress->lastname; @@ -758,6 +772,10 @@ class BillingController extends mfBaseController { } + + $locked->value(0); + $locked->save(); + $this->layout()->setFlash("$i Contract Billing records generiert. $v Voicenumber Billing records generiert"); $this->redirect("Billing"); diff --git a/application/Billing/BillingModel.php b/application/Billing/BillingModel.php index 6892bd68d..f2a40ea0c 100644 --- a/application/Billing/BillingModel.php +++ b/application/Billing/BillingModel.php @@ -9,6 +9,9 @@ class BillingModel { public $billingaddress_id; public $customer_number; public $fibu_account_number; + public $fibu_payment_due; + public $fibu_payment_skonto; + public $fibu_payment_skonto_rate; public $sepa_date; public $sepa_id; public $sepa_last_date; diff --git a/application/Invoice/InvoiceController.php b/application/Invoice/InvoiceController.php index 8d41e60bf..1871ffd2e 100644 --- a/application/Invoice/InvoiceController.php +++ b/application/Invoice/InvoiceController.php @@ -483,9 +483,9 @@ class InvoiceController extends mfBaseController { $invoice_data["billingaddress_id"] = $billingaddress_id; $invoice_data["customer_number"] = $bill->customer_number; $invoice_data["fibu_account_number"] = $bill->fibu_account_number; - $invoice_data["fibu_payment_due"] = $bill->fibu_payment_due; - $invoice_data["fibu_payment_skonto"] = $bill->fibu_payment_skonto; - $invoice_data["fibu_payment_skonto_rate"] = $bill->fibu_payment_skonto_rate; + $invoice_data["fibu_payment_due"] = $bill->fibu_payment_due ?: 14; + $invoice_data["fibu_payment_skonto"] = $bill->fibu_payment_skonto ?: 0; + $invoice_data["fibu_payment_skonto_rate"] = $bill->fibu_payment_skonto_rate ?: 0; $invoice_data["sepa_date"] = $bill->sepa_date; diff --git a/db/migrations/20250805170206_billing_add_payment_due.php b/db/migrations/20250805170206_billing_add_payment_due.php new file mode 100644 index 000000000..93e5ae308 --- /dev/null +++ b/db/migrations/20250805170206_billing_add_payment_due.php @@ -0,0 +1,77 @@ +getEnvironment() == "thetool") { + + $billing = $this->table("Billing"); + $billing->addColumn("fibu_payment_due", "integer", ["null" => true, "default" => null, "after" => "fibu_account_number"]); + $billing->addColumn("fibu_payment_skonto", "integer", ["null" => false, "default" => 0, "after" => "fibu_payment_due"]); + $billing->addColumn("fibu_payment_skonto_rate", "integer", ["null" => false, "default" => 0, "after" => "fibu_payment_skonto"]); + $billing->addIndex("invoice_id"); + $billing->addIndex("contract_id"); + $billing->addIndex("start_date"); + $billing->addIndex("end_date"); + $billing->update(); + + $bv = $this->table("BillingVoicenumber"); + $bv->addIndex("contract_id"); + $bv->addIndex("voicenumber"); + $bv->addIndex("start_date"); + $bv->addIndex("end_date"); + $bv->update(); + + $invoice = $this->table("Invoice"); + $invoice->addIndex("invoice_number"); + $invoice->addIndex("invoice_date"); + $invoice->addIndex("owner_id"); + $invoice->addIndex("billingaddress_id"); + $invoice->addIndex("customer_number"); + $invoice->save(); + + } + + if($this->getEnvironment() == "addressdb") { + + } + } + + public function down(): void + { + if($this->getEnvironment() == "thetool") { + $this->table("Billing") + ->removeColumn("fibu_payment_skonto_rate") + ->removeColumn("fibu_payment_skonto") + ->removeColumn("fibu_payment_due") + ->removeIndex("end_date") + ->removeIndex("start_date") + ->removeIndex("contract_id") + ->removeIndex("invoice_id") + ->update(); + + $this->table("BillingVoicenumber") + ->removeIndex("end_date") + ->removeIndex("start_date") + ->removeIndex("voicenumber") + ->removeIndex("contract_id") + ->update(); + + $this->table("Invoice") + ->removeIndex("customer_number") + ->removeIndex("billingaddress_id") + ->removeIndex("owner_id") + ->removeIndex("invoice_date") + ->removeIndex("invoice_number") + ->update(); + } + + if($this->getEnvironment() == "addressdb") { + + } + } +}