|
1 | | -IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'quickfee_pe6_Fee_Bulk_Print') |
2 | | -BEGIN |
3 | | - DROP PROCEDURE quickfee_pe6_Fee_Bulk_Print |
4 | | -END |
5 | | -GO |
6 | | -CREATE PROCEDURE [dbo].[quickfee_pe6_Fee_Bulk_Print] |
7 | | - |
8 | | -@Selection nvarchar(MAX) |
9 | | - |
10 | | -AS |
11 | | - |
12 | | - DECLARE @QFURL nvarchar(255) |
13 | | - SET @QFURL = 'https://wafffcxktcftkcfgtleandtosh.com/payments/login' |
14 | | - |
15 | | - CREATE TABLE #SEL (DebtTranIndex int) |
16 | | - |
17 | | - INSERT INTO #SEL(DebtTranIndex) |
18 | | - SELECT Item |
19 | | - FROM dbo.SplitString(@Selection, '|') |
20 | | - WHERE ISNumeric(Item) = 1 |
21 | | - |
22 | | - INSERT INTO tblQuickFeeIDs(DebtTranIndex, FeeGuid) |
23 | | - SELECT S.DebtTranIndex, NEWID() |
24 | | - FROM #SEL S |
25 | | - LEFT JOIN tblQuickFeeIDs D ON S.DebtTranIndex = D.DebtTranIndex |
26 | | - WHERE D.DebtTranIndex IS NULL |
27 | | - |
28 | | - DECLARE @DisbNarr nvarchar(255) |
29 | | - DECLARE @DisbPerc decimal(7,2) |
30 | | - |
31 | | - SELECT @DisbNarr = TranSetDisbNarrative, @DisbPerc = TranSetDisbPercent |
32 | | - FROM tblTransactionSettings |
33 | | - WHERE TranSetIndex = 1 |
34 | | - |
35 | | - IF @DisbPerc IS NULL |
36 | | - SET @DisbPerc = 0 |
37 | | - |
38 | | - IF @DisbNarr IS NULL |
39 | | - SET @DisbNarr = 'Credit Surcharge at' |
40 | | - |
41 | | - SET @DisbNarr = @DisbNarr + ' ' + LTrim(RTrim(Str(@DisbPerc, 7, 2))) + '%' |
42 | | - |
43 | | - SELECT Coalesce(C.PracID, 1) As PracID, Coalesce(C.PracName, '') As PracName, Coalesce(C.PracAddress, '') As PracAddress, Coalesce(C.PracTitle, '') As PracTitle, Coalesce(C.PracTitleExt, '') As PracTitleExt, |
44 | | - Coalesce(C.PracTel, '') As PracTel, Coalesce(C.PracFax, '') As PracFax, Coalesce(C.PracEmail, '') As PracEmail, Coalesce(C.PracVATNumber, '') As PracVATNumber, BS.Blob As PracLogo, |
45 | | - Coalesce(DC.TranPrinted, 0) As TranPrinted, |
46 | | - Coalesce(E.ClientTerms, '') As ClientTerms, |
47 | | - Coalesce(TT.TransTypeName, '') As TransTypeName, |
48 | | - Coalesce(Par.StaffCode, '') AS PartnerCode, |
49 | | - Coalesce(Man.StaffCode, '') AS ManagerCode, |
50 | | - Coalesce(Stf.StaffCode, '') AS ConfirmedCode, |
51 | | - Coalesce(J.Job_Name, '') As Job_Name, Coalesce(J.Job_Code, '') As Job_Code, |
52 | | - Coalesce(E.ClientOffice, '') As ClientOffice, Coalesce(E.ClientVATNumber, '') As ClientVATNumber, |
53 | | - Coalesce(O.OfficeName, '') As OfficeName, Coalesce(O.OfficeAddress, '') As OfficeAddress, Coalesce(O.OfficePhone, '') As OfficePhone, Coalesce(O.OfficeFax, '') As OfficeFax, Coalesce(O.OfficeEMail, '') As OfficeEMail, Coalesce(@DisbNarr, 'Surcharge') As SurchDesc, |
54 | | - D.DebtTranIndex, D.DebtTranType, D.ContIndex, D.ClientCode, DateName(day, D.DebtTranDate) + ' ' + DateName(month, D.DebtTranDate) + ' ' + DateName(year, D.DebtTranDate) As FeeDate, D.DebtTranDate, D.DebtTranName, D.DebtTranAddress, |
55 | | - Coalesce(D.DebtTranAttention,'') AS DebtTranAttention, D.DebtTranRefAlpha, D.DebtTranRefNum, D.DebtTranMemo, D.DebtJob, |
56 | | - Case When D.DebtTranStyle IN (1, 3, 5, 7) Then 0 Else 1 End AS DebtTranStyle , D.DebtTranAmount, D.DebtTranVAT, D.DebtTranSurch, D.DebtTranTotal, D.DebtTranUnpaid, |
57 | | - DD.DebtTranIndex, DD.DebtDetSeq, DD.DebtDetType, DD.DebtDetService, DD.DebtDetAnalysis, DD.Amount, DD.VATRate, DD.VATPercent, DD.VATAmount, Coalesce(CT.ChargeFee, '') As ChargeFee, DD.FeeNarrative, |
58 | | - (SELECT COUNT(*) FROM tblTranDebtorDetail DD2 WHERE DD2.DebtDetType = DD.DebtDetType AND DD2.VATRate = DD.VATRate AND DD2.DebtTranIndex = DD.DebtTranIndex) As NumLinesByVATByType, |
59 | | - (SELECT COUNT(DISTINCT VATRate) FROM tblTranDebtorDetail DD2 WHERE DD2.DebtDetType = DD.DebtDetType AND DD2.DebtTranIndex = DD.DebtTranIndex) As NumLinesByType, |
60 | | - (SELECT COUNT(DISTINCT DebtDetType) FROM tblTranDebtorDetail DD2 WHERE DD2.DebtTranIndex = DD.DebtTranIndex) As NumTypes, |
61 | | - (SELECT COUNT(*) FROM tblTranDebtorDetail DD2 WHERE DD2.DebtTranIndex = DD.DebtTranIndex) As NumLines, |
62 | | - (D.DebtTranTotal - D.DebtTranUnpaid) AS Paid, DateAdd(dd, Cast(E.ClientTerms as int), D.DebtTranDate) As DateDue, |
63 | | - CASE WHEN DateAdd(dd, Cast(E.ClientTerms as int), D.DebtTranDate) < GetDate() THEN 'y' ELSE 'n' END As IsOverDue, |
64 | | - CASE WHEN (SELECT Max(VATPercent) FROM tblTranDebtorDetail DD2 WHERE DD2.DebtTranIndex = DD.DebtTranIndex) > 0 THEN 'VAT at ' + Cast((SELECT Max(VATPercent) FROM tblTranDebtorDetail DD2 WHERE DD2.DebtTranIndex = DD.DebtTranIndex) as nvarchar) + '%' ELSE 'VAT Exempt' END As VATDesc, |
65 | | - Cur.CurSymbol, 1 As Final, D.DeliveryFormat, Coalesce(E.ClientCreditEMail,'') As ClientCreditEMail, Coalesce(Cred.StaffEMail,'') As CreditControllerEMail, |
66 | | - C.PracEMailOptions, DC.TranFileId, |
67 | | - @QFURL + CAST(QF.FeeGuid as nvarchar(255)) As QuickFeeLink, |
68 | | - 'https://wafffcxktcftkcfgtleandtosh.com' AS QuickFeeDisplayLink |
69 | | - FROM tblTranDebtor D INNER JOIN |
70 | | - #SEL ON D.DebtTranIndex = #SEL.DebtTranIndex INNER JOIN |
71 | | - tblTranDebtor_Collection DC ON D.DebtTranIndex = DC.DebtTranIndex INNER JOIN |
72 | | - tblTranDebtorDetail DD ON D.DebtTranIndex = DD.DebtTranIndex INNER JOIN |
73 | | - tblControl C ON D.PracID = C.PracID INNER JOIN |
74 | | - tblEngagement E ON D.ContIndex = E.ContIndex INNER JOIN |
75 | | - tblOffices O ON E.ClientOffice = O.OfficeCode INNER JOIN |
76 | | - tblTranTypes TT ON D.DebtTranType = TT.TransTypeIndex INNER JOIN |
77 | | - tblChargeTypes CT ON DD.DebtDetType = CT.ChargeType INNER JOIN |
78 | | - tblStaff Par ON D.DebtTranPartner = Par.StaffIndex INNER JOIN |
79 | | - tblStaff Man ON D.DebtTranManager = Man.StaffIndex INNER JOIN |
80 | | - tblStaff Stf ON DC.ConfirmedBy = Stf.StaffIndex INNER JOIN |
81 | | - tblStaff Cred ON E.ClientCreditController = Cred.StaffIndex INNER JOIN |
82 | | - tblJob_Header J ON D.DebtJob = J.Job_Idx INNER JOIN |
83 | | - tblCurrency Cur ON D.DebtTranCur = Cur.Currency LEFT JOIN |
84 | | - tblBlobStorage BS ON C.PracLogoId = BS.Id INNER JOIN |
85 | | - tblQuickFeeIDs QF ON D.DebtTranIndex = QF.DebtTranIndex |
| 1 | +IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'quickfee_pe6_Fee_Bulk_Print') |
| 2 | +BEGIN |
| 3 | + DROP PROCEDURE quickfee_pe6_Fee_Bulk_Print |
| 4 | +END |
| 5 | +GO |
| 6 | +CREATE PROCEDURE [dbo].[quickfee_pe6_Fee_Bulk_Print] |
| 7 | + |
| 8 | +@Selection nvarchar(MAX) |
| 9 | + |
| 10 | +AS |
| 11 | + |
| 12 | + DECLARE @QFURL nvarchar(255) |
| 13 | + SET @QFURL = 'https://wafffcxktcftkcfgtleandtosh.com/payments/login/' |
| 14 | + |
| 15 | + CREATE TABLE #SEL (DebtTranIndex int) |
| 16 | + |
| 17 | + INSERT INTO #SEL(DebtTranIndex) |
| 18 | + SELECT Item |
| 19 | + FROM dbo.SplitString(@Selection, '|') |
| 20 | + WHERE ISNumeric(Item) = 1 |
| 21 | + |
| 22 | + INSERT INTO tblQuickFeeIDs(DebtTranIndex, FeeGuid) |
| 23 | + SELECT S.DebtTranIndex, NEWID() |
| 24 | + FROM #SEL S |
| 25 | + LEFT JOIN tblQuickFeeIDs D ON S.DebtTranIndex = D.DebtTranIndex |
| 26 | + WHERE D.DebtTranIndex IS NULL |
| 27 | + |
| 28 | + DECLARE @DisbNarr nvarchar(255) |
| 29 | + DECLARE @DisbPerc decimal(7,2) |
| 30 | + |
| 31 | + SELECT @DisbNarr = TranSetDisbNarrative, @DisbPerc = TranSetDisbPercent |
| 32 | + FROM tblTransactionSettings |
| 33 | + WHERE TranSetIndex = 1 |
| 34 | + |
| 35 | + IF @DisbPerc IS NULL |
| 36 | + SET @DisbPerc = 0 |
| 37 | + |
| 38 | + IF @DisbNarr IS NULL |
| 39 | + SET @DisbNarr = 'Credit Surcharge at' |
| 40 | + |
| 41 | + SET @DisbNarr = @DisbNarr + ' ' + LTrim(RTrim(Str(@DisbPerc, 7, 2))) + '%' |
| 42 | + |
| 43 | + SELECT Coalesce(C.PracID, 1) As PracID, Coalesce(C.PracName, '') As PracName, Coalesce(C.PracAddress, '') As PracAddress, Coalesce(C.PracTitle, '') As PracTitle, Coalesce(C.PracTitleExt, '') As PracTitleExt, |
| 44 | + Coalesce(C.PracTel, '') As PracTel, Coalesce(C.PracFax, '') As PracFax, Coalesce(C.PracEmail, '') As PracEmail, Coalesce(C.PracVATNumber, '') As PracVATNumber, BS.Blob As PracLogo, |
| 45 | + Coalesce(DC.TranPrinted, 0) As TranPrinted, |
| 46 | + Coalesce(E.ClientTerms, '') As ClientTerms, |
| 47 | + Coalesce(TT.TransTypeName, '') As TransTypeName, |
| 48 | + Coalesce(Par.StaffCode, '') AS PartnerCode, |
| 49 | + Coalesce(Man.StaffCode, '') AS ManagerCode, |
| 50 | + Coalesce(Stf.StaffCode, '') AS ConfirmedCode, |
| 51 | + Coalesce(J.Job_Name, '') As Job_Name, Coalesce(J.Job_Code, '') As Job_Code, |
| 52 | + Coalesce(E.ClientOffice, '') As ClientOffice, Coalesce(E.ClientVATNumber, '') As ClientVATNumber, |
| 53 | + Coalesce(O.OfficeName, '') As OfficeName, Coalesce(O.OfficeAddress, '') As OfficeAddress, Coalesce(O.OfficePhone, '') As OfficePhone, Coalesce(O.OfficeFax, '') As OfficeFax, Coalesce(O.OfficeEMail, '') As OfficeEMail, Coalesce(@DisbNarr, 'Surcharge') As SurchDesc, |
| 54 | + D.DebtTranIndex, D.DebtTranType, D.ContIndex, D.ClientCode, DateName(day, D.DebtTranDate) + ' ' + DateName(month, D.DebtTranDate) + ' ' + DateName(year, D.DebtTranDate) As FeeDate, D.DebtTranDate, D.DebtTranName, D.DebtTranAddress, |
| 55 | + Coalesce(D.DebtTranAttention,'') AS DebtTranAttention, D.DebtTranRefAlpha, D.DebtTranRefNum, D.DebtTranMemo, D.DebtJob, |
| 56 | + Case When D.DebtTranStyle IN (1, 3, 5, 7) Then 0 Else 1 End AS DebtTranStyle , D.DebtTranAmount, D.DebtTranVAT, D.DebtTranSurch, D.DebtTranTotal, D.DebtTranUnpaid, |
| 57 | + DD.DebtTranIndex, DD.DebtDetSeq, DD.DebtDetType, DD.DebtDetService, DD.DebtDetAnalysis, DD.Amount, DD.VATRate, DD.VATPercent, DD.VATAmount, Coalesce(CT.ChargeFee, '') As ChargeFee, DD.FeeNarrative, |
| 58 | + (SELECT COUNT(*) FROM tblTranDebtorDetail DD2 WHERE DD2.DebtDetType = DD.DebtDetType AND DD2.VATRate = DD.VATRate AND DD2.DebtTranIndex = DD.DebtTranIndex) As NumLinesByVATByType, |
| 59 | + (SELECT COUNT(DISTINCT VATRate) FROM tblTranDebtorDetail DD2 WHERE DD2.DebtDetType = DD.DebtDetType AND DD2.DebtTranIndex = DD.DebtTranIndex) As NumLinesByType, |
| 60 | + (SELECT COUNT(DISTINCT DebtDetType) FROM tblTranDebtorDetail DD2 WHERE DD2.DebtTranIndex = DD.DebtTranIndex) As NumTypes, |
| 61 | + (SELECT COUNT(*) FROM tblTranDebtorDetail DD2 WHERE DD2.DebtTranIndex = DD.DebtTranIndex) As NumLines, |
| 62 | + (D.DebtTranTotal - D.DebtTranUnpaid) AS Paid, DateAdd(dd, Cast(E.ClientTerms as int), D.DebtTranDate) As DateDue, |
| 63 | + CASE WHEN DateAdd(dd, Cast(E.ClientTerms as int), D.DebtTranDate) < GetDate() THEN 'y' ELSE 'n' END As IsOverDue, |
| 64 | + CASE WHEN (SELECT Max(VATPercent) FROM tblTranDebtorDetail DD2 WHERE DD2.DebtTranIndex = DD.DebtTranIndex) > 0 THEN 'VAT at ' + Cast((SELECT Max(VATPercent) FROM tblTranDebtorDetail DD2 WHERE DD2.DebtTranIndex = DD.DebtTranIndex) as nvarchar) + '%' ELSE 'VAT Exempt' END As VATDesc, |
| 65 | + Cur.CurSymbol, 1 As Final, D.DeliveryFormat, Coalesce(E.ClientCreditEMail,'') As ClientCreditEMail, Coalesce(Cred.StaffEMail,'') As CreditControllerEMail, |
| 66 | + C.PracEMailOptions, DC.TranFileId, |
| 67 | + @QFURL + CAST(QF.FeeGuid as nvarchar(255)) As QuickFeeLink, |
| 68 | + 'https://wafffcxktcftkcfgtleandtosh.com' AS QuickFeeDisplayLink |
| 69 | + FROM tblTranDebtor D INNER JOIN |
| 70 | + #SEL ON D.DebtTranIndex = #SEL.DebtTranIndex INNER JOIN |
| 71 | + tblTranDebtor_Collection DC ON D.DebtTranIndex = DC.DebtTranIndex INNER JOIN |
| 72 | + tblTranDebtorDetail DD ON D.DebtTranIndex = DD.DebtTranIndex INNER JOIN |
| 73 | + tblControl C ON D.PracID = C.PracID INNER JOIN |
| 74 | + tblEngagement E ON D.ContIndex = E.ContIndex INNER JOIN |
| 75 | + tblOffices O ON E.ClientOffice = O.OfficeCode INNER JOIN |
| 76 | + tblTranTypes TT ON D.DebtTranType = TT.TransTypeIndex INNER JOIN |
| 77 | + tblChargeTypes CT ON DD.DebtDetType = CT.ChargeType INNER JOIN |
| 78 | + tblStaff Par ON D.DebtTranPartner = Par.StaffIndex INNER JOIN |
| 79 | + tblStaff Man ON D.DebtTranManager = Man.StaffIndex INNER JOIN |
| 80 | + tblStaff Stf ON DC.ConfirmedBy = Stf.StaffIndex INNER JOIN |
| 81 | + tblStaff Cred ON E.ClientCreditController = Cred.StaffIndex INNER JOIN |
| 82 | + tblJob_Header J ON D.DebtJob = J.Job_Idx INNER JOIN |
| 83 | + tblCurrency Cur ON D.DebtTranCur = Cur.Currency LEFT JOIN |
| 84 | + tblBlobStorage BS ON C.PracLogoId = BS.Id INNER JOIN |
| 85 | + tblQuickFeeIDs QF ON D.DebtTranIndex = QF.DebtTranIndex |
0 commit comments