mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
72 lines
2.3 KiB
PHP
72 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Facturas;
|
|
|
|
|
|
class FacturaLineaModel extends \App\Models\BaseModel {
|
|
|
|
protected $table = 'facturas_lineas';
|
|
|
|
// Lista de columnas basada en los campos de la tabla, para asignación masiva
|
|
protected $allowedFields = [
|
|
'factura_id',
|
|
'pedido_linea_impresion_id',
|
|
'pedido_maquetacion_id',
|
|
'descripcion',
|
|
'cantidad',
|
|
'precio_unidad',
|
|
'iva',
|
|
'base',
|
|
'total_iva',
|
|
'total',
|
|
'data',
|
|
'deleted_at',
|
|
'user_updated_id'
|
|
];
|
|
|
|
protected $returnType = "App\Entities\Facturas\FacturaLineaEntity";
|
|
|
|
protected $useTimestamps = false;
|
|
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 concepto, t1.cantidad as unidades, t1.precio_unidad AS precio_unidad, t1.iva AS iva,
|
|
t1.base AS subtotal, 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();
|
|
}
|
|
} |