Editar credito

This commit is contained in:
Juan Pablo Vial
2024-02-15 18:57:56 -03:00
parent 1621d6fe30
commit 51cabee824
10 changed files with 383 additions and 15 deletions

View File

@ -209,8 +209,8 @@ class Tesoreria extends Ideal\Service
'cuenta' => $deposito->cuenta,
'fecha' => $deposito->termino,
'cargo' => 0,
'abono' => $deposito->futuro,
'saldo' => $deposito->futuro,
'abono' => $deposito->capital,
'saldo' => $deposito->capital,
'glosa' => 'RESCATE DAP'
]]);
}

View File

@ -2,20 +2,25 @@
namespace Incoviba\Service\Venta;
use DateTimeImmutable;
use Incoviba\Common\Ideal\Service;
use Incoviba\Repository;
use Incoviba\Model;
use Incoviba\Service\Money;
use Psr\Log\LoggerInterface;
class Credito
class Credito extends Service
{
public function __construct(
LoggerInterface $logger,
protected Repository\Venta\Credito $creditoRepository,
protected Repository\Venta\Pago $pagoRepository,
protected Repository\Venta\TipoPago $tipoPagoRepository,
protected Repository\Venta\EstadoPago $estadoPagoRepository,
protected Repository\Venta\TipoEstadoPago $tipoEstadoPagoRepository,
protected Money $moneyService
) {}
) {
parent::__construct($logger);
}
public function add(array $data): Model\Venta\Credito
{
@ -30,6 +35,27 @@ class Credito
]);
return $this->creditoRepository->save($credito);
}
public function edit(Model\Venta\Credito $credito, array $data): Model\Venta\Credito
{
$uf = $this->moneyService->getUF($credito->pago->fecha);
if (array_key_exists('fecha', $data)) {
$fecha = new DateTimeImmutable($data['fecha']);
$data['fecha'] = $fecha->format('Y-m-d');
$uf = $this->moneyService->getUF($fecha);
$data['uf'] = $uf;
}
if (array_key_exists('valor', $data)) {
$data['valor'] = round(((float) $data['valor']) * $uf);
}
$filteredData = array_intersect_key($data, array_fill_keys([
'fecha',
'uf',
'valor',
'banco'
], 0));
$credito->pago = $this->pagoRepository->edit($credito->pago, $filteredData);
return $this->creditoRepository->edit($credito, $filteredData);
}
protected function addPago(array $data): Model\Venta\Pago
{
$pago = $this->pagoRepository->create($data);