add maquinas tareas

This commit is contained in:
amazuecos
2024-12-24 12:51:44 +01:00
parent 6790c21675
commit 60706ecfc2
15 changed files with 266 additions and 46 deletions

View File

@ -882,6 +882,7 @@ $routes->group('produccion', ['namespace' => 'App\Controllers\Produccion'], func
$routes->group('ordentrabajo', ['namespace' => 'App\Controllers\Produccion'], function ($routes) {
$routes->get('', 'Ordentrabajo::index', ['as' => 'viewOrdenTrabajoIndex']);
$routes->get('edit/(:num)', 'Ordentrabajo::edit/$1', ['as' => 'viewOrdenTrabajoEdit']);
$routes->delete('reset/tareas/(:num)', 'Ordentrabajo::reset_tareas/$1');
$routes->get('summary/(:num)', 'Ordentrabajo::get_orden_trabajo_summary/$1', ['as' => 'getOrdenTrabajoSumary']);
$routes->get('datatable', 'Ordentrabajo::datatable', ['as' => 'datatableOrdenTrabajo']);
});

View File

@ -74,6 +74,11 @@ class Ordentrabajo extends BaseController
->add("action" ,fn($q) => $q->id)
->toJson(true);
}
public function reset_tareas(int $orden_trabajo_id)
{
$r = $this->produccionService->init($orden_trabajo_id)->resetAllTareas();
return $this->response->setJSON(["message" => "Tareas reseteadas" ,"status" => $r]);
}
}

View File

@ -9,7 +9,7 @@ class MaquinaTareaSeeder extends Seeder
{
public function run()
{
$m = model(MaquinaTareaModel::class);
$data = [
[
"name" => "Grapar",
@ -39,8 +39,11 @@ class MaquinaTareaSeeder extends Seeder
"name" => "Corte",
"description" => "Manipulado"
],
[
"name" => "Marcapáginas",
"description" => "Acabado"
],
];
$m = model(MaquinaTareaModel::class);
$m->insertBatch($data);
}
}

View File

@ -1,6 +1,7 @@
<?php
namespace App\Entities\Presupuestos;
use App\Models\Tarifas\Maquinas\TarifaAcabadoMaquinaModel;
use CodeIgniter\Entity;
class PresupuestoAcabadosEntity extends \CodeIgniter\Entity\Entity
@ -28,4 +29,10 @@ class PresupuestoAcabadosEntity extends \CodeIgniter\Entity\Entity
"cubierta" => "int",
"sobrecubierta" => "int",
];
public function maquinas() : array
{
$m = model(TarifaAcabadoMaquinaModel::class);
return $m->where("tarifa_acabado_id",$this->attributes["tarifa_acabado_id"])->findAll();
}
}

View File

@ -1,6 +1,8 @@
<?php
namespace App\Entities\Presupuestos;
use App\Models\Tarifas\Maquinas\TarifaEncuadernacionMaquinaModel;
use App\Models\Tarifas\Maquinas\TarifaManipuladoMaquinaModel;
use CodeIgniter\Entity;
class PresupuestoEncuadernacionesEntity extends \CodeIgniter\Entity\Entity
@ -28,4 +30,9 @@ class PresupuestoEncuadernacionesEntity extends \CodeIgniter\Entity\Entity
"precio_total" => "float",
"margen" => "float",
];
public function maquinas() : array
{
$m = model(TarifaEncuadernacionMaquinaModel::class);
return $m->where("tarifa_encuadernacion_id",$this->attributes["tarifa_encuadernado_id"])->findAll();
}
}

View File

@ -10,6 +10,7 @@ use App\Models\Presupuestos\PresupuestoLineaModel;
use App\Models\Presupuestos\PresupuestoManipuladosModel;
use App\Models\Presupuestos\PresupuestoModel;
use App\Models\Presupuestos\PresupuestoPreimpresionesModel;
use App\Models\Presupuestos\PresupuestoServiciosExtraModel;
use CodeIgniter\Entity;
class PresupuestoEntity extends \CodeIgniter\Entity\Entity
@ -222,5 +223,9 @@ class PresupuestoEntity extends \CodeIgniter\Entity\Entity
$m = model(PresupuestoManipuladosModel::class);
return $m->where("presupuesto_id",$this->attributes["id"])->findAll();
}
public function extras(): array
{
$m = model(PresupuestoServiciosExtraModel::class);
return $m->where("presupuesto_id",$this->attributes["id"])->findAll();
}
}

View File

@ -1,6 +1,7 @@
<?php
namespace App\Entities\Presupuestos;
use App\Models\Tarifas\Maquinas\TarifaManipuladoMaquinaModel;
use CodeIgniter\Entity;
class PresupuestoManipuladosEntity extends \CodeIgniter\Entity\Entity
@ -22,4 +23,9 @@ class PresupuestoManipuladosEntity extends \CodeIgniter\Entity\Entity
"precio_total" => "float",
"margen" => "float",
];
public function maquinas() : array
{
$m = model(TarifaManipuladoMaquinaModel::class);
return $m->where("tarifa_manipulado_id",$this->attributes["tarifa_manipulado_id"])->findAll();
}
}

View File

@ -1,6 +1,7 @@
<?php
namespace App\Entities\Presupuestos;
use App\Models\Tarifas\Maquinas\TarifaPreimpresionMaquinaModel;
use CodeIgniter\Entity;
class PresupuestoPreimpresionesEntity extends \CodeIgniter\Entity\Entity
@ -20,4 +21,9 @@ class PresupuestoPreimpresionesEntity extends \CodeIgniter\Entity\Entity
"precio_total" => "float",
"margen" => "float",
];
public function maquinas() : array
{
$m = model(TarifaPreimpresionMaquinaModel::class);
return $m->where("tarifa_preimpresion_id",$this->attributes["tarifa_preimpresion_id"])->findAll();
}
}

View File

@ -1,6 +1,7 @@
<?php
namespace App\Entities\Presupuestos;
use App\Models\Tarifas\Maquinas\TarifaExtraMaquinaModel;
use CodeIgniter\Entity;
class PresupuestoServiciosExtraEntity extends \CodeIgniter\Entity\Entity
@ -20,4 +21,10 @@ class PresupuestoServiciosExtraEntity extends \CodeIgniter\Entity\Entity
"precio_total" => "float",
"margen" => "float",
];
public function maquinas() : array
{
$m = model(TarifaExtraMaquinaModel::class);
return $m->where("tarifa_extra_id",$this->attributes["tarifa_extra_id"])->findAll();
}
}

View File

@ -17,6 +17,11 @@ class OrdenTrabajoTarea extends Model
protected $allowedFields = [
"orden_trabajo_id",
"presupuesto_linea_id",
"presupuesto_acabado_id",
"presupuesto_preimpresion_id",
"presupuesto_encuadernado_id",
"presupuesto_extra_id",
"presupuesto_manipulado_id",
"nombre",
"orden",
"maquina_id",

View File

@ -64,12 +64,11 @@ class TarifaEncuadernacionMaquinaModel extends Model
"lg_maquinas.nombre as maquinaNombre",
"maquina_tareas.name as tareaNombre"
]
)->join("lg_maquinas", "lg_maquinas.id = tarifa_encuadernacion_maquinas.maquina_id", "left")
->join("maquina_tareas", "maquina_tareas.id = tarifa_encuadernacion_maquinas.maquina_tarea_id", "left")
)->join("lg_maquinas","lg_maquinas.id = tarifa_encuadernacion_maquinas.maquina_id","left")
->join("maquina_tareas","maquina_tareas.id = tarifa_encuadernacion_maquinas.maquina_tarea_id","left")
->where("tarifa_encuadernacion_maquinas.deleted_at",null);
if ($tarifa_encuadernacion_id)
$query->where("tarifa_encuadernacion_maquinas.id", $tarifa_encuadernacion_id);
$query->where("tarifa_encuadernacion_maquinas.tarifa_encuadernacion_id", $tarifa_encuadernacion_id);
return $query;
}
}

View File

@ -67,10 +67,9 @@ class TarifaExtraMaquinaModel extends Model
]
)->join("lg_maquinas", "lg_maquinas.id = tarifa_extra_maquinas.maquina_id", "left")
->join("maquina_tareas", "maquina_tareas.id = tarifa_extra_maquinas.maquina_tarea_id", "left")
->where("tarifa_extra_maquinas.deleted_at",null);
->where("tarifa_extra_maquinas.deleted_at", null);
if ($tarifa_extra_id)
$query->where("tarifa_extra_maquinas.id", $tarifa_extra_id);
$query->where("tarifa_extra_maquinas.tarifa_extra_id", $tarifa_extra_id);
return $query;
}
}

View File

@ -67,9 +67,9 @@ class TarifaManipuladoMaquinaModel extends Model
]
)->join("lg_maquinas", "lg_maquinas.id = tarifa_manipulado_maquinas.maquina_id", "left")
->join("maquina_tareas", "maquina_tareas.id = tarifa_manipulado_maquinas.maquina_tarea_id", "left")
->where("tarifa_manipulado_maquinas.deleted_at",null);
->where("tarifa_manipulado_maquinas.deleted_at", null);
if ($tarifa_manipulado_id)
$query->where("tarifa_manipulado_maquinas.id", $tarifa_manipulado_id);
$query->where("tarifa_manipulado_maquinas.tarifa_manipulado_id", $tarifa_manipulado_id);
return $query;
}
}

View File

@ -68,9 +68,8 @@ class TarifaPreimpresionMaquinaModel extends Model
)->join("lg_maquinas", "lg_maquinas.id = tarifa_preimpresion_maquinas.maquina_id", "left")
->join("maquina_tareas", "maquina_tareas.id = tarifa_preimpresion_maquinas.maquina_tarea_id", "left")
->where("tarifa_preimpresion_maquinas.deleted_at", null);
if ($tarifa_preimpresion_id)
$query->where("tarifa_preimpresion_maquinas.id", $tarifa_preimpresion_id);
$query->where("tarifa_preimpresion_maquinas.tarifa_preimpresion_id", $tarifa_preimpresion_id);
return $query;
}
}

View File

@ -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();
}
}