USE [CCH_ENT] GO /****** Object: UserDefinedFunction [dbo].[UFN_String2Table] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER FUNCTION [dbo].[UFN_String2Table] ( @List VARCHAR(MAX) ) RETURNS @ReturnTable TABLE ( column1 varchar(64) ) AS BEGIN DECLARE @mDelimiter char(1) = '|' IF ISNULL(@List, '') <> '' BEGIN /* this procedure fills a temp table from a delimiter-separated list of 'staff' values sent in */ /* note that the #tempstaff table must be created before this stored proc is called */ DECLARE @s NVARCHAR(max) WHILE LEN(@List) > 0 BEGIN IF CHARINDEX(@mDelimiter, @List) > 0 /* if there's a delimiter in the list, we need to grab everything up to the first delimiter */ BEGIN SET @s = LTRIM(RTRIM(SUBSTRING(@List, 1, CHARINDEX(@mDelimiter, @List) - 1))) SET @List = SUBSTRING(@List, CHARINDEX(@mDelimiter, @List) + 1, LEN(@List)) END ELSE /* no mare delimiters in the list, we will grab all remaining characters */ BEGIN SET @s = LTRIM(RTRIM(@List)) SET @List= '' END INSERT INTO @ReturnTable (column1) VALUES (@s) END END RETURN END GO /****** Object: View [dbo].[UVW_ARComponentDetail] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER VIEW [dbo].[UVW_ARComponentDetail] AS /* this query provides full A/R balance detail by Component */ /* this query is very similar to UVW_ARAgingDetail, and it might be possible to combine the info from those 2 views into one */ /* Invoice */ SELECT 1 AS TransactionType, ClientIdent, InvoiceDateTime AS TransactionDate, AcctPerDateTime, InvoiceNumber, 0 AS AppliedType, InvoiceNumber AS AppliedTo, (StdWIPAmount + AdjustmentAmount + ProgressBilledAmount - ProgressApplyAmount) AS Amount FROM INVOICE WHERE StatusCode=1 /* 1=posted */ /* Sales Tax */ UNION ALL SELECT 2 AS TransactionType, ClientIdent, InvoiceDateTime AS TransactionDate, AcctPerDateTime, InvoiceNumber, 0 AS AppliedType, InvoiceNumber AS AppliedTo, (TaxAmount + ProgressTaxAmount - TaxAppAmount - ProgressTaxAppAmount) AS Amount FROM INVOICE WHERE StatusCode=1 /* 1=posted */ and (TaxAmount + ProgressTaxAmount - TaxAppAmount - ProgressTaxAppAmount) <> 0 /* Miscellaneous charge, Handling Fee, Finance Charge */ UNION ALL SELECT CASE AREntryTypeCode WHEN 8 THEN 10 /* 8=Miscellaneous charge */ WHEN 9 THEN 10 /* 9=Handling Fee */ WHEN 10 THEN 3 /* 10=Finance Charge */ END AS TransactionType, ClientIdent, TransactionDateTime AS TransactionDate, PostedDateTime AS AcctPerDateTime, ReferenceNumber AS InvoiceNumber, 0 AS AppliedType, ReferenceNumber AS AppliedTo, ARChargesAmount AS Amount FROM ARCHARGES WHERE AREntryTypeCode IN (8,9,10) AND CorrectionStatusCode=1 /* 1=new entry */ /* Payments (Distributed) */ UNION ALL SELECT 4 AS TransactionType, ARTRANSACTION.ClientIdent, ARTRANSACTION.TransactionDateTime AS TransactionDate, ARTRANSACTION.PostedDateTime AS AcctPerDateTime, ARTRANSACTION.ReferenceNumber AS InvoiceNumber, ISNULL(ARCharges.AREntryTypeCode,0) AS AppliedType, COALESCE( (SELECT InvoiceNumber FROM INVOICE WHERE InvoiceIdent=ARDISTRIBUTION.InvoiceIdent), (SELECT ReferenceNumber FROM ARCHARGES WHERE ARChargesIdent=ARDISTRIBUTION.ARChargesIdent) ) AS AppliedTo, ISNULL(-ARDISTRIBUTION.DistributionAmount,0.00) AS Amount FROM ARTRANSACTION LEFT JOIN ARDISTRIBUTION on ARDISTRIBUTION.ARIdent=ARTRANSACTION.ARIdent LEFT JOIN ARCharges on ARCHARGES.ARChargesIdent=ARDISTRIBUTION.ARChargesIdent WHERE ARTRANSACTION.AREntryTypeIntCode=1 /* 1=payment */ AND ARTRANSACTION.CorrectionStatusCode=1 /* 1=new entry */ AND ARTRANSACTION.Posted = 1 /* 1=posted */ /* Payments (UnDistributed) */ UNION ALL SELECT 5 AS TransactionType, ClientIdent, TransactionDateTime AS TransactionDate, PostedDateTime AS AcctPerDateTime, ReferenceNumber AS InvoiceNumber, 0 AS AppliedType, '' AS AppliedTo, -ARTRANSACTION.amount + ISNULL((select sum(DistributionAmount) FROM ARDISTRIBUTION where arident=ARTRANSACTION.arident),0) AS Amount FROM ARTRANSACTION WHERE ARTRANSACTION.AREntryTypeIntCode = 1 /* 1=payment */ AND ARTRANSACTION.CorrectionStatusCode = 1 /* 1=new entry */ AND ARTRANSACTION.amount - ISNULL((select sum(DistributionAmount) FROM ARDISTRIBUTION where arident=ARTRANSACTION.arident),0)<>0 AND ARTRANSACTION.Posted = 1 /* Adjustment type 2/3 Distributed */ UNION ALL SELECT 6 AS TransactionType, ARTRANSACTION.ClientIdent, ARTRANSACTION.TransactionDateTime AS TransactionDate, ARTRANSACTION.PostedDateTime AS AcctPerDateTime, ARTRANSACTION.ReferenceNumber AS InvoiceNumber, ISNULL(ARCharges.AREntryTypeCode,0) AS AppliedType, INVOICE.InvoiceNumber AS AppliedTo, ISNULL(-DistributionAmount,0) as Amount FROM ARTRANSACTION LEFT JOIN ARDISTRIBUTION on ARTRANSACTION.ARIdent=ARDISTRIBUTION.ARIdent LEFT JOIN ARCharges on ARCHARGES.ARChargesIdent=ARDISTRIBUTION.ARChargesIdent LEFT JOIN INVOICE ON Invoice.InvoiceIdent=ARDISTRIBUTION.InvoiceIdent WHERE ARTRANSACTION.CorrectionStatusCode=1 /* 1=new entry */ AND ARTRANSACTION.AREntryTypeIntCode IN (2,3) /* 2=credit memo 3=credit adjustment */ AND ARTRANSACTION.Posted = 1 /* 1=posted */ /* Adjustment type 6/7 Distributed */ UNION ALL SELECT 7 AS TransactionType, ARTRANSACTION.ClientIdent, ARTRANSACTION.TransactionDateTime AS TransactionDate, ARTRANSACTION.PostedDateTime AS AcctPerDateTime, ARTRANSACTION.ReferenceNumber AS InvoiceNumber, ISNULL(ARCharges.AREntryTypeCode,0) AS AppliedType, INVOICE.InvoiceNumber AS AppliedTo, ISNULL(DistributionAmount,0) as Amount FROM ARTRANSACTION LEFT JOIN ARDISTRIBUTION on ARTRANSACTION.ARIdent=ARDISTRIBUTION.ARIdent LEFT JOIN ARCharges on ARCHARGES.ARChargesIdent=ARDISTRIBUTION.ARChargesIdent LEFT JOIN INVOICE on invoice.InvoiceIdent=ARDISTRIBUTION.InvoiceIdent WHERE ARTransaction.CorrectionStatusCode=1 /* 1=new entry */ and AREntryTypeIntCode IN (6,7) /* 6=debit memo 7=debit adjustment */ AND ARTRANSACTION.Posted = 1 /* 1=posted */ /* Adjustments 2/3 Undistributed */ UNION ALL SELECT 8 AS TransactionType, ClientIdent, TransactionDateTime AS TransactionDate, PostedDateTime AS AcctPerDateTime, ReferenceNumber AS InvoiceNumber, 0 AS AppliedType, '' AS AppliedTo, -(amount - ISNULL((select sum(DistributionAmount) FROM ARDISTRIBUTION where ARDISTRIBUTION.arident=ARTRANSACTION.arident),0)) AS Amount FROM ARTRANSACTION WHERE AREntryTypeIntCode in (2,3) /* 2=credit memo 3=credit adjustment */ AND CorrectionStatusCode = 1 AND (amount - ISNULL((select sum(DistributionAmount) FROM ARDISTRIBUTION where arident=ARTRANSACTION.arident),0))<>0 AND Posted = 1 /* Adjustments 6/7 Undistributed */ UNION ALL SELECT 9 AS TransactionType, ClientIdent, TransactionDateTime AS TransactionDate, PostedDateTime AS AcctPerDateTime, ReferenceNumber AS InvoiceNumber, 0 AS AppliedType, '' AS AppliedTo, Amount - ISNULL((select sum(DistributionAmount) FROM ARDISTRIBUTION where arident=ARTRANSACTION.arident),0) AS Amount FROM ARTRANSACTION WHERE AREntryTypeIntCode in (6,7) /* 6=debit memo 7=debit adjustment */ AND CorrectionStatusCode = 1 AND amount - ISNULL((select sum(DistributionAmount) FROM ARDISTRIBUTION where arident=ARTRANSACTION.arident),0)<>0 AND Posted = 1 /* Write-Off Distributed */ UNION ALL SELECT 11 AS TransactionType, ARTransaction.ClientIdent, ARTRANSACTION.TransactionDateTime AS TransactionDate, ARTRANSACTION.PostedDateTime AS AcctPerDateTime, ARTRANSACTION.ReferenceNumber AS InvoiceNumber, ISNULL(ARCharges.AREntryTypeCode,0) AS AppliedType, INVOICE.InvoiceNumber AS AppliedTo, ISNULL(-ARDISTRIBUTION.DistributionAmount,0.00) AS Amount FROM ARTRANSACTION LEFT JOIN ARDISTRIBUTION ON ARDISTRIBUTION.ARIdent=ARTRANSACTION.ARIdent LEFT JOIN ARCharges on ARCHARGES.ARChargesIdent=ARDISTRIBUTION.ARChargesIdent LEFT JOIN INVOICE on invoice.InvoiceIdent=ARDISTRIBUTION.InvoiceIdent WHERE AREntryTypeIntCode IN (4,5) /* 4=GST WriteOff 5=WriteOff */ and ARTransaction.CorrectionStatusCode=1 AND ARTRANSACTION.Posted = 1 /* Write-Off Undistributed */ UNION ALL SELECT 12 AS TransactionType, ClientIdent, TransactionDateTime AS TransactionDate, PostedDateTime AS AcctPerDateTime, ReferenceNumber AS InvoiceNumber, 0 AS AppliedType, '' AS AppliedTo, -Amount + ISNULL((select sum(DistributionAmount) FROM ARDISTRIBUTION where arident=ARTRANSACTION.arident),0) AS Amount FROM ARTRANSACTION WHERE AREntryTypeIntCode IN (4,5) /* 4=GST WriteOff 5=WriteOff */ AND CorrectionStatusCode = 1 AND Amount - ISNULL((select sum(DistributionAmount) FROM ARDISTRIBUTION where arident=ARTRANSACTION.arident),0)<>0 AND Posted = 1 GO /****** Object: View [dbo].[UVW_ARAvgDaysToPay] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER VIEW [dbo].[UVW_ARAvgDaysToPay] AS SELECT p9.clientident ,ar1.AppliedTo /* invoice number, underlying field is Invoice.InvoiceNumber */ ,ar1.AcctPerDateTime AS paymentdate /* individual payment posting date, underlying field is ARTransaction.PostedDateTime */ ,invoice.InvoiceDateTime /* original invoice date */ ,ar1.amount as pmtamount /* individual payment amount */ ,ar1.TransactionType /* 4=Payment 5=Credit 6=Debit 7=Writeoff 8=Adjustment */ ,(Select amount /* original invoice amount */ from [UVW_ARComponentDetail] ar2 where ar2.ClientIdent = p9.ClientIdent and ar2.AppliedTo = ar1.AppliedTo and ar2.TransactionType = 1) as invamount, invoice.invoicetitle FROM /* this creates a bare-bones unfiltered list of closed invoices */ (SELECT ClientIdent,AppliedTo FROM [UVW_ARComponentDetail] WHERE AppliedTo <> '' GROUP BY ClientIdent,AppliedTo HAVING SUM(amount) = 0) p9 INNER JOIN /* this gets a list of individual payments summarized by the client, apply to, and posting date note...this does not have distribution detail */ (SELECT clientident, AppliedTo, AcctPerDateTime, TransactionType, sum(amount) AS amount FROM [UVW_ARComponentDetail] WHERE [UVW_ARComponentDetail].TransactionType > 3 /* 4=Payment 5=Credit 6=Debit 7=Writeoff 8=Adjustment */ GROUP BY clientident,AppliedTo,AcctPerDateTime,TransactionType ) ar1 on ar1.ClientIdent = p9.ClientIdent AND p9.AppliedTo = ar1.AppliedTo LEFT JOIN INVOICE on ar1.AppliedTo = INVOICE.InvoiceNumber GO /****** Object: View [dbo].[UVW_WIPAR02Clientident] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER VIEW [dbo].[UVW_WIPAR02Clientident] AS /* WIP billed amount for any time period summarized by clientident */ SELECT WIP.Wipident ,WIP.ClientIdent ,WIP.ServiceCodeIdent ,WIP.InvoiceIdent ,WIP.StaffIdent ,WIP.ProjectIdent -- 03/22/2024 added field to support a report that needs this ,WIP.TECustomValue /* per bug 247738, hours should only be added if the WIPTypeCode=0 (time), and should not be added if hours are applied to expenses */ ,CASE WIPTypeCode WHEN 0 THEN WIP.[Hours] ELSE 0 END AS [Hours] ,WIP.StdAmount ,WIP.TransactionDate /* AdjAmount is a strict calculation of rate x hours */ ,CASE WIPTypeCode WHEN 0 THEN AdjAmount ELSE 0 END AS [TimeAdjAmount] ,CASE WIPTypeCode WHEN 0 THEN 0 ELSE AdjAmount END AS [ExpenseAdjAmount] ,WIP.AdjAmount ,WIP.SurchargeAmount /* note..."billedamount" is the adjusted amount billed with write up/down included */ /* 08-02-2023 - similar to below, I am changing the BilledAmount formula */ /* 01-12-2024 - updated to add SurchargeAmount to the billed amounts */ ,CASE WIPTypeCode WHEN 0 THEN WIP.AdjAmount + WIP.SurchargeAmount + ISNULL(t1.WriteUpDownAmount,0.00) ELSE 0 END AS [TimeBilledAmount] ,CASE WIPTypeCode WHEN 0 THEN 0 ELSE WIP.AdjAmount + WIP.SurchargeAmount + ISNULL(t1.WriteUpDownAmount,0.00) END AS [ExpenseBilledAmount] /* 08-02-2023 - for some odd reason, WIP.BilledAmount doesn't always reflect the correct amount */ /* ,WIP.BilledAmount no longer using this, since it is incorrect in some cases */ /* 01-12-2024 - updated to add SurchargeAmount to the billed amounts */ ,WIP.AdjAmount + WIP.SurchargeAmount + ISNULL(t1.WriteUpDownAmount,0.00) AS BilledAmount /* cost amounts */ ,CASE WIPTypeCode WHEN 0 THEN Cost ELSE 0 END AS [TimeCost] ,CASE WIPTypeCode WHEN 0 THEN 0 ELSE Cost END AS [ExpenseCost] ,WIP.Cost /* some reports require this info */ ,INVOICE.InvoiceNumber ,INVOICE.InvoiceDateTime ,INVOICE.StatusCode AS InvoiceStatusCode FROM WIP LEFT OUTER JOIN ServiceCode ON ServiceCode.ServiceCodeIdent = WIP.ServiceCodeIdent LEFT OUTER JOIN ClientPractice ON ClientPractice.ClientIdent = WIP.ClientIdent LEFT OUTER JOIN INVOICE ON INVOICE.InvoiceIdent = WIP.InvoiceIdent /* 08-02-2023 added this join in order to change the BilledAmount calculation */ OUTER APPLY ( SELECT SUM(WriteUpDownAmount) AS WriteUpDownAmount FROM WIPWRITEUPDOWNV2 WHERE WIPWRITEUPDOWNV2.WipIdent=WIP.WipIdent ) t1 WHERE WIP.BillingStatusCode = 2 /* 2=billed */ AND WIP.TEStatusCode = 3 /* 3=posted */ AND WIP.WIPTypeCode IN (0,1,2) /* 0=time 1=expense 2=reimb exp */ /* per bug 186182, WIP should be considered "billed" even if it is on an unposted invoice (i.e. it is no longer in WIP) this will cause a potential discrepancy with built-in reports see notes in UVW_WIPSummaryClientident which essentially say the same thing */ /* per bug 272487, WIP is not considered "invoiced" when it is not posted this totally contradicts the above item the bottom line is....these items are treated differently on different reports so the only way to effectively deal with this glaring discrepancy is to return the invoice status and filter each report based on the unique rules for that report */ AND invoice.StatusCode IN (0,1) /* 0=unposted 1=posted this change made per bug 186182 explained above */ AND (ServiceCode.BillableTypeFlag=1 OR (ServiceCode.BillableTypeFlag=3 AND ClientPractice.IsBillableFlag='T')) GO /****** Object: View [dbo].[UVW_WIPAR03Clientident] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER VIEW [dbo].[UVW_WIPAR03Clientident] AS /* progress billed */ SELECT WIP.ClientIdent ,WIP.ProjectIdent ,WIP.ProgressInvIntIdent ,ISNULL(WIP.ServiceCodeIdent,0) AS ServiceCodeIdent ,(AdjAmount + SurchargeAmount + ProjsurchargeAmount) AS ProgressBilledAmount ,WIP.TransactionDate ,INVOICE.InvoiceDateTime ,INVOICE.InvoiceNumber ,INVOICE.StatusCode AS InvoiceStatusCode from WIP INNER JOIN INVOICE ON WIP.ProgressInvIntIdent = INVOICE.InvoiceIdent WHERE BillingStatusCode NOT IN (1,3) /* 1=history 3=void */ AND WIPTypeCode=3 /* 3=progress */ GO /****** Object: View [dbo].[UVW_WIPAR04Clientident] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER VIEW [dbo].[UVW_WIPAR04Clientident] AS /* progress applied by client */ SELECT WIP.ClientIdent ,WIP.ProjectIdent ,WIP.InvoiceIdent ,ISNULL(WIP.ServiceCodeIdent,0) AS ServiceCodeIdent ,(AdjAmount + SurchargeAmount + ProjsurchargeAmount) AS ProgressApplyAmount ,WIP.TransactionDate ,INVOICE.InvoiceDateTime ,INVOICE.InvoiceNumber ,INVOICE.StatusCode AS InvoiceStatusCode FROM WIP INNER JOIN INVOICE ON WIP.InvoiceIdent = INVOICE.InvoiceIdent WHERE BillingStatusCode NOT IN (1,3) /* 1=history 3=void */ AND WIPTypeCode=3 /* 3=progress */ GO /****** Object: View [dbo].[UVW_BillingRegister] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER VIEW [dbo].[UVW_BillingRegister] AS /* this query represents all WIP-related records that are billed but where the invoice is not yet posted this total should be the same as the Billing Register but would NOT include Sales Tax (not represented in WIP) */ /* wip billed */ SELECT ClientIdent, ServiceCodeIdent, InvoiceIdent, StaffIdent, ProjectIdent, TransactionDate, StdAmount, AdjAmount, BilledAmount, 0 AS ProgressBilledAmount, 0 AS ProgressApplyAmount, BilledAmount-AdjAmount AS WriteUpDownAmount FROM UVW_WIPAR02Clientident WHERE InvoiceStatusCode=0 /* progress billed */ UNION ALL SELECT ClientIdent, ServiceCodeIdent, ProgressInvIntIdent AS InvoiceIdent, 0 AS StaffIdent, 0 AS ProjectIdent, TransactionDate, 0 AS StdAmount, 0 AS AdjAmount, 0 AS BilledAmount, ProgressBilledAmount, 0 AS ProgressApplyAmount, 0 AS WriteUpDownAmount FROM UVW_WIPAR03Clientident WHERE InvoiceStatusCode=0 /* progress apply */ UNION ALL SELECT ClientIdent, ServiceCodeIdent, InvoiceIdent, 0 AS StaffIdent, 0 AS ProjectIdent, TransactionDate, 0 AS StdAmount, 0 AS AdjAmount, 0 AS BilledAmount, 0 AS ProgressBilledAmount, ProgressApplyAmount, 0 AS WriteUpDownAmount FROM UVW_WIPAR04Clientident WHERE InvoiceStatusCode=0 GO /****** Object: View [dbo].[UVW_ClientBilled] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /* note.....this is not used directly in the reporting utility but it is used multiple PowerBI dashboards, and this is just used as a place to store/load the require View */ CREATE OR ALTER VIEW [dbo].[UVW_ClientBilled] AS (SELECT UVW_WIPAR02Clientident.ClientIdent ,ServiceCodeID ,ServiceCodeName ,InvoiceDateTime ,BilledAmount AS Amount FROM UVW_WIPAR02Clientident LEFT JOIN CLIENT ON CLIENT.ClientIdent = UVW_WIPAR02Clientident.ClientIdent LEFT JOIN SERVICECODE ON SERVICECODE.ServiceCodeIdent = UVW_WIPAR02Clientident.ServiceCodeIdent WHERE CLIENT.DeleteFlag='F' AND InvoiceStatusCode=1) UNION ALL (SELECT UVW_WIPAR03Clientident.ClientIdent ,'PROGBILL' AS ServiceCodeID ,'Progress Billed' AS ServiceCodeName ,InvoiceDateTime ,ProgressBilledAmount AS Amount FROM UVW_WIPAR03Clientident LEFT JOIN CLIENT ON CLIENT.ClientIdent=UVW_WIPAR03Clientident.ClientIdent WHERE CLIENT.DeleteFlag='F' AND InvoiceStatusCode=1) UNION ALL (SELECT UVW_WIPAR04Clientident.ClientIdent ,'PROGAPPL' AS ServiceCodeID ,'Progress Apply' AS ServiceCodeName ,InvoiceDateTime ,-ProgressApplyAmount AS Amount FROM UVW_WIPAR04Clientident LEFT JOIN CLIENT ON CLIENT.ClientIdent=UVW_WIPAR04Clientident.ClientIdent WHERE CLIENT.DeleteFlag='F' AND InvoiceStatusCode=1) GO /****** Object: View [dbo].[UVW_WIPAR05Clientident] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER VIEW [dbo].[UVW_WIPAR05Clientident] AS /* WIP WriteUpDown by client */ /* 10-13-2022 this is a new/corrected version that i created to correct a DAU issue with the WIPWRITEUPDOWN table update process from all indications, this does correct the issue with above */ SELECT WIP.Wipident ,WIP.ClientIdent ,WIP.ProjectIdent ,WIP.InvoiceIdent ,WIP.StaffIdent ,WIP.ServiceCodeIdent /* these 2 fields are just to separate the time write-up/dn from expense write up/dn */ ,CASE WIPTypeCode WHEN 0 THEN ISNULL(wwud.WriteUpDownAmount,0.00) ELSE 0 END AS TimeWriteUpDownAmount ,CASE WIPTypeCode WHEN 0 THEN 0 ELSE ISNULL(wwud.WriteUpDownAmount,0.00) END AS ExpenseWriteUpDownAmount /* this is the main write up/dn calculation */ ,ISNULL(wwud.WriteUpDownAmount,0.00) as WriteUpDownAmount /* alternate calculation */ /* just for testing */ /* ,WIP.BilledAmount - WIP.AdjAmount AS WriteUpDownAmount */ /* these 2 fields are just to separate the write-ups from the write-downs */ ,CASE WHEN ISNULL(wwud.WriteUpDownAmount,0.00) > 0 THEN ISNULL(wwud.WriteUpDownAmount,0.00) ELSE 0 END AS WriteUpAmount ,CASE WHEN ISNULL(wwud.WriteUpDownAmount,0.00) < 0 THEN ISNULL(wwud.WriteUpDownAmount,0.00) ELSE 0 END AS WriteDownAmount /* 03-07-2025 new field added 0 = allocated to staff 1 = not sure what this means 2 = allocated to firm */ ,wuwd.WriteUpCd ,WIP.TransactionDate ,INVOICE.InvoiceNumber ,INVOICE.InvoiceDateTime ,INVOICE.StatusCode AS InvoiceStatusCode FROM WIPWRITEUPDOWNV2 wwud INNER JOIN WIP on wwud.WipIdent=WIP.WIPIdent LEFT JOIN ServiceCode ON ServiceCode.ServiceCodeIdent = WIP.ServiceCodeIdent LEFT JOIN ClientPractice ON ClientPractice.ClientIdent = WIP.ClientIdent LEFT JOIN Invoice ON Invoice.InvoiceIdent = WIP.InvoiceIdent WHERE WIP.BillingStatusCode = 2 /* 2=billed */ AND WIP.TEStatusCode = 3 /* 3=posted */ AND WIP.WIPTypeCode IN (0,1,2) /* BD 8-22-2019 as far as i know, writeupdown can only occur on time or expense, never on progress */ AND (ServiceCode.BillableTypeFlag=1 OR (ServiceCode.BillableTypeFlag=3 AND ClientPractice.IsBillableFlag='T')) AND INVOICE.StatusCode IN (0,1) /* 0=unposted 1=posted */ GO /****** Object: View [dbo].[UVW_RealizationComponents] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER view [dbo].[UVW_RealizationComponents] AS /* this view provides a bare-minimum query necessary to get realization details. Primarily, this is intended for analysis in PowerBI, so it is suitable for filtering, pivoting, etc the query returned has each component coded by the record type 1 = billed amount (this is the "net" billed amount with write up/down included) 2 = progress billed 3 = progress applied 4 = write up/down amount */ select * from (select 1 as ttype,invoicedatetime,billedamount as amount from UVW_WIPAR02Clientident union all select 2 as ttype,invoicedatetime,progressbilledamount as amount from UVW_WIPAR03Clientident union all select 3 as ttype,invoicedatetime,progressapplyamount as amount from UVW_WIPAR04Clientident union all select 4 as ttype,invoicedatetime,writeupdownamount as amount from UVW_WIPAR05Clientident) t1 GO /****** Object: View [dbo].[UVW_WIPAR01Clientident] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER VIEW [dbo].[UVW_WIPAR01Clientident] AS SELECT /* this view provides the gross BILLABLE hours, time amount, and expenses amount equivalent to the first 3 columns on a WIPAR Reconciliation report */ ClientIdent, StaffIdent, ServiceCodeIdent, ProjectIdent, TransactionDate, CASE WHEN wiptypecode = 0 THEN [hours] ELSE 0.00 END AS [hours], CASE WHEN wiptypecode = 0 THEN adjamount + SurchargeAmount + ProjSurchargeAmount ELSE 0.00 END AS [time], CASE WHEN wiptypecode IN (1, 2) THEN adjamount + SurchargeAmount + ProjSurchargeAmount ELSE 0.00 END AS [expenses], /* 07/20/2023 added timecost and expensecost */ CASE WHEN WIPTypeCode = 0 THEN WIP.[Cost] ELSE 0.00 END AS TimeCost, CASE WHEN WIPTypeCode IN (1,2) THEN WIP.[Cost] ELSE 0.00 END AS ExpenseCost FROM WIP WHERE /* note that this includes BOTH unbilled AND final billed WIP since this is the "gross" amount before the billed WIP is subtracted. there are some other WIP summary queries that only include the unbilled WIP, but that represents the "net" WIP after billing */ WIPTypeCode IN (0,1,2) /* 0=time 1=expenses 2=reimbursable expenses */ AND BillingStatusCode IN (0, 2) /* 0=unbilled 2=final billed */ AND TEStatusCode IN (/* 1, */ 3) /* 06-29-2023 removed TEStatusCode 1, it appears Axcess reports do not include this */ AND IsBillableFlag = 1 GO /****** Object: View [dbo].[UVW_WIPComponentDetail] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER VIEW [dbo].[UVW_WIPComponentDetail] AS /* wip hours, time, expenses */ SELECT 1 AS TransactionType ,Clientident ,TransactionDate ,isnull([time],0.00)+isnull([Expenses],0) as [Amount] FROM UVW_WIPAR01Clientident /* wip billed amount */ UNION ALL SELECT 2 AS TransactionType ,clientident ,InvoiceDateTime AS TransactionDate ,isnull(BilledAmount,0.00)*-1 AS [Amount] FROM UVW_WIPAR02Clientident WHERE InvoiceStatusCode = 1 /* wip progress billed */ UNION ALL SELECT 3 AS TransactionType ,ClientIdent ,InvoiceDateTime AS TransactionDate ,isnull(ProgressBilledAmount,0.00)*-1 AS Amount FROM UVW_WIPAR03Clientident WHERE InvoiceStatusCode = 1 /* progress billed is only included if the invoice is posted */ /* wip progress apply */ UNION ALL Select 4 AS TransactionType ,ClientIdent ,InvoiceDateTime AS TransactionDate ,isnull(ProgressApplyAmount,0.00) AS Amount FROM UVW_WIPAR04Clientident WHERE InvoiceStatusCode = 1 /* progress apply is only included if the invoice is posted */ /* wip write up-down */ UNION ALL SELECT 5 AS TransactionType ,ClientIdent ,InvoiceDateTime AS TransactionDate ,isnull(writeupdownAmount,0.00) AS Amount FROM UVW_WIPAR05Clientident WHERE InvoiceStatusCode=1 /* write up/down is only included if the invoice is posted */ GO /****** Object: View [dbo].[UVW_ARAgingDetail] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER VIEW [dbo].[UVW_ARAgingDetail] AS /* this query provides full A/R balance detail with Aging information */ /* this query is very similar to UVW_ARComponentDetail, and it might be possible to combine the info from those 2 views into one */ /* Invoice */ SELECT ClientIdent, 'A1' AS ttype, InvoiceNumber AS document, InvoiceNumber AS applyto, InvoiceDateTime AS BalanceDate, InvoiceDateTime AS AgingBucketDate, (StdWIPAmount + AdjustmentAmount + ProgressBilledAmount - ProgressApplyAmount) AS AgingAmount FROM INVOICE WHERE StatusCode=1 /* 1=posted */ /* Sales Tax */ UNION ALL SELECT ClientIdent, 'A2' AS ttype, InvoiceNumber AS document, InvoiceNumber AS applyto, InvoiceDateTime AS BalanceDate, InvoiceDateTime AS AgingBucketDate, TaxAmount + ProgressTaxAmount - TaxAppAmount - ProgressTaxAppAmount AS AgingAmount FROM INVOICE WHERE StatusCode=1 /* 1=posted */ AND (TaxAmount + ProgressTaxAmount - TaxAppAmount - ProgressTaxAppAmount) <> 0 /* Other Adjustment */ UNION ALL SELECT ClientIdent, CASE AREntryTypeCode WHEN 8 THEN 'AA' /* other adjustment */ WHEN 9 THEN 'AA' /* other adjustment */ WHEN 10 THEN 'A3' /* finance charges */ END AS ttype, ReferenceNumber AS document, ReferenceNumber AS applyto, TransactionDateTime AS BalanceDate, TransactionDateTime AS AgingBucketDate, ARChargesAmount /* - CashAppliedAmount - CreditsAppliedAmount + DebitsAppliedAmount */ AS AgingAmount FROM ARCHARGES WHERE AREntryTypeCode IN (8,9,10) and CorrectionStatusCode=1 /* Payments (Distributed) */ UNION ALL SELECT ARTRANSACTION.ClientIdent, 'A4' AS ttype, ARTRANSACTION.ReferenceNumber AS document, (SELECT InvoiceNumber FROM INVOICE WHERE InvoiceIdent=ARDISTRIBUTION.InvoiceIdent) AS applyto, ARTRANSACTION.TransactionDateTime AS BalanceDate, /* 06-22-2020 bug fix - the aging of distributed transactions should reflect the original transaction date to which the item is applied, rather than the actual payment date note....there's a setting in CCH Axcess called "Count days old of distributed AR using... that allows the user to select either a) Transaction Date or b) Invoice Date Where Distributed apparently, the Invoice Date Where Distributed is the most popular option so I'm using that here. this was previously set to Transaction Date */ /* 10-09-2020 based on further digging, i've concluded that each distribution transaction has either an INVOICE.InvoiceIdent or ARCHARGES.ARChargesIdent field value. this implies that all distributions point to one or the other. however, i'm also finding that there are transactions that have an ARCHARGES.ARChargesIdent value, but the underlying ARCHARGES transaction does not exist, which then causes a null aging date to be returned. The only way around this is to get the ARTRANSACTION date as a last resort if the other dates cannot be found. this is awfully messy, but it's the only way to guarantee that an aging date is returned for every distribution */ COALESCE( (SELECT InvoiceDateTime FROM INVOICE WHERE InvoiceIdent=ARDISTRIBUTION.InvoiceIdent), (SELECT TransactionDateTime FROM ARCHARGES WHERE ARChargesIdent=ARDISTRIBUTION.ARChargesIdent), ARTRANSACTION.TransactionDateTime) AS AgingBucketDate, ISNULL(-ARDISTRIBUTION.DistributionAmount,0.00) AS AgingAmount FROM ARTRANSACTION INNER JOIN ARDISTRIBUTION on ARDISTRIBUTION.ARIdent=ARTRANSACTION.ARIdent WHERE ARTRANSACTION.AREntryTypeIntCode=1 /* 1=payment */ AND ARTRANSACTION.CorrectionStatusCode=1 /* 1=new entry */ AND ARTRANSACTION.Posted=1 /* 1=posted */ /* Payments (UnDistributed) */ UNION ALL SELECT ARTRANSACTION.ClientIdent, 'A5' AS ttype, ReferenceNumber AS document, '' AS applyto, TransactionDateTime AS BalanceDate, TransactionDateTime AS AgingBucketDate, -amount + ISNULL((select sum(DistributionAmount) FROM ARDISTRIBUTION where arident=ARTRANSACTION.arident),0) AS AgingAmount FROM ARTRANSACTION WHERE ARTRANSACTION.AREntryTypeIntCode = 1 /* 1=payment */ AND ARTRANSACTION.CorrectionStatusCode = 1 /* 1=new entry */ AND amount - ISNULL((select sum(DistributionAmount) FROM ARDISTRIBUTION where arident=ARTRANSACTION.arident),0)<>0 AND ARTRANSACTION.Posted=1 /* Adjustments 2/3 Distributed */ UNION ALL SELECT ARTRANSACTION.ClientIdent, 'A6' AS ttype, ARTRANSACTION.ReferenceNumber AS document, COALESCE(ARCHARGES.ReferenceNumber,INVOICE.InvoiceNumber) AS applyto, ARTRANSACTION.TransactionDateTime AS BalanceDate, COALESCE(INVOICE.InvoiceDateTime,ARCHARGES.TransactionDateTime,ARTRANSACTION.TransactionDateTime) AS AgingBucketDate, ISNULL(-DistributionAmount,0) as AgingAmount FROM ARTRANSACTION INNER JOIN ARDISTRIBUTION on ARTRANSACTION.ARIdent=ARDISTRIBUTION.ARIdent LEFT JOIN INVOICE ON Invoice.InvoiceIdent=ARDISTRIBUTION.InvoiceIdent LEFT JOIN ARCharges on ARCHARGES.ARChargesIdent=ARDISTRIBUTION.ARChargesIdent WHERE ARTransaction.CorrectionStatusCode=1 /* 1=new entry */ and ARTransaction.AREntryTypeIntCode IN (2,3) /* 2=credit memo 3=credit adjustment */ AND ARTRANSACTION.Posted=1 /* Adjustments 2/3 Undistributed */ UNION ALL SELECT ClientIdent, 'A8' AS ttype, ReferenceNumber AS document, '' AS applyto, TransactionDateTime AS BalanceDate, TransactionDateTime AS AgingBucketDate, -(amount - ISNULL((select sum(DistributionAmount) FROM ARDISTRIBUTION where arident=ARTRANSACTION.arident),0)) AS AgingAmount FROM ARTRANSACTION WHERE AREntryTypeIntCode in (2,3) AND CorrectionStatusCode = 1 AND (ARTRANSACTION.amount - ISNULL((select sum(DistributionAmount) FROM ARDISTRIBUTION where arident=ARTRANSACTION.arident),0))<>0 AND ARTRANSACTION.Posted=1 /* Adjustments 6/7 Distributed */ UNION ALL SELECT ARTRANSACTION.ClientIdent, 'A7' AS ttype, ARTRANSACTION.ReferenceNumber AS document, ARCHARGES.ReferenceNumber AS applyto, ARTRANSACTION.TransactionDateTime AS BalanceDate, COALESCE(INVOICE.InvoiceDateTime,ARCHARGES.TransactionDateTime,ARTRANSACTION.TransactionDateTime) AS AgingBucketDate, ISNULL(DistributionAmount,0) as AgingAmount FROM ARTRANSACTION INNER JOIN ARDISTRIBUTION on ARTRANSACTION.ARIdent=ARDISTRIBUTION.ARIdent LEFT JOIN INVOICE on invoice.InvoiceIdent=ARDISTRIBUTION.InvoiceIdent LEFT JOIN ARCharges on ARCHARGES.ARChargesIdent=ARDISTRIBUTION.ARChargesIdent WHERE ARTransaction.CorrectionStatusCode=1 /* 1=new entry */ and AREntryTypeIntCode IN (6,7) /* 6=debit memo 7=debit adjustment */ AND ARTRANSACTION.Posted=1 /* Adjustments 6/7 Undistributed */ UNION ALL SELECT ClientIdent, 'A9' AS ttype, ReferenceNumber AS document, '' AS applyto, TransactionDateTime AS BalanceDate, TransactionDateTime AS AgingBucketDate, amount - ISNULL((select sum(DistributionAmount) FROM ARDISTRIBUTION where arident=ARTRANSACTION.arident),0) AS AgingAmount FROM ARTRANSACTION WHERE AREntryTypeIntCode in (6,7) AND CorrectionStatusCode = 1 AND ARTRANSACTION.amount - ISNULL((select sum(DistributionAmount) FROM ARDISTRIBUTION where arident=ARTRANSACTION.arident),0)<>0 AND ARTRANSACTION.Posted=1 /* Write-Off Distributed */ UNION ALL SELECT ARTransaction.ClientIdent, 'AB' AS ttype, ARTRANSACTION.ReferenceNumber AS document, ARCHARGES.ReferenceNumber AS applyto, ARTRANSACTION.TransactionDateTime AS BalanceDate, COALESCE(INVOICE.InvoiceDateTime,ARCHARGES.TransactionDateTime,ARTRANSACTION.TransactionDateTime) AS AgingBucketDate, ISNULL(-ARDISTRIBUTION.DistributionAmount,0.00) AS AgingAmount FROM ARTRANSACTION INNER JOIN ARDISTRIBUTION ON ARDISTRIBUTION.ARIdent=ARTRANSACTION.ARIdent LEFT JOIN INVOICE on invoice.InvoiceIdent=ARDISTRIBUTION.InvoiceIdent LEFT JOIN ARCharges on ARCHARGES.ARChargesIdent=ARDISTRIBUTION.ARChargesIdent WHERE ARTRANSACTION.AREntryTypeIntCode IN (4,5) /* 4=GST Write-off 5=Write-off */ and ARTRANSACTION.CorrectionStatusCode=1 /* 1=New Entry */ AND ARTRANSACTION.Posted=1 /* Write-Off Undistributed */ UNION ALL SELECT ClientIdent, 'AC' AS ttype, ReferenceNumber AS document, '' AS applyto, TransactionDateTime AS BalanceDate, TransactionDateTime AS AgingBucketDate, -amount + ISNULL((select sum(DistributionAmount) FROM ARDISTRIBUTION where arident=ARTRANSACTION.arident),0) AS AgingAmount FROM ARTRANSACTION WHERE ARTRANSACTION.AREntryTypeIntCode IN (4,5) /* 4=GST Write-off 5=Write-off */ AND ARTRANSACTION.CorrectionStatusCode = 1 /* 1=New Entry */ AND amount - ISNULL((select sum(DistributionAmount) FROM ARDISTRIBUTION where arident=ARTRANSACTION.arident),0)<>0 AND ARTRANSACTION.Posted=1 GO /****** Object: View [dbo].[UVW_ARAgingDetailProject] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER VIEW [dbo].[UVW_ARAgingDetailProject] AS /* this query provides the same totals as UVW_ARAgingDetail however, this add the project indentifier info for amounts that can be tied directly to WIP. note....there are many A/R components that cannot be tied to WIP, so the project identifier for those parts is simply set to 0 */ /* Invoice amounts that can be tied directly to WIP */ SELECT INVOICE.ClientIdent, ISNULL(WIP.ProjectIdent,0) AS ProjectIdent, 'A1' AS ttype, INVOICE.InvoiceNumber AS document, INVOICE.InvoiceNumber AS applyto, INVOICE.InvoiceDateTime AS BalanceDate, INVOICE.InvoiceDateTime AS AgingBucketDate, ISNULL(WIP.BilledAmount + WIP.SurchargeAmount + WIP.ProjsurchargeAmount,0.00) AS AgingAmount FROM INVOICE LEFT JOIN WIP ON INVOICE.InvoiceIdent=WIP.InvoiceIdent and WIPTypeCode<>3 /* do not look at progress WIP */ WHERE INVOICE.StatusCode=1 /* 1=posted */ /* there are invoice amounts that cannot be tied directly to WIP so we need to get those amounts here */ UNION ALL SELECT INVOICE.ClientIdent, 0 AS ProjectIdent, 'AD' AS ttype, InvoiceNumber AS document, InvoiceNumber AS applyto, InvoiceDateTime AS BalanceDate, InvoiceDateTime AS AgingBucketDate, (StdWIPAmount + AdjustmentAmount + ProgressBilledAmount - ProgressApplyAmount) - (select ISNULL(sum(WIP.BilledAmount + WIP.SurchargeAmount + WIP.ProjsurchargeAmount),0.00) from wip where invoiceident = INVOICE.invoiceident and WIPTypeCode<>3) AS AgingAmount FROM INVOICE WHERE INVOICE.StatusCode = 1 /* Sales Tax */ UNION ALL SELECT INVOICE.ClientIdent, 0 AS ProjectIdent, 'A2' AS ttype, InvoiceNumber AS document, InvoiceNumber AS applyto, InvoiceDateTime AS BalanceDate, InvoiceDateTime AS AgingBucketDate, TaxAmount + ProgressTaxAmount - TaxAppAmount - ProgressTaxAppAmount AS AgingAmount FROM INVOICE WHERE INVOICE.StatusCode=1 /* 1=posted */ /* Other Adjustment */ UNION ALL SELECT ClientIdent, 0 AS ProjectIdent, CASE AREntryTypeCode WHEN 8 THEN 'AA' /* other adjustment */ WHEN 9 THEN 'AA' /* other adjustment */ WHEN 10 THEN 'A3' /* finance charges */ END AS ttype, ReferenceNumber AS document, ReferenceNumber AS applyto, TransactionDateTime AS BalanceDate, TransactionDateTime AS AgingBucketDate, ARChargesAmount - CashAppliedAmount - CreditsAppliedAmount + DebitsAppliedAmount AS AgingAmount FROM ARCHARGES WHERE AREntryTypeCode IN (8,9,10) and CorrectionStatusCode=1 /* Payments (Distributed) */ UNION ALL SELECT ARTransaction.ClientIdent, 0 AS ProjectIdent, 'A4' AS ttype, ARTRANSACTION.ReferenceNumber AS document, INVOICE.InvoiceNumber AS applyto, ARTRANSACTION.TransactionDateTime AS BalanceDate, /* 06-22-2020 bug fix - the aging of distributed transactions should reflect the original invoice date to which they were applied, rather than the actual payment date note....there's a setting in CCH Axcess called "Count days old of distributed AR using... that allows the user to select either a) Transaction Date or b) Invoice Date Where Distributed apparently, the Invoice Date Where Distributed is the most popular option so I'm using that here. this was previously set to Transaction Date */ /* ARTRANSACTION.TransactionDateTime AS AgingBucketDate previous setting, now replaced by InvoiceDateTime */ INVOICE.InvoiceDateTime AS AgingBucketDate, ISNULL(-ARDISTRIBUTION.DistributionAmount,0.00) AS AgingAmount FROM ARTRANSACTION /* 06-25-2020 changed these joins from LEFT to INNER as it was bringing up transactions with no distribution and no invoice */ INNER JOIN ARDISTRIBUTION on ARDISTRIBUTION.ARIdent=ARTRANSACTION.ARIdent INNER JOIN INVOICE on INVOICE.InvoiceIdent=ARDISTRIBUTION.InvoiceIdent WHERE ARTRANSACTION.AREntryTypeIntCode=1 /* 1=payment */ AND ARTRANSACTION.CorrectionStatusCode=1 /* 1=new entry */ AND ARTRANSACTION.Posted=1 /* Payments (UnDistributed) */ UNION ALL SELECT ClientIdent, 0 AS ProjectIdent, 'A5' AS ttype, ReferenceNumber AS document, '' AS applyto, TransactionDateTime AS BalanceDate, TransactionDateTime AS AgingBucketDate, -amount + ISNULL((select sum(DistributionAmount) FROM ARDISTRIBUTION where arident=ARTRANSACTION.arident),0) AS AgingAmount FROM ARTRANSACTION WHERE ARTRANSACTION.AREntryTypeIntCode = 1 /* 1=payment */ AND ARTRANSACTION.CorrectionStatusCode = 1 /* 1=new entry */ AND amount - ISNULL((select sum(DistributionAmount) FROM ARDISTRIBUTION where arident=ARTRANSACTION.arident),0)<>0 AND ARTRANSACTION.Posted=1 /* Adjustments 2/3 Distributed */ UNION ALL SELECT ARTRANSACTION.ClientIdent, 0 AS ProjectIdent, 'A6' AS ttype, ARTRANSACTION.ReferenceNumber AS document, COALESCE(ARCHARGES.ReferenceNumber,INVOICE.InvoiceNumber) AS applyto, ARTRANSACTION.TransactionDateTime AS BalanceDate, /* 06-25-2020 similar to above, i am changing the bucketing to reflect the invoice date to which it was applied */ /* ARTRANSACTION.TransactionDateTime AS AgingBucketDate, */ INVOICE.InvoiceDateTime AS AgingBucketDate, ISNULL(-DistributionAmount,0) as AgingAmount FROM ARTRANSACTION /* 06-25-2020 similar to above, i am changing these joins from LEFT to INNER */ INNER JOIN ARDISTRIBUTION on ARTRANSACTION.ARIdent=ARDISTRIBUTION.ARIdent INNER JOIN INVOICE ON Invoice.InvoiceIdent=ARDISTRIBUTION.InvoiceIdent LEFT JOIN ARCharges on ARCHARGES.ARChargesIdent=ARDISTRIBUTION.ARChargesIdent WHERE ARTransaction.CorrectionStatusCode=1 /* 1=new entry */ and ARTransaction.AREntryTypeIntCode IN (2,3) /* 2=credit memo 3=credit adjustment */ AND ARTRANSACTION.Posted=1 /* Adjustments 2/3 Undistributed */ UNION ALL SELECT ClientIdent, 0 AS ProjectIdent, 'A8' AS ttype, ReferenceNumber AS document, '' AS applyto, TransactionDateTime AS BalanceDate, TransactionDateTime AS AgingBucketDate, -(amount - ISNULL((select sum(DistributionAmount) FROM ARDISTRIBUTION where arident=ARTRANSACTION.arident),0)) AS AgingAmount FROM ARTRANSACTION WHERE AREntryTypeIntCode in (2,3) AND CorrectionStatusCode = 1 AND (ARTRANSACTION.amount - ISNULL((select sum(DistributionAmount) FROM ARDISTRIBUTION where arident=ARTRANSACTION.arident),0))<>0 AND ARTRANSACTION.Posted=1 /* Adjustments 6/7 Distributed */ UNION ALL SELECT ARTRANSACTION.ClientIdent, 0 AS ProjectIdent, 'A7' AS ttype, ARTRANSACTION.ReferenceNumber AS document, INVOICE.InvoiceNumber AS applyto, ARTRANSACTION.TransactionDateTime AS BalanceDate, /* 06-25-2020 similar to above, i am changing the bucketing to reflect the invoice date to which it was applied */ /* ARTRANSACTION.TransactionDateTime AS AgingBucketDate, */ INVOICE.InvoiceDateTime AS AgingBucketDate, ISNULL(DistributionAmount,0) as AgingAmount FROM ARTRANSACTION /* 06-25-2020 similar to above, i am changing these joins from LEFT to INNER */ INNER JOIN ARDISTRIBUTION on ARTRANSACTION.ARIdent=ARDISTRIBUTION.ARIdent INNER JOIN INVOICE on invoice.InvoiceIdent=ARDISTRIBUTION.InvoiceIdent LEFT JOIN ARCharges on ARCHARGES.ARChargesIdent=ARDISTRIBUTION.ARChargesIdent WHERE ARTransaction.CorrectionStatusCode=1 /* 1=new entry */ and AREntryTypeIntCode IN (6,7) /* 6=debit memo 7=debit adjustment */ AND ARTRANSACTION.Posted=1 /* Adjustments 6/7 Undistributed */ UNION ALL SELECT ClientIdent, 0 AS ProjectIdent, 'A9' AS ttype, ReferenceNumber AS document, '' AS applyto, TransactionDateTime AS BalanceDate, TransactionDateTime AS AgingBucketDate, amount - ISNULL((select sum(DistributionAmount) FROM ARDISTRIBUTION where arident=ARTRANSACTION.arident),0) AS AgingAmount FROM ARTRANSACTION WHERE AREntryTypeIntCode in (6,7) AND CorrectionStatusCode = 1 AND ARTRANSACTION.amount - ISNULL((select sum(DistributionAmount) FROM ARDISTRIBUTION where arident=ARTRANSACTION.arident),0)<>0 AND ARTRANSACTION.Posted=1 /* Write-Off Distributed */ UNION ALL SELECT ARTransaction.ClientIdent, 0 AS ProjectIdent, 'AB' AS ttype, ARTRANSACTION.ReferenceNumber AS document, INVOICE.InvoiceNumber AS applyto, ARTRANSACTION.TransactionDateTime AS BalanceDate, /* 06-25-2020 similar to above, i am changing the bucketing to reflect the invoice date to which it was applied ARTRANSACTION.TransactionDateTime AS AgingBucketDate, */ INVOICE.InvoiceDateTime AS AgingBucketDate, ISNULL(-ARDISTRIBUTION.DistributionAmount,0.00) AS AgingAmount FROM ARTRANSACTION /* 06-25-2020 similar to above, i am changing these joins from LEFT to INNER */ INNER JOIN ARDISTRIBUTION ON ARDISTRIBUTION.ARIdent=ARTRANSACTION.ARIdent INNER JOIN INVOICE on invoice.InvoiceIdent=ARDISTRIBUTION.InvoiceIdent LEFT JOIN ARCharges on ARCHARGES.ARChargesIdent=ARDISTRIBUTION.ARChargesIdent WHERE AREntryTypeIntCode IN (4,5) and ARTRANSACTION.CorrectionStatusCode=1 AND ARTRANSACTION.Posted=1 /* Write-Off Undistributed */ UNION ALL SELECT ClientIdent, 0 AS ProjectIdent, 'AC' AS ttype, ReferenceNumber AS document, '' AS applyto, TransactionDateTime AS BalanceDate, TransactionDateTime AS AgingBucketDate, -amount + ISNULL((select sum(DistributionAmount) FROM ARDISTRIBUTION where arident=ARTRANSACTION.arident),0) AS AgingAmount FROM ARTRANSACTION WHERE AREntryTypeIntCode IN (4,5) AND CorrectionStatusCode = 1 AND amount - ISNULL((select sum(DistributionAmount) FROM ARDISTRIBUTION where arident=ARTRANSACTION.arident),0)<>0 AND Posted=1 GO /****** Object: View [dbo].[UVW_ARRegister] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER VIEW [dbo].[UVW_ARRegister] AS /* this view creates a raw list of AR transactions suitable for additional processing/filtering the goal of this view is to simplify the retrieval of AR transactions since they can be stored in various tables, and depending on whether they are distributed/undistributed */ /* payments, debit memos, credit memos (Distributed) */ SELECT 1 AS TransactionType, ARTRANSACTION.ClientIdent, ARTRANSACTION.PostedByStaffIdent, ARTRANSACTION.AREntryTypeIntCode, ARTRANSACTION.ReferenceNumber, COALESCE(INVOICE.InvoiceNumber,ARCHARGES.ReferenceNumber,'Null') AS AppliedTo, INVOICE.InvoiceDateTime, ARTRANSACTION.TransactionDateTime, ARTRANSACTION.PostedDateTime, ARTRANSACTION.ReferenceDateTime, ARTRANSACTION.Posted, ARTRANSACTION.Description, /* amount column */ CASE /* transactions linked to finance charges go to the Charges column */ WHEN ARDISTRIBUTION.ARChargesIdent IS NOT NULL THEN 0 /* transactions linked to sales tax go to the sales tax column */ WHEN ARDISTRIBUTION.InvoiceSalesTaxIdent IS NOT NULL THEN 0 WHEN ARTransaction.AREntryTypeIntCode IN (1,2,3,4,5) /* 1=payments 2=cr memo 3=cr adj 4=Gwriteoff 5=writeoff */ THEN -DistributionAmount WHEN ARTransaction.AREntryTypeIntCode IN (6,7,8) /* 6=dr memo 7=dr Adj */ THEN DistributionAmount ELSE 0 END AS Amount, /* sales tax column */ CASE WHEN ARDISTRIBUTION.InvoiceSalesTaxIdent IS NOT NULL THEN ARDISTRIBUTION.DistributionAmount * (CASE WHEN ARTRANSACTION.AREntryTypeIntCode IN (1,2,4,5) THEN -1 ELSE 1 END) ELSE 0 END AS SalesTax, /* charges column */ CASE /* ONLY transactions linked to finance charges go in this column */ WHEN ARDISTRIBUTION.ARChargesIdent IS Null THEN 0 WHEN ARTransaction.AREntryTypeIntCode IN (1,2,3,4,5) /* 1=payments 2=cr memo 3=cr adj 4=Gwriteoff 5=writeoff */ THEN -ARDISTRIBUTION.DistributionAmount WHEN ARTransaction.AREntryTypeIntCode IN (6,7,8) /* 6=dr memo 7=dr adj linked to finance charge */ THEN ARDISTRIBUTION.DistributionAmount ELSE 0 END AS Charges FROM ARDISTRIBUTION LEFT JOIN ARTRANSACTION on ARTRANSACTION.ARIdent = ARDISTRIBUTION.ARIdent LEFT JOIN INVOICE ON INVOICE.Invoiceident = ARDISTRIBUTION.InvoiceIdent LEFT JOIN ARCHARGES ON ARCHARGES.ARChargesIdent = ARDISTRIBUTION.ARChargesIdent WHERE ARTransaction.CorrectionStatusCode=1 /* AND ARTRANSACTION.Posted = 1 oddly enough, the AR Register report includes unposted transactions!! */ /* payments (Undistributed) */ UNION ALL SELECT 2 AS TransactionType, ARTRANSACTION.ClientIdent, ARTRANSACTION.PostedByStaffIdent, ARTRANSACTION.AREntryTypeIntCode, ARTRANSACTION.ReferenceNumber, '0' AS AppliedTo, '01/01/1900' AS InvoiceDateTime, ARTRANSACTION.TransactionDateTime, ARTRANSACTION.PostedDateTime, ARTRANSACTION.ReferenceDateTime, ARTRANSACTION.Posted, ARTRANSACTION.Description, /* amount column */ /* note that undistributed amounts would never relate to finance charge, so they would always go in Amount */ CASE WHEN ARTransaction.AREntryTypeIntCode IN (1,2,3,4,5) /* 1=payments 2=cr memo 3=cr adj 4=G writeoff 5=writeoff */ THEN -ARTRANSACTION.amount + ISNULL((select sum(DistributionAmount) FROM ARDISTRIBUTION where arident=ARTRANSACTION.arident),0) WHEN ARTransaction.AREntryTypeIntCode IN (6,7) /* 6=dr memo 7=dr adj */ THEN ARTRANSACTION.amount - ISNULL((select sum(DistributionAmount) FROM ARDISTRIBUTION where arident=ARTRANSACTION.arident),0) ELSE 0 END AS Amount, /* sales tax column */ 0 AS SalesTax, /* charges column */ CASE /* oddly enough, ARTRANSACTION can have type 8 Misc Chg transactions as well as ARCharges table */ WHEN ARTransaction.AREntryTypeIntCode IN (8) THEN ARTRANSACTION.amount - ISNULL((select sum(DistributionAmount) FROM ARDISTRIBUTION where arident=ARTRANSACTION.arident),0) ELSE 0 END AS Charges FROM ARTRANSACTION WHERE /* note that this view returns both posted and unposted transactions some of the reports that rely on this view use posted only, while others use both posted and unposted, so we are including both in the view and passing back the Posted value so it can be filtered accordingly */ ARTRANSACTION.CorrectionStatusCode = 1 /* new entry */ AND ARTRANSACTION.amount - ISNULL((select sum(DistributionAmount) FROM ARDISTRIBUTION where arident=ARTRANSACTION.arident),0) <> 0 /* charges note that this includes all different types of "charges" also note that all of these items go into the Charges column of this report */ UNION ALL SELECT 3 AS TransactionType, ARCHARGES.ClientIdent, ARCHARGES.PostedByStaffIdent, ARCHARGES.AREntryTypeCode AS AREntryTypeIntCode, ARCHARGES.ReferenceNumber, '0' AS AppliedTo, '01/01/1900' AS InvoiceDateTime, ARCHARGES.TransactionDateTime, ARCHARGES.PostedDateTime, ARCHARGES.ReferenceDateTime, 1 AS Posted, ARCHARGES.Description, 0 AS Amount, 0 AS SalesTax, ARCHARGES.ARChargesAmount AS Charges FROM ARCHARGES GO /****** Object: View [dbo].[UVW_ClientEmail] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER VIEW [dbo].[UVW_ClientEmail] AS /* this view gets a complete list of all available email addresses email addresses are "attached" to either Client records or ClientContact records so these need to be separately accounted for and flagged accordingly */ SELECT ReferenceIdent AS ClientIdent, 0 AS ClientContactIdent, EmailIdentCategoryType, FirmEmailTypeName, EmailAddress, InvoiceFlag, StatementFlag FROM CLIENTEMAIL WHERE EmailIdentCategoryType = 'Client' UNION ALL SELECT CLIENTCONTACT.OriginatingClientIntIdent AS ClientIdent, CLIENTCONTACT.ClientContactIdent, EmailIdentCategoryType, FirmEmailTypeName, EmailAddress, InvoiceFlag, StatementFlag FROM CLIENTEMAIL LEFT JOIN CLIENTCONTACT ON CLIENTEMAIL.ReferenceIdent = CLIENTCONTACT.ClientContactIdent WHERE EmailIdentCategoryType = 'ClientContact' GO /****** Object: View [dbo].[UVW_Productivity] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER VIEW [dbo].[UVW_Productivity] AS /* this is a general "Productivity" query that includes both billable and nonbillable hours, returns client, service code, and project info */ SELECT WIP.ClientIdent ,WIP.StaffIdent ,WIP.ServiceCodeIdent ,WIP.ProjectIdent ,WIP.WorkstepIdent ,WIP.TransactionDate -- 03/22/2024 added field to support a report that needs this field ,WIP.TECustomValue -- 02/11/2024 added field to support a report that needs this field ,WIP.WIPTypeCode ,CASE WHEN WIPTypeCode = 0 THEN WIP.[Hours] ELSE 0.00 END AS AllHours ,CASE WHEN WIPTypeCode = 0 AND WIP.IsBillableFlag=1 THEN WIP.[Hours] ELSE 0.00 END AS BillableHours ,CASE WHEN WIPTypeCode = 0 AND WIP.IsBillableFlag=0 THEN WIP.[Hours] ELSE 0.00 END AS NonbillableHours /* 03/25/2024 apparently there can be an AdjAmount for non-billable lines, so it needs to be excluded. we only want this amount if it is billable also, i realized that we need to add SurchargeAmount and ProjSurchargeAmount in order to tie to WIP/AR Reconciliation report */ ,CASE WHEN WIPTypeCode = 0 AND WIP.IsBillableFlag=1 THEN AdjAmount + SurchargeAmount + ProjSurchargeAmount ELSE 0.00 END AS TimeAmount /* 03/25/2024 the above may also be true for expenses, but i'm not going to make a change until further testing */ ,CASE WHEN WIPTypeCode IN (1,2) THEN AdjAmount + SurchargeAmount + ProjSurchargeAmount ELSE 0.00 END AS ExpenseAmount ,CASE WHEN WIPTypeCode = 0 THEN WIP.[Cost] ELSE 0.00 END AS AllHoursCost ,CASE WHEN WIPTypeCode = 0 AND WIP.IsBillableFlag=1 THEN WIP.[Cost] ELSE 0.00 END AS BillableHoursCost ,CASE WHEN WIPTypeCode = 0 AND WIP.IsBillableFlag=0 THEN WIP.[Cost] ELSE 0.00 END AS NonbillableHoursCost ,CASE WHEN WIPTypeCode IN (1,2) THEN WIP.[Cost] ELSE 0.00 END AS ExpenseCost ,SurchargeAmount /* for most productivity reports, transactions are included regardless of staff status however, at least one report ("Staff Productivity") excludes all transactions for Terminated staff. So, in order to match that report, we need to have this field available for filtering */ ,StaffStatus FROM WIP LEFT JOIN STAFF ON WIP.StaffIdent=STAFF.StaffIdent WHERE WIP.TEStatusCode = 3 /* 3=posted */ AND BillingStatusCode IN (0,2) /* 0=unbilled 2=final billed */ AND WIPTypeCode IN (0,1,2) /* 0=time 1=expense 2=reimb exp */ GO /****** Object: View [dbo].[UVW_TimeCardExport] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER view [dbo].[UVW_TimeCardExport] AS /* note.....this query has been tested and verified against the built-in report "Daily Staff Posted Hours" */ /* 12-02-2021 changed this to get all time, posted or unposted (TEStatusCode) most time reports only show posted time, so anything that uses this view will need to filter TEStatusCode = 3 (posted) */ /* IMPORTANT NOTE this query gets all transaction types (time, expense, reimbursable expense) so if you are using this query in a report that should only get "time" transactions, you need to use a filterfor WIPTypeCode = 1 */ SELECT STAFF.StaffIdent, STAFF.StaffIdentifier, STAFF.EmployeeNumber, STAFF.StaffLastName, STAFF.StaffFirstName, STAFF.ReportName, STAFF.StaffPosition, STAFF.StaffUserID, STAFF.StaffDepartment, CLIENT.ClientIdSubId, CLIENT.ClientSortName, SERVICECODE.CategoryName, SERVICECODE.SubCategoryName, SERVICECODE.ServiceCodeID, SERVICECODE.ServiceCodeName, SERVICECODE.ServiceClass, /* CPE, Holiday, Marketing, Personal, Regular, Sick */ WIP.WIPTypeCode, WIP.TransactionDate, WIP.PostedDateTime, WIP.Hours, WIP.adjamount + WIP.SurchargeAmount + WIP.ProjSurchargeAmount AS Amount, WIP.IsBillableFlag, WIP.TEStatusCode, ISNULL(WIPNOTE.InvoiceDescription,'') AS InvoiceDescription FROM WIP LEFT JOIN CLIENT on wip.ClientIdent=client.ClientIdent LEFT JOIN SERVICECODE on wip.ServiceCodeIdent=SERVICECODE.ServiceCodeIdent LEFT JOIN STAFF on wip.StaffIdent=staff.StaffIdent LEFT JOIN WIPNOTE ON WIP.WIPIdent=WIPNOTE.WipIdent WHERE /* 11-10-2023 found that there is some time with code=1 (History) that is causing duplication. code 1 (History) should not be included */ /* WIP.BillingStatusCode<>3 exclude VOID status transactions */ WIP.BillingStatusCode IN (0,2) /* 0=Unbilled 2=Final Billed This excludes 1=History 3=Void 4-8 No longer used 9=Progress */ GO /****** Object: View [dbo].[UVW_WIPAgingDetail] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER VIEW [dbo].[UVW_WIPAgingDetail] AS /* IMPORTANT note about this VIEW each transaction has 2 applicable dates: 1) BalanceDate - this date determines if the WIP line balance is included in WIP for a given cutoff date 2) AgingDate - this date determines how the WIP balance is aged strangely, these are very different things if you are trying to get totals that match with reports, you need to query by BalanceDate */ /* wip time, expenses */ /* note that the criteria for this section should be the same as UVW_WIPAR01Clientident */ SELECT WIP.Clientident ,WIP.ProjectIdent ,'W1' AS ttype ,WIPTypeCode ,TransactionDate AS BalanceDate ,TransactionDate AS AgingDate ,TransactionDate ,Invoice.InvoiceDateTime ,Invoice.StatusCode ,adjamount+SurchargeAmount AS AgingAmount FROM wip Left Outer Join ServiceCode S ON S.ServiceCodeIdent = WIP.ServiceCodeIdent Left Outer Join Invoice ON Invoice.InvoiceIdent = WIP.InvoiceIdent WHERE wip.WIPTypeCode IN (0,1,2) /* 0=time 1=expense 2=reimbursable expense */ and wip.TEStatusCode=3 /* 3=posted */ and wip.isbillableflag=1 /* 1=billable */ and wip.billingstatuscode in (0,2) /* 0=unbilled 1=history 2=final billed 3=void */ /* wip billed amount */ /* note that the criteria for this section should be the same as UVW_WIPAR02Clientident */ UNION ALL SELECT WIP.clientident ,WIP.ProjectIdent ,'W2' AS ttype ,WIPTypeCode ,Invoice.InvoiceDateTime AS BalanceDate /* per bug 293707, the wip aging date for BILLED wip is based on the invoice date */ ,TransactionDate /* InvoiceDateTime */ AS AgingDate ,TransactionDate ,Invoice.InvoiceDateTime ,Invoice.StatusCode ,-BilledAmount AS AgingAmount FROM wip Left Outer Join ServiceCode ON ServiceCode.ServiceCodeIdent = WIP.ServiceCodeIdent Left Outer JOIN ClientPractice ON ClientPractice.ClientIdent = WIP.ClientIdent Left Outer Join Invoice ON Invoice.InvoiceIdent = WIP.InvoiceIdent WHERE /* per bug 272104, this report should only consider the wip billed if the invoice is posted */ Invoice.StatusCode = 1 /* 1=posted */ AND WIP.WIPTypeCode IN (0,1,2) /* 0=time 1=expense 2=reimbursable expense */ AND WIP.BillingStatusCode=2 /* 2=final billed */ AND WIP.TEStatusCode = 3 /* posted */ AND WIP.HistoryFlag = 0 AND WIP.InvoiceIdent IS NOT NULL AND (ServiceCode.BillableTypeFlag=1 OR (ServiceCode.BillableTypeFlag=3 AND ClientPractice.IsBillableFlag='T')) /* wip progress billed */ UNION ALL SELECT WIP.ClientIdent ,WIP.ProjectIdent ,'W3' AS ttype ,WIPTypeCode ,Invoice.InvoiceDateTime AS BalanceDate ,TransactionDate /* InvoiceDateTime */ AS AgingDate ,TransactionDate ,Invoice.InvoiceDateTime ,StatusCode ,-(AdjAmount+SurchargeAmount+ProjsurchargeAmount) AS AgingAmount from WIP INNER JOIN Invoice WITH (NOLOCK) ON WIP.ProgressInvIntIdent = Invoice.InvoiceIdent WHERE /* per bug 272104, this report should only consider the wip billed if the invoice is posted */ Invoice.StatusCode = 1 /* 1=posted */ AND WIP.BillingStatusCode NOT IN (1,3) /* 1=history 3=void */ AND WIP.TEStatusCode = 3 /* 3=posted */ AND WIP.WIPTypeCode=3 /* 3=progress */ /* wip progress apply */ UNION ALL Select WIP.ClientIdent ,WIP.ProjectIdent ,'W4' AS ttype ,WIPTypeCode ,InvoiceDateTime AS BalanceDate ,TransactionDate /* InvoiceDateTime */ AS AgingDate ,TransactionDate ,InvoiceDateTime ,Invoice.StatusCode ,(AdjAmount + SurchargeAmount + ProjsurchargeAmount) AS AgingAmount from WIP INNER JOIN Invoice WITH (NOLOCK) ON WIP.InvoiceIdent = Invoice.InvoiceIdent WHERE /* per bug 272104, this report should only consider the wip billed if the invoice is posted */ Invoice.StatusCode = 1 /* 1=posted */ AND BillingStatusCode NOT IN (1,3) /* 1=history 3=void */ AND WIPTypeCode=3 /* 3=progress */ /* wip write up-down */ UNION ALL SELECT WIP.ClientIdent ,WIP.ProjectIdent ,'W5' AS ttype ,WIPTypeCode ,Invoice.InvoiceDateTime AS BalanceDate ,TransactionDate /* InvoiceDateTime */ AS AgingDate ,TransactionDate ,Invoice.InvoiceDateTime ,Invoice.StatusCode ,ISNULL(wip.BilledAmount,0.00) - ISNULL(wip.AdjAmount,0.00) - ISNULL(wip.SurchargeAmount,0.00) AS AgingAmount FROM WIP LEFT JOIN ServiceCode ON ServiceCode.ServiceCodeIdent = WIP.ServiceCodeIdent LEFT JOIN ClientPractice ON ClientPractice.ClientIdent = WIP.ClientIdent LEFT JOIN Invoice ON Invoice.InvoiceIdent = WIP.InvoiceIdent WHERE WIP.BillingStatusCode = 2 /* 2=billed */ AND WIP.TEStatusCode = 3 /* 3=posted */ AND WIP.WIPTypeCode IN (0,1,2) /* BD 8-22-2019 as far as i know, writeupdown can only occur on time or expense, never on progress */ AND (ServiceCode.BillableTypeFlag=1 OR (ServiceCode.BillableTypeFlag=3 AND ClientPractice.IsBillableFlag='T')) AND Invoice.StatusCode=1 /* 1=posted */ GO /****** Object: View [dbo].[UVW_WIPAR06Clientident] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER VIEW [dbo].[UVW_WIPAR06Clientident] AS /* AR Invoice, sales tax with progress payments */ SELECT ClientIdent ,InvoiceNumber ,InvoiceDateTime ,StdWIPAmount + AdjustmentAmount + ProgressBilledAmount - ProgressApplyAmount AS InvoiceAmount ,TaxAmount + ProgressTaxAmount - TaxAppAmount - ProgressTaxAppAmount AS SalesTaxAmount ,StdWIPAmount ,AdjustmentAmount ,ProgressBilledAmount ,ProgressApplyAmount FROM INVOICE WHERE StatusCode=1 /* posted */ GO /****** Object: View [dbo].[UVW_WIPAR07Clientident] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER VIEW [dbo].[UVW_WIPAR07Clientident] AS /* AR debits, credits, adjustments */ SELECT t1.ClientIdent ,t1.TransactionDateTime ,t1.CreditAmount AS CreditAmount ,t1.Adjustment1Amount AS Adjustment1Amount ,t1.Amount4 AS Amount4 /* GST write-off */ ,t1.Amount5 AS Amount5 /* write-off */ ,t1.DebitAmount AS DebitAmount ,t1.Adjustment2Amount AS Adjustment2Amount FROM (SELECT ARTransaction.ClientIdent ,ARTransaction.TransactionDateTime /* AREntryTypeIntCode 1 = Payment 2 = Credit Memo 3 = Credit Adjustment 4 = GST Write-off 5 = Write-off 6 = Debit Memo 7 = Debit Adjustment */ /* the AR Reconciliation report uses different columns for these items */ ,CASE WHEN AREntryTypeIntCode=2 THEN amount*(-1) ELSE 0 END AS CreditAmount /* 2 = credit memo */ ,CASE WHEN AREntryTypeIntCode=3 THEN amount*(-1) ELSE 0 END AS Adjustment1Amount /* 3 = negative adjustment */ ,CASE WHEN AREntryTypeIntCode=4 THEN amount*(-1) ELSE 0 END AS Amount4 /* 4 = GST write-off */ ,CASE WHEN AREntryTypeIntCode=5 THEN amount*(-1) ELSE 0 END AS Amount5 /* 5 = write-off */ ,CASE WHEN AREntryTypeIntCode=6 THEN amount ELSE 0 END AS DebitAmount /* 6 = debit memo */ ,CASE WHEN AREntryTypeIntCode=7 THEN amount ELSE 0 END AS Adjustment2Amount /* 7 = positive adjustment */ /* the WIPAR Reconciliation report treats this as a single adjustment column */ /* ,sum(CASE /* AREntryTypeIntCode 2=Credit Memo 3=Credit Adjustment */ WHEN AREntryTypeIntCode IN (2,3) THEN amount*(-1) /* AREntryTypeIntCode 6=Debit Memo 7=Debit Adjustment */ WHEN AREntryTypeIntCode IN (6,7) THEN amount ELSE 0 END ) as [AdjustmentAmount] */ FROM ARTransaction WHERE /* this had previously been only CorrectionStatusCode=1 */ /* AND CorrectionStatusCode IN (1,2) */ CorrectionStatusCode=1 AND Posted=1 /* apparently there is additional data that needs to come from ARCHARGES in some cases */ /* this doesn't make any sense at all, as all fields just return a 0, but I'm leaving it here as documentation/reminder for the future in case it is needed */ /* 06-21-2024 i'm commenting this out, as it hasn't been needed for several years, and it produces a bunch of 0-amount records UNION ALL SELECT ARCHARGES.ClientIdent ,ARCHARGES.TransactionDateTime ,0 AS CreditAmount ,0 AS Adjustment1Amount ,0 AS Amount4 ,0 AS Amount5 ,0 AS DebitAmount ,0 AS Adjustment2Amount /* ,SUM(ARChargesAmount) AS [AdjustmentAmount] */ FROM ARCHARGES WHERE AREntryTypeCode IN (8,9) /* 8=miscellaneous charge 9=handling fee */ */ ) AS t1 GO /****** Object: View [dbo].[UVW_WIPAR08Clientident] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER VIEW [dbo].[UVW_WIPAR08Clientident] AS /* AR Charges (includes miscellaneous, handling fee, finance charge */ SELECT ARCharges.ClientIdent ,TransactionDateTime ,ARChargesAmount as [Charges] from ARCharges where /* this was previously just code 10=finance charges, but i have found some reports with code 8 and 9 needing to be picked up */ /* depending on the report, we may need to split out the 8,9,10 at some point to allow separate reporting */ /* 8 = miscellaneous charge */ /* 9 = handling fee */ /* 10 = finance charge */ AREntryTypeCode IN (8,9,10) and CorrectionStatusCode=1 GO /****** Object: View [dbo].[UVW_WIPAR09Clientident] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER VIEW [dbo].[UVW_WIPAR09Clientident] AS /* AR payments */ SELECT t1.ClientIdent, t1.TransactionDateTime, t1.ReferenceNumber, t1.PaymentAmount, t1.[Distributed], t1.ARChargesIdent, t1.InvoiceSalesTaxIdent, t1.InvoiceNumber, t1.InvoiceSalesTaxNumber FROM ( /* payments (Distributed) */ select ARTransaction.ClientIdent, ARTRANSACTION.TransactionDateTime, ARTRANSACTION.ReferenceNumber, ARDISTRIBUTION.DistributionAmount AS PaymentAmount, 1 AS [Distributed], ARDISTRIBUTION.ARChargesIdent, /* if this is not null, then the payment is applied to some type of miscellaneous charge */ ARDISTRIBUTION.InvoiceSalesTaxIdent, /* if this is not null, then the payment is applied to sales tax */ INVOICE.InvoiceNumber, INVSALESTAX.InvoiceNumber AS InvoiceSalesTaxNumber FROM ARTransaction left join ARDISTRIBUTION on ARDISTRIBUTION.ARIdent=ARTRANSACTION.ARIdent left join INVOICE ON INVOICE.InvoiceIdent = ARDISTRIBUTION.InvoiceIdent left join INVOICESALESTAX ON INVOICESALESTAX.InvoiceSalesTaxIdent = ARDISTRIBUTION.InvoiceSalesTaxIdent left join INVOICE INVSALESTAX ON INVSALESTAX.InvoiceIdent = INVOICESALESTAX.InvoiceIdent WHERE ARTransaction.AREntryTypeIntCode=1 /* 1=Payment */ AND ARTransaction.CorrectionStatusCode=1 AND ARTransaction.Posted=1 AND ARDISTRIBUTION.ARIdent is not null /* Payments (UnDistributed) */ UNION ALL SELECT ARTRANSACTION.ClientIdent, ARTRANSACTION.TransactionDateTime, ARTRANSACTION.ReferenceNumber, ARTRANSACTION.amount - ISNULL((select sum(DistributionAmount) FROM ARDISTRIBUTION where arident=ARTRANSACTION.arident),0) AS PaymentAmount, 0 AS [Distributed], NULL AS ARChargesIdent, NULL AS InvoiceSalesTaxIdent, 0 AS InvoiceNumber, 0 AS InvoiceSalesTaxNumber FROM ARTRANSACTION WHERE ARTransaction.AREntryTypeIntCode = 1 /* 1=Payment */ AND ARTransaction.CorrectionStatusCode = 1 AND ARTransaction.Posted=1 AND ARTRANSACTION.amount - ISNULL((select sum(DistributionAmount) FROM ARDISTRIBUTION where arident=ARTRANSACTION.arident),0)<>0 ) AS t1 GO /****** Object: View [dbo].[UVW_WIPAR10Clientident] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER VIEW [dbo].[UVW_WIPAR10Clientident] AS /* WIP Billed Hours and Amounts */ SELECT wip.ClientIdent ,INVOICE.InvoiceDateTime /* billed hours */ /* verified to built-in Client Billing Realization report */ ,wip.[Hours] AS BilledHours /* billing amount */ /* verified to built-in Client Billing Realization report */ ,BilledAmount FROM WIP LEFT OUTER JOIN INVOICE ON wip.InvoiceIdent = INVOICE.InvoiceIdent LEFT OUTER JOIN ServiceCode S ON S.ServiceCodeIdent = WIP.ServiceCodeIdent LEFT OUTER JOIN ClientPractice CP ON CP.ClientIdent = WIP.ClientIdent WHERE INVOICE.StatusCode = 1 AND WIP.WIPTypeCode IN (0,1,2) AND WIP.BillingStatusCode = 2 AND WIP.TEStatusCode = 3 AND WIP.HistoryFlag = 0 AND WIP.InvoiceIdent IS NOT NULL AND (S.BillableTypeFlag=1 OR (S.BillableTypeFlag=3 AND CP.IsBillableFlag='T')) GO /****** Object: View [dbo].[UVW_WIPDetailLedger] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER VIEW [dbo].[UVW_WIPDetailLedger] AS /* 04-12-2021 CREATE OR ALTERd new important notes: this view was CREATE OR ALTERd specifically to support the WIP Detail Ledger report it seems to have some awfully strange conditions for the WHERE clause, but it is in agreement with the Axcess built-in report */ /* 04-12-2021 note to Brent the below is working great... but... it could be improved by combining the 2 queries below into a single query as it stands now, the first query gathers the time/expense records, and the second query gets progress records. these 2 queries follow slightly different filter criteria, but could nontheless be combined into a single query that accomplishes both purposes in a single SELECT statement */ /* time/expense (not progress) transactions */ SELECT WIP.clientident, WIP.projectident, WIP.workstepident, WIP.servicecodeident, WIP.staffident, WIP.wiptypecode, WIP.TransactionDate, /* 02-11-2025 BD it appears that some expense transactions have a 1.00 in the hours which throws off the total hours, so I am forcing this to a 0.00 */ CASE WHEN WIP.WIPTypeCode=0 THEN WIP.[hours] ELSE 0 END AS [hours], WIP.adjrate, (WIP.adjamount + WIP.SurchargeAmount + WIP.ProjsurchargeAmount) AS amount FROM WIP LEFT JOIN Invoice INVOICE1 ON wip.ProgressInvIntIdent = INVOICE1.InvoiceIdent LEFT JOIN Invoice INVOICE2 ON wip.InvoiceIdent = INVOICE2.InvoiceIdent WHERE WIP.WIPTypeCode in (0,1,2) /* 0=time 1=expense 2=reimbursable expense (no progress) */ and WIP.TEStatusCode = 3 /* 0=unreleased 1=released 2=reviewed 3=posted */ and WIP.isbillableflag = 1 AND (BillingStatusCode = 0 OR (BillingStatusCode=2 AND ISNULL(INVOICE1.StatusCode,0)=0 AND ISNULL(INVOICE2.StatusCode,0)=0)) UNION ALL /* progress bills */ SELECT WIP.clientident, WIP.projectident, WIP.workstepident, WIP.servicecodeident, WIP.staffident, WIP.WIPTypeCode, WIP.TransactionDate, 0 AS [hours], WIP.adjrate, -(WIP.adjamount + WIP.SurchargeAmount + WIP.ProjsurchargeAmount) as amount FROM wip LEFT JOIN INVOICE AS INVOICE1 ON wip.ProgressInvIntIdent = INVOICE1.InvoiceIdent WHERE WIP.WIPTypeCode = 3 /* 3=progress */ and WIP.TEStatusCode = 3 /* 0=unreleased 1=released 2=reviewed 3=posted */ AND WIP.isbillableflag = 1 AND WIP.BillingStatusCode = 0 AND ISNULL(INVOICE1.StatusCode,0) = 1 /* WIP line is unbilled, but the progress invoice is posted */ GO /****** Object: View [dbo].[UVW_WIPSummaryClientident] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER VIEW [dbo].[UVW_WIPSummaryClientident] AS /* this returns a table summary by clientident that has WIP summary totals this query is used as the basis of "Billing Report" and "WIP Summary Report" it is also used to populate the Client selection tab with amounts for Billing worksheet selection WIPGross WIPBilled ProgGross ProgPosted 07-17-2019 verified these totals against the built-in Axcess WIP Summary report 07-24-2019 bug 186182 - we are NOT going to include any "final billed" WIP even if the invoice is unposted this will cause a potential discrepancy with built-in reports */ SELECT wip.ClientIdent, wip.ProjectIdent, wip.WIPTypeCode, wip.TransactionDate, INVOICE1.InvoiceDateTime AS InvoiceDateTime1, /* date of progress transactions */ INVOICE2.InvoiceDateTime AS InvoiceDateTime2 /* date of invoice transactions */ ,(CASE WIPTypeCode WHEN 3 THEN 0 ELSE WIP.[Hours] END) AS WIPHours /* time/expense gross (does not look at progress transactions) */ /* "gross" WIP amount (unbilled and billed) */ ,(CASE WIPTypeCode WHEN 3 THEN 0 /* exclude progress */ ELSE CASE WHEN BillingStatusCode IN (0,2) THEN /* 0=Unbilled 1=Final Billed */ AdjAmount + SurchargeAmount + ProjsurchargeAmount ELSE 0 END END) AS WIPGross /* time/expense billed */ ,(CASE WIPTypeCode WHEN 3 THEN 0 /* exclude progress */ ELSE /* if the time is billed, we need to look at invoice status */ CASE WHEN BillingStatusCode=2 AND ((INVOICE1.StatusCode = 1) OR (INVOICE2.StatusCode = 1)) THEN AdjAmount + SurchargeAmount + ProjsurchargeAmount ELSE 0 END END) AS WIPBilled /* progress records */ ,(CASE WIPTypeCode WHEN 3 THEN CASE WHEN BillingStatusCode = 0 AND ((INVOICE1.StatusCode = 1) OR (INVOICE2.StatusCode = 1)) THEN AdjAmount + SurchargeAmount + ProjsurchargeAmount ELSE 0 END ELSE 0 END) ProgGross -- minus progress posted ,(CASE WIPTypeCode WHEN 3 THEN CASE WHEN BillingStatusCode = 1 AND ((INVOICE1.StatusCode = 0 ) OR (INVOICE2.StatusCode = 0)) THEN AdjAmount + SurchargeAmount + ProjsurchargeAmount ELSE 0 END ELSE 0 END) AS ProgPosted -- count WIP transactions that will show on billing worksheet, even if the amounts are 0 ,(CASE WHEN WIPTypeCode IN (0,1,2) /* 0=time 1=expense 2=reimbursable expense */ AND BillingStatusCode = 0 /* 0=Unbilled */ /* bug 201637 added this test to not include WIP lines in the active WIP line count that have been transferred OUT (code 2) 03/07/2024 - had a long discussion with Nick and Joe about whether it is necessary to filter on TransferStatusCode I looked at a number of transaction examples, and came to this conclusion 1) If TransferStatusCode=1 (TransferIn), then it has to be included in the report, and it is treated just like a normal transaction where the TransferStatusCode=0 2) if TransferStatusCode=2 (TransferOut), then the amounts in the record are set to 0 (hours, stdamount, adjamount, etc) so the record has no effect on reporting */ AND TransferStatusCode <> 2 THEN 1 ELSE 0 END) AS WipCount FROM WIP /* bug 197487 it appears that various queries are including WIP that has been applied to an invoice or progress invoice, and subsequently reversed so I'm adding a test on both of the JOIN's below to exclude reversed invoices (StatusCode=3) */ /* bug 199404 similar to above, the query is showing things that are in unposted StatusCode so I'm making yet another change so that the query will only look at invoices that are in status 1 (posted) or 2 (rebilled). It will exclude status 0 (unposted) and 3 (reversed) */ LEFT JOIN Invoice INVOICE1 WITH (NOLOCK) ON wip.ProgressInvIntIdent = INVOICE1.InvoiceIdent LEFT JOIN Invoice INVOICE2 WITH (NOLOCK) ON wip.InvoiceIdent = INVOICE2.InvoiceIdent WHERE IsBillableFlag = 1 /* billable */ AND TEStatusCode = 3 /* posted */ GO /****** Object: StoredProcedure [dbo].[USP_AddIndexes] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_AddIndexes] AS BEGIN SET NOCOUNT ON; CREATE NONCLUSTERED INDEX [IDX_DAU001] ON [dbo].[ARTRANSACTION] ( [CorrectionStatusCode] ASC, [TransactionDateTime] ASC, [AREntryTypeIntCode] ASC ) INCLUDE ( [ARIdent], [ClientIdent], [PostedDateTime], [ReferenceDateTime], [Amount], [ReferenceNumber]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] CREATE NONCLUSTERED INDEX [IDX_DAU002] ON [dbo].[CLIENTCRS] ( [FirmClientStaffAssignmentDescription] ASC ) INCLUDE ( [ClientIdent], [StaffIdent]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] CREATE NONCLUSTERED INDEX [IDX_DAU003] ON [dbo].[ARTRANSACTION] ( [CorrectionStatusCode] ASC, [TransactionDateTime] ASC ) INCLUDE ( [ARIdent], [ClientIdent], [PostedByStaffIdent], [PostedDateTime], [ReferenceDateTime], [AREntryTypeIntCode], [Amount], [ReferenceNumber]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] CREATE NONCLUSTERED INDEX [IDX_DAU004] ON [dbo].[ARCHARGES] ( [TransactionDateTime] ASC ) INCLUDE ( [ClientIdent], [PostedByStaffIdent], [PostedDateTime], [ReferenceDateTime], [AREntryTypeCode], [ARChargesAmount], [ReferenceNumber]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] CREATE NONCLUSTERED INDEX [IDX_DAU005] ON [dbo].[CLIENT] ( [DeleteFlag] ASC ) INCLUDE ( [ClientIdent], [ClientIdSubId], [ClientSortName]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] CREATE NONCLUSTERED INDEX [IDX_DAU006] ON [dbo].[WIP] ( [TEStatusCode] ASC, [IsBillableFlag] ASC, [TransactionDate] ASC, [BillingStatusCode] ASC ) INCLUDE ( [ClientIdent], [AdjAmount], [SurchargeAmount], [ProjsurchargeAmount], [WIPTypeCode]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] CREATE NONCLUSTERED INDEX [IDX_DAU007] ON [dbo].[WIP] ( [BillingStatusCode] ASC, [TEStatusCode] ASC, [WIPTypeCode] ASC ) INCLUDE ( [ClientIdent], [ServiceCodeIdent], [InvoiceIdent], [BilledAmount]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] CREATE NONCLUSTERED INDEX [IDX_DAU008] ON [dbo].[WIP] ( [WIPTypeCode] ASC, [BillingStatusCode] ASC ) INCLUDE ( [ClientIdent], [InvoiceIdent], [AdjAmount], [SurchargeAmount], [ProjsurchargeAmount]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] CREATE NONCLUSTERED INDEX [IDX_DAU009] ON [dbo].[WIP] ( [TEStatusCode] ASC, [IsBillableFlag] ASC ) INCLUDE ( [ClientIdent], [ProgressInvIntIdent], [InvoiceIdent], [TransactionDate], [AdjAmount], [SurchargeAmount], [ProjsurchargeAmount], [WIPTypeCode], [BillingStatusCode], [TransferStatusCode]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] CREATE NONCLUSTERED INDEX [IDX_DAU010] ON [dbo].[CLIENT] ( [ClientIdSubId] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] CREATE NONCLUSTERED INDEX [IDX_DAU011] ON [dbo].[WIP] ( [BillingStatusCode] ASC, [TEStatusCode] ASC, [WIPTypeCode] ASC ) INCLUDE ( [ClientIdent], [ServiceCodeIdent], [InvoiceIdent], [Hours], [Cost], [BilledAmount]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] CREATE NONCLUSTERED INDEX [IDX_DAU012] ON [dbo].[WIP] ( [InvoiceIdent] ASC, [BillingStatusCode] ASC, [TEStatusCode] ASC, [WIPTypeCode] ASC ) INCLUDE ( [ClientIdent], [ServiceCodeIdent], [Hours], [Cost], [BilledAmount]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] CREATE NONCLUSTERED INDEX [IDX_DAU013] ON [dbo].[WIP] ( [WIPTypeCode] ASC, [Hours] ASC, [BillingStatusCode] ASC ) INCLUDE ( [StaffIdent], [ServiceCodeIdent], [TransactionDate], [PostedDateTime], [TEStatusCode], [IsBillableFlag]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] CREATE NONCLUSTERED INDEX [IDX_DAU014] ON [dbo].[INVOICE] ( [StatusCode] ASC ) INCLUDE ( [ClientIdent], [InvoiceDateTime], [StdWIPAmount], [AdjustmentAmount], [TaxAmount], [ProgressBilledAmount], [ProgressApplyAmount], [ProgressTaxAmount], [ProgressTaxAppAmount]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] CREATE NONCLUSTERED INDEX [IDX_DAU015] ON [dbo].[WIP] ( [TEStatusCode] ASC, [IsBillableFlag] ASC, [TransactionDate] ASC, [BillingStatusCode] ASC ) INCLUDE ( [ClientIdent], [Hours], [AdjAmount], [SurchargeAmount], [ProjsurchargeAmount], [WIPTypeCode]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] CREATE NONCLUSTERED INDEX [IDX_DAU016] ON [dbo].[WIP] ( [WIPTypeCode] ASC, [TEStatusCode] ASC, [TransactionDate] ASC, [BillingStatusCode] ASC ) INCLUDE ( [ClientIdent], [StaffIdent], [Hours], [AdjAmount], [IsBillableFlag]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] CREATE NONCLUSTERED INDEX [IDX_DAU017] ON [dbo].[WIP] ( [TEStatusCode] ASC, [BillingStatusCode] ASC ) INCLUDE ( [WIPIdent], [ClientIdent], [ServiceCodeIdent], [InvoiceIdent], [TransactionDate], [WIPTypeCode]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] CREATE NONCLUSTERED INDEX [IDX_DAU018] ON [dbo].[WIP] ( [TEStatusCode] ASC, [BillingStatusCode] ASC ) INCLUDE ( [ClientIdent], [ServiceCodeIdent], [InvoiceIdent], [TransactionDate], [BilledAmount], [WIPTypeCode], [HistoryFlag]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] CREATE NONCLUSTERED INDEX [IDX_DAU019] ON [dbo].[WIP] ( [WIPTypeCode] ASC, [TEStatusCode] ASC, [IsBillableFlag] ASC, [TransactionDate] ASC, [BillingStatusCode] ASC ) INCLUDE ( [ClientIdent], [StaffIdent], [ServiceCodeIdent], [ProjectIdent], [WorkstepIdent], [ProgressInvIntIdent], [InvoiceIdent], [Hours], [AdjRate], [AdjAmount], [SurchargeAmount], [ProjsurchargeAmount]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] CREATE NONCLUSTERED INDEX [IDX_DAU020] ON [dbo].[WIP] ( [TEStatusCode] ASC, [IsBillableFlag] ASC, [TransactionDate] ASC, [WIPTypeCode] ASC, [BillingStatusCode] ASC ) INCLUDE ( [ClientIdent], [StaffIdent], [ServiceCodeIdent], [ProjectIdent], [WorkstepIdent], [ProgressInvIntIdent], [InvoiceIdent], [Hours], [AdjRate], [AdjAmount], [SurchargeAmount], [ProjsurchargeAmount]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] CREATE NONCLUSTERED INDEX [IDX_DAU021] ON [dbo].[WIP] ( [BillingStatusCode] ASC, [TEStatusCode] ASC, [IsBillableFlag] ASC, [TransactionDate] ASC ) INCLUDE ( [ClientIdent], [ProgressInvIntIdent], [InvoiceIdent], [AdjAmount], [SurchargeAmount], [ProjsurchargeAmount], [WIPTypeCode]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] END GO /****** Object: StoredProcedure [dbo].[USP_ARAging] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_ARAging] @mEnddate DATETIME, @mShowFC bit = 1, @mBucketdays int = 30, /* was 180 */ /* this parameter value will either be All, or one of the firm-defined CRS positions if a CRS position name is passed in, this will be used as the primary sort field */ @mCRSTitle varchar(32) = 'All', @mStaffIdentifierList VARCHAR(MAX) = '' /* if a specified list of CRS staff is selected, this will contain the list */ AS BEGIN SET NOCOUNT ON; declare @mAddone as int = 0 /* this adds one day to aging days, it appears some versions of the built-in reports require an extra day */ /* this section CREATE OR ALTERs a temp table to hold the comma separated 'staff' values sent in by the program. */ CREATE TABLE #tempstaff (column1 NVARCHAR(255)) INSERT INTO #tempstaff select * from [dbo].[UFN_String2Table](@mStaffIdentifierList) SELECT ISNULL((SELECT STAFF.StaffName FROM CLIENTCRS LEFT JOIN STAFF ON CLIENTCRS.StaffIdent=STAFF.StaffIdent WHERE ClientIdent=t1.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription = @mCRSTitle),' No Selection') AS CRS1, Client.ClientIdSubId, Client.ClientSortName, t1.AgingAmount, t1.T01, t1.T02, t1.T03, t1.T04 FROM (SELECT ClientIdent, SUM(AgingAmount) AS AgingAmount, SUM(CASE WHEN DATEDIFF(d,AgingBucketDate,@mEnddate) BETWEEN 0 AND (@mBucketdays * 1 + @mAddone) THEN AgingAmount ELSE 0 END) as T01, SUM(CASE WHEN DATEDIFF(d,AgingBucketDate,@mEnddate) BETWEEN (@mBucketdays * 1 + 1 + @mAddone) AND (@mBucketdays * 2 + @mAddone) THEN AgingAmount ELSE 0 END) as T02, SUM(CASE WHEN DATEDIFF(d,AgingBucketDate,@mEnddate) BETWEEN (@mBucketdays * 2 + 1 + @mAddone) AND (@mBucketdays * 3 + @mAddone) THEN AgingAmount ELSE 0 END) as T03, /* 06-25-2020 bug fix oddly enough, it appears that anything that has a NEGATIVE aging days is bucketed into the OLDEST aging category by CCH Axcess report. This doesn't really make logical sense, but i'm doing this to make reports match */ SUM(CASE WHEN DATEDIFF(d,AgingBucketDate,@mEnddate) < 0 OR DATEDIFF(d,AgingBucketDate,@mEnddate) >= (@mBucketdays * 3 + 1 + @mAddone) THEN AgingAmount ELSE 0 END) as T04 FROM UVW_ARAgingDetail WHERE /* 06-25-2020 bug fix. the filtering date must be set to BalanceDate in order to match CCH Axcess report total */ /* AgingBucketDate */ BalanceDate <= @mEnddate AND (CASE WHEN document LIKE 'FC%' OR applyto LIKE 'FC%' THEN @mShowFC ELSE 1 END) = 1 GROUP BY ClientIdent ) AS t1 LEFT JOIN CLIENT ON CLIENT.ClientIdent=t1.ClientIdent LEFT JOIN CLIENTCRS ON CLIENTCRS.ClientIdent = CLIENT.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription=@mCRSTitle LEFT JOIN STAFF ON CLIENTCRS.StaffIdent = STAFF.StaffIdent WHERE (CASE WHEN @mCRSTitle = 'All' THEN 1 ELSE CASE WHEN ISNULL(STAFF.StaffIdentifier,'0') IN (SELECT column1 FROM #tempstaff) THEN 1 ELSE 0 END END) = 1 AND (t1.AgingAmount <> 0) /* AND (t1.T01 <> 0 OR t1.T02 <> 0 OR t1.T03 <> 0 OR t1.T04 <> 0) */ ORDER BY CRS1,ClientIdSubId END GO /****** Object: StoredProcedure [dbo].[USP_ARAvgDaysToPay] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_ARAvgDaysToPay] @mBegdate DATE, @mEnddate DATE, /* this parameter value will either be All, or one of the firm-defined CRS positions if a CRS position name is passed in, this will be used as the primary sort field */ @mCRSTitle varchar(32) = 'All', @mStaffIdentifierList VARCHAR(MAX) = '' /* if a specified list of CRS staff is selected, this will contain the list */ AS BEGIN SET NOCOUNT ON; /* this section CREATE OR ALTERs a temp table to hold the comma separated 'staff' values sent in by the program. */ CREATE TABLE #tempstaff (column1 NVARCHAR(255)) INSERT INTO #tempstaff select * from [dbo].[UFN_String2Table](@mStaffIdentifierList) SELECT ISNULL((SELECT STAFF.StaffName FROM CLIENTCRS LEFT JOIN STAFF ON CLIENTCRS.StaffIdent=STAFF.StaffIdent WHERE ClientIdent=ar1.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription = @mCRSTitle),' No Selection') AS CRS1 ,CLIENT.ClientIdSubId ,CLIENT.ClientSortName ,ar1.AppliedTo /* invoice number, underlying field is Invoice.InvoiceNumber */ ,ar1.paymentdate /* individual payment posting date, underlying field is ARTransaction.PostedDateTime */ ,ar1.InvoiceDateTime /* original invoice date, underlying field is Invoice.InvoiceDateTime */ ,ar1.pmtamount /* individual payment amount, this field flows from [UVW_ARComponentDetail] */ ,ar1.TransactionType /* 4=Payment 5=Credit 6=Debit 7=Writeoff 8=Adjustment, this field flows from [UVW_ARComponentDetail] */ ,ar1.invamount /* original invoice amount */ ,ar1.invoicetitle FROM [UVW_ARAvgDaysToPay] ar1 LEFT JOIN CLIENT on ar1.ClientIdent = CLIENT.ClientIdent LEFT JOIN CLIENTCRS ON CLIENTCRS.ClientIdent = CLIENT.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription=@mCRSTitle LEFT JOIN STAFF ON CLIENTCRS.StaffIdent = STAFF.StaffIdent WHERE (CASE WHEN @mCRSTitle = 'All' THEN 1 ELSE CASE WHEN ISNULL(STAFF.StaffIdentifier,'0') IN (SELECT column1 FROM #tempstaff) THEN 1 ELSE 0 END END) = 1 AND ar1.InvoiceDateTime BETWEEN @mBegdate AND @mEnddate /* invoice date range */ AND CLIENT.DeleteFlag = 'F' ORDER BY CLIENT.ClientIdSubId,ar1.InvoiceDateTime,ar1.AppliedTo,ar1.paymentdate END GO /****** Object: StoredProcedure [dbo].[USP_ARBalanceListing] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_ARBalanceListing] @mEnddate DATETIME AS BEGIN SET NOCOUNT ON; SELECT client.ClientIdSubId, client.ClientSortName, UVW_ARComponentDetail.* FROM UVW_ARComponentDetail LEFT JOIN client on client.ClientIdent = UVW_ARComponentDetail.clientident WHERE transactiondate <= @mEnddate AND amount<>0.00 ORDER BY ClientIdSubId,UVW_ARComponentDetail.transactiondate END GO /****** Object: StoredProcedure [dbo].[USP_ARComponent] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_ARComponent] @mBegdate DATE, @mEnddate DATE AS BEGIN SET NOCOUNT ON; /* this CREATE OR ALTERs an AR balance query by AR "component" there's no built-in report that shows this as such, but these components are used for AR Aging and it is a good diagnostic tool for any A/R balance type report */ SELECT client.ClientIdSubId, client.ClientSortName, ISNULL(t1.BeginBalance,0.00) AS BeginBalance, ISNULL(t2.Invoice,0.00) AS Invoice, ISNULL(t2.SalesTax,0.00) AS SalesTax, ISNULL(t2.FinChg,0.00) AS FinChg, ISNULL(t2.PmtsDistributed,0.00) AS PmtsDistributed, ISNULL(t2.PmtsUndistributed,0.00) AS PmtsUndistributed, ISNULL(t2.Adj23Distributed,0.00) AS Adj23Distributed, ISNULL(t2.Adj67Distributed,0.00) AS Adj67Distributed, ISNULL(t2.Adj23Undistributed,0.00) AS Adj23Undistributed, ISNULL(t2.Adj67Undistributed,0.00) AS Adj67Undistributed, ISNULL(t2.AdjOther,0.00) as AdjOther, ISNULL(t2.WriteOffDistributed,0.00) as WriteOffDistributed, ISNULL(t2.WriteOffUndistributed,0.00) AS WriteOffUndistributed FROM CLIENT LEFT JOIN (SELECT clientident, sum(amount) AS BeginBalance FROM UVW_ARComponentDetail WHERE TransactionDate < @mBegdate GROUP BY clientident ) AS t1 ON CLIENT.ClientIdent = t1.ClientIdent LEFT JOIN /* transactions in the current period split out in columns by transaction type note.....the transaction type is defined by UVW_ARComponentDetail, but not directly by the database table itself */ (SELECT clientident, [1] AS Invoice, [2] AS SalesTax, [3] AS FinChg, [4] AS PmtsDistributed, [5] AS PmtsUndistributed, [6] AS Adj23Distributed, [7] AS Adj67Distributed, [8] AS Adj23Undistributed, [9] AS Adj67Undistributed, [10] AS AdjOther, [11] AS WriteOffDistributed, [12] AS WriteOffUndistributed FROM (SELECT Amount, clientident, transactiontype FROM UVW_ARComponentDetail WHERE TransactionDate BETWEEN @mBegdate AND @mEnddate ) p PIVOT (SUM(Amount) FOR TransactionType IN ( [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12] ) ) AS pvt ) AS t2 ON CLIENT.ClientIdent = t2.ClientIdent WHERE (ISNULL(t1.BeginBalance,0) <> 0 OR t2.Invoice <> 0 OR t2.SalesTax <> 0 OR t2.FinChg <> 0 OR t2.PmtsDistributed <> 0 OR t2.PmtsUndistributed <> 0 OR t2.Adj23Distributed <> 0 OR t2.Adj23Undistributed <> 0 OR t2.Adj67Distributed <> 0 OR t2.Adj67Undistributed <> 0 OR t2.AdjOther <> 0 OR t2.WriteOffDistributed <> 0 OR t2.WriteOffUndistributed <> 0) ORDER BY CLIENT.ClientIdSubId END GO /****** Object: StoredProcedure [dbo].[USP_ARFinanceCharges] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_ARFinanceCharges] @mBegdate DATE = '01/01/1900', @mEnddate DATE, @mFCOnly CHAR(1) = 'F' /* set to F to exclude deleted, or set to T to include deleted */ AS BEGIN SET NOCOUNT ON; SELECT CLIENT.ClientOfficeName, CLIENT.ClientIdSubId, CLIENT.ClientSortName, T1.* FROM (SELECT ClientIdent, /* 06-29-2023 this appears to be giving the wrong Finance Charge balance, because there can be AppliedType=10 transactions that are not related to Finance Charges SUM(CASE WHEN TransactionType<>3 AND appliedtype<>10 THEN amount ELSE 0 END) AS ARBalance1, SUM(CASE WHEN TransactionType=3 OR appliedtype=10 THEN amount ELSE 0 END) AS FinChgBalance, */ /* 06-29-2023 so, I am going to change the above lines to look at the AppliedTo field and report anything with an FC as a finance charge SUM(CASE WHEN TransactionType=3 OR AppliedTo LIKE 'FC%' THEN 0 ELSE Amount END) AS ARBalance1, SUM(CASE WHEN TransactionType=3 OR AppliedTo LIKE 'FC%' THEN Amount ELSE 0 END) AS FinChgBalance, */ /* 10-11-2023 yet another change to try and fix the finance charge column */ SUM(CASE WHEN (AppliedTo LIKE 'FC%') OR (TransactionType=11 AND AppliedType=10) THEN 0 ELSE Amount END) AS ARBalance1, SUM(CASE WHEN (AppliedTo LIKE 'FC%') OR (TransactionType=11 AND AppliedType=10) THEN Amount ELSE 0 END) AS FinChgBalance, SUM(amount) AS ARBalance2 FROM UVW_ARComponentDetail WHERE TransactionDate BETWEEN @mBegdate AND @mEnddate GROUP BY clientident HAVING SUM(amount)<>0) T1 LEFT JOIN CLIENT ON T1.ClientIdent = CLIENT.ClientIdent WHERE (CASE WHEN @mFCOnly='F' THEN 1 ELSE CASE WHEN FinCHGBalance=ARBalance2 THEN 1 ELSE 0 END END) = 1 ORDER BY CLIENT.ClientOfficeName,CLIENT.ClientIdSubId END GO /****** Object: StoredProcedure [dbo].[USP_ARPaymentsCredits] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_ARPaymentsCredits] @mBegdate DATETIME, @mEnddate DATETIME, @mBegdateInvoice DATETIME, @mEnddateInvoice DATETIME, /* this parameter value will either be All, or one of the firm-defined CRS positions if a CRS position name is passed in, this will be used as the primary sort field */ @mCRSTitle varchar(32) = 'All', @mStaffIdentifierList VARCHAR(MAX) = '', /* if a specified list of CRS staff is selected, this will contain the list */ @mOffice VARCHAR(64) AS BEGIN SET NOCOUNT ON; /* this section CREATE OR ALTERs a temp table to hold the comma separated 'staff' values sent in by the program. */ CREATE TABLE #tempstaff (column1 NVARCHAR(255)) INSERT INTO #tempstaff select * from [dbo].[UFN_String2Table](@mStaffIdentifierList) SELECT ISNULL((SELECT STAFF.StaffName FROM CLIENTCRS LEFT JOIN STAFF ON CLIENTCRS.StaffIdent=STAFF.StaffIdent WHERE ClientIdent = UVW_ARRegister.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription = @mCRSTitle),' No Selection') AS CRS1, ClientIdSubId, ClientSortName, UVW_ARRegister.*, CASE UVW_ARRegister.AREntryTypeIntCode WHEN 1 THEN 'Payment' WHEN 2 THEN 'Cr Memo' WHEN 3 THEN 'Cr Adj' WHEN 4 THEN 'GST WO' WHEN 5 THEN 'W/O' WHEN 6 THEN 'Dr Memo' WHEN 7 THEN 'Dr Adj' END AS AREntryType FROM UVW_ARRegister LEFT JOIN CLIENT ON CLIENT.ClientIdent = UVW_ARRegister.ClientIdent LEFT JOIN CLIENTCRS ON CLIENTCRS.ClientIdent = CLIENT.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription = @mCRSTitle LEFT JOIN STAFF ON CLIENTCRS.StaffIdent = STAFF.StaffIdent WHERE AREntryTypeIntCode IN (1,2,3,4,5) AND UVW_ARRegister.Posted = 1 /* per bug 295968, we should only include posted transactions in this report */ AND TransactionDateTime BETWEEN @mBegdate AND @mEnddate AND InvoiceDateTime BETWEEN @mBegdateInvoice AND @mEnddateInvoice AND (CASE WHEN @mCRSTitle = 'All' THEN 1 ELSE CASE WHEN ISNULL(STAFF.StaffIdentifier,'0') IN (SELECT column1 FROM #tempstaff) THEN 1 ELSE 0 END END) = 1 AND CASE WHEN @mOffice='All' THEN CLIENT.ClientOfficeName ELSE @mOffice END = CLIENT.ClientOfficeName ORDER BY ClientIdSubId,TransactionDateTime,ReferenceNumber,AppliedTo END GO /****** Object: StoredProcedure [dbo].[USP_ARReconciliation] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_ARReconciliation] @mBegdate1 AS DATE, /* current balance date range */ @mEnddate1 AS DATE, /* current balance date range */ @mSortOrder AS INT = 0, /* 0 = sort by clientid, 1 = sort by clientsortname */ @mIncludeDeleted CHAR(1) = 'F', /* set to F to exclude deleted, or set to T to include deleted */ /* this parameter value will either be All, or one of the firm-defined CRS positions if a CRS position name is passed in, this will be used as the primary sort field */ @mCRSTitle varchar(32) = 'All', @mStaffIdentifierList VARCHAR(MAX) = '' /* if a specified list of CRS staff is selected, this will contain the list */ AS BEGIN DECLARE @mBegdate0 DATE = '01/01/1900' /* prior balance date range begin */ DECLARE @mEnddate0 DATE = DATEADD(d,-1,@mBegdate1) /* prior balance date range end */ /* this section creates a temp table to hold the comma separated 'staff' values sent in by the program. */ CREATE TABLE #tempstaff (column1 NVARCHAR(255)) INSERT INTO #tempstaff select * from [dbo].[UFN_String2Table](@mStaffIdentifierList) SELECT ISNULL((SELECT STAFF.StaffName FROM CLIENTCRS LEFT JOIN STAFF ON CLIENTCRS.StaffIdent=STAFF.StaffIdent WHERE ClientIdent = T1.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription = @mCRSTitle),' No Selection') AS CRS1, [CLIENT].ClientIdSubId, [Client].ClientSortName, t1.* FROM (SELECT t00.ClientIdent /* prior period amounts */ ,ISNULL(wipar06_prev.invoiceamount,0.00) as p_invoiceamount ,ISNULL(wipar06_prev.salestaxamount,0.00) AS p_salestaxamount ,ISNULL(wipar07_prev.creditamount,0.00) AS p_creditamount ,ISNULL(wipar07_prev.debitamount,0.00) AS p_debitamount ,ISNULL(wipar07_prev.adjustment1amount,0.00) AS p_adjustment1amount ,ISNULL(wipar07_prev.adjustment2amount,0.00) AS p_adjustment2amount ,ISNULL(wipar07_prev.Amount5,0.00) AS p_amount5 /* write-off */ ,ISNULL(wipar08_prev.charges,0.00) AS p_charges ,ISNULL(wipar09_prev.PaymentAmount,0.00) AS p_paymentamount /* current period amounts */ ,ISNULL(wipar06_curr.invoiceamount,0.00) as c_invoiceamount ,ISNULL(wipar06_curr.salestaxamount,0.00) AS c_salestaxamount ,ISNULL(wipar07_curr.creditamount,0.00) AS c_creditamount ,ISNULL(wipar07_curr.debitamount,0.00) AS c_debitamount /* for reconciliation report, we add adjustment1amount + adjustment2amount = Adjust column */ ,ISNULL(wipar07_curr.adjustment1amount,0.00) AS c_adjustment1amount ,ISNULL(wipar07_curr.adjustment2amount,0.00) AS c_adjustment2amount /* write-off */ ,ISNULL(wipar07_curr.Amount5,0.00) AS c_amount5 ,ISNULL(wipar08_curr.charges,0.00) AS c_charges ,ISNULL(wipar09_curr.PaymentAmount,0.00) AS c_paymentamount FROM /* this is the main report driver select */ (SELECT clientident FROM CLIENT ) AS t00 /* previous ar invoice */ LEFT JOIN (SELECT ClientIdent ,SUM(InvoiceAmount) AS InvoiceAmount ,SUM(SalesTaxAmount) AS SalesTaxAmount FROM UVW_WIPAR06Clientident WHERE InvoiceDateTime BETWEEN @mBegdate0 and @mEnddate0 GROUP BY ClientIdent ) as wipar06_prev ON wipar06_prev.Clientident = t00.ClientIdent /* previous credit memos, debit memos, adjustments */ LEFT JOIN (SELECT ClientIdent ,SUM(CreditAmount) AS CreditAmount ,SUM(Adjustment1Amount) AS Adjustment1Amount ,SUM(Amount4) AS Amount4 /* GST write-off */ ,SUM(Amount5) AS Amount5 /* write-off */ ,SUM(DebitAmount) AS DebitAmount ,SUM(Adjustment2Amount) AS Adjustment2Amount FROM UVW_WIPAR07Clientident WHERE transactiondatetime BETWEEN @mBegdate0 AND @mEnddate0 GROUP BY ClientIdent ) as wipar07_prev ON wipar07_prev.Clientident = t00.ClientIdent /* previous ar fin chg */ LEFT JOIN (SELECT ClientIdent ,sum(Charges) as [Charges] from UVW_WIPAR08Clientident where TransactionDateTime BETWEEN @mBegdate0 and @mEnddate0 GROUP BY Clientident ) as wipar08_prev ON wipar08_prev.Clientident = t00.ClientIdent /* previous ar payments */ LEFT JOIN (SELECT ClientIdent, SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @mBegdate0 AND @mEnddate0 GROUP BY clientident ) AS wipar09_prev ON wipar09_prev.Clientident = t00.Clientident /* current ar invoice */ LEFT JOIN (SELECT ClientIdent ,SUM(InvoiceAmount) AS InvoiceAmount ,SUM(SalesTaxAmount) AS SalesTaxAmount FROM UVW_WIPAR06Clientident WHERE InvoiceDateTime BETWEEN @mBegdate1 and @mEnddate1 GROUP BY ClientIdent ) as wipar06_curr ON wipar06_curr.Clientident = t00.ClientIdent /* current credit memos, debit memos, adjustments */ LEFT JOIN (SELECT ClientIdent ,SUM(CreditAmount) AS CreditAmount ,SUM(Adjustment1Amount) AS Adjustment1Amount ,SUM(Amount4) AS Amount4 /* GST write-off */ ,SUM(Amount5) AS Amount5 /* write-off */ ,SUM(DebitAmount) AS DebitAmount ,SUM(Adjustment2Amount) AS Adjustment2Amount FROM UVW_WIPAR07Clientident WHERE transactiondatetime BETWEEN @mBegdate1 AND @mEnddate1 GROUP BY ClientIdent ) as wipar07_curr ON wipar07_curr.Clientident = t00.ClientIdent /* current ar fin chg */ LEFT JOIN (SELECT ClientIdent ,sum(Charges) as [Charges] from UVW_WIPAR08Clientident where TransactionDateTime BETWEEN @mBegdate1 and @mEnddate1 GROUP BY Clientident ) as wipar08_curr ON wipar08_curr.Clientident = t00.ClientIdent /* current ar payments */ LEFT JOIN (SELECT ClientIdent, SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @mBegdate1 AND @mEnddate1 GROUP BY clientident ) AS wipar09_curr ON wipar09_curr.Clientident = t00.Clientident ) AS t1 LEFT JOIN CLIENT ON t1.ClientIdent=client.ClientIdent LEFT JOIN CLIENTCRS on CLIENTCRS.ClientIdent = CLIENT.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription = @mCRSTitle LEFT JOIN STAFF on CLIENTCRS.StaffIdent = STAFF.StaffIdent WHERE (t1.p_invoiceamount + t1.p_salestaxamount + t1.p_creditamount + t1.p_debitamount + t1.p_adjustment1amount + t1.p_adjustment2amount + t1.p_charges + t1.p_paymentamount <> 0 or t1.c_invoiceamount <> 0 or t1.c_salestaxamount <> 0 or t1.c_debitamount <> 0 or t1.c_creditamount <> 0 or (t1.c_adjustment1amount + t1.c_adjustment2amount) <> 0 or t1.c_charges <> 0 or t1.c_paymentamount <> 0) AND (CASE WHEN @mCRSTitle = 'All' THEN 1 ELSE CASE WHEN ISNULL(STAFF.StaffIdentifier,'0') IN (SELECT column1 FROM #tempstaff) THEN 1 ELSE 0 END END) = 1 AND (CLIENT.DeleteFlag = 'F' OR CLIENT.DeleteFlag = @mIncludeDeleted) ORDER BY CRS1,CASE WHEN @mSortOrder=0 THEN ClientIdSubId ELSE ClientSortName END END GO /****** Object: StoredProcedure [dbo].[USP_ARRegister] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_ARRegister] @mBegdate DATETIME, @mEnddate DATETIME, @mFilter INT = 0 /* 0=All or any other number selects AREntryTypeIntCode from the list below */ AS BEGIN SET NOCOUNT ON; SELECT CLIENT.ClientIdSubId, CLIENT.ClientSortName, STAFF.StaffName, CASE UVW_ARRegister.AREntryTypeIntCode WHEN 1 THEN 'Payment' WHEN 2 THEN 'Cr Memo' WHEN 3 THEN 'Cr Adj' WHEN 4 THEN 'Gwrite-off' WHEN 5 THEN 'Write-off' WHEN 6 THEN 'Dr Memo' WHEN 7 THEN 'Dr Adj' /* note that the Miscellaneous Charge code is NOT documented for the ARTRANSACTION table these transactions are documented as being in the ARCHARGES table, but it seems that Miscellaneous Charges are actually recorded in the ARTRANSACTION table the query below is looking in both tables for this transaction type */ WHEN 8 THEN 'Misc Chg' WHEN 9 THEN 'Hdlg Fee' WHEN 10 THEN 'Fin Chg' ELSE 'Error' END AS AREntryType, UVW_ARRegister.* FROM [dbo].[UVW_ARRegister] LEFT JOIN CLIENT ON Client.ClientIdent = UVW_ARRegister.ClientIdent LEFT JOIN STAFF ON STAFF.StaffIdent = UVW_ARRegister.PostedByStaffIdent WHERE transactiondatetime between @mBegdate and @mEnddate AND (CASE WHEN @mFilter = 0 THEN 1 ELSE (CASE WHEN AREntryTypeIntCode = @mFilter THEN 1 ELSE 0 END) END) = 1 AND CLIENT.DeleteFlag = 'F' ORDER BY TransactionDateTime,AREntryType,CLIENT.ClientSortName END GO /****** Object: StoredProcedure [dbo].[USP_ARUndistributed] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_ARUndistributed] @mEnddate DATETIME AS BEGIN SET NOCOUNT ON; /* show all undistributed payment items */ SELECT client.ClientIdSubId, client.ClientSortName, t1.ARIdent, t1.TransactionDateTime, ISNULL(invoice.InvoiceNumber,'') AS InvoiceNumber, t1.Amount, /* the original payment amount */ ISNULL(ARDISTRIBUTION.Distributionamount,0.00) AS DistributionAmount FROM /* this query returns ALL undistributed payments */ (SELECT ARIdent, ClientIdent, TransactionDateTime, Amount /* this provides the "starting point" of the undistributed amount */ FROM ARTRANSACTION WHERE ARTRANSACTION.AREntryTypeIntCode = 1 /* payment */ AND ARTRANSACTION.CorrectionStatusCode = 1 /* new entry */ AND ARTRANSACTION.Posted = 1 AND ARTRANSACTION.amount - ISNULL((select sum(DistributionAmount) FROM ARDISTRIBUTION where arident=ARTRANSACTION.arident),0)<>0) AS t1 LEFT JOIN CLIENT ON CLIENT.ClientIdent = t1.ClientIdent LEFT JOIN ARDISTRIBUTION ON ARDISTRIBUTION.ARIdent = t1.ARIdent LEFT JOIN INVOICE ON ARDISTRIBUTION.InvoiceIdent = INVOICE.InvoiceIdent ORDER BY client.ClientIdSubId, t1.TransactionDateTime, t1.arident, INVOICE.InvoiceNumber END GO /****** Object: StoredProcedure [dbo].[USP_Bankedhours] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_Bankedhours] @mStartdate date, @mEnddate date AS BEGIN SET NOCOUNT ON; SELECT STAFF.StaffIdentifier, STAFF.ReportName, BankedHoursDateTime, case when HoursType='Bank' then BankedHoursBalance else 0 end AS compbanked, case when HoursType='Use' then -BankedHoursBalance else 0 end AS compused FROM BANKEDHOURS INNER JOIN STAFF ON BANKEDHOURS.StaffIdent=STAFF.StaffIdent -- note....must use this CONVERT function to get a "date only" -- since the BankedHoursDateTime has both a date and time component, -- which messes up the use of BETWEEN WHERE CONVERT(date,BankedHoursDateTime) BETWEEN @mStartdate AND @mEnddate ORDER BY STAFF.ReportName,STAFF.StaffIdentifier,BankedHoursDateTime END GO /****** Object: StoredProcedure [dbo].[USP_BilledDetail] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_BilledDetail] @mBegindate DATE, @mEnddate DATE, @mCRSTitle varchar(32) AS BEGIN select CRSStaff.StaffIdentifier AS CRS ,CLIENT.ClientBusinessUnitName ,CLIENT.ClientIdSubId ,CLIENT.ClientSortName ,CLIENT.LineofBusiness ,UVW_WIPAR02Clientident.InvoiceDateTime ,UVW_WIPAR02Clientident.InvoiceNumber ,UVW_WIPAR02Clientident.BilledAmount ,STAFF.StaffLastName ,SERVICECODE.ServiceCodeID ,UVW_WIPAR02Clientident.Hours ,UVW_WIPAR02Clientident.StdAmount ,UVW_WIPAR02Clientident.AdjAmount ,UVW_WIPAR02Clientident.BilledAmount - UVW_WIPAR02Clientident.AdjAmount AS Adjustments from UVW_WIPAR02Clientident LEFT JOIN SERVICECODE ON UVW_WIPAR02Clientident.ServiceCodeIdent = SERVICECODE.ServiceCodeIdent LEFT JOIN CLIENT on UVW_WIPAR02Clientident.ClientIdent = CLIENT.ClientIdent LEFT JOIN CLIENTCRS ON CLIENT.ClientIdent=CLIENTCRS.ClientIdent and CLIENTCRS.FirmClientStaffAssignmentName = @mCRSTitle LEFT JOIN STAFF CRSStaff ON CLIENTCRS.StaffIdent = CRSStaff.StaffIdent LEFT JOIN STAFF ON UVW_WIPAR02Clientident.StaffIdent = STAFF.StaffIdent where InvoiceDateTime BETWEEN @mBegindate and @mEnddate AND UVW_WIPAR02Clientident.InvoiceStatusCode = 1 /* 1=Posted */ ORDER BY UVW_WIPAR02Clientident.InvoiceNumber,STAFF.StaffLastName END GO /****** Object: StoredProcedure [dbo].[USP_BillingAnalysisComparative] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_BillingAnalysisComparative] @PYFDate DATE, @PYTDate DATE, @CYFDate DATE, @CYTDate DATE, /* this parameter value will either be All, or one of the firm-defined CRS positions if a CRS position name is passed in, this will be used as the primary sort field */ @mCRSTitle varchar(32) = 'All', @mStaffIdentifierList VARCHAR(MAX) = '' /* if a specified list of CRS staff is selected, this will contain the list */ AS BEGIN SET NOCOUNT ON; /* this section creates a temp table to hold the comma separated 'staff' values sent in by the program. */ CREATE TABLE #tempstaff (column1 NVARCHAR(255)) INSERT INTO #tempstaff select * from [dbo].[UFN_String2Table](@mStaffIdentifierList) SELECT ISNULL((SELECT STAFF.StaffName FROM CLIENTCRS LEFT JOIN STAFF ON CLIENTCRS.StaffIdent=STAFF.StaffIdent WHERE ClientIdent=CLIENT.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription = @mCRSTitle),' No Selection') AS CRS1, CLIENT.ClientIdSubId, CLIENT.ClientSortName, ISNULL(p1.[Hours],0.00) AS p_Hours, ISNULL(p1.BilledAmount,0.00) AS p_BilledAmount, ISNULL(p2.ProgressBilledAmount,0.00) AS p_ProgressBilledAmount, ISNULL(p3.ProgressApplyAmount,0.00) AS p_ProgressApplyAmount, ISNULL(p4.WriteUpDownAmount,0.00) AS p_WriteUpDownAmount, ISNULL(c1.[Hours],0.00) AS c_Hours, ISNULL(c1.BilledAmount,0.00) AS c_BilledAmount, ISNULL(c2.ProgressBilledAmount,0.00) AS c_ProgressBilledAmount, ISNULL(c3.ProgressApplyAmount,0.00) AS c_ProgressApplyAmount, ISNULL(c4.WriteUpDownAmount,0.00) AS c_WriteUpDownAmount FROM CLIENT LEFT JOIN /* prior period WIP billed */ (SELECT clientident ,SUM([hours]) AS [Hours] ,SUM([BilledAmount]) AS [BilledAmount] FROM UVW_WIPAR02Clientident WHERE InvoiceDateTime BETWEEN @PYFDate AND @PYTDate AND InvoiceStatusCode = 1 GROUP BY clientident) as p1 ON p1.Clientident = CLIENT.ClientIdent /* prior period wip progress billed */ LEFT JOIN (SELECT ClientIdent ,sum([ProgressBilledAmount]) AS ProgressBilledAmount FROM UVW_WIPAR03Clientident WHERE InvoiceDateTime BETWEEN @PYFDate AND @PYTDate AND InvoiceStatusCode = 1 GROUP BY clientident) AS p2 ON p2.Clientident = CLIENT.ClientIdent /* prior period wip progress apply */ LEFT JOIN (Select ClientIdent ,sum([ProgressApplyAmount]) AS ProgressApplyAmount FROM UVW_WIPAR04Clientident WHERE InvoiceDateTime BETWEEN @PYFDate AND @PYTDate AND InvoiceStatusCode = 1 GROUP BY clientident) AS p3 ON p3.Clientident = CLIENT.ClientIdent /* prior period wip write up-down */ LEFT JOIN (SELECT ClientIdent ,SUM(ISNULL(writeupdownAmount,0)) AS WriteUpDownAmount FROM UVW_WIPAR05Clientident WHERE InvoiceDateTime BETWEEN @PYFDate AND @PYTDate and InvoiceStatusCode=1 GROUP BY clientident) AS p4 ON p4.Clientident = CLIENT.ClientIdent LEFT JOIN /* current period WIP billed */ (SELECT clientident ,SUM([hours]) AS [Hours] ,SUM([BilledAmount]) AS [BilledAmount] FROM UVW_WIPAR02Clientident WHERE InvoiceDateTime BETWEEN @CYFDate AND @CYTDate AND InvoiceStatusCode = 1 GROUP BY clientident) as c1 ON c1.Clientident = CLIENT.ClientIdent /* current period wip progress billed */ LEFT JOIN (SELECT ClientIdent ,sum([ProgressBilledAmount]) AS ProgressBilledAmount FROM UVW_WIPAR03Clientident WHERE InvoiceDateTime BETWEEN @CYFDate AND @CYTDate AND InvoiceStatusCode = 1 GROUP BY clientident) AS c2 ON c2.Clientident = CLIENT.ClientIdent /* current period wip progress apply */ LEFT JOIN (Select ClientIdent ,sum([ProgressApplyAmount]) AS ProgressApplyAmount FROM UVW_WIPAR04Clientident WHERE InvoiceDateTime BETWEEN @CYFDate AND @CYTDate AND InvoiceStatusCode = 1 GROUP BY clientident) AS c3 ON c3.Clientident = CLIENT.ClientIdent /* prior period wip write up-down */ LEFT JOIN (SELECT ClientIdent ,SUM(ISNULL(writeupdownAmount,0)) AS WriteUpDownAmount FROM UVW_WIPAR05Clientident WHERE InvoiceDateTime BETWEEN @CYFDate AND @CYTDate and InvoiceStatusCode=1 GROUP BY clientident) AS c4 ON c4.Clientident = CLIENT.ClientIdent LEFT JOIN CLIENTCRS on CLIENTCRS.ClientIdent = CLIENT.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription=@mCRSTitle LEFT JOIN STAFF on CLIENTCRS.StaffIdent = STAFF.StaffIdent WHERE (CASE WHEN @mCRSTitle = 'All' THEN 1 ELSE CASE WHEN ISNULL(STAFF.StaffIdentifier,'0') IN (SELECT column1 FROM #tempstaff) THEN 1 ELSE 0 END END) = 1 AND (CLIENT.DeleteFlag = 'F' /* OR CLIENT.DeleteFlag = @mIncludeDeleted */) AND ( p1.BilledAmount <> 0 OR p2.ProgressBilledAmount <> 0 OR p3.ProgressApplyAmount <> 0 OR p4.WriteUpDownAmount <> 0 OR c1.BilledAmount <> 0 OR c2.ProgressBilledAmount <> 0 OR c3.ProgressApplyAmount <> 0 OR c4.WriteUpDownAmount <> 0 ) ORDER BY ClientIdSubId END GO /****** Object: StoredProcedure [dbo].[USP_BillingRegister] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_BillingRegister] AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; SELECT client.ClientIdSubId, client.ClientSortName, invoice.InvoiceNumber, invoice.InvoiceDateTime, w.TransactionDate, w.StdAmount, w.AdjAmount, w.BilledAmount, w.ProgressBilledAmount, w.ProgressApplyAmount, w.WriteUpDownAmount, STAFF.StaffIdentifier, SERVICECODE.ServiceCodeID FROM UVW_BillingRegister w LEFT JOIN INVOICE ON w.InvoiceIdent=INVOICE.InvoiceIdent LEFT JOIN CLIENT on invoice.ClientIdent=client.ClientIdent LEFT JOIN STAFF ON w.StaffIdent=staff.StaffIdent LEFT JOIN SERVICECODE ON w.ServiceCodeIdent=SERVICECODE.ServiceCodeIdent ORDER BY ClientIdSubId,w.TransactionDate END GO /****** Object: StoredProcedure [dbo].[USP_BillingReport] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_BillingReport] @mBegdate AS varchar(10), @mEnddate AS varchar(10), /* this parameter value will either be All, or one of the firm-defined CRS positions if a CRS position name is passed in, this will be used as the primary sort field */ @mCRSTitle varchar(32) = 'All', @mStaffIdentifierList VARCHAR(MAX) = '' /* if a specified list of CRS staff is selected, this will contain the list */ AS BEGIN /* for pm column references, balance against StoredProcedure [dbo].[vpm_rpt_BillingRptMultiLevelSort] */ CREATE TABLE #tempstaff (column1 NVARCHAR(255)) INSERT INTO #tempstaff select * from [dbo].[UFN_String2Table](@mStaffIdentifierList) SELECT T00.StaffName AS CRS1, T00.StaffLastName, T00.StaffFirstName, CLIENT.ClientOfficeName, CLIENT.ClientIdSubId, CLIENT.ClientSortName /* column 1 holds a total of previous period net WIP AND Current time and expenses only */ ,ISNULL(b01.time,0.00) +ISNULL(b01.expenses,0.00) -ISNULL(b02.BilledAmount,0.00) -ISNULL(b03.ProgressBilledAmount,0.00) +ISNULL(b04.ProgressApplyAmount,0.00) +ISNULL(b05.WriteUpDownAmount,0.00) +ISNULL(t01.time,0.00) +ISNULL(t01.expenses,0.00) AS WIPAvailable /* column 2 holds a total of Current billed and Current Write Up/Down */ ,ISNULL(t02.BilledAmount,0.00) +ISNULL(t03.ProgressBilledAmount,0.00) -ISNULL(t04.ProgressApplyAmount,0.00) -ISNULL(t05.WriteUpDownAmount,0.00) AS WIPBilled /* column 3 is a calculated WIP Remaining amount (WIPAvailable - WIPBilled) */ /* column 4 is a calculated Percent Billed amount (WIPBilled / WIPAvailable) */ /* column 5 is Invoiced w/Progress */ ,ISNULL(t02.BilledAmount,0.00) + ISNULL(t03.ProgressBilledAmount,0.00) - ISNULL(t04.ProgressApplyAmount,0.00) AS InvoicedWithProg /* column 6 is realization percentage w/Progress */ /* column 7 is Invoiced w/o Progress */ ,ISNULL(t02.BilledAmount,0.00) AS BilledAmount /* column 8 is realization percentage w/o Progress */ /* column 9 is write up/down */ ,ISNULL(t05.WriteUpDownAmount,0.00) AS WriteUpDownAmount FROM CLIENT outer apply (SELECT TOP 1 StaffIdentifier,StaffName,StaffLastName,StaffFirstName FROM CLIENTCRS INNER JOIN STAFF ON CLIENTCRS.StaffIdent=STAFF.StaffIdent WHERE ClientIdent=CLIENT.ClientIdent AND FirmClientStaffAssignmentName=@mCRSTitle) T00 /* beginning balance WIP transactions */ LEFT JOIN (SELECT Clientident ,sum([time]) as [time] ,sum([expenses]) as [expenses] FROM UVW_WIPAR01Clientident WHERE transactiondate BETWEEN '01/01/1900' AND DATEADD(d,-1,@mBegdate) GROUP BY clientident) AS b01 ON b01.ClientIdent = CLIENT.ClientIdent LEFT JOIN (SELECT clientident,SUM([BilledAmount]) AS [BilledAmount] FROM UVW_WIPAR02Clientident WHERE InvoiceDateTime BETWEEN '01/01/1900' AND DATEADD(d,-1,@mBegdate) GROUP BY clientident) AS b02 ON b02.ClientIdent = CLIENT.ClientIdent LEFT JOIN (SELECT ClientIdent,sum([ProgressBilledAmount]) AS ProgressBilledAmount FROM UVW_WIPAR03Clientident WHERE InvoiceDateTime BETWEEN '01/01/1900' AND DATEADD(d,-1,@mBegdate) GROUP BY clientident) AS b03 ON b03.ClientIdent = CLIENT.ClientIdent LEFT JOIN (Select ClientIdent,sum([ProgressApplyAmount]) AS ProgressApplyAmount FROM UVW_WIPAR04Clientident WHERE InvoiceDateTime BETWEEN '01/01/1900' AND DATEADD(d,-1,@mBegdate) GROUP BY clientident) AS b04 ON b04.ClientIdent = CLIENT.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(ISNULL(writeupdownAmount,0)) AS WriteUpDownAmount FROM UVW_WIPAR05Clientident WHERE InvoiceDateTime BETWEEN '01/01/1900' AND DATEADD(d,-1,@mBegdate) GROUP BY clientident) AS b05 ON b05.ClientIdent = CLIENT.ClientIdent /* current WIP transactions */ LEFT JOIN (SELECT Clientident ,sum([time]) as [time] ,sum([expenses]) as [expenses] FROM UVW_WIPAR01Clientident WHERE transactiondate BETWEEN @mBegdate AND @mEnddate GROUP BY clientident) AS t01 ON t01.ClientIdent = CLIENT.ClientIdent LEFT JOIN (SELECT clientident,SUM([BilledAmount]) AS [BilledAmount] FROM UVW_WIPAR02Clientident WHERE InvoiceDateTime BETWEEN @mBegdate AND @mEnddate GROUP BY clientident) AS t02 ON t02.ClientIdent = CLIENT.ClientIdent LEFT JOIN (SELECT ClientIdent,sum([ProgressBilledAmount]) AS ProgressBilledAmount FROM UVW_WIPAR03Clientident WHERE InvoiceDateTime BETWEEN @mBegdate AND @mEnddate GROUP BY clientident) AS t03 ON t03.ClientIdent = CLIENT.ClientIdent LEFT JOIN (Select ClientIdent,sum([ProgressApplyAmount]) AS ProgressApplyAmount FROM UVW_WIPAR04Clientident WHERE InvoiceDateTime BETWEEN @mBegdate AND @mEnddate GROUP BY clientident) AS t04 ON t04.ClientIdent = CLIENT.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(ISNULL(writeupdownAmount,0)) AS WriteUpDownAmount FROM UVW_WIPAR05Clientident WHERE InvoiceDateTime BETWEEN @mBegdate AND @mEnddate /* 04/11/2024 note...the "WIP/AR Reconciliation Report" has an additional line below so if they have unposted invoices, it can result in different Write Up/Dn balance */ --and InvoiceStatusCode=1 /* write up/down is only included if the invoice is posted */ GROUP BY clientident) AS t05 ON t05.ClientIdent = CLIENT.ClientIdent WHERE (CASE WHEN @mCRSTitle = 'All' THEN 1 ELSE CASE WHEN ISNULL(T00.StaffIdentifier,'0') IN (SELECT column1 FROM #tempstaff) THEN 1 ELSE 0 END END) = 1 AND ( ISNULL(b01.time,0.00) +ISNULL(b01.expenses,0.00) -ISNULL(b02.BilledAmount,0.00) -ISNULL(b03.ProgressBilledAmount,0.00) +ISNULL(b04.ProgressApplyAmount,0.00) +ISNULL(b05.WriteUpDownAmount,0.00) +ISNULL(t01.time,0.00) +ISNULL(t01.expenses,0.00)<>0 OR ISNULL(t02.BilledAmount,0.00) +ISNULL(t03.ProgressBilledAmount,0.00) -ISNULL(t04.ProgressApplyAmount,0.00) -ISNULL(t05.WriteUpDownAmount,0.00)<>0 OR ISNULL(b01.time,0.00) +ISNULL(b01.expenses,0.00) -ISNULL(b02.BilledAmount,0.00) -ISNULL(b03.ProgressBilledAmount,0.00) +ISNULL(b04.ProgressApplyAmount,0.00) +ISNULL(b05.WriteUpDownAmount,0.00) +ISNULL(t01.time,0.00) +ISNULL(t01.expenses,0.00) /* minus WIPBilled */ - (ISNULL(t02.BilledAmount,0.00) +ISNULL(t03.ProgressBilledAmount,0.00) -ISNULL(t04.ProgressApplyAmount,0.00) -ISNULL(t05.WriteUpDownAmount,0.00)) <>0 OR ISNULL(t02.BilledAmount,0.00) + ISNULL(t03.ProgressBilledAmount,0.00) - ISNULL(t04.ProgressApplyAmount,0.00)<>0 OR ISNULL(t02.BilledAmount,0.00)<>0 OR ISNULL(t05.WriteUpDownAmount,0.00)<>0) ORDER BY CRS1,CLIENT.ClientIdSubId END GO /****** Object: StoredProcedure [dbo].[USP_BillingsByState] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_BillingsByState] @mBegdate DATE, @mEnddate DATE, @mReporttype BIT = 0, /* 0=Billings 1=Payments */ @mState VARCHAR(3)='ALL' AS BEGIN SET NOCOUNT ON; SELECT CLIENT.ClientId, CLIENT.ClientSubId, CLIENT.ClientSortName, A1.AddressLine1, A1.CityName, A1.StateProvinceCode, A1.PostalCode, t1.TransactionDateTime, t1.ReferenceNumber, t1.Amount FROM CLIENT LEFT JOIN ( /* invoices */ SELECT 0 AS TransType, ClientIdent, InvoiceDateTime AS TransactionDateTime, InvoiceNumber AS ReferenceNumber, InvoiceAmount+SalesTaxAmount AS Amount FROM UVW_WIPAR06Clientident WHERE InvoiceDateTime between @mBegdate and @mEnddate UNION /* payments */ SELECT 1 AS TransType, ClientIdent, TransactionDateTime, ReferenceNumber, PaymentAmount AS Amount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime between @mBegdate and @mEnddate ) t1 ON t1.ClientIdent=CLIENT.ClientIdent OUTER APPLY (SELECT TOP 1 * FROM CLIENTADDRESS WHERE CLIENTADDRESS.ReferenceIdent = CLIENT.ClientIdent AND AddressIdentCategoryType='Client' AND MailingAddressFlag='T') A1 WHERE CASE WHEN @mState='ALL' THEN 1 ELSE CASE WHEN ISNULL(A1.StateProvinceCode,'')=@mState THEN 1 ELSE 0 END END=1 AND t1.TransType=@mReporttype ORDER BY a1.StateProvinceCode,CLIENT.ClientIdSubId,t1.TransactionDateTime END GO /****** Object: StoredProcedure [dbo].[USP_BillingWorksheetClients1] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_BillingWorksheetClients1] @mActiveBegDate DATE, @mActiveEndDate DATE, @mDeleted BIT = 0, /* include deleted */ @mCRSTitle VARCHAR(64) = 'All', /* if a specified CRS position is selected, this will contain the title (e.g. Parmary Partner, Bill Manager, etc */ @mCRSStaffIdentifierList VARCHAR(MAX) = '', /* if a specified list of CRS staff is selected, this will contain the list of selected staff to be parsed below */ @mClientOfficeName VARCHAR(64) = 'All' /* this will either be 'All' or the specific office name */ AS BEGIN /* this query is used to generate a list of clients for selection from the billing worksheet screen. per requirement from Axcess product development, the query is filtered so that it will include clients that have WIP lines, but a 0 balance note that this query is essentially identical to the WIPSummary report */ SET NOCOUNT ON; CREATE TABLE #tempstaff (column1 NVARCHAR(255)) INSERT INTO #tempstaff select * from [dbo].[UFN_String2Table](@mCRSStaffIdentifierList) SELECT DISTINCT CASE WHEN @mCRSTitle='All' THEN '' ELSE STAFF.StaffIdentifier END AS StaffIdentifier, CLIENT.ClientIdent, CLIENT.ClientIdSubId, CLIENT.ClientSortname, 0 AS StaffIdent, /* not used for most reports, but there is a custom report that needs a StaffIdent column to identify the project biller */ '' AS ReportName, /* not used for most reports, but there is a custom report that needs a ReportName column to identify the project biller */ t1.WipAvailable, t1.ProgressBills, t1.WipRemaining, t1.WipCount FROM /* this gets WIP summary totals by clientident */ (SELECT ClientIdent, SUM(WipGross - WipBilled) AS WipAvailable, SUM(ProgGross - ProgPosted) AS ProgressBills, SUM(WipGross - WipBilled - ProgGross + ProgPosted) AS WipRemaining, SUM(WipCount) AS WipCount FROM UVW_WIPSummaryClientident WHERE transactiondate BETWEEN @mActiveBegDate AND @mActiveEndDate GROUP BY clientident ) AS t1 LEFT JOIN CLIENT ON CLIENT.ClientIdent = t1.ClientIdent LEFT JOIN CLIENTCRS on CLIENTCRS.ClientIdent = CLIENT.ClientIdent LEFT JOIN STAFF on CLIENTCRS.StaffIdent = STAFF.StaffIdent WHERE (CASE WHEN @mCRSTitle = 'All' THEN 1 ELSE CASE WHEN ISNULL(STAFF.StaffIdentifier,'0') IN (SELECT column1 FROM #tempstaff) THEN 1 ELSE 0 END END) = 1 AND (CASE WHEN @mDeleted = 1 THEN 'F' ELSE CLIENT.DeleteFlag END) = 'F' AND (CASE WHEN @mClientOfficeName = 'All' THEN 1 ELSE CASE WHEN CLIENT.ClientOfficeName = @mClientOfficeName THEN 1 ELSE 0 END END) = 1 AND (t1.WipAvailable<>0 OR t1.ProgressBills<>0 OR t1.WipRemaining<>0 OR t1.wipcount<>0) ORDER BY CASE WHEN @mCRSTitle='All' THEN '' ELSE STAFF.StaffIdentifier END,ClientIdSubId END GO /****** Object: StoredProcedure [dbo].[USP_BillingWorksheetSection1] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_BillingWorksheetSection1] @mActiveBegDate AS date ,@mActiveEndDate AS date ,@mClientIdSubId AS nvarchar(129) ,@mCRSBiller AS varchar(64) = 'Default' -- this will be the firm-configured CRS title for the biller of the client ,@mCRSPPartner AS varchar(64) = 'Default' -- this will be the firm-configured CRS title for the owner of the client AS BEGIN -- this is used in some of the queries where the transaction MONTH/YEAR are used DECLARE @mHistoryYear0 AS INTEGER = YEAR(GETDATE()) - 0 DECLARE @mHistoryYear1 AS INTEGER = YEAR(GETDATE()) - 1 DECLARE @mHistoryYear2 AS INTEGER = YEAR(GETDATE()) - 2 -- current year begin/end dates DECLARE @BegDate01 AS DATE = DATEADD(yy,-0,DATEADD(yy,DATEDIFF(yy,0,GETDATE()),0)) /* returns 01-01-2019 when run in 2019 */ DECLARE @EndDate01 AS DATE = CAST(DATEADD(YEAR, DATEDIFF(YEAR, -1, GETDATE() ) - 0, -1) AS DATE) /* returns 12-31-2019 when run in 2019 */ -- prior year begin/end dates DECLARE @BegDate02 AS DATE = DATEADD(yy,-1,DATEADD(yy,DATEDIFF(yy,0,GETDATE()),0)) /* returns 01-01-2018 when run in 2019 */ DECLARE @EndDate02 AS DATE = CAST(DATEADD(YEAR, DATEDIFF(YEAR, -2, GETDATE() ) - 1, -1) AS DATE) /* returns 12-31-2018 when run in 2019 */ -- prior year 2 begin/end dates DECLARE @BegDate03 AS DATE = DATEADD(yy,-2,DATEADD(yy,DATEDIFF(yy,0,GETDATE()),0)) /* returns 01-01-2017 when run in 2019 */ DECLARE @EndDate03 AS DATE = CAST(DATEADD(YEAR, DATEDIFF(YEAR, -3, GETDATE() ) - 1, -1) AS DATE) /* returns 12-31-2017 when run in 2019 */ /* staff titles used for report filtering/printing note that this "title" can vary by firm, so i am using a customized value stored in FirmOptions where the report user has to define which firm tile is used as the primary partner and billing manager. this value does NOT come from axcess itself */ DECLARE @bmTitle AS varchar(64) IF @mCRSBiller = 'Default' -- if a title was NOT passed in for the biller, then grab the CRS title from firm options SET @bmTitle = (SELECT [value] FROM FirmOptions WHERE name = 'BMCRS') -- billing manager ELSE -- if a title was passed in for the biller, use that title SET @bmTitle = @mCRSBiller DECLARE @ppTitle AS varchar(64) IF @mCRSPPartner = 'Default' SET @ppTitle = (SELECT [value] FROM FirmOptions WHERE name = 'PPCRS') -- primary partner ELSE SET @ppTitle = @mCRSPPartner --DECLARE @ppTitle AS varchar(64) = (SELECT [value] FROM FirmOptions WHERE name = 'PPCRS') -- primary partner --DECLARE @bmTitle AS varchar(64) = (SELECT [value] FROM FirmOptions WHERE name = 'BMCRS') -- billing manager --DECLARE @spTitle AS varchar(64) = (SELECT [value] FROM FirmOptions WHERE name = 'SPCRS') -- secondary partner --DECLARE @rpTitle AS varchar(64) = (SELECT [value] FROM FirmOptions WHERE name = 'RPCRS') -- responsible person --DECLARE @mgTitle AS varchar(64) = (SELECT [value] FROM FirmOptions WHERE name = 'MGCRS') -- manager --DECLARE @trTitle AS varchar(64) = (SELECT [value] FROM FirmOptions WHERE name = 'TRCRS') -- tax reviewer --DECLARE @tpTitle AS varchar(64) = (SELECT [value] FROM FirmOptions WHERE name = 'TPCRS') -- tax preparer -- define current year date buckets DECLARE @CYDate00 AS DATE = DATEADD(mm, 0,@BegDate01) DECLARE @CYDate01 AS DATE = DATEADD(mm, 1,@BegDate01) DECLARE @CYDate02 AS DATE = DATEADD(mm, 2,@BegDate01) DECLARE @CYDate03 AS DATE = DATEADD(mm, 3,@BegDate01) DECLARE @CYDate04 AS DATE = DATEADD(mm, 4,@BegDate01) DECLARE @CYDate05 AS DATE = DATEADD(mm, 5,@BegDate01) DECLARE @CYDate06 AS DATE = DATEADD(mm, 6,@BegDate01) DECLARE @CYDate07 AS DATE = DATEADD(mm, 7,@BegDate01) DECLARE @CYDate08 AS DATE = DATEADD(mm, 8,@BegDate01) DECLARE @CYDate09 AS DATE = DATEADD(mm, 9,@BegDate01) DECLARE @CYDate10 AS DATE = DATEADD(mm,10,@BegDate01) DECLARE @CYDate11 AS DATE = DATEADD(mm,11,@BegDate01) DECLARE @CYDate12 AS DATE = DATEADD(mm,12,@BegDate01) -- previous year date buckets DECLARE @PYDate00 AS DATE = DATEADD(mm, 0,@BegDate02) DECLARE @PYDate01 AS DATE = DATEADD(mm, 1,@BegDate02) DECLARE @PYDate02 AS DATE = DATEADD(mm, 2,@BegDate02) DECLARE @PYDate03 AS DATE = DATEADD(mm, 3,@BegDate02) DECLARE @PYDate04 AS DATE = DATEADD(mm, 4,@BegDate02) DECLARE @PYDate05 AS DATE = DATEADD(mm, 5,@BegDate02) DECLARE @PYDate06 AS DATE = DATEADD(mm, 6,@BegDate02) DECLARE @PYDate07 AS DATE = DATEADD(mm, 7,@BegDate02) DECLARE @PYDate08 AS DATE = DATEADD(mm, 8,@BegDate02) DECLARE @PYDate09 AS DATE = DATEADD(mm, 9,@BegDate02) DECLARE @PYDate10 AS DATE = DATEADD(mm,10,@BegDate02) DECLARE @PYDate11 AS DATE = DATEADD(mm,11,@BegDate02) DECLARE @PYDate12 AS DATE = DATEADD(mm,12,@BegDate02) -- prior year 2 date buckets DECLARE @QYDate00 AS DATE = DATEADD(mm, 0,@BegDate03) DECLARE @QYDate01 AS DATE = DATEADD(mm, 1,@BegDate03) DECLARE @QYDate02 AS DATE = DATEADD(mm, 2,@BegDate03) DECLARE @QYDate03 AS DATE = DATEADD(mm, 3,@BegDate03) DECLARE @QYDate04 AS DATE = DATEADD(mm, 4,@BegDate03) DECLARE @QYDate05 AS DATE = DATEADD(mm, 5,@BegDate03) DECLARE @QYDate06 AS DATE = DATEADD(mm, 6,@BegDate03) DECLARE @QYDate07 AS DATE = DATEADD(mm, 7,@BegDate03) DECLARE @QYDate08 AS DATE = DATEADD(mm, 8,@BegDate03) DECLARE @QYDate09 AS DATE = DATEADD(mm, 9,@BegDate03) DECLARE @QYDate10 AS DATE = DATEADD(mm,10,@BegDate03) DECLARE @QYDate11 AS DATE = DATEADD(mm,11,@BegDate03) DECLARE @QYDate12 AS DATE = DATEADD(mm,12,@BegDate03) SELECT /* Section 1 - general client info name, status, address, etc */ section1.* /* Section 4 - current year monthly totals WIP production */ ,ISNULL(CY01WipProdAmt,0.00) AS CY01WipProdAmt ,ISNULL(CY02WipProdAmt,0.00) AS CY02WipProdAmt ,ISNULL(CY03WipProdAmt,0.00) AS CY03WipProdAmt ,ISNULL(CY04WipProdAmt,0.00) AS CY04WipProdAmt ,ISNULL(CY05WipProdAmt,0.00) AS CY05WipProdAmt ,ISNULL(CY06WipProdAmt,0.00) AS CY06WipProdAmt ,ISNULL(CY07WipProdAmt,0.00) AS CY07WipProdAmt ,ISNULL(CY08WipProdAmt,0.00) AS CY08WipProdAmt ,ISNULL(CY09WipProdAmt,0.00) AS CY09WipProdAmt ,ISNULL(CY10WipProdAmt,0.00) AS CY10WipProdAmt ,ISNULL(CY11WipProdAmt,0.00) AS CY11WipProdAmt ,ISNULL(CY12WipProdAmt,0.00) AS CY12WipProdAmt /* Section 4 - current year monthly totals invoice amount */ ,ISNULL(CY01InvAmt,0.00) AS CY01InvAmt ,ISNULL(CY02InvAmt,0.00) AS CY02InvAmt ,ISNULL(CY03InvAmt,0.00) AS CY03InvAmt ,ISNULL(CY04InvAmt,0.00) AS CY04InvAmt ,ISNULL(CY05InvAmt,0.00) AS CY05InvAmt ,ISNULL(CY06InvAmt,0.00) AS CY06InvAmt ,ISNULL(CY07InvAmt,0.00) AS CY07InvAmt ,ISNULL(CY08InvAmt,0.00) AS CY08InvAmt ,ISNULL(CY09InvAmt,0.00) AS CY09InvAmt ,ISNULL(CY10InvAmt,0.00) AS CY10InvAmt ,ISNULL(CY11InvAmt,0.00) AS CY11InvAmt ,ISNULL(CY12InvAmt,0.00) AS CY12InvAmt /* Section 4 - current year monthly totals write up/down */ ,ISNULL(CY01WriteUpDown,0.00) AS CY01WriteUpDown ,ISNULL(CY02WriteUpDown,0.00) AS CY02WriteUpDown ,ISNULL(CY03WriteUpDown,0.00) AS CY03WriteUpDown ,ISNULL(CY04WriteUpDown,0.00) AS CY04WriteUpDown ,ISNULL(CY05WriteUpDown,0.00) AS CY05WriteUpDown ,ISNULL(CY06WriteUpDown,0.00) AS CY06WriteUpDown ,ISNULL(CY07WriteUpDown,0.00) AS CY07WriteUpDown ,ISNULL(CY08WriteUpDown,0.00) AS CY08WriteUpDown ,ISNULL(CY09WriteUpDown,0.00) AS CY09WriteUpDown ,ISNULL(CY10WriteUpDown,0.00) AS CY10WriteUpDown ,ISNULL(CY11WriteUpDown,0.00) AS CY11WriteUpDown ,ISNULL(CY12WriteUpDown,0.00) AS CY12WriteUpDown /* Section 4 - prior year monthly totals WIP production */ ,ISNULL(PY01WipProdAmt,0.00) AS PY01WipProdAmt ,ISNULL(PY02WipProdAmt,0.00) AS PY02WipProdAmt ,ISNULL(PY03WipProdAmt,0.00) AS PY03WipProdAmt ,ISNULL(PY04WipProdAmt,0.00) AS PY04WipProdAmt ,ISNULL(PY05WipProdAmt,0.00) AS PY05WipProdAmt ,ISNULL(PY06WipProdAmt,0.00) AS PY06WipProdAmt ,ISNULL(PY07WipProdAmt,0.00) AS PY07WipProdAmt ,ISNULL(PY08WipProdAmt,0.00) AS PY08WipProdAmt ,ISNULL(PY09WipProdAmt,0.00) AS PY09WipProdAmt ,ISNULL(PY10WipProdAmt,0.00) AS PY10WipProdAmt ,ISNULL(PY11WipProdAmt,0.00) AS PY11WipProdAmt ,ISNULL(PY12WipProdAmt,0.00) AS PY12WipProdAmt /* Section 4 - prior year monthly totals invoice amount */ ,ISNULL(PY01InvAmt,0.00) AS PY01InvAmt ,ISNULL(PY02InvAmt,0.00) AS PY02InvAmt ,ISNULL(PY03InvAmt,0.00) AS PY03InvAmt ,ISNULL(PY04InvAmt,0.00) AS PY04InvAmt ,ISNULL(PY05InvAmt,0.00) AS PY05InvAmt ,ISNULL(PY06InvAmt,0.00) AS PY06InvAmt ,ISNULL(PY07InvAmt,0.00) AS PY07InvAmt ,ISNULL(PY08InvAmt,0.00) AS PY08InvAmt ,ISNULL(PY09InvAmt,0.00) AS PY09InvAmt ,ISNULL(PY10InvAmt,0.00) AS PY10InvAmt ,ISNULL(PY11InvAmt,0.00) AS PY11InvAmt ,ISNULL(PY12InvAmt,0.00) AS PY12InvAmt /* Section 4 - prior year monthly totals write up/down */ ,ISNULL(PY01WriteUpDown,0.00) AS PY01WriteUpDown ,ISNULL(PY02WriteUpDown,0.00) AS PY02WriteUpDown ,ISNULL(PY03WriteUpDown,0.00) AS PY03WriteUpDown ,ISNULL(PY04WriteUpDown,0.00) AS PY04WriteUpDown ,ISNULL(PY05WriteUpDown,0.00) AS PY05WriteUpDown ,ISNULL(PY06WriteUpDown,0.00) AS PY06WriteUpDown ,ISNULL(PY07WriteUpDown,0.00) AS PY07WriteUpDown ,ISNULL(PY08WriteUpDown,0.00) AS PY08WriteUpDown ,ISNULL(PY09WriteUpDown,0.00) AS PY09WriteUpDown ,ISNULL(PY10WriteUpDown,0.00) AS PY10WriteUpDown ,ISNULL(PY11WriteUpDown,0.00) AS PY11WriteUpDown ,ISNULL(PY12WriteUpDown,0.00) AS PY12WriteUpDown /* Section 4 - prior year 2 monthly totals WIP production */ ,ISNULL(QY01WipProdAmt,0.00) AS QY01WipProdAmt ,ISNULL(QY02WipProdAmt,0.00) AS QY02WipProdAmt ,ISNULL(QY03WipProdAmt,0.00) AS QY03WipProdAmt ,ISNULL(QY04WipProdAmt,0.00) AS QY04WipProdAmt ,ISNULL(QY05WipProdAmt,0.00) AS QY05WipProdAmt ,ISNULL(QY06WipProdAmt,0.00) AS QY06WipProdAmt ,ISNULL(QY07WipProdAmt,0.00) AS QY07WipProdAmt ,ISNULL(QY08WipProdAmt,0.00) AS QY08WipProdAmt ,ISNULL(QY09WipProdAmt,0.00) AS QY09WipProdAmt ,ISNULL(QY10WipProdAmt,0.00) AS QY10WipProdAmt ,ISNULL(QY11WipProdAmt,0.00) AS QY11WipProdAmt ,ISNULL(QY12WipProdAmt,0.00) AS QY12WipProdAmt /* Section 4 - prior year 2 monthly totals invoice amount */ ,ISNULL(QY01InvAmt,0.00) AS QY01InvAmt ,ISNULL(QY02InvAmt,0.00) AS QY02InvAmt ,ISNULL(QY03InvAmt,0.00) AS QY03InvAmt ,ISNULL(QY04InvAmt,0.00) AS QY04InvAmt ,ISNULL(QY05InvAmt,0.00) AS QY05InvAmt ,ISNULL(QY06InvAmt,0.00) AS QY06InvAmt ,ISNULL(QY07InvAmt,0.00) AS QY07InvAmt ,ISNULL(QY08InvAmt,0.00) AS QY08InvAmt ,ISNULL(QY09InvAmt,0.00) AS QY09InvAmt ,ISNULL(QY10InvAmt,0.00) AS QY10InvAmt ,ISNULL(QY11InvAmt,0.00) AS QY11InvAmt ,ISNULL(QY12InvAmt,0.00) AS QY12InvAmt /* Section 4 - prior year 2 monthly totals write up/down */ ,ISNULL(QY01WriteUpDown,0.00) AS QY01WriteUpDown ,ISNULL(QY02WriteUpDown,0.00) AS QY02WriteUpDown ,ISNULL(QY03WriteUpDown,0.00) AS QY03WriteUpDown ,ISNULL(QY04WriteUpDown,0.00) AS QY04WriteUpDown ,ISNULL(QY05WriteUpDown,0.00) AS QY05WriteUpDown ,ISNULL(QY06WriteUpDown,0.00) AS QY06WriteUpDown ,ISNULL(QY07WriteUpDown,0.00) AS QY07WriteUpDown ,ISNULL(QY08WriteUpDown,0.00) AS QY08WriteUpDown ,ISNULL(QY09WriteUpDown,0.00) AS QY09WriteUpDown ,ISNULL(QY10WriteUpDown,0.00) AS QY10WriteUpDown ,ISNULL(QY11WriteUpDown,0.00) AS QY11WriteUpDown ,ISNULL(QY12WriteUpDown,0.00) AS QY12WriteUpDown /* Section 6 - current year monthly totals AR Payments */ ,ISNULL(Section6_01.PaymentAmount,0.00) AS CY01PmtsSum ,ISNULL(Section6_02.PaymentAmount,0.00) AS CY02PmtsSum ,ISNULL(Section6_03.PaymentAmount,0.00) AS CY03PmtsSum ,ISNULL(Section6_04.PaymentAmount,0.00) AS CY04PmtsSum ,ISNULL(Section6_05.PaymentAmount,0.00) AS CY05PmtsSum ,ISNULL(Section6_06.PaymentAmount,0.00) AS CY06PmtsSum ,ISNULL(Section6_07.PaymentAmount,0.00) AS CY07PmtsSum ,ISNULL(Section6_08.PaymentAmount,0.00) AS CY08PmtsSum ,ISNULL(Section6_09.PaymentAmount,0.00) AS CY09PmtsSum ,ISNULL(Section6_10.PaymentAmount,0.00) AS CY10PmtsSum ,ISNULL(Section6_11.PaymentAmount,0.00) AS CY11PmtsSum ,ISNULL(Section6_12.PaymentAmount,0.00) AS CY12PmtsSum /* Section 6 - prior year monthly totals AR Payments */ ,ISNULL(Section6_13.PaymentAmount,0.00) AS PY01PmtsSum ,ISNULL(Section6_14.PaymentAmount,0.00) AS PY02PmtsSum ,ISNULL(Section6_15.PaymentAmount,0.00) AS PY03PmtsSum ,ISNULL(Section6_16.PaymentAmount,0.00) AS PY04PmtsSum ,ISNULL(Section6_17.PaymentAmount,0.00) AS PY05PmtsSum ,ISNULL(Section6_18.PaymentAmount,0.00) AS PY06PmtsSum ,ISNULL(Section6_19.PaymentAmount,0.00) AS PY07PmtsSum ,ISNULL(Section6_20.PaymentAmount,0.00) AS PY08PmtsSum ,ISNULL(Section6_21.PaymentAmount,0.00) AS PY09PmtsSum ,ISNULL(Section6_22.PaymentAmount,0.00) AS PY10PmtsSum ,ISNULL(Section6_23.PaymentAmount,0.00) AS PY11PmtsSum ,ISNULL(Section6_24.PaymentAmount,0.00) AS PY12PmtsSum /* Section 6 - prior year 2 monthly totals AR Payments */ ,ISNULL(Section6_25.PaymentAmount,0.00) AS QY01PmtsSum ,ISNULL(Section6_26.PaymentAmount,0.00) AS QY02PmtsSum ,ISNULL(Section6_27.PaymentAmount,0.00) AS QY03PmtsSum ,ISNULL(Section6_28.PaymentAmount,0.00) AS QY04PmtsSum ,ISNULL(Section6_29.PaymentAmount,0.00) AS QY05PmtsSum ,ISNULL(Section6_30.PaymentAmount,0.00) AS QY06PmtsSum ,ISNULL(Section6_31.PaymentAmount,0.00) AS QY07PmtsSum ,ISNULL(Section6_32.PaymentAmount,0.00) AS QY08PmtsSum ,ISNULL(Section6_33.PaymentAmount,0.00) AS QY09PmtsSum ,ISNULL(Section6_34.PaymentAmount,0.00) AS QY10PmtsSum ,ISNULL(Section6_35.PaymentAmount,0.00) AS QY11PmtsSum ,ISNULL(Section6_36.PaymentAmount,0.00) AS QY12PmtsSum /* Section 7 - accounts receivable balance */ ,ISNULL(Section701.InvoiceAmount,0.00) + ISNULL(Section702.Wipar07Amount,0.00) + ISNULL(Section703.Charges,0.00) - ISNULL(Section704.PaymentAmount,0.00) AS ARBalance FROM /* start section 1 */ (SELECT CLIENT.ClientIdent ,CLIENT.ClientIdSubId ,CLIENT.ClientSortName ,CLIENT.ClientStatus ,CLIENTADDRESS.AddressLine1 ,CLIENTADDRESS.AddressLine2 ,CLIENTADDRESS.AddressLine3 ,CLIENTADDRESS.CityName ,CLIENTADDRESS.StateProvinceCode ,CLIENTADDRESS.PostalCode ,CLIENTPHONE.PhoneNumber ,ISNULL(Section1T1.ReportName, ' No Selection') AS PrimaryPartner --,Section1T2.ManagerIdent AS ManagerIdent ,ISNULL(Section1T2.ReportName, ' No Selection') AS Manager /* convert data such as 0130 to 'january' where 01 is the number representing the month of fiscal year end. */ ,DATENAME(month, DATEADD(month, LEFT(RIGHT('0000' + CAST(CLIENT.FiscalPeriod as varchar), 4), 2)-1, CAST('2008-01-01' AS datetime))) AS ClientFyEnd ,ISNULL(Section1T3.WipAvailable,0) AS WipRemaining ,ISNULL(Section1T3.ProgressBills, 0) AS Progress ,ISNULL(Section1T3.WipRemaining, 0) AS NetWIP ,CONVERT(VARCHAR(10), Section1T4.InvoiceDateTime, 101) AS LastInvoiceDate ,ISNULL(Section1T5.ClientGroupName, ' No Selection') AS ClientGroupName FROM CLIENT LEFT JOIN /* client primary address */ CLIENTADDRESS ON CLIENT.ClientIdent = CLIENTADDRESS.ReferenceIdent AND PrimaryAddressFlag = 'T' LEFT JOIN /* client primary phone */ CLIENTPHONE ON CLIENT.ClientIdent = CLIENTPHONE.ReferenceIdent AND CLIENTPHONE.PrimaryPhoneFlag = 'T' LEFT JOIN ( /* client primary partner */ SELECT clientident,STAFF.ReportName FROM CLIENTCRS INNER JOIN STAFF ON CLIENTCRS.StaffIdent = STAFF.StaffIdent WHERE FirmClientStaffAssignmentName = @ppTitle ) Section1T1 on CLIENT.ClientIdent = Section1T1.ClientIdent LEFT JOIN /* client billing manager */ (SELECT clientident,STAFF.ReportName FROM CLIENTCRS INNER JOIN STAFF ON CLIENTCRS.StaffIdent = STAFF.StaffIdent WHERE FirmClientStaffAssignmentName = @bmTitle ) Section1T2 on CLIENT.ClientIdent = Section1T2.ClientIdent LEFT JOIN /* get wip available, progress, and wip remaining by client note....this is the SAME sub-query used in the the WIP Summary report */ (SELECT ClientIdent, SUM(WipGross - WipBilled) AS WipAvailable, SUM(ProgGross - ProgPosted) AS ProgressBills, SUM(WipGross - WipBilled - ProgGross + ProgPosted) AS WipRemaining, SUM(WipCount) AS WipCount FROM UVW_WIPSummaryClientident WHERE transactiondate BETWEEN @mActiveBegDate AND @mActiveEndDate GROUP BY clientident ) AS Section1T3 on CLIENT.ClientIdent = Section1T3.ClientIdent OUTER APPLY /* last invoice date */ (SELECT TOP 1 ClientIdent, InvoiceDateTime FROM INVOICE WHERE INVOICE.ClientIdent = CLIENT.ClientIdent ORDER BY InvoiceDateTime DESC ) AS Section1T4 /* Financial Reporting Group / Billing Group */ OUTER APPLY (SELECT TOP 1 ClientGroupName FROM CLIENTGROUP WHERE ClientIdent = CLIENT.ClientIdent AND FinancialReportingGroupFlag = 'T' ) Section1T5 WHERE CLIENT.DeleteFlag = 'F' ) AS Section1 LEFT JOIN /* section 4 current/prior production totals by component */ (SELECT wip.ClientIdent AS Section4ClientIdent /* current year production amounts */ /* bug 198232 production amounts are doubling where WIP is billed, and the Invoice is reversed, so I added a test for the invoice StatusCode <> 3 */ ,SUM(CASE WHEN TransactionDate >= @CYDate00 AND TransactionDate < @CYDate01 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS CY01WipProdAmt ,SUM(CASE WHEN TransactionDate >= @CYDate01 AND TransactionDate < @CYDate02 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS CY02WipProdAmt ,SUM(CASE WHEN TransactionDate >= @CYDate02 AND TransactionDate < @CYDate03 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS CY03WipProdAmt ,SUM(CASE WHEN TransactionDate >= @CYDate03 AND TransactionDate < @CYDate04 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS CY04WipProdAmt ,SUM(CASE WHEN TransactionDate >= @CYDate04 AND TransactionDate < @CYDate05 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS CY05WipProdAmt ,SUM(CASE WHEN TransactionDate >= @CYDate05 AND TransactionDate < @CYDate06 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS CY06WipProdAmt ,SUM(CASE WHEN TransactionDate >= @CYDate06 AND TransactionDate < @CYDate07 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS CY07WipProdAmt ,SUM(CASE WHEN TransactionDate >= @CYDate07 AND TransactionDate < @CYDate08 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS CY08WipProdAmt ,SUM(CASE WHEN TransactionDate >= @CYDate08 AND TransactionDate < @CYDate09 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS CY09WipProdAmt ,SUM(CASE WHEN TransactionDate >= @CYDate09 AND TransactionDate < @CYDate10 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS CY10WipProdAmt ,SUM(CASE WHEN TransactionDate >= @CYDate10 AND TransactionDate < @CYDate11 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS CY11WipProdAmt ,SUM(CASE WHEN TransactionDate >= @CYDate11 AND TransactionDate < @CYDate12 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS CY12WipProdAmt /* previous year production amounts */ ,SUM(CASE WHEN TransactionDate >= @PYDate00 AND TransactionDate < @PYDate01 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS PY01WipProdAmt ,SUM(CASE WHEN TransactionDate >= @PYDate01 AND TransactionDate < @PYDate02 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS PY02WipProdAmt ,SUM(CASE WHEN TransactionDate >= @PYDate02 AND TransactionDate < @PYDate03 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS PY03WipProdAmt ,SUM(CASE WHEN TransactionDate >= @PYDate03 AND TransactionDate < @PYDate04 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS PY04WipProdAmt ,SUM(CASE WHEN TransactionDate >= @PYDate04 AND TransactionDate < @PYDate05 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS PY05WipProdAmt ,SUM(CASE WHEN TransactionDate >= @PYDate05 AND TransactionDate < @PYDate06 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS PY06WipProdAmt ,SUM(CASE WHEN TransactionDate >= @PYDate06 AND TransactionDate < @PYDate07 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS PY07WipProdAmt ,SUM(CASE WHEN TransactionDate >= @PYDate07 AND TransactionDate < @PYDate08 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS PY08WipProdAmt ,SUM(CASE WHEN TransactionDate >= @PYDate08 AND TransactionDate < @PYDate09 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS PY09WipProdAmt ,SUM(CASE WHEN TransactionDate >= @PYDate09 AND TransactionDate < @PYDate10 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS PY10WipProdAmt ,SUM(CASE WHEN TransactionDate >= @PYDate10 AND TransactionDate < @PYDate11 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS PY11WipProdAmt ,SUM(CASE WHEN TransactionDate >= @PYDate11 AND TransactionDate < @PYDate12 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS PY12WipProdAmt /* previous year 2 production amounts */ ,SUM(CASE WHEN TransactionDate >= @QYDate00 AND TransactionDate < @QYDate01 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS QY01WipProdAmt ,SUM(CASE WHEN TransactionDate >= @QYDate01 AND TransactionDate < @QYDate02 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS QY02WipProdAmt ,SUM(CASE WHEN TransactionDate >= @QYDate02 AND TransactionDate < @QYDate03 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS QY03WipProdAmt ,SUM(CASE WHEN TransactionDate >= @QYDate03 AND TransactionDate < @QYDate04 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS QY04WipProdAmt ,SUM(CASE WHEN TransactionDate >= @QYDate04 AND TransactionDate < @QYDate05 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS QY05WipProdAmt ,SUM(CASE WHEN TransactionDate >= @QYDate05 AND TransactionDate < @QYDate06 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS QY06WipProdAmt ,SUM(CASE WHEN TransactionDate >= @QYDate06 AND TransactionDate < @QYDate07 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS QY07WipProdAmt ,SUM(CASE WHEN TransactionDate >= @QYDate07 AND TransactionDate < @QYDate08 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS QY08WipProdAmt ,SUM(CASE WHEN TransactionDate >= @QYDate08 AND TransactionDate < @QYDate09 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS QY09WipProdAmt ,SUM(CASE WHEN TransactionDate >= @QYDate09 AND TransactionDate < @QYDate10 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS QY10WipProdAmt ,SUM(CASE WHEN TransactionDate >= @QYDate10 AND TransactionDate < @QYDate11 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS QY11WipProdAmt ,SUM(CASE WHEN TransactionDate >= @QYDate11 AND TransactionDate < @QYDate12 AND WIPTypeCode <> 3 AND ISNULL(INVOICE2.StatusCode,0) <> 3 THEN AdjAmount ELSE 0 END) AS QY12WipProdAmt /* current year invoice amounts */ /* bug 198232 invoice amounts are including billed amounts where invoice is reversed, so I added a test for the invoice StatusCode <> 3 */ ,SUM(CASE /*--only wip lines with invoices WITHOUT PROGRESS */ WHEN (MONTH(INVOICE2.InvoiceDateTime)= 1 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear0 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate01 AND @EndDate01) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount /*--ONLY applied progress */ WHEN (MONTH(INVOICE2.InvoiceDateTime)= 1 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount /*--ONLY progress that has not been applied */ WHEN (MONTH(INVOICE1.InvoiceDateTime)= 1 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount /*--ONLY progress that has not been invoiced nor applied */ WHEN (MONTH(INVOICE1.InvoiceDateTime)= 1 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS CY01InvAmt ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)= 2 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear0 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate01 AND @EndDate01) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)= 2 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 2 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 2 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS CY02InvAmt ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)= 3 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear0 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate01 AND @EndDate01) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)= 3 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 3 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 3 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS CY03InvAmt ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)= 4 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear0 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate01 AND @EndDate01) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)= 4 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 4 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 4 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS CY04InvAmt ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)= 5 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear0 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate01 AND @EndDate01) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)= 5 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 5 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 5 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS CY05InvAmt ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)= 6 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear0 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate01 AND @EndDate01) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)= 6 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 6 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 6 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS CY06InvAmt ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)= 7 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear0 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate01 AND @EndDate01) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)= 7 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 7 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 7 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS CY07InvAmt ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)= 8 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear0 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate01 AND @EndDate01) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)= 8 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 8 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 8 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS CY08InvAmt ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)= 9 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear0 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate01 AND @EndDate01) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)= 9 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 9 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 9 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS CY09InvAmt ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)=10 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear0 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate01 AND @EndDate01) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)=10 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)=10 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)=10 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS CY10InvAmt ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)=11 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear0 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate01 AND @EndDate01) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)=11 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)=11 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)=11 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS CY11InvAmt ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)=12 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear0 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate01 AND @EndDate01) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)=12 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)=12 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)=12 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear0 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS CY12InvAmt /* previous year invoice amounts */ ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)= 1 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear1 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate02 AND @EndDate02) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)= 1 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 1 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 1 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS PY01InvAmt ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)= 2 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear1 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate02 AND @EndDate02) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)= 2 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 2 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 2 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS PY02InvAmt ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)= 3 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear1 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate02 AND @EndDate02) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)= 3 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 3 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 3 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS PY03InvAmt ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)= 4 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear1 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate02 AND @EndDate02) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)= 4 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 4 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 4 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS PY04InvAmt ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)= 5 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear1 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate02 AND @EndDate02) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)= 5 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 5 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 5 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS PY05InvAmt ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)= 6 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear1 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate02 AND @EndDate02) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)= 6 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 6 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 6 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS PY06InvAmt ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)= 7 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear1 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate02 AND @EndDate02) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)= 7 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 7 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 7 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS PY07InvAmt ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)= 8 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear1 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate02 AND @EndDate02) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)= 8 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 8 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 8 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS PY08InvAmt ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)= 9 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear1 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate02 AND @EndDate02) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)= 9 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 9 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 9 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS PY09InvAmt ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)=10 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear1 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate02 AND @EndDate02) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)=10 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)=10 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)=10 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS PY10InvAmt ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)=11 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear1 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate02 AND @EndDate02) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)=11 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)=11 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)=11 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS PY11InvAmt ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)=12 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear1 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate02 AND @EndDate02) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)=12 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)=12 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)=12 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear1 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS PY12InvAmt /* previous year 2 invoice amounts */ ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)= 1 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear2 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate03 AND @EndDate03) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)= 1 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 1 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 1 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS QY01InvAmt ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)= 2 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear2 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate03 AND @EndDate03) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)= 2 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 2 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 2 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS QY02InvAmt ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)= 3 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear2 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate03 AND @EndDate03) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)= 3 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 3 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 3 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS QY03InvAmt ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)= 4 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear2 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate03 AND @EndDate03) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)= 4 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 4 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 4 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS QY04InvAmt ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)= 5 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear2 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate03 AND @EndDate03) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)= 5 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 5 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 5 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS QY05InvAmt ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)= 6 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear2 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate03 AND @EndDate03) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)= 6 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 6 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 6 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS QY06InvAmt ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)= 7 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear2 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate03 AND @EndDate03) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)= 7 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 7 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 7 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS QY07InvAmt ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)= 8 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear2 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate03 AND @EndDate03) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)= 8 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 8 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 8 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS QY08InvAmt ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)= 9 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear2 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate03 AND @EndDate03) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)= 9 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 9 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)= 9 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS QY09InvAmt ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)=10 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear2 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate03 AND @EndDate03) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)=10 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)=10 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)=10 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS QY10InvAmt ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)=11 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear2 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate03 AND @EndDate03) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)=11 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)=11 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)=11 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS QY11InvAmt ,SUM(CASE WHEN (MONTH(INVOICE2.InvoiceDateTime)=12 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear2 AND (INVOICE2.InvoiceDateTime BETWEEN @BegDate03 AND @EndDate03) AND ISNULL(INVOICE2.StatusCode,0) <> 3 AND wip.ProgressInvIntIdent IS NULL) THEN BilledAmount WHEN (MONTH(INVOICE2.InvoiceDateTime)=12 AND YEAR(INVOICE2.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL AND INVOICE2.ProgressApplyAmount <> 0) THEN -BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)=12 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NOT NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount WHEN (MONTH(INVOICE1.InvoiceDateTime)=12 AND YEAR(INVOICE1.InvoiceDateTime) = @mHistoryYear2 AND WipTypeCode = 3 AND wip.InvoiceIdent IS NULL AND wip.ProgressInvIntIdent IS NOT NULL) THEN BilledAmount ELSE 0 END) AS QY12InvAmt /* current year write up-down amounts */ ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @CYDate00 and INVOICE2.InvoiceDateTime < @CYDate01 THEN BilledAmount - AdjAmount ELSE 0 END) as CY01WriteUpDown ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @CYDate01 and INVOICE2.InvoiceDateTime < @CYDate02 THEN BilledAmount - AdjAmount ELSE 0 END) as CY02WriteUpDown ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @CYDate02 and INVOICE2.InvoiceDateTime < @CYDate03 THEN BilledAmount - AdjAmount ELSE 0 END) as CY03WriteUpDown ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @CYDate03 and INVOICE2.InvoiceDateTime < @CYDate04 THEN BilledAmount - AdjAmount ELSE 0 END) as CY04WriteUpDown ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @CYDate04 and INVOICE2.InvoiceDateTime < @CYDate05 THEN BilledAmount - AdjAmount ELSE 0 END) as CY05WriteUpDown ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @CYDate05 and INVOICE2.InvoiceDateTime < @CYDate06 THEN BilledAmount - AdjAmount ELSE 0 END) as CY06WriteUpDown ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @CYDate06 and INVOICE2.InvoiceDateTime < @CYDate07 THEN BilledAmount - AdjAmount ELSE 0 END) as CY07WriteUpDown ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @CYDate07 and INVOICE2.InvoiceDateTime < @CYDate08 THEN BilledAmount - AdjAmount ELSE 0 END) as CY08WriteUpDown ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @CYDate08 and INVOICE2.InvoiceDateTime < @CYDate09 THEN BilledAmount - AdjAmount ELSE 0 END) as CY09WriteUpDown ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @CYDate09 and INVOICE2.InvoiceDateTime < @CYDate10 THEN BilledAmount - AdjAmount ELSE 0 END) as CY10WriteUpDown ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @CYDate10 and INVOICE2.InvoiceDateTime < @CYDate11 THEN BilledAmount - AdjAmount ELSE 0 END) as CY11WriteUpDown ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @CYDate11 and INVOICE2.InvoiceDateTime < @CYDate12 THEN BilledAmount - AdjAmount ELSE 0 END) as CY12WriteUpDown /* previous year write up-down amounts */ ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @PYDate00 and INVOICE2.InvoiceDateTime < @PYDate01 THEN BilledAmount - AdjAmount ELSE 0 END) as PY01WriteUpDown ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @PYDate01 and INVOICE2.InvoiceDateTime < @PYDate02 THEN BilledAmount - AdjAmount ELSE 0 END) as PY02WriteUpDown ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @PYDate02 and INVOICE2.InvoiceDateTime < @PYDate03 THEN BilledAmount - AdjAmount ELSE 0 END) as PY03WriteUpDown ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @PYDate03 and INVOICE2.InvoiceDateTime < @PYDate04 THEN BilledAmount - AdjAmount ELSE 0 END) as PY04WriteUpDown ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @PYDate04 and INVOICE2.InvoiceDateTime < @PYDate05 THEN BilledAmount - AdjAmount ELSE 0 END) as PY05WriteUpDown ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @PYDate05 and INVOICE2.InvoiceDateTime < @PYDate06 THEN BilledAmount - AdjAmount ELSE 0 END) as PY06WriteUpDown ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @PYDate06 and INVOICE2.InvoiceDateTime < @PYDate07 THEN BilledAmount - AdjAmount ELSE 0 END) as PY07WriteUpDown ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @PYDate07 and INVOICE2.InvoiceDateTime < @PYDate08 THEN BilledAmount - AdjAmount ELSE 0 END) as PY08WriteUpDown ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @PYDate08 and INVOICE2.InvoiceDateTime < @PYDate09 THEN BilledAmount - AdjAmount ELSE 0 END) as PY09WriteUpDown ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @PYDate09 and INVOICE2.InvoiceDateTime < @PYDate10 THEN BilledAmount - AdjAmount ELSE 0 END) as PY10WriteUpDown ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @PYDate10 and INVOICE2.InvoiceDateTime < @PYDate11 THEN BilledAmount - AdjAmount ELSE 0 END) as PY11WriteUpDown ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @PYDate11 and INVOICE2.InvoiceDateTime < @PYDate12 THEN BilledAmount - AdjAmount ELSE 0 END) as PY12WriteUpDown /* previous year 2 write up-down amounts */ ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @QYDate00 and INVOICE2.InvoiceDateTime < @QYDate01 THEN BilledAmount - AdjAmount ELSE 0 END) as QY01WriteUpDown ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @QYDate01 and INVOICE2.InvoiceDateTime < @QYDate02 THEN BilledAmount - AdjAmount ELSE 0 END) as QY02WriteUpDown ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @QYDate02 and INVOICE2.InvoiceDateTime < @QYDate03 THEN BilledAmount - AdjAmount ELSE 0 END) as QY03WriteUpDown ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @QYDate03 and INVOICE2.InvoiceDateTime < @QYDate04 THEN BilledAmount - AdjAmount ELSE 0 END) as QY04WriteUpDown ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @QYDate04 and INVOICE2.InvoiceDateTime < @QYDate05 THEN BilledAmount - AdjAmount ELSE 0 END) as QY05WriteUpDown ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @QYDate05 and INVOICE2.InvoiceDateTime < @QYDate06 THEN BilledAmount - AdjAmount ELSE 0 END) as QY06WriteUpDown ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @QYDate06 and INVOICE2.InvoiceDateTime < @QYDate07 THEN BilledAmount - AdjAmount ELSE 0 END) as QY07WriteUpDown ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @QYDate07 and INVOICE2.InvoiceDateTime < @QYDate08 THEN BilledAmount - AdjAmount ELSE 0 END) as QY08WriteUpDown ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @QYDate08 and INVOICE2.InvoiceDateTime < @QYDate09 THEN BilledAmount - AdjAmount ELSE 0 END) as QY09WriteUpDown ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @QYDate09 and INVOICE2.InvoiceDateTime < @QYDate10 THEN BilledAmount - AdjAmount ELSE 0 END) as QY10WriteUpDown ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @QYDate10 and INVOICE2.InvoiceDateTime < @QYDate11 THEN BilledAmount - AdjAmount ELSE 0 END) as QY11WriteUpDown ,SUM(CASE WHEN wip.InvoiceIdent IS NOT NULL and INVOICE2.InvoiceDateTime >= @QYDate11 and INVOICE2.InvoiceDateTime < @QYDate12 THEN BilledAmount - AdjAmount ELSE 0 END) as QY12WriteUpDown FROM WIP LEFT JOIN INVOICE as INVOICE1 ON wip.ProgressInvIntIdent = INVOICE1.InvoiceIdent LEFT JOIN INVOICE as INVOICE2 ON wip.InvoiceIdent = INVOICE2.InvoiceIdent WHERE IsBillableFlag = 1 AND TEStatusCode = 3 /* bug 198547 - added because reports were including unposted WIP */ GROUP BY wip.ClientIdent ) As Section4 on Section1.ClientIdent = Section4.Section4ClientIdent /* monthly AR payments totals */ LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @CYDate00 AND @CYDate01 GROUP BY clientident) AS Section6_01 ON Section1.ClientIdent = Section6_01.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @CYDate01 AND @CYDate02 GROUP BY clientident) AS Section6_02 ON Section1.ClientIdent = Section6_02.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @CYDate02 AND @CYDate03 GROUP BY clientident) AS Section6_03 ON Section1.ClientIdent = Section6_03.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @CYDate03 AND @CYDate04 GROUP BY clientident) AS Section6_04 ON Section1.ClientIdent = Section6_04.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @CYDate04 AND @CYDate05 GROUP BY clientident) AS Section6_05 ON Section1.ClientIdent = Section6_05.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @CYDate05 AND @CYDate06 GROUP BY clientident) AS Section6_06 ON Section1.ClientIdent = Section6_06.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @CYDate06 AND @CYDate07 GROUP BY clientident) AS Section6_07 ON Section1.ClientIdent = Section6_07.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @CYDate07 AND @CYDate08 GROUP BY clientident) AS Section6_08 ON Section1.ClientIdent = Section6_08.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @CYDate08 AND @CYDate09 GROUP BY clientident) AS Section6_09 ON Section1.ClientIdent = Section6_09.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @CYDate09 AND @CYDate10 GROUP BY clientident) AS Section6_10 ON Section1.ClientIdent = Section6_10.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @CYDate10 AND @CYDate11 GROUP BY clientident) AS Section6_11 ON Section1.ClientIdent = Section6_11.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @CYDate11 AND @CYDate12 GROUP BY clientident) AS Section6_12 ON Section1.ClientIdent = Section6_12.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @PYDate00 AND @PYDate01 GROUP BY clientident) AS Section6_13 ON Section1.ClientIdent = Section6_13.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @PYDate01 AND @PYDate02 GROUP BY clientident) AS Section6_14 ON Section1.ClientIdent = Section6_14.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @PYDate02 AND @PYDate03 GROUP BY clientident) AS Section6_15 ON Section1.ClientIdent = Section6_15.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @PYDate03 AND @PYDate04 GROUP BY clientident) AS Section6_16 ON Section1.ClientIdent = Section6_16.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @PYDate04 AND @PYDate05 GROUP BY clientident) AS Section6_17 ON Section1.ClientIdent = Section6_17.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @PYDate05 AND @PYDate06 GROUP BY clientident) AS Section6_18 ON Section1.ClientIdent = Section6_18.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @PYDate06 AND @PYDate07 GROUP BY clientident) AS Section6_19 ON Section1.ClientIdent = Section6_19.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @PYDate07 AND @PYDate08 GROUP BY clientident) AS Section6_20 ON Section1.ClientIdent = Section6_20.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @PYDate08 AND @PYDate09 GROUP BY clientident) AS Section6_21 ON Section1.ClientIdent = Section6_21.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @PYDate09 AND @PYDate10 GROUP BY clientident) AS Section6_22 ON Section1.ClientIdent = Section6_22.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @PYDate10 AND @PYDate11 GROUP BY clientident) AS Section6_23 ON Section1.ClientIdent = Section6_23.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @PYDate11 AND @PYDate12 GROUP BY clientident) AS Section6_24 ON Section1.ClientIdent = Section6_24.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @QYDate00 AND @QYDate01 GROUP BY clientident) AS Section6_25 ON Section1.ClientIdent = Section6_25.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @QYDate01 AND @QYDate02 GROUP BY clientident) AS Section6_26 ON Section1.ClientIdent = Section6_26.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @QYDate02 AND @QYDate03 GROUP BY clientident) AS Section6_27 ON Section1.ClientIdent = Section6_27.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @QYDate03 AND @QYDate04 GROUP BY clientident) AS Section6_28 ON Section1.ClientIdent = Section6_28.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @QYDate04 AND @QYDate05 GROUP BY clientident) AS Section6_29 ON Section1.ClientIdent = Section6_29.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @QYDate05 AND @QYDate06 GROUP BY clientident) AS Section6_30 ON Section1.ClientIdent = Section6_30.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @QYDate06 AND @QYDate07 GROUP BY clientident) AS Section6_31 ON Section1.ClientIdent = Section6_31.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @QYDate07 AND @QYDate08 GROUP BY clientident) AS Section6_32 ON Section1.ClientIdent = Section6_32.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @QYDate08 AND @QYDate09 GROUP BY clientident) AS Section6_33 ON Section1.ClientIdent = Section6_33.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @QYDate09 AND @QYDate10 GROUP BY clientident) AS Section6_34 ON Section1.ClientIdent = Section6_34.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @QYDate10 AND @QYDate11 GROUP BY clientident) AS Section6_35 ON Section1.ClientIdent = Section6_35.ClientIdent LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @QYDate11 AND @QYDate12 GROUP BY clientident) AS Section6_36 ON Section1.ClientIdent = Section6_36.ClientIdent /* total AR invoice by client */ LEFT JOIN (SELECT ClientIdent,SUM(InvoiceAmount+SalesTaxAmount) AS InvoiceAmount FROM UVW_WIPAR06Clientident WHERE InvoiceDateTime <= @mActiveEndDate GROUP BY ClientIdent) as Section701 ON Section1.Clientident = Section701.ClientIdent /* ar write-offs and adjustments */ LEFT JOIN (SELECT ClientIdent,SUM(CreditAmount+Adjustment1Amount+Amount4+Amount5+DebitAmount+Adjustment2Amount) AS Wipar07Amount FROM UVW_WIPAR07Clientident WHERE transactiondatetime <= @mActiveEndDate GROUP BY ClientIdent) as Section702 ON Section1.Clientident = Section702.ClientIdent /* ar fin chg */ LEFT JOIN (SELECT ClientIdent,sum(Charges) as [Charges] from UVW_WIPAR08Clientident where TransactionDateTime <= @mActiveEndDate GROUP BY Clientident) as Section703 ON Section1.Clientident = Section703.ClientIdent /* ar payments */ LEFT JOIN (SELECT ClientIdent,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime <= @mActiveEndDate GROUP BY clientident) AS Section704 ON Section1.Clientident = Section704.Clientident WHERE Section1.ClientIdSubId = @mClientIdSubId ORDER BY [ClientIdSubId] END GO /****** Object: StoredProcedure [dbo].[USP_BillingWorksheetSection2] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_BillingWorksheetSection2] @mActiveBegDate AS date ,@mActiveEndDate AS date ,@mClientIdSubId AS nvarchar(129) ,@mPrimarywipsortfield AS varchar(16) /* this can either be CategoryID or ProjectName */ AS BEGIN DECLARE @mUnassigned AS CHAR(11) = ' Unassigned' --section 2 - WIP detail section SELECT convert(varchar(24),WIP.[ClientIdent]) AS ClientIdent ,CASE WHEN @mPrimarywipsortfield = 'ProjectName' THEN CASE WHEN LEN(ISNULL([INTERIMWORKINGPROJECT].ProjectCode, @mUnassigned))=0 THEN @mUnassigned ELSE ISNULL([INTERIMWORKINGPROJECT].ProjectCode, @mUnassigned) END ELSE CASE WHEN LEN(ISNULL(SERVICECODE.CategoryID, @mUnassigned))=0 THEN @mUnassigned ELSE ISNULL(SERVICECODE.CategoryID, @mUnassigned) END END AS PrimarySortKey ,ISNULL(INTERIMWORKINGPROJECT.ProjectName,@mUnassigned) AS ProjectName ,SERVICECODE.ServiceCodeID ,SERVICECODE.ServiceCodeName ,CASE WHEN LEN(ISNULL(SERVICECODE.CategoryID, @mUnassigned))=0 THEN @mUnassigned ELSE ISNULL(SERVICECODE.CategoryID, @mUnassigned) END AS CategoryID ,CASE WHEN LEN(ISNULL(SERVICECODE.SubCategoryId, @mUnassigned))=0 THEN @mUnassigned ELSE ISNULL(SERVICECODE.SubCategoryId, @mUnassigned) END AS SubCategoryID ,ISNULL(SERVICECODE.ServiceCodeName + ' (' + SERVICECODE.ServiceCodeID + ')', @mUnassigned) AS ServiceCodeDetail ,ISNULL([INTERIMWORKINGPROJECTWORKSTEP].WorkStepCode,'') AS WorkStepCode ,ISNULL([INTERIMWORKINGPROJECTWORKSTEP].WorkStepName,'') AS WorkStepName ,ISNULL(STAFF.StaffLastName + ', ' + STAFF.StaffFirstName, 'No Staff Name') AS StaffLastFirst ,WIP.TransactionDate /* bug 198527 added new. not needed on the report per se, but might need this info to make certain fields blank if the service code is an expense/reimbursable expense */ ,SERVICECODE.ServiceCodeTypeFlag /* bug 198527 - for expense item (type=2), the report should show a 0 rate bug 201655 - for reimbursable Expense item (type=3), the report should show the rate as entered (same as time) */ ,CASE SERVICECODE.ServiceCodeTypeFlag WHEN 1 THEN WIP.[AdjRate] /* time */ WHEN 2 THEN 0 /* expense */ WHEN 3 THEN WIP.[AdjRate] /* reimbursable expense */ ELSE 0 /* this is a catch-all, but should never happen */ END AS [AdjRate] /* bug 198527 - for expense/reimbursable expense, the report should have a 0 hours AND the field should be blank */ ,CASE SERVICECODE.ServiceCodeTypeFlag WHEN 1 THEN WIP.[Hours] /* time */ WHEN 2 THEN 0 /* expense */ WHEN 3 THEN 0 /* reimbursable expense */ ELSE 0 /* this is a catch-all, but should never happen */ END AS [Hours] ,CASE WHEN WIPTypeCode = 0 THEN AdjAmount+SurchargeAmount ELSE 0 END AS Fee ,CASE WHEN WIPTypeCode IN (1,2) THEN AdjAmount+SurchargeAmount ELSE 0 END AS Expense ,ISNULL(WIPNOTE.InvoiceDescription,'') AS InvoiceDescription ,ISNULL(WIPNOTE.InternalNote,'') AS InternalNote FROM WIP LEFT JOIN SERVICECODE ON WIP.ServiceCodeIdent = SERVICECODE.ServiceCodeIdent LEFT JOIN STAFF on WIP.StaffIdent = STAFF.StaffIdent LEFT JOIN WIPNOTE ON WIP.WIPIdent = WIPNOTE.WipIdent --LEFT JOIN INVOICE INVOICE1 WITH (NOLOCK) ON WIP.ProgressInvIntIdent = INVOICE1.InvoiceIdent --LEFT JOIN INVOICE INVOICE2 WITH (NOLOCK) ON WIP.InvoiceIdent = INVOICE2.InvoiceIdent LEFT JOIN [INTERIMWORKINGPROJECT] on WIP.projectident = [INTERIMWORKINGPROJECT].interimworkingprojectident LEFT JOIN [INTERIMWORKINGPROJECTWORKSTEP] ON WIP.Workstepident=[INTERIMWORKINGPROJECTWORKSTEP].InterimWorkingProjectWorkStepIdent WHERE WIP.ClientIdent = (SELECT ClientIdent FROM CLIENT WHERE ClientIdSubId = @mClientIdSubId) /* bug 186182 - 07-24-2019 per Sharon Law, we do not want to include any WIP that has BillingStatusCode = 2 (final billed) there is a known issue with several of the CCH Axcess report where final billed WIP is included if the invoice is unposted however, this is incorrect treatment since that WIP is no longer available for billing. so i am making a change accordingly BUT that will cause the reports to no longer agree with the built-in Billing and WIP Summary reports */ /* AND WIP.BillingStatusCode IN (0,2) */ /* unbilled, final billed */ AND WIP.BillingStatusCode = 0 /* per bug 186182 above, only look at unbilled WIP status records */ AND WIP.IsBillableFlag = 1 /* billable */ AND WIP.WIPTypeCode IN (0,1,2) /* exclude progress */ AND WIP.TEStatusCode = 3 /* posted */ AND WIP.TransactionDate >= @mActiveBegDate AND WIP.TransactionDate <= @mActiveEndDate /* bug 197478 and 197479 we need to include WIP lines even tho the hours/amount are zero AND (WIP.Hours<>0 OR WIP.AdjAmount+WIP.SurchargeAmount<>0.00) */ /* note that this section will never apply after the fix for bug 186182 above however, i am leaving this code here for historical purposes */ --AND -- (CASE WHEN BillingStatusCode = 0 -- /* if the line is unbilled, we don't look at the invoice status */ -- THEN 1 -- ELSE -- /* if the line is billed, we need to look at the invoice status -- include the line if the invoice is not Posted */ -- CASE WHEN -- (INVOICE1.InvoiceDateTime <= @mActiveEnddate AND INVOICE1.StatusCode = 1) -- OR (INVOICE2.InvoiceDateTime <= @mActiveEnddate AND INVOICE2.StatusCode = 1) -- THEN 0 -- ELSE 1 END -- END) = 1 ORDER BY CASE WHEN @mPrimarywipsortfield = 'ProjectName' THEN ISNULL([INTERIMWORKINGPROJECT].ProjectCode,@mUnassigned) ELSE ISNULL(SERVICECODE.CategoryID, ' Unassigned') END, TransactionDate, CategoryID, SubCategoryID END GO /****** Object: StoredProcedure [dbo].[USP_ClientBillingGroup] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_ClientBillingGroup] AS BEGIN SET NOCOUNT ON; select CLIENTPRACTICE.BillingGroupName, CLIENTPRACTICE.PrincipalClientFlag, client.ClientIdSubId, client.ClientSortName from CLIENTPRACTICE LEFT JOIN CLIENT ON CLIENTPRACTICE.ClientIdent=CLIENT.ClientIdent where BillingGroupName<>'' order by BillingGroupName,PrincipalClientFlag DESC,ClientIdSubId END GO /****** Object: StoredProcedure [dbo].[USP_ClientContacts] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_ClientContacts] AS BEGIN SET NOCOUNT ON; select ClientContactLastName, ClientContactFirstName, ClientContactMiddleName, client.ClientIdSubId, client.ClientSortName from CLIENTCONTACT left join CLIENT on CLIENTCONTACT.OriginatingClientIntIdent=client.ClientIdent where CLIENTCONTACT.DeleteFlag='F' order by ClientContactLastName,ClientContactFirstName,ClientContactMiddleName,ClientIdSubId END GO /****** Object: StoredProcedure [dbo].[USP_ClientEmailInvoices] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_ClientEmailInvoices] AS BEGIN SET NOCOUNT ON; -- this gets a full list of clients that are marked to receive invoice/statements via email select client.ClientIdSubId, client.ClientSortName, 'Client' AS rtype, CLIENTEMAIL.FirmEmailTypeName, CLIENTEMAIL.EmailAddress, CBE3.InvoiceFlag, CBE3.StatementFlag, client.ClientSortName AS Recipient from --CLIENTBILLINGEMAIL (select ClientIdent,ClientEmailIdent,MAX(LastUpdatedDateTime) AS LastUpdatedDateTime from CLIENTBILLINGEMAIL group by ClientIdent,ClientEmailIdent) CBE1 OUTER APPLY ( SELECT TOP 1 InvoiceFlag,StatementFlag FROM CLIENTBILLINGEMAIL CBE2 WHERE CBE2.ClientIdent=CBE1.ClientIdent AND CBE2.ClientEmailIdent=CBE1.ClientEmailIdent AND CBE2.LastUpdatedDateTime=CBE1.LastUpdatedDateTime) CBE3 inner join CLIENT on CBE1.ClientIdent=client.ClientIdent inner join CLIENTPRACTICE on CLIENTPRACTICE.ClientIdent=client.ClientIdent left join CLIENTEMAIL on CBE1.ClientEmailIdent=clientemail.EmailIdent AND EmployeePlanSubEntityTypeCode='null' WHERE clientemail.EmailAddress<>'' UNION ALL select client.ClientIdSubId, client.ClientSortName, 'Contact' AS rtype, CLIENTEMAIL.FirmEmailTypeName, CLIENTEMAIL.EmailAddress, CCBE3.InvoiceFlg, CCBE3.StatementFlg, CLIENTCONTACT.ClientContactFirstName + ' ' + CLIENTCONTACT.ClientContactLastName AS Recipient from --CLIENTCONTACTBILLINGEMAIL (select ClientIdent,ClientContactIdent,ClientContactEmailIdent,MAX(LastUpdatedDateTime) AS LastUpdatedDateTime from CLIENTCONTACTBILLINGEMAIL group by ClientIdent,ClientContactIdent,ClientContactEmailIdent) CCBE1 OUTER APPLY ( SELECT TOP 1 InvoiceFlg,StatementFlg FROM CLIENTCONTACTBILLINGEMAIL CCBE2 WHERE CCBE2.ClientIdent=CCBE1.ClientIdent AND CCBE2.ClientContactIdent=CCBE1.ClientContactIdent AND CCBE2.ClientContactEmailIdent=CCBE1.ClientContactEmailIdent AND CCBE2.LastUpdatedDateTime=CCBE1.LastUpdatedDateTime) CCBE3 INNER JOIN CLIENTCONTACT on CCBE1.ClientContactIdent = CLIENTCONTACT.ClientContactIdent INNER JOIN CLIENT on CCBE1.ClientIdent = client.ClientIdent INNER JOIN CLIENTPRACTICE on CLIENTPRACTICE.ClientIdent = CLIENT.ClientIdent left join CLIENTEMAIL on CCBE1.ClientContactEmailIdent = clientemail.EmailIdent WHERE clientemail.EmailAddress<>'' order by client.ClientIdSubId END GO /****** Object: StoredProcedure [dbo].[USP_ClientExtract] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_ClientExtract] @mPartnerTitle varchar(32) = 'Partner' ,@mManagerTitle varchar(32) = 'Manager' ,@mAssociateTitle varchar(32) = 'Associate' ,@mPhoneSource1 varchar(32) = 'Client' ,@mPhoneSource2 varchar(32) = 'Client' ,@mPhoneSource3 varchar(32) = 'Client' ,@mPhoneSource4 varchar(32) = 'Client' ,@mPhoneSource5 varchar(32) = 'Client' ,@mPhoneSource6 varchar(32) = 'Client' ,@mPhoneSource7 varchar(32) = 'Client' ,@mPhoneType1 varchar(32) = 'Business' ,@mPhoneType2 varchar(32) = 'Fax' ,@mPhoneType3 varchar(32) = 'Car' ,@mPhoneType4 varchar(32) = 'Home' ,@mPhoneType5 varchar(32) = 'Mobile' ,@mPhoneType6 varchar(32) = 'Pager' ,@mPhoneType7 varchar(32) = 'Other' ,@mAddressSource1 varchar(32) = 'Client' ,@mAddressSource2 varchar(32) = 'Client' ,@mAddressSource3 varchar(32) = 'Client' ,@mAddressType1 varchar(32) = 'Business' ,@mAddressType2 varchar(32) = 'Home' ,@mAddressType3 varchar(32) = 'Other' ,@mEmailSource1 varchar(32) = 'Client' ,@mEmailSource2 varchar(32) = 'Client' ,@mEmailSource3 varchar(32) = 'Client' ,@mEmailType1 varchar(32) = 'Business' ,@mEmailType2 varchar(32) = 'Home' ,@mEmailType3 varchar(32) = 'Other' /* this parameter value will either be All, or one of the firm-defined CRS positions if a CRS position name is passed in, this will be used as the primary sort field */ ,@mCRSTitle varchar(32) = 'All' ,@mStaffIdentifierList VARCHAR(MAX) = '' /* if a specified list of CRS staff is selected, this will contain the list */ ,@mClientStatus VARCHAR(16) = ' All' -- this can either be "All", or a specific status such as "Active" ,@mClientType VARCHAR(16) = ' All' -- this can either be "All", or a specific client type such as "Individual" AS BEGIN SET NOCOUNT ON; /* this section creates a temp table to hold the comma separated 'staff' values sent in by the program. */ CREATE TABLE #stafftemp (column1 NVARCHAR(255)) INSERT INTO #stafftemp select * from [dbo].[UFN_String2Table](@mStaffIdentifierList) select -- this is the "filtering" CRS staff info STAFFCRS.StaffIdentifier AS CRSStaffIdentifier, STAFFCRS.ReportName AS CRSReportName, CLIENT.ClientStatus, CLIENT.ClientType, ClientIdSubId, ClientSortName, CorrespondenceName AS [Name 1], SubOrdinateDescription as [Name 2], TRIM(ISNULL(CLIENTINDIVIDUAL.ClientFirstName,'')) AS TaxpayerFirstName, TRIM(ISNULL(CLIENTINDIVIDUAL.ClientMiddleName,'')) AS TaxpayerMiddleName, TRIM(ISNULL(CLIENTINDIVIDUAL.ClientLastName,'')) AS TaxpayerLastName, ISNULL(CONVERT(varchar,CLIENTINDIVIDUAL.ClientBirthDate,101),'') AS TaxpayerBirthday, TRIM(ISNULL(CLIENTINDIVIDUAL.SpouseFirstName,'')) AS SpouseFirstName, TRIM(ISNULL(CLIENTINDIVIDUAL.SpouseMiddleName,'')) AS SpouseMiddleName, TRIM(ISNULL(CLIENTINDIVIDUAL.SpouseLastName,'')) AS SpouseLastName, ISNULL(CONVERT(varchar,CLIENTINDIVIDUAL.SpouseBirthDate,101),'') AS SpouseBirthday, ClientStatus, CONVERT(varchar,AcquiredDateTime,101) AS AcquiredDateTime, CONVERT(varchar,ClientStatusDateTime,101) AS ClientStatusDateTime, /* this field is for industry code, but not all entity types provide a value, just provide what is available */ COALESCE( CLIENTCORP.BusinessCode, CLIENTCUSTOMCLIENTTYPE.BusinessCode, /* clientemployeeplan.BusinessCode, (there is no business code for Employee Plan) */ /* clientfiduciary.BusinessCode, (there is no business code for Fiduciary) */ /* clientindividual,BusinessCode, (there is no business code for Individual) */ CLIENTNONPROFIT.BusinessCode, CLIENTPARTNERSHIP.BusinessCode, CLIENTSOLEPROPRIETORSHIP.BusinessCode, '') AS IndustryCode, CASE WHEN LEN(CLIENT.FiscalPeriod)=4 THEN LEFT(FiscalPeriod,2) ELSE '' END AS FiscalPeriod, CLIENT.ClientOfficeName, ISNULL([partner].StaffLastName + ', ' + [partner].StaffFirstName,'') AS PartnerName, ISNULL([manager].StaffLastName + ', ' + [manager].StaffFirstName,'') AS ManagerName, ISNULL([associate].StaffLastName + ', ' + [associate].StaffFirstName,'') AS AssociateName, CLIENT.ClientType, CONTACT1.ClientContactFirstName, CONTACT1.ClientContactLastName, CONTACT1.ClientContactHonorificCode, CONTACT1.SalutationText AS ClientContactSalutationText, ISNULL((SELECT TOP 1 FirmPhoneTypeLabelName FROM CLIENTPHONE WHERE PhoneCategoryType='Client' AND ReferenceIdent=CLIENT.ClientIdent AND PrimaryPhoneFlag='T'),'') AS PrimaryPhoneType, ISNULL((SELECT TOP 1 FirmAddressTypeLabelName FROM CLIENTADDRESS WHERE AddressIdentCategoryType='Client' AND ReferenceIdent=CLIENT.ClientIdent AND PrimaryAddressFlag='T'),'') AS PrimaryAddressType, ISNULL((SELECT TOP 1 FirmAddressTypeLabelName FROM CLIENTADDRESS WHERE AddressIdentCategoryType='Client' AND ReferenceIdent=CLIENT.ClientIdent AND MailingAddressFlag='T'),'') AS MailingAddressType, /* 7 phone types can be selected */ ISNULL(PHONE1.PhoneNumber,'') AS BusinessPhone, ISNULL(PHONE1.Extension,'') AS BusinessExtension, ISNULL(PHONE2.PhoneNumber,'') AS FaxPhone, ISNULL(PHONE2.Extension,'') AS FaxExtension, ISNULL(PHONE3.PhoneNumber,'') AS CarPhone, ISNULL(PHONE3.Extension,'') AS CarExtension, ISNULL(PHONE4.PhoneNumber,'') AS HomePhone, ISNULL(PHONE4.Extension,'') AS HomeExtension, ISNULL(PHONE5.PhoneNumber,'') AS MobilePhone, ISNULL(PHONE5.Extension,'') AS MobileExtension, ISNULL(PHONE6.PhoneNumber,'') AS PagerPhone, ISNULL(PHONE6.Extension,'') AS PagerExtension, ISNULL(PHONE7.PhoneNumber,'') AS OtherPhone, ISNULL(PHONE7.Extension,'') AS OtherExtension, ISNULL(ADDRESS1.AddressLine1,'') AS BusinessAddressLine1, ISNULL(ADDRESS1.AddressLine2,'') AS BusinessAddressLine2, ISNULL(ADDRESS1.CityName,'') AS BusinessCity, ISNULL(ADDRESS1.StateProvinceCode,'') AS BusinessState, ISNULL(ADDRESS1.PostalCode,'') AS BusinessZip, ISNULL(ADDRESS1.CountryCode,'') AS BusinessCountry, ISNULL(ADDRESS2.AddressLine1,'') AS HomeAddressLine1, ISNULL(ADDRESS2.AddressLine2,'') AS HomeAddressLine2, ISNULL(ADDRESS2.CityName,'') AS HomeCity, ISNULL(ADDRESS2.StateProvinceCode,'') AS HomeState, ISNULL(ADDRESS2.PostalCode,'') AS HomeZip, ISNULL(ADDRESS2.CountryCode,'') AS HomeCountry, ISNULL(ADDRESS3.AddressLine1,'') AS OtherAddressLine1, ISNULL(ADDRESS3.AddressLine2,'') AS OtherAddressLine2, ISNULL(ADDRESS3.CityName,'') AS OtherCity, ISNULL(ADDRESS3.StateProvinceCode,'') AS OtherState, ISNULL(ADDRESS3.PostalCode,'') AS OtherZip, ISNULL(ADDRESS3.CountryCode,'') AS OtherCountry, ISNULL(EMAIL1.EmailAddress,'') AS Email, ISNULL(EMAIL2.EmailAddress,'') AS Email2, ISNULL(EMAIL3.EmailAddress,'') AS Email3, CLIENT.WebPageURL, ISNULL((SELECT TOP 1 C2.ClientIdSubId FROM CLIENTPRACTICE CP2 INNER JOIN CLIENT C2 ON CP2.ClientIdent=C2.ClientIdent WHERE CP2.BillingGroupName=CLIENTPRACTICE.BillingGroupName AND CP2.PrincipalClientFlag=1 ),'') AS ParentClientId FROM CLIENT -- this is the client CRS and staff list that is used for filtering LEFT JOIN CLIENTCRS on CLIENTCRS.ClientIdent = CLIENT.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription = @mCRSTitle LEFT JOIN STAFF STAFFCRS on CLIENTCRS.StaffIdent = STAFFCRS.StaffIdent -- these are the client CRS fields that will be extracted. these are not used for filtering, just exporting LEFT JOIN CLIENTCRS AS clientcrs1 ON clientcrs1.ClientIdent=CLIENT.ClientIdent AND clientcrs1.FirmClientStaffAssignmentName=@mPartnerTitle LEFT JOIN STAFF AS [partner] ON [partner].StaffIdent=CLIENTCRS1.StaffIdent LEFT JOIN CLIENTCRS AS clientcrs2 ON clientcrs2.ClientIdent=CLIENT.ClientIdent AND clientcrs2.FirmClientStaffAssignmentName=@mManagerTitle LEFT JOIN STAFF AS manager ON manager.StaffIdent=CLIENTCRS2.StaffIdent LEFT JOIN CLIENTCRS AS clientcrs3 ON clientcrs3.ClientIdent=CLIENT.ClientIdent AND clientcrs3.FirmClientStaffAssignmentName=@mAssociateTitle LEFT JOIN STAFF AS associate ON associate.StaffIdent=CLIENTCRS2.StaffIdent LEFT JOIN CLIENTPRACTICE ON CLIENT.ClientIdent = CLIENTPRACTICE.ClientIdent /* this is info that comes from the "entity type" tables */ OUTER APPLY (SELECT TOP 1 NameLine1,BusinessCode,PrincipalBusinessActivity,PrincipalProductOrService FROM CLIENTCORP WHERE CLIENTCORP.ClientIdent=CLIENT.ClientIdent) CLIENTCORP OUTER APPLY (SELECT TOP 1 NameLine1,BusinessCode,PrincipalBusinessActivity,PrincipalProductOrService FROM CLIENTCUSTOMCLIENTTYPE WHERE CLIENTCUSTOMCLIENTTYPE.ClientIdent=CLIENT.ClientIdent) CLIENTCUSTOMCLIENTTYPE OUTER APPLY (SELECT TOP 1 PlanName1 FROM CLIENTEMPLOYEEPLAN WHERE CLIENTEMPLOYEEPLAN.ClientIdent=CLIENT.ClientIdent) CLIENTEMPLOYEEPLAN OUTER APPLY (SELECT TOP 1 NameLine1 FROM CLIENTFIDUCIARY WHERE CLIENTFIDUCIARY.ClientIdent=CLIENT.ClientIdent) CLIENTFIDUCIARY OUTER APPLY (SELECT TOP 1 ClientFirstName,ClientMiddleName,ClientLastName,ClientBirthDate,SpouseFirstName,SpouseMiddleName,SpouseLastName,SpouseBirthDate FROM CLIENTINDIVIDUAL WHERE CLIENTINDIVIDUAL.ClientIdent=CLIENT.ClientIdent) CLIENTINDIVIDUAL OUTER APPLY (SELECT TOP 1 NameLine1,BusinessCode,PrincipalBusinessActivity,PrincipalProductOrService FROM CLIENTNONPROFIT WHERE CLIENTNONPROFIT.ClientIdent=CLIENT.ClientIdent) CLIENTNONPROFIT OUTER APPLY (SELECT TOP 1 NameLine1,BusinessCode,PrincipalBusinessActivity,PrincipalProductOrService FROM CLIENTPARTNERSHIP WHERE CLIENTPARTNERSHIP.ClientIdent=CLIENT.ClientIdent) CLIENTPARTNERSHIP OUTER APPLY (SELECT TOP 1 NameLine1,BusinessCode,PrincipalBusinessActivity,PrincipalProductOrService FROM CLIENTSOLEPROPRIETORSHIP WHERE CLIENTSOLEPROPRIETORSHIP.ClientIdent=CLIENT.ClientIdent) CLIENTSOLEPROPRIETORSHIP /* get info for the first contact for this client */ OUTER APPLY ( SELECT TOP 1 ClientContactFirstName,ClientContactLastName,ClientContactHonorificCode,SalutationText FROM CLIENTCLIENTREFBRIDGE INNER JOIN CLIENTCONTACT ON CLIENTCLIENTREFBRIDGE.ClientReferenceIdent=CLIENTCONTACT.ClientContactIdent WHERE CLIENTCLIENTREFBRIDGE.ClientIdent=CLIENT.ClientIdent) CONTACT1 /* 7 phone types can be selected */ OUTER APPLY (SELECT TOP 1 * FROM CLIENTPHONE WHERE CLIENTPHONE.PhoneCategoryType=@mPhoneSource1 AND CLIENTPHONE.ReferenceIdent=CLIENT.ClientIdent AND FirmPhoneTypeLabelName=@mPhoneType1) PHONE1 OUTER APPLY (SELECT TOP 1 * FROM CLIENTPHONE WHERE CLIENTPHONE.PhoneCategoryType=@mPhoneSource2 AND CLIENTPHONE.ReferenceIdent=CLIENT.ClientIdent AND FirmPhoneTypeLabelName=@mPhoneType2) PHONE2 OUTER APPLY (SELECT TOP 1 * FROM CLIENTPHONE WHERE CLIENTPHONE.PhoneCategoryType=@mPhoneSource3 AND CLIENTPHONE.ReferenceIdent=CLIENT.ClientIdent AND FirmPhoneTypeLabelName=@mPhoneType3) PHONE3 OUTER APPLY (SELECT TOP 1 * FROM CLIENTPHONE WHERE CLIENTPHONE.PhoneCategoryType=@mPhoneSource4 AND CLIENTPHONE.ReferenceIdent=CLIENT.ClientIdent AND FirmPhoneTypeLabelName=@mPhoneType4) PHONE4 OUTER APPLY (SELECT TOP 1 * FROM CLIENTPHONE WHERE CLIENTPHONE.PhoneCategoryType=@mPhoneSource5 AND CLIENTPHONE.ReferenceIdent=CLIENT.ClientIdent AND FirmPhoneTypeLabelName=@mPhoneType5) PHONE5 OUTER APPLY (SELECT TOP 1 * FROM CLIENTPHONE WHERE CLIENTPHONE.PhoneCategoryType=@mPhoneSource6 AND CLIENTPHONE.ReferenceIdent=CLIENT.ClientIdent AND FirmPhoneTypeLabelName=@mPhoneType6) PHONE6 OUTER APPLY (SELECT TOP 1 * FROM CLIENTPHONE WHERE CLIENTPHONE.PhoneCategoryType=@mPhoneSource7 AND CLIENTPHONE.ReferenceIdent=CLIENT.ClientIdent AND FirmPhoneTypeLabelName=@mPhoneType7) PHONE7 /* 3 address types can be selected */ OUTER APPLY (SELECT TOP 1 * FROM CLIENTADDRESS WHERE CLIENTADDRESS.AddressIdentCategoryType=@mAddressSource1 AND CLIENTADDRESS.ReferenceIdent=CLIENT.ClientIdent AND FirmAddressTypeLabelName=@mAddressType1) ADDRESS1 OUTER APPLY (SELECT TOP 1 * FROM CLIENTADDRESS WHERE CLIENTADDRESS.AddressIdentCategoryType=@mAddressSource2 AND CLIENTADDRESS.ReferenceIdent=CLIENT.ClientIdent AND FirmAddressTypeLabelName=@mAddressType2) ADDRESS2 OUTER APPLY (SELECT TOP 1 * FROM CLIENTADDRESS WHERE CLIENTADDRESS.AddressIdentCategoryType=@mAddressSource3 AND CLIENTADDRESS.ReferenceIdent=CLIENT.ClientIdent AND FirmAddressTypeLabelName=@mAddressType3) ADDRESS3 /* 3 email types can be selected */ OUTER APPLY (SELECT TOP 1 * FROM CLIENTEMAIL WHERE CLIENTEMAIL.EmailIdentCategoryType=@mEmailSource1 AND CLIENTEMAIL.ReferenceIdent=CLIENT.ClientIdent AND FirmEmailTypeName=@mEmailType1) EMAIL1 OUTER APPLY (SELECT TOP 1 * FROM CLIENTEMAIL WHERE CLIENTEMAIL.EmailIdentCategoryType=@mEmailSource2 AND CLIENTEMAIL.ReferenceIdent=CLIENT.ClientIdent AND FirmEmailTypeName=@mEmailType2) EMAIL2 OUTER APPLY (SELECT TOP 1 * FROM CLIENTEMAIL WHERE CLIENTEMAIL.EmailIdentCategoryType=@mEmailSource3 AND CLIENTEMAIL.ReferenceIdent=CLIENT.ClientIdent AND FirmEmailTypeName=@mEmailType3) EMAIL3 WHERE (CASE WHEN @mCRSTitle = 'All' THEN 1 ELSE CASE WHEN ISNULL(STAFFCRS.StaffIdentifier,'0') IN (SELECT column1 FROM #stafftemp) THEN 1 ELSE 0 END END) = 1 AND (CASE WHEN @mClientStatus = ' All' THEN 1 ELSE CASE WHEN CLIENT.ClientStatus = @mClientStatus THEN 1 ELSE 0 END END) = 1 AND (CASE WHEN @mClientType = ' All' THEN 1 ELSE CASE WHEN CLIENT.ClientType = @mClientType THEN 1 ELSE 0 END END) = 1 ORDER BY -- this is the "filtering" CRS staff info STAFFCRS.StaffIdentifier, STAFFCRS.ReportName, ClientIdSubId, ClientSortName END GO /****** Object: StoredProcedure [dbo].[USP_ClientGroup] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_ClientGroup] AS BEGIN SET NOCOUNT ON; SELECT CLIENTGROUP.ClientGroupName, CLIENTGROUP.FinancialReportingGroupFlag, CLIENT.ClientIdSubId, CLIENT.ClientSortName from CLIENTGROUP LEFT JOIN CLIENT ON CLIENTGROUP.ClientIdent=CLIENT.ClientIdent where ClientGroupName<>'' order by ClientGroupName,ClientIdSubId END GO /****** Object: StoredProcedure [dbo].[USP_ClientProduction] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_ClientProduction] @mBegdate AS DATE /* current balance date range */ ,@mEnddate AS DATE /* current balance date range */ /* this parameter value will either be All, or one of the firm-defined CRS positions if a CRS position name is passed in, this will be used as the primary sort field */ ,@mCRSTitle varchar(32) = 'All' ,@mStaffIdentifierList VARCHAR(MAX) = '' /* if a specified list of CRS staff is selected, this will contain the list */ AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; /* this section creates a temp table to hold the comma separated 'staff' values sent in by the program. */ CREATE TABLE #tempstaff (column1 NVARCHAR(255)) INSERT INTO #tempstaff select * from [dbo].[UFN_String2Table](@mStaffIdentifierList) SELECt ISNULL((SELECT STAFF.StaffName FROM CLIENTCRS LEFT JOIN STAFF ON CLIENTCRS.StaffIdent=STAFF.StaffIdent WHERE CLIENTCRS.ClientIdent = CLIENT.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription = @mCRSTitle),' No Selection') AS CRS1 ,CLIENT.ClientIdSubId ,CLIENT.ClientSortName ,isnull(t1.prodhours,0) as prodhours ,isnull(t1.[time],0)+isnull(t1.expenses,0) as prodamounts ,isnull(t2.billhours,0) as billhours ,isnull(t2.BilledAmount,0) as billedamount ,isnull(t3.WriteUpDownAmount,0) as writeupdownamount FROM CLIENT LEFT JOIN CLIENTCRS on CLIENTCRS.ClientIdent = CLIENT.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription = @mCRSTitle LEFT JOIN STAFF on CLIENTCRS.StaffIdent = STAFF.StaffIdent left join /* production hours and amounts */ (select clientident ,sum([hours]) AS prodhours ,sum([time]) AS [time] ,sum(expenses) AS expenses from UVW_WIPAR01Clientident where TransactionDate between @mBegdate and @mEnddate group by clientident ) AS t1 on client.ClientIdent = t1.ClientIdent left join /* billed hours and billed amount */ (select clientident, sum([hours]) AS billhours, sum(BilledAmount) AS billedamount from UVW_WIPAR02Clientident where InvoiceDateTime between @mBegdate and @mEnddate group by clientident ) AS t2 on client.ClientIdent = t2.clientident left join /* write up/down */ (select clientident, sum(WriteUpDownAmount) as [writeupdownamount] from UVW_WIPAR05Clientident where InvoiceDateTime between @mBegdate and @mEnddate group by clientident ) AS t3 on client.ClientIdent = t3.clientident WHERE client.DeleteFlag = 'F' and (t1.prodhours <> 0 or t1.[time] <> 0 or t1.expenses <> 0 or t2.billhours <> 0 or t2.BilledAmount <> 0 or t3.WriteUpDownAmount <> 0) AND (CASE WHEN @mCRSTitle = 'All' THEN 1 ELSE CASE WHEN ISNULL(STAFF.StaffIdentifier,'0') IN (SELECT column1 FROM #tempstaff) THEN 1 ELSE 0 END END) = 1 ORDER BY CRS1,client.ClientIdSubId END GO /****** Object: StoredProcedure [dbo].[USP_ClientProfile] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_ClientProfile] @mActiveBegdate DATE ,@mActiveEnddate DATE AS BEGIN DECLARE @CRS1 varchar(64) = (SELECT [value] FROM firmoptions WHERE name = 'PPCRS') DECLARE @CRS2 varchar(64) = (SELECT [value] FROM firmoptions WHERE name = 'SPCRS') DECLARE @CRS3 varchar(64) = (SELECT [value] FROM firmoptions WHERE name = 'BMCRS') DECLARE @CRS4 varchar(64) = (SELECT [value] FROM firmoptions WHERE name = 'RPCRS') DECLARE @CRS5 varchar(64) = (SELECT [value] FROM firmoptions WHERE name = 'MGCRS') DECLARE @CRS6 varchar(64) = (SELECT [value] FROM firmoptions WHERE name = 'TRCRS') DECLARE @CRS7 varchar(64) = (SELECT [value] FROM firmoptions WHERE name = 'TPCRS') SELECT clientidsubid ,ClientSortName ,SubordinateDescription ,CorrespondenceName ,acquireddatetime ,ClientStatus ,CASE WHEN ClientStatus='Inactive' THEN LastInactiveDateTime ELSE '' END AS LastInactiveDateTime ,CLIENTGROUP.ClientGroupName AS [FinancialReportingClientGroup] ,ISNULL((SELECT staffname FROM CLIENTCRS LEFT JOIN staff ON clientcrs.staffident=staff.staffident WHERE clientcrs.clientident=client.clientident and [FirmClientStaffAssignmentDescription] = @CRS1),'') AS [crs1] ,ISNULL((SELECT staffname FROM CLIENTCRS LEFT JOIN staff ON clientcrs.staffident=staff.staffident WHERE clientcrs.clientident=client.clientident and [FirmClientStaffAssignmentDescription] = @CRS2),'') AS [crs2] ,ISNULL((SELECT staffname FROM CLIENTCRS LEFT JOIN staff ON clientcrs.staffident=staff.staffident WHERE clientcrs.clientident=client.clientident and [FirmClientStaffAssignmentDescription] = @CRS3),'') AS [crs3] ,ISNULL((SELECT staffname FROM CLIENTCRS LEFT JOIN staff ON clientcrs.staffident=staff.staffident WHERE clientcrs.clientident=client.clientident and [FirmClientStaffAssignmentDescription] = @CRS4),'') AS [crs4] ,ISNULL((SELECT staffname FROM CLIENTCRS LEFT JOIN staff ON clientcrs.staffident=staff.staffident WHERE clientcrs.clientident=client.clientident and [FirmClientStaffAssignmentDescription] = @CRS5),'') AS [crs5] ,ISNULL((SELECT staffname FROM CLIENTCRS LEFT JOIN staff ON clientcrs.staffident=staff.staffident WHERE clientcrs.clientident=client.clientident and [FirmClientStaffAssignmentDescription] = @CRS6),'') AS [crs6] ,ISNULL((SELECT staffname FROM CLIENTCRS LEFT JOIN staff ON clientcrs.staffident=staff.staffident WHERE clientcrs.clientident=client.clientident and [FirmClientStaffAssignmentDescription] = @CRS7),'') AS [crs7] FROM client LEFT JOIN CLIENTGROUP ON CLIENTGROUP.ClientIdent = CLIENT.ClientIdent WHERE acquireddatetime BETWEEN @mActiveBegdate AND @mActiveEnddate ORDER BY ClientIdSubId END GO /****** Object: StoredProcedure [dbo].[USP_ClientProfit] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_ClientProfit] @mBegdate DATE, @mEnddate DATE, @mIncludeDeleted char(1) = 'F', /* set to T to include deleted, or set to F to exclude deleted */ /* this parameter value will either be All, or one of the firm-defined CRS positions if a CRS position name is passed in, this will be used as the primary sort field */ @mCRSTitle varchar(32) = 'All', @mStaffIdentifierList VARCHAR(MAX) = '' /* if a specified list of CRS staff is selected, this will contain the list */ AS BEGIN /* this section creates a temp table to hold the comma separated 'staff' values sent in by the program. */ CREATE TABLE #tempstaff (column1 NVARCHAR(255)) INSERT INTO #tempstaff select * from [dbo].[UFN_String2Table](@mStaffIdentifierList) /* ---------------------------------------------------------------------- the client profit report is essentially an analysis/breakdown of the WIP billed column of the WIPAR Reconciliation report the main distinction is that progress amounts are not included, and the analysis includes a breakdown of time vs expense amounts 12-22-2019 yet another distinction worth pointing out is that this report only considers items to be "billed" if the invoice is actually posted. ----------------------------------------------------------------------*/ SELECT ISNULL((SELECT STAFF.StaffName FROM CLIENTCRS LEFT JOIN STAFF ON CLIENTCRS.StaffIdent=STAFF.StaffIdent WHERE CLIENTCRS.ClientIdent = CLIENT.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription = @mCRSTitle),' No Selection') AS CRS1, client.ClientIdSubId, client.ClientSortName, ISNULL(t02.Hours,0.00) AS Hours, ISNULL(t02.TimeBilledAmount,0.00) AS TimeBilledAmount, ISNULL(t02.TimeCost,0.00) AS TimeCost, ISNULL(t02.ExpenseBilledAmount,0.00) AS ExpenseBilledAmount, /* 10-25-2022 based on some troubleshooting and report comparisons with the built-in Client Profit report it appears that the ExpenseCost column should use the amount from ExpenseAdjAmount rather than ExpenseCost */ ISNULL(t02.ExpenseAdjAmount,0.00) AS ExpenseCost, ISNULL(t02.BilledAmount,0.00) AS [BilledAmount], ISNULL(t05.WriteUpDownAmount,0.00) AS [WriteUpDownAmount] FROM CLIENT LEFT JOIN CLIENTCRS on CLIENTCRS.ClientIdent = CLIENT.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription = @mCRSTitle LEFT JOIN STAFF on CLIENTCRS.StaffIdent = STAFF.StaffIdent /* returns billed amounts */ LEFT JOIN (SELECT clientident ,SUM([hours]) AS [Hours] ,SUM([TimeAdjAmount]) AS [TimeAdjAmount] ,SUM([TimeCost]) AS [TimeCost] ,SUM([ExpenseAdjAmount]) AS [ExpenseAdjAmount] ,SUM([ExpenseCost]) AS [ExpenseCost] ,SUM([TimeBilledAmount]) AS [TimeBilledAmount] ,SUM([ExpenseBilledAmount]) AS [ExpenseBilledAmount] ,SUM([BilledAmount]) AS [BilledAmount] FROM UVW_WIPAR02Clientident WHERE InvoiceDateTime BETWEEN @mBegdate AND @mEnddate /* bug 294718 this particular report only includes items as "billed" if the invoice has been posted so we need to test and filter for this */ AND InvoiceStatusCode = 1 GROUP BY clientident) AS t02 ON t02.clientident = client.clientident /* returns field WriteUpDownAmount */ LEFT JOIN (SELECT ClientIdent ,SUM(TimeWriteUpDownAmount) AS TimeWriteUpDownAmount ,SUM(ExpenseWriteUpDownAmount) AS ExpenseWriteUpDownAmount ,SUM(ISNULL(writeupdownAmount,0)) AS WriteUpDownAmount FROM UVW_WIPAR05Clientident WHERE InvoiceDateTime BETWEEN @mBegdate AND @mEnddate /* bug 294718 this particular report only includes items as "billed" if the invoice has been posted so we need to test and filter for this */ AND InvoiceStatusCode = 1 GROUP BY clientident) AS t05 on t05.ClientIdent = client.ClientIdent WHERE (ISNULL(t02.Hours,0.00) <> 0.00 OR ISNULL(t02.BilledAmount,0.00) <> 0.00 OR ISNULL(t02.TimeBilledAmount,0.00) <> 0.00 OR ISNULL(t02.TimeCost,0.00) <> 0.00 OR ISNULL(t02.ExpenseBilledAmount,0.00) <> 0.00 OR ISNULL(t02.ExpenseCost,0.00) <> 0.00 OR ISNULL(t05.WriteUpDownAmount,0.00) <> 0.00) AND (client.deleteflag = 'F' OR client.deleteflag = @mIncludeDeleted) AND (CASE WHEN @mCRSTitle = 'All' THEN 1 ELSE CASE WHEN ISNULL(STAFF.StaffIdentifier,'0') IN (SELECT column1 FROM #tempstaff) THEN 1 ELSE 0 END END) = 1 ORDER BY CRS1,client.ClientIdSubId END GO /****** Object: StoredProcedure [dbo].[USP_ClientRealization] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_ClientRealization] @mBegdate DATE, @mEnddate DATE, @mIncludeDeleted char(1) = 'F', /* set to T to include deleted, or set to F to exclude deleted */ /* this parameter value will either be All, or one of the firm-defined CRS positions if a CRS position name is passed in, this will be used as the primary sort field */ @mCRSTitle varchar(32) = 'All', @mStaffIdentifierList VARCHAR(MAX) = '' /* if a specified list of CRS staff is selected, this will contain the list */ AS BEGIN /* this section creates a temp table to hold the comma separated 'staff' values sent in by the program. */ CREATE TABLE #tempstaff (column1 NVARCHAR(255)) INSERT INTO #tempstaff select * from [dbo].[UFN_String2Table](@mStaffIdentifierList) SELECT ISNULL((SELECT STAFF.StaffName FROM CLIENTCRS LEFT JOIN STAFF ON CLIENTCRS.StaffIdent=STAFF.StaffIdent WHERE CLIENTCRS.ClientIdent = CLIENT.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription = @mCRSTitle),' No Selection') AS CRS1 ,CLIENT.ClientIdSubId ,CLIENT.ClientSortName ,ISNULL(t02.[Hours],0.00) AS [Hours] ,ISNULL(t02.StdAmount,0.00) AS [StdAmount] ,ISNULL(t02.AdjAmount,0.00) AS [AdjAmount] ,ISNULL(t02.BilledAmount,0.00) AS [BilledAmount] ,ISNULL(t02.Cost,0.00) AS [Cost] ,ISNULL(t03.ProgressBilledAmount,0.00) AS [ProgressBilledAmount] ,ISNULL(t04.ProgressApplyAmount,0.00) AS [ProgressApplyAmount] ,ISNULL(t05.writeupdownamount,0.00) AS [WriteUpDownAmount] ,ISNULL(t01.time,0.00) + isnull(t01.expenses,0.00) AS [production] /* not related to billed */ ,ISNULL(t09.PaymentAmount,0.00) AS [PaymentAmount] FROM CLIENT LEFT JOIN CLIENTCRS on CLIENTCRS.ClientIdent = CLIENT.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription=@mCRSTitle LEFT JOIN STAFF on CLIENTCRS.StaffIdent = STAFF.StaffIdent /* returns billed amounts */ LEFT JOIN (SELECT clientident ,SUM([hours]) AS [Hours] ,SUM(StdAmount) AS [StdAmount] ,SUM([TimeAdjAmount]) AS [TimeAdjAmount] ,SUM([ExpenseAdjAmount]) AS [ExpenseAdjAmount] ,SUM([AdjAmount]) AS [AdjAmount] ,SUM([TimeBilledAmount]) AS [TimeBilledAmount] ,SUM([ExpenseBilledAmount]) AS [ExpenseBilledAmount] ,SUM([BilledAmount]) AS [BilledAmount] ,SUM([TimeCost]) AS [TimeCost] ,SUM([ExpenseCost]) AS [ExpenseCost] ,SUM([Cost]) AS [Cost] FROM UVW_WIPAR02Clientident WHERE InvoiceDateTime BETWEEN @mBegdate AND @mEnddate /* per 248876, this report should only show a transaction as billed when the invoice is fully posted. this is not consistent with other reports, but it will agree with built-in reports */ AND InvoiceStatusCode = 1 GROUP BY clientident) AS t02 ON t02.clientident = client.clientident /* returns field ProgressBilledAmount */ LEFT JOIN (SELECT ClientIdent ,sum([ProgressBilledAmount]) AS ProgressBilledAmount FROM UVW_WIPAR03Clientident WHERE InvoiceDateTime BETWEEN @mBegdate AND @mEnddate GROUP BY clientident) AS t03 on t03.ClientIdent = client.ClientIdent /* returns field ProgressApplyAmount */ LEFT JOIN (Select ClientIdent ,sum([ProgressApplyAmount]) AS ProgressApplyAmount FROM UVW_WIPAR04Clientident WHERE InvoiceDateTime BETWEEN @mBegdate AND @mEnddate GROUP BY clientident) AS t04 on t04.ClientIdent = Client.ClientIdent /* returns field WriteUpDownAmount */ LEFT JOIN (SELECT ClientIdent ,SUM(TimeWriteUpDownAmount) AS TimeWriteUpDownAmount ,SUM(ExpenseWriteUpDownAmount) AS ExpenseWriteUpDownAmount ,SUM(ISNULL(writeupdownAmount,0)) AS WriteUpDownAmount FROM UVW_WIPAR05Clientident WHERE InvoiceDateTime BETWEEN @mBegdate AND @mEnddate /* per 308360, this report should only show Write Up/Down transactions when the invoice is fully posted. This is not consistent with other reports, but it will agree with built-in reports */ AND InvoiceStatusCode = 1 GROUP BY clientident) AS t05 on t05.ClientIdent = client.ClientIdent /* this gets "production" amounts, not related to billed amounts */ LEFT JOIN (SELECT Clientident ,SUM([hours]) AS [hours] ,sum([time]) as [time] ,sum([expenses]) as [expenses] FROM UVW_WIPAR01Clientident WHERE transactiondate BETWEEN @mBegdate AND @mEnddate GROUP BY clientident) as t01 ON t01.Clientident = client.ClientIdent /* ar payments */ /* returns field PaymentAmount */ LEFT JOIN (SELECT ClientIdent, SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @mBegdate AND @mEnddate /* per bug 288444, payments on this report should not include payments that were for miscellaneous charges (including finance charges) the change per above bug was later reversed, and it was concluded there the FC charges SHOULD be included in the payments so i am commenting out the change */ /* and ARChargesIdent IS NULL */ GROUP BY clientident) AS t09 ON t09.Clientident = client.Clientident WHERE ( ISNULL(t02.StdAmount,0.00) <> 0.00 OR ISNULL(t02.AdjAmount,0.00) <> 0.00 OR ISNULL(t02.BilledAmount,0.00) <> 0.00 OR ISNULL(t03.ProgressBilledAmount,0.00) <> 0.00 OR ISNULL(t04.ProgressApplyAmount,0.00) <> 0.00 OR ISNULL(t05.writeupdownamount,0.00) <> 0.00 OR ISNULL(t01.time,0.00)+ISNULL(t01.expenses,0.00) <> 0 OR ISNULL(t09.PaymentAmount,0.00)<>0.00) AND (client.deleteflag = 'F' OR client.deleteflag = @mIncludeDeleted) AND (CASE WHEN @mCRSTitle = 'All' THEN 1 ELSE CASE WHEN ISNULL(STAFF.StaffIdentifier,'0') IN (SELECT column1 FROM #tempstaff) THEN 1 ELSE 0 END END) = 1 ORDER BY CRS1,CLIENT.ClientIdSubId END GO /****** Object: StoredProcedure [dbo].[USP_DepositReport] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_DepositReport] @mBegdate DATE, @mEnddate DATE, @mSubtotal INT=0, /* 0=client (default), 1=state/city */ @mState VARCHAR(3)='ALL', @mOfficelist varchar(MAX) /* contains a list of offices in the form of IN('Office1','Office2','Office3') */ AS BEGIN SET NOCOUNT ON; /* this will create a temporary table that holds the list of offices selected */ CREATE TABLE #officetemp (column1 NVARCHAR(255)) INSERT INTO #officetemp select * from [dbo].[UFN_String2Table](@mOfficelist) /* this report can either be run with subtotals at the client level or at the state/city level */ SELECT CLIENT.ClientOfficeName, CASE @mSubtotal WHEN 1 THEN ISNULL(CLIENTADDRESS.StateProvinceCode,' No Selection') ELSE CLIENT.ClientIdSubId END AS SubTotal1, CASE @mSubtotal WHEN 1 THEN ISNULL(CLIENTADDRESS.CityName,' No Selection') ELSE CLIENT.ClientIdSubId END AS SubTotal2, CLIENT.ClientIdSubId, CLIENT.ClientSortName, ISNULL(CLIENTADDRESS.CityName,'') AS CityName, ISNULL(CLIENTADDRESS.StateProvinceCode,'') AS StateProvinceCode, ISNULL(CLIENTADDRESS.PostalCode,'') AS PostalCode, ARTRANSACTION.ReferenceNumber, ARTRANSACTION.PaymentMethod, ARTRANSACTION.TransactionDateTime, ARTRANSACTION.Amount FROM ARTRANSACTION LEFT JOIN CLIENT ON CLIENT.ClientIdent=ARTRANSACTION.ClientIdent LEFT JOIN CLIENTADDRESS ON CLIENT.ClientIdent=CLIENTADDRESS.ReferenceIdent AND CLIENTADDRESS.ReferenceIdentType='ClientIntID' AND CLIENTADDRESS.PrimaryAddressFlag='T' WHERE AREntryTypeIntCode=1 and Posted=1 and TransactionDateTime between @mBegDate and @mEndDate and CASE WHEN @mState='ALL' THEN 1 ELSE CASE WHEN ISNULL(CLIENTADDRESS.StateProvinceCode,'')=@mState THEN 1 ELSE 0 END END=1 AND ClientOfficeName IN (SELECT column1 FROM #officetemp) ORDER BY CLIENT.ClientOfficeName, CASE @mSubtotal WHEN 1 THEN ISNULL(CLIENTADDRESS.StateProvinceCode,'') ELSE '' END, CASE @mSubtotal WHEN 1 THEN ISNULL(CLIENTADDRESS.CityName,'') ELSE '' END, ARTRANSACTION.TransactionDateTime, CLIENT.ClientIdSubId END GO /****** Object: StoredProcedure [dbo].[USP_DropIndexes] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_DropIndexes] AS BEGIN SET NOCOUNT ON; /* there is a new DROP INDEX IF EXISTS syntax, but it only works in SQL Server 2016 or higher, so we can't use it https://www.mssqltips.com/sqlservertip/4402/new-drop-if-exists-syntax-in-sql-server-2016/ examples from above site -- Old block of code IF EXISTS (SELECT * FROM sys.indexes WHERE NAME = N'IDX_TOY_BRANDS_NAME') DROP INDEX [IDX_TOY_BRANDS_NAME] ON [TOY].[BRANDS] GO -- New block of code DROP INDEX IF EXISTS [IDX_TOY_BRANDS_NAME] ON [TOY].[BRANDS] GO */ IF EXISTS (SELECT * FROM sys.indexes WHERE NAME = N'IDX_DAU001') DROP INDEX [IDX_DAU001] ON [dbo].[ARTRANSACTION] IF EXISTS (SELECT * FROM sys.indexes WHERE NAME = N'IDX_DAU002') DROP INDEX [IDX_DAU002] ON [dbo].[CLIENTCRS] IF EXISTS (SELECT * FROM sys.indexes WHERE NAME = N'IDX_DAU003') DROP INDEX [IDX_DAU003] ON [dbo].[ARTRANSACTION] IF EXISTS (SELECT * FROM sys.indexes WHERE NAME = N'IDX_DAU004') DROP INDEX [IDX_DAU004] ON [dbo].[ARCHARGES] IF EXISTS (SELECT * FROM sys.indexes WHERE NAME = N'IDX_DAU005') DROP INDEX [IDX_DAU005] ON [dbo].[CLIENT] IF EXISTS (SELECT * FROM sys.indexes WHERE NAME = N'IDX_DAU006') DROP INDEX [IDX_DAU006] ON [dbo].[WIP] IF EXISTS (SELECT * FROM sys.indexes WHERE NAME = N'IDX_DAU007') DROP INDEX [IDX_DAU007] ON [dbo].[WIP] IF EXISTS (SELECT * FROM sys.indexes WHERE NAME = N'IDX_DAU008') DROP INDEX [IDX_DAU008] ON [dbo].[WIP] IF EXISTS (SELECT * FROM sys.indexes WHERE NAME = N'IDX_DAU009') DROP INDEX [IDX_DAU009] ON [dbo].[WIP] IF EXISTS (SELECT * FROM sys.indexes WHERE NAME = N'IDX_DAU010') DROP INDEX [IDX_DAU010] ON [dbo].[CLIENT] IF EXISTS (SELECT * FROM sys.indexes WHERE NAME = N'IDX_DAU011') DROP INDEX [IDX_DAU011] ON [dbo].[WIP] IF EXISTS (SELECT * FROM sys.indexes WHERE NAME = N'IDX_DAU012') DROP INDEX [IDX_DAU012] ON [dbo].[WIP] IF EXISTS (SELECT * FROM sys.indexes WHERE NAME = N'IDX_DAU013') DROP INDEX [IDX_DAU013] ON [dbo].[WIP] IF EXISTS (SELECT * FROM sys.indexes WHERE NAME = N'IDX_DAU014') DROP INDEX [IDX_DAU014] ON [dbo].[INVOICE] IF EXISTS (SELECT * FROM sys.indexes WHERE NAME = N'IDX_DAU015') DROP INDEX [IDX_DAU015] ON [dbo].[WIP] IF EXISTS (SELECT * FROM sys.indexes WHERE NAME = N'IDX_DAU016') DROP INDEX [IDX_DAU016] ON [dbo].[WIP] IF EXISTS (SELECT * FROM sys.indexes WHERE NAME = N'IDX_DAU017') DROP INDEX [IDX_DAU017] ON [dbo].[WIP] IF EXISTS (SELECT * FROM sys.indexes WHERE NAME = N'IDX_DAU018') DROP INDEX [IDX_DAU018] ON [dbo].[WIP] IF EXISTS (SELECT * FROM sys.indexes WHERE NAME = N'IDX_DAU019') DROP INDEX [IDX_DAU019] ON [dbo].[WIP] IF EXISTS (SELECT * FROM sys.indexes WHERE NAME = N'IDX_DAU020') DROP INDEX [IDX_DAU020] ON [dbo].[WIP] IF EXISTS (SELECT * FROM sys.indexes WHERE NAME = N'IDX_DAU021') DROP INDEX [IDX_DAU021] ON [dbo].[WIP] END GO /****** Object: StoredProcedure [dbo].[USP_EmployeeMonthlyAnalysis] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_EmployeeMonthlyAnalysis] @mBegdate DATE, @mEnddate DATE, @mOffice VARCHAR(64) AS BEGIN SELECT STAFF.StaffOfficeName, STAFF.ReportName, CLIENT.ClientIdSubId, CLIENT.ClientSortName, t1.* FROM (SELECT StaffIdent ,ClientIdent , SUM(CASE WHEN YEAR(TransactionDate) = YEAR(DATEADD(m,0,@mBegdate)) AND MONTH(TransactionDate) = MONTH(DATEADD(m,0,@mBegdate)) THEN Hours ELSE 0 END) AS c01 , SUM(CASE WHEN YEAR(TransactionDate) = YEAR(DATEADD(m,1,@mBegdate)) AND MONTH(TransactionDate) = MONTH(DATEADD(m,1,@mBegdate)) THEN Hours ELSE 0 END) AS c02 , SUM(CASE WHEN YEAR(TransactionDate) = YEAR(DATEADD(m,2,@mBegdate)) AND MONTH(TransactionDate) = MONTH(DATEADD(m,2,@mBegdate)) THEN Hours ELSE 0 END) AS c03 , SUM(CASE WHEN YEAR(TransactionDate) = YEAR(DATEADD(m,3,@mBegdate)) AND MONTH(TransactionDate) = MONTH(DATEADD(m,3,@mBegdate)) THEN Hours ELSE 0 END) AS c04 , SUM(CASE WHEN YEAR(TransactionDate) = YEAR(DATEADD(m,4,@mBegdate)) AND MONTH(TransactionDate) = MONTH(DATEADD(m,4,@mBegdate)) THEN Hours ELSE 0 END) AS c05 , SUM(CASE WHEN YEAR(TransactionDate) = YEAR(DATEADD(m,5,@mBegdate)) AND MONTH(TransactionDate) = MONTH(DATEADD(m,5,@mBegdate)) THEN Hours ELSE 0 END) AS c06 , SUM(CASE WHEN YEAR(TransactionDate) = YEAR(DATEADD(m,6,@mBegdate)) AND MONTH(TransactionDate) = MONTH(DATEADD(m,6,@mBegdate)) THEN Hours ELSE 0 END) AS c07 , SUM(CASE WHEN YEAR(TransactionDate) = YEAR(DATEADD(m,7,@mBegdate)) AND MONTH(TransactionDate) = MONTH(DATEADD(m,7,@mBegdate)) THEN Hours ELSE 0 END) AS c08 , SUM(CASE WHEN YEAR(TransactionDate) = YEAR(DATEADD(m,8,@mBegdate)) AND MONTH(TransactionDate) = MONTH(DATEADD(m,8,@mBegdate)) THEN Hours ELSE 0 END) AS c09 , SUM(CASE WHEN YEAR(TransactionDate) = YEAR(DATEADD(m,9,@mBegdate)) AND MONTH(TransactionDate) = MONTH(DATEADD(m,9,@mBegdate)) THEN Hours ELSE 0 END) AS c10 , SUM(CASE WHEN YEAR(TransactionDate) = YEAR(DATEADD(m,10,@mBegdate)) AND MONTH(TransactionDate) = MONTH(DATEADD(m,10,@mBegdate)) THEN Hours ELSE 0 END) AS c11 , SUM(CASE WHEN YEAR(TransactionDate) = YEAR(DATEADD(m,11,@mBegdate)) AND MONTH(TransactionDate) = MONTH(DATEADD(m,11,@mBegdate)) THEN Hours ELSE 0 END) AS c12 FROM WIP WHERE TransactionDate BETWEEN @mBegdate AND @mEnddate AND TEStatusCode = 3 /* 3=posted */ AND WIPTypeCode=0 /* 0=Time */ AND (BillingStatusCode=0 OR BillingStatusCode=2) /* 0=Unbilled 1=History 2=Final Billed */ GROUP BY StaffIdent ,ClientIdent ) AS T1 LEFT JOIN STAFF ON STAFF.StaffIdent=t1.StaffIdent LEFT JOIN CLIENT ON CLIENT.ClientIdent=t1.ClientIdent WHERE STAFF.DeleteFlag = 'F' AND CASE WHEN @mOffice='All' THEN STAFF.StaffOfficeName ELSE @mOffice END = STAFF.StaffOfficeName ORDER BY STAFF.StaffOfficeName, STAFF.ReportName, CLIENT.ClientIDSubId END GO /****** Object: StoredProcedure [dbo].[USP_EmployeeSemiMonthlyTimesheet] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_EmployeeSemiMonthlyTimesheet] @mBegdate DATE, @mEnddate DATE, @mDatetype smallint = 0, /* 0=TransactionDate 1=PostedDateTime */ @mUnreleased bit = 1, @mReleased bit = 1, @mReviewed bit = 1, @mPosted bit = 1 AS BEGIN SELECT STAFF.StaffPosition ,STAFF.StaffName ,ISNULL(T1.IsBillableFlag,1) AS IsBillableFlag ,ISNULL(T1.ServiceCodeID2,'') AS ServiceCodeID2 ,ISNULL(T1.ServiceCodeName2,' Unassigned') AS ServiceCodeName2 ,ISNULL(T1.C01,0.00) AS C01 ,ISNULL(T1.C02,0.00) AS C02 ,ISNULL(T1.C03,0.00) AS C03 ,ISNULL(T1.C04,0.00) AS C04 ,ISNULL(T1.C05,0.00) AS C05 ,ISNULL(T1.C06,0.00) AS C06 ,ISNULL(T1.C07,0.00) AS C07 ,ISNULL(T1.C08,0.00) AS C08 ,ISNULL(T1.C09,0.00) AS C09 ,ISNULL(T1.C10,0.00) AS C10 ,ISNULL(T1.C11,0.00) AS C11 ,ISNULL(T1.C12,0.00) AS C12 ,ISNULL(T1.C13,0.00) AS C13 ,ISNULL(T1.C14,0.00) AS C14 ,ISNULL(T1.C15,0.00) AS C15 ,ISNULL(T1.C16,0.00) AS C16 FROM STAFF LEFT JOIN (SELECT WIP.StaffIdent , WIP.IsBillableFlag , ISNULL(ServiceCodeID,'') AS ServiceCodeID2 , ISNULL(ServiceCodeName,' Unassigned') AS ServiceCodeName2 , SUM(CASE WHEN (CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END >= DateAdd(d,-15,@mEnddate) And CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END < DateAdd(d,-14,@mEnddate)) THEN Hours ELSE 0 END) AS c01 , SUM(CASE WHEN (CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END >= DateAdd(d,-14,@mEnddate) And CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END < DateAdd(d,-13,@mEnddate)) THEN Hours ELSE 0 END) AS c02 , SUM(CASE WHEN (CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END >= DateAdd(d,-13,@mEnddate) And CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END < DateAdd(d,-12,@mEnddate)) THEN Hours ELSE 0 END) AS c03 , SUM(CASE WHEN (CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END >= DateAdd(d,-12,@mEnddate) And CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END < DateAdd(d,-11,@mEnddate)) THEN Hours ELSE 0 END) AS c04 , SUM(CASE WHEN (CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END >= DateAdd(d,-11,@mEnddate) And CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END < DateAdd(d,-10,@mEnddate)) THEN Hours ELSE 0 END) AS c05 , SUM(CASE WHEN (CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END >= DateAdd(d,-10,@mEnddate) And CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END < DateAdd(d, -9,@mEnddate)) THEN Hours ELSE 0 END) AS c06 , SUM(CASE WHEN (CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END >= DateAdd(d, -9,@mEnddate) And CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END < DateAdd(d, -8,@mEnddate)) THEN Hours ELSE 0 END) AS c07 , SUM(CASE WHEN (CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END >= DateAdd(d, -8,@mEnddate) And CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END < DateAdd(d, -7,@mEnddate)) THEN Hours ELSE 0 END) AS c08 , SUM(CASE WHEN (CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END >= DateAdd(d, -7,@mEnddate) And CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END < DateAdd(d, -6,@mEnddate)) THEN Hours ELSE 0 END) AS c09 , SUM(CASE WHEN (CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END >= DateAdd(d, -6,@mEnddate) And CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END < DateAdd(d, -5,@mEnddate)) THEN Hours ELSE 0 END) AS c10 , SUM(CASE WHEN (CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END >= DateAdd(d, -5,@mEnddate) And CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END < DateAdd(d, -4,@mEnddate)) THEN Hours ELSE 0 END) AS c11 , SUM(CASE WHEN (CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END >= DateAdd(d, -4,@mEnddate) And CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END < DateAdd(d, -3,@mEnddate)) THEN Hours ELSE 0 END) AS c12 , SUM(CASE WHEN (CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END >= DateAdd(d, -3,@mEnddate) And CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END < DateAdd(d, -2,@mEnddate)) THEN Hours ELSE 0 END) AS c13 , SUM(CASE WHEN (CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END >= DateAdd(d, -2,@mEnddate) And CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END < DateAdd(d, -1,@mEnddate)) THEN Hours ELSE 0 END) AS c14 , SUM(CASE WHEN (CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END >= DateAdd(d, -1,@mEnddate) And CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END < DateAdd(d, 0,@mEnddate)) THEN Hours ELSE 0 END) AS c15 , SUM(CASE WHEN (CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END >= DateAdd(d, 0,@mEnddate) And CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END < DateAdd(d, 1,@mEnddate)) THEN Hours ELSE 0 END) AS c16 FROM WIP LEFT JOIN SERVICECODE ON WIP.ServiceCodeIdent = SERVICECODE.ServiceCodeIdent WHERE (CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END >= @mBegdate) AND (CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END < DateAdd(d,1,@mEnddate)) AND WIP.Hours<>0.00 AND WIP.WIPTypeCode=0 /* 0=Time */ AND (WIP.BillingStatusCode=0 OR WIP.BillingStatusCode=2) /* 0=Unbilled 1=History 2=Final Billed */ /* test for which WIP status codes to include in report */ AND (CASE WHEN @mUnreleased=1 AND WIP.TEStatuscode=0 THEN 1 ELSE 0 END=1 OR CASE WHEN @mReleased=1 AND WIP.TEStatuscode=1 THEN 1 ELSE 0 END=1 OR CASE WHEN @mReviewed=1 AND WIP.TEStatuscode=2 THEN 1 ELSE 0 END=1 OR CASE WHEN @mPosted=1 AND WIP.TEStatuscode=3 THEN 1 ELSE 0 END=1) /* 03/07/2024 - had a long discussion with Nick and Joe about whether it is necessary to filter on TransferStatusCode I looked at a number of transaction examples, and came to this conclusion 1) If TransferStatusCode=1 (TransferIn), then it has to be included in the report, and it is treated just like a normal transaction where the TransferStatusCode=0 2) if TransferStatusCode=2 (TransferOut), then the amounts in the record are set to 0 (hours, stdamount, adjamount, etc) so the record has no effect on reporting */ /* AND WIP.TransferStatusCode=0 */ /* 0=None 1=TransferIn 2=TransferOut 3=ReversingEntry */ GROUP BY WIP.StaffIdent , WIP.IsBillableFlag , ISNULL(ServiceCodeID,'') , ISNULL(ServiceCodeName,' Unassigned') ) AS T1 ON T1.StaffIdent = STAFF.StaffIdent WHERE STAFF.StaffStatus = 'Active' AND STAFF.DeleteFlag = 'F' ORDER BY StaffPosition,StaffName,IsBillableFlag DESC,ServiceCodeID2 END GO /****** Object: StoredProcedure [dbo].[USP_GeneralLedgerReconciliation] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_GeneralLedgerReconciliation] @mBegdate1 AS DATE /* current balance date range */ ,@mEnddate1 AS DATE /* current balance date range */ /* this parameter value will either be All, or one of the firm-defined CRS positions if a CRS position name is passed in, this will be used as the primary sort field */ ,@mCRSTitle varchar(32) = 'All' ,@mStaffIdentifierList VARCHAR(MAX) = '' /* if a specified list of CRS staff is selected, this will contain the list */ ,@mSortOrder AS INT = 0 /* 0 = sort by clientid, 1 = sort by clientsortname */ ,@mIncludeDeleted CHAR(1) = 'F' /* set to F to exclude deleted, or set to T to include deleted */ AS BEGIN SET NOCOUNT ON; /* this section creates a temp table to hold the comma separated 'staff' values sent in by the program. */ CREATE TABLE #tempstaff (column1 NVARCHAR(255)) INSERT INTO #tempstaff select * from [dbo].[UFN_String2Table](@mStaffIdentifierList) /* beginning balances */ SELECT Clientident ,sum([time]) as [time] ,sum([expenses]) as [expenses] INTO #s01 FROM UVW_WIPAR01Clientident WHERE transactiondate < @mBegdate1 GROUP BY clientident SELECT clientident ,SUM([BilledAmount]) AS [BilledAmount] INTO #s02 FROM UVW_WIPAR02Clientident WHERE InvoiceDateTime < @mBegdate1 AND InvoiceStatusCode = 1 GROUP BY clientident SELECT ClientIdent ,sum([ProgressBilledAmount]) AS ProgressBilledAmount INTO #s03 FROM UVW_WIPAR03Clientident WHERE InvoiceDateTime < @mBegdate1 AND InvoiceStatusCode = 1 GROUP BY clientident Select ClientIdent ,sum([ProgressApplyAmount]) AS ProgressApplyAmount INTO #s04 FROM UVW_WIPAR04Clientident WHERE InvoiceDateTime < @mBegdate1 AND InvoiceStatusCode = 1 GROUP BY clientident SELECT ClientIdent ,SUM(ISNULL(writeupdownAmount,0)) AS WriteUpDownAmount INTO #s05 FROM UVW_WIPAR05Clientident WHERE InvoiceDateTime < @mBegdate1 AND InvoiceStatusCode = 1 GROUP BY clientident /* AR Components */ SELECT clientident, ISNULL([1],0.00) AS Invoice, ISNULL([2],0.00) AS SalesTax, ISNULL([3],0.00) AS FinChg, ISNULL([4],0.00) AS PmtsDistributed, ISNULL([5],0.00) AS PmtsUndistributed, ISNULL([6],0.00) AS Adj23Distributed, ISNULL([7],0.00) AS Adj67Distributed, ISNULL([8],0.00) AS Adj23Undistributed, ISNULL([9],0.00) AS Adj67Undistributed, ISNULL([10],0.00) AS AdjOther, ISNULL([11],0.00) AS WriteOffDistributed, ISNULL([12],0.00) AS WriteOffUndistributed INTO #s06 FROM (SELECT Amount, clientident, transactiontype FROM UVW_ARComponentDetail WHERE TransactionDate < @mBegdate1 ) p PIVOT (SUM(Amount) FOR TransactionType IN ( [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12] ) ) AS pvt /* current time expense */ SELECT Clientident ,sum([time]) as [time] ,sum([expenses]) as [expenses] INTO #t01 FROM UVW_WIPAR01Clientident WHERE transactiondate BETWEEN @mBegdate1 AND @mEnddate1 GROUP BY clientident SELECT clientident ,SUM([BilledAmount]) AS [BilledAmount] INTO #t02 FROM UVW_WIPAR02Clientident WHERE InvoiceDateTime BETWEEN @mBegdate1 AND @mEnddate1 AND InvoiceStatusCode = 1 GROUP BY clientident SELECT ClientIdent ,sum([ProgressBilledAmount]) AS ProgressBilledAmount INTO #t03 FROM UVW_WIPAR03Clientident WHERE InvoiceDateTime BETWEEN @mBegdate1 AND @mEnddate1 AND InvoiceStatusCode = 1 GROUP BY clientident Select ClientIdent ,sum([ProgressApplyAmount]) AS ProgressApplyAmount INTO #t04 FROM UVW_WIPAR04Clientident WHERE InvoiceDateTime BETWEEN @mBegdate1 AND @mEnddate1 AND InvoiceStatusCode = 1 GROUP BY clientident SELECT ClientIdent ,SUM(ISNULL(writeupAmount,0)) AS WriteUpAmount ,SUM(ISNULL(writedownAmount,0)) AS WriteDownAmount INTO #t05 FROM UVW_WIPAR05Clientident WHERE InvoiceDateTime BETWEEN @mBegdate1 AND @mEnddate1 AND InvoiceStatusCode = 1 GROUP BY clientident SELECT clientident, ISNULL([1],0.00) AS Invoice, ISNULL([2],0.00) AS SalesTax, ISNULL([3],0.00) AS FinChg, ISNULL([4],0.00) AS PmtsDistributed, ISNULL([5],0.00) AS PmtsUndistributed, ISNULL([6],0.00) AS Adj23Distributed, ISNULL([7],0.00) AS Adj67Distributed, ISNULL([8],0.00) AS Adj23Undistributed, ISNULL([9],0.00) AS Adj67Undistributed, ISNULL([10],0.00) AS AdjOther, ISNULL([11],0.00) AS WriteOffDistributed, ISNULL([12],0.00) AS WriteOffUndistributed INTO #t06 FROM (SELECT Amount, clientident, transactiontype FROM UVW_ARComponentDetail WHERE TransactionDate BETWEEN @mBegdate1 AND @mEnddate1 ) p PIVOT (SUM(Amount) FOR TransactionType IN ( [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12] ) ) AS pvt SELECT /* this particular report allow the primary sort to be either CRS or Business Unit if Business Unit is desired, this must be passed in as the CRS Title */ CASE @mCRSTitle WHEN 'Office' THEN ISNULL([CLIENT].ClientOfficeName,' No Selection') WHEN 'Business Unit' THEN /* get the Office-Business Unit for this client */ ISNULL([CLIENT].ClientOfficeName,' No Selection') + ' - ' + ISNULL([CLIENT].ClientBusinessUnitName,' No Selection') ELSE /* get the CRS Staff Name for this client */ ISNULL((SELECT STAFF.StaffName FROM CLIENTCRS LEFT JOIN STAFF ON CLIENTCRS.StaffIdent=STAFF.StaffIdent WHERE ClientIdent=CLIENT.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription = @mCRSTitle),' No Selection') END AS CRS1 ,[CLIENT].ClientIdSubId ,[Client].ClientSortName, /* beginning WIP balance */ (isnull(#s01.time,0.00) +isnull(#s01.expenses,0.00) -isnull(#s02.BilledAmount,0.00) -isnull(#s03.ProgressBilledAmount,0.00) +isnull(#s04.ProgressApplyAmount,0.00) +isnull(#s05.writeupdownamount,0.00)) AS [s01_wipbalance], /* beginning progress balance */ (isnull(#s03.ProgressBilledAmount,0.00) - isnull(#s04.ProgressApplyAmount,0.00)) AS [s01_progressbalance], /* beginning A/R balance */ (isnull(#s06.Invoice,0.00) + isnull(#s06.SalesTax,0.00) + isnull(#s06.FinChg,0.00) + isnull(#s06.PmtsDistributed,0.00) + isnull(#s06.PmtsUndistributed,0.00) + isnull(#s06.Adj23Distributed,0.00) + isnull(#s06.Adj23Undistributed,0.00) + isnull(#s06.Adj67Distributed,0.00) + isnull(#s06.Adj67Undistributed,0.00) + isnull(#s06.AdjOther,0.00) + isnull(#s06.WriteOffDistributed,0.00) + isnull(#s06.WriteOffUndistributed,0.00)) AS [s01_arbalance], (isnull(#t01.time,0.00)) as [t01_time], (isnull(#t01.expenses,0.00)) as [t01_expenses], (isnull(#t02.BilledAmount,0.00)) as [t02_BilledAmount], (isnull(#t03.ProgressBilledAmount,0.00)) as [t03_ProgressBilledAmount], (isnull(#t04.ProgressApplyAmount,0.00)) as [t04_ProgressApplyAmount], (isnull(#t05.writeupamount,0.00)) as [t05_WriteUpAmount], (isnull(#t05.writedownamount,0.00)) as [t05_WriteDownAmount], /* A/R components */ (isnull(#t06.Invoice,0.00)) as [t06_Invoice], (isnull(#t06.SalesTax,0.00)) as [t06_SalesTax], (isnull(#t06.FinChg,0.00)) as [t06_FinChg], (isnull(#t06.PmtsDistributed,0.00) + isnull(#t06.PmtsUndistributed,0.00)) as [t06_Payments], (isnull(#t06.Adj23Distributed,0.00) + isnull(#t06.Adj23Undistributed,0.00)) as [t06_Adj23], (isnull(#t06.Adj67Distributed,0.00) + isnull(#t06.Adj67Undistributed,0.00)) as [t06_Adj67], (isnull(#t06.AdjOther,0.00)) as [t06_AdjOther], (isnull(#t06.WriteOffDistributed,0.00) + isnull(#t06.WriteOffUndistributed,0.00)) as [t06_WriteOff] FROM client LEFT JOIN CLIENTCRS on CLIENTCRS.ClientIdent = CLIENT.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription=@mCRSTitle LEFT JOIN STAFF on CLIENTCRS.StaffIdent = STAFF.StaffIdent /* beginning balances */ LEFT JOIN #s01 on client.ClientIdent = #s01.Clientident LEFT JOIN #s02 on client.ClientIdent = #s02.Clientident LEFT JOIN #s03 on client.ClientIdent = #s03.Clientident LEFT JOIN #s04 on client.ClientIdent = #s04.Clientident LEFT JOIN #s05 on client.ClientIdent = #s05.ClientIdent /* A/R components */ LEFT JOIN #s06 ON client.ClientIdent = #s06.ClientIdent /* time/expenses */ LEFT JOIN #t01 on client.ClientIdent = #t01.Clientident LEFT JOIN #t02 on client.ClientIdent = #t02.Clientident LEFT JOIN #t03 on client.ClientIdent = #t03.Clientident LEFT JOIN #t04 on client.ClientIdent = #t04.Clientident LEFT JOIN #t05 on client.ClientIdent = #t05.ClientIdent /* A/R components */ LEFT JOIN #t06 ON Client.ClientIdent = #t06.ClientIdent WHERE (CASE WHEN @mCRSTitle = 'All' OR @mCRSTitle = 'Business Unit' OR @mCRSTitle = 'Office' THEN 1 ELSE CASE WHEN ISNULL((SELECT STAFF.StaffIdentifier FROM CLIENTCRS LEFT JOIN STAFF ON CLIENTCRS.StaffIdent=STAFF.StaffIdent WHERE ClientIdent=CLIENT.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription = @mCRSTitle),'0') IN (SELECT column1 FROM #tempstaff) THEN 1 ELSE 0 END END) = 1 AND ( (isnull(#s01.time,0.00) +isnull(#s01.expenses,0.00) -isnull(#s02.BilledAmount,0.00) -isnull(#s03.ProgressBilledAmount,0.00) +isnull(#s04.ProgressApplyAmount,0.00) +isnull(#s05.writeupdownamount,0.00)) <> 0 OR (isnull(#s03.ProgressBilledAmount,0.00) - isnull(#s04.ProgressApplyAmount,0.00)) <> 0 OR (isnull(#s06.Invoice,0.00) + isnull(#s06.SalesTax,0.00) + isnull(#s06.FinChg,0.00) + isnull(#s06.PmtsDistributed,0.00) + isnull(#s06.PmtsUndistributed,0.00) + isnull(#s06.Adj23Distributed,0.00) + isnull(#s06.Adj23Undistributed,0.00) + isnull(#s06.Adj67Distributed,0.00) + isnull(#s06.Adj67Undistributed,0.00) + isnull(#s06.AdjOther,0.00) + isnull(#s06.WriteOffDistributed,0.00) + isnull(#s06.WriteOffUndistributed,0.00)) <> 0 OR (isnull(#t01.time,0.00)) <> 0 OR (isnull(#t01.expenses,0.00)) <> 0 OR (isnull(#t02.BilledAmount,0.00)) <> 0 OR (isnull(#t03.ProgressBilledAmount,0.00)) <> 0 OR (isnull(#t04.ProgressApplyAmount,0.00)) <> 0 OR (isnull(#t05.writeupamount,0.00)) <> 0 OR (isnull(#t05.writedownamount,0.00)) <> 0 OR (isnull(#t06.Invoice,0.00)) <> 0 OR (isnull(#t06.SalesTax,0.00)) <> 0 OR (isnull(#t06.FinChg,0.00)) <> 0 OR (isnull(#t06.PmtsDistributed,0.00) + isnull(#t06.PmtsUndistributed,0.00)) <> 0 OR (isnull(#t06.Adj23Distributed,0.00) + isnull(#t06.Adj23Undistributed,0.00)) <> 0 OR (isnull(#t06.Adj67Distributed,0.00) + isnull(#t06.Adj67Undistributed,0.00)) <> 0 OR (isnull(#t06.AdjOther,0.00)) <> 0 OR (isnull(#t06.WriteOffDistributed,0.00) + isnull(#t06.WriteOffUndistributed,0.00)) <> 0 ) ORDER BY CRS1,ClientIdSubId END GO /****** Object: StoredProcedure [dbo].[USP_HighClientBilling] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_HighClientBilling] @mBegdate AS varchar(10), @mEnddate AS varchar(10), @mCount AS int = 0, /* this parameter value will either be All, or one of the firm-defined CRS positions if a CRS position name is passed in, this will be used as the primary sort field */ @mCRSTitle varchar(32) = 'All', @mStaffIdentifierList VARCHAR(MAX) = '' /* if a specified list of CRS staff is selected, this will contain the list */ AS BEGIN SET NOCOUNT ON; DECLARE @mCount2 INT = CASE WHEN @mCount=0 THEN 999999 ELSE @mCount END /* this is the High Client Billing query note that the billing amount includes the net effect of progress bills/payments */ SELECT TOP (@mCount2) CLIENT.ClientIdSubId, CLIENT.ClientSortName, ISNULL(t02.BilledAmount,0.00) + ISNULL(t03.ProgressBilledAmount,0.00) - ISNULL(t04.ProgressApplyAmount,0.00) AS BilledAmount, ISNULL(t01.time,0.00) + ISNULL(t01.expenses,0.00) AS Production, iSNULL(t09.PaymentAmount,0.00) AS PaymentAmount FROM CLIENT LEFT JOIN /* production */ (SELECT Clientident ,SUM([hours]) AS [hours] ,sum([time]) as [time] ,sum([expenses]) as [expenses] FROM UVW_WIPAR01Clientident WHERE transactiondate BETWEEN @mBegdate AND @mEnddate GROUP BY clientident) AS t01 on t01.Clientident=client.ClientIdent LEFT JOIN /* billed amounts */ (SELECT clientident ,SUM([hours]) AS [Hours] ,SUM(StdAmount) AS [StdAmount] ,SUM([TimeAdjAmount]) AS [TimeAdjAmount] ,SUM([ExpenseAdjAmount]) AS [ExpenseAdjAmount] ,SUM([AdjAmount]) AS [AdjAmount] ,SUM([TimeBilledAmount]) AS [TimeBilledAmount] ,SUM([ExpenseBilledAmount]) AS [ExpenseBilledAmount] ,SUM([BilledAmount]) AS [BilledAmount] ,SUM([TimeCost]) AS [TimeCost] ,SUM([ExpenseCost]) AS [ExpenseCost] ,SUM([Cost]) AS [Cost] FROM UVW_WIPAR02Clientident WHERE InvoiceDateTime BETWEEN @mBegdate AND @mEnddate GROUP BY clientident) AS t02 on t02.clientident=client.ClientIdent LEFT JOIN /* progress billed */ (SELECT ClientIdent ,sum([ProgressBilledAmount]) AS ProgressBilledAmount FROM UVW_WIPAR03Clientident WHERE InvoiceDateTime BETWEEN @mBegdate AND @mEnddate GROUP BY clientident) AS t03 ON t03.clientident=client.ClientIdent LEFT JOIN /* progress applied */ (Select ClientIdent ,sum([ProgressApplyAmount]) AS ProgressApplyAmount FROM UVW_WIPAR04Clientident WHERE InvoiceDateTime BETWEEN @mBegdate AND @mEnddate GROUP BY clientident) AS t04 ON t04.clientident=client.ClientIdent LEFT JOIN /* AR payments */ (SELECT clientident ,SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @mBegdate AND @mEnddate GROUP BY clientident) AS t09 ON t09.ClientIdent = client.ClientIdent ORDER BY BilledAmount DESC END GO /****** Object: StoredProcedure [dbo].[USP_InvoiceHistory01] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_InvoiceHistory01] @PYFDate DATE, @PYTDate DATE, @CYFDate DATE, @CYTDate DATE, /* this parameter value will either be All, or one of the firm-defined CRS positions if a CRS position name is passed in, this will be used as the primary sort field */ @mCRSTitle varchar(32) = 'All', @mStaffIdentifierList VARCHAR(MAX) = '' /* if a specified list of CRS staff is selected, this will contain the list */ AS BEGIN /* this is a custom report for 138543 for consistency, i should rename this proc since it is used in a custom report Billing Analysis Comparative note that this query is very similar to UVW_WIPAR06ClientIdent, and i may consider using that instead of this query */ SET NOCOUNT ON; /* this section createss a temp table to hold the comma separated 'staff' values sent in by the program. */ CREATE TABLE #tempstaff (column1 NVARCHAR(255)) INSERT INTO #tempstaff select * from [dbo].[UFN_String2Table](@mStaffIdentifierList) SELECT ISNULL((SELECT STAFF.StaffName FROM CLIENTCRS LEFT JOIN STAFF ON CLIENTCRS.StaffIdent=STAFF.StaffIdent WHERE ClientIdent=T1.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription = @mCRSTitle),' No Selection') AS CRS1, CLIENT.ClientIdSubId, CLIENT.ClientSortName, T1.* FROM (SELECT clientident /* date range 1 */ ,SUM(CASE WHEN InvoiceDateTime BETWEEN @PYFDate AND @PYTDate THEN StdWIPAmount ELSE 0.00 END) AS PY01 ,SUM(CASE WHEN InvoiceDateTime BETWEEN @PYFDate AND @PYTDate THEN AdjustmentAmount ELSE 0.00 END) AS PY02 ,SUM(CASE WHEN InvoiceDateTime BETWEEN @PYFDate AND @PYTDate THEN TaxAmount + ProgressBilledAmount - ProgressApplyAmount + ProgressTaxAmount - ProgressTaxAppAmount ELSE 0.00 END) AS PY03 /* total invoiced is just the sum of c5, c6, and c8. this should tie with the total invoiced column of the WIPAR Reconciliation report */ /* date range 2 */ ,SUM(CASE WHEN InvoiceDateTime BETWEEN @CYFDate AND @CYTDate THEN StdWIPAmount ELSE 0.00 END) AS CY01 ,SUM(CASE WHEN InvoiceDateTime BETWEEN @CYFDate AND @CYTDate THEN AdjustmentAmount ELSE 0.00 END) AS CY02 ,SUM(CASE WHEN InvoiceDateTime BETWEEN @CYFDate AND @CYTDate THEN TaxAmount + ProgressBilledAmount - ProgressApplyAmount + ProgressTaxAmount - ProgressTaxAppAmount ELSE 0.00 END) AS CY03 /* total invoiced is just the sum of c5, c6, and c8. this should tie with the total invoiced column of the WIPAR Reconciliation report */ FROM INVOICE WHERE StatusCode = 1 /* posted */ GROUP BY clientident) as T1 LEFT JOIN CLIENT ON CLIENT.clientident=T1.clientident LEFT JOIN CLIENTCRS on CLIENTCRS.ClientIdent = CLIENT.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription=@mCRSTitle LEFT JOIN STAFF on CLIENTCRS.StaffIdent = STAFF.StaffIdent WHERE (CASE WHEN @mCRSTitle = 'All' THEN 1 ELSE CASE WHEN ISNULL(STAFF.StaffIdentifier,'0') IN (SELECT column1 FROM #tempstaff) THEN 1 ELSE 0 END END) = 1 AND (T1.PY01 + T1.PY02 + T1.PY03 <> 0 OR T1.CY01 + T1.CY02 + T1.CY03 <> 0) ORDER BY ClientIdSubId END GO /****** Object: StoredProcedure [dbo].[USP_InvoiceHistory02] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_InvoiceHistory02] @mBegdate AS smalldatetime, @mEnddate AS smalldatetime, /* note....for this query, we only call it for one specific client, so the client selection must take place before calling */ @mClientIdSubId AS nvarchar(129) AS BEGIN /* this query is used to run the Invoice History section for a specific client Billing Worksheet */ SELECT ISNULL(t02.invoicenumber,'') AS InvoiceNumber, t02.InvoiceDateTime, ISNULL(t02.BilledHours,0.00) AS BilledHours, ISNULL(t02.BilledAmount,0.00) AS BilledAmount, ISNULL(t05.WriteUpDownAmount,0.00) AS WriteUpDownAmount, ISNULL(t03.ProgressBilledAmount,0.00) AS ProgressBilledAmount, ISNULL(t04.ProgressApplyAmount,0.00) AS ProgressApplyAmount FROM CLIENT /* this query gives us the current period totals by invoice number */ LEFT JOIN /* invoiced w/o progress */ /* NOTE.....this amount already includes the WriteUpDown so, if you want to show the pre-writeupdown billed amount, you need to remove writeupdown */ (SELECT clientident ,InvoiceNumber ,InvoiceDateTime ,SUM([Hours]) AS BilledHours ,SUM([BilledAmount]) AS BilledAmount FROM UVW_WIPAR02Clientident WHERE InvoiceDateTime BETWEEN @mBegdate AND @mEnddate AND InvoiceStatusCode = 1 GROUP BY clientident,InvoiceNumber,InvoiceDateTime) t02 ON t02.ClientIdent = CLIENT.ClientIdent /* write up/down amount */ LEFT JOIN (SELECT clientident ,InvoiceNumber ,SUM([WriteUpDownAmount]) AS WriteUpDownAmount FROM UVW_WIPAR05Clientident WHERE InvoiceDateTime Between @mBegdate AND @mEnddate GROUP BY clientident,InvoiceNumber) AS t05 ON t02.clientident=t05.ClientIdent AND t02.InvoiceNumber=t05.InvoiceNumber /* progress billed */ LEFT JOIN (select clientident ,InvoiceNumber ,SUM([ProgressBilledAmount]) AS ProgressBilledAmount from [UVW_WIPAR03Clientident] where InvoiceDateTime between @mBegdate AND @mEnddate GROUP BY clientident,InvoiceNumber) AS t03 ON t02.clientident=t03.clientident AND t02.InvoiceNumber=t03.InvoiceNumber /* progress applied */ LEFT JOIN (SELECT clientident ,InvoiceNumber ,SUM([ProgressApplyAmount]) AS ProgressApplyAmount FROM [UVW_WIPAR04Clientident] WHERE InvoiceDateTime BETWEEN @mBegdate AND @mEnddate GROUP BY clientident,InvoiceNumber) T04 ON t02.clientident=t04.clientident AND t02.InvoiceNumber=t04.InvoiceNumber WHERE CLIENT.ClientIdSubId = @mClientIdSubId AND (ISNULL(t02.BilledAmount,0.00) <> 0 OR ISNULL(t05.WriteUpDownAmount,0.00) <> 0 OR ISNULL(t03.ProgressBilledAmount,0.00) <> 0 OR ISNULL(t04.ProgressApplyAmount,0.00) <> 0) ORDER BY invoicenumber END GO /****** Object: StoredProcedure [dbo].[USP_InvoiceNumberStatus] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_InvoiceNumberStatus] @mBegdate AS smalldatetime, @mEnddate AS smalldatetime AS BEGIN select CLIENT.ClientIdSubId, CLIENT.ClientSortName, InvoiceNumber, InvoiceDateTime, StdWIPAmount, AdjustmentAmount, ProgressBilledAmount, ProgressApplyAmount from UVW_WIPAR06Clientident left join CLIENT ON UVW_WIPAR06Clientident.ClientIdent = CLIENT.ClientIdent where InvoiceDateTime between @mBegdate and @mEnddate order by CLIENT.ClientIdSubId,UVW_WIPAR06Clientident.InvoiceNumber END GO /****** Object: StoredProcedure [dbo].[USP_KeyAmountsSummary] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_KeyAmountsSummary] @mBegdate1 AS DATE /* current balance date range */ ,@mEnddate1 AS DATE /* current balance date range */ ,@mSortOrder AS INT = 0 /* 0 = sort by clientid, 1 = sort by clientsortname */ ,@mIncludeDeleted CHAR(1) = 'F' /* set to F to exclude deleted, or set to T to include deleted */ AS BEGIN -- this is a summary of key amounts that appear on the billing worksheet summary -- but get generated based on other common reports. this is just a proof -- of those numbers, which can be run for any date range and checked against the -- reports as noted below SELECT /* verified with WIPAR Reconciliation */ SUM(isnull(t01.hours,0.00)) as [t01_hours], /* verified with WIPAR Reconciliation */ SUM(isnull(t01.time,0.00)) as [t01_time], /* verified with WIPAR Reconciliation */ SUM(isnull(t01.expenses,0.00)) as [t01_expenses], SUM(isnull(t02.BilledAmount,0.00)) as [t02_BilledAmount], SUM(isnull(t03.ProgressBilledAmount,0.00)) as [t03_ProgressBilledAmount], SUM(isnull(t04.ProgressApplyAmount,0.00)) as [t04_ProgressApplyAmount], /* verified with Client Billing Realization */ SUM(isnull(t05.writeupdownamount,0.00)) as [t05_WriteUpDownAmount], SUM(isnull(t06.InvoiceAmount,0.00)) as [t06_InvoiceAmount], SUM(isnull(t06.SalesTaxAmount,0.00)) as [t06_SalesTaxAmount], SUM(isnull(t07.Adjustment1Amount,0.00)) as [t07_Adjustment1Amount], SUM(isnull(t07.Adjustment2Amount,0.00)) as [t07_Adjustment2Amount], SUM(isnull(t07.DebitAmount,0.00)) as [t07_DebitAmount], SUM(isnull(t07.CreditAmount,0.00)) as [t07_CreditAmount], SUM(isnull(t08.Charges,0.00)) as [t08_Charges], /* verified with WIPAR Reconciliation */ SUM(isnull(t09.PaymentAmount,0.00)) as [t09_PaymentAmount], /* verified with Client Billing Realization */ SUM(isnull(t10.BilledHours,0.00)) as [t10_BilledHours], /* verified with Client Billing Realization */ SUM(isnull(t10.BilledAmount,0.00)) as [t10_BilledAmount] from client LEFT JOIN (SELECT Clientident ,SUM([hours]) AS [hours] ,sum([time]) as [time] ,sum([expenses]) as [expenses] FROM UVW_WIPAR01Clientident WHERE transactiondate BETWEEN @mBegdate1 AND @mEnddate1 GROUP BY clientident) AS t01 on client.ClientIdent = t01.Clientident LEFT JOIN (SELECT clientident ,SUM([hours]) AS [Hours] ,SUM(StdAmount) AS [StdAmount] ,SUM([TimeAdjAmount]) AS [TimeAdjAmount] ,SUM([ExpenseAdjAmount]) AS [ExpenseAdjAmount] ,SUM([AdjAmount]) AS [AdjAmount] ,SUM([TimeBilledAmount]) AS [TimeBilledAmount] ,SUM([ExpenseBilledAmount]) AS [ExpenseBilledAmount] ,SUM([BilledAmount]) AS [BilledAmount] ,SUM([TimeCost]) AS [TimeCost] ,SUM([ExpenseCost]) AS [ExpenseCost] ,SUM([Cost]) AS [Cost] FROM UVW_WIPAR02Clientident WHERE InvoiceDateTime BETWEEN @mBegdate1 AND @mEnddate1 GROUP BY clientident) AS t02 on client.ClientIdent = t02.Clientident LEFT JOIN (SELECT ClientIdent ,sum([ProgressBilledAmount]) AS ProgressBilledAmount FROM UVW_WIPAR03Clientident WHERE InvoiceDateTime BETWEEN @mBegdate1 AND @mEnddate1 GROUP BY clientident) AS t03 on client.ClientIdent = t03.Clientident LEFT JOIN (Select ClientIdent ,sum([ProgressApplyAmount]) AS ProgressApplyAmount FROM UVW_WIPAR04Clientident WHERE InvoiceDateTime BETWEEN @mBegdate1 AND @mEnddate1 GROUP BY clientident) AS t04 on client.ClientIdent = t04.Clientident LEFT JOIN (SELECT ClientIdent ,SUM(TimeWriteUpDownAmount) AS TimeWriteUpDownAmount ,SUM(ExpenseWriteUpDownAmount) AS ExpenseWriteUpDownAmount ,SUM(ISNULL(writeupdownAmount,0)) AS WriteUpDownAmount FROM UVW_WIPAR05Clientident WHERE InvoiceDateTime BETWEEN @mBegdate1 AND @mEnddate1 GROUP BY clientident) as t05 on client.ClientIdent = t05.ClientIdent LEFT JOIN (SELECT ClientIdent ,SUM(InvoiceAmount) AS InvoiceAmount ,SUM(SalesTaxAmount) AS SalesTaxAmount FROM UVW_WIPAR06Clientident WHERE InvoiceDateTime BETWEEN @mBegdate1 and @mEnddate1 GROUP BY ClientIdent) as t06 on client.ClientIdent = t06.ClientIdent LEFT JOIN (SELECT ClientIdent ,SUM(CreditAmount) AS CreditAmount ,SUM(Adjustment1Amount) AS Adjustment1Amount ,SUM(Amount4) AS Amount4 /* GST write-off */ ,SUM(Amount5) AS Amount5 /* write-off */ ,SUM(DebitAmount) AS DebitAmount ,SUM(Adjustment2Amount) AS Adjustment2Amount FROM UVW_WIPAR07Clientident WHERE transactiondatetime BETWEEN @mBegdate1 AND @mEnddate1 GROUP BY ClientIdent) as t07 on client.ClientIdent = t07.ClientIdent LEFT JOIN (SELECT ClientIdent ,sum(Charges) as [Charges] from UVW_WIPAR08Clientident where TransactionDateTime BETWEEN @mBegdate1 and @mEnddate1 GROUP BY Clientident) as t08 on client.ClientIdent = t08.ClientIdent LEFT JOIN (SELECT ClientIdent, SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @mBegdate1 AND @mEnddate1 GROUP BY clientident) AS t09 on client.ClientIdent = t09.clientident LEFT JOIN (SELECT ClientIdent ,SUM(BilledHours) AS BilledHours ,SUM(BilledAmount) AS BilledAmount FROM UVW_WIPAR10Clientident WHERE InvoiceDateTime BETWEEN @mBegdate1 AND @mEnddate1 GROUP BY ClientIdent) as t10 on client.ClientIdent = t10.clientident END GO /****** Object: StoredProcedure [dbo].[USP_MarketingReport] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_MarketingReport] @mBegdate1 DATE ,@mEnddate1 DATE ,@mActiveBegdate DATE ,@mActiveEnddate DATE ,@mShowAllClients bit /* this parameter value will either be All, or one of the firm-defined CRS positions if a CRS position name is passed in, this will be used as the primary sort field for this report, i've also added a special parameter value "FirmMarketingMethod" when this is passed in as @mCRSTitle, the report will be grouped by marketing method field */ ,@mCRSTitle varchar(32) = 'All' ,@mStaffIdentifierList VARCHAR(MAX) = '' /* if a specified list of CRS staff is selected, this will contain the list */ ,@mCRS2Title varchar(32) /* the marketing report has a column to display any one selected CRS for each client */ AS BEGIN /* this section creates a temp table to hold the comma separated 'staff' values sent in by the program. */ CREATE TABLE #tempstaff (column1 NVARCHAR(255)) INSERT INTO #tempstaff select * from [dbo].[UFN_String2Table](@mStaffIdentifierList) SELECT /* the primary sort value can be either the client marketing method or the designated Client CRS */ CASE WHEN @mCRSTitle = 'FirmMarketingMethod' THEN CASE WHEN LEN(ISNULL(CLIENT.FirmMarketingMethod,' Unassigned'))<1 THEN ' Unassigned' ELSE ISNULL(CLIENT.FirmMarketingMethod,' Unassigned') END ELSE ISNULL((SELECT STAFF.StaffName FROM CLIENTCRS LEFT JOIN STAFF ON CLIENTCRS.StaffIdent=STAFF.StaffIdent WHERE CLIENTCRS.ClientIdent=CLIENT.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription = @mCRSTitle),' Unassigned') END AS CRS1 /* the marketing report has a column to display any one selected CRS for each client */ ,ISNULL((SELECT STAFF2.StaffName FROM CLIENTCRS AS CLIENTCRS2 LEFT JOIN STAFF AS STAFF2 ON CLIENTCRS2.StaffIdent = STAFF2.StaffIdent WHERE CLIENTCRS2.ClientIdent=CLIENT.ClientIdent AND CLIENTCRS2.FirmClientStaffAssignmentDescription = @mCRS2Title),' Unassigned') AS CRS2 ,clientidsubid ,ClientSortName ,acquireddatetime ,ISNULL(t01.Time,0.00) + ISNULL(t01.Expenses,0.00) AS ProductionAmount ,ISNULL(t02.BilledAmount,0.00) + ISNULL(t03.ProgressBilledAmount,0.00) - ISNULL(t04.ProgressApplyAmount,0.00) AS InvoicedAmount ,ISNULL(t05.WriteUpDownAmount,0.00) AS WriteUpDownAmount ,ISNULL(t08.Charges,0.00) AS Charges ,ISNULL(t09.PaymentAmount,0.00) AS PaymentAmount FROM client LEFT JOIN CLIENTCRS on CLIENTCRS.ClientIdent = CLIENT.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription=@mCRSTitle LEFT JOIN STAFF on CLIENTCRS.StaffIdent = STAFF.StaffIdent /* current WIP balances */ /* wip hours, time, expenses */ LEFT JOIN (SELECT Clientident ,SUM([hours]) AS [hours] ,sum([time]) as [time] ,sum([expenses]) as [expenses] FROM UVW_WIPAR01Clientident WHERE transactiondate BETWEEN @mBegdate1 AND @mEnddate1 GROUP BY clientident) as t01 ON t01.Clientident = CLIENT.ClientIdent /* wip billed amount */ LEFT JOIN (SELECT clientident ,SUM([hours]) AS [Hours] ,SUM(StdAmount) AS [StdAmount] ,SUM([TimeAdjAmount]) AS [TimeAdjAmount] ,SUM([ExpenseAdjAmount]) AS [ExpenseAdjAmount] ,SUM([AdjAmount]) AS [AdjAmount] ,SUM([TimeBilledAmount]) AS [TimeBilledAmount] ,SUM([ExpenseBilledAmount]) AS [ExpenseBilledAmount] ,SUM([BilledAmount]) AS [BilledAmount] ,SUM([TimeCost]) AS [TimeCost] ,SUM([ExpenseCost]) AS [ExpenseCost] ,SUM([Cost]) AS [Cost] FROM UVW_WIPAR02Clientident WHERE InvoiceDateTime BETWEEN @mBegdate1 AND @mEnddate1 /* per bug 272487, this particular report will not include unposted invoices in the Invoiced amount, even though this contradicts with other reports */ AND InvoiceStatusCode = 1 GROUP BY clientident) as t02 ON t02.Clientident = CLIENT.ClientIdent /* wip progress billed */ LEFT JOIN (SELECT ClientIdent ,sum([ProgressBilledAmount]) AS ProgressBilledAmount FROM UVW_WIPAR03Clientident WHERE InvoiceDateTime BETWEEN @mBegdate1 AND @mEnddate1 GROUP BY clientident) as t03 ON t03.Clientident = CLIENT.ClientIdent /* wip progress apply */ LEFT JOIN (Select ClientIdent ,sum([ProgressApplyAmount]) AS ProgressApplyAmount FROM UVW_WIPAR04Clientident WHERE InvoiceDateTime BETWEEN @mBegdate1 AND @mEnddate1 GROUP BY clientident) as t04 ON t04.Clientident = CLIENT.ClientIdent /* wip write up-down */ LEFT JOIN (SELECT ClientIdent ,SUM(TimeWriteUpDownAmount) AS TimeWriteUpDownAmount ,SUM(ExpenseWriteUpDownAmount) AS ExpenseWriteUpDownAmount ,SUM(ISNULL(writeupdownAmount,0)) AS WriteUpDownAmount FROM UVW_WIPAR05Clientident WHERE InvoiceDateTime BETWEEN @mBegdate1 AND @mEnddate1 GROUP BY clientident) as t05 ON t05.Clientident = CLIENT.ClientIdent /* wip other charges/credits */ LEFT JOIN (SELECT ClientIdent ,SUM(Charges) AS Charges FROM UVW_WIPAR08Clientident WHERE TransactionDateTime BETWEEN @mBegdate1 AND @mEnddate1 GROUP BY Clientident) AS t08 ON t08.Clientident = CLIENT.Clientident /* payments */ LEFT JOIN (SELECT ClientIdent, SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @mBegdate1 AND @mEnddate1 /* 12-08-2019 open item 272041 - this item makes NO sense to me, but based on the user story that was written for the Marketing Report, the Cash Receipts column should not include receipts that were applied against other charges such as finance charges. This seems completely wrong, but not worth the effort to contest it so I am just going to follow the story and remove these receipts Note...this will cause the total cash receipts to be different than other reports 12-21-2019 open item 272041 - above pronouncement is reversed, so i'm commenting out the change noted above */ /* AND ARChargesIdent IS NULL */ GROUP BY clientident) as t09 ON t09.Clientident = CLIENT.ClientIdent WHERE (CASE WHEN @mCRSTitle = 'All' OR @mCRSTitle = 'FirmMarketingMethod' THEN 1 ELSE CASE WHEN STAFF.StaffIdentifier IN (SELECT column1 FROM #tempstaff) THEN 1 ELSE 0 END END) = 1 AND acquireddatetime BETWEEN @mActiveBegdate AND @mActiveEnddate AND (CASE WHEN @mShowAllClients = 1 THEN 1 ELSE CASE WHEN ISNULL(t01.Time,0.00) + ISNULL(t01.Expenses,0.00) <> 0 OR ISNULL(t02.BilledAmount,0.00) + ISNULL(t03.ProgressBilledAmount,0.00) - ISNULL(t04.ProgressApplyAmount,0.00) <> 00 OR ISNULL(t05.WriteUpDownAmount,0.00) <> 0 OR ISNULL(t09.PaymentAmount,0.00) <> 0 THEN 1 ELSE 0 END END) = 1 ORDER BY CRS1,ClientIdSubId END GO /****** Object: StoredProcedure [dbo].[USP_StaffAllowance] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_StaffAllowance] @mBegdate1 AS DATE, @mEnddate1 AS DATE, @mIncludeTime AS bit = 1, @mIncludeExpense AS bit = 0, @mIncludeReimbursable AS bit = 0, @mIncludeBillable AS bit = 0, @mIncludeNonbillable AS bit = 1, @mIncludeUnposted AS bit = 0, @mDateType AS int = 1, /* filter transactions by 0=TransactionDate 1=PostedDateTime */ @mAllowanceName1 AS varchar(32), @mServiceCode1 AS varchar(32), @mAllowanceName2 AS varchar(32), @mServiceCode2 AS varchar(32), @mAllowanceName3 AS varchar(32), @mServiceCode3 AS varchar(32), @mAllowanceName4 AS varchar(32), @mServiceCode4 AS varchar(32), @mAllowanceName5 AS varchar(32), @mServiceCode5 AS varchar(32) AS BEGIN -- this is a staff allowance summary based on a date range -- up to 5 allowances can be specified -- each allowance type needs to have one service code specified -- time card entries filtered by date SELECT STAFF.StaffIdent, STAFF.EmployeeNumber, STAFF.StaffIdentifier, STAFF.StaffUserID, (SELECT TOP 1 EmailAddress FROM STAFFEMAIL WHERE StaffIdent=t1.StaffIdent) AS StaffEmail, ISNULL(ALLOWANCE1.AnnualHours,0) AS Allowance1Hours, ISNULL(t1.Hours1,0) AS ActualHours1, ISNULL(ALLOWANCE2.AnnualHours,0) AS Allowance2Hours, ISNULL(t1.Hours2,0) AS ActualHours2, ISNULL(ALLOWANCE3.AnnualHours,0) AS Allowance3Hours, ISNULL(t1.Hours3,0) AS ActualHours3, ISNULL(ALLOWANCE4.AnnualHours,0) AS Allowance4Hours, ISNULL(t1.Hours4,0) AS ActualHours4, ISNULL(ALLOWANCE5.AnnualHours,0) AS Allowance5Hours, ISNULL(t1.Hours5,0) AS ActualHours5 FROM (SELECT WIP.StaffIdent, SUM(CASE WHEN SERVICECODE.ServiceCodeID=@mServiceCode1 THEN WIP.Hours ELSE 0 END) AS Hours1, SUM(CASE WHEN SERVICECODE.ServiceCodeID=@mServiceCode2 THEN WIP.Hours ELSE 0 END) AS Hours2, SUM(CASE WHEN SERVICECODE.ServiceCodeID=@mServiceCode3 THEN WIP.Hours ELSE 0 END) AS Hours3, SUM(CASE WHEN SERVICECODE.ServiceCodeID=@mServiceCode4 THEN WIP.Hours ELSE 0 END) AS Hours4, SUM(CASE WHEN SERVICECODE.ServiceCodeID=@mServiceCode5 THEN WIP.Hours ELSE 0 END) AS Hours5 FROM WIP LEFT JOIN SERVICECODE on wip.ServiceCodeIdent=SERVICECODE.ServiceCodeIdent WHERE /* this allows for filtering by either the TransactionDate or the PostedDateTime */ CASE WHEN @mDateType=0 THEN TransactionDate ELSE PostedDateTime END between @mBegdate1 and @mEnddate1 /* this allows for including all time, or only posted time */ AND CASE WHEN @mIncludeUnposted=1 THEN 3 ELSE TEStatusCode END = 3 AND /* 0=time 1=expenses 2=reimbursable expenses */ (CASE WHEN @mIncludeTime=1 THEN CASE WHEN WIPTypeCode=0 THEN 1 ELSE 0 END ELSE 0 END = 1 OR CASE WHEN @mIncludeExpense=1 THEN CASE WHEN WIPTypeCode=1 THEN 1 ELSE 0 END ELSE 0 END = 1 OR CASE WHEN @mIncludeReimbursable=1 THEN CASE WHEN WIPTypeCode=2 THEN 1 ELSE 0 END ELSE 0 END = 1) AND /* 0=nonbillable 1=billable */ (CASE WHEN @mIncludeBillable=1 THEN CASE WHEN IsBillableFlag=1 THEN 1 ELSE 0 END ELSE 0 END = 1 OR CASE WHEN @mIncludeNonbillable=1 THEN CASE WHEN IsBillableFlag=0 THEN 1 ELSE 0 END ELSE 0 END = 1) AND BillingStatusCode<>3 /* 3=VOIDED */ GROUP BY WIP.StaffIdent) t1 LEFT JOIN STAFF ON t1.StaffIdent=STAFF.StaffIdent LEFT JOIN STAFFALLOWANCE ALLOWANCE1 ON t1.StaffIdent=ALLOWANCE1.StaffIdent and ALLOWANCE1.AllowanceName=@mAllowanceName1 LEFT JOIN STAFFALLOWANCE ALLOWANCE2 ON t1.StaffIdent=ALLOWANCE2.StaffIdent and ALLOWANCE2.AllowanceName=@mAllowanceName2 LEFT JOIN STAFFALLOWANCE ALLOWANCE3 ON t1.StaffIdent=ALLOWANCE3.StaffIdent and ALLOWANCE3.AllowanceName=@mAllowanceName3 LEFT JOIN STAFFALLOWANCE ALLOWANCE4 ON t1.StaffIdent=ALLOWANCE4.StaffIdent and ALLOWANCE4.AllowanceName=@mAllowanceName4 LEFT JOIN STAFFALLOWANCE ALLOWANCE5 ON t1.StaffIdent=ALLOWANCE5.StaffIdent and ALLOWANCE5.AllowanceName=@mAllowanceName5 ORDER BY EmployeeNumber, StaffIdentifier END GO /****** Object: StoredProcedure [dbo].[USP_StaffProductivity] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_StaffProductivity] @mStartdate DATE ,@mEnddate DATE, /* this parameter value will either be All, or one of the firm-defined CRS positions if a CRS position name is passed in, this will be used as the primary sort field */ @mCRSTitle varchar(32) = 'All', @mStaffIdentifierList VARCHAR(MAX) = '', /* if a specified list of CRS staff is selected, this will contain the list */ @mOfficelist varchar(MAX) /* contains a list of offices in the form of IN('Office1','Office2','Office3') */ AS BEGIN /* this section creates a temp table to hold the comma separated 'staff' values sent in by the program. */ CREATE TABLE #stafftemp (column1 NVARCHAR(255)) INSERT INTO #stafftemp select * from [dbo].[UFN_String2Table](@mStaffIdentifierList) /* this will create a temporary table that holds the list of offices selected */ CREATE TABLE #officetemp (column1 NVARCHAR(255)) INSERT INTO #officetemp select * from [dbo].[UFN_String2Table](@mOfficelist) SELECT STAFFCRS.StaffIdentifier AS CRSStaffIdentifier ,STAFFCRS.ReportName AS CRSReportName ,STAFF.StaffIdentifier ,STAFF.ReportName ,CLIENT.ClientIdSubId ,CLIENT.ClientSortName ,sum(billablehours) AS sum_billablehours ,sum(BillableHoursCost) AS sum_billablehourscost ,sum(nonbillablehours) AS sum_nonbillablehours ,sum(NonBillableHoursCost) AS sum_nonbillablehourscost ,sum(allhours) as sum_allhours ,sum(AllHoursCost) AS sum_allhourscost ,sum(timeamount) AS sum_timeamount ,sum(expenseamount) AS sum_expenseamount ,sum(ExpenseCost) AS sum_expensecost ,sum(surchargeamount) AS sum_surchargeamount FROM UVW_Productivity LEFT JOIN CLIENT on client.ClientIdent=UVW_Productivity.ClientIdent LEFT JOIN STAFF on UVW_Productivity.StaffIdent=staff.StaffIdent LEFT JOIN CLIENTCRS on CLIENTCRS.ClientIdent = UVW_Productivity.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription = @mCRSTitle LEFT JOIN STAFF STAFFCRS on CLIENTCRS.StaffIdent = STAFFCRS.StaffIdent WHERE (CASE WHEN @mCRSTitle = 'All' THEN 1 ELSE CASE WHEN ISNULL(STAFFCRS.StaffIdentifier,'0') IN (SELECT column1 FROM #stafftemp) THEN 1 ELSE 0 END END) = 1 AND CLIENT.ClientOfficeName IN (SELECT column1 FROM #officetemp) AND TransactionDate between @mStartdate and @mEnddate GROUP BY STAFFCRS.StaffIdentifier ,STAFFCRS.ReportName ,STAFF.StaffIdentifier ,STAFF.ReportName ,CLIENT.ClientIdSubId ,CLIENT.ClientSortName ORDER BY STAFFCRS.ReportName ,STAFF.ReportName ,CLIENT.ClientIdSubId ,CLIENT.ClientSortName END GO /****** Object: StoredProcedure [dbo].[USP_StaffProductivityBudget] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_StaffProductivityBudget] @mStartdate AS date ,@mEnddate AS date ,@mDepartmentIdentifierList varchar(max) AS BEGIN SET NOCOUNT ON; /* this section creates a temp table to hold the comma separated 'department' values sent in by the program. */ CREATE TABLE #tempstaff (column1 NVARCHAR(255)) INSERT INTO #tempstaff select * from [dbo].[UFN_String2Table](@mDepartmentIdentifierList) SELECT staff.StaffDepartment, staff.StaffIdent, staff.ReportName, staff.StaffPosition, /* productivity */ isnull(t1.billablehours,0.00) AS pbillablehours, isnull(t1.nonbillablehours,0.00) AS pnonbillablehours, /* budget */ isnull(t2.billablehours,0.00) AS bbillablehours, isnull(t2.nonbillablehours,0.00) AS bnonbillablehours, isnull(t2.realizationpercent,0.00) AS brealizationpercent, /* billing realization */ isnull(t3.billedamount,0.00) AS billedamount, isnull(t4.writeupdownamount,0.00) AS writeupdownamount FROM staff /* productivity amounts */ LEFT JOIN (SELECT staffident, sum(BillableHours) as billablehours, sum(nonbillablehours) AS nonbillablehours FROM UVW_Productivity WHERE TransactionDate between @mStartdate and @mEnddate GROUP BY StaffIdent) AS t1 ON staff.staffident = t1.StaffIdent /* budget amounts */ LEFT JOIN (SELECT StaffIdent, sum(billablehours) AS billablehours, sum(nonbillablehours) AS nonbillablehours, AVG(realizationpercent) AS realizationpercent FROM PRODUCTIVITYGOALS WHERE GoalDateTime between @mStartdate and @mEnddate GROUP BY StaffIdent) AS t2 on staff.StaffIdent=t2.StaffIdent /* wip billed amount */ LEFT JOIN (SELECT StaffIdent ,SUM([BilledAmount]) AS [BilledAmount] FROM UVW_WIPAR02Clientident WHERE InvoiceDateTime BETWEEN @mStartdate and @mEnddate AND InvoiceStatusCode = 1 GROUP BY StaffIdent) as t3 ON staff.StaffIdent = t3.StaffIdent /* wip write up-down */ LEFT JOIN (SELECT StaffIdent ,SUM(ISNULL(writeupdownAmount,0)) AS WriteUpDownAmount FROM UVW_WIPAR05Clientident WHERE InvoiceDateTime BETWEEN @mStartdate and @mEnddate and InvoiceStatusCode=1 GROUP BY staffident) AS t4 ON staff.StaffIdent = t4.staffIdent WHERE STAFF.StaffDepartment IN (SELECT column1 FROM #tempstaff) AND (isnull(t1.billablehours,0.00) + isnull(t1.nonbillablehours,0.00) <> 0 or isnull(t3.billedamount,0.00) <> 0) ORDER BY StaffDepartment, Staff.ReportName END GO /****** Object: StoredProcedure [dbo].[USP_ThreeYearRealization] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_ThreeYearRealization] @mBegdate DATE, @mEnddate DATE, @mIncludeDeleted char(1) = 'F', /* set to T to include deleted, or set to F to exclude deleted */ /* this parameter value will either be All, or one of the firm-defined CRS positions if a CRS position name is passed in, this will be used as the primary sort field */ @mCRSTitle varchar(32) = 'All', @mStaffIdentifierList VARCHAR(MAX) = '' /* if a specified list of CRS staff is selected, this will contain the list */ AS BEGIN /* this section creates a temp table to hold the comma separated 'staff' values sent in by the program. */ CREATE TABLE #tempstaff (column1 NVARCHAR(255)) INSERT INTO #tempstaff select * from [dbo].[UFN_String2Table](@mStaffIdentifierList) SELECT ISNULL((SELECT STAFF.StaffName FROM CLIENTCRS LEFT JOIN STAFF ON CLIENTCRS.StaffIdent=STAFF.StaffIdent WHERE CLIENTCRS.ClientIdent = CLIENT.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription = @mCRSTitle),' No Selection') AS CRS1 ,ISNULL(CLIENTGROUP.ClientGroupName,' No Selection') AS ClientGroupName ,CLIENT.ClientIdSubId ,CLIENT.ClientSortName ,ISNULL(t01.Y01_ProdHours,0.00) AS [Y01_ProdHours] ,ISNULL(t01.Y01_time,0.00) /* + isnull(t01.Y01_expenses,0.00) */ AS [Y01_ProdAmount] ,ISNULL(t02.Y01_BilledHours,0.00) AS [Y01_BilledHours] ,ISNULL(t02.Y01_BilledAmount,0.00) AS [Y01_BilledAmount] ,ISNULL(t05.Y01_writeupdownamount,0.00) AS [Y01_WriteUpDownAmount] ,ISNULL(t01.Y02_ProdHours,0.00) AS [Y02_ProdHours] ,ISNULL(t01.Y02_time,0.00) /* + isnull(t01.Y02_expenses,0.00) */ AS [Y02_ProdAmount] ,ISNULL(t02.Y02_BilledHours,0.00) AS [Y02_BilledHours] ,ISNULL(t02.Y02_BilledAmount,0.00) AS [Y02_BilledAmount] ,ISNULL(t05.Y02_writeupdownamount,0.00) AS [Y02_WriteUpDownAmount] ,ISNULL(t01.Y03_ProdHours,0.00) AS [Y03_ProdHours] ,ISNULL(t01.Y03_time,0.00) /* + isnull(t01.Y03_expenses,0.00) */ AS [Y03_ProdAmount] ,ISNULL(t02.Y03_BilledHours,0.00) AS [Y03_BilledHours] ,ISNULL(t02.Y03_BilledAmount,0.00) AS [Y03_BilledAmount] ,ISNULL(t05.Y03_writeupdownamount,0.00) AS [Y03_WriteUpDownAmount] FROM CLIENT LEFT JOIN CLIENTCRS on CLIENTCRS.ClientIdent = CLIENT.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription=@mCRSTitle LEFT JOIN STAFF on CLIENTCRS.StaffIdent = STAFF.StaffIdent LEFT JOIN CLIENTGROUP ON CLIENT.ClientIdent = CLIENTGROUP.ClientIdent AND FinancialReportingGroupFlag = 'T' /* this gets "production" amounts, not related to billed amounts */ LEFT JOIN (SELECT Clientident ,sum(CASE WHEN YEAR(TransactionDate)=YEAR(@mEnddate) THEN [hours] ELSE 0 END) as [Y01_ProdHours] ,sum(CASE WHEN YEAR(TransactionDate)=YEAR(@mEnddate)-1 THEN [hours] ELSE 0 END) as [Y02_ProdHours] ,sum(CASE WHEN YEAR(TransactionDate)=YEAR(@mEnddate)-2 THEN [hours] ELSE 0 END) as [Y03_ProdHours] ,sum(CASE WHEN YEAR(TransactionDate)=YEAR(@mEnddate) THEN [time] ELSE 0 END) as [Y01_Time] ,sum(CASE WHEN YEAR(TransactionDate)=YEAR(@mEnddate)-1 THEN [time] ELSE 0 END) as [Y02_Time] ,sum(CASE WHEN YEAR(TransactionDate)=YEAR(@mEnddate)-2 THEN [time] ELSE 0 END) as [Y03_Time] /* ,sum(CASE WHEN YEAR(TransactionDate)=YEAR(@mEnddate) THEN [expenses] ELSE 0 END) as [Y01_Expenses] ,sum(CASE WHEN YEAR(TransactionDate)=YEAR(@mEnddate)-1 THEN [expenses] ELSE 0 END) as [Y02_Expenses] ,sum(CASE WHEN YEAR(TransactionDate)=YEAR(@mEnddate)-2 THEN [expenses] ELSE 0 END) as [Y03_Expenses] */ FROM UVW_WIPAR01Clientident WHERE TransactionDate BETWEEN @mBegdate AND @mEnddate GROUP BY clientident ) as t01 ON t01.Clientident = client.ClientIdent /* returns billed amounts */ LEFT JOIN (SELECT clientident ,SUM(CASE WHEN YEAR(InvoiceDateTime)=YEAR(@mEnddate) THEN [hours] ELSE 0 END) AS [Y01_BilledHours] ,SUM(CASE WHEN YEAR(InvoiceDateTime)=YEAR(@mEnddate)-1 THEN [hours] ELSE 0 END) AS [Y02_BilledHours] ,SUM(CASE WHEN YEAR(InvoiceDateTime)=YEAR(@mEnddate)-2 THEN [hours] ELSE 0 END) AS [Y03_BilledHours] ,SUM(CASE WHEN YEAR(InvoiceDateTime)=YEAR(@mEnddate) THEN [TimeBilledAmount] ELSE 0 END) AS [Y01_BilledAmount] ,SUM(CASE WHEN YEAR(InvoiceDateTime)=YEAR(@mEnddate)-1 THEN [TimeBilledAmount] ELSE 0 END) AS [Y02_BilledAmount] ,SUM(CASE WHEN YEAR(InvoiceDateTime)=YEAR(@mEnddate)-2 THEN [TimeBilledAmount] ELSE 0 END) AS [Y03_BilledAmount] FROM UVW_WIPAR02Clientident WHERE InvoiceDateTime BETWEEN @mBegdate AND @mEnddate AND InvoiceStatusCode = 1 GROUP BY clientident ) AS t02 ON t02.clientident = client.clientident /* returns field WriteUpDownAmount */ LEFT JOIN (SELECT ClientIdent ,SUM(CASE WHEN YEAR(InvoiceDateTime)=YEAR(@mEnddate) THEN ISNULL(TimeWriteUpDownAmount,0) ELSE 0 END) AS Y01_WriteUpDownAmount ,SUM(CASE WHEN YEAR(InvoiceDateTime)=YEAR(@mEnddate)-1 THEN ISNULL(TimeWriteUpDownAmount,0) ELSE 0 END) AS Y02_WriteUpDownAmount ,SUM(CASE WHEN YEAR(InvoiceDateTime)=YEAR(@mEnddate)-2 THEN ISNULL(TimeWriteUpDownAmount,0) ELSE 0 END) AS Y03_WriteUpDownAmount FROM UVW_WIPAR05Clientident WHERE InvoiceDateTime BETWEEN @mBegdate AND @mEnddate AND InvoiceStatusCode = 1 GROUP BY clientident ) AS t05 on t05.ClientIdent = client.ClientIdent WHERE ( ISNULL(t01.Y01_ProdHours,0.00) <> 0 OR ISNULL(t01.Y01_time,0.00) /* +ISNULL(t01.Y01_expenses,0.00) */ <> 0 OR ISNULL(t02.Y01_BilledHours,0.00) <> 0.00 OR ISNULL(t02.Y01_BilledAmount,0.00) <> 0.00 OR ISNULL(t05.Y01_writeupdownamount,0.00) <> 0.00 OR ISNULL(t01.Y02_ProdHours,0.00) <> 0 OR ISNULL(t01.Y02_time,0.00) /* +ISNULL(t01.Y02_expenses,0.00) */ <> 0 OR ISNULL(t02.Y02_BilledHours,0.00) <> 0.00 OR ISNULL(t02.Y02_BilledAmount,0.00) <> 0.00 OR ISNULL(t05.Y02_writeupdownamount,0.00) <> 0.00 OR ISNULL(t01.Y03_ProdHours,0.00) <> 0 OR ISNULL(t01.Y03_time,0.00) /* +ISNULL(t01.Y03_expenses,0.00) */ <> 0 OR ISNULL(t02.Y03_BilledHours,0.00) <> 0.00 OR ISNULL(t02.Y03_BilledAmount,0.00) <> 0.00 OR ISNULL(t05.Y03_writeupdownamount,0.00) <> 0.00 ) AND (client.deleteflag = 'F' OR client.deleteflag = @mIncludeDeleted) AND (CASE WHEN @mCRSTitle = 'All' THEN 1 ELSE CASE WHEN ISNULL(STAFF.StaffIdentifier,'0') IN (SELECT column1 FROM #tempstaff) THEN 1 ELSE 0 END END) = 1 ORDER BY CRS1 ,ISNULL(CLIENTGROUP.ClientGroupName,' No Selection') ,CLIENT.ClientIdSubId END GO /****** Object: StoredProcedure [dbo].[USP_TimeAndExpense] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_TimeAndExpense] @mStartdate DATE ,@mEnddate DATE ,@mExcludeNonbillable bit = 1 /* exclude nonbillable */ AS BEGIN /* this query gives the same results as the built-in report Staff Time Analysis verified 03-04-2019 07-29-2020 apparently this query/report is based on a custom report written for 794328 because it uses a strange field CLIENT.SubOrdinateDescription which is not commonly used. ultimately, this report should probably be removed because it is too customized and does not follow a standard report layout the only real value is that the results agree with the Staff Time Analysis report */ -- this gets the primary partner responsibility designation DECLARE @responsibilityname AS varchar(32) = (SELECT [value] FROM FirmOptions WHERE [name] = 'PPCRS') SELECT ISNULL(STAFF2.ReportName,'No Selection') as PartnerName ,STAFF1.StaffPosition ,STAFF1.ReportName ,SUM(WIP.AdjAmount) AS AdjAmount ,SUM(WIP.[Hours]) AS [Hours] FROM WIP LEFT JOIN STAFF AS STAFF1 ON WIP.StaffIdent=STAFF1.StaffIdent LEFT JOIN CLIENT ON WIP.ClientIdent=CLIENT.ClientIdent /* this gets the CRS staff info */ LEFT JOIN CLIENTCRS AS CRS2 ON CRS2.ClientIdent = CLIENT.ClientIdent AND CRS2.[FirmClientStaffAssignmentDescription] = @responsibilityname LEFT JOIN STAFF AS STAFF2 ON STAFF2.[StaffIdent] = CRS2.[StaffIdent] WHERE TransactionDate >= @mStartdate AND TransactionDate < DATEADD(d,1,@mEnddate) AND WIP.WIPTypeCode=0 /* 0=time */ AND (CASE WHEN @mExcludeNonbillable=1 THEN (CASE WHEN WIP.IsBillableFlag=0 THEN 0 ELSE 1 END) ELSE 1 END = 1) AND WIP.TEStatusCode=3 /* 3=posted */ AND WIP.BillingStatusCode NOT IN (1,3) /* 1=History 3=Void */ GROUP BY ISNULL(Staff2.ReportName,'No Selection') --,ISNULL(CLIENT.SubOrdinateDescription,'No Selection') ,STAFF1.StaffPosition ,STAFF1.ReportName ORDER BY PartnerName ,STAFF1.StaffPosition ,STAFF1.ReportName END GO /****** Object: StoredProcedure [dbo].[USP_TimeCardDetail] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_TimeCardDetail] @mBegdate DATE ,@mEnddate DATE ,@mDatetype smallint = 0 /* 0=TransactionDate 1=PostedDateTime */ AS BEGIN SET NOCOUNT ON; SELECT STAFF.StaffIdentifier ,STAFF.ReportName ,convert(varchar(10),WIP.TransactionDate,101) AS TransactionDate ,convert(varchar(10),WIP.PostedDateTime,101) AS PostedDateTime ,SERVICECODE.ServiceCodeID ,CASE WHEN WIP.IsBillableFlag=1 THEN [Hours] ELSE 0 END AS Billable ,CASE WHEN WIP.IsBillableFlag=0 THEN [Hours] ELSE 0 END AS NonBillable ,CASE WHEN WIP.TEStatusCode=0 THEN [Hours] ELSE 0 END AS Unreleased ,CASE WHEN WIP.TEStatusCode=1 THEN [Hours] ELSE 0 END AS Released ,CASE WHEN WIP.TEStatusCode=2 THEN [Hours] ELSE 0 END AS Reviewed ,CASE WHEN WIP.TEStatusCode=3 THEN [Hours] ELSE 0 END AS Posted FROM WIP LEFT JOIN SERVICECODE ON WIP.ServiceCodeIdent = SERVICECODE.ServiceCodeIdent LEFT JOIN STAFF ON WIP.StaffIdent=STAFF.StaffIdent WHERE CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END BETWEEN @mBegdate AND @mEnddate AND WIP.WIPTypeCode=0 /* 0=Time */ AND (WIP.BillingStatusCode=0 OR WIP.BillingStatusCode=2) /* 0=Unbilled 1=History 2=Final Billed */ ORDER BY ReportName,CASE WHEN @mDatetype=1 THEN WIP.PostedDateTime ELSE WIP.TransactionDate END END GO /****** Object: StoredProcedure [dbo].[USP_TimeCardExport] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_TimeCardExport] @mBegdate1 AS DATE, /* this is the PROJECT date range example: 04/01/2019 */ @mEnddate1 AS DATE, /* this is the PROJECT date range example: 06/30/2020 */ @mIncludeTime AS bit, @mIncludeExpense AS bit, @mIncludeReimbursable AS bit, @mIncludeBillable AS bit, @mIncludeNonbillable AS bit, @mIncludeUnposted AS bit AS BEGIN /* note.....this query has been tested and verified against the built-in report "Daily Staff Posted Hours" */ SELECT EmployeeNumber, StaffIdentifier, StaffLastName, StaffFirstName, StaffPosition, ClientIdSubId, ClientSortName, CategoryName, SubCategoryName, ServiceCodeID, ServiceCodeName, CONVERT(varchar, TransactionDate, 101) AS TransactionDate, Hours, Amount, InvoiceDescription, CASE WipTypeCode WHEN 0 THEN 'Time' WHEN 1 THEN 'Expense' WHEN 2 THEN 'Reimbursable' END AS WipTypeDescription, CASE TEStatusCode WHEN 3 THEN 'Posted' ELSE 'Unposted' END AS WipStatus FROM [UVW_TimeCardExport] WHERE TransactionDate between @mBegdate1 and @mEnddate1 /* this allows for including all time, or only posted time */ AND CASE WHEN @mIncludeUnposted=1 THEN 3 ELSE TEStatusCode END = 3 AND /* 0=time 1=expenses 2=reimbursable expenses */ (CASE WHEN @mIncludeTime=1 THEN CASE WHEN WIPTypeCode=0 THEN 1 ELSE 0 END ELSE 0 END = 1 OR CASE WHEN @mIncludeExpense=1 THEN CASE WHEN WIPTypeCode=1 THEN 1 ELSE 0 END ELSE 0 END = 1 OR CASE WHEN @mIncludeReimbursable=1 THEN CASE WHEN WIPTypeCode=2 THEN 1 ELSE 0 END ELSE 0 END = 1) AND /* 0=nonbillable 1=billable */ (CASE WHEN @mIncludeBillable=1 THEN CASE WHEN IsBillableFlag=1 THEN 1 ELSE 0 END ELSE 0 END = 1 OR CASE WHEN @mIncludeNonbillable=1 THEN CASE WHEN IsBillableFlag=0 THEN 1 ELSE 0 END ELSE 0 END = 1) ORDER BY EmployeeNumber,StaffIdentifier,TransactionDate,ClientSortName END GO /****** Object: StoredProcedure [dbo].[USP_TimesheetDaily] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_TimesheetDaily] @mStartdate DATE ,@mEnddate DATE ,@mExcludeNonbillable bit = 0 /* exclude nonbillable */ /* 03-15-2024 added ability to create an interoffice report which shows any time where the client office and the staff office are different report allows filtering by office */ ,@mInteroffice bit = 0 /* interoffice report (client office and staff office are different) */ ,@mClientoffice varchar(32) = 'All' /* this is applicable for interoffice report */ ,@mStaffoffice varchar(32) = 'All' /* this is applicable for interoffice report */ AS BEGIN /* this query gives the same results as the built-in report Staff Time Analysis verified 03-04-2019 and 03-15-2024 */ SELECT STAFF1.StaffOfficeName ,STAFF1.StaffIdentifier ,STAFF1.ReportName ,CLIENT.ClientIdSubId ,CLIENT.ClientSortName ,CLIENT.ClientOfficeName ,SERVICECODE.ServiceCodeId ,SERVICECODE.ServiceCodeName ,WIP.TransactionDate ,WIP.[Hours] ,WIP.AdjAmount FROM WIP LEFT JOIN STAFF AS STAFF1 ON WIP.StaffIdent=STAFF1.StaffIdent LEFT JOIN CLIENT ON WIP.ClientIdent=CLIENT.ClientIdent LEFT JOIN SERVICECODE ON WIP.ServiceCodeIdent=SERVICECODE.ServiceCodeIdent WHERE TransactionDate >= @mStartdate AND TransactionDate < DATEADD(d,1,@mEnddate) AND WIP.WIPTypeCode=0 /* 0=time */ AND (CASE WHEN @mExcludeNonbillable=1 THEN (CASE WHEN WIP.IsBillableFlag=0 THEN 0 ELSE 1 END) ELSE 1 END = 1) AND WIP.TEStatusCode=3 /* 3=posted */ AND WIP.BillingStatusCode NOT IN (1,3) /* 1=History 3=Void */ AND CASE WHEN @mInteroffice=1 THEN CASE WHEN STAFF1.StaffOfficeName<>CLIENT.ClientOfficeName THEN 1 ELSE 0 END ELSE 1 END = 1 AND CASE WHEN @mClientOffice<>'All' THEN CASE WHEN CLIENT.ClientOfficeName=@mClientoffice THEN 1 ELSE 0 END ELSE 1 END = 1 AND CASE WHEN @mStaffOffice<>'All' THEN CASE WHEN STAFF1.StaffOfficeName=@mStaffoffice THEN 1 ELSE 0 END ELSE 1 END = 1 ORDER BY STAFF1.ReportName ,WIP.TransactionDate END GO /****** Object: StoredProcedure [dbo].[USP_WIPAging] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_WIPAging] @mEnddate DATETIME, @mBucketdays int = 30, /* was 180 */ /* this parameter value will either be All, or one of the firm-defined CRS positions if a CRS position name is passed in, this will be used as the primary sort field */ @mCRSTitle varchar(32) = 'All', @mStaffIdentifierList VARCHAR(MAX) = '' /* if a specified list of CRS staff is selected, this will contain the list */ AS BEGIN SET NOCOUNT ON; /* this section creates a temp table to hold the comma separated 'staff' values sent in by the program. */ CREATE TABLE #tempstaff (column1 NVARCHAR(255)) INSERT INTO #tempstaff select * from [dbo].[UFN_String2Table](@mStaffIdentifierList) SELECT ISNULL((SELECT STAFF.StaffName FROM CLIENTCRS LEFT JOIN STAFF ON CLIENTCRS.StaffIdent=STAFF.StaffIdent WHERE ClientIdent=T99.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription = @mCRSTitle),' No Selection') AS CRS1, Client.ClientIdSubId, Client.ClientSortName, T99.AgingAmount, T99.T01, T99.T02, T99.T03, T99.T04 FROM (SELECT ClientIdent, SUM(AgingAmount) AS AgingAmount, SUM(CASE WHEN DATEDIFF(d,AgingDate,@mEnddate)+1 <= @mBucketdays THEN AgingAmount else 0 end) as T01, SUM(CASE WHEN DATEDIFF(d,AgingDate,@mEnddate)+1 BETWEEN (@mBucketdays + 1) AND (@mBucketdays * 2) THEN AgingAmount else 0 end) as T02, SUM(CASE WHEN DATEDIFF(d,AgingDate,@mEnddate)+1 BETWEEN (@mBucketdays * 2 + 1) AND (@mBucketdays * 3) THEN AgingAmount else 0 end) as T03, SUM(CASE WHEN DATEDIFF(d,AgingDate,@mEnddate)+1 >= (@mBucketdays * 3 + 1) THEN AgingAmount else 0 end) as T04 FROM UVW_WIPAgingDetail WHERE BalanceDate <= @mEnddate GROUP BY ClientIdent HAVING SUM(AgingAmount)<>0 ) AS T99 LEFT JOIN Client ON client.ClientIdent=T99.ClientIdent LEFT JOIN CLIENTCRS on CLIENTCRS.ClientIdent = CLIENT.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription=@mCRSTitle LEFT JOIN STAFF on CLIENTCRS.StaffIdent = STAFF.StaffIdent WHERE (CASE WHEN @mCRSTitle = 'All' THEN 1 ELSE CASE WHEN ISNULL(STAFF.StaffIdentifier,'0') IN (SELECT column1 FROM #tempstaff) THEN 1 ELSE 0 END END) = 1 ORDER BY CRS1,ClientIdSubId END GO /****** Object: StoredProcedure [dbo].[USP_WIPAgingProject] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_WIPAgingProject] @mEnddate DATETIME, @mBucketdays int = 30, /* was 180 */ /* this parameter must receive one of the valid firm-defined PRP positions */ @mPRPTitle varchar(32) AS BEGIN SET NOCOUNT ON; /* note....this stored proc follows the SAME logic as USP_WIPAging, but adds an extra layer of detail for Project also, instead of the CRS filter, this proc uses the project role */ SELECT ISNULL(STAFF.StaffName,' No Selection') AS PRP1, Client.ClientIdSubId, Client.ClientSortName, ISNULL(p.ProjectCode, ' Unassigned') AS ProjectCode, ISNULL(p.ProjectName, ' Unassigned') AS ProjectName, ISNULL(p.ProjectStatus, '') AS ProjectStatus, T99.AgingAmount, T99.T01, T99.T02, T99.T03, T99.T04 FROM (SELECT ClientIdent, ISNULL(ProjectIdent,0) AS ProjectIdent, SUM(AgingAmount) AS AgingAmount, SUM(CASE WHEN DATEDIFF(d,AgingDate,@mEnddate)+1 <= @mBucketdays THEN AgingAmount else 0 end) as T01, SUM(CASE WHEN DATEDIFF(d,AgingDate,@mEnddate)+1 BETWEEN (@mBucketdays + 1) AND (@mBucketdays * 2) THEN AgingAmount else 0 end) as T02, SUM(CASE WHEN DATEDIFF(d,AgingDate,@mEnddate)+1 BETWEEN (@mBucketdays * 2 + 1) AND (@mBucketdays * 3) THEN AgingAmount else 0 end) as T03, SUM(CASE WHEN DATEDIFF(d,AgingDate,@mEnddate)+1 >= (@mBucketdays * 3 + 1) THEN AgingAmount else 0 end) as T04 FROM UVW_WIPAgingDetail WHERE BalanceDate <= @mEnddate GROUP BY ClientIdent,ISNULL(ProjectIdent,0) HAVING SUM(AgingAmount)<>0 ) AS T99 LEFT JOIN Client ON client.ClientIdent=T99.ClientIdent LEFT JOIN INTERIMWORKINGPROJECT p ON p.InterimWorkingProjectIdent = T99.ProjectIdent LEFT JOIN INTERIMWORKINGPROJECTROLEASSIGNEE prp on prp.InterimWorkingProjectIdent = p.InterimWorkingProjectIdent AND prp.ProjectRoleName = @mPRPTitle LEFT JOIN STAFF on STAFF.StaffIdent = prp.StaffIdent ORDER BY PRP1,ClientIdSubId,p.ProjectCode END GO /****** Object: StoredProcedure [dbo].[USP_WIPARReconciliation] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_WIPARReconciliation] @mBegdate1 AS DATE /* current balance date range */ ,@mEnddate1 AS DATE /* current balance date range */ /* this parameter value will either be All, or one of the firm-defined CRS positions if a CRS position name is passed in, this will be used as the primary sort field */ ,@mCRSTitle varchar(32) = 'All' ,@mStaffIdentifierList VARCHAR(MAX) = '' /* if a specified list of CRS staff is selected, this will contain the list */ ,@mSortOrder AS INT = 0 /* 0 = sort by clientid, 1 = sort by clientsortname */ ,@mIncludeDeleted CHAR(1) = 'F' /* set to F to exclude deleted, or set to T to include deleted */ ,@mOfficelist varchar(MAX) /* contains a list of offices in the form of IN('Office1','Office2','Office3') */ AS BEGIN DECLARE @mBegdate0 DATE = '01/01/1900' /* prior balance date range begin */ DECLARE @mEnddate0 DATE = DATEADD(d,-1,@mBegdate1) /* prior balance date range end */ /* this section creates a temp table to hold the comma separated 'staff' values sent in by the program. */ CREATE TABLE #tempstaff (column1 NVARCHAR(255)) INSERT INTO #tempstaff select * from [dbo].[UFN_String2Table](@mStaffIdentifierList) /* this will create a temporary table that holds the list of offices selected */ CREATE TABLE #officetemp (column1 NVARCHAR(255)) INSERT INTO #officetemp select * from [dbo].[UFN_String2Table](@mOfficelist) SELECT ISNULL((SELECT STAFF.StaffName FROM CLIENTCRS LEFT JOIN STAFF ON CLIENTCRS.StaffIdent=STAFF.StaffIdent WHERE ClientIdent=CLIENT.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription = @mCRSTitle),' No Selection') AS CRS1 ,[CLIENT].ClientIdSubId ,[Client].ClientSortName /* WIP fields for report */ ,t1.p_time + t1.p_expenses - t1.p_BilledAmount - t1.p_ProgressBilledAmount + t1.p_ProgressApplyAmount + t1.p_WriteUpDownAmount AS p_wipbeginbalance ,t1.c_hours ,t1.c_time ,t1.c_expenses ,t1.c_BilledAmount + t1.c_ProgressBilledAmount - t1.c_ProgressApplyAmount AS c_billings ,t1.c_writeupdownamount ,CASE WHeN (c_BilledAmount + c_ProgressBilledAmount - c_ProgressApplyAmount - c_WriteUpDownAmount) = 0 THEN 0 ELSE (c_BilledAmount + c_ProgressBilledAmount - c_ProgressApplyAmount) END / CASE WHEN (c_BilledAmount + c_ProgressBilledAmount - c_ProgressApplyAmount - c_WriteUpDownAmount) = 0 THEN 1 ELSE (c_BilledAmount + c_ProgressBilledAmount - c_ProgressApplyAmount - c_WriteUpDownAmount) END AS c_realpercent ,t1.p_time + t1.p_expenses - t1.p_BilledAmount - t1.p_ProgressBilledAmount + t1.p_ProgressApplyAmount + t1.p_WriteUpDownAmount + t1.c_time + t1.c_expenses - t1.c_BilledAmount - t1.c_ProgressBilledAmount + t1.c_ProgressApplyAmount + t1.c_WriteUpDownAmount AS c_wipendbalance /* AR fields for report */ ,t1.p_invoiceamount + t1.p_salestaxamount + t1.p_creditamount + t1.p_adjustment1amount + t1.p_debitamount + t1.p_adjustment2amount + t1.p_amount4 + t1.p_amount5 + t1.p_charges - t1.p_paymentamount AS p_arbeginbalance ,t1.c_invoiceamount + t1.c_salestaxamount AS c_invoiceamount ,t1.c_creditamount + t1.c_adjustment1amount + t1.c_debitamount + t1.c_adjustment2amount + t1.c_amount4 + t1.c_amount5 + t1.c_charges AS c_adjustments ,t1.c_paymentamount ,t1.p_invoiceamount + t1.p_salestaxamount + t1.p_creditamount + t1.p_adjustment1amount + t1.p_debitamount + t1.p_adjustment2amount + t1.p_amount4 + t1.p_amount5 + t1.p_charges - t1.p_paymentamount + t1.c_invoiceamount + t1.c_salestaxamount + t1.c_creditamount + t1.c_adjustment1amount + t1.c_debitamount + t1.c_adjustment2amount + t1.c_amount4 + t1.c_amount5 + t1.c_charges - t1.c_paymentamount AS c_arendbalance FROM (SELECT t00.ClientIdent ,ISNULL(t04.[time],0.00) as p_time ,ISNULL(t04.expenses,0.00) as p_expenses ,ISNULL(t05.BilledAmount,0.00) as p_billedamount ,ISNULL(t06.ProgressBilledAmount,0.00) as p_progressbilledamount ,ISNULL(t07.ProgressApplyAmount,0.00) as p_progressapplyamount ,ISNULL(t08.writeupdownamount,0.00) as p_writeupdownamount ,ISNULL(t19a.invoiceamount,0.00) as p_invoiceamount ,ISNULL(t19a.salestaxamount,0.00) AS p_salestaxamount /* on the WIPAR Rec report, the next 6 numbers are added together to give the "adjust" column */ ,ISNULL(t20a.creditamount,0.00) AS p_creditamount ,ISNULL(t20a.adjustment1amount,0.00) AS p_adjustment1amount ,ISNULL(t20a.debitamount,0.00) AS p_debitamount ,ISNULL(t20a.adjustment2amount,0.00) AS p_adjustment2amount ,ISNULL(t20a.amount4,0.00) AS p_amount4 ,ISNULL(t20a.amount5,0.00) AS p_amount5 ,ISNULL(t21a.charges,0.00) AS p_charges ,ISNULL(t22a.PaymentAmount,0.00) AS p_paymentamount ,ISNULL(t14.[hours],0.00) as c_hours ,ISNULL(t14.[time],0.00) as c_time ,ISNULL(t14.expenses,0.00) as c_expenses ,ISNULL(t15.BilledAmount,0.00) as c_billedamount ,ISNULL(t16.ProgressBilledAmount,0.00) as c_progressbilledamount ,ISNULL(t17.ProgressApplyAmount,0.00) as c_progressapplyamount ,ISNULL(t18.writeupdownamount,0.00) as c_writeupdownamount ,ISNULL(t19.invoiceamount,0.00) as c_invoiceamount ,ISNULL(t19.salestaxamount,0.00) AS c_salestaxamount /* on the WIPAR Rec report, the next 6 numbers are added together to give the "adjust" column */ ,ISNULL(t20.creditamount,0.00) AS c_creditamount ,ISNULL(t20.adjustment1amount,0.00) AS c_adjustment1amount ,ISNULL(t20.debitamount,0.00) AS c_debitamount ,ISNULL(t20.adjustment2amount,0.00) AS c_adjustment2amount ,ISNULL(t20.amount4,0.00) AS c_amount4 ,ISNULL(t20.amount5,0.00) AS c_amount5 ,ISNULL(t21.charges,0.00) AS c_charges ,ISNULL(t22.PaymentAmount,0.00) AS c_paymentamount FROM /* this is the main report driver select */ (SELECT clientident FROM CLIENT) AS t00 /* previous WIP balances */ /* wip hours, time, expenses */ LEFT JOIN (SELECT Clientident ,SUM([hours]) AS [hours] ,sum([time]) as [time] ,sum([expenses]) as [expenses] FROM UVW_WIPAR01Clientident WHERE transactiondate BETWEEN @mBegdate0 AND @mEnddate0 GROUP BY clientident) as t04 ON t04.Clientident = t00.ClientIdent /* wip billed amount */ LEFT JOIN (SELECT clientident ,SUM([hours]) AS [Hours] ,SUM(StdAmount) AS [StdAmount] ,SUM([TimeAdjAmount]) AS [TimeAdjAmount] ,SUM([ExpenseAdjAmount]) AS [ExpenseAdjAmount] ,SUM([AdjAmount]) AS [AdjAmount] ,SUM([TimeBilledAmount]) AS [TimeBilledAmount] ,SUM([ExpenseBilledAmount]) AS [ExpenseBilledAmount] ,SUM([BilledAmount]) AS [BilledAmount] ,SUM([TimeCost]) AS [TimeCost] ,SUM([ExpenseCost]) AS [ExpenseCost] ,SUM([Cost]) AS [Cost] FROM UVW_WIPAR02Clientident WHERE InvoiceDateTime BETWEEN @mBegdate0 AND @mEnddate0 /* per bug xxx, amounts should only be considered billed when the invoice is posted */ AND InvoiceStatusCode = 1 GROUP BY clientident) as t05 ON t05.Clientident = t00.ClientIdent /* wip progress billed */ LEFT JOIN (SELECT ClientIdent ,sum([ProgressBilledAmount]) AS ProgressBilledAmount FROM UVW_WIPAR03Clientident WHERE InvoiceDateTime BETWEEN @mBegdate0 AND @mEnddate0 AND InvoiceStatusCode = 1 /* progress billed is only included if the invoice is posted */ GROUP BY clientident) AS t06 ON t06.Clientident = t00.ClientIdent /* wip progress apply */ LEFT JOIN (Select ClientIdent ,sum([ProgressApplyAmount]) AS ProgressApplyAmount FROM UVW_WIPAR04Clientident WHERE InvoiceDateTime BETWEEN @mBegdate0 AND @mEnddate0 AND InvoiceStatusCode = 1 /* progress apply is only included if the invoice is posted */ GROUP BY clientident) AS t07 ON t07.Clientident = t00.ClientIdent /* wip write up-down */ LEFT JOIN (SELECT ClientIdent ,SUM(TimeWriteUpDownAmount) AS TimeWriteUpDownAmount ,SUM(ExpenseWriteUpDownAmount) AS ExpenseWriteUpDownAmount ,SUM(ISNULL(writeupdownAmount,0)) AS WriteUpDownAmount FROM UVW_WIPAR05Clientident WHERE InvoiceDateTime BETWEEN @mBegdate0 AND @mEnddate0 /* 04/11/2024 note...the "Billing Report" does not have this line, so if they have unposted invoices, it can result in different Write Up/Dn balance */ and InvoiceStatusCode=1 /* write up/down is only included if the invoice is posted */ GROUP BY clientident) AS t08 ON t08.Clientident = t00.ClientIdent /* previous AR balances */ /* ar invoice */ LEFT JOIN (SELECT ClientIdent ,SUM(InvoiceAmount) AS InvoiceAmount ,SUM(SalesTaxAmount) AS SalesTaxAmount FROM UVW_WIPAR06Clientident WHERE InvoiceDateTime BETWEEN @mBegdate0 and @mEnddate0 GROUP BY ClientIdent) as t19a ON t19a.Clientident = t00.ClientIdent /* ar write-offs and adjustments */ LEFT JOIN (SELECT ClientIdent ,SUM(CreditAmount) AS CreditAmount ,SUM(Adjustment1Amount) AS Adjustment1Amount ,SUM(Amount4) AS Amount4 /* GST write-off */ ,SUM(Amount5) AS Amount5 /* write-off */ ,SUM(DebitAmount) AS DebitAmount ,SUM(Adjustment2Amount) AS Adjustment2Amount FROM UVW_WIPAR07Clientident WHERE transactiondatetime BETWEEN @mBegdate0 AND @mEnddate0 GROUP BY ClientIdent) as t20a ON t20a.Clientident = t00.ClientIdent /* ar fin chg */ LEFT JOIN (SELECT ClientIdent ,sum(Charges) as [Charges] from UVW_WIPAR08Clientident where TransactionDateTime BETWEEN @mBegdate0 and @mEnddate0 GROUP BY Clientident) as t21a ON t21a.Clientident = t00.ClientIdent /* ar payments */ LEFT JOIN (SELECT ClientIdent, SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @mBegdate0 AND @mEnddate0 GROUP BY clientident) AS t22a ON t22a.Clientident = t00.Clientident /* total billable wip (billed or unbilled) */ /* wip hours, time, expenses */ LEFT JOIN (SELECT Clientident ,SUM([hours]) AS [hours] ,sum([time]) as [time] ,sum([expenses]) as [expenses] FROM UVW_WIPAR01Clientident WHERE transactiondate BETWEEN @mBegdate1 AND @mEnddate1 GROUP BY clientident) AS t14 ON t14.Clientident = t00.ClientIdent /* wip billed amount */ LEFT JOIN (SELECT clientident ,SUM([hours]) AS [Hours] ,SUM(StdAmount) AS [StdAmount] ,SUM([TimeAdjAmount]) AS [TimeAdjAmount] ,SUM([ExpenseAdjAmount]) AS [ExpenseAdjAmount] ,SUM([AdjAmount]) AS [AdjAmount] ,SUM([TimeBilledAmount]) AS [TimeBilledAmount] ,SUM([ExpenseBilledAmount]) AS [ExpenseBilledAmount] ,SUM([BilledAmount]) AS [BilledAmount] ,SUM([TimeCost]) AS [TimeCost] ,SUM([ExpenseCost]) AS [ExpenseCost] ,SUM([Cost]) AS [Cost] FROM UVW_WIPAR02Clientident WHERE InvoiceDateTime BETWEEN @mBegdate1 AND @mEnddate1 /* amounts should only be considered billed when the invoice is posted */ AND InvoiceStatusCode = 1 GROUP BY clientident) as t15 ON t15.Clientident = t00.ClientIdent /* wip progress billed */ LEFT JOIN (SELECT ClientIdent ,sum([ProgressBilledAmount]) AS ProgressBilledAmount FROM UVW_WIPAR03Clientident WHERE InvoiceDateTime BETWEEN @mBegdate1 AND @mEnddate1 AND InvoiceStatusCode = 1 GROUP BY clientident) as t16 ON t16.Clientident = t00.ClientIdent /* wip progress apply */ LEFT JOIN (Select ClientIdent ,sum([ProgressApplyAmount]) AS ProgressApplyAmount FROM UVW_WIPAR04Clientident WHERE InvoiceDateTime BETWEEN @mBegdate1 AND @mEnddate1 AND InvoiceStatusCode = 1 GROUP BY clientident) AS t17 ON t17.Clientident = t00.ClientIdent /* wip write up-down */ LEFT JOIN (SELECT ClientIdent ,SUM(TimeWriteUpDownAmount) AS TimeWriteUpDownAmount ,SUM(ExpenseWriteUpDownAmount) AS ExpenseWriteUpDownAmount ,SUM(ISNULL(writeupdownAmount,0)) AS WriteUpDownAmount FROM UVW_WIPAR05Clientident WHERE InvoiceDateTime BETWEEN @mBegdate1 AND @mEnddate1 and InvoiceStatusCode=1 /* write up/down is only included if the invoice is posted */ GROUP BY clientident) AS t18 ON t18.Clientident = t00.ClientIdent /* current AR balances */ /* ar invoice */ LEFT JOIN (SELECT ClientIdent ,SUM(InvoiceAmount) AS InvoiceAmount ,SUM(SalesTaxAmount) AS SalesTaxAmount FROM UVW_WIPAR06Clientident WHERE InvoiceDateTime BETWEEN @mBegdate1 and @mEnddate1 GROUP BY ClientIdent) AS t19 ON t19.Clientident = t00.ClientIdent /* ar debits, credits, adjustments */ LEFT JOIN (SELECT ClientIdent ,SUM(CreditAmount) AS CreditAmount ,SUM(Adjustment1Amount) AS Adjustment1Amount ,SUM(Amount4) AS Amount4 /* GST write-off */ ,SUM(Amount5) AS Amount5 /* write-off */ ,SUM(DebitAmount) AS DebitAmount ,SUM(Adjustment2Amount) AS Adjustment2Amount FROM UVW_WIPAR07Clientident WHERE transactiondatetime BETWEEN @mBegdate1 AND @mEnddate1 GROUP BY ClientIdent) AS t20 ON t20.Clientident = t00.ClientIdent /* ar fin chg */ LEFT JOIN (SELECT ClientIdent ,sum(Charges) as [Charges] from UVW_WIPAR08Clientident where TransactionDateTime BETWEEN @mBegdate1 and @mEnddate1 GROUP BY Clientident) AS t21 ON t21.Clientident = t00.ClientIdent /* ar payments */ LEFT JOIN (SELECT ClientIdent, SUM(PaymentAmount) AS PaymentAmount FROM UVW_WIPAR09Clientident WHERE TransactionDateTime BETWEEN @mBegdate1 AND @mEnddate1 GROUP BY clientident) AS t22 ON t22.Clientident = t00.Clientident ) AS t1 LEFT JOIN CLIENT ON t1.ClientIdent=client.ClientIdent LEFT JOIN CLIENTCRS on CLIENTCRS.ClientIdent = CLIENT.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription=@mCRSTitle LEFT JOIN STAFF on CLIENTCRS.StaffIdent = STAFF.StaffIdent WHERE (CASE WHEN @mCRSTitle = 'All' THEN 1 ELSE CASE WHEN ISNULL(STAFF.StaffIdentifier,'0') IN (SELECT column1 FROM #tempstaff) THEN 1 ELSE 0 END END) = 1 /* AND ClientIdSubId NOT IN ( 'D07134.01', 'GLV001', 'B191161.101', 'CRAVEND', 'B123000.101', '1003079.000', '499827904', 'B1002819.000', '15068', '504', 'B159019.101', 'B279026.001', 'three' ) */ AND (t1.p_time + t1.p_expenses + t1.p_billedamount + t1.p_progressbilledamount + t1.p_progressapplyamount + t1.p_writeupdownamount <> 0 OR t1.c_hours <> 0 OR t1.c_time <> 0 or t1.c_expenses <> 0 OR t1.c_billedamount <> 0 or t1.c_progressbilledamount <> 0 or t1.c_progressapplyamount <> 0 or t1.c_writeupdownamount <> 0 OR t1.p_invoiceamount + t1.p_salestaxamount + t1.p_creditamount + t1.p_adjustment1amount + t1.p_debitamount + t1.p_adjustment2amount + t1.p_amount4 + t1.p_amount5 + t1.p_charges + t1.p_paymentamount <> 0 or t1.c_invoiceamount <> 0 or t1.c_salestaxamount <> 0 or (t1.c_creditamount + t1.c_adjustment1amount + t1.c_debitamount + t1.c_adjustment2amount + t1.c_amount4 + t1.c_amount5) <> 0 or t1.c_charges <> 0 or t1.c_paymentamount <> 0) AND (CLIENT.DeleteFlag = 'F' OR CLIENT.DeleteFlag = @mIncludeDeleted) AND ClientOfficeName IN (SELECT column1 FROM #officetemp) /* AND CLIENT.ClientIdSubId = '22015.0' */ ORDER BY CASE WHEN @mSortOrder=0 THEN ClientIdSubId ELSE ClientSortName END END GO /****** Object: StoredProcedure [dbo].[USP_WIPComponent] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_WIPComponent] @mBegdate1 AS DATE /* current balance date range */ ,@mEnddate1 AS DATE /* current balance date range */ /* this parameter value will either be All, or one of the firm-defined CRS positions if a CRS position name is passed in, this will be used as the primary sort field */ ,@mCRSTitle varchar(32) = 'All' ,@mStaffIdentifierList VARCHAR(MAX) = '' /* if a specified list of CRS staff is selected, this will contain the list */ ,@mSortOrder AS INT = 0 /* 0 = sort by clientid, 1 = sort by clientsortname */ ,@mIncludeDeleted CHAR(1) = 'F' /* set to F to exclude deleted, or set to T to include deleted */ ,@mIncludeProgress CHAR(1) = 'T' /* set to F to exclude progress billed/applied */ ,@mFRGList varchar(32) = 'All' /* financial reporting group name */ AS BEGIN SET NOCOUNT ON; /* calculate the date range that is used for all beginning balances in this report */ DECLARE @mBegdate0 DATE = '01/01/1900' /* prior balance date range begin */ DECLARE @mEnddate0 DATE = DATEADD(d,-1,@mBegdate1) /* prior balance date range end */ /* this section creates a temp table to hold the comma separated 'staff' values sent in by the program. */ CREATE TABLE #tempstaff (column1 NVARCHAR(255)) INSERT INTO #tempstaff select * from [dbo].[UFN_String2Table](@mStaffIdentifierList) CREATE TABLE #tempfrg (column1 NVARCHAR(32)) INSERT INTO #tempfrg select * from [dbo].[UFN_String2Table](@mFRGList) SELECT ISNULL(STAFF.StaffName,' No Selection') AS CRS1 ,[CLIENT].ClientIdSubId ,[Client].ClientSortName ,t1.p_time + t1.p_expenses - t1.p_BilledAmount - CASE WHEN @mIncludeProgress='T' THEN t1.p_ProgressBilledAmount ELSE 0 END + CASE WHEN @mIncludeProgress='T' THEN t1.p_ProgressApplyAmount ELSE 0 END + t1.p_WriteUpDownAmount AS p_wipbeginbalance ,t1.c_time ,t1.c_expenses ,t1.c_TimeBilledAmount ,t1.c_ExpenseBilledAmount ,CASE WHEN @mIncludeProgress='T' THEN t1.c_ProgressBilledAmount ELSE 0 END AS c_ProgressBilledAmount ,CASE WHEN @mIncludeProgress='T' THEN t1.c_ProgressApplyAmount ELSE 0 END AS c_ProgressApplyAmount ,t1.c_writeupdownamount ,t1.p_time + t1.p_expenses - t1.p_BilledAmount - CASE WHEN @mIncludeProgress='T' THEN t1.p_ProgressBilledAmount ELSE 0 END + CASE WHEN @mIncludeProgress='T' THEN t1.p_ProgressApplyAmount ELSE 0 END + t1.p_WriteUpDownAmount + t1.c_time + t1.c_expenses - t1.c_BilledAmount - CASE WHEN @mIncludeProgress='T' THEN t1.c_ProgressBilledAmount ELSE 0 END + CASE WHEN @mIncludeProgress='T' THEN t1.c_ProgressApplyAmount ELSE 0 END + t1.c_WriteUpDownAmount AS c_wipendbalance FROM (SELECT t00.ClientIdent ,ISNULL(t04.[time],0.00) as p_time ,ISNULL(t04.expenses,0.00) as p_expenses ,ISNULL(t05.BilledAmount,0.00) as p_billedamount ,ISNULL(t06.ProgressBilledAmount,0.00) as p_progressbilledamount ,ISNULL(t07.ProgressApplyAmount,0.00) as p_progressapplyamount ,ISNULL(t08.writeupdownamount,0.00) as p_writeupdownamount ,ISNULL(t14.[hours],0.00) as c_hours ,ISNULL(t14.[time],0.00) as c_time ,ISNULL(t14.expenses,0.00) as c_expenses ,ISNULL(t15.TimeBilledAmount,0.00) AS c_TimeBilledAmount ,ISNULL(t15.ExpenseBilledAmount,0.00) AS c_ExpenseBilledAmount ,ISNULL(t15.BilledAmount,0.00) as c_BilledAmount ,ISNULL(t16.ProgressBilledAmount,0.00) as c_progressbilledamount ,ISNULL(t17.ProgressApplyAmount,0.00) as c_progressapplyamount ,ISNULL(t18.writeupdownamount,0.00) as c_writeupdownamount FROM /* this is the main report driver select */ (SELECT clientident FROM CLIENT) AS t00 /* previous WIP balances */ /* wip hours, time, expenses */ LEFT JOIN (SELECT Clientident ,SUM([hours]) AS [hours] ,sum([time]) as [time] ,sum([expenses]) as [expenses] FROM UVW_WIPAR01Clientident WHERE transactiondate BETWEEN @mBegdate0 AND @mEnddate0 GROUP BY clientident) as t04 ON t04.Clientident = t00.ClientIdent /* wip billed amount */ LEFT JOIN (SELECT clientident ,SUM([hours]) AS [Hours] ,SUM(StdAmount) AS [StdAmount] ,SUM([TimeAdjAmount]) AS [TimeAdjAmount] ,SUM([ExpenseAdjAmount]) AS [ExpenseAdjAmount] ,SUM([AdjAmount]) AS [AdjAmount] ,SUM([TimeBilledAmount]) AS [TimeBilledAmount] ,SUM([ExpenseBilledAmount]) AS [ExpenseBilledAmount] ,SUM([BilledAmount]) AS [BilledAmount] ,SUM([TimeCost]) AS [TimeCost] ,SUM([ExpenseCost]) AS [ExpenseCost] ,SUM([Cost]) AS [Cost] FROM UVW_WIPAR02Clientident WHERE InvoiceDateTime BETWEEN @mBegdate0 AND @mEnddate0 /* amounts should only be considered billed when the invoice is posted */ AND InvoiceStatusCode = 1 GROUP BY clientident) as t05 ON t05.Clientident = t00.ClientIdent /* wip progress billed */ LEFT JOIN (SELECT ClientIdent ,sum([ProgressBilledAmount]) AS ProgressBilledAmount FROM UVW_WIPAR03Clientident WHERE InvoiceDateTime BETWEEN @mBegdate0 AND @mEnddate0 /* progress billed is only included if the invoice is posted */ AND InvoiceStatusCode = 1 GROUP BY clientident) AS t06 ON t06.Clientident = t00.ClientIdent /* wip progress apply */ LEFT JOIN (Select ClientIdent ,sum([ProgressApplyAmount]) AS ProgressApplyAmount FROM UVW_WIPAR04Clientident WHERE InvoiceDateTime BETWEEN @mBegdate0 AND @mEnddate0 /* progress apply is only included if the invoice is posted */ AND InvoiceStatusCode = 1 GROUP BY clientident) AS t07 ON t07.Clientident = t00.ClientIdent /* wip write up-down */ LEFT JOIN (SELECT ClientIdent ,SUM(TimeWriteUpDownAmount) AS TimeWriteUpDownAmount ,SUM(ExpenseWriteUpDownAmount) AS ExpenseWriteUpDownAmount ,SUM(ISNULL(writeupdownAmount,0)) AS WriteUpDownAmount FROM UVW_WIPAR05Clientident WHERE InvoiceDateTime BETWEEN @mBegdate0 AND @mEnddate0 /* write up/down is only included if the invoice is posted */ and InvoiceStatusCode=1 GROUP BY clientident) AS t08 ON t08.Clientident = t00.ClientIdent /* total billable wip (billed or unbilled) */ /* wip hours, time, expenses */ LEFT JOIN (SELECT Clientident ,SUM([hours]) AS [hours] ,sum([time]) as [time] ,sum([expenses]) as [expenses] FROM UVW_WIPAR01Clientident WHERE transactiondate BETWEEN @mBegdate1 AND @mEnddate1 GROUP BY clientident) AS t14 ON t14.Clientident = t00.ClientIdent /* wip billed amount */ LEFT JOIN (SELECT clientident ,SUM([hours]) AS [Hours] ,SUM([StdAmount]) AS [StdAmount] ,SUM([TimeAdjAmount]) AS [TimeAdjAmount] ,SUM([ExpenseAdjAmount]) AS [ExpenseAdjAmount] ,SUM([AdjAmount]) AS [AdjAmount] ,SUM([TimeBilledAmount]) AS [TimeBilledAmount] ,SUM([ExpenseBilledAmount]) AS [ExpenseBilledAmount] ,SUM([BilledAmount]) AS [BilledAmount] ,SUM([TimeCost]) AS [TimeCost] ,SUM([ExpenseCost]) AS [ExpenseCost] ,SUM([Cost]) AS [Cost] FROM UVW_WIPAR02Clientident WHERE InvoiceDateTime BETWEEN @mBegdate1 AND @mEnddate1 AND InvoiceStatusCode = 1 GROUP BY clientident) as t15 ON t15.Clientident = t00.ClientIdent /* wip progress billed */ LEFT JOIN (SELECT ClientIdent ,sum([ProgressBilledAmount]) AS ProgressBilledAmount FROM UVW_WIPAR03Clientident WHERE InvoiceDateTime BETWEEN @mBegdate1 AND @mEnddate1 AND InvoiceStatusCode = 1 GROUP BY clientident) as t16 ON t16.Clientident = t00.ClientIdent /* wip progress apply */ LEFT JOIN (Select ClientIdent ,sum([ProgressApplyAmount]) AS ProgressApplyAmount FROM UVW_WIPAR04Clientident WHERE InvoiceDateTime BETWEEN @mBegdate1 AND @mEnddate1 AND InvoiceStatusCode = 1 GROUP BY clientident) AS t17 ON t17.Clientident = t00.ClientIdent /* wip write up-down */ LEFT JOIN (SELECT ClientIdent ,SUM(TimeWriteUpDownAmount) AS TimeWriteUpDownAmount ,SUM(ExpenseWriteUpDownAmount) AS ExpenseWriteUpDownAmount ,SUM(ISNULL(writeupdownAmount,0)) AS WriteUpDownAmount FROM UVW_WIPAR05Clientident WHERE InvoiceDateTime BETWEEN @mBegdate1 AND @mEnddate1 and InvoiceStatusCode=1 /* write up/down is only included if the invoice is posted */ GROUP BY clientident) AS t18 ON t18.Clientident = t00.ClientIdent ) AS t1 LEFT JOIN CLIENT ON t1.ClientIdent=client.ClientIdent LEFT JOIN CLIENTCRS on CLIENTCRS.ClientIdent = CLIENT.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription=@mCRSTitle LEFT JOIN STAFF on CLIENTCRS.StaffIdent = STAFF.StaffIdent --LEFT JOIN CLIENTGROUP ON CLIENT.ClientIdent = CLIENTGROUP.ClientIdent AND FinancialReportingGroupFlag = 'T' OUTER APPLY (SELECT TOP 1 ClientGroupName FROM CLIENTGROUP WHERE CLIENTGROUP.ClientIdent = CLIENT.ClientIdent AND FinancialReportingGroupFlag = 'T') AS FRG WHERE (CASE WHEN @mCRSTitle = 'All' THEN 1 ELSE CASE WHEN ISNULL(STAFF.StaffIdentifier,'0') IN (SELECT column1 FROM #tempstaff) THEN 1 ELSE 0 END END) = 1 AND (t1.p_time + t1.p_expenses - t1.p_billedamount - CASE WHEN @mIncludeProgress='T' THEN t1.p_progressbilledamount ELSE 0 END + CASE WHEN @mIncludeProgress='T' THEN t1.p_progressapplyamount ELSE 0 END + t1.p_writeupdownamount <> 0 OR t1.c_hours <> 0 OR t1.c_time <> 0 or t1.c_expenses <> 0 OR t1.c_billedamount <> 0 or CASE WHEN @mIncludeProgress='T' THEN t1.c_progressbilledamount ELSE 0 END <> 0 or CASE WHEN @mIncludeProgress='T' THEN t1.c_progressapplyamount ELSE 0 END <> 0 or t1.c_writeupdownamount <> 0 ) AND (CLIENT.DeleteFlag = 'F' OR CLIENT.DeleteFlag = @mIncludeDeleted) AND CASE WHEN @mFRGList = 'All' THEN 1 ELSE CASE WHEN FRG.ClientGroupName IN (SELECT column1 FROM #tempfrg) THEN 1 ELSE 0 END END = 1 ORDER BY CRS1,CASE WHEN @mSortOrder=0 THEN ClientIdSubId ELSE ClientSortName END END GO /****** Object: StoredProcedure [dbo].[USP_WIPDetailLedger] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_WIPDetailLedger] @mBegdate1 AS DATE ,@mEnddate1 AS DATE ,@mCRSTitle varchar(32) = 'All' ,@mStaffIdentifierList VARCHAR(MAX) = '' /* if a specified list of CRS staff is selected, this will contain the list */ ,@mFRGList varchar(32) = 'All' /* financial reporting group name */ AS BEGIN DECLARE @mUnassigned AS CHAR(11) = ' Unassigned' /* this section creates a temp table to hold the comma separated 'staff' values sent in by the program. */ CREATE TABLE #tempstaff (column1 NVARCHAR(255)) INSERT INTO #tempstaff select * from [dbo].[UFN_String2Table](@mStaffIdentifierList) CREATE TABLE #tempfrg (column1 NVARCHAR(32)) INSERT INTO #tempfrg select * from [dbo].[UFN_String2Table](@mFRGList) SELECT STAFF2.StaffName AS CRS1, CLIENT.ClientIdSubId, CLIENT.ClientSortName, T1.* FROM CLIENT LEFT JOIN (SELECT ClientIdent, DATEADD(d,-1,@mBegdate1) AS TransactionDate, NULL AS StaffIdentifier, NULL AS ReportName, NULL AS ServiceCodeID, 'Balance Forward' AS ServiceCodeName, SUM([hours]) AS [hours], SUM([adjrate]) AS [adjrate], SUM([amount]) AS [AdjAmount], NULL AS ProjectCode, NULL AS ProjectName, NULL AS WorkstepCode, NULL AS WorkstepName FROM UVW_WIPDetailLedger WHERE transactiondate BETWEEN '01/01/1900' AND DATEADD(d,-1,@mBegdate1) GROUP BY ClientIdent UNION ALL SELECT UVW_WIPDetailLedger.ClientIdent, UVW_WIPDetailLedger.TransactionDate, STAFF.StaffIdentifier, STAFF.ReportName, CASE WipTypeCode WHEN 3 THEN '' ELSE SERVICECODE.ServiceCodeID END AS ServiceCodeID, CASE WipTypeCode WHEN 3 THEN 'Progress bill' ELSE SERVICECODE.ServiceCodeName END AS ServiceCodeName, UVW_WIPDetailLedger.hours, UVW_WIPDetailLedger.adjrate, UVW_WIPDetailLedger.amount AS AdjAmount, ISNULL(CASE WHEN DATALENGTH([INTERIMWORKINGPROJECT].ProjectCode)=0 THEN NULL ELSE [INTERIMWORKINGPROJECT].ProjectCode END, @mUnassigned) AS ProjectCode, ISNULL(INTERIMWORKINGPROJECT.ProjectName,@mUnassigned) AS ProjectName, ISNULL([INTERIMWORKINGPROJECTWORKSTEP].WorkStepCode,'') AS WorkStepCode, ISNULL([INTERIMWORKINGPROJECTWORKSTEP].WorkStepName,'') AS WorkStepName FROM UVW_WIPDetailLedger LEFT JOIN SERVICECODE on SERVICECODE.ServiceCodeIdent = UVW_WIPDetailLedger.ServiceCodeIdent LEFT JOIN STAFF on staff.StaffIdent=UVW_WIPDetailLedger.StaffIdent LEFT JOIN [INTERIMWORKINGPROJECT] on UVW_WIPDetailLedger.projectident = [INTERIMWORKINGPROJECT].interimworkingprojectident LEFT JOIN [INTERIMWORKINGPROJECTWORKSTEP] ON UVW_WIPDetailLedger.Workstepident = [INTERIMWORKINGPROJECTWORKSTEP].InterimWorkingProjectWorkStepIdent WHERE UVW_WIPDetailLedger.transactiondate BETWEEN @mBegdate1 AND @mEnddate1 ) T1 ON CLIENT.ClientIdent = T1.ClientIdent LEFT JOIN CLIENTCRS on CLIENTCRS.ClientIdent = CLIENT.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription = @mCRSTitle LEFT JOIN STAFF AS STAFF2 on CLIENTCRS.StaffIdent = STAFF2.StaffIdent --LEFT JOIN CLIENTGROUP ON CLIENT.ClientIdent = CLIENTGROUP.ClientIdent AND FinancialReportingGroupFlag = 'T' OUTER APPLY (SELECT TOP 1 ClientGroupName FROM CLIENTGROUP WHERE CLIENTGROUP.ClientIdent = CLIENT.ClientIdent AND FinancialReportingGroupFlag = 'T') AS FRG WHERE (CASE WHEN @mCRSTitle = 'All' THEN 1 ELSE CASE WHEN ISNULL(STAFF2.StaffIdentifier,'0') IN (SELECT column1 FROM #tempstaff) THEN 1 ELSE 0 END END) = 1 AND CASE WHEN @mFRGList = 'All' THEN 1 ELSE CASE WHEN FRG.ClientGroupName IN (SELECT column1 FROM #tempfrg) THEN 1 ELSE 0 END END = 1 and (T1.[hours]<>0 OR T1.[AdjRate]<>0 OR T1.[AdjAmount]<>0) ORDER BY CRS1, CLIENT.ClientIdSubId, T1.TransactionDate END GO /****** Object: StoredProcedure [dbo].[USP_WIPReconciliationProject] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_WIPReconciliationProject] @mBegdate1 AS DATE /* current balance date range */ ,@mEnddate1 AS DATE /* current balance date range */ /* this parameter value will either be All, or one of the firm-defined CRS positions if a CRS position name is passed in, this will be used as the primary sort field */ ,@mCRSTitle varchar(32) = 'All' ,@mStaffIdentifierList VARCHAR(MAX) = '' /* if a specified list of CRS staff is selected, this will contain the list */ ,@mSortOrder AS INT = 0 /* 0 = sort by clientid, 1 = sort by clientsortname */ ,@mIncludeDeleted CHAR(1) = 'F' /* set to F to exclude deleted, or set to T to include deleted */ AS BEGIN DECLARE @mBegdate0 DATE = '01/01/1900' /* prior balance date range begin */ DECLARE @mEnddate0 DATE = DATEADD(d,-1,@mBegdate1) /* prior balance date range end */ /* this section creates a temp table to hold the comma separated 'staff' values sent in by the program. */ CREATE TABLE #tempstaff (column1 NVARCHAR(255)) INSERT INTO #tempstaff select * from [dbo].[UFN_String2Table](@mStaffIdentifierList) SELECT ISNULL((SELECT STAFF.StaffName FROM CLIENTCRS LEFT JOIN STAFF ON CLIENTCRS.StaffIdent=STAFF.StaffIdent WHERE ClientIdent=CLIENT.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription = @mCRSTitle),' No Selection') AS CRS1 ,t1.ProjectName ,[CLIENT].ClientIdSubId ,[Client].ClientSortName /* WIP fields for report */ ,t1.p_time + t1.p_expenses - t1.p_BilledAmount - t1.p_ProgressBilledAmount + t1.p_ProgressApplyAmount + t1.p_WriteUpDownAmount AS p_wipbeginbalance ,t1.c_hours ,t1.c_time ,t1.c_expenses ,t1.c_BilledAmount + t1.c_ProgressBilledAmount - t1.c_ProgressApplyAmount AS c_billings ,t1.c_writeupdownamount ,CASE WHeN (c_BilledAmount + c_ProgressBilledAmount - c_ProgressApplyAmount - c_WriteUpDownAmount) = 0 THEN 0 ELSE (c_BilledAmount + c_ProgressBilledAmount - c_ProgressApplyAmount) END / CASE WHEN (c_BilledAmount + c_ProgressBilledAmount - c_ProgressApplyAmount - c_WriteUpDownAmount) = 0 THEN 1 ELSE (c_BilledAmount + c_ProgressBilledAmount - c_ProgressApplyAmount - c_WriteUpDownAmount) END AS c_realpercent ,t1.p_time + t1.p_expenses - t1.p_BilledAmount - t1.p_ProgressBilledAmount + t1.p_ProgressApplyAmount + t1.p_WriteUpDownAmount + t1.c_time + t1.c_expenses - t1.c_BilledAmount - t1.c_ProgressBilledAmount + t1.c_ProgressApplyAmount + t1.c_WriteUpDownAmount AS c_wipendbalance FROM (SELECT t00.ClientIdent ,ISNULL((SELECT ProjectName FROM INTERIMWORKINGPROJECT WHERE InterimWorkingProjectIdent=t00.ProjectIdent),' No Selection') AS ProjectName ,ISNULL(t04.[time],0.00) as p_time ,ISNULL(t04.expenses,0.00) as p_expenses ,ISNULL(t05.BilledAmount,0.00) as p_billedamount ,ISNULL(t06.ProgressBilledAmount,0.00) as p_progressbilledamount ,ISNULL(t07.ProgressApplyAmount,0.00) as p_progressapplyamount ,ISNULL(t08.writeupdownamount,0.00) as p_writeupdownamount ,ISNULL(t14.[hours],0.00) as c_hours ,ISNULL(t14.[time],0.00) as c_time ,ISNULL(t14.expenses,0.00) as c_expenses ,ISNULL(t15.BilledAmount,0.00) as c_billedamount ,ISNULL(t16.ProgressBilledAmount,0.00) as c_progressbilledamount ,ISNULL(t17.ProgressApplyAmount,0.00) as c_progressapplyamount ,ISNULL(t18.writeupdownamount,0.00) as c_writeupdownamount FROM /* this is the main report driver select */ (SELECT DISTINCT ClientIdent,ISNULL(ProjectIdent,0) AS ProjectIdent FROM WIP) AS t00 /* previous WIP balances */ /* wip hours, time, expenses */ LEFT JOIN (SELECT Clientident ,ISNULL(ProjectIdent,0) AS ProjectIdent ,SUM([hours]) AS [hours] ,sum([time]) as [time] ,sum([expenses]) as [expenses] FROM UVW_WIPAR01Clientident WHERE transactiondate BETWEEN @mBegdate0 AND @mEnddate0 GROUP BY clientident,ProjectIdent) as t04 ON t04.Clientident = t00.ClientIdent AND t04.ProjectIdent = t00.ProjectIdent /* wip billed amount */ LEFT JOIN (SELECT ClientIdent ,ISNULL(ProjectIdent,0) AS ProjectIdent ,SUM([hours]) AS [Hours] ,SUM(StdAmount) AS [StdAmount] ,SUM([TimeAdjAmount]) AS [TimeAdjAmount] ,SUM([ExpenseAdjAmount]) AS [ExpenseAdjAmount] ,SUM([AdjAmount]) AS [AdjAmount] ,SUM([TimeBilledAmount]) AS [TimeBilledAmount] ,SUM([ExpenseBilledAmount]) AS [ExpenseBilledAmount] ,SUM([BilledAmount]) AS [BilledAmount] ,SUM([TimeCost]) AS [TimeCost] ,SUM([ExpenseCost]) AS [ExpenseCost] ,SUM([Cost]) AS [Cost] FROM UVW_WIPAR02Clientident WHERE InvoiceDateTime BETWEEN @mBegdate0 AND @mEnddate0 /* per bug xxx, amounts should only be considered billed when the invoice is posted */ AND InvoiceStatusCode = 1 GROUP BY clientident,ProjectIdent) as t05 ON t05.Clientident = t00.ClientIdent AND t05.ProjectIdent = t00.ProjectIdent /* wip progress billed */ LEFT JOIN (SELECT ClientIdent ,ISNULL(ProjectIdent,0) AS ProjectIdent ,sum([ProgressBilledAmount]) AS ProgressBilledAmount FROM UVW_WIPAR03Clientident WHERE InvoiceDateTime BETWEEN @mBegdate0 AND @mEnddate0 AND InvoiceStatusCode = 1 /* progress billed is only included if the invoice is posted */ GROUP BY clientident,ProjectIdent) AS t06 ON t06.Clientident = t00.ClientIdent AND t06.ProjectIdent = t00.ProjectIdent /* wip progress apply */ LEFT JOIN (Select ClientIdent ,ISNULL(ProjectIdent,0) AS ProjectIdent ,sum([ProgressApplyAmount]) AS ProgressApplyAmount FROM UVW_WIPAR04Clientident WHERE InvoiceDateTime BETWEEN @mBegdate0 AND @mEnddate0 AND InvoiceStatusCode = 1 /* progress apply is only included if the invoice is posted */ GROUP BY clientident,ProjectIdent) AS t07 ON t07.Clientident = t00.ClientIdent AND t07.ProjectIdent = t00.ProjectIdent /* wip write up-down */ LEFT JOIN (SELECT ClientIdent ,ISNULL(ProjectIdent,0) AS ProjectIdent ,SUM(TimeWriteUpDownAmount) AS TimeWriteUpDownAmount ,SUM(ExpenseWriteUpDownAmount) AS ExpenseWriteUpDownAmount ,SUM(ISNULL(writeupdownAmount,0)) AS WriteUpDownAmount FROM UVW_WIPAR05Clientident WHERE InvoiceDateTime BETWEEN @mBegdate0 AND @mEnddate0 and InvoiceStatusCode=1 /* write up/down is only included if the invoice is posted */ GROUP BY clientident,ProjectIdent) AS t08 ON t08.Clientident = t00.ClientIdent AND t08.ProjectIdent = t00.ProjectIdent /* current WIP balances */ /* wip hours, time, expenses */ LEFT JOIN (SELECT Clientident ,ISNULL(ProjectIdent,0) AS ProjectIdent ,SUM([hours]) AS [hours] ,sum([time]) as [time] ,sum([expenses]) as [expenses] FROM UVW_WIPAR01Clientident WHERE transactiondate BETWEEN @mBegdate1 AND @mEnddate1 GROUP BY clientident,ProjectIdent) AS t14 ON t14.Clientident = t00.ClientIdent AND t14.ProjectIdent = t00.ProjectIdent /* wip billed amount */ LEFT JOIN (SELECT ClientIdent ,ISNULL(ProjectIdent,0) AS ProjectIdent ,SUM([hours]) AS [Hours] ,SUM(StdAmount) AS [StdAmount] ,SUM([TimeAdjAmount]) AS [TimeAdjAmount] ,SUM([ExpenseAdjAmount]) AS [ExpenseAdjAmount] ,SUM([AdjAmount]) AS [AdjAmount] ,SUM([TimeBilledAmount]) AS [TimeBilledAmount] ,SUM([ExpenseBilledAmount]) AS [ExpenseBilledAmount] ,SUM([BilledAmount]) AS [BilledAmount] ,SUM([TimeCost]) AS [TimeCost] ,SUM([ExpenseCost]) AS [ExpenseCost] ,SUM([Cost]) AS [Cost] FROM UVW_WIPAR02Clientident WHERE InvoiceDateTime BETWEEN @mBegdate1 AND @mEnddate1 /* amounts should only be considered billed when the invoice is posted */ AND InvoiceStatusCode = 1 GROUP BY clientident,ProjectIdent) as t15 ON t15.Clientident = t00.ClientIdent AND t15.ProjectIdent = t00.ProjectIdent /* wip progress billed */ LEFT JOIN (SELECT ClientIdent ,ISNULL(ProjectIdent,0) AS ProjectIdent ,sum([ProgressBilledAmount]) AS ProgressBilledAmount FROM UVW_WIPAR03Clientident WHERE InvoiceDateTime BETWEEN @mBegdate1 AND @mEnddate1 AND InvoiceStatusCode = 1 GROUP BY clientident,ProjectIdent) as t16 ON t16.Clientident = t00.ClientIdent AND t16.ProjectIdent = t00.ProjectIdent /* wip progress apply */ LEFT JOIN (Select ClientIdent ,ISNULL(ProjectIdent,0) AS ProjectIdent ,sum([ProgressApplyAmount]) AS ProgressApplyAmount FROM UVW_WIPAR04Clientident WHERE InvoiceDateTime BETWEEN @mBegdate1 AND @mEnddate1 AND InvoiceStatusCode = 1 GROUP BY clientident,ProjectIdent) AS t17 ON t17.Clientident = t00.ClientIdent AND t17.ProjectIdent = t00.ProjectIdent /* wip write up-down */ LEFT JOIN (SELECT ClientIdent ,ISNULL(ProjectIdent,0) AS ProjectIdent ,SUM(TimeWriteUpDownAmount) AS TimeWriteUpDownAmount ,SUM(ExpenseWriteUpDownAmount) AS ExpenseWriteUpDownAmount ,SUM(ISNULL(writeupdownAmount,0)) AS WriteUpDownAmount FROM UVW_WIPAR05Clientident WHERE InvoiceDateTime BETWEEN @mBegdate1 AND @mEnddate1 and InvoiceStatusCode=1 /* write up/down is only included if the invoice is posted */ GROUP BY clientident,ProjectIdent) AS t18 ON t18.Clientident = t00.ClientIdent AND t18.ProjectIdent = t00.ProjectIdent ) AS t1 LEFT JOIN CLIENT ON t1.ClientIdent=client.ClientIdent LEFT JOIN CLIENTCRS on CLIENTCRS.ClientIdent = CLIENT.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription=@mCRSTitle LEFT JOIN STAFF on CLIENTCRS.StaffIdent = STAFF.StaffIdent WHERE (CASE WHEN @mCRSTitle = 'All' THEN 1 ELSE CASE WHEN ISNULL(STAFF.StaffIdentifier,'0') IN (SELECT column1 FROM #tempstaff) THEN 1 ELSE 0 END END) = 1 AND (t1.p_time + t1.p_expenses - t1.p_billedamount - t1.p_progressbilledamount + t1.p_progressapplyamount + t1.p_writeupdownamount <> 0 OR t1.c_hours <> 0 OR t1.c_time <> 0 OR t1.c_expenses <> 0 OR t1.c_billedamount + t1.c_progressbilledamount - t1.c_progressapplyamount <> 0 OR t1.c_writeupdownamount <> 0) AND (CLIENT.DeleteFlag = 'F' OR CLIENT.DeleteFlag = @mIncludeDeleted) ORDER BY CRS1, ProjectName, CASE WHEN @mSortOrder=0 THEN ClientIdSubId ELSE ClientSortName END END GO /****** Object: StoredProcedure [dbo].[USP_WIPSummary] Script Date: 3/29/2026 1:13:23 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[USP_WIPSummary] @mDateend AS DATE, /* this parameter value will either be All, or one of the firm-defined CRS positions if a CRS position name is passed in, this will be used as the primary sort field */ @mCRSTitle varchar(32) = 'All', @mStaffIdentifierList VARCHAR(MAX) = '', /* if a specified list of CRS staff is selected, this will contain the list */ @mOfficelist varchar(MAX) /* contains a list of offices in the form of IN('Office1','Office2','Office3') */ AS BEGIN /* this section creates a temp table to hold the comma separated 'staff' values sent in by the program. */ CREATE TABLE #stafftemp (column1 NVARCHAR(255)) INSERT INTO #stafftemp select * from [dbo].[UFN_String2Table](@mStaffIdentifierList) /* this will create a temporary table that holds the list of offices selected */ CREATE TABLE #officetemp (column1 NVARCHAR(255)) INSERT INTO #officetemp select * from [dbo].[UFN_String2Table](@mOfficelist) SELECT ISNULL((SELECT STAFF.StaffName FROM CLIENTCRS LEFT JOIN STAFF ON CLIENTCRS.StaffIdent=STAFF.StaffIdent WHERE ClientIdent=CLIENT.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription = @mCRSTitle),' No Selection') AS CRS1, client.clientidsubid, client.clientsortname, /* wip available */ ISNULL(t01.time,0.00) - ISNULL(t02.TimeBilledAmount,0.00) + ISNULL(t05.TimeWriteUpDownAmount,0.00) AS WIPTimeAvailable, ISNULL(t01.expenses,0.00) - ISNULL(t02.ExpenseBilledAmount,0.00) + ISNULL(t05.ExpenseWriteUpDownAmount,0.00) AS WIPExpenseAvailable, /* added 07/20/2023 cost of the remaining WIP */ ISNULL(t01.timecost,0.00) - ISNULL(t02.timecost,0.00) AS WIPTimeCost, ISNULL(t01.expensecost,0.00) - ISNULL(t02.expensecost,0.00) AS WIPExpenseCost, /* progress */ ISNULL(T03.ProgressBilledAmount,0.00) - ISNULL(t04.ProgressApplyAmount,0.00) AS WIPProgress FROM CLIENT LEFT JOIN CLIENTCRS on CLIENTCRS.ClientIdent = CLIENT.ClientIdent AND CLIENTCRS.FirmClientStaffAssignmentDescription=@mCRSTitle LEFT JOIN STAFF on CLIENTCRS.StaffIdent = STAFF.StaffIdent /* total billable wip (billed or unbilled) */ LEFT JOIN (SELECT Clientident ,SUM([hours]) AS [hours] ,sum([time]) as [time] ,sum([expenses]) as [expenses] ,SUM([timecost]) AS [timecost] ,SUM([expensecost]) AS [expensecost] FROM UVW_WIPAR01Clientident WHERE transactiondate BETWEEN '01/01/1900' AND @mDateend GROUP BY clientident) AS t01 ON t01.clientident=CLIENT.clientident /* wip billed amount */ LEFT JOIN (SELECT clientident ,SUM([hours]) AS [Hours] ,SUM(StdAmount) AS [StdAmount] ,SUM([TimeAdjAmount]) AS [TimeAdjAmount] ,SUM([ExpenseAdjAmount]) AS [ExpenseAdjAmount] ,SUM([AdjAmount]) AS [AdjAmount] ,SUM([TimeBilledAmount]) AS [TimeBilledAmount] ,SUM([ExpenseBilledAmount]) AS [ExpenseBilledAmount] ,SUM([BilledAmount]) AS [BilledAmount] ,SUM([TimeCost]) AS [TimeCost] ,SUM([ExpenseCost]) AS [ExpenseCost] ,SUM([Cost]) AS [Cost] FROM UVW_WIPAR02Clientident WHERE InvoiceDateTime BETWEEN '01/01/1900' AND @mDateend /* amounts should only be considered billed when the invoice is posted */ AND InvoiceStatusCode = 1 GROUP BY clientident) AS t02 ON t02.clientident=CLIENT.clientident /* wip progress billed */ LEFT JOIN (SELECT ClientIdent ,sum([ProgressBilledAmount]) AS ProgressBilledAmount FROM UVW_WIPAR03Clientident WHERE InvoiceDateTime BETWEEN '01/01/1900' AND @mDateend AND InvoiceStatusCode = 1 GROUP BY clientident) AS t03 ON t03.clientident=CLIENT.clientident /* wip progress apply */ LEFT JOIN (Select ClientIdent ,sum([ProgressApplyAmount]) AS ProgressApplyAmount FROM UVW_WIPAR04Clientident WHERE InvoiceDateTime BETWEEN '01/01/1900' AND @mDateend AND InvoiceStatusCode = 1 GROUP BY clientident) AS t04 ON t04.clientident=CLIENT.clientident /* wip write up-down */ LEFT JOIN (SELECT ClientIdent ,SUM(TimeWriteUpDownAmount) AS TimeWriteUpDownAmount ,SUM(ExpenseWriteUpDownAmount) AS ExpenseWriteUpDownAmount ,SUM(ISNULL(writeupdownAmount,0)) AS WriteUpDownAmount FROM UVW_WIPAR05Clientident WHERE InvoiceDateTime BETWEEN '01/01/1900' AND @mDateend and InvoiceStatusCode=1 /* write up/down is only included if the invoice is posted */ GROUP BY clientident) AS t05 ON t05.clientident=CLIENT.clientident WHERE (CASE WHEN @mCRSTitle = 'All' THEN 1 ELSE CASE WHEN ISNULL(STAFF.StaffIdentifier,'0') IN (SELECT column1 FROM #stafftemp) THEN 1 ELSE 0 END END) = 1 AND ClientOfficeName IN (SELECT column1 FROM #officetemp) AND (/* wip available */ (ISNULL(t01.time,0.00) + ISNULL(t01.expenses,0.00) - ISNULL(t02.BilledAmount,0.00) + ISNULL(t05.WriteUpDownAmount,0.00)) <> 0 /* progress */ OR (ISNULL(T03.ProgressBilledAmount,0.00) - ISNULL(t04.ProgressApplyAmount,0.00)) <> 0) ORDER BY CRS1,client.clientidsubid END GO