public ActionResult Create(StartingBalanceViewModel startingBalance)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    // TODO: Add insert logic here
                    var user = _userProfileService.GetUser(User.Identity.Name);
                    _transactionService.SaveStartingBalanceTransaction(startingBalance, user);
                    return Json(true, JsonRequestBehavior.AllowGet);

                }
                return View();
            }
            catch
            {
                return View();
            }
        }
        //
        // GET: /StartingBalance/Create
        public ActionResult Create()
        {
            List<Commodity> Commodities;
            List<Program> Programs;
            List<Store> Stores;
            List<Unit> Units;
            List<Donor> Donors;

            var user = _userProfileService.GetUser(User.Identity.Name);

            Commodities = _commodityService.GetAllCommodity().ToList();
            Programs = _programService.GetAllProgram().ToList();
            Stores =_storeService.GetAllStore().Where(h=>h.HubID == user.DefaultHub.HubID).ToList();
            Units = _unitService.GetAllUnit().ToList();
            Donors = _donorSerivce.GetAllDonor().ToList();

            StartingBalanceViewModel startingBalanceViewModel = new StartingBalanceViewModel(Commodities,Stores,Units,Programs,Donors, user);
            return PartialView(startingBalanceViewModel);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Saves the starting balance transaction.
        /// </summary>
        /// <param name="startingBalance">The starting balance.</param>
        /// <param name="user">The user.</param>
        /// <exception cref="System.Exception"></exception>
        public void SaveStartingBalanceTransaction(StartingBalanceViewModel startingBalance, UserProfile user)
        {
            int repositoryAccountGetAccountIDWithCreateNegative = _accountService.GetAccountIdWithCreate(Account.Constants.DONOR, startingBalance.DonorID); ;
            //TODO:After Implementing ProjectCodeService please return here
            int repositoryProjectCodeGetProjectCodeIdWIthCreateProjectCodeID = 0;//_projectCodeService.GetProjectCodeIdWIthCreate(startingBalance.ProjectNumber).ProjectCodeID; ;
            int repositoryShippingInstructionGetSINumberIdWithCreateShippingInstructionID =_shippingInstructionService.GetSINumberIdWithCreate(startingBalance.SINumber).ShippingInstructionID; ;
            int repositoryAccountGetAccountIDWithCreatePosetive = _accountService.GetAccountIdWithCreate(Account.Constants.HUB, user.DefaultHub.HubID); ;

            TransactionGroup transactionGroup = new TransactionGroup();

            Transaction transactionOne = new Transaction();

            transactionOne.PartitionID = 0;
            transactionOne.LedgerID = Ledger.Constants.GOODS_UNDER_CARE;
            transactionOne.HubOwnerID = user.DefaultHub.HubOwner.HubOwnerID;
            transactionOne.AccountID = repositoryAccountGetAccountIDWithCreateNegative;
            transactionOne.HubID = user.DefaultHub.HubID;
            transactionOne.StoreID = startingBalance.StoreID;
            transactionOne.Stack = startingBalance.StackNumber;
            transactionOne.ProjectCodeID = repositoryProjectCodeGetProjectCodeIdWIthCreateProjectCodeID;
            transactionOne.ShippingInstructionID = repositoryShippingInstructionGetSINumberIdWithCreateShippingInstructionID;
            transactionOne.ProgramID = startingBalance.ProgramID;
            var comm = _unitOfWork.CommodityRepository.FindById(startingBalance.CommodityID);
            transactionOne.ParentCommodityID = (comm.ParentID != null)
                                                       ? comm.ParentID.Value
                                                       : comm.CommodityID;
            transactionOne.CommodityID = startingBalance.CommodityID;
            transactionOne.CommodityGradeID = null;
            transactionOne.QuantityInMT = 0 - startingBalance.QuantityInMT;
            transactionOne.QuantityInUnit = 0 - startingBalance.QuantityInUnit;
            transactionOne.UnitID = startingBalance.UnitID;
            transactionOne.TransactionDate = DateTime.Now;

            Transaction transactionTwo = new Transaction();

            transactionTwo.PartitionID = 0;
            transactionTwo.LedgerID = Ledger.Constants.GOODS_ON_HAND_UNCOMMITED;
            transactionTwo.HubOwnerID = user.DefaultHub.HubOwnerID;
            transactionTwo.AccountID = repositoryAccountGetAccountIDWithCreatePosetive;
            transactionTwo.HubID = user.DefaultHub.HubID;
            transactionTwo.StoreID = startingBalance.StoreID;
            transactionTwo.Stack = startingBalance.StackNumber;
            transactionTwo.ProjectCodeID = repositoryProjectCodeGetProjectCodeIdWIthCreateProjectCodeID;
            transactionTwo.ShippingInstructionID = repositoryShippingInstructionGetSINumberIdWithCreateShippingInstructionID;
            transactionTwo.ProgramID = startingBalance.ProgramID;
            transactionTwo.ParentCommodityID = (comm.ParentID != null)
                                                       ? comm.ParentID.Value
                                                       : comm.CommodityID;
            transactionTwo.CommodityID = startingBalance.CommodityID;
            transactionTwo.CommodityGradeID = null; // How did I get this value ?
            transactionTwo.QuantityInMT = startingBalance.QuantityInMT;
            transactionTwo.QuantityInUnit = startingBalance.QuantityInUnit;
            transactionTwo.UnitID = startingBalance.UnitID;
            transactionTwo.TransactionDate = DateTime.Now;

            transactionGroup.PartitionID = 0;
            //transactionGroup.Transactions.Add(transactionOne);
            //transactionGroup.Transactions.Add(transactionTwo);
            //db.SaveChanges();
            // Try to save this transaction
            //db.Database.Connection.Open();
            //DbTransaction dbTransaction = db.Database.Connection.BeginTransaction();
            try
            {
                transactionGroup.Transactions.Add(transactionOne);
                transactionGroup.Transactions.Add(transactionTwo);
                _unitOfWork.TransactionGroupRepository.Add(transactionGroup);
                _unitOfWork.Save();
                //repository.TransactionGroup.Add(transactionGroup);
                //dbTransaction.Commit();
            }
            catch (Exception exp)
            {
                //dbTransaction.Rollback();
                //TODO: Save the detail of this exception somewhere
                throw new Exception("The Starting Balance Transaction Cannot be saved. <br />Detail Message :" + exp.Message);
            }
            //throw new NotImplementedException();
        }
        public ActionResult Edit(StartingBalanceViewModel startingBalance)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        public ActionResult Delete(int id, StartingBalanceViewModel startingBalance)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }