2023-09-12
This commit is contained in:
@ -5,10 +5,15 @@ use DateTimeImmutable;
|
||||
use DateInterval;
|
||||
use IntlDateFormatter;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Cuota
|
||||
{
|
||||
public function __construct(protected Repository\Venta\Cuota $cuotaRepository) {}
|
||||
public function __construct(
|
||||
protected Repository\Venta\Cuota $cuotaRepository,
|
||||
protected Pago $pagoService,
|
||||
protected Repository\Venta\TipoPago $tipoPagoRepository
|
||||
) {}
|
||||
|
||||
public function pendientes(): array
|
||||
{
|
||||
@ -68,4 +73,41 @@ class Cuota
|
||||
}
|
||||
return $cuotas_depositadas;
|
||||
}
|
||||
public function getVigenteByPie(int $pie_id): array
|
||||
{
|
||||
return $this->cuotaRepository->fetchVigenteByPie($pie_id);
|
||||
}
|
||||
|
||||
public function add(array $data): Model\Venta\Cuota
|
||||
{
|
||||
$tipoPago = $this->tipoPagoRepository->fetchByDescripcion('cheque');
|
||||
$fields = array_fill_keys([
|
||||
'fecha',
|
||||
'banco',
|
||||
'valor',
|
||||
'identificador'
|
||||
], 0);
|
||||
$filtered_data = array_intersect_key($data, $fields);
|
||||
$pago_data = array_merge($filtered_data, ['tipo' => $tipoPago->id]);
|
||||
$pago = $this->pagoService->add($pago_data);
|
||||
$data['pago'] = $pago->id;
|
||||
$data['estado'] = $pago->currentEstado->tipoEstadoPago->id;
|
||||
$fields = array_fill_keys([
|
||||
'pie',
|
||||
'fecha',
|
||||
'valor',
|
||||
'estado',
|
||||
'banco',
|
||||
'uf',
|
||||
'pago',
|
||||
'numero'
|
||||
], 0);
|
||||
$filtered_data = array_intersect_key($data, $fields);
|
||||
$mapped_data = $filtered_data;
|
||||
$mapped_data['valor_$'] = $mapped_data['valor'];
|
||||
unset($mapped_data['valor']);
|
||||
$cuota = $this->cuotaRepository->create($mapped_data);
|
||||
$this->cuotaRepository->save($cuota);
|
||||
return $cuota;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user