コード例 #1
0
 public bool DeleteTransactionGroup(TransactionGroup entity)
 {
     if(entity==null) return false;
        _unitOfWork.TransactionGroupRepository.Delete(entity);
        _unitOfWork.Save();
        return true;
 }
コード例 #2
0
        public void SaveAdjustment(StockAdjustmentViewModel viewModel, UserProfile user,int stockType)
        {
            Commodity commodity = _unitOfWork.CommodityRepository.FindById((int)viewModel.CommodityID);
            int ledgerPlus, LedgerMinus;
            if (stockType == 0)
            {
                LedgerMinus = Cats.Models.Ledger.Constants.GOODS_ON_HAND;
                ledgerPlus = Cats.Models.Ledger.Constants.LOSS_IN_TRANSIT;
            }
            else
            {
                LedgerMinus = Cats.Models.Ledger.Constants.COMMITED_TO_FDP;
                ledgerPlus = Cats.Models.Ledger.Constants.PLEDGED_TO_FDP;
            }

            Adjustment lossAndAdjustment = new Adjustment();
            TransactionGroup transactionGroup = new TransactionGroup();
            Transaction transactionOne = new Transaction();

            var transactionGroupId = Guid.NewGuid();

            transactionOne.TransactionID = Guid.NewGuid();
            transactionOne.TransactionGroupID = transactionGroupId;
            transactionOne.LedgerID = LedgerMinus;// 2;
            transactionOne.HubOwnerID = user.DefaultHubObj.HubOwner.HubOwnerID;
            //transactionOne.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.HUB, user.DefaultHub.Value); //
            transactionOne.HubID = user.DefaultHub.Value;
            transactionOne.StoreID = viewModel.StoreID;  //
            transactionOne.ProjectCodeID = viewModel.ProjectCodeID;
            transactionOne.ShippingInstructionID = viewModel.ShippingInstructionID;

            transactionOne.ParentCommodityID = (commodity.ParentID == null)
                                                       ? commodity.CommodityID
                                                       : commodity.ParentID.Value;
            transactionOne.CommodityID = viewModel.CommodityID;
            transactionOne.ProgramID = viewModel.ProgramID;
            transactionOne.CommodityGradeID = null; // How did I get this value ?

                transactionOne.QuantityInMT = 0-viewModel.QuantityInMT;
                transactionOne.QuantityInUnit =0- viewModel.QuantityInUnit;

            transactionOne.UnitID =1;
            transactionOne.TransactionDate = DateTime.Now;

            Transaction transactionTwo = new Transaction();

            transactionTwo.TransactionID = Guid.NewGuid();
            transactionTwo.TransactionGroupID = transactionGroupId;
            transactionTwo.LedgerID = ledgerPlus;// 14;
            transactionTwo.HubOwnerID = user.DefaultHubObj.HubOwnerID;
            //transactionTwo.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.HUB, user.DefaultHub.Value); //
            transactionTwo.HubID = user.DefaultHub.Value;
            transactionTwo.StoreID = viewModel.StoreID;  //
            transactionTwo.ProjectCodeID = viewModel.ProjectCodeID;
            transactionTwo.ShippingInstructionID = viewModel.ShippingInstructionID;
            transactionTwo.ParentCommodityID = (commodity.ParentID == null)
                                                       ? commodity.CommodityID
                                                       : commodity.ParentID.Value;
            transactionTwo.CommodityID = viewModel.CommodityID;
            transactionTwo.ProgramID = viewModel.ProgramID;
            transactionTwo.CommodityGradeID = null; // How did I get this value ?

                transactionTwo.QuantityInMT = viewModel.QuantityInMT;
                transactionTwo.QuantityInUnit = viewModel.QuantityInUnit;

            transactionTwo.UnitID =1;
            transactionTwo.TransactionDate = DateTime.Now;

            transactionGroup.TransactionGroupID = transactionGroupId;
            transactionGroup.Transactions.Add(transactionOne);
            transactionGroup.Transactions.Add(transactionTwo);

            lossAndAdjustment.PartitionId = 0;
            lossAndAdjustment.AdjustmentID = Guid.NewGuid();
            lossAndAdjustment.TransactionGroupID = transactionGroupId;
            lossAndAdjustment.TransactionGroup = transactionGroup;
            lossAndAdjustment.HubID = user.DefaultHub.Value;
            lossAndAdjustment.AdjustmentReasonID = 7;
            lossAndAdjustment.AdjustmentDirection = "S";
            lossAndAdjustment.AdjustmentDate = DateTime.Now.Date;
            lossAndAdjustment.ApprovedBy = "";
            lossAndAdjustment.Remarks = "Stock take adjustement";
            lossAndAdjustment.UserProfileID = user.UserProfileID;
            lossAndAdjustment.ReferenceNumber = "";
            lossAndAdjustment.StoreManName = "";

            // Try to save this transaction
            try
            {
                _unitOfWork.AdjustmentRepository.Add(lossAndAdjustment);
                _unitOfWork.Save();
            }
            catch (Exception exp)
            {
                // dbTransaction.Rollback();
                //TODO: Save the detail of this exception somewhere
                throw new Exception("The Internal Movement Transaction Cannot be saved. <br />Detail Message :" + exp.Message);
            }
        }
コード例 #3
0
 public bool EditTransactionGroup(TransactionGroup entity)
 {
     _unitOfWork.TransactionGroupRepository.Edit(entity);
        _unitOfWork.Save();
        return true;
 }
コード例 #4
0
ファイル: TransactionService.cs プロジェクト: FishAbe/cats
        /// <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); ;

            int repositoryProjectCodeGetProjectCodeIdWIthCreateProjectCodeID = _projectCodeService.GetProjectCodeIdWIthCreate(startingBalance.ProjectNumber).ProjectCodeID; ;
            int repositoryShippingInstructionGetSINumberIdWithCreateShippingInstructionID = _shippingInstructionService.GetSINumberIdWithCreate(startingBalance.SINumber).ShippingInstructionID; ;
            int repositoryAccountGetAccountIDWithCreatePosetive = _accountService.GetAccountIdWithCreate(Account.Constants.HUB, user.DefaultHub.Value); ;

            TransactionGroup transactionGroup = new TransactionGroup();

            Transaction transactionOne = new Transaction();

            var transactionGroupId = Guid.NewGuid();

            transactionOne.TransactionID = Guid.NewGuid();
            transactionOne.TransactionGroupID = transactionGroupId;
            transactionOne.PartitionId = 0;
            transactionOne.LedgerID = Cats.Models.Ledger.Constants.GOODS_UNDER_CARE;
            transactionOne.HubOwnerID = user.DefaultHubObj.HubOwner.HubOwnerID;
            transactionOne.AccountID = repositoryAccountGetAccountIDWithCreateNegative;
            transactionOne.HubID = user.DefaultHub.Value;
            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.CommodityID = (comm.ParentID != null)
                                                      ? comm.ParentID.Value
                                                      : comm.CommodityID;

            //transactionOne.ParentCommodityID = (comm.ParentID != null)
            //                                           ? comm.ParentID.Value
            //                                           : comm.CommodityID;
            transactionOne.CommodityChildID = 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.TransactionID = Guid.NewGuid();
            transactionTwo.TransactionGroupID = transactionGroupId;
            transactionTwo.PartitionId = 0;
            transactionTwo.LedgerID = Cats.Models.Ledger.Constants.GOODS_ON_HAND;
            transactionTwo.HubOwnerID = user.DefaultHubObj.HubOwnerID;
            transactionTwo.AccountID = repositoryAccountGetAccountIDWithCreatePosetive;
            transactionTwo.HubID = user.DefaultHub.Value;
            transactionTwo.StoreID = startingBalance.StoreID;
            transactionTwo.Stack = startingBalance.StackNumber;
            transactionTwo.ProjectCodeID = repositoryProjectCodeGetProjectCodeIdWIthCreateProjectCodeID;
            transactionTwo.ShippingInstructionID = repositoryShippingInstructionGetSINumberIdWithCreateShippingInstructionID;
            transactionTwo.ProgramID = startingBalance.ProgramID;

            transactionTwo.CommodityID = (comm.ParentID != null)
                                                      ? comm.ParentID.Value
                                                      : comm.CommodityID;

            //transactionTwo.ParentCommodityID = (comm.ParentID != null)
            //                                           ? comm.ParentID.Value
            //                                           : comm.CommodityID;
            transactionTwo.CommodityChildID = 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;

            try
            {
                transactionGroup.TransactionGroupID = transactionGroupId;
                transactionGroup.Transactions.Add(transactionOne);
                transactionGroup.Transactions.Add(transactionTwo);
                _unitOfWork.TransactionGroupRepository.Add(transactionGroup);
                _unitOfWork.Save();

            }
            catch (Exception exp)
            {

                //TODO: Save the detail of this exception somewhere
                throw new Exception("The Starting Balance Transaction Cannot be saved. <br />Detail Message :" + exp.Message);
            }
        }
コード例 #5
0
ファイル: TransactionService.cs プロジェクト: FishAbe/cats
        public bool ReceiptTransactionForLoanFromNGOs(ReceiveNewViewModel viewModel, Boolean reverse = false)
        {
            //Todo: Construct Receive from the viewModel .... refactor
            int transactionsign = reverse ? -1 : 1;

            #region BindReceiveFromViewModel

            Receive receive;

            if (viewModel.ReceiveId == Guid.Empty)
            {
                receive = new Receive();
                receive.ReceiveID = Guid.NewGuid();

            }
            else
            {
                receive = _unitOfWork.ReceiveRepository.FindById(viewModel.ReceiveId);
            }

            receive.GRN = viewModel.Grn;
            receive.CommodityTypeID = viewModel.CommodityTypeId;

            receive.SourceDonorID = viewModel.SourceDonorId;
            receive.ResponsibleDonorID = viewModel.ResponsibleDonorId;

            receive.TransporterID = viewModel.TransporterId > 0 ? viewModel.TransporterId : 1;
            receive.PlateNo_Prime = viewModel.PlateNoPrime;
            receive.PlateNo_Trailer = viewModel.PlateNoTrailer;
            receive.DriverName = viewModel.DriverName;
            receive.WeightBridgeTicketNumber = viewModel.WeightBridgeTicketNumber;
            receive.WeightBeforeUnloading = viewModel.WeightBeforeUnloading;
            receive.WeightAfterUnloading = viewModel.WeightAfterUnloading;

            receive.VesselName = viewModel.VesselName;
            receive.PortName = viewModel.PortName;

            receive.ReceiptDate = viewModel.ReceiptDate;
            receive.CreatedDate = DateTime.Now;
            receive.WayBillNo = viewModel.WayBillNo;
            receive.CommoditySourceID = viewModel.CommoditySourceTypeId;
            receive.ReceivedByStoreMan = viewModel.ReceivedByStoreMan;

            receive.PurchaseOrder = viewModel.PurchaseOrder;
            receive.SupplierName = viewModel.SupplierName;

            receive.Remark = viewModel.Remark;

            receive.ReceiptAllocationID = viewModel.ReceiptAllocationId;
            receive.HubID = viewModel.CurrentHub;
            receive.UserProfileID = viewModel.UserProfileId;
            receive.StoreId = viewModel.StoreId;
            receive.StackNumber = viewModel.StackNumber;
            receive.SourceDonorID = viewModel.SourceDonorId;
            receive.ResponsibleDonorID = viewModel.ResponsibleDonorId;

            #endregion

            //Todo: Construct ReceiveDetail from the viewModel Transaction

            var transactionGroup = new TransactionGroup { TransactionGroupID = Guid.NewGuid() };

            #region transaction for receiveDetail

            //foreach (var receiveDetailNewViewModel in viewModel.ReceiveDetailNewViewModels)
            //{
            //    ReceiveSingleTransaction(viewModel, receiveDetailNewViewModel, receive, transactionGroup);
            //}

            //Tem implantation for one Receive

            //check for non food

            #region

            if (viewModel.CommodityTypeId == 2)
            {
                viewModel.ReceiveDetailNewViewModel.ReceivedQuantityInMt = 0;
                viewModel.ReceiveDetailNewViewModel.SentQuantityInMt = 0;
            }

            #endregion

            //Construct receive detail from viewModel

            #region

            var receiveDetail = new ReceiveDetail
            {
                ReceiveDetailID = Guid.NewGuid(), //Todo: if there is existing id dont give new one

                CommodityID = viewModel.ReceiveDetailNewViewModel.CommodityId,
                CommodityChildID = viewModel.ReceiveDetailNewViewModel.CommodityChildID,
                Description = viewModel.ReceiveDetailNewViewModel.Description,
                SentQuantityInMT = viewModel.ReceiveDetailNewViewModel.SentQuantityInMt,
                SentQuantityInUnit = viewModel.ReceiveDetailNewViewModel.SentQuantityInUnit,
                UnitID = viewModel.ReceiveDetailNewViewModel.UnitId,
                ReceiveID = receive.ReceiveID,
                TransactionGroupID = transactionGroup.TransactionGroupID,
                TransactionGroup = transactionGroup,

            };

            #endregion

            //add to receive
            receive.ReceiveDetails.Clear();
            receive.ReceiveDetails.Add(receiveDetail);

            var parentCommodityId =
                _unitOfWork.CommodityRepository.FindById(viewModel.ReceiveDetailNewViewModel.CommodityId).ParentID ??
                viewModel.ReceiveDetailNewViewModel.CommodityId;

            //get transactionGroup from a a loaned commodity so that we can deduct commodity amount using this transactionGroup.

             Guid? transactionGroupIdForLoan  = _unitOfWork.ReceiveDetailRepository.FindBy(r => r.ReceiveID == viewModel.SelectedGRN).Select(
                    t => t.TransactionGroupID).FirstOrDefault();

            //physical stock movement

            #region

            //transaction for goods on hand

            #region On Positive Side

            var transactionOne = new Transaction
            {
                TransactionID = Guid.NewGuid(),
                TransactionGroupID = transactionGroup.TransactionGroupID,
                TransactionDate = DateTime.Now,
                ParentCommodityID = null,
                CommodityID = receiveDetail.CommodityID,
                CommodityChildID = receiveDetail.CommodityChildID,
                LedgerID = Ledger.Constants.GOODS_ON_HAND,
                //HubOwnerID =
                DonorID = receive.SourceDonorID,
                AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.HUB, receive.HubID),
                ShippingInstructionID =
                    _shippingInstructionService.GetSINumberIdWithCreate(viewModel.SiNumber).ShippingInstructionID,
                ProjectCodeID = _projectCodeService.GetProjectCodeIdWIthCreate(viewModel.ProjectCode).ProjectCodeID,
                HubID = viewModel.CurrentHub,
                UnitID = viewModel.ReceiveDetailNewViewModel.UnitId,
                QuantityInMT = transactionsign * viewModel.ReceiveDetailNewViewModel.ReceivedQuantityInMt,
                QuantityInUnit = transactionsign * viewModel.ReceiveDetailNewViewModel.ReceivedQuantityInUnit,

                //CommodityGradeID =
                ProgramID = viewModel.ProgramId,
                StoreID = viewModel.StoreId,
                Stack = viewModel.StackNumber,
                IsFalseGRN = viewModel.IsFalseGRN
            };
            transactionGroup.Transactions.Add(transactionOne);

            #endregion

            // transaction for goods under care, receivable, liabilities

            #region Negative Side

            var transactionTwo = new Transaction
            {
                TransactionID = Guid.NewGuid(),
                TransactionGroupID = transactionGroupIdForLoan,// transactionGroup.TransactionGroupID,
                TransactionDate = DateTime.Now,
                ParentCommodityID = null,
                CommodityID = receiveDetail.CommodityID,
                CommodityChildID = receiveDetail.CommodityChildID,
                LedgerID = Ledger.Constants.GOODS_ON_HAND,//Ledger.Constants.GOODS_UNDER_CARE,
                AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.HUB,
                        viewModel.SourceHubId.GetValueOrDefault(0)),
                //HubOwnerID =
                DonorID = receive.SourceDonorID, //

                ShippingInstructionID =
                    _shippingInstructionService.GetSINumberIdWithCreate(viewModel.SiNumber).ShippingInstructionID,
                ProjectCodeID = _projectCodeService.GetProjectCodeIdWIthCreate(viewModel.ProjectCode).ProjectCodeID,
                HubID = viewModel.CurrentHub,
                UnitID = viewModel.ReceiveDetailNewViewModel.UnitId,
                QuantityInMT = transactionsign * (-viewModel.ReceiveDetailNewViewModel.ReceivedQuantityInMt),
                QuantityInUnit = transactionsign * (-viewModel.ReceiveDetailNewViewModel.ReceivedQuantityInUnit),

                //CommodityGradeID =
                ProgramID = viewModel.ProgramId,
                StoreID = viewModel.StoreId,
                Stack = viewModel.StackNumber,
                IsFalseGRN = true
            };

            //switch (viewModel.CommoditySourceTypeId)
            //{
            //    case CommoditySource.Constants.LOCALPURCHASE:
            //    case CommoditySource.Constants.DONATION:
            //        transactionTwo.LedgerID = Ledger.Constants.GOODS_UNDER_CARE;
            //        transactionTwo.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.DONOR,
            //            receive.ResponsibleDonorID.GetValueOrDefault(0));
            //        break;
            //    case CommoditySource.Constants.REPAYMENT:
            //        transactionTwo.LedgerID = Ledger.Constants.GOODS_RECIEVABLE;
            //        transactionTwo.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.HUB,
            //            viewModel.SourceHubId.GetValueOrDefault(0));
            //        break;
            //    default:
            //        transactionTwo.LedgerID = Ledger.Constants.LIABILITIES;
            //        transactionTwo.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.HUB,
            //            viewModel.SourceHubId.GetValueOrDefault(0));
            //        break;
            //}

            transactionGroup.Transactions.Add(transactionTwo);

            #endregion

            #endregion

            // plan side

            #region

            #region Positive Side

            //statstics free

            var transactionThree = new Transaction
            {
                TransactionID = Guid.NewGuid(),
                TransactionGroupID = transactionGroup.TransactionGroupID,
                TransactionDate = DateTime.Now,
                ParentCommodityID = null,
                CommodityID = receiveDetail.CommodityID,
                CommodityChildID = receiveDetail.CommodityChildID,
                LedgerID = Ledger.Constants.STATISTICS_FREE_STOCK,
                //HubOwnerID =
                DonorID = receive.SourceDonorID,
                AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.HUB, receive.HubID),
                ShippingInstructionID =
                    _shippingInstructionService.GetSINumberIdWithCreate(viewModel.SiNumber).ShippingInstructionID,
                ProjectCodeID = _projectCodeService.GetProjectCodeIdWIthCreate(viewModel.ProjectCode).ProjectCodeID,
                HubID = viewModel.CurrentHub,
                UnitID = viewModel.ReceiveDetailNewViewModel.UnitId,
                QuantityInMT = transactionsign * viewModel.ReceiveDetailNewViewModel.ReceivedQuantityInMt,
                QuantityInUnit = transactionsign * viewModel.ReceiveDetailNewViewModel.ReceivedQuantityInUnit,

                //CommodityGradeID =
                ProgramID = viewModel.ProgramId,
                StoreID = viewModel.StoreId,
                Stack = viewModel.StackNumber,
                IsFalseGRN = viewModel.IsFalseGRN
            };

            transactionGroup.Transactions.Add(transactionThree);

            #endregion

            #region Negative Side

            var transactionFour = new Transaction
            {
                TransactionID = Guid.NewGuid(),
                TransactionGroupID =transactionGroupIdForLoan,
                TransactionDate = DateTime.Now,
                ParentCommodityID = null,
                CommodityID = receiveDetail.CommodityID,
                CommodityChildID = receiveDetail.CommodityChildID,
                 LedgerID = Ledger.Constants.STATISTICS_FREE_STOCK,
                 AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.HUB,
                    viewModel.SourceHubId.GetValueOrDefault(0)),
                //HubOwnerID =
                DonorID = receive.SourceDonorID,
                ShippingInstructionID =
                    _shippingInstructionService.GetSINumberIdWithCreate(viewModel.SiNumber).ShippingInstructionID,
                ProjectCodeID = _projectCodeService.GetProjectCodeIdWIthCreate(viewModel.ProjectCode).ProjectCodeID,
                HubID = viewModel.CurrentHub,
                UnitID = viewModel.ReceiveDetailNewViewModel.UnitId,
                QuantityInMT = transactionsign * (-viewModel.ReceiveDetailNewViewModel.ReceivedQuantityInMt),
                QuantityInUnit = transactionsign * (-viewModel.ReceiveDetailNewViewModel.ReceivedQuantityInUnit),

                //CommodityGradeID =
                ProgramID = viewModel.ProgramId,
                StoreID = viewModel.StoreId,
                Stack = viewModel.StackNumber,
                IsFalseGRN =true// viewModel.IsFalseGRN
            };

            //if (transactionFour.CommoditySourceID == CommoditySource.Constants.DONATION ||
            //    viewModel.CommoditySourceTypeId == CommoditySource.Constants.LOCALPURCHASE)
            //{
            //    transactionFour.LedgerID = Ledger.Constants.GOODS_UNDER_CARE;
            //    transactionFour.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.DONOR,
            //        receive.ResponsibleDonorID.GetValueOrDefault(0));
            //}
            //else if (transactionFour.CommoditySourceID == CommoditySource.Constants.REPAYMENT)
            //{
            //    transactionFour.LedgerID = Ledger.Constants.GOODS_RECIEVABLE;
            //    transactionFour.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.HUB,
            //        viewModel.SourceHubId.GetValueOrDefault(0));
            //}
            //else
            //{
            //    transactionFour.LedgerID = Ledger.Constants.LIABILITIES;
            //    transactionFour.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.HUB,
            //        viewModel.SourceHubId.GetValueOrDefault(0));
            //}

            transactionGroup.Transactions.Add(transactionFour);

            #endregion

            #endregion

            #endregion

            //Todo: Save Receive

            try
            {
                if (!reverse)
                {
                    if (viewModel.ReceiveId == Guid.Empty)
                    {
                        _unitOfWork.ReceiveRepository.Add(receive);
                    }
                    else
                    {
                        _unitOfWork.ReceiveRepository.Edit(receive);
                    }

                }

                _unitOfWork.Save();
                return true;
            }
            catch (Exception exception)
            {
                throw exception;
            }
        }
コード例 #6
0
ファイル: TransactionService.cs プロジェクト: FishAbe/cats
        /// <summary>
        /// </summary>
        /// <param name="viewModel"></param>
        /// <param name="user"></param>
        /// <exception cref="System.Exception"></exception>
        public void SaveLossTrasnsaction(LossesAndAdjustmentsViewModel viewModel, UserProfile user)
        {
            Commodity commodity = _unitOfWork.CommodityRepository.FindById(viewModel.CommodityId);

            Adjustment lossAndAdjustment = new Adjustment();
            TransactionGroup transactionGroup = new TransactionGroup();
            Transaction transactionOne = new Transaction();

            var transactionGroupId = Guid.NewGuid();

            transactionOne.TransactionID = Guid.NewGuid();
            transactionOne.TransactionGroupID = transactionGroupId;
            transactionOne.LedgerID = Cats.Models.Ledger.Constants.GOODS_ON_HAND;// 2;
            transactionOne.HubOwnerID = user.DefaultHubObj.HubOwner.HubOwnerID;
            transactionOne.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.HUB, user.DefaultHub.Value); //
            transactionOne.HubID = user.DefaultHub.Value;
            transactionOne.StoreID = viewModel.StoreId;  //
            transactionOne.ProjectCodeID = viewModel.ProjectCodeId;
            transactionOne.ShippingInstructionID = viewModel.ShippingInstructionId;

            transactionOne.ParentCommodityID = (commodity.ParentID == null)
                                                       ? commodity.CommodityID
                                                       : commodity.ParentID.Value;
            transactionOne.CommodityID = viewModel.CommodityId;
            transactionOne.ProgramID = viewModel.ProgramId;
            transactionOne.CommodityGradeID = null; // How did I get this value ?
            transactionOne.QuantityInMT = 0 - viewModel.QuantityInMt;
            transactionOne.QuantityInUnit = 0 - viewModel.QuantityInUint;
            transactionOne.UnitID = viewModel.UnitId;
            transactionOne.TransactionDate = DateTime.Now;

            Transaction transactionTwo = new Transaction();

            transactionTwo.TransactionID = Guid.NewGuid();
            transactionTwo.TransactionGroupID = transactionGroupId;
            transactionTwo.LedgerID = Cats.Models.Ledger.Constants.LOSS_IN_TRANSIT;// 14;
            transactionTwo.HubOwnerID = user.DefaultHubObj.HubOwnerID;
            transactionTwo.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.HUB, user.DefaultHub.Value); //
            transactionTwo.HubID = user.DefaultHub.Value;
            transactionTwo.StoreID = viewModel.StoreId;  //
            transactionTwo.ProjectCodeID = viewModel.ProjectCodeId;
            transactionTwo.ShippingInstructionID = viewModel.ShippingInstructionId;
            transactionTwo.ParentCommodityID = (commodity.ParentID == null)
                                                       ? commodity.CommodityID
                                                       : commodity.ParentID.Value;
            transactionTwo.CommodityID = viewModel.CommodityId;
            transactionTwo.ProgramID = viewModel.ProgramId;
            transactionTwo.CommodityGradeID = null; // How did I get this value ?
            transactionTwo.QuantityInMT = viewModel.QuantityInMt;
            transactionTwo.QuantityInUnit = viewModel.QuantityInUint;
            transactionTwo.UnitID = viewModel.UnitId;
            transactionTwo.TransactionDate = DateTime.Now;

            transactionGroup.TransactionGroupID = transactionGroupId;
            transactionGroup.Transactions.Add(transactionOne);
            transactionGroup.Transactions.Add(transactionTwo);

            lossAndAdjustment.PartitionId = 0;
            lossAndAdjustment.AdjustmentID = Guid.NewGuid();
            lossAndAdjustment.TransactionGroupID = transactionGroupId;
            lossAndAdjustment.TransactionGroup = transactionGroup;
            lossAndAdjustment.HubID = user.DefaultHub.Value;
            lossAndAdjustment.AdjustmentReasonID = viewModel.ReasonId;
            lossAndAdjustment.AdjustmentDirection = "L";
            lossAndAdjustment.AdjustmentDate = viewModel.SelectedDate;
            lossAndAdjustment.ApprovedBy = viewModel.ApprovedBy;
            lossAndAdjustment.Remarks = viewModel.Description;
            lossAndAdjustment.UserProfileID = user.UserProfileID;
            lossAndAdjustment.ReferenceNumber = viewModel.MemoNumber;
            lossAndAdjustment.StoreManName = viewModel.StoreMan;

            // Try to save this transaction
            try
            {
                _unitOfWork.AdjustmentRepository.Add(lossAndAdjustment);
                _unitOfWork.Save();
            }
            catch (Exception exp)
            {
                // dbTransaction.Rollback();
                //TODO: Save the detail of this exception somewhere
                throw new Exception("The Internal Movement Transaction Cannot be saved. <br />Detail Message :" + exp.Message);
            }
        }
コード例 #7
0
ファイル: TransactionService.cs プロジェクト: FishAbe/cats
        /// <summary>
        /// Saves the receipt transaction.
        /// </summary>
        /// <param name="receiveModels">The receive models.</param>
        /// <param name="user">The user.</param>
        public Boolean SaveReceiptTransaction(ReceiveViewModel receiveModels, UserProfile user, Boolean reverse=false)
        {
            // Populate more details of the reciept object
            // Save it when you are done.
            int transactionsign = reverse ? -1 : 1;
            Receive receive;

            if(receiveModels.ReceiveID!=null)
            {
                receive = _unitOfWork.ReceiveRepository.FindById(receiveModels.ReceiveID.GetValueOrDefault());
            }
            else
            {
                receive=new Receive();
                receive = receiveModels.GenerateReceive();
            }

            receive.CreatedDate = DateTime.Now;
            receive.HubID = user.DefaultHubObj.HubID;
            receive.UserProfileID = user.UserProfileID;

            int? donorId = receive.SourceDonorID;
            var commType = _unitOfWork.CommodityTypeRepository.FindById(receiveModels.CommodityTypeID);

            // var comms = GenerateReceiveDetail(commodities);

            var transactionGroupId = Guid.NewGuid();

            receive.ReceiveDetails.Clear();

            foreach (ReceiveDetailViewModel c in receiveModels.ReceiveDetails)
            {
                if (commType.CommodityTypeID == 2)//if it's a non food
                {
                    c.ReceivedQuantityInMT = 0;
                    c.SentQuantityInMT = 0;
                }

                TransactionGroup tgroup = new TransactionGroup();
                tgroup.TransactionGroupID = transactionGroupId;
                var receiveDetail = new ReceiveDetail()
                {
                    CommodityID = c.CommodityID,
                    Description = c.Description,
                    SentQuantityInMT = c.SentQuantityInMT.Value,
                    SentQuantityInUnit = c.SentQuantityInUnit.Value,
                    UnitID = c.UnitID,
                    ReceiveID = receive.ReceiveID,
                    ReceiveDetailID = Guid.NewGuid()
                };
                //if (c.ReceiveDetailID.HasValue&&!reverse)
                //{
                //    receiveDetail.ReceiveDetailID = c.ReceiveDetailID.Value;
                //}

                receiveDetail.TransactionGroupID = tgroup.TransactionGroupID;
                receiveDetail.TransactionGroup = tgroup;
                receive.ReceiveDetails.Add(receiveDetail);

                #region physical stock movement
                //transaction for goods on hand // previously it was GOODS_ON_HAND_UNCOMMITED
                var transaction = new Transaction();
                transaction.TransactionID = Guid.NewGuid();
                transaction.TransactionGroupID = transactionGroupId;
                transaction.TransactionDate = DateTime.Now;
                transaction.ParentCommodityID = _unitOfWork.CommodityRepository.FindById(c.CommodityID).ParentID ?? c.CommodityID;
                transaction.CommodityID = c.CommodityID;
                transaction.LedgerID = Cats.Models.Ledger.Constants.GOODS_ON_HAND;
                transaction.HubOwnerID = user.DefaultHubObj.HubOwnerID;

                transaction.DonorID = donorId;

                transaction.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.HUB, receive.HubID);
                transaction.ShippingInstructionID = _shippingInstructionService.GetSINumberIdWithCreate(receiveModels.SINumber).ShippingInstructionID;

                transaction.ProjectCodeID = _projectCodeService.GetProjectCodeIdWIthCreate(receiveModels.ProjectNumber).ProjectCodeID;
                transaction.HubID = user.DefaultHubObj.HubID;
                transaction.UnitID = c.UnitID;
                if (c.ReceivedQuantityInMT != null) transaction.QuantityInMT = transactionsign * c.ReceivedQuantityInMT.Value;
                if (c.ReceivedQuantityInUnit != null) transaction.QuantityInUnit = transactionsign * c.ReceivedQuantityInUnit.Value;
                if (c.CommodityGradeID != null) transaction.CommodityGradeID = c.CommodityGradeID.Value;

                transaction.ProgramID = receiveModels.ProgramID;
                transaction.StoreID = receiveModels.StoreID;
                transaction.Stack = receiveModels.StackNumber;
                transaction.TransactionGroupID = tgroup.TransactionGroupID;
                tgroup.Transactions.Add(transaction);

                var transaction2 = new Transaction();
                transaction2.TransactionID = Guid.NewGuid();
                transaction2.TransactionGroupID = transactionGroupId;
                transaction2.TransactionDate = DateTime.Now;

                transaction2.ParentCommodityID = transaction.ParentCommodityID;
                transaction2.CommodityID = c.CommodityID;
                transaction2.HubOwnerID = user.DefaultHubObj.HubOwnerID;

                transaction2.LedgerID = Cats.Models.Ledger.Constants.GOODS_UNDER_CARE;
                if (receive.ResponsibleDonorID != null)
                    transaction2.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.DONOR, receive.ResponsibleDonorID.Value);

                //Decide from where the -ve side of the transaction comes from
                //it is either from the allocated stock
                // or it is from goods under care.

                // this means that this receipt is done without having gone through the gift certificate process.

                if (receiveModels.CommoditySourceID == CommoditySource.Constants.DONATION || receiveModels.CommoditySourceID == CommoditySource.Constants.LOCALPURCHASE)
                {
                    transaction2.LedgerID = Cats.Models.Ledger.Constants.GOODS_UNDER_CARE;
                    transaction2.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.DONOR, receive.ResponsibleDonorID.Value);
                }
                else if (receiveModels.CommoditySourceID == CommoditySource.Constants.REPAYMENT)
                {
                    transaction2.LedgerID = Cats.Models.Ledger.Constants.GOODS_RECIEVABLE;
                    transaction2.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.HUB, receiveModels.SourceHubID.Value);
                }
                else
                {
                    transaction2.LedgerID = Cats.Models.Ledger.Constants.LIABILITIES;
                    transaction2.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.HUB, receiveModels.SourceHubID.Value);
                }

                transaction2.DonorID = donorId;

                transaction2.ShippingInstructionID = _shippingInstructionService.GetSINumberIdWithCreate(receiveModels.SINumber).ShippingInstructionID;
                transaction2.ProjectCodeID = _projectCodeService.GetProjectCodeIdWIthCreate(receiveModels.ProjectNumber).ProjectCodeID;
                transaction2.HubID = user.DefaultHubObj.HubID;
                transaction2.UnitID = c.UnitID;
                // this is the credit part, so make it Negative
                if (c.ReceivedQuantityInMT != null) transaction2.QuantityInMT = transactionsign*(-c.ReceivedQuantityInMT.Value);
                if (c.ReceivedQuantityInUnit != null) transaction2.QuantityInUnit = transactionsign*(-c.ReceivedQuantityInUnit.Value);
                if (c.CommodityGradeID != null) transaction2.CommodityGradeID = c.CommodityGradeID.Value;

                transaction2.ProgramID = receiveModels.ProgramID;
                transaction2.StoreID = receiveModels.StoreID;
                transaction2.Stack = receiveModels.StackNumber;
                transaction2.TransactionGroupID = tgroup.TransactionGroupID;
                tgroup.Transactions.Add(transaction2);
                #endregion

                #region plan side of the transaction
                //transaction for statistics
                transaction = new Transaction();
                transaction.TransactionID = Guid.NewGuid();
                transaction.TransactionGroupID = transactionGroupId;
                transaction.TransactionDate = DateTime.Now;
                transaction.ParentCommodityID = _unitOfWork.CommodityRepository.FindById(c.CommodityID).ParentID ?? c.CommodityID;
                transaction.CommodityID = c.CommodityID;
                transaction.DonorID = donorId;
                transaction.LedgerID = Cats.Models.Ledger.Constants.STATISTICS_FREE_STOCK;
                transaction.HubOwnerID = user.DefaultHubObj.HubOwnerID;

                transaction.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.HUB, receive.HubID);
                transaction.ShippingInstructionID = _shippingInstructionService.GetSINumberIdWithCreate(receiveModels.SINumber).ShippingInstructionID;

                transaction.ProjectCodeID = _projectCodeService.GetProjectCodeIdWIthCreate(receiveModels.ProjectNumber).ProjectCodeID;
                transaction.HubID = user.DefaultHubObj.HubID;
                transaction.UnitID = c.UnitID;
                if (c.ReceivedQuantityInMT != null) transaction.QuantityInMT = transactionsign*  c.ReceivedQuantityInMT.Value;
                if (c.ReceivedQuantityInUnit != null) transaction.QuantityInUnit = transactionsign * c.ReceivedQuantityInUnit.Value;
                if (c.CommodityGradeID != null) transaction.CommodityGradeID = c.CommodityGradeID.Value;

                transaction.ProgramID = receiveModels.ProgramID;
                transaction.StoreID = receiveModels.StoreID;
                transaction.Stack = receiveModels.StackNumber;
                transaction.TransactionGroupID = tgroup.TransactionGroupID;
                tgroup.Transactions.Add(transaction);

                // transaction for Receivable
                transaction2 = new Transaction();
                transaction2.TransactionID = Guid.NewGuid();
                transaction2.TransactionGroupID = transactionGroupId;
                transaction2.TransactionDate = DateTime.Now;
                //TAKEs the PARENT FROM THE FIRST TRANSACTION
                transaction2.ParentCommodityID = transaction.ParentCommodityID;
                transaction2.CommodityID = c.CommodityID;
                transaction2.DonorID = donorId;
                transaction2.HubOwnerID = user.DefaultHubObj.HubOwnerID;

                transaction2.LedgerID = Cats.Models.Ledger.Constants.GOODS_RECIEVABLE;
                if (receive.ResponsibleDonorID != null)
                    transaction2.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.DONOR, receive.ResponsibleDonorID.Value);

                //Decide from where the -ve side of the transaction comes from
                //it is either from the allocated stock
                // or it is from goods under care.

                // this means that this receipt is done without having gone through the gift certificate process.

                #region "commented out"
                if (receiveModels.CommoditySourceID == CommoditySource.Constants.DONATION || receiveModels.CommoditySourceID == CommoditySource.Constants.LOCALPURCHASE)
                {
                    transaction2.LedgerID = Cats.Models.Ledger.Constants.GOODS_UNDER_CARE;
                    transaction2.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.DONOR, receive.ResponsibleDonorID.Value);
                }
                else if (receiveModels.CommoditySourceID == CommoditySource.Constants.REPAYMENT)
                {
                    transaction2.LedgerID = Cats.Models.Ledger.Constants.GOODS_RECIEVABLE;
                    transaction2.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.HUB, receiveModels.SourceHubID.Value);
                }
                else
                {
                    transaction2.LedgerID = Cats.Models.Ledger.Constants.LIABILITIES;
                    transaction2.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.HUB, receiveModels.SourceHubID.Value);
                }
                #endregion

                transaction2.ShippingInstructionID = _shippingInstructionService.GetSINumberIdWithCreate(receiveModels.SINumber).ShippingInstructionID;
                transaction2.ProjectCodeID = _projectCodeService.GetProjectCodeIdWIthCreate(receiveModels.ProjectNumber).ProjectCodeID;
                transaction2.HubID = user.DefaultHubObj.HubID;
                transaction2.UnitID = c.UnitID;
                // this is the credit part, so make it Negative
                if (c.ReceivedQuantityInMT != null) transaction2.QuantityInMT = transactionsign * (- c.ReceivedQuantityInMT.Value);
                if (c.ReceivedQuantityInUnit != null) transaction2.QuantityInUnit = transactionsign * (-c.ReceivedQuantityInUnit.Value);
                if (c.CommodityGradeID != null) transaction2.CommodityGradeID = c.CommodityGradeID.Value;

                transaction2.ProgramID = receiveModels.ProgramID;
                transaction2.StoreID = receiveModels.StoreID;
                transaction2.Stack = receiveModels.StackNumber;
                transaction2.TransactionGroupID = tgroup.TransactionGroupID;
                // hack to get past same key object in context error
                //repository.Transaction = new TransactionRepository();
                tgroup.Transactions.Add(transaction2);

                #endregion
            }

            try
            {
                if(!reverse)
                {
                    if(receiveModels.ReceiveID==null)
                    {
                        _unitOfWork.ReceiveRepository.Add(receive);
                    }
                    else
                    {
                        _unitOfWork.ReceiveRepository.Edit(receive);
                    }

                }

                _unitOfWork.Save();
                return true;
            }
            catch (Exception exp)
            {
                //TODO: Save the exception somewhere
                throw new Exception("The Receipt Transaction Cannot be saved. <br />Detail Message :" + exp.StackTrace);

            }
        }
コード例 #8
0
ファイル: TransactionService.cs プロジェクト: FishAbe/cats
        /// <summary>
        /// </summary>
        /// <param name="viewModel"></param>
        /// <param name="user"></param>
        /// <exception cref="System.Exception"></exception>
        public void SaveInternalMovementTrasnsaction(InternalMovementViewModel viewModel, UserProfile user)
        {
            InternalMovement internalMovement = new InternalMovement();
            TransactionGroup transactionGroup = new TransactionGroup();
            Transaction transactionFromStore = new Transaction();
            var transactionGroupId = Guid.NewGuid();

            Commodity commodity = _unitOfWork.CommodityRepository.FindById(viewModel.CommodityId);

            transactionFromStore.TransactionID = Guid.NewGuid();
            transactionFromStore.TransactionGroupID = transactionGroupId;
            transactionFromStore.LedgerID = 2;
            transactionFromStore.HubOwnerID = user.DefaultHubObj.HubOwner.HubOwnerID;
            //trasaction.AccountID
            transactionFromStore.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.HUB, user.DefaultHub.Value); //
            transactionFromStore.HubID = user.DefaultHub.Value;
            transactionFromStore.StoreID = viewModel.FromStoreId;  //
            transactionFromStore.Stack = viewModel.FromStackId; //
            transactionFromStore.ProjectCodeID = viewModel.ProjectCodeId;
            transactionFromStore.ShippingInstructionID = viewModel.ShippingInstructionId;
            transactionFromStore.ProgramID = viewModel.ProgramId;
            transactionFromStore.ParentCommodityID = (commodity.ParentID == null)
                                                       ? commodity.CommodityID
                                                       : commodity.ParentID.Value;
            transactionFromStore.CommodityID = viewModel.CommodityId;
            transactionFromStore.CommodityGradeID = null; // How did I get this value ?
            transactionFromStore.QuantityInMT = 0 - viewModel.QuantityInMt;
            transactionFromStore.QuantityInUnit = 0 - viewModel.QuantityInUnit;
            transactionFromStore.UnitID = viewModel.UnitId;
            transactionFromStore.TransactionDate = DateTime.Now;

            Transaction transactionToStore = new Transaction();

            transactionToStore.TransactionID = Guid.NewGuid();
            transactionToStore.TransactionGroupID = transactionGroupId;
            transactionToStore.LedgerID = 2;
            transactionToStore.HubOwnerID = user.DefaultHubObj.HubOwner.HubOwnerID;
            //transactionToStore.AccountID
            transactionToStore.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.HUB, user.DefaultHub.Value); //
            transactionToStore.HubID = user.DefaultHub.Value;
            transactionToStore.StoreID = viewModel.ToStoreId;  //
            transactionToStore.Stack = viewModel.ToStackId; //
            transactionToStore.ProjectCodeID = viewModel.ProjectCodeId;
            transactionToStore.ShippingInstructionID = viewModel.ShippingInstructionId;
            transactionToStore.ProgramID = viewModel.ProgramId;

            transactionToStore.ParentCommodityID = (commodity.ParentID == null)
                                                       ? commodity.CommodityID
                                                       : commodity.ParentID.Value;
            transactionToStore.CommodityID = viewModel.CommodityId;
            transactionToStore.CommodityGradeID = null; // How did I get this value ?
            transactionToStore.QuantityInMT = viewModel.QuantityInMt;
            transactionToStore.QuantityInUnit = viewModel.QuantityInUnit;
            transactionToStore.UnitID = viewModel.UnitId;
            transactionToStore.TransactionDate = DateTime.Now;

            transactionGroup.TransactionGroupID = transactionGroupId;
            transactionGroup.Transactions.Add(transactionFromStore);
            transactionGroup.Transactions.Add(transactionToStore);
            transactionGroup.PartitionId = 0;

            internalMovement.InternalMovementID = Guid.NewGuid();
            internalMovement.PartitionId = 0;
            internalMovement.TransactionGroupID = transactionGroupId;
            internalMovement.TransactionGroup = transactionGroup;
            internalMovement.TransferDate = viewModel.SelectedDate;
            internalMovement.DReason = viewModel.ReasonId;
            internalMovement.Notes = viewModel.Note;
            internalMovement.ApprovedBy = viewModel.ApprovedBy;
            internalMovement.ReferenceNumber = viewModel.ReferenceNumber;
            internalMovement.HubID = user.DefaultHub.Value;

            // Try to save this transaction

            try
            {
                _unitOfWork.InternalMovementRepository.Add(internalMovement);
                _unitOfWork.Save();
            }
            catch (Exception exp)
            {
                //dbTransaction.Rollback();
                //TODO: Save the detail of this exception somewhere
                throw new Exception("The Internal Movement Transaction Cannot be saved. <br />Detail Message :" + exp.Message);
            }
        }
コード例 #9
0
ファイル: TransactionService.cs プロジェクト: FishAbe/cats
        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);
            }
        }
コード例 #10
0
ファイル: TransactionService.cs プロジェクト: FishAbe/cats
        //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;
        }
コード例 #11
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);
            //}
        }
コード例 #12
0
ファイル: TransactionService.cs プロジェクト: robela/cats
        /// <summary>
        /// Saves the receipt transaction.
        /// </summary>
        /// <param name="receiveModels">The receive models.</param>
        /// <param name="user">The user.</param>
        public void SaveReceiptTransaction(ReceiveViewModel receiveModels, UserProfile user)
        {
            // Populate more details of the reciept object
            // Save it when you are done.

            Receive receive = receiveModels.GenerateReceive();
            receive.CreatedDate = DateTime.Now;
            receive.HubID = user.DefaultHub.HubID;
            receive.UserProfileID = user.UserProfileID;
            var commType = _unitOfWork.CommodityTypeRepository.FindById(receiveModels.CommodityTypeID);

            // var comms = GenerateReceiveDetail(commodities);

            var transactionGroupId = Guid.NewGuid();

            foreach (ReceiveDetailViewModel c in receiveModels.ReceiveDetails)
            {
                if (commType.CommodityTypeID == 2)//if it's a non food
                {
                    c.ReceivedQuantityInMT = 0;
                    c.SentQuantityInMT = 0;
                }
                TransactionGroup tgroup = new TransactionGroup();
                tgroup.TransactionGroupID = transactionGroupId;
                var receiveDetail = new ReceiveDetail()
                {
                    CommodityID = c.CommodityID,
                    Description = c.Description,
                    SentQuantityInMT = c.SentQuantityInMT.Value,
                    SentQuantityInUnit = c.SentQuantityInUnit.Value,
                    UnitID = c.UnitID,
                    ReceiveID = receive.ReceiveID
                };
                if (c.ReceiveDetailID.HasValue)
                {
                    receiveDetail.ReceiveDetailID = c.ReceiveDetailID.Value;
                }

                receiveDetail.TransactionGroupID = tgroup.TransactionGroupID;
                receiveDetail.TransactionGroup = tgroup;
                receive.ReceiveDetails.Add(receiveDetail);

                Transaction transaction = new Transaction();
                transaction.TransactionID = Guid.NewGuid();
                transaction.TransactionGroupID = transactionGroupId;
                transaction.TransactionDate = DateTime.Now;
                transaction.ParentCommodityID = _unitOfWork.CommodityRepository.FindById(c.CommodityID).ParentID ?? c.CommodityID;
                transaction.CommodityID = c.CommodityID;
                transaction.LedgerID = Ledger.Constants.GOODS_ON_HAND_UNCOMMITED;
                transaction.HubOwnerID = user.DefaultHub.HubOwnerID;

                transaction.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.HUB, receive.HubID);
                transaction.ShippingInstructionID = _shippingInstructionService.GetSINumberIdWithCreate(receiveModels.SINumber).ShippingInstructionID;

                transaction.ProjectCodeID = _projectCodeService.GetProjectCodeIdWIthCreate(receiveModels.ProjectNumber).ProjectCodeID;
                transaction.HubID = user.DefaultHub.HubID;
                transaction.UnitID = c.UnitID;
                if (c.ReceivedQuantityInMT != null) transaction.QuantityInMT = c.ReceivedQuantityInMT.Value;
                if (c.ReceivedQuantityInUnit != null) transaction.QuantityInUnit = c.ReceivedQuantityInUnit.Value;
                if (c.CommodityGradeID != null) transaction.CommodityGradeID = c.CommodityGradeID.Value;

                transaction.ProgramID = receiveModels.ProgramID;
                transaction.StoreID = receiveModels.StoreID;
                transaction.Stack = receiveModels.StackNumber;
                transaction.TransactionGroupID = tgroup.TransactionGroupID;
                tgroup.Transactions.Add(transaction);

                // do the second half of the transaction here.

                var transaction2 = new Transaction();
                transaction2.TransactionID = Guid.NewGuid();
                transaction2.TransactionGroupID = transactionGroupId;
                transaction2.TransactionDate = DateTime.Now;
                //TAKEs the PARENT FROM THE FIRST TRANSACTION
                transaction2.ParentCommodityID = transaction.ParentCommodityID;
                transaction2.CommodityID = c.CommodityID;
                transaction2.HubOwnerID = user.DefaultHub.HubOwnerID;
                //Decide from where the -ve side of the transaction comes from
                //it is either from the allocated stock
                // or it is from goods under care.

                // this means that this receipt is done without having gone through the gift certificate process.

                if (receiveModels.CommoditySourceID == CommoditySource.Constants.DONATION || receiveModels.CommoditySourceID == CommoditySource.Constants.LOCALPURCHASE)
                {
                    transaction2.LedgerID = Ledger.Constants.GOODS_UNDER_CARE;
                    transaction2.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.DONOR, receive.ResponsibleDonorID.Value);
                }
                else if (receiveModels.CommoditySourceID == CommoditySource.Constants.REPAYMENT)
                {
                    transaction2.LedgerID = Ledger.Constants.GOODS_RECIEVABLE;
                    transaction2.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.HUB, receiveModels.SourceHubID.Value);
                }
                else
                {
                    transaction2.LedgerID = Ledger.Constants.LIABILITIES;
                    transaction2.AccountID = _accountService.GetAccountIdWithCreate(Account.Constants.HUB, receiveModels.SourceHubID.Value);
                }

                transaction2.ShippingInstructionID = _shippingInstructionService.GetSINumberIdWithCreate(receiveModels.SINumber).ShippingInstructionID;
                transaction2.ProjectCodeID = _projectCodeService.GetProjectCodeIdWIthCreate(receiveModels.ProjectNumber).ProjectCodeID;
                transaction2.HubID = user.DefaultHub.HubID;
                transaction2.UnitID = c.UnitID;
                // this is the credit part, so make it Negative
                if (c.ReceivedQuantityInMT != null) transaction2.QuantityInMT = -c.ReceivedQuantityInMT.Value;
                if (c.ReceivedQuantityInUnit != null) transaction2.QuantityInUnit = -c.ReceivedQuantityInUnit.Value;
                if (c.CommodityGradeID != null) transaction2.CommodityGradeID = c.CommodityGradeID.Value;

                transaction2.ProgramID = receiveModels.ProgramID;
                transaction2.StoreID = receiveModels.StoreID;
                transaction2.Stack = receiveModels.StackNumber;
                transaction2.TransactionGroupID = tgroup.TransactionGroupID;
                // hack to get past same key object in context error
                //repository.Transaction = new TransactionRepository();
                tgroup.Transactions.Add(transaction2);

            }

            // Try to save this transaction
            //   db.Database.Connection.Open();
            //  DbTransaction dbTransaction = db.Database.Connection.BeginTransaction();
            try
            {
                //repository.Receive.Add(receive);
                _unitOfWork.ReceiveRepository.Add(receive);
                _unitOfWork.Save();
            }
            catch (Exception exp)
            {
                //  dbTransaction.Rollback();
                //TODO: Save the exception somewhere
                throw new Exception("The Receipt Transaction Cannot be saved. <br />Detail Message :" + exp.StackTrace);

            }
        }