SELECT pr.ProID,pr.ProName,lt.`PanelName`,lt.`Panel_ID` ,lt.`LedgerTransactionID`,lt.`LedgerTransactionNo`,lt.`PName`, lt.Age,lt.Gender,if(lt.Doctor_ID=2,'Other',lt.`DoctorName`)DocName,Date_Format(lt.Date,'%d-%m-%Y')Date, (Select Rate from f_ratelist where ItemID=itm.`ItemID` And Panel_id=78 limit 1)MrpRate, SUM(plo.Rate*plo.Quantity)GrossAmount,SUM(plo.DiscountAmt)DiscountAmt,SUM(plo.Amount)NetAmount,lt.Adjustment ,(SUM(plo.Amount)-lt.Adjustment)DueAmt FROM `patient_labinvestigation_opd` plo INNER JOIN f_ledgertransaction lt ON lt.`LedgerTransactionID`=plo.`LedgerTransactionID` INNER JOIN f_panel_master fpm ON fpm.Panel_ID=lt.Panel_ID INNER JOIN pro_master pr ON pr.PROID=fpm.PROID INNER JOIN f_itemmaster itm ON plo.`ItemId`=itm.`ItemID` AND lt.`Panel_ID` IN ({0}) AND lt.`CentreID` IN ({1}) and fpm.PROID IN ({2}) AND plo.date >=@fromDate AND plo.date <= @toDate AND IF(plo.isPackage=1,plo.`SubCategoryID`=15,plo.`SubCategoryID`!=15) GROUP BY lt.`LedgerTransactionID`,lt.`Panel_ID` ORDER BY pr.PROName,lt.PanelName,lt.Date;