@Override
  public void restoreView(HashMap<String, Object> map) {

    if (map == null || map.isEmpty()) {
      return;
    }
    String activeInactive = (String) map.get("activeInActive");
    activeInActiveSelect.setComboItem(activeInactive);
    if (activeInactive.equalsIgnoreCase(messages.active())) {
      refreshActiveinactiveList(true);
    } else {
      refreshActiveinactiveList(false);
    }

    String currentView = (String) map.get("currentView");
    trasactionViewSelect.setComboItem(currentView);
    if (currentView != null) {
      getMessagesList();
    }

    String transctionType = (String) map.get("transactionType");
    trasactionViewTypeSelect.setComboItem(transctionType);

    String dateRange1 = (String) map.get("dateRange");
    dateRangeSelector.setComboItem(dateRange1);
    if (dateRange1 != null) {
      dateRangeChanged(dateRange1);
    }
    ClientItem object = (ClientItem) map.get("itemSelection");
    itemsListGrid.setSelection(object);

    String customer = (String) map.get("selectedItem");

    if (customer != null && !(customer.isEmpty())) {
      selectedItem = getCompany().getItemByName(customer);
    }
    if (this.selectedItem != null) {
      itemsListGrid.setSelectedItem(selectedItem);

      selectedItem = Accounter.getCompany().getItem(selectedItem.getID());

      onItemSelected();
    } else {
      callRPC(0, getPageSize());
    }
  }
  public void dateRangeChanged(String dateRange) {
    ClientFinanceDate date = new ClientFinanceDate();
    startDate = Accounter.getStartDate();
    endDate = getCompany().getCurrentFiscalYearEndDate();
    // getLastandOpenedFiscalYearEndDate();
    if (dateRange.equals(messages.thisWeek())) {
      startDate = getWeekStartDate();
      endDate.setDay(startDate.getDay() + 6);
      endDate.setMonth(startDate.getMonth());
      endDate.setYear(startDate.getYear());
    }
    if (dateRange.equals(messages.thisMonth())) {
      startDate = new ClientFinanceDate(date.getYear(), date.getMonth(), 1);
      Calendar endCal = Calendar.getInstance();
      endCal.setTime(new ClientFinanceDate().getDateAsObject());
      endCal.set(Calendar.DAY_OF_MONTH, endCal.getActualMaximum(Calendar.DAY_OF_MONTH));
      endDate = new ClientFinanceDate(endCal.getTime());
    }
    if (dateRange.equals(messages.lastWeek())) {
      endDate = getWeekStartDate();
      endDate.setDay(endDate.getDay() - 1);
      startDate = new ClientFinanceDate(endDate.getDate());
      startDate.setDay(startDate.getDay() - 6);
    }
    if (dateRange.equals(messages.lastMonth())) {
      int day;
      if (date.getMonth() == 0) {
        day = getMonthLastDate(11, date.getYear() - 1);
        startDate = new ClientFinanceDate(date.getYear() - 1, 11, 1);
        endDate = new ClientFinanceDate(date.getYear() - 1, 11, day);
      } else {
        day = getMonthLastDate(date.getMonth() - 1, date.getYear());
        startDate = new ClientFinanceDate(date.getYear(), date.getMonth() - 1, 1);
        endDate = new ClientFinanceDate(date.getYear(), date.getMonth() - 1, day);
      }
    }
    if (dateRange.equals(messages.thisFinancialYear())) {
      startDate = getCompany().getCurrentFiscalYearStartDate();
      endDate = getCompany().getCurrentFiscalYearEndDate();
    }
    if (dateRange.equals(messages.lastFinancialYear())) {

      startDate = Accounter.getCompany().getCurrentFiscalYearStartDate();
      startDate.setYear(startDate.getYear() - 1);
      Calendar endCal = Calendar.getInstance();
      endCal.setTime(Accounter.getCompany().getCurrentFiscalYearEndDate().getDateAsObject());
      endCal.set(Calendar.DAY_OF_MONTH, endCal.getActualMaximum(Calendar.DAY_OF_MONTH));
      endDate = new ClientFinanceDate(endCal.getTime());
      endDate.setYear(endDate.getYear() - 1);
    }
    if (dateRange.equals(messages.thisFinancialQuarter())) {
      startDate = new ClientFinanceDate();
      endDate = getCompany().getCurrentFiscalYearEndDate();
      // getLastandOpenedFiscalYearEndDate();
      getCurrentQuarter();
    }
    if (dateRange.equals(messages.lastFinancialQuarter())) {
      startDate = new ClientFinanceDate();
      endDate = getCompany().getCurrentFiscalYearEndDate();
      // getLastandOpenedFiscalYearEndDate();
      getCurrentQuarter();
      startDate.setYear(startDate.getYear() - 1);
      endDate.setYear(endDate.getYear() - 1);
    }
    if (dateRange.equals(messages.financialYearToDate())) {
      startDate = getCompany().getCurrentFiscalYearStartDate();
      endDate = new ClientFinanceDate();
    }
  }
  @Override
  protected void initTransactionViewData() {
    if (transaction == null) {
      setData(new ClientCustomerPrePayment());
      initDepositInAccounts();
    } else {

      if (currencyWidget != null) {
        this.currency = getCompany().getCurrency(transaction.getCurrency());
        this.currencyFactor = transaction.getCurrencyFactor();
        currencyWidget.setSelectedCurrency(this.currency);
        // currencyWidget.currencyChanged(this.currency);
        currencyWidget.setCurrencyFactor(transaction.getCurrencyFactor());
        currencyWidget.setEnabled(!isInViewMode());
      }
      ClientCompany comapny = getCompany();

      ClientCustomer customer = comapny.getCustomer(transaction.getCustomer());
      customerSelected(comapny.getCustomer(transaction.getCustomer()));
      this.billingAddress = transaction.getAddress();
      if (billingAddress != null) billToaddressSelected(billingAddress);
      amountText.setEnabled(!isInViewMode());
      amountText.setAmount(transaction.getTotal());
      if (customer != null) {
        customerBalText.setAmount(customer.getBalance());
      }
      // bankBalText.setAmount(getAmountInTransactionCurrency(transaction.g));
      paymentMethodSelected(transaction.getPaymentMethod());
      this.depositInAccount = comapny.getAccount(transaction.getDepositIn());
      if (depositInAccount != null) {
        depositInCombo.setComboItem(depositInAccount);
        bankBalText.setAmount(depositInAccount.getTotalBalanceInAccountCurrency());
        bankBalText.setCurrency(getCompany().getCurrency(depositInAccount.getCurrency()));
      }
      if (isTrackClass()) {
        classListCombo.setComboItem(
            getCompany().getAccounterClass(transaction.getAccounterClass()));
      }
      paymentMethodCombo.setComboItem(transaction.getPaymentMethod());
      checkNo.setValue(transaction.getCheckNumber());
      // if (transaction.getPaymentMethod().equals(constants.check())) {
      // printCheck.setDisabled(isInViewMode());
      // checkNo.setDisabled(isInViewMode());
      // } else {
      // printCheck.setDisabled(true);
      // checkNo.setDisabled(true);
      // }

      // if (transaction.getCheckNumber() != null) {
      // if (transaction.getCheckNumber().equals(
      // messages.toBePrinted())) {
      // checkNo.setValue(messages.toBePrinted());
      // printCheck.setValue(true);
      // } else {
      // checkNo.setValue(transaction.getCheckNumber());
      // printCheck.setValue(false);
      // }
      // }
    }
    if (locationTrackingEnabled)
      locationSelected(getCompany().getLocation(transaction.getLocation()));
    if (isTrackJob()) {
      if (customer != null) {
        jobListCombo.setCustomer(customer);
      }
      jobSelected(Accounter.getCompany().getjob(transaction.getJob()));
    }
    initMemoAndReference();
    initCustomers();
    if (isMultiCurrencyEnabled()) {
      updateAmountsFromGUI();
    }
  }