2026-09-06 16:11:37 +01:00
|
|
|
#nullable enable annotations
|
|
|
|
|
|
2017-06-02 21:34:18 +02:00
|
|
|
using System.Globalization;
|
2017-05-27 16:22:58 +02:00
|
|
|
using Yavsc.Billing;
|
2017-06-02 10:13:55 +02:00
|
|
|
using Yavsc.Models.Billing;
|
2025-02-17 23:56:28 +00:00
|
|
|
using Yavsc.Server.Helpers;
|
2018-05-15 12:13:38 +02:00
|
|
|
using Yavsc.Services;
|
2017-05-12 16:29:47 +02:00
|
|
|
|
|
|
|
|
namespace Yavsc.Helpers
|
|
|
|
|
{
|
|
|
|
|
public static class BillingHelpers
|
|
|
|
|
{
|
|
|
|
|
public static decimal Addition(this List<IBillItem> items) => items.Aggregate<IBillItem, decimal>(0m, (t, l) => t + l.Count * l.UnitaryCost);
|
|
|
|
|
|
2017-06-02 10:13:55 +02:00
|
|
|
public static decimal Addition(this List<CommandLine> items) => items.Select(i=>((IBillItem)i)).ToList().Addition();
|
|
|
|
|
|
2017-06-02 21:34:18 +02:00
|
|
|
public static string GetBillText(this IBillable query) {
|
|
|
|
|
string total = query.GetBillItems().Addition().ToString("C", CultureInfo.CurrentUICulture);
|
|
|
|
|
string bill = string.Join("\n", query.GetBillItems().Select(l=> $"{l.Name} {l.Description} : {l.UnitaryCost} € " + ((l.Count != 1) ? "*"+l.Count.ToString() : ""))) +
|
|
|
|
|
$"\n\nTotal: {total}";
|
2026-10-19 20:29:08 +01:00
|
|
|
if (query.PaymentSummary is { } payment)
|
|
|
|
|
{
|
|
|
|
|
bill += $"\nPaid: {payment.AmountPaid.ToString("C", CultureInfo.CurrentUICulture)}"
|
|
|
|
|
+ $"\nRemaining: {payment.AmountRemaining.ToString("C", CultureInfo.CurrentUICulture)}"
|
|
|
|
|
+ $"\nStatus: {payment.Status}";
|
|
|
|
|
}
|
2017-06-02 21:34:18 +02:00
|
|
|
return bill;
|
|
|
|
|
}
|
2017-07-06 13:00:06 +02:00
|
|
|
|
2026-09-17 22:22:18 +01:00
|
|
|
public static FileInfo GetBillInfo(this IBillable bill,
|
|
|
|
|
IBillingService service, SiteSettings siteSettings)
|
2017-07-06 13:00:06 +02:00
|
|
|
{
|
2017-07-08 03:23:21 +02:00
|
|
|
var suffix = bill.GetIsAcquitted() ? "-ack":null;
|
2018-05-15 12:13:38 +02:00
|
|
|
var filename = bill.GetFileBaseName(service)+".pdf";
|
2026-09-17 22:22:18 +01:00
|
|
|
return new FileInfo(Path.Combine(siteSettings.Bills, filename));
|
2017-07-06 13:00:06 +02:00
|
|
|
}
|
2017-05-12 16:29:47 +02:00
|
|
|
}
|
|
|
|
|
}
|