# pop_all.awk by Dan Martin (DRM/CTG) Tue Feb 14 08:41:47 CST 1995 # Called by: SHELLS/pmpopp.sh SHELLS/podo.sh SHELLS/buy.sh # SHELLS/sell.sh SHELLS/xfer.sh # As of 03/27/95: replaces REPORTS/pms_po.ace # Mod 03/28/95: Print Unit Cost & Extended Values only on n-House # and uy or ell Purchase Orders (per bat). # PRECIOUS METALS PURCHASE ORDERS REPORT # Can produce any of three (count 'em: 3) versions: ax, ardcopy, # or n-House. Internal-Notes are NOT output with either # ax or ardcopy (i.e., Mailed-to-Vendor) versions, but the # n-House version ALWAYS outputs both Vendor & Internal Notes. # Note: Variable "fxhc" is one (only) of: ax, ardcopy or nternal, # and the value it contains controls which kind of PO is produced. # awk variables passed in from the calling squipt: # cona="$coname" plna="$plname" plad="$pladd" plct="$plcity" # plst="$plst" plzp="$plzip" pvph="$plvph" pfph="$plfph" # bmoc="$chief" btit="$title" pfix="$upit" fxhc="F" eof=EOF Line # # Records are pre-sorted (by Informix) in this sequence: # $1 = pomnum, $43 = poi_rec, $45 = pov_rec, $50 = ref_ain # awk fields are: # $1 = pomnum, $2 = podueby, $3 = po_vnd, $4 = po_attn, $5 = po_vdq, # $6 = po_vrf, $7 = po_rfq, $8 = po_req, $9 = po_via, $10 = po_cpp, # $11 = po_tax, $12 = po_cnf, $13 = po_trm, $14 = po_fob, $15 = ran, # $16 = rit, $17 = pomrem, $18 = po_fom, $19 = v_no, $20 = v_name, # $21 = v_add1, $22 = v_add2, $23 = v_city, $24 = v_st, $25 = v_zip, # $26 = v_con, $27 = v_con_ph, $28 = faxph, $29 = acctno, $30 = v_faxok, # $31 = who_log, $32 = who_at, $33 = who_tit, $34 = who_ami, $35 = shplnam, # $36 = shpladd, $37 = shplcty, $38 = shplst, $39 = shplzip, $40 = shplwho, # $41 = shplph, $42 = shplfx, $43 = poi_rec, $44 = poitxt, $45 = pov_rec, # $46 = povtxt, $47 = ref_name, $48 = ref_num, $49 = ref_ty, $50 = ref_ain, # $51 = ref_vpn, $52 = ref_key, $53 = ref_gdi, $54 = ref_edi, $55 = ref_sha, # $56 = ref_ega, $57 = ref_opt, $58 = ref_tpd, $59 = ref_flo, $60 = ref_sqi, # $61 = ref_run, $62 = pt_amte, $63 = pd_amte, $64 = rh_amte, $65 = ref_ln1, # $66 = ref_ln2, $67 = ref_ln3, $68 = ref_ln4, $69 = ref_ln5, $70 = ref_ln6, # $71 = ref_ln7, $72 = ref_due, $73 = ptm, $74 = pdm, $75 = rhm, # $76 = clo, $77 = ref, $78 = po_blnk # # $49 = ref_ty = efine, abricate, uy, ell, or Xfer n, ut BEGIN \ { yak = 0 # Yak-Switch which, if (yak == 1), blabs debuggerous yak-attacks. pgl = 88 # Page Length pct = 0 # Page Counter lsf = 0 # Lines So Far (Incoming from calling *.sh) need = 0 # Number of Lines Needed for Current Item jump = 0 # Used by tailer(n) to ratchet to bottom of page doli = 1 # switch: if = 1 prints Line Item Info. dovn = 0 # switch: if = 1 prints Vendor Notes. doin = 0 # switch: if = 1 prints Internal Notes. vyak = 0 # switch: if = 1 prints the literal "Vendor Notes". iyak = 0 # switch: if = 1 prints the literal "Internal Notes". fxnum = 1 # switch: if = 1 then prints fax command ("SND=" etc.). ept = 0 # Is -pt_amte if abricate, ell, or ut. epd = 0 # Is -pd_amte if abricate, ell, or ut. erh = 0 # Is -rh_amte if abricate, ell, or ut. eop = " " # END-OF PAGE FOR FAX MACHINE ("ZZZ"). psla = -1 # Previous Value Of Sort Level "A" sla = 0 # Sort Level "A" = $1 = pomnum = PO Number pslb = 0 # Previous Value Of Sort Level "B" slb = 0 # Sort Level "B" = $43 = poi_rec = Internal Note Index # pslc = 0 # Previous Value Of Sort Level "C" slc = 0 # Sort Level "C" = $45 = pov_rec = Vendor Note Index # psld = "ZY" # Previous Value Of Sort Level "D" sld = "ZZ" # Sort Level "D" = $50 = ref_ain = PO Line Item Number pvn = " " # Previous Vendor Note Line. pin = " " # Previous Internal Note Line. } # |<--------------[MAKE NO LINE BELOW LONGER THAN THIS]--------------->| # main() { # The Control-Logic of all the below is driven by comparing the # Current Value of a Sort Level with that of its Previous Value # [e.g., if (slb != pslb)]. The former gets read below as the First # Act of the Current Row, while the latter is stored (much further # below) as the Last Act for the Current Row. Values set in BEGIN # (further above) take care of the Special Case of the first record # [i.e., if (NR == 1)]. # FIRST ACTS: # Read the Values of the Sort-Levels for the Current Row: sla = $1; slb = $43; slc = $45; sld = $50 # de-null slc & slb if (slc == "") slc = 0; if (slb == "") slb = 0 # Save the Account Number and Market Prices Date so END can access it vacc = $29; mdat = $76 # Save some other stuff for END: wtit = $33; wami = $34; fom = $18 # IF NEW GROUP OF pov_rec = $45 = Sort Level C = VENDOR-NOTE CONTROL: if (slc != pslc) {doli = 0 # don't print Line Item dovn = 1 # OK to print previous Vendor Note if (yak == 1) blab("SLC") } # IF NEW GROUP OF poi_rec = $43 = Sort Level "B" = INTERNAL-NOTE CONTROL: if (slb != pslb) {doin = 1 dovn = 1 doli = 0 if (yak == 1) blab("SLB") } # IF NEW GROUP OF pomnum = $1 = Sort Level "A" = A NEW PO: if (sla != psla) {if (NR != 1 && pin > "") inote() # if OK, print the last Internal Note doli = 1 # print Line Item dovn = 0 # do not print Vendor Note doin = 0 # do not print Internal Note vyak = 0 # reset Vendor note counter iyak = 0 # reset Internal note counter if (yak == 1) blab("SLA") if (fxhc == "F") {eop = "ZZZ"; fxnum = 1} else {eop = " "; fxnum = 0} if (NR == 1) header() else tailer(1) # tailer(1) calls header() pct = 0 # reset virtual page counter } ################################ ## PRINT ONE LINE-ITEM BELOW: ## ################################ if (doli == 1) { if ($49 == "B" || $49 == "S") need = 6 else if ($49 == "R" || $49 == "O" || $49 == "I") need = 10 else if ($49 == "F") need = 12 else need = 1 if (lsf + need >= 75) tailer(1) if (yak == 1) blab("ITEM") spc(1) printf("%2s", $50); spc(4); printf("%-14s", $47); spc(1) if ($49 == "R") # efine Item {printf("REFINE & RECOVER PRECIOUS METAL ") printf("AS DESCRIBED BELOW ON OR BEFORE ") ept = $62; epd = $63; erh = $64 } else if ($49 == "F") # abricate Item {printf("FABRICATE PRECIOUS METAL PER ") printf("SPECIFICATION BELOW ON OR BEFORE ") ept = -$62; epd = -$63; erh = -$64 } else if ($49 == "O") # Xfer ut Item {printf("TRANSFER METAL OUT PER ") printf("INSTRUCTIONS BELOW ON OR BEFORE ") ept = -$62; epd = -$63; erh = -$64 } else if ($49 == "I") # Xfer n Item {printf("TRANSFER METAL IN PER ") printf("INSTRUCTIONS BELOW ON OR BEFORE ") ept = $62; epd = $63; erh = $64 } else if ($49 == "B") # uy Item {printf("BUY PRECIOUS METAL PER ") printf("INSTRUCTIONS BELOW ON OR BEFORE ") ept = $62; epd = $63; erh = $64 } else if ($49 == "S") # ell Item {printf("SELL PRECIOUS METAL PER ") printf("INSTRUCTIONS BELOW ON OR BEFORE ") ept = -$62; epd = -$63; erh = -$64 } printf("%10s\n", $72); lsf++ # NEW LINE if ($49 == "F" || $49 == "R") {spc(22); printf("%-20s", $52); spc(1)} if ($51 != "UNK") {printf("YOUR P/N: %-12s", $51); spc(1)} if ($55 == "C") printf("CIR") else if ($55 == "H") printf("HEX") if ($56 > 0) printf(" EFF AREA: %6.1f SQ IN", $56) printf("\n") # NEW LINE (maybe) if ($55 != "O") # ther Shape {spc(22); lsf++ printf("GROSS DIA: %-5.1f", $53); spc(2) printf("EFF DIA: %-5.1f BOTH IN INCHES", $54) if ($55 == "H") printf(", FLAT-TO-FLAT.") else printf(".") printf("\n"); lsf++ } # END if ($55 != "O") # NEW LINE if ($65 > " ") {spc(22); printf("%-70s", $65)} else spc(92) spc(4); printf("PT: %8.3f ", ept) if (fxhc == "I" || $78 == "B" || $78 == "S") printf("$%7.2f $%9.2f", $73, ept * $73) printf("\n"); lsf++ # NEW LINE if ($66 > " ") {spc(22); printf("%-70s", $66)} else spc(92) spc(4); printf("PD: %8.3f ", epd) if (fxhc == "I" || $78 == "B" || $78 == "S") printf("$%7.2f $%9.2f", $74, epd * $74) printf("\n"); lsf++ # NEW LINE if ($67 > " ") {spc(22); printf("%-70s", $67)} else spc(92) spc(4); printf("RH: %8.3f ", erh) if (fxhc == "I" || $78 == "B" || $78 == "S") printf("$%7.2f $%9.2f", $75, erh * $75) printf("\n"); lsf++ # NEW LINES (Min of 0 to Max of 4): if ($68 > " ") {spc(22); printf("%-70s\n", $68); lsf++} if ($69 > " ") {spc(22); printf("%-70s\n", $69); lsf++} if ($70 > " ") {spc(22); printf("%-70s\n", $70); lsf++} if ($71 > " ") {spc(22); printf("%-70s\n", $71); lsf++} # NEW LINE if ($49 == "F") {spc(7); printf("PROCESS COND.: TEMP = %4d DEG F.,", $57) spc(3); printf("PRES = %4d PSI,", $60) spc(3); printf("FLOW = %6d LBS/HOUR,", $59) col(22); printf("PROD = %4d TONS/DAY,", $58) spc(3); printf("EXPECTED SERVICE LIFE = %4d DAYS.\n", $61); lsf++ } # END if ($49 == "F") skip(1); lsf++ } # END if (doli == 1) (i.e., PRINT ONE LINE-ITEM) if (lsf >= 75) tailer(1) ## PRINT ONE VENDOR-NOTE (maybe): vnote() # PRINT ONE INTERNAL-NOTE (maybe): inote() # LAST ACTS: # Save the "previous" Vendor and Internal Notes for use in Next Record: pvn = $46; pin = $44 # Save the "previous" Sort-Levels for processing by the Next Record: psla = sla; pslb = slb; pslc = slc; psld = sld } # END main() # awk now ratchets into the Next Record (if there is one) END \ { # Put a tailer(0) on the last Record: if (slc != 0 && pvn > "") {dovn = 1; vnote()} if (fxhc == "I" && slb != 0 && pin > "") {doin = 1; inote()} # pct = 0 tailer(0) # 0 tells tailer(n) not to do a header() } # END END ############################## ## FUNCTION DEFINITION AREA ## ############################## # und(n) draws a line n underscores wide along the current line: function und(n) {for (i = 0; i < n; i++) printf("_")} # spc(n) slides n [more] spaces along the current line: function spc(n) {for (i = 0; i < n; i++) printf(" ")} # col(n) throws one new line and then slides n spaces along it: function col(n) {printf("\n"); for (i = 0; i < n; i++) printf(" ")} # skip(n) prints n new lines: function skip(n) {for (i = 0; i < n; i++) printf("\n")} # header() prints the Page Header and is always called by tailer(1) function header() { if (yak == 1) blab("HEAD") if (fxhc == "F" && fxnum = 1) { printf(" /SND;TEL=%s;W160CT/", $28) fxnum = 0 } if (fxhc == "I") { spc(50) printf("*** PRECIOUS METALS PURCHASE ORDER # %s%s%-5d%s", pfix, "-PM-", $1, " IN-HOUSE COPY ") if ($18 == "F") printf("(FAXED TO VENDOR)") else printf("(MAILED TO VENDOR)") printf(" * * *\n") } else skip(1) spc(48); printf("FROM: %s\n", cona) spc(54); printf("%s\n", plna) spc(54); printf("%s %s %s %s\n", plad, plct, plst, plzp) skip(1) spc(47); printf("PHONE: %s FAX: %s\n", pvph, pfph) skip(6) spc(21) if (fxhc != "H") printf("TO: ") else spc(4) printf("%-30s", $20) spc(5) if (fxhc == "I") printf("(#%-2d)", $3) else spc(5) spc(31) if (fxhc != "H") printf("SHIP TO: ") else spc(9) printf("%s\n", cona) spc(25); printf("%-30s", $21); spc(50); printf("%s\n", $35) spc(25); printf("%-30s", $22); spc(50); printf("%s\n", $36) spc(25); printf("%-20s %-2s %-10s", $23, $24, $25) spc(44); printf("%-20s %-2s %-10s\n", $37, $38, $39) # NEW LINE: (Should now be on Line 17) spc(19); printf("ATTN: ") if ($4 > " ") {printf("%-30s", $4); spc(2)} else {printf("%-25s", $26); spc(7)} if (fxhc == "I") {if ($18 == "F") {printf("*** IN-HOUSE COPY - VENDOR PO FAXED ***"); spc(3)} else {printf("*** IN-HOUSE COPY - VENDOR PO MAILED ***"); spc(2)} } else spc(42) printf("ATTN: %s\n", $40) skip(2) # NEW LOGICAL LINE BELOW ALL NEEDS TO APPEAR ON PHYSICAL LINE 21: if (fxhc != "H") printf(" TERMS: ") else spc(8) printf("%-13s", $13); spc(15) if (fxhc != "H") printf("VENDOR REF #: ") else spc(14) printf("%-12s", $6); spc(28) if (fxhc != "H") printf("VENDOR QUOTE #: ") else spc(12) printf("%-12s", $5); spc(14) if (fxhc != "H") printf("TAXABLE? ") else spc(9) printf("%s\n", $11) skip(2) # NEW LOGICAL LINE BELOW ALL NEEDS TO APPEAR ON PHYSICAL LINE 24: if (fxhc != "H") printf(" FOB: ") else spc(8) printf("%-16s", $14); spc(12) if (fxhc != "H") printf("SHIP VIA: ") else spc(10) printf("%-10s", $9) if ($10 == "A") printf(" ADVISE PAYMENT") else if ($10 == "C") printf(" FREIGHT COLL ") else if ($10 == "P") printf(" PREPAY & ADD ") else if ($10 == "V") printf(" VENDOR PAID ") else spc(15) if (fxhc != "H") printf("W9? ") else spc(4) printf("N"); spc(20) if (fxhc != "H") {printf("##################################\n") spc(96); printf("## PURCHASE ORDER NUMBER ##\n") } else skip(2) # NEW LOGICAL LINE BELOW ALL NEEDS TO APPEAR ON PHYSICAL LINE 26: if (fxhc != "H") printf(" DATE: ") else spc(8) printf("%10s", $16); spc(27) if (fxhc != "H") printf("REQ # ") else spc(6) printf(" %-8s", $8); spc(36) if (fxhc != "H") printf("## ") else spc(4) printf("%3s%s%-5d", pfix, "-PM-", $1) if ($12 == "Y") printf("**CONFIRMING** ") else spc(16) if (fxhc != "H") printf("##") printf("\n") # NEW LINE: if (fxhc != "H") {spc(96); printf("##################################")} skip(2) if (fxhc == "F") { spc(10); printf("PLEASE CONFIRM PRICES & DELIVERY DATES, ") printf("THEN SIGN AND RETURN AT ONCE VIA FAX TO: ") printf("%s. THANK YOU.\n", pfph) } else skip(1) skip(2) # NEW LINE: - Should be on Line 32 by now spc(118) if (fxhc != "H") printf("(for Goods and Services)\n") else {spc(8); printf("+\n")} skip(1) if (fxhc != "H") {printf("IT#"); spc(4) printf("STOCK NUMBER"); spc(34) printf("DESCRIPTION"); spc(32) if ($49 == "F" || $49 == "R") printf("EST. ") else spc(5) printf("QUANTITY"); spc(8) printf("UNIT COST"); spc(6) printf("EXTENSION\n") printf("--- -------------- ---------------------------------") printf("---------------------------------------"); spc(2) printf("------------- --------- ---------\n") } else skip(1) skip(1) lsf = 34 # represents either: (A) kinduva best-guess, or (B) The Truth } # EOF header() # tailer(n) is called by # main() whenever lsf gets too big, or whenever # a new PO# is encountered. Note: if (n == 0), no subsequent header() will # be printed, but if (n == 1), a subsequent header() will be printed. function tailer(n) { # NOTE: Since END does not "see" any data fields (e.g., $34), they cannot be # directly referenced within tailer(n). Therefore any needed data must # be previously saved into a variable for it to be accessed below. pct++ if (yak == 1) blab("TAIL") if (lsf < 76) {jump = (76 - lsf -1); skip(jump); lsf += jump} spc(1); printf("ATTN: LINE ITEMS ARE QTY. ONE EA. ") printf("METAL QUANTITIES ARE IN TROY OZ.") spc(64); printf("PAGE %2d\n", pct); lsf++ spc(7); printf("UNIT COSTS ARE AS OF MARKET CLOSE %10s", mdat) printf(". ANY NEGATIVE VALUES ABOVE\n"); lsf++; spc(7) if ($49 == "F") printf("ARE ESTIMATED FABRICATION AMOUNTS WHICH ") if ($49 == "O") printf("ARE METAL AMOUNTS TO BE TRANSFERRED WHICH ") if ($49 == "B") printf("ARE METAL AMOUNTS TO BE PURCHASED WHICH ") printf("REDUCE FARMLAND ACCOUNT # %s\n", vacc); lsf++ skip(1); lsf++ spc(57) if (fom == "F" || wami == bmoc) spc(38) else und(38) spc(4) if (fom == "F") spc(1) else und(38) printf("\n"); lsf++ spc(49) if (fom == "F" && wami != bmoc) printf("SIGNED: ") else spc(8) if (wami != bmoc) printf("%-30s", wami) else spc(30) spc(4) if (fom == "F") printf("SIGNED: ") else spc(8) printf("%-30s\n", bmoc); lsf++ spc(57) if (wami != bmoc) printf("%-30s", wtit) else spc(30) spc(12) printf("%s\n", btit); lsf++ spc(1); printf("%s\n", eop); lsf++ # will be "ZZZ" for Fax End-Xmsn # Got tired of trying to stop page-creep ...so used ^L as a TOF command: if (lsf < pgl) printf(" ") if (n == 1) header() } # EOF tailer(n) # function vnote() will, under proper conditions, print one Vendor Note. function vnote() {if (dovn == 1 && iyak == 0) {vyak++ if (vyak == 1) {spc(8); printf("VENDOR NOTES: ")} else spc(22) printf("%s\n", pvn); lsf++ dovn = 0 # don't print Vendor Note } } # EOF vnote() # function inote() will, under proper conditions, print one Internal Note. function inote() {if (doin == 1) {dovn = 0 # don't print Vendor Note doin = 0 # don't print Internal Note doli = 0 # don't print Line Item iyak++ if (fxhc == "I") {if (iyak == 1) {skip(1); lsf += 1; spc(6); printf("INTERNAL NOTES: ")} else spc(22) printf("%s\n", pin); lsf++ } } } # EOF inote() # blab(loc) prints values of loc, NR & misc switches for acts of debuggerie. function blab(loc) {printf("%4s NR=%d psla=%d sla=%d pslb=%d slb=%d ", loc, NR, psla, sla, pslb, slb) printf("pslc=%d slc=%d psld=%s sld=%s doli=%d ", pslc, slc, psld, sld, doli) printf("dovn=%d vyak=%d doin=%d iyak=%d lsf=%d pct=%d\n", dovn, vyak, doin, iyak, lsf, pct) } # EOF [at last, of] pop_all.awk