- Created a new SQL migration for the sag_salgsvarer table to manage sales and purchase items. - Implemented a new HTML template for the Varekøb & Salg module, including summary cards and tables for sales and purchases. - Added JavaScript functions for loading and rendering order data dynamically. - Introduced a new backend search module for customers, contacts, hardware, and locations with autocomplete functionality. - Developed an email templates API for managing system and customer-specific email templates. - Created multiple migrations for Nextcloud instances, cache, audit logs, email templates, sag comments, hardware locations, and billing methods. - Enhanced the sag module with solutions, order lines, work types, and 2FA support for user authentication.
37 lines
1.3 KiB
PL/PgSQL
37 lines
1.3 KiB
PL/PgSQL
-- Sag Module: Varekøb & Salg (case-linked sales items)
|
|
|
|
CREATE TABLE IF NOT EXISTS sag_salgsvarer (
|
|
id SERIAL PRIMARY KEY,
|
|
sag_id INTEGER NOT NULL REFERENCES sag_sager(id) ON DELETE CASCADE,
|
|
type VARCHAR(20) NOT NULL DEFAULT 'sale', -- sale | purchase
|
|
description TEXT NOT NULL,
|
|
quantity NUMERIC(12, 2),
|
|
unit VARCHAR(50),
|
|
unit_price NUMERIC(12, 2),
|
|
amount NUMERIC(12, 2) NOT NULL,
|
|
currency VARCHAR(10) NOT NULL DEFAULT 'DKK',
|
|
status VARCHAR(20) NOT NULL DEFAULT 'draft', -- draft | confirmed | cancelled
|
|
line_date DATE,
|
|
external_ref VARCHAR(100),
|
|
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
|
updated_at TIMESTAMP NOT NULL DEFAULT NOW()
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_sag_salgsvarer_sag_id ON sag_salgsvarer(sag_id);
|
|
CREATE INDEX IF NOT EXISTS idx_sag_salgsvarer_type ON sag_salgsvarer(type);
|
|
CREATE INDEX IF NOT EXISTS idx_sag_salgsvarer_status ON sag_salgsvarer(status);
|
|
|
|
CREATE OR REPLACE FUNCTION update_sag_salgsvarer_updated_at()
|
|
RETURNS TRIGGER AS $$
|
|
BEGIN
|
|
NEW.updated_at = NOW();
|
|
RETURN NEW;
|
|
END;
|
|
$$ LANGUAGE plpgsql;
|
|
|
|
DROP TRIGGER IF EXISTS trigger_sag_salgsvarer_updated_at ON sag_salgsvarer;
|
|
CREATE TRIGGER trigger_sag_salgsvarer_updated_at
|
|
BEFORE UPDATE ON sag_salgsvarer
|
|
FOR EACH ROW
|
|
EXECUTE FUNCTION update_sag_salgsvarer_updated_at();
|