diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 95f60c04..92c10179 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -1001,6 +1001,11 @@ $routes->group('produccion', ['namespace' => 'App\Controllers\Produccion'], func $routes->post("upload/portada", 'Ordentrabajo::upload_orden_trabajo_portada'); $routes->delete("portada/(:num)", 'Ordentrabajo::delete_orden_trabajo_portada/$1'); + /**====================== + * FILES + *========================**/ + $routes->post('get_files', 'Ordentrabajo::get_files'); + $routes->post('upload_files', 'Ordentrabajo::upload_files'); /**====================== * PDF *========================**/ diff --git a/ci4/app/Controllers/Produccion/Ordentrabajo.php b/ci4/app/Controllers/Produccion/Ordentrabajo.php index 0fef800c..3238788b 100755 --- a/ci4/app/Controllers/Produccion/Ordentrabajo.php +++ b/ci4/app/Controllers/Produccion/Ordentrabajo.php @@ -68,8 +68,13 @@ class Ordentrabajo extends BaseController public function get_orden_trabajo_summary($orden_trabajo_id) { - $summary = $this->produccionService->init($orden_trabajo_id)->getSummary(); - return $this->response->setJSON($summary); + try { + //code... + $summary = $this->produccionService->init($orden_trabajo_id)->getSummary(); + return $this->response->setJSON($summary); + } catch (\Throwable $th) { + return $this->response->setStatusCode(500)->setJSON(["message" => $th->getMessage(), "error" => $th]); + } } public function add() {} @@ -168,7 +173,7 @@ class Ordentrabajo extends BaseController ->add("logo", fn($q) => site_url($logo->get_logo_path($q->presupuesto_linea_tipo))) ->edit( "fecha_encuadernado_at", - fn($q) =>$q->fecha_encuadernado_at ? Time::createFromFormat("Y-m-d", $q->fecha_encuadernado_at)->format("d/m/Y") : "" + fn($q) => $q->fecha_encuadernado_at ? Time::createFromFormat("Y-m-d", $q->fecha_encuadernado_at)->format("d/m/Y") : "" ) ->add("action", fn($q) => $q->id) ->toJson(true); @@ -193,8 +198,8 @@ class Ordentrabajo extends BaseController $q = $this->produccionService->papelGramajeDatatableQuery(); return DataTable::of($q) - ->edit("tiempoReal", fn($q) => $q->tiempoReal * 3600) - ->add("action", fn($q) => ["title" => lang('Produccion.datatable.filter_by_task'), 'data' => $q]) + ->edit("tiempoReal", fn($q) => $q->tiempoReal) + ->add("action", fn($q) => ["title" => lang('Produccion.datatable.filter_by_paper'), 'data' => $q]) ->toJson(true); } public function papel_pliego_datatable() @@ -202,8 +207,8 @@ class Ordentrabajo extends BaseController $q = $this->produccionService->papelPliegoDatatableQuery(); return DataTable::of($q) - ->edit("tiempoReal", fn($q) => $q->tiempoReal * 3600) - ->add("action", fn($q) => ["title" => lang('Produccion.datatable.filter_by_task'), 'data' => $q]) + ->edit("tiempoReal", fn($q) => $q->tiempoReal) + ->add("action", fn($q) => ["title" => lang('Produccion.datatable.filter_by_paper'), 'data' => $q]) ->toJson(true); } public function reset_tareas(int $orden_trabajo_id) @@ -260,7 +265,7 @@ class Ordentrabajo extends BaseController $otEntity = $this->otModel->find($orden_trabajo_id); $pathActualFile = $otEntity->portada_path; $fullPath = WRITEPATH . 'uploads/' . $pathActualFile; - if(file_exists($fullPath)){ + if (file_exists($fullPath)) { delete_files($fullPath); } $r = $this->otModel->update($otEntity->id, ["portada_path" => null]); @@ -289,7 +294,7 @@ class Ordentrabajo extends BaseController return DataTable::of($q) ->edit("fecha_entrega_real_at", fn($q) => $q->fecha_entrega_real_at ? Time::createFromFormat("Y-m-d", $q->fecha_entrega_real_at)->format("d/m/Y") : "") ->add("metros_check", fn($q) => $q->otId) - ->add("corte", fn($q) => ["otId" => $q->otId,"tipo_corte" => $this->produccionService->ordenTrabajoTareaCorte($q->otId)]) + ->add("corte", fn($q) => ["otId" => $q->otId, "tipo_corte" => $this->produccionService->ordenTrabajoTareaCorte($q->otId)]) ->add("action", fn($q) => $q) ->toJson(true); } @@ -297,27 +302,32 @@ class Ordentrabajo extends BaseController { $q = $this->produccionService->planningPlanaQueryDatatable(); return DataTable::of($q) + ->edit("tiempo_real_sum", fn($q) => $q->tiempo_real_sum) ->edit("fecha_entrega_real_at", fn($q) => $q->fecha_entrega_real_at ? Time::createFromFormat("Y-m-d", $q->fecha_entrega_real_at)->format("d/m/Y") : "") ->add("pliegos_check", fn($q) => $q->otId) ->add("action", fn($q) => $q) ->toJson(true); } - public function select_maquina_planning_rot(){ + public function select_maquina_planning_rot() + { $q = $this->request->getGet('q'); $result = $this->produccionService->querySelectMaquinaPlanningRotativa($q); return $this->response->setJSON($result); } - public function select_papel_planning_rot(){ + public function select_papel_planning_rot() + { $q = $this->request->getGet('q'); $result = $this->produccionService->querySelectPapelPlanningRot($q); return $this->response->setJSON($result); } - public function select_maquina_planning_plana(){ + public function select_maquina_planning_plana() + { $q = $this->request->getGet('q'); $result = $this->produccionService->querySelectMaquinaPlanningPlana($q); return $this->response->setJSON($result); } - public function select_papel_planning_plana(){ + public function select_papel_planning_plana() + { $q = $this->request->getGet('q'); $result = $this->produccionService->querySelectPapelPlanningPlana($q); return $this->response->setJSON($result); @@ -325,7 +335,52 @@ class Ordentrabajo extends BaseController public function tarea_toggle_corte($orden_trabajo_id) { $status = $this->produccionService->tareaUpdateMaquinaCorte($orden_trabajo_id); - return $this->response->setJSON(["message" => lang("App.global_alert_save_success"), "status" => $status ]); + return $this->response->setJSON(["message" => lang("App.global_alert_save_success"), "status" => $status]); + } + public function get_files() + { + $bodyData = $this->request->getPost(); + $files = $this->produccionService->init($bodyData["orden_trabajo_id"])->getOtFiles(); + $response = []; + foreach ($files as $key => $file) { + $file_ci4 = new File($file->file_path); + $response[] = [ + "name" => $file->name, + "size" => $file_ci4->getSize(), + "hash" => $file->hash() + ]; + } + return json_encode($response); + } + public function upload_files() + { + try { + //code... + $otFiles = []; + $bodyData = $this->request->getPost(); + $files = $this->request->getFileMultiple('file'); + $ps = $this->produccionService->init($bodyData["orden_trabajo_id"]); + $existingFiles = json_decode($bodyData["oldFiles"]); + $ps->deleteOtFiles($existingFiles); + if($files){ + $response = $ps->storeOtFiles($files); + }else{ + $response = null; + } + return $this->response->setJSON([ + "message" => lang("App.global_alert_save_success"), + "data" => $response, + "status" => true + ]); + } catch (\Throwable $th) { + return $this->response->setJSON( + [ + "message" => lang("App.global_alert_save_error"), + "data" => $th, + "error" => $th->getMessage(), + "status" => false + ] + ); + } } - } diff --git a/ci4/app/Controllers/Sistema/Intranet.php b/ci4/app/Controllers/Sistema/Intranet.php index 73aa48f2..e9da0b31 100644 --- a/ci4/app/Controllers/Sistema/Intranet.php +++ b/ci4/app/Controllers/Sistema/Intranet.php @@ -56,5 +56,27 @@ class Intranet extends Controller } } + function orden_trabajo($ot_id,$resource_name) + { + helper('file'); + $resource_path = WRITEPATH . 'uploads/orden_trabajo/'.$ot_id. '/' . $resource_name; + if (file_exists($resource_path)) { + // Get the mime type of the file + $mime_type = mime_content_type($resource_path); + + // Get an instance of the Response class + $response = service('response'); + + // Set the content type + $response->setContentType($mime_type); + + // Set the output + $response->setBody(file_get_contents($resource_path)); + + // Send the response to the browser + $response->send(); + } + + } } \ No newline at end of file diff --git a/ci4/app/Database/Migrations/2025-04-03-233800_OrdenTrabajoFilesTable.php b/ci4/app/Database/Migrations/2025-04-03-233800_OrdenTrabajoFilesTable.php new file mode 100644 index 00000000..788b3518 --- /dev/null +++ b/ci4/app/Database/Migrations/2025-04-03-233800_OrdenTrabajoFilesTable.php @@ -0,0 +1,63 @@ + [ + "type" => "INT", + "unsigned" => true, + "auto_increment" => true + ], + "orden_trabajo_id" => [ + "type" => "INT", + "unsigned" => true, + ], + "name" => [ + "type" => "TEXT", + ], + "upload_by" => [ + "type" => "INT", + "unsigned" => true, + "constraint" => 10, + ], + "file_path" => [ + "type" => "TEXT", + ] + ]; + + public function up() + { + $this->forge->addField($this->COLUMNS); + $currenttime = new RawSql("CURRENT_TIMESTAMP"); + $this->forge->addField([ + "created_at" => [ + "type" => "TIMESTAMP", + "default" => $currenttime, + + ], + "updated_at" => [ + "type" => "TIMESTAMP", + "null" => true, + + ], + "deleted_at" => [ + "type" => "TIMESTAMP", + "null" => true, + ], + ]); + $this->forge->addPrimaryKey("id"); + $this->forge->addForeignKey("upload_by", "users", "id","CASCADE","CASCADE"); + $this->forge->addForeignKey("orden_trabajo_id", "ordenes_trabajo", "id","CASCADE","CASCADE"); + $this->forge->createTable("orden_trabajo_files", true); + } + + public function down() + { + $this->forge->dropTable("orden_trabajo_files"); + } +} diff --git a/ci4/app/Database/Migrations/2025-04-04-212900_AddColumnIsPedidoEsperaOrdenTrabajoTable.php b/ci4/app/Database/Migrations/2025-04-04-212900_AddColumnIsPedidoEsperaOrdenTrabajoTable.php new file mode 100644 index 00000000..324f3d41 --- /dev/null +++ b/ci4/app/Database/Migrations/2025-04-04-212900_AddColumnIsPedidoEsperaOrdenTrabajoTable.php @@ -0,0 +1,34 @@ + [ + 'type' => 'BOOLEAN', + 'default' => false, + 'comment' => 'Marca que el pedido está en espera.' + ], + 'pedido_espera_by' => [ + 'type' => 'int', + 'unsigned' => true, + 'constraint' => 11, + 'null' => true, + 'comment' => 'Foreign a usuario que ha marcado is_pedido_espera' + + ] + ]; + $this->forge->addColumn('ordenes_trabajo',$field); + } + + public function down() + { + $this->forge->dropColumn('ordenes_trabajo',['is_pedido_espera','pedido_espera_by']); + + } +} diff --git a/ci4/app/Entities/Presupuestos/PresupuestoEntity.php b/ci4/app/Entities/Presupuestos/PresupuestoEntity.php index 2b28d821..9fc90892 100755 --- a/ci4/app/Entities/Presupuestos/PresupuestoEntity.php +++ b/ci4/app/Entities/Presupuestos/PresupuestoEntity.php @@ -8,6 +8,7 @@ use App\Models\Clientes\ClienteModel; use App\Models\Configuracion\PapelFormatoModel; use App\Models\Presupuestos\PresupuestoAcabadosModel; use App\Models\Presupuestos\PresupuestoEncuadernacionesModel; +use App\Models\Presupuestos\PresupuestoFicheroModel; use App\Models\Presupuestos\PresupuestoLineaModel; use App\Models\Presupuestos\PresupuestoManipuladosModel; use App\Models\Presupuestos\PresupuestoModel; @@ -293,4 +294,10 @@ class PresupuestoEntity extends \CodeIgniter\Entity\Entity $m = model(PapelFormatoModel::class); return $m->find($this->attributes["papel_formato_id"]); } + public function files(): array + { + $m = model(PresupuestoFicheroModel::class); + $files = $m->where('presupuesto_id',$this->attributes['id'])->findAll(); + return $files ?? []; + } } diff --git a/ci4/app/Entities/Produccion/OrdenTrabajoEntity.php b/ci4/app/Entities/Produccion/OrdenTrabajoEntity.php index 329a3e3f..2ad1b2fc 100644 --- a/ci4/app/Entities/Produccion/OrdenTrabajoEntity.php +++ b/ci4/app/Entities/Produccion/OrdenTrabajoEntity.php @@ -5,10 +5,14 @@ namespace App\Entities\Produccion; use App\Controllers\Produccion\Ordentrabajo; use App\Database\Migrations\OrdenTrabajoDatesTable; use App\Entities\Pedidos\PedidoEntity; +use App\Entities\Usuarios\UserEntity; +use App\Entities\Usuarios\UsersEntity; use App\Models\OrdenTrabajo\OrdenTrabajoDate; +use App\Models\OrdenTrabajo\OrdenTrabajoFileModel; use App\Models\OrdenTrabajo\OrdenTrabajoTarea; use App\Models\OrdenTrabajo\OrdenTrabajoUser; use App\Models\Pedidos\PedidoModel; +use App\Models\UserModel; use CodeIgniter\Entity\Entity; use Picqer\Barcode\Renderers\PngRenderer; use Picqer\Barcode\Types\TypeCode128; @@ -34,6 +38,9 @@ class OrdenTrabajoEntity extends Entity "revisar_codigo_barras" => false, "realizar_imposicion" => false, "enviar_impresion" => false, + "portada_path" => null, + "is_pedido_espera" => null, + "pedido_espera_by" => null, ]; protected $casts = [ "pedido_id" => "integer", @@ -54,6 +61,8 @@ class OrdenTrabajoEntity extends Entity "revisar_codigo_barras" => "bool", "realizar_imposicion" => "bool", "enviar_impresion" => "bool", + "portada_path" => "string", + "is_pedido_espera" => "bool", ]; @@ -109,4 +118,22 @@ class OrdenTrabajoEntity extends Entity $barcodeData = $barcode->getBarcode($this->pedido()->presupuesto()->id); return base64_encode($renderer->render($barcodeData,200, 50)); } + public function files() : array + { + $m = model(OrdenTrabajoFileModel::class); + return $m->where('orden_trabajo_id',$this->attributes['id'])->findAll() ?? []; + } + public function pedidoEsperaBy() : ?UsersEntity + { + $m = model(UserModel::class); + if($this->attributes['pedido_espera_by']){ + return $m->findById($this->attributes['pedido_espera_by']); + }else{ + return null; + } + } + public function getPedidoEsperaBy(): ?UsersEntity + { + return $this->pedidoEsperaBy(); + } } diff --git a/ci4/app/Entities/Produccion/OrdenTrabajoFileEntity.php b/ci4/app/Entities/Produccion/OrdenTrabajoFileEntity.php new file mode 100644 index 00000000..87d9de3a --- /dev/null +++ b/ci4/app/Entities/Produccion/OrdenTrabajoFileEntity.php @@ -0,0 +1,32 @@ + null, + "name" => null, + "upload_by" => null, + "file_path" => null + ]; + protected $casts = [ + "orden_trabajo_id" => "integer", + "name" => "string", + "upload_by" => "integer", + "file_path" => "string" + ]; + + public function orden_trabajo(): ?OrdenTrabajoEntity + { + $m = model(OrdenTrabajoModel::class); + return $m->find($this->attributes["orden_trabajo_id"]); + } + public function hash(): string + { + return array_reverse(explode('/', $this->attributes["file_path"]))[0]; + } +} diff --git a/ci4/app/Language/es/Produccion.php b/ci4/app/Language/es/Produccion.php index da69474a..98e81d76 100644 --- a/ci4/app/Language/es/Produccion.php +++ b/ci4/app/Language/es/Produccion.php @@ -24,6 +24,7 @@ return [ "progreso" => "Progreso", "logo" => "Logo impresion", "filter_by_task" => "Filtrar por tarea", + "filter_by_paper" => "Filtrar por papel", "metros" => "Metros", "corte" => "Corte", "pliegos" => "Pliegos", @@ -76,6 +77,8 @@ return [ "planning_rotativa" => "Planificación rotativa", "planning_plana" => "Planificación plana", "solapa" => "Solapa", - "papel_gramajes" => "Papel y gramajes" + "papel_gramajes" => "Papel y gramajes", + "estado" => "Estado", + "pedido_espera" => "Pedido en espera" ]; \ No newline at end of file diff --git a/ci4/app/Models/OrdenTrabajo/OrdenTrabajoFileModel.php b/ci4/app/Models/OrdenTrabajo/OrdenTrabajoFileModel.php new file mode 100644 index 00000000..5676317b --- /dev/null +++ b/ci4/app/Models/OrdenTrabajo/OrdenTrabajoFileModel.php @@ -0,0 +1,56 @@ + "integer", - "user_created_id" => "?integer", - "user_updated_id" => "?integer", - "fecha_entrega_warning" => "bool", - "fecha_entrega_warning_revised" => "bool", - "total_tirada" => "?integer", - "total_precio" => "?integer", - "tipo_entrada" => "?integer", - "progreso" => "float", - "revisar_formato" => "bool", - "revisar_lomo" => "bool", - "revisar_solapa" => "bool", - "revisar_isbn" => "bool", - "revisar_codigo_barras" => "bool", - "realizar_imposicion" => "bool", - "enviar_impresion" => "bool" - ]; + protected array $casts = []; protected array $castHandlers = []; // Dates diff --git a/ci4/app/Services/ProductionService.php b/ci4/app/Services/ProductionService.php index 15b8b2a8..f758c344 100644 --- a/ci4/app/Services/ProductionService.php +++ b/ci4/app/Services/ProductionService.php @@ -15,15 +15,18 @@ use App\Models\OrdenTrabajo\OrdenTrabajoUser; use App\Models\Usuarios\UserModel; use CodeIgniter\Config\BaseService; use App\Entities\Configuracion\Maquina as MaquinaEntity; +use App\Entities\Produccion\OrdenTrabajoFileEntity; use App\Entities\Produccion\OrdenTrabajoTareaEntity; use App\Models\Configuracion\ConfigVariableModel; use App\Models\Configuracion\MaquinaModel; +use App\Models\OrdenTrabajo\OrdenTrabajoFileModel; use CodeIgniter\Database\BaseBuilder; use CodeIgniter\Database\BaseResult; use CodeIgniter\Database\Exceptions\DatabaseException; +use CodeIgniter\Files\File; +use CodeIgniter\HTTP\Files\UploadedFile; use CodeIgniter\I18n\Time; -use CodeIgniter\Model; -use Dompdf\Dompdf; +use Exception; /** * Clase con las funcionalidades necesarias trabajar con las ordenes de trabajo. @@ -39,6 +42,7 @@ class ProductionService extends BaseService protected OrdenTrabajoDate $otDate; protected OrdenTrabajoUser $otUser; protected OrdenTrabajoEntity $ot; + protected OrdenTrabajoFileModel $otFileModel; protected UserModel $userModel; protected string $defaultMaquinaCorteName = 'HT-1000'; protected MaquinaEntity $defaultMaquinaCorte; @@ -80,6 +84,7 @@ class ProductionService extends BaseService $this->otTarea = model(OrdenTrabajoTarea::class); $this->otUser = model(OrdenTrabajoUser::class); $this->userModel = model(UserModel::class); + $this->otFileModel = model(OrdenTrabajoFileModel::class); } public function init(int $orden_trabajo_id): self { @@ -138,6 +143,7 @@ class ProductionService extends BaseService ]; $id = $this->otModel->insert($data); $this->init($id); + $this->updatePedidoEspera(); $this->storeOrdenTrabajoUsers(); $this->storeOrdenTrabajoDates(); $this->storeAllTareas(); @@ -329,6 +335,8 @@ class ProductionService extends BaseService $ot_tareas["nombre"] = $p_linea->tarifa()->nombre; $ot_tareas["orden"] = $linea_maquina->orden_planning ?? 110; $ot_tareas["maquina_id"] = $linea_maquina->id; + $ot_tareas["tiempo_estimado"] = $p_linea->tiempo; + $ot_tareas["tiempo_real"] = $p_linea->tiempo; $ot_tareas["imposicion_id"] = null; $this->otTarea->insert($ot_tareas); $ot_tareas = []; @@ -336,6 +344,8 @@ class ProductionService extends BaseService $ot_tareas["orden_trabajo_id"] = $this->ot->id; $ot_tareas["presupuesto_encuadernado_id"] = $p_linea->id; $ot_tareas["nombre"] = $p_linea->tarifa()->nombre ?? ""; + $ot_tareas["tiempo_estimado"] = $p_linea->tiempo; + $ot_tareas["tiempo_real"] = $p_linea->tiempo; $ot_tareas["orden"] = 110; $this->otTarea->insert($ot_tareas); } @@ -443,13 +453,8 @@ class ProductionService extends BaseService "lg_papel_formato.ancho as papel_ancho", "lg_papel_formato.alto as papel_alto", "presupuesto_linea.rotativa_metros_total as metros", - // "JSON_EXTRACT(presupuesto_linea.formas,'$.maquina_ancho') as maquina_ancho", - // "JSON_EXTRACT(presupuesto_linea.formas,'$.maquina_alto') as maquina_alto", "lg_papel_impresion.nombre as papel_impresion", "presupuesto_linea.gramaje as papel_gramaje", - - - ]) ->join("orden_trabajo_tareas", "orden_trabajo_tareas.orden_trabajo_id = ordenes_trabajo.id", "left") ->join("orden_trabajo_dates", "orden_trabajo_dates.orden_trabajo_id = ordenes_trabajo.id", "left") @@ -460,11 +465,12 @@ class ProductionService extends BaseService ->join("lg_papel_impresion", "lg_papel_impresion.id = presupuesto_linea.papel_impresion_id", "left") ->join("lg_maquinas as lgmp", "lgmp.id = presupuesto_linea.maquina_id", "left") ->join("lg_imposiciones", "lg_imposiciones.id = orden_trabajo_tareas.imposicion_id", "left") - // ->where("orden_trabajo_tareas.orden_trabajo_id", $this->ot->id) ->whereIn("presupuesto_linea.tipo", $this->TIPOS_ROTATIVA) ->where('lg_maquinas.is_rotativa', true) ->where("orden_trabajo_tareas.deleted_at", null) - ->orderBy("orden_trabajo_tareas.orden", "ASC"); + ->orderBy("orden_trabajo_tareas.orden", "ASC") + ->groupBy('ordenes_trabajo.id'); + return $q; } /** @@ -488,9 +494,7 @@ class ProductionService extends BaseService // "JSON_EXTRACT(presupuesto_linea.formas,'$.maquina_alto') as maquina_alto", "lg_papel_impresion.nombre as papel_impresion", "presupuesto_linea.gramaje as papel_gramaje", - - - + "SUM(orden_trabajo_tareas.tiempo_real) as tiempo_real_sum" ]) ->join("orden_trabajo_tareas", "orden_trabajo_tareas.orden_trabajo_id = ordenes_trabajo.id", "left") ->join("orden_trabajo_dates", "orden_trabajo_dates.orden_trabajo_id = ordenes_trabajo.id", "left") @@ -505,7 +509,9 @@ class ProductionService extends BaseService ->whereIn("presupuesto_linea.tipo", $this->TIPOS_PLANA) ->where('lg_maquinas.is_rotativa', false) ->where("orden_trabajo_tareas.deleted_at", null) - ->orderBy("orden_trabajo_tareas.orden", "ASC"); + ->orderBy("orden_trabajo_tareas.orden", "ASC") + ->groupBy('ordenes_trabajo.id'); + return $q; } /** @@ -749,6 +755,9 @@ class ProductionService extends BaseService public function updateOrdenTrabajo($data): bool { + if(isset($data["is_pedido_espera"])){ + $data["pedido_espera_by"] = auth()->user()->id; + } return $this->otModel->update($this->ot->id, $data); } /**======================================================================== @@ -894,7 +903,8 @@ class ProductionService extends BaseService ->join("lg_papel_impresion", "presupuesto_linea.papel_impresion_id = lg_papel_impresion.id", "left") ->join("lg_papel_formato", "lg_papel_formato.id = presupuestos.papel_formato_id", "left") ->where("orden_trabajo_tareas.deleted_at", null) - ->where("orden_trabajo_tareas.presupuesto_linea_id IS NOT NULL", NULL, FALSE) + ->where("orden_trabajo_tareas.presupuesto_linea_ + id IS NOT NULL", NULL, FALSE) ->whereIn("presupuesto_linea.tipo", $this->TIPOS_PLANA) ->groupBy('lg_papel_impresion.id'); if ($q) { @@ -926,4 +936,66 @@ class ProductionService extends BaseService { return $this->otTarea->where('orden_trabajo_id', $ot_id)->where('is_corte', true)?->first()->tipo_corte ?? null; } + + public function getOtFiles(): array + { + $otFiles = $this->ot->files(); + return $otFiles; + } + public function storeOtFiles(array $uploadFiles): array + { + $otFileEntities = []; + foreach ($uploadFiles as $uploadFile) { + $otFileEntities[] = $this->storeOtFile($uploadFile); + } + return $otFileEntities; + } + protected function storeOtFile(UploadedFile $file): ?OrdenTrabajoFileEntity + { + $result = null; + if ($this->ot) { + if ($file->isValid() && !$file->hasMoved()) { + $fullpath = $file->store('orden_trabajo/' . $this->ot->id); + $ot_file_id = $this->otFileModel->insert([ + "orden_trabajo_id" => $this->ot->id, + "name" => $file->getClientName(), + "file_path" => WRITEPATH . 'uploads/' . $fullpath, + "upload_by" => auth()->user()->id + ]); + $result = $this->otFileModel->find($ot_file_id); + } + return $result; + } else { + throw new Exception('No se ha especificado una orden de trabajo. Usa $this->producctionService->init($orden_trabajo_id)'); + } + } + public function deleteOtFiles(?array $existingFiles): bool + { + helper('filesystem'); + if ($this->ot) { + $otFiles = $this->ot->files(); + + foreach ($otFiles as $key => $file) { + $file_path = $file->file_path; + if ($existingFiles) { + if (!in_array($file->name, $existingFiles)) { + $this->otFileModel->delete($file->id); + unlink($file_path); + } + } + } + return true; + } else { + throw new Exception('No se ha especificado una orden de trabajo. Usa $this->producctionService->init($orden_trabajo_id)'); + } + } + protected function updatePedidoEspera(): bool + { + $status = false; + $presupuestoFiles = $this->presupuesto->files(); + if (count($presupuestoFiles) == 0) { + $status = $this->otModel->update($this->ot->id, ['pedido_espera' => true]); + } + return $status; + } } diff --git a/ci4/app/Views/themes/vuexy/components/dropzone.php b/ci4/app/Views/themes/vuexy/components/dropzone.php index 886d4d24..ad2893df 100644 --- a/ci4/app/Views/themes/vuexy/components/dropzone.php +++ b/ci4/app/Views/themes/vuexy/components/dropzone.php @@ -4,7 +4,8 @@