package com.jwipc.finance.dto;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;


@Data
public class PaymentAdvanceRefundTransferApplySaveDto {
    private Long id;

    /**
     * 保存类型 1:新增 2:编辑
     */
    private Integer saveType;

    /**
     * 预付款变更单
     */
    private String paymentChangeNo;

    /**
     * 供应商编码
     */
    private String supplierCode;

    /**
     * 供应商名称
     */
    private String supplierName;

    /**
     * 币种
     */
    private String currencyCode;

    /**
     * 公司名称
     */
    private String companyName;

    /**
     * 付款公司代码
     */
    private String companyCode;

    /**
     * 数据类型：转单、退款
     */
    private Integer dataType;

    /**
     * 暂存 0、发布 1
     */
    private Integer status;

    /**
     * 删除标识 0:未删除 1:已删除
     */
    private Integer deleteFlag;

    /**
     * ①预付款菜单订单转单金额或者预付款采购订单退款金额
     */
    private Long recordedAmount;

    /**
     * ①已关联开票申请单，被冲账的金额
     */
    private Long reversedAmount;

    /**
     * 备注
     */
    private String remark;

    /**
     * 附件ids
     */
    private String files;

    /**
     * 创建用户ID
     */
    private Long createUserId;

    /**
     * 创建用户姓名
     */
    private String createUserName;

    /**
     * 创建用户工号
     */
    private String createUserCode;

    /**
     * 创建时间
     */
    private LocalDateTime createTime;

    /**
     * 最后更新用户ID
     */
    private Long updateUserId;

    /**
     * 最后更新用户工号
     */
    private String updateUserCode;

    /**
     * 最后更新用户姓名
     */
    private String updateUserName;

    /**
     * 最后更新时间
     */
    private LocalDateTime updateTime;
    /**
     * 审批意见
     */
    private String approvalOpinion;

    /**
     * 申请明细
     */
    private List<PaymentAdvanceRefundTransferApplyDetail> itemList;


    /**
     * 编辑时删除的明细ID
     */
    private List<Long> delItemIdList;




    /**
     * 申请明细
     */
    @Data
    public static class PaymentAdvanceRefundTransferApplyDetail {
        private Long id;

        /**
         * 行号
         */
        private String itemNo;

        /**
         * 采购订单号
         */
        private String poCode;

        /**
         * 订单行号
         */
        private String poItemNo;

        /**
         * 预付款申请单号
         */
        private String appNo;

        /**
         * 预付款申请单行
         */
        private String appItemNo;

        /**
         * 采购员
         */
        private String purchaser;

        /**
         * 订单数量
         */
        private BigDecimal poNum;

        /**
         * 订单行工厂编码
         */
        private String factoryCode;

        /**
         * 物料编码
         */
        private String materialCode;

        /**
         * 物料描述
         */
        private String materialDesc;

        /**
         * 税率代码
         */
        private String taxCode;

        /**
         * 税率描述
         */
        private String taxDesc;

        /**
         * 含税单价
         */
        private BigDecimal itPrice;

        /**
         * 未税单价
         */
        private BigDecimal ntPrice;

        /**
         * 订单含税金额
         */
        private BigDecimal itAmount;

        /**
         * 已付预付款含税金额
         */
        private BigDecimal prepaymentAmountInclusiveTax;

        /**
         * 付款条件编码
         */
        private String paymentConditionCode;

        /**
         * 付款条件描述
         */
        private String paymentConditionDesc;

        /**
         * 报关公司
         */
        private String customsBroker;

        /**
         * 摘要
         */
        private String summary;

        /**
         * 参考采购订单（转单时必填）
         */
        private String referPurchaseOrder;

        /**
         * 参考采购订单行（转单时必填）
         */
        private String referPurchaseOrderItem;

        /**
         * 预付款变更单号
         */
        private String paymentChangeNumber;
        /**
         * 预付款变更单id
         */
        private Long paymentChangeId;

        /**
         * 采购订单号_订单行号
         */
        private String dataKey;

        /**
         * 本次登记含税金额
         */
        private BigDecimal theRegistTaxAmount;
        /**
         * 可登记含税金额
         */
        private BigDecimal cantRegistTaxAmount;
        /**
         * 已付预付款含税金额
         */
        private BigDecimal prepaidTaxAmount;
        /**
         * 已冲账含税金额
         */
        private BigDecimal alreadyApplyAmount;

        /**
         * 已登记含税金额
         */
        private BigDecimal registTaxAmount;

        /**
         * 删除标志 0 未删除 1 删除
         */
        private Integer deleteFlag;

        /**
         * 数据转化表结构 方便存储
         *
         * @return 结果
         */
        public PaymentAdvanceRefundTransferApplyDetailBaseDTO toAdvanceRefundTransferApplyDetail(){
            PaymentAdvanceRefundTransferApplyDetailBaseDTO detail = new PaymentAdvanceRefundTransferApplyDetailBaseDTO();
            detail.setId(this.id);
            detail.setItemNo(this.itemNo);
            detail.setPoCode(this.poCode);
            detail.setPoItemNo(this.poItemNo);
            detail.setAppNo(this.appNo);
            detail.setAppItemNo(this.appItemNo);
            detail.setPurchaser(this.purchaser);
            detail.setPoNum(this.poNum);
            detail.setFactoryCode(this.factoryCode);
            detail.setMaterialCode(this.materialCode);
            detail.setMaterialDesc(this.materialDesc);
            detail.setTaxCode(this.taxCode);
            detail.setTaxDesc(this.taxDesc);
            detail.setItPrice(this.itPrice);
            detail.setNtPrice(this.ntPrice);
            detail.setItAmount(this.itAmount);
            detail.setPrepaymentAmountInclusiveTax(this.prepaymentAmountInclusiveTax);
            detail.setPaymentConditionCode(this.paymentConditionCode);
            detail.setPaymentConditionDesc(this.paymentConditionDesc);
            detail.setCustomsBroker(this.customsBroker);
            detail.setSummary(this.summary);
            detail.setReferPurchaseOrder(this.referPurchaseOrder);
            detail.setReferPurchaseOrderItem(this.referPurchaseOrderItem);
            detail.setPaymentChangeNumber(this.paymentChangeNumber);
            detail.setPaymentChangeId(this.paymentChangeId);
            detail.setTheRegistTaxAmount(this.theRegistTaxAmount);
            detail.setCantRegistTaxAmount(this.cantRegistTaxAmount);
            detail.setPrepaidTaxAmount(this.prepaidTaxAmount);
            detail.setAlreadyApplyAmount(this.alreadyApplyAmount);
            detail.setRegistTaxAmount(this.registTaxAmount);
            detail.setDeleteFlag(this.deleteFlag);
            // 数据主键 预付款单号_预付款行号
            String dataKey = this.appNo + "_" + this.appItemNo;
            detail.setDataKey(dataKey);
            return detail;
        }

    }


    /**
     * 数据转化为表结构 方便存储
     *
     * @return 结果
     */
    public PaymentAdvanceRefundTransferApplyBaseDTO toAdvanceRefundTransferApply(){
        PaymentAdvanceRefundTransferApplyBaseDTO apply = new PaymentAdvanceRefundTransferApplyBaseDTO();
        apply.setId(this.id);
        apply.setPaymentChangeNo(this.paymentChangeNo);
        apply.setSupplierCode(this.supplierCode);
        apply.setSupplierName(this.supplierName);
        apply.setCurrencyCode(this.currencyCode);
        apply.setCompanyName(this.companyName);
        apply.setCompanyCode(this.companyCode);
        apply.setDataType(this.dataType);
        apply.setStatus(this.status);
        apply.setDeleteFlag(this.deleteFlag);
        apply.setRecordedAmount(this.recordedAmount);
        apply.setReversedAmount(this.reversedAmount);
        apply.setRemark(this.remark);
        apply.setFiles(this.files);
        apply.setCreateUserId(this.createUserId);
        apply.setCreateUserName(this.createUserName);
        apply.setCreateUserCode(this.createUserCode);
        apply.setCreateTime(this.createTime);
        apply.setUpdateUserId(this.updateUserId);
        apply.setUpdateUserCode(this.updateUserCode);
        apply.setUpdateUserName(this.updateUserName);
        apply.setUpdateTime(this.updateTime);
        apply.setApprovalOpinion(this.approvalOpinion);
        return apply;
    }
}
