modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/filterexpression/SalesInvoiceAddPaymentDisplayLogics.java
author David Baz Fayos <david.baz@openbravo.com>
Wed, 23 Sep 2015 19:54:52 +0200
changeset 27628 87fcaa257950
parent 27080 9d85d9a430b2
child 35352 4590a05d86f8
permissions -rw-r--r--
Related to issue 29414: Updated browser supported/recommended list for PR15Q4

* Chrome. Supported 44, Recommended 45 or higher.
* Firefox. Supported 38, Recommended 38 or higher.
* Internet Explorer. Supported 9, Recommended 11 or higher.
* Safari. Supported 7, Recommended 8 or higher.
/*
 *************************************************************************
 * The contents of this file are subject to the Openbravo  Public  License
 * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
 * Version 1.1  with a permitted attribution clause; you may not  use this
 * file except in compliance with the License. You  may  obtain  a copy of
 * the License at http://www.openbravo.com/legal/license.html
 * Software distributed under the License  is  distributed  on  an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific  language  governing  rights  and  limitations
 * under the License.
 * The Original Code is Openbravo ERP.
 * The Initial Developer of the Original Code is Openbravo SLU
 * All portions are Copyright (C) 2014-2015 Openbravo SLU
 * All Rights Reserved.
 * Contributor(s):  ______________________________________.
 ************************************************************************
 */
package org.openbravo.advpaymentmngt.filterexpression;

import java.math.BigDecimal;
import java.util.Map;

import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.openbravo.advpaymentmngt.dao.AdvPaymentMngtDao;
import org.openbravo.advpaymentmngt.utility.APRMConstants;
import org.openbravo.client.kernel.ComponentProvider;
import org.openbravo.dal.service.OBDal;
import org.openbravo.model.common.businesspartner.BusinessPartner;
import org.openbravo.model.common.currency.Currency;
import org.openbravo.model.common.enterprise.Organization;
import org.openbravo.model.common.invoice.Invoice;

@ComponentProvider.Qualifier(APRMConstants.SALES_INVOICE_WINDOW_ID)
public class SalesInvoiceAddPaymentDisplayLogics extends AddPaymentDisplayLogicsHandler {

  private static final long SEQUENCE = 100l;

  protected long getSeq() {
    return SEQUENCE;
  }

  @Override
  public boolean getDocumentDisplayLogic(Map<String, String> requestMap) throws JSONException {
    // Document Type
    return false;
  }

  @Override
  public boolean getOrganizationDisplayLogic(Map<String, String> requestMap) throws JSONException {
    // Organization
    return false;
  }

  @Override
  public boolean getCreditToUseDisplayLogic(Map<String, String> requestMap) throws JSONException {
    JSONObject context = new JSONObject(requestMap.get("context"));
    Invoice invoice = getInvoice(context);
    BusinessPartner bpartner = invoice.getBusinessPartner();
    if (bpartner != null) {
      Organization org = invoice.getOrganization();
      Currency currency = invoice.getCurrency();
      BigDecimal customerCredit = new AdvPaymentMngtDao().getCustomerCredit(bpartner, true, org,
          currency);
      return customerCredit.signum() > 0;
    } else {
      return false;
    }
  }

  Invoice getInvoice(JSONObject context) throws JSONException {
    return OBDal.getInstance().get(Invoice.class, context.getString("inpcInvoiceId"));
  }

  @Override
  public boolean getBankStatementLineDisplayLogic(Map<String, String> requestMap)
      throws JSONException {
    // BankStatementLineDisplayLogic
    return false;
  }
}