package com.uas.platform.b2b.erp.model;

import com.uas.platform.b2b.model.Product;
import com.uas.platform.b2b.model.PurchaseApBillOut;
import com.uas.platform.b2b.model.PurchaseApBillOutInfo;
import com.uas.platform.b2b.model.PurchaseApBillOutItem;
import com.uas.platform.b2b.support.SystemSession;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * ERP应收开票主表数据
 * @author huangct
 * @date 2018年2月08日10:14:24
 *
 */
public class BillOut {
    private String bi_id;
    private String bi_code;
    private Date bi_date;
    private String bi_custcode;
    private String bi_custname;
    private String bi_sellercode;
    private String bi_seller;
    private Double bi_amount;
    private String bi_recorder;
    private Date bi_indate;
    private String bi_status;
    private String bi_remark;
    private String bi_cop;
    private String bi_currency;
    private Double bi_rate;
    private String bi_vouchercode;
    private String bi_costvouchercode;
    private String bi_departmentcode;
    private String bi_department;
    private String bi_refno;
    private String bi_salekind;
    private Double bi_taxdiffer;
    private Double bi_taxamount;
    private String bi_salemethod;
    private String bi_discountamount;
    private String bi_discount;
    private String bi_catecode;
    private String bi_catename;
    private String bi_setkind;
    private String bi_sendkind;
    private String bi_tradecode;
    private String bi_tradename;
    private String bi_pricekind;
    private String bi_pidepartmentcode;
    private String bi_pidepartmentname;
    private String bi_statuscode;
    private Date bi_auditdate;
    private String bi_auditer;
    private String bi_paymentscode;
    private String bi_paymentsmethod;
    private Double bi_payamount;
    private Date bi_postdate;
    private String bi_postman;
    private String bi_thispayamount;
    private Date bi_paydate;
    private List<BillOutDetail> details;
    private Long bi_custuu;

    public String getBi_id() {
        return bi_id;
    }

    public void setBi_id(String bi_id) {
        this.bi_id = bi_id;
    }

    public String getBi_code() {
        return bi_code;
    }

    public void setBi_code(String bi_code) {
        this.bi_code = bi_code;
    }

    public Date getBi_date() {
        return bi_date;
    }

    public void setBi_date(Date bi_date) {
        this.bi_date = bi_date;
    }

    public String getBi_custcode() {
        return bi_custcode;
    }

    public void setBi_custcode(String bi_custcode) {
        this.bi_custcode = bi_custcode;
    }

    public String getBi_custname() {
        return bi_custname;
    }

    public void setBi_custname(String bi_custname) {
        this.bi_custname = bi_custname;
    }

    public String getBi_sellercode() {
        return bi_sellercode;
    }

    public void setBi_sellercode(String bi_sellercode) {
        this.bi_sellercode = bi_sellercode;
    }

    public String getBi_seller() {
        return bi_seller;
    }

    public void setBi_seller(String bi_seller) {
        this.bi_seller = bi_seller;
    }

    public Double getBi_amount() {
        return bi_amount;
    }

    public void setBi_amount(Double bi_amount) {
        this.bi_amount = bi_amount;
    }

    public String getBi_recorder() {
        return bi_recorder;
    }

    public void setBi_recorder(String bi_recorder) {
        this.bi_recorder = bi_recorder;
    }

    public Date getBi_indate() {
        return bi_indate;
    }

    public void setBi_indate(Date bi_indate) {
        this.bi_indate = bi_indate;
    }

    public String getBi_status() {
        return bi_status;
    }

    public void setBi_status(String bi_status) {
        this.bi_status = bi_status;
    }

    public String getBi_remark() {
        return bi_remark;
    }

    public void setBi_remark(String bi_remark) {
        this.bi_remark = bi_remark;
    }

    public String getBi_cop() {
        return bi_cop;
    }

    public void setBi_cop(String bi_cop) {
        this.bi_cop = bi_cop;
    }

    public String getBi_currency() {
        return bi_currency;
    }

    public void setBi_currency(String bi_currency) {
        this.bi_currency = bi_currency;
    }

    public Double getBi_rate() {
        return bi_rate;
    }

    public void setBi_rate(Double bi_rate) {
        this.bi_rate = bi_rate;
    }

    public String getBi_vouchercode() {
        return bi_vouchercode;
    }

    public void setBi_vouchercode(String bi_vouchercode) {
        this.bi_vouchercode = bi_vouchercode;
    }

    public String getBi_costvouchercode() {
        return bi_costvouchercode;
    }

    public void setBi_costvouchercode(String bi_costvouchercode) {
        this.bi_costvouchercode = bi_costvouchercode;
    }

    public String getBi_departmentcode() {
        return bi_departmentcode;
    }

    public void setBi_departmentcode(String bi_departmentcode) {
        this.bi_departmentcode = bi_departmentcode;
    }

    public String getBi_department() {
        return bi_department;
    }

    public void setBi_department(String bi_department) {
        this.bi_department = bi_department;
    }

    public String getBi_refno() {
        return bi_refno;
    }

    public void setBi_refno(String bi_refno) {
        this.bi_refno = bi_refno;
    }

    public String getBi_salekind() {
        return bi_salekind;
    }

    public void setBi_salekind(String bi_salekind) {
        this.bi_salekind = bi_salekind;
    }

    public Double getBi_taxdiffer() {
        return bi_taxdiffer;
    }

    public void setBi_taxdiffer(Double bi_taxdiffer) {
        this.bi_taxdiffer = bi_taxdiffer;
    }

    public Double getBi_taxamount() {
        return bi_taxamount;
    }

    public void setBi_taxamount(Double bi_taxamount) {
        this.bi_taxamount = bi_taxamount;
    }

    public String getBi_salemethod() {
        return bi_salemethod;
    }

    public void setBi_salemethod(String bi_salemethod) {
        this.bi_salemethod = bi_salemethod;
    }

    public String getBi_discountamount() {
        return bi_discountamount;
    }

    public void setBi_discountamount(String bi_discountamount) {
        this.bi_discountamount = bi_discountamount;
    }

    public String getBi_discount() {
        return bi_discount;
    }

    public void setBi_discount(String bi_discount) {
        this.bi_discount = bi_discount;
    }

    public String getBi_catecode() {
        return bi_catecode;
    }

    public void setBi_catecode(String bi_catecode) {
        this.bi_catecode = bi_catecode;
    }

    public String getBi_catename() {
        return bi_catename;
    }

    public void setBi_catename(String bi_catename) {
        this.bi_catename = bi_catename;
    }

    public String getBi_setkind() {
        return bi_setkind;
    }

    public void setBi_setkind(String bi_setkind) {
        this.bi_setkind = bi_setkind;
    }

    public String getBi_sendkind() {
        return bi_sendkind;
    }

    public void setBi_sendkind(String bi_sendkind) {
        this.bi_sendkind = bi_sendkind;
    }

    public String getBi_tradecode() {
        return bi_tradecode;
    }

    public void setBi_tradecode(String bi_tradecode) {
        this.bi_tradecode = bi_tradecode;
    }

    public String getBi_tradename() {
        return bi_tradename;
    }

    public void setBi_tradename(String bi_tradename) {
        this.bi_tradename = bi_tradename;
    }

    public String getBi_pricekind() {
        return bi_pricekind;
    }

    public void setBi_pricekind(String bi_pricekind) {
        this.bi_pricekind = bi_pricekind;
    }

    public String getBi_pidepartmentcode() {
        return bi_pidepartmentcode;
    }

    public void setBi_pidepartmentcode(String bi_pidepartmentcode) {
        this.bi_pidepartmentcode = bi_pidepartmentcode;
    }

    public String getBi_pidepartmentname() {
        return bi_pidepartmentname;
    }

    public void setBi_pidepartmentname(String bi_pidepartmentname) {
        this.bi_pidepartmentname = bi_pidepartmentname;
    }

    public String getBi_statuscode() {
        return bi_statuscode;
    }

    public void setBi_statuscode(String bi_statuscode) {
        this.bi_statuscode = bi_statuscode;
    }

    public Date getBi_auditdate() {
        return bi_auditdate;
    }

    public void setBi_auditdate(Date bi_auditdate) {
        this.bi_auditdate = bi_auditdate;
    }

    public String getBi_auditer() {
        return bi_auditer;
    }

    public void setBi_auditer(String bi_auditer) {
        this.bi_auditer = bi_auditer;
    }

    public String getBi_paymentscode() {
        return bi_paymentscode;
    }

    public void setBi_paymentscode(String bi_paymentscode) {
        this.bi_paymentscode = bi_paymentscode;
    }

    public String getBi_paymentsmethod() {
        return bi_paymentsmethod;
    }

    public void setBi_paymentsmethod(String bi_paymentsmethod) {
        this.bi_paymentsmethod = bi_paymentsmethod;
    }

    public Double getBi_payamount() {
        return bi_payamount;
    }

    public void setBi_payamount(Double bi_payamount) {
        this.bi_payamount = bi_payamount;
    }

    public Date getBi_postdate() {
        return bi_postdate;
    }

    public void setBi_postdate(Date bi_postdate) {
        this.bi_postdate = bi_postdate;
    }

    public String getBi_postman() {
        return bi_postman;
    }

    public void setBi_postman(String bi_postman) {
        this.bi_postman = bi_postman;
    }

    public String getBi_thispayamount() {
        return bi_thispayamount;
    }

    public void setBi_thispayamount(String bi_thispayamount) {
        this.bi_thispayamount = bi_thispayamount;
    }

    public Date getBi_paydate() {
        return bi_paydate;
    }

    public void setBi_paydate(Date bi_paydate) {
        this.bi_paydate = bi_paydate;
    }

    public List<BillOutDetail> getDetails() {
        return details;
    }

    public void setDetails(List<BillOutDetail> details) {
        this.details = details;
    }

    public Long getBi_custuu() {
        return bi_custuu;
    }

    public void setBi_custuu(Long bi_custuu) {
        this.bi_custuu = bi_custuu;
    }

    public PurchaseApBillOut convert(PurchaseApBillOutInfo customerApBillOutInfo, PurchaseApBillOutInfo apBillOutInfo, List<Product> products) {
        PurchaseApBillOut purchaseApBillOut = new PurchaseApBillOut();
        purchaseApBillOut.setTaxSum(this.bi_taxamount);
        purchaseApBillOut.setDiffer(this.bi_taxdiffer);
        purchaseApBillOut.setRecordDate(this.bi_indate);
        purchaseApBillOut.setRecorder(this.bi_recorder);
        purchaseApBillOut.setCheckStatus("未开票");//未开票 已开票 已作废
        purchaseApBillOut.setRemark(this.bi_remark);
        purchaseApBillOut.setAuditDate(this.bi_auditdate);
        //purchaseApBillOut.setResDate(null);//作废日期
        //purchaseApBillOut.setResMan(null);//作废人
        //purchaseApBillOut.setStatus(null);//状态 short
        purchaseApBillOut.setAmount(this.bi_amount);
        purchaseApBillOut.setPayAmount(this.bi_payamount);
        purchaseApBillOut.setCurrency(this.bi_currency);
        purchaseApBillOut.setRate(this.bi_rate);
        //客户企业开票信息
        purchaseApBillOut.setCustUu(this.bi_custuu);
        if (customerApBillOutInfo != null) {
            purchaseApBillOut.setCustomerApBillOutInfo(customerApBillOutInfo);
        }
        purchaseApBillOut.setCustName(this.bi_custname);
        //当前企业开票信息
        purchaseApBillOut.setEnUu(SystemSession.getUser().getEnterprise().getUu());
        if (apBillOutInfo != null) {
            purchaseApBillOut.setApBillOutInfo(apBillOutInfo);
        }
        purchaseApBillOut.setCode(this.bi_code);
        //purchaseApBillOut.setPrint(null);//打印次数

        if (!CollectionUtils.isEmpty(this.details)) {
            Set<PurchaseApBillOutItem> purchaseApBillOutItems = new HashSet<PurchaseApBillOutItem>();
            for (BillOutDetail billOutDetail : this.details) {
                for (Product product : products) {
                    if (SystemSession.getUser().getEnterprise().getUu().equals(product.getEnUU()) && billOutDetail.getArd_prodcode().equals(product.getCode())) {
                        purchaseApBillOutItems.add(billOutDetail.convert(product));
                    }
                }
            }
            purchaseApBillOut.setItems(purchaseApBillOutItems);
        }
        return purchaseApBillOut;
    }
}
