id = $row['id']; $model->pie = $this->getMapper(Pie::class)->fetchById($row['pie']); $model->fecha = new \DateTimeImmutable($row['fecha']); $model->valor = $row['valor_$']; $model->estado = $row['estado']; $model->banco = ($row['banco'] != '') ? $this->getMapper(Banco::class)->fetchById($row['banco']) : null; $estado = new CuotaModel\Estado(); $estado->fecha_pago = ($row['fecha_pago']) ? new \DateTimeImmutable($row['fecha_pago']) : null; $estado->abonado = $row['abonado']; $estado->fecha_abono = ($row['fecha_abono']) ? new \DateTimeImmutable($row['fecha_abono']) : null; $model->estado_cuota = $estado; $model->uf = $row['uf']; $model->pago = $this->getMapper(Pago::class)->fetchById($row['pago']); $model->numero = $row['numero']; return $model; } public function save(Model $model): bool { return true; } public function fetchByProyecto(int $proyecto_id): array { $qb = $this->connection->createQueryBuilder() ->select('a.*') ->from($this->table, 'a') ->innerJoin('a', 'venta', 'v', 'v.pie = a.pie') ->innerJoin('v', 'propiedad', 'p', 'p.id = v.propiedad') ->innerJoin('p', 'unidad', 'u', 'u.id = p.unidad_principal') ->innerJoin('u', 'proyecto_tipo_unidad', 'ptu', 'ptu.id = u.pt') ->where('ptu.proyecto = ?'); return array_map([$this, 'load'], $this->connection->executeQuery($qb, [$proyecto_id])->fetchAllAssociative()); } public function fetchByProyectoAndFecha(int $proyecto_id, \DateTimeInterface $fecha): array { $qb = $this->connection->createQueryBuilder() ->select('a.*') ->from($this->table, 'a') ->innerJoin('a', 'venta', 'v', 'v.pie = a.pie') ->innerJoin('v', 'propiedad', 'p', 'p.id = v.propiedad') ->innerJoin('p', 'unidad', 'u', 'u.id = p.unidad_principal') ->innerJoin('u', 'proyecto_tipo_unidad', 'ptu', 'ptu.id = u.pt') ->innerJoin('a', 'pago', 'g', 'g.id = a.pago') ->where('ptu.proyecto = ?') ->andWhere('g.fecha = ?'); return array_map([$this, 'load'], $this->connection->executeQuery($qb, [$proyecto_id, $fecha->format('y-m-d')])->fetchAllAssociative()); } public function fetchByProyectoAndMes(int $proyecto_id, \DateTimeInterface $mes): array { $qb = $this->connection->createQueryBuilder() ->select('a.*') ->from($this->table, 'a') ->innerJoin('a', 'venta', 'v', 'v.pie = a.pie') ->innerJoin('v', 'propiedad', 'p', 'p.id = v.propiedad') ->innerJoin('p', 'unidad', 'u', 'u.id = p.unidad_principal') ->innerJoin('u', 'proyecto_tipo_unidad', 'ptu', 'ptu.id = u.pt') ->innerJoin('a', 'pago', 'g', 'g.id = a.pago') ->where('ptu.proyecto = ?') ->andWhere('g.fecha BETWEEN ? AND ?'); return array_map([$this, 'load'], $this->connection->executeQuery($qb, [$proyecto_id, $mes->format('y-m-1'), $mes->format('y-m-t')])->fetchAllAssociative()); } public function fetchByProyectoAndPendiente(int $proyecto_id): array { $qb = $this->connection->createQueryBuilder() ->select('a.*') ->from($this->table, 'a') ->innerJoin('a', 'venta', 'v', 'v.pie = a.pie') ->innerJoin('v', 'propiedad', 'p', 'p.id = v.propiedad') ->innerJoin('p', 'unidad', 'u', 'u.id = p.unidad_principal') ->innerJoin('u', 'proyecto_tipo_unidad', 'ptu', 'ptu.id = u.pt') ->innerJoin('a', 'pago', 'g', 'g.id = a.pago') ->leftJoin('g', '(SELECT e1.* FROM estado_pago e1 JOIN (SELECT MAX(id) AS id, pago FROM estado_pago GROUP BY pago) e0 ON e0.id = e1.id)', 'ep', 'ep.pago = g.id') ->where('ptu.proyecto = ?') ->andWhere('ep.estado < 1') ->andWhere('ep.estado >= 0'); return array_map([$this, 'load'], $this->connection->executeQuery($qb, [$proyecto_id])->fetchAllAssociative()); } }