
select tbk_flex_3,0,0,0,0,0,0,0,0,0,0,0,0,'','','','',tbk_booking_number,'HO',''
from ke014t3.id_tb_booking_header where ltrim(length(tbk_flex_3))<>6 and tbk_flex_3 is not null and 
tbk_booking_number not in ('IB17060249','IB17060214','OB18110017','IB19040001','IB17060212')

select * from ke074t3.id_tb_ar_header

create or replace view ke074t3_support.bcd_ict_safcom_inv_rct
as
(select Branch,INV_Date,Invoice, IBOB, PO, Receipt, Receipt_Date from
(select 'HO' Branch,SUB_AR_DATE Inv_Date,SUB_AR_DOC_NUMBER Invoice,SUB_ARD_DETAIL_2 IBOB,SUB_AR_OTHER_REFERENCE PO,
(Select receipt from ke074t3_support.bcd_ict_s0171_receipt_with_inv where invoice=sUB_AR_DOC_NUMBER and rownum=1) Receipt,
(Select receipt_date from ke074t3_support.bcd_ict_s0171_receipt_with_inv where invoice=SUB_AR_DOC_NUMBER and rownum=1) Receipt_date
from ke014t3_support.id_tb_ar_details,ke014t3_support.id_tb_ar_header
where
SUB_ARD_DOC_NUMBER=SUB_AR_DOC_NUMBER
and sub_ar_code in ('S0171','S0171A','S0171B','S0171C','S0175','S0177') and SUB_AR_DOC_TYPE='TIN'
union all
select 'SAFCOM' Branch,SUB_AR_DATE INV_Date, SUB_AR_DOC_NUMBER Invoice, SUB_ARD_DETAIL_2 IBOB,SUB_AR_OTHER_REFERENCE PO,
(Select receipt from ke074t3_support.bcd_ict_s0171_receipt_with_inv where invoice=sUB_AR_DOC_NUMBER and rownum=1) Receipt,
(Select receipt_date from ke074t3_support.bcd_ict_s0171_receipt_with_inv where invoice=SUB_AR_DOC_NUMBER and rownum=1) Receipt_date
from ke074t3_support.id_tb_ar_details,ke074t3_support.id_tb_ar_header
where
SUB_ARD_DOC_NUMBER=SUB_AR_DOC_NUMBER
and sub_ar_code in ('S0171','S0171A','S0171B','S0171C','S0175','S0177') and SUB_AR_DOC_TYPE='TIN')
)


select * from bcd_ict_po_closure where BIPOC_PO_NUMBER='258191'
