private int getTransactionType() {
   String selectedValue = trasactionViewSelect.getSelectedValue();
   if (selectedValue.equalsIgnoreCase(messages.invoices())) {
     return ClientTransaction.TYPE_INVOICE;
   } else if (selectedValue.equalsIgnoreCase(messages.cashSales())) {
     return ClientTransaction.TYPE_CASH_SALES;
   } else if (selectedValue.equalsIgnoreCase(messages.payeeCreditNotes(Global.get().Customer()))) {
     return ClientTransaction.TYPE_CUSTOMER_CREDIT_MEMO;
   } else if (selectedValue.equalsIgnoreCase(messages.quotes())
       || selectedValue.equalsIgnoreCase(messages.credits())
       || selectedValue.equalsIgnoreCase(messages.Charges())) {
     return ClientTransaction.TYPE_ESTIMATE;
   } else if (trasactionViewSelect.getSelectedValue().equalsIgnoreCase(messages.cashPurchases())) {
     return ClientTransaction.TYPE_CASH_PURCHASE;
   } else if (trasactionViewSelect.getSelectedValue().equalsIgnoreCase(messages.bills())) {
     return ClientTransaction.TYPE_ENTER_BILL;
   } else if (trasactionViewSelect
       .getSelectedValue()
       .equalsIgnoreCase(messages.payeeCreditNotes(Global.get().Vendor()))) {
     return ClientTransaction.TYPE_VENDOR_CREDIT_MEMO;
   } else if (trasactionViewSelect.getSelectedValue().equalsIgnoreCase(messages.expenses())) {
     return ClientTransaction.TYPE_EXPENSE;
   } else if (trasactionViewSelect.getSelectedValue().equalsIgnoreCase(messages.salesOrders())) {
     return TransactionHistory.TYPE_SALES_ORDER;
   } else if (trasactionViewSelect
       .getSelectedValue()
       .equalsIgnoreCase(messages.purchaseOrders())) {
     return TransactionHistory.TYPE_PURCHASE_ORDER;
   }
   return 0;
 }
Exemplo n.º 2
0
  @Override
  public void selfValidate() throws AccounterException {
    super.selfValidate();
    // Checking transaction items empty
    if (getTransactionItems() == null || getTransactionItems().isEmpty()) {
      throw new AccounterException(
          AccounterException.ERROR_NO_RECORDS_TO_SAVE, Global.get().messages().journalEntry());
    }
    // checking for Amounts zero or negative
    List<TransactionItem> entrylist = this.getTransactionItems();
    for (TransactionItem entry : entrylist) {
      if (entry.getLineTotal() == null || entry.getLineTotal() == 0) {
        throw new AccounterException(
            AccounterException.ERROR_AMOUNT_ZERO, Global.get().messages().amount());
      }
    }

    // Checking Accounts same

    for (TransactionItem entry : entrylist) {
      long accountId = entry.getAccount().getID();
      for (TransactionItem entry2 : entrylist) {
        long accountId2 = entry2.getAccount().getID();
        if (!entry.equals(entry2) && accountId == accountId2) {
          throw new AccounterException(
              AccounterException.ERROR_SHOULD_NOT_SELECT_SAME_ACCOUNT_MULTIPLE_TIMES);
        }
      }
    }
    checkCreditsAndDebits();
  }
Exemplo n.º 3
0
 @Override
 public void selfValidate() throws AccounterException {
   if (themeName == null || themeName.trim().isEmpty()) {
     throw new AccounterException(
         AccounterException.ERROR_NAME_NULL, Global.get().messages().brandingTheme());
   }
 }
Exemplo n.º 4
0
  @Override
  public void addButtons(ButtonGroup group) {

    ImageButton addCustomerButton = null;
    if (Accounter.isIpadApp()) {
      addCustomerButton = new ImageButton(Accounter.getFinanceImages().ipadAdd(), "add");
    } else {
      addCustomerButton =
          new ImageButton(
              messages.addNew(Global.get().Customer()),
              Accounter.getFinanceImages().portletPageSettings(),
              "add");
    }

    addCustomerButton.addStyleName("settingsButton");
    addCustomerButton.getElement().setId("addCustomerButton");
    addCustomerButton.addClickHandler(
        new ClickHandler() {

          @Override
          public void onClick(ClickEvent event) {
            ActionFactory.getNewCustomerAction().run();
          }
        });

    addCustomerButton.getElement().setAttribute("data-icon", "add");
    addButton(group, addCustomerButton);
  }
Exemplo n.º 5
0
  @Override
  public void exportToCsv() {
    if (selectedCustomer != null) {
      Accounter.createExportCSVService()
          .getCustomerTransactionsListExportCsv(
              selectedCustomer,
              getTransactionType(),
              getTransactionStatusType(),
              getStartDate(),
              getEndDate(),
              new AsyncCallback<String>() {

                @Override
                public void onSuccess(String id) {
                  UIUtils.downloadFileFromTemp(
                      trasactionViewSelect.getSelectedValue()
                          + " of "
                          + selectedCustomer.getName()
                          + ".csv",
                      id);
                }

                @Override
                public void onFailure(Throwable caught) {
                  caught.printStackTrace();
                }
              });
    } else {
      Accounter.showError(messages.pleaseSelect(Global.get().Customer()));
    }
  }
Exemplo n.º 6
0
  @Override
  public void writeAudit(AuditWriter w) throws JSONException {
    AccounterMessages messages = Global.get().messages();

    w.put(messages.type(), messages.brandingTheme()).gap();

    w.put(messages.name(), this.themeName);
  }
Exemplo n.º 7
0
 public List<String> getFaxTypes() {
   List<String> valueMap = new ArrayList<String>();
   AccounterMessages messages = Global.get().messages();
   valueMap.add(messages.company());
   valueMap.add(messages.clientAddresshome());
   valueMap.add(messages.other());
   return valueMap;
 }
 @Override
 public String[] getColunms() {
   return new String[] {
     Global.get().customer(),
     getMessages().date(),
     getMessages().type(),
     getMessages().noDot(),
     getMessages().amount()
   };
 }
 @Override
 public String[] getDynamicHeaders() {
   return new String[] {
     Global.get().customer(),
     getMessages().job(),
     getMessages().type(),
     getMessages().date(),
     getMessages().memo(),
     getMessages().account(),
     getMessages().amount()
   };
 }
Exemplo n.º 10
0
  @Override
  public void writeAudit(AuditWriter w) throws JSONException {
    if (getSaveStatus() == STATUS_DRAFT) {
      return;
    }

    AccounterMessages messages = Global.get().messages();

    w.put(messages.type(), messages.journalEntry()).gap();
    w.put(messages.journalEntryNo(), this.number);

    w.put(messages.date(), this.transactionDate.toString()).gap().gap();
    w.put(messages.currency(), this.currencyFactor).gap().gap();

    w.put(messages.memo(), this.memo);

    w.put(messages.details(), this.transactionPayBills);
    w.put(messages.details(), this.transactionReceivePayments);
  }
Exemplo n.º 11
0
  private void transactionViewSelectCombo() {
    if (trasactionViewSelect == null) {
      trasactionViewSelect = new SelectCombo(messages.currentView());

      List<String> transactionTypeList = new ArrayList<String>();
      transactionTypeList.add(messages.allTransactions());
      transactionTypeList.add(messages.invoices());
      if (getPreferences().isDoyouwantEstimates()) {
        transactionTypeList.add(messages.quotes());
      }
      if (getCompany().getPreferences().isDelayedchargesEnabled()) {
        transactionTypeList.add(messages.Charges());
        transactionTypeList.add(messages.credits());
      }
      transactionTypeList.add(messages.cashSales());
      transactionTypeList.add(messages.receivedPayments());
      transactionTypeList.add(messages.CustomerCreditNotes());
      transactionTypeList.add(messages.customerRefunds(Global.get().Customer()));
      transactionTypeList.add(messages.cheques());
      if (getPreferences().isSalesOrderEnabled()) {
        transactionTypeList.add(messages.salesOrders());
      }
      trasactionViewSelect.initCombo(transactionTypeList);
      trasactionViewSelect.setComboItem(messages.allTransactions());
      trasactionViewSelect.addSelectionChangeHandler(
          new IAccounterComboSelectionChangeHandler<String>() {

            @Override
            public void selectedComboBoxItem(String selectItem) {
              if (trasactionViewSelect.getSelectedValue() != null) {
                getMessagesList();
                callRPC(0, getPageSize());
              }
            }
          });
    }
  }
Exemplo n.º 12
0
  private int getTransactionType() {
    String selectedValue = trasactionViewSelect.getSelectedValue();
    if (selectedValue.equalsIgnoreCase(messages.invoices())) {

      return TYPE_INVOICE;
    } else if (selectedValue.equalsIgnoreCase(messages.cashSales())) {
      return TYPE_CAHSSALE;
    } else if (selectedValue.equalsIgnoreCase(messages.receivedPayments())) {
      return TYPE_RECEIVE_PAYMENT;
    } else if (selectedValue.equalsIgnoreCase(messages.CustomerCreditNotes())) {
      return TYPE_CREDITNOTE;
    } else if (selectedValue.equalsIgnoreCase(messages.quotes())
        || selectedValue.equalsIgnoreCase(messages.credits())
        || selectedValue.equalsIgnoreCase(messages.Charges())) {
      return TYPE_ESTIMATE;
    } else if (selectedValue.equalsIgnoreCase(messages.customerRefunds(Global.get().Customer()))) {
      return TYPE_CUSTOMER_REFUND;
    } else if (selectedValue.equalsIgnoreCase(messages.cheques())) {
      return TYPE_WRITE_CHECK;
    } else if (selectedValue.equalsIgnoreCase(messages.salesOrders())) {
      return TYPE_SALES_ORDER;
    }
    return TYPE_ALL_TRANSACTION;
  }
Exemplo n.º 13
0
  private void getMessagesList() {
    String selectedValue = trasactionViewSelect.getSelectedValue();
    transactiontypebyStatusMap = new HashMap<Integer, String>();
    if (trasactionViewSelect.getSelectedValue().equalsIgnoreCase(messages.allTransactions())) {
      transactiontypebyStatusMap.put(
          TransactionHistory.ALL_TRANSACTIONS, messages.allTransactions());
    } else if (selectedValue.equalsIgnoreCase(messages.quotes())) {

      transactiontypebyStatusMap.put(TransactionHistory.ALL_QUOTES, messages.allQuotes());
      transactiontypebyStatusMap.put(
          TransactionHistory.DRAFT_QUOTES, messages.draftTransaction(messages.quotes()));

    } else if (selectedValue.equalsIgnoreCase(messages.Charges())) {

      transactiontypebyStatusMap.put(TransactionHistory.ALL_CHARGES, messages.allCahrges());
      transactiontypebyStatusMap.put(
          TransactionHistory.DRAFT_CHARGES, messages.draftTransaction(messages.Charges()));

    } else if (selectedValue.equalsIgnoreCase(messages.credits())) {
      transactiontypebyStatusMap.put(TransactionHistory.ALL_CREDITS, messages.allCredits());
      transactiontypebyStatusMap.put(
          TransactionHistory.DRAFT_CREDITS, messages.draftTransaction(messages.credits()));

    } else if (selectedValue.equalsIgnoreCase(messages.invoices())) {
      transactiontypebyStatusMap.put(TransactionHistory.ALL_INVOICES, messages.getallInvoices());
      transactiontypebyStatusMap.put(
          TransactionHistory.OPENED_INVOICES, messages.getOpendInvoices());
      transactiontypebyStatusMap.put(
          TransactionHistory.OVER_DUE_INVOICES, messages.overDueInvoices());
      transactiontypebyStatusMap.put(
          TransactionHistory.DRAFT_INVOICES, messages.draftTransaction(messages.invoices()));
    } else if (selectedValue.equalsIgnoreCase(messages.cashSales())) {
      transactiontypebyStatusMap.put(
          TransactionHistory.ALL_CASHSALES, messages.all() + " " + messages.cashSales());
      transactiontypebyStatusMap.put(
          TransactionHistory.DRAFT_CASHSALES, messages.draftTransaction(messages.cashSales()));

    } else if (selectedValue.equalsIgnoreCase(messages.payeeCreditNotes(Global.get().Customer()))) {
      transactiontypebyStatusMap.put(TransactionHistory.ALL_CREDITMEMOS, messages.allCreditMemos());
      transactiontypebyStatusMap.put(
          TransactionHistory.DRAFT_CREDITMEMOS, messages.draftTransaction(messages.creditNote()));
      // transactiontypebyStatusMap.put(
      // TransactionHistory.OPEND_CREDITMEMOS,
      // messages.openCreditMemos());

    } else if (trasactionViewSelect.getSelectedValue().equalsIgnoreCase(messages.cashPurchases())) {
      transactiontypebyStatusMap.put(
          TransactionHistory.ALL_CASH_PURCHASES, messages.allCashPurchases());
      transactiontypebyStatusMap.put(
          TransactionHistory.DRAFT_CASH_PURCHASES,
          messages.draftTransaction(messages.cashPurchases()));

    } else if (trasactionViewSelect.getSelectedValue().equalsIgnoreCase(messages.bills())) {
      transactiontypebyStatusMap.put(TransactionHistory.ALL_BILLS, messages.allBills());
      transactiontypebyStatusMap.put(
          TransactionHistory.OPEND_BILLS, messages.all() + " " + messages.openedBills());
      transactiontypebyStatusMap.put(
          TransactionHistory.OVERDUE_BILLS, messages.all() + " " + messages.overDueBills());
      transactiontypebyStatusMap.put(
          TransactionHistory.DRAFT_BILLS, messages.draftTransaction(messages.bills()));

    } else if (trasactionViewSelect
        .getSelectedValue()
        .equalsIgnoreCase(messages.payeeCreditNotes(Global.get().Vendor()))) {
      transactiontypebyStatusMap.put(
          TransactionHistory.ALL_VENDOR_CREDITNOTES,
          messages.all() + " " + messages.payeeCreditNotes(Global.get().Vendor()));
      transactiontypebyStatusMap.put(
          TransactionHistory.DRAFT_VENDOR_CREDITNOTES,
          messages.draftTransaction(messages.payeeCreditNotes(Global.get().Vendor())));

    } else if (trasactionViewSelect.getSelectedValue().equalsIgnoreCase(messages.expenses())) {
      transactiontypebyStatusMap.put(TransactionHistory.ALL_EXPENSES, messages.allExpenses());
      transactiontypebyStatusMap.put(
          TransactionHistory.CREDIT_CARD_EXPENSES, messages.creditCardExpenses());
      transactiontypebyStatusMap.put(TransactionHistory.CASH_EXPENSES, messages.cashExpenses());
      transactiontypebyStatusMap.put(
          TransactionHistory.DRAFT_CREDIT_CARD_EXPENSES,
          messages.draftTransaction(messages.creditCardExpenses()));
      transactiontypebyStatusMap.put(
          TransactionHistory.DRAFT_CASH_EXPENSES,
          messages.draftTransaction(messages.cashExpenses()));

    } else if (trasactionViewSelect.getSelectedValue().equalsIgnoreCase(messages.salesOrders())) {

      transactiontypebyStatusMap.put(TransactionHistory.ALL_SALES_ORDERS, messages.all());
      transactiontypebyStatusMap.put(TransactionHistory.DRAFT_SALES_ORDERS, messages.drafts());

    } else if (trasactionViewSelect
        .getSelectedValue()
        .equalsIgnoreCase(messages.purchaseOrders())) {

      transactiontypebyStatusMap.put(TransactionHistory.ALL_PURCHASE_ORDERS, messages.all());
      transactiontypebyStatusMap.put(TransactionHistory.DRAFT_PURCHASE_ORDERS, messages.drafts());
    }
    List<String> typeList = new ArrayList<String>(transactiontypebyStatusMap.values());
    Collections.sort(
        typeList,
        new Comparator<String>() {

          @Override
          public int compare(String entry1, String entry2) {
            return entry1.compareTo(entry2);
          }
        });
    trasactionViewTypeSelect.initCombo(typeList);
    trasactionViewTypeSelect.setComboItem(typeList.get(0));
  }
Exemplo n.º 14
0
 @Override
 protected String getViewTitle() {
   return messages.payees(Global.get().Customer());
 }
Exemplo n.º 15
0
  private void getMessagesList() {
    transactiontypebyStatusMap = new HashMap<Integer, String>();
    String selectedValue = trasactionViewSelect.getSelectedValue();
    if (selectedValue.equalsIgnoreCase(messages.allTransactions())) {
      transactiontypebyStatusMap.put(
          TransactionHistory.ALL_TRANSACTIONS, messages.allTransactions());
    } else if (selectedValue.equalsIgnoreCase(messages.invoices())) {
      transactiontypebyStatusMap.put(TransactionHistory.ALL_INVOICES, messages.getallInvoices());
      transactiontypebyStatusMap.put(
          TransactionHistory.OPENED_INVOICES, messages.getOpendInvoices());
      transactiontypebyStatusMap.put(
          TransactionHistory.OVER_DUE_INVOICES, messages.overDueInvoices());
      if (Accounter.hasPermission(Features.DRAFTS)) {
        transactiontypebyStatusMap.put(
            TransactionHistory.DRAFT_INVOICES, messages.draftTransaction(messages.invoices()));
      }
    } else if (selectedValue.equalsIgnoreCase(messages.cashSales())) {
      transactiontypebyStatusMap.put(
          TransactionHistory.ALL_CASHSALES, messages.all() + " " + messages.cashSales());
      if (Accounter.hasPermission(Features.DRAFTS)) {
        transactiontypebyStatusMap.put(
            TransactionHistory.DRAFT_CASHSALES, messages.draftTransaction(messages.cashSales()));
      }

    } else if (selectedValue.equalsIgnoreCase(messages.quotes())) {

      transactiontypebyStatusMap.put(TransactionHistory.ALL_QUOTES, messages.allQuotes());
      if (Accounter.hasPermission(Features.DRAFTS)) {
        transactiontypebyStatusMap.put(
            TransactionHistory.DRAFT_QUOTES, messages.draftTransaction(messages.quotes()));
      }
    } else if (selectedValue.equalsIgnoreCase(messages.credits())) {
      transactiontypebyStatusMap.put(TransactionHistory.ALL_CREDITS, messages.allCredits());
      if (Accounter.hasPermission(Features.DRAFTS)) {
        transactiontypebyStatusMap.put(
            TransactionHistory.DRAFT_CREDITS, messages.draftTransaction(messages.credits()));
      }

    } else if (selectedValue.equalsIgnoreCase(messages.Charges())) {

      transactiontypebyStatusMap.put(TransactionHistory.ALL_CHARGES, messages.allCahrges());
      if (Accounter.hasPermission(Features.DRAFTS)) {
        transactiontypebyStatusMap.put(
            TransactionHistory.DRAFT_CHARGES, messages.draftTransaction(messages.Charges()));
      }

    } else if (selectedValue.equalsIgnoreCase(messages.receivedPayments())) {
      transactiontypebyStatusMap.put(
          TransactionHistory.ALL_RECEIVEDPAYMENTS,
          messages.all() + " " + messages.receivedPayments());
      transactiontypebyStatusMap.put(
          TransactionHistory.RECEV_PAY_BY_CASH, messages.receivedPaymentsbyCash());
      transactiontypebyStatusMap.put(
          TransactionHistory.RECEV_PAY_BY_CHEQUE, messages.receivedPaymentsbyCheque());
      transactiontypebyStatusMap.put(
          TransactionHistory.RECEV_PAY_BY_CREDITCARD, messages.receivedPaymentsbyCreditCard());
      transactiontypebyStatusMap.put(
          TransactionHistory.RECEV_PAY_BY_DIRECT_DEBIT, messages.receivedPaymentsbyDirectDebit());
      transactiontypebyStatusMap.put(
          TransactionHistory.RECEV_PAY_BY_MASTERCARD, messages.receivedPaymentsbyMastercard());
      transactiontypebyStatusMap.put(
          TransactionHistory.RECEV_PAY_BY_ONLINE, messages.receivedPaymentsbyOnlineBanking());
      transactiontypebyStatusMap.put(
          TransactionHistory.RECEV_PAY_BY_STANDING_ORDER,
          messages.receivedPaymentsbyStandingOrder());
      transactiontypebyStatusMap.put(
          TransactionHistory.RECEV_PAY_BY_MAESTRO, messages.receivedPaymentsbySwitchMaestro());

    } else if (selectedValue.equalsIgnoreCase(messages.CustomerCreditNotes())) {
      transactiontypebyStatusMap.put(TransactionHistory.ALL_CREDITMEMOS, messages.allCreditMemos());
      if (Accounter.hasPermission(Features.DRAFTS)) {
        transactiontypebyStatusMap.put(
            TransactionHistory.DRAFT_CREDITMEMOS, messages.draftTransaction(messages.creditNote()));
      }
      // transactiontypebyStatusMap.put(
      // TransactionHistory.OPEND_CREDITMEMOS,
      // messages.openCreditMemos());

    } else if (selectedValue.equalsIgnoreCase(messages.customerRefunds(Global.get().Customer()))) {
      transactiontypebyStatusMap.put(
          TransactionHistory.REFUNDS_BY_CREDITCARD, messages.refundsByCreditCard());
      transactiontypebyStatusMap.put(TransactionHistory.REFUNDS_BYCASH, messages.refundsByCash());
      transactiontypebyStatusMap.put(
          TransactionHistory.REFUNDS_BYCHEQUE, messages.refundsByCheck());

      transactiontypebyStatusMap.put(
          TransactionHistory.ALL_CUSTOMER_REFUNDS, messages.allCustomerRefunds());
      if (Accounter.hasPermission(Features.DRAFTS)) {
        transactiontypebyStatusMap.put(
            TransactionHistory.DRAFT_CUSTOMER_REFUNDS,
            messages.draftTransaction(messages.customerRefunds(Global.get().Customer())));
      }
    } else if (trasactionViewSelect.getSelectedValue().equalsIgnoreCase(messages.cheques())) {
      transactiontypebyStatusMap.put(TransactionHistory.ALL_CHEQUES, messages.allcheques());
      if (Accounter.hasPermission(Features.DRAFTS)) {
        transactiontypebyStatusMap.put(
            TransactionHistory.DRAFT_CHEQUES, messages.draftTransaction(messages.cheques()));
      }
    } else if (trasactionViewSelect.getSelectedValue().equalsIgnoreCase(messages.salesOrders())) {
      transactiontypebyStatusMap.put(TransactionHistory.ALL_SALES_ORDERS, messages.all());
      transactiontypebyStatusMap.put(
          TransactionHistory.COMPLETED_SALES_ORDERS, messages.completed());
      transactiontypebyStatusMap.put(TransactionHistory.OPEN_SALES_ORDERS, messages.open());
    }
    List<String> typeList = new ArrayList<String>(transactiontypebyStatusMap.values());
    Collections.sort(
        typeList,
        new Comparator<String>() {

          @Override
          public int compare(String entry1, String entry2) {
            return entry1.compareTo(entry2);
          }
        });
    trasactionViewTypeSelect.initCombo(typeList);
    trasactionViewTypeSelect.setComboItem(typeList.get(0));
  }
Exemplo n.º 16
0
/** @author Gajendra Choudhary */
public abstract class Portlet extends WorkbenchPanel {
  protected static AccounterMessages messages = Global.get().messages();

  public static final int TYPE_I_OWE = 1;
  public static final int TYPE_OWE_TO_ME = 2;

  public static final String ACCOUNT_TYPE = "ACCOUNT_TYPE";
  public static final String DATE_RANGE = "DATE_RANGE";
  public static final String LIMIT = "LIMIT";
  public static final String ACCOUNT_ID = "ACCOUNT_ID";

  private ClientCompanyPreferences preferences = Global.get().preferences();
  private HTML title = new HTML();
  private String name;
  protected Label all;
  private StyledPanel vPanel;
  private int previousIndex;
  public HTML refresh;
  private int row;
  private int column;
  public StyledPanel body;
  private ClientPortletConfiguration configuration;
  private PortletPage portletPage;

  protected boolean isInitializing;

  public Portlet(ClientPortletConfiguration configuration, String title, String gotoString) {
    this(title, gotoString);
    setName(title);
    this.setConfiguration(configuration);
  }

  public Portlet(
      ClientPortletConfiguration configuration,
      String title,
      String gotoString,
      String titleWidth) {
    this(title, gotoString, titleWidth);
    setName(title);
    this.setConfiguration(configuration);
  }

  public Portlet(String title, String gotoString, String titleWidth) {
    super(title, gotoString, titleWidth);
    createControls();
  }

  private void createControls() {
    vPanel = new StyledPanel("vPanel");
    body = new StyledPanel("body");
    body.setStyleName("portlet-body");
    addStyleName("portlet");
    vPanel.add(body);
    super.add(vPanel);
  }

  public Portlet(String title, String gotoString) {
    super(title, gotoString);
    createControls();
  }

  public ClientCompany getCompany() {
    return Accounter.getCompany();
  }

  public void setTitle(String title) {
    super.setTitle(title);
    this.title.setHTML(title);
    this.title.setStyleName("portletLabel");
  }

  public void setName(String name) {
    this.name = name;
  }

  public String getName() {
    return name;
  }

  // @Override
  // public void add(Widget w) {
  // this.vPanel.add(w);
  // }

  public void fitToSize(int width, int height) {
    width = Math.max(width, 300);
    height = Math.max(height, 100);
    // this.setWidth(width + "px");
    // this.setHeight(height + "px");
    // setGridWidth(width - 10, height - 40);
  }

  public void createBody() {}

  @Override
  public void titleClicked() {
    super.titleClicked();
    goToClicked();
  }

  public void goToClicked() {}

  public void refreshWidget() {
    isInitializing = true;
  }

  protected void completeInitialization() {
    isInitializing = false;
  }

  public void refreshClicked() {}

  public void helpClicked() {}

  public int getRow() {
    return row;
  }

  public void setRow(int row) {
    this.row = row;
  }

  public int getColumn() {
    return column;
  }

  public void setColumn(int column) {
    this.column = column;
  }

  public void setPreviousIndex(int widgetIndex) {
    this.previousIndex = widgetIndex;
  }

  public int getPreviousIndex() {
    return this.previousIndex;
  }

  public ClientCompanyPreferences getPreferences() {
    return preferences;
  }

  public String getDecimalCharacter() {
    return getPreferences().getDecimalCharacter();
  }

  public String amountAsString(Double amount) {
    return DataUtils.getAmountAsStrings(amount);
  }

  public String getPrimaryCurrencySymbol() {
    return getPreferences().getPrimaryCurrency().getSymbol();
  }

  public ClientPortletConfiguration getConfiguration() {
    return configuration;
  }

  @Override
  protected boolean canClose() {
    return true;
  }

  @Override
  protected boolean canConfigure() {
    return false;
  }

  @Override
  protected void onClose() {
    this.removeFromParent();
    portletPage.config.getPortletConfigurations().remove(getConfiguration());
    portletPage.haveToRefresh = false;
    portletPage.updatePortletPage();
  }

  @Override
  protected void onConfigure() {}

  public PortletPage getPortletPage() {
    return portletPage;
  }

  public void setPortletPage(PortletPage portletPage) {
    this.portletPage = portletPage;
  }

  public boolean isInitializing() {
    return isInitializing;
  }

  @Override
  public void setHeight(String height) {
    // super.setHeight(height);
    // vPanel.setHeight(height);
  }

  public void setConfiguration(ClientPortletConfiguration configuration) {
    this.configuration = configuration;
  }

  public void updateConfiguration() {
    if (portletPage.config.getId() == 0 || configuration.getId() == 0) {
      portletPage.updateConfiguration();
      portletPage.updatePortletPage();
    } else {
      Accounter.createHomeService()
          .savePortletConfiguration(
              configuration,
              new AsyncCallback<Boolean>() {

                @Override
                public void onSuccess(Boolean arg0) {}

                @Override
                public void onFailure(Throwable arg0) {
                  System.err.println(arg0.toString());
                }
              });
    }
  }
}
 @Override
 public String getTitle() {
   return messages.salesByCustomerDetail(Global.get().Customer());
 }
  @Override
  protected void addRequirements(List<Requirement> list) {
    list.add(
        new VendorRequirement(
            VENDOR,
            getMessages().pleaseEnterName(Global.get().Vendor()),
            getMessages().payeeName(Global.get().Vendor()),
            false,
            true,
            new ChangeListner<Vendor>() {

              @Override
              public void onSelection(Vendor value) {
                try {
                  double mostRecentTransactionCurrencyFactor =
                      CommandUtils.getMostRecentTransactionCurrencyFactor(
                          getCompanyId(),
                          value.getCurrency().getID(),
                          new ClientFinanceDate().getDate());
                  CreateCreditCardChargeCommand.this
                      .get(CURRENCY_FACTOR)
                      .setValue(mostRecentTransactionCurrencyFactor);
                } catch (AccounterException e) {
                  e.printStackTrace();
                }
              }
            }) {

          @Override
          protected String getSetMessage() {
            return getMessages().hasSelected(Global.get().Vendor());
          }

          @Override
          protected List<Vendor> getLists(Context context) {
            return getVendors();
          }

          @Override
          protected boolean filter(Vendor e, String name) {
            return e.getName().startsWith(name);
          }
        });

    list.add(
        new CurrencyFactorRequirement(
            CURRENCY_FACTOR,
            getMessages().pleaseEnter(getMessages().currencyFactor()),
            getMessages().currencyFactor()) {
          @Override
          protected Currency getCurrency() {
            Vendor vendor = (Vendor) CreateCreditCardChargeCommand.this.get(VENDOR).getValue();
            return vendor.getCurrency();
          }
        });

    list.add(
        new AmountRequirement(
            DISCOUNT,
            getMessages().pleaseEnter(getMessages().discount()),
            getMessages().discount(),
            true,
            true) {
          @Override
          public Result run(
              Context context, Result makeResult, ResultList list, ResultList actions) {
            if (getPreferences().isTrackDiscounts()
                && !getPreferences().isDiscountPerDetailLine()) {
              return super.run(context, makeResult, list, actions);
            } else {
              return null;
            }
          }
        });

    list.add(
        new TransactionItemTableRequirement(
            ITEMS,
            getMessages().pleaseEnter(getMessages().itemName()),
            getMessages().items(),
            true,
            true) {

          @Override
          public List<Item> getItems(Context context) {
            Set<Item> items2 = context.getCompany().getItems();
            List<Item> items = new ArrayList<Item>();
            for (Item item : items2) {
              if (item.isISellThisItem()) {
                if (item.isActive()) items.add(item);
              }
            }
            return items;
          }

          @Override
          public boolean isSales() {
            return true;
          }

          @Override
          protected Currency getCurrency() {
            return ((Vendor) CreateCreditCardChargeCommand.this.get(VENDOR).getValue())
                .getCurrency();
          }

          @Override
          protected double getCurrencyFactor() {
            return CreateCreditCardChargeCommand.this.getCurrencyFactor();
          }

          @Override
          protected double getDiscount() {
            Double value2 = CreateCreditCardChargeCommand.this.get(DISCOUNT).getValue();
            return value2;
          }
        });

    list.add(
        new TransactionAccountTableRequirement(
            ACCOUNTS,
            getMessages().pleaseEnterNameOrNumber(getMessages().Account()),
            getMessages().Account(),
            true,
            true) {

          @Override
          protected List<Account> getAccounts(Context context) {
            List<Account> filteredList = new ArrayList<Account>();
            for (Account obj : context.getCompany().getAccounts()) {
              if (new ListFilter<Account>() {

                @Override
                public boolean filter(Account account) {
                  if (account.getType() != Account.TYPE_CASH
                      && account.getType() != Account.TYPE_BANK
                      && account.getType() != Account.TYPE_INVENTORY_ASSET
                      && account.getType() != Account.TYPE_ACCOUNT_RECEIVABLE
                      && account.getType() != Account.TYPE_ACCOUNT_PAYABLE
                      && account.getType() != Account.TYPE_INCOME
                      && account.getType() != Account.TYPE_OTHER_INCOME
                      && account.getType() != Account.TYPE_OTHER_CURRENT_ASSET
                      && account.getType() != Account.TYPE_OTHER_CURRENT_LIABILITY
                      && account.getType() != Account.TYPE_OTHER_ASSET
                      && account.getType() != Account.TYPE_EQUITY
                      && account.getType() != Account.TYPE_LONG_TERM_LIABILITY) {
                    return true;
                  } else {
                    return false;
                  }
                }
              }.filter(obj)) {
                filteredList.add(obj);
              }
            }
            return filteredList;
          }

          @Override
          public boolean isSales() {
            return true;
          }

          @Override
          protected Currency getCurrency() {
            return ((Vendor) CreateCreditCardChargeCommand.this.get(VENDOR).getValue())
                .getCurrency();
          }

          @Override
          protected boolean isTrackTaxPaidAccount() {
            return false;
          }

          @Override
          protected double getDiscount() {
            Double value2 = CreateCreditCardChargeCommand.this.get(DISCOUNT).getValue();
            return value2;
          }
        });

    list.add(
        new DateRequirement(
            DATE,
            getMessages().pleaseEnter(getMessages().date()),
            getMessages().date(),
            true,
            true));

    list.add(
        new NumberRequirement(
            NUMBER,
            getMessages().pleaseEnter(getMessages().number()),
            getMessages().number(),
            true,
            false));

    list.add(
        new ContactRequirement(
            CONTACT,
            getMessages().pleaseEnter(getMessages().contactName()),
            getMessages().contacts(),
            true,
            true,
            null) {

          @Override
          protected Payee getPayee() {
            return get(CUSTOMER).getValue();
          }
        });
    list.add(
        new NumberRequirement(
            PHONE,
            getMessages().pleaseEnter(getMessages().phoneNumber()),
            getMessages().phone(),
            true,
            true));

    list.add(
        new NameRequirement(
            MEMO,
            getMessages().pleaseEnter(getMessages().memo()),
            getMessages().memo(),
            true,
            true));

    list.add(
        new StringListRequirement(
            PAYMENT_METHOD,
            getMessages().pleaseEnterName(getMessages().paymentMethod()),
            getMessages().paymentMethod(),
            true,
            true,
            null) {

          @Override
          protected String getSetMessage() {
            return getMessages().hasSelected(getMessages().paymentMethod());
          }

          @Override
          protected String getSelectString() {
            return getMessages().pleaseSelect(getMessages().paymentMethod());
          }

          @Override
          protected List<String> getLists(Context context) {
            return getPaymentMethods();
          }

          @Override
          protected String getEmptyString() {
            return getMessages().youDontHaveAny(getMessages().paymentMethod());
          }
        });

    list.add(
        new AccountRequirement(
            PAY_FROM,
            getMessages().pleaseSelect(getMessages().bankAccount()),
            getMessages().bankAccount(),
            false,
            false,
            null) {

          @Override
          protected String getSetMessage() {
            return getMessages().hasSelected(getMessages().payFrom());
          }

          @Override
          protected void setCreateCommand(CommandList list) {
            list.add(new UserCommand("newBankAccount", getMessages().bank()));
            list.add(
                new UserCommand(
                    "newBankAccount",
                    "Create Other CurrentAsset Account",
                    getMessages().otherCurrentAsset()));
            list.add(
                new UserCommand("newBankAccount", "Create Cash Account", getMessages().cash()));
            list.add(
                new UserCommand(
                    "newBankAccount", "Create Inventory Account", getMessages().inventoryAsset()));
            list.add(
                new UserCommand("newBankAccount", "Create Paypal Account", getMessages().paypal()));
            list.add(
                new UserCommand(
                    "newBankAccount", "Create Creditcard Account", getMessages().creditCard()));
          }

          @Override
          protected List<Account> getLists(Context context) {
            List<Account> filteredList = new ArrayList<Account>();
            for (Account obj : context.getCompany().getAccounts()) {
              if (new ListFilter<Account>() {

                @Override
                public boolean filter(Account e) {
                  if (e.getIsActive()
                      && (e.getSubBaseType() == ClientAccount.SUBBASETYPE_CURRENT_ASSET
                          || e.getType() == ClientAccount.TYPE_CREDIT_CARD)) {
                    return true;
                  }
                  return false;
                }
              }.filter(obj)) {
                filteredList.add(obj);
              }
            }
            return filteredList;
          }

          @Override
          protected String getEmptyString() {
            return getMessages().youDontHaveAny(getMessages().Accounts());
          }

          @Override
          protected boolean filter(Account e, String name) {
            return false;
          }
        });

    list.add(
        new DateRequirement(
            DELIVERY_DATE,
            getMessages().pleaseEnter(getMessages().deliveryDate()),
            getMessages().deliveryDate(),
            true,
            true));

    list.add(
        new TaxCodeRequirement(
            TAXCODE,
            getMessages().pleaseEnterName(getMessages().taxCode()),
            getMessages().taxCode(),
            false,
            true,
            new ChangeListner<TAXCode>() {

              @Override
              public void onSelection(TAXCode value) {
                setTaxCodeToItems(value);
              }
            }) {

          @Override
          protected List<TAXCode> getLists(Context context) {
            return new ArrayList<TAXCode>(context.getCompany().getTaxCodes());
          }

          @Override
          protected boolean filter(TAXCode e, String name) {
            return e.getName().toLowerCase().startsWith(name);
          }
        });

    list.add(
        new BooleanRequirement(IS_VAT_INCLUSIVE, true) {
          @Override
          public Result run(
              Context context, Result makeResult, ResultList list, ResultList actions) {
            ClientCompanyPreferences preferences = context.getPreferences();
            if (preferences.isTrackTax()) {
              return super.run(context, makeResult, list, actions);
            }
            return null;
          }

          @Override
          protected String getTrueString() {
            return "Include VAT with Amount enabled";
          }

          @Override
          protected String getFalseString() {
            return "Include VAT with Amount disabled";
          }
        });
  }
  @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();
  }
Exemplo n.º 20
0
  private void creatControls() {

    StyledPanel mainPanel = new StyledPanel("customerCenter");

    StyledPanel leftVpPanel = new StyledPanel("leftPanel");

    viewTypeCombo();
    DynamicForm viewform = new DynamicForm("viewform");
    viewform.setStyleName("filterPanel");
    viewform.add(activeInActiveSelect);
    leftVpPanel.add(viewform);
    custGrid = new CustomersListGrid();
    custGrid.init();
    initCustomersListGrid();
    leftVpPanel.add(custGrid);

    custGrid.setStyleName("cusotmerCentrGrid");

    rightVpPanel = new StyledPanel("rightPanel");
    dummyPanel = new StyledPanel("dummyPanel");

    detailsPanel = new CustomerDetailsPanel(selectedCustomer);
    rightVpPanel.add(detailsPanel);
    custGrid.setCustomerSelectionListener(
        new CustomerSelectionListener() {
          @Override
          public void cusotmerSelected() {
            OncusotmerSelected();
          }
        });
    transactionViewSelectCombo();
    transactionViewTypeSelectCombo();
    transactionDateRangeSelector();
    DynamicForm transactionViewform = new DynamicForm("transactionViewform");

    transactionViewform.add(trasactionViewSelect, trasactionViewTypeSelect, dateRangeSelector);

    transactionGridpanel = new StyledPanel("transactionGridpanel");
    transactionGridpanel.add(transactionViewform);
    custHistoryGrid =
        new CustomerTransactionsHistoryGrid() {
          @Override
          public void initListData() {
            OncusotmerSelected();
          }
        };
    custHistoryGrid.init();
    custHistoryGrid.addEmptyMessage(messages.pleaseSelectAnyPayee(Global.get().Customer()));
    int pageSize = getPageSize();
    custHistoryGrid.addRangeChangeHandler2(
        new Handler() {

          @Override
          public void onRangeChange(RangeChangeEvent event) {
            onPageChange(event.getNewRange().getStart(), event.getNewRange().getLength());
          }
        });
    SimplePager pager =
        new SimplePager(
            TextLocation.CENTER,
            (Resources) GWT.create(Resources.class),
            false,
            pageSize * 2,
            true);
    pager.setDisplay(custHistoryGrid);
    updateRecordsCount(0, 0, 0);

    if (Accounter.isIpadApp()) {

      transactionButton = new Button(messages.transaction());
      transactionButton.addClickHandler(
          new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
              ActionFactory.getCustomerTransactionListHistory(selectedCustomer).run();
            }
          });

    } else {
      dummyPanel.add(transactionGridpanel);
      dummyPanel.add(custHistoryGrid);
      dummyPanel.add(pager);
    }
    rightVpPanel.add(dummyPanel);
    Label labelTitle = new Label(messages.customerCentre(Global.get().Customer()));
    labelTitle.setStyleName("label-title");

    mainPanel.add(leftVpPanel);
    mainPanel.add(rightVpPanel);
    deleteButtonPanel = new StyledPanel("deleteButtonPanel");
    add(labelTitle);
    add(deleteButtonPanel);
    add(mainPanel);
  }
Exemplo n.º 21
0
public class InventoryCentreView<T> extends AbstractBaseView<T>
    implements ISavableView<HashMap<String, Object>>, IEditableView {

  private ClientItem selectedItem;
  private ArrayList<ClientItem> listOfItems;
  protected ArrayList<ClientFinanceDate> startEndDates;
  private ArrayList<TransactionHistory> records;

  private ItemDetailsPanel itemDetailsPanel;
  private InventoryCentreItemsListGrid itemsListGrid;
  private SelectCombo activeInActiveSelect,
      trasactionViewSelect,
      trasactionViewTypeSelect,
      dateRangeSelector;
  private StyledPanel transactionGridpanel;
  private ItemTransactionsHistoryGrid transactionHistoryGrid;
  private HashMap<Integer, String> transactiontypebyStatusMap;
  private boolean isActiveItems = true;
  private ClientFinanceDate startDate, endDate;

  private String[] transactionTypes =
      new String[] {
        messages.quotes(),
        messages.Charges(),
        messages.credits(),
        messages.invoices(),
        messages.cashSales(),
        messages.payeeCreditNotes(Global.get().Customer()),
        messages.cashPurchases(),
        messages.payeeCreditNotes(Global.get().Vendor()),
        messages.bills(),
        messages.expenses(),
        messages.salesOrders(),
        messages.purchaseOrders()
      };
  private Button transactionButton;
  private StyledPanel rightVpPanel, dummyPanel;

  public InventoryCentreView() {
    this.getElement().setId("InventoryCentreView");
  }

  @Override
  public void init() {
    super.init();
    createControls();
  }

  private void createControls() {
    StyledPanel mainPanel = new StyledPanel("mainPanel");
    StyledPanel leftVpPanel = new StyledPanel("leftVpPanel");
    viewTypeCombo();
    DynamicForm viewform = new DynamicForm("viewform");
    viewform.add(activeInActiveSelect);
    leftVpPanel.add(viewform);
    itemsListGrid = new InventoryCentreItemsListGrid();
    itemsListGrid.init();
    initItemsListGrid();
    leftVpPanel.add(itemsListGrid);

    itemsListGrid.setStyleName("cusotmerCentrGrid");

    rightVpPanel = new StyledPanel("rightVpPanel");
    dummyPanel = new StyledPanel("dummyPanel");
    itemDetailsPanel = new ItemDetailsPanel(selectedItem);
    rightVpPanel.add(itemDetailsPanel);
    itemsListGrid.setItemSelectionListener(
        new ItemSelectionListener() {

          @Override
          public void itemSelected(ClientItem selectedItem) {
            InventoryCentreView.this.selectedItem = selectedItem;
            onItemSelected();
          }
        });
    transactionViewSelectCombo();
    transactionViewTypeSelectCombo();
    transactionDateRangeSelector();
    DynamicForm transactionViewform = new DynamicForm("viewform");

    transactionViewform.add(trasactionViewSelect, trasactionViewTypeSelect, dateRangeSelector);

    transactionGridpanel = new StyledPanel("transactionGridpanel");
    transactionGridpanel.add(transactionViewform);
    transactionHistoryGrid =
        new ItemTransactionsHistoryGrid() {
          @Override
          public void initListData() {

            onItemSelected();
          }

          @Override
          protected String[] setHeaderStyle() {
            return new String[] {"date", "type", "no", "memo", "quantity", "amount"};
          }

          @Override
          protected String[] setRowElementsStyle() {
            return new String[] {
              "date-value", "type-value", "no-value", "memo-value", "quantity-value", "amount"
            };
          }
        };
    transactionHistoryGrid.init();
    transactionHistoryGrid.addEmptyMessage(messages.pleaseSelectAnItem());
    int pageSize = getPageSize();
    transactionHistoryGrid.addRangeChangeHandler2(
        new Handler() {

          @Override
          public void onRangeChange(RangeChangeEvent event) {
            onPageChange(event.getNewRange().getStart(), event.getNewRange().getLength());
          }
        });
    SimplePager pager =
        new SimplePager(
            TextLocation.CENTER,
            (Resources) GWT.create(Resources.class),
            false,
            pageSize * 2,
            true);
    pager.setDisplay(transactionHistoryGrid);
    updateRecordsCount(0, 0, 0);

    if (Accounter.isIpadApp()) {

      transactionButton = new Button(messages.transaction());
      transactionButton.addClickHandler(
          new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
              ActionFactory.getInventoryTransactionListHistory(selectedItem).run();
            }
          });

    } else {
      dummyPanel.add(transactionGridpanel);
      dummyPanel.add(transactionHistoryGrid);
      dummyPanel.add(pager);
    }

    rightVpPanel.add(dummyPanel);

    Label labelTitle = new Label(messages.inventoryCentre());
    labelTitle.setStyleName("label-title");
    mainPanel.add(leftVpPanel);
    mainPanel.add(rightVpPanel);
    add(labelTitle);
    add(mainPanel);
  }

  public void updateRecordsCount(int start, int length, int total) {
    transactionHistoryGrid.updateRange(new Range(start, getPageSize()));
    transactionHistoryGrid.setRowCount(total, (start + length) == total);
  }

  private int getPageSize() {
    return 25;
  }

  private void viewTypeCombo() {
    if (activeInActiveSelect == null) {
      activeInActiveSelect = new SelectCombo(messages.show());

      ArrayList<String> activetypeList = new ArrayList<String>();
      activetypeList.add(messages.active());
      activetypeList.add(messages.inActive());
      activeInActiveSelect.initCombo(activetypeList);
      activeInActiveSelect.setComboItem(messages.active());
      activeInActiveSelect.addSelectionChangeHandler(
          new IAccounterComboSelectionChangeHandler<String>() {

            @Override
            public void selectedComboBoxItem(String selectItem) {
              if (activeInActiveSelect.getSelectedValue() != null) {
                if (activeInActiveSelect
                    .getSelectedValue()
                    .toString()
                    .equalsIgnoreCase(messages.active())) {
                  refreshActiveinactiveList(true);

                } else {
                  refreshActiveinactiveList(false);
                }
              }
            }
          });
    }
  }

  private void refreshActiveinactiveList(boolean isActiveList) {
    itemsListGrid.setSelectedItem(null);
    itemDetailsPanel.itemName.setText(messages.noItemSelected());
    this.selectedItem = null;
    onItemSelected();
    isActiveItems = isActiveList;
    initItemsListGrid();
  }

  private void transactionViewTypeSelectCombo() {
    if (trasactionViewTypeSelect == null) {
      trasactionViewTypeSelect = new SelectCombo(messages.type());
      getMessagesList();
      trasactionViewTypeSelect.addSelectionChangeHandler(
          new IAccounterComboSelectionChangeHandler<String>() {

            @Override
            public void selectedComboBoxItem(String selectItem) {
              if (trasactionViewTypeSelect.getSelectedValue() != null) {
                callRPC(0, 25);
              }
            }
          });
    }
  }

  private void transactionViewSelectCombo() {
    if (trasactionViewSelect == null) {
      trasactionViewSelect = new SelectCombo(messages.currentView());

      ArrayList<String> transactionTypeList = new ArrayList<String>();
      transactionTypeList.add(messages.allTransactions());
      for (String type : transactionTypes) {
        if (type.equalsIgnoreCase(messages.Charges())
            || type.equalsIgnoreCase(messages.credits())) {
          if (getPreferences().isDelayedchargesEnabled()) {
            transactionTypeList.add(type);
          } else {
            continue;
          }
        } else if (type.equalsIgnoreCase(messages.salesOrders())) {
          if (getPreferences().isSalesOrderEnabled()) {
            transactionTypeList.add(type);
          } else {
            continue;
          }
        } else if (type.equalsIgnoreCase(messages.purchaseOrders())) {
          if (getPreferences().isPurchaseOrderEnabled()) {
            transactionTypeList.add(type);
          } else {
            continue;
          }
        } else {
          transactionTypeList.add(type);
        }
      }
      trasactionViewSelect.initCombo(transactionTypeList);
      trasactionViewSelect.setComboItem(messages.allTransactions());
      trasactionViewSelect.addSelectionChangeHandler(
          new IAccounterComboSelectionChangeHandler<String>() {

            @Override
            public void selectedComboBoxItem(String selectItem) {
              if (trasactionViewSelect.getSelectedValue() != null) {
                getMessagesList();
                callRPC(0, 25);
              }
            }
          });
    }
  }

  private void getMessagesList() {
    String selectedValue = trasactionViewSelect.getSelectedValue();
    transactiontypebyStatusMap = new HashMap<Integer, String>();
    if (trasactionViewSelect.getSelectedValue().equalsIgnoreCase(messages.allTransactions())) {
      transactiontypebyStatusMap.put(
          TransactionHistory.ALL_TRANSACTIONS, messages.allTransactions());
    } else if (selectedValue.equalsIgnoreCase(messages.quotes())) {

      transactiontypebyStatusMap.put(TransactionHistory.ALL_QUOTES, messages.allQuotes());
      transactiontypebyStatusMap.put(
          TransactionHistory.DRAFT_QUOTES, messages.draftTransaction(messages.quotes()));

    } else if (selectedValue.equalsIgnoreCase(messages.Charges())) {

      transactiontypebyStatusMap.put(TransactionHistory.ALL_CHARGES, messages.allCahrges());
      transactiontypebyStatusMap.put(
          TransactionHistory.DRAFT_CHARGES, messages.draftTransaction(messages.Charges()));

    } else if (selectedValue.equalsIgnoreCase(messages.credits())) {
      transactiontypebyStatusMap.put(TransactionHistory.ALL_CREDITS, messages.allCredits());
      transactiontypebyStatusMap.put(
          TransactionHistory.DRAFT_CREDITS, messages.draftTransaction(messages.credits()));

    } else if (selectedValue.equalsIgnoreCase(messages.invoices())) {
      transactiontypebyStatusMap.put(TransactionHistory.ALL_INVOICES, messages.getallInvoices());
      transactiontypebyStatusMap.put(
          TransactionHistory.OPENED_INVOICES, messages.getOpendInvoices());
      transactiontypebyStatusMap.put(
          TransactionHistory.OVER_DUE_INVOICES, messages.overDueInvoices());
      transactiontypebyStatusMap.put(
          TransactionHistory.DRAFT_INVOICES, messages.draftTransaction(messages.invoices()));
    } else if (selectedValue.equalsIgnoreCase(messages.cashSales())) {
      transactiontypebyStatusMap.put(
          TransactionHistory.ALL_CASHSALES, messages.all() + " " + messages.cashSales());
      transactiontypebyStatusMap.put(
          TransactionHistory.DRAFT_CASHSALES, messages.draftTransaction(messages.cashSales()));

    } else if (selectedValue.equalsIgnoreCase(messages.payeeCreditNotes(Global.get().Customer()))) {
      transactiontypebyStatusMap.put(TransactionHistory.ALL_CREDITMEMOS, messages.allCreditMemos());
      transactiontypebyStatusMap.put(
          TransactionHistory.DRAFT_CREDITMEMOS, messages.draftTransaction(messages.creditNote()));
      // transactiontypebyStatusMap.put(
      // TransactionHistory.OPEND_CREDITMEMOS,
      // messages.openCreditMemos());

    } else if (trasactionViewSelect.getSelectedValue().equalsIgnoreCase(messages.cashPurchases())) {
      transactiontypebyStatusMap.put(
          TransactionHistory.ALL_CASH_PURCHASES, messages.allCashPurchases());
      transactiontypebyStatusMap.put(
          TransactionHistory.DRAFT_CASH_PURCHASES,
          messages.draftTransaction(messages.cashPurchases()));

    } else if (trasactionViewSelect.getSelectedValue().equalsIgnoreCase(messages.bills())) {
      transactiontypebyStatusMap.put(TransactionHistory.ALL_BILLS, messages.allBills());
      transactiontypebyStatusMap.put(
          TransactionHistory.OPEND_BILLS, messages.all() + " " + messages.openedBills());
      transactiontypebyStatusMap.put(
          TransactionHistory.OVERDUE_BILLS, messages.all() + " " + messages.overDueBills());
      transactiontypebyStatusMap.put(
          TransactionHistory.DRAFT_BILLS, messages.draftTransaction(messages.bills()));

    } else if (trasactionViewSelect
        .getSelectedValue()
        .equalsIgnoreCase(messages.payeeCreditNotes(Global.get().Vendor()))) {
      transactiontypebyStatusMap.put(
          TransactionHistory.ALL_VENDOR_CREDITNOTES,
          messages.all() + " " + messages.payeeCreditNotes(Global.get().Vendor()));
      transactiontypebyStatusMap.put(
          TransactionHistory.DRAFT_VENDOR_CREDITNOTES,
          messages.draftTransaction(messages.payeeCreditNotes(Global.get().Vendor())));

    } else if (trasactionViewSelect.getSelectedValue().equalsIgnoreCase(messages.expenses())) {
      transactiontypebyStatusMap.put(TransactionHistory.ALL_EXPENSES, messages.allExpenses());
      transactiontypebyStatusMap.put(
          TransactionHistory.CREDIT_CARD_EXPENSES, messages.creditCardExpenses());
      transactiontypebyStatusMap.put(TransactionHistory.CASH_EXPENSES, messages.cashExpenses());
      transactiontypebyStatusMap.put(
          TransactionHistory.DRAFT_CREDIT_CARD_EXPENSES,
          messages.draftTransaction(messages.creditCardExpenses()));
      transactiontypebyStatusMap.put(
          TransactionHistory.DRAFT_CASH_EXPENSES,
          messages.draftTransaction(messages.cashExpenses()));

    } else if (trasactionViewSelect.getSelectedValue().equalsIgnoreCase(messages.salesOrders())) {

      transactiontypebyStatusMap.put(TransactionHistory.ALL_SALES_ORDERS, messages.all());
      transactiontypebyStatusMap.put(TransactionHistory.DRAFT_SALES_ORDERS, messages.drafts());

    } else if (trasactionViewSelect
        .getSelectedValue()
        .equalsIgnoreCase(messages.purchaseOrders())) {

      transactiontypebyStatusMap.put(TransactionHistory.ALL_PURCHASE_ORDERS, messages.all());
      transactiontypebyStatusMap.put(TransactionHistory.DRAFT_PURCHASE_ORDERS, messages.drafts());
    }
    List<String> typeList = new ArrayList<String>(transactiontypebyStatusMap.values());
    Collections.sort(
        typeList,
        new Comparator<String>() {

          @Override
          public int compare(String entry1, String entry2) {
            return entry1.compareTo(entry2);
          }
        });
    trasactionViewTypeSelect.initCombo(typeList);
    trasactionViewTypeSelect.setComboItem(typeList.get(0));
  }

  protected void transactionDateRangeSelector() {
    dateRangeSelector = new SelectCombo(messages.date());

    ArrayList<String> dateRangeList = new ArrayList<String>();
    String[] dateRangeArray = {
      messages.all(),
      messages.thisWeek(),
      messages.thisMonth(),
      messages.lastWeek(),
      messages.lastMonth(),
      messages.thisFinancialYear(),
      messages.lastFinancialYear(),
      messages.thisFinancialQuarter(),
      messages.lastFinancialQuarter(),
      messages.financialYearToDate()
    };
    for (int i = 0; i < dateRangeArray.length; i++) {
      dateRangeList.add(dateRangeArray[i]);
    }
    dateRangeSelector.initCombo(dateRangeList);

    dateRangeSelector.setComboItem(messages.all());
    dateRangeSelector.addSelectionChangeHandler(
        new IAccounterComboSelectionChangeHandler<String>() {
          @Override
          public void selectedComboBoxItem(String selectItem) {
            dateRangeSelector.setComboItem(selectItem);
            if (dateRangeSelector.getValue() != null) {
              dateRangeChanged(selectItem);
              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();
    }
  }

  private void getCurrentQuarter() {

    ClientFinanceDate date = new ClientFinanceDate();

    int currentQuarter;
    if ((date.getMonth() + 1) % 3 == 0) {
      currentQuarter = (date.getMonth() + 1) / 3;
    } else {
      currentQuarter = ((date.getMonth() + 1) / 3) + 1;
    }
    switch (currentQuarter) {
      case 1:
        startDate = new ClientFinanceDate(date.getYear(), 0, 1);
        endDate = new ClientFinanceDate(date.getYear(), 2, 31);
        break;

      case 2:
        startDate = new ClientFinanceDate(date.getYear(), 3, 1);
        endDate = new ClientFinanceDate(date.getYear(), 5, 30);
        break;

      case 3:
        startDate = new ClientFinanceDate(date.getYear(), 6, 1);
        endDate = new ClientFinanceDate(date.getYear(), 8, 30);
        break;
      default:
        startDate = new ClientFinanceDate(date.getYear(), 9, 1);
        endDate = new ClientFinanceDate(date.getYear(), 11, 31);
        break;
    }
  }

  private int getMonthLastDate(int month, int year) {
    int lastDay;
    switch (month) {
      case 0:
      case 2:
      case 4:
      case 6:
      case 7:
      case 9:
      case 11:
        lastDay = 31;
        break;
      case 1:
        if (year % 4 == 0 && year % 100 == 0) lastDay = 29;
        else lastDay = 28;
        break;

      default:
        lastDay = 30;
        break;
    }
    return lastDay;
  }

  public ClientFinanceDate getWeekStartDate() {
    ClientFinanceDate date = new ClientFinanceDate();
    int day = date.getDay() % 6;
    ClientFinanceDate newDate = new ClientFinanceDate();
    if (day != 1) {
      newDate.setDay(date.getDay() - day);
    } else {
      newDate.setDay(date.getDay());
    }
    return newDate;
  }

  @Override
  public void deleteFailed(AccounterException caught) {
    // TODO Auto-generated method stub

  }

  @Override
  public void deleteSuccess(IAccounterCore result) {
    // TODO Auto-generated method stub

  }

  @Override
  protected String getViewTitle() {
    return null;
  }

  @Override
  public void setFocus() {
    // TODO Auto-generated method stub

  }

  private void initItemsListGrid() {
    filterItems();
    itemsListGrid.removeAllRecords();
    if (listOfItems.isEmpty()) {
      itemsListGrid.addEmptyMessage(messages.youDontHaveAny(messages.inventoryItems()));
    } else {
      itemsListGrid.setRecords(listOfItems);
    }
  }

  private void filterItems() {
    ArrayList<ClientItem> items = getCompany().getItems();
    ArrayList<ClientItem> result = new ArrayList<ClientItem>();
    for (ClientItem item : items) {
      if (item.getType() == ClientItem.TYPE_INVENTORY_PART
          || item.getType() == ClientItem.TYPE_INVENTORY_ASSEMBLY) {
        if (isActiveItems == item.isActive()) {
          result.add(item);
        }
      }
    }
    listOfItems = result;
  }

  void onPageChange(int start, int length) {
    callRPC(start, length);
  }

  private void onItemSelected() {

    itemDetailsPanel.showItemDetails(selectedItem);
    if (Accounter.isIpadApp()) {
      rightVpPanel.add(transactionButton);
      transactionButton.setText(messages2.transactionListFor(selectedItem.getDisplayName()));
    }
    transactionHistoryGrid.setSelectedItem(selectedItem);
    MainFinanceWindow.getViewManager().updateButtons();
    callRPC(0, 25);
  }

  protected void callRPC(int start, int length) {
    transactionHistoryGrid.removeAllRecords();
    records = new ArrayList<TransactionHistory>();
    if (selectedItem != null) {
      Accounter.createHomeService()
          .getItemTransactionsList(
              selectedItem.getID(),
              getTransactionType(),
              getTransactionStatusType(),
              startDate,
              endDate,
              start,
              length,
              new AsyncCallback<PaginationList<TransactionHistory>>() {

                @Override
                public void onFailure(Throwable caught) {
                  Accounter.showError(messages.unableToPerformTryAfterSomeTime());
                }

                @Override
                public void onSuccess(PaginationList<TransactionHistory> result) {
                  records = result;
                  selectedItem = getCompany().getItem(selectedItem.getID());
                  transactionHistoryGrid.setSelectedItem(selectedItem);
                  itemDetailsPanel.showItemDetails(selectedItem);
                  transactionHistoryGrid.removeAllRecords();
                  if (records != null) {
                    transactionHistoryGrid.addRecords(records);
                  }
                  updateRecordsCount(result.getStart(), result.size(), result.getTotalCount());
                  if (records.size() == 0) {
                    transactionHistoryGrid.addEmptyMessage(
                        messages.thereAreNo(messages.transactions()));
                  }
                }
              });

    } else {
      transactionHistoryGrid.removeAllRecords();
      transactionHistoryGrid.addEmptyMessage(messages.thereAreNo(messages.transactions()));
    }
  }

  private int getTransactionType() {
    String selectedValue = trasactionViewSelect.getSelectedValue();
    if (selectedValue.equalsIgnoreCase(messages.invoices())) {
      return ClientTransaction.TYPE_INVOICE;
    } else if (selectedValue.equalsIgnoreCase(messages.cashSales())) {
      return ClientTransaction.TYPE_CASH_SALES;
    } else if (selectedValue.equalsIgnoreCase(messages.payeeCreditNotes(Global.get().Customer()))) {
      return ClientTransaction.TYPE_CUSTOMER_CREDIT_MEMO;
    } else if (selectedValue.equalsIgnoreCase(messages.quotes())
        || selectedValue.equalsIgnoreCase(messages.credits())
        || selectedValue.equalsIgnoreCase(messages.Charges())) {
      return ClientTransaction.TYPE_ESTIMATE;
    } else if (trasactionViewSelect.getSelectedValue().equalsIgnoreCase(messages.cashPurchases())) {
      return ClientTransaction.TYPE_CASH_PURCHASE;
    } else if (trasactionViewSelect.getSelectedValue().equalsIgnoreCase(messages.bills())) {
      return ClientTransaction.TYPE_ENTER_BILL;
    } else if (trasactionViewSelect
        .getSelectedValue()
        .equalsIgnoreCase(messages.payeeCreditNotes(Global.get().Vendor()))) {
      return ClientTransaction.TYPE_VENDOR_CREDIT_MEMO;
    } else if (trasactionViewSelect.getSelectedValue().equalsIgnoreCase(messages.expenses())) {
      return ClientTransaction.TYPE_EXPENSE;
    } else if (trasactionViewSelect.getSelectedValue().equalsIgnoreCase(messages.salesOrders())) {
      return TransactionHistory.TYPE_SALES_ORDER;
    } else if (trasactionViewSelect
        .getSelectedValue()
        .equalsIgnoreCase(messages.purchaseOrders())) {
      return TransactionHistory.TYPE_PURCHASE_ORDER;
    }
    return 0;
  }

  private int getTransactionStatusType() {
    if (trasactionViewTypeSelect.getSelectedValue() != null) {
      Set<Integer> keySet = transactiontypebyStatusMap.keySet();
      for (Integer integerKey : keySet) {
        String entrystring = transactiontypebyStatusMap.get(integerKey);
        if (trasactionViewTypeSelect.getSelectedValue().equals(entrystring)) {
          return integerKey;
        }
      }
    }
    return TransactionHistory.ALL_INVOICES;
  }

  public String getAddNewLabelString() {
    return messages.addaNew(messages.inventoryItem());
  }

  public NewItemAction getAddNewAction() {
    if (!Accounter.getUser().canDoInvoiceTransactions()) return null;
    else {
      NewItemAction action = new NewItemAction(true);
      action.setType(ClientItem.TYPE_INVENTORY_PART);
      return action;
    }
  }

  @Override
  public HashMap<String, Object> saveView() {
    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put("activeInActive", activeInActiveSelect.getSelectedValue());
    map.put("currentView", trasactionViewSelect.getSelectedValue());
    map.put("transactionType", trasactionViewTypeSelect.getSelectedValue());
    map.put("dateRange", dateRangeSelector.getSelectedValue());
    map.put("selectedItem", selectedItem == null ? "" : selectedItem.getName());
    map.put("itemSelection", itemsListGrid.getSelection());
    return map;
  }

  @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());
    }
  }

  @Override
  public boolean canEdit() {
    return selectedItem == null
        ? false
        : Utility.isUserHavePermissions(selectedItem.getObjectType());
  }

  @Override
  public void onEdit() {
    if (selectedItem.getType() == ClientItem.TYPE_INVENTORY_ASSEMBLY) {
      InventoryActions inventoryAssemblyAction = InventoryActions.newAssembly();
      inventoryAssemblyAction.setisItemEditable(true);
      inventoryAssemblyAction.run((ClientInventoryAssembly) selectedItem, false);

    } else {
      NewItemAction itemAction = new NewItemAction(true);
      itemAction.setType(selectedItem.getType());
      itemAction.setisItemEditable(true);
      itemAction.run(selectedItem, false);
    }
  }

  @Override
  public boolean isDirty() {
    return false;
  }
}