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

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

View File

@@ -240,8 +240,8 @@
</div>
</div>
<div class="card border-top-warning">
<div class="card-header">
<h5>Journaleinträge</h5>
@@ -267,7 +267,7 @@
<?php if(strlen($j->text) > 120): ?>
<td style="width: 100%" class="pointer" onclick="toggleTruncatedJournalText(<?=$j->id?>)">
<span id="truncated-<?=$j->id?>"><i class="fas fa-caret-right"></i> <?=self::strtrim(str_replace(["\n", "\r", "\t"]," ", $j->text), 120)?></span>
<span id="fulltext-<?=$j->id?>" class="hidden"><?=nl2br(htmlentities($j->text))?></span>
<span id="fulltext-<?=$j->id?>" class="hidden"><?=nl2br($j->text)?></span>
</td>
<?php else: ?>
<td style="width: 100%">
@@ -293,7 +293,7 @@
<?php elseif($j->value == "import"): ?>
<em>Vertrag importiert: <?=nl2br(htmlentities($j->text))?>
<?php elseif($j->value == "order"): ?>
<em>Vertrag aus Bestellung <a href="<?=self::getUrl("Order", "edit", ["id" => $contract->orderproduct->order_id])?>">#<?=$contract->orderproduct->order_id?></a> erstellt
<em>Vertrag aus Bestellung <a href="<?=self::getUrl("Order", "", ["id" => $contract->orderproduct->order_id])?>">#<?=$contract->orderproduct->order_id?></a> erstellt
<?php elseif($j->value == "productchange"): ?>
<em>Vertrag erstellt: <?=nl2br(htmlentities($j->text))?>
<?php endif; ?>
@@ -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="<?=self::getUrl("File", "download")?>?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");
}
}
</script>
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?>

View File

@@ -79,13 +79,12 @@
<div class="card">
<div class="card-body mb-3">
<form method="post" action="<?=self::getUrl("Contractqueue", "commit")?>">
<div class="row">
<div class="col-12">
<div class="float-left">
<h4 class="header-title">Fertiggestellte Bestellungen</h4>
<button type="submit" class="btn btn-primary"><i class="fas fa-fw fa-check"></i> Markierte Elemente als Contract übernehmen</button>
</div>
<div class="float-right">
<a class="btn btn-outline-primary mb-2" href="<?=self::getUrl("Contractqueue", "importFinishedOrders")?>"><i class="fas fa-fw fa-file-import"></i> Fertiggestellte Bestellungen importieren</a>
@@ -243,7 +242,6 @@
<h5>Produkte</h5>
<table class="table table-striped table-hover" id="order-products-<?=$order_id?>">
<tr>
<th style="width:56px;"><input type="checkbox" class="form-control pointer checkbox-toggle" onclick="toggleOrderApproval(this, <?=$order_id?>, 'order')" /></th>
<th>Produkt</th>
<th>Matchcode</th>
<th>Preis</th>
@@ -257,7 +255,6 @@
<?php foreach($contracts as $contract): ?>
<tr id="contract-<?=$contract->id?>">
<td><input type="checkbox" class="form-control pointer" value="<?=$contract->id?>" id="approve-order-<?=$order_id?>-contract-<?=$contract->id?>" onclick="toggleApproval(<?=$order_id?>, 'order')" <?=($contract->approved) ? "checked='checked'" : ""?> /></td>
<td class="text-wrap product">
<div class="text">
<!--i class="fas fa-fw fa-pencil pointer text-primary" onclick="toggleEdit('contract', <?=$contract->id?>, 'product')"></i--> <span class="value"><?=$contract->product_name?></span>
@@ -371,7 +368,6 @@
<h5>Gutschriften / Provisionen</h5>
<table class="table table-striped table-hover" id="credit-products-<?=$order_id?>">
<tr>
<th style="width:56px;"><input type="checkbox" class="form-control pointer checkbox-toggle" onclick="toggleOrderApproval(this, <?=$order_id?>, 'credit')" /></th>
<th>Bezieher</th>
<th>Produkt</th>
<th>Matchcode</th>
@@ -386,7 +382,6 @@
<?php foreach($contracts as $contract): ?>
<?php $credit = $contract->getCredit(); if(!$credit) continue; ?>
<tr id="credit-<?=$contract->id?>">
<td><input type="checkbox" class="form-control pointer" value="<?=$contract->id?>" id="approve-credit-<?=$order_id?>-contract-<?=$contract->id?>" onclick="toggleApproval(<?=$order_id?>, 'credit')" <?=($contract->approved_credit) ? "checked='checked'" : ""?> /></td>
<td class="crediting_partner_name text value"><?=($credit["partner"]) ? $credit["partner"]->getCompanyOrName() : ""?></td>
<td class="text-wrap product text">
<span class="value"><?=$contract->product_name?></span>
@@ -427,7 +422,10 @@
<?php endforeach; ?>
</table>
<form method="post" action="<?=self::getUrl("Contractqueue", "commitOrder")?>">
<input type="hidden" name="order_id" value="<?=$contract->order_id?>" />
<button type="submit" class="btn btn-primary"><i class="fas fa-fw fa-check"></i> Produkte dieser Bestellung als Contract übernehmen</button>
</form>
</div>
</div>
</div>
@@ -443,8 +441,6 @@
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination-summary.php"); ?>
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination.php"); ?>
<button type="submit" class="btn btn-primary"><i class="fas fa-fw fa-check"></i> Markierte Elemente als Contract übernehmen</button>
</form>
</div>
</div>

View File

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

View File

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

View File

@@ -1,5 +1,49 @@
<?php
class ContractFile extends mfBaseModel {
public function isImage() {
if(!$this->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;
}
}

View File

@@ -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]);
}

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");

View File

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