use of org.compiere.model.MProject in project adempiere by adempiere.
the class Doc_ProjectIssue method createFacts.
// getBalance
/**
* 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 (// standard Product Costs
costs == null) {
for (MCostDetail cost : m_line.getCostDetail(as, false)) {
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());
// from Loc
cr.setLocationFromLocator(m_line.getM_Locator_ID(), true);
//
ArrayList<Fact> facts = new ArrayList<Fact>();
facts.add(fact);
return facts;
}
use of org.compiere.model.MProject in project adempiere by adempiere.
the class ExpenseSOrder method processLine.
// doIt
/**
* Process Expense Line
* @param te header
* @param tel line
* @param bp bp
*/
private void processLine(MTimeExpense te, MTimeExpenseLine tel, MBPartner bp) {
if (m_order == null) {
log.info("New Order for " + bp + ", Project=" + tel.getC_Project_ID());
m_order = new MOrder(getCtx(), 0, get_TrxName());
m_order.setAD_Org_ID(tel.getAD_Org_ID());
m_order.setC_DocTypeTarget_ID(MOrder.DocSubTypeSO_OnCredit);
//
m_order.setBPartner(bp);
if (m_order.getC_BPartner_Location_ID() == 0) {
log.log(Level.SEVERE, "No BP Location: " + bp);
addLog(0, te.getDateReport(), null, "No Location: " + te.getDocumentNo() + " " + bp.getName());
m_order = null;
return;
}
m_order.setM_Warehouse_ID(te.getM_Warehouse_ID());
if (tel.getC_Activity_ID() != 0)
m_order.setC_Activity_ID(tel.getC_Activity_ID());
if (tel.getC_Campaign_ID() != 0)
m_order.setC_Campaign_ID(tel.getC_Campaign_ID());
if (tel.getC_Project_ID() != 0) {
m_order.setC_Project_ID(tel.getC_Project_ID());
// Optionally Overwrite BP Price list from Project
MProject project = new MProject(getCtx(), tel.getC_Project_ID(), get_TrxName());
if (project.getM_PriceList_ID() != 0)
m_order.setM_PriceList_ID(project.getM_PriceList_ID());
}
m_order.setSalesRep_ID(te.getDoc_User_ID());
//
if (!m_order.save()) {
throw new IllegalStateException("Cannot save Order");
}
} else {
// Update Header info
if (tel.getC_Activity_ID() != 0 && tel.getC_Activity_ID() != m_order.getC_Activity_ID())
m_order.setC_Activity_ID(tel.getC_Activity_ID());
if (tel.getC_Campaign_ID() != 0 && tel.getC_Campaign_ID() != m_order.getC_Campaign_ID())
m_order.setC_Campaign_ID(tel.getC_Campaign_ID());
if (!m_order.save())
new IllegalStateException("Cannot save Order");
}
// OrderLine
MOrderLine ol = new MOrderLine(m_order);
//
if (tel.getM_Product_ID() != 0)
ol.setM_Product_ID(tel.getM_Product_ID(), tel.getC_UOM_ID());
if (tel.getS_ResourceAssignment_ID() != 0)
ol.setS_ResourceAssignment_ID(tel.getS_ResourceAssignment_ID());
//
ol.setQty(tel.getQtyInvoiced());
ol.setDescription(tel.getDescription());
//
ol.setC_Project_ID(tel.getC_Project_ID());
ol.setC_ProjectPhase_ID(tel.getC_ProjectPhase_ID());
ol.setC_ProjectTask_ID(tel.getC_ProjectTask_ID());
ol.setC_Activity_ID(tel.getC_Activity_ID());
ol.setC_Campaign_ID(tel.getC_Campaign_ID());
//
//
BigDecimal price = tel.getPriceInvoiced();
if (price != null && price.compareTo(Env.ZERO) != 0) {
if (tel.getC_Currency_ID() != m_order.getC_Currency_ID())
price = MConversionRate.convert(getCtx(), price, tel.getC_Currency_ID(), m_order.getC_Currency_ID(), m_order.getAD_Client_ID(), m_order.getAD_Org_ID());
ol.setPrice(price);
} else
ol.setPrice();
if (tel.getC_UOM_ID() != 0 && ol.getC_UOM_ID() == 0)
ol.setC_UOM_ID(tel.getC_UOM_ID());
ol.setTax();
if (!ol.save()) {
throw new IllegalStateException("Cannot save Order Line");
}
// Update TimeExpense Line
tel.setC_OrderLine_ID(ol.getC_OrderLine_ID());
if (tel.save())
log.fine("Updated " + tel + " with C_OrderLine_ID");
else
log.log(Level.SEVERE, "Not Updated " + tel + " with C_OrderLine_ID");
}
use of org.compiere.model.MProject in project adempiere by adempiere.
the class CalloutA_Asset_Addition method project.
public String project(Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) {
if (isCalloutActive())
return "";
//
int project_id = 0;
if (value != null && value instanceof Number)
project_id = ((Number) value).intValue();
else
return "";
//
BigDecimal amt = Env.ZERO;
if (project_id > 0) {
MProject prj = new MProject(ctx, project_id, null);
amt = prj.getProjectBalanceAmt();
mTab.setValue(MAssetAddition.COLUMNNAME_C_Currency_ID, prj.getC_Currency_ID());
}
mTab.setValue(MAssetAddition.COLUMNNAME_AssetSourceAmt, amt);
return amt(ctx, WindowNo, mTab, mField, value);
}
Aggregations