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
and dh.type=#{type}
and dh.sub_type=#{subType}
and dh.status in (
#{status}
)
and dh.purchase_status in (
#{purchaseStatus}
)
and dh.number like #{bindNumber}
and dh.link_apply like #{bindLinkApply}
and dh.link_number like #{bindLinkNumber}
and dh.oper_time >= #{beginTime}
and dh.oper_time <= #{endTime}
and (me.bar_code 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.mfrs 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})
and dh.organ_id=#{organId}
and dh.organ_id in (
#{organId}
)
and dh.creator=#{creator}
and di.depot_id=#{depotId}
and di.depot_id in (
#{depotId}
)
and dh.creator in (
#{creator}
)
and (dh.account_id=#{accountId} or dh.account_id_list like #{bindAccountId})
and
(ifnull(dh.discount_last_money,0)+ifnull(dh.other_money,0)-ifnull(dh.deposit,0)-abs(ifnull(dh.change_amount,0))>0)
and
(ifnull(dh.discount_last_money,0)+ifnull(dh.other_money,0)-ifnull(dh.deposit,0)-abs(ifnull(dh.change_amount,0))=0)
and (dh.remark like #{bindRemark} or di.remark like #{bindRemark})
and ifnull(dh.delete_flag,'0') !='1'
group by dh.id
order by dh.id desc
limit #{offset},#{rows}
) 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
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
and dh.type=#{type}
and dh.sub_type=#{subType}
and dh.status in (
#{status}
)
and dh.purchase_status in (
#{purchaseStatus}
)
and dh.number like #{bindNumber}
and dh.link_apply like #{bindLinkApply}
and dh.link_number like #{bindLinkNumber}
and dh.oper_time >= #{beginTime}
and dh.oper_time <= #{endTime}
and (me.bar_code 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.mfrs 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})
and dh.organ_id=#{organId}
and dh.organ_id in (
#{organId}
)
and dh.creator=#{creator}
and di.depot_id=#{depotId}
and di.depot_id in (
#{depotId}
)
and dh.creator in (
#{creator}
)
and (dh.account_id=#{accountId} or dh.account_id_list like #{bindAccountId})
and (ifnull(dh.discount_last_money,0)+ifnull(dh.other_money,0)-ifnull(dh.deposit,0)-abs(ifnull(dh.change_amount,0))>0)
and (ifnull(dh.discount_last_money,0)+ifnull(dh.other_money,0)-ifnull(dh.deposit,0)-abs(ifnull(dh.change_amount,0))=0)
and (dh.remark like #{bindRemark} or di.remark like #{bindRemark})
and ifnull(dh.delete_Flag,'0') !='1') tb
select dh.number,me.bar_code barCode, m.name mname,m.model,m.standard,m.color,m.brand,m.mfrs,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}
and dh.organ_id = #{oId}
and di.depot_id in
#{item}
and dh.type=#{type}
and (dh.sub_type!='采购' and dh.sub_type!='采购退货' and dh.sub_type!='销售' and dh.sub_type!='销售退货')
and dh.creator in (
#{creator}
)
and (dh.organ_id in (
#{organId}
) or dh.sub_type='采购退货' or dh.sub_type='零售' or dh.sub_type='其它')
and m.category_id in
#{item}
and dh.status = '1'
and dh.number like #{bindNumber}
and (me.bar_code 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.mfrs 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})
and dh.creator=#{creator}
and (dh.remark like #{bindRemark} or di.remark like #{bindRemark})
and dh.sub_type!='调拨'
and ifnull(dh.delete_flag,'0') !='1'
order by oper_time desc,number desc
order by ${column} ${order}
limit #{offset},#{rows}
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}
and dh.organ_id = #{oId}
and di.depot_id in
#{item}
and dh.type=#{type}
and (dh.sub_type!='采购' and dh.sub_type!='采购退货' and dh.sub_type!='销售' and dh.sub_type!='销售退货')
and dh.creator in (
#{creator}
)
and (dh.organ_id in (
#{organId}
) or dh.sub_type='采购退货' or dh.sub_type='零售' or dh.sub_type='其它')
and m.category_id in
#{item}
and dh.status = '1'
and dh.number like #{bindNumber}
and (me.bar_code 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.mfrs 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})
and dh.creator=#{creator}
and (dh.remark like #{bindRemark} or di.remark like #{bindRemark})
and dh.sub_type!='调拨'
and ifnull(dh.delete_flag,'0') !='1'
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}
and dh.organ_id = #{oId}
and di.depot_id in
#{item}
and dh.type=#{type}
and (dh.sub_type!='采购' and dh.sub_type!='采购退货' and dh.sub_type!='销售' and dh.sub_type!='销售退货')
and dh.creator in (
#{creator}
)
and (dh.organ_id in (
#{organId}
) or dh.sub_type='采购退货' or dh.sub_type='零售' or dh.sub_type='其它')
and m.category_id in
#{item}
and dh.status = '1'
and dh.number like #{bindNumber}
and (me.bar_code 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.mfrs 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})
and dh.creator=#{creator}
and (dh.remark like #{bindRemark} or di.remark like #{bindRemark})
and dh.sub_type!='调拨'
and ifnull(dh.delete_flag,'0') !='1'
select di.material_id materialId, me.bar_code barCode, m.name mName,m.model,m.standard,m.color,m.brand,m.mfrs,
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}
and dh.organ_id = #{oId}
and dh.creator in (
#{creator}
)
and (dh.organ_id in (
#{organId}
) or dh.sub_type='采购退货' or dh.sub_type='零售' or dh.sub_type='其它')
and ((
dh.sub_type!='调拨' and di.depot_id in
#{item}
) or (
dh.sub_type='调拨' and di.another_depot_id in
#{item}
))
and di.depot_id in
#{item}
and (me.bar_code 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.mfrs 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})
and m.category_id in
#{item}
and (dh.status = '1' or dh.status = '2' or dh.status = '3')
and (dh.sub_type!='采购' and dh.sub_type!='采购退货' and dh.sub_type!='销售' and dh.sub_type!='销售退货')
and ifnull(dh.delete_flag,'0') !='1'
group by di.material_id
order by materialId desc
order by ${column} ${order}
limit #{offset},#{rows}
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}
and dh.organ_id = #{oId}
and dh.creator in (
#{creator}
)
and (dh.organ_id in (
#{organId}
) or dh.sub_type='采购退货' or dh.sub_type='零售' or dh.sub_type='其它')
and ((
dh.sub_type!='调拨' and di.depot_id in
#{item}
) or (
dh.sub_type='调拨' and di.another_depot_id in
#{item}
))
and di.depot_id in
#{item}
and (me.bar_code 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.mfrs 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})
and m.category_id in
#{item}
and (dh.status = '1' or dh.status = '2' or dh.status = '3')
and (dh.sub_type!='采购' and dh.sub_type!='采购退货' and dh.sub_type!='销售' and dh.sub_type!='销售退货')
and ifnull(dh.delete_flag,'0') !='1'
group by di.material_id) a
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}
and dh.organ_id = #{oId}
and dh.creator in (
#{creator}
)
and (dh.organ_id in (
#{organId}
) or dh.sub_type='采购退货' or dh.sub_type='零售' or dh.sub_type='其它')
and ((
dh.sub_type!='调拨' and di.depot_id in
#{item}
) or (
dh.sub_type='调拨' and di.another_depot_id in
#{item}
))
and di.depot_id in
#{item}
and (me.bar_code 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.mfrs 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})
and m.category_id in
#{item}
and (dh.status = '1' or dh.status = '2' or dh.status = '3')
and (dh.sub_type!='采购' and dh.sub_type!='采购退货' and dh.sub_type!='销售' and dh.sub_type!='销售退货')
and ifnull(dh.delete_flag,'0') !='1'
select dh.number,me.bar_code barCode, m.name mname,m.model,m.standard,m.color,m.brand,m.mfrs,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}
and di.depot_id in
#{item}
and di.another_depot_id in
#{item}
and dh.sub_type=#{subType}
and dh.number like #{bindNumber}
and dh.creator in (
#{creator}
)
and m.category_id in
#{item}
and dh.status = '1'
and (me.bar_code 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.mfrs 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})
and (dh.remark like #{bindRemark} or di.remark like #{bindRemark})
and ifnull(dh.delete_flag,'0') !='1'
order by oper_time desc,number desc
order by ${column} ${order}
limit #{offset},#{rows}
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}
and di.depot_id in
#{item}
and di.another_depot_id in
#{item}
and dh.sub_type=#{subType}
and dh.number like #{bindNumber}
and dh.creator in (
#{creator}
)
and m.category_id in
#{item}
and dh.status = '1'
and (me.bar_code 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.mfrs 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})
and (dh.remark like #{bindRemark} or di.remark like #{bindRemark})
and ifnull(dh.delete_flag,'0') !='1'
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}
and di.depot_id in
#{item}
and di.another_depot_id in
#{item}
and dh.sub_type=#{subType}
and dh.number like #{bindNumber}
and dh.creator in (
#{creator}
)
and m.category_id in
#{item}
and dh.status = '1'
and (me.bar_code 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.mfrs 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})
and (dh.remark like #{bindRemark} or di.remark like #{bindRemark})
and ifnull(dh.delete_flag,'0') !='1'
select * 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 (case when ah.type='收款' then ifnull(sum(ai.each_amount),0) else 0-ifnull(sum(ai.each_amount),0) end) 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=#{billType}
and ah.bill_time <= #{beginTime}
and ifnull(ai.delete_flag,'0') !='1') preBackMoney,
-- 本期欠款
(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 (case when ah.type='收款' then ifnull(sum(ai.each_amount),0) else 0-ifnull(sum(ai.each_amount),0) end) 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=#{billType}
and ah.bill_time>#{beginTime} and ah.bill_time <= #{endTime}
and ifnull(ai.delete_flag,'0') !='1') backMoney
from jsh_supplier s
where s.enabled=1
and s.type=#{supplierType}
and s.id = #{organId}
and s.id in (
#{organId}
)
and ifnull(s.delete_flag,'0') !='1') tb
where begin_need+preDebtMoney-preReturnDebtMoney-preBackMoney+debtMoney-returnDebtMoney-backMoney!=0
where begin_need+preDebtMoney-preReturnDebtMoney-preBackMoney+debtMoney-returnDebtMoney-backMoney=0
order by begin_need+preDebtMoney-preReturnDebtMoney-preBackMoney+debtMoney-returnDebtMoney-backMoney desc
limit #{offset},#{rows}
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 (case when ah.type='收款' then ifnull(sum(ai.each_amount),0) else 0-ifnull(sum(ai.each_amount),0) end) 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=#{billType}
and ah.bill_time <= #{beginTime}
and ifnull(ai.delete_flag,'0') !='1') preBackMoney,
-- 本期欠款
(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 (case when ah.type='收款' then ifnull(sum(ai.each_amount),0) else 0-ifnull(sum(ai.each_amount),0) end) 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=#{billType}
and ah.bill_time>#{beginTime} and ah.bill_time <= #{endTime}
and ifnull(ai.delete_flag,'0') !='1') backMoney
from jsh_supplier s
where s.enabled=1
and s.type=#{supplierType}
and s.id = #{organId}
and s.id in (
#{organId}
)
and ifnull(s.delete_flag,'0') !='1') tb
where begin_need+preDebtMoney-preReturnDebtMoney-preBackMoney+debtMoney-returnDebtMoney-backMoney!=0
where begin_need+preDebtMoney-preReturnDebtMoney-preBackMoney+debtMoney-returnDebtMoney-backMoney=0
select sum(begin_need) begin_need, sum(preDebtMoney) preDebtMoney, sum(preReturnDebtMoney) preReturnDebtMoney, sum(preBackMoney) preBackMoney,
sum(debtMoney) debtMoney, sum(returnDebtMoney) returnDebtMoney, sum(backMoney) 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 (case when ah.type='收款' then ifnull(sum(ai.each_amount),0) else 0-ifnull(sum(ai.each_amount),0) end) 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=#{billType}
and ah.bill_time <= #{beginTime}
and ifnull(ai.delete_flag,'0') !='1') preBackMoney,
(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 (case when ah.type='收款' then ifnull(sum(ai.each_amount),0) else 0-ifnull(sum(ai.each_amount),0) end) 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=#{billType}
and ah.bill_time>#{beginTime} and ah.bill_time <= #{endTime}
and ifnull(ai.delete_flag,'0') !='1') backMoney
from jsh_supplier s
where s.enabled=1
and s.type=#{supplierType}
and s.id = #{organId}
and s.id in (
#{organId}
)
and ifnull(s.delete_flag,'0') !='1') tb
where begin_need+preDebtMoney-preReturnDebtMoney-preBackMoney+debtMoney-returnDebtMoney-backMoney!=0
where begin_need+preDebtMoney-preReturnDebtMoney-preBackMoney+debtMoney-returnDebtMoney-backMoney=0
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
and dh.number=#{number}
and ifnull(dh.delete_flag,'0') !='1'
update jsh_depot_head
set delete_flag='1'
where 1=1
and id in (
#{id}
)
select
from jsh_depot_head
where 1=1
and account_id in (
#{accountId}
)
and ifnull(delete_flag,'0') !='1'
select
from jsh_depot_head
where 1=1
and organ_id in (
#{organId}
)
and ifnull(delete_flag,'0') !='1'
select
from jsh_depot_head
where 1=1
and creator in (
#{creator}
)
and ifnull(delete_flag,'0') !='1'
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='出库')
and dh.oper_time >= #{beginTime}
and dh.oper_time <= #{endTime}
and (dh.status = '1' or dh.status = '2' or dh.status = '3')
and dh.creator in (
#{creator}
)
and ifnull(dh.delete_flag,'0') !='1'
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='销售退货')
and dh.organ_id = #{organId}
and dh.status =#{status}
and dh.number like #{bindNumber}
and dh.oper_time >= #{beginTime}
and dh.oper_time <= #{endTime}
and (m.name like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey})
and di.depot_id in (
#{depotId}
)
and dh.creator in (
#{creator}
)
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
limit #{offset},#{rows}
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='销售退货')
and dh.organ_id = #{organId}
and dh.status =#{status}
and dh.number like #{bindNumber}
and dh.oper_time >= #{beginTime}
and dh.oper_time <= #{endTime}
and (m.name like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey})
and di.depot_id in (
#{depotId}
)
and dh.creator in (
#{creator}
)
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 dh.link_number number, ifnull(sum(dh.deposit),0) finishDeposit
from jsh_depot_head dh
where 1=1
and dh.link_number in
#{item}
and ifnull(dh.delete_flag,'0') !='1'
group by dh.link_number
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'
update jsh_depot_head dh set dh.account_id = null
where dh.id=#{id}
and ifnull(dh.delete_flag,'0') !='1'
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 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
and dh.type=#{type}
and dh.sub_type in (
#{subType}
)
and dh.status in (
#{status}
)
and dh.number like #{bindNumber}
and dh.oper_time >= #{beginTime}
and dh.oper_time <= #{endTime}
and (me.bar_code like #{bindKey} or m.name like #{bindKey} or m.standard like #{bindKey} or m.model like
#{bindKey}
or m.color like #{bindKey} or m.mfrs like #{bindKey} or m.other_field1 like #{bindKey}
or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
and di.depot_id in (
#{depotId}
)
and dh.creator in (
#{creator}
)
and ifnull(dh.delete_flag,'0') !='1'
group by dh.id
order by dh.id desc
limit #{offset},#{rows}
) 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
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
and dh.type=#{type}
and dh.sub_type in (
#{subType}
)
and dh.status in (
#{status}
)
and dh.number like #{bindNumber}
and dh.oper_time >= #{beginTime}
and dh.oper_time <= #{endTime}
and (me.bar_code like #{bindKey} or m.name like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey}
or m.color like #{bindKey} or m.mfrs like #{bindKey} or m.other_field1 like #{bindKey}
or m.other_field2 like #{bindKey} or m.other_field3 like #{bindKey})
and di.depot_id in (
#{depotId}
)
and dh.creator in (
#{creator}
)
and ifnull(dh.delete_Flag,'0') !='1') tb
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'