Ejemplo n.º 1
0
        public ActionResult Create()
        {
            GLHeaderModel model = SessionHelper.JV;

            if (model == null)
            {
                model = new GLHeaderModel();
                model = new GLHeaderModel
                {
                    CompanyId      = AuthenticationHelper.CompanyId.Value,
                    SOBId          = SessionHelper.SOBId,
                    GlLines        = new List <GLLinesModel>(),
                    DocumentNo     = "New",
                    ConversionRate = 1
                };
                SessionHelper.JV = model;
            }
            model.Currencies = CurrencyHelper.GetCurrencyList(SessionHelper.SOBId);
            model.Periods    = CalendarHelper.GetCalendarsList(SessionHelper.SOBId);

            if (model.Currencies != null && model.Currencies.Count() > 0)
            {
                model.CurrencyId             = Convert.ToInt64(model.Currencies.FirstOrDefault().Value);
                SessionHelper.PrecisionLimit = CurrencyHelper.GetCurrency(model.CurrencyId.ToString()).Precision;
            }
            if (model.Periods != null && model.Periods.Count() > 0)
            {
                model.PeriodId         = Convert.ToInt64(model.Periods.FirstOrDefault().Value);
                SessionHelper.Calendar = CalendarHelper.GetCalendar(model.PeriodId.ToString());
                model.GLDate           = SessionHelper.Calendar.StartDate;
            }

            return(View(model));
        }
Ejemplo n.º 2
0
        private static GLHeader getEntityByModel(GLHeaderModel model)
        {
            if (model == null)
            {
                return(null);
            }

            GLHeader entity = new GLHeader();

            entity.Id             = model.Id;
            entity.JournalName    = model.JournalName;
            entity.ConversionRate = model.ConversionRate;
            entity.CurrencyId     = model.CurrencyId;
            entity.Description    = model.Description;
            entity.DocumentNo     = model.DocumentNo;
            entity.GLDate         = model.GLDate;
            entity.PeriodId       = model.PeriodId;
            entity.SOBId          = model.SOBId;
            if (model.Id == 0)
            {
                entity.CreateBy   = AuthenticationHelper.UserId;
                entity.CreateDate = DateTime.Now;
                entity.CompanyId  = AuthenticationHelper.CompanyId.Value;
            }
            else
            {
                entity.CreateBy   = model.CreateBy;
                entity.CreateDate = model.CreateDate;
                entity.CompanyId  = model.CompanyId;
            }
            entity.UpdateBy   = AuthenticationHelper.UserId;
            entity.UpdateDate = DateTime.Now;
            return(entity);
        }
Ejemplo n.º 3
0
        public static void DeleteGLLine(GLLinesModel model)
        {
            GLHeaderModel header = SessionHelper.JV;
            GLLinesModel  glLine = header.GlLines.FirstOrDefault(x => x.Id == model.Id);

            header.GlLines.Remove(glLine);
        }
Ejemplo n.º 4
0
        public static GLHeaderModel GetVoucher(string id)
        {
            GLHeaderModel jvHeader = new GLHeaderModel(service.GetSingle(id, AuthenticationHelper.CompanyId.Value));

            jvHeader.GlLines = getGLLinesByHeaderId(id);

            return(jvHeader);
        }
Ejemplo n.º 5
0
        public static void UpdateGLLine(GLLinesModel model)
        {
            GLHeaderModel header = SessionHelper.JV;

            header.GlLines.FirstOrDefault(x => x.Id == model.Id).AccountedCr       = model.AccountedCr;
            header.GlLines.FirstOrDefault(x => x.Id == model.Id).AccountedDr       = model.AccountedDr;
            header.GlLines.FirstOrDefault(x => x.Id == model.Id).CodeCombinationId = model.CodeCombinationId;
            header.GlLines.FirstOrDefault(x => x.Id == model.Id).Description       = model.Description;
            header.GlLines.FirstOrDefault(x => x.Id == model.Id).EnteredCr         = model.EnteredCr;
            header.GlLines.FirstOrDefault(x => x.Id == model.Id).EnteredDr         = model.EnteredDr;
            header.GlLines.FirstOrDefault(x => x.Id == model.Id).Quantity          = model.Quantity;
            header.GlLines.FirstOrDefault(x => x.Id == model.Id).TaxRateCode       = model.TaxRateCode;
        }
Ejemplo n.º 6
0
        public static void Update(GLHeaderModel jv)
        {
            GLHeader entity = getEntityByModel(jv);

            string result = string.Empty;

            if (entity.IsValid())
            {
                if (jv.Id > 0)
                {
                    result = service.Update(entity);
                }
                else
                {
                    result = service.Insert(entity);
                }

                if (!string.IsNullOrEmpty(result))
                {
                    var savedLines = getGLLinesByHeaderId(result);
                    if (savedLines.Count() > jv.GlLines.Count())
                    {
                        var tobeDeleted = savedLines.Take(savedLines.Count() - jv.GlLines.Count());
                        foreach (var item in tobeDeleted)
                        {
                            lineService.Delete(item.Id.ToString(), AuthenticationHelper.CompanyId.Value);
                        }
                        savedLines = getGLLinesByHeaderId(result);
                    }

                    foreach (var line in jv.GlLines)
                    {
                        GLLines lineEntity = getEntityByModel(line, jv.ConversionRate);
                        if (lineEntity.IsValid())
                        {
                            lineEntity.HeaderId = Convert.ToInt64(result);
                            if (savedLines.Count() > 0)
                            {
                                lineEntity.Id = savedLines.FirstOrDefault().Id;
                                savedLines.Remove(savedLines.FirstOrDefault(rec => rec.Id == lineEntity.Id));
                                lineService.Update(lineEntity);
                            }
                            else
                            {
                                lineService.Insert(lineEntity);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public ActionResult Edit(string id, long currencyId, long periodId)
        {
            GLHeaderModel model = JVHelper.GetGLHeaders(id);

            SessionHelper.Calendar       = new CalendarViewModel(calendarService.GetSingle(periodId.ToString(), AuthenticationHelper.CompanyId.Value));
            SessionHelper.PrecisionLimit = currencyService.GetSingle(currencyId.ToString(), AuthenticationHelper.CompanyId.Value).Precision;

            model.GlLines    = JVHelper.GetGLLines(id);
            model.CurrencyId = currencyId;
            model.SOBId      = SessionHelper.SOBId;
            model.PeriodId   = periodId;
            SessionHelper.JV = model;

            model.Currencies = CurrencyHelper.GetCurrencyList(SessionHelper.SOBId);
            model.Periods    = CalendarHelper.GetCalendarsList(SessionHelper.SOBId);

            return(View("Create", model));
        }
Ejemplo n.º 8
0
 public ActionResult DeletePartial(GLLinesModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             GLHeaderModel header = SessionHelper.JV;
             JVHelper.DeleteGLLine(model);
             SessionHelper.JV = header;
             IList <GLLinesModel> glLines = JVHelper.GetGLLines();
             return(PartialView("createPartial", glLines));
         }
         catch (Exception e)
         {
             ViewData["EditError"] = e.Message;
         }
     }
     else
     {
         ViewData["EditError"] = "Please, correct all errors.";
     }
     return(PartialView("createPartial"));
 }
Ejemplo n.º 9
0
        public static void Insert(GLLinesModel model)
        {
            GLHeaderModel header = SessionHelper.JV;

            header.GlLines.Add(model);
        }