// GET: /ProductMaster/Create

        public ActionResult Create()
        {
            PrepareViewBag();
            LedgerAccountViewModel vm = new LedgerAccountViewModel();

            vm.IsActive = true;
            return(View("Create", vm));
        }
        public ActionResult Modify(int id)
        {
            //LedgerAccount pt = _LedgerAccountService.Find(id);
            LedgerAccountViewModel pt = _LedgerAccountService.GetLedgerAccountForEdit(id);

            if (pt == null)
            {
                return(HttpNotFound());
            }
            PrepareViewBag();
            return(View("Create", pt));
        }
Esempio n. 3
0
        public static LedgerAccountViewModel MakeLedgerAccount(this Account source)
        {
            LedgerAccountViewModel ledgerAccountViewModel = new LedgerAccountViewModel
            {
                AccountId = source.Id,
                Balance   = source.Ballance.ToString("C"),
                Name      = source.Name
            };

            ledgerAccountViewModel.DepositHistory = source.Deposits.MakeDeposits();

            return(ledgerAccountViewModel);
        }
        public IActionResult Add([FromBody] LedgerAccountViewModel lavm)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                // TODO: get the user creating the ledger account
                // get the admin creating the student
                //                var adminId = GetCurrentUserId();
                //                if (adminId == null) return NotFound(new { error = "User is not authenticated." });
                //                var admin = _dbContext.Admins.SingleOrDefault(i => i.Id == adminId);
                //                if (admin == null) return NotFound(new { error = $"User ID {adminId} has not been found" });

                var group = (LedgerAccountGroup)Enum.Parse(typeof(LedgerAccountGroup), lavm.Group);
                var type  = (LedgerAccountType)CommonHelper.GetFirstDigit((int)group);

                var ledgerAccount = new LedgerAccount
                {
                    Name              = lavm.Name,
                    Description       = lavm.Description,
                    Type              = type,
                    Group             = group,
                    ChartOfAccountsId = lavm.ChartOfAccountsId
                };

                _ledgerAccountService.InsertLedgerAccount(ledgerAccount);

                // return the newly-created ledger account to the client.
                return(new JsonResult(Mapper.Map <LedgerAccount, LedgerAccountViewModel>(ledgerAccount),
                                      DefaultJsonSettings));
            }
            catch (Exception)
            {
                // return the error.
                return(BadRequest(new { Error = "Check that all the fields are valid." }));
            }
        }
        public ActionResult Post(LedgerAccountViewModel vm)
        {
            LedgerAccount pt = AutoMapper.Mapper.Map <LedgerAccountViewModel, LedgerAccount>(vm);

            if (ModelState.IsValid)
            {
                if (vm.LedgerAccountId <= 0)
                {
                    Product pt1 = new Product();
                    pt1.ProductName          = vm.LedgerAccountName;
                    pt1.ProductCode          = vm.LedgerAccountSuffix;
                    pt1.ProductDescription   = vm.LedgerAccountName;
                    pt1.ProductGroupId       = new ProductGroupService(_unitOfWork).Find(ProductGroupConstants.LedgerAccount).ProductGroupId;
                    pt1.ProductCategoryId    = null;
                    pt1.ProductSpecification = null;
                    pt1.StandardCost         = 0;
                    pt1.SaleRate             = 0;
                    pt1.Tags   = null;
                    pt1.UnitId = UnitConstants.Nos;
                    pt1.SalesTaxGroupProductId = vm.SalesTaxGroupProductId;
                    pt1.IsActive              = vm.IsActive;
                    pt1.DivisionId            = (int)System.Web.HttpContext.Current.Session["DivisionId"];
                    pt1.ProfitMargin          = 0;
                    pt1.CarryingCost          = 0;
                    pt1.DefaultDimension1Id   = null;
                    pt1.DefaultDimension2Id   = null;
                    pt1.DefaultDimension3Id   = null;
                    pt1.DefaultDimension4Id   = null;
                    pt1.DiscontinueDate       = null;
                    pt1.DiscontinueReason     = null;
                    pt1.SalesTaxProductCodeId = null;
                    pt1.CreatedDate           = DateTime.Now;
                    pt1.ModifiedDate          = DateTime.Now;
                    pt1.CreatedBy             = User.Identity.Name;
                    pt1.ModifiedBy            = User.Identity.Name;
                    pt1.ObjectState           = Model.ObjectState.Added;
                    new ProductService(_unitOfWork).Create(pt1);


                    pt.ProductId    = pt1.ProductId;
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;
                    _LedgerAccountService.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.LedgerAccount).DocumentTypeId,
                        DocId        = pt.LedgerAccountId,
                        ActivityType = (int)ActivityTypeContants.Added,
                    }));


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

                    LedgerAccount temp = _LedgerAccountService.Find(pt.LedgerAccountId);

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

                    temp.LedgerAccountName    = pt.LedgerAccountName;
                    temp.LedgerAccountGroupId = pt.LedgerAccountGroupId;
                    temp.LedgerAccountSuffix  = pt.LedgerAccountSuffix;
                    temp.IsActive             = pt.IsActive;
                    temp.ModifiedDate         = DateTime.Now;
                    temp.ModifiedBy           = User.Identity.Name;
                    temp.ObjectState          = Model.ObjectState.Modified;
                    _LedgerAccountService.Update(temp);


                    if (temp.ProductId != null)
                    {
                        Product pt1 = new ProductService(_unitOfWork).Find((int)temp.ProductId);
                        pt1.ProductName            = vm.LedgerAccountName;
                        pt1.ProductCode            = vm.LedgerAccountSuffix;
                        pt1.ProductDescription     = vm.LedgerAccountName;
                        pt1.SalesTaxGroupProductId = vm.SalesTaxGroupProductId;
                        pt1.IsActive     = vm.IsActive;
                        pt1.ModifiedDate = DateTime.Now;
                        pt1.ModifiedBy   = User.Identity.Name;
                        pt1.ObjectState  = Model.ObjectState.Modified;
                        new ProductService(_unitOfWork).Update(pt1);
                    }


                    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", vm));
                    }

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

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

            PrepareViewBag();
            return(View("Create", vm));
        }