Présenter la facture à sa génération
This commit is contained in:
@ -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; }
|
||||
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
@ -22,6 +25,8 @@ namespace Yavsc
|
||||
public static Dictionary<string,Func<ApplicationDbContext,long,IBillable>> Billing =
|
||||
new Dictionary<string,Func<ApplicationDbContext,long,IBillable>> ();
|
||||
|
||||
public static Dictionary<string,string> BillingMap =
|
||||
new Dictionary<string,string>();
|
||||
/// <summary>
|
||||
/// Lists available command forms.
|
||||
/// This is hard coded.
|
||||
@ -71,7 +76,7 @@ mais n'implemente pas l'interface IQueryable<ISpecializationSettings>
|
||||
}
|
||||
}
|
||||
|
||||
Billing.Add("Brush", new Func<ApplicationDbContext,long,IBillable>
|
||||
RegisterBilling<HairCutQuery>("Brush", new Func<ApplicationDbContext,long,IBillable>
|
||||
( ( 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<ISpecializationSettings>
|
||||
return query;
|
||||
})) ;
|
||||
|
||||
Billing.Add("MBrush",new Func<ApplicationDbContext,long,IBillable>
|
||||
RegisterBilling<HairMultiCutQuery>("MBrush",new Func<ApplicationDbContext,long,IBillable>
|
||||
( (db, id) => db.HairMultiCutQueries.Include(q=>q.Regularisation).Single(q=>q.Id == id)));
|
||||
Billing.Add("Rdv", new Func<ApplicationDbContext,long,IBillable>
|
||||
RegisterBilling<RdvQuery>("Rdv", new Func<ApplicationDbContext,long,IBillable>
|
||||
( (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<T>(string code, Func<ApplicationDbContext,long,IBillable> getter) where T : IBillable
|
||||
{
|
||||
Billing.Add(code,getter) ;
|
||||
BillingMap.Add(typeof(T).Name,code);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -4,8 +4,30 @@
|
||||
@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">
|
||||
<input class="btn btn-default" type="submit" value="Générer la facture au format Pdf"/>
|
||||
<script>
|
||||
var onGenerate = function () {
|
||||
var _btn = this;
|
||||
$.post('/api/bill/genpdf/@ViewBag.BillingCode/@Model.Id')
|
||||
.done(function(data){
|
||||
var res = JSON.parse(data);
|
||||
window.location.href = '/api/bill/' + res.Generated;
|
||||
_btn.disabled = true;
|
||||
})
|
||||
.fail(function( jqXHR, textStatus, errorThrown ) {
|
||||
$('#billgenerr').html('<em>La génération a échoué</em><p>'+textStatus+'</p>')
|
||||
})
|
||||
};
|
||||
|
||||
$(document).ready(function(){$('#btnGen').on('click',onGenerate)})
|
||||
|
||||
</script>
|
||||
<div id="billgen">
|
||||
<form action= method="POST">
|
||||
<input id="btnGen" class="btn btn-default" type="button" onclick="onGenerate" value="Générer la facture au format Pdf" />
|
||||
|
||||
<div id="billgenerr" class="error">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user