from acr_invoice_contract_v t1, ACR_INVOICE_CONTRACT_CF_V t2
where
t1.contract_id=t2.contract_id
and ((decode(t2.cf_item,
'250',
t1.inv_object_taxpayer_type,
t1.object_taxpayer_type) = 'SMALL_SCALE_TAXPAYER' and
to_char(t2.due_date,'yyyy-mm') <= to_char(SYSDATE,'yyyy-mm')) or (t2.write_off_flag = 'FULL' and t1.contract_status not in('REPURING','REPUR')) or(nvl(t2.write_off_flag,'NOT')='FULL' and t1.contract_status in('REPURING','REPUR') and t2.cf_item<>1) or (nvl(t2.write_off_flag,'NOT') <> 'NOT' and t1.contract_status in('REPURING','REPUR') and t2.cf_item=1 ) )
AND cf_item<> 9
AND ((t2.cf_status='RELEASE' and t1.contract_status not in('REPURING','REPUR') and t2.cf_direction='INFLOW') or(t1.contract_status in ('REPURING','REPUR') and t2.cf_item in(1,2,250) and t2.cf_status='RELEASE' )or ( t2.cf_status in('BLOCK') and nvl(t2.write_off_flag,'NOT')='PARTIAL' and nvl(t2.billing_status,'NOT') != 'FULL' and t1.contract_status in ('REPURING','REPUR') and t2.cf_item =1 and t2.cf_direction='NONCASH' and nvl(t2.billing_amount,0) <> t2.received_amount))
and t2.cashflow_id not in (20265,34267,24445)
and nvl(t2.billing_status,'NOT') != 'FULL'
--and t2.cf_direction='INFLOW'
and ((decode(t2.cf_item,
'250',
t1.inv_object_taxpayer_type,
t1.object_taxpayer_type) <> 'SMALL_SCALE_TAXPAYER' and
<bm:query-fieldname="received_flag"queryExpression="(nvl(t1.express_status,'UNDELIVERED') !='RECEIVED' or ${@received_flag}='Y')"/>
<bm:query-fieldname="query_contract_number"queryExpression="exists (select 1 from con_contract cc where t1.contract_id = cc.contract_id and cc.contract_number between nvl(${@contract_number_f}, cc.contract_number) and nvl(${@contract_number_t}, cc.contract_number))"/>
<bm:query-fieldname="query_project_number"queryExpression="exists (select 1 from hls_document_flow_all_v df, prj_project pp where df.ar_invoice_hd_id = t1.invoice_hd_id and df.project_id = pp.project_id and pp.project_number between nvl(${@project_number_f}, pp.project_number) and nvl(${@project_number_t}, pp.project_number))"/>
<bm:query-fieldname="invoice_apply_num"
queryExpression="t.invoice_apply_num like '%'||${@invoice_apply_num}||'%'"/>
<bm:data-filterenforceOperations="query"expression="t1.invoice_status IN ('CONFIRM', 'POST')"/>
<bm:data-filterenforceOperations="query"expression="not exists (select 1 from acr_invoice_hd_wfl ah where ah.invoice_hd_id = t1.invoice_hd_id and ah.reversed_flag = 'I')"/>
<bm:query-fieldname="query_contract_number"queryExpression="exists (select 1 from hls_document_flow_all_v df, con_contract cc where df.contract_id = cc.contract_id and df.ar_invoice_hd_id = t1.invoice_hd_id and cc.contract_number between nvl(${@contract_number_f}, cc.contract_number) and nvl(${@contract_number_t}, cc.contract_number))"/>
<bm:query-fieldname="query_project_number"queryExpression="exists (select 1 from hls_document_flow_all_v df, prj_project pp where df.ar_invoice_hd_id = t1.invoice_hd_id and df.project_id = pp.project_id and pp.project_number between nvl(${@project_number_f}, pp.project_number) and nvl(${@project_number_t}, pp.project_number))"/>
<bm:query-fieldname="query_contract_number"queryExpression="exists (select 1 from hls_document_flow_all_v df, con_contract cc where df.contract_id = cc.contract_id and df.ar_invoice_hd_id = t1.invoice_hd_id and cc.contract_number between nvl(${@contract_number_f}, cc.contract_number) and nvl(${@contract_number_t}, cc.contract_number))"/>
<bm:query-fieldname="query_project_number"queryExpression="exists (select 1 from hls_document_flow_all_v df, prj_project pp where df.ar_invoice_hd_id = t1.invoice_hd_id and df.project_id = pp.project_id and pp.project_number between nvl(${@project_number_f}, pp.project_number) and nvl(${@project_number_t}, pp.project_number))"/>
<bm:fieldname="invoice_apply_num"expression="(select ap.invoice_apply_num from acr_invoice_apply ap, acr_invoice_hd_wfl aw where ap.wfl_apply_status='APPROVED' and ap.apply_mode='APPLY' and ap.invoice_apply_id=aw.invoice_apply_id
and aw.invoice_hd_id=t1.invoice_hd_id)"/>
<bm:fieldname="invoice_apply_id"expression="(select ap.invoice_apply_id from acr_invoice_apply ap, acr_invoice_hd_wfl aw where ap.wfl_apply_status='APPROVED' and ap.apply_mode='APPLY' and ap.invoice_apply_id=aw.invoice_apply_id
<bm:query-fieldname="query_contract_number"queryExpression="exists (select 1 from hls_document_flow_all_v df, con_contract cc where df.contract_id = cc.contract_id and df.ar_invoice_hd_id = t1.invoice_hd_id and cc.contract_number between nvl(${@contract_number_f}, cc.contract_number) and nvl(${@contract_number_t}, cc.contract_number))"/>
<bm:query-fieldname="query_project_number"queryExpression="exists (select 1 from hls_document_flow_all_v df, prj_project pp where df.ar_invoice_hd_id = t1.invoice_hd_id and df.project_id = pp.project_id and pp.project_number between nvl(${@project_number_f}, pp.project_number) and nvl(${@project_number_t}, pp.project_number))"/>
<bm:query-fieldname="invoice_apply_num"queryExpression="${@invoice_apply_num}=(select ap.invoice_apply_num from acr_invoice_apply ap, acr_invoice_hd_wfl aw where ap.wfl_apply_status='APPROVED' and ap.apply_mode='APPLY' and ap.invoice_apply_id=aw.invoice_apply_id