Contract Cancelling done

This commit is contained in:
Frank Schubert
2024-07-10 21:13:21 +02:00
parent 171b32fb56
commit 5b0141cf68
6 changed files with 276 additions and 15 deletions

View File

@@ -272,7 +272,7 @@ class Admin_IvtCreditImport {
$link = ContractLinkModel::create([
'contract_id' => $cred_contract->id,
'origin_contract_id' => $contract->id,
'type' => 'link'
'type' => 'credit'
]);
$link->save();
}

View File

@@ -115,6 +115,82 @@ class ContractController extends mfBaseController
}
protected function cancelAction() {
$this->layout()->setTemplate("Contract/CancelForm");
$id = $this->request->contract_id;
if (!$id) $id = $this->request->id;
if(!$id) {
$id = $this->request->id;
}
if (!is_numeric($id) || !$id) {
$this->layout()->setFlash("Vertrag nicht gefunden", "error");
$this->redirect("Contract");
}
$contract = new Contract($id);
if (!$contract->id) {
$this->layout()->setFlash("Vertrag nicht gefunden", "error");
$this->redirect("Contract");
}
$this->layout()->set("contract", $contract);
}
protected function saveCancel() {
$r = $this->request;
$id = $r->contract_id;
if (!is_numeric($id) || !$id) {
$this->layout()->setFlash("Vertrag nicht gefunden", "error");
$this->redirect("Contract");
}
$contract = new Contract($id);
if (!$contract->id) {
$this->layout()->setFlash("Vertrag nicht gefunden", "error");
$this->redirect("Contract");
}
try {
$cancel_date = DateTime::createFromFormat("d.m.Y", trim($r->cancel_date), new DateTimeZone("Europe/Vienna"));
$cancel_date->setTime(2,0,0);
} catch(Exception $e) {
$this->layout()->setFlash("Ungültiges Datumsformat");
$this->redirect("Contract", "cancel", ["contract_id" => $contract->id]);
}
$contract->cancel_date = $cancel_date->getTimestamp();
if(!$contract->save()) {
$this->layout()->setFlash("Verlinkten Vertrag $link_id nicht gefunden", "error");
$this->redirect("Contract", "cancel", ["contract_id" => $contract->id]);
}
if(is_array($r->links)) {
foreach($r->links as $link_id => $action) {
if($action == "cancel") {
$link_contract = new Contract($link_id);
if (!$link_contract->id) {
$this->layout()->setFlash("Verlinkten Vertrag $link_id nicht gefunden", "warning");
continue;
}
$link_contract->cancel_date = $cancel_date->getTimestamp();
if(!$link_contract->save()) {
$this->layout()->setFlash("Fehler beim Speichern von verlinktem Vertrag", "warning");
}
}
}
}
$this->layout()->setFlash("Kündigung gespeichert", "success");
$this->redirect("Contract", "view", ["contract_id" => $contract->id]);
}
protected function productchangeAction()
{
$this->layout()->setTemplate("Contract/ProductchangeForm");
@@ -387,18 +463,6 @@ class ContractController extends mfBaseController
}
protected function cancelAction()
{
$id = $this->request->contract_id;
if (!$id) $id = $this->request->id;
$this->layout()->setFlash("Not implemented", "error");
if ($id) {
$this->redirect("Contract", "view", ["id" => $id]);
} else {
$this->redirect("Contract");
}
}
protected function addAction()
{