ALTER TABLE `job_cards`
  ADD CONSTRAINT `job_cards_asset_id_foreign` FOREIGN KEY (`asset_id`) REFERENCES `assets` (`id`),
  ADD CONSTRAINT `job_cards_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `job_cards_work_reason_id_foreign` FOREIGN KEY (`work_reason_id`) REFERENCES `work_reasons` (`id`);

--
-- Constraints for table `job_card_daily_actions`
--
ALTER TABLE `job_card_daily_actions`
  ADD CONSTRAINT `job_card_daily_actions_job_id_foreign` FOREIGN KEY (`job_id`) REFERENCES `job_cards` (`id`);

--
-- Constraints for table `journal_vouchers`
--
ALTER TABLE `journal_vouchers`
  ADD CONSTRAINT `journal_vouchers_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `journal_vouchers_group_company_id_foreign` FOREIGN KEY (`group_company_id`) REFERENCES `groupcompanies` (`id`);

--
-- Constraints for table `journal_voucher_subs`
--
ALTER TABLE `journal_voucher_subs`
  ADD CONSTRAINT `journal_voucher_subs_emp_id_foreign` FOREIGN KEY (`emp_id`) REFERENCES `employees` (`id`),
  ADD CONSTRAINT `journal_voucher_subs_journal_voucher_id_foreign` FOREIGN KEY (`journal_voucher_id`) REFERENCES `journal_vouchers` (`id`),
  ADD CONSTRAINT `journal_voucher_subs_ledger_id_foreign` FOREIGN KEY (`ledger_id`) REFERENCES `accounts_ledgers` (`id`);

--
-- Constraints for table `leave_entries`
--
ALTER TABLE `leave_entries`
  ADD CONSTRAINT `leave_entries_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `leave_entries_emp_id_foreign` FOREIGN KEY (`emp_id`) REFERENCES `employees` (`id`),
  ADD CONSTRAINT `leave_entries_leave_type_foreign` FOREIGN KEY (`leave_type`) REFERENCES `leavetypes` (`id`),
  ADD CONSTRAINT `leave_entries_shift_id_foreign` FOREIGN KEY (`shift_id`) REFERENCES `shiftcreations` (`id`);

--
-- Constraints for table `ledger_transactions`
--
ALTER TABLE `ledger_transactions`
  ADD CONSTRAINT `ledger_transactions_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `ledger_transactions_group_company_id_foreign` FOREIGN KEY (`group_company_id`) REFERENCES `groupcompanies` (`id`),
  ADD CONSTRAINT `ledger_transactions_ledger_id_foreign` FOREIGN KEY (`ledger_id`) REFERENCES `accounts_ledgers` (`id`);

--
-- Constraints for table `loading_types`
--
ALTER TABLE `loading_types`
  ADD CONSTRAINT `loading_types_asset_group_foreign` FOREIGN KEY (`asset_group`) REFERENCES `asset_groups` (`id`),
  ADD CONSTRAINT `loading_types_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `loading_types_uom_id_foreign` FOREIGN KEY (`uom_id`) REFERENCES `uoms` (`id`);

--
-- Constraints for table `loading_type_costs`
--
ALTER TABLE `loading_type_costs`
  ADD CONSTRAINT `loading_type_costs_loading_type_id_foreign` FOREIGN KEY (`loading_type_id`) REFERENCES `loading_types` (`id`),
  ADD CONSTRAINT `loading_type_costs_uom_id_foreign` FOREIGN KEY (`uom_id`) REFERENCES `uoms` (`id`);

--
-- Constraints for table `machineryassigns`
--
ALTER TABLE `machineryassigns`
  ADD CONSTRAINT `machineryassigns_driver_id_foreign` FOREIGN KEY (`driver_id`) REFERENCES `employees` (`id`),
  ADD CONSTRAINT `machineryassigns_machinery_id_foreign` FOREIGN KEY (`machinery_id`) REFERENCES `assets` (`id`),
  ADD CONSTRAINT `machineryassigns_shift_id_foreign` FOREIGN KEY (`shift_id`) REFERENCES `shiftcreations` (`id`);

--
-- Constraints for table `machinery_logs`
--
ALTER TABLE `machinery_logs`
  ADD CONSTRAINT `machinery_logs_machinery_id_foreign` FOREIGN KEY (`machinery_id`) REFERENCES `assets` (`id`),
  ADD CONSTRAINT `machinery_logs_operator_id_foreign` FOREIGN KEY (`operator_id`) REFERENCES `employees` (`id`),
  ADD CONSTRAINT `machinery_logs_shift_id_foreign` FOREIGN KEY (`shift_id`) REFERENCES `shiftcreations` (`id`);

--
-- Constraints for table `machinery_log_subs`
--
ALTER TABLE `machinery_log_subs`
  ADD CONSTRAINT `machinery_log_subs_activity_type_foreign` FOREIGN KEY (`activity_type`) REFERENCES `activity_types` (`id`),
  ADD CONSTRAINT `machinery_log_subs_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `machinery_log_subs_machinery_log_id_foreign` FOREIGN KEY (`machinery_log_id`) REFERENCES `machinery_logs` (`id`);

--
-- Constraints for table `machine_centers`
--
ALTER TABLE `machine_centers`
  ADD CONSTRAINT `machine_centers_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `machine_centers_work_center_id_foreign` FOREIGN KEY (`work_center_id`) REFERENCES `work_centers` (`id`);

--
-- Constraints for table `machine_center_costs`
--
ALTER TABLE `machine_center_costs`
  ADD CONSTRAINT `machine_center_costs_cost_type_id_foreign` FOREIGN KEY (`cost_type_id`) REFERENCES `work_center_cost_types` (`id`),
  ADD CONSTRAINT `machine_center_costs_machine_center_id_foreign` FOREIGN KEY (`machine_center_id`) REFERENCES `machine_centers` (`id`);

--
-- Constraints for table `manual_attendances`
--
ALTER TABLE `manual_attendances`
  ADD CONSTRAINT `manual_attendances_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `manual_attendances_salary_type_foreign` FOREIGN KEY (`salary_type`) REFERENCES `salary_types` (`id`),
  ADD CONSTRAINT `manual_attendances_shift_id_foreign` FOREIGN KEY (`shift_id`) REFERENCES `shiftcreations` (`id`);

--
-- Constraints for table `manual_attendance_subs`
--
ALTER TABLE `manual_attendance_subs`
  ADD CONSTRAINT `manual_attendance_subs_attendance_id_foreign` FOREIGN KEY (`attendance_id`) REFERENCES `manual_attendances` (`id`),
  ADD CONSTRAINT `manual_attendance_subs_design_wages_id_foreign` FOREIGN KEY (`design_wages_id`) REFERENCES `designation_wages_subs` (`id`),
  ADD CONSTRAINT `manual_attendance_subs_emp_id_foreign` FOREIGN KEY (`emp_id`) REFERENCES `employees` (`id`),
  ADD CONSTRAINT `manual_attendance_subs_main_division_id_foreign` FOREIGN KEY (`main_division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `manual_attendance_subs_salary_type_foreign` FOREIGN KEY (`salary_type`) REFERENCES `salary_types` (`id`),
  ADD CONSTRAINT `manual_attendance_subs_shift_id_foreign` FOREIGN KEY (`shift_id`) REFERENCES `shiftcreations` (`id`),
  ADD CONSTRAINT `manual_attendance_subs_sub_division_id_foreign` FOREIGN KEY (`sub_division_id`) REFERENCES `divisions` (`id`);

--
-- Constraints for table `manual_trip_sheets`
--
ALTER TABLE `manual_trip_sheets`
  ADD CONSTRAINT `manual_trip_sheets_driver_id_foreign` FOREIGN KEY (`driver_id`) REFERENCES `employees` (`id`),
  ADD CONSTRAINT `manual_trip_sheets_po_id_foreign` FOREIGN KEY (`po_id`) REFERENCES `purchase_orders` (`id`),
  ADD CONSTRAINT `manual_trip_sheets_trip_id_foreign` FOREIGN KEY (`trip_id`) REFERENCES `inter_trip_masters` (`id`),
  ADD CONSTRAINT `manual_trip_sheets_truck_id_foreign` FOREIGN KEY (`truck_id`) REFERENCES `assets` (`id`);

--
-- Constraints for table `material_issues`
--
ALTER TABLE `material_issues`
  ADD CONSTRAINT `material_issues_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `material_issues_received_by_foreign` FOREIGN KEY (`received_by`) REFERENCES `employees` (`id`),
  ADD CONSTRAINT `material_issues_request_id_foreign` FOREIGN KEY (`request_id`) REFERENCES `material_requests` (`id`);

--
-- Constraints for table `material_issue_returns`
--
ALTER TABLE `material_issue_returns`
  ADD CONSTRAINT `material_issue_returns_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `material_issue_returns_issue_id_foreign` FOREIGN KEY (`issue_id`) REFERENCES `material_issues` (`id`),
  ADD CONSTRAINT `material_issue_returns_returned_by_foreign` FOREIGN KEY (`returned_by`) REFERENCES `employees` (`id`);

--
-- Constraints for table `material_issue_return_subs`
--
ALTER TABLE `material_issue_return_subs`
  ADD CONSTRAINT `material_issue_return_subs_issue_id_foreign` FOREIGN KEY (`issue_id`) REFERENCES `material_issues` (`id`),
  ADD CONSTRAINT `material_issue_return_subs_issue_sub_id_foreign` FOREIGN KEY (`issue_sub_id`) REFERENCES `material_issue_subs` (`id`),
  ADD CONSTRAINT `material_issue_return_subs_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`),
  ADD CONSTRAINT `material_issue_return_subs_return_id_foreign` FOREIGN KEY (`return_id`) REFERENCES `material_requests` (`id`);

--
-- Constraints for table `material_issue_subs`
--
ALTER TABLE `material_issue_subs`
  ADD CONSTRAINT `material_issue_subs_issue_id_foreign` FOREIGN KEY (`issue_id`) REFERENCES `material_issues` (`id`),
  ADD CONSTRAINT `material_issue_subs_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`),
  ADD CONSTRAINT `material_issue_subs_request_id_foreign` FOREIGN KEY (`request_id`) REFERENCES `material_requests` (`id`),
  ADD CONSTRAINT `material_issue_subs_request_sub_id_foreign` FOREIGN KEY (`request_sub_id`) REFERENCES `material_request_subs` (`id`);

--
-- Constraints for table `material_requests`
--
ALTER TABLE `material_requests`
  ADD CONSTRAINT `material_requests_asset_id_foreign` FOREIGN KEY (`asset_id`) REFERENCES `assets` (`id`),
  ADD CONSTRAINT `material_requests_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `material_requests_job_id_foreign` FOREIGN KEY (`job_id`) REFERENCES `job_cards` (`id`),
  ADD CONSTRAINT `material_requests_production_id_foreign` FOREIGN KEY (`production_id`) REFERENCES `production_orders` (`id`),
  ADD CONSTRAINT `material_requests_production_log_id_foreign` FOREIGN KEY (`production_log_id`) REFERENCES `production_order_logs` (`id`),
  ADD CONSTRAINT `material_requests_work_id_foreign` FOREIGN KEY (`work_id`) REFERENCES `workcenters` (`id`),
  ADD CONSTRAINT `material_requests_workorder_id_foreign` FOREIGN KEY (`workorder_id`) REFERENCES `workorders` (`id`);

--
-- Constraints for table `material_request_subs`
--
ALTER TABLE `material_request_subs`
  ADD CONSTRAINT `material_request_subs_brand_name_foreign` FOREIGN KEY (`brand_name`) REFERENCES `product_vendors_subs` (`id`),
  ADD CONSTRAINT `material_request_subs_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`),
  ADD CONSTRAINT `material_request_subs_production_id_foreign` FOREIGN KEY (`production_id`) REFERENCES `production_orders` (`id`),
  ADD CONSTRAINT `material_request_subs_production_sub_id_foreign` FOREIGN KEY (`production_sub_id`) REFERENCES `production_order_subs` (`id`),
  ADD CONSTRAINT `material_request_subs_request_id_foreign` FOREIGN KEY (`request_id`) REFERENCES `material_requests` (`id`);

--
-- Constraints for table `menuitems`
--
ALTER TABLE `menuitems`
  ADD CONSTRAINT `menuitems_menu_id_foreign` FOREIGN KEY (`menu_id`) REFERENCES `menus` (`id`);

--
-- Constraints for table `mobilemenuitems`
--
ALTER TABLE `mobilemenuitems`
  ADD CONSTRAINT `mobilemenuitems_menu_id_foreign` FOREIGN KEY (`menu_id`) REFERENCES `menus` (`id`);

--
-- Constraints for table `mobilemenupermissions`
--
ALTER TABLE `mobilemenupermissions`
  ADD CONSTRAINT `mobilemenupermissions_form_id_foreign` FOREIGN KEY (`form_id`) REFERENCES `mobilemenuitems` (`id`),
  ADD CONSTRAINT `mobilemenupermissions_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`);

--
-- Constraints for table `model_has_permissions`
--
ALTER TABLE `model_has_permissions`
  ADD CONSTRAINT `model_has_permissions_permission_id_foreign` FOREIGN KEY (`permission_id`) REFERENCES `permissions` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `model_has_roles`
--
ALTER TABLE `model_has_roles`
  ADD CONSTRAINT `model_has_roles_role_id_foreign` FOREIGN KEY (`role_id`) REFERENCES `roles` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `otherincomes`
--
ALTER TABLE `otherincomes`
  ADD CONSTRAINT `otherincomes_branch_id_foreign` FOREIGN KEY (`branch_id`) REFERENCES `branch_creations` (`id`),
  ADD CONSTRAINT `otherincomes_customer_id_foreign` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`),
  ADD CONSTRAINT `otherincomes_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `otherincomes_group_company_id_foreign` FOREIGN KEY (`group_company_id`) REFERENCES `groupcompanies` (`id`),
  ADD CONSTRAINT `otherincomes_paymentterm_id_foreign` FOREIGN KEY (`paymentterm_id`) REFERENCES `paymentterms` (`id`),
  ADD CONSTRAINT `otherincomes_salesperson_id_foreign` FOREIGN KEY (`salesperson_id`) REFERENCES `staffbranches` (`id`);

--
-- Constraints for table `otherincomesubs`
--
ALTER TABLE `otherincomesubs`
  ADD CONSTRAINT `otherincomesubs_main_id_foreign` FOREIGN KEY (`main_id`) REFERENCES `otherincomes` (`id`),
  ADD CONSTRAINT `otherincomesubs_otherincometype_id_foreign` FOREIGN KEY (`otherincometype_id`) REFERENCES `otherincometypes` (`id`),
  ADD CONSTRAINT `otherincomesubs_tax_id_foreign` FOREIGN KEY (`tax_id`) REFERENCES `taxes` (`id`),
  ADD CONSTRAINT `otherincomesubs_uom_id_foreign` FOREIGN KEY (`uom_id`) REFERENCES `uoms` (`id`);

--
-- Constraints for table `otherincometypes`
--
ALTER TABLE `otherincometypes`
  ADD CONSTRAINT `otherincometypes_ledger_id_foreign` FOREIGN KEY (`ledger_id`) REFERENCES `accounts_ledgers` (`id`);

--
-- Constraints for table `outersalestrips`
--
ALTER TABLE `outersalestrips`
  ADD CONSTRAINT `outersalestrips_assign_truck_id_foreign` FOREIGN KEY (`assign_truck_id`) REFERENCES `truckassigns` (`id`),
  ADD CONSTRAINT `outersalestrips_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `outersalestrips_po_id_foreign` FOREIGN KEY (`po_id`) REFERENCES `purchase_orders` (`id`),
  ADD CONSTRAINT `outersalestrips_sales_id_foreign` FOREIGN KEY (`sales_id`) REFERENCES `salesorders` (`id`),
  ADD CONSTRAINT `outersalestrips_shift_id_foreign` FOREIGN KEY (`shift_id`) REFERENCES `shiftcreations` (`id`),
  ADD CONSTRAINT `outersalestrips_trip_id_foreign` FOREIGN KEY (`trip_id`) REFERENCES `tripmasters` (`id`);

--
-- Constraints for table `outersalestripsubs`
--
ALTER TABLE `outersalestripsubs`
  ADD CONSTRAINT `outersalestripsubs_main_id_foreign` FOREIGN KEY (`main_id`) REFERENCES `outersalestrips` (`id`),
  ADD CONSTRAINT `outersalestripsubs_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`),
  ADD CONSTRAINT `outersalestripsubs_sales_id_foreign` FOREIGN KEY (`sales_id`) REFERENCES `salesorders` (`id`),
  ADD CONSTRAINT `outersalestripsubs_sales_sub_id_foreign` FOREIGN KEY (`sales_sub_id`) REFERENCES `salesorder_subs` (`id`),
  ADD CONSTRAINT `outersalestripsubs_uom_id_foreign` FOREIGN KEY (`uom_id`) REFERENCES `uoms` (`id`);

--
-- Constraints for table `outertriptrackings`
--
ALTER TABLE `outertriptrackings`
  ADD CONSTRAINT `outertriptrackings_outertrip_id_foreign` FOREIGN KEY (`outertrip_id`) REFERENCES `outersalestrips` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `outertrip_weightments`
--
ALTER TABLE `outertrip_weightments`
  ADD CONSTRAINT `outertrip_weightments_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `outertrip_weightments_outertrip_id_foreign` FOREIGN KEY (`outertrip_id`) REFERENCES `outersalestrips` (`id`);

--
-- Constraints for table `outer_triploadings`
--
ALTER TABLE `outer_triploadings`
  ADD CONSTRAINT `outer_triploadings_asset_id_foreign` FOREIGN KEY (`asset_id`) REFERENCES `assets` (`id`),
  ADD CONSTRAINT `outer_triploadings_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `outer_triploadings_outertrip_id_foreign` FOREIGN KEY (`outertrip_id`) REFERENCES `outersalestrips` (`id`);

--
-- Constraints for table `over_times`
--
ALTER TABLE `over_times`
  ADD CONSTRAINT `over_times_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `over_times_salary_type_foreign` FOREIGN KEY (`salary_type`) REFERENCES `salary_types` (`id`);

--
-- Constraints for table `over_time_subs`
--
ALTER TABLE `over_time_subs`
  ADD CONSTRAINT `over_time_subs_emp_id_foreign` FOREIGN KEY (`emp_id`) REFERENCES `employees` (`id`),
  ADD CONSTRAINT `over_time_subs_main_division_id_foreign` FOREIGN KEY (`main_division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `over_time_subs_ot_id_foreign` FOREIGN KEY (`ot_id`) REFERENCES `over_times` (`id`),
  ADD CONSTRAINT `over_time_subs_salary_type_foreign` FOREIGN KEY (`salary_type`) REFERENCES `salary_types` (`id`),
  ADD CONSTRAINT `over_time_subs_shift_id_foreign` FOREIGN KEY (`shift_id`) REFERENCES `shiftcreations` (`id`),
  ADD CONSTRAINT `over_time_subs_sub_division_id_foreign` FOREIGN KEY (`sub_division_id`) REFERENCES `divisions` (`id`);

--
-- Constraints for table `payment_vouchers`
--
ALTER TABLE `payment_vouchers`
  ADD CONSTRAINT `payment_vouchers_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `payment_vouchers_group_company_id_foreign` FOREIGN KEY (`group_company_id`) REFERENCES `groupcompanies` (`id`),
  ADD CONSTRAINT `payment_vouchers_main_ledger_id_foreign` FOREIGN KEY (`main_ledger_id`) REFERENCES `accounts_ledgers` (`id`),
  ADD CONSTRAINT `payment_vouchers_schedulepayment_id_foreign` FOREIGN KEY (`schedulepayment_id`) REFERENCES `schedulepayments` (`id`);

--
-- Constraints for table `payment_voucher_subs`
--
ALTER TABLE `payment_voucher_subs`
  ADD CONSTRAINT `payment_voucher_subs_asset_id_foreign` FOREIGN KEY (`asset_id`) REFERENCES `assets` (`id`),
  ADD CONSTRAINT `payment_voucher_subs_ledger_id_foreign` FOREIGN KEY (`ledger_id`) REFERENCES `accounts_ledgers` (`id`),
  ADD CONSTRAINT `payment_voucher_subs_payment_voucher_id_foreign` FOREIGN KEY (`payment_voucher_id`) REFERENCES `payment_vouchers` (`id`);

--
-- Constraints for table `permissions`
--
ALTER TABLE `permissions`
  ADD CONSTRAINT `permissions_form_id_foreign` FOREIGN KEY (`form_id`) REFERENCES `menuitems` (`id`);

--
-- Constraints for table `privatevehiclemobiles`
--
ALTER TABLE `privatevehiclemobiles`
  ADD CONSTRAINT `privatevehiclemobiles_main_id_foreign` FOREIGN KEY (`main_id`) REFERENCES `privatevehicles` (`id`);

--
-- Constraints for table `productionroutings`
--
ALTER TABLE `productionroutings`
  ADD CONSTRAINT `productionroutings_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`);

--
-- Constraints for table `productionroutingsubs`
--
ALTER TABLE `productionroutingsubs`
  ADD CONSTRAINT `productionroutingsubs_machinecenter_id_foreign` FOREIGN KEY (`machinecenter_id`) REFERENCES `machine_centers` (`id`),
  ADD CONSTRAINT `productionroutingsubs_main_id_foreign` FOREIGN KEY (`main_id`) REFERENCES `productionroutings` (`id`),
  ADD CONSTRAINT `productionroutingsubs_workcenter_id_foreign` FOREIGN KEY (`workcenter_id`) REFERENCES `work_centers` (`id`);

--
-- Constraints for table `production_orders`
--
ALTER TABLE `production_orders`
  ADD CONSTRAINT `production_orders_bom_id_foreign` FOREIGN KEY (`bom_id`) REFERENCES `standard_boms` (`id`),
  ADD CONSTRAINT `production_orders_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `production_orders_emp_id_foreign` FOREIGN KEY (`emp_id`) REFERENCES `employees` (`id`),
  ADD CONSTRAINT `production_orders_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`),
  ADD CONSTRAINT `production_orders_routing_id_foreign` FOREIGN KEY (`routing_id`) REFERENCES `productionroutings` (`id`),
  ADD CONSTRAINT `production_orders_sales_id_foreign` FOREIGN KEY (`sales_id`) REFERENCES `salesorders` (`id`),
  ADD CONSTRAINT `production_orders_uom_id_foreign` FOREIGN KEY (`uom_id`) REFERENCES `uoms` (`id`);

--
-- Constraints for table `production_order_logs`
--
ALTER TABLE `production_order_logs`
  ADD CONSTRAINT `production_order_logs_production_order_id_foreign` FOREIGN KEY (`production_order_id`) REFERENCES `production_orders` (`id`),
  ADD CONSTRAINT `production_order_logs_warehouse_id_foreign` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`);

--
-- Constraints for table `production_order_log_machine_cenetrs`
--
ALTER TABLE `production_order_log_machine_cenetrs`
  ADD CONSTRAINT `production_order_log_machine_cenetrs_machine_center_id_foreign` FOREIGN KEY (`machine_center_id`) REFERENCES `machine_centers` (`id`),
  ADD CONSTRAINT `production_order_log_machine_cenetrs_production_log_id_foreign` FOREIGN KEY (`production_log_id`) REFERENCES `production_order_logs` (`id`),
  ADD CONSTRAINT `production_order_log_machine_cenetrs_production_order_id_foreign` FOREIGN KEY (`production_order_id`) REFERENCES `production_orders` (`id`),
  ADD CONSTRAINT `production_order_log_machine_cenetrs_work_center_id_foreign` FOREIGN KEY (`work_center_id`) REFERENCES `work_centers` (`id`);

--
-- Constraints for table `production_order_log_work_cenetrs`
--
ALTER TABLE `production_order_log_work_cenetrs`
  ADD CONSTRAINT `production_order_log_work_cenetrs_production_log_id_foreign` FOREIGN KEY (`production_log_id`) REFERENCES `production_order_logs` (`id`),
  ADD CONSTRAINT `production_order_log_work_cenetrs_production_order_id_foreign` FOREIGN KEY (`production_order_id`) REFERENCES `production_orders` (`id`),
  ADD CONSTRAINT `production_order_log_work_cenetrs_work_center_id_foreign` FOREIGN KEY (`work_center_id`) REFERENCES `work_centers` (`id`);

--
-- Constraints for table `production_order_machine_centers`
--
ALTER TABLE `production_order_machine_centers`
  ADD CONSTRAINT `production_order_machine_centers_machine_center_id_foreign` FOREIGN KEY (`machine_center_id`) REFERENCES `machine_centers` (`id`),
  ADD CONSTRAINT `production_order_machine_centers_production_order_id_foreign` FOREIGN KEY (`production_order_id`) REFERENCES `production_orders` (`id`),
  ADD CONSTRAINT `production_order_machine_centers_work_center_id_foreign` FOREIGN KEY (`work_center_id`) REFERENCES `work_centers` (`id`);

--
-- Constraints for table `production_order_subs`
--
ALTER TABLE `production_order_subs`
  ADD CONSTRAINT `production_order_subs_bom_sub_id_foreign` FOREIGN KEY (`bom_sub_id`) REFERENCES `standard_bom_subs` (`id`),
  ADD CONSTRAINT `production_order_subs_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`),
  ADD CONSTRAINT `production_order_subs_production_order_id_foreign` FOREIGN KEY (`production_order_id`) REFERENCES `production_orders` (`id`),
  ADD CONSTRAINT `production_order_subs_uom_id_foreign` FOREIGN KEY (`uom_id`) REFERENCES `uoms` (`id`);

--
-- Constraints for table `production_order_trackings`
--
ALTER TABLE `production_order_trackings`
  ADD CONSTRAINT `production_order_trackings_order_id_foreign` FOREIGN KEY (`order_id`) REFERENCES `production_orders` (`id`);

--
-- Constraints for table `production_order_work_centers`
--
ALTER TABLE `production_order_work_centers`
  ADD CONSTRAINT `production_order_work_centers_production_order_id_foreign` FOREIGN KEY (`production_order_id`) REFERENCES `production_orders` (`id`),
  ADD CONSTRAINT `production_order_work_centers_work_center_id_foreign` FOREIGN KEY (`work_center_id`) REFERENCES `work_centers` (`id`);

--
-- Constraints for table `production_routing_machines`
--
ALTER TABLE `production_routing_machines`
  ADD CONSTRAINT `production_routing_machines_machinecenter_id_foreign` FOREIGN KEY (`machinecenter_id`) REFERENCES `machine_centers` (`id`),
  ADD CONSTRAINT `production_routing_machines_main_id_foreign` FOREIGN KEY (`main_id`) REFERENCES `productionroutings` (`id`),
  ADD CONSTRAINT `production_routing_machines_workcenter_id_foreign` FOREIGN KEY (`workcenter_id`) REFERENCES `work_centers` (`id`);

--
-- Constraints for table `products`
--
ALTER TABLE `products`
  ADD CONSTRAINT `products_inventory_ledger_id_foreign` FOREIGN KEY (`inventory_ledger_id`) REFERENCES `accounts_ledgers` (`id`),
  ADD CONSTRAINT `products_product_group_id_foreign` FOREIGN KEY (`product_group_id`) REFERENCES `product_groups` (`id`),
  ADD CONSTRAINT `products_purchase_ledger_id_foreign` FOREIGN KEY (`purchase_ledger_id`) REFERENCES `accounts_ledgers` (`id`),
  ADD CONSTRAINT `products_sales_ledger_id_foreign` FOREIGN KEY (`sales_ledger_id`) REFERENCES `accounts_ledgers` (`id`),
  ADD CONSTRAINT `products_uom_id_foreign` FOREIGN KEY (`uom_id`) REFERENCES `uoms` (`id`);

--
-- Constraints for table `productstandard_consumptions`
--
ALTER TABLE `productstandard_consumptions`
  ADD CONSTRAINT `productstandard_consumptions_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `productstandard_consumptions_uom_id_foreign` FOREIGN KEY (`uom_id`) REFERENCES `uoms` (`id`);

--
-- Constraints for table `productuoms`
--
ALTER TABLE `productuoms`
  ADD CONSTRAINT `productuoms_auom_id_foreign` FOREIGN KEY (`auom_id`) REFERENCES `uoms` (`id`),
  ADD CONSTRAINT `productuoms_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `productuoms_uom_foreign` FOREIGN KEY (`uom`) REFERENCES `uoms` (`id`);

--
-- Constraints for table `product_costs`
--
ALTER TABLE `product_costs`
  ADD CONSTRAINT `product_costs_cost_id_foreign` FOREIGN KEY (`cost_id`) REFERENCES `product_cost_types` (`id`),
  ADD CONSTRAINT `product_costs_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`);

--
-- Constraints for table `product_cost_types`
--
ALTER TABLE `product_cost_types`
  ADD CONSTRAINT `product_cost_types_ledger_id_foreign` FOREIGN KEY (`ledger_id`) REFERENCES `accounts_ledgers` (`id`);

--
-- Constraints for table `product_groups`
--
ALTER TABLE `product_groups`
  ADD CONSTRAINT `product_groups_category_id_foreign` FOREIGN KEY (`category_id`) REFERENCES `productcategories` (`id`);

--
-- Constraints for table `product_routings`
--
ALTER TABLE `product_routings`
  ADD CONSTRAINT `product_routings_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `product_routings_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`),
  ADD CONSTRAINT `product_routings_uom_id_foreign` FOREIGN KEY (`uom_id`) REFERENCES `uoms` (`id`);

--
-- Constraints for table `product_routing_subs`
--
ALTER TABLE `product_routing_subs`
  ADD CONSTRAINT `product_routing_subs_route_id_foreign` FOREIGN KEY (`route_id`) REFERENCES `product_routings` (`id`),
  ADD CONSTRAINT `product_routing_subs_workcenter_id_foreign` FOREIGN KEY (`workcenter_id`) REFERENCES `workcenters` (`id`);

--
-- Constraints for table `product_vendors_subs`
--
ALTER TABLE `product_vendors_subs`
  ADD CONSTRAINT `product_vendors_subs_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`),
  ADD CONSTRAINT `product_vendors_subs_vendor_id_foreign` FOREIGN KEY (`vendor_id`) REFERENCES `suppliers` (`id`);

--
-- Constraints for table `projectcompletions`
--
ALTER TABLE `projectcompletions`
  ADD CONSTRAINT `projectcompletions_project_id_foreign` FOREIGN KEY (`project_id`) REFERENCES `projectcreations` (`id`);

--
-- Constraints for table `projectcompletionsubs`
--
ALTER TABLE `projectcompletionsubs`
  ADD CONSTRAINT `projectcompletionsubs_dc_qty_uom_id_foreign` FOREIGN KEY (`dc_qty_uom_id`) REFERENCES `uoms` (`id`),
  ADD CONSTRAINT `projectcompletionsubs_estimated_qty_uom_id_foreign` FOREIGN KEY (`estimated_qty_uom_id`) REFERENCES `uoms` (`id`),
  ADD CONSTRAINT `projectcompletionsubs_main_id_foreign` FOREIGN KEY (`main_id`) REFERENCES `projectcompletions` (`id`),
  ADD CONSTRAINT `projectcompletionsubs_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`);

--
-- Constraints for table `projectcreations`
--
ALTER TABLE `projectcreations`
  ADD CONSTRAINT `projectcreations_contractor_id_foreign` FOREIGN KEY (`contractor_id`) REFERENCES `suppliers` (`id`),
  ADD CONSTRAINT `projectcreations_customer_id_foreign` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`),
  ADD CONSTRAINT `projectcreations_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `projectcreations_executive_id_foreign` FOREIGN KEY (`executive_id`) REFERENCES `staffbranches` (`id`),
  ADD CONSTRAINT `projectcreations_layingsite_id_foreign` FOREIGN KEY (`layingsite_id`) REFERENCES `customeraddresses` (`id`),
  ADD CONSTRAINT `projectcreations_officesite_id_foreign` FOREIGN KEY (`officesite_id`) REFERENCES `customeraddresses` (`id`),
  ADD CONSTRAINT `projectcreations_projectcompletion_id_foreign` FOREIGN KEY (`projectcompletion_id`) REFERENCES `projectcompletions` (`id`);

--
-- Constraints for table `purchasebooks`
--
ALTER TABLE `purchasebooks`
  ADD CONSTRAINT `purchasebooks_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `purchasebooks_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`),
  ADD CONSTRAINT `purchasebooks_supplier_id_foreign` FOREIGN KEY (`supplier_id`) REFERENCES `suppliers` (`id`);

--
-- Constraints for table `purchasereturns`
--
ALTER TABLE `purchasereturns`
  ADD CONSTRAINT `purchasereturns_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `purchasereturns_grnbill_id_foreign` FOREIGN KEY (`grnbill_id`) REFERENCES `grn_bills` (`id`),
  ADD CONSTRAINT `purchasereturns_group_company_id_foreign` FOREIGN KEY (`group_company_id`) REFERENCES `groupcompanies` (`id`),
  ADD CONSTRAINT `purchasereturns_supplier_id_foreign` FOREIGN KEY (`supplier_id`) REFERENCES `suppliers` (`id`);

--
-- Constraints for table `purchasereturn_subs`
--
ALTER TABLE `purchasereturn_subs`
  ADD CONSTRAINT `purchasereturn_subs_grnbillsub_id_foreign` FOREIGN KEY (`grnbillsub_id`) REFERENCES `grn_bill_subs` (`id`),
  ADD CONSTRAINT `purchasereturn_subs_main_id_foreign` FOREIGN KEY (`main_id`) REFERENCES `purchasereturns` (`id`),
  ADD CONSTRAINT `purchasereturn_subs_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`);

--
-- Constraints for table `purchase_advances`
--
ALTER TABLE `purchase_advances`
  ADD CONSTRAINT `purchase_advances_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `purchase_advances_emp_id_foreign` FOREIGN KEY (`emp_id`) REFERENCES `employees` (`id`),
  ADD CONSTRAINT `purchase_advances_group_company_foreign` FOREIGN KEY (`group_company`) REFERENCES `groupcompanies` (`id`),
  ADD CONSTRAINT `purchase_advances_paid_id_foreign` FOREIGN KEY (`paid_id`) REFERENCES `accounts_ledgers` (`id`),
  ADD CONSTRAINT `purchase_advances_paid_ledger_id_foreign` FOREIGN KEY (`paid_ledger_id`) REFERENCES `accounts_ledgers` (`id`);

--
-- Constraints for table `purchase_advance_revises`
--
ALTER TABLE `purchase_advance_revises`
  ADD CONSTRAINT `purchase_advance_revises_purchase_advance_id_foreign` FOREIGN KEY (`purchase_advance_id`) REFERENCES `purchase_advances` (`id`);

--
-- Constraints for table `purchase_advance_revise_subs`
--
ALTER TABLE `purchase_advance_revise_subs`
  ADD CONSTRAINT `purchase_advance_revise_subs_ledger_id_foreign` FOREIGN KEY (`ledger_id`) REFERENCES `accounts_ledgers` (`id`),
  ADD CONSTRAINT `purchase_advance_revise_subs_purchase_advance_revise_id_foreign` FOREIGN KEY (`purchase_advance_revise_id`) REFERENCES `purchase_advance_revises` (`id`);

--
-- Constraints for table `purchase_orders`
--
ALTER TABLE `purchase_orders`
  ADD CONSTRAINT `purchase_orders_billing_address_id_foreign` FOREIGN KEY (`billing_address_id`) REFERENCES `groupcompanies` (`id`),
  ADD CONSTRAINT `purchase_orders_delivery_id_foreign` FOREIGN KEY (`delivery_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `purchase_orders_other_id_foreign` FOREIGN KEY (`other_id`) REFERENCES `accounts_ledgers` (`id`),
  ADD CONSTRAINT `purchase_orders_supplier_id_foreign` FOREIGN KEY (`supplier_id`) REFERENCES `suppliers` (`id`);

--
-- Constraints for table `purchase_order_subs`
--
ALTER TABLE `purchase_order_subs`
  ADD CONSTRAINT `purchase_order_subs_brand_name_foreign` FOREIGN KEY (`brand_name`) REFERENCES `product_vendors_subs` (`id`),
  ADD CONSTRAINT `purchase_order_subs_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`),
  ADD CONSTRAINT `purchase_order_subs_purchase_order_id_foreign` FOREIGN KEY (`purchase_order_id`) REFERENCES `purchase_orders` (`id`),
  ADD CONSTRAINT `purchase_order_subs_uom_id_foreign` FOREIGN KEY (`uom_id`) REFERENCES `uoms` (`id`);

--
-- Constraints for table `purchase_order_trackings`
--
ALTER TABLE `purchase_order_trackings`
  ADD CONSTRAINT `purchase_order_trackings_order_id_foreign` FOREIGN KEY (`order_id`) REFERENCES `purchase_orders` (`id`);

--
-- Constraints for table `purchase_quotations`
--
ALTER TABLE `purchase_quotations`
  ADD CONSTRAINT `purchase_quotations_purchase_id_foreign` FOREIGN KEY (`purchase_id`) REFERENCES `purchase_requests` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `purchase_requests`
--
ALTER TABLE `purchase_requests`
  ADD CONSTRAINT `purchase_requests_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `purchase_requests_inter_from_division_foreign` FOREIGN KEY (`inter_from_division`) REFERENCES `divisions` (`id`);

--
-- Constraints for table `purchase_request_subs`
--
ALTER TABLE `purchase_request_subs`
  ADD CONSTRAINT `purchase_request_subs_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`),
  ADD CONSTRAINT `purchase_request_subs_purchase_id_foreign` FOREIGN KEY (`purchase_id`) REFERENCES `purchase_requests` (`id`),
  ADD CONSTRAINT `purchase_request_subs_request_sub_id_foreign` FOREIGN KEY (`request_sub_id`) REFERENCES `material_request_subs` (`id`),
  ADD CONSTRAINT `purchase_request_subs_uom_id_foreign` FOREIGN KEY (`uom_id`) REFERENCES `uoms` (`id`);

--
-- Constraints for table `receiptadjustment_subs`
--
ALTER TABLE `receiptadjustment_subs`
  ADD CONSTRAINT `receiptadjustment_subs_main_id_foreign` FOREIGN KEY (`main_id`) REFERENCES `collectionforms` (`id`);

--
-- Constraints for table `receipt_vouchers`
--
ALTER TABLE `receipt_vouchers`
  ADD CONSTRAINT `receipt_vouchers_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `receipt_vouchers_group_company_id_foreign` FOREIGN KEY (`group_company_id`) REFERENCES `groupcompanies` (`id`),
  ADD CONSTRAINT `receipt_vouchers_main_ledger_id_foreign` FOREIGN KEY (`main_ledger_id`) REFERENCES `accounts_ledgers` (`id`);

--
-- Constraints for table `receipt_voucher_subs`
--
ALTER TABLE `receipt_voucher_subs`
  ADD CONSTRAINT `receipt_voucher_subs_ledger_id_foreign` FOREIGN KEY (`ledger_id`) REFERENCES `accounts_ledgers` (`id`),
  ADD CONSTRAINT `receipt_voucher_subs_receipt_voucher_id_foreign` FOREIGN KEY (`receipt_voucher_id`) REFERENCES `receipt_vouchers` (`id`);

--
-- Constraints for table `refundforms`
--
ALTER TABLE `refundforms`
  ADD CONSTRAINT `refundforms_creditnote_id_foreign` FOREIGN KEY (`creditnote_id`) REFERENCES `creditnotes` (`id`),
  ADD CONSTRAINT `refundforms_customer_id_foreign` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`),
  ADD CONSTRAINT `refundforms_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `refundforms_groupcompany_id_foreign` FOREIGN KEY (`groupcompany_id`) REFERENCES `groupcompanies` (`id`),
  ADD CONSTRAINT `refundforms_ledger_id_foreign` FOREIGN KEY (`ledger_id`) REFERENCES `accounts_ledgers` (`id`),
  ADD CONSTRAINT `refundforms_receipt_id_foreign` FOREIGN KEY (`receipt_id`) REFERENCES `collectionforms` (`id`);

--
-- Constraints for table `role_has_permissions`
--
ALTER TABLE `role_has_permissions`
  ADD CONSTRAINT `role_has_permissions_permission_id_foreign` FOREIGN KEY (`permission_id`) REFERENCES `permissions` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `role_has_permissions_role_id_foreign` FOREIGN KEY (`role_id`) REFERENCES `roles` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `salescosts`
--
ALTER TABLE `salescosts`
  ADD CONSTRAINT `salescosts_costtype_id_foreign` FOREIGN KEY (`costtype_id`) REFERENCES `product_cost_types` (`id`),
  ADD CONSTRAINT `salescosts_dc_id_foreign` FOREIGN KEY (`dc_id`) REFERENCES `sales_dcs` (`id`),
  ADD CONSTRAINT `salescosts_salesorder_id_foreign` FOREIGN KEY (`salesorder_id`) REFERENCES `salesorders` (`id`);

--
-- Constraints for table `salesdiscounts`
--
ALTER TABLE `salesdiscounts`
  ADD CONSTRAINT `salesdiscounts_branch_id_foreign` FOREIGN KEY (`branch_id`) REFERENCES `branch_creations` (`id`),
  ADD CONSTRAINT `salesdiscounts_customer_id_foreign` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`),
  ADD CONSTRAINT `salesdiscounts_discountreason_id_foreign` FOREIGN KEY (`discountreason_id`) REFERENCES `discountreasons` (`id`),
  ADD CONSTRAINT `salesdiscounts_salesperson_id_foreign` FOREIGN KEY (`salesperson_id`) REFERENCES `staffbranches` (`id`);

--
-- Constraints for table `salesdiscountsubs`
--
ALTER TABLE `salesdiscountsubs`
  ADD CONSTRAINT `salesdiscountsubs_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `salesdiscountsubs_main_id_foreign` FOREIGN KEY (`main_id`) REFERENCES `salesdiscounts` (`id`);

--
-- Constraints for table `salesgateins`
--
ALTER TABLE `salesgateins`
  ADD CONSTRAINT `salesgateins_assign_truck_id_foreign` FOREIGN KEY (`assign_truck_id`) REFERENCES `truckassigns` (`id`),
  ADD CONSTRAINT `salesgateins_outertrip_id_foreign` FOREIGN KEY (`outertrip_id`) REFERENCES `outersalestrips` (`id`),
  ADD CONSTRAINT `salesgateins_salesreturn_id_foreign` FOREIGN KEY (`salesreturn_id`) REFERENCES `salesreturns` (`id`),
  ADD CONSTRAINT `salesgateins_truck_id_foreign` FOREIGN KEY (`truck_id`) REFERENCES `assets` (`id`);

--
-- Constraints for table `salesinvoices`
--
ALTER TABLE `salesinvoices`
  ADD CONSTRAINT `salesinvoices_billing_id_foreign` FOREIGN KEY (`billing_id`) REFERENCES `customeraddresses` (`id`),
  ADD CONSTRAINT `salesinvoices_customer_id_foreign` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`),
  ADD CONSTRAINT `salesinvoices_dc_id_foreign` FOREIGN KEY (`dc_id`) REFERENCES `sales_dcs` (`id`),
  ADD CONSTRAINT `salesinvoices_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `salesinvoices_shipping_id_foreign` FOREIGN KEY (`shipping_id`) REFERENCES `customeraddresses` (`id`);

--
-- Constraints for table `salesinvoicesubs`
--
ALTER TABLE `salesinvoicesubs`
  ADD CONSTRAINT `salesinvoicesubs_main_id_foreign` FOREIGN KEY (`main_id`) REFERENCES `salesinvoices` (`id`),
  ADD CONSTRAINT `salesinvoicesubs_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`),
  ADD CONSTRAINT `salesinvoicesubs_salesdc_subid_foreign` FOREIGN KEY (`salesdc_subid`) REFERENCES `sales_dc_subs` (`id`),
  ADD CONSTRAINT `salesinvoicesubs_tax_id_foreign` FOREIGN KEY (`tax_id`) REFERENCES `taxes` (`id`),
  ADD CONSTRAINT `salesinvoicesubs_uom_id_foreign` FOREIGN KEY (`uom_id`) REFERENCES `uoms` (`id`);

--
-- Constraints for table `salesorders`
--
ALTER TABLE `salesorders`
  ADD CONSTRAINT `salesorders_branch_id_foreign` FOREIGN KEY (`branch_id`) REFERENCES `branch_creations` (`id`),
  ADD CONSTRAINT `salesorders_customer_id_foreign` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`),
  ADD CONSTRAINT `salesorders_deliverysite_id_foreign` FOREIGN KEY (`deliverysite_id`) REFERENCES `customeraddresses` (`id`),
  ADD CONSTRAINT `salesorders_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `salesorders_estimation_id_foreign` FOREIGN KEY (`estimation_id`) REFERENCES `estimationforms` (`id`),
  ADD CONSTRAINT `salesorders_paymentterm_id_foreign` FOREIGN KEY (`paymentterm_id`) REFERENCES `paymentterms` (`id`),
  ADD CONSTRAINT `salesorders_po_id_foreign` FOREIGN KEY (`po_id`) REFERENCES `customerpos` (`id`),
  ADD CONSTRAINT `salesorders_salesperson_id_foreign` FOREIGN KEY (`salesperson_id`) REFERENCES `staffbranches` (`id`),
  ADD CONSTRAINT `salesorders_tax_id_foreign` FOREIGN KEY (`tax_id`) REFERENCES `taxes` (`id`),
  ADD CONSTRAINT `salesorders_unloading_type_id_foreign` FOREIGN KEY (`unloading_type_id`) REFERENCES `loading_types` (`id`);

--
-- Constraints for table `salesorder_subs`
--
ALTER TABLE `salesorder_subs`
  ADD CONSTRAINT `salesorder_subs_main_id_foreign` FOREIGN KEY (`main_id`) REFERENCES `salesorders` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `salesorder_subs_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`),
  ADD CONSTRAINT `salesorder_subs_tax_id_foreign` FOREIGN KEY (`tax_id`) REFERENCES `taxes` (`id`),
  ADD CONSTRAINT `salesorder_subs_uom_id_foreign` FOREIGN KEY (`uom_id`) REFERENCES `uoms` (`id`);

--
-- Constraints for table `salesorder_vehicles`
--
ALTER TABLE `salesorder_vehicles`
  ADD CONSTRAINT `salesorder_vehicles_dispatch_id_foreign` FOREIGN KEY (`dispatch_id`) REFERENCES `division_dispatch_vehicles` (`id`),
  ADD CONSTRAINT `salesorder_vehicles_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `salesorder_vehicles_sales_id_foreign` FOREIGN KEY (`sales_id`) REFERENCES `salesorders` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `salesreturnreceives`
--
ALTER TABLE `salesreturnreceives`
  ADD CONSTRAINT `salesreturnreceives_salesreturn_id_foreign` FOREIGN KEY (`salesreturn_id`) REFERENCES `salesreturns` (`id`);

--
-- Constraints for table `salesreturnreceivesubs`
--
ALTER TABLE `salesreturnreceivesubs`
  ADD CONSTRAINT `salesreturnreceivesubs_main_id_foreign` FOREIGN KEY (`main_id`) REFERENCES `salesreturnreceives` (`id`),
  ADD CONSTRAINT `salesreturnreceivesubs_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`),
  ADD CONSTRAINT `salesreturnreceivesubs_salesreturn_id_foreign` FOREIGN KEY (`salesreturn_id`) REFERENCES `salesreturns` (`id`),
  ADD CONSTRAINT `salesreturnreceivesubs_salesreturn_subid_foreign` FOREIGN KEY (`salesreturn_subid`) REFERENCES `salesreturnsubs` (`id`);

--
-- Constraints for table `salesreturns`
--
ALTER TABLE `salesreturns`
  ADD CONSTRAINT `salesreturns_customer_id_foreign` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`),
  ADD CONSTRAINT `salesreturns_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `salesreturns_group_company_id_foreign` FOREIGN KEY (`group_company_id`) REFERENCES `groupcompanies` (`id`),
  ADD CONSTRAINT `salesreturns_salesorder_id_foreign` FOREIGN KEY (`salesorder_id`) REFERENCES `salesorders` (`id`),
  ADD CONSTRAINT `salesreturns_salesperson_id_foreign` FOREIGN KEY (`salesperson_id`) REFERENCES `staffbranches` (`id`),
  ADD CONSTRAINT `salesreturns_truck_id_foreign` FOREIGN KEY (`truck_id`) REFERENCES `assets` (`id`);

--
-- Constraints for table `salesreturnsubs`
--
ALTER TABLE `salesreturnsubs`
  ADD CONSTRAINT `salesreturnsubs_main_id_foreign` FOREIGN KEY (`main_id`) REFERENCES `salesreturns` (`id`),
  ADD CONSTRAINT `salesreturnsubs_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`),
  ADD CONSTRAINT `salesreturnsubs_reason_foreign` FOREIGN KEY (`reason`) REFERENCES `salesreturnreasons` (`id`),
  ADD CONSTRAINT `salesreturnsubs_salesorder_id_foreign` FOREIGN KEY (`salesorder_id`) REFERENCES `salesorders` (`id`),
  ADD CONSTRAINT `salesreturnsubs_salesorder_subid_foreign` FOREIGN KEY (`salesorder_subid`) REFERENCES `salesorder_subs` (`id`);

--
-- Constraints for table `sales_dcs`
--
ALTER TABLE `sales_dcs`
  ADD CONSTRAINT `sales_dcs_branch_id_foreign` FOREIGN KEY (`branch_id`) REFERENCES `branch_creations` (`id`),
  ADD CONSTRAINT `sales_dcs_customer_id_foreign` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`),
  ADD CONSTRAINT `sales_dcs_deliverysite_id_foreign` FOREIGN KEY (`deliverysite_id`) REFERENCES `customeraddresses` (`id`),
  ADD CONSTRAINT `sales_dcs_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `sales_dcs_groupcompany_id_foreign` FOREIGN KEY (`groupcompany_id`) REFERENCES `groupcompanies` (`id`),
  ADD CONSTRAINT `sales_dcs_outertrip_id_foreign` FOREIGN KEY (`outertrip_id`) REFERENCES `outersalestrips` (`id`),
  ADD CONSTRAINT `sales_dcs_paymentterm_id_foreign` FOREIGN KEY (`paymentterm_id`) REFERENCES `paymentterms` (`id`),
  ADD CONSTRAINT `sales_dcs_sales_id_foreign` FOREIGN KEY (`sales_id`) REFERENCES `salesorders` (`id`),
  ADD CONSTRAINT `sales_dcs_salesperson_id_foreign` FOREIGN KEY (`salesperson_id`) REFERENCES `staffbranches` (`id`),
  ADD CONSTRAINT `sales_dcs_tax_id_foreign` FOREIGN KEY (`tax_id`) REFERENCES `taxes` (`id`);

--
-- Constraints for table `sales_dc_subs`
--
ALTER TABLE `sales_dc_subs`
  ADD CONSTRAINT `sales_dc_subs_main_id_foreign` FOREIGN KEY (`main_id`) REFERENCES `sales_dcs` (`id`),
  ADD CONSTRAINT `sales_dc_subs_outertrip_sub_id_foreign` FOREIGN KEY (`outertrip_sub_id`) REFERENCES `outersalestripsubs` (`id`),
  ADD CONSTRAINT `sales_dc_subs_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`),
  ADD CONSTRAINT `sales_dc_subs_sales_sub_id_foreign` FOREIGN KEY (`sales_sub_id`) REFERENCES `salesorder_subs` (`id`),
  ADD CONSTRAINT `sales_dc_subs_tax_id_foreign` FOREIGN KEY (`tax_id`) REFERENCES `taxes` (`id`),
  ADD CONSTRAINT `sales_dc_subs_uom_id_foreign` FOREIGN KEY (`uom_id`) REFERENCES `uoms` (`id`);

--
-- Constraints for table `schedulepayments`
--
ALTER TABLE `schedulepayments`
  ADD CONSTRAINT `schedulepayments_asset_id_foreign` FOREIGN KEY (`asset_id`) REFERENCES `assets` (`id`),
  ADD CONSTRAINT `schedulepayments_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `schedulepayments_group_company_id_foreign` FOREIGN KEY (`group_company_id`) REFERENCES `groupcompanies` (`id`),
  ADD CONSTRAINT `schedulepayments_loan_account_id_foreign` FOREIGN KEY (`loan_account_id`) REFERENCES `accounts_ledgers` (`id`),
  ADD CONSTRAINT `schedulepayments_paid_through_foreign` FOREIGN KEY (`paid_through`) REFERENCES `accounts_ledgers` (`id`);

--
-- Constraints for table `service_bills`
--
ALTER TABLE `service_bills`
  ADD CONSTRAINT `service_bills_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `service_bills_expense_type_id_foreign` FOREIGN KEY (`expense_type_id`) REFERENCES `expense_types` (`id`),
  ADD CONSTRAINT `service_bills_group_company_id_foreign` FOREIGN KEY (`group_company_id`) REFERENCES `groupcompanies` (`id`),
  ADD CONSTRAINT `service_bills_job_card_id_foreign` FOREIGN KEY (`job_card_id`) REFERENCES `job_cards` (`id`),
  ADD CONSTRAINT `service_bills_other_id_foreign` FOREIGN KEY (`other_id`) REFERENCES `accounts_ledgers` (`id`),
  ADD CONSTRAINT `service_bills_supplier_id_foreign` FOREIGN KEY (`supplier_id`) REFERENCES `suppliers` (`id`),
  ADD CONSTRAINT `service_bills_tcs_id_foreign` FOREIGN KEY (`tcs_id`) REFERENCES `tcs` (`id`),
  ADD CONSTRAINT `service_bills_tds_id_foreign` FOREIGN KEY (`tds_id`) REFERENCES `tds` (`id`),
  ADD CONSTRAINT `service_bills_tds_ledger_foreign` FOREIGN KEY (`tds_ledger`) REFERENCES `accounts_ledgers` (`id`);

--
-- Constraints for table `service_bill_subs`
--
ALTER TABLE `service_bill_subs`
  ADD CONSTRAINT `service_bill_subs_service_bill_id_foreign` FOREIGN KEY (`service_bill_id`) REFERENCES `service_bills` (`id`),
  ADD CONSTRAINT `service_bill_subs_uom_id_foreign` FOREIGN KEY (`uom_id`) REFERENCES `uoms` (`id`);

--
-- Constraints for table `service_bill_uploads`
--
ALTER TABLE `service_bill_uploads`
  ADD CONSTRAINT `service_bill_uploads_bill_id_foreign` FOREIGN KEY (`bill_id`) REFERENCES `service_bills` (`id`);

--
-- Constraints for table `staffbranches`
--
ALTER TABLE `staffbranches`
  ADD CONSTRAINT `staffbranches_staff_id_foreign` FOREIGN KEY (`staff_id`) REFERENCES `employees` (`id`);

--
-- Constraints for table `standard_boms`
--
ALTER TABLE `standard_boms`
  ADD CONSTRAINT `standard_boms_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `standard_boms_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `standard_boms_uom_id_foreign` FOREIGN KEY (`uom_id`) REFERENCES `uoms` (`id`);

--
-- Constraints for table `standard_bom_subs`
--
ALTER TABLE `standard_bom_subs`
  ADD CONSTRAINT `standard_bom_subs_main_id_foreign` FOREIGN KEY (`main_id`) REFERENCES `standard_boms` (`id`),
  ADD CONSTRAINT `standard_bom_subs_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`),
  ADD CONSTRAINT `standard_bom_subs_uom_id_foreign` FOREIGN KEY (`uom_id`) REFERENCES `uoms` (`id`);

--
-- Constraints for table `stockadjustments`
--
ALTER TABLE `stockadjustments`
  ADD CONSTRAINT `stockadjustments_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `stockadjustments_reason_id_foreign` FOREIGN KEY (`reason_id`) REFERENCES `stockreasons` (`id`),
  ADD CONSTRAINT `stockadjustments_warehouse_id_foreign` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`);

--
-- Constraints for table `stockadjustment_subs`
--
ALTER TABLE `stockadjustment_subs`
  ADD CONSTRAINT `stockadjustment_subs_brand_name_foreign` FOREIGN KEY (`brand_name`) REFERENCES `product_vendors_subs` (`id`),
  ADD CONSTRAINT `stockadjustment_subs_main_id_foreign` FOREIGN KEY (`main_id`) REFERENCES `stockadjustments` (`id`),
  ADD CONSTRAINT `stockadjustment_subs_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`);

--
-- Constraints for table `stocks`
--
ALTER TABLE `stocks`
  ADD CONSTRAINT `stocks_brand_name_foreign` FOREIGN KEY (`brand_name`) REFERENCES `product_vendors_subs` (`id`),
  ADD CONSTRAINT `stocks_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `stocks_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`),
  ADD CONSTRAINT `stocks_purchase_uom_id_foreign` FOREIGN KEY (`purchase_uom_id`) REFERENCES `uoms` (`id`),
  ADD CONSTRAINT `stocks_uom_id_foreign` FOREIGN KEY (`uom_id`) REFERENCES `uoms` (`id`),
  ADD CONSTRAINT `stocks_warehouse_id_foreign` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`);

--
-- Constraints for table `stocktransfers`
--
ALTER TABLE `stocktransfers`
  ADD CONSTRAINT `stocktransfers_destination_division_id_foreign` FOREIGN KEY (`destination_division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `stocktransfers_destination_warehouse_id_foreign` FOREIGN KEY (`destination_warehouse_id`) REFERENCES `warehouses` (`id`),
  ADD CONSTRAINT `stocktransfers_source_division_id_foreign` FOREIGN KEY (`source_division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `stocktransfers_source_warehouse_id_foreign` FOREIGN KEY (`source_warehouse_id`) REFERENCES `warehouses` (`id`);

--
-- Constraints for table `stocktransfer_subs`
--
ALTER TABLE `stocktransfer_subs`
  ADD CONSTRAINT `stocktransfer_subs_brand_name_foreign` FOREIGN KEY (`brand_name`) REFERENCES `product_vendors_subs` (`id`),
  ADD CONSTRAINT `stocktransfer_subs_main_id_foreign` FOREIGN KEY (`main_id`) REFERENCES `stocktransfers` (`id`),
  ADD CONSTRAINT `stocktransfer_subs_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`);

--
-- Constraints for table `stock_locations`
--
ALTER TABLE `stock_locations`
  ADD CONSTRAINT `stock_locations_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `stock_locations_warehouse_id_foreign` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`);

--
-- Constraints for table `supplierrefunds`
--
ALTER TABLE `supplierrefunds`
  ADD CONSTRAINT `supplierrefunds_debitnote_id_foreign` FOREIGN KEY (`debitnote_id`) REFERENCES `purchasereturns` (`id`),
  ADD CONSTRAINT `supplierrefunds_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `supplierrefunds_groupcompany_id_foreign` FOREIGN KEY (`groupcompany_id`) REFERENCES `groupcompanies` (`id`),
  ADD CONSTRAINT `supplierrefunds_ledger_id_foreign` FOREIGN KEY (`ledger_id`) REFERENCES `accounts_ledgers` (`id`),
  ADD CONSTRAINT `supplierrefunds_payment_id_foreign` FOREIGN KEY (`payment_id`) REFERENCES `vendor_payments` (`id`),
  ADD CONSTRAINT `supplierrefunds_supplier_id_foreign` FOREIGN KEY (`supplier_id`) REFERENCES `suppliers` (`id`);

--
-- Constraints for table `suppliers`
--
ALTER TABLE `suppliers`
  ADD CONSTRAINT `suppliers_payment_terms_id_foreign` FOREIGN KEY (`payment_terms_id`) REFERENCES `paymentterms` (`id`);

--
-- Constraints for table `supplier_transactions`
--
ALTER TABLE `supplier_transactions`
  ADD CONSTRAINT `supplier_transactions_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `supplier_transactions_groupcompany_id_foreign` FOREIGN KEY (`groupcompany_id`) REFERENCES `groupcompanies` (`id`),
  ADD CONSTRAINT `supplier_transactions_supplier_id_foreign` FOREIGN KEY (`supplier_id`) REFERENCES `suppliers` (`id`);

--
-- Constraints for table `transport_routings`
--
ALTER TABLE `transport_routings`
  ADD CONSTRAINT `transport_routings_asset_id_foreign` FOREIGN KEY (`asset_id`) REFERENCES `assets` (`id`),
  ADD CONSTRAINT `transport_routings_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `transport_routings_uom_id_foreign` FOREIGN KEY (`uom_id`) REFERENCES `uoms` (`id`);

--
-- Constraints for table `transport_routing_subs`
--
ALTER TABLE `transport_routing_subs`
  ADD CONSTRAINT `transport_routing_subs_route_id_foreign` FOREIGN KEY (`route_id`) REFERENCES `transport_routings` (`id`),
  ADD CONSTRAINT `transport_routing_subs_workcenter_id_foreign` FOREIGN KEY (`workcenter_id`) REFERENCES `workcenters` (`id`);

--
-- Constraints for table `truckassigns`
--
ALTER TABLE `truckassigns`
  ADD CONSTRAINT `truckassigns_driver_id_foreign` FOREIGN KEY (`driver_id`) REFERENCES `employees` (`id`),
  ADD CONSTRAINT `truckassigns_shift_id_foreign` FOREIGN KEY (`shift_id`) REFERENCES `shiftcreations` (`id`),
  ADD CONSTRAINT `truckassigns_truck_id_foreign` FOREIGN KEY (`truck_id`) REFERENCES `assets` (`id`);

--
-- Constraints for table `users`
--
ALTER TABLE `users`
  ADD CONSTRAINT `users_emp_id_foreign` FOREIGN KEY (`emp_id`) REFERENCES `employees` (`id`);

--
-- Constraints for table `vehiclemeterreadings`
--
ALTER TABLE `vehiclemeterreadings`
  ADD CONSTRAINT `vehiclemeterreadings_vehicle_id_foreign` FOREIGN KEY (`vehicle_id`) REFERENCES `assets` (`id`);

--
-- Constraints for table `vendoropening_balances`
--
ALTER TABLE `vendoropening_balances`
  ADD CONSTRAINT `vendoropening_balances_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `vendoropening_balances_supplier_id_foreign` FOREIGN KEY (`supplier_id`) REFERENCES `suppliers` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `vendor_bills`
--
ALTER TABLE `vendor_bills`
  ADD CONSTRAINT `vendor_bills_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `vendor_bills_groupcompany_id_foreign` FOREIGN KEY (`groupcompany_id`) REFERENCES `groupcompanies` (`id`),
  ADD CONSTRAINT `vendor_bills_supplier_id_foreign` FOREIGN KEY (`supplier_id`) REFERENCES `suppliers` (`id`);

--
-- Constraints for table `vendor_payments`
--
ALTER TABLE `vendor_payments`
  ADD CONSTRAINT `vendor_payments_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `vendor_payments_groupcompany_id_foreign` FOREIGN KEY (`groupcompany_id`) REFERENCES `groupcompanies` (`id`),
  ADD CONSTRAINT `vendor_payments_ledger_id_foreign` FOREIGN KEY (`ledger_id`) REFERENCES `accounts_ledgers` (`id`),
  ADD CONSTRAINT `vendor_payments_supplier_id_foreign` FOREIGN KEY (`supplier_id`) REFERENCES `suppliers` (`id`);

--
-- Constraints for table `vendor_payment_subs`
--
ALTER TABLE `vendor_payment_subs`
  ADD CONSTRAINT `vendor_payment_subs_payment_id_foreign` FOREIGN KEY (`payment_id`) REFERENCES `vendor_payments` (`id`);

--
-- Constraints for table `wages_creations`
--
ALTER TABLE `wages_creations`
  ADD CONSTRAINT `wages_creations_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `wages_creations_salary_type_foreign` FOREIGN KEY (`salary_type`) REFERENCES `salary_types` (`id`);

--
-- Constraints for table `wages_creation_subs`
--
ALTER TABLE `wages_creation_subs`
  ADD CONSTRAINT `wages_creation_subs_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `wages_creation_subs_emp_id_foreign` FOREIGN KEY (`emp_id`) REFERENCES `employees` (`id`),
  ADD CONSTRAINT `wages_creation_subs_salary_type_foreign` FOREIGN KEY (`salary_type`) REFERENCES `salary_types` (`id`),
  ADD CONSTRAINT `wages_creation_subs_wages_id_foreign` FOREIGN KEY (`wages_id`) REFERENCES `wages_creations` (`id`);

--
-- Constraints for table `warehouses`
--
ALTER TABLE `warehouses`
  ADD CONSTRAINT `warehouses_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `warehouses_product_category_id_foreign` FOREIGN KEY (`product_category_id`) REFERENCES `productcategories` (`id`);

--
-- Constraints for table `workcenters`
--
ALTER TABLE `workcenters`
  ADD CONSTRAINT `workcenters_activity_id_foreign` FOREIGN KEY (`activity_id`) REFERENCES `activitycenters` (`id`),
  ADD CONSTRAINT `workcenters_asset_id_foreign` FOREIGN KEY (`asset_id`) REFERENCES `assets` (`id`);

--
-- Constraints for table `workcenter_standardcosts`
--
ALTER TABLE `workcenter_standardcosts`
  ADD CONSTRAINT `workcenter_standardcosts_workcenter_id_foreign` FOREIGN KEY (`workcenter_id`) REFERENCES `workcenters` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `workcenter_standardcosts_worktype_id_foreign` FOREIGN KEY (`worktype_id`) REFERENCES `worktypes` (`id`);

--
-- Constraints for table `workorderbilldeductions`
--
ALTER TABLE `workorderbilldeductions`
  ADD CONSTRAINT `workorderbilldeductions_workorderbill_id_foreign` FOREIGN KEY (`workorderbill_id`) REFERENCES `workorderbills` (`id`);

--
-- Constraints for table `workorderbills`
--
ALTER TABLE `workorderbills`
  ADD CONSTRAINT `workorderbills_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `workorderbills_group_company_id_foreign` FOREIGN KEY (`group_company_id`) REFERENCES `groupcompanies` (`id`),
  ADD CONSTRAINT `workorderbills_supplier_id_foreign` FOREIGN KEY (`supplier_id`) REFERENCES `suppliers` (`id`),
  ADD CONSTRAINT `workorderbills_workorder_id_foreign` FOREIGN KEY (`workorder_id`) REFERENCES `workorders` (`id`);

--
-- Constraints for table `workorderbillsubs`
--
ALTER TABLE `workorderbillsubs`
  ADD CONSTRAINT `workorderbillsubs_main_id_foreign` FOREIGN KEY (`main_id`) REFERENCES `workorderbills` (`id`),
  ADD CONSTRAINT `workorderbillsubs_tax_id_foreign` FOREIGN KEY (`tax_id`) REFERENCES `taxes` (`id`),
  ADD CONSTRAINT `workorderbillsubs_workorder_id_foreign` FOREIGN KEY (`workorder_id`) REFERENCES `workorders` (`id`),
  ADD CONSTRAINT `workorderbillsubs_workordersub_id_foreign` FOREIGN KEY (`workordersub_id`) REFERENCES `workordersubs` (`id`);

--
-- Constraints for table `workorderdedcutions`
--
ALTER TABLE `workorderdedcutions`
  ADD CONSTRAINT `workorderdedcutions_workorder_id_foreign` FOREIGN KEY (`workorder_id`) REFERENCES `workorders` (`id`);

--
-- Constraints for table `workorderlogs`
--
ALTER TABLE `workorderlogs`
  ADD CONSTRAINT `workorderlogs_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `workorderlogs_ibfk_1` FOREIGN KEY (`project_id`) REFERENCES `projectcreations` (`id`),
  ADD CONSTRAINT `workorderlogs_production_id_foreign` FOREIGN KEY (`production_id`) REFERENCES `production_orders` (`id`),
  ADD CONSTRAINT `workorderlogs_production_log_id_foreign` FOREIGN KEY (`production_log_id`) REFERENCES `production_order_logs` (`id`),
  ADD CONSTRAINT `workorderlogs_supplier_id_foreign` FOREIGN KEY (`supplier_id`) REFERENCES `suppliers` (`id`),
  ADD CONSTRAINT `workorderlogs_work_center_id_foreign` FOREIGN KEY (`work_center_id`) REFERENCES `work_centers` (`id`),
  ADD CONSTRAINT `workorderlogs_workorder_id_foreign` FOREIGN KEY (`workorder_id`) REFERENCES `workorders` (`id`);

--
-- Constraints for table `workorderlogsubs`
--
ALTER TABLE `workorderlogsubs`
  ADD CONSTRAINT `workorderlogsubs_main_id_foreign` FOREIGN KEY (`main_id`) REFERENCES `workorderlogs` (`id`),
  ADD CONSTRAINT `workorderlogsubs_workorder_id_foreign` FOREIGN KEY (`workorder_id`) REFERENCES `workorders` (`id`),
  ADD CONSTRAINT `workorderlogsubs_workordersub_id_foreign` FOREIGN KEY (`workordersub_id`) REFERENCES `workordersubs` (`id`);

--
-- Constraints for table `workorders`
--
ALTER TABLE `workorders`
  ADD CONSTRAINT `workorders_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`),
  ADD CONSTRAINT `workorders_ledger_id_foreign` FOREIGN KEY (`ledger_id`) REFERENCES `accounts_ledgers` (`id`),
  ADD CONSTRAINT `workorders_project_id_foreign` FOREIGN KEY (`project_id`) REFERENCES `projectcreations` (`id`),
  ADD CONSTRAINT `workorders_supplier_id_foreign` FOREIGN KEY (`supplier_id`) REFERENCES `suppliers` (`id`);

--
-- Constraints for table `workordersubs`
--
ALTER TABLE `workordersubs`
  ADD CONSTRAINT `workordersubs_activity_id_foreign` FOREIGN KEY (`activity_id`) REFERENCES `workorderactivities` (`id`),
  ADD CONSTRAINT `workordersubs_main_id_foreign` FOREIGN KEY (`main_id`) REFERENCES `workorders` (`id`),
  ADD CONSTRAINT `workordersubs_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`),
  ADD CONSTRAINT `workordersubs_tax_id_foreign` FOREIGN KEY (`tax_id`) REFERENCES `taxes` (`id`),
  ADD CONSTRAINT `workordersubs_uom_id_foreign` FOREIGN KEY (`uom_id`) REFERENCES `uoms` (`id`);

--
-- Constraints for table `work_centers`
--
ALTER TABLE `work_centers`
  ADD CONSTRAINT `work_centers_contractor_id_foreign` FOREIGN KEY (`contractor_id`) REFERENCES `suppliers` (`id`),
  ADD CONSTRAINT `work_centers_division_id_foreign` FOREIGN KEY (`division_id`) REFERENCES `divisions` (`id`);

--
-- Constraints for table `work_center_cost_data`
--
ALTER TABLE `work_center_cost_data`
  ADD CONSTRAINT `work_center_cost_data_cost_type_id_foreign` FOREIGN KEY (`cost_type_id`) REFERENCES `work_center_cost_types` (`id`),
  ADD CONSTRAINT `work_center_cost_data_work_center_id_foreign` FOREIGN KEY (`work_center_id`) REFERENCES `work_centers` (`id`);
COMMIT;