|  | @@ -621,8 +621,8 @@ public class MzChargeDetailServiceImpl implements MzChargeDetailService {
 | 
	
		
			
				|  |  |          mzChargeDetailMapper.updatePayMakAndPrintFlag(updateMzChargeDetail);
 | 
	
		
			
				|  |  |          List<MzReceiptSerial> mzReceiptSerials = mzReceiptSerialMapper.selectSerialForThisTime(mzDepositFileVo.getPatientId(), mzDepositFileVo.getTimes());
 | 
	
		
			
				|  |  |          if (mzReceiptSerials != null && mzReceiptSerials.size() > 0) {
 | 
	
		
			
				|  |  | -            formatRefundReceiptSerial(mzReceiptSerials,opId);
 | 
	
		
			
				|  |  | -            mzReceiptSerialMapper.batchInsertMzReceiptSerial(mzReceiptSerials);
 | 
	
		
			
				|  |  | +            List<MzReceiptSerial> newReceiptSerials  = formatRefundReceiptSerial(mzReceiptSerials,opId);
 | 
	
		
			
				|  |  | +            mzReceiptSerialMapper.batchInsertMzReceiptSerial(newReceiptSerials);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          MzReceiptSerial updateMzReceiptSerial = new MzReceiptSerial(mzDepositFileVo.getPatientId(), mzDepositFileVo.getTimes());
 | 
	
		
			
				|  |  |          //updateMzReceiptSerial.setPayMark(PayMarkEnum.RETURN_PREMIUM.code);
 | 
	
	
		
			
				|  | @@ -689,8 +689,19 @@ public class MzChargeDetailServiceImpl implements MzChargeDetailService {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    private void formatRefundReceiptSerial(List<MzReceiptSerial> mzReceiptSerials,String opId) {
 | 
	
		
			
				|  |  | +    private List<MzReceiptSerial> formatRefundReceiptSerial(List<MzReceiptSerial> mzReceiptSerials,String opId) {
 | 
	
		
			
				|  |  | +        Set<String> tempSet = new HashSet<>();
 | 
	
		
			
				|  |  | +        List<MzReceiptSerial> newReceiptSerials  = new ArrayList<>();
 | 
	
		
			
				|  |  |          for (MzReceiptSerial mz : mzReceiptSerials) {
 | 
	
		
			
				|  |  | +            //退过费的发票表记录
 | 
	
		
			
				|  |  | +            if(mz.getSerialNo()<0 && mz.getReceiptNo()<0){
 | 
	
		
			
				|  |  | +                Integer tempSerialNo =-mz.getSerialNo();
 | 
	
		
			
				|  |  | +                tempSet.add(mz.getChequeType()+"_"+tempSerialNo);
 | 
	
		
			
				|  |  | +                continue;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if(tempSet.contains(mz.getChequeType()+"_"+mz.getSerialNo())){
 | 
	
		
			
				|  |  | +                continue;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |              mz.setOperatorId(opId);
 | 
	
		
			
				|  |  |              mz.setReceiptNo(-mz.getReceiptNo());
 | 
	
		
			
				|  |  |              mz.setPayId(opId);
 | 
	
	
		
			
				|  | @@ -723,7 +734,9 @@ public class MzChargeDetailServiceImpl implements MzChargeDetailService {
 | 
	
		
			
				|  |  |              mz.setChequeType(Constants.CASH);
 | 
	
		
			
				|  |  |              mz.setChargeDcountDate(null);
 | 
	
		
			
				|  |  |              mz.setChargeDcountNo(YesNoEnum.NO.code);
 | 
	
		
			
				|  |  | +            newReceiptSerials.add(mz);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        return newReceiptSerials;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      private void fromatRefundDetail(String opId, List<MzChargeDetail> mzChargeDetails, List<String> chargeItemCodeList, List<MzChargeDetail> oriMzChargeDetails, Date now, List<MzChargeDetail> tcMzChargeDetails, List<MzChargeDetail> removeMzChargeDetails) {
 | 
	
	
		
			
				|  | @@ -776,26 +789,29 @@ public class MzChargeDetailServiceImpl implements MzChargeDetailService {
 | 
	
		
			
				|  |  |      private String getDeposFiles(String opId, MzDepositFileVo mzDepositFileVo, Date now, int times, int serialNo, BigDecimal totalPayable, String payWay, List<MzDepositFile> newMzDepositFiles, boolean allRefund) {
 | 
	
		
			
				|  |  |          List<MzDepositFile> mzDepositFiles = mzDepositFileMapper.selectMzDepositFileByTimes(mzDepositFileVo.getPatientId(), mzDepositFileVo.getTimes(),mzDepositFileVo.getReceiptNo());
 | 
	
		
			
				|  |  |          if (mzDepositFiles != null || mzDepositFiles.size() > 0) {
 | 
	
		
			
				|  |  | +            MzDepositFile temp = CloneUtil.clone(mzDepositFiles.get(0));
 | 
	
		
			
				|  |  | +            temp.setReceiptNo(-temp.getReceiptNo());
 | 
	
		
			
				|  |  | +            temp.setAmount(BigDecimal.ZERO.subtract(temp.getAmount()));
 | 
	
		
			
				|  |  | +            temp.setReceiptSn(-temp.getReceiptSn());
 | 
	
		
			
				|  |  | +            temp.setSerialNo(-temp.getSerialNo());
 | 
	
		
			
				|  |  | +            temp.setDeptNo(null);
 | 
	
		
			
				|  |  | +            temp.setChargeDate(now);
 | 
	
		
			
				|  |  | +            temp.setPayMark(PayMarkEnum.RETURN_PREMIUM.code);
 | 
	
		
			
				|  |  | +            temp.setOpId(opId);
 | 
	
		
			
				|  |  | +            temp.setChequeType(Constants.CASH);
 | 
	
		
			
				|  |  | +            temp.setDcountNo(YesNoEnum.NO.code);
 | 
	
		
			
				|  |  | +            temp.setDcountDate(null);
 | 
	
		
			
				|  |  | +            newMzDepositFiles.add(temp);
 | 
	
		
			
				|  |  | +            BigDecimal amount=BigDecimal.ZERO;
 | 
	
		
			
				|  |  |              for (MzDepositFile ms : mzDepositFiles) {
 | 
	
		
			
				|  |  |                  if (ms != null) {
 | 
	
		
			
				|  |  |                      if (StringUtils.isNotBlank(ms.getChequeType())) {
 | 
	
		
			
				|  |  |                          payWay = ms.getChequeType();
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  | -                    MzDepositFile temp = CloneUtil.clone(ms);
 | 
	
		
			
				|  |  | -                    temp.setReceiptNo(-temp.getReceiptNo());
 | 
	
		
			
				|  |  | -                    temp.setAmount(BigDecimal.ZERO.subtract(temp.getAmount()));
 | 
	
		
			
				|  |  | -                    temp.setReceiptSn(-temp.getReceiptSn());
 | 
	
		
			
				|  |  | -                    temp.setSerialNo(-temp.getSerialNo());
 | 
	
		
			
				|  |  | -                    temp.setDeptNo(null);
 | 
	
		
			
				|  |  | -                    temp.setChargeDate(now);
 | 
	
		
			
				|  |  | -                    temp.setPayMark(PayMarkEnum.RETURN_PREMIUM.code);
 | 
	
		
			
				|  |  | -                    temp.setOpId(opId);
 | 
	
		
			
				|  |  | -                    temp.setChequeType(Constants.CASH);
 | 
	
		
			
				|  |  | -                    temp.setDcountNo(YesNoEnum.NO.code);
 | 
	
		
			
				|  |  | -                    temp.setDcountDate(null);
 | 
	
		
			
				|  |  | -                    newMzDepositFiles.add(temp);
 | 
	
		
			
				|  |  | +                    amount=amount.add(ms.getAmount());
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | +            temp.setAmount(amount);
 | 
	
		
			
				|  |  |              if (!allRefund) {
 | 
	
		
			
				|  |  |                  MzDepositFile m = mzDepositFiles.get(0);
 | 
	
		
			
				|  |  |                  m.setTimes(times);
 |