/// <summary> /// Process /// </summary> /// <returns></returns> protected override string DoIt() { try { MRevenueRecognitionPlan revenueRecognitionPlan = null; MInvoiceLine invoiceLine = null; MInvoice invoice = null; MRevenueRecognition mRevenueRecognition = new MRevenueRecognition(GetCtx(), _RevenueRecognition_ID, Get_Trx()); // Count of previous date's RevenueRecognition_Run whose journal is not created string sql = "SELECT COUNT(C_RevenueRecognition_Run_ID) FROM C_RevenueRecognition_Run run " + "INNER JOIN C_RevenueRecognition_Plan pl ON pl.C_RevenueRecognition_Plan_ID = run.C_RevenueRecognition_Plan_ID WHERE "; if (C_InvoiceLine_ID > 0) { sql += "pl.C_invoiceLine_ID = " + C_InvoiceLine_ID + " AND "; } sql += "pl.C_RevenueRecognition_ID = " + _RevenueRecognition_ID + " AND NVL(GL_Journal_ID, 0)<=0 AND run.RECOGNITIONDATE < " + GlobalVariable.TO_DATE(DateTime.Now, true); if (Util.GetValueOfInt(DB.ExecuteScalar(sql)) == 0) { MRevenueRecognitionPlan[] revenueRecognitionPlans = MRevenueRecognitionPlan.GetRecognitionPlans(mRevenueRecognition, C_InvoiceLine_ID, _orgId); journal_ID = new int[revenueRecognitionPlans.Length]; if (ReversalType == "P") { for (int i = 0; i < revenueRecognitionPlans.Length; i++) { revenueRecognitionPlan = revenueRecognitionPlans[i]; invoiceLine = new MInvoiceLine(GetCtx(), revenueRecognitionPlan.GetC_InvoiceLine_ID(), Get_Trx()); invoice = new MInvoice(GetCtx(), invoiceLine.GetC_Invoice_ID(), Get_Trx()); //get Sum of Amount Whose journal is not yet created sql = "SELECT SUM(run.Recognizedamt) AS TotalRecognizedAmt FROM C_RevenueRecognition_Run run WHERE " + "C_RevenueRecognition_Plan_ID = " + revenueRecognitionPlan.GetC_RevenueRecognition_Plan_ID() + " AND NVL(GL_Journal_ID,0) <= 0"; totalAmt = Util.GetValueOfInt(DB.ExecuteScalar(sql)); if (totalAmt != 0) { //if totalAmount is not 0 then only create Journal if (revenueRecognitionPlan.GetC_AcctSchema_ID() != _AcctSchema_ID || revenueRecognitionPlan.GetC_Currency_ID() != _Currency_ID) { if (journal != null) { if (DocNo == null) { DocNo = journal.GetDocumentNo(); } else { DocNo += "," + journal.GetDocumentNo(); } journal_ID[i - 1] = journal.GetGL_Journal_ID(); } journal = new MJournal(GetCtx(), 0, Get_Trx()); journal.SetC_DocType_ID(_DocType); journal = CreateJournalHDR(revenueRecognitionPlan); if (journal.Save(Get_TrxName())) { _AcctSchema_ID = journal.GetC_AcctSchema_ID(); _Currency_ID = journal.GetC_Currency_ID(); lineno = Util.GetValueOfInt(DB.ExecuteScalar("SELECT NVL(MAX(Line), 0)+10 AS DefaultValue FROM GL_JournalLine WHERE GL_Journal_ID=" + journal.GetGL_Journal_ID(), null, invoice.Get_Trx())); } else { pp = VLogger.RetrieveError(); if (pp != null) { errorMsg = pp.GetName(); if (errorMsg == "") { errorMsg = pp.GetValue(); } } if (errorMsg == "") { errorMsg = Msg.GetMsg(GetCtx(), "GLJournalNotCreated"); } Get_TrxName().Rollback(); return(errorMsg); } } revenueRecognitionPlan.SetRecognizedAmt(totalAmt + revenueRecognitionPlan.GetRecognizedAmt()); if (!revenueRecognitionPlan.Save()) { pp = VLogger.RetrieveError(); if (pp != null) { errorMsg = pp.GetName(); if (errorMsg == "") { errorMsg = pp.GetValue(); } } if (errorMsg == "") { errorMsg = Msg.GetMsg(GetCtx(), "GLJournalNotCreated"); } Get_TrxName().Rollback(); return(errorMsg); } for (int k = 0; k < 2; k++) { journalLine = new MJournalLine(journal); journalLine = GenerateJounalLine(journal, invoice, invoiceLine, revenueRecognitionPlan, totalAmt, mRevenueRecognition.GetRecognitionType(), k); if (journalLine.Save(Get_TrxName())) { lineno += 10; } else { pp = VLogger.RetrieveError(); if (pp != null) { errorMsg = pp.GetName(); if (errorMsg == "") { errorMsg = pp.GetValue(); } } if (errorMsg == "") { errorMsg = Msg.GetMsg(GetCtx(), "GLJournalNotCreated"); } Get_TrxName().Rollback(); return(errorMsg); } } sql = "UPDATE C_RevenueRecognition_Run set Gl_Journal_ID= " + journal.GetGL_Journal_ID() + " WHERE C_RevenueRecognition_Plan_ID= " + revenueRecognitionPlan.GetC_RevenueRecognition_Plan_ID() + "AND NVL(Gl_Journal_ID,0)=0"; int count = DB.ExecuteQuery(sql, null, Get_Trx()); log.Log(Level.INFO, (Msg.GetMsg(GetCtx(), "RevenueRecognitionRunUpdated") + count)); } } if (journal != null) { if (DocNo == null) { DocNo = journal.GetDocumentNo(); } else { DocNo += "," + journal.GetDocumentNo(); } journal_ID[journal_ID.Length - 1] = journal.GetGL_Journal_ID(); } } #region Existing Reversal Type //else if (ReversalType == "E") //{ // for (int i = 0; i < revenueRecognitionPlans.Length; i++) // { // MRevenueRecognitionPlan revenueRecognitionPlan = revenueRecognitionPlans[i]; // MInvoiceLine invoiceLine = new MInvoiceLine(GetCtx(), revenueRecognitionPlan.GetC_InvoiceLine_ID(), Get_Trx()); // MInvoice invoice = new MInvoice(GetCtx(), invoiceLine.GetC_Invoice_ID(), Get_Trx()); // sql = "Select Distinct round(SUM(recognizedamt),5) as RecognizedAmt from C_RevenueRecognition_Run Where C_RevenueRecognition_Plan_ID = " + revenueRecognitionPlan.GetC_RevenueRecognition_Plan_ID() + " And NVL(GL_Journal_ID,0) > 0 "; // DataSet ds = new DataSet(); // ds = DB.ExecuteDataset(sql); // if (ds != null && ds.Tables[0].Rows.Count > 0) // { // decimal Amt = Util.GetValueOfDecimal(ds.Tables[0].Rows[i]["RecognizedAmt"]); // string sql1 = "Select GL_Journal_ID from C_RevenueRecognition_Run Where C_RevenueRecognition_Plan_ID = " + revenueRecognitionPlan.GetC_RevenueRecognition_Plan_ID() + " And NVL(GL_Journal_ID,0) > 0 AND RowNum=1"; // int GL_Journal_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql1)); // MJournal journal = new MJournal(GetCtx(), GL_Journal_ID, Get_TrxName()); // log.Info(ToString()); // // Journal // MJournal reverse = new MJournal(journal); // reverse.SetDateDoc(DateTime.Now); // reverse.SetC_Period_ID(journal.GetC_Period_ID()); // int Period_ID = MPeriod.GetC_Period_ID(GetCtx(), DateTime.Now); // reverse.SetDateAcct(DateTime.Now); // if (reverse.Save()) // { // MJournalLine[] journalLines = journal.GetLines(false); // if (journalLines.Length > 0) // { // for (int j = 0; j < journalLines.Length; j++) // { // MJournalLine journalLine = journalLines[j]; // MJournalLine newjournalLine = new MJournalLine(GetCtx(), 0, Get_TrxName()); // PO.CopyValues(journalLine, newjournalLine, GetAD_Client_ID(), GetAD_Org_ID()); // newjournalLine.SetGL_Journal_ID(reverse.GetGL_Journal_ID()); // newjournalLine.SetDateAcct(DateTime.Now); // // Amounts // if (newjournalLine.GetAmtAcctCr() > 0) // { // newjournalLine.SetAmtAcctDr(0); // newjournalLine.SetAmtSourceDr(0); // newjournalLine.SetAmtSourceCr(Decimal.Negate(Amt)); // newjournalLine.SetAmtAcctCr(Decimal.Negate(Amt)); // } // else // { // newjournalLine.SetAmtAcctDr(Decimal.Negate(Amt)); // newjournalLine.SetAmtSourceDr(Decimal.Negate(Amt)); // newjournalLine.SetAmtSourceCr(0); // newjournalLine.SetAmtAcctCr(0); // } // newjournalLine.SetIsGenerated(true); // newjournalLine.SetProcessed(false); // newjournalLine.Save(); // if (j == 1) // { // break; // } // } // } // } // if (reverse != null && reverse.GetDocStatus() != "CO") // { // reverse.CompleteIt(); // reverse.SetProcessed(true); // reverse.SetDocStatus("CO"); // reverse.SetDocAction("CL"); // reverse.Save(Get_TrxName()); // if (DocNo == null) // { // DocNo = reverse.GetDocumentNo(); // } // int count = Util.GetValueOfInt(DB.ExecuteQuery("Update C_RevenueRecognition_Run Set GL_Journal_ID=null WHere C_RevenueRecognition_Plan_ID=" + revenueRecognitionPlan.GetC_RevenueRecognition_Plan_ID())); // int count1 = Util.GetValueOfInt(DB.ExecuteQuery("Update C_RevenueRecognition_Plan Set RecognizedAmt=RecognizedAmt - " + Amt + " WHere C_RevenueRecognition_Plan_ID=" + revenueRecognitionPlan.GetC_RevenueRecognition_Plan_ID())); // } // } // } //} #endregion Get_TrxName().Commit(); if (journal_ID != null) { for (int i = 0; i < journal_ID.Length; i++) { if (journal_ID[i] > 0) { string result = RevenueRun.CompleteOrReverse(GetCtx(), journal_ID[i], 169, "CO"); if (!String.IsNullOrEmpty(result)) { journalIDS += ", " + journal_ID[i] + " " + result; } } } } if (DocNo == null) { return(Msg.GetMsg(GetCtx(), "FoundNoRevenueRecognitionPlan")); } } else { return(Msg.GetMsg(GetCtx(), "NotRecoganized")); } } catch (Exception ex) { log.Log(Level.SEVERE, Msg.GetMsg(GetCtx(), "GLJournalnotallocateddueto") + ex.Message); Get_TrxName().Rollback(); return(ex.Message); } if (!String.IsNullOrEmpty(journalIDS)) { return(Msg.GetMsg(GetCtx(), "GLJournalCreated") + DocNo + ", " + Msg.GetMsg(GetCtx(), "GLJournalNotCompleted") + journalIDS); } else { return(Msg.GetMsg(GetCtx(), "GLJournalCreated") + DocNo); } }
public string createJournals(MRevenueRecognition mRevenueRecognition) { try { MRevenueRecognitionPlan[] revenueRecognitionPlans = MRevenueRecognitionPlan.GetRecognitionPlans(mRevenueRecognition, 0); MRevenueRecognitionRun[] mRevenueRecognitionRuns = null; for (int i = 0; i < revenueRecognitionPlans.Length; i++) { MRevenueRecognitionPlan revenueRecognitionPlan = revenueRecognitionPlans[i]; VAdvantage.Model.MInvoiceLine invoiceLine = new VAdvantage.Model.MInvoiceLine(GetCtx(), revenueRecognitionPlan.GetC_InvoiceLine_ID(), Get_Trx()); MInvoice invoice = new MInvoice(GetCtx(), invoiceLine.GetC_Invoice_ID(), Get_Trx()); mRevenueRecognitionRuns = MRevenueRecognitionRun.GetRecognitionRuns(revenueRecognitionPlan, _RecognitionDate, true); if (mRevenueRecognitionRuns.Length > 0) { for (int j = 0; j < mRevenueRecognitionRuns.Length; j++) { MRevenueRecognitionRun revenueRecognitionRun = mRevenueRecognitionRuns[j]; if (_DocType == "GL") { if (revenueRecognitionPlan.GetC_AcctSchema_ID() != _AcctSchema_ID || revenueRecognitionPlan.GetC_Currency_ID() != _Currency_ID || revenueRecognitionRun.GetINT15_RecognitionDate() != _RecognizeDate) { if (journal != null && journal.CompleteIt() == "CO") { journal.SetProcessed(true); journal.SetDocStatus("CO"); journal.SetDocAction("CL"); journal.Save(Get_Trx()); if (DocNo == null) { DocNo = journal.GetDocumentNo(); } else { DocNo += "," + journal.GetDocumentNo(); } } journal = new VAdvantage.Model.MJournal(GetCtx(), 0, Get_Trx()); journal = CreateJournalHDR(revenueRecognitionPlan, revenueRecognitionRun); #region Commented Code for Journal Batch //else if (_DocType == "GB") //{ // VAdvantage.Model.MJournalBatch journalBatch = new VAdvantage.Model.MJournalBatch(GetCtx(), 0, Get_Trx()); // journalBatch.SetClientOrg(revenueRecognitionPlan); // journalBatch.SetDescription("Revenue Recognition Run"); // journalBatch.SetPostingType("A"); // journalBatch.SetDateDoc(_RecognitionDate); // journalBatch.SetDateAcct(_RecognitionDate); // journalBatch.SetC_Period_ID(C_Period_ID); // int C_Doctype_ID = Util.GetValueOfInt(DB.ExecuteScalar("Select C_Doctype_ID From C_Doctype Where DocBaseType='GLJ'")); // journalBatch.SetC_DocType_ID(C_Doctype_ID); // journalBatch.SetC_Currency_ID(revenueRecognitionPlan.GetC_Currency_ID()); // journalBatch.SetTotalCr(revenueRecognitionPlan.GetTotalAmt()); // journalBatch.SetTotalDr(revenueRecognitionPlan.GetTotalAmt()); // journalBatch.SetDocStatus("DR"); // journalBatch.SetDocAction("CO"); // if (journalBatch.Save()) // { // if (revenueRecognitionPlan.GetC_AcctSchema_ID() != _AcctSchema_ID || revenueRecognitionPlan.GetC_Currency_ID() != _Currency_ID) // { // journal = new VAdvantage.Model.MJournal(journalBatch); // journal = CreateJournalHDR(mRevenueRecognition, revenueRecognitionPlan); // } // } //} #endregion if (journal.Save()) { _AcctSchema_ID = journal.GetC_AcctSchema_ID(); _Currency_ID = journal.GetC_Currency_ID(); _RecognizeDate = revenueRecognitionRun.GetINT15_RecognitionDate(); } } for (int k = 0; k < 2; k++) { journalLine = new VAdvantage.Model.MJournalLine(journal); journalLine = GenerateJounalLine(journal, invoice, invoiceLine, revenueRecognitionPlan, revenueRecognitionRun, mRevenueRecognition.GetINT15_RecognizeType(), k); if (journalLine.Save()) { revenueRecognitionRun.SetGL_Journal_ID(journal.GetGL_Journal_ID()); revenueRecognitionRun.Save(); } } revenueRecognitionPlan.SetRecognizedAmt(revenueRecognitionRun.GetRecognizedAmt() + revenueRecognitionPlan.GetRecognizedAmt()); revenueRecognitionPlan.Save(); } } } } if (journal != null && journal.GetDocStatus() != "CO") { journal.CompleteIt(); journal.SetProcessed(true); journal.SetDocStatus("CO"); journal.SetDocAction("CL"); journal.Save(Get_Trx()); if (DocNo == null) { DocNo = journal.GetDocumentNo(); } else { DocNo += "," + journal.GetDocumentNo(); } } } catch (Exception ex) { log.Log(Level.SEVERE, "GL Journal not allocated due to " + ex); return(ex.ToString()); } if (DocNo == null) { DocNo = "0"; } return(Msg.GetMsg(GetCtx(), "INT15_GLJournalCreated = " + DocNo)); }
/// <summary> /// Revenue Recognition. /// Called from FactLine.save /// <p> /// Create Revenue recognition plan and return Unearned Revenue account /// to be used instead of Revenue Account. If not found, it returns /// the revenue account. /// </summary> /// <param name="C_RevenueRecognition_ID">revenue recognition</param> /// <param name="C_InvoiceLine_ID">invoice line</param> /// <param name="AD_Client_ID">client</param> /// <param name="AD_Org_ID">Org</param> /// <param name="AD_User_ID">user</param> /// <param name="Account_ID">of Revenue Account</param> /// <param name="C_SubAcct_ID"> sub account</param> /// <param name="M_Product_ID">product</param> /// <param name="C_BPartner_ID">bpartner</param> /// <param name="AD_OrgTrx_ID"> trx org</param> /// <param name="C_LocFrom_ID">loc from</param> /// <param name="C_LocTo_ID">loc to</param> /// <param name="C_SRegion_ID">sales region</param> /// <param name="C_Project_ID">project</param> /// <param name="C_Campaign_ID">campaign</param> /// <param name="C_Activity_ID">activity</param> /// <param name="User1_ID"></param> /// <param name="User2_ID"></param> /// <param name="UserElement1_ID">user element 1</param> /// <param name="UserElement2_ID">user element 2</param> /// <returns></returns> private int CreateRevenueRecognition( int C_RevenueRecognition_ID, int C_InvoiceLine_ID, int AD_Client_ID, int AD_Org_ID, int AD_User_ID, int Account_ID, int C_SubAcct_ID, int M_Product_ID, int C_BPartner_ID, int AD_OrgTrx_ID, int C_LocFrom_ID, int C_LocTo_ID, int C_SRegion_ID, int C_Project_ID, int C_Campaign_ID, int C_Activity_ID, int User1_ID, int User2_ID, int UserElement1_ID, int UserElement2_ID) { log.Fine("From Accout_ID=" + Account_ID); // get VC for P_Revenue (from Product) MAccount revenue = MAccount.Get(GetCtx(), AD_Client_ID, AD_Org_ID, GetC_AcctSchema_ID(), Account_ID, C_SubAcct_ID, M_Product_ID, C_BPartner_ID, AD_OrgTrx_ID, C_LocFrom_ID, C_LocTo_ID, C_SRegion_ID, C_Project_ID, C_Campaign_ID, C_Activity_ID, User1_ID, User2_ID, UserElement1_ID, UserElement2_ID); if (revenue != null && revenue.Get_ID() == 0) { revenue.Save(); } if (revenue == null || revenue.Get_ID() == 0) { log.Severe("Revenue_Acct not found"); return(Account_ID); } int P_Revenue_Acct = revenue.Get_ID(); // get Unearned Revenue Acct from BPartner Group int unearnedRevenue_Acct = 0; int new_Account_ID = 0; String sql = "SELECT ga.UnearnedRevenue_Acct, vc.Account_ID " + "FROM C_BP_Group_Acct ga, C_BPartner p, C_ValidCombination vc " + "WHERE ga.C_BP_Group_ID=p.C_BP_Group_ID" + " AND ga.UnearnedRevenue_Acct=vc.C_ValidCombination_ID" + " AND ga.C_AcctSchema_ID=" + GetC_AcctSchema_ID() + " AND p.C_BPartner_ID=" + C_BPartner_ID; IDataReader idr = null; try { idr = DataBase.DB.ExecuteReader(sql, null, Get_TrxName()); if (idr.Read()) { unearnedRevenue_Acct = Utility.Util.GetValueOfInt(idr[0]); ///.getInt(1); new_Account_ID = Utility.Util.GetValueOfInt(idr[1]); //.getInt(2); } idr.Close(); } catch (Exception e) { if (idr != null) { idr.Close(); } log.Log(Level.SEVERE, sql, e); } if (new_Account_ID == 0) { log.Severe("UnearnedRevenue_Acct not found"); return(Account_ID); } MRevenueRecognitionPlan plan = new MRevenueRecognitionPlan(GetCtx(), 0, null); plan.SetC_RevenueRecognition_ID(C_RevenueRecognition_ID); plan.SetC_AcctSchema_ID(GetC_AcctSchema_ID()); plan.SetC_InvoiceLine_ID(C_InvoiceLine_ID); plan.SetUnEarnedRevenue_Acct(unearnedRevenue_Acct); plan.SetP_Revenue_Acct(P_Revenue_Acct); plan.SetC_Currency_ID(GetC_Currency_ID()); plan.SetTotalAmt(GetAcctBalance()); if (!plan.Save(Get_TrxName())) { log.Severe("Plan NOT created"); return(Account_ID); } log.Fine("From Acctount_ID=" + Account_ID + " to " + new_Account_ID + " - Plan from UnearnedRevenue_Acct=" + unearnedRevenue_Acct + " to Revenue_Acct=" + P_Revenue_Acct); return(new_Account_ID); }
protected override string DoIt() { try { MRevenueRecognition mRevenueRecognition = new MRevenueRecognition(GetCtx(), _RevenueRecognition_ID, Get_Trx()); MRevenueRecognitionPlan[] revenueRecognitionPlans = MRevenueRecognitionPlan.GetRecognitionPlans(mRevenueRecognition, C_InvoiceLine_ID); for (int i = 0; i < revenueRecognitionPlans.Length; i++) { MRevenueRecognitionPlan revenueRecognitionPlan = revenueRecognitionPlans[i]; VAdvantage.Model.MInvoiceLine invoiceLine = new VAdvantage.Model.MInvoiceLine(GetCtx(), revenueRecognitionPlan.GetC_InvoiceLine_ID(), Get_Trx()); MInvoice invoice = new MInvoice(GetCtx(), invoiceLine.GetC_Invoice_ID(), Get_Trx()); MRevenueRecognitionRun[] mRevenueRecognitionRuns = MRevenueRecognitionRun.GetRecognitionRuns(revenueRecognitionPlan, _RecognitionDate, false); if (mRevenueRecognitionRuns.Length > 0) { if (_DocType == "GL") { if (revenueRecognitionPlan.GetC_AcctSchema_ID() != _AcctSchema_ID || revenueRecognitionPlan.GetC_Currency_ID() != _Currency_ID) { if (journal != null && journal.CompleteIt() == "CO") { journal.SetProcessed(true); journal.SetDocStatus("CO"); journal.SetDocAction("CL"); journal.Save(Get_Trx()); if (DocNo == null) { DocNo = journal.GetDocumentNo(); } else { DocNo += "," + journal.GetDocumentNo(); } } journal = new VAdvantage.Model.MJournal(GetCtx(), 0, Get_Trx()); journal = CreateJournalHDR(mRevenueRecognition, revenueRecognitionPlan); journal.Save(); _AcctSchema_ID = journal.GetC_AcctSchema_ID(); _Currency_ID = journal.GetC_Currency_ID(); decimal totalAmt = 0; for (int j = 0; j < mRevenueRecognitionRuns.Length; j++) { MRevenueRecognitionRun revenueRecognitionRun = mRevenueRecognitionRuns[j]; totalAmt += revenueRecognitionRun.GetRecognizedAmt(); revenueRecognitionRun.SetGL_Journal_ID(journal.GetGL_Journal_ID()); revenueRecognitionRun.Save(); } revenueRecognitionPlan.SetRecognizedAmt(totalAmt + revenueRecognitionPlan.GetRecognizedAmt()); revenueRecognitionPlan.Save(); for (int k = 0; k < 2; k++) { journalLine = new VAdvantage.Model.MJournalLine(journal); int combination_ID = 0; if (k == 0) { if (mRevenueRecognition.GetINT15_RecognizeType() == "R") { combination_ID = revenueRecognitionPlan.GetUnEarnedRevenue_Acct(); //journalLine.SetC_ValidCombination_ID(combination_ID); } else { combination_ID = revenueRecognitionPlan.GetINT15_ProductExpense(); //journalLine.SetC_ValidCombination_ID(combination_ID); } journalLine.SetAmtAcctDr(totalAmt); journalLine.SetAmtSourceDr(totalAmt); journalLine.SetAmtSourceCr(0); journalLine.SetAmtAcctCr(0); } else { if (mRevenueRecognition.GetINT15_RecognizeType() == "R") { combination_ID = revenueRecognitionPlan.GetP_Revenue_Acct(); //journalLine.SetC_ValidCombination_ID(combination_ID); } else { combination_ID = revenueRecognitionPlan.GetINT15_PrepaidExpense(); //journalLine.SetC_ValidCombination_ID(combination_ID); } journalLine.SetAmtAcctDr(0); journalLine.SetAmtSourceDr(0); journalLine.SetAmtSourceCr(totalAmt); journalLine.SetAmtAcctCr(totalAmt); } int account_ID = Util.GetValueOfInt(DB.ExecuteScalar("Select Account_ID From C_ValidCombination Where C_ValidCombination_ID=" + combination_ID)); VAdvantage.Model.MElementValue elementValue = new VAdvantage.Model.MElementValue(GetCtx(), account_ID, Get_Trx()); try { journalLine.Set_ValueNoCheck("Account_ID", account_ID); journalLine.Set_ValueNoCheck("C_BPartner_ID", invoice.GetC_BPartner_ID()); journalLine.Set_ValueNoCheck("M_Product_ID", invoiceLine.GetM_Product_ID()); } catch (Exception ex) { } journalLine.Save(); } } } } } if (journal != null && journal.GetDocStatus() != "CO") { if (journal.CompleteIt() == "CO") { journal.SetProcessed(true); journal.SetDocStatus("CO"); journal.SetDocAction("CL"); journal.Save(Get_Trx()); if (DocNo == null) { DocNo = journal.GetDocumentNo(); } else { DocNo += "," + journal.GetDocumentNo(); } } } } catch (Exception ex) { log.Log(Level.SEVERE, "GL Journal not allocated due to " + ex); return(ex.ToString()); } return(Msg.GetMsg(GetCtx(), "INT15_GLJournalCreated = " + DocNo)); }
/// <summary> /// Create GL Journal /// </summary> /// <param name="mRevenueRecognition">Revenue Recognition</param> /// <returns>Message</returns> public string CreateJournals(MRevenueRecognition mRevenueRecognition) { try { MRevenueRecognitionRun[] mRevenueRecognitionRuns = null; MRevenueRecognitionPlan revenueRecognitionPlan = null; MInvoiceLine invoiceLine = null; MInvoice invoice = null; mRevenueRecognitionRuns = MRevenueRecognitionRun.GetRecognitionRuns(mRevenueRecognition, _RecognitionDate, _orgId, false); journal_ID = new int[mRevenueRecognitionRuns.Length]; if (mRevenueRecognitionRuns.Length > 0) { for (int j = 0; j < mRevenueRecognitionRuns.Length; j++) { MRevenueRecognitionRun revenueRecognitionRun = mRevenueRecognitionRuns[j]; revenueRecognitionPlan = new MRevenueRecognitionPlan(GetCtx(), revenueRecognitionRun.GetC_RevenueRecognition_Plan_ID(), Get_TrxName()); invoiceLine = new MInvoiceLine(GetCtx(), revenueRecognitionPlan.GetC_InvoiceLine_ID(), Get_TrxName()); invoice = new MInvoice(GetCtx(), invoiceLine.GetC_Invoice_ID(), Get_TrxName()); if (revenueRecognitionPlan.GetC_AcctSchema_ID() != _AcctSchema_ID || revenueRecognitionPlan.GetC_Currency_ID() != _Currency_ID || revenueRecognitionRun.GetRecognitionDate() != _RecognizeDate) { if (journal != null) { if (DocNo == null) { DocNo = journal.GetDocumentNo(); } else { DocNo += ", " + journal.GetDocumentNo(); } journal_ID[j - 1] = journal.GetGL_Journal_ID(); } journal = new MJournal(GetCtx(), 0, Get_TrxName()); journal.SetC_DocType_ID(_DocType); journal = CreateJournalHDR(revenueRecognitionPlan, revenueRecognitionRun, mRevenueRecognition.GetRecognitionFrequency()); if (journal.Save()) { _AcctSchema_ID = journal.GetC_AcctSchema_ID(); _Currency_ID = journal.GetC_Currency_ID(); _RecognizeDate = revenueRecognitionRun.GetRecognitionDate(); lineno = Util.GetValueOfInt(DB.ExecuteScalar("SELECT NVL(MAX(Line), 0)+10 AS DefaultValue FROM GL_JournalLine WHERE GL_Journal_ID=" + journal.GetGL_Journal_ID(), null, invoice.Get_Trx())); } else { pp = VLogger.RetrieveError(); if (pp != null) { errorMsg = pp.GetName(); if (errorMsg == "") { errorMsg = pp.GetValue(); } } if (errorMsg == "") { errorMsg = Msg.GetMsg(GetCtx(), "GLJournalNotCreated"); } Get_TrxName().Rollback(); return(errorMsg); } } for (int k = 0; k < 2; k++) { journalLine = new MJournalLine(journal); journalLine = GenerateJounalLine(journal, invoice, invoiceLine, revenueRecognitionPlan, revenueRecognitionRun, mRevenueRecognition.GetRecognitionType(), k); if (journalLine.Save()) { revenueRecognitionRun.SetGL_Journal_ID(journal.GetGL_Journal_ID()); revenueRecognitionRun.Save(); lineno += 10; } else { pp = VLogger.RetrieveError(); if (pp != null) { errorMsg = pp.GetName(); if (errorMsg == "") { errorMsg = pp.GetValue(); } } if (errorMsg == "") { errorMsg = Msg.GetMsg(GetCtx(), "GLJournalNotCreated"); } Get_TrxName().Rollback(); return(errorMsg); } } revenueRecognitionPlan.SetRecognizedAmt(revenueRecognitionRun.GetRecognizedAmt() + revenueRecognitionPlan.GetRecognizedAmt()); if (!revenueRecognitionPlan.Save()) { pp = VLogger.RetrieveError(); if (pp != null) { errorMsg = pp.GetName(); if (errorMsg == "") { errorMsg = pp.GetValue(); } } if (errorMsg == "") { errorMsg = Msg.GetMsg(GetCtx(), "GLJournalNotCreated"); } Get_TrxName().Rollback(); return(errorMsg); } } if (journal != null) { if (DocNo == null) { DocNo = journal.GetDocumentNo(); } else { DocNo += ", " + journal.GetDocumentNo(); } journal_ID[journal_ID.Length - 1] = journal.GetGL_Journal_ID(); } } } catch (Exception ex) { log.Log(Level.SEVERE, Msg.GetMsg(GetCtx(), "GLJournalnotallocateddueto") + ex.Message); Get_TrxName().Rollback(); return(ex.Message); } if (DocNo == null) { return(Msg.GetMsg(GetCtx(), "FoundNoRevenueRecognitionPlan")); } Get_TrxName().Commit(); if (journal_ID != null) { for (int i = 0; i < journal_ID.Length; i++) { if (journal_ID[i] > 0) { string result = CompleteOrReverse(GetCtx(), journal_ID[i], 169, "CO"); if (!String.IsNullOrEmpty(result)) { journalIDS += ", " + journal_ID[i] + " " + result; } } } } if (!String.IsNullOrEmpty(journalIDS)) { return(Msg.GetMsg(GetCtx(), "GLJournalCreated") + DocNo + " " + Msg.GetMsg(GetCtx(), "GLJournalNotCompleted") + journalIDS); } else { return(Msg.GetMsg(GetCtx(), "GLJournalCreated") + DocNo); } }