/** * Create Facts (the accounting logic) for PJI * * <pre> * Issue * ProjectWIP DR * Inventory CR * </pre> * * Project Account is either Asset or WIP depending on Project Type * * @param as accounting schema * @return Fact */ public ArrayList<Fact> createFacts(MAcctSchema as) { // create Fact Header Fact fact = new Fact(this, as, Fact.POST_Actual); setC_Currency_ID(as.getC_Currency_ID()); MProject project = new MProject(getCtx(), m_issue.getC_Project_ID(), getTrxName()); String ProjectCategory = project.getProjectCategory(); MProduct product = MProduct.get(getCtx(), m_issue.getM_Product_ID()); // Line pointers FactLine dr = null; FactLine cr = null; // Issue Cost BigDecimal costs = null; BigDecimal total = Env.ZERO; if (m_issue.getM_InOutLine_ID() != 0) costs = getPOCost(as); else if (m_issue.getS_TimeExpenseLine_ID() != 0) costs = getLaborCost(as); if (costs == null) // standard Product Costs { for (MCostDetail cost : m_line.getCostDetail(as)) { if (!MCostDetail.existsCost(cost)) continue; costs = MCostDetail.getTotalCost(cost, as); total = total.add(costs); } } if (total == null || total.signum() == 0) { p_Error = "Resubmit - No Costs for " + product.getName(); log.log(Level.WARNING, p_Error); return null; } // Project DR int acctType = ACCTTYPE_ProjectWIP; if (MProject.PROJECTCATEGORY_AssetProject.equals(ProjectCategory)) acctType = ACCTTYPE_ProjectAsset; dr = fact.createLine(m_line, getAccount(acctType, as), as.getC_Currency_ID(), costs, null); dr.setQty(m_line.getQty().negate()); // Inventory CR acctType = ProductCost.ACCTTYPE_P_Asset; if (product.isService()) acctType = ProductCost.ACCTTYPE_P_Expense; cr = fact.createLine( m_line, m_line.getAccount(acctType, as), as.getC_Currency_ID(), null, costs); cr.setM_Locator_ID(m_line.getM_Locator_ID()); cr.setLocationFromLocator(m_line.getM_Locator_ID(), true); // from Loc // ArrayList<Fact> facts = new ArrayList<Fact>(); facts.add(fact); return facts; } // createFact