|
|
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.gaotao.modules.boxManage.dao.BoxForNotificationMapper"> <select id="searchSoReceiveBoxesData" resultType="SoReceiveBoxesData"> SELECT s.id, s.site, s.WareHouseID as wareHouseID, s.box_no as boxNo, s.order_no as orderNo, s.status, s.rolls_qty as rollsQty, s.box_type as boxType, s.c_in_stock_flag as cInStockFlag, s.created_date as createdDate, s.created_by as createdBy, s.update_date as updateDate, s.update_by as updateBy, s.version, w.WareHouseName as wareHouseName, s.bu_no, T.box_count as boxCount, T.roll_count as rollCount, T.rollsCount as rollsCount from so_receive_boxes s with(nolock) left join warehouse w with(nolock) on s.WareHouseID = w.WareHouseID and s.site = w.site and s.bu_no = w.bu_no left JOIN ( select a.site, a.bu_no, a.order_no, A.box_no, COUNT(DISTINCT a.box_no) AS box_count, --箱标签张数 COUNT(DISTINCT b.final_roll_no) AS roll_count, --卷标签张数 ISNULL(SUM(roll_qty),0) AS rollsCount --物料总数 from so_receive_boxes a with(nolock) LEFT join so_receive_box_rolls b with(nolock) on a.site = b.site and a.bu_no = b.bu_no and a.box_no = b.box_no WHERE a.SITE = #{site} AND a.bu_no = #{buNo} and a.order_no = #{orderNo} group by a.site, a.bu_no, a.order_no,A.box_no) T ON S.site = T.site AND S.bu_no = T.bu_no AND S.order_no = T.order_no AND T.box_no = S.box_no <where> s.site = #{site} and s.bu_no = #{buNo} <if test="orderNo != null and orderNo != ''"> and s.order_no = #{orderNo} </if> <if test="boxType != null and boxType != ''"> and s.box_type = #{boxType} </if> </where>
</select>
<insert id="newSoReceiveBoxesData" > insert into so_receive_boxes (site,box_no,order_no,[status],rolls_qty,box_type,c_in_stock_flag,created_date,created_by, version,WareHouseID,bu_no) values (#{site},#{boxNo},#{orderNo},#{status},#{rollsQty},#{boxType},'Y',GetDate(),#{createdBy}, 0,#{wareHouseID},#{buNo}) </insert>
<!-- 查询指定订单号下已有的所有箱号,用于断号取号 --> <select id="getExistingBoxNosByOrderNo" resultType="java.lang.String"> SELECT box_no FROM so_receive_boxes WHERE site = #{site} AND bu_no = #{buNo} AND order_no = #{orderNo} ORDER BY box_no </select>
<!-- 查询以指定销售订单号为前缀的所有箱号,用于断号取号 --> <select id="getExistingBoxNosBySaleOrderNo" resultType="java.lang.String"> SELECT box_no FROM so_receive_boxes WHERE site = #{site} AND bu_no = #{buNo} AND box_no LIKE #{saleOrderNo} + '%' ORDER BY box_no </select>
<select id="searchBoxRollDetail" resultType="SoReceiveBoxRollsData"> select ROW_NUMBER() OVER (ORDER BY a.received_date) orderId, a.id,a.site,a.bu_no,a.box_no,a.final_roll_no,a.roll_qty,a.received_by,a.received_date,a.WareHouseID,a.part_no from so_receive_box_rolls a where a.site=#{site} and a.box_no=#{boxNo} and a.bu_no= #{buNo} order by a.received_date desc </select>
<select id="searchBoxData" resultType="SoReceiveBoxesData"> select a.id, a.site, a.bu_no, a.box_no, a.order_no, a.status, a.rolls_qty, a.box_type, a.c_in_stock_flag, a.created_date, a.created_by, a.version, a.WareHouseID, b.std_packing_qty as stdPackingQty from so_receive_boxes a left join outbound_notification_detail b on a.site = b.site and a.bu_no = b.bu_no and a.order_no = b.order_no where a.site= #{site} and a.box_no= #{boxNo} and a.bu_no= #{buNo} </select> <delete id="deleteSoReceiveBoxesData"> delete from so_receive_boxes where id=#{id} </delete> <update id="updateBoxStatus"> update so_receive_boxes set [status]=#{status} where id=#{id} </update> <select id="selectByRollNo" resultType="com.gaotao.modules.inventoryStock.entity.InventoryStock"> SELECT site, bu_no, roll_no, parent_roll_no, parent_roll_type, part_no, warehouse_id, location_id, batch_no, status, qty_on_hand FROM inventory_stock WHERE roll_no = #{rollNo} AND site = #{site} AND bu_no = #{buNo} </select>
<select id="selectByRollNo2" resultType="com.gaotao.modules.inventoryStock.entity.InventoryStock"> SELECT site, bu_no, roll_no, parent_roll_no, parent_roll_type, part_no, warehouse_id, location_id, batch_no, status, qty_on_hand FROM inventory_stock WHERE parent_roll_no = #{rollNo} AND site = #{site} AND bu_no = #{buNo} and status='在库' AND COALESCE(parent_roll_type, '*') NOT IN ('箱标签') </select>
<update id="updateStockParentRollNo"> UPDATE inventory_stock SET ori_parent_roll_no = parent_roll_no, ori_parent_roll_type = parent_roll_type, parent_roll_no = #{parentRollNo}, parent_roll_type = '箱标签' WHERE roll_no = #{rollNo} AND site = #{site} AND bu_no = #{buNo} </update> <insert id="addBoxRoll"> insert into so_receive_box_rolls (site,box_no,final_roll_no,roll_qty,received_by,received_date,WareHouseID,part_no,bu_no) values (#{site},#{boxNo},#{finalRollNo},#{rollQty},#{receivedBy},GetDate(),#{wareHouseID},#{partNo},#{buNo}) </insert>
<update id="updateBoxRollQty"> update so_receive_boxes set rolls_qty =isnull((select count(1) from so_receive_box_rolls where box_no = #{boxNo} and site=#{site} and bu_no= #{buNo}),0) where site = #{site} and box_no = #{boxNo} and bu_no = #{buNo} </update>
<select id="searchOutboundNotificationDetail" resultType="com.gaotao.modules.outboundNotification.entity.OutboundNotificationDetailEntity"> SELECT site, bu_no, order_no, part_no, part_desc, unit, required_qty, out_warehouse, out_batch_no, created_by, created_date, updated_by, updated_date, order_qty, related_order_no, related_order_line_no, inspection_flag FROM outbound_notification_detail where site = #{site} and bu_no = #{buNo} and order_no = #{orderNo} </select>
<select id="getOutboundNotificationDetailByKey" resultType="com.gaotao.modules.outboundNotification.entity.OutboundNotificationDetailEntity"> select site,bu_no,order_no,part_no,part_desc,unit,required_qty,out_warehouse,out_batch_no,created_by,created_date,updated_by, updated_date,order_qty,related_order_no,related_order_line_no,inspection_flag from outbound_notification_detail where site = #{site} and bu_no = #{buNo} and order_no = #{orderNo} and part_no = #{partNo} </select>
<update id="updateBoxWareHouse"> update so_receive_boxes set WareHouseID = #{warehouseId} where site = #{site} and box_no = #{boxNo} and bu_no = #{buNo} </update>
<delete id="deleteBoxRoll"> delete from so_receive_box_rolls where site = #{site} and box_no = #{boxNo} and bu_no = #{buNo} and final_roll_no = #{finalRollNo} </delete>
<select id="searchRollForOrderNo" resultType="SoReceiveBoxRollsData"> select ROW_NUMBER() OVER (ORDER BY b.received_date) orderId, b.id, b.site, b.bu_no, b.box_no, b.final_roll_no, b.roll_qty, b.received_by, b.received_date, b.WareHouseID, b.part_no, c.warehouse_id, c.batch_no, c.location_id from so_receive_boxes a INNER join so_receive_box_rolls b on a.site = b.site and a.box_no = b.box_no and a.bu_no = b.bu_no left join inventory_stock c on b.site = c.site and b.final_roll_no = c.roll_no and b.bu_no = c.bu_no where a.site = #{site} and a.order_no = #{orderNo} and a.bu_no = #{buNo} </select>
<!-- 盒清单相关SQL --> <select id="searchSoReceiveCasesData" resultType="SoReceiveCasesData"> SELECT s.Id as id, s.NotifyNo as notifyNo, s.cases_no as casesNo, s.roll_no as rollNo, s.roll_qty as rollQty, s.part_no as partNo, s.part_desc as partDesc, s.create_date as createDate, s.create_by as createBy, s.Remark as remark, s.site, s.bu_no as buNo, agg.box_count_cases as boxCountCases, agg.box_count_rolls as boxCountRolls, agg.total_qty as totalQty FROM so_receive_cases s WITH(NOLOCK) LEFT JOIN ( SELECT site, NotifyNo, COUNT(DISTINCT cases_no) AS box_count_cases, --盒标签张数 COUNT(DISTINCT roll_no) AS box_count_rolls, --卷标签张数 SUM(roll_qty) AS total_qty --物料总数 FROM so_receive_cases WITH(NOLOCK) WHERE site = #{site} and NotifyNo = #{notifyNo} GROUP BY site, NotifyNo ) as agg ON s.site = agg.site AND s.NotifyNo = agg.NotifyNo <where> s.site = #{site} AND s.bu_no = #{buNo} <if test="notifyNo != null and notifyNo != ''"> AND s.NotifyNo = #{notifyNo} </if> <if test="casesNo != null and casesNo != ''"> AND s.cases_no = #{casesNo} </if> </where> ORDER BY s.create_date DESC </select>
<delete id="deleteSoReceiveCasesData"> DELETE FROM so_receive_cases WHERE Id = #{id} AND site = #{site} AND bu_no = #{buNo} </delete>
<select id="validateCaseRoll" resultType="SoReceiveCasesData"> SELECT #{casesNo} as casesNo, a.roll_no as rollNo, a.qty_on_hand as rollQty, a.part_no as partNo, b.PartDescription as partDesc, a.batch_no as batchNo, a.status, a.parent_roll_type as parentRollType FROM inventory_stock a INNER JOIN part b ON a.site = b.site AND a.part_no = b.PartNo WHERE a.site = #{site} AND a.parent_roll_no = #{rollNo} AND a.part_no = #{partNo} </select>
<insert id="saveSoReceiveCases"> INSERT INTO so_receive_cases ( NotifyNo, cases_no, roll_no, roll_qty, part_no, part_desc, create_date, create_by, Remark, site, bu_no ) VALUES ( #{notifyNo}, #{casesNo}, #{rollNo}, #{rollQty}, #{partNo}, #{partDesc}, GETDATE(), #{createBy}, #{remark}, #{site}, #{buNo} ) </insert>
<update id="updateStockParentRollType"> UPDATE inventory_stock SET ori_parent_roll_no = parent_roll_no, ori_parent_roll_type = parent_roll_type, parent_roll_no = #{parentRollNo}, parent_roll_type = #{parentRollType} WHERE roll_no = #{rollNo} AND site = #{site} AND bu_no = #{buNo} </update>
<!-- 恢复库存的原始上级标签 --> <update id="restoreStockParentRollType"> UPDATE inventory_stock SET parent_roll_no = ori_parent_roll_no, parent_roll_type = ori_parent_roll_type WHERE roll_no = #{rollNo} AND site = #{site} AND bu_no = #{buNo} </update>
<!-- 查询出库通知单主记录(关联明细) --> <select id="searchOutboundNotificationWithDetail" resultType="com.gaotao.modules.outboundNotification.entity.vo.OutboundNotificationHeadVo"> SELECT a.site, a.bu_no as buNo, dbo.get_bu_desc(a.site, a.bu_no) as buDesc, a.order_no as orderNo, a.order_type as orderType, a.order_status as orderStatus, a.customer_id as customerId, c.customerName, c.CustomerAbb as customerAbb,<!-- a.related_order_no as relatedOrderNo,--><!-- a.related_order_line_no as relatedOrderLineNo,--> a.required_outbound_date as requiredOutboundDate, a.remarks, a.erp_order_no as erpOrderNo, a.erp_order_line_no as erpOrderLineNo, a.erp_order_date as erpOrderDate, a.created_by as createdBy, a.created_date as createdDate, a.updated_by as updatedBy, a.updated_date as updatedDate, a.assigned_by as assignedBy, a.assigned_date as assignedDate, a.closed_by as closedBy, a.closed_date as closedDate, a.archived_by as archivedBy, a.archived_date as archivedDate, a.orderref1, a.orderref2, a.orderref3, a.orderref4, a.orderref5, a.order_date as orderDate, a.close_flag as closeFlag, a.out_warehouse as outWarehouse, a.customer_order_no as customerOrderNo, a.show_in_query_flag as showInQueryFlag, <!-- 关联明细信息 --> b.part_no as partNo, b.part_desc as partDesc, b.unit, b.required_qty as requiredQty, b.out_warehouse as detailOutWarehouse, b.out_batch_no as outBatchNo, b.order_qty as orderQty, b.related_order_no as relatedOrderNo, b.related_order_line_no as relatedOrderLineNo, <!-- 已扫描数量和未扫描数量 --> ISNULL(SUM(e.roll_qty), 0) as rollQty, CASE WHEN b.required_qty - ISNULL(SUM(e.roll_qty), 0) > 0 THEN ROUND(b.required_qty - ISNULL(SUM(e.roll_qty), 0), 3) ELSE 0 END as unScanQty , ISNULL(SUM(i.qty_on_hand), 0) as availableStock, b.std_packing_qty, ISNULL(b.inspection_flag,'N') as inspectionFlag FROM outbound_notification_head a LEFT JOIN Customer c ON a.site = c.site AND a.customer_id = c.CustomerID LEFT JOIN outbound_notification_detail b ON a.site = b.site AND a.bu_no = b.bu_no AND a.order_no = b.order_no LEFT JOIN inventory_stock I ON B.site = I.site AND B.part_no = I.part_no AND I.status = '在库' and i.batch_no = b.out_batch_no LEFT JOIN so_receive_boxes d ON b.site = d.site AND b.bu_no = d.bu_no AND b.order_no = d.order_no LEFT JOIN so_receive_box_rolls e ON b.site = e.site AND b.bu_no = e.bu_no AND d.box_no = e.box_no AND b.part_no = e.part_no <where> <if test="site != null and site != ''"> AND a.site = #{site} </if> <if test="buNo != null and buNo != ''"> AND a.bu_no = #{buNo} </if> <if test="orderNo != null and orderNo != ''"> AND a.order_no LIKE '%' + #{orderNo} + '%' </if> <if test="orderType != null and orderType != ''"> AND a.order_type = #{orderType} </if> <if test="orderStatus != null and orderStatus != ''"> AND a.order_status in <foreach collection="statusArr" close=")" open="(" item="item" separator=","> #{item} </foreach> </if> <if test="orderStatus == null or orderStatus == ''"> AND a.order_status not in ('待出库', '草稿') </if> <if test="customerId != null and customerId != ''"> AND a.customer_id LIKE '%' + #{customerId} + '%' </if> <if test="customerName != null and customerName != ''"> AND c.customerName LIKE '%' + #{customerName} + '%' </if> <if test="inspectionFlag != null and inspectionFlag != ''"> AND ISNULL(b.inspection_flag,'N') = #{inspectionFlag} </if> <if test="startDate != null"> AND a.required_outbound_date >= #{startDate} </if> <if test="endDate != null"> AND #{endDate} >= a.required_outbound_date </if> </where> GROUP BY a.site, a.bu_no, a.order_no, a.order_type, a.order_status, a.customer_id, c.customerName, a.related_order_no, a.related_order_line_no, a.required_outbound_date, a.remarks, a.erp_order_no, a.erp_order_line_no, a.erp_order_date, a.created_by, a.created_date, a.updated_by, a.updated_date, a.assigned_by, a.assigned_date, a.closed_by, a.closed_date, a.archived_by, a.archived_date, a.orderref1, a.orderref2, a.orderref3, a.orderref4, a.orderref5, a.order_date, a.close_flag, a.out_warehouse, a.customer_order_no, a.show_in_query_flag, b.part_no, b.part_desc, b.unit, b.required_qty, b.out_warehouse, b.out_batch_no, b.order_qty, b.related_order_no, b.related_order_line_no, b.std_packing_qty, b.inspection_flag, c.CustomerAbb ORDER BY a.created_date DESC, b.part_no </select>
<!-- 分页查询出库通知单主记录(关联明细) --> <select id="searchOutboundNotificationWithDetailByPage" resultType="com.gaotao.modules.outboundNotification.entity.vo.OutboundNotificationHeadVo"> SELECT a.site, a.bu_no as buNo, dbo.get_bu_desc(a.site, a.bu_no) as buDesc, a.order_no as orderNo, a.order_type as orderType, a.order_status as orderStatus, a.customer_id as customerId, c.customerName, c.CustomerAbb as customerAbb, a.required_outbound_date as requiredOutboundDate, a.remarks, a.erp_order_no as erpOrderNo, a.erp_order_line_no as erpOrderLineNo, a.erp_order_date as erpOrderDate, a.created_by as createdBy, a.created_date as createdDate, a.updated_by as updatedBy, a.updated_date as updatedDate, a.assigned_by as assignedBy, a.assigned_date as assignedDate, a.closed_by as closedBy, a.closed_date as closedDate, a.archived_by as archivedBy, a.archived_date as archivedDate, a.orderref1, a.orderref2, a.orderref3, a.orderref4, a.orderref5, a.order_date as orderDate, a.close_flag as closeFlag, a.out_warehouse as outWarehouse, a.customer_order_no as customerOrderNo, a.show_in_query_flag as showInQueryFlag, b.part_no as partNo, b.part_desc as partDesc, b.unit, b.required_qty as requiredQty, b.out_warehouse as detailOutWarehouse, b.out_batch_no as outBatchNo, b.order_qty as orderQty, b.related_order_no as relatedOrderNo, b.related_order_line_no as relatedOrderLineNo, ISNULL(SUM(e.roll_qty), 0) as rollQty, CASE WHEN b.required_qty - ISNULL(SUM(e.roll_qty), 0) > 0 THEN ROUND(b.required_qty - ISNULL(SUM(e.roll_qty), 0), 3) ELSE 0 END as unScanQty, ISNULL(SUM(i.qty_on_hand), 0) as availableStock, b.std_packing_qty, ISNULL(b.inspection_flag,'N') as inspectionFlag FROM outbound_notification_head a LEFT JOIN Customer c ON a.site = c.site AND a.customer_id = c.CustomerID LEFT JOIN outbound_notification_detail b ON a.site = b.site AND a.bu_no = b.bu_no AND a.order_no = b.order_no LEFT JOIN inventory_stock I ON B.site = I.site AND B.part_no = I.part_no AND I.status = '在库' and i.batch_no = b.out_batch_no LEFT JOIN so_receive_boxes d ON b.site = d.site AND b.bu_no = d.bu_no AND b.order_no = d.order_no LEFT JOIN so_receive_box_rolls e ON b.site = e.site AND b.bu_no = e.bu_no AND d.box_no = e.box_no AND b.part_no = e.part_no <where> <if test="query.site != null and query.site != ''"> AND a.site = #{query.site} </if> <if test="query.buNo != null and query.buNo != ''"> AND a.bu_no = #{query.buNo} </if> <if test="query.orderNo != null and query.orderNo != ''"> AND a.order_no LIKE '%' + #{query.orderNo} + '%' </if> <if test="query.orderType != null and query.orderType != ''"> AND a.order_type = #{query.orderType} </if> <if test="query.orderStatus != null and query.orderStatus != ''"> AND a.order_status in <foreach collection="query.statusArr" close=")" open="(" item="item" separator=","> #{item} </foreach> </if> <if test="query.orderStatus == null or query.orderStatus == ''"> AND a.order_status not in ('待出库', '草稿') </if> <if test="query.customerId != null and query.customerId != ''"> AND a.customer_id LIKE '%' + #{query.customerId} + '%' </if> <if test="query.customerName != null and query.customerName != ''"> AND c.customerName LIKE '%' + #{query.customerName} + '%' </if> <if test="query.inspectionFlag != null and query.inspectionFlag != ''"> AND ISNULL(b.inspection_flag,'N') = #{query.inspectionFlag} </if> <if test="query.startDate != null"> AND a.required_outbound_date >= #{query.startDate} </if> <if test="query.endDate != null"> AND #{query.endDate} >= a.required_outbound_date </if> </where> GROUP BY a.site, a.bu_no, a.order_no, a.order_type, a.order_status, a.customer_id, c.customerName, a.related_order_no, a.related_order_line_no, a.required_outbound_date, a.remarks, a.erp_order_no, a.erp_order_line_no, a.erp_order_date, a.created_by, a.created_date, a.updated_by, a.updated_date, a.assigned_by, a.assigned_date, a.closed_by, a.closed_date, a.archived_by, a.archived_date, a.orderref1, a.orderref2, a.orderref3, a.orderref4, a.orderref5, a.order_date, a.close_flag, a.out_warehouse, a.customer_order_no, a.show_in_query_flag, b.part_no, b.part_desc, b.unit, b.required_qty, b.out_warehouse, b.out_batch_no, b.order_qty, b.related_order_no, b.related_order_line_no, b.std_packing_qty, b.inspection_flag, c.CustomerAbb ORDER BY a.required_outbound_date DESC, b.part_no OFFSET #{query.offset} ROWS FETCH NEXT #{query.limit} ROWS ONLY </select>
<!-- 分页查询出库通知单主记录(关联明细)- 总数查询 --> <select id="searchOutboundNotificationWithDetailCount" resultType="int"> SELECT COUNT(1) FROM ( SELECT a.order_no, b.part_no FROM outbound_notification_head a LEFT JOIN Customer c ON a.site = c.site AND a.customer_id = c.CustomerID LEFT JOIN outbound_notification_detail b ON a.site = b.site AND a.bu_no = b.bu_no AND a.order_no = b.order_no LEFT JOIN inventory_stock I ON B.site = I.site AND B.part_no = I.part_no AND I.status = '在库' and i.batch_no = b.out_batch_no LEFT JOIN so_receive_boxes d ON b.site = d.site AND b.bu_no = d.bu_no AND b.order_no = d.order_no LEFT JOIN so_receive_box_rolls e ON b.site = e.site AND b.bu_no = e.bu_no AND d.box_no = e.box_no AND b.part_no = e.part_no <where> <if test="query.site != null and query.site != ''"> AND a.site = #{query.site} </if> <if test="query.buNo != null and query.buNo != ''"> AND a.bu_no = #{query.buNo} </if> <if test="query.orderNo != null and query.orderNo != ''"> AND a.order_no LIKE '%' + #{query.orderNo} + '%' </if> <if test="query.orderType != null and query.orderType != ''"> AND a.order_type = #{query.orderType} </if> <if test="query.orderStatus != null and query.orderStatus != ''"> AND a.order_status in <foreach collection="query.statusArr" close=")" open="(" item="item" separator=","> #{item} </foreach> </if> <if test="query.orderStatus == null or query.orderStatus == ''"> AND a.order_status not in ('待出库', '草稿') </if> <if test="query.customerId != null and query.customerId != ''"> AND a.customer_id LIKE '%' + #{query.customerId} + '%' </if> <if test="query.customerName != null and query.customerName != ''"> AND c.customerName LIKE '%' + #{query.customerName} + '%' </if> <if test="query.inspectionFlag != null and query.inspectionFlag != ''"> AND ISNULL(b.inspection_flag,'N') = #{query.inspectionFlag} </if> <if test="query.startDate != null"> AND a.required_outbound_date >= #{query.startDate} </if> <if test="query.endDate != null"> AND #{query.endDate} >= a.required_outbound_date </if> </where> GROUP BY a.site, a.bu_no, a.order_no, a.order_type, a.order_status, a.customer_id, c.customerName, a.related_order_no, a.related_order_line_no, a.required_outbound_date, a.remarks, a.erp_order_no, a.erp_order_line_no, a.erp_order_date, a.created_by, a.created_date, a.updated_by, a.updated_date, a.assigned_by, a.assigned_date, a.closed_by, a.closed_date, a.archived_by, a.archived_date, a.orderref1, a.orderref2, a.orderref3, a.orderref4, a.orderref5, a.order_date, a.close_flag, a.out_warehouse, a.customer_order_no, a.show_in_query_flag, b.part_no, b.part_desc, b.unit, b.required_qty, b.out_warehouse, b.out_batch_no, b.order_qty, b.related_order_no, b.related_order_line_no, b.std_packing_qty, b.inspection_flag, c.CustomerAbb ) T </select>
<!-- 更新出库通知单状态 --> <update id="updateOrderStatus"> UPDATE outbound_notification_head SET order_status = #{orderStatus} WHERE site = #{site} AND bu_no = #{buNo} AND order_no = #{orderNo} </update>
<!-- ==================== 托清单相关SQL ==================== --> <!-- 查询托清单列表 --> <select id="searchSoReceivePalletsData" resultType="SoReceivePalletsData"> SELECT s.id, s.site, s.bu_no as buNo, s.pallet_no as palletNo, s.order_no as orderNo, s.status, s.boxes_qty as boxesQty, s.pallet_type as palletType, s.c_in_stock_flag as cInStockFlag, s.created_date as createdDate, s.created_by as createdBy, s.update_date as updateDate, s.update_by as updateBy, s.version, ISNULL(pallet_count, 0) as palletCount, ISNULL(boxesCount, 0) as boxesCount, ISNULL(rollCount, 0) as rollCount, ISNULL(rollsQty, 0) as rollsQty FROM so_receive_pallets s with(nolock) LEFT JOIN ( select a.site, a.bu_no, a.order_no, COUNT(DISTINCT a.pallet_no) AS pallet_count, -- 托数量 COUNT(DISTINCT B.box_no) AS boxesCount, -- 箱标签张数 COUNT(DISTINCT c.final_roll_no) AS rollCount, -- 卷标签张数 ISNULL(SUM(c.roll_qty), 0) AS rollsQty -- 物料总数 from so_receive_pallets A with(nolock) INNER JOIN so_receive_pallet_boxes B with(nolock) ON A.site = B.site AND A.pallet_no = B.pallet_no INNER JOIN so_receive_box_rolls C with(nolock) ON C.site = B.site AND B.box_no = C.box_no WHERE a.SITE = #{site} AND a.bu_no = #{buNo} and a.order_no = #{orderNo} group by a.site, a.bu_no, a.order_no ) T ON S.site = T.site AND S.bu_no = T.bu_no AND S.order_no = T.order_no WHERE s.site = #{site} AND s.bu_no = #{buNo} AND s.order_no = #{orderNo} ORDER BY s.created_date DESC </select>
<!-- 新增托 --> <insert id="newSoReceivePalletsData"> INSERT INTO so_receive_pallets (site, pallet_no, order_no, [status], boxes_qty, pallet_type, c_in_stock_flag, created_date, created_by, version, bu_no) VALUES (#{site}, #{palletNo}, #{orderNo}, #{status}, #{boxesQty}, #{palletType}, 'Y', GETDATE(), #{createdBy}, 0, #{buNo}) </insert>
<!-- 查询托明细列表 --> <select id="searchPalletBoxDetail" resultType="SoReceivePalletBoxesData"> SELECT ROW_NUMBER() OVER (ORDER BY a.received_date) orderId, a.id, a.site, a.bu_no, a.pallet_no, a.box_no, a.boxes_qty, a.received_by, a.received_date FROM so_receive_pallet_boxes a WHERE a.site = #{site} AND a.pallet_no = #{palletNo} AND a.bu_no = #{buNo} ORDER BY a.received_date DESC </select>
<!-- 查询托数据 --> <select id="searchPalletData" resultType="SoReceivePalletsData"> SELECT a.id, a.site, a.bu_no, a.pallet_no, a.order_no, [status], boxes_qty, pallet_type, c_in_stock_flag, created_date, created_by, version FROM so_receive_pallets a WHERE a.site = #{site} AND a.pallet_no = #{palletNo} AND a.bu_no = #{buNo} </select>
<!-- 删除托 --> <delete id="deleteSoReceivePalletsData"> DELETE FROM so_receive_pallets WHERE id = #{id} </delete>
<!-- 更新托状态 --> <update id="updatePalletStatus"> UPDATE so_receive_pallets SET [status] = #{status} WHERE id = #{id} </update>
<!-- 根据箱号查询箱信息(用于装托扫描) --> <select id="selectBoxByBoxNo" resultType="SoReceiveBoxesData"> SELECT a.id, a.site, a.bu_no, a.box_no as boxNo, a.order_no as orderNo, a.[status], a.rolls_qty as rollsQty, a.box_type as boxType, a.WareHouseID as wareHouseID FROM so_receive_boxes a WHERE a.site = #{site} AND a.box_no = #{boxNo} AND a.bu_no = #{buNo} </select>
<!-- 装托:添加箱到托 --> <insert id="addBoxToPallet"> INSERT INTO so_receive_pallet_boxes (site, bu_no, pallet_no, box_no, boxes_qty, received_by, received_date) VALUES (#{site}, #{buNo}, #{palletNo}, #{boxNo}, #{boxesQty}, #{receivedBy}, GETDATE()) </insert>
<!-- 拆托:从托中删除箱 --> <delete id="deleteBoxFromPallet"> DELETE FROM so_receive_pallet_boxes WHERE site = #{site} AND bu_no = #{buNo} AND pallet_no = #{palletNo} <if test="boxNo != null and boxNo != ''"> AND box_no = #{boxNo} </if> </delete>
<!-- 更新托的箱数量 --> <update id="updatePalletBoxesQty"> UPDATE so_receive_pallets SET boxes_qty = ( SELECT COUNT(*) FROM so_receive_pallet_boxes WHERE site = #{site} AND bu_no = #{buNo} AND pallet_no = #{palletNo} ) WHERE site = #{site} AND bu_no = #{buNo} AND pallet_no = #{palletNo} </update>
<!-- 检查箱是否在托中 --> <select id="checkBoxInPallet" resultType="SoReceivePalletBoxesData"> SELECT id, site, bu_no, pallet_no, box_no, boxes_qty, received_by, received_date FROM so_receive_pallet_boxes WHERE site = #{site} AND bu_no = #{buNo} AND box_no = #{boxNo} </select>
<!-- 检查卷是否已装箱 --> <select id="checkRollInBox" resultType="SoReceiveBoxRollsData"> SELECT id, site, bu_no, box_no, final_roll_no, roll_qty, received_by, received_date, WareHouseID, part_no FROM so_receive_box_rolls WHERE site = #{site} AND bu_no = #{buNo} AND final_roll_no = #{rollNo} </select>
<!-- 查询装箱明细列表(关联仓库和物料信息) --> <select id="searchBoxRollDetailList" resultType="map"> SELECT br.box_no AS boxNo, br.final_roll_no AS finalRollNo, br.roll_qty AS rollQty, br.received_by AS receivedBy, br.received_date AS receivedDate, br.WareHouseID AS wareHouseId, wh.WareHouseName AS wareHouseName, br.part_no AS partNo, p.PartDescription AS partDesc FROM so_receive_box_rolls br LEFT JOIN WareHouse wh ON br.site = wh.site and br.WareHouseID = wh.WareHouseID LEFT JOIN Part p ON br.site = p.site and br.part_no = p.partNo WHERE br.site = #{site} AND br.bu_no = #{buNo} AND br.box_no = #{boxNo} ORDER BY br.received_date DESC </select></mapper>
|