|
|
@@ -24,6 +24,7 @@ import io.seata.spring.annotation.GlobalTransactional;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springblade.core.secure.utils.AuthUtil;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.core.tool.utils.BeanUtil;
|
|
|
import org.springblade.los.basic.business.entity.BusinessType;
|
|
|
import org.springblade.los.basic.business.service.IBusinessTypeService;
|
|
|
import org.springblade.los.basic.cur.service.IBCurrencyService;
|
|
|
@@ -48,6 +49,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.MathContext;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
@@ -133,7 +135,6 @@ public class FinInvoicesServiceImpl extends ServiceImpl<FinInvoicesMapper, FinIn
|
|
|
}
|
|
|
this.saveOrUpdate(finInvoices);
|
|
|
if (ObjectUtils.isNotNull(finInvoices.getFinInvoicesItemsList())) {
|
|
|
-
|
|
|
for (FinInvoicesItems item : finInvoices.getFinInvoicesItemsList()) {
|
|
|
//计算字段null值处理
|
|
|
item.setCurrentAmount(ObjectUtils.isNotNull(item.getCurrentAmount()) ? item.getCurrentAmount() : new BigDecimal("0.00"));
|
|
|
@@ -189,6 +190,33 @@ public class FinInvoicesServiceImpl extends ServiceImpl<FinInvoicesMapper, FinIn
|
|
|
finInvoices.setAmountLoc(amountCny.add(bCurrencyService.converterCny("USD", amountUsd)));
|
|
|
finInvoices.setAmountSub(finInvoices.getAmountLoc());
|
|
|
}
|
|
|
+ BigDecimal invoiceAmount = new BigDecimal("0.00");
|
|
|
+ if (ObjectUtils.isNotNull(finInvoices.getFinInvoiceItemDetailList())) {
|
|
|
+ BigDecimal taxRate = new BigDecimal("1").add(finInvoices.getTaxRate().divide(new BigDecimal("100"), MathContext.DECIMAL32).setScale(2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ for (FinInvoiceItemDetail item : finInvoices.getFinInvoiceItemDetailList()) {
|
|
|
+ item.setPid(finInvoices.getId());
|
|
|
+ if (item.getId() == null) {
|
|
|
+ item.setCreateTime(new Date());
|
|
|
+ item.setCreateUser(AuthUtil.getUserId());
|
|
|
+ item.setCreateUserName(AuthUtil.getUserName());
|
|
|
+ if (ObjectUtils.isNotNull(AuthUtil.getDeptId())) {
|
|
|
+ item.setCreateDept(AuthUtil.getDeptId());
|
|
|
+ item.setCreateDeptName(deptName);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ item.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ item.setUpdateTime(new Date());
|
|
|
+ item.setUpdateUserName(AuthUtil.getUserName());
|
|
|
+ }
|
|
|
+ item.setAmountRate(taxRate);
|
|
|
+ item.setAmountTax(item.getAmount().multiply(taxRate));
|
|
|
+ invoiceAmount = invoiceAmount.add(item.getAmount());
|
|
|
+ }
|
|
|
+ finInvoiceItemDetailService.saveOrUpdateBatch(finInvoices.getFinInvoiceItemDetailList());
|
|
|
+ }
|
|
|
+ if (invoiceAmount.compareTo(finInvoices.getAmountLoc()) > 0) {
|
|
|
+ throw new RuntimeException("开票金额大于合计金额,保存失败");
|
|
|
+ }
|
|
|
this.saveOrUpdate(finInvoices);
|
|
|
return R.data(finInvoices);
|
|
|
}
|
|
|
@@ -229,6 +257,29 @@ public class FinInvoicesServiceImpl extends ServiceImpl<FinInvoicesMapper, FinIn
|
|
|
item.setUpdateUserName(AuthUtil.getUserName());
|
|
|
}
|
|
|
finInvoicesItemsService.saveOrUpdateBatch(finInvoices.getFinInvoicesItemsList());
|
|
|
+ List<Long> ids = finInvoices.getFinInvoicesItemsList().stream().map(FinInvoicesItems::getApplySrcId).collect(Collectors.toList());
|
|
|
+ if (ids.size() > 0) {
|
|
|
+ List<FinInvoicesItems> finInvoicesItemsList = finInvoicesItemsService.list(new LambdaQueryWrapper<FinInvoicesItems>()
|
|
|
+ .eq(FinInvoicesItems::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(FinInvoicesItems::getIsDeleted, 0)
|
|
|
+ .in(FinInvoicesItems::getId, ids));
|
|
|
+ for (FinInvoicesItems item : finInvoicesItemsList) {
|
|
|
+ item.setGenerateInvoices("1");
|
|
|
+ }
|
|
|
+ if (finInvoicesItemsList.size() > 0) {
|
|
|
+ FinInvoices finInvoices1 = baseMapper.selectById(finInvoicesItemsList.get(0).getPid());
|
|
|
+ List<FinInvoicesItems> finInvoicesItemsList1 = finInvoicesItemsService.list(new LambdaQueryWrapper<FinInvoicesItems>()
|
|
|
+ .eq(FinInvoicesItems::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(FinInvoicesItems::getIsDeleted, 0)
|
|
|
+ .eq(FinInvoicesItems::getGenerateInvoices, "0")
|
|
|
+ .eq(FinInvoicesItems::getPid, finInvoices1.getId()));
|
|
|
+ if (finInvoicesItemsList.size() == finInvoicesItemsList1.size()) {
|
|
|
+ finInvoices1.setBillStatus("1");
|
|
|
+ baseMapper.updateById(finInvoices1);
|
|
|
+ }
|
|
|
+ finInvoicesItemsService.saveOrUpdateBatch(finInvoicesItemsList);
|
|
|
+ }
|
|
|
+ }
|
|
|
//通过明细里账单id查询具体账单数据
|
|
|
List<Long> accIds = finInvoices.getFinInvoicesItemsList().stream().map(FinInvoicesItems::getAccBillId)
|
|
|
.filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
@@ -253,50 +304,9 @@ public class FinInvoicesServiceImpl extends ServiceImpl<FinInvoicesMapper, FinIn
|
|
|
.eq(FeeCenter::getIsDeleted, 0));
|
|
|
List<FeeCenter> feeCenterListNew = reconciliationFeeCenter(detail, feeCenterList, 1);
|
|
|
feeCenterService.saveOrUpdateBatch(feeCenterListNew);
|
|
|
- /*List<Bills> billsList = new ArrayList<>();
|
|
|
- List<Long> ids = feeCenterListNew.stream().map(FeeCenter::getPid).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
- BigDecimal idsD = feeCenterListNew.stream().filter(e -> "D".equals(e.getDc())).map(FeeCenter::getUninvoicedAmount).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- BigDecimal idsC = feeCenterListNew.stream().filter(e -> "C".equals(e.getDc())).map(FeeCenter::getUninvoicedAmount).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- List<Long> divideIds = feeCenterListNew.stream().map(FeeCenter::getPid).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
- BigDecimal divideIdsD = feeCenterListNew.stream().filter(e -> "D".equals(e.getDc())).map(FeeCenter::getUninvoicedAmount).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- BigDecimal divideIdsC = feeCenterListNew.stream().filter(e -> "C".equals(e.getDc())).map(FeeCenter::getUninvoicedAmount).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- if (ObjectUtils.isNotNull(ids) && ids.size() > 0) {
|
|
|
- billsList = billsMapper.selectList(new LambdaQueryWrapper<Bills>()
|
|
|
- .eq(Bills::getTenantId, AuthUtil.getTenantId())
|
|
|
- .eq(Bills::getIsDeleted, 0)
|
|
|
- .in(Bills::getId, ids));
|
|
|
- }
|
|
|
- if (ObjectUtils.isNotNull(divideIds) && divideIds.size() > 0) {
|
|
|
- List<Bills> divideBillsList = billsMapper.selectList(new LambdaQueryWrapper<Bills>()
|
|
|
- .eq(Bills::getTenantId, AuthUtil.getTenantId())
|
|
|
- .eq(Bills::getIsDeleted, 0)
|
|
|
- .in(Bills::getId, divideIds));
|
|
|
- billsList.addAll(divideBillsList);
|
|
|
- }
|
|
|
- for (Bills item : billsList) {
|
|
|
- item.setBillingStatus(item.getBillingStatus() + 1);
|
|
|
- BigDecimal countD = finAccBillsService.list(new LambdaQueryWrapper<FinAccBills>()
|
|
|
- .eq(FinAccBills::getBusinessBillId, item.getId())
|
|
|
- .eq(FinAccBills::getTenantId, AuthUtil.getTenantId())
|
|
|
- .eq(FinAccBills::getIsDeleted, 0)
|
|
|
- .eq(FinAccBills::getAccountDc, "D")).stream()
|
|
|
- .map(FinAccBills::getAmountDrLoc).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- BigDecimal countC = finAccBillsService.list(new LambdaQueryWrapper<FinAccBills>()
|
|
|
- .eq(FinAccBills::getBusinessBillId, item.getId())
|
|
|
- .eq(FinAccBills::getTenantId, AuthUtil.getTenantId())
|
|
|
- .eq(FinAccBills::getIsDeleted, 0)
|
|
|
- .eq(FinAccBills::getAccountDc, "C")).stream()
|
|
|
- .map(FinAccBills::getAmountDrLoc).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- if (item.getCheckDrStatus() != 9) {
|
|
|
- Bills bills = reconciliation(item, countD, divideIdsD, countC, divideIdsC, idsD, idsC, detail.getType());
|
|
|
- billsMapper.updateById(bills);
|
|
|
- } else {
|
|
|
- billsMapper.updateById(item);
|
|
|
- }
|
|
|
- }*/
|
|
|
finAccBillsService.saveOrUpdateBatch(finAccBillsList);
|
|
|
}
|
|
|
- detail.setStatus(1);
|
|
|
+ detail.setStatus(3);
|
|
|
baseMapper.updateById(detail);
|
|
|
return R.data(detail);
|
|
|
}
|
|
|
@@ -381,9 +391,9 @@ public class FinInvoicesServiceImpl extends ServiceImpl<FinInvoicesMapper, FinIn
|
|
|
item.setInvoiceById(detail.getCreateUser());
|
|
|
item.setInvoiceByName(detail.getCreateUserName());
|
|
|
} else if (count == 3) {
|
|
|
- item.setAppliedAmount(item.getAppliedAmount().add(detail.getAmountLoc()));
|
|
|
+ item.setAppliedInvoiceAmount(item.getAppliedInvoiceAmount().add(detail.getAmountLoc()));
|
|
|
} else if (count == 4) {
|
|
|
- item.setAppliedAmount(item.getAppliedAmount().subtract(detail.getAmountLoc()));
|
|
|
+ item.setAppliedInvoiceAmount(item.getAppliedInvoiceAmount().subtract(detail.getAmountLoc()));
|
|
|
}
|
|
|
}
|
|
|
return feeCenterList;
|
|
|
@@ -405,6 +415,22 @@ public class FinInvoicesServiceImpl extends ServiceImpl<FinInvoicesMapper, FinIn
|
|
|
item.setUpdateUserName(AuthUtil.getUserName());
|
|
|
}
|
|
|
finInvoicesItemsService.saveOrUpdateBatch(finInvoices.getFinInvoicesItemsList());
|
|
|
+ List<Long> ids = finInvoices.getFinInvoicesItemsList().stream().map(FinInvoicesItems::getApplySrcId).collect(Collectors.toList());
|
|
|
+ if (ids.size() > 0) {
|
|
|
+ List<FinInvoicesItems> finInvoicesItemsList = finInvoicesItemsService.list(new LambdaQueryWrapper<FinInvoicesItems>()
|
|
|
+ .eq(FinInvoicesItems::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(FinInvoicesItems::getIsDeleted, 0)
|
|
|
+ .in(FinInvoicesItems::getId, ids));
|
|
|
+ for (FinInvoicesItems item : finInvoicesItemsList) {
|
|
|
+ item.setGenerateInvoices("0");
|
|
|
+ }
|
|
|
+ if (finInvoicesItemsList.size() > 0) {
|
|
|
+ FinInvoices finInvoices1 = baseMapper.selectById(finInvoicesItemsList.get(0).getPid());
|
|
|
+ finInvoices1.setBillStatus("0");
|
|
|
+ baseMapper.updateById(finInvoices1);
|
|
|
+ finInvoicesItemsService.saveOrUpdateBatch(finInvoicesItemsList);
|
|
|
+ }
|
|
|
+ }
|
|
|
List<Long> accIds = finInvoices.getFinInvoicesItemsList().stream().map(FinInvoicesItems::getAccBillId)
|
|
|
.filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
List<FinAccBills> finAccBillsList = finAccBillsService.list(new LambdaQueryWrapper<FinAccBills>()
|
|
|
@@ -428,49 +454,8 @@ public class FinInvoicesServiceImpl extends ServiceImpl<FinInvoicesMapper, FinIn
|
|
|
List<FeeCenter> feeCenterListNew = reconciliationFeeCenter(detail, feeCenterList, 2);
|
|
|
feeCenterService.saveOrUpdateBatch(feeCenterListNew);
|
|
|
finAccBillsService.saveOrUpdateBatch(finAccBillsList);
|
|
|
- /*List<Bills> billsList = new ArrayList<>();
|
|
|
- List<Long> ids = feeCenterListNew.stream().map(FeeCenter::getPid).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
- BigDecimal idsD = feeCenterListNew.stream().filter(e -> "D".equals(e.getDc())).map(FeeCenter::getInvoiceAmountLoc).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- BigDecimal idsC = feeCenterListNew.stream().filter(e -> "C".equals(e.getDc())).map(FeeCenter::getInvoiceAmountLoc).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- List<Long> divideIds = feeCenterListNew.stream().map(FeeCenter::getPid).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
- BigDecimal divideIdsD = feeCenterListNew.stream().filter(e -> "D".equals(e.getDc())).map(FeeCenter::getInvoiceAmountLoc).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- BigDecimal divideIdsC = feeCenterListNew.stream().filter(e -> "C".equals(e.getDc())).map(FeeCenter::getInvoiceAmountLoc).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
-
|
|
|
- if (ObjectUtils.isNotNull(ids) && ids.size() > 0) {
|
|
|
- billsList = billsMapper.selectList(new LambdaQueryWrapper<Bills>()
|
|
|
- .eq(Bills::getTenantId, AuthUtil.getTenantId())
|
|
|
- .eq(Bills::getIsDeleted, 0)
|
|
|
- .in(Bills::getId, ids));
|
|
|
- }
|
|
|
- if (ObjectUtils.isNotNull(divideIds) && divideIds.size() > 0) {
|
|
|
- List<Bills> divideBillsList = billsMapper.selectList(new LambdaQueryWrapper<Bills>()
|
|
|
- .eq(Bills::getTenantId, AuthUtil.getTenantId())
|
|
|
- .eq(Bills::getIsDeleted, 0)
|
|
|
- .in(Bills::getId, divideIds));
|
|
|
- billsList.addAll(divideBillsList);
|
|
|
- }
|
|
|
- for (Bills item : billsList) {
|
|
|
- if (item.getBillingStatus() == 0) {
|
|
|
- throw new RuntimeException("撤销对账失败");
|
|
|
- }
|
|
|
- item.setBillingStatus(item.getBillingStatus() - 1);
|
|
|
- BigDecimal countD = finAccBillsService.list(new LambdaQueryWrapper<FinAccBills>()
|
|
|
- .eq(FinAccBills::getBusinessBillId, item.getId())
|
|
|
- .eq(FinAccBills::getTenantId, AuthUtil.getTenantId())
|
|
|
- .eq(FinAccBills::getIsDeleted, 0)
|
|
|
- .eq(FinAccBills::getAccountDc, "D")).stream()
|
|
|
- .map(FinAccBills::getAmountDrLoc).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- BigDecimal countC = finAccBillsService.list(new LambdaQueryWrapper<FinAccBills>()
|
|
|
- .eq(FinAccBills::getBusinessBillId, item.getId())
|
|
|
- .eq(FinAccBills::getTenantId, AuthUtil.getTenantId())
|
|
|
- .eq(FinAccBills::getIsDeleted, 0)
|
|
|
- .eq(FinAccBills::getAccountDc, "C")).stream()
|
|
|
- .map(FinAccBills::getAmountDrLoc).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- Bills bills = reconciliation(item, countD, divideIdsD, countC, divideIdsC, idsD, idsC, detail.getType());
|
|
|
- billsMapper.updateById(bills);
|
|
|
- }*/
|
|
|
}
|
|
|
- detail.setStatus(2);
|
|
|
+ detail.setStatus(0);
|
|
|
baseMapper.updateById(detail);
|
|
|
return R.data(detail);
|
|
|
}
|
|
|
@@ -483,69 +468,6 @@ public class FinInvoicesServiceImpl extends ServiceImpl<FinInvoicesMapper, FinIn
|
|
|
throw new RuntimeException("缺少必要参数");
|
|
|
}
|
|
|
FinInvoices detail = baseMapper.selectById(finInvoices.getId());
|
|
|
- /*if (ObjectUtils.isNotNull(finInvoices.getFinInvoicesItemsList())) {
|
|
|
- //审批数据
|
|
|
- LosAuditProecessDTO auditProecessDTO = new LosAuditProecessDTO();
|
|
|
- //获取审批级次
|
|
|
- List<LosAuditPathsLevels> auditPathsLevels;
|
|
|
- // 判断是否有审批流,如果审批流已开启就进入审批流,否则直接走申请通过
|
|
|
- LosAuditPathsActs pathsActs;
|
|
|
- //是否开启流程
|
|
|
- LambdaQueryWrapper<LosAuditPathsActs> auditPathsActsLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
- auditPathsActsLambdaQueryWrapper
|
|
|
- .eq(LosAuditPathsActs::getIsEnable, 1)
|
|
|
- .eq(LosAuditPathsActs::getFidStatus, "status")
|
|
|
- .eq(LosAuditPathsActs::getTenantId, AuthUtil.getTenantId())
|
|
|
- .eq(LosAuditPathsActs::getSalesCompanyId, AuthUtil.getDeptId())
|
|
|
- .eq(LosAuditPathsActs::getActId, 1110);
|
|
|
- pathsActs = auditPathsActsService.getOne(auditPathsActsLambdaQueryWrapper);
|
|
|
- //获取审批信息
|
|
|
- LosAuditPathsActs losAuditPathsActs = auditPathsActsService.getOne(new LambdaQueryWrapper<LosAuditPathsActs>()
|
|
|
- .eq(LosAuditPathsActs::getActId, 1110)
|
|
|
- .eq(LosAuditPathsActs::getFidStatus, "status")
|
|
|
- .eq(LosAuditPathsActs::getSalesCompanyId, AuthUtil.getDeptId())
|
|
|
- .eq(LosAuditPathsActs::getTenantId, AuthUtil.getTenantId()));
|
|
|
- Long pathId = losAuditPathsActs.getPathId();
|
|
|
- auditPathsLevels = auditPathsLevelsService.list(new LambdaQueryWrapper<LosAuditPathsLevels>()
|
|
|
- .eq(LosAuditPathsLevels::getTenantId, AuthUtil.getTenantId()).eq(LosAuditPathsLevels::getPathId, pathId));
|
|
|
- auditProecessDTO.setTimes(1);
|
|
|
- auditProecessDTO.setProcessType("发票申请");
|
|
|
-
|
|
|
- // 没开启审批流直接走 通过流程
|
|
|
- if (pathsActs == null || pathsActs.getIsEnable() == 2) {
|
|
|
- throw new SecurityException("当前租户未查询到审批流配置");
|
|
|
- } else {
|
|
|
-
|
|
|
- if (CollectionUtils.isEmpty(auditPathsLevels)) {
|
|
|
- throw new SecurityException("开启审批失败:未查询到审批信息");
|
|
|
- }
|
|
|
- // 绑定审核类型
|
|
|
- auditProecessDTO.setCheckType("HYCK-FPSQ");
|
|
|
- // 追加跳转路由url
|
|
|
- auditProecessDTO.setUrl(finInvoices.getUrl());
|
|
|
- auditProecessDTO.setPageStatus(finInvoices.getPageStatus());
|
|
|
- auditProecessDTO.setPageLabel(finInvoices.getPageLabel());
|
|
|
- auditProecessDTO.setOrderRemark(detail.getRemarks());
|
|
|
- auditProecessDTO.setPathsLevelsList(auditPathsLevels);
|
|
|
- auditProecessDTO.setActId(1);
|
|
|
- auditProecessDTO.setSrcBillId(detail.getId());
|
|
|
- auditProecessDTO.setBillId(detail.getId());
|
|
|
- auditProecessDTO.setBillNo(detail.getBillNo());
|
|
|
- auditProecessDTO.setSendUserId(AuthUtil.getUserId());
|
|
|
- auditProecessDTO.setSendName(AuthUtil.getUserName());
|
|
|
- auditProecessDTO.setSendTime(new Date());
|
|
|
- auditProecessDTO.setBillTime(detail.getCreateTime());
|
|
|
- auditProecessDTO.setTenantId(AuthUtil.getTenantId());
|
|
|
- auditProecessDTO.setCorpId(detail.getCorpId());
|
|
|
- auditProecessDTO.setSalesCompanyId(Long.parseLong(detail.getCreateDept()));
|
|
|
- auditProecessDTO.setSalesCompanyName(detail.getCreateDeptName());
|
|
|
- R financeProcess = auditProecessService.createFinanceProcess(auditProecessDTO);
|
|
|
- if (!financeProcess.isSuccess()) {
|
|
|
- throw new SecurityException("操作失败,请联系管理员");
|
|
|
- }
|
|
|
- }
|
|
|
- detail.setStatus(1);
|
|
|
- }*/
|
|
|
List<FeeCenter> feeCenterList = new ArrayList<>();
|
|
|
if (ObjectUtils.isNotNull(finInvoices.getFinInvoicesItemsList())) {
|
|
|
for (FinInvoicesItems item : finInvoices.getFinInvoicesItemsList()) {
|
|
|
@@ -559,7 +481,7 @@ public class FinInvoicesServiceImpl extends ServiceImpl<FinInvoicesMapper, FinIn
|
|
|
.eq(FeeCenter::getIsDeleted, 0)
|
|
|
.eq(FeeCenter::getAccBillId, finAccBills.getId())
|
|
|
.eq(FeeCenter::getAccStatus, 1)
|
|
|
- .apply("amount != stl_ttl_amount + applied_amount")
|
|
|
+ .apply("amount > applied_invoice_amount")
|
|
|
.orderByDesc(FeeCenter::getCreateTime));
|
|
|
BigDecimal currentStlAmount = item.getCurrentAmount();
|
|
|
for (FeeCenter e : feeCenters) {
|
|
|
@@ -568,15 +490,14 @@ public class FinInvoicesServiceImpl extends ServiceImpl<FinInvoicesMapper, FinIn
|
|
|
} else {
|
|
|
//计算字段null值处理
|
|
|
e.setAmount(ObjectUtils.isNotNull(e.getAmount()) ? e.getAmount() : new BigDecimal("0.00"));
|
|
|
- e.setStlTtlAmount(ObjectUtils.isNotNull(e.getStlTtlAmount()) ? e.getStlTtlAmount() : new BigDecimal("0.00"));
|
|
|
- if (e.getAmount().subtract(e.getAppliedAmount()).subtract(e.getStlTtlAmount()).compareTo(currentStlAmount) > 0) {
|
|
|
- e.setAppliedAmount(e.getAppliedAmount().add(currentStlAmount));
|
|
|
+ if (e.getAmount().subtract(e.getAppliedInvoiceAmount()).compareTo(currentStlAmount) > 0) {
|
|
|
+ e.setAppliedInvoiceAmount(e.getAppliedInvoiceAmount().add(currentStlAmount));
|
|
|
currentStlAmount = new BigDecimal("0.00");
|
|
|
- } else if (e.getAmount().subtract(e.getAppliedAmount()).subtract(e.getStlTtlAmount()).compareTo(currentStlAmount) == 0) {
|
|
|
- e.setAppliedAmount(e.getAppliedAmount().add(currentStlAmount));
|
|
|
+ } else if (e.getAmount().subtract(e.getAppliedInvoiceAmount()).compareTo(currentStlAmount) == 0) {
|
|
|
+ e.setAppliedInvoiceAmount(e.getAppliedInvoiceAmount().add(currentStlAmount));
|
|
|
currentStlAmount = new BigDecimal("0.00");
|
|
|
} else {
|
|
|
- e.setAppliedAmount(e.getAmount());
|
|
|
+ e.setAppliedInvoiceAmount(e.getAmount());
|
|
|
currentStlAmount = currentStlAmount.subtract(e.getAmount());
|
|
|
}
|
|
|
feeCenterList.add(e);
|
|
|
@@ -601,19 +522,12 @@ public class FinInvoicesServiceImpl extends ServiceImpl<FinInvoicesMapper, FinIn
|
|
|
throw new RuntimeException("缺少必要参数");
|
|
|
}
|
|
|
FinInvoices detail = baseMapper.selectById(finInvoices.getId());
|
|
|
- /* if (ObjectUtils.isNotNull(finInvoices.getFinInvoicesItemsList())) {
|
|
|
- if (detail.getStatus() > 1) {
|
|
|
- throw new RuntimeException("正在审核中,撤销失败");
|
|
|
- }
|
|
|
- R financeProcess = auditProecessService.deteleByBillId(detail.getId());
|
|
|
- if (!financeProcess.isSuccess()) {
|
|
|
- throw new SecurityException("操作失败,请联系管理员");
|
|
|
- }
|
|
|
- detail.setStatus(0);
|
|
|
- }*/
|
|
|
List<FeeCenter> feeCenterList = new ArrayList<>();
|
|
|
if (ObjectUtils.isNotNull(finInvoices.getFinInvoicesItemsList())) {
|
|
|
for (FinInvoicesItems item : finInvoices.getFinInvoicesItemsList()) {
|
|
|
+ if ("1".equals(item.getGenerateInvoices())) {
|
|
|
+ throw new RuntimeException("已开发票,撤销失败");
|
|
|
+ }
|
|
|
FinAccBills finAccBills = finAccBillsService.getById(item.getAccBillId());
|
|
|
if (finAccBills == null) {
|
|
|
throw new RuntimeException("未找到账单明细,操作失败");
|
|
|
@@ -624,7 +538,7 @@ public class FinInvoicesServiceImpl extends ServiceImpl<FinInvoicesMapper, FinIn
|
|
|
.eq(FeeCenter::getIsDeleted, 0)
|
|
|
.eq(FeeCenter::getAccBillId, finAccBills.getId())
|
|
|
.eq(FeeCenter::getAccStatus, 1)
|
|
|
- .apply("applied_amount != 0")
|
|
|
+ .apply("applied_invoice_amount != 0")
|
|
|
.orderByDesc(FeeCenter::getCreateTime));
|
|
|
BigDecimal currentStlAmount = item.getCurrentAmount();
|
|
|
for (FeeCenter e : feeCenters) {
|
|
|
@@ -633,16 +547,14 @@ public class FinInvoicesServiceImpl extends ServiceImpl<FinInvoicesMapper, FinIn
|
|
|
} else {
|
|
|
//计算字段null值处理
|
|
|
e.setAmount(ObjectUtils.isNotNull(e.getAmount()) ? e.getAmount() : new BigDecimal("0.00"));
|
|
|
- e.setUnsettledAmount(ObjectUtils.isNotNull(e.getUnsettledAmount()) ? e.getUnsettledAmount() : new BigDecimal("0.00"));
|
|
|
- e.setStlTtlAmount(ObjectUtils.isNotNull(e.getStlTtlAmount()) ? e.getStlTtlAmount() : new BigDecimal("0.00"));
|
|
|
- if (e.getAppliedAmount().compareTo(currentStlAmount) > 0) {
|
|
|
- e.setAppliedAmount(e.getAppliedAmount().subtract(currentStlAmount));
|
|
|
+ if (e.getAppliedInvoiceAmount().compareTo(currentStlAmount) > 0) {
|
|
|
+ e.setAppliedInvoiceAmount(e.getAppliedInvoiceAmount().subtract(currentStlAmount));
|
|
|
currentStlAmount = new BigDecimal("0.00");
|
|
|
- } else if (e.getAppliedAmount().compareTo(currentStlAmount) == 0) {
|
|
|
- e.setAppliedAmount(e.getAppliedAmount().subtract(currentStlAmount));
|
|
|
+ } else if (e.getAppliedInvoiceAmount().compareTo(currentStlAmount) == 0) {
|
|
|
+ e.setAppliedInvoiceAmount(e.getAppliedInvoiceAmount().subtract(currentStlAmount));
|
|
|
currentStlAmount = new BigDecimal("0.00");
|
|
|
} else {
|
|
|
- e.setAppliedAmount(new BigDecimal("0.00"));
|
|
|
+ e.setAppliedInvoiceAmount(new BigDecimal("0.00"));
|
|
|
currentStlAmount = currentStlAmount.subtract(e.getAmount());
|
|
|
}
|
|
|
feeCenterList.add(e);
|
|
|
@@ -727,10 +639,10 @@ public class FinInvoicesServiceImpl extends ServiceImpl<FinInvoicesMapper, FinIn
|
|
|
finInvoiceItemDetail.setTenantId(AuthUtil.getTenantId());
|
|
|
finInvoiceItemDetail.setPid(finInvoices.getId());
|
|
|
finInvoiceItemDetail.setNumber(new BigDecimal("1"));
|
|
|
- BigDecimal amount = finInvoices.getFinInvoicesItemsList().stream().map(FinInvoicesItems::getCurrentAmountLoc).filter(Objects::nonNull)
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- finInvoiceItemDetail.setAmount(amount);
|
|
|
- finInvoiceItemDetail.setPrice(amount);
|
|
|
+ finInvoiceItemDetail.setAmountRate(finInvoices.getTaxRate());
|
|
|
+ finInvoiceItemDetail.setUnit("票");
|
|
|
+ finInvoiceItemDetail.setServerName(finInvoices.getServerName());
|
|
|
+ BigDecimal amount = new BigDecimal("0.00");
|
|
|
StringBuilder srcIds = new StringBuilder();
|
|
|
for (FinInvoicesItems item : finInvoices.getFinInvoicesItemsList()) {
|
|
|
srcIds.append(item.getId()).append(",");
|
|
|
@@ -738,7 +650,16 @@ public class FinInvoicesServiceImpl extends ServiceImpl<FinInvoicesMapper, FinIn
|
|
|
item.setUpdateTime(new Date());
|
|
|
item.setUpdateUser(AuthUtil.getUserId());
|
|
|
item.setUpdateUserName(AuthUtil.getUserName());
|
|
|
+ if ("USD".equals(item.getCurCode())) {
|
|
|
+ amount = amount.add(item.getAmount().multiply(finInvoices.getExrate()));
|
|
|
+ } else {
|
|
|
+ amount = amount.add(item.getAmount());
|
|
|
+ }
|
|
|
}
|
|
|
+ finInvoiceItemDetail.setAmount(amount);
|
|
|
+ finInvoiceItemDetail.setPrice(amount);
|
|
|
+ BigDecimal taxRate = new BigDecimal("1").add(finInvoices.getTaxRate().divide(new BigDecimal("100"), MathContext.DECIMAL32).setScale(2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ finInvoiceItemDetail.setAmountTax(amount.multiply(taxRate));
|
|
|
if (srcIds.length() > 0) {
|
|
|
finInvoiceItemDetail.setSrcId(srcIds.substring(0, srcIds.length() - 1));
|
|
|
}
|
|
|
@@ -766,4 +687,58 @@ public class FinInvoicesServiceImpl extends ServiceImpl<FinInvoicesMapper, FinIn
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public R generateFinInvoices(String billId) {
|
|
|
+ if (ObjectUtils.isNull(billId)) {
|
|
|
+ throw new RuntimeException("缺少必要参数");
|
|
|
+ }
|
|
|
+ List<FinInvoicesItems> finStlBillsItemsList = new ArrayList<>();
|
|
|
+ List<FinInvoiceItemDetail> finInvoiceItemDetailList = new ArrayList<>();
|
|
|
+ FinInvoices finInvoices = new FinInvoices();
|
|
|
+ finInvoices.setType("销项");
|
|
|
+ finInvoices.setBillDate(new Date());
|
|
|
+ List<FinInvoicesItems> finInvoicesItems = finInvoicesItemsService.list(new LambdaQueryWrapper<FinInvoicesItems>()
|
|
|
+ .eq(FinInvoicesItems::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(FinInvoicesItems::getIsDeleted, 0)
|
|
|
+ .eq(FinInvoicesItems::getGenerateInvoices, "0")
|
|
|
+ .apply("find_in_set(pid,'" + billId + "')"));
|
|
|
+ if (finInvoicesItems.size() > 0) {
|
|
|
+ List<Long> ids = finInvoicesItems.stream().map(FinInvoicesItems::getPid).distinct().collect(Collectors.toList());
|
|
|
+ if (ids.size() > 0) {
|
|
|
+ List<FinInvoices> finInvoicesList = baseMapper.selectList(new LambdaQueryWrapper<FinInvoices>()
|
|
|
+ .eq(FinInvoices::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(FinInvoices::getIsDeleted, 0)
|
|
|
+ .in(FinInvoices::getId, ids));
|
|
|
+ finInvoices.setApplyNo(finInvoicesList.stream().map(FinInvoices::getBillNo).distinct().collect(Collectors.joining(",")));
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("数据错误");
|
|
|
+ }
|
|
|
+ finInvoices.setCorpId(finInvoicesItems.get(0).getCorpId());
|
|
|
+ finInvoices.setCorpCnName(finInvoicesItems.get(0).getCorpCnName());
|
|
|
+ finInvoices.setCorpEnName(finInvoicesItems.get(0).getCorpEnName());
|
|
|
+ for (FinInvoicesItems item : finInvoicesItems) {
|
|
|
+ FinInvoicesItems detail = new FinInvoicesItems();
|
|
|
+ BeanUtil.copyProperties(item, detail);
|
|
|
+ detail.setId(null);
|
|
|
+ detail.setApplySrcId(item.getId());
|
|
|
+ finStlBillsItemsList.add(detail);
|
|
|
+ }
|
|
|
+ finInvoices.setFinInvoicesItemsList(finStlBillsItemsList);
|
|
|
+ }
|
|
|
+ List<FinInvoiceItemDetail> finInvoiceItemDetails = finInvoiceItemDetailService.list(new LambdaQueryWrapper<FinInvoiceItemDetail>()
|
|
|
+ .eq(FinInvoiceItemDetail::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(FinInvoiceItemDetail::getIsDeleted, 0)
|
|
|
+ .apply("find_in_set(pid,'" + billId + "')"));
|
|
|
+ if (finInvoiceItemDetails.size() > 0) {
|
|
|
+ for (FinInvoiceItemDetail item : finInvoiceItemDetails) {
|
|
|
+ FinInvoiceItemDetail detail = new FinInvoiceItemDetail();
|
|
|
+ BeanUtil.copyProperties(item, detail);
|
|
|
+ detail.setId(null);
|
|
|
+ finInvoiceItemDetailList.add(detail);
|
|
|
+ }
|
|
|
+ finInvoices.setFinInvoiceItemDetailList(finInvoiceItemDetailList);
|
|
|
+ }
|
|
|
+ return R.data(finInvoices);
|
|
|
+ }
|
|
|
+
|
|
|
}
|