CREATE TABLE `stock_replenishment_requests` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `client_uuid` char(36) DEFAULT NULL,
  `request_number` varchar(30) DEFAULT NULL,
  `salesman_id` bigint(20) unsigned NOT NULL,
  `status` varchar(40) NOT NULL DEFAULT 'draft',
  `salesman_note` text DEFAULT NULL,
  `admin_approval_note` text DEFAULT NULL,
  `warehouse_note` text DEFAULT NULL,
  `admin_release_note` text DEFAULT NULL,
  `dispatch_note` text DEFAULT NULL,
  `receiving_note` text DEFAULT NULL,
  `decision_reason` text DEFAULT NULL,
  `return_to_warehouse_reason` text DEFAULT NULL,
  `submitted_at` timestamp NULL DEFAULT NULL,
  `submitted_by` bigint(20) unsigned DEFAULT NULL,
  `approved_at` timestamp NULL DEFAULT NULL,
  `approved_by` bigint(20) unsigned DEFAULT NULL,
  `preparation_started_at` timestamp NULL DEFAULT NULL,
  `preparation_started_by` bigint(20) unsigned DEFAULT NULL,
  `prepared_at` timestamp NULL DEFAULT NULL,
  `prepared_by` bigint(20) unsigned DEFAULT NULL,
  `released_at` timestamp NULL DEFAULT NULL,
  `released_by` bigint(20) unsigned DEFAULT NULL,
  `dispatched_at` timestamp NULL DEFAULT NULL,
  `dispatched_by` bigint(20) unsigned DEFAULT NULL,
  `receiving_started_at` timestamp NULL DEFAULT NULL,
  `completed_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `is_test_data` tinyint(1) NOT NULL DEFAULT 0,
  `qa_owner_user_id` bigint(20) unsigned DEFAULT NULL,
  `qa_archived_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `stock_replenishment_requests_client_uuid_unique` (`client_uuid`),
  UNIQUE KEY `stock_replenishment_requests_request_number_unique` (`request_number`),
  KEY `stock_replenishment_requests_salesman_id_status_index` (`salesman_id`,`status`),
  KEY `sr_req_submitted_by_fk` (`submitted_by`),
  KEY `sr_req_approved_by_fk` (`approved_by`),
  KEY `sr_req_preparation_started_by_fk` (`preparation_started_by`),
  KEY `sr_req_prepared_by_fk` (`prepared_by`),
  KEY `sr_req_released_by_fk` (`released_by`),
  KEY `sr_req_dispatched_by_fk` (`dispatched_by`),
  KEY `stock_replenishment_requests_status_index` (`status`),
  KEY `stock_replenishment_requests_qa_owner_user_id_foreign` (`qa_owner_user_id`),
  KEY `stock_replenishment_requests_is_test_data_index` (`is_test_data`),
  KEY `stock_replenishment_requests_qa_archived_at_index` (`qa_archived_at`),
  CONSTRAINT `sr_req_approved_by_fk` FOREIGN KEY (`approved_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `sr_req_dispatched_by_fk` FOREIGN KEY (`dispatched_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `sr_req_preparation_started_by_fk` FOREIGN KEY (`preparation_started_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `sr_req_prepared_by_fk` FOREIGN KEY (`prepared_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `sr_req_released_by_fk` FOREIGN KEY (`released_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `sr_req_salesman_fk` FOREIGN KEY (`salesman_id`) REFERENCES `users` (`id`),
  CONSTRAINT `sr_req_submitted_by_fk` FOREIGN KEY (`submitted_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `stock_replenishment_requests_qa_owner_user_id_foreign` FOREIGN KEY (`qa_owner_user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
