package com.dhcc.finance.main.model;

import com.dhcc.finance.main.domain.CwGlFreevalue;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
/**
 * 功能描述：用于制单新增接收web端参数等
 * @author dml
 * @date 2019年4月12日 下午9:20:24
 * @修改日志：
 */
@ApiModel(value = "CwGlVoucherWeb",description = "制单信息web端所需实体类")
@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class CwGlVoucherWeb { 
    @ApiModelProperty(value = "凭证主键", required = true, example = "")
    private String pkVoucher;

    @ApiModelProperty(value = "账套主键", required = false, example = "")
    private String pkGlorgbook;
    
    @ApiModelProperty(value = "分期募集编号", required = false, example = "")
    private String fqmjbh;

    @ApiModelProperty(value = "凭证类型", required = false, example = "")
    private String pkVoucherty;

    @ApiModelProperty(value = "来源系统", required = false, example = "")
    private String pkSystem;

    @ApiModelProperty(value = "凭证状态", required = false, example = "")
    private String vouchertype;
    
    @ApiModelProperty(value = "交易码", required = false, example = "")
    private String tradecode;

    @ApiModelProperty(value = "摘要", required = false, example = "")
    private String abstracts;
    
    @ApiModelProperty(value = "制单人", required = false, example = "")
    private String pkPrepared;

    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @ApiModelProperty(value = "制单日期", required = false, example = "")
    private Date preparedate;

    @ApiModelProperty(value = "是否已审核", required = false, example = "")
    private String isaudit;

    @ApiModelProperty(value = "审核人", required = false, example = "")
    private String pkAudit;

    @ApiModelProperty(value = "审核时间", required = false, example = "")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date auditdate;

    @ApiModelProperty(value = "是否已记账", required = false, example = "")
    private String issign;

    @ApiModelProperty(value = "记账人", required = false, example = "")
    private String pkSign;

    @ApiModelProperty(value = "记账时间", required = false, example = "")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date signdate;

    @ApiModelProperty(value = "凭证号", required = false, example = "")
    private String voucherno;

    @ApiModelProperty(value = "是否修改", required = false, example = "")
    private String ismodify;

    @ApiModelProperty(value = "年度", required = false, example = "")
    private String year;

    @ApiModelProperty(value = "会计期间", required = false, example = "")
    private String period;

    @ApiModelProperty(value = "暂存标识", required = false, example = "")
    private String tempsave;

    @ApiModelProperty(value = "借方合计", required = false, example = "")
    private BigDecimal totaldebit;

    @ApiModelProperty(value = "贷方合计", required = false, example = "")
    private BigDecimal totalcredit;

    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @ApiModelProperty(value = "业务发生时间", required = false, example = "")
    private Date occDate;
    
    @ApiModelProperty(value = "使用状态", required = false, example = "")
    private String useState;

    @ApiModelProperty(value = "录入人员", required = false, example = "")
    private String createUser;

    @ApiModelProperty(value = "录入时间", required = false, example = "")
    private Date createTime;

    @ApiModelProperty(value = "最后修改人员", required = false, example = "")
    private String updateUser;

    @ApiModelProperty(value = "最后修改时间", required = false, example = "CURRENT_TIMESTAMP")
    private Date updateTime;

    @ApiModelProperty(value = "备注", required = false, example = "")
    private String remark;
    
    @ApiModelProperty(value = "凭证分录信息表", required = false, example = "")
    private List<CwGlDetailWeb> cwGlDetailList;

    @ApiModelProperty(value = "是否手工录入凭证", required = false, example = "")
    private String isManual;
    /**
     * 功能描述：数据校验
     * @return boolean
     * @author dml
     * @date 2019年4月13日 下午5:25:42
     * @修改日志：
     */
    public boolean chackData() {
    	boolean flag = false;
    	if (StringUtils.isBlank(this.pkGlorgbook) ||StringUtils.isBlank(this.pkVoucherty) || StringUtils.isBlank(this.voucherno)|| 
    		StringUtils.isBlank(this.period) ||this.cwGlDetailList == null || this.cwGlDetailList.isEmpty()) {
    		flag = true;
    		return flag;
		}
    	for (CwGlDetailWeb cwGlDetailWeb : this.cwGlDetailList) {
    		if (cwGlDetailWeb.getCwGlFreevalueList() != null && !cwGlDetailWeb.getCwGlFreevalueList().isEmpty()) {
    			for (CwGlFreevalue cwGlFreevalue : cwGlDetailWeb.getCwGlFreevalueList()) {
    				if (StringUtils.isBlank(cwGlFreevalue.getChecktype()) || StringUtils.isBlank(cwGlFreevalue.getCheckvalue())) {
    					flag = true;
					}
				}
			}
		}
    	return flag;
    }
}
