CREATE PROCEDURE `spGetFeeDetailsNew` ( IN `P_BatchId` INTEGER , IN `P_StudentId` INTEGER , IN `P_TeacherId` INTEGER , IN `P_Month` INTEGER , IN `P_Year` INTEGER ) BEGIN DECLARE `l_StartDate` DATE ; DECLARE `l_EndDate` DATE ; DECLARE `l_StartDatestring` NVARCHAR (?) DEFAULT ? ; DECLARE `l_FeeSetupAllow` BOOL ; SET `l_StartDatestring` = `CONCAT` ( ? , `P_Month` , ? , `P_Year` ) ; SET `l_StartDate` = `STR_TO_DATE` ( `l_StartDatestring` , ? ) ; SET `l_EndDate` = `LAST_DAY` ( `l_StartDate` ) ; IF ( `P_StudentId` != ? ) THEN SELECT `F` . `Id` AS `FeeId` , `F` . `StudentId` AS `StudentId` , `F` . `FeeAmount` AS `FeeAmount` , CASE WHEN `F` . `IsRecurringMonthly` = ? THEN CAST ( `ifnull` ( `F` . `DateOfFeeCollection` , ? ) AS CHARACTER ) ELSE ? END AS `DueDate` , CASE WHEN `F` . `IsRecurringMonthly` = ? THEN CAST ( `F` . `DateOfFeeCollection` AS CHARACTER ) ELSE NOW ( ) END AS `CreatedDateTime` , CASE WHEN `IFNULL` ( `PT` . `TransactionStatusId` , ? ) = ? THEN ? ELSE `SM` . `Code` END AS `PaymentStatus` , `PT` . `TransactionStatusId` AS `PaymentStatusId` , CASE WHEN `IFNULL` ( `SM` . `Id` , ? ) = ? OR `IFNULL` ( `SM` . `Id` , ? ) = ? THEN `ifnull` ( CAST ( 