private IEnumerable <JournalVoucherReportOutputItem> CreateJournalVoucherOutputItemsForDist(
            string fundId,
            string primaryFundId,
            List <Domain.Core.DistDbModels.Gl00100> distFunds,
            decimal entryValue,
            int entryRowIndex,
            bool isExceptionRule,
            JournalVoucherType journalVoucher,
            JournalVoucherMatchingResultBuilder matchingResultBuilder)
        {
            if (entryValue == 0)
            {
                return(Enumerable.Empty <JournalVoucherReportOutputItem>());
            }

            (string debitFundId, string creditFundId) = GetDebitAndCreditFundIdsForRemit(primaryFundId, entryValue);

            var debitFund  = distFunds.FirstOrDefault(t => t.Actnumbr3.Trim() == debitFundId);
            var creditFund = distFunds.FirstOrDefault(t => t.Actnumbr3.Trim() == creditFundId);

            if (debitFund == null)
            {
                matchingResultBuilder.ReportUnmatchedDistFund(entryRowIndex, _sheetName, primaryFundId, journalVoucher, debitFundId);
                return(Enumerable.Empty <JournalVoucherReportOutputItem>());
            }

            if (creditFund == null)
            {
                matchingResultBuilder.ReportUnmatchedDistFund(entryRowIndex, _sheetName, primaryFundId, journalVoucher, creditFundId);
                return(Enumerable.Empty <JournalVoucherReportOutputItem>());
            }

            string debitAccountNumber = $"{primaryFundId}.{debitFund.Actnumbr2.Trim()}.{debitFundId}";

            if (isExceptionRule)
            {
                fundId = fundId.Replace('-', '.');
                if (fundId.IndexOf('.') == 3)
                {
                    fundId = fundId.Remove(3, 1);
                }
                debitAccountNumber = $"{fundId}.{debitFundId}";
            }
            string creditAccountNumber = $"{primaryFundId}.{creditFund.Actnumbr2.Trim()}.{creditFundId}";

            if (isExceptionRule)
            {
                fundId = fundId.Replace('-', '.');
                if (fundId.IndexOf('.') == 3)
                {
                    fundId = fundId.Remove(3, 1);
                }
                creditAccountNumber = $"{fundId}.{creditFundId}";
            }

            return(new[] {
                CreateDebitJournalVoucherOutputItem(debitAccountNumber, debitFund.Actdescr.Trim(), entryValue, journalVoucher, DbSource.DIST),
                CreateCreditJournalVoucherOutputItem(creditAccountNumber, creditFund.Actdescr.Trim(), entryValue, journalVoucher, DbSource.DIST)
            });
        }
        private IEnumerable <JournalVoucherReportOutputItem> CreateJournalVoucherOutputItemsForGc(
            string fundId,
            string primaryFundId,
            List <Domain.Core.GcDbModels.Gl00100> gcFunds,
            decimal entryValue,
            int entryRowIndex,
            bool isExceptionRule,
            JournalVoucherType journalVoucher,
            JournalVoucherMatchingResultBuilder matchingResultBuilder)
        {
            if (entryValue == 0)
            {
                return(Enumerable.Empty <JournalVoucherReportOutputItem>());
            }

            string debitFundId  = string.Empty;
            string creditFundId = string.Empty;

            var getDebitAndCreditForInvestmentJournalVoucherResult = GetDebitAndCreditForInvestmentJournalVoucher(journalVoucher, primaryFundId, entryValue);

            debitFundId  = getDebitAndCreditForInvestmentJournalVoucherResult.debit;
            creditFundId = getDebitAndCreditForInvestmentJournalVoucherResult.credit;
            var debitFund  = gcFunds.FirstOrDefault(t => t.Actnumbr5.Trim() == debitFundId);
            var creditFund = gcFunds.FirstOrDefault(t => t.Actnumbr5.Trim() == creditFundId);

            if (debitFund == null)
            {
                matchingResultBuilder.ReportUnmatchedGcFund(entryRowIndex, _sheetName, primaryFundId, journalVoucher, debitFundId);
                return(Enumerable.Empty <JournalVoucherReportOutputItem>());
            }

            if (creditFund == null)
            {
                matchingResultBuilder.ReportUnmatchedGcFund(entryRowIndex, _sheetName, primaryFundId, journalVoucher, creditFundId);
                return(Enumerable.Empty <JournalVoucherReportOutputItem>());
            }

            string debitAccountNumber = $"{primaryFundId}.{debitFund.Actnumbr2.Trim()}.{debitFund.Actnumbr3.Trim()}.{debitFund.Actnumbr4.Trim()}.{debitFundId}";

            if (isExceptionRule)
            {
                fundId             = fundId.Replace('-', '.');
                debitAccountNumber = $"{fundId}.{debitFundId}";
            }
            string creditAccountNumber = $"{primaryFundId}.{creditFund.Actnumbr2.Trim()}.{debitFund.Actnumbr3.Trim()}.{debitFund.Actnumbr4.Trim()}.{creditFundId}";

            if (isExceptionRule)
            {
                fundId = fundId.Replace('-', '.');
                creditAccountNumber = $"{fundId}.{creditFundId}";
            }

            return(new[] {
                CreateDebitJournalVoucherOutputItem(debitAccountNumber, debitFund.Actdescr.Trim(), entryValue, journalVoucher, DbSource.GC),
                CreateCreditJournalVoucherOutputItem(creditAccountNumber, creditFund.Actdescr.Trim(), entryValue, journalVoucher, DbSource.GC)
            });
        }
        public MemoryStream Execute(Stream inputStream, int year, List <MonthlyImportFundExceptionRule> exceptionRules)
        {
            List <JournalVoucherReportOutputItem> results = new List <JournalVoucherReportOutputItem>();
            var matchingResultBuilder = new JournalVoucherMatchingResultBuilder();

            foreach (var processor in _sheetProcessors)
            {
                results.AddRange(processor.Process(inputStream, year, matchingResultBuilder, exceptionRules));
            }

            return(_exportingService.GetJournalVoucherReportExcel(results, matchingResultBuilder.UnmatchedFunds));
        }
        private IEnumerable <JournalVoucherReportOutputItem> CreateJournalVoucherOutputItemsForGc(
            string fundId,
            string primaryFundId,
            List <Domain.Core.GcDbModels.Gl00100> gcFunds,
            WarrantsInterestSheetInputItem input,
            JournalVoucherMatchingResultBuilder matchingResultBuilder)
        {
            var results = new List <JournalVoucherReportOutputItem>();

            results.AddRange(
                CreateJournalVoucherOutputItemsForGc(
                    input.FundId, primaryFundId, gcFunds, input.WarrantInterest, input.RowIndex, input.IsExceptionRuleMatched, JournalVoucherType.WarrantInterest, matchingResultBuilder));

            return(results);
        }
        private IEnumerable <JournalVoucherReportOutputItem> CreateJournalVoucherOutputItemsForDist(
            string fundId,
            string primaryFundId,
            List <Domain.Core.DistDbModels.Gl00100> distFunds,
            RemitsSheetInputItem input,
            JournalVoucherMatchingResultBuilder matchingResultBuilder)
        {
            var results = new List <JournalVoucherReportOutputItem>();

            results.AddRange(
                CreateJournalVoucherOutputItemsForDist(
                    fundId, primaryFundId, distFunds, input.Remits, input.RowIndex, input.IsExceptionRuleMatched, JournalVoucherType.Remits, matchingResultBuilder));

            return(results);
        }
Example #6
0
        public override IEnumerable <JournalVoucherReportOutputItem> Process(
            Stream inputStream,
            int year,
            JournalVoucherMatchingResultBuilder matchingResultBuilder,
            List <MonthlyImportFundExceptionRule> exceptionRules)
        {
            List <JournalVoucherReportOutputItem> results = new List <JournalVoucherReportOutputItem>();

            const int warrantsSheetIndex     = 1;
            var       warrantSheetInputItems = WarrantSheetParser.Parse(inputStream, warrantsSheetIndex, exceptionRules);
            var       funds = _fundsRepository.Get(t => t.Year == year).ToList();

            foreach (var warrantInput in warrantSheetInputItems)
            {
                var primaryFundId = warrantInput.IsExceptionRuleMatched ? warrantInput.FundId.Split('.')[0] : warrantInput.FundId.Split('-')[0];
                var existingFund  = funds.FirstOrDefault(t => t.FundNumber.Trim() == primaryFundId);
                if (existingFund == null)
                {
                    matchingResultBuilder.ReportUnmatchedFund(warrantInput.RowIndex, _sheetName, primaryFundId);
                    continue;
                }

                if (existingFund?.DbSource == DbSource.GC)
                {
                    var gcFunds = _gcDbFundRepo.Get(t => t.FundNumber.StartsWith(primaryFundId)).ToList();
                    results.AddRange(CreateJournalVoucherOutputItemsForGc(warrantInput.FundId, primaryFundId, gcFunds, warrantInput, matchingResultBuilder));
                }
                else
                {
                    primaryFundId = Regex.Replace(warrantInput.FundId, @"[-.]", "")
                                    .Truncate(9)
                                    .Remove(6, 1);
                    var distFunds = _distDbFundRepo.Get(t => t.FundNumber.StartsWith(primaryFundId)).ToList();

                    results.AddRange(CreateJournalVoucherOutputItemsForDist(warrantInput.FundId, primaryFundId, distFunds, warrantInput, matchingResultBuilder));
                }
            }

            return(results);
        }
Example #7
0
 public abstract IEnumerable <JournalVoucherReportOutputItem> Process(
     Stream inputStream,
     int year,
     JournalVoucherMatchingResultBuilder matchingResultBuilder,
     List <MonthlyImportFundExceptionRule> exceptionRules);
Example #8
0
        private IEnumerable <JournalVoucherReportOutputItem> CreateJournalVoucherOutputItemsForGc(
            string fundId,
            string primaryFundId,
            List <Domain.Core.GcDbModels.Gl00100> gcFunds,
            decimal entryValue,
            int entryRowIndex,
            bool isExceptionRule,
            JournalVoucherType journalVoucher,
            JournalVoucherMatchingResultBuilder matchingResultBuilder)
        {
            if (entryValue == 0)
            {
                return(Enumerable.Empty <JournalVoucherReportOutputItem>());
            }

            string debitFundId  = string.Empty;
            string creditFundId = string.Empty;

            switch (journalVoucher)
            {
            case JournalVoucherType.WarrantIssues:
                (debitFundId, creditFundId) = GetDebitAndCreditFundIdsForWarrantIssues(primaryFundId, entryValue);
                break;

            case JournalVoucherType.WarrantPresented:
                (debitFundId, creditFundId) = GetDebitAndCreditFundIdsForWarrantPresented(primaryFundId, entryValue);
                break;

            case JournalVoucherType.WarrantCancels:
                (debitFundId, creditFundId) = GetDebitAndCreditFundIdsForWarrantCancels(primaryFundId, entryValue);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(journalVoucher));
            }
            var debitFund  = gcFunds.FirstOrDefault(t => t.Actnumbr5.Trim() == debitFundId);
            var creditFund = gcFunds.FirstOrDefault(t => t.Actnumbr5.Trim() == creditFundId);

            if (debitFund == null)
            {
                matchingResultBuilder.ReportUnmatchedGcFund(entryRowIndex, _sheetName, primaryFundId, journalVoucher, debitFundId);
                return(Enumerable.Empty <JournalVoucherReportOutputItem>());
            }

            if (creditFund == null)
            {
                matchingResultBuilder.ReportUnmatchedGcFund(entryRowIndex, _sheetName, primaryFundId, journalVoucher, creditFundId);
                return(Enumerable.Empty <JournalVoucherReportOutputItem>());
            }

            string debitAccountNumber = $"{primaryFundId}.{debitFund.Actnumbr2.Trim()}.{debitFund.Actnumbr3.Trim()}.{debitFund.Actnumbr4.Trim()}.{debitFundId}";

            if (isExceptionRule)
            {
                fundId             = fundId.Replace('-', '.');
                debitAccountNumber = $"{fundId}.{debitFundId}";
            }

            string creditAccountNumber = $"{primaryFundId}.{creditFund.Actnumbr2.Trim()}.{debitFund.Actnumbr3.Trim()}.{debitFund.Actnumbr4.Trim()}.{creditFundId}";

            if (isExceptionRule)
            {
                fundId = fundId.Replace('-', '.');
                creditAccountNumber = $"{fundId}.{creditFundId}";
            }

            return(new[] {
                CreateDebitJournalVoucherOutputItem(debitAccountNumber, debitFund.Actdescr.Trim(), entryValue, journalVoucher, DbSource.GC),
                CreateCreditJournalVoucherOutputItem(creditAccountNumber, creditFund.Actdescr.Trim(), entryValue, journalVoucher, DbSource.GC)
            });
        }