-- ERP1 Enterprise Expansion Rollback (2026-02-08)
USE erp1;
SET FOREIGN_KEY_CHECKS = 0;

-- Drop foreign keys added by expansion
ALTER TABLE companies
  DROP FOREIGN KEY fk_companies_parent,
  DROP FOREIGN KEY fk_companies_secondary_currency,
  DROP FOREIGN KEY fk_companies_default_wh,
  DROP FOREIGN KEY fk_companies_default_bank,
  DROP FOREIGN KEY fk_companies_bank_currency;

ALTER TABLE customers
  DROP FOREIGN KEY fk_customers_parent,
  DROP FOREIGN KEY fk_customers_bank_currency;

ALTER TABLE vendors
  DROP FOREIGN KEY fk_vendors_parent,
  DROP FOREIGN KEY fk_vendors_bank_currency,
  DROP FOREIGN KEY fk_vendors_default_bank;

ALTER TABLE contacts
  DROP FOREIGN KEY fk_contacts_reporting_manager,
  DROP FOREIGN KEY fk_contacts_user,
  DROP FOREIGN KEY fk_contacts_account_owner,
  DROP FOREIGN KEY fk_contacts_sales_rep,
  DROP FOREIGN KEY fk_contacts_account_manager,
  DROP FOREIGN KEY fk_contacts_approval_currency;

ALTER TABLE rfqs
  DROP FOREIGN KEY fk_rfq_requester,
  DROP FOREIGN KEY fk_rfq_buyer,
  DROP FOREIGN KEY fk_rfq_primary_vendor,
  DROP FOREIGN KEY fk_rfq_vendor_contact,
  DROP FOREIGN KEY fk_rfq_awarded_vendor,
  DROP FOREIGN KEY fk_rfq_awarded_by,
  DROP FOREIGN KEY fk_rfq_bid_currency,
  DROP FOREIGN KEY fk_rfq_invoice_currency;

ALTER TABLE rfq_items
  DROP FOREIGN KEY fk_rfqitem_gl,
  DROP FOREIGN KEY fk_rfqitem_cost_center;

ALTER TABLE rfq_vendor_quotes
  DROP FOREIGN KEY fk_rfqquote_currency;

ALTER TABLE sales_quotations
  DROP FOREIGN KEY fk_sq_salesperson,
  DROP FOREIGN KEY fk_sq_warehouse;

ALTER TABLE sales_quotation_items
  DROP FOREIGN KEY fk_sqi_warehouse,
  DROP FOREIGN KEY fk_sqi_revenue_account,
  DROP FOREIGN KEY fk_sqi_cost_center;

ALTER TABLE sales_orders
  DROP FOREIGN KEY fk_so_salesperson,
  DROP FOREIGN KEY fk_so_warehouse;

ALTER TABLE sales_order_items
  DROP FOREIGN KEY fk_soi_warehouse,
  DROP FOREIGN KEY fk_soi_revenue_account,
  DROP FOREIGN KEY fk_soi_cost_center;

ALTER TABLE delivery_notes
  DROP FOREIGN KEY fk_dn_warehouse;

ALTER TABLE delivery_note_items
  DROP FOREIGN KEY fk_dni_warehouse;

ALTER TABLE invoices
  DROP FOREIGN KEY fk_inv_salesperson,
  DROP FOREIGN KEY fk_inv_warehouse;

ALTER TABLE invoice_items
  DROP FOREIGN KEY fk_invi_revenue_account,
  DROP FOREIGN KEY fk_invi_cost_center;

ALTER TABLE employees
  DROP FOREIGN KEY fk_emp_reporting_manager;

ALTER TABLE payroll_items
  DROP FOREIGN KEY fk_pi_cost_center,
  DROP FOREIGN KEY fk_pi_currency;

ALTER TABLE leave_requests
  DROP FOREIGN KEY fk_lr_approver;

ALTER TABLE employee_travel_expenses
  DROP FOREIGN KEY fk_ete_currency;

ALTER TABLE employee_travel_advances
  DROP FOREIGN KEY fk_eta_currency;

ALTER TABLE vehicle_maintenance
  DROP FOREIGN KEY fk_vm_vendor,
  DROP FOREIGN KEY fk_vm_currency;

ALTER TABLE vehicle_expenses
  DROP FOREIGN KEY fk_ve_vendor,
  DROP FOREIGN KEY fk_ve_currency,
  DROP FOREIGN KEY fk_ve_cost_center;

ALTER TABLE vehicle_reminders
  DROP FOREIGN KEY fk_vr_assigned_user;

ALTER TABLE vehicle_documents
  DROP FOREIGN KEY fk_vd_vehicle,
  DROP FOREIGN KEY fk_vd_attachment;

ALTER TABLE vehicle_incidents
  DROP FOREIGN KEY fk_vi_vehicle,
  DROP FOREIGN KEY fk_vi_driver;

ALTER TABLE attachments
  DROP FOREIGN KEY fk_att_verified_by,
  DROP FOREIGN KEY fk_att_approved_by,
  DROP FOREIGN KEY fk_att_parent,
  DROP FOREIGN KEY fk_att_superseded_by;

-- Drop columns added by expansion
ALTER TABLE companies
  DROP COLUMN company_code,
  DROP COLUMN trade_name,
  DROP COLUMN company_type,
  DROP COLUMN industry,
  DROP COLUMN parent_company_id,
  DROP COLUMN is_subsidiary,
  DROP COLUMN company_status,
  DROP COLUMN legal_jurisdiction_country,
  DROP COLUMN cr_issue_date,
  DROP COLUMN cr_expiry_date,
  DROP COLUMN cr_issuing_authority,
  DROP COLUMN chamber_membership_no,
  DROP COLUMN chamber_expiry_date,
  DROP COLUMN unified_national_no,
  DROP COLUMN misa_license_no,
  DROP COLUMN misa_license_expiry,
  DROP COLUMN aoa_reference,
  DROP COLUMN intl_registration_no,
  DROP COLUMN incorporation_date,
  DROP COLUMN incorporation_country,
  DROP COLUMN incorporation_authority,
  DROP COLUMN vat_effective_date,
  DROP COLUMN vat_status,
  DROP COLUMN zatca_registration_status,
  DROP COLUMN zakat_file_no,
  DROP COLUMN tax_identification_no,
  DROP COLUMN withholding_tax_applicable,
  DROP COLUMN zakat_tax_percentage,
  DROP COLUMN gst_number,
  DROP COLUMN sales_tax_number,
  DROP COLUMN corporate_tax_number,
  DROP COLUMN tax_residency_country,
  DROP COLUMN double_tax_treaty_applicable,
  DROP COLUMN national_address_id,
  DROP COLUMN building_no,
  DROP COLUMN street_name,
  DROP COLUMN district,
  DROP COLUMN city,
  DROP COLUMN postal_code,
  DROP COLUMN additional_no,
  DROP COLUMN short_address,
  DROP COLUMN address_type,
  DROP COLUMN intl_address_line1,
  DROP COLUMN intl_address_line2,
  DROP COLUMN intl_city,
  DROP COLUMN intl_state,
  DROP COLUMN intl_postal_code,
  DROP COLUMN intl_country,
  DROP COLUMN intl_address_type,
  DROP COLUMN phone_main,
  DROP COLUMN phone_secondary,
  DROP COLUMN mobile,
  DROP COLUMN fax,
  DROP COLUMN email,
  DROP COLUMN support_email,
  DROP COLUMN website,
  DROP COLUMN social_links,
  DROP COLUMN bank_name,
  DROP COLUMN bank_branch,
  DROP COLUMN bank_account_name,
  DROP COLUMN bank_account_number,
  DROP COLUMN iban,
  DROP COLUMN swift_code,
  DROP COLUMN bank_currency_code,
  DROP COLUMN bank_country,
  DROP COLUMN default_bank_account_id,
  DROP COLUMN owner_name,
  DROP COLUMN owner_nationality,
  DROP COLUMN owner_id_no,
  DROP COLUMN ownership_percentage,
  DROP COLUMN board_of_directors,
  DROP COLUMN general_manager_name,
  DROP COLUMN authorized_signatory_name,
  DROP COLUMN signatory_id_no,
  DROP COLUMN signatory_title,
  DROP COLUMN power_of_attorney_ref,
  DROP COLUMN secondary_currency_code,
  DROP COLUMN fiscal_year_start,
  DROP COLUMN fiscal_year_end,
  DROP COLUMN accounting_standard,
  DROP COLUMN chart_of_accounts_ref,
  DROP COLUMN cost_center_structure,
  DROP COLUMN profit_center_structure,
  DROP COLUMN payment_terms,
  DROP COLUMN credit_limit,
  DROP COLUMN gosi_no,
  DROP COLUMN gosi_office,
  DROP COLUMN labor_office_no,
  DROP COLUMN saudization_level,
  DROP COLUMN establishment_id,
  DROP COLUMN employee_capacity,
  DROP COLUMN warehouse_locations,
  DROP COLUMN default_warehouse_id,
  DROP COLUMN importer_code,
  DROP COLUMN exporter_code,
  DROP COLUMN customs_reg_no,
  DROP COLUMN port_of_entry,
  DROP COLUMN incoterms,
  DROP COLUMN created_by,
  DROP COLUMN updated_by,
  DROP COLUMN approved_by,
  DROP COLUMN approval_date,
  DROP COLUMN is_active,
  DROP COLUMN blocked_sales,
  DROP COLUMN blocked_purchasing,
  DROP COLUMN blocked_payments,
  DROP COLUMN compliance_flag,
  DROP COLUMN risk_category,
  DROP COLUMN print_header_accent,
  DROP COLUMN print_header_logo_size,
  DROP COLUMN print_header_show_logo;

ALTER TABLE customers
  DROP COLUMN customer_code,
  DROP COLUMN trade_name,
  DROP COLUMN company_type,
  DROP COLUMN industry,
  DROP COLUMN parent_customer_id,
  DROP COLUMN is_subsidiary,
  DROP COLUMN customer_status,
  DROP COLUMN legal_jurisdiction_country,
  DROP COLUMN cr_issue_date,
  DROP COLUMN cr_expiry_date,
  DROP COLUMN cr_issuing_authority,
  DROP COLUMN chamber_membership_no,
  DROP COLUMN chamber_expiry_date,
  DROP COLUMN unified_national_no,
  DROP COLUMN misa_license_no,
  DROP COLUMN misa_license_expiry,
  DROP COLUMN aoa_reference,
  DROP COLUMN intl_registration_no,
  DROP COLUMN incorporation_date,
  DROP COLUMN incorporation_country,
  DROP COLUMN incorporation_authority,
  DROP COLUMN vat_effective_date,
  DROP COLUMN vat_status,
  DROP COLUMN zatca_registration_status,
  DROP COLUMN zakat_file_no,
  DROP COLUMN tax_identification_no,
  DROP COLUMN withholding_tax_applicable,
  DROP COLUMN zakat_tax_percentage,
  DROP COLUMN gst_number,
  DROP COLUMN sales_tax_number,
  DROP COLUMN corporate_tax_number,
  DROP COLUMN tax_residency_country,
  DROP COLUMN double_tax_treaty_applicable,
  DROP COLUMN national_address_id,
  DROP COLUMN building_no,
  DROP COLUMN street_name,
  DROP COLUMN district,
  DROP COLUMN city,
  DROP COLUMN postal_code,
  DROP COLUMN additional_no,
  DROP COLUMN short_address,
  DROP COLUMN address_type,
  DROP COLUMN intl_address_line1,
  DROP COLUMN intl_address_line2,
  DROP COLUMN intl_city,
  DROP COLUMN intl_state,
  DROP COLUMN intl_postal_code,
  DROP COLUMN intl_country,
  DROP COLUMN intl_address_type,
  DROP COLUMN phone_main,
  DROP COLUMN phone_secondary,
  DROP COLUMN mobile,
  DROP COLUMN fax,
  DROP COLUMN email,
  DROP COLUMN support_email,
  DROP COLUMN website,
  DROP COLUMN social_links,
  DROP COLUMN bank_name,
  DROP COLUMN bank_branch,
  DROP COLUMN bank_account_name,
  DROP COLUMN bank_account_number,
  DROP COLUMN iban,
  DROP COLUMN swift_code,
  DROP COLUMN bank_currency_code,
  DROP COLUMN bank_country,
  DROP COLUMN default_bank_flag,
  DROP COLUMN owner_name,
  DROP COLUMN owner_nationality,
  DROP COLUMN owner_id_no,
  DROP COLUMN ownership_percentage,
  DROP COLUMN board_of_directors,
  DROP COLUMN general_manager_name,
  DROP COLUMN authorized_signatory_name,
  DROP COLUMN signatory_id_no,
  DROP COLUMN signatory_title,
  DROP COLUMN power_of_attorney_ref,
  DROP COLUMN customer_group,
  DROP COLUMN customer_segment,
  DROP COLUMN bill_to_party,
  DROP COLUMN ship_to_party,
  DROP COLUMN payer,
  DROP COLUMN end_customer_name,
  DROP COLUMN accounting_standard,
  DROP COLUMN payment_terms,
  DROP COLUMN credit_exposure,
  DROP COLUMN gosi_no,
  DROP COLUMN importer_code,
  DROP COLUMN exporter_code,
  DROP COLUMN customs_reg_no,
  DROP COLUMN port_of_entry,
  DROP COLUMN incoterms,
  DROP COLUMN created_by,
  DROP COLUMN updated_by,
  DROP COLUMN approved_by,
  DROP COLUMN approval_date,
  DROP COLUMN blocked_sales,
  DROP COLUMN blocked_purchasing,
  DROP COLUMN blocked_payments,
  DROP COLUMN compliance_flag,
  DROP COLUMN risk_category,
  DROP COLUMN default_version_no,
  DROP COLUMN default_reference_doc_no,
  DROP COLUMN default_shipping_method,
  DROP COLUMN default_delivery_priority,
  DROP COLUMN default_delivery_terms;

ALTER TABLE vendors
  DROP COLUMN vendor_code,
  DROP COLUMN trade_name,
  DROP COLUMN company_type,
  DROP COLUMN industry,
  DROP COLUMN parent_vendor_id,
  DROP COLUMN is_subsidiary,
  DROP COLUMN vendor_status,
  DROP COLUMN legal_jurisdiction_country,
  DROP COLUMN cr_issue_date,
  DROP COLUMN cr_expiry_date,
  DROP COLUMN cr_issuing_authority,
  DROP COLUMN chamber_membership_no,
  DROP COLUMN chamber_expiry_date,
  DROP COLUMN unified_national_no,
  DROP COLUMN misa_license_no,
  DROP COLUMN misa_license_expiry,
  DROP COLUMN aoa_reference,
  DROP COLUMN intl_registration_no,
  DROP COLUMN incorporation_date,
  DROP COLUMN incorporation_country,
  DROP COLUMN incorporation_authority,
  DROP COLUMN vat_effective_date,
  DROP COLUMN vat_status,
  DROP COLUMN zatca_registration_status,
  DROP COLUMN zakat_file_no,
  DROP COLUMN tax_identification_no,
  DROP COLUMN withholding_tax_applicable,
  DROP COLUMN zakat_tax_percentage,
  DROP COLUMN gst_number,
  DROP COLUMN sales_tax_number,
  DROP COLUMN corporate_tax_number,
  DROP COLUMN tax_residency_country,
  DROP COLUMN double_tax_treaty_applicable,
  DROP COLUMN national_address_id,
  DROP COLUMN building_no,
  DROP COLUMN street_name,
  DROP COLUMN district,
  DROP COLUMN city,
  DROP COLUMN postal_code,
  DROP COLUMN additional_no,
  DROP COLUMN short_address,
  DROP COLUMN address_type,
  DROP COLUMN intl_address_line1,
  DROP COLUMN intl_address_line2,
  DROP COLUMN intl_city,
  DROP COLUMN intl_state,
  DROP COLUMN intl_postal_code,
  DROP COLUMN intl_country,
  DROP COLUMN intl_address_type,
  DROP COLUMN phone_main,
  DROP COLUMN phone_secondary,
  DROP COLUMN mobile,
  DROP COLUMN fax,
  DROP COLUMN email,
  DROP COLUMN support_email,
  DROP COLUMN website,
  DROP COLUMN social_links,
  DROP COLUMN bank_branch,
  DROP COLUMN bank_account_name,
  DROP COLUMN bank_account_number,
  DROP COLUMN swift_code,
  DROP COLUMN bank_currency_code,
  DROP COLUMN bank_country,
  DROP COLUMN default_bank_flag,
  DROP COLUMN default_bank_account_id,
  DROP COLUMN owner_name,
  DROP COLUMN owner_nationality,
  DROP COLUMN owner_id_no,
  DROP COLUMN ownership_percentage,
  DROP COLUMN board_of_directors,
  DROP COLUMN general_manager_name,
  DROP COLUMN authorized_signatory_name,
  DROP COLUMN signatory_id_no,
  DROP COLUMN signatory_title,
  DROP COLUMN power_of_attorney_ref,
  DROP COLUMN vendor_group,
  DROP COLUMN vendor_segment,
  DROP COLUMN payment_terms,
  DROP COLUMN credit_exposure,
  DROP COLUMN importer_code,
  DROP COLUMN exporter_code,
  DROP COLUMN customs_reg_no,
  DROP COLUMN port_of_entry,
  DROP COLUMN incoterms,
  DROP COLUMN created_by,
  DROP COLUMN updated_by,
  DROP COLUMN approved_by,
  DROP COLUMN approval_date,
  DROP COLUMN blocked_sales,
  DROP COLUMN blocked_purchasing,
  DROP COLUMN blocked_payments,
  DROP COLUMN compliance_flag,
  DROP COLUMN risk_category,
  DROP COLUMN default_po_type,
  DROP COLUMN default_price_control_type,
  DROP COLUMN default_invoice_matching_type,
  DROP COLUMN default_invoice_matching_rule,
  DROP COLUMN default_approval_workflow_id,
  DROP COLUMN default_nda_reference,
  DROP COLUMN default_delivery_address_id,
  DROP COLUMN tags,
  DROP COLUMN kanban_rank;

ALTER TABLE contacts
  DROP COLUMN uuid,
  DROP COLUMN contact_type,
  DROP COLUMN contact_role,
  DROP COLUMN status,
  DROP COLUMN priority_level,
  DROP COLUMN confidentiality_level,
  DROP COLUMN first_name,
  DROP COLUMN middle_name,
  DROP COLUMN last_name,
  DROP COLUMN full_name,
  DROP COLUMN name_ar_full,
  DROP COLUMN gender,
  DROP COLUMN date_of_birth,
  DROP COLUMN nationality,
  DROP COLUMN preferred_language,
  DROP COLUMN title,
  DROP COLUMN national_id_number,
  DROP COLUMN iqama_number,
  DROP COLUMN passport_number,
  DROP COLUMN passport_issuing_country,
  DROP COLUMN passport_expiry_date,
  DROP COLUMN absher_registered,
  DROP COLUMN government_id_type,
  DROP COLUMN government_id_number,
  DROP COLUMN id_issuing_authority,
  DROP COLUMN id_expiry_date,
  DROP COLUMN kyc_verified,
  DROP COLUMN aml_checked,
  DROP COLUMN sanction_screened,
  DROP COLUMN pep_flag,
  DROP COLUMN department,
  DROP COLUMN job_title,
  DROP COLUMN employment_type,
  DROP COLUMN start_date,
  DROP COLUMN end_date,
  DROP COLUMN is_primary,
  DROP COLUMN reporting_manager_contact_id,
  DROP COLUMN preferred_contact_method,
  DROP COLUMN preferred_contact_time,
  DROP COLUMN do_not_call,
  DROP COLUMN do_not_email,
  DROP COLUMN whatsapp_consent,
  DROP COLUMN marketing_consent,
  DROP COLUMN sms_consent,
  DROP COLUMN authorized_signatory,
  DROP COLUMN approval_limit_amount,
  DROP COLUMN approval_currency_code,
  DROP COLUMN payment_approval_authority,
  DROP COLUMN contract_signing_authority,
  DROP COLUMN bank_authorization_ref,
  DROP COLUMN user_id,
  DROP COLUMN system_role,
  DROP COLUMN mfa_enabled,
  DROP COLUMN last_login_date,
  DROP COLUMN account_locked,
  DROP COLUMN relationship_type,
  DROP COLUMN account_owner_user_id,
  DROP COLUMN assigned_sales_rep_id,
  DROP COLUMN assigned_account_manager_id,
  DROP COLUMN interaction_frequency,
  DROP COLUMN last_interaction_date,
  DROP COLUMN notes,
  DROP COLUMN internal_comments,
  DROP COLUMN created_by,
  DROP COLUMN updated_by,
  DROP COLUMN approved_by,
  DROP COLUMN approval_date,
  DROP COLUMN source_system,
  DROP COLUMN data_sync_status,
  DROP COLUMN record_status,
  DROP COLUMN active_flag,
  DROP COLUMN blocked_flag,
  DROP COLUMN legal_hold_flag,
  DROP COLUMN blacklisted_flag,
  DROP COLUMN data_retention_expiry_date;

ALTER TABLE rfqs
  DROP COLUMN rfq_type,
  DROP COLUMN rfq_version,
  DROP COLUMN reference_rfq_no,
  DROP COLUMN business_unit,
  DROP COLUMN requesting_department,
  DROP COLUMN requester_id,
  DROP COLUMN buyer_id,
  DROP COLUMN approval_workflow_id,
  DROP COLUMN primary_vendor_id,
  DROP COLUMN vendor_contact_id,
  DROP COLUMN sourcing_type,
  DROP COLUMN bid_submission_method,
  DROP COLUMN bid_currency_code,
  DROP COLUMN bid_exchange_rate,
  DROP COLUMN rfq_issue_date,
  DROP COLUMN bid_submission_deadline,
  DROP COLUMN rfq_validity_date,
  DROP COLUMN expected_award_date,
  DROP COLUMN incoterms,
  DROP COLUMN delivery_location,
  DROP COLUMN payment_terms,
  DROP COLUMN tax_scheme,
  DROP COLUMN price_basis,
  DROP COLUMN contract_reference,
  DROP COLUMN nda_reference,
  DROP COLUMN header_notes,
  DROP COLUMN technical_specs_ref,
  DROP COLUMN attachments_ref,
  DROP COLUMN po_type,
  DROP COLUMN price_control_type,
  DROP COLUMN delivery_address_id,
  DROP COLUMN invoice_matching_type,
  DROP COLUMN acceptance_required,
  DROP COLUMN receipt_required,
  DROP COLUMN service_acceptance_required,
  DROP COLUMN inspection_required,
  DROP COLUMN tolerance_qty_pct,
  DROP COLUMN tolerance_price_pct,
  DROP COLUMN over_delivery_pct,
  DROP COLUMN invoice_currency_code,
  DROP COLUMN tax_code,
  DROP COLUMN vat_rate,
  DROP COLUMN withholding_tax_pct,
  DROP COLUMN invoice_matching_rule,
  DROP COLUMN retention_pct,
  DROP COLUMN milestone_billing,
  DROP COLUMN advance_payment_pct,
  DROP COLUMN budget_check,
  DROP COLUMN budget_reference,
  DROP COLUMN approval_matrix,
  DROP COLUMN risk_level,
  DROP COLUMN awarded_vendor_id,
  DROP COLUMN award_date,
  DROP COLUMN awarded_by,
  DROP COLUMN award_notes,
  DROP COLUMN rfq_closed_after_po,
  DROP COLUMN po_balance_remaining,
  DROP COLUMN invoiced_amount,
  DROP COLUMN grn_quantity,
  DROP COLUMN invoice_hold_flag;

ALTER TABLE rfq_items
  DROP COLUMN item_type,
  DROP COLUMN item_code,
  DROP COLUMN item_category,
  DROP COLUMN manufacturer,
  DROP COLUMN estimated_unit_price,
  DROP COLUMN line_total,
  DROP COLUMN price_breaks,
  DROP COLUMN discount_pct,
  DROP COLUMN discount_amount,
  DROP COLUMN delivery_date,
  DROP COLUMN lead_time_days,
  DROP COLUMN partial_delivery_allowed,
  DROP COLUMN vat_applicable,
  DROP COLUMN vat_rate,
  DROP COLUMN withholding_tax_rate,
  DROP COLUMN tax_inclusive,
  DROP COLUMN tax_code,
  DROP COLUMN gl_account_id,
  DROP COLUMN cost_center_id,
  DROP COLUMN project_code,
  DROP COLUMN asset_no,
  DROP COLUMN country_of_origin,
  DROP COLUMN hs_code,
  DROP COLUMN warranty_period,
  DROP COLUMN compliance_cert_required;

ALTER TABLE rfq_vendor_quotes
  DROP COLUMN quotation_currency_code,
  DROP COLUMN quotation_validity,
  DROP COLUMN delivery_lead_time_days,
  DROP COLUMN payment_terms,
  DROP COLUMN incoterms,
  DROP COLUMN deviation_notes,
  DROP COLUMN attachment_path,
  DROP COLUMN price_score,
  DROP COLUMN delivery_score,
  DROP COLUMN payment_term_score,
  DROP COLUMN total_score,
  DROP COLUMN rank_no,
  DROP COLUMN technical_compliance,
  DROP COLUMN qa_approval,
  DROP COLUMN engineering_approval,
  DROP COLUMN award_status,
  DROP COLUMN award_date,
  DROP COLUMN award_notes;

ALTER TABLE rfq_vendor_quote_items
  DROP COLUMN quoted_qty,
  DROP COLUMN quoted_unit_price,
  DROP COLUMN quoted_total;

ALTER TABLE sales_quotations
  DROP COLUMN document_type,
  DROP COLUMN document_status,
  DROP COLUMN version_no,
  DROP COLUMN reference_doc_no,
  DROP COLUMN business_unit,
  DROP COLUMN sales_org,
  DROP COLUMN distribution_channel,
  DROP COLUMN division,
  DROP COLUMN branch_location,
  DROP COLUMN customer_group,
  DROP COLUMN bill_to_party,
  DROP COLUMN ship_to_party,
  DROP COLUMN payer,
  DROP COLUMN end_customer,
  DROP COLUMN customer_vat_number,
  DROP COLUMN customer_cr_number,
  DROP COLUMN customer_national_address_id,
  DROP COLUMN quotation_validity_date,
  DROP COLUMN order_date,
  DROP COLUMN requested_delivery_date,
  DROP COLUMN confirmed_delivery_date,
  DROP COLUMN billing_date,
  DROP COLUMN price_list,
  DROP COLUMN payment_terms,
  DROP COLUMN credit_limit,
  DROP COLUMN credit_check_status,
  DROP COLUMN incoterms,
  DROP COLUMN delivery_terms,
  DROP COLUMN salesperson_id,
  DROP COLUMN tax_scheme,
  DROP COLUMN vat_rate,
  DROP COLUMN vat_amount,
  DROP COLUMN withholding_tax_rate,
  DROP COLUMN tax_code,
  DROP COLUMN zatca_compliance_flag,
  DROP COLUMN warehouse_id,
  DROP COLUMN shipping_method,
  DROP COLUMN delivery_priority,
  DROP COLUMN partial_delivery_allowed,
  DROP COLUMN packing_instructions,
  DROP COLUMN header_notes,
  DROP COLUMN internal_notes,
  DROP COLUMN attachments_ref,
  DROP COLUMN open_quantity,
  DROP COLUMN open_amount,
  DROP COLUMN blocked_status,
  DROP COLUMN cancellation_reason;

ALTER TABLE sales_quotation_items
  DROP COLUMN item_type,
  DROP COLUMN item_category,
  DROP COLUMN brand,
  DROP COLUMN delivered_qty,
  DROP COLUMN invoiced_qty,
  DROP COLUMN line_net_amount,
  DROP COLUMN line_gross_amount,
  DROP COLUMN warehouse_id,
  DROP COLUMN delivery_date,
  DROP COLUMN shipping_point,
  DROP COLUMN batch_no,
  DROP COLUMN serial_no,
  DROP COLUMN vat_amount,
  DROP COLUMN tax_code,
  DROP COLUMN revenue_account_id,
  DROP COLUMN cost_center_id,
  DROP COLUMN profit_center_id,
  DROP COLUMN project_code,
  DROP COLUMN price_override_flag,
  DROP COLUMN approval_required_flag,
  DROP COLUMN backorder_qty;

ALTER TABLE sales_orders
  DROP COLUMN document_type,
  DROP COLUMN document_status,
  DROP COLUMN version_no,
  DROP COLUMN reference_doc_no,
  DROP COLUMN business_unit,
  DROP COLUMN sales_org,
  DROP COLUMN distribution_channel,
  DROP COLUMN division,
  DROP COLUMN branch_location,
  DROP COLUMN customer_group,
  DROP COLUMN bill_to_party,
  DROP COLUMN ship_to_party,
  DROP COLUMN payer,
  DROP COLUMN end_customer,
  DROP COLUMN customer_vat_number,
  DROP COLUMN customer_cr_number,
  DROP COLUMN customer_national_address_id,
  DROP COLUMN quotation_validity_date,
  DROP COLUMN requested_delivery_date,
  DROP COLUMN confirmed_delivery_date,
  DROP COLUMN billing_date,
  DROP COLUMN price_list,
  DROP COLUMN payment_terms,
  DROP COLUMN credit_limit,
  DROP COLUMN credit_check_status,
  DROP COLUMN incoterms,
  DROP COLUMN delivery_terms,
  DROP COLUMN salesperson_id,
  DROP COLUMN tax_scheme,
  DROP COLUMN vat_rate,
  DROP COLUMN vat_amount,
  DROP COLUMN withholding_tax_rate,
  DROP COLUMN tax_code,
  DROP COLUMN zatca_compliance_flag,
  DROP COLUMN warehouse_id,
  DROP COLUMN shipping_method,
  DROP COLUMN delivery_priority,
  DROP COLUMN partial_delivery_allowed,
  DROP COLUMN packing_instructions,
  DROP COLUMN header_notes,
  DROP COLUMN internal_notes,
  DROP COLUMN attachments_ref,
  DROP COLUMN open_quantity,
  DROP COLUMN open_amount,
  DROP COLUMN blocked_status,
  DROP COLUMN cancellation_reason;

ALTER TABLE sales_order_items
  DROP COLUMN item_type,
  DROP COLUMN item_category,
  DROP COLUMN brand,
  DROP COLUMN invoiced_qty,
  DROP COLUMN line_net_amount,
  DROP COLUMN line_gross_amount,
  DROP COLUMN warehouse_id,
  DROP COLUMN delivery_date,
  DROP COLUMN shipping_point,
  DROP COLUMN batch_no,
  DROP COLUMN serial_no,
  DROP COLUMN vat_amount,
  DROP COLUMN tax_code,
  DROP COLUMN revenue_account_id,
  DROP COLUMN cost_center_id,
  DROP COLUMN profit_center_id,
  DROP COLUMN project_code,
  DROP COLUMN price_override_flag,
  DROP COLUMN approval_required_flag,
  DROP COLUMN backorder_qty;

ALTER TABLE delivery_notes
  DROP COLUMN delivery_status,
  DROP COLUMN pick_status,
  DROP COLUMN pack_status,
  DROP COLUMN goods_issue_date,
  DROP COLUMN carrier,
  DROP COLUMN tracking_number,
  DROP COLUMN shipping_method,
  DROP COLUMN delivery_priority,
  DROP COLUMN warehouse_id;

ALTER TABLE delivery_note_items
  DROP COLUMN warehouse_id,
  DROP COLUMN shipping_point,
  DROP COLUMN batch_no,
  DROP COLUMN serial_no;

ALTER TABLE invoices
  DROP COLUMN document_type,
  DROP COLUMN document_status,
  DROP COLUMN version_no,
  DROP COLUMN reference_doc_no,
  DROP COLUMN bill_to_party,
  DROP COLUMN ship_to_party,
  DROP COLUMN payer,
  DROP COLUMN end_customer,
  DROP COLUMN due_date,
  DROP COLUMN payment_terms,
  DROP COLUMN credit_limit,
  DROP COLUMN credit_check_status,
  DROP COLUMN incoterms,
  DROP COLUMN delivery_terms,
  DROP COLUMN salesperson_id,
  DROP COLUMN tax_scheme,
  DROP COLUMN vat_rate,
  DROP COLUMN vat_amount,
  DROP COLUMN withholding_tax_rate,
  DROP COLUMN tax_code,
  DROP COLUMN zatca_compliance_flag,
  DROP COLUMN warehouse_id,
  DROP COLUMN shipping_method,
  DROP COLUMN delivery_priority,
  DROP COLUMN partial_delivery_allowed,
  DROP COLUMN packing_instructions,
  DROP COLUMN header_notes,
  DROP COLUMN internal_notes,
  DROP COLUMN open_amount,
  DROP COLUMN blocked_status,
  DROP COLUMN cancellation_reason,
  DROP COLUMN invoice_type,
  DROP COLUMN business_unit,
  DROP COLUMN sales_org,
  DROP COLUMN distribution_channel,
  DROP COLUMN division,
  DROP COLUMN branch_location;

ALTER TABLE invoice_items
  DROP COLUMN item_type,
  DROP COLUMN item_category,
  DROP COLUMN brand,
  DROP COLUMN line_net_amount,
  DROP COLUMN line_gross_amount,
  DROP COLUMN vat_amount,
  DROP COLUMN tax_code,
  DROP COLUMN revenue_account_id,
  DROP COLUMN cost_center_id,
  DROP COLUMN profit_center_id,
  DROP COLUMN project_code,
  DROP COLUMN price_override_flag,
  DROP COLUMN approval_required_flag;

ALTER TABLE employees
  DROP COLUMN employee_number,
  DROP COLUMN employee_status,
  DROP COLUMN employment_type,
  DROP COLUMN employee_category,
  DROP COLUMN business_unit,
  DROP COLUMN position_title,
  DROP COLUMN grade_level,
  DROP COLUMN reporting_manager_id,
  DROP COLUMN confirmation_date,
  DROP COLUMN contract_start_date,
  DROP COLUMN contract_end_date,
  DROP COLUMN first_name,
  DROP COLUMN middle_name,
  DROP COLUMN last_name,
  DROP COLUMN full_name,
  DROP COLUMN gender,
  DROP COLUMN date_of_birth,
  DROP COLUMN nationality,
  DROP COLUMN marital_status,
  DROP COLUMN religion,
  DROP COLUMN blood_group,
  DROP COLUMN iqama_expiry_date,
  DROP COLUMN passport_number,
  DROP COLUMN passport_expiry_date,
  DROP COLUMN passport_issuing_country,
  DROP COLUMN visa_type,
  DROP COLUMN visa_expiry_date,
  DROP COLUMN personal_mobile,
  DROP COLUMN work_mobile,
  DROP COLUMN personal_email,
  DROP COLUMN work_email,
  DROP COLUMN emergency_contact_name,
  DROP COLUMN emergency_contact_relation,
  DROP COLUMN emergency_contact_phone,
  DROP COLUMN national_address,
  DROP COLUMN address_line1,
  DROP COLUMN city,
  DROP COLUMN state_province,
  DROP COLUMN postal_code,
  DROP COLUMN country,
  DROP COLUMN data_access_level,
  DROP COLUMN record_status,
  DROP COLUMN created_by,
  DROP COLUMN updated_by,
  DROP COLUMN approved_by,
  DROP COLUMN approval_date;

ALTER TABLE payroll_runs
  DROP COLUMN period_month,
  DROP COLUMN period_year,
  DROP COLUMN posting_reference,
  DROP COLUMN payment_method,
  DROP COLUMN bank_file_reference;

ALTER TABLE payroll_items
  DROP COLUMN basic_salary,
  DROP COLUMN allowances,
  DROP COLUMN overtime_amount,
  DROP COLUMN bonus_amount,
  DROP COLUMN deductions,
  DROP COLUMN net_pay,
  DROP COLUMN payroll_currency,
  DROP COLUMN exchange_rate,
  DROP COLUMN cost_center_id,
  DROP COLUMN gl_posting_reference,
  DROP COLUMN payment_method;

ALTER TABLE leave_types
  DROP COLUMN leave_category,
  DROP COLUMN max_allowed_days,
  DROP COLUMN carry_forward_allowed,
  DROP COLUMN paid_flag;

ALTER TABLE leave_requests
  DROP COLUMN total_days,
  DROP COLUMN reason,
  DROP COLUMN approver_id,
  DROP COLUMN approved_date;

ALTER TABLE employee_travel
  DROP COLUMN travel_type,
  DROP COLUMN from_location,
  DROP COLUMN to_location,
  DROP COLUMN status;

ALTER TABLE employee_documents
  DROP COLUMN document_number,
  DROP COLUMN issue_date,
  DROP COLUMN expiry_date,
  DROP COLUMN confidentiality_level,
  DROP COLUMN verified_flag;

ALTER TABLE vehicles
  DROP COLUMN vehicle_code,
  DROP COLUMN plate_type,
  DROP COLUMN registration_country,
  DROP COLUMN vin,
  DROP COLUMN vehicle_type,
  DROP COLUMN make,
  DROP COLUMN body_type,
  DROP COLUMN color,
  DROP COLUMN fuel_type,
  DROP COLUMN transmission_type,
  DROP COLUMN engine_capacity,
  DROP COLUMN seating_capacity,
  DROP COLUMN load_capacity,
  DROP COLUMN ownership_type,
  DROP COLUMN business_unit,
  DROP COLUMN assignment_start_date,
  DROP COLUMN assignment_end_date,
  DROP COLUMN purchase_date,
  DROP COLUMN in_service_date,
  DROP COLUMN odometer_reading,
  DROP COLUMN odometer_unit;

ALTER TABLE vehicle_maintenance
  DROP COLUMN maintenance_category,
  DROP COLUMN workshop_type,
  DROP COLUMN vendor_id,
  DROP COLUMN start_date,
  DROP COLUMN end_date,
  DROP COLUMN downtime_hours,
  DROP COLUMN status,
  DROP COLUMN labor_cost,
  DROP COLUMN parts_cost,
  DROP COLUMN external_service_cost,
  DROP COLUMN total_cost,
  DROP COLUMN currency_code;

ALTER TABLE vehicle_warranties
  DROP COLUMN coverage_description,
  DROP COLUMN coverage_limit_km,
  DROP COLUMN remaining_coverage_km,
  DROP COLUMN warranty_provider,
  DROP COLUMN claim_procedure_ref;

ALTER TABLE vehicle_expenses
  DROP COLUMN expense_type,
  DROP COLUMN expense_category,
  DROP COLUMN vendor_id,
  DROP COLUMN payment_method,
  DROP COLUMN currency_code,
  DROP COLUMN quantity,
  DROP COLUMN unit_cost,
  DROP COLUMN tax_amount,
  DROP COLUMN vat_applicable,
  DROP COLUMN vat_rate,
  DROP COLUMN invoice_reference,
  DROP COLUMN cost_center_id,
  DROP COLUMN project_code,
  DROP COLUMN posting_status;

ALTER TABLE vehicle_reminders
  DROP COLUMN reference_type,
  DROP COLUMN reference_id,
  DROP COLUMN trigger_condition,
  DROP COLUMN trigger_value,
  DROP COLUMN reminder_frequency,
  DROP COLUMN notification_channel,
  DROP COLUMN assigned_to_user_id,
  DROP COLUMN last_triggered_date,
  DROP COLUMN next_trigger_date;

ALTER TABLE attachments
  DROP COLUMN file_display_name,
  DROP COLUMN file_description,
  DROP COLUMN file_category,
  DROP COLUMN document_type,
  DROP COLUMN reference_module,
  DROP COLUMN reference_record_id,
  DROP COLUMN file_extension,
  DROP COLUMN file_hash,
  DROP COLUMN version_no,
  DROP COLUMN is_latest,
  DROP COLUMN upload_source,
  DROP COLUMN storage_type,
  DROP COLUMN storage_provider,
  DROP COLUMN storage_key,
  DROP COLUMN encryption_flag,
  DROP COLUMN compression_flag,
  DROP COLUMN access_level,
  DROP COLUMN allowed_roles,
  DROP COLUMN allowed_users,
  DROP COLUMN download_allowed,
  DROP COLUMN print_allowed,
  DROP COLUMN watermark_enabled,
  DROP COLUMN confidentiality_level,
  DROP COLUMN contains_pii,
  DROP COLUMN data_classification,
  DROP COLUMN legal_hold_flag,
  DROP COLUMN retention_policy_id,
  DROP COLUMN retention_expiry_date,
  DROP COLUMN document_status,
  DROP COLUMN verified_by,
  DROP COLUMN verified_date,
  DROP COLUMN approval_required,
  DROP COLUMN approved_by,
  DROP COLUMN approval_date,
  DROP COLUMN expiry_date,
  DROP COLUMN auto_archive_flag,
  DROP COLUMN parent_document_id,
  DROP COLUMN change_reason,
  DROP COLUMN superseded_date,
  DROP COLUMN superseded_by,
  DROP COLUMN version_notes,
  DROP COLUMN tags,
  DROP COLUMN ocr_enabled,
  DROP COLUMN ocr_text,
  DROP COLUMN language,
  DROP COLUMN search_index_status,
  DROP COLUMN last_accessed_by,
  DROP COLUMN last_accessed_at,
  DROP COLUMN download_count,
  DROP COLUMN access_log_id,
  DROP COLUMN ip_address,
  DROP COLUMN reminder_enabled,
  DROP COLUMN reminder_type,
  DROP COLUMN reminder_schedule,
  DROP COLUMN notified_roles,
  DROP COLUMN notified_users,
  DROP COLUMN source_system,
  DROP COLUMN external_reference_id,
  DROP COLUMN api_sync_status;

-- Drop tables created by expansion
DROP TABLE IF EXISTS contact_phones;
DROP TABLE IF EXISTS contact_emails;
DROP TABLE IF EXISTS contact_addresses;
DROP TABLE IF EXISTS customer_price_agreements;
DROP TABLE IF EXISTS sales_pricing_conditions;
DROP TABLE IF EXISTS employee_salary_structures;
DROP TABLE IF EXISTS leave_balances;
DROP TABLE IF EXISTS employee_travel_expenses;
DROP TABLE IF EXISTS employee_travel_advances;
DROP TABLE IF EXISTS hr_requests;
DROP TABLE IF EXISTS vehicle_maintenance_plans;
DROP TABLE IF EXISTS vehicle_warranty_claims;
DROP TABLE IF EXISTS vehicle_documents;
DROP TABLE IF EXISTS vehicle_incidents;
DROP TABLE IF EXISTS lookup_values;
DROP TABLE IF EXISTS party_addresses;
DROP TABLE IF EXISTS user_saved_filters;
DROP TABLE IF EXISTS money_account_permissions;
DROP TABLE IF EXISTS money_transactions;
DROP TABLE IF EXISTS money_accounts;
DROP TABLE IF EXISTS money_customers;

SET FOREIGN_KEY_CHECKS = 1;
