mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
91 lines
2.6 KiB
PHP
91 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Facturas;
|
|
|
|
class FacturaModel extends \App\Models\BaseModel {
|
|
|
|
protected $table = 'facturas';
|
|
|
|
protected $useAutoIncrement = true;
|
|
|
|
const SORTABLE = [
|
|
0 => "t1.id",
|
|
1 => "t1.numero",
|
|
2 => "t1.fecha_factura_at",
|
|
3 => "t2.nombre",
|
|
4 => "t1.base",
|
|
5 => "t1.total",
|
|
6 => "t1.pendiente",
|
|
7 => "t1.creditoAsegurado",
|
|
8 => "t1.estado",
|
|
9 => "t1.estado_pago",
|
|
10 => "t4.nombre",
|
|
11 => "DAFEDIFF(days, NOW(), t3.fecha_vencimiento_at)",
|
|
];
|
|
|
|
// Lista de columnas basada en los campos de la tabla, para asignación masiva
|
|
protected $allowedFields = [
|
|
'pedido_id',
|
|
'factura_retificada_id',
|
|
'factura_retificativa_id',
|
|
'cliente_id',
|
|
'serie_id',
|
|
'numero',
|
|
'estado',
|
|
'estado_pago',
|
|
'fecha_factura_at',
|
|
'notas',
|
|
'base',
|
|
'total',
|
|
'pendiente',
|
|
'total_pagos',
|
|
'creditoAsegurado',
|
|
'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'
|
|
];
|
|
|
|
protected $returnType = "App\Entities\Facturas\FacturaEntity";
|
|
|
|
protected $useTimestamps = true;
|
|
protected $useSoftDeletes = true;
|
|
|
|
protected $createdField = "created_at";
|
|
protected $updatedField = "updated_at";
|
|
|
|
public static $labelField = "id";
|
|
|
|
public function getResource(string $search = "")
|
|
{
|
|
$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,
|
|
t4.nombre AS forma_pago, DATE_FORMAT(t3.fecha_vencimiento_at, '%d/%m/%Y') AS 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");
|
|
|
|
|
|
return empty($search)
|
|
? $builder
|
|
: $builder
|
|
->groupStart()
|
|
->like("t1.id", $search)
|
|
->orLike("t1.id", $search)
|
|
->groupEnd();
|
|
}
|
|
} |