[demo] add sheet file
This commit is contained in:
parent
a29a44799d
commit
2f82b33c22
|
@ -1,5 +1,6 @@
|
|||
paisa.db
|
||||
/paisa.yaml
|
||||
/Schedule AL.paisa
|
||||
/paisa
|
||||
/sample
|
||||
web/static
|
||||
|
|
|
@ -60,6 +60,7 @@ db_path: '%s'
|
|||
func Demo(cwd string) {
|
||||
generateConfigFile(cwd)
|
||||
generateJournalFile(cwd)
|
||||
generateSheetFile(cwd)
|
||||
}
|
||||
|
||||
func generateConfigFile(cwd string) {
|
||||
|
@ -112,6 +113,9 @@ schedule_al:
|
|||
- code: liability
|
||||
accounts:
|
||||
- Liabilities:Homeloan
|
||||
- code: immovable
|
||||
accounts:
|
||||
- Assets:House
|
||||
commodities:
|
||||
- name: NIFTY
|
||||
type: mutualfund
|
||||
|
@ -457,3 +461,37 @@ func generateJournalFile(cwd string) {
|
|||
|
||||
emitChitFund(&state)
|
||||
}
|
||||
|
||||
func generateSheetFile(cwd string) {
|
||||
sheetFilePath := filepath.Join(cwd, "Schedule AL.paisa")
|
||||
sheet := `
|
||||
date_query = {date <= [2023-03-31]}
|
||||
cost_basis(x) = cost(fifo(x AND date_query))
|
||||
cost_basis_negative(x) = cost(fifo(negate(x AND date_query)))
|
||||
|
||||
# Immovable
|
||||
immovable = cost_basis({account = Assets:House})
|
||||
|
||||
# Movable
|
||||
metal = 0
|
||||
art = 0
|
||||
vehicle = 0
|
||||
bank = cost_basis({account =~ /^Assets:Checking/})
|
||||
share = cost_basis({account =~ /^Assets:Equity:.*/ OR
|
||||
account =~ /^Assets:Debt:.*/})
|
||||
insurance = 0
|
||||
loan = 0
|
||||
cash = 0
|
||||
|
||||
# Liability
|
||||
liability = cost_basis_negative({account =~ /^Liabilities:Homeloan/})
|
||||
|
||||
# Total
|
||||
total = immovable + metal + art + vehicle + bank + share + insurance + loan + cash - liability
|
||||
`
|
||||
log.Info("Generating sheet file: ", sheetFilePath)
|
||||
err := os.WriteFile(sheetFilePath, []byte(sheet), 0644)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,19 @@ function cost(env: Environment, q: PostingsOrQuery): BigNumber {
|
|||
return ps.reduce((acc, p) => acc.plus(new BigNumber(p.amount)), new BigNumber(0));
|
||||
}
|
||||
|
||||
function negate(env: Environment, q: PostingsOrQuery): Posting[] {
|
||||
assertType("Postings", q);
|
||||
|
||||
const ps = toPostings(env, q);
|
||||
return ps.map((p) => {
|
||||
p = { ...p };
|
||||
p.quantity = -p.quantity;
|
||||
p.amount = -p.amount;
|
||||
p.market_amount = -p.market_amount;
|
||||
return p;
|
||||
});
|
||||
}
|
||||
|
||||
function fifo(env: Environment, q: PostingsOrQuery): Posting[] {
|
||||
assertType("Postings", q);
|
||||
|
||||
|
@ -32,7 +45,13 @@ function fifo(env: Environment, q: PostingsOrQuery): Posting[] {
|
|||
if (a.quantity > quantity) {
|
||||
const diff = a.quantity - quantity;
|
||||
const price = a.amount / a.quantity;
|
||||
available.unshift({ ...a, quantity: diff, amount: diff * price });
|
||||
const marketPrice = a.market_amount / a.quantity;
|
||||
available.unshift({
|
||||
...a,
|
||||
quantity: diff,
|
||||
amount: diff * price,
|
||||
market_amount: diff * marketPrice
|
||||
});
|
||||
quantity = 0;
|
||||
} else {
|
||||
quantity -= a.quantity;
|
||||
|
@ -53,4 +72,4 @@ function toPostings(env: Environment, q: PostingsOrQuery) {
|
|||
return q.resolve(env);
|
||||
}
|
||||
|
||||
export const functions = { cost, fifo };
|
||||
export const functions = { cost, fifo, negate };
|
||||
|
|
|
@ -48,10 +48,10 @@
|
|||
<div class="container is-fluid">
|
||||
<div class="columns">
|
||||
<div class="column is-6 mx-auto">
|
||||
<div class="box px-3">
|
||||
<div class="flex items-center justify-center mt-5">
|
||||
<div class="field">
|
||||
<p class="control">
|
||||
<button class="button is-link" on:click={(_e) => openCreateModal()}>
|
||||
<button class="button is-medium is-link" on:click={(_e) => openCreateModal()}>
|
||||
<span class="icon is-small">
|
||||
<i class="fas fa-file-circle-plus" />
|
||||
</span>
|
||||
|
|
Loading…
Reference in New Issue