Merge branch 'fronkdev' into 'master'

Order/Form: documents can be uploaded even if order is closed already

See merge request fronk/thetool!1831
This commit is contained in:
Frank Schubert
2025-10-09 13:35:27 +00:00
4 changed files with 127 additions and 26 deletions
+10 -18
View File
@@ -40,26 +40,18 @@ class File extends mfBaseModel {
public function delete() {
if($this->id) {
$id = $this->id;
$id = $this->id;
// delete file in store
if($this->subfolder) {
$path = MFUPLOAD_FILE_SAVE_PATH."/".$this->subfolder."/".$this->store_filename;
} else {
$path = MFUPLOAD_FILE_SAVE_PATH."/".$this->store_filename;
}
if(!unlink($path)) {
$this->log->warn(__CLASS__."::delete(): Error unlinking file ($path)");
}
// delete physical file
if(!unlink($this->getFullPath())) {
$this->log->warn(__CLASS__."::delete(): Error unlinking file ({$this->getFullPath()})");
}
$where = "id=$id";
if($this->fieldprefix && !strstr($field,"_")) {
$where = $this->fieldprefix."_id=$id";
}
if($this->db->delete($this->table,$where)) {
if(method_exists($this, "afterDelete")) {
$this->afterDelete();
}
$where = "id=$id";
if($this->db->delete($this->table,$where)) {
if(method_exists($this, "afterDelete")) {
$this->afterDelete();
}
$this->data = new stdClass();
$this->id = "";
return true;
+73 -2
View File
@@ -239,7 +239,7 @@ class OrderController extends mfBaseController {
&& $lop->product->attributes['termination_required']
&& $lop->termination_id
) {
$has_term = true;
$has_term = true; // is already in orders with terminations
}
}
if(!$has_bras && !$has_voice && !$has_term) {
@@ -1286,7 +1286,7 @@ class OrderController extends mfBaseController {
}
}
protected function saveVorortterminAction() {
if(!$this->me->is(["Admin","salespartner"])) {
$this->layout()->setFlash("Keine Berechtigung", "error");
@@ -1478,5 +1478,76 @@ class OrderController extends mfBaseController {
$this->redirect("Order");
}
protected function apiAction() {
$do = $this->request->do;
$data = [];
switch($do) {
case "uploadDocument":
$return = $this->uploadDocumentApi();
break;
default:
$return = false;
}
if(!is_array($return) || !count($return)) {
$data = ["status" => "error"];
$this->returnJson($data);
}
if(mfResponse::isResponse($return)) {
$this->returnJson($return);
} else {
$data['status'] = "OK";
$data['result'] = $return;
$this->returnJson($data);
}
}
private function uploadDocumentApi() {
$order_id = $this->request->id;
$filename = $this->request->file_name;
$orig_filename = $this->request->orig_filename;
$description = $this->request->file_description;
if(!$order_id || !is_numeric($order_id) || $order_id < 1) {
return false;
}
$order = new Order($order_id);
if(!$order->id) {
return false;
}
if(!$filename) {
$this->log->error(__METHOD__.": No filename");
return false;
}
$file = mfUpload::handleFormUpload("file_contents");
if(!$file) {
$this->log->error(__METHOD__.": Error uploading file");
return false;
} else {
$of = [];
$of['order_id'] = $order_id;
$of['file_id'] = $file->id;
$of['name'] = $filename;
$of['description'] = $description;
$orderfile = OrderFileModel::create($of);
if(!$orderfile->save()) {
$file->delete();
$this->log->error(__METHOD__.": Error saving OrderFile object: ".print_r($orderfile, true));
} else {
// send email based on file type
$order->sendFileuploadEmail($orderfile);
}
}
return ["status" => "OK", "message" => "File uploaded successfully"];
}
}