# verifydatasrc.awk # /* # ************************************************************************* # ** * # ** Copyright (C) 1992-2005 Trans-Mit Pty. Ltd. Melbourne Australia * # ** This software may not be loaned, resold, changed or copied * # ** in any way without the express written permission of author * # ** and Trans-Mit Pty. Ltd., Australia. * # ** * # ************************************************************************* # ** # ** $Header: /usr/local/lib/cake/RCS/rcshead,v 1.10 2004/01/07 02:42:19 root Exp $ # ** $Author: root $ # ** $Date: 2004/01/07 02:42:19 $ # ** $Locker: $ # ** # ************************************************************************* # */ function trim(s) { sub(/^[ \t]*/,"",s) sub(/[ \t]*$/,"",s) return s } function clip(s) { sub(/[ \t]*$/,"",s) return s } # output func to standard out (ie. IE log window) and also to outfile function outstr(s) { outs = s printf("%s",outs) if ( match(s,/.*\n$/) > 0 ) outs = sprintf("%s
\n",outs) writeoutfile(outs) } function outstrsubheading(s) { sbold = sprintf("

%s

", s) printf("%s",sbold) writeoutfile(sbold) } function outstrbold(s) { sbold = sprintf("%s", s) printf("%s",sbold) outs = sbold if ( match(s,/.*\n$/) > 0 ) outs = sprintf("%s
\n",outs) writeoutfile(outs) } # out to outfile only function writeoutfile(s) { if ( outfile != "" ) { printf("%s",s) >> outfile } } #---------------------------------------------------------- BEGIN { print "verify_mobile_phones:" print "" print " billperiod = [" billperiod "]" print " datasrcid = [" datasrcid "]" print " tagname = [" tagname "]" print " outfile = [" outfile "]" print " carrier = [" carrier "]" print " sidmainttype = [" sidmainttype "]" print " confinfofile = [" confinfofile "]" print " dsstddetailfile = [" dsstddetailfile "]" print " tagname = [" tagname "]" print " upfile_accountnumber = [" upfile_accountnumber "]" print " upfile_invoicenumber = [" upfile_invoicenumber "]" print " upfile_totalcost = [" upfile_totalcost "]" print "" #load sid config print "" printf("load sid conf file %s\n", confinfofile) print "" while ( (getline aline < confinfofile) > 0 ) { split(aline, a_arr, "|") #printf("aline=%s\n", aline) f = 0 # from getSIDMAINTconf recordno = clip(a_arr[++f]) sid = clip(a_arr[++f]) sidmainttype = clip(a_arr[++f]) sdate = clip(a_arr[++f]) edate = clip(a_arr[++f]) directoryid = clip(a_arr[++f]) grid = clip(a_arr[++f]) datatype = clip(a_arr[++f]) serviceproviderdir = clip(a_arr[++f]) carriercode = clip(a_arr[++f]) grname1 = clip(a_arr[++f]) grname3 = clip(a_arr[++f]) surname = clip(a_arr[++f]) firstname = clip(a_arr[++f]) confsid = sid gsub(" ","",confsid) gsub("-","",confsid) #print "confsid = " confsid confsid_arr[confsid] = 1 sid_arr[confsid] = 1 if ( surname == "" ) surname = "_blank_" if ( firstname == "" ) firstname = "_blank_" name = surname if ( firstname != "_blank_") name = sprintf("%s %s", firstname, name) #print "conf name=[" name "]" if ( confsid_to_name_arr[confsid] == "" ) confsid_to_name_arr[confsid] = name if ( confsid_to_name_arr[confsid] != name ) confsid_to_name_arr[confsid] = "Multiple" #print "confinfofile: confsid_to_name_arr[" confsid "] = " confsid_to_name_arr[confsid] CCP = grname1 #print "conf CCP=[" CCP "]" if ( confsid_to_CCP_arr[confsid] == "" ) confsid_to_CCP_arr[confsid] = CCP if ( confsid_to_CCP_arr[confsid] != CCP ) confsid_to_CCP_arr[confsid] = "Multiple" #print "confinfofile: confsid_to_CCP_arr[" confsid "] = " confsid_to_CCP_arr[confsid] } close(confinfofile) print "" # load data source standard detail file print "" printf("load standard detail file %s\n", dsstddetailfile) print "" while ( (getline aline < dsstddetailfile) > 0 ) { split(aline, a_arr, "|") #printf("aline=%s\n", aline) f = 0 # from data source standard detail file datasrcid = clip(a_arr[++f]) sid = clip(a_arr[++f]) carrier = clip(a_arr[++f]) rectype = clip(a_arr[++f]) recclass = clip(a_arr[++f]) billperiod = clip(a_arr[++f]) sdate_str = clip(a_arr[++f]) btxt_stime_str = clip(a_arr[++f]) btxt_origin = clip(a_arr[++f]) btxt_destination = clip(a_arr[++f]) btxt_dialled = clip(a_arr[++f]) btxt_rate = clip(a_arr[++f]) dursecs = sprintf("%d", clip(a_arr[++f]) ) costinclgst = sprintf("%0.2f", clip(a_arr[++f])) dssid = sid gsub(" ","",dssid) gsub("-","",dssid) #print "dssid = " dssid dssid_arr[dssid] = 1 sid_arr[dssid] = 1 ################################### if ( rectype == "CDR" ) { # add up call detail record dssid_to_cdr_totalcost_arr[dssid] = dssid_to_cdr_totalcost_arr[dssid] + 0.0 + costinclgst continue } ################################### # import data erros if ( rectype == "ERROR" && recclass == "CONVERROR" ) { print "CONVERROR: linetype=" btxt_origin " recno=" btxt_destination " nflds=" btxt_dialled continue } if ( rectype == "ERROR" && recclass == "CONVERRORS" ) { ds_converrors = btxt_dialled continue } ################################### # import data config if ( rectype == "CONFIG" && recclass == "COSTCENTRE" ) { CCP = btxt_origin name = btxt_destination gsub("-"," ",CCP) gsub(" +","-",CCP) #print "ds CCP=[" CCP "]" dssid_to_CCP_arr[dssid] = CCP if ( dssid_to_CCP_arr[dssid] == "" ) dssid_to_CCP_arr[dssid] = CCP if ( dssid_to_CCP_arr[dssid] != CCP ) dssid_to_CCP_arr[dssid] = "Multiple" #print "dsstddetaifile: dssid_to_CCP_arr[" dssid "] = " dssid_to_CCP_arr[dssid] continue } if ( rectype == "CONFIG" && recclass == "NAME" ) { name = btxt_destination accountnumber = btxt_origin invoicenumber = btxt_rate #print "ds name=[" name "]" if ( dssid_to_name_arr[dssid] == "" ) dssid_to_name_arr[dssid] = name if ( dssid_to_name_arr[dssid] != name ) dssid_to_name_arr[dssid] = "Multiple" #print "dsstddetailfile: dssid_to_name_arr[" dssid "] = " dssid_to_name_arr[dssid] #print "ds name accountnumber=[" accountnumber "]" if ( dssid_to_accountnumber_arr[dssid] == "" ) dssid_to_accountnumber_arr[dssid] = accountnumber if ( dssid_to_accountnumber_arr[dssid] != accountnumber ) dssid_to_accountnumber_arr[dssid] = "Multiple" #print "dsstddetailfile: dssid_to_accountnumber_arr[" dssid "] = " dssid_to_accountnumber_arr[dssid] #print "ds name invoicenumber=[" invoicenumber "]" if ( dssid_to_invoicenumber_arr[dssid] == "" ) dssid_to_invoicenumber_arr[dssid] = invoicenumber if ( dssid_to_invoicenumber_arr[dssid] != invoicenumber ) dssid_to_invoicenumber_arr[dssid] = "Multiple" #print "dsstddetailfile: dssid_to_invoicenumber_arr[" dssid "] = " dssid_to_invoicenumber_arr[dssid] continue } ################################### # summary records if (rectype == "CHARGE_DESC" && recclass == "RENT") { desc = btxt_destination from_to = btxt_dialled dssid_to_rentcost_arr[dssid] = 0.0 + costinclgst continue } if (rectype == "CHARGE_DESC" && recclass == "CALL") { # (not incl. discount) desc = btxt_destination dssid_to_callcost_arr[dssid] = 0.0 + costinclgst continue continue } if (rectype == "CHARGE_DESC" && recclass == "OTHER") { desc = btxt_destination dssid_to_othercost_arr[dssid] = 0.0 + costinclgst continue } if (rectype == "CHARGE_DESC_INFO" && recclass == "CALL_TOTAL"){ # (incl. discount) dssid_to_call_totalcount_arr[dssid] = 0 + dursecs dssid_to_call_totalcost_arr[dssid] = 0.0 + costinclgst continue } if (rectype == "CHARGE_DESC_INFO" && recclass == "CALL_DISCOUNT" ) { dssid_to_call_discount_arr[dssid] = 0.0 + costinclgst continue } if (rectype == "CHARGE_DESC_INFO" && recclass == "ADJUSTMENT"){ dssid_to_adjustmentcost_arr[dssid] = 0.0 + costinclgst continue } if (rectype == "CHARGE_DESC_INFO" && recclass == "RECURRING") { dssid_to_recurringcost_arr[dssid] = 0.0 + costinclgst continue } if (rectype == "CHARGE_DESC_INFO" && recclass == "RECURRING_DISCOUNT") { dssid_to_recurringdiscountcost_arr[dssid] = 0.0 + costinclgst continue } if (rectype == "CHARGE_DESC_INFO" && recclass == "EQUIPMENT") { dssid_to_equipmentcost_arr[dssid] = 0.0 + costinclgst continue } if (rectype == "CHARGE_DESC_INFO" && recclass == "TOTAL") { ds_total_accountnumber = btxt_origin ds_total_desc = btxt_destination ds_total_from_to = btxt_dialled ds_total_invoicenumber = btxt_rate ds_total_totalcost = 0.0 + costinclgst continue } } close(dsstddetailfile) print "" recurring_charge = "11.82" } #-------------------------------------------------------- # main: load sorted sid list { #print "$0=[" $0 "]" sid = $1 sid_arr[++nsids] = sid } #-------------------------------------------------------- # verify END { got_error = 0 # force to a number ds_total_totalcost += 0.0 atitle = sprintf("Data Import Verification Report for: %s (%s)\n", tagname, carrier) # out to outfile only writeoutfile("\n") writeoutfile("\n") writeoutfile("\n") writeoutfile(atitle) writeoutfile("\n") writeoutfile("\n") writeoutfile("\n") # output to standard out (ie. IE log window) and also to outfile outstr("\n") outstrbold(atitle) outstr("\n") outstr("\n") "date" | getline dateline outp = sprintf("Run on: %s\n", dateline) outstrbold(outp) outstr("\n") outp = sprintf("Account Number: %s Invoice Number: %s Total Cost: $%-0.2f\n", ds_total_accountnumber, ds_total_invoicenumber, ds_total_totalcost) outstrbold(outp) outp = sprintf("From %s\n", ds_total_from_to) outstrbold(outp) outstr("\n") #-------------------------------------- outstr("\n") outstr("\n") outstr("\n") outp = "Import Conversion Errors\n" outstrsubheading(outp) ds_has_conv_error = 0 if ( ds_converrors ) { got_error = 1 ds_has_conv_error = 1 outstr(ds_converrors) } else { outstr("None.") } outstr("\n") #-------------------------------------- outstr("\n") outstr("\n") outstr("\n") outp = "Critical Configuration Errors\n" outstrsubheading(outp) critical_error_count = 0 ds_has_critical_error = 0 ############################################## # critcal error: account number mismatch accountnumber_mismatch = 0 if ( upfile_accountnumber != ds_total_accountnumber ) { outstr("\n") outp = "Account Number Mismatch\n" outstrbold(outp) outp = sprintf(" Entry: %s Data: %s\n", upfile_accountnumber, ds_total_accountnumber) outstr(outp) got_error = 1 ++critical_error_count ds_has_critical_error = 1 accountnumber_mismatch = 1 outstr("\n") } ############################################## # critcal error: invoice number mismatch invoicenumber_mismatch = 0 if ( upfile_invoicenumber != ds_total_invoicenumber ) { outstr("\n") outp = "Invoice Number Mismatch\n" outstrbold(outp) outp = sprintf(" Entry: %s Data: %s\n", upfile_invoicenumber, ds_total_invoicenumber) outstr(outp) got_error = 1 ++critical_error_count ds_has_critical_error = 1 invoicenumber_mismatch = 1 outstr("\n") } ############################################## # critcal error: total cost mismatch totalcost_mismatch = 0 if ( upfile_totalcost != ds_total_totalcost ) { outstr("\n") outp = "Total Cost Mismatch\n" outstrbold(outp) outp = sprintf(" Entry: %s Data: %s\n", upfile_totalcost, ds_total_totalcost) outstr(outp) got_error = 1 ++critical_error_count ds_has_critical_error = 1 totalcost_mismatch = 1 outstr("\n") } ############################################## # critcal error: mobile not in bilmax21 config not_in_config_count = 0 for ( i = 1; i <= nsids; ++i ) { sid = sid_arr[i] # force flag to a number confsid_arr[sid] += 0 if ( confsid_arr[sid] == 0 ) { if ( not_in_config_count == 0 ) { # header outstr("\n") outp = "Not in Bilmax21 Mobile Phone Maintenance Configuration.\n" outstrbold(outp) outp = sprintf("MaintType: %s Carrier: %s\n", sidmainttype, carrier) outstr(outp) outstr("
\n")
			}
			outp = sprintf("%-20.20s", sid)
			outstr(outp)
			if ( !(++not_in_config_count % 4) )
				outstr("\n")
			got_error = 1
			++critical_error_count
			ds_has_critical_error = 1
		}
	}	
	if ( critical_error_count > 0 ) {
		outstr("
") } else { outstr("None.\n") } outstr("\n") #-------------------------------------- outstr("\n") outstr("\n") outstr("\n") outp = "Non-Critical Configuration Errors\n" outstrsubheading(outp) noncritical_error_count = 0 ds_has_noncritical_error = 1 for ( i = 1; i <= nsids; ++i ) { sid = sid_arr[i] # force flag to a number dssid_arr[sid] += 0 sid_has_noncritical_error[sid] = 0 not_in_data = 0 CCP_blank_in_data = 0 name_conflict = 0 CCP_conflict = 0 if ( dssid_arr[sid] == 0 ) { got_error = 1 ds_has_noncritical_error = 1 sid_has_noncritical_error[sid] = 1 not_in_data = 1 } if ( dssid_to_name_arr[sid] == "" ) { got_error = 1 ds_has_noncritical_error = 1 sid_has_noncritical_error[sid] = 1 name_blank_in_data = 1 } if ( dssid_to_CCP_arr[sid] == "" ) { got_error = 1 ds_has_noncritical_error = 1 sid_has_noncritical_error[sid] = 1 CCP_blank_in_data = 1 } if ( confsid_to_name_arr[sid] != dssid_to_name_arr[sid] ) { got_error = 1 ds_has_noncritical_error = 1 sid_has_noncritical_error[sid] = 1 name_conflict = 1 } if ( confsid_to_CCP_arr[sid] != dssid_to_CCP_arr[sid] ) { got_error = 1 ds_has_noncritical_error = 1 sid_has_noncritical_error[sid] = 1 CCP_conflict = 1 } if ( sid_has_noncritical_error[sid] ) { if ( (noncritical_error_count % 24) == 0 ) { # header outstr("\n") #fmtstr = "%-10.10s %-17.17s %-17.17s %-17.17s %-17.17s %-17.17s\n" fmtstr = "%s,%s,%s,%s,%s,%s\n" # stdout only printf(fmtstr, "Mobile", "NotInData", "NameBlankInData", "CCPBlankInData", "NameConflict", "CCPConflict") writeoutfile("\n") outp = sprintf("\n", "Mobile", "NotInData", "NameBlankInData", "CCPBlankInData", "NameConflict", "CCPConflict") writeoutfile(outp) } truestr = "X" rest_truestr = not_in_data ? "N/A" : "X" falsestr = "_" # stdout only printf(fmtstr, sid, not_in_data ? truestr : falsestr, name_blank_in_data ? rest_truestr : falsestr, CCP_blank_in_data ? rest_truestr : falsestr, name_conflict ? rest_truestr : falsestr, CCP_conflict ? rest_truestr : falsestr) falsestr = "" outp = sprintf("\n", sid, not_in_data ? truestr : falsestr, name_blank_in_data ? rest_truestr : falsestr, CCP_blank_in_data ? rest_truestr : falsestr, name_conflict ? rest_truestr : falsestr, CCP_conflict ? rest_truestr : falsestr) writeoutfile(outp) ++noncritical_error_count } } if ( noncritical_error_count > 0 ) { writeoutfile("
%s%s%s%s%s%s
%s%s%s%s%s%s
\n") outstr("\n") } else { outstr("None.\n") outstr("\n") } #-------------------------------------- outstr("\n") outstr("\n") outstr("\n") outp = "Cost Exceptions\n" outstrsubheading(outp) cost_exception_count = 0 ds_has_cost_exception = 0 for ( i = 1; i <= nsids; ++i ) { sid = sid_arr[i] # force flag to a number dssid_arr[sid] += 0 sid_has_cost_exception[sid] = 0 # force costs to numbers dssid_to_rentcost_arr[dssid] += 0.0 dssid_to_callcost_arr[dssid] += 0.0 dssid_to_othercost_arr[sid] += 0.0 dssid_to_call_discount_arr[sid] += 0.0 dssid_to_adjustmentcost_arr[sid] += 0.0 dssid_to_recurringcost_arr[sid] += 0.0 dssid_to_equipmentcost_arr[sid] += 0.0 dssid_to_cdr_totalcost_arr[sid] += 0.0 dssid_to_call_totalcount_arr[sid] += 0 dssid_to_call_totalcost_arr[sid] += 0.0 if ( dssid_arr[sid] == 0 ) # skip if not in data continue recurringcost_not_x = 0 callcost_is_0 = 0 cdr_totalcost_mismatch = 0 othercost_not_0 = 0 adjustmentcost_is_0 = 0 equipmentcost_not_0 = 0 if ( dssid_to_recurringcost_arr[sid] != recurring_charge ) { got_error = 1 ds_has_cost_exception = 1 sid_has_cost_exception[sid] = 1 recurringcost_not_x = 1 } if ( dssid_to_callcost_arr[sid] == 0 ) { got_error = 1 ds_has_cost_exception = 1 sid_has_cost_exception[sid] = 1 callcost_is_0 = 1 } #a = dssid_to_cdr_totalcost_arr[sid] #b = dssid_to_call_totalcost_arr[sid] a = sprintf("%0.2f", dssid_to_cdr_totalcost_arr[sid]) b = sprintf("%0.2f", dssid_to_call_totalcost_arr[sid]) if ( a != b ) { #print "DEBUG: a = [" a "]" #print " b = [" b "]" got_error = 1 ds_has_cost_exception = 1 sid_has_cost_exception[sid] = 1 cdr_totalcost_mismatch = 1 } if ( dssid_to_othercost_arr[sid] != 0 ) { got_error = 1 ds_has_cost_exception = 1 sid_has_cost_exception[sid] = 1 othercost_not_0 = 1 } if ( dssid_to_adjustmentcost_arr[sid] == 0 ) { got_error = 1 ds_has_cost_exception = 1 sid_has_cost_exception[sid] = 1 adjustmentcost_is_0 = 1 } if ( dssid_to_equipmentcost_arr[sid] != 0 ) { got_error = 1 ds_has_cost_exception = 1 sid_has_cost_exception[sid] = 1 equipmentcost_not_0 = 1 } if ( sid_has_cost_exception[sid] ) { if ( (cost_exception_count % 24) == 0 ) { # header outstr("\n") recurring_not_x_desc = sprintf("Recurring$ not $%-0.2f", recurring_charge) #fmtstr = "%-10.10s %-21.21s %-21.21s %-21.21s %-21.21s %-21.21s %-21.21s\n" fmtstr = "%s,%s,%s,%s,%s,%s,%s\n" # stdout only printf(fmtstr, "Mobile", "Equipment$ not $0", "Call$ is $0", "Detail$ Mismatch", recurring_not_x_desc, "Other$ not $0", "Adjustment$ is $0") writeoutfile("\n") outp = sprintf("\n", "Mobile", "Equipment$ not $0", "Call$ is $0", "Detail$ Mismatch", recurring_not_x_desc, "Other$ not $0", "Adjustment$ is $0") writeoutfile(outp) } truestr = "X" falsestr = "_" # stdout only printf(fmtstr, sid, equipment_not_0 ? truestr : falsestr, callcost_is_0 ? truestr : falsestr, cdr_totalcost_mismatch ? truestr : falsestr, recurringcost_not_x ? truestr : falsestr, othercost_not_0 ? truestr : falsestr, adjustmentcost_is_0 ? truestr : falsestr) falsestr = "" outp = sprintf("\n", sid, equipment_not_0 ? truestr : falsestr, callcost_is_0 ? truestr : falsestr, cdr_totalcost_mismatch ? truestr : falsestr, recurringcost_not_x ? truestr : falsestr, othercost_not_0 ? truestr : falsestr, adjustmentcost_is_0 ? truestr : falsestr) writeoutfile(outp) ++cost_exception_count } } if ( cost_exception_count > 0 ) { writeoutfile("
%s%s%s%s%s%s%s
%s%s%s%s%s%s%s
\n") outstr("\n") } else { outstr("None.\n") outstr("\n") } #-------------------------------------- # debug print "" print "++++++++++++++++++++++++++++++++++" print "" print "Debug" print "" print "" print "ds_total_accountnumber = " ds_total_accountnumber print "ds_total_desc = " ds_total_desc print "ds_total_from_to = " ds_total_from_to print "ds_total_invoicenumber = " ds_total_invoicenumber print "ds_total_totalcost = " ds_total_totalcost print "" for ( i = 1; i <= nsids; ++i ) { sid = sid_arr[i] print "confsid_arr[" sid "] = " confsid_arr[sid] print "dssid_arr[" sid "] = " dssid_arr[sid] print "confsid_to_name_arr[" sid "] = " confsid_to_name_arr[sid] print " dssid_to_name_arr[" sid "] = " dssid_to_name_arr[sid] print "confsid_to_CCP_arr[" sid "] = " confsid_to_CCP_arr[sid] print " dssid_to_CCP_arr[" sid "] = " dssid_to_CCP_arr[sid] print "dssid_to_accountnumber_arr[" sid "] = " dssid_to_accountnumber_arr[sid] print "dssid_to_invoicenumber_arr[" sid "] = " dssid_to_invoicenumber_arr[sid] print "dssid_to_rentcost_arr[" sid "] = " dssid_to_rentcost_arr[sid] print "dssid_to_callcost_arr[" sid "] = " dssid_to_callcost_arr[sid] print "dssid_to_othercost_arr[" sid "] = " dssid_to_othercost_arr[sid] print "dssid_to_adjustmentcost_arr[" sid "] = " dssid_to_adjustmentcost_arr[sid] print "dssid_to_recurringcost_arr[" sid "] = " dssid_to_recurringcost_arr[sid] print "dssid_to_recurringdiscountcost_arr[" sid "] = " dssid_to_recurringdiscountcost_arr[sid] print "dssid_to_equipmentcost_arr[" sid "] = " dssid_to_equipmentcost_arr[sid] print "dssid_to_cdr_totalcost_arr[" sid "] = " dssid_to_cdr_totalcost_arr[sid] print "dssid_to_call_totalcount_arr[" sid "] = " dssid_to_call_totalcount_arr[sid] print "dssid_to_call_totalcost_arr[" sid "] = " dssid_to_call_totalcost_arr[sid] print "" } print "++++++++++++++++++++++++++++++++++" print "" #-------------------------------------- if ( !got_error ) { outstr("\n") outstr("------------------------------------------------\n") outstr("NO Verification Errors.\n") outstr("\n") } #-------------------------------------- writeoutfile("\n") writeoutfile("\n") #-------------------------------------- exit(got_error) }