public bool DeleteDispatchDetail(DispatchDetail dispatchDetail)
 {
     if (dispatchDetail == null) return false;
     _unitOfWork.DispatchDetailRepository.Delete(dispatchDetail);
     _unitOfWork.Save();
     return true;
 }
Beispiel #2
0
        private static DispatchDetailModel GenerateReceiveDetailModel(DispatchDetail dispatchDetail)
        {
            DispatchDetailModel model = new DispatchDetailModel();

            model.Id         = dispatchDetail.DispatchDetailID;
            model.DispatchID = dispatchDetail.DispatchID;

            model.CommodityID          = dispatchDetail.CommodityID;
            model.Description          = dispatchDetail.Description;
            model.Unit                 = dispatchDetail.UnitID;
            model.RequestedQuantity    = dispatchDetail.RequestedQunatityInUnit;
            model.RequestedQuantityMT  = dispatchDetail.RequestedQuantityInMT;
            model.DispatchedQuantity   = dispatchDetail.DispatchedQuantityInUnit;
            model.DispatchedQuantityMT = dispatchDetail.DispatchedQuantityInMT;

            return(model);
        }
Beispiel #3
0
        /// <summary>
        /// Generates the dispatch detail.
        /// </summary>
        /// <param name="c">The c.</param>
        /// <returns></returns>
        private DispatchDetail GenerateDispatchDetail(DispatchDetailModel c)
        {
            if (c != null)
            {
                DispatchDetail dispatchDetail = new DispatchDetail()
                {
                    CommodityID = c.CommodityID,
                    Description = c.Description,
                    // DispatchDetailID = c.Id,
                    RequestedQuantityInMT = c.RequestedQuantityMT.Value,
                    //DispatchedQuantityInMT = c.DispatchedQuantityMT,
                    //DispatchedQuantityInUnit = c.DispatchedQuantity,
                    RequestedQunatityInUnit = c.RequestedQuantity.Value,
                    UnitID = c.Unit
                };
                if (c.Id.HasValue)
                {
                    dispatchDetail.DispatchDetailID = c.Id.Value;
                }

                return dispatchDetail;
            }
            else
            {
                return null;
            }
        }
Beispiel #4
0
        public void SaveDispatchTransaction(DispatchViewModel dispatchViewModel, Boolean reverse=false)
        {
            int transactionsign = reverse ? -1 : 1;
            Dispatch dispatch;
            if (dispatchViewModel.DispatchID != null)
                dispatch = _unitOfWork.DispatchRepository.FindById(dispatchViewModel.DispatchID.GetValueOrDefault());
            else
            {
                dispatch = new Dispatch();
                dispatch.DispatchID = Guid.NewGuid();
            }

            dispatch.BidNumber = dispatchViewModel.BidNumber;
                dispatch.CreatedDate = dispatchViewModel.CreatedDate;
                dispatch.DispatchAllocationID = dispatchViewModel.DispatchAllocationID;
                dispatch.DispatchDate = dispatchViewModel.DispatchDate;

                dispatch.DispatchedByStoreMan = dispatchViewModel.DispatchedByStoreMan;
                dispatch.DriverName = dispatchViewModel.DriverName;
                dispatch.FDPID = dispatchViewModel.FDPID;
                dispatch.GIN = dispatchViewModel.GIN;
                dispatch.HubID = dispatchViewModel.HubID;
                dispatch.PeriodMonth = dispatchViewModel.Month;
                dispatch.PeriodYear = dispatchViewModel.Year;
                dispatch.PlateNo_Prime = dispatchViewModel.PlateNo_Prime;
                dispatch.PlateNo_Trailer = dispatchViewModel.PlateNo_Trailer;
                dispatch.Remark = dispatchViewModel.Remark;
                dispatch.RequisitionNo = dispatchViewModel.RequisitionNo;
                dispatch.Round = dispatchViewModel.Round;
                dispatch.TransporterID = dispatchViewModel.TransporterID;
                dispatch.UserProfileID = dispatchViewModel.UserProfileID;
            dispatch.WeighBridgeTicketNumber = dispatchViewModel.WeighBridgeTicketNumber;

            //dispatch.Type = dispatchViewModel.Type;

            var group = new TransactionGroup();
            group.TransactionGroupID = Guid.NewGuid();

            var dispatchDetail = new DispatchDetail
            {
                DispatchID = dispatch.DispatchID,
                CommodityID = dispatchViewModel.CommodityID,
                CommodityChildID=dispatchViewModel.CommodityChildID,
                Description = dispatchViewModel.Commodity,
                DispatchDetailID = Guid.NewGuid(),
                RequestedQuantityInMT = dispatchViewModel.Quantity,
                RequestedQunatityInUnit = dispatchViewModel.QuantityInUnit,
                QuantityPerUnit = dispatchViewModel.QuantityPerUnit,

                UnitID = dispatchViewModel.UnitID,
                TransactionGroupID = @group.TransactionGroupID
            };

            //var parentCommodityId =
            //    _unitOfWork.CommodityRepository.FindById(dispatchViewModel.CommodityChildID).ParentID ??
            //    dispatchViewModel.CommodityID;
            // Physical movement of stock
            var transactionInTransit = new Transaction
            {
                TransactionID = Guid.NewGuid(),
                AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.FDP, dispatchViewModel.FDPID),
                ProgramID = dispatchViewModel.ProgramID,
                ParentCommodityID = null,
                CommodityID = dispatchViewModel.CommodityID,
                CommodityChildID = dispatchViewModel.CommodityChildID,
                FDPID = dispatchViewModel.FDPID,
                HubID = dispatchViewModel.HubID,
                HubOwnerID = _unitOfWork.HubRepository.FindById(dispatchViewModel.HubID).HubOwnerID,
                LedgerID = Models.Ledger.Constants.GOODS_IN_TRANSIT,
                QuantityInMT = transactionsign * (+ dispatchViewModel.Quantity),
                QuantityInUnit = transactionsign * (+dispatchViewModel.QuantityInUnit),
                ShippingInstructionID = dispatchViewModel.ShippingInstructionID,
                ProjectCodeID = dispatchViewModel.ProjectCodeID,
                Round = dispatchViewModel.Round,
                PlanId = dispatchViewModel.PlanId,
                TransactionDate = DateTime.Now,
                UnitID = dispatchViewModel.UnitID,
                TransactionGroupID = @group.TransactionGroupID
            };
            //transaction2.Stack = dispatchModel.StackNumber;
            //transaction2.StoreID = dispatchModel.StoreID;
            //group.Transactions.Add(transaction2);

            var transactionGoh = new Transaction
            {
                TransactionID = Guid.NewGuid(),
                AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.FDP, dispatchViewModel.FDPID),
                ProgramID = dispatchViewModel.ProgramID,
                ParentCommodityID = null,
                CommodityID = dispatchViewModel.CommodityID,
                CommodityChildID = dispatchViewModel.CommodityChildID,
                FDPID = dispatchViewModel.FDPID,
                HubID = dispatchViewModel.HubID,
                HubOwnerID = _unitOfWork.HubRepository.FindById(dispatchViewModel.HubID).HubOwnerID,
                LedgerID = Models.Ledger.Constants.GOODS_ON_HAND,
                QuantityInMT = transactionsign * (-dispatchViewModel.Quantity),
                QuantityInUnit = transactionsign * (-dispatchViewModel.QuantityInUnit),
                ShippingInstructionID = dispatchViewModel.ShippingInstructionID,
                ProjectCodeID = dispatchViewModel.ProjectCodeID,
                Round = dispatchViewModel.Round,
                PlanId = dispatchViewModel.PlanId,
                TransactionDate = DateTime.Now,
                UnitID = dispatchViewModel.UnitID,
                TransactionGroupID = @group.TransactionGroupID
            };
            //transaction.Stack = dispatch.StackNumber;
            //transaction.StoreID = dispatch.StoreID;

            // plan side of the transaction (Red Border)

            var transactionComitedToFdp = new Transaction
            {
                TransactionID = Guid.NewGuid(),
                AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.FDP, dispatchViewModel.FDPID),
                ProgramID = dispatchViewModel.ProgramID,
                ParentCommodityID = null,
                CommodityID = dispatchViewModel.CommodityID,
                CommodityChildID = dispatchViewModel.CommodityChildID,
                FDPID = dispatchViewModel.FDPID,
                HubID = dispatchViewModel.HubID,
                HubOwnerID = _unitOfWork.HubRepository.FindById(dispatchViewModel.HubID).HubOwnerID,
                LedgerID = Models.Ledger.Constants.COMMITED_TO_FDP,
                QuantityInMT = transactionsign * (+dispatchViewModel.Quantity),
                QuantityInUnit = transactionsign * (+dispatchViewModel.QuantityInUnit),
                ShippingInstructionID = dispatchViewModel.ShippingInstructionID,
                ProjectCodeID = dispatchViewModel.ProjectCodeID,
                Round = dispatchViewModel.Round,
                PlanId = dispatchViewModel.PlanId,
                TransactionDate = DateTime.Now,
                UnitID = dispatchViewModel.UnitID,
                TransactionGroupID = @group.TransactionGroupID
            };
            //transaction2.Stack = dispatchModel.StackNumber;
            //transaction2.StoreID = dispatchModel.StoreID;
            //group.Transactions.Add(transaction2);

            var transactionInTansitFreeStock = new Transaction
            {
                TransactionID = Guid.NewGuid(),
                AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.FDP, dispatchViewModel.FDPID),
                ProgramID = dispatchViewModel.ProgramID,
                ParentCommodityID = null,
                CommodityID = dispatchViewModel.CommodityID,
                CommodityChildID = dispatchViewModel.CommodityChildID,
                FDPID = dispatchViewModel.FDPID,
                HubID = dispatchViewModel.HubID,
                HubOwnerID = _unitOfWork.HubRepository.FindById(dispatchViewModel.HubID).HubOwnerID,
                LedgerID = Cats.Models.Ledger.Constants.STATISTICS_FREE_STOCK,
                QuantityInMT = transactionsign * (-dispatchViewModel.Quantity),
                QuantityInUnit = transactionsign * (-dispatchViewModel.QuantityInUnit),
                ShippingInstructionID = dispatchViewModel.ShippingInstructionID,
                ProjectCodeID = dispatchViewModel.ProjectCodeID,
                Round = dispatchViewModel.Round,
                PlanId = dispatchViewModel.PlanId,
                TransactionDate = DateTime.Now,
                UnitID = dispatchViewModel.UnitID,
                TransactionGroupID = @group.TransactionGroupID
            };
            //transaction.Stack = dispatch.StackNumber;
            //transaction.StoreID = dispatch.StoreID;
            dispatch.DispatchDetails.Clear();
            dispatch.DispatchDetails.Add(dispatchDetail);

            try
            {
                _unitOfWork.TransactionGroupRepository.Add(group);
                _unitOfWork.TransactionRepository.Add(transactionInTransit);
                _unitOfWork.TransactionRepository.Add(transactionGoh);
                _unitOfWork.TransactionRepository.Add(transactionInTansitFreeStock);
                _unitOfWork.TransactionRepository.Add(transactionComitedToFdp);
                if (!reverse)
                {
                    if (dispatchViewModel.DispatchID == null)
                    {
                        _unitOfWork.DispatchRepository.Add(dispatch);
                    }

                    else
                    {
                        _unitOfWork.DispatchRepository.Edit(dispatch);
                    }
                }

            _unitOfWork.Save();

            }

            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);
            }
        }
Beispiel #5
0
        public void SaveDispatchTransaction(DispatchViewModel dispatchViewModel)
        {
            var dispatch = new Dispatch();
            dispatch.BidNumber = dispatchViewModel.BidNumber;
            dispatch.CreatedDate = dispatchViewModel.CreatedDate;
            dispatch.DispatchAllocationID = dispatchViewModel.DispatchAllocationID;
            dispatch.DispatchDate = dispatchViewModel.DispatchDate;
            dispatch.DispatchID = Guid.NewGuid();
            dispatch.DispatchedByStoreMan = dispatchViewModel.DispatchedByStoreMan;
            dispatch.DriverName = dispatchViewModel.DriverName;
            dispatch.FDPID = dispatchViewModel.FDPID;
            dispatch.GIN = dispatchViewModel.GIN;
            dispatch.HubID = dispatchViewModel.HubID;
            dispatch.PeriodMonth = dispatchViewModel.Month;
            dispatch.PeriodYear = dispatchViewModel.Year;
            dispatch.PlateNo_Prime = dispatchViewModel.PlateNo_Prime;
            dispatch.PlateNo_Trailer = dispatchViewModel.PlateNo_Trailer;
            dispatch.Remark = dispatchViewModel.Remark;
            dispatch.RequisitionNo = dispatchViewModel.RequisitionNo;
            dispatch.Round = dispatchViewModel.Round;

            dispatch.TransporterID = dispatchViewModel.TransporterID;
            //dispatch.Type = dispatchViewModel.Type;
            dispatch.UserProfileID = dispatchViewModel.UserProfileID;
            dispatch.WeighBridgeTicketNumber = dispatchViewModel.WeighBridgeTicketNumber;

            TransactionGroup group = new TransactionGroup();
            group.TransactionGroupID = Guid.NewGuid();

            DispatchDetail dispatchDetail = new DispatchDetail();
            dispatchDetail.DispatchID = dispatch.DispatchID;
            dispatchDetail.CommodityID = dispatchViewModel.CommodityID;
            dispatchDetail.Description = dispatchViewModel.Commodity;
            dispatchDetail.DispatchDetailID = Guid.NewGuid();
            dispatchDetail.RequestedQuantityInMT = dispatchViewModel.Quantity;
            dispatchDetail.RequestedQunatityInUnit = dispatchViewModel.QuantityInUnit;
            dispatchDetail.QuantityPerUnit = dispatchViewModel.QuantityPerUnit;
            dispatchDetail.UnitID = dispatchViewModel.UnitID;
            dispatchDetail.TransactionGroupID = group.TransactionGroupID;

                //if (dispatchViewModel.Type == 1)
                //{
                    Transaction transaction2 = new Transaction();
                    transaction2.TransactionID = Guid.NewGuid();
                    transaction2.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.FDP, dispatchViewModel.FDPID);
                    transaction2.ProgramID = dispatchViewModel.ProgramID;
                    transaction2.ParentCommodityID = dispatchViewModel.CommodityID;
                    transaction2.CommodityID = dispatchViewModel.CommodityID;
                    transaction2.HubID = dispatchViewModel.HubID;
                    transaction2.HubOwnerID = _unitOfWork.HubRepository.FindById(dispatchViewModel.HubID).HubOwnerID;
                    transaction2.LedgerID = Ledger.Constants.GOODS_IN_TRANSIT;
                    transaction2.QuantityInMT = +dispatchViewModel.Quantity;
                    transaction2.QuantityInUnit = +dispatchViewModel.QuantityInUnit;
                    transaction2.ShippingInstructionID = dispatchViewModel.ShippingInstructionID;
                    transaction2.ProjectCodeID = dispatchViewModel.ProjectCodeID;
                    transaction2.Round = dispatchViewModel.Round;
                    transaction2.PlanId = dispatchViewModel.PlanId;
                    //transaction2.Stack = dispatchModel.StackNumber;
                    //transaction2.StoreID = dispatchModel.StoreID;
                    transaction2.TransactionDate = DateTime.Now;
                    transaction2.UnitID = dispatchViewModel.UnitID;
                    transaction2.TransactionGroupID = group.TransactionGroupID;
                    //group.Transactions.Add(transaction2);

                    Transaction transaction = new Transaction();
                    transaction.TransactionID = Guid.NewGuid();
                    transaction.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.FDP, dispatchViewModel.FDPID);
                    transaction.ProgramID = dispatchViewModel.ProgramID;
                    transaction.ParentCommodityID = dispatchViewModel.CommodityID;
                    transaction.CommodityID = dispatchViewModel.CommodityID;
                    transaction.HubID = dispatchViewModel.HubID;
                    transaction.HubOwnerID = _unitOfWork.HubRepository.FindById(dispatchViewModel.HubID).HubOwnerID;
                    transaction.LedgerID = Ledger.Constants.GOODS_ON_HAND_UNCOMMITED;
                    transaction.QuantityInMT = -dispatchViewModel.Quantity;
                    transaction.QuantityInUnit = -dispatchViewModel.QuantityInUnit;
                    transaction.ShippingInstructionID = dispatchViewModel.ShippingInstructionID;
                    transaction.ProjectCodeID = dispatchViewModel.ProjectCodeID;
                    transaction.Round = dispatchViewModel.Round;
                    transaction.PlanId = dispatchViewModel.PlanId;
                    //transaction.Stack = dispatch.StackNumber;
                    //transaction.StoreID = dispatch.StoreID;
                    transaction.TransactionDate = DateTime.Now;
                    transaction.UnitID = dispatchViewModel.UnitID;
                    transaction.TransactionGroupID = group.TransactionGroupID;

                    // group.Transactions.Add(transaction);
               // }
                //else
                //{
                //    Transaction transaction2 = GetPositiveHUBTransaction(dispatchModel, dispatch, detail);
                //    group.Transactions.Add(transaction2);

                //    Transaction transaction = GetNegativeHUBTransaction(dispatchModel, dispatch, detail);
                //    group.Transactions.Add(transaction);
                //}

                dispatch.DispatchDetails.Add(dispatchDetail);

               // }
            // Try to save this transaction
            //    db.Database.Connection.Open();
            //  DbTransaction dbTransaction = db.Database.Connection.BeginTransaction();
            try
            {
                _unitOfWork.TransactionGroupRepository.Add(group);
                _unitOfWork.TransactionRepository.Add(transaction2);
                _unitOfWork.TransactionRepository.Add(transaction);
                _unitOfWork.DispatchRepository.Add(dispatch);
                _unitOfWork.Save();
                //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 (dispatchViewModel.Type == 1)
            //{
            //    string sms = dispatchViewModel.GetSMSText();
            //    SMS.SendSMS(dispatchViewModel.FDPID.Value, sms);
            //}
        }
 public bool EditDispatchDetail(DispatchDetail dispatchDetail)
 {
     _unitOfWork.DispatchDetailRepository.Edit(dispatchDetail);
     _unitOfWork.Save();
     return true;
 }
        private static DispatchDetailModel GenerateReceiveDetailModel(DispatchDetail dispatchDetail)
        {
            DispatchDetailModel model = new DispatchDetailModel();
            model.Id = dispatchDetail.DispatchDetailID;
            model.DispatchID = dispatchDetail.DispatchID;

            model.CommodityID = dispatchDetail.CommodityID;
            model.Description = dispatchDetail.Description;
            model.Unit = dispatchDetail.UnitID;
            model.RequestedQuantity = dispatchDetail.RequestedQunatityInUnit;
            model.RequestedQuantityMT = dispatchDetail.RequestedQuantityInMT;
            model.DispatchedQuantity = dispatchDetail.DispatchedQuantityInUnit;
            model.DispatchedQuantityMT = dispatchDetail.DispatchedQuantityInMT;

            return model;
        }