Package org.openbravo.costing
Class CostingUtils
- java.lang.Object
-
- org.openbravo.costing.CostingUtils
-
public class CostingUtils extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static String
MovementTypeRefID
static String
propADListPriority
static String
propADListReference
static String
propADListValue
-
Constructor Summary
Constructors Constructor Description CostingUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
checkValidOrganization(String processId, Organization scheduledOrg)
Throws an OBException when the processId is the CostingBackground and it is being executed by an organization which has a legal entity as an ancestor.static boolean
existsProcessedTransactions(Product product, HashMap<CostingAlgorithm.CostDimension,BaseOBObject> _costDimensions, Organization costorg, MaterialTransaction trx, boolean isManufacturingProduct)
Check if exists processed transactions for this productstatic CostingRule
getCostDimensionRule(Organization org, Date date)
static Date
getCostingRuleFixBackdatedFrom(CostingRule rule)
Returns the Fix Backdated From of a Costing Rule, if is null returns 01/01/1900static Date
getCostingRuleStartingDate(CostingRule rule)
Returns the Starting Date of a Costing Rule, if is null returns 01/01/1900static BigDecimal
getCurrentStock(Product product, Organization costorg, Date dateTo, HashMap<CostingAlgorithm.CostDimension,BaseOBObject> costDimensions, Currency currency, Costing costing)
Calculates the stock of the product on the given date and for the given cost dimensions.static BigDecimal
getCurrentStock(MaterialTransaction trx, Organization org, HashMap<CostingAlgorithm.CostDimension,BaseOBObject> costDimensions, boolean areBackdatedTrxFixed, Currency currency)
Calculates the stock of the product on the given date and for the given cost dimensions.static BigDecimal
getCurrentValuedStock(Product product, Organization costorg, Date dateTo, HashMap<CostingAlgorithm.CostDimension,BaseOBObject> costDimensions, Currency currency, Costing costing)
Calculates the value of the stock of the product on the given date, for the given cost dimensions and for the given currency.static BigDecimal
getCurrentValuedStock(MaterialTransaction trx, Organization org, HashMap<CostingAlgorithm.CostDimension,BaseOBObject> costDimensions, boolean areBackdatedTrxFixed, Currency currency)
Calculates the value of the stock of the product on the given date, for the given cost dimensions and for the given currency.static BigDecimal
getDefaultCost(Product product, BigDecimal qty, Organization org, Date costDate, Date movementDate, BusinessPartner bp, Currency currency, HashMap<CostingAlgorithm.CostDimension,BaseOBObject> costDimensions)
static HashMap<CostingAlgorithm.CostDimension,BaseOBObject>
getEmptyDimensions()
static Date
getLastDate()
static Date
getMaxTransactionDate(Organization org)
Returns the max transaction date with cost calculatedstatic OrderLine
getOrderLine(Product product, BusinessPartner bp, Organization org)
Returns the newer order line for the given product, business partner and organization.static Organization
getOrganizationForCloseAndOpenInventories(String OrgId, Warehouse warehouse)
For the givenWarehouse
parameter, this method returns anOrganization
that allows to create Transactions.static BigDecimal
getStandardCost(Product product, Organization org, Date date, HashMap<CostingAlgorithm.CostDimension,BaseOBObject> costDimensions, boolean recheckWithoutDimensions, Currency convCurrency)
Calculates the standard cost of a product on the given date and cost dimensions.static BigDecimal
getStandardCost(Product product, Organization org, Date date, HashMap<CostingAlgorithm.CostDimension,BaseOBObject> costDimensions, Currency convCurrency)
CallsgetStandardCost(Product, Organization, Date, HashMap, boolean, Currency)
setting the recheckWithoutDimensions flag to true.static Costing
getStandardCostDefinition(Product product, Organization org, Date date, HashMap<CostingAlgorithm.CostDimension,BaseOBObject> costDimensions)
CallsgetStandardCostDefinition(Product, Organization, Date, HashMap, boolean)
setting the recheckWithoutDimensions flag to true.static Costing
getStandardCostDefinition(Product product, Organization org, Date date, HashMap<CostingAlgorithm.CostDimension,BaseOBObject> costDimensions, boolean recheckWithoutDimensions)
Calculates the standard cost definition of a product on the given date and cost dimensions.static Costing
getStandardCostDefinition(Product product, Organization org, Date date, HashMap<CostingAlgorithm.CostDimension,BaseOBObject> costDimensions, boolean recheckWithoutDimensions, String costtype)
Calculates the standard cost definition of a product on the given date and cost dimensions.static BigDecimal
getTransactionCost(MaterialTransaction transaction, Date date, boolean calculateTrx, Currency currency)
Calculates the total cost amount of a transaction including the cost adjustments done until the given date.static BigDecimal
getTransactionCost(MaterialTransaction transaction, Date date, Currency currency)
CallsgetTransactionCost(MaterialTransaction, Date, boolean, Currency)
setting the calculateTrx flag to false.static BusinessPartner
getTrxBusinessPartner(MaterialTransaction transaction, CostingServer.TrxType trxType)
static boolean
hasStandardCostDefinition(Product product, Organization org, Date date, HashMap<CostingAlgorithm.CostDimension,BaseOBObject> costDimensions)
CallshasStandardCostDefinition(Product, Organization, Date, HashMap, boolean)
setting the recheckWithoutDimensions flag to true.static boolean
hasStandardCostDefinition(Product product, Organization org, Date date, HashMap<CostingAlgorithm.CostDimension,BaseOBObject> costDimensions, boolean recheckWithoutDimensions)
Check the existence of a standard cost definition of a product on the given date and cost dimensions.static boolean
isAllowNegativeStock(Client client)
Deprecated.static boolean
isLastOpeningTransaction(MaterialTransaction trx, boolean includeWarehouseDimension)
Check if trx is the last opening one of an Inventory Amount Updatestatic boolean
isNegativeStockAllowedForShipmentInout(String shipmentInOutId)
static boolean
isNegativeStockEnabledForAnyStorageBin(Client client)
static Period
periodClosed(Organization org, Date dateFrom, Date dateTo, String docType)
Search period control closed between dateFrom and dateTo
-
-
-
Field Detail
-
propADListPriority
public static final String propADListPriority
- See Also:
- Constant Field Values
-
propADListValue
public static final String propADListValue
- See Also:
- Constant Field Values
-
propADListReference
public static final String propADListReference
- See Also:
- Constant Field Values
-
MovementTypeRefID
public static final String MovementTypeRefID
- See Also:
- Constant Field Values
-
-
Method Detail
-
getTransactionCost
public static BigDecimal getTransactionCost(MaterialTransaction transaction, Date date, Currency currency)
CallsgetTransactionCost(MaterialTransaction, Date, boolean, Currency)
setting the calculateTrx flag to false.
-
getTransactionCost
public static BigDecimal getTransactionCost(MaterialTransaction transaction, Date date, boolean calculateTrx, Currency currency)
Calculates the total cost amount of a transaction including the cost adjustments done until the given date.- Parameters:
transaction
- MaterialTransaction to get its cost.date
- The Date it is desired to know the cost.calculateTrx
- boolean flag to force the calculation of the transaction cost if it is not calculated.currency
- The Currency to calculate the amount.- Returns:
- The total cost amount.
-
getDefaultCost
public static BigDecimal getDefaultCost(Product product, BigDecimal qty, Organization org, Date costDate, Date movementDate, BusinessPartner bp, Currency currency, HashMap<CostingAlgorithm.CostDimension,BaseOBObject> costDimensions)
-
getStandardCost
public static BigDecimal getStandardCost(Product product, Organization org, Date date, HashMap<CostingAlgorithm.CostDimension,BaseOBObject> costDimensions, Currency convCurrency) throws OBException
CallsgetStandardCost(Product, Organization, Date, HashMap, boolean, Currency)
setting the recheckWithoutDimensions flag to true.- Throws:
OBException
-
getStandardCost
public static BigDecimal getStandardCost(Product product, Organization org, Date date, HashMap<CostingAlgorithm.CostDimension,BaseOBObject> costDimensions, boolean recheckWithoutDimensions, Currency convCurrency) throws OBException
Calculates the standard cost of a product on the given date and cost dimensions.- Parameters:
product
- The Product to get its Standard Costdate
- The Date to get the Standard CostcostDimensions
- The cost dimensions to get the Standard Cost if it is defined by some of them.recheckWithoutDimensions
- boolean flag to force a recall the method to get the Standard Cost at client level if no cost is found in the given cost dimensions.convCurrency
- The Currency to calculate the amount.- Returns:
- the Standard Cost.
- Throws:
OBException
- when no standard cost is found.
-
hasStandardCostDefinition
public static boolean hasStandardCostDefinition(Product product, Organization org, Date date, HashMap<CostingAlgorithm.CostDimension,BaseOBObject> costDimensions)
CallshasStandardCostDefinition(Product, Organization, Date, HashMap, boolean)
setting the recheckWithoutDimensions flag to true.
-
hasStandardCostDefinition
public static boolean hasStandardCostDefinition(Product product, Organization org, Date date, HashMap<CostingAlgorithm.CostDimension,BaseOBObject> costDimensions, boolean recheckWithoutDimensions)
Check the existence of a standard cost definition of a product on the given date and cost dimensions.- Parameters:
product
- The Product to get its Standard Costdate
- The Date to get the Standard CostcostDimensions
- The cost dimensions to get the Standard Cost if it is defined by some of them.recheckWithoutDimensions
- boolean flag to force a recall the method to get the Standard Cost at client level if no cost is found in the given cost dimensions.- Returns:
- the Standard Cost. Null when no definition is found.
-
getStandardCostDefinition
public static Costing getStandardCostDefinition(Product product, Organization org, Date date, HashMap<CostingAlgorithm.CostDimension,BaseOBObject> costDimensions)
CallsgetStandardCostDefinition(Product, Organization, Date, HashMap, boolean)
setting the recheckWithoutDimensions flag to true.
-
getStandardCostDefinition
public static Costing getStandardCostDefinition(Product product, Organization org, Date date, HashMap<CostingAlgorithm.CostDimension,BaseOBObject> costDimensions, boolean recheckWithoutDimensions)
Calculates the standard cost definition of a product on the given date and cost dimensions.- Parameters:
product
- The Product to get its Standard Costdate
- The Date to get the Standard CostcostDimensions
- The cost dimensions to get the Standard Cost if it is defined by some of them.recheckWithoutDimensions
- boolean flag to force a recall the method to get the Standard Cost at client level if no cost is found in the given cost dimensions.- Returns:
- the Standard Cost. Null when no definition is found.
-
getStandardCostDefinition
public static Costing getStandardCostDefinition(Product product, Organization org, Date date, HashMap<CostingAlgorithm.CostDimension,BaseOBObject> costDimensions, boolean recheckWithoutDimensions, String costtype)
Calculates the standard cost definition of a product on the given date and cost dimensions.- Parameters:
product
- The Product to get its Standard Costdate
- The Date to get the Standard CostcostDimensions
- The cost dimensions to get the Standard Cost if it is defined by some of them.recheckWithoutDimensions
- boolean flag to force a recall the method to get the Standard Cost at client level if no cost is found in the given cost dimensions.- Returns:
- the Standard Cost. Null when no definition is found.
-
getEmptyDimensions
public static HashMap<CostingAlgorithm.CostDimension,BaseOBObject> getEmptyDimensions()
- Returns:
- The costDimensions HashMap with null values for the dimensions.
-
getCurrentStock
public static BigDecimal getCurrentStock(MaterialTransaction trx, Organization org, HashMap<CostingAlgorithm.CostDimension,BaseOBObject> costDimensions, boolean areBackdatedTrxFixed, Currency currency)
Calculates the stock of the product on the given date and for the given cost dimensions. It only takes transactions that have its cost calculated.
-
getCurrentStock
public static BigDecimal getCurrentStock(Product product, Organization costorg, Date dateTo, HashMap<CostingAlgorithm.CostDimension,BaseOBObject> costDimensions, Currency currency, Costing costing)
Calculates the stock of the product on the given date and for the given cost dimensions. It only takes transactions that have its cost calculated.
-
getCurrentValuedStock
public static BigDecimal getCurrentValuedStock(MaterialTransaction trx, Organization org, HashMap<CostingAlgorithm.CostDimension,BaseOBObject> costDimensions, boolean areBackdatedTrxFixed, Currency currency)
Calculates the value of the stock of the product on the given date, for the given cost dimensions and for the given currency. It only takes transactions that have its cost calculated.
-
getCurrentValuedStock
public static BigDecimal getCurrentValuedStock(Product product, Organization costorg, Date dateTo, HashMap<CostingAlgorithm.CostDimension,BaseOBObject> costDimensions, Currency currency, Costing costing)
Calculates the value of the stock of the product on the given date, for the given cost dimensions and for the given currency. It only takes transactions that have its cost calculated.
-
getTrxBusinessPartner
public static BusinessPartner getTrxBusinessPartner(MaterialTransaction transaction, CostingServer.TrxType trxType)
-
getOrderLine
public static OrderLine getOrderLine(Product product, BusinessPartner bp, Organization org)
Returns the newer order line for the given product, business partner and organization.
-
getCostDimensionRule
public static CostingRule getCostDimensionRule(Organization org, Date date)
-
getMaxTransactionDate
public static Date getMaxTransactionDate(Organization org)
Returns the max transaction date with cost calculated
-
periodClosed
public static Period periodClosed(Organization org, Date dateFrom, Date dateTo, String docType) throws javax.servlet.ServletException
Search period control closed between dateFrom and dateTo- Throws:
javax.servlet.ServletException
-
getCostingRuleStartingDate
public static Date getCostingRuleStartingDate(CostingRule rule)
Returns the Starting Date of a Costing Rule, if is null returns 01/01/1900
-
getCostingRuleFixBackdatedFrom
public static Date getCostingRuleFixBackdatedFrom(CostingRule rule)
Returns the Fix Backdated From of a Costing Rule, if is null returns 01/01/1900
-
checkValidOrganization
public static void checkValidOrganization(String processId, Organization scheduledOrg)
Throws an OBException when the processId is the CostingBackground and it is being executed by an organization which has a legal entity as an ancestor.- Parameters:
processId
- This is the process Id being executed. The method only runs the validation when the process ID is equal to CostingBackground.AD_PROCESS_IDscheduledOrg
- the organization that runs the process
-
existsProcessedTransactions
public static boolean existsProcessedTransactions(Product product, HashMap<CostingAlgorithm.CostDimension,BaseOBObject> _costDimensions, Organization costorg, MaterialTransaction trx, boolean isManufacturingProduct)
Check if exists processed transactions for this product
-
isLastOpeningTransaction
public static boolean isLastOpeningTransaction(MaterialTransaction trx, boolean includeWarehouseDimension)
Check if trx is the last opening one of an Inventory Amount Update
-
isAllowNegativeStock
@Deprecated public static boolean isAllowNegativeStock(Client client)
Deprecated.
-
isNegativeStockEnabledForAnyStorageBin
public static boolean isNegativeStockEnabledForAnyStorageBin(Client client)
-
isNegativeStockAllowedForShipmentInout
public static boolean isNegativeStockAllowedForShipmentInout(String shipmentInOutId)
-
getOrganizationForCloseAndOpenInventories
public static Organization getOrganizationForCloseAndOpenInventories(String OrgId, Warehouse warehouse)
For the givenWarehouse
parameter, this method returns anOrganization
that allows to create Transactions. If the Organization of the Warehouse is valid, it returns this Organization, if not, it looks for a valid one in the parent Organizations of the Warehouse Organization. If no valid Organization is found, the Organization of the id given as a parameter is returned.- Parameters:
OrgId
- The identifier of anOrganization
objectwarehouse
- TheWarehouse
for which the Opening and Close Inventories are going to be created- Returns:
- An
Organization
that allows to create transactions that is the Organization or one of the parent Organizations of the givenWarehouse
. If no one is found, it returns the Organization of the given id as a parameter
-
getLastDate
public static Date getLastDate()
-
-