



CREATE PROCEDURE DBO.[GetVatValueProduct] @VatPercent FLOAT OUTPUT, @VatFrom INT OUTPUT, @DayProduct INT, @ProductNumber INT, @SegmentNumber INT, @PointofSaleNumber INT, @BookedTypeNumber INT AS
SET NOCOUNT ON
/*
  NB20050621: Created
  NOTE: Find the product vat value based on the system setup  
  STATUS: UNDER CONSTRUCTION
*/
DECLARE @GetVATFrom SMALLINT
, @WareNumber INT
, @VatProduct BIT
, @DummyBalanceAccountNumber INT
, @DummyResultAccountNumber INT
, @StayBalanceAccountNumber INT
, @StayResultAccountNumber INT
, @DummyVATAccountNumber INT
, @StayVATAccountNumber INT
, @WareText VARCHAR
, @LogiWareIndex INT
SELECT @GetVATFrom=CONVERT(INT,KeyValue) FROM HotelSetup WITH (NOLOCK)  WHERE  SearchKey='BookkeepingReport'
--Select the first roomline  info to calculate the vat amount 
IF ((@GetVATFrom>=0) AND (@GetVATFrom<>3))
BEGIN
  IF (@GetVATFrom=0) -- Get Vat From Segment
    EXEC GetVatValueAndAccountnumbers @DayProduct, @GetVatFrom, @SegmentNumber, @WareNumber OUTPUT, @DummyBalanceAccountNumber OUTPUT, @DummyResultAccountNumber OUTPUT, @DummyVATAccountNumber OUTPUT , @VatPercent OUTPUT, @WareText OUTPUT
  ELSE
  IF (@GetVATFrom=1) -- Get Vat From POS
    EXEC GetVatValueAndAccountnumbers @DayProduct, @GetVatFrom, @PointOfSaleNumber, @WareNumber OUTPUT, @StayBalanceAccountNumber OUTPUT, @StayResultAccountNumber OUTPUT, @StayVATAccountNumber OUTPUT , @VatPercent OUTPUT, @WareText OUTPUT
  ELSE IF (@GetVATFrom=2) -- Get Vat From Roomtype -- TODO ConferenceRoom if DayProduct
    EXEC GetVatValueAndAccountnumbers @DayProduct, @GetVatFrom, @BookedTypeNumber, @WareNumber OUTPUT, @StayBalanceAccountNumber OUTPUT, @StayResultAccountNumber OUTPUT, @StayVATAccountNumber OUTPUT , @VatPercent OUTPUT, @WareText OUTPUT
  ELSE IF (@GetVATFrom=4) -- VAT
  BEGIN
    IF  @ProductNumber>0
    BEGIN
      SELECT @VATProduct = ISNULL(ExcludeVAT,0) FROM Products WITH (NOLOCK) WHERE ProductNumber=@ProductNumber
      IF @VATProduct = 0 
        SET @VATProduct = 1
      ELSE
        SET @VATProduct = 0
    END
    --SET @LogiWareIndex = @VATProduct+1
    EXEC GetVatValueAndAccountnumbers @DayProduct, @GetVatFrom, @LogiWareIndex, @WareNumber OUTPUT, @StayBalanceAccountNumber OUTPUT, @StayResultAccountNumber OUTPUT, @StayVATAccountNumber OUTPUT , @VatPercent OUTPUT, @WareText OUTPUT
  END
END
ELSE --Get Vat From Producttype
  EXEC GetVatValueAndAccountnumbers @DayProduct, @GetVatFrom, @ProductNumber,  @WareNumber OUTPUT, @StayBalanceAccountNumber OUTPUT, @StayResultAccountNumber OUTPUT, @StayVATAccountNumber OUTPUT , @VatPercent OUTPUT, @WareText OUTPUT
--TODO: Avoid the account/ware numbers overhead, a split of GetVatValueAndAccountnumbers needed

