Quellcode durchsuchen

君海:1.增加确认开票接口
2.增加撤销开票接口
3.增加开票明细获取数据明细
4.增加开票报表打印接口

纪新园 vor 7 Monaten
Ursprung
Commit
87f906d348

+ 12 - 0
blade-service-api/blade-los-api/src/main/java/org/springblade/los/trade/entity/AgentItems.java

@@ -302,5 +302,17 @@ public class AgentItems implements Serializable {
 	@ApiModelProperty(value = "操作员")
 	private String operatorName;
 
+	/**
+	 * 规格
+	 */
+	@ApiModelProperty(value = "规格")
+	private String specifications;
+
+	/**
+	 * 已开发票金额
+	 */
+	@ApiModelProperty(value = "已开发票金额")
+	private BigDecimal invoiceAmount;
+
 
 }

+ 66 - 0
blade-service-api/blade-los-api/src/main/java/org/springblade/los/trade/entity/Invoicing.java

@@ -178,5 +178,71 @@ public class Invoicing implements Serializable {
 	@TableField(exist = false)
 	private String businessTypeCode;
 
+	/**
+	 * 数量
+	 */
+	@TableField(exist = false)
+	private BigDecimal totalNumber;
+
+	/**
+	 * 金额
+	 */
+	@TableField(exist = false)
+	private BigDecimal amount;
+
+	/**
+	 * 金额
+	 */
+	@TableField(exist = false)
+	private BigDecimal amountUsd;
+
+	/**
+	 * 其他费用
+	 */
+	@TableField(exist = false)
+	private BigDecimal otherAmount;
+
+	/**
+	 * 增值税
+	 */
+	@TableField(exist = false)
+	private BigDecimal valueAddedTax;
+
+	/**
+	 * 关税
+	 */
+	@TableField(exist = false)
+	private BigDecimal tariff;
+
+	/**
+	 * 滞纳金
+	 */
+	@TableField(exist = false)
+	private BigDecimal lateFee;
+
+	/**
+	 * 滞纳金
+	 */
+	@TableField(exist = false)
+	private BigDecimal amountTotal;
+
+	/**
+	 * 进口时间
+	 */
+	@TableField(exist = false)
+	private Date eta;
+
+	/**
+	 * 收款时间
+	 */
+	@TableField(exist = false)
+	private Date receivePaymentDate;
+
+	/**
+	 * 付汇时间
+	 */
+	@TableField(exist = false)
+	private Date payConvergeDate;
+
 
 }

+ 2 - 0
blade-service-api/blade-los-api/src/main/java/org/springblade/los/trade/entity/InvoicingItem.java

@@ -128,6 +128,8 @@ public class InvoicingItem implements Serializable {
 	private String specifications;
 	@ApiModelProperty(value = "租户")
 	private String tenantId;
+	@ApiModelProperty(value = "来源明细id")
+	private Long srcId;
 
 
 }

+ 2 - 0
blade-service/blade-los/src/main/java/org/springblade/los/Util/MagicValues.java

@@ -17,6 +17,7 @@ public class MagicValues {
 	public static final String RECONCILIATION_CENTER = "对账中心";
 	public static final String RECONCILIATION_SUMMARY = "对账汇总";
 	public static final String INVOICE_APPLICATION = "发票申请";
+	public static final String INVOICING_APPLICATION = "开票申请";
 	public static final String CHARGE_PAID_OFFSET = "收付相抵";
 	public static final String CHARGE_SETTLEMENT = "收费结算";
 	public static final String CHARGE = "收费";
@@ -49,6 +50,7 @@ public class MagicValues {
 	public static final String MYDL = "MYDL";
 
 	public static final String MYDL_STL = "MYDL-STL";
+	public static final String MYDL_KPSQ = "MYDL_KPSQ";
 	public static final String AMEND = "AMEND";
 	public static final String AMEND_SI = "AMENDSI";
 	public static final String AMEND_SE = "AMENDSE";

+ 2 - 2
blade-service/blade-los/src/main/java/org/springblade/los/finance/invoices/service/impl/FinInvoicesServiceImpl.java

@@ -990,9 +990,9 @@ public class FinInvoicesServiceImpl extends ServiceImpl<FinInvoicesMapper, FinIn
 				invoiceAmount = invoiceAmount.add(item.getAmount());
 			}
 		}
-		if (invoiceAmount.compareTo(finInvoices.getAmountLoc()) > 0) {
+		/*if (invoiceAmount.compareTo(finInvoices.getAmountLoc()) > 0) {
 			throw new RuntimeException("开票金额为负数,保存失败");
-		}
+		}*/
 		detail.setStatus(3);
 		baseMapper.updateById(detail);
 		return R.data(detail);

+ 22 - 1
blade-service/blade-los/src/main/java/org/springblade/los/trade/controller/AgentController.java

@@ -41,6 +41,7 @@ import org.springblade.los.trade.vo.AgentVO;
 import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -405,7 +406,7 @@ public class AgentController extends BladeController {
 								@RequestParam(value = "curCode", required = false) String curCode,
 								@RequestParam(value = "type", required = false) String type
 	) {
-		return agentService.getReportDataTrade(billId, reportCode, groupCode, corpIds, itemIds, type,curCode);
+		return agentService.getReportDataTrade(billId, reportCode, groupCode, corpIds, itemIds, type, curCode);
 	}
 
 	/**
@@ -426,4 +427,24 @@ public class AgentController extends BladeController {
 		return agentService.revokePaidAlready(agent);
 	}
 
+	/**
+	 * 分页 贸易代理明细表
+	 */
+	@GetMapping("/listAll")
+	public R<List<AgentItems>> listAll(@RequestParam("corpId") Long corpId, @RequestParam("contractNo") String contractNo) {
+		Agent agent = agentService.getOne(new LambdaQueryWrapper<Agent>()
+			.eq(Agent::getTenantId, AuthUtil.getTenantId())
+			.eq(Agent::getIsDeleted, 0)
+			.eq(Agent::getCorpId, corpId)
+			.eq(Agent::getContractNo, contractNo));
+		if (agent == null) {
+			throw new RuntimeException("未查到数据");
+		}
+		List<AgentItems> agentItemsList = agentItemsService.list(new LambdaQueryWrapper<AgentItems>()
+			.eq(AgentItems::getTenantId, AuthUtil.getTenantId())
+			.eq(AgentItems::getIsDeleted, 0)
+			.eq(AgentItems::getPid, agent.getId()));
+		return R.data(agentItemsList.isEmpty() ? new ArrayList<>() : agentItemsList);
+	}
+
 }

+ 0 - 3
blade-service/blade-los/src/main/java/org/springblade/los/trade/controller/AgentItemsController.java

@@ -19,7 +19,6 @@ package org.springblade.los.trade.controller;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
-import io.seata.spring.annotation.GlobalTransactional;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
@@ -175,6 +174,4 @@ public class AgentItemsController extends BladeController {
 		}
 		return R.status(agentItemsService.removeByIds(idList));
 	}
-
-
 }

+ 42 - 7
blade-service/blade-los/src/main/java/org/springblade/los/trade/controller/InvoicingController.java

@@ -16,23 +16,26 @@
  */
 package org.springblade.los.trade.controller;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
+import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
-import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import lombok.AllArgsConstructor;
-import javax.validation.Valid;
-
+import org.springblade.core.boot.ctrl.BladeController;
 import org.springblade.core.mp.support.Condition;
 import org.springblade.core.mp.support.Query;
+import org.springblade.core.secure.utils.AuthUtil;
 import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.utils.Func;
-import org.springframework.web.bind.annotation.*;
-import com.baomidou.mybatisplus.core.metadata.IPage;
 import org.springblade.los.trade.entity.Invoicing;
-import org.springblade.los.trade.vo.InvoicingVO;
 import org.springblade.los.trade.service.IInvoicingService;
-import org.springblade.core.boot.ctrl.BladeController;
+import org.springblade.los.trade.vo.InvoicingVO;
+import org.springframework.web.bind.annotation.*;
+
+import javax.validation.Valid;
 
 /**
  * 开票申请表 控制器
@@ -66,6 +69,17 @@ public class InvoicingController extends BladeController {
 	@ApiOperationSupport(order = 2)
 	@ApiOperation(value = "分页", notes = "传入invoicing")
 	public R<IPage<Invoicing>> list(Invoicing invoicing, Query query) {
+		LambdaQueryWrapper<Invoicing> lambdaQueryWrapper = new LambdaQueryWrapper<>();
+		lambdaQueryWrapper.eq(Invoicing::getTenantId, AuthUtil.getTenantId())
+			.eq(Invoicing::getIsDeleted, 0)
+			.like(ObjectUtils.isNotNull(invoicing.getBuyCorporateName()), Invoicing::getBuyCorporateName, invoicing.getBuyCorporateName())
+			.like(ObjectUtils.isNotNull(invoicing.getTaxpayerIdentification()), Invoicing::getTaxpayerIdentification, invoicing.getTaxpayerIdentification())
+			.like(ObjectUtils.isNotNull(invoicing.getBusinessOrganizerName()), Invoicing::getBusinessOrganizerName, invoicing.getBusinessOrganizerName())
+			.like(ObjectUtils.isNotNull(invoicing.getInvoiceNo()), Invoicing::getInvoiceNo, invoicing.getInvoiceNo())
+			.like(ObjectUtils.isNotNull(invoicing.getContractNumber()), Invoicing::getContractNumber, invoicing.getContractNumber())
+			.like(ObjectUtils.isNotNull(invoicing.getCorporateName()), Invoicing::getCorporateName, invoicing.getCorporateName())
+			.orderByDesc(Invoicing::getBusinessDate)
+		;
 		IPage<Invoicing> pages = invoicingService.page(Condition.getPage(query), Condition.getQueryWrapper(invoicing));
 		return R.data(pages);
 	}
@@ -123,4 +137,25 @@ public class InvoicingController extends BladeController {
 	}
 
 
+	/**
+	 * 确认开票
+	 */
+	@PostMapping("/confirmInvoicing")
+	@ApiOperationSupport(order = 6)
+	@ApiOperation(value = "新增或修改", notes = "传入invoicing")
+	public R confirmInvoicing(@Valid @RequestBody Invoicing invoicing) {
+		return invoicingService.confirmInvoicing(invoicing);
+	}
+
+	/**
+	 * 撤销开票
+	 */
+	@PostMapping("/revokeInvoicing")
+	@ApiOperationSupport(order = 6)
+	@ApiOperation(value = "新增或修改", notes = "传入invoicing")
+	public R revokeInvoicing(@Valid @RequestBody Invoicing invoicing) {
+		return invoicingService.revokeInvoicing(invoicing);
+	}
+
+
 }

+ 2 - 0
blade-service/blade-los/src/main/java/org/springblade/los/trade/mapper/AgentItemsMapper.xml

@@ -45,6 +45,8 @@
         <result column="freight_forwarder" property="freightForwarder"/>
         <result column="clearance_speed_of_progress" property="clearanceSpeedOfProgress"/>
         <result column="payment_record" property="paymentRecord"/>
+        <result column="specifications" property="specifications"/>
+        <result column="invoice_amount" property="invoiceAmount"/>
     </resultMap>
 
 

+ 1 - 0
blade-service/blade-los/src/main/java/org/springblade/los/trade/mapper/InvoicingItemMapper.xml

@@ -23,6 +23,7 @@
         <result column="specifications" property="specifications"/>
         <result column="this_amount" property="thisAmount"/>
         <result column="invoiced_amount" property="invoicedAmount"/>
+        <result column="src_id" property="srcId"/>
     </resultMap>
 
 

+ 4 - 0
blade-service/blade-los/src/main/java/org/springblade/los/trade/service/IInvoicingService.java

@@ -42,4 +42,8 @@ public interface IInvoicingService extends IService<Invoicing> {
     Invoicing detail(Invoicing invoicing);
 
 	R submit(Invoicing invoicing);
+
+	R confirmInvoicing(Invoicing invoicing);
+
+	R revokeInvoicing(Invoicing invoicing);
 }

+ 74 - 12
blade-service/blade-los/src/main/java/org/springblade/los/trade/service/impl/AgentServiceImpl.java

@@ -134,6 +134,8 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
 	private final IRecordService recordService;
 	private final IBCorpsService bCorpsService;
 	private final IReportDataTradeService reportDataTradeService;
+	private final IInvoicingService invoicingService;
+	private final IInvoicingItemService invoicingItemService;
 
 	@Override
 	public IPage<AgentVO> selectAgentPage(IPage<AgentVO> page, AgentVO agent) {
@@ -573,7 +575,7 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
 					item.setPodEnName(agent.getPodEnName());
 					item.setPid(agent.getId());
 				} else {
-					if ("录入".equals(agent.getOrderStatus())){
+					if ("录入".equals(agent.getOrderStatus())) {
 						item.setStlExrate(agent.getExchangeRate());
 						if (item.getStlExrate().compareTo(item.getDiscountExrate()) < 0) {
 							throw new RuntimeException("优惠汇率不能大于结算汇率");
@@ -615,7 +617,7 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
 				if (ObjectUtils.isNull(item.getDiscountExrate())) {
 					throw new RuntimeException("首款、尾款,手续费优惠汇率不能为空");
 				}
-				if ("录入".equals(agent.getOrderStatus())){
+				if ("录入".equals(agent.getOrderStatus())) {
 					if (!"SXF".equals(item.getFeeCode())) {
 						BigDecimal amount = item.getAmountLoc().multiply(item.getDiscountExrate());
 						item.setProfit(item.getAmount().subtract(amount));
@@ -683,7 +685,7 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
 					item.setPid(agent.getId());
 				} else {
 					item.setStlPid(agent.getId());
-					if ("录入".equals(agent.getOrderStatus())){
+					if ("录入".equals(agent.getOrderStatus())) {
 						item.setStlExrate(agent.getExchangeRate());
 //					item.setExrate(agent.getExchangeRate());
 						item.setDiscountExrate(agent.getExchangeRate());
@@ -3506,7 +3508,7 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
 						.map(FeeCenter::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add));
 					agentFeeReport.setRealityTradeAgencyAmount(feeCenterListC.stream().filter(e -> "DLF".equals(e.getFeeCode()))
 						.map(FeeCenter::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add));
-				}else{
+				} else {
 					agentFeeReport.setRealityOtherAmount(new BigDecimal("0.00"));
 					agentFeeReport.setRealityTariff(new BigDecimal("0.00"));
 					agentFeeReport.setRealityValueAddedTax(new BigDecimal("0.00"));
@@ -3562,7 +3564,7 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
 								agentFeeItemsReport.setRealityExchangeRate(null);
 								agentFeeItemsReport.setRealityAmount(null);
 							}
-						}else{
+						} else {
 							agentFeeItemsReport.setRealityExchangeRate(null);
 							agentFeeItemsReport.setRealityAmount(null);
 						}
@@ -3576,7 +3578,7 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
 						agentFeeReport.setRealityServiceCharge(feeCenterListC.stream().filter(e -> e.getFeeCode().equals("SXF")
 								&& ObjectUtils.isNotNull(e.getFeeType()) && "1".equals(e.getFeeType()))
 							.map(FeeCenter::getAmount).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
-					}else{
+					} else {
 						agentFeeReport.setRealityPostElectricFee(new BigDecimal("0.00"));
 						agentFeeReport.setRealityServiceCharge(new BigDecimal("0.00"));
 					}
@@ -3642,7 +3644,7 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
 								agentFeeItemsReport.setRealityExchangeRate(null);
 								agentFeeItemsReport.setRealityAmount(null);
 							}
-						}else{
+						} else {
 							agentFeeItemsReport.setRealityExchangeRate(null);
 							agentFeeItemsReport.setRealityAmount(null);
 						}
@@ -3716,7 +3718,7 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
 				agentFeeReport.setPaymentMethod(agent.getAdvanceRatio());
 				agentFeeReport.setReportPostElectricFee(agentFeeReport.getRealityPostElectricFee());
 				BigDecimal discountAmount = new BigDecimal("0.00");
-				if (!reportList.isEmpty()){
+				if (!reportList.isEmpty()) {
 					discountAmount = reportList.stream().map(AgentRecordReport::getDiscountAmount)
 						.filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
 				}
@@ -3832,7 +3834,7 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
 						.map(FeeCenter::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add));
 					agentFeeReport.setRealityTradeAgencyAmount(feeCenterListC.stream().filter(e -> "DLF".equals(e.getFeeCode()))
 						.map(FeeCenter::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add));
-				}else{
+				} else {
 					agentFeeReport.setRealityOtherAmount(new BigDecimal("0.00"));
 					agentFeeReport.setRealityTariff(new BigDecimal("0.00"));
 					agentFeeReport.setRealityValueAddedTax(new BigDecimal("0.00"));
@@ -3888,7 +3890,7 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
 								agentFeeItemsReport.setRealityExchangeRate(null);
 								agentFeeItemsReport.setRealityAmount(null);
 							}
-						}else{
+						} else {
 							agentFeeItemsReport.setRealityExchangeRate(null);
 							agentFeeItemsReport.setRealityAmount(null);
 						}
@@ -3901,7 +3903,7 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
 						agentFeeReport.setRealityServiceCharge(feeCenterListC.stream().filter(e -> e.getFeeCode().equals("SXF")
 								&& ObjectUtils.isNotNull(e.getFeeType()) && "1".equals(e.getFeeType()))
 							.map(FeeCenter::getAmount).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
-					}else{
+					} else {
 						agentFeeReport.setRealityPostElectricFee(new BigDecimal("0.00"));
 						agentFeeReport.setRealityServiceCharge(new BigDecimal("0.00"));
 					}
@@ -3967,7 +3969,7 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
 								agentFeeItemsReport.setRealityExchangeRate(null);
 								agentFeeItemsReport.setRealityAmount(null);
 							}
-						}else{
+						} else {
 							agentFeeItemsReport.setRealityExchangeRate(null);
 							agentFeeItemsReport.setRealityAmount(null);
 						}
@@ -4369,6 +4371,66 @@ public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements
 			} else {
 				map.put(MagicValues.DATA, null);
 			}
+		} else if (MagicValues.INVOICING_APPLICATION.equals(reportCode) && MagicValues.INVOICING_APPLICATION.equals(groupCode) && MagicValues.MYDL_KPSQ.equals(type)) {
+			Invoicing invoicing = invoicingService.getById(billId);
+			if (invoicing != null) {
+				R<Dept> res = sysClient.getDept(Long.parseLong(AuthUtil.getDeptId()));
+				Dept dept;
+				if (res.isSuccess() && res.getData() != null) {
+					dept = res.getData();
+					String status = sysClient.getParamServiceNew("is.update.default");
+					if ("1".equals(status)) {
+						R<User> resUser = userClient.userInfoById(AuthUtil.getUserId());
+						if (resUser.isSuccess() && resUser.getData() != null) {
+							dept.setEmail(resUser.getData().getEmail());
+							dept.setTel(resUser.getData().getPhone());
+							dept.setContacts(resUser.getData().getRealName());
+						}
+					}
+				} else {
+					throw new RuntimeException("获取报表表头数据失败");
+				}
+				List<InvoicingItem> invoicingItemList = invoicingItemService.list(new LambdaQueryWrapper<InvoicingItem>()
+					.eq(InvoicingItem::getTenantId, AuthUtil.getTenantId())
+					.eq(InvoicingItem::getIsDeleted, 0)
+					.eq(InvoicingItem::getPid, invoicing.getId()));
+				invoicing.setInvoicingItemList(invoicingItemList.isEmpty() ? new ArrayList<>() : invoicingItemList);
+				if (!invoicingItemList.isEmpty()) {
+					AgentItems agentItems = agentItemsService.getById(invoicingItemList.get(0).getSrcId());
+					if (agentItems != null){
+						Agent agent = baseMapper.selectById(agentItems.getPid());
+						if (agent != null) {
+							invoicing.setEta(agent.getContractDate());
+							invoicing.setPayConvergeDate(agent.getFirstActualPaymentDate());
+							invoicing.setReceivePaymentDate(agent.getFirstPaidInPaymentDate());
+							invoicing.setAmount(agent.getSumAmount());
+							invoicing.setAmountUsd(agent.getGoodsValue());
+							List<FeeCenter> feeCenterList = feeCenterService.list(new LambdaQueryWrapper<FeeCenter>()
+								.eq(FeeCenter::getTenantId, AuthUtil.getTenantId())
+								.eq(FeeCenter::getIsDeleted, 0)
+								.eq(FeeCenter::getPid, agent.getId())
+								.eq(FeeCenter::getDc, "C")
+								.eq(FeeCenter::getBusinessType, "MYDL")
+								.apply("not find_in_set(fee_code,'SXF,SFK,WK,YDF,YFK')"));
+							if (!feeCenterList.isEmpty()) {
+								invoicing.setTariff(feeCenterList.stream().filter(e -> "GS".equals(e.getFeeCode())).map(FeeCenter::getAmount)
+									.reduce(BigDecimal.ZERO, BigDecimal::add));
+								invoicing.setLateFee(feeCenterList.stream().filter(e -> "ZNJ".equals(e.getFeeCode())).map(FeeCenter::getAmount)
+									.reduce(BigDecimal.ZERO, BigDecimal::add));
+								invoicing.setValueAddedTax(feeCenterList.stream().filter(e -> "ZZS".equals(e.getFeeCode())).map(FeeCenter::getAmount)
+									.reduce(BigDecimal.ZERO, BigDecimal::add));
+								invoicing.setOtherAmount(feeCenterList.stream().filter(e -> !"GS,ZNJ,ZZS".contains(e.getFeeCode())).map(FeeCenter::getAmount)
+									.reduce(BigDecimal.ZERO, BigDecimal::add));
+								invoicing.setAmountTotal(invoicing.getTariff().add(invoicing.getLateFee()).add(invoicing.getValueAddedTax())
+									.add(invoicing.getOtherAmount()));
+							}
+						}
+					}
+				}
+				map.put(MagicValues.DATA, invoicing);
+			} else {
+				map.put(MagicValues.DATA, new Invoicing());
+			}
 		} else {
 			map = reportDataTradeService.getReportDataTrade(billId, reportCode, groupCode, corpIds, itemIds, type, curCode);
 		}

+ 99 - 0
blade-service/blade-los/src/main/java/org/springblade/los/trade/service/impl/InvoicingServiceImpl.java

@@ -27,9 +27,11 @@ import org.springblade.los.basic.business.entity.BusinessType;
 import org.springblade.los.basic.business.service.IBusinessTypeService;
 import org.springblade.los.billno.entity.BusinessBillNo;
 import org.springblade.los.billno.service.IBusinessBillNoService;
+import org.springblade.los.trade.entity.AgentItems;
 import org.springblade.los.trade.entity.Invoicing;
 import org.springblade.los.trade.entity.InvoicingItem;
 import org.springblade.los.trade.mapper.InvoicingMapper;
+import org.springblade.los.trade.service.IAgentItemsService;
 import org.springblade.los.trade.service.IInvoicingItemService;
 import org.springblade.los.trade.service.IInvoicingService;
 import org.springblade.los.trade.vo.InvoicingVO;
@@ -41,6 +43,7 @@ import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * 开票申请表 服务实现类
@@ -55,6 +58,7 @@ public class InvoicingServiceImpl extends ServiceImpl<InvoicingMapper, Invoicing
 	private final IInvoicingItemService invoicingItemService;
 	private final IBusinessBillNoService businessBillNoService;
 	private final IBusinessTypeService bBusinessTypeService;
+	private final IAgentItemsService agentItemsService;
 
 	@Override
 	public IPage<InvoicingVO> selectInvoicingPage(IPage<InvoicingVO> page, InvoicingVO invoicing) {
@@ -97,6 +101,7 @@ public class InvoicingServiceImpl extends ServiceImpl<InvoicingMapper, Invoicing
 				return R.fail(500, "生成订单编号失败");
 			}
 			invoicing.setBusinessNo((String) clientBillNo.getData());
+			invoicing.setBusinessDate(new Date());
 			invoicing.setCreateTime(new Date());
 			invoicing.setCreateUser(AuthUtil.getUserId());
 			invoicing.setCreateUserName(AuthUtil.getUserName());
@@ -126,4 +131,98 @@ public class InvoicingServiceImpl extends ServiceImpl<InvoicingMapper, Invoicing
 		return R.data(invoicing);
 	}
 
+	@Override
+	public R confirmInvoicing(Invoicing invoicing) {
+		invoicing.setUpdateTime(new Date());
+		invoicing.setUpdateUser(AuthUtil.getUserId());
+		invoicing.setUpdateUserName(AuthUtil.getUserName());
+		invoicing.setStatus("已开票");
+		baseMapper.updateById(invoicing);
+		if (ObjectUtils.isNotNull(invoicing.getInvoicingItemList()) && !invoicing.getInvoicingItemList().isEmpty()) {
+			List<Long> srcIdList = invoicing.getInvoicingItemList().stream().map(InvoicingItem::getSrcId).distinct().collect(Collectors.toList());
+			List<AgentItems> agentItemsList = new ArrayList<>();
+			List<AgentItems> agentItemsUpdate = new ArrayList<>();
+			if (!srcIdList.isEmpty()) {
+				agentItemsList = agentItemsService.list(new LambdaQueryWrapper<AgentItems>()
+					.eq(AgentItems::getTenantId, AuthUtil.getTenantId())
+					.eq(AgentItems::getIsDeleted, 0)
+					.in(AgentItems::getId, srcIdList));
+			}
+			if (agentItemsList.isEmpty()) {
+				throw new RuntimeException("未找到贸易代理-合同号:" + invoicing.getContractNumber() + "明细信息");
+			}
+			for (InvoicingItem item : invoicing.getInvoicingItemList()) {
+				item.setUpdateTime(new Date());
+				item.setUpdateUser(AuthUtil.getUserId());
+				item.setUpdateUserName(AuthUtil.getUserName());
+				AgentItems agentItems = agentItemsList.stream().filter(e -> e.getId().equals(item.getSrcId()))
+					.findFirst().orElse(null);
+				if (agentItems == null) {
+					throw new RuntimeException("商品:" + item.getLabelProductName() + "未查到对应明细");
+				}
+				if (item.getAmount().compareTo(agentItems.getInvoiceAmount().add(item.getThisAmount())) < 0) {
+					throw new RuntimeException("商品:" + item.getLabelProductName() + "本次结算金额" + item.getThisAmount() + "+已开票金额" +
+						agentItems.getInvoiceAmount() + "大于货值金额" + item.getAmount());
+				}
+				agentItems.setInvoiceAmount(agentItems.getInvoiceAmount().add(item.getThisAmount()));
+				agentItems.setUpdateTime(new Date());
+				agentItems.setUpdateUser(AuthUtil.getUserId());
+				agentItems.setUpdateUserName(AuthUtil.getUserName());
+				agentItemsUpdate.add(agentItems);
+			}
+			invoicingItemService.updateBatchById(invoicing.getInvoicingItemList());
+			if (!agentItemsUpdate.isEmpty()) {
+				agentItemsService.updateBatchById(agentItemsUpdate);
+			}
+		}
+		return R.data(invoicing);
+	}
+
+	@Override
+	public R revokeInvoicing(Invoicing invoicing) {
+		invoicing.setUpdateTime(new Date());
+		invoicing.setUpdateUser(AuthUtil.getUserId());
+		invoicing.setUpdateUserName(AuthUtil.getUserName());
+		invoicing.setStatus("录入");
+		baseMapper.updateById(invoicing);
+		if (ObjectUtils.isNotNull(invoicing.getInvoicingItemList()) && !invoicing.getInvoicingItemList().isEmpty()) {
+			List<Long> srcIdList = invoicing.getInvoicingItemList().stream().map(InvoicingItem::getSrcId).distinct().collect(Collectors.toList());
+			List<AgentItems> agentItemsList = new ArrayList<>();
+			List<AgentItems> agentItemsUpdate = new ArrayList<>();
+			if (!srcIdList.isEmpty()) {
+				agentItemsList = agentItemsService.list(new LambdaQueryWrapper<AgentItems>()
+					.eq(AgentItems::getTenantId, AuthUtil.getTenantId())
+					.eq(AgentItems::getIsDeleted, 0)
+					.in(AgentItems::getId, srcIdList));
+			}
+			if (agentItemsList.isEmpty()) {
+				throw new RuntimeException("未找到贸易代理-合同号:" + invoicing.getContractNumber() + "明细信息");
+			}
+			for (InvoicingItem item : invoicing.getInvoicingItemList()) {
+				item.setUpdateTime(new Date());
+				item.setUpdateUser(AuthUtil.getUserId());
+				item.setUpdateUserName(AuthUtil.getUserName());
+				AgentItems agentItems = agentItemsList.stream().filter(e -> e.getId().equals(item.getSrcId()))
+					.findFirst().orElse(null);
+				if (agentItems == null) {
+					throw new RuntimeException("商品:" + item.getLabelProductName() + "未查到对应明细");
+				}
+				if (agentItems.getInvoiceAmount().subtract(item.getThisAmount()).compareTo(new BigDecimal("0.00")) < 0) {
+					throw new RuntimeException("商品:" + item.getLabelProductName() + "已开票金额" + agentItems.getInvoiceAmount() + "-本次结算金额" +
+						item.getThisAmount() + "小于0");
+				}
+				agentItems.setInvoiceAmount(agentItems.getInvoiceAmount().subtract(item.getThisAmount()));
+				agentItems.setUpdateTime(new Date());
+				agentItems.setUpdateUser(AuthUtil.getUserId());
+				agentItems.setUpdateUserName(AuthUtil.getUserName());
+				agentItemsUpdate.add(agentItems);
+			}
+			invoicingItemService.updateBatchById(invoicing.getInvoicingItemList());
+			if (!agentItemsUpdate.isEmpty()) {
+				agentItemsService.updateBatchById(agentItemsUpdate);
+			}
+		}
+		return R.data(invoicing);
+	}
+
 }