mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
update with ot files
This commit is contained in:
@ -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
|
||||
{
|
||||
@ -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)');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user