refactorise la génération de la facture au format Pdf, presente la facture aquittée.
This commit is contained in:
@ -19,5 +19,9 @@ namespace Yavsc.Billing
|
||||
|
||||
DateTime? ValidationDate { get; }
|
||||
|
||||
bool GetIsAcquitted ();
|
||||
|
||||
string GetFileBaseName ();
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +64,8 @@ namespace Yavsc.ApiControllers
|
||||
return new ChallengeResult();
|
||||
}
|
||||
|
||||
var fi = BillingHelpers.GetBillInfo(billingCode,id);
|
||||
var fi = bill.GetBillInfo();
|
||||
|
||||
if (!fi.Exists) return Ok(new { Error = "Not generated" });
|
||||
return File(fi.OpenRead(), "application/x-pdf", fi.Name);
|
||||
}
|
||||
@ -85,19 +86,20 @@ namespace Yavsc.ApiControllers
|
||||
return new ChallengeResult();
|
||||
}
|
||||
Response.ContentType = "text/x-tex";
|
||||
return ViewComponent("Bill",new object[] { billingCode, bill , OutputFormat.LaTeX, true, false });
|
||||
return ViewComponent("Bill",new object[] { billingCode, bill , OutputFormat.LaTeX, true });
|
||||
}
|
||||
|
||||
[HttpPost("genpdf/{billingCode}/{id}")]
|
||||
public async Task<IActionResult> GeneratePdf(string billingCode, long id)
|
||||
{
|
||||
var bill = await billingService.GetBillAsync(billingCode, id);
|
||||
|
||||
|
||||
if (bill==null) {
|
||||
logger.LogCritical ( $"# not found !! {id} in {billingCode}");
|
||||
return this.HttpNotFound();
|
||||
}
|
||||
return ViewComponent("Bill",new object[] { billingCode, bill, OutputFormat.Pdf, true, false } );
|
||||
logger.LogWarning("Got bill ack:"+bill.GetIsAcquitted().ToString());
|
||||
return ViewComponent("Bill",new object[] { billingCode, bill, OutputFormat.Pdf, true } );
|
||||
}
|
||||
|
||||
|
||||
|
@ -20,10 +20,10 @@ namespace Yavsc.Helpers
|
||||
return bill;
|
||||
}
|
||||
|
||||
public static FileInfo GetBillInfo(string billingcode, long id, bool acquitted = false)
|
||||
public static FileInfo GetBillInfo(this IBillable bill)
|
||||
{
|
||||
var suffix = acquitted ? "-ack":null;
|
||||
var filename = $"facture-{billingcode}-{id}{suffix}.pdf";
|
||||
var suffix = bill.GetIsAcquitted() ? "-ack":null;
|
||||
var filename = bill.GetFileBaseName()+".pdf";
|
||||
return new FileInfo(Path.Combine(Startup.UserBillsDirName, filename));
|
||||
}
|
||||
}
|
||||
|
@ -78,6 +78,19 @@ namespace Yavsc.Models.Billing
|
||||
public virtual Activity Context { get; set ; }
|
||||
|
||||
public abstract System.Collections.Generic.List<IBillItem> GetBillItems();
|
||||
|
||||
public bool GetIsAcquitted()
|
||||
{
|
||||
return Regularisation?.IsOk() ?? false;
|
||||
}
|
||||
|
||||
public string GetFileBaseName()
|
||||
{
|
||||
string type = GetType().Name;
|
||||
string ack = GetIsAcquitted() ? "-ack" : null;
|
||||
return $"facture-{ActivityCode}-{type}-{Id}{ack}";
|
||||
}
|
||||
|
||||
public string PaymentId { get; set; }
|
||||
|
||||
[ForeignKey("PaymentId"), Display(Name = "Acquittement de la facture")]
|
||||
|
@ -18,6 +18,7 @@ namespace Yavsc
|
||||
/// </summary>
|
||||
public static List<Type> ProfileTypes = new List<Type>();
|
||||
public static List<PropertyInfo> UserSettings = new List<PropertyInfo>();
|
||||
|
||||
public static Dictionary<string,Func<ApplicationDbContext,long,IBillable>> Billing =
|
||||
new Dictionary<string,Func<ApplicationDbContext,long,IBillable>> ();
|
||||
|
||||
@ -73,15 +74,15 @@ mais n'implemente pas l'interface IQueryable<ISpecializationSettings>
|
||||
Billing.Add("Brush", new Func<ApplicationDbContext,long,IBillable>
|
||||
( ( db, id) =>
|
||||
{
|
||||
var query = db.HairCutQueries.Include(q=>q.Prestation).Single(q=>q.Id == id) ;
|
||||
var query = db.HairCutQueries.Include(q=>q.Prestation).Include(q=>q.Regularisation).Single(q=>q.Id == id) ;
|
||||
query.SelectedProfile = db.BrusherProfile.Single(b=>b.UserId == query.PerformerId);
|
||||
return query;
|
||||
})) ;
|
||||
|
||||
Billing.Add("MBrush",new Func<ApplicationDbContext,long,IBillable>
|
||||
( (db, id) => db.HairMultiCutQueries.Single(q=>q.Id == id)));
|
||||
( (db, id) => db.HairMultiCutQueries.Include(q=>q.Regularisation).Single(q=>q.Id == id)));
|
||||
Billing.Add("Rdv", new Func<ApplicationDbContext,long,IBillable>
|
||||
( (db, id) => db.RdvQueries.Single(q=>q.Id == id)));
|
||||
( (db, id) => db.RdvQueries.Include(q=>q.Regularisation).Single(q=>q.Id == id)));
|
||||
}
|
||||
public static System.Reflection.Assembly OnYavscResourceResolve(object sender, ResolveEventArgs ev)
|
||||
{
|
||||
|
@ -27,14 +27,14 @@ namespace Yavsc.ViewComponents
|
||||
logger = loggerFactory.CreateLogger<BillViewComponent>();
|
||||
}
|
||||
|
||||
public async Task<IViewComponentResult> InvokeAsync(string code, IBillable billable, OutputFormat format, bool asBill, bool acquitted)
|
||||
public async Task<IViewComponentResult> InvokeAsync(string code, IBillable billable, OutputFormat format, bool asBill)
|
||||
{
|
||||
var di = new DirectoryInfo(Startup.SiteSetup.UserFiles.Bills);
|
||||
var dia = new DirectoryInfo(Startup.SiteSetup.UserFiles.Avatars);
|
||||
ViewBag.BillsDir = di.FullName;
|
||||
ViewBag.AvatarsDir = dia.FullName;
|
||||
ViewBag.AsBill = asBill; // vrai pour une facture, sinon, c'est un devis
|
||||
ViewBag.Acquitted = acquitted;
|
||||
ViewBag.Acquitted = billable.GetIsAcquitted();
|
||||
|
||||
ViewBag.BillingCode = code;
|
||||
var client = await dbContext.Users
|
||||
@ -81,9 +81,10 @@ namespace Yavsc.ViewComponents
|
||||
Temp = Startup.Temp,
|
||||
TeXSource = tex,
|
||||
DestDir = Startup.UserBillsDirName,
|
||||
BaseFileName = $"facture-{code}-{billable.Id}"
|
||||
BaseFileName = billable.GetFileBaseName()
|
||||
} );
|
||||
}
|
||||
ViewBag.BillFileInfo = billable.GetBillInfo();
|
||||
return View("Default",billable);
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
|
||||
@model IBillable
|
||||
<div class="bill">
|
||||
@{ var fi = BillingHelpers.GetBillInfo(ViewBag.BillingCode,Model.Id); }
|
||||
@if (fi.Exists) {
|
||||
@if (ViewBag.BillFileInfo.Exists) {
|
||||
<a class="btn btn-link" href="~/api/bill/facture-@(ViewBag.BillingCode)-@(Model.Id).pdf" >La facture au format Pdf</a>
|
||||
} else {
|
||||
<form action="~/api/bill/genpdf/@ViewBag.BillingCode/@Model.Id" method="POST">
|
||||
|
@ -15,12 +15,14 @@
|
||||
<text> :
|
||||
|
||||
</text>
|
||||
<label>
|
||||
<input type="checkbox" checked="@Model.Regularisation.IsOk()" disabled/>
|
||||
<label>@Model.GetIsAcquitted()
|
||||
<input type="checkbox" checked="@Model.GetIsAcquitted()" disabled/>
|
||||
<a asp-controller="Manage" asp-action="PaymentInfo" asp-route-id="@Model.Regularisation.CreationToken">@Model.Regularisation.CreationToken</a>
|
||||
</label>
|
||||
|
||||
} else {
|
||||
}
|
||||
|
||||
@if (!Model.GetIsAcquitted()) {
|
||||
<div id="paypalzone"></div>
|
||||
<script>
|
||||
var CREATE_PAYMENT_URL = '@ViewBag.CreatePaymentUrl';
|
||||
|
@ -1,15 +1,4 @@
|
||||
@model HairCutQuery
|
||||
@{
|
||||
var paid = false;
|
||||
if (Model.PaymentId!=null) {
|
||||
if (Model.Regularisation!=null) {
|
||||
if (Model.Regularisation.IsOk()) {
|
||||
paid=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
<dl class="dl-horizontal">
|
||||
<dt>@Html.DisplayNameFor(m=>m.Prestation)
|
||||
</dt>
|
||||
@ -33,7 +22,7 @@
|
||||
</dd>
|
||||
<dt>@SR["La facture"]
|
||||
</dt>
|
||||
<dd>@await Component.InvokeAsync("Bill", "Brush", Model, OutputFormat.Html, true, paid )
|
||||
<dd>@await Component.InvokeAsync("Bill", "Brush", Model, OutputFormat.Html, true)
|
||||
</dd>
|
||||
<dt>@Html.DisplayNameFor(m=>m.Regularisation)</dt>
|
||||
<dd>
|
||||
|
Reference in New Issue
Block a user