From a67a9eabc9551fa6475643d3a7498b56bcdaf215 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Mon, 24 Jul 2017 17:45:50 +0200 Subject: [PATCH] =?UTF-8?q?Pr=C3=A9senter=20la=20facture=20=C3=A0=20sa=20g?= =?UTF-8?q?=C3=A9n=C3=A9ration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Billing/NominativeServiceCommand.cs | 3 ++- Yavsc/Startup/Startup.Workflow.cs | 17 +++++++++--- Yavsc/ViewComponents/BillViewComponent.cs | 10 ++++--- .../Shared/Components/Bill/Default.cshtml | 26 +++++++++++++++++-- 4 files changed, 47 insertions(+), 9 deletions(-) diff --git a/Yavsc/Models/Billing/NominativeServiceCommand.cs b/Yavsc/Models/Billing/NominativeServiceCommand.cs index 02608c5f..112f041e 100644 --- a/Yavsc/Models/Billing/NominativeServiceCommand.cs +++ b/Yavsc/Models/Billing/NominativeServiceCommand.cs @@ -88,7 +88,8 @@ namespace Yavsc.Models.Billing { string type = GetType().Name; string ack = GetIsAcquitted() ? "-ack" : null; - return $"facture-{ActivityCode}-{type}-{Id}{ack}"; + var bcode = Startup.BillingMap[type]; + return $"facture-{bcode}-{Id}{ack}"; } public string PaymentId { get; set; } diff --git a/Yavsc/Startup/Startup.Workflow.cs b/Yavsc/Startup/Startup.Workflow.cs index 90b0c383..68208498 100644 --- a/Yavsc/Startup/Startup.Workflow.cs +++ b/Yavsc/Startup/Startup.Workflow.cs @@ -10,6 +10,9 @@ namespace Yavsc using Microsoft.Data.Entity; using Models; using Yavsc.Billing; + using Yavsc.Models.Haircut; + using Yavsc.Models.Workflow; + public partial class Startup { /// @@ -22,6 +25,8 @@ namespace Yavsc public static Dictionary> Billing = new Dictionary> (); + public static Dictionary BillingMap = + new Dictionary(); /// /// Lists available command forms. /// This is hard coded. @@ -71,7 +76,7 @@ mais n'implemente pas l'interface IQueryable } } - Billing.Add("Brush", new Func + RegisterBilling("Brush", new Func ( ( db, id) => { var query = db.HairCutQueries.Include(q=>q.Prestation).Include(q=>q.Regularisation).Single(q=>q.Id == id) ; @@ -79,15 +84,21 @@ mais n'implemente pas l'interface IQueryable return query; })) ; - Billing.Add("MBrush",new Func + RegisterBilling("MBrush",new Func ( (db, id) => db.HairMultiCutQueries.Include(q=>q.Regularisation).Single(q=>q.Id == id))); - Billing.Add("Rdv", new Func + RegisterBilling("Rdv", new Func ( (db, id) => db.RdvQueries.Include(q=>q.Regularisation).Single(q=>q.Id == id))); } public static System.Reflection.Assembly OnYavscResourceResolve(object sender, ResolveEventArgs ev) { return AppDomain.CurrentDomain.GetAssemblies()[0]; } + + public static void RegisterBilling(string code, Func getter) where T : IBillable + { + Billing.Add(code,getter) ; + BillingMap.Add(typeof(T).Name,code); + } } } diff --git a/Yavsc/ViewComponents/BillViewComponent.cs b/Yavsc/ViewComponents/BillViewComponent.cs index d82fa237..068e8cfa 100644 --- a/Yavsc/ViewComponents/BillViewComponent.cs +++ b/Yavsc/ViewComponents/BillViewComponent.cs @@ -76,13 +76,17 @@ namespace Yavsc.ViewComponents } ViewComponentContext.ViewContext.Writer = oldWriter; - return this.View("Bill_pdf", - new PdfGenerationViewModel{ + var genrtrData = new PdfGenerationViewModel{ Temp = Startup.Temp, TeXSource = tex, DestDir = Startup.UserBillsDirName, BaseFileName = billable.GetFileBaseName() - } ); + }; + if (genrtrData.GenerateEstimatePdf()) { + return Json(new { Generated = genrtrData.BaseFileName+".pdf" }); + } else { + return Json(new { Error = genrtrData.GenerationErrorMessage } ); + } } 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 26222c75..2d0a67f7 100644 --- a/Yavsc/Views/Shared/Components/Bill/Default.cshtml +++ b/Yavsc/Views/Shared/Components/Bill/Default.cshtml @@ -4,8 +4,30 @@ @if (ViewBag.BillFileInfo.Exists) { La facture au format Pdf } else { -
- + +
+ + + +
+
+
}