package thyyxxk.webserver.service.zygl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ReflectUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import thyyxxk.webserver.config.exception.BizException;
import thyyxxk.webserver.config.exception.ExceptionEnum;
import thyyxxk.webserver.constants.Constants;
import thyyxxk.webserver.constants.SettleTypeEnum;
import thyyxxk.webserver.constants.YesOrNo;
import thyyxxk.webserver.constants.ZyDepositFileStatusEnum;
import thyyxxk.webserver.dao.his.datamodify.ZyDetailChargeDao;
import thyyxxk.webserver.dao.his.inpatient.charge.MzsfBillnoRecDao;
import thyyxxk.webserver.dao.his.zygl.ZyActpatientDao;
import thyyxxk.webserver.dao.his.zygl.ZyDepositFileDao;
import thyyxxk.webserver.dao.his.zygl.ZyLedgerFileDao;
import thyyxxk.webserver.dao.his.zygl.ZyReceiptDao;
import thyyxxk.webserver.entity.executeItem.ZyLedgerFile;
import thyyxxk.webserver.entity.inpatient.ZyActpatient;
import thyyxxk.webserver.entity.inpatient.charge.MzsfBillnoRec;
import thyyxxk.webserver.entity.inpatient.charge.ZyDepositFile;
import thyyxxk.webserver.entity.inpatient.charge.ZyReceipt;
import thyyxxk.webserver.utils.AssertUtil;
import thyyxxk.webserver.utils.CloneUtil;
import thyyxxk.webserver.utils.TokenUtil;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * @Description:
 * @Author:lihong
 * @Date: 2025/5/8
 */
@Service
@Slf4j
public class ZyDepositFileService {

    @Resource
    private ZyDepositFileDao zyDepositFileMapper;
    @Resource
    private ZyActpatientDao zyActpatientMapper;
    @Resource
    private ZyLedgerFileDao zyLedgerFileMapper;
    @Resource
    private ZyReceiptDao zyReceiptMapper;
    @Resource
    private ZyDetailChargeDao zyDetailChargeMapper;
    @Resource
    private MzsfBillnoRecDao mzsfBillnoRecDao;

    public List<ZyDepositFile> queryZyDepositFileByInpatientNoAndTimes(ZyDepositFile zyDepositFile) {
        return zyDepositFileMapper.selectZyDepositFileByInpatientNoAndTimes(zyDepositFile);
    }

    @Transactional(rollbackFor = Exception.class)
    public int saveZyDepositFile(ZyDepositFile zyDepositFile)  {
        AssertUtil.isnotBlank(zyDepositFile.getInpatientNo(),"住院号不能为空");
        AssertUtil.isnotBlank(zyDepositFile.getStatus(),"事务类型不能为空");
        if(!ZyDepositFileStatusEnum.PREPAY.code.equals(zyDepositFile.getStatus()) && !ZyDepositFileStatusEnum.STRAIGHT_BACK.code.equals(zyDepositFile.getStatus())){
            throw new BizException(ExceptionEnum.LOGICAL_ERROR,"事务类型的值不符合规范,只能缴费或直退");
        }
        ZyActpatient zyActpatient = zyActpatientMapper.selectByInpatientNo(ZyActpatient.ZY_ACTPATIENT, zyDepositFile.getInpatientNo(), null);
        AssertUtil.isnotBlank(zyActpatient,"住院号没有查询到对应的住院记录");
        zyDepositFile.setAdmissTimes(zyActpatient.getAdmissTimes());
        Integer depoTimes = zyDepositFileMapper.selectMaxDepoTimes(zyDepositFile);
        if (depoTimes == null) {
            depoTimes = 0;
        }
        depoTimes++;
        zyDepositFile.setDepoTimes(depoTimes);
        zyDepositFile.setDepoDate(new Date());
        zyDepositFile.setWindowNo(ZyDepositFile.IN_HOSPITAL);
        zyDepositFile.setDeleted(YesOrNo.NO.getCode().toString());
        //此时账页信息为空，是收费
        if (zyDepositFile.getLedgerSn() == null) {
            Integer currentLedgerSn = zyLedgerFileMapper.selectCurrentLedgerSn(zyDepositFile.getInpatientNo(), zyActpatient.getAdmissTimes());
            if (currentLedgerSn == null) {
                Integer maxLedgerSn = zyLedgerFileMapper.selectMaxLedgerSn(zyDepositFile.getInpatientNo(), zyActpatient.getAdmissTimes());
                if (maxLedgerSn == null) {
                    maxLedgerSn = 0;
                }
                currentLedgerSn = maxLedgerSn++;
            }
            zyDepositFile.setLedgerSn(currentLedgerSn);
        }
        //查询账页信息
        ZyLedgerFile zyLedgerFile = zyLedgerFileMapper.selectZyLedgerFileByInpatientNoAndTimesAndLedgerSn(zyDepositFile.getInpatientNo(), zyActpatient.getAdmissTimes(), zyDepositFile.getLedgerSn());
        AssertUtil.isnotBlank(zyLedgerFile,"没有找到当前病人本次住院的账页信息");
        //缴费
        if (ZyDepositFileStatusEnum.PREPAY.code.equals(zyDepositFile.getStatus())) {
            AssertUtil.isnotBlank(zyDepositFile.getDepoAmount(),"缴费金额不能为空");
            //非自助或者非聚合支付与银联卡的需要传缴费流水号
            MzsfBillnoRec mzsfBillnoRec = mzsfBillnoRecDao.selectCurYjjSjh(TokenUtil.getInstance().getTokenUserId());
            if(mzsfBillnoRec == null || mzsfBillnoRec.getCurrentNo() == null){
                throw new BizException(ExceptionEnum.LOGICAL_ERROR, "请先设置收据号!");
            }
            Integer countReceiptNo =  zyDepositFileMapper.countReceiptNo(Convert.toStr(mzsfBillnoRec.getCurrentNo()));
            if(countReceiptNo > 0){
                throw new BizException(ExceptionEnum.LOGICAL_ERROR, "当前收据号已经存在,请重新设置!");
            }
            mzsfBillnoRecDao.addYjjSj(TokenUtil.getInstance().getTokenUserId());
            if (YesOrNo.YES.getCode().equals(zyDepositFile.getAutoFlag()) && Arrays.asList(Constants.ZZWX, Constants.ZZZFB, Constants.JHZF, Constants.YLK).contains(zyDepositFile.getDepoType())) {
                AssertUtil.isnotBlank(zyDepositFile.getReceiptNo(),"his缴费订单号不能为空");
                AssertUtil.isnotBlank(zyDepositFile.getAgtordnum(),"流水号不能为空");
                AssertUtil.isnotBlank(zyDepositFile.getPsordnum(),"订单号不能为空");
                zyDepositFile.setChequeNo(zyDepositFile.getReceiptNo());
            }
            zyDepositFile.setReceiptNo(Convert.toStr(mzsfBillnoRec.getCurrentNo()));
            zyDepositFile.setPrinted(0);
        }
        else{
            AssertUtil.isnotBlank(zyDepositFile.getReceiptNo(),"退费,收据号不能为空");
            AssertUtil.isnotBlank(zyDepositFile.getDepoType(),"退费,支付方式不能为空");
            ZyDepositFile tempZyDepositFile =  queryZyDepositFileByReceiptNo(zyDepositFile.getReceiptNo());
            AssertUtil.isnotBlank(tempZyDepositFile, "当前退费的收据号不存在");
            if(YesOrNo.YES.getCode().equals(zyDepositFile.getRefundType())){
                if(!Constants.JHZF.equals(zyDepositFile.getDepoType()) && !Constants.YLK.equals(zyDepositFile.getDepoType())){
                    throw new BizException(ExceptionEnum.LOGICAL_ERROR, "原路退费只能选择聚合支付或银联卡");
                }
                AssertUtil.isnotBlank(tempZyDepositFile.getAgtordnum(),"原缴费记录流水号为空,不能原路退费,请选择普通退费");
                AssertUtil.isnotBlank(tempZyDepositFile.getPsordnum(),"原缴费记录订单号为空,不能原路退费,请选择普通退费");
                zyDepositFile.setPsordnum(tempZyDepositFile.getPsordnum());
                zyDepositFile.setAgtordnum(tempZyDepositFile.getAgtordnum());
                zyDepositFile.setTraceNo(tempZyDepositFile.getTraceNo());
                zyDepositFile.setParChannel(tempZyDepositFile.getParChannel());
            }
            BigDecimal sum = querySumDepoAmountByReceiptNo(zyDepositFile.getReceiptNo());
            if(BigDecimal.ZERO.compareTo(sum) == 0){
                modifyReportFlag(zyDepositFile.getReceiptNo());
                AssertUtil.isnotBlank(tempZyDepositFile, "当前操作的费用已经退过费，请勿重复操作。");
            }
            zyDepositFile.setDepoAmount(BigDecimal.ZERO.subtract(tempZyDepositFile.getDepoAmount()));
            zyDepositFile.setAdmissTimes(tempZyDepositFile.getAdmissTimes());
            zyDepositFile.setLedgerSn(tempZyDepositFile.getLedgerSn());
            zyDepositFile.setPrinted(tempZyDepositFile.getPrinted());
            zyDepositFile.setReportFlag(YesOrNo.YES.getCode().toString());
            zyDepositFile.setReportFlag(YesOrNo.YES.getCode().toString());
            zyDepositFile.setDepoType(zyDepositFile.getDepoType());
            zyDepositFileMapper.updateReportFlag(zyDepositFile.getReceiptNo());
        }
        zyDepositFile.setOpIdCode(TokenUtil.getInstance().getTokenUserId());
        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(ZyActpatient.ZY_ACTPATIENT);
        zyActpatientMapper.updateBalance(zyActpatient);
        return num;
    }

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

    /**
     * @param
     * @description: 按照住院号查询该收据号的总费用  ==0 说明已经退了费  >0 说明未退费
     * @author: lihong
     * @date: 2023/11/15 14:42
     * @param: receiptNo
     * @return: java.math.BigDecimal
     */
    public BigDecimal querySumDepoAmountByInpatientNo(String inpatientNo,Integer admissTimes) {
        return zyDepositFileMapper.selectSumDepoAmountByInpatientNo(inpatientNo,admissTimes);
    }

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

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

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

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

    @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class)
    public int cancelCashi(String opId, String inpatientNo, Integer admissTimes)  {
        ZyLedgerFile zyLedgerFile = zyLedgerFileMapper.selectLastLedgerSn(inpatientNo, admissTimes);
        if (zyLedgerFile == null) {
            throw new BizException(ExceptionEnum.LOGICAL_ERROR,"账页信息不存在");
        }
        if (!SettleTypeEnum.TELLER.code.equals(zyLedgerFile.getSettleType())) {
            throw new BizException(ExceptionEnum.LOGICAL_ERROR,"当前病人的结算状态非【已出纳】，无法进行费用冲销操作！");
        }
        Integer minLedgerSn = zyLedgerFileMapper.selectMinLedgerSn(inpatientNo, admissTimes);
        Date now = new Date();
        //将原账页信息修改保存
        ZyLedgerFile oriZyLedgerFile = CloneUtil.clone(zyLedgerFile);
        oriZyLedgerFile.setLedgerSn(minLedgerSn - 1);
        oriZyLedgerFile.setTfFlag(YesOrNo.YES.getCode().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 BizException(ExceptionEnum.LOGICAL_ERROR,"收据信息不存在");
        }
        ZyDepositFile updateZyDepositFile = new ZyDepositFile();
        updateZyDepositFile.setInpatientNo(inpatientNo);
        updateZyDepositFile.setAdmissTimes(zyDepositFile.getAdmissTimes());
        updateZyDepositFile.setDepoTimes(zyDepositFile.getDepoTimes());
        updateZyDepositFile.setLedgerSn(oriZyLedgerFile.getLedgerSn());
        updateZyDepositFile.setDeleted(YesOrNo.YES.getCode().toString());
        zyDepositFileMapper.updateZyDepositFileCommon(updateZyDepositFile);
        zyDepositFile.setDepoDate(now);
        zyDepositFile.setOpIdCode(opId);
        zyDepositFile.setDepoAmount(BigDecimal.ZERO.subtract(zyDepositFile.getDepoAmount()));
        zyDepositFile.setLedgerSn(newZyLedgerFile.getLedgerSn());
        zyDepositFile.setDeleted(YesOrNo.YES.getCode().toString());
        zyDepositFileMapper.insetZyDepositFile(zyDepositFile);

        ZyReceipt zyReceipt = zyReceiptMapper.selectLastZyReceipt(inpatientNo, admissTimes);
        if (zyReceipt == null) {
            throw new BizException(ExceptionEnum.LOGICAL_ERROR,"发票信息不存在");
        }
        //将原账页信息修改保存
        ZyReceipt oriZyReceipt = CloneUtil.clone(zyReceipt);
        oriZyReceipt.setLedgerSn(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("");
        updateZyReceipt.setPrintDate(DateUtil.parse("1970-01-01", "yyyy-MM-dd"));
        zyReceiptMapper.clearZyReceipt(updateZyReceipt);
        zyDetailChargeMapper.insertForCancelCashi(inpatientNo, admissTimes, 1, 1, now, oriZyLedgerFile.getLedgerSn());
        return zyDetailChargeMapper.insertForCancelCashi(inpatientNo, admissTimes, 1, -1, now, newZyLedgerFile.getLedgerSn());
    }

    //@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class)
    //public List<ZyDepositFile> teller(String opId, ZyDepositFileVo zyDepositFileVo)  {
    //    if (zyDepositFileVo == null) {
    //        throw new MzException("费用参数不能为空！");
    //    }
    //    if (zyDepositFileVo.getZyDepositFiles() == null || zyDepositFileVo.getZyDepositFiles().size() == 0) {
    //        throw new MzException("结算补交或者结算退费支付方式不能为空！");
    //    }
    //    String inpatientNo = null;
    //    Double admissTimes = null;
    //    Integer maxDepoTimes = null;
    //    Integer maxLedgerSn = null;
    //    List<ZyDepositFile> refundPosList = null;
    //    Date now = new Date();
    //    for (ZyDepositFile zyDepositFile : zyDepositFileVo.getZyDepositFiles()) {
    //        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());
    //        }
    //        if (zyDepositFileVo.getRefundType() != null) {
    //            if (YesNoEnum.NO.code.equals(zyDepositFileVo.getRefundType())) {
    //                zyDepositFile.setDepoType(Constants.CASH);
    //            } else if (YesNoEnum.YES.code.equals(zyDepositFileVo.getRefundType())) {
    //                if (refundPosList == null) {
    //                    refundPosList = new ArrayList<>();
    //                }
    //                if (Constants.YLK.equals(zyDepositFile.getDepoType()) || Constants.JHZF.equals(zyDepositFile.getDepoType())) {
    //                    ZyDepositFile dbZyDepositFile=zyDepositFileMapper.selectZyDepositFileByReceiptNo(zyDepositFile.getReceiptNo());
    //                    if(dbZyDepositFile==null){
    //                        throw new MzException("根据收据号未查询到对应的未退费预交金记录！");
    //                    }
    //                    zyDepositFile.setParChannel(dbZyDepositFile.getParChannel());
    //                    zyDepositFile.setPsordnum(dbZyDepositFile.getPsordnum());
    //                    zyDepositFile.setAgtordnum(dbZyDepositFile.getAgtordnum());
    //                    zyDepositFile.setTransDate(dbZyDepositFile.getTransDate());
    //                    zyDepositFile.setTraceNo(dbZyDepositFile.getTraceNo());
    //                    refundPosList.add(zyDepositFile);
    //                }
    //            }
    //        }
    //        zyDepositFile.setDepoTimes(Double.valueOf(++maxDepoTimes));
    //        zyDepositFile.setDepoDate(now);
    //        zyDepositFile.setOpIdCode(opId);
    //        if(zyDepositFile.getReceiptNo()==null){
    //            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");
    //    zyActpatientMapper.updateBalance(updateZyActpatient);
    //    return refundPosList;
    //}

    private ZyReceipt getZyReceipt(String opId, Date now, ZyLedgerFile newZyLedgerFile, ZyReceipt zyReceipt) {
        ZyReceipt newZyReceipt = CloneUtil.clone(zyReceipt);
        newZyReceipt.setLedgerSn(newZyLedgerFile.getLedgerSn());
        newZyReceipt.setTotalCharge(BigDecimal.ZERO.subtract(newZyReceipt.getTotalCharge()));
        newZyReceipt.setAccountDate(now);
        newZyReceipt.setPrintDate(DateUtil.parse("1900-01-01 00:00:00.000", "yyyy-MM-dd HH:mm:ss"));
        newZyReceipt.setOpIdCode(opId);
        for (int i = 1; i <= 30 ; i++) {
            String fieldName = "charge"+i;
            BigDecimal charge = Convert.toBigDecimal(ReflectUtil.getFieldValue(newZyReceipt, fieldName),BigDecimal.ZERO);
            ReflectUtil.setFieldValue(newZyReceipt,fieldName,BigDecimal.ZERO.subtract(charge));
        }
        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(YesOrNo.NO.getCode().toString());
        newZyLedgerFile.setDcountDate(null);
        newZyLedgerFile.setTfFlag(YesOrNo.YES.getCode().toString());
        return newZyLedgerFile;
    }
}
