WarehouseBaseInfoMapper.xml 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991
  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.yh.saas.plugin.yiliangyiyun.mapper.WarehouseBaseInfoMapper">
  4. <!-- 质检信息数量包括已删除的 -->
  5. <select id="getCountByCondition" parameterType="Map" resultType="java.lang.Integer">
  6. SELECT
  7. COUNT(q.id)
  8. FROM quality_inspection_management q
  9. WHERE
  10. q.comp_id = #{compId}
  11. AND q.service_management_type = #{serviceManagementType}
  12. AND q.warehouse_name = #{warehouseName}
  13. AND TO_DAYS(q.create_date) = TO_DAYS(NOW())
  14. </select>
  15. <!-- 常用仓库数量包括已删除的 -->
  16. <select id="getWareHouseCountByCondition" parameterType="Map" resultType="java.lang.Integer">
  17. SELECT
  18. COUNT(w.id)
  19. FROM warehouse_base_info w
  20. WHERE
  21. w.comp_id = #{compId}
  22. and w.warehouse_type="1"
  23. </select>
  24. <!-- 临时仓库数量包括已删除的 -->
  25. <select id="getTemWareHouseCountByCondition" parameterType="Map" resultType="java.lang.Integer">
  26. SELECT
  27. COUNT(w.id)
  28. FROM warehouse_base_info w
  29. WHERE
  30. w.comp_id = #{compId}
  31. and w.warehouse_type="2"
  32. </select>
  33. <!-- 获得入库导出列表 -->
  34. <select id="getListByCondition" parameterType="Map"
  35. resultType="com.yh.saas.plugin.yiliangyiyun.entity.view.ExportVView">
  36. SELECT
  37. distinct
  38. IFNULL(m.buyer,c.comp_name) as compName,
  39. a.warehouse_name as warehouseName,
  40. q.bin_number as binNumber,
  41. a.settlement_date as createDate,
  42. a.contract_no as contractNo,
  43. iowt.in_out_task_no as warehousingTaskNo,
  44. a.payment_no as paymentNo,
  45. a.customer_name as customerName,
  46. '收购入库' as inOutType,
  47. '' as deliveryGrossWeight,
  48. '' as deliveryTare,
  49. '' as deliveryVolume,
  50. '' as sendWarehouse,
  51. '' as tranPrice,
  52. a.freight as freight,
  53. i.supplier as supplier,
  54. a.goods_name as goodsName,
  55. case when a.goods_name like '%潮粮%' then '潮粮' else '干粮' end as type,
  56. q.grade as grade,
  57. q.water_content as waterContent,
  58. q.impurity as impurity,
  59. q.mildew_grain as mildewGrain,
  60. q.imperfect_grain as imperfectGrain,
  61. q.bulk_density as bulkDensity,
  62. q.jiaorenli as jiaorenli,
  63. a.car_no as carNo,
  64. q.box_no as boxNo,
  65. q.box_no_other as boxNoOther,
  66. q.title_no as titleNo,
  67. q.title_no_other as titleNoOther,
  68. ROUND(case when a.type ='干粮' then q.dry_grain_price*1000 else q.tidal_grain_price*1000 end ,2) as
  69. netWeightPrice,
  70. ROUND(a.gross_weight/1000,2) as grossWeight,
  71. ROUND(a.tare/1000,2) as tare,
  72. ROUND(a.weight_deduction/1000,2) as buckleWeight,
  73. ROUND(a.net_weight/1000,5) as netWeight,
  74. a.unit_deduction as unitDeduction,
  75. a.unload_deduction as unloadingDeduction,
  76. a.solid_grain_price as pureWeightPrice,
  77. case when a.goods_name like '%潮粮%' then a.pure_weight else a.net_weight end as pureWeight,
  78. a.amount_ing_payable as amountIngPayable,
  79. a.amount_ed_payable as amountEdPayable,
  80. i.payee_name as payeeName,
  81. i.bank_card as cardNo,
  82. i.bank_deposit as bankDeposit,
  83. i.bank_deposit_branch as bankDepositBranch
  84. FROM payment_management a
  85. left join contract_management_info m on m.comp_id = a.comp_id and m.contract_no = a.contract_no and m.delete_flag = 0
  86. left join quality_inspection_management q on q.relation_id = a.relation_id and q.comp_id = a.comp_id and q.delete_flag = 0
  87. left join weighing_management w on w.relation_id = a.relation_id and w.comp_id = a.comp_id and w.delete_flag = 0
  88. left join common_company c on c.comp_id = a.comp_id and c.delete_flag = 0
  89. left join identity_authentication_info i on i.customer_name = a.customer_name
  90. and i.customer_phone = a.customer_phone and i.customer_type_flag = 1 and i.delete_flag = 0 and i.cover = 0
  91. left join common_company_identity cci on cci.com_id = a.comp_id and cci.delete_flag = 0 and cci.identity_id = i.id
  92. left join in_out_warehouse_task iowt on iowt.comp_id = a.comp_id and iowt.delete_flag = 0 and iowt.contract_no = a.contract_no
  93. and iowt.approve_status is null and iowt.in_out_type = '收购入库'
  94. WHERE a.delete_flag = '0'
  95. AND a.comp_id = #{compId}
  96. AND a.management_type = '1'
  97. AND a.contract_no is not null
  98. AND q.warehouse_in_out_id is not null
  99. <if test="warehouseName != null and warehouseName != ''">
  100. AND a.warehouse_name= #{warehouseName}
  101. </if>
  102. <if test="startDate != null">
  103. AND (DATE_FORMAT(a.settlement_date,"%Y%m%d%H%i%s") &gt;=
  104. DATE_FORMAT(#{startDate},"%Y%m%d%H%i%s"))
  105. </if>
  106. <if test="endDate != null">
  107. AND (DATE_FORMAT(a.settlement_date,"%Y%m%d%H%i%s") &lt;=
  108. DATE_FORMAT(#{endDate},"%Y%m%d%H%i%s"))
  109. </if>
  110. UNION ALL
  111. SELECT
  112. m.buyer as compName,
  113. s.warehouse_name as warehouseName,
  114. w.bin_number as binNumber,
  115. w.update_date as createDate,
  116. s.contract_no as contractNo,
  117. iowt.in_out_task_no as warehousingTaskNo,
  118. '' as paymentNo,
  119. m.seller as customerName,
  120. '采购入库' as inOutType,
  121. '' as deliveryGrossWeight,
  122. '' as deliveryTare,
  123. '' as deliveryVolume,
  124. '' as sendWarehouse,
  125. '' as tranPrice,
  126. case when m.deliver_type = '1' then ifNull(r.amount_ed_payable,0) else 0 end as freight,
  127. '' as supplier,
  128. w.goods_name as goodsName,
  129. case when w.goods_name like '%潮粮%' then '潮粮' else '干粮' end as type,
  130. w.grade as grade,
  131. IFNULL(q.water_content,wd.water_content) as waterContent,
  132. IFNULL(q.impurity,wd.impurity) as impurity,
  133. IFNULL(q.mildew_grain,wd.mildew_grain) as mildewGrain,
  134. IFNULL(q.imperfect_grain,wd.imperfect_grain) as imperfectGrain,
  135. IFNULL(q.bulk_density,wd.bulk_density) as bulkDensity,
  136. IFNULL(q.jiaorenli,wd.jiaorenli) as jiaorenli,
  137. s.car_no as carNo,
  138. w.box_no as boxNo,
  139. w.box_no_other as boxNoOther,
  140. w.title_no as titleNo,
  141. w.title_no_other as titleNoOther,
  142. s.settlement_price as netWeightPrice,
  143. ROUND(s.gross_weight,2) as grossWeight,
  144. ROUND(s.tare,2) as tare,
  145. s.deduction_weight as buckleWeight,
  146. s.net_weight as netWeight,
  147. s.deduction_amount as unitDeduction,
  148. '' as pureWeightPrice,
  149. 0 as unloadingDeduction,
  150. case when w.goods_name like '%潮粮%' then w.pure_weight*1000 else w.net_weight*1000 end as pureWeight,
  151. s.amount_ing_payable as amountIngPayable,
  152. s.amount_ed_payable as amountEdPayable,
  153. i.payee_name as payeeName,
  154. i.bank_card as cardNo,
  155. i.bank_deposit as bankDeposit,
  156. i.bank_deposit_branch as bankDepositBranch
  157. FROM stock_purchase_receipt_report s
  158. left join warehouse_in_out_info w on w.id = s.warehouse_record_id and w.delete_flag = 0
  159. left join in_out_warehouse_task iowt on iowt.in_out_task_no = w.in_out_task_no and iowt.delete_flag = 0
  160. left join quality_inspection_management q on q.warehouse_in_out_id = w.id and q.delete_flag = 0
  161. left join warehouse_in_out_detail wd on wd.info_id = w.id
  162. left join tran_car_info t on t.contract_no = w.contract_no and t.delete_flag = 0 and t.tran_car_no = w.tran_car_no and t.car_no = w.car_no
  163. left join tran_settlement_report r on r.car_id = t.id and r.delete_flag = 0
  164. left join common_company c on c.comp_id = s.comp_id and c.delete_flag = 0
  165. left join contract_management_info m on m.comp_id = s.comp_id and m.contract_no = s.contract_no and m.delete_flag = 0
  166. left join contract_goods_info g on m.id=g.contract_id and g.delete_flag = 0
  167. left join customer_info i on ((i.comp_name = m.seller and customer_type='企业客户') or (i.customer_name = m.seller
  168. and customer_type='个人客户'))
  169. and i.customer_phone = m.seller_phone and i.delete_flag = 0
  170. WHERE s.delete_flag = '0'
  171. AND s.comp_id = #{compId}
  172. <if test="warehouseName != null and warehouseName != ''">
  173. AND s.warehouse_name= #{warehouseName}
  174. </if>
  175. <if test="startDate != null">
  176. AND (DATE_FORMAT(w.update_date,"%Y%m%d%H%i%s") &gt;=
  177. DATE_FORMAT(#{startDate},"%Y%m%d%H%i%s"))
  178. </if>
  179. <if test="endDate != null">
  180. AND (DATE_FORMAT(w.update_date,"%Y%m%d%H%i%s") &lt;=
  181. DATE_FORMAT(#{endDate},"%Y%m%d%H%i%s"))
  182. </if>
  183. UNION ALL
  184. SELECT
  185. c.comp_name as compName,
  186. w.warehouse_name as warehouseName,
  187. w.bin_number as binNumber,
  188. w.update_date as createDate,
  189. w.contract_no as contractNo,
  190. iowt.in_out_task_no as warehousingTaskNo,
  191. '' as paymentNo,
  192. IFNULL(cmi.seller,'') as customerName,
  193. '移库入库' as inOutType,
  194. wi.gross_weight as deliveryGrossWeight,
  195. wi.tare as deliveryTare,
  196. t.load_net_weight as deliveryVolume,
  197. i.send_warehouse as sendWarehouse,
  198. t.tran_price as tranPrice,
  199. ROUND(IFNULL(r.amount_ing_payable,IFNULL(t.tran_price,0)*t.load_net_weight),2) as freight,
  200. '' as supplier,
  201. w.goods_name as goodsName,
  202. case when w.goods_name like '%潮粮%' then '潮粮' else '干粮' end as type,
  203. w.grade as grade,
  204. q.water_content as waterContent,
  205. q.impurity as impurity,
  206. q.mildew_grain as mildewGrain,
  207. q.imperfect_grain as imperfectGrain,
  208. q.bulk_density as bulkDensity,
  209. q.jiaorenli as jiaorenli,
  210. w.car_no as carNo,
  211. w.box_no as boxNo,
  212. w.box_no_other as boxNoOther,
  213. w.title_no as titleNo,
  214. w.title_no_other as titleNoOther,
  215. w.cost as netWeightPrice,
  216. ROUND(w.gross_weight,2) as grossWeight,
  217. ROUND(w.tare,2) as tare,
  218. w.deduction_weight as buckleWeight,
  219. w.net_weight as netWeight,
  220. IFNULL(q.deduction_amount,0) as unitDeduction,
  221. 0 as unloadingDeduction,
  222. '' as pureWeightPrice,
  223. case when w.goods_name like '%潮粮%' then w.pure_weight*1000 else w.net_weight*1000 end as pureWeight,
  224. -- ROUND(IFNULL(r.amount_ing_payable,(w.cost+IFNULL(t.tran_price,0))*t.load_net_weight),2) as amountIngPayable,
  225. case when cmi.settlement_weight_method = '1' then
  226. ROUND((w.cost-IFNULL(q.deduction_amount,0))*t.load_net_weight,2)
  227. else ROUND((w.cost-IFNULL(q.deduction_amount,0))*w.net_weight,2) end as amountIngPayable,
  228. 0 as amountEdPayable,
  229. '' as payeeName,
  230. '' as cardNo,
  231. '' as bankDeposit,
  232. '' as bankDepositBranch
  233. FROM warehouse_in_out_info w
  234. left join warehouse_in_out_detail d on w.id=d.info_id and d.delete_flag = 0
  235. left join quality_inspection_management q on w.id=q.warehouse_in_out_id and q.delete_flag = 0
  236. left join stock_purchase_receipt_report s on s.warehouse_record_id=w.id and s.delete_flag = 0
  237. left join warehouse_base_info b on b.id=w.base_id and b.delete_flag = 0
  238. left join common_company c on c.comp_id = b.comp_id and c.delete_flag = 0
  239. left join in_out_warehouse_task i on w.contract_no = i.move_task_no and i.delete_flag = 0 and i.in_out_type = '移库出库'
  240. <if test="warehouseName != null and warehouseName != ''">
  241. AND i.receive_warehouse = #{warehouseName}
  242. </if>
  243. left join tran_car_info t on t.contract_no = w.contract_no and t.delete_flag = 0 and t.tran_car_no = w.tran_car_no and t.car_no = w.car_no
  244. left join warehouse_in_out_info wi on t.contract_no = wi.contract_no and wi.delete_flag = 0 and t.tran_car_no = wi.tran_car_no and t.car_no = wi.car_no and wi.in_out_flag = 1
  245. left join tran_settlement_report r on r.car_id = t.id and r.delete_flag = 0
  246. left join contract_management_info cmi on cmi.contract_no = wi.warehouse_name and cmi.delete_flag = 0
  247. left join in_out_warehouse_task iowt on iowt.in_out_task_no = w.in_out_task_no and iowt.delete_flag = 0
  248. WHERE w.delete_flag = '0'
  249. AND b.comp_id = #{compId}
  250. and w.in_out_flag = 2
  251. and w.in_out_type='移库入库'
  252. and w.status_flag=3
  253. and s.id is null
  254. <if test="warehouseName != null and warehouseName != ''">
  255. AND w.warehouse_name= #{warehouseName}
  256. </if>
  257. <if test="startDate != null">
  258. AND (DATE_FORMAT(w.update_date,"%Y%m%d%H%i%s") &gt;=
  259. DATE_FORMAT(#{startDate},"%Y%m%d%H%i%s"))
  260. </if>
  261. <if test="endDate != null">
  262. AND (DATE_FORMAT(w.update_date,"%Y%m%d%H%i%s") &lt;=
  263. DATE_FORMAT(#{endDate},"%Y%m%d%H%i%s"))
  264. </if>
  265. group by w.id
  266. UNION ALL
  267. SELECT
  268. c.comp_name as compName,
  269. w.warehouse_name as warehouseName,
  270. w.bin_number as binNumber,
  271. w.update_date as createDate,
  272. w.contract_no as contractNo,
  273. iowt.in_out_task_no as warehousingTaskNo,
  274. '' as paymentNo,
  275. '' as customerName,
  276. '退库' as inOutType,
  277. '' as deliveryGrossWeight,
  278. '' as deliveryTare,
  279. '' as deliveryVolume,
  280. '' as sendWarehouse,
  281. 0 as tranPrice,
  282. 0 as freight,
  283. '' as supplier,
  284. w.goods_name as goodsName,
  285. case when w.goods_name like '%潮粮%' then '潮粮' else '干粮' end as type,
  286. w.grade as grade,
  287. d.water_content as waterContent,
  288. d.impurity as impurity,
  289. d.mildew_grain as mildewGrain,
  290. d.imperfect_grain as imperfectGrain,
  291. d.bulk_density as bulkDensity,
  292. d.jiaorenli as jiaorenli,
  293. w.car_no as carNo,
  294. w.box_no as boxNo,
  295. w.box_no_other as boxNoOther,
  296. w.title_no as titleNo,
  297. w.title_no_other as titleNoOther,
  298. w.cost as netWeightPrice,
  299. ROUND(w.gross_weight,2) as grossWeight,
  300. ROUND(w.tare,2) as tare,
  301. w.deduction_weight as buckleWeight,
  302. w.net_weight as netWeight,
  303. '' as unitDeduction,
  304. 0 as unloadingDeduction,
  305. '' as pureWeightPrice,
  306. case when w.goods_name like '%潮粮%' then w.pure_weight*1000 else w.net_weight*1000 end as pureWeight,
  307. 0 as amountIngPayable,
  308. 0 as amountEdPayable,
  309. '' as payeeName,
  310. '' as cardNo,
  311. '' as bankDeposit,
  312. '' as bankDepositBranch
  313. FROM warehouse_in_out_info w
  314. left join warehouse_in_out_detail d on w.id=d.info_id and d.delete_flag = 0
  315. left join warehouse_base_info b on b.id=w.base_id and b.delete_flag = 0
  316. left join common_company c on c.comp_id = b.comp_id and c.delete_flag = 0
  317. left join in_out_warehouse_task iowt on iowt.in_out_task_no = w.in_out_task_no and iowt.delete_flag = 0
  318. WHERE w.delete_flag = '0'
  319. AND b.comp_id = #{compId}
  320. and w.in_out_flag = 2
  321. and w.in_out_type='退库'
  322. and w.status_flag=3
  323. <if test="warehouseName != null and warehouseName != ''">
  324. AND w.warehouse_name= #{warehouseName}
  325. </if>
  326. <if test="startDate != null">
  327. AND (DATE_FORMAT(w.update_date,"%Y%m%d%H%i%s") &gt;=
  328. DATE_FORMAT(#{startDate},"%Y%m%d%H%i%s"))
  329. </if>
  330. <if test="endDate != null">
  331. AND (DATE_FORMAT(w.update_date,"%Y%m%d%H%i%s") &lt;=
  332. DATE_FORMAT(#{endDate},"%Y%m%d%H%i%s"))
  333. </if>
  334. group by w.id
  335. </select>
  336. <!-- 获得出库导出列表 -->
  337. <select id="getListByConditionOut" parameterType="Map"
  338. resultType="com.yh.saas.plugin.yiliangyiyun.entity.view.ExportVView">
  339. SELECT * from (SELECT
  340. '' as compName,
  341. w.warehouse_name as warehouseName,
  342. w.bin_number as binNumber,
  343. w.update_date as createDate,
  344. ROUND(sum(sri.avg_cost * sri.proportion * w.net_weight)/w.net_weight,2) as costPrice,
  345. -- w.warehouse_name as contractNo,
  346. case when m.contract_type = '1' then m.contract_no else '' end as contractNo,
  347. IFNULL(m.seller,'') as customerName,
  348. '' as remark,
  349. w.in_out_task_no as inOutTaskNo,
  350. w.goods_name as goodsName,
  351. case when w.goods_name like '%潮粮%' then '潮粮' else '干粮' end as type,
  352. w.grade as grade,
  353. d.water_content as waterContent,
  354. d.impurity as impurity,
  355. d.mildew_grain as mildewGrain,
  356. d.imperfect_grain as imperfectGrain,
  357. d.bulk_density as bulkDensity,
  358. d.jiaorenli as jiaorenli,
  359. w.car_no as carNo,
  360. w.box_no as boxNo,
  361. w.box_no_other as boxNoOther,
  362. w.title_no as titleNo,
  363. w.title_no_other as titleNoOther,
  364. w.wing_number as wingNumber,
  365. w.ship_number as shipNumber,
  366. w.ship_name as shipName,
  367. m.unit_contract_price as unitContractPrice,
  368. m.weight as weight,
  369. ROUND(w.gross_weight,2) as grossWeight,
  370. ROUND(w.tare,2) as tare,
  371. '' as contractStatus,
  372. IFNULL(t.unload_net_weight,0) as feedbackWeight,
  373. w.in_out_date as feedbackDate,
  374. w.net_weight as settlementWeight,
  375. 0 as settlementPrice,
  376. IFNULL(t.tran_price,0) as carFreight,
  377. '' as trainFreight,
  378. '' as shipFreight,
  379. IFNULL(t.tran_price,0) as freight,
  380. '' as amountIngReceivable,
  381. '' as amountEdReceivable,
  382. '' as amountNotReceivable,
  383. '' as collectionDate,
  384. '' as money,
  385. '' as status,
  386. w.net_weight as netWeight,
  387. tti.receive_warehouse as receiveWarehouse
  388. FROM warehouse_in_out_info w
  389. left join warehouse_in_out_detail d on w.id=d.info_id and d.delete_flag = 0
  390. left join tran_car_info t on t.contract_no = w.contract_no and t.delete_flag = 0 and t.tran_car_no = w.tran_car_no and t.car_no = w.car_no
  391. left join tran_task_info tti on tti.id = t.info_id and tti.delete_flag = 0
  392. left join warehouse_base_info b on b.id=w.base_id and b.delete_flag = 0
  393. left join contract_management_info m on m.comp_id = b.comp_id and m.contract_no = w.warehouse_name and m.delete_flag = 0
  394. left join in_out_warehouse_task iowt on iowt.in_out_task_no = w.in_out_task_no and iowt.delete_flag = 0
  395. left join source_relation_info sri on iowt.id = sri.task_id and sri.delete_flag = 0
  396. WHERE w.delete_flag = '0'
  397. AND b.comp_id = #{compId}
  398. and w.in_out_flag = 1
  399. and w.in_out_type='移库出库'
  400. and w.status_flag=3
  401. <if test="warehouseName != null and warehouseName != ''">
  402. AND w.warehouse_name= #{warehouseName}
  403. </if>
  404. <if test="startDate != null">
  405. AND (DATE_FORMAT(w.update_date,"%Y%m%d%H%i%s") &gt;=
  406. DATE_FORMAT(#{startDate},"%Y%m%d%H%i%s"))
  407. </if>
  408. <if test="endDate != null">
  409. AND (DATE_FORMAT(w.update_date,"%Y%m%d%H%i%s") &lt;=
  410. DATE_FORMAT(#{endDate},"%Y%m%d%H%i%s"))
  411. </if>
  412. GROUP BY w.id
  413. UNION ALL
  414. SELECT
  415. m.seller as compName,
  416. w.warehouse_name as warehouseName,
  417. w.bin_number as binNumber,
  418. s.delivery_date as createDate,ROUND(sum(sri.avg_cost * sri.proportion * w.net_weight)/w.net_weight ,2)as costPrice,
  419. case when m.contract_type = '1' then m.contract_no else '' end as contractNo,
  420. m.buyer as customerName,
  421. wm.customer as remark,
  422. w.in_out_task_no as inOutTaskNo,
  423. g.goods_name as goodsName,
  424. case when g.goods_name like '%潮粮%' then '潮粮' else '干粮' end as type,
  425. g.grade as grade,
  426. g.water_content as waterContent,
  427. g.impurity as impurity,
  428. g.mildew_grain as mildewGrain,
  429. g.imperfect_grain as imperfectGrain,
  430. g.bulk_density as bulkDensity,
  431. g.jiaorenli as jiaorenli,
  432. s.car_no as carNo,
  433. s.case_no as boxNo,
  434. s.case_no_other as boxNoOther,
  435. s.title_no as titleNo,
  436. s.title_no_other as titleNoOther,
  437. s.bin_number as wingNumber,
  438. '' as shipNumber,
  439. '' as shipName,
  440. m.unit_contract_price as unitContractPrice,
  441. m.weight as weight,
  442. ROUND(s.gross_weight,2) as grossWeight,
  443. ROUND(s.tare,2) as tare,
  444. CASE WHEN ( SELECT sum( ssrr.amount_not_receivable ) FROM stock_sale_receipt_report ssrr WHERE ssrr.contract_no
  445. = s.contract_no ) > 0 THEN
  446. '未结算' ELSE '已结算' END AS contractStatus,
  447. s.feedback_weight as feedbackWeight,
  448. s.feedback_date as feedbackDate,
  449. s.settlement_weight as settlementWeight,
  450. s.settlement_price as settlementPrice,
  451. case when p.tran_type_key = '1' then p.actual_freight else '' end as carFreight,
  452. case when p.tran_type_key = '2' then p.actual_freight else '' end as trainFreight,
  453. case when p.tran_type_key = '3' then p.actual_freight else '' end as shipFreight,
  454. case when m.deliver_type = '1' then IFNULL(r.amount_ed_payable,0) else 0 end as freight,
  455. s.amount_ing_receivable as amountIngReceivable,
  456. s.amount_ed_receivable as amountEdReceivable,
  457. s.amount_not_receivable as amountNotReceivable,
  458. s.collection_date as collectionDate,
  459. '' as money,
  460. s.status as status,
  461. s.net_weight as netWeight,
  462. t.receive_warehouse as receiveWarehouse
  463. FROM stock_sale_receipt_report s
  464. left join warehouse_in_out_info w on w.id = s.warehouse_record_id and w.delete_flag = 0
  465. left join weighing_management wm on wm.warehouse_in_out_id = w.id and wm.delete_flag = 0
  466. left join tran_process_info p on p.id = s.process_id and p.delete_flag = 0
  467. left join tran_task_info t on t.id = p.info_id and t.delete_flag = 0
  468. left join tran_car_info i on i.process_id = p.id and i.delete_flag = 0 and i.tran_car_no = s.tran_car_no and i.car_no = s.car_no
  469. left join tran_settlement_report r on r.car_id = i.id and r.delete_flag = 0
  470. left join contract_management_info m on m.contract_no = w.contract_no and m.comp_id=s.comp_id and m.delete_flag = 0
  471. left join contract_goods_info g on m.id = g.contract_id and g.delete_flag = 0
  472. left join in_out_warehouse_task iowt on iowt.in_out_task_no = w.in_out_task_no and iowt.delete_flag = 0
  473. left join source_relation_info sri on iowt.id = sri.task_id and sri.delete_flag = 0
  474. WHERE s.delete_flag = '0'
  475. AND s.comp_id = #{compId}
  476. and w.in_out_type='销售出库'
  477. <if test="warehouseName != null and warehouseName != ''">
  478. AND s.warehouse_name= #{warehouseName}
  479. </if>
  480. <if test="startDate != null">
  481. AND (DATE_FORMAT(s.delivery_date,"%Y%m%d%H%i%s") &gt;=
  482. DATE_FORMAT(#{startDate},"%Y%m%d%H%i%s"))
  483. </if>
  484. <if test="endDate != null">
  485. AND (DATE_FORMAT(s.delivery_date,"%Y%m%d%H%i%s") &lt;=
  486. DATE_FORMAT(#{endDate},"%Y%m%d%H%i%s"))
  487. </if>
  488. GROUP BY w.id
  489. ORDER BY contractNo) tt where tt.warehouseName is not null
  490. </select>
  491. <!-- 获得今日储量明细列表 -->
  492. <select id="getReservesDetailsListByCondition" parameterType="Map"
  493. resultType="com.yh.saas.plugin.yiliangyiyun.entity.view.WarehouseNumView">
  494. SELECT
  495. wpsi.goods_name as goodsName,
  496. sum( wpsi.`storage` ) as stockNum,
  497. (
  498. SELECT
  499. sum( tci.load_net_weight )
  500. FROM
  501. tran_task_info tti
  502. LEFT JOIN tran_car_info tci ON tci.info_id = tti.id
  503. AND tci.delete_flag = 0
  504. AND tci.comp_id = #{compId}
  505. WHERE
  506. tti.task_type = '移库'
  507. AND tti.goods_name = wpsi.goods_name
  508. AND tti.delete_flag = 0
  509. AND tci.status_flag = 3
  510. <if test="compId != null and compId != ''">
  511. AND tti.comp_id = #{compId}
  512. </if>
  513. )as moveNum/* 移库在途数量,已发出未反馈 */,
  514. (
  515. SELECT
  516. SUM(ROUND((cpi.mildew_grain - tt.total)/cmi.unit_contract_price ,3))
  517. FROM
  518. (
  519. SELECT
  520. cmi.contract_no,
  521. cgi.goods_name,
  522. sum( sprr.amount_not_payable ) AS total
  523. FROM
  524. contract_management_info cmi
  525. LEFT JOIN contract_goods_info cgi ON cgi.contract_id = cmi.id
  526. AND cgi.delete_flag = 0
  527. LEFT JOIN stock_purchase_receipt_report sprr ON sprr.contract_no = cmi.contract_no
  528. AND sprr.delete_flag = 0
  529. WHERE
  530. cmi.contract_type = 2
  531. AND cmi.delete_flag = 0
  532. AND sprr.amount_not_payable IS NOT NULL
  533. <if test="compId != null and compId != ''">
  534. AND cmi.comp_id = #{compId}
  535. </if>
  536. GROUP BY
  537. cmi.contract_no,
  538. cgi.goods_name
  539. ) tt
  540. LEFT JOIN contract_management_info cmi ON cmi.contract_no = tt.contract_no
  541. AND cmi.delete_flag = 0
  542. LEFT JOIN contract_process_info cpi ON cpi.contract_id = cmi.id
  543. AND cpi.delete_flag = 0
  544. WHERE
  545. tt.goods_name = wpsi.goods_name
  546. <if test="compId != null and compId != ''">
  547. AND cmi.comp_id= #{compId}
  548. </if>
  549. AND tt.total &lt; cpi.mildew_grain
  550. ) as purchaseNum/* 采购在途数量,合同已付减应付除以单价得到吨数 */,
  551. (
  552. SELECT
  553. sum( tci.load_net_weight )
  554. FROM
  555. tran_task_info tti
  556. LEFT JOIN tran_car_info tci ON tci.info_id = tti.id
  557. AND tci.delete_flag = 0
  558. WHERE
  559. tti.task_type = '销售出库'
  560. AND tti.goods_name = wpsi.goods_name
  561. AND tti.delete_flag = 0
  562. AND tci.status_flag = 3
  563. AND tci.comp_id = #{compId}
  564. AND tti.comp_id = #{compId}
  565. ) as saleNum
  566. FROM
  567. warehouse_base_info wbi
  568. LEFT JOIN warehouse_position_info wpi ON wpi.base_id = wbi.id and wpi.delete_flag = 0
  569. LEFT JOIN warehouse_position_storage_info wpsi ON wpsi.position_id = wpi.id and wpsi.delete_flag = 0
  570. WHERE
  571. 1 = 1
  572. <if test="compId != null and compId != ''">
  573. AND wbi.comp_id= #{compId}
  574. </if>
  575. AND wpsi.id IS NOT NULL
  576. GROUP BY
  577. wpsi.goods_name
  578. order by wpsi.goods_name_key
  579. </select>
  580. <!-- 获得储量柱形图 -->
  581. <select id="getReservesWarehouseListByCondition" parameterType="Map"
  582. resultType="com.yh.saas.plugin.yiliangyiyun.entity.view.WarehouseNumView">
  583. SELECT
  584. wpsi.goods_name AS goodsName,
  585. sum( wpsi.STORAGE ) AS stockNum,
  586. (
  587. SELECT
  588. ROUND( AVG( wo.avg_cost ), 3 )
  589. FROM
  590. warehousing_order wo
  591. WHERE
  592. wo.warehouse_name = wbi.warehouse_name
  593. AND wo.delete_flag = 0
  594. AND wbi.comp_id = wo.comp_id
  595. and wo.goods_name = wpsi.goods_name
  596. ) AS cost
  597. FROM
  598. warehouse_base_info wbi
  599. LEFT JOIN warehouse_position_info wpi ON wpi.base_id = wbi.id
  600. AND wpi.delete_flag = 0
  601. LEFT JOIN warehouse_position_storage_info wpsi ON wpsi.position_id = wpi.id
  602. AND wpsi.delete_flag = 0
  603. WHERE
  604. wpsi.id IS NOT NULL
  605. <if test="compId != null and compId != ''">
  606. AND wbi.comp_id= #{compId}
  607. </if>
  608. <if test="warehouseName != null and warehouseName != ''">
  609. AND wbi.warehouse_name= #{warehouseName}
  610. </if>
  611. GROUP BY
  612. wpsi.goods_name_key
  613. </select>
  614. <select id="getAllWarehouseListByCondition" parameterType="Map"
  615. resultType="com.yh.saas.plugin.yiliangyiyun.entity.view.WarehouseView">
  616. SELECT
  617. wbi.warehouse_name as warehouseName,
  618. wpi.bin_number as binNumber,
  619. wpi.id as binNumberId,
  620. wpi.max_storage as capacity,
  621. (SELECT
  622. sum(wioi.net_weight)
  623. FROM
  624. warehouse_in_out_info wioi
  625. WHERE
  626. wioi.in_out_flag = '2'
  627. AND wioi.delete_flag=0
  628. AND wioi.status_flag=3
  629. and wioi.position_id=wpi.id
  630. and wioi.goods_name=wpsi.goods_name
  631. )as inNetWeight,/*入库量*/
  632. (SELECT
  633. sum(wioi.net_weight)
  634. FROM
  635. warehouse_in_out_info wioi
  636. WHERE
  637. wioi.in_out_flag = '1'
  638. AND wioi.delete_flag=0
  639. AND wioi.status_flag=3
  640. and wioi.position_id=wpi.id
  641. and wioi.goods_name=wpsi.goods_name
  642. )as outNetWeight,/*出库量*/
  643. wpsi.storage as storage,
  644. wpsi.goods_name as goodsName
  645. FROM
  646. warehouse_base_info wbi
  647. LEFT JOIN warehouse_position_info wpi ON wpi.base_id = wbi.id
  648. LEFT JOIN warehouse_position_storage_info wpsi ON wpsi.position_id = wpi.id
  649. WHERE
  650. wbi.comp_id= #{compId}
  651. AND wbi.warehouse_type='1'
  652. <if test="warehouseName != null and warehouseName != ''">
  653. AND wbi.warehouse_name= #{warehouseName}
  654. </if>
  655. <if test="goodsName != null and goodsName != ''">
  656. AND wpsi.goods_name= #{goodsName}
  657. </if>
  658. GROUP BY
  659. wpi.id,wpsi.goods_name_key
  660. order by wbi.common_warehouse_no,wpi.bin_number
  661. </select>
  662. <!-- 出入库质检用 -->
  663. <select id="getTranCarInfo" parameterType="Map"
  664. resultType="com.yh.saas.plugin.yiliangyiyun.entity.TranCarInfo">
  665. SELECT
  666. wbi.id as contractId,
  667. wpi.*
  668. FROM
  669. contract_management_info wbi
  670. LEFT JOIN tran_car_info wpi ON wpi.contract_no = wbi.contract_no
  671. WHERE
  672. wbi.delete_flag ='0'
  673. AND
  674. wpi.delete_flag ='0'
  675. <if test="compId != null and compId != ''">
  676. AND wbi.comp_id= #{compId}
  677. </if>
  678. <if test="contractType != null and contractType != ''">
  679. AND wbi.contract_type= #{contractType}
  680. </if>
  681. <if test="statusFlag != null and statusFlag != ''">
  682. AND wbi.status_flag= #{statusFlag}
  683. </if>
  684. <if test="deliverType != null and deliverType != ''">
  685. AND wbi.deliver_type= #{deliverType}
  686. </if>
  687. <if test="flag != null and flag = '1'">
  688. <if test="fleetFlag != null and fleetFlag != ''">
  689. AND wpi.fleet_flag= #{fleetFlag}
  690. </if>
  691. <if test="tranType != null and tranType != ''">
  692. AND wpi.tran_type= #{tranType}
  693. </if>
  694. <if test="threeTranType != null and threeTranType != ''">
  695. AND wpi.three_tran_type= #{threeTranType}
  696. </if>
  697. <if test="submit != null and submit != ''">
  698. AND wpi.submit= #{submit}
  699. </if>
  700. </if>
  701. <if test="flag != null and flag = '2'">
  702. and(
  703. <if test="tranType != null and tranType != ''">
  704. wpi.tran_type= #{tranType}
  705. </if>
  706. <if test="threeTranType != null and threeTranType != ''">
  707. or wpi.three_tran_type= #{threeTranType}
  708. </if>
  709. )
  710. </if>
  711. ORDER BY
  712. wbi.update_date;
  713. </select>
  714. <!--获得库点利润详情列表总数-->
  715. <select id="getBaseCountByCondition" parameterType="Map" resultType="java.lang.Integer">
  716. select
  717. count(1)
  718. from(
  719. SELECT
  720. COUNT(w.id)
  721. FROM
  722. warehouse_base_info w
  723. LEFT JOIN warehousing_order war ON war.base_id = w.id AND war.in_type = '收购入库'
  724. AND war.delete_flag = '0'
  725. WHERE
  726. w.comp_id = #{compId}
  727. AND w.warehouse_type = '1'
  728. <if test="searchKeyWord != null and searchKeyWord != ''">
  729. AND (lower(w.warehouse_name) like lower(CONCAT('%',#{searchKeyWord},'%')))
  730. </if>
  731. GROUP BY
  732. w.id)t
  733. </select>
  734. <!--库点利润详情列表查询-->
  735. <select id="getBaseListByCondition" parameterType="Map"
  736. resultType="com.yh.saas.plugin.yiliangyiyun.entity.WarehouseBaseInfo">
  737. SELECT
  738. w.id,
  739. w.comp_id AS compId,
  740. CASE
  741. WHEN w.delete_flag = '1' THEN
  742. CONCAT( w.warehouse_name, '(已删)' ) ELSE w.warehouse_name
  743. END AS warehouseName,
  744. sum( war.in_warehouse_weight ) AS acquisitionWeight,
  745. (SELECT
  746. sum(ssrr.settlement_weight)*sri.proportion
  747. FROM
  748. warehouse_base_info wbi
  749. LEFT JOIN warehousing_order ward ON ward.base_id = wbi.id
  750. AND ward.in_type = '收购入库'
  751. AND ward.delete_flag = '0'
  752. LEFT JOIN source_relation_info sri ON sri.source_id = ward.id
  753. AND sri.delete_flag = '0'
  754. LEFT JOIN in_out_warehouse_task iowt ON iowt.id = sri.task_id
  755. AND iowt.in_out_flag = 1
  756. AND iowt.in_out_type_key = 1
  757. AND iowt.delete_flag = '0'
  758. LEFT JOIN warehouse_in_out_info wioi1 ON wioi1.in_out_task_no = iowt.in_out_task_no
  759. AND wioi1.delete_flag = 0
  760. AND wioi1.status_flag = 3
  761. LEFT JOIN stock_sale_receipt_report ssrr ON ssrr.contract_no = iowt.contract_no
  762. AND ssrr.warehouse_record_id = wioi1.id
  763. where wbi.id=w.id) as saleWeight,
  764. (SELECT
  765. sum(ssrr.amount_ing_receivable)*sri.proportion
  766. FROM
  767. warehouse_base_info wbi
  768. LEFT JOIN warehousing_order ward ON ward.base_id = wbi.id
  769. AND ward.in_type = '收购入库'
  770. AND ward.delete_flag = '0'
  771. LEFT JOIN source_relation_info sri ON sri.source_id = ward.id
  772. AND sri.delete_flag = '0'
  773. LEFT JOIN in_out_warehouse_task iowt ON iowt.id = sri.task_id
  774. AND iowt.in_out_flag = 1
  775. AND iowt.in_out_type_key = 1
  776. AND iowt.delete_flag = '0'
  777. LEFT JOIN warehouse_in_out_info wioi1 ON wioi1.in_out_task_no = iowt.in_out_task_no
  778. AND wioi1.delete_flag = 0
  779. AND wioi1.status_flag = 3
  780. LEFT JOIN stock_sale_receipt_report ssrr ON ssrr.contract_no = iowt.contract_no
  781. AND ssrr.warehouse_record_id = wioi1.id
  782. where wbi.id=w.id) as salesVolume,
  783. (
  784. SELECT
  785. IFNULL( SUM( ei.amount_money ), 0 )
  786. FROM
  787. expense_info ei
  788. WHERE
  789. ei.warehouse_id = w.id
  790. AND ei.delete_flag = '0'
  791. AND ei.expenses_type = '2'
  792. AND ei.expenses_purpose = '3'
  793. AND (DATE_FORMAT(ei.create_date,"%Y%m%d") &gt;=
  794. DATE_FORMAT(#{startDate},"%Y%m%d"))
  795. AND (DATE_FORMAT(ei.create_date,"%Y%m%d") &lt;=
  796. DATE_FORMAT(#{endDate},"%Y%m%d"))
  797. ) AS cost
  798. FROM
  799. warehouse_base_info w
  800. LEFT JOIN warehousing_order war ON war.base_id = w.id AND war.in_type = '收购入库'
  801. AND war.delete_flag = '0'
  802. -- LEFT JOIN source_relation_info sri ON sri.source_id = war.id
  803. -- AND sri.delete_flag = '0'
  804. -- LEFT JOIN in_out_warehouse_task iowt ON iowt.id = sri.task_id
  805. -- AND iowt.in_out_flag = 1
  806. -- AND iowt.in_out_type_key = 1
  807. -- AND iowt.delete_flag = '0'
  808. -- LEFT JOIN warehouse_in_out_info wioi1 ON wioi1.in_out_task_no = iowt.in_out_task_no
  809. -- AND wioi1.car_no = sri.car_no
  810. -- AND wioi1.delete_flag = 0
  811. -- AND wioi1.status_flag = 3
  812. -- LEFT JOIN stock_sale_receipt_report ssrr ON ssrr.contract_no = iowt.contract_no
  813. -- AND ssrr.warehouse_record_id = wioi1.id
  814. -- AND ssrr.delete_flag = 0
  815. -- LEFT JOIN expense_info ei ON ei.warehouse_id = w.id and ei.delete_flag = '0'
  816. -- AND ei.expenses_type = '2'
  817. -- AND ei.expenses_purpose = '3'
  818. WHERE
  819. w.comp_id = #{compId}
  820. AND w.warehouse_type = '1'
  821. <if test="searchKeyWord != null and searchKeyWord != ''">
  822. AND (lower(w.warehouse_name) like lower(CONCAT('%',#{searchKeyWord},'%')))
  823. </if>
  824. GROUP BY
  825. w.id
  826. ORDER BY
  827. w.delete_flag
  828. <if test="currentPage != null and currentPage != ''">
  829. LIMIT ${startRecord}, ${pageSize}
  830. </if>
  831. </select>
  832. <!-- 库点利润图 -->
  833. <select id="getWarehouseChartByCondition" parameterType="Map"
  834. resultType="com.yh.saas.plugin.yiliangyiyun.entity.WarehouseBaseInfo">
  835. SELECT
  836. pm.goods_name AS goodsName,
  837. SUM( IFNULL( sri.proportion, 1 ) * IFNULL( ssrr.amount_ing_receivable, 0 )) - sum( pm.amount_ing_payable ) AS profit
  838. FROM
  839. payment_management pm
  840. LEFT JOIN warehouse_base_info wbi ON wbi.warehouse_name = pm.warehouse_name
  841. AND wbi.comp_id = pm.comp_id
  842. AND wbi.delete_flag = 0
  843. LEFT JOIN warehousing_order war ON war.base_id = wbi.id
  844. AND war.in_type = '收购入库'
  845. AND war.comp_id = wbi.comp_id
  846. AND war.delete_flag = '0'
  847. LEFT JOIN source_relation_info sri ON sri.source_id = war.id
  848. AND sri.delete_flag = '0'
  849. LEFT JOIN in_out_warehouse_task iowt ON iowt.id = sri.task_id
  850. AND iowt.in_out_flag = 1
  851. AND iowt.in_out_type_key = 1
  852. AND iowt.delete_flag = '0'
  853. LEFT JOIN warehouse_in_out_info wioi1 ON wioi1.in_out_task_no = iowt.in_out_task_no
  854. AND wioi1.delete_flag = 0
  855. AND wioi1.status_flag = 3
  856. and wioi1.in_out_flag = 1
  857. LEFT JOIN stock_sale_receipt_report ssrr ON ssrr.warehouse_record_id = wioi1.id
  858. AND ssrr.delete_flag = 0
  859. WHERE
  860. pm.delete_flag = 0
  861. AND wbi.comp_id = #{compId}
  862. AND (DATE_FORMAT(pm.create_date,"%Y%m%d") &gt;=
  863. DATE_FORMAT(#{startDate},"%Y%m%d"))
  864. AND (DATE_FORMAT(pm.create_date,"%Y%m%d") &lt;=
  865. DATE_FORMAT(#{endDate},"%Y%m%d"))
  866. GROUP BY
  867. pm.goods_name;
  868. </select>
  869. <!-- 库点利润表 -->
  870. <select id="getWarehouseFormByCondition" parameterType="Map"
  871. resultType="com.yh.saas.plugin.yiliangyiyun.entity.WarehouseBaseInfo">
  872. SELECT
  873. '收购重量' AS type,
  874. sum( wioi.net_weight ) AS num
  875. FROM
  876. warehouse_in_out_info wioi
  877. LEFT JOIN warehouse_base_info wbi ON wbi.id = wioi.base_id
  878. AND wbi.delete_flag = 0
  879. WHERE
  880. wioi.in_out_type = '收购入库'
  881. AND wioi.status_flag = '3'
  882. AND wbi.comp_id =#{compId}
  883. AND (DATE_FORMAT(wioi.in_out_date,"%Y%m%d") &gt;=
  884. DATE_FORMAT(#{startDate},"%Y%m%d"))
  885. AND (DATE_FORMAT(wioi.in_out_date,"%Y%m%d") &lt;=
  886. DATE_FORMAT(#{endDate},"%Y%m%d"))
  887. UNION ALL
  888. SELECT
  889. '销售重量' AS type,
  890. sum( ssrr.settlement_weight ) AS num
  891. FROM
  892. warehouse_in_out_info wioi
  893. LEFT JOIN warehouse_base_info wbi ON wbi.id = wioi.base_id
  894. AND wbi.delete_flag = 0
  895. LEFT JOIN warehousing_order war ON war.base_id = wbi.id AND war.in_type = '收购入库'
  896. AND war.comp_id = wbi.comp_id
  897. AND war.delete_flag = '0'
  898. LEFT JOIN source_relation_info sri ON sri.source_id = war.id
  899. AND sri.delete_flag = '0'
  900. LEFT JOIN in_out_warehouse_task iowt ON iowt.id = sri.task_id
  901. AND iowt.in_out_flag = 1
  902. AND iowt.in_out_type_key = 1
  903. AND iowt.delete_flag = '0'
  904. LEFT JOIN warehouse_in_out_info wioi1 ON wioi1.in_out_task_no = iowt.in_out_task_no
  905. AND wioi1.car_no = sri.car_no
  906. AND wioi1.delete_flag = 0
  907. AND wioi1.status_flag = 3
  908. LEFT JOIN stock_sale_receipt_report ssrr ON ssrr.contract_no = iowt.contract_no
  909. AND ssrr.warehouse_record_id = wioi1.id
  910. AND ssrr.delete_flag = 0
  911. WHERE
  912. wioi.in_out_type = '收购入库'
  913. AND wioi.status_flag = '3'
  914. AND wbi.comp_id= #{compId}
  915. AND (DATE_FORMAT(wioi.in_out_date,"%Y%m%d") &gt;=
  916. DATE_FORMAT(#{startDate},"%Y%m%d"))
  917. AND (DATE_FORMAT(wioi.in_out_date,"%Y%m%d") &lt;=
  918. DATE_FORMAT(#{endDate},"%Y%m%d"))
  919. UNION ALL
  920. SELECT
  921. '支付粮款' AS type,
  922. sum( ei.amount_money ) AS num
  923. FROM
  924. expense_info ei
  925. WHERE
  926. ei.delete_flag = '0'
  927. AND ei.expenses_type = '2'
  928. AND ei.expenses_purpose = '3'
  929. AND ei.comp_id= #{compId}
  930. AND (DATE_FORMAT(ei.create_date,"%Y%m%d") &gt;=
  931. DATE_FORMAT(#{startDate},"%Y%m%d"))
  932. AND (DATE_FORMAT(ei.create_date,"%Y%m%d") &lt;=
  933. DATE_FORMAT(#{endDate},"%Y%m%d"))
  934. UNION ALL
  935. SELECT
  936. '收入粮款' AS type,
  937. sum( ei.amount_money ) AS num
  938. FROM
  939. expense_info ei
  940. WHERE
  941. ei.delete_flag = '0'
  942. AND ei.expenses_type = '1'
  943. AND ei.expenses_purpose = '3'
  944. AND ei.comp_id =#{compId}
  945. AND (DATE_FORMAT(ei.create_date,"%Y%m%d") &gt;=
  946. DATE_FORMAT(#{startDate},"%Y%m%d"))
  947. AND (DATE_FORMAT(ei.create_date,"%Y%m%d") &lt;=
  948. DATE_FORMAT(#{endDate},"%Y%m%d"))
  949. UNION ALL
  950. SELECT
  951. '其他支出' AS type,
  952. sum( ei.amount_money ) AS num
  953. FROM
  954. expense_info ei
  955. WHERE
  956. ei.delete_flag = '0'
  957. AND ei.expenses_type = '2'
  958. AND ei.expenses_purpose != '3'
  959. AND ei.comp_id =#{compId}
  960. AND (DATE_FORMAT(ei.create_date,"%Y%m%d") &gt;=
  961. DATE_FORMAT(#{startDate},"%Y%m%d"))
  962. AND (DATE_FORMAT(ei.create_date,"%Y%m%d") &lt;=
  963. DATE_FORMAT(#{endDate},"%Y%m%d"))
  964. UNION ALL
  965. SELECT
  966. '其他收入' AS type,
  967. sum( ei.amount_money ) AS num
  968. FROM
  969. expense_info ei
  970. WHERE
  971. ei.delete_flag = '0'
  972. AND ei.expenses_type = '1'
  973. AND ei.expenses_purpose != '3'
  974. AND ei.comp_id =#{compId}
  975. AND (DATE_FORMAT(ei.create_date,"%Y%m%d") &gt;=
  976. DATE_FORMAT(#{startDate},"%Y%m%d"))
  977. AND (DATE_FORMAT(ei.create_date,"%Y%m%d") &lt;=
  978. DATE_FORMAT(#{endDate},"%Y%m%d"))
  979. </select>
  980. </mapper>