public static MCAdvComSystem retrieveDefaultEx( final Properties ctx, final int adOrgId, final String trxName) { final String wc = I_C_AdvComSystem.COLUMNNAME_AD_Org_ID + "=? AND " + I_C_AdvComSystem.COLUMNNAME_IsDefault + "='Y'"; final MCAdvComSystem result = new Query(ctx, I_C_AdvComSystem.Table_Name, wc, trxName) .setParameters(adOrgId) .setOnlyActiveRecords(true) .setClient_ID() .firstOnly(); if (result == null) { // TODO -> AD_Message throw CommissionException.inconsistentConfig( "In der Organisation " + MOrg.get(ctx, adOrgId).getName() + " gibt es keinen Standard-Verguetungsplan", null); } return result; }
/** * Create GL Journal * * @return document info */ private String createGLJournal() { // FR: [ 2214883 ] Remove SQL code and Replace for Query String whereClause = "AD_PInstance_ID=?"; List<X_T_InvoiceGL> list = new Query(getCtx(), X_T_InvoiceGL.Table_Name, whereClause, get_TrxName()) .setParameters(new Object[] {getAD_PInstance_ID()}) .setOrderBy("AD_Org_ID") .list(); // FR: [ 2214883 ] Remove SQL code and Replace for Query 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); // TODO: C_ValidCombination_ID is no longer a column because we have DR/CR accounts // line.setC_ValidCombination(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.save(); // if (AD_Org_ID == 0) // invoice org id 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(); } // createGLJournal