<?xml version="1.0" encoding="UTF-8" ?>
|
<?DOCTYPE sqls SYSTEM "../config/sql.dtd" ?>
|
|
<sqls>
|
<dataSpace name="rebate">
|
|
<sql name = "addBookGeneralChannel">
|
<![CDATA[
|
insert into wm_book_general_channel (
|
id, year, month, org_id, org_code, org_name,
|
product_id, product_code, product_name, material_code, material_name, spec,
|
qty_total, qty_frozen, qty_available, amt, create_time
|
)
|
select @{guid}, @{year}, @{month},
|
org_id as org_id, org_code as org_code, org_name as org_name,
|
product_id, product_code, product_name, material_code, material_name, spec,
|
sum(qty_total) as qty_total, sum(qty_frozen) as qty_frozen,
|
sum(qty_available) as qty_available,
|
sum(amt) as amt, now()
|
from wm_book_detail
|
group by org_id, org_code, org_name
|
]]>
|
</sql>
|
|
<sql name = "getBookGeneralChannel">
|
<![CDATA[
|
select *
|
from (
|
select *
|
from wm_book_general_channel
|
union all
|
select @{guid}, '', @{getYear(}now()) AS year, MONTH (now()) AS month,
|
org_id as org_id, org_code as org_code, org_name as org_name,
|
product_id, product_code, product_name, material_code, material_name, spec,
|
sum(qty_total) as qty_total, sum(qty_frozen) as qty_frozen,
|
sum(qty_available) as qty_available, sum(amt) as amt,
|
now()
|
from wm_book_detail
|
group by org_id, org_code, org_name,
|
product_id, product_code, product_name, material_code, material_name, spec
|
) wm_book_general_channel
|
where @{filter}
|
order by year desc, month desc, org_code
|
@{limit}
|
]]>
|
</sql>
|
|
<sql name = "getBookFlowState">
|
<![CDATA[
|
select distinct doc_type as code, doc_type as name
|
from wm_book_flow
|
]]>
|
</sql>
|
|
<sql name = "getFreezeWarehouseByDetail">
|
<![CDATA[
|
select wm_warehouse.*, wm_warehouse.id as warehouse_id,
|
wm_warehouse.code as warehouse_code,
|
wm_warehouse.name as warehouse_name
|
from wm_warehouse
|
inner join (select *
|
from wm_book_detail
|
where id = '@{id}') wm_book_detail on wm_warehouse.org_id = wm_book_detail.org_id
|
where wm_warehouse.type_code = 'Freeze'
|
]]>
|
</sql>
|
|
<sql name="lockRebateBook">
|
update @{documentTable} document set update_time = now()
|
where document.id = '@{document_id}'
|
</sql>
|
|
<sql name="getRebateAmtBookFlowBasicFields">
|
<![CDATA[
|
select
|
rebate.bu_id,rebate.org_id, md_bu.name bu_name, '@{batch_mark}' batchMark,
|
rebate.id rebate_id, rebate.oa_no rebate_oa_no,
|
rebate.code rebate_code, rebate.item_name rebate_name,
|
rebate.year, rebate.season, rebate.doc_date valid_from, rebate.expire_date valid_to,rebate.batch_mark,
|
rebate.type_code, rebate.type_name,
|
rebate.account_id,rebate.account_code,rebate.account_name,
|
@{documentTypeCode} operate_name, document.doc_date, rebate.company_id, md_org.short_name company_name,
|
document.code doc_code, @{region} region, document_detail.id document_detail_id, @{document_num} as amt
|
from @{detailTableName} document_detail
|
left join @{tableName} document on @{documentDetailParentId} = document.id
|
inner join rebate_amt_detail rebate on rebate.id = @{rebateId}
|
left join md_bu on md_bu.id = rebate.bu_id
|
left join md_org on md_org.is_master = 'T' and md_org.id = rebate.company_id
|
where @{filter}
|
]]>
|
</sql>
|
|
<sql name="getCloseOrderDetailRebateAmtBookFlow">
|
<![CDATA[
|
select document.bu_id,document.org_id, md_bu.name bu_name, '@{batch_mark}' batch_mark,'@{batch_mark}' rebate_id, document.code rebate_code,
|
concat('订单', concat(document.code,concat('折扣退回', @{document_num}))) rebate_name, 'OrderReturn' type_code, '订单退回' type_name,
|
@{getYear(}@{currentDate}) year, @{season} season,
|
document.doc_date doc_date, @{currentDate} valid_from, '@{expireDate}' valid_to,'@{batch_mark}' batch_mark,
|
document.customer_id account_id,document.customer_code account_code,document.customer_name account_name,
|
@{documentTypeCode} operate_name, document.doc_date, document.company_id, md_org.short_name company_name,
|
document.code doc_code, document.region_name region, document_detail.id document_detail_id, @{document_num} as amt
|
from so_order_detail document_detail
|
left join so_order document on document_detail.parent_id = document.id
|
left join md_bu on md_bu.id = document.bu_id
|
left join md_org on md_org.is_master = 'T' and md_org.id = document.company_id
|
where @{filter}
|
]]>
|
</sql>
|
|
<sql name="getRebateQtyBookFlowBasicFields">
|
<![CDATA[
|
select rebate.bu_id,rebate.org_id, md_bu.name bu_name, '@{batch_mark}' batchMark,
|
rebate.id rebate_id, rebate.oa_no rebate_oa_no,
|
rebate.code rebate_code, rebate.item_name rebate_name, rebate.type_code, rebate.type_name,
|
rebate.year, rebate.season, document.doc_date, rebate.doc_date valid_from, rebate.expire_date valid_to,
|
rebate.product_id, rebate.product_code, rebate.product_name,
|
rebate.account_id,rebate.account_code,rebate.account_name,
|
document_detail.sku_id, document_detail.spec,
|
rebate.emption_product_id, rebate.emption_product_code, rebate.emption_product_name,
|
rebate.emption_sku_id, rebate.emption_spec,
|
@{documentTypeCode} operate_name, rebate.company_id, md_org.short_name company_name,
|
document.code doc_code, @{region} region, document_detail.id document_detail_id, @{document_num} as qty
|
from @{detailTableName} document_detail
|
left join @{tableName} document on @{documentDetailParentId} = document.id
|
inner join rebate_qty_detail rebate on rebate.id = @{rebateId}
|
left join md_bu on md_bu.id = rebate.bu_id
|
left join md_org on md_org.is_master = 'T' and md_org.id = rebate.company_id
|
where @{filter}
|
]]>
|
</sql>
|
|
<sql name="getCloseOrderDetailRebateQtyBookFlow">
|
<![CDATA[
|
select
|
document.bu_id,document.org_id, md_bu.name bu_name, '@{batch_mark}' batch_mark,'@{batch_mark}' rebate_id,
|
document.code rebate_code, concat('订单', concat(document.code, concat('买赠退回', @{document_num}))) rebate_name, 'OrderReturn' type_code, '订单退回' type_name,
|
@{getYear(}@{currentDate}) year, @{season} season,
|
document.doc_date doc_date, @{currentDate} valid_from, '@{expireDate}' valid_to,
|
document_detail.product_id, document_detail.product_code, document_detail.product_name,
|
document.customer_id account_id,document.customer_code account_code,document.customer_name account_name,
|
document_detail.sku_id, document_detail.spec,
|
null emption_product_id,null emption_product_code,null emption_product_name,
|
null emption_sku_id, null emption_spec,
|
@{documentTypeCode} operate_name, document.company_id, md_org.short_name company_name,
|
document.code doc_code, document.region_name region, document_detail.id document_detail_id, @{document_num} as qty
|
from so_order_detail document_detail
|
left join so_order document on document_detail.parent_id = document.id
|
left join md_bu on md_bu.id = document.bu_id
|
left join md_org on md_org.is_master = 'T' and md_org.id = document.company_id
|
where @{filter}
|
]]>
|
</sql>
|
|
<sql name="writeUpdateRebateAmtDetail">
|
<![CDATA[
|
update rebate_amt_detail
|
set rebate_amt_detail.batch_mark = '@{batch_mark}', rebate_amt_detail.update_time = @{update_time} ,
|
rebate_amt_detail.amt_used = rebate_amt_detail.amt_used - (
|
select (sum(@{IfEmpty}(num_return, 0)) - sum(@{IfEmpty}(num_used, 0))) as num_used_change
|
from rebate_amt_flow
|
where batch_mark = '@{batch_mark}' and record_operator = 'Update' and rebate_amt_flow.rebate_id = rebate_amt_detail.id
|
group by rebate_id ),
|
rebate_amt_detail.amt_freeze = rebate_amt_detail.amt_freeze + (
|
select (sum(@{IfEmpty}(num_freeze, 0)) - sum(@{IfEmpty}(num_unfreeze, 0))) as num_frozen_change
|
from rebate_amt_flow
|
where batch_mark = '@{batch_mark}' and record_operator = 'Update' and rebate_amt_flow.rebate_id = rebate_amt_detail.id
|
group by rebate_id )
|
where EXISTS(
|
select 1 from rebate_amt_flow
|
where rebate_amt_flow.REBATE_ID = rebate_amt_detail.id
|
and batch_mark = '@{batch_mark}' and record_operator = 'Update' )
|
]]>
|
</sql>
|
|
<sql name="writeUpdateRebateQtyDetail">
|
<![CDATA[
|
update rebate_qty_detail
|
set rebate_qty_detail.batch_mark = '@{batch_mark}', rebate_qty_detail.update_time = @{update_time} ,
|
rebate_qty_detail.qty_used = rebate_qty_detail.qty_used - (
|
select (sum(@{IfEmpty}(num_return, 0)) - sum(@{IfEmpty}(num_used, 0))) as num_used_change
|
from rebate_qty_flow
|
where batch_mark = '@{batch_mark}' and record_operator = 'Update' and rebate_qty_flow.rebate_id = rebate_qty_detail.id
|
group by rebate_id ),
|
rebate_qty_detail.qty_freeze = rebate_qty_detail.qty_freeze + (
|
select (sum(@{IfEmpty}(num_freeze, 0)) - sum(@{IfEmpty}(num_unfreeze, 0))) as num_frozen_change
|
from rebate_qty_flow
|
where batch_mark = '@{batch_mark}' and record_operator = 'Update' and rebate_qty_flow.rebate_id = rebate_qty_detail.id
|
group by rebate_id )
|
where EXISTS(
|
select 1 from rebate_qty_flow
|
where rebate_qty_flow.REBATE_ID = rebate_qty_detail.id
|
and batch_mark = '@{batch_mark}' and record_operator = 'Update' )
|
]]>
|
</sql>
|
|
<sql name="resetRebateAmtDetailOtherFields">
|
<![CDATA[
|
update rebate_amt_detail book_detail
|
set book_detail.amt_net = book_detail.amt_book - book_detail.amt_used,
|
book_detail.amt_available = book_detail.amt_book - book_detail.amt_used - book_detail.amt_freeze
|
where book_detail.batch_mark = '@{batch_mark}'
|
]]>
|
</sql>
|
|
<sql name="resetRebateQtyDetailOtherFields">
|
<![CDATA[
|
update rebate_qty_detail book_detail
|
set book_detail.qty_net = book_detail.qty_book - book_detail.qty_used,
|
book_detail.qty_available = book_detail.qty_book - book_detail.qty_used - book_detail.qty_freeze
|
where book_detail.batch_mark = '@{batch_mark}'
|
]]>
|
</sql>
|
|
<sql name="getNegativeRebateAmtDetail">
|
<![CDATA[
|
select count(1)
|
from rebate_amt_detail
|
where batch_mark = '@{batch_mark}'
|
and ((amt_available < 0) or (amt_net < 0))
|
]]>
|
</sql>
|
|
<sql name="getNegativeRebateQtyDetail">
|
<![CDATA[
|
select count(1)
|
from rebate_qty_detail
|
where batch_mark = '@{batch_mark}'
|
and ((qty_available < 0) or (qty_net < 0))
|
]]>
|
</sql>
|
</dataSpace>
|
|
<dataSpace name="rebate-validator">
|
<sql name="getNotEnoughImplantDetails">
|
<![CDATA[
|
select so_implant_detail.*, wm_book_detail.qty_available
|
from so_implant_detail
|
left join wm_book_detail
|
on so_implant_detail.warehouse_id = wm_book_detail.warehouse_id
|
and so_implant_detail.product_id = wm_book_detail.product_id
|
and so_implant_detail.order_right_code = wm_book_detail.order_right_code
|
and so_implant_detail.stock_type_code = wm_book_detail.stock_type_code
|
and @{IfEmpty}(so_implant_detail.batch_no, '') = @{IfEmpty}(wm_book_detail.batch_no, '')
|
and @{IfEmpty}(so_implant_detail.batch_sn, '') = @{IfEmpty}(wm_book_detail.batch_sn, '')
|
where parent_id = '@{document_id}'
|
and so_implant_detail.qty > @{IfEmpty}(wm_book_detail.qty_available, 0)
|
]]>
|
</sql>
|
</dataSpace>
|
|
</sqls>
|