CREATE TABLE sales_ledger_product_process
(
    id               INT PRIMARY KEY AUTO_INCREMENT,
    sales_product_id INT          NOT NULL COMMENT '销售产品ID(关联sales_ledger_product.id)',
    process_name     VARCHAR(100) NOT NULL COMMENT '工艺名称',
    quantity         DECIMAL(12, 3) DEFAULT NULL COMMENT '数量',
    unit_price       DECIMAL(10, 2) DEFAULT NULL COMMENT '单价',
    remark           VARCHAR(255)   DEFAULT NULL,
    create_time      DATETIME       DEFAULT CURRENT_TIMESTAMP
) COMMENT ='销售产品加工明细';


DROP TABLE IF EXISTS `sales_ledger_product_process_bind`;
CREATE TABLE `sales_ledger_product_process_bind`
(
    `id`                              int NOT NULL AUTO_INCREMENT COMMENT '主键',
    `sales_ledger_product_id`         int NULL DEFAULT NULL COMMENT '销售台账产品信息ID',
    `sales_ledger_product_process_id` int NULL DEFAULT NULL COMMENT '销售产品加工明细ID',
    `quantity`                        int NULL DEFAULT NULL COMMENT '加工数量',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB
  AUTO_INCREMENT = 2
  CHARACTER SET = utf8mb3
  COLLATE = utf8mb3_general_ci COMMENT = '销售产品额外加工数量'
  ROW_FORMAT = Dynamic;

SET FOREIGN_KEY_CHECKS = 1;

ALTER TABLE sales_ledger_product
    ADD COLUMN actual_piece_area DECIMAL(18, 6) DEFAULT NULL COMMENT '实际单片面积(㎡)',
    ADD COLUMN actual_total_area DECIMAL(18, 6) DEFAULT NULL COMMENT '实际总面积(㎡)',
    ADD COLUMN settle_piece_area DECIMAL(18, 6) DEFAULT NULL COMMENT '结算单片面积(㎡)',
    ADD COLUMN settle_total_area DECIMAL(18, 6) DEFAULT NULL COMMENT '结算总面积(㎡)';

ALTER TABLE sales_ledger_product
    ADD COLUMN process_requirement VARCHAR(500) DEFAULT NULL COMMENT '加工要求';
ALTER TABLE sales_ledger_product
    ADD COLUMN remark VARCHAR(500) DEFAULT NULL COMMENT '备注';

ALTER TABLE sales_ledger_product_process
    CHANGE COLUMN remark code VARCHAR(255) COMMENT '编码';