diff --git a/erp-frontend-vue/src/api/purchaseOrder.ts b/erp-frontend-vue/src/api/purchaseOrder.ts index 8888d50..36fe07a 100644 --- a/erp-frontend-vue/src/api/purchaseOrder.ts +++ b/erp-frontend-vue/src/api/purchaseOrder.ts @@ -173,6 +173,11 @@ export function exportPurchaseOrder(params: PurchaseOrderQuery): Promise { return request.post('/erp/po/order/export', params, { responseType: 'blob' }) } +// 根据采购订单生成到货通知单 +export function genArrivalNotice(orderId: number): Promise { + return request.post(`/erp/po/order/genArrivalNotice/${orderId}`).then((res: any) => res.data) +} + // ============ 供应商 API(使用 MOM md_vendor,表 erp_po_supplier 在 my_mes 中未建) ============ export function getPoSupplierList(params?: { supplierName?: string; contact1?: string; pageNum?: number; pageSize?: number }): Promise<{ rows: PoSupplier[]; total: number }> { diff --git a/erp-frontend-vue/src/views/Purchasing/Order/form.vue b/erp-frontend-vue/src/views/Purchasing/Order/form.vue index 3316fd7..d03ff0a 100644 --- a/erp-frontend-vue/src/views/Purchasing/Order/form.vue +++ b/erp-frontend-vue/src/views/Purchasing/Order/form.vue @@ -28,6 +28,7 @@ 编辑 审核 反审核 + 生成到货通知单 打印 {{ headerCollapsed ? '展开' : '收起' }} @@ -379,6 +380,7 @@ import { approvePurchaseOrder, unapprovePurchaseOrder, genPurchaseOrderCode, + genArrivalNotice, getPoSupplierList, getLeadInList, STATUS_MAP, @@ -817,6 +819,18 @@ async function handleUnapprove() { } } +// ============ Generate arrival notice ============ +async function handleGenArrivalNotice() { + if (!form.orderId) return + try { + await ElMessageBox.confirm('确认根据当前采购订单生成到货通知单吗?', '生成到货通知单', { type: 'info' }) + const noticeId = await genArrivalNotice(form.orderId) + ElMessage.success('到货通知单生成成功') + } catch (error: any) { + if (error !== 'cancel') console.error('生成到货通知单失败:', error) + } +} + // ============ View-mode actions ============ function handleNewFromView() { router.push('/purchasing/order/new') } function handleSwitchToEdit() { diff --git a/mom-backend/ktg-mes/src/main/java/com/ktg/mes/po/controller/PoOrderController.java b/mom-backend/ktg-mes/src/main/java/com/ktg/mes/po/controller/PoOrderController.java index 628a7ef..072e1bf 100644 --- a/mom-backend/ktg-mes/src/main/java/com/ktg/mes/po/controller/PoOrderController.java +++ b/mom-backend/ktg-mes/src/main/java/com/ktg/mes/po/controller/PoOrderController.java @@ -1,5 +1,7 @@ package com.ktg.mes.po.controller; +import java.math.BigDecimal; +import java.util.Date; import java.util.List; import javax.servlet.http.HttpServletResponse; @@ -26,6 +28,11 @@ import com.ktg.mes.po.service.IPoOrderService; import com.ktg.mes.po.service.IPoOrderLineService; import com.ktg.mes.mp.domain.MpPurchase; import com.ktg.mes.mp.mapper.MpPurchaseMapper; +import com.ktg.mes.wm.domain.WmArrivalNotice; +import com.ktg.mes.wm.domain.WmArrivalNoticeLine; +import com.ktg.mes.wm.service.IWmArrivalNoticeService; +import com.ktg.mes.wm.service.IWmArrivalNoticeLineService; +import com.ktg.system.strategy.AutoCodeUtil; import com.ktg.common.utils.poi.ExcelUtil; import com.ktg.common.core.page.TableDataInfo; @@ -48,6 +55,15 @@ public class PoOrderController extends BaseController @Autowired private MpPurchaseMapper mpPurchaseMapper; + @Autowired + private IWmArrivalNoticeService wmArrivalNoticeService; + + @Autowired + private IWmArrivalNoticeLineService wmArrivalNoticeLineService; + + @Autowired + private AutoCodeUtil autoCodeUtil; + /** * 查询采购订单列表(明细视图 - 按行级别,JOIN 订单表头+明细行) */ @@ -264,4 +280,73 @@ public class PoOrderController extends BaseController } return AjaxResult.success("成功反审核 " + count + " 条订单"); } + + /** + * 根据采购订单自动生成到货通知单 + */ + @Log(title = "采购订单", businessType = BusinessType.INSERT) + @Transactional + @PostMapping("/genArrivalNotice/{orderId}") + public AjaxResult genArrivalNotice(@PathVariable Long orderId) + { + // 1. 查询采购订单及明细 + PoOrder order = poOrderService.selectPoOrderByOrderId(orderId); + if (order == null) { + return AjaxResult.error("采购订单不存在!"); + } + if (!UserConstants.ORDER_STATUS_APPROVED.equals(order.getStatus())) { + return AjaxResult.error("只有已审核的采购订单才能生成到货通知单!"); + } + + List lines = poOrderLineService.selectPoOrderLineByOrderId(orderId); + if (CollUtil.isEmpty(lines)) { + return AjaxResult.error("采购订单没有物料明细,无法生成到货通知单!"); + } + + // 过滤出仍有未到货数量的明细行 + List pendingLines = new java.util.ArrayList<>(); + for (PoOrderLine line : lines) { + BigDecimal qty = line.getQuantity() != null ? line.getQuantity() : BigDecimal.ZERO; + BigDecimal arrived = line.getArrivedQuantity() != null ? line.getArrivedQuantity() : BigDecimal.ZERO; + if (qty.subtract(arrived).compareTo(BigDecimal.ZERO) > 0) { + pendingLines.add(line); + } + } + if (pendingLines.isEmpty()) { + return AjaxResult.error("所有物料已全部到货,无需生成到货通知单!"); + } + + // 2. 创建到货通知单表头 + WmArrivalNotice notice = new WmArrivalNotice(); + notice.setNoticeCode(autoCodeUtil.genSerialCode(UserConstants.ARRIVAL_NOTICE_CODE, "")); + notice.setNoticeName("采购订单[" + order.getOrderCode() + "]到货通知单"); + notice.setPoCode(order.getOrderCode()); + notice.setVendorId(order.getSupplierId()); + notice.setVendorCode(order.getSupplierCode()); + notice.setVendorName(order.getSupplierName()); + notice.setArrivalDate(order.getDeliveryDate() != null ? order.getDeliveryDate() : new Date()); + notice.setStatus(UserConstants.ORDER_STATUS_PREPARE); + notice.setCreateBy(getUsername()); + wmArrivalNoticeService.insertWmArrivalNotice(notice); + + // 3. 创建到货通知单明细行 + for (PoOrderLine line : pendingLines) { + WmArrivalNoticeLine noticeLine = new WmArrivalNoticeLine(); + noticeLine.setNoticeId(notice.getNoticeId()); + noticeLine.setItemId(line.getItemId()); + noticeLine.setItemCode(line.getItemCode()); + noticeLine.setItemName(line.getItemName()); + noticeLine.setSpecification(line.getSpecification()); + noticeLine.setUnitOfMeasure(line.getUnitName()); + noticeLine.setUnitName(line.getUnitName()); + BigDecimal qty = line.getQuantity() != null ? line.getQuantity() : BigDecimal.ZERO; + BigDecimal arrived = line.getArrivedQuantity() != null ? line.getArrivedQuantity() : BigDecimal.ZERO; + noticeLine.setQuantityArrival(qty.subtract(arrived)); + noticeLine.setIqcCheck(UserConstants.NO); + noticeLine.setCreateBy(getUsername()); + wmArrivalNoticeLineService.insertWmArrivalNoticeLine(noticeLine); + } + + return AjaxResult.success("到货通知单生成成功", notice.getNoticeId()); + } }