diff --git a/src/html/api/entry.php b/src/html/api/entry.php
index f1bbf6b..fa684a7 100644
--- a/src/html/api/entry.php
+++ b/src/html/api/entry.php
@@ -129,21 +129,17 @@ class EntryAPI extends RestAPI {
protected function get_months() {
- $year=$this->_request['year'];
+ $account=$this->_request['account'];
$connection=$this->get_db_connection();
- $statement=$connection->prepare("select distinct extract(month from value_date) as month from entry where value_date between date (:year || '-01-01') and date(:year || '-01-01') + interval '1 year' - interval '1 day' order by month desc");
- $statement->bindParam("year", $year);
+ $statement=$connection->prepare("select distinct extract(year from value_date) as year, extract(month from value_date) as month from entry where account_id = :account order by year, month");
+ $statement->bindParam("account", $account);
$return=$statement->execute();
if($return) {
- $result=[];
- foreach($statement->fetchAll(PDO::FETCH_NUM) as $value) {
- array_push($result, $value[0]);
- }
- $this->response($result);
+ $this->response($statement->fetchAll(PDO::FETCH_ASSOC));
} else {
$this->response($statement->errorInfo()[2], 500);
}
diff --git a/src/html/index.html b/src/html/index.html
index 01689b8..4862ccd 100644
--- a/src/html/index.html
+++ b/src/html/index.html
@@ -24,24 +24,28 @@
Add entry
-
+
+
-
-
-
- Value date |
- Op. date |
- Label |
- Value |
- Sold |
- Pointed sold |
- Actions |
-
-
+
+
+
+ Value date |
+ Op. date |
+ Label |
+ Value |
+ Sold |
+ P. sold |
+ Actions |
+
+
-
-
-
+
+
+
+
diff --git a/src/html/js/entries.js b/src/html/js/entries.js
index cb959bd..0bc0157 100644
--- a/src/html/js/entries.js
+++ b/src/html/js/entries.js
@@ -32,8 +32,6 @@ var ListViewModel = function() {
self.entries = ko.observableArray([]);
- self.years = ko.observableArray();
- self.year = ko.observable();
self.months = ko.observableArray();
self.month = ko.observable();
@@ -45,7 +43,7 @@ var ListViewModel = function() {
self.savedItem = ko.observable();
self.loadEntries = function() {
- $.post("api/entry.php", {action: "get_entries", account: self.account().id, year: self.year(), month:self.month()}, function(data) {
+ $.post("api/entry.php", {action: "get_entries", account: self.account().id, year: self.month().year, month:self.month().month}, function(data) {
self.entries.removeAll();
self.selectedItem(null);
@@ -165,6 +163,10 @@ var ListViewModel = function() {
}
};
+ self.changeMonth = function(month) {
+ self.month(month);
+ };
+
self.loadAccounts = function() {
$.post("api/entry.php", {action: "get_accounts"}).success(function (result) {
self.accounts(result);
@@ -175,29 +177,17 @@ var ListViewModel = function() {
});
};
- self.loadYears = function(account) {
- $.post("api/entry.php", {action: "get_years", account: account.id}).success(function (result) {
- self.years(result);
-
- if(! self.year()){
- self.year(result[0]);
- }
- });
- };
-
- self.loadMonths = function(year){
- $.post("api/entry.php", {action: "get_months", year: year}).success(function (result) {
+ self.loadMonths = function(account){
+ $.post("api/entry.php", {action: "get_months", account: account.id}).success(function (result) {
self.months(result);
if(! self.month()) {
- self.month(result[0]);
+ self.month(result[result.length - 1]);
}
});
};
- self.account.subscribe(self.loadYears);
-
- self.year.subscribe(self.loadMonths);
+ self.account.subscribe(self.loadMonths);
self.month.subscribe(self.loadEntries);