Exemple #1
0
        public static string EditPaymentVoucher(BO_PaymentVoucher _rvoucher)
        {
            using (AprosysAccountingEntities db = new AprosysAccountingEntities())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        var actingID         = _rvoucher.expenseTypeCategory == 10 || _rvoucher.expenseTypeCategory == 12 ? _rvoucher.expensetype : 0;
                        var PreviousPaymentV = db.Acc_GL.Where(x => x.InvoiceNo == _rvoucher.invoiceNo).ToList();
                        //Parent Entry
                        var parent = PreviousPaymentV.Find(x => x.CoaId == 0 && x.IsActive == true);
                        parent.Comments          = _rvoucher.comments;
                        parent.CustId            = _rvoucher.expenseTypeCategory == 10 ? actingID : (int?)null;
                        parent.VendorId          = _rvoucher.expenseTypeCategory == 12 ? actingID : (int?)null;
                        parent.Debit             = _rvoucher.paid;
                        parent.Credit            = _rvoucher.paid;
                        parent.ActivityTimestamp = _rvoucher.activityDate;
                        parent.UserId            = _rvoucher.empID;
                        parent.ModifiedBy        = _rvoucher.empID;
                        parent.ModifiedDate      = DateTime.Now;
                        db.SaveChanges();

                        var cash = PreviousPaymentV.Find(x => x.CoaId == 11 && x.IsActive == true);
                        cash.CustId            = _rvoucher.expenseTypeCategory == 10 ? actingID : (int?)null;
                        cash.VendorId          = _rvoucher.expenseTypeCategory == 12 ? actingID : (int?)null;
                        cash.Credit            = _rvoucher.paid;
                        cash.ActivityTimestamp = _rvoucher.activityDate;
                        cash.UserId            = _rvoucher.empID;
                        cash.ModifiedBy        = _rvoucher.empID;
                        cash.ModifiedDate      = DateTime.Now;
                        db.SaveChanges();

                        var totals = PreviousPaymentV.Find(x => x.CoaId != 11 && x.CoaId != 0 && x.Debit > 0 && x.IsActive == true);
                        totals.CoaId             = _rvoucher.expenseTypeCategory == 10 || _rvoucher.expenseTypeCategory == 12 ? _rvoucher.expenseTypeCategory : _rvoucher.expensetype;
                        totals.CustId            = _rvoucher.expenseTypeCategory == 10 ? actingID : (int?)null;
                        totals.VendorId          = _rvoucher.expenseTypeCategory == 12 ? actingID : (int?)null;
                        totals.Debit             = _rvoucher.paid;
                        totals.ActivityTimestamp = _rvoucher.activityDate;
                        totals.UserId            = _rvoucher.empID;
                        totals.ModifiedBy        = _rvoucher.empID;
                        totals.ModifiedDate      = DateTime.Now;
                        db.SaveChanges();
                        transaction.Commit();
                        return("success");
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        throw;
                    }
                }
            }
        }
Exemple #2
0
        public static string SavePaymentVoucher(BO_PaymentVoucher _rvoucher)
        {
            using (AprosysAccountingEntities db = new AprosysAccountingEntities())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        int transType = (int)Constants.TransactionTypes.PaymentVoucher;
                        _rvoucher.invoiceNo = Util.GetNextVoucher(transType);
                        var actingID = _rvoucher.expenseTypeCategory == 10 || _rvoucher.expenseTypeCategory == 12 ? _rvoucher.expensetype : 0;
                        //Parent Entry
                        var GLParent = new Acc_GL()
                        {
                            CoaId = 0, UserId = _rvoucher.empID, Comments = _rvoucher.comments, CustId = _rvoucher.expenseTypeCategory == 10 ? actingID : (int?)null, VendorId = _rvoucher.expenseTypeCategory == 12 ? actingID : (int?)null, Debit = _rvoucher.paid, Credit = _rvoucher.paid, ActivityTimestamp = _rvoucher.activityDate, TranTypeId = transType, InvoiceNo = _rvoucher.invoiceNo, IsActive = true, CreatedBy = _rvoucher.empID, CreatedDate = DateTime.Now, ModifiedBy = _rvoucher.empID, ModifiedDate = DateTime.Now
                        };
                        db.Acc_GL.Add(GLParent);
                        db.SaveChanges();
                        int _coaId = 11;
                        if (_rvoucher.paymentMode == 2)
                        {
                            _coaId = _rvoucher.bankId ?? 0;
                        }
                        if (_rvoucher.paymentMode == 3)
                        {
                            _coaId = _rvoucher.bankTransferAccountId ?? 0;
                        }
                        var GLPaid = new Acc_GL()
                        {
                            TranId = GLParent.GlId, UserId = _rvoucher.empID, CoaId = _coaId, CustId = _rvoucher.expenseTypeCategory == 10 ? actingID : (int?)null, VendorId = _rvoucher.expenseTypeCategory == 12 ? actingID : (int?)null, Credit = _rvoucher.paid, ActivityTimestamp = _rvoucher.activityDate, TranTypeId = transType, InvoiceNo = _rvoucher.invoiceNo, IsActive = true, CreatedBy = _rvoucher.empID, CreatedDate = DateTime.Now, ModifiedBy = _rvoucher.empID, ModifiedDate = DateTime.Now, DocumentId = _rvoucher.checkNo
                        };
                        db.Acc_GL.Add(GLPaid);

                        var GLType = new Acc_GL()
                        {
                            TranId = GLParent.GlId, UserId = _rvoucher.empID, CoaId = _rvoucher.expenseTypeCategory == 10 || _rvoucher.expenseTypeCategory == 12 ? _rvoucher.expenseTypeCategory : _rvoucher.expensetype, CustId = _rvoucher.expenseTypeCategory == 10 ? actingID : (int?)null, VendorId = _rvoucher.expenseTypeCategory == 12 ? actingID : (int?)null, Debit = _rvoucher.paid, ActivityTimestamp = _rvoucher.activityDate, TranTypeId = transType, InvoiceNo = _rvoucher.invoiceNo, IsActive = true, CreatedBy = _rvoucher.empID, CreatedDate = DateTime.Now, ModifiedBy = _rvoucher.empID, ModifiedDate = DateTime.Now
                        };
                        db.Acc_GL.Add(GLType);
                        db.SaveChanges();
                        transaction.Commit();
                        return("success");
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        throw;
                    }
                }
            }
        }