diff --git a/ci4/app/Entities/Produccion/OrdenTrabajoEntity.php b/ci4/app/Entities/Produccion/OrdenTrabajoEntity.php index 329a3e3f..81df1687 100644 --- a/ci4/app/Entities/Produccion/OrdenTrabajoEntity.php +++ b/ci4/app/Entities/Produccion/OrdenTrabajoEntity.php @@ -6,6 +6,7 @@ use App\Controllers\Produccion\Ordentrabajo; use App\Database\Migrations\OrdenTrabajoDatesTable; use App\Entities\Pedidos\PedidoEntity; 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; @@ -109,4 +110,9 @@ 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() ?? []; + } } 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/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 @@ +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 { @@ -894,7 +899,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 +932,37 @@ 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)'); + } + } } diff --git a/ci4/app/Views/themes/vuexy/components/dropzone.php b/ci4/app/Views/themes/vuexy/components/dropzone.php index 886d4d24..8da70305 100644 --- a/ci4/app/Views/themes/vuexy/components/dropzone.php +++ b/ci4/app/Views/themes/vuexy/components/dropzone.php @@ -22,11 +22,11 @@