CREATE PROC sp_GetQuoteItemsFinal
(
	@ParentSurfaceItemId INT = 0
)
AS

SELECT  Q.itemID
		,Q.isActive
		,Q.surfaceId
		,Q.ParentSurfaceItemId
		,Q.QuoteItemsFinal_QuoteItemsFinal_QuoteItemsFinalSequenceNumber
		,Q.QuoteItemsFinal_QuoteItemsFinal_QuoteItemsFinalPartNumber
		,Q.QuoteItemsFinal_QuoteItemsFinal_QuoteItemsFinalMasterPartNumber
		,Q.QuoteItemsFinal_QuoteItemsFinal_QuoteItemsFinalDescription
		,Q.QuoteItemsFinal_QuoteItemsFinal_QuoteItemsFinalQuantityRequired
		,Q.QuoteItemsFinal_QuoteItemsFinal_QuoteItemsFinalBrand
		,Q.QuoteItemsFinal_QuoteItemsFinal_QuoteItemsFinalCondition
		,Q.QuoteItemsFinal_QuoteItemsFinal_QuoteItemsFinalLeadTime
		,Q.QuoteItemsFinal_QuoteItemsFinal_QuoteItemsFinalWeightKG
		,(Q.QuoteItemsFinal_QuoteItemsFinal_QuoteItemsFinalQuantityAvailable - ISNULL(Q.QuoteItemsFinal_QuoteItemsFinal_InvoicedQty,0)) AS QuoteItemsFinal_QuoteItemsFinal_QuoteItemsFinalQuantityAvailable
		,Q.QuoteItemsFinal_QuoteItemsFinal_QuoteItemsFinalUnitPriceZAR
		,Q.QuoteItemsFinal_QuoteItemsFinal_QuoteItemsFinalTotalPriceZAR
		,Q.QuoteItemsFinal_QuoteItemsFinal_QuoteItemsFinalUniqueNumber
		,Q.QuoteItemsFinal_QuoteItemsFinal_QuoteItemsFinalCategory
		,Q.QuoteItemsFinal_QuoteItemsFinal_QuoteItemsFinalSubCategory
		,Q.QuoteItemsFinal_QuoteItemsFinal_QuoteItemsFinalMinorCode
		,Q.QuoteItemsFinal_QuoteItemsFinal_QuoteItemsFinalAdditionalDescription
		,Q.QuoteItemsFinal_QuoteItemsFinal_QuoteItemsFinalDimensionalDescription
		,Q.recId
		,Q.QuoteItemsFinal_QuoteItemsFinal_InvoicedQty
		,Q.QuoteItemsFinal_QuoteItemsFinal_QuoteItemsLink
FROM	publ_QuoteItemsFinal Q
WHERE	Q.ParentSurfaceItemId = @ParentSurfaceItemId  
		AND Q.isActive = '1'  
		AND ISNULL(Q.QuoteItemsFinal_QuoteItemsFinal_InvoicedQty,0) < Q.QuoteItemsFinal_QuoteItemsFinal_QuoteItemsFinalQuantityAvailable