mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
orden trabajo files methods
This commit is contained in:
@ -143,6 +143,7 @@ class ProductionService extends BaseService
|
|||||||
];
|
];
|
||||||
$id = $this->otModel->insert($data);
|
$id = $this->otModel->insert($data);
|
||||||
$this->init($id);
|
$this->init($id);
|
||||||
|
$this->updatePedidoEspera();
|
||||||
$this->storeOrdenTrabajoUsers();
|
$this->storeOrdenTrabajoUsers();
|
||||||
$this->storeOrdenTrabajoDates();
|
$this->storeOrdenTrabajoDates();
|
||||||
$this->storeAllTareas();
|
$this->storeAllTareas();
|
||||||
@ -933,7 +934,7 @@ class ProductionService extends BaseService
|
|||||||
return $this->otTarea->where('orden_trabajo_id', $ot_id)->where('is_corte', true)?->first()->tipo_corte ?? null;
|
return $this->otTarea->where('orden_trabajo_id', $ot_id)->where('is_corte', true)?->first()->tipo_corte ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOtFiles() : array
|
public function getOtFiles(): array
|
||||||
{
|
{
|
||||||
$otFiles = $this->ot->files();
|
$otFiles = $this->ot->files();
|
||||||
return $otFiles;
|
return $otFiles;
|
||||||
@ -946,23 +947,52 @@ class ProductionService extends BaseService
|
|||||||
}
|
}
|
||||||
return $otFileEntities;
|
return $otFileEntities;
|
||||||
}
|
}
|
||||||
protected function storeOtFile(UploadedFile $file) : ?OrdenTrabajoFileEntity
|
protected function storeOtFile(UploadedFile $file): ?OrdenTrabajoFileEntity
|
||||||
{
|
{
|
||||||
$result = null;
|
$result = null;
|
||||||
if($this->ot){
|
if ($this->ot) {
|
||||||
if ($file->isValid() && !$file->hasMoved()) {
|
if ($file->isValid() && !$file->hasMoved()) {
|
||||||
$fullpath = $file->store('orden_trabajo/'.$this->ot->id);
|
$fullpath = $file->store('orden_trabajo/' . $this->ot->id);
|
||||||
$ot_file_id = $this->otFileModel->insert([
|
$ot_file_id = $this->otFileModel->insert([
|
||||||
"orden_trabajo_id" => $this->ot->id,
|
"orden_trabajo_id" => $this->ot->id,
|
||||||
"name" => $file->getClientName(),
|
"name" => $file->getClientName(),
|
||||||
"file_path" => WRITEPATH.'uploads/'.$fullpath,
|
"file_path" => WRITEPATH . 'uploads/' . $fullpath,
|
||||||
"upload_by" => auth()->user()->id
|
"upload_by" => auth()->user()->id
|
||||||
]);
|
]);
|
||||||
$result = $this->otFileModel->find($ot_file_id);
|
$result = $this->otFileModel->find($ot_file_id);
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}else{
|
} else {
|
||||||
throw new Exception('No se ha especificado una orden de trabajo. Usa $this->producctionService->init($orden_trabajo_id)');
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user