Editar valor venta
This commit is contained in:
@ -189,6 +189,23 @@ class Ventas
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function edit(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta $ventaRepository, int $venta_id): ResponseInterface
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
$output = [
|
||||
'venta_id' => $venta_id,
|
||||
'input' => $body,
|
||||
'edited' => false
|
||||
];
|
||||
try {
|
||||
$venta = $ventaRepository->fetchById($venta_id);
|
||||
$body['valor_uf'] = $body['valor'];
|
||||
$body['fecha'] = (new DateTimeImmutable($body['fecha']))->format('Y-m-d');
|
||||
$ventaRepository->edit($venta, $body);
|
||||
$output['edited'] = true;
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function unidades(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
|
||||
Service\Venta\Unidad $unidadService, int $venta_id): ResponseInterface
|
||||
{
|
||||
|
@ -75,10 +75,10 @@ class Venta extends Ideal\Model
|
||||
if (!isset($this->valor_util)) {
|
||||
$sum = $this->valor;
|
||||
$sum -= array_reduce($this->propiedad()->estacionamientos(), function(float $sum, Venta\Unidad $unidad) {
|
||||
return $unidad->precio($this->fecha)->valor;
|
||||
return $unidad->valor ?? $unidad->precio($this->fecha)->valor;
|
||||
}, 0);
|
||||
$sum -= array_reduce($this->propiedad()->bodegas(), function(float $sum, Venta\Unidad $unidad) {
|
||||
return $unidad->precio($this->fecha)->valor;
|
||||
return $unidad->valor ?? $unidad->precio($this->fecha)->valor;
|
||||
}, 0);
|
||||
$this->valor_util = $sum;
|
||||
}
|
||||
|
Reference in New Issue
Block a user