signature du devis, dans le Pdf

main
Paul Schneider 9 years ago
parent 78f2af069a
commit b993d8451b
3 changed files with 50 additions and 14 deletions

@ -2,6 +2,7 @@ using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Rendering; using Microsoft.AspNet.Mvc.Rendering;
@ -67,6 +68,13 @@ namespace Yavsc.Helpers
{ {
return data; return data;
} }
public HtmlString ToHtmlString()
{
return new HtmlString(ToString());
}
} }
public static class TeXHelpers public static class TeXHelpers
{ {
@ -78,11 +86,24 @@ namespace Yavsc.Helpers
return string.Join(separator, items); return string.Join(separator, items);
} }
public static TeXString ToTeX(string target, string lineSeparator = "\n\\\\") public static TeXString ToTeX(this string target, string lineSeparator = "\n\\\\")
{ {
if (target == null) return null; if (target == null) return null;
return new TeXString(target.NewLinesWith(lineSeparator)); return new TeXString(target.NewLinesWith(lineSeparator));
} }
public static HtmlString SplitAddressToTeX (this string target)
{
var alines = target.Split(',');
var texlines = alines.Select(l=>new TeXString(l));
StringBuilder sb = new StringBuilder();
foreach (var l in texlines)
{
sb.AppendFormat("{0}\\\\\n",l.ToString());
}
return new HtmlString(sb.ToString());
}
public static bool GenerateEstimatePdf(this PdfGenerationViewModel Model) public static bool GenerateEstimatePdf(this PdfGenerationViewModel Model)
{ {
string errorMsg = null; string errorMsg = null;

@ -34,7 +34,10 @@ namespace Yavsc.ViewComponents
.Include(e => e.Bill).FirstOrDefault(x => x.Id == id); .Include(e => e.Bill).FirstOrDefault(x => x.Id == id);
if (estimate == null) if (estimate == null)
throw new Exception("No data"); throw new Exception("No data");
var di = new DirectoryInfo(Startup.SiteSetup.UserFiles.Bills);
var dia = new DirectoryInfo(Startup.SiteSetup.UserFiles.Avatars);
ViewBag.BillsDir = di.FullName;
ViewBag.AvatarsDir = dia.FullName;
if (outputFormat == "LaTeX") { if (outputFormat == "LaTeX") {
return this.View("Estimate_tex", estimate); return this.View("Estimate_tex", estimate);
} }

@ -6,10 +6,10 @@
var pro = Model.Query.PerformerProfile; var pro = Model.Query.PerformerProfile;
var from = Model.Query.PerformerProfile.Performer; var from = Model.Query.PerformerProfile.Performer;
var to = Model.Query.Client; var to = Model.Query.Client;
var PostalAddress = (to.PostalAddress!=null) ? to.PostalAddress.Address.Replace("\n","\\\\\n") : null ; var PostalAddress = to.PostalAddress?.Address.SplitAddressToTeX();
var proaddr = Model.Query?.PerformerProfile.OrganizationAddress.Address; var proaddr = Model.Query.PerformerProfile.OrganizationAddress.Address.SplitAddressToTeX();
var proaddrn = (proaddr!=null) ? proaddr.NewLinesWith("\\\\\n") : null ; var proaddrm = new HtmlString(Model.Query.PerformerProfile.OrganizationAddress.Address);
var proaddrm = (proaddr!=null) ? proaddr.NewLinesWith(" - ") : null ;
}\documentclass[french,11pt]{article} }\documentclass[french,11pt]{article}
\usepackage{eurosym} \usepackage{eurosym}
\usepackage{babel} \usepackage{babel}
@ -68,7 +68,7 @@
\def\FactureNum {@Model.Id.ToString()} % Numéro de facture \def\FactureNum {@Model.Id.ToString()} % Numéro de facture
\def\FactureAcquittee {non} % Facture acquittée : oui/non \def\FactureAcquittee {non} % Facture acquittée : oui/non
\def\FactureLieu {@proaddrn} % Lieu de l'édition de la facture \def\FactureLieu {@proaddrm} % Lieu de l'édition de la facture
\def\FactureObjet {Facture : @TeXHelpers.ToTeX(Model.Title)} % Objet du document \def\FactureObjet {Facture : @TeXHelpers.ToTeX(Model.Title)} % Objet du document
% Description de la facture % Description de la facture
\def\FactureDescr { \def\FactureDescr {
@ -80,10 +80,9 @@
\def\ClientAdresse{ \def\ClientAdresse{
% Adresse du client % Adresse du client
@if (!string.IsNullOrWhiteSpace(PostalAddress)) { @PostalAddress
<text> @TeXHelpers.ToTeX(PostalAddress)\\</text> } @if (PostalAddress!=null) {<text>@PostalAddress</text>}
@if (!string.IsNullOrWhiteSpace(to.PhoneNumber)) {<text> @if (!string.IsNullOrWhiteSpace(to.PhoneNumber)) {<text>@TeXHelpers.ToTeX(to.PhoneNumber)<text>\\</text>
@TeXHelpers.ToTeX(to.PhoneNumber)<text>\\</text>
</text>} </text>}
E-mail: @TeXHelpers.ToTeX(to.Email) E-mail: @TeXHelpers.ToTeX(to.Email)
} }
@ -106,7 +105,7 @@
\setlength{\parindent}{0pt} \setlength{\parindent}{0pt}
\renewcommand{\headrulewidth}{0pt} \renewcommand{\headrulewidth}{0pt}
\cfoot{ @TeXHelpers.ToTeX(from.UserName) @if (!string.IsNullOrWhiteSpace(proaddrm)) { <text> - @TeXHelpers.ToTeX(proaddrm) </text> } \newline \cfoot{ @TeXHelpers.ToTeX(from.UserName) @if (proaddrm!=null) { <text> - @proaddrm </text> } \newline
\small{ E-mail: @TeXHelpers.ToTeX(from.Email) @if (!string.IsNullOrWhiteSpace(from.PhoneNumber)) { <text> - Téléphone fixe: @TeXHelpers.ToTeX(from.PhoneNumber) </text> } \small{ E-mail: @TeXHelpers.ToTeX(from.Email) @if (!string.IsNullOrWhiteSpace(from.PhoneNumber)) { <text> - Téléphone fixe: @TeXHelpers.ToTeX(from.PhoneNumber) </text> }
} }
} }
@ -115,7 +114,7 @@
% Logo de la société % Logo de la société
@if (from.Avatar != null) { @if (from.Avatar != null) {
<text>\includegraphics{@from.Avatar} <text>\includegraphics[height=60pt]{@(ViewBag.AvatarsDir)/@(from.UserName).png}
</text> </text>
} else { } else {
<text>%\includegraphics{logo.png} <text>%\includegraphics{logo.png}
@ -123,7 +122,7 @@
} }
% Nom et adresse de la société % Nom et adresse de la société
@TeXHelpers.ToTeX(from.UserName) \\ @TeXHelpers.ToTeX(from.UserName) \\
@TeXHelpers.ToTeX(proaddrn) @proaddr
Facture n°\FactureNum Facture n°\FactureNum
@ -188,5 +187,18 @@ Facture n°\FactureNum
} }
} }
}
@if (!(Model.ProviderValidationDate==null)) {
<text>
\begin{flushright}
Facture validée le @TeXHelpers.ToTeX(Model.ProviderValidationDate.ToString("dddd dd MMMM yyyy",
CultureInfo.CreateSpecificCulture("fr-FR"))).ToHtmlString()
\end{flushright}
\begin{center}
\hspace{263pt}
\includegraphics[height=60pt]{@(ViewBag.BillsDir)/estimate-prosign-@(Model.Id).png}
\end{center}
</text>
} }
\end{document} \end{document}

Loading…