--EXEC PROC_CUSTOMER_STATEMENT_SUMMARY_RPT @User = 'admin', @Date = '10/17/2019'

ALTER PROC PROC_CUSTOMER_STATEMENT_SUMMARY_RPT
(
	@User		VARCHAR(100)
	,@Date		VARCHAR(100)
)
AS
SET NOCOUNT ON;
BEGIN 
SELECT ac.acct_name +' | '+ac.acct_num AS acct_name,x.DRTOTAL,x.CRTOTAL FROM (
	SELECT T.acc_num,
	SUM(CASE WHEN PART_TRAN_TYPE = 'DR' THEN TRAN_AMT ELSE 0 END) AS DRTOTAL
	,SUM(CASE WHEN PART_TRAN_TYPE = 'CR' THEN TRAN_AMT ELSE 0 END) AS CRTOTAL	
	FROM FastMoneyPro_Account.DBO.VW_PostedAccountDetail T WITH (NOLOCK) 
	WHERE  T.COMPANY_ID=1 AND T.gl_sub_head_code='79'
	AND TRAN_DATE <= @Date  
	 GROUP BY acc_num
	)x INNER JOIN FastMoneyPro_Account.dbo.ac_master (NOLOCK) ac ON ac.acct_num=x.acc_num
	ORDER BY acct_name ASC 
RETURN
END


