Fetch ventas con cuotas pendientes
This commit is contained in:
@ -600,6 +600,42 @@ class Venta extends Ideal\Repository
|
||||
return $this->connection->execute($query, [$venta_id])->fetch(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchAllWithCuotaPending(): array
|
||||
{
|
||||
$subSubQuery = $this->connection->getQueryBuilder()
|
||||
->select('MAX(id) AS id, pago')
|
||||
->from('estado_pago')
|
||||
->group('pago');
|
||||
$subQuery = $this->connection->getQueryBuilder()
|
||||
->select('ep1.*')
|
||||
->from('estado_pago ep1')
|
||||
->joined("INNER JOIN ({$subSubQuery}) ep0 ON ep0.id = ep1.id");
|
||||
$subSubQuery2 = $this->connection->getQueryBuilder()
|
||||
->select('MAX(id) AS id, venta')
|
||||
->from('estado_venta')
|
||||
->group('venta');
|
||||
$subQuery2 = $this->connection->getQueryBuilder()
|
||||
->select('ev1.*')
|
||||
->from('estado_venta ev1')
|
||||
->joined("INNER JOIN ({$subSubQuery2}) ev0 ON ev0.id = ev1.id");
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('DISTINCT a.*')
|
||||
->from("{$this->getTable()} a")
|
||||
->joined('INNER JOIN cuota ON cuota.pie = a.pie')
|
||||
->joined('INNER JOIN pago ON pago.id = cuota.pago')
|
||||
->joined("INNER JOIN ({$subQuery}) ep ON ep.pago = pago.id")
|
||||
->joined('INNER JOIN tipo_estado_pago tep ON tep.id = ep.estado')
|
||||
->joined("INNER JOIN ({$subQuery2}) ev ON ev.venta = a.id")
|
||||
->joined('INNER JOIN tipo_estado_venta tev ON tev.id = ev.estado')
|
||||
->where('tev.descripcion = "vigente" AND tep.descripcion = "no pagado"')
|
||||
->group('a.id');
|
||||
return $this->fetchMany($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param array|null $data
|
||||
|
Reference in New Issue
Block a user