mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
348 lines
12 KiB
PHP
Executable File
348 lines
12 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Entities\Presupuestos;
|
|
|
|
use App\Entities\Clientes\ClienteEntity;
|
|
use App\Entities\Configuracion\PapelFormatoEntity;
|
|
use App\Entities\Configuracion\TipoPresupuestoEntity;
|
|
use App\Models\Clientes\ClienteModel;
|
|
use App\Models\Configuracion\PapelFormatoModel;
|
|
use App\Models\Configuracion\TipoPresupuestoModel;
|
|
use App\Models\Presupuestos\PresupuestoAcabadosModel;
|
|
use App\Models\Presupuestos\PresupuestoEncuadernacionesModel;
|
|
use App\Models\Presupuestos\PresupuestoFicheroModel;
|
|
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
|
|
{
|
|
protected $attributes = [
|
|
"id" => null,
|
|
"cliente_id" => null,
|
|
"user_created_id" => 1,
|
|
"user_update_id" => null,
|
|
"tipo_impresion_id" => null,
|
|
"tipologia_id" => null,
|
|
"catalogo_id" => null,
|
|
"pais_id" => 1,
|
|
"estado_id" => 1,
|
|
"inc_rei" => null,
|
|
"causa_cancelacion" => null,
|
|
"retractilado" => false,
|
|
"retractilado5" => false,
|
|
"guardas" => false,
|
|
"recoger_en_taller" => false,
|
|
"ferro" => false,
|
|
"ferro_digital" => false,
|
|
"marcapaginas" => false,
|
|
"prototipo" => false,
|
|
"papel_formato_id" => null,
|
|
"papel_formato_personalizado" => false,
|
|
"papel_formato_ancho" => null,
|
|
"papel_formato_alto" => null,
|
|
"titulo" => "",
|
|
"autor" => null,
|
|
"coleccion" => null,
|
|
"numero_edicion" => null,
|
|
"isbn" => null,
|
|
"referencia_cliente" => null,
|
|
"paginas" => null,
|
|
"tirada" => null,
|
|
"solapas" => false,
|
|
"solapas_ancho" => 0.0,
|
|
"solapas_sobrecubierta" => false,
|
|
"solapas_ancho_sobrecubierta" => 0.0,
|
|
"faja_color" => false,
|
|
"solapas_ancho_faja_color" => 0.0,
|
|
"alto_faja_color" => 0.0,
|
|
"cosido" => false,
|
|
"sobrecubiertas" => false,
|
|
"sobrecubiertas_ancho" => 0.0,
|
|
"merma" => null,
|
|
"merma_cubierta" => 6.0,
|
|
"comentarios_cliente" => null,
|
|
"comentarios_safekat" => null,
|
|
"comentarios_pdf" => null,
|
|
"comentarios_tarifa" => null,
|
|
"comentarios_produccion" => null,
|
|
"comentarios_presupuesto" => null,
|
|
"lomo_cubierta" => null,
|
|
"lomo_sobrecubierta" => null,
|
|
"total_presupuesto" => null,
|
|
"envios_recoge_cliente" => false,
|
|
"tirada_alternativa_json_data" => null,
|
|
"aprobado_user_id" => null,
|
|
"aprobado_at" => null,
|
|
"comparador_json_data" => null,
|
|
"is_deleted" => 0,
|
|
"deleted_at" => null,
|
|
"created_at" => null,
|
|
"updated_at" => null,
|
|
"comp_tipo_impresion" => null,
|
|
"pos_paginas_color" => null,
|
|
"total_coste_papel" => null,
|
|
"total_margen_papel" => null,
|
|
"total_margenPercent_papel" => null,
|
|
"total_coste_impresion" => null,
|
|
"total_margen_impresion" => null,
|
|
"total_margenPercent_impresion" => null,
|
|
"total_coste_servicios" => null,
|
|
"total_margen_servicios" => null,
|
|
"total_margenPercent_servicios" => null,
|
|
"total_coste_envios" => null,
|
|
"total_margen_envios" => null,
|
|
"total_costes" => null,
|
|
"total_margenes" => null,
|
|
"total_antes_descuento" => null,
|
|
"total_descuento" => null,
|
|
"total_descuentoPercent" => null,
|
|
"total_precio_unidad" => null,
|
|
"total_factor" => null,
|
|
"total_factor_ponderado" => null,
|
|
'total_aceptado' => null,
|
|
'total_aceptado_revisado' => null,
|
|
'iva_reducido' => null,
|
|
'excluir_rotativa' => null,
|
|
"acabado_cubierta_id" => null,
|
|
"acabado_sobrecubierta_id" => null,
|
|
"acabado_faja_id" => null,
|
|
"is_duplicado" => false,
|
|
'paginas_color_consecutivas' => null,
|
|
'papel_interior_diferente' => null,
|
|
'paginasCuadernillo' => null,
|
|
'lomo_redondo' => null,
|
|
'cabezada' => null,
|
|
'envio_base' => null,
|
|
'direcciones_fp_checks' => [
|
|
'addFP1isAddMain' => "false",
|
|
'addFP2isAddMain' => "false",
|
|
'addFP2isaddFP1' => "false"
|
|
],
|
|
|
|
];
|
|
protected $casts = [
|
|
"cliente_id" => "int",
|
|
"user_created_id" => "int",
|
|
"user_update_id" => "?int",
|
|
"tipo_impresion_id" => "?int",
|
|
"tipologia_id" => "?int",
|
|
"catalogo_id" => "?int",
|
|
"pais_id" => "int",
|
|
"estado_id" => "int",
|
|
"retractilado" => "boolean",
|
|
"retractilado5" => "boolean",
|
|
"guardas" => "boolean",
|
|
"recoger_en_taller" => "boolean",
|
|
"ferro" => "boolean",
|
|
"ferro_digital" => "boolean",
|
|
"marcapaginas" => "boolean",
|
|
"prototipo" => "boolean",
|
|
"papel_formato_id" => "int",
|
|
"papel_formato_personalizado" => "boolean",
|
|
"papel_formato_ancho" => "?float",
|
|
"papel_formato_alto" => "?float",
|
|
"paginas" => "int",
|
|
"tirada" => "int",
|
|
"solapas" => "boolean",
|
|
"solapas_ancho" => "float",
|
|
"solapas_sobrecubierta" => "boolean",
|
|
"solapas_ancho_sobrecubierta" => "float",
|
|
"faja_color" => "boolean",
|
|
"solapas_ancho_faja_color" => "float",
|
|
"alto_faja_color" => "float",
|
|
"cosido" => "boolean",
|
|
"sobrecubiertas" => "boolean",
|
|
"sobrecubiertas_ancho" => "float",
|
|
"merma" => "float",
|
|
"merma_cubierta" => "float",
|
|
"lomo_cubierta" => "?float",
|
|
"lomo_sobrecubierta" => "?float",
|
|
"envios_recoge_cliente" => "boolean",
|
|
"aprobado_user_id" => "?int",
|
|
"is_deleted" => "int",
|
|
"total_coste_papel" => "?float",
|
|
"total_margen_papel" => "?float",
|
|
"total_margenPercent_papel" => "?float",
|
|
"total_coste_impresion" => "?float",
|
|
"total_margen_impresion" => "?float",
|
|
"total_margenPercent_impresion" => "?float",
|
|
"total_coste_servicios" => "?float",
|
|
"total_margen_servicios" => "?float",
|
|
"total_margenPercent_servicios" => "?float",
|
|
"total_coste_envios" => "?float",
|
|
"total_margen_envios" => "?float",
|
|
"total_costes" => "?float",
|
|
"total_margenes" => "?float",
|
|
"total_antes_descuento" => "?float",
|
|
"total_descuento" => "?float",
|
|
"total_descuentoPercent" => "?float",
|
|
"total_presupuesto" => "?float",
|
|
"total_precio_unidad" => "?float",
|
|
"total_factor" => "?float",
|
|
"total_factor_ponderado" => "?float",
|
|
'total_aceptado' => "?float",
|
|
'total_aceptado_revisado' => "?float",
|
|
'iva_reducido' => "?boolean",
|
|
'excluir_rotativa' => "?boolean",
|
|
"acabado_cubierta_id" => "int",
|
|
"acabado_sobrecubierta_id" => "int",
|
|
"acabado_faja_id" => "int",
|
|
"is_duplicado" => "boolean",
|
|
'paginas_color_consecutivas' => "boolean",
|
|
'papel_interior_diferente' => "boolean",
|
|
'paginasCuadernillo' => "int",
|
|
'lomo_redondo' => "boolean",
|
|
'direcciones_fp_checks' => 'json',
|
|
];
|
|
/**
|
|
* Devuelve la entity con un campo `presupuesto_lineas` con las lineas de presupuesto asociadas
|
|
*
|
|
* @return this
|
|
*/
|
|
public function withPresupuestoLineas()
|
|
{
|
|
$this->attributes["presupuesto_lineas"] = $this->presupuestoLineas();
|
|
return $this;
|
|
}
|
|
/**
|
|
* Obtiene las lineas de presupuesto del actual presupuesto
|
|
*
|
|
* @return array<PresupuestoLineaEntity>
|
|
*/
|
|
public function presupuestoLineas(): array
|
|
{
|
|
$model = model(PresupuestoLineaModel::class);
|
|
|
|
$q = $model->where('presupuesto_id', $this->attributes["id"])->findAll();
|
|
|
|
return $q ?? [];
|
|
}
|
|
/**
|
|
* Obtiene las lineas de presupuesto del actual presupuesto
|
|
*
|
|
* @return ?PresupuestoLineaEntity
|
|
*/
|
|
public function presupuestoLineaImpresion(): ?PresupuestoLineaEntity
|
|
{
|
|
$model = model(PresupuestoLineaModel::class);
|
|
|
|
$q = $model->where('presupuesto_id', $this->attributes["id"])->whereIn("tipo", ["lp_rot_bn", "lp_rot_color", "lp_color", "lp_colorhq", "lp_bn", "lp_bnhq"])->first();
|
|
|
|
return $q;
|
|
}
|
|
/**
|
|
* Obtiene las lineas de presupuesto del actual presupuesto
|
|
*
|
|
* @return PresupuestoLineaEntity
|
|
*/
|
|
public function presupuestoLineaCubierta(): ?PresupuestoLineaEntity
|
|
{
|
|
$model = model(PresupuestoLineaModel::class);
|
|
|
|
$q = $model->where('presupuesto_id', $this->attributes["id"])->whereIn("tipo", ["lp_cubierta"])->first();
|
|
|
|
return $q;
|
|
}
|
|
/**
|
|
* Obtiene las lineas de presupuesto del actual presupuesto
|
|
*
|
|
* @return PresupuestoLineaEntity
|
|
*/
|
|
public function presupuestoLineaSobreCubierta(): ?PresupuestoLineaEntity
|
|
{
|
|
$model = model(PresupuestoLineaModel::class);
|
|
|
|
$q = $model->where('presupuesto_id', $this->attributes["id"])->whereIn("tipo", ["lp_sobrecubierta"])->first();
|
|
|
|
return $q;
|
|
}
|
|
public function presupuestoLineaGuarda(): ?PresupuestoLineaEntity
|
|
{
|
|
$model = model(PresupuestoLineaModel::class);
|
|
|
|
$q = $model->where('presupuesto_id', $this->attributes["id"])->whereIn("tipo", ["lp_guardas"])->first();
|
|
|
|
return $q;
|
|
}
|
|
public function hasSobrecubierta(): bool
|
|
{
|
|
$hasSobrecubierta = false;
|
|
$model = model(PresupuestoLineaModel::class);
|
|
$q = $model->where('presupuesto_id', $this->attributes["id"])->whereIn("tipo", ["lp_sobrecubierta"])->countAllResults();
|
|
if ($q > 0) {
|
|
$hasSobrecubierta = true;
|
|
}
|
|
return $hasSobrecubierta;
|
|
}
|
|
public function cliente(): ?ClienteEntity
|
|
{
|
|
$m = model(ClienteModel::class);
|
|
if ($this->attributes['cliente_id']) {
|
|
|
|
return $m->find($this->attributes["cliente_id"]);
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
public function encuadernaciones(): array
|
|
{
|
|
$m = model(PresupuestoEncuadernacionesModel::class);
|
|
return $m->where("presupuesto_id", $this->attributes["id"])->findAll();
|
|
}
|
|
public function acabados(): array
|
|
{
|
|
$m = model(PresupuestoAcabadosModel::class);
|
|
return $m->where("presupuesto_id", $this->attributes["id"])->findAll();
|
|
}
|
|
public function preimpresiones(): array
|
|
{
|
|
$m = model(PresupuestoPreimpresionesModel::class);
|
|
return $m->where("presupuesto_id", $this->attributes["id"])->findAll();
|
|
}
|
|
public function manipulados(): array
|
|
{
|
|
$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();
|
|
}
|
|
public function papel_formato(): PapelFormatoEntity
|
|
{
|
|
$m = model(PapelFormatoModel::class);
|
|
return $m->find($this->attributes["papel_formato_id"]);
|
|
}
|
|
public function files(): array
|
|
{
|
|
$m = model(PresupuestoFicheroModel::class);
|
|
$files = $m->where('presupuesto_id', $this->attributes['id'])->findAll();
|
|
return $files ?? [];
|
|
}
|
|
public function tipo_presupuesto(): ?TipoPresupuestoEntity
|
|
{
|
|
$tipo_presupuesto = null;
|
|
$m = model(TipoPresupuestoModel::class);
|
|
if ($this->attributes["tipo_impresion_id"]) {
|
|
$tipo_presupuesto = $m->find($this->attributes['tipo_impresion_id']);
|
|
}
|
|
return $tipo_presupuesto;
|
|
}
|
|
|
|
public function getDireccionFPChecks()
|
|
{
|
|
return $this->attributes['direcciones_fp_checks'] ?? [];
|
|
}
|
|
|
|
public function setDireccionFPChecks($value)
|
|
{
|
|
$this->attributes['direcciones_fp_checks'] = is_array($value) ? json_encode($value) : $value;
|
|
return $this;
|
|
}
|
|
}
|