/// <summary>
 /// Helper method that forms the DepositLogProjectionViewModel instance.
 /// </summary>
 /// <param name="depositLogSimpleBusinessDaysViewModel"></param>
 /// <param name="payments"></param>
 /// <param name="depositLogAmountForMonth"></param>
 /// <param name="numberOfLastWorkingDays"></param>
 /// <returns></returns>
 private DepositLogProjectionViewModel GetDepositLogProjectionViewModel(DepositLogProjectionViewModel depositLogSimpleBusinessDaysViewModel, long?payments, decimal?depositLogAmountForMonth, int numberOfLastWorkingDays)
 {
     if (payments != null)
     {
         depositLogSimpleBusinessDaysViewModel                  = new DepositLogProjectionViewModel();
         depositLogSimpleBusinessDaysViewModel.Payments         = payments;
         depositLogSimpleBusinessDaysViewModel.DepositLogAmount = depositLogAmountForMonth;
         depositLogSimpleBusinessDaysViewModel.NumberOfLastWorkingDaysOrWeeks = numberOfLastWorkingDays;
         return(depositLogSimpleBusinessDaysViewModel);
     }
     else
     {
         return(depositLogSimpleBusinessDaysViewModel);
     }
 }
 /// <summary>
 /// To get the Projected Cash From Deposit Log when number of last working days are given.
 /// </summary>
 /// <param name="clientCode"></param>
 /// <param name="numberOfLastWorkingDays"></param>
 /// <param name="month"></param>
 /// <param name="year"></param>
 /// <param name="savedLastNumberOfBusinessDays"></param>
 /// <returns></returns>
 public DepositLogProjectionViewModel GetProjectedCashFromSimpleBusinessDays(string clientCode, int numberOfLastWorkingDays, int month, int year, int savedLastNumberOfBusinessDays)
 {
     try
     {
         DepositLogProjectionViewModel depositLogSimpleBusinessDaysViewModel = null;
         DepositLogSimpleBusinessDays  depositLogSimpleBusinessDays          = null;
         DateTime endDate = DateTime.Today;
         decimal? depositLogAmountForMonth = 0;
         long?    payments = null;
         if (new DateTime(year, month, 1) < new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1))
         {
             endDate = new DateTime(year, month, DateTime.DaysInMonth(year, month));
         }
         ClientDepositLogInfo clientDepositLogInfo = new ClientDepositLogInfo();
         clientDepositLogInfo = _depositLogResposiotory.GetDepositLogStartDateAndNumberOfDepositDates(clientCode, numberOfLastWorkingDays, endDate);
         if (clientDepositLogInfo.NumberOfDepositDates > 0)
         {
             depositLogSimpleBusinessDays = _depositLogResposiotory.GetProjectedCashFromSimpleBusinessDays(clientCode, clientDepositLogInfo.NumberOfDepositDates, month, year, clientDepositLogInfo.DepositStartDate, endDate);
             if (depositLogSimpleBusinessDays != null)
             {
                 depositLogSimpleBusinessDaysViewModel                                = new DepositLogProjectionViewModel();
                 depositLogSimpleBusinessDaysViewModel.Payments                       = depositLogSimpleBusinessDays.Payments;
                 depositLogSimpleBusinessDays.DepositLogPaymentsOnWeekEnds            = depositLogSimpleBusinessDays.DepositLogPaymentsOnWeekEnds != null ? (decimal)depositLogSimpleBusinessDays.DepositLogPaymentsOnWeekEnds : (decimal)0.0;
                 depositLogSimpleBusinessDaysViewModel.DepositLogAmount               = depositLogSimpleBusinessDays.DepositLogPaymentsOnWeekDays != null ? (decimal)depositLogSimpleBusinessDays.DepositLogPaymentsOnWeekDays : (decimal)0.0;
                 depositLogSimpleBusinessDaysViewModel.DepositLogAmount               = ((depositLogSimpleBusinessDaysViewModel.DepositLogAmount / clientDepositLogInfo.NumberOfDepositDates) * depositLogSimpleBusinessDays.BusinessDays) + depositLogSimpleBusinessDays.DepositLogPaymentsOnWeekEnds;
                 depositLogSimpleBusinessDaysViewModel.NumberOfLastWorkingDaysOrWeeks = clientDepositLogInfo.NumberOfDepositDates;
                 return(depositLogSimpleBusinessDaysViewModel);
             }
             else
             {
                 return(depositLogSimpleBusinessDaysViewModel);
             }
         }
         else
         {
             payments = _depositLogResposiotory.GetClientPaymentForMonth(clientCode, month, year);
             depositLogSimpleBusinessDaysViewModel = GetDepositLogProjectionViewModel(depositLogSimpleBusinessDaysViewModel, payments, depositLogAmountForMonth, clientDepositLogInfo.NumberOfDepositDates);
             return(depositLogSimpleBusinessDaysViewModel);
         }
     }
     catch (Exception ex)
     {
         _logger.Log(ex, LogLevel.Error, ex.Message);
         return(null);
     }
 }
        /// <summary>
        /// To get the Projected Cash From Deposit Log when number of weeks are given.
        /// </summary>
        /// <param name="clientCode"></param>
        /// <param name="month"></param>
        /// <param name="year"></param>
        /// <param name="numberOfWeeks"></param>
        /// <returns></returns>
        public DepositLogProjectionViewModel GetProjectedCashOfPreviousWeeks(string clientCode, int month, int year, int numberOfWeeks)
        {
            DepositLogProjectionViewModel depositLogProjectionViewModel = new DepositLogProjectionViewModel();

            try
            {
                decimal  totalForecast      = 0;
                decimal? totalDepositAmount = 0;
                DateTime startDate          = new DateTime(year, month, 1);
                DateTime endDate            = DateTime.Today;
                depositLogProjectionViewModel.Payments = _depositLogResposiotory.GetClientPaymentForMonth(clientCode, month, year);
                if (new DateTime(year, month, 1) < new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1))
                {
                    endDate = new DateTime(year, month, DateTime.DaysInMonth(year, month));
                }

                totalDepositAmount = _depositLogResposiotory.GetDepositLogAmountFromGivenDatesIncludingWeekEnds(clientCode, month, year, startDate, endDate);
                List <DepositLogWeekDays> depositLogWeekDaysList = _depositLogResposiotory.GetProjectedCashOfPreviousWeeks(clientCode, month, year, numberOfWeeks, endDate);
                if (depositLogWeekDaysList != null && depositLogWeekDaysList.Count == 5)
                {
                    foreach (DepositLogWeekDays depositLogWeekDays in depositLogWeekDaysList)
                    {
                        decimal averageDepositLogAmountOfWeekDay  = depositLogWeekDays.DepositAmount / depositLogWeekDays.WeekDaysCompleted;
                        decimal forecastDepositLogAmountOfWeekDay = averageDepositLogAmountOfWeekDay * depositLogWeekDays.WeekDaysLeft;
                        totalForecast += forecastDepositLogAmountOfWeekDay;
                        depositLogProjectionViewModel.NumberOfLastWorkingDaysOrWeeks = depositLogWeekDays.WeekDaysCompleted;
                    }
                    depositLogProjectionViewModel.DepositLogAmount  = totalDepositAmount != null ? (decimal)totalDepositAmount : (decimal)0.0;
                    depositLogProjectionViewModel.DepositLogAmount += totalForecast;
                    return(depositLogProjectionViewModel);
                }
                else
                {
                    depositLogProjectionViewModel.NumberOfLastWorkingDaysOrWeeks = 0;
                    depositLogProjectionViewModel.DepositLogAmount = totalForecast;
                    return(depositLogProjectionViewModel);
                }
            }
            catch (Exception ex)
            {
                _logger.Log(ex, LogLevel.Error, ex.Message);
                return(depositLogProjectionViewModel);
            }
        }
Exemple #4
0
        /// <summary>
        /// To update the projected cash for all clients when attribute value is changed.
        /// </summary>
        /// <param name="attribute"></param>
        private void UpdateProjectedCashForAllClients(AttributesBusinessModel attribute)
        {
            IEnumerable <Client> clientList = _m3pactContext.Client.ToList();

            foreach (Client client in clientList)
            {
                if (client.IsActive == DomainConstants.RecordStatusActive)
                {
                    DepositLogProjectionViewModel depositLogSimpleBusinessDaysViewModel = new DepositLogProjectionViewModel();
                    depositLogSimpleBusinessDaysViewModel = _depositLogRepository.GetProjectedCashForAClient(client.ClientId, Convert.ToInt32(attribute.AttributeValue), DateTime.Today.Month, DateTime.Today.Year);
                    if (depositLogSimpleBusinessDaysViewModel != null)
                    {
                        if (depositLogSimpleBusinessDaysViewModel.Payments != null || depositLogSimpleBusinessDaysViewModel.NumberOfLastWorkingDaysOrWeeks > 0)
                        {
                            _depositLogRepository.SaveProjectedCashOfAClient(client.ClientId, depositLogSimpleBusinessDaysViewModel);
                        }
                    }
                }
            }
        }