SELECT * FROM ( SELECT 'Credit' ClientPaymentMode,fpm.Panel_Code ClientCode, fpm.`Company_Name` ClientName,CONCAT ( ROUND(ivac.S_Amount,2),'(',ivac.S_Notation,')')BaseAmount, ivac.PaymentMode, (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 )PaymentType, ivac.cardNo,ivac.OrderId RRR_NO,DATE_FORMAT(ivac.`CardDate`, '%d-%b-%Y')CardDate,ivac.S_Currency PayCurrency, ivac.`ReceivedAmt` PaidAmount,ivac.C_factor Conversion,ivac.Bank BankName,ivac.EntryByName EntryBy, DATE_FORMAT(ivac.`receiveddate`,'%d-%b-%Y') DepositDate ,DATE_FORMAT(ivac.EntryDate,'%d-%b-%Y %I:%i %p') `EntryDate/ValidateDate`, CASE WHEN IsCancel=1 THEN 'Reject' WHEN ValidateStatus=0 THEN 'Pending' WHEN ValidateStatus=1 THEN 'Approve' END `Status`,ivac.ApprovedBy, DATE_FORMAT(ivac.`receivedDate`,'%d-%b-%Y')ReceivedDate,Remarks,IF(IsCancel=1,CancelReason,'')RejectReason,IsCancel,IFNULL(CreditDebitNoteType,'')CreditDebitNoteType FROM `invoicemaster_onaccount` ivac INNER JOIN `f_panel_master` fpm ON ivac.`Panel_id` = fpm.`Panel_ID` WHERE fpm.`Panel_ID`<>'' AND ivac.panel_id IN({0}) AND ivac.ValidateStatus=1 AND IsCancel=0 AND ivac.`EntryDate`>=@FromDate AND ivac.`EntryDate`<=@ToDate UNION ALL SELECT 'Cash' ClientPaymentMode,fpm.Panel_Code ClientCode, fpm.`Company_Name` ClientName,CONCAT ( ROUND(sum(r.S_Amount),2),'(',group_concat(distinct r.S_Notation),')')BaseAmount, r.PaymentMode,'Deposit' PaymentType, group_concat(distinct r.cardNo) CardNo,r.TransactionID RRR_NO,group_concat(distinct DATE_FORMAT(r.`CardDate`, '%d-%b-%Y'))CardDate, group_concat(distinct r.S_Currency) PayCurrency,SUM(r.`Amount`) PaidAmount,group_concat(distinct r.C_factor) Conversion, Replace(r.BankName,'0','') BankName,group_concat(distinct r.CreatedBy) EntryBy, DATE_FORMAT(r.`CreatedDate`,'%d-%b-%Y') DepositDate ,DATE_FORMAT(r.CreatedDate,'%d-%b-%Y %I:%i %p') `EntryDate/ValidateDate`, 'Approve' `Status`,r.CreatedBy ApprovedBy, DATE_FORMAT(r.`CreatedDate`,'%d-%b-%Y')ReceivedDate, r.Narration Remarks,'' RejectReason,0 IsCancel,'' CreditDebitNoteType FROM `f_receipt` r INNER JOIN `f_ledgertransaction` lt ON lt.`ledgertransactionno` = r.`ledgertransactionno` INNER JOIN `f_panel_master` fpm ON r.`Panel_id` = fpm.`Panel_ID` WHERE fpm.`Panel_ID`<>'' AND r.panel_id IN({0}) AND lt.`date`>=@FromDate AND lt.`date`<=@ToDate GROUP BY r.Panel_ID,r.CreatedByID,DATE(r.`CreatedDate`),r.PaymentMode UNION ALL SELECT 'Credit' ClientPaymentMode,fpm.Panel_Code ClientCode, fpm.`Company_Name` ClientName,CONCAT(ivac.S_Amount,'(',ivac.S_Notation,')')BaseAmount, ivac.PaymentMode, (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 )PaymentType, ivac.cardNo,ivac.TransactionID RRR_NO,DATE_FORMAT(ivac.`CardDate`, '%d-%b-%Y')CardDate,ivac.S_Currency PayCurrency, ivac.`ReceivedAmt` PaidAmount,ivac.C_factor Conversion,ivac.Bank BankName,ivac.EntryByName EntryBy, DATE_FORMAT(ivac.`receiveddate`,'%d-%b-%Y') DepositDate ,DATE_FORMAT(ivac.EntryDate,'%d-%b-%Y %I:%i %p') `EntryDate/ValidateDate`,CASE WHEN IsCancel=1 THEN 'Reject' WHEN ValidateStatus=0 THEN 'Pending' WHEN ValidateStatus=1 THEN 'Approve' END `Status`,'' ApprovedBy, DATE_FORMAT(ivac.`receivedDate`,'%d-%b-%Y')ReceivedDate,Remarks,if(IsCancel=1,CancelReason,'')RejectReason,IsCancel,'' CreditDebitNoteType FROM `Invoicemaster_Payment` ivac INNER JOIN `f_panel_master` fpm ON ivac.`Panel_id` = fpm.`Panel_ID` WHERE fpm.`Panel_ID`<>'' AND ValidateStatus=0 AND ivac.panel_id IN({0}) AND ivac.`receivedDate`>= @FromDate AND ivac.`receivedDate`<= @ToDate )t ORDER BY STR_TO_DATE(t.`EntryDate/ValidateDate`, '%l:%i %p');