123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.jsh.erp.datasource.mappers.DepotHeadMapperEx">
- <resultMap extends="com.jsh.erp.datasource.mappers.DepotHeadMapper.BaseResultMap" id="ResultMapEx" type="com.jsh.erp.datasource.vo.DepotHeadVo4List">
- <result column="depotHeadType" jdbcType="VARCHAR" property="depotHeadType" />
- <result column="OrganName" jdbcType="VARCHAR" property="organName" />
- <result column="userName" jdbcType="VARCHAR" property="userName" />
- <result column="AccountName" jdbcType="VARCHAR" property="accountName" />
- <result column="contacts" jdbcType="VARCHAR" property="contacts" />
- <result column="telephone" jdbcType="VARCHAR" property="telephone" />
- <result column="address" jdbcType="VARCHAR" property="address" />
- </resultMap>
- <resultMap id="ResultWithInfoExMap" type="com.jsh.erp.datasource.vo.DepotHeadVo4InDetail">
- <result column="number" jdbcType="VARCHAR" property="number" />
- <result column="barCode" jdbcType="VARCHAR" property="barCode" />
- <result column="mname" jdbcType="VARCHAR" property="mname" />
- <result column="model" jdbcType="VARCHAR" property="model" />
- <result column="standard" jdbcType="VARCHAR" property="standard" />
- <result column="color" jdbcType="VARCHAR" property="color" />
- <result column="brand" jdbcType="VARCHAR" property="brand" />
- <result column="mfrs" jdbcType="VARCHAR" property="mfrs" />
- <result column="unitPrice" jdbcType="DECIMAL" property="unitPrice" />
- <result column="sku" jdbcType="VARCHAR" property="sku" />
- <result column="operNumber" jdbcType="DECIMAL" property="operNumber" />
- <result column="allPrice" jdbcType="DECIMAL" property="allPrice" />
- <result column="taxRate" jdbcType="DECIMAL" property="taxRate" />
- <result column="taxMoney" jdbcType="DECIMAL" property="taxMoney" />
- <result column="taxLastMoney" jdbcType="DECIMAL" property="taxLastMoney" />
- <result column="sname" jdbcType="VARCHAR" property="sname" />
- <result column="dname" jdbcType="VARCHAR" property="dname" />
- <result column="operTime" jdbcType="VARCHAR" property="operTime" />
- <result column="newType" jdbcType="VARCHAR" property="newType" />
- </resultMap>
- <resultMap id="ResultInOutMaterialCount" type="com.jsh.erp.datasource.vo.DepotHeadVo4InOutMCount">
- <result column="materialId" jdbcType="BIGINT" property="materialId" />
- <result column="barCode" jdbcType="VARCHAR" property="barCode" />
- <result column="mName" jdbcType="VARCHAR" property="mName" />
- <result column="model" jdbcType="VARCHAR" property="model" />
- <result column="standard" jdbcType="VARCHAR" property="standard" />
- <result column="color" jdbcType="VARCHAR" property="color" />
- <result column="brand" jdbcType="VARCHAR" property="brand" />
- <result column="mfrs" jdbcType="VARCHAR" property="mfrs" />
- <result column="categoryName" jdbcType="VARCHAR" property="categoryName" />
- <result column="materialUnit" jdbcType="VARCHAR" property="materialUnit" />
- <result column="numSum" jdbcType="DECIMAL" property="numSum" />
- <result column="priceSum" jdbcType="DECIMAL" property="priceSum" />
- </resultMap>
- <resultMap id="ResultStatementAccount" type="com.jsh.erp.datasource.vo.DepotHeadVo4StatementAccount">
- <result column="number" jdbcType="VARCHAR" property="number" />
- <result column="type" jdbcType="VARCHAR" property="type" />
- <result column="discount_last_money" jdbcType="DECIMAL" property="discountLastMoney" />
- <result column="other_money" jdbcType="DECIMAL" property="otherMoney" />
- <result column="change_amount" jdbcType="DECIMAL" property="changeAmount" />
- <result column="supplierName" jdbcType="VARCHAR" property="supplierName" />
- <result column="oTime" jdbcType="VARCHAR" property="oTime" />
- </resultMap>
- <select id="selectByConditionDepotHead" parameterType="com.jsh.erp.datasource.entities.DepotHeadExample" resultMap="ResultMapEx">
- select jdh.*, s.supplier OrganName, u.username userName, a.name AccountName
- from (select dh.id
- from jsh_depot_head dh
- left join jsh_depot_item di on dh.id = di.header_id and ifnull(di.delete_flag,'0') !='1'
- left join jsh_material m on di.material_id = m.id and ifnull(m.delete_flag,'0') !='1'
- left join jsh_material_extend me on di.material_extend_id = me.id and ifnull(me.delete_flag,'0') !='1'
- where 1=1
- <if test="type != null">
- and dh.type=#{type}
- </if>
- <if test="subType != null">
- and dh.sub_type=#{subType}
- </if>
- <if test="statusArray != null and statusArray !=''">
- and dh.status in (
- <foreach collection="statusArray" item="status" separator=",">
- #{status}
- </foreach>
- )
- </if>
- <if test="purchaseStatusArray != null and purchaseStatusArray !=''">
- and dh.purchase_status in (
- <foreach collection="purchaseStatusArray" item="purchaseStatus" separator=",">
- #{purchaseStatus}
- </foreach>
- )
- </if>
- <if test="number != null">
- <bind name="bindNumber" value="'%'+number+'%'"/>
- and dh.number like #{bindNumber}
- </if>
- <if test="linkApply != null">
- <bind name="bindLinkApply" value="'%'+linkApply+'%'"/>
- and dh.link_apply like #{bindLinkApply}
- </if>
- <if test="linkNumber != null">
- <bind name="bindLinkNumber" value="'%'+linkNumber+'%'"/>
- and dh.link_number like #{bindLinkNumber}
- </if>
- <if test="beginTime != null">
- and dh.oper_time >= #{beginTime}
- </if>
- <if test="endTime != null">
- and dh.oper_time <= #{endTime}
- </if>
- <if test="materialParam != null and materialParam !=''">
- <bind name="bindKey" value="'%'+materialParam+'%'"/>
- 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}
- or m.color like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
- or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
- </if>
- <if test="organId != null">
- and dh.organ_id=#{organId}
- </if>
- <if test="organArray != null and organArray !=''">
- and dh.organ_id in (
- <foreach collection="organArray" item="organId" separator=",">
- #{organId}
- </foreach>
- )
- </if>
- <if test="creator != null">
- and dh.creator=#{creator}
- </if>
- <if test="depotId != null">
- and di.depot_id=#{depotId}
- </if>
- <if test="depotArray != null and depotArray !=''">
- and di.depot_id in (
- <foreach collection="depotArray" item="depotId" separator=",">
- #{depotId}
- </foreach>
- )
- </if>
- <if test="creatorArray != null">
- and dh.creator in (
- <foreach collection="creatorArray" item="creator" separator=",">
- #{creator}
- </foreach>
- )
- </if>
- <if test="accountId != null">
- <bind name="bindAccountId" value="'%'+accountId+'%'"/>
- and (dh.account_id=#{accountId} or dh.account_id_list like #{bindAccountId})
- </if>
- <if test="hasDebt != null and hasDebt ==1">
- and
- (ifnull(dh.discount_last_money,0)+ifnull(dh.other_money,0)-ifnull(dh.deposit,0)-abs(ifnull(dh.change_amount,0))>0)
- </if>
- <if test="hasDebt != null and hasDebt ==0">
- and
- (ifnull(dh.discount_last_money,0)+ifnull(dh.other_money,0)-ifnull(dh.deposit,0)-abs(ifnull(dh.change_amount,0))=0)
- </if>
- <if test="remark != null and remark !=''">
- <bind name="bindRemark" value="'%'+remark+'%'"/>
- and (dh.remark like #{bindRemark} or di.remark like #{bindRemark})
- </if>
- and ifnull(dh.delete_flag,'0') !='1'
- group by dh.id
- order by dh.id desc) tb
- left join jsh_depot_head jdh on jdh.id=tb.id and ifnull(jdh.delete_flag,'0') !='1'
- left join jsh_supplier s on jdh.organ_id=s.id and ifnull(s.delete_flag,'0') !='1'
- left join jsh_user u on jdh.creator=u.id
- left join jsh_account a on jdh.account_id=a.id and ifnull(a.delete_flag,'0') !='1'
- order by jdh.id desc
- </select>
- <select id="findMaterialsListMapByHeaderIdList" resultType="com.jsh.erp.datasource.vo.MaterialsListVo">
- select jsh_depot_item.header_id, group_concat(concat(jsh_material.name,' ',ifnull(jsh_material.standard,''),' ',
- ifnull(jsh_material.model,''),' ',ifnull(jsh_material.color,''))) as materialsList
- from jsh_depot_item
- left join jsh_material on jsh_depot_item.material_id = jsh_material.Id and ifnull(jsh_material.delete_Flag,'0') !='1'
- where 1=1
- <if test="idList.size()>0">
- and jsh_depot_item.header_id in
- <foreach collection="idList" item="item" index="index" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- and ifnull(jsh_depot_item.delete_flag,'0') !='1'
- group by jsh_depot_item.header_id
- </select>
- <select id="getMaterialCountListByHeaderIdList" resultType="com.jsh.erp.datasource.vo.MaterialCountVo">
- select header_id, sum(oper_number) materialCount from jsh_depot_item
- where 1=1
- <if test="idList.size()>0">
- and header_id in
- <foreach collection="idList" item="item" index="index" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- and ifnull(delete_flag,'0') !='1'
- group by header_id
- </select>
- <select id="findInOutDetail" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultWithInfoExMap">
- 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,
- 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,
- s.supplier sname,d.dname dname, date_format(dh.oper_time, '%Y-%m-%d') operTime, concat(dh.sub_type,dh.type) as newType,
- concat_ws(' ',dh.remark,di.remark) as newRemark
- from jsh_depot_head dh
- left join jsh_depot_item di on di.header_id=dh.id and ifnull(di.delete_flag,'0') !='1'
- left join jsh_material m on m.id=di.material_id and ifnull(m.delete_flag,'0') !='1'
- left join jsh_material_extend me on me.id=di.material_extend_id and ifnull(me.delete_Flag,'0') !='1'
- left join jsh_supplier s on s.id=dh.organ_id and ifnull(s.delete_Flag,'0') !='1'
- 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'
- where dh.oper_time >=#{beginTime} and dh.oper_time <=#{endTime}
- <if test="oId != null">
- and dh.organ_id = #{oId}
- </if>
- <if test="depotList.size()>0">
- and di.depot_id in
- <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="type != null">
- and dh.type=#{type}
- </if>
- <if test="inOutManageFlag">
- and (dh.sub_type!='采购' and dh.sub_type!='采购退货' and dh.sub_type!='销售' and dh.sub_type!='销售退货')
- </if>
- <if test="creatorArray != null">
- and dh.creator in (
- <foreach collection="creatorArray" item="creator" separator=",">
- #{creator}
- </foreach>
- )
- </if>
- <if test="organArray != null and organArray !=''">
- and (dh.organ_id in (
- <foreach collection="organArray" item="organId" separator=",">
- #{organId}
- </foreach>
- ) or dh.sub_type='采购退货' or dh.sub_type='零售' or dh.sub_type='其它')
- </if>
- <if test="categoryList.size()>0">
- and m.category_id in
- <foreach collection="categoryList" item="item" index="index" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="forceFlag">
- and dh.status = '1'
- </if>
- <if test="number != null and number !=''">
- <bind name="bindNumber" value="'%'+number+'%'"/>
- and dh.number like #{bindNumber}
- </if>
- <if test="materialParam != null and materialParam !=''">
- <bind name="bindKey" value="'%'+materialParam+'%'"/>
- 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}
- or m.color like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
- or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
- </if>
- <if test="creator != null">
- and dh.creator=#{creator}
- </if>
- <if test="remark != null and remark !=''">
- <bind name="bindRemark" value="'%'+remark+'%'"/>
- and (dh.remark like #{bindRemark} or di.remark like #{bindRemark})
- </if>
- and dh.sub_type!='调拨'
- and ifnull(dh.delete_flag,'0') !='1'
- <if test="column == 'createTime'">
- order by oper_time desc,number desc
- </if>
- <if test="column != 'createTime'">
- order by ${column} ${order}
- </if>
- <if test="offset != null and rows != null">
- limit #{offset},#{rows}
- </if>
- </select>
- <select id="findInOutDetailCount" resultType="java.lang.Integer">
- select count(1)
- from jsh_depot_head dh
- left join jsh_depot_item di on di.header_id=dh.id and ifnull(di.delete_flag,'0') !='1'
- left join jsh_material m on m.id=di.material_id and ifnull(m.delete_Flag,'0') !='1'
- left join jsh_material_extend me on me.id=di.material_extend_id and ifnull(me.delete_Flag,'0') !='1'
- left join jsh_supplier s on s.id=dh.organ_id and ifnull(s.delete_Flag,'0') !='1'
- 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'
- where dh.oper_time >=#{beginTime} and dh.oper_time <=#{endTime}
- <if test="oId != null">
- and dh.organ_id = #{oId}
- </if>
- <if test="depotList.size()>0">
- and di.depot_id in
- <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="type != null">
- and dh.type=#{type}
- </if>
- <if test="inOutManageFlag">
- and (dh.sub_type!='采购' and dh.sub_type!='采购退货' and dh.sub_type!='销售' and dh.sub_type!='销售退货')
- </if>
- <if test="creatorArray != null">
- and dh.creator in (
- <foreach collection="creatorArray" item="creator" separator=",">
- #{creator}
- </foreach>
- )
- </if>
- <if test="organArray != null and organArray !=''">
- and (dh.organ_id in (
- <foreach collection="organArray" item="organId" separator=",">
- #{organId}
- </foreach>
- ) or dh.sub_type='采购退货' or dh.sub_type='零售' or dh.sub_type='其它')
- </if>
- <if test="categoryList.size()>0">
- and m.category_id in
- <foreach collection="categoryList" item="item" index="index" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="forceFlag">
- and dh.status = '1'
- </if>
- <if test="number != null and number !=''">
- <bind name="bindNumber" value="'%'+number+'%'"/>
- and dh.number like #{bindNumber}
- </if>
- <if test="materialParam != null and materialParam !=''">
- <bind name="bindKey" value="'%'+materialParam+'%'"/>
- 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}
- or m.color like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
- or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
- </if>
- <if test="creator != null">
- and dh.creator=#{creator}
- </if>
- <if test="remark != null and remark !=''">
- <bind name="bindRemark" value="'%'+remark+'%'"/>
- and (dh.remark like #{bindRemark} or di.remark like #{bindRemark})
- </if>
- and dh.sub_type!='调拨'
- and ifnull(dh.delete_flag,'0') !='1'
- </select>
- <select id="findInOutDetailStatistic" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultWithInfoExMap">
- select ifnull(sum(di.oper_number),0) operNumber, ifnull(sum(di.all_price),0) allPrice
- from jsh_depot_head dh
- left join jsh_depot_item di on di.header_id=dh.id and ifnull(di.delete_flag,'0') !='1'
- left join jsh_material m on m.id=di.material_id and ifnull(m.delete_flag,'0') !='1'
- left join jsh_material_extend me on me.id=di.material_extend_id and ifnull(me.delete_Flag,'0') !='1'
- left join jsh_supplier s on s.id=dh.organ_id and ifnull(s.delete_Flag,'0') !='1'
- 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'
- where dh.oper_time >=#{beginTime} and dh.oper_time <=#{endTime}
- <if test="oId != null">
- and dh.organ_id = #{oId}
- </if>
- <if test="depotList.size()>0">
- and di.depot_id in
- <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="type != null">
- and dh.type=#{type}
- </if>
- <if test="inOutManageFlag">
- and (dh.sub_type!='采购' and dh.sub_type!='采购退货' and dh.sub_type!='销售' and dh.sub_type!='销售退货')
- </if>
- <if test="creatorArray != null">
- and dh.creator in (
- <foreach collection="creatorArray" item="creator" separator=",">
- #{creator}
- </foreach>
- )
- </if>
- <if test="organArray != null and organArray !=''">
- and (dh.organ_id in (
- <foreach collection="organArray" item="organId" separator=",">
- #{organId}
- </foreach>
- ) or dh.sub_type='采购退货' or dh.sub_type='零售' or dh.sub_type='其它')
- </if>
- <if test="categoryList.size()>0">
- and m.category_id in
- <foreach collection="categoryList" item="item" index="index" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="forceFlag">
- and dh.status = '1'
- </if>
- <if test="number != null and number !=''">
- <bind name="bindNumber" value="'%'+number+'%'"/>
- and dh.number like #{bindNumber}
- </if>
- <if test="materialParam != null and materialParam !=''">
- <bind name="bindKey" value="'%'+materialParam+'%'"/>
- 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}
- or m.color like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
- or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
- </if>
- <if test="creator != null">
- and dh.creator=#{creator}
- </if>
- <if test="remark != null and remark !=''">
- <bind name="bindRemark" value="'%'+remark+'%'"/>
- and (dh.remark like #{bindRemark} or di.remark like #{bindRemark})
- </if>
- and dh.sub_type!='调拨'
- and ifnull(dh.delete_flag,'0') !='1'
- </select>
- <select id="findInOutMaterialCount" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultInOutMaterialCount">
- select di.material_id materialId, me.bar_code barCode, m.name mName,m.model,m.standard,m.color,m.brand,
- mc.name categoryName,concat_ws('', m.unit, u.basic_unit) materialUnit,
- sum(di.basic_number) numSum,
- sum(di.all_price) priceSum
- from jsh_depot_head dh
- left join jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1'
- left join jsh_material m on m.id=di.material_id and ifnull(m.delete_flag,'0') !='1'
- left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
- left join jsh_material_extend me on me.material_id=m.id and ifnull(me.delete_Flag,'0') !='1'
- left join jsh_material_category mc on m.category_id=mc.Id and ifnull(mc.delete_flag,'0') !='1'
- where me.default_flag=1
- and (dh.type=#{type} or dh.sub_type='调拨') and dh.oper_time >=#{beginTime} and dh.oper_time <=#{endTime}
- <if test="oId != null">
- and dh.organ_id = #{oId}
- </if>
- <if test="creatorArray != null">
- and dh.creator in (
- <foreach collection="creatorArray" item="creator" separator=",">
- #{creator}
- </foreach>
- )
- </if>
- <if test="organArray != null and organArray !=''">
- and (dh.organ_id in (
- <foreach collection="organArray" item="organId" separator=",">
- #{organId}
- </foreach>
- ) or dh.sub_type='采购退货' or dh.sub_type='零售' or dh.sub_type='其它')
- </if>
- <if test="depotList.size()>0">
- <if test="type == '入库'">
- and ((
- dh.sub_type!='调拨' and di.depot_id in
- <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
- #{item}
- </foreach>
- ) or (
- dh.sub_type='调拨' and di.another_depot_id in
- <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
- #{item}
- </foreach>
- ))
- </if>
- <if test="type == '出库'">
- and di.depot_id in
- <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- </if>
- <if test="materialParam != null and materialParam !=''">
- <bind name="bindKey" value="'%'+materialParam+'%'"/>
- 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}
- or m.color like #{bindKey} like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
- or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
- </if>
- <if test="categoryList.size()>0">
- and m.category_id in
- <foreach collection="categoryList" item="item" index="index" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="forceFlag">
- and (dh.status = '1' or dh.status = '2' or dh.status = '3')
- </if>
- <if test="inOutManageFlag">
- and (dh.sub_type!='采购' and dh.sub_type!='采购退货' and dh.sub_type!='销售' and dh.sub_type!='销售退货')
- </if>
- and ifnull(dh.delete_flag,'0') !='1'
- group by di.material_id, me.bar_code, m.name,m.model,m.standard,m.color,m.brand,
- mc.name, m.unit, u.basic_unit
- <if test="column == 'createTime'">
- order by materialId desc
- </if>
- <if test="column != 'createTime'">
- order by ${column} ${order}
- </if>
- <if test="offset != null and rows != null">
- limit #{offset},#{rows}
- </if>
- </select>
- <select id="findInOutMaterialCountTotal" resultType="java.lang.Integer">
- select count(1) from
- (select di.material_id from jsh_depot_head dh
- left join jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1'
- left join jsh_material m on m.id=di.material_id and ifnull(m.delete_flag,'0') !='1'
- left join jsh_material_extend me on me.material_id=m.id and ifnull(me.delete_flag,'0') !='1'
- where me.default_flag=1
- and (dh.type=#{type} or dh.sub_type='调拨') and dh.oper_time >=#{beginTime} and dh.oper_time <=#{endTime}
- <if test="oId != null">
- and dh.organ_id = #{oId}
- </if>
- <if test="creatorArray != null">
- and dh.creator in (
- <foreach collection="creatorArray" item="creator" separator=",">
- #{creator}
- </foreach>
- )
- </if>
- <if test="organArray != null and organArray !=''">
- and (dh.organ_id in (
- <foreach collection="organArray" item="organId" separator=",">
- #{organId}
- </foreach>
- ) or dh.sub_type='采购退货' or dh.sub_type='零售' or dh.sub_type='其它')
- </if>
- <if test="depotList.size()>0">
- <if test="type == '入库'">
- and ((
- dh.sub_type!='调拨' and di.depot_id in
- <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
- #{item}
- </foreach>
- ) or (
- dh.sub_type='调拨' and di.another_depot_id in
- <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
- #{item}
- </foreach>
- ))
- </if>
- <if test="type == '出库'">
- and di.depot_id in
- <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- </if>
- <if test="materialParam != null and materialParam !=''">
- <bind name="bindKey" value="'%'+materialParam+'%'"/>
- 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}
- or m.color like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
- or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
- </if>
- <if test="categoryList.size()>0">
- and m.category_id in
- <foreach collection="categoryList" item="item" index="index" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="forceFlag">
- and (dh.status = '1' or dh.status = '2' or dh.status = '3')
- </if>
- <if test="inOutManageFlag">
- and (dh.sub_type!='采购' and dh.sub_type!='采购退货' and dh.sub_type!='销售' and dh.sub_type!='销售退货')
- </if>
- and ifnull(dh.delete_flag,'0') !='1'
- group by di.material_id) a
- </select>
- <select id="findInOutMaterialCountStatistic" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultInOutMaterialCount">
- select ifnull(sum(di.basic_number),0) numSum, ifnull(sum(di.all_price),0) priceSum
- from jsh_depot_head dh
- left join jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1'
- left join jsh_material m on m.id=di.material_id and ifnull(m.delete_flag,'0') !='1'
- left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
- left join jsh_material_extend me on me.material_id=m.id and ifnull(me.delete_Flag,'0') !='1'
- left join jsh_material_category mc on m.category_id=mc.Id and ifnull(mc.delete_flag,'0') !='1'
- where me.default_flag=1
- and (dh.type=#{type} or dh.sub_type='调拨') and dh.oper_time >=#{beginTime} and dh.oper_time <=#{endTime}
- <if test="oId != null">
- and dh.organ_id = #{oId}
- </if>
- <if test="creatorArray != null">
- and dh.creator in (
- <foreach collection="creatorArray" item="creator" separator=",">
- #{creator}
- </foreach>
- )
- </if>
- <if test="organArray != null and organArray !=''">
- and (dh.organ_id in (
- <foreach collection="organArray" item="organId" separator=",">
- #{organId}
- </foreach>
- ) or dh.sub_type='采购退货' or dh.sub_type='零售' or dh.sub_type='其它')
- </if>
- <if test="depotList.size()>0">
- <if test="type == '入库'">
- and ((
- dh.sub_type!='调拨' and di.depot_id in
- <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
- #{item}
- </foreach>
- ) or (
- dh.sub_type='调拨' and di.another_depot_id in
- <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
- #{item}
- </foreach>
- ))
- </if>
- <if test="type == '出库'">
- and di.depot_id in
- <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- </if>
- <if test="materialParam != null and materialParam !=''">
- <bind name="bindKey" value="'%'+materialParam+'%'"/>
- 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}
- or m.color like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
- or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
- </if>
- <if test="categoryList.size()>0">
- and m.category_id in
- <foreach collection="categoryList" item="item" index="index" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="forceFlag">
- and (dh.status = '1' or dh.status = '2' or dh.status = '3')
- </if>
- <if test="inOutManageFlag">
- and (dh.sub_type!='采购' and dh.sub_type!='采购退货' and dh.sub_type!='销售' and dh.sub_type!='销售退货')
- </if>
- and ifnull(dh.delete_flag,'0') !='1'
- </select>
- <select id="findAllocationDetail" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultWithInfoExMap">
- 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.oper_number operNumber,di.all_price allPrice,sname, d.dName dname,date_format(dh.oper_time, '%Y-%m-%d') operTime,
- concat(dh.sub_type,dh.type) as newType, concat_ws(' ',dh.remark,di.remark) as newRemark
- from jsh_depot_head dh
- left join jsh_depot_item di on di.header_id=dh.id and ifnull(di.delete_flag,'0') !='1'
- left join jsh_material m on m.id=di.material_id and ifnull(m.delete_flag,'0') !='1'
- left join jsh_material_extend me on me.id=di.material_extend_id and ifnull(me.delete_Flag,'0') !='1'
- 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'
- <!-- 调出仓库名查询 -->
- 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'
- where dh.oper_time >=#{beginTime} and dh.oper_time <=#{endTime}
- <if test="depotFList.size()>0">
- and di.depot_id in
- <foreach collection="depotFList" item="item" index="index" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="depotList.size()>0">
- and di.another_depot_id in
- <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="subType != null">
- and dh.sub_type=#{subType}
- </if>
- <if test="number != null and number !=''">
- <bind name="bindNumber" value="'%'+number+'%'"/>
- and dh.number like #{bindNumber}
- </if>
- <if test="creatorArray != null">
- and dh.creator in (
- <foreach collection="creatorArray" item="creator" separator=",">
- #{creator}
- </foreach>
- )
- </if>
- <if test="categoryList.size()>0">
- and m.category_id in
- <foreach collection="categoryList" item="item" index="index" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="forceFlag">
- and dh.status = '1'
- </if>
- <if test="materialParam != null and materialParam !=''">
- <bind name="bindKey" value="'%'+materialParam+'%'"/>
- 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}
- or m.color like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
- or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey} or dh.remark like #{bindKey})
- </if>
- <if test="remark != null and remark !=''">
- <bind name="bindRemark" value="'%'+remark+'%'"/>
- and (dh.remark like #{bindRemark} or di.remark like #{bindRemark})
- </if>
- and ifnull(dh.delete_flag,'0') !='1'
- <if test="column == 'createTime'">
- order by oper_time desc,number desc
- </if>
- <if test="column != 'createTime'">
- order by ${column} ${order}
- </if>
- <if test="offset != null and rows != null">
- limit #{offset},#{rows}
- </if>
- </select>
- <select id="findAllocationDetailCount" resultType="java.lang.Integer">
- select count(1)
- from jsh_depot_head dh
- left join jsh_depot_item di on di.header_id=dh.id and ifnull(di.delete_flag,'0') !='1'
- left join jsh_material m on m.id=di.material_id and ifnull(m.delete_Flag,'0') !='1'
- left join jsh_material_extend me on me.id=di.material_extend_id and ifnull(me.delete_Flag,'0') !='1'
- 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'
- where dh.oper_time >=#{beginTime} and dh.oper_time <=#{endTime}
- <if test="depotFList.size()>0">
- and di.depot_id in
- <foreach collection="depotFList" item="item" index="index" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="depotList.size()>0">
- and di.another_depot_id in
- <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="subType != null">
- and dh.sub_type=#{subType}
- </if>
- <if test="number != null and number !=''">
- <bind name="bindNumber" value="'%'+number+'%'"/>
- and dh.number like #{bindNumber}
- </if>
- <if test="creatorArray != null">
- and dh.creator in (
- <foreach collection="creatorArray" item="creator" separator=",">
- #{creator}
- </foreach>
- )
- </if>
- <if test="categoryList.size()>0">
- and m.category_id in
- <foreach collection="categoryList" item="item" index="index" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="forceFlag">
- and dh.status = '1'
- </if>
- <if test="materialParam != null and materialParam !=''">
- <bind name="bindKey" value="'%'+materialParam+'%'"/>
- 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}
- or m.color like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
- or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey} or dh.remark like #{bindKey})
- </if>
- <if test="remark != null and remark !=''">
- <bind name="bindRemark" value="'%'+remark+'%'"/>
- and (dh.remark like #{bindRemark} or di.remark like #{bindRemark})
- </if>
- and ifnull(dh.delete_flag,'0') !='1'
- </select>
- <select id="findAllocationStatistic" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultWithInfoExMap">
- select ifnull(sum(di.oper_number),0) operNumber, ifnull(sum(di.all_price),0) allPrice
- from jsh_depot_head dh
- left join jsh_depot_item di on di.header_id=dh.id and ifnull(di.delete_flag,'0') !='1'
- left join jsh_material m on m.id=di.material_id and ifnull(m.delete_flag,'0') !='1'
- left join jsh_material_extend me on me.id=di.material_extend_id and ifnull(me.delete_Flag,'0') !='1'
- 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'
- <!-- 调出仓库名查询 -->
- 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'
- where dh.oper_time >=#{beginTime} and dh.oper_time <=#{endTime}
- <if test="depotFList.size()>0">
- and di.depot_id in
- <foreach collection="depotFList" item="item" index="index" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="depotList.size()>0">
- and di.another_depot_id in
- <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="subType != null">
- and dh.sub_type=#{subType}
- </if>
- <if test="number != null and number !=''">
- <bind name="bindNumber" value="'%'+number+'%'"/>
- and dh.number like #{bindNumber}
- </if>
- <if test="creatorArray != null">
- and dh.creator in (
- <foreach collection="creatorArray" item="creator" separator=",">
- #{creator}
- </foreach>
- )
- </if>
- <if test="categoryList.size()>0">
- and m.category_id in
- <foreach collection="categoryList" item="item" index="index" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="forceFlag">
- and dh.status = '1'
- </if>
- <if test="materialParam != null and materialParam !=''">
- <bind name="bindKey" value="'%'+materialParam+'%'"/>
- 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}
- or m.color like #{bindKey} or m.brand like #{bindKey} or m.other_field1 like #{bindKey}
- or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey} or dh.remark like #{bindKey})
- </if>
- <if test="remark != null and remark !=''">
- <bind name="bindRemark" value="'%'+remark+'%'"/>
- and (dh.remark like #{bindRemark} or di.remark like #{bindRemark})
- </if>
- and ifnull(dh.delete_flag,'0') !='1'
- </select>
- <select id="getStatementAccount" resultType="com.jsh.erp.datasource.vo.DepotHeadVo4StatementAccount">
- select *, (preBackInMoney+preBackOutMoney) as preBackMoney, (backInMoney+backOutMoney) as backMoney from
- (select s.id, s.supplier, s.contacts, s.telephone, s.phone_num, s.email,
- -- 起始期初金额
- (case when s.type='供应商' then ifnull(s.begin_need_pay,0) else ifnull(s.begin_need_get,0) end) begin_need,
- -- 上期欠款金额
- (select
- 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))
- from jsh_depot_head dh
- where dh.organ_id=s.id
- and dh.type=#{type} and dh.sub_type=#{subType}
- and dh.oper_time <= #{beginTime}
- and ifnull(dh.delete_flag,'0') !='1') preDebtMoney,
- -- 上期退货的欠款金额
- (select
- 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))
- from jsh_depot_head dh
- where dh.organ_id=s.id
- and dh.type=#{typeBack} and dh.sub_type=#{subTypeBack}
- and dh.oper_time <= #{beginTime}
- and ifnull(dh.delete_flag,'0') !='1') preReturnDebtMoney,
- -- 上期收款
- (select ifnull(sum(ai.each_amount),0) from jsh_account_item ai
- left join jsh_account_head ah on ai.header_id=ah.id and ifnull(ah.delete_flag,'0') !='1'
- where ah.organ_id=s.id and ah.type='收款'
- and ah.bill_time <= #{beginTime}
- and ifnull(ai.delete_flag,'0') !='1') preBackInMoney,
- -- 上期付款
- (select 0-ifnull(sum(ai.each_amount),0) from jsh_account_item ai
- left join jsh_account_head ah on ai.header_id=ah.id and ifnull(ah.delete_flag,'0') !='1'
- where ah.organ_id=s.id and ah.type='付款'
- and ah.bill_time <= #{beginTime}
- and ifnull(ai.delete_flag,'0') !='1') preBackOutMoney,
- -- 本期欠款
- (select
- 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))
- from jsh_depot_head dh
- where dh.organ_id=s.id
- and dh.type=#{type} and dh.sub_type=#{subType}
- and dh.oper_time>#{beginTime} and dh.oper_time <= #{endTime}
- and ifnull(dh.delete_flag,'0') !='1') debtMoney,
- -- 本期退货的欠款金额
- (select
- 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))
- from jsh_depot_head dh
- where dh.organ_id=s.id
- and dh.type=#{typeBack} and dh.sub_type=#{subTypeBack}
- and dh.oper_time>#{beginTime} and dh.oper_time <= #{endTime}
- and ifnull(dh.delete_flag,'0') !='1') returnDebtMoney,
- -- 本期收款
- (select ifnull(sum(ai.each_amount),0) from jsh_account_item ai
- left join jsh_account_head ah on ai.header_id=ah.id and ifnull(ah.delete_flag,'0') !='1'
- where ah.organ_id=s.id and ah.type='收款'
- and ah.bill_time>#{beginTime} and ah.bill_time <= #{endTime}
- and ifnull(ai.delete_flag,'0') !='1') backInMoney,
- -- 本期付款
- (select 0-ifnull(sum(ai.each_amount),0) from jsh_account_item ai
- left join jsh_account_head ah on ai.header_id=ah.id and ifnull(ah.delete_flag,'0') !='1'
- where ah.organ_id=s.id and ah.type='付款'
- and ah.bill_time>#{beginTime} and ah.bill_time <= #{endTime}
- and ifnull(ai.delete_flag,'0') !='1') backOutMoney
- from jsh_supplier s
- where s.enabled=1
- and s.type=#{supplierType}
- <if test="organId != null">
- and s.id = #{organId}
- </if>
- <if test="organArray != null and organArray !=''">
- and s.id in (
- <foreach collection="organArray" item="organId" separator=",">
- #{organId}
- </foreach>
- )
- </if>
- and ifnull(s.delete_flag,'0') !='1') tb
- <if test="hasDebt == 1">
- where begin_need+preDebtMoney-preReturnDebtMoney-preBackInMoney-preBackOutMoney+debtMoney-returnDebtMoney-backInMoney-backOutMoney!=0
- </if>
- <if test="hasDebt == 0">
- where begin_need+preDebtMoney-preReturnDebtMoney-preBackInMoney-preBackOutMoney+debtMoney-returnDebtMoney-backInMoney-backOutMoney=0
- </if>
- order by begin_need+preDebtMoney-preReturnDebtMoney-preBackInMoney-preBackOutMoney+debtMoney-returnDebtMoney-backInMoney-backOutMoney desc
- <if test="offset != null and rows != null">
- limit #{offset},#{rows}
- </if>
- </select>
- <select id="getStatementAccountCount" resultType="java.lang.Integer">
- select count(1) from
- (select s.id, s.supplier, s.contacts, s.telephone, s.phone_num, s.email,
- -- 起始期初金额
- (case when s.type='供应商' then ifnull(s.begin_need_pay,0) else ifnull(s.begin_need_get,0) end) begin_need,
- -- 上期欠款金额
- (select
- 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))
- from jsh_depot_head dh
- where dh.organ_id=s.id
- and dh.type=#{type} and dh.sub_type=#{subType}
- and dh.oper_time <= #{beginTime}
- and ifnull(dh.delete_flag,'0') !='1') preDebtMoney,
- -- 上期退货的欠款金额
- (select
- 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))
- from jsh_depot_head dh
- where dh.organ_id=s.id
- and dh.type=#{typeBack} and dh.sub_type=#{subTypeBack}
- and dh.oper_time <= #{beginTime}
- and ifnull(dh.delete_flag,'0') !='1') preReturnDebtMoney,
- -- 上期收款
- (select ifnull(sum(ai.each_amount),0) from jsh_account_item ai
- left join jsh_account_head ah on ai.header_id=ah.id and ifnull(ah.delete_flag,'0') !='1'
- where ah.organ_id=s.id and ah.type='收款'
- and ah.bill_time <= #{beginTime}
- and ifnull(ai.delete_flag,'0') !='1') preBackInMoney,
- -- 上期付款
- (select 0-ifnull(sum(ai.each_amount),0) from jsh_account_item ai
- left join jsh_account_head ah on ai.header_id=ah.id and ifnull(ah.delete_flag,'0') !='1'
- where ah.organ_id=s.id and ah.type='付款'
- and ah.bill_time <= #{beginTime}
- and ifnull(ai.delete_flag,'0') !='1') preBackOutMoney,
- -- 本期欠款
- (select
- 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))
- from jsh_depot_head dh
- where dh.organ_id=s.id
- and dh.type=#{type} and dh.sub_type=#{subType}
- and dh.oper_time>#{beginTime} and dh.oper_time <= #{endTime}
- and ifnull(dh.delete_flag,'0') !='1') debtMoney,
- -- 本期退货的欠款金额
- (select
- 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))
- from jsh_depot_head dh
- where dh.organ_id=s.id
- and dh.type=#{typeBack} and dh.sub_type=#{subTypeBack}
- and dh.oper_time>#{beginTime} and dh.oper_time <= #{endTime}
- and ifnull(dh.delete_flag,'0') !='1') returnDebtMoney,
- -- 本期收款
- (select ifnull(sum(ai.each_amount),0) from jsh_account_item ai
- left join jsh_account_head ah on ai.header_id=ah.id and ifnull(ah.delete_flag,'0') !='1'
- where ah.organ_id=s.id and ah.type='收款'
- and ah.bill_time>#{beginTime} and ah.bill_time <= #{endTime}
- and ifnull(ai.delete_flag,'0') !='1') backInMoney,
- -- 本期付款
- (select 0-ifnull(sum(ai.each_amount),0) from jsh_account_item ai
- left join jsh_account_head ah on ai.header_id=ah.id and ifnull(ah.delete_flag,'0') !='1'
- where ah.organ_id=s.id and ah.type='付款'
- and ah.bill_time>#{beginTime} and ah.bill_time <= #{endTime}
- and ifnull(ai.delete_flag,'0') !='1') backOutMoney
- from jsh_supplier s
- where s.enabled=1
- and s.type=#{supplierType}
- <if test="organId != null">
- and s.id = #{organId}
- </if>
- <if test="organArray != null and organArray !=''">
- and s.id in (
- <foreach collection="organArray" item="organId" separator=",">
- #{organId}
- </foreach>
- )
- </if>
- and ifnull(s.delete_flag,'0') !='1') tb
- <if test="hasDebt == 1">
- where begin_need+preDebtMoney-preReturnDebtMoney-preBackInMoney-preBackOutMoney+debtMoney-returnDebtMoney-backInMoney-backOutMoney!=0
- </if>
- <if test="hasDebt == 0">
- where begin_need+preDebtMoney-preReturnDebtMoney-preBackInMoney-preBackOutMoney+debtMoney-returnDebtMoney-backInMoney-backOutMoney=0
- </if>
- </select>
- <select id="getStatementAccountTotalPay" resultType="com.jsh.erp.datasource.vo.DepotHeadVo4StatementAccount">
- select sum(begin_need) begin_need, sum(preDebtMoney) preDebtMoney, sum(preReturnDebtMoney) preReturnDebtMoney, sum(preBackInMoney+preBackOutMoney) preBackMoney,
- sum(debtMoney) debtMoney, sum(returnDebtMoney) returnDebtMoney, sum(backInMoney+backOutMoney) backMoney from
- (select s.id,
- (case when s.type='供应商' then ifnull(s.begin_need_pay,0) else ifnull(s.begin_need_get,0) end) begin_need,
- (select
- 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))
- from jsh_depot_head dh
- where dh.organ_id=s.id
- and dh.type=#{type} and dh.sub_type=#{subType}
- and dh.oper_time <= #{beginTime}
- and ifnull(dh.delete_flag,'0') !='1') preDebtMoney,
- (select
- 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))
- from jsh_depot_head dh
- where dh.organ_id=s.id
- and dh.type=#{typeBack} and dh.sub_type=#{subTypeBack}
- and dh.oper_time <= #{beginTime}
- and ifnull(dh.delete_flag,'0') !='1') preReturnDebtMoney,
- (select ifnull(sum(ai.each_amount),0) from jsh_account_item ai
- left join jsh_account_head ah on ai.header_id=ah.id and ifnull(ah.delete_flag,'0') !='1'
- where ah.organ_id=s.id and ah.type='收款'
- and ah.bill_time <= #{beginTime}
- and ifnull(ai.delete_flag,'0') !='1') preBackInMoney,
- (select 0-ifnull(sum(ai.each_amount),0) from jsh_account_item ai
- left join jsh_account_head ah on ai.header_id=ah.id and ifnull(ah.delete_flag,'0') !='1'
- where ah.organ_id=s.id and ah.type='付款'
- and ah.bill_time <= #{beginTime}
- and ifnull(ai.delete_flag,'0') !='1') preBackOutMoney,
- (select
- 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))
- from jsh_depot_head dh
- where dh.organ_id=s.id
- and dh.type=#{type} and dh.sub_type=#{subType}
- and dh.oper_time>#{beginTime} and dh.oper_time <= #{endTime}
- and ifnull(dh.delete_flag,'0') !='1') debtMoney,
- (select
- 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))
- from jsh_depot_head dh
- where dh.organ_id=s.id
- and dh.type=#{typeBack} and dh.sub_type=#{subTypeBack}
- and dh.oper_time>#{beginTime} and dh.oper_time <= #{endTime}
- and ifnull(dh.delete_flag,'0') !='1') returnDebtMoney,
- (select ifnull(sum(ai.each_amount),0) from jsh_account_item ai
- left join jsh_account_head ah on ai.header_id=ah.id and ifnull(ah.delete_flag,'0') !='1'
- where ah.organ_id=s.id and ah.type='收款'
- and ah.bill_time>#{beginTime} and ah.bill_time <= #{endTime}
- and ifnull(ai.delete_flag,'0') !='1') backInMoney,
- (select 0-ifnull(sum(ai.each_amount),0) from jsh_account_item ai
- left join jsh_account_head ah on ai.header_id=ah.id and ifnull(ah.delete_flag,'0') !='1'
- where ah.organ_id=s.id and ah.type='付款'
- and ah.bill_time>#{beginTime} and ah.bill_time <= #{endTime}
- and ifnull(ai.delete_flag,'0') !='1') backOutMoney
- from jsh_supplier s
- where s.enabled=1
- and s.type=#{supplierType}
- <if test="organId != null">
- and s.id = #{organId}
- </if>
- <if test="organArray != null and organArray !=''">
- and s.id in (
- <foreach collection="organArray" item="organId" separator=",">
- #{organId}
- </foreach>
- )
- </if>
- and ifnull(s.delete_flag,'0') !='1') tb
- <if test="hasDebt == 1">
- where begin_need+preDebtMoney-preReturnDebtMoney-preBackInMoney-preBackOutMoney+debtMoney-returnDebtMoney-backInMoney-backOutMoney!=0
- </if>
- <if test="hasDebt == 0">
- where begin_need+preDebtMoney-preReturnDebtMoney-preBackInMoney-preBackOutMoney+debtMoney-returnDebtMoney-backInMoney-backOutMoney=0
- </if>
- </select>
- <select id="getDetailByNumber" parameterType="com.jsh.erp.datasource.entities.DepotHeadExample" resultMap="ResultMapEx">
- select dh.*, concat(dh.sub_type,dh.type) as depotHeadType, a.name AccountName,
- s.supplier OrganName, s.contacts, s.telephone, s.address
- from jsh_depot_head dh
- left join jsh_supplier s on dh.organ_id=s.id and ifnull(s.delete_Flag,'0') !='1'
- left join jsh_account a on dh.account_id=a.id and ifnull(a.delete_Flag,'0') !='1'
- where 1=1
- <if test="number != null">
- and dh.number=#{number}
- </if>
- and ifnull(dh.delete_flag,'0') !='1'
- </select>
- <update id="batchDeleteDepotHeadByIds">
- update jsh_depot_head
- set delete_flag='1'
- where 1=1
- and id in (
- <foreach collection="ids" item="id" separator=",">
- #{id}
- </foreach>
- )
- </update>
- <select id="getDepotHeadListByAccountIds" resultMap="com.jsh.erp.datasource.mappers.DepotHeadMapper.BaseResultMap">
- select
- <include refid="com.jsh.erp.datasource.mappers.DepotHeadMapper.Base_Column_List" />
- from jsh_depot_head
- where 1=1
- and account_id in (
- <foreach collection="accountIds" item="accountId" separator=",">
- #{accountId}
- </foreach>
- )
- and ifnull(delete_flag,'0') !='1'
- </select>
- <select id="getDepotHeadListByOrganIds" resultMap="com.jsh.erp.datasource.mappers.DepotHeadMapper.BaseResultMap">
- select
- <include refid="com.jsh.erp.datasource.mappers.DepotHeadMapper.Base_Column_List" />
- from jsh_depot_head
- where 1=1
- and organ_id in (
- <foreach collection="organIds" item="organId" separator=",">
- #{organId}
- </foreach>
- )
- and ifnull(delete_flag,'0') !='1'
- </select>
- <select id="getDepotHeadListByCreator" resultMap="com.jsh.erp.datasource.mappers.DepotHeadMapper.BaseResultMap">
- select
- <include refid="com.jsh.erp.datasource.mappers.DepotHeadMapper.Base_Column_List" />
- from jsh_depot_head
- where 1=1
- and creator in (
- <foreach collection="creatorArray" item="creator" separator=",">
- #{creator}
- </foreach>
- )
- and ifnull(delete_flag,'0') !='1'
- </select>
- <select id="getBuyAndSaleStatisticsList" resultType="com.jsh.erp.datasource.vo.InOutPriceVo">
- select distinct dh.id, dh.discount_last_money, dh.total_price, dh.type, dh.sub_type, dh.oper_time
- from jsh_depot_head dh
- left join jsh_depot_item di on dh.id = di.header_id and ifnull(di.delete_flag,'0') !='1'
- where di.id is not null
- and (dh.type='入库' or dh.type='出库')
- <if test="beginTime != null">
- and dh.oper_time >= #{beginTime}
- </if>
- <if test="endTime != null">
- and dh.oper_time <= #{endTime}
- </if>
- <if test="forceFlag">
- and (dh.status = '1' or dh.status = '2' or dh.status = '3')
- </if>
- <if test="creatorArray != null">
- and dh.creator in (
- <foreach collection="creatorArray" item="creator" separator=",">
- #{creator}
- </foreach>
- )
- </if>
- and ifnull(dh.delete_flag,'0') !='1'
- </select>
- <select id="debtList" parameterType="com.jsh.erp.datasource.entities.DepotHeadExample" resultMap="ResultMapEx">
- select distinct dh.*, s.supplier OrganName, u.username userName
- from jsh_depot_head dh
- left join jsh_supplier s on dh.organ_id=s.id and ifnull(s.delete_Flag,'0') !='1'
- left join jsh_user u on dh.creator=u.id and ifnull(u.delete_flag,'0') !='1'
- left join jsh_depot_item di on dh.id = di.header_id and ifnull(di.delete_flag,'0') !='1'
- left join jsh_material m on di.material_id = m.id and ifnull(m.delete_flag,'0') !='1'
- where 1=1
- and (dh.type='入库' or dh.type='出库')
- and (dh.sub_type='采购' or dh.sub_type='销售' or dh.sub_type='采购退货' or dh.sub_type='销售退货')
- <if test="organId != null">
- and dh.organ_id = #{organId}
- </if>
- <if test="status != null">
- and dh.status =#{status}
- </if>
- <if test="number != null">
- <bind name="bindNumber" value="'%'+number+'%'"/>
- and dh.number like #{bindNumber}
- </if>
- <if test="beginTime != null">
- and dh.oper_time >= #{beginTime}
- </if>
- <if test="endTime != null">
- and dh.oper_time <= #{endTime}
- </if>
- <if test="materialParam != null and materialParam !=''">
- <bind name="bindKey" value="'%'+materialParam+'%'"/>
- and (m.name like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey})
- </if>
- <if test="depotArray != null and depotArray !=''">
- and di.depot_id in (
- <foreach collection="depotArray" item="depotId" separator=",">
- #{depotId}
- </foreach>
- )
- </if>
- <if test="creatorArray != null">
- and dh.creator in (
- <foreach collection="creatorArray" item="creator" separator=",">
- #{creator}
- </foreach>
- )
- </if>
- 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'))
- < (ifnull(dh.discount_last_money,0) + ifnull(dh.other_money,0) - ifnull(dh.deposit,0))
- and ifnull(dh.delete_flag,'0') !='1'
- order by dh.oper_time desc
- <if test="offset != null and rows != null">
- limit #{offset},#{rows}
- </if>
- </select>
- <select id="debtListCount" resultType="java.lang.Integer">
- select count(1) from (
- select distinct dh.*, s.supplier OrganName, u.username userName
- from jsh_depot_head dh
- left join jsh_supplier s on dh.organ_id=s.id and ifnull(s.delete_Flag,'0') !='1'
- left join jsh_user u on dh.creator=u.id and ifnull(u.delete_flag,'0') !='1'
- left join jsh_depot_item di on dh.id = di.header_id and ifnull(di.delete_flag,'0') !='1'
- left join jsh_material m on di.material_id = m.id and ifnull(m.delete_flag,'0') !='1'
- where 1=1
- and (dh.type='入库' or dh.type='出库')
- and (dh.sub_type='采购' or dh.sub_type='销售' or dh.sub_type='采购退货' or dh.sub_type='销售退货')
- <if test="organId != null">
- and dh.organ_id = #{organId}
- </if>
- <if test="status != null">
- and dh.status =#{status}
- </if>
- <if test="number != null">
- <bind name="bindNumber" value="'%'+number+'%'"/>
- and dh.number like #{bindNumber}
- </if>
- <if test="beginTime != null">
- and dh.oper_time >= #{beginTime}
- </if>
- <if test="endTime != null">
- and dh.oper_time <= #{endTime}
- </if>
- <if test="materialParam != null and materialParam !=''">
- <bind name="bindKey" value="'%'+materialParam+'%'"/>
- and (m.name like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey})
- </if>
- <if test="depotArray != null and depotArray !=''">
- and di.depot_id in (
- <foreach collection="depotArray" item="depotId" separator=",">
- #{depotId}
- </foreach>
- )
- </if>
- <if test="creatorArray != null">
- and dh.creator in (
- <foreach collection="creatorArray" item="creator" separator=",">
- #{creator}
- </foreach>
- )
- </if>
- 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'))
- < (ifnull(dh.discount_last_money,0) + ifnull(dh.other_money,0) - ifnull(dh.deposit,0))
- and ifnull(dh.delete_flag,'0') !='1' ) tb
- </select>
- <select id="getFinishDepositByNumberList" resultType="com.jsh.erp.datasource.vo.FinishDepositVo">
- select dh.link_number number, ifnull(sum(dh.deposit),0) finishDeposit
- from jsh_depot_head dh
- where 1=1
- <if test="numberList.size()>0">
- and dh.link_number in
- <foreach collection="numberList" item="item" index="index" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- and ifnull(dh.delete_flag,'0') !='1'
- group by dh.link_number
- </select>
- <select id="getFinishDepositByNumberExceptCurrent" resultType="java.math.BigDecimal">
- select ifnull(sum(dh.deposit),0)
- from jsh_depot_head dh
- where dh.link_number=#{linkNumber}
- and dh.number!=#{number}
- and ifnull(dh.delete_flag,'0') !='1'
- </select>
- <update id="setAccountIdToNull">
- update jsh_depot_head dh set dh.account_id = null
- where dh.id=#{id}
- and ifnull(dh.delete_flag,'0') !='1'
- </update>
- <select id="getSerialNumberBySell" resultType="java.lang.Integer">
- select count(s.id) from jsh_depot_head dh
- left join jsh_serial_number s on dh.number=s.in_bill_no
- where dh.number = #{number}
- and (s.out_bill_no is not null or s.out_bill_no!='')
- </select>
- <select id="waitBillList" parameterType="com.jsh.erp.datasource.entities.DepotHeadExample" resultMap="ResultMapEx">
- select jdh.*, s.supplier OrganName, u.username userName, a.name AccountName
- from (select dh.id
- from jsh_depot_head dh
- left join jsh_depot_item di on dh.id = di.header_id and ifnull(di.delete_flag,'0') !='1'
- left join jsh_material m on di.material_id = m.id and ifnull(m.delete_flag,'0') !='1'
- left join jsh_material_extend me on di.material_extend_id = me.id and ifnull(me.delete_flag,'0') !='1'
- where 1=1
- <if test="type != null">
- and dh.type=#{type}
- </if>
- <if test="subTypeArray != null and subTypeArray !=''">
- and dh.sub_type in (
- <foreach collection="subTypeArray" item="subType" separator=",">
- #{subType}
- </foreach>
- )
- </if>
- <if test="statusArray != null and statusArray !=''">
- and dh.status in (
- <foreach collection="statusArray" item="status" separator=",">
- #{status}
- </foreach>
- )
- </if>
- <if test="number != null">
- <bind name="bindNumber" value="'%'+number+'%'"/>
- and dh.number like #{bindNumber}
- </if>
- <if test="beginTime != null">
- and dh.oper_time >= #{beginTime}
- </if>
- <if test="endTime != null">
- and dh.oper_time <= #{endTime}
- </if>
- <if test="materialParam != null and materialParam !=''">
- <bind name="bindKey" value="'%'+materialParam+'%'"/>
- 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}
- or m.color like #{bindKey} or m.other_field1 like #{bindKey}
- or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
- </if>
- <if test="depotArray != null and depotArray !=''">
- and di.depot_id in (
- <foreach collection="depotArray" item="depotId" separator=",">
- #{depotId}
- </foreach>
- )
- </if>
- <if test="creatorArray != null">
- and dh.creator in (
- <foreach collection="creatorArray" item="creator" separator=",">
- #{creator}
- </foreach>
- )
- </if>
- and ifnull(dh.delete_flag,'0') !='1'
- group by dh.id
- order by dh.id desc
- <if test="offset != null and rows != null">
- limit #{offset},#{rows}
- </if>) tb
- left join jsh_depot_head jdh on jdh.id=tb.id and ifnull(jdh.delete_flag,'0') !='1'
- left join jsh_supplier s on jdh.organ_id=s.id and ifnull(s.delete_flag,'0') !='1'
- left join jsh_user u on jdh.creator=u.id and ifnull(u.delete_flag,'0') !='1'
- left join jsh_account a on jdh.account_id=a.id and ifnull(a.delete_flag,'0') !='1'
- </select>
- <select id="waitBillCount" resultType="java.lang.Long">
- select
- count(1) from
- (select distinct dh.id from jsh_depot_head dh
- left join jsh_depot_item di on dh.Id = di.header_id and ifnull(di.delete_flag,'0') !='1'
- left join jsh_material m on di.material_id = m.Id and ifnull(m.delete_Flag,'0') !='1'
- left join jsh_material_extend me on di.material_extend_id = me.id and ifnull(me.delete_flag,'0') !='1'
- WHERE 1=1
- <if test="type != null">
- and dh.type=#{type}
- </if>
- <if test="subTypeArray != null and subTypeArray !=''">
- and dh.sub_type in (
- <foreach collection="subTypeArray" item="subType" separator=",">
- #{subType}
- </foreach>
- )
- </if>
- <if test="statusArray != null and statusArray !=''">
- and dh.status in (
- <foreach collection="statusArray" item="status" separator=",">
- #{status}
- </foreach>
- )
- </if>
- <if test="number != null">
- <bind name="bindNumber" value="'%'+number+'%'"/>
- and dh.number like #{bindNumber}
- </if>
- <if test="beginTime != null">
- and dh.oper_time >= #{beginTime}
- </if>
- <if test="endTime != null">
- and dh.oper_time <= #{endTime}
- </if>
- <if test="materialParam != null and materialParam !=''">
- <bind name="bindKey" value="'%'+materialParam+'%'"/>
- 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}
- or m.color like #{bindKey} or m.other_field1 like #{bindKey}
- or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
- </if>
- <if test="depotArray != null and depotArray !=''">
- and di.depot_id in (
- <foreach collection="depotArray" item="depotId" separator=",">
- #{depotId}
- </foreach>
- )
- </if>
- <if test="creatorArray != null">
- and dh.creator in (
- <foreach collection="creatorArray" item="creator" separator=",">
- #{creator}
- </foreach>
- )
- </if>
- and ifnull(dh.delete_Flag,'0') !='1') tb
- </select>
- <select id="getBillAllPriceByOrganId" resultType="java.math.BigDecimal">
- select ifnull(sum(dh.total_price),0) allPrice from jsh_depot_head dh
- where dh.organ_id=#{organId}
- and dh.type = '出库'
- and dh.sub_type = '零售'
- and dh.pay_type = '预付款'
- and ifnull(dh.delete_flag,'0') !='1'
- </select>
- </mapper>
|