|
sanjivus
Starting Member
16 Posts |
Posted - 2007-09-19 : 15:14:15
|
| Here is the code...[Code]USE [S2T_Test]GO/****** Object: StoredProcedure [dbo].[Pay_GetPaymentDetails] Script Date: 09/19/2007 15:02:39 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER OFFGOALTER procedure [dbo].[Pay_GetPaymentDetails](@DistID int,@InvNo int,@StartDate datetime,@EndDate datetime,@UnpaidAlso varchar(5),@SortBy int = 1)as begin SET @UnpaidAlso = LTRIM( RTRIM ( @UnpaidAlso )) IF ( @SortBy = 1 ) BEGIN SELECT Distributor.BusinessName, CONVERT(VARCHAR,RefNumber) as InvNo, ReceivePmt.TotalAmount as InvAmt , Memo, ReceivePmt.TxnDate as InvDttm,null as paiddttm, -UnusedPayment as BalanceAmt ,'0.00' as 'PaidAmt','0.00' as 'CreditAmt', null as CreatedBy, CONVERT(VARCHAR,ReceivePmt.RefNumber) AS qbinvno, ReceivePmt.TxnId, ReceivePmt.TxnDate AS DueDttm, 'P' as TxnType, ReceivePmt.DistID, Distributor.Address1,Distributor.Address2,Distributor.Address3,Distributor.ActConfirmFax,Distributor.ActPhone FROM ReceivePmt INNER JOIN Distributor ON ReceivePmt.DistID = Distributor.DistID WHERE ReceivePmt.distid = distributor.distid -- and invoice.invdttm between @Startdate and dateadd(day,1,@EndDate) and invoice.invamt > 0 and ( ReceivePmt.distid = @DistID OR @DistID = 0 ) and ( ReceivePmt.TxnDate between @Startdate and dateadd(day,1,@EndDate) ) and ( UnusedPayment <> 0 ) and ( Deleted <> 'H' ) UNION ALL SELECT Distributor.BusinessName, CONVERT(VARCHAR, invoice.InvNo) as InvNo, invoice.InvAmt , Memo, invoice.InvDttm,null as paiddttm, BalanceAmt ,'0.00' as 'PaidAmt','0.00' as 'CreditAmt', null as CreatedBy, CONVERT(VARCHAR, invoice.qbinvno) as qbinvno ,Invoice.TxnId, DueDttm,TxnType,Invoice.DistID, Distributor.Address1,Distributor.Address2,Distributor.Address3,Distributor.ActConfirmFax,Distributor.ActPhone FROM invoice,Distributor WHERE invoice.distid = distributor.distid -- and invoice.invdttm between @Startdate and dateadd(day,1,@EndDate) and invoice.invamt > 0 AND ( invoice.distid = @DistID OR @DistID = 0 ) AND ( invoice.qbinvno = @InvNo OR @InvNo = 0 ) AND ( invoice.invdttm between @Startdate and dateadd(day,1,@EndDate) ) AND ( @UnpaidAlso = 'TRUE' OR (Invoice.PaidFlg = 'N' AND balanceamt <> 0) ) AND ( invoice.InvType = 'D' OR invoice.InvType = 'A' OR Invoice.InvType = 'F' OR Invoice.InvType = 'N' OR Invoice.InvType = 'C' ) ORDER BY Invoice.InvDttm ASC, Invoice.QBInvNo ASC END ELSE BEGIN SELECT Distributor.BusinessName, CONVERT(VARCHAR,RefNumber) as InvNo, ReceivePmt.TotalAmount as InvAmt , Memo, ReceivePmt.TxnDate as InvDttm,null as paiddttm, -UnusedPayment as BalanceAmt ,'0.00' as 'PaidAmt','0.00' as 'CreditAmt', null as CreatedBy, CONVERT(VARCHAR,ReceivePmt.RefNumber) AS qbinvno, ReceivePmt.TxnId, ReceivePmt.TxnDate AS DueDttm, 'P' as TxnType, ReceivePmt.DistID, Distributor.Address1,Distributor.Address2,Distributor.Address3,Distributor.ActConfirmFax,Distributor.ActPhone FROM ReceivePmt INNER JOIN Distributor ON ReceivePmt.DistID = Distributor.DistID WHERE ReceivePmt.distid = distributor.distid -- and invoice.invdttm between @Startdate and dateadd(day,1,@EndDate) and invoice.invamt > 0 and ( ReceivePmt.distid = @DistID OR @DistID = 0 ) and ( ReceivePmt.TxnDate between @Startdate and dateadd(day,1,@EndDate) ) and ( UnusedPayment <> 0 ) UNION ALL SELECT Distributor.BusinessName, CONVERT(VARCHAR, invoice.InvNo) as InvNo, invoice.InvAmt , Memo, invoice.InvDttm,null as paiddttm, BalanceAmt ,'0.00' as 'PaidAmt','0.00' as 'CreditAmt', null as CreatedBy, CONVERT(VARCHAR, invoice.qbinvno) as qbinvno, Invoice.TxnId, DueDttm,TxnType,Invoice.DistID, Distributor.Address1,Distributor.Address2,Distributor.Address3,Distributor.ActConfirmFax,Distributor.ActPhone FROM invoice,Distributor WHERE invoice.distid = distributor.distid -- and invoice.invdttm between @Startdate and dateadd(day,1,@EndDate) and invoice.invamt > 0 AND ( invoice.distid = @DistID OR @DistID = 0 ) AND ( invoice.qbinvno = @InvNo OR @InvNo = 0 ) AND ( invoice.invdttm between @Startdate and dateadd(day,1,@EndDate) ) AND ( @UnpaidAlso = 'TRUE' OR (Invoice.PaidFlg = 'N' AND balanceamt <> 0) ) AND ( invoice.InvType = 'D' OR invoice.InvType = 'A' OR Invoice.InvType = 'F' OR Invoice.InvType = 'N' ) ORDER BY Invoice.DueDttm ASC , Invoice.QBInvNo ASC ENDend[/code] |
 |
|