left join ag_mkt_leads_assigneds a on p.id = a.assigned_practitioner_id and a.is_active = 1
left join ag_acl_insurer_branch b on b.id = p.insurer_branch_id
left join ag_acl_practitioner_subordinate_system s on s.id = p.subordinate_system_id
left join ag_acl_insurer_branch b on b.id = p.insurer_branch_id and b.is_active = 1
left join ag_acl_practitioner_subordinate_system s on s.id = p.subordinate_system_id and s.is_active = 1
left join ag_acl_practitioner_setting ps on ps.practitioner_id = p.id
where
ps.practitioner_type_id = 28
...
...
@@ -88,9 +88,11 @@
and a.id = tt.leads_assigned_id)
<choose>
<whentest="type.equalsIgnoreCase('B')">
and p.insurer_branch_id is not null
group by p.insurer_branch_id
</when>
<whentest="type.equalsIgnoreCase('T')">
and p.subordinate_system_id is not null
group by p.subordinate_system_id
</when>
</choose>
...
...
@@ -131,107 +133,203 @@
<whentest="type.equalsIgnoreCase('B')">
b.branch_name as typeName,
b.id as typeId,
'' as level,
</when>
<otherwise>
s.name as typeName,
s.id as typeId,
(SELECT drop_option_code
from ag_acl_practitioner_setting b
LEFT JOIN ag_md_drop_options op1 ON op1.id = b.practitioner_level
where b.practitioner_id = p.id
) as level,
</otherwise>
</choose>
concat(ifnull(sum(cf.order_price),0),'') as fyp,
concat(ifnull(sum(cf.fyc_amount),0),'') as fyc,
ifnull(count(cf.order_id),0) as pieces
from ag_acl_practitioner p inner join (select t.* from ag_acl_customer_fortune t where t.drop_option_code = "S01" group by t.order_id ) cf on p.customer_id = cf.customer_id
inner join ag_po_order o on cf.order_id = o.id and o.status = 3
concat(ifnull(sum(o.order_price),0),'') as fyp,
concat(ifnull(sum(o.commission_amount),0),'') as fyc,
ifnull(count(o.id),0) as pieces
from ag_acl_practitioner p
inner join ag_po_order o on o.broker_customer_id = p.id
left join ag_acl_insurer_branch b on b.id = p.insurer_branch_id
left join ag_acl_practitioner_subordinate_system s on s.id = p.subordinate_system_id
where
where o.status = 3 and o.payment_status=3
<choose>
<whentest="type.equalsIgnoreCase('B')">
p.insurer_branch_id is not null
<whentest="category.equalsIgnoreCase('life')">
and o.product_category_id in (2,5,8)
</when>
<whentest="category.equalsIgnoreCase('pc')">
and o.product_category_id not in (2,5,8)
</when>
<otherwise>
p.subordinate_system_id is not null
</otherwise>
</choose>
<choose>
<whentest="time.equalsIgnoreCase('D')">
and TO_DAYS(o.order_date) = TO_DAYS(now())
and TO_DAYS(o.underwriting_date) = TO_DAYS(now())
</when>
<whentest="time.equalsIgnoreCase('W')">
and YEARWEEK(DATE_FORMAT(o.order_date,'%Y-%m-%d')) = YEARWEEK(NOW())
and YEARWEEK(DATE_FORMAT(o.underwriting_date,'%Y-%m-%d')) = YEARWEEK(NOW())
select p.insurer_branch_id insurer_branch_id,count(distinct f.customer_id) as real_count
from ag_acl_customer_fortune f inner join ag_po_order o on f.order_id = o.id and o.status = 3 and f.drop_option_code = "S01"
inner join ag_acl_practitioner p on f.customer_id = p.customer_id
group by p.insurer_branch_id
)a on a.insurer_branch_id = p.insurer_branch_id
left join
(
select t.insurer_branch_id,count(t.id) as mdrt_count from ag_acl_practitioner t where t.cert_list is not null and t.cert_list like "%1%" group by t.insurer_branch_id
)b on b.insurer_branch_id = p.insurer_branch_id
left join ag_acl_insurer_branch ib on ib.id = p.insurer_branch_id
where p.is_active = 1
and p.insurer_branch_id is not null
group by p.insurer_branch_id order by amount desc ;
SELECT
ib.branch_name AS typeName,
ib.id AS typeId,
ifnull( count( p.id ), 0 ) AS amount,
ifnull( a.real_count, 0 ) AS realAmount,
<includerefid="statisticsPractitionerHiring"/> AS hiringAmount,
sum(case when p.cert_list LIKE "%1%" then 1 else 0 end) AS mdrt
FROM
ag_acl_practitioner p
left join ag_acl_practitioner_hiring_approve_records hr on hr.hiring_basic_info_id=p.hiring_basic_info_id
and hr.approve_step_id=5 and hr.approving_status=1
LEFT JOIN (
SELECT p.insurer_branch_id insurer_branch_id,
count( DISTINCT o.broker_customer_id ) AS real_count
FROM ag_po_order o
INNER JOIN ag_acl_practitioner p ON o.broker_customer_id = p.customer_id
WHERE o.STATUS = 3 AND o.payment_status = 3
GROUP BY
p.insurer_branch_id
) a ON a.insurer_branch_id = p.insurer_branch_id
inner JOIN ag_acl_insurer_branch ib ON ib.id = p.insurer_branch_id and ib.is_active=1
WHERE
p.is_active = 1 AND p.insurer_branch_id IS NOT NULL
GROUP BY p.insurer_branch_id
ORDER BY amount DESC
</when>
<otherwise>
select
s.id as typeId,
s.name as typeName,
ifnull(count(p.id),0) as amount,
ifnull(a.real_count,0) as realAmount,
ifnull(b.mdrt_count,0) as mdrt
from ag_acl_practitioner p left join
(
select p.subordinate_system_id subordinate_system_id,count(distinct f.customer_id) as real_count
from ag_acl_customer_fortune f inner join ag_po_order o on f.order_id = o.id and o.status = 3 and f.drop_option_code = "S01"
inner join ag_acl_practitioner p on f.customer_id = p.customer_id
group by p.subordinate_system_id
)a on a.subordinate_system_id = p.subordinate_system_id
left join
(
select t.subordinate_system_id,count(t.id) as mdrt_count from ag_acl_practitioner t where t.cert_list is not null and t.cert_list like "%1%" group by t.subordinate_system_id
)b on b.subordinate_system_id = p.subordinate_system_id
left join ag_acl_practitioner_subordinate_system s on s.id = p.subordinate_system_id
where p.is_active = 1
and p.subordinate_system_id is not null
group by p.subordinate_system_id order by amount desc ;
SELECT
s.id as typeId,
s.name as typeName,
ifnull( count( p.id ), 0 ) AS amount,
ifnull( a.real_count, 0 ) AS realAmount,
<includerefid="statisticsPractitionerHiring"/> AS hiringAmount,
sum(case when p.cert_list LIKE "%1%" then 1 else 0 end) AS mdrt
FROM
ag_acl_practitioner p
left join ag_acl_practitioner_hiring_approve_records hr on hr.hiring_basic_info_id=p.hiring_basic_info_id
and hr.approve_step_id=5 and hr.approving_status=1