public static BO_BonusRevenue GetBonusRecordById(int transId) { BO_BonusRevenue obj_br = null; using (AprosysAccountingEntities db_aa = new AprosysAccountingEntities()) { var objBonus = (from glRevenue in db_aa.Acc_GL join glAccount in db_aa.Acc_GL on glRevenue.TranId equals glAccount.TranId join caRevenue in db_aa.Acc_COA on glRevenue.CoaId equals caRevenue.CoaId join caAccount in db_aa.Acc_COA on glAccount.CoaId equals caAccount.CoaId where caRevenue.PId == 25 && glRevenue.IsActive == true && glAccount.IsActive == true //&& glRevenue.TranId == transId select new BO_BonusRevenue { activityDate = glRevenue.CreatedDate, BankAccount = caAccount.CoaId.ToString(), RevenueAccount = caRevenue.CoaId.ToString(), BonusAmount = glRevenue.Credit, TransactionId = glRevenue.TranId, Misc = glRevenue.Comments ?? "" }).ToList(); obj_br = objBonus.FirstOrDefault(x => x.TransactionId == transId); } return(obj_br); }
public static string SaveBonus(BO_BonusRevenue br, int empID, System.Data.Entity.DbContextTransaction trans = null, AprosysAccountingEntities context = null) { AprosysAccountingEntities db = context == null ? new AprosysAccountingEntities() : context; var transaction = trans == null?db.Database.BeginTransaction() : trans; try { var editVal = trans != null?db.Acc_GL.Where(x => x.IsActive == false && x.CoaId == 0).Select(x => new { createdBy = x.CreatedBy.Value, createdDate = x.CreatedDate.Value }).FirstOrDefault() : new { createdBy = empID, createdDate = DateTime.Now }; if (br.TransactionId != null) { var update = db.Acc_GL.Where(x => (x.TranId == br.TransactionId || x.GlId == br.TransactionId) && x.IsActive == true).ToList(); foreach (var rows in update) { rows.IsActive = false; } db.SaveChanges(); } var GLParent = new Acc_GL() { CoaId = 5, UserId = empID, Comments = br.Misc, ActivityTimestamp = br.activityDate, Debit = br.BonusAmount, Credit = br.BonusAmount, TranTypeId = (int)TransactionTypes.Bonus, IsActive = true, CreatedBy = editVal.createdBy, CreatedDate = editVal.createdDate, ModifiedBy = empID, ModifiedDate = DateTime.Now }; db.Acc_GL.Add(GLParent); db.SaveChanges(); var GLDebitEntry = new Acc_GL() { TranId = GLParent.GlId, Comments = br.Misc, UserId = empID, CoaId = br.BankAccount != null?Convert.ToInt32(br.BankAccount) : (int?)null, ActivityTimestamp = br.activityDate, TranTypeId = (int)TransactionTypes.Bonus, IsActive = true, Debit = br.BonusAmount, CreatedBy = editVal.createdBy, CreatedDate = editVal.createdDate, ModifiedBy = empID, ModifiedDate = DateTime.Now }; db.Acc_GL.Add(GLDebitEntry); var GLCreditEntry = new Acc_GL() { TranId = GLParent.GlId, Comments = br.Misc, UserId = empID, CoaId = br.RevenueAccount != null?Convert.ToInt32(br.RevenueAccount) : (int?)null, ActivityTimestamp = br.activityDate, TranTypeId = (int)TransactionTypes.Bonus, IsActive = true, Credit = br.BonusAmount, CreatedBy = editVal.createdBy, CreatedDate = editVal.createdDate, ModifiedBy = empID, ModifiedDate = DateTime.Now }; db.Acc_GL.Add(GLCreditEntry); db.SaveChanges(); if (trans == null) { transaction.Commit(); db.Dispose(); transaction.Dispose(); } return("Success"); } catch (Exception ex) { transaction.Rollback(); throw; } }
public string SaveBonus(BO_BonusRevenue br) { var empID = UserAprosysAccounting.id; return(BL_Common.Serialize(BL_BonusRevenue.SaveBonus(br, empID))); }