diff --git a/Yavsc.Abstract/Billing/IBillable.cs b/Yavsc.Abstract/Billing/IBillable.cs index d6920671..069d7a5d 100644 --- a/Yavsc.Abstract/Billing/IBillable.cs +++ b/Yavsc.Abstract/Billing/IBillable.cs @@ -19,5 +19,9 @@ namespace Yavsc.Billing DateTime? ValidationDate { get; } + bool GetIsAcquitted (); + + string GetFileBaseName (); + } } diff --git a/Yavsc/ApiControllers/BillingController.cs b/Yavsc/ApiControllers/BillingController.cs index fd252263..6055083b 100644 --- a/Yavsc/ApiControllers/BillingController.cs +++ b/Yavsc/ApiControllers/BillingController.cs @@ -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 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 } ); } diff --git a/Yavsc/Helpers/BillingHelpers.cs b/Yavsc/Helpers/BillingHelpers.cs index c9a233f8..d11d5887 100644 --- a/Yavsc/Helpers/BillingHelpers.cs +++ b/Yavsc/Helpers/BillingHelpers.cs @@ -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)); } } diff --git a/Yavsc/Models/Billing/NominativeServiceCommand.cs b/Yavsc/Models/Billing/NominativeServiceCommand.cs index 100d3517..02608c5f 100644 --- a/Yavsc/Models/Billing/NominativeServiceCommand.cs +++ b/Yavsc/Models/Billing/NominativeServiceCommand.cs @@ -78,6 +78,19 @@ namespace Yavsc.Models.Billing public virtual Activity Context  { get; set ; } public abstract System.Collections.Generic.List 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")] diff --git a/Yavsc/Startup/Startup.Workflow.cs b/Yavsc/Startup/Startup.Workflow.cs index 58a0d485..90b0c383 100644 --- a/Yavsc/Startup/Startup.Workflow.cs +++ b/Yavsc/Startup/Startup.Workflow.cs @@ -18,6 +18,7 @@ namespace Yavsc /// public static List ProfileTypes = new List(); public static List UserSettings = new List(); + public static Dictionary> Billing = new Dictionary> (); @@ -73,15 +74,15 @@ mais n'implemente pas l'interface IQueryable Billing.Add("Brush", new Func ( ( 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 - ( (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 - ( (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) { diff --git a/Yavsc/ViewComponents/BillViewComponent.cs b/Yavsc/ViewComponents/BillViewComponent.cs index 88aa8498..d82fa237 100644 --- a/Yavsc/ViewComponents/BillViewComponent.cs +++ b/Yavsc/ViewComponents/BillViewComponent.cs @@ -27,14 +27,14 @@ namespace Yavsc.ViewComponents logger = loggerFactory.CreateLogger(); } - public async Task InvokeAsync(string code, IBillable billable, OutputFormat format, bool asBill, bool acquitted) + public async Task 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); } diff --git a/Yavsc/Views/Shared/Components/Bill/Default.cshtml b/Yavsc/Views/Shared/Components/Bill/Default.cshtml index c56e66ee..26222c75 100644 --- a/Yavsc/Views/Shared/Components/Bill/Default.cshtml +++ b/Yavsc/Views/Shared/Components/Bill/Default.cshtml @@ -1,8 +1,7 @@ @model IBillable
-@{ var fi = BillingHelpers.GetBillInfo(ViewBag.BillingCode,Model.Id); } -@if (fi.Exists) { +@if (ViewBag.BillFileInfo.Exists) { La facture au format Pdf } else {
diff --git a/Yavsc/Views/Shared/Components/PayPalButton/Default.cshtml b/Yavsc/Views/Shared/Components/PayPalButton/Default.cshtml index a0511eee..c7e8568c 100644 --- a/Yavsc/Views/Shared/Components/PayPalButton/Default.cshtml +++ b/Yavsc/Views/Shared/Components/PayPalButton/Default.cshtml @@ -15,12 +15,14 @@ : -