-- stationId > 600 的 /outOrder 不再立即生成 WrkMast/WrkDetl，
-- 而是先把 ERP 参数完整落到出库订单明细，后续定时器再还原参数生成任务。
-- 因此 man_order_detl_pakout 需要保存接口字段。

IF COL_LENGTH('dbo.man_order_detl_pakout', 'batch_seq') IS NULL
BEGIN
    ALTER TABLE [dbo].[man_order_detl_pakout]
        ADD [batch_seq] NVARCHAR(100) NULL;
END
GO

IF COL_LENGTH('dbo.man_order_detl_pakout', 'seq') IS NULL
BEGIN
    ALTER TABLE [dbo].[man_order_detl_pakout]
        ADD [seq] INT NULL;
END
GO

IF COL_LENGTH('dbo.man_order_detl_pakout', 'pallet_id') IS NULL
BEGIN
    ALTER TABLE [dbo].[man_order_detl_pakout]
        ADD [pallet_id] NVARCHAR(100) NULL;
END
GO

IF COL_LENGTH('dbo.man_order_detl_pakout', 'station_id') IS NULL
BEGIN
    ALTER TABLE [dbo].[man_order_detl_pakout]
        ADD [station_id] NVARCHAR(100) NULL;
END
GO

IF COL_LENGTH('dbo.man_order_detl_pakout', 'entry_wms_code') IS NULL
BEGIN
    ALTER TABLE [dbo].[man_order_detl_pakout]
        ADD [entry_wms_code] NVARCHAR(100) NULL;
END
GO

IF COL_LENGTH('dbo.man_order_detl_pakout', 'container_no') IS NULL
BEGIN
    ALTER TABLE [dbo].[man_order_detl_pakout]
        ADD [container_no] NVARCHAR(100) NULL;
END
GO

IF COL_LENGTH('dbo.man_order_detl_pakout', 'out_door_no') IS NULL
BEGIN
    ALTER TABLE [dbo].[man_order_detl_pakout]
        ADD [out_door_no] NVARCHAR(100) NULL;
END
GO

IF COL_LENGTH('dbo.man_order_detl_pakout', 'plate_no') IS NULL
BEGIN
    ALTER TABLE [dbo].[man_order_detl_pakout]
        ADD [plate_no] NVARCHAR(100) NULL;
END
GO

IF COL_LENGTH('dbo.man_order_detl_pakout', 'train_no') IS NULL
BEGIN
    ALTER TABLE [dbo].[man_order_detl_pakout]
        ADD [train_no] NVARCHAR(100) NULL;
END
GO

IF COL_LENGTH('dbo.man_order_detl_pakout', 'freq_type') IS NULL
BEGIN
    ALTER TABLE [dbo].[man_order_detl_pakout]
        ADD [freq_type] INT NULL;
END
GO

IF COL_LENGTH('dbo.man_order_detl_pakout', 'cube_number') IS NULL
BEGIN
    ALTER TABLE [dbo].[man_order_detl_pakout]
        ADD [cube_number] DECIMAL(18, 4) NULL;
END
GO

IF COL_LENGTH('dbo.man_order_detl_pakout', 'teu') IS NULL
BEGIN
    ALTER TABLE [dbo].[man_order_detl_pakout]
        ADD [teu] INT NULL;
END
GO

-- 现有归档逻辑使用 INSERT INTO man_order_detl_log_pakout SELECT * FROM man_order_detl_pakout。
-- 两张表字段必须同步补齐，否则订单明细归档时会因为列数不一致失败。

IF COL_LENGTH('dbo.man_order_detl_log_pakout', 'batch_seq') IS NULL
BEGIN
    ALTER TABLE [dbo].[man_order_detl_log_pakout]
        ADD [batch_seq] NVARCHAR(100) NULL;
END
GO

IF COL_LENGTH('dbo.man_order_detl_log_pakout', 'seq') IS NULL
BEGIN
    ALTER TABLE [dbo].[man_order_detl_log_pakout]
        ADD [seq] INT NULL;
END
GO

IF COL_LENGTH('dbo.man_order_detl_log_pakout', 'pallet_id') IS NULL
BEGIN
    ALTER TABLE [dbo].[man_order_detl_log_pakout]
        ADD [pallet_id] NVARCHAR(100) NULL;
END
GO

IF COL_LENGTH('dbo.man_order_detl_log_pakout', 'station_id') IS NULL
BEGIN
    ALTER TABLE [dbo].[man_order_detl_log_pakout]
        ADD [station_id] NVARCHAR(100) NULL;
END
GO

IF COL_LENGTH('dbo.man_order_detl_log_pakout', 'entry_wms_code') IS NULL
BEGIN
    ALTER TABLE [dbo].[man_order_detl_log_pakout]
        ADD [entry_wms_code] NVARCHAR(100) NULL;
END
GO

IF COL_LENGTH('dbo.man_order_detl_log_pakout', 'container_no') IS NULL
BEGIN
    ALTER TABLE [dbo].[man_order_detl_log_pakout]
        ADD [container_no] NVARCHAR(100) NULL;
END
GO

IF COL_LENGTH('dbo.man_order_detl_log_pakout', 'out_door_no') IS NULL
BEGIN
    ALTER TABLE [dbo].[man_order_detl_log_pakout]
        ADD [out_door_no] NVARCHAR(100) NULL;
END
GO

IF COL_LENGTH('dbo.man_order_detl_log_pakout', 'plate_no') IS NULL
BEGIN
    ALTER TABLE [dbo].[man_order_detl_log_pakout]
        ADD [plate_no] NVARCHAR(100) NULL;
END
GO

IF COL_LENGTH('dbo.man_order_detl_log_pakout', 'train_no') IS NULL
BEGIN
    ALTER TABLE [dbo].[man_order_detl_log_pakout]
        ADD [train_no] NVARCHAR(100) NULL;
END
GO

IF COL_LENGTH('dbo.man_order_detl_log_pakout', 'freq_type') IS NULL
BEGIN
    ALTER TABLE [dbo].[man_order_detl_log_pakout]
        ADD [freq_type] INT NULL;
END
GO

IF COL_LENGTH('dbo.man_order_detl_log_pakout', 'cube_number') IS NULL
BEGIN
    ALTER TABLE [dbo].[man_order_detl_log_pakout]
        ADD [cube_number] DECIMAL(18, 4) NULL;
END
GO

IF COL_LENGTH('dbo.man_order_detl_log_pakout', 'teu') IS NULL
BEGIN
    ALTER TABLE [dbo].[man_order_detl_log_pakout]
        ADD [teu] INT NULL;
END
GO
