public InvoiceSource GetSingle(string id, long companyId) { InvoiceSource invoiceSource = this.GetAll(companyId) .FirstOrDefault(x => x.Id == Convert.ToInt32(id)); return(invoiceSource); }
public async Task <List <sbc_scrape.Joining.ExportRow> > Evaluate() { var startYear = 2017; var years = Enumerable.Range(startYear, DateTime.Now.Year - startYear + 1); //var invoices = await main.MediusFlow.LoadInvoiceSummaries(fl => years.Contains(fl.RegisteredDate.Year)); var invoices = await main.MediusFlow.LoadInvoices(fl => years.Contains(fl.RegisteredDate.Year)); var sieFiles = new System.IO.DirectoryInfo(settings.StorageFolderSIE) .GetFiles($"output_*.se") .Where(o => years.Any(p => o.Name.Contains(p.ToString()))) .Select(o => o.FullName); var sie = await SIE.SBCExtensions.ReadSIEFiles(sieFiles); var sbcInvoices = new InvoiceSource().ReadAll(settings.StorageFolderSbcHtml).Where(o => years.Contains(o.RegisteredDate.Year)).ToList(); var sbcReceipts = new ReceiptsSource().ReadAll(settings.StorageFolderSbcHtml).Where(o => years.Contains(o.Date.Year)).ToList(); var sbcTransactions = new BankTransactionSource().ReadAll(settings.StorageFolderSbcHtml).Where(o => years.Contains(o.AccountingDate.Year)).ToList(); //return sbc_scrape.Joining.JoinSbcSieMediusFlow.MatchMediusFlowWithSIE(years, invoices, sie.ToList(), sbcInvoices); var joined = sbc_scrape.Joining.JoinSbcSieMediusFlow.Testing(years, invoices, sie.ToList(), sbcInvoices, sbcReceipts, sbcTransactions); //var accountNames = sie.First().Children.OfType<AccountRecord>().ToDictionary(o => o.AccountId, o => o.AccountName); var accountNamesMF = invoices.Select(o => InvoiceSummary.Summarize(o)).GroupBy(o => o.AccountId).ToDictionary(o => o.Key, o => o.First().AccountName); var accountNames = sbcInvoices.GroupBy(o => o.AccountId).ToDictionary(o => o.Key, o => o.First().AccountName); foreach (var accountId in accountNames.Keys) { if (accountNamesMF.TryGetValue(accountId, out var val)) { accountNames[accountId] = val; } } return(joined.Select(o => o.ToExportRow(accountNames)).ToList()); }
private static InvoiceSource getEntityByModel(InvoiceSourceViewModel model) { if (model == null) { return(null); } InvoiceSource entity = new InvoiceSource(); entity.CodeCombinationId = model.CodeCombinationId; entity.StartDate = model.StartDate; entity.EndDate = model.EndDate; entity.Description = model.Description; entity.Id = model.Id; entity.SOBId = model.SOBId; if (model.Id == 0) { entity.CompanyId = AuthenticationHelper.CompanyId.Value; entity.CreateBy = AuthenticationHelper.UserId; entity.CreateDate = DateTime.Now; } else { entity.CompanyId = model.CompanyId; entity.CreateBy = model.CreateBy; entity.CreateDate = model.CreateDate; } entity.UpdateDate = DateTime.Now; entity.UpdateBy = AuthenticationHelper.UserId; return(entity); }
public string Update(InvoiceSource entity) { var originalEntity = this.Context.InvoiceSources.Find(entity.Id); this.Context.Entry(originalEntity).CurrentValues.SetValues(entity); this.Context.Entry(originalEntity).State = EntityState.Modified; this.Commit(); return(entity.Id.ToString()); }
public InvoiceSourceViewModel(InvoiceSource entity) { this.CodeCombinationId = entity.CodeCombinationId; this.StartDate = entity.StartDate; this.EndDate = entity.EndDate; this.Description = entity.Description; this.Id = entity.Id; this.SOBId = entity.SOBId; this.CompanyId = entity.CompanyId; this.CreateBy = entity.CreateBy; this.CreateDate = entity.CreateDate; this.UpdateBy = entity.UpdateBy; this.UpdateDate = entity.UpdateDate; }
public async Task <IActionResult> GetSupervisingAsync( string searchValue, Period period, List <InvoiceStatus> status, string sortField, bool sortAscending) { InvoiceSource source = await _invoiceService.GetSupervisingAsync( User.GetMerchantId(), User.GetEmployeeId(), status, period, searchValue, sortField, sortAscending, 0, int.MaxValue); string content; using (TextWriter stringWriter = new StringWriter()) { var svcWriter = new CsvHelper.CsvWriter(stringWriter); var records = new List <InvoiceSupervisingCsvRowModel>(); foreach (var invoice in source.Items) { records.Add(new InvoiceSupervisingCsvRowModel { Creator = await _merchantService.GetMerchantNameAsync(invoice.MerchantId), Number = invoice.Number, ClientName = invoice.ClientName, ClientEmail = invoice.ClientEmail, Amount = invoice.Amount, Currency = invoice.SettlementAsset.DisplayId, Status = invoice.Status.ToString(), DueDate = invoice.DueDate.ToIsoDateTime(), CreatedDate = invoice.CreatedDate.ToIsoDateTime() }); } svcWriter.WriteRecords(records); content = stringWriter.ToString(); } return(File(new MemoryStream(Encoding.UTF8.GetBytes(content)), "text/csv", "invoices.csv")); }
private async Task RefreshData() { InvoiceSource.Clear(); var child = MainHelper.FirebaseClient.Child("Invoices"); var fooPosts = await child.OnceAsync <Invoice>(); foreach (var item in fooPosts) { InvoiceSource.Add(new InvoiceVM() { Key = item.Key, InvoiceNo = item.Object.InvoiceNo, Amount = item.Object.Amount, Title = item.Object.Title, Date = item.Object.Date, Memo = item.Object.Memo, }); } }
public async Task RefreshInvoice() { InvoiceSource.Clear(); var child = MainHelper.FirebaseClient.Child("Invoices"); var fooPosts = await child.OnceAsync <Invoice>(); foreach (var item in fooPosts) { var fooItem = new InvoiceVM() { Amount = item.Object.Amount, Date = item.Object.Date, InvoiceNo = item.Object.InvoiceNo, Memo = item.Object.Title, Key = item.Key, }; InvoiceSource.Add(fooItem); } }
public async Task <IActionResult> GetSupervisingInvoicesAsync( string searchValue, Period period, List <PayInvoice.Client.Models.Invoice.InvoiceStatus> status, string sortField, bool sortAscending, int skip, int take) { InvoiceSource source = await _invoiceService.GetSupervisingAsync( User.GetMerchantId(), User.GetEmployeeId(), status, period, searchValue, sortField, sortAscending, skip, take); var model = new InvoicesGatheredInfoModel { List = new ListModel { Total = source.Total, CountPerStatus = source.CountPerStatus.ToDictionary(o => o.Key.ToString(), o => o.Value), Items = Mapper.Map <List <ListItemModel> >(source.Items) }, Balance = source.Balance, BaseAsset = source.BaseAsset, BaseAssetAccuracy = source.BaseAssetAccuracy, Statistic = new StatisticModel { MainStatistic = source.MainStatistic.ToDictionary(x => x.Key.ToString(), x => x.Value), SummaryStatistic = source.SummaryStatistic, Rates = source.Rates, HasErrorsInStatistic = source.HasErrorsInStatistic } }; return(Json(model)); }
private async Task <(int[], List <InvoiceFull>, List <RootRecord>, List <Invoice>, List <Receipt>, List <BankTransaction>)> Prepare(int[] years) { var store = new FileSystemKVStore(Tools.GetOutputFolder()); var invoiceStore = new SBCScan.InvoiceStore(store); var files = await invoiceStore.GetKeysParsed(); var invoices = (await Task.WhenAll(files.Where(o => years.Contains(o.RegisteredDate.Year)).Select(async o => await invoiceStore.Get(o)).ToList())).ToList(); var sieFolder = Tools.GetOutputFolder("SIE"); var sieFiles = new DirectoryInfo(sieFolder).GetFiles($"output_*.se").Select(o => o.Name).Where(o => years.Any(p => o.Contains(p.ToString()))); var sie = await SBCExtensions.ReadSIEFiles(sieFiles.Select(file => Tools.GetOutputFolder("SIE", file))); var dir = Tools.GetOutputFolder("sbc_html"); var sbcInvoices = new InvoiceSource().ReadAll(dir).Where(o => years.Contains(o.RegisteredDate.Year)).ToList(); var sbcReceipts = new ReceiptsSource().ReadAll(dir).Where(o => years.Contains(o.Date.Year)).ToList(); var sbcTransactions = new BankTransactionSource().ReadAll(dir).Where(o => years.Contains(o.CurrencyDate.Year)).ToList(); return(years, invoices, sie.ToList(), sbcInvoices, sbcReceipts, sbcTransactions); }
public InvoiceBatch LoadInvoices( InvoiceSource invoiceSource, Func <ApiFilter, IList <IssuedInvoice> > invoicePrefetch = null, Func <ApiFilter, IList <Contact> > contactPrefetch = null) { var data = (invoiceSource as ShoptetInvoiceSource)?.Content ?? throw new InvalidCastException($"{nameof(invoiceSource)} has to be of type {nameof(ShoptetInvoiceSource)}"); _prefetchedContacts = contactPrefetch?.Invoke(GetContactFilter(data)) ?? new List <Contact>(); _prefetchedInvoices = invoicePrefetch?.Invoke(GetInvoiceFilter(data)) ?? new List <IssuedInvoice>(); var batch = new InvoiceBatch(); foreach (var i in data.dataPackItem) { var contact = ParseContact(i); var invoice = ParseInvoice(i, contact); batch.Invoices.Add(new InvoicePair(invoice, contact)); } return(batch); }
public string Insert(InvoiceSource entity) { this.Context.InvoiceSources.Add(entity); this.Commit(); return(entity.Id.ToString()); }
public string Update(InvoiceSource entity) { return(this.repository.Update(entity)); }
public string Insert(InvoiceSource entity) { return(this.repository.Insert(entity)); }
public async Task MatchSbcHtmlAndSIE() { var year = 2020; var roots = await SBCExtensions.ReadSIEFiles(new[] { "output_20201209.se" }.Select(file => Tools.GetOutputFolder("SIE", file)), SBCExtensions.ProcessCompanyNameMode.SeparateIdAndName); var allVouchers = roots.SelectMany(o => o.Children).OfType <VoucherRecord>(); var resultRecords = roots.SelectMany(o => o.Children).OfType <ResultRecord>(); var accountChanged = allVouchers.Where(o => o.Transactions.Where( t => t.AccountId >= 40000 && t.AccountId < 70000 && t.Amount != 0).GroupBy(t => Math.Sign(t.Amount)).Count() > 1).ToList(); // From here, ignore AV allVouchers = allVouchers.Where(o => o.VoucherType != VoucherType.AV); //var byType = allVouchers.GroupBy(v => v.VoucherTypeCode).ToDictionary(g => g.Key, g => g.ToList()); var htmlFolder = Tools.GetOutputFolder("sbc_html"); var transactions = new BankTransactionSource().ReadAll(htmlFolder).Where(r => r.AccountingDate.Year == year).ToList(); bool IsIncomeAccount(int accountId) => accountId >= 30110 && accountId <= 32910; // BGINB // AG // IT-A06 - 16899 OBS Konto? // KI - 16410 "Skattefordran"? var bankgiroSum = transactions.Where(o => o.Amount > 0 && o.Text.Any()).Sum(o => o.Amount); // o.Reference.EndsWith("BGINB") || o.Reference.EndsWith(" AG")) var incomes = allVouchers.SelectMany(o => o.Transactions.Where(t => IsIncomeAccount(t.AccountId))); var incomesSum = incomes.Sum(o => o.Amount); var resIncomedSum = resultRecords.Where(o => IsIncomeAccount(o.AccountId)).Sum(o => o.Amount); //var soso = transactions.Where(o => o.Amount > 0).ToList(); var unusedVouchers = allVouchers.ToList(); var result = MatchTransactions(transactions, unusedVouchers, (0, 0)); var matched = result.matched; transactions = result.unmatched; //var unmatchedTxStrings = matchTx.Where(o => !o.Item2.Any()).Select(o => o.Item1.ToString()); //transactions = transactions.Where(tx => unmatchedTxStrings.Contains(tx.ToString())).ToList(); result = MatchTransactions(transactions, unusedVouchers, (-3, 3)); matched.AddRange(result.matched); transactions = result.unmatched; var withDate = transactions.Select(o => (LocalDate.FromDateTime(o.AccountingDate), $"TX\t{o}")) .Concat(unusedVouchers.Select(o => (o.Date, FullVoucher(o)))) .OrderBy(o => o.Item1).ToList(); string FullVoucher(VoucherRecord v) { return($"{v}\n\t\t" + string.Join("\n\t\t", v.Transactions.Select(o => $"{o.Amount} {o.CompanyName}"))); } var dbg = string.Join("\n", withDate.Select(o => $"{o.Item1.ToSimpleDateString()}\t{o.Item2}")); var invoices = new InvoiceSource().ReadAll(htmlFolder).Where(r => r.RegisteredDate.Year == year).ToList(); var receipts = new ReceiptsSource().ReadAll(htmlFolder).Where(r => r.Date.Year == year).ToList(); var recInv = receipts.Select(receipt => { return(new { Receipt = receipt, Invoices = invoices.Where(o => o.Amount == receipt.Amount && o.PaymentDate == receipt.Date).ToList() }); }).ToList(); var triedMatchedInvoices = invoices.Select(invoice => { var matchedVouchers = unusedVouchers .Where(o => o.Series == invoice.VerSeries) .Where(o => o.SerialNumber == invoice.VerNum) //.Where(o => o.GetTransactionsMaxAmount() == invoice.Amount && o.Date == NodaTime.LocalDate.FromDateTime(invoice.RegisteredDate)) //.Where(o => o.CompanyName == invoice.Supplier) .ToList(); if (matchedVouchers.Count() == 1) { RemoveVouchers(matchedVouchers, unusedVouchers); } return(new { Invoice = invoice, Vouchers = matchedVouchers }); }).ToList(); var matchedInvoices = triedMatchedInvoices.Where(o => o.Vouchers.Count == 1).Select(o => new { o.Invoice, Voucher = o.Vouchers.Single() }).ToList(); var mismatch = triedMatchedInvoices.Where(o => o.Vouchers.Count != 1).ToList(); var matchedReceipts = MatchReceipts(receipts, unusedVouchers); var doubleUse = matchedReceipts.SelectMany(o => o.Item2).GroupBy(o => o.Id).Where(o => o.Count() > 1).ToList(); //var sieDir = Path.Join(Tools.GetCurrentOrSolutionDirectory(), "sbc_scrape", "scraped", "SIE"); //var tmp = File.ReadAllText(Path.Combine(sieDir, "accountsexport.txt")); }
public async Task <InvoiceSource> GetSupervisingAsync( string merchantId, string employeeId, IReadOnlyList <InvoiceStatus> status, Period period, string searchValue, string sortField, bool sortAscending, int skip, int take) { MerchantsSupervisorMembershipResponse membership = await _payInternalClient.GetSupervisorMembershipWithMerchantsAsync(employeeId); var invoiceslist = new List <InvoiceModel>(); if (membership?.Merchants.Any() ?? false) { foreach (var merchant in membership.Merchants) { var invoices = await _payInvoiceClient.GetMerchantInvoicesAsync(merchant); invoiceslist.AddRange(invoices); } } IReadOnlyList <Invoice> result = await FilterAsync(invoiceslist, period, searchValue, sortField, sortAscending); var source = new InvoiceSource { Total = result.Count, CountPerStatus = new Dictionary <InvoiceStatus, int>(), Balance = 0, MainStatistic = new Dictionary <InvoiceStatus, double>(), SummaryStatistic = Enumerable.Empty <SummaryStatisticModel>(), Rates = new Dictionary <string, double>(), HasErrorsInStatistic = false }; if (status.Count > 0) { source.Items = result .Where(o => status.Contains(o.Status)) .Skip(skip) .Take(take) .ToList(); } else { source.Items = result .Skip(skip) .Take(take) .ToList(); } foreach (InvoiceStatus value in Enum.GetValues(typeof(InvoiceStatus))) { source.CountPerStatus[value] = result.Count(o => o.Status == value); } return(source); }
public void Should_Clone_AvailSource() { var availSource = new InvoiceSource() { Identifier = "TestAvailSource", InvoiceGroups = new [] { new InvoiceGroup { Identifier = "TestGroupIdentifier", Invoices = new [] { new Invoice { DayTimes = new [] { new InvoiceDayTime { ProgramName = "TestProgram", Days = CustomDaysOfWeek.MondayToFriday, BroadcastTimeRange = new TimeSpanRange(TimeSpan.FromHours(0), TimeSpan.FromHours(12)) } }, Name = "TestAvail", OutletName = "TestOutlet", Periods = new [] { new InvoicePeriod { AdjustedStartDate = new DateTime(2021, 1, 1), AdjustedEndDate = new DateTime(2021, 3, 1), AllocatedDayOfWeek = DayOfWeek.Monday | DayOfWeek.Tuesday | DayOfWeek.Wednesday, InvoicePeriodType = InvoicePeriodType.DayDetailedPeriodType, OriginalStartDate = new DateTime(2021, 1, 1), OriginalEndDate = new DateTime(2021, 3, 1), Rate = 100.0m, SpotsPerWeek = "10", DemoValues = new [] { new DemoValue { DemoCategoryRef = "TestDemoCategoryRef", DemoValueType = DemographicValueTypes.CPM, Value = "value" } }, OriginalSpotsPerDayOfWeek = new ItemsPerDayOfWeek { Monday = 5, Tuesday = 3, Wednesday = 2, Thursday = 1 } } }, ProgramNames = new [] { "Program name" }, SourceModel = new TimeSpan(), SourceModelLineNumber = 10, SourceModelType = SourceModelType.SpotCableOrder, SpotLength = "30", UUID = "fake uuid" } }, IsPackage = true, DemoCategories = new [] { new InvoiceDemoCategory { AgeFrom = 18, AgeTo = 56, DemoValueType = DemographicValueTypes.CPM, Group = "TestGroup", Identifier = "TestIdentifier" } } } }, MediaType = InvoiceSourceMediaTypes.MediaType2, OriginalProposalStartDate = new DateTime(2021, 1, 1), OriginalProposalEndDate = new DateTime(2021, 3, 1), Outlets = new [] { new InvoiceOutlet { Identifier = "TestOutletIdentifier", MarketZone = 100, MediaType = InvoiceSourceMediaTypes.MediaType2, Name = "TestOutletName" } } }; // clone the original object var cloned = availSource.Clone(); Assert.AreEqual(availSource.Identifier, cloned.Identifier); Assert.AreEqual(availSource.MediaType, cloned.MediaType); Assert.AreEqual(availSource.OriginalProposalStartDate, cloned.OriginalProposalStartDate); Assert.AreEqual(availSource.OriginalProposalEndDate, cloned.OriginalProposalEndDate); Assert.AreEqual(availSource.InvoiceGroups.Length, cloned.InvoiceGroups.Length); Assert.AreEqual(availSource.InvoiceGroups[0].Invoices.Length, cloned.InvoiceGroups[0].Invoices.Length); Assert.AreEqual(availSource.InvoiceGroups[0].Invoices[0].Name, cloned.InvoiceGroups[0].Invoices[0].Name); Assert.AreEqual(availSource.InvoiceGroups[0].Invoices[0].OutletName, cloned.InvoiceGroups[0].Invoices[0].OutletName); Assert.AreEqual(availSource.InvoiceGroups[0].Invoices[0].UUID, cloned.InvoiceGroups[0].Invoices[0].UUID); Assert.AreEqual(availSource.InvoiceGroups[0].Invoices[0].SourceModelType, cloned.InvoiceGroups[0].Invoices[0].SourceModelType); Assert.AreEqual(availSource.InvoiceGroups[0].Invoices[0].SourceModelLineNumber, cloned.InvoiceGroups[0].Invoices[0].SourceModelLineNumber); Assert.AreEqual(availSource.InvoiceGroups[0].Invoices[0].SpotLength, cloned.InvoiceGroups[0].Invoices[0].SpotLength); Assert.AreEqual(availSource.InvoiceGroups[0].Invoices[0].OutletName, cloned.InvoiceGroups[0].Invoices[0].OutletName); Assert.AreEqual(availSource.InvoiceGroups[0].Invoices[0].DayTimes[0].Days, cloned.InvoiceGroups[0].Invoices[0].DayTimes[0].Days); Assert.AreEqual(availSource.InvoiceGroups[0].Invoices[0].DayTimes[0].ProgramName, cloned.InvoiceGroups[0].Invoices[0].DayTimes[0].ProgramName); Assert.AreEqual(availSource.InvoiceGroups[0].Invoices[0].Periods[0].AdjustedStartDate, cloned.InvoiceGroups[0].Invoices[0].Periods[0].AdjustedStartDate); Assert.AreEqual(availSource.InvoiceGroups[0].Invoices[0].Periods[0].AdjustedEndDate, cloned.InvoiceGroups[0].Invoices[0].Periods[0].AdjustedEndDate); Assert.AreEqual(availSource.InvoiceGroups[0].StartDate, cloned.InvoiceGroups[0].StartDate); Assert.AreEqual(availSource.InvoiceGroups[0].EndDate, cloned.InvoiceGroups[0].EndDate); Assert.AreEqual(availSource.InvoiceGroups[0].DemoCategories[0].Identifier, cloned.InvoiceGroups[0].DemoCategories[0].Identifier); Assert.AreEqual(availSource.InvoiceGroups[0].DemoCategories[0].AgeFrom, cloned.InvoiceGroups[0].DemoCategories[0].AgeFrom); Assert.AreEqual(availSource.InvoiceGroups[0].DemoCategories[0].AgeTo, cloned.InvoiceGroups[0].DemoCategories[0].AgeTo); Assert.AreEqual(availSource.InvoiceGroups[0].DemoCategories[0].DemoValueType, cloned.InvoiceGroups[0].DemoCategories[0].DemoValueType); Assert.AreEqual(availSource.Outlets[0].Identifier, cloned.Outlets[0].Identifier); Assert.AreEqual(availSource.Outlets[0].Name, cloned.Outlets[0].Name); Assert.AreEqual(availSource.Outlets[0].MediaType, cloned.Outlets[0].MediaType); Assert.AreEqual(availSource.Outlets[0].MarketZone, cloned.Outlets[0].MarketZone); // modify some properties availSource.Identifier = "TestAvailSourceModified"; availSource.InvoiceGroups[0].Identifier = "TestGroupIdentifierModified"; availSource.InvoiceGroups[0].Invoices[0].Name = "TestAvailModified"; availSource.InvoiceGroups[0].Invoices[0].ProgramNames[0] = "Program name modified"; availSource.InvoiceGroups[0].Invoices[0].SourceModelType = SourceModelType.SpotCableProposal; availSource.InvoiceGroups[0].Invoices[0].DayTimes[0].Days = CustomDaysOfWeek.Weekend; availSource.Outlets[0].MarketZone = 200; availSource.Outlets[0].Name = "TestOutletNameModified"; // ensure values changed are different Assert.AreNotEqual(availSource.Identifier, cloned.Identifier); Assert.AreNotEqual(availSource.InvoiceGroups[0].Identifier, cloned.InvoiceGroups[0].Identifier); Assert.AreNotEqual(availSource.InvoiceGroups[0].Invoices[0].Name, cloned.InvoiceGroups[0].Invoices[0].Name); Assert.AreNotEqual(availSource.InvoiceGroups[0].Invoices[0].ProgramNames[0], cloned.InvoiceGroups[0].Invoices[0].ProgramNames[0]); Assert.AreNotEqual(availSource.InvoiceGroups[0].Invoices[0].SourceModelType, cloned.InvoiceGroups[0].Invoices[0].SourceModelType); Assert.AreNotEqual(availSource.InvoiceGroups[0].Invoices[0].DayTimes[0].Days, cloned.InvoiceGroups[0].Invoices[0].DayTimes[0].Days); Assert.AreNotEqual(availSource.Outlets[0].MarketZone, cloned.Outlets[0].MarketZone); Assert.AreNotEqual(availSource.Outlets[0].Name, cloned.Outlets[0].Name); }