diff --git a/Layout/default/Contractqueue/Index.php b/Layout/default/Contractqueue/Index.php index c48014fb6..7285e07b3 100644 --- a/Layout/default/Contractqueue/Index.php +++ b/Layout/default/Contractqueue/Index.php @@ -194,8 +194,12 @@
-
+
+
+ +
+
Bestelljournal
@@ -248,6 +252,7 @@ + @@ -354,6 +359,11 @@ +
Verz. Verrechnungsstart Erstellt Zuletzt bearbeitet
orderproduct->create)?>
orderproduct->creator->name?>
orderproduct->edit)?>
orderproduct->editor->name?>
+ $contract->orderproduct_id])?>" onclick="if(!confirm('Löscht die Position in Bestellung und Contractqueue. Wirklich löschen?')) return false;"> + + +
@@ -721,6 +731,11 @@ }); } + function toggleJournal(order_id) { + $("#orderjournal-" + order_id).find("div.opener").remove(); + $("#orderjournal-" + order_id).css("max-height", "550px").css("overflow", "auto"); + } + diff --git a/application/Contract/ContractModel.php b/application/Contract/ContractModel.php index f1ea89cf0..d712b70fc 100644 --- a/application/Contract/ContractModel.php +++ b/application/Contract/ContractModel.php @@ -94,6 +94,7 @@ class ContractModel { $data["price_setup"] = $op->price_setup; $data["price_nne"] = $op->price_nne; $data["price_nbe"] = $op->price_nbe; + $data["vatgroup_id"] = $op->product->vatgroup_id; $data["billing_delay"] = $op->billing_delay; $data["billing_period"] = $op->billing_period; $data["order_date"] = $order->order_date; @@ -152,6 +153,7 @@ class ContractModel { $data["price_setup"] = $cq->price_setup; $data["price_nne"] = $cq->price_nne; $data["price_nbe"] = $cq->price_nbe; + $data["vatgroup_id"] = $cq->vatgroup_id; $data["billing_delay"] = $cq->billing_delay; $data["billing_period"] = $cq->billing_period; $data["contract_term"] = $cq->contract_term; diff --git a/application/Contractqueue/ContractqueueController.php b/application/Contractqueue/ContractqueueController.php index 9b9c5f4fc..0971c0e10 100644 --- a/application/Contractqueue/ContractqueueController.php +++ b/application/Contractqueue/ContractqueueController.php @@ -15,6 +15,8 @@ class ContractqueueController extends mfBaseController { } protected function indexAction() { + $this->importOrders(); + if($this->request->resetFilter) { unset($_SESSION[MFAPPNAME.'-Contractqueue-filter']); } @@ -67,22 +69,65 @@ class ContractqueueController extends mfBaseController { } protected function getPreparedFilter($filter) { - return $filter; } - - protected function importFinishedOrdersAction() { - $o = 0; - $max_orders = 1500; - $not_before = new DateTime("2024-07-10"); + protected function deletePosition() { + $op_id = $this->request->op_id; + + $cq = ContractqueueModel::getFirst(["orderproduct_id" => $op_id]); + if(!$cq) { + $this->layout()->setFlash("Bestellung in Contractqueue nicht gefunden", "error"); + $this->redirect("Contractqueue"); + } + + $op = new OrderProduct($op_id); + if(!$op->id) { + $this->layout()->setFlash("Bestellung nicht gefunden", "error"); + $this->redirect("Contractqueue"); + } + + $order = $op->order; + if(!$order) { + $this->layout()->setFlash("Bestellung nicht gefunden", "error"); + $this->redirect("Contractqueue"); + } + + if(!is_array($order->products) || $order->products < 2 ) { + $this->layout()->setFlash("Nur ein Produkt in Bestellung gefunden. Kann nicht gelöscht werden", "warning"); + $this->redirect("Contractqueue"); + } + + $this->log->debug(__METHOD__.": Deleting OrderProduct $op_id from Order ".$order->id." (product_id: ".$op->product_id." product_name: ".$op->product->name." price: ".$op->price." price_setup: ".$op->price_setup." termination_id: ".$op->termination_id." voicenumber: ".$op->voicenumber.")"); + + if(!$op->delete()) { + $this->layout()->setFlash("Fehler beim Löschen der Bestellposition", "error"); + $this->redirect("Contractqueue"); + } + + if(!$cq->delete()) { + $this->layout()->setFlash("Fehler beim Löschen der Contractqueue Position", "error"); + $this->redirect("Contractqueue"); + } + + $this->layout()->setFlash("Position erfolgreich gelöscht", "success"); + $this->redirect("Contractqueue"); + + + } + + private function importOrders() { + $o = 0; + //$max_orders = 1500; + + $not_before = new DateTime("2024-07-01"); foreach(OrderModel::search(["finish_date" => true, "finish_date<" => date("U"), "finish_date>" => $not_before->getTimestamp()]) as $order) { if(!is_array($order->products) || !count($order->products)) { //echo "keine Produkte in Order ".$order->id."\n"; continue; } - + if(ContractqueueModel::getFirst(["order_id" => $order->id])) { continue; } @@ -90,7 +135,7 @@ class ContractqueueController extends mfBaseController { $skip_order = false; $contracts = []; $primary_matchcode = false; - + foreach($order->products as $op) { $contract = ContractModel::getFirst(["orderproduct_id" => $op->id]); @@ -108,10 +153,10 @@ class ContractqueueController extends mfBaseController { $skip_order = true; continue; } - + // if contract does not exist yet, create Contractqueue $contract = ContractqueueModel::createFromOrderproduct($op); - + // find reseller / receiver of credit // from product $product_attribs = $contract->product->attributes; @@ -130,7 +175,7 @@ class ContractqueueController extends mfBaseController { if(!$contract->crediting_partner_id && $contract->termination_id) { $contract->crediting_partner_id = $contract->termination->building->network->owner_id; } - + if($contract->matchcode) { $primary_matchcode = $contract->matchcode; } @@ -142,26 +187,26 @@ class ContractqueueController extends mfBaseController { $contracts = []; continue; } - + if(!$primary_matchcode) { $primary_matchcode = $order->owner->street.", ".$order->owner->zip." ".$order->owner->city; } - + $links = []; // set matchcode and save foreach($contracts as $contract) { if(!$contract->matchcode) { $contract->matchcode = $primary_matchcode; - + } //var_dump($contract);exit; $contract->save(); - + /*if(!count($links)) { $links[$contract->id] = $contract; } elseif(!array_key_exists($contract->id, $links)) { $first_link = reset($links); - + $new_link = ContractLinkModel::create([ "contract_id" => $first_link->id, "origin_contract_id" => $contract->id, @@ -170,18 +215,13 @@ class ContractqueueController extends mfBaseController { $new_link->save(); $links[$contract->id] = $contract; }*/ - + } - + $o++; - - if($o >= $max_orders) { - $this->layout()->setFlash("$o Bestellungen importiert, es gibt noch mehr Bestellungen zum importieren.", "info"); - $this->redirect("Contractqueue"); - } } - $this->layout()->setFlash("Alle Bestellungen importiert", "success"); - $this->redirect("Contractqueue"); + return true; + } protected function commitAction() { @@ -238,6 +278,7 @@ class ContractqueueController extends mfBaseController { $journal->save(); $contract->addFilesFromOrder(); + $contract->addJournalFromOrder(); /* * Create Crediting Contract diff --git a/application/Contractqueue/ContractqueueModel.php b/application/Contractqueue/ContractqueueModel.php index ee066fa14..51d6cf481 100644 --- a/application/Contractqueue/ContractqueueModel.php +++ b/application/Contractqueue/ContractqueueModel.php @@ -23,6 +23,7 @@ class ContractqueueModel { public $price_setup = null; public $price_nne = null; public $price_nbe = null; + public $vatgroup_id = null; public $billing_delay = null; public $billing_period = null; public $order_date; @@ -100,6 +101,7 @@ class ContractqueueModel { $data["price_setup"] = $op->price_setup; $data["price_nne"] = $op->price_nne; $data["price_nbe"] = $op->price_nbe; + $data["vatgroup_id"] = $op->product->vatgroup_id; $data["billing_delay"] = $op->billing_delay; $data["billing_period"] = $op->billing_period; $data["order_date"] = $order->order_date; diff --git a/db/migrations/20240801152305_contractqueue_add_vatgroup_id.php b/db/migrations/20240801152305_contractqueue_add_vatgroup_id.php new file mode 100644 index 000000000..a40d73edf --- /dev/null +++ b/db/migrations/20240801152305_contractqueue_add_vatgroup_id.php @@ -0,0 +1,31 @@ +getEnvironment() == "thetool") { + $table = $this->table("Contractqueue"); + $table->addColumn("vatgroup_id", "integer", ["null" => false, "after" => "price_nbe"]); + $table->save(); + } + + if($this->getEnvironment() == "addressdb") { + + } + } + + public function down(): void + { + if($this->getEnvironment() == "thetool") { + + } + + if($this->getEnvironment() == "addressdb") { + + } + } +}