protected override bool AfterSave(bool newRecord, bool success) { if (newRecord) { MRevenueRecognition rr = new MRevenueRecognition(GetCtx(), GetC_RevenueRecognition_ID(), Get_TrxName()); if (rr.IsTimeBased()) { /** Get InvoiveQty * SELECT QtyInvoiced, M_Product_ID * INTO v_Qty, v_M_Product_ID * FROM C_InvoiceLine * WHERE C_InvoiceLine_ID=:new.C_InvoiceLine_ID; * -- Insert * AD_Sequence_Next ('C_ServiceLevel', :new.AD_Client_ID, v_NextNo); * INSERT INTO C_ServiceLevel * (C_ServiceLevel_ID, C_RevenueRecognition_Plan_ID, * AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy, * M_Product_ID, Description, ServiceLevelInvoiced, ServiceLevelProvided, * Processing,Processed) * VALUES * (v_NextNo, :new.C_RevenueRecognition_Plan_ID, * :new.AD_Client_ID,:new.AD_Org_ID,'Y',SysDate,:new.CreatedBy,SysDate,:new.UpdatedBy, * v_M_Product_ID, NULL, v_Qty, 0, * 'N', 'N'); **/ } } return(success); } // afterSave
private static MINT15RevenueService[] GetServices(MRevenueRecognition MRevenueRecognition) { List <MINT15RevenueService> list = new List <MINT15RevenueService>(); String sql = "SELECT * FROM INT15_RevenueService WHERE C_RevenueRecognition_ID=" + MRevenueRecognition.GetC_RevenueRecognition_ID(); DataSet ds = new DataSet(); try { ds = DB.ExecuteDataset(sql, null, MRevenueRecognition.Get_TrxName()); foreach (DataRow dr in ds.Tables[0].Rows) { MINT15RevenueService il = new MINT15RevenueService(MRevenueRecognition.GetCtx(), dr, MRevenueRecognition.Get_TrxName()); list.Add(il); } ds = null; } catch (Exception e) { // log.Log(Level.SEVERE, "getServices", e); } MINT15RevenueService[] lines = new MINT15RevenueService[list.Count]; lines = list.ToArray(); return(lines); }
public void SetRecognitionRun(MRevenueRecognition revenueRecognition, MINT15RevenueService revenueService, MRevenueRecognitionPlan revenueRecognitionPlan) { SetAD_Client_ID(revenueRecognitionPlan.GetAD_Client_ID()); SetAD_Org_ID(revenueRecognitionPlan.GetAD_Org_ID()); SetC_RevenueRecognition_Plan_ID(revenueRecognitionPlan.GetC_RevenueRecognition_Plan_ID()); if (revenueService != null) { SetINT15_RevenueService_ID(revenueService.GetINT15_RevenueService_ID()); } }
} // afterSave public static MRevenueRecognitionPlan[] GetRecognitionPlans(MRevenueRecognition revenueRecognition, int invoiceLine_ID) { List <MRevenueRecognitionPlan> list = new List <MRevenueRecognitionPlan>(); string sql = "Select * from C_RevenueRecognition_Plan pl"; if (invoiceLine_ID > 0) { sql += " inner join c_invoiceline invl on invl.c_invoiceline_id = pl.c_invoiceline_id Where pl.C_RevenueRecognition_ID=" + revenueRecognition.GetC_RevenueRecognition_ID() + "" + " and invl.c_invoiceLine_id=" + invoiceLine_ID; } else { sql += " Where pl.C_RevenueRecognition_ID=" + revenueRecognition.GetC_RevenueRecognition_ID(); } DataTable dt = null; IDataReader idr = null; try { idr = DB.ExecuteReader(sql, null, revenueRecognition.Get_Trx()); dt = new DataTable(); dt.Load(idr); idr.Close(); foreach (DataRow dr in dt.Rows) { list.Add(new MRevenueRecognitionPlan(revenueRecognition.GetCtx(), dr, revenueRecognition.Get_Trx())); } } catch (Exception e) { if (idr != null) { idr.Close(); } _log.Log(Level.SEVERE, sql, e); } finally { dt = null; } MRevenueRecognitionPlan[] retValue = new MRevenueRecognitionPlan[list.Count]; retValue = list.ToArray(); return(retValue); }
public static MRevenueRecognition[] GetRecognitions(Ctx ctx, Trx trx) { List <MRevenueRecognition> list = new List <MRevenueRecognition>(); string sql = "Select * From C_RevenueRecognition Where AD_Client_ID=" + ctx.GetAD_Client_ID(); DataTable dt = null; IDataReader idr = null; try { idr = DB.ExecuteReader(sql, null, null); dt = new DataTable(); dt.Load(idr); idr.Close(); foreach (DataRow dr in dt.Rows) { list.Add(new MRevenueRecognition(ctx, dr, trx)); } } catch (Exception e) { if (idr != null) { idr.Close(); } _log.Log(Level.SEVERE, sql, e); } finally { dt = null; } MRevenueRecognition[] retValue = new MRevenueRecognition[list.Count]; retValue = list.ToArray(); return(retValue); }
public static string CreateRevenueRecognitionPlan(int C_InvoiceLine_ID, int C_RevenueRecognition_ID, MInvoice Invoice) { try { MRevenueRecognitionRun revenueRecognitionRun = null; DateTime? RecognizationDate = null; MRevenueRecognition revenueRecognition = new MRevenueRecognition(Invoice.GetCtx(), C_RevenueRecognition_ID, Invoice.Get_Trx()); int defaultAccSchemaOrg_ID = GetDefaultActSchema(Invoice.GetAD_Org_ID()); if (defaultAccSchemaOrg_ID <= 0) { _log.Log(Level.SEVERE, "Default Schema not found for the oraganization"); return("Default Schema not found for the oraganization"); } MINT15AccountingSchemaOrg accountingSchemaOrg = new MINT15AccountingSchemaOrg(Invoice.GetCtx(), defaultAccSchemaOrg_ID, Invoice.Get_Trx()); MRevenueRecognitionPlan revenueRecognitionPlan = new MRevenueRecognitionPlan(Invoice.GetCtx(), 0, Invoice.Get_Trx()); MInvoiceLine invoiceLine = new MInvoiceLine(Invoice.GetCtx(), C_InvoiceLine_ID, Invoice.Get_Trx()); MInvoice invoice = new MInvoice(Invoice.GetCtx(), invoiceLine.GetC_Invoice_ID(), Invoice.Get_Trx()); string sql = "Select INT15_StartDate From C_InvoiceLine Where C_InvoiceLine_ID=" + invoiceLine.GetC_InvoiceLine_ID(); RecognizationDate = Util.GetValueOfDateTime(DB.ExecuteScalar(sql)); if (RecognizationDate == null) { RecognizationDate = invoice.GetDateInvoiced(); } revenueRecognitionPlan.SetRecognitionPlan(invoiceLine, invoice, C_RevenueRecognition_ID); revenueRecognitionPlan.SetC_AcctSchema_ID(accountingSchemaOrg.GetC_AcctSchema_ID()); revenueRecognitionPlan.SetRecognizedAmt(0); if (revenueRecognition.GetINT15_RecognizeType() == "R") { revenueRecognitionPlan.SetUnEarnedRevenue_Acct(RecognitionCombination(accountingSchemaOrg, "UR", invoiceLine)); revenueRecognitionPlan.SetP_Revenue_Acct(RecognitionCombination(accountingSchemaOrg, "TR", invoiceLine)); } else { revenueRecognitionPlan.SetINT15_PrepaidExpense(RecognitionCombination(accountingSchemaOrg, "DE", invoiceLine)); revenueRecognitionPlan.SetINT15_ProductExpense(RecognitionCombination(accountingSchemaOrg, "PE", invoiceLine)); } revenueRecognitionPlan.Save(); if (!revenueRecognition.IsTimeBased()) { MINT15RevenueService[] revenueService = GetServices(revenueRecognition); for (int i = 0; i < revenueService.Length; i++) { MINT15RevenueService revenueserviceline = revenueService[i]; revenueRecognitionRun = new MRevenueRecognitionRun(Invoice.GetCtx(), 0, Invoice.Get_Trx()); revenueRecognitionRun.SetRecognitionRun(revenueRecognition, revenueserviceline, revenueRecognitionPlan); Decimal recognizedAmt = (revenueRecognitionPlan.GetTotalAmt() * revenueserviceline.GetINT15_Percentage()) / 100; revenueRecognitionRun.SetRecognizedAmt(recognizedAmt); revenueRecognitionRun.SetINT15_RevenueService_ID(revenueserviceline.GetINT15_RevenueService_ID()); revenueRecognitionRun.Save(); } } else { if (revenueRecognition.GetRecognitionFrequency() == "M") { //Decimal recognizedAmt = revenueRecognitionPlan.GetTotalAmt() / revenueRecognition.GetNoMonths(); double totaldays = (RecognizationDate.Value.AddMonths(revenueRecognition.GetNoMonths()) - RecognizationDate.Value.Date).TotalDays; decimal perdayAmt = revenueRecognitionPlan.GetTotalAmt() / Convert.ToDecimal(totaldays); decimal recognizedAmt = 0; DateTime?lastdate = null; int days = 0; for (int i = 0; i < revenueRecognition.GetNoMonths() + 1; i++) { if (i == 0) { if (RecognizationDate.Value.Month == 12) { lastdate = new DateTime(RecognizationDate.Value.Year, RecognizationDate.Value.Month, 1).AddMonths(1).AddDays(-1); } else { lastdate = new DateTime(RecognizationDate.Value.Year, RecognizationDate.Value.Month + 1, 1).AddDays(-1); } days = Util.GetValueOfInt((lastdate.Value.Date - RecognizationDate.Value.Date).TotalDays); days += 1; } else if (i == (revenueRecognition.GetNoMonths())) { DateTime EndDate = RecognizationDate.Value.AddMonths(i); var startDate = new DateTime(EndDate.Year, EndDate.Month, 1); days = Util.GetValueOfInt((EndDate.Date - startDate.Date).TotalDays); } else { DateTime startdate = RecognizationDate.Value.AddMonths(i); days = DateTime.DaysInMonth(startdate.Year, startdate.Month); } recognizedAmt = Convert.ToDecimal(days) * perdayAmt; revenueRecognitionRun = new MRevenueRecognitionRun(Invoice.GetCtx(), 0, Invoice.Get_Trx()); revenueRecognitionRun.SetRecognitionRun(revenueRecognition, null, revenueRecognitionPlan); revenueRecognitionRun.SetRecognizedAmt(recognizedAmt); revenueRecognitionRun.SetINT15_RecognitionDate(RecognizationDate.Value.AddMonths(i)); revenueRecognitionRun.Save(); recognizedAmt = 0; } } else if (revenueRecognition.GetRecognitionFrequency() == "D") { Decimal recognizedAmt = revenueRecognitionPlan.GetTotalAmt() / revenueRecognition.GetNoMonths(); int days = 0; for (int i = 0; i < revenueRecognition.GetNoMonths(); i++) { revenueRecognitionRun = new MRevenueRecognitionRun(Invoice.GetCtx(), 0, Invoice.Get_Trx()); revenueRecognitionRun.SetRecognitionRun(revenueRecognition, null, revenueRecognitionPlan); revenueRecognitionRun.SetRecognizedAmt(recognizedAmt); revenueRecognitionRun.SetINT15_RecognitionDate(RecognizationDate.Value.AddDays(days)); days += 1; revenueRecognitionRun.Save(); } } } } catch (Exception ex) { return(ex.ToString()); } return("Revenue Recognition Created"); }