Contractqueue changes

This commit is contained in:
Frank Schubert
2024-08-01 19:15:44 +02:00
parent ffa5497759
commit 7f3075dae6
5 changed files with 117 additions and 26 deletions

View File

@@ -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

View File

@@ -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;