%{#
    Copyright (c) 2015 Chintalagiri Shashank
    Released under the MIT license
%#}

\documentclass[fontsize=9pt, BCOR=1.5cm, DIV=14, twoside, titlepage = false]{scrartcl}
\usepackage[top=2cm, bottom=3cm, left=2.5cm, right=2.5cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{tabularx}
\usepackage{ltablex}
\usepackage{array}
\usepackage{multicol}
\usepackage{colortbl}
\usepackage{tfrupee}
\pdfmapfile{=tfrupee.map}
\usepackage{lastpage}
\usepackage[lighttt]{lmodern}

\newcommand{\pcbname}{%{{stage.configname%}}}
\newcommand{\ptitle}{%{{stage.title%}}}
\newcommand{\sno}{%{{stage.sno%}}}

\usepackage[%
  automark,
  headsepline,                %% Separation line below the header
  footsepline,               %% Separation line above the footer
  markuppercase
]{scrpage2}

\lehead{\tt \ptitle  AM  \pcbname\ S.\sno}    %% Top left on even pages
\lohead{\includegraphics[width=0.12in]{%{{stage.logo%}}}\hspace{0.01in} \tt %{{stage.company%}}}    %% Top left on odd pages
\rehead{\tt %{{stage.company%}}\hspace{0.1in}\includegraphics[width=0.12in]{%{{stage.logo%}}}}    %% Top right on even pages
\rohead{\tt \ptitle  AM  \pcbname\ S.\sno}    %% Top right on odd pages
\chead{}                       %% Top center

\rofoot{\tt Page \thepage\ of \pageref{LastPage}}
\lefoot{\tt Page \thepage\ of \pageref{LastPage}}
\cfoot{}


\title{\ptitle  Assembly Manifest}
\subtitle{}
\author{}
\date{}

\makeatletter
\renewcommand{\@maketitle}{
\begin{center}
  \ifx\@subject\@empty \else
    {\subject@font \@subject \par}
  \fi
  \titlefont\huge \@title\par
\end{center}
}
\makeatother


\makeatletter
  \def\cleardoublepage{\clearpage%
    \if@twoside
      \ifodd\c@page\else
	\section*{Notes}
	\newpage
	\if@twocolumn\hbox{}\newpage\fi
      \fi
    \fi
  }
\makeatother

%opening
\begin{document}
\pagestyle{scrheadings}
\maketitle
\thispagestyle{scrheadings}
\begin{center}
 
\keepXColumns
\renewcommand{\arraystretch}{1.3}
\small
\begin{tabularx}{1.0\textwidth}{>{\raggedleft\arraybackslash}p{0.15\textwidth}>{\raggedright\arraybackslash}p{0.25\textwidth}>{\raggedleft\arraybackslash}p{0.20\textwidth}>{\raggedright\arraybackslash}p{0.25\textwidth}}
\small{Card Name:} & {\ttfamily\bfseries\normalsize \pcbname} & Production Order:& {\tt %{{stage.productionorderno%}}} \\
\small{S.No.:} & {\ttfamily\bfseries\normalsize \sno} & Stock Indent: & {\tt %{{stage.stockindent%}}}\\
\small{Base PCB:} & {\ttfamily  %{{stage.pcbname%}}} & Assembly Date: & \\
\small{Description:} & \multicolumn{3}{l}{\ttfamily \parbox{0.7\textwidth}{%{{stage.desc%}}}} \\
\small{Repository Path:} & \multicolumn{3}{l}{\ttfamily \parbox{0.7\textwidth}{%{{stage.repopath%}}}} \\
\end{tabularx}
\renewcommand{\arraystretch}{1.1}
\begin{tabularx}{1.0\textwidth}{>{\centering\arraybackslash}p{0.07\textwidth}|>{\centering\arraybackslash}p{0.07\textwidth}|>{\centering\arraybackslash}p{0.07\textwidth}|>{\centering\arraybackslash}p{0.07\textwidth}|>{\centering\arraybackslash}p{0.07\textwidth}|>{\centering\arraybackslash}p{0.07\textwidth}|>{\centering\arraybackslash}p{0.07\textwidth}|>{\centering\arraybackslash}p{0.07\textwidth}|>{\centering\arraybackslash}p{0.07\textwidth}|>{\centering\arraybackslash}p{0.07\textwidth}|}
  \hline
  \multicolumn{10}{|c|}{\cellcolor[gray]{0.8}\normalsize\textbf{BOM}}\tabularnewline\hline
  %{ for line in stage.lines %}
  %{ if line.refdeslist|count > 5 %}
  \rowcolor[gray]{0.9}\multicolumn{1}{|c|}{%{{loop.index%}}.} & \multicolumn{6}{l}{%{{line.ident|escape_latex%}}} & \multicolumn{3}{r|}{%{{line.quantity%}}} \\\hline\nopagebreak[4]
  %{ for refdes in line.refdeslist %} & %{{refdes%}} %{ if loop.last %} %{set llen = loop.index%9 %} %{ if llen == 0 %} %{set llen = 9 %} %{endif%}  \\* %{for i in range(llen)%} & %{endfor%} \\\hline %{ elif loop.index is divisibleby 9 %} \\\nopagebreak[4] & & & & & & & & & \\\cline{2-10}\nopagebreak[4]  %{ endif %} %{ endfor %} 
  %{ else %}
  \multicolumn{1}{|c|}{\cellcolor[gray]{0.9} %{{loop.index%}}.} & \multicolumn{%{{8-line.refdeslist|count%}}}{l|}{\cellcolor[gray]{0.9}\parbox{%{{0.07*(8-line.refdeslist|count)%}}\textwidth}{%{{line.ident|escape_latex%}}}} & %{ for refdes in line.refdeslist %} %{{refdes%}} & %{ endfor %} \multicolumn{1}{r|}{\cellcolor[gray]{0.9} %{{line.quantity%}}} \\\cline{1-%{{9-line.refdeslist|count%}}}\cline{10-10}  
  \multicolumn{%{{9-line.refdeslist|count%}}}{|c|}{\cellcolor[gray]{0.98}} & %{ for refdes in line.refdeslist %} & %{ endfor %} \multicolumn{1}{r|}{\cellcolor[gray]{0.99}} \\\hline  
  %{ endif %} 
  %{ endfor %} 
\end{tabularx}

\end{center}

\begin{tabular}{|>{\centering\arraybackslash}p{0.22\textwidth}|>{\centering\arraybackslash}p{0.22\textwidth}|>{\centering\arraybackslash}p{0.44\textwidth}|}
\hline
  \small Assembly Complete  & \small PCB Inspected & \small Blocking Issues \\\nopagebreak[4]
  & & \\\nopagebreak[4]
  \small Date & \small Date & \\
\hline
\end{tabular}
%{ if stage.evenpages == True %}
\cleardoublepage
%{ endif %} 
\end{document}


