-- ============================================================
-- Buyer PO Destinations — multi-destination delivery support
-- Follows SAP FMS Buyer PO architecture
-- ============================================================

SET FOREIGN_KEY_CHECKS = 0;

CREATE TABLE IF NOT EXISTS `buyer_po_destinations` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `company_id` int unsigned NOT NULL DEFAULT 1,
  `po_id` int unsigned NOT NULL,
  `destination_name` varchar(255) NOT NULL COMMENT 'Port / city / warehouse',
  `country` varchar(100) DEFAULT NULL,
  `address` text DEFAULT NULL,
  `contact_person` varchar(255) DEFAULT NULL,
  `contact_phone` varchar(50) DEFAULT NULL,
  `contact_email` varchar(255) DEFAULT NULL,
  `quantity` int unsigned NOT NULL DEFAULT 0 COMMENT 'Units allocated to this destination',
  `delivery_date` date DEFAULT NULL,
  `mode_of_shipment` varchar(50) DEFAULT NULL COMMENT 'Sea, Air, Road, Rail',
  `incoterms` varchar(20) DEFAULT NULL COMMENT 'FOB, CIF, DDP, EXW, etc.',
  `status` enum('pending','partially_shipped','shipped','delivered') NOT NULL DEFAULT 'pending',
  `notes` text DEFAULT NULL,
  `display_order` int unsigned NOT NULL DEFAULT 0,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `po_id` (`po_id`),
  KEY `company_id` (`company_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

SET FOREIGN_KEY_CHECKS = 1;
