mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
add maquinas tareas
This commit is contained in:
@ -14,6 +14,7 @@ use App\Models\OrdenTrabajo\OrdenTrabajoModel;
|
||||
use App\Models\OrdenTrabajo\OrdenTrabajoTarea;
|
||||
use CodeIgniter\Config\BaseService;
|
||||
use CodeIgniter\Database\BaseBuilder;
|
||||
use CodeIgniter\Database\BaseResult;
|
||||
use CodeIgniter\Database\Exceptions\DatabaseException;
|
||||
|
||||
/**
|
||||
@ -62,28 +63,16 @@ class ProductionService extends BaseService
|
||||
$this->otTarea = model(OrdenTrabajoTarea::class);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtiene el pedido asociado a esta clase
|
||||
* Devuelve la orden de trabajo.
|
||||
*
|
||||
* @return PedidoEntity
|
||||
* @return OrdenTrabajoEntity
|
||||
*/
|
||||
public function getPedido(): PedidoEntity
|
||||
{
|
||||
return $this->pedido;
|
||||
}
|
||||
public function getPresupuesto(): PresupuestoEntity
|
||||
{
|
||||
return $this->presupuesto;
|
||||
}
|
||||
public function getCliente(): ClienteEntity
|
||||
{
|
||||
return $this->presupuesto->cliente();
|
||||
}
|
||||
public function getOrdenTrabajo(): OrdenTrabajoEntity
|
||||
{
|
||||
return $this->ot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea una instancia de la orden de trabajo
|
||||
*
|
||||
@ -110,7 +99,8 @@ class ProductionService extends BaseService
|
||||
$ot_id = $this->otModel->getInsertID();
|
||||
$ot->id = $ot_id;
|
||||
$this->storeOrdenTrabajoDates($ot);
|
||||
$this->storeOrdenTrabajoTareas($ot);
|
||||
$this->storeAllTareas();
|
||||
$this->init($ot_id);
|
||||
return $ot;
|
||||
}
|
||||
|
||||
@ -130,15 +120,29 @@ class ProductionService extends BaseService
|
||||
"fecha_entrega_externo" => $this->pedido->fecha_entrega_externo,
|
||||
]);
|
||||
}
|
||||
protected function storeAllTareas()
|
||||
{
|
||||
$this->storeOrdenTrabajoTareas();
|
||||
$this->storeOrdenTrabajoAcabadoTareas();
|
||||
$this->storeOrdenTrabajoManipuladoTareas();
|
||||
$this->storeOrdenTrabajoPreimpresionTareas();
|
||||
$this->storeOrdenTrabajoEncuadernacionTareas();
|
||||
$this->storeOrdenTrabajoExtraTareas();
|
||||
}
|
||||
public function resetAllTareas() : BaseResult|bool
|
||||
{
|
||||
$r = $this->otTarea->where("orden_trabajo_id",$this->ot->id)->delete(purge:true);
|
||||
$this->storeAllTareas();
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Inserta las tareas de la orden de trabajo.
|
||||
* Acepta como argumento una entidad de la orden de trabajo OrdenTrabajoEntity
|
||||
*
|
||||
*
|
||||
* @param OrdenTrabajoEntity $ot
|
||||
* @return integer|boolean Numero de registro insertados o `FALSE` si error
|
||||
*/
|
||||
protected function storeOrdenTrabajoTareas(OrdenTrabajoEntity $ot): int|bool
|
||||
protected function storeOrdenTrabajoTareas(): int|bool
|
||||
{
|
||||
|
||||
$p_lineas = $this->presupuesto->presupuestoLineas();
|
||||
@ -146,7 +150,7 @@ class ProductionService extends BaseService
|
||||
|
||||
foreach ($p_lineas as $key => $p_linea) {
|
||||
$p_linea_maquina = $p_linea->maquina();
|
||||
$ot_tareas["orden_trabajo_id"] = $ot->id;
|
||||
$ot_tareas["orden_trabajo_id"] = $this->ot->id;
|
||||
$ot_tareas["presupuesto_linea_id"] = $p_linea->id;
|
||||
//TODO : Por ahora nombre maquina, asignar nombre tarea en
|
||||
//TODO : base a la tarifa asociada a la linea de presupuesto
|
||||
@ -161,19 +165,132 @@ class ProductionService extends BaseService
|
||||
}
|
||||
return $insert_query_result;
|
||||
}
|
||||
/**
|
||||
* Devuelve las lineas de presupuesto con la máquina asociada a cada una
|
||||
*
|
||||
* @return array<PresupuestoLineaEntity>
|
||||
*/
|
||||
protected function getPresupuestoLineasWithMaquina(): array
|
||||
protected function storeOrdenTrabajoAcabadoTareas(): bool
|
||||
{
|
||||
$presupuesto_lineas = $this->presupuesto->presupuestoLineas();
|
||||
foreach ($presupuesto_lineas as $key => $linea) {
|
||||
$linea->maquina = $linea->maquina();
|
||||
$p_lineas = $this->presupuesto_lineas_acabado();
|
||||
foreach ($p_lineas as $key => $p_linea) {
|
||||
$p_linea_maquinas = $p_linea->maquinas();
|
||||
$ot_tareas = [];
|
||||
if (count($p_linea_maquinas) > 0) {
|
||||
foreach ($p_linea_maquinas as $key => $linea) {
|
||||
$ot_tareas["orden_trabajo_id"] = $this->ot->id;
|
||||
$ot_tareas["presupuesto_acabado_id"] = $p_linea->id;
|
||||
$ot_tareas["nombre"] = $linea->nombre;
|
||||
$ot_tareas["orden"] = $linea->orden_planning;
|
||||
$ot_tareas["maquina_id"] = $linea->id;
|
||||
$ot_tareas["imposicion_id"] = null;
|
||||
$this->otTarea->insert($ot_tareas);
|
||||
$ot_tareas = [];
|
||||
}
|
||||
} else {
|
||||
$ot_tareas["orden_trabajo_id"] = $this->ot->id;
|
||||
$ot_tareas["presupuesto_acabado_id"] = $p_linea->id;
|
||||
$this->otTarea->insert($ot_tareas);
|
||||
}
|
||||
}
|
||||
return $presupuesto_lineas;
|
||||
return true;
|
||||
}
|
||||
protected function storeOrdenTrabajoManipuladoTareas(): bool
|
||||
{
|
||||
$p_lineas = $this->presupuesto_lineas_manipulado();
|
||||
foreach ($p_lineas as $key => $p_linea) {
|
||||
$p_linea_maquinas = $p_linea->maquinas();
|
||||
$ot_tareas = [];
|
||||
if (count($p_linea_maquinas) > 0) {
|
||||
foreach ($p_linea_maquinas as $key => $linea) {
|
||||
$ot_tareas["orden_trabajo_id"] = $this->ot->id;
|
||||
$ot_tareas["presupuesto_manipulado_id"] = $p_linea->id;
|
||||
$ot_tareas["nombre"] = $linea->nombre;
|
||||
$ot_tareas["orden"] = $linea->orden_planning;
|
||||
$ot_tareas["maquina_id"] = $linea->id;
|
||||
$ot_tareas["imposicion_id"] = null;
|
||||
$this->otTarea->insert($ot_tareas);
|
||||
$ot_tareas = [];
|
||||
}
|
||||
} else {
|
||||
$ot_tareas["orden_trabajo_id"] = $this->ot->id;
|
||||
$ot_tareas["presupuesto_manipulado_id"] = $p_linea->id;
|
||||
$this->otTarea->insert($ot_tareas);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
protected function storeOrdenTrabajoPreimpresionTareas(): bool
|
||||
{
|
||||
$p_lineas = $this->presupuesto_lineas_preimpresion();
|
||||
foreach ($p_lineas as $key => $p_linea) {
|
||||
$p_linea_maquinas = $p_linea->maquinas();
|
||||
$ot_tareas = [];
|
||||
if (count($p_linea_maquinas) > 0) {
|
||||
foreach ($p_linea_maquinas as $key => $linea) {
|
||||
$ot_tareas["orden_trabajo_id"] = $this->ot->id;
|
||||
$ot_tareas["presupuesto_preimpresion_id"] = $p_linea->id;
|
||||
$ot_tareas["nombre"] = $linea->nombre;
|
||||
$ot_tareas["orden"] = $linea->orden_planning;
|
||||
$ot_tareas["maquina_id"] = $linea->id;
|
||||
$ot_tareas["imposicion_id"] = null;
|
||||
$this->otTarea->insert($ot_tareas);
|
||||
$ot_tareas = [];
|
||||
}
|
||||
} else {
|
||||
$ot_tareas["orden_trabajo_id"] = $this->ot->id;
|
||||
$ot_tareas["presupuesto_preimpresion_id"] = $p_linea->id;
|
||||
$this->otTarea->insert($ot_tareas);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
protected function storeOrdenTrabajoEncuadernacionTareas(): bool
|
||||
{
|
||||
$p_lineas = $this->presupuesto_lineas_encuadernaciones();
|
||||
foreach ($p_lineas as $key => $p_linea) {
|
||||
$p_linea_maquinas = $p_linea->maquinas();
|
||||
$ot_tareas = [];
|
||||
if (count($p_linea_maquinas) > 0) {
|
||||
foreach ($p_linea_maquinas as $key => $linea) {
|
||||
$ot_tareas["orden_trabajo_id"] = $this->ot->id;
|
||||
$ot_tareas["presupuesto_encuadernacion_id"] = $p_linea->id;
|
||||
$ot_tareas["nombre"] = $linea->nombre;
|
||||
$ot_tareas["orden"] = $linea->orden_planning;
|
||||
$ot_tareas["maquina_id"] = $linea->id;
|
||||
$ot_tareas["imposicion_id"] = null;
|
||||
$this->otTarea->insert($ot_tareas);
|
||||
$ot_tareas = [];
|
||||
}
|
||||
} else {
|
||||
$ot_tareas["orden_trabajo_id"] = $this->ot->id;
|
||||
$ot_tareas["presupuesto_encuadernacion_id"] = $p_linea->id;
|
||||
$this->otTarea->insert($ot_tareas);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
protected function storeOrdenTrabajoExtraTareas(): bool
|
||||
{
|
||||
$p_lineas = $this->presupuesto_lineas_extras();
|
||||
foreach ($p_lineas as $key => $p_linea) {
|
||||
$p_linea_maquinas = $p_linea->maquinas();
|
||||
$ot_tareas = [];
|
||||
if (count($p_linea_maquinas) > 0) {
|
||||
foreach ($p_linea_maquinas as $key => $linea) {
|
||||
$ot_tareas["orden_trabajo_id"] = $this->ot->id;
|
||||
$ot_tareas["presupuesto_extra_id"] = $p_linea->id;
|
||||
$ot_tareas["nombre"] = $linea->nombre;
|
||||
$ot_tareas["orden"] = $linea->orden_planning;
|
||||
$ot_tareas["maquina_id"] = $linea->id;
|
||||
$ot_tareas["imposicion_id"] = null;
|
||||
$this->otTarea->insert($ot_tareas);
|
||||
$ot_tareas = [];
|
||||
}
|
||||
} else {
|
||||
$ot_tareas["orden_trabajo_id"] = $this->ot->id;
|
||||
$ot_tareas["presupuesto_extra_id"] = $p_linea->id;
|
||||
$this->otTarea->insert($ot_tareas);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getTareas(): array
|
||||
@ -221,9 +338,6 @@ class ProductionService extends BaseService
|
||||
/**
|
||||
* Get a summary from ot with the following structure
|
||||
*
|
||||
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
* ```php
|
||||
* [
|
||||
@ -248,4 +362,61 @@ class ProductionService extends BaseService
|
||||
];
|
||||
return $summary;
|
||||
}
|
||||
|
||||
/**========================================================================
|
||||
* RELATION METHODS
|
||||
*========================================================================**/
|
||||
/**
|
||||
* Obtiene el pedido asociado a esta clase
|
||||
*
|
||||
* @return PedidoEntity
|
||||
*/
|
||||
public function getPedido(): PedidoEntity
|
||||
{
|
||||
return $this->pedido;
|
||||
}
|
||||
|
||||
public function getCliente(): ClienteEntity
|
||||
{
|
||||
return $this->presupuesto->cliente();
|
||||
}
|
||||
|
||||
|
||||
public function getPresupuesto(): PresupuestoEntity
|
||||
{
|
||||
return $this->presupuesto;
|
||||
}
|
||||
/**
|
||||
* Devuelve las lineas de presupuesto con la máquina asociada a cada una
|
||||
*
|
||||
* @return array<PresupuestoLineaEntity>
|
||||
*/
|
||||
protected function getPresupuestoLineasWithMaquina(): array
|
||||
{
|
||||
$presupuesto_lineas = $this->presupuesto->presupuestoLineas();
|
||||
foreach ($presupuesto_lineas as $key => $linea) {
|
||||
$linea->maquina = $linea->maquina();
|
||||
}
|
||||
return $presupuesto_lineas;
|
||||
}
|
||||
protected function presupuesto_lineas_acabado(): array
|
||||
{
|
||||
return $this->presupuesto->acabados();
|
||||
}
|
||||
protected function presupuesto_lineas_manipulado(): array
|
||||
{
|
||||
return $this->presupuesto->manipulados();
|
||||
}
|
||||
protected function presupuesto_lineas_preimpresion(): array
|
||||
{
|
||||
return $this->presupuesto->preimpresiones();
|
||||
}
|
||||
protected function presupuesto_lineas_encuadernaciones(): array
|
||||
{
|
||||
return $this->presupuesto->encuadernaciones();
|
||||
}
|
||||
protected function presupuesto_lineas_extras(): array
|
||||
{
|
||||
return $this->presupuesto->extras();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user