SELECT ivac.S_Currency, ivac.S_Amount, ivac.C_Factor, IFNULL(ivac.CardNo,'') CardNo, IF(IFNULL(ivac.CardNo,'')='','',DAte_Format(CardDate,'%d-%M-%y')) CardDate, ivac.`ID`,fpm.Panel_Code, fpm.`Company_Name`,ivac.`ReceivedAmt` `ReceivedAmt`,ivac.EntryByName EntryBy , DATE_FORMAT(ivac.`receiveddate`,'%d-%b-%Y') AdvanceAmtDate,(case when ivac.CreditNote='0' then 'Deposit' when ivac.CreditNote='1' then 'Credit Note' when ivac.CreditNote='2' then 'Debit Note' when ivac.CreditNote='3' then 'Cheque Bounce' else '' end )CreditNote ,DATE_FORMAT(ivac.EntryDate,'%d-%b-%Y %I:%i %p') EntryDate ,IF((SELECT MAX(EntryDate) FROM `invoicemaster_onaccount` WHERE panel_id = IF(@panel_id='',panel_id,@panel_id) AND isCancel=0 AND IFNULL(invoiceNo, '') <> '') > ivac.`EntryDate`,0,1)`AllowCancel` , remarks,PaymentMode,IFNULL(ChequeNo,'')ChequeNo,IF(ivac.ChequeDate='0001-01-01','',DATE_FORMAT(ivac.ChequeDate,'%d-%b-%Y'))ChequeDate,ivac.HdfctnxID AS TransactionID FROM `invoicemaster_onaccount` ivac INNER JOIN `f_panel_master` fpm ON ivac.`Panel_id` = fpm.`Panel_ID` WHERE ivac.panel_id = if(@panel_id='',ivac.panel_id,@panel_id) AND isCancel = 0 AND CreditNote=@CreditNote ORDER BY ivac.`EntryDate` DESC limit 500