cd MIG
rm MIG/*
prods=/tmp/prods
ihdm prods h00"^" h01"^" h02"^" h03"^" h04"^" h05"^" h06"^" h07"^" h08"^" h09"^" h10"^" h11"^" h12"^" h13"^" h14"^" h15"^" h16"^" h17"^" h18"^" h19"^" h20"^" h21"^" h22"^" h23"^" h24"^" h25 > $prods

# |  1 H00 identi 06 15   0 | 2 H01 codbar 15 00   6 | 3 H02 codig  12 00  21 |
# |  4 H03 descrl 40 00  33 | 5 H04 descrC 25 00  73 | 6 H05 grupo  02 51  98 |
# |  7 H06 sgrupo 02 52 100 | 8 H07 impto1 02 53 102 | 9 H08 vimp1  07 00 104 |
# | 10 H09 impto2 02 54 111 |11 H10 vimp2  07 00 113 |12 H11 unidvt 02 55 120 |
# | 13 H12 provee 13 56 122 |14 H13 provee 13 57 135 |15 H14 polit1 03 01 148 |
# | 16 H15 precv1 07 01 151 |17 H16 polit2 03 01 158 |18 H17 precv2 07 01 161 |
# | 19 H18 polit3 03 01 168 |20 H19 precv3 07 01 171 |21 H20 seriad 10 15 178 |
# | 22 H21 stock  05 01 188 |23 H22 costo  10 01 193 |24 H23 minimo 05 01 203 |
# | 25 H24 minimo 05 01 208 |26 H25 status 02 58 213 |

venta=/tmp/venta

# |  1 H00 fventa 06 00   0 | 2 H01 fechai 16 00   6 | 3 H02 kilom1 06 00  22 |
# |  4 H03 vende  04 56  28 | 5 H04 fechat 16 00  32 | 6 H05 kilom2 06 01  48 |
# |  7 H06 valorg 10 01  54 | 8 H07 gastos 246 11  64 | 9 H08 faltan 10 01 310 |

# 10 D00 client  10  55 | 11 D01 guiads  6   01 | 12 D02 9milim  7   01 | 
# 13 D03 12mili  7   01 | 14 D04 penter  7   01 | 15 D05 pestof  7   01 | 
# 16 D06 ppcubo  7   01 | 17 D07 pcort6  7   01 | 18 D08 mallas  4   01 | 
# 19 D09 sacosp  4   01 | 20 D10 kgrane  7   01 | 21 D11 codigs  20  15 | 
# 22 D12 tkilos  8   01 | 23 D13 vlrvta  10  01 | 24 D14 vlrpag  10  01 | 
# 25 D15 frpago  2   57 | 

cliok=/tmp/cliok
ihdm cliok h00"^" h01"^" h02"^" h03"^" h04"^" h05"^" h06"^" h07"^" h08"^" h09"^" h10"^" h11"^" h12"^" h13"^" h14"^" d00"^" d01 > $cliok

# |  1 H00 codigo 10 00   0 | 2 H01 rutcli 13 00  10 | 3 H02 identi 40 00  23 |
# |  4 H03 girocl 25 00  63 | 5 H04 direcc 40 00  88 | 6 H05 comuna 25 00 128 |
# |  7 H06 ciudad 25 00 153 | 8 H07 telefo 25 00 178 | 9 H08 cortec 20 00 203 |
# | 10 H09 atenci 04 55 223 |11 H10 fopago 20 00 227 |12 H11 contac 30 00 247 |
# | 13 H12 cargoe 30 00 277 |14 H13 telefo 30 00 307 |15 H14 emailc 40 00 337 |

# 16 D00 codigp  6   51 | 17 D01 precio  10  01 | 

tipos=/tmp/tipos
ihdm tipos h00"^" h01 > $tipos

# |  1 H00 codigo 02 00   0 | 2 H01 descri 10 00   2 |

ihdm venta h00"^" h01"^" h02"^" h03"^" h04"^" h05"^" h06"^" h07"^" h08"^" d00"^" d01"^" d02"^" d03"^" d04"^" d05"^" d06"^" d07"^" d08"^" d09"^" d10"^" d11"^" d12"^" d13"^" d14"^" d15 |
awk -F"^" ' index($2,"12/2019") '  > $venta

awk -F"^" ' 
FILENAME==ARGV[1] { cl[$1]=$3 ; next }
FILENAME==ARGV[2] { pr[$1]=$4 ; un[$1]=$12;next }
FILENAME==ARGV[3] { tp[$1]=$2 ; next }
$23+0==0 && $24+0  { zz=zz""trail($10)"|"cl[$10]"||" $24"|" $25"|" }
ant!=$1 {
if(ant!="") print "H10|"zz" " >file
file="MIG/"$1
 print "H00"$1 >file
 print "H01"$2 >file
 print "H02"$3 >file
 print "H03"$4 >file
 print "H04"$5 >file
 print "H05"$6 >file
 print "H06"$7 >file
 print "H07"$8 >file
 print "H08"$9 >file
 ant=$1
zz=""
jj=0
}
$12 +0 {
doc=sprintf("D%.2d",jj)
print doc"00"trail($10) >file
print doc"01"cl[$10] >file
print doc"02"$11 >file
cod="000001"
print doc"03"cod >file
print doc"04"tp[un[cod]] >file
printf "%s05%.2f\n",doc,$23/$22 >file
print doc"06"$12 >file
print doc"07"$12*$23/$22 >file
if($25=="EF") print doc"08"$12*$23/$22 >file
print doc"09"$25" " >file
jj++
} 
$13 +0 {
doc=sprintf("D%.2d",jj)
print doc"00"trail($10) >file
print doc"01"cl[$10] >file
print doc"02"$11 >file
cod="000002"
print doc"03"cod >file
print doc"04"tp[un[cod]] >file
printf "%s05%.2f\n",doc,$23/$22 >file
print doc"06"$13 >file
print doc"07"$13*$23/$22 >file
if($25=="EF") print doc"08"$13*$23/$22 >file
print doc"09"$25" " >file
jj++
} 
$14 +0 {
doc=sprintf("D%.2d",jj)
print doc"00"trail($10) >file
print doc"01"cl[$10] >file
print doc"02"$11 >file
cod="000003"
print doc"03"cod >file
print doc"04"tp[un[cod]] >file
printf "%s05%.2f\n",doc,$23/$22 >file
print doc"06"$14 >file
print doc"07"$14*$23/$22 >file
if($25=="EF") print doc"08"$14*$23/$22 >file
print doc"09"$25" " >file
jj++
} 
$15 +0 {
doc=sprintf("D%.2d",jj)
print doc"00"trail($10) >file
print doc"01"cl[$10] >file
print doc"02"$11 >file
cod="000004"
print doc"03"cod >file
print doc"04"tp[un[cod]] >file
printf "%s05%.2f\n",doc,$23/$22 >file
print doc"06"$15 >file
print doc"07"$15*$23/$22 >file
if($25=="EF") print doc"08"$15*$23/$22 >file
print doc"09"$25" " >file
jj++
} 
$16+0 {
doc=sprintf("D%.2d",jj)
print doc"00"trail($10) >file
print doc"01"cl[$10] >file
print doc"02"$11 >file
cod="000005"
print doc"03"cod >file
print doc"04"tp[un[cod]] >file
printf "%s05%.2f\n",doc,$23/$22 >file
print doc"06"$16 >file
print doc"07"$16*$23/$22 >file
if($25=="EF") print doc"08"$16*$23/$22 >file
print doc"09"$25" " >file
jj++
} 
$17 +0 {
doc=sprintf("D%.2d",jj)
print doc"00"trail($10) >file
print doc"01"cl[$10] >file
print doc"02"$11 >file
cod="000006"
print doc"03"cod >file
print doc"04"tp[un[cod]] >file
printf "%s05%.2f\n",doc,$23/$22 >file
print doc"06"$17 >file
print doc"07"$17*$23/$22 >file
if($25=="EF") print doc"08"$17*$23/$22 >file
print doc"09"$25" " >file
jj++
} 
$18 +0 {
doc=sprintf("D%.2d",jj)
print doc"00"trail($10) >file
print doc"01"cl[$10] >file
print doc"02"$11 >file
cod="000007"
print doc"03"cod >file
print doc"04"tp[un[cod]] >file
printf "%s05%.2f\n",doc,$23/$22 >file
print doc"06"$18 >file
print doc"07"$18*$23/$22 >file
if($25=="EF") print doc"08"$18*$23/$22 >file
print doc"09"$25" " >file
jj++
} 
$19 +0 {
doc=sprintf("D%.2d",jj)
print doc"00"trail($10) >file
print doc"01"cl[$10] >file
print doc"02"$11 >file
cod="000008"
print doc"03"cod >file
print doc"04"tp[un[cod]] >file
printf "%s05%.2f\n",doc,$23/$19 >file
print doc"06"$19 >file
print doc"07"$19*$23/$19 >file
if($25=="EF") print doc"08"$19*$23/$22 >file
print doc"09"$25" " >file
jj++
} 
function trail(txt) { while (substr(txt,length(txt),1)==" ") txt=substr(txt,1,length(txt)-1); return (txt) }
END {

print "H10|"zz" " >file

} 
 ' $cliok $prods $tipos $venta
>../data/docvt/H


echo "    0      0" >../data/docvt/INFO

for i in MIG/*
do
echo ../ihd/bin/ihmu docvt ../../MIG/$i
../ihd/bin/ihmu docvt ../../MIG/$i
done
