mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Merge branch 'main' into 'mod/autoroute'
terminado añadir usuarios y fechas a pedidos. añadido inaplazable. color en... See merge request jjimenez/safekat!695
This commit is contained in:
@ -25,12 +25,12 @@ class ClienteContactoModel extends \App\Models\BaseModel
|
||||
protected $returnType = "App\Entities\Clientes\ClienteContactoEntity";
|
||||
|
||||
protected $useTimestamps = true;
|
||||
protected $useSoftDeletes = false;
|
||||
protected $useSoftDeletes = true;
|
||||
protected $deletedField = 'deleted_at';
|
||||
|
||||
protected $createdField = "created_at";
|
||||
|
||||
protected $updatedField = "updated_at";
|
||||
protected $deletedField = 'deleted_at';
|
||||
|
||||
public static $labelField = "nombre";
|
||||
|
||||
@ -113,7 +113,7 @@ class ClienteContactoModel extends \App\Models\BaseModel
|
||||
);
|
||||
|
||||
$builder->where('t1.cliente_id', $cliente_id);
|
||||
$builder->where("t1.is_deleted", 0);
|
||||
$builder->where("t1.deleted_at", null);
|
||||
$builder->join("clientes t2", "t1.cliente_id = t2.id", "left");
|
||||
|
||||
return empty($search)
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Models\Clientes;
|
||||
|
||||
use App\Entities\Clientes\ClienteEntity;
|
||||
|
||||
class ClienteModel extends \App\Models\BaseModel
|
||||
{
|
||||
protected $table = "clientes";
|
||||
@ -57,13 +59,11 @@ class ClienteModel extends \App\Models\BaseModel
|
||||
"comentarios_tirada_flexible",
|
||||
"margen_plantilla_id",
|
||||
"comentarios",
|
||||
"is_deleted",
|
||||
"deleted_at",
|
||||
"user_created_id",
|
||||
"user_update_id",
|
||||
];
|
||||
protected $returnType = "App\Entities\Clientes\ClienteEntity";
|
||||
|
||||
protected $returnType = ClienteEntity::class;
|
||||
protected $useSoftDeletes = true;
|
||||
protected $deletedField = 'deleted_at';
|
||||
|
||||
public static $labelField = "nombre";
|
||||
@ -197,10 +197,7 @@ class ClienteModel extends \App\Models\BaseModel
|
||||
"fecha_vencimiento" => [
|
||||
"max_length" => "Clientes.validation.fecha_vencimiento.max_length",
|
||||
],
|
||||
"is_deleted" => [
|
||||
"integer" => "Clientes.validation.is_deleted.integer",
|
||||
"required" => "Clientes.validation.is_deleted.required",
|
||||
],
|
||||
|
||||
"limite_credito" => [
|
||||
"decimal" => "Clientes.validation.limite_credito.decimal",
|
||||
"required" => "Clientes.validation.limite_credito.required",
|
||||
@ -287,7 +284,7 @@ class ClienteModel extends \App\Models\BaseModel
|
||||
->select(
|
||||
"t1.id AS id, t1.nombre AS nombre, t1.alias AS alias, t1.cif AS cif, t1.email AS email, t1.vencimiento AS vencimiento, t5.first_name AS comercial, t7.nombre AS forma_pago_id"
|
||||
)
|
||||
->where("is_deleted", 0);;
|
||||
->where("t1.deleted_at", null);;
|
||||
$builder->join("users t5", "t1.comercial_id = t5.id", "left");
|
||||
$builder->join("formas_pago t7", "t1.forma_pago_id = t7.id", "left");
|
||||
|
||||
@ -315,7 +312,7 @@ class ClienteModel extends \App\Models\BaseModel
|
||||
->select(
|
||||
"t1.limite_credito AS limite_credito"
|
||||
)
|
||||
->where("t1.is_deleted", 0)
|
||||
->where("t1.deleted_at", null)
|
||||
->where("t1.id", $cliente_id);
|
||||
$limite = $builder->get()->getResultObject();
|
||||
|
||||
@ -340,7 +337,7 @@ class ClienteModel extends \App\Models\BaseModel
|
||||
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.deleted_at", null)
|
||||
->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");
|
||||
@ -394,7 +391,7 @@ class ClienteModel extends \App\Models\BaseModel
|
||||
"t1.nombre AS nombre"
|
||||
)
|
||||
->where("id", $id)
|
||||
->where("is_deleted", 0);
|
||||
->where("t1.deleted_at", null);
|
||||
|
||||
return $builder->get()->getResultObject()[0]->nombre;
|
||||
} catch (\Exception $e) {
|
||||
@ -409,7 +406,7 @@ class ClienteModel extends \App\Models\BaseModel
|
||||
->select(
|
||||
"t1.id AS id, t1.nombre AS name"
|
||||
)
|
||||
->where("is_deleted", 0);
|
||||
->where("t1.deleted_at", null);
|
||||
return empty($search)
|
||||
? $builder->get()->getResultObject()
|
||||
: $builder
|
||||
@ -586,7 +583,7 @@ class ClienteModel extends \App\Models\BaseModel
|
||||
$result['limite_credito'] = $this->db->table('clientes')
|
||||
->select('limite_credito')
|
||||
->where('id', $cliente_id)
|
||||
->where('is_deleted', 0)
|
||||
->where("deleted_at", null)
|
||||
->get()
|
||||
->getResultObject()[0]->limite_credito;
|
||||
$result['limite_credito'] = round(floatval($result['limite_credito']), 2);
|
||||
|
||||
@ -36,7 +36,6 @@ class ClientePlantillaPreciosLineasModel extends \App\Models\BaseModel
|
||||
"tiempo_max",
|
||||
"precio_hora",
|
||||
"margen",
|
||||
"is_deleted",
|
||||
"deleted_at",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
@ -45,11 +44,12 @@ class ClientePlantillaPreciosLineasModel extends \App\Models\BaseModel
|
||||
protected $returnType = "App\Entities\Clientes\ClientePlantillaPreciosLineasEntity";
|
||||
|
||||
protected $useTimestamps = true;
|
||||
protected $useSoftDeletes = false;
|
||||
protected $useSoftDeletes = true;
|
||||
|
||||
protected $createdField = "created_at";
|
||||
|
||||
protected $updatedField = "updated_at";
|
||||
protected $deletedField = 'deleted_at';
|
||||
|
||||
public static $labelField = "plantilla_id";
|
||||
|
||||
@ -121,7 +121,6 @@ class ClientePlantillaPreciosLineasModel extends \App\Models\BaseModel
|
||||
$this->db
|
||||
->table($this->table . " t1")
|
||||
->where('t1.plantilla_id', $plantilla_id)
|
||||
->set('is_deleted', 1)
|
||||
->set('deleted_at', $date_value)
|
||||
->update();
|
||||
|
||||
@ -152,7 +151,7 @@ class ClientePlantillaPreciosLineasModel extends \App\Models\BaseModel
|
||||
|
||||
$builder->join("users t2", "t1.user_updated_id = t2.id", "left");
|
||||
|
||||
$builder->where('t1.is_deleted', 0);
|
||||
$builder->where('t1.deleted_at', 0);
|
||||
$builder->where('t1.plantilla_id', $plantilla_id);
|
||||
|
||||
if (empty($search))
|
||||
@ -181,7 +180,7 @@ class ClientePlantillaPreciosLineasModel extends \App\Models\BaseModel
|
||||
$rows = $this->db
|
||||
->table($this->table)
|
||||
->select("id, tiempo_min, tiempo_max")
|
||||
->where("is_deleted", 0)
|
||||
->where("deleted_at", null)
|
||||
->where("tipo", $data["tipo"])
|
||||
->where("tipo_maquina", $data["tipo_maquina"])
|
||||
->where("tipo_impresion", $data["tipo_impresion"])
|
||||
|
||||
@ -19,11 +19,12 @@ class ClientePlantillaPreciosModel extends \App\Models\BaseModel
|
||||
protected $useAutoIncrement = true;
|
||||
|
||||
|
||||
protected $allowedFields = ["nombre", "is_deleted", "deleted_at", "created_at", "updated_at"];
|
||||
protected $allowedFields = ["nombre", "deleted_at", "created_at", "updated_at"];
|
||||
protected $returnType = "App\Entities\Clientes\ClientePlantillaPreciosEntity";
|
||||
|
||||
protected $useTimestamps = true;
|
||||
protected $useSoftDeletes = false;
|
||||
protected $useSoftDeletes = true;
|
||||
protected $deletedField = 'deleted_at';
|
||||
|
||||
protected $createdField = "created_at";
|
||||
|
||||
@ -61,7 +62,7 @@ class ClientePlantillaPreciosModel extends \App\Models\BaseModel
|
||||
"t1.id as id, t1.nombre AS nombre"
|
||||
);
|
||||
|
||||
$builder->where('t1.is_deleted', 0);
|
||||
$builder->where('t1.deleted_at', null);
|
||||
|
||||
if (empty($search))
|
||||
return $builder;
|
||||
|
||||
@ -34,7 +34,6 @@ class ClientePreciosModel extends \App\Models\BaseModel
|
||||
"tiempo_max",
|
||||
"precio_hora",
|
||||
"margen",
|
||||
"is_deleted",
|
||||
"deleted_at",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
@ -45,7 +44,8 @@ class ClientePreciosModel extends \App\Models\BaseModel
|
||||
protected $returnType = "App\Entities\Clientes\ClientePreciosEntity";
|
||||
|
||||
protected $useTimestamps = true;
|
||||
protected $useSoftDeletes = false;
|
||||
protected $useSoftDeletes = true;
|
||||
protected $deletedField = 'deleted_at';
|
||||
|
||||
protected $createdField = "created_at";
|
||||
|
||||
@ -140,7 +140,6 @@ class ClientePreciosModel extends \App\Models\BaseModel
|
||||
$this->db
|
||||
->table($this->table . " t1")
|
||||
->where('cliente_id', $cliente_id)
|
||||
->set('is_deleted', 1)
|
||||
->set('deleted_at', $date_value)
|
||||
->set('user_updated_id', $session->id_user)
|
||||
->update();
|
||||
@ -153,7 +152,7 @@ class ClientePreciosModel extends \App\Models\BaseModel
|
||||
// Se borran los valores existentes para todos los clientes en una sola consulta
|
||||
|
||||
$modelCliente = model('App\Models\Clientes\ClienteModel');
|
||||
$clientes = $modelCliente->select('id')->where('is_deleted', 0)->findAll();
|
||||
$clientes = $modelCliente->select('id')->where('deleted_at', null)->findAll();
|
||||
|
||||
// Se borra la tabla
|
||||
$this->db->table($this->table)->truncate();
|
||||
@ -288,7 +287,7 @@ class ClientePreciosModel extends \App\Models\BaseModel
|
||||
->table($this->table . " t1")
|
||||
->select("t1.cliente_id AS id")
|
||||
->where('t1.plantilla_id', $plantilla_id)
|
||||
->where('t1.is_deleted', 0)
|
||||
->where('t1.deleted_at', null)
|
||||
->distinct()
|
||||
->get()->getResultArray();
|
||||
// Extraer solo los IDs de los clientes
|
||||
@ -359,7 +358,7 @@ class ClientePreciosModel extends \App\Models\BaseModel
|
||||
->where('tipo_impresion', $config->tipo_impresion)
|
||||
->where('tiempo_min <=', $tiempo)
|
||||
->where('tiempo_max >=', $tiempo)
|
||||
->where('is_deleted', 0)
|
||||
->where('deleted_at', null)
|
||||
->get()->getResultObject();
|
||||
|
||||
if (count($values) > 0) {
|
||||
@ -389,7 +388,7 @@ class ClientePreciosModel extends \App\Models\BaseModel
|
||||
|
||||
$builder->join("users t2", "t1.user_updated_id = t2.id", "left");
|
||||
|
||||
$builder->where('t1.is_deleted', 0);
|
||||
$builder->where('t1.deleted_at', 0);
|
||||
$builder->where('t1.cliente_id', $cliente_id);
|
||||
|
||||
if (empty($search))
|
||||
@ -415,7 +414,7 @@ class ClientePreciosModel extends \App\Models\BaseModel
|
||||
"t1.plantilla_id AS id, t2.nombre AS nombre"
|
||||
);
|
||||
|
||||
$builder->where('t1.is_deleted', 0);
|
||||
$builder->where('t1.deleted_at', null);
|
||||
$builder->where('t1.cliente_id', $cliente_id);
|
||||
$builder->join("cliente_plantilla_precios t2", "t1.plantilla_id = t2.id", "left");
|
||||
$builder->limit(1);
|
||||
@ -442,7 +441,7 @@ class ClientePreciosModel extends \App\Models\BaseModel
|
||||
$rows = $this->db
|
||||
->table($this->table)
|
||||
->select("id, tiempo_min, tiempo_max")
|
||||
->where("is_deleted", 0)
|
||||
->where("deleted_at", null)
|
||||
->where("tipo", $data["tipo"])
|
||||
->where("tipo_maquina", $data["tipo_maquina"])
|
||||
->where("tipo_impresion", $data["tipo_impresion"])
|
||||
@ -476,7 +475,7 @@ class ClientePreciosModel extends \App\Models\BaseModel
|
||||
$value = $this->db
|
||||
->table($this->table)
|
||||
->select("plantilla_id")
|
||||
->where("is_deleted", 0)
|
||||
->where("deleted_at", null)
|
||||
->where("cliente_id", $cliente_id)
|
||||
->limit(1)->get()->getResultObject();
|
||||
|
||||
|
||||
@ -26,7 +26,8 @@ class ClienteUsuariosModel extends ShieldUserModel
|
||||
protected $returnType = "App\Entities\Usuarios\UserEntity";
|
||||
|
||||
protected $useTimestamps = true;
|
||||
protected $useSoftDeletes = false;
|
||||
protected $useSoftDeletes = true;
|
||||
protected $deletedField = 'deleted_at';
|
||||
|
||||
protected $createdField = "created_at";
|
||||
|
||||
|
||||
@ -14,7 +14,6 @@ class FacturaLineaModel extends \App\Models\BaseModel {
|
||||
'pedido_maquetacion_id',
|
||||
'descripcion',
|
||||
'cantidad',
|
||||
'precio_unidad',
|
||||
'iva',
|
||||
'base',
|
||||
'total_iva',
|
||||
@ -38,9 +37,9 @@ class FacturaLineaModel extends \App\Models\BaseModel {
|
||||
->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.descripcion AS descripcion, t1.cantidad as cantidad, 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, t4.tirada_flexible AS tirada_flexible, t4.descuento_tirada_flexible AS descuento_tirada_flexible,
|
||||
t3.total_aceptado_revisado AS total_aceptado, t4.tirada_flexible AS tirada_flexible, t4.descuento_tirada_flexible AS descuento_tirada_flexible,
|
||||
t6.cantidad AS cantidad_albaran"
|
||||
)
|
||||
->join("pedidos_linea t2", "t2.id = t1.pedido_linea_impresion_id", "left")
|
||||
@ -89,7 +88,7 @@ class FacturaLineaModel extends \App\Models\BaseModel {
|
||||
->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.descripcion AS descripcion, t1.cantidad as cantidad, 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)
|
||||
|
||||
@ -145,6 +145,27 @@ class FacturaModel extends \App\Models\BaseModel
|
||||
return $builder;
|
||||
}
|
||||
|
||||
|
||||
public function presupuestoHasFacturaValidada($presupuesto_id = null)
|
||||
{
|
||||
if ($presupuesto_id == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = $this->db->table($this->table . " t1")
|
||||
->select("t1.id")
|
||||
->join("facturas_lineas t2", "t2.factura_id = t1.id", "left")
|
||||
->join("pedidos_linea t3", "t2.pedido_linea_impresion_id = t3.id", "left")
|
||||
->where("t3.presupuesto_id", $presupuesto_id)
|
||||
->where("t1.deleted_at IS NULL")
|
||||
->where("t2.deleted_at IS NULL")
|
||||
->where("t1.estado", "validada")
|
||||
->get()
|
||||
->getResultObject();
|
||||
|
||||
return !empty($result);
|
||||
}
|
||||
|
||||
public function getSumatoriosFacturacionCliente($cliente_id = -1){
|
||||
|
||||
if($cliente_id == -1){
|
||||
|
||||
@ -36,6 +36,8 @@ class PedidoLineaModel extends \App\Models\BaseModel
|
||||
"user_updated_id",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
"cantidad",
|
||||
"descripcion",
|
||||
];
|
||||
protected $returnType = "App\Entities\Pedidos\PedidoLineaEntity";
|
||||
|
||||
|
||||
@ -37,6 +37,7 @@ class PedidoModel extends \App\Models\BaseModel
|
||||
"total_precio",
|
||||
"total_tirada",
|
||||
"estado",
|
||||
"inaplazable",
|
||||
"user_created_id",
|
||||
"user_updated_id",
|
||||
"user_validated_id",
|
||||
@ -44,6 +45,11 @@ class PedidoModel extends \App\Models\BaseModel
|
||||
"fecha_impresion",
|
||||
"fecha_encuadernado",
|
||||
"fecha_entrega_externo",
|
||||
"fecha_entrega_real_change_user_id",
|
||||
"fecha_impresion_change_user_id",
|
||||
"fecha_encuadernado_change_user_id",
|
||||
"fecha_entrega_externo_change_user_id",
|
||||
"inaplazable_change_user_id",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
"validated_at",
|
||||
@ -111,15 +117,28 @@ class PedidoModel extends \App\Models\BaseModel
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
->select(
|
||||
"t2.presupuesto_id"
|
||||
"t2.presupuesto_id, t3.total_aceptado, t2.descripcion, t2.cantidad"
|
||||
);
|
||||
$builder->where("t1.id", $pedido_id);
|
||||
$builder->join("pedidos_linea t2", "t2.pedido_id = t1.id", "left");
|
||||
$builder->join("presupuestos t3", "t2.presupuesto_id = t3.id", "left");
|
||||
$model_presupuesto = model("App\Models\Presupuestos\PresupuestoModel");
|
||||
$lineasPresupuesto = [];
|
||||
|
||||
foreach ($builder->get()->getResultObject() as $row) {
|
||||
array_push($lineasPresupuesto, $model_presupuesto->generarLineaPedido($row->presupuesto_id)[0]);
|
||||
if($row->descripcion == null){
|
||||
array_push($lineasPresupuesto, $model_presupuesto->generarLineaPedido($row->presupuesto_id)[0]);
|
||||
}
|
||||
else{
|
||||
$presupuesto = (object) [
|
||||
'numero' => $row->presupuesto_id,
|
||||
'unidades' => $row->cantidad,
|
||||
'total' => $row->total_aceptado,
|
||||
'concepto' => $row->descripcion,
|
||||
];
|
||||
array_push($lineasPresupuesto, $presupuesto);
|
||||
}
|
||||
|
||||
}
|
||||
$builder->groupBy("t1.id");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user