Commit bdf1b53e by huluobin

fix

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