Exemplo n.º 1
0
        public ActionResult Create(ServiceTaxCategory vm)
        {
            ServiceTaxCategory pt = vm;

            if (ModelState.IsValid)
            {
                pt.CreatedDate  = DateTime.Now;
                pt.ModifiedDate = DateTime.Now;
                pt.CreatedBy    = User.Identity.Name;
                pt.ModifiedBy   = User.Identity.Name;
                pt.ObjectState  = Model.ObjectState.Added;
                _ServiceTaxCategoryService.Create(pt);

                try
                {
                    _unitOfWork.Save();
                }

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


                return(RedirectToAction("Create").Success("Data saved successfully"));
            }
            return(View("Create", vm));
        }
Exemplo n.º 2
0
        public ActionResult Create(TdsCategory vm)
        {
            TdsCategory pt = vm;

            if (ModelState.IsValid)
            {
                pt.CreatedDate  = DateTime.Now;
                pt.ModifiedDate = DateTime.Now;
                pt.CreatedBy    = User.Identity.Name;
                pt.ModifiedBy   = User.Identity.Name;
                pt.ObjectState  = Model.ObjectState.Added;
                _TdsCategoryService.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.TdsCategory).DocumentTypeId,
                    DocId        = pt.TdsCategoryId,
                    ActivityType = (int)ActivityTypeContants.Added,
                }));

                return(RedirectToAction("Create").Success("Data saved successfully"));
            }
            return(View("Create", vm));
        }
        public ActionResult PostPOCalculationFields(List <HeaderChargeViewModel> temp)
        {
            foreach (var item in temp)
            {
                var header = new PurchaseOrderHeaderChargeService(_unitOfWork).Find(item.Id);
                header.Rate   = item.Rate;
                header.Amount = item.Amount;
                new PurchaseOrderHeaderChargeService(_unitOfWork).Update(header);
            }

            try
            {
                _unitOfWork.Save();
            }

            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                ModelState.AddModelError("", message);

                return(PartialView("FooterChargeEdit", temp));
            }


            return(Json(new { success = true }));
        }
Exemplo n.º 4
0
        public ActionResult _CreatePost(PersonProcessViewModel svm)
        {
            if (ModelState.IsValid)
            {
                if (svm.PersonProcessId == 0)
                {
                    PersonProcess PersonProcess = new PersonProcess();

                    PersonProcess.PersonId          = svm.PersonId;
                    PersonProcess.PersonRateGroupId = svm.PersonRateGroupId;
                    PersonProcess.ProcessId         = svm.ProcessId;
                    PersonProcess.CreatedDate       = DateTime.Now;
                    PersonProcess.ModifiedDate      = DateTime.Now;
                    PersonProcess.CreatedBy         = User.Identity.Name;
                    PersonProcess.ModifiedBy        = User.Identity.Name;
                    PersonProcess.ObjectState       = Model.ObjectState.Added;
                    _PersonProcessService.Create(PersonProcess);


                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        return(PartialView("_Create", svm));
                    }
                    return(RedirectToAction("_Create", new { id = PersonProcess.PersonId }));
                }
                else
                {
                    PersonProcess PersonProcess = _PersonProcessService.Find(svm.PersonProcessId);

                    PersonProcess.ProcessId         = svm.ProcessId;
                    PersonProcess.PersonRateGroupId = svm.PersonRateGroupId;

                    _PersonProcessService.Update(PersonProcess);

                    try
                    {
                        _unitOfWork.Save();
                    }

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


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

            return(PartialView("_Create", svm));
        }
Exemplo n.º 5
0
        public ActionResult AddStencilSizePost(RugStencilViewModel vm)
        {
            if (ModelState.IsValid)
            {
                Product p = new Product();
                p.ProductCode  = vm.StencilName;
                p.ProductName  = vm.StencilName;
                p.IsActive     = true;
                p.CreatedBy    = User.Identity.Name;
                p.ModifiedBy   = User.Identity.Name;
                p.DivisionId   = vm.DivisionId;
                p.CreatedDate  = DateTime.Now;
                p.ModifiedDate = DateTime.Now;

                new ProductService(_unitOfWork).Create(p);

                RugStencil rs = new RugStencil();
                rs.FullHalf        = vm.FullHalf;
                rs.CreatedBy       = User.Identity.Name;
                rs.CreatedDate     = DateTime.Now;
                rs.ModifiedBy      = User.Identity.Name;
                rs.ModifiedDate    = DateTime.Now;
                rs.ProductDesignId = vm.ProductDesignId;
                rs.ProductSizeId   = vm.ProductSizeId;
                rs.StencilId       = p.ProductId;
                _RugStencilService.Create(rs);


                ProductSize ps = new ProductSize();

                ps.CreatedBy         = User.Identity.Name;
                ps.CreatedDate       = DateTime.Now;
                ps.IsActive          = true;
                ps.ModifiedBy        = User.Identity.Name;
                ps.ModifiedDate      = DateTime.Now;
                ps.ProductId         = p.ProductId;
                ps.ProductSizeTypeId = new ProductSizeTypeService(_unitOfWork).Find(SizeTypeConstants.Standard).ProductSizeTypeId;
                ps.SizeId            = vm.StencilSizeId;

                new ProductSizeService(_unitOfWork).Create(ps);

                try
                {
                    _unitOfWork.Save();
                }

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

                return(Json(new { success = true }));
            }
            return(PartialView("AddStencilSize", vm));
        }
Exemplo n.º 6
0
        public ActionResult _ResultsPost(SaleDeliveryMasterDetailModel vm)
        {
            if (ModelState.IsValid)
            {
                SaleDeliveryOrderHeader Header = new SaleDeliveryOrderHeaderService(_unitOfWork).Find(vm.SaleDeliveryOrderLineViewModel.FirstOrDefault().SaleDeliveryOrderHeaderId);

                foreach (var item in vm.SaleDeliveryOrderLineViewModel)
                {
                    decimal balqty = (from p in db.ViewSaleOrderBalanceForCancellation
                                      where p.SaleOrderLineId == item.SaleOrderLineId
                                      select p.BalanceQty).FirstOrDefault();

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

                        line.SaleDeliveryOrderHeaderId = item.SaleDeliveryOrderHeaderId;
                        line.SaleOrderLineId           = item.SaleOrderLineId;
                        line.Qty          = item.Qty;
                        line.CreatedDate  = DateTime.Now;
                        line.ModifiedDate = DateTime.Now;
                        line.CreatedBy    = User.Identity.Name;
                        line.ModifiedBy   = User.Identity.Name;
                        line.Remark       = item.Remark;
                        _SaleDeliveryOrderLineService.Create(line);
                    }
                }

                if (Header.Status != (int)StatusConstants.Drafted && Header.Status != (int)StatusConstants.Import)
                {
                    Header.Status      = (int)StatusConstants.Modified;
                    Header.ObjectState = Model.ObjectState.Modified;
                    new SaleDeliveryOrderHeaderService(_unitOfWork).Update(Header);
                }

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

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

                return(Json(new { success = true }));
            }
            return(PartialView("_Results", vm));
        }
Exemplo n.º 7
0
        public ActionResult Post(ProductUid vm)
        {
            if (ModelState.IsValid)
            {
                if (vm.ProductUIDId != 0)
                {
                    ProductUid P = new ProductUidService(_unitOfWork).Find(vm.ProductUIDId);
                    P.Dimension1Id             = vm.Dimension1Id;
                    P.Dimension2Id             = vm.Dimension2Id;
                    P.Dimension3Id             = vm.Dimension3Id;
                    P.Dimension4Id             = vm.Dimension4Id;
                    P.ProductUidSpecification  = vm.ProductUidSpecification;
                    P.ProductUidSpecification1 = vm.ProductUidSpecification1;
                    P.ModifiedDate             = DateTime.Now;
                    P.ModifiedBy  = User.Identity.Name;
                    P.ObjectState = Model.ObjectState.Modified;
                    db.ProductUid.Add(P);

                    try
                    {
                        db.SaveChanges();
                    }

                    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.ProductUid).DocumentTypeId,
                        DocId        = vm.ProductUIDId,
                        ActivityType = (int)ActivityTypeContants.Added,
                    }));

                    return(RedirectToAction("Create").Success("Data saved successfully"));
                }
            }
            return(View("Create", vm));
        }
Exemplo n.º 8
0
        public ActionResult HeaderPost(string Ids)
        {
            string[] subStr = Ids.Split(',');
            for (int i = 0; i < subStr.Length; i++)
            {
                int            temp = Convert.ToInt32(subStr[i]);
                GatePassHeader ah   = _GatePassService.Find(temp);
                ah.Status      = 1;
                ah.ObjectState = Model.ObjectState.Modified;
                db.GatePassHeader.Add(ah);
                try
                {
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    ModelState.AddModelError("", message);
                }
            }
            //  return Json(new { success = true });

            return(RedirectToAction("Index1", "GatePass"));
        }
Exemplo n.º 9
0
        public ActionResult Post(LedgerSettingViewModel vm)
        {
            LedgerSetting pt = AutoMapper.Mapper.Map <LedgerSettingViewModel, LedgerSetting>(vm);

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

                    try
                    {
                        _unitOfWork.Save();
                    }

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


                    return(RedirectToAction("Index", "LedgerHeader", new { id = vm.DocTypeId }).Success("Data saved successfully"));
                }
                else
                {
                    LedgerSetting temp = _LedgerSettingService.Find(pt.LedgerSettingId);
                    temp.filterContraDivisions                  = pt.filterContraDivisions;
                    temp.filterContraDocTypes                   = pt.filterContraDocTypes;
                    temp.filterContraSites                      = pt.filterContraSites;
                    temp.filterDocTypeCostCenter                = pt.filterDocTypeCostCenter;
                    temp.filterLedgerAccountGroupHeaders        = pt.filterLedgerAccountGroupHeaders;
                    temp.filterExcludeLedgerAccountGroupHeaders = pt.filterExcludeLedgerAccountGroupHeaders;
                    temp.filterLedgerAccountGroupLines          = pt.filterLedgerAccountGroupLines;
                    temp.filterExcludeLedgerAccountGroupLines   = pt.filterExcludeLedgerAccountGroupLines;
                    temp.isMandatoryChqNo            = pt.isMandatoryChqNo;
                    temp.BaseRateText                = pt.BaseRateText;
                    temp.BaseValueText               = pt.BaseValueText;
                    temp.isMandatoryGodown           = pt.isMandatoryGodown;
                    temp.isVisibleGodown             = pt.isVisibleGodown;
                    temp.isVisibleProcess            = pt.isVisibleProcess;
                    temp.isMandatoryProcess          = pt.isMandatoryProcess;
                    temp.isMandatoryHeaderCostCenter = pt.isMandatoryHeaderCostCenter;
                    temp.isVisibleHeaderCostCenter   = pt.isVisibleHeaderCostCenter;
                    temp.ProcessId = pt.ProcessId;
                    temp.isMandatoryLineCostCenter = pt.isMandatoryLineCostCenter;
                    temp.isMandatoryRefNo          = pt.isMandatoryRefNo;
                    temp.SqlProcReferenceNo        = pt.SqlProcReferenceNo;
                    temp.isVisibleChqNo            = pt.isVisibleChqNo;
                    temp.WizardMenuId = pt.WizardMenuId;
                    temp.filterPersonProcessHeaders  = pt.filterPersonProcessHeaders;
                    temp.filterPersonProcessLines    = pt.filterPersonProcessLines;
                    temp.isVisibleLineCostCenter     = pt.isVisibleLineCostCenter;
                    temp.isVisibleRefNo              = pt.isVisibleRefNo;
                    temp.isVisibleProductUid         = pt.isVisibleProductUid;
                    temp.isVisibleReferenceDocId     = pt.isVisibleReferenceDocId;
                    temp.isVisibleReferenceDocTypeId = pt.isVisibleReferenceDocTypeId;
                    temp.isVisibleDrCr                     = pt.isVisibleDrCr;
                    temp.isVisibleLineDrCr                 = pt.isVisibleLineDrCr;
                    temp.isVisibleAdjustmentType           = pt.isVisibleAdjustmentType;
                    temp.isVisiblePaymentFor               = pt.isVisiblePaymentFor;
                    temp.isVisiblePartyDocNo               = pt.isVisiblePartyDocNo;
                    temp.isVisiblePartyDocDate             = pt.isVisiblePartyDocDate;
                    temp.isVisibleLedgerAdj                = pt.isVisibleLedgerAdj;
                    temp.IsAutoDocNo                       = pt.IsAutoDocNo;
                    temp.PartyDocNoCaption                 = pt.PartyDocNoCaption;
                    temp.PartyDocDateCaption               = pt.PartyDocDateCaption;
                    temp.CancelDocTypeId                   = pt.CancelDocTypeId;
                    temp.filterReferenceDocTypes           = pt.filterReferenceDocTypes;
                    temp.SqlProcDocumentPrint              = pt.SqlProcDocumentPrint;
                    temp.SqlProcDocumentPrint_AfterApprove = pt.SqlProcDocumentPrint_AfterApprove;
                    temp.SqlProcDocumentPrint_AfterSubmit  = pt.SqlProcDocumentPrint_AfterSubmit;

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

                    try
                    {
                        _unitOfWork.Save();
                    }

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

                    return(RedirectToAction("Index", "LedgerHeader", new { id = vm.DocTypeId }).Success("Data saved successfully"));
                }
            }
            PrepareViewBag(vm.DocTypeId);
            return(View("Create", vm));
        }
Exemplo n.º 10
0
        public ActionResult Post(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;
                    _ProductBuyerService.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.ProductBuyer).DocumentTypeId,
                        DocId        = pt.ProductBuyerId,
                        ActivityType = (int)ActivityTypeContants.Added,
                    }));

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

                    ProductBuyer temp = _ProductBuyerService.Find(pt.ProductBuyerId);

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

                    temp.BuyerId             = pt.BuyerId;
                    temp.BuyerSku            = pt.BuyerSku;
                    temp.BuyerProductCode    = pt.BuyerProductCode;
                    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;
                    _ProductBuyerService.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.ProductBuyer).DocumentTypeId,
                        DocId           = temp.ProductBuyerId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        xEModifications = Modifications,
                    }));

                    return(RedirectToAction("Index", new { id = vm.ProductId }).Success("Data saved successfully"));
                }
            }
            return(View("Create", vm));
        }
        public ActionResult HeaderPost(SaleOrderHeaderIndexViewModel svm)
        {
            if (svm.DocDate > svm.DueDate)
            {
                ModelState.AddModelError("DueDate", "DueDate cannot be greater than DocDate");
            }

            #region DocTypeTimeLineValidation

            try
            {
                if (svm.SaleOrderHeaderId <= 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))
            {
                #region CreateRecord
                if (svm.SaleOrderHeaderId == 0)
                {
                    SaleOrderHeader s = Mapper.Map <SaleOrderHeaderIndexViewModel, SaleOrderHeader>(svm);

                    s.ActualDueDate = s.DueDate;
                    s.CreatedDate   = DateTime.Now;
                    s.ModifiedDate  = DateTime.Now;
                    s.CreatedBy     = User.Identity.Name;
                    s.ModifiedBy    = User.Identity.Name;
                    s.Status        = (int)StatusConstants.Drafted;
                    _SaleOrderHeaderService.Create(s);

                    try
                    {
                        _unitOfWork.Save();
                    }

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

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

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

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

                    //string tempredirect = (Request["Redirect"].ToString());
                    SaleOrderHeader s         = Mapper.Map <SaleOrderHeaderIndexViewModel, SaleOrderHeader>(svm);
                    StringBuilder   logstring = new StringBuilder();
                    SaleOrderHeader temp      = _SaleOrderHeaderService.Find(s.SaleOrderHeaderId);

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

                    int status = temp.Status;

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

                    temp.DocTypeId           = s.DocTypeId;
                    temp.DocDate             = s.DocDate;
                    temp.DocNo               = s.DocNo;
                    temp.BuyerOrderNo        = s.BuyerOrderNo;
                    temp.SaleToBuyerId       = s.SaleToBuyerId;
                    temp.BillToBuyerId       = s.BillToBuyerId;
                    temp.CurrencyId          = s.CurrencyId;
                    temp.Priority            = s.Priority;
                    temp.UnitConversionForId = s.UnitConversionForId;
                    temp.ShipMethodId        = s.ShipMethodId;
                    temp.ShipAddress         = s.ShipAddress;
                    temp.DeliveryTermsId     = s.DeliveryTermsId;
                    temp.Remark              = s.Remark;
                    temp.DueDate             = s.DueDate;
                    temp.Advance             = s.Advance;
                    temp.FinancierId         = s.FinancierId;
                    temp.SalesExecutiveId    = s.SalesExecutiveId;
                    temp.ModifiedDate        = DateTime.Now;
                    temp.ModifiedBy          = User.Identity.Name;
                    _SaleOrderHeaderService.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);
                        TempData["CSEXC"] += message;
                        PrepareViewBag(svm);
                        ViewBag.Mode = "Edit";
                        return(View("Create", svm));
                    }

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

                    return(RedirectToAction("Index", new { id = svm.DocTypeId }).Success("Data saved successfully"));
                }
                #endregion
            }
            PrepareViewBag(svm);
            ViewBag.Mode = "Add";
            return(View("Create", svm));
        }
Exemplo n.º 12
0
        public ActionResult Create(AgentViewModel AgentVm)
        {
            if (AgentVm.LedgerAccountGroupId == 0)
            {
                PrepareViewBag();
                return(View(AgentVm).Danger("Account Group field is required"));
            }

            if (_PersonService.CheckDuplicate(AgentVm.Name, AgentVm.Suffix, AgentVm.PersonId) == true)
            {
                PrepareViewBag();
                return(View(AgentVm).Danger("Combination of name and sufix is duplicate"));
            }


            if (ModelState.IsValid)
            {
                if (AgentVm.PersonId == 0)
                {
                    Person         person         = Mapper.Map <AgentViewModel, Person>(AgentVm);
                    BusinessEntity businessentity = Mapper.Map <AgentViewModel, BusinessEntity>(AgentVm);
                    Agent          Agent          = Mapper.Map <AgentViewModel, Agent>(AgentVm);
                    PersonAddress  personaddress  = Mapper.Map <AgentViewModel, PersonAddress>(AgentVm);
                    LedgerAccount  account        = Mapper.Map <AgentViewModel, LedgerAccount>(AgentVm);

                    person.CreatedDate  = DateTime.Now;
                    person.ModifiedDate = DateTime.Now;
                    person.CreatedBy    = User.Identity.Name;
                    person.ModifiedBy   = User.Identity.Name;
                    person.ObjectState  = Model.ObjectState.Added;
                    new PersonService(_unitOfWork).Create(person);

                    _BusinessEntityService.Create(businessentity);
                    _AgentService.Create(Agent);

                    personaddress.AddressType  = AddressTypeConstants.Work;
                    personaddress.CreatedDate  = DateTime.Now;
                    personaddress.ModifiedDate = DateTime.Now;
                    personaddress.CreatedBy    = User.Identity.Name;
                    personaddress.ModifiedBy   = User.Identity.Name;
                    personaddress.ObjectState  = Model.ObjectState.Added;
                    _PersonAddressService.Create(personaddress);


                    account.LedgerAccountName   = person.Name;
                    account.LedgerAccountSuffix = person.Suffix;
                    account.CreatedDate         = DateTime.Now;
                    account.ModifiedDate        = DateTime.Now;
                    account.CreatedBy           = User.Identity.Name;
                    account.ModifiedBy          = User.Identity.Name;
                    account.ObjectState         = Model.ObjectState.Added;
                    _AccountService.Create(account);


                    try
                    {
                        _unitOfWork.Save();
                    }

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


                    #region

                    //Saving Images if any uploaded after UnitOfWorkSave

                    if (Request.Files[0] != null && Request.Files[0].ContentLength > 0)
                    {
                        //For checking the first time if the folder exists or not-----------------------------
                        string uploadfolder;
                        int    MaxLimit;
                        int.TryParse(ConfigurationManager.AppSettings["MaxFileUploadLimit"], out MaxLimit);
                        var x = (from iid in db.Counter
                                 select iid).FirstOrDefault();
                        if (x == null)
                        {
                            uploadfolder = System.Guid.NewGuid().ToString();
                            Counter img = new Counter();
                            img.ImageFolderName = uploadfolder;
                            img.ModifiedBy      = User.Identity.Name;
                            img.CreatedBy       = User.Identity.Name;
                            img.ModifiedDate    = DateTime.Now;
                            img.CreatedDate     = DateTime.Now;
                            new CounterService(_unitOfWork).Create(img);
                            _unitOfWork.Save();
                        }

                        else
                        {
                            uploadfolder = x.ImageFolderName;
                        }


                        //For checking if the image contents length is greater than 100 then create a new folder------------------------------------

                        if (!Directory.Exists(System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder)))
                        {
                            Directory.CreateDirectory(System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder));
                        }

                        int count = Directory.GetFiles(System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder)).Length;

                        if (count >= MaxLimit)
                        {
                            uploadfolder = System.Guid.NewGuid().ToString();
                            var u = new CounterService(_unitOfWork).Find(x.CounterId);
                            u.ImageFolderName = uploadfolder;
                            new CounterService(_unitOfWork).Update(u);
                            _unitOfWork.Save();
                        }


                        //Saving Thumbnails images:
                        Dictionary <string, string> versions = new Dictionary <string, string>();

                        //Define the versions to generate
                        versions.Add("_thumb", "maxwidth=100&maxheight=100");  //Crop to square thumbnail
                        versions.Add("_medium", "maxwidth=200&maxheight=200"); //Fit inside 400x400 area, jpeg

                        string temp2    = "";
                        string filename = System.Guid.NewGuid().ToString();
                        foreach (string filekey in System.Web.HttpContext.Current.Request.Files.Keys)
                        {
                            HttpPostedFile pfile = System.Web.HttpContext.Current.Request.Files[filekey];
                            if (pfile.ContentLength <= 0)
                            {
                                continue;                           //Skip unused file controls.
                            }
                            temp2 = Path.GetExtension(pfile.FileName);

                            string uploadFolder = System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder);
                            if (!Directory.Exists(uploadFolder))
                            {
                                Directory.CreateDirectory(uploadFolder);
                            }

                            string filecontent = Path.Combine(uploadFolder, AgentVm.Name + "_" + filename);

                            //pfile.SaveAs(filecontent);
                            ImageBuilder.Current.Build(new ImageJob(pfile, filecontent, new Instructions(), false, true));


                            //Generate each version
                            foreach (string suffix in versions.Keys)
                            {
                                if (suffix == "_thumb")
                                {
                                    string tuploadFolder = System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder + "/Thumbs");
                                    if (!Directory.Exists(tuploadFolder))
                                    {
                                        Directory.CreateDirectory(tuploadFolder);
                                    }

                                    //Generate a filename (GUIDs are best).
                                    string tfileName = Path.Combine(tuploadFolder, AgentVm.Name + "_" + filename);

                                    //Let the image builder add the correct extension based on the output file type
                                    //fileName = ImageBuilder.Current.Build(file, fileName, new ResizeSettings(versions[suffix]), false, true);
                                    ImageBuilder.Current.Build(new ImageJob(pfile, tfileName, new Instructions(versions[suffix]), false, true));
                                }
                                else if (suffix == "_medium")
                                {
                                    string tuploadFolder = System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder + "/Medium");
                                    if (!Directory.Exists(tuploadFolder))
                                    {
                                        Directory.CreateDirectory(tuploadFolder);
                                    }

                                    //Generate a filename (GUIDs are best).
                                    string tfileName = Path.Combine(tuploadFolder, AgentVm.Name + "_" + filename);

                                    //Let the image builder add the correct extension based on the output file type
                                    //fileName = ImageBuilder.Current.Build(file, fileName, new ResizeSettings(versions[suffix]), false, true);
                                    ImageBuilder.Current.Build(new ImageJob(pfile, tfileName, new Instructions(versions[suffix]), false, true));
                                }
                            }

                            //var tempsave = _FinishedProductService.Find(pt.ProductId);

                            person.ImageFileName   = AgentVm.Name + "_" + filename + temp2;
                            person.ImageFolderName = uploadfolder;
                            person.ObjectState     = Model.ObjectState.Modified;
                            _PersonService.Update(person);
                            _unitOfWork.Save();
                        }
                    }

                    #endregion



                    //return RedirectToAction("Create").Success("Data saved successfully");
                    return(RedirectToAction("Edit", new { id = person.PersonID }).Success("Data saved Successfully"));
                }
                else
                {
                    //string tempredirect = (Request["Redirect"].ToString());
                    Person         person         = Mapper.Map <AgentViewModel, Person>(AgentVm);
                    BusinessEntity businessentity = Mapper.Map <AgentViewModel, BusinessEntity>(AgentVm);
                    Agent          Agent          = Mapper.Map <AgentViewModel, Agent>(AgentVm);
                    PersonAddress  personaddress  = _PersonAddressService.Find(AgentVm.PersonAddressID);
                    LedgerAccount  account        = _AccountService.Find(AgentVm.AccountId);

                    StringBuilder logstring = new StringBuilder();

                    person.ModifiedDate = DateTime.Now;
                    person.ModifiedBy   = User.Identity.Name;
                    new PersonService(_unitOfWork).Update(person);


                    _BusinessEntityService.Update(businessentity);
                    _AgentService.Update(Agent);

                    personaddress.Address      = AgentVm.Address;
                    personaddress.CityId       = AgentVm.CityId;
                    personaddress.Zipcode      = AgentVm.Zipcode;
                    personaddress.ModifiedDate = DateTime.Now;
                    personaddress.ModifiedBy   = User.Identity.Name;
                    personaddress.ObjectState  = Model.ObjectState.Modified;
                    _PersonAddressService.Update(personaddress);

                    account.LedgerAccountName   = person.Name;
                    account.LedgerAccountSuffix = person.Suffix;
                    account.ModifiedDate        = DateTime.Now;
                    account.ModifiedBy          = User.Identity.Name;
                    _AccountService.Update(account);

                    ////Saving Activity Log::
                    ActivityLog al = new ActivityLog()
                    {
                        ActivityType = (int)ActivityTypeContants.Modified,
                        DocId        = AgentVm.PersonId,
                        Narration    = logstring.ToString(),
                        CreatedDate  = DateTime.Now,
                        CreatedBy    = User.Identity.Name,
                        //DocTypeId = new DocumentTypeService(_unitOfWork).FindByName(TransactionDocCategoryConstants.ProcessSequence).DocumentTypeId,
                    };
                    new ActivityLogService(_unitOfWork).Create(al);
                    //End of Saving ActivityLog

                    try
                    {
                        _unitOfWork.Save();
                    }

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



                    #region

                    //Saving Image if file is uploaded
                    if (Request.Files[0] != null && Request.Files[0].ContentLength > 0)
                    {
                        string uploadfolder = AgentVm.ImageFolderName;
                        string tempfilename = AgentVm.ImageFileName;
                        if (uploadfolder == null)
                        {
                            var x = (from iid in db.Counter
                                     select iid).FirstOrDefault();
                            if (x == null)
                            {
                                uploadfolder = System.Guid.NewGuid().ToString();
                                Counter img = new Counter();
                                img.ImageFolderName = uploadfolder;
                                img.ModifiedBy      = User.Identity.Name;
                                img.CreatedBy       = User.Identity.Name;
                                img.ModifiedDate    = DateTime.Now;
                                img.CreatedDate     = DateTime.Now;
                                new CounterService(_unitOfWork).Create(img);
                                _unitOfWork.Save();
                            }
                            else
                            {
                                uploadfolder = x.ImageFolderName;
                            }
                        }
                        //Deleting Existing Images
                        //ConfigurationManager.AppSettings["PhysicalRDLCPath"] + uploadfolder + "/" + tempfilename;
                        var xtemp = System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + uploadfolder + "/" + tempfilename);
                        if (System.IO.File.Exists(System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + uploadfolder + "/" + tempfilename)))
                        {
                            System.IO.File.Delete(System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + uploadfolder + "/" + tempfilename));
                        }

                        //Deleting Thumbnail Image:

                        if (System.IO.File.Exists(System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + uploadfolder + "/Thumbs/" + tempfilename)))
                        {
                            System.IO.File.Delete(System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + uploadfolder + "/Thumbs/" + tempfilename));
                        }

                        //Deleting Medium Image:
                        if (System.IO.File.Exists(System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + uploadfolder + "/Medium/" + tempfilename)))
                        {
                            System.IO.File.Delete(System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + uploadfolder + "/Medium/" + tempfilename));
                        }

                        //Saving Thumbnails images:
                        Dictionary <string, string> versions = new Dictionary <string, string>();

                        //Define the versions to generate
                        versions.Add("_thumb", "maxwidth=100&maxheight=100");  //Crop to square thumbnail
                        versions.Add("_medium", "maxwidth=200&maxheight=200"); //Fit inside 400x400 area, jpeg

                        string temp2    = "";
                        string filename = System.Guid.NewGuid().ToString();
                        foreach (string filekey in System.Web.HttpContext.Current.Request.Files.Keys)
                        {
                            HttpPostedFile pfile = System.Web.HttpContext.Current.Request.Files[filekey];
                            if (pfile.ContentLength <= 0)
                            {
                                continue;                           //Skip unused file controls.
                            }
                            temp2 = Path.GetExtension(pfile.FileName);

                            string uploadFolder = System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder);
                            if (!Directory.Exists(uploadFolder))
                            {
                                Directory.CreateDirectory(uploadFolder);
                            }

                            string filecontent = Path.Combine(uploadFolder, AgentVm.Name + "_" + filename);

                            //pfile.SaveAs(filecontent);

                            ImageBuilder.Current.Build(new ImageJob(pfile, filecontent, new Instructions(), false, true));

                            //Generate each version
                            foreach (string suffix in versions.Keys)
                            {
                                if (suffix == "_thumb")
                                {
                                    string tuploadFolder = System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder + "/Thumbs");
                                    if (!Directory.Exists(tuploadFolder))
                                    {
                                        Directory.CreateDirectory(tuploadFolder);
                                    }

                                    //Generate a filename (GUIDs are best).
                                    string tfileName = Path.Combine(tuploadFolder, AgentVm.Name + "_" + filename);

                                    //Let the image builder add the correct extension based on the output file type
                                    //fileName = ImageBuilder.Current.Build(file, fileName, new ResizeSettings(versions[suffix]), false, true);
                                    ImageBuilder.Current.Build(new ImageJob(pfile, tfileName, new Instructions(versions[suffix]), false, true));
                                }
                                else if (suffix == "_medium")
                                {
                                    string tuploadFolder = System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder + "/Medium");
                                    if (!Directory.Exists(tuploadFolder))
                                    {
                                        Directory.CreateDirectory(tuploadFolder);
                                    }

                                    //Generate a filename (GUIDs are best).
                                    string tfileName = Path.Combine(tuploadFolder, AgentVm.Name + "_" + filename);

                                    //Let the image builder add the correct extension based on the output file type
                                    //fileName = ImageBuilder.Current.Build(file, fileName, new ResizeSettings(versions[suffix]), false, true);
                                    ImageBuilder.Current.Build(new ImageJob(pfile, tfileName, new Instructions(versions[suffix]), false, true));
                                }
                            }
                        }

                        person.ImageFileName   = person.Name + "_" + filename + temp2;
                        person.ImageFolderName = uploadfolder;
                        _PersonService.Update(person);
                        _unitOfWork.Save();
                    }

                    #endregion



                    return(RedirectToAction("Index").Success("Data saved successfully"));
                }
            }
            PrepareViewBag();
            return(View(AgentVm));
        }
        public ActionResult _ResultsPost(RequisitionCancelListModel vm)
        {
            Dictionary <int, decimal> LineStatus = new Dictionary <int, decimal>();

            var Header = new RequisitionCancelHeaderService(_unitOfWork).Find(vm.RequisitionCancelViewModels.FirstOrDefault().RequisitionCancelHeaderId);

            bool BeforeSave = true;

            try
            {
                BeforeSave = MaterialRequestCancelDocEvents.beforeLineSaveBulkEvent(this, new StockEventArgs(vm.RequisitionCancelViewModels.FirstOrDefault().RequisitionCancelHeaderId), ref db);
            }
            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                TempData["CSEXC"] += message;
                EventException     = true;
            }

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

            if (ModelState.IsValid && BeforeSave && !EventException)
            {
                foreach (var item in vm.RequisitionCancelViewModels)
                {
                    decimal balqty = (from p in db.ViewRequisitionBalance
                                      where p.RequisitionLineId == item.RequisitionLineId
                                      select p.BalanceQty).FirstOrDefault();

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

                        line.RequisitionCancelHeaderId = item.RequisitionCancelHeaderId;
                        line.RequisitionLineId         = item.RequisitionLineId;
                        line.Qty          = item.Qty;
                        line.CreatedDate  = DateTime.Now;
                        line.ModifiedDate = DateTime.Now;
                        line.CreatedBy    = User.Identity.Name;
                        line.ModifiedBy   = User.Identity.Name;
                        line.Remark       = item.Remark;

                        LineStatus.Add(line.RequisitionLineId, line.Qty);

                        //_RequisitionCancelLineService.Create(line);

                        line.ObjectState = Model.ObjectState.Added;
                        db.RequisitionCancelLine.Add(line);
                    }
                }

                new RequisitionLineStatusService(_unitOfWork).UpdateRequisitionQtyCancelMultiple(LineStatus, Header.DocDate, ref db);

                try
                {
                    MaterialRequestCancelDocEvents.onLineSaveBulkEvent(this, new StockEventArgs(vm.RequisitionCancelViewModels.FirstOrDefault().RequisitionCancelHeaderId), ref db);
                }
                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    TempData["CSEXCL"] += message;
                    EventException      = true;
                }

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

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

                try
                {
                    MaterialRequestCancelDocEvents.afterLineSaveBulkEvent(this, new StockEventArgs(vm.RequisitionCancelViewModels.FirstOrDefault().RequisitionCancelHeaderId), ref db);
                }
                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    TempData["CSEXC"] += message;
                }

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

                return(Json(new { success = true }));
            }
            return(PartialView("_Results", vm));
        }
Exemplo n.º 14
0
        public ActionResult _CreatePost(RequisitionLineViewModel svm)
        {
            RequisitionHeader temp = new RequisitionHeaderService(_unitOfWork).Find(svm.RequisitionHeaderId);

            RequisitionLine s = Mapper.Map <RequisitionLineViewModel, RequisitionLine>(svm);

            if (svm.MaterialRequestSettings != null)
            {
                if (svm.MaterialRequestSettings.isMandatoryProcessLine == true && (svm.ProcessId <= 0 || svm.ProcessId == null))
                {
                    ModelState.AddModelError("ProcessId", "The Process field is required");
                }
            }

            bool BeforeSave = true;

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

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

            if (svm.Qty <= 0)
            {
                ModelState.AddModelError("Qty", "The Qty field is required");
            }

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

            if (ModelState.IsValid && BeforeSave && !EventException)
            {
                if (svm.RequisitionLineId <= 0)
                {
                    s.CreatedDate  = DateTime.Now;
                    s.ModifiedDate = DateTime.Now;
                    s.CreatedBy    = User.Identity.Name;
                    s.ModifiedBy   = User.Identity.Name;
                    s.ObjectState  = Model.ObjectState.Added;
                    //_RequisitionLineService.Create(s);
                    db.RequisitionLine.Add(s);

                    new RequisitionLineStatusService(_unitOfWork).CreateLineStatus(s.RequisitionLineId, ref db);

                    //RequisitionHeader header = new RequisitionHeaderService(_unitOfWork).Find(s.RequisitionHeaderId);
                    if (temp.Status != (int)StatusConstants.Drafted)
                    {
                        temp.Status       = (int)StatusConstants.Modified;
                        temp.ModifiedDate = DateTime.Now;
                        temp.ModifiedBy   = User.Identity.Name;

                        temp.ObjectState = Model.ObjectState.Modified;
                        db.RequisitionHeader.Add(temp);
                        //new RequisitionHeaderService(_unitOfWork).Update(temp);
                    }

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


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

                        db.SaveChanges();
                    }

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

                    try
                    {
                        MaterialRequestDocEvents.afterLineSaveEvent(this, new StockEventArgs(s.RequisitionHeaderId, s.RequisitionLineId, EventModeConstants.Add), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXCL"] += message;
                    }

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

                    return(RedirectToAction("_Create", new { id = svm.RequisitionHeaderId }));
                }


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

                    RequisitionLine templine = _RequisitionLineService.Find(s.RequisitionLineId);

                    int Status = temp.Status;

                    RequisitionLine ExRec = new RequisitionLine();
                    ExRec = Mapper.Map <RequisitionLine>(templine);

                    templine.ProductId     = s.ProductId;
                    templine.Specification = s.Specification;
                    templine.Dimension1Id  = s.Dimension1Id;
                    templine.Dimension2Id  = s.Dimension2Id;
                    templine.Dimension3Id  = s.Dimension3Id;
                    templine.Dimension4Id  = s.Dimension4Id;
                    templine.ProcessId     = s.ProcessId;
                    templine.DueDate       = s.DueDate;
                    templine.Remark        = s.Remark;
                    templine.Qty           = s.Qty;

                    templine.ModifiedDate = DateTime.Now;
                    templine.ModifiedBy   = User.Identity.Name;
                    //_RequisitionLineService.Update(templine);
                    templine.ObjectState = Model.ObjectState.Modified;
                    db.RequisitionLine.Add(templine);


                    if (temp.Status != (int)StatusConstants.Drafted)
                    {
                        temp.Status       = (int)StatusConstants.Modified;
                        temp.ModifiedBy   = User.Identity.Name;
                        temp.ModifiedDate = DateTime.Now;

                        temp.ObjectState = Model.ObjectState.Modified;
                        db.RequisitionHeader.Add(temp);
                        //new RequisitionHeaderService(_unitOfWork).Update(temp);
                    }
                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = ExRec,
                        Obj   = templine,
                    });

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

                    try
                    {
                        MaterialRequestDocEvents.onLineSaveEvent(this, new StockEventArgs(s.RequisitionHeaderId, templine.RequisitionLineId, EventModeConstants.Edit), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                        EventException     = true;
                    }


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

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

                    try
                    {
                        MaterialRequestDocEvents.afterLineSaveEvent(this, new StockEventArgs(s.RequisitionHeaderId, templine.RequisitionLineId, EventModeConstants.Edit), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                    }

                    //Saving the Activity Log

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

                    //End of Saving the Activity Log

                    return(Json(new { success = true }));
                }
            }
            PrepareViewBag(svm);
            return(PartialView("_Create", svm));
        }
        public ActionResult Post(JobOrderAmendmentHeaderViewModel vm)
        {
            bool BeforeSave = true;
            int  Serial     = 1;
            Dictionary <int, decimal> LineStatus = new Dictionary <int, decimal>();

            JobOrderAmendmentHeader pt = AutoMapper.Mapper.Map <JobOrderAmendmentHeaderViewModel, JobOrderAmendmentHeader>(vm);

            var settings = new JobOrderSettingsService(_unitOfWork).GetJobOrderSettingsForDocument(pt.DocTypeId, pt.DivisionId, pt.SiteId);

            if (!vm.JobOrderSettings.isVisibleJobWorkerLine && !vm.JobWorkerId.HasValue)
            {
                ModelState.AddModelError("JobWorkerId", "The JobWorker field is required");
            }

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


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

            if (ModelState.IsValid && BeforeSave && !EventException)
            {
                pt.Status       = (int)StatusConstants.Drafted;
                pt.CreatedDate  = DateTime.Now;
                pt.ModifiedDate = DateTime.Now;
                pt.CreatedBy    = User.Identity.Name;
                pt.ModifiedBy   = User.Identity.Name;
                pt.ObjectState  = Model.ObjectState.Added;
                db.JobOrderAmendmentHeader.Add(pt);
                //_JobOrderAmendmentHeaderService.Create(pt);


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

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

                var JobOrderBalanceRecords = (from p in db.ViewJobOrderBalanceForInvoice
                                              where JobOrderLineIds.Contains(p.JobOrderLineId)
                                              select p).AsNoTracking().ToList();

                var JobOrderRecords = (from p in db.JobOrderLine
                                       where JobOrderLineIds.Contains(p.JobOrderLineId)
                                       select p).AsNoTracking().ToList();

                foreach (var item in SelectedJobOrders)
                {
                    if (item.Rate - JobOrderBalanceRecords.Where(m => m.JobOrderLineId == item.JobOrderLineId).FirstOrDefault().Rate != 0)
                    {
                        JobOrderRateAmendmentLine line = new JobOrderRateAmendmentLine();

                        line.JobOrderAmendmentHeaderId = pt.JobOrderAmendmentHeaderId;
                        line.JobOrderLineId            = item.JobOrderLineId;
                        line.Qty          = JobOrderBalanceRecords.Where(m => m.JobOrderLineId == item.JobOrderLineId).FirstOrDefault().BalanceQty;
                        line.AmendedRate  = item.Rate;
                        line.Rate         = line.AmendedRate - JobOrderBalanceRecords.Where(m => m.JobOrderLineId == item.JobOrderLineId).FirstOrDefault().Rate;
                        line.Amount       = JobOrderBalanceRecords.Where(m => m.JobOrderLineId == item.JobOrderLineId).FirstOrDefault().BalanceQty *JobOrderRecords.Where(m => m.JobOrderLineId == item.JobOrderLineId).FirstOrDefault().UnitConversionMultiplier *line.Rate;
                        line.Amount       = DecimalRoundOff.amountToFixed(line.Amount, settings.AmountRoundOff);
                        line.JobOrderRate = JobOrderBalanceRecords.Where(m => m.JobOrderLineId == item.JobOrderLineId).FirstOrDefault().Rate;
                        line.JobWorkerId  = JobOrderBalanceRecords.Where(m => m.JobOrderLineId == item.JobOrderLineId).FirstOrDefault().JobWorkerId;
                        line.Sr           = Serial++;
                        line.CreatedDate  = DateTime.Now;
                        line.ModifiedDate = DateTime.Now;
                        line.CreatedBy    = User.Identity.Name;
                        line.ModifiedBy   = User.Identity.Name;
                        LineStatus.Add(line.JobOrderLineId, line.Rate);

                        line.ObjectState = Model.ObjectState.Added;
                        db.JobOrderRateAmendmentLine.Add(line);
                    }
                }

                new JobOrderLineStatusService(_unitOfWork).UpdateJobRateOnAmendmentMultiple(LineStatus, pt.DocDate, ref db);


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

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

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

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

                LogActivity.LogActivityDetail(new ActiivtyLogViewModel
                {
                    DocTypeId    = pt.DocTypeId,
                    DocId        = pt.JobOrderAmendmentHeaderId,
                    ActivityType = (int)ActivityTypeContants.WizardCreate,
                    User         = User.Identity.Name,
                    DocNo        = pt.DocNo,
                    DocDate      = pt.DocDate
                });


                Session.Remove("RateAmendmentWizardOrders");


                return(RedirectToAction("Index", "JobOrderAmendmentHeader", new { id = pt.DocTypeId }).Success("Data saved Successfully"));
            }
            PrepareViewBag(vm.DocTypeId);
            ViewBag.Mode = "Add";
            return(View("Create", vm));
        }
        public ActionResult Post(JobConsumptionSettingsViewModel vm)
        {
            JobConsumptionSettings pt = AutoMapper.Mapper.Map <JobConsumptionSettingsViewModel, JobConsumptionSettings>(vm);

            if (ModelState.IsValid)
            {
                if (vm.JobConsumptionSettingsId <= 0)
                {
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;
                    _JobConsumptionSettingsService.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.JobConsumptionSettingsId,
                        ActivityType = (int)ActivityTypeContants.SettingsAdded,
                    }));


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

                    //JobConsumptionSettings temp = _JobConsumptionSettingsService.Find(pt.JobConsumptionSettingsId);

                    JobConsumptionSettings temp = db.JobConsumptionSettings.Find(pt.JobConsumptionSettingsId);

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

                    temp.filterContraDocTypes   = pt.filterContraDocTypes;
                    temp.ProcessId              = pt.ProcessId;
                    temp.filterProductGroups    = pt.filterProductGroups;
                    temp.filterProducts         = pt.filterProducts;
                    temp.filterProductTypes     = pt.filterProductTypes;
                    temp.isMandatoryCostCenter  = pt.isMandatoryCostCenter;
                    temp.isMandatoryMachine     = pt.isMandatoryMachine;
                    temp.isMandatoryProcessLine = pt.isMandatoryProcessLine;
                    temp.isVisibleCostCenter    = pt.isVisibleCostCenter;
                    temp.isVisibleDimension1    = pt.isVisibleDimension1;
                    temp.isVisibleDimension2    = pt.isVisibleDimension2;
                    temp.isVisibleDimension3    = pt.isVisibleDimension3;
                    temp.isVisibleDimension4    = pt.isVisibleDimension4;
                    temp.isVisibleLotNo         = pt.isVisibleLotNo;
                    temp.isVisibleMachine       = pt.isVisibleMachine;
                    temp.isVisibleProductUID    = pt.isVisibleProductUID;
                    temp.SqlProcDocumentPrint   = pt.SqlProcDocumentPrint;
                    temp.ModifiedDate           = DateTime.Now;
                    temp.ModifiedBy             = User.Identity.Name;
                    temp.ObjectState            = Model.ObjectState.Modified;

                    _JobConsumptionSettingsService.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.JobConsumptionSettingsId,
                        ActivityType    = (int)ActivityTypeContants.SettingsModified,
                        xEModifications = Modifications,
                    }));

                    return(RedirectToAction("Index", "JobConsumptionHeader", new { id = vm.DocTypeId }).Success("Data saved successfully"));
                }
            }
            PrepareViewBag();
            return(View("Create", vm));
        }
        public ActionResult Post(SaleInvoiceSettingsViewModel vm)
        {
            SaleInvoiceSetting pt = AutoMapper.Mapper.Map <SaleInvoiceSettingsViewModel, SaleInvoiceSetting>(vm);

            if (pt.CalculationId <= 0)
            {
                ModelState.AddModelError("CalculationId", "The Calculation field is required");
            }

            if (ModelState.IsValid)
            {
                if (vm.SaleInvoiceSettingId <= 0)
                {
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;
                    _SaleInvoiceSettingService.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.SaleInvoiceSettingId,
                        ActivityType = (int)ActivityTypeContants.SettingsAdded,
                    }));



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

                    SaleInvoiceSetting temp = _SaleInvoiceSettingService.Find(pt.SaleInvoiceSettingId);

                    SaleInvoiceSetting ExRec = Mapper.Map <SaleInvoiceSetting>(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.filterPersonRoles                 = pt.filterPersonRoles;
                    temp.CalculationId                     = pt.CalculationId;
                    temp.SqlProcDocumentPrint_AfterApprove = pt.SqlProcDocumentPrint_AfterApprove;
                    temp.SqlProcDocumentPrint_AfterSubmit  = pt.SqlProcDocumentPrint_AfterSubmit;
                    temp.isVisibleDimension1               = pt.isVisibleDimension1;
                    temp.isVisibleDimension2               = pt.isVisibleDimension2;
                    temp.isVisibleDimension3               = pt.isVisibleDimension3;
                    temp.isVisibleDimension4               = pt.isVisibleDimension4;
                    temp.DocTypeDispatchReturnId           = pt.DocTypeDispatchReturnId;
                    temp.isVisibleLotNo                    = pt.isVisibleLotNo;
                    temp.SqlProcDocumentPrint              = pt.SqlProcDocumentPrint;
                    temp.CalculateDiscountOnRate           = pt.CalculateDiscountOnRate;
                    temp.DocTypePackingHeaderId            = pt.DocTypePackingHeaderId;
                    temp.SaleDispatchDocTypeId             = pt.SaleDispatchDocTypeId;
                    temp.SaleInvoiceReturnDocTypeId        = pt.SaleInvoiceReturnDocTypeId;
                    temp.SqlProcGatePass                   = pt.SqlProcGatePass;
                    temp.UnitConversionForId               = pt.UnitConversionForId;
                    temp.ImportMenuId                  = pt.ImportMenuId;
                    temp.isVisibleAgent                = pt.isVisibleAgent;
                    temp.isVisibleCurrency             = pt.isVisibleCurrency;
                    temp.isVisibleDeliveryTerms        = pt.isVisibleDeliveryTerms;
                    temp.isVisibleDealUnit             = pt.isVisibleDealUnit;
                    temp.isVisibleShipMethod           = pt.isVisibleShipMethod;
                    temp.isVisibleSpecification        = pt.isVisibleSpecification;
                    temp.isVisibleSalesTaxGroupPerson  = pt.isVisibleSalesTaxGroupPerson;
                    temp.isVisibleSalesTaxGroupProduct = pt.isVisibleSalesTaxGroupProduct;
                    temp.isVisibleProductUid           = pt.isVisibleProductUid;
                    temp.isVisibleProductCode          = pt.isVisibleProductCode;
                    temp.isVisibleBaleNo               = pt.isVisibleBaleNo;
                    temp.isVisibleDiscountPer          = pt.isVisibleDiscountPer;
                    temp.isVisiblePromoCode            = pt.isVisiblePromoCode;
                    temp.isVisibleForSaleOrder         = pt.isVisibleForSaleOrder;
                    temp.isVisibleWeight               = pt.isVisibleWeight;
                    temp.isVisibleFinancier            = pt.isVisibleFinancier;
                    temp.isVisibleSalesExecutive       = pt.isVisibleSalesExecutive;
                    temp.isVisibleFreeQty              = pt.isVisibleFreeQty;
                    temp.isVisibleRewardPoints         = pt.isVisibleRewardPoints;
                    temp.isVisibleCreditDays           = pt.isVisibleCreditDays;
                    temp.isVisibleTermsAndConditions   = pt.isVisibleTermsAndConditions;
                    temp.isVisibleShipToPartyAddress   = pt.isVisibleShipToPartyAddress;
                    temp.DoNotUpdateProductUidStatus   = pt.DoNotUpdateProductUidStatus;
                    temp.CurrencyId            = pt.CurrencyId;
                    temp.DeliveryTermsId       = pt.DeliveryTermsId;
                    temp.ShipMethodId          = pt.ShipMethodId;
                    temp.ProcessId             = pt.ProcessId;
                    temp.SalesTaxGroupPersonId = pt.SalesTaxGroupPersonId;
                    temp.GodownId = pt.GodownId;
                    temp.DocumentPrintReportHeaderId = pt.DocumentPrintReportHeaderId;
                    temp.ModifiedDate = DateTime.Now;
                    temp.ModifiedBy   = User.Identity.Name;
                    temp.ObjectState  = Model.ObjectState.Modified;
                    _SaleInvoiceSettingService.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.SaleInvoiceSettingId,
                        ActivityType    = (int)ActivityTypeContants.SettingsModified,
                        xEModifications = Modifications,
                    }));

                    return(RedirectToAction("Index", "DirectSaleInvoiceHeader", new { id = vm.DocTypeId }).Success("Data saved successfully"));
                }
            }
            PrepareViewBag();
            return(View("Create", vm));
        }
        public ActionResult _ResultsPost(SaleDeliveryListViewModel vm)
        {
            int Cnt = 0;


            SaleDeliveryHeader Dh = new SaleDeliveryHeaderService(_unitOfWork).Find(vm.SaleDeliveryLineViewModel.FirstOrDefault().SaleDeliveryHeaderId);

            SaleDeliverySetting Settings = new SaleDeliverySettingService(_unitOfWork).GetSaleDeliverySettingForDocument(Dh.DocTypeId, Dh.DivisionId, Dh.SiteId);



            int pk = 0;
            int PackingPrimaryKey  = 0;
            int DeliveryPrimaryKey = 0;


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

            if (ModelState.IsValid)
            {
                foreach (var item in vm.SaleDeliveryLineViewModel)
                {
                    decimal balqty = (from p in db.ViewSaleInvoiceBalanceForDelivery
                                      where p.SaleInvoiceLineId == item.SaleInvoiceLineId
                                      select p.BalanceQty).FirstOrDefault();
                    if (item.Qty > 0 && item.Qty <= balqty)
                    {
                        SaleDeliveryLine Dl = new SaleDeliveryLine();

                        Dl.UnitConversionMultiplier = item.UnitConversionMultiplier ?? 0;
                        Dl.DealQty              = item.Qty * item.UnitConversionMultiplier ?? 0;
                        Dl.DealUnitId           = item.DealUnitId;
                        Dl.CreatedBy            = User.Identity.Name;
                        Dl.CreatedDate          = DateTime.Now;
                        Dl.ModifiedBy           = User.Identity.Name;
                        Dl.ModifiedDate         = DateTime.Now;
                        Dl.SaleDeliveryHeaderId = Dh.SaleDeliveryHeaderId;
                        Dl.Qty                = item.Qty;
                        Dl.Remark             = item.Remark;
                        Dl.SaleInvoiceLineId  = item.SaleInvoiceLineId;
                        Dl.SaleDeliveryLineId = DeliveryPrimaryKey++;
                        Dl.ObjectState        = Model.ObjectState.Added;
                        _SaleDeliveryLineService.Create(Dl);



                        LineList.Add(new LineDetailListViewModel {
                            Amount = 0, Rate = 0, LineTableId = Dl.SaleDeliveryLineId, HeaderTableId = item.SaleDeliveryHeaderId, PersonID = Dh.SaleToBuyerId
                        });

                        pk++;
                        Cnt = Cnt + 1;
                    }
                }

                new SaleDeliveryHeaderService(_unitOfWork).Update(Dh);


                try
                {
                    _unitOfWork.Save();
                }

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

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


                return(Json(new { success = true }));
            }
            return(PartialView("_Results", vm));
        }
Exemplo n.º 19
0
        public ActionResult HeaderPost(ProductContentHeader svm)
        {
            if (ModelState.IsValid)
            {
                if (svm.ProductContentHeaderId == 0)
                {
                    svm.CreatedDate  = DateTime.Now;
                    svm.ModifiedDate = DateTime.Now;
                    svm.CreatedBy    = User.Identity.Name;
                    svm.ModifiedBy   = User.Identity.Name;
                    _ProductContentHeaderService.Create(svm);

                    try
                    {
                        _unitOfWork.Save();
                    }

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

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

                    return(RedirectToAction("Edit", new { id = svm.ProductContentHeaderId }).Success("Data saved Successfully"));
                }
                else
                {
                    List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                    ProductContentHeader temp = _ProductContentHeaderService.Find(svm.ProductContentHeaderId);

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

                    temp.ProductContentName = svm.ProductContentName;
                    temp.IsActive           = svm.IsActive;
                    temp.ModifiedDate       = DateTime.Now;
                    temp.ModifiedBy         = User.Identity.Name;
                    _ProductContentHeaderService.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", svm));
                    }


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

                    return(RedirectToAction("Index").Success("Data saved successfully"));
                }
            }
            return(View("Create", svm));
        }
        public ActionResult Post(JobReceiveQAAttributeViewModel vm)
        {
            if (ModelState.IsValid)
            {
                #region CreateRecord
                if (vm.JobReceiveQALineId <= 0)
                {
                    JobReceiveQALine Line = new JobReceiveQALine();
                    Line = _JobReceiveQAAttributeService.Create(vm, User.Identity.Name);



                    try
                    {
                        db.SaveChanges();
                    }

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

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


                    return(RedirectToAction("Edit", new { id = Line.JobReceiveQALineId }).Success("Data saved successfully"));
                }
                #endregion

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

                    JobReceiveQAHeader temp = new JobReceiveQAHeaderService(db).Find(vm.JobReceiveQAHeaderId);

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


                    int status = temp.Status;

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


                    _JobReceiveQAAttributeService.Update(vm, User.Identity.Name);

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

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

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

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

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

                    try
                    {
                        JobReceiveQADocEvents.afterHeaderSaveEvent(this, new JobEventArgs(temp.JobReceiveQAHeaderId, EventModeConstants.Edit), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                    }

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

                    return(RedirectToAction("Index", new { id = temp.DocTypeId }).Success("Data saved successfully"));
                }
                #endregion
            }
            PrepareViewBag(vm.DocTypeId);
            ViewBag.Mode = "Add";
            return(View("Create", vm));
        }
        public ActionResult _CreatePost(ProductConsumptionLineViewModel svm)
        {
            if (ModelState.IsValid)
            {
                if (svm.BomDetailId == 0)
                {
                    BomDetail bomdetail = new BomDetail();

                    bomdetail.BaseProductId = svm.BaseProductId;
                    bomdetail.BatchQty      = 1;
                    //bomdetail.ProcessId = new ProcessService(_unitOfWork).Find(ProcessConstants.Silai).ProcessId;
                    bomdetail.BaseProcessId = new ProcessService(_unitOfWork).Find(ProcessConstants.Manufacturing).ProcessId;
                    bomdetail.ProductId     = svm.ProductId;
                    bomdetail.ProcessId     = svm.ProcessId;
                    bomdetail.Dimension1Id  = svm.Dimension1Id;
                    bomdetail.Dimension2Id  = svm.Dimension2Id;
                    bomdetail.Dimension3Id  = svm.Dimension3Id;
                    bomdetail.Dimension4Id  = svm.Dimension4Id;
                    bomdetail.Qty           = svm.Qty;
                    bomdetail.MBQ           = svm.MBQ;
                    bomdetail.StdCost       = svm.StdCost;
                    bomdetail.StdTime       = svm.StdTime;

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


                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        return(PartialView("_Create", svm));
                    }
                    return(RedirectToAction("_Create", new { id = svm.BaseProductId }));
                }
                else
                {
                    BomDetail     bomdetail = _BomDetailService.Find(svm.BomDetailId);
                    StringBuilder logstring = new StringBuilder();

                    bomdetail.BaseProductId = svm.BaseProductId;
                    bomdetail.BatchQty      = 1;
                    bomdetail.BaseProcessId = new ProcessService(_unitOfWork).Find(ProcessConstants.Manufacturing).ProcessId;
                    bomdetail.ProductId     = svm.ProductId;
                    bomdetail.ProcessId     = svm.ProcessId;
                    bomdetail.Dimension1Id  = svm.Dimension1Id;
                    bomdetail.Dimension2Id  = svm.Dimension2Id;
                    bomdetail.Dimension3Id  = svm.Dimension3Id;
                    bomdetail.Dimension4Id  = svm.Dimension4Id;
                    bomdetail.Qty           = svm.Qty;
                    bomdetail.MBQ           = svm.MBQ;
                    bomdetail.StdCost       = svm.StdCost;
                    bomdetail.StdTime       = svm.StdTime;


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


                    //Saving the Activity Log
                    ActivityLog al = new ActivityLog()
                    {
                        ActivityType = (int)ActivityTypeContants.Modified,
                        DocId        = bomdetail.BomDetailId,
                        CreatedDate  = DateTime.Now,
                        Narration    = logstring.ToString(),
                        CreatedBy    = User.Identity.Name,
                        //DocTypeId = new DocumentTypeService(_unitOfWork).FindByName(TransactionDocCategoryConstants.BomDetail).DocumentTypeId,
                    };
                    new ActivityLogService(_unitOfWork).Create(al);
                    //End of Saving the Activity Log


                    try
                    {
                        _unitOfWork.Save();
                    }

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

            PrepareViewBag(svm);
            return(PartialView("_Create", svm));
        }
Exemplo n.º 22
0
        public ActionResult _CreatePost(QAGroupLineViewModel svm)
        {
            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();
            bool    BeforeSave = true;
            QAGroup temp       = new QAGroupService(_unitOfWork).Find(svm.QAGroupId);
            int     i          = 0;

            if (temp.QAGroupId <= 0)
            {
                i = _QAGroupLineService.GetQAGroupLineListForIndex(svm.QAGroupId).Where(x => x.Name == svm.Name).ToList().Count();
            }
            else
            {
                i = _QAGroupLineService.GetQAGroupLineListForIndex(svm.QAGroupId).Where(x => x.Name == svm.Name && x.QAGroupLineId != svm.QAGroupLineId).ToList().Count();
            }
            #region BeforeSave
            //try
            //{

            //    if (svm.GatePassLineId <= 0)
            //        BeforeSave = JobOrderDocEvents.beforeLineSaveEvent(this, new JobEventArgs(svm.GatePassHeaderId, EventModeConstants.Add), ref db);
            //    else
            //        BeforeSave = JobOrderDocEvents.beforeLineSaveEvent(this, new JobEventArgs(svm.GatePassHeaderId, EventModeConstants.Edit), ref db);

            //}
            //catch (Exception ex)
            //{
            //    string message = _exception.HandleException(ex);
            //    TempData["CSEXCL"] += message;
            //    EventException = true;
            //}

            //if (!BeforeSave)
            //    ModelState.AddModelError("", "Validation failed before save.");
            #endregion


            if (svm.Name == "" || svm.Name == null)
            {
                ModelState.AddModelError("Name", "The Name is required");
            }

            if (i != 0)
            {
                ModelState.AddModelError("Name", svm.Name + " already exist");
            }


            QAGroupLine s = Mapper.Map <QAGroupLineViewModel, QAGroupLine>(svm);

            ViewBag.Status = temp.Status;



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

            if (ModelState.IsValid && BeforeSave && !EventException)
            {
                if (svm.QAGroupLineId <= 0)
                {
                    //Posting in Stock
                    s.CreatedDate  = DateTime.Now;
                    s.ModifiedDate = DateTime.Now;
                    s.CreatedBy    = User.Identity.Name;
                    s.ModifiedBy   = User.Identity.Name;
                    s.ObjectState  = Model.ObjectState.Added;
                    db.QAGroupLine.Add(s);

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

                    temp.ObjectState = Model.ObjectState.Modified;
                    db.QAGroup.Add(temp);
                    //try
                    //{
                    //    JobOrderDocEvents.onLineSaveEvent(this, new JobEventArgs(s.GatePassHeaderId, s.GatePassLineId, EventModeConstants.Add), ref db);
                    //}
                    //catch (Exception ex)
                    //{
                    //    string message = _exception.HandleException(ex);
                    //    TempData["CSEXCL"] += message;
                    //    EventException = true;
                    //}
                    try
                    {
                        if (EventException)
                        {
                            throw new Exception();
                        }

                        db.SaveChanges();
                    }

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



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

                    return(RedirectToAction("_Create", new { id = svm.QAGroupId, IsProdBased = false }));
                    //return RedirectToAction("_Create", new { id = svm.GatePassHeaderId, IsProdBased = (s.ProdOrderLineId == null ? false : true) });
                }
                else
                {
                    QAGroupLine templine = (from p in db.QAGroupLine
                                            where p.QAGroupLineId == s.QAGroupLineId
                                            select p).FirstOrDefault();

                    QAGroupLine ExTempLine = new QAGroupLine();
                    ExTempLine = Mapper.Map <QAGroupLine>(templine);

                    templine.QAGroupId = s.QAGroupId;

                    /*templine.Name = s.Name;
                     * templine.IsMandatory = s.IsMandatory;
                     * templine.DataType = s.DataType;
                     * templine.ListItem = s.ListItem;
                     * templine.DefaultValue = s.DefaultValue;
                     * templine.IsActive = s.IsActive;*/
                    templine.ModifiedDate = DateTime.Now;
                    templine.ModifiedBy   = User.Identity.Name;
                    templine.ObjectState  = Model.ObjectState.Modified;
                    db.QAGroupLine.Add(templine);
                    int Status = 0;
                    if (temp.Status != (int)StatusConstants.Drafted && temp.Status != (int)StatusConstants.Import)
                    {
                        Status            = temp.Status;
                        temp.Status       = (int)StatusConstants.Modified;
                        temp.ModifiedBy   = User.Identity.Name;
                        temp.ModifiedDate = DateTime.Now;
                    }


                    temp.ObjectState = Model.ObjectState.Modified;
                    db.QAGroup.Add(temp);



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



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



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

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

                    try
                    {
                        JobOrderDocEvents.afterLineSaveEvent(this, new JobEventArgs(s.QAGroupId, templine.QAGroupLineId, EventModeConstants.Edit), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                    }


                    //Saving the Activity Log

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId       = temp.DocTypeId,
                        DocId           = templine.QAGroupId,
                        DocLineId       = templine.QAGroupLineId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        DocNo           = temp.QaGroupName,
                        xEModifications = Modifications,
                        DocDate         = temp.CreatedDate,
                        DocStatus       = temp.Status,
                    }));

                    //End of Saving the Activity Log

                    return(Json(new { success = true }));
                }
            }
            PrepareViewBag(svm);
            return(PartialView("_Create", svm));
        }
Exemplo n.º 23
0
        public ActionResult Post(ProductTypeAttribute pt)
        {
            if (ModelState.IsValid)
            {
                if (pt.ProductTypeAttributeId <= 0)
                {
                    pt.CreatedBy    = User.Identity.Name;
                    pt.CreatedDate  = System.DateTime.Now;
                    pt.ModifiedDate = System.DateTime.Now;
                    pt.ModifiedBy   = User.Identity.Name;
                    _ProductTypeAttributeService.Create(pt);

                    try
                    {
                        _unitOfWork.Save();
                    }

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

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

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

                    ProductTypeAttribute TypeAttribute = _ProductTypeAttributeService.Find(pt.ProductTypeAttributeId);

                    ProductTypeAttribute ExRec = Mapper.Map <ProductTypeAttribute>(TypeAttribute);

                    TypeAttribute.IsActive     = pt.IsActive;
                    TypeAttribute.DefaultValue = pt.DefaultValue;
                    TypeAttribute.Name         = pt.Name;
                    TypeAttribute.IsMandatory  = pt.IsMandatory;
                    TypeAttribute.DataType     = pt.DataType;
                    TypeAttribute.ListItem     = pt.ListItem;
                    TypeAttribute.ModifiedDate = DateTime.Now;
                    TypeAttribute.ModifiedBy   = User.Identity.Name;
                    _ProductTypeAttributeService.Update(TypeAttribute);

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

                    try
                    {
                        _unitOfWork.Save();
                    }

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

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

                    return(RedirectToAction("Index", new { id = TypeAttribute.ProductType_ProductTypeId }).Success("Data saved successfully"));
                }
            }
            PrepareViewBag(pt);
            return(View(pt));
        }
        public ActionResult Post(ProductGroupProcessSettingsViewModel vm)
        {
            ProductGroupProcessSettings pt = AutoMapper.Mapper.Map <ProductGroupProcessSettingsViewModel, ProductGroupProcessSettings>(vm);


            if (ModelState.IsValid)
            {
                ProductGroup ProductGroup = new ProductGroupService(_unitOfWork).Find(vm.ProductGroupId);
                if (vm.ProductGroupProcessSettingsId <= 0)
                {
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;
                    _ProductGroupProcessSettingsService.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.ProductGroupProcessSettingsId,
                        DocTypeId    = DocTypeId,
                        ActivityType = (int)ActivityTypeContants.SettingsAdded,
                    }));



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

                    ProductGroupProcessSettings temp = _ProductGroupProcessSettingsService.Find(pt.ProductGroupProcessSettingsId);

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

                    temp.ProcessId    = vm.ProcessId;
                    temp.QAGroupId    = vm.QAGroupId;
                    temp.ModifiedDate = DateTime.Now;
                    temp.ModifiedBy   = User.Identity.Name;
                    temp.ObjectState  = Model.ObjectState.Modified;
                    _ProductGroupProcessSettingsService.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.ProductGroupProcessSettingsId,
                        ActivityType    = (int)ActivityTypeContants.SettingsModified,
                        DocTypeId       = DocTypeId,
                        xEModifications = Modifications,
                    }));

                    return(RedirectToAction("Index", "ProductGroupProcessSettings", new { id = ProductGroup.ProductGroupId }).Success("Data saved successfully"));
                }
            }
            PrepareViewBag(vm);
            return(View("Create", vm));
        }
Exemplo n.º 25
0
        public ActionResult _ResultsPost(StockMasterDetailModel vm)
        {
            int Cnt    = 0;
            int pk     = 0;
            int Serial = _StockLineService.GetMaxSr(vm.StockLineViewModel.FirstOrDefault().StockHeaderId);
            Dictionary <int, decimal> LineStatus = new Dictionary <int, decimal>();
            StockHeader Header = new StockHeaderService(_unitOfWork).Find(vm.StockLineViewModel.FirstOrDefault().StockHeaderId);

            StockHeaderSettings Settings = new StockHeaderSettingsService(_unitOfWork).GetStockHeaderSettingsForDocument(Header.DocTypeId, Header.DivisionId, Header.SiteId);


            if (Settings.isMandatoryLineCostCenter == true && vm.StockLineViewModel.Where(m => m.CostCenterId == null).Any())
            {
                ModelState.AddModelError("", "CostCenter is mandatory");
            }

            decimal Qty = vm.StockLineViewModel.Where(m => m.Rate > 0).Sum(m => m.Qty);

            bool BeforeSave = true;

            try
            {
                BeforeSave = StockIssueDocEvents.beforeLineSaveBulkEvent(this, new StockEventArgs(vm.StockLineViewModel.FirstOrDefault().StockHeaderId), ref db);
            }
            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                TempData["CSEXC"] += message;
                EventException     = true;
            }

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

            if (ModelState.IsValid && BeforeSave && !EventException)
            {
                foreach (var item in vm.StockLineViewModel)
                {
                    //if (item.Qty > 0 &&  ((Settings.isMandatoryRate.HasValue && Settings.isMandatoryRate == true )? item.Rate > 0 : 1 == 1))
                    if (item.Qty > 0)
                    {
                        StockLine line = new StockLine();

                        line.StockHeaderId     = item.StockHeaderId;
                        line.RequisitionLineId = item.RequisitionLineId;
                        line.ProductId         = item.ProductId;
                        line.Dimension1Id      = item.Dimension1Id;
                        line.Dimension2Id      = item.Dimension2Id;
                        line.Dimension3Id      = item.Dimension3Id;
                        line.Dimension4Id      = item.Dimension4Id;
                        line.Specification     = item.Specification;
                        line.CostCenterId      = item.CostCenterId;
                        line.Qty                = item.Qty;
                        line.DocNature          = StockNatureConstants.Issue;
                        line.Rate               = item.Rate ?? 0;
                        line.Amount             = (line.Qty * line.Rate);
                        line.ReferenceDocId     = item.ReferenceDocId;
                        line.ReferenceDocTypeId = item.ReferenceDocTypeId;
                        line.CreatedDate        = DateTime.Now;
                        line.ModifiedDate       = DateTime.Now;
                        line.CreatedBy          = User.Identity.Name;
                        line.ModifiedBy         = User.Identity.Name;
                        line.StockLineId        = pk;
                        line.Sr          = Serial++;
                        line.ObjectState = Model.ObjectState.Added;
                        db.StockLine.Add(line);
                        pk++;
                        Cnt = Cnt + 1;
                        if (line.RequisitionLineId.HasValue)
                        {
                            LineStatus.Add(line.RequisitionLineId.Value, line.Qty);
                        }
                    }
                }
                //new RequisitionLineStatusService(_unitOfWork).UpdateRequisitionQtyIssueMultiple(LineStatus, Header.DocDate, ref db);

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

                Header.ObjectState = Model.ObjectState.Modified;
                db.StockHeader.Add(Header);

                try
                {
                    StockIssueDocEvents.onLineSaveBulkEvent(this, new StockEventArgs(vm.StockLineViewModel.FirstOrDefault().StockHeaderId), ref db);
                }
                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    TempData["CSEXCL"] += message;
                    EventException      = true;
                }

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

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

                try
                {
                    StockIssueDocEvents.afterLineSaveBulkEvent(this, new StockEventArgs(vm.StockLineViewModel.FirstOrDefault().StockHeaderId), ref db);
                }
                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    TempData["CSEXC"] += message;
                }

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

                return(Json(new { success = true }));
            }
            return(PartialView("_Results", vm));
        }
Exemplo n.º 26
0
        public ActionResult CreatePost(PackingHeaderViewModel vm)
        {
            #region DocTypeTimeLineValidation

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

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

            #endregion

            if (ModelState.IsValid && (TimePlanValidation || Continue))
            {
                #region CreateRecord
                if (vm.PackingHeaderId == 0)
                {
                    PackingHeader Packingheader = Mapper.Map <PackingHeaderViewModel, PackingHeader>(vm);

                    Packingheader.BuyerId      = vm.BuyerId;
                    Packingheader.CreatedBy    = User.Identity.Name;
                    Packingheader.ModifiedBy   = User.Identity.Name;
                    Packingheader.CreatedDate  = DateTime.Now;
                    Packingheader.ModifiedDate = DateTime.Now;
                    Packingheader.ObjectState  = Model.ObjectState.Added;
                    _PackingHeaderService.Create(Packingheader);



                    try
                    {
                        _unitOfWork.Save();
                    }

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

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


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

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


                    PackingHeader Packingheader = _PackingHeaderService.Find(vm.PackingHeaderId);

                    PackingHeader ExRec = Mapper.Map <PackingHeader>(Packingheader);


                    StockHeader StockHeader = new StockHeaderService(_unitOfWork).Find(Packingheader.StockHeaderId ?? 0);


                    int status = Packingheader.Status;

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


                    Packingheader.DocNo        = vm.DocNo;
                    Packingheader.DocDate      = vm.DocDate;
                    Packingheader.BuyerId      = vm.BuyerId;
                    Packingheader.GodownId     = vm.GodownId;
                    Packingheader.Remark       = vm.Remark;
                    Packingheader.ModifiedDate = DateTime.Now;
                    Packingheader.ModifiedBy   = User.Identity.Name;
                    _PackingHeaderService.Update(Packingheader);


                    if (StockHeader != null)
                    {
                        StockHeader.DocDate      = vm.DocDate;
                        StockHeader.PersonId     = vm.BuyerId;
                        StockHeader.GodownId     = vm.GodownId;
                        StockHeader.Remark       = vm.Remark;
                        StockHeader.ModifiedDate = DateTime.Now;
                        StockHeader.ModifiedBy   = User.Identity.Name;
                        new StockHeaderService(_unitOfWork).Update(StockHeader);
                    }

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

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

                    try
                    {
                        _unitOfWork.Save();
                    }

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

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

                    return(RedirectToAction("Index", new { id = vm.DocTypeId }).Success("Data saved successfully"));
                }
                #endregion
            }
            PrepareViewBag(vm.DocTypeId);
            ViewBag.Mode = "Add";
            return(View("Create", vm));
        }
Exemplo n.º 27
0
        public ActionResult Post(JobInvoiceAmendmentHeaderViewModel vm)
        {
            int    Serial             = 1;
            bool   TimePlanValidation = true;
            string ExceptionMsg       = "";
            bool   Continue           = true;
            int    pk = 0;

            Dictionary <int, decimal> LineStatus = new Dictionary <int, decimal>();

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

            JobInvoiceAmendmentHeader Header = AutoMapper.Mapper.Map <JobInvoiceAmendmentHeaderViewModel, JobInvoiceAmendmentHeader>(vm);

            List <HeaderChargeViewModel> HeaderCharges = new List <HeaderChargeViewModel>();
            List <LineChargeViewModel>   LineCharges   = new List <LineChargeViewModel>();

            List <LineReferenceIds> RefIds = new List <LineReferenceIds>();
            bool HeaderChargeEdit          = false;
            int  PersonCount = 0;

            var settings = new JobInvoiceSettingsService(_unitOfWork).GetJobInvoiceSettingsForDocument(Header.DocTypeId, Header.DivisionId, Header.SiteId);

            //int? CalculationId = settings.CalculationId;


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

            if (vm.JobInvoiceSettings.isVisibleHeaderJobWorker && !vm.JobWorkerId.HasValue)
            {
                ModelState.AddModelError("JobWorkerId", "The JobWorker field is required");
            }

            #region BeforeSave
            bool BeforeSave = true;
            try
            {
                BeforeSave = JobInvoiceAmendmentDocEvents.beforeWizardSaveEvent(this, new JobEventArgs(vm.JobInvoiceAmendmentHeaderId), ref db);
            }
            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                TempData["CSEXC"] += message;
                EventException     = true;
            }
            if (!BeforeSave)
            {
                TempData["CSEXC"] += "Failed validation before save";
            }
            #endregion

            #region DocTypeTimeLineValidation

            try
            {
                TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(vm), 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 && BeforeSave && !EventException && (TimePlanValidation || Continue))
            {
                if (SelectedJobInvoices.Count > 0)
                {
                    Header.Status       = (int)StatusConstants.Drafted;
                    Header.CreatedDate  = DateTime.Now;
                    Header.ModifiedDate = DateTime.Now;
                    Header.CreatedBy    = User.Identity.Name;
                    Header.ModifiedBy   = User.Identity.Name;
                    Header.ObjectState  = Model.ObjectState.Added;
                    db.JobInvoiceAmendmentHeader.Add(Header);
                    //_JobInvoiceAmendmentHeaderService.Create(pt);

                    var JobInvoiceLineIds = SelectedJobInvoices.Select(m => m.JobInvoiceLineId).ToArray();

                    var JobInvoiceBalanceRecords = (from p in db.ViewJobInvoiceBalanceForRateAmendment
                                                    where JobInvoiceLineIds.Contains(p.JobInvoiceLineId)
                                                    select p).AsNoTracking().ToList();

                    var JobInvoiceRecords = (from p in db.JobInvoiceLine
                                             where JobInvoiceLineIds.Contains(p.JobInvoiceLineId)
                                             select p).AsNoTracking().ToList();



                    int?CalculationId       = 0;
                    int JobInvoiceLineId    = JobInvoiceBalanceRecords.FirstOrDefault().JobInvoiceLineId;
                    var SalesTaxGroupPerson = (from L in db.JobInvoiceLine where L.JobInvoiceLineId == JobInvoiceLineId select new { SalesTaxGroupPersonId = (int?)L.JobInvoiceHeader.SalesTaxGroupPerson.ChargeGroupPersonId ?? 0 }).FirstOrDefault();
                    if (SalesTaxGroupPerson != null)
                    {
                        CalculationId = new ChargeGroupPersonCalculationService(_unitOfWork).GetChargeGroupPersonCalculation(Header.DocTypeId, SalesTaxGroupPerson.SalesTaxGroupPersonId, Header.SiteId, Header.DivisionId) ?? 0;
                    }
                    if (CalculationId == 0)
                    {
                        CalculationId = settings.CalculationId ?? 0;
                    }


                    foreach (var item in SelectedJobInvoices)
                    {
                        if (item.Rate - JobInvoiceBalanceRecords.Where(m => m.JobInvoiceLineId == item.JobInvoiceLineId).FirstOrDefault().Rate != 0)
                        {
                            JobInvoiceRateAmendmentLine line = new JobInvoiceRateAmendmentLine();

                            line.JobInvoiceAmendmentHeaderId = Header.JobInvoiceAmendmentHeaderId;
                            line.JobInvoiceLineId            = item.JobInvoiceLineId;
                            line.Qty            = JobInvoiceBalanceRecords.Where(m => m.JobInvoiceLineId == item.JobInvoiceLineId).FirstOrDefault().BalanceQty;
                            line.AmendedRate    = item.Rate;
                            line.Rate           = line.AmendedRate - JobInvoiceBalanceRecords.Where(m => m.JobInvoiceLineId == item.JobInvoiceLineId).FirstOrDefault().Rate;
                            line.Amount         = JobInvoiceBalanceRecords.Where(m => m.JobInvoiceLineId == item.JobInvoiceLineId).FirstOrDefault().BalanceQty *JobInvoiceRecords.Where(m => m.JobInvoiceLineId == item.JobInvoiceLineId).FirstOrDefault().UnitConversionMultiplier *line.Rate;
                            line.Amount         = DecimalRoundOff.amountToFixed(line.Amount, settings.AmountRoundOff);
                            line.JobInvoiceRate = JobInvoiceBalanceRecords.Where(m => m.JobInvoiceLineId == item.JobInvoiceLineId).FirstOrDefault().Rate;
                            line.JobWorkerId    = JobInvoiceBalanceRecords.Where(m => m.JobInvoiceLineId == item.JobInvoiceLineId).FirstOrDefault().JobWorkerId;
                            line.Sr             = Serial++;
                            line.JobInvoiceRateAmendmentLineId = pk;
                            line.CreatedDate  = DateTime.Now;
                            line.ModifiedDate = DateTime.Now;
                            line.CreatedBy    = User.Identity.Name;
                            line.ModifiedBy   = User.Identity.Name;
                            LineStatus.Add(line.JobInvoiceLineId, line.Rate);
                            RefIds.Add(new LineReferenceIds {
                                LineId = line.JobInvoiceRateAmendmentLineId, RefLineId = line.JobInvoiceLineId
                            });

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

                            LineList.Add(new LineDetailListViewModel {
                                Amount = line.Amount, Rate = line.Rate, LineTableId = line.JobInvoiceRateAmendmentLineId, HeaderTableId = Header.JobInvoiceAmendmentHeaderId, PersonID = line.JobWorkerId, DealQty = 0
                            });

                            pk++;
                        }
                    }

                    //new JobInvoiceLineStatusService(_unitOfWork).UpdateJobRateOnAmendmentMultiple(LineStatus, pt.DocDate, ref db);


                    int[] RecLineIds = null;
                    RecLineIds = RefIds.Select(m => m.RefLineId).ToArray();

                    var Charges = (from p in db.JobInvoiceLine
                                   where RecLineIds.Contains(p.JobInvoiceLineId)
                                   join LineCharge in db.JobInvoiceLineCharge on p.JobInvoiceLineId equals LineCharge.LineTableId
                                   join HeaderCharge in db.JobInvoiceHeaderCharges on p.JobInvoiceHeaderId equals HeaderCharge.HeaderTableId
                                   group new { p, LineCharge, HeaderCharge } by new { p.JobInvoiceLineId } into g
                                   select new
                    {
                        LineId = g.Key.JobInvoiceLineId,
                        HeaderCharges = g.Select(m => m.HeaderCharge).ToList(),
                        Linecharges = g.Select(m => m.LineCharge).ToList(),
                    }).ToList();



                    var LineListWithReferences = (from p in LineList
                                                  join t in RefIds on p.LineTableId equals t.LineId
                                                  join t2 in Charges on t.RefLineId equals t2.LineId into table
                                                  from LineLis in table.DefaultIfEmpty()
                                                  orderby p.LineTableId
                                                  select new LineDetailListViewModel
                    {
                        Amount = p.Amount,
                        DealQty = p.DealQty,
                        HeaderTableId = p.HeaderTableId,
                        LineTableId = p.LineTableId,
                        PersonID = p.PersonID,
                        Rate = p.Rate,
                        CostCenterId = p.CostCenterId,
                        RLineCharges = (LineLis == null ? null : Mapper.Map <List <LineChargeViewModel> >(LineLis.Linecharges)),
                    }).ToList();


                    if (CalculationId != null)
                    {
                        new ChargesCalculationService(_unitOfWork).CalculateCharges(LineListWithReferences, Header.JobInvoiceAmendmentHeaderId, (int)CalculationId, 0, out LineCharges, out HeaderChargeEdit, out HeaderCharges, "Web.JobInvoiceAmendmentHeaderCharges", "Web.JobInvoiceRateAmendmentLineCharges", out PersonCount, Header.DocTypeId, Header.SiteId, Header.DivisionId);
                    }

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


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



                    try
                    {
                        JobInvoiceAmendmentDocEvents.onWizardSaveEvent(this, new JobEventArgs(Header.JobInvoiceAmendmentHeaderId, EventModeConstants.Add), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                        EventException     = true;
                    }

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

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

                    try
                    {
                        JobInvoiceAmendmentDocEvents.afterWizardSaveEvent(this, new JobEventArgs(Header.JobInvoiceAmendmentHeaderId, EventModeConstants.Add), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                    }

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


                    Session.Remove("RateAmendmentWizardOrders");
                }
                return(RedirectToAction("Index", "JobInvoiceAmendmentHeader", new { id = Header.DocTypeId }).Success("Data saved Successfully"));
            }
            PrepareViewBag(vm.DocTypeId);
            ViewBag.Mode = "Add";
            return(View("Create", vm));
        }
        public ActionResult _CreatePost(SaleOrderLineViewModel svm)
        {
            SaleOrderLine   s    = Mapper.Map <SaleOrderLineViewModel, SaleOrderLine>(svm);
            SaleOrderHeader temp = new SaleOrderHeaderService(_unitOfWork).Find(s.SaleOrderHeaderId);
            //if (Command == "Submit" && (s.ProductId == 0))
            //    return RedirectToAction("Submit", "SaleOrderHeader", new { id = s.SaleOrderHeaderId }).Success("Data saved successfully");

            var settings = new SaleOrderSettingsService(_unitOfWork).GetSaleOrderSettingsForDocument(temp.DocTypeId, temp.DivisionId, temp.SiteId);

            if (svm.Qty <= 0)
            {
                ModelState.AddModelError("Qty", "Please Check Qty");
            }
            else if (svm.Rate <= 0 && settings.isMandatoryRate == true)
            {
                ModelState.AddModelError("Rate", "Please Check Rate");
            }
            else if (svm.Amount <= 0 && settings.isMandatoryRate == true)
            {
                ModelState.AddModelError("Amount", "Please Check Amount");
            }
            if (svm.DueDate < temp.DocDate)
            {
                ModelState.AddModelError("DueDate", "DueDate greater than DocDate");
            }

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

            if (ModelState.IsValid)
            {
                if (svm.SaleOrderLineId <= 0)
                {
                    StockViewModel StockViewModel = new StockViewModel();
                    //Posting in Stock
                    if (settings.isPostedInStock.HasValue && settings.isPostedInStock == true)
                    {
                        StockViewModel.StockHeaderId      = temp.StockHeaderId ?? 0;
                        StockViewModel.DocHeaderId        = temp.SaleOrderHeaderId;
                        StockViewModel.DocLineId          = s.SaleOrderLineId;
                        StockViewModel.DocTypeId          = temp.DocTypeId;
                        StockViewModel.StockHeaderDocDate = temp.DocDate;
                        StockViewModel.StockDocDate       = temp.DocDate;
                        StockViewModel.DocNo              = temp.DocNo;
                        StockViewModel.DivisionId         = temp.DivisionId;
                        StockViewModel.SiteId             = temp.SiteId;
                        StockViewModel.CurrencyId         = null;
                        StockViewModel.HeaderProcessId    = null;
                        StockViewModel.PersonId           = temp.SaleToBuyerId;
                        StockViewModel.ProductId          = s.ProductId;
                        StockViewModel.HeaderFromGodownId = null;
                        StockViewModel.HeaderGodownId     = null;
                        StockViewModel.GodownId           = temp.GodownId ?? 0;
                        StockViewModel.ProcessId          = null;
                        StockViewModel.LotNo              = null;
                        StockViewModel.CostCenterId       = null;
                        StockViewModel.Qty_Iss            = 0;
                        StockViewModel.Qty_Rec            = s.Qty;
                        StockViewModel.Rate          = s.Rate;
                        StockViewModel.ExpiryDate    = null;
                        StockViewModel.Specification = s.Specification;
                        StockViewModel.Dimension1Id  = s.Dimension1Id;
                        StockViewModel.Dimension2Id  = s.Dimension2Id;
                        StockViewModel.Dimension3Id  = s.Dimension3Id;
                        StockViewModel.Dimension4Id  = s.Dimension4Id;
                        StockViewModel.Remark        = s.Remark;
                        StockViewModel.ProductUidId  = null;
                        StockViewModel.Status        = temp.Status;
                        StockViewModel.CreatedBy     = temp.CreatedBy;
                        StockViewModel.CreatedDate   = DateTime.Now;
                        StockViewModel.ModifiedBy    = temp.ModifiedBy;
                        StockViewModel.ModifiedDate  = DateTime.Now;

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

                        if (StockPostingError != "")
                        {
                            ModelState.AddModelError("", StockPostingError);
                            return(PartialView("_Create", svm));
                        }

                        s.StockId = StockViewModel.StockId;

                        if (temp.StockHeaderId == null)
                        {
                            temp.StockHeaderId = StockViewModel.StockHeaderId;
                        }
                    }

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

                    new SaleOrderLineStatusService(_unitOfWork).CreateLineStatus(s.SaleOrderLineId);

                    SaleOrderHeader header = new SaleOrderHeaderService(_unitOfWork).Find(s.SaleOrderHeaderId);

                    if (temp.StockHeaderId != null && temp.StockHeaderId != 0)
                    {
                        header.StockHeaderId = temp.StockHeaderId;
                    }

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

                    new SaleOrderHeaderService(_unitOfWork).Update(header);


                    try
                    {
                        _unitOfWork.Save();
                    }

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

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


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


                    SaleOrderHeader header    = new SaleOrderHeaderService(_unitOfWork).Find(svm.SaleOrderHeaderId);
                    StringBuilder   logstring = new StringBuilder();
                    int             status    = header.Status;
                    SaleOrderLine   temp1     = _SaleOrderLineService.Find(svm.SaleOrderLineId);

                    SaleOrderLine ExRec = new SaleOrderLine();
                    ExRec = Mapper.Map <SaleOrderLine>(temp1);

                    //End of Tracking the Modifications::


                    if (temp1.StockId != null)
                    {
                        StockViewModel StockViewModel = new StockViewModel();
                        StockViewModel.StockHeaderId      = temp.StockHeaderId ?? 0;
                        StockViewModel.StockId            = temp1.StockId ?? 0;
                        StockViewModel.DocHeaderId        = temp1.SaleOrderHeaderId;
                        StockViewModel.DocLineId          = temp1.SaleOrderLineId;
                        StockViewModel.DocTypeId          = temp.DocTypeId;
                        StockViewModel.StockHeaderDocDate = temp.DocDate;
                        StockViewModel.StockDocDate       = temp.DocDate;
                        StockViewModel.DocNo              = temp.DocNo;
                        StockViewModel.DivisionId         = temp.DivisionId;
                        StockViewModel.SiteId             = temp.SiteId;
                        StockViewModel.CurrencyId         = null;
                        StockViewModel.HeaderProcessId    = null;
                        StockViewModel.PersonId           = temp.SaleToBuyerId;
                        StockViewModel.ProductId          = s.ProductId;
                        StockViewModel.HeaderFromGodownId = null;
                        StockViewModel.HeaderGodownId     = temp.GodownId;
                        StockViewModel.GodownId           = temp.GodownId ?? 0;
                        StockViewModel.ProcessId          = null;
                        StockViewModel.LotNo              = null;
                        StockViewModel.CostCenterId       = null;
                        StockViewModel.Qty_Iss            = 0;
                        StockViewModel.Qty_Rec            = s.Qty;
                        StockViewModel.Rate          = temp1.Rate;
                        StockViewModel.ExpiryDate    = null;
                        StockViewModel.Specification = temp1.Specification;
                        StockViewModel.Dimension1Id  = temp1.Dimension1Id;
                        StockViewModel.Dimension2Id  = temp1.Dimension2Id;
                        StockViewModel.Dimension3Id  = temp1.Dimension3Id;
                        StockViewModel.Dimension4Id  = temp1.Dimension4Id;
                        StockViewModel.Remark        = s.Remark;
                        StockViewModel.ProductUidId  = null;
                        StockViewModel.Status        = temp.Status;
                        StockViewModel.CreatedBy     = temp1.CreatedBy;
                        StockViewModel.CreatedDate   = temp1.CreatedDate;
                        StockViewModel.ModifiedBy    = User.Identity.Name;
                        StockViewModel.ModifiedDate  = DateTime.Now;

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

                        if (StockPostingError != "")
                        {
                            ModelState.AddModelError("", StockPostingError);
                            return(PartialView("_Create", svm));
                        }
                    }

                    temp1.DueDate                  = svm.DueDate;
                    temp1.ProductId                = svm.ProductId ?? 0;
                    temp1.Specification            = svm.Specification;
                    temp1.Dimension1Id             = svm.Dimension1Id;
                    temp1.Dimension2Id             = svm.Dimension2Id;
                    temp1.Dimension3Id             = svm.Dimension3Id;
                    temp1.Dimension4Id             = svm.Dimension4Id;
                    temp1.Qty                      = svm.Qty ?? 0;
                    temp1.DealQty                  = svm.DealQty ?? 0;
                    temp1.DealUnitId               = svm.DealUnitId;
                    temp1.UnitConversionMultiplier = svm.UnitConversionMultiplier;
                    temp1.Rate                     = svm.Rate ?? 0;
                    temp1.Amount                   = svm.Amount ?? 0;
                    temp1.Remark                   = svm.Remark;
                    temp1.ModifiedDate             = DateTime.Now;
                    temp1.ModifiedBy               = User.Identity.Name;
                    _SaleOrderLineService.Update(temp1);

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

                    if (header.Status != (int)StatusConstants.Drafted && header.Status != (int)StatusConstants.Import)
                    {
                        header.Status       = (int)StatusConstants.Modified;
                        header.ModifiedBy   = User.Identity.Name;
                        header.ModifiedDate = DateTime.Now;
                        new SaleOrderHeaderService(_unitOfWork).Update(header);
                    }
                    XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);
                    try
                    {
                        _unitOfWork.Save();
                    }

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

                    //Saving the Activity Log

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

                    //End of Saving the Activity Log

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

            ViewBag.Status = temp.Status;
            PrepareViewBag(temp);
            return(PartialView("_Create", svm));
        }
Exemplo n.º 29
0
        public ActionResult Post(ProductUid vm)
        {
            ProductUid pt = vm;

            ViewBag.id = vm.GenDocTypeId;
            if (vm.ProductUIDId <= 0)
            {
                var Test = (from p in db.ProductUid where p.ProductUidName == pt.ProductUidName && p.ProductId == pt.ProductId && p.GenDocTypeId == pt.GenDocTypeId select p).ToList();
                if (Test.Count() > 0)
                {
                    ModelState.AddModelError("ProductUidName", "Already Exist");
                }
            }
            else
            {
                var Test = (from p in db.ProductUid where p.ProductUidName == pt.ProductUidName && p.ProductId == pt.ProductId && p.GenDocTypeId == pt.GenDocTypeId && p.ProductUIDId != pt.ProductUIDId select p).ToList();
                if (Test.Count() > 0)
                {
                    ModelState.AddModelError("ProductUidName", "Already Exist");
                }
            }
            if (ModelState.IsValid)
            {
                if (vm.ProductUIDId <= 0)
                {
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;
                    _ProductUidService.Create(pt);

                    ActivityLog log = new ActivityLog()
                    {
                        ActivityType = (int)(ActivityTypeContants.Added),
                        CreatedBy    = User.Identity.Name,
                        CreatedDate  = DateTime.Now,
                        DocId        = pt.ProductUIDId,
                        DocTypeId    = pt.GenDocTypeId,
                        Narration    = "Machine Name" + pt.ProductUidName,
                    };

                    try
                    {
                        _unitOfWork.Save();
                    }

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

                    return(RedirectToAction("Index", new { id = vm.GenDocTypeId }).Success("Data saved successfully"));
                }
                else
                {
                    ProductUid temp = _ProductUidService.Find(pt.ProductUIDId);
                    temp.ProductUidName = pt.ProductUidName;
                    temp.IsActive       = pt.IsActive;
                    temp.ModifiedDate   = DateTime.Now;
                    temp.ModifiedBy     = User.Identity.Name;
                    temp.ObjectState    = Model.ObjectState.Modified;
                    _ProductUidService.Update(temp);

                    ActivityLog log = new ActivityLog()
                    {
                        ActivityType = (int)(ActivityTypeContants.Modified),
                        CreatedBy    = User.Identity.Name,
                        CreatedDate  = DateTime.Now,
                        DocId        = pt.ProductUIDId,
                        DocTypeId    = pt.GenDocTypeId,
                        Narration    = "Machine Name" + pt.ProductUidName,
                    };

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        return(View("Create", pt));
                    }
                    return(RedirectToAction("Index", new { id = vm.GenDocTypeId }).Success("Data saved successfully"));
                }
            }
            return(View("Create", vm));
        }
Exemplo n.º 30
0
        public ActionResult GeneratePrints(string ActionName, int LedgerAccountGroupId = 0)
        {
            string PrintProcedure = "";


            if (!string.IsNullOrEmpty(ActionName))
            {
                var settings = new TrialBalanceSettingService(_unitOfWork).GetTrailBalanceSetting(User.Identity.Name);

                string SiteId     = settings.SiteIds;
                string DivisionId = settings.DivisionIds;
                string FromDate   = settings.FromDate.HasValue ? settings.FromDate.Value.ToString("dd/MMM/yyyy") : "";
                string ToDate     = settings.ToDate.HasValue ? settings.ToDate.Value.ToString("dd/MMM/yyyy") : "";

                if (ActionName == "BalanceSheet")
                {
                    PrintProcedure = "Web.spBalanceSheet '" + SiteId.ToString() + "','" + DivisionId.ToString() + "','" + FromDate.ToString() + "','" + ToDate.ToString() + "'";
                }
                else if (ActionName == "ProfitAndLoss")
                {
                    PrintProcedure = "Web.spProfitAndLoss '" + SiteId.ToString() + "','" + DivisionId.ToString() + "','" + FromDate.ToString() + "','" + ToDate.ToString() + "'";
                }
                else if (ActionName == "TrialBalanceSummary")
                {
                    PrintProcedure = "Web.spTrialBalanceSummary '" + SiteId.ToString() + "','" + DivisionId.ToString() + "','" + FromDate.ToString() + "','" + ToDate.ToString() + "'";
                }
                else if (ActionName == "TrialBalance")
                {
                    PrintProcedure = "Web.spTrialBalance '" + SiteId.ToString() + "','" + DivisionId.ToString() + "','" + ToDate.ToString() + "'";
                }
                else if (ActionName == "SubTrialBalanceSummary")
                {
                    if (LedgerAccountGroupId == 0)
                    {
                        PrintProcedure = "Web.spSubTrialBalanceSummary '" + SiteId.ToString() + "','" + DivisionId.ToString() + "','" + FromDate.ToString() + "','" + ToDate.ToString() + "'";
                    }
                    else
                    {
                        PrintProcedure = "Web.spSubTrialBalanceSummary '" + SiteId.ToString() + "','" + DivisionId.ToString() + "','" + FromDate.ToString() + "','" + ToDate.ToString() + "','" + LedgerAccountGroupId.ToString() + "'";
                    }
                }
                else if (ActionName == "SubTrialBalance")
                {
                    if (LedgerAccountGroupId == 0)
                    {
                        PrintProcedure = "Web.spSubTrialBalance '" + SiteId.ToString() + "','" + DivisionId.ToString() + "','" + ToDate.ToString() + "'";
                    }
                    else
                    {
                        PrintProcedure = "Web.spSubTrialBalance '" + SiteId.ToString() + "','" + DivisionId.ToString() + "','" + ToDate.ToString() + "','" + LedgerAccountGroupId.ToString() + "'";
                    }
                }
                else if (ActionName == "LedgerBalance")
                {
                    if (LedgerAccountGroupId == 0)
                    {
                        PrintProcedure = "Web.spLedger '" + SiteId.ToString() + "','" + DivisionId.ToString() + "','" + FromDate.ToString() + "','" + ToDate.ToString() + "'";
                    }
                    else
                    {
                        PrintProcedure = "Web.spLedger '" + SiteId.ToString() + "','" + DivisionId.ToString() + "','" + FromDate.ToString() + "','" + ToDate.ToString() + "','" + LedgerAccountGroupId.ToString() + "'";
                    }
                }

                try
                {
                    List <byte[]>     PdfStream = new List <byte[]>();
                    DirectReportPrint drp       = new DirectReportPrint();
                    byte[]            Pdf;
                    Pdf = drp.DirectDocumentPrint(PrintProcedure, User.Identity.Name);
                    PdfStream.Add(Pdf);


                    PdfMerger pm = new PdfMerger();

                    byte[] Merge = pm.MergeFiles(PdfStream);

                    if (Merge != null)
                    {
                        return(File(Merge, "application/pdf"));
                    }
                }

                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    return(Json(new { success = "Error", data = message }, JsonRequestBehavior.AllowGet));
                }


                return(Json(new { success = "Success" }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { success = "Error", data = "No Records Selected." }, JsonRequestBehavior.AllowGet));
        }