<?xml version="1.0" encoding="UTF-8" ?>
|
|
<sqls>
|
<dataSpace name="flow">
|
|
<sql name="insertQuarterFlows">
|
<![CDATA[
|
INSERT INTO tgt_flow_last3 (
|
id, year, quarter, quarter_no,
|
territory_code, co_manage_ratio,
|
product_code, product_name, sku_code, sku_name, customer_code,
|
qty, amt, sales_category)
|
select
|
md5(UUID_SHORT()) id, hm_fiscal_month.fiscal_year year, hm_fiscal_month.quarter_no quarter, hm_fiscal_month.fiscal_quarter quarter_no,
|
hm_territory_hospital_product_relation.territory_code, hm_territory_hospital_product_relation.co_manage_ratio,
|
hm_sales_flow.product_code, product_name, product_specs_code sku_code, product_specs_name sku_name, hm_territory_hospital_product_relation.hospital_code customer_code,
|
sum(ifnull(qty,0)) qty, sum(ifnull(amt,0)) amt, sales_category
|
from dscn_crm.hm_sales_flow
|
inner join dscn_crm.hm_fiscal_month on hm_fiscal_month.month_no = hm_sales_flow.data_version
|
left join dscn_crm.hm_institution_affiliated on hm_institution_affiliated.pharmacy_code = hm_sales_flow.institution_code and hm_institution_affiliated.product_code = hm_sales_flow.product_code
|
inner join dscn_crm.hm_territory_hospital_product_relation on hm_territory_hospital_product_relation.hospital_code = ifnull(hm_institution_affiliated.institution_code, hm_sales_flow.institution_code) and hm_territory_hospital_product_relation.product_code = hm_sales_flow.product_code
|
where sales_category='MONTH_END' and @{filter}
|
group by hm_territory_hospital_product_relation.territory_code, hm_territory_hospital_product_relation.hospital_code,institution_type,hm_sales_flow.product_code,product_specs_code, hm_fiscal_month.fiscal_quarter
|
]]>
|
</sql>
|
|
<sql name="updateCustomerInfoByCode">
|
<![CDATA[
|
update tgt_flow_last3
|
inner join dscn_crm.hm_institution on hm_institution.institution_code = tgt_flow_last3.customer_code
|
set tgt_flow_last3.customer_name = hm_institution.institution_name ,tgt_flow_last3.customer_id = hm_institution.id
|
where tgt_flow_last3.quarter_no = '@{quarterNo}'
|
]]>
|
</sql>
|
|
<sql name="updateTerritoryIdByCode">
|
<![CDATA[
|
update tgt_flow_last3
|
inner join dscn_crm.hm_territory on hm_territory.code = tgt_flow_last3.territory_code
|
set tgt_flow_last3.territory_id = hm_territory.id
|
where tgt_flow_last3.quarter_no = '@{quarterNo}'
|
]]>
|
</sql>
|
|
<sql name="updatePositionIdByTerritory">
|
<![CDATA[
|
update tgt_flow_last3
|
inner join dscn_crm.hm_position_territory on hm_position_territory.territory_id = tgt_flow_last3.territory_id
|
set tgt_flow_last3.position_id = hm_position_territory.position_id
|
where tgt_flow_last3.quarter_no = '@{quarterNo}'
|
]]>
|
</sql>
|
|
<sql name="updateSkuInfoByCode">
|
<![CDATA[
|
update tgt_flow_last3
|
inner join dscn_crm.md_product_sku on md_product_sku.sku_code = tgt_flow_last3.sku_code
|
set tgt_flow_last3.sku_id = md_product_sku.sku_id ,tgt_flow_last3.product_id = md_product_sku.product_id
|
where tgt_flow_last3.quarter_no = '@{quarterNo}'
|
]]>
|
</sql>
|
|
<sql name="updateTerritorySales">
|
<![CDATA[
|
update tgt_flow_last3
|
set territory_qty = qty * co_manage_ratio ,territory_amt = amt * co_manage_ratio ,position_qty = qty * co_manage_ratio ,position_amt = amt * co_manage_ratio
|
where tgt_flow_last3.quarter_no = '@{quarterNo}'
|
]]>
|
</sql>
|
|
</dataSpace>
|
</sqls>
|