I work at a company that uses a program written in AWK to track various data and prepare reports. Worked with this program for three years plus (the author is no longer with us) and the YTD Production report will not return a report with a date after 123119. This is a problem. Below is the (I believe) the code for the print YTD report function.
<
function f_printytd( ytd_date, i, j, k) {
plus6 = 4
plus7 = 5
ytd_date = false
while ( ytd_date !~ /^[01][0-9][0-3][0-9][901][0-9]$/ ) {
printf("\n\t\tEnter last date for report (MMDDYY): ")
getline ytd_date < keyboard
if ( toupper(ytd_date) == "X" ) return false
if ( length(ytd_date) == 0 ) {
printf("\n\t\tUsing %s", datestr)
ytd_date = mdy_global
}
}
yymmdd = f_mdy2ymd(ytd_date) #y2k
yy = substr(yymmdd, 1, 2)
if ( yy < 50 ) YY = 20
else YY = 19
lastdate = sprintf("%s%s", YY, yymmdd)
FS = "%"
while ( ( getline < runlist ) > 0 ) {
A_ytd_gtype[$1] = $4
A_ytd_var[$1] = $5
}
close(runlist)
FS = "%"
while ( ( getline < packfile ) > 0 ) {
ymd = f_mdy2ymd($2) #y2k
y = substr(ymd, 1, 2)
if ( y < 50 ) Y = 20
else Y = 19
thisdate = sprintf("%s%s", Y, ymd)
if ( thisdate > lastdate ) continue
gt = A_ytd_gtype[$1]
vr = A_ytd_var[$1]
if ($3 ~ /^\#/) {
sub("#", "", $3)
A_ytd_trucks[gt] += $3
A_ytd_trucks["T"] += $3
A_ytd_hours[gt] += $4
A_ytd_hours["T"] += $4
}
else {
A_ytd_dt[$2]
ytd_cwt = $4 * prod_wght[$3] / 100
A_ytd_cwtV[vr] += ytd_cwt
if ($3 ~ /^1/) {
A_ytd_cwt1[gt] += ytd_cwt
A_ytd_cwt1[vr] += ytd_cwt
A_ytd_cwt1["T"] += ytd_cwt
if (prod_clas[$3] >= plus7) {
A_ytd_size[gt] += ytd_cwt
A_ytd_size[vr] += ytd_cwt
A_ytd_size["T"] += ytd_cwt
}
}
else if ($3 ~ /^2/) {
A_ytd_cwt2[gt] += ytd_cwt
A_ytd_cwt2[vr] += ytd_cwt
A_ytd_cwt2["T"] += ytd_cwt
}
else if ($3 ~ /^B/) {
A_ytd_cwtB[gt] += ytd_cwt
A_ytd_cwtB[vr] += ytd_cwt
A_ytd_cwtB["T"] += ytd_cwt
}
else {
A_ytd_cwtC[gt] += ytd_cwt
A_ytd_cwtC[vr] += ytd_cwt
A_ytd_cwtC["T"] += ytd_cwt
}
}
}
close(packfile)
printf("\t\t%s %s\n\n\t\t%s%s\n\n", datestr, co,
"YTD Production Summary Report Through ",
f_datef(ytd_date)) > tmpfile
f_ytd_printinfo("O", "Outside Growers:")
f_ytd_printinfo("S", "Share Growers:")
if ( f_ytd_printinfo("T", "\nTOTALS:") < 0 ) return
cwtTT = A_ytd_cwt1["T"] + A_ytd_cwt2["T"] + \
A_ytd_cwtB["T"] + A_ytd_cwtC["T"]
printf("\nProduction By Variety:\n\n") > tmpfile
printf("%11s%16s%12s%7s%7s%7s%7s\n", "Variety", "Total CWT",
"%7oz.", "%Ones", "%Twos", "%Bees", "%Cull") > tmpfile
for ( x in A_ytd_cwtV ) {
if ( A_ytd_cwt1[x] + 0 == 0 ) prt_size_val = 0
else prt_size_val = A_ytd_size[x] * 100 / A_ytd_cwt1[x]
printf(" %5.1f%% %-8s:%10.2f%12.1f%7.1f%7.1f%7.1f%7.1f\n",
A_ytd_cwtV[x] * 100 / cwtTT, x, A_ytd_cwtV[x],
prt_size_val,
A_ytd_cwt1[x] * 100 / A_ytd_cwtV[x],
A_ytd_cwt2[x] * 100 / A_ytd_cwtV[x],
A_ytd_cwtB[x] * 100 / A_ytd_cwtV[x],
A_ytd_cwtC[x] * 100 / A_ytd_cwtV[x]) > tmpfile
varT += A_ytd_cwtV[x]
}
printf("\t%19s\n\t%-8s:%10.2f\n",
"==========", "Checksum", varT) > tmpfile
for ( xx in A_ytd_dt ) if ( xx !~ /r$/ ) num_days++
if (num_days < 1)
printf("\n\nNo packing days reported.\n") > tmpfile
else printf("\n\nRun %d days, Avg: %.1f MTH/day, %d 12BC/day.\n",
num_days, A_ytd_hours["T"] / num_days,
cwtTT / num_days) > tmpfile
close(tmpfile)
printf("\a\n\t\t")
comm = sprintf("%s %s", printer, tmpfile)
system(comm)
}
function f_ytd_printinfo(n, name, tot_ytd_cwt) {
tot_ytd_cwt = A_ytd_cwt1[n] + A_ytd_cwt2[n] + \
A_ytd_cwtB[n] + A_ytd_cwtC[n]
if (tot_ytd_cwt * 100 < 5) { # less than 5 pounds
printf("\nNo Production For %s\n\n", name) > tmpfile
return -1
}
printf("\n%s\n%s\n", name, "================") > tmpfile
printf("%5.1f%% %-10s%10.2f%30s%9.1f%%\n",
A_ytd_cwt1[n] * 100 / tot_ytd_cwt, "Ones:",
A_ytd_cwt1[n], "Plus Seven Oz. :",
A_ytd_size[n] * 100 / A_ytd_cwt1[n]) > tmpfile
printf("%5.1f%% %-10s%10.2f%30s%10.1f\n",
A_ytd_cwt2[n] * 100 / tot_ytd_cwt, "Twos:", A_ytd_cwt2[n],
"Main Table Hrs.:", A_ytd_hours[n]) > tmpfile
printf("%5.1f%% %-10s%10.2f%30s%10.1f\n",
A_ytd_cwtB[n] * 100 / tot_ytd_cwt, "Bees:", A_ytd_cwtB[n],
"Truck loads run:", A_ytd_trucks[n]) > tmpfile
printf("%5.1f%% %-10s%10.2f%30s%10d\n",
A_ytd_cwtC[n] * 100 / tot_ytd_cwt, "Cull:",
A_ytd_cwtC[n], "Ones per MTH :",
A_ytd_cwt1[n] / A_ytd_hours[n]) > tmpfile
printf("%27s\n", "==========") > tmpfile
printf("%6s%-11s%10.2f\n\n", "", "Total:", tot_ytd_cwt) > tmpfile
}
function f_printpct( i, j, k, tot, total_cwt,
total_cw1, total_cw2, total_cwB, total_cwC) {
f_clear()
printf("\n\t%s%s %s\n\n\n",
co, " Print List Of Runs ", hist_code)
num_runs = f_getrunrg(A_runs)
if ( ! num_runs ) f_exit()
FS = "%"
for ( i = 1; i <= num_runs; i++ ) {
split(A_runs, runinfo, FS)
runn = runinfo[1]
A_runs[runn]
A_runn = runn
grcode = runinfo[2]
A_gstr[runn] = grwr_name[grcode]
A_lotnum[runn] = runinfo[3]
A_grt[runn] = runinfo[4]
A_vty[runn] = runinfo[5]
}
run_file = sprintf("%s%s\\%s", root_dir, data_dir, runf)
FS = "%"
while ( ( getline < run_file ) > 0 ) {
if ( $1 in A_runs ) {
pct_cwt = prod_wght[$2] * $3 / 100
if ( $2 ~ /^1/ ) {
A_pct_cw1[$1] += pct_cwt
if ( prod_clas[$2] >= 5 ) {
A_pct_7oz[$1] += pct_cwt
}
}
else if ( $2 ~ /^2/ ) A_pct_cw2[$1] += pct_cwt
else if ( $2 ~ /^B/ ) A_pct_cwB[$1] += pct_cwt
else if ( $2 ~ /^C/ ) A_pct_cwC[$1] += pct_cwt
}
else continue
}
close(run_file)
line = 500
for ( j = 1; j <= num_runs; j++ ) {
if ( line > 50 ) {
if ( line < 500 ) printf("\f") > tmpfile
printf("%s%s%s%3d\n\n%s\n\n\n", datestr, co,
" GAS Run Percentages Page",
++page, rng_str) > tmpfile
printf("%-5s%-2s%-33.31s%-10s%6s%6s%6s%6s%6s\n\n",
"RUN", "", "GROWER DESCRIPTION", "CWT RAN",
"%+7oz.", "%1's",
"%2's", "%B's", "%C's") > tmpfile
line = 5
}
r = A_runn[j]
grwrstr = sprintf("%s #%s, %s",
A_gstr[r], A_lotnum[r], A_vty[r])
tot = A_pct_cw1[r] + A_pct_cw2[r] + A_pct_cwB[r] + A_pct_cwC[r]
if ( tot == 0 ) continue
if ( A_pct_cw1[r] == 0 ) seven_oz = 0
else seven_oz = A_pct_7oz[r] * 100 / A_pct_cw1[r]
printf("%-6d%s-%-32.30s%9.2f%7.1f%6.1f%6.1f%6.1f%6.1f\n\n",
r, A_grt[r], grwrstr, tot,
seven_oz,
A_pct_cw1[r] * 100 / tot,
A_pct_cw2[r] * 100 / tot,
A_pct_cwB[r] * 100 / tot,
A_pct_cwC[r] * 100 / tot) > tmpfile
line += 2
total_7oz += A_pct_7oz[r]
total_cw1 += A_pct_cw1[r]
total_cw2 += A_pct_cw2[r]
total_cwB += A_pct_cwB[r]
total_cwC += A_pct_cwC[r]
}
total_cwt = total_cw1 + total_cw2 + total_cwB + total_cwC
if ( total_cw1 == 0 ) tot_seven_oz = 0
else tot_seven_oz = total_7oz * 100 / total_cw1
printf("\n%-40s%9.2f%7.1f%6.1f%6.1f%6.1f%6.1f\n",
"Totals for Runs in Range:", total_cwt,
tot_seven_oz,
total_cw1 * 100 / total_cwt,
total_cw2 * 100 / total_cwt,
total_cwB * 100 / total_cwt,
total_cwC * 100 / total_cwt) > tmpfile
close(tmpfile)
printf("\a\n\t")
comm = sprintf("%s %s", printer, tmpfile)
system(comm)
}
function f_FormatDate(date, c) {
if ( substr(date, 5, 2) > 50 ) c = 19
else c = 20
return sprintf("%s%s%s", c, substr(date, 5, 2), substr(date, 1, 4))
}
>
Any help would be greatly appreciated. Thanks, Paul G.