mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Merge branch 'mod/presupuesto_admin' of https://git.imnavajas.es/jjimenez/safekat into mod/presupuesto_admin
This commit is contained in:
@ -1,14 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Presupuestos\PresupuestoModel;
|
||||
use CodeIgniter\Config\BaseService;
|
||||
|
||||
class MessageService extends BaseService
|
||||
{
|
||||
public static function get_chat_title_from_presupuesto(int $presuesto_id,?string $department_name = null) : string
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
696
ci4/app/Services/ProductionService.php
Normal file
696
ci4/app/Services/ProductionService.php
Normal file
@ -0,0 +1,696 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Entities\Clientes\ClienteEntity;
|
||||
use App\Entities\Pedidos\PedidoEntity;
|
||||
use App\Entities\Presupuestos\PresupuestoEntity;
|
||||
use App\Entities\Presupuestos\PresupuestoLineaEntity;
|
||||
use App\Entities\Produccion\OrdenTrabajoEntity;
|
||||
use App\Models\OrdenTrabajo\OrdenTrabajoDate;
|
||||
use App\Models\OrdenTrabajo\OrdenTrabajoModel;
|
||||
use App\Models\OrdenTrabajo\OrdenTrabajoTarea;
|
||||
use App\Models\OrdenTrabajo\OrdenTrabajoUser;
|
||||
use App\Models\Usuarios\UserModel;
|
||||
use CodeIgniter\Config\BaseService;
|
||||
use CodeIgniter\Database\BaseBuilder;
|
||||
use CodeIgniter\Database\BaseResult;
|
||||
use CodeIgniter\Database\Exceptions\DatabaseException;
|
||||
use CodeIgniter\I18n\Time;
|
||||
use Dompdf\Dompdf;
|
||||
|
||||
/**
|
||||
* Clase con las funcionalidades necesarias trabajar con las ordenes de trabajo.
|
||||
*/
|
||||
class ProductionService extends BaseService
|
||||
{
|
||||
protected OrdenTrabajoModel $otModel;
|
||||
protected OrdenTrabajoTarea $otTarea;
|
||||
protected OrdenTrabajoDate $otDate;
|
||||
protected OrdenTrabajoUser $otUser;
|
||||
protected OrdenTrabajoEntity $ot;
|
||||
protected UserModel $userModel;
|
||||
protected array $MAPPING_DATE_USER = [
|
||||
"fecha_encuadernado_at" => "encuadernacion_user_id",
|
||||
// "fecha_externo_at" => "null",
|
||||
"fecha_impresion_at" => "null",
|
||||
"pendiente_ferro_at" => "pendiente_ferro_user_id",
|
||||
"ferro_en_cliente_at" => "ferro_en_cliente_user_id",
|
||||
"ferro_ok_at" => "ferro_ok_user_id",
|
||||
"interior_bn_at" => "interior_bn_user_id",
|
||||
"interior_color_at" => "interior_color_user_id",
|
||||
"preparacion_interiores_at" => "preparacion_interior_user_id",
|
||||
"cubierta_at" => "cubierta_user_id",
|
||||
"plastificado_at" => "plastificado_user_id",
|
||||
"corte_at" => "corte_user_id",
|
||||
"embalaje_at" => "embalaje_user_id",
|
||||
"entrada_manipulado_at" => "entrada_manipulado_user_id"
|
||||
];
|
||||
|
||||
/**
|
||||
* Pedido Entity
|
||||
*
|
||||
* @var PedidoEntity
|
||||
*/
|
||||
protected PedidoEntity $pedido;
|
||||
/**
|
||||
* Presupuesto Entity
|
||||
*
|
||||
* @var PresupuestoEntity
|
||||
*/
|
||||
protected PresupuestoEntity $presupuesto;
|
||||
|
||||
public function __construct() {
|
||||
$this->otModel = model(OrdenTrabajoModel::class);
|
||||
$this->otDate = model(OrdenTrabajoDate::class);
|
||||
$this->otTarea = model(OrdenTrabajoTarea::class);
|
||||
$this->otUser = model(OrdenTrabajoUser::class);
|
||||
$this->userModel = model(UserModel::class);
|
||||
|
||||
}
|
||||
public function init(int $orden_trabajo_id): self
|
||||
{
|
||||
$this->otModel = model(OrdenTrabajoModel::class);
|
||||
$this->ot = $this->otModel->find($orden_trabajo_id);
|
||||
$pedido = $this->ot->pedido();
|
||||
$this->setPedido($pedido);
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Establece el pedido sobre el que se va a trabajar
|
||||
*
|
||||
* @param PedidoEntity $pedido
|
||||
* @return self
|
||||
*/
|
||||
public function setPedido(PedidoEntity $pedido): self
|
||||
{
|
||||
$this->pedido = $pedido;
|
||||
$this->presupuesto = $this->pedido->presupuesto();
|
||||
$this->otModel = model(OrdenTrabajoModel::class);
|
||||
$this->otDate = model(OrdenTrabajoDate::class);
|
||||
$this->otTarea = model(OrdenTrabajoTarea::class);
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Devuelve la orden de trabajo.
|
||||
*
|
||||
* @return OrdenTrabajoEntity
|
||||
*/
|
||||
public function getOrdenTrabajo(): OrdenTrabajoEntity
|
||||
{
|
||||
return $this->ot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea una instancia de la orden de trabajo
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function createOrdenTrabajo(): OrdenTrabajoEntity|DatabaseException
|
||||
{
|
||||
|
||||
$auth_user = auth()->user();
|
||||
$ot = new OrdenTrabajoEntity();
|
||||
$ot_exists = $this->pedido->orden_trabajo();
|
||||
if ($ot_exists) {
|
||||
return $ot_exists;
|
||||
}
|
||||
$data = [
|
||||
"pedido_id" => $this->pedido->id,
|
||||
"user_created_id" => $auth_user->id,
|
||||
"user_updated_id" => $auth_user->id,
|
||||
"total_tirada" => $this->pedido->total_tirada,
|
||||
"total_precio" => $this->pedido->total_precio
|
||||
];
|
||||
$ot->fill($data);
|
||||
$this->otModel->save($ot);
|
||||
$ot_id = $this->otModel->getInsertID();
|
||||
$ot->id = $ot_id;
|
||||
$this->init($ot_id);
|
||||
$this->storeOrdenTrabajoUsers();
|
||||
$this->storeOrdenTrabajoDates();
|
||||
$this->storeAllTareas();
|
||||
return $this->ot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserta las fechas del pedido asociado a la orden de trabajo en `orden_trabajo_tareas`
|
||||
*
|
||||
* @param OrdenTrabajoEntity $ot
|
||||
* @return integer|boolean|string ID
|
||||
*/
|
||||
protected function storeOrdenTrabajoDates() : int|bool|string
|
||||
{
|
||||
$fecha_encuadernado = Time::now()->addDays(2)->format("Y-m-d");
|
||||
$fecha_entrega_real = Time::now()->addDays(5)->format("Y-m-d");
|
||||
$fecha_embalaje_at = Time::now()->addDays(4)->format("Y-m-d");
|
||||
return $this->otDate->insert([
|
||||
"orden_trabajo_id" => $this->ot->id,
|
||||
"fecha_encuadernado_at" => $fecha_encuadernado,
|
||||
"fecha_entrega_real_at" => $fecha_entrega_real,
|
||||
"fecha_impresion_at" => Time::now()->format("Y-m-d"),
|
||||
"embalaje_at" => $fecha_embalaje_at,
|
||||
"fecha_entrega_externo" => $this->pedido->fecha_entrega_externo,
|
||||
]);
|
||||
}
|
||||
protected function storeOrdenTrabajoUsers() : int|bool|string
|
||||
{
|
||||
return $this->otUser->insert([
|
||||
"orden_trabajo_id" => $this->ot->id,
|
||||
]);
|
||||
}
|
||||
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
|
||||
*
|
||||
*
|
||||
* @return integer|boolean Numero de registro insertados o `FALSE` si error
|
||||
*/
|
||||
protected function storeOrdenTrabajoTareas(): int|bool
|
||||
{
|
||||
|
||||
$p_lineas = $this->presupuesto->presupuestoLineas();
|
||||
$ot_tareas = [];
|
||||
|
||||
foreach ($p_lineas as $key => $p_linea) {
|
||||
$p_linea_maquina = $p_linea->maquina();
|
||||
$nombre = $p_linea->get_nombre_tarea();
|
||||
$ot_tareas["orden_trabajo_id"] = $this->ot->id;
|
||||
$ot_tareas["presupuesto_linea_id"] = $p_linea->id;
|
||||
$ot_tareas["nombre"] = $nombre;
|
||||
$ot_tareas["orden"] = $p_linea_maquina->orden_planning ?? 0;
|
||||
$ot_tareas["maquina_id"] = $p_linea_maquina->id;
|
||||
$ot_tareas["imposicion_id"] = null;
|
||||
$ot_tareas["tiempo_estimado"] = $p_linea->horas_maquina;
|
||||
$ot_tareas["tiempo_real"] = $p_linea->horas_maquina; //? Tiempo real se inserta manual?
|
||||
$insert_query_result = $this->otTarea->insert($ot_tareas);
|
||||
$ot_tareas = [];
|
||||
}
|
||||
return $insert_query_result;
|
||||
}
|
||||
protected function storeOrdenTrabajoAcabadoTareas(): bool
|
||||
{
|
||||
$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"] = $p_linea->tarifa()->nombre;
|
||||
$ot_tareas["orden"] = $linea->orden_planning ?? 0;
|
||||
$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;
|
||||
$ot_tareas["nombre"] = $p_linea->tarifa()->nombre ?? "";
|
||||
$this->otTarea->insert($ot_tareas);
|
||||
}
|
||||
}
|
||||
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"] = $p_linea->tarifa()->nombre;
|
||||
$ot_tareas["orden"] = $linea->orden_planning ?? 0;
|
||||
$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;
|
||||
$ot_tareas["nombre"] = $p_linea->tarifa()->nombre ?? "";
|
||||
$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"] = $p_linea->tarifa()->nombre;
|
||||
$ot_tareas["orden"] = $linea->orden_planning ?? 0;
|
||||
$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;
|
||||
$ot_tareas["nombre"] = $p_linea->tarifa()->nombre ?? "";
|
||||
$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_encuadernado_id"] = $p_linea->id;
|
||||
$ot_tareas["nombre"] = $p_linea->tarifa()->nombre;
|
||||
$ot_tareas["orden"] = $linea->orden_planning ?? 0;
|
||||
$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_encuadernado_id"] = $p_linea->id;
|
||||
$ot_tareas["nombre"] = $p_linea->tarifa()->nombre ?? "";
|
||||
$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"] = $p_linea->tarifa()->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;
|
||||
$ot_tareas["nombre"] = $p_linea->tarifa()->nombre ?? "";
|
||||
|
||||
$this->otTarea->insert($ot_tareas);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getTareas(): array
|
||||
{
|
||||
$p_lineas_with_maquina = $this->getPresupuestoLineasWithMaquina();
|
||||
$tareas = [];
|
||||
$tarea = [];
|
||||
foreach ($p_lineas_with_maquina as $key => $linea) {
|
||||
$tarea["orden"] = $linea->maquina->orden_planning;
|
||||
$tarea["maquina_tipo"] = $linea->maquina->tipo;
|
||||
$tarea["maquina_nombre"] = $linea->maquina->nombre;
|
||||
$tarea["nota"] = null;
|
||||
$tareas[] = $tarea;
|
||||
$tarea = [];
|
||||
}
|
||||
return ["tareas" => $tareas];
|
||||
}
|
||||
|
||||
public function getPdf()
|
||||
{
|
||||
return view("themes/vuexy/pdfs/orden_trabajo",$this->getDataPdf());
|
||||
}
|
||||
/**
|
||||
* Query para mostrar en datatable
|
||||
*
|
||||
* @return BaseBuilder
|
||||
*/
|
||||
public function taskDatatableQuery(): BaseBuilder
|
||||
{
|
||||
$q = $this->otModel->builder()->select([
|
||||
"orden_trabajo_tareas.id",
|
||||
"orden_trabajo_tareas.orden",
|
||||
"orden_trabajo_tareas.nombre",
|
||||
"lgmp.nombre as maquina_presupuesto_linea",
|
||||
"orden_trabajo_tareas.maquina_id as maquina_tarea",
|
||||
"lg_maquinas.nombre as maquina_nombre",
|
||||
"lg_imposiciones.id as imposicion_id",
|
||||
"orden_trabajo_tareas.tiempo_estimado",
|
||||
"orden_trabajo_tareas.tiempo_real",
|
||||
"orden_trabajo_tareas.comment",
|
||||
|
||||
])
|
||||
->join("orden_trabajo_tareas", "orden_trabajo_tareas.orden_trabajo_id = ordenes_trabajo.id", "left")
|
||||
->join("presupuesto_linea", "presupuesto_linea.id = orden_trabajo_tareas.presupuesto_linea_id", "left")
|
||||
->join("presupuesto_acabados", "presupuesto_acabados.id = orden_trabajo_tareas.presupuesto_acabado_id", "left")
|
||||
->join("presupuesto_manipulados", "presupuesto_manipulados.id = orden_trabajo_tareas.presupuesto_manipulado_id", "left")
|
||||
->join("presupuesto_preimpresiones", "presupuesto_preimpresiones.id = orden_trabajo_tareas.presupuesto_preimpresion_id", "left")
|
||||
->join("presupuesto_encuadernaciones", "presupuesto_encuadernaciones.id = orden_trabajo_tareas.presupuesto_encuadernado_id", "left")
|
||||
->join("presupuesto_serviciosExtra", "presupuesto_serviciosExtra.id = orden_trabajo_tareas.presupuesto_extra_id", "left")
|
||||
->join("lg_maquinas", "lg_maquinas.id = orden_trabajo_tareas.maquina_id", "left")
|
||||
->join("lg_maquinas as lgmp", "lgmp.id = presupuesto_linea.maquina_id", "left")
|
||||
->join("lg_imposiciones", "lg_imposiciones.id = orden_trabajo_tareas.imposicion_id", "left")
|
||||
->where("orden_trabajo_tareas.orden_trabajo_id", $this->ot->id)
|
||||
->where("orden_trabajo_tareas.deleted_at", null)
|
||||
->orderBy("orden_trabajo_tareas.orden", "ASC");
|
||||
return $q;
|
||||
}
|
||||
/**
|
||||
* Query para mostrar en datatable
|
||||
*
|
||||
* @return BaseBuilder
|
||||
*/
|
||||
public function planningRotativaQueryDatatable(): BaseBuilder
|
||||
{
|
||||
$q = $this->otModel->builder()->select([
|
||||
"ordenes_trabajo.id as otId",
|
||||
"orden_trabajo_dates.fecha_entrega_real_at",
|
||||
"presupuestos.titulo as presupuesto_titulo",
|
||||
"orden_trabajo_tareas.maquina_id",
|
||||
"lg_maquinas.nombre as maquina_planning_nombre",
|
||||
"ordenes_trabajo.total_tirada as ot_tirada",
|
||||
"lg_papel_formato.ancho as maquina_ancho",
|
||||
"lg_papel_formato.alto as maquina_alto",
|
||||
// "JSON_EXTRACT(presupuesto_linea.formas,'$.maquina_ancho') as maquina_ancho",
|
||||
// "JSON_EXTRACT(presupuesto_linea.formas,'$.maquina_alto') as maquina_alto",
|
||||
"lg_papel_impresion.nombre as papel_impresion",
|
||||
"presupuesto_linea.gramaje as papel_gramaje",
|
||||
|
||||
|
||||
|
||||
])
|
||||
->join("orden_trabajo_tareas", "orden_trabajo_tareas.orden_trabajo_id = ordenes_trabajo.id", "left")
|
||||
->join("orden_trabajo_dates", "orden_trabajo_dates.orden_trabajo_id = ordenes_trabajo.id", "left")
|
||||
->join("presupuesto_linea", "presupuesto_linea.id = orden_trabajo_tareas.presupuesto_linea_id", "left")
|
||||
->join("presupuestos", "presupuestos.id = presupuesto_linea.presupuesto_id", "right")
|
||||
->join("lg_papel_formato", "lg_papel_formato.id = presupuestos.papel_formato_id", "left")
|
||||
->join("lg_maquinas", "lg_maquinas.id = orden_trabajo_tareas.maquina_id", "left")
|
||||
->join("lg_papel_impresion", "lg_papel_impresion.id = presupuesto_linea.papel_impresion_id", "left")
|
||||
->join("lg_maquinas as lgmp", "lgmp.id = presupuesto_linea.maquina_id", "left")
|
||||
->join("lg_imposiciones", "lg_imposiciones.id = orden_trabajo_tareas.imposicion_id", "left")
|
||||
// ->where("orden_trabajo_tareas.orden_trabajo_id", $this->ot->id)
|
||||
->whereIn("presupuesto_linea.tipo", ["lp_rot_bn","lp_rot_color"])
|
||||
->where("orden_trabajo_tareas.deleted_at", null)
|
||||
->orderBy("orden_trabajo_tareas.orden", "ASC");
|
||||
return $q;
|
||||
}
|
||||
/**
|
||||
* Query para mostrar en datatable
|
||||
*
|
||||
* @return BaseBuilder
|
||||
*/
|
||||
public function costDatatableQuery(): BaseBuilder
|
||||
{
|
||||
$q = $this->otModel->builder()->select([
|
||||
"orden_trabajo_tareas.id",
|
||||
"orden_trabajo_tareas.orden",
|
||||
"orden_trabajo_tareas.nombre",
|
||||
"lgmp.nombre as maquina_presupuesto_linea",
|
||||
"orden_trabajo_tareas.maquina_id as maquina_tarea",
|
||||
"lg_maquinas.nombre as maquina_nombre",
|
||||
"lg_imposiciones.id as imposicion_id",
|
||||
"orden_trabajo_tareas.tiempo_estimado",
|
||||
"orden_trabajo_tareas.tiempo_real"
|
||||
])
|
||||
->join("orden_trabajo_tareas", "orden_trabajo_tareas.orden_trabajo_id = ordenes_trabajo.id", "left")
|
||||
->join("presupuesto_linea", "presupuesto_linea.id = orden_trabajo_tareas.presupuesto_linea_id", "left")
|
||||
->join("presupuesto_acabados", "presupuesto_acabados.id = orden_trabajo_tareas.presupuesto_acabado_id", "left")
|
||||
->join("presupuesto_manipulados", "presupuesto_manipulados.id = orden_trabajo_tareas.presupuesto_manipulado_id", "left")
|
||||
->join("presupuesto_preimpresiones", "presupuesto_preimpresiones.id = orden_trabajo_tareas.presupuesto_preimpresion_id", "left")
|
||||
->join("presupuesto_encuadernaciones", "presupuesto_encuadernaciones.id = orden_trabajo_tareas.presupuesto_encuadernado_id", "left")
|
||||
->join("presupuesto_serviciosExtra", "presupuesto_serviciosExtra.id = orden_trabajo_tareas.presupuesto_extra_id", "left")
|
||||
->join("lg_maquinas", "lg_maquinas.id = orden_trabajo_tareas.maquina_id", "left")
|
||||
->join("lg_maquinas as lgmp", "lgmp.id = presupuesto_linea.maquina_id", "left")
|
||||
->join("lg_imposiciones", "lg_imposiciones.id = orden_trabajo_tareas.imposicion_id", "left")
|
||||
->where("orden_trabajo_tareas.orden_trabajo_id", $this->ot->id)
|
||||
->where("orden_trabajo_tareas.deleted_at", null)
|
||||
->orderBy("orden_trabajo_tareas.orden", "ASC");
|
||||
return $q;
|
||||
}
|
||||
public function papelGramajeDatatableQuery() : BaseBuilder
|
||||
{
|
||||
$q = $this->otModel->builder()->select([
|
||||
"lg_papel_impresion.nombre as papelImpresionNombre",
|
||||
"lg_papel_impresion.gramaje as papelImpresionGramaje",
|
||||
"COUNT(orden_trabajo_tareas.id) as tareasCount",
|
||||
"SUM(ordenes_trabajo.total_tirada) as totalTirada",
|
||||
"SUM(orden_trabajo_tareas.tiempo_real) as tiempoReal"
|
||||
])
|
||||
->join("orden_trabajo_tareas", "orden_trabajo_tareas.orden_trabajo_id = ordenes_trabajo.id", "left")
|
||||
->join("presupuesto_linea", "presupuesto_linea.id = orden_trabajo_tareas.presupuesto_linea_id", "left")
|
||||
->join("lg_papel_impresion","presupuesto_linea.papel_impresion_id = lg_papel_impresion.id","left")
|
||||
->where("orden_trabajo_tareas.deleted_at", null)
|
||||
->where("orden_trabajo_tareas.presupuesto_linea_id IS NOT NULL", NULL,FALSE);
|
||||
|
||||
|
||||
|
||||
return $q;
|
||||
}
|
||||
/**
|
||||
* Get a summary from ot with the following structure
|
||||
*
|
||||
* @return array
|
||||
* ```php
|
||||
* [
|
||||
* "ot" => OrdenTrabajoEntity
|
||||
* "dates" => OrdenTrabajoDateEntity
|
||||
* "tasks" => array<OrdenTrabajoTareaEntity>
|
||||
* ];
|
||||
* ```
|
||||
*/
|
||||
public function getSummary(): array
|
||||
{
|
||||
|
||||
$summary = [
|
||||
"ot" => $this->ot,
|
||||
"pedido" => $this->pedido,
|
||||
"presupuesto" => $this->presupuesto,
|
||||
"dates" => $this->ot->dates(),
|
||||
"tasks" => $this->ot->tareas(),
|
||||
"acabados" => $this->presupuesto->acabados(),
|
||||
"preimpresiones" => $this->presupuesto->preimpresiones(),
|
||||
"manipulados" => $this->presupuesto->manipulados(),
|
||||
"encuadernaciones" => $this->presupuesto->encuadernaciones(),
|
||||
"impresion_interior_bn" => $this->getTareaImpresionInteriorBn(),
|
||||
"impresion_interior_color" => $this->getTareaImpresionInteriorColor(),
|
||||
"tareas_acabado" => $this->tareas_acabado(),
|
||||
"tareas_manipulado" => $this->tareas_manipulado(),
|
||||
"tareas_encuadernacion" => $this->tareas_encuadernacion(),
|
||||
"tareas_preimpresion" => $this->tareas_preimpresion(),
|
||||
"tareas_impresion" => $this->tareas_impresion(),
|
||||
];
|
||||
return $summary;
|
||||
}
|
||||
public function getDataPdf(){
|
||||
$logistica_data = $this->logistica_data();
|
||||
return [
|
||||
"ot" => $this->ot,
|
||||
"pedido" => $this->pedido,
|
||||
"presupuesto" => $this->presupuesto,
|
||||
"cliente" => $this->presupuesto->cliente(),
|
||||
"ubicacion" => $this->pedido->ubicacion()->nombre,
|
||||
"dates" => $this->ot->dates(),
|
||||
"tasks" => $this->ot->tareas(),
|
||||
"papel_formato" => $this->presupuesto->papel_formato(),
|
||||
"acabados" => $this->presupuesto->acabados(),
|
||||
"preimpresiones" => $this->presupuesto->preimpresiones(),
|
||||
"manipulados" => $this->presupuesto->manipulados(),
|
||||
"encuadernaciones" => $this->presupuesto->encuadernaciones(),
|
||||
"linea_impresion" => $this->presupuesto->presupuestoLineaImpresion(),
|
||||
"linea_cubierta" => $this->presupuesto->presupuestoLineaCubierta(),
|
||||
"peso_unidad" => $logistica_data["peso_unidad"],
|
||||
"peso_pedido" => $logistica_data["peso_pedido"]
|
||||
];
|
||||
}
|
||||
public function getTareaImpresionSobreCubierta() : array
|
||||
{
|
||||
$q = $this->otTarea->select('orden_trabajo_tareas.*')
|
||||
->join("presupuesto_linea","presupuesto_linea.id = orden_trabajo_tareas.presupuesto_linea_id","left")
|
||||
->where("orden_trabajo_tareas.orden_trabajo_id",$this->ot->id)
|
||||
->whereIn("presupuesto_linea.tipo",["lp_sobrecubierta"])->findAll();
|
||||
return $q;
|
||||
}
|
||||
public function getTareaImpresionCubierta() : array
|
||||
{
|
||||
$q = $this->otTarea->select('orden_trabajo_tareas.*')
|
||||
->join("presupuesto_linea","presupuesto_linea.id = orden_trabajo_tareas.presupuesto_linea_id","left")
|
||||
->where("orden_trabajo_tareas.orden_trabajo_id",$this->ot->id)
|
||||
->whereIn("presupuesto_linea.tipo",["lp_cubierta"])->findAll();
|
||||
return $q;
|
||||
}
|
||||
public function getTareaImpresionInteriorBn() : array
|
||||
{
|
||||
$q = $this->otTarea->select('orden_trabajo_tareas.*')
|
||||
->join("presupuesto_linea","presupuesto_linea.id = orden_trabajo_tareas.presupuesto_linea_id","left")
|
||||
->where("orden_trabajo_tareas.orden_trabajo_id",$this->ot->id)
|
||||
->whereIn("presupuesto_linea.tipo",["lp_rot_bn","lp_bn","lp_bnhq"])->findAll();
|
||||
return $q;
|
||||
}
|
||||
public function getTareaImpresionInteriorColor() : array
|
||||
{
|
||||
$q = $this->otTarea->select('orden_trabajo_tareas.*')
|
||||
->join("presupuesto_linea","presupuesto_linea.id = orden_trabajo_tareas.presupuesto_linea_id","left")
|
||||
->where("orden_trabajo_tareas.orden_trabajo_id",$this->ot->id)
|
||||
->whereIn("presupuesto_linea.tipo",["lp_rot_color","lp_color","lp_colorhq"])->findAll();
|
||||
return $q;
|
||||
}
|
||||
public function getPresupuestoLineaImpresion(){
|
||||
}
|
||||
public function tareas_acabado(): array
|
||||
{
|
||||
$q = $this->otTarea->where("presupuesto_acabado_id IS NOT NULL",NULL,FALSE)->findAll();
|
||||
return $q;
|
||||
}
|
||||
public function tareas_impresion(): array
|
||||
{
|
||||
$q = $this->otTarea->where("presupuesto_linea_id IS NOT NULL",NULL,FALSE)->findAll();
|
||||
return $q;
|
||||
}
|
||||
public function tareas_encuadernacion(): array
|
||||
{
|
||||
$q = $this->otTarea->where("presupuesto_encuadernado_id IS NOT NULL",NULL,FALSE)->findAll();
|
||||
return $q;
|
||||
}
|
||||
public function tareas_preimpresion(): array
|
||||
{
|
||||
$q = $this->otTarea->where("presupuesto_preimpresion_id IS NOT NULL",NULL,FALSE)->findAll();
|
||||
return $q;
|
||||
}
|
||||
public function tareas_manipulado(): array
|
||||
{
|
||||
$q = $this->otTarea->where("presupuesto_manipulado_id IS NOT NULL",NULL,FALSE)->findAll();
|
||||
return $q;
|
||||
}
|
||||
/**========================================================================
|
||||
* UPDATES
|
||||
*========================================================================**/
|
||||
|
||||
public function updateOrdenTrabajoTarea($tarea_id,$data) : bool
|
||||
{
|
||||
return $this->otTarea->update($tarea_id,$data);
|
||||
}
|
||||
|
||||
public function updateOrdenTrabajoDate($data)
|
||||
{
|
||||
// return $this->otDate->find($this->ot->id);
|
||||
$r = $this->otDate->update($this->ot->id,$data);
|
||||
$ot_users = $this->ot->users();
|
||||
$ot_users = $ot_users->toArray();
|
||||
$user_id = $ot_users[$this->MAPPING_DATE_USER[$data["name"]]];
|
||||
$user = $this->userModel->find($user_id);
|
||||
return ["user" => $user,"status" => $r];
|
||||
}
|
||||
|
||||
public function updateOrdenTrabajo($data) : bool
|
||||
{
|
||||
return $this->otModel->update($this->ot->id,$data);
|
||||
}
|
||||
/**========================================================================
|
||||
* 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();
|
||||
}
|
||||
protected function logistica_data() : array
|
||||
{
|
||||
$presupuesto_lineas = $this->presupuesto->presupuestoLineas();
|
||||
$peso = 0;
|
||||
foreach ($presupuesto_lineas as $key => $linea) {
|
||||
$peso += $linea->peso;
|
||||
}
|
||||
return [
|
||||
"peso_unidad" => $peso,
|
||||
"peso_pedido" => $peso*$this->ot->total_tirada
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
58
ci4/app/Services/TarifaMaquinaService.php
Normal file
58
ci4/app/Services/TarifaMaquinaService.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Configuracion\MaquinaTareaModel;
|
||||
use App\Models\Tarifas\Maquinas\TarifaAcabadoMaquinaModel;
|
||||
use App\Models\Tarifas\Maquinas\TarifaManipuladoMaquinaModel;
|
||||
use App\Models\Tarifas\Maquinas\TarifaEncuadernacionMaquinaModel;
|
||||
use App\Models\Tarifas\Maquinas\TarifaPreimpresionMaquinaModel;
|
||||
use App\Models\Tarifas\Maquinas\TarifaExtraMaquinaModel;
|
||||
use CodeIgniter\Config\BaseService;
|
||||
use CodeIgniter\Database\BaseBuilder;
|
||||
use CodeIgniter\Database\Exceptions\DatabaseException;
|
||||
|
||||
/**
|
||||
* Clase con las funcionalidades necesarias trabajar con tarifas maquinas
|
||||
*/
|
||||
|
||||
class TarifaMaquinaService extends BaseService
|
||||
{
|
||||
protected TarifaAcabadoMaquinaModel $tarifaAcabadoMaquina;
|
||||
protected TarifaManipuladoMaquinaModel $tarifaManipuladoMaquina;
|
||||
protected TarifaPreimpresionMaquinaModel $tarifaPreimpresionMaquina;
|
||||
protected TarifaEncuadernacionMaquinaModel $tarifaEncuadernacionMaquina;
|
||||
protected TarifaExtraMaquinaModel $tarifaExtraMaquina;
|
||||
protected MaquinaTareaModel $maquinaTarea;
|
||||
|
||||
public function __construct() {
|
||||
$this->tarifaAcabadoMaquina = model(TarifaAcabadoMaquinaModel::class);
|
||||
$this->tarifaManipuladoMaquina = model(TarifaManipuladoMaquinaModel::class);
|
||||
$this->tarifaEncuadernacionMaquina = model(TarifaEncuadernacionMaquinaModel::class);
|
||||
$this->tarifaPreimpresionMaquina = model(TarifaPreimpresionMaquinaModel::class);
|
||||
$this->tarifaExtraMaquina = model(TarifaExtraMaquinaModel::class);
|
||||
|
||||
}
|
||||
|
||||
public function attachAcabadoToMaquina(int $tarifa_acabado_id, int $maquina_id, int $maquina_tarea_id): bool|int|string
|
||||
{
|
||||
return $this->tarifaAcabadoMaquina->insert(["tarifa_acabado_id" => $tarifa_acabado_id, "maquina_id" => $maquina_id, "maquina_tarea_id" => $maquina_tarea_id]);
|
||||
}
|
||||
public function attachManipuladoToMaquina(int $tarifa_manipulado_id, int $maquina_id, int $maquina_tarea_id): bool|int|string
|
||||
{
|
||||
return $this->tarifaManipuladoMaquina->insert(["tarifa_manipulado_id" => $tarifa_manipulado_id, "maquina_id" => $maquina_id, "maquina_tarea_id" => $maquina_tarea_id]);
|
||||
}
|
||||
public function attachPreimpresionToMaquina(int $tarifa_preimpresion_id, int $maquina_id, int $maquina_tarea_id): bool|int|string
|
||||
{
|
||||
return $this->tarifaPreimpresionMaquina->insert(["tarifa_preimpresion_id" => $tarifa_preimpresion_id, "maquina_id" => $maquina_id, "maquina_tarea_id" => $maquina_tarea_id]);
|
||||
}
|
||||
public function attachEncuadernacionToMaquina(int $tarifa_encuadernacion_id, int $maquina_id, int $maquina_tarea_id): bool|int|string
|
||||
{
|
||||
return $this->tarifaEncuadernacionMaquina->insert(["tarifa_encuadernacion_id" => $tarifa_encuadernacion_id, "maquina_id" => $maquina_id, "maquina_tarea_id" => $maquina_tarea_id]);
|
||||
}
|
||||
public function attachExtraToMaquina(int $tarifa_extra_id, int $maquina_id, int $maquina_tarea_id): bool|int|string
|
||||
{
|
||||
return $this->tarifaExtraMaquina->insert(["tarifa_extra_id" => $tarifa_extra_id, "maquina_id" => $maquina_id, "maquina_tarea_id" => $maquina_tarea_id]);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user