mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
432 lines
14 KiB
PHP
Executable File
432 lines
14 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Models\Presupuestos;
|
|
|
|
class PresupuestoLineaModel extends \App\Models\GoBaseModel
|
|
{
|
|
protected $table = "presupuesto_linea";
|
|
|
|
/**
|
|
* Whether primary key uses auto increment.
|
|
*
|
|
* @var bool
|
|
*/
|
|
protected $useAutoIncrement = true;
|
|
|
|
protected $allowedFields = [
|
|
"presupuesto_id",
|
|
"tipo",
|
|
"paginas",
|
|
"paginas_impresion", //guardas
|
|
"paginas_color_posicion",
|
|
"solapas_ancho",
|
|
"papel_id",
|
|
"papel_impresion_id",
|
|
"formas",
|
|
"gramaje",
|
|
"pliegos_libro",
|
|
"pliegos_pedido",
|
|
"pliegos_precio",
|
|
"libro",
|
|
"pedido",
|
|
"mano",
|
|
"peso",
|
|
"maquina_id",
|
|
"tarifa_impresion_id",
|
|
"click",
|
|
"precio",
|
|
"total_papel_pedido",
|
|
"margen_papel_pedido",
|
|
"margen_impresion",
|
|
"rotativa_impresion",
|
|
"rotativa_pag_color",
|
|
"rotativa_set_values",
|
|
"rotativa_negro",
|
|
"rotativa_cyan",
|
|
"rotativa_magenta",
|
|
"rotativa_amarillo",
|
|
"rotativa_gota_negro",
|
|
"rotativa_gota_color",
|
|
"rotativa_saturacion",
|
|
"rotativa_a_favor_fibra",
|
|
"rotativa_mxm",
|
|
"rotativa_area_paginas",
|
|
"rotativa_num_gotas_negro",
|
|
"rotativa_num_gotas_cyan",
|
|
"rotativa_num_gotas_magenta",
|
|
"rotativa_num_gotas_amarillo",
|
|
"rotativa_peso_gotas_negro",
|
|
"rotativa_peso_gotas_cyan",
|
|
"rotativa_peso_gotas_magenta",
|
|
"rotativa_peso_gotas_amarillo",
|
|
"rotativa_precio_pag_negro",
|
|
"rotativa_precio_pag_color",
|
|
"rotativa_factor_altura",
|
|
"rotativa_factor_anchura",
|
|
"rotativa_pag_por_pliego",
|
|
"rotativa_metros_libro",
|
|
"rotativa_metros_total",
|
|
"rotativa_clicks_libro",
|
|
"rotativa_clicks_total",
|
|
"rotativa_precio_tinta",
|
|
"rotativa_total_impresion",
|
|
"rotativa_velocidad_corte",
|
|
"rotativa_tiempo_corte",
|
|
"rotativa_precio_hora_corte",
|
|
"rotativa_total_corte",
|
|
'check_impresion_total',
|
|
'check_papel_total',
|
|
"maquina",
|
|
"papel_impresion",
|
|
"maquina_tipo",
|
|
"horas_maquina",
|
|
"precio_hora",
|
|
"precio_impresion",
|
|
"total_linea",
|
|
];
|
|
protected $returnType = "App\Entities\Presupuestos\PresupuestoLineaEntity";
|
|
|
|
public static $labelField = "presupuesto_id";
|
|
|
|
protected $validationRules = [
|
|
"click" => [
|
|
"label" => "PresupuestoLineas.click",
|
|
"rules" => "decimal|permit_empty",
|
|
],
|
|
"formas" => [
|
|
"label" => "PresupuestoLineas.formas",
|
|
"rules" => "trim|max_length[16313]",
|
|
],
|
|
"gramaje" => [
|
|
"label" => "PresupuestoLineas.gramaje",
|
|
"rules" => "decimal|permit_empty",
|
|
],
|
|
"libro" => [
|
|
"label" => "PresupuestoLineas.libro",
|
|
"rules" => "decimal|permit_empty",
|
|
],
|
|
"mano" => [
|
|
"label" => "PresupuestoLineas.mano",
|
|
"rules" => "decimal|permit_empty",
|
|
],
|
|
"paginas" => [
|
|
"label" => "PresupuestoLineas.paginas",
|
|
"rules" => "required|integer",
|
|
],
|
|
"paginas_color_posicion" => [
|
|
"label" => "PresupuestoLineas.paginasColorPosicion",
|
|
"rules" => "trim|max_length[16313]",
|
|
],
|
|
"pedido" => [
|
|
"label" => "PresupuestoLineas.pedido",
|
|
"rules" => "decimal|permit_empty",
|
|
],
|
|
"peso" => [
|
|
"label" => "PresupuestoLineas.peso",
|
|
"rules" => "decimal|permit_empty",
|
|
],
|
|
"pliegos_libro" => [
|
|
"label" => "PresupuestoLineas.pliegosLibro",
|
|
"rules" => "decimal|permit_empty",
|
|
],
|
|
"pliegos_pedido" => [
|
|
"label" => "PresupuestoLineas.pliegosPedido",
|
|
"rules" => "decimal|permit_empty",
|
|
],
|
|
"pliegos_precio" => [
|
|
"label" => "PresupuestoLineas.pliegosPrecio",
|
|
"rules" => "decimal|permit_empty",
|
|
],
|
|
"precio" => [
|
|
"label" => "PresupuestoLineas.precio",
|
|
"rules" => "decimal|permit_empty",
|
|
],
|
|
"rotativa_amarillo" => [
|
|
"label" => "PresupuestoLineas.rotativaAmarillo",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"rotativa_area_paginas" => [
|
|
"label" => "PresupuestoLineas.rotativaAreaPaginas",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"rotativa_clicks_libro" => [
|
|
"label" => "PresupuestoLineas.rotativaClicksLibro",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"rotativa_clicks_total" => [
|
|
"label" => "PresupuestoLineas.rotativaClicksTotal",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"rotativa_cyan" => [
|
|
"label" => "PresupuestoLineas.rotativaCyan",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"rotativa_factor_altura" => [
|
|
"label" => "PresupuestoLineas.rotativaFactorAltura",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"rotativa_factor_anchura" => [
|
|
"label" => "PresupuestoLineas.rotativaFactorAnchura",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"rotativa_gota_color" => [
|
|
"label" => "PresupuestoLineas.rotativaGotaColor",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"rotativa_gota_negro" => [
|
|
"label" => "PresupuestoLineas.rotativaGotaNegro",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"rotativa_impresion" => [
|
|
"label" => "PresupuestoLineas.rotativaImpresion",
|
|
"rules" => "required|in_list[negro,color]",
|
|
],
|
|
"rotativa_magenta" => [
|
|
"label" => "PresupuestoLineas.rotativaMagenta",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"rotativa_metros_libro" => [
|
|
"label" => "PresupuestoLineas.rotativaMetrosLibro",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"rotativa_metros_total" => [
|
|
"label" => "PresupuestoLineas.rotativaMetrosTotal",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"rotativa_mxm" => [
|
|
"label" => "PresupuestoLineas.rotativaMxm",
|
|
"rules" => "decimal|permit_empty",
|
|
],
|
|
"rotativa_negro" => [
|
|
"label" => "PresupuestoLineas.rotativaNegro",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"rotativa_num_gotas_amarillo" => [
|
|
"label" => "PresupuestoLineas.rotativaNumGotasAmarillo",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"rotativa_num_gotas_cyan" => [
|
|
"label" => "PresupuestoLineas.rotativaNumGotasCyan",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"rotativa_num_gotas_magenta" => [
|
|
"label" => "PresupuestoLineas.rotativaNumGotasMagenta",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"rotativa_num_gotas_negro" => [
|
|
"label" => "PresupuestoLineas.rotativaNumGotasNegro",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"rotativa_pag_color" => [
|
|
"label" => "PresupuestoLineas.rotativaPagColor",
|
|
"rules" => "required|integer",
|
|
],
|
|
"rotativa_pag_por_pliego" => [
|
|
"label" => "PresupuestoLineas.rotativaPagPorPliego",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"rotativa_peso_gotas_amarillo" => [
|
|
"label" => "PresupuestoLineas.rotativaPesoGotasAmarillo",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"rotativa_peso_gotas_cyan" => [
|
|
"label" => "PresupuestoLineas.rotativaPesoGotasCyan",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"rotativa_peso_gotas_magenta" => [
|
|
"label" => "PresupuestoLineas.rotativaPesoGotasMagenta",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"rotativa_peso_gotas_negro" => [
|
|
"label" => "PresupuestoLineas.rotativaPesoGotasNegro",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"rotativa_precio_hora_corte" => [
|
|
"label" => "PresupuestoLineas.rotativaPrecioHoraCorte",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"rotativa_precio_pag_color" => [
|
|
"label" => "PresupuestoLineas.rotativaPrecioPagColor",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"rotativa_precio_pag_negro" => [
|
|
"label" => "PresupuestoLineas.rotativaPrecioPagNegro",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"rotativa_precio_tinta" => [
|
|
"label" => "PresupuestoLineas.rotativaPrecioTinta",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"rotativa_saturacion" => [
|
|
"label" => "PresupuestoLineas.rotativaSaturacion",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"rotativa_tiempo_corte" => [
|
|
"label" => "PresupuestoLineas.rotativaTiempoCorte",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"rotativa_total_corte" => [
|
|
"label" => "PresupuestoLineas.rotativaTotalCorte",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"rotativa_total_impresion" => [
|
|
"label" => "PresupuestoLineas.rotativaTotalImpresion",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"rotativa_velocidad_corte" => [
|
|
"label" => "PresupuestoLineas.rotativaVelocidadCorte",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"solapas_ancho" => [
|
|
"label" => "PresupuestoLineas.solapasAncho",
|
|
"rules" => "required|decimal",
|
|
],
|
|
"tipo" => [
|
|
"label" => "PresupuestoLineas.tipo",
|
|
"rules" => "required|in_list[bn,bnhq,color,colorhq,cubierta,sobrecubierta,rot_bn,rot_color]",
|
|
],
|
|
];
|
|
|
|
|
|
public function findAllWithAllRelations(string $selcols = "*", int $limit = null, int $offset = 0)
|
|
{
|
|
$sql =
|
|
"SELECT t1." .
|
|
$selcols .
|
|
", t2.id AS presupuesto, t3.nombre AS papel, t4.nombre AS papel_impresion, t5.nombre AS maquina, t6.tipo AS tarifa_impresion FROM " .
|
|
$this->table .
|
|
" t1 LEFT JOIN presupuestos t2 ON t1.presupuesto_id = t2.id LEFT JOIN lg_papel_generico t3 ON t1.papel_id = t3.id LEFT JOIN lg_papel_impresion t4 ON t1.papel_impresion_id = t4.id LEFT JOIN lg_maquinas t5 ON t1.maquina_id = t5.id LEFT JOIN lg_maquinas_tarifas_impresion t6 ON t1.tarifa_impresion_id = t6.id";
|
|
if (!is_null($limit) && intval($limit) > 0) {
|
|
$sql .= " LIMIT " . intval($limit);
|
|
}
|
|
|
|
if (!is_null($offset) && intval($offset) > 0) {
|
|
$sql .= " OFFSET " . intval($offset);
|
|
}
|
|
|
|
$query = $this->db->query($sql);
|
|
$result = $query->getResultObject();
|
|
return $result;
|
|
}
|
|
|
|
public function createForPresupuesto($presupuesto_id)
|
|
{
|
|
|
|
$tipos = ['bn', 'bnhq', 'color', 'colorhq', 'cubierta', 'sobrecubierta', 'rot_bn', 'rot_color'];
|
|
foreach ($tipos as $tipo) {
|
|
$builder = $this->db
|
|
->table($this->table . " t1");
|
|
$data = [
|
|
'presupuesto_id' => $presupuesto_id,
|
|
'tipo' => $tipo,
|
|
];
|
|
|
|
$builder->insert($data);
|
|
}
|
|
}
|
|
|
|
public function getLineasPresupuesto($presupuesto_id = -1)
|
|
{
|
|
$builder = $this->db
|
|
->table($this->table . " t1")
|
|
->select(
|
|
"*"
|
|
)
|
|
->where("t1.presupuesto_id", $presupuesto_id);
|
|
|
|
return $builder->orderBy("t1.id", "asc")->get()->getResultObject();
|
|
}
|
|
|
|
public function deleteLineasPresupuesto($presupuesto_id)
|
|
{
|
|
$this->db
|
|
->table($this->table . " t1")
|
|
->where("presupuesto_id", $presupuesto_id)
|
|
->delete();
|
|
}
|
|
|
|
public function insertLineasPresupuesto($presupuesto_id = -1, $datos = [])
|
|
{
|
|
$this->deleteLineasPresupuesto($presupuesto_id);
|
|
|
|
foreach ($datos as $linea) {
|
|
|
|
$this->db
|
|
->table($this->table . " t1")
|
|
->where("t1.presupuesto_id", $presupuesto_id)
|
|
->insert($linea);
|
|
}
|
|
|
|
}
|
|
|
|
public function getResourceByNForPdf($presupuesto_id = -1)
|
|
{
|
|
$builder = $this->db
|
|
->table($this->table . " t1")
|
|
->select(
|
|
"t1.paginas AS paginas, t1.papel_impresion AS papel, t1.gramaje AS gramaje"
|
|
)
|
|
->where("t1.presupuesto_id", $presupuesto_id)
|
|
->whereIn('t1.tipo', ['lp_bn', 'lp_bnhq', 'lp_rot_bn']);
|
|
|
|
return $builder;
|
|
}
|
|
|
|
public function getResourceColorForPdf($presupuesto_id = -1)
|
|
{
|
|
$builder = $this->db
|
|
->table($this->table . " t1")
|
|
->select(
|
|
"t1.paginas AS paginas, t1.papel_impresion AS papel, t1.gramaje AS gramaje"
|
|
)
|
|
->where("t1.presupuesto_id", $presupuesto_id)
|
|
->whereIn('t1.tipo', ['lp_color', 'lp_colorhq', 'lp_rot_color']);
|
|
|
|
return $builder;
|
|
}
|
|
|
|
public function getResourceCubiertaForPdf($presupuesto_id = -1)
|
|
{
|
|
$builder = $this->db
|
|
->table($this->table . " t1")
|
|
->select(
|
|
"t1.paginas AS paginas, t1.papel_impresion AS papel, t1.gramaje AS gramaje"
|
|
)
|
|
->where("t1.presupuesto_id", $presupuesto_id)
|
|
->whereIn('t1.tipo', ['lp_cubierta']);
|
|
|
|
return $builder;
|
|
}
|
|
|
|
public function getResourceSobrecubiertaForPdf($presupuesto_id = -1)
|
|
{
|
|
$builder = $this->db
|
|
->table($this->table . " t1")
|
|
->select(
|
|
"t1.paginas AS paginas, t1.papel_impresion AS papel, t1.gramaje AS gramaje"
|
|
)
|
|
->where("t1.presupuesto_id", $presupuesto_id)
|
|
->whereIn('t1.tipo', ['lp_sobrecubierta']);
|
|
|
|
return $builder;
|
|
}
|
|
|
|
public function duplicateLineasPresupuesto($presupuesto_id, $new_presupuesto_id)
|
|
{
|
|
$lineas = $this->getLineasPresupuesto($presupuesto_id);
|
|
$lineas = json_decode(json_encode($lineas), true);
|
|
foreach ($lineas as $linea) {
|
|
$linea['presupuesto_id'] = $new_presupuesto_id;
|
|
unset($linea['id']);
|
|
$this->db
|
|
->table($this->table . " t1")
|
|
->insert($linea);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|