Changed to contractqueue and contract

This commit is contained in:
Frank Schubert
2024-08-01 20:45:44 +02:00
parent 489d081d35
commit 840c5b6f2a
9 changed files with 282 additions and 38 deletions

View File

@@ -225,16 +225,16 @@ class ContractqueueController extends mfBaseController {
}
protected function commitAction() {
protected function commitOrderAction() {
$r = $this->request;
//var_dump($r->get());exit;
$new_contracts = [];
$c = 0;
$o = 0;
$last_order_id = 0;
$new_contracts = [];
$order_id = $r->order_id;
foreach(ContractqueueModel::search(["approved" => true, "contract_id" => null]) as $cq) {
foreach(ContractqueueModel::search(["order_id" => $order_id, "contract_id" => null]) as $cq) {
//var_dump($cq);exit;
$contract = ContractModel::getFirst(["orderproduct_id" => $cq->orderproduct_id]);
if($contract) {
@@ -242,18 +242,6 @@ class ContractqueueController extends mfBaseController {
continue;
} // contract should not yet exist
$order_id = $cq->orderproduct->order_id;
if($c >= 2000) {
if($order_id != $last_order_id) {
$this->layout()->setFlash("$c Contracts (exkl. Gutschriften) erstellt", "info");
$this->redirect("Contractqueue");
}
}
$last_order_id = $order_id;
/*
* Create Contract
*/
@@ -266,7 +254,6 @@ class ContractqueueController extends mfBaseController {
$c++;
$cq->contract_id = $contract->id;
$cq->save();
@@ -358,6 +345,139 @@ class ContractqueueController extends mfBaseController {
}
/*protected function commitAction() {
$r = $this->request;
//var_dump($r->get());exit;
$new_contracts = [];
$c = 0;
$o = 0;
$last_order_id = 0;
foreach(ContractqueueModel::search(["approved" => true, "contract_id" => null]) as $cq) {
//var_dump($cq);exit;
$contract = ContractModel::getFirst(["orderproduct_id" => $cq->orderproduct_id]);
if($contract) {
$this->log->debug("Contract von orderproduct ".$cq->orderproduct_id." existiert schon: ".$contract->id);
continue;
} // contract should not yet exist
$order_id = $cq->orderproduct->order_id;
if($c >= 2000) {
if($order_id != $last_order_id) {
$this->layout()->setFlash("$c Contracts (exkl. Gutschriften) erstellt", "info");
$this->redirect("Contractqueue");
}
}
$last_order_id = $order_id;
/*
* Create Contract
*//*
$contract = ContractModel::createFromContractqueue($cq);
if(!$contract->save()) {
$this->log->debug("Eine Position in Bestellung ".$cq->order_id." konnte nicht übernommen werden: Fehler beim Speichern");
$this->layout()->setFlash("Eine Position in Bestellung ".$cq->order_id." konnte nicht übernommen werden: Fehler beim Speichern", "warning");
continue;
}
$c++;
$cq->contract_id = $contract->id;
$cq->save();
// create Contractjournal
$journal = ContractjournalModel::create([
'contract_id' => $contract->id,
'type' => "created_from",
'value' => "order"
]);
$journal->save();
$contract->addFilesFromOrder();
$contract->addJournalFromOrder();
/*
* Create Crediting Contract
* if required
*//*
if($cq->approved_credit) {
$credit = ContractModel::createFromContractQueue($cq, "credit");
if(!$credit->save()) {
$this->log->log("Zu einer Position in Bestellung ".$cq->order_id." konnte keine Gutschrift erstellt werden: Fehler beim Speichern");
$this->layout()->setFlash("Zu einer Position in Bestellung ".$cq->order_id." konnte keine Gutschrift erstellt werden: Fehler beim Speichern", "warning");
continue;
}
$journal = ContractjournalModel::create([
'contract_id' => $credit->id,
'type' => "created_from",
'value' => "order"
]);
$journal->save();
$journal = ContractjournalModel::create([
'contract_id' => $contract->id,
'type' => "credit_created",
'value' => $credit->id
]);
$journal->save();
$link = ContractLinkModel::create([
'contract_id' => $credit->id,
'origin_contract_id' => $contract->id,
'type' => 'credit'
]);
$link->save();
// XXX: retour link erstellen?
}
/*
* Create ContractLinks
*//*
if(array_key_exists($order_id, $new_contracts)) {
foreach ($new_contracts[$order_id] as $origin) {
if (ContractLinkModel::getFirst(["contract_id" => $contract->id, "origin_contract_id" => $origin->id])) {
continue;
}
$link = ContractLinkModel::create([
'contract_id' => $contract->id,
'origin_contract_id' => $origin->id,
'type' => 'link'
]);
$link->save();
if ($link->id) {
$journal = ContractjournalModel::create([
'contract_id' => $contract->id,
'type' => "link",
'value' => $origin->id
]);
$journal->save();
$ojournal = ContractjournalModel::create([
'contract_id' => $origin->id,
'type' => "link",
'value' => $contract->id
]);
$ojournal->save();
}
}
} else {
$new_contracts[$order_id] = [];
}
$new_contracts[$order_id][] = $contract;
}
$this->layout()->setFlash("$c Contracts erstellt", "success");
$this->redirect("Contractqueue");
}*/
protected function apiAction() {
if(!$this->me->is(["Admin"])) {
$this->redirect("Dashboard");