DepotHeadMapperEx.xml 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422
  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.jsh.erp.datasource.mappers.DepotHeadMapperEx">
  4. <resultMap extends="com.jsh.erp.datasource.mappers.DepotHeadMapper.BaseResultMap" id="ResultMapEx" type="com.jsh.erp.datasource.vo.DepotHeadVo4List">
  5. <result column="depotHeadType" jdbcType="VARCHAR" property="depotHeadType" />
  6. <result column="OrganName" jdbcType="VARCHAR" property="organName" />
  7. <result column="userName" jdbcType="VARCHAR" property="userName" />
  8. <result column="AccountName" jdbcType="VARCHAR" property="accountName" />
  9. <result column="contacts" jdbcType="VARCHAR" property="contacts" />
  10. <result column="telephone" jdbcType="VARCHAR" property="telephone" />
  11. <result column="address" jdbcType="VARCHAR" property="address" />
  12. </resultMap>
  13. <resultMap id="ResultWithInfoExMap" type="com.jsh.erp.datasource.vo.DepotHeadVo4InDetail">
  14. <result column="number" jdbcType="VARCHAR" property="number" />
  15. <result column="barCode" jdbcType="VARCHAR" property="barCode" />
  16. <result column="mname" jdbcType="VARCHAR" property="mname" />
  17. <result column="model" jdbcType="VARCHAR" property="model" />
  18. <result column="standard" jdbcType="VARCHAR" property="standard" />
  19. <result column="color" jdbcType="VARCHAR" property="color" />
  20. <result column="brand" jdbcType="VARCHAR" property="brand" />
  21. <result column="mfrs" jdbcType="VARCHAR" property="mfrs" />
  22. <result column="unitPrice" jdbcType="DECIMAL" property="unitPrice" />
  23. <result column="sku" jdbcType="VARCHAR" property="sku" />
  24. <result column="operNumber" jdbcType="DECIMAL" property="operNumber" />
  25. <result column="allPrice" jdbcType="DECIMAL" property="allPrice" />
  26. <result column="taxRate" jdbcType="DECIMAL" property="taxRate" />
  27. <result column="taxMoney" jdbcType="DECIMAL" property="taxMoney" />
  28. <result column="taxLastMoney" jdbcType="DECIMAL" property="taxLastMoney" />
  29. <result column="sname" jdbcType="VARCHAR" property="sname" />
  30. <result column="dname" jdbcType="VARCHAR" property="dname" />
  31. <result column="operTime" jdbcType="VARCHAR" property="operTime" />
  32. <result column="newType" jdbcType="VARCHAR" property="newType" />
  33. </resultMap>
  34. <resultMap id="ResultInOutMaterialCount" type="com.jsh.erp.datasource.vo.DepotHeadVo4InOutMCount">
  35. <result column="materialId" jdbcType="BIGINT" property="materialId" />
  36. <result column="barCode" jdbcType="VARCHAR" property="barCode" />
  37. <result column="mName" jdbcType="VARCHAR" property="mName" />
  38. <result column="model" jdbcType="VARCHAR" property="model" />
  39. <result column="standard" jdbcType="VARCHAR" property="standard" />
  40. <result column="color" jdbcType="VARCHAR" property="color" />
  41. <result column="brand" jdbcType="VARCHAR" property="brand" />
  42. <result column="mfrs" jdbcType="VARCHAR" property="mfrs" />
  43. <result column="categoryName" jdbcType="VARCHAR" property="categoryName" />
  44. <result column="materialUnit" jdbcType="VARCHAR" property="materialUnit" />
  45. <result column="numSum" jdbcType="DECIMAL" property="numSum" />
  46. <result column="priceSum" jdbcType="DECIMAL" property="priceSum" />
  47. </resultMap>
  48. <resultMap id="ResultStatementAccount" type="com.jsh.erp.datasource.vo.DepotHeadVo4StatementAccount">
  49. <result column="number" jdbcType="VARCHAR" property="number" />
  50. <result column="type" jdbcType="VARCHAR" property="type" />
  51. <result column="discount_last_money" jdbcType="DECIMAL" property="discountLastMoney" />
  52. <result column="other_money" jdbcType="DECIMAL" property="otherMoney" />
  53. <result column="change_amount" jdbcType="DECIMAL" property="changeAmount" />
  54. <result column="supplierName" jdbcType="VARCHAR" property="supplierName" />
  55. <result column="oTime" jdbcType="VARCHAR" property="oTime" />
  56. </resultMap>
  57. <select id="selectByConditionDepotHead" parameterType="com.jsh.erp.datasource.entities.DepotHeadExample" resultMap="ResultMapEx">
  58. select jdh.*, s.supplier OrganName, u.username userName, a.name AccountName
  59. from (select dh.id
  60. from jsh_depot_head dh
  61. left join jsh_depot_item di on dh.id = di.header_id and ifnull(di.delete_flag,'0') !='1'
  62. left join jsh_material m on di.material_id = m.id and ifnull(m.delete_flag,'0') !='1'
  63. left join jsh_material_extend me on di.material_extend_id = me.id and ifnull(me.delete_flag,'0') !='1'
  64. where 1=1
  65. <if test="type != null">
  66. and dh.type=#{type}
  67. </if>
  68. <if test="subType != null">
  69. and dh.sub_type=#{subType}
  70. </if>
  71. <if test="statusArray != null and statusArray !=''">
  72. and dh.status in (
  73. <foreach collection="statusArray" item="status" separator=",">
  74. #{status}
  75. </foreach>
  76. )
  77. </if>
  78. <if test="purchaseStatusArray != null and purchaseStatusArray !=''">
  79. and dh.purchase_status in (
  80. <foreach collection="purchaseStatusArray" item="purchaseStatus" separator=",">
  81. #{purchaseStatus}
  82. </foreach>
  83. )
  84. </if>
  85. <if test="number != null">
  86. <bind name="bindNumber" value="'%'+number+'%'"/>
  87. and dh.number like #{bindNumber}
  88. </if>
  89. <if test="linkApply != null">
  90. <bind name="bindLinkApply" value="'%'+linkApply+'%'"/>
  91. and dh.link_apply like #{bindLinkApply}
  92. </if>
  93. <if test="linkNumber != null">
  94. <bind name="bindLinkNumber" value="'%'+linkNumber+'%'"/>
  95. and dh.link_number like #{bindLinkNumber}
  96. </if>
  97. <if test="beginTime != null">
  98. and dh.oper_time >= #{beginTime}
  99. </if>
  100. <if test="endTime != null">
  101. and dh.oper_time &lt;= #{endTime}
  102. </if>
  103. <if test="materialParam != null and materialParam !=''">
  104. <bind name="bindKey" value="'%'+materialParam+'%'"/>
  105. and (me.bar_code like #{bindKey} or me.batch_number like #{bindKey} or m.name like #{bindKey} or m.mnemonic like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey}
  106. or m.color like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
  107. or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
  108. </if>
  109. <if test="organId != null">
  110. and dh.organ_id=#{organId}
  111. </if>
  112. <if test="organArray != null and organArray !=''">
  113. and dh.organ_id in (
  114. <foreach collection="organArray" item="organId" separator=",">
  115. #{organId}
  116. </foreach>
  117. )
  118. </if>
  119. <if test="creator != null">
  120. and dh.creator=#{creator}
  121. </if>
  122. <if test="depotId != null">
  123. and di.depot_id=#{depotId}
  124. </if>
  125. <if test="depotArray != null and depotArray !=''">
  126. and di.depot_id in (
  127. <foreach collection="depotArray" item="depotId" separator=",">
  128. #{depotId}
  129. </foreach>
  130. )
  131. </if>
  132. <if test="creatorArray != null">
  133. and dh.creator in (
  134. <foreach collection="creatorArray" item="creator" separator=",">
  135. #{creator}
  136. </foreach>
  137. )
  138. </if>
  139. <if test="accountId != null">
  140. <bind name="bindAccountId" value="'%'+accountId+'%'"/>
  141. and (dh.account_id=#{accountId} or dh.account_id_list like #{bindAccountId})
  142. </if>
  143. <if test="hasDebt != null and hasDebt ==1">
  144. and
  145. (ifnull(dh.discount_last_money,0)+ifnull(dh.other_money,0)-ifnull(dh.deposit,0)-abs(ifnull(dh.change_amount,0))>0)
  146. </if>
  147. <if test="hasDebt != null and hasDebt ==0">
  148. and
  149. (ifnull(dh.discount_last_money,0)+ifnull(dh.other_money,0)-ifnull(dh.deposit,0)-abs(ifnull(dh.change_amount,0))=0)
  150. </if>
  151. <if test="remark != null and remark !=''">
  152. <bind name="bindRemark" value="'%'+remark+'%'"/>
  153. and (dh.remark like #{bindRemark} or di.remark like #{bindRemark})
  154. </if>
  155. and ifnull(dh.delete_flag,'0') !='1'
  156. group by dh.id
  157. order by dh.id desc) tb
  158. left join jsh_depot_head jdh on jdh.id=tb.id and ifnull(jdh.delete_flag,'0') !='1'
  159. left join jsh_supplier s on jdh.organ_id=s.id and ifnull(s.delete_flag,'0') !='1'
  160. left join jsh_user u on jdh.creator=u.id
  161. left join jsh_account a on jdh.account_id=a.id and ifnull(a.delete_flag,'0') !='1'
  162. order by jdh.id desc
  163. </select>
  164. <select id="findMaterialsListMapByHeaderIdList" resultType="com.jsh.erp.datasource.vo.MaterialsListVo">
  165. select jsh_depot_item.header_id, group_concat(concat(jsh_material.name,' ',ifnull(jsh_material.standard,''),' ',
  166. ifnull(jsh_material.model,''),' ',ifnull(jsh_material.color,''))) as materialsList
  167. from jsh_depot_item
  168. left join jsh_material on jsh_depot_item.material_id = jsh_material.Id and ifnull(jsh_material.delete_Flag,'0') !='1'
  169. where 1=1
  170. <if test="idList.size()>0">
  171. and jsh_depot_item.header_id in
  172. <foreach collection="idList" item="item" index="index" separator="," open="(" close=")">
  173. #{item}
  174. </foreach>
  175. </if>
  176. and ifnull(jsh_depot_item.delete_flag,'0') !='1'
  177. group by jsh_depot_item.header_id
  178. </select>
  179. <select id="getMaterialCountListByHeaderIdList" resultType="com.jsh.erp.datasource.vo.MaterialCountVo">
  180. select header_id, sum(oper_number) materialCount from jsh_depot_item
  181. where 1=1
  182. <if test="idList.size()>0">
  183. and header_id in
  184. <foreach collection="idList" item="item" index="index" separator="," open="(" close=")">
  185. #{item}
  186. </foreach>
  187. </if>
  188. and ifnull(delete_flag,'0') !='1'
  189. group by header_id
  190. </select>
  191. <select id="findInOutDetail" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultWithInfoExMap">
  192. select dh.number,me.bar_code barCode, m.name mname,m.model,m.standard,m.color,m.brand,di.unit_price unitPrice,di.material_unit as mUnit, di.sku,
  193. di.oper_number operNumber,di.all_price allPrice, ifnull(di.tax_rate,0) taxRate, ifnull(di.tax_money,0) taxMoney, ifnull(di.tax_last_money,0) taxLastMoney,
  194. s.supplier sname,d.dname dname, date_format(dh.oper_time, '%Y-%m-%d') operTime, concat(dh.sub_type,dh.type) as newType,
  195. concat_ws(' ',dh.remark,di.remark) as newRemark
  196. from jsh_depot_head dh
  197. left join jsh_depot_item di on di.header_id=dh.id and ifnull(di.delete_flag,'0') !='1'
  198. left join jsh_material m on m.id=di.material_id and ifnull(m.delete_flag,'0') !='1'
  199. left join jsh_material_extend me on me.id=di.material_extend_id and ifnull(me.delete_Flag,'0') !='1'
  200. left join jsh_supplier s on s.id=dh.organ_id and ifnull(s.delete_Flag,'0') !='1'
  201. left join (select id,name as dName,delete_Flag from jsh_depot ) d on d.id=di.depot_id and ifnull(d.delete_Flag,'0') !='1'
  202. where dh.oper_time >=#{beginTime} and dh.oper_time &lt;=#{endTime}
  203. <if test="oId != null">
  204. and dh.organ_id = #{oId}
  205. </if>
  206. <if test="depotList.size()>0">
  207. and di.depot_id in
  208. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  209. #{item}
  210. </foreach>
  211. </if>
  212. <if test="type != null">
  213. and dh.type=#{type}
  214. </if>
  215. <if test="inOutManageFlag">
  216. and (dh.sub_type!='采购' and dh.sub_type!='采购退货' and dh.sub_type!='销售' and dh.sub_type!='销售退货')
  217. </if>
  218. <if test="creatorArray != null">
  219. and dh.creator in (
  220. <foreach collection="creatorArray" item="creator" separator=",">
  221. #{creator}
  222. </foreach>
  223. )
  224. </if>
  225. <if test="organArray != null and organArray !=''">
  226. and (dh.organ_id in (
  227. <foreach collection="organArray" item="organId" separator=",">
  228. #{organId}
  229. </foreach>
  230. ) or dh.sub_type='采购退货' or dh.sub_type='零售' or dh.sub_type='其它')
  231. </if>
  232. <if test="categoryList.size()>0">
  233. and m.category_id in
  234. <foreach collection="categoryList" item="item" index="index" separator="," open="(" close=")">
  235. #{item}
  236. </foreach>
  237. </if>
  238. <if test="forceFlag">
  239. and dh.status = '1'
  240. </if>
  241. <if test="number != null and number !=''">
  242. <bind name="bindNumber" value="'%'+number+'%'"/>
  243. and dh.number like #{bindNumber}
  244. </if>
  245. <if test="materialParam != null and materialParam !=''">
  246. <bind name="bindKey" value="'%'+materialParam+'%'"/>
  247. and (me.bar_code like #{bindKey} or me.batch_number like #{bindKey} or m.name like #{bindKey} or m.mnemonic like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey}
  248. or m.color like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
  249. or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
  250. </if>
  251. <if test="creator != null">
  252. and dh.creator=#{creator}
  253. </if>
  254. <if test="remark != null and remark !=''">
  255. <bind name="bindRemark" value="'%'+remark+'%'"/>
  256. and (dh.remark like #{bindRemark} or di.remark like #{bindRemark})
  257. </if>
  258. and dh.sub_type!='调拨'
  259. and ifnull(dh.delete_flag,'0') !='1'
  260. <if test="column == 'createTime'">
  261. order by oper_time desc,number desc
  262. </if>
  263. <if test="column != 'createTime'">
  264. order by ${column} ${order}
  265. </if>
  266. <if test="offset != null and rows != null">
  267. limit #{offset},#{rows}
  268. </if>
  269. </select>
  270. <select id="findInOutDetailCount" resultType="java.lang.Integer">
  271. select count(1)
  272. from jsh_depot_head dh
  273. left join jsh_depot_item di on di.header_id=dh.id and ifnull(di.delete_flag,'0') !='1'
  274. left join jsh_material m on m.id=di.material_id and ifnull(m.delete_Flag,'0') !='1'
  275. left join jsh_material_extend me on me.id=di.material_extend_id and ifnull(me.delete_Flag,'0') !='1'
  276. left join jsh_supplier s on s.id=dh.organ_id and ifnull(s.delete_Flag,'0') !='1'
  277. left join (select id,name as dName,delete_Flag from jsh_depot) d on d.id=di.depot_id and ifnull(d.delete_Flag,'0') !='1'
  278. where dh.oper_time >=#{beginTime} and dh.oper_time &lt;=#{endTime}
  279. <if test="oId != null">
  280. and dh.organ_id = #{oId}
  281. </if>
  282. <if test="depotList.size()>0">
  283. and di.depot_id in
  284. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  285. #{item}
  286. </foreach>
  287. </if>
  288. <if test="type != null">
  289. and dh.type=#{type}
  290. </if>
  291. <if test="inOutManageFlag">
  292. and (dh.sub_type!='采购' and dh.sub_type!='采购退货' and dh.sub_type!='销售' and dh.sub_type!='销售退货')
  293. </if>
  294. <if test="creatorArray != null">
  295. and dh.creator in (
  296. <foreach collection="creatorArray" item="creator" separator=",">
  297. #{creator}
  298. </foreach>
  299. )
  300. </if>
  301. <if test="organArray != null and organArray !=''">
  302. and (dh.organ_id in (
  303. <foreach collection="organArray" item="organId" separator=",">
  304. #{organId}
  305. </foreach>
  306. ) or dh.sub_type='采购退货' or dh.sub_type='零售' or dh.sub_type='其它')
  307. </if>
  308. <if test="categoryList.size()>0">
  309. and m.category_id in
  310. <foreach collection="categoryList" item="item" index="index" separator="," open="(" close=")">
  311. #{item}
  312. </foreach>
  313. </if>
  314. <if test="forceFlag">
  315. and dh.status = '1'
  316. </if>
  317. <if test="number != null and number !=''">
  318. <bind name="bindNumber" value="'%'+number+'%'"/>
  319. and dh.number like #{bindNumber}
  320. </if>
  321. <if test="materialParam != null and materialParam !=''">
  322. <bind name="bindKey" value="'%'+materialParam+'%'"/>
  323. and (me.bar_code like #{bindKey} or me.batch_number like #{bindKey} or m.name like #{bindKey} or m.mnemonic like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey}
  324. or m.color like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
  325. or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
  326. </if>
  327. <if test="creator != null">
  328. and dh.creator=#{creator}
  329. </if>
  330. <if test="remark != null and remark !=''">
  331. <bind name="bindRemark" value="'%'+remark+'%'"/>
  332. and (dh.remark like #{bindRemark} or di.remark like #{bindRemark})
  333. </if>
  334. and dh.sub_type!='调拨'
  335. and ifnull(dh.delete_flag,'0') !='1'
  336. </select>
  337. <select id="findInOutDetailStatistic" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultWithInfoExMap">
  338. select ifnull(sum(di.oper_number),0) operNumber, ifnull(sum(di.all_price),0) allPrice
  339. from jsh_depot_head dh
  340. left join jsh_depot_item di on di.header_id=dh.id and ifnull(di.delete_flag,'0') !='1'
  341. left join jsh_material m on m.id=di.material_id and ifnull(m.delete_flag,'0') !='1'
  342. left join jsh_material_extend me on me.id=di.material_extend_id and ifnull(me.delete_Flag,'0') !='1'
  343. left join jsh_supplier s on s.id=dh.organ_id and ifnull(s.delete_Flag,'0') !='1'
  344. left join (select id,name as dName,delete_Flag from jsh_depot ) d on d.id=di.depot_id and ifnull(d.delete_Flag,'0') !='1'
  345. where dh.oper_time >=#{beginTime} and dh.oper_time &lt;=#{endTime}
  346. <if test="oId != null">
  347. and dh.organ_id = #{oId}
  348. </if>
  349. <if test="depotList.size()>0">
  350. and di.depot_id in
  351. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  352. #{item}
  353. </foreach>
  354. </if>
  355. <if test="type != null">
  356. and dh.type=#{type}
  357. </if>
  358. <if test="inOutManageFlag">
  359. and (dh.sub_type!='采购' and dh.sub_type!='采购退货' and dh.sub_type!='销售' and dh.sub_type!='销售退货')
  360. </if>
  361. <if test="creatorArray != null">
  362. and dh.creator in (
  363. <foreach collection="creatorArray" item="creator" separator=",">
  364. #{creator}
  365. </foreach>
  366. )
  367. </if>
  368. <if test="organArray != null and organArray !=''">
  369. and (dh.organ_id in (
  370. <foreach collection="organArray" item="organId" separator=",">
  371. #{organId}
  372. </foreach>
  373. ) or dh.sub_type='采购退货' or dh.sub_type='零售' or dh.sub_type='其它')
  374. </if>
  375. <if test="categoryList.size()>0">
  376. and m.category_id in
  377. <foreach collection="categoryList" item="item" index="index" separator="," open="(" close=")">
  378. #{item}
  379. </foreach>
  380. </if>
  381. <if test="forceFlag">
  382. and dh.status = '1'
  383. </if>
  384. <if test="number != null and number !=''">
  385. <bind name="bindNumber" value="'%'+number+'%'"/>
  386. and dh.number like #{bindNumber}
  387. </if>
  388. <if test="materialParam != null and materialParam !=''">
  389. <bind name="bindKey" value="'%'+materialParam+'%'"/>
  390. and (me.bar_code like #{bindKey} or me.batch_number like #{bindKey} or m.name like #{bindKey} or m.mnemonic like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey}
  391. or m.color like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
  392. or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
  393. </if>
  394. <if test="creator != null">
  395. and dh.creator=#{creator}
  396. </if>
  397. <if test="remark != null and remark !=''">
  398. <bind name="bindRemark" value="'%'+remark+'%'"/>
  399. and (dh.remark like #{bindRemark} or di.remark like #{bindRemark})
  400. </if>
  401. and dh.sub_type!='调拨'
  402. and ifnull(dh.delete_flag,'0') !='1'
  403. </select>
  404. <select id="findInOutMaterialCount" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultInOutMaterialCount">
  405. select di.material_id materialId, me.bar_code barCode, m.name mName,m.model,m.standard,m.color,m.brand,
  406. mc.name categoryName,concat_ws('', m.unit, u.basic_unit) materialUnit,
  407. sum(di.basic_number) numSum,
  408. sum(di.all_price) priceSum
  409. from jsh_depot_head dh
  410. left join jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1'
  411. left join jsh_material m on m.id=di.material_id and ifnull(m.delete_flag,'0') !='1'
  412. left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
  413. left join jsh_material_extend me on me.material_id=m.id and ifnull(me.delete_Flag,'0') !='1'
  414. left join jsh_material_category mc on m.category_id=mc.Id and ifnull(mc.delete_flag,'0') !='1'
  415. where me.default_flag=1
  416. and (dh.type=#{type} or dh.sub_type='调拨') and dh.oper_time >=#{beginTime} and dh.oper_time &lt;=#{endTime}
  417. <if test="oId != null">
  418. and dh.organ_id = #{oId}
  419. </if>
  420. <if test="creatorArray != null">
  421. and dh.creator in (
  422. <foreach collection="creatorArray" item="creator" separator=",">
  423. #{creator}
  424. </foreach>
  425. )
  426. </if>
  427. <if test="organArray != null and organArray !=''">
  428. and (dh.organ_id in (
  429. <foreach collection="organArray" item="organId" separator=",">
  430. #{organId}
  431. </foreach>
  432. ) or dh.sub_type='采购退货' or dh.sub_type='零售' or dh.sub_type='其它')
  433. </if>
  434. <if test="depotList.size()>0">
  435. <if test="type == '入库'">
  436. and ((
  437. dh.sub_type!='调拨' and di.depot_id in
  438. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  439. #{item}
  440. </foreach>
  441. ) or (
  442. dh.sub_type='调拨' and di.another_depot_id in
  443. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  444. #{item}
  445. </foreach>
  446. ))
  447. </if>
  448. <if test="type == '出库'">
  449. and di.depot_id in
  450. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  451. #{item}
  452. </foreach>
  453. </if>
  454. </if>
  455. <if test="materialParam != null and materialParam !=''">
  456. <bind name="bindKey" value="'%'+materialParam+'%'"/>
  457. and (me.bar_code like #{bindKey} or me.batch_number like #{bindKey} or m.name like #{bindKey} or m.mnemonic like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey}
  458. or m.color like #{bindKey} like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
  459. or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
  460. </if>
  461. <if test="categoryList.size()>0">
  462. and m.category_id in
  463. <foreach collection="categoryList" item="item" index="index" separator="," open="(" close=")">
  464. #{item}
  465. </foreach>
  466. </if>
  467. <if test="forceFlag">
  468. and (dh.status = '1' or dh.status = '2' or dh.status = '3')
  469. </if>
  470. <if test="inOutManageFlag">
  471. and (dh.sub_type!='采购' and dh.sub_type!='采购退货' and dh.sub_type!='销售' and dh.sub_type!='销售退货')
  472. </if>
  473. and ifnull(dh.delete_flag,'0') !='1'
  474. group by di.material_id, me.bar_code, m.name,m.model,m.standard,m.color,m.brand,
  475. mc.name, m.unit, u.basic_unit
  476. <if test="column == 'createTime'">
  477. order by materialId desc
  478. </if>
  479. <if test="column != 'createTime'">
  480. order by ${column} ${order}
  481. </if>
  482. <if test="offset != null and rows != null">
  483. limit #{offset},#{rows}
  484. </if>
  485. </select>
  486. <select id="findInOutMaterialCountTotal" resultType="java.lang.Integer">
  487. select count(1) from
  488. (select di.material_id from jsh_depot_head dh
  489. left join jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1'
  490. left join jsh_material m on m.id=di.material_id and ifnull(m.delete_flag,'0') !='1'
  491. left join jsh_material_extend me on me.material_id=m.id and ifnull(me.delete_flag,'0') !='1'
  492. where me.default_flag=1
  493. and (dh.type=#{type} or dh.sub_type='调拨') and dh.oper_time >=#{beginTime} and dh.oper_time &lt;=#{endTime}
  494. <if test="oId != null">
  495. and dh.organ_id = #{oId}
  496. </if>
  497. <if test="creatorArray != null">
  498. and dh.creator in (
  499. <foreach collection="creatorArray" item="creator" separator=",">
  500. #{creator}
  501. </foreach>
  502. )
  503. </if>
  504. <if test="organArray != null and organArray !=''">
  505. and (dh.organ_id in (
  506. <foreach collection="organArray" item="organId" separator=",">
  507. #{organId}
  508. </foreach>
  509. ) or dh.sub_type='采购退货' or dh.sub_type='零售' or dh.sub_type='其它')
  510. </if>
  511. <if test="depotList.size()>0">
  512. <if test="type == '入库'">
  513. and ((
  514. dh.sub_type!='调拨' and di.depot_id in
  515. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  516. #{item}
  517. </foreach>
  518. ) or (
  519. dh.sub_type='调拨' and di.another_depot_id in
  520. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  521. #{item}
  522. </foreach>
  523. ))
  524. </if>
  525. <if test="type == '出库'">
  526. and di.depot_id in
  527. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  528. #{item}
  529. </foreach>
  530. </if>
  531. </if>
  532. <if test="materialParam != null and materialParam !=''">
  533. <bind name="bindKey" value="'%'+materialParam+'%'"/>
  534. and (me.bar_code like #{bindKey} or me.batch_number like #{bindKey} or m.name like #{bindKey} or m.mnemonic like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey}
  535. or m.color like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
  536. or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
  537. </if>
  538. <if test="categoryList.size()>0">
  539. and m.category_id in
  540. <foreach collection="categoryList" item="item" index="index" separator="," open="(" close=")">
  541. #{item}
  542. </foreach>
  543. </if>
  544. <if test="forceFlag">
  545. and (dh.status = '1' or dh.status = '2' or dh.status = '3')
  546. </if>
  547. <if test="inOutManageFlag">
  548. and (dh.sub_type!='采购' and dh.sub_type!='采购退货' and dh.sub_type!='销售' and dh.sub_type!='销售退货')
  549. </if>
  550. and ifnull(dh.delete_flag,'0') !='1'
  551. group by di.material_id) a
  552. </select>
  553. <select id="findInOutMaterialCountStatistic" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultInOutMaterialCount">
  554. select ifnull(sum(di.basic_number),0) numSum, ifnull(sum(di.all_price),0) priceSum
  555. from jsh_depot_head dh
  556. left join jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1'
  557. left join jsh_material m on m.id=di.material_id and ifnull(m.delete_flag,'0') !='1'
  558. left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
  559. left join jsh_material_extend me on me.material_id=m.id and ifnull(me.delete_Flag,'0') !='1'
  560. left join jsh_material_category mc on m.category_id=mc.Id and ifnull(mc.delete_flag,'0') !='1'
  561. where me.default_flag=1
  562. and (dh.type=#{type} or dh.sub_type='调拨') and dh.oper_time >=#{beginTime} and dh.oper_time &lt;=#{endTime}
  563. <if test="oId != null">
  564. and dh.organ_id = #{oId}
  565. </if>
  566. <if test="creatorArray != null">
  567. and dh.creator in (
  568. <foreach collection="creatorArray" item="creator" separator=",">
  569. #{creator}
  570. </foreach>
  571. )
  572. </if>
  573. <if test="organArray != null and organArray !=''">
  574. and (dh.organ_id in (
  575. <foreach collection="organArray" item="organId" separator=",">
  576. #{organId}
  577. </foreach>
  578. ) or dh.sub_type='采购退货' or dh.sub_type='零售' or dh.sub_type='其它')
  579. </if>
  580. <if test="depotList.size()>0">
  581. <if test="type == '入库'">
  582. and ((
  583. dh.sub_type!='调拨' and di.depot_id in
  584. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  585. #{item}
  586. </foreach>
  587. ) or (
  588. dh.sub_type='调拨' and di.another_depot_id in
  589. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  590. #{item}
  591. </foreach>
  592. ))
  593. </if>
  594. <if test="type == '出库'">
  595. and di.depot_id in
  596. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  597. #{item}
  598. </foreach>
  599. </if>
  600. </if>
  601. <if test="materialParam != null and materialParam !=''">
  602. <bind name="bindKey" value="'%'+materialParam+'%'"/>
  603. and (me.bar_code like #{bindKey} or me.batch_number like #{bindKey} or m.name like #{bindKey} or m.mnemonic like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey}
  604. or m.color like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
  605. or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
  606. </if>
  607. <if test="categoryList.size()>0">
  608. and m.category_id in
  609. <foreach collection="categoryList" item="item" index="index" separator="," open="(" close=")">
  610. #{item}
  611. </foreach>
  612. </if>
  613. <if test="forceFlag">
  614. and (dh.status = '1' or dh.status = '2' or dh.status = '3')
  615. </if>
  616. <if test="inOutManageFlag">
  617. and (dh.sub_type!='采购' and dh.sub_type!='采购退货' and dh.sub_type!='销售' and dh.sub_type!='销售退货')
  618. </if>
  619. and ifnull(dh.delete_flag,'0') !='1'
  620. </select>
  621. <select id="findAllocationDetail" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultWithInfoExMap">
  622. select dh.number,me.bar_code barCode, m.name mname,m.model,m.standard,m.color,m.brand,di.unit_price unitPrice,di.material_unit as mUnit,
  623. di.oper_number operNumber,di.all_price allPrice,sname, d.dName dname,date_format(dh.oper_time, '%Y-%m-%d') operTime,
  624. concat(dh.sub_type,dh.type) as newType, concat_ws(' ',dh.remark,di.remark) as newRemark
  625. from jsh_depot_head dh
  626. left join jsh_depot_item di on di.header_id=dh.id and ifnull(di.delete_flag,'0') !='1'
  627. left join jsh_material m on m.id=di.material_id and ifnull(m.delete_flag,'0') !='1'
  628. left join jsh_material_extend me on me.id=di.material_extend_id and ifnull(me.delete_Flag,'0') !='1'
  629. left join (select id,name as dName,delete_Flag from jsh_depot ) d on d.id=di.depot_id and ifnull(d.delete_Flag,'0') !='1'
  630. <!-- 调出仓库名查询 -->
  631. left join (select id as aid,name as sname,delete_Flag as adelete_Flag from jsh_depot ) ddd on ddd.aid=di.another_depot_id and ifnull(ddd.adelete_Flag,'0') !='1'
  632. where dh.oper_time >=#{beginTime} and dh.oper_time &lt;=#{endTime}
  633. <if test="depotFList.size()>0">
  634. and di.depot_id in
  635. <foreach collection="depotFList" item="item" index="index" separator="," open="(" close=")">
  636. #{item}
  637. </foreach>
  638. </if>
  639. <if test="depotList.size()>0">
  640. and di.another_depot_id in
  641. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  642. #{item}
  643. </foreach>
  644. </if>
  645. <if test="subType != null">
  646. and dh.sub_type=#{subType}
  647. </if>
  648. <if test="number != null and number !=''">
  649. <bind name="bindNumber" value="'%'+number+'%'"/>
  650. and dh.number like #{bindNumber}
  651. </if>
  652. <if test="creatorArray != null">
  653. and dh.creator in (
  654. <foreach collection="creatorArray" item="creator" separator=",">
  655. #{creator}
  656. </foreach>
  657. )
  658. </if>
  659. <if test="categoryList.size()>0">
  660. and m.category_id in
  661. <foreach collection="categoryList" item="item" index="index" separator="," open="(" close=")">
  662. #{item}
  663. </foreach>
  664. </if>
  665. <if test="forceFlag">
  666. and dh.status = '1'
  667. </if>
  668. <if test="materialParam != null and materialParam !=''">
  669. <bind name="bindKey" value="'%'+materialParam+'%'"/>
  670. and (me.bar_code like #{bindKey} or me.batch_number like #{bindKey} or m.name like #{bindKey} or m.mnemonic like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey}
  671. or m.color like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
  672. or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey} or dh.remark like #{bindKey})
  673. </if>
  674. <if test="remark != null and remark !=''">
  675. <bind name="bindRemark" value="'%'+remark+'%'"/>
  676. and (dh.remark like #{bindRemark} or di.remark like #{bindRemark})
  677. </if>
  678. and ifnull(dh.delete_flag,'0') !='1'
  679. <if test="column == 'createTime'">
  680. order by oper_time desc,number desc
  681. </if>
  682. <if test="column != 'createTime'">
  683. order by ${column} ${order}
  684. </if>
  685. <if test="offset != null and rows != null">
  686. limit #{offset},#{rows}
  687. </if>
  688. </select>
  689. <select id="findAllocationDetailCount" resultType="java.lang.Integer">
  690. select count(1)
  691. from jsh_depot_head dh
  692. left join jsh_depot_item di on di.header_id=dh.id and ifnull(di.delete_flag,'0') !='1'
  693. left join jsh_material m on m.id=di.material_id and ifnull(m.delete_Flag,'0') !='1'
  694. left join jsh_material_extend me on me.id=di.material_extend_id and ifnull(me.delete_Flag,'0') !='1'
  695. left join (select id,name as dName,delete_Flag from jsh_depot) d on d.id=di.depot_id and ifnull(d.delete_Flag,'0') !='1'
  696. where dh.oper_time >=#{beginTime} and dh.oper_time &lt;=#{endTime}
  697. <if test="depotFList.size()>0">
  698. and di.depot_id in
  699. <foreach collection="depotFList" item="item" index="index" separator="," open="(" close=")">
  700. #{item}
  701. </foreach>
  702. </if>
  703. <if test="depotList.size()>0">
  704. and di.another_depot_id in
  705. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  706. #{item}
  707. </foreach>
  708. </if>
  709. <if test="subType != null">
  710. and dh.sub_type=#{subType}
  711. </if>
  712. <if test="number != null and number !=''">
  713. <bind name="bindNumber" value="'%'+number+'%'"/>
  714. and dh.number like #{bindNumber}
  715. </if>
  716. <if test="creatorArray != null">
  717. and dh.creator in (
  718. <foreach collection="creatorArray" item="creator" separator=",">
  719. #{creator}
  720. </foreach>
  721. )
  722. </if>
  723. <if test="categoryList.size()>0">
  724. and m.category_id in
  725. <foreach collection="categoryList" item="item" index="index" separator="," open="(" close=")">
  726. #{item}
  727. </foreach>
  728. </if>
  729. <if test="forceFlag">
  730. and dh.status = '1'
  731. </if>
  732. <if test="materialParam != null and materialParam !=''">
  733. <bind name="bindKey" value="'%'+materialParam+'%'"/>
  734. and (me.bar_code like #{bindKey} or me.batch_number like #{bindKey} or m.name like #{bindKey} or m.mnemonic like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey}
  735. or m.color like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
  736. or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey} or dh.remark like #{bindKey})
  737. </if>
  738. <if test="remark != null and remark !=''">
  739. <bind name="bindRemark" value="'%'+remark+'%'"/>
  740. and (dh.remark like #{bindRemark} or di.remark like #{bindRemark})
  741. </if>
  742. and ifnull(dh.delete_flag,'0') !='1'
  743. </select>
  744. <select id="findAllocationStatistic" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultWithInfoExMap">
  745. select ifnull(sum(di.oper_number),0) operNumber, ifnull(sum(di.all_price),0) allPrice
  746. from jsh_depot_head dh
  747. left join jsh_depot_item di on di.header_id=dh.id and ifnull(di.delete_flag,'0') !='1'
  748. left join jsh_material m on m.id=di.material_id and ifnull(m.delete_flag,'0') !='1'
  749. left join jsh_material_extend me on me.id=di.material_extend_id and ifnull(me.delete_Flag,'0') !='1'
  750. left join (select id,name as dName,delete_Flag from jsh_depot ) d on d.id=di.depot_id and ifnull(d.delete_Flag,'0') !='1'
  751. <!-- 调出仓库名查询 -->
  752. left join (select id as aid,name as sname,delete_Flag as adelete_Flag from jsh_depot ) ddd on ddd.aid=di.another_depot_id and ifnull(ddd.adelete_Flag,'0') !='1'
  753. where dh.oper_time >=#{beginTime} and dh.oper_time &lt;=#{endTime}
  754. <if test="depotFList.size()>0">
  755. and di.depot_id in
  756. <foreach collection="depotFList" item="item" index="index" separator="," open="(" close=")">
  757. #{item}
  758. </foreach>
  759. </if>
  760. <if test="depotList.size()>0">
  761. and di.another_depot_id in
  762. <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
  763. #{item}
  764. </foreach>
  765. </if>
  766. <if test="subType != null">
  767. and dh.sub_type=#{subType}
  768. </if>
  769. <if test="number != null and number !=''">
  770. <bind name="bindNumber" value="'%'+number+'%'"/>
  771. and dh.number like #{bindNumber}
  772. </if>
  773. <if test="creatorArray != null">
  774. and dh.creator in (
  775. <foreach collection="creatorArray" item="creator" separator=",">
  776. #{creator}
  777. </foreach>
  778. )
  779. </if>
  780. <if test="categoryList.size()>0">
  781. and m.category_id in
  782. <foreach collection="categoryList" item="item" index="index" separator="," open="(" close=")">
  783. #{item}
  784. </foreach>
  785. </if>
  786. <if test="forceFlag">
  787. and dh.status = '1'
  788. </if>
  789. <if test="materialParam != null and materialParam !=''">
  790. <bind name="bindKey" value="'%'+materialParam+'%'"/>
  791. and (me.bar_code like #{bindKey} or me.batch_number like #{bindKey} or m.name like #{bindKey} or m.mnemonic like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey}
  792. or m.color like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
  793. or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey} or dh.remark like #{bindKey})
  794. </if>
  795. <if test="remark != null and remark !=''">
  796. <bind name="bindRemark" value="'%'+remark+'%'"/>
  797. and (dh.remark like #{bindRemark} or di.remark like #{bindRemark})
  798. </if>
  799. and ifnull(dh.delete_flag,'0') !='1'
  800. </select>
  801. <select id="getStatementAccount" resultType="com.jsh.erp.datasource.vo.DepotHeadVo4StatementAccount">
  802. select *, (preBackInMoney+preBackOutMoney) as preBackMoney, (backInMoney+backOutMoney) as backMoney from
  803. (select s.id, s.supplier, s.contacts, s.telephone, s.phone_num, s.email,
  804. -- 起始期初金额
  805. (case when s.type='供应商' then ifnull(s.begin_need_pay,0) else ifnull(s.begin_need_get,0) end) begin_need,
  806. -- 上期欠款金额
  807. (select
  808. ifnull(sum(dh.discount_last_money),0)+ifnull(sum(dh.other_money),0)-ifnull(sum(dh.deposit),0)-abs(ifnull(sum(dh.change_amount),0))
  809. from jsh_depot_head dh
  810. where dh.organ_id=s.id
  811. and dh.type=#{type} and dh.sub_type=#{subType}
  812. and dh.oper_time &lt;= #{beginTime}
  813. and ifnull(dh.delete_flag,'0') !='1') preDebtMoney,
  814. -- 上期退货的欠款金额
  815. (select
  816. ifnull(sum(dh.discount_last_money),0)+ifnull(sum(dh.other_money),0)-ifnull(sum(dh.deposit),0)-abs(ifnull(sum(dh.change_amount),0))
  817. from jsh_depot_head dh
  818. where dh.organ_id=s.id
  819. and dh.type=#{typeBack} and dh.sub_type=#{subTypeBack}
  820. and dh.oper_time &lt;= #{beginTime}
  821. and ifnull(dh.delete_flag,'0') !='1') preReturnDebtMoney,
  822. -- 上期收款
  823. (select ifnull(sum(ai.each_amount),0) from jsh_account_item ai
  824. left join jsh_account_head ah on ai.header_id=ah.id and ifnull(ah.delete_flag,'0') !='1'
  825. where ah.organ_id=s.id and ah.type='收款'
  826. and ah.bill_time &lt;= #{beginTime}
  827. and ifnull(ai.delete_flag,'0') !='1') preBackInMoney,
  828. -- 上期付款
  829. (select 0-ifnull(sum(ai.each_amount),0) from jsh_account_item ai
  830. left join jsh_account_head ah on ai.header_id=ah.id and ifnull(ah.delete_flag,'0') !='1'
  831. where ah.organ_id=s.id and ah.type='付款'
  832. and ah.bill_time &lt;= #{beginTime}
  833. and ifnull(ai.delete_flag,'0') !='1') preBackOutMoney,
  834. -- 本期欠款
  835. (select
  836. ifnull(sum(dh.discount_last_money),0)+ifnull(sum(dh.other_money),0)-ifnull(sum(dh.deposit),0)-abs(ifnull(sum(dh.change_amount),0))
  837. from jsh_depot_head dh
  838. where dh.organ_id=s.id
  839. and dh.type=#{type} and dh.sub_type=#{subType}
  840. and dh.oper_time>#{beginTime} and dh.oper_time &lt;= #{endTime}
  841. and ifnull(dh.delete_flag,'0') !='1') debtMoney,
  842. -- 本期退货的欠款金额
  843. (select
  844. ifnull(sum(dh.discount_last_money),0)+ifnull(sum(dh.other_money),0)-ifnull(sum(dh.deposit),0)-abs(ifnull(sum(dh.change_amount),0))
  845. from jsh_depot_head dh
  846. where dh.organ_id=s.id
  847. and dh.type=#{typeBack} and dh.sub_type=#{subTypeBack}
  848. and dh.oper_time>#{beginTime} and dh.oper_time &lt;= #{endTime}
  849. and ifnull(dh.delete_flag,'0') !='1') returnDebtMoney,
  850. -- 本期收款
  851. (select ifnull(sum(ai.each_amount),0) from jsh_account_item ai
  852. left join jsh_account_head ah on ai.header_id=ah.id and ifnull(ah.delete_flag,'0') !='1'
  853. where ah.organ_id=s.id and ah.type='收款'
  854. and ah.bill_time>#{beginTime} and ah.bill_time &lt;= #{endTime}
  855. and ifnull(ai.delete_flag,'0') !='1') backInMoney,
  856. -- 本期付款
  857. (select 0-ifnull(sum(ai.each_amount),0) from jsh_account_item ai
  858. left join jsh_account_head ah on ai.header_id=ah.id and ifnull(ah.delete_flag,'0') !='1'
  859. where ah.organ_id=s.id and ah.type='付款'
  860. and ah.bill_time>#{beginTime} and ah.bill_time &lt;= #{endTime}
  861. and ifnull(ai.delete_flag,'0') !='1') backOutMoney
  862. from jsh_supplier s
  863. where s.enabled=1
  864. and s.type=#{supplierType}
  865. <if test="organId != null">
  866. and s.id = #{organId}
  867. </if>
  868. <if test="organArray != null and organArray !=''">
  869. and s.id in (
  870. <foreach collection="organArray" item="organId" separator=",">
  871. #{organId}
  872. </foreach>
  873. )
  874. </if>
  875. and ifnull(s.delete_flag,'0') !='1') tb
  876. <if test="hasDebt == 1">
  877. where begin_need+preDebtMoney-preReturnDebtMoney-preBackInMoney-preBackOutMoney+debtMoney-returnDebtMoney-backInMoney-backOutMoney!=0
  878. </if>
  879. <if test="hasDebt == 0">
  880. where begin_need+preDebtMoney-preReturnDebtMoney-preBackInMoney-preBackOutMoney+debtMoney-returnDebtMoney-backInMoney-backOutMoney=0
  881. </if>
  882. order by begin_need+preDebtMoney-preReturnDebtMoney-preBackInMoney-preBackOutMoney+debtMoney-returnDebtMoney-backInMoney-backOutMoney desc
  883. <if test="offset != null and rows != null">
  884. limit #{offset},#{rows}
  885. </if>
  886. </select>
  887. <select id="getStatementAccountCount" resultType="java.lang.Integer">
  888. select count(1) from
  889. (select s.id, s.supplier, s.contacts, s.telephone, s.phone_num, s.email,
  890. -- 起始期初金额
  891. (case when s.type='供应商' then ifnull(s.begin_need_pay,0) else ifnull(s.begin_need_get,0) end) begin_need,
  892. -- 上期欠款金额
  893. (select
  894. ifnull(sum(dh.discount_last_money),0)+ifnull(sum(dh.other_money),0)-ifnull(sum(dh.deposit),0)-abs(ifnull(sum(dh.change_amount),0))
  895. from jsh_depot_head dh
  896. where dh.organ_id=s.id
  897. and dh.type=#{type} and dh.sub_type=#{subType}
  898. and dh.oper_time &lt;= #{beginTime}
  899. and ifnull(dh.delete_flag,'0') !='1') preDebtMoney,
  900. -- 上期退货的欠款金额
  901. (select
  902. ifnull(sum(dh.discount_last_money),0)+ifnull(sum(dh.other_money),0)-ifnull(sum(dh.deposit),0)-abs(ifnull(sum(dh.change_amount),0))
  903. from jsh_depot_head dh
  904. where dh.organ_id=s.id
  905. and dh.type=#{typeBack} and dh.sub_type=#{subTypeBack}
  906. and dh.oper_time &lt;= #{beginTime}
  907. and ifnull(dh.delete_flag,'0') !='1') preReturnDebtMoney,
  908. -- 上期收款
  909. (select ifnull(sum(ai.each_amount),0) from jsh_account_item ai
  910. left join jsh_account_head ah on ai.header_id=ah.id and ifnull(ah.delete_flag,'0') !='1'
  911. where ah.organ_id=s.id and ah.type='收款'
  912. and ah.bill_time &lt;= #{beginTime}
  913. and ifnull(ai.delete_flag,'0') !='1') preBackInMoney,
  914. -- 上期付款
  915. (select 0-ifnull(sum(ai.each_amount),0) from jsh_account_item ai
  916. left join jsh_account_head ah on ai.header_id=ah.id and ifnull(ah.delete_flag,'0') !='1'
  917. where ah.organ_id=s.id and ah.type='付款'
  918. and ah.bill_time &lt;= #{beginTime}
  919. and ifnull(ai.delete_flag,'0') !='1') preBackOutMoney,
  920. -- 本期欠款
  921. (select
  922. ifnull(sum(dh.discount_last_money),0)+ifnull(sum(dh.other_money),0)-ifnull(sum(dh.deposit),0)-abs(ifnull(sum(dh.change_amount),0))
  923. from jsh_depot_head dh
  924. where dh.organ_id=s.id
  925. and dh.type=#{type} and dh.sub_type=#{subType}
  926. and dh.oper_time>#{beginTime} and dh.oper_time &lt;= #{endTime}
  927. and ifnull(dh.delete_flag,'0') !='1') debtMoney,
  928. -- 本期退货的欠款金额
  929. (select
  930. ifnull(sum(dh.discount_last_money),0)+ifnull(sum(dh.other_money),0)-ifnull(sum(dh.deposit),0)-abs(ifnull(sum(dh.change_amount),0))
  931. from jsh_depot_head dh
  932. where dh.organ_id=s.id
  933. and dh.type=#{typeBack} and dh.sub_type=#{subTypeBack}
  934. and dh.oper_time>#{beginTime} and dh.oper_time &lt;= #{endTime}
  935. and ifnull(dh.delete_flag,'0') !='1') returnDebtMoney,
  936. -- 本期收款
  937. (select ifnull(sum(ai.each_amount),0) from jsh_account_item ai
  938. left join jsh_account_head ah on ai.header_id=ah.id and ifnull(ah.delete_flag,'0') !='1'
  939. where ah.organ_id=s.id and ah.type='收款'
  940. and ah.bill_time>#{beginTime} and ah.bill_time &lt;= #{endTime}
  941. and ifnull(ai.delete_flag,'0') !='1') backInMoney,
  942. -- 本期付款
  943. (select 0-ifnull(sum(ai.each_amount),0) from jsh_account_item ai
  944. left join jsh_account_head ah on ai.header_id=ah.id and ifnull(ah.delete_flag,'0') !='1'
  945. where ah.organ_id=s.id and ah.type='付款'
  946. and ah.bill_time>#{beginTime} and ah.bill_time &lt;= #{endTime}
  947. and ifnull(ai.delete_flag,'0') !='1') backOutMoney
  948. from jsh_supplier s
  949. where s.enabled=1
  950. and s.type=#{supplierType}
  951. <if test="organId != null">
  952. and s.id = #{organId}
  953. </if>
  954. <if test="organArray != null and organArray !=''">
  955. and s.id in (
  956. <foreach collection="organArray" item="organId" separator=",">
  957. #{organId}
  958. </foreach>
  959. )
  960. </if>
  961. and ifnull(s.delete_flag,'0') !='1') tb
  962. <if test="hasDebt == 1">
  963. where begin_need+preDebtMoney-preReturnDebtMoney-preBackInMoney-preBackOutMoney+debtMoney-returnDebtMoney-backInMoney-backOutMoney!=0
  964. </if>
  965. <if test="hasDebt == 0">
  966. where begin_need+preDebtMoney-preReturnDebtMoney-preBackInMoney-preBackOutMoney+debtMoney-returnDebtMoney-backInMoney-backOutMoney=0
  967. </if>
  968. </select>
  969. <select id="getStatementAccountTotalPay" resultType="com.jsh.erp.datasource.vo.DepotHeadVo4StatementAccount">
  970. select sum(begin_need) begin_need, sum(preDebtMoney) preDebtMoney, sum(preReturnDebtMoney) preReturnDebtMoney, sum(preBackInMoney+preBackOutMoney) preBackMoney,
  971. sum(debtMoney) debtMoney, sum(returnDebtMoney) returnDebtMoney, sum(backInMoney+backOutMoney) backMoney from
  972. (select s.id,
  973. (case when s.type='供应商' then ifnull(s.begin_need_pay,0) else ifnull(s.begin_need_get,0) end) begin_need,
  974. (select
  975. ifnull(sum(dh.discount_last_money),0)+ifnull(sum(dh.other_money),0)-ifnull(sum(dh.deposit),0)-abs(ifnull(sum(dh.change_amount),0))
  976. from jsh_depot_head dh
  977. where dh.organ_id=s.id
  978. and dh.type=#{type} and dh.sub_type=#{subType}
  979. and dh.oper_time &lt;= #{beginTime}
  980. and ifnull(dh.delete_flag,'0') !='1') preDebtMoney,
  981. (select
  982. ifnull(sum(dh.discount_last_money),0)+ifnull(sum(dh.other_money),0)-ifnull(sum(dh.deposit),0)-abs(ifnull(sum(dh.change_amount),0))
  983. from jsh_depot_head dh
  984. where dh.organ_id=s.id
  985. and dh.type=#{typeBack} and dh.sub_type=#{subTypeBack}
  986. and dh.oper_time &lt;= #{beginTime}
  987. and ifnull(dh.delete_flag,'0') !='1') preReturnDebtMoney,
  988. (select ifnull(sum(ai.each_amount),0) from jsh_account_item ai
  989. left join jsh_account_head ah on ai.header_id=ah.id and ifnull(ah.delete_flag,'0') !='1'
  990. where ah.organ_id=s.id and ah.type='收款'
  991. and ah.bill_time &lt;= #{beginTime}
  992. and ifnull(ai.delete_flag,'0') !='1') preBackInMoney,
  993. (select 0-ifnull(sum(ai.each_amount),0) from jsh_account_item ai
  994. left join jsh_account_head ah on ai.header_id=ah.id and ifnull(ah.delete_flag,'0') !='1'
  995. where ah.organ_id=s.id and ah.type='付款'
  996. and ah.bill_time &lt;= #{beginTime}
  997. and ifnull(ai.delete_flag,'0') !='1') preBackOutMoney,
  998. (select
  999. ifnull(sum(dh.discount_last_money),0)+ifnull(sum(dh.other_money),0)-ifnull(sum(dh.deposit),0)-abs(ifnull(sum(dh.change_amount),0))
  1000. from jsh_depot_head dh
  1001. where dh.organ_id=s.id
  1002. and dh.type=#{type} and dh.sub_type=#{subType}
  1003. and dh.oper_time>#{beginTime} and dh.oper_time &lt;= #{endTime}
  1004. and ifnull(dh.delete_flag,'0') !='1') debtMoney,
  1005. (select
  1006. ifnull(sum(dh.discount_last_money),0)+ifnull(sum(dh.other_money),0)-ifnull(sum(dh.deposit),0)-abs(ifnull(sum(dh.change_amount),0))
  1007. from jsh_depot_head dh
  1008. where dh.organ_id=s.id
  1009. and dh.type=#{typeBack} and dh.sub_type=#{subTypeBack}
  1010. and dh.oper_time>#{beginTime} and dh.oper_time &lt;= #{endTime}
  1011. and ifnull(dh.delete_flag,'0') !='1') returnDebtMoney,
  1012. (select ifnull(sum(ai.each_amount),0) from jsh_account_item ai
  1013. left join jsh_account_head ah on ai.header_id=ah.id and ifnull(ah.delete_flag,'0') !='1'
  1014. where ah.organ_id=s.id and ah.type='收款'
  1015. and ah.bill_time>#{beginTime} and ah.bill_time &lt;= #{endTime}
  1016. and ifnull(ai.delete_flag,'0') !='1') backInMoney,
  1017. (select 0-ifnull(sum(ai.each_amount),0) from jsh_account_item ai
  1018. left join jsh_account_head ah on ai.header_id=ah.id and ifnull(ah.delete_flag,'0') !='1'
  1019. where ah.organ_id=s.id and ah.type='付款'
  1020. and ah.bill_time>#{beginTime} and ah.bill_time &lt;= #{endTime}
  1021. and ifnull(ai.delete_flag,'0') !='1') backOutMoney
  1022. from jsh_supplier s
  1023. where s.enabled=1
  1024. and s.type=#{supplierType}
  1025. <if test="organId != null">
  1026. and s.id = #{organId}
  1027. </if>
  1028. <if test="organArray != null and organArray !=''">
  1029. and s.id in (
  1030. <foreach collection="organArray" item="organId" separator=",">
  1031. #{organId}
  1032. </foreach>
  1033. )
  1034. </if>
  1035. and ifnull(s.delete_flag,'0') !='1') tb
  1036. <if test="hasDebt == 1">
  1037. where begin_need+preDebtMoney-preReturnDebtMoney-preBackInMoney-preBackOutMoney+debtMoney-returnDebtMoney-backInMoney-backOutMoney!=0
  1038. </if>
  1039. <if test="hasDebt == 0">
  1040. where begin_need+preDebtMoney-preReturnDebtMoney-preBackInMoney-preBackOutMoney+debtMoney-returnDebtMoney-backInMoney-backOutMoney=0
  1041. </if>
  1042. </select>
  1043. <select id="getDetailByNumber" parameterType="com.jsh.erp.datasource.entities.DepotHeadExample" resultMap="ResultMapEx">
  1044. select dh.*, concat(dh.sub_type,dh.type) as depotHeadType, a.name AccountName,
  1045. s.supplier OrganName, s.contacts, s.telephone, s.address
  1046. from jsh_depot_head dh
  1047. left join jsh_supplier s on dh.organ_id=s.id and ifnull(s.delete_Flag,'0') !='1'
  1048. left join jsh_account a on dh.account_id=a.id and ifnull(a.delete_Flag,'0') !='1'
  1049. where 1=1
  1050. <if test="number != null">
  1051. and dh.number=#{number}
  1052. </if>
  1053. and ifnull(dh.delete_flag,'0') !='1'
  1054. </select>
  1055. <update id="batchDeleteDepotHeadByIds">
  1056. update jsh_depot_head
  1057. set delete_flag='1'
  1058. where 1=1
  1059. and id in (
  1060. <foreach collection="ids" item="id" separator=",">
  1061. #{id}
  1062. </foreach>
  1063. )
  1064. </update>
  1065. <select id="getDepotHeadListByAccountIds" resultMap="com.jsh.erp.datasource.mappers.DepotHeadMapper.BaseResultMap">
  1066. select
  1067. <include refid="com.jsh.erp.datasource.mappers.DepotHeadMapper.Base_Column_List" />
  1068. from jsh_depot_head
  1069. where 1=1
  1070. and account_id in (
  1071. <foreach collection="accountIds" item="accountId" separator=",">
  1072. #{accountId}
  1073. </foreach>
  1074. )
  1075. and ifnull(delete_flag,'0') !='1'
  1076. </select>
  1077. <select id="getDepotHeadListByOrganIds" resultMap="com.jsh.erp.datasource.mappers.DepotHeadMapper.BaseResultMap">
  1078. select
  1079. <include refid="com.jsh.erp.datasource.mappers.DepotHeadMapper.Base_Column_List" />
  1080. from jsh_depot_head
  1081. where 1=1
  1082. and organ_id in (
  1083. <foreach collection="organIds" item="organId" separator=",">
  1084. #{organId}
  1085. </foreach>
  1086. )
  1087. and ifnull(delete_flag,'0') !='1'
  1088. </select>
  1089. <select id="getDepotHeadListByCreator" resultMap="com.jsh.erp.datasource.mappers.DepotHeadMapper.BaseResultMap">
  1090. select
  1091. <include refid="com.jsh.erp.datasource.mappers.DepotHeadMapper.Base_Column_List" />
  1092. from jsh_depot_head
  1093. where 1=1
  1094. and creator in (
  1095. <foreach collection="creatorArray" item="creator" separator=",">
  1096. #{creator}
  1097. </foreach>
  1098. )
  1099. and ifnull(delete_flag,'0') !='1'
  1100. </select>
  1101. <select id="getBuyAndSaleStatisticsList" resultType="com.jsh.erp.datasource.vo.InOutPriceVo">
  1102. select distinct dh.id, dh.discount_last_money, dh.total_price, dh.type, dh.sub_type, dh.oper_time
  1103. from jsh_depot_head dh
  1104. left join jsh_depot_item di on dh.id = di.header_id and ifnull(di.delete_flag,'0') !='1'
  1105. where di.id is not null
  1106. and (dh.type='入库' or dh.type='出库')
  1107. <if test="beginTime != null">
  1108. and dh.oper_time >= #{beginTime}
  1109. </if>
  1110. <if test="endTime != null">
  1111. and dh.oper_time &lt;= #{endTime}
  1112. </if>
  1113. <if test="forceFlag">
  1114. and (dh.status = '1' or dh.status = '2' or dh.status = '3')
  1115. </if>
  1116. <if test="creatorArray != null">
  1117. and dh.creator in (
  1118. <foreach collection="creatorArray" item="creator" separator=",">
  1119. #{creator}
  1120. </foreach>
  1121. )
  1122. </if>
  1123. and ifnull(dh.delete_flag,'0') !='1'
  1124. </select>
  1125. <select id="debtList" parameterType="com.jsh.erp.datasource.entities.DepotHeadExample" resultMap="ResultMapEx">
  1126. select distinct dh.*, s.supplier OrganName, u.username userName
  1127. from jsh_depot_head dh
  1128. left join jsh_supplier s on dh.organ_id=s.id and ifnull(s.delete_Flag,'0') !='1'
  1129. left join jsh_user u on dh.creator=u.id and ifnull(u.delete_flag,'0') !='1'
  1130. left join jsh_depot_item di on dh.id = di.header_id and ifnull(di.delete_flag,'0') !='1'
  1131. left join jsh_material m on di.material_id = m.id and ifnull(m.delete_flag,'0') !='1'
  1132. where 1=1
  1133. and (dh.type='入库' or dh.type='出库')
  1134. and (dh.sub_type='采购' or dh.sub_type='销售' or dh.sub_type='采购退货' or dh.sub_type='销售退货')
  1135. <if test="organId != null">
  1136. and dh.organ_id = #{organId}
  1137. </if>
  1138. <if test="status != null">
  1139. and dh.status =#{status}
  1140. </if>
  1141. <if test="number != null">
  1142. <bind name="bindNumber" value="'%'+number+'%'"/>
  1143. and dh.number like #{bindNumber}
  1144. </if>
  1145. <if test="beginTime != null">
  1146. and dh.oper_time >= #{beginTime}
  1147. </if>
  1148. <if test="endTime != null">
  1149. and dh.oper_time &lt;= #{endTime}
  1150. </if>
  1151. <if test="materialParam != null and materialParam !=''">
  1152. <bind name="bindKey" value="'%'+materialParam+'%'"/>
  1153. and (m.name like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey})
  1154. </if>
  1155. <if test="depotArray != null and depotArray !=''">
  1156. and di.depot_id in (
  1157. <foreach collection="depotArray" item="depotId" separator=",">
  1158. #{depotId}
  1159. </foreach>
  1160. )
  1161. </if>
  1162. <if test="creatorArray != null">
  1163. and dh.creator in (
  1164. <foreach collection="creatorArray" item="creator" separator=",">
  1165. #{creator}
  1166. </foreach>
  1167. )
  1168. </if>
  1169. and (ifnull(abs(dh.change_amount),0)+(select ifnull(sum(abs(ai.each_amount)),0) from jsh_account_item ai where ai.bill_id=dh.id and ifnull(ai.delete_flag,'0') !='1'))
  1170. &lt; (ifnull(dh.discount_last_money,0) + ifnull(dh.other_money,0) - ifnull(dh.deposit,0))
  1171. and ifnull(dh.delete_flag,'0') !='1'
  1172. order by dh.oper_time desc
  1173. <if test="offset != null and rows != null">
  1174. limit #{offset},#{rows}
  1175. </if>
  1176. </select>
  1177. <select id="debtListCount" resultType="java.lang.Integer">
  1178. select count(1) from (
  1179. select distinct dh.*, s.supplier OrganName, u.username userName
  1180. from jsh_depot_head dh
  1181. left join jsh_supplier s on dh.organ_id=s.id and ifnull(s.delete_Flag,'0') !='1'
  1182. left join jsh_user u on dh.creator=u.id and ifnull(u.delete_flag,'0') !='1'
  1183. left join jsh_depot_item di on dh.id = di.header_id and ifnull(di.delete_flag,'0') !='1'
  1184. left join jsh_material m on di.material_id = m.id and ifnull(m.delete_flag,'0') !='1'
  1185. where 1=1
  1186. and (dh.type='入库' or dh.type='出库')
  1187. and (dh.sub_type='采购' or dh.sub_type='销售' or dh.sub_type='采购退货' or dh.sub_type='销售退货')
  1188. <if test="organId != null">
  1189. and dh.organ_id = #{organId}
  1190. </if>
  1191. <if test="status != null">
  1192. and dh.status =#{status}
  1193. </if>
  1194. <if test="number != null">
  1195. <bind name="bindNumber" value="'%'+number+'%'"/>
  1196. and dh.number like #{bindNumber}
  1197. </if>
  1198. <if test="beginTime != null">
  1199. and dh.oper_time >= #{beginTime}
  1200. </if>
  1201. <if test="endTime != null">
  1202. and dh.oper_time &lt;= #{endTime}
  1203. </if>
  1204. <if test="materialParam != null and materialParam !=''">
  1205. <bind name="bindKey" value="'%'+materialParam+'%'"/>
  1206. and (m.name like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey})
  1207. </if>
  1208. <if test="depotArray != null and depotArray !=''">
  1209. and di.depot_id in (
  1210. <foreach collection="depotArray" item="depotId" separator=",">
  1211. #{depotId}
  1212. </foreach>
  1213. )
  1214. </if>
  1215. <if test="creatorArray != null">
  1216. and dh.creator in (
  1217. <foreach collection="creatorArray" item="creator" separator=",">
  1218. #{creator}
  1219. </foreach>
  1220. )
  1221. </if>
  1222. and (ifnull(abs(dh.change_amount),0)+(select ifnull(sum(abs(ai.each_amount)),0) from jsh_account_item ai where ai.bill_id=dh.id and ifnull(ai.delete_flag,'0') !='1'))
  1223. &lt; (ifnull(dh.discount_last_money,0) + ifnull(dh.other_money,0) - ifnull(dh.deposit,0))
  1224. and ifnull(dh.delete_flag,'0') !='1' ) tb
  1225. </select>
  1226. <select id="getFinishDepositByNumberList" resultType="com.jsh.erp.datasource.vo.FinishDepositVo">
  1227. select dh.link_number number, ifnull(sum(dh.deposit),0) finishDeposit
  1228. from jsh_depot_head dh
  1229. where 1=1
  1230. <if test="numberList.size()>0">
  1231. and dh.link_number in
  1232. <foreach collection="numberList" item="item" index="index" separator="," open="(" close=")">
  1233. #{item}
  1234. </foreach>
  1235. </if>
  1236. and ifnull(dh.delete_flag,'0') !='1'
  1237. group by dh.link_number
  1238. </select>
  1239. <select id="getFinishDepositByNumberExceptCurrent" resultType="java.math.BigDecimal">
  1240. select ifnull(sum(dh.deposit),0)
  1241. from jsh_depot_head dh
  1242. where dh.link_number=#{linkNumber}
  1243. and dh.number!=#{number}
  1244. and ifnull(dh.delete_flag,'0') !='1'
  1245. </select>
  1246. <update id="setAccountIdToNull">
  1247. update jsh_depot_head dh set dh.account_id = null
  1248. where dh.id=#{id}
  1249. and ifnull(dh.delete_flag,'0') !='1'
  1250. </update>
  1251. <select id="getSerialNumberBySell" resultType="java.lang.Integer">
  1252. select count(s.id) from jsh_depot_head dh
  1253. left join jsh_serial_number s on dh.number=s.in_bill_no
  1254. where dh.number = #{number}
  1255. and (s.out_bill_no is not null or s.out_bill_no!='')
  1256. </select>
  1257. <select id="waitBillList" parameterType="com.jsh.erp.datasource.entities.DepotHeadExample" resultMap="ResultMapEx">
  1258. select jdh.*, s.supplier OrganName, u.username userName, a.name AccountName
  1259. from (select dh.id
  1260. from jsh_depot_head dh
  1261. left join jsh_depot_item di on dh.id = di.header_id and ifnull(di.delete_flag,'0') !='1'
  1262. left join jsh_material m on di.material_id = m.id and ifnull(m.delete_flag,'0') !='1'
  1263. left join jsh_material_extend me on di.material_extend_id = me.id and ifnull(me.delete_flag,'0') !='1'
  1264. where 1=1
  1265. <if test="type != null">
  1266. and dh.type=#{type}
  1267. </if>
  1268. <if test="subTypeArray != null and subTypeArray !=''">
  1269. and dh.sub_type in (
  1270. <foreach collection="subTypeArray" item="subType" separator=",">
  1271. #{subType}
  1272. </foreach>
  1273. )
  1274. </if>
  1275. <if test="statusArray != null and statusArray !=''">
  1276. and dh.status in (
  1277. <foreach collection="statusArray" item="status" separator=",">
  1278. #{status}
  1279. </foreach>
  1280. )
  1281. </if>
  1282. <if test="number != null">
  1283. <bind name="bindNumber" value="'%'+number+'%'"/>
  1284. and dh.number like #{bindNumber}
  1285. </if>
  1286. <if test="beginTime != null">
  1287. and dh.oper_time >= #{beginTime}
  1288. </if>
  1289. <if test="endTime != null">
  1290. and dh.oper_time &lt;= #{endTime}
  1291. </if>
  1292. <if test="materialParam != null and materialParam !=''">
  1293. <bind name="bindKey" value="'%'+materialParam+'%'"/>
  1294. and (me.bar_code like #{bindKey} or me.batch_number like #{bindKey} or m.name like #{bindKey} or m.standard like #{bindKey} or m.model like
  1295. #{bindKey}
  1296. or m.color like #{bindKey} or m.other_field1 like #{bindKey}
  1297. or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
  1298. </if>
  1299. <if test="depotArray != null and depotArray !=''">
  1300. and di.depot_id in (
  1301. <foreach collection="depotArray" item="depotId" separator=",">
  1302. #{depotId}
  1303. </foreach>
  1304. )
  1305. </if>
  1306. <if test="creatorArray != null">
  1307. and dh.creator in (
  1308. <foreach collection="creatorArray" item="creator" separator=",">
  1309. #{creator}
  1310. </foreach>
  1311. )
  1312. </if>
  1313. and ifnull(dh.delete_flag,'0') !='1'
  1314. group by dh.id
  1315. order by dh.id desc
  1316. <if test="offset != null and rows != null">
  1317. limit #{offset},#{rows}
  1318. </if>) tb
  1319. left join jsh_depot_head jdh on jdh.id=tb.id and ifnull(jdh.delete_flag,'0') !='1'
  1320. left join jsh_supplier s on jdh.organ_id=s.id and ifnull(s.delete_flag,'0') !='1'
  1321. left join jsh_user u on jdh.creator=u.id and ifnull(u.delete_flag,'0') !='1'
  1322. left join jsh_account a on jdh.account_id=a.id and ifnull(a.delete_flag,'0') !='1'
  1323. </select>
  1324. <select id="waitBillCount" resultType="java.lang.Long">
  1325. select
  1326. count(1) from
  1327. (select distinct dh.id from jsh_depot_head dh
  1328. left join jsh_depot_item di on dh.Id = di.header_id and ifnull(di.delete_flag,'0') !='1'
  1329. left join jsh_material m on di.material_id = m.Id and ifnull(m.delete_Flag,'0') !='1'
  1330. left join jsh_material_extend me on di.material_extend_id = me.id and ifnull(me.delete_flag,'0') !='1'
  1331. WHERE 1=1
  1332. <if test="type != null">
  1333. and dh.type=#{type}
  1334. </if>
  1335. <if test="subTypeArray != null and subTypeArray !=''">
  1336. and dh.sub_type in (
  1337. <foreach collection="subTypeArray" item="subType" separator=",">
  1338. #{subType}
  1339. </foreach>
  1340. )
  1341. </if>
  1342. <if test="statusArray != null and statusArray !=''">
  1343. and dh.status in (
  1344. <foreach collection="statusArray" item="status" separator=",">
  1345. #{status}
  1346. </foreach>
  1347. )
  1348. </if>
  1349. <if test="number != null">
  1350. <bind name="bindNumber" value="'%'+number+'%'"/>
  1351. and dh.number like #{bindNumber}
  1352. </if>
  1353. <if test="beginTime != null">
  1354. and dh.oper_time >= #{beginTime}
  1355. </if>
  1356. <if test="endTime != null">
  1357. and dh.oper_time &lt;= #{endTime}
  1358. </if>
  1359. <if test="materialParam != null and materialParam !=''">
  1360. <bind name="bindKey" value="'%'+materialParam+'%'"/>
  1361. and (me.bar_code like #{bindKey} or me.batch_number like #{bindKey} or m.name like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey}
  1362. or m.color like #{bindKey} or m.other_field1 like #{bindKey}
  1363. or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
  1364. </if>
  1365. <if test="depotArray != null and depotArray !=''">
  1366. and di.depot_id in (
  1367. <foreach collection="depotArray" item="depotId" separator=",">
  1368. #{depotId}
  1369. </foreach>
  1370. )
  1371. </if>
  1372. <if test="creatorArray != null">
  1373. and dh.creator in (
  1374. <foreach collection="creatorArray" item="creator" separator=",">
  1375. #{creator}
  1376. </foreach>
  1377. )
  1378. </if>
  1379. and ifnull(dh.delete_Flag,'0') !='1') tb
  1380. </select>
  1381. <select id="getBillAllPriceByOrganId" resultType="java.math.BigDecimal">
  1382. select ifnull(sum(dh.total_price),0) allPrice from jsh_depot_head dh
  1383. where dh.organ_id=#{organId}
  1384. and dh.type = '出库'
  1385. and dh.sub_type = '零售'
  1386. and dh.pay_type = '预付款'
  1387. and ifnull(dh.delete_flag,'0') !='1'
  1388. </select>
  1389. </mapper>