FIX: cuentas
This commit is contained in:
@ -15,9 +15,11 @@ class Categorias {
|
|||||||
$categorias = $factory->find(Categoria::class)->many();
|
$categorias = $factory->find(Categoria::class)->many();
|
||||||
array_walk($categorias, function(&$item) use ($service) {
|
array_walk($categorias, function(&$item) use ($service) {
|
||||||
$arr = $item->toArray();
|
$arr = $item->toArray();
|
||||||
|
if ($item->cuentas()) {
|
||||||
$arr['cuentas'] = array_map(function($item) {
|
$arr['cuentas'] = array_map(function($item) {
|
||||||
return $item->toArray();
|
return $item->toArray();
|
||||||
}, $item->cuentas());
|
}, $item->cuentas());
|
||||||
|
}
|
||||||
$maps = ['activo', 'pasivo', 'ganancia', 'perdida'];
|
$maps = ['activo', 'pasivo', 'ganancia', 'perdida'];
|
||||||
foreach ($maps as $m) {
|
foreach ($maps as $m) {
|
||||||
$p = $m . 's';
|
$p = $m . 's';
|
||||||
|
@ -12,8 +12,13 @@ class Cuentas {
|
|||||||
use Json;
|
use Json;
|
||||||
|
|
||||||
public function __invoke(Request $request, Response $response, Factory $factory): Response {
|
public function __invoke(Request $request, Response $response, Factory $factory): Response {
|
||||||
$cuentas = $factory->find(Cuenta::class)->array();
|
$cuentas = $factory->find(Cuenta::class)->many();
|
||||||
if ($cuentas) {
|
if ($cuentas) {
|
||||||
|
array_walk($cuentas, function (&$item) {
|
||||||
|
$arr = $item->toArray();
|
||||||
|
$arr['categoria'] = $item->categoria()->toArray();
|
||||||
|
$item = $arr;
|
||||||
|
});
|
||||||
usort($cuentas, function($a, $b) {
|
usort($cuentas, function($a, $b) {
|
||||||
$t = strcmp($a['tipo']['descripcion'], $b['tipo']['descripcion']);
|
$t = strcmp($a['tipo']['descripcion'], $b['tipo']['descripcion']);
|
||||||
if ($t != 0) {
|
if ($t != 0) {
|
||||||
|
@ -89,4 +89,10 @@ class Categoria extends Model {
|
|||||||
}
|
}
|
||||||
return $this->saldo;
|
return $this->saldo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function toArray(): array {
|
||||||
|
$arr = parent::toArray();
|
||||||
|
$arr['tipo'] = $this->tipo()->toArray();
|
||||||
|
return $arr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user