/* Vendor Usage — Miscellaneous Orders (transactional / ReloAction) BackOffice: frmRptVendorUsage (cboVendors index 8) Crystal: VendorUsage_MiscOrders.rpt Source: dbo.vwTEServiceOrders (excludes TLV/TAD) Date filter: OrderSentDate. Pm-ServiceType: 0=Both, 1=Domestic, 2=International (form radios). */ DECLARE @StartDate datetime = '2026-01-01'; DECLARE @EndDate datetime = '2026-01-31'; DECLARE @CorpCode varchar(15) = ''; DECLARE @ParentRollup bit = 0; DECLARE @SrvcProvider varchar(4) = ''; DECLARE @VendorParentID int = 0; DECLARE @ServiceType smallint = 0; -- 0=Both, 1=Domestic, 2=International SELECT DISTINCT 'MiscOrders' AS UsageReportType, so.TEFileNo, te.CorpCode, cl.ParentCompany, cl.FormalName, te.TELastName, te.TEFirstName, fs.ServiceType, fs.SrvcProvider, fs.SrvcFirstName, fs.SrvcLastName, so.OrderSentDate AS OrderDate, so.VendorParentID, so.CompanyName, vp.CompanySubName, so.VendorID, so.ServiceCode, so.Description AS ServiceDescription, so.TEServiceOrderID, so.TEServiceOrderDetailID FROM dbo.vwTEServiceOrders so INNER JOIN dbo.tblTEMain1 te ON so.TEFileNo = te.TEFileNo INNER JOIN dbo.tblCorpClient cl ON te.CorpCode = cl.CorpCode INNER JOIN dbo.vwTEFullServiceList fs ON so.TEFileNo = fs.TEFileNo AND so.ServiceCode = fs.ServiceCode AND fs.CancelDate IS NULL LEFT JOIN dbo.tblVendorParent vp ON so.VendorParentID = vp.VendorParentID WHERE so.OrderCanceled IS NULL AND so.VendorID <> 0 AND so.ServiceCode NOT IN ('TLV', 'TAD') AND so.OrderSentDate BETWEEN @StartDate AND @EndDate AND ( (@ParentRollup = 0 AND (@CorpCode = '' OR te.CorpCode = @CorpCode)) OR (@ParentRollup = 1 AND (@CorpCode = '' OR cl.ParentCompany = @CorpCode OR te.CorpCode = @CorpCode)) ) AND (@SrvcProvider = '' OR fs.SrvcProvider = @SrvcProvider) AND (@VendorParentID = 0 OR so.VendorParentID = @VendorParentID) AND (@ServiceType = 0 OR fs.ServiceType = @ServiceType) ORDER BY so.CompanyName, te.CorpCode, so.OrderSentDate, so.TEFileNo;