Search in sources :

Example 1 with MChargeAcct

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

the class ImportAccount method updateCharge.

//	doIt
private void updateCharge(X_I_ElementValue impEV, MElementValue ev) {
    MCharge charge = (MCharge) impEV.getC_Charge();
    if (charge.get_ID() == 0 && !Util.isEmpty(impEV.getChargeName())) {
        charge.setName(impEV.getChargeName());
        charge.setAD_Org_ID(0);
        if (impEV.getC_TaxCategory_ID() == 0) {
            String sql = "SELECT C_TaxCategory_ID FROM C_TaxCategory WHERE AD_Client_ID = ? ORDER BY IsDefault DESC ";
            int taxc = DB.getSQLValue(get_TrxName(), sql, m_AD_Client_ID);
            charge.setC_TaxCategory_ID(taxc);
        } else {
            charge.setC_TaxCategory_ID(impEV.getC_TaxCategory_ID());
        }
        charge.saveEx();
        impEV.setC_Charge_ID(charge.getC_Charge_ID());
    }
    // add/update charge accounting 
    if (ev != null && !charge.is_new()) {
        // for accounting schemas
        for (MAcctSchema schema : MAcctSchema.getClientAcctSchema(getCtx(), m_AD_Client_ID)) {
            // with the same Account Element as the import
            if (schema.getAcctSchemaElement(MAcctSchemaElement.ELEMENTTYPE_Account).getC_Element_ID() == ev.getC_Element_ID()) {
                MChargeAcct chargeacct = MChargeAcct.get(schema, charge.getC_Charge_ID(), get_TrxName());
                if (chargeacct == null) {
                    chargeacct = new MChargeAcct(getCtx(), 0, get_TrxName());
                    chargeacct.setAD_Org_ID(charge.getAD_Org_ID());
                    chargeacct.setC_AcctSchema_ID(schema.getC_AcctSchema_ID());
                    chargeacct.setC_Charge_ID(charge.getC_Charge_ID());
                }
                MAccount expenseAccount = (MAccount) chargeacct.getCh_Expense_A();
                if (expenseAccount == null) {
                    //  optional null
                    expenseAccount = MAccount.getDefault(schema, true);
                }
                if (expenseAccount.getAccount_ID() != ev.getC_ElementValue_ID()) {
                    MAccount account = MAccount.get(Env.getCtx(), charge.getAD_Client_ID(), charge.getAD_Org_ID(), schema.getC_AcctSchema_ID(), ev.getC_ElementValue_ID(), expenseAccount.getC_SubAcct_ID(), expenseAccount.getM_Product_ID(), expenseAccount.getC_BPartner_ID(), expenseAccount.getAD_OrgTrx_ID(), expenseAccount.getC_LocFrom_ID(), expenseAccount.getC_LocTo_ID(), expenseAccount.getC_SalesRegion_ID(), expenseAccount.getC_Project_ID(), expenseAccount.getC_Campaign_ID(), expenseAccount.getC_Activity_ID(), expenseAccount.getUser1_ID(), expenseAccount.getUser2_ID(), expenseAccount.getUser3_ID(), expenseAccount.getUser4_ID(), expenseAccount.getUserElement1_ID(), expenseAccount.getUserElement2_ID(), get_TrxName());
                    chargeacct.setCh_Expense_Acct(account.getC_ValidCombination_ID());
                }
                MAccount revenueAccount = (MAccount) chargeacct.getCh_Revenue_A();
                if (revenueAccount == null) {
                    //  optional null
                    revenueAccount = MAccount.getDefault(schema, true);
                }
                if (revenueAccount.getAccount_ID() != ev.getC_ElementValue_ID()) {
                    MAccount account = MAccount.get(Env.getCtx(), charge.getAD_Client_ID(), charge.getAD_Org_ID(), schema.getC_AcctSchema_ID(), ev.getC_ElementValue_ID(), revenueAccount.getC_SubAcct_ID(), revenueAccount.getM_Product_ID(), revenueAccount.getC_BPartner_ID(), revenueAccount.getAD_OrgTrx_ID(), revenueAccount.getC_LocFrom_ID(), revenueAccount.getC_LocTo_ID(), revenueAccount.getC_SalesRegion_ID(), revenueAccount.getC_Project_ID(), revenueAccount.getC_Campaign_ID(), revenueAccount.getC_Activity_ID(), revenueAccount.getUser1_ID(), revenueAccount.getUser2_ID(), revenueAccount.getUser3_ID(), revenueAccount.getUser4_ID(), revenueAccount.getUserElement1_ID(), revenueAccount.getUserElement2_ID(), get_TrxName());
                    chargeacct.setCh_Revenue_Acct(account.getC_ValidCombination_ID());
                }
                chargeacct.saveEx();
            }
        }
    }
}
Also used : MAcctSchema(org.compiere.model.MAcctSchema) MAccount(org.compiere.model.MAccount) MCharge(org.compiere.model.MCharge) MChargeAcct(org.compiere.model.MChargeAcct)

Aggregations

MAccount (org.compiere.model.MAccount)1 MAcctSchema (org.compiere.model.MAcctSchema)1 MCharge (org.compiere.model.MCharge)1 MChargeAcct (org.compiere.model.MChargeAcct)1