FIX: Empty results threw errors
This commit is contained in:
@ -13,6 +13,7 @@ class Categorias {
|
|||||||
|
|
||||||
public function __invoke(Request $request, Response $response, Factory $factory, Service $service): Response {
|
public function __invoke(Request $request, Response $response, Factory $factory, Service $service): Response {
|
||||||
$categorias = $factory->find(Categoria::class)->many();
|
$categorias = $factory->find(Categoria::class)->many();
|
||||||
|
if ($categorias !== null) {
|
||||||
array_walk($categorias, function(&$item) use ($service) {
|
array_walk($categorias, function(&$item) use ($service) {
|
||||||
$arr = $item->toArray();
|
$arr = $item->toArray();
|
||||||
if ($item->cuentas()) {
|
if ($item->cuentas()) {
|
||||||
@ -35,7 +36,6 @@ class Categorias {
|
|||||||
}
|
}
|
||||||
$item = $arr;
|
$item = $arr;
|
||||||
});
|
});
|
||||||
if ($categorias) {
|
|
||||||
usort($categorias, function($a, $b) {
|
usort($categorias, function($a, $b) {
|
||||||
return strcmp($a['nombre'], $b['nombre']);
|
return strcmp($a['nombre'], $b['nombre']);
|
||||||
});
|
});
|
||||||
|
@ -13,11 +13,15 @@ class TiposCategorias {
|
|||||||
|
|
||||||
public function __invoke(Request $request, Response $response, Factory $factory, Service $service): Response {
|
public function __invoke(Request $request, Response $response, Factory $factory, Service $service): Response {
|
||||||
$tipos = $factory->find(TipoCategoria::class)->many();
|
$tipos = $factory->find(TipoCategoria::class)->many();
|
||||||
|
if ($tipos !== null) {
|
||||||
array_walk($tipos, function(&$item) use ($service) {
|
array_walk($tipos, function(&$item) use ($service) {
|
||||||
$arr = $item->toArray();
|
$arr = $item->toArray();
|
||||||
|
$arr['categorias'] = $item->categorias();
|
||||||
|
if ($arr['categorias'] !== null) {
|
||||||
$arr['categorias'] = array_map(function($item) {
|
$arr['categorias'] = array_map(function($item) {
|
||||||
return $item->toArray();
|
return $item->toArray();
|
||||||
}, $item->categorias());
|
}, $item->categorias());
|
||||||
|
}
|
||||||
$arr['saldo'] = abs($item->saldo($service));
|
$arr['saldo'] = abs($item->saldo($service));
|
||||||
$maps = ['activo', 'pasivo', 'ganancia', 'perdida'];
|
$maps = ['activo', 'pasivo', 'ganancia', 'perdida'];
|
||||||
foreach ($maps as $m) {
|
foreach ($maps as $m) {
|
||||||
@ -34,7 +38,6 @@ class TiposCategorias {
|
|||||||
}
|
}
|
||||||
$item = $arr;
|
$item = $arr;
|
||||||
});
|
});
|
||||||
if ($tipos) {
|
|
||||||
usort($tipos, function($a, $b) {
|
usort($tipos, function($a, $b) {
|
||||||
return strcmp($a['descripcion'], $b['descripcion']);
|
return strcmp($a['descripcion'], $b['descripcion']);
|
||||||
});
|
});
|
||||||
|
@ -37,7 +37,7 @@ class TipoCategoria extends Model {
|
|||||||
protected $saldo;
|
protected $saldo;
|
||||||
public function saldo(Service $service = null) {
|
public function saldo(Service $service = null) {
|
||||||
if ($this->saldo === null) {
|
if ($this->saldo === null) {
|
||||||
$this->saldo = array_reduce($this->categorias(), function($sum, $item) use ($service) {
|
$this->saldo = array_reduce($this->categorias() ?? [], function($sum, $item) use ($service) {
|
||||||
return $sum + $item->saldo($service);
|
return $sum + $item->saldo($service);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user