# getdetail6 # is called for each relevant PERIOD # its SQL is... SELECT tBatch.ID, tBatch.BillingPeriod, tBatchType.ID, tBatchType.SupplierID, tBatchType.Description AS BatchType, tSupplier.SupplierName, tServiceID.ServiceID, tServiceID.Service, tServiceType.Code AS ServiceTypeCode, tServiceType.Description AS ServiceType, tInvoice.InvoiceDate, ${transactiontable}.TxnDate, tReportGroup.ID AS ReportGrpID, tReportGroup.GroupDesc AS ReportGrpDesc, tInvoice.PlatinumFileName, tInvoice.PlatinumInvoiceNo, tCustomer.ShipTo, tCustomer.FullName, tCentre.Description AS CustCentre, tActivity.Description AS CustActivity, tElement.ElementCode AS EleRevServTypeCode, tElement.Description AS EleRevServTypeDesc, tElement_1.ElementCode AS CustEleCode, tElement_1.Description AS CustEleDesc, tElement_2.ElementCode AS EleAdmCode, tElement_2.Description AS EleAdmDesc, tSubledger.Description AS CustSubLedger, tDepartment.Description AS CustDept, tLocation.Description AS Location, tPerson.Person, tApplication.ID, tApplication.Description, tOrigin.Description AS Origin, tDestination.Description AS Destination, tRateDescription.Description AS RateDescription, tRate.Cost, tTransactionType.Description AS TransactionType, tTransactionGroup.Description AS TransactionGroup, tDialledNumber.Description AS DialledNumber, ${transactiontable}.Duration, ${transactiontable}.AmountExGST, tBatchType.Var01Description, ${transactiontable}.Var01, tBatchType.Var02Description, ${transactiontable}.Var02, tBatchType.Var03Description, ${transactiontable}.Var03, tBatchType.Var04Description, ${transactiontable}.Var04, tBatchType.Var05Description, ${transactiontable}.Var05, tBatchType.Var06Description, ${transactiontable}.Var06, tBatchType.Var07Description, ${transactiontable}.Var07, tBatchType.Var08Description, ${transactiontable}.Var08, tBatchType.Var09Description, ${transactiontable}.Var09, tBatchType.Var10Description, ${transactiontable}.Var10, tBatchType.Var11Description, ${transactiontable}.Var11, tBatchType.Var12Description, ${transactiontable}.Var12, tBatchType.Var13Description, ${transactiontable}.Var13, tBatchType.Var14Description, ${transactiontable}.Var14, tBatchType.Var15Description, ${transactiontable}.Var15, ${transactiontable}.CustomerCentreID, ${transactiontable}.DepartmentID, ${transactiontable}.GroupID, ${transactiontable}.CustomerID FROM ${transactiontable} INNER JOIN ( tBatch LEFT JOIN ( tBatchType LEFT JOIN tReportGroup ON tBatchType.ReportGroupID = tReportGroup.ID ) ON tBatch.BatchTypeID = tBatchType.ID ) ON ${transactiontable}.BatchID = tBatch.ID LEFT JOIN ( tServiceID LEFT JOIN tApplication ON tServiceID.ApplicationID = tApplication.ID ) ON ${transactiontable}.ServiceID = tServiceID.ID LEFT JOIN ( tInvoiceDetail INNER JOIN tInvoice ON tInvoiceDetail.InvoiceID = tInvoice.ID ) ON ${transactiontable}.InvoiceDetailID = tInvoiceDetail.ID LEFT JOIN tDialledNumber ON ${transactiontable}.DialledNumberID = tDialledNumber.ID LEFT JOIN tRateDescription ON ${transactiontable}.RateDescriptionID = tRateDescription.ID LEFT JOIN tDestination ON ${transactiontable}.DestinationID = tDestination.ID LEFT JOIN tOrigin ON ${transactiontable}.OriginID = tOrigin.ID LEFT JOIN tElement ON ${transactiontable}.ElementID = tElement.ID LEFT JOIN tElement tElement_1 ON ${transactiontable}.CustomerElementID = tElement_1.ID LEFT JOIN ( tServiceType LEFT JOIN tSupplier ON tServiceType.SupplierID = tSupplier.ID LEFT JOIN tElement tElement_2 ON tServiceType.RevenueElementID = tElement_2.ID LEFT JOIN tRate ON tServiceType.ID = tRate.ServiceTypeID ) ON ${transactiontable}.ServiceTypeID = tServiceType.ID LEFT JOIN ( tTransactionType LEFT JOIN tTransactionGroup ON tTransactionType.TransactionGroupID = tTransactionGroup.ID ) ON ${transactiontable}.TransactionTypeID = tTransactionType.ID LEFT JOIN tCustomer ON ${transactiontable}.CustomerID = tCustomer.ID LEFT JOIN tCentre ON ${transactiontable}.CustomerCentreID = tCentre.ID LEFT JOIN tActivity ON ${transactiontable}.CustomerActivityID = tActivity.ID LEFT JOIN tSubledger ON ${transactiontable}.CustomerSubledgerID = tSubledger.ID LEFT JOIN tDepartment ON ${transactiontable}.DepartmentID = tDepartment.ID LEFT JOIN tLocation ON ${transactiontable}.LocationID = tLocation.ID LEFT JOIN tPerson ON ${transactiontable}.PersonID = tPerson.ID WHERE tBatch.BillingPeriod = '$tbsbillingperiod' $SHIPTOBIT $BATCHIDBIT $INVOICENOBIT AND ${transactiontable}.RevenueFlag = 1 AND tCustomer.ShipTo <> 'VRT' AND tInvoice.InvoiceDate > dateadd(dd,$IOFFSETDAYS,'$IYYYYMMDD') AND tInvoice.InvoiceDate <= dateadd(mm,1,dateadd(dd,$IOFFSETDAYS,'$IYYYYMMDD')) --# exclude Victrack Rent and Calls AND tBatchType.ID <> 199 $EXCLUDEINVBIT $EXCLUDEBATCHIDBIT $EXCLUDEINVBIT $EXCLUDEBATCHIDBIT ORDER BY tCustomer.ShipTo, tInvoice.PlatinumInvoiceNo, tBatch.ID, tServiceID.ServiceID, ${transactiontable}.Var01, tReportGroup.ID # for VRT SELECT tBatch.ID, tBatch.BillingPeriod, tBatchType.ID, tBatchType.SupplierID, tBatchType.Description AS BatchType, tSupplier.SupplierName, tServiceID.ServiceID, tServiceID.Service, tServiceType.Code AS ServiceTypeCode, tServiceType.Description AS ServiceType, '' AS InvoiceDate, ${transactiontable}.TxnDate, tReportGroup.ID AS ReportGrpID, tReportGroup.GroupDesc AS ReportGrpDesc, '' AS PlatinumFileName, 'VRT999999' AS PlatinumInvoiceNo, tCustomer.ShipTo, tCustomer.FullName, tCentre.Description AS CustCentre, tActivity.Description AS CustActivity, tElement.ElementCode AS EleRevServTypeCode, tElement.Description AS EleRevServTypeDesc, tElement_1.ElementCode AS CustEleCode, tElement_1.Description AS CustEleDesc, tElement_2.ElementCode AS EleAdmCode, tElement_2.Description AS EleAdmDesc, tSubledger.Description AS CustSubLedger, tDepartment.Description AS CustDept, tLocation.Description AS Location, tPerson.Person, tApplication.ID, tApplication.Description, tOrigin.Description AS Origin, tDestination.Description AS Destination, tRateDescription.Description AS RateDescription, tRate.Cost, tTransactionType.Description AS TransactionType, tTransactionGroup.Description AS TransactionGroup, tDialledNumber.Description AS DialledNumber, ${transactiontable}.Duration, ${transactiontable}.AmountExGST, tBatchType.Var01Description, ${transactiontable}.Var01, tBatchType.Var02Description, ${transactiontable}.Var02, tBatchType.Var03Description, ${transactiontable}.Var03, tBatchType.Var04Description, ${transactiontable}.Var04, tBatchType.Var05Description, ${transactiontable}.Var05, tBatchType.Var06Description, ${transactiontable}.Var06, tBatchType.Var07Description, ${transactiontable}.Var07, tBatchType.Var08Description, ${transactiontable}.Var08, tBatchType.Var09Description, ${transactiontable}.Var09, tBatchType.Var10Description, ${transactiontable}.Var10, tBatchType.Var11Description, ${transactiontable}.Var11, tBatchType.Var12Description, ${transactiontable}.Var12, tBatchType.Var13Description, ${transactiontable}.Var13, tBatchType.Var14Description, ${transactiontable}.Var14, tBatchType.Var15Description, ${transactiontable}.Var15, ${transactiontable}.CustomerCentreID, ${transactiontable}.DepartmentID, ${transactiontable}.GroupID, ${transactiontable}.CustomerID FROM ${transactiontable} INNER JOIN ( tBatch LEFT JOIN ( tBatchType LEFT JOIN tReportGroup ON tBatchType.ReportGroupID = tReportGroup.ID ) ON tBatch.BatchTypeID = tBatchType.ID ) ON ${transactiontable}.BatchID = tBatch.ID LEFT JOIN ( tServiceID LEFT JOIN tApplication ON tServiceID.ApplicationID = tApplication.ID ) ON ${transactiontable}.ServiceID = tServiceID.ID LEFT JOIN tDialledNumber ON ${transactiontable}.DialledNumberID = tDialledNumber.ID LEFT JOIN tRateDescription ON ${transactiontable}.RateDescriptionID = tRateDescription.ID LEFT JOIN tDestination ON ${transactiontable}.DestinationID = tDestination.ID LEFT JOIN tOrigin ON ${transactiontable}.OriginID = tOrigin.ID LEFT JOIN tElement ON ${transactiontable}.ElementID = tElement.ID LEFT JOIN tElement tElement_1 ON ${transactiontable}.CustomerElementID = tElement_1.ID LEFT JOIN ( tServiceType LEFT JOIN tSupplier ON tServiceType.SupplierID = tSupplier.ID LEFT JOIN tElement tElement_2 ON tServiceType.RevenueElementID = tElement_2.ID LEFT JOIN tRate ON tServiceType.ID = tRate.ServiceTypeID ) ON ${transactiontable}.ServiceTypeID = tServiceType.ID LEFT JOIN ( tTransactionType LEFT JOIN tTransactionGroup ON tTransactionType.TransactionGroupID = tTransactionGroup.ID ) ON ${transactiontable}.TransactionTypeID = tTransactionType.ID LEFT JOIN tCustomer ON ${transactiontable}.CustomerID = tCustomer.ID LEFT JOIN tCentre ON ${transactiontable}.CustomerCentreID = tCentre.ID LEFT JOIN tActivity ON ${transactiontable}.CustomerActivityID = tActivity.ID LEFT JOIN tSubledger ON ${transactiontable}.CustomerSubledgerID = tSubledger.ID LEFT JOIN tDepartment ON ${transactiontable}.DepartmentID = tDepartment.ID LEFT JOIN tLocation ON ${transactiontable}.LocationID = tLocation.ID LEFT JOIN tPerson ON ${transactiontable}.PersonID = tPerson.ID WHERE tBatch.BillingPeriod = '$tbsbillingperiod' $SHIPTOBIT $BATCHIDBIT $INVOICENOBIT AND ${transactiontable}.RevenueFlag = 1 AND tCustomer.ShipTo = 'VRT' --# exclude Victrack Rent and Calls AND tBatchType.ID <> 199 $EXCLUDEINVBIT $EXCLUDEBATCHIDBIT $EXCLUDEINVBIT $EXCLUDEBATCHIDBIT ORDER BY tCustomer.ShipTo, PlatinumInvoiceNo, tBatch.ID, tServiceID.ServiceID, ${transactiontable}.Var01, tReportGroup.ID