mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Merge branch 'main' into 'dev/chat'
Main See merge request jjimenez/safekat!296
This commit is contained in:
@ -315,4 +315,21 @@ class ClienteModel extends \App\Models\BaseModel
|
||||
public function creditoDisponible($cliente_id){
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getClienteDataFacturas($cliente_id){
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
->select(
|
||||
"
|
||||
t1.nombre AS cliente_nombre, t1.direccion AS cliente_address, t1.cif AS cliente_cif,
|
||||
t2.nombre AS cliente_pais, t1.cp AS cliente_cp, t1.ciudad AS cliente_ciudad,
|
||||
t3.nombre AS cliente_provincia, t1.credito_asegurado AS creditoAsegurado"
|
||||
)
|
||||
->where("t1.is_deleted", 0)
|
||||
->where("t1.id", $cliente_id);
|
||||
$builder->join("lg_paises t2", "t1.pais_id = t2.id", "left");
|
||||
$builder->join("lg_provincias t3", "t1.provincia_id = t3.id", "left");
|
||||
|
||||
return $builder->get()->getResultArray();
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ namespace App\Models\Configuracion;
|
||||
|
||||
class FormaPagoModel extends \App\Models\BaseModel
|
||||
{
|
||||
protected $table = "lg_formas_pago";
|
||||
protected $table = "formas_pago";
|
||||
|
||||
/**
|
||||
* Whether primary key uses auto increment.
|
||||
@ -38,6 +38,18 @@ class FormaPagoModel extends \App\Models\BaseModel
|
||||
],
|
||||
];
|
||||
|
||||
public function getMenuItems(){
|
||||
$items = $this->findAll();
|
||||
$menuItems = [];
|
||||
foreach ($items as $item) {
|
||||
$menuItems[] = [
|
||||
"value" => $item->id,
|
||||
"label" => $item->nombre,
|
||||
];
|
||||
}
|
||||
return $menuItems;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get resource data.
|
||||
*
|
||||
|
||||
@ -91,4 +91,36 @@ class SeriesFacturasModel extends \App\Models\BaseModel
|
||||
->orLike("t1.grupo", $search)
|
||||
->groupEnd();
|
||||
}
|
||||
|
||||
public function getMenuItemsFacturas(){
|
||||
|
||||
$resultSorting = $this->getPrimaryKeyName();
|
||||
|
||||
$id = 'id AS id';
|
||||
$text = 'nombre AS text';
|
||||
|
||||
$queryBuilder = $this->db->table($this->table);
|
||||
$queryBuilder->select([$id, $text]);
|
||||
$queryBuilder->where('tipo', 'facturacion');
|
||||
$queryBuilder->where('grupo', '1');
|
||||
$queryBuilder->orderBy($resultSorting);
|
||||
$result = $queryBuilder->get()->getResult();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getSerieNumerada($id)
|
||||
{
|
||||
$number = $this->db->table($this->table)
|
||||
->select("next, formato")
|
||||
->where("id", $id)
|
||||
->get()->getFirstRow();
|
||||
|
||||
$this->db->table($this->table)
|
||||
->where("id", $id)
|
||||
->set("next", $number->next + 1, false)
|
||||
->update();
|
||||
|
||||
return str_replace("{number}", $number->next, $number->formato);
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ class FacturaLineaModel extends \App\Models\BaseModel {
|
||||
// Lista de columnas basada en los campos de la tabla, para asignación masiva
|
||||
protected $allowedFields = [
|
||||
'factura_id',
|
||||
'pedido_impresion_id',
|
||||
'pedido_linea_impresion_id',
|
||||
'pedido_maquetacion_id',
|
||||
'descripcion',
|
||||
'cantidad',
|
||||
@ -21,7 +21,7 @@ class FacturaLineaModel extends \App\Models\BaseModel {
|
||||
'total',
|
||||
'data',
|
||||
'deleted_at',
|
||||
'user_update_id'
|
||||
'user_updated_id'
|
||||
];
|
||||
|
||||
protected $returnType = "App\Entities\Facturas\FacturaLineaEntity";
|
||||
@ -30,4 +30,68 @@ class FacturaLineaModel extends \App\Models\BaseModel {
|
||||
protected $useSoftDeletes = true;
|
||||
|
||||
public static $labelField = "id";
|
||||
|
||||
public function getResource($factura_id)
|
||||
{
|
||||
$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, t2.pedido_id AS pedido_id,
|
||||
t3.total_aceptado AS total_aceptado"
|
||||
)
|
||||
->join("pedidos_linea t2", "t2.id = t1.pedido_linea_impresion_id", "left")
|
||||
->join("presupuestos t3", "t3.id = t2.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 = [
|
||||
"factura_id" => $factura_id,
|
||||
"pedido_linea_id" => $pedido_linea_id,
|
||||
"cantidad" => $cantidad
|
||||
];
|
||||
|
||||
return $this->db->table("facturas_pedidos_lineas")->insert($data);
|
||||
}
|
||||
|
||||
public function deleteFacturasLineasPedido($factura_id, $pedido_linea_id, $cantidad){
|
||||
|
||||
$this->db->table("facturas_pedidos_lineas")
|
||||
->where("factura_id", $factura_id)
|
||||
->where("pedido_linea_id", $pedido_linea_id)
|
||||
->where("cantidad", $cantidad)
|
||||
->delete();
|
||||
}
|
||||
|
||||
public function updateFacturaPedidoLinea($factura_id, $pedido_linea_id, $cantidad, $cantidad_new)
|
||||
{
|
||||
// Obtener la ID del registro que queremos actualizar
|
||||
$record = $this->db->table("facturas_pedidos_lineas")
|
||||
->select('id')
|
||||
->where("factura_id", $factura_id)
|
||||
->where("pedido_linea_id", $pedido_linea_id)
|
||||
->where("cantidad", $cantidad)
|
||||
->limit(1)
|
||||
->get()
|
||||
->getRow();
|
||||
|
||||
// Si existe el registro
|
||||
if ($record) {
|
||||
$data = [
|
||||
"cantidad" => $cantidad_new
|
||||
];
|
||||
|
||||
// Actualizar el registro especificado por su ID
|
||||
$this->db->table("facturas_pedidos_lineas")
|
||||
->where("id", $record->id)
|
||||
->update($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -23,12 +23,20 @@ class FacturaModel extends \App\Models\BaseModel {
|
||||
11 => "DAFEDIFF(days, NOW(), t3.fecha_vencimiento_at)",
|
||||
];
|
||||
|
||||
const SORTABLE_PEDIDOS = [
|
||||
1 => "t1.numero",
|
||||
2 => "t2.nombre",
|
||||
3 => "t1.estado",
|
||||
4 => "t1.fecha_factura_at",
|
||||
5 => "t1.total",
|
||||
];
|
||||
|
||||
// Lista de columnas basada en los campos de la tabla, para asignación masiva
|
||||
protected $allowedFields = [
|
||||
'pedido_id',
|
||||
'factura_retificada_id',
|
||||
'factura_retificativa_id',
|
||||
'customer_id',
|
||||
'factura_rectificada_id',
|
||||
'factura_rectificativa_id',
|
||||
'cliente_id',
|
||||
'serie_id',
|
||||
'numero',
|
||||
'estado',
|
||||
@ -40,18 +48,18 @@ class FacturaModel extends \App\Models\BaseModel {
|
||||
'pendiente',
|
||||
'total_pagos',
|
||||
'creditoAsegurado',
|
||||
'customer_nombre',
|
||||
'customer_address',
|
||||
'customer_cif',
|
||||
'customer_pais',
|
||||
'customer_cp',
|
||||
'customer_ciudad',
|
||||
'customer_provincia',
|
||||
'cliente_nombre',
|
||||
'cliente_address',
|
||||
'cliente_cif',
|
||||
'cliente_pais',
|
||||
'cliente_cp',
|
||||
'cliente_ciudad',
|
||||
'cliente_provincia',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
'user_created_id',
|
||||
'user_update_id'
|
||||
'user_updated_id'
|
||||
];
|
||||
|
||||
protected $returnType = "App\Entities\Facturas\FacturaEntity";
|
||||
@ -69,16 +77,20 @@ class FacturaModel extends \App\Models\BaseModel {
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
->select(
|
||||
"t1.id AS id, t1.numero AS numero, t1.fecha_factura_at AS fecha_factura_at,
|
||||
"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,
|
||||
t4.nombre AS forma_pago, t3.fecha_vencimiento_at AS venciemento"
|
||||
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 IS NULL");
|
||||
$builder->groupBy("t1.id"); // Agrupa por id de la factura
|
||||
|
||||
return empty($search)
|
||||
? $builder
|
||||
@ -88,4 +100,48 @@ class FacturaModel extends \App\Models\BaseModel {
|
||||
->orLike("t1.id", $search)
|
||||
->groupEnd();
|
||||
}
|
||||
|
||||
|
||||
public function getResourcePedidos($pedido_id)
|
||||
{
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
->select(
|
||||
"t1.id AS id, t1.numero AS numero, t2.nombre AS serie, t1.estado AS estado,
|
||||
DATE_FORMAT(t1.fecha_factura_at, '%d/%m/%Y') AS fecha_factura_at, t1.total AS total"
|
||||
);
|
||||
|
||||
$builder->join("series t2", "t2.id = t1.serie_id", "left");
|
||||
$builder->join("facturas_lineas t3", "t1.id = t3.factura_id", "left");
|
||||
$builder->join("facturas_pedidos_lineas t4", "t1.id = t4.factura_id", "left");
|
||||
$builder->join("pedidos_linea t5", "t4.pedido_linea_id = t5.id", "left");
|
||||
$builder->join("pedidos t6", "t5.pedido_id = t6.id", "left");
|
||||
|
||||
$builder->where("t1.deleted_at IS NULL");
|
||||
$builder->where("t6.id", $pedido_id);
|
||||
|
||||
$builder->groupBy("t1.id"); // Agrupa por id de la factura
|
||||
|
||||
return $builder;
|
||||
}
|
||||
|
||||
public function getCantidadLineaPedidoFacturada($linea_pedido_id)
|
||||
{
|
||||
$builder = $this->db
|
||||
->table("facturas_pedidos_lineas t1")
|
||||
->select("SUM(t1.cantidad) AS cantidad")
|
||||
->where("t1.pedido_linea_id", $linea_pedido_id);
|
||||
|
||||
return $builder->get()->getRow()->cantidad;
|
||||
}
|
||||
|
||||
public function deleteFacturasLineasPedido($factura_id, $pedido_linea_id, $cantidad)
|
||||
{
|
||||
$this->db->table("facturas_pedidos_lineas")
|
||||
->where("factura_id", $factura_id)
|
||||
->where("pedido_linea_id", $pedido_linea_id)
|
||||
->where("cantidad", $cantidad)
|
||||
->delete();
|
||||
}
|
||||
|
||||
}
|
||||
@ -14,7 +14,7 @@ class FacturaPagoModel extends \App\Models\BaseModel {
|
||||
'forma_pago_id',
|
||||
'total',
|
||||
'deleted_at',
|
||||
'user_update_id'
|
||||
'user_updated_id'
|
||||
];
|
||||
|
||||
protected $returnType = "App\Entities\Facturas\FacturaPagoEntity";
|
||||
@ -23,4 +23,20 @@ class FacturaPagoModel extends \App\Models\BaseModel {
|
||||
protected $useSoftDeletes = true;
|
||||
|
||||
public static $labelField = "id";
|
||||
|
||||
public function getResource($factura_id)
|
||||
{
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
->select(
|
||||
"t1.id AS id, t1.factura_id AS factura_id,
|
||||
t1.notes AS notes, t1.fecha_pago_at AS fecha_pago_at, t1.fecha_vencimiento_at AS fecha_vencimiento_at,
|
||||
t1.forma_pago_id AS forma_pago_id, t2.nombre as forma_pago, t1.total AS total"
|
||||
)
|
||||
->join("formas_pago t2", "t2.id = t1.forma_pago_id", "left")
|
||||
->where("t1.factura_id", $factura_id)
|
||||
->where("t1.deleted_at", null);
|
||||
|
||||
return $builder;
|
||||
}
|
||||
}
|
||||
@ -76,4 +76,41 @@ class PedidoLineaModel extends \App\Models\BaseModel
|
||||
->orLike("t1.id", $search)
|
||||
->groupEnd();
|
||||
}
|
||||
|
||||
|
||||
public function obtenerLineasPedidoSinFacturar($cliente_id) {
|
||||
$resultaArray = [];
|
||||
|
||||
$subquery = $this->db
|
||||
->table('facturas_pedidos_lineas')
|
||||
->select('pedido_linea_id, SUM(cantidad) AS total_cantidad')
|
||||
->groupBy('pedido_linea_id')
|
||||
->getCompiledSelect();
|
||||
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
->select("t1.id AS id, t1.pedido_id AS pedido_id, t3.titulo AS titulo, t4.codigo AS tipo_impresion")
|
||||
->join("pedidos t2", "t2.id = t1.pedido_id", "left")
|
||||
->join("presupuestos t3", "t3.id = t1.presupuesto_id", "left")
|
||||
->join("tipos_presupuestos t4", "t4.id = t3.tipo_impresion_id", "left")
|
||||
->join("($subquery) fpl", "fpl.pedido_linea_id = t1.id", "left")
|
||||
->where("t3.cliente_id", $cliente_id)
|
||||
->where("t2.estado", "finalizado")
|
||||
->where("(t3.tirada > IFNULL(fpl.total_cantidad, 0))");
|
||||
|
||||
// Ejecutar la consulta y devolver resultados
|
||||
$query = $builder->get();
|
||||
$data = $query->getResult();
|
||||
|
||||
foreach($data as $register) {
|
||||
$item = (object)[
|
||||
'id' => $register->id,
|
||||
'text' => '['. lang('Pedidos.pedido') . ' ' . $register->pedido_id . '] ' . $register->titulo . ' - ' . lang('Presupuestos.' . $register->tipo_impresion),
|
||||
];
|
||||
array_push($resultaArray, $item);
|
||||
}
|
||||
|
||||
return $resultaArray;
|
||||
}
|
||||
|
||||
}
|
||||
@ -142,7 +142,7 @@ class PresupuestoModel extends \App\Models\BaseModel
|
||||
],
|
||||
"titulo" => [
|
||||
"label" => "Presupuestos.titulo",
|
||||
"rules" => "trim|required|max_length[30]",
|
||||
"rules" => "trim|required|max_length[300]",
|
||||
],
|
||||
"inc_rei" => [
|
||||
"label" => "Presupuestos.incRei",
|
||||
@ -538,7 +538,7 @@ class PresupuestoModel extends \App\Models\BaseModel
|
||||
return $json;
|
||||
}
|
||||
|
||||
public function generarLineaPedido($presupuesto_id)
|
||||
public function generarLineaPedido($presupuesto_id, $forFactura = false, $pedido_id = 0)
|
||||
{
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
@ -565,13 +565,18 @@ class PresupuestoModel extends \App\Models\BaseModel
|
||||
$presupuesto = $presupuesto[0];
|
||||
|
||||
// Libro
|
||||
if($presupuesto->tipo < 10){
|
||||
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;
|
||||
}
|
||||
|
||||
$presupuesto->concepto = sprintf(lang('Pedidos.lineasTemplates.libro'),
|
||||
$presupuesto->numero,
|
||||
if($forFactura){
|
||||
$presupuesto->concepto = sprintf(lang('Pedidos.lineasTemplates.pedido'), $pedido_id);
|
||||
}
|
||||
else{
|
||||
$presupuesto->concepto = sprintf(lang('Pedidos.lineasTemplates.presupuesto'), $presupuesto->numero);
|
||||
}
|
||||
$presupuesto->concepto .= sprintf(lang('Pedidos.lineasTemplates.libro'),
|
||||
$presupuesto->unidades,
|
||||
$presupuesto->paginas,
|
||||
$presupuesto->titulo,
|
||||
|
||||
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Entities\Usuarios\UsersEntity;
|
||||
use CodeIgniter\Shield\Models\UserModel as ShieldUserModel;
|
||||
|
||||
class UserModel extends ShieldUserModel
|
||||
@ -17,26 +18,51 @@ class UserModel extends ShieldUserModel
|
||||
'first_name', // Añadido
|
||||
'last_name', // Añadido
|
||||
'cliente_id', // Añadido
|
||||
'comments', // Añadido
|
||||
];
|
||||
}
|
||||
|
||||
protected $returnType = UsersEntity::class;
|
||||
|
||||
protected $useSoftDeletes = true;
|
||||
protected $useTimestamps = true;
|
||||
protected $createdField = 'created_at';
|
||||
protected $updatedField = 'updated_at';
|
||||
protected $deletedField = 'deleted_at';
|
||||
protected $deletedField = 'deleted_at';
|
||||
|
||||
|
||||
|
||||
protected $validationRules = [
|
||||
"username" => [
|
||||
"label" => "correo duplicado",
|
||||
"rules" => "is_unique[users.username]",
|
||||
]
|
||||
"first_name" => "required|trim|max_length[150]",
|
||||
"last_name" => "required|trim|max_length[150]",
|
||||
'new_pwd' => 'permit_empty|min_length[8]',
|
||||
'new_pwd_confirm' => 'permit_empty|required_with[new_pwd]|matches[new_pwd]',
|
||||
"comments" => "permit_empty|trim|max_length[512]"
|
||||
];
|
||||
|
||||
protected $validationMessages = [
|
||||
'first_name' => [
|
||||
"max_length" => "Users.validation.first_name.max_length",
|
||||
"required" => "Users.validation.first_name.required"
|
||||
],
|
||||
'last_name' => [
|
||||
"max_length" => "Users.validation.last_name.max_length",
|
||||
"required" => "Users.validation.last_name.required"
|
||||
],
|
||||
'new_pwd' => [
|
||||
'min_length' => "App.profile_rules_password_m"
|
||||
],
|
||||
'new_pwd_confirm' => [
|
||||
'matches' => "App.profile_rules_password_confirm_m"
|
||||
],
|
||||
'comments' => [
|
||||
"max_length" => "Users.validation.last_name.max_length",
|
||||
],
|
||||
|
||||
];
|
||||
|
||||
public function getComerciales(){
|
||||
|
||||
public function getComerciales()
|
||||
{
|
||||
|
||||
$builder = $this->db
|
||||
->table("users" . " t1")
|
||||
->select(
|
||||
@ -51,17 +77,5 @@ class UserModel extends ShieldUserModel
|
||||
|
||||
}
|
||||
|
||||
public function getUsersList(){
|
||||
$builder = $this->db
|
||||
->table("users" . " t1")
|
||||
->select(
|
||||
"t1.id AS id, t1.first_name AS first_name, t1.last_name AS last_name, t1.last_active AS last_active, t2.group AS group"
|
||||
);
|
||||
|
||||
$builder->where('t1.deleted_at', null);
|
||||
$builder->join("auth_groups_users t2", "t1.id = t2.user_id", "left");
|
||||
|
||||
return $builder->get()->getResult();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user