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.

906 lines
35 KiB

10 months ago
4 months ago
4 months ago
4 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
8 months ago
10 months ago
10 months ago
10 months ago
8 months ago
8 months ago
8 months ago
10 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. <select id="searchSoReceiveCasesDataByPage" resultType="SoReceiveCasesData">
  275. SELECT
  276. s.Id as id,
  277. s.NotifyNo as notifyNo,
  278. s.cases_no as casesNo,
  279. s.roll_no as rollNo,
  280. s.roll_qty as rollQty,
  281. s.part_no as partNo,
  282. s.part_desc as partDesc,
  283. s.create_date as createDate,
  284. s.create_by as createBy,
  285. s.Remark as remark,
  286. s.site,
  287. s.bu_no as buNo,
  288. agg.box_count_cases as boxCountCases,
  289. agg.box_count_rolls as boxCountRolls,
  290. agg.total_qty as totalQty
  291. FROM so_receive_cases s WITH(NOLOCK)
  292. LEFT JOIN (
  293. SELECT
  294. site,
  295. NotifyNo,
  296. COUNT(DISTINCT cases_no) AS box_count_cases, --盒标签张数
  297. COUNT(DISTINCT roll_no) AS box_count_rolls, --卷标签张数
  298. SUM(roll_qty) AS total_qty --物料总数
  299. FROM so_receive_cases WITH(NOLOCK)
  300. WHERE site = #{site} and NotifyNo = #{notifyNo}
  301. GROUP BY site, NotifyNo
  302. ) as agg ON s.site = agg.site AND s.NotifyNo = agg.NotifyNo
  303. <where>
  304. s.site = #{site} AND s.bu_no = #{buNo}
  305. <if test="notifyNo != null and notifyNo != ''">
  306. AND s.NotifyNo = #{notifyNo}
  307. </if>
  308. <if test="casesNo != null and casesNo != ''">
  309. AND s.cases_no = #{casesNo}
  310. </if>
  311. </where>
  312. ORDER BY s.create_date DESC
  313. OFFSET #{offset} ROWS FETCH NEXT #{limit} ROWS ONLY
  314. </select>
  315. <select id="searchSoReceiveCasesDataCount" resultType="int">
  316. SELECT COUNT(1)
  317. FROM so_receive_cases s WITH(NOLOCK)
  318. <where>
  319. s.site = #{site} AND s.bu_no = #{buNo}
  320. <if test="notifyNo != null and notifyNo != ''">
  321. AND s.NotifyNo = #{notifyNo}
  322. </if>
  323. <if test="casesNo != null and casesNo != ''">
  324. AND s.cases_no = #{casesNo}
  325. </if>
  326. </where>
  327. </select>
  328. <delete id="deleteSoReceiveCasesData">
  329. DELETE FROM so_receive_cases
  330. WHERE Id = #{id}
  331. AND site = #{site}
  332. AND bu_no = #{buNo}
  333. </delete>
  334. <select id="validateCaseRoll" resultType="SoReceiveCasesData">
  335. SELECT
  336. #{casesNo} as casesNo,
  337. a.roll_no as rollNo,
  338. a.qty_on_hand as rollQty,
  339. a.part_no as partNo,
  340. b.PartDescription as partDesc,
  341. a.batch_no as batchNo,
  342. a.status,
  343. a.parent_roll_type as parentRollType
  344. FROM
  345. inventory_stock a
  346. INNER JOIN part b ON a.site = b.site
  347. AND a.part_no = b.PartNo
  348. WHERE
  349. a.site = #{site}
  350. AND a.parent_roll_no = #{rollNo}
  351. AND a.part_no = #{partNo}
  352. </select>
  353. <insert id="saveSoReceiveCases">
  354. INSERT INTO so_receive_cases (
  355. NotifyNo,
  356. cases_no,
  357. roll_no,
  358. roll_qty,
  359. part_no,
  360. part_desc,
  361. create_date,
  362. create_by,
  363. Remark,
  364. site,
  365. bu_no
  366. ) VALUES (
  367. #{notifyNo},
  368. #{casesNo},
  369. #{rollNo},
  370. #{rollQty},
  371. #{partNo},
  372. #{partDesc},
  373. GETDATE(),
  374. #{createBy},
  375. #{remark},
  376. #{site},
  377. #{buNo}
  378. )
  379. </insert>
  380. <update id="updateStockParentRollType">
  381. UPDATE inventory_stock
  382. SET ori_parent_roll_no = parent_roll_no,
  383. ori_parent_roll_type = parent_roll_type,
  384. parent_roll_no = #{parentRollNo},
  385. parent_roll_type = #{parentRollType}
  386. WHERE roll_no = #{rollNo}
  387. AND site = #{site}
  388. AND bu_no = #{buNo}
  389. </update>
  390. <!-- 恢复库存的原始上级标签 -->
  391. <update id="restoreStockParentRollType">
  392. UPDATE inventory_stock
  393. SET parent_roll_no = ori_parent_roll_no,
  394. parent_roll_type = ori_parent_roll_type
  395. WHERE roll_no = #{rollNo}
  396. AND site = #{site}
  397. AND bu_no = #{buNo}
  398. </update>
  399. <!-- 查询出库通知单主记录(关联明细) -->
  400. <select id="searchOutboundNotificationWithDetail" resultType="com.gaotao.modules.outboundNotification.entity.vo.OutboundNotificationHeadVo">
  401. SELECT
  402. a.site,
  403. a.bu_no as buNo,
  404. dbo.get_bu_desc(a.site, a.bu_no) as buDesc,
  405. a.order_no as orderNo,
  406. a.order_type as orderType,
  407. a.order_status as orderStatus,
  408. a.customer_id as customerId,
  409. c.customerName,
  410. c.CustomerAbb as customerAbb,
  411. <!-- a.related_order_no as relatedOrderNo,-->
  412. <!-- a.related_order_line_no as relatedOrderLineNo,-->
  413. a.required_outbound_date as requiredOutboundDate,
  414. a.remarks,
  415. a.erp_order_no as erpOrderNo,
  416. a.erp_order_line_no as erpOrderLineNo,
  417. a.erp_order_date as erpOrderDate,
  418. a.created_by as createdBy,
  419. a.created_date as createdDate,
  420. a.updated_by as updatedBy,
  421. a.updated_date as updatedDate,
  422. a.assigned_by as assignedBy,
  423. a.assigned_date as assignedDate,
  424. a.closed_by as closedBy,
  425. a.closed_date as closedDate,
  426. a.archived_by as archivedBy,
  427. a.archived_date as archivedDate,
  428. a.orderref1,
  429. a.orderref2,
  430. a.orderref3,
  431. a.orderref4,
  432. a.orderref5,
  433. a.order_date as orderDate,
  434. a.close_flag as closeFlag,
  435. a.out_warehouse as outWarehouse,
  436. a.customer_order_no as customerOrderNo,
  437. a.show_in_query_flag as showInQueryFlag,
  438. <!-- 关联明细信息 -->
  439. b.part_no as partNo,
  440. b.part_desc as partDesc,
  441. b.unit,
  442. b.required_qty as requiredQty,
  443. b.out_warehouse as detailOutWarehouse,
  444. b.out_batch_no as outBatchNo,
  445. b.order_qty as orderQty,
  446. b.related_order_no as relatedOrderNo,
  447. b.related_order_line_no as relatedOrderLineNo,
  448. <!-- 已扫描数量和未扫描数量 -->
  449. ISNULL(e_agg.roll_qty, 0) as rollQty,
  450. CASE WHEN b.required_qty - ISNULL(e_agg.roll_qty, 0) > 0
  451. THEN ROUND(b.required_qty - ISNULL(e_agg.roll_qty, 0), 3)
  452. ELSE 0
  453. END as unScanQty ,
  454. ISNULL(inv_agg.qty_on_hand, 0) as availableStock,
  455. b.std_packing_qty,
  456. ISNULL(b.inspection_flag,'N') as inspectionFlag
  457. FROM outbound_notification_head a
  458. LEFT JOIN Customer c ON a.site = c.site AND a.customer_id = c.CustomerID
  459. 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
  460. LEFT JOIN (
  461. SELECT
  462. site,
  463. part_no,
  464. batch_no,
  465. SUM(qty_on_hand) as qty_on_hand
  466. FROM inventory_stock
  467. WHERE status = '在库'
  468. <if test="site != null and site != ''">
  469. AND site = #{site}
  470. </if>
  471. GROUP BY site, part_no, batch_no
  472. ) AS inv_agg ON b.site = inv_agg.site AND b.part_no = inv_agg.part_no AND b.out_batch_no = inv_agg.batch_no
  473. LEFT JOIN (
  474. SELECT
  475. d.site,
  476. d.bu_no,
  477. d.order_no,
  478. e.part_no,
  479. SUM(e.roll_qty) as roll_qty
  480. FROM so_receive_boxes d
  481. INNER JOIN so_receive_box_rolls e ON d.site = e.site AND d.bu_no = e.bu_no AND d.box_no = e.box_no
  482. <where>
  483. <if test="site != null and site != ''">
  484. d.site = #{site}
  485. </if>
  486. </where>
  487. GROUP BY d.site, d.bu_no, d.order_no, e.part_no
  488. ) AS e_agg ON b.site = e_agg.site AND b.bu_no = e_agg.bu_no AND b.order_no = e_agg.order_no AND b.part_no = e_agg.part_no
  489. <where>
  490. <if test="site != null and site != ''">
  491. AND a.site = #{site}
  492. </if>
  493. <if test="buNo != null and buNo != ''">
  494. AND a.bu_no = #{buNo}
  495. </if>
  496. <if test="orderNo != null and orderNo != ''">
  497. AND a.order_no LIKE '%' + #{orderNo} + '%'
  498. </if>
  499. <if test="orderType != null and orderType != ''">
  500. AND a.order_type = #{orderType}
  501. </if>
  502. <if test="orderStatus != null and orderStatus != ''">
  503. AND a.order_status in
  504. <foreach collection="statusArr" close=")" open="(" item="item" separator=",">
  505. #{item}
  506. </foreach>
  507. </if>
  508. <if test="orderStatus == null or orderStatus == ''">
  509. AND a.order_status not in ('待出库', '草稿')
  510. </if>
  511. <if test="customerId != null and customerId != ''">
  512. AND a.customer_id LIKE '%' + #{customerId} + '%'
  513. </if>
  514. <if test="customerName != null and customerName != ''">
  515. AND c.customerName LIKE '%' + #{customerName} + '%'
  516. </if>
  517. <if test="inspectionFlag != null and inspectionFlag != ''">
  518. AND ISNULL(b.inspection_flag,'N') = #{inspectionFlag}
  519. </if>
  520. <if test="startDate != null">
  521. AND a.required_outbound_date >= #{startDate}
  522. </if>
  523. <if test="endDate != null">
  524. AND #{endDate} >= a.required_outbound_date
  525. </if>
  526. </where>
  527. ORDER BY a.required_outbound_date DESC, b.part_no
  528. </select>
  529. <!-- 分页查询出库通知单主记录(关联明细) -->
  530. <select id="searchOutboundNotificationWithDetailByPage" resultType="com.gaotao.modules.outboundNotification.entity.vo.OutboundNotificationHeadVo">
  531. SELECT
  532. a.site,
  533. a.bu_no as buNo,
  534. dbo.get_bu_desc(a.site, a.bu_no) as buDesc,
  535. a.order_no as orderNo,
  536. a.order_type as orderType,
  537. a.order_status as orderStatus,
  538. a.customer_id as customerId,
  539. c.customerName,
  540. c.CustomerAbb as customerAbb,
  541. a.required_outbound_date as requiredOutboundDate,
  542. a.remarks,
  543. a.erp_order_no as erpOrderNo,
  544. a.erp_order_line_no as erpOrderLineNo,
  545. a.erp_order_date as erpOrderDate,
  546. a.created_by as createdBy,
  547. a.created_date as createdDate,
  548. a.updated_by as updatedBy,
  549. a.updated_date as updatedDate,
  550. a.assigned_by as assignedBy,
  551. a.assigned_date as assignedDate,
  552. a.closed_by as closedBy,
  553. a.closed_date as closedDate,
  554. a.archived_by as archivedBy,
  555. a.archived_date as archivedDate,
  556. a.orderref1,
  557. a.orderref2,
  558. a.orderref3,
  559. a.orderref4,
  560. a.orderref5,
  561. a.order_date as orderDate,
  562. a.close_flag as closeFlag,
  563. a.out_warehouse as outWarehouse,
  564. a.customer_order_no as customerOrderNo,
  565. a.show_in_query_flag as showInQueryFlag,
  566. b.part_no as partNo,
  567. b.part_desc as partDesc,
  568. b.unit,
  569. b.required_qty as requiredQty,
  570. b.out_warehouse as detailOutWarehouse,
  571. b.out_batch_no as outBatchNo,
  572. b.order_qty as orderQty,
  573. b.related_order_no as relatedOrderNo,
  574. b.related_order_line_no as relatedOrderLineNo,
  575. ISNULL(e_agg.roll_qty, 0) as rollQty,
  576. CASE WHEN b.required_qty - ISNULL(e_agg.roll_qty, 0) > 0
  577. THEN ROUND(b.required_qty - ISNULL(e_agg.roll_qty, 0), 3)
  578. ELSE 0
  579. END as unScanQty,
  580. ISNULL(inv_agg.qty_on_hand, 0) as availableStock,
  581. b.std_packing_qty,
  582. ISNULL(b.inspection_flag,'N') as inspectionFlag
  583. FROM outbound_notification_head a
  584. LEFT JOIN Customer c ON a.site = c.site AND a.customer_id = c.CustomerID
  585. 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
  586. LEFT JOIN (
  587. SELECT
  588. site,
  589. part_no,
  590. batch_no,
  591. SUM(qty_on_hand) as qty_on_hand
  592. FROM inventory_stock
  593. WHERE status = '在库'
  594. <if test="query.site != null and query.site != ''">
  595. AND site = #{query.site}
  596. </if>
  597. GROUP BY site, part_no, batch_no
  598. ) AS inv_agg ON b.site = inv_agg.site AND b.part_no = inv_agg.part_no AND b.out_batch_no = inv_agg.batch_no
  599. LEFT JOIN (
  600. SELECT
  601. d.site,
  602. d.bu_no,
  603. d.order_no,
  604. e.part_no,
  605. SUM(e.roll_qty) as roll_qty
  606. FROM so_receive_boxes d
  607. INNER JOIN so_receive_box_rolls e ON d.site = e.site AND d.bu_no = e.bu_no AND d.box_no = e.box_no
  608. <where>
  609. <if test="query.site != null and query.site != ''">
  610. d.site = #{query.site}
  611. </if>
  612. </where>
  613. GROUP BY d.site, d.bu_no, d.order_no, e.part_no
  614. ) AS e_agg ON b.site = e_agg.site AND b.bu_no = e_agg.bu_no AND b.order_no = e_agg.order_no AND b.part_no = e_agg.part_no
  615. <where>
  616. <if test="query.site != null and query.site != ''">
  617. AND a.site = #{query.site}
  618. </if>
  619. <if test="query.buNo != null and query.buNo != ''">
  620. AND a.bu_no = #{query.buNo}
  621. </if>
  622. <if test="query.orderNo != null and query.orderNo != ''">
  623. AND a.order_no LIKE '%' + #{query.orderNo} + '%'
  624. </if>
  625. <if test="query.orderType != null and query.orderType != ''">
  626. AND a.order_type = #{query.orderType}
  627. </if>
  628. <if test="query.orderStatus != null and query.orderStatus != ''">
  629. AND a.order_status in
  630. <foreach collection="query.statusArr" close=")" open="(" item="item" separator=",">
  631. #{item}
  632. </foreach>
  633. </if>
  634. <if test="query.orderStatus == null or query.orderStatus == ''">
  635. AND a.order_status not in ('待出库', '草稿')
  636. </if>
  637. <if test="query.customerId != null and query.customerId != ''">
  638. AND a.customer_id LIKE '%' + #{query.customerId} + '%'
  639. </if>
  640. <if test="query.customerName != null and query.customerName != ''">
  641. AND c.customerName LIKE '%' + #{query.customerName} + '%'
  642. </if>
  643. <if test="query.inspectionFlag != null and query.inspectionFlag != ''">
  644. AND ISNULL(b.inspection_flag,'N') = #{query.inspectionFlag}
  645. </if>
  646. <if test="query.startDate != null">
  647. AND a.required_outbound_date >= #{query.startDate}
  648. </if>
  649. <if test="query.endDate != null">
  650. AND #{query.endDate} >= a.required_outbound_date
  651. </if>
  652. </where>
  653. ORDER BY a.required_outbound_date DESC, b.part_no
  654. OFFSET #{query.offset} ROWS FETCH NEXT #{query.limit} ROWS ONLY
  655. </select>
  656. <!-- 分页查询出库通知单主记录(关联明细)- 总数查询 -->
  657. <select id="searchOutboundNotificationWithDetailCount" resultType="int">
  658. SELECT COUNT(1)
  659. FROM outbound_notification_head a
  660. LEFT JOIN Customer c ON a.site = c.site AND a.customer_id = c.CustomerID
  661. 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
  662. <where>
  663. <if test="query.site != null and query.site != ''">
  664. AND a.site = #{query.site}
  665. </if>
  666. <if test="query.buNo != null and query.buNo != ''">
  667. AND a.bu_no = #{query.buNo}
  668. </if>
  669. <if test="query.orderNo != null and query.orderNo != ''">
  670. AND a.order_no LIKE '%' + #{query.orderNo} + '%'
  671. </if>
  672. <if test="query.orderType != null and query.orderType != ''">
  673. AND a.order_type = #{query.orderType}
  674. </if>
  675. <if test="query.orderStatus != null and query.orderStatus != ''">
  676. AND a.order_status in
  677. <foreach collection="query.statusArr" close=")" open="(" item="item" separator=",">
  678. #{item}
  679. </foreach>
  680. </if>
  681. <if test="query.orderStatus == null or query.orderStatus == ''">
  682. AND a.order_status not in ('待出库', '草稿')
  683. </if>
  684. <if test="query.customerId != null and query.customerId != ''">
  685. AND a.customer_id LIKE '%' + #{query.customerId} + '%'
  686. </if>
  687. <if test="query.customerName != null and query.customerName != ''">
  688. AND c.customerName LIKE '%' + #{query.customerName} + '%'
  689. </if>
  690. <if test="query.inspectionFlag != null and query.inspectionFlag != ''">
  691. AND ISNULL(b.inspection_flag,'N') = #{query.inspectionFlag}
  692. </if>
  693. <if test="query.startDate != null">
  694. AND a.required_outbound_date >= #{query.startDate}
  695. </if>
  696. <if test="query.endDate != null">
  697. AND #{query.endDate} >= a.required_outbound_date
  698. </if>
  699. </where>
  700. </select>
  701. <!-- 更新出库通知单状态 -->
  702. <update id="updateOrderStatus">
  703. UPDATE outbound_notification_head
  704. SET order_status = #{orderStatus}
  705. WHERE site = #{site}
  706. AND bu_no = #{buNo}
  707. AND order_no = #{orderNo}
  708. </update>
  709. <!-- ==================== 托清单相关SQL ==================== -->
  710. <!-- 查询托清单列表 -->
  711. <select id="searchSoReceivePalletsData" resultType="SoReceivePalletsData">
  712. SELECT
  713. s.id,
  714. s.site,
  715. s.bu_no as buNo,
  716. s.pallet_no as palletNo,
  717. s.order_no as orderNo,
  718. s.status,
  719. s.boxes_qty as boxesQty,
  720. s.pallet_type as palletType,
  721. s.c_in_stock_flag as cInStockFlag,
  722. s.created_date as createdDate,
  723. s.created_by as createdBy,
  724. s.update_date as updateDate,
  725. s.update_by as updateBy,
  726. s.version,
  727. ISNULL(pallet_count, 0) as palletCount,
  728. ISNULL(boxesCount, 0) as boxesCount,
  729. ISNULL(rollCount, 0) as rollCount,
  730. ISNULL(rollsQty, 0) as rollsQty
  731. FROM so_receive_pallets s with(nolock)
  732. LEFT JOIN (
  733. select
  734. a.site,
  735. a.bu_no,
  736. a.order_no,
  737. COUNT(DISTINCT a.pallet_no) AS pallet_count, -- 托数量
  738. COUNT(DISTINCT B.box_no) AS boxesCount, -- 箱标签张数
  739. COUNT(DISTINCT c.final_roll_no) AS rollCount, -- 卷标签张数
  740. ISNULL(SUM(c.roll_qty), 0) AS rollsQty -- 物料总数
  741. from so_receive_pallets A with(nolock)
  742. INNER JOIN so_receive_pallet_boxes B with(nolock) ON A.site = B.site AND A.pallet_no = B.pallet_no
  743. INNER JOIN so_receive_box_rolls C with(nolock) ON C.site = B.site AND B.box_no = C.box_no
  744. WHERE a.SITE = #{site} AND a.bu_no = #{buNo} and a.order_no = #{orderNo} group by a.site, a.bu_no, a.order_no
  745. ) T ON S.site = T.site AND S.bu_no = T.bu_no AND S.order_no = T.order_no
  746. WHERE s.site = #{site}
  747. AND s.bu_no = #{buNo}
  748. AND s.order_no = #{orderNo}
  749. ORDER BY s.created_date DESC
  750. </select>
  751. <!-- 新增托 -->
  752. <insert id="newSoReceivePalletsData">
  753. INSERT INTO so_receive_pallets
  754. (site, pallet_no, order_no, [status], boxes_qty, pallet_type, c_in_stock_flag, created_date, created_by,
  755. version, bu_no)
  756. VALUES
  757. (#{site}, #{palletNo}, #{orderNo}, #{status}, #{boxesQty}, #{palletType}, 'Y', GETDATE(), #{createdBy},
  758. 0, #{buNo})
  759. </insert>
  760. <!-- 查询托明细列表 -->
  761. <select id="searchPalletBoxDetail" resultType="SoReceivePalletBoxesData">
  762. SELECT ROW_NUMBER() OVER (ORDER BY a.received_date) orderId,
  763. a.id, a.site, a.bu_no, a.pallet_no, a.box_no, a.boxes_qty, a.received_by, a.received_date
  764. FROM so_receive_pallet_boxes a
  765. WHERE a.site = #{site}
  766. AND a.pallet_no = #{palletNo}
  767. AND a.bu_no = #{buNo}
  768. ORDER BY a.received_date DESC
  769. </select>
  770. <!-- 查询托数据 -->
  771. <select id="searchPalletData" resultType="SoReceivePalletsData">
  772. SELECT a.id, a.site, a.bu_no, a.pallet_no, a.order_no, [status], boxes_qty, pallet_type, c_in_stock_flag,
  773. created_date, created_by, version
  774. FROM so_receive_pallets a
  775. WHERE a.site = #{site}
  776. AND a.pallet_no = #{palletNo}
  777. AND a.bu_no = #{buNo}
  778. </select>
  779. <!-- 删除托 -->
  780. <delete id="deleteSoReceivePalletsData">
  781. DELETE FROM so_receive_pallets
  782. WHERE id = #{id}
  783. </delete>
  784. <!-- 更新托状态 -->
  785. <update id="updatePalletStatus">
  786. UPDATE so_receive_pallets
  787. SET [status] = #{status}
  788. WHERE id = #{id}
  789. </update>
  790. <!-- 根据箱号查询箱信息(用于装托扫描) -->
  791. <select id="selectBoxByBoxNo" resultType="SoReceiveBoxesData">
  792. 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,
  793. a.box_type as boxType, a.WareHouseID as wareHouseID
  794. FROM so_receive_boxes a
  795. WHERE a.site = #{site}
  796. AND a.box_no = #{boxNo}
  797. AND a.bu_no = #{buNo}
  798. </select>
  799. <!-- 装托:添加箱到托 -->
  800. <insert id="addBoxToPallet">
  801. INSERT INTO so_receive_pallet_boxes
  802. (site, bu_no, pallet_no, box_no, boxes_qty, received_by, received_date)
  803. VALUES
  804. (#{site}, #{buNo}, #{palletNo}, #{boxNo}, #{boxesQty}, #{receivedBy}, GETDATE())
  805. </insert>
  806. <!-- 拆托:从托中删除箱 -->
  807. <delete id="deleteBoxFromPallet">
  808. DELETE FROM so_receive_pallet_boxes
  809. WHERE site = #{site}
  810. AND bu_no = #{buNo}
  811. AND pallet_no = #{palletNo}
  812. <if test="boxNo != null and boxNo != ''">
  813. AND box_no = #{boxNo}
  814. </if>
  815. </delete>
  816. <!-- 更新托的箱数量 -->
  817. <update id="updatePalletBoxesQty">
  818. UPDATE so_receive_pallets
  819. SET boxes_qty = (
  820. SELECT COUNT(*)
  821. FROM so_receive_pallet_boxes
  822. WHERE site = #{site}
  823. AND bu_no = #{buNo}
  824. AND pallet_no = #{palletNo}
  825. )
  826. WHERE site = #{site}
  827. AND bu_no = #{buNo}
  828. AND pallet_no = #{palletNo}
  829. </update>
  830. <!-- 检查箱是否在托中 -->
  831. <select id="checkBoxInPallet" resultType="SoReceivePalletBoxesData">
  832. SELECT id, site, bu_no, pallet_no, box_no, boxes_qty, received_by, received_date
  833. FROM so_receive_pallet_boxes
  834. WHERE site = #{site}
  835. AND bu_no = #{buNo}
  836. AND box_no = #{boxNo}
  837. </select>
  838. <!-- 检查卷是否已装箱 -->
  839. <select id="checkRollInBox" resultType="SoReceiveBoxRollsData">
  840. SELECT id, site, bu_no, box_no, final_roll_no, roll_qty, received_by, received_date, WareHouseID, part_no
  841. FROM so_receive_box_rolls
  842. WHERE site = #{site}
  843. AND bu_no = #{buNo}
  844. AND final_roll_no = #{rollNo}
  845. </select>
  846. <!-- 查询装箱明细列表(关联仓库和物料信息) -->
  847. <select id="searchBoxRollDetailList" resultType="map">
  848. SELECT
  849. br.box_no AS boxNo,
  850. br.final_roll_no AS finalRollNo,
  851. br.roll_qty AS rollQty,
  852. br.received_by AS receivedBy,
  853. br.received_date AS receivedDate,
  854. br.WareHouseID AS wareHouseId,
  855. wh.WareHouseName AS wareHouseName,
  856. br.part_no AS partNo,
  857. p.PartDescription AS partDesc
  858. FROM so_receive_box_rolls br
  859. LEFT JOIN WareHouse wh ON br.site = wh.site and br.WareHouseID = wh.WareHouseID
  860. LEFT JOIN Part p ON br.site = p.site and br.part_no = p.partNo
  861. WHERE br.site = #{site}
  862. AND br.bu_no = #{buNo}
  863. AND br.box_no = #{boxNo}
  864. ORDER BY br.received_date DESC
  865. </select>
  866. </mapper>