Ventas
This commit is contained in:
44
app/src/Service/Menu.php
Normal file
44
app/src/Service/Menu.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
namespace Incoviba\Service;
|
||||
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Menu
|
||||
{
|
||||
public function __construct(protected Repository\Menu $menuRepository, protected Permission $permissionService, protected object $urls) {}
|
||||
|
||||
public function build(int $user_id): string
|
||||
{
|
||||
$menus = $this->getValid($user_id);
|
||||
$output = [];
|
||||
foreach ($menus as $menu) {
|
||||
$output []= $this->buildItem($menu);
|
||||
}
|
||||
return implode(PHP_EOL, $output);
|
||||
}
|
||||
protected function buildItem(mixed $item): string
|
||||
{
|
||||
if (isset($item->submenus)) {
|
||||
return $this->buildDropdown($item);
|
||||
}
|
||||
return "<a class=\"item\" href=\"{{$this->urls->base}}/{{$item->url}}\">{{$item->title}}</a>";
|
||||
}
|
||||
protected function buildDropdown(mixed $item): string
|
||||
{
|
||||
$output []= '<div class="ui simple dropdown item">';
|
||||
$output []= $item->title;
|
||||
$output []= '<i class="dropdown icon"></i>';
|
||||
$output []= '<div class="menu">';
|
||||
foreach ($item->submenus as $menu) {
|
||||
$output []= $this->buildItem($menu);
|
||||
}
|
||||
$output []= '</div>';
|
||||
$output []= '</div>';
|
||||
return implode(PHP_EOL, $output);
|
||||
}
|
||||
|
||||
public function getValid(int $user_id): array
|
||||
{
|
||||
return $this->menuRepository->fetchByUser($user_id);
|
||||
}
|
||||
}
|
9
app/src/Service/Permission.php
Normal file
9
app/src/Service/Permission.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace Incoviba\Service;
|
||||
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Permission
|
||||
{
|
||||
public function __construct(protected Repository\Permission $permissionRepository) {}
|
||||
}
|
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;
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use DateTimeImmutable;
|
||||
use PDOException;
|
||||
use Incoviba\Repository;
|
||||
@ -12,13 +13,45 @@ class Pago
|
||||
protected Repository\Venta\EstadoPago $estadoPagoRepository,
|
||||
protected Repository\Venta\TipoEstadoPago $tipoEstadoPagoRepository) {}
|
||||
|
||||
public function depositar(Model\Venta\Pago $pago): bool
|
||||
public function depositar(Model\Venta\Pago $pago, DateTimeInterface $fecha): bool
|
||||
{
|
||||
$tipo_estado = $this->tipoEstadoPagoRepository->fetchByDescripcion('depositado');
|
||||
$data = [
|
||||
'pago' => $pago->id,
|
||||
'estado' => $tipo_estado->id,
|
||||
'fecha' => (new DateTimeImmutable())->format('Y-m-d')
|
||||
'fecha' => $fecha->format('Y-m-d')
|
||||
];
|
||||
try {
|
||||
$estado = $this->estadoPagoRepository->create($data);
|
||||
$this->estadoPagoRepository->save($estado);
|
||||
return true;
|
||||
} catch (PDOException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public function abonar(Model\Venta\Pago $pago, DateTimeInterface $fecha): bool
|
||||
{
|
||||
$tipo_estado = $this->tipoEstadoPagoRepository->fetchByDescripcion('abonado');
|
||||
$data = [
|
||||
'pago' => $pago->id,
|
||||
'estado' => $tipo_estado->id,
|
||||
'fecha' => $fecha->format('Y-m-d')
|
||||
];
|
||||
try {
|
||||
$estado = $this->estadoPagoRepository->create($data);
|
||||
$this->estadoPagoRepository->save($estado);
|
||||
return true;
|
||||
} catch (PDOException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public function devolver(Model\Venta\Pago $pago, DateTimeInterface $fecha): bool
|
||||
{
|
||||
$tipo_estado = $this->tipoEstadoPagoRepository->fetchByDescripcion('devuelto');
|
||||
$data = [
|
||||
'pago' => $pago->id,
|
||||
'estado' => $tipo_estado->id,
|
||||
'fecha' => $fecha->format('Y-m-d')
|
||||
];
|
||||
try {
|
||||
$estado = $this->estadoPagoRepository->create($data);
|
||||
@ -35,4 +68,17 @@ class Pago
|
||||
$pago->currentEstado = $this->estadoPagoRepository->fetchCurrentByPago($pago_id);
|
||||
return $pago;
|
||||
}
|
||||
|
||||
public function getPendientes(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
public function getDepositados(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
public function getRebotes(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user