/*
 * Copyright (c) 2005-2010 Grameen Foundation USA
 * All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
 *
 * See also http://www.apache.org/licenses/LICENSE-2.0.html for an
 * explanation of the license and how it is applied.
 */

package org.mifos.test.acceptance.framework.savingsproduct;

import org.mifos.test.acceptance.framework.MifosPage;

import com.thoughtworks.selenium.Selenium;

public class DefineNewSavingsProductPage extends MifosPage {
    public DefineNewSavingsProductPage(Selenium selenium) {
        super(selenium);
    }

    public void verifyPage() {
        verifyPage("CreateSavingsProduct");
    }

    public DefineNewSavingsProductPreviewPage submitAndNavigateToDefineNewSavingsProductPreviewPage(SavingsProductParameters productParameters) {
        selenium.type("CreateSavingsProduct.input.prdOfferingName", productParameters.getProductInstanceName());
        selenium.type("CreateSavingsProduct.input.prdOfferingShortName", productParameters.getShortName());
        selenium.type("startDateDD", productParameters.getStartDateDD());
        selenium.type("startDateMM", productParameters.getStartDateMM());
        selenium.type("startDateYY", productParameters.getStartDateYYYY());

        selectValueIfNotZero("savingsProduct.generalDetails.selectedCategory", productParameters.getProductCategory());

        selectValueIfNotZero("savingsProduct.generalDetails.selectedApplicableFor", productParameters.getApplicableFor());
        selectValueIfNotZero("savingsProduct.selectedDepositType", productParameters.getTypeOfDeposits());
        typeTextIfNotEmpty("savingsProduct.amountForDeposit", productParameters.getMandatoryAmount());
        selectValueIfNotZero("savingsProduct.selectedGroupSavingsApproach", productParameters.getAmountAppliesTo());
        selenium.type("savingsProduct.interestRate", productParameters.getInterestRate());

        selectValueIfNotZero("savingsProduct.selectedInterestCalculation", productParameters.getBalanceUsedForInterestCalculation());

        selenium.type("savingsProduct.interestCalculationFrequency", productParameters.getNumberOfDaysOrMonthsForInterestCalculation());
        selectValueIfNotZero("savingsProduct.selectedFequencyPeriod", productParameters.getDaysOrMonthsForInterestCalculation());

        selenium.type("savingsProduct.selectedFequencyPeriod", productParameters.getFrequencyOfInterestPostings());

        selectIfNotEmpty("savingsProduct.selectedPrincipalGlCode", productParameters.getGlCodeForDeposit());
        selectIfNotEmpty("savingsProduct.selectedInterestGlCode", productParameters.getGlCodeForInterest());

        selenium.click("CreateSavingsProduct.button.preview");
        waitForPageToLoad();

        return new DefineNewSavingsProductPreviewPage(selenium);
    }
}

@@ -1769,39 +1769,24 @@
 eIfNotZero(%22
-savingsProduct.
 generalDetai
@@ -1879,31 +1879,16 @@
 otZero(%22
-savingsProduct.
 generalD
@@ -1983,39 +1983,24 @@
 eIfNotZero(%22
-savingsProduct.
 selectedDepo
@@ -2077,31 +2077,16 @@
 tEmpty(%22
-savingsProduct.
 amountFo
@@ -2163,39 +2163,24 @@
 eIfNotZero(%22
-savingsProduct.
 selectedGrou
@@ -2258,39 +2258,24 @@
 enium.type(%22
-savingsProduct.
 interestRate
@@ -2342,39 +2342,24 @@
 eIfNotZero(%22
-savingsProduct.
 selectedInte
@@ -2459,31 +2459,16 @@
 m.type(%22
-savingsProduct.
 interest
@@ -2588,31 +2588,16 @@
 otZero(%22
-savingsProduct.
 selected
@@ -2697,31 +2697,16 @@
 m.type(%22
-savingsProduct.
 selected
@@ -2798,39 +2798,24 @@
 IfNotEmpty(%22
-savingsProduct.
 selectedPrin
@@ -2900,23 +2900,8 @@
 ty(%22
-savingsProduct.
 sele

fix failing acceptance tests around saving product creation.