if(o.payment_term IS NOT NULL ,CONCAT(o.payment_term,o.payment_term_unit),(SELECT e.element_text from ag_po_order_life_product_elements e where o.id = e.order_id and e.factor_code like 'f_pay_term' LIMIT 1)) paymentTermUnit,
if(o.cover_term IS NOT NULL ,CONCAT(o.cover_term,o.cover_term_type) ,(SELECT e.element_text from ag_po_order_life_product_elements e where o.id = e.order_id and e.factor_code like 'f_coverage_term' LIMIT 1)) coverTermType,
if(o.payment_term IS NOT NULL ,CONCAT(o.payment_term,(case o.payment_term_unit when 'Y' then '年' when 'M' then '月' else '日' END ) ),(SELECT e.element_text from ag_po_order_life_product_elements e where o.id = e.order_id and e.factor_code like 'f_pay_term' LIMIT 1)) paymentTermUnit,
if(o.cover_term IS NOT NULL ,o.cover_term_type ,(SELECT e.element_text from ag_po_order_life_product_elements e where o.id = e.order_id and e.factor_code like 'f_coverage_term' LIMIT 1)) coverTermType,
o.order_price orderPrice,
pra.name practitionerName,
dept.name insurerBranchDeptName,
sub.name subordinateSystemName,
f.practitioner_level practitionerLevel,
f.commission_amount commissionAmount,
f.commission_type commissionType,
f.referral_rate referralRate,
f.referral_amount referralAmount,
op.drop_option_name commissionPayoutStatus,
pb.payout_yearmonth monthPeriod
from ag_acl_customer_fortune f
LEFT JOIN ag_po_order o
LEFT JOIN ag_acl_insurer i ON i.id = o.insurer_id
LEFT JOIN ag_product p ON p.id = o.product_id
LEFT JOIN ag_product_plan pp ON pp.id = o.plan_id
ON o.id = f.order_id
LEFT JOIN ag_acl_practitioner pra
LEFT JOIN ag_acl_insurer_branch_dept dept ON pra.dept_id = dept.id
LEFT JOIN ag_acl_practitioner_subordinate_system sub ON sub.id = pra.subordinate_system_id
ON pra.customer_id = f.customer_id
LEFT JOIN ag_acl_customer_fortune_payout_batch pb ON pb.id = f.payout_batch_id
LEFT JOIN ag_md_drop_options op
LEFT JOIN ag_md_drop_master mas ON mas.id = op.drop_master_id
ON op.drop_option_code = f.commission_payout_status
LEFT JOIN ag_po_order o
LEFT JOIN ag_acl_insurer i ON i.id = o.insurer_id
LEFT JOIN ag_product p ON p.id = o.product_id
LEFT JOIN ag_product_plan pp ON pp.id = o.plan_id
ON o.id = f.order_id
LEFT JOIN ag_acl_practitioner pra
LEFT JOIN ag_acl_insurer_branch_dept dept ON pra.dept_id = dept.id
LEFT JOIN ag_acl_practitioner_subordinate_system sub ON sub.id = pra.subordinate_system_id
ON pra.customer_id = f.customer_id
LEFT JOIN ag_acl_customer_fortune_payout_batch pb ON pb.id = f.payout_batch_id
LEFT JOIN ag_md_drop_options op
LEFT JOIN ag_md_drop_master mas ON mas.id = op.drop_master_id
ON op.drop_option_code = f.commission_payout_status