Merge branch 'fronkdev' into 'master'

Added warning when not uploading file in Contract Productchange

See merge request fronk/thetool!1166
This commit is contained in:
Frank Schubert
2025-04-03 17:36:36 +00:00
2 changed files with 149 additions and 12 deletions

View File

@@ -19,7 +19,7 @@
<div class="card-body">
<h4 class="text-center mb-3">Neuer Contract</h4>
<form method="post" action="<?=self::getUrl("Contract", "saveProductchange")?>">
<form method="post" action="<?=self::getUrl("Contract", "saveProductchange")?>" enctype="multipart/form-data" id="changeForm">
<input type="hidden" name="contract_id" value="<?=$contract->id?>"/>
<?php if($f): ?>
<input type="hidden" name="f" value="<?=$f?>" />
@@ -235,10 +235,29 @@
</table>
<?php endif; ?>
<!-- TODO: Fileupload -->
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="contract_file_upload">Vertragsdokument Upload *</label>
<div class="col-lg-10">
<div class="custom-file">
<input type="file" name="contract_file_upload[]" id="contract_file_upload" class="custom-file-input" multiple="multiple" />
<label class="custom-file-label" for="attachment"> Datei(en) auswählen</label>
</div>
<small class="text-danger">Vertragsdokument erforderlich</small>
</div>
</div>
<div class="form-group row" id="no-upload-confirm-box">
<label class="col-lg-2 col-form-label" for="contract_file_upload"></label>
<div class="col-lg-10">
<div class="alert alert-danger">
<p><strong>ACHTUNG</strong>: Der Upload eines Vertragsdokuments ist, bis auf wenige Ausnahmen, immer nötig. Wenn Sie sich sicher sind, dass der Upload nicht nötig ist, kreuzen Sie folgende Option an:</p>
<label><input type="checkbox" id="no-upload-confirm"> Ich, <?=($me->name)?>, versichere, dass für diesen Produktwechsel kein Vertragsdokument nötig ist.</label>
</div>
</div>
</div>
<div class="form-group row mt-3">
<label class="col-lg-2 col-form-label" for="note">Interne Notiz</label>
<div class="col-lg-10">
<textarea id="note" class="form-control" name="note"
@@ -261,7 +280,14 @@
</div>
</div>
<script type="text/javascript" src="<?=self::getResourcePath()?>plugins/bs-custom-file-input/bs-custom-file-input.min.js"></script>
<script>
bsCustomFileInput.init();
$(document).ready(() => {
$("#no-upload-confirm-box").hide();
});
$(".select2").select2({
allowClear: true,
placeholder: ""
@@ -381,4 +407,32 @@
linkActionChange(link_id);
});
}
function validateOrderForm() {
$("#contract_file_upload").removeClass("is-invalid");
$("#no-upload-confirm-box").hide();
let filelist = document.getElementById("contract_file_upload").files;
let confirm = $("#no-upload-confirm").is(":checked");
if(!filelist.length && !confirm) {
$("#no-upload-confirm-box").show();
$("#contract_file_upload").addClass("is-invalid");
return false;
}
return true;
}
$('#changeForm').submit(function(e) {
console.log("submit");
if(!validateOrderForm()) {
console.log("nope");
e.preventDefault();
return false;
}
return true;
});
</script>

View File

@@ -393,8 +393,10 @@ class ContractController extends mfBaseController {
$this->redirect("Dashboard");
}
var_dump($_FILES);exit;
$r = $this->request;
//var_dump($r->links);exit;
$f = $r->f;
if (!$f) {
@@ -477,7 +479,7 @@ class ContractController extends mfBaseController {
$require_term = false;
if (array_key_exists(TT_ATTRIB_TERMINATION_REQUIRED_NAME, $product->attributes) && $product->attributes[TT_ATTRIB_TERMINATION_REQUIRED_NAME]->value == 1) {
//var_dump($prod->attributes);
$require_term = true;
$termination = new Termination($contract_data['termination_id']);
@@ -493,8 +495,7 @@ class ContractController extends mfBaseController {
$contract_data['termination_id'] = null;
}
//var_dump($r->links);
// lookup credit contract and if it's missing in $r->links
// lookup credit contract and if it's missing in $r->links
if (!$this->me->is("Admin")) {
$credit_link = ContractLinkModel::includesContractId($contract->id, ["type" => "credit"]);
if ($credit_link) {
@@ -506,9 +507,6 @@ class ContractController extends mfBaseController {
}
}
//var_dump($r->links);exit;
$new_contract->update($contract_data);
$new_contract_id = $new_contract->save();
@@ -521,7 +519,92 @@ class ContractController extends mfBaseController {
}
}
// TODO: Contractconfig übernehmen
/*
* File upload
*/
if(array_key_exists("contract_file_upload", $_FILES)) {
$files = $_FILES['contract_file_upload'];
if(is_array($files) && count($files)) {
$file_errors = 0;
foreach($files['name'] as $i => $name) {
if(!$name) continue;
$upload_error = false;
try {
$upload = new mfUpload(['contract_file_upload', $i]);
$upload->setSavepath(MFUPLOAD_FILE_SAVE_PATH . "/" . TT_PREORDERNOTIFICATION_FILE_UPLOAD_SUBFOLDER);
} catch(Exception $e) {
$this->layout()->setFlash("Dateiupload fehlgeschlagen: " . $e->getMessage(), "warn");
$file_errors++;
continue;
}
if(!$upload->getSize()) {
$this->layout()->setFlash("Dateiupload fehlgeschlagen: Datei ist leer!", "warn");
$upload_error = true;
}
$mime = "";
if(!$upload_error) {
try {
$mime = $upload->getMimetype();
$upload->save();
} catch(Exception $e) {
$this->layout()->setFlash("Dateiupload fehlgeschlagen", "warn");
$upload_error = true;
}
}
if($upload_error) {
$file_errors++;
continue;
}
$file_data = [];
$file_data['name'] = $upload->getOriginalFilename();
$file_data['filename'] = $upload->getOriginalFilename();
$file_data['subfolder'] = TT_PREORDERNOTIFICATION_FILE_UPLOAD_SUBFOLDER;
$file_data['store_filename'] = $upload->getFilename();
$file_data['orig_filename'] = $upload->getOriginalFilename();
$file_data['mimetype'] = $mime;
$file = FileModel::create($file_data);
$file_id = $file->save();
if(!$file_id) {
$this->layout()->setFlash("Dateiupload fehlgeschlagen", "warn");
unlink($upload->getSavepath() . "/" . $upload->getFilename());
} else {
$contract_file = ContractFileModel::create([
"contract_id" => $new_contract->id,
"file_id" => $file_id,
"name" => "order_internet",
]);
if(!$contract_file->save()) {
$file->delete();
unlink($upload->getSavepath() . "/" . $upload->getFilename());
$this->layout()->setFlash("Dateiupload fehlgeschlagen", "warn");
} else {
$journal = ContractjournalModel::create([
"contract_id" => $new_contract->id,
"type" => "file",
"value" => $contract_file->id,
"text" => "Bestellung/Vertrag",
]);
if(!$journal->save()) {
$file->delete();
$contract_file->delete();
unlink($upload->getSavepath() . "/" . $upload->getFilename());
$this->layout()->setFlash("Dateiupload fehlgeschlagen", "warn");
}
}
}
}
}
}
// TODO: Contractconfig übernehmen
if ($contract_cancel_date) {