|
|
@@ -30,13 +30,17 @@ import lombok.AllArgsConstructor;
|
|
|
import javax.validation.Valid;
|
|
|
|
|
|
import org.springblade.client.entity.CorpsDesc;
|
|
|
+import org.springblade.client.entity.FeesDesc;
|
|
|
import org.springblade.client.feign.ICorpsDescClient;
|
|
|
+import org.springblade.client.feign.IFeesDescClient;
|
|
|
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.secure.utils.SecureUtil;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
import org.springblade.core.tool.utils.Func;
|
|
|
+import org.springblade.finance.entity.Acc;
|
|
|
+import org.springblade.finance.feign.IFinanceClient;
|
|
|
import org.springblade.purchase.sales.entity.OrderFees;
|
|
|
import org.springblade.purchase.sales.entity.OrderItems;
|
|
|
import org.springblade.purchase.sales.service.*;
|
|
|
@@ -74,6 +78,8 @@ public class OrderController extends BladeController {
|
|
|
private final IOrderPartsService orderPartsService;
|
|
|
private final ICorpsDescClient corpsDescClient;//获取客户信息
|
|
|
private final IUserClient userClient;//获取用户信息
|
|
|
+ private final IFeesDescClient feesDescClient;
|
|
|
+ private final IFinanceClient iFinanceClient;
|
|
|
|
|
|
/**
|
|
|
* 详情
|
|
|
@@ -349,11 +355,184 @@ public class OrderController extends BladeController {
|
|
|
e.setSaleCorpName(corpsDescClientCorpMessage.getData().getCname());
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ //采购主表id
|
|
|
Long orderId = e.getOrderId();
|
|
|
+ LambdaQueryWrapper<Order> orderLambdaQueryWrapper=new LambdaQueryWrapper<>();
|
|
|
+ orderLambdaQueryWrapper
|
|
|
+ .eq(Order::getId,orderId)
|
|
|
+ .eq(Order::getTenantId,AuthUtil.getTenantId())
|
|
|
+ .eq(Order::getIsDeleted,0);
|
|
|
+
|
|
|
+ Order service = orderService.getOne(orderLambdaQueryWrapper);
|
|
|
+
|
|
|
|
|
|
+ //调用-费用微服务-获取费用设置详情
|
|
|
+ R<FeesDesc> customDuty = feesDescClient.getFeesByName("关税");
|
|
|
+ Long customDutyId=null;
|
|
|
+ if(customDuty.isSuccess())
|
|
|
+ {
|
|
|
+ customDutyId=customDuty.getData().getId();
|
|
|
+ }
|
|
|
|
|
|
+ Long quotaId=null;
|
|
|
+ R<FeesDesc> quota = feesDescClient.getFeesByName("配额");
|
|
|
+ if(quota.isSuccess())
|
|
|
+ {
|
|
|
+ quotaId=quota.getData().getId();
|
|
|
+ }
|
|
|
|
|
|
+ Long gstId=null;
|
|
|
+ R<FeesDesc> GST = feesDescClient.getFeesByName("增值税");
|
|
|
+ if(GST.isSuccess())
|
|
|
+ {
|
|
|
+ gstId=GST.getData().getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ Long deliverId=null;
|
|
|
+ R<FeesDesc> deliver = feesDescClient.getFeesByName("物流费");
|
|
|
+ if(deliver.isSuccess())
|
|
|
+ {
|
|
|
+ deliverId=deliver.getData().getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取关税账单明细
|
|
|
+ Acc customDutyAcc=new Acc();
|
|
|
+ customDutyAcc.setSrcType(2);
|
|
|
+ customDutyAcc.setSrcFeesId(customDutyId);
|
|
|
+ customDutyAcc.setSrcParentId(orderId);
|
|
|
+ R<List<Acc>> accListByCondition = iFinanceClient.getAccListByCondition(customDutyAcc);
|
|
|
+ //关税
|
|
|
+ BigDecimal customDutyMoney=BigDecimal.ZERO;
|
|
|
+ if(accListByCondition.isSuccess())
|
|
|
+ {
|
|
|
+ List<Acc> customDutyList = accListByCondition.getData();
|
|
|
+ //关税
|
|
|
+
|
|
|
+ if(CollectionUtils.isNotEmpty(customDutyList))
|
|
|
+ {
|
|
|
+ customDutyMoney=customDutyList.stream().reduce(BigDecimal.ZERO,(x,y) ->{ return x.add(y.getAmount().multiply(y.getExchangeRate())); },BigDecimal::add);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ customDutyMoney=BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ e.setCustomDutyMoney(customDutyMoney);
|
|
|
+
|
|
|
+ //获取配额账单明细
|
|
|
+ Acc quotaAcc=new Acc();
|
|
|
+ quotaAcc.setSrcType(2);
|
|
|
+ quotaAcc.setSrcFeesId(quotaId);
|
|
|
+ quotaAcc.setSrcParentId(orderId);
|
|
|
+ R<List<Acc>> accListByCondition2 = iFinanceClient.getAccListByCondition(quotaAcc);
|
|
|
+ //配额
|
|
|
+ BigDecimal quotaMoney=BigDecimal.ZERO;
|
|
|
+ if(accListByCondition2.isSuccess())
|
|
|
+ {
|
|
|
+ List<Acc> quotaList = accListByCondition2.getData();
|
|
|
+ //配额
|
|
|
+ if(CollectionUtils.isNotEmpty(quotaList))
|
|
|
+ {
|
|
|
+ quotaMoney=quotaList.stream().reduce(BigDecimal.ZERO,(x,y) ->{ return x.add(y.getAmount().multiply(y.getExchangeRate())); },BigDecimal::add);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ quotaMoney=BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ e.setQuotaMoney(quotaMoney);
|
|
|
+ //获取增值税账单明细
|
|
|
+ Acc gstAcc=new Acc();
|
|
|
+ gstAcc.setSrcType(2);
|
|
|
+ gstAcc.setSrcFeesId(gstId);
|
|
|
+ gstAcc.setSrcParentId(orderId);
|
|
|
+ R<List<Acc>> accListByCondition3 = iFinanceClient.getAccListByCondition(gstAcc);
|
|
|
+ //增值税
|
|
|
+ BigDecimal gstMoney=BigDecimal.ZERO;
|
|
|
+ if(accListByCondition3.isSuccess())
|
|
|
+ {
|
|
|
+ List<Acc> gstList = accListByCondition3.getData();
|
|
|
+
|
|
|
+ //增值税
|
|
|
+ if(CollectionUtils.isNotEmpty(gstList))
|
|
|
+ {
|
|
|
+ gstMoney=gstList.stream().reduce(BigDecimal.ZERO,(x,y) ->{ return x.add(y.getAmount().multiply(y.getExchangeRate())); },BigDecimal::add);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ gstMoney=BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ e.setGstMoney(gstMoney);
|
|
|
+ //获取货款账单明细
|
|
|
+ Acc itemAcc=new Acc();
|
|
|
+ itemAcc.setSrcType(1);
|
|
|
+ itemAcc.setSrcFeesId(null);
|
|
|
+ itemAcc.setSrcParentId(orderId);
|
|
|
+ R<List<Acc>> accListByCondition4 = iFinanceClient.getAccListByCondition(itemAcc);
|
|
|
+ //货款
|
|
|
+ BigDecimal itemMoney=BigDecimal.ZERO;
|
|
|
+ if(accListByCondition4.isSuccess())
|
|
|
+ {
|
|
|
+ List<Acc> itemList = accListByCondition4.getData();
|
|
|
+ if(CollectionUtils.isNotEmpty(itemList))
|
|
|
+ {
|
|
|
+ //货款
|
|
|
+ itemMoney=itemList.stream().reduce(BigDecimal.ZERO,(x,y) ->{ return x.add(y.getAmount().multiply(y.getExchangeRate())); },BigDecimal::add);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ itemMoney=BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ e.setItemMoney(itemMoney);
|
|
|
+ //销售主表信息
|
|
|
+ LambdaQueryWrapper<Order> saleOrderWrapper=new LambdaQueryWrapper<>();
|
|
|
+ saleOrderWrapper.eq(Order::getId,e.getOrderSaleId()).eq(Order::getTenantId,AuthUtil.getTenantId());
|
|
|
+ Order serviceOne = orderService.getOne(saleOrderWrapper);
|
|
|
+
|
|
|
+ //成本单价=(货款+关税+配额)/发票重量---精确小数点2位
|
|
|
+ BigDecimal unitPrice=((itemMoney.add(quotaMoney)).add(customDutyMoney)).divide(service.getInvoiceWeight(),2,BigDecimal.ROUND_DOWN);
|
|
|
+ e.setUnitPrice(unitPrice);
|
|
|
+ if(serviceOne.getExchangeRate()==null)
|
|
|
+ {
|
|
|
+ throw new SecurityException("销售订单:"+serviceOne.getOrderNo()+",汇率未填,无法完成统计");
|
|
|
+ }
|
|
|
+ //开票金额= 销售订单明细总价*销售订单主表的汇率
|
|
|
+ BigDecimal InvoiceAmount=e.getAmount().multiply(serviceOne.getExchangeRate());
|
|
|
+ e.setInvoiceAmount(InvoiceAmount);
|
|
|
+ //成本金额=提货数量*成本价格
|
|
|
+ BigDecimal costAmount=e.getSaleBillWeight().multiply(unitPrice);
|
|
|
+ e.setCostAmount(costAmount);
|
|
|
+ //物流费用
|
|
|
+ Acc deliverAcc=new Acc();
|
|
|
+ deliverAcc.setSrcType(2);
|
|
|
+ deliverAcc.setSrcFeesId(deliverId);
|
|
|
+ deliverAcc.setSrcParentId(e.getOrderSaleId());
|
|
|
+ R<List<Acc>> accListByCondition5 = iFinanceClient.getAccListByCondition(gstAcc);
|
|
|
+ BigDecimal deliverMoney=BigDecimal.ZERO;
|
|
|
+ if(accListByCondition5.isSuccess())
|
|
|
+ {
|
|
|
+ List<Acc> deliverMoneyList = accListByCondition5.getData();
|
|
|
+ //关税
|
|
|
+
|
|
|
+ if(CollectionUtils.isNotEmpty(deliverMoneyList))
|
|
|
+ {
|
|
|
+ deliverMoney=deliverMoneyList.stream().reduce(BigDecimal.ZERO,(x,y) ->{ return x.add(y.getAmount().multiply(y.getExchangeRate())); },BigDecimal::add);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ deliverMoney=BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ e.setDeliverMoney(deliverMoney);
|
|
|
+ //利润=开票金额-成本金额-物流费用
|
|
|
+ BigDecimal profit=(InvoiceAmount.subtract(costAmount)).subtract(deliverMoney);
|
|
|
+ e.setProfit(profit);
|
|
|
});
|
|
|
}
|
|
|
orderStatisticAnalysisVOIPage.setRecords(records);
|