From 840c5b6f2a1435423a63aecb3ba142ffdbd51ea2 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Thu, 1 Aug 2024 20:45:44 +0200 Subject: [PATCH] Changed to contractqueue and contract --- Layout/default/Contract/Form.php | 10 +- Layout/default/Contract/View.php | 36 +++- Layout/default/Contractqueue/Index.php | 14 +- application/Contract/Contract.php | 29 ++++ application/Contract/ContractController.php | 2 +- application/ContractFile/ContractFile.php | 46 +++++- .../ContractjournalController.php | 2 +- .../Contractqueue/ContractqueueController.php | 156 ++++++++++++++++-- application/File/File.php | 25 ++- 9 files changed, 282 insertions(+), 38 deletions(-) diff --git a/Layout/default/Contract/Form.php b/Layout/default/Contract/Form.php index d7219b92a..def3cfd44 100644 --- a/Layout/default/Contract/Form.php +++ b/Layout/default/Contract/Form.php @@ -438,7 +438,15 @@ }, function(success) { if(success.status != "OK") return; - + + var sla_id; + if(p.sla_id) { + sla_id = p.sla_id; + } else { + sla_id = 4; + } + + p = success.result.product; $("#vatgroup_id").val(p.vatgroup_id); $("#price").val(p.price); diff --git a/Layout/default/Contract/View.php b/Layout/default/Contract/View.php index a32bf419b..4f474abaf 100644 --- a/Layout/default/Contract/View.php +++ b/Layout/default/Contract/View.php @@ -240,8 +240,8 @@ - - + +
Journaleinträge
@@ -267,7 +267,7 @@ text) > 120): ?> text), 120)?> - + @@ -293,7 +293,7 @@ value == "import"): ?> Vertrag importiert: text))?> value == "order"): ?> - Vertrag aus Bestellung $contract->orderproduct->order_id])?>">#orderproduct->order_id?> erstellt + Vertrag aus Bestellung $contract->orderproduct->order_id])?>">#orderproduct->order_id?> erstellt value == "productchange"): ?> Vertrag erstellt: text))?> @@ -454,5 +454,33 @@ $("#truncated-" + id).toggle(); $("#fulltext-" + id).toggle(); } + + $(document).on('click', '[data-toggle="lightbox"]', function(event) { + event.preventDefault(); + $(this).ekkoLightbox({ + alwaysShowClose: true, + showArrows: false + }); + }); + + function downloadImage(image_id) { + event.preventDefault(); + location.href="?id=" + image_id; + } + + function toggleGallery() { + $("#ticketfile-body").toggle(); + + if($("#ticketfile-body").is(":hidden")) { + console.log("is hidden"); + $("#gallery-toggle-button").removeClass("fa-caret-down"); + $("#gallery-toggle-button").addClass("fa-caret-right"); + } else { + console.log("is not hidden"); + $("#gallery-toggle-button").removeClass("fa-caret-right"); + $("#gallery-toggle-button").addClass("fa-caret-down"); + } + + } \ No newline at end of file diff --git a/Layout/default/Contractqueue/Index.php b/Layout/default/Contractqueue/Index.php index 7285e07b3..9d8c4d85a 100644 --- a/Layout/default/Contractqueue/Index.php +++ b/Layout/default/Contractqueue/Index.php @@ -79,13 +79,12 @@
-
"> +

Fertiggestellte Bestellungen

-
"> Fertiggestellte Bestellungen importieren @@ -243,7 +242,6 @@
Produkte
- @@ -257,7 +255,6 @@ -
Produkt Matchcode Preis
approved) ? "checked='checked'" : ""?> />
product_name?> @@ -371,7 +368,6 @@
Gutschriften / Provisionen
- @@ -386,7 +382,6 @@ getCredit(); if(!$credit) continue; ?> -
Bezieher Produkt Matchcode
approved_credit) ? "checked='checked'" : ""?> /> getCompanyOrName() : ""?> product_name?> @@ -427,7 +422,10 @@
- + "> + + +
@@ -443,8 +441,6 @@ - - diff --git a/application/Contract/Contract.php b/application/Contract/Contract.php index 18b9b889c..1c173d0e5 100644 --- a/application/Contract/Contract.php +++ b/application/Contract/Contract.php @@ -32,6 +32,7 @@ class Contract extends mfBaseModel { private $vatgroup; private $vatrate; private $voicenumbers; + private $files; private $finisher; private $canceler; private $creator; @@ -305,8 +306,28 @@ class Contract extends mfBaseModel { ]); $journal->save(); } + } + public function addJournalFromOrder() { + if(!$this->orderproduct_id) { + return true; + } + $order = $this->getProperty("orderproduct")->order; + if(!$order || !$order->id) { + return true; + } + foreach($order->journals as $order_journal) { + $journal = ContractjournalModel::create([ + 'contract_id' => $this->id, + 'type' => "text", + 'value' => "", + 'text' => $order_journal->text + ]); + $journal->save(); + } + + return true; } public function getVoicenumbers() { @@ -589,6 +610,14 @@ class Contract extends mfBaseModel { } return $this->$name; } + if($name == "files") { + $files = ContractFileModel::search(["contract_id" => $this->id]); + if($files) { + $this->files = $files; + return $this->files; + } + return []; + } if($name == "finisher") { $this->finisher = mfValuecache::singleton()->get("Worker-id-" . $this->finish_date_by); diff --git a/application/Contract/ContractController.php b/application/Contract/ContractController.php index 2ce35032c..221ef2126 100644 --- a/application/Contract/ContractController.php +++ b/application/Contract/ContractController.php @@ -766,7 +766,7 @@ class ContractController extends mfBaseController $contract_data["product_info"] = $r->product_info; $contract_data['amount'] = ($r->amount) ? (float)$r->amount : 1; $contract_data['vatgroup_id'] = $r->vatgroup_id; - $contract_data['sla_id'] = (float)$r->sla_id; + $contract_data['sla_id'] = $r->sla_id; $contract_data['price'] = (float)$r->price; $contract_data['price_setup'] = (float)$r->price_setup; $contract_data['price_nne'] = (float)$r->price_nne; diff --git a/application/ContractFile/ContractFile.php b/application/ContractFile/ContractFile.php index f8f88ebda..fad92dbf4 100644 --- a/application/ContractFile/ContractFile.php +++ b/application/ContractFile/ContractFile.php @@ -1,5 +1,49 @@ id) { + return false; + } + + $file = $this->getProperty("file"); + if(preg_match('#^image/#i', $file->mimetype)) { + return true; + } + + return false; + } + + public function getProperty($name) { + if($this->$name == null) { + + if(!$this->id) { + return null; + } + + if($name == "creator") { + $this->creator = new User($this->create_by); + return $this->creator; + } + + if($name == "editor") { + $this->editor = new User($this->edit_by); + return $this->editor; + } + + $classname = ucfirst($name); + $idfield = $name."_id"; + $this->$name = new $classname($this->$idfield); + + if($this->$name->id) { + return $this->$name; + } else { + return null; + } + } + + return $this->$name; + } } \ No newline at end of file diff --git a/application/Contractjournal/ContractjournalController.php b/application/Contractjournal/ContractjournalController.php index 410856b3e..0d6bdf648 100644 --- a/application/Contractjournal/ContractjournalController.php +++ b/application/Contractjournal/ContractjournalController.php @@ -52,7 +52,7 @@ class ContractjournalController extends mfBaseController { // returns File object or throws Exception on error $file = mfUpload::handleFormUpload("journal_file"); } catch (Exception $ex) { - $this->layout()->setFlash("Fehler beim Dateiupload: ".$ex->getMessage(), "error"); + $this->layout()->setFlash("Fehler beim Dateiupload: ".$ex->getCode().": ".$ex->getMessage(), "error"); $this->redirect("Contract", "view", ['contract_id' => $contract_id]); } diff --git a/application/Contractqueue/ContractqueueController.php b/application/Contractqueue/ContractqueueController.php index fd17c253b..8747b085a 100644 --- a/application/Contractqueue/ContractqueueController.php +++ b/application/Contractqueue/ContractqueueController.php @@ -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"); diff --git a/application/File/File.php b/application/File/File.php index b31d476f9..da8241163 100644 --- a/application/File/File.php +++ b/application/File/File.php @@ -9,7 +9,26 @@ class File extends mfBaseModel { } - + + protected function beforeSave() { + if($this->mimetype) { + return true; + } + $this->mimetype = $this->getMimetype(); + } + + public function getMimetype() { + if(!$this->store_filename) return false; + + $filepath = $this->getFullPath(); + if(!file_exists($filepath)) return false; + + $finfo = new finfo(FILEINFO_MIME_TYPE); + $mime = $finfo->file($filepath); + + return $mime; + } + public function delete() { if($this->id) { $id = $this->id; @@ -41,9 +60,9 @@ class File extends mfBaseModel { } public function getFullPath() { - if(!is_numeric($this->id) || $this->id < 1) { + /*if(!is_numeric($this->id) || $this->id < 1) { throw new Exception("File not found", 4040); - } + }*/ $filename = $this->store_filename; $path = MFUPLOAD_FILE_SAVE_PATH;