mirror of
https://github.com/gwenhael-le-moine/credger.git
synced 2025-01-13 20:02:06 +01:00
clik on line to display register
This commit is contained in:
parent
ab80bb8be2
commit
e3d6504b22
7 changed files with 86 additions and 79 deletions
51
credger.cr
51
credger.cr
|
@ -10,31 +10,22 @@ ledger = Ledger.new
|
||||||
# Matches GET "http://host:port/"
|
# Matches GET "http://host:port/"
|
||||||
get "/" do |env|
|
get "/" do |env|
|
||||||
env.response.content_type = "text/html"
|
env.response.content_type = "text/html"
|
||||||
send_file env, "./public/index.html"
|
|
||||||
|
send_file( env, "./public/index.html" )
|
||||||
|
end
|
||||||
|
|
||||||
|
get "/api/ledger/version" do |env|
|
||||||
|
env.response.content_type = "text"
|
||||||
|
|
||||||
|
ledger.version
|
||||||
end
|
end
|
||||||
|
|
||||||
get "/api/ledger/accounts" do |env|
|
get "/api/ledger/accounts" do |env|
|
||||||
env.response.content_type = "application/json"
|
env.response.content_type = "application/json"
|
||||||
|
|
||||||
ledger.accounts.to_json
|
ledger.accounts.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
# get "/api/ledger/accounts/depth/:depth/?" do |env|
|
|
||||||
# env.response.content_type = "application/json"
|
|
||||||
# ledger.accounts( ).to_json
|
|
||||||
# end
|
|
||||||
|
|
||||||
# get "/api/ledger/dates_salaries/?" do |env|
|
|
||||||
# env.response.content_type = "application/json"
|
|
||||||
# ledger.dates_salaries( "salaire" ).to_json
|
|
||||||
# end
|
|
||||||
|
|
||||||
# get "/api/ledger/register/?" do |env|
|
|
||||||
# env.response.content_type = "application/json"
|
|
||||||
# { key: params[ :categories ],
|
|
||||||
# values: ledger.register( params[ :period ], params[ :categories ] ) }
|
|
||||||
# .to_json
|
|
||||||
# end
|
|
||||||
|
|
||||||
get "/api/ledger/balance" do |env|
|
get "/api/ledger/balance" do |env|
|
||||||
env.response.content_type = "application/json"
|
env.response.content_type = "application/json"
|
||||||
|
|
||||||
|
@ -47,27 +38,19 @@ get "/api/ledger/balance" do |env|
|
||||||
.to_json
|
.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
# get "/api/ledger/cleared/?" do |env|
|
|
||||||
# env.response.content_type = "application/json"
|
|
||||||
# ledger.cleared().to_json
|
|
||||||
# end
|
|
||||||
|
|
||||||
# get "/api/ledger/budget/?" do |env|
|
|
||||||
# env.response.content_type = "application/json"
|
|
||||||
# ledger.budget( params[ :period ],
|
|
||||||
# params[ :categories ] ).to_json
|
|
||||||
# end
|
|
||||||
|
|
||||||
get "/api/ledger/graph_values" do |env|
|
get "/api/ledger/graph_values" do |env|
|
||||||
env.response.content_type = "application/json"
|
env.response.content_type = "application/json"
|
||||||
|
|
||||||
ledger.graph_values( env.params.query["period"], env.params.query["categories"].split(" ") ).to_json
|
ledger.graph_values( env.params.query["period"], env.params.query["categories"].split(" ") ).to_json
|
||||||
#ledger.graph_values.to_json
|
|
||||||
end
|
end
|
||||||
|
|
||||||
get "/api/ledger/version" do |env|
|
get "/api/ledger/register" do |env|
|
||||||
env.response.content_type = "text"
|
env.response.content_type = "application/json"
|
||||||
ledger.version
|
|
||||||
|
{ key: env.params.query[ "categories" ],
|
||||||
|
values: ledger.register( env.params.query[ "period" ],
|
||||||
|
env.params.query[ "categories" ].split(" ") ) }
|
||||||
|
.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
Kemal.run 9292
|
Kemal.run
|
||||||
|
|
15
ledger.cr
15
ledger.cr
|
@ -1,6 +1,7 @@
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
|
||||||
require "csv"
|
require "csv"
|
||||||
|
require "xml"
|
||||||
|
|
||||||
# Crystal wrapper module for calling ledger
|
# Crystal wrapper module for calling ledger
|
||||||
class Ledger
|
class Ledger
|
||||||
|
@ -70,4 +71,18 @@ class Ledger
|
||||||
|
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def register( period : String = "", categories : Array(String) = ["Expenses"] ) : Array( NamedTuple( date: String, payee: String, account: String, amount: String, currency: String ) )
|
||||||
|
period = period == "" ? "" : "-p '#{period}'"
|
||||||
|
|
||||||
|
CSV
|
||||||
|
.parse( run( "--exchange '#{CURRENCY}' #{period}", "csv --no-revalued", categories.join(" ") ) )
|
||||||
|
.map do |row|
|
||||||
|
{ date: row[ 0 ],
|
||||||
|
payee: row[ 2 ],
|
||||||
|
account: row[ 3 ],
|
||||||
|
amount: row[ 5 ],
|
||||||
|
currency: row[ 4 ] }
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
<script src="/vendor/node_modules/hammerjs/hammer.min.js"></script>
|
<script src="/vendor/node_modules/hammerjs/hammer.min.js"></script>
|
||||||
<script src="/vendor/node_modules/d3/d3.min.js"></script>
|
<script src="/vendor/node_modules/d3/d3.min.js"></script>
|
||||||
<script src="/vendor/node_modules/nvd3/build/nv.d3.min.js"></script>
|
<script src="/vendor/node_modules/nvd3/build/nv.d3.min.js"></script>
|
||||||
|
<script src="/vendor/node_modules/sweetalert2/dist/sweetalert2.all.min.js"></script>
|
||||||
|
|
||||||
<script src="/vendor/node_modules/angular/angular.min.js"></script>
|
<script src="/vendor/node_modules/angular/angular.min.js"></script>
|
||||||
<script src="/vendor/node_modules/angular-i18n/angular-locale_en-us.js"></script>
|
<script src="/vendor/node_modules/angular-i18n/angular-locale_en-us.js"></script>
|
||||||
|
|
|
@ -30,17 +30,44 @@ app.component('bucket',
|
||||||
duration: 500,
|
duration: 500,
|
||||||
labelThreshold: 0.01,
|
labelThreshold: 0.01,
|
||||||
labelSunbeamLayout: true,
|
labelSunbeamLayout: true,
|
||||||
labelsOutside: true
|
labelsOutside: true,
|
||||||
|
multibar: {
|
||||||
|
dispatch: {
|
||||||
|
elementClick: (event) => {
|
||||||
|
API.register(ctrl.period, event.data.account)
|
||||||
|
.then(function success(response) {
|
||||||
|
let format_transaction = (transaction) => {
|
||||||
|
return `
|
||||||
|
<tr>
|
||||||
|
<td>${transaction.date}</td>
|
||||||
|
<td>${transaction.payee}</td>
|
||||||
|
<td style="text-align: right;">${transaction.amount} ${transaction.currency}</td>
|
||||||
|
</tr>`;
|
||||||
|
};
|
||||||
|
|
||||||
|
swal({
|
||||||
|
title: response.data.key,
|
||||||
|
html: `<table style="width: 100%;">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<td>Date</td><td>Payee</td><td>Amount</td>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
${response.data.values.map(function(transaction) { return format_transaction(transaction); }).join("")}
|
||||||
|
</tbody>
|
||||||
|
<tfoot><td></td><td>Total</td><td style="text-align: right;">${event.data.amount} €</td></tfoot>
|
||||||
|
</table>`});
|
||||||
|
}, function error(response) { alert("error!"); });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ctrl.$onChanges = (changes) => {
|
ctrl.$onChanges = (changes) => {
|
||||||
if (changes.period && changes.period.currentValue != undefined) {
|
if (changes.period && changes.period.currentValue != undefined) {
|
||||||
API.balance({
|
API.balance(ctrl.period, ctrl.categories, ctrl.depth)
|
||||||
period: ctrl.period,
|
|
||||||
categories: ctrl.categories,
|
|
||||||
depth: ctrl.depth
|
|
||||||
})
|
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
ctrl.raw_data = _(response.data)
|
ctrl.raw_data = _(response.data)
|
||||||
.sortBy((account) => { return account.amount; })
|
.sortBy((account) => { return account.amount; })
|
||||||
|
@ -81,7 +108,7 @@ app.component('bucket',
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
template: `
|
template: `
|
||||||
<div class="bucket">
|
<div class="bucket">
|
||||||
<div class="tollbar">
|
<div class="tollbar">
|
||||||
<span ng:repeat="account in $ctrl.total_detailed">{{account.account}} = {{account.amount | number:2}} €</span>
|
<span ng:repeat="account in $ctrl.total_detailed">{{account.account}} = {{account.amount | number:2}} €</span>
|
||||||
|
|
|
@ -5,8 +5,8 @@ app.component('dashboard',
|
||||||
let ctrl = this;
|
let ctrl = this;
|
||||||
ctrl.graphed_accounts = ['Expenses', 'Income'];
|
ctrl.graphed_accounts = ['Expenses', 'Income'];
|
||||||
|
|
||||||
let retrieve_graph_values = (params) => {
|
let retrieve_graph_values = (period, categories) => {
|
||||||
API.graph_values(params)
|
API.graph_values(period, categories)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
ctrl.periods = [];
|
ctrl.periods = [];
|
||||||
|
|
||||||
|
@ -111,10 +111,7 @@ app.component('dashboard',
|
||||||
ctrl.accounts = ctrl.raw_accounts.map((account_ary) => { return account_ary.join(':'); });
|
ctrl.accounts = ctrl.raw_accounts.map((account_ary) => { return account_ary.join(':'); });
|
||||||
});
|
});
|
||||||
|
|
||||||
retrieve_graph_values({
|
retrieve_graph_values('', ctrl.graphed_accounts.join(' '));
|
||||||
period: '',
|
|
||||||
categories: ctrl.graphed_accounts.join(' ')
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|
|
@ -3,52 +3,35 @@ app.service('API',
|
||||||
function($http) {
|
function($http) {
|
||||||
let API = this;
|
let API = this;
|
||||||
|
|
||||||
API.balance = function(params) {
|
API.balance = _.memoize(function(period, categories, depth) {
|
||||||
return $http.get('/api/ledger/balance', {
|
return $http.get('/api/ledger/balance', {
|
||||||
params: {
|
params: {
|
||||||
period: params.period,
|
period: period,
|
||||||
categories: params.categories,
|
categories: categories,
|
||||||
depth: params.depth
|
depth: depth
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
});
|
||||||
|
|
||||||
API.register = function(params) {
|
API.register = _.memoize(function(period, categories) {
|
||||||
return $http.get('/api/ledger/register', {
|
return $http.get('/api/ledger/register', {
|
||||||
params: {
|
params: {
|
||||||
period: params.period,
|
period: period,
|
||||||
categories: params.categories
|
categories: categories
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
});
|
||||||
|
|
||||||
API.graph_values = function(params) {
|
API.graph_values = _.memoize(function(period, categories) {
|
||||||
return $http.get('/api/ledger/graph_values', {
|
return $http.get('/api/ledger/graph_values', {
|
||||||
params: {
|
params: {
|
||||||
period: params.period,
|
period: period,
|
||||||
categories: params.categories
|
categories: categories
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
});
|
||||||
|
|
||||||
API.budget = function(params) {
|
API.accounts = _.memoize(function() {
|
||||||
return $http.get('/api/ledger/budget', {
|
|
||||||
params: {
|
|
||||||
period: params.period,
|
|
||||||
categories: params.categories
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
API.dates_salaries = function() {
|
|
||||||
return $http.get('/ai/ledger/dates_salaries');
|
|
||||||
};
|
|
||||||
|
|
||||||
API.accounts = function() {
|
|
||||||
return $http.get('/api/ledger/accounts');
|
return $http.get('/api/ledger/accounts');
|
||||||
};
|
});
|
||||||
|
|
||||||
API.cleared = function() {
|
|
||||||
return $http.get('/api/ledger/cleared');
|
|
||||||
};
|
|
||||||
}]);
|
}]);
|
||||||
|
|
1
public/vendor/package.json
vendored
1
public/vendor/package.json
vendored
|
@ -35,6 +35,7 @@
|
||||||
"hammerjs": "^2.0.8",
|
"hammerjs": "^2.0.8",
|
||||||
"moment": "^2.19.2",
|
"moment": "^2.19.2",
|
||||||
"nvd3": "^1.8.4",
|
"nvd3": "^1.8.4",
|
||||||
|
"sweetalert2": "^7.0.3",
|
||||||
"typescript": "^2.6.1",
|
"typescript": "^2.6.1",
|
||||||
"underscore": "^1.8.3"
|
"underscore": "^1.8.3"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue