Merge branch 'main' into 'add/view_logistica_principal'

Main

See merge request jjimenez/safekat!710
This commit is contained in:
2025-04-16 16:24:25 +00:00
21 changed files with 777 additions and 164 deletions

View File

@ -16,6 +16,7 @@ use CodeIgniter\Config\BaseService;
use App\Entities\Configuracion\Maquina as MaquinaEntity;
use App\Entities\Produccion\OrdenTrabajoFileEntity;
use App\Entities\Produccion\OrdenTrabajoTareaEntity;
use App\Entities\Tarifas\Acabados\TarifaAcabadoEntity;
use App\Models\Configuracion\ConfigVariableModel;
use App\Models\Configuracion\MaquinaModel;
use App\Models\OrdenTrabajo\OrdenTrabajoFileModel;
@ -34,7 +35,17 @@ use Exception;
*/
class ProductionService extends BaseService
{
/**
* Tipos de impresion para identificar linea de impresion plana/general
*
* @var array
*/
public array $TIPOS_PLANA = ['lp_bn', 'lp_color', 'lp_colorhq'];
/**
* Tipos de impresion para idenficiar si es rotativa
*
* @var array
*/
public array $TIPOS_ROTATIVA = ['lp_rot_bn', 'lp_rot_color'];
protected OrdenTrabajoModel $otModel;
@ -46,12 +57,99 @@ class ProductionService extends BaseService
protected OrdenTrabajoFileModel $otFileModel;
protected PedidoModel $pedidoModel;
protected UserModel $userModel;
protected string $defaultMaquinaCorteName = 'HT-1000';
protected ConfigVariableModel $configVariableModel;
protected MaquinaEntity $defaultMaquinaCorte;
protected MaquinaModel $maquinaModel;
protected OrdenTrabajo $ordenTrabajoConfig;
public string $statusColor;
/**
* Nombre de la maquina por defecto para realizar la tarea de corte.
*
* @var string 'HT-1000'
*/
protected string $defaultMaquinaCorteName = 'HT-1000';
/**
* Color del header en el formulario de orden de trabajo
*
* @var string
*/
public string $statusColor;
/**
* Valor límite del POD
*
* `$this->configVariableModel->getVariable('POD')->value;`
* @var integer
*/
protected int $podValue = 0;
/**
* Indica si es POD
*
* `tirada <= podValue`
* @var boolean
*/
protected bool $isPOD = false;
/**
* Indica si la orden de trabajo contiene gofrado
* Se usa para mostrar la fecha correspondiente en la vista
* @var boolean
*/
public bool $isGofrado = false; //* CHECK DONE
/**
* Indica si la orden de trabajo contiene gofrado
* Se usa para mostrar la fecha correspondiente en la vista
* TODO Hay que implementar un boolean en `lg_tarifa_acabado` para identificar
* @var boolean
*/
public bool $isGrapado = true; //TODO
/**
* Indica si la orden de trabajo contiene espiral
* Se usa para mostrar la fecha correspondiente en la vista
* TODO Hay que implementar un boolean en `lg_tarifa_manipulado` para identificar
* DEFAULT true hasta implementacion
* @var boolean
*/
public bool $isEspiral = true; //TODO
/**
* Indica si la orden de trabajo contiene UVI
* Se usa para mostrar la fecha correspondiente en la vista
* @var boolean
*/
public bool $isUVI = false; //* CHECK DONE
/**
* Indica si la orden de trabajo contiene plastificado
* Se usa para mostrar la fecha correspondiente en la vista
* TODO Hay que implementar un boolean en `lg_tarifa_acabado` para identificar
* DEFAULT true hasta implementacion
* @var boolean
*/
public bool $isPlastificado = true; //TODO
/**
* Indica si la orden de trabajo contiene cubierta
* Se usa para mostrar la fecha correspondiente en la vista
* @var boolean
*/
public bool $isCubierta = false; //* CHECK DONE
/**
* Indica si la impresion es en color
* Se usa para mostrar la fecha correspondiente en la vista
* @var boolean
*/
public bool $isColor = false; //* CHECK DONE
/**
* Indica si la impresion es en bn
* Se usa para mostrar la fecha correspondiente en la vista
* @var boolean
*/
public bool $isBN = false; //* CHECK DONE
/**
* Indica si hay una tarea de corte
* Se usa para mostrar la fecha correspondiente en la vista
* ! Se añade por defecto siempre en una rotativa una tarea de corte
* @var boolean
*/
public bool $isCorte = false; //* CHECK DONE
/**
* Pedido Entity
*
@ -76,11 +174,13 @@ class ProductionService extends BaseService
$this->pedidoModel = model(PedidoModel::class);
$this->ordenTrabajoConfig = config('OrdenTrabajo');
$this->statusColor = $this->ordenTrabajoConfig->OT_COLORS["sin_imprimir"];
$this->configVariableModel = model(ConfigVariableModel::class);
$this->podValue = $this->configVariableModel->getVariable('POD')->value;
}
public function init(int $orden_trabajo_id): self
{
try {
//code...
$this->maquinaModel = model(MaquinaModel::class);
$this->otModel = model(OrdenTrabajoModel::class);
$this->ot = $this->otModel->find($orden_trabajo_id);
@ -90,7 +190,6 @@ class ProductionService extends BaseService
$this->statusColor = $this->ordenTrabajoConfig->OT_COLORS["sin_imprimir"];
return $this;
} catch (\Throwable $th) {
dd($orden_trabajo_id);
throw $th;
}
}
@ -107,6 +206,7 @@ class ProductionService extends BaseService
$this->otModel = model(OrdenTrabajoModel::class);
$this->otDate = model(OrdenTrabajoDate::class);
$this->otTarea = model(OrdenTrabajoTarea::class);
$this->isPOD = $this->presupuesto->tirada <= $this->podValue;
return $this;
}
/**
@ -141,10 +241,10 @@ class ProductionService extends BaseService
];
$id = $this->otModel->insert($data);
$this->init($id);
$this->updatePedidoEspera();
$this->storeOrdenTrabajoUsers();
$this->storeOrdenTrabajoDates();
$this->storeAllTareas();
$this->updatePedidoEspera();
return $this->ot;
}
@ -171,12 +271,48 @@ class ProductionService extends BaseService
$this->otDate->updateUserDateMap($this->ot->id, $data);
return $otDateId;
}
/**
* Crea un registro en `orden_trabajo_users`
*
* @return integer|boolean|string
*/
protected function storeOrdenTrabajoUsers(): int|bool|string
{
return $this->otUser->insert([
"orden_trabajo_id" => $this->ot->id,
]);
}
/**
* Crea un registro en `orden_trabajo_users` si no ha sido creado previamente
*
* @return integer|boolean|string
*/
public function reInsertOrdenTrabajoUsers(): int|bool|string
{
$status = false;
if ($this->otUser->where('orden_trabajo_id', $this->ot->id)->countAllResults() == 0) {
$status = $this->storeOrdenTrabajoUsers();
}
return $status;
}
/**
* Crea un registro en `orden_trabajo_dates` si no ha sido creado previamente
*
* @return integer|boolean|string
*/
public function reInsertOrdenTrabajoDates(): int|bool|string
{
$status = false;
if ($this->otDate->where('orden_trabajo_id', $this->ot->id)->countAllResults() == 0) {
$status = $this->storeOrdenTrabajoDates();
}
return $status;
}
/**
* General las correspondientes tareas de la orden de trabajo en la table `orden_trabajo_tareas`
*
* @return integer|boolean|string
*/
protected function storeAllTareas()
{
$this->storeOrdenTrabajoTareas();
@ -186,6 +322,12 @@ class ProductionService extends BaseService
$this->storeOrdenTrabajoEncuadernacionTareas();
// $this->storeOrdenTrabajoExtraTareas();
}
/**
* Regenera las tareas.
* !! Se eliminan las que hay previamente sin `softDelete`
*
* @return integer|boolean|string
*/
public function resetAllTareas(): BaseResult|bool
{
$r = $this->otTarea->where("orden_trabajo_id", $this->ot->id)->delete(purge: true);
@ -222,6 +364,12 @@ class ProductionService extends BaseService
}
return $insert_query_result;
}
/**
* Inserta una tarea de corte si la impresion es en `rotativa`
*
* @param PresupuestoLineaEntity $pLinea
* @return OrdenTrabajoTareaEntity|null
*/
protected function storeTareaCorte(PresupuestoLineaEntity $pLinea): ?OrdenTrabajoTareaEntity
{
$otCorte = null;
@ -242,6 +390,11 @@ class ProductionService extends BaseService
return $otCorte;
}
/**
* General las tareas de acabado segun las líneas de presupuesto_acabados
*
* @return boolean
*/
protected function storeOrdenTrabajoAcabadoTareas(): bool
{
$p_lineas = $this->presupuesto_lineas_acabado();
@ -268,6 +421,11 @@ class ProductionService extends BaseService
}
return true;
}
/**
* General las tareas de acabado segun las líneas de presupuesto_manipulados
*
* @return boolean
*/
protected function storeOrdenTrabajoManipuladoTareas(): bool
{
$p_lineas = $this->presupuesto_lineas_manipulado();
@ -294,6 +452,11 @@ class ProductionService extends BaseService
}
return true;
}
/**
* General las tareas de acabado segun las líneas de presupuesto_preimpresion
*
* @return boolean
*/
protected function storeOrdenTrabajoPreimpresionTareas(): bool
{
$p_lineas = $this->presupuesto_lineas_preimpresion();
@ -320,6 +483,11 @@ class ProductionService extends BaseService
}
return true;
}
/**
* General las tareas de acabado segun las líneas de presupuesto_encuadernaciones
*
* @return boolean
*/
protected function storeOrdenTrabajoEncuadernacionTareas(): bool
{
$p_lineas = $this->presupuesto_lineas_encuadernaciones();
@ -666,6 +834,10 @@ class ProductionService extends BaseService
"peso_pedido" => $logistica_data["peso_pedido"],
"imposicion" => $this->getImposicionTareaImpresion(),
"tiempo_procesamiento" => $this->getTiempoProcesamientoHHMM(),
"tiempo_impresion" => $this->getTiempoTareasImpresionHHMM(),
"colors" => $this->getPdfColors(),
"isPOD" => $this->isPOD,
"uvi" => $this->getUVI()
];
}
@ -757,8 +929,8 @@ class ProductionService extends BaseService
{
$result = [];
$otDate = $this->otDate->where('orden_trabajo_id', $this->ot->id)
->set([$data['name'] => $data[$data['name']]])
->update($data);
->set($data['name'], $data[$data['name']])
->update();
$this->otDate->updateUserDateMap($this->ot->id, $data);
$ot_users = $this->ot->users();
if (isset($this->ordenTrabajoConfig->DATE_USER_MAPPING[$data["name"]])) {
@ -1063,7 +1235,7 @@ class ProductionService extends BaseService
$status = false;
$presupuestoFiles = $this->presupuesto->files();
if (count($presupuestoFiles) == 0) {
$status = $this->otModel->update($this->ot->id, ['pedido_espera' => true]);
$status = $this->otModel->update($this->ot->id, ['is_pedido_espera' => true]);
}
return $status;
}
@ -1100,6 +1272,28 @@ class ProductionService extends BaseService
$seconds = array_sum($time_tareas_seconds);
return float_seconds_to_hhmm_string($seconds);
}
public function getTiempoTareasImpresionHHMM(): string
{
$tareas_impresion = $this->ot->tareas_impresion();
$tiempo_seconds = 0;
foreach ($tareas_impresion as $key => $tarea) {
if ($tarea->is_corte == false) {
$tiempo_seconds += $tarea->tiempo_estimado;
}
}
return float_seconds_to_hhmm_string($tiempo_seconds);
}
public function getUVI(): ?TarifaAcabadoEntity
{
$uvi = null;
$acabados = $this->presupuesto->acabados();
foreach ($acabados as $key => $acabado) {
if ($acabado->tarifa()->isUVI()) {
$uvi = $acabado->tarifa();
}
}
return $uvi;
}
public function updateProgress(): bool
{
$userDates = $this->ordenTrabajoConfig->DATE_USER_MAPPING;
@ -1125,7 +1319,7 @@ class ProductionService extends BaseService
}
public function getOtColorStatus(): string
{
if($this->ot->dates()){
if ($this->ot->dates()) {
$this->updateColor();
}
return $this->statusColor;
@ -1190,7 +1384,8 @@ class ProductionService extends BaseService
$this->statusColor = $this->ordenTrabajoConfig->OT_COLORS["grapado"];
};
}
protected function updateColor(){
protected function updateColor()
{
$this->otSinImprimirColor();
$this->otImpresionIntColor();
$this->otCosidoColor();
@ -1202,4 +1397,219 @@ class ProductionService extends BaseService
$this->otEncuadernadoColor();
$this->otCorteColor();
}
public function getEncuadernacionCode(): ?string
{
$code = "";
$encuadernaciones = $this->presupuesto->encuadernaciones();
if (isset($encuadernaciones[0])) {
$code = $encuadernaciones[0]->tarifa()->code;
}
return $code;
}
public function getEncuadernacionColor(): array
{
$color = $this->ordenTrabajoConfig->OT_ENCUADERNACION_COLOR["default"];
$encuadernacion_code = $this->getEncuadernacionCode();
if ($encuadernacion_code) {
if (isset($this->ordenTrabajoConfig->OT_ENCUADERNACION_COLOR[$encuadernacion_code])) {
$color = $this->ordenTrabajoConfig->OT_ENCUADERNACION_COLOR[$encuadernacion_code];
}
}
return $color;
}
public function getWeekDayColor(): array
{
$color = $this->ordenTrabajoConfig->OT_WEEK_COLOR_DAY[0];
if ($this->ot->pedido()->fecha_encuadernado) {
$week_day = Time::createFromFormat("Y-m-d H:i:s", $this->ot->pedido()->fecha_encuadernado)->getDayOfWeek();
$color = $this->ordenTrabajoConfig->OT_WEEK_COLOR_DAY[$week_day];
}
return $color;
}
public function getGeneralBackgroundColor()
{
$color = $this->ordenTrabajoConfig->OT_BACKGROUND_COLOR['default'];
$is_ferro_or_prototipo = ($this->presupuesto->ferro || $this->presupuesto->ferro_digital || $this->presupuesto->prototipo);
$color = $is_ferro_or_prototipo ? $this->ordenTrabajoConfig->OT_BACKGROUND_COLOR['ferro'] : $color;
$color = $this->isPOD ? $this->ordenTrabajoConfig->OT_BACKGROUND_COLOR['pod'] : $color;
$color = $this->pedido->inaplazable ? $this->ordenTrabajoConfig->OT_BACKGROUND_COLOR['inaplazable'] : $color;
return $color;
}
public function getPapelImpresionBackgroundColor()
{
$papel = $this->presupuesto->presupuestoLineaImpresion()->papel_generico();
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['default'];
$papel_code = $papel->code_ot;
if ($papel_code) {
if (strpos($papel_code, "BCLOF")) {
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['blanco'];
}
if (strpos($papel_code, "AH") && $papel->code == "OFF2") {
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['ahuesado'];
}
if (strpos($papel_code, "MARF")) {
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['marfil'];
}
if (strpos($papel_code, "VOLAH")) {
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['volumen_ahuesado'];
}
if ($papel_code == "EM") {
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['estucado_mate'];
}
if ($papel_code == "CGE") {
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['cartulina'];
}
}
return $color;
}
public function getPapelImpresionCubiertaBackgroundColor()
{
$papel = $this->presupuesto->presupuestoLineaCubierta()->papel_generico();
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['default'];
$papel_code = $papel->code_ot;
if ($papel_code) {
if (strpos($papel_code, "BCLOF")) {
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['blanco'];
}
if (strpos($papel_code, "AH") && $papel->code == "OFF2") {
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['ahuesado'];
}
if (strpos($papel_code, "MARF")) {
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['marfil'];
}
if (strpos($papel_code, "VOLAH")) {
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['volumen_ahuesado'];
}
if ($papel_code == "EM") {
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['estucado_mate'];
}
if ($papel_code == "CGE") {
$color = $this->ordenTrabajoConfig->OT_PAPEL_COLOR['cartulina'];
}
}
return $color;
}
public function getPlastificadoColor()
{
$acabados = $this->presupuesto->acabados();
$color = $this->ordenTrabajoConfig->OT_PLASTIFICADO_COLOR['default'];
foreach ($acabados as $key => $acabado) {
$tarifa_acabado = $acabado->tarifa();
if ($tarifa_acabado->code) {
$plastificado_code = $tarifa_acabado->code;
if ($plastificado_code == "BRIL") {
$color = $this->ordenTrabajoConfig->OT_PLASTIFICADO_COLOR['BRIL'];
}
if ($plastificado_code == "MATE") {
$color = $this->ordenTrabajoConfig->OT_PLASTIFICADO_COLOR['MATE'];
}
if ($plastificado_code == "ANTI") {
$color = $this->ordenTrabajoConfig->OT_PLASTIFICADO_COLOR['ANTIRAYADO'];
}
if ($plastificado_code == "SAND") {
$color = $this->ordenTrabajoConfig->OT_PLASTIFICADO_COLOR['SANDY'];
}
if ($plastificado_code == "GOF") {
$color = $this->ordenTrabajoConfig->OT_PLASTIFICADO_COLOR['GOFRADO'];
}
}
}
return $color;
}
public function getImpresionInteriorPPALColor()
{
$isRotativa = $this->presupuesto->presupuestoLineaImpresion()->isRotativa();
$color = $isRotativa ? $this->ordenTrabajoConfig->OT_IMPRESION_INTERIOR_PPAL_COLOR['ROTATIVA'] : $this->ordenTrabajoConfig->OT_IMPRESION_INTERIOR_PPAL_COLOR['GENERAL'];
$color = $this->isPOD ? $this->ordenTrabajoConfig->OT_IMPRESION_INTERIOR_PPAL_COLOR['POD'] : $color;
return $color;
}
public function getPdfColors(): array
{
return [
"general" => $this->getGeneralBackgroundColor(),
"week_day" => $this->getWeekDayColor(),
"ot" => $this->getEncuadernacionColor(),
"papel_interior" => $this->getPapelImpresionBackgroundColor(),
"papel_cubierta" => $this->getPapelImpresionCubiertaBackgroundColor(),
"plastificado" => $this->getPlastificadoColor(),
"impresion_interior_ppal" => $this->getImpresionInteriorPPALColor()
];
}
public function getFlags()
{
$this->color();
return [
"isGofrado" => $this->gofrado(),
"isEspiral" => $this->isEspiral,
"isUVI" => $this->uvi(),
"isPlastificado" => $this->isPlastificado,
"isCubierta" => $this->cubierta(),
"isColor" => $this->isColor,
"isBN" => $this->isBN,
"isCorte" => $this->corte(),
"isGrapado" => $this->isGrapado
];
}
public function gofrado(): bool
{
$flag = false;
$acabados = $this->presupuesto->acabados();
foreach ($acabados as $key => $acabado) {
$tarifa_acabado = $acabado->tarifa();
if ($tarifa_acabado->code) {
$plastificado_code = $tarifa_acabado->code;
if ($plastificado_code == "GOF") {
$flag = true;
break;
}
}
}
$this->isGofrado = $flag;
return $this->isGofrado;
}
public function uvi(): bool
{
$flag = false;
$tarifa_acabado_uvi = $this->getUVI();
if ($tarifa_acabado_uvi) {
$flag = true;
}
$this->isUVI = $flag;
return $this->isUVI;
}
public function cubierta(): bool
{
$lineaCubierta = $this->presupuesto->presupuestoLineaCubierta();
if ($lineaCubierta) {
$this->isCubierta = true;
}
return $this->isCubierta;
}
public function color(): bool
{
$linea_impresion = $this->presupuesto->presupuestoLineaImpresion();
if ($linea_impresion) {
if ($linea_impresion->isColor()) {
$this->isColor = true;
$this->isBN = false;
} else {
$this->isColor = false;
$this->isBN = true;
}
}
return $this->isColor;
}
public function corte(): bool
{
$ot_tareas = $this->ot->tareas();
foreach ($ot_tareas as $key => $tarea) {
if ($tarea->is_corte) {
$this->isCorte = true;
break;
}
}
return $this->isCorte;
}
}