Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
36958 amit 1
-- Flagship credit: per-device tracking via a child table (instead of denormalizing IMEI onto transaction.loan).
2
--
3
-- A mixed flagship invoice creates ONE combined flagship limit row in transaction.loan, plus one
4
-- loan_imei row per device it covers. On sale/activation the sold IMEI's row is converted to a real
5
-- loan (converting only that unit's credit); same-model siblings keep their interest-free window.
6
-- Keeping transaction.loan at one-row-per-invoice avoids disturbing the many loan-row consumers
7
-- (statements, reco, utilization, selectLoanByInvoice).
8
--
9
-- Additive (new table only); safe to run on any environment before deploying the code.
10
 
11
CREATE TABLE IF NOT EXISTS transaction.loan_imei (
12
    id                INT AUTO_INCREMENT PRIMARY KEY,
13
    loan_id           INT NOT NULL,            -- the flagship limit row (transaction.loan.id)
14
    imei              VARCHAR(64) NOT NULL,    -- the device serial this slice covers
15
    amount            DECIMAL(12,4) NOT NULL,  -- this unit's credit amount
16
    converted_on      DATETIME NULL,           -- NULL = still interest-free under the limit
17
    converted_loan_id INT NULL,                -- the real loan created on conversion (audit)
18
    created_on        DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
19
    INDEX ix_loan_imei_loan (loan_id),
20
    INDEX ix_loan_imei_imei (imei)
21
);