Ejemplo n.º 1
0
        /// <summary>
        /// Generates the dispatch model.
        /// </summary>
        /// <param name="dispatch">The dispatch.</param>
        /// <param name="Repository">The repository.</param>
        /// <returns></returns>
        public static DispatchModel GenerateDispatchModel(Dispatch dispatch, Transaction transactionObj,
                                                          List <Commodity> commodities,
                                                          List <Transporter> transporters,
                                                          List <Unit> units,
                                                          List <FDP> fdps,
                                                          List <Program> programs,
                                                          List <AdminUnit> regions,
                                                          List <AdminUnit> zones,
                                                          List <Store> stores)
        {
            DispatchModel model = new DispatchModel(commodities,
                                                    transporters,
                                                    units,
                                                    fdps,
                                                    programs,
                                                    regions,
                                                    zones,
                                                    stores);

            model.BidNumber            = dispatch.BidNumber;
            model.DispatchDate         = dispatch.DispatchDate;
            model.DispatchID           = dispatch.DispatchID;
            model.DriverName           = dispatch.DriverName;
            model.DispatchedByStoreMan = dispatch.DispatchedByStoreMan;
            model.FDPID           = dispatch.FDPID;
            model.GIN             = dispatch.GIN;
            model.Month           = dispatch.PeriodMonth;
            model.Year            = dispatch.PeriodYear;
            model.PlateNo_Prime   = dispatch.PlateNo_Prime;
            model.PlateNo_Trailer = dispatch.PlateNo_Trailer;
            model.RequisitionNo   = dispatch.RequisitionNo;
            model.Type            = dispatch.Type;
            //model.StackNumber = dispatch.StackNumber;
            //model.StoreID = dispatch.StoreID;
            model.TransporterID = dispatch.TransporterID;
            model.WarehouseID   = dispatch.HubID;
            //model.ProgramID = dispatch.ProgramID;
            model.WeighBridgeTicketNumber = dispatch.WeighBridgeTicketNumber;
            model.Remark = dispatch.Remark;

            model.OtherDispatchAllocationID = dispatch.OtherDispatchAllocationID;
            model.DispatchAllocationID      = dispatch.DispatchAllocationID;

            // model.ProjectNumber = dispatch.ProjectNumber;
            //model.SINumber = dispatch.SINumber;
            //TODO:Check modification have any impact
            Transaction transaction = transactionObj;// Repository.Dispatch.GetDispatchTransaction(dispatch.DispatchID);

            if (transaction != null)
            {
                if (transaction.Stack != null)
                {
                    model.StackNumber = transaction.Stack.Value;
                }
                if (transaction.StoreID.HasValue)
                {
                    model.StoreID = transaction.StoreID.Value;
                }
                model.ProgramID = transaction.ProgramID;
                //model.ProjectNumber = transaction.ProjectCode.Value;
                model.SINumber        = transaction.ShippingInstruction.Value;
                model.CommodityTypeID = transaction.Commodity.CommodityTypeID;
            }
            model.DispatchDetails = DispatchDetailModel.GenerateDispatchDetailModels(dispatch.DispatchDetails);
            return(model);
        }
Ejemplo n.º 2
0
        public ActionResult Create(DispatchModel dispatchModel)
        {
            var user = _userProfileService.GetUser(User.Identity.Name);

            var insertCommodities = new List<DispatchDetailModel>();
            var updateCommodities = new List<DispatchDetailModel>();
            var prevCommodities = new List<DispatchDetailModel>();
            if (dispatchModel.JSONPrev != null)
            {
                prevCommodities = GetSelectedCommodities(dispatchModel.JSONPrev);

                //Even though they are updated they are not saved so move them in to the inserted at the end of a succcessful submit
                int count = 0;
                foreach (var dispatchDetailAllViewModels in prevCommodities)
                {
                    if (dispatchDetailAllViewModels.Id != null)
                    {
                        count--;
                        dispatchDetailAllViewModels.DispatchDetailCounter = count;
                        insertCommodities.Add(dispatchDetailAllViewModels);
                    }
                    else
                    {
                        updateCommodities.Add(dispatchDetailAllViewModels);
                    }
                }

                ViewBag.ReceiveDetails = prevCommodities;
                ViewBag.SelectedCommodities = prevCommodities;
                dispatchModel.DispatchDetails = prevCommodities;

                //this check need's to be revisited
                if (!prevCommodities.Any())
                {
                    ModelState.AddModelError("DispatchDetails", @"Please add atleast one commodity to save this Dispatch");
                }
                string errorMessage = null;
                foreach (var dispatchDetailViewModel in prevCommodities)
                {
                    var validationContext = new ValidationContext(dispatchDetailViewModel, null, null);
                    var validationResults = dispatchDetailViewModel.Validate(validationContext);
                    errorMessage = validationResults.Aggregate(errorMessage, (current, v) => string.Format("{0}, {1}", current, v.ErrorMessage));
                    var comms = _commodityService.FindById(dispatchDetailViewModel.CommodityID);
                    var commType = _commodityTypeService.FindById(dispatchModel.CommodityTypeID);
                    if (dispatchModel.CommodityTypeID != comms.CommodityTypeID)
                        ModelState.AddModelError("DispatchDetails", comms.Name + @" is not of type " + commType.Name);
                }
                if (errorMessage != null)
                {
                    ModelState.AddModelError("DispatchDetails", errorMessage);
                }
            }
            else
            {
                ModelState.AddModelError("DispatchDetails", @"Please add atleast one commodity to save this Dispatch");
            }
            if (dispatchModel.Type != 1)
            {
                ModelState.Remove("FDPID");
                ModelState.Remove("RegionID");
                ModelState.Remove("WoredaID");
                ModelState.Remove("ZoneID");
                ModelState.Remove("BidNumber");
                dispatchModel.BidNumber = "00000";
                //NOT really needed
                ModelState.Remove("Year");
                ModelState.Remove("Month");
            }
            else
            {
                ModelState.Remove("ToHubID");
            }

            if (ModelState.IsValid && user != null)
            {

                if (dispatchModel.ChangeStoreManPermanently)
                {
                    var storeTobeChanged = _storeService.FindById(dispatchModel.StoreID);
                    if (storeTobeChanged != null && dispatchModel.ChangeStoreManPermanently)
                        storeTobeChanged.StoreManName = dispatchModel.DispatchedByStoreMan;
                }
                var dispatch = dispatchModel.GenerateDipatch(user);
                //if (dispatch.DispatchID == null )
                if (dispatchModel.DispatchID == null)
                {

                    dispatchModel.DispatchDetails = prevCommodities;
                    foreach (var gridCommodities in prevCommodities)
                    {
                        if (user.PreferedWeightMeasurment.Equals("qn"))
                        {
                            gridCommodities.DispatchedQuantityMT /= 10;
                            gridCommodities.RequestedQuantityMT /= 10;
                        }
                    }
                    //InsertDispatch(dispatchModel, user);
                    _transactionService.SaveDispatchTransaction(dispatchModel, user);
                }
                else
                {

                    // List<Models.DispatchDetailModel> insertCommodities = GetSelectedCommodities(dispatchModel.JSONInsertedCommodities);
                    var deletedCommodities = GetSelectedCommodities(dispatchModel.JSONDeletedCommodities);
                    // List<Models.DispatchDetailModel> updateCommodities = GetSelectedCommodities(dispatchModel.JSONUpdatedCommodities);
                    dispatch.HubID = user.DefaultHub.Value;
                    dispatch.Update(GenerateDispatchDetail(insertCommodities),
                        GenerateDispatchDetail(updateCommodities),
                        GenerateDispatchDetail(deletedCommodities));

                }

                return RedirectToAction("Index");
            }
            //List<Models.DispatchDetailModel> details = GetSelectedCommodities(dispatchModel.JSONInsertedCommodities);
            //Session["SELCOM"] = details;

            //UserProfile user =UserProfile.GetUser(User.Identity.Name);
            PrepareCreate(dispatchModel.Type);

            if (dispatchModel.FDPID != null)
            {
                PrepareFDPForEdit(dispatchModel.FDPID);
                dispatchModel.WoredaID = _fdpService.FindById(dispatchModel.FDPID.Value).AdminUnitID;
            } //PrepareEdit(dispatchModel.GenerateDipatch(), user,dispatchModel.Type);
            return View(dispatchModel);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Generates the dispatch model.
        /// </summary>
        /// <param name="dispatch">The dispatch.</param>
        /// <param name="Repository">The repository.</param>
        /// <returns></returns>
        public static DispatchModel GenerateDispatchModel(Dispatch dispatch, Transaction transactionObj,
            List<Commodity> commodities,
            List<Transporter> transporters,
            List<Unit> units,
            List<FDP> fdps,
            List<Program> programs,
            List<AdminUnit> regions,
            List<AdminUnit> zones,
            List<Store> stores)
        {
            DispatchModel model = new DispatchModel(commodities,
            transporters,
            units,
            fdps,
            programs,
               regions,
            zones,
              stores);
            model.BidNumber = dispatch.BidNumber;
            model.DispatchDate = dispatch.DispatchDate;
            model.DispatchID = dispatch.DispatchID;
            model.DriverName = dispatch.DriverName;
            model.DispatchedByStoreMan = dispatch.DispatchedByStoreMan;
            model.FDPID = dispatch.FDPID;
            model.GIN = dispatch.GIN;
            model.Month = dispatch.PeriodMonth;
            model.Year = dispatch.PeriodYear;
            model.PlateNo_Prime = dispatch.PlateNo_Prime;
            model.PlateNo_Trailer = dispatch.PlateNo_Trailer;
            model.RequisitionNo = dispatch.RequisitionNo;
            model.Type = dispatch.Type;
            //model.StackNumber = dispatch.StackNumber;
            //model.StoreID = dispatch.StoreID;
            model.TransporterID = dispatch.TransporterID;
            model.WarehouseID = dispatch.HubID;
            //model.ProgramID = dispatch.ProgramID;
            model.WeighBridgeTicketNumber = dispatch.WeighBridgeTicketNumber;
            model.Remark = dispatch.Remark;

            model.OtherDispatchAllocationID = dispatch.OtherDispatchAllocationID;
            model.DispatchAllocationID = dispatch.DispatchAllocationID;

            // model.ProjectNumber = dispatch.ProjectNumber;
            //model.SINumber = dispatch.SINumber;
            //TODO:Check modification have any impact
            Transaction transaction = transactionObj;// Repository.Dispatch.GetDispatchTransaction(dispatch.DispatchID);
            if (transaction != null)
            {
                if (transaction.Stack != null) model.StackNumber = transaction.Stack.Value;
                if (transaction.StoreID.HasValue) model.StoreID = transaction.StoreID.Value;
                model.ProgramID = transaction.ProgramID;
                //model.ProjectNumber = transaction.ProjectCode.Value;
                model.SINumber = transaction.ShippingInstruction.Value;
                model.CommodityTypeID = transaction.Commodity.CommodityTypeID;
            }
            model.DispatchDetails = DispatchDetailModel.GenerateDispatchDetailModels(dispatch.DispatchDetails);
            return model;
        }
Ejemplo n.º 4
0
 //TODO remove this function later
 private void InsertDispatch(DispatchModel dispatchModel, UserProfile user)
 {
     List<DispatchDetailModel> commodities = GetSelectedCommodities(dispatchModel.JSONInsertedCommodities);
     dispatchModel.DispatchDetails = commodities;
     _transactionService.SaveDispatchTransaction(dispatchModel,user);
 }
Ejemplo n.º 5
0
        public ActionResult Create(string ginNo, int type)
        {
            var commodities = _commodityService.GetAllCommodity();
            var transporters = _transporterService.GetAllTransporter();
            var units = _unitService.GetAllUnit();
            var fdps = _fdpService.GetAllFDP();
            var programs = _programService.GetAllProgram();
            var regions = _adminUnitService.GetRegions();
            var zones = _adminUnitService.GetAllAdminUnit().Where(t => t.AdminUnitTypeID == 2).ToList();
            var stores = _storeService.GetAllStore();

            ViewBag.Units = _unitService.GetAllUnit();

            var dispatch = _dispatchService.GetDispatchByGIN(ginNo);
            var user = _userProfileService.GetUser(User.Identity.Name);
            if (dispatch != null)
            {
                if (user.DefaultHub != null && user.DefaultHub.Value == dispatch.HubID)
                {
                    PrepareEdit(dispatch, user, type);
                    var transaction = _dispatchService.GetDispatchTransaction(dispatch.DispatchID);
                    var dis = DispatchModel.GenerateDispatchModel(dispatch, transaction, commodities, transporters, units, fdps, programs, regions, zones, stores);
                    return View(dis);
                }
                PrepareCreate(type);
                var comms = new List<DispatchDetailModel>();
                ViewBag.SelectedCommodities = comms;
                var theViewModel = new DispatchModel(commodities, transporters, units,
                    fdps, programs, regions, zones, stores) { Type = type, DispatchDetails = comms };
                ViewBag.Message = "The selected GIN Number doesn't exist on your default warehouse. Try changing your default warehouse.";
                return View(theViewModel);
            }
            else
            {
                PrepareCreate(type);
                var comms = new List<DispatchDetailModel>();
                ViewBag.SelectedCommodities = comms;
                var theViewModel = new DispatchModel(commodities, transporters, units,
                    fdps, programs, regions, zones, stores) { Type = type, DispatchDetails = comms };

                if (Request["type"] != null && Request["allocationId"] != null)
                {
                    var allocationId = Guid.Parse(Request["allocationId"]);
                    var allocationTypeId = Convert.ToInt32(Request["type"]);

                    if (allocationTypeId == 1)//to FDP
                    {
                        DispatchAllocation toFDPDispatchAllocation = _dispatchAllocationService.FindById(allocationId);

                        theViewModel.FDPID = toFDPDispatchAllocation.FDPID;
                        PrepareFDPForEdit(toFDPDispatchAllocation.FDPID);

                        theViewModel.RequisitionNo = toFDPDispatchAllocation.RequisitionNo;
                        theViewModel.BidNumber = toFDPDispatchAllocation.BidRefNo;
                        theViewModel.SINumber = toFDPDispatchAllocation.ShippingInstruction.Value;
                        theViewModel.ProjectNumber = toFDPDispatchAllocation.ProjectCode.Value;

                        theViewModel.CommodityTypeID = toFDPDispatchAllocation.Commodity.CommodityTypeID;
                        ViewBag.CommodityTypeID = new SelectList(_commodityTypeService.GetAllCommodityType(), "CommodityTypeID", "Name", toFDPDispatchAllocation.Commodity.CommodityTypeID);

                        if (toFDPDispatchAllocation.ProgramID.HasValue)
                        {
                            theViewModel.ProgramID = toFDPDispatchAllocation.ProgramID.Value;
                            ViewBag.ProgramID = new SelectList(_programService.GetAllProgram(), "ProgramID", "Name", theViewModel.ProgramID);
                        }
                        if (toFDPDispatchAllocation.TransporterID.HasValue)
                            theViewModel.TransporterID = toFDPDispatchAllocation.TransporterID.Value;
                        ViewBag.TransporterID = new SelectList(_transporterService.GetAllTransporter(), "TransporterID", "Name", theViewModel.TransporterID);
                        if (toFDPDispatchAllocation.Year.HasValue)
                            theViewModel.Year = toFDPDispatchAllocation.Year.Value;
                        var years = (from y in _periodService.GetYears()
                                     select new { Name = y, Id = y }).ToList();
                        ViewBag.Year = new SelectList(years, "Id", "Name");
                        ViewBag.Year = new SelectList(years, "Id", "Name", theViewModel.Year);
                        if (toFDPDispatchAllocation.Month.HasValue)
                            theViewModel.Month = toFDPDispatchAllocation.Month.Value;
                        var months = (from y in _periodService.GetMonths(theViewModel.Year)
                                      select new { Name = y, Id = y }).ToList();
                        ViewBag.Month = new SelectList(months, "Id", "Name", theViewModel.Month);
                        if (toFDPDispatchAllocation.Round.HasValue)
                            theViewModel.Round = toFDPDispatchAllocation.Round.Value;
                        theViewModel.DispatchAllocationID = toFDPDispatchAllocation.DispatchAllocationID;

                    }
                    else //allocationTypeId == 2
                    {
                        var otherDispatchAllocation = _otherDispatchAllocationService.FindById(allocationId);
                        theViewModel.ToHubID = otherDispatchAllocation.ToHubID;
                        theViewModel.SINumber = otherDispatchAllocation.ShippingInstruction.Value;
                        theViewModel.ProjectNumber = otherDispatchAllocation.ProjectCode.Value;
                        theViewModel.ProgramID = otherDispatchAllocation.ProgramID;

                        theViewModel.CommodityTypeID = otherDispatchAllocation.Commodity.CommodityTypeID;
                        ViewBag.CommodityTypeID = new SelectList(_commodityTypeService.GetAllCommodityType(), "CommodityTypeID", "Name", otherDispatchAllocation.Commodity.CommodityTypeID);

                        ViewBag.ProgramID = new SelectList(_programService.GetAllProgram(), "ProgramID", "Name", theViewModel.ProgramID);
                        theViewModel.OtherDispatchAllocationID = otherDispatchAllocation.OtherDispatchAllocationID;
                    }

                }

                return View(theViewModel);
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Gets the negative HUB Transaction.
 /// </summary>
 /// <param name="dispatchModel">The dispatch model.</param>
 /// <param name="dispatch">The dispatch.</param>
 /// <param name="detail">The detail.</param>
 /// <returns></returns>
 private Transaction GetStatisticsHUBTransaction(DispatchModel dispatchModel, Dispatch dispatch, DispatchDetailModel detail)
 {
     Transaction transaction = new Transaction();
     transaction.TransactionID = Guid.NewGuid();
     transaction.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.HUB, dispatch.HubID);
     transaction.ProgramID = dispatchModel.ProgramID;
     transaction.ParentCommodityID = detail.CommodityID;
     transaction.CommodityID = detail.CommodityID;
     transaction.HubID = dispatch.HubID;
     transaction.HubOwnerID = _unitOfWork.HubRepository.FindById(dispatch.HubID).HubOwnerID;
     transaction.LedgerID = Cats.Models.Ledger.Constants.STATISTICS_FREE_STOCK;
     transaction.QuantityInMT = -detail.DispatchedQuantityMT.Value;
     transaction.QuantityInUnit = -detail.DispatchedQuantity.Value;
     transaction.ShippingInstructionID = _shippingInstructionService.GetShipingInstructionId(dispatchModel.SINumber);
     //transaction.ProjectCodeID = _projectCodeService.GetProjectCodeId(dispatchModel.ProjectNumber);
     transaction.Stack = dispatchModel.StackNumber;
     transaction.StoreID = dispatchModel.StoreID;
     transaction.TransactionDate = DateTime.Now;
     transaction.UnitID = detail.Unit;
     return transaction;
 }
Ejemplo n.º 7
0
        private Transaction GetGoodsOnHandHUBTransaction(DispatchModel dispatchModel, Dispatch dispatch, DispatchDetailModel detail)
        {
            Transaction transaction2 = new Transaction();
            transaction2.TransactionID = Guid.NewGuid();
            transaction2.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.HUB, dispatchModel.ToHubID.Value);
            transaction2.ProgramID = dispatchModel.ProgramID;
            transaction2.ParentCommodityID = detail.CommodityID;
            transaction2.CommodityID = detail.CommodityID;
            transaction2.HubID = dispatch.HubID;
            transaction2.HubOwnerID = _unitOfWork.HubRepository.FindById(dispatch.HubID).HubOwnerID;
            transaction2.LedgerID = Cats.Models.Ledger.Constants.GOODS_ON_HAND; //Previously GOODS_ON_HAND_UNCOMMITED
            transaction2.QuantityInMT = -detail.DispatchedQuantityMT.Value;
            transaction2.QuantityInUnit = -detail.DispatchedQuantity.Value;
            transaction2.ShippingInstructionID = _shippingInstructionService.GetShipingInstructionId(dispatchModel.SINumber);

            transaction2.ProjectCodeID = _projectCodeService.GetProjectCodeId(dispatchModel.ProjectNumber);
            transaction2.Stack = dispatchModel.StackNumber;
            transaction2.StoreID = dispatchModel.StoreID;
            transaction2.TransactionDate = DateTime.Now;
            transaction2.UnitID = detail.Unit;
            return transaction2;
        }
Ejemplo n.º 8
0
 private Transaction GetCommitedToFDPTransaction(DispatchModel dispatchModel, Dispatch dispatch, DispatchDetailModel detail)
 {
     Transaction transaction = new Transaction();
     transaction.TransactionID = Guid.NewGuid();
     transaction.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.FDP, dispatch.FDPID.Value);
     transaction.ProgramID = dispatchModel.ProgramID;
     transaction.ParentCommodityID = detail.CommodityID;
     transaction.CommodityID = detail.CommodityID;
     transaction.HubID = dispatch.HubID;
     transaction.HubOwnerID = _unitOfWork.HubRepository.FindById(dispatch.HubID).HubOwnerID;
     transaction.LedgerID = Cats.Models.Ledger.Constants.COMMITED_TO_FDP;
     transaction.QuantityInMT = +detail.DispatchedQuantityMT.Value;
     transaction.QuantityInUnit = +detail.DispatchedQuantity.Value;
     transaction.ShippingInstructionID = _shippingInstructionService.GetShipingInstructionId(dispatchModel.SINumber);
     transaction.ProjectCodeID = _projectCodeService.GetProjectCodeId(dispatchModel.ProjectNumber);
     transaction.Stack = dispatchModel.StackNumber;
     transaction.StoreID = dispatchModel.StoreID;
     transaction.TransactionDate = DateTime.Now;
     transaction.UnitID = detail.Unit;
     return transaction;
 }
Ejemplo n.º 9
0
        //used to return void
        /// <summary>
        /// Saves the dispatch transaction.
        /// </summary>
        /// <param name="dispatchModel">The dispatch model.</param>
        /// <param name="user">The user.</param>
        public bool SaveDispatchTransaction(DispatchModel dispatchModel, UserProfile user)
        {
            Dispatch dispatch = dispatchModel.GenerateDipatch(user);
            dispatch.DispatchID = Guid.NewGuid();
            dispatch.HubID = user.DefaultHub.Value;
            dispatch.UserProfileID = user.UserProfileID;
            dispatch.DispatchAllocationID = dispatchModel.DispatchAllocationID;
            dispatch.OtherDispatchAllocationID = dispatchModel.OtherDispatchAllocationID;
            CommodityType commType = _unitOfWork.CommodityTypeRepository.FindById(dispatchModel.CommodityTypeID);

            foreach (DispatchDetailModel detail in dispatchModel.DispatchDetails)
            {

                if (commType.CommodityTypeID == 2)//if it's a non food
                {
                    detail.DispatchedQuantityMT = 0;
                    detail.RequestedQuantityMT = 0;
                }

                TransactionGroup group = new TransactionGroup();
                group.TransactionGroupID = Guid.NewGuid();
                if (dispatchModel.Type == 1)
                {
                    Transaction transaction = GetGoodsOnHandFDPTransaction(dispatchModel, dispatch, detail);
                    group.Transactions.Add(transaction);

                    Transaction transaction2 = GetGoodsInTransitFDPTransaction(dispatchModel, dispatch, detail);
                    group.Transactions.Add(transaction2);

                    Transaction transaction3 = GetStatisticsFDPTransaction(dispatchModel, dispatch, detail);
                    group.Transactions.Add(transaction3);

                    Transaction transaction4 = GetCommitedToFDPTransaction(dispatchModel, dispatch, detail);
                    group.Transactions.Add(transaction4);
                }
                else
                {
                    Transaction transaction = GetGoodsOnHandHUBTransaction(dispatchModel, dispatch, detail);
                    group.Transactions.Add(transaction);

                    Transaction transaction2 = GetGoodInTransitHUBTransaction(dispatchModel, dispatch, detail);
                    group.Transactions.Add(transaction2);

                    Transaction transaction3 = GetStatisticsHUBTransaction(dispatchModel, dispatch, detail);
                    group.Transactions.Add(transaction3);

                    Transaction transaction4 = GetCommittedToFDPHUBTransaction(dispatchModel, dispatch, detail);
                    group.Transactions.Add(transaction4);
                }

                DispatchDetail dispatchDetail = GenerateDispatchDetail(detail);
                dispatchDetail.DispatchDetailID = Guid.NewGuid();
                dispatchDetail.TransactionGroup = group;

                dispatch.DispatchDetails.Add(dispatchDetail);

            }
            // Try to save this transaction
            //    db.Database.Connection.Open();
            //  DbTransaction dbTransaction = db.Database.Connection.BeginTransaction();
            try
            {
                _unitOfWork.DispatchRepository.Add(dispatch);
                _unitOfWork.Save();
                return true;
                //repository.Dispatch.Add(dispatch);
                //dbTransaction.Commit();
            }
            catch (Exception exp)
            {
                // dbTransaction.Rollback();
                //TODO: Save the detail of this exception somewhere
                throw new Exception("The Dispatch Transaction Cannot be saved. <br />Detail Message :" + exp.Message);
            }

            if (dispatch.Type == 1)
            {
                string sms = dispatch.GetSMSText();
                //SMS.SendSMS(dispatch.FDPID.Value, sms);
            }
            return false;
        }
Ejemplo n.º 10
0
 //TODO: this section has to be cleaned
 /// <summary>
 /// Gets the positive FDP transaction.
 /// </summary>
 /// <param name="dispatchModel">The dispatch model.</param>
 /// <param name="dispatch">The dispatch.</param>
 /// <param name="detail">The detail.</param>
 /// <returns></returns>
 private Transaction GetGoodsInTransitFDPTransaction(DispatchModel dispatchModel, Dispatch dispatch, DispatchDetailModel detail)
 {
     Transaction transaction2 = new Transaction();
     transaction2.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.FDP, dispatchModel.FDPID.Value);
     transaction2.ProgramID = dispatchModel.ProgramID;
     transaction2.ParentCommodityID = detail.CommodityID;
     transaction2.CommodityID = detail.CommodityID;
     transaction2.HubID = dispatch.HubID;
     transaction2.HubOwnerID = _unitOfWork.HubRepository.FindById(dispatch.HubID).HubOwnerID;
     transaction2.LedgerID = Ledger.Constants.GOODS_IN_TRANSIT;
     transaction2.QuantityInMT = +detail.DispatchedQuantityMT.Value;
     transaction2.QuantityInUnit = +detail.DispatchedQuantity.Value;
     transaction2.ShippingInstructionID = _shippingInstructionService.GetShipingInstructionId(dispatchModel.SINumber);
     transaction2.ProjectCodeID = _projectCodeService.GetProjectCodeId(dispatchModel.ProjectNumber);
     transaction2.Stack = dispatchModel.StackNumber;
     transaction2.StoreID = dispatchModel.StoreID;
     transaction2.TransactionDate = DateTime.Now;
     transaction2.UnitID = detail.Unit;
     return transaction2;
 }