You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

832 lines
34 KiB

4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.gaotao.modules.boxManage.dao.BoxForNotificationMapper">
  4. <select id="searchSoReceiveBoxesData" resultType="SoReceiveBoxesData">
  5. SELECT
  6. s.id,
  7. s.site,
  8. s.WareHouseID as wareHouseID,
  9. s.box_no as boxNo,
  10. s.order_no as orderNo,
  11. s.status,
  12. s.rolls_qty as rollsQty,
  13. s.box_type as boxType,
  14. s.c_in_stock_flag as cInStockFlag,
  15. s.created_date as createdDate,
  16. s.created_by as createdBy,
  17. s.update_date as updateDate,
  18. s.update_by as updateBy,
  19. s.version,
  20. w.WareHouseName as wareHouseName,
  21. s.bu_no,
  22. T.box_count as boxCount,
  23. T.roll_count as rollCount,
  24. T.rollsCount as rollsCount
  25. from so_receive_boxes s with(nolock)
  26. left join warehouse w with(nolock) on s.WareHouseID = w.WareHouseID and s.site = w.site and s.bu_no = w.bu_no
  27. left JOIN (
  28. select
  29. a.site,
  30. a.bu_no,
  31. a.order_no,
  32. A.box_no,
  33. COUNT(DISTINCT a.box_no) AS box_count, --箱标签张数
  34. COUNT(DISTINCT b.final_roll_no) AS roll_count, --卷标签张数
  35. ISNULL(SUM(roll_qty),0) AS rollsCount --物料总数
  36. from so_receive_boxes a with(nolock)
  37. 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
  38. WHERE a.SITE = #{site} AND a.bu_no = #{buNo} and a.order_no = #{orderNo}
  39. 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
  40. <where>
  41. s.site = #{site} and s.bu_no = #{buNo}
  42. <if test="orderNo != null and orderNo != ''">
  43. and s.order_no = #{orderNo}
  44. </if>
  45. <if test="boxType != null and boxType != ''">
  46. and s.box_type = #{boxType}
  47. </if>
  48. </where>
  49. </select>
  50. <insert id="newSoReceiveBoxesData" >
  51. insert into so_receive_boxes
  52. (site,box_no,order_no,[status],rolls_qty,box_type,c_in_stock_flag,created_date,created_by,
  53. version,WareHouseID,bu_no) values
  54. (#{site},#{boxNo},#{orderNo},#{status},#{rollsQty},#{boxType},'Y',GetDate(),#{createdBy},
  55. 0,#{wareHouseID},#{buNo})
  56. </insert>
  57. <!-- 查询指定订单号下已有的所有箱号,用于断号取号 -->
  58. <select id="getExistingBoxNosByOrderNo" resultType="java.lang.String">
  59. SELECT box_no
  60. FROM so_receive_boxes
  61. WHERE site = #{site}
  62. AND bu_no = #{buNo}
  63. AND order_no = #{orderNo}
  64. ORDER BY box_no
  65. </select>
  66. <!-- 查询以指定销售订单号为前缀的所有箱号,用于断号取号 -->
  67. <select id="getExistingBoxNosBySaleOrderNo" resultType="java.lang.String">
  68. SELECT box_no
  69. FROM so_receive_boxes
  70. WHERE site = #{site}
  71. AND bu_no = #{buNo}
  72. AND box_no LIKE #{saleOrderNo} + '%'
  73. ORDER BY box_no
  74. </select>
  75. <select id="searchBoxRollDetail" resultType="SoReceiveBoxRollsData">
  76. 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
  77. from so_receive_box_rolls a
  78. where a.site=#{site} and a.box_no=#{boxNo} and a.bu_no= #{buNo}
  79. order by a.received_date desc
  80. </select>
  81. <select id="searchBoxData" resultType="SoReceiveBoxesData">
  82. select
  83. a.id,
  84. a.site,
  85. a.bu_no,
  86. a.box_no,
  87. a.order_no,
  88. a.status,
  89. a.rolls_qty,
  90. a.box_type,
  91. a.c_in_stock_flag,
  92. a.created_date,
  93. a.created_by,
  94. a.version,
  95. a.WareHouseID,
  96. b.std_packing_qty as stdPackingQty
  97. from so_receive_boxes a
  98. 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
  99. where a.site= #{site} and a.box_no= #{boxNo} and a.bu_no= #{buNo}
  100. </select>
  101. <delete id="deleteSoReceiveBoxesData">
  102. delete from so_receive_boxes
  103. where id=#{id}
  104. </delete>
  105. <update id="updateBoxStatus">
  106. update so_receive_boxes
  107. set [status]=#{status}
  108. where id=#{id}
  109. </update>
  110. <select id="selectByRollNo" resultType="com.gaotao.modules.inventoryStock.entity.InventoryStock">
  111. SELECT
  112. site,
  113. bu_no,
  114. roll_no,
  115. parent_roll_no,
  116. parent_roll_type,
  117. part_no,
  118. warehouse_id,
  119. location_id,
  120. batch_no,
  121. status,
  122. qty_on_hand
  123. FROM inventory_stock
  124. WHERE roll_no = #{rollNo}
  125. AND site = #{site}
  126. AND bu_no = #{buNo}
  127. </select>
  128. <select id="selectByRollNo2" resultType="com.gaotao.modules.inventoryStock.entity.InventoryStock">
  129. SELECT
  130. site,
  131. bu_no,
  132. roll_no,
  133. parent_roll_no,
  134. parent_roll_type,
  135. part_no,
  136. warehouse_id,
  137. location_id,
  138. batch_no,
  139. status,
  140. qty_on_hand
  141. FROM inventory_stock
  142. WHERE parent_roll_no = #{rollNo}
  143. AND site = #{site}
  144. AND bu_no = #{buNo}
  145. and status='在库' AND COALESCE(parent_roll_type, '*') NOT IN ('箱标签')
  146. </select>
  147. <update id="updateStockParentRollNo">
  148. UPDATE inventory_stock
  149. SET ori_parent_roll_no = parent_roll_no,
  150. ori_parent_roll_type = parent_roll_type,
  151. parent_roll_no = #{parentRollNo},
  152. parent_roll_type = '箱标签'
  153. WHERE roll_no = #{rollNo}
  154. AND site = #{site}
  155. AND bu_no = #{buNo}
  156. </update>
  157. <insert id="addBoxRoll">
  158. insert into so_receive_box_rolls
  159. (site,box_no,final_roll_no,roll_qty,received_by,received_date,WareHouseID,part_no,bu_no)
  160. values
  161. (#{site},#{boxNo},#{finalRollNo},#{rollQty},#{receivedBy},GetDate(),#{wareHouseID},#{partNo},#{buNo})
  162. </insert>
  163. <update id="updateBoxRollQty">
  164. update so_receive_boxes
  165. set rolls_qty =isnull((select count(1) from so_receive_box_rolls where box_no = #{boxNo} and site=#{site} and bu_no= #{buNo}),0)
  166. where site = #{site}
  167. and box_no = #{boxNo}
  168. and bu_no = #{buNo}
  169. </update>
  170. <select id="searchOutboundNotificationDetail" resultType="com.gaotao.modules.outboundNotification.entity.OutboundNotificationDetailEntity">
  171. SELECT
  172. site,
  173. bu_no,
  174. order_no,
  175. part_no,
  176. part_desc,
  177. unit,
  178. required_qty,
  179. out_warehouse,
  180. out_batch_no,
  181. created_by,
  182. created_date,
  183. updated_by,
  184. updated_date,
  185. order_qty,
  186. related_order_no,
  187. related_order_line_no,
  188. inspection_flag
  189. FROM outbound_notification_detail
  190. where site = #{site} and bu_no = #{buNo} and order_no = #{orderNo}
  191. </select>
  192. <select id="getOutboundNotificationDetailByKey" resultType="com.gaotao.modules.outboundNotification.entity.OutboundNotificationDetailEntity">
  193. select site,bu_no,order_no,part_no,part_desc,unit,required_qty,out_warehouse,out_batch_no,created_by,created_date,updated_by,
  194. updated_date,order_qty,related_order_no,related_order_line_no,inspection_flag
  195. from outbound_notification_detail
  196. where site = #{site} and bu_no = #{buNo} and order_no = #{orderNo} and part_no = #{partNo}
  197. </select>
  198. <update id="updateBoxWareHouse">
  199. update so_receive_boxes
  200. set WareHouseID = #{warehouseId}
  201. where site = #{site}
  202. and box_no = #{boxNo}
  203. and bu_no = #{buNo}
  204. </update>
  205. <delete id="deleteBoxRoll">
  206. delete from so_receive_box_rolls
  207. where site = #{site}
  208. and box_no = #{boxNo}
  209. and bu_no = #{buNo}
  210. and final_roll_no = #{finalRollNo}
  211. </delete>
  212. <select id="searchRollForOrderNo" resultType="SoReceiveBoxRollsData">
  213. select
  214. ROW_NUMBER() OVER (ORDER BY b.received_date) orderId,
  215. b.id,
  216. b.site,
  217. b.bu_no,
  218. b.box_no,
  219. b.final_roll_no,
  220. b.roll_qty,
  221. b.received_by,
  222. b.received_date,
  223. b.WareHouseID,
  224. b.part_no,
  225. c.warehouse_id,
  226. c.batch_no,
  227. c.location_id
  228. from so_receive_boxes a
  229. 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
  230. 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
  231. where a.site = #{site} and a.order_no = #{orderNo} and a.bu_no = #{buNo}
  232. </select>
  233. <!-- 盒清单相关SQL -->
  234. <select id="searchSoReceiveCasesData" resultType="SoReceiveCasesData">
  235. SELECT
  236. s.Id as id,
  237. s.NotifyNo as notifyNo,
  238. s.cases_no as casesNo,
  239. s.roll_no as rollNo,
  240. s.roll_qty as rollQty,
  241. s.part_no as partNo,
  242. s.part_desc as partDesc,
  243. s.create_date as createDate,
  244. s.create_by as createBy,
  245. s.Remark as remark,
  246. s.site,
  247. s.bu_no as buNo,
  248. agg.box_count_cases as boxCountCases,
  249. agg.box_count_rolls as boxCountRolls,
  250. agg.total_qty as totalQty
  251. FROM so_receive_cases s WITH(NOLOCK)
  252. LEFT JOIN (
  253. SELECT
  254. site,
  255. NotifyNo,
  256. COUNT(DISTINCT cases_no) AS box_count_cases, --盒标签张数
  257. COUNT(DISTINCT roll_no) AS box_count_rolls, --卷标签张数
  258. SUM(roll_qty) AS total_qty --物料总数
  259. FROM so_receive_cases WITH(NOLOCK)
  260. WHERE site = #{site} and NotifyNo = #{notifyNo}
  261. GROUP BY site, NotifyNo
  262. ) as agg ON s.site = agg.site AND s.NotifyNo = agg.NotifyNo
  263. <where>
  264. s.site = #{site} AND s.bu_no = #{buNo}
  265. <if test="notifyNo != null and notifyNo != ''">
  266. AND s.NotifyNo = #{notifyNo}
  267. </if>
  268. <if test="casesNo != null and casesNo != ''">
  269. AND s.cases_no = #{casesNo}
  270. </if>
  271. </where>
  272. ORDER BY s.create_date DESC
  273. </select>
  274. <delete id="deleteSoReceiveCasesData">
  275. DELETE FROM so_receive_cases
  276. WHERE Id = #{id}
  277. AND site = #{site}
  278. AND bu_no = #{buNo}
  279. </delete>
  280. <select id="validateCaseRoll" resultType="SoReceiveCasesData">
  281. SELECT
  282. #{casesNo} as casesNo,
  283. a.roll_no as rollNo,
  284. a.qty_on_hand as rollQty,
  285. a.part_no as partNo,
  286. b.PartDescription as partDesc,
  287. a.batch_no as batchNo,
  288. a.status,
  289. a.parent_roll_type as parentRollType
  290. FROM
  291. inventory_stock a
  292. INNER JOIN part b ON a.site = b.site
  293. AND a.part_no = b.PartNo
  294. WHERE
  295. a.site = #{site}
  296. AND a.parent_roll_no = #{rollNo}
  297. AND a.part_no = #{partNo}
  298. </select>
  299. <insert id="saveSoReceiveCases">
  300. INSERT INTO so_receive_cases (
  301. NotifyNo,
  302. cases_no,
  303. roll_no,
  304. roll_qty,
  305. part_no,
  306. part_desc,
  307. create_date,
  308. create_by,
  309. Remark,
  310. site,
  311. bu_no
  312. ) VALUES (
  313. #{notifyNo},
  314. #{casesNo},
  315. #{rollNo},
  316. #{rollQty},
  317. #{partNo},
  318. #{partDesc},
  319. GETDATE(),
  320. #{createBy},
  321. #{remark},
  322. #{site},
  323. #{buNo}
  324. )
  325. </insert>
  326. <update id="updateStockParentRollType">
  327. UPDATE inventory_stock
  328. SET ori_parent_roll_no = parent_roll_no,
  329. ori_parent_roll_type = parent_roll_type,
  330. parent_roll_no = #{parentRollNo},
  331. parent_roll_type = #{parentRollType}
  332. WHERE roll_no = #{rollNo}
  333. AND site = #{site}
  334. AND bu_no = #{buNo}
  335. </update>
  336. <!-- 恢复库存的原始上级标签 -->
  337. <update id="restoreStockParentRollType">
  338. UPDATE inventory_stock
  339. SET parent_roll_no = ori_parent_roll_no,
  340. parent_roll_type = ori_parent_roll_type
  341. WHERE roll_no = #{rollNo}
  342. AND site = #{site}
  343. AND bu_no = #{buNo}
  344. </update>
  345. <!-- 查询出库通知单主记录(关联明细) -->
  346. <select id="searchOutboundNotificationWithDetail" resultType="com.gaotao.modules.outboundNotification.entity.vo.OutboundNotificationHeadVo">
  347. SELECT
  348. a.site,
  349. a.bu_no as buNo,
  350. dbo.get_bu_desc(a.site, a.bu_no) as buDesc,
  351. a.order_no as orderNo,
  352. a.order_type as orderType,
  353. a.order_status as orderStatus,
  354. a.customer_id as customerId,
  355. c.customerName,
  356. c.CustomerAbb as customerAbb,
  357. <!-- a.related_order_no as relatedOrderNo,-->
  358. <!-- a.related_order_line_no as relatedOrderLineNo,-->
  359. a.required_outbound_date as requiredOutboundDate,
  360. a.remarks,
  361. a.erp_order_no as erpOrderNo,
  362. a.erp_order_line_no as erpOrderLineNo,
  363. a.erp_order_date as erpOrderDate,
  364. a.created_by as createdBy,
  365. a.created_date as createdDate,
  366. a.updated_by as updatedBy,
  367. a.updated_date as updatedDate,
  368. a.assigned_by as assignedBy,
  369. a.assigned_date as assignedDate,
  370. a.closed_by as closedBy,
  371. a.closed_date as closedDate,
  372. a.archived_by as archivedBy,
  373. a.archived_date as archivedDate,
  374. a.orderref1,
  375. a.orderref2,
  376. a.orderref3,
  377. a.orderref4,
  378. a.orderref5,
  379. a.order_date as orderDate,
  380. a.close_flag as closeFlag,
  381. a.out_warehouse as outWarehouse,
  382. a.customer_order_no as customerOrderNo,
  383. a.show_in_query_flag as showInQueryFlag,
  384. <!-- 关联明细信息 -->
  385. b.part_no as partNo,
  386. b.part_desc as partDesc,
  387. b.unit,
  388. b.required_qty as requiredQty,
  389. b.out_warehouse as detailOutWarehouse,
  390. b.out_batch_no as outBatchNo,
  391. b.order_qty as orderQty,
  392. b.related_order_no as relatedOrderNo,
  393. b.related_order_line_no as relatedOrderLineNo,
  394. <!-- 已扫描数量和未扫描数量 -->
  395. ISNULL(SUM(e.roll_qty), 0) as rollQty,
  396. CASE WHEN b.required_qty - ISNULL(SUM(e.roll_qty), 0) > 0
  397. THEN ROUND(b.required_qty - ISNULL(SUM(e.roll_qty), 0), 3)
  398. ELSE 0
  399. END as unScanQty ,
  400. ISNULL(SUM(i.qty_on_hand), 0) as availableStock,
  401. b.std_packing_qty,
  402. ISNULL(b.inspection_flag,'N') as inspectionFlag
  403. FROM outbound_notification_head a
  404. LEFT JOIN Customer c ON a.site = c.site AND a.customer_id = c.CustomerID
  405. 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
  406. 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
  407. 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
  408. 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
  409. <where>
  410. <if test="site != null and site != ''">
  411. AND a.site = #{site}
  412. </if>
  413. <if test="buNo != null and buNo != ''">
  414. AND a.bu_no = #{buNo}
  415. </if>
  416. <if test="orderNo != null and orderNo != ''">
  417. AND a.order_no LIKE '%' + #{orderNo} + '%'
  418. </if>
  419. <if test="orderType != null and orderType != ''">
  420. AND a.order_type = #{orderType}
  421. </if>
  422. <if test="orderStatus != null and orderStatus != ''">
  423. AND a.order_status in
  424. <foreach collection="statusArr" close=")" open="(" item="item" separator=",">
  425. #{item}
  426. </foreach>
  427. </if>
  428. <if test="orderStatus == null or orderStatus == ''">
  429. AND a.order_status not in ('待出库', '草稿')
  430. </if>
  431. <if test="customerId != null and customerId != ''">
  432. AND a.customer_id LIKE '%' + #{customerId} + '%'
  433. </if>
  434. <if test="customerName != null and customerName != ''">
  435. AND c.customerName LIKE '%' + #{customerName} + '%'
  436. </if>
  437. <if test="inspectionFlag != null and inspectionFlag != ''">
  438. AND ISNULL(b.inspection_flag,'N') = #{inspectionFlag}
  439. </if>
  440. <if test="startDate != null">
  441. AND a.required_outbound_date >= #{startDate}
  442. </if>
  443. <if test="endDate != null">
  444. AND #{endDate} >= a.required_outbound_date
  445. </if>
  446. </where>
  447. GROUP BY
  448. a.site, a.bu_no, a.order_no, a.order_type, a.order_status, a.customer_id, c.customerName,
  449. a.related_order_no, a.related_order_line_no, a.required_outbound_date, a.remarks,
  450. a.erp_order_no, a.erp_order_line_no, a.erp_order_date, a.created_by, a.created_date,
  451. a.updated_by, a.updated_date, a.assigned_by, a.assigned_date, a.closed_by, a.closed_date,
  452. a.archived_by, a.archived_date, a.orderref1, a.orderref2, a.orderref3, a.orderref4, a.orderref5,
  453. a.order_date, a.close_flag, a.out_warehouse, a.customer_order_no, a.show_in_query_flag,
  454. b.part_no, b.part_desc, b.unit, b.required_qty, b.out_warehouse, b.out_batch_no, b.order_qty,
  455. b.related_order_no, b.related_order_line_no, b.std_packing_qty, b.inspection_flag, c.CustomerAbb
  456. ORDER BY a.created_date DESC, b.part_no
  457. </select>
  458. <!-- 分页查询出库通知单主记录(关联明细) -->
  459. <select id="searchOutboundNotificationWithDetailByPage" resultType="com.gaotao.modules.outboundNotification.entity.vo.OutboundNotificationHeadVo">
  460. SELECT
  461. a.site,
  462. a.bu_no as buNo,
  463. dbo.get_bu_desc(a.site, a.bu_no) as buDesc,
  464. a.order_no as orderNo,
  465. a.order_type as orderType,
  466. a.order_status as orderStatus,
  467. a.customer_id as customerId,
  468. c.customerName,
  469. c.CustomerAbb as customerAbb,
  470. a.required_outbound_date as requiredOutboundDate,
  471. a.remarks,
  472. a.erp_order_no as erpOrderNo,
  473. a.erp_order_line_no as erpOrderLineNo,
  474. a.erp_order_date as erpOrderDate,
  475. a.created_by as createdBy,
  476. a.created_date as createdDate,
  477. a.updated_by as updatedBy,
  478. a.updated_date as updatedDate,
  479. a.assigned_by as assignedBy,
  480. a.assigned_date as assignedDate,
  481. a.closed_by as closedBy,
  482. a.closed_date as closedDate,
  483. a.archived_by as archivedBy,
  484. a.archived_date as archivedDate,
  485. a.orderref1,
  486. a.orderref2,
  487. a.orderref3,
  488. a.orderref4,
  489. a.orderref5,
  490. a.order_date as orderDate,
  491. a.close_flag as closeFlag,
  492. a.out_warehouse as outWarehouse,
  493. a.customer_order_no as customerOrderNo,
  494. a.show_in_query_flag as showInQueryFlag,
  495. b.part_no as partNo,
  496. b.part_desc as partDesc,
  497. b.unit,
  498. b.required_qty as requiredQty,
  499. b.out_warehouse as detailOutWarehouse,
  500. b.out_batch_no as outBatchNo,
  501. b.order_qty as orderQty,
  502. b.related_order_no as relatedOrderNo,
  503. b.related_order_line_no as relatedOrderLineNo,
  504. ISNULL(SUM(e.roll_qty), 0) as rollQty,
  505. CASE WHEN b.required_qty - ISNULL(SUM(e.roll_qty), 0) > 0
  506. THEN ROUND(b.required_qty - ISNULL(SUM(e.roll_qty), 0), 3)
  507. ELSE 0
  508. END as unScanQty,
  509. ISNULL(SUM(i.qty_on_hand), 0) as availableStock,
  510. b.std_packing_qty,
  511. ISNULL(b.inspection_flag,'N') as inspectionFlag
  512. FROM outbound_notification_head a
  513. LEFT JOIN Customer c ON a.site = c.site AND a.customer_id = c.CustomerID
  514. 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
  515. 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
  516. 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
  517. 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
  518. <where>
  519. <if test="query.site != null and query.site != ''">
  520. AND a.site = #{query.site}
  521. </if>
  522. <if test="query.buNo != null and query.buNo != ''">
  523. AND a.bu_no = #{query.buNo}
  524. </if>
  525. <if test="query.orderNo != null and query.orderNo != ''">
  526. AND a.order_no LIKE '%' + #{query.orderNo} + '%'
  527. </if>
  528. <if test="query.orderType != null and query.orderType != ''">
  529. AND a.order_type = #{query.orderType}
  530. </if>
  531. <if test="query.orderStatus != null and query.orderStatus != ''">
  532. AND a.order_status in
  533. <foreach collection="query.statusArr" close=")" open="(" item="item" separator=",">
  534. #{item}
  535. </foreach>
  536. </if>
  537. <if test="query.orderStatus == null or query.orderStatus == ''">
  538. AND a.order_status not in ('待出库', '草稿')
  539. </if>
  540. <if test="query.customerId != null and query.customerId != ''">
  541. AND a.customer_id LIKE '%' + #{query.customerId} + '%'
  542. </if>
  543. <if test="query.customerName != null and query.customerName != ''">
  544. AND c.customerName LIKE '%' + #{query.customerName} + '%'
  545. </if>
  546. <if test="query.inspectionFlag != null and query.inspectionFlag != ''">
  547. AND ISNULL(b.inspection_flag,'N') = #{query.inspectionFlag}
  548. </if>
  549. <if test="query.startDate != null">
  550. AND a.required_outbound_date >= #{query.startDate}
  551. </if>
  552. <if test="query.endDate != null">
  553. AND #{query.endDate} >= a.required_outbound_date
  554. </if>
  555. </where>
  556. GROUP BY
  557. a.site, a.bu_no, a.order_no, a.order_type, a.order_status, a.customer_id, c.customerName,
  558. a.related_order_no, a.related_order_line_no, a.required_outbound_date, a.remarks,
  559. a.erp_order_no, a.erp_order_line_no, a.erp_order_date, a.created_by, a.created_date,
  560. a.updated_by, a.updated_date, a.assigned_by, a.assigned_date, a.closed_by, a.closed_date,
  561. a.archived_by, a.archived_date, a.orderref1, a.orderref2, a.orderref3, a.orderref4, a.orderref5,
  562. a.order_date, a.close_flag, a.out_warehouse, a.customer_order_no, a.show_in_query_flag,
  563. b.part_no, b.part_desc, b.unit, b.required_qty, b.out_warehouse, b.out_batch_no, b.order_qty,
  564. b.related_order_no, b.related_order_line_no, b.std_packing_qty, b.inspection_flag, c.CustomerAbb
  565. ORDER BY a.required_outbound_date DESC, b.part_no
  566. OFFSET #{query.offset} ROWS FETCH NEXT #{query.limit} ROWS ONLY
  567. </select>
  568. <!-- 分页查询出库通知单主记录(关联明细)- 总数查询 -->
  569. <select id="searchOutboundNotificationWithDetailCount" resultType="int">
  570. SELECT COUNT(1) FROM (
  571. SELECT
  572. a.order_no,
  573. b.part_no
  574. FROM outbound_notification_head a
  575. LEFT JOIN Customer c ON a.site = c.site AND a.customer_id = c.CustomerID
  576. 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
  577. 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
  578. 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
  579. 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
  580. <where>
  581. <if test="query.site != null and query.site != ''">
  582. AND a.site = #{query.site}
  583. </if>
  584. <if test="query.buNo != null and query.buNo != ''">
  585. AND a.bu_no = #{query.buNo}
  586. </if>
  587. <if test="query.orderNo != null and query.orderNo != ''">
  588. AND a.order_no LIKE '%' + #{query.orderNo} + '%'
  589. </if>
  590. <if test="query.orderType != null and query.orderType != ''">
  591. AND a.order_type = #{query.orderType}
  592. </if>
  593. <if test="query.orderStatus != null and query.orderStatus != ''">
  594. AND a.order_status in
  595. <foreach collection="query.statusArr" close=")" open="(" item="item" separator=",">
  596. #{item}
  597. </foreach>
  598. </if>
  599. <if test="query.orderStatus == null or query.orderStatus == ''">
  600. AND a.order_status not in ('待出库', '草稿')
  601. </if>
  602. <if test="query.customerId != null and query.customerId != ''">
  603. AND a.customer_id LIKE '%' + #{query.customerId} + '%'
  604. </if>
  605. <if test="query.customerName != null and query.customerName != ''">
  606. AND c.customerName LIKE '%' + #{query.customerName} + '%'
  607. </if>
  608. <if test="query.inspectionFlag != null and query.inspectionFlag != ''">
  609. AND ISNULL(b.inspection_flag,'N') = #{query.inspectionFlag}
  610. </if>
  611. <if test="query.startDate != null">
  612. AND a.required_outbound_date >= #{query.startDate}
  613. </if>
  614. <if test="query.endDate != null">
  615. AND #{query.endDate} >= a.required_outbound_date
  616. </if>
  617. </where>
  618. GROUP BY
  619. a.site, a.bu_no, a.order_no, a.order_type, a.order_status, a.customer_id, c.customerName,
  620. a.related_order_no, a.related_order_line_no, a.required_outbound_date, a.remarks,
  621. a.erp_order_no, a.erp_order_line_no, a.erp_order_date, a.created_by, a.created_date,
  622. a.updated_by, a.updated_date, a.assigned_by, a.assigned_date, a.closed_by, a.closed_date,
  623. a.archived_by, a.archived_date, a.orderref1, a.orderref2, a.orderref3, a.orderref4, a.orderref5,
  624. a.order_date, a.close_flag, a.out_warehouse, a.customer_order_no, a.show_in_query_flag,
  625. b.part_no, b.part_desc, b.unit, b.required_qty, b.out_warehouse, b.out_batch_no, b.order_qty,
  626. b.related_order_no, b.related_order_line_no, b.std_packing_qty, b.inspection_flag, c.CustomerAbb
  627. ) T
  628. </select>
  629. <!-- 更新出库通知单状态 -->
  630. <update id="updateOrderStatus">
  631. UPDATE outbound_notification_head
  632. SET order_status = #{orderStatus}
  633. WHERE site = #{site}
  634. AND bu_no = #{buNo}
  635. AND order_no = #{orderNo}
  636. </update>
  637. <!-- ==================== 托清单相关SQL ==================== -->
  638. <!-- 查询托清单列表 -->
  639. <select id="searchSoReceivePalletsData" resultType="SoReceivePalletsData">
  640. SELECT
  641. s.id,
  642. s.site,
  643. s.bu_no as buNo,
  644. s.pallet_no as palletNo,
  645. s.order_no as orderNo,
  646. s.status,
  647. s.boxes_qty as boxesQty,
  648. s.pallet_type as palletType,
  649. s.c_in_stock_flag as cInStockFlag,
  650. s.created_date as createdDate,
  651. s.created_by as createdBy,
  652. s.update_date as updateDate,
  653. s.update_by as updateBy,
  654. s.version,
  655. ISNULL(pallet_count, 0) as palletCount,
  656. ISNULL(boxesCount, 0) as boxesCount,
  657. ISNULL(rollCount, 0) as rollCount,
  658. ISNULL(rollsQty, 0) as rollsQty
  659. FROM so_receive_pallets s with(nolock)
  660. LEFT JOIN (
  661. select
  662. a.site,
  663. a.bu_no,
  664. a.order_no,
  665. COUNT(DISTINCT a.pallet_no) AS pallet_count, -- 托数量
  666. COUNT(DISTINCT B.box_no) AS boxesCount, -- 箱标签张数
  667. COUNT(DISTINCT c.final_roll_no) AS rollCount, -- 卷标签张数
  668. ISNULL(SUM(c.roll_qty), 0) AS rollsQty -- 物料总数
  669. from so_receive_pallets A with(nolock)
  670. INNER JOIN so_receive_pallet_boxes B with(nolock) ON A.site = B.site AND A.pallet_no = B.pallet_no
  671. INNER JOIN so_receive_box_rolls C with(nolock) ON C.site = B.site AND B.box_no = C.box_no
  672. WHERE a.SITE = #{site} AND a.bu_no = #{buNo} and a.order_no = #{orderNo} group by a.site, a.bu_no, a.order_no
  673. ) T ON S.site = T.site AND S.bu_no = T.bu_no AND S.order_no = T.order_no
  674. WHERE s.site = #{site}
  675. AND s.bu_no = #{buNo}
  676. AND s.order_no = #{orderNo}
  677. ORDER BY s.created_date DESC
  678. </select>
  679. <!-- 新增托 -->
  680. <insert id="newSoReceivePalletsData">
  681. INSERT INTO so_receive_pallets
  682. (site, pallet_no, order_no, [status], boxes_qty, pallet_type, c_in_stock_flag, created_date, created_by,
  683. version, bu_no)
  684. VALUES
  685. (#{site}, #{palletNo}, #{orderNo}, #{status}, #{boxesQty}, #{palletType}, 'Y', GETDATE(), #{createdBy},
  686. 0, #{buNo})
  687. </insert>
  688. <!-- 查询托明细列表 -->
  689. <select id="searchPalletBoxDetail" resultType="SoReceivePalletBoxesData">
  690. SELECT ROW_NUMBER() OVER (ORDER BY a.received_date) orderId,
  691. a.id, a.site, a.bu_no, a.pallet_no, a.box_no, a.boxes_qty, a.received_by, a.received_date
  692. FROM so_receive_pallet_boxes a
  693. WHERE a.site = #{site}
  694. AND a.pallet_no = #{palletNo}
  695. AND a.bu_no = #{buNo}
  696. ORDER BY a.received_date DESC
  697. </select>
  698. <!-- 查询托数据 -->
  699. <select id="searchPalletData" resultType="SoReceivePalletsData">
  700. SELECT a.id, a.site, a.bu_no, a.pallet_no, a.order_no, [status], boxes_qty, pallet_type, c_in_stock_flag,
  701. created_date, created_by, version
  702. FROM so_receive_pallets a
  703. WHERE a.site = #{site}
  704. AND a.pallet_no = #{palletNo}
  705. AND a.bu_no = #{buNo}
  706. </select>
  707. <!-- 删除托 -->
  708. <delete id="deleteSoReceivePalletsData">
  709. DELETE FROM so_receive_pallets
  710. WHERE id = #{id}
  711. </delete>
  712. <!-- 更新托状态 -->
  713. <update id="updatePalletStatus">
  714. UPDATE so_receive_pallets
  715. SET [status] = #{status}
  716. WHERE id = #{id}
  717. </update>
  718. <!-- 根据箱号查询箱信息(用于装托扫描) -->
  719. <select id="selectBoxByBoxNo" resultType="SoReceiveBoxesData">
  720. 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,
  721. a.box_type as boxType, a.WareHouseID as wareHouseID
  722. FROM so_receive_boxes a
  723. WHERE a.site = #{site}
  724. AND a.box_no = #{boxNo}
  725. AND a.bu_no = #{buNo}
  726. </select>
  727. <!-- 装托:添加箱到托 -->
  728. <insert id="addBoxToPallet">
  729. INSERT INTO so_receive_pallet_boxes
  730. (site, bu_no, pallet_no, box_no, boxes_qty, received_by, received_date)
  731. VALUES
  732. (#{site}, #{buNo}, #{palletNo}, #{boxNo}, #{boxesQty}, #{receivedBy}, GETDATE())
  733. </insert>
  734. <!-- 拆托:从托中删除箱 -->
  735. <delete id="deleteBoxFromPallet">
  736. DELETE FROM so_receive_pallet_boxes
  737. WHERE site = #{site}
  738. AND bu_no = #{buNo}
  739. AND pallet_no = #{palletNo}
  740. <if test="boxNo != null and boxNo != ''">
  741. AND box_no = #{boxNo}
  742. </if>
  743. </delete>
  744. <!-- 更新托的箱数量 -->
  745. <update id="updatePalletBoxesQty">
  746. UPDATE so_receive_pallets
  747. SET boxes_qty = (
  748. SELECT COUNT(*)
  749. FROM so_receive_pallet_boxes
  750. WHERE site = #{site}
  751. AND bu_no = #{buNo}
  752. AND pallet_no = #{palletNo}
  753. )
  754. WHERE site = #{site}
  755. AND bu_no = #{buNo}
  756. AND pallet_no = #{palletNo}
  757. </update>
  758. <!-- 检查箱是否在托中 -->
  759. <select id="checkBoxInPallet" resultType="SoReceivePalletBoxesData">
  760. SELECT id, site, bu_no, pallet_no, box_no, boxes_qty, received_by, received_date
  761. FROM so_receive_pallet_boxes
  762. WHERE site = #{site}
  763. AND bu_no = #{buNo}
  764. AND box_no = #{boxNo}
  765. </select>
  766. <!-- 检查卷是否已装箱 -->
  767. <select id="checkRollInBox" resultType="SoReceiveBoxRollsData">
  768. SELECT id, site, bu_no, box_no, final_roll_no, roll_qty, received_by, received_date, WareHouseID, part_no
  769. FROM so_receive_box_rolls
  770. WHERE site = #{site}
  771. AND bu_no = #{buNo}
  772. AND final_roll_no = #{rollNo}
  773. </select>
  774. <!-- 查询装箱明细列表(关联仓库和物料信息) -->
  775. <select id="searchBoxRollDetailList" resultType="map">
  776. SELECT
  777. br.box_no AS boxNo,
  778. br.final_roll_no AS finalRollNo,
  779. br.roll_qty AS rollQty,
  780. br.received_by AS receivedBy,
  781. br.received_date AS receivedDate,
  782. br.WareHouseID AS wareHouseId,
  783. wh.WareHouseName AS wareHouseName,
  784. br.part_no AS partNo,
  785. p.PartDescription AS partDesc
  786. FROM so_receive_box_rolls br
  787. LEFT JOIN WareHouse wh ON br.site = wh.site and br.WareHouseID = wh.WareHouseID
  788. LEFT JOIN Part p ON br.site = p.site and br.part_no = p.partNo
  789. WHERE br.site = #{site}
  790. AND br.bu_no = #{buNo}
  791. AND br.box_no = #{boxNo}
  792. ORDER BY br.received_date DESC
  793. </select>
  794. </mapper>