private void PrepareViewBag(SaleOrderHeaderIndexViewModel s)
        {
            ViewBag.UnitConvForList = (from p in context.UnitConversonFor
                                       select p).ToList();
            ViewBag.Name = new DocumentTypeService(_unitOfWork).Find(s.DocTypeId).DocumentTypeName;
            ViewBag.id   = s.DocTypeId;
            //ViewBag.DivisionList = new DivisionService(_unitOfWork).GetDivisionList().ToList();
            ViewBag.ShipMethodList    = new ShipMethodService(_unitOfWork).GetShipMethodList().ToList();
            ViewBag.DeliveryTermsList = new DeliveryTermsService(_unitOfWork).GetDeliveryTermsList().ToList();
            ViewBag.BuyerList         = new BuyerService(_unitOfWork).GetBuyerList().ToList();
            ViewBag.CurrencyList      = new CurrencyService(_unitOfWork).GetCurrencyList().ToList();
            //ViewBag.SiteList = new SiteService(_unitOfWork).GetSiteList().ToList();
            List <SelectListItem> temp = new List <SelectListItem>();

            temp.Add(new SelectListItem {
                Text = Enum.GetName(typeof(SaleOrderPriority), -10), Value = ((int)(SaleOrderPriority.Low)).ToString()
            });
            temp.Add(new SelectListItem {
                Text = Enum.GetName(typeof(SaleOrderPriority), 0), Value = ((int)(SaleOrderPriority.Normal)).ToString()
            });
            temp.Add(new SelectListItem {
                Text = Enum.GetName(typeof(SaleOrderPriority), 10), Value = ((int)(SaleOrderPriority.High)).ToString()
            });

            if (s == null)
            {
                ViewBag.Priority = new SelectList(temp, "Value", "Text");
            }
            else
            {
                ViewBag.Priority = new SelectList(temp, "Value", "Text", s.Priority);
            }
        }
Пример #2
0
        public SaleOrderHeaderIndexViewModel GetSaleOrderHeaderVM(int id)
        {
            SaleOrderHeaderIndexViewModel temp = (from p in db.SaleOrderHeader
                                                  join t in db.Persons on p.SaleToBuyerId equals t.PersonID into table
                                                  from tab in table.DefaultIfEmpty()
                                                  join t2 in db.Persons on p.BillToBuyerId equals t2.PersonID into table2
                                                  from tab2 in table2.DefaultIfEmpty()

                                                  where p.SaleOrderHeaderId == id
                                                  select new SaleOrderHeaderIndexViewModel
            {
                DocTypeId = p.DocTypeId,
                BillToBuyerName = tab2.Name,
                BuyerOrderNo = p.BuyerOrderNo,
                CreatedBy = p.CreatedBy,
                CreatedDate = p.CreatedDate,
                DivisionName = p.Division.DivisionName,
                DocDate = p.DocDate,
                DocNo = p.DocNo,
                DueDate = p.DueDate,
                ModifiedBy = p.ModifiedBy,
                ModifiedDate = p.ModifiedDate,
                Remark = p.Remark,
                SaleOrderHeaderId = p.SaleOrderHeaderId,
                SaleToBuyerName = tab.Name,
                ShipAddress = p.ShipAddress,
                SiteName = p.Site.SiteName,
                SiteId = p.SiteId,
                DivisionId = p.DivisionId,
                Status = p.Status,
                DocumentTypeName = p.DocType.DocumentTypeName,
                CurrencyName = p.Currency.Name,
                ShipMethodName = p.ShipMethod.ShipMethodName,
                DeliveryTermsName = p.DeliveryTerms.DeliveryTermsName,
                CreditDays = p.CreditDays,
                TermsAndConditions = p.TermsAndConditions,
                Priority = p.Priority,
            }

                                                  ).FirstOrDefault();

            temp.PriorityName = Enum.GetName(typeof(SaleOrderPriority), temp.Priority);
            return(temp);
        }
        // GET: /SaleOrderHeader/Create

        public ActionResult Create(int id)
        {
            SaleOrderHeaderIndexViewModel p = new SaleOrderHeaderIndexViewModel();

            p.DocDate     = DateTime.Now.Date;
            p.DueDate     = DateTime.Now.Date;
            p.CreatedDate = DateTime.Now;
            p.DivisionId  = (int)System.Web.HttpContext.Current.Session["DivisionId"];
            p.SiteId      = (int)System.Web.HttpContext.Current.Session["SiteId"];
            SaleOrderSettings settings = new SaleOrderSettingsService(_unitOfWork).GetSaleOrderSettings(id, p.DivisionId, p.SiteId);

            if (settings != null)
            {
                p.DocTypeId           = id;
                p.ShipMethodId        = settings.ShipMethodId;
                p.DeliveryTermsId     = settings.DeliveryTermsId;
                p.Priority            = settings.Priority;
                p.CurrencyId          = settings.CurrencyId;
                p.UnitConversionForId = settings.UnitConversionForId;
                p.ProcessId           = settings.ProcessId;
                PrepareViewBag(p);
            }
            else
            {
                return(RedirectToAction("Edit", "SaleOrderSettings", new { id = id }).Warning("Please create sale order settings"));
            }

            if (new RolePermissionService(_unitOfWork).IsActionAllowed(UserRoles, id, settings.ProcessId, this.ControllerContext.RouteData.Values["controller"].ToString(), "Create") == false)
            {
                return(View("~/Views/Shared/PermissionDenied.cshtml").Warning("You don't have permission to do this task."));
            }

            p.SaleOrderSettings = Mapper.Map <SaleOrderSettings, SaleOrderSettingsViewModel>(settings);
            ViewBag.Mode        = "Add";
            p.DocNo             = new DocumentTypeService(_unitOfWork).FGetNewDocNo("DocNo", ConfigurationManager.AppSettings["DataBaseSchema"] + ".SaleOrderHeaders", p.DocTypeId, p.DocDate, p.DivisionId, p.SiteId);
            return(View("Create", p));
        }
        public ActionResult Detail(int id, string transactionType, string IndexType)
        {
            ViewBag.transactionType = transactionType;
            ViewBag.IndexStatus     = IndexType;

            SaleOrderHeader s = _SaleOrderHeaderService.GetSaleOrderHeader(id);
            SaleOrderHeaderIndexViewModel svm = Mapper.Map <SaleOrderHeader, SaleOrderHeaderIndexViewModel>(s);


            var settings = new SaleOrderSettingsService(_unitOfWork).GetSaleOrderSettings(s.DocTypeId, s.DivisionId, s.SiteId);

            svm.SaleOrderSettings = Mapper.Map <SaleOrderSettings, SaleOrderSettingsViewModel>(settings);


            PrepareViewBag(svm);
            if (s == null)
            {
                return(HttpNotFound());
            }

            if (String.IsNullOrEmpty(transactionType) || transactionType == "detail")
            {
                LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                {
                    DocTypeId    = s.DocTypeId,
                    DocId        = s.SaleOrderHeaderId,
                    ActivityType = (int)ActivityTypeContants.Detail,
                    DocNo        = s.DocNo,
                    DocDate      = s.DocDate,
                    DocStatus    = s.Status,
                }));
            }


            return(View("Create", svm));
        }
        // GET: /SaleOrderHeader/Edit/5
        private ActionResult Edit(int id, string IndexType)
        {
            ViewBag.IndexStatus = IndexType;

            SaleOrderHeader s = _SaleOrderHeaderService.GetSaleOrderHeader(id);

            if (s == null)
            {
                return(HttpNotFound());
            }

            if (new RolePermissionService(_unitOfWork).IsActionAllowed(UserRoles, s.DocTypeId, null, this.ControllerContext.RouteData.Values["controller"].ToString(), "Edit") == false)
            {
                return(View("~/Views/Shared/PermissionDenied.cshtml").Warning("You don't have permission to do this task."));
            }

            #region DocTypeTimeLineValidation
            try
            {
                TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(s), DocumentTimePlanTypeConstants.Modify, User.Identity.Name, out ExceptionMsg, out Continue);
            }
            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                TempData["CSEXC"] += message;
                TimePlanValidation = false;
            }

            if (!TimePlanValidation)
            {
                TempData["CSEXC"] += ExceptionMsg;
            }
            #endregion

            if ((!TimePlanValidation && !Continue))
            {
                return(RedirectToAction("DetailInformation", new { id = id, IndexType = IndexType }));
            }


            SaleOrderHeaderIndexViewModel svm = Mapper.Map <SaleOrderHeader, SaleOrderHeaderIndexViewModel>(s);
            PrepareViewBag(svm);
            ViewBag.Mode = "Edit";

            SaleOrderSettings temp = new SaleOrderSettingsService(_unitOfWork).GetSaleOrderSettings(s.DocTypeId, s.DivisionId, s.SiteId);
            svm.SaleOrderSettings = Mapper.Map <SaleOrderSettings, SaleOrderSettingsViewModel>(temp);
            svm.ProcessId         = temp.ProcessId;

            if (!(System.Web.HttpContext.Current.Request.UrlReferrer.PathAndQuery).Contains("Create"))
            {
                LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                {
                    DocTypeId    = s.DocTypeId,
                    DocId        = s.SaleOrderHeaderId,
                    ActivityType = (int)ActivityTypeContants.Detail,
                    DocNo        = s.DocNo,
                    DocDate      = s.DocDate,
                    DocStatus    = s.Status,
                }));
            }

            return(View("Create", svm));
        }
        public ActionResult HeaderPost(SaleOrderHeaderIndexViewModel svm)
        {
            if (svm.DocDate > svm.DueDate)
            {
                ModelState.AddModelError("DueDate", "DueDate cannot be greater than DocDate");
            }

            #region DocTypeTimeLineValidation

            try
            {
                if (svm.SaleOrderHeaderId <= 0)
                {
                    TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(svm), DocumentTimePlanTypeConstants.Create, User.Identity.Name, out ExceptionMsg, out Continue);
                }
                else
                {
                    TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(svm), DocumentTimePlanTypeConstants.Modify, User.Identity.Name, out ExceptionMsg, out Continue);
                }
            }
            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                TempData["CSEXC"] += message;
                TimePlanValidation = false;
            }

            if (!TimePlanValidation)
            {
                TempData["CSEXC"] += ExceptionMsg;
            }

            #endregion

            if (ModelState.IsValid && (TimePlanValidation || Continue))
            {
                #region CreateRecord
                if (svm.SaleOrderHeaderId == 0)
                {
                    SaleOrderHeader s = Mapper.Map <SaleOrderHeaderIndexViewModel, SaleOrderHeader>(svm);

                    s.ActualDueDate = s.DueDate;
                    s.CreatedDate   = DateTime.Now;
                    s.ModifiedDate  = DateTime.Now;
                    s.CreatedBy     = User.Identity.Name;
                    s.ModifiedBy    = User.Identity.Name;
                    s.Status        = (int)StatusConstants.Drafted;
                    _SaleOrderHeaderService.Create(s);

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                        PrepareViewBag(svm);
                        ViewBag.Mode = "Add";
                        return(View("Create", svm));
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId    = s.DocTypeId,
                        DocId        = s.SaleOrderHeaderId,
                        ActivityType = (int)ActivityTypeContants.Added,
                        DocNo        = s.DocNo,
                        DocDate      = s.DocDate,
                        DocStatus    = s.Status,
                    }));

                    return(RedirectToAction("Modify", new { id = s.SaleOrderHeaderId }).Success("Data saved Successfully"));
                }
                #endregion

                #region EditRecord
                else
                {
                    List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                    //string tempredirect = (Request["Redirect"].ToString());
                    SaleOrderHeader s         = Mapper.Map <SaleOrderHeaderIndexViewModel, SaleOrderHeader>(svm);
                    StringBuilder   logstring = new StringBuilder();
                    SaleOrderHeader temp      = _SaleOrderHeaderService.Find(s.SaleOrderHeaderId);

                    SaleOrderHeader ExRec = new SaleOrderHeader();
                    ExRec = Mapper.Map <SaleOrderHeader>(temp);

                    int status = temp.Status;

                    if (temp.Status != (int)StatusConstants.Drafted && temp.Status != (int)StatusConstants.Import)
                    {
                        temp.Status = (int)StatusConstants.Modified;
                    }

                    temp.DocTypeId           = s.DocTypeId;
                    temp.DocDate             = s.DocDate;
                    temp.DocNo               = s.DocNo;
                    temp.BuyerOrderNo        = s.BuyerOrderNo;
                    temp.SaleToBuyerId       = s.SaleToBuyerId;
                    temp.BillToBuyerId       = s.BillToBuyerId;
                    temp.CurrencyId          = s.CurrencyId;
                    temp.Priority            = s.Priority;
                    temp.UnitConversionForId = s.UnitConversionForId;
                    temp.ShipMethodId        = s.ShipMethodId;
                    temp.ShipAddress         = s.ShipAddress;
                    temp.DeliveryTermsId     = s.DeliveryTermsId;
                    temp.Remark              = s.Remark;
                    temp.DueDate             = s.DueDate;
                    temp.Advance             = s.Advance;
                    temp.FinancierId         = s.FinancierId;
                    temp.SalesExecutiveId    = s.SalesExecutiveId;
                    temp.ModifiedDate        = DateTime.Now;
                    temp.ModifiedBy          = User.Identity.Name;
                    _SaleOrderHeaderService.Update(temp);

                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = ExRec,
                        Obj   = temp,
                    });
                    XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);
                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                        PrepareViewBag(svm);
                        ViewBag.Mode = "Edit";
                        return(View("Create", svm));
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId       = temp.DocTypeId,
                        DocId           = temp.SaleOrderHeaderId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        DocNo           = temp.DocNo,
                        xEModifications = Modifications,
                        DocDate         = temp.DocDate,
                        DocStatus       = temp.Status,
                    }));

                    return(RedirectToAction("Index", new { id = svm.DocTypeId }).Success("Data saved successfully"));
                }
                #endregion
            }
            PrepareViewBag(svm);
            ViewBag.Mode = "Add";
            return(View("Create", svm));
        }