SELECT ap.invoice_id,ap.invoice_no 
FROM 0p4_invoice ap left join `0p4_gl_transaction` gl 
on gl.transaction_no=ap.invoice_no 
and gl.parent_object in ('app\\modules\\sale\\models\\Invoice','app\\modules\\sale\\models\\ConsignmentInvoice') 
WHERE gl.gl_transaction_id is null and ifnull(ap.opening,0)=0 and ifnull(ap.total_amount,0)!=0;


SELECT ap.invoice_id,ap.invoice_no 
FROM 0p4_cash_invoice ap left join `0p4_gl_transaction` gl 
on gl.transaction_no=ap.invoice_no 
and gl.parent_object='app\\modules\\sale\\models\\CashInvoice' 
WHERE gl.gl_transaction_id is null and ifnull(ap.opening,0)=0 and ifnull(ap.total_amount,0)!=0;


SELECT ap.id,ap.costing_no 
FROM 0p4_costing ap left join `0p4_gl_transaction` gl 
on gl.transaction_no=ap.costing_no 
and gl.parent_object='app\\modules\\sale\\models\\Costing' 
WHERE gl.gl_transaction_id is null and ifnull(ap.opening,0)=0 and ifnull(ap.total_amount,0)!=0;


SELECT ap.id,ap.credit_note_no 
FROM 0p4_credit_note ap left join `0p4_gl_transaction` gl 
on gl.transaction_no=ap.credit_note_no 
and gl.parent_object='app\\modules\\sale\\models\\CreditNote' 
WHERE gl.gl_transaction_id is null and ifnull(ap.opening,0)=0 and ifnull(ap.total_amount,0)!=0;


SELECT ap.id,ap.debit_note_no 
FROM 0p4_debit_note ap left join `0p4_gl_transaction` gl 
on gl.transaction_no=ap.debit_note_no 
and gl.parent_object='app\\modules\\sale\\models\\DebitNote' 
WHERE gl.gl_transaction_id is null and ifnull(ap.opening,0)=0 and ifnull(ap.total_amount,0)!=0;

SELECT ap.id,ap.vendor_credit_note_no 
FROM 0p4_vendor_credit_note ap left join `0p4_gl_transaction` gl 
on gl.transaction_no=ap.vendor_credit_note_no 
and gl.parent_object='app\\modules\\sale\\models\\VendorCreditNote' 
WHERE gl.gl_transaction_id is null and ifnull(ap.opening,0)=0 and ifnull(ap.total_amount,0)!=0;

SELECT ap.id,ap.vendor_debit_note_no 
FROM 0p4_vendor_debit_note ap left join `0p4_gl_transaction` gl 
on gl.transaction_no=ap.vendor_debit_note_no 
and gl.parent_object='app\\modules\\sale\\models\\VendorDebitNote' 
WHERE gl.gl_transaction_id is null  and ifnull(ap.total_amount,0)!=0;

SELECT ap.account_payable_id,ap.account_payable_payment_number FROM
0p4_account_payable ap
left join
`0p4_gl_transaction` gl on gl.transaction_no=ap.account_payable_payment_number 
and gl.parent_object='app\\models\\AccountPayable' WHERE gl.gl_transaction_id is null and ifnull(ap.opening,0)=0
and ap.post_status_id!=3;

SELECT ap.account_receivable_id,ap.account_receivable_receive_number 
FROM 0p4_account_receivable ap left join `0p4_gl_transaction` gl 
on gl.transaction_no=ap.account_receivable_receive_number 
and gl.parent_object='app\\models\\AccountReceivable' 
WHERE gl.gl_transaction_id is null 
and ifnull(ap.opening,0)=0 and ap.post_status_id!=3;

SELECT ap.pos_receipt_id,ap.pos_receipt_no 
FROM 0p4_pos_receipt ap left join `0p4_gl_transaction` gl 
on gl.transaction_no=ap.pos_receipt_no 
and gl.parent_object='app\\modules\\pos\\models\\PosReceipt' 
WHERE gl.gl_transaction_id is null  and ifnull(ap.grand_total,0)!=0;

SELECT ap.petty_cash_id,ap.petty_cash_number 
FROM 0p4_petty_cash ap left join `0p4_gl_transaction` gl 
on gl.transaction_no=ap.petty_cash_number 
and gl.parent_object='app\\models\\PettyCash' 
WHERE gl.gl_transaction_id is null  and ifnull(ap.total_amount,0)!=0;

SELECT ap.journal_id,ap.journal_no 
FROM 0p4_journal ap left join `0p4_gl_transaction` gl 
on gl.transaction_no=ap.journal_no 
and gl.parent_object='app\\models\\Journal' 
WHERE gl.gl_transaction_id is null and (ifnull(ap.debit_total,0)!=0 || ifnull(ap.credit_total,0)!=0);

SELECT ap.id,ap.invoice_no 
FROM 0p4_miscellaneous_invoice ap left join `0p4_gl_transaction` gl 
on gl.transaction_no=ap.invoice_no 
and gl.parent_object='app\\modules\\sale\\models\\MiscellaneousInvoice' 
WHERE gl.gl_transaction_id is null  and ifnull(ap.total_amount,0)!=0;
