use of org.compiere.model.MAcctSchema in project adempiere by adempiere.
the class GenerateCostDetail method generateCostDetail.
public void generateCostDetail() {
//Generate Costdetail
KeyNamePair[] transactions = getTransactionIdsByDateAcct();
// System.out.println("Transaction to process : " + transactions.length);
Integer process = 0;
Integer productId = 0;
boolean processNewProduct = true;
Trx dbTransaction = null;
try {
//Process transaction
for (KeyNamePair keyNamePair : transactions) {
int transactionId = keyNamePair.getKey();
int transactionProductId = new Integer(keyNamePair.getName());
//Detected a new product
if (productId != transactionProductId) {
//commit last transaction by product
if (dbTransaction != null) {
dbTransaction.commit(true);
dbTransaction.close();
}
productId = transactionProductId;
processNewProduct = true;
//Create new transaction for this product
dbTransaction = Trx.get(productId.toString(), true);
}
MTransaction transaction = new MTransaction(getCtx(), transactionId, dbTransaction.getTrxName());
// for each Account Schema
for (MAcctSchema accountSchema : acctSchemas) {
// for each Cost Type
for (MCostType costType : costTypes) {
// for each Cost Element
for (MCostElement costElement : costElements) {
if (processNewProduct) {
applyCriteria(accountSchema.getC_AcctSchema_ID(), costType.getM_CostType_ID(), costElement.getM_CostElement_ID(), productId, getAccountDate(), getAccountDateTo());
deleteCostDetail(dbTransaction.getTrxName());
resetCostDimension(costType.getCostingMethod(), dbTransaction.getTrxName());
generateCostCollectorNotTransaction(accountSchema, costType, productId, dbTransaction.getTrxName());
processNewProduct = false;
}
generateCostDetail(accountSchema, costType, costElement, transaction);
}
}
}
process++;
//System.out.println("Transaction : " + transactionId + " Transaction Type :"+ transaction.getMovementType() + " record ..." + process);
}
if (dbTransaction != null) {
dbTransaction.commit(true);
dbTransaction.close();
dbTransaction = null;
}
} catch (Exception e) {
if (dbTransaction != null) {
dbTransaction.rollback();
dbTransaction.close();
dbTransaction = null;
e.printStackTrace();
addLog(e.getMessage());
}
} finally {
if (dbTransaction != null) {
dbTransaction.commit();
dbTransaction.close();
dbTransaction = null;
}
}
}
use of org.compiere.model.MAcctSchema in project adempiere by adempiere.
the class WAccountDialog method initAccount.
// jbInit
/**
* Dyanmic Init.
* When a row is selected, the editor values are set
* (editors do not change grid)
* @return true if initialized
*/
private boolean initAccount() {
m_AD_Client_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "AD_Client_ID");
// Get AcctSchema Info
if (s_AcctSchema == null || s_AcctSchema.getC_AcctSchema_ID() != m_C_AcctSchema_ID)
s_AcctSchema = new MAcctSchema(Env.getCtx(), m_C_AcctSchema_ID, null);
log.config(s_AcctSchema.toString() + ", #" + s_AcctSchema.getAcctSchemaElements().length);
Env.setContext(Env.getCtx(), m_WindowNo, "C_AcctSchema_ID", m_C_AcctSchema_ID);
// Model
// Maintain Account Combinations
int AD_Window_ID = 153;
GridWindowVO wVO = AEnv.getMWindowVO(m_WindowNo, AD_Window_ID, 0);
if (wVO == null)
return false;
m_mWindow = new GridWindow(wVO);
m_mTab = m_mWindow.getTab(0);
// Make sure is the tab is loaded - teo_sarca [ 1659124 ]
if (!m_mTab.isLoadComplete())
m_mWindow.initTab(0);
// ParameterPanel restrictions
m_mTab.getField("Alias").setDisplayLength(15);
m_mTab.getField("Combination").setDisplayLength(15);
// Grid restrictions
m_mTab.getField("AD_Client_ID").setDisplayed(false);
m_mTab.getField("C_AcctSchema_ID").setDisplayed(false);
m_mTab.getField("IsActive").setDisplayed(false);
m_mTab.getField("IsFullyQualified").setDisplayed(false);
// don't show fields not being displayed in this environment
for (int i = 0; i < m_mTab.getFieldCount(); i++) {
GridField field = m_mTab.getField(i);
if (// check context
!field.isDisplayed(true))
field.setDisplayed(false);
}
// GridController
m_adTabPanel.init(null, m_WindowNo, m_mTab, null);
// Prepare Parameter
parameterLayout.makeNoStrip();
parameterLayout.setOddRowSclass("even");
parameterLayout.setParent(parameterPanel);
parameterLayout.setStyle("background-color: transparent;");
m_rows = new Rows();
m_rows.setParent(parameterLayout);
int TabNo = 0;
// Alias
if (s_AcctSchema.isHasAlias()) {
GridField alias = m_mTab.getField("Alias");
f_Alias = WebEditorFactory.getEditor(alias, false);
addLine(alias, f_Alias, false);
}
// Alias
// Combination
GridField combination = m_mTab.getField("Combination");
f_Combination = WebEditorFactory.getEditor(combination, false);
addLine(combination, f_Combination, false);
m_newRow = true;
/**
* Create Fields in Element Order
*/
MAcctSchemaElement[] elements = s_AcctSchema.getAcctSchemaElements();
for (int i = 0; i < elements.length; i++) {
MAcctSchemaElement ase = elements[i];
String type = ase.getElementType();
boolean isMandatory = ase.isMandatory();
//
if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Organization)) {
GridField field = m_mTab.getField("AD_Org_ID");
f_AD_Org_ID = WebEditorFactory.getEditor(field, false);
addLine(field, f_AD_Org_ID, isMandatory);
} else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Account)) {
GridField field = m_mTab.getField("Account_ID");
f_Account_ID = WebEditorFactory.getEditor(field, false);
// ((VLookup)f_Account_ID).setWidth(400);
addLine(field, f_Account_ID, isMandatory);
f_Account_ID.addValueChangeListener(this);
} else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_SubAccount)) {
GridField field = m_mTab.getField("C_SubAcct_ID");
f_SubAcct_ID = WebEditorFactory.getEditor(field, false);
// ((VLookup)f_SubAcct_ID).setWidth(400);
addLine(field, f_SubAcct_ID, isMandatory);
} else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Product)) {
GridField field = m_mTab.getField("M_Product_ID");
f_M_Product_ID = WebEditorFactory.getEditor(field, false);
addLine(field, f_M_Product_ID, isMandatory);
} else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_BPartner)) {
GridField field = m_mTab.getField("C_BPartner_ID");
f_C_BPartner_ID = WebEditorFactory.getEditor(field, false);
addLine(field, f_C_BPartner_ID, isMandatory);
} else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Campaign)) {
GridField field = m_mTab.getField("C_Campaign_ID");
f_C_Campaign_ID = WebEditorFactory.getEditor(field, false);
addLine(field, f_C_Campaign_ID, isMandatory);
} else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_LocationFrom)) {
GridField field = m_mTab.getField("C_LocFrom_ID");
f_C_LocFrom_ID = WebEditorFactory.getEditor(field, false);
addLine(field, f_C_LocFrom_ID, isMandatory);
} else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_LocationTo)) {
GridField field = m_mTab.getField("C_LocTo_ID");
f_C_LocTo_ID = WebEditorFactory.getEditor(field, false);
addLine(field, f_C_LocTo_ID, isMandatory);
} else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Project)) {
GridField field = m_mTab.getField("C_Project_ID");
f_C_Project_ID = WebEditorFactory.getEditor(field, false);
addLine(field, f_C_Project_ID, isMandatory);
} else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_SalesRegion)) {
GridField field = m_mTab.getField("C_SalesRegion_ID");
f_C_SalesRegion_ID = WebEditorFactory.getEditor(field, false);
addLine(field, f_C_SalesRegion_ID, isMandatory);
} else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_OrgTrx)) {
GridField field = m_mTab.getField("AD_OrgTrx_ID");
f_AD_OrgTrx_ID = WebEditorFactory.getEditor(field, false);
addLine(field, f_AD_OrgTrx_ID, isMandatory);
} else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Activity)) {
GridField field = m_mTab.getField("C_Activity_ID");
f_C_Activity_ID = WebEditorFactory.getEditor(field, false);
addLine(field, f_C_Activity_ID, isMandatory);
} else // User1
if (type.equals(MAcctSchemaElement.ELEMENTTYPE_UserList1)) {
GridField field = m_mTab.getField("User1_ID");
f_User1_ID = WebEditorFactory.getEditor(field, false);
// Change the label from the default to the user defined name
//f_User1_ID.setLabel(ase.getName());
addLine(field, f_User1_ID, isMandatory);
} else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_UserList2)) {
GridField field = m_mTab.getField("User2_ID");
f_User2_ID = WebEditorFactory.getEditor(field, false);
// Change the label from the default to the user defined name
//f_User2_ID.setLabel(ase.getName());
addLine(field, f_User2_ID, isMandatory);
} else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_UserList3)) {
GridField field = m_mTab.getField("User3_ID");
f_User3_ID = WebEditorFactory.getEditor(field, false);
// Change the label from the default to the user defined name
//f_User3_ID.setLabel(ase.getName());
addLine(field, f_User3_ID, isMandatory);
} else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_UserList4)) {
GridField field = m_mTab.getField("User4_ID");
f_User4_ID = WebEditorFactory.getEditor(field, false);
// Change the label from the default to the user defined name
//f_User4_ID.setLabel(ase.getName());
addLine(field, f_User4_ID, isMandatory);
}
}
// Create Fields in Element Order
// Add description
m_newRow = true;
Row row = new Row();
f_Description.setStyle("font-decoration: italic;");
row.appendChild(f_Description);
row.setSpans("4");
row.setStyle("background-color: transparent;");
m_rows.appendChild(row);
// Finish
m_query = new MQuery();
m_query.addRestriction("C_AcctSchema_ID", MQuery.EQUAL, m_C_AcctSchema_ID);
m_query.addRestriction("IsFullyQualified", MQuery.EQUAL, "Y");
if (m_mAccount.C_ValidCombination_ID == 0)
m_mTab.setQuery(MQuery.getEqualQuery("1", "2"));
else {
MQuery query = new MQuery();
query.addRestriction("C_AcctSchema_ID", MQuery.EQUAL, m_C_AcctSchema_ID);
query.addRestriction("C_ValidCombination_ID", MQuery.EQUAL, m_mAccount.C_ValidCombination_ID);
m_mTab.setQuery(query);
}
m_mTab.query(false);
m_adTabPanel.getGridTab().addDataStatusListener(this);
m_adTabPanel.activate(true);
if (!m_adTabPanel.isGridView())
m_adTabPanel.switchRowPresentation();
statusBar.setStatusLine(s_AcctSchema.toString());
statusBar.setStatusDB("?");
// Initial value
if (m_mAccount.C_ValidCombination_ID != 0)
m_mTab.navigate(0);
log.config("fini");
return true;
}
use of org.compiere.model.MAcctSchema in project adempiere by adempiere.
the class RollupBillOfMaterial method getFutureCostPriceLowLevel.
/**
* Get the sum Current Cost Price Level Low for this Cost Element
* @param acctSchema
* @param bom MPPProductBOM
* @param costElement MCostElement
* @param trxName
* @return Cost Price Lower Level
*/
private BigDecimal getFutureCostPriceLowLevel(MAcctSchema acctSchema, MPPProductBOM bom, MCostElement costElement, String trxName) {
log.info("Element: " + costElement);
AtomicReference<BigDecimal> costPriceLowLevel = new AtomicReference<>(Env.ZERO);
if (bom == null)
return costPriceLowLevel.get();
//Iterate bom lines
Arrays.stream(bom.getLines()).filter(bomLine -> bomLine != null && !bomLine.isCoProduct()).forEach(bomLine -> {
MProduct component = MProduct.get(getCtx(), bomLine.getM_Product_ID());
MCost cost = MCost.getOrCreate(component, 0, acctSchema, getOrganizationId(), getWarehouseId(), getCostTypeId(), costElement.getM_CostElement_ID());
Boolean includingScrapQty = true;
BigDecimal qty = bomLine.getQty(includingScrapQty);
if (bomLine.isByProduct())
cost.setFutureCostPriceLL(Env.ZERO);
BigDecimal costPrice = cost.getFutureCostPrice().add(cost.getFutureCostPriceLL());
if (costPrice.equals(BigDecimal.ZERO))
costPrice = cost.getCurrentCostPrice().add(cost.getCurrentCostPriceLL());
if (bomLine.getM_Product().getC_UOM_ID() != bomLine.getC_UOM_ID()) {
BigDecimal rate = MUOMConversion.getProductRateFrom(getCtx(), component.getM_Product_ID(), bomLine.getC_UOM_ID());
if (rate == null)
costPrice = costPrice.multiply(BigDecimal.ONE);
else
costPrice = costPrice.multiply(rate);
}
if (bomLine.isPacking()) {
int workflowId = 0;
MProduct product = MProduct.get(getCtx(), bom.getM_Product_ID());
MPPProductPlanning productPlanning = null;
if (workflowId <= 0)
workflowId = MWorkflow.getWorkflowSearchKey(product);
if (workflowId <= 0) {
productPlanning = MPPProductPlanning.find(getCtx(), getOrganizationId(), getWarehouseId(), getResourcePlantId(), product.get_ID(), get_TrxName());
if (productPlanning != null)
workflowId = productPlanning.getAD_Workflow_ID();
else
createNotice(product, "@NotFound@ @PP_Product_Planning_ID@");
}
if (workflowId <= 0)
createNotice(product, "@NotFound@ @AD_Workflow_ID@");
BigDecimal qtyBatchSize = DB.getSQLValueBD(trxName, "SELECT QtyBatchSize FROM AD_Workflow WHERE AD_Workflow_ID=?", workflowId);
if (qtyBatchSize != null && qtyBatchSize.signum() != 0)
qty = qty.divide(qtyBatchSize, acctSchema.getCostingPrecision(), BigDecimal.ROUND_HALF_UP);
}
BigDecimal componentCost = costPrice.multiply(qty);
costPriceLowLevel.updateAndGet(costAmt -> costAmt.add(componentCost));
log.info("CostElement: " + costElement.getName() + ", Component: " + component.getValue() + ", CostPrice: " + costPrice + ", Qty: " + qty + ", Cost: " + componentCost + " => Total Cost Element: " + costPriceLowLevel.get());
});
// BOM line
return costPriceLowLevel.get();
}
use of org.compiere.model.MAcctSchema in project adempiere by adempiere.
the class Doc_AllocationTax method createCashBasedAcct.
/**
* Create Cash Based Acct
* @param as accounting schema
* @param fact fact
* @param invoice invoice
* @param allocationSource allocation amount (incl discount, writeoff)
* @return Accounted Amt
*/
private BigDecimal createCashBasedAcct(MAcctSchema as, Fact fact, MInvoice invoice, BigDecimal allocationSource) {
BigDecimal allocationAccounted = Env.ZERO;
// Multiplier
double percent = invoice.getGrandTotal().doubleValue() / allocationSource.doubleValue();
if (percent > 0.99 && percent < 1.01)
percent = 1.0;
log.config("Multiplier=" + percent + " - GrandTotal=" + invoice.getGrandTotal() + " - Allocation Source=" + allocationSource);
// Get Invoice Postings
Doc_Invoice docInvoice = (Doc_Invoice) Doc.get(new MAcctSchema[] { as }, MInvoice.Table_ID, invoice.getC_Invoice_ID(), getTrxName());
docInvoice.loadDocumentDetails();
allocationAccounted = docInvoice.createFactCash(as, fact, new BigDecimal(percent));
log.config("Allocation Accounted=" + allocationAccounted);
// Cash Based Commitment Release
if (as.isCreatePOCommitment() && !invoice.isSOTrx()) {
MInvoiceLine[] lines = invoice.getLines();
for (int i = 0; i < lines.length; i++) {
Fact factC = Doc_Order.getCommitmentRelease(as, this, lines[i].getQtyInvoiced(), lines[i].getC_InvoiceLine_ID(), new BigDecimal(percent));
if (factC == null)
return null;
m_facts.add(factC);
}
}
return allocationAccounted;
}
use of org.compiere.model.MAcctSchema in project adempiere by adempiere.
the class AverageInvoiceCostingMethod method adjustCostDetail.
/**
* Recalculate Cost Detail
* @param cost
*/
public void adjustCostDetail(MCostDetail cost) {
Properties ctx = cost.getCtx();
String trxName = cost.get_TrxName();
int transactionId = cost.getM_Transaction_ID();
int clientId = cost.getAD_Client_ID();
MTransaction transaction = new MTransaction(ctx, transactionId, trxName);
MCostType costType = (MCostType) cost.getM_CostType();
MCostElement costElement = (MCostElement) cost.getM_CostElement();
MAcctSchema accountSchema = (MAcctSchema) cost.getC_AcctSchema();
CostEngineFactory.getCostEngine(accountSchema.getAD_Client_ID()).clearAccounting(accountSchema, transaction);
if (MTransaction.MOVEMENTTYPE_VendorReceipts.equals(transaction.getMovementType())) {
MInOutLine line = (MInOutLine) transaction.getDocumentLine();
if (MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
if (cost.getM_InOutLine_ID() > 0 && cost.getQty().signum() != 0) {
CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, line, true);
} else if (cost.getM_InOutLine_ID() > 0 && cost.getQty().signum() != 0 && cost.getC_OrderLine_ID() > 0) {
List<MMatchPO> orderMatches = MMatchPO.getInOutLine(line);
for (MMatchPO match : orderMatches) {
if (match.getM_InOutLine_ID() == line.getM_InOutLine_ID() && match.getM_Product_ID() == transaction.getM_Product_ID()) {
CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, match, true);
}
}
} else if (cost.getM_InOutLine_ID() > 0 && cost.getQty().signum() == 0 && cost.getC_InvoiceLine_ID() > 0 && cost.getC_LandedCostAllocation_ID() == 0) {
List<MMatchInv> invoiceMatches = MMatchInv.getInOutLine(line);
for (MMatchInv match : invoiceMatches) {
if (match.getM_Product_ID() == transaction.getM_Product_ID()) {
CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, match, true);
}
}
}
}
// only own allocation
if (cost.getC_LandedCostAllocation_ID() != 0) {
MLandedCostAllocation allocation = (MLandedCostAllocation) cost.getC_LandedCostAllocation();
{
CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, allocation, true);
}
}
} else
CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, transaction.getDocumentLine(), true);
}
Aggregations