Exemplo n.º 1
0
        public ActionResult DeletePost(PurchaseIndentLineViewModel vm)
        {
            bool BeforeSave = true;

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

            if (!BeforeSave)
            {
                TempData["CSEXC"] += "Validation failed before delete.";
            }

            if (BeforeSave && !EventException)
            {
                List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                PurchaseIndentLine PurchaseIndentLine = db.PurchaseIndentLine.Find(vm.PurchaseIndentLineId);

                try
                {
                    PurchaseIndentDocEvents.onLineDeleteEvent(this, new PurchaseEventArgs(PurchaseIndentLine.PurchaseIndentHeaderId, PurchaseIndentLine.PurchaseIndentLineId), ref db);
                }
                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    TempData["CSEXCL"] += message;
                    EventException      = true;
                }

                LogList.Add(new LogTypeViewModel
                {
                    ExObj = Mapper.Map <PurchaseIndentLine>(PurchaseIndentLine),
                });

                //_PurchaseIndentLineService.Delete(PurchaseIndentLine);
                PurchaseIndentHeader header = new PurchaseIndentHeaderService(_unitOfWork).Find(PurchaseIndentLine.PurchaseIndentHeaderId);
                if (header.Status != (int)StatusConstants.Drafted)
                {
                    header.Status = (int)StatusConstants.Modified;
                    //new PurchaseIndentHeaderService(_unitOfWork).Update(header);
                    header.ModifiedBy   = User.Identity.Name;
                    header.ModifiedDate = DateTime.Now;
                    header.ObjectState  = Model.ObjectState.Modified;
                    db.PurchaseIndentHeader.Add(header);
                }

                PurchaseIndentLine.ObjectState = Model.ObjectState.Deleted;
                db.PurchaseIndentLine.Remove(PurchaseIndentLine);

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

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

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

                try
                {
                    PurchaseIndentDocEvents.afterLineDeleteEvent(this, new PurchaseEventArgs(PurchaseIndentLine.PurchaseIndentHeaderId, PurchaseIndentLine.PurchaseIndentLineId), ref db);
                }
                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    TempData["CSEXC"] += message;
                }

                LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                {
                    DocTypeId       = header.DocTypeId,
                    DocId           = header.PurchaseIndentHeaderId,
                    DocLineId       = PurchaseIndentLine.PurchaseIndentLineId,
                    ActivityType    = (int)ActivityTypeContants.Deleted,
                    DocNo           = header.DocNo,
                    xEModifications = Modifications,
                    DocDate         = header.DocDate,
                    DocStatus       = header.Status,
                }));
            }
            return(Json(new { success = true }));
        }
Exemplo n.º 2
0
        public ActionResult _ResultsPost(PurchaseIndentMasterDetailModel vm)
        {
            int  Serial     = _PurchaseIndentLineService.GetMaxSr(vm.PurchaseIndentLineViewModel.FirstOrDefault().PurchaseIndentHeaderId);
            bool BeforeSave = true;

            try
            {
                BeforeSave = PurchaseIndentDocEvents.beforeLineSaveBulkEvent(this, new PurchaseEventArgs(vm.PurchaseIndentLineViewModel.FirstOrDefault().PurchaseIndentHeaderId), ref db);
            }
            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                TempData["CSEXCL"] += message;
                EventException      = true;
            }

            if (!BeforeSave)
            {
                ModelState.AddModelError("", "Validation failed before save");
            }

            if (ModelState.IsValid && BeforeSave && !EventException)
            {
                PurchaseIndentHeader header = new PurchaseIndentHeaderService(_unitOfWork).Find(vm.PurchaseIndentLineViewModel.FirstOrDefault().PurchaseIndentHeaderId);
                if (header.Status != (int)StatusConstants.Drafted && header.Status != (int)StatusConstants.Import)
                {
                    header.Status       = (int)StatusConstants.Modified;
                    header.ModifiedBy   = User.Identity.Name;
                    header.ModifiedDate = DateTime.Now;
                    header.ObjectState  = Model.ObjectState.Modified;
                    db.PurchaseIndentHeader.Add(header);
                }

                foreach (var item in vm.PurchaseIndentLineViewModel)
                {
                    if (item.Qty > 0)
                    {
                        PurchaseIndentLine line = new PurchaseIndentLine();

                        line.PurchaseIndentHeaderId = item.PurchaseIndentHeaderId;
                        line.MaterialPlanLineId     = item.MaterialPlanLineId;
                        line.ProductId     = item.ProductId;
                        line.Dimension1Id  = item.Dimension1Id;
                        line.Dimension2Id  = item.Dimension2Id;
                        line.Specification = item.Specification;
                        line.Remark        = item.Remark;
                        line.Qty           = item.Qty;
                        line.Sr            = Serial++;
                        line.CreatedDate   = DateTime.Now;
                        line.ModifiedDate  = DateTime.Now;
                        line.CreatedBy     = User.Identity.Name;
                        line.ModifiedBy    = User.Identity.Name;

                        line.ObjectState = Model.ObjectState.Added;
                        //_PurchaseIndentLineService.Create(line);
                        db.PurchaseIndentLine.Add(line);
                    }
                }

                try
                {
                    PurchaseIndentDocEvents.onLineSaveBulkEvent(this, new PurchaseEventArgs(vm.PurchaseIndentLineViewModel.FirstOrDefault().PurchaseIndentHeaderId), ref db);
                }
                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    TempData["CSEXCL"] += message;
                    EventException      = true;
                }

                try
                {
                    if (EventException)
                    {
                        throw new Exception();
                    }

                    db.SaveChanges();
                    //_unitOfWork.Save();
                }

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

                try
                {
                    PurchaseIndentDocEvents.afterLineSaveBulkEvent(this, new PurchaseEventArgs(vm.PurchaseIndentLineViewModel.FirstOrDefault().PurchaseIndentHeaderId), ref db);
                }
                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    TempData["CSEXC"] += message;
                }

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

                return(Json(new { success = true }));
            }
            return(PartialView("_Results", vm));
        }
Exemplo n.º 3
0
        public ActionResult _CreatePost(PurchaseIndentLineViewModel svm)
        {
            PurchaseIndentLine   s    = Mapper.Map <PurchaseIndentLineViewModel, PurchaseIndentLine>(svm);
            PurchaseIndentHeader temp = new PurchaseIndentHeaderService(_unitOfWork).Find(s.PurchaseIndentHeaderId);

            ViewBag.Status = temp.Status;

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

            if (temp.DocDate > s.DueDate && s.DueDate != null)
            {
                ModelState.AddModelError("DueDate", "Duedate should be greater than Docdate");
            }
            if (s.Qty <= 0)
            {
                ModelState.AddModelError("Qty", "Qty field is required");
            }

            bool BeforeSave = true;

            try
            {
                if (svm.PurchaseIndentLineId <= 0)
                {
                    BeforeSave = PurchaseIndentDocEvents.beforeLineSaveEvent(this, new PurchaseEventArgs(svm.PurchaseIndentHeaderId, EventModeConstants.Add), ref db);
                }
                else
                {
                    BeforeSave = PurchaseIndentDocEvents.beforeLineSaveEvent(this, new PurchaseEventArgs(svm.PurchaseIndentHeaderId, EventModeConstants.Edit), ref db);
                }
            }
            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                TempData["CSEXCL"] += message;
                EventException      = true;
            }

            if (!BeforeSave)
            {
                ModelState.AddModelError("", "Validation failed before save.");
            }


            if (ModelState.IsValid && BeforeSave && !EventException)
            {
                if (svm.PurchaseIndentLineId <= 0)
                {
                    s.Sr           = _PurchaseIndentLineService.GetMaxSr(s.PurchaseIndentHeaderId);
                    s.CreatedDate  = DateTime.Now;
                    s.ModifiedDate = DateTime.Now;
                    s.CreatedBy    = User.Identity.Name;
                    s.ModifiedBy   = User.Identity.Name;
                    s.ObjectState  = Model.ObjectState.Added;
                    //_PurchaseIndentLineService.Create(s);
                    db.PurchaseIndentLine.Add(s);

                    PurchaseIndentHeader header = new PurchaseIndentHeaderService(_unitOfWork).Find(s.PurchaseIndentHeaderId);
                    if (header.Status != (int)StatusConstants.Drafted)
                    {
                        header.Status = (int)StatusConstants.Modified;
                        //new PurchaseIndentHeaderService(_unitOfWork).Update(header);
                        header.ModifiedBy   = User.Identity.Name;
                        header.ModifiedDate = DateTime.Now;
                        header.ObjectState  = Model.ObjectState.Modified;
                        db.PurchaseIndentHeader.Add(header);
                    }

                    try
                    {
                        PurchaseIndentDocEvents.onLineSaveEvent(this, new PurchaseEventArgs(s.PurchaseIndentHeaderId, s.PurchaseIndentLineId, EventModeConstants.Add), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXCL"] += message;
                        EventException      = true;
                    }


                    try
                    {
                        if (EventException)
                        {
                            throw new Exception();
                        }

                        db.SaveChanges();
                        //_unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXCL"] += message;
                        return(PartialView("_Create", svm));
                    }
                    try
                    {
                        PurchaseIndentDocEvents.afterLineSaveEvent(this, new PurchaseEventArgs(s.PurchaseIndentHeaderId, s.PurchaseIndentLineId, EventModeConstants.Add), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXCL"] += message;
                    }

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

                    return(RedirectToAction("_Create", new { id = svm.PurchaseIndentHeaderId, date = ((svm.DueDate == null) ? null : svm.DueDate) }));
                    //return _Create(svm.PurchaseIndentHeaderId, ((svm.DueDate == null) ? null : svm.DueDate));
                }


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

                    PurchaseIndentLine templine = _PurchaseIndentLineService.Find(s.PurchaseIndentLineId);

                    int Status = temp.Status;
                    PurchaseIndentLine ExRec = new PurchaseIndentLine();
                    ExRec = Mapper.Map <PurchaseIndentLine>(templine);


                    templine.DueDate       = s.DueDate;
                    templine.ProductId     = s.ProductId;
                    templine.Qty           = s.Qty;
                    templine.Remark        = s.Remark;
                    templine.Dimension1Id  = s.Dimension1Id;
                    templine.Dimension2Id  = s.Dimension2Id;
                    templine.Specification = s.Specification;
                    templine.ModifiedDate  = DateTime.Now;
                    templine.ModifiedBy    = User.Identity.Name;
                    //_PurchaseIndentLineService.Update(templine);
                    templine.ObjectState = Model.ObjectState.Modified;
                    db.PurchaseIndentLine.Add(templine);

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



                    if (temp.Status != (int)StatusConstants.Drafted)
                    {
                        temp.Status = (int)StatusConstants.Modified;
                        //new PurchaseIndentHeaderService(_unitOfWork).Update(temp);
                        temp.ModifiedDate = DateTime.Now;
                        temp.ModifiedBy   = User.Identity.Name;
                        temp.ObjectState  = Model.ObjectState.Modified;
                        db.PurchaseIndentHeader.Add(temp);
                    }

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

                    try
                    {
                        PurchaseIndentDocEvents.onLineSaveEvent(this, new PurchaseEventArgs(s.PurchaseIndentHeaderId, templine.PurchaseIndentLineId, EventModeConstants.Edit), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXCL"] += message;
                        EventException      = true;
                    }

                    try
                    {
                        if (EventException)
                        {
                            throw new Exception();
                        }

                        db.SaveChanges();
                        //_unitOfWork.Save();
                    }

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

                    try
                    {
                        PurchaseIndentDocEvents.afterLineSaveEvent(this, new PurchaseEventArgs(s.PurchaseIndentHeaderId, templine.PurchaseIndentLineId, 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           = templine.PurchaseIndentHeaderId,
                        DocLineId       = templine.PurchaseIndentLineId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        DocNo           = temp.DocNo,
                        xEModifications = Modifications,
                        DocDate         = temp.DocDate,
                        DocStatus       = temp.Status,
                    }));

                    return(Json(new { success = true }));
                }
            }

            return(PartialView("_Create", svm));
        }
Exemplo n.º 4
0
        public ActionResult Post(MaterialPlanHeaderViewModel vm)
        {
            MaterialPlanHeader pt = AutoMapper.Mapper.Map <MaterialPlanHeaderViewModel, MaterialPlanHeader>(vm);

            //#region DocTypeTimeLineValidation

            //try
            //{

            //    if (vm.MaterialPlanHeaderId <= 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 && (TimePlanValidation || Continue))
            {
                #region CreateRecord
                if (vm.MaterialPlanHeaderId <= 0)
                {
                    using (var context = new ApplicationDbContext())
                    {
                        pt.CreatedDate  = DateTime.Now;
                        pt.ModifiedDate = DateTime.Now;
                        pt.CreatedBy    = User.Identity.Name;
                        pt.ModifiedBy   = User.Identity.Name;
                        pt.ObjectState  = Model.ObjectState.Added;
                        context.MaterialPlanHeader.Add(pt);

                        int Serial = 0;

                        MaterialPlanLineListViewModel svm = new MaterialPlanLineListViewModel();
                        svm.MaterialPlanLineViewModel = (List <MaterialPlanForSaleOrderViewModel>)System.Web.HttpContext.Current.Session["SODyeingPlan"];

                        var Summary = (IEnumerable <MaterialPlanLineViewModel>)System.Web.HttpContext.Current.Session["SODyeingPlanSummary"];

                        MaterialPlanSettings Settings = new MaterialPlanSettingsService(_unitOfWork).GetMaterialPlanSettingsForDocument(pt.DocTypeId, pt.DivisionId, pt.SiteId);


                        bool isPr = false;
                        bool isPP = false;
                        int  j    = 0;
                        foreach (var item in Summary)
                        {
                            {
                                MaterialPlanLine planLine = new MaterialPlanLine();
                                planLine.RequiredQty          = item.RequiredQty;
                                planLine.ExcessStockQty       = item.ExcessStockQty;
                                planLine.MaterialPlanHeaderId = item.MaterialPlanHeaderId;
                                planLine.ProductId            = item.ProductId;
                                planLine.Dimension1Id         = item.Dimension1Id;
                                planLine.Dimension2Id         = item.Dimension2Id;
                                planLine.ProdPlanQty          = item.ProdPlanQty;
                                planLine.CreatedBy            = User.Identity.Name;
                                planLine.CreatedDate          = DateTime.Now;
                                planLine.Sr                 = Serial++;
                                planLine.Specification      = item.Specification;
                                planLine.ModifiedBy         = User.Identity.Name;
                                planLine.MaterialPlanLineId = j;
                                planLine.ModifiedDate       = DateTime.Now;
                                planLine.ProcessId          = item.ProcessId;
                                planLine.Remark             = item.Remark;
                                planLine.PurchPlanQty       = item.PurchPlanQty;
                                planLine.StockPlanQty       = item.StockPlanQty;
                                planLine.GeneratedFor       = MaterialPlanConstants.SaleOrder;
                                planLine.ObjectState        = Model.ObjectState.Added;
                                context.MaterialPlanLine.Add(planLine);
                                if (!isPr)
                                {
                                    if (item.ProdPlanQty > 0)
                                    {
                                        isPr = true;
                                    }
                                }
                                if (!isPP)
                                {
                                    if (item.PurchPlanQty > 0)
                                    {
                                        isPP = true;
                                    }
                                }
                            }
                            j++;
                        }

                        if (isPr)
                        {
                            ProdOrderHeader ExistingProdOrder = new ProdOrderHeaderService(_unitOfWork).GetProdOrderForMaterialPlan(pt.MaterialPlanHeaderId);
                            int             ProdORderSerial   = 1;
                            if (ExistingProdOrder == null)
                            {
                                ProdOrderHeader prodOrderHeader = new ProdOrderHeader();

                                prodOrderHeader.CreatedBy            = User.Identity.Name;
                                prodOrderHeader.CreatedDate          = DateTime.Now;
                                prodOrderHeader.DivisionId           = pt.DivisionId;
                                prodOrderHeader.DocDate              = pt.DocDate;
                                prodOrderHeader.DocNo                = pt.DocNo;
                                prodOrderHeader.DocTypeId            = Settings.DocTypeProductionOrderId.Value;
                                prodOrderHeader.DueDate              = pt.DueDate;
                                prodOrderHeader.MaterialPlanHeaderId = pt.MaterialPlanHeaderId;
                                prodOrderHeader.ModifiedBy           = User.Identity.Name;
                                prodOrderHeader.ModifiedDate         = DateTime.Now;
                                prodOrderHeader.Remark               = pt.Remark;
                                prodOrderHeader.BuyerId              = pt.BuyerId;
                                prodOrderHeader.SiteId               = pt.SiteId;
                                //prodOrderHeader.Status = header.Status;
                                prodOrderHeader.Status      = (int)StatusConstants.System;
                                prodOrderHeader.ObjectState = Model.ObjectState.Added;
                                context.ProdOrderHeader.Add(prodOrderHeader);

                                //ForCreating ProdOrderStatus
                                ProdOrderHeaderStatus pts = new ProdOrderHeaderStatus();
                                pts.ProdOrderHeaderId = prodOrderHeader.ProdOrderHeaderId;
                                pts.ObjectState       = Model.ObjectState.Added;
                                context.ProdOrderHeaderStatus.Add(pts);

                                int ProdOrderLineKey = 0;
                                foreach (var item in context.MaterialPlanLine.Local.Where(m => m.ProdPlanQty > 0))
                                {
                                    ProdOrderLine prodOrderLine = new ProdOrderLine();
                                    prodOrderLine.CreatedBy          = User.Identity.Name;
                                    prodOrderLine.CreatedDate        = DateTime.Now;
                                    prodOrderLine.MaterialPlanLineId = item.MaterialPlanLineId;
                                    prodOrderLine.ModifiedBy         = User.Identity.Name;
                                    prodOrderLine.ModifiedDate       = DateTime.Now;
                                    prodOrderLine.ProdOrderHeaderId  = prodOrderHeader.ProdOrderHeaderId;
                                    prodOrderLine.Specification      = item.Specification;
                                    prodOrderLine.ProductId          = item.ProductId;
                                    prodOrderLine.Dimension1Id       = item.Dimension1Id;
                                    prodOrderLine.Dimension2Id       = item.Dimension2Id;
                                    prodOrderLine.Sr              = ProdORderSerial++;
                                    prodOrderLine.Qty             = item.ProdPlanQty;
                                    prodOrderLine.Remark          = item.Remark;
                                    prodOrderLine.ProdOrderLineId = ProdOrderLineKey++;
                                    prodOrderLine.ObjectState     = Model.ObjectState.Added;
                                    context.ProdOrderLine.Add(prodOrderLine);

                                    //ForAdding ProdrderLinestatus
                                    ProdOrderLineStatus ptl = new ProdOrderLineStatus();
                                    ptl.ProdOrderLineId = prodOrderLine.ProdOrderLineId;
                                    ptl.ObjectState     = Model.ObjectState.Added;
                                    context.ProdOrderLineStatus.Add(ptl);
                                }
                            }
                            else
                            {
                                ProdORderSerial = new ProdOrderLineService(_unitOfWork).GetMaxSr(ExistingProdOrder.ProdOrderHeaderId);


                                int ProdOrderLineKey = 0;
                                foreach (var item in context.MaterialPlanLine.Local.Where(m => m.ProdPlanQty > 0))
                                {
                                    ProdOrderLine prodOrderLine = new ProdOrderLine();
                                    prodOrderLine.CreatedBy          = User.Identity.Name;
                                    prodOrderLine.CreatedDate        = DateTime.Now;
                                    prodOrderLine.MaterialPlanLineId = item.MaterialPlanLineId;
                                    prodOrderLine.ModifiedBy         = User.Identity.Name;
                                    prodOrderLine.ModifiedDate       = DateTime.Now;
                                    prodOrderLine.ProdOrderHeaderId  = ExistingProdOrder.ProdOrderHeaderId;
                                    prodOrderLine.ProductId          = item.ProductId;
                                    prodOrderLine.Dimension1Id       = item.Dimension1Id;
                                    prodOrderLine.Dimension2Id       = item.Dimension2Id;
                                    prodOrderLine.Specification      = item.Specification;
                                    prodOrderLine.Qty             = item.ProdPlanQty;
                                    prodOrderLine.Sr              = ProdORderSerial++;
                                    prodOrderLine.Remark          = item.Remark;
                                    prodOrderLine.ProdOrderLineId = ProdOrderLineKey++;
                                    prodOrderLine.ObjectState     = Model.ObjectState.Added;
                                    context.ProdOrderLine.Add(prodOrderLine);

                                    //ForAdding ProdrderLinestatus
                                    ProdOrderLineStatus ptl = new ProdOrderLineStatus();
                                    ptl.ProdOrderLineId = prodOrderLine.ProdOrderLineId;
                                    ptl.ObjectState     = Model.ObjectState.Added;
                                    context.ProdOrderLineStatus.Add(ptl);
                                }
                            }
                        }
                        if (isPP)
                        {
                            PurchaseIndentHeader ExistingIndent = new PurchaseIndentHeaderService(_unitOfWork).GetPurchaseIndentForMaterialPlan(pt.MaterialPlanHeaderId);
                            int PurchaseIndentSr = 1;
                            if (ExistingIndent == null)
                            {
                                PurchaseIndentHeader indentHeader = new PurchaseIndentHeader();
                                indentHeader.CreatedBy            = User.Identity.Name;
                                indentHeader.CreatedDate          = DateTime.Now;
                                indentHeader.DivisionId           = pt.DivisionId;
                                indentHeader.DocDate              = pt.DocDate;
                                indentHeader.DocNo                = pt.DocNo;
                                indentHeader.DocTypeId            = Settings.DocTypePurchaseIndentId.Value;
                                indentHeader.ModifiedBy           = User.Identity.Name;
                                indentHeader.MaterialPlanHeaderId = pt.MaterialPlanHeaderId;
                                indentHeader.ModifiedDate         = DateTime.Now;
                                indentHeader.Remark               = pt.Remark;
                                indentHeader.SiteId               = pt.SiteId;
                                //indentHeader.Status = header.Status;
                                indentHeader.Status       = (int)StatusConstants.System;
                                indentHeader.DepartmentId = (int)DepartmentConstants.Production;
                                indentHeader.ObjectState  = Model.ObjectState.Added;
                                context.PurchaseIndentHeader.Add(indentHeader);
                                foreach (var item in context.MaterialPlanLine.Local.Where(m => m.PurchPlanQty > 0))
                                {
                                    PurchaseIndentLine indentLine = new PurchaseIndentLine();
                                    indentLine.CreatedBy              = User.Identity.Name;
                                    indentLine.CreatedDate            = DateTime.Now;
                                    indentLine.MaterialPlanLineId     = item.MaterialPlanLineId;
                                    indentLine.ModifiedBy             = User.Identity.Name;
                                    indentLine.ModifiedDate           = DateTime.Now;
                                    indentLine.ProductId              = item.ProductId;
                                    indentLine.Dimension1Id           = item.Dimension1Id;
                                    indentLine.Dimension2Id           = item.Dimension2Id;
                                    indentLine.Specification          = item.Specification;
                                    indentLine.PurchaseIndentHeaderId = indentHeader.PurchaseIndentHeaderId;
                                    indentLine.Qty         = item.PurchPlanQty;
                                    indentLine.Sr          = PurchaseIndentSr++;
                                    indentLine.Remark      = item.Remark;
                                    indentLine.ObjectState = Model.ObjectState.Added;
                                    context.PurchaseIndentLine.Add(indentLine);
                                }
                            }
                            else
                            {
                                PurchaseIndentSr = new PurchaseIndentLineService(_unitOfWork).GetMaxSr(ExistingIndent.PurchaseIndentHeaderId);
                                foreach (var item in context.MaterialPlanLine.Local.Where(m => m.PurchPlanQty > 0))
                                {
                                    PurchaseIndentLine indentLine = new PurchaseIndentLine();
                                    indentLine.CreatedBy          = User.Identity.Name;
                                    indentLine.CreatedDate        = DateTime.Now;
                                    indentLine.MaterialPlanLineId = item.MaterialPlanLineId;
                                    indentLine.ModifiedBy         = User.Identity.Name;
                                    indentLine.Specification      = item.Specification;
                                    indentLine.ModifiedDate       = DateTime.Now;
                                    indentLine.ProductId          = item.ProductId;
                                    indentLine.Dimension1Id       = item.Dimension1Id;
                                    indentLine.Dimension2Id       = item.Dimension2Id;
                                    indentLine.Sr = PurchaseIndentSr++;
                                    indentLine.PurchaseIndentHeaderId = ExistingIndent.PurchaseIndentHeaderId;
                                    indentLine.Qty         = item.PurchPlanQty;
                                    indentLine.Remark      = item.Remark;
                                    indentLine.ObjectState = Model.ObjectState.Added;
                                    context.PurchaseIndentLine.Add(indentLine);
                                }
                            }
                        }


                        int i = 0;
                        int MaterialPlanForSaleOrderSr = new MaterialPlanForSaleOrderService(_unitOfWork).GetMaxSr(svm.MaterialPlanLineViewModel.FirstOrDefault().MaterialPlanHeaderId);
                        foreach (var item in svm.MaterialPlanLineViewModel)
                        {
                            if (item.Qty > 0)
                            {
                                MaterialPlanForSaleOrder order = new MaterialPlanForSaleOrder();
                                order.MaterialPlanHeaderId = item.MaterialPlanHeaderId;
                                order.Qty                        = item.Qty;
                                order.SaleOrderLineId            = item.SaleOrderLineId;
                                order.MaterialPlanForSaleOrderId = i;
                                order.Sr           = MaterialPlanForSaleOrderSr++;
                                order.CreatedBy    = User.Identity.Name;
                                order.CreatedDate  = DateTime.Now;
                                order.ModifiedBy   = User.Identity.Name;
                                order.ModifiedDate = DateTime.Now;

                                //if (item.Dimension1Id != null)
                                //{
                                //    var MaterialPlan = context.MaterialPlanLine.Local.Where(m => m.ProductId == item.ProductId && m.Dimension1Id == item.Dimension1Id).FirstOrDefault();
                                //    if (order != null)
                                //    {
                                //        order.MaterialPlanLineId = MaterialPlan.MaterialPlanLineId;
                                //    }
                                //}
                                //else
                                //{
                                //    var MaterialPlan = context.MaterialPlanLine.Local.Where(m => m.ProductId == item.ProductId).FirstOrDefault();
                                //    if (order != null)
                                //    {
                                //        order.MaterialPlanLineId = MaterialPlan.MaterialPlanLineId;
                                //    }
                                //}

                                order.ObjectState = Model.ObjectState.Added;
                                context.MaterialPlanForSaleOrder.Add(order);

                                i++;
                            }
                        }

                        try
                        {
                            context.SaveChanges();
                        }

                        catch (Exception ex)
                        {
                            string message = _exception.HandleException(ex);
                            TempData["CSEXC"] += message;
                            ViewBag.Mode       = "Add";
                            ViewBag.Name       = new DocumentTypeService(_unitOfWork).Find(vm.DocTypeId).DocumentTypeName;
                            ViewBag.id         = vm.DocTypeId;
                            return(View("Create", vm));
                        }

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

                        return(RedirectToAction("Index", "MaterialPlanHeader", new { id = pt.DocTypeId }));
                    }
                }
                #endregion
            }
            ViewBag.Name = new DocumentTypeService(_unitOfWork).Find(vm.DocTypeId).DocumentTypeName;
            ViewBag.id   = vm.DocTypeId;
            ViewBag.Mode = "Add";
            return(View("Create", vm));
        }
Exemplo n.º 5
0
 public void Update(PurchaseIndentLine s)
 {
     s.ObjectState = ObjectState.Modified;
     _unitOfWork.Repository <PurchaseIndentLine>().Update(s);
 }
Exemplo n.º 6
0
 public void Delete(PurchaseIndentLine s)
 {
     _unitOfWork.Repository <PurchaseIndentLine>().Delete(s);
 }
Exemplo n.º 7
0
 public PurchaseIndentLine Create(PurchaseIndentLine S)
 {
     S.ObjectState = ObjectState.Added;
     _unitOfWork.Repository <PurchaseIndentLine>().Insert(S);
     return(S);
 }