Ejemplo n.º 1
0
 public bool Approve(LocalPurchase localPurchase)
 {
     try
     {
         localPurchase.StatusID = (int)LocalPurchaseStatus.Approved;
         _unitOfWork.LocalPurchaseRepository.Edit(localPurchase);
         foreach (var localPurchaseDetail in localPurchase.LocalPurchaseDetails)
         {
             var reciptAllocaltion = new ReceiptAllocation()
             {
                 ReceiptAllocationID = Guid.NewGuid(),
                 ProgramID           = localPurchase.ProgramID,
                 CommodityID         = localPurchase.CommodityID,
                 DonorID             = localPurchase.DonorID,
                 ETA               = localPurchase.DateCreated,
                 SINumber          = localPurchase.ShippingInstruction.Value,
                 QuantityInMT      = localPurchaseDetail.AllocatedAmount,
                 HubID             = localPurchaseDetail.HubID,
                 CommoditySourceID = 3,    //Local Purchase
                 ProjectNumber     = localPurchase.ProjectCode,
                 //PurchaseOrder = localPurchase.PurchaseOrder,
                 PartitionId   = 0,
                 IsCommited    = false,
                 ReceiptPlanID = localPurchaseDetail.LocalPurchaseDetailID
             };
             _unitOfWork.ReceiptAllocationReository.Add(reciptAllocaltion);
             _unitOfWork.Save();
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Ejemplo n.º 2
0
        public bool Approve(Transfer transfer)
        {
            if (transfer != null)
            {
                transfer.StatusID = (int)LocalPurchaseStatus.Approved;
                _unitOfWork.TransferRepository.Edit(transfer);
                var reciptAllocaltion = new ReceiptAllocation()
                {
                    ReceiptAllocationID = Guid.NewGuid(),
                    ProgramID           = transfer.ProgramID,
                    CommodityID         = transfer.CommodityID,
                    ETA               = transfer.CreatedDate,
                    SINumber          = transfer.ShippingInstruction.Value,
                    QuantityInMT      = transfer.Quantity,
                    HubID             = transfer.DestinationHubID,
                    CommoditySourceID = transfer.CommoditySourceID,
                    ProjectNumber     = transfer.ProjectCode,
                    SourceHubID       = transfer.SourceHubID,
                    PartitionId       = 0,
                    IsCommited        = false
                };
                _unitOfWork.ReceiptAllocationReository.Add(reciptAllocaltion);
                _unitOfWork.Save();

                return(true);
            }
            return(false);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Generates the receipt allocation.
        /// </summary>
        /// <returns></returns>
        public BLL.ReceiptAllocation GenerateReceiptAllocation()
        {
            ReceiptAllocation receiptAllocation = new ReceiptAllocation()
            {
                ProjectNumber           = this.ProjectNumber,
                SINumber                = this.SINumber,
                QuantityInMT            = this.QuantityInMT,
                CommodityID             = this.CommodityID,
                HubID                   = this.HubID,
                ETA                     = this.ETA,
                DonorID                 = this.DonorID == null ? (int?)null : this.DonorID.Value,
                GiftCertificateDetailID = this.GiftCertificateDetailID,
                PartitionID             = this.PartitionID,
                ProgramID               = this.ProgramID,
                CommoditySourceID       = this.CommoditySourceID,
                IsCommited              = this.IsCommited,
                SourceHubID             = this.SourceHubID,
                PurchaseOrder           = this.PurchaseOrder,
                SupplierName            = this.SupplierName,
                OtherDocumentationRef   = this.OtherDocumentationRef,
                QuantityInUnit          = this.QuantityInUnit,
                Remark                  = this.Remark
            };

            if (this.ReceiptAllocationID.HasValue)
            {
                receiptAllocation.ReceiptAllocationID = this.ReceiptAllocationID.Value;
            }

            return(receiptAllocation);
        }
Ejemplo n.º 4
0
 public bool DeleteReceiptAllocation(ReceiptAllocation receiptAllocation)
 {
     if (receiptAllocation == null)
     {
         return(false);
     }
     _unitOfWork.ReceiptAllocationRepository.Delete(receiptAllocation);
     _unitOfWork.Save();
     return(true);
 }
Ejemplo n.º 5
0
        public ActionResult Edit(ReceiptAllocationViewModel receiptAllocationViewModel)
        {
            if (receiptAllocationViewModel.CommoditySourceID == CommoditySource.Constants.DONATION)
            {
                ModelState.Remove("SourceHubID");
                ModelState.Remove("SupplierName");
                ModelState.Remove("PurchaseOrder");
            }
            else if (receiptAllocationViewModel.CommoditySourceID == CommoditySource.Constants.LOCALPURCHASE)
            {
                ModelState.Remove("DonorID");
                ModelState.Remove("SourceHubID");
            }
            else
            {
                ModelState.Remove("DonorID");
                ModelState.Remove("SupplierName");
                ModelState.Remove("PurchaseOrder");
            }


            if (!(IsSIValid(receiptAllocationViewModel.SINumber, receiptAllocationViewModel.CommoditySourceID)))
            {
                ModelState.AddModelError("SINumber", "");
            }

            if (ModelState.IsValid)
            {
                ReceiptAllocation receiptAllocation = receiptAllocationViewModel.GenerateReceiptAllocation();
                int typeOfGridToReload = receiptAllocation.CommoditySourceID;
                int commType           = _commodityService.FindById(receiptAllocation.CommodityID).CommodityTypeID;
                //override to default hub
                UserProfile user = _userProfileService.GetUser(User.Identity.Name);
                receiptAllocation.HubID = user.DefaultHub.HubID;
                if (typeOfGridToReload != Cats.Models.Hubs.CommoditySource.Constants.DONATION &&
                    typeOfGridToReload != Cats.Models.Hubs.CommoditySource.Constants.LOCALPURCHASE)
                {
                    typeOfGridToReload = Cats.Models.Hubs.CommoditySource.Constants.LOAN;
                }
                //TODO:Check savechanges -> EditRecieptAllocation
                _receiptAllocationService.EditReceiptAllocation(receiptAllocation);
                return(Json(new { gridId = typeOfGridToReload, CommodityTypeID = commType }, JsonRequestBehavior.AllowGet));
                //return RedirectToAction("Index");
            }
            //return this.Create(receiptAllocationViewModel.CommoditySourceID);
            //ModelState.Remove("SINumber");
            //TODO:Check if commenting out has any effect
            //================================================
            // receiptAllocationViewModel.InitalizeViewModel();
            //=============================================
            return(PartialView(receiptAllocationViewModel));
        }
Ejemplo n.º 6
0
        public decimal GetReceivedAlreadyInUnit(ReceiptAllocation receiptAllocation)
        {
            decimal sum = 0;

            if (receiptAllocation.Receives != null)
            {
                foreach (Receive r in receiptAllocation.Receives)
                {
                    foreach (ReceiveDetail rd in r.ReceiveDetails)
                    {
                        sum = sum + Math.Abs(rd.QuantityInUnit);
                    }
                }
            }
            return(sum);
        }
Ejemplo n.º 7
0
        public bool ApproveRecieptPlan(LoanReciptPlan loanReciptPlan)
        {
            if (loanReciptPlan != null)
            {
                loanReciptPlan.StatusID = (int)LocalPurchaseStatus.Approved;
                _unitOfWork.LoanReciptPlanRepository.Edit(loanReciptPlan);
                _unitOfWork.Save();
                var loanReceiptPlanDetail =
                    _unitOfWork.LoanReciptPlanDetailRepository.FindBy(
                        l => l.LoanReciptPlanID == loanReciptPlan.LoanReciptPlanID);
                if (loanReceiptPlanDetail != null)
                {
                    foreach (var loan in loanReceiptPlanDetail)
                    {
                        var parentID = _unitOfWork.CommodityRepository.FindById(loanReciptPlan.CommodityID).ParentID ??
                                       loanReciptPlan.CommodityID;

                        var reciptAllocaltion = new ReceiptAllocation()
                        {
                            ReceiptAllocationID = Guid.NewGuid(),
                            ProgramID           = loanReciptPlan.ProgramID,
                            CommodityID         = (int)parentID,
                            ETA               = loanReciptPlan.CreatedDate,
                            SINumber          = loanReciptPlan.ShippingInstruction.Value,
                            QuantityInMT      = loan.RecievedQuantity,
                            HubID             = loan.HubID,
                            CommoditySourceID = loanReciptPlan.CommoditySourceID,
                            ProjectNumber     = loanReciptPlan.ProjectCode,
                            //SourceHubID = loanReciptPlan.SourceHubID,
                            DonorID       = int.Parse(loanReciptPlan.LoanSource),
                            PartitionId   = 0,
                            IsCommited    = false,
                            IsFalseGRN    = loanReciptPlan.IsFalseGRN,
                            ReceiptPlanID = loan.LoanReciptPlanDetailID
                        };

                        _unitOfWork.ReceiptAllocationReository.Add(reciptAllocaltion);

                        _unitOfWork.Save();
                    }
                }
                return(true);
            }
            return(false);
        }
Ejemplo n.º 8
0
        public ReceiveNewViewModel ReceiptAllocationToReceive(ReceiptAllocation receiptAllocation)
        {
            var viewModel = new ReceiveNewViewModel
            {
                ReceiptDate         = DateTime.Now,
                ReceiptAllocationId = receiptAllocation.ReceiptAllocationID,
                SiNumber            = receiptAllocation.SINumber,
                ProjectCode         = receiptAllocation.ProjectNumber,
                Program             = _unitOfWork.ProgramRepository.FindById(receiptAllocation.ProgramID).Name,
                ProgramId           = receiptAllocation.ProgramID,
                CommodityType       = _unitOfWork.CommodityTypeRepository.FindById(receiptAllocation.Commodity.CommodityTypeID).Name,
                CommodityTypeId     = receiptAllocation.Commodity.CommodityTypeID,
            };

            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 = _unitOfWork.HubRepository.FindById(receiptAllocation.SourceHubID.GetValueOrDefault(0)).Name;
                }
                viewModel.IsFalseGRN = receiptAllocation.IsFalseGRN;
            }

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

            viewModel.CommoditySource            = receiptAllocation.CommoditySource.Name;
            viewModel.CommoditySourceTypeId      = receiptAllocation.CommoditySourceID;
            viewModel.ReceiveDetailNewViewModels = new List <ReceiveDetailNewViewModel> {
            };
            return(viewModel);
        }
Ejemplo n.º 9
0
 public bool EditReceiptAllocation(ReceiptAllocation receiptAllocation)
 {
     _unitOfWork.ReceiptAllocationRepository.Edit(receiptAllocation);
     _unitOfWork.Save();
     return(true);
 }
 public bool DeleteReceiptAllocation(ReceiptAllocation receiptAllocation)
 {
     if (receiptAllocation == null) return false;
     _unitOfWork.ReceiptAllocationRepository.Delete(receiptAllocation);
     _unitOfWork.Save();
     return true;
 }
 public bool AddReceiptAllocation(ReceiptAllocation receiptAllocation)
 {
     _unitOfWork.ReceiptAllocationRepository.Add(receiptAllocation);
     _unitOfWork.Save();
     return true;
 }
 public decimal GetReceivedAlreadyInUnit(ReceiptAllocation receiptAllocation)
 {
     decimal sum = 0;
     if (receiptAllocation.Receives != null)
         foreach (Receive r in receiptAllocation.Receives)
         {
             foreach (ReceiveDetail rd in r.ReceiveDetails)
             {
                 sum = sum + Math.Abs(rd.QuantityInUnit);
             }
         }
     return sum;
 }
Ejemplo n.º 13
0
        public ActionResult Create(ReceiptAllocationViewModel receiptAllocationViewModel)
        {
            if (receiptAllocationViewModel.CommoditySourceID == CommoditySource.Constants.DONATION)
            {
                ModelState.Remove("SourceHubID");
                ModelState.Remove("SupplierName");
                ModelState.Remove("PurchaseOrder");
            }
            else if (receiptAllocationViewModel.CommoditySourceID == CommoditySource.Constants.LOCALPURCHASE)
            {
                ModelState.Remove("DonorID");
                ModelState.Remove("SourceHubID");
            }
            else
            {
                ModelState.Remove("DonorID");
                ModelState.Remove("SupplierName");
                ModelState.Remove("PurchaseOrder");
            }

            if (!(IsSIValid(receiptAllocationViewModel.SINumber, receiptAllocationViewModel.CommoditySourceID)))
            {
                ModelState.AddModelError("SINumber", "");
            }

            if (ModelState.IsValid)
            {
                ReceiptAllocation receiptAllocation = receiptAllocationViewModel.GenerateReceiptAllocation();
                //for creation make the giftCetificate null if it's from
                if (receiptAllocationViewModel.GiftCertificateDetailID == 0 ||
                    receiptAllocationViewModel.GiftCertificateDetailID == null
                    )
                {
                    var shippingInstruction =
                        _shippingInstructionService.FindBy(t => t.Value == receiptAllocationViewModel.SINumber).
                        FirstOrDefault();
                    var GC = new GiftCertificate();
                    if (shippingInstruction != null)
                    {
                        GC = _giftCertificateService.FindBySINumber(shippingInstruction.ShippingInstructionID);
                    }

                    if (GC != null)
                    {
                        var GCD =
                            GC.GiftCertificateDetails.FirstOrDefault(
                                p => p.CommodityID == receiptAllocationViewModel.CommodityID);
                        if (GCD != null) //&& GCD.GiftCertificateDetailID;
                        {
                            receiptAllocation.GiftCertificateDetailID = GCD.GiftCertificateDetailID;
                        }
                    }
                    else
                    {
                        receiptAllocation.GiftCertificateDetailID = null;
                    }
                }
                int typeOfGridToReload = receiptAllocation.CommoditySourceID;
                int commType           = _commodityService.FindById(receiptAllocation.CommodityID).CommodityTypeID;
                //override to default hub
                UserProfile user = _userProfileService.GetUser(User.Identity.Name);
                receiptAllocation.HubID = user.DefaultHub.HubID;

                if (typeOfGridToReload != Cats.Models.Hubs.CommoditySource.Constants.DONATION &&
                    typeOfGridToReload != Cats.Models.Hubs.CommoditySource.Constants.LOCALPURCHASE)
                {
                    typeOfGridToReload = Cats.Models.Hubs.CommoditySource.Constants.LOAN;
                }
                receiptAllocation.ReceiptAllocationID = Guid.NewGuid();
                _receiptAllocationService.AddReceiptAllocation(receiptAllocation);

                return(Json(new { gridId = typeOfGridToReload, CommodityTypeID = commType }, JsonRequestBehavior.AllowGet));
                //return RedirectToAction("Index");
            }
            //check this out later
            //return this.Create(receiptAllocationViewModel.CommoditySourceID);
            //ModelState.Remove("SINumber");
            //TODO:Check if commenting out has any effect
            //=================================================
            //receiptAllocationViewModel.InitalizeViewModel();
            //================================================
            return(PartialView(receiptAllocationViewModel));
        }