private ActionResult _Modify(int id)
        {
            SaleDeliveryLine temp = _SaleDeliveryLineService.Find(id);

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

            #region DocTypeTimeLineValidation
            try
            {
                TimePlanValidation = DocumentValidation.ValidateDocumentLine(new DocumentUniqueId {
                    LockReason = temp.LockReason
                }, User.Identity.Name, out ExceptionMsg, out Continue);
            }
            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                TempData["CSEXCL"] += message;
                TimePlanValidation  = false;
            }

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

            if ((TimePlanValidation || Continue))
            {
                ViewBag.LineMode = "Edit";
            }

            SaleDeliveryHeader H = new SaleDeliveryHeaderService(_unitOfWork).Find(temp.SaleDeliveryHeaderId);
            PrepareViewBag();

            SaleDeliveryLineViewModel vm = _SaleDeliveryLineService.GetSaleDeliveryLineForEdit(id);
            //Getting Settings
            var settings = new SaleDeliverySettingService(_unitOfWork).GetSaleDeliverySettingForDocument(H.DocTypeId, H.DivisionId, H.SiteId);

            vm.SaleDeliverySettings = Mapper.Map <SaleDeliverySetting, SaleDeliverySettingsViewModel>(settings);

            vm.DocumentTypeSettings = new DocumentTypeSettingsService(_unitOfWork).GetDocumentTypeSettingsForDocument(H.DocTypeId);

            vm.SiteId     = H.SiteId;
            vm.DivisionId = H.DivisionId;
            vm.DocTypeId  = H.DocTypeId;

            return(PartialView("_Create", vm));
        }
Exemplo n.º 2
0
        public bool CheckForProductExists(int ProductId, int SaleDeliveryHeaderId)
        {
            SaleDeliveryLine temp = (from p in db.SaleDeliveryLine
                                     where p.SaleDeliveryHeaderId == SaleDeliveryHeaderId
                                     select p).FirstOrDefault();

            if (temp != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public ActionResult _Detail(int id)
        {
            SaleDeliveryLine temp = _SaleDeliveryLineService.Find(id);

            SaleDeliveryHeader H = new SaleDeliveryHeaderService(_unitOfWork).Find(temp.SaleDeliveryHeaderId);

            PrepareViewBag();

            SaleDeliveryLineViewModel vm = _SaleDeliveryLineService.GetSaleDeliveryLineForEdit(id);
            //Getting Settings
            var settings = new SaleDeliverySettingService(_unitOfWork).GetSaleDeliverySettingForDocument(H.DocTypeId, H.DivisionId, H.SiteId);

            vm.SaleDeliverySettings = Mapper.Map <SaleDeliverySetting, SaleDeliverySettingsViewModel>(settings);

            if (temp == null)
            {
                return(HttpNotFound());
            }
            return(PartialView("_Create", vm));
        }
        public ActionResult _ResultsPost(SaleDeliveryListViewModel vm)
        {
            int Cnt = 0;


            SaleDeliveryHeader Dh = new SaleDeliveryHeaderService(_unitOfWork).Find(vm.SaleDeliveryLineViewModel.FirstOrDefault().SaleDeliveryHeaderId);

            SaleDeliverySetting Settings = new SaleDeliverySettingService(_unitOfWork).GetSaleDeliverySettingForDocument(Dh.DocTypeId, Dh.DivisionId, Dh.SiteId);



            int pk = 0;
            int PackingPrimaryKey  = 0;
            int DeliveryPrimaryKey = 0;


            List <LineDetailListViewModel> LineList = new List <LineDetailListViewModel>();

            if (ModelState.IsValid)
            {
                foreach (var item in vm.SaleDeliveryLineViewModel)
                {
                    decimal balqty = (from p in db.ViewSaleInvoiceBalanceForDelivery
                                      where p.SaleInvoiceLineId == item.SaleInvoiceLineId
                                      select p.BalanceQty).FirstOrDefault();
                    if (item.Qty > 0 && item.Qty <= balqty)
                    {
                        SaleDeliveryLine Dl = new SaleDeliveryLine();

                        Dl.UnitConversionMultiplier = item.UnitConversionMultiplier ?? 0;
                        Dl.DealQty              = item.Qty * item.UnitConversionMultiplier ?? 0;
                        Dl.DealUnitId           = item.DealUnitId;
                        Dl.CreatedBy            = User.Identity.Name;
                        Dl.CreatedDate          = DateTime.Now;
                        Dl.ModifiedBy           = User.Identity.Name;
                        Dl.ModifiedDate         = DateTime.Now;
                        Dl.SaleDeliveryHeaderId = Dh.SaleDeliveryHeaderId;
                        Dl.Qty                = item.Qty;
                        Dl.Remark             = item.Remark;
                        Dl.SaleInvoiceLineId  = item.SaleInvoiceLineId;
                        Dl.SaleDeliveryLineId = DeliveryPrimaryKey++;
                        Dl.ObjectState        = Model.ObjectState.Added;
                        _SaleDeliveryLineService.Create(Dl);



                        LineList.Add(new LineDetailListViewModel {
                            Amount = 0, Rate = 0, LineTableId = Dl.SaleDeliveryLineId, HeaderTableId = item.SaleDeliveryHeaderId, PersonID = Dh.SaleToBuyerId
                        });

                        pk++;
                        Cnt = Cnt + 1;
                    }
                }

                new SaleDeliveryHeaderService(_unitOfWork).Update(Dh);


                try
                {
                    _unitOfWork.Save();
                }

                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    TempData["CSEXCL"] += message;
                    return(PartialView("_Results", vm));
                }

                LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                {
                    DocTypeId    = Dh.DocTypeId,
                    DocId        = Dh.SaleDeliveryHeaderId,
                    ActivityType = (int)ActivityTypeContants.MultipleCreate,
                    DocNo        = Dh.DocNo,
                    DocDate      = Dh.DocDate,
                    DocStatus    = Dh.Status,
                }));


                return(Json(new { success = true }));
            }
            return(PartialView("_Results", vm));
        }
        public ActionResult DeletePost(SaleDeliveryLineViewModel vm)
        {
            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

            int?StockId = 0;

            SaleDeliveryHeader Dh = new SaleDeliveryHeaderService(_unitOfWork).Find(vm.SaleDeliveryHeaderId);


            int status = Dh.Status;


            SaleDeliveryLine Dl = _SaleDeliveryLineService.Find(vm.SaleDeliveryLineId);



            LogList.Add(new LogTypeViewModel
            {
                ExObj = Dl,
            });



            _SaleDeliveryLineService.Delete(Dl);



            if (Dh.Status != (int)StatusConstants.Drafted)
            {
                Dh.Status = (int)StatusConstants.Modified;
                new SaleDeliveryHeaderService(_unitOfWork).Update(Dh);
            }


            XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);

            try
            {
                _unitOfWork.Save();
            }

            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                TempData["CSEXCL"] += message;
                PrepareViewBag();
                return(PartialView("_Create", vm));
            }

            LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
            {
                DocTypeId       = Dh.DocTypeId,
                DocId           = Dh.SaleDeliveryHeaderId,
                DocLineId       = Dl.SaleDeliveryLineId,
                ActivityType    = (int)ActivityTypeContants.Deleted,
                DocNo           = Dh.DocNo,
                xEModifications = Modifications,
                DocDate         = Dh.DocDate,
                DocStatus       = Dh.Status,
            }));

            return(Json(new { success = true }));
        }
        //[ValidateAntiForgeryToken]
        public ActionResult _CreatePost(SaleDeliveryLineViewModel svm)
        {
            SaleDeliverySetting Settings = new SaleDeliverySettingService(_unitOfWork).GetSaleDeliverySettingForDocument(svm.DocTypeId, svm.DivisionId, svm.SiteId);
            SaleDeliveryHeader  Dh       = new SaleDeliveryHeaderService(_unitOfWork).Find(svm.SaleDeliveryHeaderId);

            if (svm.SaleDeliveryLineId <= 0)
            {
                ViewBag.LineMode = "Create";
            }
            else
            {
                ViewBag.LineMode = "Edit";
            }

            if (svm.SaleInvoiceLineId <= 0)
            {
                ModelState.AddModelError("SaleInvoiceLineId", "Sale Invoice field is required");
            }

            if (svm.Qty <= 0)
            {
                ModelState.AddModelError("Qty", "The Qty field is required");
            }



            if (ModelState.IsValid)
            {
                if (svm.SaleDeliveryLineId <= 0)
                {
                    SaleDeliveryLine Dl = Mapper.Map <SaleDeliveryLineViewModel, SaleDeliveryLine>(svm);


                    Dl.SaleDeliveryHeaderId = Dh.SaleDeliveryHeaderId;
                    Dl.CreatedBy            = User.Identity.Name;
                    Dl.CreatedDate          = DateTime.Now;
                    Dl.ModifiedBy           = User.Identity.Name;
                    Dl.ModifiedDate         = DateTime.Now;
                    Dl.ObjectState          = Model.ObjectState.Added;
                    _SaleDeliveryLineService.Create(Dl);



                    if (Dh.Status != (int)StatusConstants.Drafted)
                    {
                        Dh.Status = (int)StatusConstants.Modified;
                    }

                    new SaleDeliveryHeaderService(_unitOfWork).Update(Dh);

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXCL"] += message;
                        PrepareViewBag();
                        return(PartialView("_Create", svm));
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId    = Dh.DocTypeId,
                        DocId        = Dl.SaleDeliveryHeaderId,
                        DocLineId    = Dl.SaleDeliveryLineId,
                        ActivityType = (int)ActivityTypeContants.Added,
                        DocNo        = Dh.DocNo,
                        DocDate      = Dh.DocDate,
                        DocStatus    = Dh.Status,
                    }));


                    return(RedirectToAction("_Create", new { id = Dh.SaleDeliveryHeaderId }));
                }
                else
                {
                    List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                    int status = Dh.Status;


                    SaleDeliveryLine Dl = _SaleDeliveryLineService.Find(svm.SaleDeliveryLineId);


                    SaleDeliveryLine ExRecD = new SaleDeliveryLine();
                    ExRecD = Mapper.Map <SaleDeliveryLine>(Dl);



                    Dl.SaleInvoiceLineId = svm.SaleInvoiceLineId;
                    Dl.Qty        = svm.Qty;
                    Dl.DealQty    = svm.DealQty;
                    Dl.DealUnitId = svm.DealUnitId;
                    Dl.Remark     = svm.Remark;
                    _SaleDeliveryLineService.Update(Dl);

                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = ExRecD,
                        Obj   = Dl,
                    });



                    if (Dh.Status != (int)StatusConstants.Drafted)
                    {
                        Dh.Status = (int)StatusConstants.Modified;
                        new SaleDeliveryHeaderService(_unitOfWork).Update(Dh);
                    }

                    XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);
                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXCL"] += message;
                        PrepareViewBag();
                        return(PartialView("_Create", svm));
                    }

                    //Saving the Activity Log

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId       = Dh.DocTypeId,
                        DocId           = Dl.SaleDeliveryHeaderId,
                        DocLineId       = Dl.SaleDeliveryLineId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        DocNo           = Dh.DocNo,
                        xEModifications = Modifications,
                        DocDate         = Dh.DocDate,
                        DocStatus       = Dh.Status,
                    }));

                    //End of Saving the Activity Log

                    return(Json(new { success = true }));
                }
            }
            PrepareViewBag();
            return(PartialView("_Create", svm));
        }
Exemplo n.º 7
0
 public void Update(SaleDeliveryLine s)
 {
     s.ObjectState = ObjectState.Modified;
     _unitOfWork.Repository <SaleDeliveryLine>().Update(s);
 }
Exemplo n.º 8
0
 public void Delete(SaleDeliveryLine s)
 {
     _unitOfWork.Repository <SaleDeliveryLine>().Delete(s);
 }
Exemplo n.º 9
0
 public SaleDeliveryLine Create(SaleDeliveryLine S)
 {
     S.ObjectState = ObjectState.Added;
     _unitOfWork.Repository <SaleDeliveryLine>().Insert(S);
     return(S);
 }
        public ActionResult Post(SaleDeliveryHeaderViewModel svm)
        {
            bool   TimePlanValidation = true;
            string ExceptionMsg       = "";
            bool   Continue           = true;

            SaleDeliveryHeader s = Mapper.Map <SaleDeliveryHeaderViewModel, SaleDeliveryHeader>(svm);
            List <SaleDeliveryWizardViewModel> SaleInvoiceAndQtys = (List <SaleDeliveryWizardViewModel>)System.Web.HttpContext.Current.Session["PendingInvoiceForSaleDelivery"];

            if (svm.SaleDeliverySettings != null)
            {
                //if (svm.SaleDeliverySettings.isMandatoryCostCenter == true && (string.IsNullOrEmpty(svm.CostCenterName)))
                //{
                //    ModelState.AddModelError("CostCenterName", "The CostCenter field is required");
                //}
            }



            if (SaleInvoiceAndQtys.Count() <= 0)
            {
                ModelState.AddModelError("", "No Records Selected");
            }

            int SaleToBuyerCnt = (from l in SaleInvoiceAndQtys
                                  group l by l.SaleToBuyerId into g
                                  select new
            {
                SaleToBuyerId = g.Key,
            }).Distinct().Count();

            if (SaleToBuyerCnt > 1)
            {
                ModelState.AddModelError("", "Select any one Buyer Orders.");
            }

            List <SaleDeliveryLine> BarCodesToUpdate = new List <SaleDeliveryLine>();

            bool CostCenterGenerated = false;

            #region DocTypeTimeLineValidation

            try
            {
                if (svm.SaleDeliveryHeaderId <= 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))
            {
                if (svm.SaleDeliveryHeaderId <= 0)
                {
                    if (SaleInvoiceAndQtys.Count() > 0)
                    {
                        s.CreatedDate  = DateTime.Now;
                        s.ModifiedDate = DateTime.Now;
                        s.CreatedBy    = User.Identity.Name;
                        s.ModifiedBy   = User.Identity.Name;
                        s.Status       = (int)StatusConstants.Drafted;
                        _SaleDeliveryHeaderService.Create(s);


                        int Cnt = 0;
                        int Sr  = 0;

                        int pk = 0;

                        SaleDeliverySetting Settings = new SaleDeliverySettingService(_unitOfWork).GetSaleDeliverySettingForDocument(s.DocTypeId, s.DivisionId, s.SiteId);


                        var SaleInvoiceLineIds = SaleInvoiceAndQtys.Select(m => m.SaleInvoiceLineId).ToArray();

                        var BalQtyandUnits = (from p in db.ViewSaleInvoiceBalanceForDelivery
                                              join t in db.Product on p.ProductId equals t.ProductId
                                              where SaleInvoiceLineIds.Contains(p.SaleInvoiceLineId)
                                              select new
                        {
                            BalQty = p.BalanceQty,
                            SaleInvoiceLineId = p.SaleInvoiceLineId,
                            UnitId = t.UnitId,
                        }).ToList();

                        if (ModelState.IsValid)
                        {
                            foreach (var SelectedSaleInvoice in SaleInvoiceAndQtys)
                            {
                                if (SelectedSaleInvoice.SaleInvoiceLineId > 0)
                                {
                                    var SaleInvoiceLine = new SaleInvoiceLineService(_unitOfWork).Find((SelectedSaleInvoice.SaleInvoiceLineId));
                                    var Product         = new ProductService(_unitOfWork).Find(SaleInvoiceLine.ProductId);


                                    var bal = BalQtyandUnits.Where(m => m.SaleInvoiceLineId == SelectedSaleInvoice.SaleInvoiceLineId).FirstOrDefault();

                                    if (SelectedSaleInvoice.Qty <= bal.BalQty)
                                    {
                                        SaleDeliveryLine line = new SaleDeliveryLine();


                                        line.SaleDeliveryHeaderId = s.SaleDeliveryHeaderId;
                                        line.SaleInvoiceLineId    = SaleInvoiceLine.SaleInvoiceLineId;
                                        line.Qty = SelectedSaleInvoice.Qty;
                                        line.UnitConversionMultiplier = SaleInvoiceLine.UnitConversionMultiplier ?? 1;
                                        line.DealQty            = SelectedSaleInvoice.Qty * line.UnitConversionMultiplier;
                                        line.DealUnitId         = SaleInvoiceLine.DealUnitId;
                                        line.Sr                 = Sr++;
                                        line.CreatedDate        = DateTime.Now;
                                        line.ModifiedDate       = DateTime.Now;
                                        line.CreatedBy          = User.Identity.Name;
                                        line.ModifiedBy         = User.Identity.Name;
                                        line.SaleDeliveryLineId = pk;
                                        line.ObjectState        = Model.ObjectState.Added;
                                        new SaleDeliveryLineService(_unitOfWork).Create(line);


                                        pk++;
                                        Cnt = Cnt + 1;
                                    }
                                }
                            }
                        }
                        string Errormessage = "";
                        try
                        {
                            _unitOfWork.Save();
                        }

                        catch (Exception ex)
                        {
                            Errormessage = _exception.HandleException(ex);
                            ModelState.AddModelError("", Errormessage);
                            PrepareViewBag();
                            ViewBag.Mode = "Add";
                            return(View("Create", svm));
                        }


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

                        System.Web.HttpContext.Current.Session.Remove("PendingInvoiceForSaleDelivery");

                        return(Redirect(System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/SaleDeliveryHeader/Submit/" + s.SaleDeliveryHeaderId));
                    }
                    else
                    {
                        return(Redirect(System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/SaleDeliveryHeader/Index/" + s.DocTypeId));
                    }
                }
                else
                {
                }
            }
            PrepareViewBag();
            ViewBag.Mode = "Add";
            return(View("Create", svm));
        }