-- Slice 8R-PricingDefaults · schema
-- Single-row org-wide defaults for new pricing versions. Edited by CRM / Finance Manager / Executive
-- (and Administrator as safety net). Every new tender_pricing_versions row picks these up unless
-- an explicit override is passed to createVersion().

CREATE TABLE IF NOT EXISTS pricing_defaults (
    c0d                       INT UNSIGNED   NOT NULL AUTO_INCREMENT,
    default_markup_pct        DECIMAL(6,3)   NOT NULL DEFAULT 20.000,
    default_contingency_pct   DECIMAL(6,3)   NOT NULL DEFAULT 2.000,
    default_vat_pct           DECIMAL(6,3)   NOT NULL DEFAULT 18.000,
    default_prelims_amount    DECIMAL(20,2)  NOT NULL DEFAULT 0.00,
    default_currency          VARCHAR(6)     NOT NULL DEFAULT 'TZS',
    notes                     VARCHAR(500)   NULL,
    edited_by                 INT UNSIGNED   NULL,
    edited_by_name            VARCHAR(160)   NULL,
    edited_on                 TIMESTAMP      NULL,
    PRIMARY KEY (c0d)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Seed the single settings row (id=1). If it already exists, no-op.
INSERT INTO pricing_defaults (c0d, default_markup_pct, default_contingency_pct, default_vat_pct, default_prelims_amount, default_currency, notes)
VALUES (1, 20.000, 2.000, 18.000, 0.00, 'TZS', 'Org-wide defaults for new pricing drafts. Update via Pricing Defaults settings.')
ON DUPLICATE KEY UPDATE c0d = c0d;
