INSERT INTO `tbl_acc_details`(`_date`, `description`, `cheque_no`, `payee`, `amount`, `type`, `tag_id`, `account_id`, `transaction_id`, `event`, `is_send`, `account_code`, `location_id`, `cheque_date`, `sent_on`, `log_id`, `created_on`,transaction_code)
select 
( case when sp.payment_type = 'CHEQUE' then sp.cheque_date else sp.payment_date end ) as _date
,'by api - ' as description
,( case when sp.payment_type = 'CHEQUE' then sp.cheque_no else '' end ) as cheque_no
,s.name as payee
,sp.amount as amount
,'DR' as `type`
,0 as tag_id
,85 as account_id 
,sp.id as transaction_id 
,'supplier_payments' as `event`
,0 as is_send
,'Accounts Payable' as account_code
,bil.fn_companyCode as location_id
,now() as cheque_date
,now() as sent_on
,'' as log_id
,now() as created_on
,sp.code as transaction_code
from tbl_supplier_payments sp 
inner join tbl_supplier s on s.supplier_id = sp.supplier_id
inner join tbl_branch_inventory_locations bil on bil.id = sp.location_id
where sp.payment_type in ('CASH','CHEQUE','ONLINE')
and sp.id = ?






