Esempio n. 1
0
        public ActionResult Create(GLPostingViewModel model)
        {
            if (config.IsBusinessOpen == false)
            {
                return(View("BusinessClosed"));
            }
            ViewData["GLAccounts"] = context.GLAccounts.ToList();

            if (ModelState.IsValid)
            {
                GLPosting gLPost = new GLPosting();
                gLPost.CreditAccount   = context.GLAccounts.Include(g => g.GLCategory).SingleOrDefault(x => x.Id == model.CreditAccountID);
                gLPost.DebitAccount    = context.GLAccounts.Include(g => g.GLCategory).SingleOrDefault(x => x.Id == model.DebitAccountID);
                gLPost.CreditAmount    = model.CreditAmount;
                gLPost.DebitAmount     = model.DebitAmount;
                gLPost.TransactionDate = DateTime.Now;

                if ((GLPostingLogic.CreditGL(gLPost.CreditAccount, gLPost.CreditAmount)) && (GLPostingLogic.DebitGL(gLPost.DebitAccount, gLPost.DebitAmount)))
                {
                    context.GLPostings.Add(gLPost);
                    context.SaveChanges();
                    return(RedirectToAction("Index"));
                }

                ViewBag.Error = "Error Completing Transaction";
                return(View(model));
            }

            return(View(model));
        }
Esempio n. 2
0
        // GET: GLPosting/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GLPosting gLPosting = context.GLPostings.Find(id);

            if (gLPosting == null)
            {
                return(HttpNotFound());
            }
            return(View(gLPosting));
        }
        public static List <GLPosting> fxGLPostingGet(string xmlParam)
        {
            var dbUtil     = new DatabaseManager();
            var GLPostings = new List <GLPosting>();

            using (var conn = new SqlConnection(dbUtil.getSQLConnectionString("MainDB")))
            {
                conn.Open();
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "spAccGLPostingGet";
                    cmd.Parameters.AddWithValue("@xmlParam", xmlParam);
                    cmd.CommandTimeout = 180;

                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var GLPosting = new GLPosting
                            {
                                ID               = ReferenceEquals(reader["ID"], DBNull.Value) ? Convert.ToUInt32(0) : Convert.ToUInt32(reader["ID"]),
                                datFrom          = ReferenceEquals(reader["datFrom"], DBNull.Value) ? String.Empty : Convert.ToDateTime(reader["datFrom"]).ToShortDateString(),
                                strLocation      = ReferenceEquals(reader["strLocation"], DBNull.Value) ? string.Empty : Convert.ToString(reader["strLocation"]),
                                datTo            = ReferenceEquals(reader["datTo"], DBNull.Value) ? String.Empty : Convert.ToDateTime(reader["datTo"]).ToShortDateString(),
                                strUserName      = ReferenceEquals(reader["strUserName"], DBNull.Value) ? string.Empty : Convert.ToString(reader["strUserName"]),
                                datPosted        = ReferenceEquals(reader["datPosted"], DBNull.Value) ? String.Empty : Convert.ToDateTime(reader["datPosted"]).ToShortDateString(),
                                intIDMasLocation = ReferenceEquals(reader["intIDMasLocation"], DBNull.Value) ? Convert.ToUInt16(0) : Convert.ToUInt16(reader["intIDMasLocation"]),
                                strStatus        = ReferenceEquals(reader["blnLockStatus"], DBNull.Value) ? string.Empty : Convert.ToString(reader["blnLockStatus"])
                            };

                            GLPostings.Add(GLPosting);
                        }

                        return(GLPostings);
                    }
                }
            }
        }
        public ActionResult Create(GLPosting glPost)
        {
            var glAccountRepository = new Repository <GLAccount>();

            ViewBag.GLAccounts = glAccountRepository.GetAll();
            // if (ModelState.IsValid)
            {
                try
                {
                    if (glPost.GLAccountToDebit.Id != glPost.GLAccountToCredit.Id)
                    {
                        using (ISession session = NHibernateHelper.Session)
                        {
                            using (ITransaction transaction = session.BeginTransaction())
                            {
                                var Cacc = session.Query <GLAccount>().FirstOrDefault(b => b.Id == glPost.GLAccountToCredit.Id);
                                glPost.GLAccountToCredit = Cacc;
                                var Dacc = session.Query <GLAccount>().FirstOrDefault(b => b.Id == glPost.GLAccountToDebit.Id);
                                glPost.GLAccountToDebit = Dacc;
                                glPost.TransactionDate  = DateTime.Now;

                                if (!IsAssetOrExpense(Dacc))
                                {
                                    if (Dacc.AccountBalance >= glPost.PostAmount)
                                    {
                                        Dacc.AccountBalance -= glPost.PostAmount;
                                    }
                                    else
                                    {
                                        ModelState.AddModelError("PostAmount", "Insufficient Balance");
                                    }
                                }
                                else
                                {
                                    Dacc.AccountBalance += glPost.PostAmount;
                                }
                                if (!IsAssetOrExpense(Cacc))
                                {
                                    Cacc.AccountBalance += glPost.PostAmount;
                                }
                                else
                                {
                                    if (Cacc.AccountBalance > glPost.PostAmount)
                                    {
                                        Cacc.AccountBalance -= glPost.PostAmount;
                                    }
                                    else
                                    {
                                        ModelState.AddModelError("PostAmount", "Insufficient Balance");
                                    }
                                }
                                glPost.DateAdded   = DateTime.Now;
                                glPost.DateUpdated = DateTime.Now;
                                glAccountRepository.Update(Dacc, Dacc.Id);
                                glAccountRepository.Update(Cacc, Cacc.Id);
                                _glPostingRepository.Save(glPost);
                            }
                        }
                        return(RedirectToAction("Index"));
                    }
                    ModelState.AddModelError("Id", "You cannot Post to the same account.");
                }
                catch (Exception exception)
                {
                    ViewBag.Exception = exception.Message;
                }
            }
            return(View());
        }