public async Task <IEnumerable <Billing> > CreateAsync(IEnumerable <PeriodicBillingSetting> settings, CancellationToken token = default(CancellationToken)) { using (var scope = transactionScopeBuilder.Create()) { var result = new List <Billing>(); var first = settings.First(); var companyId = first.CompanyId; var customers = (await customerQueryProcessor .GetByIdsAsync(settings.Select(x => x.CustomerId).Distinct().ToArray(), token)) .ToDictionary(x => x.Id); var holidays = (await holidayCalendarQueryProcessor.GetItemsAsync(companyId, token)).ToArray(); foreach (var setting in settings) { var billings = setting.GetBillings(customers[setting.CustomerId], holidays).ToArray(); result.AddRange((await billingSaveForInputProcessor.SaveAsync(billings, token)).ToArray()); await addPeriodicBillingCreatedQueryProcessor.SaveAsync(new PeriodicBillingCreated { PeriodicBillingSettingId = setting.Id, CreateYearMonth = setting.BaseDate, CreateBy = setting.UpdateBy, UpdateBy = setting.UpdateBy, }, token); } scope.Complete(); return(result); } }
public async Task <IEnumerable <PaymentAgency> > GetAsync(MasterSearchOption option, CancellationToken token = default(CancellationToken)) { if (option.Ids?.Any() ?? false) { return(await paymentAgencyGetByIdsQueryProcessor.GetByIdsAsync(option.Ids, token)); } return(await masterGetByCodesQueryProcessor.GetByCodesAsync(option.CompanyId, option.Codes, token)); }
/// <summary> /// 学習履歴登録 /// </summary> /// <param name="Matching"></param> /// <param name="CompanyId"></param> /// <param name="CustomerId"></param> /// <param name="PaymentAgencyId"></param> /// <param name="LoginUserId"></param> /// <param name="UpdateAt"></param> private async Task SaveKanaLearningAsync(IEnumerable <Matching> Matching, int CompanyId, int CustomerId, int PaymentAgencyId, int LoginUserId, DateTime UpdateAt, CancellationToken token = default(CancellationToken)) { if (CustomerId != 0) { var kana = (await customerGetByIdsQueryProcessor.GetByIdsAsync(new[] { CustomerId }, token)).FirstOrDefault()?.Kana ?? ""; var items = Matching.Where(x => !string.IsNullOrEmpty(x.PayerName) && x.PayerName != kana) .GroupBy(x => new { x.PayerName, x.SourceBankName, x.SourceBranchName }) .Select(g => new KanaHistoryCustomer { CompanyId = CompanyId, PayerName = g.Key.PayerName, SourceBankName = g.Key.SourceBankName ?? string.Empty, SourceBranchName = g.Key.SourceBranchName ?? string.Empty, CustomerId = CustomerId, HitCount = g.Count(), CreateAt = UpdateAt, UpdateAt = UpdateAt, CreateBy = LoginUserId, UpdateBy = LoginUserId, }); foreach (var item in items) { await updateKanaHistoryCustomerQueryProcessor.UpdateAsync(item, token); } } if (PaymentAgencyId != 0) { var kana = (await paymentAgencyGetByIdsQueryProcessor.GetByIdsAsync(new[] { PaymentAgencyId }, token)).FirstOrDefault()?.Kana ?? ""; var items = Matching.Where(x => !string.IsNullOrEmpty(x.PayerName) && x.PayerName != kana) .GroupBy(x => new { x.PayerName, x.SourceBankName, x.SourceBranchName }) .Select(g => new KanaHistoryPaymentAgency { CompanyId = CompanyId, PayerName = g.Key.PayerName, SourceBankName = g.Key.SourceBankName ?? string.Empty, SourceBranchName = g.Key.SourceBranchName ?? string.Empty, PaymentAgencyId = PaymentAgencyId, HitCount = g.Count(), CreateAt = UpdateAt, UpdateAt = UpdateAt, CreateBy = LoginUserId, UpdateBy = LoginUserId, }); foreach (var item in items) { await updateKanaHistoryPaymentAgencyQueryProcessor.UpdateAsync(item, token); } } }
public async Task <byte[]> GetAsync(AccountTransferImportSource source, CancellationToken token = default(CancellationToken)) { var importDataId = source.ImportDataId ?? 0; var importDataTask = importDataProcessor.GetAsync(importDataId, token: token); var companyTask = companyGetByIdsQueryProcessor.GetByIdsAsync(new[] { source.CompanyId }, token); await Task.WhenAll(importDataTask, companyTask); var importData = importDataTask.Result; var company = companyTask.Result.First(); var sources = importData.Details.Select(x => serializer.UnpackSingleObject(x.RecordItem)).ToArray(); var reportSource = sources.Select(x => new AccountTransferImportReport.ReportRow { Billing = x.Billings?.Single(b => b.Id == x.Billings.Min(y => y.Id)), TransferResultCode = x.TransferResultCode, TransferAmount = x.TransferAmount, TransferBankName = x.TransferBankName, TransferBranchName = x.TransferBranchName, TransferCustomerCode = x.TransferCustomerCode, TransferAccountName = x.TransferAccountName, }).ToArray(); if (!(reportSource?.Any() ?? false)) { return(null); } var report = new AccountTransferImportReport() { Name = $"口座振替結果データ一覧_{DateTime.Now:yyyyMMdd_HHmmss}" }; // 帳票生成 report.SetBasicPageSetting(company.Code, company.Name); report.SetData(reportSource); report.Run(); return(report.Convert()); }
/// <summary>取込処理</summary> public async Task <AccountTransferImportResult> ReadAsync(AccountTransferImportSource source, CancellationToken token = default(CancellationToken)) { var encoding = Encoding.GetEncoding(source.EncodingCodePage); var csv = encoding.GetString(source.Data); var companyTask = companyGetByIdQueryProcessor.GetByIdsAsync(new[] { source.CompanyId }, token); var currencyTask = currencyQueryProcessor.GetAsync(new CurrencySearch { CompanyId = source.CompanyId, Codes = new[] { DefaultCurrencyCode }, }, token); var agencyTask = paymentAgencyGetByIdsQueryProcessor.GetByIdsAsync(new[] { source.PaymentAgencyId }, token); await Task.WhenAll(companyTask, currencyTask, agencyTask); var company = companyTask.Result.First(); var currency = currencyTask.Result.First(); var agency = agencyTask.Result.First(); var helper = new Helper { GetBillingsAsync = async(companyId, paymentAgencyId, dueAt) => (await billingQueryProcessor.GetAccountTransferMatchingTargetListAsync(paymentAgencyId, dueAt, currency.Id)).ToList(), GetCustomersAsync = async(ids) => (await customerQueryProcessor.GetAsync(new CustomerSearch { Ids = ids, }, token)).ToDictionary(x => x.Id), }; var reader = helper.CreateReader((AccountTransferFileFormatId)agency.FileFormatId); reader.CompanyId = company.Id; reader.AggregateBillings = company.TransferAggregate == 1; reader.PaymentAgencyId = agency.Id; reader.TransferYear = source.TransferYear; reader.Encoding = encoding; reader.FileName = source.FileName; reader.IsAsync = true; reader.IsPlainText = true; var sources = await reader.ReadAsync(csv); var data = new ImportData { CompanyId = source.CompanyId, FileName = source.FileName, FileSize = encoding.GetByteCount(csv), CreateBy = source.LoginUserId, }; data.Details = sources.Select(x => new ImportDataDetail { ObjectType = 0, RecordItem = serializer.PackSingleObject(x), }).ToArray(); var dataSaved = await importDataProcessor.SaveAsync(data, token); var result = new AccountTransferImportResult { ImportData = dataSaved, ProcessResult = new ProcessResult { Result = true }, }; for (var i = 0; i < sources.Count; i++) { result.ReadCount++; if (sources[i].TransferResultCode == 0) { result.ValidCount++; result.ValidAmount += sources[i].TransferAmount; } else { result.InvalidCount++; result.InvalidAmount += sources[i].TransferAmount; } } result.InvalidSources = sources.Where(x => x.TransferResultCode != 0 || !(x.Billings?.Any() ?? false)).ToList(); result.Logs = sources.SelectMany(x => x.GetInvalidLogs()).ToList(); return(result); }
public async Task <byte[]> GetAsync(BillingAgingListSearch option, IProgressNotifier notifier = null, CancellationToken token = default(CancellationToken)) { var companyTask = companyQueryProcessor.GetAsync(new CompanySearch { Id = option.CompanyId, }, token); var appConTask = applicationControlGetByCompanyQueryProcessor.GetAsync(option.CompanyId, token); var settingTask = reportSettingQueryProcessor.GetAsync(option.CompanyId, ReportId, token); var loadTask = billingAgingListProcessor.GetAsync(option, notifier, token); var tasks = new List <Task> { companyTask, appConTask, settingTask, loadTask }; Task <IEnumerable <Currency> > currenciesTask = null; if (option.CurrencyId.HasValue) { currenciesTask = currencyGetByIdsQueryProcessor.GetByIdsAsync(new[] { option.CurrencyId.Value }, token); tasks.Add(currenciesTask); } await Task.WhenAll(tasks); var company = companyTask.Result.First(); var appCon = appConTask.Result; var settings = settingTask.Result.ToList(); var items = loadTask.Result.ToList(); var precition = currenciesTask?.Result.FirstOrDefault().Precision ?? 0; if (!items.Any()) { return(null); } var remianType = settings.GetReportSetting <ReportAdvanceReceivedType>(BillingRemainType); var displayCode = settings.GetReportSetting <ReportDoOrNot>(DisplayCustomerCode) == ReportDoOrNot.Do; var processor = remianType == ReportAdvanceReceivedType.UseMatchingAmount ? (IProcessor) new BillingAgingListDocumentProcessor { Company = company, Items = items, Option = option, Precision = precition, DisplayCustomerCode = displayCode, UseForeignCurrency = appCon.UseForeignCurrency == 1, } : new BillingAgingListReceiptDocumentProcessor { Company = company, Items = items, Option = option, Precision = precition, DisplayCustomerCode = displayCode, UseForeignCurrency = appCon.UseForeignCurrency == 1, }; using (var stream = new MemoryStream()) { using (var document = SpreadsheetDocument.Create(stream, SpreadsheetDocumentType.Workbook)) { processor.Process(document); } return(stream.ToArray()); } }
private async Task <Dictionary <int, Category> > GetBillingCategoryDictionary(IEnumerable <BillingImport> billingImport, CancellationToken token) => (await categoryIdenticalEntityGetByIdsQueryProcessor.GetByIdsAsync(billingImport.Select(x => x.BillingCategoryId).Distinct().ToArray(), token)) .ToDictionary(x => x.Id, x => x);