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

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