-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
242 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using Faktur.Contracts.Receipts; | ||
using Faktur.Domain.Receipts; | ||
using Faktur.Domain.Receipts.Events; | ||
using Logitar.EventSourcing; | ||
using Logitar.Portal.Contracts; | ||
|
||
namespace Faktur.ETL.Worker; | ||
|
||
internal static class AggregateExtensions | ||
{ | ||
public static void SetDates(this AggregateRoot aggregate, Aggregate model) | ||
{ | ||
foreach (DomainEvent change in aggregate.Changes) | ||
{ | ||
if (change.Version > 1) | ||
{ | ||
change.OccurredOn = model.UpdatedOn; | ||
} | ||
else | ||
{ | ||
change.OccurredOn = model.CreatedOn; | ||
} | ||
} | ||
} | ||
|
||
public static void SetDates(this ReceiptAggregate aggregate, Receipt model) | ||
{ | ||
foreach (DomainEvent change in aggregate.Changes) | ||
{ | ||
if (change is ReceiptCategorizedEvent categorized && model.ProcessedOn.HasValue) | ||
{ | ||
categorized.OccurredOn = model.ProcessedOn.Value == default ? model.UpdatedOn : model.ProcessedOn.Value; | ||
} | ||
else if (change.Version > 1) | ||
{ | ||
change.OccurredOn = model.UpdatedOn; | ||
} | ||
else | ||
{ | ||
change.OccurredOn = model.CreatedOn; | ||
} | ||
} | ||
} | ||
} |
40 changes: 0 additions & 40 deletions
40
backend/tools/Faktur.ETL.Worker/Commands/ExtractActorsCommandHandler.cs
This file was deleted.
Oops, something went wrong.
5 changes: 3 additions & 2 deletions
5
backend/tools/Faktur.ETL.Worker/Commands/ExtractDataCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
using MediatR; | ||
using Logitar.Portal.Contracts.Actors; | ||
using MediatR; | ||
|
||
namespace Faktur.ETL.Worker.Commands; | ||
|
||
internal record ExtractDataCommand : IRequest<ExtractedData>; | ||
internal record ExtractDataCommand(Actor Actor) : IRequest<ExtractedData>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
backend/tools/Faktur.ETL.Worker/Commands/ImportDataCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
using MediatR; | ||
using Logitar.Portal.Contracts.Actors; | ||
using MediatR; | ||
|
||
namespace Faktur.ETL.Worker.Commands; | ||
|
||
internal record ImportDataCommand(ExtractedData ExtractedData) : IRequest; | ||
internal record ImportDataCommand(Actor Actor, ExtractedData ExtractedData) : IRequest; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
backend/tools/Faktur.ETL.Worker/Commands/ImportReceiptsCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
using Faktur.Contracts.Receipts; | ||
using MediatR; | ||
|
||
namespace Faktur.ETL.Worker.Commands; | ||
|
||
internal record ImportReceiptsCommand(IEnumerable<Receipt> Receipts) : IRequest<int>; |
102 changes: 102 additions & 0 deletions
102
backend/tools/Faktur.ETL.Worker/Commands/ImportReceiptsCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
using Faktur.Contracts.Receipts; | ||
using Faktur.Domain.Articles; | ||
using Faktur.Domain.Products; | ||
using Faktur.Domain.Receipts; | ||
using Faktur.Domain.Stores; | ||
using Faktur.Domain.Taxes; | ||
using Logitar.EventSourcing; | ||
using Logitar.Identity.Domain.Shared; | ||
using MediatR; | ||
|
||
namespace Faktur.ETL.Worker.Commands; | ||
|
||
internal class ImportReceiptsCommandHandler : IRequestHandler<ImportReceiptsCommand, int> | ||
{ | ||
private readonly IReceiptRepository _receiptRepository; | ||
private readonly ITaxRepository _taxRepository; | ||
|
||
public ImportReceiptsCommandHandler(IReceiptRepository receiptRepository, ITaxRepository taxRepository) | ||
{ | ||
_receiptRepository = receiptRepository; | ||
_taxRepository = taxRepository; | ||
} | ||
|
||
public async Task<int> Handle(ImportReceiptsCommand command, CancellationToken cancellationToken) | ||
{ | ||
int errors = 0; | ||
|
||
IEnumerable<TaxAggregate> taxes = await _taxRepository.LoadAsync(cancellationToken); | ||
|
||
Dictionary<Guid, ReceiptAggregate> receipts = (await _receiptRepository.LoadAsync(cancellationToken)) | ||
.ToDictionary(x => x.Id.ToGuid(), x => x); | ||
int count = 0; | ||
foreach (Receipt receipt in command.Receipts) | ||
{ | ||
ReceiptId id = new(receipt.Id); | ||
|
||
NumberUnit? number = NumberUnit.TryCreate(receipt.Number); | ||
if (receipts.TryGetValue(receipt.Id, out ReceiptAggregate? existingReceipt)) | ||
{ | ||
existingReceipt.IssuedOn = receipt.IssuedOn; | ||
existingReceipt.Number = number; | ||
|
||
ActorId updatedBy = new(receipt.UpdatedBy.Id); | ||
existingReceipt.Update(updatedBy); | ||
} | ||
else | ||
{ | ||
StoreId storeId = new(receipt.Store.Id); | ||
StoreAggregate store = new(storeId.AggregateId); | ||
|
||
List<ReceiptItemUnit> items = new(capacity: receipt.Items.Count); | ||
Dictionary<ushort, CategoryUnit?> itemCategories = new(capacity: receipt.Items.Count); | ||
foreach (ReceiptItem item in receipt.Items) | ||
{ | ||
if (item.Quantity < 1 || item.UnitPrice < 1 || item.Price < 1) | ||
{ | ||
errors++; | ||
continue; | ||
} | ||
|
||
NumberUnit? departmentNumber = null; | ||
DepartmentUnit? department = null; | ||
if (item.Department != null) | ||
{ | ||
departmentNumber = new NumberUnit(item.Department.Number); | ||
department = new DepartmentUnit(new DisplayNameUnit(item.Department.DisplayName), DescriptionUnit.TryCreate(item.Department.Description)); | ||
} | ||
|
||
items.Add(new ReceiptItemUnit(GtinUnit.TryCreate(item.Gtin), SkuUnit.TryCreate(item.Sku), new DisplayNameUnit(item.Label), FlagsUnit.TryCreate(item.Flags), | ||
item.Quantity, item.UnitPrice, item.Price, departmentNumber, department)); | ||
|
||
CategoryUnit? category = null; | ||
if (item.Category != null && item.Category != "Shared") | ||
{ | ||
category = new CategoryUnit(item.Category); | ||
} | ||
itemCategories[item.Number] = category; | ||
} | ||
|
||
ActorId createdBy = new(receipt.CreatedBy.Id); | ||
existingReceipt = ReceiptAggregate.Import(store, receipt.IssuedOn, number, items, taxes, createdBy, id); | ||
receipts[receipt.Id] = existingReceipt; | ||
|
||
if (receipt.HasBeenProcessed) | ||
{ | ||
ActorId processedBy = receipt.ProcessedBy == null ? createdBy : new(receipt.ProcessedBy.Id); | ||
existingReceipt.Categorize(itemCategories, processedBy); | ||
} | ||
} | ||
|
||
if (existingReceipt.HasChanges) | ||
{ | ||
existingReceipt.SetDates(receipt); | ||
count++; | ||
} | ||
} | ||
|
||
await _receiptRepository.SaveAsync(receipts.Values, cancellationToken); | ||
|
||
return count; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
backend/tools/Faktur.ETL.Worker/Commands/ImportTaxesCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using Faktur.Domain.Products; | ||
using Faktur.Domain.Taxes; | ||
using Logitar.EventSourcing; | ||
using MediatR; | ||
|
||
namespace Faktur.ETL.Worker.Commands; | ||
|
||
internal class ImportTaxesCommandHandler : IRequestHandler<ImportTaxesCommand, int> | ||
{ | ||
private readonly ITaxRepository _taxRepository; | ||
|
||
public ImportTaxesCommandHandler(ITaxRepository taxRepository) | ||
{ | ||
_taxRepository = taxRepository; | ||
} | ||
|
||
public async Task<int> Handle(ImportTaxesCommand command, CancellationToken cancellationToken) | ||
{ | ||
ActorId actorId = new(command.Actor.Id); | ||
|
||
Dictionary<TaxCodeUnit, TaxAggregate> taxes = (await _taxRepository.LoadAsync(cancellationToken)) | ||
.ToDictionary(x => x.Code, x => x); | ||
|
||
int count = 0; | ||
|
||
TaxCodeUnit gstCode = new("GST"); | ||
if (!taxes.TryGetValue(gstCode, out TaxAggregate? gst)) | ||
{ | ||
gst = new(gstCode, rate: 0.05, actorId); | ||
taxes[gstCode] = gst; | ||
} | ||
gst.Flags = new FlagsUnit("F"); | ||
gst.Update(actorId); | ||
if (gst.HasChanges) | ||
{ | ||
count++; | ||
} | ||
|
||
TaxCodeUnit qstCode = new("QST"); | ||
if (!taxes.TryGetValue(qstCode, out TaxAggregate? qst)) | ||
{ | ||
qst = new(qstCode, rate: 0.09975, actorId); | ||
taxes[qstCode] = qst; | ||
} | ||
qst.Flags = new FlagsUnit("P"); | ||
qst.Update(actorId); | ||
if (gst.HasChanges) | ||
{ | ||
count++; | ||
} | ||
|
||
await _taxRepository.SaveAsync(taxes.Values, cancellationToken); | ||
|
||
return count; | ||
} | ||
} |
13 changes: 0 additions & 13 deletions
13
backend/tools/Faktur.ETL.Worker/Entities/Configurations/UserConfiguration.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.