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.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 java.util.List;

/**
 * @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_MASTER", indexes = {
        @Index(columnList = "ORDER_NO"),
        @Index(columnList = "ORGANIZE_CODE")
})
@Api("PO主表信息")
public class WmsPOMaster extends BaseBean {

    private static final long serialVersionUID = -5439534283717671648L;
    @Column(name = "ORDER_NO")
    @ApiParam("订单号")
    public String orderNo;

    /**
     * 单据类型:
     * 1 REG=原物料采购,10 SUB=委外采购,20 TAR=多角贸易采购,30 TAP=多角代采购
     */
    @Column(name = "PO_TYPE")
    @ApiParam("单据类型")
    public String poType;

    /**
     * 状态:1=新建,10=收货中,20=收货完成,
     * 30=入库中,40=入库完成,90=已关闭,91=已取消
     */
    @Column(name = "PO_STATUS")
    @ApiParam(value = "状态", example = "1")
    @AnnoOutputColumn(refClass = WmsEnumUtil.MASTER_ORDER_STATUS.class, refForeignKey = "value", value = "description")
    public Integer poStatus;

    @Column(name = "VENDOR_NO")
    @ApiParam("供应商编号")
    public String vendorNo;

    @Column(name = "VERSION")
    @ApiParam("版本")
    public String version;

    /**
     * 单据来源：1 MNU=手工,2 ERP=ERP接口
     */
    @Column(name = "SRC")
    @ApiParam("单据来源")
    public String src;

    @Column(name = "IS_ASN")
    @ApiParam("是否有ASN")
    public String isAsn;

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

    @Column(name = "IS_TASK")
    @ApiParam(value = "是否生成任务", example = "1")
    public Integer isTask;

    @Column(name = "IS_PART")
    @ApiParam(value = "是否散件", example = "1")
    public Integer isPart;

    @ApiParam("PO明细列表信息")
    @Transient
    public List<WmsPOMasterDetails> poDetailList;

    @Transient
    @ApiParam(value = "发运单号")
    private String shipOrderNo;

    @Transient
    @ApiParam(value = "打印时间")
    private String printDate;

    @Transient
    @ApiParam(value = "发货人")
    private String sendUser;

    @Transient
    @ApiParam(value = "发货日期")
    private String sendDate;

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

    @Column(name = "IS_SN")
    @ApiParam(value = "是否生成条码", example = "1")
    public Integer isSn;

    @Column(name = "CONTAINER_NO")
    @ApiParam("集装箱号")
    public String containerNo;

    @Column(name = "PRIOR_RC",columnDefinition = "int default 2")
    @ApiParam("预收货")
    public Integer priorRC;

    @Transient
    @ApiParam(value = "工厂名称")
    public String organizeName;

    @Transient
    @ApiParam("联系人")
    private String vendorOwner;

    @Transient
    @ApiParam("邮箱")
    private String vendorEmail;

    @Transient
    @ApiParam("供应商电话")
    private String vendorCall;

    @Transient
    @ApiParam("传真")
    private String vendorFax;

    @Transient
    @ApiParam("手机")
    private String vendorPhone;

    @Transient
    @ApiParam("前端信息")
    private String message;

    @Transient
    @ApiParam("计划日期开始")
    private String planDateStart;

    @Transient
    @ApiParam("计划日期结束")
    private String planDateEnd;

    @Transient
    @ApiParam("计划日期")
    private String planDate;

    @Transient
    @ApiParam("计划时间")
    private String planTime;

    @Transient
    @ApiParam("看板状态")
    private Integer boardStatus;

    @Transient
    @ApiParam("物料编码")
    private String partNo;

    @Transient
    @ApiParam("需求数量")
    private Double qty;

    @Transient
    @ApiParam("实收数量")
    private Double rcqty;

    @Transient
    private List<String> orderNoList;

    @Column(name = "DOCK", columnDefinition = "varchar(50) default ''")
    @ApiParam("道口")
    public String dock;

    @ApiParam("泊位")
    @Column(name = "ZDOC", columnDefinition = "varchar(50) default ''")
    public String zdoc;

    @ApiParam("发运单号")
    @Column(name = "SHIPMENT_NOTE_NUMBER")
    public String shipmentNoteNumber;

    @ApiParam("erp单号")
    @Column(name = "ERP_SRC_NO")
    private String erpSrcNo;

    @Column(name = "DEPART_NAME")
    @ApiParam(value = "部门名称", example = "1")
    public Integer departName;

    @Column(name = "REASON")
    @ApiParam(value = "原因", example = "1")
    public String reason;

    @Column(name = "RECEIVE_DATE")
    @ApiParam(value = "收货日期")
    public String receiveDate;

    @Column(name = "RECEIVE_TIME")
    @ApiParam(value = "收货时间")
    public String receiveTime;

    @Column(name = "WINDOW_START_TIME")
    @ApiParam(value = "窗口开始时间")
    public String windowStartTime;

    @Column(name = "WINDOW_END_TIME")
    @ApiParam(value = "窗口结束时间")
    public String windowEndTime;


    @Transient
    @ApiParam("周总数")
    private Integer weekRcCount;

    @Transient
    @ApiParam("容差")
    private Integer delayHour;

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

    @ApiParam(value = "延迟次数")
    private Long delayCount;

    @ApiParam(value = "延迟次数")
    private Long sumDelayCount;

    @ApiParam(value = "延迟到货百分比")
    private String delayPercent;

    @ApiParam("计划交货时间")
    private String planPlanDateTime;





    public WmsPOMaster() {

    }

    public WmsPOMaster(String orderNo, Integer poStatus, String organizeCode, String vendorNo, String dockCode, String zdoc, String createDateTime, String receiveDateTime) {
        this.orderNo = orderNo;
        this.poStatus = poStatus;
        this.organizeCode = organizeCode;
        this.vendorNo = vendorNo;
        this.dock = dockCode;
        this.zdoc = zdoc;
        this.createDatetime = createDateTime;
        this.createDateTimeStart = receiveDateTime;
    }
    public WmsPOMaster(String orderNo, Integer poStatus, String vendorNo,
                       String dockCode, String planDate, String planTime) {
        this.orderNo = orderNo;
        this.poStatus = poStatus;
        this.vendorNo = vendorNo;
        this.dock = dockCode;
        this.planDate = planDate;
        this.planTime = planTime;
    }

    public WmsPOMaster(String orderNo, Integer poStatus, String vendorNo, String vendorName,
                       String dockCode, String planDate, String planTime, Integer delayHour) {
        this.orderNo = orderNo;
        this.poStatus = poStatus;
        this.vendorNo = vendorNo;
        this.vendorName = vendorName;
        this.dock = dockCode;
        this.planDate = planDate;
        this.planTime = planTime;
        this.delayHour = delayHour;
    }

    public WmsPOMaster(String vendorNo, Long delayCount) {
        this.vendorNo = vendorNo;
        this.delayCount = delayCount;
    }

    public WmsPOMaster(String orderNo, String reason, String planDate, String planTime,
                       String receiveTime, String vendorNo, String vendorName, String organizeCode) {
        this.orderNo = orderNo;
        this.reason = reason;
        this.planDate = planDate;
        this.planTime = planTime;
        this.receiveTime = receiveTime;
        this.vendorNo = vendorNo;
        this.vendorName = vendorName;
        this.organizeCode = organizeCode;
    }

    public int getPoStatusVal() {
        return this.poStatus == null ? 0 : this.poStatus;
    }
}
