# getmcsv6 - (Customer import CSV data) # is called for each relevant PERIOD # its SQL is... # for non-VRT SELECT tElement.Description AS ElementDesc, tServiceID.ServiceID AS ServiceID, tInvoiceDetail.BatchID AS Batch, tBatchType.SupplierDisplayedName AS Supplier, tLocation.Description AS Location, tPerson.Person, tCentre.Description AS Centre, tActivity.Description AS Activity, tElement_1.Description AS Element1Desc, tSubledger.Description AS SubLedger, ${transactiontable}.PayType, tServiceType.Description AS ServiceType, tInvoiceDetail.Description AS InvoiceDescription, tInvoiceDetail.Period, tCustomer.ShipTo, tInvoice.PlatinumInvoiceNo AS Invoice, SUM(${transactiontable}.AmountExGST) AS ExGST, SUM(${transactiontable}.GSTAmount) AS GST, SUM(${transactiontable}.AmountIncGST) AS IncGST, tTransactionGroup.Description AS TxnGrp, ${transactiontable}.Var01, ${transactiontable}.Var02, ${transactiontable}.Var03, ${transactiontable}.Var04, ${transactiontable}.Var05, ${transactiontable}.Var06, ${transactiontable}.Var07, ${transactiontable}.Var08, ${transactiontable}.Var09, ${transactiontable}.Var10, ${transactiontable}.Var11, ${transactiontable}.Var12, ${transactiontable}.Var13, ${transactiontable}.Var14, ${transactiontable}.Var15, tBatchType.Description AS BatchType, tReportGroup.GroupDesc ReportGroup, tDepartment.Description AS Dept, tServiceID.Service AS Service, tCentre.ID AS CentreID, tDepartment.ID AS DeptID, ${transactiontable}.GroupID FROM ${transactiontable} INNER JOIN ( tBatch LEFT JOIN ( tBatchType LEFT OUTER JOIN tReportGroup ON tBatchType.ReportGroupID = tReportGroup.ID ) ON tBatch.BatchTypeID = tBatchType.ID ) ON tBatch.ID = ${transactiontable}.BatchID LEFT JOIN tServiceID ON ${transactiontable}.ServiceID = tServiceID.ID INNER JOIN ( tInvoiceDetail INNER JOIN tInvoice ON tInvoiceDetail.InvoiceID = tInvoice.ID ) ON ${transactiontable}.InvoiceDetailID = tInvoiceDetail.ID LEFT JOIN tTransactionType ON ${transactiontable}.TransactionTypeID = tTransactionType.ID LEFT JOIN tTransactionGroup ON tTransactionType.TransactionGroupID = tTransactionGroup.ID LEFT JOIN tElement ON ${transactiontable}.ElementID = tElement.ID LEFT JOIN tElement tElement_1 ON ${transactiontable}.CustomerElementID = tElement_1.ID LEFT JOIN tServiceType ON ${transactiontable}.ServiceTypeID = tServiceType.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')) $EXCLUDEINVBIT $EXCLUDEBATCHIDBIT $EXCLUDEINVBIT $EXCLUDEBATCHIDBIT GROUP BY tElement.Description, tServiceID.ServiceID, tServiceID.Service, tInvoiceDetail.BatchID, tBatchType.SupplierDisplayedName, tLocation.Description, tPerson.Person, tCentre.ID, tCentre.Description, tServiceType.Description, tInvoiceDetail.Description, tSubledger.Description, tInvoiceDetail.Period, tCustomer.ShipTo, tInvoice.PlatinumInvoiceNo, tDepartment.ID, ${transactiontable}.GroupID, ${transactiontable}.Var01, ${transactiontable}.Var02, ${transactiontable}.Var03, ${transactiontable}.Var04, ${transactiontable}.Var05, ${transactiontable}.Var06, ${transactiontable}.Var07, ${transactiontable}.Var08, ${transactiontable}.Var09, ${transactiontable}.Var10, ${transactiontable}.Var11, ${transactiontable}.Var12, ${transactiontable}.Var13, ${transactiontable}.Var14, ${transactiontable}.Var15, tBatchType.Description, tReportGroup.GroupDesc, tTransactionGroup.Description, tDepartment.Description, ${transactiontable}.PayType, tActivity.Description, tElement_1.Description ORDER BY tInvoice.PlatinumInvoiceNo, Batch # for VRT SELECT tElement.Description AS ElementDesc, tServiceID.ServiceID AS ServiceID, ${transactiontable}.BatchID AS Batch, tBatchType.SupplierDisplayedName AS Supplier, tLocation.Description AS Location, tPerson.Person, tCentre.Description AS Centre, tActivity.Description AS Activity, tElement_1.Description AS Element1Desc, tSubledger.Description AS SubLedger, ${transactiontable}.PayType, tServiceType.Description AS ServiceType, '' AS InvoiceDescription, tBatch.BillingPeriod AS Period, tCustomer.ShipTo, 'VRT999999' AS Invoice, SUM(${transactiontable}.AmountExGST) AS ExGST, SUM(${transactiontable}.GSTAmount) AS GST, SUM(${transactiontable}.AmountIncGST) AS IncGST, tTransactionGroup.Description AS TxnGrp, ${transactiontable}.Var01, ${transactiontable}.Var02, ${transactiontable}.Var03, ${transactiontable}.Var04, ${transactiontable}.Var05, ${transactiontable}.Var06, ${transactiontable}.Var07, ${transactiontable}.Var08, ${transactiontable}.Var09, ${transactiontable}.Var10, ${transactiontable}.Var11, ${transactiontable}.Var12, ${transactiontable}.Var13, ${transactiontable}.Var14, ${transactiontable}.Var15, tBatchType.Description AS BatchType, tReportGroup.GroupDesc ReportGroup, tDepartment.Description AS Dept, tServiceID.Service AS Service, tCentre.ID AS CentreID, tDepartment.ID AS DeptID, ${transactiontable}.GroupID FROM ${transactiontable} INNER JOIN ( tBatch LEFT JOIN ( tBatchType LEFT OUTER JOIN tReportGroup ON tBatchType.ReportGroupID = tReportGroup.ID ) ON tBatch.BatchTypeID = tBatchType.ID ) ON tBatch.ID = ${transactiontable}.BatchID LEFT JOIN tServiceID ON ${transactiontable}.ServiceID = tServiceID.ID LEFT JOIN tTransactionType ON ${transactiontable}.TransactionTypeID = tTransactionType.ID LEFT JOIN tTransactionGroup ON tTransactionType.TransactionGroupID = tTransactionGroup.ID LEFT JOIN tElement ON ${transactiontable}.ElementID = tElement.ID LEFT JOIN tElement tElement_1 ON ${transactiontable}.CustomerElementID = tElement_1.ID LEFT JOIN tServiceType ON ${transactiontable}.ServiceTypeID = tServiceType.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 AND ${transactiontable}.RevenueFlag = 1 AND tCustomer.ShipTo = "VRT" $EXCLUDEINVBIT $EXCLUDEBATCHIDBIT $EXCLUDEINVBIT $EXCLUDEBATCHIDBIT GROUP BY tElement.Description, tServiceID.ServiceID, tServiceID.Service, ${transactiontable}.BatchID, tBatchType.SupplierDisplayedName, tLocation.Description, tPerson.Person, tCentre.ID, tCentre.Description, tServiceType.Description, tSubledger.Description, tBatch.BillingPeriod, tCustomer.ShipTo, tDepartment.ID, ${transactiontable}.GroupID, ${transactiontable}.Var01, ${transactiontable}.Var02, ${transactiontable}.Var03, ${transactiontable}.Var04, ${transactiontable}.Var05, ${transactiontable}.Var06, ${transactiontable}.Var07, ${transactiontable}.Var08, ${transactiontable}.Var09, ${transactiontable}.Var10, ${transactiontable}.Var11, ${transactiontable}.Var12, ${transactiontable}.Var13, ${transactiontable}.Var14, ${transactiontable}.Var15, tBatchType.Description, tReportGroup.GroupDesc, tTransactionGroup.Description, tDepartment.Description, ${transactiontable}.PayType, tActivity.Description, tElement_1.Description ORDER BY Batch