public VAdvantage.Model.MJournalLine GenerateJounalLine(VAdvantage.Model.MJournal journal, MInvoice invoice, VAdvantage.Model.MInvoiceLine invoiceLine, MRevenueRecognitionPlan revenueRecognitionPlan, MRevenueRecognitionRun revenueRecognitionRun, string recognitionType, int k) { try { int combination_ID = 0; if (k == 0) { if (recognitionType == "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(revenueRecognitionRun.GetRecognizedAmt()); journalLine.SetAmtSourceDr(revenueRecognitionRun.GetRecognizedAmt()); journalLine.SetAmtSourceCr(0); journalLine.SetAmtAcctCr(0); } else { if (recognitionType == "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(revenueRecognitionRun.GetRecognizedAmt()); journalLine.SetAmtAcctCr(revenueRecognitionRun.GetRecognizedAmt()); } 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()); 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) { log.SaveError(null, ex); } return(journalLine); }
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)); }