@Override
  public ValidationResult validate() {
    ValidationResult result = super.validate();

    if (AccounterValidator.isInPreventPostingBeforeDate(this.transactionDate)) {
      result.addError(transactionDateItem, messages.invalidateDate());
    }

    result.add(payForm.validate());

    if (!AccounterValidator.isPositiveAmount(amountText.getAmount())) {
      amountText.textBox.addStyleName("highlightedFormItem");
      result.addError(amountText, messages.valueCannotBe0orlessthan0(messages.amount()));
    }
    ClientAccount bankAccount = depositInCombo.getSelectedValue();
    // check if the currency of accounts is valid or not
    if (bankAccount != null) {
      ClientCurrency bankCurrency = getCurrency(bankAccount.getCurrency());
      ClientCurrency customerCurrency = getCurrency(customer.getCurrency());
      if (bankCurrency != getBaseCurrency() && bankCurrency != customerCurrency) {
        result.addError(depositInCombo, messages.selectProperBankAccount());
      }
    }
    return result;
  }
  @Override
  protected void createControls() {
    Label lab1 = new Label(messages.payeePrePayment(Global.get().Customer()));
    lab1.setStyleName("label-title");
    // lab1.setHeight("35px");
    transactionDateItem = createTransactionDateItem();

    transactionNumber = createTransactionNumberItem();

    listforms = new ArrayList<DynamicForm>();
    locationCombo = createLocationCombo();
    DynamicForm dateNoForm = new DynamicForm("datenumber-panel");
    dateNoForm.add(transactionDateItem, transactionNumber);

    StyledPanel datepanel = new StyledPanel("datepanel");
    datepanel.add(dateNoForm);

    StyledPanel labeldateNoLayout = new StyledPanel("labeldateNoLayout");
    labeldateNoLayout.add(lab1);
    labeldateNoLayout.add(datepanel);
    // customer and address
    customerCombo = createCustomerComboItem(messages.payeeName(Global.get().Customer()));

    billToCombo = createBillToComboItem(messages.address());
    billToCombo.setEnabled(false);

    // Ending and Vendor Balance
    bankBalText = new AmountField(messages.bankBalance(), this, getBaseCurrency(), "bankBalText");
    bankBalText.setEnabled(false);

    customerBalText =
        new AmountField(
            messages.payeeBalance(Global.get().Customer()),
            this,
            getBaseCurrency(),
            "customerBalText");
    customerBalText.setEnabled(false);

    DynamicForm balForm = new DynamicForm("balForm");
    if (locationTrackingEnabled) balForm.add(locationCombo);
    classListCombo = createAccounterClassListCombo();
    if (isTrackClass()) {
      balForm.add(classListCombo);
    }
    jobListCombo = createJobListCombo();
    if (isTrackJob()) {
      jobListCombo.setEnabled(false);
      balForm.add(jobListCombo);
    }
    balForm.add(bankBalText, customerBalText);
    // balForm.getCellFormatter().setWidth(0, 0, "205px");

    // payment
    depositInCombo = createDepositInComboItem(bankBalText);
    // depositInCombo.setPopupWidth("500px");

    amountText = new AmountField(messages.amount(), this, getBaseCurrency(), "amountText");
    amountText.setRequired(true);
    amountText.addBlurHandler(getBlurHandler());

    paymentMethodCombo = createPaymentMethodSelectItem();
    paymentMethodCombo.setComboItem(UIUtils.getpaymentMethodCheckBy_CompanyType(messages.check()));
    // printCheck = new CheckboxItem(messages.toBePrinted());
    // printCheck.setValue(true);
    // printCheck.addChangeHandler(new ValueChangeHandler<Boolean>() {
    //
    // @Override
    // public void onValueChange(ValueChangeEvent<Boolean> event) {
    // isChecked = (Boolean) event.getValue();
    // if (isChecked) {
    // if (printCheck.getValue().toString()
    // .equalsIgnoreCase("true")) {
    // checkNo.setValue(messages.toBePrinted());
    // checkNo.setDisabled(true);
    // } else {
    // if (depositInAccount == null)
    // checkNo.setValue(messages
    // .toBePrinted());
    // else if (isInViewMode()) {
    // checkNo.setValue(((ClientCustomerPrePayment) transaction)
    // .getCheckNumber());
    // }
    // }
    // } else
    // // setCheckNumber();
    // checkNo.setValue("");
    // checkNo.setDisabled(false);
    //
    // }
    // });
    checkNo = createCheckNumberItm();
    // checkNo.setValue(messages.toBePrinted());
    // checkNo.setDisabled(true);
    checkNo.addChangeHandler(
        new ChangeHandler() {

          @Override
          public void onChange(ChangeEvent event) {
            checkNumber = checkNo.getValue().toString();
          }
        });
    checkNo.setEnabled(!isInViewMode());
    currencyWidget = createCurrencyFactorWidget();
    payForm = UIUtils.form(messages.payment());
    memoTextAreaItem = createMemoTextAreaItem();
    // refText = createRefereceText();
    // refText.setWidth(100);
    payForm.add(
        customerCombo,
        billToCombo,
        depositInCombo,
        amountText,
        paymentMethodCombo,
        checkNo,
        memoTextAreaItem);
    // memo and Reference
    ClientAccount selectedValue = depositInCombo.getSelectedValue();
    if (selectedValue != null) {
      bankBalText.setAmount(selectedValue.getTotalBalanceInAccountCurrency());
      bankBalText.setCurrency(getCompany().getCurrency(selectedValue.getCurrency()));
    }

    // payForm.getCellFormatter().setWidth(0, 0, "160px");

    StyledPanel leftPanel = new StyledPanel("leftPanel");
    leftPanel.add(payForm);
    // leftPanel.add(payForm);
    // leftPanel.add(memoForm);

    StyledPanel rightPanel = new StyledPanel("rightPanel");
    rightPanel.add(balForm);
    if (isMultiCurrencyEnabled()) {
      rightPanel.add(currencyWidget);
    }

    StyledPanel mainVLay = new StyledPanel("mainVLay");
    mainVLay.add(voidedPanel);
    mainVLay.add(labeldateNoLayout);
    StyledPanel hLay = getTopLayOut();
    if (hLay != null) {
      hLay.add(leftPanel);
      hLay.add(rightPanel);
      mainVLay.add(hLay);
    } else {
      mainVLay.add(leftPanel);
      mainVLay.add(rightPanel);
    }

    this.add(mainVLay);

    /* Adding dynamic forms in list */
    listforms.add(dateNoForm);
    listforms.add(balForm);
    listforms.add(payForm);
    // settabIndexes();
  }