Commit bdf1b53e by huluobin

fix

parent 0ce8ec64
...@@ -88,7 +88,7 @@ public abstract class AbstractCostPlanService implements CostPlanService { ...@@ -88,7 +88,7 @@ public abstract class AbstractCostPlanService implements CostPlanService {
costPlanDomain.setCreateUserid(user.getUserid()); costPlanDomain.setCreateUserid(user.getUserid());
costPlanDomain.setCreateUsername(user.getUsername()); costPlanDomain.setCreateUsername(user.getUsername());
costPlanDomain.setCreateTime(new Date()); costPlanDomain.setCreateTime(new Date());
costPlanDomain.setPayCur(costPlanDomain.getCur());
/*附件字段*/ /*附件字段*/
......
...@@ -77,6 +77,9 @@ public class CostPlanDomain { ...@@ -77,6 +77,9 @@ public class CostPlanDomain {
private String payDic; // 支付币种 private String payDic; // 支付币种
private BigDecimal payCur; // 汇率 private BigDecimal payCur; // 汇率
@TableField(exist = false)
private BigDecimal cur; // 汇率
private Integer isTax; // 0 不抵扣个税 1 抵扣个税 private Integer isTax; // 0 不抵扣个税 1 抵扣个税
private Integer companyValue; // 公司主体value private Integer companyValue; // 公司主体value
......
...@@ -2,10 +2,11 @@ package com.blt.other.module.purchasing.service.impl; ...@@ -2,10 +2,11 @@ package com.blt.other.module.purchasing.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.blt.other.module.auth.dao.UserDao; import com.blt.other.common.util.BuyUtils;
import com.blt.other.common.util.CurUtils; import com.blt.other.common.util.CurUtils;
import com.blt.other.common.util.MoneyUtil; import com.blt.other.common.util.MoneyUtil;
import com.blt.other.common.util.PathUtil; import com.blt.other.common.util.PathUtil;
import com.blt.other.module.auth.dao.UserDao;
import com.blt.other.module.cost.dao.CostCompanyDao; import com.blt.other.module.cost.dao.CostCompanyDao;
import com.blt.other.module.cost.dao.CostDao; import com.blt.other.module.cost.dao.CostDao;
import com.blt.other.module.cost.dao.CostPlanDao; import com.blt.other.module.cost.dao.CostPlanDao;
...@@ -23,7 +24,6 @@ import com.blt.other.module.purchasing.dto.*; ...@@ -23,7 +24,6 @@ import com.blt.other.module.purchasing.dto.*;
import com.blt.other.module.purchasing.service.BuyLogService; import com.blt.other.module.purchasing.service.BuyLogService;
import com.blt.other.module.purchasing.service.BuyPlanService; import com.blt.other.module.purchasing.service.BuyPlanService;
import com.blt.other.module.purchasing.service.BuyService; import com.blt.other.module.purchasing.service.BuyService;
import com.blt.other.common.util.BuyUtils;
import com.blt.other.module.supplier.service.SupplierService; import com.blt.other.module.supplier.service.SupplierService;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
...@@ -84,21 +84,22 @@ public class BuyServiceImpl implements BuyService { ...@@ -84,21 +84,22 @@ public class BuyServiceImpl implements BuyService {
/** /**
* 分页获取采购订单列表 * 分页获取采购订单列表
*
* @param pageSize * @param pageSize
* @param page * @param page
* @return * @return
*/ */
@Override @Override
public Map<String, Object> getAllBuyList(int pageSize, int page) { public Map<String, Object> getAllBuyList(int pageSize, int page) {
logger.warn("分页查询采购单列表:pagesize "+pageSize+" ,page "+page); logger.warn("分页查询采购单列表:pagesize " + pageSize + " ,page " + page);
PageHelper.startPage(page,pageSize); PageHelper.startPage(page, pageSize);
Map<String,Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
List<BuyDomain> buyDomains = buyDao.selectAll(); List<BuyDomain> buyDomains = buyDao.selectAll();
List<BuyListDto> buyListDto = getBuyListDto(buyDomains); List<BuyListDto> buyListDto = getBuyListDto(buyDomains);
PageInfo<BuyDomain> pageInfo = new PageInfo<>(buyDomains); PageInfo<BuyDomain> pageInfo = new PageInfo<>(buyDomains);
map.put("buys",buyListDto); map.put("buys", buyListDto);
map.put("pageInfo",pageInfo); map.put("pageInfo", pageInfo);
return map; return map;
} }
...@@ -108,7 +109,7 @@ public class BuyServiceImpl implements BuyService { ...@@ -108,7 +109,7 @@ public class BuyServiceImpl implements BuyService {
buyDomain.setBuyno(buyno); buyDomain.setBuyno(buyno);
List<BuyDomain> buyDomainList = buyDao.selectByBuyno(buyDomain); List<BuyDomain> buyDomainList = buyDao.selectByBuyno(buyDomain);
List<BuyListDto> buyListDto = getBuyListDto(buyDomainList); List<BuyListDto> buyListDto = getBuyListDto(buyDomainList);
if (null != buyListDto && buyListDto.size() >= 1){ if (null != buyListDto && buyListDto.size() >= 1) {
return buyListDto.get(0); return buyListDto.get(0);
} }
return null; return null;
...@@ -116,21 +117,23 @@ public class BuyServiceImpl implements BuyService { ...@@ -116,21 +117,23 @@ public class BuyServiceImpl implements BuyService {
@Override @Override
public Integer getUpdate(BuyDomain buyDomain) { public Integer getUpdate(BuyDomain buyDomain) {
logger.warn("修改采购单信息"+buyDomain); logger.warn("修改采购单信息" + buyDomain);
String skucode = buyDomain.getSkucode(); String skucode = buyDomain.getSkucode();
String skuname = buyDomain.getSkuname(); String skuname = buyDomain.getSkuname();
if (null != skucode && !skucode.contains("[")){ if (null != skucode && !skucode.contains("[")) {
skucode = "["+skucode+"]"; skucode = "[" + skucode + "]";
} }
if (null != skuname && !skuname.contains("[")){ if (null != skuname && !skuname.contains("[")) {
skuname = "["+skuname+"]"; skuname = "[" + skuname + "]";
} }
Integer update = buyDao.update(buyDomain); Integer update = buyDao.update(buyDomain);
return update; return update;
} }
@Override @Override
public BuyDomain getBuyDomain(BuyDomain buyDomain) { return buyDao.selectBuy(buyDomain); } public BuyDomain getBuyDomain(BuyDomain buyDomain) {
return buyDao.selectBuy(buyDomain);
}
@Override @Override
public List<BuyListDto> getDtoList(List<BuyDomain> list) { public List<BuyListDto> getDtoList(List<BuyDomain> list) {
...@@ -139,6 +142,7 @@ public class BuyServiceImpl implements BuyService { ...@@ -139,6 +142,7 @@ public class BuyServiceImpl implements BuyService {
/** /**
* 生成采购单 * 生成采购单
*
* @param buy * @param buy
* @param buyPlanDomain * @param buyPlanDomain
* @return * @return
...@@ -180,14 +184,14 @@ public class BuyServiceImpl implements BuyService { ...@@ -180,14 +184,14 @@ public class BuyServiceImpl implements BuyService {
List<String> skuname = new ArrayList<>(); List<String> skuname = new ArrayList<>();
BigDecimal amount = new BigDecimal(0); BigDecimal amount = new BigDecimal(0);
Integer count = 0; Integer count = 0;
for (BuyPlanDetailDomain detail: buy){ for (BuyPlanDetailDomain detail : buy) {
skucode.add(detail.getSkucode()); skucode.add(detail.getSkucode());
skuname.add(detail.getSkuname()); skuname.add(detail.getSkuname());
amount = amount.add(detail.getAmount()); amount = amount.add(detail.getAmount());
count = count+detail.getCount(); count = count + detail.getCount();
// 生成 buy_detail 记录 // 生成 buy_detail 记录
BuyDetailDomain buyDetailDomain = new BuyDetailDomain(); BuyDetailDomain buyDetailDomain = new BuyDetailDomain();
BeanUtils.copyProperties(detail,buyDetailDomain); BeanUtils.copyProperties(detail, buyDetailDomain);
buyDetailDomain.setBuyno(buyDomain.getBuyno()); buyDetailDomain.setBuyno(buyDomain.getBuyno());
Integer insert = buyDetailDao.insert(buyDetailDomain); Integer insert = buyDetailDao.insert(buyDetailDomain);
} }
...@@ -199,14 +203,15 @@ public class BuyServiceImpl implements BuyService { ...@@ -199,14 +203,15 @@ public class BuyServiceImpl implements BuyService {
} }
Integer insert = buyDao.insert(buyDomain); Integer insert = buyDao.insert(buyDomain);
// 生成采购单后,记录日志 // 生成采购单后,记录日志
if (null != insert && insert == 1){ if (null != insert && insert == 1) {
buyLogService.save(buyDomain.getBuyno(),buyPlanDomain.getAudituserid(),"由"+buyDomain.getNo()+"生成采购单"); buyLogService.save(buyDomain.getBuyno(), buyPlanDomain.getAudituserid(), "由" + buyDomain.getNo() + "生成采购单");
} }
return insert; return insert;
} }
/** /**
* 获取最新的一条采购单 * 获取最新的一条采购单
*
* @return * @return
*/ */
@Override @Override
...@@ -216,51 +221,52 @@ public class BuyServiceImpl implements BuyService { ...@@ -216,51 +221,52 @@ public class BuyServiceImpl implements BuyService {
/** /**
* 更改采购单号(避免出纳驳回的采购单重新提交出纳系统出现采购单重复) * 更改采购单号(避免出纳驳回的采购单重新提交出纳系统出现采购单重复)
*
* @param oldBuyno * @param oldBuyno
* @param newBuyno * @param newBuyno
* @return * @return
*/ */
@Override @Override
public Integer updateNewBuyno(String oldBuyno, String newBuyno) { public Integer updateNewBuyno(String oldBuyno, String newBuyno) {
return buyDao.updateNewBuyno(oldBuyno,newBuyno); return buyDao.updateNewBuyno(oldBuyno, newBuyno);
} }
private List<BuyListDto> getBuyListDto(List<BuyDomain> buyDomains){ private List<BuyListDto> getBuyListDto(List<BuyDomain> buyDomains) {
List<BuyListDto> buyListDtos = new ArrayList<>(); List<BuyListDto> buyListDtos = new ArrayList<>();
if (null != buyDomains && buyDomains.size()>=1){ if (null != buyDomains && buyDomains.size() >= 1) {
BuyListDto buyListDto = null; BuyListDto buyListDto = null;
for (BuyDomain buyDomain : buyDomains){ for (BuyDomain buyDomain : buyDomains) {
buyListDto = new BuyListDto(); buyListDto = new BuyListDto();
BeanUtils.copyProperties(buyDomain,buyListDto); BeanUtils.copyProperties(buyDomain, buyListDto);
String skucode = buyListDto.getSkucode(); String skucode = buyListDto.getSkucode();
String skuname = buyListDto.getSkuname(); String skuname = buyListDto.getSkuname();
if (null != skucode){ if (null != skucode) {
skucode = skucode.substring(1,skucode.lastIndexOf("]")); skucode = skucode.substring(1, skucode.lastIndexOf("]"));
skuname = skuname.substring(1,skuname.lastIndexOf("]")); skuname = skuname.substring(1, skuname.lastIndexOf("]"));
} }
if (skucode != null && skucode.contains(",")){ if (skucode != null && skucode.contains(",")) {
// 含有多种商品 // 含有多种商品
String[] split = skucode.split(","); String[] split = skucode.split(",");
skucode = split[0]+"等共 "+split.length+" 项"; skucode = split[0] + "等共 " + split.length + " 项";
} }
if (skuname != null && skuname.contains(",")){ if (skuname != null && skuname.contains(",")) {
// 含有多种商品 // 含有多种商品
String[] split = skuname.split(","); String[] split = skuname.split(",");
skuname = split[0]+"等共 "+split.length+" 项"; skuname = split[0] + "等共 " + split.length + " 项";
} }
// 获取文件名 // 获取文件名
String filePath = buyDomain.getFilepath(); String filePath = buyDomain.getFilepath();
if (null != filePath && filePath.contains("&")){ if (null != filePath && filePath.contains("&")) {
buyListDto.setFilename(filePath.substring(filePath.lastIndexOf("&") + 1)); buyListDto.setFilename(filePath.substring(filePath.lastIndexOf("&") + 1));
} }
buyListDto.setSkucode(skucode); buyListDto.setSkucode(skucode);
buyListDto.setSkuname(skuname); buyListDto.setSkuname(skuname);
buyListDto.setBuystatusDto(statusMapper.getStatusValue("buystatus",buyDomain.getBuystatus())); buyListDto.setBuystatusDto(statusMapper.getStatusValue("buystatus", buyDomain.getBuystatus()));
buyListDto.setDelstatusDto(statusMapper.getStatusValue("delstatus",buyDomain.getDelstatus())); buyListDto.setDelstatusDto(statusMapper.getStatusValue("delstatus", buyDomain.getDelstatus()));
buyListDto.setIsurgencyDto(statusMapper.getStatusValue("isurgency",buyDomain.getIsurgency())); buyListDto.setIsurgencyDto(statusMapper.getStatusValue("isurgency", buyDomain.getIsurgency()));
buyListDto.setPaystatusDto(statusMapper.getStatusValue("paystatus",buyDomain.getPaystatus())); buyListDto.setPaystatusDto(statusMapper.getStatusValue("paystatus", buyDomain.getPaystatus()));
buyListDto.setPaytypeDto(statusMapper.getStatusValue("paytype",buyDomain.getPaytype())); buyListDto.setPaytypeDto(statusMapper.getStatusValue("paytype", buyDomain.getPaytype()));
buyListDto.setSendstatusDto(statusMapper.getStatusValue("sendstatus",buyDomain.getSendstatus())); buyListDto.setSendstatusDto(statusMapper.getStatusValue("sendstatus", buyDomain.getSendstatus()));
buyListDtos.add(buyListDto); buyListDtos.add(buyListDto);
} }
...@@ -276,10 +282,11 @@ public class BuyServiceImpl implements BuyService { ...@@ -276,10 +282,11 @@ public class BuyServiceImpl implements BuyService {
if (null == linkLendCost.getCounteract()) linkLendCost.setCounteract(new BigDecimal(0)); if (null == linkLendCost.getCounteract()) linkLendCost.setCounteract(new BigDecimal(0));
if (null == linkLendCost.getLendBalance()) linkLendCost.setLendBalance(new BigDecimal(0)); if (null == linkLendCost.getLendBalance()) linkLendCost.setLendBalance(new BigDecimal(0));
BigDecimal subtract = linkLendCost.getAmount().subtract(linkLendCost.getHadPay()); // 关联借支单还需还差额 BigDecimal subtract = linkLendCost.getAmount().subtract(linkLendCost.getHadPay()); // 关联借支单还需还差额
BigDecimal exRate = null; // 采购单币种(现默认CNY)转借支单币种汇率
if("CNY".equals(linkLendCost.getDic())){ BigDecimal exRate; // 采购单币种(现默认CNY)转借支单币种汇率
if ("CNY".equals(linkLendCost.getDic())) {
exRate = new BigDecimal("1"); exRate = new BigDecimal("1");
}else{ } else {
exRate = CurUtils.getCur("CNY", linkLendCost.getDic(), getExchangeRateApi); exRate = CurUtils.getCur("CNY", linkLendCost.getDic(), getExchangeRateApi);
} }
BigDecimal counteract = buyListDto.getAmount().multiply(exRate).setScale(2, BigDecimal.ROUND_HALF_UP); // 冲销金额,RMB BigDecimal counteract = buyListDto.getAmount().multiply(exRate).setScale(2, BigDecimal.ROUND_HALF_UP); // 冲销金额,RMB
...@@ -291,10 +298,10 @@ public class BuyServiceImpl implements BuyService { ...@@ -291,10 +298,10 @@ public class BuyServiceImpl implements BuyService {
String result = "采购单【" + buyListDto.getBuyno() + "】冲销借支单【" + linkLendCost.getCostNo() + "】成功,金额为" + String result = "采购单【" + buyListDto.getBuyno() + "】冲销借支单【" + linkLendCost.getCostNo() + "】成功,金额为" +
counteract.toString() + linkLendCost.getDic(); counteract.toString() + linkLendCost.getDic();
if(counteract.compareTo(numZero) != 1){ if (counteract.compareTo(numZero) != 1) {
result = "采购单金额必须大于0,请驳回"; result = "采购单金额必须大于0,请驳回";
return result; return result;
} else if(counteract.compareTo(subtract) == -1){ } else if (counteract.compareTo(subtract) == -1) {
// 冲销金额<借支单待还金额,借支单改为部分还款状态 // 冲销金额<借支单待还金额,借支单改为部分还款状态
linkLendCost.setLendStatus(2); linkLendCost.setLendStatus(2);
// 生成一张已完成的借还单 // 生成一张已完成的借还单
...@@ -302,21 +309,21 @@ public class BuyServiceImpl implements BuyService { ...@@ -302,21 +309,21 @@ public class BuyServiceImpl implements BuyService {
result += ",借支单剩余待还金额" + subtract.subtract(counteract).toString() + linkLendCost.getDic(); result += ",借支单剩余待还金额" + subtract.subtract(counteract).toString() + linkLendCost.getDic();
} else if(counteract.compareTo(subtract) == 0){ } else if (counteract.compareTo(subtract) == 0) {
// 冲销金额=借支单待还金额,借支单改为已结清状态 // 冲销金额=借支单待还金额,借支单改为已结清状态
linkLendCost.setLendStatus(4); linkLendCost.setLendStatus(4);
// 生成一张已完成的借还单 // 生成一张已完成的借还单
backCost = generateBackCost(buyListDto, linkLendCost, counteract, exRate); backCost = generateBackCost(buyListDto, linkLendCost, counteract, exRate);
result += ",借支单已结清"; result += ",借支单已结清";
} else if(counteract.compareTo(subtract) == 1){ } else if (counteract.compareTo(subtract) == 1) {
// 冲销金额>借支单待还金额,不允许关联借支单 // 冲销金额>借支单待还金额,不允许关联借支单
/*result = "采购单的金额大于借支单待还金额,不允许进行冲销,请驳回"; /*result = "采购单的金额大于借支单待还金额,不允许进行冲销,请驳回";
return result;*/ return result;*/
// 冲销金额>借支单待还金额,借支单改为待补差额状态,生成一张待提交的付款计划单 // 冲销金额>借支单待还金额,借支单改为待补差额状态,生成一张待提交的付款计划单
linkLendCost.setLendStatus(3); linkLendCost.setLendStatus(3);
// 生成一张已完成的借还单,金额为借支单剩余待还金额,不包含待补差额 // 生成一张已完成的借还单,金额为借支单剩余待还金额,不包含待补差额
backCost = generateBackCost(buyListDto, linkLendCost,counteract, exRate); backCost = generateBackCost(buyListDto, linkLendCost, counteract, exRate);
backCost.setAmount(subtract); backCost.setAmount(subtract);
backCost.setCounteract(subtract); backCost.setCounteract(subtract);
backCost.setPayPlanAmount(subtract.divide(exRate, 4)); backCost.setPayPlanAmount(subtract.divide(exRate, 4));
...@@ -388,13 +395,14 @@ public class BuyServiceImpl implements BuyService { ...@@ -388,13 +395,14 @@ public class BuyServiceImpl implements BuyService {
/** /**
* 采购单冲销借支单时生成已完成状态的借还单 * 采购单冲销借支单时生成已完成状态的借还单
* @param buyListDto 采购单 *
* @param buyListDto 采购单
* @param linkLendCost 关联的借支单 * @param linkLendCost 关联的借支单
* @param counteract 采购单冲销金额,即生成的借还单金额 * @param counteract 采购单冲销金额,即生成的借还单金额
* @param exRate 汇率:采购单币种-->借支单币种 * @param exRate 汇率:采购单币种-->借支单币种
* @return * @return
*/ */
public CostDomain generateBackCost(BuyListDto buyListDto, CostDomain linkLendCost, BigDecimal counteract, BigDecimal exRate){ public CostDomain generateBackCost(BuyListDto buyListDto, CostDomain linkLendCost, BigDecimal counteract, BigDecimal exRate) {
CostDomain backCost = new CostDomain(); CostDomain backCost = new CostDomain();
BeanUtils.copyProperties(linkLendCost, backCost); BeanUtils.copyProperties(linkLendCost, backCost);
backCost.setCostPlanNo(null); backCost.setCostPlanNo(null);
...@@ -427,7 +435,7 @@ public class BuyServiceImpl implements BuyService { ...@@ -427,7 +435,7 @@ public class BuyServiceImpl implements BuyService {
List<BuyDomain> buyList = buyDao.selectByIds(printBuyIds); List<BuyDomain> buyList = buyDao.selectByIds(printBuyIds);
List<BuyListPrintDto> buyListPrintDtos = new ArrayList<>(); List<BuyListPrintDto> buyListPrintDtos = new ArrayList<>();
BuyListPrintDto printDto = null; BuyListPrintDto printDto = null;
for (BuyDomain buyDomain : buyList){ for (BuyDomain buyDomain : buyList) {
printDto = new BuyListPrintDto(); printDto = new BuyListPrintDto();
BeanUtils.copyProperties(buyDomain, printDto); BeanUtils.copyProperties(buyDomain, printDto);
printDto.setTxtAmount(MoneyUtil.getCnNum(printDto.getAmount())); printDto.setTxtAmount(MoneyUtil.getCnNum(printDto.getAmount()));
...@@ -442,19 +450,19 @@ public class BuyServiceImpl implements BuyService { ...@@ -442,19 +450,19 @@ public class BuyServiceImpl implements BuyService {
HSSFSheet sheet = workbook.createSheet("采购单"); HSSFSheet sheet = workbook.createSheet("采购单");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
List<BuyExportDto> exportList = buyDao.selectExportByIds(buyIds); List<BuyExportDto> exportList = buyDao.selectExportByIds(buyIds);
if (null == exportList || exportList.size() < 1){ if (null == exportList || exportList.size() < 1) {
return null; return null;
} }
// 设置表头 // 设置表头
String[] headers = {"采购单号","SKU大类","仓库","采购单状态","发货状态","关联借支单号","采购主体","供应商","SKU标题","数量","单价","付款金额","币种","创建人名称","部门","下单时间","付款日期"}; String[] headers = {"采购单号", "SKU大类", "仓库", "采购单状态", "发货状态", "关联借支单号", "采购主体", "供应商", "SKU标题", "数量", "单价", "付款金额", "币种", "创建人名称", "部门", "下单时间", "付款日期"};
HSSFRow row0 = sheet.createRow(0); HSSFRow row0 = sheet.createRow(0);
for (int i = 0; i<headers.length;i++){ for (int i = 0; i < headers.length; i++) {
HSSFCell cell = row0.createCell(i); HSSFCell cell = row0.createCell(i);
HSSFRichTextString text = new HSSFRichTextString(headers[i]); HSSFRichTextString text = new HSSFRichTextString(headers[i]);
cell.setCellValue(text); cell.setCellValue(text);
} }
int rows = 1; int rows = 1;
for (BuyExportDto buyExportDto : exportList){ for (BuyExportDto buyExportDto : exportList) {
HSSFRow row = sheet.createRow(rows); HSSFRow row = sheet.createRow(rows);
row.createCell(0).setCellValue(buyExportDto.getBuyno()); row.createCell(0).setCellValue(buyExportDto.getBuyno());
row.createCell(1).setCellValue(buyExportDto.getSkuTypeName()); row.createCell(1).setCellValue(buyExportDto.getSkuTypeName());
...@@ -473,13 +481,13 @@ public class BuyServiceImpl implements BuyService { ...@@ -473,13 +481,13 @@ public class BuyServiceImpl implements BuyService {
row.createCell(14).setCellValue(buyExportDto.getDepartmentname()); row.createCell(14).setCellValue(buyExportDto.getDepartmentname());
row.createCell(15).setCellValue(sdf.format(buyExportDto.getCreatetime())); row.createCell(15).setCellValue(sdf.format(buyExportDto.getCreatetime()));
row.createCell(16).setCellValue(buyExportDto.getPayTime() != null ? sdf.format(buyExportDto.getPayTime()) : ""); row.createCell(16).setCellValue(buyExportDto.getPayTime() != null ? sdf.format(buyExportDto.getPayTime()) : "");
rows ++; rows++;
} }
// 保存到本地,并且返回路径 // 保存到本地,并且返回路径
String filePath = PathUtil.getBasePath() + PathUtil.getPath("export/temp/") + System.currentTimeMillis() + "&buy.xls"; String filePath = PathUtil.getBasePath() + PathUtil.getPath("export/temp/") + System.currentTimeMillis() + "&buy.xls";
File tempFile = new File(filePath); File tempFile = new File(filePath);
// 创建路径 // 创建路径
if(!tempFile.getParentFile().exists()){ if (!tempFile.getParentFile().exists()) {
tempFile.getParentFile().mkdirs(); tempFile.getParentFile().mkdirs();
} }
FileOutputStream fileOut = null; FileOutputStream fileOut = null;
...@@ -501,15 +509,15 @@ public class BuyServiceImpl implements BuyService { ...@@ -501,15 +509,15 @@ public class BuyServiceImpl implements BuyService {
if (null == linkLendCost.getLendBalance()) linkLendCost.setLendBalance(new BigDecimal(0)); if (null == linkLendCost.getLendBalance()) linkLendCost.setLendBalance(new BigDecimal(0));
BigDecimal subtract = linkLendCost.getAmount().subtract(linkLendCost.getHadPay()); // 关联借支单还需还差额 BigDecimal subtract = linkLendCost.getAmount().subtract(linkLendCost.getHadPay()); // 关联借支单还需还差额
BigDecimal exRate = null; // 采购单币种(现默认CNY)转借支单币种汇率 BigDecimal exRate = null; // 采购单币种(现默认CNY)转借支单币种汇率
if("CNY".equals(linkLendCost.getDic())){ if ("CNY".equals(linkLendCost.getDic())) {
exRate = new BigDecimal("1"); exRate = new BigDecimal("1");
}else{ } else {
exRate = CurUtils.getCur("CNY", linkLendCost.getDic(), getExchangeRateApi); exRate = CurUtils.getCur("CNY", linkLendCost.getDic(), getExchangeRateApi);
} }
BigDecimal counteract = buyListDto.getAmount().multiply(exRate).setScale(2, BigDecimal.ROUND_HALF_UP); // 冲销金额 BigDecimal counteract = buyListDto.getAmount().multiply(exRate).setScale(2, BigDecimal.ROUND_HALF_UP); // 冲销金额
String result = null; String result = null;
if(counteract.compareTo(BigDecimal.ZERO) != 1){ if (counteract.compareTo(BigDecimal.ZERO) != 1) {
result = "采购单金额必须大于0,请修改"; result = "采购单金额必须大于0,请修改";
} /*else if(counteract.compareTo(subtract) == 1){ } /*else if(counteract.compareTo(subtract) == 1){
// 冲销金额>借支单待还金额,不允许关联借支单 // 冲销金额>借支单待还金额,不允许关联借支单
...@@ -525,10 +533,10 @@ public class BuyServiceImpl implements BuyService { ...@@ -525,10 +533,10 @@ public class BuyServiceImpl implements BuyService {
String installmentInfo = buyDomain.getInstallmentInfo(); String installmentInfo = buyDomain.getInstallmentInfo();
List<InstallmentDto> installmentList = null; List<InstallmentDto> installmentList = null;
int periods = 1; // 期数 int periods = 1; // 期数
if(installmentInfo != null){ if (installmentInfo != null) {
installmentList = JSONObject.parseArray(installmentInfo, InstallmentDto.class); installmentList = JSONObject.parseArray(installmentInfo, InstallmentDto.class);
periods = installmentList.size() + 1; periods = installmentList.size() + 1;
}else{ } else {
installmentList = new ArrayList<>(); installmentList = new ArrayList<>();
} }
// 生成子采购单 // 生成子采购单
...@@ -548,21 +556,21 @@ public class BuyServiceImpl implements BuyService { ...@@ -548,21 +556,21 @@ public class BuyServiceImpl implements BuyService {
// 生成子采购单明细 // 生成子采购单明细
List<BuyDetailDomain> subBuyDetails = buyDetailDao.selectByBuyno(buyNo); List<BuyDetailDomain> subBuyDetails = buyDetailDao.selectByBuyno(buyNo);
int detailNum = subBuyDetails.size(); int detailNum = subBuyDetails.size();
if(detailNum > 1){ if (detailNum > 1) {
BigDecimal oneSubBuyDetailAmount = payment.divide(new BigDecimal(detailNum)).setScale(2); // 单个SKU总金额 BigDecimal oneSubBuyDetailAmount = payment.divide(new BigDecimal(detailNum)).setScale(2); // 单个SKU总金额
BigDecimal remainAmount = payment.subtract(oneSubBuyDetailAmount.multiply(new BigDecimal(detailNum - 1))); // 支付额分摊到最后一个SKU的金额 BigDecimal remainAmount = payment.subtract(oneSubBuyDetailAmount.multiply(new BigDecimal(detailNum - 1))); // 支付额分摊到最后一个SKU的金额
for (BuyDetailDomain subBuyDetail : subBuyDetails){ for (BuyDetailDomain subBuyDetail : subBuyDetails) {
subBuyDetail.setId(null); subBuyDetail.setId(null);
subBuyDetail.setBuyno(subBuyNo); subBuyDetail.setBuyno(subBuyNo);
subBuyDetail.setAmount(oneSubBuyDetailAmount); subBuyDetail.setAmount(oneSubBuyDetailAmount);
} }
subBuyDetails.get(detailNum - 1).setAmount(remainAmount); subBuyDetails.get(detailNum - 1).setAmount(remainAmount);
}else{ } else {
subBuyDetails.get(0).setId(null); subBuyDetails.get(0).setId(null);
subBuyDetails.get(0).setBuyno(subBuyNo); subBuyDetails.get(0).setBuyno(subBuyNo);
subBuyDetails.get(0).setAmount(payment); subBuyDetails.get(0).setAmount(payment);
} }
for (BuyDetailDomain subBuyDetail : subBuyDetails){ for (BuyDetailDomain subBuyDetail : subBuyDetails) {
buyDetailDao.insert(subBuyDetail); buyDetailDao.insert(subBuyDetail);
} }
// 更新分期主采购单 // 更新分期主采购单
...@@ -581,7 +589,7 @@ public class BuyServiceImpl implements BuyService { ...@@ -581,7 +589,7 @@ public class BuyServiceImpl implements BuyService {
List<InstallmentDto> installmentList = JSONObject.parseArray(buyDomain.getInstallmentInfo(), InstallmentDto.class); List<InstallmentDto> installmentList = JSONObject.parseArray(buyDomain.getInstallmentInfo(), InstallmentDto.class);
installmentList.get(periods - 1).setPayStatus(1); // 对应分期状态更改为已支付 installmentList.get(periods - 1).setPayStatus(1); // 对应分期状态更改为已支付
BigDecimal hadPayAmount = (buyDomain.getPayamount() == null ? BigDecimal.ZERO : buyDomain.getPayamount()).add(payment); BigDecimal hadPayAmount = (buyDomain.getPayamount() == null ? BigDecimal.ZERO : buyDomain.getPayamount()).add(payment);
if(hadPayAmount.compareTo(buyDomain.getAmount()) == 0){ if (hadPayAmount.compareTo(buyDomain.getAmount()) == 0) {
buyDomain.setBuystatus(4); buyDomain.setBuystatus(4);
} }
buyDomain.setPayamount(hadPayAmount); buyDomain.setPayamount(hadPayAmount);
...@@ -595,11 +603,11 @@ public class BuyServiceImpl implements BuyService { ...@@ -595,11 +603,11 @@ public class BuyServiceImpl implements BuyService {
int periods = Integer.parseInt(buyNoInfo[1]); int periods = Integer.parseInt(buyNoInfo[1]);
BuyDomain buyDomain = buyDao.findByBuyNo(buyNoInfo[0]); BuyDomain buyDomain = buyDao.findByBuyNo(buyNoInfo[0]);
List<InstallmentDto> installmentList = JSONObject.parseArray(buyDomain.getInstallmentInfo(), InstallmentDto.class); List<InstallmentDto> installmentList = JSONObject.parseArray(buyDomain.getInstallmentInfo(), InstallmentDto.class);
if(installmentList.size() == 1){ // 废弃分期的首期子采购单,分期主采购单类型更改为普通采购单 if (installmentList.size() == 1) { // 废弃分期的首期子采购单,分期主采购单类型更改为普通采购单
buyDomain.setInstallmentInfo(null); buyDomain.setInstallmentInfo(null);
buyDomain.setBuyType(1); // 普通采购单 buyDomain.setBuyType(1); // 普通采购单
buyDao.updateInstallment(buyDomain); buyDao.updateInstallment(buyDomain);
}else{ } else {
installmentList.remove(periods - 1); installmentList.remove(periods - 1);
buyDomain.setInstallmentInfo(JSON.toJSONString(installmentList)); buyDomain.setInstallmentInfo(JSON.toJSONString(installmentList));
buyDao.update(buyDomain); buyDao.update(buyDomain);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment