销售利润优化

jg-waiwang-pro
vayne 5 months ago
parent 4e0eb3c50c
commit ed1d824d67

@ -1119,4 +1119,9 @@
where c.code = #{code}
</select>
<select id="getSaleAmountSum" resultType="java.math.BigDecimal">
select sum(tax_count) as taxCount from jg_business_order_product_relational
where f_delete_mark is null and business_order_id = #{id}
</select>
</mapper>

@ -661,4 +661,15 @@
left join jg_voucher_vehicle c on a.id = c.voucher_id and c.f_delete_mark is null
where a.f_delete_mark is null and a.id = #{id}
</select>
<select id="queryVoucherByBusinessOrder" resultType="java.math.BigDecimal">
select
IFNULL(sum(round(e.business_price * b.net_weight,2)),0) AS netWeight
from jg_voucher a
left join jg_voucher_product b on a.id = b.voucher_id and b.f_delete_mark is null
left join jg_voucher c on a.voucher_relation = c.id and c.f_delete_mark is null
left join jg_business_order d on c.business_order_id = d.id
left join jg_business_order_product_relational e on d.id = e.business_order_id and b.product_id = e.product_id and e.f_delete_mark is null
where a.f_delete_mark is null and a.is_transfer = '2' and a.business_order_id = #{id}
</select>
</mapper>

@ -72,4 +72,5 @@ public interface BusinessOrderMapper extends BaseMapper<BusinessOrderEntity> {
List<HashMap<String, Object>> getWordExcelInfo(@Param("code") String code);
List<HashMap<String, Object>> getOrderInfo(@Param("code") String code);
BigDecimal getSaleAmountSum(@Param("id") String id);
}

@ -47,4 +47,5 @@ public interface VoucherMapper extends BaseMapper<VoucherEntity> {
List<WarehousingOutboundPoundlistEntity> salereturnVoucher(@Param("ew")QueryWrapper<WarehousingOutboundPoundlistEntity> voucherEntityQueryWrapper);
BigDecimal queryVoucherProductNetWeight(@Param("id") String id);
VoucherEntity queryVoucherDetail(@Param("id") String id);
BigDecimal queryVoucherByBusinessOrder(@Param("id") String id);
}

@ -11,6 +11,7 @@ import jnpf.model.yunguan.YunguanPurchaseOrderModel;
import jnpf.model.yunguan.YunguanPurchaseOrderProductModel;
import jnpf.model.yunguan.YunguanSaleOrderModel;
import jnpf.model.yunguan.YunguanSaleOrderProductModel;
import org.apache.ibatis.annotations.Param;
import javax.servlet.http.HttpServletResponse;
@ -95,4 +96,6 @@ public interface BusinessOrderService extends IService<BusinessOrderEntity> {
List<YunguanSaleOrderProductModel> querySaleOrderProductByYunGuanInfo(String id);
void getPdfInfo(BusinessOrderEntity businessOrderEntity, HttpServletResponse response, String token) throws Exception;
BigDecimal getSaleAmountSumInfo(@Param("id") String id);
}

@ -76,4 +76,5 @@ public interface VoucherService extends IService<VoucherEntity> {
List<WarehousingOutboundPoundlistEntity> salereturnVoucherInfo(String id,VoucherPagination voucherPagination);
VoucherEntity queryVoucherDetailInfo(String id);
BigDecimal queryVoucherProductNetWeightInfo(String id);
BigDecimal queryVoucherByBusinessOrderInfo(String id);
}

@ -1378,6 +1378,11 @@ public class BusinessOrderServiceImpl extends ServiceImpl<BusinessOrderMapper, B
}
}
@Override
public BigDecimal getSaleAmountSumInfo(String id) {
return businessOrderMapper.getSaleAmountSum(id);
}
public void getExcel(List<HashMap<String, Object>> list, String templateFilePath,String settlements,BigDecimal amount) throws Exception {
String[] strings = settlements.split("_");
settlements=strings[0];

@ -1244,4 +1244,9 @@ public class VoucherServiceImpl extends ServiceImpl<VoucherMapper, VoucherEntity
public BigDecimal queryVoucherProductNetWeightInfo(String id) {
return voucherMapper.queryVoucherProductNetWeight(id);
}
@Override
public BigDecimal queryVoucherByBusinessOrderInfo(String id) {
return voucherMapper.queryVoucherByBusinessOrder(id);
}
}

@ -139,35 +139,24 @@ public class BusinessOrderController {
//计算销售订单的利润
for (BusinessOrderEntity entity : list) {
//计算销售订单的总额
QueryWrapper<BusinessOrderProductRelationalEntity> queryWrapperSaleProduct = new QueryWrapper<>();
queryWrapperSaleProduct.lambda().eq(BusinessOrderProductRelationalEntity::getBusinessOrderId,entity.getId());
List<BusinessOrderProductRelationalEntity> businessOrderProductList = businessOrderProductRelationalService.list(queryWrapperSaleProduct);
BigDecimal saleAmount = new BigDecimal(0); //销售订单总额
BigDecimal purchaseAmount = new BigDecimal(0); //采购订单总额
for (BusinessOrderProductRelationalEntity productEntity : businessOrderProductList){
saleAmount = saleAmount.add(new BigDecimal(productEntity.getTaxCount()));
}
QueryWrapper<VoucherEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(VoucherEntity::getIsTransfer,"2");
queryWrapper.lambda().eq(VoucherEntity::getBusinessOrderId,entity.getId());
queryWrapper.lambda().isNull(VoucherEntity::getDeleteMark);
List<VoucherEntity> voucherEntityList = voucherService.list(queryWrapper); //销售订单下所有销售发货凭证
for (VoucherEntity entity1 : voucherEntityList){
VoucherEntity saleVoucher = voucherService.queryVoucherDetailInfo(entity1.getId()); //得到销售发货凭证的净重
VoucherEntity voucherEntity = voucherService.queryVoucherDetailInfo(entity1.getVoucherRelation()); //销售发货凭证对应的采购收货凭证
if (ObjectUtil.isNotEmpty(voucherEntity)){
BusinessOrderEntity businessOrderEntity = businessOrderService.getInfo(voucherEntity.getBusinessOrderId()); //采购收货凭证对应的采购单
if (ObjectUtil.isNotEmpty(businessOrderEntity)){
QueryWrapper<BusinessOrderProductRelationalEntity> queryWrapper2 = new QueryWrapper<>();
queryWrapper2.lambda().eq(BusinessOrderProductRelationalEntity::getBusinessOrderId,businessOrderEntity.getId());
queryWrapper2.lambda().eq(BusinessOrderProductRelationalEntity::getProductId,voucherEntity.getProductId());
BusinessOrderProductRelationalEntity businessOrderProductRelationalEntity = businessOrderProductRelationalService.getOne(queryWrapper2); //通过凭证商品id和采购单id找出采购单下具体的商品信息
if (ObjectUtil.isNotEmpty(businessOrderProductRelationalEntity)){
purchaseAmount = purchaseAmount.add(businessOrderProductRelationalEntity.getBusinessPrice().multiply(saleVoucher.getNetWeight()).setScale(2, RoundingMode.HALF_UP)); //采购单价*凭证净重 = 采购金额
}
}
}
}
BigDecimal saleAmount = businessOrderService.getSaleAmountSumInfo(entity.getId()); //销售订单总额
BigDecimal purchaseAmount = voucherService.queryVoucherByBusinessOrderInfo(entity.getId()); //采购订单总额
// List<VoucherEntity> voucherEntityList = voucherService.queryVoucherByBusinessOrderInfo(entity.getId()); //销售订单下所有销售发货凭证
// for (VoucherEntity entity1 : voucherEntityList){
// VoucherEntity voucherEntity = voucherService.queryVoucherDetailInfo(entity1.getVoucherRelation()); //销售发货凭证对应的采购收货凭证
// if (ObjectUtil.isNotEmpty(voucherEntity)){
// BusinessOrderEntity businessOrderEntity = businessOrderService.getInfo(voucherEntity.getBusinessOrderId()); //采购收货凭证对应的采购单
// if (ObjectUtil.isNotEmpty(businessOrderEntity)){
// QueryWrapper<BusinessOrderProductRelationalEntity> queryWrapper2 = new QueryWrapper<>();
// queryWrapper2.lambda().eq(BusinessOrderProductRelationalEntity::getBusinessOrderId,businessOrderEntity.getId());
// queryWrapper2.lambda().eq(BusinessOrderProductRelationalEntity::getProductId,voucherEntity.getProductId());
// BusinessOrderProductRelationalEntity businessOrderProductRelationalEntity = businessOrderProductRelationalService.getOne(queryWrapper2); //通过凭证商品id和采购单id找出采购单下具体的商品信息
// if (ObjectUtil.isNotEmpty(businessOrderProductRelationalEntity)){
// purchaseAmount = purchaseAmount.add(businessOrderProductRelationalEntity.getBusinessPrice().multiply(entity1.getNetWeight()).setScale(2, RoundingMode.HALF_UP)); //采购单价*凭证净重 = 采购金额
// }
// }
// }
// }
entity.setProfit(saleAmount.subtract(purchaseAmount));//利润
Map<String, Object> businessOrderMap=JsonUtil.entityToMap(entity);
businessOrderMap.put("id", businessOrderMap.get("id"));

Loading…
Cancel
Save