Subversion Repositories SmartDukaan

Rev

Rev 37588 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
37588 amit 1
-- Partner investment snapshot.
2
--
3
-- One row per active franchise partner, refreshed by the 2-minute sweep
4
-- (PartnerInvestmentSweepService). Replaces the 3-hour Redis cache that used to sit in
5
-- front of PartnerInvestmentServiceImpl.getInvestment().
6
--
7
-- Every column in a row is computed in ONE pass, so coupled terms (wallet vs utilised,
8
-- in-stock vs aged-Apple) can never be read at different vintages. That skew is what
9
-- caused a partner's credit limit to be overstated by the full value of an advance
10
-- payment for an hour on 2026-09-10.
11
--
12
-- Money is DECIMAL, not FLOAT: float money columns lose paise above ~1.67 lakh, and
13
-- base_value is compared on every sweep to decide whether the limit must be recomputed.
14
--
15
-- Safe to re-run.
16
 
17
CREATE TABLE IF NOT EXISTS fofo.partner_investment (
18
    fofo_id                      INT            NOT NULL,
19
 
20
    -- refreshed every 2 minutes
21
    wallet_amount                DECIMAL(14,2)  NOT NULL DEFAULT 0,
37592 amit 22
 
23
    -- GROSS stock. Investment counts stock net of live-demo units held past 90 days, but that
24
    -- haircut moves on its own daily clock, so storing the netted figure would mean re-netting it
25
    -- every time the haircut changed. Store what is measured and derive the net
26
    -- (getNetInStockAmount = gross - demo_excluded_amount).
27
    in_stock_gross_amount        DECIMAL(14,2)  NOT NULL DEFAULT 0,
37588 amit 28
    unbilled_amount              DECIMAL(14,2)  NOT NULL DEFAULT 0,
29
    grn_pending_amount           DECIMAL(14,2)  NOT NULL DEFAULT 0,
30
    activated_stock_amount       DECIMAL(14,2)  NOT NULL DEFAULT 0,
31
    activated_grn_pending_amount DECIMAL(14,2)  NOT NULL DEFAULT 0,
32
    return_in_transit_amount     DECIMAL(14,2)  NOT NULL DEFAULT 0,
33
    utilized_amount              DECIMAL(14,2)  NOT NULL DEFAULT 0,
34
 
35
    -- refreshed daily (time-driven), plus on the sweep when the partner's stock moved
36
    aged_apple_stock_amount      DECIMAL(14,2)  NOT NULL DEFAULT 0,
37592 amit 37
    aged_apple_qty               INT            NOT NULL DEFAULT 0,
37588 amit 38
    demo_excluded_amount         DECIMAL(14,2)  NOT NULL DEFAULT 0,
39
    aged_refreshed_on            DATE               NULL,
40
 
41
    -- derived
42
    total_investment             DECIMAL(14,2)  NOT NULL DEFAULT 0,
43
    base_value                   DECIMAL(14,2)  NOT NULL DEFAULT 0,
44
 
45
    snapshot_timestamp           DATETIME       NOT NULL,
46
 
47
    PRIMARY KEY (fofo_id),
48
    KEY ix_partner_investment_snapshot (snapshot_timestamp)
49
) ENGINE=InnoDB DEFAULT CHARSET=latin1;