src/org/openbravo/erpCommon/ad_callouts/SL_MachineCost.java
author Mark Molina <mark.molina@doceleguas.com>
Thu, 14 Mar 2019 12:23:44 -0300
changeset 35548 30c40214364b
parent 35352 4590a05d86f8
permissions -rw-r--r--
Fixes issue 40190: Not possible to set Attributes opening BackOffice from POS

Was not possible to set Attributes opening a BackOffice session from POS because
an incorrect selection of the opener.

Now to select the opener is asked if it has the closeSearch function registered
and also it is included the getFrame('LayoutMDI').parent object for cases where
is coming from POS
carlos@0
     1
/*
carlos@0
     2
 *************************************************************************
carlos@0
     3
 * The contents of this file are subject to the Openbravo  Public  License
priya@9072
     4
 * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
carlos@0
     5
 * Version 1.1  with a permitted attribution clause; you may not  use this
carlos@0
     6
 * file except in compliance with the License. You  may  obtain  a copy of
carlos@0
     7
 * the License at http://www.openbravo.com/legal/license.html 
carlos@0
     8
 * Software distributed under the License  is  distributed  on  an "AS IS"
carlos@0
     9
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
carlos@0
    10
 * License for the specific  language  governing  rights  and  limitations
carlos@0
    11
 * under the License. 
carlos@0
    12
 * The Original Code is Openbravo ERP. 
ggi@6701
    13
 * The Initial Developer of the Original Code is Openbravo SLU 
markmm82@32538
    14
 * All portions are Copyright (C) 2001-2017 Openbravo SLU 
carlos@0
    15
 * All Rights Reserved. 
carlos@0
    16
 * Contributor(s):  ______________________________________.
carlos@0
    17
 ************************************************************************
martin@2462
    18
 */
carlos@0
    19
carlos@0
    20
package org.openbravo.erpCommon.ad_callouts;
carlos@0
    21
martin@2598
    22
import java.math.BigDecimal;
stefan@33602
    23
import java.math.RoundingMode;
martin@2598
    24
martin@2598
    25
import javax.servlet.ServletException;
martin@2598
    26
markmm82@32538
    27
import org.apache.commons.lang.StringUtils;
carlos@0
    28
markmm82@32538
    29
public class SL_MachineCost extends SimpleCallout {
markmm82@32538
    30
  @Override
markmm82@32538
    31
  protected void execute(CalloutInfo info) throws ServletException {
carlos@0
    32
markmm82@32538
    33
    String strChanged = info.getLastFieldChanged();
markmm82@32538
    34
    if (log4j.isDebugEnabled()) {
markmm82@32538
    35
      log4j.debug("CHANGED: " + strChanged);
carlos@0
    36
    }
carlos@0
    37
markmm82@32538
    38
    // Parameters
markmm82@32538
    39
    BigDecimal fPurchaseAmt = info.getBigDecimalParameter("inppurchaseamt");
markmm82@32538
    40
    BigDecimal fToolsetAmt = info.getBigDecimalParameter("inptoolsetamt");
markmm82@32538
    41
    BigDecimal fYearValue = info.getBigDecimalParameter("inpyearvalue");
markmm82@32538
    42
    BigDecimal fAmortization = info.getBigDecimalParameter("inpamortization");
markmm82@32538
    43
    BigDecimal fDaysYear = info.getBigDecimalParameter("inpdaysyear");
markmm82@32538
    44
    BigDecimal fDayHours = info.getBigDecimalParameter("inpdayhours");
markmm82@32538
    45
    BigDecimal fImproductiveHoursYear = info.getBigDecimalParameter("inpimproductivehoursyear");
markmm82@32538
    46
    BigDecimal fCostUomYear = info.getBigDecimalParameter("inpcostuomyear");
markmm82@32538
    47
    BigDecimal fCost = info.getBigDecimalParameter("inpcost");
markmm82@32538
    48
    String strCostUom = info.getStringParameter("inpcostuom");
markmm82@32538
    49
markmm82@32538
    50
    if (StringUtils.equals(strChanged, "inppurchaseamt")
markmm82@32538
    51
        || StringUtils.equals(strChanged, "inptoolsetamt")
markmm82@32538
    52
        || StringUtils.equals(strChanged, "inpyearvalue")) {
markmm82@32538
    53
      // Calculate Amortization, Cost
asier@35352
    54
      fAmortization = fYearValue.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO
asier@35352
    55
          : (fPurchaseAmt.add(fToolsetAmt)).divide(fYearValue, 12, RoundingMode.HALF_EVEN);
asier@35352
    56
      fCost = fCostUomYear.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO
asier@35352
    57
          : fYearValue.divide(fCostUomYear, 12, RoundingMode.HALF_EVEN);
markmm82@32538
    58
markmm82@32538
    59
    } else if (StringUtils.equals(strChanged, "inpamortization")) {
markmm82@32538
    60
      // Calculate Value per Year, Cost
asier@35352
    61
      fYearValue = fAmortization.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO
asier@35352
    62
          : (fPurchaseAmt.add(fToolsetAmt)).divide(fAmortization, 12, RoundingMode.HALF_EVEN);
asier@35352
    63
      fCost = fCostUomYear.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO
asier@35352
    64
          : fYearValue.divide(fCostUomYear, 12, RoundingMode.HALF_EVEN);
markmm82@32538
    65
markmm82@32538
    66
    } else if (StringUtils.equals(strChanged, "inpdaysyear")
markmm82@32538
    67
        || StringUtils.equals(strChanged, "inpdayhours")
markmm82@32538
    68
        || strChanged.equals("inpimproductivehoursyear")) {
markmm82@32538
    69
      // Calculate UOM Annual Cost, Cost
markmm82@32538
    70
      fCostUomYear = (fDaysYear.multiply(fDayHours)).subtract(fImproductiveHoursYear);
asier@35352
    71
      fCost = fCostUomYear.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO
asier@35352
    72
          : fYearValue.divide(fCostUomYear, 12, RoundingMode.HALF_EVEN);
markmm82@32538
    73
markmm82@32538
    74
    } else if (StringUtils.equals(strChanged, "inpcostuomyear")) {
markmm82@32538
    75
      // Calculate Productive Hours per Year, Cost
markmm82@32538
    76
      if (strCostUom.equals("H")) {
markmm82@32538
    77
        fImproductiveHoursYear = (fDaysYear.multiply(fDayHours)).subtract(fCostUomYear);
markmm82@32538
    78
      }
asier@35352
    79
      fCost = fCostUomYear.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO
asier@35352
    80
          : fYearValue.divide(fCostUomYear, 12, RoundingMode.HALF_EVEN);
markmm82@32538
    81
markmm82@32538
    82
    } else if (StringUtils.equals(strChanged, "inpcost")) {
markmm82@32538
    83
      // Calculate Value per Year, Amortization
markmm82@32538
    84
      fYearValue = fCost.multiply(fCostUomYear);
asier@35352
    85
      fAmortization = fYearValue.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO
asier@35352
    86
          : (fPurchaseAmt.add(fToolsetAmt)).divide(fYearValue, 12, RoundingMode.HALF_EVEN);
javier@15543
    87
    }
markmm82@32538
    88
markmm82@32538
    89
    // Set Purchase Amount, ToolSetAmount, Value per Year, Amortization, Hours per Day,
markmm82@32538
    90
    // ProductiveHours per Year, UOM Annual Cost, Cost
markmm82@32538
    91
    info.addResult("inppurchaseamt", fPurchaseAmt);
markmm82@32538
    92
    info.addResult("inptoolsetamt", fToolsetAmt);
markmm82@32538
    93
    info.addResult("inpyearvalue", fYearValue);
markmm82@32538
    94
    info.addResult("inpamortization", fAmortization);
markmm82@32538
    95
    info.addResult("inpdaysyear", fDaysYear);
markmm82@32538
    96
    info.addResult("inpdayhours", fDayHours);
markmm82@32538
    97
    info.addResult("inpimproductivehoursyear", fImproductiveHoursYear);
markmm82@32538
    98
    info.addResult("inpcostuomyear", fCostUomYear);
markmm82@32538
    99
    info.addResult("inpcost", fCost);
martin@2868
   100
  }
carlos@0
   101
}