public ActionResult Detail(int id, string transactionType, string IndexType)
        {
            SaleOrderCancelHeader s = _SaleOrderCancelHeaderService.GetSaleOrderCancelHeader(id);

            if (s == null)
            {
                return(HttpNotFound());
            }
            SaleOrderCancelHeaderIndexViewModel svm = Mapper.Map <SaleOrderCancelHeader, SaleOrderCancelHeaderIndexViewModel>(s);

            PrepareViewBag(s.DocTypeId);
            ViewBag.Mode            = "Detail";
            ViewBag.transactionType = transactionType;
            ViewBag.IndexStatus     = IndexType;

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

            return(View("Create", svm));
        }
        public ActionResult DeleteAfter_Submit(int id)
        {
            SaleOrderCancelHeader header = _SaleOrderCancelHeaderService.Find(id);

            if (header.Status == (int)StatusConstants.Submitted || header.Status == (int)StatusConstants.Modified)
            {
                return(Remove(id));
            }
            else
            {
                return(HttpNotFound());
            }
        }
        public ActionResult Delete(int id)
        {
            SaleOrderCancelHeader header = _SaleOrderCancelHeaderService.Find(id);

            if (header.Status == (int)StatusConstants.Drafted || header.Status == (int)StatusConstants.Import)
            {
                return(Remove(id));
            }
            else
            {
                return(HttpNotFound());
            }
        }
        public ActionResult ModifyAfter_Submit(int id, string IndexType)
        {
            SaleOrderCancelHeader header = _SaleOrderCancelHeaderService.Find(id);

            if (header.Status == (int)StatusConstants.Submitted || header.Status == (int)StatusConstants.Modified || header.Status == (int)StatusConstants.ModificationSubmitted)
            {
                return(Edit(id, IndexType));
            }
            else
            {
                return(HttpNotFound());
            }
        }
        // GET: /PurchaseOrderHeader/Delete/5

        private ActionResult Remove(int id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SaleOrderCancelHeader SaleOrderCancelHeader = _SaleOrderCancelHeaderService.Find(id);

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

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

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

            if (!TimePlanValidation && !Continue)
            {
                return(PartialView("AjaxError"));
            }
            #endregion

            ReasonViewModel rvm = new ReasonViewModel()
            {
                id = id,
            };
            return(PartialView("_Reason", rvm));
        }
        public ActionResult Submit(int id, string IndexType, string TransactionType)
        {
            SaleOrderCancelHeader s = context.SaleOrderCancelHeader.Find(id);

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

            #region DocTypeTimeLineValidation


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

            if (!TimePlanValidation && !Continue)
            {
                return(RedirectToAction("Index", new { id = s.DocTypeId, IndexType = IndexType }));
            }
            #endregion
            return(RedirectToAction("Detail", new { id = id, IndexType = IndexType, transactionType = string.IsNullOrEmpty(TransactionType) ? "submit" : TransactionType }));
        }
示例#7
0
        public ActionResult SaleOrderCancelExcelImport()
        {
            int    i        = 0;
            var    file     = Request.Files[0];
            string filePath = Request.MapPath(ConfigurationManager.AppSettings["ExcelFilePath"] + file.FileName);

            file.SaveAs(filePath);
            var excel = new ExcelQueryFactory();

            //excel.FileName =ConfigurationManager.AppSettings["ExcelFilePath"]; //  @"C:\Users\guru\Downloads\PO.xls"; //TODO: Rempve hardcode
            excel.FileName = filePath;
            var SaleOrderCancelRecordList = from c in excel.Worksheet <SaleOrderCancelExcel>() select c;

            StringBuilder strSaleOrder         = new StringBuilder();
            StringBuilder strSaleOrderCancelNo = new StringBuilder();

            StringBuilder strOtherValidation = new StringBuilder();

            foreach (var SaleOrderCancelRecord in SaleOrderCancelRecordList)
            {
                if (_SaleOrderCancelHeaderService.FindByDocNo(SaleOrderCancelRecord.SaleOrderCancelNo) != null)
                {
                    if (!strSaleOrderCancelNo.ToString().Contains("" + SaleOrderCancelRecord.SaleOrderCancelNo))
                    {
                        strSaleOrderCancelNo.Append(" " + SaleOrderCancelRecord.SaleOrderCancelNo + ",");
                    }
                }

                if (_SaleOrderHeaderService.FindByDocNo(SaleOrderCancelRecord.SaleOrderNo) == null)
                {
                    if (!strSaleOrder.ToString().Contains("" + SaleOrderCancelRecord.SaleOrderNo))
                    {
                        strSaleOrder.Append(" " + SaleOrderCancelRecord.SaleOrderNo + ",");
                    }
                }


                //SaleOrderLine pol = _SaleOrderLineService.GetSaleOrderLineForSaleOrderAndProduct(SaleOrderCancelRecord.SaleOrderNo, SaleOrderCancelRecord.Product);
                decimal balqty = _SaleOrderCancelLineService.GetSaleOrderBalanceQty(SaleOrderCancelRecord.SaleOrderNo, SaleOrderCancelRecord.Product);
                if (balqty != null)
                {
                    i = i + 1;
                    if (balqty < SaleOrderCancelRecord.Quantity)
                    {
                        strOtherValidation.Append("SaleOrder Cancel qty is greater than Order qty for Sale Order " + SaleOrderCancelRecord.SaleOrderNo + " and Product " + SaleOrderCancelRecord.Product + "." + Environment.NewLine);
                    }
                }
            }


            if (!string.IsNullOrEmpty(strSaleOrderCancelNo.ToString()) || !string.IsNullOrEmpty(strSaleOrder.ToString()) || !string.IsNullOrEmpty(strOtherValidation.ToString()))
            {
                if (string.IsNullOrEmpty(strSaleOrderCancelNo.ToString()))
                {
                    ViewBag.SaleOrderCancelNo = null;
                }
                else
                {
                    ViewBag.SaleOrderCancelNo = strSaleOrderCancelNo;
                }

                if (string.IsNullOrEmpty(strSaleOrder.ToString()))
                {
                    ViewBag.SaleOrder = null;
                }
                else
                {
                    ViewBag.SaleOrder = strSaleOrder;
                }

                if (string.IsNullOrEmpty(strOtherValidation.ToString()))
                {
                    ViewBag.OtherValidation = null;
                }
                else
                {
                    ViewBag.OtherValidation = strOtherValidation;
                }

                return(View());
            }
            else
            {
                string previousRecord = null;
                int    count          = 0;

                SaleOrderCancelHeader Temp_SaleOrderCancelHeader = new SaleOrderCancelHeader();

                foreach (var SaleOrderCancelRecord in SaleOrderCancelRecordList)
                {
                    //Object for SaleOrderCancelLine Model
                    SaleOrderCancelLine sl = new SaleOrderCancelLine();
                    sl.CreatedBy               = User.Identity.Name;
                    sl.CreatedDate             = DateTime.Now;
                    sl.ModifiedBy              = User.Identity.Name;
                    sl.ModifiedDate            = DateTime.Now;
                    sl.SaleOrderCancelHeaderId = Temp_SaleOrderCancelHeader.SaleOrderCancelHeaderId;
                    sl.SaleOrderLineId         = _SaleOrderCancelLineService.GetSaleOrderLineIdForProductandSaleOrderDocNo(SaleOrderCancelRecord.SaleOrderNo, SaleOrderCancelRecord.Product);
                    sl.Qty = SaleOrderCancelRecord.Quantity;


                    if (count == 0 || SaleOrderCancelRecord.SaleOrderCancelNo != previousRecord)
                    {
                        //Object for SaleOrderCancelHeader Model

                        SaleOrderCancelHeader sh = new SaleOrderCancelHeader();
                        sh.CreatedBy    = User.Identity.Name;
                        sh.CreatedDate  = DateTime.Now;
                        sh.DivisionId   = (int)System.Web.HttpContext.Current.Session["DivisionId"];
                        sh.SiteId       = (int)System.Web.HttpContext.Current.Session["SiteId"];
                        sh.DocDate      = SaleOrderCancelRecord.CancelDate;
                        sh.DocNo        = SaleOrderCancelRecord.SaleOrderCancelNo;
                        sh.DocTypeId    = new DocumentTypeService(_unitOfWork).FindByName(TransactionDocCategoryConstants.SaleOrderCancel).DocumentTypeId;
                        sh.ModifiedBy   = User.Identity.Name;
                        sh.ModifiedDate = DateTime.Now;
                        sh.Remark       = SaleOrderCancelRecord.Remark;
                        sh.ReasonId     = new ReasonService(_unitOfWork).FindByName(TransactionDocCategoryConstants.SaleOrderCancel).ReasonId;

                        int BuyerId = (from L in db.SaleOrderLine
                                       join H in db.SaleOrderHeader on L.SaleOrderHeaderId equals H.SaleOrderHeaderId into SaleOrderHeaderTable
                                       from SaleOrderHeaderTab in SaleOrderHeaderTable.DefaultIfEmpty()
                                       where L.SaleOrderLineId == sl.SaleOrderLineId
                                       select new { BuyerId = SaleOrderHeaderTab.SaleToBuyerId }).FirstOrDefault().BuyerId;
                        sh.BuyerId = BuyerId;


                        _SaleOrderCancelHeaderService.Create(sh);
                        Temp_SaleOrderCancelHeader = sh;
                    }


                    _SaleOrderCancelLineService.Create(sl);

                    count++;
                    previousRecord = SaleOrderCancelRecord.SaleOrderCancelNo;

                    //Saving DB::
                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        throw ex;
                    }
                }

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

            SaleOrderCancelHeader s = _SaleOrderCancelHeaderService.GetSaleOrderCancelHeader(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 }));
            }

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

            if (settings == null && UserRoles.Contains("SysAdmin"))
            {
                return(RedirectToAction("CreateForCancel", "SaleOrderSettings", new { id = s.DocTypeId }).Warning("Please create Sale order Cancel settings"));
            }
            else if (settings == null && !UserRoles.Contains("SysAdmin"))
            {
                return(View("~/Views/Shared/InValidSettings.cshtml"));
            }

            SaleOrderCancelHeaderIndexViewModel svm = Mapper.Map <SaleOrderCancelHeader, SaleOrderCancelHeaderIndexViewModel>(s);
            PrepareViewBag(s.DocTypeId);
            ViewBag.Mode = "Edit";

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

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

            return(View("Create", svm));
        }
        public ActionResult HeaderPost(SaleOrderCancelHeaderIndexViewModel svm)
        {
            if (svm.BuyerId == 0)
            {
                ModelState.AddModelError("BuyerId", "The BuyerId Field is Required");
            }

            #region DocTypeTimeLineValidation

            try
            {
                if (svm.SaleOrderCancelHeaderId <= 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.SaleOrderCancelHeaderId <= 0)
                {
                    SaleOrderCancelHeader s = new SaleOrderCancelHeader();
                    s.DocTypeId    = svm.DocTypeId;
                    s.DocDate      = svm.DocDate;
                    s.DocNo        = svm.DocNo;
                    s.ReasonId     = svm.ReasonId;
                    s.BuyerId      = svm.BuyerId;
                    s.Remark       = svm.Remark;
                    s.CreatedDate  = DateTime.Now;
                    s.SiteId       = svm.SiteId;
                    s.DivisionId   = svm.DivisionId;
                    s.ModifiedDate = DateTime.Now;
                    s.CreatedBy    = User.Identity.Name;
                    s.ModifiedBy   = User.Identity.Name;
                    s.Status       = (int)StatusConstants.Drafted;
                    _SaleOrderCancelHeaderService.Create(s);

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

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

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

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


                    StringBuilder         logstring = new StringBuilder();
                    SaleOrderCancelHeader temp      = _SaleOrderCancelHeaderService.Find(svm.SaleOrderCancelHeaderId);

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


                    int status = temp.Status;

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

                    temp.DocDate  = svm.DocDate;
                    temp.DocNo    = svm.DocNo;
                    temp.BuyerId  = svm.BuyerId;
                    temp.ReasonId = svm.ReasonId;
                    temp.Remark   = svm.Remark;

                    temp.ModifiedDate = DateTime.Now;
                    temp.ModifiedBy   = User.Identity.Name;
                    _SaleOrderCancelHeaderService.Update(temp);

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

                    try
                    {
                        _unitOfWork.Save();
                    }

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

                    //Saving Activity Log::

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

                    //End of Saving ActivityLog

                    return(RedirectToAction("Index", new { id = svm.DocTypeId }).Success("Data saved successfully"));
                }
                #endregion
            }
            PrepareViewBag(svm.DocTypeId);
            ViewBag.Mode = "Add";
            return(View("Create", svm));
        }
 public SaleOrderCancelHeader Add(SaleOrderCancelHeader p)
 {
     _unitOfWork.Repository <SaleOrderCancelHeader>().Insert(p);
     return(p);
 }
 public void Update(SaleOrderCancelHeader p)
 {
     p.ObjectState = ObjectState.Modified;
     _unitOfWork.Repository <SaleOrderCancelHeader>().Update(p);
 }
 public void Delete(SaleOrderCancelHeader p)
 {
     _unitOfWork.Repository <SaleOrderCancelHeader>().Delete(p);
 }
 public SaleOrderCancelHeader Create(SaleOrderCancelHeader p)
 {
     p.ObjectState = ObjectState.Added;
     _unitOfWork.Repository <SaleOrderCancelHeader>().Insert(p);
     return(p);
 }