-- CreateEnum
CREATE TYPE "UserRole" AS ENUM ('super_admin', 'admin', 'user');

-- CreateEnum
CREATE TYPE "Gender" AS ENUM ('male', 'female', 'others');

-- CreateEnum
CREATE TYPE "OtpPurpose" AS ENUM ('login', 'password_reset', 'verify_email', 'others');

-- CreateEnum
CREATE TYPE "CashCollectionType" AS ENUM ('immpay', 'credit');

-- CreateEnum
CREATE TYPE "CashCollectionPaymentType" AS ENUM ('cash', 'bank');

-- CreateEnum
CREATE TYPE "WalletPaymentType" AS ENUM ('advance', 'redeem', 'cash');

-- CreateEnum
CREATE TYPE "WalletTransactionType" AS ENUM ('debit', 'credit');

-- CreateEnum
CREATE TYPE "RecipientType" AS ENUM ('tag', 'user_id', 'custom');

-- CreateTable
CREATE TABLE "users" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "username" VARCHAR(100) NOT NULL,
    "email" VARCHAR(100) NOT NULL,
    "email_verified" BOOLEAN NOT NULL DEFAULT false,
    "password" VARCHAR(255),
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "role" "UserRole" NOT NULL DEFAULT 'user',
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,
    "last_login" TIMESTAMPTZ,
    "last_login_device" VARCHAR(100),

    CONSTRAINT "users_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "user_details" (
    "id" SERIAL NOT NULL,
    "user_id" INTEGER NOT NULL,
    "code" VARCHAR(100) NOT NULL,
    "first_name" VARCHAR(100) NOT NULL,
    "last_name" VARCHAR(100),
    "designation_id" INTEGER,
    "department_id" INTEGER,
    "profile_pic" VARCHAR(255),
    "dob" DATE,
    "country_code" VARCHAR(100),
    "phone_number" VARCHAR(100),
    "gender" "Gender" NOT NULL DEFAULT 'male',
    "user_time_zone" VARCHAR(100),
    "address" VARCHAR(255),
    "culture" VARCHAR(100),
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "user_details_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "request_logs" (
    "id" BIGSERIAL NOT NULL,
    "user_id" INTEGER,
    "req_method" VARCHAR(100),
    "req_url" VARCHAR(255),
    "req_body" TEXT,
    "res_status" BOOLEAN NOT NULL DEFAULT false,
    "res_code" INTEGER NOT NULL DEFAULT 500,
    "res_message" TEXT,
    "req_response" TEXT,
    "req_headers" TEXT,
    "req_ip" VARCHAR(255),
    "req_device" VARCHAR(255),
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "request_logs_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "permissions" (
    "id" SERIAL NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "slug" VARCHAR(100) NOT NULL,
    "entity_id" INTEGER,
    "order_no" DECIMAL(4,2) NOT NULL DEFAULT 0,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "permissions_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "roles" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "name" VARCHAR(100) NOT NULL,
    "description" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "roles_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "role_permissions" (
    "role_id" INTEGER NOT NULL,
    "permission_id" INTEGER NOT NULL,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "role_permissions_pkey" PRIMARY KEY ("company_id","role_id","permission_id")
);

-- CreateTable
CREATE TABLE "user_roles" (
    "user_id" INTEGER NOT NULL,
    "role_id" INTEGER NOT NULL,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "user_roles_pkey" PRIMARY KEY ("company_id","user_id","role_id")
);

-- CreateTable
CREATE TABLE "user_permissions" (
    "user_id" INTEGER NOT NULL,
    "permission_id" INTEGER NOT NULL,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "user_permissions_pkey" PRIMARY KEY ("company_id","user_id","permission_id")
);

-- CreateTable
CREATE TABLE "otps" (
    "id" SERIAL NOT NULL,
    "user_id" INTEGER NOT NULL,
    "otp" VARCHAR(8) NOT NULL,
    "purpose" "OtpPurpose" NOT NULL,
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "otps_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "languages" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "name" VARCHAR(100) NOT NULL,
    "name_in_english" VARCHAR(100),
    "flag" VARCHAR(10),
    "code" VARCHAR(10),
    "rtl" BOOLEAN NOT NULL DEFAULT false,
    "description" TEXT NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "languages_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "language_contents" (
    "id" SERIAL NOT NULL,
    "language_id" INTEGER NOT NULL DEFAULT 1,
    "key_content" VARCHAR(100) NOT NULL,
    "values" VARCHAR(100) NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "language_contents_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "designations" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "code" VARCHAR(100) NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "description" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "is_approvel_required" BOOLEAN NOT NULL DEFAULT false,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "designations_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "departments" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "code" VARCHAR(100) NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "description" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "departments_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "vans" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "van_number" VARCHAR(100) NOT NULL,
    "van_model" VARCHAR(100) NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "department_id" INTEGER,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "vans_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "menu" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "name" VARCHAR(100) NOT NULL,
    "slug" VARCHAR(255),
    "description" VARCHAR(100),
    "menu_type" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "menu_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "menu_items" (
    "id" SERIAL NOT NULL,
    "menu_id" INTEGER NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "target" VARCHAR(255),
    "parent_id" INTEGER,
    "permission_id" INTEGER,
    "entity_id" INTEGER,
    "link_type" INTEGER,
    "order_no" DECIMAL(4,2) NOT NULL DEFAULT 0,
    "menu_img" VARCHAR(255),
    "short_cut_keys" VARCHAR(255),
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "menu_items_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "taxes" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "name" VARCHAR(100) NOT NULL,
    "tax_percentage" DECIMAL(5,2) NOT NULL DEFAULT 0,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "taxes_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "suppliers" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "code" VARCHAR(100) NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "description" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "address_line1" TEXT,
    "address_line2" TEXT,
    "area" VARCHAR(255),
    "city" VARCHAR(255),
    "country" VARCHAR(255),
    "phone" VARCHAR(100),
    "email_id" VARCHAR(255),
    "website" VARCHAR(255),
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "suppliers_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "brands" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "code" VARCHAR(100) NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "description" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "supplier_id" INTEGER,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "brands_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "banks" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "code" VARCHAR(100) NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "description" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "banks_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "bankbranches" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "bank_id" INTEGER NOT NULL,
    "code" VARCHAR(100) NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "description" TEXT,
    "outlet_target_id" INTEGER,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "bankbranches_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "price_types" (
    "PriceTypeID" SERIAL NOT NULL,
    "PriceType" VARCHAR(50) NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "price_types_pkey" PRIMARY KEY ("PriceTypeID")
);

-- CreateTable
CREATE TABLE "location_types" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "name" VARCHAR(100) NOT NULL,
    "description" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "location_types_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "payment_terms" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "outlet_id" BIGINT NOT NULL,
    "credit_days" INTEGER DEFAULT 0,
    "discount_type" CHAR(1) NOT NULL,
    "cash_payment_discount" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "payment_terms_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "outlets" (
    "id" BIGSERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "code" VARCHAR(100) NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "description" TEXT,
    "parent_id" BIGINT,
    "department_id" INTEGER,
    "mobile_no" VARCHAR(100),
    "phone_no" VARCHAR(100),
    "email" VARCHAR(100),
    "city" VARCHAR(255),
    "country" VARCHAR(255),
    "address" VARCHAR(255),
    "credit_limit" DECIMAL(18,10) NOT NULL DEFAULT 0,
    "allow_meterial_trans" BOOLEAN DEFAULT true,
    "allow_financial_trans" BOOLEAN DEFAULT true,
    "allow_credit" BOOLEAN DEFAULT false,
    "allow_central" BOOLEAN DEFAULT false,
    "allow_short_expiry_item" BOOLEAN DEFAULT false,
    "latitude" DECIMAL(18,10) NOT NULL DEFAULT 0.00000,
    "longitude" DECIMAL(18,10) NOT NULL DEFAULT 0.00000,
    "is_approved" BOOLEAN DEFAULT false,
    "cr_number" VARCHAR(100),
    "qid_number" VARCHAR(100),
    "qid_name" VARCHAR(255),
    "post_box_number" INTEGER,
    "currency_id" INTEGER,
    "area" VARCHAR(100),
    "sponsor_qid" VARCHAR(100),
    "sponsor_mobile_no" VARCHAR(100),
    "sponsor_name" VARCHAR(100),
    "outlet_class" VARCHAR(100),
    "outlet_category_id" INTEGER,
    "outlet_zone_id" INTEGER,
    "outlet_type_id" INTEGER,
    "outlet_classification_id" INTEGER,
    "outlet_group_id" INTEGER,
    "legal_document_path" VARCHAR(255),
    "payment_terms" VARCHAR(100),
    "available_credit_limit" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "total_wallet_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "total_outstanding_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "outlets_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "free_items" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "item_id" INTEGER NOT NULL,
    "uom_id" INTEGER NOT NULL,
    "quantity" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "start_date" TIMESTAMP(3) NOT NULL,
    "end_date" TIMESTAMP(3) NOT NULL,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "trade_name" VARCHAR(255) NOT NULL,
    "item_status_id" INTEGER NOT NULL,

    CONSTRAINT "free_items_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "outlet_targets" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "outlet_id" BIGINT NOT NULL,
    "name" VARCHAR(100),
    "description" TEXT,
    "outlet_target_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "from_date" TIMESTAMPTZ NOT NULL,
    "to_date" TIMESTAMPTZ NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "outlet_targets_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "currencies" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "code" VARCHAR(100) NOT NULL,
    "name" VARCHAR(255) NOT NULL,
    "symbol" VARCHAR(100) NOT NULL,
    "decimal_length" INTEGER NOT NULL DEFAULT 2,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "is_current_currency" BOOLEAN NOT NULL DEFAULT false,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "currencies_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "categories" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "code" VARCHAR(100) NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "description" TEXT,
    "parent_id" INTEGER,
    "type" VARCHAR(100),
    "is_current_category" BOOLEAN NOT NULL DEFAULT false,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "categories_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "items" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "code" VARCHAR(100) NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "description" TEXT,
    "category_id" INTEGER NOT NULL,
    "brand_id" INTEGER NOT NULL,
    "warehouse_id" INTEGER NOT NULL,
    "department_id" INTEGER NOT NULL,
    "is_core_item" BOOLEAN NOT NULL DEFAULT false,
    "supplier_id" INTEGER NOT NULL,
    "volumetric_uom_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "items_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "devices" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "device_no" VARCHAR(100) NOT NULL,
    "device_imei" VARCHAR(100) NOT NULL,
    "salesman_id" INTEGER,
    "route_id" INTEGER,
    "boot_loader_updated" BOOLEAN NOT NULL DEFAULT false,
    "firmware_version" VARCHAR(100),
    "hht_app_version" VARCHAR(100),
    "is_device_locked" BOOLEAN NOT NULL DEFAULT false,
    "is_pull" BOOLEAN NOT NULL DEFAULT false,
    "is_lock_initilized" BOOLEAN NOT NULL DEFAULT false,
    "locked_date_time" TIMESTAMPTZ,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "devices_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "salesman_outlet_mappings" (
    "salesman_id" INTEGER NOT NULL,
    "outlet_id" BIGINT NOT NULL,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "salesman_outlet_mappings_pkey" PRIMARY KEY ("company_id","outlet_id","salesman_id")
);

-- CreateTable
CREATE TABLE "warehouses" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "code" VARCHAR(100) NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "warehouses_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "display_control_types" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "control_type" VARCHAR(100) NOT NULL,
    "dt_string" INTEGER NOT NULL,
    "integer_dt" INTEGER NOT NULL,
    "decimal_dt" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "boolean_dt" BOOLEAN NOT NULL DEFAULT false,
    "date_dt" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "time_dt" TIMESTAMPTZ NOT NULL,
    "date_time_dt" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "display_control_types_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "routes" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "code" VARCHAR(100) NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "routes_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "versions" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "assembly_version" VARCHAR(100) NOT NULL,
    "release_date" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "versions_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "route_outlet_mappings" (
    "route_id" INTEGER NOT NULL,
    "outlet_id" BIGINT NOT NULL,
    "company_id" INTEGER NOT NULL,
    "sequence_no" INTEGER NOT NULL,

    CONSTRAINT "route_outlet_mappings_pkey" PRIMARY KEY ("company_id","route_id","outlet_id")
);

-- CreateTable
CREATE TABLE "alert_datas" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "to_address" TEXT NOT NULL,
    "cc_address" TEXT,
    "bcc_address" TEXT,
    "user_id" INTEGER NOT NULL,
    "alert_notification_type_id" INTEGER NOT NULL,
    "alert_type_id" INTEGER NOT NULL,
    "alert_subject" VARCHAR(255),
    "alert_content" TEXT NOT NULL,
    "process_result_id" INTEGER,
    "department_id" INTEGER,
    "error_count" INTEGER NOT NULL DEFAULT 0,
    "is_transfered" BOOLEAN NOT NULL DEFAULT false,
    "is_delivered" BOOLEAN NOT NULL DEFAULT false,
    "transfered_at" TIMESTAMPTZ,
    "delivered_at" TIMESTAMPTZ,
    "file_path" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "alert_datas_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "outlet_persons" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "outlet_id" BIGINT NOT NULL,
    "person_name" VARCHAR(255) NOT NULL,
    "person_qid" VARCHAR(100),
    "mobile_no" VARCHAR(100),
    "email" VARCHAR(100),
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "outlet_persons_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "item_uoms" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "uom_id" INTEGER NOT NULL,
    "item_id" INTEGER NOT NULL,
    "conversion_factor" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "is_base_uom" BOOLEAN NOT NULL DEFAULT false,
    "item_barcode" VARCHAR(100) NOT NULL,
    "volume" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "pricing" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "item_uoms_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "outlet_classifications" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "code" VARCHAR(100) NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "description" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "outlet_classifications_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "reasons" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "reason" VARCHAR(255) NOT NULL,
    "reason_type" VARCHAR(100) NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "reasons_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "discount_line_items" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "discount_id" INTEGER NOT NULL,
    "item_id" INTEGER NOT NULL,
    "uom_id" INTEGER NOT NULL,
    "outlet_id" BIGINT NOT NULL,
    "outlet_group_id" INTEGER NOT NULL,
    "outlet_category_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,

    CONSTRAINT "discount_line_items_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "route_pattern_line_items" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "route_pattern_id" INTEGER NOT NULL,
    "route_id" INTEGER NOT NULL,
    "day_no" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,

    CONSTRAINT "route_pattern_line_items_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "uoms" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "code" VARCHAR(100) NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "description" TEXT,
    "uom_class" VARCHAR(100) NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "is_logistics_uom" INTEGER NOT NULL DEFAULT 0,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "uoms_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "outlet_zones" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "code" VARCHAR(100) NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "description" TEXT,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,

    CONSTRAINT "outlet_zones_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "team_line_items" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "team_id" INTEGER NOT NULL,
    "salesman_id" INTEGER,
    "route_id" INTEGER,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "team_line_items_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "price_lists" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "name" VARCHAR(100) NOT NULL,
    "description" TEXT,
    "item_status_id" INTEGER,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "price_lists_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "price_list_lineitems" (
    "id" SERIAL NOT NULL,
    "price_list_id" INTEGER NOT NULL,
    "item_id" INTEGER NOT NULL,
    "uom_id" INTEGER NOT NULL,
    "price" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "price_list_lineitems_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "outlet_price_list_mapping" (
    "item_status_id" INTEGER NOT NULL,
    "outlet_id" BIGINT NOT NULL,
    "price_list_id" INTEGER NOT NULL,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "outlet_price_list_mapping_pkey" PRIMARY KEY ("company_id","outlet_id","price_list_id","item_status_id")
);

-- CreateTable
CREATE TABLE "outlet_types" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "code" VARCHAR(100) NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "description" TEXT,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,

    CONSTRAINT "outlet_types_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "tax_line_items" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "tax_id" INTEGER NOT NULL,
    "item_id" INTEGER NOT NULL,
    "item_category_id" INTEGER,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,

    CONSTRAINT "tax_line_items_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "outlet_scans" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "outlet_id" BIGINT NOT NULL,
    "salesman_id" INTEGER NOT NULL,
    "in_date_time" TIMESTAMPTZ NOT NULL,
    "out_date_time" TIMESTAMPTZ,
    "journey_plan_id" INTEGER NOT NULL,
    "in_latitude" DECIMAL(18,10) NOT NULL DEFAULT 0.00000,
    "in_longitude" DECIMAL(18,10) NOT NULL DEFAULT 0.00000,
    "out_latitude" DECIMAL(18,10) NOT NULL DEFAULT 0.00000,
    "out_longitude" DECIMAL(18,10) NOT NULL DEFAULT 0.00000,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "in_reason_id" INTEGER NOT NULL,
    "out_reason_id" INTEGER NOT NULL,
    "web_service_log_id" BIGINT NOT NULL,

    CONSTRAINT "outlet_scans_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "outlet_credit_limits" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "salesman_id" INTEGER NOT NULL,
    "outlet_id" BIGINT NOT NULL,
    "outlet_limit" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "credit_duration" INTEGER NOT NULL DEFAULT 0,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "return_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "available_credit_limit" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "outlet_group_id" INTEGER NOT NULL,

    CONSTRAINT "outlet_credit_limits_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "discounts" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "discount_name" VARCHAR(255) NOT NULL,
    "discount_value" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "start_date" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "end_date" TIMESTAMPTZ,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "value_type" VARCHAR(100) NOT NULL,

    CONSTRAINT "discounts_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "route_patterns" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "code" VARCHAR(100) NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "description" TEXT,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,

    CONSTRAINT "route_patterns_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "free_item_outlet_mappings" (
    "free_item_id" INTEGER NOT NULL,
    "outlet_id" BIGINT NOT NULL,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "free_item_outlet_mappings_pkey" PRIMARY KEY ("company_id","outlet_id","free_item_id")
);

-- CreateTable
CREATE TABLE "teams" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "supervisor_id" INTEGER NOT NULL,
    "team_name" VARCHAR(255) NOT NULL,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,

    CONSTRAINT "teams_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "outlet_target_line_items" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "outlet_target_id" INTEGER NOT NULL,
    "item_id" INTEGER NOT NULL,
    "target_quantity" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,

    CONSTRAINT "outlet_target_line_items_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "outlet_groups" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "code" VARCHAR(100) NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "description" TEXT,
    "parent_id" INTEGER,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,

    CONSTRAINT "outlet_groups_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "item_statuses" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "name" VARCHAR(100) NOT NULL,
    "allw_invoice" BOOLEAN NOT NULL DEFAULT false,
    "allow_return" BOOLEAN NOT NULL DEFAULT false,
    "allow_vanload" BOOLEAN NOT NULL DEFAULT false,
    "allow_vanunload" BOOLEAN NOT NULL DEFAULT false,
    "allow_damage_request" BOOLEAN NOT NULL DEFAULT false,
    "allow_reconcile_dump" BOOLEAN NOT NULL DEFAULT false,
    "allow_promotion" BOOLEAN NOT NULL DEFAULT false,
    "allow_price_list" BOOLEAN NOT NULL DEFAULT false,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,

    CONSTRAINT "item_statuses_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "outlet_categories" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "code" VARCHAR(100) NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "description" TEXT,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,

    CONSTRAINT "outlet_categories_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "salesman_item_mappings" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "salesman_id" INTEGER,
    "route_id" INTEGER,
    "item_id" INTEGER,
    "item_category_id" INTEGER,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "salesman_item_mappings_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "route_outlet_sequences" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "route_id" INTEGER NOT NULL,
    "outlet_id" BIGINT NOT NULL,
    "sequence_no" INTEGER NOT NULL,
    "day_no" INTEGER NOT NULL DEFAULT 0,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,

    CONSTRAINT "route_outlet_sequences_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "alert_types" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "alert_type_name" VARCHAR(100) NOT NULL,
    "alert_type_desc" VARCHAR(255) NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "is_deleted" BOOLEAN NOT NULL DEFAULT false,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "alert_types_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "user_grids" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "user_id" INTEGER NOT NULL,
    "target_index_id" INTEGER NOT NULL,
    "target_index_line_item_id" INTEGER NOT NULL,
    "order_no" DECIMAL(4,2) NOT NULL,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,

    CONSTRAINT "user_grids_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "master_transactions" (
    "id" SERIAL NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "entity_name" VARCHAR(100) NOT NULL,
    "primary_table" VARCHAR(100) NOT NULL,
    "query_information" JSONB,
    "sample_query" JSONB,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "master_transactions_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "action_types" (
    "id" SERIAL NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "description" VARCHAR(255) NOT NULL,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "action_types_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "entity_types" (
    "id" SERIAL NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "slug" VARCHAR(100) NOT NULL,
    "description" VARCHAR(255) NOT NULL,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "entity_types_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "wizard_group" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "name" VARCHAR(100) NOT NULL,
    "slug" VARCHAR(100) NOT NULL,
    "description" VARCHAR(100),
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "wizard_group_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "wizard_types" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "name" VARCHAR(100) NOT NULL,
    "description" VARCHAR(100) NOT NULL,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "wizard_types_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "master_entities" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "name" VARCHAR(100) NOT NULL,
    "entity_name" VARCHAR(100) NOT NULL,
    "entity_type" VARCHAR(100) NOT NULL,
    "primary_table" VARCHAR(100),
    "query_information" JSONB,
    "form_information" JSONB,
    "add_query_information" JSONB,
    "edit_query_information" JSONB,
    "preset_query_information" JSONB,
    "static_page_content" TEXT,
    "dashboard_wizard_group_id" INTEGER,
    "dashboard_wizard_type" VARCHAR(100),
    "dashboard_wizard_rows" INTEGER,
    "dashboard_wizard_columns" INTEGER,
    "dashboard_wizard_order_no" DECIMAL(4,2) DEFAULT 0,
    "dashboard_wizard_options" JSONB,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "master_entities_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "master_entity_line_items" (
    "id" SERIAL NOT NULL,
    "master_grid_id" INTEGER NOT NULL,
    "field_name" VARCHAR(255) NOT NULL,
    "display_name" VARCHAR(100) NOT NULL,
    "width" INTEGER DEFAULT 0,
    "format" VARCHAR(100),
    "is_default" BOOLEAN NOT NULL DEFAULT true,
    "order_no" DECIMAL(4,2) NOT NULL DEFAULT 0,
    "is_grid_column" BOOLEAN NOT NULL DEFAULT true,
    "is_searchable" BOOLEAN NOT NULL DEFAULT true,
    "is_sortable" BOOLEAN NOT NULL DEFAULT true,
    "field_type_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "master_entity_line_items_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "field_types" (
    "id" SERIAL NOT NULL,
    "field_type" VARCHAR(100) NOT NULL,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "field_types_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "invoice_request_line_items" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "invoice_request_id" INTEGER NOT NULL,
    "item_id" INTEGER NOT NULL,
    "uom_id" INTEGER NOT NULL,
    "tax_name" VARCHAR(100) NOT NULL,
    "tax" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "tax_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "quantity" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "is_free_item" BOOLEAN NOT NULL DEFAULT false,
    "discount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "discount_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "transaction_type" VARCHAR(100) NOT NULL,
    "item_status_id" INTEGER NOT NULL,
    "is_manual_foc" BOOLEAN,
    "discount_type" VARCHAR(100) NOT NULL,
    "unit_price" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,

    CONSTRAINT "invoice_request_line_items_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "coordinator_approvals" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "supervisor_approval_id" BIGINT NOT NULL,
    "supervisor_id" INTEGER NOT NULL,
    "item_id" INTEGER NOT NULL,
    "uom_id" INTEGER NOT NULL,
    "quantity" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "supervisor_quantity" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "approval_quantity" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "approved_by" INTEGER NOT NULL,
    "approved_date_time" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,

    CONSTRAINT "coordinator_approvals_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "supervisor_approvals" (
    "id" BIGSERIAL NOT NULL,
    "van_load_request_id" BIGINT NOT NULL,
    "supervisor_id" INTEGER NOT NULL,
    "item_id" INTEGER NOT NULL,
    "uom_id" INTEGER NOT NULL,
    "quantity" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "supervisor_quantity" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "approval_quantity" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "approved_by" INTEGER NOT NULL,
    "approved_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "supervisor_approvals_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "approval_workflow_line_items" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "approval_workflow_id" INTEGER NOT NULL,
    "approval_by" INTEGER NOT NULL,
    "order_no" DECIMAL(4,2) NOT NULL DEFAULT 0,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,

    CONSTRAINT "approval_workflow_line_items_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "approval_workflows" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "workflow_name" VARCHAR(100) NOT NULL,
    "entity_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,

    CONSTRAINT "approval_workflows_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "entity_constraints" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "approval_workflow_id" INTEGER NOT NULL,
    "field_name" VARCHAR(100) NOT NULL,
    "field_type_id" INTEGER NOT NULL,
    "field_constraint" VARCHAR(100) NOT NULL,
    "field_value" VARCHAR(100) NOT NULL,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,

    CONSTRAINT "entity_constraints_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "approver_constraints" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "approval_workflow_id" INTEGER NOT NULL,
    "field_name" VARCHAR(100) NOT NULL,
    "field_type_id" INTEGER NOT NULL,
    "field_value" VARCHAR(100) NOT NULL,
    "order_no" DECIMAL(4,2) NOT NULL DEFAULT 0,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,

    CONSTRAINT "approver_constraints_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "approval_modules" (
    "id" SERIAL NOT NULL,
    "module_name" VARCHAR(100) NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "approval_modules_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "damage_request_line_items" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "damage_request_id" INTEGER NOT NULL,
    "item_id" INTEGER NOT NULL,
    "uom_id" INTEGER NOT NULL,
    "quantity" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "item_status_id" INTEGER NOT NULL,
    "salesman_qty" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "storekeeper_qty" DECIMAL(18,5) NOT NULL DEFAULT 0,

    CONSTRAINT "damage_request_line_items_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "damage_requests" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "damage_request_no" VARCHAR(50) NOT NULL,
    "damage_request_date" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "salesman_id" INTEGER NOT NULL,
    "process_status_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "web_service_log_id" BIGINT NOT NULL,
    "storekeeper_id" INTEGER,
    "stock_accept_date_time" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "damage_requests_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "invoice_requests" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "invoice_request_no" VARCHAR(100) NOT NULL,
    "invoice_request_date_time" TIMESTAMP(3) NOT NULL,
    "outlet_id" BIGINT NOT NULL,
    "salesman_id" INTEGER NOT NULL,
    "total_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "received_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "invoice_discount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "payment_type" VARCHAR(100) NOT NULL,
    "transaction_type" VARCHAR(100) NOT NULL,
    "signature" TEXT NOT NULL,
    "currency_id" INTEGER NOT NULL,
    "cheque_number" VARCHAR(100) NOT NULL,
    "cheque_date" TIMESTAMP(3) NOT NULL,
    "is_current_dated_cheque" BOOLEAN NOT NULL DEFAULT false,
    "bank_name" VARCHAR(255) NOT NULL,
    "branch_name" VARCHAR(255) NOT NULL,
    "redeem_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "bank_id" INTEGER NOT NULL,
    "bank_branch_id" INTEGER NOT NULL,
    "invoice_tax_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "return_tax_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "created_from_web" BOOLEAN NOT NULL DEFAULT false,
    "cheque_image" TEXT NOT NULL,
    "outlet_discount_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "process_status_id" INTEGER NOT NULL,
    "invoice_id" INTEGER,
    "web_service_log_id" BIGINT,
    "outlet_discount_type" VARCHAR(100) NOT NULL,
    "outlet_discount_value" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,

    CONSTRAINT "invoice_requests_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "invoice_collections" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "document_no" VARCHAR(100) NOT NULL,
    "journey_plan_id" INTEGER NOT NULL,
    "invoice_id" INTEGER NOT NULL,
    "invoice_no" VARCHAR(100) NOT NULL,
    "collection_date_time" TIMESTAMP(3) NOT NULL,
    "outlet_id" BIGINT NOT NULL,
    "salesman_id" INTEGER NOT NULL,
    "invoice_pending_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "collected_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "payment_type" VARCHAR(100) NOT NULL,
    "transaction_type" VARCHAR(100) NOT NULL,
    "signature" TEXT NOT NULL,
    "currency_id" INTEGER NOT NULL,
    "cheque_number" VARCHAR(100) NOT NULL,
    "cheque_date" TIMESTAMP(3) NOT NULL,
    "is_current_dated_cheque" BOOLEAN NOT NULL DEFAULT false,
    "bank_name" VARCHAR(255) NOT NULL,
    "branch_name" VARCHAR(255) NOT NULL,
    "bank_id" INTEGER NOT NULL,
    "bank_branch_id" INTEGER NOT NULL,
    "redeem_amount" DECIMAL(18,5) NOT NULL,
    "cheque_image" BYTEA,
    "web_service_log_id" BIGINT NOT NULL,
    "ratings" VARCHAR(255) NOT NULL,
    "latitude" DECIMAL(18,10) NOT NULL DEFAULT 0.00000,
    "longitude" DECIMAL(18,10) NOT NULL DEFAULT 0.00000,
    "print_count" INTEGER NOT NULL DEFAULT 0,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,

    CONSTRAINT "invoice_collections_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "invoices" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "journey_plan_id" INTEGER NOT NULL,
    "invoice_no" VARCHAR(100) NOT NULL,
    "invoice_date_time" TIMESTAMP(3) NOT NULL,
    "outlet_id" BIGINT NOT NULL,
    "salesman_id" INTEGER,
    "route_id" INTEGER,
    "total_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "received_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "invoice_discount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "payment_type" VARCHAR(100) NOT NULL,
    "transaction_type" VARCHAR(100) NOT NULL,
    "signature" TEXT NOT NULL,
    "currency_id" INTEGER NOT NULL,
    "cheque_number" VARCHAR(100) NOT NULL,
    "cheque_date" TIMESTAMP(3) NOT NULL,
    "is_current_dated_cheque" BOOLEAN NOT NULL DEFAULT false,
    "bank_name" VARCHAR(255) NOT NULL,
    "branch_name" VARCHAR(255) NOT NULL,
    "redeem_amount" DECIMAL(18,5) NOT NULL,
    "bank_id" INTEGER NOT NULL,
    "bank_branch_id" INTEGER NOT NULL,
    "tax_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "created_from_web" BOOLEAN NOT NULL DEFAULT false,
    "cheque_image" TEXT NOT NULL,
    "web_service_log_id" BIGINT NOT NULL,
    "outlet_discount_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "process_status_id" INTEGER NOT NULL,
    "outlet_discount_type" VARCHAR(100) NOT NULL,
    "outlet_discount_value" DECIMAL(18,5) NOT NULL,
    "reconciliation_id" INTEGER NOT NULL,
    "is_cash_received" BOOLEAN NOT NULL DEFAULT false,
    "manual_cash_discount_value" DECIMAL(18,5) NOT NULL,
    "manual_cash_discount_amount" DECIMAL(18,5) NOT NULL,
    "sent_status" BOOLEAN NOT NULL DEFAULT false,
    "sent_date_time" TIMESTAMP(3) NOT NULL,
    "ratings" VARCHAR(255) NOT NULL,
    "latitude" DECIMAL(18,10) NOT NULL DEFAULT 0.00000,
    "longitude" DECIMAL(18,10) NOT NULL DEFAULT 0.00000,
    "manual_cash_discount_type" VARCHAR(100) NOT NULL,
    "deleted_reason" VARCHAR(255) NOT NULL,
    "free_item_tax_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "print_count" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,

    CONSTRAINT "invoices_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "invoice_line_items" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "invoice_id" INTEGER NOT NULL,
    "item_id" INTEGER NOT NULL,
    "uom_id" INTEGER NOT NULL,
    "tax_name" VARCHAR(100),
    "tax" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "tax_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "quantity" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "amount" DECIMAL(18,5) NOT NULL,
    "is_free_item" BOOLEAN DEFAULT false,
    "discount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "discount_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "is_manual_foc" BOOLEAN,
    "free_item_id" INTEGER,
    "unit_price" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "discount_type" VARCHAR(50),
    "retail_unit_price" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "item_status_id" INTEGER DEFAULT 1,
    "old_line_amount" INTEGER,
    "old_tax_amount" INTEGER,
    "old_unit_price" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "invoice_line_items_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "credit_dues" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "credit_due_no" VARCHAR(100) NOT NULL,
    "outlet_id" BIGINT NOT NULL,
    "statement_id" INTEGER,
    "amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "pending_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "currency_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "credit_dues_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "journey_plans" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "plan_date" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "salesman_id" INTEGER NOT NULL,
    "route_id" INTEGER NOT NULL,
    "day_no" INTEGER NOT NULL DEFAULT 0,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "journey_plans_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "upper_trade_logs" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "error_details" VARCHAR(255) NOT NULL,
    "table_name" VARCHAR(100) NOT NULL,
    "reference_no" VARCHAR(100) NOT NULL,
    "line_reference_no" VARCHAR(100) NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "upper_trade_logs_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "reconciliation_line_items" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "reconciliation_id" INTEGER NOT NULL,
    "item_status_id" INTEGER NOT NULL,
    "hht_stock_quantity" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "reconcile_quantity" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "variance_quantity" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "variance_value" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "total_variance_value" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "item_id" INTEGER NOT NULL,
    "uom_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "reconciliation_line_items_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "pre_order_line_items" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "pre_order_id" INTEGER NOT NULL,
    "item_id" INTEGER NOT NULL,
    "uom_id" INTEGER NOT NULL,
    "quantity" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "item_status_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "pre_order_line_items_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "reconciliations" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "reconciliation_no" VARCHAR(100) NOT NULL,
    "store_keeper_id" INTEGER NOT NULL,
    "salesman_id" INTEGER NOT NULL,
    "reconciliation_date" TIMESTAMP(3) NOT NULL,
    "process_status_id" INTEGER NOT NULL DEFAULT 1,
    "is_cash_received" BOOLEAN NOT NULL DEFAULT false,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "reconciliations_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "pre_orders" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "pre_order_no" VARCHAR(100) NOT NULL,
    "pre_order_date" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "journey_plan_id" INTEGER,
    "outlet_id" BIGINT NOT NULL,
    "salesman_id" INTEGER NOT NULL,
    "amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "request_delivery_date" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "order_discount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "signature" TEXT NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "pre_orders_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "salesman_targets" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "salesman_id" INTEGER NOT NULL,
    "outlet_id" BIGINT NOT NULL,
    "salesman_target_amount" INTEGER NOT NULL DEFAULT 0,
    "from_date" TIMESTAMP(3) NOT NULL,
    "to_date" TIMESTAMP(3) NOT NULL,
    "target_type" VARCHAR(100) NOT NULL,
    "brand_id" INTEGER,
    "supplier_id" INTEGER,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "salesman_targets_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "department_salesman_mappings" (
    "id" SERIAL NOT NULL,
    "department_id" INTEGER NOT NULL,
    "salesman_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "company_id" INTEGER NOT NULL,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "department_salesman_mappings_pkey" PRIMARY KEY ("company_id","salesman_id","department_id")
);

-- CreateTable
CREATE TABLE "salesman_trackings" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "salesman_id" INTEGER NOT NULL,
    "device_id" INTEGER NOT NULL,
    "device_no" VARCHAR(100) NOT NULL,
    "latitude" DECIMAL(18,10) NOT NULL DEFAULT 0.00000,
    "longitude" DECIMAL(18,10) NOT NULL DEFAULT 0.00000,
    "outlet_id" BIGINT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "salesman_trackings_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "van_unload_request_line_items" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "van_unload_request_id" INTEGER NOT NULL,
    "item_id" INTEGER NOT NULL,
    "uom_id" INTEGER NOT NULL,
    "quantity" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "item_status_id" INTEGER,
    "salesman_qty" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "storekeeper_qty" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "van_unload_request_line_items_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "return_line_items" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "return_id" INTEGER NOT NULL,
    "item_id" INTEGER NOT NULL,
    "uom_id" INTEGER NOT NULL,
    "quantity" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "tax_name" VARCHAR(100) NOT NULL,
    "tax" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "tax_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "remarks" VARCHAR(255) NOT NULL,
    "item_status_id" INTEGER,
    "unit_price" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "retail_unit_price" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "discount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "discount_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "discount_type" VARCHAR(100) NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "return_line_items_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "salesman_target_line_items" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "salesman_target_id" INTEGER NOT NULL,
    "item_id" INTEGER NOT NULL,
    "salesman_target_quantity" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "salesman_target_line_items_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "van_unload_requests" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "request_no" VARCHAR(100) NOT NULL,
    "request_date" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "salesman_id" INTEGER,
    "route_id" INTEGER,
    "process_status_id" INTEGER NOT NULL,
    "created_from_web" INTEGER NOT NULL DEFAULT 0,
    "web_service_log_id" BIGINT,
    "remarks" VARCHAR(255) NOT NULL,
    "storekeeper_id" INTEGER,
    "stock_issued_date_time" TIMESTAMP(3),
    "department_id" INTEGER,
    "total_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "disc_percent" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "disc_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "tax_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "van_unload_requests_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "return_items" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "return_no" VARCHAR(100) NOT NULL,
    "return_date_time" TIMESTAMP(3) NOT NULL,
    "invoice_id" INTEGER,
    "journey_plan_id" INTEGER,
    "outlet_id" BIGINT NOT NULL,
    "salesman_id" INTEGER NOT NULL,
    "route_id" INTEGER,
    "total_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "signature" TEXT NOT NULL,
    "currency_id" INTEGER NOT NULL,
    "invoice_no" VARCHAR(100) NOT NULL,
    "remarks" VARCHAR(255) NOT NULL,
    "tax_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "created_from_web" BOOLEAN NOT NULL DEFAULT false,
    "web_service_log_id" BIGINT,
    "process_status_id" INTEGER,
    "reconciliation_id" INTEGER,
    "is_cash_received" BOOLEAN NOT NULL DEFAULT false,
    "sent_status" BOOLEAN NOT NULL DEFAULT false,
    "sent_date_time" TIMESTAMP(3),
    "ratings" VARCHAR(255) NOT NULL,
    "latitude" DECIMAL(18,10) NOT NULL DEFAULT 0.00000,
    "longitude" DECIMAL(18,10) NOT NULL DEFAULT 0.00000,
    "discount_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "deleted_reason" VARCHAR(255) NOT NULL,
    "print_count" INTEGER NOT NULL DEFAULT 0,
    "transaction_type" VARCHAR(100) NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "return_items_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "financial_years" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "name" VARCHAR(100) NOT NULL,
    "code" VARCHAR(100) NOT NULL,
    "is_freezed" BOOLEAN NOT NULL DEFAULT false,
    "start_date" TIMESTAMPTZ NOT NULL,
    "end_date" TIMESTAMPTZ NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "financial_years_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "configurations" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "conf_name" VARCHAR(100) NOT NULL,
    "conf_value" TEXT NOT NULL,
    "tool_tip_text" VARCHAR(100),
    "data_type" VARCHAR(100),
    "drop_down_value" TEXT,
    "min_value" INTEGER,
    "max_value" INTEGER,
    "conf_type" CHAR(1) NOT NULL,
    "order_no" DECIMAL(4,2) NOT NULL DEFAULT 0,
    "default_value" TEXT,
    "suffix_text" VARCHAR(100),
    "category_name" VARCHAR(100) NOT NULL,
    "conf_imgs" VARCHAR(255),
    "is_admin_access" BOOLEAN NOT NULL DEFAULT false,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "configurations_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "audit_logs" (
    "id" SERIAL NOT NULL,
    "action_type" INTEGER,
    "entity_name" VARCHAR(100),
    "user_id" INTEGER,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "audit_logs_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "audit_log_line_items" (
    "id" SERIAL NOT NULL,
    "audit_log_id" INTEGER NOT NULL,
    "entity_id" INTEGER NOT NULL,
    "field_name" VARCHAR(100) NOT NULL,
    "old_value" TEXT,
    "new_value" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "audit_log_line_items_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "app_error_log" (
    "id" SERIAL NOT NULL,
    "url_str" TEXT,
    "req_data" TEXT,
    "res_data" TEXT,
    "stack_trace" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "app_error_log_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "process_status" (
    "id" SERIAL NOT NULL,
    "name" TEXT NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "process_status_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "webservice_logs" (
    "id" BIGSERIAL NOT NULL,
    "salesman_id" INTEGER,
    "route_id" INTEGER,
    "req_method" VARCHAR(100),
    "device_id" INTEGER,
    "service_type" VARCHAR(100),
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "app_version" VARCHAR(100),
    "parameters" TEXT,
    "time_taken_to_complete" INTEGER,
    "response" TEXT,
    "device_imei" VARCHAR(100),
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "webservice_logs_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "application_modules" (
    "id" SERIAL NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "application_modules_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "alert_notify_types" (
    "id" SERIAL NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "description" TEXT,
    "max_chars" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "alert_notify_types_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "document_sequences" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "module_name" VARCHAR(100) NOT NULL,
    "salesman_id" INTEGER NOT NULL,
    "prefix_code" CHAR(1) NOT NULL DEFAULT 'V',
    "salesman_code" VARCHAR(100),
    "code_value" INTEGER,
    "current_sequence_no" BIGINT NOT NULL,
    "start_sequence_no" INTEGER NOT NULL DEFAULT 0,
    "end_sequence_no" INTEGER NOT NULL DEFAULT 0,
    "doc_year" INTEGER NOT NULL,
    "fin_year_id" INTEGER,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "document_sequences_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "user_configurations" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "user_id" INTEGER,
    "conf_name" VARCHAR(100) NOT NULL,
    "conf_value" TEXT,
    "tool_tip_text" VARCHAR(100),
    "data_type" VARCHAR(100),
    "drop_down_value" TEXT,
    "min_value" INTEGER,
    "max_value" INTEGER,
    "conf_type" CHAR(1) NOT NULL DEFAULT 'C',
    "order_no" DECIMAL(4,2) NOT NULL DEFAULT 0,
    "default_value" TEXT,
    "display_conf" INTEGER DEFAULT 1,
    "suffix_text" VARCHAR(100),
    "category_name" VARCHAR(100) NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "user_configurations_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "user_types" (
    "id" SERIAL NOT NULL,
    "name" VARCHAR(100),
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "user_types_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "data_transfer_queries" (
    "id" BIGSERIAL NOT NULL,
    "select_query" TEXT NOT NULL,
    "insert_query" TEXT NOT NULL,
    "transfer_type" VARCHAR(100) NOT NULL,
    "job_name" VARCHAR(100) NOT NULL,
    "destination_table_name" VARCHAR(100) NOT NULL,
    "clear_destination_table" BOOLEAN DEFAULT false,
    "execution_order" INTEGER NOT NULL,
    "command_type" VARCHAR(100) NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "data_transfer_queries_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "warehouse_stocks" (
    "id" BIGSERIAL NOT NULL,
    "warehouse_id" INTEGER NOT NULL,
    "item_id" INTEGER NOT NULL,
    "uom_id" INTEGER NOT NULL,
    "quantity" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "item_status_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ,

    CONSTRAINT "warehouse_stocks_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "stock_adjustments" (
    "id" SERIAL NOT NULL,
    "adjustment_date" TIMESTAMPTZ NOT NULL,
    "salesman_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ,

    CONSTRAINT "stock_adjustments_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "stock_adjustment_line_items" (
    "id" SERIAL NOT NULL,
    "stock_adjustment_id" INTEGER NOT NULL,
    "item_id" INTEGER NOT NULL,
    "item_status_id" INTEGER NOT NULL,
    "quantity" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "current_van_stock" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "stock_adjustment_line_items_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "daily_open_stocks" (
    "id" BIGSERIAL NOT NULL,
    "item_id" INTEGER NOT NULL,
    "salesman_id" INTEGER NOT NULL,
    "uom_id" INTEGER NOT NULL,
    "item_status_id" INTEGER NOT NULL,
    "quantity" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ,

    CONSTRAINT "daily_open_stocks_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "stock_transfer_requests" (
    "id" BIGSERIAL NOT NULL,
    "stock_transfer_request_date" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "stock_transfer_request_no" VARCHAR(100) NOT NULL,
    "from_salesman_id" INTEGER NOT NULL,
    "to_salesman_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "process_status_id" INTEGER NOT NULL,
    "web_service_log_id" BIGINT,
    "storekeeper_id" INTEGER,
    "stock_accept_date_time" TIMESTAMPTZ,
    "stock_issued_date_time" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ,

    CONSTRAINT "stock_transfer_requests_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "stock_transfer_request_line_items" (
    "id" SERIAL NOT NULL,
    "stock_transfer_request_id" BIGINT NOT NULL,
    "item_id" INTEGER NOT NULL,
    "uom_id" INTEGER NOT NULL,
    "quantity" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "item_status_id" INTEGER NOT NULL,
    "salesman_qty" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "storekeeper_qty" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "stock_transfer_request_line_items_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "outlet_stock_audit_headers" (
    "id" BIGSERIAL NOT NULL,
    "outlet_stock_audit_no" VARCHAR(100) NOT NULL,
    "outlet_stock_audit_date" TIMESTAMPTZ,
    "outlet_id" BIGINT NOT NULL,
    "salesman_id" INTEGER NOT NULL,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ,

    CONSTRAINT "outlet_stock_audit_headers_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "outlet_stock_audit_line_items" (
    "id" SERIAL NOT NULL,
    "outlet_stock_audit_header_id" BIGINT NOT NULL,
    "item_id" INTEGER NOT NULL,
    "uom_id" INTEGER NOT NULL,
    "quantity" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "item_status_id" INTEGER NOT NULL,
    "location_type_id" INTEGER NOT NULL,
    "expiry_date_time" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "created_by" INTEGER NOT NULL,
    "updated_at" TIMESTAMPTZ,
    "updated_by" INTEGER,

    CONSTRAINT "outlet_stock_audit_line_items_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "van_load_requests" (
    "id" BIGSERIAL NOT NULL,
    "request_no" VARCHAR(50) NOT NULL,
    "request_date" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "salesman_id" INTEGER,
    "route_id" INTEGER,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "process_status_id" INTEGER NOT NULL,
    "web_service_log_id" BIGINT,
    "expected_delivery_date" TIMESTAMPTZ,
    "is_supervisor_approval" BOOLEAN NOT NULL DEFAULT false,
    "is_coordinator_approval" BOOLEAN NOT NULL DEFAULT false,
    "van_load_approval_id" BIGINT,
    "storekeeper_id" INTEGER,
    "stock_accept_date_time" TIMESTAMPTZ,
    "sent_status" BOOLEAN NOT NULL DEFAULT false,
    "department_id" INTEGER,
    "total_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "disc_perc" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "disc_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "tax_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ,
    "created_from_web" BOOLEAN NOT NULL DEFAULT false,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "van_load_requests_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "van_load_request_line_items" (
    "id" BIGSERIAL NOT NULL,
    "van_load_request_id" BIGINT NOT NULL,
    "item_id" INTEGER NOT NULL,
    "uom_id" INTEGER NOT NULL,
    "quantity" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "item_status_id" INTEGER,
    "salesman_qty" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "is_supervisor_approval" BOOLEAN NOT NULL DEFAULT false,
    "is_coordinator_approval" BOOLEAN NOT NULL DEFAULT false,
    "storekeeper_qty" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "coordinator_qty" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "created_by" INTEGER NOT NULL,

    CONSTRAINT "van_load_request_line_items_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "van_load_approvals" (
    "id" BIGSERIAL NOT NULL,
    "date" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "supervisor_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "van_load_approvals_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "van_load_approval_line_items" (
    "id" BIGSERIAL NOT NULL,
    "van_load_approval_id" BIGINT NOT NULL,
    "item_id" INTEGER NOT NULL,
    "uom_id" INTEGER NOT NULL,
    "item_status_id" INTEGER NOT NULL,
    "quantity" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "approved_quantity" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "salesman_id" INTEGER,
    "route_id" INTEGER,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "van_load_approval_line_items_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "van_stocks" (
    "id" BIGSERIAL NOT NULL,
    "item_id" INTEGER NOT NULL,
    "uom_id" INTEGER NOT NULL,
    "quantity" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "salesman_id" INTEGER,
    "route_id" INTEGER,
    "item_status_id" INTEGER,
    "expiry_date" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "van_stocks_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "van_stock_audits" (
    "id" BIGSERIAL NOT NULL,
    "salesman_id" INTEGER,
    "route_id" INTEGER,
    "van_stock_audit_no" VARCHAR(50) NOT NULL,
    "audit_date_time" TIMESTAMPTZ NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ,

    CONSTRAINT "van_stock_audits_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "van_stock_audit_line_items" (
    "id" BIGSERIAL NOT NULL,
    "van_stock_audit_id" BIGINT NOT NULL,
    "item_id" INTEGER NOT NULL,
    "uom_id" INTEGER NOT NULL,
    "quantity" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "item_status_id" INTEGER NOT NULL,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ,

    CONSTRAINT "van_stock_audit_line_items_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "email_template_process" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "name" VARCHAR(100) NOT NULL,
    "slug" VARCHAR(100) NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "email_template_process_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "email_template_tags" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "slug" VARCHAR(100) NOT NULL,
    "name" VARCHAR(100),
    "description" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "email_template_tags_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "email_template_recipient_tags" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "slug" VARCHAR(100) NOT NULL,
    "name" VARCHAR(100),
    "description" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "email_template_recipient_tags_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "email_template_process_tags_mapping" (
    "email_template_process_id" INTEGER NOT NULL,
    "email_template_tag_id" INTEGER NOT NULL,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "email_template_process_tags_mapping_pkey" PRIMARY KEY ("email_template_process_id","email_template_tag_id","company_id")
);

-- CreateTable
CREATE TABLE "email_templates" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "slug" VARCHAR(100) NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "subject" VARCHAR(255) NOT NULL,
    "template_body" TEXT NOT NULL,
    "email_template_process_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "created_by" INTEGER NOT NULL,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "updated_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "deleted_by" INTEGER,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "email_templates_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "email_template_assignments" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "email_template_process_id" INTEGER NOT NULL,
    "template_id" INTEGER NOT NULL,
    "recipient_type" "RecipientType" NOT NULL DEFAULT 'tag',
    "email_to" VARCHAR(100),
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "created_by" INTEGER NOT NULL,

    CONSTRAINT "email_template_assignments_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "cash_receipts" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "document_no" VARCHAR(100) NOT NULL,
    "statement_id" INTEGER,
    "invoice_id" INTEGER,
    "invoice_no" VARCHAR(100),
    "transaction_at" TIMESTAMP(3) NOT NULL,
    "outlet_id" BIGINT NOT NULL,
    "salesman_id" INTEGER,
    "route_id" INTEGER,
    "total_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "received_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "wallet_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "transaction_type" "CashCollectionType",
    "payment_type" "CashCollectionPaymentType",
    "signature" TEXT,
    "currency_id" INTEGER,
    "cheque_number" VARCHAR(100),
    "cheque_date" TIMESTAMP(3),
    "is_current_dated_cheque" BOOLEAN NOT NULL DEFAULT false,
    "bank_name" VARCHAR(255),
    "branch_name" VARCHAR(255),
    "bank_id" INTEGER,
    "bank_branch_id" INTEGER,
    "cheque_image" VARCHAR(255),
    "web_service_log_id" BIGINT NOT NULL,
    "latitude" DECIMAL(18,10) NOT NULL DEFAULT 0.00000,
    "longitude" DECIMAL(18,10) NOT NULL DEFAULT 0.00000,
    "print_count" INTEGER NOT NULL DEFAULT 0,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,

    CONSTRAINT "cash_receipts_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "wallet_transactions" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "transaction_no" VARCHAR(100) NOT NULL,
    "description" TEXT,
    "statement_id" INTEGER,
    "invoice_id" INTEGER,
    "return_id" INTEGER,
    "invoice_no" VARCHAR(100),
    "transaction_at" TIMESTAMP(3) NOT NULL,
    "outlet_id" BIGINT NOT NULL,
    "salesman_id" INTEGER,
    "route_id" INTEGER,
    "total_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "wallet_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "payment_type" "WalletPaymentType",
    "transaction_type" "WalletTransactionType",
    "currency_id" INTEGER,
    "cheque_number" VARCHAR(100),
    "cheque_date" TIMESTAMP(3),
    "is_current_dated_cheque" BOOLEAN NOT NULL DEFAULT false,
    "bank_name" VARCHAR(255),
    "branch_name" VARCHAR(255),
    "bank_id" INTEGER,
    "bank_branch_id" INTEGER,
    "web_service_log_id" BIGINT,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,

    CONSTRAINT "wallet_transactions_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "statements" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "transaction_no" VARCHAR(100) NOT NULL,
    "description" TEXT,
    "outlet_id" BIGINT NOT NULL,
    "salesman_id" INTEGER,
    "route_id" INTEGER,
    "total_amount" DECIMAL(18,5) NOT NULL DEFAULT 0,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,

    CONSTRAINT "statements_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "import_templates" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "name" VARCHAR(100) NOT NULL,
    "slug" VARCHAR(100) NOT NULL,
    "description" VARCHAR(100),
    "primary_table" VARCHAR(100) NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,

    CONSTRAINT "import_templates_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "import_template_line_items" (
    "id" SERIAL NOT NULL,
    "import_template_id" INTEGER NOT NULL,
    "field_name" VARCHAR(255) NOT NULL,
    "display_name" VARCHAR(100) NOT NULL,
    "order_no" DECIMAL(4,2) NOT NULL DEFAULT 0,
    "width" INTEGER DEFAULT 0,
    "default_value" VARCHAR(100),
    "is_nullable" BOOLEAN NOT NULL DEFAULT true,
    "is_unique" BOOLEAN NOT NULL DEFAULT false,
    "is_foreign" BOOLEAN NOT NULL DEFAULT false,
    "is_enum" BOOLEAN NOT NULL DEFAULT false,
    "enum_values" VARCHAR(100),
    "foreign_table" VARCHAR(100),
    "foreign_column" VARCHAR(100),
    "foreign_create_data" JSONB,
    "foreign_can_create" BOOLEAN NOT NULL DEFAULT false,
    "field_type_id" INTEGER,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "import_template_line_items_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "statuses" (
    "id" SERIAL NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "slug" VARCHAR(100) NOT NULL,
    "description" TEXT,
    "status_id" INTEGER DEFAULT 1,

    CONSTRAINT "statuses_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "users_company_id_uuid_key" ON "users"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "users_company_id_email_role_key" ON "users"("company_id", "email", "role");

-- CreateIndex
CREATE UNIQUE INDEX "users_company_id_username_key" ON "users"("company_id", "username");

-- CreateIndex
CREATE UNIQUE INDEX "users_company_id_id_key" ON "users"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "user_details_company_id_user_id_key" ON "user_details"("company_id", "user_id");

-- CreateIndex
CREATE INDEX "request_logs_company_id_idx" ON "request_logs"("company_id");

-- CreateIndex
CREATE INDEX "permissions_company_id_order_no_idx" ON "permissions"("company_id", "order_no");

-- CreateIndex
CREATE UNIQUE INDEX "permissions_company_id_slug_key" ON "permissions"("company_id", "slug");

-- CreateIndex
CREATE UNIQUE INDEX "permissions_company_id_id_key" ON "permissions"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "roles_company_id_id_key" ON "roles"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "roles_company_id_uuid_key" ON "roles"("company_id", "uuid");

-- CreateIndex
CREATE INDEX "otps_company_id_user_id_purpose_idx" ON "otps"("company_id", "user_id", "purpose");

-- CreateIndex
CREATE UNIQUE INDEX "languages_company_id_id_key" ON "languages"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "languages_company_id_uuid_key" ON "languages"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "languages_company_id_code_key" ON "languages"("company_id", "code");

-- CreateIndex
CREATE UNIQUE INDEX "language_contents_company_id_id_key" ON "language_contents"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "designations_company_id_id_key" ON "designations"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "designations_company_id_uuid_key" ON "designations"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "departments_company_id_id_key" ON "departments"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "departments_company_id_uuid_key" ON "departments"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "vans_company_id_id_key" ON "vans"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "vans_company_id_uuid_key" ON "vans"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "menu_company_id_id_key" ON "menu"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "menu_company_id_uuid_key" ON "menu"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "menu_items_company_id_id_key" ON "menu_items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "taxes_company_id_id_key" ON "taxes"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "taxes_company_id_uuid_key" ON "taxes"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "suppliers_company_id_id_key" ON "suppliers"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "suppliers_company_id_uuid_key" ON "suppliers"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "brands_company_id_id_key" ON "brands"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "brands_company_id_uuid_key" ON "brands"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "brands_company_id_code_key" ON "brands"("company_id", "code");

-- CreateIndex
CREATE UNIQUE INDEX "banks_company_id_id_key" ON "banks"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "banks_company_id_uuid_key" ON "banks"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "bankbranches_company_id_id_key" ON "bankbranches"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "bankbranches_company_id_uuid_key" ON "bankbranches"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "price_types_company_id_PriceTypeID_key" ON "price_types"("company_id", "PriceTypeID");

-- CreateIndex
CREATE UNIQUE INDEX "price_types_company_id_uuid_key" ON "price_types"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "location_types_company_id_id_key" ON "location_types"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "location_types_company_id_uuid_key" ON "location_types"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "payment_terms_company_id_id_key" ON "payment_terms"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "payment_terms_company_id_uuid_key" ON "payment_terms"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "outlets_company_id_id_key" ON "outlets"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "outlets_company_id_uuid_key" ON "outlets"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "free_items_company_id_id_key" ON "free_items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "free_items_company_id_uuid_key" ON "free_items"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "outlet_targets_company_id_id_key" ON "outlet_targets"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "outlet_targets_company_id_uuid_key" ON "outlet_targets"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "currencies_company_id_id_key" ON "currencies"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "currencies_company_id_uuid_key" ON "currencies"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "categories_company_id_id_key" ON "categories"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "categories_company_id_uuid_key" ON "categories"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "categories_company_id_code_key" ON "categories"("company_id", "code");

-- CreateIndex
CREATE UNIQUE INDEX "items_company_id_id_key" ON "items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "items_company_id_uuid_key" ON "items"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "devices_company_id_id_key" ON "devices"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "devices_company_id_uuid_key" ON "devices"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "warehouses_company_id_id_key" ON "warehouses"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "warehouses_company_id_uuid_key" ON "warehouses"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "display_control_types_company_id_id_key" ON "display_control_types"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "display_control_types_company_id_uuid_key" ON "display_control_types"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "routes_company_id_id_key" ON "routes"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "routes_company_id_uuid_key" ON "routes"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "versions_company_id_id_key" ON "versions"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "versions_company_id_uuid_key" ON "versions"("company_id", "uuid");

-- CreateIndex
CREATE INDEX "route_outlet_mappings_outlet_id_idx" ON "route_outlet_mappings"("outlet_id");

-- CreateIndex
CREATE UNIQUE INDEX "alert_datas_company_id_id_key" ON "alert_datas"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "alert_datas_company_id_uuid_key" ON "alert_datas"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "outlet_persons_company_id_id_key" ON "outlet_persons"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "outlet_persons_company_id_uuid_key" ON "outlet_persons"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "item_uoms_company_id_id_key" ON "item_uoms"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "item_uoms_company_id_uuid_key" ON "item_uoms"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "outlet_classifications_company_id_id_key" ON "outlet_classifications"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "outlet_classifications_company_id_uuid_key" ON "outlet_classifications"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "reasons_company_id_id_key" ON "reasons"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "reasons_company_id_uuid_key" ON "reasons"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "discount_line_items_company_id_id_key" ON "discount_line_items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "discount_line_items_company_id_uuid_key" ON "discount_line_items"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "route_pattern_line_items_company_id_id_key" ON "route_pattern_line_items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "route_pattern_line_items_company_id_uuid_key" ON "route_pattern_line_items"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "uoms_company_id_id_key" ON "uoms"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "uoms_company_id_uuid_key" ON "uoms"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "outlet_zones_company_id_id_key" ON "outlet_zones"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "outlet_zones_company_id_uuid_key" ON "outlet_zones"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "team_line_items_company_id_id_key" ON "team_line_items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "team_line_items_company_id_uuid_key" ON "team_line_items"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "price_lists_company_id_id_key" ON "price_lists"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "price_lists_company_id_uuid_key" ON "price_lists"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "price_list_lineitems_price_list_id_id_key" ON "price_list_lineitems"("price_list_id", "id");

-- CreateIndex
CREATE INDEX "outlet_price_list_mapping_price_list_id_idx" ON "outlet_price_list_mapping"("price_list_id");

-- CreateIndex
CREATE UNIQUE INDEX "outlet_types_company_id_id_key" ON "outlet_types"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "outlet_types_company_id_uuid_key" ON "outlet_types"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "tax_line_items_company_id_id_key" ON "tax_line_items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "tax_line_items_company_id_uuid_key" ON "tax_line_items"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "outlet_scans_company_id_id_key" ON "outlet_scans"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "outlet_scans_company_id_uuid_key" ON "outlet_scans"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "outlet_credit_limits_company_id_id_key" ON "outlet_credit_limits"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "outlet_credit_limits_company_id_uuid_key" ON "outlet_credit_limits"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "discounts_company_id_id_key" ON "discounts"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "discounts_company_id_uuid_key" ON "discounts"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "route_patterns_company_id_id_key" ON "route_patterns"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "route_patterns_company_id_uuid_key" ON "route_patterns"("company_id", "uuid");

-- CreateIndex
CREATE INDEX "free_item_outlet_mappings_free_item_id_idx" ON "free_item_outlet_mappings"("free_item_id");

-- CreateIndex
CREATE UNIQUE INDEX "teams_company_id_id_key" ON "teams"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "teams_company_id_uuid_key" ON "teams"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "outlet_target_line_items_company_id_id_key" ON "outlet_target_line_items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "outlet_target_line_items_company_id_uuid_key" ON "outlet_target_line_items"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "outlet_groups_company_id_id_key" ON "outlet_groups"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "outlet_groups_company_id_uuid_key" ON "outlet_groups"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "item_statuses_company_id_id_key" ON "item_statuses"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "item_statuses_company_id_uuid_key" ON "item_statuses"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "outlet_categories_company_id_id_key" ON "outlet_categories"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "outlet_categories_company_id_uuid_key" ON "outlet_categories"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "salesman_item_mappings_company_id_id_key" ON "salesman_item_mappings"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "salesman_item_mappings_company_id_uuid_key" ON "salesman_item_mappings"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "route_outlet_sequences_company_id_id_key" ON "route_outlet_sequences"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "route_outlet_sequences_company_id_uuid_key" ON "route_outlet_sequences"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "alert_types_company_id_id_key" ON "alert_types"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "alert_types_company_id_uuid_key" ON "alert_types"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "user_grids_company_id_id_key" ON "user_grids"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "user_grids_company_id_uuid_key" ON "user_grids"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "master_transactions_company_id_id_key" ON "master_transactions"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "master_transactions_company_id_entity_name_key" ON "master_transactions"("company_id", "entity_name");

-- CreateIndex
CREATE UNIQUE INDEX "action_types_company_id_id_key" ON "action_types"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "entity_types_company_id_id_key" ON "entity_types"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "wizard_group_company_id_id_key" ON "wizard_group"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "wizard_group_company_id_slug_key" ON "wizard_group"("company_id", "slug");

-- CreateIndex
CREATE UNIQUE INDEX "wizard_types_company_id_id_key" ON "wizard_types"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "wizard_types_company_id_name_key" ON "wizard_types"("company_id", "name");

-- CreateIndex
CREATE UNIQUE INDEX "master_entities_company_id_id_key" ON "master_entities"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "master_entities_company_id_entity_name_key" ON "master_entities"("company_id", "entity_name");

-- CreateIndex
CREATE UNIQUE INDEX "master_entity_line_items_company_id_id_key" ON "master_entity_line_items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "master_entity_line_items_company_id_field_name_display_name_key" ON "master_entity_line_items"("company_id", "field_name", "display_name");

-- CreateIndex
CREATE UNIQUE INDEX "field_types_company_id_id_key" ON "field_types"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "invoice_request_line_items_company_id_id_key" ON "invoice_request_line_items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "invoice_request_line_items_company_id_uuid_key" ON "invoice_request_line_items"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "coordinator_approvals_company_id_id_key" ON "coordinator_approvals"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "coordinator_approvals_company_id_uuid_key" ON "coordinator_approvals"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "supervisor_approvals_company_id_id_key" ON "supervisor_approvals"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "approval_workflow_line_items_company_id_id_key" ON "approval_workflow_line_items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "approval_workflow_line_items_company_id_uuid_key" ON "approval_workflow_line_items"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "approval_workflows_company_id_id_key" ON "approval_workflows"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "approval_workflows_company_id_uuid_key" ON "approval_workflows"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "entity_constraints_company_id_id_key" ON "entity_constraints"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "entity_constraints_company_id_uuid_key" ON "entity_constraints"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "approver_constraints_company_id_id_key" ON "approver_constraints"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "approver_constraints_company_id_uuid_key" ON "approver_constraints"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "approval_modules_company_id_id_key" ON "approval_modules"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "damage_request_line_items_company_id_id_key" ON "damage_request_line_items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "damage_request_line_items_company_id_uuid_key" ON "damage_request_line_items"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "damage_requests_company_id_id_key" ON "damage_requests"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "damage_requests_company_id_uuid_key" ON "damage_requests"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "invoice_requests_company_id_id_key" ON "invoice_requests"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "invoice_requests_company_id_uuid_key" ON "invoice_requests"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "invoice_collections_company_id_id_key" ON "invoice_collections"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "invoice_collections_company_id_uuid_key" ON "invoice_collections"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "invoices_company_id_id_key" ON "invoices"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "invoices_company_id_uuid_key" ON "invoices"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "invoice_line_items_company_id_id_key" ON "invoice_line_items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "invoice_line_items_company_id_uuid_key" ON "invoice_line_items"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "credit_dues_company_id_id_key" ON "credit_dues"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "credit_dues_company_id_uuid_key" ON "credit_dues"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "journey_plans_company_id_id_key" ON "journey_plans"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "journey_plans_company_id_uuid_key" ON "journey_plans"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "upper_trade_logs_company_id_id_key" ON "upper_trade_logs"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "upper_trade_logs_company_id_uuid_key" ON "upper_trade_logs"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "reconciliation_line_items_company_id_id_key" ON "reconciliation_line_items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "reconciliation_line_items_company_id_uuid_key" ON "reconciliation_line_items"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "pre_order_line_items_company_id_id_key" ON "pre_order_line_items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "pre_order_line_items_company_id_uuid_key" ON "pre_order_line_items"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "reconciliations_company_id_id_key" ON "reconciliations"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "reconciliations_company_id_uuid_key" ON "reconciliations"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "pre_orders_company_id_id_key" ON "pre_orders"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "pre_orders_company_id_uuid_key" ON "pre_orders"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "salesman_targets_company_id_id_key" ON "salesman_targets"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "salesman_targets_company_id_uuid_key" ON "salesman_targets"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "salesman_trackings_company_id_id_key" ON "salesman_trackings"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "salesman_trackings_company_id_uuid_key" ON "salesman_trackings"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "van_unload_request_line_items_company_id_id_key" ON "van_unload_request_line_items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "van_unload_request_line_items_company_id_uuid_key" ON "van_unload_request_line_items"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "return_line_items_company_id_id_key" ON "return_line_items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "return_line_items_company_id_uuid_key" ON "return_line_items"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "salesman_target_line_items_company_id_id_key" ON "salesman_target_line_items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "salesman_target_line_items_company_id_uuid_key" ON "salesman_target_line_items"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "van_unload_requests_company_id_id_key" ON "van_unload_requests"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "van_unload_requests_company_id_uuid_key" ON "van_unload_requests"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "return_items_company_id_id_key" ON "return_items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "return_items_company_id_uuid_key" ON "return_items"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "financial_years_company_id_id_key" ON "financial_years"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "financial_years_company_id_uuid_key" ON "financial_years"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "configurations_company_id_id_key" ON "configurations"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "configurations_company_id_uuid_key" ON "configurations"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "audit_logs_company_id_id_key" ON "audit_logs"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "audit_log_line_items_company_id_id_key" ON "audit_log_line_items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "app_error_log_company_id_id_key" ON "app_error_log"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "process_status_company_id_id_key" ON "process_status"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "webservice_logs_company_id_id_key" ON "webservice_logs"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "application_modules_company_id_id_key" ON "application_modules"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "alert_notify_types_company_id_id_key" ON "alert_notify_types"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "document_sequences_company_id_id_key" ON "document_sequences"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "document_sequences_company_id_uuid_key" ON "document_sequences"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "user_configurations_company_id_id_key" ON "user_configurations"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "user_configurations_company_id_uuid_key" ON "user_configurations"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "user_types_company_id_id_key" ON "user_types"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "data_transfer_queries_company_id_id_key" ON "data_transfer_queries"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "warehouse_stocks_company_id_id_key" ON "warehouse_stocks"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "stock_adjustments_company_id_id_key" ON "stock_adjustments"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "stock_adjustment_line_items_company_id_id_key" ON "stock_adjustment_line_items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "daily_open_stocks_company_id_id_key" ON "daily_open_stocks"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "stock_transfer_requests_company_id_id_key" ON "stock_transfer_requests"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "stock_transfer_request_line_items_company_id_id_key" ON "stock_transfer_request_line_items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "outlet_stock_audit_headers_company_id_id_key" ON "outlet_stock_audit_headers"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "outlet_stock_audit_line_items_company_id_id_key" ON "outlet_stock_audit_line_items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "van_load_requests_company_id_id_key" ON "van_load_requests"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "van_load_request_line_items_company_id_id_key" ON "van_load_request_line_items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "van_load_approvals_company_id_id_key" ON "van_load_approvals"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "van_load_approval_line_items_company_id_id_key" ON "van_load_approval_line_items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "van_stocks_company_id_id_key" ON "van_stocks"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "van_stock_audits_company_id_id_key" ON "van_stock_audits"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "van_stock_audit_line_items_company_id_id_key" ON "van_stock_audit_line_items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "email_template_process_company_id_id_key" ON "email_template_process"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "email_template_process_company_id_slug_key" ON "email_template_process"("company_id", "slug");

-- CreateIndex
CREATE UNIQUE INDEX "email_template_process_id_company_id_key" ON "email_template_process"("id", "company_id");

-- CreateIndex
CREATE UNIQUE INDEX "email_template_tags_company_id_id_key" ON "email_template_tags"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "email_template_tags_company_id_slug_key" ON "email_template_tags"("company_id", "slug");

-- CreateIndex
CREATE UNIQUE INDEX "email_template_recipient_tags_company_id_id_key" ON "email_template_recipient_tags"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "email_template_recipient_tags_company_id_slug_key" ON "email_template_recipient_tags"("company_id", "slug");

-- CreateIndex
CREATE UNIQUE INDEX "email_templates_company_id_id_key" ON "email_templates"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "email_templates_company_id_slug_key" ON "email_templates"("company_id", "slug");

-- CreateIndex
CREATE UNIQUE INDEX "cash_receipts_company_id_id_key" ON "cash_receipts"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "cash_receipts_company_id_uuid_key" ON "cash_receipts"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "wallet_transactions_company_id_id_key" ON "wallet_transactions"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "wallet_transactions_company_id_uuid_key" ON "wallet_transactions"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "statements_company_id_id_key" ON "statements"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "statements_company_id_uuid_key" ON "statements"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "import_templates_company_id_id_key" ON "import_templates"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "import_templates_company_id_slug_key" ON "import_templates"("company_id", "slug");

-- CreateIndex
CREATE UNIQUE INDEX "import_template_line_items_company_id_id_key" ON "import_template_line_items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "import_template_line_items_company_id_field_name_display_na_key" ON "import_template_line_items"("company_id", "field_name", "display_name");

-- CreateIndex
CREATE UNIQUE INDEX "statuses_id_key" ON "statuses"("id");

-- CreateIndex
CREATE UNIQUE INDEX "statuses_slug_key" ON "statuses"("slug");

-- AddForeignKey
ALTER TABLE "users" ADD CONSTRAINT "users_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "users" ADD CONSTRAINT "users_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "users" ADD CONSTRAINT "users_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "users" ADD CONSTRAINT "users_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_details" ADD CONSTRAINT "user_details_company_id_user_id_fkey" FOREIGN KEY ("company_id", "user_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_details" ADD CONSTRAINT "user_details_company_id_designation_id_fkey" FOREIGN KEY ("company_id", "designation_id") REFERENCES "designations"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_details" ADD CONSTRAINT "user_details_company_id_department_id_fkey" FOREIGN KEY ("company_id", "department_id") REFERENCES "departments"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_details" ADD CONSTRAINT "user_details_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_details" ADD CONSTRAINT "user_details_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_details" ADD CONSTRAINT "user_details_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "request_logs" ADD CONSTRAINT "request_logs_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "request_logs" ADD CONSTRAINT "request_logs_company_id_user_id_fkey" FOREIGN KEY ("company_id", "user_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "permissions" ADD CONSTRAINT "permissions_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "permissions" ADD CONSTRAINT "permissions_company_id_entity_id_fkey" FOREIGN KEY ("company_id", "entity_id") REFERENCES "master_entities"("company_id", "id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "roles" ADD CONSTRAINT "roles_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "roles" ADD CONSTRAINT "roles_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "roles" ADD CONSTRAINT "roles_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "roles" ADD CONSTRAINT "roles_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "role_permissions" ADD CONSTRAINT "role_permissions_company_id_role_id_fkey" FOREIGN KEY ("company_id", "role_id") REFERENCES "roles"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "role_permissions" ADD CONSTRAINT "role_permissions_company_id_permission_id_fkey" FOREIGN KEY ("company_id", "permission_id") REFERENCES "permissions"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_roles" ADD CONSTRAINT "user_roles_company_id_user_id_fkey" FOREIGN KEY ("company_id", "user_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_roles" ADD CONSTRAINT "user_roles_company_id_role_id_fkey" FOREIGN KEY ("company_id", "role_id") REFERENCES "roles"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_permissions" ADD CONSTRAINT "user_permissions_company_id_user_id_fkey" FOREIGN KEY ("company_id", "user_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_permissions" ADD CONSTRAINT "user_permissions_company_id_permission_id_fkey" FOREIGN KEY ("company_id", "permission_id") REFERENCES "permissions"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "otps" ADD CONSTRAINT "otps_company_id_user_id_fkey" FOREIGN KEY ("company_id", "user_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "languages" ADD CONSTRAINT "languages_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "languages" ADD CONSTRAINT "languages_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "languages" ADD CONSTRAINT "languages_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "languages" ADD CONSTRAINT "languages_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "language_contents" ADD CONSTRAINT "language_contents_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "language_contents" ADD CONSTRAINT "language_contents_company_id_language_id_fkey" FOREIGN KEY ("company_id", "language_id") REFERENCES "languages"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "designations" ADD CONSTRAINT "designations_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "designations" ADD CONSTRAINT "designations_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "designations" ADD CONSTRAINT "designations_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "designations" ADD CONSTRAINT "designations_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "departments" ADD CONSTRAINT "departments_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "departments" ADD CONSTRAINT "departments_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "departments" ADD CONSTRAINT "departments_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "departments" ADD CONSTRAINT "departments_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "vans" ADD CONSTRAINT "vans_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "vans" ADD CONSTRAINT "vans_company_id_department_id_fkey" FOREIGN KEY ("company_id", "department_id") REFERENCES "departments"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "vans" ADD CONSTRAINT "vans_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "vans" ADD CONSTRAINT "vans_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "vans" ADD CONSTRAINT "vans_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "menu" ADD CONSTRAINT "menu_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "menu" ADD CONSTRAINT "menu_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "menu" ADD CONSTRAINT "menu_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "menu" ADD CONSTRAINT "menu_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "menu_items" ADD CONSTRAINT "menu_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "menu_items" ADD CONSTRAINT "menu_items_company_id_menu_id_fkey" FOREIGN KEY ("company_id", "menu_id") REFERENCES "menu"("company_id", "id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "menu_items" ADD CONSTRAINT "menu_items_company_id_entity_id_fkey" FOREIGN KEY ("company_id", "entity_id") REFERENCES "master_entities"("company_id", "id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "menu_items" ADD CONSTRAINT "menu_items_company_id_permission_id_fkey" FOREIGN KEY ("company_id", "permission_id") REFERENCES "permissions"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "menu_items" ADD CONSTRAINT "menu_items_company_id_parent_id_fkey" FOREIGN KEY ("company_id", "parent_id") REFERENCES "menu_items"("company_id", "id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "menu_items" ADD CONSTRAINT "menu_items_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "menu_items" ADD CONSTRAINT "menu_items_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "menu_items" ADD CONSTRAINT "menu_items_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "taxes" ADD CONSTRAINT "taxes_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "taxes" ADD CONSTRAINT "taxes_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "taxes" ADD CONSTRAINT "taxes_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "taxes" ADD CONSTRAINT "taxes_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "suppliers" ADD CONSTRAINT "suppliers_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "suppliers" ADD CONSTRAINT "suppliers_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "suppliers" ADD CONSTRAINT "suppliers_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "suppliers" ADD CONSTRAINT "suppliers_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "brands" ADD CONSTRAINT "brands_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "brands" ADD CONSTRAINT "brands_supplier_id_fkey" FOREIGN KEY ("supplier_id") REFERENCES "suppliers"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "brands" ADD CONSTRAINT "brands_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "brands" ADD CONSTRAINT "brands_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "brands" ADD CONSTRAINT "brands_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "banks" ADD CONSTRAINT "banks_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "banks" ADD CONSTRAINT "banks_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "banks" ADD CONSTRAINT "banks_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "banks" ADD CONSTRAINT "banks_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "bankbranches" ADD CONSTRAINT "bankbranches_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "bankbranches" ADD CONSTRAINT "bankbranches_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "bankbranches" ADD CONSTRAINT "bankbranches_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "bankbranches" ADD CONSTRAINT "bankbranches_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "bankbranches" ADD CONSTRAINT "bankbranches_company_id_bank_id_fkey" FOREIGN KEY ("company_id", "bank_id") REFERENCES "banks"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "bankbranches" ADD CONSTRAINT "bankbranches_company_id_outlet_target_id_fkey" FOREIGN KEY ("company_id", "outlet_target_id") REFERENCES "outlet_targets"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "price_types" ADD CONSTRAINT "price_types_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "price_types" ADD CONSTRAINT "price_types_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "price_types" ADD CONSTRAINT "price_types_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "price_types" ADD CONSTRAINT "price_types_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "location_types" ADD CONSTRAINT "location_types_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "location_types" ADD CONSTRAINT "location_types_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "location_types" ADD CONSTRAINT "location_types_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "location_types" ADD CONSTRAINT "location_types_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "payment_terms" ADD CONSTRAINT "payment_terms_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "payment_terms" ADD CONSTRAINT "payment_terms_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "payment_terms" ADD CONSTRAINT "payment_terms_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "payment_terms" ADD CONSTRAINT "payment_terms_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "payment_terms" ADD CONSTRAINT "payment_terms_company_id_outlet_id_fkey" FOREIGN KEY ("company_id", "outlet_id") REFERENCES "outlets"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlets" ADD CONSTRAINT "outlets_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlets" ADD CONSTRAINT "outlets_company_id_parent_id_fkey" FOREIGN KEY ("company_id", "parent_id") REFERENCES "outlets"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlets" ADD CONSTRAINT "outlets_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlets" ADD CONSTRAINT "outlets_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlets" ADD CONSTRAINT "outlets_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlets" ADD CONSTRAINT "outlets_company_id_department_id_fkey" FOREIGN KEY ("company_id", "department_id") REFERENCES "departments"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlets" ADD CONSTRAINT "outlets_company_id_currency_id_fkey" FOREIGN KEY ("company_id", "currency_id") REFERENCES "currencies"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlets" ADD CONSTRAINT "outlets_company_id_outlet_category_id_fkey" FOREIGN KEY ("company_id", "outlet_category_id") REFERENCES "outlet_categories"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlets" ADD CONSTRAINT "outlets_company_id_outlet_zone_id_fkey" FOREIGN KEY ("company_id", "outlet_zone_id") REFERENCES "outlet_zones"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlets" ADD CONSTRAINT "outlets_company_id_outlet_type_id_fkey" FOREIGN KEY ("company_id", "outlet_type_id") REFERENCES "outlet_types"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlets" ADD CONSTRAINT "outlets_company_id_outlet_classification_id_fkey" FOREIGN KEY ("company_id", "outlet_classification_id") REFERENCES "outlet_classifications"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlets" ADD CONSTRAINT "outlets_company_id_outlet_group_id_fkey" FOREIGN KEY ("company_id", "outlet_group_id") REFERENCES "outlet_groups"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "free_items" ADD CONSTRAINT "free_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "free_items" ADD CONSTRAINT "free_items_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "free_items" ADD CONSTRAINT "free_items_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "free_items" ADD CONSTRAINT "free_items_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "free_items" ADD CONSTRAINT "free_items_company_id_item_id_fkey" FOREIGN KEY ("company_id", "item_id") REFERENCES "items"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "free_items" ADD CONSTRAINT "free_items_company_id_uom_id_fkey" FOREIGN KEY ("company_id", "uom_id") REFERENCES "uoms"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "free_items" ADD CONSTRAINT "free_items_company_id_item_status_id_fkey" FOREIGN KEY ("company_id", "item_status_id") REFERENCES "item_statuses"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_targets" ADD CONSTRAINT "outlet_targets_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_targets" ADD CONSTRAINT "outlet_targets_company_id_outlet_id_fkey" FOREIGN KEY ("company_id", "outlet_id") REFERENCES "outlets"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_targets" ADD CONSTRAINT "outlet_targets_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_targets" ADD CONSTRAINT "outlet_targets_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_targets" ADD CONSTRAINT "outlet_targets_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "currencies" ADD CONSTRAINT "currencies_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "currencies" ADD CONSTRAINT "currencies_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "currencies" ADD CONSTRAINT "currencies_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "currencies" ADD CONSTRAINT "currencies_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "categories" ADD CONSTRAINT "categories_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "categories" ADD CONSTRAINT "categories_company_id_parent_id_fkey" FOREIGN KEY ("company_id", "parent_id") REFERENCES "categories"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "categories" ADD CONSTRAINT "categories_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "categories" ADD CONSTRAINT "categories_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "categories" ADD CONSTRAINT "categories_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "items" ADD CONSTRAINT "items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "items" ADD CONSTRAINT "items_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "items" ADD CONSTRAINT "items_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "items" ADD CONSTRAINT "items_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "items" ADD CONSTRAINT "items_company_id_volumetric_uom_id_fkey" FOREIGN KEY ("company_id", "volumetric_uom_id") REFERENCES "uoms"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "items" ADD CONSTRAINT "items_company_id_category_id_fkey" FOREIGN KEY ("company_id", "category_id") REFERENCES "categories"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "items" ADD CONSTRAINT "items_company_id_brand_id_fkey" FOREIGN KEY ("company_id", "brand_id") REFERENCES "brands"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "items" ADD CONSTRAINT "items_company_id_warehouse_id_fkey" FOREIGN KEY ("company_id", "warehouse_id") REFERENCES "warehouses"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "items" ADD CONSTRAINT "items_company_id_department_id_fkey" FOREIGN KEY ("company_id", "department_id") REFERENCES "departments"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "items" ADD CONSTRAINT "items_company_id_supplier_id_fkey" FOREIGN KEY ("company_id", "supplier_id") REFERENCES "suppliers"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "devices" ADD CONSTRAINT "devices_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "devices" ADD CONSTRAINT "devices_company_id_salesman_id_fkey" FOREIGN KEY ("company_id", "salesman_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "devices" ADD CONSTRAINT "devices_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "devices" ADD CONSTRAINT "devices_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "devices" ADD CONSTRAINT "devices_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "devices" ADD CONSTRAINT "devices_company_id_route_id_fkey" FOREIGN KEY ("company_id", "route_id") REFERENCES "routes"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "salesman_outlet_mappings" ADD CONSTRAINT "salesman_outlet_mappings_company_id_salesman_id_fkey" FOREIGN KEY ("company_id", "salesman_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "salesman_outlet_mappings" ADD CONSTRAINT "salesman_outlet_mappings_company_id_outlet_id_fkey" FOREIGN KEY ("company_id", "outlet_id") REFERENCES "outlets"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "warehouses" ADD CONSTRAINT "warehouses_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "warehouses" ADD CONSTRAINT "warehouses_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "warehouses" ADD CONSTRAINT "warehouses_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "warehouses" ADD CONSTRAINT "warehouses_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "display_control_types" ADD CONSTRAINT "display_control_types_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "display_control_types" ADD CONSTRAINT "display_control_types_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "display_control_types" ADD CONSTRAINT "display_control_types_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "display_control_types" ADD CONSTRAINT "display_control_types_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "routes" ADD CONSTRAINT "routes_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "routes" ADD CONSTRAINT "routes_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "routes" ADD CONSTRAINT "routes_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "routes" ADD CONSTRAINT "routes_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "versions" ADD CONSTRAINT "versions_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "versions" ADD CONSTRAINT "versions_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "versions" ADD CONSTRAINT "versions_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "versions" ADD CONSTRAINT "versions_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "route_outlet_mappings" ADD CONSTRAINT "route_outlet_mappings_company_id_route_id_fkey" FOREIGN KEY ("company_id", "route_id") REFERENCES "routes"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "route_outlet_mappings" ADD CONSTRAINT "route_outlet_mappings_company_id_outlet_id_fkey" FOREIGN KEY ("company_id", "outlet_id") REFERENCES "outlets"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "alert_datas" ADD CONSTRAINT "alert_datas_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "alert_datas" ADD CONSTRAINT "alert_datas_company_id_user_id_fkey" FOREIGN KEY ("company_id", "user_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "alert_datas" ADD CONSTRAINT "alert_datas_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "alert_datas" ADD CONSTRAINT "alert_datas_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "alert_datas" ADD CONSTRAINT "alert_datas_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "alert_datas" ADD CONSTRAINT "alert_datas_company_id_alert_notification_type_id_fkey" FOREIGN KEY ("company_id", "alert_notification_type_id") REFERENCES "alert_notify_types"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "alert_datas" ADD CONSTRAINT "alert_datas_company_id_alert_type_id_fkey" FOREIGN KEY ("company_id", "alert_type_id") REFERENCES "alert_types"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "alert_datas" ADD CONSTRAINT "alert_datas_company_id_department_id_fkey" FOREIGN KEY ("company_id", "department_id") REFERENCES "departments"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_persons" ADD CONSTRAINT "outlet_persons_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_persons" ADD CONSTRAINT "outlet_persons_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_persons" ADD CONSTRAINT "outlet_persons_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_persons" ADD CONSTRAINT "outlet_persons_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_persons" ADD CONSTRAINT "outlet_persons_company_id_outlet_id_fkey" FOREIGN KEY ("company_id", "outlet_id") REFERENCES "outlets"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "item_uoms" ADD CONSTRAINT "item_uoms_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "item_uoms" ADD CONSTRAINT "item_uoms_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "item_uoms" ADD CONSTRAINT "item_uoms_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "item_uoms" ADD CONSTRAINT "item_uoms_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "item_uoms" ADD CONSTRAINT "item_uoms_company_id_uom_id_fkey" FOREIGN KEY ("company_id", "uom_id") REFERENCES "uoms"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "item_uoms" ADD CONSTRAINT "item_uoms_company_id_item_id_fkey" FOREIGN KEY ("company_id", "item_id") REFERENCES "items"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_classifications" ADD CONSTRAINT "outlet_classifications_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_classifications" ADD CONSTRAINT "outlet_classifications_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_classifications" ADD CONSTRAINT "outlet_classifications_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_classifications" ADD CONSTRAINT "outlet_classifications_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "reasons" ADD CONSTRAINT "reasons_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "reasons" ADD CONSTRAINT "reasons_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "reasons" ADD CONSTRAINT "reasons_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "reasons" ADD CONSTRAINT "reasons_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "discount_line_items" ADD CONSTRAINT "discount_line_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "discount_line_items" ADD CONSTRAINT "discount_line_items_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "discount_line_items" ADD CONSTRAINT "discount_line_items_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "discount_line_items" ADD CONSTRAINT "discount_line_items_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "discount_line_items" ADD CONSTRAINT "discount_line_items_company_id_discount_id_fkey" FOREIGN KEY ("company_id", "discount_id") REFERENCES "discounts"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "discount_line_items" ADD CONSTRAINT "discount_line_items_company_id_item_id_fkey" FOREIGN KEY ("company_id", "item_id") REFERENCES "items"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "discount_line_items" ADD CONSTRAINT "discount_line_items_company_id_uom_id_fkey" FOREIGN KEY ("company_id", "uom_id") REFERENCES "uoms"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "discount_line_items" ADD CONSTRAINT "discount_line_items_company_id_outlet_id_fkey" FOREIGN KEY ("company_id", "outlet_id") REFERENCES "outlets"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "discount_line_items" ADD CONSTRAINT "discount_line_items_company_id_outlet_group_id_fkey" FOREIGN KEY ("company_id", "outlet_group_id") REFERENCES "outlet_groups"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "discount_line_items" ADD CONSTRAINT "discount_line_items_company_id_outlet_category_id_fkey" FOREIGN KEY ("company_id", "outlet_category_id") REFERENCES "outlet_categories"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "route_pattern_line_items" ADD CONSTRAINT "route_pattern_line_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "route_pattern_line_items" ADD CONSTRAINT "route_pattern_line_items_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "route_pattern_line_items" ADD CONSTRAINT "route_pattern_line_items_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "route_pattern_line_items" ADD CONSTRAINT "route_pattern_line_items_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "route_pattern_line_items" ADD CONSTRAINT "route_pattern_line_items_company_id_route_pattern_id_fkey" FOREIGN KEY ("company_id", "route_pattern_id") REFERENCES "route_patterns"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "route_pattern_line_items" ADD CONSTRAINT "route_pattern_line_items_company_id_route_id_fkey" FOREIGN KEY ("company_id", "route_id") REFERENCES "routes"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "uoms" ADD CONSTRAINT "uoms_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "uoms" ADD CONSTRAINT "uoms_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "uoms" ADD CONSTRAINT "uoms_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "uoms" ADD CONSTRAINT "uoms_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_zones" ADD CONSTRAINT "outlet_zones_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_zones" ADD CONSTRAINT "outlet_zones_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_zones" ADD CONSTRAINT "outlet_zones_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_zones" ADD CONSTRAINT "outlet_zones_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "team_line_items" ADD CONSTRAINT "team_line_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "team_line_items" ADD CONSTRAINT "team_line_items_company_id_salesman_id_fkey" FOREIGN KEY ("company_id", "salesman_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "team_line_items" ADD CONSTRAINT "team_line_items_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "team_line_items" ADD CONSTRAINT "team_line_items_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "team_line_items" ADD CONSTRAINT "team_line_items_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "team_line_items" ADD CONSTRAINT "team_line_items_company_id_team_id_fkey" FOREIGN KEY ("company_id", "team_id") REFERENCES "teams"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "team_line_items" ADD CONSTRAINT "team_line_items_company_id_route_id_fkey" FOREIGN KEY ("company_id", "route_id") REFERENCES "routes"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "price_lists" ADD CONSTRAINT "price_lists_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "price_lists" ADD CONSTRAINT "price_lists_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "price_lists" ADD CONSTRAINT "price_lists_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "price_lists" ADD CONSTRAINT "price_lists_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "price_lists" ADD CONSTRAINT "price_lists_company_id_item_status_id_fkey" FOREIGN KEY ("company_id", "item_status_id") REFERENCES "item_statuses"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "price_list_lineitems" ADD CONSTRAINT "price_list_lineitems_company_id_price_list_id_fkey" FOREIGN KEY ("company_id", "price_list_id") REFERENCES "price_lists"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "price_list_lineitems" ADD CONSTRAINT "price_list_lineitems_company_id_item_id_fkey" FOREIGN KEY ("company_id", "item_id") REFERENCES "items"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "price_list_lineitems" ADD CONSTRAINT "price_list_lineitems_company_id_uom_id_fkey" FOREIGN KEY ("company_id", "uom_id") REFERENCES "uoms"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_price_list_mapping" ADD CONSTRAINT "outlet_price_list_mapping_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_price_list_mapping" ADD CONSTRAINT "outlet_price_list_mapping_company_id_price_list_id_fkey" FOREIGN KEY ("company_id", "price_list_id") REFERENCES "price_lists"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_price_list_mapping" ADD CONSTRAINT "outlet_price_list_mapping_company_id_outlet_id_fkey" FOREIGN KEY ("company_id", "outlet_id") REFERENCES "outlets"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_price_list_mapping" ADD CONSTRAINT "outlet_price_list_mapping_company_id_item_status_id_fkey" FOREIGN KEY ("company_id", "item_status_id") REFERENCES "item_statuses"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_types" ADD CONSTRAINT "outlet_types_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_types" ADD CONSTRAINT "outlet_types_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_types" ADD CONSTRAINT "outlet_types_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_types" ADD CONSTRAINT "outlet_types_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "tax_line_items" ADD CONSTRAINT "tax_line_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "tax_line_items" ADD CONSTRAINT "tax_line_items_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "tax_line_items" ADD CONSTRAINT "tax_line_items_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "tax_line_items" ADD CONSTRAINT "tax_line_items_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "tax_line_items" ADD CONSTRAINT "tax_line_items_company_id_tax_id_fkey" FOREIGN KEY ("company_id", "tax_id") REFERENCES "taxes"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "tax_line_items" ADD CONSTRAINT "tax_line_items_company_id_item_id_fkey" FOREIGN KEY ("company_id", "item_id") REFERENCES "items"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "tax_line_items" ADD CONSTRAINT "tax_line_items_company_id_item_category_id_fkey" FOREIGN KEY ("company_id", "item_category_id") REFERENCES "categories"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_scans" ADD CONSTRAINT "outlet_scans_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_scans" ADD CONSTRAINT "outlet_scans_company_id_salesman_id_fkey" FOREIGN KEY ("company_id", "salesman_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_scans" ADD CONSTRAINT "outlet_scans_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_scans" ADD CONSTRAINT "outlet_scans_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_scans" ADD CONSTRAINT "outlet_scans_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_scans" ADD CONSTRAINT "outlet_scans_company_id_journey_plan_id_fkey" FOREIGN KEY ("company_id", "journey_plan_id") REFERENCES "journey_plans"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_scans" ADD CONSTRAINT "outlet_scans_company_id_in_reason_id_fkey" FOREIGN KEY ("company_id", "in_reason_id") REFERENCES "reasons"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_scans" ADD CONSTRAINT "outlet_scans_company_id_out_reason_id_fkey" FOREIGN KEY ("company_id", "out_reason_id") REFERENCES "reasons"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_scans" ADD CONSTRAINT "outlet_scans_company_id_web_service_log_id_fkey" FOREIGN KEY ("company_id", "web_service_log_id") REFERENCES "webservice_logs"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_scans" ADD CONSTRAINT "outlet_scans_company_id_outlet_id_fkey" FOREIGN KEY ("company_id", "outlet_id") REFERENCES "outlets"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_credit_limits" ADD CONSTRAINT "outlet_credit_limits_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_credit_limits" ADD CONSTRAINT "outlet_credit_limits_company_id_salesman_id_fkey" FOREIGN KEY ("company_id", "salesman_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_credit_limits" ADD CONSTRAINT "outlet_credit_limits_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_credit_limits" ADD CONSTRAINT "outlet_credit_limits_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_credit_limits" ADD CONSTRAINT "outlet_credit_limits_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_credit_limits" ADD CONSTRAINT "outlet_credit_limits_company_id_outlet_id_fkey" FOREIGN KEY ("company_id", "outlet_id") REFERENCES "outlets"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_credit_limits" ADD CONSTRAINT "outlet_credit_limits_company_id_outlet_group_id_fkey" FOREIGN KEY ("company_id", "outlet_group_id") REFERENCES "outlet_groups"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "discounts" ADD CONSTRAINT "discounts_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "discounts" ADD CONSTRAINT "discounts_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "discounts" ADD CONSTRAINT "discounts_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "discounts" ADD CONSTRAINT "discounts_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "route_patterns" ADD CONSTRAINT "route_patterns_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "route_patterns" ADD CONSTRAINT "route_patterns_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "route_patterns" ADD CONSTRAINT "route_patterns_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "route_patterns" ADD CONSTRAINT "route_patterns_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "free_item_outlet_mappings" ADD CONSTRAINT "free_item_outlet_mappings_company_id_free_item_id_fkey" FOREIGN KEY ("company_id", "free_item_id") REFERENCES "free_items"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "free_item_outlet_mappings" ADD CONSTRAINT "free_item_outlet_mappings_company_id_outlet_id_fkey" FOREIGN KEY ("company_id", "outlet_id") REFERENCES "outlets"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "teams" ADD CONSTRAINT "teams_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "teams" ADD CONSTRAINT "teams_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "teams" ADD CONSTRAINT "teams_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "teams" ADD CONSTRAINT "teams_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "teams" ADD CONSTRAINT "teams_company_id_supervisor_id_fkey" FOREIGN KEY ("company_id", "supervisor_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_target_line_items" ADD CONSTRAINT "outlet_target_line_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_target_line_items" ADD CONSTRAINT "outlet_target_line_items_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_target_line_items" ADD CONSTRAINT "outlet_target_line_items_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_target_line_items" ADD CONSTRAINT "outlet_target_line_items_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_target_line_items" ADD CONSTRAINT "outlet_target_line_items_company_id_outlet_target_id_fkey" FOREIGN KEY ("company_id", "outlet_target_id") REFERENCES "outlet_targets"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_target_line_items" ADD CONSTRAINT "outlet_target_line_items_company_id_item_id_fkey" FOREIGN KEY ("company_id", "item_id") REFERENCES "items"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_groups" ADD CONSTRAINT "outlet_groups_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_groups" ADD CONSTRAINT "outlet_groups_company_id_parent_id_fkey" FOREIGN KEY ("company_id", "parent_id") REFERENCES "outlet_groups"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_groups" ADD CONSTRAINT "outlet_groups_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_groups" ADD CONSTRAINT "outlet_groups_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_groups" ADD CONSTRAINT "outlet_groups_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "item_statuses" ADD CONSTRAINT "item_statuses_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "item_statuses" ADD CONSTRAINT "item_statuses_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "item_statuses" ADD CONSTRAINT "item_statuses_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "item_statuses" ADD CONSTRAINT "item_statuses_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_categories" ADD CONSTRAINT "outlet_categories_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_categories" ADD CONSTRAINT "outlet_categories_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_categories" ADD CONSTRAINT "outlet_categories_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_categories" ADD CONSTRAINT "outlet_categories_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "salesman_item_mappings" ADD CONSTRAINT "salesman_item_mappings_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "salesman_item_mappings" ADD CONSTRAINT "salesman_item_mappings_company_id_route_id_fkey" FOREIGN KEY ("company_id", "route_id") REFERENCES "routes"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "salesman_item_mappings" ADD CONSTRAINT "salesman_item_mappings_company_id_salesman_id_fkey" FOREIGN KEY ("company_id", "salesman_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "salesman_item_mappings" ADD CONSTRAINT "salesman_item_mappings_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "salesman_item_mappings" ADD CONSTRAINT "salesman_item_mappings_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "salesman_item_mappings" ADD CONSTRAINT "salesman_item_mappings_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "salesman_item_mappings" ADD CONSTRAINT "salesman_item_mappings_company_id_item_id_fkey" FOREIGN KEY ("company_id", "item_id") REFERENCES "items"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "salesman_item_mappings" ADD CONSTRAINT "salesman_item_mappings_company_id_item_category_id_fkey" FOREIGN KEY ("company_id", "item_category_id") REFERENCES "categories"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "route_outlet_sequences" ADD CONSTRAINT "route_outlet_sequences_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "route_outlet_sequences" ADD CONSTRAINT "route_outlet_sequences_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "route_outlet_sequences" ADD CONSTRAINT "route_outlet_sequences_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "route_outlet_sequences" ADD CONSTRAINT "route_outlet_sequences_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "route_outlet_sequences" ADD CONSTRAINT "route_outlet_sequences_company_id_route_id_fkey" FOREIGN KEY ("company_id", "route_id") REFERENCES "routes"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "route_outlet_sequences" ADD CONSTRAINT "route_outlet_sequences_company_id_outlet_id_fkey" FOREIGN KEY ("company_id", "outlet_id") REFERENCES "outlets"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "alert_types" ADD CONSTRAINT "alert_types_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "alert_types" ADD CONSTRAINT "alert_types_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "alert_types" ADD CONSTRAINT "alert_types_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "alert_types" ADD CONSTRAINT "alert_types_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_grids" ADD CONSTRAINT "user_grids_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_grids" ADD CONSTRAINT "user_grids_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_grids" ADD CONSTRAINT "user_grids_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_grids" ADD CONSTRAINT "user_grids_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_grids" ADD CONSTRAINT "user_grids_company_id_user_id_fkey" FOREIGN KEY ("company_id", "user_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_grids" ADD CONSTRAINT "user_grids_company_id_target_index_id_fkey" FOREIGN KEY ("company_id", "target_index_id") REFERENCES "master_entities"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_grids" ADD CONSTRAINT "user_grids_company_id_target_index_line_item_id_fkey" FOREIGN KEY ("company_id", "target_index_line_item_id") REFERENCES "master_entity_line_items"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "master_transactions" ADD CONSTRAINT "master_transactions_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "master_entities" ADD CONSTRAINT "master_entities_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "master_entity_line_items" ADD CONSTRAINT "master_entity_line_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "master_entity_line_items" ADD CONSTRAINT "master_entity_line_items_company_id_master_grid_id_fkey" FOREIGN KEY ("company_id", "master_grid_id") REFERENCES "master_entities"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "master_entity_line_items" ADD CONSTRAINT "master_entity_line_items_company_id_field_type_id_fkey" FOREIGN KEY ("company_id", "field_type_id") REFERENCES "field_types"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "field_types" ADD CONSTRAINT "field_types_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_request_line_items" ADD CONSTRAINT "invoice_request_line_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_request_line_items" ADD CONSTRAINT "invoice_request_line_items_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_request_line_items" ADD CONSTRAINT "invoice_request_line_items_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_request_line_items" ADD CONSTRAINT "invoice_request_line_items_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_request_line_items" ADD CONSTRAINT "invoice_request_line_items_company_id_invoice_request_id_fkey" FOREIGN KEY ("company_id", "invoice_request_id") REFERENCES "invoice_requests"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_request_line_items" ADD CONSTRAINT "invoice_request_line_items_company_id_item_id_fkey" FOREIGN KEY ("company_id", "item_id") REFERENCES "items"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_request_line_items" ADD CONSTRAINT "invoice_request_line_items_company_id_uom_id_fkey" FOREIGN KEY ("company_id", "uom_id") REFERENCES "uoms"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_request_line_items" ADD CONSTRAINT "invoice_request_line_items_company_id_item_status_id_fkey" FOREIGN KEY ("company_id", "item_status_id") REFERENCES "item_statuses"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "coordinator_approvals" ADD CONSTRAINT "coordinator_approvals_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "coordinator_approvals" ADD CONSTRAINT "coordinator_approvals_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "coordinator_approvals" ADD CONSTRAINT "coordinator_approvals_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "coordinator_approvals" ADD CONSTRAINT "coordinator_approvals_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "coordinator_approvals" ADD CONSTRAINT "coordinator_approvals_company_id_supervisor_id_fkey" FOREIGN KEY ("company_id", "supervisor_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "coordinator_approvals" ADD CONSTRAINT "coordinator_approvals_company_id_supervisor_approval_id_fkey" FOREIGN KEY ("company_id", "supervisor_approval_id") REFERENCES "supervisor_approvals"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "coordinator_approvals" ADD CONSTRAINT "coordinator_approvals_company_id_item_id_fkey" FOREIGN KEY ("company_id", "item_id") REFERENCES "items"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "coordinator_approvals" ADD CONSTRAINT "coordinator_approvals_company_id_uom_id_fkey" FOREIGN KEY ("company_id", "uom_id") REFERENCES "uoms"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "supervisor_approvals" ADD CONSTRAINT "supervisor_approvals_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "supervisor_approvals" ADD CONSTRAINT "supervisor_approvals_company_id_van_load_request_id_fkey" FOREIGN KEY ("company_id", "van_load_request_id") REFERENCES "van_load_requests"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "supervisor_approvals" ADD CONSTRAINT "supervisor_approvals_company_id_supervisor_id_fkey" FOREIGN KEY ("company_id", "supervisor_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "supervisor_approvals" ADD CONSTRAINT "supervisor_approvals_company_id_approved_by_fkey" FOREIGN KEY ("company_id", "approved_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "supervisor_approvals" ADD CONSTRAINT "supervisor_approvals_company_id_item_id_fkey" FOREIGN KEY ("company_id", "item_id") REFERENCES "items"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "supervisor_approvals" ADD CONSTRAINT "supervisor_approvals_company_id_uom_id_fkey" FOREIGN KEY ("company_id", "uom_id") REFERENCES "uoms"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "approval_workflow_line_items" ADD CONSTRAINT "approval_workflow_line_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "approval_workflow_line_items" ADD CONSTRAINT "approval_workflow_line_items_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "approval_workflow_line_items" ADD CONSTRAINT "approval_workflow_line_items_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "approval_workflow_line_items" ADD CONSTRAINT "approval_workflow_line_items_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "approval_workflows" ADD CONSTRAINT "approval_workflows_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "approval_workflows" ADD CONSTRAINT "approval_workflows_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "approval_workflows" ADD CONSTRAINT "approval_workflows_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "approval_workflows" ADD CONSTRAINT "approval_workflows_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "approval_workflows" ADD CONSTRAINT "approval_workflows_company_id_entity_id_fkey" FOREIGN KEY ("company_id", "entity_id") REFERENCES "master_entities"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "entity_constraints" ADD CONSTRAINT "entity_constraints_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "entity_constraints" ADD CONSTRAINT "entity_constraints_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "entity_constraints" ADD CONSTRAINT "entity_constraints_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "entity_constraints" ADD CONSTRAINT "entity_constraints_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "entity_constraints" ADD CONSTRAINT "entity_constraints_company_id_approval_workflow_id_fkey" FOREIGN KEY ("company_id", "approval_workflow_id") REFERENCES "approval_workflows"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "approver_constraints" ADD CONSTRAINT "approver_constraints_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "approver_constraints" ADD CONSTRAINT "approver_constraints_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "approver_constraints" ADD CONSTRAINT "approver_constraints_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "approver_constraints" ADD CONSTRAINT "approver_constraints_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "approver_constraints" ADD CONSTRAINT "approver_constraints_company_id_approval_workflow_id_fkey" FOREIGN KEY ("company_id", "approval_workflow_id") REFERENCES "approval_workflows"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "approval_modules" ADD CONSTRAINT "approval_modules_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "approval_modules" ADD CONSTRAINT "approval_modules_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "approval_modules" ADD CONSTRAINT "approval_modules_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "approval_modules" ADD CONSTRAINT "approval_modules_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "damage_request_line_items" ADD CONSTRAINT "damage_request_line_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "damage_request_line_items" ADD CONSTRAINT "damage_request_line_items_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "damage_request_line_items" ADD CONSTRAINT "damage_request_line_items_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "damage_request_line_items" ADD CONSTRAINT "damage_request_line_items_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "damage_request_line_items" ADD CONSTRAINT "damage_request_line_items_company_id_damage_request_id_fkey" FOREIGN KEY ("company_id", "damage_request_id") REFERENCES "damage_requests"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "damage_request_line_items" ADD CONSTRAINT "damage_request_line_items_company_id_item_id_fkey" FOREIGN KEY ("company_id", "item_id") REFERENCES "items"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "damage_request_line_items" ADD CONSTRAINT "damage_request_line_items_company_id_uom_id_fkey" FOREIGN KEY ("company_id", "uom_id") REFERENCES "uoms"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "damage_request_line_items" ADD CONSTRAINT "damage_request_line_items_company_id_item_status_id_fkey" FOREIGN KEY ("company_id", "item_status_id") REFERENCES "item_statuses"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "damage_requests" ADD CONSTRAINT "damage_requests_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "damage_requests" ADD CONSTRAINT "damage_requests_company_id_process_status_id_fkey" FOREIGN KEY ("company_id", "process_status_id") REFERENCES "process_status"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "damage_requests" ADD CONSTRAINT "damage_requests_company_id_web_service_log_id_fkey" FOREIGN KEY ("company_id", "web_service_log_id") REFERENCES "webservice_logs"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "damage_requests" ADD CONSTRAINT "damage_requests_company_id_storekeeper_id_fkey" FOREIGN KEY ("company_id", "storekeeper_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "damage_requests" ADD CONSTRAINT "damage_requests_company_id_salesman_id_fkey" FOREIGN KEY ("company_id", "salesman_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "damage_requests" ADD CONSTRAINT "damage_requests_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "damage_requests" ADD CONSTRAINT "damage_requests_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "damage_requests" ADD CONSTRAINT "damage_requests_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_requests" ADD CONSTRAINT "invoice_requests_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_requests" ADD CONSTRAINT "invoice_requests_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_requests" ADD CONSTRAINT "invoice_requests_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_requests" ADD CONSTRAINT "invoice_requests_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_requests" ADD CONSTRAINT "invoice_requests_company_id_outlet_id_fkey" FOREIGN KEY ("company_id", "outlet_id") REFERENCES "outlets"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_requests" ADD CONSTRAINT "invoice_requests_company_id_currency_id_fkey" FOREIGN KEY ("company_id", "currency_id") REFERENCES "currencies"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_requests" ADD CONSTRAINT "invoice_requests_company_id_bank_id_fkey" FOREIGN KEY ("company_id", "bank_id") REFERENCES "banks"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_requests" ADD CONSTRAINT "invoice_requests_company_id_bank_branch_id_fkey" FOREIGN KEY ("company_id", "bank_branch_id") REFERENCES "bankbranches"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_requests" ADD CONSTRAINT "invoice_requests_company_id_invoice_id_fkey" FOREIGN KEY ("company_id", "invoice_id") REFERENCES "invoices"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_requests" ADD CONSTRAINT "invoice_requests_company_id_process_status_id_fkey" FOREIGN KEY ("company_id", "process_status_id") REFERENCES "process_status"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_requests" ADD CONSTRAINT "invoice_requests_company_id_salesman_id_fkey" FOREIGN KEY ("company_id", "salesman_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_requests" ADD CONSTRAINT "invoice_requests_company_id_web_service_log_id_fkey" FOREIGN KEY ("company_id", "web_service_log_id") REFERENCES "webservice_logs"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_collections" ADD CONSTRAINT "invoice_collections_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_collections" ADD CONSTRAINT "invoice_collections_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_collections" ADD CONSTRAINT "invoice_collections_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_collections" ADD CONSTRAINT "invoice_collections_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_collections" ADD CONSTRAINT "invoice_collections_company_id_outlet_id_fkey" FOREIGN KEY ("company_id", "outlet_id") REFERENCES "outlets"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_collections" ADD CONSTRAINT "invoice_collections_company_id_currency_id_fkey" FOREIGN KEY ("company_id", "currency_id") REFERENCES "currencies"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_collections" ADD CONSTRAINT "invoice_collections_company_id_bank_id_fkey" FOREIGN KEY ("company_id", "bank_id") REFERENCES "banks"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_collections" ADD CONSTRAINT "invoice_collections_company_id_bank_branch_id_fkey" FOREIGN KEY ("company_id", "bank_branch_id") REFERENCES "bankbranches"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_collections" ADD CONSTRAINT "invoice_collections_company_id_invoice_id_fkey" FOREIGN KEY ("company_id", "invoice_id") REFERENCES "invoices"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_collections" ADD CONSTRAINT "invoice_collections_company_id_journey_plan_id_fkey" FOREIGN KEY ("company_id", "journey_plan_id") REFERENCES "journey_plans"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_collections" ADD CONSTRAINT "invoice_collections_company_id_salesman_id_fkey" FOREIGN KEY ("company_id", "salesman_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_collections" ADD CONSTRAINT "invoice_collections_company_id_web_service_log_id_fkey" FOREIGN KEY ("company_id", "web_service_log_id") REFERENCES "webservice_logs"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoices" ADD CONSTRAINT "invoices_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoices" ADD CONSTRAINT "invoices_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoices" ADD CONSTRAINT "invoices_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoices" ADD CONSTRAINT "invoices_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoices" ADD CONSTRAINT "invoices_company_id_journey_plan_id_fkey" FOREIGN KEY ("company_id", "journey_plan_id") REFERENCES "journey_plans"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoices" ADD CONSTRAINT "invoices_company_id_salesman_id_fkey" FOREIGN KEY ("company_id", "salesman_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoices" ADD CONSTRAINT "invoices_company_id_web_service_log_id_fkey" FOREIGN KEY ("company_id", "web_service_log_id") REFERENCES "webservice_logs"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoices" ADD CONSTRAINT "invoices_company_id_process_status_id_fkey" FOREIGN KEY ("company_id", "process_status_id") REFERENCES "process_status"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoices" ADD CONSTRAINT "invoices_company_id_reconciliation_id_fkey" FOREIGN KEY ("company_id", "reconciliation_id") REFERENCES "reconciliations"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoices" ADD CONSTRAINT "invoices_company_id_outlet_id_fkey" FOREIGN KEY ("company_id", "outlet_id") REFERENCES "outlets"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoices" ADD CONSTRAINT "invoices_company_id_currency_id_fkey" FOREIGN KEY ("company_id", "currency_id") REFERENCES "currencies"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoices" ADD CONSTRAINT "invoices_company_id_bank_id_fkey" FOREIGN KEY ("company_id", "bank_id") REFERENCES "banks"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoices" ADD CONSTRAINT "invoices_company_id_bank_branch_id_fkey" FOREIGN KEY ("company_id", "bank_branch_id") REFERENCES "bankbranches"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoices" ADD CONSTRAINT "invoices_company_id_route_id_fkey" FOREIGN KEY ("company_id", "route_id") REFERENCES "routes"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_line_items" ADD CONSTRAINT "invoice_line_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_line_items" ADD CONSTRAINT "invoice_line_items_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_line_items" ADD CONSTRAINT "invoice_line_items_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_line_items" ADD CONSTRAINT "invoice_line_items_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_line_items" ADD CONSTRAINT "invoice_line_items_company_id_invoice_id_fkey" FOREIGN KEY ("company_id", "invoice_id") REFERENCES "invoices"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_line_items" ADD CONSTRAINT "invoice_line_items_company_id_item_id_fkey" FOREIGN KEY ("company_id", "item_id") REFERENCES "items"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_line_items" ADD CONSTRAINT "invoice_line_items_company_id_uom_id_fkey" FOREIGN KEY ("company_id", "uom_id") REFERENCES "uoms"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "invoice_line_items" ADD CONSTRAINT "invoice_line_items_company_id_free_item_id_fkey" FOREIGN KEY ("company_id", "free_item_id") REFERENCES "free_items"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "credit_dues" ADD CONSTRAINT "credit_dues_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "credit_dues" ADD CONSTRAINT "credit_dues_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "credit_dues" ADD CONSTRAINT "credit_dues_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "credit_dues" ADD CONSTRAINT "credit_dues_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "credit_dues" ADD CONSTRAINT "credit_dues_company_id_outlet_id_fkey" FOREIGN KEY ("company_id", "outlet_id") REFERENCES "outlets"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "credit_dues" ADD CONSTRAINT "credit_dues_company_id_currency_id_fkey" FOREIGN KEY ("company_id", "currency_id") REFERENCES "currencies"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "credit_dues" ADD CONSTRAINT "credit_dues_company_id_statement_id_fkey" FOREIGN KEY ("company_id", "statement_id") REFERENCES "statements"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "journey_plans" ADD CONSTRAINT "journey_plans_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "journey_plans" ADD CONSTRAINT "journey_plans_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "journey_plans" ADD CONSTRAINT "journey_plans_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "journey_plans" ADD CONSTRAINT "journey_plans_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "journey_plans" ADD CONSTRAINT "journey_plans_company_id_salesman_id_fkey" FOREIGN KEY ("company_id", "salesman_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "journey_plans" ADD CONSTRAINT "journey_plans_company_id_route_id_fkey" FOREIGN KEY ("company_id", "route_id") REFERENCES "routes"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "upper_trade_logs" ADD CONSTRAINT "upper_trade_logs_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "upper_trade_logs" ADD CONSTRAINT "upper_trade_logs_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "upper_trade_logs" ADD CONSTRAINT "upper_trade_logs_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "upper_trade_logs" ADD CONSTRAINT "upper_trade_logs_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "reconciliation_line_items" ADD CONSTRAINT "reconciliation_line_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "reconciliation_line_items" ADD CONSTRAINT "reconciliation_line_items_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "reconciliation_line_items" ADD CONSTRAINT "reconciliation_line_items_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "reconciliation_line_items" ADD CONSTRAINT "reconciliation_line_items_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "reconciliation_line_items" ADD CONSTRAINT "reconciliation_line_items_company_id_reconciliation_id_fkey" FOREIGN KEY ("company_id", "reconciliation_id") REFERENCES "reconciliations"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "reconciliation_line_items" ADD CONSTRAINT "reconciliation_line_items_company_id_item_id_fkey" FOREIGN KEY ("company_id", "item_id") REFERENCES "items"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "reconciliation_line_items" ADD CONSTRAINT "reconciliation_line_items_company_id_uom_id_fkey" FOREIGN KEY ("company_id", "uom_id") REFERENCES "uoms"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "reconciliation_line_items" ADD CONSTRAINT "reconciliation_line_items_company_id_item_status_id_fkey" FOREIGN KEY ("company_id", "item_status_id") REFERENCES "item_statuses"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "pre_order_line_items" ADD CONSTRAINT "pre_order_line_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "pre_order_line_items" ADD CONSTRAINT "pre_order_line_items_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "pre_order_line_items" ADD CONSTRAINT "pre_order_line_items_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "pre_order_line_items" ADD CONSTRAINT "pre_order_line_items_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "pre_order_line_items" ADD CONSTRAINT "pre_order_line_items_company_id_pre_order_id_fkey" FOREIGN KEY ("company_id", "pre_order_id") REFERENCES "pre_orders"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "pre_order_line_items" ADD CONSTRAINT "pre_order_line_items_company_id_item_id_fkey" FOREIGN KEY ("company_id", "item_id") REFERENCES "items"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "pre_order_line_items" ADD CONSTRAINT "pre_order_line_items_company_id_uom_id_fkey" FOREIGN KEY ("company_id", "uom_id") REFERENCES "uoms"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "pre_order_line_items" ADD CONSTRAINT "pre_order_line_items_company_id_item_status_id_fkey" FOREIGN KEY ("company_id", "item_status_id") REFERENCES "item_statuses"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "reconciliations" ADD CONSTRAINT "reconciliations_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "reconciliations" ADD CONSTRAINT "reconciliations_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "reconciliations" ADD CONSTRAINT "reconciliations_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "reconciliations" ADD CONSTRAINT "reconciliations_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "reconciliations" ADD CONSTRAINT "reconciliations_company_id_salesman_id_fkey" FOREIGN KEY ("company_id", "salesman_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "reconciliations" ADD CONSTRAINT "reconciliations_company_id_store_keeper_id_fkey" FOREIGN KEY ("company_id", "store_keeper_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "pre_orders" ADD CONSTRAINT "pre_orders_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "pre_orders" ADD CONSTRAINT "pre_orders_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "pre_orders" ADD CONSTRAINT "pre_orders_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "pre_orders" ADD CONSTRAINT "pre_orders_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "pre_orders" ADD CONSTRAINT "pre_orders_company_id_journey_plan_id_fkey" FOREIGN KEY ("company_id", "journey_plan_id") REFERENCES "journey_plans"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "pre_orders" ADD CONSTRAINT "pre_orders_company_id_salesman_id_fkey" FOREIGN KEY ("company_id", "salesman_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "pre_orders" ADD CONSTRAINT "pre_orders_company_id_outlet_id_fkey" FOREIGN KEY ("company_id", "outlet_id") REFERENCES "outlets"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "salesman_targets" ADD CONSTRAINT "salesman_targets_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "salesman_targets" ADD CONSTRAINT "salesman_targets_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "salesman_targets" ADD CONSTRAINT "salesman_targets_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "salesman_targets" ADD CONSTRAINT "salesman_targets_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "salesman_targets" ADD CONSTRAINT "salesman_targets_company_id_salesman_id_fkey" FOREIGN KEY ("company_id", "salesman_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "salesman_targets" ADD CONSTRAINT "salesman_targets_company_id_outlet_id_fkey" FOREIGN KEY ("company_id", "outlet_id") REFERENCES "outlets"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "salesman_targets" ADD CONSTRAINT "salesman_targets_company_id_brand_id_fkey" FOREIGN KEY ("company_id", "brand_id") REFERENCES "brands"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "salesman_targets" ADD CONSTRAINT "salesman_targets_company_id_supplier_id_fkey" FOREIGN KEY ("company_id", "supplier_id") REFERENCES "suppliers"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "department_salesman_mappings" ADD CONSTRAINT "department_salesman_mappings_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "department_salesman_mappings" ADD CONSTRAINT "department_salesman_mappings_company_id_salesman_id_fkey" FOREIGN KEY ("company_id", "salesman_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "department_salesman_mappings" ADD CONSTRAINT "department_salesman_mappings_company_id_department_id_fkey" FOREIGN KEY ("company_id", "department_id") REFERENCES "departments"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "salesman_trackings" ADD CONSTRAINT "salesman_trackings_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "salesman_trackings" ADD CONSTRAINT "salesman_trackings_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "salesman_trackings" ADD CONSTRAINT "salesman_trackings_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "salesman_trackings" ADD CONSTRAINT "salesman_trackings_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "salesman_trackings" ADD CONSTRAINT "salesman_trackings_company_id_salesman_id_fkey" FOREIGN KEY ("company_id", "salesman_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "salesman_trackings" ADD CONSTRAINT "salesman_trackings_company_id_device_id_fkey" FOREIGN KEY ("company_id", "device_id") REFERENCES "devices"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "salesman_trackings" ADD CONSTRAINT "salesman_trackings_company_id_outlet_id_fkey" FOREIGN KEY ("company_id", "outlet_id") REFERENCES "outlets"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_unload_request_line_items" ADD CONSTRAINT "van_unload_request_line_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_unload_request_line_items" ADD CONSTRAINT "van_unload_request_line_items_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_unload_request_line_items" ADD CONSTRAINT "van_unload_request_line_items_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_unload_request_line_items" ADD CONSTRAINT "van_unload_request_line_items_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_unload_request_line_items" ADD CONSTRAINT "van_unload_request_line_items_van_unload_request_id_fkey" FOREIGN KEY ("van_unload_request_id") REFERENCES "van_unload_requests"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_unload_request_line_items" ADD CONSTRAINT "van_unload_request_line_items_company_id_item_id_fkey" FOREIGN KEY ("company_id", "item_id") REFERENCES "items"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_unload_request_line_items" ADD CONSTRAINT "van_unload_request_line_items_company_id_uom_id_fkey" FOREIGN KEY ("company_id", "uom_id") REFERENCES "uoms"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_unload_request_line_items" ADD CONSTRAINT "van_unload_request_line_items_company_id_item_status_id_fkey" FOREIGN KEY ("company_id", "item_status_id") REFERENCES "item_statuses"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "return_line_items" ADD CONSTRAINT "return_line_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "return_line_items" ADD CONSTRAINT "return_line_items_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "return_line_items" ADD CONSTRAINT "return_line_items_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "return_line_items" ADD CONSTRAINT "return_line_items_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "return_line_items" ADD CONSTRAINT "return_line_items_company_id_return_id_fkey" FOREIGN KEY ("company_id", "return_id") REFERENCES "return_items"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "return_line_items" ADD CONSTRAINT "return_line_items_company_id_item_id_fkey" FOREIGN KEY ("company_id", "item_id") REFERENCES "items"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "return_line_items" ADD CONSTRAINT "return_line_items_company_id_uom_id_fkey" FOREIGN KEY ("company_id", "uom_id") REFERENCES "uoms"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "return_line_items" ADD CONSTRAINT "return_line_items_company_id_item_status_id_fkey" FOREIGN KEY ("company_id", "item_status_id") REFERENCES "item_statuses"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "salesman_target_line_items" ADD CONSTRAINT "salesman_target_line_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "salesman_target_line_items" ADD CONSTRAINT "salesman_target_line_items_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "salesman_target_line_items" ADD CONSTRAINT "salesman_target_line_items_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "salesman_target_line_items" ADD CONSTRAINT "salesman_target_line_items_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "salesman_target_line_items" ADD CONSTRAINT "salesman_target_line_items_company_id_salesman_target_id_fkey" FOREIGN KEY ("company_id", "salesman_target_id") REFERENCES "salesman_targets"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "salesman_target_line_items" ADD CONSTRAINT "salesman_target_line_items_company_id_item_id_fkey" FOREIGN KEY ("company_id", "item_id") REFERENCES "items"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_unload_requests" ADD CONSTRAINT "van_unload_requests_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_unload_requests" ADD CONSTRAINT "van_unload_requests_company_id_process_status_id_fkey" FOREIGN KEY ("company_id", "process_status_id") REFERENCES "process_status"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_unload_requests" ADD CONSTRAINT "van_unload_requests_company_id_web_service_log_id_fkey" FOREIGN KEY ("company_id", "web_service_log_id") REFERENCES "webservice_logs"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_unload_requests" ADD CONSTRAINT "van_unload_requests_company_id_salesman_id_fkey" FOREIGN KEY ("company_id", "salesman_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_unload_requests" ADD CONSTRAINT "van_unload_requests_company_id_storekeeper_id_fkey" FOREIGN KEY ("company_id", "storekeeper_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_unload_requests" ADD CONSTRAINT "van_unload_requests_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_unload_requests" ADD CONSTRAINT "van_unload_requests_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_unload_requests" ADD CONSTRAINT "van_unload_requests_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_unload_requests" ADD CONSTRAINT "van_unload_requests_company_id_route_id_fkey" FOREIGN KEY ("company_id", "route_id") REFERENCES "routes"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_unload_requests" ADD CONSTRAINT "van_unload_requests_company_id_department_id_fkey" FOREIGN KEY ("company_id", "department_id") REFERENCES "departments"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "return_items" ADD CONSTRAINT "return_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "return_items" ADD CONSTRAINT "return_items_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "return_items" ADD CONSTRAINT "return_items_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "return_items" ADD CONSTRAINT "return_items_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "return_items" ADD CONSTRAINT "return_items_company_id_process_status_id_fkey" FOREIGN KEY ("company_id", "process_status_id") REFERENCES "process_status"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "return_items" ADD CONSTRAINT "return_items_company_id_web_service_log_id_fkey" FOREIGN KEY ("company_id", "web_service_log_id") REFERENCES "webservice_logs"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "return_items" ADD CONSTRAINT "return_items_company_id_salesman_id_fkey" FOREIGN KEY ("company_id", "salesman_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "return_items" ADD CONSTRAINT "return_items_company_id_route_id_fkey" FOREIGN KEY ("company_id", "route_id") REFERENCES "routes"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "return_items" ADD CONSTRAINT "return_items_invoice_id_fkey" FOREIGN KEY ("invoice_id") REFERENCES "invoices"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "return_items" ADD CONSTRAINT "return_items_journey_plan_id_fkey" FOREIGN KEY ("journey_plan_id") REFERENCES "journey_plans"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "return_items" ADD CONSTRAINT "return_items_outlet_id_fkey" FOREIGN KEY ("outlet_id") REFERENCES "outlets"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "return_items" ADD CONSTRAINT "return_items_currency_id_fkey" FOREIGN KEY ("currency_id") REFERENCES "currencies"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "return_items" ADD CONSTRAINT "return_items_reconciliation_id_fkey" FOREIGN KEY ("reconciliation_id") REFERENCES "reconciliations"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "financial_years" ADD CONSTRAINT "financial_years_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "financial_years" ADD CONSTRAINT "financial_years_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "financial_years" ADD CONSTRAINT "financial_years_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "financial_years" ADD CONSTRAINT "financial_years_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "configurations" ADD CONSTRAINT "configurations_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "audit_logs" ADD CONSTRAINT "audit_logs_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "audit_logs" ADD CONSTRAINT "audit_logs_company_id_user_id_fkey" FOREIGN KEY ("company_id", "user_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "audit_log_line_items" ADD CONSTRAINT "audit_log_line_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "audit_log_line_items" ADD CONSTRAINT "audit_log_line_items_company_id_audit_log_id_fkey" FOREIGN KEY ("company_id", "audit_log_id") REFERENCES "audit_logs"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "app_error_log" ADD CONSTRAINT "app_error_log_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "process_status" ADD CONSTRAINT "process_status_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "webservice_logs" ADD CONSTRAINT "webservice_logs_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "webservice_logs" ADD CONSTRAINT "webservice_logs_company_id_salesman_id_fkey" FOREIGN KEY ("company_id", "salesman_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "webservice_logs" ADD CONSTRAINT "webservice_logs_company_id_route_id_fkey" FOREIGN KEY ("company_id", "route_id") REFERENCES "routes"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "webservice_logs" ADD CONSTRAINT "webservice_logs_company_id_device_id_fkey" FOREIGN KEY ("company_id", "device_id") REFERENCES "devices"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "application_modules" ADD CONSTRAINT "application_modules_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "alert_notify_types" ADD CONSTRAINT "alert_notify_types_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "document_sequences" ADD CONSTRAINT "document_sequences_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "document_sequences" ADD CONSTRAINT "document_sequences_company_id_salesman_id_fkey" FOREIGN KEY ("company_id", "salesman_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "document_sequences" ADD CONSTRAINT "document_sequences_company_id_fin_year_id_fkey" FOREIGN KEY ("company_id", "fin_year_id") REFERENCES "financial_years"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "document_sequences" ADD CONSTRAINT "document_sequences_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "document_sequences" ADD CONSTRAINT "document_sequences_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "document_sequences" ADD CONSTRAINT "document_sequences_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_configurations" ADD CONSTRAINT "user_configurations_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_configurations" ADD CONSTRAINT "user_configurations_company_id_user_id_fkey" FOREIGN KEY ("company_id", "user_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_types" ADD CONSTRAINT "user_types_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "data_transfer_queries" ADD CONSTRAINT "data_transfer_queries_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "data_transfer_queries" ADD CONSTRAINT "data_transfer_queries_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "warehouse_stocks" ADD CONSTRAINT "warehouse_stocks_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "warehouse_stocks" ADD CONSTRAINT "warehouse_stocks_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "warehouse_stocks" ADD CONSTRAINT "warehouse_stocks_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "warehouse_stocks" ADD CONSTRAINT "warehouse_stocks_company_id_warehouse_id_fkey" FOREIGN KEY ("company_id", "warehouse_id") REFERENCES "warehouses"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "warehouse_stocks" ADD CONSTRAINT "warehouse_stocks_company_id_item_id_fkey" FOREIGN KEY ("company_id", "item_id") REFERENCES "items"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "warehouse_stocks" ADD CONSTRAINT "warehouse_stocks_company_id_uom_id_fkey" FOREIGN KEY ("company_id", "uom_id") REFERENCES "uoms"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "warehouse_stocks" ADD CONSTRAINT "warehouse_stocks_company_id_item_status_id_fkey" FOREIGN KEY ("company_id", "item_status_id") REFERENCES "item_statuses"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "stock_adjustments" ADD CONSTRAINT "stock_adjustments_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "stock_adjustments" ADD CONSTRAINT "stock_adjustments_company_id_salesman_id_fkey" FOREIGN KEY ("company_id", "salesman_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "stock_adjustments" ADD CONSTRAINT "stock_adjustments_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "stock_adjustments" ADD CONSTRAINT "stock_adjustments_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "stock_adjustment_line_items" ADD CONSTRAINT "stock_adjustment_line_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "stock_adjustment_line_items" ADD CONSTRAINT "stock_adjustment_line_items_company_id_item_id_fkey" FOREIGN KEY ("company_id", "item_id") REFERENCES "items"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "stock_adjustment_line_items" ADD CONSTRAINT "stock_adjustment_line_items_company_id_item_status_id_fkey" FOREIGN KEY ("company_id", "item_status_id") REFERENCES "item_statuses"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "stock_adjustment_line_items" ADD CONSTRAINT "stock_adjustment_line_items_company_id_stock_adjustment_id_fkey" FOREIGN KEY ("company_id", "stock_adjustment_id") REFERENCES "stock_adjustments"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "stock_adjustment_line_items" ADD CONSTRAINT "stock_adjustment_line_items_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "daily_open_stocks" ADD CONSTRAINT "daily_open_stocks_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "daily_open_stocks" ADD CONSTRAINT "daily_open_stocks_company_id_item_id_fkey" FOREIGN KEY ("company_id", "item_id") REFERENCES "items"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "daily_open_stocks" ADD CONSTRAINT "daily_open_stocks_company_id_item_status_id_fkey" FOREIGN KEY ("company_id", "item_status_id") REFERENCES "item_statuses"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "daily_open_stocks" ADD CONSTRAINT "daily_open_stocks_company_id_uom_id_fkey" FOREIGN KEY ("company_id", "uom_id") REFERENCES "uoms"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "daily_open_stocks" ADD CONSTRAINT "daily_open_stocks_company_id_salesman_id_fkey" FOREIGN KEY ("company_id", "salesman_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "daily_open_stocks" ADD CONSTRAINT "daily_open_stocks_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "daily_open_stocks" ADD CONSTRAINT "daily_open_stocks_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "stock_transfer_requests" ADD CONSTRAINT "stock_transfer_requests_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "stock_transfer_requests" ADD CONSTRAINT "stock_transfer_requests_company_id_web_service_log_id_fkey" FOREIGN KEY ("company_id", "web_service_log_id") REFERENCES "webservice_logs"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "stock_transfer_requests" ADD CONSTRAINT "stock_transfer_requests_company_id_process_status_id_fkey" FOREIGN KEY ("company_id", "process_status_id") REFERENCES "process_status"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "stock_transfer_requests" ADD CONSTRAINT "stock_transfer_requests_company_id_from_salesman_id_fkey" FOREIGN KEY ("company_id", "from_salesman_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "stock_transfer_requests" ADD CONSTRAINT "stock_transfer_requests_company_id_to_salesman_id_fkey" FOREIGN KEY ("company_id", "to_salesman_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "stock_transfer_requests" ADD CONSTRAINT "stock_transfer_requests_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "stock_transfer_requests" ADD CONSTRAINT "stock_transfer_requests_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "stock_transfer_request_line_items" ADD CONSTRAINT "stock_transfer_request_line_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "stock_transfer_request_line_items" ADD CONSTRAINT "stock_transfer_request_line_items_company_id_item_id_fkey" FOREIGN KEY ("company_id", "item_id") REFERENCES "items"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "stock_transfer_request_line_items" ADD CONSTRAINT "stock_transfer_request_line_items_company_id_item_status_i_fkey" FOREIGN KEY ("company_id", "item_status_id") REFERENCES "item_statuses"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "stock_transfer_request_line_items" ADD CONSTRAINT "stock_transfer_request_line_items_company_id_uom_id_fkey" FOREIGN KEY ("company_id", "uom_id") REFERENCES "uoms"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "stock_transfer_request_line_items" ADD CONSTRAINT "stock_transfer_request_line_items_company_id_stock_transfe_fkey" FOREIGN KEY ("company_id", "stock_transfer_request_id") REFERENCES "stock_transfer_requests"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "stock_transfer_request_line_items" ADD CONSTRAINT "stock_transfer_request_line_items_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_stock_audit_headers" ADD CONSTRAINT "outlet_stock_audit_headers_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_stock_audit_headers" ADD CONSTRAINT "outlet_stock_audit_headers_company_id_outlet_id_fkey" FOREIGN KEY ("company_id", "outlet_id") REFERENCES "outlets"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_stock_audit_headers" ADD CONSTRAINT "outlet_stock_audit_headers_company_id_salesman_id_fkey" FOREIGN KEY ("company_id", "salesman_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_stock_audit_headers" ADD CONSTRAINT "outlet_stock_audit_headers_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_stock_audit_headers" ADD CONSTRAINT "outlet_stock_audit_headers_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_stock_audit_line_items" ADD CONSTRAINT "outlet_stock_audit_line_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_stock_audit_line_items" ADD CONSTRAINT "outlet_stock_audit_line_items_company_id_item_id_fkey" FOREIGN KEY ("company_id", "item_id") REFERENCES "items"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_stock_audit_line_items" ADD CONSTRAINT "outlet_stock_audit_line_items_company_id_item_status_id_fkey" FOREIGN KEY ("company_id", "item_status_id") REFERENCES "item_statuses"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_stock_audit_line_items" ADD CONSTRAINT "outlet_stock_audit_line_items_company_id_uom_id_fkey" FOREIGN KEY ("company_id", "uom_id") REFERENCES "uoms"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_stock_audit_line_items" ADD CONSTRAINT "outlet_stock_audit_line_items_company_id_location_type_id_fkey" FOREIGN KEY ("company_id", "location_type_id") REFERENCES "location_types"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_stock_audit_line_items" ADD CONSTRAINT "outlet_stock_audit_line_items_company_id_outlet_stock_audi_fkey" FOREIGN KEY ("company_id", "outlet_stock_audit_header_id") REFERENCES "outlet_stock_audit_headers"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_stock_audit_line_items" ADD CONSTRAINT "outlet_stock_audit_line_items_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "outlet_stock_audit_line_items" ADD CONSTRAINT "outlet_stock_audit_line_items_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_load_requests" ADD CONSTRAINT "van_load_requests_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_load_requests" ADD CONSTRAINT "van_load_requests_company_id_department_id_fkey" FOREIGN KEY ("company_id", "department_id") REFERENCES "departments"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_load_requests" ADD CONSTRAINT "van_load_requests_company_id_web_service_log_id_fkey" FOREIGN KEY ("company_id", "web_service_log_id") REFERENCES "webservice_logs"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_load_requests" ADD CONSTRAINT "van_load_requests_company_id_process_status_id_fkey" FOREIGN KEY ("company_id", "process_status_id") REFERENCES "process_status"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_load_requests" ADD CONSTRAINT "van_load_requests_company_id_salesman_id_fkey" FOREIGN KEY ("company_id", "salesman_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_load_requests" ADD CONSTRAINT "van_load_requests_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_load_requests" ADD CONSTRAINT "van_load_requests_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_load_requests" ADD CONSTRAINT "van_load_requests_company_id_route_id_fkey" FOREIGN KEY ("company_id", "route_id") REFERENCES "routes"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_load_requests" ADD CONSTRAINT "van_load_requests_company_id_van_load_approval_id_fkey" FOREIGN KEY ("company_id", "van_load_approval_id") REFERENCES "van_load_approvals"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_load_requests" ADD CONSTRAINT "van_load_requests_company_id_storekeeper_id_fkey" FOREIGN KEY ("company_id", "storekeeper_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_load_request_line_items" ADD CONSTRAINT "van_load_request_line_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_load_request_line_items" ADD CONSTRAINT "van_load_request_line_items_company_id_item_id_fkey" FOREIGN KEY ("company_id", "item_id") REFERENCES "items"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_load_request_line_items" ADD CONSTRAINT "van_load_request_line_items_company_id_item_status_id_fkey" FOREIGN KEY ("company_id", "item_status_id") REFERENCES "item_statuses"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_load_request_line_items" ADD CONSTRAINT "van_load_request_line_items_company_id_uom_id_fkey" FOREIGN KEY ("company_id", "uom_id") REFERENCES "uoms"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_load_request_line_items" ADD CONSTRAINT "van_load_request_line_items_company_id_van_load_request_id_fkey" FOREIGN KEY ("company_id", "van_load_request_id") REFERENCES "van_load_requests"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_load_request_line_items" ADD CONSTRAINT "van_load_request_line_items_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_load_approvals" ADD CONSTRAINT "van_load_approvals_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_load_approvals" ADD CONSTRAINT "van_load_approvals_company_id_supervisor_id_fkey" FOREIGN KEY ("company_id", "supervisor_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_load_approvals" ADD CONSTRAINT "van_load_approvals_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_load_approvals" ADD CONSTRAINT "van_load_approvals_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_load_approval_line_items" ADD CONSTRAINT "van_load_approval_line_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_load_approval_line_items" ADD CONSTRAINT "van_load_approval_line_items_company_id_item_id_fkey" FOREIGN KEY ("company_id", "item_id") REFERENCES "items"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_load_approval_line_items" ADD CONSTRAINT "van_load_approval_line_items_company_id_item_status_id_fkey" FOREIGN KEY ("company_id", "item_status_id") REFERENCES "item_statuses"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_load_approval_line_items" ADD CONSTRAINT "van_load_approval_line_items_company_id_uom_id_fkey" FOREIGN KEY ("company_id", "uom_id") REFERENCES "uoms"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_load_approval_line_items" ADD CONSTRAINT "van_load_approval_line_items_company_id_van_load_approval__fkey" FOREIGN KEY ("company_id", "van_load_approval_id") REFERENCES "van_load_approvals"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_load_approval_line_items" ADD CONSTRAINT "van_load_approval_line_items_company_id_route_id_fkey" FOREIGN KEY ("company_id", "route_id") REFERENCES "routes"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_load_approval_line_items" ADD CONSTRAINT "van_load_approval_line_items_company_id_salesman_id_fkey" FOREIGN KEY ("company_id", "salesman_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_load_approval_line_items" ADD CONSTRAINT "van_load_approval_line_items_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_stocks" ADD CONSTRAINT "van_stocks_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_stocks" ADD CONSTRAINT "van_stocks_company_id_item_id_fkey" FOREIGN KEY ("company_id", "item_id") REFERENCES "items"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_stocks" ADD CONSTRAINT "van_stocks_company_id_item_status_id_fkey" FOREIGN KEY ("company_id", "item_status_id") REFERENCES "item_statuses"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_stocks" ADD CONSTRAINT "van_stocks_company_id_uom_id_fkey" FOREIGN KEY ("company_id", "uom_id") REFERENCES "uoms"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_stocks" ADD CONSTRAINT "van_stocks_company_id_salesman_id_fkey" FOREIGN KEY ("company_id", "salesman_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_stocks" ADD CONSTRAINT "van_stocks_company_id_route_id_fkey" FOREIGN KEY ("company_id", "route_id") REFERENCES "routes"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_stocks" ADD CONSTRAINT "van_stocks_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_stocks" ADD CONSTRAINT "van_stocks_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_stocks" ADD CONSTRAINT "van_stocks_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_stock_audits" ADD CONSTRAINT "van_stock_audits_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_stock_audits" ADD CONSTRAINT "van_stock_audits_company_id_salesman_id_fkey" FOREIGN KEY ("company_id", "salesman_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_stock_audits" ADD CONSTRAINT "van_stock_audits_company_id_route_id_fkey" FOREIGN KEY ("company_id", "route_id") REFERENCES "routes"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_stock_audits" ADD CONSTRAINT "van_stock_audits_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_stock_audits" ADD CONSTRAINT "van_stock_audits_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_stock_audit_line_items" ADD CONSTRAINT "van_stock_audit_line_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_stock_audit_line_items" ADD CONSTRAINT "van_stock_audit_line_items_company_id_item_id_fkey" FOREIGN KEY ("company_id", "item_id") REFERENCES "items"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_stock_audit_line_items" ADD CONSTRAINT "van_stock_audit_line_items_company_id_item_status_id_fkey" FOREIGN KEY ("company_id", "item_status_id") REFERENCES "item_statuses"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_stock_audit_line_items" ADD CONSTRAINT "van_stock_audit_line_items_company_id_uom_id_fkey" FOREIGN KEY ("company_id", "uom_id") REFERENCES "uoms"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_stock_audit_line_items" ADD CONSTRAINT "van_stock_audit_line_items_company_id_van_stock_audit_id_fkey" FOREIGN KEY ("company_id", "van_stock_audit_id") REFERENCES "van_stock_audits"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_stock_audit_line_items" ADD CONSTRAINT "van_stock_audit_line_items_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "van_stock_audit_line_items" ADD CONSTRAINT "van_stock_audit_line_items_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "email_template_process" ADD CONSTRAINT "email_template_process_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "email_template_tags" ADD CONSTRAINT "email_template_tags_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "email_template_recipient_tags" ADD CONSTRAINT "email_template_recipient_tags_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "email_template_process_tags_mapping" ADD CONSTRAINT "email_template_process_tags_mapping_email_template_process_fkey" FOREIGN KEY ("email_template_process_id", "company_id") REFERENCES "email_template_process"("id", "company_id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "email_template_process_tags_mapping" ADD CONSTRAINT "email_template_process_tags_mapping_email_template_tag_id__fkey" FOREIGN KEY ("email_template_tag_id", "company_id") REFERENCES "email_template_tags"("id", "company_id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "email_templates" ADD CONSTRAINT "email_templates_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "email_templates" ADD CONSTRAINT "email_templates_email_template_process_id_company_id_fkey" FOREIGN KEY ("email_template_process_id", "company_id") REFERENCES "email_template_process"("id", "company_id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "email_templates" ADD CONSTRAINT "email_templates_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "email_templates" ADD CONSTRAINT "email_templates_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "email_templates" ADD CONSTRAINT "email_templates_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "email_template_assignments" ADD CONSTRAINT "email_template_assignments_email_template_process_id_compa_fkey" FOREIGN KEY ("email_template_process_id", "company_id") REFERENCES "email_template_process"("id", "company_id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "email_template_assignments" ADD CONSTRAINT "email_template_assignments_template_id_company_id_fkey" FOREIGN KEY ("template_id", "company_id") REFERENCES "email_templates"("id", "company_id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "email_template_assignments" ADD CONSTRAINT "email_template_assignments_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "cash_receipts" ADD CONSTRAINT "cash_receipts_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "cash_receipts" ADD CONSTRAINT "cash_receipts_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "cash_receipts" ADD CONSTRAINT "cash_receipts_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "cash_receipts" ADD CONSTRAINT "cash_receipts_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "cash_receipts" ADD CONSTRAINT "cash_receipts_company_id_salesman_id_fkey" FOREIGN KEY ("company_id", "salesman_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "cash_receipts" ADD CONSTRAINT "cash_receipts_company_id_statement_id_fkey" FOREIGN KEY ("company_id", "statement_id") REFERENCES "statements"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "cash_receipts" ADD CONSTRAINT "cash_receipts_company_id_route_id_fkey" FOREIGN KEY ("company_id", "route_id") REFERENCES "routes"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "cash_receipts" ADD CONSTRAINT "cash_receipts_company_id_outlet_id_fkey" FOREIGN KEY ("company_id", "outlet_id") REFERENCES "outlets"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "cash_receipts" ADD CONSTRAINT "cash_receipts_company_id_currency_id_fkey" FOREIGN KEY ("company_id", "currency_id") REFERENCES "currencies"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "cash_receipts" ADD CONSTRAINT "cash_receipts_company_id_bank_id_fkey" FOREIGN KEY ("company_id", "bank_id") REFERENCES "banks"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "cash_receipts" ADD CONSTRAINT "cash_receipts_company_id_bank_branch_id_fkey" FOREIGN KEY ("company_id", "bank_branch_id") REFERENCES "bankbranches"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "cash_receipts" ADD CONSTRAINT "cash_receipts_company_id_web_service_log_id_fkey" FOREIGN KEY ("company_id", "web_service_log_id") REFERENCES "webservice_logs"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "wallet_transactions" ADD CONSTRAINT "wallet_transactions_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "wallet_transactions" ADD CONSTRAINT "wallet_transactions_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "wallet_transactions" ADD CONSTRAINT "wallet_transactions_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "wallet_transactions" ADD CONSTRAINT "wallet_transactions_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "wallet_transactions" ADD CONSTRAINT "wallet_transactions_company_id_salesman_id_fkey" FOREIGN KEY ("company_id", "salesman_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "wallet_transactions" ADD CONSTRAINT "wallet_transactions_company_id_statement_id_fkey" FOREIGN KEY ("company_id", "statement_id") REFERENCES "statements"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "wallet_transactions" ADD CONSTRAINT "wallet_transactions_company_id_return_id_fkey" FOREIGN KEY ("company_id", "return_id") REFERENCES "return_items"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "wallet_transactions" ADD CONSTRAINT "wallet_transactions_company_id_route_id_fkey" FOREIGN KEY ("company_id", "route_id") REFERENCES "routes"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "wallet_transactions" ADD CONSTRAINT "wallet_transactions_company_id_outlet_id_fkey" FOREIGN KEY ("company_id", "outlet_id") REFERENCES "outlets"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "wallet_transactions" ADD CONSTRAINT "wallet_transactions_company_id_currency_id_fkey" FOREIGN KEY ("company_id", "currency_id") REFERENCES "currencies"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "wallet_transactions" ADD CONSTRAINT "wallet_transactions_company_id_bank_id_fkey" FOREIGN KEY ("company_id", "bank_id") REFERENCES "banks"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "wallet_transactions" ADD CONSTRAINT "wallet_transactions_company_id_bank_branch_id_fkey" FOREIGN KEY ("company_id", "bank_branch_id") REFERENCES "bankbranches"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "wallet_transactions" ADD CONSTRAINT "wallet_transactions_company_id_web_service_log_id_fkey" FOREIGN KEY ("company_id", "web_service_log_id") REFERENCES "webservice_logs"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "statements" ADD CONSTRAINT "statements_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "statements" ADD CONSTRAINT "statements_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "statements" ADD CONSTRAINT "statements_company_id_salesman_id_fkey" FOREIGN KEY ("company_id", "salesman_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "statements" ADD CONSTRAINT "statements_company_id_route_id_fkey" FOREIGN KEY ("company_id", "route_id") REFERENCES "routes"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "statements" ADD CONSTRAINT "statements_company_id_outlet_id_fkey" FOREIGN KEY ("company_id", "outlet_id") REFERENCES "outlets"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "import_templates" ADD CONSTRAINT "import_templates_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "import_templates" ADD CONSTRAINT "import_templates_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "import_templates" ADD CONSTRAINT "import_templates_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "import_templates" ADD CONSTRAINT "import_templates_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "import_template_line_items" ADD CONSTRAINT "import_template_line_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "import_template_line_items" ADD CONSTRAINT "import_template_line_items_company_id_import_template_id_fkey" FOREIGN KEY ("company_id", "import_template_id") REFERENCES "import_templates"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "statuses" ADD CONSTRAINT "statuses_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;
