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.

323 lines
15 KiB

2 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 months ago
​
​
​
2 months ago
​
​
​
​
2 months ago
​
​
2 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
1 month ago
​
2 months ago
​
​
​
​
​
​
1 month ago
​
​
​
2 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 months ago
2 months ago
​
​
2 months ago
2 months ago
2 months ago
2 months ago
​
​
​
​
2 months ago
2 months ago
2 months ago
2 months ago
​
​
​
​
2 months ago
2 months ago
2 months ago
2 months ago
​
​
​
​
2 months ago
2 months ago
2 months ago
2 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 months ago
​
2 months ago
2 months ago
​
2 months ago
2 months ago
​
2 months ago
​
​
​
2 months ago
2 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 months ago
2 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.xujie.modules.supplier.mapper.PriceSheetReportMapper">
  4. <select id="countPriceList" resultType="long">
  5. SELECT COUNT(1)
  6. FROM SupplierforPart sp
  7. INNER JOIN part p
  8. ON p.site = sp.site
  9. AND p.part_no = sp.part_no
  10. LEFT JOIN srm_supplier s
  11. ON s.site = sp.site
  12. AND s.supplier_no = sp.supplier_no
  13. WHERE sp.site = #{query.site}
  14. AND p.item IS NOT NULL
  15. AND LTRIM(RTRIM(p.item)) &lt;&gt; ''
  16. <if test="query.item != null and query.item != ''">
  17. AND p.item LIKE CONCAT('%', #{query.item}, '%')
  18. </if>
  19. <if test="query.sku != null and query.sku != ''">
  20. AND p.sku LIKE CONCAT('%', #{query.sku}, '%')
  21. </if>
  22. <if test="query.shortNpc != null and query.shortNpc != ''">
  23. AND s.c_short_npc LIKE CONCAT('%', #{query.shortNpc}, '%')
  24. </if>
  25. <if test="query.category != null and query.category != ''">
  26. AND p.category LIKE CONCAT('%', #{query.category}, '%')
  27. </if>
  28. </select>
  29. <!--
  30. 价格表查询:QTY/PO 读 minOrderQty,MOQ/COLOR 读 minColorQty,QTY/CARTON 读 minCartonQty。
  31. site 必须来自请求。空数量按 0 返回,避免前端显示空白。
  32. -->
  33. <select id="listPriceList" resultType="com.xujie.modules.supplier.data.PriceSheetReportPriceVo">
  34. SELECT
  35. p.item AS rawCode,
  36. p.sku AS sku,
  37. s.c_short_npc AS supplier,
  38. ISNULL(sp.minOrderQty, 0) AS qtyPo,
  39. ISNULL(sp.minColorQty, 0) AS moqColor,
  40. ISNULL(sp.minCartonQty, 0) AS qtyCarton,
  41. CONVERT(VARCHAR(10), current_price.priceDate, 23) AS startDate,
  42. current_price.tierQty1 AS tierQty1,
  43. current_price.tierQty2 AS tierQty2,
  44. current_price.tierQty3 AS tierQty3,
  45. current_price.tierQty4 AS tierQty4,
  46. current_price.tierQty5 AS tierQty5,
  47. current_price.tierQty6 AS tierQty6,
  48. current_price.tierQty7 AS tierQty7,
  49. current_price.tierQty8 AS tierQty8,
  50. current_price.priceTier1 AS priceTier1,
  51. current_price.priceTier2 AS priceTier2,
  52. current_price.priceTier3 AS priceTier3,
  53. current_price.priceTier4 AS priceTier4,
  54. current_price.priceTier5 AS priceTier5,
  55. current_price.priceTier6 AS priceTier6,
  56. current_price.priceTier7 AS priceTier7,
  57. current_price.priceTier8 AS priceTier8,
  58. fsc.propertyValue AS fsc,
  59. fsc_claim.propertyValue AS fscClaim,
  60. aware_dpp.propertyValue AS awareDpp,
  61. coo.propertyValue AS coo,
  62. COALESCE(sku_lead.production_lead_time, s.production_lead_time) AS leadTime
  63. FROM SupplierforPart sp
  64. INNER JOIN part p
  65. ON p.site = sp.site
  66. AND p.part_no = sp.part_no
  67. LEFT JOIN srm_supplier s
  68. ON s.site = sp.site
  69. AND s.supplier_no = sp.supplier_no
  70. LEFT JOIN SupplierforSku sku_lead
  71. ON sku_lead.supplier_no = sp.supplier_no
  72. AND sku_lead.sku = p.sku
  73. AND NULLIF(LTRIM(RTRIM(p.sku)), '') IS NOT NULL
  74. LEFT JOIN
  75. (
  76. SELECT
  77. ranked.site,
  78. ranked.supplier_code,
  79. ranked.part_no,
  80. MAX(CASE WHEN ranked.tierRank = 1 THEN ranked.price_date END) AS priceDate,
  81. MAX(CASE WHEN ranked.tierRank = 1 THEN ranked.qty_end END) AS tierQty1,
  82. MAX(CASE WHEN ranked.tierRank = 2 THEN ranked.qty_end END) AS tierQty2,
  83. MAX(CASE WHEN ranked.tierRank = 3 THEN ranked.qty_end END) AS tierQty3,
  84. MAX(CASE WHEN ranked.tierRank = 4 THEN ranked.qty_end END) AS tierQty4,
  85. MAX(CASE WHEN ranked.tierRank = 5 THEN ranked.qty_end END) AS tierQty5,
  86. MAX(CASE WHEN ranked.tierRank = 6 THEN ranked.qty_end END) AS tierQty6,
  87. MAX(CASE WHEN ranked.tierRank = 7 THEN ranked.qty_end END) AS tierQty7,
  88. MAX(CASE WHEN ranked.tierRank = 8 THEN ranked.qty_end END) AS tierQty8,
  89. MAX(CASE WHEN ranked.tierRank = 1 THEN ranked.unit_price END) AS priceTier1,
  90. MAX(CASE WHEN ranked.tierRank = 2 THEN ranked.unit_price END) AS priceTier2,
  91. MAX(CASE WHEN ranked.tierRank = 3 THEN ranked.unit_price END) AS priceTier3,
  92. MAX(CASE WHEN ranked.tierRank = 4 THEN ranked.unit_price END) AS priceTier4,
  93. MAX(CASE WHEN ranked.tierRank = 5 THEN ranked.unit_price END) AS priceTier5,
  94. MAX(CASE WHEN ranked.tierRank = 6 THEN ranked.unit_price END) AS priceTier6,
  95. MAX(CASE WHEN ranked.tierRank = 7 THEN ranked.unit_price END) AS priceTier7,
  96. MAX(CASE WHEN ranked.tierRank = 8 THEN ranked.unit_price END) AS priceTier8
  97. FROM
  98. (
  99. SELECT
  100. price.site,
  101. price.supplier_code,
  102. price.part_no,
  103. price.qty_end,
  104. price.unit_price,
  105. price.price_date,
  106. ROW_NUMBER() OVER
  107. (
  108. PARTITION BY price.site, price.supplier_code, price.part_no
  109. ORDER BY price.qty_start, price.qty_end, price.id
  110. ) AS tierRank
  111. FROM sp_current_tier_price price
  112. WHERE price.site = #{query.site}
  113. ) ranked
  114. WHERE ranked.tierRank &lt;= 8
  115. GROUP BY ranked.site, ranked.supplier_code, ranked.part_no
  116. ) current_price
  117. ON current_price.site = sp.site
  118. AND current_price.supplier_code = sp.supplier_no
  119. AND current_price.part_no = sp.part_no
  120. <!-- 物料附加属性:FSC / FSC claim / AWARE DPP / COO。Lead free Pellet(T0016) 已从价格单查询与导出移除,不再关联。 -->
  121. LEFT JOIN
  122. (
  123. SELECT Site, PartNo,
  124. MAX(TextValue) AS propertyValue
  125. FROM PartSubPropertiesValue
  126. WHERE PropertiesItemNo = 'T0011' AND RecordType = 'P'
  127. GROUP BY Site, PartNo
  128. ) fsc ON fsc.Site = sp.site AND fsc.PartNo = sp.part_no
  129. LEFT JOIN
  130. (
  131. SELECT Site, PartNo,
  132. MAX(TextValue) AS propertyValue
  133. FROM PartSubPropertiesValue
  134. WHERE PropertiesItemNo = 'T0012' AND RecordType = 'P'
  135. GROUP BY Site, PartNo
  136. ) fsc_claim ON fsc_claim.Site = sp.site AND fsc_claim.PartNo = sp.part_no
  137. LEFT JOIN
  138. (
  139. SELECT Site, PartNo,
  140. MAX(TextValue) AS propertyValue
  141. FROM PartSubPropertiesValue
  142. WHERE PropertiesItemNo = 'T0052' AND RecordType = 'P'
  143. GROUP BY Site, PartNo
  144. ) aware_dpp ON aware_dpp.Site = sp.site AND aware_dpp.PartNo = sp.part_no
  145. LEFT JOIN
  146. (
  147. SELECT Site, PartNo,
  148. MAX(TextValue) AS propertyValue
  149. FROM PartSubPropertiesValue
  150. WHERE PropertiesItemNo = 'T0042' AND RecordType = 'P'
  151. GROUP BY Site, PartNo
  152. ) coo ON coo.Site = sp.site AND coo.PartNo = sp.part_no
  153. WHERE sp.site = #{query.site}
  154. AND p.item IS NOT NULL
  155. AND LTRIM(RTRIM(p.item)) &lt;&gt; ''
  156. <if test="query.item != null and query.item != ''">
  157. AND p.item LIKE CONCAT('%', #{query.item}, '%')
  158. </if>
  159. <if test="query.sku != null and query.sku != ''">
  160. AND p.sku LIKE CONCAT('%', #{query.sku}, '%')
  161. </if>
  162. <if test="query.shortNpc != null and query.shortNpc != ''">
  163. AND s.c_short_npc LIKE CONCAT('%', #{query.shortNpc}, '%')
  164. </if>
  165. <if test="query.category != null and query.category != ''">
  166. AND p.category LIKE CONCAT('%', #{query.category}, '%')
  167. </if>
  168. ORDER BY p.item, s.c_short_npc, sp.part_no, sp.supplier_no
  169. <if test="offset != null and limit != null">
  170. OFFSET #{offset} ROWS FETCH NEXT #{limit} ROWS ONLY
  171. </if>
  172. </select>
  173. <!--
  174. handling charge 只展示配置了最低出货金额的供应商。
  175. min_ship_account 已改为 varchar 字典值:null 或空白视为未配置,页签查询与导出共用本条件。
  176. -->
  177. <sql id="HandlingChargeHasMinShipAccount">
  178. AND NULLIF(LTRIM(RTRIM(s.min_ship_account)), '') IS NOT NULL
  179. </sql>
  180. <select id="countHandlingCharges" resultType="long">
  181. SELECT COUNT(1)
  182. FROM srm_supplier s
  183. WHERE s.site = #{query.site}
  184. <include refid="HandlingChargeHasMinShipAccount"/>
  185. <if test="query.shortNpc != null and query.shortNpc != ''">
  186. AND s.c_short_npc LIKE CONCAT('%', #{query.shortNpc}, '%')
  187. </if>
  188. AND EXISTS (
  189. SELECT 1
  190. FROM SupplierforPart filter_relation
  191. INNER JOIN part filter_part
  192. ON filter_part.site = filter_relation.site
  193. AND filter_part.part_no = filter_relation.part_no
  194. WHERE filter_relation.site = s.site
  195. AND filter_relation.supplier_no = s.supplier_no
  196. AND filter_part.item IS NOT NULL
  197. AND LTRIM(RTRIM(filter_part.item)) &lt;&gt; ''
  198. <if test="query.item != null and query.item != ''">
  199. AND filter_part.item LIKE CONCAT('%', #{query.item}, '%')
  200. </if>
  201. <if test="query.sku != null and query.sku != ''">
  202. AND filter_part.sku LIKE CONCAT('%', #{query.sku}, '%')
  203. </if>
  204. <if test="query.category != null and query.category != ''">
  205. AND filter_part.category LIKE CONCAT('%', #{query.category}, '%')
  206. </if>
  207. )
  208. </select>
  209. <select id="listHandlingCharges"
  210. resultType="com.xujie.modules.supplier.data.PriceSheetReportHandlingChargeVo">
  211. SELECT
  212. s.c_short_npc AS supplier,
  213. s.min_ship_account AS minShipAccount,
  214. s.handling_charge AS handlingChargeAmount
  215. FROM srm_supplier s
  216. WHERE s.site = #{query.site}
  217. <include refid="HandlingChargeHasMinShipAccount"/>
  218. <if test="query.shortNpc != null and query.shortNpc != ''">
  219. AND s.c_short_npc LIKE CONCAT('%', #{query.shortNpc}, '%')
  220. </if>
  221. AND EXISTS (
  222. SELECT 1
  223. FROM SupplierforPart filter_relation
  224. INNER JOIN part filter_part
  225. ON filter_part.site = filter_relation.site
  226. AND filter_part.part_no = filter_relation.part_no
  227. WHERE filter_relation.site = s.site
  228. AND filter_relation.supplier_no = s.supplier_no
  229. AND filter_part.item IS NOT NULL
  230. AND LTRIM(RTRIM(filter_part.item)) &lt;&gt; ''
  231. <if test="query.item != null and query.item != ''">
  232. AND filter_part.item LIKE CONCAT('%', #{query.item}, '%')
  233. </if>
  234. <if test="query.sku != null and query.sku != ''">
  235. AND filter_part.sku LIKE CONCAT('%', #{query.sku}, '%')
  236. </if>
  237. <if test="query.category != null and query.category != ''">
  238. AND filter_part.category LIKE CONCAT('%', #{query.category}, '%')
  239. </if>
  240. )
  241. ORDER BY s.c_short_npc, s.supplier_no
  242. <if test="offset != null and limit != null">
  243. OFFSET #{offset} ROWS FETCH NEXT #{limit} ROWS ONLY
  244. </if>
  245. </select>
  246. <select id="countPaymentTerms" resultType="long">
  247. SELECT COUNT(1)
  248. FROM srm_supplier s
  249. WHERE s.site = #{query.site}
  250. <if test="query.shortNpc != null and query.shortNpc != ''">
  251. AND s.c_short_npc LIKE CONCAT('%', #{query.shortNpc}, '%')
  252. </if>
  253. AND EXISTS (
  254. SELECT 1
  255. FROM SupplierforPart filter_relation
  256. INNER JOIN part filter_part
  257. ON filter_part.site = filter_relation.site
  258. AND filter_part.part_no = filter_relation.part_no
  259. WHERE filter_relation.site = s.site
  260. AND filter_relation.supplier_no = s.supplier_no
  261. AND filter_part.item IS NOT NULL
  262. AND LTRIM(RTRIM(filter_part.item)) &lt;&gt; ''
  263. <if test="query.item != null and query.item != ''">
  264. AND filter_part.item LIKE CONCAT('%', #{query.item}, '%')
  265. </if>
  266. <if test="query.sku != null and query.sku != ''">
  267. AND filter_part.sku LIKE CONCAT('%', #{query.sku}, '%')
  268. </if>
  269. <if test="query.category != null and query.category != ''">
  270. AND filter_part.category LIKE CONCAT('%', #{query.category}, '%')
  271. </if>
  272. )
  273. </select>
  274. <select id="listPaymentTerms"
  275. resultType="com.xujie.modules.supplier.data.PriceSheetReportPaymentTermVo">
  276. SELECT
  277. ROW_NUMBER() OVER (ORDER BY s.c_short_npc, s.supplier_no) AS rowNo,
  278. s.c_short_npc AS supplier,
  279. payment_term.payment_term AS paymentTerms,
  280. CAST(NULL AS VARCHAR(1)) AS telexReleaseStatus
  281. FROM srm_supplier s
  282. LEFT JOIN PaymentTerm payment_term
  283. ON payment_term.site = s.site
  284. AND payment_term.payment_term_id = s.PaymentTerm
  285. WHERE s.site = #{query.site}
  286. <if test="query.shortNpc != null and query.shortNpc != ''">
  287. AND s.c_short_npc LIKE CONCAT('%', #{query.shortNpc}, '%')
  288. </if>
  289. AND EXISTS (
  290. SELECT 1
  291. FROM SupplierforPart filter_relation
  292. INNER JOIN part filter_part
  293. ON filter_part.site = filter_relation.site
  294. AND filter_part.part_no = filter_relation.part_no
  295. WHERE filter_relation.site = s.site
  296. AND filter_relation.supplier_no = s.supplier_no
  297. AND filter_part.item IS NOT NULL
  298. AND LTRIM(RTRIM(filter_part.item)) &lt;&gt; ''
  299. <if test="query.item != null and query.item != ''">
  300. AND filter_part.item LIKE CONCAT('%', #{query.item}, '%')
  301. </if>
  302. <if test="query.sku != null and query.sku != ''">
  303. AND filter_part.sku LIKE CONCAT('%', #{query.sku}, '%')
  304. </if>
  305. <if test="query.category != null and query.category != ''">
  306. AND filter_part.category LIKE CONCAT('%', #{query.category}, '%')
  307. </if>
  308. )
  309. ORDER BY s.c_short_npc, s.supplier_no
  310. <if test="offset != null and limit != null">
  311. OFFSET #{offset} ROWS FETCH NEXT #{limit} ROWS ONLY
  312. </if>
  313. </select>
  314. </mapper>