mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Merge branch 'main' into feat/sk-31
This commit is contained in:
@ -49,7 +49,8 @@ class FacturaLineaModel extends \App\Models\BaseModel {
|
||||
->join("albaranes t5", "t5.pedido_id = t2.pedido_id", "left")
|
||||
->join("albaranes_lineas t6", "t6.albaran_id = t5.id", "left")
|
||||
->where("t1.factura_id", $factura_id)
|
||||
->where("t1.deleted_at", null);
|
||||
->where("t1.deleted_at", null)
|
||||
->groupBy('t1.id');
|
||||
|
||||
return $builder;
|
||||
}
|
||||
|
||||
@ -2,7 +2,10 @@
|
||||
|
||||
namespace App\Models\Facturas;
|
||||
|
||||
class FacturaModel extends \App\Models\BaseModel {
|
||||
use CodeIgniter\Database\BaseBuilder;
|
||||
|
||||
class FacturaModel extends \App\Models\BaseModel
|
||||
{
|
||||
|
||||
protected $table = 'facturas';
|
||||
|
||||
@ -26,9 +29,11 @@ class FacturaModel extends \App\Models\BaseModel {
|
||||
const SORTABLE_PEDIDOS = [
|
||||
1 => "t1.numero",
|
||||
2 => "t2.nombre",
|
||||
3 => "t1.estado",
|
||||
4 => "t1.fecha_factura_at",
|
||||
5 => "t1.total",
|
||||
3 => "t4.cantidad",
|
||||
4 => "t2.nombre",
|
||||
5 => "t1.estado",
|
||||
6 => "t1.fecha_factura_at",
|
||||
7 => "t1.total",
|
||||
];
|
||||
|
||||
// Lista de columnas basada en los campos de la tabla, para asignación masiva
|
||||
@ -71,8 +76,8 @@ class FacturaModel extends \App\Models\BaseModel {
|
||||
protected $updatedField = "updated_at";
|
||||
|
||||
public static $labelField = "id";
|
||||
|
||||
public function getResource(string $search = "", $cliente_id=-1)
|
||||
|
||||
public function getResource(string $search = "", $cliente_id = -1)
|
||||
{
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
@ -88,16 +93,16 @@ class FacturaModel extends \App\Models\BaseModel {
|
||||
$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->where("t1.deleted_at IS NULL");
|
||||
if(auth()->user()->inGroup("cliente-admin") || auth()->user()->inGroup("cliente-editor")) {
|
||||
if (auth()->user()->inGroup("cliente-admin") || auth()->user()->inGroup("cliente-editor")) {
|
||||
$builder->where("t1.estado", "validada");
|
||||
}
|
||||
|
||||
if($cliente_id != -1) {
|
||||
if ($cliente_id != -1) {
|
||||
$builder->where("t1.cliente_id", $cliente_id);
|
||||
}
|
||||
|
||||
|
||||
$builder->groupBy("t1.id"); // Agrupa por id de la factura
|
||||
|
||||
return empty($search)
|
||||
@ -109,6 +114,37 @@ class FacturaModel extends \App\Models\BaseModel {
|
||||
->groupEnd();
|
||||
}
|
||||
|
||||
public function getDatatableQuery($cliente_id): BaseBuilder
|
||||
{
|
||||
$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,
|
||||
t2.nombre AS cliente, 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,
|
||||
GROUP_CONCAT(DISTINCT t4.nombre ORDER BY t4.nombre ASC SEPARATOR ', ') 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.vencimiento AS dias_vencimiento"
|
||||
);
|
||||
$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->where("t1.deleted_at", null);
|
||||
|
||||
if (auth()->user()->inGroup("cliente-admin") || auth()->user()->inGroup("cliente-editor")) {
|
||||
$builder->where("t1.estado", "validada");
|
||||
}
|
||||
|
||||
if ($cliente_id != -1) {
|
||||
$builder->where("t1.cliente_id", $cliente_id);
|
||||
}
|
||||
|
||||
$builder->groupBy("t1.id");
|
||||
//$query = $builder->getCompiledSelect();
|
||||
return $builder;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get resource data for creating PDFs.
|
||||
@ -151,6 +187,7 @@ class FacturaModel extends \App\Models\BaseModel {
|
||||
->table($this->table . " t1")
|
||||
->select(
|
||||
"t1.id AS id, t1.numero AS numero, t2.nombre AS serie, t1.estado AS estado,
|
||||
t4.cantidad AS ejemplares,
|
||||
DATE_FORMAT(t1.fecha_factura_at, '%d/%m/%Y') AS fecha_factura_at, t1.total AS total"
|
||||
);
|
||||
|
||||
@ -164,7 +201,7 @@ class FacturaModel extends \App\Models\BaseModel {
|
||||
$builder->where("t6.id", $pedido_id);
|
||||
|
||||
$builder->groupBy("t1.id"); // Agrupa por id de la factura
|
||||
|
||||
|
||||
return $builder;
|
||||
}
|
||||
|
||||
|
||||
@ -71,10 +71,41 @@ class PedidoModel extends \App\Models\BaseModel
|
||||
$builder->join("clientes t4", "t4.id = t3.cliente_id", "left");
|
||||
$builder->join("users t5", "t5.id = t4.comercial_id", "left");
|
||||
|
||||
$builder->where("t1.id", $pedido_id);
|
||||
|
||||
return $builder->get()->getResultObject();
|
||||
}
|
||||
|
||||
public function obtenerDatosForFactura($pedido_id = -1){
|
||||
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
->select("
|
||||
t3.cliente_id, t4.nombre as cliente_nombre, t4.cif as cliente_cif, t4.direccion as cliente_direccion,
|
||||
t5.nombre as cliente_pais, t4.cp as cliente_cp, t4.ciudad as cliente_ciudad, t6.nombre as cliente_provincia
|
||||
"
|
||||
)
|
||||
->join("pedidos_linea t2", "t2.pedido_id = t1.id", "left")
|
||||
->join("presupuestos t3", "t2.presupuesto_id = t3.id", "left")
|
||||
->join("clientes t4", "t4.id = t3.cliente_id", "left")
|
||||
->join("lg_paises t5", "t5.id = t4.pais_id", "left")
|
||||
->join("lg_provincias t6", "t6.id = t4.provincia_id", "left");
|
||||
|
||||
$builder->where("t1.id", $pedido_id);
|
||||
return $builder->get()->getResultObject();
|
||||
}
|
||||
|
||||
public function addFacturaPedidoLinea($pedido_id, $factura_id, $cantidad)
|
||||
{
|
||||
return $this->db
|
||||
->table("facturas_pedidos_lineas")
|
||||
->insert([
|
||||
"factura_id" => $factura_id,
|
||||
"pedido_id" => $pedido_id,
|
||||
"cantidad" => $cantidad
|
||||
]);
|
||||
}
|
||||
|
||||
public function obtenerLineasPedido($pedido_id)
|
||||
{
|
||||
$builder = $this->db
|
||||
@ -90,6 +121,7 @@ class PedidoModel extends \App\Models\BaseModel
|
||||
foreach ($builder->get()->getResultObject() as $row) {
|
||||
array_push($lineasPresupuesto, $model_presupuesto->generarLineaPedido($row->presupuesto_id)[0]);
|
||||
}
|
||||
$builder->groupBy("t1.id");
|
||||
|
||||
return $lineasPresupuesto;
|
||||
}
|
||||
|
||||
@ -404,9 +404,9 @@ class PresupuestoModel extends \App\Models\BaseModel
|
||||
$is_cosido = (new TipoPresupuestoModel())->get_isCosido($data['tipo_impresion_id']);
|
||||
|
||||
$totalCostes = $resumen_totales['totalPapel'] + $resumen_totales['totalImpresion'] +
|
||||
$resumen_totales['totalServicios'] + $resumen_totales['coste_envio'];
|
||||
$resumen_totales['totalServicios'] + $resumen_totales['envio_base_coste'];
|
||||
$totalMargenes = $resumen_totales['margenPapel'] + $resumen_totales['margenImpresion'] +
|
||||
$resumen_totales['margenServicios'] + $resumen_totales['margen_envio'];
|
||||
$resumen_totales['margenServicios'] + $resumen_totales['envio_base_margen'];
|
||||
|
||||
$fields = [
|
||||
'cliente_id' => $data['clienteId'],
|
||||
@ -486,9 +486,9 @@ class PresupuestoModel extends \App\Models\BaseModel
|
||||
'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' => $resumen_totales['precio_unidad'],
|
||||
'total_presupuesto' => round($totalCostes + $totalMargenes + $resumen_totales['coste_envio']+$resumen_totales['margen_envio'], 2),
|
||||
'total_aceptado' => round($totalCostes + $totalMargenes + $resumen_totales['coste_envio']+$resumen_totales['margen_envio'], 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),
|
||||
|
||||
Reference in New Issue
Block a user