awk -F= 'BEGIN {
T["00"]="REGISTRO"
T["01"]="Nº DOCUMENTO DTE"
T["02"]="EMSIóN"
T["03"]="VENCIMIENTO"
T["04"]="PROVEEDOR"
T["05"]="RESPONSABLE"
T["06"]="STATUS"
T["07"]="FORMA DE PAGO"
T["08"]="FECHA PAGO"
T["09"]="OBSERVACIONES"
T["10"]="VALOR NETO"
T["11"]="VALOR IVA"
T["12"]="VALOR BRUTO"
T["13"]="PRD"
T["14"]="DESCRIPCION"
T["15"]="PRECIO"
T["16"]="CANT"
T["17"]="TOTAL"
T["18"]="INDICACIONES"
printf "%s^",T["00"]
NH=13
}
!/adquisicionesmpH/ && !/adquisicionesmpD00/  { next }
$2!="" && /adquisicionesmpH/ {
        if(substr($1,length($1)-1)!="00")
        {
                x=substr($1,length($1)-1)
                printf "%s^",T[x]
        }
}
$2!="" && /adquisicionesmpD/ {
                x=sprintf("%.2d",substr($1,length($1)-1)+NH)
                printf "%s^",T[x]
}
END {
	print ""
} ' $1 |
awk -F^ ' BEGIN {
ttop("B&uacute;squeda en Compras de Materia Prima");bgcolor="#FFFFFF"}
{
for (i=1;i<NF;i++ ) printf "%s^",trail($i)>"tmp/'"$0"'"
print "">"tmp/'"$0"'"
}
NR==1 { print "<tr>";labels("##"); for (i=1; i<NF; i++) labels(trail($i))
print "</tr>"
next
}
function trail(txt) { while (substr(txt,length(txt),1)==" ") txt=substr(txt,1,length(txt)-1); return (txt) }
{
print "<tr>";label(NR-1,"")
	for (i=1; i<NF; i++)if (i==1) boton($i)
	else { split($i,a,"|")
	if(a[2]=="") label($i,"")
	else label(a[2],"")
	}
print "</tr>"
}
END { foot() } 
function boton(value)
{
	print "<td>"
	printf "<input id=\"submit\" type=\"submit\" center value=\"%s\" name=\"T02\">\n",value
	print "</td>"
}
function label(value,sty)
{
        if(value+0 || trail(value)=="0") align=" align=\"right\""
	else align=""
printf "<td%s %s>",align,sty
printf "&nbsp;%s&nbsp;\n",trail(value)
print "</td>"
}
function labels(value)
{
print "<th>"
printf "&nbsp;%s&nbsp;\n",trail(value)
print "</th>"
}
function ttop(value)
{
print "<! DOCTYPE html>"
print "<html lang=\"en-US\">"
print "<head>"
print "<meta charset=\"UTF-8\">"
print "<meta http-equiv=\"Content-Type\" content=\"text/html\">"
print "<meta name=\"GENERATOR\" content=\"Inhedo 4gt 1.0\">"
print "<meta name=\"ProgId\" content=\"Inhedo Form Generator\">"
print "<link rel=\"stylesheet\" href=\"../css/list.css\">"
printf "<title>%s</title>\n",value
print "</head>"
print "<body>"
print "<center>"
print "<tr><img border=\"0\" src=\"../logol.png\" width=\"120\" height=\"97\" style=\"background:#7C0A76;border:solid 1px #FFFF00;\"></tr>"
printf "<H2>B&uacute;squeda en Compras de Materia Prima</H2>\n"
print "<form method=\"post\" action=\"../cgi-bin/adquisicionesmpbsc.cgi\" name=billform>"
print "<table id=\"customers\">"
printf "<input type=\"hidden\" value=\"Query\" name=\"B1\">\n"
print "</center>"
}
function foot()
{
print "</table>"
print "<b>"NR -1 " Registros</b>"
print "</center>"
print "</form>"

} ' - $2
awk ' BEGIN {
print "<form method=\"GET\" name=\"excel\" action=\"../cgi-bin/exc.cgi\">"
printf "<input type=\"hidden\" value=\"%s\" name=\"F1\">\n","'"$1"'"
print "<input type=\"hidden\" value=\"adquisicionesmp\" name=\"B2\">"
printf "<p align=\"center\"><input type=\"submit\" value=\"Continuar\" name=\"B1\" style=\"width: 100; height: 20; font-weight: bold; font-size: 10pt\">\n"
printf "<input type=\"submit\" value=\"Excel\" name=\"B1\" style=\"width: 100; height: 20; font-weight: bold; font-size: 10pt\"></p>\n"
print "</form>"
print "</body>"
print "</html>"
printf "<script language=\"Javascript\" src=\"../js/cols.js\"></script>\n"
exit } ' - $2
