Esempio n. 1
0
        /// <summary>
        /// This is used mainly for ViewBudget. It calculates the numbers (totals) for each category
        /// </summary>
        /// <param name="category"></param>
        /// <param name="budgetLines"></param>
        private static void AddCategoryLinesWithNumbers(IExchangeRateService exchangeRateService, Models.Category category,
                                                        List <ProjectBudget> budgetLines, Currency displayCurrency, CountryProgramme countryProg)
        {
            List <Models.BudgetLine> bsl = new List <Models.BudgetLine>();

            Models.BudgetLine subLine;
            decimal           budgetAmount;
            decimal?          committed, posted;

            budgetAmount = 0;
            committed    = posted = 0;
            foreach (ProjectBudget item in budgetLines)
            {
                subLine = new Models.BudgetLine();
                subLine.EntityBudgetLine     = item;
                subLine.SubLineId            = item.Id;
                subLine.BudgetCategoryId     = category.EntityBudgetCategory.Id.ToString();
                subLine.BudgetCategoryNumber = category.EntityBudgetCategory.Number;
                subLine.TotalBudget          = (decimal)exchangeRateService.GetForeignCurrencyValue(displayCurrency, item.BudgetCategory.ProjectDonor.Currency, item.TotalBudget, countryProg.Id);
                subLine.TotalCommitted       = (decimal)exchangeRateService.GetForeignCurrencyValue(displayCurrency, item.BudgetCategory.ProjectDonor.Currency, item.TotalCommitted, countryProg.Id);
                subLine.TotalPosted          = (decimal)exchangeRateService.GetForeignCurrencyValue(displayCurrency, item.BudgetCategory.ProjectDonor.Currency, item.TotalPosted, countryProg.Id);
                subLine.RemainingBalance     = subLine.TotalBudget - (subLine.TotalCommitted + subLine.TotalPosted);
                //Sum up for category
                budgetAmount += subLine.TotalBudget;
                committed    += subLine.TotalCommitted;
                posted       += subLine.TotalPosted;
                bsl.Add(subLine);
            }
            category.BudgetLines      = bsl;
            category.TotalBudget      = budgetAmount;
            category.TotalCommitted   = committed;
            category.TotalPosted      = posted;
            category.RemainingBalance = budgetAmount - (committed + posted);
        }
Esempio n. 2
0
 public ActionResult CalculateFXValue(SCMS.UI.Models.CurrencyConvert cc)
 {
     try
     {
         decimal amount = exchangeRateService.GetForeignCurrencyValue(new Guid(cc.FXCurrencyId), new Guid(cc.LocalCurrencyId), cc.Amount, countryProg.Id);
         ViewBag.Response = amount;
     }
     catch
     {
         ViewBag.Response = 0;
     }
     return(View("GeneralResponse"));
 }
Esempio n. 3
0
        public ActionResult AddPPItems2OR(Guid pdId, Model.OrderRequest or)
        {
            ProcurementPlan model = ppService.GetProcurementPlanByProjectId(pdId);

            if (model == null)
            {
                return(Content("<i style=\"color: Red\">" + Resources.OrderRequestController_String_NoPPItems + "</i>", "text/html"));
            }
            model.PPItemList     = model.ProcurementPlanItems.Where(p => (p.Quantity - p.ProcuredAmount) > 0).OrderBy(p => p.Item.Name).ToList();
            model.OrderRequestId = or.Id;
            Currency orCurr = currencyService.GetCurrency(or.CurrencyId);

            foreach (ProcurementPlanItem ppItem in model.PPItemList)
            {
                ppItem.UnitCost        = Math.Round(exchangeRateService.GetForeignCurrencyValue(or.CurrencyId, ppItem.CurrencyId, ppItem.UnitCost, countryProg.Id), 2);
                ppItem.QuantityToOrder = ppItem.Quantity - ppItem.ProcuredAmount;
                ppItem.TotalCost       = Math.Round((ppItem.UnitCost * ppItem.QuantityToOrder), 2);
            }
            //model.PPItemList = model.ProcurementPlanItems.Where(p => !p.AddedToOR && p.IsApproved && !p.IsRemoved).OrderBy(p => p.Item.Name).ToList();
            ViewBag.Currency = orCurr.ShortName;
            return(View("AddPPItems2OR", model));
        }
Esempio n. 4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="mbId">MasterBudgetCategoryId</param>
 /// <param name="cpId">CountryProgrammeId</param>
 /// <returns></returns>
 private decimal?GetMBCategoryProjection(Guid mbId, Guid cpId, Currency mbCurr)
 {
     using (var context = new SCMSEntities())
     {
         var mbp = context.AnnualCostProjections.FirstOrDefault(a => a.MasterBudgetCategoryId == mbId && a.CountryProgrammeId == cpId);
         if (mbp == null)
         {
             return(0);
         }
         return(exchangeRateService.GetForeignCurrencyValue(mbCurr, mbp.Currency, mbp.AmountProjected, cpId));
     }
 }
Esempio n. 5
0
        public bool SufficientFundsAvailable(decimal amount, string budgetLineId, string currencyId, Guid poId, Guid rfpId, Guid orItemId)
        {
            decimal?budgetCurrencyAmount;

            using (var context = new SCMSEntities())
            {
                var orCurrency = context.Currencies.FirstOrDefault(c => c.Id == new Guid(currencyId));
                var pb         = context.ProjectBudgets.FirstOrDefault(p => p.Id == new Guid(budgetLineId));
                budgetCurrencyAmount = exchangeRateService.GetForeignCurrencyValue(pb.BudgetCategory.ProjectDonor.Currency, orCurrency, amount, pb.BudgetCategory.ProjectDonor.Project.CountryProgrammeId);
                //Get percentage allowed overrun for bl
                double overrun = 1;
                if (pb.OverrunAdjustment.HasValue)
                {
                    overrun  = pb.OverrunAdjustment.Value / 100;
                    overrun += 1;
                }

                //Compute available balance while considering overrun %age cussion
                var blAvailableFunds = (pb.TotalBudget * (decimal)overrun) - pb.TotalCommitted - pb.TotalPosted;

                //Add back commitments from related dox
                if (poId != Guid.Empty)
                {
                    var poItemList   = context.PurchaseOrderItems.Where(p => p.PurchaseOrderId == poId).ToList();
                    var orItemIdList = new List <Guid>();
                    foreach (var poItem in poItemList)
                    {
                        if (poItem.OrderRequestItemId.HasValue)
                        {
                            orItemIdList.Add(poItem.OrderRequestItemId.Value);
                        }
                    }
                    var commits = context.BudgetCommitments.Where(bc => bc.BudgetLineId == new Guid(budgetLineId) && bc.OrderRequestItemId.HasValue == true && orItemIdList.Contains(bc.OrderRequestItemId.Value));
                    foreach (var commit in commits)
                    {
                        blAvailableFunds += commit.AmountCommitted;
                    }
                }
                else if (rfpId != Guid.Empty)
                {
                    var rfpItemList  = context.PaymentRequestBudgetLines.Where(p => p.PaymentRequestId == rfpId).ToList();
                    var poItemIdList = new List <Guid>();
                    foreach (var rfpItem in rfpItemList)
                    {
                        poItemIdList.Add(rfpItem.PurchaseOrderItemId.Value);
                    }
                    var commits = context.BudgetCommitments.Where(bc => bc.BudgetLineId == new Guid(budgetLineId) && bc.PurchaseOrderItemId.HasValue == true && poItemIdList.Contains(bc.PurchaseOrderItemId.Value));
                    foreach (var commit in commits)
                    {
                        blAvailableFunds += commit.AmountCommitted;
                    }
                }
                else if (orItemId != Guid.Empty)
                {
                    var commit = context.BudgetCommitments.FirstOrDefault(bc => bc.BudgetLineId == new Guid(budgetLineId) && bc.OrderRequestItemId == orItemId);
                    if (commit != null)
                    {
                        blAvailableFunds += commit.AmountCommitted;
                    }
                }

                if (budgetCurrencyAmount <= blAvailableFunds)
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 6
0
 private void ConvertORItemNumbersToPOCurrency(Model.PurchaseOrder po, Model.OrderRequestItem orItem)
 {
     orItem.EstimatedUnitPrice = Math.Round((decimal)exchangeRateService.GetForeignCurrencyValue(po.Currency, orItem.OrderRequest.Currency, orItem.EstimatedUnitPrice, countryProg.Id), 2);
     orItem.EstimatedPrice     = orItem.EstimatedUnitPrice * orItem.Quantity;
 }
Esempio n. 7
0
        public bool CommitFunds(PaymentRequest rfp)
        {
            decimal rfpCommited = 0;
            decimal poCommitAmt = 0;//this amount is in the currency of the rfp;

            using (var context = SCMSEntities.Define())
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    try
                    {
                        var po            = context.PurchaseOrders.FirstOrDefault(p => p.Id == rfp.PurchaseOrderId);
                        var poItemCommits = context.BudgetCommitments.Where(c => c.PurchaseOrderItem.PaymentRequestBudgetLines.Where(p => p.PaymentRequestId == rfp.Id).Count() > 0).ToList();
                        //REMOVE FUNDS FROM PO COMMITTED
                        foreach (var poItemCommit in poItemCommits)
                        {
                            var rfpBL = poItemCommit.PurchaseOrderItem.PaymentRequestBudgetLines.FirstOrDefault(p => p.PurchaseOrderItemId == poItemCommit.PurchaseOrderItemId);
                            if (rfpBL == null)
                            {
                                continue;
                            }
                            //Get committed amount in rfp currency
                            poCommitAmt  = (decimal)exchangeRateService.GetForeignCurrencyValue(po.Currency, poItemCommit.ProjectBudget.BudgetCategory.ProjectDonor.Currency, poItemCommit.AmountCommitted, rfp.CountryProgrammeId);
                            rfpCommited += poCommitAmt;
                            var pb = context.ProjectBudgets.FirstOrDefault(p => p.Id == poItemCommit.BudgetLineId);
                            if (rfpBL.Amount >= poCommitAmt)
                            {
                                //Delete commitment
                                context.BudgetCommitments.Remove(poItemCommit);
                                //Deduct value from budget commitment
                                pb.TotalCommitted -= poItemCommit.AmountCommitted;
                            }
                            else
                            {
                                //convert rfpBL.Amount to project budget currency and deduct it
                                poCommitAmt = (decimal)exchangeRateService.GetForeignCurrencyValue(poItemCommit.ProjectBudget.BudgetCategory.ProjectDonor.Currency, po.Currency, rfpBL.Amount, rfp.CountryProgrammeId);
                                //Deduct this amount from budget commitments and also from project budget commitments
                                poItemCommit.AmountCommitted -= poCommitAmt;
                                pb.TotalCommitted            -= poCommitAmt;
                            }
                        }
                        //MOVE FUNDS TO COMMITTED
                        var rfpBudgetLines = context.PaymentRequestBudgetLines.Where(p => p.PaymentRequestId == rfp.Id).ToList();
                        foreach (var rfpBL in rfpBudgetLines)
                        {
                            var budgetLine = context.ProjectBudgets.FirstOrDefault(pb => pb.Id == rfpBL.BudgetLineId);
                            var newCommit  = new BudgetCommitment();
                            newCommit.Id = Guid.NewGuid();
                            newCommit.AmountCommitted = (decimal)exchangeRateService.GetForeignCurrencyValue(budgetLine.BudgetCategory.ProjectDonor.Currency, po.Currency, rfpBL.Amount, rfp.CountryProgrammeId);
                            newCommit.DateCommitted   = DateTime.Now;
                            newCommit.RFPBudgetLineId = rfpBL.Id;
                            newCommit.BudgetLineId    = budgetLine.Id;
                            context.BudgetCommitments.Add(newCommit);
                            budgetLine.TotalCommitted += newCommit.AmountCommitted;
                        }
                        //SAVE ALL CHANGES
                        if (context.SaveChanges() > 0)
                        {
                            scope.Complete();
                            return(true);
                        }
                        else
                        {
                            scope.Dispose();
                            return(false);
                        }
                    }
                    catch (Exception ex)
                    {
                        scope.Dispose();
                        throw ex;
                    }
                }
            }
        }