mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
trabajando en pagos (datepicker)
This commit is contained in:
@ -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.
|
||||
*
|
||||
|
||||
@ -108,4 +108,19 @@ class SeriesFacturasModel extends \App\Models\BaseModel
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,8 +38,8 @@ 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 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,
|
||||
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")
|
||||
@ -68,5 +68,30 @@ class FacturaLineaModel extends \App\Models\BaseModel {
|
||||
->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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -51,7 +51,7 @@ class FacturaModel extends \App\Models\BaseModel {
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
'user_created_id',
|
||||
'user_update_id'
|
||||
'user_updated_id'
|
||||
];
|
||||
|
||||
protected $returnType = "App\Entities\Facturas\FacturaEntity";
|
||||
@ -79,6 +79,7 @@ class FacturaModel extends \App\Models\BaseModel {
|
||||
$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");
|
||||
|
||||
return empty($search)
|
||||
? $builder
|
||||
@ -98,5 +99,14 @@ class FacturaModel extends \App\Models\BaseModel {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -78,38 +78,39 @@ class PedidoLineaModel extends \App\Models\BaseModel
|
||||
}
|
||||
|
||||
|
||||
public function obtenerLineasPedidoSinFacturar($cliente_id){
|
||||
|
||||
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");
|
||||
|
||||
$builder->join("pedidos t2", "t2.id = t1.pedido_id", "left");
|
||||
$builder->join("presupuestos t3", "t3.id = t1.presupuesto_id", "left");
|
||||
$builder->join("tipos_presupuestos t4", "t4.id = t3.tipo_impresion_id", "left");
|
||||
|
||||
$builder->join("facturas_pedidos_lineas fpl", "fpl.pedido_linea_id = t1.id", "left");
|
||||
|
||||
$builder->where("t3.cliente_id", $cliente_id);
|
||||
$builder->where("t2.estado", "finalizado");
|
||||
|
||||
|
||||
$builder->where("(`t3`.`tirada` > `fpl`.`cantidad` OR fpl.pedido_linea_id IS NULL)");
|
||||
|
||||
->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){
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user