Merge branch 'main' into dev/chat

This commit is contained in:
amazuecos
2024-09-07 20:30:51 +02:00
55 changed files with 2452 additions and 240 deletions

View File

@ -54,6 +54,76 @@ class FacturaLineaModel extends \App\Models\BaseModel {
return $builder;
}
public function getResourceResumenIVAsForPdf($factura_id = -1)
{
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.iva,
ROUND(SUM(t1.base), 2) AS base,
ROUND(SUM(t1.total_iva), 2) AS total_iva,
ROUND(SUM(t1.total), 2) AS total"
)
->where("t1.factura_id", $factura_id)
->where("t1.deleted_at", null)
->groupBy('t1.iva')
->orderBy('t1.iva', 'ASC'); // Ordena por iva en forma ascendente
return $builder;
}
/**
* Get resource data for creating PDFs.
*
* @param string $search
*
* @return \CodeIgniter\Database\BaseBuilder
*/
public function getResourceForPdf($factura_id = -1)
{
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.id AS id, t1.factura_id AS factura_id,
t1.pedido_linea_impresion_id AS pedido_linea_impresion_id, t1.pedido_maquetacion_id AS pedido_maquetacion_id,
t1.descripcion AS descripcion, t1.cantidad as cantidad, t1.precio_unidad AS precio_unidad, t1.iva AS iva,
t1.base AS base, t1.total_iva AS total_iva, t1.total AS total, t1.data AS data"
)
->where("t1.factura_id", $factura_id)
->where("t1.deleted_at", null);
return $builder;
}
/**
* Get resource data for creating PDFs.
*
* @param string $search
*
* @return \CodeIgniter\Database\BaseBuilder
*/
public function getResourceForExcel($factura_id = -1)
{
$builder = $this->db
->table($this->table . " t1")
->select(
"t2.numero AS ref_factura,
t3.pedido_id AS pedido_id,
t4.referencia_cliente AS referencia_cliente,
t1.base AS base"
)
->join("facturas t2", "t2.id = t1.factura_id", "left")
->join("pedidos_linea t3", "t3.id = t1.pedido_linea_impresion_id", "left")
->join("presupuestos t4", "t4.id = t3.presupuesto_id", "left")
->where("t1.factura_id", $factura_id)
->where("t1.deleted_at", null);
return $builder;
}
public function addFacturaPedidoLinea($factura_id, $pedido_linea_id, $cantidad)
{
$data = [

View File

@ -102,6 +102,41 @@ class FacturaModel extends \App\Models\BaseModel {
}
/**
* Get resource data for creating PDFs.
*
* @param string $search
*
* @return \CodeIgniter\Database\BaseBuilder
*/
public function getResourceForPdf($factura_id = -1)
{
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.id AS id, t1.numero AS numero, DATE_FORMAT(t1.fecha_factura_at, '%d/%m/%Y') AS fecha_factura_at,
t1.base AS base, t1.total AS total, t1.pendiente AS pendiente,
t1.creditoAsegurado AS creditoAsegurado, t1.estado AS estado, t1.estado_pago AS estado_pago,
t4.nombre AS forma_pago,
DATE_FORMAT(MIN(CASE WHEN t3.fecha_vencimiento_at != '0000-00-00 00:00:00' THEN t3.fecha_vencimiento_at ELSE NULL END), '%d/%m/%Y') AS vencimiento,
t2.nombre AS cliente, t2.direccion AS cliente_direccion, t2.ciudad AS cliente_ciudad,
t2.cp AS cliente_cp, t2.cif AS cliente_cif, t2.vencimiento AS dias_vencimiento, t2.ccc AS cliente_ccc,
t5.nombre AS cliente_pais"
);
$builder->join("clientes t2", "t2.id = t1.cliente_id", "left");
$builder->join("facturas_pagos t3", "t3.factura_id = t1.id", "left");
$builder->join("formas_pago t4", "t3.forma_pago_id = t4.id", "left");
$builder->join("lg_paises t5", "t2.pais_id = t5.id", "left");
$builder->where("t1.id", $factura_id);
$builder->where("t1.deleted_at IS NULL");
$builder->groupBy("t1.id"); // Agrupa por id de la factura
return $builder;
}
public function getResourcePedidos($pedido_id)
{
$builder = $this->db

View File

@ -216,5 +216,10 @@ class PedidoLineaModel extends \App\Models\BaseModel
return $resultaArray;
}
public function findByPresupuesto(int $presupuestoId){
$builder = $this->db
->table($this->table)
->select();
return $builder->where('presupuesto_id',$presupuestoId)->get()->getFirstRow();
}
}

View File

@ -2,6 +2,8 @@
namespace App\Models\Pedidos;
use function PHPSTORM_META\map;
class PedidoModel extends \App\Models\BaseModel
{
protected $table = "pedidos";
@ -29,11 +31,11 @@ class PedidoModel extends \App\Models\BaseModel
];
protected $allowedFields = [
"total_precio",
"total_tirada",
"estado",
"user_created_id",
"user_updated_id",
"total_precio",
"total_tirada",
"estado",
"user_created_id",
"user_updated_id",
"user_validated_id",
"fecha_entrega_real",
"fecha_impresion",
@ -53,22 +55,25 @@ class PedidoModel extends \App\Models\BaseModel
public static $labelField = "id";
public function obtenerDatosForm($pedido_id){
public function obtenerDatosForm($pedido_id)
{
$builder = $this->db
->table($this->table . " t1")
->select(
"t4.id AS cliente_id, t4.nombre AS cliente, CONCAT(t5.first_name, ' ', t5.last_name) AS comercial");
"t4.id AS cliente_id, t4.nombre AS cliente, CONCAT(t5.first_name, ' ', t5.last_name) AS comercial"
);
$builder->join("pedidos_linea t2", "t2.pedido_id = t1.id", "left");
$builder->join("presupuestos t3", "t2.presupuesto_id = t3.id", "left");
$builder->join("pedidos_linea t2", "t2.pedido_id = t1.id", "left");
$builder->join("presupuestos t3", "t2.presupuesto_id = t3.id", "left");
$builder->join("clientes t4", "t4.id = t3.cliente_id", "left");
$builder->join("users t5", "t5.id = t4.comercial_id", "left");
return $builder->get()->getResultObject();
}
public function obtenerLineasPedido($pedido_id){
public function obtenerLineasPedido($pedido_id)
{
$builder = $this->db
->table($this->table . " t1")
->select(
@ -79,10 +84,116 @@ class PedidoModel extends \App\Models\BaseModel
$model_presupuesto = model("App\Models\Presupuestos\PresupuestoModel");
$lineasPresupuesto = [];
foreach($builder->get()->getResultObject() as $row){
foreach ($builder->get()->getResultObject() as $row) {
array_push($lineasPresupuesto, $model_presupuesto->generarLineaPedido($row->presupuesto_id)[0]);
}
return $lineasPresupuesto;
}
}
public function getPedidoPresupuestoTipoImpresion(int $presupuesto_id) : array|object|null
{
$q = $this->db->table($this->table)
->select(
[
'tipos_presupuesto.codigo',
'presupuestos.solapas'
]
)
->join('tipos_presupuestos', 'tipos_presupuestos.id = presupuestos.tipo_impresion_id', 'left')
->where('presupuestos.id', $presupuesto_id);
return $q->get()->getFirstRow();
}
public function getPedidoClientePresupuesto(int $pedido_id)
{
$query = $this->db->table($this->table)
->select([
'pedidos.id as pedidoId',
'clientes.nombre as customerName',
'presupuestos.total_aceptado as totalAceptado',
'presupuestos.id as presupuestoId',
'presupuestos.cliente_id as presupuestoClienteId',
'presupuestos.margen',
'presupuestos.inc_rei',
'presupuestos.tirada',
'presupuestos.tirada',
'presupuestos.titulo',
'presupuestos.paginas',
'presupuestos.solapas',
'presupuestos.solapas_ancho',
'presupuestos.marcapaginas',
'presupuestos.comentarios_cliente',
'presupuestos.comentarios_safekat',
'presupuestos.papel_formato_personalizado',
'presupuestos.papel_formato_ancho as papelAnchoPersonalidado ',
'presupuestos.papel_formato_alto as papelAltoPersonalidado',
'tipos_presupuestos.codigo as codigoTipoImpresion',
'lg_papel_formato.ancho as lgPapelFormatoAncho ',
'lg_papel_formato.alto as lgPapelFormatoAlto',
])
->join('pedidos_linea', 'pedidos_linea.id = pedidos.id', 'left')
->join('presupuestos', 'presupuestos.id = pedidos_linea.presupuesto_id', 'left')
->join('presupuesto_ficheros', 'presupuesto_ficheros.presupuesto_id = presupuestos.id', 'left')
->join('tipos_presupuestos', 'tipos_presupuestos.id = presupuestos.tipo_impresion_id', 'left')
// ->join('presupuesto_linea','presupuestos.id = presupuesto_linea.presupuesto_id','left')
->join('clientes', 'clientes.id = presupuestos.cliente_id', 'left')
->join('lg_papel_formato', 'lg_papel_formato.id = presupuestos.papel_formato_id', 'left')
->where('pedidos.id', $pedido_id);
$cliente_presupuesto = $query->get()->getFirstRow();
return $cliente_presupuesto;
}
public function getPedidoPresupuestoLineas(int $pedido_id)
{
$query = $this->db->table($this->table)
->select([
'pedidos.id as pedidoId',
'presupuesto_linea.tipo',
'presupuesto_linea.paginas',
'presupuesto_linea.gramaje',
'lg_papel_generico.code as papelCode',
])
->join('pedidos_linea', 'pedidos_linea.id = pedidos.id', 'left')
->join('presupuestos', 'presupuestos.id = pedidos_linea.presupuesto_id', 'left')
->join('presupuesto_linea', 'presupuestos.id = presupuesto_linea.presupuesto_id', 'left')
->join('lg_papel_generico', 'lg_papel_generico.id = presupuesto_linea.papel_id', 'left')
->where('pedidos.id', $pedido_id);
$pedido_presupuesto_lineas = $query->get()->getResultObject();
return $pedido_presupuesto_lineas;
}
public function getPedidoPresupuestoDirecciones($pedido_id)
{
$query = $this->db->table($this->table)
->select([
'pedidos.id as pedidoId',
'presupuestos.id as presupuestoId',
'clientes.nombre as customerName',
'presupuesto_direcciones.*',
'lg_paises.code3 as paisCode3'
])
->join('pedidos_linea', 'pedidos_linea.id = pedidos.id', 'left')
->join('presupuestos', 'presupuestos.id = pedidos_linea.presupuesto_id', 'left')
->join('presupuesto_direcciones', 'presupuestos.id = presupuesto_direcciones.presupuesto_id', 'left')
->join('clientes', 'clientes.id = presupuestos.cliente_id', 'left')
->join('cliente_direcciones', 'clientes.id = cliente_direcciones.cliente_id', 'left')
->join('lg_paises', 'lg_paises.id = presupuesto_direcciones.pais_id', 'left')
->where('pedidos.id', $pedido_id);
$pedido_cliente_direcciones = $query->get()->getResultObject();
return $pedido_cliente_direcciones;
}
public function getPedidoPresupuestoFicheros($pedido_id)
{
$query = $this->db->table($this->table)
->select([
'presupuesto_ficheros.nombre as fileName',
'presupuesto_ficheros.file_path as filePath'
])
->join('pedidos_linea', 'pedidos_linea.id = pedidos.id', 'left')
->join('presupuestos', 'presupuestos.id = pedidos_linea.presupuesto_id', 'left')
->join('presupuesto_ficheros', 'presupuesto_ficheros.presupuesto_id = presupuestos.id', 'left')
->where('pedidos.id', $pedido_id);
$presupuesto_ficheros = $query->get()->getFirstRow();
return $presupuesto_ficheros;
}
}

View File

@ -17,11 +17,12 @@ class PresupuestoAcabadosModel extends \App\Models\BaseModel
const SORTABLE = [
0 => "t2.nombre",
1 => "t1.precio_unidad",
2 => "t1.precio_total"
1 => "t1.proveedor_id",
2 => "t1.precio_unidad",
3 => "t1.precio_total"
];
protected $allowedFields = ["presupuesto_id", "tarifa_acabado_id", "nombre", "precio_total", "precio_unidad", "margen", "cubierta", "sobrecubierta"];
protected $allowedFields = ["presupuesto_id", "tarifa_acabado_id", "proveedor_id", "nombre", "precio_total", "precio_unidad", "margen", "cubierta", "sobrecubierta"];
protected $returnType = "App\Entities\Presupuestos\PresupuestoAcabadosEntity";
protected $useTimestamps = true;
@ -46,10 +47,29 @@ class PresupuestoAcabadosModel extends \App\Models\BaseModel
],
];
public function getPrecioTarifa($tarifa_acabado_id, $tirada, $POD){
public function getProveedoresForSelector($tarifa_acabado_id, $tirada){
$proveedores = [];
$modelTarifa = model('App\Models\Tarifas\Acabados\TarifaAcabadoModel');
$tarifa_value = $modelTarifa->getTarifaPresupuestoAcabado($tarifa_acabado_id, $tirada);
if (count($tarifa_value)>0) {
foreach($tarifa_value as $tarifa)
array_push($proveedores,
(object)[
'id'=> $tarifa->proveedor_id,
'text'=> $tarifa->proveedor_nombre,
]);
}
return $proveedores;
}
public function getPrecioTarifa($tarifa_acabado_id, $tirada, $proveedor_id, $POD){
$modelTarifa = model('App\Models\Tarifas\Acabados\TarifaAcabadoModel');
$tarifa_value = $modelTarifa->getTarifaPresupuestoAcabado($tarifa_acabado_id, $tirada);
$tarifa_value = $modelTarifa->getTarifaPresupuestoAcabado($tarifa_acabado_id, $tirada, $proveedor_id);
if (count($tarifa_value)>0) {
$result_data = $this->calcularTarifa($tarifa_value[0], $tirada, $POD<$tirada?false:true);
@ -59,6 +79,8 @@ class PresupuestoAcabadosModel extends \App\Models\BaseModel
'precio_unidad'=> $result_data[0],
'total'=> $result_data[1],
'margen'=> $result_data[2],
'proveedor' => $tarifa_value[0]->proveedor_nombre,
'proveedor_id' => $tarifa_value[0]->proveedor_id,
];
return $ret_array;
}
@ -119,6 +141,8 @@ class PresupuestoAcabadosModel extends \App\Models\BaseModel
foreach($tarifas as $tarifa){
$proveedor = $tarifa->proveedor_id=='undefined'?'NULL':$tarifa->proveedor_id;
$builder = $this->db
->table($this->table . " t1");
$builder->select("id");
@ -132,6 +156,7 @@ class PresupuestoAcabadosModel extends \App\Models\BaseModel
->table($this->table . " t1")
->where('presupuesto_id', $presupuesto_id)
->where('tarifa_acabado_id', $tarifa->tarifa_id)
->set('proveedor_id', $proveedor)
->set('precio_unidad', $tarifa->precio_unidad)
->set('precio_total', $tarifa->precio_total)
->set('margen', $tarifa->margen)
@ -146,6 +171,7 @@ class PresupuestoAcabadosModel extends \App\Models\BaseModel
->table($this->table . " t1")
->set('presupuesto_id', $presupuesto_id)
->set('tarifa_acabado_id', $tarifa->tarifa_id)
->set('proveedor_id', $proveedor, false)
->set('precio_unidad', $tarifa->precio_unidad)
->set('precio_total', $tarifa->precio_total)
->set('margen', $tarifa->margen)
@ -169,11 +195,13 @@ class PresupuestoAcabadosModel extends \App\Models\BaseModel
->table($this->table . " t1")
->select(
"t1.id AS id, t1.tarifa_acabado_id AS tarifa_acabado_id, t1.precio_unidad AS precio_unidad,
t1.precio_total AS precio_total, t1.margen AS margen, t2.nombre AS nombre, t1.cubierta AS cubierta, t1.sobrecubierta AS sobrecubierta"
t1.precio_total AS precio_total, t1.margen AS margen, t2.nombre AS nombre, t1.cubierta AS cubierta, t1.sobrecubierta AS sobrecubierta,
t1.proveedor_id AS proveedor_id, t3.nombre AS proveedor,"
);
$builder->where('t1.presupuesto_id', $presupuesto_id);
$builder->join("lg_tarifa_acabado t2", "t1.tarifa_acabado_id = t2.id", "left");
$builder->join("lg_proveedores t3", "t1.proveedor_id = t3.id", "left");
return $builder;
}

View File

@ -21,7 +21,7 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel
4 => "t1.precio_total"
];
protected $allowedFields = ["presupuesto_id", "tarifa_encuadernado_id", "proveedor_id", "nombre", "precio_total", "precio_unidad", "tiempo", "margen"];
protected $allowedFields = ["presupuesto_id", "tarifa_encuadernado_id", "proveedor_id", "nombre", "precio_total", "precio_unidad", "paginas_por_cuadernillo", "tiempo", "margen"];
protected $returnType = "App\Entities\Presupuestos\PresupuestoEncuadernacionesEntity";
protected $useTimestamps = true;
@ -48,7 +48,7 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel
public function initPresupuesto($tipo_presupuesto, $solapas, $tirada, $paginas, $ancho, $alto, $POD){
public function initPresupuesto($tipo_presupuesto, $solapas, $tirada, $paginas, $ancho, $alto, $POD, $paginasCuadernillo = 32){
$model = model('App\Models\Presupuestos\TipoPresupuestoServiciosDefectoModel');
$tarifas_procesar = $model->get_tarifas($tipo_presupuesto, $solapas, "encuadernacion");
@ -60,7 +60,12 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel
if($modelTarifa->isTarifaPorHoras($tarifa['tarifa_id'])){
$tiempo = $this->calcularTiempo(16, $paginas, $tirada); // ID fija. Cambiar cuando se metan maquinas de corte. Velocidad en minutos
if($tarifa['tarifa_id'] == 2 || $tarifa['tarifa_id'] == 14){ // Rústica cosido hilo vegetal y Rústica cosido hilo vegetal solapas
$tiempo = $this->calcularTiempoCosido(16, $paginas, $tirada, $paginasCuadernillo); // ID fija. Cambiar cuando se metan maquinas de corte. Velocidad en minutos
}
else{
$tiempo = $this->calcularTiempo(16, $paginas, $tirada); // ID fija. Cambiar cuando se metan maquinas de corte. Velocidad en minutos
}
$tarifa_value = $modelTarifa->getTarifaPresupuestoEncuadernacionHoras($tarifa['tarifa_id'], $tiempo, $tirada);
if (count($tarifa_value)>0) {
@ -76,8 +81,7 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel
$result_data[1] = $precio_total;
$result_data[2] = $tarifa_proveedor->margen ; // margen
array_push($result_array,
(object)[
$datos = [
'tarifa_id'=> $tarifa['tarifa_id'],
'tarifa_nombre'=> $tarifa_proveedor->tarifa_enc_nombre,
'precio_unidad'=> $result_data[0],
@ -86,7 +90,14 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel
'margen' => $result_data[2],
'proveedor' => $tarifa_proveedor->proveedor_nombre,
'proveedor_id' => $tarifa_proveedor->proveedor_id,
]);
];
if($tarifa['tarifa_id'] == 2 || $tarifa['tarifa_id'] == 14){
$datos['paginas_por_cuadernillo'] = $paginasCuadernillo;
}
array_push($result_array,
(object)$datos);
}
usort($result_array, function($a, $b) {
@ -237,11 +248,16 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel
return [];
}
public function getPrecioTarifaHoras($tarifa_encuadernacion_id, $paginas, $tirada, $proveedor_id, $POD){
public function getPrecioTarifaHoras($tarifa_encuadernacion_id, $paginas, $tirada, $proveedor_id, $POD, $paginas_cuadernillo = null){
$modelTarifa = model('App\Models\Tarifas\TarifaEncuadernacionModel');
$tiempo = $this->calcularTiempo(16, $paginas, $tirada); // ID fija. Cambiar cuando se metan maquinas de corte. Velocidad en minutos
if($tarifa_encuadernacion_id == 2 || $tarifa_encuadernacion_id == 14){ // Rústica cosido hilo vegetal y Rústica cosido hilo vegetal solapas
$tiempo = $this->calcularTiempoCosido(16, $paginas, $tirada, $paginas_cuadernillo); // ID fija. Cambiar cuando se metan maquinas de corte. Velocidad en minutos
}
else{
$tiempo = $this->calcularTiempo(16, $paginas, $tirada); // ID fija. Cambiar cuando se metan maquinas de corte. Velocidad en minutos
}
$tarifa_value = $modelTarifa->getTarifaPresupuestoEncuadernacionHoras($tarifa_encuadernacion_id, $tiempo, $tirada, $proveedor_id);
if (count($tarifa_value)>0) {
@ -256,6 +272,7 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel
$result_data[0] = floatval($precio_total / $tirada); // Precio/unidad
$result_data[1] = $precio_total;
$result_data[2] = $tarifa_proveedor->margen ; // margen
array_push($ret_array,
(object)[
@ -263,6 +280,7 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel
'tarifa_nombre'=> $tarifa_proveedor->tarifa_enc_nombre,
'precio_unidad'=> $result_data[0],
'tiempo' => $tiempo,
'paginas_por_cuadernillo' => $paginas_cuadernillo,
'total'=> $result_data[1],
'margen' => $result_data[2],
'proveedor' => $tarifa_proveedor->proveedor_nombre,
@ -287,6 +305,7 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel
'proveedor' => lang('Presupuestos.no_disponible'),
'precio_unidad'=> 0,
'tiempo' => null,
'paginas_por_cuadernillo' => null,
'total'=> 0,
'margen' => 0,
];
@ -355,6 +374,7 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel
$builder->where('presupuesto_id', $presupuesto_id);
$builder->where('tarifa_encuadernado_id', $tarifa->tarifa_id);
$result = $builder->get()->getResultObject();
$paginas_cuadernillo = $tarifa->paginas_por_cuadernillo??null;
if(count($result)>0){
$this->db
->table($this->table . " t1")
@ -365,6 +385,7 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel
->set('tiempo', $tarifa->tiempo)
->set('precio_total', $tarifa->precio_total)
->set('margen', $tarifa->margen)
->set('paginas_por_cuadernillo', $paginas_cuadernillo)
->update();
@ -397,7 +418,8 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel
->table($this->table . " t1")
->select(
"t1.id AS id, t1.tarifa_encuadernado_id AS tarifa_encuadernado_id, t1.precio_unidad AS precio_unidad, t1.tiempo AS tiempo,
t1.precio_total AS precio_total, t1.margen AS margen, t2.nombre AS nombre, t1.proveedor_id AS proveedor_id, t3.nombre AS proveedor"
t1.precio_total AS precio_total, t1.margen AS margen, t2.nombre AS nombre, t1.proveedor_id AS proveedor_id, t3.nombre AS proveedor,
t1.paginas_por_cuadernillo AS paginas_por_cuadernillo"
);
$builder->where('t1.presupuesto_id', $presupuesto_id);
@ -415,4 +437,13 @@ class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel
$velocidad = $maquinaModel->getVelocidad($maquina_id);
return round($cuadernillos_pedido/($velocidad*60.0), 2);
}
private function calcularTiempoCosido($maquina_id, $paginas, $tirada, $cuadernillos_por_pagina = 32){
$maquinaModel = model("App\Models\Configuracion\MaquinaModel");
$velocidad = $maquinaModel->getVelocidad($maquina_id); // cuadernillos por minuto
$cuadernillos_libro = ceil($paginas/intval($cuadernillos_por_pagina));
$cuadernillos_pedido = $cuadernillos_libro*$tirada;
return round($cuadernillos_pedido/($velocidad*60.0), 2); // tiempo en segundos
}
}

View File

@ -162,7 +162,7 @@ class PresupuestoModel extends \App\Models\BaseModel
],
"pais_id" => [
"label" => "Presupuestos.paisId",
"rules" => "required|integer|greater_than[0]",
"rules" => "integer",
],
"cliente_id" => [
"label" => "Presupuestos.clienteId",
@ -326,7 +326,8 @@ class PresupuestoModel extends \App\Models\BaseModel
return $builder;
}
function getListaPresupuestosCliente($search = [] , $clienteId){
function getListaPresupuestosCliente($search = [], $clienteId)
{
$builder = $this->db
->table($this->table . " t1")
@ -343,7 +344,7 @@ class PresupuestoModel extends \App\Models\BaseModel
$builder->join("presupuesto_estados t6", "t1.estado_id = t6.id", "left");
$builder->join("tipos_presupuestos t7", "t1.tipo_impresion_id = t7.id", "left");
if($clienteId != 0)
if ($clienteId != 0)
$builder->where("t1.cliente_id", $clienteId);
$builder->where("t1.is_deleted", 0);
@ -363,7 +364,7 @@ class PresupuestoModel extends \App\Models\BaseModel
}
$builder->groupEnd();
return $builder;
}
}
}
function confirmarPresupuesto($presupuesto_id)
@ -377,16 +378,16 @@ class PresupuestoModel extends \App\Models\BaseModel
function insertarPresupuestoCliente($id, $tirada, $data, $data_cabecera, $extra_info, $resumen_totales, $iva_reducido, $excluir_rotativa, $tiradas_alternativas)
{
helper('date');
$model = model('App\Models\Configuracion\PapelFormatoModel');
$papel_formato_id = $model->where('ancho', $data['tamanio']['ancho'])->where('alto', $data['tamanio']['alto'])->first();
$is_cosido = (new TipoPresupuestoModel())->get_isCosido($data['tipo_impresion_id']);
$totalCostes = $resumen_totales['totalPapel'] + $resumen_totales['totalImpresion'] +
$resumen_totales['totalServicios']+$resumen_totales['coste_envio'];
$totalCostes = $resumen_totales['totalPapel'] + $resumen_totales['totalImpresion'] +
$resumen_totales['totalServicios'] + $resumen_totales['coste_envio'];
$totalMargenes = $resumen_totales['margenPapel'] + $resumen_totales['margenImpresion'] +
$resumen_totales['margenServicios'] + $resumen_totales['margen_envio'];
@ -400,22 +401,22 @@ class PresupuestoModel extends \App\Models\BaseModel
'faja_color' => in_array(16, $data['servicios']) ? 1 : 0,
'ferro' => in_array(24, $data['servicios']) ? 1 : 0,
'prototipo' => in_array(9, $data['servicios']) ? 1 : 0,
'papel_formato_id' => is_null($papel_formato_id) ? 0: $papel_formato_id->id,
'papel_formato_personalizado' => !$papel_formato_id ? 1:0,
'papel_formato_ancho' => !$papel_formato_id ? $data['tamanio']['ancho']:null,
'papel_formato_alto' => !$papel_formato_id ? $data['tamanio']['alto']:null,
'papel_formato_id' => is_null($papel_formato_id) ? 0 : $papel_formato_id->id,
'papel_formato_personalizado' => !$papel_formato_id ? 1 : 0,
'papel_formato_ancho' => !$papel_formato_id ? $data['tamanio']['ancho'] : null,
'papel_formato_alto' => !$papel_formato_id ? $data['tamanio']['alto'] : null,
'titulo' => $data_cabecera['titulo'],
'referencia_cliente' => $data_cabecera['referenciaCliente'],
'paginas' => $data['interior']['paginas'],
'tirada' => $tirada,
'solapas' => $data['cubierta']['solapasCubierta']>0 ? 1 : 0,
'solapas_ancho' => $data['cubierta']['solapasCubierta']>0 ? $data['cubierta']['solapasCubierta'] : 0,
'solapas_sobrecubierta' => is_null($data['sobrecubierta']) ? 0 :1,
'solapas' => $data['cubierta']['solapasCubierta'] > 0 ? 1 : 0,
'solapas_ancho' => $data['cubierta']['solapasCubierta'] > 0 ? $data['cubierta']['solapasCubierta'] : 0,
'solapas_sobrecubierta' => is_null($data['sobrecubierta']) ? 0 : 1,
'solapas_ancho_sobrecubierta' => is_null($data['sobrecubierta']) ? 0 : $data['sobrecubierta']['solapas'],
'cosido' => $is_cosido,
'merma' => $extra_info['merma'],
'merma_cubierta' => $extra_info['merma'],
'lomo_cubierta' => $extra_info['lomo_cubierta'],
'lomo_sobrecubierta' => $extra_info['lomo_sobrecubierta'],
@ -424,12 +425,12 @@ class PresupuestoModel extends \App\Models\BaseModel
'acabado_cubierta_id' => $data['acabadoCubierta'],
'acabado_sobrecubierta_id' => is_null($data['sobrecubierta']) ? 0 : $data['sobrecubierta']['acabado'],
'comp_tipo_impresion' => $data['isHq']? ($data['isColor']? 'colorhq':'negrohq'):($data['isColor']? 'color':'negro'),
'comp_tipo_impresion' => $data['isHq'] ? ($data['isColor'] ? 'colorhq' : 'negrohq') : ($data['isColor'] ? 'color' : 'negro'),
'user_created_id' => $extra_info['user_id'],
'created_at' => date('Y-m-d H:i:s', now()),
'updated_at' => date('Y-m-d H:i:s', now()),
'tirada_alternativa_json_data' => json_encode($tiradas_alternativas),
'total_coste_papel' => round($resumen_totales['totalPapel'], 2),
@ -445,32 +446,31 @@ class PresupuestoModel extends \App\Models\BaseModel
'total_margen_envios' => round($resumen_totales['margen_envio'], 2),
'total_costes' => round($totalCostes, 2),
'total_margenes' => round($totalMargenes, 2),
'total_antes_descuento' => round($totalCostes + $totalMargenes, 2),
'total_descuento' => 0,
'total_descuentoPercent' => 0,
'total_precio_unidad' => round(($totalCostes + $totalMargenes)/$tirada, 4),
'total_presupuesto' => round($totalCostes + $totalMargenes, 2),
'total_aceptado' => round($totalCostes + $totalMargenes, 2),
'total_precio_unidad' => round(($totalCostes + $totalMargenes) / $tirada, 4),
'total_presupuesto' => round($totalCostes + $totalMargenes, 2),
'total_aceptado' => round($totalCostes + $totalMargenes, 2),
'total_factor' => round(($totalCostes + $totalMargenes-$resumen_totales['coste_envio']-$resumen_totales['margen_envio'])/$resumen_totales['sumForFactor'], 2),
'total_factor_ponderado' => round(($totalCostes + $totalMargenes-$resumen_totales['coste_envio']-$resumen_totales['margen_envio'])/$resumen_totales['sumForFactorPonderado'], 2),
'total_factor' => round(($totalCostes + $totalMargenes - $resumen_totales['coste_envio'] - $resumen_totales['margen_envio']) / $resumen_totales['sumForFactor'], 2),
'total_factor_ponderado' => round(($totalCostes + $totalMargenes - $resumen_totales['coste_envio'] - $resumen_totales['margen_envio']) / $resumen_totales['sumForFactorPonderado'], 2),
'iva_reducido' => $iva_reducido,
'excluir_rotativa' => $excluir_rotativa,
];
if($id != 0){
if ($id != 0) {
$fields['id'] = $id;
$fields['updated_at'] = date('Y-m-d H:i:s', now());
}
if($id != 0){
if ($id != 0) {
$this->db->table($this->table)->where('id', $id)->update($fields);
return $id;
}
else{
} else {
$this->db->table($this->table)->insert($fields);
return $this->db->insertID();
}
@ -482,27 +482,27 @@ class PresupuestoModel extends \App\Models\BaseModel
if (is_array($data)) {
// -- INTERIOR --
// Si hay negro
if($data['interior']['paginas'] > $data['interior']['paginas_color']){
if ($data['interior']['paginas'] > $data['interior']['paginas_color']) {
if($data['isHq'])
if ($data['isHq'])
$key = 'bnhq';
else
$key = 'bn';
$values[$key] = array(
'paginas'=> intval($data['interior']['paginas'])-intval($data['interior']['paginas_color']),
'paginas' => intval($data['interior']['paginas']) - intval($data['interior']['paginas_color']),
'papel_id' => intval($data['interior']['papel_generico']['id']),
'gramaje' => intval($data['interior']['gramaje']),
);
}
// Si hay color
if($data['interior']['paginas_color']>0){
// Si hay color
if ($data['interior']['paginas_color'] > 0) {
if($data['isHq'])
if ($data['isHq'])
$key = 'colorhq';
else
$key = 'color';
$values[$key] = array(
'paginas'=> intval($data['interior']['paginas_color']),
'paginas' => intval($data['interior']['paginas_color']),
'papel_id' => intval($data['interior']['papel_generico']['id']),
'gramaje' => intval($data['interior']['gramaje']),
);
@ -516,7 +516,7 @@ class PresupuestoModel extends \App\Models\BaseModel
);
// -- SOBRECUBIERTA --
if(!is_null($data['sobrecubierta'])){
if (!is_null($data['sobrecubierta'])) {
$values['sobrecubierta'] = array(
'papel_id' => intval($data['sobrecubierta']['papel']),
'gramaje' => intval($data['sobrecubierta']['gramaje']),
@ -525,14 +525,13 @@ class PresupuestoModel extends \App\Models\BaseModel
}
// -- GUARDAS --
if($data['datos_guardas'] != 0){
if ($data['datos_guardas'] != 0) {
$values['guardas'] = array(
'papel_id' => intval($data['datos_guardas']['papel']),
'gramaje' => intval($data['datos_guardas']['gramaje']),
'paginas' => intval($data['datos_guardas']['caras']),
);
}
}
$json = json_encode($values);
return $json;
@ -557,32 +556,33 @@ class PresupuestoModel extends \App\Models\BaseModel
$builder->where("t1.is_deleted", 0);
$builder->where("t1.id", $presupuesto_id);
$presupuesto = $builder->get()->getResultObject();
if(count($presupuesto) > 0){
if (count($presupuesto) > 0) {
$modelLinea = model('App\Models\Presupuestos\PresupuestoLineaModel');
$lineas = $modelLinea->where('presupuesto_id', $presupuesto_id)->findAll();
$lineas = $modelLinea->where('presupuesto_id', $presupuesto_id)->findAll();
$presupuesto = $presupuesto[0];
// Libro
if($presupuesto->tipo < 10 || $presupuesto->tipo==20 || $presupuesto->tipo==21){
if($presupuesto->papel_formato_personalizado == 1){
$presupuesto->tamanio= $presupuesto->papel_formato_ancho . "x" . $presupuesto->papel_formato_alto;
if ($presupuesto->tipo < 10 || $presupuesto->tipo == 20 || $presupuesto->tipo == 21) {
if ($presupuesto->papel_formato_personalizado == 1) {
$presupuesto->tamanio = $presupuesto->papel_formato_ancho . "x" . $presupuesto->papel_formato_alto;
}
if($forFactura){
if ($forFactura) {
$presupuesto->concepto = sprintf(lang('Pedidos.lineasTemplates.pedido'), $pedido_id);
}
else{
} else {
$presupuesto->concepto = sprintf(lang('Pedidos.lineasTemplates.presupuesto'), $presupuesto->numero);
}
$presupuesto->concepto .= sprintf(lang('Pedidos.lineasTemplates.libro'),
$presupuesto->concepto .= sprintf(
lang('Pedidos.lineasTemplates.libro'),
$presupuesto->unidades,
$presupuesto->paginas,
$presupuesto->titulo,
$presupuesto->autor,
$presupuesto->isbn,
$presupuesto->tamanio);
$presupuesto->tamanio
);
$presupuesto->concepto .= $this->generarConceptoLineasPresupuestoLibro($lineas, $presupuesto);
$presupuesto = (object)[
@ -594,10 +594,67 @@ class PresupuestoModel extends \App\Models\BaseModel
}
return [$presupuesto];
}
}
public function getServiciosPresupuesto($presupuesto_id)
{
$queryAcabado = $this->db->table($this->table)
->select(
[
'lg_tarifa_acabado.id',
'lg_tarifa_acabado.nombre',
private function generarConceptoLineasPresupuestoLibro($lineas, $presupuesto){
]
)
->join('presupuesto_acabados', 'presupuesto_acabados.presupuesto_id = presupuestos.id', 'left')
->join('lg_tarifa_acabado', 'lg_tarifa_acabado.id = presupuesto_acabados.tarifa_acabado_id', 'left')
->where('presupuestos.id', $presupuesto_id);
$queryPreimpresion = $this->db->table($this->table)
->select(
[
'lg_tarifa_preimpresion.id',
'lg_tarifa_preimpresion.nombre',
'lg_tarifa_preimpresion.precio',
]
)
->join('presupuesto_preimpresiones', 'presupuesto_preimpresiones.presupuesto_id = presupuestos.id', 'left')
->join('lg_tarifa_preimpresion', 'lg_tarifa_preimpresion.id = presupuesto_preimpresiones.tarifa_preimpresion_id', 'left')
->where('presupuestos.id', $presupuesto_id);
$queryManipulado = $this->db->table($this->table)
->select(
[
'lg_tarifa_manipulado.id',
'lg_tarifa_manipulado.nombre',
]
)
->join('presupuesto_manipulados', 'presupuesto_manipulados.presupuesto_id = presupuestos.id', 'left')
->join('lg_tarifa_manipulado', 'lg_tarifa_manipulado.id = presupuesto_manipulados.tarifa_manipulado_id', 'left')
->where('presupuestos.id', $presupuesto_id);
$queryExtras = $this->db->table($this->table)
->select(
[
'lg_tarifa_preimpresion.id',
'lg_tarifa_preimpresion.nombre',
]
)
->join('presupuesto_serviciosExtra', 'presupuesto_serviciosExtra.presupuesto_id = presupuestos.id', 'left')
->join('lg_tarifa_preimpresion', 'lg_tarifa_preimpresion.id = presupuesto_serviciosExtra.tarifa_extra_id', 'left')
->where('presupuestos.id', $presupuesto_id);
$servicios['acabado'] = $queryAcabado->get()->getResultObject();
$servicios['manipulado'] = $queryManipulado->get()->getResultObject();
$servicios['preimpresion'] = $queryPreimpresion->get()->getResultObject();
$servicios['extra'] = $queryExtras->get()->getResultObject();
return $servicios;
}
private function generarConceptoLineasPresupuestoLibro($lineas, $presupuesto)
{
$model_papel = model('App\Models\Configuracion\PapelImpresionModel');
$description_interior = "";
@ -610,105 +667,118 @@ class PresupuestoModel extends \App\Models\BaseModel
$gramaje_negro = 0;
$gramaje_color = 0;
$lp_bn_lines = array_filter($lineas, function($linea) {
$lp_bn_lines = array_filter($lineas, function ($linea) {
return strpos($linea->tipo, 'lp_bn') === 0;
});
$lp_color_lines = array_filter($lineas, function($linea) {
$lp_color_lines = array_filter($lineas, function ($linea) {
return strpos($linea->tipo, 'lp_color') === 0;
});
$lp_rot_bn = array_filter($lineas, function($linea) {
$lp_rot_bn = array_filter($lineas, function ($linea) {
return strpos($linea->tipo, 'lp_rot_bn') === 0;
});
$lp_rot_color = array_filter($lineas, function($linea) {
$lp_rot_color = array_filter($lineas, function ($linea) {
return strpos($linea->tipo, 'lp_rot_color') === 0;
});
if(count($lp_bn_lines) > 0){
if (count($lp_bn_lines) > 0) {
$lp_bn_lines = array_values($lp_bn_lines)[0];
$paginas_negro = $lp_bn_lines->paginas;
$gramaje_negro = $lp_bn_lines->gramaje;
$papel_negro = $model_papel->where('id', $lp_bn_lines->papel_impresion_id)->first()->nombre;
$description_interior .= sprintf(lang('Pedidos.lineasTemplates.libro_linea_interior'),
$papel_negro = $model_papel->where('id', $lp_bn_lines->papel_impresion_id)->first()->nombre;
$description_interior .= sprintf(
lang('Pedidos.lineasTemplates.libro_linea_interior'),
strval($paginas_negro),
$papel_negro,
strval($gramaje_negro)) . ". ";
strval($gramaje_negro)
) . ". ";
}
if(count($lp_color_lines) > 0){
if (count($lp_color_lines) > 0) {
$lp_color_lines = array_values($lp_color_lines)[0];
$paginas_color = $lp_color_lines->paginas;
$gramaje_color = $lp_color_lines->gramaje;
$papel_color = $model_papel->where('id', $lp_color_lines->papel_impresion_id)->first()->nombre;
$description_interior .= sprintf(lang('Pedidos.lineasTemplates.libro_linea_interior'),
$papel_color = $model_papel->where('id', $lp_color_lines->papel_impresion_id)->first()->nombre;
$description_interior .= sprintf(
lang('Pedidos.lineasTemplates.libro_linea_interior'),
strval($paginas_color),
$papel_color,
strval($gramaje_color)) . ". ";
strval($gramaje_color)
) . ". ";
}
if(count($lp_rot_bn) > 0){
if (count($lp_rot_bn) > 0) {
$lp_rot_bn = array_values($lp_rot_bn)[0];
$paginas_negro = $lp_rot_bn->paginas;
$gramaje_negro = $lp_rot_bn->gramaje;
$papel_negro = $model_papel->where('id', $lp_rot_bn->papel_impresion_id)->first()->nombre;
$description_interior .= sprintf(lang('Pedidos.lineasTemplates.libro_linea_interior'),
$papel_negro = $model_papel->where('id', $lp_rot_bn->papel_impresion_id)->first()->nombre;
$description_interior .= sprintf(
lang('Pedidos.lineasTemplates.libro_linea_interior'),
strval($paginas_negro),
$papel_negro,
strval($gramaje_negro)) . ". ";
strval($gramaje_negro)
) . ". ";
}
if(count($lp_rot_color) > 0){
if (count($lp_rot_color) > 0) {
$lp_rot_color = array_values($lp_rot_color)[0];
$paginas_negro = intval($lp_rot_color->paginas)-intval($lp_rot_color->rotativa_pag_color);
$paginas_negro = intval($lp_rot_color->paginas) - intval($lp_rot_color->rotativa_pag_color);
$gramaje = $lp_rot_color->gramaje;
$papel = $model_papel->where('id', $lp_rot_color->papel_impresion_id)->first()->nombre;
if($paginas_negro > 0){
$description_interior .= sprintf(lang('Pedidos.lineasTemplates.libro_linea_interior'),
strval($paginas_negro),
$papel,
strval($gramaje)) . ". ";
$papel = $model_papel->where('id', $lp_rot_color->papel_impresion_id)->first()->nombre;
if ($paginas_negro > 0) {
$description_interior .= sprintf(
lang('Pedidos.lineasTemplates.libro_linea_interior'),
strval($paginas_negro),
$papel,
strval($gramaje)
) . ". ";
}
$description_interior .= sprintf(lang('Pedidos.lineasTemplates.libro_linea_interior'),
$description_interior .= sprintf(
lang('Pedidos.lineasTemplates.libro_linea_interior'),
strval($lp_rot_color->rotativa_pag_color),
$papel,
strval($gramaje)) . ". ";
strval($gramaje)
) . ". ";
}
$lp_cubierta = array_filter($lineas, function($linea) {
$lp_cubierta = array_filter($lineas, function ($linea) {
return strpos($linea->tipo, 'lp_cubierta') === 0;
});
$lp_sobrecubierta = array_filter($lineas, function($linea) {
$lp_sobrecubierta = array_filter($lineas, function ($linea) {
return strpos($linea->tipo, 'lp_sobrecubierta') === 0;
});
if(count($lp_cubierta) > 0){
if (count($lp_cubierta) > 0) {
$lp_cubierta = array_values($lp_cubierta)[0];
if($lp_cubierta->paginas == 2){
if ($lp_cubierta->paginas == 2) {
$lp_cubierta->caras = lang('Pedidos.unaCara');
}
else{
} else {
$lp_cubierta->caras = lang('Pedidos.dosCaras');
}
$description_cubierta = sprintf(lang('Pedidos.lineasTemplates.libro_linea_cubierta'),
$description_cubierta = sprintf(
lang('Pedidos.lineasTemplates.libro_linea_cubierta'),
$lp_cubierta->caras,
$model_papel->where('id', $lp_cubierta->papel_impresion_id)->first()->nombre,
strval($lp_cubierta->gramaje));
$description_cubierta .= ($presupuesto->solapas_cubierta==1? sprintf(lang('Pedidos.lineasTemplates.libro_solapas'), $presupuesto->solapas_ancho_cubierta):". ");
}
if(count($lp_sobrecubierta) > 0){
$model_papel->where('id', $lp_cubierta->papel_impresion_id)->first()->nombre,
strval($lp_cubierta->gramaje)
);
$description_cubierta .= ($presupuesto->solapas_cubierta == 1 ? sprintf(lang('Pedidos.lineasTemplates.libro_solapas'), $presupuesto->solapas_ancho_cubierta) : ". ");
}
if (count($lp_sobrecubierta) > 0) {
$lp_sobrecubierta = array_values($lp_sobrecubierta)[0];
$description_sobrecubierta = sprintf(lang('Pedidos.lineasTemplates.libro_linea_sobrecubierta'),
$model_papel->where('id', $lp_sobrecubierta->papel_impresion_id)->first()->nombre,
strval($lp_sobrecubierta->gramaje));
$description_sobrecubierta .= ($presupuesto->solapas_sobrecubierta==1? sprintf(lang('Pedidos.lineasTemplates.libro_solapas'), $presupuesto->solapas_ancho_sobrecubierta):". ");
}
$description_sobrecubierta = sprintf(
lang('Pedidos.lineasTemplates.libro_linea_sobrecubierta'),
$model_papel->where('id', $lp_sobrecubierta->papel_impresion_id)->first()->nombre,
strval($lp_sobrecubierta->gramaje)
);
$description_sobrecubierta .= ($presupuesto->solapas_sobrecubierta == 1 ? sprintf(lang('Pedidos.lineasTemplates.libro_solapas'), $presupuesto->solapas_ancho_sobrecubierta) : ". ");
}
$acabado = sprintf(lang('Pedidos.lineasTemplates.libro_encuadernacion'),
lang('Presupuestos.' . $presupuesto->codigo_encuadernacion));
return $description_interior. $description_cubierta . $description_sobrecubierta . $acabado;
$acabado = sprintf(
lang('Pedidos.lineasTemplates.libro_encuadernacion'),
lang('Presupuestos.' . $presupuesto->codigo_encuadernacion)
);
return $description_interior . $description_cubierta . $description_sobrecubierta . $acabado;
}
}

View File

@ -1,6 +1,9 @@
<?php
namespace App\Models\Tarifas\Acabados;
use function PHPUnit\Framework\isNan;
use function PHPUnit\Framework\isNull;
class TarifaAcabadoLineaModel extends \App\Models\BaseModel
{
protected $table = "tarifa_acabado_lineas";
@ -13,14 +16,16 @@ class TarifaAcabadoLineaModel extends \App\Models\BaseModel
protected $useAutoIncrement = true;
const SORTABLE = [
0 => "t1.tirada_min",
1 => "t1.tirada_max",
2 => "t1.precio_min",
3 => "t1.precio_max",
4 => "t1.margen",
0 => "t3.nombre",
1 => "t1.tirada_min",
2 => "t1.precio_max",
3 => "t1.tirada_max",
4 => "t1.precio_min",
5 => "t1.margen",
];
protected $allowedFields = [
"proveedor_id",
"tirada_min",
"tirada_max",
"precio_min",
@ -126,12 +131,12 @@ class TarifaAcabadoLineaModel extends \App\Models\BaseModel
*
* @return \CodeIgniter\Database\BaseBuilder
*/
public function getResource(string $search = "", $tarifa_acabado_id = -1)
public function getResource($search = [], $tarifa_acabado_id = -1)
{
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.id AS id, t1.tirada_min AS tirada_min, t1.tirada_max AS tirada_max, t1.precio_min AS precio_min, t1.precio_max AS precio_max, t1.margen AS margen, t2.id AS tarifa_acabado"
"t1.id AS id, t1.proveedor_id AS proveedor_id, t3.nombre AS proveedor_nombre, t1.tirada_min AS tirada_min, t1.tirada_max AS tirada_max, t1.precio_min AS precio_min, t1.precio_max AS precio_max, t1.margen AS margen, t2.id AS tarifa_acabado"
);
//JJO
@ -139,21 +144,66 @@ class TarifaAcabadoLineaModel extends \App\Models\BaseModel
$builder->where("t1.is_deleted", 0);
$builder->join("lg_tarifa_acabado t2", "t1.tarifa_acabado_id = t2.id", "left");
$builder->join("lg_proveedores t3", "t1.proveedor_id = t3.id", "left");
return empty($search)
? $builder
: $builder
->groupStart()
->like("t1.tirada_min", $search)
->orLike("t1.tirada_max", $search)
->orLike("t1.precio_min", $search)
->orLike("t1.precio_max", $search)
->orLike("t1.tirada_min", $search)
->orLike("t1.tirada_max", $search)
->orLike("t1.precio_min", $search)
->orLike("t1.precio_max", $search)
->groupEnd();
if (empty($search))
return $builder;
else {
$filterEnabled = 0;
foreach ($search as $col_search) {
if($col_search[0] != 0){
if(strlen($col_search[2]) > 1){
$values = explode(",",$col_search[2]);
$min_val = floatval($values[0]);
$max_val = floatval($values[1]);
if(!is_nan($min_val) && !is_null($min_val) && strlen($values[0]) > 0){
if($filterEnabled == 0){
$builder->groupStart();
$filterEnabled = 1;
}
$builder->where(self::SORTABLE[$col_search[0]] . " >=", $min_val);
}
if(!is_nan($max_val) && !is_null($max_val) && strlen($values[1]) > 0){
if($filterEnabled == 0){
$builder->groupStart();
$filterEnabled = 1;
}
$builder->where(self::SORTABLE[$col_search[0]] . " <", $max_val);
}
}
}
else{
if(strlen($col_search[2]) > 1){
$values = explode(",",$col_search[2]);
if(count($values) > 1){
foreach ($values as $value) {
if($filterEnabled == 0){
$builder->groupStart();
$filterEnabled = 1;
}
$builder->orWhere("t1.proveedor_id", $value);
}
}
else{
if($filterEnabled == 0){
$builder->groupStart();
$filterEnabled = 1;
}
$builder->where("t1.proveedor_id", $col_search[2]);
}
}
}
}
if($filterEnabled == 1){
$builder->groupEnd();
}
return $builder;
}
}
public function findLineasForTarifaAcabado(int $tarifaacabado_id){
@ -181,6 +231,7 @@ class TarifaAcabadoLineaModel extends \App\Models\BaseModel
->select("id, tirada_min, tirada_max")
->where("is_deleted", 0)
->where("tarifa_acabado_id", $id_tarifa_acabado)
->where("proveedor_id", $data["proveedor_id"])
->get()->getResultObject();

View File

@ -114,16 +114,17 @@ class TarifaAcabadoModel extends \App\Models\BaseModel
return $builder->orderBy("t1.nombre", "asc")->get()->getResultObject();
}
public function getTarifaPresupuestoAcabado($tarifa_id, $tirada){
public function getTarifaPresupuestoAcabado($tarifa_id, $tirada, $proveedor_id = -1){
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.id AS tarifa_acabado_id, t1.nombre AS tarifa_acabado_nombre, t1.precio_min AS tarifa_precio_min, t1.importe_fijo AS tarifa_importe_fijo,
t1.acabado_cubierta AS acabado_cubierta, t1.acabado_sobrecubierta AS acabado_sobrecubierta, t2.id AS tarifa_linea_id, t2.tirada_min AS tirada_min, t2.tirada_max AS tirada_max,
t2.precio_min AS precio_min, t2.precio_max AS precio_max, t2.margen AS margen"
t2.precio_min AS precio_min, t2.precio_max AS precio_max, t2.margen AS margen, t2.proveedor_id AS proveedor_id, t3.nombre AS proveedor_nombre"
)
->join("tarifa_acabado_lineas t2", "t1.id = t2.tarifa_acabado_id", "left")
->join("lg_proveedores t3", "t2.proveedor_id = t3.id", "left")
->where("t1.is_deleted", 0)
//->where("t1.mostrar_en_presupuesto", 1)
->where("t2.is_deleted", 0);
@ -132,6 +133,9 @@ class TarifaAcabadoModel extends \App\Models\BaseModel
$builder->where('t2.tirada_min <=', $tirada);
$builder->where('t2.tirada_max >=', $tirada);
if($proveedor_id != -1){
$builder->where('t2.proveedor_id', $proveedor_id);
}
return $builder->get()->getResultObject();
}