Skip to content

Commit

Permalink
Added InvoiceMapper and new properties to Invoice VO
Browse files Browse the repository at this point in the history
  • Loading branch information
jarmatys committed Nov 28, 2024
1 parent ca11b2e commit eee9a6e
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 15 deletions.
7 changes: 4 additions & 3 deletions FAKTUROWNIA/SOFTURE.Fakturownia.Playground/Playground.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@ public sealed class Playground(IFakturowniaClient fakturowniaClient)
{
public async Task Run()
{
//var currentMonthStatement = await fakturowniaClient.GetCurrentMonthStatement(clientId: 145264330);
// var currentMonthStatement = await fakturowniaClient.GetCurrentMonthStatement(clientId: 145264330);

// var monthlyStatement = await fakturowniaClient.GetMonthlyStatement(
// clientId: 135057762,
// month: 7,
// year: 2024
// );

// var invoice = await fakturowniaClient.GetInvoice(invoiceId: 315738314, kind: DocumentKind.Proforma);
var invoiceProforma = await fakturowniaClient.GetInvoice(invoiceId: 294812795, kind: DocumentKind.Proforma);
var invoiceVat = await fakturowniaClient.GetInvoice(invoiceId: 300462117, kind: DocumentKind.Vat);

// var currentlyPaidInvoices = await fakturowniaClient.GetCurrentlyPaidInvoices(
// clientId: 135057762,
// unPayedProInvoiceIds: [294812716, 315738315]
// );

var allStatements = await fakturowniaClient.GetAllStatements(clientId: 149831120);
// var allStatements = await fakturowniaClient.GetAllStatements(clientId: 145264330);
}
}
19 changes: 10 additions & 9 deletions FAKTUROWNIA/SOFTURE.Fakturownia/FakturowniaClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CSharpFunctionalExtensions;
using SOFTURE.Fakturownia.Abstractions;
using SOFTURE.Fakturownia.Mappers;
using SOFTURE.Fakturownia.Models.Api.Enums;
using SOFTURE.Fakturownia.Models.Client;

Expand Down Expand Up @@ -30,14 +31,14 @@ public async Task<Result<MonthlyStatement>> GetCurrentMonthStatement(int clientI
return Result.Failure<MonthlyStatement>($"Missing proforma invoice for client with id: {clientId}");

var statement = MonthlyStatement.Create(
new Invoice(proFormaInvoice.Id, proFormaInvoice.IssueDate, proFormaInvoice.PriceNet)
proFormaInvoice.MapToInvoice()
);

var invoice = invoices.SingleOrDefault(i => i.Kind == DocumentKind.Vat &&
i.FromInvoiceId == proFormaInvoice.Id);

if (invoice != null)
statement.Paid(new Invoice(invoice.Id, invoice.IssueDate, invoice.PriceNet));
statement.Paid(invoice.MapToInvoice());

return Result.Success(statement);
}
Expand Down Expand Up @@ -69,14 +70,14 @@ public async Task<Result<MonthlyStatement>> GetMonthlyStatement(int clientId, in
return Result.Failure<MonthlyStatement>($"Missing proforma invoice for client with id: {clientId}");

var statement = MonthlyStatement.Create(
new Invoice(proFormaInvoice.Id, proFormaInvoice.IssueDate, proFormaInvoice.PriceNet)
proFormaInvoice.MapToInvoice()
);

var invoice = allInvoice.SingleOrDefault(i => i.Kind == DocumentKind.Vat &&
i.FromInvoiceId == proFormaInvoice.Id);

if (invoice != null)
statement.Paid(new Invoice(invoice.Id, invoice.IssueDate, invoice.PriceNet));
statement.Paid(invoice.MapToInvoice());

return Result.Success(statement);
}
Expand All @@ -95,7 +96,7 @@ public async Task<Result<Invoice>> GetInvoice(int invoiceId, DocumentKind kind)

var invoice = response.Content;

return Result.Success(new Invoice(invoice.Id, invoice.IssueDate, invoice.PriceNet));
return Result.Success(invoice.MapToInvoice());
}

public async Task<Result<IReadOnlyList<MonthlyStatement>>> GetCurrentlyPaidInvoices(
Expand Down Expand Up @@ -138,10 +139,10 @@ public async Task<Result<IReadOnlyList<MonthlyStatement>>> GetCurrentlyPaidInvoi
continue;

var statement = MonthlyStatement.Create(
new Invoice(proFormaInvoice.Id, proFormaInvoice.IssueDate, proFormaInvoice.PriceNet)
proFormaInvoice.MapToInvoice()
);

statement.Paid(new Invoice(invoice.Id, invoice.IssueDate, invoice.PriceNet));
statement.Paid(invoice.MapToInvoice());

currentlyPayedStatements.Add(statement);
}
Expand Down Expand Up @@ -180,7 +181,7 @@ public async Task<Result<IReadOnlyList<MonthlyStatement>>> GetAllStatements(int
foreach (var proFormaInvoice in proFormaInvoices)
{
var statement = MonthlyStatement.Create(
new Invoice(proFormaInvoice.Id, proFormaInvoice.IssueDate, proFormaInvoice.PriceNet)
proFormaInvoice.MapToInvoice()
);

var invoiceCount = allInvoice.Count(i => i.FromInvoiceId == proFormaInvoice.Id &&
Expand All @@ -205,7 +206,7 @@ public async Task<Result<IReadOnlyList<MonthlyStatement>>> GetAllStatements(int
continue;
}

statement.Paid(new Invoice(invoice.Id, invoice.IssueDate, invoice.PriceNet));
statement.Paid(invoice.MapToInvoice());

allStatements.Add(statement);
}
Expand Down
18 changes: 18 additions & 0 deletions FAKTUROWNIA/SOFTURE.Fakturownia/Mappers/InvoiceDetailsMapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using SOFTURE.Fakturownia.Models.Api;
using SOFTURE.Fakturownia.Models.Client;

namespace SOFTURE.Fakturownia.Mappers;

internal static class InvoiceDetailsMapper
{
public static Invoice MapToInvoice(this InvoiceDetails invoiceDetails)
{
return new Invoice(
identifier: invoiceDetails.Id,
number: invoiceDetails.Number,
issueDate: invoiceDetails.IssueDate,
paymentDate: invoiceDetails.PaymentTo,
priceNet: invoiceDetails.PriceNet
);
}
}
4 changes: 2 additions & 2 deletions FAKTUROWNIA/SOFTURE.Fakturownia/Models/Api/InvoiceDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public sealed class InvoiceDetails

[JsonPropertyName("app")] public object? App { get; set; }

[JsonPropertyName("number")] public string? Number { get; set; }
[JsonPropertyName("number")] public string Number { get; set; } = null!;

[JsonPropertyName("place")] public string? Place { get; set; }

Expand Down Expand Up @@ -104,7 +104,7 @@ public sealed class InvoiceDetails

[JsonPropertyName("client_id")] public int ClientId { get; set; }

[JsonPropertyName("payment_to")] public string? PaymentTo { get; set; }
[JsonPropertyName("payment_to")] public DateTime PaymentTo { get; set; }

[JsonPropertyName("paid")] public string? Paid { get; set; }

Expand Down
8 changes: 7 additions & 1 deletion FAKTUROWNIA/SOFTURE.Fakturownia/Models/Client/Invoice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,27 @@ namespace SOFTURE.Fakturownia.Models.Client;

public sealed class Invoice : ValueObject
{
public Invoice(int identifier, DateTime issueDate, string priceNet)
public Invoice(int identifier, string number, DateTime issueDate, DateTime paymentDate, string priceNet)
{
Identifier = identifier;
Number = number;
IssueDate = issueDate;
PaymentDate = paymentDate;
PriceNet = decimal.Parse(priceNet);
}

public int Identifier { get; }
public string Number { get; }
public DateTime IssueDate { get; }
public DateTime PaymentDate { get; }
public decimal PriceNet { get; }

protected override IEnumerable<IComparable> GetEqualityComponents()
{
yield return Identifier;
yield return Number;
yield return IssueDate;
yield return PaymentDate;
yield return PriceNet;
}
}
7 changes: 7 additions & 0 deletions FAKTUROWNIA/global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"sdk": {
"version": "8.0.0",
"rollForward": "latestMajor",
"allowPrerelease": true
}
}

0 comments on commit eee9a6e

Please sign in to comment.