fpago=../tmp/fpago
ihdm fpago h00"^" h01 > $fpago
# |  1 H00 codigo 02 00   0 | 2 H01 formap 20 00   2 |
assoc=../tmp/assoc
ihdm assoc h00"^" h01"^" h02"^" h03"^" h04"^" h05"^" h06"^" h07"^" h08"^" h09"^" h10"^" h11"^" h12 > $assoc

# |  1 H00 codigo 03 01   0 | 2 H01 identi 50 00   3 | 3 H02 namess 20 00  53 |
# |  4 H03 lastna 25 00  73 | 5 H04 addres 30 00  98 | 6 H05 addres 20 00 128 |
# |  7 H06 cities 20 00 148 | 8 H07 state  02 55 168 | 9 H08 zipcod 10 01 170 |
# | 10 H09 emaill 50 00 180 |11 H10 celpho 15 00 230 |12 H11 otherp 15 00 245 |
# | 13 H12 social 20 15 260 |

awk -F"^" ' 
FILENAME==ARGV[1] { z=trail($2); x[z]=$1 ; next }
FILENAME==ARGV[2] { z=trail($2); a[z]=$1 ; next }
FILENAME==ARGV[3] { tn[$1]= sprintf("%.2f",nume($12)+nume($13)+nume($18)); next }
function parf(a0) { split(a0,a9,"-"); return a9[1]"/"a9[2]"/"a9[3] }
function nume(a0) { split(a0,a9,","); return sprintf("%.2f",a9[1]"."a9[2]) }
function trail(txt) { while (substr(txt,length(txt),1)==" ") txt=substr(txt,1,length(txt)-1); return (txt) }
FNR==1 { next }
xx[$1]=="" { xx[$1]="|" }
{
	xx[$1]=xx[$1]x[$4]"|"$3"|"$5"|"$6"|"$7"|"a[$13]"|"nume($8)"|"
	tot[$1] += nume($8)
}
END { for (i in xx)
	{
		file="VEN/"i
		printf "H22%.2f\n",tot[i] >>file
		printf "H23%.2f\n",tn[i]-tot[i] >>file
		print "H30"xx[i]" " >>file
		close(file)
	}
} ' $fpago $assoc VentasH Pay*
