Improved UI, improved API, improved other things...

This commit is contained in:
Alexis Lahouze
2013-01-09 23:39:26 +01:00
parent 264ce12658
commit d361e827d4
3 changed files with 47 additions and 54 deletions

View File

@ -17,30 +17,14 @@ class EntryAPI extends RestAPI {
$account=$this->_request['account'];
$statement=$connection->prepare("select sum(value) as futuresold, sum(case when operation_date is not null then value else cast(0 as numeric) end) as pointedsold, sum(case when value_date <= now() then value else cast(0 as numeric) end) as currentsold from entry");
$return=$statement->execute();
if(!$return) {
$this->response($statement->errorInfo()[2], 500);
}
$pageInfos=$statement->fetch(PDO::FETCH_ASSOC);
$statement=$connection->prepare("select id, value_date, operation_date, label, value, account_id, sold, pointedSold from (select *, sum(value) over(order by value_date, operation_date, label desc, id desc) as sold, sum(value) over(partition by operation_date is not null order by value_date, operation_date, label desc, id desc) as pointedSold from entry where account_id=:account order by value_date desc, operation_date desc, label, id) as e where date_trunc('month', e.value_date) = :day ");
$statement->bindParam("day", $day);
$statement->bindParam("account", $account);
$return=$statement->execute();
$data=array(
"pointedSold"=>$pageInfos['pointedsold'],
"futureSold"=>$pageInfos['futuresold'],
"currentSold"=>$pageInfos['currentsold'],
"entries"=>$statement->fetchAll(PDO::FETCH_ASSOC));
if($return) {
$this->response($data);
$this->response($statement->fetchAll(PDO::FETCH_ASSOC));
} else {
$this->response($statement->errorInfo()[2], 500);
}
@ -93,7 +77,7 @@ class EntryAPI extends RestAPI {
protected function get_accounts() {
$connection=$this->get_db_connection();
$statement=$connection->prepare("select id, name from account order by name");
$statement=$connection->prepare("select account.id, account.name, sum(entry.value) as future, sum(case when entry.operation_date is not null then entry.value else cast(0 as numeric) end) as pointed, sum(case when entry.value_date <= now() then entry.value else cast(0 as numeric) end) as current from account join entry on (account.id = entry.account_id) group by account.id order by account.name");
$return=$statement->execute();