mirror of
https://github.com/gwenhael-le-moine/ledgerrb.git
synced 2024-12-26 09:59:18 +01:00
APIs for balance and cleared balance
This commit is contained in:
parent
12a482b16e
commit
9f2ea4913d
2 changed files with 30 additions and 6 deletions
26
app.rb
26
app.rb
|
@ -40,6 +40,32 @@ class LedgerRbApp < Sinatra::Base
|
|||
end.to_json
|
||||
end
|
||||
|
||||
get '/api/ledger/balance/?' do
|
||||
content_type :json
|
||||
|
||||
Ledger.balance.to_json
|
||||
end
|
||||
|
||||
get '/api/ledger/balance/depth/:depth/?' do
|
||||
content_type :json
|
||||
param :depth, Integer, required: true
|
||||
|
||||
Ledger.balance( false, params[ :depth ] ).to_json
|
||||
end
|
||||
|
||||
get '/api/ledger/cleared/?' do
|
||||
content_type :json
|
||||
|
||||
Ledger.balance( true ).to_json
|
||||
end
|
||||
|
||||
get '/api/ledger/cleared/depth/:depth/?' do
|
||||
content_type :json
|
||||
param :depth, Integer, required: true
|
||||
|
||||
Ledger.balance( true, params[ :depth ] ).to_json
|
||||
end
|
||||
|
||||
get '/api/ledger/version/?' do
|
||||
content_type :json
|
||||
|
||||
|
|
|
@ -25,10 +25,6 @@ module Ledger
|
|||
end.uniq
|
||||
end
|
||||
|
||||
def cleared
|
||||
run '', 'cleared'
|
||||
end
|
||||
|
||||
def register( category, options='' )
|
||||
run( "#{options} --collapse --amount-data --exchange '€'", 'register', "#{category}" )
|
||||
.split( "\n" )
|
||||
|
@ -48,8 +44,10 @@ module Ledger
|
|||
register category, "--yearly"
|
||||
end
|
||||
|
||||
def balance( period = nil )
|
||||
def balance( cleared=false, depth=nil, period=nil )
|
||||
period = period.nil? ? '' : "-p #{period}"
|
||||
output run "--flat --exchange '€' #{period}", 'balance', "#{category}"
|
||||
depth = depth.nil? ? '' : "--depth #{depth}"
|
||||
operation = cleared ? 'cleared' : 'balance'
|
||||
run "--flat --exchange '€' #{period} #{depth}", operation
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue