SELECT
SUM(paymentAmt)
INTO
:count
FROM
(
SELECT
SUM(InstructionLineItem.amount) AS paymentAmt
FROM
CaseDecisionFinancialComp,
CaseDecisionObjective,
InstructionLineItem
WHERE CaseDecisionFinancialComp.caseDecisionObjectiveID = CaseDecisionObjective.caseDecisionObjectiveID
AND InstructionLineItem.financialCompID = CaseDecisionFinancialComp.financialCompID
AND CaseDecisionObjective.overflowInd = :overflowInd
AND CaseDecisionObjective.relatedReference IN
(
SELECT
CAST(ServiceInvoiceLineItem.serviceInvoiceLineItemID AS CHAR(20))
FROM
ServiceInvoiceLineItem,
ProviderOffering,
ServiceOffering
WHERE ProviderOffering.providerConcernRoleID = :resourceID
AND ProviderOffering.serviceOfferingID = ServiceOffering.serviceOfferingID
AND ServiceInvoiceLineItem.serviceID = ServiceOffering.serviceOfferingID
AND ProviderOffering.providerOfferingID IN
(
SELECT
ContractPOLink.providerOfferingID
FROM
UtilizationContract,
ContractVersion,
ContractPOLink
WHERE ContractVersion.concernRoleID = :resourceID
AND ContractVersion.contractType = :contractType
AND ContractVersion.status = :contractStatus
AND ContractVersion.contractVersionID = ContractPOLink.contractVersionID
AND ServiceInvoiceLineItem.serviceDateFrom BETWEEN ContractVersion.startDate AND ContractVersion.endDate
AND UtilizationContract.contractVersionID = ContractVersion.contractVersionID
)
)
AND InstructionLineItem.instructionLineItemType = :siliInstructionLineItemType
AND InstructionLineItem.instructLineItemCategory = :instructLineItemCategory
AND InstructionLineItem.statusCode = :statusCode
UNION ALL
SELECT
SUM(InstructionLineItem.amount) AS paymentAmt
FROM
CaseDecisionFinancialComp,
CaseDecisionObjective,
InstructionLineItem
WHERE CaseDecisionFinancialComp.caseDecisionObjectiveID = CaseDecisionObjective.caseDecisionObjectiveID
AND InstructionLineItem.financialCompID = CaseDecisionFinancialComp.financialCompID
AND CaseDecisionObjective.overflowInd = :overflowInd
AND CaseDecisionObjective.relatedReference IN
(
SELECT
CAST(ProviderRosterLineItem.providerRosterLineItemID AS CHAR(20))
FROM
ProviderRosterLineItem,
RosterLineItem,
Roster
WHERE Roster.concernRoleID = :resourceID
AND Roster.rosterID = RosterLineItem.rosterID
AND RosterLineItem.rosterLineItemID = ProviderRosterLineItem.rosterLineItemID
AND Roster.serviceID IN
(
SELECT
ContractPOLink.providerOfferingID
FROM
UtilizationContract,
ContractVersion,
ContractPOLink
WHERE ContractVersion.concernRoleID = :resourceID
AND ContractVersion.contractType = :contractType
AND ContractVersion.status = :contractStatus
AND ContractVersion.contractVersionID = ContractPOLink.contractVersionID
AND RosterLineItem.serviceFrom BETWEEN ContractVersion.startDate AND ContractVersion.endDate
AND UtilizationContract.contractVersionID = ContractVersion.contractVersionID
)
)
AND InstructionLineItem.instructionLineItemType = :rosterInstructionLineItemType
AND InstructionLineItem.instructLineItemCategory = :instructLineItemCategory
AND InstructionLineItem.statusCode = :statusCode
) InstructionLineItem
|