| | |
| | | import cn.iocoder.yudao.module.crm.api.customer.CrmCustomerApi; |
| | | import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService; |
| | | import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO; |
| | | import cn.iocoder.yudao.module.system.api.storage.StorageAttachmentApi; |
| | | import cn.iocoder.yudao.module.mdm.api.item.MdmItemApi; |
| | | import cn.iocoder.yudao.module.mdm.api.item.dto.MdmItemRespDTO; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import jakarta.annotation.Resource; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | /** |
| | | * CRM 销售报价单 Service 实现类 |
| | | * |
| | | * @author 芋道源码 |
| | | * @author 超级管理员 |
| | | */ |
| | | @Service |
| | | @Validated |
| | |
| | | private CrmContactService contactService; |
| | | @Resource |
| | | private CrmPermissionService permissionService; |
| | | @Resource |
| | | private StorageAttachmentApi storageAttachmentApi; |
| | | @Resource |
| | | private CrmContractService contractService; |
| | | |
| | |
| | | .setBizType(CrmBizTypeEnum.CRM_SALE_QUOTATION.getType()) |
| | | .setBizId(saleQuotation.getId()) |
| | | .setLevel(CrmPermissionLevelEnum.OWNER.getLevel())); |
| | | storageAttachmentApi.bindAttachments("file", "crm_sale_quotation", |
| | | saleQuotation.getId(), createReqVO.getBlobIds()); |
| | | return saleQuotation.getId(); |
| | | } |
| | | |
| | |
| | | saleQuotationMapper.updateById(updateObj); |
| | | // 2.2 更新报价明细 |
| | | updateQuotationProductList(updateReqVO.getId(), quotationProducts); |
| | | storageAttachmentApi.updateAttachments("file", "crm_sale_quotation", updateReqVO.getId(), updateReqVO.getBlobIds()); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | // 2. 遍历删除 |
| | | saleQuotations.forEach(saleQuotation -> { |
| | | // 2.0 删除附件关联 |
| | | storageAttachmentApi.deleteAttachmentsByRecord("crm_sale_quotation", saleQuotation.getId()); |
| | | // 2.1 删除报价单 |
| | | saleQuotationMapper.deleteById(saleQuotation.getId()); |
| | | // 2.2 删除报价明细 |
| | |
| | | // 物料原价,如果 MDM 中没有则默认为 0 |
| | | item.setItemPrice(mdmItem.getSalesPrice() != null ? mdmItem.getSalesPrice() : BigDecimal.ZERO); |
| | | if (item.getQuotationPrice() != null && item.getCount() != null) { |
| | | item.setTotalPrice(MoneyUtils.priceMultiply(item.getQuotationPrice(), item.getCount())); |
| | | // 报价为含税单价:含税金额 = 单价 × 数量;税额 = 含税金额 × 税率;不含税金额 = 含税金额 - 税额 |
| | | BigDecimal taxInclusivePrice = MoneyUtils.priceMultiply(item.getQuotationPrice(), item.getCount()); |
| | | BigDecimal taxPrice = null; |
| | | if (item.getTaxPercent() != null) { |
| | | item.setTaxPrice(MoneyUtils.priceMultiplyPercent(item.getTotalPrice(), item.getTaxPercent())); |
| | | taxPrice = MoneyUtils.priceMultiplyPercent(taxInclusivePrice, item.getTaxPercent()); |
| | | } |
| | | item.setTaxPrice(taxPrice); |
| | | item.setTotalPrice(taxPrice != null ? taxInclusivePrice.subtract(taxPrice) : taxInclusivePrice); |
| | | } |
| | | })); |
| | | } |
| | |
| | | return contractId; |
| | | } |
| | | |
| | | @Override |
| | | public CrmSaleQuotationDO getByContractId(Long id) { |
| | | return saleQuotationMapper.selectOne(new LambdaQueryWrapper<CrmSaleQuotationDO>().eq(CrmSaleQuotationDO::getContractId,id)); |
| | | } |
| | | |
| | | @Override |
| | | public void clearContractReference(Long quotationId) { |
| | | saleQuotationMapper.clearContractReference(quotationId); |
| | | } |
| | | |
| | | } |