Пример #1
0
        //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;
                    }
                }
            }
        }
Пример #2
0
        public static string InsertEquityInfo(BO_Equity obj)
        {
            using (AprosysAccountingEntities db = new AprosysAccountingEntities())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        int transType = (int)Constants.TransactionTypes.Equity;
                        obj.invoiceNo = Util.GetNextVoucher(transType);
                        //obj.transDate = DateTime.Now;
                        //Parent Entry
                        var GLParent = new Acc_GL()
                        {
                            CoaId = 0, UserId = obj.userId, Debit = Math.Abs(obj.amount), Credit = Math.Abs(obj.amount), ActivityTimestamp = obj.activityTime, TranTypeId = transType, InvoiceNo = obj.invoiceNo, IsActive = true, CreatedBy = obj.userId, CreatedDate = DateTime.Now, ModifiedBy = obj.userId, ModifiedDate = DateTime.Now
                        };
                        db.Acc_GL.Add(GLParent);
                        db.SaveChanges();
                        //Bank Entry
                        if (obj.accountId > 0)
                        {
                            var GLBank = new Acc_GL()
                            {
                                TranId = GLParent.GlId, CoaId = obj.accountId, UserId = obj.userId, Debit = (obj.isdeposit == true ? obj.amount : 0), Credit = (obj.isdeposit == false ? obj.amount : 0), ActivityTimestamp = obj.activityTime, TranTypeId = transType, InvoiceNo = obj.invoiceNo, IsActive = true, CreatedBy = obj.userId, CreatedDate = DateTime.Now, ModifiedBy = obj.userId, ModifiedDate = DateTime.Now
                            };
                            GLBank.Comments = obj.comments;
                            db.Acc_GL.Add(GLBank);
                        }
                        else
                        {
                            ///Cash Entry
                            var GLBank = new Acc_GL()
                            {
                                TranId = GLParent.GlId, CoaId = 11, UserId = obj.userId, Debit = (obj.isdeposit == true ? obj.amount : 0), Credit = (obj.isdeposit == false ? obj.amount : 0), ActivityTimestamp = obj.activityTime, TranTypeId = transType, InvoiceNo = obj.invoiceNo, IsActive = true, CreatedBy = obj.userId, CreatedDate = DateTime.Now, ModifiedBy = obj.userId, ModifiedDate = DateTime.Now
                            };
                            GLBank.Comments = obj.comments;
                            db.Acc_GL.Add(GLBank);
                        }

                        //Investor Entry
                        var GLRecvable = new Acc_GL()
                        {
                            TranId = GLParent.GlId, CoaId = obj.investorId, UserId = obj.userId, Debit = (obj.isdeposit == false ? obj.amount : 0), Credit = (obj.isdeposit == true ? obj.amount : 0), ActivityTimestamp = obj.activityTime, TranTypeId = transType, InvoiceNo = obj.invoiceNo, IsActive = true, CreatedBy = obj.userId, CreatedDate = DateTime.Now, ModifiedBy = obj.userId, ModifiedDate = DateTime.Now
                        };
                        db.Acc_GL.Add(GLRecvable);


                        db.SaveChanges();
                        transaction.Commit();
                        return("success");
                    }
                    catch { transaction.Rollback(); throw; }
                }
            }
        }
Пример #3
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;
                    }
                }
            }
        }
Пример #4
0
        public static string InsertBankTransfer(BO_Banks obj)
        {
            using (AprosysAccountingEntities db = new AprosysAccountingEntities())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        int transType = (int)Constants.TransactionTypes.BanksTransfer;
                        obj.invoiceNo = Util.GetNextVoucher(transType);
                        //obj.transDate = DateTime.Now;
                        //Parent Entry
                        var GLParent = new Acc_GL()
                        {
                            CoaId = 0, UserId = obj.empID, Debit = Math.Abs(obj.amount), Credit = Math.Abs(obj.amount), ActivityTimestamp = obj.transDate, TranTypeId = transType, InvoiceNo = obj.invoiceNo, IsActive = true, CreatedBy = obj.empID, CreatedDate = DateTime.Now, ModifiedBy = obj.empID, ModifiedDate = DateTime.Now
                        };
                        db.Acc_GL.Add(GLParent);
                        db.SaveChanges();
                        //Bank Entry
                        var GLBank = new Acc_GL()
                        {
                            TranId = GLParent.GlId, CoaId = obj.bankID, UserId = obj.empID, Debit = obj.amount > 0 ? obj.amount : (decimal?)null, Credit = obj.amount < 0 ? Math.Abs(obj.amount) : (decimal?)null, ActivityTimestamp = obj.transDate, TranTypeId = transType, InvoiceNo = obj.invoiceNo, IsActive = true, CreatedBy = obj.empID, CreatedDate = DateTime.Now, ModifiedBy = obj.empID, ModifiedDate = DateTime.Now
                        };
                        GLBank.Comments = obj.comment;
                        db.Acc_GL.Add(GLBank);

                        if (!string.IsNullOrEmpty(obj.documentId))
                        {
                            // Receivable Entry
                            var GLRecvable = new Acc_GL()
                            {
                                TranId = GLParent.GlId, CoaId = 11, UserId = obj.empID, Debit = obj.amount < 0 ? Math.Abs(obj.amount) : (decimal?)null, Credit = obj.amount > 0 ? obj.amount : (decimal?)null, ActivityTimestamp = obj.transDate, TranTypeId = transType, InvoiceNo = obj.invoiceNo, IsActive = true, CreatedBy = obj.empID, CreatedDate = DateTime.Now, ModifiedBy = obj.empID, ModifiedDate = DateTime.Now, DocumentId = obj.documentId
                            };
                            db.Acc_GL.Add(GLRecvable);
                        }
                        else
                        {
                            //Cash Entry
                            var GLCash = new Acc_GL()
                            {
                                TranId = GLParent.GlId, CoaId = 11, UserId = obj.empID, Debit = obj.amount < 0 ? Math.Abs(obj.amount) : (decimal?)null, Credit = obj.amount > 0 ? obj.amount : (decimal?)null, ActivityTimestamp = obj.transDate, TranTypeId = transType, InvoiceNo = obj.invoiceNo, IsActive = true, CreatedBy = obj.empID, CreatedDate = DateTime.Now, ModifiedBy = obj.empID, ModifiedDate = DateTime.Now
                            };
                            db.Acc_GL.Add(GLCash);
                        }
                        db.SaveChanges();
                        transaction.Commit();
                        return("success");
                    }
                    catch { transaction.Rollback(); throw; }
                }
            }
        }
Пример #5
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;
                    }
                }
            }
        }
        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;
            }
        }
Пример #7
0
 public static string AddNewBankAccoount(string bankName, string bankAccount, decimal?depositAmmount)
 {
     using (AprosysAccountingEntities db = new AprosysAccountingEntities())
     {
         try
         {
             var chk = db.Acc_COA.FirstOrDefault(x => x.TreeName == bankAccount);
             if (chk != null)
             {
                 return(String.Format("Account No: {0} is already exist.", bankAccount));
             }
             var acc = new Acc_COA();
             acc.PId            = 104;
             acc.CoaNo          = "";
             acc.HeadAccount    = 1;
             acc.TreeName       = bankAccount;
             acc.CoaLevel       = 2;
             acc.OpeningBalance = depositAmmount;
             acc.IsActive       = true;
             db.Acc_COA.Add(acc);
             db.SaveChanges();
             return("success");
         }
         catch (Exception ex) { throw ex; }
     }
 }
Пример #8
0
        public static string SaveUser(BO_Users _user, int UserID)
        {
            using (AprosysAccountingEntities db = new AprosysAccountingEntities())
            {
                try
                {
                    //var objcheck = db.Users.Where(x => x.UserName.ToLower() == _user.userId.ToLower()).FirstOrDefault();
                    //if (objcheck != null)
                    //{
                    //    return "User Already Exists";
                    //}

                    var obj = _user.id == 0 ? new ApprosysAccDB.User() : db.Users.Where(x => x.Id == _user.id).FirstOrDefault();
                    if (_user.id > 0)
                    {
                        var checkCust = db.Users.Where(x => x.UserName.ToLower() == _user.userId.ToLower() && x.Id != _user.id && x.IsActive == true).FirstOrDefault();
                        if (checkCust != null)
                        {
                            return("UserID Already Exists");
                        }
                    }
                    if (obj != null && obj.Id > 0)
                    {
                        obj.ModifiedBy = UserID;
                        obj.ModifiedOn = BL_Common.GetDatetime();
                    }
                    obj.Id = _user.id;

                    obj.LastName  = _user.lastName ?? "";
                    obj.FirstName = _user.firstName ?? "";
                    obj.UserName  = _user.userId;
                    obj.Password  = _user.password;
                    obj.Phone     = _user.phone;
                    obj.Email     = _user.email;
                    obj.IsActive  = true;
                    obj.Address   = _user.address;


                    obj.IsActive    = true;
                    obj.AdminRights = _user.adminRights;
                    if (obj.Id == 0)
                    {
                        obj.CreatedBy = UserID;
                        obj.CreatedOn = BL_Common.GetDatetime();
                        var objcheck = db.Users.Where(x => x.UserName.ToLower() == _user.userId.ToLower() && x.Id != _user.id && x.IsActive == true).FirstOrDefault();
                        if (objcheck != null)
                        {
                            return("UserID Already Exists");
                        }
                        db.Users.Add(obj);
                    }

                    db.SaveChanges();
                    return("success");

                    // return "Insertion Failed";
                }
                catch { throw; }
            }
        }
Пример #9
0
 public static string UpdateSaleInvoice(BO_SaleInvoice pi)
 {
     //if (pi.items.GroupBy(x => x.itemID).Where(x => x.Count() > 1).Count() == 1) { return "bad request"; }
     using (AprosysAccountingEntities db = new AprosysAccountingEntities())
     {
         using (var transaction = db.Database.BeginTransaction())
         {
             try
             {
                 if (DeleteSaleInvoice(pi.invoiceNo, pi.empID, transaction, db) == "Success")
                 {
                     SaveSales(pi, transaction, db);
                 }
                 db.SaveChanges();
                 transaction.Commit();
                 return(pi.invoiceNo);
             }
             catch (Exception ex)
             {
                 transaction.Rollback();
                 throw;
             }
         }
     }
 }
Пример #10
0
        public static string SaveRevenueSales(string name, decimal cost, string code)
        {
            using (AprosysAccountingEntities db = new AprosysAccountingEntities())
            {
                var obj = db.Acc_COA.Where(x => x.PId == 101 && x.HeadAccount == 5 && x.TreeName.ToLower() == name.ToLower() && x.IsActive == true).FirstOrDefault();
                if (obj != null)
                {
                    return("Exists");
                }
                var objS = db.Acc_COA.Where(x => x.PId == 101 && x.HeadAccount == 5 && x.ServiceCode == code && x.IsActive == true).FirstOrDefault();
                if (objS != null)
                {
                    return("Code Already Exists");
                }

                var obj_COA = new ApprosysAccDB.Acc_COA();
                obj_COA.PId            = 101;
                obj_COA.HeadAccount    = 5;
                obj_COA.TreeName       = name;
                obj_COA.CoaLevel       = 2;
                obj_COA.OpeningBalance = 0;
                obj_COA.IsActive       = true;
                obj_COA.Cost           = cost;
                obj_COA.ServiceCode    = code;
                db.Acc_COA.Add(obj_COA);
                db.SaveChanges();
                return("success");
            }
        }
Пример #11
0
        public static string SaveCustomer(BO_Customers _customer, int UserID)
        {
            using (AprosysAccountingEntities db = new AprosysAccountingEntities())
            {
                try
                {
                    var obj = _customer.id == 0 ? new ApprosysAccDB.Customer() : db.Customers.Where(x => x.Id == _customer.id && x.IsActive == true).FirstOrDefault();
                    if (_customer.id > 0)
                    {
                        var checkCust = db.Customers.Where(x => x.LastName.ToLower() == _customer.lastName.ToLower() && x.FirstName.ToLower() == _customer.firstName.ToLower() && x.Id != _customer.id && x.IsActive == true).FirstOrDefault();
                        if (checkCust != null)
                        {
                            return("Customer Already Exists");
                        }
                    }

                    if (obj != null && obj.Id > 0)
                    {
                        obj.ModifiedBy = UserID;
                        obj.ModifiedOn = BL_Common.GetDatetime();
                    }
                    obj.Id            = _customer.id;
                    obj.LastName      = _customer.lastName;
                    obj.FirstName     = _customer.firstName;
                    obj.SalesPersonId = _customer.salesPerson;
                    obj.Phone         = _customer.phone ?? "";
                    obj.CNIC          = _customer.cnic ?? "";
                    obj.NTN           = _customer.ntn ?? "";

                    obj.Email = _customer.email;
                    if (_customer.startDate == null)
                    {
                        _customer.startDate = DateTime.Now.Date;
                    }
                    obj.StartDate = _customer.startDate;

                    obj.OpeningBalance = _customer.openingBalance;
                    obj.Misc           = _customer.misc;
                    obj.TypeId         = 1;
                    if (obj.Id == 0)
                    {
                        obj.CreatedBy = UserID;
                        obj.CreatedOn = BL_Common.GetDatetime();
                        var objcheck = db.Customers.Where(x => x.LastName.ToLower() == _customer.lastName.ToLower() && x.FirstName.ToLower() == _customer.firstName.ToLower() && x.IsActive == true).FirstOrDefault();
                        if (objcheck != null)
                        {
                            return("Customer Already Exists");
                        }
                        db.Customers.Add(obj);
                    }
                    obj.IsActive = true;
                    db.SaveChanges();
                    return(obj.Id.ToString());

                    // return "Insertion Failed";
                }
                catch { throw; }
            }
        }
Пример #12
0
 public static string SaveStockOut(BO_StockIn so)
 {
     using (AprosysAccountingEntities db = new AprosysAccountingEntities())
     {
         using (var transaction = db.Database.BeginTransaction())
         {
             try
             {
                 int    transType = (int)Constants.TransactionTypes.StockOut;
                 string invNo     = Util.GetNextVoucher(transType);
                 so.date = DateTime.Now;
                 //Parent Entry
                 var GLParent = new Acc_GL()
                 {
                     CoaId = 0, UserId = so.empID, Comments = so.comments, ActivityTimestamp = so.date, TranTypeId = transType, Debit = so.netAmount, Credit = so.netAmount, InvoiceNo = invNo, IsActive = true, CreatedBy = so.empID, CreatedDate = DateTime.Now, ModifiedBy = so.empID, ModifiedDate = DateTime.Now
                 };
                 db.Acc_GL.Add(GLParent);
                 db.SaveChanges();
                 foreach (var item in so.items)
                 {
                     //Stock Entry
                     var GLStock = new Acc_GL()
                     {
                         TranId = GLParent.GlId, UserId = so.empID, CoaId = 6, ActivityTimestamp = so.date, TranTypeId = transType, InvoiceNo = invNo, IsActive = true, ItemId = item.itemID, Quantity = -item.qty, QuantityBalance = item.qty, UnitPrice = item.unitPrice, Credit = item.amount, CreatedBy = so.empID, CreatedDate = DateTime.Now, ModifiedBy = so.empID, ModifiedDate = DateTime.Now
                     };
                     db.Acc_GL.Add(GLStock);
                 }
                 //Counter Entry
                 var GLpayable = new Acc_GL()
                 {
                     TranId = GLParent.GlId, UserId = so.empID, CoaId = so.coaID, ActivityTimestamp = so.date, TranTypeId = transType, InvoiceNo = invNo, IsActive = true, Debit = so.netAmount, CreatedBy = so.empID, CreatedDate = DateTime.Now, ModifiedBy = so.empID, ModifiedDate = DateTime.Now
                 };
                 db.Acc_GL.Add(GLpayable);
                 db.SaveChanges();
                 transaction.Commit();
                 return("success");
             }
             catch (Exception)
             {
                 transaction.Rollback();
                 throw;
             }
         }
     }
 }
        public static void DeletePartialPayments(AprosysAccountingEntities db, string Invoice, int User)
        {
            var refTrans = db.Acc_GL.Where(x => x.InvoiceNo == Invoice && x.IsActive == true && x.TranTypeId == (int)Constants.TransactionTypes.PaymentAgainstCreditSales).ToList();

            foreach (var item in refTrans)
            {
                item.IsActive     = false;
                item.ModifiedBy   = User;
                item.ModifiedDate = DateTime.Now;
            }
            db.SaveChanges();
        }
Пример #14
0
        public static string SaveSalesReturn(BO_SalesReturn salesReturn, int empId)
        {
            string         InvoiceNo;
            BO_LineItems   lineItem     = null;
            BO_SaleInvoice obj          = null;
            var            orderDetails = GetOrderDetailsByInvoiceNo(salesReturn.InvoiceNo).FirstOrDefault(x => x.ItemCode == salesReturn.ItemCode);
            int?           itemId       = orderDetails.ItemId;
            var            quantity     = salesReturn.Quantity;
            var            unitPrice    = orderDetails.UnitPrice * (-1);
            var            amount       = orderDetails.UnitPrice * (-1 * quantity);
            var            tex          = orderDetails.TAX;

            obj           = new BO_SaleInvoice();
            obj.items     = new List <BO_LineItems>();
            obj.comments  = salesReturn.Comments;
            obj.empID     = empId;
            obj.invoiceNo = orderDetails.InvoiceNo;
            lineItem      = new BO_LineItems()
            {
                amount        = amount,
                unitPrice     = unitPrice,
                qty           = quantity,
                itemID        = itemId ?? 0,
                isServiceItem = false,
                glid          = 0,
                coaID         = 0,
                tax           = tex,
            };
            obj.items.Add(lineItem);
            obj.empID     = empId;
            obj.saleDate  = DateTime.Now;
            obj.netAmount = amount ?? 0m;
            obj.paid      = amount ?? 0;
            using (AprosysAccountingEntities db = new AprosysAccountingEntities())
            {
                Acc_GL GLPurchases = db.Acc_GL.FirstOrDefault(x => (x.IsActive ?? false) && x.CoaId == 6 && x.ItemId == itemId.Value &&
                                                              (x.TranTypeId == 1 || x.TranTypeId == 7));
                GLPurchases.QuantityBalance = GLPurchases.QuantityBalance + quantity;

                var itmTransaction = db.Acc_GL.Where(x => (x.ItemId == itemId) && (x.InvoiceNo == salesReturn.InvoiceNo));
                foreach (var item in itmTransaction)
                {
                    //Comment for sales return goes here.
                    if (item.InvoiceNo == salesReturn.InvoiceNo && item.ItemId == itemId)
                    {
                    }
                    //item.Quantity = item.Quantity - quantity;
                }
                db.SaveChanges();
            }
            InvoiceNo = SaveSalesReturn(obj);
            return(InvoiceNo);
        }
 public static string SaveItem(BO_RepoConfig obj)
 {
     using (AprosysAccountingEntities db = new AprosysAccountingEntities())
     {
         db.ReportConfigs.ToList().ForEach(x => x.active = false);
         db.ReportConfigs.Add(new ReportConfig()
         {
             title = obj.title, address = obj.address, detailTitle = obj.detailTitle, detail = obj.detail, active = true, createdBy = obj.empID.ToString(), createdDate = DateTime.Now, modifiedBy = obj.empID.ToString(), modifiedDate = DateTime.Now
         });
         db.SaveChanges();
         return("success");
     }
 }
Пример #16
0
        public static string EditRevenueSales(int id, string name, decimal cost, string code)
        {
            using (AprosysAccountingEntities db = new AprosysAccountingEntities())
            {
                var objexist = db.Acc_COA.Where(x => x.PId == 101 && x.HeadAccount == 5 && x.CoaId == id).FirstOrDefault();
                var objS     = db.Acc_COA.Where(x => x.PId == 101 && x.HeadAccount == 5 && x.ServiceCode == code && x.IsActive == true && x.CoaId != id).FirstOrDefault();
                if (objS != null)
                {
                    if (objS.ServiceCode.ToLower() == code.ToLower())
                    {
                        return("Code Already Exists");
                    }
                    if (objS.TreeName.ToLower() == name.ToLower())
                    {
                        return("Service Already Exists");
                    }
                }
                if (objexist.TreeName.ToLower() == name.ToLower() && objexist.ServiceCode.ToLower() == code.ToLower())
                {
                    objexist.Cost = cost; objexist.ServiceCode = code; db.SaveChanges(); return("Cost Updated");
                }
                if (objexist.TreeName != name)
                {
                    var nameexists = db.Acc_COA.Where(x => x.PId == 101 && x.HeadAccount == 5 && x.TreeName.ToLower() == name.ToLower()).FirstOrDefault();
                    if (nameexists != null)
                    {
                        return("Exists");
                    }

                    objexist.Cost        = cost;
                    objexist.TreeName    = name;
                    objexist.ServiceCode = code;
                    db.SaveChanges();
                    return("Service Updated");
                }
                return("success");
            }
        }
Пример #17
0
 public static string RenameBank(int bankID, string name)
 {
     using (AprosysAccountingEntities db = new AprosysAccountingEntities())
     {
         try
         {
             var acc = db.Acc_COA.Where(x => x.CoaId == bankID).FirstOrDefault();
             acc.TreeName = name;
             db.SaveChanges();
             return("success");
         }
         catch (Exception ex) { throw ex; }
     }
 }
 public static void DeletePartialPayments(int tranId, int Invoice, int User)
 {
     using (AprosysAccountingEntities db = new AprosysAccountingEntities())
     {
         var refTrans = db.Acc_GL.Where(x => (x.TranId == tranId) && x.IsActive == true).ToList();
         foreach (var item in refTrans)
         {
             item.IsActive     = false;
             item.ModifiedBy   = User;
             item.ModifiedDate = DateTime.Now;
         }
         db.SaveChanges();
     }
 }
 public static string DeleteBonus(int transId)
 {
     using (AprosysAccountingEntities db_aa = new AprosysAccountingEntities())
     {
         var update = db_aa.Acc_GL.Where(x =>
                                         (x.TranId == transId || x.GlId == transId) && x.IsActive == true).ToList();
         foreach (var rows in update)
         {
             rows.IsActive = false;
         }
         db_aa.SaveChanges();
         return("Success");
     }
 }
Пример #20
0
        public static string DeleteSaleInvoice(string voucherNo, 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 snv = db.Acc_GL.Where(x => x.InvoiceNo == voucherNo && x.IsActive == true
                                          &&
                                          x.TranTypeId == 2
                                          ).ToList();
                foreach (var item in snv.Where(x => x.CoaId == 6))
                {
                    var txLinks = db.Acc_GLTxLinks.Where(x => x.GLID == item.GlId && x.IsActive == true).ToList();
                    //Revert Stock to purchases
                    foreach (var txlinks in txLinks)
                    {
                        var pnv = db.Acc_GL.SingleOrDefault(x => x.GlId == txlinks.RelGLID);
                        pnv.QuantityBalance += txlinks.Quantity;
                        txlinks.IsActive     = false;
                    }
                }
                foreach (var item in snv)
                {
                    item.IsActive = false;
                    if (trans == null)
                    {
                        item.ModifiedBy = empID; item.ModifiedDate = DateTime.Now;
                    }
                }
                BL_CreditSales.DeletePartialPayments(db, voucherNo, empID);

                db.SaveChanges();

                if (trans == null)
                {
                    transaction.Commit();
                    db.Dispose();
                    transaction.Dispose();
                }

                return("Success");
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                throw;
            }
        }
Пример #21
0
 public static string DeletePaymentVoucher(string invoiceNo, int empID)
 {
     using (AprosysAccountingEntities db = new AprosysAccountingEntities())
     {
         var obj = db.Acc_GL.Where(x => x.InvoiceNo == invoiceNo).ToList();
         if (obj != null)
         {
             foreach (var item in obj)
             {
                 item.IsActive     = false;
                 item.ModifiedBy   = empID;
                 item.ModifiedDate = DateTime.Now;
             }
         }
         db.SaveChanges();
     }
     return("success");
 }
Пример #22
0
 public static string EditAdministrativeExpense(int id, string name)
 {
     using (AprosysAccountingEntities db = new AprosysAccountingEntities())
     {
         var obj = db.Acc_COA.Where(x => x.PId == 19 && x.HeadAccount == 4 && x.CoaId == id && x.IsActive == true).FirstOrDefault();
         if (obj != null && obj.TreeName == name)
         {
             return("Expense Already Exists");
         }
         var obj2 = db.Acc_COA.Where(x => x.PId == 19 && x.HeadAccount == 4 && x.TreeName == name && x.IsActive == true).FirstOrDefault();
         if (obj2 != null)
         {
             return("Expense Already Exists");
         }
         obj.TreeName = name;
         db.SaveChanges(); return("success");//return obj_COA.CoaId;
     }
 }
Пример #23
0
        public static string DeleteInvestor(int CoaId)
        {
            using (AprosysAccountingEntities db = new AprosysAccountingEntities())
            {
                var chk = db.Acc_COA.FirstOrDefault(x => x.CoaId == CoaId);
                if (chk != null)
                {
                    chk.IsActive = false;
                }
                else
                {
                    return("Record not found");
                }
                db.SaveChanges();
            }


            return("success");
        }
        public string DeletePaymentHistory(int tranId, int empID)
        {
            using (AprosysAccountingEntities db_aa = new AprosysAccountingEntities())
            {
                var obj = db_aa.Acc_GL.Where(x => x.TranId == tranId && x.TranTypeId == 10 && x.IsActive == true || (x.GlId == tranId));
                if (obj != null)
                {
                    foreach (var item in obj)
                    {
                        item.IsActive     = false;
                        item.ModifiedBy   = empID;
                        item.ModifiedDate = DateTime.Now;
                    }
                }

                db_aa.SaveChanges();
                return("Success");
            }
        }
Пример #25
0
        public static string DeleteRevenueService(int id)
        {
            using (AprosysAccountingEntities db = new AprosysAccountingEntities())
            {
                var serviceTransaction = db.Acc_GL.Where(x => x.CoaId == id && x.IsActive == true).ToList();// && x.Quantity == x.QuantityBalance).ToList();
                if (serviceTransaction == null || serviceTransaction.Count > 0)
                {
                    return("Transaction is Performed against Service, it can not be deleted ");
                }

                var obj = db.Acc_COA.Where(x => x.PId == 101 && x.HeadAccount == 5 && x.CoaId == id).FirstOrDefault();
                if (obj != null && obj.CoaId > 0)
                {
                    obj.IsActive = false;
                }
                db.SaveChanges();
                return("success");
            }
        }
Пример #26
0
        public static string DeleteAdministrativeExpense(int id)
        {
            using (AprosysAccountingEntities db = new AprosysAccountingEntities())
            {
                var vendTransaction = db.Acc_GL.Where(x => x.CoaId == id && x.IsActive == true).ToList();// && x.Quantity == x.QuantityBalance).ToList();
                if (vendTransaction == null || vendTransaction.Count > 0)
                {
                    return("Transaction is Performed from Expense, it can not be deleted ");
                }


                var obj = db.Acc_COA.Where(x => x.PId == 19 && x.HeadAccount == 4 && x.CoaId == id).FirstOrDefault();
                if (obj != null && obj.CoaId > 0)
                {
                    obj.IsActive = false;
                }
                db.SaveChanges();
                return("success");
            }
        }
Пример #27
0
 public static string SaveAdministrativeExpense(string name)
 {
     using (AprosysAccountingEntities db = new AprosysAccountingEntities())
     {
         var obj = db.Acc_COA.Where(x => x.PId == 19 && x.HeadAccount == 4 && x.TreeName.ToLower() == name.ToLower() && x.IsActive == true).FirstOrDefault();
         if (obj != null)
         {
             return("Expense Already Exists");
         }
         var obj_COA = new ApprosysAccDB.Acc_COA();
         obj_COA.PId            = 19;
         obj_COA.HeadAccount    = 4;
         obj_COA.TreeName       = name;
         obj_COA.CoaLevel       = 2;
         obj_COA.OpeningBalance = 0;
         obj_COA.IsActive       = true;
         db.Acc_COA.Add(obj_COA);
         db.SaveChanges(); return("success");
         //return "success";
     }
 }
        public static string DeleteSalesPerson(int salesPersonID, int userID)
        {
            using (AprosysAccountingEntities db = new AprosysAccountingEntities())
            {
                var salespersonTransaction = db.Acc_GL.Where(x => x.SalesPersonId == salesPersonID && x.IsActive == true).ToList();// && x.Quantity == x.QuantityBalance).ToList();
                if (salespersonTransaction == null || salespersonTransaction.Count > 0)
                {
                    return("Transaction is Performed against Sales Person, it can not be deleted ");
                }

                var obj = db.SalesPersons.Where(x => x.Id == salesPersonID).FirstOrDefault();

                if (obj != null && obj.Id > 0)
                {
                    obj.ModifiedBy = userID;
                    obj.ModifiedOn = BL_Common.GetDatetime();
                }
                obj.IsActive = false;
                db.SaveChanges();
                return("success");
            }
        }
Пример #29
0
        public static string SaveGrade(int?Id, string Grade)
        {
            using (AprosysAccountingEntities db_aa = new AprosysAccountingEntities())
            {
                var chk = db_aa.OilGrades.FirstOrDefault(x => x.Id == Id) != null?db_aa.OilGrades.FirstOrDefault(x => x.Id == Id) : db_aa.OilGrades.Add(new OilGrade()
                {
                    OilGade = Grade, IsActive = true
                });

                if (chk != null || chk.Id != 0)
                {
                    chk.OilGade  = Grade;
                    chk.IsActive = true;
                    db_aa.SaveChanges();
                    return("success");
                }
                else
                {
                    return("Record Not Found");
                }
            }
        }
Пример #30
0
 public static string DeleteGradeRecord(int Id)
 {
     using (AprosysAccountingEntities db_aa = new AprosysAccountingEntities())
     {
         var chk = db_aa.Items.FirstOrDefault(x => x.OilGradeId == Id && x.IsActive == true);
         if (chk != null)
         {
             return("You Can't Delete Oil Grade Because Its being Transacted");
         }
         var delRcd = db_aa.OilGrades.FirstOrDefault(x => x.Id == Id);
         if (delRcd != null)
         {
             delRcd.IsActive = false;
             db_aa.SaveChanges();
             return("success");
         }
         else
         {
             return("Record Not Found");
         }
     }
 }