As you are using TSQL at that point :
@PFromDate=@PFromDate -1
@PToDate=@PToDate-1
needs the word SET
SET @PFromDate=@PFromDate -1
SET @PToDate=@PToDate-1
As an additional point the WITH statement of the CTE later on needs to have a ; between it and the preceding code so best to put
;WITH CTE (...