//public static string SaveSuspendedDuesofCustomer(int CustID,int EmpId) //{ // decimal pendingdues= BL_Customer.GetCustomerBalance(CustID)??0; // if (pendingdues > 0) // { // BO_ReceiptVoucher _rvoucher = new BO_ReceiptVoucher(); // _rvoucher.rCustomerId = CustID; // _rvoucher.rRecived = pendingdues; // _rvoucher.empID = EmpId; // _rvoucher.rComments = "Clear Pending Dues of Subscription Customer"; // _rvoucher.rActivityDate = BL_Common.GetDatetime(); // _rvoucher.TypeId = 2; // _rvoucher.rbalance = pendingdues;//its not enter in db , sets it for Acc REC entry // SaveReceiptVoucher(_rvoucher); // } // return "success"; //} public static string SaveReceiptVoucher(BO_ReceiptVoucher _rvoucher) { using (AprosysAccountingEntities db = new AprosysAccountingEntities()) { using (var transaction = db.Database.BeginTransaction()) { try { int transType = (int)Constants.TransactionTypes.ReceiptVoucher; _rvoucher.invoiceNo = Util.GetNextVoucher(transType); bool isPostPaid = _rvoucher.TypeId == 2 ? true : false; //Parent Entry var GLParent = new Acc_GL() { CoaId = 0, UserId = _rvoucher.empID, Comments = _rvoucher.rComments, CustId = _rvoucher.rCustomerId, ActivityTimestamp = _rvoucher.rActivityDate, TranTypeId = transType, Debit = _rvoucher.rRecived, Credit = _rvoucher.rRecived, InvoiceNo = _rvoucher.invoiceNo, IsActive = true, IsPostpaid = isPostPaid, CreatedBy = _rvoucher.empID, ModifiedBy = _rvoucher.empID, CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now }; string InvoiceID = GLParent.InvoiceNo; db.Acc_GL.Add(GLParent); db.SaveChanges(); //Acc Receiveable for Type=1 , Subscrtiption Receiveable=2 if (_rvoucher.TypeId == 1 || (_rvoucher.TypeId == 2 && _rvoucher.rbalance != 0)) { //Acc Receivable var GLpaid = new Acc_GL() { TranId = GLParent.GlId, UserId = _rvoucher.empID, CoaId = 10, CustId = _rvoucher.rCustomerId, ActivityTimestamp = _rvoucher.rActivityDate, TranTypeId = transType, InvoiceNo = _rvoucher.invoiceNo, IsActive = true, Credit = _rvoucher.rRecived, IsPostpaid = isPostPaid, CreatedBy = _rvoucher.empID, ModifiedBy = _rvoucher.empID, CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now }; db.Acc_GL.Add(GLpaid); } else { //Subscription Sales var GLSalesSub = new Acc_GL() { TranId = GLParent.GlId, UserId = _rvoucher.empID, CoaId = 100, CustId = _rvoucher.rCustomerId, ActivityTimestamp = _rvoucher.rActivityDate, TranTypeId = transType, InvoiceNo = _rvoucher.invoiceNo, IsActive = true, Credit = _rvoucher.rRecived, IsPostpaid = isPostPaid, CreatedBy = _rvoucher.empID, ModifiedBy = _rvoucher.empID, CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now }; db.Acc_GL.Add(GLSalesSub); } //Cash Entry var GLCash = new Acc_GL() { TranId = GLParent.GlId, UserId = _rvoucher.empID, CoaId = 11, CustId = _rvoucher.rCustomerId, ActivityTimestamp = _rvoucher.rActivityDate, TranTypeId = transType, InvoiceNo = _rvoucher.invoiceNo, IsActive = true, Debit = _rvoucher.rRecived, IsPostpaid = isPostPaid, CreatedBy = _rvoucher.empID, ModifiedBy = _rvoucher.empID, CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now }; db.Acc_GL.Add(GLCash); db.SaveChanges(); transaction.Commit(); return(InvoiceID); } catch (Exception) { transaction.Rollback(); throw; } } } }
public static string EditReceiptVoucher(BO_ReceiptVoucher _rvoucher) { using (AprosysAccountingEntities db = new AprosysAccountingEntities()) { using (var transaction = db.Database.BeginTransaction()) { try { bool isPostPaid = _rvoucher.TypeId == 2 ? true : false; var rctL = db.Acc_GL.Where(x => x.InvoiceNo == _rvoucher.invoiceNo && x.IsActive == true).ToList(); rctL.ForEach(x => x.IsActive = false); var parent = rctL.Find(x => x.CoaId == 0); parent.Comments = _rvoucher.rComments; parent.CustId = _rvoucher.rCustomerId; parent.ActivityTimestamp = _rvoucher.rActivityDate; parent.Debit = _rvoucher.rRecived; parent.Credit = _rvoucher.rRecived; parent.InvoiceNo = _rvoucher.invoiceNo; parent.UserId = parent.ModifiedBy = _rvoucher.empID; parent.ModifiedDate = DateTime.Now; parent.IsActive = true; db.SaveChanges(); if (_rvoucher.TypeId == 1 || (_rvoucher.TypeId == 2 && _rvoucher.rbalance != 0)) { var paid = rctL.Find(x => x.CoaId == 10); if (paid != null) { paid.CustId = _rvoucher.rCustomerId; paid.ActivityTimestamp = _rvoucher.rActivityDate; paid.Credit = _rvoucher.rRecived; paid.UserId = paid.ModifiedBy = _rvoucher.empID; paid.ModifiedDate = DateTime.Now; paid.IsActive = true; } else { var GLpaid = new Acc_GL() { TranId = parent.GlId, UserId = _rvoucher.empID, CoaId = 10, CustId = _rvoucher.rCustomerId, ActivityTimestamp = _rvoucher.rActivityDate, TranTypeId = parent.TranTypeId, InvoiceNo = _rvoucher.invoiceNo, IsActive = true, Credit = _rvoucher.rRecived, IsPostpaid = isPostPaid, CreatedBy = _rvoucher.empID, ModifiedBy = _rvoucher.empID, CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now }; db.Acc_GL.Add(GLpaid); } } else { var paid = rctL.Find(x => x.CoaId == 100); if (paid != null) { paid.CustId = _rvoucher.rCustomerId; paid.ActivityTimestamp = _rvoucher.rActivityDate; paid.Credit = _rvoucher.rRecived; paid.UserId = paid.ModifiedBy = _rvoucher.empID; paid.IsActive = true; paid.ModifiedDate = DateTime.Now; } else { var GLSalesSub = new Acc_GL() { TranId = parent.GlId, UserId = _rvoucher.empID, CoaId = 100, CustId = _rvoucher.rCustomerId, ActivityTimestamp = _rvoucher.rActivityDate, TranTypeId = parent.TranTypeId, InvoiceNo = _rvoucher.invoiceNo, IsActive = true, Credit = _rvoucher.rRecived, IsPostpaid = isPostPaid, CreatedBy = _rvoucher.empID, ModifiedBy = _rvoucher.empID, CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now }; db.Acc_GL.Add(GLSalesSub); } } var cash = rctL.Find(x => x.CoaId == 11); cash.CustId = _rvoucher.rCustomerId; cash.ActivityTimestamp = _rvoucher.rActivityDate; cash.IsActive = true; cash.Debit = _rvoucher.rRecived; cash.ModifiedDate = DateTime.Now; cash.UserId = cash.ModifiedBy = _rvoucher.empID; db.SaveChanges(); transaction.Commit(); return(_rvoucher.invoiceNo); } catch (Exception) { transaction.Rollback(); throw; } } } }