7 lines
2.0 KiB
SQL
7 lines
2.0 KiB
SQL
-- ============================================
|
|
-- 此文件由 Meoo Cloud 自动生成,请勿修改
|
|
-- This file is auto-generated by Meoo Cloud, DO NOT MODIFY
|
|
-- ============================================
|
|
|
|
CREATE TABLE public.accounts_payable (id UUID PRIMARY KEY DEFAULT gen_random_uuid(), plan_id UUID NOT NULL REFERENCES public.production_plans(id) ON DELETE CASCADE, purchaser_id UUID NOT NULL REFERENCES public.companies(id) ON DELETE CASCADE, textile_factory_id UUID NOT NULL REFERENCES public.companies(id) ON DELETE CASCADE, total_amount DECIMAL NOT NULL DEFAULT 0, paid_amount DECIMAL NOT NULL DEFAULT 0, unpaid_amount DECIMAL NOT NULL DEFAULT 0, total_quantity DECIMAL NOT NULL DEFAULT 0, paid_quantity DECIMAL NOT NULL DEFAULT 0, unpaid_quantity DECIMAL NOT NULL DEFAULT 0, price_per_meter DECIMAL NOT NULL DEFAULT 0, status TEXT NOT NULL DEFAULT 'unpaid', created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()); CREATE TABLE public.accounts_payable_items (id UUID PRIMARY KEY DEFAULT gen_random_uuid(), accounts_payable_id UUID NOT NULL REFERENCES public.accounts_payable(id) ON DELETE CASCADE, inventory_record_id UUID REFERENCES public.inventory_records(id) ON DELETE SET NULL, quantity DECIMAL NOT NULL DEFAULT 0, rolls INTEGER DEFAULT 0, price_per_meter DECIMAL NOT NULL DEFAULT 0, amount DECIMAL NOT NULL DEFAULT 0, status TEXT NOT NULL DEFAULT 'unpaid', payment_id UUID REFERENCES public.payments(id) ON DELETE SET NULL, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), paid_at TIMESTAMPTZ); CREATE INDEX idx_accounts_payable_plan ON public.accounts_payable(plan_id); CREATE INDEX idx_accounts_payable_purchaser ON public.accounts_payable(purchaser_id); CREATE INDEX idx_accounts_payable_factory ON public.accounts_payable(textile_factory_id); CREATE INDEX idx_accounts_payable_status ON public.accounts_payable(status); CREATE INDEX idx_accounts_payable_items_ap ON public.accounts_payable_items(accounts_payable_id); CREATE INDEX idx_accounts_payable_items_status ON public.accounts_payable_items(status);
|