\documentclass[a4paper]{article}

% LAYOUT
%--------------------------------
\usepackage{tikz}
% Set font for xelatex compilation
\usepackage{fontspec}
\setmainfont{Lato}
\newcommand{\euro}{€}
\usepackage{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
\usepackage{booktabs,tabularx}
\usepackage{graphicx}
\usepackage{parskip}
\usepackage{multirow}
\usepackage[left=2cm, right=2cm, top=2cm, bottom=2cm]{geometry}

% LANGUAGE
%--------------------------------
\usepackage{polyglossia}
\setmainlanguage{es_ES}


\usepackage{tikz}
\newcommand{\logo}[1]{
  \begin{tikzpicture}[y=0.80pt, x=0.80pt, yscale=-{ {{"#1"}} }, xscale={ {{"#1"}} }, inner sep=0pt, outer sep=0pt]
    \begin{scope}[shift={(3.54331,-984.39026)}]
      \begin{scope}[shift={(-161.98599,807.24042)}]
        \begin{scope}[shift={(-13.57143,-11.78571)},fill=black,line join=miter,line cap=butt,line width=0.800pt]
          \path[fill] (175.5574,234.4789) -- (203.0824,234.4789) -- (203.0824,231.7789) --
          (178.7824,231.7789) -- (178.7824,214.5289) -- (199.3324,214.5289) --
          (199.3324,211.8289) -- (178.7824,211.8289) -- (178.7824,195.9289) --
          (203.0824,195.9289) -- (203.0824,193.2289) -- (175.5574,193.2289) --
          (175.5574,234.4789) -- cycle;
          \path[fill] (208.2234,234.4789) -- (211.4484,234.4789) -- (211.4484,193.2289) --
          (208.2234,193.2289) -- (208.2234,234.4789) -- cycle;
          \path[fill] (216.6375,219.7039) .. controls (216.6375,230.9539) and
          (225.3375,235.3039) .. (233.1375,235.3039) .. controls (244.9875,235.3039) and
          (248.4375,230.5789) .. (249.1875,226.0789) -- (245.5875,226.0789) .. controls
          (244.8375,227.9539) and (243.4125,232.0789) .. (233.1375,232.0789) .. controls
          (227.2125,232.0789) and (220.6875,228.4789) .. (220.1625,221.0539) --
          (249.1875,221.0539) -- (249.1875,217.8289) .. controls (248.4375,207.4039) and
          (242.7375,202.0789) .. (233.1375,202.0789) .. controls (223.5375,202.0789) and
          (216.6375,209.2789) .. (216.6375,219.7039) -- cycle(220.3125,217.8289) ..
          controls (221.3625,209.9539) and (225.4875,205.2289) .. (233.4375,205.2289) ..
          controls (241.3875,205.2289) and (244.8375,210.3289) .. (245.5875,217.8289) --
          (220.3125,217.8289) -- cycle;
          \path[fill] (254.5875,234.4789) -- (257.8125,234.4789) -- (257.8125,208.6039) ..
          controls (259.3875,206.5789) and (262.8375,205.3789) .. (268.0125,205.3789) ..
          controls (271.6125,205.3789) and (276.1125,206.7289) .. (276.1125,213.0289) --
          (276.1125,234.4789) -- (279.5625,234.4789) -- (279.5625,213.0289) .. controls
          (279.5625,204.7789) and (273.4125,202.0789) .. (268.0125,202.0789) .. controls
          (262.4625,202.0789) and (258.9375,203.4289) .. (257.8125,206.1289) --
          (257.8125,202.9039) -- (254.5875,202.9039) -- (254.5875,234.4789) -- cycle;
          \path[fill] (284.5312,213.8539) .. controls (284.5312,225.0289) and
          (293.8313,235.3039) .. (305.1562,235.3039) .. controls (309.9563,235.3039) and
          (314.3062,233.4289) .. (317.8313,230.5039) -- (322.6313,234.4789) --
          (326.3813,234.4789) -- (319.7812,228.7039) .. controls (323.4563,224.7289) and
          (325.7812,219.4039) .. (325.7812,213.8539) .. controls (325.7812,202.7539) and
          (316.5562,192.4789) .. (305.1562,192.4789) .. controls (293.7563,192.4789) and
          (284.5312,202.6789) .. (284.5312,213.8539) -- cycle(287.8313,213.8539) ..
          controls (287.8313,204.7039) and (295.4062,195.5539) .. (305.1562,195.5539) ..
          controls (314.9062,195.5539) and (322.4812,204.7039) .. (322.4812,213.8539) ..
          controls (322.4812,223.0039) and (314.9062,232.2289) .. (305.1562,232.2289) ..
          controls (295.4062,232.2289) and (287.8313,223.0039) .. (287.8313,213.8539) --
          cycle;
        \end{scope}
        \begin{scope}[fill=black,line join=miter,line cap=butt,line width=0.800pt]
          \path[fill] (176.4077,232.6768) -- (180.4452,232.6768) -- (180.4452,244.8605) --
          (181.4665,244.8605) -- (181.4665,232.6768) -- (185.5277,232.6768) --
          (185.5277,231.7980) -- (176.4077,231.7980) -- (176.4077,232.6768) -- cycle;
          \path[fill] (187.0132,244.8605) -- (195.7295,244.8605) -- (195.7295,244.0055) --
          (188.0345,244.0055) -- (188.0345,238.5430) -- (194.5420,238.5430) --
          (194.5420,237.6880) -- (188.0345,237.6880) -- (188.0345,232.6530) --
          (195.7295,232.6530) -- (195.7295,231.7980) -- (187.0132,231.7980) --
          (187.0132,244.8605) -- cycle;
          \path[fill] (197.2387,238.3293) .. controls (197.2387,242.6043) and
          (199.2099,245.1218) .. (202.8674,245.1218) .. controls (205.6699,245.1218) and
          (208.0212,243.6255) .. (208.0212,241.4880) -- (206.8812,241.4880) .. controls
          (206.8812,242.7943) and (205.3137,244.1005) .. (202.8674,244.1005) .. controls
          (199.7087,244.1005) and (198.3549,241.0368) .. (198.3549,238.3293) .. controls
          (198.3549,235.2180) and (200.1837,232.5580) .. (202.9624,232.5580) .. controls
          (205.3849,232.5580) and (206.8812,233.8168) .. (206.8812,235.2418) --
          (208.0212,235.2418) .. controls (208.0212,232.8905) and (205.6699,231.5605) ..
          (202.8674,231.5605) .. controls (198.9724,231.5605) and (197.2387,235.0280) ..
          (197.2387,238.3293) -- cycle;
          \path[fill] (209.6499,244.8605) -- (210.6712,244.8605) -- (210.6712,238.5430) --
          (217.1787,238.5430) -- (217.1787,244.8605) -- (218.1999,244.8605) --
          (218.1999,231.7980) -- (217.1787,231.7980) -- (217.1787,237.6880) --
          (210.6712,237.6880) -- (210.6712,231.7980) -- (209.6499,231.7980) --
          (209.6499,244.8605) -- cycle;
          \path[fill] (219.9942,244.8605) -- (221.0392,244.8605) -- (221.0392,233.7455) --
          (228.2354,244.8605) -- (229.2567,244.8605) -- (229.2567,231.7980) --
          (228.2354,231.7980) -- (228.2354,243.0318) -- (221.0392,231.7980) --
          (219.9942,231.7980) -- (219.9942,244.8605) -- cycle;
          \path[fill] (230.8917,238.3293) .. controls (230.8917,241.8680) and
          (233.8367,245.1218) .. (237.4229,245.1218) .. controls (241.0092,245.1218) and
          (243.9542,241.8680) .. (243.9542,238.3293) .. controls (243.9542,234.8143) and
          (241.0329,231.5605) .. (237.4229,231.5605) .. controls (233.8129,231.5605) and
          (230.8917,234.7905) .. (230.8917,238.3293) -- cycle(231.9367,238.3293) ..
          controls (231.9367,235.4318) and (234.3354,232.5343) .. (237.4229,232.5343) ..
          controls (240.5104,232.5343) and (242.9092,235.4318) .. (242.9092,238.3293) ..
          controls (242.9092,241.2268) and (240.5104,244.1480) .. (237.4229,244.1480) ..
          controls (234.3354,244.1480) and (231.9367,241.2268) .. (231.9367,238.3293) --
          cycle;
          \path[fill] (245.5521,244.8605) -- (253.4609,244.8605) -- (253.4609,243.8393) --
          (246.5734,243.8393) -- (246.5734,231.7980) -- (245.5521,231.7980) --
          (245.5521,244.8605) -- cycle;
          \path[fill] (254.9200,238.3293) .. controls (254.9200,241.8680) and
          (257.8650,245.1218) .. (261.4513,245.1218) .. controls (265.0375,245.1218) and
          (267.9825,241.8680) .. (267.9825,238.3293) .. controls (267.9825,234.8143) and
          (265.0613,231.5605) .. (261.4513,231.5605) .. controls (257.8413,231.5605) and
          (254.9200,234.7905) .. (254.9200,238.3293) -- cycle(255.9650,238.3293) ..
          controls (255.9650,235.4318) and (258.3638,232.5343) .. (261.4513,232.5343) ..
          controls (264.5388,232.5343) and (266.9375,235.4318) .. (266.9375,238.3293) ..
          controls (266.9375,241.2268) and (264.5388,244.1480) .. (261.4513,244.1480) ..
          controls (258.3638,244.1480) and (255.9650,241.2268) .. (255.9650,238.3293) --
          cycle;
          \path[fill] (269.5092,238.3293) .. controls (269.5092,242.6043) and
          (271.4805,245.1218) .. (275.1380,245.1218) .. controls (276.7767,245.1218) and
          (278.2255,244.5993) .. (279.1517,243.7443) -- (279.1517,244.8605) --
          (280.1730,244.8605) -- (280.1730,238.4480) -- (274.9480,238.4480) --
          (274.9480,239.4693) -- (279.1517,239.4693) -- (279.1517,241.4880) .. controls
          (279.1517,242.7943) and (277.5842,244.1005) .. (275.1380,244.1005) .. controls
          (271.9792,244.1005) and (270.6255,241.0368) .. (270.6255,238.3293) .. controls
          (270.6255,235.2180) and (272.4542,232.5580) .. (275.2330,232.5580) .. controls
          (277.6555,232.5580) and (279.1517,233.8168) .. (279.1517,235.2418) --
          (280.1730,235.2418) .. controls (280.1730,232.8905) and (277.9405,231.5605) ..
          (275.1380,231.5605) .. controls (271.2430,231.5605) and (269.5092,235.0280) ..
          (269.5092,238.3293) -- cycle;
          \path[fill] (281.6818,231.7980) -- (286.4318,239.4218) -- (286.4318,244.8605) --
          (287.4531,244.8605) -- (287.4531,239.4218) -- (292.2268,231.7980) --
          (291.0868,231.7980) -- (286.9543,238.4480) -- (282.8456,231.7980) --
          (281.6818,231.7980) -- cycle;
        \end{scope}
      \end{scope}
    \end{scope}
  \end{tikzpicture}}


% PDF SETUP
%--------------------------------
\usepackage[xetex, bookmarks, colorlinks, breaklinks]{hyperref}
\hypersetup
{
  pdfauthor=ElenQ Technology,
  pdfsubject= Factura {{invoice.id}},
  pdftitle= Factura {{invoice.id}},
  linkcolor=blue,
  citecolor=blue,
  filecolor=black,
  urlcolor=blue
}

% DOCUMENT
%--------------------------------
\begin{document}
\pagestyle{empty}


\begin{center}
\logo{1.3}
\end{center}

% Client data
\section*{CLIENTE}
{% for line in invoice.customer.address.split("\n") -%}
  {{line}}\\
{% endfor -%}
  {{invoice.customer.id}}

% Invoice start
\section*{FACTURA}

Número de factura:  {{ invoice.id }}\\
Fecha: {{ invoice.date }}

\begin{table}[h]
\begin{tabularx}{\textwidth}{lcccc}

  \toprule
  \multirow{2}{*}{\textbf{DESCRIPCIÓN}} & \textbf{PRECIO UD.} & \textbf{UNIDADES} & \textbf{BASE IMP.} & \textbf{IVA} \\
                                        & (€/h)               & (h)               & (€)              & (\%) \\
  \midrule

  {% for i in invoice.products -%}
    {{i.description}} & {{i["price-unit"]}} & {{i.units}} & {{i.base}}  & {{i.vat * 100}} \\
  {% endfor -%}
  \midrule

  \multirow{ 4 }{*}{
    \begin{tabular}{c}
      \textbf{FORMA DE PAGO}\\
        Transferencia o ingreso bancario\\
        Banca del mal ES00 0000 0000 00000 0000 0000
    \end{tabular}
  } &  & SUBTOTAL         & {{invoice.base}}\\

    &  & IVA & {{invoice["vat-charged"]}} \\
    {% for i in invoice.taxes %}
    &  & {{i.name}} ({{i.ratio}}\%)      & {{i.applied}}   \\
    {% endfor %}

      &  & \textbf{TOTAL}   & {{invoice.total}}  \\
  \bottomrule

\end{tabularx}
\end{table}


\begin{table}[h]
\begin{tabularx}{\textwidth}{ccc}
  \multicolumn{3}{c}{\textbf{Desglose IVA}} \\
  \textbf{\%} & \textbf{Base Imp.} & \textbf{Importe} \\

  {% for i in invoice["vat-summary"]-%}
  {{i.vat * 100}} & {{i.base}} &  {{i.charged}}\\
  {% endfor -%}

\end{tabularx}
\end{table}


\section*{OBSERVACIONES}
{%for i in invoice["notes"].split("\n") -%}
  {{i}}\\
{%endfor -%}


% Company data
\vfill
\begin{center}
  \textbf{Ekaitz Zárraga} \\
  Fernandez del Campo 8 Exterior 2ºD \\
  48010 Bilbao (Bizkaia) \\
  NIF: 45824316J \\
  \texttt{http://elenq.tech}
\end{center}
\vspace{2ex}

% End legal note
\hrulefill

{\small\itshape
 De acuerdo con lo que establece la Ley Orgánica de
 Protección de Datos (LOPD) 15/1999, le informamos que los datos
 personales recogidos en este documento serán incluidos en un fichero
 bajo la responsabilidad de EKAITZ ZARRAGA RIO, con la finalidad de
 cumplir los compromisos entre las partes. Puede ejercer sus derechos
 de acceso, rectificación, cancelación y oposición enviando un email a
 ekaitz@elenq.tech
}

\end{document}
