Ventas
This commit is contained in:
71
app/src/Service/Venta/Cuota.php
Normal file
71
app/src/Service/Venta/Cuota.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use DateInterval;
|
||||
use IntlDateFormatter;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Cuota
|
||||
{
|
||||
public function __construct(protected Repository\Venta\Cuota $cuotaRepository) {}
|
||||
|
||||
public function pendientes(): array
|
||||
{
|
||||
$cuotas = $this->cuotaRepository->fetchPendientes();
|
||||
$cuotas_pendientes = [];
|
||||
$today = new DateTimeImmutable();
|
||||
$formatter = new IntlDateFormatter('es_ES');
|
||||
$formatter->setPattern('EEEE dd');
|
||||
foreach ($cuotas as $cuota) {
|
||||
$date = new DateTimeImmutable($cuota['fecha']);
|
||||
$day = clone $date;
|
||||
$weekday = $date->format('N');
|
||||
if ($weekday > 5) {
|
||||
$diff = 7 - $weekday + 1;
|
||||
$day = $day->add(new DateInterval("P{$diff}D"));
|
||||
}
|
||||
$cuotas_pendientes []= [
|
||||
'id' => $cuota['cuota_id'],
|
||||
'venta_id' => $cuota['venta_id'],
|
||||
'Proyecto' => $cuota['Proyecto'],
|
||||
'Departamento' => $cuota['Departamento'],
|
||||
'Valor' => $cuota['Valor'],
|
||||
'Dia' => $formatter->format($day),
|
||||
'Numero' => $cuota['Numero'],
|
||||
'Propietario' => $cuota['Propietario'],
|
||||
'Banco' => $cuota['Banco'],
|
||||
'Fecha Cheque' => $date->format('d-m-Y'),
|
||||
'Vencida' => $today->diff($date)->days,
|
||||
'Fecha ISO' => $date->format('Y-m-d')
|
||||
];
|
||||
}
|
||||
return $cuotas_pendientes;
|
||||
}
|
||||
public function depositadas(): array
|
||||
{
|
||||
$cuotas = $this->cuotaRepository->fetchDepositadas();
|
||||
$cuotas_depositadas = [];
|
||||
$today = new DateTimeImmutable();
|
||||
$formatter = new IntlDateFormatter('es_ES');
|
||||
$formatter->setPattern('EEEE dd');
|
||||
foreach ($cuotas as $cuota) {
|
||||
$date = new DateTimeImmutable($cuota['fecha']);
|
||||
$deposito = new DateTimeImmutable($cuota['Fecha Depositada']);
|
||||
$cuotas_depositadas []= [
|
||||
'id' => $cuota['cuota_id'],
|
||||
'venta_id' => $cuota['venta_id'],
|
||||
'Proyecto' => $cuota['Proyecto'],
|
||||
'Departamento' => $cuota['Departamento'],
|
||||
'Valor' => $cuota['Valor'],
|
||||
'Numero' => $cuota['Numero'],
|
||||
'Propietario' => $cuota['Propietario'],
|
||||
'Banco' => $cuota['Banco'],
|
||||
'Fecha Cheque' => $date->format('d-m-Y'),
|
||||
'Fecha ISO' => $date->format('Y-m-d'),
|
||||
'Fecha Depositada' => $deposito->format('d-m-Y')
|
||||
];
|
||||
}
|
||||
return $cuotas_depositadas;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user