Esempio n. 1
0
        public ActionResult UpdatePymtDueFlags([FromBody] List <PositionsForPaymentDueVm> positionsToUpdate)
        {
            // Pending updates for user-selected Position ids marked as having received income.
            PositionDataProcessing positionDataAccessComponent = new PositionDataProcessing(_ctx);
            bool updatesAreValid = positionDataAccessComponent.UpdatePositionPymtDueFlags(positionsToUpdate);

            if (updatesAreValid)
            {
                Log.Information("Payment(s) received & marked as paid ('PymtDue': False) for {0} position(s).", positionsToUpdate.Count());
            }
            else
            {
                Log.Warning("'Income due' payment processing aborted; one or more delinquent positions found among current selections. " +
                            "Processing via PositionController.UpdatePymtDueFlags().");
            }
            return(Ok(updatesAreValid));
        }
Esempio n. 2
0
        public DataImportVm SaveRevenue(DataImportVm importVmToUpdate, PIMS3Context _ctx, string investorId)
        {
            //  Processing includes:
            //  1. persisting revenue,
            //  2. persisting revenue delinquencies, and
            //  3. updating Positions ("PymtDue") where applicable.

            ImportFileProcessing   busLayerComponent = new ImportFileProcessing(importVmToUpdate, _ctx, null);
            IEnumerable <Income>   revenueListingToSave;
            PositionDataProcessing positionDataAccessComponent = new PositionDataProcessing(_ctx);

            if (busLayerComponent.ValidateVm())
            {
                revenueListingToSave = busLayerComponent.ParseRevenueSpreadsheetForIncomeRecords(importVmToUpdate.ImportFilePath.Trim(), this, investorId);

                if (revenueListingToSave == null || revenueListingToSave.Count() == 0)
                {
                    if (!string.IsNullOrEmpty(importVmToUpdate.ExceptionTickers))
                    {
                        importVmToUpdate.MiscMessage = "Error saving revenue for " + importVmToUpdate.ExceptionTickers + ". Check position(s).";
                    }
                    else
                    {
                        importVmToUpdate.MiscMessage = BuildLogMessage("revenue");
                    }

                    return(importVmToUpdate);
                }
                else
                {
                    // Persist to 'Income'. Deferring use of using{}: ctx scope needed.
                    _ctx.AddRange(revenueListingToSave);
                    recordsSaved = _ctx.SaveChanges();
                }

                if (recordsSaved > 0)
                {
                    totalAmtSaved = 0M;
                    foreach (var record in revenueListingToSave)
                    {
                        totalAmtSaved += record.AmountRecvd;
                    }

                    // Returned values to UI.
                    importVmToUpdate.AmountSaved  = totalAmtSaved;
                    importVmToUpdate.RecordsSaved = recordsSaved;

                    // Update Positions.
                    positionDataAccessComponent.UpdatePositionPymtDueFlags(ExtractPositionIdsForPymtDueProcessing(revenueListingToSave), true);

                    /* === Month-end delinquent revenue processing === */

                    // If at month end/beginning, we'll query Positions for any now delinquent income receivables via "PymtDue" flag.
                    // Any unpaid income receivables, those not marked as received via 'Income due', will STILL have their 'PymtDue' flag set as
                    // True, and hence will now be considered a delinquent Position, resulting in persistence to 'DelinquentIncome' table.
                    // Delinquent position searches may ONLY be performed during month-end xLSX processing, as income receipts are still being
                    // accepted during the month via 'Income due'. During 'Income due' payments, flags are set accordingly: [PymtDue : True -> False].
                    // Any delinquent Positions will automatically be added to the 'Income due' collection that is broadcast via the UI schedule,
                    // for necessary action.
                    if (DateTime.Now.Day <= 3 && DateTime.Now.DayOfWeek.ToString() != "Saturday" && DateTime.Now.DayOfWeek.ToString() != "Sunday")
                    {
                        //PositionDataProcessing positionDataAccessComponent = new PositionDataProcessing(_ctx);
                        IQueryable <dynamic>     filteredPositionAssetJoinData = positionDataAccessComponent.GetCandidateDelinquentPositions(investorId);
                        IList <DelinquentIncome> pastDueListing = new List <DelinquentIncome>();
                        string delinquentMonth = DateTime.Now.AddMonths(-1).Month.ToString().Trim();
                        int    matchingPositionDelinquencyCount       = 0;
                        IList <DelinquentIncome> existingDelinqencies = positionDataAccessComponent.GetSavedDelinquentRecords(investorId, "");
                        int duplicateDelinquencyCount = 0;

                        foreach (dynamic joinData in filteredPositionAssetJoinData)
                        {
                            // 'DelinquentIncome' PKs: InvestorId, MonthDue, PositionId
                            // Do we have a match based on PositionId & InvestorId ? If so, Position is eligible for omitting setting 'PymtDue' to True.
                            matchingPositionDelinquencyCount = existingDelinqencies.Where(d => d.PositionId == joinData.PositionId &&
                                                                                          d.InvestorId == joinData.InvestorId).Count();

                            if (matchingPositionDelinquencyCount >= 1)
                            {
                                // Do we have a duplicate entry ?
                                duplicateDelinquencyCount = existingDelinqencies.Where(d => d.PositionId == joinData.PositionId &&
                                                                                       d.InvestorId == joinData.InvestorId &&
                                                                                       d.MonthDue == delinquentMonth).Count();
                            }

                            if (joinData.DividendFreq == "M")
                            {
                                if (matchingPositionDelinquencyCount > 0 && duplicateDelinquencyCount == 0)
                                {
                                    pastDueListing.Add(InitializeDelinquentIncome(joinData));
                                }
                                else
                                {
                                    continue;
                                }
                            }
                            else
                            {
                                string[] divMonths = joinData.DividendMonths.Split(',');
                                for (var i = 0; i < divMonths.Length; i++)
                                {
                                    if (divMonths[i].Trim() == delinquentMonth)
                                    {
                                        if (matchingPositionDelinquencyCount > 0 && duplicateDelinquencyCount == 0)
                                        {
                                            pastDueListing.Add(InitializeDelinquentIncome(joinData));
                                        }
                                        else
                                        {
                                            continue;
                                        }
                                    }
                                }
                            }
                            matchingPositionDelinquencyCount = 0;
                        }

                        // Persist to 'DelinquentIncome' as needed.
                        if (pastDueListing.Any())
                        {
                            bool pastDueSaved = positionDataAccessComponent.SaveDelinquencies(pastDueListing.ToList());
                            if (pastDueSaved)
                            {
                                importVmToUpdate.MiscMessage = "Found & stored " + pastDueListing.Count() + " Position(s) with delinquent revenue.";
                                Log.Information("Saved {0} delinquent position(s) to 'DelinquentIncome' via ImportFileDataProcessing.SaveRevenue()", pastDueListing.Count());
                            }
                        }

                        // Finally, update PymtDue flags on received XLSX positions.
                        positionDataAccessComponent.UpdatePositionPymtDueFlags(ExtractPositionIdsForPymtDueProcessing(revenueListingToSave), true);
                    }
                }
                _ctx.Dispose();
            }

            // Missing amount & record count reflects error condition.
            return(importVmToUpdate);
        }