/// <summary> /// Is used to create line against Income Account summary account -- /// </summary> /// <param name="Profit">class object of MProfitLoss </param> private void InsertProfitLossLine(MProfitLoss Profit) { // get consolidated profit amount agsint Organization String Sql = @"SELECT AD_Org_ID , (SUM(AccountDebit) - SUM(AccountCredit)) AS ProfitAmt FROM C_ProfitLossLines WHERE C_ProfitAndLoss_ID > 0 AND C_ProfitLoss_ID = " + Profit.GetC_ProfitLoss_ID() + @" GROUP BY AD_Org_ID"; DataSet dsProfit = DB.ExecuteDataset(Sql, null, Get_Trx()); if (dsProfit != null && dsProfit.Tables.Count > 0 && dsProfit.Tables[0].Rows.Count > 0) { // get max line no int lineNo = Convert.ToInt32(DB.ExecuteScalar(@"SELECT NVL(MAX(Line),0)+10 AS line FROM C_ProfitLossLines WHERE C_ProfitLoss_ID = " + Profit.GetC_ProfitLoss_ID(), null, Get_Trx())); // get Valid Combination against Income Summary Acct from accounting schema int validComID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT IncomeSummary_Acct FROM C_AcctSchema_GL WHERE C_AcctSchema_ID=" + Util.GetValueOfInt(Profit.Get_Value("C_AcctSchema_ID")))); // get account id MAccount acct = MAccount.Get(GetCtx(), validComID); for (int i = 0; i < dsProfit.Tables[0].Rows.Count; i++) { Decimal profitAmt = Util.GetValueOfDecimal(dsProfit.Tables[0].Rows[i]["ProfitAmt"]); // when difference of DR - CR is ZERO then not to create line if (profitAmt == 0) { continue; } MProfitLossLines profitLossLines = new MProfitLossLines(GetCtx(), 0, Get_Trx()); profitLossLines.SetAD_Client_ID(Profit.GetAD_Client_ID()); profitLossLines.SetAD_Org_ID(Util.GetValueOfInt(dsProfit.Tables[0].Rows[i]["AD_Org_ID"])); profitLossLines.SetC_ProfitLoss_ID(Profit.GetC_ProfitLoss_ID()); profitLossLines.SetLine(lineNo); profitLossLines.SetC_AcctSchema_ID(Util.GetValueOfInt(Profit.Get_Value("C_AcctSchema_ID"))); profitLossLines.SetPostingType(Util.GetValueOfString(Profit.Get_Value("PostingType"))); profitLossLines.SetAccount_ID(acct.GetAccount_ID()); profitLossLines.Set_Value("LedgerCode", acct.GetAccount().Get_Value("Value")); profitLossLines.Set_Value("LedgerName", acct.GetAccount().Get_Value("Name")); if (profitAmt > 0) { profitLossLines.SetAccountCredit(profitAmt); } else { profitLossLines.SetAccountDebit(profitAmt); } if (!profitLossLines.Save(Get_Trx())) { ValueNamePair pp = VLogger.RetrieveError(); log.Fine("Failed - Profit loss line not saved for income acct summary - " + (pp != null && !String.IsNullOrEmpty(pp.GetName()) ? pp.GetName() : "")); } else { lineNo += 10; } } } }