: !/bin/sh # IYYYYMMDD env var must me set to which month # APERIOD env var must me set to which month # $1 will override IYYYYMMDD env var # $2 will override IOFFSETDAYS env var # $3 will override APERIOD env var # $4 will override SHIPTO env var # $5 will override BATCHID env var # $6 will override INVOICENO env var # $7 will override default outdir # $8 will override default splitby ############################# ## Testing SDATE="01/01/2011" EDATE="31/01/2011" IYYYYMMDD="20110131" IOFFSETDAYS="9" APERIOD="2011/01" ##SHIPTO="" ###BATCHID="33671" ####BATCHID="33792" ##INVOICENO="INV003314" ##splitby="0" # invoiceno/batchtype ###outdir="." #outdir="tdetail" ############################# if [ -n "$1" ]; then IYYYYMMDD="$1" export IYYYYMMDD fi if [ -z "$IYYYYMMDD" ]; then echo "$0: Must set invoiced date IYYYYMMDD env var OR $0 yyyymmdd" exit 1 fi echo "IYYYYMMDD = [$IYYYYMMDD]" IYYYYMM=`echo "$IYYYYMMDD" | cut -c1-6` if [ -n "$2" ]; then IOFFSETDAYS="$2" export IOFFSETDAYS fi if [ -z "$IOFFSETDAYS" ]; then echo "$0: Must set invoiced date offset days IOFFSETDAYS env var OR $0 ndays" exit 1 fi if [ -n "$3" ]; then APERIOD="$3" export APERIOD fi if [ -z "$APERIOD" ]; then echo "$0: Must set bill Period date APERIOD env var OR $0 yyyy/mm" exit 1 fi YYYY=`awk -v"IYYYYMM=$IYYYYMM" 'BEGIN { print substr(IYYYYMM,1,4); exit 0}'` MM=`awk -v"IYYYYMM=$IYYYYMM" 'BEGIN { print substr(IYYYYMM,5,2); exit 0}'` MMYYYY="${MM}${YYYY}" echo "MMYYYY = [$MMYYYY]" billperiod=`MMYYYYtobillperiod $MMYYYY _` echo "billperiod = [$billperiod]" tbsbillingperiod="$APERIOD" echo "tbsbillingperiod=[$tbsbillingperiod]" AYYYYMM=`echo "$tbsbillingperiod" | sed 's/\///'` echo "AYYYYMM=[$AYYYYMM]" #transactiontable="tFinalisedTransaction" transactiontable="tFinalisedTransaction${AYYYYMM}" echo "transactiontable=[$transactiontable]" CURMMYYYY=`awk -v"EYYYYMMDD=$IYYYYMMDD" 'BEGIN { print substr(EYYYYMMDD,5,2) substr(EYYYYMMDD,1,4) }'` echo "CURMMYYYY=[$CURMMYYYY]" curtbsbillingperiod=`MMYYYYtotbsbillperiod $CURMMYYYY /` echo "curtbsbillingperiod=[$curtbsbillingperiod]" if [ -n "$4" ]; then SHIPTO="$4" else if [ -z "$SHIPTO" ]; then SHIPTO="all" fi fi if [ "$SHIPTO" != "all" -a "$SHIPTO" != "" ]; then SHIPTOBIT=" and tCustomer.ShipTo = '$SHIPTO'" else SHIPTOBIT="" fi if [ -n "$5" ]; then BATCHID="$5" else if [ -z "$BATCHID" ]; then BATCHID="all" fi fi if [ "$BATCHID" != "all" -a "$BATCHID" != "" ]; then BATCHIDBIT=" and ${transactiontable}.BatchID = $BATCHID" else BATCHIDBIT="" fi if [ -n "$6" ]; then INVOICENO="$6" else if [ -z "$INVOICENO" ]; then INVOICENO="all" fi fi if [ "$INVOICENO" != "all" -a "$INVOICENO" != "" ]; then INVOICENOBIT=" and tInvoice.PlatinumInvoiceNo = '$INVOICENO'" else INVOICENOBIT="" fi if [ -n "$7" ]; then outdir="$7" else if [ -z "$outdir" ]; then #outdir="tdetail_${APERIOD}_${BATCHID}" #outdir="tdetail_${IYYYYMMDD}_${BATCHID}" outdir="tdetail_${IYYYYMM}_${BATCHID}" fi fi if [ -n "$8" ]; then splitby="$8" else if [ -z "$splitby" ]; then # split tbs detail data into files by... #splitby="" # all splitby="0" # shipto/batchid #splitby="1" # batchid/serviceid #splitby="2 # invoiceno/batchid fi fi ##outfilepref="$0_${AYYYYMM}_${BATCHID}.unl" #outfilepref="$0_${AYYYYMM}" outfilepref="tdetail" echo "$0: for $IYYYYMMDD, $IOFFSETDAYS, $APERIOD, batchid [$BATCHID], invoiceno [$INVOICENO] to outdir [$outdir] outfilepref prefix [$outfilepref] splitby [$splitby]" . tbsserver_vars #if [ "$outdir" != "." ]; then # rm -r "${outdir}" # mkdir -p "${outdir}" #fi if [ ! -d "${outdir}" ]; then mkdir -p "${outdir}" fi #-------------------------------------------------------------- # Bilmax21 standard internal mobile call data format # first is sundry then folowed by.. # printf("%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%d|%0.2f|\n", servicenumber, carrier, callclass, billperiod, sdate_str, btxt_stime_str, btxt_origin, btxt_destination, btxt_dialled, btxt_rate, dursecs, costinclgst) #then "%0.2f|", recost # RENT / OTHER / (also has CALL summary) #sdate_str = "CHARGE_DESC" #btxt_origin = "RENT" ( #cat </dev/null < 'VRT' AND tBatchType.Active = 1 --# AND tSupplierServiceCode.Active <> 0 --# and tElement.ID = tServiceType.RevenueElementID --# and tTransactionType.ID = tSupplierServiceCode.TransactionTypeID --# and tSupplier.ID = SupplierServiceCode.SupplierID AND tInvoice.InvoiceDate > dateadd(dd,$IOFFSETDAYS,'$IYYYYMMDD') AND tInvoice.InvoiceDate <= dateadd(mm,1,dateadd(dd,$IOFFSETDAYS,'$IYYYYMMDD')) --# exclude Victrack Rent and Calls AND tBatchType.ID <> 199 $EXCLUDEINVBIT $EXCLUDEBATCHIDBIT $EXCLUDEINVBIT $EXCLUDEBATCHIDBIT --# and tBatch.ID = 33671 --# and tServiceID.ServiceID = '0409-428164' ORDER BY tCustomer.ShipTo, tInvoice.PlatinumInvoiceNo, tBatch.ID, tServiceID.ServiceID, ${transactiontable}.Var01, tReportGroup.ID \go -m bcp SQLCMD0 #--------------------------- if [ "$tbsbillingperiod" = "$curtbsbillingperiod" ]; then #cat </dev/null < 0 --# and tElement.ID = tServiceType.RevenueElementID --# and tTransactionType.ID = tSupplierServiceCode.TransactionTypeID --# and tSupplier.ID = SupplierServiceCode.SupplierID --#--# AND tInvoice.InvoiceDate > dateadd(dd,$IOFFSETDAYS,'$IYYYYMMDD') --#--# AND tInvoice.InvoiceDate <= dateadd(mm,1,dateadd(dd,$IOFFSETDAYS,'$IYYYYMMDD')) --# exclude Victrack Rent and Calls AND tBatchType.ID <> 199 $EXCLUDEINVBIT $EXCLUDEBATCHIDBIT $EXCLUDEINVBIT $EXCLUDEBATCHIDBIT --# and tBatch.ID = 33671 --# and tServiceID.ServiceID = '0409-428164' ORDER BY tCustomer.ShipTo, PlatinumInvoiceNo, tBatch.ID, tServiceID.ServiceID, ${transactiontable}.Var01, tReportGroup.ID \go -m bcp SQLCMD1 fi ) >gdet7.out exit 0 ) | tr "," ";" | awk -F'|' \ -v"pid=$$" \ -v"IYYYYMMDD=$IYYYYMMDD" \ -v"billperiod=$billperiod" \ -v"aperiod=$APERIOD" \ -v"splitby=$splitby" \ -v"outfilepref=$outfilepref" \ -v"outdir=$outdir" ' BEGIN { f = 0 fldname_arr[++f] = "tBatch_ID" fldname_arr[++f] = "tBatch_BillingPeriod" fldname_arr[++f] = "tBatchType_ID" fldname_arr[++f] = "tBatchType_SupplierID" fldname_arr[++f] = "tBatchType_Description" fldname_arr[++f] = "tSupplier_SupplierName" fldname_arr[++f] = "tServiceID_ServiceID" fldname_arr[++f] = "tServiceID_Service" fldname_arr[++f] = "tServiceType_Code" fldname_arr[++f] = "tServiceType_Description" fldname_arr[++f] = "tInvoice_InvoiceDate" fldname_arr[++f] = "tTransactionTableYYYYMM_TxnDate" fldname_arr[++f] = "tReportGroupID" fldname_arr[++f] = "tReportGroup_GroupDesc" fldname_arr[++f] = "tInvoice_PlatinumFileName" fldname_arr[++f] = "tInvoice_PlatinumInvoiceNo" fldname_arr[++f] = "tCustomer_ShipTo" fldname_arr[++f] = "tCustomer_FullName" fldname_arr[++f] = "tCentre_Description" fldname_arr[++f] = "tActivity_Description" fldname_arr[++f] = "tElement_ElementCode" fldname_arr[++f] = "tElement_Description" fldname_arr[++f] = "tElement_1_ElementCode" fldname_arr[++f] = "tElement_1_Description" fldname_arr[++f] = "tElement_2_ElementCode" fldname_arr[++f] = "tElement_2_Description" fldname_arr[++f] = "tSubledger_Description" fldname_arr[++f] = "tDepartment_Description" fldname_arr[++f] = "tLocation_Description" fldname_arr[++f] = "tPerson_Person" fldname_arr[++f] = "tApplication_ID" fldname_arr[++f] = "tApplication_Description" fldname_arr[++f] = "tOrigin_Description" fldname_arr[++f] = "tDestination_Description" fldname_arr[++f] = "tRateDescription_Description" fldname_arr[++f] = "tRate_Cost" fldname_arr[++f] = "tTransactionType_Description" fldname_arr[++f] = "tTransactionGroup_Description" fldname_arr[++f] = "tDialledNumber_Description" fldname_arr[++f] = "tTransactionTableYYYYMM_Duration" fldname_arr[++f] = "tTransactionTableYYYYMM_AmountExGST" fldname_arr[++f] = "tBatchType_Var01Description" fldname_arr[++f] = "tTransactionTableYYYYMM_Var01" fldname_arr[++f] = "tBatchType_Var02Description" fldname_arr[++f] = "tTransactionTableYYYYMM_Var02" fldname_arr[++f] = "tBatchType_Var03Description" fldname_arr[++f] = "tTransactionTableYYYYMM_Var03" fldname_arr[++f] = "tBatchType_Var04Description" fldname_arr[++f] = "tTransactionTableYYYYMM_Var04" fldname_arr[++f] = "tBatchType_Var05Description" fldname_arr[++f] = "tTransactionTableYYYYMM_Var05" fldname_arr[++f] = "tBatchType_Var06Description" fldname_arr[++f] = "tTransactionTableYYYYMM_Var06" fldname_arr[++f] = "tBatchType_Var07Description" fldname_arr[++f] = "tTransactionTableYYYYMM_Var07" fldname_arr[++f] = "tBatchType_Var08Description" fldname_arr[++f] = "tTransactionTableYYYYMM_Var08" fldname_arr[++f] = "tBatchType_Var09Description" fldname_arr[++f] = "tTransactionTableYYYYMM_Var09" fldname_arr[++f] = "tBatchType_Var10Description" fldname_arr[++f] = "tTransactionTableYYYYMM_Var10" fldname_arr[++f] = "tBatchType_Var11Description" fldname_arr[++f] = "tTransactionTableYYYYMM_Var11" fldname_arr[++f] = "tBatchType_Var12Description" fldname_arr[++f] = "tTransactionTableYYYYMM_Var12" fldname_arr[++f] = "tBatchType_Var13Description" fldname_arr[++f] = "tTransactionTableYYYYMM_Var13" fldname_arr[++f] = "tBatchType_Var14Description" fldname_arr[++f] = "tTransactionTableYYYYMM_Var14" fldname_arr[++f] = "tBatchType_Var15Description" fldname_arr[++f] = "tTransactionTableYYYYMM_Var15" #print "fldname_arr[38]=[" fldname_arr[38] "]" mmmstr["Jan"] = 1 mmmstr["Feb"] = 2 mmmstr["Mar"] = 3 mmmstr["Apr"] = 4 mmmstr["May"] = 5 mmmstr["Jun"] = 6 mmmstr["Jul"] = 7 mmmstr["Aug"] = 8 mmmstr["Sep"] = 9 mmmstr["Oct"] = 10 mmmstr["Nov"] = 11 mmmstr["Dec"] = 12 # IYYYYMMDD IYYYY = substr(IYYYYMMDD,1,4) IMM = substr(IYYYYMMDD,5,2) IDD = substr(IYYYYMMDD,7,2) EDATE = sprintf("%02d/%02d/%04d", IDD, IMM, IYYYY) #APERIOD="2010/04" billyyyy = substr(aperiod,1,4) billmm = substr(aperiod,6,2) #m11file = outdir "/" "wb4_m11_" billmm billyyyy ".in" #system("rm -f \"" m11file "\"") doKBUSAGEsummary = 0 } { #print $0 # store vals for ( i = 1; i <= (NF-1); ++i ) { fldname = fldname_arr[i] fldvalue = $i fldvalue_arr[fldname] = fldvalue } batchid = fldvalue_arr["tBatch_ID"] batchtypeid = fldvalue_arr["tBatchType_ID"] suppliername = fldvalue_arr["tSupplier_SupplierName"] serviceid = fldvalue_arr["tServiceID_ServiceID"] reportgroupid = fldvalue_arr["tReportGroupID"] invoiceno = fldvalue_arr["tInvoice_PlatinumInvoiceNo"] shipto = fldvalue_arr["tCustomer_ShipTo"] var01 = fldvalue_arr["tTransactionTableYYYYMM_Var01"] split(suppliername, suppliername_arr, " ") carrier = toupper(suppliername_arr[1]) if ( splitby == "" ) splitby = "0" domobdet = "0" dodet = "0" dosplitby = splitby # to determine if its a mobile sid # match SID with 04..-...... if (match(serviceid, "04[0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9]")) { if ( batchtypeid != 141 && # not Victrack Call Diversion reportgroupid != 15 && # not Smartbus GPRS reportgroupid != 19 ) { # not Smartbus Aggregate dosplitby = "-1" domobdet = "1" } } if ( domobdet == "0" ) { # to detimine if we should have other # than mobile call detail data # test for Victrack call diversion (batchtypeid 141) # or supliers TELSTRA, OPTSU, VODAFONE if ( batchtypeid == 141 || carrier == "TELSTRA" || carrier == "OPTUS" || carrier == "VODAFONE" ) { dosplitby = "-1" dodet = "1" } } if ( reportgroupid == 15 || # Smartbus GPRS reportgroupid == 19 ) { # Smartbus Aggregate dosplitby = "-1" dodet = "1" doKBUSAGEsummary = 1 # reportgroupx fields... #"ServiceID", "tServiceID_ServiceID" }, #"Location", "tLocation_Description" }, #"Application", "tApplication_Description" }, #"Access Charge", "tRate_Cost" }, #"TransactionGroup", "tTransactionGroup_Description" }, #"Usage (kB)", "tTransactionTableYYYYMM_Var01" }, #"Total", "tTransactionTableYYYYMM_AmountExGST" } # must sum Var01 kb and amountexgst #print "getdetail6: still need to sum Smartbus Aggregate" # ... atag = "" #print "---------------------" for ( i = 1; i <= (NF-1); ++i ) { fldname = fldname_arr[i] #print fldname " value=[" fldvalue_arr[fldname] "]" #if ( i <= 40 ) { if ( fldname == "tBatch_ID" || #fldname == "tBatch_BillingPeriod" || fldname == "tBatchType_ID" || fldname == "tBatchType_SupplierID" || fldname == "tBatchType_Description" || fldname == "tSupplier_SupplierName" || fldname == "tServiceID_ServiceID" || fldname == "tServiceID_Service" || fldname == "tServiceType_Code" || fldname == "tServiceType_Description" || #fldname == "tInvoice_InvoiceDate" || #fldname == "tTransactionTableYYYYMM_TxnDate" || fldname == "tReportGroupID" || fldname == "tReportGroup_GroupDesc" || fldname == "tInvoice_PlatinumFileName" || fldname == "tInvoice_PlatinumInvoiceNo" || fldname == "tCustomer_ShipTo" || fldname == "tCustomer_FullName" || fldname == "tCentre_Description" || fldname == "tActivity_Description" || fldname == "tElement_ElementCode" || fldname == "tElement_Description" || fldname == "tElement_1_ElementCode" || fldname == "tElement_1_Description" || fldname == "tElement_2_ElementCode" || fldname == "tElement_2_Description" || fldname == "tSubledger_Description" || fldname == "tDepartment_Description" || fldname == "tLocation_Description" || fldname == "tPerson_Person" || fldname == "tApplication_ID" || fldname == "tApplication_Description" || #fldname == "tOrigin_Description" || #fldname == "tDestination_Description" || #fldname == "tRateDescription_Description" || #fldname == "tRate_Cost" || #fldname == "tTransactionType_Description" || #fldname == "tTransactionGroup_Description" || #fldname == "tDialledNumber_Description" || #fldname == "tTransactionTableYYYYMM_Duration" || 1 == 0 ) { fldvalue = fldvalue_arr[fldname] } else { fldvalue = "" } atag = atag fldvalue "|" } TxnGrp = fldvalue_arr["tTransactionGroup_Description"] if ( TxnGrp == "RENT" ) { UsagekB = 0 + fldvalue_arr["tTransactionTableYYYYMM_Var01"] AmountExGST = 0 + fldvalue_arr["tTransactionTableYYYYMM_AmountExGST"] KBUSAGE_UsagekB_total_arr[atag] += UsagekB KBUSAGE_RENT_AmountExGST_total_arr[atag] += AmountExGST } else { UsagekB = 0 + fldvalue_arr["tTransactionTableYYYYMM_Var01"] AmountExGST = 0 + fldvalue_arr["tTransactionTableYYYYMM_AmountExGST"] KBUSAGE_UsagekB_total_arr[atag] += UsagekB KBUSAGE_EXCESS_AmountExGST_total_arr[atag] += AmountExGST # append usage to dialledno field for detail report dialno = fldvalue_arr["tDialledNumber_Description"] if ( dialno != "" ) dialno = dialno " " dialno = dialno fldvalue_arr["tTransactionTableYYYYMM_Var01"] " kB" desc fldvalue_arr["tDialledNumber_Description"] = dialno } #print "row: atag=[" atag "]" " TxnGrp=[" TxnGrp "]" " UsagekB=[" UsagekB "]" " AmountExGST=[" AmountExGST "]" } #print "serviceid=[" serviceid "] dosplitby=" dosplitby if ( dosplitby == "0" ) { # shipto/invoiceno/batchid/reportgroupid #ofile = outdir "/" outfilepref "_" shipto "_" batchid ".unl" ofile = outdir "/" outfilepref "_" shipto "_" invoiceno "_" batchid "_" reportgroupid ".unl" } if ( dosplitby == "1" ) { # batchid/serviceid # cant have "/" in SID (re: filenames) gsub("/",".",serviceid) #ofile = outdir "/" outfilepref "_" batchid "_" serviceid "_" var01 ".unl" #ofile= outdir "/" outfilepref "_" batchid "_" serviceid ".unl" ofile = outdir "/" outfilepref "_" shipto "_" invoiceno "_" batchid "_" serviceid "_" reportgroupid ".unl" } if ( dosplitby == "2" ) { # invoiceno/batchid ofile = outdir "/" outfilepref "_" invoiceno "_" batchid ".unl" } if ( reportgroupid == 5 ) { print "RG5: dosplitby=[" dosplitby "]" " ofile=[" ofile "]" " dodet=[" dodet "]" " domobdet=[" domobdet "]" print "rg5: " $0 } if ( dosplitby >= 0 ) { handle_ofile() } if ( dodet == "1" || domobdet == "1" ) { # create m11 mobile detail format spit_m11() } } function handle_ofile() { if ( ofile != last_ofile ) { if ( last_ofile != "" ) close last_ofile last_ofile = ofile if ( done_header[ofile] == "" ) { system("rm -f \"" ofile "\"") done_header[ofile] = "1" f = 0 for ( i = 1; i <= (NF-1); ++i ) { fldname = fldname_arr[i] if ( i > 1 ) printf(",") >> ofile printf("%02d_%s", i, fldname) >> ofile } printf("\n") >> ofile } } for ( i = 1; i <= (NF-1); ++i ) { fldname = fldname_arr[i] fldvalue = fldvalue_arr[fldname] if ( i > 1 ) printf(",") >> ofile printf("%02d: %s", i, fldvalue) >> ofile } printf("\n") >> ofile } function trim(s) { sub(/^[ \t]*/,"",s) sub(/[ \t]*$/,"",s) return s } function clip(s) { sub(/[ \t]*$/,"",s) return s } function fixforfname(s) { gsub(/\//,"+",s) return s } function MMM_to_MM(MMM) { return 0 + mmmstr[MMM] } function spit_m11() { if ( domobdet == "1") { m11file = outdir "/" "wb4_m11_" billmm billyyyy ".in" } if ( dodet == "1") { #m11file = outdir "/" "wb4_m11_" carrier "_" batchtypeid ".in" m11file = outdir "/" "wb4_m11_cdr.in" } # mobile m11 input file... #10188|0418113733|OPTUS|CDR|MOBCL M S|Sep 2010|30/08/2010|112800||Div-VoiceMail|DEPOSIT|P|11|0.050| #10188|0418113733|OPTUS|CHARGE_DESC|CALL|Sep 2010||||Short Messaging Charges|05/08/2010 to 04/09/2010||0|1.590| # mob_sundry # mob_mobile # mob_carrier # mob_rectype "CDR|CONFIG|CHARGE_DESC|CHAGE_DESC_INFO|ERROR" # mob_recclass "CALLTYPE|COSTCENTRE|NAME|RENT|CALL|OTHER|TOTAL" # mob_billperiod # mob_cdate # mob_ctime # mob_origin # mob_destination # mob_dialled # mob_rate # mob_duration # mob_cost # mob_newcost if ( domobdet == "1" && done_mobiles_from_config == "" ) { # add in mobiles from config # to get 0 totals for mobiles without data # or have no detail recs mobconffile = "indata/" billperiod "/mobconf.unl" printf("getdetail6: ld_mobconf(%s)\n", mobconffile) while ( (getline aline < mobconffile) > 0 ) { split(aline, a_arr, "|") #printf("aline=%s\n", aline) f = 0 # from getSIDMAINTconf recordno = trim(a_arr[++f]) mobconf_mobile = clip(a_arr[++f]) sidmainttype = clip(a_arr[++f]) mobconf_sdate = clip(a_arr[++f]) mobconf_edate = clip(a_arr[++f]) directoryID = clip(a_arr[++f]) grid = fixforfname(clip(a_arr[++f])) datatype = clip(a_arr[++f]) conf_carrier = clip(a_arr[++f]) carriercode = clip(a_arr[++f]) grname1 = clip(a_arr[++f]) grname3 = fixforfname(clip(a_arr[++f])) surname = clip(a_arr[++f]) firstname = clip(a_arr[++f]) manufacturer = clip(a_arr[++f]) model = clip(a_arr[++f]) servicetype = clip(a_arr[++f]) dataplan = clip(a_arr[++f]) conf_batchtypeid = 0 datasrcid = 0 mobile = mobconf_mobile gsub(" ","",mobile) gsub("-","",mobile) if ( conf_carrier == "" ) conf_carrier = "notset" csvstr = conf_batchtypeid "|" datasrcid "|" mobile "|" conf_carrier "|" "CDR" "|" "X" "|" billperiod "|" EDATE "|" "000000" "|" "" "|" "" "|" "" "|" "" "|" "0" "|" "0.00" printf("%s\n", csvstr) >>m11file } close(mobconffile) done_mobiles_from_config = 1 } #33671|0407191094|TELSTRA|Rent|Apr_2010|CHARGE_DESC|000000|RENT|Rent||MESSAGEBANK ACCESS FEE|0|0.00|0.00| #33671|0407191094|TELSTRA|CALLS TO SENSIS|Apr_2010|06/04/2010|125100|MELBOURNE|Mobile Originated SMS|1234|CALLS TO SENSIS|38|1.27|1.27| sundry = batchid serviceid = fldvalue_arr["tServiceID_ServiceID"] if ( domobdet == "1" ) servicenumber = substr(serviceid,1,4) substr(serviceid,6,6) else servicenumber = serviceid # set in main #suppliername = fldvalue_arr["tSupplier_SupplierName"] #split(suppliername, suppliername_arr, " ") #carrier = toupper(suppliername_arr[1]) TxnGrp = fldvalue_arr["tTransactionGroup_Description"] if ( TxnGrp == "CALL") { rectype = "CDR" #recclass = fldvalue_arr["tTransactionType_Description"] recclass = fldvalue_arr["tRateDescription_Description"] } else { # RENT/OTHER/ADMIN rectype = "CHARGE_DESC" recclass = fldvalue_arr["tTransactionGroup_Description"] } # cnv dt to "dd/mm/yyyy" and 24hr "hhmmss" #Jan 05 2009 04:23PM dt = fldvalue_arr["tTransactionTableYYYYMM_TxnDate"] MM = MMM_to_MM(substr(dt,1,3)) DD = 0 + substr(dt,5,2) YYYY = 0 + substr(dt,8,4) if ( MM == 0 || DD == 0 || YYYY == 0 ) { MM = IMM DD = IDD YYYY = IYYYY } cdate = sprintf("%02d/%02d/%04d", DD, MM, YYYY) hh = 0 + substr(dt,13,2) if ( hh == 12 && toupper(substr(dt,18,2)) == "AM" ) hh = 0 if ( hh < 12 && toupper(substr(dt,18,2)) == "PM" ) hh += 12 mm = 0 + substr(dt,16,2) ss = 0 ctime = sprintf("%02s%02d%02d", hh, mm, ss) dursecs = int(fldvalue_arr["tTransactionTableYYYYMM_Duration"]) # Rate Desc rate = fldvalue_arr["tRateDescription_Description"] origin = fldvalue_arr["tOrigin_Description"] ## if blank use Location Desciption #if ( origin == "" ) # origin = fldvalue_arr["tLocation_Description"] # if blank use ServiceType Desciption if ( origin == "" ) origin = fldvalue_arr["tServiceType_Description"] # set dialled no dialled = fldvalue_arr["tDialledNumber_Description"] # set destination/description info if (recclass == "RENT" || recclass == "OTHER" || recclass == "ADMIN" ) { # CHARGE_DESC RENT, OTHER, ADMIN # Use RateDescription Description destination = fldvalue_arr["tRateDescription_Description"] if ( destination == "" ) { #destination = "Blank tRateDescription.Desc. using tTransactionType.Desc. [" fldvalue_arr["tTransactionType_Description"] "]" destination = fldvalue_arr["tTransactionType_Description"] } } else { # CDR CALL destination = fldvalue_arr["tDestination_Description"] # also use TransactionType Description (Calltype/ChargeDesc) if ( destination != "" ) destination = destination " " destination = destination fldvalue_arr["tTransactionType_Description"] # if still blank use TransactionGroup Desc if ( destination == "" ) destination = fldvalue_arr["tTransactionGroup_Description"] # remove dialled number from start of destination #if ( dialled == destination ) # destination = "" if ( dialled != "" ) { #sub(dialled,"",destination) if ( substr(destination,1,length(dialled)) == dialled ) destination = substr(destination,length(dialled)+1) } } cost = fldvalue_arr["tTransactionTableYYYYMM_AmountExGST"] ## tdetail ##date, ctimestr, origin, expdialledno, destination "~" aline, durstr, cost #aline = $0 #destination = destination "~" aline csvstr = "" csvstr = csvstr sprintf("%s|",batchtypeid) csvstr = csvstr sprintf("%s|",sundry) csvstr = csvstr sprintf("%s|%s|%s|%s|%s|", servicenumber, carrier, rectype, recclass, billperiod) csvstr = csvstr sprintf("%s|%s|%s|%s|%s|%s|%d|%s|", cdate, ctime, origin, destination, dialled, rate, dursecs, cost) csvstr = csvstr sprintf("%0.2f|", cost) printf("%s\n", csvstr) >>m11file } END { # output kB Usage summary (reportgroup 15 & 19) if ( doKBUSAGEsummary ) { for ( atag in KBUSAGE_UsagekB_total_arr ) { split(atag, atag_arr, "|") for ( i = 1; i <= (NF-1); ++i ) { fldname = fldname_arr[i] fldvalue = atag_arr[i] fldvalue_arr[fldname] = fldvalue } UsagekB = KBUSAGE_UsagekB_total_arr[atag] RENT_AmountExGST = KBUSAGE_RENT_AmountExGST_total_arr[atag] EXCESS_AmountExGST = KBUSAGE_EXCESS_AmountExGST_total_arr[atag] AmountExGST = RENT_AmountExGST + EXCESS_AmountExGST fldvalue_arr["tTransactionTableYYYYMM_Var01"] = UsagekB fldvalue_arr["tTransactionTableYYYYMM_Var13"] = RENT_AmountExGST fldvalue_arr["tTransactionTableYYYYMM_Var15"] = EXCESS_AmountExGST fldvalue_arr["tTransactionTableYYYYMM_AmountExGST"] = AmountExGST print "TOTAL: atag=[" atag "]" " UsagekB=[" UsagekB "]" " RENT_AmountExGST=[" RENT_AmountExGST "]" " EXCESS_AmountExGST=[" EXCESS_AmountExGST "]" " AmountExGST=[" AmountExGST "]" batchid = fldvalue_arr["tBatch_ID"] batchtypeid = fldvalue_arr["tBatchType_ID"] suppliername = fldvalue_arr["tSupplier_SupplierName"] serviceid = fldvalue_arr["tServiceID_ServiceID"] reportgroupid = fldvalue_arr["tReportGroupID"] invoiceno = fldvalue_arr["tInvoice_PlatinumInvoiceNo"] shipto = fldvalue_arr["tCustomer_ShipTo"] split(suppliername, suppliername_arr, " ") carrier = toupper(suppliername_arr[1]) ofile = outdir "/" outfilepref "_" shipto "_" invoiceno "_" batchid "_" reportgroupid ".unl" print "ofile=" ofile handle_ofile() } } } '