Search in sources :

Example 31 with MAccount

use of org.compiere.model.MAccount in project adempiere by adempiere.

the class Doc_PPCostCollector method createMaterialReceipt.

/**
	 * The Receipt Finish good product created the next account fact
	 * Debit Product Asset Account for each Cost Element using Current Cost 
	 * Create a fact line for each cost element type
	 * 		Material
	 * 		Labor(Resources)
	 * 		Burden
	 * 		Overhead 
	 * 		Outsite Processing
	 * Debit Scrap Account for each Cost Element using Current Cost 
	 * Create a fact line for each cost element type
	 * 		Material
	 * 		Labor(Resources)
	 * 		Burden
	 * 		Overhead 
	 * 		Outsite Processing			
	 * Credit Work in Process Account for each Cost Element using Current Cost 
	 * Create a fact line for each cost element type
	 * 		Material
	 * 		Labor(Resources)
	 * 		Burden
	 * 		Overhead 
	 * 		Outsite Processing		
	 */
protected Fact createMaterialReceipt(MAcctSchema acctSchema) {
    final Fact fact = new Fact(this, acctSchema, Fact.POST_Actual);
    FactLine debitLine = null;
    FactLine creditLine = null;
    final MAccount workInProcessAccount = docLineCostCollector.getAccount(ProductCost.ACCTTYPE_P_WorkInProcess, acctSchema);
    final MAccount burdenAccount = docLineCostCollector.getAccount(ProductCost.ACCTTYPE_P_Burden, acctSchema);
    MAccount inventoryAccount = docLineCostCollector.getAccount(ProductCost.ACCTTYPE_P_Asset, acctSchema);
    BigDecimal totalcosts = BigDecimal.ZERO;
    BigDecimal totalcostsScrapped = BigDecimal.ZERO;
    for (MCostDetail costDetail : docLineCostCollector.getCostDetail(acctSchema, true)) {
        MCostElement costElement = MCostElement.get(getCtx(), costDetail.getM_CostElement_ID());
        String description = manufacturingOrder.getDocumentNo() + " - " + costDetail.getM_CostType().getName() + " - " + costElement.getName();
        if (MCostElement.COSTELEMENTTYPE_BurdenMOverhead.equals(costElement.getCostElementType())) {
            BigDecimal absoluteCost = costDetail.getTotalCost(costDetail, acctSchema);
            if (absoluteCost.signum() == 0)
                continue;
            BigDecimal cost = costDetail.getQty().signum() < 0 ? absoluteCost.negate() : absoluteCost;
            if (cost.scale() > acctSchema.getStdPrecision())
                cost = cost.setScale(acctSchema.getStdPrecision(), RoundingMode.HALF_UP);
            if (cost.compareTo(Env.ZERO) == 0)
                continue;
            creditLine = fact.createLine(docLineCostCollector, burdenAccount, acctSchema.getC_Currency_ID(), null, cost);
            creditLine.setQty(costCollector.getMovementQty());
            creditLine.setDescription(description);
            totalcosts = totalcosts.add(cost);
            continue;
        }
        if (costCollector.getMovementQty().signum() != 0) {
            BigDecimal absoluteCost = costDetail.getTotalCost(costDetail, acctSchema);
            if (absoluteCost.signum() == 0)
                continue;
            BigDecimal cost = costDetail.getQty().signum() < 0 ? absoluteCost.negate() : absoluteCost;
            if (cost.scale() > acctSchema.getStdPrecision())
                cost = cost.setScale(acctSchema.getStdPrecision(), RoundingMode.HALF_UP);
            if (cost.compareTo(Env.ZERO) == 0)
                continue;
            creditLine = fact.createLine(docLineCostCollector, workInProcessAccount, acctSchema.getC_Currency_ID(), cost.negate());
            creditLine.setQty(costCollector.getMovementQty());
            creditLine.setDescription(description);
            totalcosts = totalcosts.add(cost);
        }
        if (costCollector.getScrappedQty().signum() != 0) {
            BigDecimal absoluteCost = costDetail.getPrice().multiply(costCollector.getScrappedQty()).add(costDetail.getTotalCost(costDetail, acctSchema));
            if (absoluteCost.signum() == 0)
                continue;
            BigDecimal cost = costDetail.getQty().signum() < 0 ? absoluteCost.negate() : absoluteCost;
            if (cost.scale() > acctSchema.getStdPrecision())
                cost = cost.setScale(acctSchema.getStdPrecision(), RoundingMode.HALF_UP);
            creditLine = fact.createLine(docLineCostCollector, workInProcessAccount, acctSchema.getC_Currency_ID(), null, cost.negate());
            creditLine.setQty(costCollector.getMovementQty());
            description = manufacturingOrder.getDocumentNo() + " - " + costDetail.getM_CostType().getName() + " - " + costElement.getName() + " - " + Msg.parseTranslation(getCtx(), "@Scrap@");
            ;
            creditLine.setDescription(description);
            totalcostsScrapped = totalcostsScrapped.add(cost);
        }
    }
    String description = manufacturingOrder.getDocumentNo();
    // Debit Amount based on sign of total costs
    debitLine = fact.createLine(docLineCostCollector, inventoryAccount, acctSchema.getC_Currency_ID(), totalcosts);
    debitLine.setQty(costCollector.getMovementQty());
    debitLine.setDescription(description);
    if (totalcostsScrapped.compareTo(Env.ZERO) != 0) {
        debitLine = fact.createLine(docLineCostCollector, inventoryAccount, acctSchema.getC_Currency_ID(), totalcostsScrapped);
        debitLine.setQty(costCollector.getScrappedQty());
        description = Msg.parseTranslation(getCtx(), "@Scrap@");
        debitLine.setDescription(description);
    }
    return fact;
}
Also used : MCostElement(org.compiere.model.MCostElement) MAccount(org.compiere.model.MAccount) MCostDetail(org.compiere.model.MCostDetail) BigDecimal(java.math.BigDecimal)

Example 32 with MAccount

use of org.compiere.model.MAccount in project adempiere by adempiere.

the class Doc_PPCostCollector method createVariance.

protected Fact createVariance(MAcctSchema acctSchema, int varianceAcctType) {
    final Fact fact = new Fact(this, acctSchema, Fact.POST_Actual);
    final MProduct product = costCollector.getM_Product();
    MAccount varianceAccount = docLineCostCollector.getAccount(varianceAcctType, acctSchema);
    MAccount workInProcess = docLineCostCollector.getAccount(ProductCost.ACCTTYPE_P_WorkInProcess, acctSchema);
    for (MCostDetail costDetail : docLineCostCollector.getCostDetail(acctSchema, false)) {
        MCostElement costElement = MCostElement.get(getCtx(), costDetail.getM_CostElement_ID());
        BigDecimal absoluteCost = costDetail.getTotalCost(costDetail, acctSchema);
        if (absoluteCost.signum() == 0)
            continue;
        BigDecimal cost = costDetail.getQty().signum() < 0 ? absoluteCost.negate() : absoluteCost;
        if (cost == null)
            cost = BigDecimal.ZERO;
        if (cost.scale() > acctSchema.getStdPrecision())
            cost = cost.setScale(acctSchema.getStdPrecision(), RoundingMode.HALF_UP);
        BigDecimal qty = costDetail.getQty();
        createLines(costElement, acctSchema, fact, product, varianceAccount, workInProcess, cost, qty);
    }
    return fact;
}
Also used : MCostElement(org.compiere.model.MCostElement) MProduct(org.compiere.model.MProduct) MAccount(org.compiere.model.MAccount) MCostDetail(org.compiere.model.MCostDetail) BigDecimal(java.math.BigDecimal)

Example 33 with MAccount

use of org.compiere.model.MAccount in project adempiere by adempiere.

the class AcctSchemaCopyAcct method copyGL.

//	doIt
/**
	 * 	Copy GL 
	 *	@param targetAS target
	 *	@throws Exception
	 */
private void copyGL(MAcctSchema targetAS) throws Exception {
    MAcctSchemaGL source = MAcctSchemaGL.get(getCtx(), p_SourceAcctSchema_ID);
    MAcctSchemaGL target = new MAcctSchemaGL(getCtx(), 0, get_TrxName());
    target.setC_AcctSchema_ID(p_TargetAcctSchema_ID);
    ArrayList<KeyNamePair> list = source.getAcctInfo();
    for (int i = 0; i < list.size(); i++) {
        KeyNamePair pp = list.get(i);
        int sourceC_ValidCombination_ID = pp.getKey();
        String columnName = pp.getName();
        MAccount sourceAccount = MAccount.get(getCtx(), sourceC_ValidCombination_ID);
        MAccount targetAccount = createAccount(targetAS, sourceAccount);
        target.setValue(columnName, new Integer(targetAccount.getC_ValidCombination_ID()));
    }
    if (!target.save())
        throw new AdempiereSystemError("Could not Save GL");
}
Also used : MAcctSchemaGL(org.compiere.model.MAcctSchemaGL) AdempiereSystemError(org.compiere.util.AdempiereSystemError) MAccount(org.compiere.model.MAccount) KeyNamePair(org.compiere.util.KeyNamePair)

Example 34 with MAccount

use of org.compiere.model.MAccount in project adempiere by adempiere.

the class Doc_HRProcess method createFacts.

//  getBalance
@Override
public ArrayList<Fact> createFacts(MAcctSchema as) {
    Fact fact = new Fact(this, as, Fact.POST_Actual);
    final String sql = // 1,2,3,4
    "SELECT m.HR_Concept_id, MAX(c.Name) As Name, SUM(m.Amount) As Amount, MAX(c.AccountSign) As AccountSign, " + // 5,6,7
    " MAX(CA.IsBalancing) As IsBalancing, e.AD_Org_ID As AD_Org_ID, m.C_Activity_ID, bp.C_BPartner_ID, m.User1_ID, m.User2_ID, m.User3_ID, m.User4_ID " + " FROM HR_Movement m" + " INNER JOIN HR_Concept_Acct ca ON (ca.HR_Concept_ID=m.HR_Concept_ID AND ca.AD_Client_ID = m.AD_Client_ID AND ca.IsActive = 'Y')" + " INNER JOIN HR_Concept      c  ON (c.HR_Concept_ID=m.HR_Concept_ID AND c.IsActive = 'Y')" + " INNER JOIN C_BPartner      bp ON (bp.C_BPartner_ID = m.C_BPartner_ID)" + " INNER JOIN HR_Employee	 e  ON (bp.C_BPartner_ID=e.C_BPartner_ID)" + " INNER JOIN HR_Department   d  ON (d.HR_Department_ID=e.HR_Department_ID)" + " WHERE m.HR_Process_ID=? AND (m.Qty <> 0 OR m.Amount <> 0) AND c.AccountSign != 'N'" + " GROUP BY m.HR_Concept_ID,e.AD_Org_ID,m.C_Activity_ID , bp.C_BPartner_ID , m.User1_ID, m.User2_ID, m.User3_ID, m.User4_ID  " + " ORDER BY e.AD_Org_ID,m.C_Activity_ID,bp.C_BPartner_ID, m.User1_ID, m.User2_ID, m.User3_ID, m.User4_ID ";
    ResultSet rs = null;
    PreparedStatement pstmt = null;
    try {
        BigDecimal totalDebit = Env.ZERO;
        BigDecimal totalCredit = Env.ZERO;
        pstmt = DB.prepareStatement(sql, getTrxName());
        pstmt.setInt(1, process.getHR_Process_ID());
        rs = pstmt.executeQuery();
        while (rs.next()) {
            int HR_Concept_ID = rs.getInt("HR_Concept_ID");
            BigDecimal sumAmount = rs.getBigDecimal("Amount");
            // round amount according to currency
            sumAmount = sumAmount.setScale(as.getStdPrecision(), BigDecimal.ROUND_HALF_UP);
            String AccountSign = rs.getString("AccountSign");
            boolean isBalancing = "Y".equals(rs.getString("IsBalancing"));
            int AD_OrgTrx_ID = rs.getInt("AD_Org_ID");
            int C_Activity_ID = rs.getInt("C_Activity_ID");
            int C_BPartner_ID = rs.getInt("C_BPartner_ID");
            int user1Id = rs.getInt("User1_ID");
            int user2Id = rs.getInt("User3_ID");
            int user3Id = rs.getInt("User4_ID");
            int user4Id = rs.getInt("User5_ID");
            MHRMovement movement = new MHRMovement(getCtx(), 0, getTrxName());
            movement.setC_BPartner_ID(C_BPartner_ID);
            movement.setHR_Concept_ID(HR_Concept_ID);
            movement.setAccountSign(AccountSign);
            movement.setAD_OrgTrx_ID(AD_OrgTrx_ID);
            movement.setC_Activity_ID(C_Activity_ID);
            movement.setAmount(sumAmount);
            movement.setUser1_ID(user1Id);
            movement.setUser2_ID(user2Id);
            movement.setUser3_ID(user3Id);
            movement.setUser4_ID(user4Id);
            DocLine_Payroll docLine = new DocLine_Payroll(movement, this);
            //
            if (AccountSign != null && AccountSign.length() > 0 && (MHRConcept.ACCOUNTSIGN_Debit.equals(AccountSign) || MHRConcept.ACCOUNTSIGN_Credit.equals(AccountSign))) {
                if (isBalancing) {
                    MAccount accountBPD = MAccount.get(getCtx(), getAccountBalancing(as.getC_AcctSchema_ID(), HR_Concept_ID, MHRConcept.ACCOUNTSIGN_Debit));
                    FactLine debit = fact.createLine(docLine, accountBPD, as.getC_Currency_ID(), sumAmount, null);
                    debit.saveEx();
                    MAccount accountBPC = MAccount.get(getCtx(), this.getAccountBalancing(as.getC_AcctSchema_ID(), HR_Concept_ID, MHRConcept.ACCOUNTSIGN_Credit));
                    FactLine credit = fact.createLine(docLine, accountBPC, as.getC_Currency_ID(), null, sumAmount);
                    credit.saveEx();
                } else {
                    if (MHRConcept.ACCOUNTSIGN_Debit.equals(AccountSign)) {
                        MAccount accountBPD = MAccount.get(getCtx(), getAccountBalancing(as.getC_AcctSchema_ID(), HR_Concept_ID, MHRConcept.ACCOUNTSIGN_Debit));
                        FactLine debit = fact.createLine(docLine, accountBPD, as.getC_Currency_ID(), sumAmount, null);
                        debit.saveEx();
                        totalDebit = totalDebit.add(sumAmount);
                    } else if (MHRConcept.ACCOUNTSIGN_Credit.equals(AccountSign)) {
                        MAccount accountBPC = MAccount.get(getCtx(), this.getAccountBalancing(as.getC_AcctSchema_ID(), HR_Concept_ID, MHRConcept.ACCOUNTSIGN_Credit));
                        FactLine credit = fact.createLine(docLine, accountBPC, as.getC_Currency_ID(), null, sumAmount);
                        credit.saveEx();
                        totalCredit = totalCredit.add(sumAmount);
                    }
                }
            }
            movement = null;
        }
        if (totalDebit.signum() != 0 || totalCredit.signum() != 0) {
            int C_Charge_ID = process.getHR_Payroll().getC_Charge_ID();
            if (C_Charge_ID > 0) {
                MAccount acct = MCharge.getAccount(C_Charge_ID, as, totalDebit.subtract(totalCredit));
                FactLine regTotal = null;
                if (totalDebit.abs().compareTo(totalCredit.abs()) > 0)
                    regTotal = fact.createLine(null, acct, as.getC_Currency_ID(), null, totalDebit.subtract(totalCredit));
                else
                    regTotal = fact.createLine(null, acct, as.getC_Currency_ID(), totalCredit.abs().subtract(totalDebit.abs()), null);
                regTotal.setAD_Org_ID(getAD_Org_ID());
                regTotal.saveEx();
            }
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, sql, e);
        p_Error = e.getLocalizedMessage();
        return null;
    } finally {
        DB.close(rs, pstmt);
        pstmt = null;
        rs = null;
    }
    ArrayList<Fact> facts = new ArrayList<Fact>();
    facts.add(fact);
    return facts;
}
Also used : MAccount(org.compiere.model.MAccount) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) BigDecimal(java.math.BigDecimal) MHRMovement(org.eevolution.model.MHRMovement) ResultSet(java.sql.ResultSet)

Example 35 with MAccount

use of org.compiere.model.MAccount in project adempiere by adempiere.

the class InvoiceNGL method createBalancing.

//	createGLJournal
/**
	 * 	Create Balancing Entry
	 *	@param asDefaultAccts acct schema default accounts
	 *	@param journal journal
	 *	@param drTotal dr
	 *	@param crTotal cr
	 *	@param AD_Org_ID org
	 *	@param lineNo base line no
	 */
private void createBalancing(MAcctSchemaDefault asDefaultAccts, MJournal journal, BigDecimal drTotal, BigDecimal crTotal, int AD_Org_ID, int lineNo) {
    if (journal == null)
        throw new IllegalArgumentException("Jornal is null");
    //		CR Entry = Gain
    if (drTotal.signum() != 0) {
        MJournalLine line = new MJournalLine(journal);
        line.setLine(lineNo + 1);
        MAccount base = MAccount.get(getCtx(), asDefaultAccts.getUnrealizedGain_Acct());
        MAccount acct = MAccount.get(getCtx(), asDefaultAccts.getAD_Client_ID(), AD_Org_ID, asDefaultAccts.getC_AcctSchema_ID(), base.getAccount_ID(), base.getC_SubAcct_ID(), base.getM_Product_ID(), base.getC_BPartner_ID(), base.getAD_OrgTrx_ID(), base.getC_LocFrom_ID(), base.getC_LocTo_ID(), base.getC_SalesRegion_ID(), base.getC_Project_ID(), base.getC_Campaign_ID(), base.getC_Activity_ID(), base.getUser1_ID(), base.getUser2_ID(), base.getUser3_ID(), base.getUser4_ID(), base.getUserElement1_ID(), base.getUserElement2_ID(), null);
        line.setDescription(Msg.getElement(getCtx(), "UnrealizedGain_Acct"));
        line.setC_ValidCombination_ID(acct.getC_ValidCombination_ID());
        line.setAmtSourceCr(drTotal);
        line.setAmtAcctCr(drTotal);
        line.saveEx();
    }
    //	DR Entry = Loss
    if (crTotal.signum() != 0) {
        MJournalLine line = new MJournalLine(journal);
        line.setLine(lineNo + 2);
        MAccount base = MAccount.get(getCtx(), asDefaultAccts.getUnrealizedLoss_Acct());
        MAccount acct = MAccount.get(getCtx(), asDefaultAccts.getAD_Client_ID(), AD_Org_ID, asDefaultAccts.getC_AcctSchema_ID(), base.getAccount_ID(), base.getC_SubAcct_ID(), base.getM_Product_ID(), base.getC_BPartner_ID(), base.getAD_OrgTrx_ID(), base.getC_LocFrom_ID(), base.getC_LocTo_ID(), base.getC_SalesRegion_ID(), base.getC_Project_ID(), base.getC_Campaign_ID(), base.getC_Activity_ID(), base.getUser1_ID(), base.getUser2_ID(), base.getUser3_ID(), base.getUser4_ID(), base.getUserElement1_ID(), base.getUserElement2_ID(), null);
        line.setDescription(Msg.getElement(getCtx(), "UnrealizedLoss_Acct"));
        line.setC_ValidCombination_ID(acct.getC_ValidCombination_ID());
        line.setAmtSourceDr(crTotal);
        line.setAmtAcctDr(crTotal);
        line.saveEx();
    }
}
Also used : MJournalLine(org.compiere.model.MJournalLine) MAccount(org.compiere.model.MAccount)

Aggregations

MAccount (org.compiere.model.MAccount)42 BigDecimal (java.math.BigDecimal)25 ArrayList (java.util.ArrayList)16 MCostDetail (org.compiere.model.MCostDetail)8 PreparedStatement (java.sql.PreparedStatement)7 ResultSet (java.sql.ResultSet)7 MProduct (org.compiere.model.MProduct)6 SQLException (java.sql.SQLException)5 MCostElement (org.compiere.model.MCostElement)5 MJournalLine (org.compiere.model.MJournalLine)4 MCostType (org.compiere.model.MCostType)3 Timestamp (java.sql.Timestamp)2 MAcctSchemaElement (org.compiere.model.MAcctSchemaElement)2 MCharge (org.compiere.model.MCharge)2 MElementValue (org.compiere.model.MElementValue)2 MInvoice (org.compiere.model.MInvoice)2 AdempiereSystemError (org.compiere.util.AdempiereSystemError)2 TreeMap (java.util.TreeMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 I_C_Project (org.compiere.model.I_C_Project)1