-- CompanyDetails relations
ALTER TABLE "company" ADD CONSTRAINT fk_company_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "company" ADD CONSTRAINT fk_company_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "company" ADD CONSTRAINT fk_company_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "company" ADD CONSTRAINT fk_company_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- BusinessUnit relations
ALTER TABLE "business_unit" ADD CONSTRAINT fk_business_unit_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "business_unit" ADD CONSTRAINT fk_business_unit_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "business_unit" ADD CONSTRAINT fk_business_unit_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "business_unit" ADD CONSTRAINT fk_business_unit_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- Currency relations
ALTER TABLE "currency" ADD CONSTRAINT fk_currency_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "currency" ADD CONSTRAINT fk_currency_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "currency" ADD CONSTRAINT fk_currency_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "currency" ADD CONSTRAINT fk_currency_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- Country relations
ALTER TABLE "country" ADD CONSTRAINT fk_country_currency FOREIGN KEY (currency_id) REFERENCES "currency"(id) ON DELETE CASCADE;
ALTER TABLE "country" ADD CONSTRAINT fk_country_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "country" ADD CONSTRAINT fk_country_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "country" ADD CONSTRAINT fk_country_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "country" ADD CONSTRAINT fk_country_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- State relations
ALTER TABLE "states" ADD CONSTRAINT fk_state_country FOREIGN KEY (country_id) REFERENCES "country"(id) ON DELETE CASCADE;
ALTER TABLE "states" ADD CONSTRAINT fk_state_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "states" ADD CONSTRAINT fk_state_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "states" ADD CONSTRAINT fk_state_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "states" ADD CONSTRAINT fk_state_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- City relations
ALTER TABLE "city" ADD CONSTRAINT fk_city_state FOREIGN KEY (state_id) REFERENCES "states"(id) ON DELETE CASCADE;
ALTER TABLE "city" ADD CONSTRAINT fk_city_country FOREIGN KEY (country_id) REFERENCES "country"(id) ON DELETE CASCADE;
ALTER TABLE "city" ADD CONSTRAINT fk_city_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "city" ADD CONSTRAINT fk_city_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "city" ADD CONSTRAINT fk_city_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "city" ADD CONSTRAINT fk_city_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- TaxType relations
ALTER TABLE "tax_types" ADD CONSTRAINT fk_taxtype_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "tax_types" ADD CONSTRAINT fk_taxtype_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "tax_types" ADD CONSTRAINT fk_taxtype_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "tax_types" ADD CONSTRAINT fk_taxtype_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- TaxRegion relations
ALTER TABLE "tax_regions" ADD CONSTRAINT fk_taxregion_city FOREIGN KEY (city_id) REFERENCES "city"(id) ON DELETE CASCADE;
ALTER TABLE "tax_regions" ADD CONSTRAINT fk_taxregion_state FOREIGN KEY (state_id) REFERENCES "states"(id) ON DELETE CASCADE;
ALTER TABLE "tax_regions" ADD CONSTRAINT fk_taxregion_country FOREIGN KEY (country_id) REFERENCES "country"(id) ON DELETE CASCADE;
ALTER TABLE "tax_regions" ADD CONSTRAINT fk_taxregion_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "tax_regions" ADD CONSTRAINT fk_taxregion_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "tax_regions" ADD CONSTRAINT fk_taxregion_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "tax_regions" ADD CONSTRAINT fk_taxregion_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- TaxRule relations
ALTER TABLE "tax_rules" ADD CONSTRAINT fk_taxrule_taxtype FOREIGN KEY (tax_type_id) REFERENCES "tax_types"(id) ON DELETE CASCADE;
ALTER TABLE "tax_rules" ADD CONSTRAINT fk_taxrule_taxregion FOREIGN KEY (tax_region_id) REFERENCES "tax_regions"(id) ON DELETE CASCADE;
ALTER TABLE "tax_rules" ADD CONSTRAINT fk_taxrule_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "tax_rules" ADD CONSTRAINT fk_taxrule_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "tax_rules" ADD CONSTRAINT fk_taxrule_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "tax_rules" ADD CONSTRAINT fk_taxrule_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- TaxComponent relations
ALTER TABLE "tax_components" ADD CONSTRAINT fk_taxcomponent_taxrule FOREIGN KEY (tax_rule_id) REFERENCES "tax_rules"(id) ON DELETE CASCADE;
ALTER TABLE "tax_components" ADD CONSTRAINT fk_taxcomponent_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "tax_components" ADD CONSTRAINT fk_taxcomponent_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "tax_components" ADD CONSTRAINT fk_taxcomponent_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "tax_components" ADD CONSTRAINT fk_taxcomponent_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- Industry relations
ALTER TABLE "industry" ADD CONSTRAINT fk_industry_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "industry" ADD CONSTRAINT fk_industry_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "industry" ADD CONSTRAINT fk_industry_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "industry" ADD CONSTRAINT fk_industry_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- CompanyCurrencies relations
ALTER TABLE "company_currencies" ADD CONSTRAINT fk_companycurrencies_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "company_currencies" ADD CONSTRAINT fk_companycurrencies_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "company_currencies" ADD CONSTRAINT fk_companycurrencies_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "company_currencies" ADD CONSTRAINT fk_companycurrencies_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "company_currencies" ADD CONSTRAINT fk_companycurrencies_business_unit FOREIGN KEY (business_unit_id) REFERENCES "business_unit"(id) ON DELETE CASCADE;
ALTER TABLE "company_currencies" ADD CONSTRAINT fk_companycurrencies_currency FOREIGN KEY (currency_id) REFERENCES "currency"(id) ON DELETE CASCADE;

-- CurrencyExchangeRates relations
ALTER TABLE "currency_exchange_rates" ADD CONSTRAINT fk_currencyexchangerates_business_unit FOREIGN KEY (business_unit_id) REFERENCES "business_unit"(id) ON DELETE CASCADE;
ALTER TABLE "currency_exchange_rates" ADD CONSTRAINT fk_currencyexchangerates_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "currency_exchange_rates" ADD CONSTRAINT fk_currencyexchangerates_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "currency_exchange_rates" ADD CONSTRAINT fk_currencyexchangerates_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "currency_exchange_rates" ADD CONSTRAINT fk_currencyexchangerates_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- CompanyBranch relations
ALTER TABLE "company_branches" ADD CONSTRAINT fk_companybranch_business_unit FOREIGN KEY (business_unit_id) REFERENCES "business_unit"(id) ON DELETE CASCADE;
ALTER TABLE "company_branches" ADD CONSTRAINT fk_companybranch_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "company_branches" ADD CONSTRAINT fk_companybranch_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "company_branches" ADD CONSTRAINT fk_companybranch_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "company_branches" ADD CONSTRAINT fk_companybranch_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- Section relations
ALTER TABLE "section" ADD CONSTRAINT fk_section_department FOREIGN KEY (department_id) REFERENCES "departments"(id) ON DELETE CASCADE;
ALTER TABLE "section" ADD CONSTRAINT fk_section_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "section" ADD CONSTRAINT fk_section_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "section" ADD CONSTRAINT fk_section_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "section" ADD CONSTRAINT fk_section_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- OutletGroup relations
ALTER TABLE "outlet_group" ADD CONSTRAINT fk_outletgroup_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "outlet_group" ADD CONSTRAINT fk_outletgroup_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "outlet_group" ADD CONSTRAINT fk_outletgroup_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "outlet_group" ADD CONSTRAINT fk_outletgroup_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- OutletClass relations
ALTER TABLE "outlet_class" ADD CONSTRAINT fk_outletclass_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "outlet_class" ADD CONSTRAINT fk_outletclass_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "outlet_class" ADD CONSTRAINT fk_outletclass_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "outlet_class" ADD CONSTRAINT fk_outletclass_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- OutletTag relations
ALTER TABLE "outlet_tags" ADD CONSTRAINT fk_outlettag_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "outlet_tags" ADD CONSTRAINT fk_outlettag_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "outlet_tags" ADD CONSTRAINT fk_outlettag_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "outlet_tags" ADD CONSTRAINT fk_outlettag_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- OutletType relations
ALTER TABLE "outlet_types" ADD CONSTRAINT fk_outlettype_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "outlet_types" ADD CONSTRAINT fk_outlettype_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "outlet_types" ADD CONSTRAINT fk_outlettype_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "outlet_types" ADD CONSTRAINT fk_outlettype_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- Outlet relations
ALTER TABLE "outlet" ADD CONSTRAINT fk_outlet_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "outlet" ADD CONSTRAINT fk_outlet_group FOREIGN KEY (group_id) REFERENCES "outlet_group"(id) ON DELETE CASCADE;
ALTER TABLE "outlet" ADD CONSTRAINT fk_outlet_type FOREIGN KEY (type_id) REFERENCES "outlet_types"(id) ON DELETE CASCADE;
ALTER TABLE "outlet" ADD CONSTRAINT fk_outlet_class FOREIGN KEY (class_id) REFERENCES "outlet_class"(id) ON DELETE CASCADE;
ALTER TABLE "outlet" ADD CONSTRAINT fk_outlet_tax_region FOREIGN KEY (tax_region_id) REFERENCES "tax_regions"(id) ON DELETE CASCADE;
ALTER TABLE "outlet" ADD CONSTRAINT fk_outlet_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "outlet" ADD CONSTRAINT fk_outlet_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "outlet" ADD CONSTRAINT fk_outlet_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "outlet" ADD CONSTRAINT fk_outlet_billing_to FOREIGN KEY (billing_to_id) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "outlet" ADD CONSTRAINT fk_outlet_account_manager FOREIGN KEY (account_manager_id) REFERENCES "users"(id) ON DELETE CASCADE;

-- OutletAddress relations
ALTER TABLE "outlet_address" ADD CONSTRAINT fk_outletaddress_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "outlet_address" ADD CONSTRAINT fk_outletaddress_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "outlet_address" ADD CONSTRAINT fk_outletaddress_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "outlet_address" ADD CONSTRAINT fk_outletaddress_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- OutletAddressMapping relations
ALTER TABLE "outlet_address_mapping" ADD CONSTRAINT fk_outletaddressmapping_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "outlet_address_mapping" ADD CONSTRAINT fk_outletaddressmapping_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "outlet_address_mapping" ADD CONSTRAINT fk_outletaddressmapping_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "outlet_address_mapping" ADD CONSTRAINT fk_outletaddressmapping_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "outlet_address_mapping" ADD CONSTRAINT fk_outletaddressmapping_outlet FOREIGN KEY (outlet_id) REFERENCES "outlet"(id) ON DELETE CASCADE;
ALTER TABLE "outlet_address_mapping" ADD CONSTRAINT fk_outletaddressmapping_outlet_address FOREIGN KEY (outlet_address_id) REFERENCES "outlet_address"(id) ON DELETE CASCADE;

-- OutletTagMapping relations
ALTER TABLE "outlet_tag_mapping" ADD CONSTRAINT fk_outlettagmapping_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "outlet_tag_mapping" ADD CONSTRAINT fk_outlettagmapping_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "outlet_tag_mapping" ADD CONSTRAINT fk_outlettagmapping_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "outlet_tag_mapping" ADD CONSTRAINT fk_outlettagmapping_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "outlet_tag_mapping" ADD CONSTRAINT fk_outlettagmapping_outlet FOREIGN KEY (outlet_id) REFERENCES "outlet"(id) ON DELETE CASCADE;
ALTER TABLE "outlet_tag_mapping" ADD CONSTRAINT fk_outlettagmapping_outlet_tag FOREIGN KEY (outlet_tag_id) REFERENCES "outlet_tags"(id) ON DELETE CASCADE;

-- OutletContact relations
ALTER TABLE "outlet_contact" ADD CONSTRAINT fk_outletcontact_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "outlet_contact" ADD CONSTRAINT fk_outletcontact_outlet FOREIGN KEY (outlet_id) REFERENCES "outlet"(id) ON DELETE CASCADE;
ALTER TABLE "outlet_contact" ADD CONSTRAINT fk_outletcontact_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "outlet_contact" ADD CONSTRAINT fk_outletcontact_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "outlet_contact" ADD CONSTRAINT fk_outletcontact_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "outlet_contact" ADD CONSTRAINT fk_outletcontact_designation FOREIGN KEY (designation_id) REFERENCES "designations"(id) ON DELETE CASCADE;

-- WarehouseType relations
ALTER TABLE "warehouse_type" ADD CONSTRAINT fk_warehousetype_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "warehouse_type" ADD CONSTRAINT fk_warehousetype_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "warehouse_type" ADD CONSTRAINT fk_warehousetype_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "warehouse_type" ADD CONSTRAINT fk_warehousetype_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- WarehouseSite relations
ALTER TABLE "warehouse_site" ADD CONSTRAINT fk_warehousesite_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "warehouse_site" ADD CONSTRAINT fk_warehousesite_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "warehouse_site" ADD CONSTRAINT fk_warehousesite_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "warehouse_site" ADD CONSTRAINT fk_warehousesite_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- Warehouse relations
ALTER TABLE "warehouse" ADD CONSTRAINT fk_warehouse_warehouse_type FOREIGN KEY (warehouse_type_id) REFERENCES "warehouse_type"(id) ON DELETE CASCADE;
ALTER TABLE "warehouse" ADD CONSTRAINT fk_warehouse_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "warehouse" ADD CONSTRAINT fk_warehouse_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "warehouse" ADD CONSTRAINT fk_warehouse_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "warehouse" ADD CONSTRAINT fk_warehouse_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- WarehouseZoneType relations
ALTER TABLE "warehouse_zone_type" ADD CONSTRAINT fk_warehousezonetype_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "warehouse_zone_type" ADD CONSTRAINT fk_warehousezonetype_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "warehouse_zone_type" ADD CONSTRAINT fk_warehousezonetype_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "warehouse_zone_type" ADD CONSTRAINT fk_warehousezonetype_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- WarehouseZone relations
ALTER TABLE "warehouse_zones" ADD CONSTRAINT fk_warehousezone_warehouse FOREIGN KEY (warehouse_id) REFERENCES "warehouse"(id) ON DELETE CASCADE;
ALTER TABLE "warehouse_zones" ADD CONSTRAINT fk_warehousezone_zone_type FOREIGN KEY (zone_type_id) REFERENCES "warehouse_zone_type"(id) ON DELETE CASCADE;
ALTER TABLE "warehouse_zones" ADD CONSTRAINT fk_warehousezone_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "warehouse_zones" ADD CONSTRAINT fk_warehousezone_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "warehouse_zones" ADD CONSTRAINT fk_warehousezone_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "warehouse_zones" ADD CONSTRAINT fk_warehousezone_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- WarehouseLocation relations
ALTER TABLE "warehouse_locations" ADD CONSTRAINT fk_warehouselocation_warehouse FOREIGN KEY (warehouse_id) REFERENCES "warehouse"(id) ON DELETE CASCADE;
ALTER TABLE "warehouse_locations" ADD CONSTRAINT fk_warehouselocation_warehouse_zone FOREIGN KEY (warehouse_zone_id) REFERENCES "warehouse_zones"(id) ON DELETE CASCADE;
ALTER TABLE "warehouse_locations" ADD CONSTRAINT fk_warehouselocation_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "warehouse_locations" ADD CONSTRAINT fk_warehouselocation_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "warehouse_locations" ADD CONSTRAINT fk_warehouselocation_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "warehouse_locations" ADD CONSTRAINT fk_warehouselocation_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- UomType relations
ALTER TABLE "uom_type" ADD CONSTRAINT fk_uomtype_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "uom_type" ADD CONSTRAINT fk_uomtype_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "uom_type" ADD CONSTRAINT fk_uomtype_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "uom_type" ADD CONSTRAINT fk_uomtype_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- UnitsOfMeasure relations
ALTER TABLE "units_of_measure" ADD CONSTRAINT fk_unitsofmeasure_uom_type FOREIGN KEY (uom_type_id) REFERENCES "uom_type"(id) ON DELETE CASCADE;
ALTER TABLE "units_of_measure" ADD CONSTRAINT fk_unitsofmeasure_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "units_of_measure" ADD CONSTRAINT fk_unitsofmeasure_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "units_of_measure" ADD CONSTRAINT fk_unitsofmeasure_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "units_of_measure" ADD CONSTRAINT fk_unitsofmeasure_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- ProductCategory relations
ALTER TABLE "product_category" ADD CONSTRAINT fk_productcategory_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "product_category" ADD CONSTRAINT fk_productcategory_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "product_category" ADD CONSTRAINT fk_productcategory_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "product_category" ADD CONSTRAINT fk_productcategory_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- ProductGroup relations
ALTER TABLE "product_group" ADD CONSTRAINT fk_productgroup_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "product_group" ADD CONSTRAINT fk_productgroup_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "product_group" ADD CONSTRAINT fk_productgroup_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "product_group" ADD CONSTRAINT fk_productgroup_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- ProductTags relations
ALTER TABLE "product_tags" ADD CONSTRAINT fk_producttags_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "product_tags" ADD CONSTRAINT fk_producttags_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "product_tags" ADD CONSTRAINT fk_producttags_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "product_tags" ADD CONSTRAINT fk_producttags_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- Brands relations
ALTER TABLE "brands" ADD CONSTRAINT fk_brands_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "brands" ADD CONSTRAINT fk_brands_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "brands" ADD CONSTRAINT fk_brands_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "brands" ADD CONSTRAINT fk_brands_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- ProductModel relations
ALTER TABLE "product_models" ADD CONSTRAINT fk_productmodel_brand FOREIGN KEY (brand_id) REFERENCES "brands"(id) ON DELETE CASCADE;
ALTER TABLE "product_models" ADD CONSTRAINT fk_productmodel_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "product_models" ADD CONSTRAINT fk_productmodel_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "product_models" ADD CONSTRAINT fk_productmodel_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "product_models" ADD CONSTRAINT fk_productmodel_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- Manufacture relations
ALTER TABLE "manufacture" ADD CONSTRAINT fk_manufacture_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "manufacture" ADD CONSTRAINT fk_manufacture_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "manufacture" ADD CONSTRAINT fk_manufacture_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "manufacture" ADD CONSTRAINT fk_manufacture_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- Product relations
ALTER TABLE "product" ADD CONSTRAINT fk_product_category FOREIGN KEY (category_id) REFERENCES "product_category"(id);
ALTER TABLE "product" ADD CONSTRAINT fk_product_group FOREIGN KEY (group_id) REFERENCES "product_group"(id);
ALTER TABLE "product" ADD CONSTRAINT fk_product_brand FOREIGN KEY (brand_id) REFERENCES "brands"(id);
ALTER TABLE "product" ADD CONSTRAINT fk_product_manufacturer FOREIGN KEY (manufacturer_id) REFERENCES "manufacture"(id);
ALTER TABLE "product" ADD CONSTRAINT fk_product_model FOREIGN KEY (model_id) REFERENCES "product_models"(id);
ALTER TABLE "product" ADD CONSTRAINT fk_product_tax_rule FOREIGN KEY (tax_rule_id) REFERENCES "tax_rules"(id);
ALTER TABLE "product" ADD CONSTRAINT fk_product_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "product" ADD CONSTRAINT fk_product_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "product" ADD CONSTRAINT fk_product_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "product" ADD CONSTRAINT fk_product_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- ProductTagMapping relations
ALTER TABLE "product_tag_mapping" ADD CONSTRAINT fk_producttagmapping_product FOREIGN KEY (product_id) REFERENCES "product"(id);
ALTER TABLE "product_tag_mapping" ADD CONSTRAINT fk_producttagmapping_product_tag FOREIGN KEY (product_tag_id) REFERENCES "product_tags"(id);
ALTER TABLE "product_tag_mapping" ADD CONSTRAINT fk_producttagmapping_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "product_tag_mapping" ADD CONSTRAINT fk_producttagmapping_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "product_tag_mapping" ADD CONSTRAINT fk_producttagmapping_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "product_tag_mapping" ADD CONSTRAINT fk_producttagmapping_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- ProductUom relations
ALTER TABLE "product_uom" ADD CONSTRAINT fk_productuom_product FOREIGN KEY (product_id) REFERENCES "product"(id);
ALTER TABLE "product_uom" ADD CONSTRAINT fk_productuom_uom FOREIGN KEY (uom_id) REFERENCES "units_of_measure"(id);
ALTER TABLE "product_uom" ADD CONSTRAINT fk_productuom_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "product_uom" ADD CONSTRAINT fk_productuom_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "product_uom" ADD CONSTRAINT fk_productuom_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "product_uom" ADD CONSTRAINT fk_productuom_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- PriceList relations
ALTER TABLE "price_list" ADD CONSTRAINT fk_pricelist_currency FOREIGN KEY (currency_id) REFERENCES "currency"(id);
ALTER TABLE "price_list" ADD CONSTRAINT fk_pricelist_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "price_list" ADD CONSTRAINT fk_pricelist_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "price_list" ADD CONSTRAINT fk_pricelist_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "price_list" ADD CONSTRAINT fk_pricelist_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- PriceListLine relations
ALTER TABLE "price_list_lines" ADD CONSTRAINT fk_pricelistline_pricelist FOREIGN KEY (price_list_id) REFERENCES "price_list"(id);
ALTER TABLE "price_list_lines" ADD CONSTRAINT fk_pricelistline_product FOREIGN KEY (product_id) REFERENCES "product"(id);
ALTER TABLE "price_list_lines" ADD CONSTRAINT fk_pricelistline_uom FOREIGN KEY (uom_id) REFERENCES "units_of_measure"(id);
ALTER TABLE "price_list_lines" ADD CONSTRAINT fk_pricelistline_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "price_list_lines" ADD CONSTRAINT fk_pricelistline_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "price_list_lines" ADD CONSTRAINT fk_pricelistline_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "price_list_lines" ADD CONSTRAINT fk_pricelistline_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- Discount relations
ALTER TABLE "discounts" ADD CONSTRAINT fk_discount_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "discounts" ADD CONSTRAINT fk_discount_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "discounts" ADD CONSTRAINT fk_discount_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "discounts" ADD CONSTRAINT fk_discount_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- DiscountRule relations
ALTER TABLE "discount_rules" ADD CONSTRAINT fk_discountrule_discount FOREIGN KEY (discount_id) REFERENCES "discounts"(id);
ALTER TABLE "discount_rules" ADD CONSTRAINT fk_discountrule_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "discount_rules" ADD CONSTRAINT fk_discountrule_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "discount_rules" ADD CONSTRAINT fk_discountrule_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "discount_rules" ADD CONSTRAINT fk_discountrule_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- RoutePlan relations
ALTER TABLE "route_plans" ADD CONSTRAINT fk_routeplan_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "route_plans" ADD CONSTRAINT fk_routeplan_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "route_plans" ADD CONSTRAINT fk_routeplan_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "route_plans" ADD CONSTRAINT fk_routeplan_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- Route relations
ALTER TABLE "route" ADD CONSTRAINT fk_route_status FOREIGN KEY (status_id) REFERENCES "statuses"(id) ON DELETE CASCADE;
ALTER TABLE "route" ADD CONSTRAINT fk_route_created_by FOREIGN KEY (created_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "route" ADD CONSTRAINT fk_route_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id) ON DELETE CASCADE;
ALTER TABLE "route" ADD CONSTRAINT fk_route_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id) ON DELETE CASCADE;

-- RoutePlanDay relations
ALTER TABLE "route_plan_days" ADD CONSTRAINT fk_routeplandays_routeplan FOREIGN KEY (route_plans_id) REFERENCES "route_plans"(id);
ALTER TABLE "route_plan_days" ADD CONSTRAINT fk_routeplandays_route FOREIGN KEY (route_id) REFERENCES "route"(id);
ALTER TABLE "route_plan_days" ADD CONSTRAINT fk_routeplandays_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "route_plan_days" ADD CONSTRAINT fk_routeplandays_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "route_plan_days" ADD CONSTRAINT fk_routeplandays_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "route_plan_days" ADD CONSTRAINT fk_routeplandays_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- PlannedOutletVisit relations
ALTER TABLE "planned_outlet_visit" ADD CONSTRAINT fk_plannedoutletvisit_routeplan FOREIGN KEY (route_plans_id) REFERENCES "route_plans"(id);
ALTER TABLE "planned_outlet_visit" ADD CONSTRAINT fk_plannedoutletvisit_outlet FOREIGN KEY (outlet_id) REFERENCES "outlet"(id);
ALTER TABLE "planned_outlet_visit" ADD CONSTRAINT fk_plannedoutletvisit_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "planned_outlet_visit" ADD CONSTRAINT fk_plannedoutletvisit_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "planned_outlet_visit" ADD CONSTRAINT fk_plannedoutletvisit_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "planned_outlet_visit" ADD CONSTRAINT fk_plannedoutletvisit_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- RouteVisitSequence relations
ALTER TABLE "route_visit_sequence" ADD CONSTRAINT fk_routevisitsequence_routeplan FOREIGN KEY (route_plans_id) REFERENCES "route_plans"(id);
ALTER TABLE "route_visit_sequence" ADD CONSTRAINT fk_routevisitsequence_route FOREIGN KEY (route_id) REFERENCES "route"(id);
ALTER TABLE "route_visit_sequence" ADD CONSTRAINT fk_routevisitsequence_outlet FOREIGN KEY (outlet_id) REFERENCES "outlet"(id);
ALTER TABLE "route_visit_sequence" ADD CONSTRAINT fk_routevisitsequence_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "route_visit_sequence" ADD CONSTRAINT fk_routevisitsequence_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "route_visit_sequence" ADD CONSTRAINT fk_routevisitsequence_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "route_visit_sequence" ADD CONSTRAINT fk_routevisitsequence_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- VisitScheduleEntry relations
ALTER TABLE "visit_schedule_entry" ADD CONSTRAINT fk_visitscheduleentry_routeplan FOREIGN KEY (route_plans_id) REFERENCES "route_plans"(id);
ALTER TABLE "visit_schedule_entry" ADD CONSTRAINT fk_visitscheduleentry_route FOREIGN KEY (route_id) REFERENCES "route"(id);
ALTER TABLE "visit_schedule_entry" ADD CONSTRAINT fk_visitscheduleentry_outlet FOREIGN KEY (outlet_id) REFERENCES "outlet"(id);
ALTER TABLE "visit_schedule_entry" ADD CONSTRAINT fk_visitscheduleentry_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "visit_schedule_entry" ADD CONSTRAINT fk_visitscheduleentry_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "visit_schedule_entry" ADD CONSTRAINT fk_visitscheduleentry_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "visit_schedule_entry" ADD CONSTRAINT fk_visitscheduleentry_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- TargetType relations
ALTER TABLE "target_type" ADD CONSTRAINT fk_targettype_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "target_type" ADD CONSTRAINT fk_targettype_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "target_type" ADD CONSTRAINT fk_targettype_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "target_type" ADD CONSTRAINT fk_targettype_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- TargetMetric relations
ALTER TABLE "target_metrics" ADD CONSTRAINT fk_targetmetric_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "target_metrics" ADD CONSTRAINT fk_targetmetric_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "target_metrics" ADD CONSTRAINT fk_targetmetric_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "target_metrics" ADD CONSTRAINT fk_targetmetric_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- Target relations
ALTER TABLE "targets" ADD CONSTRAINT fk_target_target_type FOREIGN KEY (target_type_id) REFERENCES "target_type"(id);
ALTER TABLE "targets" ADD CONSTRAINT fk_target_target_metric FOREIGN KEY (target_metrics_id) REFERENCES "target_metrics"(id);
ALTER TABLE "targets" ADD CONSTRAINT fk_target_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "targets" ADD CONSTRAINT fk_target_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "targets" ADD CONSTRAINT fk_target_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "targets" ADD CONSTRAINT fk_target_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- CreditLimit relations
ALTER TABLE "credit_limit" ADD CONSTRAINT fk_creditlimit_currency FOREIGN KEY (currency_id) REFERENCES "currency"(id);
ALTER TABLE "credit_limit" ADD CONSTRAINT fk_creditlimit_outlet FOREIGN KEY (outlet_id) REFERENCES "outlet"(id);
ALTER TABLE "credit_limit" ADD CONSTRAINT fk_creditlimit_outlet_group FOREIGN KEY (outlet_group_id) REFERENCES "outlet_group"(id);
ALTER TABLE "credit_limit" ADD CONSTRAINT fk_creditlimit_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "credit_limit" ADD CONSTRAINT fk_creditlimit_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "credit_limit" ADD CONSTRAINT fk_creditlimit_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "credit_limit" ADD CONSTRAINT fk_creditlimit_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- SupervisorTeam relations
ALTER TABLE "supervisor_team" ADD CONSTRAINT fk_supervisorteam_supervisor FOREIGN KEY (supervisor_id) REFERENCES "users"(id);
ALTER TABLE "supervisor_team" ADD CONSTRAINT fk_supervisorteam_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "supervisor_team" ADD CONSTRAINT fk_supervisorteam_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "supervisor_team" ADD CONSTRAINT fk_supervisorteam_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "supervisor_team" ADD CONSTRAINT fk_supervisorteam_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- SupervisorTeamAssignment relations
ALTER TABLE "supervisor_team_assignments" ADD CONSTRAINT fk_supervisorteamassignment_supervisor_team FOREIGN KEY (supervisor_team_id) REFERENCES "supervisor_team"(id);
ALTER TABLE "supervisor_team_assignments" ADD CONSTRAINT fk_supervisorteamassignment_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "supervisor_team_assignments" ADD CONSTRAINT fk_supervisorteamassignment_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "supervisor_team_assignments" ADD CONSTRAINT fk_supervisorteamassignment_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "supervisor_team_assignments" ADD CONSTRAINT fk_supervisorteamassignment_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- InventoryBatch relations
ALTER TABLE "inventory_batch" ADD CONSTRAINT fk_inventorybatch_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "inventory_batch" ADD CONSTRAINT fk_inventorybatch_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "inventory_batch" ADD CONSTRAINT fk_inventorybatch_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "inventory_batch" ADD CONSTRAINT fk_inventorybatch_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- Inventory relations
ALTER TABLE "inventory" ADD CONSTRAINT fk_inventory_warehouse FOREIGN KEY (warehouse_id) REFERENCES "warehouse"(id);
ALTER TABLE "inventory" ADD CONSTRAINT fk_inventory_warehouse_location FOREIGN KEY (warehouse_locations_id) REFERENCES "warehouse_locations"(id);
ALTER TABLE "inventory" ADD CONSTRAINT fk_inventory_product FOREIGN KEY (product_id) REFERENCES "product"(id);
ALTER TABLE "inventory" ADD CONSTRAINT fk_inventory_uom FOREIGN KEY (uom_id) REFERENCES "units_of_measure"(id);
ALTER TABLE "inventory" ADD CONSTRAINT fk_inventory_inventory_batch FOREIGN KEY (inventory_batch_id) REFERENCES "inventory_batch"(id);
ALTER TABLE "inventory" ADD CONSTRAINT fk_inventory_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "inventory" ADD CONSTRAINT fk_inventory_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "inventory" ADD CONSTRAINT fk_inventory_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "inventory" ADD CONSTRAINT fk_inventory_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- InventoryMovement relations
ALTER TABLE "inventory_movement" ADD CONSTRAINT fk_inventorymovement_warehouse FOREIGN KEY (warehouse_id) REFERENCES "warehouse"(id);
ALTER TABLE "inventory_movement" ADD CONSTRAINT fk_inventorymovement_warehouse_location FOREIGN KEY (warehouse_locations_id) REFERENCES "warehouse_locations"(id);
ALTER TABLE "inventory_movement" ADD CONSTRAINT fk_inventorymovement_product FOREIGN KEY (product_id) REFERENCES "product"(id);
ALTER TABLE "inventory_movement" ADD CONSTRAINT fk_inventorymovement_uom FOREIGN KEY (uom_id) REFERENCES "units_of_measure"(id);
ALTER TABLE "inventory_movement" ADD CONSTRAINT fk_inventorymovement_inventory_batch FOREIGN KEY (inventory_batch_id) REFERENCES "inventory_batch"(id);
ALTER TABLE "inventory_movement" ADD CONSTRAINT fk_inventorymovement_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "inventory_movement" ADD CONSTRAINT fk_inventorymovement_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "inventory_movement" ADD CONSTRAINT fk_inventorymovement_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "inventory_movement" ADD CONSTRAINT fk_inventorymovement_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- EndorseVanTransaction relations
ALTER TABLE "endorse_van_transactions" ADD CONSTRAINT fk_endorsevantransaction_warehouse FOREIGN KEY (warehouse_id) REFERENCES "warehouse"(id);
ALTER TABLE "endorse_van_transactions" ADD CONSTRAINT fk_endorsevantransaction_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "endorse_van_transactions" ADD CONSTRAINT fk_endorsevantransaction_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "endorse_van_transactions" ADD CONSTRAINT fk_endorsevantransaction_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "endorse_van_transactions" ADD CONSTRAINT fk_endorsevantransaction_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- SettlementVanTransaction relations
ALTER TABLE "settlement_van_tranactions" ADD CONSTRAINT fk_settlementvantransaction_route FOREIGN KEY (route_id) REFERENCES "route"(id);
ALTER TABLE "settlement_van_tranactions" ADD CONSTRAINT fk_settlementvantransaction_endorse FOREIGN KEY (endorse_van_transactions_id) REFERENCES "endorse_van_transactions"(id);
ALTER TABLE "settlement_van_tranactions" ADD CONSTRAINT fk_settlementvantransaction_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "settlement_van_tranactions" ADD CONSTRAINT fk_settlementvantransaction_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "settlement_van_tranactions" ADD CONSTRAINT fk_settlementvantransaction_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "settlement_van_tranactions" ADD CONSTRAINT fk_settlementvantransaction_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- VanLoadRequest relations
ALTER TABLE "van_load_request" ADD CONSTRAINT fk_vanloadrequest_fy FOREIGN KEY (fy_id) REFERENCES "financial_years"(id);
ALTER TABLE "van_load_request" ADD CONSTRAINT fk_vanloadrequest_outlet FOREIGN KEY (outlet_id) REFERENCES "outlet"(id);
ALTER TABLE "van_load_request" ADD CONSTRAINT fk_vanloadrequest_salesman FOREIGN KEY (salesman_id) REFERENCES "users"(id);
ALTER TABLE "van_load_request" ADD CONSTRAINT fk_vanloadrequest_from_warehouse FOREIGN KEY (from_warehouse_id) REFERENCES "warehouse"(id);
ALTER TABLE "van_load_request" ADD CONSTRAINT fk_vanloadrequest_to_warehouse FOREIGN KEY (to_warehouse_id) REFERENCES "warehouse"(id);
ALTER TABLE "van_load_request" ADD CONSTRAINT fk_vanloadrequest_route FOREIGN KEY (route_id) REFERENCES "route"(id);
ALTER TABLE "van_load_request" ADD CONSTRAINT fk_vanloadrequest_endorse FOREIGN KEY (endorse_van_transactions_id) REFERENCES "endorse_van_transactions"(id);
ALTER TABLE "van_load_request" ADD CONSTRAINT fk_vanloadrequest_settlement FOREIGN KEY (settlement_van_tranactions_id) REFERENCES "settlement_van_tranactions"(id);
ALTER TABLE "van_load_request" ADD CONSTRAINT fk_vanloadrequest_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "van_load_request" ADD CONSTRAINT fk_vanloadrequest_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "van_load_request" ADD CONSTRAINT fk_vanloadrequest_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "van_load_request" ADD CONSTRAINT fk_vanloadrequest_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- StockTransfer relations
ALTER TABLE "stock_transfer" ADD CONSTRAINT fk_stocktransfer_from_warehouse FOREIGN KEY (from_warehouse_id) REFERENCES "warehouse"(id);
ALTER TABLE "stock_transfer" ADD CONSTRAINT fk_stocktransfer_to_warehouse FOREIGN KEY (to_warehouse_id) REFERENCES "warehouse"(id);
ALTER TABLE "stock_transfer" ADD CONSTRAINT fk_stocktransfer_requested_by FOREIGN KEY (requested_by) REFERENCES "users"(id);
ALTER TABLE "stock_transfer" ADD CONSTRAINT fk_stocktransfer_endorse FOREIGN KEY (endorse_van_txn_id) REFERENCES "endorse_van_transactions"(id);
ALTER TABLE "stock_transfer" ADD CONSTRAINT fk_stocktransfer_settlement FOREIGN KEY (settlement_van_txn_id) REFERENCES "settlement_van_tranactions"(id);
ALTER TABLE "stock_transfer" ADD CONSTRAINT fk_stocktransfer_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "stock_transfer" ADD CONSTRAINT fk_stocktransfer_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "stock_transfer" ADD CONSTRAINT fk_stocktransfer_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "stock_transfer" ADD CONSTRAINT fk_stocktransfer_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- VanLoadRequestLine relations
ALTER TABLE "van_load_request_lines" ADD CONSTRAINT fk_vanloadrequestline_load_request FOREIGN KEY (load_request_id) REFERENCES "van_load_request"(id);
ALTER TABLE "van_load_request_lines" ADD CONSTRAINT fk_vanloadrequestline_stock_transfer FOREIGN KEY (stock_transfer_id) REFERENCES "stock_transfer"(id);
ALTER TABLE "van_load_request_lines" ADD CONSTRAINT fk_vanloadrequestline_product FOREIGN KEY (product_id) REFERENCES "product"(id);
ALTER TABLE "van_load_request_lines" ADD CONSTRAINT fk_vanloadrequestline_uom FOREIGN KEY (uom_id) REFERENCES "units_of_measure"(id);
ALTER TABLE "van_load_request_lines" ADD CONSTRAINT fk_vanloadrequestline_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "van_load_request_lines" ADD CONSTRAINT fk_vanloadrequestline_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "van_load_request_lines" ADD CONSTRAINT fk_vanloadrequestline_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "van_load_request_lines" ADD CONSTRAINT fk_vanloadrequestline_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- VanInvoice relations
ALTER TABLE "van_invoice" ADD CONSTRAINT fk_vaninvoice_fy FOREIGN KEY (fy_id) REFERENCES "financial_years"(id);
ALTER TABLE "van_invoice" ADD CONSTRAINT fk_vaninvoice_salesman FOREIGN KEY (salesman_id) REFERENCES "users"(id);
ALTER TABLE "van_invoice" ADD CONSTRAINT fk_vaninvoice_outlet FOREIGN KEY (outlet_id) REFERENCES "outlet"(id);
ALTER TABLE "van_invoice" ADD CONSTRAINT fk_vaninvoice_warehouse FOREIGN KEY (warehouse_id) REFERENCES "warehouse"(id);
ALTER TABLE "van_invoice" ADD CONSTRAINT fk_vaninvoice_route FOREIGN KEY (route_id) REFERENCES "route"(id);
ALTER TABLE "van_invoice" ADD CONSTRAINT fk_vaninvoice_endorse FOREIGN KEY (endorse_van_transactions_id) REFERENCES "endorse_van_transactions"(id);
ALTER TABLE "van_invoice" ADD CONSTRAINT fk_vaninvoice_settlement FOREIGN KEY (settlement_van_tranactions_id) REFERENCES "settlement_van_tranactions"(id);
ALTER TABLE "van_invoice" ADD CONSTRAINT fk_vaninvoice_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "van_invoice" ADD CONSTRAINT fk_vaninvoice_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "van_invoice" ADD CONSTRAINT fk_vaninvoice_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "van_invoice" ADD CONSTRAINT fk_vaninvoice_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- VanInvoiceLine relations
ALTER TABLE "van_invoice_lines" ADD CONSTRAINT fk_vaninvoiceline_van_invoice FOREIGN KEY (van_invoice_id) REFERENCES "van_invoice"(id);
ALTER TABLE "van_invoice_lines" ADD CONSTRAINT fk_vaninvoiceline_product FOREIGN KEY (product_id) REFERENCES "product"(id);
ALTER TABLE "van_invoice_lines" ADD CONSTRAINT fk_vaninvoiceline_uom FOREIGN KEY (uom_id) REFERENCES "units_of_measure"(id);
ALTER TABLE "van_invoice_lines" ADD CONSTRAINT fk_vaninvoiceline_inventory_batch FOREIGN KEY (inventory_batch_id) REFERENCES "inventory_batch"(id);
ALTER TABLE "van_invoice_lines" ADD CONSTRAINT fk_vaninvoiceline_deal FOREIGN KEY (deal_id) REFERENCES "deal"(id);
ALTER TABLE "van_invoice_lines" ADD CONSTRAINT fk_vaninvoiceline_currency FOREIGN KEY (currency_id) REFERENCES "currency"(id);
ALTER TABLE "van_invoice_lines" ADD CONSTRAINT fk_vaninvoiceline_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "van_invoice_lines" ADD CONSTRAINT fk_vaninvoiceline_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "van_invoice_lines" ADD CONSTRAINT fk_vaninvoiceline_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "van_invoice_lines" ADD CONSTRAINT fk_vaninvoiceline_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- VanReceipt relations
ALTER TABLE "van_receipt" ADD CONSTRAINT fk_vanreceipt_fy FOREIGN KEY (fy_id) REFERENCES "financial_years"(id);
ALTER TABLE "van_receipt" ADD CONSTRAINT fk_vanreceipt_currency FOREIGN KEY (currency_id) REFERENCES "currency"(id);
ALTER TABLE "van_receipt" ADD CONSTRAINT fk_vanreceipt_endorse FOREIGN KEY (endorse_van_transactions_id) REFERENCES "endorse_van_transactions"(id);
ALTER TABLE "van_receipt" ADD CONSTRAINT fk_vanreceipt_settlement FOREIGN KEY (settlement_van_tranactions_id) REFERENCES "settlement_van_tranactions"(id);
ALTER TABLE "van_receipt" ADD CONSTRAINT fk_vanreceipt_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "van_receipt" ADD CONSTRAINT fk_vanreceipt_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "van_receipt" ADD CONSTRAINT fk_vanreceipt_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "van_receipt" ADD CONSTRAINT fk_vanreceipt_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- VanReceiptLine relations
ALTER TABLE "van_receipt_lines" ADD CONSTRAINT fk_vanreceiptline_field_sales_receipt FOREIGN KEY (field_sales_receipt_id) REFERENCES "van_receipt"(id);
ALTER TABLE "van_receipt_lines" ADD CONSTRAINT fk_vanreceiptline_field_sales_invoice FOREIGN KEY (field_sales_invoice_id) REFERENCES "van_invoice"(id);
ALTER TABLE "van_receipt_lines" ADD CONSTRAINT fk_vanreceiptline_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "van_receipt_lines" ADD CONSTRAINT fk_vanreceiptline_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "van_receipt_lines" ADD CONSTRAINT fk_vanreceiptline_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "van_receipt_lines" ADD CONSTRAINT fk_vanreceiptline_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- VanSalesReturn relations
ALTER TABLE "van_sales_return" ADD CONSTRAINT fk_vansalesreturn_fy FOREIGN KEY (fy_id) REFERENCES "financial_years"(id);
ALTER TABLE "van_sales_return" ADD CONSTRAINT fk_vansalesreturn_salesman FOREIGN KEY (salesman_id) REFERENCES "users"(id);
ALTER TABLE "van_sales_return" ADD CONSTRAINT fk_vansalesreturn_outlet FOREIGN KEY (outlet_id) REFERENCES "outlet"(id);
ALTER TABLE "van_sales_return" ADD CONSTRAINT fk_vansalesreturn_warehouse FOREIGN KEY (warehouse_id) REFERENCES "warehouse"(id);
ALTER TABLE "van_sales_return" ADD CONSTRAINT fk_vansalesreturn_route FOREIGN KEY (route_id) REFERENCES "route"(id);
ALTER TABLE "van_sales_return" ADD CONSTRAINT fk_vansalesreturn_van_invoice FOREIGN KEY (van_invoice_id) REFERENCES "van_invoice"(id);
ALTER TABLE "van_sales_return" ADD CONSTRAINT fk_vansalesreturn_endorse FOREIGN KEY (endorse_van_transactions_id) REFERENCES "endorse_van_transactions"(id);
ALTER TABLE "van_sales_return" ADD CONSTRAINT fk_vansalesreturn_settlement FOREIGN KEY (settlement_van_tranactions_id) REFERENCES "settlement_van_tranactions"(id);
ALTER TABLE "van_sales_return" ADD CONSTRAINT fk_vansalesreturn_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "van_sales_return" ADD CONSTRAINT fk_vansalesreturn_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "van_sales_return" ADD CONSTRAINT fk_vansalesreturn_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "van_sales_return" ADD CONSTRAINT fk_vansalesreturn_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- VanSalesReturnLine relations
ALTER TABLE "van_sales_return_lines" ADD CONSTRAINT fk_vansalesreturnline_field_sales_invoice FOREIGN KEY (field_sales_invoice_id) REFERENCES "van_invoice"(id);
ALTER TABLE "van_sales_return_lines" ADD CONSTRAINT fk_vansalesreturnline_product FOREIGN KEY (product_id) REFERENCES "product"(id);
ALTER TABLE "van_sales_return_lines" ADD CONSTRAINT fk_vansalesreturnline_uom FOREIGN KEY (uom_id) REFERENCES "units_of_measure"(id);
ALTER TABLE "van_sales_return_lines" ADD CONSTRAINT fk_vansalesreturnline_inventory_batch FOREIGN KEY (inventory_batch_id) REFERENCES "inventory_batch"(id);
ALTER TABLE "van_sales_return_lines" ADD CONSTRAINT fk_vansalesreturnline_currency FOREIGN KEY (currency_id) REFERENCES "currency"(id);
ALTER TABLE "van_sales_return_lines" ADD CONSTRAINT fk_vansalesreturnline_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "van_sales_return_lines" ADD CONSTRAINT fk_vansalesreturnline_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "van_sales_return_lines" ADD CONSTRAINT fk_vansalesreturnline_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "van_sales_return_lines" ADD CONSTRAINT fk_vansalesreturnline_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- StockTransferRequest relations
ALTER TABLE "stock_transfer_request" ADD CONSTRAINT fk_stocktransferrequest_stock_transfer FOREIGN KEY (stock_transfer_id) REFERENCES "stock_transfer"(id);
ALTER TABLE "stock_transfer_request" ADD CONSTRAINT fk_stocktransferrequest_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "stock_transfer_request" ADD CONSTRAINT fk_stocktransferrequest_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "stock_transfer_request" ADD CONSTRAINT fk_stocktransferrequest_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "stock_transfer_request" ADD CONSTRAINT fk_stocktransferrequest_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- StockTransferLine relations
ALTER TABLE "stock_transfer_lines" ADD CONSTRAINT fk_stocktransferline_stock_transfer FOREIGN KEY (stock_transfer_id) REFERENCES "stock_transfer"(id);
ALTER TABLE "stock_transfer_lines" ADD CONSTRAINT fk_stocktransferline_product FOREIGN KEY (product_id) REFERENCES "product"(id);
ALTER TABLE "stock_transfer_lines" ADD CONSTRAINT fk_stocktransferline_uom FOREIGN KEY (uom_id) REFERENCES "units_of_measure"(id);
ALTER TABLE "stock_transfer_lines" ADD CONSTRAINT fk_stocktransferline_inventory_batch FOREIGN KEY (inventory_batch_id) REFERENCES "inventory_batch"(id);
ALTER TABLE "stock_transfer_lines" ADD CONSTRAINT fk_stocktransferline_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "stock_transfer_lines" ADD CONSTRAINT fk_stocktransferline_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "stock_transfer_lines" ADD CONSTRAINT fk_stocktransferline_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "stock_transfer_lines" ADD CONSTRAINT fk_stocktransferline_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- StockDepletionRequest relations
ALTER TABLE "stock_depletion_request" ADD CONSTRAINT fk_stockdepletionrequest_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "stock_depletion_request" ADD CONSTRAINT fk_stockdepletionrequest_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "stock_depletion_request" ADD CONSTRAINT fk_stockdepletionrequest_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "stock_depletion_request" ADD CONSTRAINT fk_stockdepletionrequest_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);
ALTER TABLE "stock_depletion_request" ADD CONSTRAINT fk_stockdepletionrequest_requested_by FOREIGN KEY (requested_by) REFERENCES "users"(id);

-- StockDepletionRequestLine relations
ALTER TABLE "stock_depletion_request_lines" ADD CONSTRAINT fk_stockdepletionrequestline_stock_depletion_request FOREIGN KEY (stock_depletion_request_id) REFERENCES "stock_depletion_request"(id);
ALTER TABLE "stock_depletion_request_lines" ADD CONSTRAINT fk_stockdepletionrequestline_product FOREIGN KEY (product_id) REFERENCES "product"(id);
ALTER TABLE "stock_depletion_request_lines" ADD CONSTRAINT fk_stockdepletionrequestline_uom FOREIGN KEY (uom_id) REFERENCES "units_of_measure"(id);
ALTER TABLE "stock_depletion_request_lines" ADD CONSTRAINT fk_stockdepletionrequestline_inventory_batch FOREIGN KEY (inventory_batch_id) REFERENCES "inventory_batch"(id);
ALTER TABLE "stock_depletion_request_lines" ADD CONSTRAINT fk_stockdepletionrequestline_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "stock_depletion_request_lines" ADD CONSTRAINT fk_stockdepletionrequestline_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "stock_depletion_request_lines" ADD CONSTRAINT fk_stockdepletionrequestline_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "stock_depletion_request_lines" ADD CONSTRAINT fk_stockdepletionrequestline_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- StockReconcilation relations
ALTER TABLE "stock_reconcilation" ADD CONSTRAINT fk_stockreconcilation_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "stock_reconcilation" ADD CONSTRAINT fk_stockreconcilation_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "stock_reconcilation" ADD CONSTRAINT fk_stockreconcilation_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "stock_reconcilation" ADD CONSTRAINT fk_stockreconcilation_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);
ALTER TABLE "stock_reconcilation" ADD CONSTRAINT fk_stockreconcilation_reconciled_by FOREIGN KEY (reconciled_by) REFERENCES "users"(id);

-- StockReconcilationLine relations
ALTER TABLE "stock_reconcilation_lines" ADD CONSTRAINT fk_stockreconcilationline_stock_reconcilation FOREIGN KEY (stock_reconcilation_id) REFERENCES "stock_reconcilation"(id);
ALTER TABLE "stock_reconcilation_lines" ADD CONSTRAINT fk_stockreconcilationline_product FOREIGN KEY (product_id) REFERENCES "product"(id);
ALTER TABLE "stock_reconcilation_lines" ADD CONSTRAINT fk_stockreconcilationline_uom FOREIGN KEY (uom_id) REFERENCES "units_of_measure"(id);
ALTER TABLE "stock_reconcilation_lines" ADD CONSTRAINT fk_stockreconcilationline_inventory_batch FOREIGN KEY (inventory_batch_id) REFERENCES "inventory_batch"(id);
ALTER TABLE "stock_reconcilation_lines" ADD CONSTRAINT fk_stockreconcilationline_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "stock_reconcilation_lines" ADD CONSTRAINT fk_stockreconcilationline_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "stock_reconcilation_lines" ADD CONSTRAINT fk_stockreconcilationline_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "stock_reconcilation_lines" ADD CONSTRAINT fk_stockreconcilationline_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- Deal relations
ALTER TABLE "deal" ADD CONSTRAINT fk_deal_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "deal" ADD CONSTRAINT fk_deal_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "deal" ADD CONSTRAINT fk_deal_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "deal" ADD CONSTRAINT fk_deal_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- DealCondition relations
ALTER TABLE "deal_conditions" ADD CONSTRAINT fk_dealcondition_deal FOREIGN KEY (deal_id) REFERENCES "deal"(id);
ALTER TABLE "deal_conditions" ADD CONSTRAINT fk_dealcondition_product FOREIGN KEY (product_id) REFERENCES "product"(id);
ALTER TABLE "deal_conditions" ADD CONSTRAINT fk_dealcondition_brand FOREIGN KEY (brand_id) REFERENCES "brands"(id);
ALTER TABLE "deal_conditions" ADD CONSTRAINT fk_dealcondition_category FOREIGN KEY (category_id) REFERENCES "product_category"(id);
ALTER TABLE "deal_conditions" ADD CONSTRAINT fk_dealcondition_outlet_type FOREIGN KEY (outlet_type_id) REFERENCES "outlet_types"(id);
ALTER TABLE "deal_conditions" ADD CONSTRAINT fk_dealcondition_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "deal_conditions" ADD CONSTRAINT fk_dealcondition_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "deal_conditions" ADD CONSTRAINT fk_dealcondition_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "deal_conditions" ADD CONSTRAINT fk_dealcondition_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- DealReward relations
ALTER TABLE "deal_rewards" ADD CONSTRAINT fk_dealreward_deal FOREIGN KEY (deal_id) REFERENCES "deal"(id);
ALTER TABLE "deal_rewards" ADD CONSTRAINT fk_dealreward_reward_product FOREIGN KEY (reward_product_id) REFERENCES "product"(id);
ALTER TABLE "deal_rewards" ADD CONSTRAINT fk_dealreward_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "deal_rewards" ADD CONSTRAINT fk_dealreward_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "deal_rewards" ADD CONSTRAINT fk_dealreward_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "deal_rewards" ADD CONSTRAINT fk_dealreward_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- DealMixItem relations
ALTER TABLE "deal_mix_items" ADD CONSTRAINT fk_dealmixitem_deal FOREIGN KEY (deal_id) REFERENCES "deal"(id);
ALTER TABLE "deal_mix_items" ADD CONSTRAINT fk_dealmixitem_product FOREIGN KEY (product_id) REFERENCES "product"(id);
ALTER TABLE "deal_mix_items" ADD CONSTRAINT fk_dealmixitem_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "deal_mix_items" ADD CONSTRAINT fk_dealmixitem_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "deal_mix_items" ADD CONSTRAINT fk_dealmixitem_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "deal_mix_items" ADD CONSTRAINT fk_dealmixitem_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- DealSlab relations
ALTER TABLE "deal_slabs" ADD CONSTRAINT fk_dealslab_deal FOREIGN KEY (deal_id) REFERENCES "deal"(id);
ALTER TABLE "deal_slabs" ADD CONSTRAINT fk_dealslab_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "deal_slabs" ADD CONSTRAINT fk_dealslab_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "deal_slabs" ADD CONSTRAINT fk_dealslab_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "deal_slabs" ADD CONSTRAINT fk_dealslab_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- DealScopeFilter relations
ALTER TABLE "deal_scope_fliters" ADD CONSTRAINT fk_dealscopefilter_deal FOREIGN KEY (deal_id) REFERENCES "deal"(id);
ALTER TABLE "deal_scope_fliters" ADD CONSTRAINT fk_dealscopefilter_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "deal_scope_fliters" ADD CONSTRAINT fk_dealscopefilter_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "deal_scope_fliters" ADD CONSTRAINT fk_dealscopefilter_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "deal_scope_fliters" ADD CONSTRAINT fk_dealscopefilter_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- DealException relations
ALTER TABLE "deal_exceptions" ADD CONSTRAINT fk_dealexception_deal FOREIGN KEY (deal_id) REFERENCES "deal"(id);
ALTER TABLE "deal_exceptions" ADD CONSTRAINT fk_dealexception_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "deal_exceptions" ADD CONSTRAINT fk_dealexception_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "deal_exceptions" ADD CONSTRAINT fk_dealexception_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "deal_exceptions" ADD CONSTRAINT fk_dealexception_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- DealCustomerSegment relations
ALTER TABLE "deal_customer_segments" ADD CONSTRAINT fk_dealcustomersegment_deal FOREIGN KEY (deal_id) REFERENCES "deal"(id);
ALTER TABLE "deal_customer_segments" ADD CONSTRAINT fk_dealcustomersegment_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "deal_customer_segments" ADD CONSTRAINT fk_dealcustomersegment_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "deal_customer_segments" ADD CONSTRAINT fk_dealcustomersegment_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "deal_customer_segments" ADD CONSTRAINT fk_dealcustomersegment_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- StockEntry relations
ALTER TABLE "stock_entry" ADD CONSTRAINT fk_stockentry_warehouse FOREIGN KEY (warehouse_id) REFERENCES "warehouse"(id);
ALTER TABLE "stock_entry" ADD CONSTRAINT fk_stockentry_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "stock_entry" ADD CONSTRAINT fk_stockentry_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "stock_entry" ADD CONSTRAINT fk_stockentry_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "stock_entry" ADD CONSTRAINT fk_stockentry_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- StockEntryLine relations
ALTER TABLE "stock_entry_lines" ADD CONSTRAINT fk_stockentryline_stock_entry FOREIGN KEY (stock_entry_id) REFERENCES "stock_entry"(id);
ALTER TABLE "stock_entry_lines" ADD CONSTRAINT fk_stockentryline_product FOREIGN KEY (product_id) REFERENCES "product"(id);
ALTER TABLE "stock_entry_lines" ADD CONSTRAINT fk_stockentryline_uom FOREIGN KEY (uom_id) REFERENCES "units_of_measure"(id);
ALTER TABLE "stock_entry_lines" ADD CONSTRAINT fk_stockentryline_inventory_batch FOREIGN KEY (inventory_batch_id) REFERENCES "inventory_batch"(id);
ALTER TABLE "stock_entry_lines" ADD CONSTRAINT fk_stockentryline_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "stock_entry_lines" ADD CONSTRAINT fk_stockentryline_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "stock_entry_lines" ADD CONSTRAINT fk_stockentryline_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "stock_entry_lines" ADD CONSTRAINT fk_stockentryline_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- ShelfRentAgreement relations
ALTER TABLE "shelf_rent_agreements" ADD CONSTRAINT fk_shelfrentagreement_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "shelf_rent_agreements" ADD CONSTRAINT fk_shelfrentagreement_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "shelf_rent_agreements" ADD CONSTRAINT fk_shelfrentagreement_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "shelf_rent_agreements" ADD CONSTRAINT fk_shelfrentagreement_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- ShelfRentTarget relations
ALTER TABLE "shelf_rent_targets" ADD CONSTRAINT fk_shelfrenttarget_shelf_rent_agreements FOREIGN KEY (shelf_rent_agreements_id) REFERENCES "shelf_rent_agreements"(id);
ALTER TABLE "shelf_rent_targets" ADD CONSTRAINT fk_shelfrenttarget_outlet FOREIGN KEY (outlet_id) REFERENCES "outlet"(id);
ALTER TABLE "shelf_rent_targets" ADD CONSTRAINT fk_shelfrenttarget_product FOREIGN KEY (product_id) REFERENCES "product"(id);
ALTER TABLE "shelf_rent_targets" ADD CONSTRAINT fk_shelfrenttarget_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "shelf_rent_targets" ADD CONSTRAINT fk_shelfrenttarget_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "shelf_rent_targets" ADD CONSTRAINT fk_shelfrenttarget_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "shelf_rent_targets" ADD CONSTRAINT fk_shelfrenttarget_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- ShelfRentRule relations
ALTER TABLE "shelf_rent_rules" ADD CONSTRAINT fk_shelfrentrule_shelf_rent_agreements FOREIGN KEY (shelf_rent_agreements_id) REFERENCES "shelf_rent_agreements"(id);
ALTER TABLE "shelf_rent_rules" ADD CONSTRAINT fk_shelfrentrule_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "shelf_rent_rules" ADD CONSTRAINT fk_shelfrentrule_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "shelf_rent_rules" ADD CONSTRAINT fk_shelfrentrule_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "shelf_rent_rules" ADD CONSTRAINT fk_shelfrentrule_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- ShelfRentAchievement relations
ALTER TABLE "shelf_rent_achievements" ADD CONSTRAINT fk_shelfrentachievement_shelf_rent_agreements FOREIGN KEY (shelf_rent_agreements_id) REFERENCES "shelf_rent_agreements"(id);
ALTER TABLE "shelf_rent_achievements" ADD CONSTRAINT fk_shelfrentachievement_shelf_rent_targets FOREIGN KEY (shelf_rent_targets_id) REFERENCES "shelf_rent_targets"(id);
ALTER TABLE "shelf_rent_achievements" ADD CONSTRAINT fk_shelfrentachievement_outlet FOREIGN KEY (outlet_id) REFERENCES "outlet"(id);
ALTER TABLE "shelf_rent_achievements" ADD CONSTRAINT fk_shelfrentachievement_product FOREIGN KEY (product_id) REFERENCES "product"(id);
ALTER TABLE "shelf_rent_achievements" ADD CONSTRAINT fk_shelfrentachievement_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "shelf_rent_achievements" ADD CONSTRAINT fk_shelfrentachievement_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "shelf_rent_achievements" ADD CONSTRAINT fk_shelfrentachievement_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "shelf_rent_achievements" ADD CONSTRAINT fk_shelfrentachievement_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- ShelfRentPayment relations
ALTER TABLE "shelf_rent_payments" ADD CONSTRAINT fk_shelfrentpayment_shelf_rent_agreements FOREIGN KEY (shelf_rent_agreements_id) REFERENCES "shelf_rent_agreements"(id);
ALTER TABLE "shelf_rent_payments" ADD CONSTRAINT fk_shelfrentpayment_shelf_rent_targets FOREIGN KEY (shelf_rent_targets_id) REFERENCES "shelf_rent_targets"(id);
ALTER TABLE "shelf_rent_payments" ADD CONSTRAINT fk_shelfrentpayment_outlet FOREIGN KEY (outlet_id) REFERENCES "outlet"(id);
ALTER TABLE "shelf_rent_payments" ADD CONSTRAINT fk_shelfrentpayment_product FOREIGN KEY (product_id) REFERENCES "product"(id);
ALTER TABLE "shelf_rent_payments" ADD CONSTRAINT fk_shelfrentpayment_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "shelf_rent_payments" ADD CONSTRAINT fk_shelfrentpayment_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "shelf_rent_payments" ADD CONSTRAINT fk_shelfrentpayment_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "shelf_rent_payments" ADD CONSTRAINT fk_shelfrentpayment_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- OutletStockCount relations
ALTER TABLE "outlet_stock_counts" ADD CONSTRAINT fk_outletstockcount_outlet FOREIGN KEY (outlet_id) REFERENCES "outlet"(id);
ALTER TABLE "outlet_stock_counts" ADD CONSTRAINT fk_outletstockcount_salesman FOREIGN KEY (salesman_id) REFERENCES "users"(id);
ALTER TABLE "outlet_stock_counts" ADD CONSTRAINT fk_outletstockcount_route FOREIGN KEY (route_id) REFERENCES "route"(id);
ALTER TABLE "outlet_stock_counts" ADD CONSTRAINT fk_outletstockcount_visit_schedule_entries FOREIGN KEY (visit_schedule_entries_id) REFERENCES "visit_schedule_entry"(id);
ALTER TABLE "outlet_stock_counts" ADD CONSTRAINT fk_outletstockcount_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "outlet_stock_counts" ADD CONSTRAINT fk_outletstockcount_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "outlet_stock_counts" ADD CONSTRAINT fk_outletstockcount_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "outlet_stock_counts" ADD CONSTRAINT fk_outletstockcount_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- OutletStockCountLine relations
ALTER TABLE "outlet_stock_count_lines" ADD CONSTRAINT fk_outletstockcountline_outlet_stock_counts FOREIGN KEY (outlet_stock_counts_id) REFERENCES "outlet_stock_counts"(id);
ALTER TABLE "outlet_stock_count_lines" ADD CONSTRAINT fk_outletstockcountline_product FOREIGN KEY (product_id) REFERENCES "product"(id);
ALTER TABLE "outlet_stock_count_lines" ADD CONSTRAINT fk_outletstockcountline_uom FOREIGN KEY (uom_id) REFERENCES "units_of_measure"(id);
ALTER TABLE "outlet_stock_count_lines" ADD CONSTRAINT fk_outletstockcountline_inventory_batch FOREIGN KEY (iventory_batch_id) REFERENCES "inventory_batch"(id);
ALTER TABLE "outlet_stock_count_lines" ADD CONSTRAINT fk_outletstockcountline_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "outlet_stock_count_lines" ADD CONSTRAINT fk_outletstockcountline_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "outlet_stock_count_lines" ADD CONSTRAINT fk_outletstockcountline_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "outlet_stock_count_lines" ADD CONSTRAINT fk_outletstockcountline_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- CompetitiveBrand relations
ALTER TABLE "competitive_brands" ADD CONSTRAINT fk_competitivebrand_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "competitive_brands" ADD CONSTRAINT fk_competitivebrand_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "competitive_brands" ADD CONSTRAINT fk_competitivebrand_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "competitive_brands" ADD CONSTRAINT fk_competitivebrand_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- CompetitiveProduct relations
ALTER TABLE "competitive_products" ADD CONSTRAINT fk_competitiveproduct_competitive_brand FOREIGN KEY (competitive_brand_id) REFERENCES "competitive_brands"(id);
ALTER TABLE "competitive_products" ADD CONSTRAINT fk_competitiveproduct_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "competitive_products" ADD CONSTRAINT fk_competitiveproduct_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "competitive_products" ADD CONSTRAINT fk_competitiveproduct_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "competitive_products" ADD CONSTRAINT fk_competitiveproduct_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- CompetitivePresenceLog relations
ALTER TABLE "competitive_presence_log" ADD CONSTRAINT fk_competitivepresencelog_outlet FOREIGN KEY (outlet_id) REFERENCES "outlet"(id);
ALTER TABLE "competitive_presence_log" ADD CONSTRAINT fk_competitivepresencelog_route FOREIGN KEY (route_id) REFERENCES "route"(id);
ALTER TABLE "competitive_presence_log" ADD CONSTRAINT fk_competitivepresencelog_salesman FOREIGN KEY (salesman_id) REFERENCES "users"(id);
ALTER TABLE "competitive_presence_log" ADD CONSTRAINT fk_competitivepresencelog_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "competitive_presence_log" ADD CONSTRAINT fk_competitivepresencelog_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "competitive_presence_log" ADD CONSTRAINT fk_competitivepresencelog_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "competitive_presence_log" ADD CONSTRAINT fk_competitivepresencelog_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- CompetitivePresenceItem relations
ALTER TABLE "competitive_presence_item" ADD CONSTRAINT fk_competitivepresenceitem_competitive_presence_logs FOREIGN KEY (competitive_presence_logs_id) REFERENCES "competitive_presence_log"(id);
ALTER TABLE "competitive_presence_item" ADD CONSTRAINT fk_competitivepresenceitem_product FOREIGN KEY (product_id) REFERENCES "product"(id);
ALTER TABLE "competitive_presence_item" ADD CONSTRAINT fk_competitivepresenceitem_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "competitive_presence_item" ADD CONSTRAINT fk_competitivepresenceitem_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "competitive_presence_item" ADD CONSTRAINT fk_competitivepresenceitem_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "competitive_presence_item" ADD CONSTRAINT fk_competitivepresenceitem_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- SalesmanAttendance relations
ALTER TABLE "salesman_attendance" ADD CONSTRAINT fk_salesmanattendance_salesman FOREIGN KEY (salesman_id) REFERENCES "users"(id);
ALTER TABLE "salesman_attendance" ADD CONSTRAINT fk_salesmanattendance_route FOREIGN KEY (route_id) REFERENCES "route"(id);
ALTER TABLE "salesman_attendance" ADD CONSTRAINT fk_salesmanattendance_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "salesman_attendance" ADD CONSTRAINT fk_salesmanattendance_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "salesman_attendance" ADD CONSTRAINT fk_salesmanattendance_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "salesman_attendance" ADD CONSTRAINT fk_salesmanattendance_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- SalesmanLiveLocation relations
ALTER TABLE "salesman_live_locations" ADD CONSTRAINT fk_salesmanlivelocation_salesman FOREIGN KEY (salesman_id) REFERENCES "users"(id);
ALTER TABLE "salesman_live_locations" ADD CONSTRAINT fk_salesmanlivelocation_route FOREIGN KEY (route_id) REFERENCES "route"(id);
ALTER TABLE "salesman_live_locations" ADD CONSTRAINT fk_salesmanlivelocation_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "salesman_live_locations" ADD CONSTRAINT fk_salesmanlivelocation_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "salesman_live_locations" ADD CONSTRAINT fk_salesmanlivelocation_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "salesman_live_locations" ADD CONSTRAINT fk_salesmanlivelocation_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- SalesmanTrip relations
ALTER TABLE "salesman_trip" ADD CONSTRAINT fk_salesmantrip_salesman FOREIGN KEY (salesman_id) REFERENCES "users"(id);
ALTER TABLE "salesman_trip" ADD CONSTRAINT fk_salesmantrip_route FOREIGN KEY (route_id) REFERENCES "route"(id);
ALTER TABLE "salesman_trip" ADD CONSTRAINT fk_salesmantrip_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "salesman_trip" ADD CONSTRAINT fk_salesmantrip_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "salesman_trip" ADD CONSTRAINT fk_salesmantrip_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "salesman_trip" ADD CONSTRAINT fk_salesmantrip_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- SalesmanTripOdometerLog relations
ALTER TABLE "salesman_trip_odometer_logs" ADD CONSTRAINT fk_salesmantripodometerlog_salesman FOREIGN KEY (salesman_id) REFERENCES "users"(id);
ALTER TABLE "salesman_trip_odometer_logs" ADD CONSTRAINT fk_salesmantripodometerlog_route FOREIGN KEY (route_id) REFERENCES "route"(id);
ALTER TABLE "salesman_trip_odometer_logs" ADD CONSTRAINT fk_salesmantripodometerlog_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "salesman_trip_odometer_logs" ADD CONSTRAINT fk_salesmantripodometerlog_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "salesman_trip_odometer_logs" ADD CONSTRAINT fk_salesmantripodometerlog_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "salesman_trip_odometer_logs" ADD CONSTRAINT fk_salesmantripodometerlog_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- GeoFenceZone relations
ALTER TABLE "geo_fence_zones" ADD CONSTRAINT fk_geofencezone_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "geo_fence_zones" ADD CONSTRAINT fk_geofencezone_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "geo_fence_zones" ADD CONSTRAINT fk_geofencezone_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "geo_fence_zones" ADD CONSTRAINT fk_geofencezone_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- GeoFenceViolation relations
ALTER TABLE "geo_fence_violations" ADD CONSTRAINT fk_geofenceviolation_geo_fence FOREIGN KEY (geo_fence_id) REFERENCES "geo_fence_zones"(id);
ALTER TABLE "geo_fence_violations" ADD CONSTRAINT fk_geofenceviolation_salesman FOREIGN KEY (salesman_id) REFERENCES "users"(id);
ALTER TABLE "geo_fence_violations" ADD CONSTRAINT fk_geofenceviolation_warehouse FOREIGN KEY (company_id, van_id) REFERENCES "warehouse"(company_id, id);
ALTER TABLE "geo_fence_violations" ADD CONSTRAINT fk_geofenceviolation_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "geo_fence_violations" ADD CONSTRAINT fk_geofenceviolation_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "geo_fence_violations" ADD CONSTRAINT fk_geofenceviolation_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "geo_fence_violations" ADD CONSTRAINT fk_geofenceviolation_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- GeoFenceAssignment relations
ALTER TABLE "geo_fence_assignments" ADD CONSTRAINT fk_geofenceassignment_geo_fence FOREIGN KEY (geo_fence_id) REFERENCES "geo_fence_zones"(id);
ALTER TABLE "geo_fence_assignments" ADD CONSTRAINT fk_geofenceassignment_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "geo_fence_assignments" ADD CONSTRAINT fk_geofenceassignment_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "geo_fence_assignments" ADD CONSTRAINT fk_geofenceassignment_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "geo_fence_assignments" ADD CONSTRAINT fk_geofenceassignment_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- GLJournalEntry relations
ALTER TABLE "gl_journal_entries" ADD CONSTRAINT fk_gljournalentry_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "gl_journal_entries" ADD CONSTRAINT fk_gljournalentry_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "gl_journal_entries" ADD CONSTRAINT fk_gljournalentry_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "gl_journal_entries" ADD CONSTRAINT fk_gljournalentry_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- GLJournalLine relations
ALTER TABLE "gl_journal_lines" ADD CONSTRAINT fk_gljournalline_journal_entry FOREIGN KEY (journal_entry_id) REFERENCES "gl_journal_entries"(id);
ALTER TABLE "gl_journal_lines" ADD CONSTRAINT fk_gljournalline_cost_center FOREIGN KEY (cost_center_id) REFERENCES "gl_cost_centers"(id);
ALTER TABLE "gl_journal_lines" ADD CONSTRAINT fk_gljournalline_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "gl_journal_lines" ADD CONSTRAINT fk_gljournalline_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "gl_journal_lines" ADD CONSTRAINT fk_gljournalline_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "gl_journal_lines" ADD CONSTRAINT fk_gljournalline_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- GLAccount relations
ALTER TABLE "gl_accounts" ADD CONSTRAINT fk_glaccount_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "gl_accounts" ADD CONSTRAINT fk_glaccount_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "gl_accounts" ADD CONSTRAINT fk_glaccount_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "gl_accounts" ADD CONSTRAINT fk_glaccount_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- GLAccountMapping relations
ALTER TABLE "gl_account_mappings" ADD CONSTRAINT fk_glaccountmapping_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "gl_account_mappings" ADD CONSTRAINT fk_glaccountmapping_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "gl_account_mappings" ADD CONSTRAINT fk_glaccountmapping_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "gl_account_mappings" ADD CONSTRAINT fk_glaccountmapping_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- GLCostCenter relations
ALTER TABLE "gl_cost_centers" ADD CONSTRAINT fk_glcostcenter_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "gl_cost_centers" ADD CONSTRAINT fk_glcostcenter_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "gl_cost_centers" ADD CONSTRAINT fk_glcostcenter_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "gl_cost_centers" ADD CONSTRAINT fk_glcostcenter_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);

-- GLTransactionAudit relations
ALTER TABLE "gl_transaction_audit" ADD CONSTRAINT fk_gltransactionaudit_journal_entry FOREIGN KEY (journal_entry_id) REFERENCES "gl_journal_entries"(id);
ALTER TABLE "gl_transaction_audit" ADD CONSTRAINT fk_gltransactionaudit_status FOREIGN KEY (status_id) REFERENCES "statuses"(id);
ALTER TABLE "gl_transaction_audit" ADD CONSTRAINT fk_gltransactionaudit_created_by FOREIGN KEY (created_by) REFERENCES "users"(id);
ALTER TABLE "gl_transaction_audit" ADD CONSTRAINT fk_gltransactionaudit_updated_by FOREIGN KEY (updated_by) REFERENCES "users"(id);
ALTER TABLE "gl_transaction_audit" ADD CONSTRAINT fk_gltransactionaudit_deleted_by FOREIGN KEY (deleted_by) REFERENCES "users"(id);
