Search in sources :

Example 1 with MGLCategory

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

the class CreateDocType method createGLCategory.

/**
	 *  Create GL Category
	 *  @param Name name
	 *  @param CategoryType category type MGLCategory.CATEGORYTYPE_*
	 *  @param isDefault is default value
	 *  @return GL_Category_ID
	 */
private int createGLCategory(String Name, String CategoryType, boolean isDefault) {
    MGLCategory cat = new MGLCategory(Env.getCtx(), 0, trxname);
    cat.setName(Name);
    cat.setCategoryType(CategoryType);
    cat.setIsDefault(isDefault);
    if (!cat.save()) {
        log.log(Level.SEVERE, "GL Category NOT created - " + Name);
        return 0;
    }
    //
    return cat.getGL_Category_ID();
}
Also used : MGLCategory(org.compiere.model.MGLCategory)

Example 2 with MGLCategory

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

the class InvoiceNGL method createGLJournal.

//	doIt
/**
	 * 	Create GL Journal
	 * 	@return document info
	 */
private String createGLJournal() {
    //FR: [ 2214883 ] Remove SQL code and Replace for Query
    final String whereClause = "AD_PInstance_ID=?";
    List<X_T_InvoiceGL> list = new Query(getCtx(), X_T_InvoiceGL.Table_Name, whereClause, get_TrxName()).setParameters(getAD_PInstance_ID()).setOrderBy("AD_Org_ID").list();
    if (list.size() == 0)
        return " - No Records found";
    //
    MAcctSchema as = MAcctSchema.get(getCtx(), p_C_AcctSchema_ID);
    MAcctSchemaDefault asDefaultAccts = MAcctSchemaDefault.get(getCtx(), p_C_AcctSchema_ID);
    MGLCategory cat = MGLCategory.getDefaultSystem(getCtx());
    if (cat == null) {
        MDocType docType = MDocType.get(getCtx(), p_C_DocTypeReval_ID);
        cat = MGLCategory.get(getCtx(), docType.getGL_Category_ID());
    }
    //
    MJournalBatch batch = new MJournalBatch(getCtx(), 0, get_TrxName());
    batch.setDescription(getName());
    batch.setC_DocType_ID(p_C_DocTypeReval_ID);
    batch.setDateDoc(new Timestamp(System.currentTimeMillis()));
    batch.setDateAcct(p_DateReval);
    batch.setC_Currency_ID(as.getC_Currency_ID());
    if (!batch.save())
        return " - Could not create Batch";
    //
    MJournal journal = null;
    BigDecimal drTotal = Env.ZERO;
    BigDecimal crTotal = Env.ZERO;
    int AD_Org_ID = 0;
    for (int i = 0; i < list.size(); i++) {
        X_T_InvoiceGL gl = list.get(i);
        if (gl.getAmtRevalDrDiff().signum() == 0 && gl.getAmtRevalCrDiff().signum() == 0)
            continue;
        MInvoice invoice = new MInvoice(getCtx(), gl.getC_Invoice_ID(), null);
        if (invoice.getC_Currency_ID() == as.getC_Currency_ID())
            continue;
        //
        if (journal == null) {
            journal = new MJournal(batch);
            journal.setC_AcctSchema_ID(as.getC_AcctSchema_ID());
            journal.setC_Currency_ID(as.getC_Currency_ID());
            journal.setC_ConversionType_ID(p_C_ConversionTypeReval_ID);
            MOrg org = MOrg.get(getCtx(), gl.getAD_Org_ID());
            journal.setDescription(getName() + " - " + org.getName());
            journal.setGL_Category_ID(cat.getGL_Category_ID());
            if (!journal.save())
                return " - Could not create Journal";
        }
        //
        MJournalLine line = new MJournalLine(journal);
        line.setLine((i + 1) * 10);
        line.setDescription(invoice.getSummary());
        //
        MFactAcct fa = new MFactAcct(getCtx(), gl.getFact_Acct_ID(), null);
        line.setC_ValidCombination_ID(MAccount.get(fa));
        BigDecimal dr = gl.getAmtRevalDrDiff();
        BigDecimal cr = gl.getAmtRevalCrDiff();
        drTotal = drTotal.add(dr);
        crTotal = crTotal.add(cr);
        line.setAmtSourceDr(dr);
        line.setAmtAcctDr(dr);
        line.setAmtSourceCr(cr);
        line.setAmtAcctCr(cr);
        line.saveEx();
        //
        if (//	invoice org id
        AD_Org_ID == 0)
            AD_Org_ID = gl.getAD_Org_ID();
        //	Change in Org
        if (AD_Org_ID != gl.getAD_Org_ID()) {
            createBalancing(asDefaultAccts, journal, drTotal, crTotal, AD_Org_ID, (i + 1) * 10);
            //
            AD_Org_ID = gl.getAD_Org_ID();
            drTotal = Env.ZERO;
            crTotal = Env.ZERO;
            journal = null;
        }
    }
    createBalancing(asDefaultAccts, journal, drTotal, crTotal, AD_Org_ID, (list.size() + 1) * 10);
    return " - " + batch.getDocumentNo() + " #" + list.size();
}
Also used : MDocType(org.compiere.model.MDocType) Query(org.compiere.model.Query) X_T_InvoiceGL(org.compiere.model.X_T_InvoiceGL) MGLCategory(org.compiere.model.MGLCategory) MJournalLine(org.compiere.model.MJournalLine) MInvoice(org.compiere.model.MInvoice) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal) MAcctSchema(org.compiere.model.MAcctSchema) MOrg(org.compiere.model.MOrg) MAcctSchemaDefault(org.compiere.model.MAcctSchemaDefault) MFactAcct(org.compiere.model.MFactAcct) MJournal(org.compiere.model.MJournal) MJournalBatch(org.compiere.model.MJournalBatch)

Aggregations

MGLCategory (org.compiere.model.MGLCategory)2 BigDecimal (java.math.BigDecimal)1 Timestamp (java.sql.Timestamp)1 MAcctSchema (org.compiere.model.MAcctSchema)1 MAcctSchemaDefault (org.compiere.model.MAcctSchemaDefault)1 MDocType (org.compiere.model.MDocType)1 MFactAcct (org.compiere.model.MFactAcct)1 MInvoice (org.compiere.model.MInvoice)1 MJournal (org.compiere.model.MJournal)1 MJournalBatch (org.compiere.model.MJournalBatch)1 MJournalLine (org.compiere.model.MJournalLine)1 MOrg (org.compiere.model.MOrg)1 Query (org.compiere.model.Query)1 X_T_InvoiceGL (org.compiere.model.X_T_InvoiceGL)1