@sachfolio/cas-reader 0.0.0-stage → 0.2.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/LICENSE +71 -0
- package/NOTICE +41 -0
- package/README.md +198 -2
- package/dist/analytics/contract.d.ts +110 -0
- package/dist/analytics/contract.js +79 -0
- package/dist/analytics/eligibility.d.ts +66 -0
- package/dist/analytics/eligibility.js +93 -0
- package/dist/analytics/gains-schema.d.ts +898 -0
- package/dist/analytics/gains-schema.js +170 -0
- package/dist/analytics/gains.d.ts +319 -0
- package/dist/analytics/gains.js +649 -0
- package/dist/analytics/modules.d.ts +33 -0
- package/dist/analytics/modules.js +74 -0
- package/dist/analytics/returns-schema.d.ts +931 -0
- package/dist/analytics/returns-schema.js +152 -0
- package/dist/analytics/returns.d.ts +126 -0
- package/dist/analytics/returns.js +453 -0
- package/dist/analytics/schedule112a.d.ts +77 -0
- package/dist/analytics/schedule112a.js +134 -0
- package/dist/analytics/xirr.d.ts +75 -0
- package/dist/analytics/xirr.js +314 -0
- package/dist/bin/cas.d.ts +2 -0
- package/dist/bin/cas.js +137 -0
- package/dist/checks.d.ts +49 -0
- package/dist/checks.js +227 -0
- package/dist/compat/casparser.d.ts +121 -0
- package/dist/compat/casparser.js +193 -0
- package/dist/detect.d.ts +10 -0
- package/dist/detect.js +69 -0
- package/dist/errors.d.ts +26 -0
- package/dist/errors.js +95 -0
- package/dist/export/csv.d.ts +21 -0
- package/dist/export/csv.js +49 -0
- package/dist/extract/browser.d.ts +17 -0
- package/dist/extract/browser.js +34 -0
- package/dist/extract/budget.d.ts +46 -0
- package/dist/extract/budget.js +88 -0
- package/dist/extract/node.d.ts +11 -0
- package/dist/extract/node.js +31 -0
- package/dist/extract/pdfjs.d.ts +71 -0
- package/dist/extract/pdfjs.js +244 -0
- package/dist/extract/types.d.ts +106 -0
- package/dist/extract/types.js +11 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +26 -0
- package/dist/layout/lines.d.ts +51 -0
- package/dist/layout/lines.js +115 -0
- package/dist/licence/app-licence.d.ts +53 -0
- package/dist/licence/app-licence.js +139 -0
- package/dist/licence/ed25519.d.ts +2 -0
- package/dist/licence/ed25519.js +103 -0
- package/dist/model.d.ts +148 -0
- package/dist/model.js +1 -0
- package/dist/num.d.ts +19 -0
- package/dist/num.js +27 -0
- package/dist/parse.d.ts +4 -0
- package/dist/parse.js +13 -0
- package/dist/parsers/cams/classify.d.ts +25 -0
- package/dist/parsers/cams/classify.js +103 -0
- package/dist/parsers/cams/detailed.d.ts +15 -0
- package/dist/parsers/cams/detailed.js +343 -0
- package/dist/parsers/cams/header.d.ts +47 -0
- package/dist/parsers/cams/header.js +170 -0
- package/dist/parsers/cams/investor.d.ts +28 -0
- package/dist/parsers/cams/investor.js +139 -0
- package/dist/parsers/cams/summary.d.ts +29 -0
- package/dist/parsers/cams/summary.js +413 -0
- package/dist/parsers/cams/table.d.ts +55 -0
- package/dist/parsers/cams/table.js +144 -0
- package/dist/parsers/cams/total.d.ts +17 -0
- package/dist/parsers/cams/total.js +105 -0
- package/dist/parsers/depository/mf.d.ts +22 -0
- package/dist/parsers/depository/mf.js +438 -0
- package/dist/privacy.d.ts +243 -0
- package/dist/privacy.js +256 -0
- package/dist/schema.d.ts +779 -0
- package/dist/schema.js +214 -0
- package/examples/nextjs/app/page.jsx +34 -0
- package/examples/node/server.mjs +45 -0
- package/examples/python/read_cas.py +67 -0
- package/examples/vite/index.html +14 -0
- package/examples/vite/main.js +22 -0
- package/package.json +54 -4
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gains@1 output (GainsOutput, analytics/gains.ts) as a runtime schema, the
|
|
3
|
+
* way returns-schema.ts mirrors xirr@1. Generates the committed
|
|
4
|
+
* schema/gains.v1.schema.json (npm run schema). v1 is the first published
|
|
5
|
+
* schema; it describes engine version 1.1.0 (mergers, bonus units, flags for
|
|
6
|
+
* a chartered accountant, advance-tax windows). New fields are additive; a
|
|
7
|
+
* field that changes meaning gets gains.v2. The guards at the bottom fail the
|
|
8
|
+
* typecheck when the schema and the types drift apart.
|
|
9
|
+
*/
|
|
10
|
+
import * as z from "zod";
|
|
11
|
+
import { isoDateSchema, sourceSchema, txnTypeSchema } from "../schema.js";
|
|
12
|
+
import { QUARTERS } from "./gains.js";
|
|
13
|
+
import { count, decimal, reasonSchema, rupees } from "./returns-schema.js";
|
|
14
|
+
z.config({ jitless: true });
|
|
15
|
+
export const GAINS_SCHEMA_ID = "urn:foliolens:schema:gains:v1";
|
|
16
|
+
const fundTypeSchema = z
|
|
17
|
+
.enum(["equity_oriented", "debt", "low_equity", "mid_equity"])
|
|
18
|
+
.meta({ id: "FundType", description: "equity_oriented: 65% or more in Indian company shares (STT on redemptions). debt: more than 65% in debt and money market. low_equity: 35% or less in Indian company shares and not debt. mid_equity: in between." });
|
|
19
|
+
const termSchema = z.enum(["short", "long"]).meta({ id: "Term" });
|
|
20
|
+
const ruleSchema = z
|
|
21
|
+
.enum(["equity_12m", "other_12m", "other_36m", "other_24m", "specified_always_short"])
|
|
22
|
+
.meta({ id: "RuleCode", description: "The holding-period rule that decided the term (docs/SPEC-gains.md)." });
|
|
23
|
+
const bucketSchema = z
|
|
24
|
+
.enum(["equity_short", "equity_long", "other_short", "other_long", "depends"])
|
|
25
|
+
.meta({ id: "Bucket", description: "Kind of gain; depends = the fund type isn't known yet." });
|
|
26
|
+
const periodSchema = z.enum(["whole", "before_23jul2024", "from_23jul2024"]).describe("whole, except FY 2024-25, split at 23 Jul 2024.");
|
|
27
|
+
const quarterSchema = z.enum(QUARTERS).meta({ id: "Quarter", description: "Advance-tax window of the sale date: up to 15 Jun, 16 Jun–15 Sep, 16 Sep–15 Dec, 16 Dec–15 Mar, 16 Mar–31 Mar." });
|
|
28
|
+
const fy = z.string().regex(/^\d{4}-\d{2}$/, 'must be a financial year such as "2024-25"');
|
|
29
|
+
const flagSchema = z
|
|
30
|
+
.enum(["s94_8_bonus_stripping", "s94_7_dividend_stripping", "grandfathering_merged_after_31jan2018", "s50aa_merged_after_1apr2023", "indexation_before_apr2017"])
|
|
31
|
+
.meta({ id: "LotFlag", description: "A point for a chartered accountant; the lot is still worked out as described." });
|
|
32
|
+
const mergerStepSchema = z
|
|
33
|
+
.strictObject({
|
|
34
|
+
date: isoDateSchema.describe("Date of the merger-in row."),
|
|
35
|
+
fromFolio: z.string(),
|
|
36
|
+
fromRtaCode: z.string(),
|
|
37
|
+
fromScheme: z.string(),
|
|
38
|
+
fromIsin: z.string().nullable(),
|
|
39
|
+
outOrder: count,
|
|
40
|
+
outSource: sourceSchema,
|
|
41
|
+
inOrder: count,
|
|
42
|
+
inSource: sourceSchema,
|
|
43
|
+
unitsBefore: decimal("The lot's units in the old scheme."),
|
|
44
|
+
})
|
|
45
|
+
.meta({ id: "MergerStep", description: "A scheme merger the lot passed through (s.47(xviii)): cost and purchase date carried, units scaled." });
|
|
46
|
+
const grandfatheringSchema = z
|
|
47
|
+
.strictObject({
|
|
48
|
+
navOn31Jan2018: decimal("NAV on 31 Jan 2018 from the data pack."),
|
|
49
|
+
valueOn31Jan2018: rupees("NAV × units."),
|
|
50
|
+
costUsed: rupees("max(cost, min(valueOn31Jan2018, saleValue)), s.55(2)(ac)."),
|
|
51
|
+
})
|
|
52
|
+
.meta({ id: "Grandfathering" });
|
|
53
|
+
const lotHome = {
|
|
54
|
+
buyOrder: count,
|
|
55
|
+
buyDate: isoDateSchema,
|
|
56
|
+
buyType: txnTypeSchema,
|
|
57
|
+
buySource: sourceSchema,
|
|
58
|
+
buyFolio: z.string().describe("Folio printing the purchase row (another scheme's after a merger)."),
|
|
59
|
+
buyRtaCode: z.string(),
|
|
60
|
+
mergers: z.array(mergerStepSchema),
|
|
61
|
+
};
|
|
62
|
+
const realisedLotSchema = z
|
|
63
|
+
.strictObject({
|
|
64
|
+
saleOrder: count,
|
|
65
|
+
saleDate: isoDateSchema,
|
|
66
|
+
saleType: txnTypeSchema,
|
|
67
|
+
saleSource: sourceSchema,
|
|
68
|
+
salePrice: decimal("Printed price per unit.").nullable(),
|
|
69
|
+
...lotHome,
|
|
70
|
+
flags: z.array(flagSchema),
|
|
71
|
+
window: quarterSchema,
|
|
72
|
+
stampOrder: count.nullable(),
|
|
73
|
+
units: decimal("Units of this lot sold."),
|
|
74
|
+
cost: rupees("Purchase amount share + stamp duty share; 0.00 for bonus units."),
|
|
75
|
+
stampDuty: rupees("Stamp duty inside the cost."),
|
|
76
|
+
saleValue: rupees("After exit load, before STT and TDS."),
|
|
77
|
+
stt: rupees("STT share, shown, not deducted."),
|
|
78
|
+
gain: rupees("saleValue − cost."),
|
|
79
|
+
daysHeld: count,
|
|
80
|
+
financialYear: fy,
|
|
81
|
+
onOrAfter23Jul2024: z.boolean(),
|
|
82
|
+
act: z.enum(["1961", "2025"]),
|
|
83
|
+
term: termSchema.nullable(),
|
|
84
|
+
rule: ruleSchema.nullable(),
|
|
85
|
+
termIf: z.partialRecord(fundTypeSchema, z.strictObject({ term: termSchema, rule: ruleSchema })).nullable(),
|
|
86
|
+
grandfathering: grandfatheringSchema.nullable(),
|
|
87
|
+
grandfatheringMissing: z.boolean(),
|
|
88
|
+
boughtBefore1Apr2001: z.boolean(),
|
|
89
|
+
sameDayReordered: z.boolean(),
|
|
90
|
+
gainAfterGrandfathering: rupees("saleValue − grandfathered cost, else the gain."),
|
|
91
|
+
indexedCost: rupees("cost × CII(sale year) / CII(purchase year), long-term non-equity sales before 23 Jul 2024.").nullable(),
|
|
92
|
+
})
|
|
93
|
+
.meta({ id: "RealisedLot", description: "One purchase lot (or part) used up by one sale." });
|
|
94
|
+
const openLotSchema = z
|
|
95
|
+
.strictObject({
|
|
96
|
+
...lotHome,
|
|
97
|
+
units: decimal("Units still held."),
|
|
98
|
+
cost: rupees("Their cost."),
|
|
99
|
+
value: rupees("units × the statement's NAV.").nullable(),
|
|
100
|
+
termOnValuationDate: termSchema.nullable(),
|
|
101
|
+
})
|
|
102
|
+
.meta({ id: "OpenLot" });
|
|
103
|
+
const saleNoteSchema = z
|
|
104
|
+
.strictObject({ saleOrder: count, unexplainedDeduction: rupees("units × price − sale value, above a paisa.") })
|
|
105
|
+
.meta({ id: "SaleNote" });
|
|
106
|
+
const schemeGainsSchema = z
|
|
107
|
+
.strictObject({
|
|
108
|
+
folio: z.string(),
|
|
109
|
+
amc: z.string(),
|
|
110
|
+
rtaCode: z.string(),
|
|
111
|
+
scheme: z.string(),
|
|
112
|
+
isin: z.string().nullable(),
|
|
113
|
+
included: z.boolean(),
|
|
114
|
+
reasons: z.array(reasonSchema).describe("Why the scheme is left out; empty when included."),
|
|
115
|
+
fundType: fundTypeSchema.nullable(),
|
|
116
|
+
fundTypeBasis: z.enum(["stt_on_redemption", "caller", "no_stt_on_redemption", "no_sales"]),
|
|
117
|
+
fundTypeSource: sourceSchema.nullable(),
|
|
118
|
+
realised: z.array(realisedLotSchema),
|
|
119
|
+
saleNotes: z.array(saleNoteSchema),
|
|
120
|
+
open: z.array(openLotSchema),
|
|
121
|
+
})
|
|
122
|
+
.meta({ id: "SchemeGains" });
|
|
123
|
+
const yearTotalsSchema = z
|
|
124
|
+
.strictObject({
|
|
125
|
+
financialYear: fy,
|
|
126
|
+
period: periodSchema,
|
|
127
|
+
bucket: bucketSchema,
|
|
128
|
+
lots: count,
|
|
129
|
+
lotsMissing2018Nav: count,
|
|
130
|
+
lotsFlagged: count,
|
|
131
|
+
saleValue: rupees("Σ sale value."),
|
|
132
|
+
cost: rupees("Σ cost."),
|
|
133
|
+
gain: rupees("Σ gain, before grandfathering and indexation."),
|
|
134
|
+
gainAfterGrandfathering: rupees("Σ gain after grandfathering (equity long term), else Σ gain."),
|
|
135
|
+
gainAfterIndexation: rupees("other_long with an indexed lot: Σ sale value − indexed cost for those, gain for the rest.").nullable(),
|
|
136
|
+
})
|
|
137
|
+
.meta({ id: "YearTotals" });
|
|
138
|
+
const quarterTotalsSchema = z
|
|
139
|
+
.strictObject({
|
|
140
|
+
financialYear: fy,
|
|
141
|
+
period: periodSchema,
|
|
142
|
+
bucket: bucketSchema,
|
|
143
|
+
lots: count,
|
|
144
|
+
lotsWithNote: count.describe("Lots with a flag for a chartered accountant, or missing a 31 Jan 2018 NAV."),
|
|
145
|
+
windows: z.array(rupees("Net gain in the window, before any set-off of losses.")).length(QUARTERS.length),
|
|
146
|
+
total: rupees("Σ windows."),
|
|
147
|
+
})
|
|
148
|
+
.meta({ id: "QuarterTotals", description: "Gains by advance-tax window (ITR Schedule CG table F, by date of sale), before set-off of losses." });
|
|
149
|
+
export const gainsOutputSchema = z
|
|
150
|
+
.strictObject({
|
|
151
|
+
schemes: z.array(schemeGainsSchema),
|
|
152
|
+
years: z.array(yearTotalsSchema),
|
|
153
|
+
quarters: z.array(quarterTotalsSchema),
|
|
154
|
+
fmvPack: z.string().nullable().describe("Version of the 31 Jan 2018 NAV pack used."),
|
|
155
|
+
})
|
|
156
|
+
.meta({
|
|
157
|
+
$id: GAINS_SCHEMA_ID,
|
|
158
|
+
title: "gains@1",
|
|
159
|
+
description: "Capital gains per lot, first in first out, from the statement's own rows (docs/SPEC-gains.md). Gains only: no tax rate or tax amount. Not reviewed by a chartered accountant. " +
|
|
160
|
+
"Contains personal data (folios, amounts): handle it like the statement itself.",
|
|
161
|
+
});
|
|
162
|
+
/** The JSON Schema (draft 2020-12) committed as schema/gains.v1.schema.json. */
|
|
163
|
+
export function gainsJsonSchema() {
|
|
164
|
+
const { $schema, $id, title, description, ...rest } = z.toJSONSchema(gainsOutputSchema, { target: "draft-2020-12" });
|
|
165
|
+
return { $schema, $id, title, description, ...rest };
|
|
166
|
+
}
|
|
167
|
+
export function validateGainsOutput(x) {
|
|
168
|
+
const r = gainsOutputSchema.safeParse(x);
|
|
169
|
+
return r.success ? { ok: true } : { ok: false, issues: r.error.issues.map((i) => `${i.path.join("/")}: ${i.message}`) };
|
|
170
|
+
}
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capital gains per lot, first in first out: analysis `gains@1`, regClass
|
|
3
|
+
* "computation". It works out each sale's gain, short or long term, from the
|
|
4
|
+
* statement's own purchase and sale rows, and says which rule decided it. It
|
|
5
|
+
* never applies a tax rate (that depends on the investor's slab and other
|
|
6
|
+
* income) and gives no advice.
|
|
7
|
+
*
|
|
8
|
+
* Rules (each lot carries the rule code that decided it; sources in
|
|
9
|
+
* docs/SPEC-gains.md):
|
|
10
|
+
*
|
|
11
|
+
* - Cost of a lot: the purchase row's amount plus the stamp duty row that
|
|
12
|
+
* follows it (stamp duty is part of the cost of acquisition). Reinvested
|
|
13
|
+
* IDCW starts a new lot at its amount.
|
|
14
|
+
* - Sale value: what the sale fetched after any exit load and before STT and
|
|
15
|
+
* TDS: |amount| + the STT and TDS rows of that sale, capped at |units| ×
|
|
16
|
+
* price. A gap below units × price (an exit load, usually) is shown on the
|
|
17
|
+
* sale; it is already out of the sale value.
|
|
18
|
+
* - Lots leave first in, first out, in statement order. A sale that needs
|
|
19
|
+
* units bought later the same day takes them, and its lots say so.
|
|
20
|
+
* - Fund type: STT on a redemption means an equity-oriented fund (STT is
|
|
21
|
+
* charged only there), for the whole history. Without STT the statement
|
|
22
|
+
* can't prove the type, so the caller may pass it (`fundTypes`), else a lot
|
|
23
|
+
* whose term depends on it says "depends" and lists each possible answer.
|
|
24
|
+
* - Equity-oriented: long term when held more than 12 months.
|
|
25
|
+
* - Other funds: units bought on or after 1 Apr 2023 in a "specified" fund are
|
|
26
|
+
* always short term (s.50AA). Before 1 Apr 2025 a specified fund had at most
|
|
27
|
+
* 35% equity; from 1 Apr 2025 it has more than 65% in debt and money market
|
|
28
|
+
* instruments. Otherwise long term when held more than 12 months (sold up
|
|
29
|
+
* to 10 Jul 2014), 36 months (sold before 23 Jul 2024) or 24 months (sold
|
|
30
|
+
* on or after).
|
|
31
|
+
* - Grandfathering (s.55(2)(ac)): an equity-oriented lot bought on or before
|
|
32
|
+
* 31 Jan 2018 and sold long term on or after 1 Apr 2018 uses the higher of
|
|
33
|
+
* its cost and the lower of its 31 Jan 2018 value (NAV × units) and the
|
|
34
|
+
* sale value. The NAV comes from a data pack the caller passes (`fmv2018`).
|
|
35
|
+
* - Indexed cost (CII, base 2001-02) is shown for long-term non-equity lots
|
|
36
|
+
* sold from 1 Apr 2017 to 22 Jul 2024; earlier sales used the 1981-82 base,
|
|
37
|
+
* which isn't in the table, so those lots are flagged instead.
|
|
38
|
+
* - Scheme mergers (s.47(xviii): not a transfer): the old scheme's open lots
|
|
39
|
+
* move to the new scheme with their cost (s.49(2AD)) and purchase date
|
|
40
|
+
* (s.2(42A)), units scaled by the merger ratio (3 decimals, by running
|
|
41
|
+
* total, so the parts add up). The merger-out row must
|
|
42
|
+
* pair with exactly one merger-in row of the same fund house within 7
|
|
43
|
+
* days; otherwise the new scheme is left out ("can't calculate").
|
|
44
|
+
* - Bonus units: a new lot at nil cost (s.55(2)(aa)(iiia)), dated the
|
|
45
|
+
* allotment.
|
|
46
|
+
* - Lots a chartered accountant should look at carry a flag and are still
|
|
47
|
+
* worked out: s.94(7)/(8) stripping may apply, s.50AA for units that
|
|
48
|
+
* arrived through a merger, and grandfathering for units merged after
|
|
49
|
+
* 31 Jan 2018 (not applied: the gain is shown before it).
|
|
50
|
+
* - Gains by advance-tax window (ITR Schedule CG table F) per year, kind and,
|
|
51
|
+
* in FY 2024-25, side of 23 Jul 2024.
|
|
52
|
+
*
|
|
53
|
+
* Schemes whose history doesn't start at zero, or that hold rows whose cost
|
|
54
|
+
* lineage is outside the statement (gifts, transfers, unit adjustments,
|
|
55
|
+
* segregation, pledge invocations), are left out with a reason.
|
|
56
|
+
*/
|
|
57
|
+
import type Big from "big.js";
|
|
58
|
+
import type { CasDocument, Source, TxnType } from "../model.js";
|
|
59
|
+
import { type AnalysisManifest, type AnalysisModule, type PredicateCode, type Reason } from "./contract.js";
|
|
60
|
+
export declare const GAINS_MANIFEST: AnalysisManifest;
|
|
61
|
+
/** Sales on or after this date: 36 months for funds other than equity-oriented; earlier, 12 months (Finance (No. 2) Act 2014). */
|
|
62
|
+
export declare const REGIME_2014 = "2014-07-11";
|
|
63
|
+
/** Units bought on or after this date in a specified fund are always short term. */
|
|
64
|
+
export declare const SPECIFIED_FROM = "2023-04-01";
|
|
65
|
+
/** Sales on or after this date: 24 months for other funds, no indexation (Finance (No. 2) Act 2024). */
|
|
66
|
+
export declare const REGIME_2024 = "2024-07-23";
|
|
67
|
+
/** Sales on or after this date use the narrower "specified fund" definition (> 65% debt). */
|
|
68
|
+
export declare const SPECIFIED_REDEFINED = "2025-04-01";
|
|
69
|
+
/** Grandfathering applies to lots bought on or before this date… */
|
|
70
|
+
export declare const GRANDFATHER_BUY_BY = "2018-01-31";
|
|
71
|
+
/** …and sold on or after this date (earlier long-term equity gains were exempt). */
|
|
72
|
+
export declare const GRANDFATHER_SELL_FROM = "2018-04-01";
|
|
73
|
+
/** IDCW became taxable in the investor's hands from this date (Finance Act 2020), which ends s.94(7) for it. */
|
|
74
|
+
export declare const IDCW_TAXABLE_FROM = "2020-04-01";
|
|
75
|
+
/** The Income-tax Act, 2025 applies to transfers from this date (s.196/198 replace s.111A/112A). */
|
|
76
|
+
export declare const ACT_2025_FROM = "2026-04-01";
|
|
77
|
+
/** The 2001-02 base index applies to transfers from this date (Finance Act 2017); earlier sales used the 1981-82 base. */
|
|
78
|
+
export declare const CII_2001_FROM = "2017-04-01";
|
|
79
|
+
/** Cost Inflation Index, base 2001-02 = 100, by financial year's first calendar year. */
|
|
80
|
+
export declare const CII: Readonly<Record<number, number>>;
|
|
81
|
+
/** What the fund holds, as far as tax is concerned. */
|
|
82
|
+
export type FundType =
|
|
83
|
+
/** At least 65% in Indian equity (or a fund of funds with 90% in such ETFs): STT is charged on its redemptions. */
|
|
84
|
+
"equity_oriented"
|
|
85
|
+
/** More than 65% in debt and money market instruments, or a fund of funds with at least 65% in such funds. */
|
|
86
|
+
| "debt"
|
|
87
|
+
/** At most 35% equity and not a debt fund (gold, overseas fund of funds…). */
|
|
88
|
+
| "low_equity"
|
|
89
|
+
/** More than 35% and less than 65% equity (some hybrids). */
|
|
90
|
+
| "mid_equity";
|
|
91
|
+
export type Term = "short" | "long";
|
|
92
|
+
export type RuleCode = "equity_12m"
|
|
93
|
+
/** Funds other than equity-oriented, sold up to 10 Jul 2014: long term after 12 months. */
|
|
94
|
+
| "other_12m" | "other_36m" | "other_24m"
|
|
95
|
+
/** s.50AA: units of a specified fund bought on or after 1 Apr 2023. */
|
|
96
|
+
| "specified_always_short";
|
|
97
|
+
/** "2024-25" for any date from 1 Apr 2024 to 31 Mar 2025. */
|
|
98
|
+
export declare function financialYear(iso: string): string;
|
|
99
|
+
/** The same calendar date `months` later; 29 Feb and month ends clamp to the last day. */
|
|
100
|
+
export declare function addMonths(iso: string, months: number): string;
|
|
101
|
+
export declare const QUARTERS: readonly ["up_to_15jun", "16jun_15sep", "16sep_15dec", "16dec_15mar", "16mar_31mar"];
|
|
102
|
+
export type Quarter = (typeof QUARTERS)[number];
|
|
103
|
+
/** The advance-tax window a sale on `iso` falls in: up to 15 Jun, 16 Jun–15 Sep, 16 Sep–15 Dec, 16 Dec–15 Mar, 16 Mar–31 Mar. */
|
|
104
|
+
export declare function quarterOf(iso: string): Quarter;
|
|
105
|
+
/** The term of one lot and the rule that decided it. */
|
|
106
|
+
export declare function termOf(type: FundType, buyDate: string, saleDate: string): {
|
|
107
|
+
term: Term;
|
|
108
|
+
rule: RuleCode;
|
|
109
|
+
};
|
|
110
|
+
export type GainsReasonCode = PredicateCode | "event_not_supported" | "amount_missing" | "sign_mismatch" | "reversal_unmatched" | "units_short" | "stamp_unattributed"
|
|
111
|
+
/** Units arrived by a merger whose merger-out row isn't on the statement, or can't be told apart from another. */
|
|
112
|
+
| "merger_unmatched"
|
|
113
|
+
/** The scheme the units merged from is itself left out. */
|
|
114
|
+
| "merger_source_left_out"
|
|
115
|
+
/** Merged units and units already held interleave by date: the order they leave in needs a chartered accountant. */
|
|
116
|
+
| "merger_order_unclear"
|
|
117
|
+
/** A merger these rules don't cover: before 1 Apr 2015 (then a sale), or between an equity-oriented and another fund. */
|
|
118
|
+
| "merger_not_covered"
|
|
119
|
+
/** The new scheme's units are too few to share out the old lots at 3 decimals. */
|
|
120
|
+
| "merger_units_too_small";
|
|
121
|
+
/** Something about a lot a chartered accountant should look at. The lot is still worked out as described. */
|
|
122
|
+
export type LotFlag =
|
|
123
|
+
/** Bought within about 3 months before a bonus allotment and sold at a loss within about 9 months after it: s.94(8) may ignore the loss. */
|
|
124
|
+
"s94_8_bonus_stripping"
|
|
125
|
+
/** Bought within about 3 months before an IDCW paid before 1 Apr 2020 (then exempt) and sold at a loss within about 9 months after it: s.94(7) may ignore the loss up to the IDCW. */
|
|
126
|
+
| "s94_7_dividend_stripping"
|
|
127
|
+
/** Equity-oriented, bought by 31 Jan 2018, merged after that date: grandfathering isn't applied, the gain is before it. */
|
|
128
|
+
| "grandfathering_merged_after_31jan2018"
|
|
129
|
+
/** Not equity-oriented, bought before 1 Apr 2023 and merged on or after it: s.50AA is applied from the first purchase date. */
|
|
130
|
+
| "s50aa_merged_after_1apr2023"
|
|
131
|
+
/** Long-term, not equity-oriented, sold before 1 Apr 2017: the 1981-82 base index applied then, which isn't in our table, so no indexed cost is shown. */
|
|
132
|
+
| "indexation_before_apr2017";
|
|
133
|
+
/** One scheme merger a lot passed through, oldest first. */
|
|
134
|
+
export interface MergerStep {
|
|
135
|
+
/** Date of the merger-in row. */
|
|
136
|
+
date: string;
|
|
137
|
+
fromFolio: string;
|
|
138
|
+
fromRtaCode: string;
|
|
139
|
+
fromScheme: string;
|
|
140
|
+
fromIsin: string | null;
|
|
141
|
+
outOrder: number;
|
|
142
|
+
outSource: Source;
|
|
143
|
+
inOrder: number;
|
|
144
|
+
inSource: Source;
|
|
145
|
+
/** The lot's units in the old scheme. */
|
|
146
|
+
unitsBefore: string;
|
|
147
|
+
}
|
|
148
|
+
/** How the fund type was decided. */
|
|
149
|
+
export type FundTypeBasis = "stt_on_redemption" | "caller" | "no_stt_on_redemption" | "no_sales";
|
|
150
|
+
export interface Grandfathering {
|
|
151
|
+
/** NAV on 31 Jan 2018 from the data pack. */
|
|
152
|
+
navOn31Jan2018: string;
|
|
153
|
+
/** navOn31Jan2018 × units, to the paisa. */
|
|
154
|
+
valueOn31Jan2018: string;
|
|
155
|
+
/** max(cost, min(valueOn31Jan2018, saleValue)). */
|
|
156
|
+
costUsed: string;
|
|
157
|
+
}
|
|
158
|
+
export interface RealisedLot {
|
|
159
|
+
saleOrder: number;
|
|
160
|
+
saleDate: string;
|
|
161
|
+
saleType: TxnType;
|
|
162
|
+
saleSource: Source;
|
|
163
|
+
/** The sale row's printed price per unit, as a decimal string; null when not printed. */
|
|
164
|
+
salePrice: string | null;
|
|
165
|
+
buyOrder: number;
|
|
166
|
+
buyDate: string;
|
|
167
|
+
buyType: TxnType;
|
|
168
|
+
buySource: Source;
|
|
169
|
+
/** Folio and scheme that print the purchase row: another scheme when the units came through a merger. */
|
|
170
|
+
buyFolio: string;
|
|
171
|
+
buyRtaCode: string;
|
|
172
|
+
/** Mergers between the purchase and the sale, oldest first; empty for most lots. */
|
|
173
|
+
mergers: MergerStep[];
|
|
174
|
+
/** Notes for a chartered accountant; empty for most lots. */
|
|
175
|
+
flags: LotFlag[];
|
|
176
|
+
/** Advance-tax window of the sale date. */
|
|
177
|
+
window: Quarter;
|
|
178
|
+
/** Stamp duty row folded into the cost, if any. */
|
|
179
|
+
stampOrder: number | null;
|
|
180
|
+
units: string;
|
|
181
|
+
/** Purchase amount share + stamp duty share. */
|
|
182
|
+
cost: string;
|
|
183
|
+
stampDuty: string;
|
|
184
|
+
saleValue: string;
|
|
185
|
+
/** STT share on this lot (shown, not deducted). */
|
|
186
|
+
stt: string;
|
|
187
|
+
/** saleValue − cost. */
|
|
188
|
+
gain: string;
|
|
189
|
+
daysHeld: number;
|
|
190
|
+
financialYear: string;
|
|
191
|
+
/** Sold on or after 23 Jul 2024 (the FY 2024-25 split). */
|
|
192
|
+
onOrAfter23Jul2024: boolean;
|
|
193
|
+
/** "Income-tax Act, 1961" up to 31 Mar 2026, then 2025. */
|
|
194
|
+
act: "1961" | "2025";
|
|
195
|
+
/** null when it depends on a fund type the statement doesn't show. */
|
|
196
|
+
term: Term | null;
|
|
197
|
+
rule: RuleCode | null;
|
|
198
|
+
/** When `term` is null: the answer for each fund type it could be. */
|
|
199
|
+
termIf: Partial<Record<FundType, {
|
|
200
|
+
term: Term;
|
|
201
|
+
rule: RuleCode;
|
|
202
|
+
}>> | null;
|
|
203
|
+
/** Equity-oriented, long term, bought by 31 Jan 2018. null when it doesn't apply. */
|
|
204
|
+
grandfathering: Grandfathering | null;
|
|
205
|
+
/** Grandfathering applies but the data pack has no NAV for this ISIN: the gain is before grandfathering. */
|
|
206
|
+
grandfatheringMissing: boolean;
|
|
207
|
+
/** Bought before 1 Apr 2001: the 1 Apr 2001 value may replace the cost (s.55(2)(b)); not done here. */
|
|
208
|
+
boughtBefore1Apr2001: boolean;
|
|
209
|
+
/** The sale used units bought later the same day (statement order put the sale first). */
|
|
210
|
+
sameDayReordered: boolean;
|
|
211
|
+
/** saleValue − (grandfathered cost, else cost). */
|
|
212
|
+
gainAfterGrandfathering: string;
|
|
213
|
+
/** Long-term non-equity sold before 23 Jul 2024: cost × CII(sale FY) / CII(buy FY). */
|
|
214
|
+
indexedCost: string | null;
|
|
215
|
+
}
|
|
216
|
+
export interface SaleNote {
|
|
217
|
+
saleOrder: number;
|
|
218
|
+
/** units × price − sale value: usually an exit load, already out of the sale value. Only when above a paisa. */
|
|
219
|
+
unexplainedDeduction: string;
|
|
220
|
+
}
|
|
221
|
+
export interface OpenLot {
|
|
222
|
+
buyOrder: number;
|
|
223
|
+
buyDate: string;
|
|
224
|
+
buyType: TxnType;
|
|
225
|
+
buySource: Source;
|
|
226
|
+
buyFolio: string;
|
|
227
|
+
buyRtaCode: string;
|
|
228
|
+
mergers: MergerStep[];
|
|
229
|
+
units: string;
|
|
230
|
+
cost: string;
|
|
231
|
+
/** units × the statement's NAV, when printed. */
|
|
232
|
+
value: string | null;
|
|
233
|
+
/** Term if sold on the valuation date; null when it depends on the fund type. */
|
|
234
|
+
termOnValuationDate: Term | null;
|
|
235
|
+
}
|
|
236
|
+
export interface SchemeGains {
|
|
237
|
+
folio: string;
|
|
238
|
+
amc: string;
|
|
239
|
+
rtaCode: string;
|
|
240
|
+
scheme: string;
|
|
241
|
+
isin: string | null;
|
|
242
|
+
included: boolean;
|
|
243
|
+
reasons: Reason<GainsReasonCode>[];
|
|
244
|
+
fundType: FundType | null;
|
|
245
|
+
fundTypeBasis: FundTypeBasis;
|
|
246
|
+
fundTypeSource: Source | null;
|
|
247
|
+
realised: RealisedLot[];
|
|
248
|
+
saleNotes: SaleNote[];
|
|
249
|
+
open: OpenLot[];
|
|
250
|
+
}
|
|
251
|
+
export type Bucket = "equity_short" | "equity_long" | "other_short" | "other_long" | "depends";
|
|
252
|
+
export interface YearTotals {
|
|
253
|
+
financialYear: string;
|
|
254
|
+
/** "whole" except FY 2024-25, which is split at 23 Jul 2024. */
|
|
255
|
+
period: "whole" | "before_23jul2024" | "from_23jul2024";
|
|
256
|
+
bucket: Bucket;
|
|
257
|
+
lots: number;
|
|
258
|
+
/** Lots that need grandfathering but have no 31 Jan 2018 NAV: their gain is before grandfathering. */
|
|
259
|
+
lotsMissing2018Nav: number;
|
|
260
|
+
/** Lots with at least one flag for a chartered accountant. */
|
|
261
|
+
lotsFlagged: number;
|
|
262
|
+
saleValue: string;
|
|
263
|
+
cost: string;
|
|
264
|
+
gain: string;
|
|
265
|
+
/** equity_long only: after grandfathering. Same as `gain` elsewhere. */
|
|
266
|
+
gainAfterGrandfathering: string;
|
|
267
|
+
/** other_long with at least one indexed lot: sale value − indexed cost for those lots, gain for the rest. Else null. */
|
|
268
|
+
gainAfterIndexation: string | null;
|
|
269
|
+
}
|
|
270
|
+
/** Gains by advance-tax window, as ITR Schedule CG table F lays them out (by date of sale). */
|
|
271
|
+
export interface QuarterTotals {
|
|
272
|
+
financialYear: string;
|
|
273
|
+
/** As in YearTotals: FY 2024-25 is split at 23 Jul 2024, when the rates changed (the form has a row per rate). */
|
|
274
|
+
period: YearTotals["period"];
|
|
275
|
+
bucket: Bucket;
|
|
276
|
+
lots: number;
|
|
277
|
+
/** Lots with a flag for a chartered accountant, or needing a 31 Jan 2018 NAV the data pack lacks. */
|
|
278
|
+
lotsWithNote: number;
|
|
279
|
+
/**
|
|
280
|
+
* Net gain per window, in QUARTERS order, before any set-off of losses (the form takes
|
|
281
|
+
* the figures after set-off, from Schedule BFLA). Equity long term: after grandfathering;
|
|
282
|
+
* other long term: after indexation where it applied; else the gain.
|
|
283
|
+
*/
|
|
284
|
+
windows: string[];
|
|
285
|
+
total: string;
|
|
286
|
+
}
|
|
287
|
+
export interface GainsOutput {
|
|
288
|
+
schemes: SchemeGains[];
|
|
289
|
+
years: YearTotals[];
|
|
290
|
+
quarters: QuarterTotals[];
|
|
291
|
+
/** Version of the 31 Jan 2018 NAV pack used, null when none was passed. */
|
|
292
|
+
fmvPack: string | null;
|
|
293
|
+
}
|
|
294
|
+
export interface GainsOptions {
|
|
295
|
+
/** NAV on 31 Jan 2018 by ISIN, as a decimal string; null when unknown. */
|
|
296
|
+
fmv2018?: {
|
|
297
|
+
version: string;
|
|
298
|
+
lookup: (isin: string) => string | null;
|
|
299
|
+
};
|
|
300
|
+
/** Fund type chosen by the caller, keyed `${folio}|${rtaCode}`. Overrides "no STT" evidence, never STT. */
|
|
301
|
+
fundTypes?: Readonly<Record<string, FundType>>;
|
|
302
|
+
}
|
|
303
|
+
/** s.47(xviii) (consolidation of schemes is not a transfer) applies from AY 2016-17 (Finance Act 2015). */
|
|
304
|
+
export declare const MERGER_EXEMPT_FROM = "2015-04-01";
|
|
305
|
+
/** What a lot adds to its advance-tax window: equity long term after grandfathering, other long term after indexation where it applied, else the gain. */
|
|
306
|
+
export declare function windowAmount(bucket: Bucket, l: RealisedLot): Big;
|
|
307
|
+
/** The shape of refdata/nav-2018-01-31.json (tools/refdata/nav2018.py). */
|
|
308
|
+
export interface Nav2018Pack {
|
|
309
|
+
id: "nav-2018-01-31";
|
|
310
|
+
version: string;
|
|
311
|
+
source: string;
|
|
312
|
+
count: number;
|
|
313
|
+
navs: Readonly<Record<string, string>>;
|
|
314
|
+
}
|
|
315
|
+
/** The `fmv2018` option from the data pack. */
|
|
316
|
+
export declare function fmv2018FromPack(pack: Nav2018Pack): NonNullable<GainsOptions["fmv2018"]>;
|
|
317
|
+
/** Capital gains for every scheme in the statement. */
|
|
318
|
+
export declare function gains(cas: CasDocument, opt?: GainsOptions): GainsOutput;
|
|
319
|
+
export declare const gainsModule: AnalysisModule<GainsOutput>;
|