Improved UI, improved API, improved other things...
This commit is contained in:
parent
264ce12658
commit
d361e827d4
@ -17,30 +17,14 @@ class EntryAPI extends RestAPI {
|
|||||||
|
|
||||||
$account=$this->_request['account'];
|
$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=$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("day", $day);
|
||||||
$statement->bindParam("account", $account);
|
$statement->bindParam("account", $account);
|
||||||
|
|
||||||
$return=$statement->execute();
|
$return=$statement->execute();
|
||||||
|
|
||||||
$data=array(
|
|
||||||
"pointedSold"=>$pageInfos['pointedsold'],
|
|
||||||
"futureSold"=>$pageInfos['futuresold'],
|
|
||||||
"currentSold"=>$pageInfos['currentsold'],
|
|
||||||
"entries"=>$statement->fetchAll(PDO::FETCH_ASSOC));
|
|
||||||
|
|
||||||
if($return) {
|
if($return) {
|
||||||
$this->response($data);
|
$this->response($statement->fetchAll(PDO::FETCH_ASSOC));
|
||||||
} else {
|
} else {
|
||||||
$this->response($statement->errorInfo()[2], 500);
|
$this->response($statement->errorInfo()[2], 500);
|
||||||
}
|
}
|
||||||
@ -93,7 +77,7 @@ class EntryAPI extends RestAPI {
|
|||||||
protected function get_accounts() {
|
protected function get_accounts() {
|
||||||
$connection=$this->get_db_connection();
|
$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();
|
$return=$statement->execute();
|
||||||
|
|
||||||
|
@ -11,23 +11,32 @@
|
|||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<div class="row-fluid">
|
<div class="row-fluid">
|
||||||
<div class="span12">
|
<div class="span12">
|
||||||
<!--Body content-->
|
<div class="navbar navbar-fixed-top">
|
||||||
<h1>Entries</h1>
|
<div class="navbar-inner">
|
||||||
|
<a class="brand" href="#"> Comptes</a>
|
||||||
|
<ul class="nav" data-bind="foreach: accounts, value: account">
|
||||||
|
<li data-bind="css: { active: $data === $root.account() }"><a href="#" data-bind="click: $parent.selectAccount"><span data-bind="text: name"></span><br/>
|
||||||
|
current: <span data-bind="text: current, css: {'text-error': $data.current < 0 }"></span><br/>
|
||||||
|
pointed: <span data-bind="text: pointed, css: {'text-error': $data.pointed < 0 }"></span><br/>
|
||||||
|
future: <span data-bind="text: future, css: {'text-error': $data.future < 0 }"></span></a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="navbar navbar-fixed-bottom">
|
||||||
|
<div class="navbar-inner">
|
||||||
|
<ul data-bind="foreach: months()" class="nav">
|
||||||
|
<li data-bind="css: {'active': $data == $root.month()}"><a href="#" data-bind="click: $parent.selectMonth"><span data-bind="text: $data.year"></span>-<span data-bind="text: $data.month"></span></a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="content" style="margin-top: 120px; margin-bottom: 40px">
|
||||||
|
|
||||||
<div id="message-placeholder"></div>
|
<div id="message-placeholder"></div>
|
||||||
|
|
||||||
<p><select data-bind="options: accounts, optionsText: 'name', value: account"></select></p>
|
<a class="btn btn-primary" data-bind="click: $root.add" href="#" title="Add entry"><i class="icon-plus"></i> Add entry</a>
|
||||||
|
|
||||||
<p>Current sold: <span data-bind="text: currentSold, css: {'text-error': currentSold() < 0 }"></span><br />
|
|
||||||
Future sold: <span data-bind="text: futureSold, css: {'text-error': futureSold() < 0 }"></span></br />
|
|
||||||
Pointed sold: <span data-bind="text: pointedSold, css: {'text-error': pointedSold() < 0 }"></span></p>
|
|
||||||
|
|
||||||
<p><a class="btn btn-primary" data-bind="click: $root.add" href="#" title="Add entry"><i class="icon-plus"></i> Add entry</a></p>
|
|
||||||
|
|
||||||
<div class="tabbable">
|
|
||||||
<ul data-bind="foreach: months()" class="nav nav-tabs">
|
|
||||||
<li data-bind="css: {'active': $data == $root.month()}"><a href="#" data-bind="click: $parent.changeMonth"><span data-bind="text: $data.year"></span>-<span data-bind="text: $data.month"></span></a></li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<table class="table table-striped table-condensed table-hover">
|
<table class="table table-striped table-condensed table-hover">
|
||||||
<thead>
|
<thead>
|
||||||
|
@ -47,7 +47,7 @@ var ListViewModel = function() {
|
|||||||
self.entries.removeAll();
|
self.entries.removeAll();
|
||||||
self.selectedItem(null);
|
self.selectedItem(null);
|
||||||
|
|
||||||
$.each(data['entries'], function(index, element) {
|
$.each(data, function(index, element) {
|
||||||
self.entries.push(new entry({
|
self.entries.push(new entry({
|
||||||
id: element.id,
|
id: element.id,
|
||||||
value_date: new Date(element.value_date),
|
value_date: new Date(element.value_date),
|
||||||
@ -59,10 +59,24 @@ var ListViewModel = function() {
|
|||||||
pointedSold: element.operation_date ? element.pointedsold : ''
|
pointedSold: element.operation_date ? element.pointedsold : ''
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
self.currentSold(data['currentSold']);
|
self.loadAccounts = function() {
|
||||||
self.pointedSold(data['pointedSold']);
|
$.post("api/entry.php", {action: "get_accounts"}).success(function (result) {
|
||||||
self.futureSold(data['futureSold']);
|
self.accounts(result);
|
||||||
|
|
||||||
|
if(!self.account()){
|
||||||
|
self.account(result[0]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
self.loadMonths = function(account){
|
||||||
|
$.post("api/entry.php", {action: "get_months", account: account.id}).success(function (result) {
|
||||||
|
self.months(result);
|
||||||
|
|
||||||
|
self.month(result[result.length - 1]);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -155,7 +169,7 @@ var ListViewModel = function() {
|
|||||||
if (confirm('Are you sure you wish to delete this item?')) {
|
if (confirm('Are you sure you wish to delete this item?')) {
|
||||||
$.post("api/entry.php", {action: "remove_entry", entry:item}).success(function (result) {
|
$.post("api/entry.php", {action: "remove_entry", entry:item}).success(function (result) {
|
||||||
self.selectedItem(null);
|
self.selectedItem(null);
|
||||||
self.loadEntries();
|
self.loadAccounts();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -163,33 +177,19 @@ var ListViewModel = function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
self.changeMonth = function(month) {
|
self.selectMonth = function(month) {
|
||||||
self.month(month);
|
self.month(month);
|
||||||
};
|
};
|
||||||
|
|
||||||
self.loadAccounts = function() {
|
self.selectAccount = function(account) {
|
||||||
$.post("api/entry.php", {action: "get_accounts"}).success(function (result) {
|
self.account(account);
|
||||||
self.accounts(result);
|
|
||||||
|
|
||||||
if(! self.account()) {
|
|
||||||
self.account(result[0]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
self.loadMonths = function(account){
|
|
||||||
$.post("api/entry.php", {action: "get_months", account: account.id}).success(function (result) {
|
|
||||||
self.months(result);
|
|
||||||
|
|
||||||
self.month(result[result.length - 1]);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
self.account.subscribe(self.loadMonths);
|
self.account.subscribe(self.loadMonths);
|
||||||
|
|
||||||
self.month.subscribe(self.loadEntries);
|
self.month.subscribe(self.loadEntries);
|
||||||
|
|
||||||
self.loadAccounts();
|
$(document).ready(self.loadAccounts);
|
||||||
};
|
};
|
||||||
|
|
||||||
function dateToString(date) {
|
function dateToString(date) {
|
||||||
|
Loading…
Reference in New Issue
Block a user