Cartola Diaria Manual
This commit is contained in:
@ -66,6 +66,11 @@ class Cartolas extends Controller
|
||||
try {
|
||||
$cuenta = $cuentaRepository->fetchById($body["cuenta_id{$field}"]);
|
||||
$fecha = new DateTimeImmutable($body["fecha{$field}"]);
|
||||
if (array_key_exists("manual{$field}", $body)) {
|
||||
$file = json_decode($body["file{$field}"], JSON_OBJECT_AS_ARRAY);
|
||||
$output['cartolas'][$field] = $cartolaService->diariaManual($cuenta, $fecha, $file);
|
||||
continue;
|
||||
}
|
||||
$file = $request->getUploadedFiles()["file{$field}"];
|
||||
|
||||
$output['cartolas'][$field] = $cartolaService->diaria($cuenta, $fecha, $file);
|
||||
|
@ -61,12 +61,12 @@ class Movimiento extends Ideal\Repository
|
||||
->where('cuenta_id = ? AND fecha = ?');
|
||||
return $this->fetchMany($query, [$cuenta_id, $fecha->format('Y-m-d')]);
|
||||
}
|
||||
public function fetchByCuentaAndFechaAndMonto(int $cuenta_id, DateTimeInterface $fecha, int $monto): Model\Movimiento
|
||||
public function fetchByCuentaAndFechaAndCargoAndAbonoAndSaldo(int $cuenta_id, DateTimeInterface $fecha, int $cargo, int $abono, int $saldo): Model\Movimiento
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('cuenta_id = ? AND fecha = ? AND (cargo = ? OR abono = ?)');
|
||||
return $this->fetchOne($query, [$cuenta_id, $fecha->format('Y-m-d'), $monto, $monto]);
|
||||
->where('cuenta_id = ? AND fecha = ? AND cargo = ? AND abono = ? AND saldo = ?');
|
||||
return $this->fetchOne($query, [$cuenta_id, $fecha->format('Y-m-d'), $cargo, $abono, $saldo]);
|
||||
}
|
||||
}
|
||||
|
@ -65,6 +65,28 @@ class Cartola extends Service
|
||||
$cartola = $this->buildCartola($cuenta, $fecha, $cartolaData);
|
||||
return compact('cartola', 'movimientos');
|
||||
}
|
||||
public function diariaManual(Model\Inmobiliaria\Cuenta $cuenta, DateTimeInterface $fecha, array $data): array
|
||||
{
|
||||
$cartolaData = [
|
||||
'cargos' => 0,
|
||||
'abonos' => 0,
|
||||
'saldos' => 0
|
||||
];
|
||||
$movimientos = [];
|
||||
foreach ($data as $row) {
|
||||
$dataMovimiento = $row;
|
||||
$dataMovimiento['fecha'] = $fecha->format('Y-m-d');
|
||||
$dataMovimiento['documento'] = '';
|
||||
$movimiento = $this->buildMovimiento($cuenta, $dataMovimiento);
|
||||
|
||||
$movimientos []= $movimiento;
|
||||
$cartolaData['cargos'] += $movimiento->cargo;
|
||||
$cartolaData['abonos'] += $movimiento->abono;
|
||||
$cartolaData['saldo'] = $movimiento->saldo;
|
||||
}
|
||||
$cartola = $this->buildCartola($cuenta, $fecha, $cartolaData);
|
||||
return compact('cartola', 'movimientos');
|
||||
}
|
||||
|
||||
protected function getMovimientosDiarios(Model\Banco $banco, UploadedFileInterface $file): array
|
||||
{
|
||||
@ -85,12 +107,13 @@ class Cartola extends Service
|
||||
protected function buildMovimiento(Model\Inmobiliaria\Cuenta $cuenta, array $data): Model\Movimiento
|
||||
{
|
||||
try {
|
||||
$valor = ($data['cargo'] !== 0 and $data['cargo'] !== null) ? $data['cargo'] : $data['abono'];
|
||||
return $this->movimientoRepository
|
||||
->fetchByCuentaAndFechaAndMonto(
|
||||
->fetchByCuentaAndFechaAndCargoAndAbonoAndSaldo(
|
||||
$cuenta->id,
|
||||
new DateTimeImmutable($data['fecha']),
|
||||
$valor
|
||||
$data['cargo'] ?? 0,
|
||||
$data['abono'] ?? 0,
|
||||
$data['saldo']
|
||||
);
|
||||
} catch (Exception\EmptyResult $exception) {
|
||||
$data['cuenta_id'] = $cuenta->id;
|
||||
|
Reference in New Issue
Block a user