Current sold:
- Future sold:
- Pointed sold:
diff --git a/src/html/api/entry.php b/src/html/api/entry.php index de509b9..ff13390 100644 --- a/src/html/api/entry.php +++ b/src/html/api/entry.php @@ -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(); diff --git a/src/html/index.html b/src/html/index.html index 4862ccd..0d315c3 100644 --- a/src/html/index.html +++ b/src/html/index.html @@ -11,23 +11,32 @@
Current sold:
- Future sold:
- Pointed sold: