public PurchaseIndentCancelLine Create(PurchaseIndentCancelLine p)
 {
     p.ObjectState = ObjectState.Added;
     _unitOfWork.Repository <PurchaseIndentCancelLine>().Insert(p);
     return(p);
 }
 public void Delete(PurchaseIndentCancelLine p)
 {
     _unitOfWork.Repository <PurchaseIndentCancelLine>().Delete(p);
 }
 public void Update(PurchaseIndentCancelLine p)
 {
     p.ObjectState = ObjectState.Modified;
     _unitOfWork.Repository <PurchaseIndentCancelLine>().Update(p);
 }
 public PurchaseIndentCancelLine Add(PurchaseIndentCancelLine p)
 {
     _unitOfWork.Repository <PurchaseIndentCancelLine>().Insert(p);
     return(p);
 }
        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));
        }
        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));
        }
Beispiel #7
0
        public ActionResult _ResultsPost(PurchaseIndentCancelMasterDetailModel vm)
        {
            int Serial = _PurchaseIndentCancelLineService.GetMaxSr(vm.PurchaseIndentCancelViewModels.FirstOrDefault().PurchaseIndentCancelHeaderId);

            bool BeforeSave = true;

            try
            {
                BeforeSave = PurchaseIndentCancelDocEvents.beforeLineSaveBulkEvent(this, new PurchaseEventArgs(vm.PurchaseIndentCancelViewModels.FirstOrDefault().PurchaseIndentCancelHeaderId), 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)
            {
                foreach (var item in vm.PurchaseIndentCancelViewModels)
                {
                    decimal balqty = (from p in db.ViewPurchaseIndentBalance
                                      where p.PurchaseIndentLineId == item.PurchaseIndentLineId
                                      select p.BalanceQty).FirstOrDefault();
                    if (balqty < item.Qty)
                    {
                        ModelState.AddModelError("", "Qty Exceeding Balance Qty");
                        return(PartialView("_Results", vm));
                    }
                    if (item.Qty > 0)
                    {
                        PurchaseIndentCancelLine line = new PurchaseIndentCancelLine();

                        line.PurchaseIndentCancelHeaderId = item.PurchaseIndentCancelHeaderId;
                        line.PurchaseIndentLineId         = item.PurchaseIndentLineId;
                        line.Qty          = item.Qty;
                        line.CreatedDate  = DateTime.Now;
                        line.ModifiedDate = DateTime.Now;
                        line.CreatedBy    = User.Identity.Name;
                        line.ModifiedBy   = User.Identity.Name;
                        line.ObjectState  = Model.ObjectState.Added;
                        db.PurchaseIndentCancelLine.Add(line);

                        //_PurchaseIndentCancelLineService.Create(line);
                    }
                }

                PurchaseIndentCancelHeader Header = db.PurchaseIndentCancelHeader.Find(vm.PurchaseIndentCancelViewModels.FirstOrDefault().PurchaseIndentCancelHeaderId);

                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.PurchaseIndentCancelHeader.Add(Header);
                }

                try
                {
                    PurchaseIndentCancelDocEvents.onLineSaveBulkEvent(this, new PurchaseEventArgs(vm.PurchaseIndentCancelViewModels.FirstOrDefault().PurchaseIndentCancelHeaderId), 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
                {
                    PurchaseIndentCancelDocEvents.afterLineSaveBulkEvent(this, new PurchaseEventArgs(vm.PurchaseIndentCancelViewModels.FirstOrDefault().PurchaseIndentCancelHeaderId), ref db);
                }
                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    TempData["CSEXC"] += message;
                }

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

                return(Json(new { success = true }));
            }
            return(PartialView("_Results", vm));
        }
Beispiel #8
0
        public ActionResult DeletePost(PurchaseIndentCancelLineViewModel vm)
        {
            bool BeforeSave = true;

            try
            {
                BeforeSave = PurchaseIndentCancelDocEvents.beforeLineDeleteEvent(this, new PurchaseEventArgs(vm.PurchaseIndentCancelHeaderId, vm.PurchaseIndentCancelLineId), 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>();

                PurchaseIndentCancelLine IndentCancelLine = db.PurchaseIndentCancelLine.Find(vm.PurchaseIndentCancelLineId);

                try
                {
                    PurchaseIndentCancelDocEvents.onLineDeleteEvent(this, new PurchaseEventArgs(IndentCancelLine.PurchaseIndentCancelHeaderId, IndentCancelLine.PurchaseIndentCancelLineId), ref db);
                }
                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    TempData["CSEXCL"] += message;
                    EventException      = true;
                }

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

                IndentCancelLine.ObjectState = Model.ObjectState.Deleted;
                db.PurchaseIndentCancelLine.Remove(IndentCancelLine);

                //_PurchaseIndentCancelLineService.Delete(vm.PurchaseIndentCancelLineId);
                PurchaseIndentCancelHeader header = new PurchaseIndentCancelHeaderService(_unitOfWork).Find(IndentCancelLine.PurchaseIndentCancelHeaderId);
                if (header.Status != (int)StatusConstants.Drafted)
                {
                    header.Status = (int)StatusConstants.Modified;
                    //new PurchaseIndentCancelHeaderService(_unitOfWork).Update(header);
                    header.ModifiedBy   = User.Identity.Name;
                    header.ModifiedDate = DateTime.Now;
                    header.ObjectState  = Model.ObjectState.Modified;
                    db.PurchaseIndentCancelHeader.Add(header);
                }

                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
                {
                    PurchaseIndentCancelDocEvents.afterLineDeleteEvent(this, new PurchaseEventArgs(IndentCancelLine.PurchaseIndentCancelHeaderId, IndentCancelLine.PurchaseIndentCancelLineId), ref db);
                }
                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    TempData["CSEXC"] += message;
                }


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

            return(Json(new { success = true }));
        }
Beispiel #9
0
        public ActionResult _CreatePost(PurchaseIndentCancelLineViewModel svm)
        {
            if (svm.PurchaseIndentCancelLineId <= 0)
            {
                ViewBag.LineMode = "Create";
            }
            else
            {
                ViewBag.LineMode = "Edit";
            }

            bool BeforeSave = true;

            try
            {
                if (svm.PurchaseIndentLineId <= 0)
                {
                    BeforeSave = PurchaseIndentCancelDocEvents.beforeLineSaveEvent(this, new PurchaseEventArgs(svm.PurchaseIndentCancelHeaderId, EventModeConstants.Add), ref db);
                }
                else
                {
                    BeforeSave = PurchaseIndentCancelDocEvents.beforeLineSaveEvent(this, new PurchaseEventArgs(svm.PurchaseIndentCancelHeaderId, 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 (svm.PurchaseIndentCancelLineId <= 0)
            {
                PurchaseIndentCancelLine s = new PurchaseIndentCancelLine();
                decimal balqty             = (from p in db.ViewPurchaseIndentBalance
                                              where p.PurchaseIndentLineId == svm.PurchaseIndentLineId
                                              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.PurchaseIndentLineId <= 0)
                {
                    ModelState.AddModelError("PurchaseIndentLineId", "The Purchase Indent field is required");
                }
                if (ModelState.IsValid && BeforeSave && !EventException)
                {
                    s.PurchaseIndentCancelHeaderId = svm.PurchaseIndentCancelHeaderId;
                    s.PurchaseIndentLineId         = svm.PurchaseIndentLineId;
                    s.Qty          = svm.Qty;
                    s.CreatedDate  = DateTime.Now;
                    s.ModifiedDate = DateTime.Now;
                    s.Sr           = _PurchaseIndentCancelLineService.GetMaxSr(s.PurchaseIndentCancelHeaderId);
                    s.CreatedBy    = User.Identity.Name;
                    s.ModifiedBy   = User.Identity.Name;
                    //_PurchaseIndentCancelLineService.Create(s);
                    s.ObjectState = Model.ObjectState.Added;
                    db.PurchaseIndentCancelLine.Add(s);

                    PurchaseIndentCancelHeader temp2 = new PurchaseIndentCancelHeaderService(_unitOfWork).Find(s.PurchaseIndentCancelHeaderId);
                    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;
                        temp2.ObjectState  = Model.ObjectState.Modified;
                        db.PurchaseIndentCancelHeader.Add(temp2);
                        //new PurchaseIndentCancelHeaderService(_unitOfWork).Update(temp2);
                    }

                    try
                    {
                        PurchaseIndentCancelDocEvents.onLineSaveEvent(this, new PurchaseEventArgs(s.PurchaseIndentCancelHeaderId, s.PurchaseIndentCancelLineId, 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
                    {
                        PurchaseIndentCancelDocEvents.afterLineSaveEvent(this, new PurchaseEventArgs(s.PurchaseIndentCancelHeaderId, s.PurchaseIndentCancelLineId, EventModeConstants.Add), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXCL"] += message;
                    }


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


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

                PurchaseIndentCancelHeader temp = new PurchaseIndentCancelHeaderService(_unitOfWork).Find(svm.PurchaseIndentCancelHeaderId);


                int           status    = temp.Status;
                StringBuilder logstring = new StringBuilder();

                PurchaseIndentCancelLine s = _PurchaseIndentCancelLineService.Find(svm.PurchaseIndentCancelLineId);

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

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


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

                    s.ObjectState = Model.ObjectState.Modified;
                    db.PurchaseIndentCancelLine.Add(s);

                    //_PurchaseIndentCancelLineService.Update(s);

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

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

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

                    try
                    {
                        PurchaseIndentCancelDocEvents.onLineSaveEvent(this, new PurchaseEventArgs(s.PurchaseIndentCancelHeaderId, s.PurchaseIndentCancelLineId, 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
                    {
                        PurchaseIndentCancelDocEvents.afterLineSaveEvent(this, new PurchaseEventArgs(s.PurchaseIndentCancelHeaderId, s.PurchaseIndentCancelLineId, EventModeConstants.Edit), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                    }


                    //SAving the Activity Log::

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

                    return(Json(new { success = true }));
                }
                return(PartialView("_Create", svm));
            }
        }