Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Mindee.Cli/Commands/PredictInvoiceCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public async Task<int> InvokeAsync(InvocationContext context)

var invoicePrediction = await _mindeeClient
.LoadDocument(new FileInfo(Path))
.ParseAsync<InvoiceV3Prediction>(WithWords);
.ParseAsync<InvoiceV4Prediction>(WithWords);

if(Output == "summary")
if (Output == "summary")
{
context.Console.Out.Write(invoicePrediction != null ? invoicePrediction.Inference.Prediction.ToString()! : "null");
}
Expand Down
6 changes: 0 additions & 6 deletions src/Mindee/Parsing/Common/FinancialPredictionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ public abstract class FinancialPredictionBase : PredictionBase
[JsonPropertyName("date")]
public Date Date { get; set; }

/// <summary>
/// The supplier name.
/// </summary>
[JsonPropertyName("supplier")]
public StringField Supplier { get; set; }

/// <summary>
/// <see cref="Tax"/>
/// </summary>
Expand Down
101 changes: 101 additions & 0 deletions src/Mindee/Parsing/Invoice/InvoiceLineItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;
using Mindee.Parsing.Common;

namespace Mindee.Parsing.Invoice
{
/// <summary>
/// Line items details.
/// </summary>
public sealed class InvoiceLineItem : FinancialPredictionBase
{
/// <summary>
/// The product code referring to the item.
/// </summary>
[JsonPropertyName("product_code")]
public string ProductCode { get; set; }

/// <summary>
/// The item description.
/// </summary>
[JsonPropertyName("description")]
public string Description { get; set; }

/// <summary>
/// The item quantity.
/// </summary>
[JsonPropertyName("quantity")]
public double? Quantity { get; set; }

/// <summary>
/// The item unit price.
/// </summary>
[JsonPropertyName("unit_price")]
public double? UnitPrice { get; set; }

/// <summary>
/// The item total amount.
/// </summary>
[JsonPropertyName("total_amount")]
public double? TotalAmount { get; set; }

/// <summary>
/// The item tax rate in percentage.
/// </summary>
[JsonPropertyName("tax_rate")]
public double? TaxRate { get; set; }

/// <summary>
/// The item tax amount.
/// </summary>
[JsonPropertyName("tax_amount")]
public double? TaxAmount { get; set; }

/// <summary>
/// Confidence score.
/// </summary>
[JsonPropertyName("confidence")]
public double Confidence { get; set; } = 0.0;

/// <summary>
/// The document page on which the information was found.
/// </summary>
[JsonPropertyName("page_id")]
public double PageId { get; set; }

/// <summary>
/// Contains the relative vertices coordinates (points) of a polygon containing
/// the field in the document.
/// </summary>
[JsonPropertyName("polygon")]
public List<List<double>> Polygon { get; set; }

/// <summary>
/// A prettier reprensentation of the current model values.
/// </summary>
public override string ToString()
{
string productCode = ProductCode?.ToString() ?? "";
string quantity = Quantity?.ToString() ?? "";
string unitPrice = UnitPrice?.ToString() ?? "";
string totalAmount = TotalAmount?.ToString() ?? "";
string tax = TotalAmount?.ToString() ?? "";
tax += TaxRate != null ? $" ({TaxRate} %)" : "";
string description = Description ?? "";
if (description.Length > 32)
{
description = description.Substring(0, 32) + "...";
}

return string.Join(" | ",
productCode.PadRight(14),
quantity.PadRight(6),
unitPrice.PadRight(7),
totalAmount.PadRight(8),
tax.PadRight(14),
description
);
}
}
}
6 changes: 6 additions & 0 deletions src/Mindee/Parsing/Invoice/InvoiceV3Prediction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public sealed class InvoiceV3Prediction : FinancialPredictionBase
[JsonPropertyName("customer")]
public StringField Customer { get; set; }

/// <summary>
/// The supplier name.
/// </summary>
[JsonPropertyName("supplier")]
public StringField Supplier { get; set; }

/// <summary>
/// The adress of the customer.
/// </summary>
Expand Down
121 changes: 121 additions & 0 deletions src/Mindee/Parsing/Invoice/InvoiceV4Prediction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using Mindee.Parsing.Common;

namespace Mindee.Parsing.Invoice
{
/// <summary>
/// The invoice model for the v4.
/// </summary>
[Endpoint("invoices", "4")]
public sealed class InvoiceV4Prediction : FinancialPredictionBase
{
/// <summary>
/// The supplier name.
/// </summary>
[JsonPropertyName("supplier_name")]
public StringField SupplierName { get; set; }

/// <summary>
/// List of <see cref="CompanyRegistration"/>
/// </summary>
[JsonPropertyName("supplier_company_registrations")]
public List<CompanyRegistration> SupplierCompanyRegistrations { get; set; }

/// <summary>
/// List of payment details.
/// </summary>
[JsonPropertyName("supplier_payment_details")]
public List<PaymentDetail> SupplierPaymentDetails { get; set; }

/// <summary>
/// The supplier address.
/// </summary>
[JsonPropertyName("supplier_address")]
public StringField SupplierAddress { get; set; }

/// <summary>
/// The customer.
/// </summary>
[JsonPropertyName("customer_name")]
public StringField CustomerName { get; set; }

/// <summary>
/// List of customer company registrations.
/// </summary>
[JsonPropertyName("customer_company_registrations")]
public List<CustomerCompanyRegistration> CustomerCompanyRegistrations { get; set; }

/// <summary>
/// The adress of the customer.
/// </summary>
[JsonPropertyName("customer_address")]
public StringField CustomerAddress { get; set; }

/// <summary>
/// The due date of the invoice.
/// </summary>
[JsonPropertyName("due_date")]
public Date DueDate { get; set; }

/// <summary>
/// The invoice number.
/// </summary>
[JsonPropertyName("invoice_number")]
public StringField InvoiceNumber { get; set; }

/// <summary>
/// Total amount including taxes.
/// </summary>
[JsonPropertyName("total_amount")]
public AmountField TotalAmount { get; set; }

/// <summary>
/// Total amount excluding taxes.
/// </summary>
[JsonPropertyName("total_net")]
public AmountField TotalNet { get; set; }

/// <summary>
/// Line items details.
/// </summary>
[JsonPropertyName("line_items")]
public List<InvoiceLineItem> LineItems { get; set; }

/// <summary>
/// A prettier reprensentation of the current model values.
/// </summary>
public override string ToString()
{
string lineItems = "\n";
if (LineItems.Any())
{
lineItems =
"\n Code | QTY | Price | Amount | Tax (Rate) | Description\n ";
lineItems += string.Join("\n ", LineItems.Select(item => item.ToString()));
}

StringBuilder result = new StringBuilder("----- Invoice v4 -----\n");
result.Append($"Invoice number: {InvoiceNumber.Value}\n");
result.Append($"Locale: {Locale}\n");
result.Append($"Invoice date: {Date.Value}\n");
result.Append($"Invoice due date: {DueDate.Value}\n");
result.Append($"Supplier name: {SupplierName.Value}\n");
result.Append($"Supplier address: {SupplierAddress.Value}\n");
result.Append($"Supplier company registrations: {string.Join("\n ", SupplierCompanyRegistrations.Select(c => c.Value))}\n");
result.Append($"Supplier payment details: {string.Join("\n ", SupplierPaymentDetails.Select(p => p))}\n");
result.Append($"Customer name: {CustomerName.Value}\n");
result.Append($"Customer company registrations: {string.Join("; ", CustomerCompanyRegistrations.Select(c => c.Value))}\n");
result.Append($"Customer address: {string.Join("; ", CustomerAddress.Value)}\n");
result.Append($"Taxes: {string.Join("\n ", Taxes.Select(t => t))}\n");
result.Append($"Line items: {lineItems}\n");
result.Append($"Total amount including taxes: {TotalAmount.Value}\n");
result.Append($"Total amount excluding taxes: {TotalNet.Value}\n");
result.Append("----------------------");

return result.ToString();
}
}
}
6 changes: 6 additions & 0 deletions src/Mindee/Parsing/Receipt/ReceiptV4Prediction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public sealed class ReceiptV4Prediction : FinancialPredictionBase
[JsonPropertyName("category")]
public StringField Category { get; set; }

/// <summary>
/// The supplier name.
/// </summary>
[JsonPropertyName("supplier")]
public StringField Supplier { get; set; }

/// <summary>
/// <see cref="Time"/>
/// </summary>
Expand Down
Loading