Exemple #1
0
        public ActionResult DeletePost(ProdOrderCancelLineViewModel vm)
        {
            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

            ProdOrderCancelLine SaleOrderLine = _ProdOrderCancelLineService.Find(vm.ProdOrderCancelLineId);

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

            ProdOrderCancelHeader header = new ProdOrderCancelHeaderService(_unitOfWork).Find(SaleOrderLine.ProdOrderCancelHeaderId);
            int status = header.Status;

            new ProdOrderLineStatusService(_unitOfWork).UpdateProdQtyOnCancel(SaleOrderLine.ProdOrderLineId, SaleOrderLine.ProdOrderCancelLineId, header.DocDate, 0, ref db, false);

            _ProdOrderCancelLineService.Delete(vm.ProdOrderCancelLineId);

            if (header.Status != (int)StatusConstants.Drafted)
            {
                header.Status = (int)StatusConstants.Modified;
                new ProdOrderCancelHeaderService(_unitOfWork).Update(header);
            }
            XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);

            try
            {
                _unitOfWork.Save();
            }

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

            LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
            {
                DocTypeId       = header.DocTypeId,
                DocId           = header.ProdOrderCancelHeaderId,
                DocLineId       = SaleOrderLine.ProdOrderCancelLineId,
                ActivityType    = (int)ActivityTypeContants.Deleted,
                DocNo           = header.DocNo,
                xEModifications = Modifications,
                DocDate         = header.DocDate,
                DocStatus       = header.Status,
            }));

            return(Json(new { success = true }));
        }
Exemple #2
0
        public ActionResult _ResultsPost(ProdOrderCancelMasterDetailModel vm)
        {
            Dictionary <int, decimal> LineStatus = new Dictionary <int, decimal>();
            var Header = new ProdOrderCancelHeaderService(_unitOfWork).Find(vm.ProdOrderCancelViewModels.FirstOrDefault().ProdOrderCancelHeaderId);

            if (ModelState.IsValid)
            {
                foreach (var item in vm.ProdOrderCancelViewModels)
                {
                    decimal balqty = (from p in db.ViewProdOrderBalance
                                      where p.ProdOrderLineId == item.ProdOrderLineId
                                      select p.BalanceQty).FirstOrDefault();

                    if (item.Qty > 0 && item.Qty <= balqty)
                    {
                        ProdOrderCancelLine line = new ProdOrderCancelLine();

                        line.ProdOrderCancelHeaderId = item.ProdOrderCancelHeaderId;
                        line.ProdOrderLineId         = item.ProdOrderLineId;
                        line.Qty          = item.Qty;
                        line.CreatedDate  = DateTime.Now;
                        line.ModifiedDate = DateTime.Now;
                        line.CreatedBy    = User.Identity.Name;
                        line.ModifiedBy   = User.Identity.Name;
                        LineStatus.Add(line.ProdOrderLineId, line.Qty);
                        _ProdOrderCancelLineService.Create(line);
                    }
                }

                new ProdOrderLineStatusService(_unitOfWork).UpdateProdQtyCancelMultiple(LineStatus, Header.DocDate);

                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;
                }

                new ProdOrderCancelHeaderService(_unitOfWork).Update(Header);

                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    = Header.DocTypeId,
                    DocId        = Header.ProdOrderCancelHeaderId,
                    ActivityType = (int)ActivityTypeContants.MultipleCreate,
                    DocNo        = Header.DocNo,
                    DocDate      = Header.DocDate,
                    DocStatus    = Header.Status,
                }));

                return(Json(new { success = true }));
            }
            return(PartialView("_Results", vm));
        }
        public ActionResult _ResultsPost(MaterialPlanCancelLineListViewModel vm)
        {
            MaterialPlanCancelHeader header = new MaterialPlanCancelHeaderService(_unitOfWork).Find(vm.MaterialPlanCancelLineViewModel.FirstOrDefault().MaterialPlanCancelHeaderId);

            MaterialPlanSettings Setting = new MaterialPlanSettingsService(_unitOfWork).GetMaterialPlanSettingsForDocument(header.DocTypeId, header.DivisionId, header.SiteId);

            if (ModelState.IsValid)
            {
                var ProductIds = vm.MaterialPlanCancelLineViewModel.Select(m => m.ProductId).ToArray();

                List <MaterialPlanCancelLineViewModel> Line = new List <MaterialPlanCancelLineViewModel>();

                int i      = 0;
                int si     = 0;
                int linePk = 0;
                int Cnt    = 0;

                var mPlanLineIds = vm.MaterialPlanCancelLineViewModel.Where(m => m.Qty > 0 && m.Qty <= m.BalanceQty).Select(m => m.MaterialPlanLineId).ToList();


                //var mPlanRecords = db.ViewMaterialPlanForSaleOrderBalance.AsNoTracking().Where(m => mPlanLineIds.Contains(m.MaterialPlanLineId.Value)).ToList();
                //Changed because ViewMaterialPlanForSaleOrderBalance is not required.
                var mPlanRecords = db.MaterialPlanForSaleOrder.AsNoTracking().Where(m => mPlanLineIds.Contains(m.MaterialPlanLineId.Value)).ToList();

                foreach (var item in vm.MaterialPlanCancelLineViewModel.Where(m => m.Qty > 0 && m.Qty <= m.BalanceQty))
                {
                    MaterialPlanCancelLine cline = new MaterialPlanCancelLine();
                    cline.MaterialPlanCancelHeaderId = header.MaterialPlanCancelHeaderId;
                    cline.CreatedBy          = User.Identity.Name;
                    cline.CreatedDate        = DateTime.Now;
                    cline.MaterialPlanLineId = item.MaterialPlanLineId;
                    cline.CreatedBy          = User.Identity.Name;
                    cline.CreatedDate        = DateTime.Now;
                    cline.ModifiedBy         = User.Identity.Name;
                    cline.ModifiedDate       = DateTime.Now;
                    cline.ObjectState        = Model.ObjectState.Added;
                    cline.Qty    = item.Qty;
                    cline.Remark = item.Remark;
                    cline.Sr     = i++;
                    cline.MaterialPlanCancelLineId = linePk++;
                    cline.ObjectState = Model.ObjectState.Added;
                    db.MaterialPlanCancelLine.Add(cline);

                    SqlParameter SqlParameterMaterialPlanLineId = new SqlParameter("@MaterialPlanLineId", cline.MaterialPlanLineId);
                    SqlParameter SqlParameterQty = new SqlParameter("@Qty", cline.Qty);

                    IEnumerable <MaterialPlanForSaleOrderFifo> MaterialPlanForSaleOrderFifo = db.Database.SqlQuery <MaterialPlanForSaleOrderFifo>("" + ConfigurationManager.AppSettings["DataBaseSchema"] + ".sp_GetMaterialPlanForSaleOrderFifo @MaterialPlanLineId, @Qty", SqlParameterMaterialPlanLineId, SqlParameterQty).ToList();


                    //foreach (var detailSo in mPlanRecords.Where(m => m.MaterialPlanLineId == item.MaterialPlanLineId).ToList())
                    foreach (var detailSo in MaterialPlanForSaleOrderFifo)
                    {
                        MaterialPlanCancelForSaleOrder cso = new MaterialPlanCancelForSaleOrder();
                        cso.CreatedBy    = User.Identity.Name;
                        cso.CreatedDate  = DateTime.Now;
                        cso.ModifiedBy   = User.Identity.Name;
                        cso.ModifiedDate = DateTime.Now;
                        cso.MaterialPlanCancelHeaderId = header.MaterialPlanCancelHeaderId;
                        cso.MaterialPlanCancelLineId   = cline.MaterialPlanCancelLineId;
                        cso.MaterialPlanForSaleOrderId = detailSo.MaterialPlanForSaleOrderId;
                        cso.Qty         = detailSo.Qty;
                        cso.Sr          = si++;
                        cso.ObjectState = Model.ObjectState.Added;
                        db.MaterialPlanCancelForSaleOrder.Add(cso);
                    }


                    var MaterialPlanLine        = new MaterialPlanLineService(_unitOfWork).Find(item.MaterialPlanLineId);
                    int ProdOrderCancelHeaderId = 0;
                    if (MaterialPlanLine.ProdPlanQty > 0)
                    {
                        ProdOrderCancelHeader ExistingProdOrderCancel = new ProdOrderCancelHeaderService(_unitOfWork).GetProdOrderCancelForMaterialPlan(header.MaterialPlanCancelHeaderId);
                        ProdOrderCancelHeader ProdOrderCancelHeader   = new ProdOrderCancelHeader();

                        if (ExistingProdOrderCancel == null && Cnt == 0)
                        {
                            ProdOrderCancelHeader.CreatedBy   = User.Identity.Name;
                            ProdOrderCancelHeader.CreatedDate = DateTime.Now;
                            ProdOrderCancelHeader.DivisionId  = header.DivisionId;
                            ProdOrderCancelHeader.DocDate     = header.DocDate;
                            ProdOrderCancelHeader.DocNo       = header.DocNo;
                            ProdOrderCancelHeader.DocTypeId   = Setting.DocTypeProductionOrderId.Value;
                            ProdOrderCancelHeader.MaterialPlanCancelHeaderId = header.MaterialPlanCancelHeaderId;
                            ProdOrderCancelHeader.ModifiedBy   = User.Identity.Name;
                            ProdOrderCancelHeader.ModifiedDate = DateTime.Now;
                            ProdOrderCancelHeader.Remark       = header.Remark;
                            ProdOrderCancelHeader.SiteId       = header.SiteId;
                            ProdOrderCancelHeader.Status       = (int)StatusConstants.System;
                            ProdOrderCancelHeader.ObjectState  = Model.ObjectState.Added;
                            db.ProdOrderCancelHeader.Add(ProdOrderCancelHeader);
                            ProdOrderCancelHeaderId = ProdOrderCancelHeader.ProdOrderCancelHeaderId;

                            Cnt = Cnt + 1;
                        }
                        else
                        {
                            if (ExistingProdOrderCancel == null)
                            {
                                ProdOrderCancelHeaderId = ProdOrderCancelHeader.ProdOrderCancelHeaderId;
                            }
                            else
                            {
                                ProdOrderCancelHeaderId = ExistingProdOrderCancel.ProdOrderCancelHeaderId;
                            }
                        }


                        var ProdOrderLine          = new ProdOrderLineService(_unitOfWork).GetProdOrderLineForMaterialPlan(item.MaterialPlanLineId);
                        int ProdOrderCancelLineKey = 0;
                        ProdOrderCancelLine ProdOrderCancelLine = new ProdOrderCancelLine();
                        ProdOrderCancelLine.ProdOrderCancelLineId    = linePk++;
                        ProdOrderCancelLine.CreatedBy                = User.Identity.Name;
                        ProdOrderCancelLine.CreatedDate              = DateTime.Now;
                        ProdOrderCancelLine.ProdOrderLineId          = ProdOrderLine.FirstOrDefault().ProdOrderLineId;
                        ProdOrderCancelLine.ModifiedBy               = User.Identity.Name;
                        ProdOrderCancelLine.ModifiedDate             = DateTime.Now;
                        ProdOrderCancelLine.ProdOrderCancelHeaderId  = ProdOrderCancelHeaderId;
                        ProdOrderCancelLine.MaterialPlanCancelLineId = cline.MaterialPlanCancelLineId;
                        ProdOrderCancelLine.Qty = item.Qty;
                        ProdOrderCancelLine.ProdOrderCancelLineId = ProdOrderCancelLineKey--;
                        ProdOrderCancelLine.ObjectState           = Model.ObjectState.Added;
                        db.ProdOrderCancelLine.Add(ProdOrderCancelLine);
                    }


                    if (MaterialPlanLine.PurchPlanQty > 0)
                    {
                        PurchaseIndentCancelHeader ExistingPurchaseIndentCancel = new PurchaseIndentCancelHeaderService(_unitOfWork).GetPurchaseIndentCancelForMaterialPlan(header.MaterialPlanCancelHeaderId);

                        if (ExistingPurchaseIndentCancel == null)
                        {
                            PurchaseIndentCancelHeader PurchaseIndentCancelHeader = new PurchaseIndentCancelHeader();

                            PurchaseIndentCancelHeader.CreatedBy   = User.Identity.Name;
                            PurchaseIndentCancelHeader.CreatedDate = DateTime.Now;
                            PurchaseIndentCancelHeader.DivisionId  = header.DivisionId;
                            PurchaseIndentCancelHeader.DocDate     = header.DocDate;
                            PurchaseIndentCancelHeader.DocNo       = header.DocNo;
                            PurchaseIndentCancelHeader.DocTypeId   = Setting.DocTypeProductionOrderId.Value;
                            PurchaseIndentCancelHeader.MaterialPlanCancelHeaderId = header.MaterialPlanCancelHeaderId;
                            PurchaseIndentCancelHeader.ModifiedBy   = User.Identity.Name;
                            PurchaseIndentCancelHeader.ModifiedDate = DateTime.Now;
                            PurchaseIndentCancelHeader.Remark       = header.Remark;
                            PurchaseIndentCancelHeader.SiteId       = header.SiteId;
                            PurchaseIndentCancelHeader.Status       = (int)StatusConstants.System;
                            PurchaseIndentCancelHeader.ObjectState  = Model.ObjectState.Added;
                            db.PurchaseIndentCancelHeader.Add(PurchaseIndentCancelHeader);
                        }


                        var PurchaseIndentLine          = new PurchaseIndentLineService(_unitOfWork).GetPurchaseIndentLineForMaterialPlan(item.MaterialPlanLineId);
                        int PurchaseIndentCancelLineKey = 0;
                        PurchaseIndentCancelLine PurchaseIndentCancelLine = new PurchaseIndentCancelLine();
                        PurchaseIndentCancelLine.CreatedBy                    = User.Identity.Name;
                        PurchaseIndentCancelLine.CreatedDate                  = DateTime.Now;
                        PurchaseIndentCancelLine.PurchaseIndentLineId         = PurchaseIndentLine.FirstOrDefault().PurchaseIndentLineId;
                        PurchaseIndentCancelLine.ModifiedBy                   = User.Identity.Name;
                        PurchaseIndentCancelLine.ModifiedDate                 = DateTime.Now;
                        PurchaseIndentCancelLine.PurchaseIndentCancelHeaderId = ExistingPurchaseIndentCancel.PurchaseIndentCancelHeaderId;
                        PurchaseIndentCancelLine.MaterialPlanCancelLineId     = cline.MaterialPlanCancelLineId;
                        PurchaseIndentCancelLine.Qty = item.Qty;
                        PurchaseIndentCancelLine.PurchaseIndentCancelLineId = PurchaseIndentCancelLineKey--;
                        PurchaseIndentCancelLine.ObjectState = Model.ObjectState.Added;
                        db.PurchaseIndentCancelLine.Add(PurchaseIndentCancelLine);
                    }
                }

                try
                {
                    db.SaveChanges();
                }

                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    ModelState.AddModelError("", message);
                    return(PartialView("_Results", vm));
                }

                return(Json(new { success = true }));
            }
            return(PartialView("_Results", vm));
        }
Exemple #4
0
        public ActionResult _CreatePost(ProdOrderCancelLineViewModel svm)
        {
            if (svm.ProdOrderCancelLineId <= 0)
            {
                ViewBag.LineMode = "Create";
            }
            else
            {
                ViewBag.LineMode = "Edit";
            }

            if (svm.ProdOrderCancelLineId <= 0)
            {
                ProdOrderCancelLine s      = new ProdOrderCancelLine();
                decimal             balqty = (from p in db.ViewProdOrderBalance
                                              where p.ProdOrderLineId == svm.ProdOrderLineId
                                              select p.BalanceQty).FirstOrDefault();
                if (balqty < svm.Qty)
                {
                    ModelState.AddModelError("Qty", "Qty Exceeding Balance Qty");
                }
                if (svm.Qty == 0)
                {
                    ModelState.AddModelError("Qty", "Please Check Qty");
                }
                if (svm.ProdOrderLineId == 0)
                {
                    ModelState.AddModelError("ProdOrderLineId", "The Prod Order field is required");
                }
                if (ModelState.IsValid)
                {
                    s.ProdOrderCancelHeaderId = svm.ProdOrderCancelHeaderId;
                    s.ProdOrderLineId         = svm.ProdOrderLineId;
                    s.Qty          = svm.Qty;
                    s.CreatedDate  = DateTime.Now;
                    s.ModifiedDate = DateTime.Now;
                    s.CreatedBy    = User.Identity.Name;
                    s.ModifiedBy   = User.Identity.Name;
                    _ProdOrderCancelLineService.Create(s);

                    ProdOrderCancelHeader temp2 = new ProdOrderCancelHeaderService(_unitOfWork).Find(s.ProdOrderCancelHeaderId);

                    new ProdOrderLineStatusService(_unitOfWork).UpdateProdQtyOnCancel(s.ProdOrderLineId, s.ProdOrderCancelLineId, temp2.DocDate, s.Qty, ref db, false);


                    if (temp2.Status != (int)StatusConstants.Drafted && temp2.Status != (int)StatusConstants.Import)
                    {
                        temp2.Status       = (int)StatusConstants.Modified;
                        temp2.ModifiedBy   = User.Identity.Name;
                        temp2.ModifiedDate = DateTime.Now;
                    }
                    new ProdOrderCancelHeaderService(_unitOfWork).Update(temp2);

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

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

                    return(RedirectToAction("_Create", new { id = s.ProdOrderCancelHeaderId }));
                }
                return(PartialView("_Create", svm));
            }
            else
            {
                List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                ProdOrderCancelHeader temp = new ProdOrderCancelHeaderService(_unitOfWork).Find(svm.ProdOrderCancelHeaderId);
                int           status       = temp.Status;
                StringBuilder logstring    = new StringBuilder();

                ProdOrderCancelLine s = _ProdOrderCancelLineService.Find(svm.ProdOrderCancelLineId);

                ProdOrderCancelLine ExRec = new ProdOrderCancelLine();
                ExRec = Mapper.Map <ProdOrderCancelLine>(s);

                decimal balqty = (from p in db.ViewProdOrderBalance
                                  where p.ProdOrderLineId == svm.ProdOrderLineId
                                  select p.BalanceQty).FirstOrDefault();
                if (balqty + s.Qty < svm.Qty)
                {
                    ModelState.AddModelError("Qty", "Qty Exceeding Balance Qty");
                }


                if (ModelState.IsValid)
                {
                    if (svm.Qty > 0)
                    {
                        s.Qty          = svm.Qty;
                        s.ModifiedBy   = User.Identity.Name;
                        s.ModifiedDate = DateTime.Now;
                    }

                    _ProdOrderCancelLineService.Update(s);

                    new ProdOrderLineStatusService(_unitOfWork).UpdateProdQtyOnCancel(s.ProdOrderLineId, s.ProdOrderCancelLineId, temp.DocDate, s.Qty, ref db, false);

                    temp.Status = (int)StatusConstants.Modified;
                    new ProdOrderCancelHeaderService(_unitOfWork).Update(temp);

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

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

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

                    return(Json(new { success = true }));
                }
                return(PartialView("_Create", svm));
            }
        }
        public ActionResult _ResultsPostProduction(MaterialPlanCancelLineListViewModel vm)
        {
            MaterialPlanCancelHeader header = new MaterialPlanCancelHeaderService(_unitOfWork).Find(vm.MaterialPlanCancelLineViewModel.FirstOrDefault().MaterialPlanCancelHeaderId);

            MaterialPlanSettings Setting = new MaterialPlanSettingsService(_unitOfWork).GetMaterialPlanSettingsForDocument(header.DocTypeId, header.DivisionId, header.SiteId);

            if (ModelState.IsValid)
            {
                var ProductIds = vm.MaterialPlanCancelLineViewModel.Select(m => m.ProductId).ToArray();

                List <MaterialPlanCancelLineViewModel> Line = new List <MaterialPlanCancelLineViewModel>();

                int i        = 0;
                int si       = 0;
                int linePk   = 0;
                int poLinePK = 0;

                var mPlanLineIds = vm.MaterialPlanCancelLineViewModel.Where(m => m.Qty > 0 && m.Qty == m.BalanceQty).Select(m => m.MaterialPlanLineId).ToList();

                var mPlanProdOrderLineRecords = db.ViewMaterialPlanForProdOrderLineBalance.AsNoTracking().Where(m => mPlanLineIds.Contains(m.MaterialPlanLineId.Value)).ToList();

                var mPlanProdOrderIds = mPlanProdOrderLineRecords.Select(m => m.MaterialPlanForProdOrderId).Distinct().ToList();

                var mPlanProdOrderRecords = db.ViewMaterialPlanForProdOrderBalance.AsNoTracking().Where(m => mPlanProdOrderIds.Contains(m.MaterialPlanForProdOrderId)).ToList();


                foreach (var item in vm.MaterialPlanCancelLineViewModel.Where(m => m.Qty > 0 && m.Qty == m.BalanceQty))
                {
                    MaterialPlanCancelLine cline = new MaterialPlanCancelLine();
                    cline.MaterialPlanCancelHeaderId = header.MaterialPlanCancelHeaderId;
                    cline.CreatedBy          = User.Identity.Name;
                    cline.CreatedDate        = DateTime.Now;
                    cline.MaterialPlanLineId = item.MaterialPlanLineId;
                    cline.CreatedBy          = User.Identity.Name;
                    cline.CreatedDate        = DateTime.Now;
                    cline.ModifiedBy         = User.Identity.Name;
                    cline.ModifiedDate       = DateTime.Now;
                    cline.ObjectState        = Model.ObjectState.Added;
                    cline.Qty    = item.Qty;
                    cline.Remark = item.Remark;
                    cline.Sr     = i++;
                    cline.MaterialPlanCancelLineId = linePk++;
                    cline.ObjectState = Model.ObjectState.Added;
                    db.MaterialPlanCancelLine.Add(cline);

                    var poLineRecords = mPlanProdOrderLineRecords.Where(m => m.MaterialPlanLineId == item.MaterialPlanLineId).ToList();

                    var ProdOrder = mPlanProdOrderRecords.Where(m => m.MaterialPlanForProdOrderId == poLineRecords.Select(t => t.MaterialPlanForProdOrderId).FirstOrDefault()).FirstOrDefault();

                    MaterialPlanCancelForProdOrder poLine = new MaterialPlanCancelForProdOrder();
                    poLine.CreatedBy   = User.Identity.Name;
                    poLine.CreatedDate = DateTime.Now;
                    poLine.MaterialPlanCancelHeaderId       = header.MaterialPlanCancelHeaderId;
                    poLine.MaterialPlanLineId               = cline.MaterialPlanLineId;
                    poLine.MaterialPlanCancelForProdOrderId = poLinePK++;
                    poLine.ModifiedDate = DateTime.Now;
                    poLine.ModifiedBy   = User.Identity.Name;
                    poLine.ObjectState  = Model.ObjectState.Added;
                    poLine.Qty          = ProdOrder.BalanceQty;
                    poLine.Sr           = cline.Sr;
                    poLine.ObjectState  = Model.ObjectState.Added;
                    db.MaterialPlanCancelForProdOrder.Add(poLine);


                    foreach (var detailSo in poLineRecords)
                    {
                        MaterialPlanCancelForProdOrderLine cso = new MaterialPlanCancelForProdOrderLine();
                        cso.MaterialPlanCancelLineId         = cline.MaterialPlanCancelLineId;
                        cso.MaterialPlanCancelForProdOrderId = poLine.MaterialPlanCancelForProdOrderId;
                        cso.Qty         = detailSo.BalanceQty;
                        cso.Sr          = si++;
                        cso.ObjectState = Model.ObjectState.Added;
                        db.MaterialPlanCancelForProdOrderLine.Add(cso);
                    }


                    var MaterialPlanLine = new MaterialPlanLineService(_unitOfWork).Find(item.MaterialPlanLineId);

                    if (MaterialPlanLine.ProdPlanQty > 0)
                    {
                        ProdOrderCancelHeader ExistingProdOrderCancel = new ProdOrderCancelHeaderService(_unitOfWork).GetProdOrderCancelForMaterialPlan(header.MaterialPlanCancelHeaderId);

                        if (ExistingProdOrderCancel == null)
                        {
                            ProdOrderCancelHeader ProdOrderCancelHeader = new ProdOrderCancelHeader();

                            ProdOrderCancelHeader.CreatedBy   = User.Identity.Name;
                            ProdOrderCancelHeader.CreatedDate = DateTime.Now;
                            ProdOrderCancelHeader.DivisionId  = header.DivisionId;
                            ProdOrderCancelHeader.DocDate     = header.DocDate;
                            ProdOrderCancelHeader.DocNo       = header.DocNo;
                            ProdOrderCancelHeader.DocTypeId   = Setting.DocTypeProductionOrderId.Value;
                            ProdOrderCancelHeader.MaterialPlanCancelHeaderId = header.MaterialPlanCancelHeaderId;
                            ProdOrderCancelHeader.ModifiedBy   = User.Identity.Name;
                            ProdOrderCancelHeader.ModifiedDate = DateTime.Now;
                            ProdOrderCancelHeader.Remark       = header.Remark;
                            ProdOrderCancelHeader.SiteId       = header.SiteId;
                            ProdOrderCancelHeader.Status       = (int)StatusConstants.System;
                            ProdOrderCancelHeader.ObjectState  = Model.ObjectState.Added;
                            db.ProdOrderCancelHeader.Add(ProdOrderCancelHeader);
                        }


                        var ProdOrderLine          = new ProdOrderLineService(_unitOfWork).GetProdOrderLineForMaterialPlan(item.MaterialPlanLineId);
                        int ProdOrderCancelLineKey = 0;
                        ProdOrderCancelLine ProdOrderCancelLine = new ProdOrderCancelLine();
                        ProdOrderCancelLine.CreatedBy               = User.Identity.Name;
                        ProdOrderCancelLine.CreatedDate             = DateTime.Now;
                        ProdOrderCancelLine.ProdOrderLineId         = ProdOrderLine.FirstOrDefault().ProdOrderLineId;
                        ProdOrderCancelLine.ModifiedBy              = User.Identity.Name;
                        ProdOrderCancelLine.ModifiedDate            = DateTime.Now;
                        ProdOrderCancelLine.ProdOrderCancelHeaderId = ExistingProdOrderCancel.ProdOrderCancelHeaderId;
                        ProdOrderCancelLine.Qty = item.Qty;
                        ProdOrderCancelLine.ProdOrderCancelLineId = ProdOrderCancelLineKey--;
                        ProdOrderCancelLine.ObjectState           = Model.ObjectState.Added;
                        db.ProdOrderCancelLine.Add(ProdOrderCancelLine);
                    }


                    if (MaterialPlanLine.PurchPlanQty > 0)
                    {
                        PurchaseIndentCancelHeader ExistingPurchaseIndentCancel = new PurchaseIndentCancelHeaderService(_unitOfWork).GetPurchaseIndentCancelForMaterialPlan(header.MaterialPlanCancelHeaderId);

                        if (ExistingPurchaseIndentCancel == null)
                        {
                            PurchaseIndentCancelHeader PurchaseIndentCancelHeader = new PurchaseIndentCancelHeader();

                            PurchaseIndentCancelHeader.CreatedBy   = User.Identity.Name;
                            PurchaseIndentCancelHeader.CreatedDate = DateTime.Now;
                            PurchaseIndentCancelHeader.DivisionId  = header.DivisionId;
                            PurchaseIndentCancelHeader.DocDate     = header.DocDate;
                            PurchaseIndentCancelHeader.DocNo       = header.DocNo;
                            PurchaseIndentCancelHeader.DocTypeId   = Setting.DocTypeProductionOrderId.Value;
                            PurchaseIndentCancelHeader.MaterialPlanCancelHeaderId = header.MaterialPlanCancelHeaderId;
                            PurchaseIndentCancelHeader.ModifiedBy   = User.Identity.Name;
                            PurchaseIndentCancelHeader.ModifiedDate = DateTime.Now;
                            PurchaseIndentCancelHeader.Remark       = header.Remark;
                            PurchaseIndentCancelHeader.SiteId       = header.SiteId;
                            PurchaseIndentCancelHeader.Status       = (int)StatusConstants.System;
                            PurchaseIndentCancelHeader.ObjectState  = Model.ObjectState.Added;
                            db.PurchaseIndentCancelHeader.Add(PurchaseIndentCancelHeader);
                        }


                        var PurchaseIndentLine          = new PurchaseIndentLineService(_unitOfWork).GetPurchaseIndentLineForMaterialPlan(item.MaterialPlanLineId);
                        int PurchaseIndentCancelLineKey = 0;
                        PurchaseIndentCancelLine PurchaseIndentCancelLine = new PurchaseIndentCancelLine();
                        PurchaseIndentCancelLine.CreatedBy                    = User.Identity.Name;
                        PurchaseIndentCancelLine.CreatedDate                  = DateTime.Now;
                        PurchaseIndentCancelLine.PurchaseIndentLineId         = PurchaseIndentLine.FirstOrDefault().PurchaseIndentLineId;
                        PurchaseIndentCancelLine.ModifiedBy                   = User.Identity.Name;
                        PurchaseIndentCancelLine.ModifiedDate                 = DateTime.Now;
                        PurchaseIndentCancelLine.PurchaseIndentCancelHeaderId = ExistingPurchaseIndentCancel.PurchaseIndentCancelHeaderId;
                        PurchaseIndentCancelLine.Qty = item.Qty;
                        PurchaseIndentCancelLine.PurchaseIndentCancelLineId = PurchaseIndentCancelLineKey--;
                        PurchaseIndentCancelLine.ObjectState = Model.ObjectState.Added;
                        db.PurchaseIndentCancelLine.Add(PurchaseIndentCancelLine);
                    }
                }

                try
                {
                    db.SaveChanges();
                }

                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    ModelState.AddModelError("", message);
                    return(PartialView("_Results", vm));
                }

                return(Json(new { success = true }));
            }
            return(PartialView("_Results", vm));
        }
        public ActionResult DeletePost(MaterialPlanCancelLineViewModel vm)
        {
            bool BeforeSave = true;

            //try
            //{
            //    BeforeSave = MaterialPlanCancelDocEvents.beforeLineDeleteEvent(this, new PurchaseEventArgs(vm.MaterialPlanCancelHeaderId, vm.MaterialPlanCancelLineId), 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)
            {
                List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                MaterialPlanCancelLine MaterialPlanCancelLine = db.MaterialPlanCancelLine.Find(vm.MaterialPlanCancelLineId);

                //try
                //{
                //    MaterialPlanCancelDocEvents.onLineDeleteEvent(this, new PurchaseEventArgs(MaterialPlanCancelLine.MaterialPlanCancelHeaderId, MaterialPlanCancelLine.MaterialPlanCancelLineId), ref db);
                //}
                //catch (Exception ex)
                //{
                //    string message = _exception.HandleException(ex);
                //    TempData["CSEXCL"] += message;
                //    EventException = true;
                //}

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


                IEnumerable <MaterialPlanCancelForSaleOrder> sOrderList = db.MaterialPlanCancelForSaleOrder.Where(m => m.MaterialPlanCancelLineId == MaterialPlanCancelLine.MaterialPlanCancelLineId).ToList();

                IEnumerable <MaterialPlanCancelForProdOrderLine> pOrderList = db.MaterialPlanCancelForProdOrderLine.Where(m => m.MaterialPlanCancelLineId == MaterialPlanCancelLine.MaterialPlanCancelLineId).ToList();

                MaterialPlanCancelForProdOrder prodOrder = db.MaterialPlanCancelForProdOrder.Find(pOrderList.Select(m => m.MaterialPlanCancelForProdOrderId).FirstOrDefault());

                foreach (var item2 in sOrderList)
                {
                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = item2,
                    });

                    item2.ObjectState = Model.ObjectState.Deleted;
                    db.MaterialPlanCancelForSaleOrder.Remove(item2);
                }

                foreach (var item2 in pOrderList)
                {
                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = item2,
                    });

                    item2.ObjectState = Model.ObjectState.Deleted;
                    db.MaterialPlanCancelForProdOrderLine.Remove(item2);
                }

                if (prodOrder != null)
                {
                    prodOrder.ObjectState = Model.ObjectState.Deleted;
                    db.MaterialPlanCancelForProdOrder.Remove(prodOrder);
                }


                IEnumerable <ProdOrderCancelLine> ProdOrderCancelLineListAutoGenerated = new ProdOrderCancelLineService(_unitOfWork).GetProdOrderCancelLineForMaterialPlanCancel(vm.MaterialPlanCancelLineId);

                foreach (ProdOrderCancelLine item in ProdOrderCancelLineListAutoGenerated)
                {
                    //new ProdOrderCancelLineService(_unitOfWork).Delete(item.ProdOrderCancelLineId);
                    ProdOrderCancelLine ProdOrderCancelLine = db.ProdOrderCancelLine.Find(item.ProdOrderCancelLineId);
                    ProdOrderCancelLine.ObjectState = Model.ObjectState.Deleted;
                    db.ProdOrderCancelLine.Remove(ProdOrderCancelLine);
                }



                MaterialPlanCancelHeader header = new MaterialPlanCancelHeaderService(_unitOfWork).Find(MaterialPlanCancelLine.MaterialPlanCancelHeaderId);
                //_MaterialPlanCancelLineService.Delete(vm.MaterialPlanCancelLineId);

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


                if (header.Status != (int)StatusConstants.Drafted)
                {
                    header.Status       = (int)StatusConstants.Modified;
                    header.ModifiedDate = DateTime.Now;
                    header.ModifiedBy   = User.Identity.Name;
                    header.ObjectState  = Model.ObjectState.Modified;
                    db.MaterialPlanCancelHeader.Add(header);
                    //new MaterialPlanCancelHeaderService(_unitOfWork).Update(header);
                }
                XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);
                try
                {
                    db.SaveChanges();
                    //_unitOfWork.Save();
                }
                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    TempData["CSEXCL"] += message;
                    return(PartialView("_Create", vm));
                }

                //try
                //{
                //    MaterialPlanCancelDocEvents.afterLineDeleteEvent(this, new PurchaseEventArgs(MaterialPlanCancelLine.MaterialPlanCancelHeaderId, MaterialPlanCancelLine.MaterialPlanCancelLineId), ref db);
                //}
                //catch (Exception ex)
                //{
                //    string message = _exception.HandleException(ex);
                //    TempData["CSEXC"] += message;
                //}

                LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                {
                    DocTypeId       = header.DocTypeId,
                    DocId           = header.MaterialPlanCancelHeaderId,
                    DocLineId       = MaterialPlanCancelLine.MaterialPlanCancelLineId,
                    ActivityType    = (int)ActivityTypeContants.Deleted,
                    DocNo           = header.DocNo,
                    xEModifications = Modifications,
                    DocDate         = header.DocDate,
                    DocStatus       = header.Status,
                }));
            }
            return(Json(new { success = true }));
        }
Exemple #7
0
        public ActionResult Post(JobOrderHeaderViewModel svm)
        {
            JobOrderHeader        s       = Mapper.Map <JobOrderHeaderViewModel, JobOrderHeader>(svm);
            ProdOrderCancelHeader cHeader = new ProdOrderCancelHeader();

            if (svm.JobOrderSettings != null)
            {
                if (svm.JobOrderSettings.isMandatoryCostCenter == true && (svm.CostCenterId <= 0 || svm.CostCenterId == null))
                {
                    ModelState.AddModelError("CostCenterId", "The CostCenter field is required");
                }
                if (svm.JobOrderSettings.isMandatoryMachine == true && (svm.MachineId <= 0 || svm.MachineId == null))
                {
                    ModelState.AddModelError("MachineId", "The Machine field is required");
                }
                if (svm.JobOrderSettings.isPostedInStock == true && !svm.GodownId.HasValue)
                {
                    ModelState.AddModelError("GodownId", "The Godown field is required");
                }
            }

            #region DocTypeTimeLineValidation

            try
            {
                TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(svm), DocumentTimePlanTypeConstants.Create, 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))
            {
                List <ProdOrderHeaderListViewModel> ProdOrderIds = (List <ProdOrderHeaderListViewModel>)System.Web.HttpContext.Current.Session["ConfirmProdOrderIds"];
                bool CancelBalProdOrders = (bool)System.Web.HttpContext.Current.Session["CancelBalProdOrdrs"];
                bool CreateDyeingOrder   = ProdOrderIds.Any(m => m.Qty > 0);

                var ProdOrderLineIds = ProdOrderIds.Select(m => m.ProdOrderLineId).ToArray();

                var BalProdOrders = (from p in db.ViewProdOrderBalance.AsNoTracking()
                                     where ProdOrderLineIds.Contains(p.ProdOrderLineId)
                                     select p).ToList();

                var ProdOrderLines = (from p in db.ProdOrderLine.AsNoTracking()
                                      where ProdOrderLineIds.Contains(p.ProdOrderLineId)
                                      select p).ToList();

                var ProductIds = BalProdOrders.Select(m => m.ProductId).ToList();

                var Products = (from p in db.Product.AsNoTracking()
                                where ProductIds.Contains(p.ProductId)
                                select p).ToList();

                bool CancelQty = (from p in ProdOrderIds
                                  join t in BalProdOrders
                                  on p.ProdOrderLineId equals t.ProdOrderLineId
                                  where (t.BalanceQty - p.Qty) > 0
                                  select p).Any();
                CancelBalProdOrders = (CancelBalProdOrders && CancelQty);

                if (CreateDyeingOrder)
                {
                    s.CreatedDate   = DateTime.Now;
                    s.ModifiedDate  = DateTime.Now;
                    s.ActualDueDate = s.DueDate;
                    s.ActualDocDate = s.DocDate;
                    s.CreatedBy     = User.Identity.Name;
                    s.ModifiedBy    = User.Identity.Name;
                    s.Status        = (int)StatusConstants.Drafted;
                    _JobOrderHeaderService.Create(s);

                    new JobOrderHeaderStatusService(_unitOfWork).CreateHeaderStatus(s.JobOrderHeaderId, ref db, false);

                    if (svm.PerkViewModel != null)
                    {
                        foreach (PerkViewModel item in svm.PerkViewModel)
                        {
                            JobOrderPerk perk = Mapper.Map <PerkViewModel, JobOrderPerk>(item);
                            perk.CreatedBy        = User.Identity.Name;
                            perk.CreatedDate      = DateTime.Now;
                            perk.ModifiedBy       = User.Identity.Name;
                            perk.ModifiedDate     = DateTime.Now;
                            perk.JobOrderHeaderId = s.JobOrderHeaderId;
                            new JobOrderPerkService(_unitOfWork).Create(perk);
                        }
                    }
                }

                if (CancelBalProdOrders)
                {
                    cHeader.DocNo              = s.DocNo;
                    cHeader.DocDate            = s.DocDate;
                    cHeader.DocTypeId          = new DocumentTypeService(_unitOfWork).FindByName(TransactionDoctypeConstants.DyeingPlanCancel).DocumentTypeId;
                    cHeader.DivisionId         = s.DivisionId;
                    cHeader.SiteId             = s.SiteId;
                    cHeader.CreatedBy          = User.Identity.Name;
                    cHeader.CreatedDate        = DateTime.Now;
                    cHeader.ModifiedBy         = User.Identity.Name;
                    cHeader.ModifiedDate       = DateTime.Now;
                    cHeader.ReferenceDocId     = s.JobOrderHeaderId;
                    cHeader.ReferenceDocTypeId = s.DocTypeId;
                    cHeader.Remark             = s.Remark;
                    cHeader.ObjectState        = Model.ObjectState.Added;
                    new ProdOrderCancelHeaderService(_unitOfWork).Create(cHeader);
                }

                int Cnt = 0;

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



                JobOrderSettings Settings = new JobOrderSettingsService(_unitOfWork).GetJobOrderSettingsForDocument(s.DocTypeId, s.DivisionId, s.SiteId);

                int?MaxLineId = new JobOrderLineChargeService(_unitOfWork).GetMaxProductCharge(s.JobOrderHeaderId, "Web.JobOrderLines", "JobOrderHeaderId", "JobOrderLineId");

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

                int CalculationId = Settings.CalculationId ?? 0;

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

                foreach (var ProdORderLineId in ProdOrderIds)
                {
                    var BalProdOrderLine = BalProdOrders.Where(m => m.ProdOrderLineId == ProdORderLineId.ProdOrderLineId).FirstOrDefault();
                    var Product          = Products.Where(m => m.ProductId == BalProdOrderLine.ProductId).FirstOrDefault();


                    if (ProdORderLineId.Qty <= BalProdOrderLine.BalanceQty && ProdORderLineId.Qty > 0)
                    {
                        if (((Settings.isVisibleRate == false || Settings.isVisibleRate == true)))
                        {
                            JobOrderLine line = new JobOrderLine();

                            if (Settings.isPostedInStock ?? false)
                            {
                                StockViewModel StockViewModel = new StockViewModel();

                                if (Cnt == 0)
                                {
                                    StockViewModel.StockHeaderId = s.StockHeaderId ?? 0;
                                }
                                else
                                {
                                    if (s.StockHeaderId != null && s.StockHeaderId != 0)
                                    {
                                        StockViewModel.StockHeaderId = (int)s.StockHeaderId;
                                    }
                                    else
                                    {
                                        StockViewModel.StockHeaderId = -1;
                                    }
                                }

                                StockViewModel.StockId            = -Cnt;
                                StockViewModel.DocHeaderId        = s.JobOrderHeaderId;
                                StockViewModel.DocLineId          = line.JobOrderLineId;
                                StockViewModel.DocTypeId          = s.DocTypeId;
                                StockViewModel.StockHeaderDocDate = s.DocDate;
                                StockViewModel.StockDocDate       = s.DocDate;
                                StockViewModel.DocNo              = s.DocNo;
                                StockViewModel.DivisionId         = s.DivisionId;
                                StockViewModel.SiteId             = s.SiteId;
                                StockViewModel.CurrencyId         = null;
                                StockViewModel.PersonId           = s.JobWorkerId;
                                StockViewModel.ProductId          = BalProdOrderLine.ProductId;
                                StockViewModel.HeaderFromGodownId = null;
                                StockViewModel.HeaderGodownId     = s.GodownId;
                                StockViewModel.HeaderProcessId    = s.ProcessId;
                                StockViewModel.GodownId           = (int)s.GodownId;
                                StockViewModel.Remark             = s.Remark;
                                StockViewModel.Status             = s.Status;
                                StockViewModel.ProcessId          = s.ProcessId;
                                StockViewModel.LotNo              = null;
                                StockViewModel.CostCenterId       = s.CostCenterId;
                                StockViewModel.Qty_Iss            = ProdORderLineId.Qty;
                                StockViewModel.Qty_Rec            = 0;
                                StockViewModel.Rate          = 0;
                                StockViewModel.ExpiryDate    = null;
                                StockViewModel.Specification = ProdOrderLines.Where(m => m.ProdOrderLineId == ProdORderLineId.ProdOrderLineId).FirstOrDefault().Specification;
                                StockViewModel.Dimension1Id  = BalProdOrderLine.Dimension1Id;
                                StockViewModel.Dimension2Id  = BalProdOrderLine.Dimension2Id;
                                StockViewModel.CreatedBy     = User.Identity.Name;
                                StockViewModel.CreatedDate   = DateTime.Now;
                                StockViewModel.ModifiedBy    = User.Identity.Name;
                                StockViewModel.ModifiedDate  = DateTime.Now;

                                string StockPostingError = "";
                                StockPostingError = new StockService(_unitOfWork).StockPost(ref StockViewModel);

                                if (StockPostingError != "")
                                {
                                    string message = StockPostingError;
                                    ModelState.AddModelError("", message);
                                    return(View("Create", svm));
                                }

                                if (Cnt == 0)
                                {
                                    s.StockHeaderId = StockViewModel.StockHeaderId;
                                }
                                line.StockId = StockViewModel.StockId;
                            }



                            if (Settings.isPostedInStockProcess ?? false)
                            {
                                StockProcessViewModel StockProcessViewModel = new StockProcessViewModel();

                                if (s.StockHeaderId != null && s.StockHeaderId != 0)//If Transaction Header Table Has Stock Header Id Then It will Save Here.
                                {
                                    StockProcessViewModel.StockHeaderId = (int)s.StockHeaderId;
                                }
                                else if (Settings.isPostedInStock ?? false)//If Stok Header is already posted during stock posting then this statement will Execute.So theat Stock Header will not generate again.
                                {
                                    StockProcessViewModel.StockHeaderId = -1;
                                }
                                else if (Cnt > 0)//If function will only post in stock process then after first iteration of loop the stock header id will go -1
                                {
                                    StockProcessViewModel.StockHeaderId = -1;
                                }
                                else//If function will only post in stock process then this statement will execute.For Example Job consumption.
                                {
                                    StockProcessViewModel.StockHeaderId = 0;
                                }
                                StockProcessViewModel.StockProcessId      = -Cnt;
                                StockProcessViewModel.DocHeaderId         = s.JobOrderHeaderId;
                                StockProcessViewModel.DocLineId           = line.JobOrderLineId;
                                StockProcessViewModel.DocTypeId           = s.DocTypeId;
                                StockProcessViewModel.StockHeaderDocDate  = s.DocDate;
                                StockProcessViewModel.StockProcessDocDate = s.DocDate;
                                StockProcessViewModel.DocNo              = s.DocNo;
                                StockProcessViewModel.DivisionId         = s.DivisionId;
                                StockProcessViewModel.SiteId             = s.SiteId;
                                StockProcessViewModel.CurrencyId         = null;
                                StockProcessViewModel.PersonId           = s.JobWorkerId;
                                StockProcessViewModel.ProductId          = BalProdOrderLine.ProductId;
                                StockProcessViewModel.HeaderFromGodownId = null;
                                StockProcessViewModel.HeaderGodownId     = s.GodownId;
                                StockProcessViewModel.HeaderProcessId    = s.ProcessId;
                                StockProcessViewModel.GodownId           = s.GodownId;
                                StockProcessViewModel.Remark             = s.Remark;
                                StockProcessViewModel.Status             = s.Status;
                                StockProcessViewModel.ProcessId          = s.ProcessId;
                                StockProcessViewModel.LotNo              = null;
                                StockProcessViewModel.CostCenterId       = s.CostCenterId;
                                StockProcessViewModel.Qty_Iss            = 0;
                                StockProcessViewModel.Qty_Rec            = ProdORderLineId.Qty;
                                StockProcessViewModel.Rate          = 0;
                                StockProcessViewModel.ExpiryDate    = null;
                                StockProcessViewModel.Specification = ProdOrderLines.Where(m => m.ProdOrderLineId == ProdORderLineId.ProdOrderLineId).FirstOrDefault().Specification;
                                StockProcessViewModel.Dimension1Id  = BalProdOrderLine.Dimension1Id;
                                StockProcessViewModel.Dimension2Id  = BalProdOrderLine.Dimension2Id;
                                StockProcessViewModel.CreatedBy     = User.Identity.Name;
                                StockProcessViewModel.CreatedDate   = DateTime.Now;
                                StockProcessViewModel.ModifiedBy    = User.Identity.Name;
                                StockProcessViewModel.ModifiedDate  = DateTime.Now;

                                string StockProcessPostingError = "";
                                StockProcessPostingError = new StockProcessService(_unitOfWork).StockProcessPost(ref StockProcessViewModel);

                                if (StockProcessPostingError != "")
                                {
                                    string message = StockProcessPostingError;
                                    ModelState.AddModelError("", message);
                                    return(PartialView("_Results", svm));
                                }


                                if ((Settings.isPostedInStock ?? false) == false)
                                {
                                    if (Cnt == 0)
                                    {
                                        s.StockHeaderId = StockProcessViewModel.StockHeaderId;
                                    }
                                }

                                line.StockProcessId = StockProcessViewModel.StockProcessId;
                            }



                            line.JobOrderHeaderId = s.JobOrderHeaderId;
                            line.ProdOrderLineId  = BalProdOrderLine.ProdOrderLineId;
                            line.ProductId        = BalProdOrderLine.ProductId;
                            line.Dimension1Id     = BalProdOrderLine.Dimension1Id;
                            line.Dimension2Id     = BalProdOrderLine.Dimension2Id;
                            line.Specification    = ProdOrderLines.Where(m => m.ProdOrderLineId == ProdORderLineId.ProdOrderLineId).FirstOrDefault().Specification;
                            line.Qty        = ProdORderLineId.Qty;
                            line.Rate       = ProdORderLineId.Rate;
                            line.DealQty    = ProdORderLineId.Qty;
                            line.UnitId     = Product.UnitId;
                            line.DealUnitId = Product.UnitId;
                            line.Amount     = (line.DealQty * line.Rate);
                            line.UnitConversionMultiplier = 1;
                            line.CreatedDate    = DateTime.Now;
                            line.ModifiedDate   = DateTime.Now;
                            line.CreatedBy      = User.Identity.Name;
                            line.ModifiedBy     = User.Identity.Name;
                            line.JobOrderLineId = pk;
                            line.Sr             = pk;
                            line.ObjectState    = Model.ObjectState.Added;
                            new JobOrderLineService(_unitOfWork).Create(line);

                            new JobOrderLineStatusService(_unitOfWork).CreateLineStatus(line.JobOrderLineId, ref db, false);

                            LineList.Add(new LineDetailListViewModel {
                                Amount = line.Amount, Rate = line.Rate, LineTableId = line.JobOrderLineId, HeaderTableId = s.JobOrderHeaderId, PersonID = s.JobWorkerId, DealQty = line.DealQty
                            });

                            pk++;
                            Cnt++;
                        }
                    }


                    if (CancelBalProdOrders && (BalProdOrderLine.BalanceQty - ProdORderLineId.Qty > 0))
                    {
                        ProdOrderCancelLine cLine = new ProdOrderCancelLine();
                        cLine.CreatedBy               = User.Identity.Name;
                        cLine.CreatedDate             = DateTime.Now;
                        cLine.ModifiedBy              = User.Identity.Name;
                        cLine.ModifiedDate            = DateTime.Now;
                        cLine.ProdOrderCancelHeaderId = cHeader.ProdOrderCancelHeaderId;
                        cLine.ProdOrderLineId         = ProdORderLineId.ProdOrderLineId;
                        cLine.Qty = (BalProdOrderLine.BalanceQty - ProdORderLineId.Qty);
                        cLine.ReferenceDocTypeId = cHeader.ReferenceDocTypeId;
                        cLine.ObjectState        = Model.ObjectState.Added;
                        new ProdOrderCancelLineService(_unitOfWork).Create(cLine);
                    }
                }

                //new JobOrderHeaderService(_unitOfWork).Update(s);

                new ChargesCalculationService(_unitOfWork).CalculateCharges(LineList, s.JobOrderHeaderId, CalculationId, MaxLineId, out LineCharges, out HeaderChargeEdit, out HeaderCharges, "Web.JobOrderHeaderCharges", "Web.JobOrderLineCharges", out PersonCount, s.DocTypeId, s.SiteId, s.DivisionId);

                //Saving Charges
                foreach (var item in LineCharges)
                {
                    JobOrderLineCharge PoLineCharge = Mapper.Map <LineChargeViewModel, JobOrderLineCharge>(item);
                    PoLineCharge.ObjectState = Model.ObjectState.Added;
                    new JobOrderLineChargeService(_unitOfWork).Create(PoLineCharge);
                }


                //Saving Header charges
                for (int i = 0; i < HeaderCharges.Count(); i++)
                {
                    if (!HeaderChargeEdit)
                    {
                        JobOrderHeaderCharge POHeaderCharge = Mapper.Map <HeaderChargeViewModel, JobOrderHeaderCharge>(HeaderCharges[i]);
                        POHeaderCharge.HeaderTableId = s.JobOrderHeaderId;
                        POHeaderCharge.PersonID      = s.JobWorkerId;
                        POHeaderCharge.ObjectState   = Model.ObjectState.Added;
                        new JobOrderHeaderChargeService(_unitOfWork).Create(POHeaderCharge);
                    }
                    else
                    {
                        var footercharge = new JobOrderHeaderChargeService(_unitOfWork).Find(HeaderCharges[i].Id);
                        footercharge.Rate   = HeaderCharges[i].Rate;
                        footercharge.Amount = HeaderCharges[i].Amount;
                        new JobOrderHeaderChargeService(_unitOfWork).Update(footercharge);
                    }
                }



                try
                {
                    _unitOfWork.Save();
                }

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

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

                System.Web.HttpContext.Current.Session.Remove("ConfirmProdOrderIds");
                System.Web.HttpContext.Current.Session.Remove("CancelBalProdOrdrs");

                if (CreateDyeingOrder)
                {
                    return(Redirect(System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobOrderHeader/Submit/" + s.JobOrderHeaderId));
                }
                else
                {
                    return(Redirect(System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobOrderHeader/Index/" + s.DocTypeId));
                }
            }

            PrepareViewBag();
            ViewBag.Mode = "Add";
            return(View("Create", svm));
        }
 public void Delete(ProdOrderCancelLine p)
 {
     _unitOfWork.Repository <ProdOrderCancelLine>().Delete(p);
 }
 public ProdOrderCancelLine Create(ProdOrderCancelLine p)
 {
     p.ObjectState = ObjectState.Added;
     _unitOfWork.Repository <ProdOrderCancelLine>().Insert(p);
     return(p);
 }
 public ProdOrderCancelLine Add(ProdOrderCancelLine p)
 {
     _unitOfWork.Repository <ProdOrderCancelLine>().Insert(p);
     return(p);
 }
 public void Update(ProdOrderCancelLine p)
 {
     p.ObjectState = ObjectState.Modified;
     _unitOfWork.Repository <ProdOrderCancelLine>().Update(p);
 }