Beispiel #1
0
        public ActionResult Post(FeetConversionToCms vm)
        {
            FeetConversionToCms pt = vm;

            if (ModelState.IsValid)
            {
                if (vm.FeetConversionToCmsId <= 0)
                {
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;
                    _FeetConversionToCmsService.Create(pt);

                    try
                    {
                        _unitOfWork.Save();
                    }

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

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId    = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.FeetConversionToCms).DocumentTypeId,
                        DocId        = pt.FeetConversionToCmsId,
                        ActivityType = (int)ActivityTypeContants.Added,
                    }));

                    return(RedirectToAction("Create").Success("Data saved successfully"));
                }
                else
                {
                    List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                    FeetConversionToCms temp = _FeetConversionToCmsService.Find(pt.FeetConversionToCmsId);

                    FeetConversionToCms ExRec = Mapper.Map <FeetConversionToCms>(temp);

                    temp.Feet         = pt.Feet;
                    temp.Inch         = pt.Inch;
                    temp.Cms          = pt.Cms;
                    temp.ModifiedDate = DateTime.Now;
                    temp.ModifiedBy   = User.Identity.Name;
                    temp.ObjectState  = Model.ObjectState.Modified;
                    _FeetConversionToCmsService.Update(temp);

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

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        return(View("Create", pt));
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.FeetConversionToCms).DocumentTypeId,
                        DocId           = temp.FeetConversionToCmsId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        xEModifications = Modifications,
                    }));

                    return(RedirectToAction("Index").Success("Data saved successfully"));
                }
            }
            return(View("Create", vm));
        }
        public ActionResult Post(ProductInvoiceGroup vm)
        {
            ProductInvoiceGroup pt = vm;

            if (ModelState.IsValid)
            {
                if (vm.ProductInvoiceGroupId <= 0)
                {
                    //pt.DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"];
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;
                    _ProductInvoiceGroupService.Create(pt);

                    try
                    {
                        _unitOfWork.Save();
                    }

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

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId    = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProductInvoiceGroup).DocumentTypeId,
                        DocId        = pt.ProductInvoiceGroupId,
                        ActivityType = (int)ActivityTypeContants.Added,
                    }));


                    return(RedirectToAction("Create").Success("Data saved successfully"));
                }
                else
                {
                    List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                    ProductInvoiceGroup temp = _ProductInvoiceGroupService.Find(pt.ProductInvoiceGroupId);

                    ProductInvoiceGroup ExRec = Mapper.Map <ProductInvoiceGroup>(temp);

                    temp.ProductInvoiceGroupName = pt.ProductInvoiceGroupName;
                    temp.DivisionId              = pt.DivisionId;
                    temp.IsActive                = pt.IsActive;
                    temp.ItcHsCode               = pt.ItcHsCode;
                    temp.Rate                    = pt.Rate;
                    temp.Weight                  = pt.Weight;
                    temp.Knots                   = pt.Knots;
                    temp.DescriptionOfGoodsId    = pt.DescriptionOfGoodsId;
                    temp.IsSample                = pt.IsSample;
                    temp.SeparateWeightInInvoice = pt.SeparateWeightInInvoice;
                    temp.ModifiedDate            = DateTime.Now;
                    temp.ModifiedBy              = User.Identity.Name;
                    temp.ObjectState             = Model.ObjectState.Modified;
                    _ProductInvoiceGroupService.Update(temp);

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

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        return(View("Create", pt));
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProductInvoiceGroup).DocumentTypeId,
                        DocId           = temp.ProductInvoiceGroupId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        xEModifications = Modifications,
                    }));

                    return(RedirectToAction("Index").Success("Data saved successfully"));
                }
            }

            return(View("Create", vm));
        }
        public ActionResult Post(ProductBuyerSettingsViewModel vm)
        {
            ProductBuyerSettings pt = AutoMapper.Mapper.Map <ProductBuyerSettingsViewModel, ProductBuyerSettings>(vm);


            if (ModelState.IsValid)
            {
                if (vm.ProductBuyerSettingsId <= 0)
                {
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;
                    _ProductBuyerSettingsService.Create(pt);

                    try
                    {
                        _unitOfWork.Save();
                    }

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

                    int DocTypeId = new DocumentTypeService(_unitOfWork).Find(MasterDocTypeConstants.Carpet).DocumentTypeId;

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocId        = pt.ProductBuyerSettingsId,
                        DocTypeId    = DocTypeId,
                        ActivityType = (int)ActivityTypeContants.SettingsAdded,
                    }));



                    return(RedirectToAction("Index", "ProductBuyer", new { id = vm.ProductId }).Success("Data saved successfully"));
                }
                else
                {
                    List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                    ProductBuyerSettings temp = _ProductBuyerSettingsService.Find(pt.ProductBuyerSettingsId);

                    ProductBuyerSettings ExRec = Mapper.Map <ProductBuyerSettings>(temp);

                    temp.BuyerSpecificationDisplayName  = vm.BuyerSpecificationDisplayName;
                    temp.BuyerSpecification1DisplayName = vm.BuyerSpecification1DisplayName;
                    temp.BuyerSpecification2DisplayName = vm.BuyerSpecification2DisplayName;
                    temp.BuyerSpecification3DisplayName = vm.BuyerSpecification3DisplayName;
                    temp.BuyerSpecification4DisplayName = vm.BuyerSpecification4DisplayName;
                    temp.BuyerSpecification5DisplayName = vm.BuyerSpecification5DisplayName;
                    temp.BuyerSpecification6DisplayName = vm.BuyerSpecification6DisplayName;
                    temp.ModifiedDate = DateTime.Now;
                    temp.ModifiedBy   = User.Identity.Name;
                    temp.ObjectState  = Model.ObjectState.Modified;
                    _ProductBuyerSettingsService.Update(temp);

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

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

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        PrepareViewBag(vm);
                        return(View("Create", pt));
                    }

                    int DocTypeId = new DocumentTypeService(_unitOfWork).Find(MasterDocTypeConstants.Carpet).DocumentTypeId;

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocId           = temp.ProductBuyerSettingsId,
                        ActivityType    = (int)ActivityTypeContants.SettingsModified,
                        DocTypeId       = DocTypeId,
                        xEModifications = Modifications,
                    }));

                    return(RedirectToAction("Index", "ProductBuyer", new { id = vm.ProductId }).Success("Data saved successfully"));
                }
            }
            PrepareViewBag(vm);
            return(View("Create", vm));
        }
        public ActionResult _CreatePost(ProductBuyerViewModel vm)
        {
            ProductBuyer pt = AutoMapper.Mapper.Map <ProductBuyerViewModel, ProductBuyer>(vm);

            if (ModelState.IsValid)
            {
                if (vm.ProductBuyerId <= 0)
                {
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;
                    new ProductBuyerService(_unitOfWork).Create(pt);

                    try
                    {
                        _unitOfWork.Save();
                    }

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

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId    = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProductBuyer).DocumentTypeId,
                        DocId        = pt.ProductBuyerId,
                        ActivityType = (int)ActivityTypeContants.Added,
                    }));

                    return(RedirectToAction("_Create", new { ProductId = pt.ProductId }));
                }
                else
                {
                    List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                    ProductBuyer temp = new ProductBuyerService(_unitOfWork).Find(pt.ProductBuyerId);

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

                    temp.BuyerId             = pt.BuyerId;
                    temp.BuyerSku            = pt.BuyerSku;
                    temp.BuyerSpecification  = pt.BuyerSpecification;
                    temp.BuyerSpecification1 = pt.BuyerSpecification1;
                    temp.BuyerSpecification2 = pt.BuyerSpecification2;
                    temp.BuyerSpecification3 = pt.BuyerSpecification3;
                    temp.BuyerSpecification4 = pt.BuyerSpecification4;
                    temp.BuyerSpecification5 = pt.BuyerSpecification5;
                    temp.BuyerSpecification6 = pt.BuyerSpecification6;
                    temp.BuyerUpcCode        = pt.BuyerUpcCode;
                    temp.ModifiedDate        = DateTime.Now;
                    temp.ModifiedBy          = User.Identity.Name;
                    temp.ObjectState         = Model.ObjectState.Modified;
                    new ProductBuyerService(_unitOfWork).Update(temp);

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

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

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProductBuyer).DocumentTypeId,
                        DocId           = temp.ProductBuyerId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        xEModifications = Modifications,
                    }));

                    return(Json(new { success = true }));
                }
            }
            return(PartialView("_Create", vm));
        }
Beispiel #5
0
        public ActionResult Post(ProductQuality vm)
        {
            ProductQuality pt = vm;

            if (ModelState.IsValid)
            {
                if (vm.ProductQualityId <= 0)
                {
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;
                    _ProductQualityService.Create(pt);

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        ViewBag.id   = vm.ProductTypeId;
                        ViewBag.Name = new ProductTypeService(_unitOfWork).Find(vm.ProductTypeId).ProductTypeName;
                        return(View("Create", vm));
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId    = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProductQuality).DocumentTypeId,
                        DocId        = pt.ProductQualityId,
                        ActivityType = (int)ActivityTypeContants.Added,
                    }));

                    return(RedirectToAction("Create", new { id = vm.ProductTypeId }).Success("Data saved successfully"));
                }
                else
                {
                    List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();
                    ProductQuality          temp    = _ProductQualityService.Find(pt.ProductQualityId);

                    ProductQuality ExRec = Mapper.Map <ProductQuality>(temp);

                    temp.ProductQualityName = pt.ProductQualityName;
                    temp.IsActive           = pt.IsActive;
                    temp.ModifiedDate       = DateTime.Now;
                    temp.ModifiedBy         = User.Identity.Name;
                    temp.ObjectState        = Model.ObjectState.Modified;
                    _ProductQualityService.Update(temp);

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

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        ViewBag.id   = pt.ProductTypeId;
                        ViewBag.Name = new ProductTypeService(_unitOfWork).Find(pt.ProductTypeId).ProductTypeName;
                        return(View("Create", pt));
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProductQuality).DocumentTypeId,
                        DocId           = temp.ProductQualityId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        xEModifications = Modifications,
                    }));

                    return(RedirectToAction("Index", new { id = pt.ProductTypeId }).Success("Data saved successfully"));
                }
            }
            ViewBag.id   = vm.ProductTypeId;
            ViewBag.Name = new ProductTypeService(_unitOfWork).Find(vm.ProductTypeId).ProductTypeName;
            return(View("Create", vm));
        }
        public ActionResult Post(ProductCollection vm)
        {
            ProductCollection pt = vm;

            if (ModelState.IsValid)
            {
                if (vm.ProductCollectionId <= 0)
                {
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;
                    _ProductCollectionService.Create(pt);

                    int RefDocTypeId = new DocumentTypeService(_unitOfWork).Find(MasterDocTypeConstants.ProductCollection).DocumentTypeId;

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        ViewBag.id   = vm.ProductTypeId;
                        ViewBag.Name = new ProductTypeService(_unitOfWork).Find(vm.ProductTypeId).ProductTypeName;
                        return(View("Create", vm));
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId    = RefDocTypeId,
                        DocId        = pt.ProductCollectionId,
                        ActivityType = (int)ActivityTypeContants.Added,
                    }));

                    ViewBag.id   = vm.ProductTypeId;
                    ViewBag.Name = new ProductTypeService(_unitOfWork).Find(vm.ProductTypeId).ProductTypeName;
                    return(RedirectToAction("Edit", new { id = pt.ProductCollectionId }).Success("Data saved successfully"));
                }

                else
                {
                    List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();
                    ProductCollection       temp    = _ProductCollectionService.Find(pt.ProductCollectionId);
                    int RefDocTypeId = new DocumentTypeService(_unitOfWork).Find(MasterDocTypeConstants.ProductCollection).DocumentTypeId;

                    ProductCollection ExRec = Mapper.Map <ProductCollection>(temp);

                    temp.ProductCollectionName = pt.ProductCollectionName;
                    temp.IsActive     = pt.IsActive;
                    temp.ModifiedDate = DateTime.Now;
                    temp.ModifiedBy   = User.Identity.Name;
                    temp.ObjectState  = Model.ObjectState.Modified;
                    _ProductCollectionService.Update(temp);

                    var ProcSeqHeader = (from p in db.ProcessSequenceHeader
                                         where p.ReferenceDocId == temp.ProductCollectionId && p.ReferenceDocTypeId == RefDocTypeId
                                         select p).FirstOrDefault();

                    if (ProcSeqHeader != null)
                    {
                        ProcSeqHeader.ProcessSequenceHeaderName = temp.ProductCollectionName + "-" + new DivisionService(_unitOfWork).Find((int)HttpContext.Session["DivisionId"]).DivisionName;
                    }


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

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        ViewBag.id   = pt.ProductTypeId;
                        ViewBag.Name = new ProductTypeService(_unitOfWork).Find(pt.ProductTypeId).ProductTypeName;
                        return(View("Create", pt));
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId       = RefDocTypeId,
                        DocId           = temp.ProductCollectionId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        xEModifications = Modifications,
                    }));

                    ViewBag.id   = pt.ProductTypeId;
                    ViewBag.Name = new ProductTypeService(_unitOfWork).Find(pt.ProductTypeId).ProductTypeName;
                    return(RedirectToAction("Index", new { id = vm.ProductTypeId }).Success("Data saved successfully"));
                }
            }
            ViewBag.id   = vm.ProductTypeId;
            ViewBag.Name = new ProductTypeService(_unitOfWork).Find(vm.ProductTypeId).ProductTypeName;
            return(View("Create", vm));
        }
        public ActionResult _CreatePost(ProductConsumptionLineViewModel svm)
        {
            if (ModelState.IsValid)
            {
                if (svm.BomDetailId == 0)
                {
                    BomDetail bomdetail = new BomDetail();

                    bomdetail.BaseProductId  = svm.BaseProductId;
                    bomdetail.BatchQty       = 1;
                    bomdetail.ConsumptionPer = svm.ConsumptionPer;
                    bomdetail.Dimension1Id   = svm.Dimension1Id;
                    bomdetail.ProcessId      = new ProcessService(_unitOfWork).Find(ProcessConstants.Weaving).ProcessId;
                    bomdetail.ProductId      = svm.ProductId;
                    bomdetail.Qty            = svm.Qty;

                    bomdetail.CreatedDate  = DateTime.Now;
                    bomdetail.ModifiedDate = DateTime.Now;
                    bomdetail.CreatedBy    = User.Identity.Name;
                    bomdetail.ModifiedBy   = User.Identity.Name;
                    bomdetail.ObjectState  = Model.ObjectState.Added;
                    _BomDetailService.Create(bomdetail);


                    if (bomdetail.BaseProductId == bomdetail.ProductId)
                    {
                        //return View(svm).Danger(DataValidationMsg);
                        ModelState.AddModelError("", "Invalid Product is Selected!");
                        return(PartialView("_Create", svm));
                    }

                    try
                    {
                        _unitOfWork.Save();
                    }

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


                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId    = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProductConsumption).DocumentTypeId,
                        DocId        = bomdetail.BomDetailId,
                        ActivityType = (int)ActivityTypeContants.Added,
                    }));

                    return(RedirectToAction("_Create", new { id = svm.BaseProductId }));
                }
                else
                {
                    List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();
                    BomDetail bomdetail             = _BomDetailService.Find(svm.BomDetailId);

                    BomDetail ExRec = Mapper.Map <BomDetail>(bomdetail);

                    bomdetail.BaseProductId  = svm.BaseProductId;
                    bomdetail.BatchQty       = 1;
                    bomdetail.ConsumptionPer = svm.ConsumptionPer;
                    bomdetail.Dimension1Id   = svm.Dimension1Id;
                    bomdetail.ProductId      = svm.ProductId;
                    bomdetail.Qty            = svm.Qty;


                    bomdetail.ModifiedDate = DateTime.Now;
                    bomdetail.ModifiedBy   = User.Identity.Name;
                    bomdetail.ObjectState  = Model.ObjectState.Modified;
                    _BomDetailService.Update(bomdetail);


                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = ExRec,
                        Obj   = bomdetail,
                    });
                    XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);

                    try
                    {
                        _unitOfWork.Save();
                    }

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

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProductConsumption).DocumentTypeId,
                        DocId           = bomdetail.BomDetailId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        xEModifications = Modifications,
                    }));

                    return(Json(new { success = true }));
                }
            }
            return(PartialView("_Create", svm));
        }
Beispiel #8
0
        public ActionResult PostIAPSummary(JobReceiveIAPSummaryDetailViewModel vm)
        {
            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();
            bool Modified = false;

            int Id = vm.JobReceiveHeaderId;

            var Header = _JobReceiveHeaderService.Find(Id);

            int[] BarCodes = vm.JobReceiveIAPSummaryViewModel.Select(m => m.ProductUidId).ToArray();

            var ReceiveLines = (from p in db.JobReceiveLine
                                where p.JobReceiveHeaderId == Id && p.ProductUidId != null && BarCodes.Contains(p.ProductUidId.Value)
                                select p);

            foreach (var item in vm.JobReceiveIAPSummaryViewModel)
            {
                var ReceiveLine = ReceiveLines.Where(m => m.ProductUidId == item.ProductUidId).FirstOrDefault();

                if (ReceiveLine.PenaltyAmt != item.PenalityAmt || (ReceiveLine.IncentiveAmt != item.IncentiveAmt) || ReceiveLine.Remark != item.Remark)
                {
                    JobReceiveLine ExRec = new JobReceiveLine();
                    ExRec = Mapper.Map <JobReceiveLine>(ReceiveLine);
                    ReceiveLine.PenaltyAmt   = item.PenalityAmt;
                    ReceiveLine.IncentiveAmt = item.IncentiveAmt;
                    ReceiveLine.Remark       = item.Remark;
                    ReceiveLine.ModifiedBy   = User.Identity.Name;
                    ReceiveLine.ModifiedDate = DateTime.Now;
                    ReceiveLine.ObjectState  = Model.ObjectState.Modified;

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

                    _JobReceiveLineService.Update(ReceiveLine);
                    Modified = true;
                }
            }


            if ((Header.Status != (int)StatusConstants.Drafted && Header.Status != (int)StatusConstants.Import) && Modified)
            {
                Header.Status     = (int)StatusConstants.Modified;
                Header.ModifiedBy = User.Identity.Name;
            }

            Header.ObjectState = Model.ObjectState.Modified;
            new JobReceiveHeaderService(_unitOfWork).Update(Header);

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

            try
            {
                _unitOfWork.Save();
            }

            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                ModelState.AddModelError("", message);
                PrepareViewBag(vm.JobReceiveHeaderId);
                return(Json(new { Success = false }));
            }

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

            string RetUrl = "";

            if (Header.Status == (int)StatusConstants.Drafted || Header.Status == (int)StatusConstants.Import)
            {
                RetUrl = (System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobReceiveHeader/Modify/" + Header.JobReceiveHeaderId);
            }
            else if (Header.Status == (int)StatusConstants.Submitted || Header.Status == (int)StatusConstants.ModificationSubmitted || Header.Status == (int)StatusConstants.Modified)
            {
                RetUrl = (System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobReceiveHeader/ModifyAfter_Submit/" + Header.JobReceiveHeaderId);
            }
            else if (Header.Status == (int)StatusConstants.Approved || Header.Status == (int)StatusConstants.Closed)
            {
                RetUrl = (System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobReceiveHeader/ModifyAfter_Approve/" + Header.JobReceiveHeaderId);
            }
            else
            {
                RetUrl = (System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobReceiveHeader/Index/" + Header.DocTypeId);
            }

            return(Json(new { Success = true, Url = RetUrl }));
        }
Beispiel #9
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));
        }
Beispiel #10
0
        public ActionResult Post(UnitConversionViewModel vm)
        {
            UnitConversion pt = AutoMapper.Mapper.Map <UnitConversionViewModel, UnitConversion>(vm);

            if (ModelState.IsValid)
            {
                if (vm.UnitConversionId <= 0)
                {
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;
                    _UnitConversionService.Create(pt);

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        PrepareViewBag(pt.ProductId ?? 0);
                        return(View("Create", vm));
                    }


                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId    = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.UnitConversion).DocumentTypeId,
                        DocId        = pt.UnitConversionId,
                        ActivityType = (int)ActivityTypeContants.Added,
                    }));

                    return(RedirectToAction("Create", new { ProductId = pt.ProductId }).Success("Data saved successfully"));
                }
                else
                {
                    List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                    UnitConversion temp  = _UnitConversionService.Find(pt.UnitConversionId);
                    UnitConversion ExRec = new UnitConversion();
                    ExRec = Mapper.Map <UnitConversion>(temp);


                    temp.FromQty             = pt.FromQty;
                    temp.FromUnitId          = pt.FromUnitId;
                    temp.ToQty               = pt.ToQty;
                    temp.ToUnitId            = pt.ToUnitId;
                    temp.UnitConversionForId = pt.UnitConversionForId;
                    temp.ModifiedDate        = DateTime.Now;
                    temp.Description         = pt.Description;
                    temp.ModifiedBy          = User.Identity.Name;
                    temp.ObjectState         = Model.ObjectState.Modified;
                    _UnitConversionService.Update(temp);
                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = ExRec,
                        Obj   = temp,
                    });
                    XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);
                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        PrepareViewBag(pt.ProductId ?? 0);
                        return(View("Create", pt));
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.UnitConversion).DocumentTypeId,
                        DocId           = temp.UnitConversionId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        xEModifications = Modifications,
                    }));

                    return(RedirectToAction("Index", new { id = vm.ProductId }).Success("Data saved successfully"));
                }
            }
            PrepareViewBag(pt.ProductId ?? 0);
            return(View("Create", vm));
        }
Beispiel #11
0
        public ActionResult PostSummary(JobReceiveSummaryDetailViewModel vm)
        {
            //TempData["CSEXC"] = "Customize Test Exception";

            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();
            bool Modified = false;
            int  Id       = vm.JobReceiveHeaderId;

            var Header = _JobReceiveHeaderService.Find(Id);

            var JobReceives = (from p in db.JobReceiveLine
                               join t in db.JobOrderLine on p.JobOrderLineId equals t.JobOrderLineId
                               where p.JobReceiveHeaderId == Id
                               group t by new { t.ProductId, t.JobOrderHeaderId } into g
                               select g.Key).ToList();

            foreach (var item in vm.JobReceiveSummaryViewModel)
            {
                // Receive Line which has return also and return has no weight then receive weight should be 0.
                //var ReceiveWithReturnLines = from p in db.JobReceiveLine
                //                    join t in db.JobOrderLine on p.JobOrderLineId equals t.JobOrderLineId
                //                    join t2 in db.JobReceiveLineStatus on p.JobReceiveLineId equals t2.JobReceiveLineId into table
                //                    from tab in table.DefaultIfEmpty()
                //                    where t.JobOrderHeaderId == item.JobOrderHeaderId && p.PassQty > 0 && p.JobReceiveHeaderId == Id && t.ProductId == item.ProductId
                //                    && (p.PassQty - (tab.ReturnQty ?? 0)) == 0
                //                    select p;


                //foreach (var item3 in ReceiveWithReturnLines)
                //{

                //    item3.Weight = 0;
                //    item3.ObjectState = Model.ObjectState.Modified;
                //    _JobReceiveLineService.Update(item3);
                //}



                var ReceiveLines = (from p in db.JobReceiveLine
                                    join t in db.JobOrderLine on p.JobOrderLineId equals t.JobOrderLineId
                                    join t2 in db.JobReceiveLineStatus on p.JobReceiveLineId equals t2.JobReceiveLineId into table
                                    from tab in table.DefaultIfEmpty()
                                    where t.JobOrderHeaderId == item.JobOrderHeaderId && p.PassQty > 0 && p.JobReceiveHeaderId == Id && t.ProductId == item.ProductId &&
                                    (p.PassQty - (tab.ReturnQty ?? 0)) > 0
                                    select p).ToList();

                bool ValidationError = ReceiveLines.Where(m => m.Weight > 0).Any() && ReceiveLines.Where(m => m.Weight == 0).Any();

                if (ReceiveLines != null && ReceiveLines.Count > 0)
                {
                    decimal Weight = item.Weight;

                    decimal XWeight = ReceiveLines.Sum(m => m.Weight);

                    decimal PassQty = ReceiveLines.Sum(m => m.PassQty);


                    if (Weight != XWeight)
                    {
                        int     i = 0;
                        decimal WeightShortage   = 0;
                        decimal IndividualWeight = Math.Round((Weight / PassQty), 2);
                        if (i == 0 && IndividualWeight * PassQty != Weight)
                        {
                            WeightShortage = (Weight - (IndividualWeight * PassQty));
                        }

                        foreach (var item2 in ReceiveLines)
                        {
                            JobReceiveLine ExRec = new JobReceiveLine();
                            ExRec = Mapper.Map <JobReceiveLine>(item2);

                            item2.Weight       = IndividualWeight * item2.PassQty + (i == 0 ? WeightShortage : 0);
                            item2.ModifiedBy   = User.Identity.Name;
                            item2.ModifiedDate = DateTime.Now;
                            item2.ObjectState  = Model.ObjectState.Modified;

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

                            _JobReceiveLineService.Update(item2);
                            i++;

                            Modified = true;
                        }
                    }
                }
            }

            if ((Header.Status != (int)StatusConstants.Drafted && Header.Status != (int)StatusConstants.Import) && Modified)
            {
                Header.Status     = (int)StatusConstants.Modified;
                Header.ModifiedBy = User.Identity.Name;
            }

            Header.ModifiedDate = DateTime.Now;
            Header.ObjectState  = Model.ObjectState.Modified;
            new JobReceiveHeaderService(_unitOfWork).Update(Header);

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

            try
            {
                _unitOfWork.Save();
            }

            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                ModelState.AddModelError("", message);
                PrepareViewBag(vm.JobReceiveHeaderId);
                return(Json(new { Success = false }));
            }

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

            string RetUrl = "";


            if (Header.Status == (int)StatusConstants.Drafted || Header.Status == (int)StatusConstants.Import)
            {
                RetUrl = System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobReceiveHeader/Modify/" + Header.JobReceiveHeaderId;
            }
            else if (Header.Status == (int)StatusConstants.Submitted || Header.Status == (int)StatusConstants.ModificationSubmitted || Header.Status == (int)StatusConstants.Modified)
            {
                RetUrl = System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobReceiveHeader/ModifyAfter_Submit/" + Header.JobReceiveHeaderId;
            }
            else if (Header.Status == (int)StatusConstants.Approved || Header.Status == (int)StatusConstants.Closed)
            {
                RetUrl = System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobReceiveHeader/ModifyAfter_Approve/" + Header.JobReceiveHeaderId;
            }
            else
            {
                RetUrl = System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobReceiveHeader/Index/" + Header.DocTypeId;
            }

            return(Json(new { Success = true, Url = RetUrl }));
        }
        public ActionResult ReportPrint(FormCollection form, string ReportFileType)
        {
            var       SubReportDataList = new List <DataTable>();
            var       SubReportNameList = new List <string>();
            DataTable ReportData        = new DataTable();
            Dictionary <string, string> ReportFilters = new Dictionary <string, string>();
            StringBuilder queryString = new StringBuilder();

            string ReportHeaderId = (form["ReportHeaderId"].ToString());

            ReportHeader      header = new ReportHeaderService(_unitOfWork).GetReportHeader(Convert.ToInt32(ReportHeaderId));
            List <ReportLine> lines  = _ReportLineService.GetReportLineList(header.ReportHeaderId).ToList();


            if (string.IsNullOrEmpty(header.ReportSQL))
            {
                //List<string> SubReportProcList = new ReportHeaderService(_unitOfWork).GetSubReportProcList (Convert.ToInt32(ReportHeaderId));
                List <string> SubReportProcList = new List <string>();

                ApplicationDbContext Db = new ApplicationDbContext();
                queryString.Append(db.strSchemaName + "." + header.SqlProc);


                using (SqlConnection sqlConnection = new SqlConnection(connectionString))
                {
                    SqlCommand cmd = new SqlCommand(queryString.ToString(), sqlConnection);

                    foreach (var item in lines)
                    {
                        if (item.SqlParameter != "" && item.SqlParameter != null)
                        {
                            if (item.SqlParameter == "@LoginSite" || item.SqlParameter == "@LoginDivision")
                            {
                                if (item.SqlParameter == "@LoginSite")
                                {
                                    cmd.Parameters.AddWithValue(item.SqlParameter, (int)System.Web.HttpContext.Current.Session[SessionNameConstants.LoginSiteId]);
                                }
                                //cmd.Parameters.AddWithValue(item.SqlParameter, 17);
                                else if (item.SqlParameter == "@LoginDivision")
                                {
                                    cmd.Parameters.AddWithValue(item.SqlParameter, (int)System.Web.HttpContext.Current.Session[SessionNameConstants.LoginDivisionId]);
                                }
                            }
                            else if (item.FieldName == "Site" && form[item.FieldName].ToString() == "")
                            {
                                cmd.Parameters.AddWithValue(item.SqlParameter, (int)System.Web.HttpContext.Current.Session[SessionNameConstants.LoginSiteId]);
                            }

                            else if (item.FieldName == "Division" && form[item.FieldName].ToString() == "")
                            {
                                cmd.Parameters.AddWithValue(item.SqlParameter, (int)System.Web.HttpContext.Current.Session[SessionNameConstants.LoginDivisionId]);
                            }

                            else
                            {
                                if (form[item.FieldName].ToString() != "")
                                {
                                    if (item.DataType == "Date")
                                    {
                                        cmd.Parameters.AddWithValue(item.SqlParameter, (form[item.FieldName].ToString() != "" ? String.Format("{0:MMMM dd yyyy}", form[item.FieldName].ToString()) : "Null"));
                                    }
                                    else
                                    {
                                        cmd.Parameters.AddWithValue(item.SqlParameter, (form[item.FieldName].ToString() != "" ? form[item.FieldName].ToString() : "Null"));
                                    }
                                }
                            }
                        }
                    }


                    cmd.CommandTimeout = 200;
                    SqlDataAdapter sqlDataAapter = new SqlDataAdapter(cmd);
                    sqlDataAapter.SelectCommand.CommandType = CommandType.StoredProcedure;
                    dsRep.EnforceConstraints = false;
                    sqlDataAapter.Fill(ReportData);


                    if (ReportData.Rows.Count > 0)
                    {
                        if (ReportData.Columns.Contains("SubReportProcList"))
                        {
                            SubReportProcList.Add(ReportData.Rows[0]["SubReportProcList"].ToString());
                        }


                        DataTable SubRepData = new DataTable();
                        String    SubReportProc;

                        if (SubReportProcList != null)
                        {
                            if (SubReportProcList.Count > 0)
                            {
                                SubRepData = ReportData.Copy();

                                SqlConnection Con = new SqlConnection(connectionString);

                                while (SubRepData.Rows.Count > 0 && SubRepData.Columns.Contains("SubReportProcList"))
                                {
                                    SubReportProc = SubRepData.Rows[0]["SubReportProcList"].ToString();

                                    if (SubReportProc != "")
                                    {
                                        String         query          = db.strSchemaName + "." + SubReportProc;
                                        SqlDataAdapter sqlDataAapter1 = new SqlDataAdapter(query.ToString(), Con);
                                        sqlDataAapter1.SelectCommand.CommandTimeout = 200;
                                        dsRep.EnforceConstraints = false;
                                        SubRepData.Reset();

                                        sqlDataAapter1.Fill(SubRepData);

                                        DataTable SubDataTable = new DataTable();
                                        SubDataTable = SubRepData.Copy();

                                        string SubRepName = "";
                                        if (SubDataTable.Rows.Count > 0)
                                        {
                                            SubReportDataList.Add(SubDataTable);
                                            SubRepName = (string)SubDataTable.Rows[0]["ReportName"];
                                            SubReportNameList.Add(SubRepName);
                                        }
                                        SubDataTable.Dispose();
                                    }
                                    else
                                    {
                                        //SubRepData = null;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }

                if (ReportData.Rows.Count > 0)
                {
                    var Paralist = new List <string>();

                    foreach (var item in lines)
                    {
                        if (item.SqlParameter == "@LoginSite" || item.SqlParameter == "@LoginDivision")
                        {
                        }
                        else
                        {
                            if (item.SqlParameter != "" && item.SqlParameter != null && form[item.FieldName].ToString() != "")
                            {
                                if (item.DataType == "Date")
                                {
                                    if (!string.IsNullOrEmpty(form[item.FieldName].ToString()))
                                    {
                                        Paralist.Add(item.DisplayName + " : " + form[item.FieldName].ToString()); ReportFilters.Add(item.DisplayName, form[item.FieldName].ToString());
                                    }
                                }
                                else if (item.DataType == "Single Select")
                                {
                                    if (!string.IsNullOrEmpty(item.ListItem))
                                    {
                                        Paralist.Add(item.DisplayName + " : " + form[item.FieldName].ToString());
                                    }
                                    else if (!string.IsNullOrEmpty(form[item.FieldName].ToString()))
                                    {
                                        Paralist.Add(item.DisplayName + " : " + form[item.FieldName + "Names"].ToString()); ReportFilters.Add(item.DisplayName, form[item.FieldName + "Names"].ToString());
                                    }
                                }
                                //else if (item.DataType == "Constant Value")
                                //{

                                //    //if (!string.IsNullOrEmpty(form[item.FieldName].ToString())) { Paralist.Add(item.DisplayName + " : " + form[item.FieldName + "Names"].ToString()); }
                                //}

                                else if (item.DataType == "Multi Select")
                                {
                                    if (form[item.FieldName].ToString() != "")
                                    {
                                        Paralist.Add(item.DisplayName + " : " + form[item.FieldName + "Names"].ToString()); ReportFilters.Add(item.DisplayName, form[item.FieldName + "Names"].ToString());
                                    }
                                }
                                else
                                {
                                    if (form[item.FieldName].ToString() != "")
                                    {
                                        Paralist.Add(item.DisplayName + " : " + form[item.FieldName].ToString()); ReportFilters.Add(item.DisplayName, form[item.FieldName].ToString());
                                    }
                                }
                            }
                        }
                    }

                    string mimtype;
                    ReportGenerateService c = new ReportGenerateService();
                    byte[] BAR;
                    //BAR = c.ReportGenerate(ReportData, out mimtype, ReportFileType, Paralist, SubReportDataList);
                    BAR = c.ReportGenerate(ReportData, out mimtype, ReportFileType, Paralist, SubReportDataList, null, SubReportNameList, User.Identity.Name);

                    XElement s    = new XElement(CustomStringOp.CleanCode(header.ReportName));
                    XElement Name = new XElement("Filters");
                    foreach (var Rec in ReportFilters)
                    {
                        Name.Add(new XElement(CustomStringOp.CleanCode(Rec.Key), Rec.Value));
                    }
                    s.Add(Name);

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId       = new DocumentTypeService(_unitOfWork).Find(TransactionDoctypeConstants.Report).DocumentTypeId,
                        DocId           = header.ReportHeaderId,
                        ActivityType    = (int)ActivityTypeContants.Report,
                        xEModifications = s,
                    }));

                    if (BAR.Length == 1)
                    {
                        ViewBag.Message = "Report Name is not define.";
                        return(View("Close"));
                    }
                    else if (BAR.Length == 2)
                    {
                        ViewBag.Message = "Report Title is not define.";
                        return(View("Close"));
                    }
                    else
                    {
                        //if (mimtype != "application/pdf")
                        if (mimtype == "application/vnd.ms-excel")
                        {
                            return(File(BAR, mimtype, header.ReportName + ".xls"));
                        }
                        else
                        {
                            return(File(BAR, mimtype));
                        }
                    }
                }

                else
                {
                    ViewBag.Message = "No Record to Print.";
                    return(View("Close"));
                }
            }

            else
            {
                List <ReportParameter> Params = new List <ReportParameter>();
                string ReportName             = "";

                ApplicationDbContext Db = new ApplicationDbContext();

                foreach (var item in lines)
                {
                    if (item.SqlParameter != "" && item.SqlParameter != null)
                    {
                        if (item.SqlParameter == "@LoginSite" || item.SqlParameter == "@LoginDivision")
                        {
                            if (item.SqlParameter == "@LoginSite")
                            {
                                ReportParameter Param = new ReportParameter();
                                Param.Name = CustomStringOp.CleanCode(item.SqlParameter);
                                Param.Values.Add(Convert.ToString(System.Web.HttpContext.Current.Session[SessionNameConstants.LoginSiteId]));

                                Params.Add(Param);
                            }
                            else if (item.SqlParameter == "@LoginDivision")
                            {
                                ReportParameter Param = new ReportParameter();
                                Param.Name = CustomStringOp.CleanCode(item.SqlParameter);
                                Param.Values.Add(Convert.ToString(System.Web.HttpContext.Current.Session[SessionNameConstants.LoginDivisionId]));

                                Params.Add(Param);
                            }
                        }
                        else if (item.FieldName == "Site" && form[item.FieldName].ToString() == "")
                        {
                            ReportParameter Param = new ReportParameter();
                            Param.Name = CustomStringOp.CleanCode(item.SqlParameter);
                            Param.Values.Add(Convert.ToString(System.Web.HttpContext.Current.Session[SessionNameConstants.LoginSiteId]));
                            Params.Add(Param);
                        }

                        else if (item.FieldName == "Division" && form[item.FieldName].ToString() == "")
                        {
                            ReportParameter Param = new ReportParameter();
                            Param.Name = CustomStringOp.CleanCode(item.SqlParameter);
                            Param.Values.Add(Convert.ToString(System.Web.HttpContext.Current.Session[SessionNameConstants.LoginDivisionId]));

                            Params.Add(Param);
                        }

                        else
                        {
                            if (form[item.FieldName].ToString() != "")
                            {
                                if (item.DataType == "Date")
                                {
                                    ReportParameter Param = new ReportParameter();
                                    Param.Name = CustomStringOp.CleanCode(item.SqlParameter);
                                    Param.Values.Add((form[item.FieldName].ToString() != "" ? String.Format("{0:MMMM dd yyyy}", form[item.FieldName].ToString()) : "Null"));

                                    Params.Add(Param);
                                }
                                else
                                {
                                    ReportParameter Param = new ReportParameter();
                                    Param.Name = CustomStringOp.CleanCode(item.SqlParameter);
                                    Param.Values.Add((form[item.FieldName].ToString() != "" ? form[item.FieldName].ToString() : "Null"));

                                    Params.Add(Param);
                                }
                            }
                        }
                    }
                }



                int i = 0;
                foreach (var item in lines)
                {
                    if (item.SqlParameter == "@LoginSite" || item.SqlParameter == "@LoginDivision")
                    {
                    }
                    else
                    {
                        if (item.SqlParameter != "" && item.SqlParameter != null && form[item.FieldName].ToString() != "")
                        {
                            if (item.DataType == "Date")
                            {
                                if (!string.IsNullOrEmpty(form[item.FieldName].ToString()))
                                {
                                    ReportParameter Param = new ReportParameter();
                                    Param.Name = "FilterStr" + ++i;
                                    Param.Values.Add(item.DisplayName + " : " + form[item.FieldName].ToString());
                                    Params.Add(Param);

                                    ReportFilters.Add(item.DisplayName, form[item.FieldName].ToString());
                                }
                            }
                            else if (item.DataType == "Single Select")
                            {
                                if (!string.IsNullOrEmpty(item.ListItem) && !string.IsNullOrEmpty(form[item.FieldName]))
                                {
                                    ReportParameter Param = new ReportParameter();
                                    Param.Name = "FilterStr" + ++i;
                                    Param.Values.Add(item.DisplayName + " : " + form[item.FieldName].ToString());
                                    Params.Add(Param);
                                }
                                else if (!string.IsNullOrEmpty(form[item.FieldName].ToString()) && !string.IsNullOrEmpty(form[item.FieldName + "Names"]))
                                {
                                    ReportParameter Param = new ReportParameter();
                                    Param.Name = "FilterStr" + ++i;
                                    Param.Values.Add(item.DisplayName + " : " + form[item.FieldName + "Names"].ToString());
                                    Params.Add(Param);

                                    ReportFilters.Add(item.DisplayName, form[item.FieldName + "Names"].ToString());
                                }
                            }

                            else if (item.DataType == "Multi Select")
                            {
                                if (form[item.FieldName].ToString() != "" && !string.IsNullOrEmpty(form[item.FieldName + "Names"]))
                                {
                                    ReportParameter Param = new ReportParameter();
                                    Param.Name = "FilterStr" + ++i;
                                    Param.Values.Add(item.DisplayName + " : " + form[item.FieldName + "Names"].ToString());
                                    Params.Add(Param);

                                    ReportFilters.Add(item.DisplayName, form[item.FieldName + "Names"].ToString());
                                }
                            }
                            else
                            {
                                if (form[item.FieldName].ToString() != "" && !string.IsNullOrEmpty(form[item.FieldName]))
                                {
                                    ReportParameter Param = new ReportParameter();
                                    Param.Name = "FilterStr" + ++i;
                                    Param.Values.Add(item.DisplayName + " : " + form[item.FieldName].ToString());
                                    Params.Add(Param);

                                    ReportFilters.Add(item.DisplayName, form[item.FieldName].ToString());
                                }
                            }
                        }
                    }
                }

                var uid = Guid.NewGuid();
                using (ApplicationDbContext context = new ApplicationDbContext())
                {
                    foreach (var item in Params)
                    {
                        ReportUIDValues rid = new ReportUIDValues();
                        rid.UID   = uid;
                        rid.Type  = item.Name;
                        rid.Value = item.Values[0];

                        rid.ObjectState = Model.ObjectState.Added;
                        context.ReportUIDValues.Add(rid);
                    }
                    context.SaveChanges();
                }



                ReportName = Db.Database.SqlQuery <string>(header.ReportSQL.Replace("REPORTUID", uid.ToString())).FirstOrDefault();

                using (ApplicationDbContext context = new ApplicationDbContext())
                {
                    var Items = context.ReportUIDValues.Where(m => m.UID == uid).ToList();

                    foreach (var item in Items)
                    {
                        item.ObjectState = Model.ObjectState.Deleted;
                        context.ReportUIDValues.Remove(item);
                    }
                    context.SaveChanges();
                }

                ReportParameter UserName = new ReportParameter();
                UserName.Name = "PrintedBy";
                UserName.Values.Add(User.Identity.Name);
                Params.Add(UserName);

                ReportParameter ConString = new ReportParameter();
                ConString.Name = "DatabaseConnectionString";
                ConString.Values.Add(connectionString);
                //Data Source=192.168.2.17;Initial Catalog=RUG;Integrated Security=false; User Id=sa; pwd=
                Params.Add(ConString);

                string mimtype;
                ReportGenerateService c = new ReportGenerateService();
                byte[] BAR;

                BAR = c.ReportGenerateCustom(out mimtype, ReportFileType, User.Identity.Name, Params, ReportName);

                XElement s    = new XElement(CustomStringOp.CleanCode(header.ReportName));
                XElement Name = new XElement("Filters");
                foreach (var Rec in ReportFilters)
                {
                    Name.Add(new XElement(CustomStringOp.CleanCode(Rec.Key), Rec.Value));
                }
                s.Add(Name);


                LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                {
                    DocTypeId       = new DocumentTypeService(_unitOfWork).Find(TransactionDoctypeConstants.Report).DocumentTypeId,
                    DocId           = header.ReportHeaderId,
                    ActivityType    = (int)ActivityTypeContants.Report,
                    xEModifications = s,
                }));

                if (BAR.Length == 1)
                {
                    ViewBag.Message = "Report Name is not define.";
                    return(View("Close"));
                }
                else if (BAR.Length == 2)
                {
                    ViewBag.Message = "Report Title is not define.";
                    return(View("Close"));
                }
                else
                {
                    if (mimtype == "application/vnd.ms-excel")
                    {
                        return(File(BAR, mimtype, header.ReportName + ".xls"));
                    }
                    else
                    {
                        return(File(BAR, mimtype));
                    }
                }
            }
        }
Beispiel #13
0
        public ActionResult Post(ProductDesign vm)
        {
            ProductDesign pt = vm;

            if (ModelState.IsValid)
            {
                if (vm.ProductDesignId <= 0)
                {
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;
                    _ProductDesignService.Create(pt);

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        ViewBag.id   = pt.ProductTypeId;
                        ViewBag.Name = new ProductTypeService(_unitOfWork).Find(pt.ProductTypeId ?? 0).ProductTypeName;
                        return(View("Create", vm));
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId    = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProductDesign).DocumentTypeId,
                        DocId        = pt.ProductDesignId,
                        ActivityType = (int)ActivityTypeContants.Added,
                    }));

                    ViewBag.id   = pt.ProductTypeId;
                    ViewBag.Name = new ProductTypeService(_unitOfWork).Find(pt.ProductTypeId ?? 0).ProductTypeName;
                    return(RedirectToAction("Create", new { id = pt.ProductTypeId }).Success("Data saved successfully"));
                }

                else
                {
                    ProductDesign temp = _ProductDesignService.Find(pt.ProductDesignId);

                    temp.ProductDesignName = pt.ProductDesignName;
                    temp.IsActive          = pt.IsActive;
                    temp.ModifiedDate      = DateTime.Now;
                    temp.ModifiedBy        = User.Identity.Name;
                    temp.ObjectState       = Model.ObjectState.Modified;
                    _ProductDesignService.Update(temp);

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        ViewBag.Name = new ProductTypeService(_unitOfWork).Find(pt.ProductTypeId ?? 0).ProductTypeName;
                        ViewBag.id   = pt.ProductTypeId;
                        return(View("Create", pt));
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId    = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProductDesign).DocumentTypeId,
                        DocId        = temp.ProductDesignId,
                        ActivityType = (int)ActivityTypeContants.Modified,
                    }));


                    ViewBag.Name = new ProductTypeService(_unitOfWork).Find(pt.ProductTypeId ?? 0).ProductTypeName;
                    ViewBag.id   = pt.ProductTypeId;
                    return(RedirectToAction("Index", new { id = pt.ProductTypeId }).Success("Data saved successfully"));
                }
            }
            ViewBag.Name = new ProductTypeService(_unitOfWork).Find(vm.ProductTypeId ?? 0).ProductTypeName;
            ViewBag.id   = pt.ProductTypeId;
            return(View("Create", vm));
        }
        public ActionResult Post(CarpetSkuSettingsViewModel vm)
        {
            CarpetSkuSettings pt = AutoMapper.Mapper.Map<CarpetSkuSettingsViewModel, CarpetSkuSettings>(vm);


            if (ModelState.IsValid)
            {

                if (vm.CarpetSkuSettingsId <= 0)
                {
                    pt.CreatedDate = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy = User.Identity.Name;
                    pt.ModifiedBy = User.Identity.Name;
                    pt.ObjectState = Model.ObjectState.Added;
                    _CarpetSkuSettingsService.Create(pt);

                    try
                    {
                        _unitOfWork.Save();
                    }

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

                    int DocTypeId = new DocumentTypeService(_unitOfWork).Find(MasterDocTypeConstants.Carpet).DocumentTypeId;

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocId = pt.CarpetSkuSettingsId,
                        DocTypeId = DocTypeId,
                        ActivityType = (int)ActivityTypeContants.SettingsAdded,
                    }));



                    return RedirectToAction("Index", "CarpetMaster", new { id = 0 }).Success("Data saved successfully");
                }
                else
                {
                    List<LogTypeViewModel> LogList = new List<LogTypeViewModel>();

                    CarpetSkuSettings temp = _CarpetSkuSettingsService.Find(pt.CarpetSkuSettingsId);

                    CarpetSkuSettings ExRec = Mapper.Map<CarpetSkuSettings>(temp);

                    temp.isVisibleProductDesign = vm.isVisibleProductDesign;
                    temp.isVisibleProductStyle = vm.isVisibleProductStyle;
                    temp.isVisibleProductManufacturer = vm.isVisibleProductManufacturer;
                    temp.isVisibleProductDesignPattern = vm.isVisibleProductDesignPattern;
                    temp.isVisibleContent = vm.isVisibleContent;
                    temp.isVisibleOriginCountry = vm.isVisibleOriginCountry;
                    temp.isVisibleInvoiceGroup = vm.isVisibleInvoiceGroup;
                    temp.isVisibleDrawbackTarrif = vm.isVisibleDrawbackTarrif;
                    temp.isVisibleStandardCost = vm.isVisibleStandardCost;
                    temp.isVisibleStandardWeight = vm.isVisibleStandardWeight;
                    temp.isVisibleGrossWeight = vm.isVisibleGrossWeight;
                    temp.isVisibleSupplierDetail = vm.isVisibleSupplierDetail;
                    temp.isVisibleSample = vm.isVisibleSample;
                    temp.isVisibleCounterNo = vm.isVisibleCounterNo;
                    temp.isVisibleTags = vm.isVisibleTags;
                    temp.isVisibleDivision = vm.isVisibleDivision;
                    temp.isVisibleColour = vm.isVisibleColour;
                    temp.isVisibleProductionRemark = vm.isVisibleProductionRemark;
                    temp.ProductDesignId = pt.ProductDesignId;
                    temp.OriginCountryId = pt.OriginCountryId;
                    temp.UnitConversions = pt.UnitConversions;
                    temp.PerimeterSizeTypeId = pt.PerimeterSizeTypeId;
                    temp.isVisibleCBM = pt.isVisibleCBM;
                    temp.isVisibleMapScale = pt.isVisibleMapScale;
                    temp.isVisibleTraceType = pt.isVisibleTraceType;
                    temp.isVisibleMapType = pt.isVisibleMapType;
                    temp.isVisibleStencilSize = pt.isVisibleStencilSize;
                    temp.isVisibleSalesTaxProductCode = pt.isVisibleSalesTaxProductCode;
                    temp.SalesTaxProductCodeCaption = pt.SalesTaxProductCodeCaption;
                    temp.ModifiedDate = DateTime.Now;
                    temp.ModifiedBy = User.Identity.Name;
                    temp.ObjectState = Model.ObjectState.Modified;
                    _CarpetSkuSettingsService.Update(temp);

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

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

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        PrepareViewBag(vm);
                        return View("Create", pt);
                    }

                    int DocTypeId = new DocumentTypeService(_unitOfWork).Find(MasterDocTypeConstants.Carpet).DocumentTypeId;

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocId = temp.CarpetSkuSettingsId,
                        ActivityType = (int)ActivityTypeContants.SettingsModified,
                        DocTypeId = DocTypeId,
                        xEModifications = Modifications,
                    }));

                    return RedirectToAction("Index", "CarpetMaster", new { id = 0 }).Success("Data saved successfully");

                }

            }
            PrepareViewBag(vm);
            return View("Create", vm);
        }
        public ActionResult PostSummary(JobInvoiceSummaryDetailViewModel vm)
        {
            //TempData["CSEXC"] = "Customize Test Exception";


            String ErrorMsg = "";

            foreach (var item in vm.JobInvoiceSummaryViewModel)
            {
                if (item.AdvanceAdjusted > item.InvoiceAmount + item.TanaAmount)
                {
                    string ProductUidName = "";
                    if (item.ProductUidId != null)
                    {
                        ProductUidName = new ProductUidService(_unitOfWork).Find((int)item.ProductUidId).ProductUidName;
                    }

                    ErrorMsg = "Total adjusted advance for barcode " + ProductUidName + " is exceeding invoice amount.";
                }
            }


            var AdvanceData = (from H in vm.JobInvoiceSummaryViewModel
                               group new { H } by new { H.CostCenterId } into Result
                               select new
            {
                CostCenterId = Result.Key.CostCenterId,
                TotalAdvanceAmount = Result.Max(m => m.H.AdvanceAmount),
                TotalAdvanceAdjusted = Result.Sum(m => m.H.AdvanceAdjusted)
            }).ToList();

            foreach (var item in AdvanceData)
            {
                if (item.TotalAdvanceAdjusted > item.TotalAdvanceAmount)
                {
                    string CostCenterName = new CostCenterService(_unitOfWork).Find(item.CostCenterId).CostCenterName;
                    ErrorMsg = "Total adjusted advance for purja " + CostCenterName + " is exceeding total advance amount.";
                }
            }



            var TdsData = (from H in vm.JobInvoiceSummaryViewModel
                           group new { H } by new { H.PersonId } into Result
                           select new
            {
                PersonId = Result.Key.PersonId,
                TotalTdsAmount = Result.Max(m => m.H.TdsAmount),
                TotalTdsAdjusted = Result.Sum(m => m.H.TdsAdjusted)
            }).ToList();

            foreach (var item in TdsData)
            {
                if (item.TotalTdsAdjusted > item.TotalTdsAmount)
                {
                    string PersonName = new PersonService(_unitOfWork).Find(item.PersonId).Name;
                    ErrorMsg = "Total adjusted tds for person " + PersonName + " is exceeding total tds amount.";
                }
            }

            if (ErrorMsg != "")
            {
                TempData["CSEXC"] = ErrorMsg;
                return(View("Summary", vm));
            }



            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();
            bool Modified = false;
            int  Id       = vm.JobInvoiceHeaderId;

            var Header = _JobInvoiceHeaderService.Find(Id);


            int LedgerHeaderId                   = 0;
            int LedgerLineId                     = 0;
            int LedgerId                         = 0;
            int LedgerAdjId                      = 0;
            int TanaPaymentDueCnt                = 0;
            int TdsCollectionCnt                 = 0;
            int SavedTanaLedgerHeaderId          = 0;
            int SavedTdsCollectionLedgerHeaderId = 0;
            int TanaPaymentDueAcId               = new LedgerAccountService(_unitOfWork).Find(TanaPaymentDueAccount).LedgerAccountId;


            DeleteLedgerTransaction(Header.JobInvoiceHeaderId);


            DataTable AdvanceAdjustedDataTable = new DataTable();

            AdvanceAdjustedDataTable.Columns.Add("Id");
            AdvanceAdjustedDataTable.Columns.Add("Qty");

            foreach (var item in vm.JobInvoiceSummaryViewModel)
            {
                if (item.TanaAmount > 0)
                {
                    #region "Tana Payment Due"
                    if (TanaPaymentDueCnt == 0)
                    {
                        LedgerHeader TanaLedgerHeader = new LedgerHeader();
                        TanaLedgerHeader.LedgerHeaderId  = LedgerHeaderId;
                        TanaLedgerHeader.DocTypeId       = new DocumentTypeService(_unitOfWork).Find(TanaPaymentDueDocType).DocumentTypeId;
                        TanaLedgerHeader.DocDate         = DateTime.Now.Date;
                        TanaLedgerHeader.DivisionId      = Header.DivisionId;
                        TanaLedgerHeader.SiteId          = Header.SiteId;
                        TanaLedgerHeader.DocNo           = new DocumentTypeService(_unitOfWork).FGetNewDocNo("DocNo", ConfigurationManager.AppSettings["DataBaseSchema"] + ".LedgerHeaders", TanaLedgerHeader.DocTypeId, TanaLedgerHeader.DocDate, TanaLedgerHeader.DivisionId, TanaLedgerHeader.SiteId);
                        TanaLedgerHeader.LedgerAccountId = TanaPaymentDueAcId;
                        TanaLedgerHeader.Narration       = "Tana Payment Due";
                        TanaLedgerHeader.Status          = (int)StatusConstants.Submitted;
                        TanaLedgerHeader.ProcessId       = new ProcessService(_unitOfWork).Find(ProcessConstants.Weaving).ProcessId;
                        TanaLedgerHeader.CostCenterId    = null;
                        TanaLedgerHeader.AdjustmentType  = "Due";
                        TanaLedgerHeader.PaymentFor      = DateTime.Now.Date;

                        TanaLedgerHeader.ReferenceDocId     = Header.JobInvoiceHeaderId;
                        TanaLedgerHeader.ReferenceDocTypeId = Header.DocTypeId;

                        TanaLedgerHeader.CreatedDate  = DateTime.Now;
                        TanaLedgerHeader.ModifiedDate = DateTime.Now;
                        TanaLedgerHeader.CreatedBy    = User.Identity.Name;
                        TanaLedgerHeader.ModifiedBy   = User.Identity.Name;
                        TanaLedgerHeader.ObjectState  = Model.ObjectState.Added;
                        new LedgerHeaderService(_unitOfWork).Create(TanaLedgerHeader);
                        LedgerHeaderId          = LedgerHeaderId - 1;
                        TanaPaymentDueCnt       = TanaPaymentDueCnt + 1;
                        SavedTanaLedgerHeaderId = TanaLedgerHeader.LedgerHeaderId;
                    }


                    LedgerLine TanaLedgerLine = new LedgerLine();
                    TanaLedgerLine.LedgerLineId       = LedgerLineId;
                    TanaLedgerLine.LedgerHeaderId     = SavedTanaLedgerHeaderId;
                    TanaLedgerLine.LedgerAccountId    = new LedgerAccountService(_unitOfWork).GetLedgerAccountByPersondId(item.PersonId).LedgerAccountId;
                    TanaLedgerLine.CostCenterId       = item.CostCenterId;
                    TanaLedgerLine.ProductUidId       = item.ProductUidId;
                    TanaLedgerLine.Amount             = item.TanaAmount;
                    TanaLedgerLine.ReferenceDocLineId = item.JobInvoiceLineId;
                    TanaLedgerLine.ReferenceDocTypeId = Header.DocTypeId;
                    TanaLedgerLine.CreatedDate        = DateTime.Now;
                    TanaLedgerLine.ModifiedDate       = DateTime.Now;
                    TanaLedgerLine.CreatedBy          = User.Identity.Name;
                    TanaLedgerLine.ModifiedBy         = User.Identity.Name;
                    TanaLedgerLine.ObjectState        = Model.ObjectState.Added;
                    new LedgerLineService(_unitOfWork).Create(TanaLedgerLine);
                    LedgerLineId = LedgerLineId - 1;


                    Ledger TanaLedgerDr = new Ledger();
                    TanaLedgerDr.LedgerId              = LedgerId;
                    TanaLedgerDr.LedgerHeaderId        = SavedTanaLedgerHeaderId;
                    TanaLedgerDr.LedgerAccountId       = TanaPaymentDueAcId;
                    TanaLedgerDr.ContraLedgerAccountId = TanaLedgerLine.LedgerAccountId;
                    TanaLedgerDr.CostCenterId          = null;
                    TanaLedgerDr.ProductUidId          = item.ProductUidId;
                    TanaLedgerDr.AmtDr        = TanaLedgerLine.Amount;
                    TanaLedgerDr.AmtCr        = 0;
                    TanaLedgerDr.Narration    = "Tana Payment Due";
                    TanaLedgerDr.LedgerLineId = TanaLedgerLine.LedgerLineId;
                    TanaLedgerDr.ObjectState  = Model.ObjectState.Added;
                    new LedgerService(_unitOfWork).Create(TanaLedgerDr);
                    LedgerId = LedgerId - 1;


                    Ledger TanaLedgerCr = new Ledger();
                    TanaLedgerDr.LedgerId              = LedgerId;
                    TanaLedgerCr.LedgerHeaderId        = SavedTanaLedgerHeaderId;
                    TanaLedgerCr.LedgerAccountId       = TanaLedgerLine.LedgerAccountId;
                    TanaLedgerCr.ContraLedgerAccountId = TanaPaymentDueAcId;
                    TanaLedgerCr.CostCenterId          = item.CostCenterId;
                    TanaLedgerDr.ProductUidId          = item.ProductUidId;
                    TanaLedgerCr.AmtDr        = 0;
                    TanaLedgerCr.AmtCr        = TanaLedgerLine.Amount;
                    TanaLedgerCr.Narration    = null;
                    TanaLedgerCr.LedgerLineId = TanaLedgerLine.LedgerLineId;
                    TanaLedgerCr.ObjectState  = Model.ObjectState.Added;
                    new LedgerService(_unitOfWork).Create(TanaLedgerCr);
                    LedgerId = LedgerId - 1;

                    #endregion
                }

                if (item.TdsAdjusted > 0)
                {
                    #region "Tds Collection"


                    var TdsRate = (from H in db.BusinessEntity
                                   join Tr in db.TdsRate on new { X1 = H.TdsCategoryId ?? 0, X2 = H.TdsGroupId ?? 0 } equals new { X1 = Tr.TdsCategoryId, X2 = Tr.TdsGroupId } into TdsRateTable
                                   from TdsRateTab in TdsRateTable.DefaultIfEmpty()
                                   where H.PersonID == item.PersonId
                                   select TdsRateTab).FirstOrDefault();


                    if (TdsCollectionCnt == 0)
                    {
                        LedgerHeader TdsLedgerHeader = new LedgerHeader();
                        TdsLedgerHeader.LedgerHeaderId  = LedgerHeaderId;
                        TdsLedgerHeader.DocTypeId       = new DocumentTypeService(_unitOfWork).Find(TdsCollectionDocType).DocumentTypeId;
                        TdsLedgerHeader.DocDate         = DateTime.Now.Date;
                        TdsLedgerHeader.DivisionId      = Header.DivisionId;
                        TdsLedgerHeader.SiteId          = Header.SiteId;
                        TdsLedgerHeader.DocNo           = new DocumentTypeService(_unitOfWork).FGetNewDocNo("DocNo", ConfigurationManager.AppSettings["DataBaseSchema"] + ".LedgerHeaders", TdsLedgerHeader.DocTypeId, TdsLedgerHeader.DocDate, TdsLedgerHeader.DivisionId, TdsLedgerHeader.SiteId);
                        TdsLedgerHeader.LedgerAccountId = TdsRate.LedgerAccountId;
                        TdsLedgerHeader.Narration       = "Tds Adjustment";
                        TdsLedgerHeader.Status          = (int)StatusConstants.Submitted;
                        TdsLedgerHeader.ProcessId       = new ProcessService(_unitOfWork).Find(ProcessConstants.Weaving).ProcessId;
                        TdsLedgerHeader.CostCenterId    = null;
                        TdsLedgerHeader.AdjustmentType  = "Due";
                        TdsLedgerHeader.PaymentFor      = DateTime.Now.Date;

                        TdsLedgerHeader.ReferenceDocId     = Header.JobInvoiceHeaderId;
                        TdsLedgerHeader.ReferenceDocTypeId = Header.DocTypeId;

                        TdsLedgerHeader.CreatedDate  = DateTime.Now;
                        TdsLedgerHeader.ModifiedDate = DateTime.Now;
                        TdsLedgerHeader.CreatedBy    = User.Identity.Name;
                        TdsLedgerHeader.ModifiedBy   = User.Identity.Name;
                        TdsLedgerHeader.ObjectState  = Model.ObjectState.Added;
                        new LedgerHeaderService(_unitOfWork).Create(TdsLedgerHeader);
                        LedgerHeaderId   = LedgerHeaderId - 1;
                        TdsCollectionCnt = TdsCollectionCnt + 1;
                        SavedTdsCollectionLedgerHeaderId = TdsLedgerHeader.LedgerHeaderId;
                    }


                    LedgerLine TdsLedgerLine = new LedgerLine();
                    TdsLedgerLine.LedgerLineId    = LedgerLineId;
                    TdsLedgerLine.LedgerHeaderId  = SavedTdsCollectionLedgerHeaderId;
                    TdsLedgerLine.LedgerAccountId = new LedgerAccountService(_unitOfWork).GetLedgerAccountByPersondId(item.PersonId).LedgerAccountId;
                    if (item.CostCenterId != 0)
                    {
                        TdsLedgerLine.CostCenterId = item.CostCenterId;
                    }
                    TdsLedgerLine.ProductUidId = item.ProductUidId;
                    TdsLedgerLine.BaseValue    = item.TdsAdjusted * 100 / TdsRate.Percentage;
                    TdsLedgerLine.Amount       = item.TdsAdjusted;
                    TdsLedgerLine.CreatedDate  = DateTime.Now;
                    TdsLedgerLine.ModifiedDate = DateTime.Now;
                    TdsLedgerLine.CreatedBy    = User.Identity.Name;
                    TdsLedgerLine.ModifiedBy   = User.Identity.Name;
                    TdsLedgerLine.ObjectState  = Model.ObjectState.Added;
                    new LedgerLineService(_unitOfWork).Create(TdsLedgerLine);
                    LedgerLineId = LedgerLineId - 1;


                    Ledger TdsLedgerDr = new Ledger();
                    TdsLedgerDr.LedgerId              = LedgerId;
                    TdsLedgerDr.LedgerHeaderId        = SavedTdsCollectionLedgerHeaderId;
                    TdsLedgerDr.LedgerAccountId       = TdsLedgerLine.LedgerAccountId;
                    TdsLedgerDr.ContraLedgerAccountId = TdsRate.LedgerAccountId;
                    if (item.CostCenterId != 0)
                    {
                        TdsLedgerDr.CostCenterId = item.CostCenterId;
                    }
                    TdsLedgerDr.ProductUidId = item.ProductUidId;
                    TdsLedgerDr.AmtDr        = TdsLedgerLine.Amount;
                    TdsLedgerDr.AmtCr        = 0;
                    TdsLedgerDr.Narration    = "Tds Adjusted.";
                    TdsLedgerDr.LedgerLineId = TdsLedgerLine.LedgerLineId;
                    TdsLedgerDr.ObjectState  = Model.ObjectState.Added;
                    new LedgerService(_unitOfWork).Create(TdsLedgerDr);
                    LedgerId = LedgerId - 1;


                    Ledger TdsLedgerCr = new Ledger();
                    TdsLedgerCr.LedgerId              = LedgerId;
                    TdsLedgerCr.LedgerHeaderId        = SavedTdsCollectionLedgerHeaderId;
                    TdsLedgerCr.LedgerAccountId       = (int)TdsRate.LedgerAccountId;
                    TdsLedgerCr.ContraLedgerAccountId = TdsLedgerLine.LedgerAccountId;
                    TdsLedgerCr.CostCenterId          = null;
                    TdsLedgerCr.ProductUidId          = item.ProductUidId;
                    TdsLedgerCr.AmtDr        = 0;
                    TdsLedgerCr.AmtCr        = TdsLedgerLine.Amount;
                    TdsLedgerCr.Narration    = null;
                    TdsLedgerCr.LedgerLineId = TdsLedgerLine.LedgerLineId;
                    TdsLedgerCr.ObjectState  = Model.ObjectState.Added;
                    new LedgerService(_unitOfWork).Create(TdsLedgerCr);
                    LedgerId = LedgerId - 1;


                    var TempLedger = (from L in db.Ledger
                                      where L.ReferenceDocLineId == item.JobInvoiceLineId && L.ReferenceDocTypeId == Header.DocTypeId
                                      select new
                    {
                        LedgerCrId = L.LedgerId
                    }).FirstOrDefault();

                    LedgerAdj LedgerAdj = new LedgerAdj();
                    LedgerAdj.LedgerAdjId  = LedgerAdjId;
                    LedgerAdj.DrLedgerId   = TdsLedgerDr.LedgerId;
                    LedgerAdj.CrLedgerId   = TempLedger == null ? 0 : TempLedger.LedgerCrId;
                    LedgerAdj.SiteId       = Header.SiteId;
                    LedgerAdj.Adj_Type     = "Tds Adjustment";
                    LedgerAdj.Amount       = TdsLedgerDr.AmtDr;
                    LedgerAdj.CreatedBy    = Header.CreatedBy;
                    LedgerAdj.CreatedDate  = DateTime.Now;
                    LedgerAdj.ModifiedBy   = Header.ModifiedBy;
                    LedgerAdj.ModifiedDate = DateTime.Now;
                    LedgerAdj.ObjectState  = Model.ObjectState.Added;
                    new LedgerAdjService(_unitOfWork).Create(LedgerAdj);
                    LedgerAdjId = LedgerAdjId - 1;

                    #endregion
                }

                if (item.AdvanceAdjusted > 0)
                {
                    var AdvanceAdjustedDataRow = AdvanceAdjustedDataTable.NewRow();
                    AdvanceAdjustedDataRow["Id"]  = item.JobInvoiceLineId;
                    AdvanceAdjustedDataRow["Qty"] = item.AdvanceAdjusted;
                    AdvanceAdjustedDataTable.Rows.Add(AdvanceAdjustedDataRow);
                }
            }


            if (AdvanceAdjustedDataTable.Rows.Count > 0)
            {
                string  ConnectionString = (string)System.Web.HttpContext.Current.Session["DefaultConnectionString"];
                DataSet ds = new DataSet();
                using (SqlConnection sqlConnection = new SqlConnection(ConnectionString))
                {
                    sqlConnection.Open();
                    using (SqlCommand cmd = new SqlCommand("" + ConfigurationManager.AppSettings["DataBaseSchema"] + ".spGetLedgerAdj"))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Connection  = sqlConnection;
                        cmd.Parameters.AddWithValue("@T", AdvanceAdjustedDataTable);
                        cmd.CommandTimeout = 1000;
                        using (SqlDataAdapter adp = new SqlDataAdapter(cmd))
                        {
                            adp.Fill(ds);
                        }
                    }
                }

                for (int j = 0; j <= ds.Tables[0].Rows.Count - 1; j++)
                {
                    LedgerAdj LedgerAdj = new LedgerAdj();
                    LedgerAdj.LedgerAdjId  = LedgerAdjId;
                    LedgerAdj.DrLedgerId   = (int)ds.Tables[0].Rows[j]["LedgerDrId"];
                    LedgerAdj.CrLedgerId   = (int)ds.Tables[0].Rows[j]["LedgerCrId"];
                    LedgerAdj.SiteId       = Header.SiteId;
                    LedgerAdj.Adj_Type     = "Advance Adjustment";
                    LedgerAdj.Amount       = (decimal)ds.Tables[0].Rows[j]["BalanceDr"];
                    LedgerAdj.CreatedBy    = Header.CreatedBy;
                    LedgerAdj.CreatedDate  = DateTime.Now;
                    LedgerAdj.ModifiedBy   = Header.ModifiedBy;
                    LedgerAdj.ModifiedDate = DateTime.Now;
                    LedgerAdj.ObjectState  = Model.ObjectState.Added;
                    new LedgerAdjService(_unitOfWork).Create(LedgerAdj);
                    LedgerAdjId = LedgerAdjId - 1;
                }
            }

            try
            {
                _unitOfWork.Save();
            }

            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                ModelState.AddModelError("", message);
                PrepareViewBag(vm.JobInvoiceHeaderId);
                return(Json(new { Success = false }));
            }

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

            string RetUrl = "";


            if (Header.Status == (int)StatusConstants.Drafted || Header.Status == (int)StatusConstants.Import)
            {
                RetUrl = System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobInvoiceHeader/Modify/" + Header.JobInvoiceHeaderId;
            }
            else if (Header.Status == (int)StatusConstants.Submitted || Header.Status == (int)StatusConstants.ModificationSubmitted || Header.Status == (int)StatusConstants.Modified)
            {
                RetUrl = System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobInvoiceHeader/ModifyAfter_Submit/" + Header.JobInvoiceHeaderId;
            }
            else if (Header.Status == (int)StatusConstants.Approved || Header.Status == (int)StatusConstants.Closed)
            {
                RetUrl = System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobInvoiceHeader/ModifyAfter_Approve/" + Header.JobInvoiceHeaderId;
            }
            else
            {
                RetUrl = System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobInvoiceHeader/Index/" + Header.DocTypeId;
            }

            return(Json(new { Success = true, Url = RetUrl }));
        }
        public ActionResult Post(PackingSettingsViewModel vm)
        {
            PackingSetting pt = AutoMapper.Mapper.Map <PackingSettingsViewModel, PackingSetting>(vm);


            if (ModelState.IsValid)
            {
                if (vm.PackingSettingId <= 0)
                {
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;
                    _PackingSettingService.Create(pt);

                    try
                    {
                        _unitOfWork.Save();
                    }

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

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId    = pt.DocTypeId,
                        DocId        = pt.PackingSettingId,
                        ActivityType = (int)ActivityTypeContants.SettingsAdded,
                    }));



                    return(RedirectToAction("Index", "PackingHeader", new { id = vm.DocTypeId }).Success("Data saved successfully"));
                }
                else
                {
                    List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                    PackingSetting temp = _PackingSettingService.Find(pt.PackingSettingId);

                    PackingSetting ExRec = Mapper.Map <PackingSetting>(temp);

                    temp.filterContraDocTypes      = pt.filterContraDocTypes;
                    temp.filterLedgerAccountGroups = pt.filterLedgerAccountGroups;
                    temp.filterLedgerAccounts      = pt.filterLedgerAccounts;
                    temp.filterProductGroups       = pt.filterProductGroups;
                    temp.filterProducts            = pt.filterProducts;
                    temp.filterProductTypes        = pt.filterProductTypes;
                    temp.filterContraDivisions     = pt.filterContraDivisions;
                    temp.filterContraSites         = pt.filterContraSites;
                    temp.filterProductDivision     = pt.filterProductDivision;
                    temp.filterPersonRoles         = pt.filterPersonRoles;
                    temp.ProcessId = pt.ProcessId;
                    temp.SqlProcDocumentPrint_AfterApprove = pt.SqlProcDocumentPrint_AfterApprove;
                    temp.SqlProcDocumentPrint_AfterSubmit  = pt.SqlProcDocumentPrint_AfterSubmit;
                    temp.isVisibleProductUID  = pt.isVisibleProductUID;
                    temp.isVisibleDimension1  = pt.isVisibleDimension1;
                    temp.isVisibleDimension2  = pt.isVisibleDimension2;
                    temp.isVisibleDimension3  = pt.isVisibleDimension3;
                    temp.isVisibleDimension4  = pt.isVisibleDimension4;
                    temp.isVisibleBaleCount   = pt.isVisibleBaleCount;
                    temp.SqlProcDocumentPrint = pt.SqlProcDocumentPrint;
                    temp.ImportMenuId         = pt.ImportMenuId;
                    temp.ModifiedDate         = DateTime.Now;
                    temp.ModifiedBy           = User.Identity.Name;
                    temp.ObjectState          = Model.ObjectState.Modified;
                    _PackingSettingService.Update(temp);

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

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

                    try
                    {
                        _unitOfWork.Save();
                    }

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

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId       = temp.DocTypeId,
                        DocId           = temp.PackingSettingId,
                        ActivityType    = (int)ActivityTypeContants.SettingsModified,
                        xEModifications = Modifications,
                    }));

                    return(RedirectToAction("Index", "PackingHeader", new { id = vm.DocTypeId }).Success("Data saved successfully"));
                }
            }
            PrepareViewBag();
            return(View("Create", vm));
        }
        public ActionResult DeleteConfirmed(ReasonViewModel vm)
        {
            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

            if (ModelState.IsValid)
            {
                var temp = _ProductCollectionService.Find(vm.id);

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

                int RefDocTypeId = new DocumentTypeService(_unitOfWork).Find(MasterDocTypeConstants.ProductCollection).DocumentTypeId;

                var ProcSeqHeader = (from p in db.ProcessSequenceHeader
                                     where p.ReferenceDocId == temp.ProductCollectionId && p.ReferenceDocTypeId == RefDocTypeId
                                     select p).FirstOrDefault();

                if (ProcSeqHeader != null)
                {
                    var ProcSeqLines = (from p in db.ProcessSequenceLine
                                        where p.ProcessSequenceHeaderId == p.ProcessSequenceHeaderId
                                        select p).ToList();

                    foreach (var item in ProcSeqLines)
                    {
                        new ProcessSequenceLineService(_unitOfWork).Delete(item);
                    }

                    new ProcessSequenceHeaderService(_unitOfWork).Delete(ProcSeqHeader);
                }

                _ProductCollectionService.Delete(vm.id);

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

                try
                {
                    _unitOfWork.Save();
                }

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

                LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                {
                    DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProductCollection).DocumentTypeId,
                    DocId           = vm.id,
                    ActivityType    = (int)ActivityTypeContants.Deleted,
                    UserRemark      = vm.Reason,
                    xEModifications = Modifications,
                }));

                return(Json(new { success = true }));
            }
            return(PartialView("_Reason", vm));
        }
        public ActionResult _CreatePost(ReportLine pt)
        {
            if (ModelState.IsValid)
            {
                if (pt.ReportLineId <= 0)
                {
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;
                    _ReportLineService.Create(pt);

                    try
                    {
                        _unitOfWork.Save();
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        return(PartialView("_Create", pt));
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId    = new DocumentTypeService(_unitOfWork).Find(TransactionDoctypeConstants.Report).DocumentTypeId,
                        DocId        = pt.ReportHeaderId,
                        DocLineId    = pt.ReportLineId,
                        ActivityType = (int)ActivityTypeContants.Added,
                    }));


                    return(RedirectToAction("_Create", new { id = pt.ReportHeaderId }));
                }
                else
                {
                    pt.ModifiedDate = DateTime.Now;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Modified;
                    _ReportLineService.Update(pt);

                    try
                    {
                        _unitOfWork.Save();
                    }

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

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId    = new DocumentTypeService(_unitOfWork).Find(TransactionDoctypeConstants.Report).DocumentTypeId,
                        DocId        = pt.ReportHeaderId,
                        DocLineId    = pt.ReportLineId,
                        ActivityType = (int)ActivityTypeContants.Modified,
                    }));

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

            return(PartialView("_Create", pt));
        }
        public ActionResult Post(ShipMethod vm)
        {
            ShipMethod pt = vm;

            if (ModelState.IsValid)
            {
                if (vm.ShipMethodId <= 0)
                {
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;
                    _ShipMethodService.Create(pt);

                    try
                    {
                        _unitOfWork.Save();
                    }

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


                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId    = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ShipMethod).DocumentTypeId,
                        DocId        = pt.ShipMethodId,
                        ActivityType = (int)ActivityTypeContants.Added,
                    }));


                    return(RedirectToAction("Create").Success("Data saved successfully"));
                }
                else
                {
                    List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                    ShipMethod sm = _ShipMethodService.Find(pt.ShipMethodId);

                    ShipMethod ExRec = Mapper.Map <ShipMethod>(sm);

                    sm.ShipMethodName = pt.ShipMethodName;
                    sm.IsActive       = pt.IsActive;

                    sm.ModifiedDate = DateTime.Now;
                    sm.ModifiedBy   = User.Identity.Name;
                    sm.ObjectState  = Model.ObjectState.Modified;
                    _ShipMethodService.Update(sm);

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

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        return(View("Create", pt));
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ShipMethod).DocumentTypeId,
                        DocId           = sm.ShipMethodId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        xEModifications = Modifications,
                    }));

                    return(RedirectToAction("Index").Success("Data saved successfully"));
                }
            }
            return(View("Create", vm));
        }
        public ActionResult Post(JobReceiveHeaderViewModel svm)
        {
            bool   TimePlanValidation = true;
            string ExceptionMsg       = "";
            bool   Continue           = true;

            JobReceiveHeader s = Mapper.Map <JobReceiveHeaderViewModel, JobReceiveHeader>(svm);
            List <WeavingReceiveWizardViewModel> JobOrdersAndQtys = (List <WeavingReceiveWizardViewModel>)System.Web.HttpContext.Current.Session["BarCodesWeavingWizardJobOrder"];



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

            int JobWorkerCnt = (from l in JobOrdersAndQtys
                                group l by l.JobWorkerId into g
                                select new
            {
                JobWorkerId = g.Key,
            }).Distinct().Count();

            if (JobWorkerCnt > 1)
            {
                ModelState.AddModelError("", "Select any one Job Worker Orders.");
            }



            s.JobWorkerId   = JobOrdersAndQtys.FirstOrDefault().JobWorkerId;
            svm.JobWorkerId = JobOrdersAndQtys.FirstOrDefault().JobWorkerId;


            #region DocTypeTimeLineValidation

            try
            {
                if (svm.JobReceiveHeaderId <= 0)
                {
                    TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(svm), DocumentTimePlanTypeConstants.Create, User.Identity.Name, out ExceptionMsg, out Continue);
                }
                else
                {
                    TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(svm), DocumentTimePlanTypeConstants.Modify, User.Identity.Name, out ExceptionMsg, out Continue);
                }
            }
            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                TempData["CSEXC"] += message;
                TimePlanValidation = false;
            }

            if (!TimePlanValidation)
            {
                TempData["CSEXC"] += ExceptionMsg;
            }

            #endregion

            if (ModelState.IsValid && (TimePlanValidation || Continue))
            {
                if (svm.JobReceiveHeaderId <= 0)
                {
                    if (JobOrdersAndQtys.Count() > 0)
                    {
                        s.CreatedDate  = DateTime.Now;
                        s.ModifiedDate = DateTime.Now;
                        s.CreatedBy    = User.Identity.Name;
                        s.ModifiedBy   = User.Identity.Name;
                        s.Status       = (int)StatusConstants.Drafted;
                        _JobReceiveHeaderService.Create(s);


                        int Cnt = 0;
                        int Sr  = 0;


                        JobReceiveSettings Settings = new JobReceiveSettingsService(_unitOfWork).GetJobReceiveSettingsForDocument(s.DocTypeId, s.DivisionId, s.SiteId);

                        int ProductUidCountForJobOrderLine = 0;
                        int pk = 0;

                        var JobOrderLineIds = JobOrdersAndQtys.Select(m => m.JobOrderLineId).ToArray();

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

                        if (ModelState.IsValid)
                        {
                            foreach (var SelectedJobOrderLine in JobOrdersAndQtys)
                            {
                                if (SelectedJobOrderLine.JobOrderLineId > 0)
                                {
                                    if (SelectedJobOrderLine.ToProductUidName != "" && SelectedJobOrderLine.ToProductUidName != null && SelectedJobOrderLine.FromProductUidName != "" && SelectedJobOrderLine.FromProductUidName != null)
                                    {
                                        if (SelectedJobOrderLine.Qty != (Convert.ToInt32(SelectedJobOrderLine.ToProductUidName) - Convert.ToInt32(SelectedJobOrderLine.FromProductUidName) + 1))
                                        {
                                            string Msg = "";
                                            Msg = "Qty and Barcode series does not match.";
                                            ModelState.AddModelError("", Msg);
                                            PrepareViewBag();
                                            ViewBag.Mode = "Add";
                                            return(View("Create", svm));
                                        }
                                    }



                                    ProductUidCountForJobOrderLine = 0;
                                    var JobOrderLine = new JobOrderLineService(_unitOfWork).Find((SelectedJobOrderLine.JobOrderLineId));
                                    var Product      = new ProductService(_unitOfWork).Find(JobOrderLine.ProductId);

                                    var bal = BalQtyandUnits.Where(m => m.JobOrderLineId == SelectedJobOrderLine.JobOrderLineId).FirstOrDefault();

                                    if (SelectedJobOrderLine.Qty <= bal.BalQty)
                                    {
                                        for (int i = 0; i <= SelectedJobOrderLine.Qty - 1; i++)
                                        {
                                            int?ProductUidHeaderId = null;
                                            int?ProductUidId       = null;


                                            var SisterSite = (from S in db.Site where S.PersonId == s.JobWorkerId select S).FirstOrDefault();

                                            //if (!string.IsNullOrEmpty(Settings.SqlProcGenProductUID))
                                            if (SisterSite == null)
                                            {
                                                ProductUidHeader ProdUidHeader = new ProductUidHeader();

                                                ProdUidHeader.ProductUidHeaderId = Cnt;
                                                ProdUidHeader.ProductId          = JobOrderLine.ProductId;
                                                ProdUidHeader.Dimension1Id       = JobOrderLine.Dimension1Id;
                                                ProdUidHeader.Dimension2Id       = JobOrderLine.Dimension2Id;
                                                ProdUidHeader.GenDocId           = s.JobReceiveHeaderId;
                                                ProdUidHeader.GenDocNo           = s.DocNo;
                                                ProdUidHeader.GenDocTypeId       = s.DocTypeId;
                                                ProdUidHeader.GenDocDate         = s.DocDate;
                                                ProdUidHeader.GenPersonId        = s.JobWorkerId;
                                                ProdUidHeader.CreatedBy          = User.Identity.Name;
                                                ProdUidHeader.CreatedDate        = DateTime.Now;
                                                ProdUidHeader.ModifiedBy         = User.Identity.Name;
                                                ProdUidHeader.ModifiedDate       = DateTime.Now;
                                                ProdUidHeader.ObjectState        = Model.ObjectState.Added;
                                                new ProductUidHeaderService(_unitOfWork).Create(ProdUidHeader);
                                                ProductUidHeaderId = ProdUidHeader.ProductUidHeaderId;


                                                string ProductUidName = (Convert.ToInt32(SelectedJobOrderLine.FromProductUidName) + ProductUidCountForJobOrderLine).ToString();

                                                ProductUid ProdUid = new ProductUid();
                                                ProdUid.ProductUidHeaderId       = ProdUidHeader.ProductUidHeaderId;
                                                ProdUid.ProductUidName           = ProductUidName;
                                                ProdUid.ProductId                = JobOrderLine.ProductId;
                                                ProdUid.IsActive                 = true;
                                                ProdUid.CreatedBy                = User.Identity.Name;
                                                ProdUid.CreatedDate              = DateTime.Now;
                                                ProdUid.ModifiedBy               = User.Identity.Name;
                                                ProdUid.ModifiedDate             = DateTime.Now;
                                                ProdUid.GenLineId                = null;
                                                ProdUid.GenDocId                 = s.JobReceiveHeaderId;
                                                ProdUid.GenDocNo                 = s.DocNo;
                                                ProdUid.GenDocTypeId             = s.DocTypeId;
                                                ProdUid.GenDocDate               = s.DocDate;
                                                ProdUid.GenPersonId              = s.JobWorkerId;
                                                ProdUid.Dimension1Id             = JobOrderLine.Dimension1Id;
                                                ProdUid.Dimension2Id             = JobOrderLine.Dimension2Id;
                                                ProdUid.CurrenctProcessId        = s.ProcessId;
                                                ProdUid.CurrenctGodownId         = s.GodownId;
                                                ProdUid.Status                   = "Receive";
                                                ProdUid.LastTransactionDocId     = s.JobReceiveHeaderId;
                                                ProdUid.LastTransactionDocNo     = s.DocNo;
                                                ProdUid.LastTransactionDocTypeId = s.DocTypeId;
                                                ProdUid.LastTransactionDocDate   = s.DocDate;
                                                ProdUid.LastTransactionPersonId  = s.JobWorkerId;
                                                ProdUid.LastTransactionLineId    = null;
                                                ProdUid.ProductUIDId             = pk;
                                                new ProductUidService(_unitOfWork).Create(ProdUid);
                                                ProductUidId = ProdUid.ProductUIDId;
                                            }

                                            if (ProductUidId == null)
                                            {
                                                string ProductUidName = (Convert.ToInt32(SelectedJobOrderLine.FromProductUidName) + ProductUidCountForJobOrderLine).ToString();
                                                var    temp           = new ProductUidService(_unitOfWork).Find(ProductUidName);
                                                if (temp != null)
                                                {
                                                    ProductUidId = temp.ProductUIDId;
                                                }
                                                else
                                                {
                                                    string Msg = ProductUidName + " is not a valid barcode.";
                                                    ModelState.AddModelError("", Msg);
                                                    PrepareViewBag();
                                                    ViewBag.Mode = "Add";
                                                    return(View("Create", svm));
                                                }

                                                if (temp.CurrenctGodownId != null)
                                                {
                                                    string Msg = ProductUidName + " is already in Stock at Godown " + new GodownService(_unitOfWork).Find(temp.CurrenctGodownId ?? 0).GodownName;
                                                    ModelState.AddModelError("", Msg);
                                                    PrepareViewBag();
                                                    ViewBag.Mode = "Add";
                                                    return(View("Create", svm));
                                                }

                                                if (temp.LastTransactionPersonId != s.JobWorkerId)
                                                {
                                                    string Msg = ProductUidName + ProductUidName + " does not belong to this Job Worker";
                                                    ModelState.AddModelError("", Msg);
                                                    PrepareViewBag();
                                                    ViewBag.Mode = "Add";
                                                    return(View("Create", svm));
                                                }
                                            }


                                            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.JobReceiveHeaderId;
                                            StockViewModel.DocLineId          = null;
                                            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  = JobOrderLine.ProductId;
                                            //StockViewModel.ProductUidId = ProdUid.ProductUIDId;
                                            StockViewModel.ProductUidId       = ProductUidId;
                                            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  = SelectedJobOrderLine.CostCenterId;
                                            StockViewModel.Qty_Iss       = 0;
                                            StockViewModel.Qty_Rec       = 1;
                                            StockViewModel.Rate          = SelectedJobOrderLine.Rate;
                                            StockViewModel.ExpiryDate    = null;
                                            StockViewModel.Specification = JobOrderLine.Specification;
                                            StockViewModel.Dimension1Id  = JobOrderLine.Dimension1Id;
                                            StockViewModel.Dimension2Id  = JobOrderLine.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;
                                            }


                                            JobReceiveLine line = new JobReceiveLine();
                                            line.StockId = StockViewModel.StockId;
                                            //line.ProductUidHeaderId = ProdUidHeader.ProductUidHeaderId;
                                            line.ProductUidHeaderId = ProductUidHeaderId;
                                            //line.ProductUidId = ProdUid.ProductUIDId;
                                            line.ProductUidId       = ProductUidId;
                                            line.JobReceiveHeaderId = s.JobReceiveHeaderId;
                                            line.JobOrderLineId     = JobOrderLine.JobOrderLineId;
                                            line.Qty     = 1;
                                            line.PassQty = 1;
                                            line.LossQty = 0;
                                            line.UnitConversionMultiplier = JobOrderLine.UnitConversionMultiplier;
                                            line.DealQty          = 1 * JobOrderLine.UnitConversionMultiplier;
                                            line.DealUnitId       = JobOrderLine.DealUnitId;
                                            line.Sr               = Sr++;
                                            line.CreatedDate      = DateTime.Now;
                                            line.ModifiedDate     = DateTime.Now;
                                            line.CreatedBy        = User.Identity.Name;
                                            line.ModifiedBy       = User.Identity.Name;
                                            line.JobReceiveLineId = pk;
                                            line.ObjectState      = Model.ObjectState.Added;
                                            new JobReceiveLineService(_unitOfWork).Create(line);

                                            new JobReceiveLineStatusService(_unitOfWork).CreateLineStatus(line.JobReceiveLineId, ref db, false);


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

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



                        IEnumerable <JobReceiveLine> JobReceiveLineList = new JobReceiveLineService(_unitOfWork).GetJobReceiveLineList(s.JobReceiveHeaderId);

                        foreach (JobReceiveLine Line in JobReceiveLineList)
                        {
                            if (Line.ProductUidId != null)
                            {
                                ProductUid ProductUid = new ProductUidService(_unitOfWork).Find((int)Line.ProductUidId);
                                ProductUid.GenDocId              = Line.JobReceiveHeaderId;
                                ProductUid.LastTransactionDocId  = Line.JobReceiveHeaderId;
                                ProductUid.GenLineId             = Line.JobReceiveLineId;
                                ProductUid.LastTransactionLineId = Line.JobReceiveLineId;
                                new ProductUidService(_unitOfWork).Update(ProductUid);
                            }
                        }

                        try
                        {
                            _unitOfWork.Save();
                        }

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

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

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

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