public void Update(PurchaseOrderAmendmentHeader pt, string UserName)
 {
     pt.ModifiedBy   = UserName;
     pt.ModifiedDate = DateTime.Now;
     pt.ObjectState  = ObjectState.Modified;
     db.PurchaseOrderAmendmentHeader.Add(pt);
 }
Exemple #2
0
        public ActionResult Submit(int id, string IndexType, string TransactionType)
        {
            #region DocTypeTimeLineValidation

            bool   TimePlanValidation = true;
            string ExceptionMsg       = "";
            bool   Continue           = true;

            PurchaseOrderAmendmentHeader s = db.PurchaseOrderAmendmentHeader.Find(id);

            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 }));
        }
Exemple #3
0
        public ActionResult Reviewed(int Id, string IndexType, string UserRemark, string IsContinue)
        {
            PurchaseOrderAmendmentHeader pd = new PurchaseOrderAmendmentHeaderService(db).Find(Id);

            if (ModelState.IsValid)
            {
                pd.ReviewCount = (pd.ReviewCount ?? 0) + 1;
                pd.ReviewBy   += User.Identity.Name + ", ";

                pd.ObjectState = Model.ObjectState.Modified;
                db.PurchaseOrderAmendmentHeader.Add(pd);

                db.SaveChanges();

                LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                {
                    DocTypeId    = pd.DocTypeId,
                    DocId        = pd.PurchaseOrderAmendmentHeaderId,
                    ActivityType = (int)ActivityTypeContants.Reviewed,
                    UserRemark   = UserRemark,
                    DocNo        = pd.DocNo,
                    DocDate      = pd.DocDate,
                    DocStatus    = pd.Status,
                }));

                if (!string.IsNullOrEmpty(IsContinue) && IsContinue == "True")
                {
                    PurchaseOrderAmendmentHeader HEader = _PurchaseOrderAmendmentHeaderService.Find(Id);

                    int nextId = new NextPrevIdService(_unitOfWork).GetNextPrevId(Id, HEader.DocTypeId, User.Identity.Name, ForActionConstants.PendingToReview, "Web.PurchaseOrderAmendmentHeaders", "PurchaseOrderAmendmentHeaderId", PrevNextConstants.Next);
                    if (nextId == 0)
                    {
                        var PendingtoSubmitCount = PendingToReviewCount(HEader.DocTypeId);
                        if (PendingtoSubmitCount > 0)
                        {
                            return(RedirectToAction("Index_PendingToReview", new { id = HEader.DocTypeId, IndexType = IndexType }).Success("Record Reviewed Successfully."));
                        }
                        else
                        {
                            return(RedirectToAction("Index", new { id = HEader.DocTypeId, IndexType = IndexType }).Success("Record Reviewed Successfully."));
                        }
                    }

                    ViewBag.PendingToReview = PendingToReviewCount(Id);
                    return(RedirectToAction("Detail", new { id = nextId, transactionType = "ReviewContinue", IndexType = IndexType }).Success("Record Reviewed Successfully."));
                }


                else
                {
                    return(RedirectToAction("Index", new { id = pd.DocTypeId, IndexType = IndexType }).Success("Record Reviewed Successfully."));
                }
            }

            return(RedirectToAction("Index", new { id = pd.DocTypeId, IndexType = IndexType }));
        }
 public PurchaseOrderAmendmentHeader Create(PurchaseOrderAmendmentHeader pt, string UserName)
 {
     pt.CreatedDate  = DateTime.Now;
     pt.ModifiedDate = DateTime.Now;
     pt.CreatedBy    = UserName;
     pt.ModifiedBy   = UserName;
     pt.ObjectState  = ObjectState.Added;
     db.PurchaseOrderAmendmentHeader.Add(pt);
     return(pt);
 }
Exemple #5
0
        public ActionResult DeleteAfter_Approve(int id)
        {
            PurchaseOrderAmendmentHeader header = _PurchaseOrderAmendmentHeaderService.Find(id);

            if (header.Status == (int)StatusConstants.Approved)
            {
                return(Remove(id));
            }
            else
            {
                return(HttpNotFound());
            }
        }
Exemple #6
0
        public ActionResult ModifyAfter_Approve(int id, string IndexType)
        {
            PurchaseOrderAmendmentHeader header = _PurchaseOrderAmendmentHeaderService.Find(id);

            if (header.Status == (int)StatusConstants.Approved)
            {
                return(Edit(id, IndexType));
            }
            else
            {
                return(HttpNotFound());
            }
        }
Exemple #7
0
        // GET: /ProductMaster/Delete/5

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

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

            #region DocTypeTimeLineValidation

            bool   TimePlanValidation = true;
            string ExceptionMsg       = "";
            try
            {
                TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(PurchaseOrderAmendmentHeader), 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 vm = new ReasonViewModel()
            {
                id = id,
            };

            return(PartialView("_Reason", vm));
        }
Exemple #8
0
        public ActionResult Detail(int id, string IndexType, string transactionType)
        {
            //var UManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db));
            //var UserRoles = UManager.GetRoles(User.Identity.GetUserId());

            ViewBag.transactionType = transactionType;
            ViewBag.IndexStatus     = IndexType;

            PurchaseOrderAmendmentHeader          pt   = _PurchaseOrderAmendmentHeaderService.Find(id);
            PurchaseOrderAmendmentHeaderViewModel temp = AutoMapper.Mapper.Map <PurchaseOrderAmendmentHeader, PurchaseOrderAmendmentHeaderViewModel>(pt);

            //Getting Settings
            var settings = new PurchaseOrderSettingService(_unitOfWork).GetPurchaseOrderSettingForDocument(pt.DocTypeId, pt.DivisionId, pt.SiteId);

            temp.PurchaseOrderSettings = Mapper.Map <PurchaseOrderSetting, PurchaseOrderSettingsViewModel>(settings);

            PrepareViewBag(pt.DocTypeId);
            if (pt == null)
            {
                return(HttpNotFound());
            }

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

            return(View("Create", temp));
        }
Exemple #9
0
        public ActionResult Post(PurchaseOrderAmendmentHeaderViewModel vm)
        {
            bool BeforeSave = true;
            int  Serial     = 1;
            Dictionary <int, decimal> LineStatus = new Dictionary <int, decimal>();

            PurchaseOrderAmendmentHeader pt = AutoMapper.Mapper.Map <PurchaseOrderAmendmentHeaderViewModel, PurchaseOrderAmendmentHeader>(vm);

            try
            {
                BeforeSave = PurchaseOrderAmendmentDocEvents.beforeWizardSaveEvent(this, new PurchaseEventArgs(vm.PurchaseOrderAmendmentHeaderId), ref db);
            }
            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                TempData["CSEXC"] += message;
                EventException     = true;
            }


            if (!BeforeSave)
            {
                TempData["CSEXC"] += "Failed validation before save";
            }


            int Cnt = 0;
            int Sr  = 0;

            List <HeaderChargeViewModel> HeaderCharges = new List <HeaderChargeViewModel>();
            List <LineChargeViewModel>   LineCharges   = new List <LineChargeViewModel>();
            int  pk = 0;
            bool HeaderChargeEdit = false;



            PurchaseOrderSetting Settings = new PurchaseOrderSettingService(_unitOfWork).GetPurchaseOrderSettingForDocument(vm.DocTypeId, vm.DivisionId, vm.SiteId);

            int?MaxLineId   = 0;
            int PersonCount = 0;

            if (!Settings.CalculationId.HasValue)
            {
                throw new Exception("Calculation not configured in Purchase order settings");
            }

            int CalculationId = Settings.CalculationId ?? 0;

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


            if (ModelState.IsValid && BeforeSave && !EventException)
            {
                pt.Status = (int)StatusConstants.Drafted;

                _PurchaseOrderAmendmentHeaderService.Create(pt, User.Identity.Name);

                var SelectedPurchaseOrders = (List <PurchaseOrderAmendmentWizardViewModel>)System.Web.HttpContext.Current.Session["RateAmendmentWizardOrders"];

                var PurchaseOrderLineIds = SelectedPurchaseOrders.Select(m => m.PurchaseOrderLineId).ToArray();

                var PurchaseOrderBalanceRecords = (from p in db.ViewPurchaseOrderBalanceForInvoice
                                                   where PurchaseOrderLineIds.Contains(p.PurchaseOrderLineId)
                                                   select p).AsNoTracking().ToList();

                var PurchaseOrderRecords = (from p in db.PurchaseOrderLine
                                            where PurchaseOrderLineIds.Contains(p.PurchaseOrderLineId)
                                            select p).AsNoTracking().ToList();

                foreach (var item in SelectedPurchaseOrders)
                {
                    PurchaseOrderLine orderline = PurchaseOrderRecords.Where(m => m.PurchaseOrderLineId == item.PurchaseOrderLineId).FirstOrDefault();
                    var balorderline            = PurchaseOrderBalanceRecords.Where(m => m.PurchaseOrderLineId == item.PurchaseOrderLineId).FirstOrDefault();

                    if (item.Rate - PurchaseOrderBalanceRecords.Where(m => m.PurchaseOrderLineId == item.PurchaseOrderLineId).FirstOrDefault().Rate != 0)
                    {
                        PurchaseOrderRateAmendmentLine line = new PurchaseOrderRateAmendmentLine();

                        line.PurchaseOrderAmendmentHeaderId = pt.PurchaseOrderAmendmentHeaderId;
                        line.PurchaseOrderLineId            = item.PurchaseOrderLineId;
                        line.Qty               = PurchaseOrderBalanceRecords.Where(m => m.PurchaseOrderLineId == item.PurchaseOrderLineId).FirstOrDefault().BalanceQty;
                        line.AmendedRate       = item.Rate;
                        line.Rate              = line.AmendedRate - balorderline.Rate;
                        line.Amount            = balorderline.BalanceQty * orderline.UnitConversionMultiplier * line.Rate;
                        line.PurchaseOrderRate = balorderline.Rate;
                        line.Sr = Serial++;
                        line.PurchaseOrderRateAmendmentLineId = pk;
                        line.CreatedDate  = DateTime.Now;
                        line.ModifiedDate = DateTime.Now;
                        line.CreatedBy    = User.Identity.Name;
                        line.ModifiedBy   = User.Identity.Name;
                        LineStatus.Add(line.PurchaseOrderLineId, line.Rate);

                        line.ObjectState = Model.ObjectState.Added;
                        db.PurchaseOrderRateAmendmentLine.Add(line);

                        if (Settings.CalculationId.HasValue)
                        {
                            LineList.Add(new LineDetailListViewModel {
                                Amount = line.Amount, Rate = line.Rate, LineTableId = line.PurchaseOrderRateAmendmentLineId, HeaderTableId = pt.PurchaseOrderAmendmentHeaderId, PersonID = pt.SupplierId, DealQty = orderline.DealQty
                            });
                        }
                        pk++;
                        Cnt = Cnt + 1;
                    }
                }

                new PurchaseOrderLineStatusService(_unitOfWork).UpdatePurchaseRateOnAmendmentMultiple(LineStatus, pt.DocDate, ref db);


                new ChargesCalculationService(_unitOfWork).CalculateCharges(LineList, pt.PurchaseOrderAmendmentHeaderId, CalculationId, MaxLineId, out LineCharges, out HeaderChargeEdit, out HeaderCharges, "Web.PurchaseOrderAmendmentHeaderCharges", "Web.PurchaseOrderRateAmendmentLineCharges", out PersonCount, pt.DocTypeId, pt.SiteId, pt.DivisionId);

                //Saving Charges
                foreach (var item in LineCharges)
                {
                    PurchaseOrderRateAmendmentLineCharge PoLineCharge = Mapper.Map <LineChargeViewModel, PurchaseOrderRateAmendmentLineCharge>(item);
                    PoLineCharge.ObjectState = Model.ObjectState.Added;
                    db.PurchaseOrderRateAmendmentLineCharge.Add(PoLineCharge);
                }


                //Saving Header charges
                for (int i = 0; i < HeaderCharges.Count(); i++)
                {
                    if (!HeaderChargeEdit)
                    {
                        PurchaseOrderAmendmentHeaderCharge POHeaderCharge = Mapper.Map <HeaderChargeViewModel, PurchaseOrderAmendmentHeaderCharge>(HeaderCharges[i]);
                        POHeaderCharge.HeaderTableId = pt.PurchaseOrderAmendmentHeaderId;
                        POHeaderCharge.PersonID      = pt.SupplierId;
                        POHeaderCharge.ObjectState   = Model.ObjectState.Added;
                        db.PurchaseOrderAmendmentHeaderCharges.Add(POHeaderCharge);
                    }
                    else
                    {
                        var footercharge = new PurchaseOrderAmendmentHeaderChargeService(_unitOfWork).Find(HeaderCharges[i].Id);
                        footercharge.Rate        = HeaderCharges[i].Rate;
                        footercharge.Amount      = HeaderCharges[i].Amount;
                        footercharge.ObjectState = Model.ObjectState.Modified;
                        db.PurchaseOrderAmendmentHeaderCharges.Add(footercharge);
                    }
                }


                try
                {
                    PurchaseOrderAmendmentDocEvents.onWizardSaveEvent(this, new PurchaseEventArgs(pt.PurchaseOrderAmendmentHeaderId, EventModeConstants.Add), ref db);
                }
                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    TempData["CSEXC"] += message;
                    EventException     = true;
                }

                try
                {
                    if (EventException)
                    {
                        throw new Exception();
                    }
                    db.SaveChanges();
                    //_unitOfWork.Save();
                }

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

                try
                {
                    PurchaseOrderAmendmentDocEvents.afterWizardSaveEvent(this, new PurchaseEventArgs(pt.PurchaseOrderAmendmentHeaderId, EventModeConstants.Add), ref db);
                }
                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    TempData["CSEXC"] += message;
                }

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

                Session.Remove("RateAmendmentWizardOrders");

                return(RedirectToAction("Index", "PurchaseOrderAmendmentHeader", new { id = pt.DocTypeId }).Success("Data saved Successfully"));
            }
            PrepareViewBag(vm.DocTypeId);
            ViewBag.Mode = "Add";
            return(View("Create", vm));
        }
Exemple #10
0
        public ActionResult ConfirmedPurchaseOrders(List <PurchaseOrderAmendmentWizardViewModel> ConfirmedList, int DocTypeId, string UserRemark)
        {
            //System.Web.HttpContext.Current.Session["RateAmendmentWizardOrders"] = ConfirmedList;
            //return Json(new { Success = "URL", Data = "/PurchaseOrderRateAmendmentWizard/Create/" + DocTypeId }, JsonRequestBehavior.AllowGet);

            if (ConfirmedList.Count() > 0 && ConfirmedList.GroupBy(m => m.SupplierId).Count() > 1)
            {
                return(Json(new { Success = false, Data = " Multiple Headers are selected. " }, JsonRequestBehavior.AllowGet));
            }
            else if (ConfirmedList.Count() == 0)
            {
                return(Json(new { Success = false, Data = " No Records are selected. " }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                int DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"];
                int SiteId     = (int)System.Web.HttpContext.Current.Session["SiteId"];

                bool BeforeSave = true;
                int  Serial     = 1;
                Dictionary <int, decimal> LineStatus = new Dictionary <int, decimal>();

                try
                {
                    BeforeSave = PurchaseOrderAmendmentDocEvents.beforeWizardSaveEvent(this, new PurchaseEventArgs(0), ref db);
                }
                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    return(Json(new { Success = false, Data = message }, JsonRequestBehavior.AllowGet));
                }


                if (!BeforeSave)
                {
                    TempData["CSEXC"] += "Failed validation before save";
                }


                int Cnt = 0;
                int Sr  = 0;

                List <HeaderChargeViewModel> HeaderCharges = new List <HeaderChargeViewModel>();
                List <LineChargeViewModel>   LineCharges   = new List <LineChargeViewModel>();
                int  pk = 0;
                bool HeaderChargeEdit = false;



                PurchaseOrderSetting Settings = new PurchaseOrderSettingService(_unitOfWork).GetPurchaseOrderSettingForDocument(DocTypeId, DivisionId, SiteId);

                int?MaxLineId   = 0;
                int PersonCount = 0;
                if (!Settings.CalculationId.HasValue)
                {
                    throw new Exception("Calculation not configured in Purchase order settings");
                }

                int CalculationId = Settings.CalculationId ?? 0;

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


                if (ModelState.IsValid && BeforeSave && !EventException)
                {
                    PurchaseOrderAmendmentHeader pt = new PurchaseOrderAmendmentHeader();

                    //Getting Settings
                    pt.SiteId     = SiteId;
                    pt.SupplierId = ConfirmedList.FirstOrDefault().SupplierId;
                    pt.DivisionId = DivisionId;
                    pt.DocTypeId  = DocTypeId;
                    pt.DocDate    = DateTime.Now;
                    pt.DocNo      = new DocumentTypeService(_unitOfWork).FGetNewDocNo("DocNo", ConfigurationManager.AppSettings["DataBaseSchema"] + ".PurchaseOrderAmendmentHeaders", pt.DocTypeId, pt.DocDate, pt.DivisionId, pt.SiteId);


                    pt.Status = (int)StatusConstants.Drafted;

                    _PurchaseOrderAmendmentHeaderService.Create(pt, User.Identity.Name);

                    var SelectedPurchaseOrders = ConfirmedList;

                    var PurchaseOrderLineIds = SelectedPurchaseOrders.Select(m => m.PurchaseOrderLineId).ToArray();

                    var PurchaseOrderBalanceRecords = (from p in db.ViewPurchaseOrderBalanceForInvoice
                                                       where PurchaseOrderLineIds.Contains(p.PurchaseOrderLineId)
                                                       select p).AsNoTracking().ToList();

                    var PurchaseOrderRecords = (from p in db.PurchaseOrderLine
                                                where PurchaseOrderLineIds.Contains(p.PurchaseOrderLineId)
                                                select p).AsNoTracking().ToList();

                    foreach (var item in SelectedPurchaseOrders)
                    {
                        PurchaseOrderLine orderline = PurchaseOrderRecords.Where(m => m.PurchaseOrderLineId == item.PurchaseOrderLineId).FirstOrDefault();
                        var balorderline            = PurchaseOrderBalanceRecords.Where(m => m.PurchaseOrderLineId == item.PurchaseOrderLineId).FirstOrDefault();

                        if (item.Rate - PurchaseOrderBalanceRecords.Where(m => m.PurchaseOrderLineId == item.PurchaseOrderLineId).FirstOrDefault().Rate != 0)
                        {
                            PurchaseOrderRateAmendmentLine line = new PurchaseOrderRateAmendmentLine();

                            line.PurchaseOrderAmendmentHeaderId = pt.PurchaseOrderAmendmentHeaderId;
                            line.PurchaseOrderLineId            = item.PurchaseOrderLineId;
                            line.Qty               = PurchaseOrderBalanceRecords.Where(m => m.PurchaseOrderLineId == item.PurchaseOrderLineId).FirstOrDefault().BalanceQty;
                            line.AmendedRate       = item.Rate;
                            line.Rate              = line.AmendedRate - balorderline.Rate;
                            line.Amount            = balorderline.BalanceQty * orderline.UnitConversionMultiplier * line.Rate;
                            line.PurchaseOrderRate = balorderline.Rate;
                            line.Sr = Serial++;
                            line.PurchaseOrderRateAmendmentLineId = pk;
                            line.CreatedDate  = DateTime.Now;
                            line.ModifiedDate = DateTime.Now;
                            line.CreatedBy    = User.Identity.Name;
                            line.ModifiedBy   = User.Identity.Name;
                            LineStatus.Add(line.PurchaseOrderLineId, line.Rate);

                            line.ObjectState = Model.ObjectState.Added;
                            db.PurchaseOrderRateAmendmentLine.Add(line);

                            if (Settings.CalculationId.HasValue)
                            {
                                LineList.Add(new LineDetailListViewModel {
                                    Amount = line.Amount, Rate = line.Rate, LineTableId = line.PurchaseOrderRateAmendmentLineId, HeaderTableId = pt.PurchaseOrderAmendmentHeaderId, PersonID = pt.SupplierId, DealQty = orderline.DealQty
                                });
                            }
                            pk++;
                            Cnt = Cnt + 1;
                        }
                    }

                    new PurchaseOrderLineStatusService(_unitOfWork).UpdatePurchaseRateOnAmendmentMultiple(LineStatus, pt.DocDate, ref db);


                    new ChargesCalculationService(_unitOfWork).CalculateCharges(LineList, pt.PurchaseOrderAmendmentHeaderId, CalculationId, MaxLineId, out LineCharges, out HeaderChargeEdit, out HeaderCharges, "Web.PurchaseOrderAmendmentHeaderCharges", "Web.PurchaseOrderRateAmendmentLineCharges", out PersonCount, pt.DocTypeId, pt.SiteId, pt.DivisionId);

                    //Saving Charges
                    foreach (var item in LineCharges)
                    {
                        PurchaseOrderRateAmendmentLineCharge PoLineCharge = Mapper.Map <LineChargeViewModel, PurchaseOrderRateAmendmentLineCharge>(item);
                        PoLineCharge.ObjectState = Model.ObjectState.Added;
                        db.PurchaseOrderRateAmendmentLineCharge.Add(PoLineCharge);
                    }


                    //Saving Header charges
                    for (int i = 0; i < HeaderCharges.Count(); i++)
                    {
                        if (!HeaderChargeEdit)
                        {
                            PurchaseOrderAmendmentHeaderCharge POHeaderCharge = Mapper.Map <HeaderChargeViewModel, PurchaseOrderAmendmentHeaderCharge>(HeaderCharges[i]);
                            POHeaderCharge.HeaderTableId = pt.PurchaseOrderAmendmentHeaderId;
                            POHeaderCharge.PersonID      = pt.SupplierId;
                            POHeaderCharge.ObjectState   = Model.ObjectState.Added;
                            db.PurchaseOrderAmendmentHeaderCharges.Add(POHeaderCharge);
                        }
                        else
                        {
                            var footercharge = new PurchaseOrderAmendmentHeaderChargeService(_unitOfWork).Find(HeaderCharges[i].Id);
                            footercharge.Rate        = HeaderCharges[i].Rate;
                            footercharge.Amount      = HeaderCharges[i].Amount;
                            footercharge.ObjectState = Model.ObjectState.Modified;
                            db.PurchaseOrderAmendmentHeaderCharges.Add(footercharge);
                        }
                    }


                    try
                    {
                        PurchaseOrderAmendmentDocEvents.onWizardSaveEvent(this, new PurchaseEventArgs(pt.PurchaseOrderAmendmentHeaderId, EventModeConstants.Add), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                        EventException     = true;
                    }

                    try
                    {
                        if (EventException)
                        {
                            throw new Exception();
                        }
                        db.SaveChanges();
                        //_unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        return(Json(new { Success = false, Data = message }, JsonRequestBehavior.AllowGet));
                    }

                    try
                    {
                        PurchaseOrderAmendmentDocEvents.afterWizardSaveEvent(this, new PurchaseEventArgs(pt.PurchaseOrderAmendmentHeaderId, EventModeConstants.Add), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                    }

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

                    return(Json(new { Success = "URL", Data = "/PurchaseOrderAmendmentHeader/Submit/" + pt.PurchaseOrderAmendmentHeaderId }, JsonRequestBehavior.AllowGet));
                }

                else
                {
                    return(Json(new { Success = false, Data = "ModelState is Invalid" }, JsonRequestBehavior.AllowGet));
                }
            }
        }
 public void Delete(PurchaseOrderAmendmentHeader pt)
 {
     db.PurchaseOrderAmendmentHeader.Remove(pt);
 }
        public void Delete(int id)
        {
            PurchaseOrderAmendmentHeader Header = db.PurchaseOrderAmendmentHeader.Find(id);

            db.PurchaseOrderAmendmentHeader.Remove(Header);
        }
Exemple #13
0
        // GET: /ProductMaster/Edit/5

        private ActionResult Edit(int id, string IndexType)
        {
            ViewBag.IndexStatus = IndexType;
            PurchaseOrderAmendmentHeader pt = _PurchaseOrderAmendmentHeaderService.Find(id);

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

            PurchaseOrderAmendmentHeaderViewModel temp = AutoMapper.Mapper.Map <PurchaseOrderAmendmentHeader, PurchaseOrderAmendmentHeaderViewModel>(pt);

            #region DocTypeTimeLineValidation
            try
            {
                TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(pt), 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 }));
            }
            //Purchase Order Settings
            var settings = new PurchaseOrderSettingService(_unitOfWork).GetPurchaseOrderSettingForDocument(pt.DocTypeId, pt.DivisionId, pt.SiteId);

            if (settings == null && UserRoles.Contains("SysAdmin"))
            {
                return(RedirectToAction("Create", "PurchaseOrderSettings", new { id = pt.DocTypeId }).Warning("Please create Purchase order settings"));
            }
            else if (settings == null && !UserRoles.Contains("SysAdmin"))
            {
                return(View("~/Views/Shared/InValidSettings.cshtml"));
            }

            temp.PurchaseOrderSettings = Mapper.Map <PurchaseOrderSetting, PurchaseOrderSettingsViewModel>(settings);

            PrepareViewBag(pt.DocTypeId);
            ViewBag.Mode = "Edit";

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


            return(View("Create", temp));
        }
Exemple #14
0
        public ActionResult Post(PurchaseOrderAmendmentHeaderViewModel vm)
        {
            bool BeforeSave = true;

            PurchaseOrderAmendmentHeader pt = AutoMapper.Mapper.Map <PurchaseOrderAmendmentHeaderViewModel, PurchaseOrderAmendmentHeader>(vm);

            #region BeforeSave
            try
            {
                if (vm.PurchaseOrderAmendmentHeaderId <= 0)
                {
                    BeforeSave = PurchaseOrderAmendmentDocEvents.beforeHeaderSaveEvent(this, new PurchaseEventArgs(vm.PurchaseOrderAmendmentHeaderId, EventModeConstants.Add), ref db);
                }
                else
                {
                    BeforeSave = PurchaseOrderAmendmentDocEvents.beforeHeaderSaveEvent(this, new PurchaseEventArgs(vm.PurchaseOrderAmendmentHeaderId, EventModeConstants.Edit), ref db);
                }
            }
            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                TempData["CSEXC"] += message;
                EventException     = true;
            }


            if (!BeforeSave)
            {
                TempData["CSEXC"] += "Failed validation before save";
            }
            #endregion

            #region DocTypeTimeLineValidation

            try
            {
                if (vm.PurchaseOrderAmendmentHeaderId <= 0)
                {
                    TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(vm), DocumentTimePlanTypeConstants.Create, User.Identity.Name, out ExceptionMsg, out Continue);
                }
                else
                {
                    TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(vm), 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 && BeforeSave && !EventException && (TimePlanValidation || Continue))
            {
                #region CreateRecord
                if (vm.PurchaseOrderAmendmentHeaderId <= 0)
                {
                    pt.Status = (int)StatusConstants.Drafted;

                    _PurchaseOrderAmendmentHeaderService.Create(pt, User.Identity.Name);

                    try
                    {
                        PurchaseOrderAmendmentDocEvents.onHeaderSaveEvent(this, new PurchaseEventArgs(pt.PurchaseOrderAmendmentHeaderId, EventModeConstants.Add), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                        EventException     = true;
                    }

                    try
                    {
                        if (EventException)
                        {
                            throw new Exception();
                        }
                        db.SaveChanges();
                        //_unitOfWork.Save();
                    }

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

                    try
                    {
                        PurchaseOrderAmendmentDocEvents.afterHeaderSaveEvent(this, new PurchaseEventArgs(pt.PurchaseOrderAmendmentHeaderId, EventModeConstants.Add), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                    }

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

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

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

                    PurchaseOrderAmendmentHeader temp = _PurchaseOrderAmendmentHeaderService.Find(pt.PurchaseOrderAmendmentHeaderId);


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


                    int status = temp.Status;

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

                    temp.DocDate    = pt.DocDate;
                    temp.DocNo      = pt.DocNo;
                    temp.DocTypeId  = pt.DocTypeId;
                    temp.Remark     = pt.Remark;
                    temp.SupplierId = pt.SupplierId;

                    _PurchaseOrderAmendmentHeaderService.Update(temp, User.Identity.Name);

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



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

                    try
                    {
                        PurchaseOrderAmendmentDocEvents.onHeaderSaveEvent(this, new PurchaseEventArgs(temp.PurchaseOrderAmendmentHeaderId, EventModeConstants.Edit), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                        EventException     = true;
                    }

                    try
                    {
                        if (EventException)
                        {
                            throw new Exception();
                        }
                        db.SaveChanges();
                        //_unitOfWork.Save();
                    }

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

                    try
                    {
                        PurchaseOrderAmendmentDocEvents.afterHeaderSaveEvent(this, new PurchaseEventArgs(pt.PurchaseOrderAmendmentHeaderId, EventModeConstants.Edit), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                    }

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

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