public bool EditGL_Transactions(LedgerVoucherModel model)
        {
            foreach (var t in model.TranList)
            {
                GL_Transactions transaction = ent.GL_Transactions.Where(x => x.TranId == t.TranID).FirstOrDefault();

                transaction.Dr_Cr      = t.Debit == "Dr" ? "D" : "C";
                transaction.LedgerId   = t.LedgerId;
                transaction.Narration1 = t.Narration1;
                if (t.Debit == "Dr")
                {
                    transaction.Amount = t.DebitAmount;
                }
                else if (t.Debit == "Cr")
                {
                    transaction.Amount = t.CreditAmount;
                }
                transaction.TranStatusId = 1;

                transaction.CheckerId         = model.AppUserId;
                transaction.CheckerDate       = DateTime.UtcNow;
                transaction.CheckerTerminalId = model.CheckerTerminal;
                transaction.CheckerRemark     = GetFormattedRemark(transaction.CheckerRemark, model.CheckerRemark, model.AppUserId);


                ent.ApplyCurrentValues(transaction.EntityKey.EntitySetName, transaction);
            }
            ent.SaveChanges();
            return(true);
        }
Example #2
0
        public ActionResult Create(LedgerVoucherModel model, FormCollection coll)
        {
            try
            {
                var   ts            = (TravelSession)Session["TravelPortalSessionInfo"];
                Int64 VoucherNumber = _ser.GetVoucherNumber(model.ProductId);

                ///////////Begin of Saving transaction info  ///////////////////////
                int totalentry = Convert.ToInt32(coll["noOfentry"]);
                List <GL_Transactions> entryDataList = new List <GL_Transactions>();
                for (int i = 0; i < totalentry; i++)
                {
                    string          Dr_Cr = coll["DrCr"] ?? coll["DrCr" + i];
                    GL_Transactions list  = new GL_Transactions();
                    if (string.IsNullOrEmpty(coll["Narration"] ?? coll["Narration" + i]) && (string.IsNullOrEmpty(coll["DrCr"] ?? coll["DrCr" + i])))
                    {
                        /////// TODO: Handle error due to java script error.Do not put this code here /////
                    }
                    else
                    {
                        list.LedgerId     = Convert.ToInt32(coll["LedgerId"] ?? coll["LedgerId" + i]);
                        list.Narration1   = coll["Narration"] ?? coll["Narration" + i];
                        list.TranDate     = model.TranDate;
                        list.ProductId    = model.ProductId;
                        list.CurrencyId   = model.CurrencyID;
                        list.TranStatusId = 1;
                        list.MakerId      = ts.AppUserId;
                        list.TranTypeId   = 2;
                        list.MakerDate    = DateTime.Now;
                        if (Dr_Cr == "Dr" || Dr_Cr == "D" || Dr_Cr == "d")
                        {
                            list.Dr_Cr  = "D";
                            list.Amount = Convert.ToDouble(coll["Debit"] ?? coll["Debit" + i]);
                        }
                        else if (Dr_Cr == "Cr" || Dr_Cr == "C" || Dr_Cr == "c")
                        {
                            list.Dr_Cr  = "C";
                            list.Amount = Convert.ToDouble(coll["Credit"] ?? coll["Credit" + i]);
                        }
                        list.VoucherNo      = VoucherNumber;
                        list.BaseCurrencyId = 1;

                        Core_FXRate ExchangeRate = ent.Core_FXRate.Where(x => (x.CurrencyID == model.CurrencyID && x.isApproved == true)).OrderByDescending(xx => xx.CreatedDate).FirstOrDefault();

                        double FXRate = 1;
                        if (ExchangeRate != null)
                        {
                            FXRate = ExchangeRate.ExchangeRate;
                        }

                        list.FXRate    = FXRate;
                        list.FCYAmount = list.Amount * FXRate;

                        list.CheckerRemark = model.CheckerRemark;
                        string clientIP;
                        clientIP = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                        if (clientIP == string.Empty)
                        {
                            clientIP = Request.ServerVariables["REMOTE_ADDR"];
                        }
                        list.CheckerTerminalId = clientIP;

                        entryDataList.Add(list);
                    }
                }
                _ser.SaveVoucher(entryDataList);
                TempData["SuccessMessage"] = "Successfully Created General Voucher";
                return(RedirectToAction("Create"));
            }
            catch (Exception ex)
            {
                TempData["ActionResponse"] = "There is an error: " + ex.Message;
                return(RedirectToAction("Create"));
            }
        }