package cn.estsh.i3plus.pojo.wms.bean;

import cn.estsh.i3plus.pojo.base.annotation.AnnoOutputColumn;
import cn.estsh.i3plus.pojo.base.bean.BaseBean;
import cn.estsh.i3plus.pojo.base.enumutil.WmsEnumUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Index;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.Version;

/**
 * @Description : PO订单明细信息
 * @Reference :
 * @Author : silliter.yuan
 * @CreateDate : 2018-11-06 15:58
 * @Modify:
 **/
@Data
@Entity
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Table(name = "WMS_DOC_PO_DETAILS", indexes = {
        @Index(columnList = "ORDER_NO"),
        @Index(columnList = "PART_NO"),
        @Index(columnList = "ORGANIZE_CODE")
})
@Api("PO订单明细信息")
public class WmsPOMasterDetails extends BaseBean {

    private static final long serialVersionUID = -677572691809622129L;

    @Column(name = "PART_NO")
    @ApiParam("物料编码")
    private String partNo;

    @Column(name = "BOX_QTY", nullable = false)
    @ColumnDefault("0")
    @ApiParam(value = "箱数", example = "0")
    private Integer boxQty;

    @Column(name = "PART_NAME_RDD")
    @ApiParam("物料名称")
    private String partNameRdd;

    @Column(name = "ITEM")
    @ApiParam("行号")
    private Integer item;

    @Column(name = "QTY", columnDefinition = "decimal(18,8)", nullable = false)
    @ColumnDefault("0")
    @ApiParam(value = "需求数量", example = "0")
    private Double qty;

    // 不可能为 null 值
    // Rock.Yu at 2019-06-22 20:03
    //private Double getQty(){ return this.qty == null ? new Double(0) : this.qty; }

    @Column(name = "UNIT")
    @ApiParam("单位")
    private String unit;

    @Column(name = "ORDER_NO")
    @ApiParam("订单号")
    private String orderNo;

    @Column(name = "PRINT_QTY", columnDefinition = "decimal(18,8)", nullable = false)
    @ColumnDefault("0")
    @ApiParam(value = "条码打印数量", example = "0")
    private Double printQty;

    //private Double getPrintQty(){ return this.printQty == null ? new Double(0) : this.printQty; }

    @Column(name = "RC_QTY", columnDefinition = "decimal(18,8)", nullable = false)
    @ColumnDefault("0")
    @ApiParam(value = "收货数量", example = "0")
    private Double rcQty = 0d;

    //private Double getRcQty(){ return this.rcQty == null ? new Double(0) : this.rcQty; }

    @Column(name = "PASS_QTY", columnDefinition = "decimal(18,8)", nullable = false)
    @ColumnDefault("0")
    @ApiParam(value = "质检合格数量", example = "0")
    private Double passQty;

    //private Double getPassQty(){ return this.passQty == null ? new Double(0) : this.passQty; }

    @Column(name = "NG_QTY", columnDefinition = "decimal(18,8)", nullable = false)
    @ColumnDefault("0")
    @ApiParam(value = "质检不合格数量", example = "0")
    private Double ngQty;

    //private Double getNgQty(){ return this.ngQty == null ? new Double(0) : this.ngQty; }

    @Column(name = "PLAN_DATE")
    @ApiParam("计划交货日期")
    private String planDate;

    @Column(name = "PLAN_TIME")
    @ApiParam("计划交货时间")
    private String planTime;

    @Transient
    @ApiParam("当前状态")
    private String nowStatus;

    @Transient
    @ApiParam(value = "实际到货日期")
    private String arrDate;

    @Transient
    @ApiParam(value = "实际到货时间")
    private String arrTime;

    @Column(name = "ERP_AREA_NO")
    @ApiParam("默认收货库存地")
    private String erpAreaNo;

    /**
     * 状态:10 N=正常,20 C=行取消
     */
    @Column(name = "ITEM_STATUS")
    @ApiParam("状态")
    @AnnoOutputColumn(refClass = WmsEnumUtil.ORDER_DETAILS_STATUS.class, refForeignKey = "value", value = "description")
    private Integer itemStatus;

    @Column(name = "SNP", columnDefinition = "decimal(18,8)")
    @ApiParam("标准包装")
    private Double snp;

    /**
     * 是否免费:0=计费,1=免费
     */
    @Column(name = "IS_FREE")
    @ApiParam(value = "是否免费", example = "1")
    private Integer isFree;

    @Column(name = "DELAY_HOUR", columnDefinition = "int default 0")
    @ApiParam(value = "容差")
    private Integer delayHour;

    @Column(name = "REMARK")
    @ApiParam("备注")
    private String remark;

    @Transient
    @ApiParam(value = "散件收货输入数量", example = "0")
    private Double inputRcQty;

    @Transient
    @ApiParam(value = "供应商批次")
    private String dateCode;

    @Transient
    @ApiParam(value = "颜色控制")
    private String color;

    @Transient
    @ApiParam("前端表格编辑使用")
    private Boolean isSet = false;

    @Transient
    @ApiParam("道口，临时使用")
    private String dock;

    @Transient
    @ApiParam("收货状态，临时使用")
    private String receiveStatus;



    @Transient
    @ApiParam("供应商批次字段是否可编辑")
    private Boolean isDateCodeEdit = true;

    //private Double getInputRcQty(){ return this.inputRcQty == null ? new Double(0) : this.inputRcQty; }

    @Version
    @Column(name = "LOCK_VERSION", columnDefinition = "int default 0")
    @ApiParam(value = "乐观锁", example = "1")
    private transient Integer lockVersion;

    @Transient
    @ApiParam("PO条码总箱数")
    private Integer totalBoxes;

    @Transient
    @ApiParam("差异")
    private Double difference;

    @Transient
    @ApiParam("集装箱号")
    private String containerNo;


    @Transient
    @ApiParam("采购订单状态")
    @AnnoOutputColumn(refClass = WmsEnumUtil.PURCHASE_PLAN_HISTORY_STATUS.class, refForeignKey = "value", value = "description")
    private Integer purchaseItemStatus;

    @Transient
    @ApiParam("供应商")
    private String vendorNo;

    @Transient
    @ApiParam("供应商名称")
    private String vendorName;

    @Transient
    @ApiParam("开始时间")
    private String planStratDate;

    @Transient
    @ApiParam("结束时间")
    private String planEndDate;

    @Transient
    @ApiParam("erp单号")
    private String erpSrcNo;

    @Transient
    @ApiParam("汇总数量")
    private Double sumQty;

    @Transient
    @ApiParam("汇总收货数量")
    private Double sumRcQty;


    /**
     * 状态:1=新建,10=收货中,20=收货完成,
     * 30=入库中,40=入库完成,90=已关闭,91=已取消
     */
    @Transient
    @ApiParam(value = "状态", example = "1")
    public Integer poStatus;

    public Double getSnpVal() {
        return snp;
    }

    public WmsPOMasterDetails(){}

    public WmsPOMasterDetails(String orderNo,String containerNo,String partNo,Integer item,String organizeCode,String erpAreaNo,Double qty,Double rcQty){
        this.orderNo = orderNo;
        this.containerNo = containerNo;
        this.partNo = partNo;
        this.item = item;
        this.organizeCode = organizeCode;
        this.erpAreaNo = erpAreaNo;
        this.qty = qty;
        this.rcQty = rcQty;
    }

    public WmsPOMasterDetails(String orderNo ,String erpAreaNo,String organizeCode){
        this.orderNo = orderNo;
        this.erpAreaNo = erpAreaNo;
        this.organizeCode = organizeCode;
    }

    public WmsPOMasterDetails(
            String organizeCode,
            String orderNo,
            Integer purchaseItemStatus,
            String planDate,
            String planTime,
            String partNo,
            String partNameRdd,
            Double qty,
            Double rcQty,
            String vendorNo,
            String createUser,
            String createDatetime,
            String modifyUser,
            String modifyDatetime,
            String remark
    ){
        this.organizeCode = organizeCode;
        this.orderNo = orderNo;
        this.purchaseItemStatus = purchaseItemStatus;
        this.planDate = planDate;
        this.planTime = planTime;
        this.partNo = partNo;
        this.partNameRdd = partNameRdd;
        this.qty = qty;
        this.rcQty = rcQty;
        this.vendorNo = vendorNo;
        this.createUser = createUser;
        this.createDatetime = createDatetime;
        this.modifyUser = modifyUser;
        this.modifyDatetime = modifyDatetime;
        this.remark = remark;
    }

    public WmsPOMasterDetails(String partNo,String partNameRdd,String planDate,
            Double snp,Long totalBoxes,Double qty){
        this.partNo = partNo;
        this.partNameRdd = partNameRdd;
        this.planDate = planDate;//批次号（yyyyMMdd）
        this.snp=snp;
        this.totalBoxes = totalBoxes.intValue();
        this.qty = qty;
    }

    public WmsPOMasterDetails(String orderNo, String partNo, String partNameRdd, String planDate, String planTime,
                              Double snp, Long totalBoxes, Double qty) {
        this.orderNo = orderNo;
        this.partNo = partNo;
        this.partNameRdd = partNameRdd;
        this.planDate = planDate;//批次号（yyyyMMdd）
        this.planTime = planTime;//批次号（yyyyMMdd）
        this.snp = snp;
        this.totalBoxes = totalBoxes.intValue();
        this.qty = qty;
    }

    public WmsPOMasterDetails(String orderNo, String erpSrcNo, Integer item,String partNo,String partNameRdd, Double qty,
                                Double rcQty, Integer itemStatus) {
        this.orderNo = orderNo;
        this.erpSrcNo = erpSrcNo;
        this.item = item;
        this.partNo = partNo;
        this.partNameRdd = partNameRdd;
        this.qty = qty;
        this.rcQty = rcQty;
        this.itemStatus = itemStatus;
    }

    public WmsPOMasterDetails(Integer poStatus,String dock,String orderNo,String vendorNo,String planDate,String planTime,Double sumQty,Double sumRcQty) {
        this.orderNo = orderNo;
        this.planDate=planDate;
        this.planTime=planTime;
        this.vendorNo=vendorNo;
        this.dock=dock;
        this.poStatus=poStatus;
        this.sumQty = sumQty;
        this.sumRcQty = sumRcQty;
    }

}
