package cn.hnthyy.thmz.service.impl.his.zy;

import cn.hnthyy.thmz.Utils.CloneUtil;
import cn.hnthyy.thmz.Utils.DateUtil;
import cn.hnthyy.thmz.Utils.Md5Util;
import cn.hnthyy.thmz.entity.MzException;
import cn.hnthyy.thmz.entity.his.zy.ZyActpatient;
import cn.hnthyy.thmz.entity.his.zy.ZyDepositFile;
import cn.hnthyy.thmz.entity.his.zy.ZyLedgerFile;
import cn.hnthyy.thmz.entity.his.zy.ZyReceipt;
import cn.hnthyy.thmz.enums.SettleTypeEnum;
import cn.hnthyy.thmz.enums.YesNoEnum;
import cn.hnthyy.thmz.enums.ZyDepositFileStatusEnum;
import cn.hnthyy.thmz.mapper.his.zy.*;
import cn.hnthyy.thmz.service.his.zy.ZyDepositFileService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Service
public class ZyDepositFileServiceImpl implements ZyDepositFileService {
    @SuppressWarnings("all")
    @Autowired
    private ZyDepositFileMapper zyDepositFileMapper;
    @SuppressWarnings("all")
    @Autowired
    private ZyActpatientMapper zyActpatientMapper;
    @SuppressWarnings("all")
    @Autowired
    private ZyLedgerFileMapper zyLedgerFileMapper;
    @SuppressWarnings("all")
    @Autowired
    private ZyReceiptMapper zyReceiptMapper;
    @SuppressWarnings("all")
    @Autowired
    private ZyDetailChargeMapper zyDetailChargeMapper;
    @Override
    public List<ZyDepositFile> queryZyDepositFileBYInpatientNoAndTimes(ZyDepositFile zyDepositFile) {
        return zyDepositFileMapper.selectZyDepositFileBYInpatientNoAndTimes(zyDepositFile);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class)
    public int saveZyDepositFile(ZyDepositFile zyDepositFile) throws MzException {
        ZyActpatient zyActpatient = zyActpatientMapper.selectByInpatientNo("zy_actpatient", zyDepositFile.getInpatientNo(), null);
        if (zyActpatient == null) {
            throw new MzException("住院号没有查询到对应的住院记录");
        }
        zyDepositFile.setAdmissTimes(Double.valueOf(zyActpatient.getAdmissTimes()));
        int depoTimes = zyDepositFileMapper.selectMaxDepoTimes(zyDepositFile);
        depoTimes++;
        zyDepositFile.setDepoTimes(Double.valueOf(depoTimes));
        zyDepositFile.setDepoDate(new Date());
        zyDepositFile.setWindowNo("1");
        zyDepositFile.setDeleted(YesNoEnum.NO.code.toString());
        //此时账页信息为空，是收费
        if (zyDepositFile.getLedgerSn() == null) {
            Integer currentLedgerSn = zyLedgerFileMapper.selectCurrentLedgerSn(zyDepositFile.getInpatientNo(), zyActpatient.getAdmissTimes());
            if (currentLedgerSn == null) {
                Integer maxLedgerSn = zyLedgerFileMapper.selectMaxLedgerSn(zyDepositFile.getInpatientNo(), zyActpatient.getAdmissTimes());
                currentLedgerSn = maxLedgerSn++;
            }
            zyDepositFile.setLedgerSn(Double.valueOf(currentLedgerSn));
        }
        //查询账页信息
        ZyLedgerFile zyLedgerFile = zyLedgerFileMapper.selectZyLedgerFileByInpatientNoAndTimesAndLedgerSn(zyDepositFile.getInpatientNo(), zyActpatient.getAdmissTimes(), zyDepositFile.getLedgerSn().intValue());
        if (zyLedgerFile == null) {
            throw new MzException("没有找到当前病人本次住院的账页信息");
        }
        //缴费
        if (ZyDepositFileStatusEnum.PREPAY.code.equals(zyDepositFile.getStatus())) {
            zyDepositFile.setReceiptNo(Md5Util.getReceiptNo());
            zyDepositFile.setPrinted(Double.valueOf(0));
        } else if (ZyDepositFileStatusEnum.STRAIGHT_BACK.code.equals(zyDepositFile.getStatus())) {
            //退费
            zyDepositFile.setReportFlag(YesNoEnum.YES.code.toString());
            zyDepositFileMapper.updateReportFlag(zyDepositFile.getReceiptNo());
        }
        int num = zyDepositFileMapper.insetZyDepositFile(zyDepositFile);
        //设置账页信息
        zyLedgerFile.setDeposit(zyLedgerFile.getDeposit().add(zyDepositFile.getDepoAmount()));
        zyLedgerFile.setBalance(zyLedgerFile.getBalance().add(zyDepositFile.getDepoAmount()));
        zyLedgerFileMapper.updateZyLedgerFile(zyLedgerFile);
        //设置住院表的余额
        zyActpatient.setBalance(zyActpatient.getBalance().add(zyDepositFile.getDepoAmount()));
        zyActpatient.setTableName("zy_actpatient");
        zyActpatientMapper.updateBalance(zyActpatient);
        return num;
    }

    @Override
    public BigDecimal querySumDepoAmountByReceiptNo(String receiptNo) {
        return zyDepositFileMapper.selectSumDepoAmountByReceiptNo(receiptNo);
    }

    @Override
    public int modifyReportFlag(String receiptNo) {
        return zyDepositFileMapper.updateReportFlag(receiptNo);
    }

    @Override
    public ZyDepositFile queryZyDepositFileByReceiptNo(String receiptNo) {
        return zyDepositFileMapper.selectZyDepositFileByReceiptNo(receiptNo);
    }

    @Override
    public int modifyPrinted(String receiptNo) {
        return zyDepositFileMapper.updatePrinted(receiptNo);
    }

    @Override
    public ZyDepositFile queryZyDepositFileByAgtordnum(String psordnum, String agtordnum, String tableName) {
        if (tableName == null) {
            tableName = "zy_deposit_file";
        }
        return zyDepositFileMapper.selectZyDepositFileByAgtordnum(psordnum, agtordnum, tableName);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class)
    public int cancelCashi(String opId,String inpatientNo, Integer admissTimes) throws MzException {
        ZyLedgerFile zyLedgerFile = zyLedgerFileMapper.selectLastLedgerSn(inpatientNo, admissTimes);
        if (zyLedgerFile == null) {
            throw new MzException("账页信息不存在");
        }
        if (!SettleTypeEnum.TELLER.code.equals(zyLedgerFile.getSettleType())) {
            throw new MzException("当前病人的结算状态非【已出纳】，无法进行费用冲销操作！");
        }
        Integer minLedgerSn = zyLedgerFileMapper.selectMinLedgerSn(inpatientNo, admissTimes);
        Date now = new Date();
        //将原账页信息修改保存
        ZyLedgerFile oriZyLedgerFile = CloneUtil.clone(zyLedgerFile);
        oriZyLedgerFile.setLedgerSn(minLedgerSn-1);
        oriZyLedgerFile.setTfFlag(YesNoEnum.YES.code.toString());
        zyLedgerFileMapper.insetZyLedgerFile(oriZyLedgerFile);
        //退费后的冲抵记录
        ZyLedgerFile newZyLedgerFile = getZyLedgerFile(opId, zyLedgerFile, minLedgerSn, now);
        zyLedgerFileMapper.insetZyLedgerFile(newZyLedgerFile);
        //更新源账页数据
        zyLedgerFileMapper.updateZyLedgerFileForCancelCashi(inpatientNo,admissTimes,zyLedgerFile.getLedgerSn());
        ZyDepositFile zyDepositFile = zyDepositFileMapper.selectLastZyDepositFile(inpatientNo,Double.valueOf(admissTimes));
        if (zyDepositFile == null) {
            throw new MzException("收据信息不存在");
        }
        ZyDepositFile updateZyDepositFile = new ZyDepositFile();
        updateZyDepositFile.setInpatientNo(inpatientNo);
        updateZyDepositFile.setAdmissTimes(zyDepositFile.getAdmissTimes());
        updateZyDepositFile.setDepoTimes(zyDepositFile.getDepoTimes());
        updateZyDepositFile.setLedgerSn(Double.valueOf(oriZyLedgerFile.getLedgerSn()));
        updateZyDepositFile.setDeleted(YesNoEnum.YES.code.toString());
        zyDepositFileMapper.updateZyDepositFileCommon(updateZyDepositFile);
        zyDepositFile.setDepoDate(now);
        zyDepositFile.setOpIdCode(opId);
        zyDepositFile.setDepoAmount(BigDecimal.ZERO.subtract(zyDepositFile.getDepoAmount()));
        zyDepositFile.setLedgerSn(Double.valueOf(newZyLedgerFile.getLedgerSn()));
        zyDepositFile.setDeleted(YesNoEnum.YES.code.toString());
        zyDepositFileMapper.insetZyDepositFile(zyDepositFile);

        ZyReceipt zyReceipt=zyReceiptMapper.selectLastZyReceipt(inpatientNo,admissTimes);
        if (zyReceipt == null) {
            throw new MzException("发票信息不存在");
        }
        //将原账页信息修改保存
        ZyReceipt oriZyReceipt = CloneUtil.clone(zyReceipt);
        oriZyReceipt.setLedgerSn(Long.valueOf(oriZyLedgerFile.getLedgerSn()));
        zyReceiptMapper.insertZyReceipt(oriZyReceipt);
        //退费后的冲抵记录
        ZyReceipt newZyReceipt = getZyReceipt(opId, now, newZyLedgerFile, zyReceipt);
        zyReceiptMapper.insertZyReceipt(newZyReceipt);
        //设置新的发票信息
        ZyReceipt updateZyReceipt = new ZyReceipt();
        updateZyReceipt.setInpatientNo(inpatientNo);
        updateZyReceipt.setAdmissTimes(zyReceipt.getAdmissTimes());
        updateZyReceipt.setLedgerSn(zyReceipt.getLedgerSn());
        updateZyReceipt.setReceiptNo("00000000");
        updateZyReceipt.setOpIdCode(null);
        updateZyReceipt.setPrintDate(null);
        zyReceiptMapper.clearZyReceipt(updateZyReceipt);
        zyDetailChargeMapper.insertForCancelCashi(inpatientNo,admissTimes,1,1,now,oriZyLedgerFile.getLedgerSn());
        return zyDetailChargeMapper.insertForCancelCashi(inpatientNo,admissTimes,1,-1,now,newZyLedgerFile.getLedgerSn());
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class)
    public int teller(String opId, List<ZyDepositFile> zyDepositFiles) throws MzException {
        if(zyDepositFiles==null || zyDepositFiles.size()==0){
            throw new MzException("结算补交或者结算退费支付方式不能为空！");
        }
        String inpatientNo=null;
        Double admissTimes=null;
        Integer maxDepoTimes=null;
        Integer maxLedgerSn=null;
        Date now = new Date();
        for(ZyDepositFile zyDepositFile:zyDepositFiles){
            if(StringUtils.isBlank(zyDepositFile.getInpatientNo())){
                throw new MzException("患者住院号不能为空！");
            }
            if(zyDepositFile.getAdmissTimes()==null){
                throw new MzException("患者住院次数不能为空！");
            }
            if(zyDepositFile.getDepoAmount()==null){
                throw new MzException("支付金额不能为空！");
            }
            if(StringUtils.isBlank(zyDepositFile.getDepoType())){
                throw new MzException("支付方式不能为空！");
            }
            if(StringUtils.isBlank(zyDepositFile.getStatus())){
                throw new MzException("事务类型不能为空！");
            }
            if(maxDepoTimes==null){
                maxDepoTimes= zyDepositFileMapper.selectMaxDepoTimes(zyDepositFile);
                if(maxDepoTimes==null){
                    maxDepoTimes=0;
                }
            }
            if(maxLedgerSn==null){
                inpatientNo=zyDepositFile.getInpatientNo();
                admissTimes=zyDepositFile.getAdmissTimes();
                maxLedgerSn = zyLedgerFileMapper.selectMaxLedgerSn(zyDepositFile.getInpatientNo(), zyDepositFile.getAdmissTimes().intValue());
            }
            zyDepositFile.setDepoTimes(Double.valueOf(++maxDepoTimes));
            zyDepositFile.setDepoDate(now);
            zyDepositFile.setOpIdCode(opId);
            zyDepositFile.setReceiptNo("");
            zyDepositFile.setPrinted(0D);
            zyDepositFile.setLedgerSn(Double.valueOf(maxLedgerSn));
            zyDepositFile.setWindowNo(ZyDepositFile.NEW_VALUATION);
            zyDepositFile.setDeleted(YesNoEnum.NO.code.toString());
            zyDepositFileMapper.insetZyDepositFile(zyDepositFile);
        }
        zyDepositFileMapper.updateHsrAndHsTime(inpatientNo, admissTimes,opId,now);
        ZyLedgerFile updateZyLedgerFile = new ZyLedgerFile();
        updateZyLedgerFile.setInpatientNo(inpatientNo);
        updateZyLedgerFile.setAdmissTimes(admissTimes.intValue());
        updateZyLedgerFile.setLedgerSn(maxLedgerSn);
        updateZyLedgerFile.setCashId(opId);
        updateZyLedgerFile.setCashDate(now);
        updateZyLedgerFile.setSettleType(SettleTypeEnum.TELLER.code);
        updateZyLedgerFile.setBalance(BigDecimal.ZERO);
        zyLedgerFileMapper.updateZyLedgerFileCommon(updateZyLedgerFile);
        ZyActpatient updateZyActpatient = new  ZyActpatient();
        updateZyActpatient.setInpatientNo(inpatientNo);
        updateZyActpatient.setAdmissTimes(admissTimes.intValue());
        updateZyActpatient.setBalance(BigDecimal.ZERO);
        updateZyActpatient.setTableName("zy_inactpatient");
        return zyActpatientMapper.updateBalance(updateZyActpatient);
    }

    private ZyReceipt getZyReceipt(String opId, Date now, ZyLedgerFile newZyLedgerFile, ZyReceipt zyReceipt) {
        ZyReceipt newZyReceipt = CloneUtil.clone(zyReceipt);
        newZyReceipt.setLedgerSn(Long.valueOf(newZyLedgerFile.getLedgerSn()));
        newZyReceipt.setTotalCharge(0-newZyReceipt.getTotalCharge());
        newZyReceipt.setAccountDate(now);
        newZyReceipt.setPrintDate(DateUtil.pase("1900-01-01 00:00:00.000","yyyy-MM-dd HH:mm:ss"));
        newZyReceipt.setOpIdCode(opId);
        newZyReceipt.setCharge1(BigDecimal.ZERO.subtract(newZyReceipt.getCharge1()==null?BigDecimal.ZERO:BigDecimal.valueOf(newZyReceipt.getCharge1())).doubleValue());
        newZyReceipt.setCharge2(BigDecimal.ZERO.subtract(newZyReceipt.getCharge2()==null?BigDecimal.ZERO:BigDecimal.valueOf(newZyReceipt.getCharge2())).doubleValue());
        newZyReceipt.setCharge3(BigDecimal.ZERO.subtract(newZyReceipt.getCharge3()==null?BigDecimal.ZERO:BigDecimal.valueOf(newZyReceipt.getCharge3())).doubleValue());
        newZyReceipt.setCharge4(BigDecimal.ZERO.subtract(newZyReceipt.getCharge4()==null?BigDecimal.ZERO:BigDecimal.valueOf(newZyReceipt.getCharge4())).doubleValue());
        newZyReceipt.setCharge5(BigDecimal.ZERO.subtract(newZyReceipt.getCharge5()==null?BigDecimal.ZERO:BigDecimal.valueOf(newZyReceipt.getCharge5())).doubleValue());
        newZyReceipt.setCharge6(BigDecimal.ZERO.subtract(newZyReceipt.getCharge6()==null?BigDecimal.ZERO:BigDecimal.valueOf(newZyReceipt.getCharge6())).doubleValue());
        newZyReceipt.setCharge7(BigDecimal.ZERO.subtract(newZyReceipt.getCharge7()==null?BigDecimal.ZERO:BigDecimal.valueOf(newZyReceipt.getCharge7())).doubleValue());
        newZyReceipt.setCharge8(BigDecimal.ZERO.subtract(newZyReceipt.getCharge8()==null?BigDecimal.ZERO:BigDecimal.valueOf(newZyReceipt.getCharge8())).doubleValue());
        newZyReceipt.setCharge9(BigDecimal.ZERO.subtract(newZyReceipt.getCharge9()==null?BigDecimal.ZERO:BigDecimal.valueOf(newZyReceipt.getCharge9())).doubleValue());
        newZyReceipt.setCharge10(BigDecimal.ZERO.subtract(newZyReceipt.getCharge10()==null?BigDecimal.ZERO:BigDecimal.valueOf(newZyReceipt.getCharge10())).doubleValue());
        newZyReceipt.setCharge11(BigDecimal.ZERO.subtract(newZyReceipt.getCharge11()==null?BigDecimal.ZERO:BigDecimal.valueOf(newZyReceipt.getCharge11())).doubleValue());
        newZyReceipt.setCharge12(BigDecimal.ZERO.subtract(newZyReceipt.getCharge12()==null?BigDecimal.ZERO:BigDecimal.valueOf(newZyReceipt.getCharge12())).doubleValue());
        newZyReceipt.setCharge13(BigDecimal.ZERO.subtract(newZyReceipt.getCharge13()==null?BigDecimal.ZERO:BigDecimal.valueOf(newZyReceipt.getCharge13())).doubleValue());
        newZyReceipt.setCharge14(BigDecimal.ZERO.subtract(newZyReceipt.getCharge14()==null?BigDecimal.ZERO:BigDecimal.valueOf(newZyReceipt.getCharge14())).doubleValue());
        newZyReceipt.setCharge15(BigDecimal.ZERO.subtract(newZyReceipt.getCharge15()==null?BigDecimal.ZERO:BigDecimal.valueOf(newZyReceipt.getCharge15())).doubleValue());
        newZyReceipt.setCharge16(BigDecimal.ZERO.subtract(newZyReceipt.getCharge16()==null?BigDecimal.ZERO:BigDecimal.valueOf(newZyReceipt.getCharge16())).doubleValue());
        newZyReceipt.setCharge17(BigDecimal.ZERO.subtract(newZyReceipt.getCharge17()==null?BigDecimal.ZERO:BigDecimal.valueOf(newZyReceipt.getCharge17())).doubleValue());
        newZyReceipt.setCharge18(BigDecimal.ZERO.subtract(newZyReceipt.getCharge18()==null?BigDecimal.ZERO:BigDecimal.valueOf(newZyReceipt.getCharge18())).doubleValue());
        newZyReceipt.setCharge19(BigDecimal.ZERO.subtract(newZyReceipt.getCharge19()==null?BigDecimal.ZERO:BigDecimal.valueOf(newZyReceipt.getCharge19())).doubleValue());
        newZyReceipt.setCharge20(BigDecimal.ZERO.subtract(newZyReceipt.getCharge20()==null?BigDecimal.ZERO:BigDecimal.valueOf(newZyReceipt.getCharge20())).doubleValue());
        newZyReceipt.setCharge21(BigDecimal.ZERO.subtract(newZyReceipt.getCharge21()==null?BigDecimal.ZERO:BigDecimal.valueOf(newZyReceipt.getCharge21())).doubleValue());
        newZyReceipt.setCharge22(BigDecimal.ZERO.subtract(newZyReceipt.getCharge22()==null?BigDecimal.ZERO:BigDecimal.valueOf(newZyReceipt.getCharge22())).doubleValue());
        newZyReceipt.setCharge23(BigDecimal.ZERO.subtract(newZyReceipt.getCharge23()==null?BigDecimal.ZERO:BigDecimal.valueOf(newZyReceipt.getCharge23())).doubleValue());
        newZyReceipt.setCharge24(BigDecimal.ZERO.subtract(newZyReceipt.getCharge24()==null?BigDecimal.ZERO:BigDecimal.valueOf(newZyReceipt.getCharge24())).doubleValue());
        newZyReceipt.setCharge25(BigDecimal.ZERO.subtract(newZyReceipt.getCharge25()==null?BigDecimal.ZERO:BigDecimal.valueOf(newZyReceipt.getCharge25())).doubleValue());
        newZyReceipt.setCharge26(BigDecimal.ZERO.subtract(newZyReceipt.getCharge26()==null?BigDecimal.ZERO:BigDecimal.valueOf(newZyReceipt.getCharge26())).doubleValue());
        newZyReceipt.setCharge27(BigDecimal.ZERO.subtract(newZyReceipt.getCharge27()==null?BigDecimal.ZERO:BigDecimal.valueOf(newZyReceipt.getCharge27())).doubleValue());
        newZyReceipt.setCharge28(BigDecimal.ZERO.subtract(newZyReceipt.getCharge28()==null?BigDecimal.ZERO:BigDecimal.valueOf(newZyReceipt.getCharge28())).doubleValue());
        newZyReceipt.setCharge29(BigDecimal.ZERO.subtract(newZyReceipt.getCharge29()==null?BigDecimal.ZERO:BigDecimal.valueOf(newZyReceipt.getCharge29())).doubleValue());
        newZyReceipt.setCharge30(BigDecimal.ZERO.subtract(newZyReceipt.getCharge30()==null?BigDecimal.ZERO:BigDecimal.valueOf(newZyReceipt.getCharge30())).doubleValue());
        return newZyReceipt;
    }

    private ZyLedgerFile getZyLedgerFile(String opId, ZyLedgerFile zyLedgerFile, Integer minLedgerSn, Date now) {
        ZyLedgerFile newZyLedgerFile = CloneUtil.clone(zyLedgerFile);
        newZyLedgerFile.setLedgerSn(minLedgerSn-2);
        newZyLedgerFile.setAccountDate(now);
        newZyLedgerFile.setOpIdCode(opId);
        newZyLedgerFile.setDeposit(BigDecimal.ZERO.subtract(newZyLedgerFile.getDeposit()));
        newZyLedgerFile.setBalance(BigDecimal.ZERO.subtract(newZyLedgerFile.getBalance()));
        newZyLedgerFile.setTotalCharge(BigDecimal.ZERO.subtract(newZyLedgerFile.getTotalCharge()));
        newZyLedgerFile.setCharge1(BigDecimal.ZERO.subtract(newZyLedgerFile.getCharge1()));
        newZyLedgerFile.setCharge2(BigDecimal.ZERO.subtract(newZyLedgerFile.getCharge2()));
        newZyLedgerFile.setCharge3(BigDecimal.ZERO.subtract(newZyLedgerFile.getCharge3()));
        newZyLedgerFile.setCharge4(BigDecimal.ZERO.subtract(newZyLedgerFile.getCharge4()));
        newZyLedgerFile.setCharge5(BigDecimal.ZERO.subtract(newZyLedgerFile.getCharge5()));
        newZyLedgerFile.setCharge6(BigDecimal.ZERO.subtract(newZyLedgerFile.getCharge6()));
        newZyLedgerFile.setCharge7(BigDecimal.ZERO.subtract(newZyLedgerFile.getCharge7()));
        newZyLedgerFile.setCharge8(BigDecimal.ZERO.subtract(newZyLedgerFile.getCharge8()));
        newZyLedgerFile.setCharge9(BigDecimal.ZERO.subtract(newZyLedgerFile.getCharge9()));
        newZyLedgerFile.setCharge10(BigDecimal.ZERO.subtract(newZyLedgerFile.getCharge10()));
        newZyLedgerFile.setCharge11(BigDecimal.ZERO.subtract(newZyLedgerFile.getCharge11()));
        newZyLedgerFile.setCharge12(BigDecimal.ZERO.subtract(newZyLedgerFile.getCharge12()));
        newZyLedgerFile.setCharge13(BigDecimal.ZERO.subtract(newZyLedgerFile.getCharge13()));
        newZyLedgerFile.setCharge14(BigDecimal.ZERO.subtract(newZyLedgerFile.getCharge14()));
        newZyLedgerFile.setCharge15(BigDecimal.ZERO.subtract(newZyLedgerFile.getCharge15()));
        newZyLedgerFile.setCharge16(BigDecimal.ZERO.subtract(newZyLedgerFile.getCharge16()));
        newZyLedgerFile.setCharge17(BigDecimal.ZERO.subtract(newZyLedgerFile.getCharge17()));
        newZyLedgerFile.setCharge18(BigDecimal.ZERO.subtract(newZyLedgerFile.getCharge18()));
        newZyLedgerFile.setCharge19(BigDecimal.ZERO.subtract(newZyLedgerFile.getCharge19()));
        newZyLedgerFile.setCharge20(BigDecimal.ZERO.subtract(newZyLedgerFile.getCharge20()));
        newZyLedgerFile.setCharge21(BigDecimal.ZERO.subtract(newZyLedgerFile.getCharge21()));
        newZyLedgerFile.setCharge22(BigDecimal.ZERO.subtract(newZyLedgerFile.getCharge22()));
        newZyLedgerFile.setCharge23(BigDecimal.ZERO.subtract(newZyLedgerFile.getCharge23()));
        newZyLedgerFile.setCharge24(BigDecimal.ZERO.subtract(newZyLedgerFile.getCharge24()));
        newZyLedgerFile.setCharge25(BigDecimal.ZERO.subtract(newZyLedgerFile.getCharge25()));
        newZyLedgerFile.setCharge26(BigDecimal.ZERO.subtract(newZyLedgerFile.getCharge26()));
        newZyLedgerFile.setCharge27(BigDecimal.ZERO.subtract(newZyLedgerFile.getCharge27()));
        newZyLedgerFile.setCharge28(BigDecimal.ZERO.subtract(newZyLedgerFile.getCharge28()));
        newZyLedgerFile.setCharge29(BigDecimal.ZERO.subtract(newZyLedgerFile.getCharge29()));
        newZyLedgerFile.setCharge30(BigDecimal.ZERO.subtract(newZyLedgerFile.getCharge30()));
        newZyLedgerFile.setLastBalance(BigDecimal.ZERO.subtract(newZyLedgerFile.getLastBalance()));
        newZyLedgerFile.setSettle(BigDecimal.ZERO.subtract(newZyLedgerFile.getSettle()));
        newZyLedgerFile.setCashDate(now);
        newZyLedgerFile.setCashId(opId);
        newZyLedgerFile.setDcountNo(YesNoEnum.NO.code.toString());
        newZyLedgerFile.setDcountDate(null);
        newZyLedgerFile.setTfFlag(YesNoEnum.YES.code.toString());
        return newZyLedgerFile;
    }
}
