Cambios al api revisado en UI
This commit is contained in:
@ -12,6 +12,15 @@ class Entradas {
|
|||||||
|
|
||||||
public function __invoke(Request $request, Response $response, Factory $factory): Response {
|
public function __invoke(Request $request, Response $response, Factory $factory): Response {
|
||||||
$entradas = $factory->find(Entrada::class)->array();
|
$entradas = $factory->find(Entrada::class)->array();
|
||||||
|
if ($entradas !== null) {
|
||||||
|
usort($entradas, function($a, $b) {
|
||||||
|
$d = $a['fecha'] - $b['fecha'];
|
||||||
|
if ($d === 0) {
|
||||||
|
return strcmp($a['cuenta']['nombre'], $b['cuenta']['nombre']);
|
||||||
|
}
|
||||||
|
return $d;
|
||||||
|
});
|
||||||
|
}
|
||||||
$output = [
|
$output = [
|
||||||
'entradas' => $entradas
|
'entradas' => $entradas
|
||||||
];
|
];
|
||||||
|
@ -69,6 +69,13 @@ class Fuentes {
|
|||||||
if ($fuente !== null) {
|
if ($fuente !== null) {
|
||||||
$entradas = $fuente->entradas();
|
$entradas = $fuente->entradas();
|
||||||
if ($entradas !== null) {
|
if ($entradas !== null) {
|
||||||
|
usort($entradas, function($a, $b) {
|
||||||
|
$d = $a->fecha()->diffInDays($b->fecha(), false);
|
||||||
|
if ($d === 0) {
|
||||||
|
return strcmp($a->cuenta()->nombre, $b->cuenta()->nombre);
|
||||||
|
}
|
||||||
|
return $d;
|
||||||
|
});
|
||||||
array_walk($entradas, function(&$item) {
|
array_walk($entradas, function(&$item) {
|
||||||
$item = $item->toArray();
|
$item = $item->toArray();
|
||||||
});
|
});
|
||||||
|
@ -10,6 +10,22 @@ server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
location ~ \.php$ {
|
location ~ \.php$ {
|
||||||
|
if ($request_method = 'OPTIONS') {
|
||||||
|
add_header 'Access-Control-Max-Age' 1728000;
|
||||||
|
add_header 'Access-Control-Allow-Origin' '*';
|
||||||
|
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,
|
||||||
|
X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
|
||||||
|
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH';
|
||||||
|
add_header 'Content-Type' 'application/json';
|
||||||
|
add_header 'Content-Length' 0;
|
||||||
|
return 204;
|
||||||
|
}
|
||||||
|
|
||||||
|
add_header 'Access-Control-Allow-Origin' '*';
|
||||||
|
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,
|
||||||
|
X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
|
||||||
|
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH';
|
||||||
|
|
||||||
try_files $uri =404;
|
try_files $uri =404;
|
||||||
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||||
fastcgi_pass api:9000;
|
fastcgi_pass api:9000;
|
||||||
|
@ -8,12 +8,14 @@ use ProVM\Common\Alias\Model;
|
|||||||
* @property int $id
|
* @property int $id
|
||||||
* @property \DateTime $fecha
|
* @property \DateTime $fecha
|
||||||
* @property Fuente $fuente_id
|
* @property Fuente $fuente_id
|
||||||
|
* @property string $glosa
|
||||||
|
* @property string $detalle
|
||||||
* @property Cuenta $cuenta_id
|
* @property Cuenta $cuenta_id
|
||||||
* @property double $valor
|
* @property double $valor
|
||||||
*/
|
*/
|
||||||
class Entrada extends Model {
|
class Entrada extends Model {
|
||||||
public static $_table = 'entradas';
|
public static $_table = 'entradas';
|
||||||
protected static $fields = ['fecha', 'fuente_id', 'cuenta_id', 'value'];
|
protected static $fields = ['fecha', 'fuente_id', 'glosa', 'detalle', 'cuenta_id', 'valor'];
|
||||||
|
|
||||||
protected $fuente;
|
protected $fuente;
|
||||||
public function fuente() {
|
public function fuente() {
|
||||||
@ -25,7 +27,7 @@ class Entrada extends Model {
|
|||||||
protected $cuenta;
|
protected $cuenta;
|
||||||
public function cuenta() {
|
public function cuenta() {
|
||||||
if ($this->cuenta === null) {
|
if ($this->cuenta === null) {
|
||||||
$this->cuenta = $this->childOf(Cuente::class, [Model::SELF_KEY => 'cuenta_id']);
|
$this->cuenta = $this->childOf(Cuenta::class, [Model::SELF_KEY => 'cuenta_id']);
|
||||||
}
|
}
|
||||||
return $this->cuenta;
|
return $this->cuenta;
|
||||||
}
|
}
|
||||||
@ -35,4 +37,13 @@ class Entrada extends Model {
|
|||||||
}
|
}
|
||||||
$this->fecha = $fecha->format('Y-m-d');
|
$this->fecha = $fecha->format('Y-m-d');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function toArray(): array {
|
||||||
|
$arr = parent::toArray();
|
||||||
|
$arr['fuente'] = $this->fuente()->toArray();
|
||||||
|
$arr['cuenta'] = $this->cuenta()->toArray();
|
||||||
|
$arr['fechaFormateada'] = $this->fecha()->format('d-m-Y');
|
||||||
|
$arr['valorFormateado'] = '$' . number_format($this->valor, 0, ',', '.');
|
||||||
|
return $arr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,18 @@ class Fuente extends Model {
|
|||||||
}
|
}
|
||||||
return $this->banco;
|
return $this->banco;
|
||||||
}
|
}
|
||||||
|
protected $saldo;
|
||||||
|
public function saldo() {
|
||||||
|
if ($this->saldo === null) {
|
||||||
|
$this->saldo = 0;
|
||||||
|
if ($this->entradas() !== null) {
|
||||||
|
$this->saldo = array_reduce($this->entradas(), function($sum, $item) {
|
||||||
|
return $sum + $item->valor;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this->saldo;
|
||||||
|
}
|
||||||
|
|
||||||
protected $entradas;
|
protected $entradas;
|
||||||
public function entradas() {
|
public function entradas() {
|
||||||
@ -39,6 +51,8 @@ class Fuente extends Model {
|
|||||||
$arr = parent::toArray();
|
$arr = parent::toArray();
|
||||||
$arr['tipo'] = $this->tipo()->toArray();
|
$arr['tipo'] = $this->tipo()->toArray();
|
||||||
$arr['banco'] = $this->banco()->toArray();
|
$arr['banco'] = $this->banco()->toArray();
|
||||||
|
$arr['saldo'] = $this->saldo();
|
||||||
|
$arr['saldoFormateado'] = '$' . number_format($this->saldo(), 0, ',', '.');
|
||||||
return $arr;
|
return $arr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user