コード例 #1
0
ファイル: ReceiveService.cs プロジェクト: FishAbe/cats
 public bool DeleteReceive(Receive entity)
 {
     if (entity == null) return false;
     _unitOfWork.ReceiveRepository.Delete(entity);
     _unitOfWork.Save();
     return true;
 }
コード例 #2
0
ファイル: ReceiveService.cs プロジェクト: FishAbe/cats
 public bool EditReceive(Receive entity)
 {
     _unitOfWork.ReceiveRepository.Edit(entity);
     _unitOfWork.Save();
     return true;
 }
コード例 #3
0
ファイル: ReceiveService.cs プロジェクト: FishAbe/cats
        public void Update(List<ReceiveDetail> inserted, List<ReceiveDetail> updated, List<ReceiveDetail> deleted, Receive receive)
        {
            if (receive != null)
            {

                _unitOfWork.ReceiveRepository.Edit(receive);
                _unitOfWork.Save();

                foreach (ReceiveDetail insert in inserted)
                {
                    //TODO THIS should be in transaction
                    insert.ReceiveDetailID = Guid.NewGuid();
                    receive.ReceiveDetails.Add(insert);
                }

                foreach (ReceiveDetail delete in deleted)
                {
                    ReceiveDetail deletedCommodity = _unitOfWork.ReceiveDetailRepository.FindBy(p => p.ReceiveDetailID == delete.ReceiveDetailID).FirstOrDefault();
                    if (deletedCommodity != null)
                    {
                        _unitOfWork.ReceiveDetailRepository.Delete(deletedCommodity);
                    }
                }

                foreach (ReceiveDetail update in updated)
                {
                    ReceiveDetail updatedCommodity = _unitOfWork.ReceiveDetailRepository.FindBy(p => p.ReceiveDetailID == update.ReceiveDetailID).FirstOrDefault();
                    if (updatedCommodity != null)
                    {
                        updatedCommodity.CommodityID = update.CommodityID;
                        updatedCommodity.Description = update.Description;
                        updatedCommodity.ReceiveID = update.ReceiveID;
                        updatedCommodity.SentQuantityInMT = update.SentQuantityInMT;
                        // updatedCommodity.QuantityInMT = updatedCommodity.QuantityInMT;
                        updatedCommodity.SentQuantityInUnit = update.SentQuantityInUnit;
                        updatedCommodity.UnitID = update.UnitID;
                    }
                }
                _unitOfWork.Save();
            }
        }
コード例 #4
0
ファイル: ReceiveService.cs プロジェクト: FishAbe/cats
 public bool AddReceive(Receive entity)
 {
     _unitOfWork.ReceiveRepository.Add(entity);
     _unitOfWork.Save();
     return true;
 }
コード例 #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>
        /// 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);

            }
        }
コード例 #7
0
ファイル: ReceiveViewModel.cs プロジェクト: robela/cats
        /// <summary>
        /// Generates the receive.
        /// </summary>
        /// <returns></returns>
        public Receive GenerateReceive()
        {
            Receive receive = new Receive()
            {
                CreatedDate = DateTime.Now,
                ReceiptDate = this.ReceiptDate,

                DriverName = this.DriverName,
                GRN = this.GRN,
                PlateNo_Prime = this.PlateNo_Prime,
                PlateNo_Trailer = this.PlateNo_Trailer,
                TransporterID = this.TransporterID,
                HubID = this.HubID,
                CommodityTypeID = this.CommodityTypeID,
                WayBillNo = this.WayBillNo,
                ResponsibleDonorID = this.ResponsibleDonorID,
                SourceDonorID = this.SourceDonorID,
                CommoditySourceID = this.CommoditySourceID,
                WeightBridgeTicketNumber = this.TicketNumber,
                WeightBeforeUnloading = this.WeightBeforeUnloading,
                WeightAfterUnloading = this.WeightAfterUnloading,
                ReceivedByStoreMan = this.ReceivedByStoreMan,
                VesselName = this.VesselName,
                PortName = this.PortName,
                PurchaseOrder = this.PurchaseOrder,
                SupplierName = this.SupplierName,
                ReceiptAllocationID = this.ReceiptAllocationID,
                Remark = this.Remark,
            };
            if (this.ReceiveID.HasValue)
            {
                receive.ReceiveID = this.ReceiveID.Value;
            }
            return receive;
        }
コード例 #8
0
ファイル: ReceiveViewModel.cs プロジェクト: robela/cats
        /// <summary>
        /// Generates the receive model.
        /// </summary>
        /// <param name="receive">The receive.</param>
        /// <param name="user">The user.</param>
        /// <returns></returns>
        public static ReceiveViewModel GenerateReceiveModel(Receive receive, List<Commodity> commodities, List<CommodityGrade> commodityGrades, List<Transporter> transporters, List<CommodityType> commodityTypes,
            List<CommoditySource> commoditySources, List<Program> programs, List<Donor> donors, List<Hub> hubs, UserProfile user,List<Unit> units )
        {
            ReceiveViewModel model = new ReceiveViewModel();
            model._UserProfile = user;

            model.InitalizeViewModel(commodities, commodityGrades, transporters, commodityTypes,
             commoditySources, programs, donors, hubs, user,units);
            model.IsEditMode = true;
            model.ReceiveID = receive.ReceiveID;
            model.DriverName = receive.DriverName;
            model.GRN = receive.GRN;
            model.PlateNo_Prime = receive.PlateNo_Prime;
            model.PlateNo_Trailer = receive.PlateNo_Trailer;

            model.TransporterID = receive.TransporterID;
            model.HubID = receive.HubID;

            ReceiveDetail receiveDetail = receive.ReceiveDetails.FirstOrDefault();//p=>p.QuantityInMT>0);
            Transaction receiveDetailtransaction = null;
            if (receiveDetail != null)
                foreach (Transaction transaction in receiveDetail.TransactionGroup.Transactions)
                {
                    var negTransaction = receiveDetail.TransactionGroup.Transactions.FirstOrDefault(p => p.QuantityInMT < 0);
                    if (negTransaction != null)
                        model.SourceHubID = negTransaction.Account.EntityID;
                    receiveDetailtransaction = transaction;
                    break;
                }
            if (receiveDetailtransaction != null)
            {
                model.SINumber = receiveDetailtransaction.ShippingInstruction != null ? receiveDetailtransaction.ShippingInstruction.Value : "";

                model.ProjectNumber = receiveDetailtransaction.ProjectCode != null ? receiveDetailtransaction.ProjectCode.Value : "";

                model.ProgramID = receiveDetailtransaction.Program != null ? receiveDetailtransaction.Program.ProgramID : default(int);

                model.StoreID = receiveDetailtransaction.Store != null ? receiveDetailtransaction.Store.StoreID : default(int);

                model.StackNumber = receiveDetailtransaction.Stack.HasValue ? receiveDetailtransaction.Stack.Value : default(int);

            }
            else
            {
                model.SINumber = "";
                model.ProjectNumber = "";
                model.ProgramID = default(int);
                model.StoreID = default(int);
                model.StackNumber = default(int);
            }

            model.ReceiptDate = receive.ReceiptDate;
            model.WayBillNo = receive.WayBillNo;
            model.CommodityTypeID = receive.CommodityTypeID;
            model.ResponsibleDonorID = receive.ResponsibleDonorID;
            model.SourceDonorID = receive.SourceDonorID;
            model.CommoditySourceID = receive.CommoditySourceID;
            model.TicketNumber = receive.WeightBridgeTicketNumber;
            model.WeightBeforeUnloading = receive.WeightBeforeUnloading;
            model.WeightAfterUnloading = receive.WeightAfterUnloading;
            model.VesselName = receive.VesselName;
            model.PortName = receive.PortName;
            model.ReceiptAllocationID = receive.ReceiptAllocationID;
            model.PurchaseOrder = receive.PurchaseOrder;
            model.SupplierName = receive.SupplierName;

            model.Remark = receive.Remark;
            model.ReceivedByStoreMan = receive.ReceivedByStoreMan;

            model.ReceiveDetails =Cats.Models.Hubs.ReceiveDetailViewModel.GenerateReceiveDetailModels(receive.ReceiveDetails);
            return model;
        }
コード例 #9
0
ファイル: ReceiveNewController.cs プロジェクト: FishAbe/cats
        //string receiveId, string grn)
        public ReceiveNewViewModel ModeltoNewView(Receive receive)
        {
            var receiptAllocation = _receiptAllocationService.FindById(receive.ReceiptAllocationID.GetValueOrDefault());

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

            var viewModel = _receiveService.ReceiptAllocationToReceive(receiptAllocation);
            viewModel.CurrentHub = user.DefaultHub.Value;
            viewModel.UserProfileId = user.UserProfileID;
            var hubOwner = _hub.FindById(user.DefaultHub.Value);
            viewModel.IsTransporterDetailVisible = !hubOwner.HubOwner.Name.Contains("WFP");
            viewModel.AllocationStatusViewModel = _receiveService.GetAllocationStatus(receive.ReceiptAllocationID.GetValueOrDefault());
            //var commodities = _commodityService.GetAllCommodityViewModelsByParent(receiptAllocation.CommodityID);
            //ViewData["commodities"] = commodities;
            //ViewData["units"] = _unitService.GetAllUnitViewModels();

            viewModel.Grn = receive.GRN;
            viewModel.ReceiptDate = receive.ReceiptDate;
                                                      viewModel.SiNumber=receiptAllocation.SINumber;
                                                           viewModel.ReceiptDate = viewModel.ReceiptDate;
            viewModel.ReceiptAllocationId = receive.ReceiptAllocationID.GetValueOrDefault();
            viewModel.ReceiveId = receive.ReceiveID;

                //viewModel.StackNumber
            viewModel.WayBillNo = receive.WayBillNo;
            viewModel.SiNumber = receiptAllocation.SINumber;
            viewModel.ProjectCode = receiptAllocation.ProjectNumber;
            //viewModel.Program = .FindById(receiptAllocation.ProgramID).Name;
            viewModel.ProgramId = receiptAllocation.ProgramID;
                //viewModel.CommodityType = _CommodityTypeRepository.FindById(receiptAllocation.Commodity.CommodityTypeID).Name,
            viewModel.CommodityTypeId = receiptAllocation.Commodity.CommodityTypeID;
            viewModel.CommoditySourceTypeId = receiptAllocation.CommoditySourceID;

            if (CommoditySource.Constants.LOAN == receiptAllocation.CommoditySourceID
                || CommoditySource.Constants.SWAP == receiptAllocation.CommoditySourceID
                || CommoditySource.Constants.TRANSFER == receiptAllocation.CommoditySourceID
                || CommoditySource.Constants.REPAYMENT == receiptAllocation.CommoditySourceID)
            {
                if (receiptAllocation.SourceHubID.HasValue)
                {

                    viewModel.SourceHub = _hub.FindById(receiptAllocation.SourceHubID.GetValueOrDefault(0)).Name;
                }
            }

            if (CommoditySource.Constants.LOCALPURCHASE == receiptAllocation.CommoditySourceID)
            {
                viewModel.SupplierName = receiptAllocation.SupplierName;
                viewModel.PurchaseOrder = receiptAllocation.PurchaseOrder;
            }

            viewModel.CommoditySource = receiptAllocation.CommoditySource.Name;
            viewModel.CommoditySourceTypeId = receiptAllocation.CommoditySourceID;
            viewModel.ReceivedByStoreMan = receive.ReceivedByStoreMan;
            ReceiveDetail receivedetail = receive.ReceiveDetails.FirstOrDefault();
            viewModel.StoreId = receive.StoreId.GetValueOrDefault();
            viewModel.StackNumber = receive.StackNumber.GetValueOrDefault();
            viewModel.ReceiveDetailNewViewModel = new ReceiveDetailNewViewModel
                                                      {
                                                          CommodityId = receivedetail.CommodityID,
                                                          CommodityChildID=receivedetail.CommodityChildID,
                                                          ReceivedQuantityInMt =
                                                              receivedetail.QuantityInMT,
                                                          ReceivedQuantityInUnit =
                                                              receivedetail.QuantityInUnit,
                                                              SentQuantityInMt=receivedetail.SentQuantityInMT,
                                                              SentQuantityInUnit=receivedetail.SentQuantityInUnit,
                                                              UnitId=receivedetail.UnitID,
                                                              Description=receivedetail.Description,
                                                              ReceiveId=receivedetail.ReceiveID,
            ReceiveDetailId=receivedetail.ReceiveDetailID,

                                                      };

            viewModel.WeightBridgeTicketNumber = receive.WeightBridgeTicketNumber;
            viewModel.WeightBeforeUnloading = receive.WeightBeforeUnloading;
            viewModel.WeightAfterUnloading = receive.WeightAfterUnloading;
            viewModel.TransporterId = receive.TransporterID;
            viewModel.DriverName = receive.DriverName;
            viewModel.PlateNoPrime = receive.PlateNo_Prime;
            viewModel.PlateNoTrailer = receive.PlateNo_Trailer;
            viewModel.PortName = receive.PortName;
            viewModel.Remark = receive.Remark;

            return viewModel;
        }