Search in sources :

Example 1 with X_I_Budget

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

the class ImportBudget method fillIdValues.

/**
     * Fill Id Values
     * @param importBudget
     * @param acctSchemaElements
     * @param trxName
     */
private void fillIdValues(X_I_Budget importBudget, MAcctSchemaElement[] acctSchemaElements, String trxName) {
    StringBuffer stringError = new StringBuffer("");
    // Set Organization
    Integer orgId = 0;
    if (importBudget.getAD_Org_ID() > 0)
        orgId = importBudget.getAD_Org_ID();
    if (orgId <= 0 && importBudget.getOrgValue() != null)
        orgId = getId(MOrg.Table_Name, MOrg.COLUMNNAME_Value + "=?", trxName, importBudget.getOrgValue());
    if (orgId > 0 && importBudget.getAD_Org_ID() <= 0)
        importBudget.setAD_Org_ID(orgId);
    if (importBudget.getAD_Org_ID() <= 0 && importBudget.getOrgValue() != null)
        stringError.append("@AD_Org_ID@ @NotFound@ ");
    // Set Organization Trx
    Integer orgTrxId = 0;
    if (importBudget.getAD_OrgTrx_ID() > 0)
        orgTrxId = importBudget.getAD_OrgTrx_ID();
    if (orgTrxId <= 0 && importBudget.getOrgTrxValue() != null)
        orgTrxId = getId(MOrg.Table_Name, MOrg.COLUMNNAME_Value + "=?", trxName, importBudget.getOrgTrxValue());
    if (orgTrxId > 0 && importBudget.getAD_OrgTrx_ID() <= 0)
        importBudget.setAD_OrgTrx_ID(orgTrxId);
    if (importBudget.getAD_Org_ID() <= 0 && importBudget.getOrgTrxValue() != null)
        stringError.append("@AD_OrgTrx_ID@ @NotFound@ ");
    // Set Account Schema
    Integer accountSchemaId = 0;
    if (importBudget.getC_AcctSchema_ID() > 0)
        accountSchemaId = importBudget.getC_AcctSchema_ID();
    if (accountSchemaId <= 0 && importBudget.getAcctSchemaName() != null)
        accountSchemaId = getId(MAcctSchema.Table_Name, MAcctSchema.COLUMNNAME_Name + "=?", trxName, importBudget.getAcctSchemaName());
    if (accountSchemaId > 0 && importBudget.getC_AcctSchema_ID() <= 0)
        importBudget.setC_AcctSchema_ID(accountSchemaId);
    else {
        accountSchemaId = getAccountingSchemaId();
        importBudget.setC_AcctSchema_ID(accountSchemaId);
    }
    // Set Budget
    Integer budgetId = 0;
    if (importBudget.getGL_Budget_ID() > 0)
        budgetId = importBudget.getGL_Budget_ID();
    if (budgetId <= 0 && importBudget.getBudgetCode() != null)
        budgetId = getId(X_GL_Budget.Table_Name, X_GL_Budget.COLUMNNAME_Name + "=?", trxName, importBudget.getBudgetCode());
    if (budgetId > 0 && importBudget.getGL_Budget_ID() <= 0)
        importBudget.setGL_Budget_ID(budgetId);
    if (importBudget.getGL_Budget_ID() <= 0 && importBudget.getBudgetCode() != null)
        stringError.append("@GL_Budget_ID@ @NotFound@ ");
    // Set Asset
    Integer assetId = 0;
    if (importBudget.getA_Asset_ID() > 0)
        assetId = importBudget.getA_Asset_ID();
    if (assetId <= 0 && importBudget.getAssetValue() != null)
        assetId = getId(X_A_Asset.Table_Name, X_A_Asset.COLUMNNAME_Value + "=?", trxName, importBudget.getAssetValue());
    if (assetId > 0 && importBudget.getA_Asset_ID() <= 0)
        importBudget.setA_Asset_ID(assetId);
    if (importBudget.getA_Asset_ID() <= 0 && importBudget.getAssetValue() != null)
        stringError.append("@A_Asset_ID@ @NotFound@ ");
    // Set Account
    int accountId = 0;
    if (importBudget.getAccount_ID() > 0)
        accountId = importBudget.getAccount_ID();
    if (accountId <= 0 && importBudget.getAccountValue() != null)
        accountId = getId(MElementValue.Table_Name, MElementValue.COLUMNNAME_Value + "=?", trxName, importBudget.getAccountValue());
    if (accountId > 0 && importBudget.getAccount_ID() <= 0)
        importBudget.setAccount_ID(accountId);
    if (importBudget.getAccount_ID() <= 0 && importBudget.getAccountValue() != null)
        stringError.append("@Account_ID@ @NotFound@ ");
    int partnerId = 0;
    if (importBudget.getC_BPartner_ID() > 0)
        partnerId = importBudget.getC_BPartner_ID();
    if (partnerId <= 0 && importBudget.getBPartnerValue() != null) {
        MBPartner partner = MBPartner.get(getCtx(), importBudget.getBPartnerValue());
        if (partner != null)
            partnerId = partner.getC_BPartner_ID();
    }
    if (partnerId > 0 && importBudget.getC_BPartner_ID() <= 0)
        importBudget.setC_BPartner_ID(partnerId);
    if (importBudget.getC_BPartner_ID() <= 0 && importBudget.getBPartnerValue() != null)
        stringError.append("@C_BPartner_ID@ @NotFound@ ");
    // Set Product
    Integer productId = 0;
    if (importBudget.getM_Product_ID() > 0)
        productId = importBudget.getM_Product_ID();
    if (productId <= 0 && importBudget.getProductValue() != null)
        productId = getId(MProduct.Table_Name, MProduct.COLUMNNAME_Value + "=?", trxName, importBudget.getProductValue());
    if (productId > 0 && importBudget.getM_Product_ID() <= 0)
        importBudget.setM_Product_ID(productId);
    if (importBudget.getM_Product_ID() <= 0 && importBudget.getProductValue() != null)
        stringError.append("@M_Product_ID@ @NotFound@ ");
    // Set Project
    Integer projectId = 0;
    if (importBudget.getC_Project_ID() > 0)
        projectId = importBudget.getC_Project_ID();
    if (projectId <= 0 && importBudget.getProjectValue() != null)
        projectId = getId(MProject.Table_Name, MProject.COLUMNNAME_Value + "=?", trxName, importBudget.getProjectValue());
    if (projectId > 0 && importBudget.getC_Project_ID() <= 0)
        importBudget.setC_Project_ID(projectId);
    if (importBudget.getC_Project_ID() <= 0 && importBudget.getProjectValue() != null)
        stringError.append("@C_Project_ID@ @NotFound@ ");
    // Set Campaign
    Integer campaignId = 0;
    if (importBudget.getC_Campaign_ID() > 0)
        campaignId = importBudget.getC_Campaign_ID();
    if (campaignId <= 0 && importBudget.getCampaignValue() != null)
        campaignId = getId(MCampaign.Table_Name, MCampaign.COLUMNNAME_Value + "=?", trxName, importBudget.getCampaignValue());
    if (campaignId > 0 && importBudget.getC_Campaign_ID() <= 0)
        importBudget.setC_Campaign_ID(campaignId);
    if (importBudget.getC_Campaign_ID() <= 0 && importBudget.getCampaignValue() != null)
        stringError.append("@C_Campaign_ID@ @NotFound@ ");
    // Set Sales Region
    Integer salesRegionId = 0;
    if (importBudget.getC_SalesRegion_ID() > 0)
        salesRegionId = importBudget.getC_SalesRegion_ID();
    if (salesRegionId <= 0 && importBudget.getSalesRegionValue() != null)
        salesRegionId = getId(MSalesRegion.Table_Name, MSalesRegion.COLUMNNAME_Value + "=?", trxName, importBudget.getSalesRegionValue());
    if (salesRegionId > 0 && importBudget.getC_SalesRegion_ID() <= 0)
        importBudget.setC_SalesRegion_ID(salesRegionId);
    if (importBudget.getC_SalesRegion_ID() <= 0 && importBudget.getSalesRegionValue() != null)
        stringError.append("@C_SalesRegion_ID@ @NotFound@");
    // Set Activity Id
    Integer activityId = 0;
    if (importBudget.getC_Activity_ID() > 0)
        activityId = importBudget.getC_Activity_ID();
    if (activityId <= 0 && importBudget.getActivityValue() != null)
        activityId = getId(MActivity.Table_Name, MActivity.COLUMNNAME_Value + "=?", trxName, importBudget.getActivityValue());
    if (accountId > 0 && importBudget.getC_Activity_ID() <= 0)
        importBudget.setC_Activity_ID(activityId);
    if (importBudget.getC_Activity_ID() <= 0 && importBudget.getActivityValue() != null)
        stringError.append("@C_SalesRegion_ID@ @NotFound@ ");
    // Set Sub Acct Id
    Integer subAcctountId = 0;
    if (importBudget.getC_SubAcct_ID() > 0)
        subAcctountId = importBudget.getC_SubAcct_ID();
    if (subAcctountId <= 0 && importBudget.getSubAcctValue() != null)
        subAcctountId = getId(X_C_SubAcct.Table_Name, X_C_SubAcct.COLUMNNAME_Value + "=?", trxName, importBudget.getSubAcctValue());
    if (subAcctountId > 0 && importBudget.getC_SubAcct_ID() <= 0)
        importBudget.setC_SubAcct_ID(subAcctountId);
    if (importBudget.getC_SubAcct_ID() <= 0 && importBudget.getSubAcctValue() != null)
        stringError.append("@C_SubAcct_ID@ @NotFound@ ");
    // Set User 1
    Integer user1Id = 0;
    if (importBudget.getUser1_ID() > 0)
        user1Id = importBudget.getUser1_ID();
    if (user1Id <= 0 && importBudget.getUser1_ID() <= 0 && importBudget.getUserValue1() != null) {
        Arrays.stream(acctSchemaElements).filter(acctSchemaElement -> MAcctSchemaElement.ELEMENTTYPE_UserList1.equals(acctSchemaElement.getElementType())).forEach(acctSchemaElement -> {
            String where = MElementValue.COLUMNNAME_C_Element_ID + "=? AND " + MElementValue.COLUMNNAME_Value + "=?";
            importBudget.setUser1_ID(getId(MElementValue.Table_Name, where, trxName, acctSchemaElement.getC_Element_ID(), importBudget.getUserValue1()));
        });
    }
    if (importBudget.getUser1_ID() <= 0 && importBudget.getUserValue1() != null)
        stringError.append("@User1_ID@ @NotFound@ ");
    // User 2
    Integer user2Id = 0;
    if (importBudget.getUser2_ID() > 0)
        user2Id = importBudget.getUser2_ID();
    if (user2Id <= 0 && importBudget.getUser2_ID() <= 0 && importBudget.getUserValue2() != null) {
        Arrays.stream(acctSchemaElements).filter(acctSchemaElement -> MAcctSchemaElement.ELEMENTTYPE_UserList2.equals(acctSchemaElement.getElementType())).forEach(acctSchemaElement -> {
            String where = MElementValue.COLUMNNAME_C_Element_ID + "=? AND " + MElementValue.COLUMNNAME_Value + "=?";
            importBudget.setUser2_ID(getId(MElementValue.Table_Name, where, trxName, acctSchemaElement.getC_Element_ID(), importBudget.getUserValue2()));
        });
    }
    if (importBudget.getUser2_ID() <= 0 && importBudget.getUserValue2() != null)
        stringError.append("@User2_ID@ @NotFound@ ");
    Integer user3Id = 0;
    if (importBudget.getUser3_ID() > 0)
        user3Id = importBudget.getUser3_ID();
    if (user3Id <= 0 && importBudget.getUser3_ID() <= 0 && importBudget.getUserValue3() != null) {
        Arrays.stream(acctSchemaElements).filter(acctSchemaElement -> MAcctSchemaElement.ELEMENTTYPE_UserList3.equals(acctSchemaElement.getElementType())).forEach(acctSchemaElement -> {
            String where = MElementValue.COLUMNNAME_C_Element_ID + "=? AND " + MElementValue.COLUMNNAME_Value + "=?";
            importBudget.setUser3_ID(getId(MElementValue.Table_Name, where, trxName, acctSchemaElement.getC_Element_ID(), importBudget.getUserValue3()));
        });
    }
    if (importBudget.getUser3_ID() <= 0 && importBudget.getUserValue3() != null)
        stringError.append("@User3_ID@ @NotFound@ ");
    Integer user4Id = 0;
    if (importBudget.getUser4_ID() > 0)
        user4Id = importBudget.getUser4_ID();
    if (user4Id <= 0 && importBudget.getUser4_ID() <= 0 && importBudget.getUserValue4() != null) {
        Arrays.stream(acctSchemaElements).filter(acctSchemaElement -> MAcctSchemaElement.ELEMENTTYPE_UserList4.equals(acctSchemaElement.getElementType())).forEach(acctSchemaElement -> {
            String where = MElementValue.COLUMNNAME_C_Element_ID + "=? AND " + MElementValue.COLUMNNAME_Value + "=?";
            importBudget.setUser4_ID(getId(MElementValue.Table_Name, where, trxName, acctSchemaElement.getC_Element_ID(), importBudget.getUserValue4()));
        });
    }
    if (importBudget.getUser4_ID() <= 0 && importBudget.getUserValue4() != null)
        stringError.append("@User4_ID@ @NotFound@ ");
    Integer userElement1Id = 0;
    if (importBudget.getUserElement1_ID() > 0)
        userElement1Id = importBudget.getUserElement1_ID();
    if (userElement1Id <= 0 && importBudget.getUserElement1_ID() <= 0 && importBudget.getUserElementValue1() != null) {
        Arrays.stream(acctSchemaElements).filter(acctSchemaElement -> MAcctSchemaElement.ELEMENTTYPE_UserElement1.equals(acctSchemaElement.getElementType())).forEach(acctSchemaElement -> {
            I_AD_Column column = acctSchemaElement.getAD_Column();
            MTable table = (MTable) column.getAD_Table();
            MColumn columnName = table.getColumn("Value");
            if (columnName == null)
                columnName = table.getColumn("Name");
            if (columnName != null)
                importBudget.setUserElement1_ID(getId(table.getTableName(), columnName.getColumnName() + "=?", trxName, importBudget.getUserElementValue1()));
        });
    }
    if (importBudget.getUserElement1_ID() <= 0 && importBudget.getUserElementValue1() != null)
        stringError.append("@UserElement1_ID@ @NotFound@ ");
    Integer userElement2Id = 0;
    if (importBudget.getUserElement2_ID() > 0)
        userElement2Id = importBudget.getUserElement2_ID();
    if (userElement2Id <= 0 && importBudget.getUserElement2_ID() <= 0 && importBudget.getUserElementValue2() != null) {
        Arrays.stream(acctSchemaElements).filter(acctSchemaElement -> MAcctSchemaElement.ELEMENTTYPE_UserElement2.equals(acctSchemaElement.getElementType())).forEach(acctSchemaElement -> {
            I_AD_Column column = acctSchemaElement.getAD_Column();
            MTable table = (MTable) column.getAD_Table();
            MColumn columnName = table.getColumn("Value");
            if (columnName == null)
                columnName = table.getColumn("Name");
            if (columnName != null)
                importBudget.setUserElement2_ID(getId(table.getTableName(), columnName.getColumnName() + "=?", trxName, importBudget.getUserElementValue2()));
        });
    }
    if (importBudget.getUserElement2_ID() <= 0 && importBudget.getUserElementValue2() != null)
        stringError.append("@UserElement2_ID@ @NotFound@ ");
    if (accountSchemaId <= 0)
        stringError.append("@C_AcctSchema_ID@ @NotFound@ ");
    if (budgetId <= 0)
        stringError.append("@GL_Budget_ID@ @NotFound@ ");
    if (accountId <= 0)
        stringError.append("@Account_ID@ @NotFound@ ");
    if (!stringError.toString().isEmpty() && stringError.toString().length() > 0) {
        importBudget.setI_ErrorMsg(Msg.parseTranslation(getCtx(), stringError.toString()));
        importBudget.saveEx();
    }
    importBudget.saveEx();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MAcctSchemaElement(org.compiere.model.MAcctSchemaElement) Arrays(java.util.Arrays) MProject(org.compiere.model.MProject) X_I_Budget(org.compiere.model.X_I_Budget) CLogger(org.compiere.util.CLogger) MJournalLine(org.compiere.model.MJournalLine) MJournalBatch(org.compiere.model.MJournalBatch) Env(org.compiere.util.Env) SimpleDateFormat(java.text.SimpleDateFormat) X_GL_Budget(org.compiere.model.X_GL_Budget) MCampaign(org.compiere.model.MCampaign) AtomicReference(java.util.concurrent.atomic.AtomicReference) MAcctSchema(org.compiere.model.MAcctSchema) ArrayList(java.util.ArrayList) MActivity(org.compiere.model.MActivity) MSalesRegion(org.compiere.model.MSalesRegion) BigDecimal(java.math.BigDecimal) Query(org.compiere.model.Query) DB(org.compiere.util.DB) Calendar(java.util.Calendar) MBPartner(org.compiere.model.MBPartner) Msg(org.compiere.util.Msg) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MElementValue(org.compiere.model.MElementValue) MPeriod(org.compiere.model.MPeriod) Trx(org.compiere.util.Trx) MJournal(org.compiere.model.MJournal) DateFormat(java.text.DateFormat) Timestamp(java.sql.Timestamp) X_C_SubAcct(org.compiere.model.X_C_SubAcct) Logger(java.util.logging.Logger) MColumn(org.compiere.model.MColumn) Date(java.sql.Date) I_AD_Column(org.compiere.model.I_AD_Column) List(java.util.List) MOrg(org.compiere.model.MOrg) AdempiereException(org.adempiere.exceptions.AdempiereException) X_A_Asset(org.compiere.model.X_A_Asset) MTable(org.compiere.model.MTable) MAccount(org.compiere.model.MAccount) MProduct(org.compiere.model.MProduct) I_I_Budget(org.compiere.model.I_I_Budget) MColumn(org.compiere.model.MColumn) MTable(org.compiere.model.MTable) I_AD_Column(org.compiere.model.I_AD_Column) MBPartner(org.compiere.model.MBPartner)

Example 2 with X_I_Budget

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

the class ImportBudget method createJournalLine.

/**
     * Create Journal Line
     * @param journal
     * @param documentNo
     * @param noOfMonth
     */
private void createJournalLine(MJournal journal, String documentNo, int noOfMonth) {
    AtomicInteger lines = new AtomicInteger();
    Arrays.stream(getBudget(documentNo, false, false)).forEach(importBudgetId -> {
        X_I_Budget importBudget = new X_I_Budget(getCtx(), importBudgetId, journal.get_TrxName());
        BigDecimal amount = (BigDecimal) importBudget.get_Value("Month_" + noOfMonth + "_Amt");
        BigDecimal quantity = (BigDecimal) importBudget.get_Value("Month_" + noOfMonth + "_Qty");
        if (amount != null && amount.compareTo(BigDecimal.ZERO) != 0) {
            MJournalLine journalLine = new MJournalLine(getCtx(), 0, journal.get_TrxName());
            journalLine.setGL_Journal_ID(journal.getGL_Journal_ID());
            if (amount.compareTo(BigDecimal.ZERO) < 0)
                journalLine.setAmtSourceCr(amount.abs());
            else
                journalLine.setAmtSourceDr(amount);
            if (quantity != null)
                journalLine.setQty(quantity);
            journalLine.setAD_Org_ID(journalLine.getParent().getAD_Org_ID());
            journalLine.setC_Currency_ID(journal.getC_Currency_ID());
            journalLine.setDateAcct(journalLine.getParent().getDateAcct());
            journalLine.setC_ConversionType_ID(journal.getC_ConversionType_ID());
            journalLine.setCurrencyRate(BigDecimal.ONE);
            journalLine.setLine(lines.get());
            journalLine.setDescription(importBudget.getJnl_Line_Description());
            lines.updateAndGet(line -> line + 1);
            if (importBudget.getA_Asset_ID() > 0) {
                journalLine.setA_Asset_ID(importBudget.getA_Asset_ID());
                journalLine.setA_CreateAsset(true);
            }
            MAccount account = MAccount.get(getCtx(), importBudget.getAD_Client_ID(), importBudget.getAD_Org_ID(), importBudget.getC_AcctSchema_ID(), importBudget.getAccount_ID(), importBudget.getC_SubAcct_ID(), importBudget.getM_Product_ID(), importBudget.getC_BPartner_ID(), importBudget.getAD_OrgTrx_ID(), importBudget.getC_LocFrom_ID(), importBudget.getC_LocTo_ID(), importBudget.getC_SalesRegion_ID(), importBudget.getC_Project_ID(), importBudget.getC_Campaign_ID(), importBudget.getC_Activity_ID(), importBudget.getUser1_ID(), importBudget.getUser2_ID(), importBudget.getUser3_ID(), importBudget.getUser4_ID(), importBudget.getUserElement1_ID(), importBudget.getUserElement2_ID(), journal.get_TrxName());
            account.saveEx();
            journalLine.setC_ValidCombination_ID(account.getC_ValidCombination_ID());
            journalLine.saveEx();
            importBudget.setI_IsImported(true);
            importBudget.setC_ValidCombination_ID(account.getC_ValidCombination_ID());
            importBudget.setGL_JournalBatch_ID(journal.getGL_JournalBatch_ID());
            importBudget.setGL_Journal_ID(journal.getGL_Journal_ID());
            importBudget.setGL_JournalLine_ID(journalLine.getGL_JournalLine_ID());
            importBudget.setProcessed(true);
            importBudget.saveEx();
        }
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MJournalLine(org.compiere.model.MJournalLine) MAccount(org.compiere.model.MAccount) X_I_Budget(org.compiere.model.X_I_Budget) BigDecimal(java.math.BigDecimal)

Example 3 with X_I_Budget

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

the class ImportBudget method validateBudget.

/**
     * Validate Quantity Check
     * @param budgetLinesIds
     */
private void validateBudget(int[] budgetLinesIds) {
    AtomicReference<BigDecimal> balance0 = new AtomicReference<>(BigDecimal.ZERO);
    AtomicReference<BigDecimal> balance1 = new AtomicReference<>(BigDecimal.ZERO);
    AtomicReference<BigDecimal> balance2 = new AtomicReference<>(BigDecimal.ZERO);
    AtomicReference<BigDecimal> balance3 = new AtomicReference<>(BigDecimal.ZERO);
    AtomicReference<BigDecimal> balance4 = new AtomicReference<>(BigDecimal.ZERO);
    AtomicReference<BigDecimal> balance5 = new AtomicReference<>(BigDecimal.ZERO);
    AtomicReference<BigDecimal> balance6 = new AtomicReference<>(BigDecimal.ZERO);
    AtomicReference<BigDecimal> balance7 = new AtomicReference<>(BigDecimal.ZERO);
    AtomicReference<BigDecimal> balance8 = new AtomicReference<>(BigDecimal.ZERO);
    AtomicReference<BigDecimal> balance9 = new AtomicReference<>(BigDecimal.ZERO);
    AtomicReference<BigDecimal> balance10 = new AtomicReference<>(BigDecimal.ZERO);
    AtomicReference<BigDecimal> balance11 = new AtomicReference<>(BigDecimal.ZERO);
    Arrays.stream(budgetLinesIds).forEach(importBudgetId -> {
        X_I_Budget importBudget = new X_I_Budget(getCtx(), importBudgetId, null);
        if (importBudget.getMonth_0_Amt().signum() != 0 && importBudget.getMonth_0_Qty().signum() != 0 && importBudget.getMonth_0_Amt() != importBudget.getMonth_0_Qty() || importBudget.getMonth_1_Amt().signum() != 0 && importBudget.getMonth_1_Qty().signum() != 0 && importBudget.getMonth_1_Amt() != importBudget.getMonth_1_Qty() || importBudget.getMonth_2_Amt().signum() != 0 && importBudget.getMonth_2_Qty().signum() != 0 && importBudget.getMonth_2_Amt() != importBudget.getMonth_2_Qty() || importBudget.getMonth_3_Amt().signum() != 0 && importBudget.getMonth_3_Qty().signum() != 0 && importBudget.getMonth_3_Amt() != importBudget.getMonth_3_Qty() || importBudget.getMonth_4_Amt().signum() != 0 && importBudget.getMonth_4_Qty().signum() != 0 && importBudget.getMonth_4_Amt() != importBudget.getMonth_4_Qty() || importBudget.getMonth_5_Amt().signum() != 0 && importBudget.getMonth_5_Qty().signum() != 0 && importBudget.getMonth_5_Amt() != importBudget.getMonth_5_Qty() || importBudget.getMonth_6_Amt().signum() != 0 && importBudget.getMonth_6_Qty().signum() != 0 && importBudget.getMonth_6_Amt() != importBudget.getMonth_6_Qty() || importBudget.getMonth_7_Amt().signum() != 0 && importBudget.getMonth_7_Qty().signum() != 0 && importBudget.getMonth_7_Amt() != importBudget.getMonth_7_Qty() || importBudget.getMonth_8_Amt().signum() != 0 && importBudget.getMonth_8_Qty().signum() != 0 && importBudget.getMonth_8_Amt() != importBudget.getMonth_8_Qty() || importBudget.getMonth_9_Amt().signum() != 0 && importBudget.getMonth_9_Qty().signum() != 0 && importBudget.getMonth_9_Amt() != importBudget.getMonth_9_Qty() || importBudget.getMonth_10_Amt().signum() != 0 && importBudget.getMonth_10_Qty().signum() != 0 && importBudget.getMonth_10_Amt() != importBudget.getMonth_10_Qty() || importBudget.getMonth_11_Amt().signum() != 0 && importBudget.getMonth_11_Qty().signum() != 0 && importBudget.getMonth_11_Amt() != importBudget.getMonth_11_Qty())
            throw new AdempiereException("Amount balance(DR-CR) of all journals are not zero");
        balance0.updateAndGet(balance -> balance.add(importBudget.getMonth_0_Amt()));
        balance1.updateAndGet(balance -> balance.add(importBudget.getMonth_1_Amt()));
        balance2.updateAndGet(balance -> balance.add(importBudget.getMonth_2_Amt()));
        balance3.updateAndGet(balance -> balance.add(importBudget.getMonth_3_Amt()));
        balance4.updateAndGet(balance -> balance.add(importBudget.getMonth_4_Amt()));
        balance5.updateAndGet(balance -> balance.add(importBudget.getMonth_5_Amt()));
        balance6.updateAndGet(balance -> balance.add(importBudget.getMonth_6_Amt()));
        balance7.updateAndGet(balance -> balance.add(importBudget.getMonth_7_Amt()));
        balance8.updateAndGet(balance -> balance.add(importBudget.getMonth_8_Amt()));
        balance9.updateAndGet(balance -> balance.add(importBudget.getMonth_9_Amt()));
        balance10.updateAndGet(balance -> balance.add(importBudget.getMonth_10_Amt()));
        balance11.updateAndGet(balance -> balance.add(importBudget.getMonth_11_Amt()));
    });
    if (balance0.get().compareTo(BigDecimal.ZERO) != 0 || balance1.get().compareTo(BigDecimal.ZERO) != 0 || balance2.get().compareTo(BigDecimal.ZERO) != 0 || balance3.get().compareTo(BigDecimal.ZERO) != 0 || balance4.get().compareTo(BigDecimal.ZERO) != 0 || balance5.get().compareTo(BigDecimal.ZERO) != 0 || balance6.get().compareTo(BigDecimal.ZERO) != 0 || balance7.get().compareTo(BigDecimal.ZERO) != 0 || balance8.get().compareTo(BigDecimal.ZERO) != 0 || balance9.get().compareTo(BigDecimal.ZERO) != 0 || balance10.get().compareTo(BigDecimal.ZERO) != 0 || balance11.get().compareTo(BigDecimal.ZERO) != 0)
        throw new AdempiereException("Amount balance(DR-CR) of all journals are not zero");
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) AtomicReference(java.util.concurrent.atomic.AtomicReference) X_I_Budget(org.compiere.model.X_I_Budget) BigDecimal(java.math.BigDecimal)

Example 4 with X_I_Budget

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

the class ImportBudget method doIt.

/**
     * Perform process.
     * @return Message
     * @throws Exception
     */
protected String doIt() throws Exception {
    // Validate Budget
    X_I_Budget importBudgetCurrent = new X_I_Budget(getCtx(), getRecord_ID(), null);
    int budgetId = importBudgetCurrent.getGL_Budget_ID();
    if (budgetId <= 0)
        budgetId = getId(X_GL_Budget.Table_Name, X_GL_Budget.COLUMNNAME_Name + "=?", get_TrxName(), importBudgetCurrent.getBudgetCode());
    if (budgetId <= 0)
        throw new AdempiereException("@GL_Budget_ID@ @NotFound@");
    else {
        importBudgetCurrent.setGL_Budget_ID(budgetId);
        importBudgetCurrent.saveEx();
    }
    MAcctSchema acctSchema = MAcctSchema.get(getCtx(), getAccountingSchemaId());
    MAcctSchemaElement[] acctSchemaElements = MAcctSchemaElement.getAcctSchemaElements(acctSchema);
    MPeriod period = MPeriod.get(getCtx(), acctSchema.getC_Period_ID());
    int glCategoryId = DB.getSQLValue(get_TrxName(), "SELECT GL_Category_ID FROM GL_Category WHERE Name = 'Manual'  AND AD_Client_ID =? ", Env.getAD_Client_ID(getCtx()));
    int currencyId = acctSchema.getC_Currency_ID();
    int docTypeId = DB.getSQLValue(get_TrxName(), "SELECT C_DocType_ID FROM C_DocType WHERE Name = 'GL Journal' AND AD_Client_ID =?", Env.getAD_Client_ID(getCtx()));
    int conversionTypeId = DB.getSQLValue(get_TrxName(), "SELECT C_ConversionType_ID FROM C_ConversionType WHERE Value =? ", "S");
    String documentNo = importBudgetCurrent.getBatchDocumentNo();
    int calendarId = period.getC_Calendar_ID();
    if (isDeleteoldimportedrecords())
        Arrays.stream(getBudget(documentNo, true, true)).forEach(importBudgetId -> {
            X_I_Budget importBudget = new X_I_Budget(getCtx(), importBudgetId, null);
            importBudget.deleteEx(true);
        });
    //Validation document
    int[] budgetLinesIds = getBudget(documentNo, false, false);
    validateBudget(budgetLinesIds);
    //AtomicInteger importedRecord = new AtomicInteger(0);
    //AtomicInteger withErrors = new AtomicInteger(0);
    Arrays.stream(budgetLinesIds).forEach(importBudgetId -> {
        Trx.run(trxName -> {
            X_I_Budget importBudget = new X_I_Budget(getCtx(), importBudgetId, trxName);
            importBudget.setI_ErrorMsg(null);
            fillIdValues(importBudget, acctSchemaElements, trxName);
        });
    });
    // Validate  have not Error
    Arrays.stream(budgetLinesIds).forEach(importBudgetId -> {
        X_I_Budget importBudget = new X_I_Budget(getCtx(), importBudgetId, null);
        if (importBudget.getI_ErrorMsg() != null)
            throw new AdempiereException("@GL_BudgetID@ @ProcessFailed@");
    });
    Trx.run(trxName -> generateJournalBatch(trxName, documentNo, glCategoryId, docTypeId, currencyId, conversionTypeId, calendarId, importBudgetCurrent.getGL_Budget_ID()));
    return "@Ok@";
}
Also used : MAcctSchemaElement(org.compiere.model.MAcctSchemaElement) Arrays(java.util.Arrays) MProject(org.compiere.model.MProject) X_I_Budget(org.compiere.model.X_I_Budget) CLogger(org.compiere.util.CLogger) MJournalLine(org.compiere.model.MJournalLine) MJournalBatch(org.compiere.model.MJournalBatch) Env(org.compiere.util.Env) SimpleDateFormat(java.text.SimpleDateFormat) X_GL_Budget(org.compiere.model.X_GL_Budget) MCampaign(org.compiere.model.MCampaign) AtomicReference(java.util.concurrent.atomic.AtomicReference) MAcctSchema(org.compiere.model.MAcctSchema) ArrayList(java.util.ArrayList) MActivity(org.compiere.model.MActivity) MSalesRegion(org.compiere.model.MSalesRegion) BigDecimal(java.math.BigDecimal) Query(org.compiere.model.Query) DB(org.compiere.util.DB) Calendar(java.util.Calendar) MBPartner(org.compiere.model.MBPartner) Msg(org.compiere.util.Msg) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MElementValue(org.compiere.model.MElementValue) MPeriod(org.compiere.model.MPeriod) Trx(org.compiere.util.Trx) MJournal(org.compiere.model.MJournal) DateFormat(java.text.DateFormat) Timestamp(java.sql.Timestamp) X_C_SubAcct(org.compiere.model.X_C_SubAcct) Logger(java.util.logging.Logger) MColumn(org.compiere.model.MColumn) Date(java.sql.Date) I_AD_Column(org.compiere.model.I_AD_Column) List(java.util.List) MOrg(org.compiere.model.MOrg) AdempiereException(org.adempiere.exceptions.AdempiereException) X_A_Asset(org.compiere.model.X_A_Asset) MTable(org.compiere.model.MTable) MAccount(org.compiere.model.MAccount) MProduct(org.compiere.model.MProduct) I_I_Budget(org.compiere.model.I_I_Budget) MAcctSchema(org.compiere.model.MAcctSchema) AdempiereException(org.adempiere.exceptions.AdempiereException) MPeriod(org.compiere.model.MPeriod) X_I_Budget(org.compiere.model.X_I_Budget) MAcctSchemaElement(org.compiere.model.MAcctSchemaElement)

Aggregations

BigDecimal (java.math.BigDecimal)4 X_I_Budget (org.compiere.model.X_I_Budget)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 AdempiereException (org.adempiere.exceptions.AdempiereException)3 MAccount (org.compiere.model.MAccount)3 MJournalLine (org.compiere.model.MJournalLine)3 Date (java.sql.Date)2 Timestamp (java.sql.Timestamp)2 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Calendar (java.util.Calendar)2 List (java.util.List)2 Logger (java.util.logging.Logger)2 I_AD_Column (org.compiere.model.I_AD_Column)2 I_I_Budget (org.compiere.model.I_I_Budget)2 MAcctSchema (org.compiere.model.MAcctSchema)2 MAcctSchemaElement (org.compiere.model.MAcctSchemaElement)2