Skip to content

Commit 2f82b33

Browse files
[demo] add sheet file
1 parent a29a447 commit 2f82b33

File tree

4 files changed

+62
-4
lines changed

4 files changed

+62
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
paisa.db
22
/paisa.yaml
3+
/Schedule AL.paisa
34
/paisa
45
/sample
56
web/static

internal/generator/config.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ db_path: '%s'
6060
func Demo(cwd string) {
6161
generateConfigFile(cwd)
6262
generateJournalFile(cwd)
63+
generateSheetFile(cwd)
6364
}
6465

6566
func generateConfigFile(cwd string) {
@@ -112,6 +113,9 @@ schedule_al:
112113
- code: liability
113114
accounts:
114115
- Liabilities:Homeloan
116+
- code: immovable
117+
accounts:
118+
- Assets:House
115119
commodities:
116120
- name: NIFTY
117121
type: mutualfund
@@ -457,3 +461,37 @@ func generateJournalFile(cwd string) {
457461

458462
emitChitFund(&state)
459463
}
464+
465+
func generateSheetFile(cwd string) {
466+
sheetFilePath := filepath.Join(cwd, "Schedule AL.paisa")
467+
sheet := `
468+
date_query = {date <= [2023-03-31]}
469+
cost_basis(x) = cost(fifo(x AND date_query))
470+
cost_basis_negative(x) = cost(fifo(negate(x AND date_query)))
471+
472+
# Immovable
473+
immovable = cost_basis({account = Assets:House})
474+
475+
# Movable
476+
metal = 0
477+
art = 0
478+
vehicle = 0
479+
bank = cost_basis({account =~ /^Assets:Checking/})
480+
share = cost_basis({account =~ /^Assets:Equity:.*/ OR
481+
account =~ /^Assets:Debt:.*/})
482+
insurance = 0
483+
loan = 0
484+
cash = 0
485+
486+
# Liability
487+
liability = cost_basis_negative({account =~ /^Liabilities:Homeloan/})
488+
489+
# Total
490+
total = immovable + metal + art + vehicle + bank + share + insurance + loan + cash - liability
491+
`
492+
log.Info("Generating sheet file: ", sheetFilePath)
493+
err := os.WriteFile(sheetFilePath, []byte(sheet), 0644)
494+
if err != nil {
495+
log.Fatal(err)
496+
}
497+
}

src/lib/sheet/functions.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ function cost(env: Environment, q: PostingsOrQuery): BigNumber {
1212
return ps.reduce((acc, p) => acc.plus(new BigNumber(p.amount)), new BigNumber(0));
1313
}
1414

15+
function negate(env: Environment, q: PostingsOrQuery): Posting[] {
16+
assertType("Postings", q);
17+
18+
const ps = toPostings(env, q);
19+
return ps.map((p) => {
20+
p = { ...p };
21+
p.quantity = -p.quantity;
22+
p.amount = -p.amount;
23+
p.market_amount = -p.market_amount;
24+
return p;
25+
});
26+
}
27+
1528
function fifo(env: Environment, q: PostingsOrQuery): Posting[] {
1629
assertType("Postings", q);
1730

@@ -32,7 +45,13 @@ function fifo(env: Environment, q: PostingsOrQuery): Posting[] {
3245
if (a.quantity > quantity) {
3346
const diff = a.quantity - quantity;
3447
const price = a.amount / a.quantity;
35-
available.unshift({ ...a, quantity: diff, amount: diff * price });
48+
const marketPrice = a.market_amount / a.quantity;
49+
available.unshift({
50+
...a,
51+
quantity: diff,
52+
amount: diff * price,
53+
market_amount: diff * marketPrice
54+
});
3655
quantity = 0;
3756
} else {
3857
quantity -= a.quantity;
@@ -53,4 +72,4 @@ function toPostings(env: Environment, q: PostingsOrQuery) {
5372
return q.resolve(env);
5473
}
5574

56-
export const functions = { cost, fifo };
75+
export const functions = { cost, fifo, negate };

src/routes/(app)/more/sheets/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@
4848
<div class="container is-fluid">
4949
<div class="columns">
5050
<div class="column is-6 mx-auto">
51-
<div class="box px-3">
51+
<div class="flex items-center justify-center mt-5">
5252
<div class="field">
5353
<p class="control">
54-
<button class="button is-link" on:click={(_e) => openCreateModal()}>
54+
<button class="button is-medium is-link" on:click={(_e) => openCreateModal()}>
5555
<span class="icon is-small">
5656
<i class="fas fa-file-circle-plus" />
5757
</span>

0 commit comments

Comments
 (0)