: !/bin/sh SDATE="$1" EDATE="$2" mcsvfile="$3" mcsvoutdir="topdat" mcsvoutfilepref="import" #Testing ###SDATE="01/04/2010" ###EDATE="30/04/2010" ##SDATE="01/12/2010" ##EDATE="31/12/2010" SDATE="01/05/2011" EDATE="31/05/2011" #mcsvoutdir="import" mcsvfile="mcsv.sql" ###################################################################### MMYYYY=`SDATEtoMMYYYY $SDATE` echo "MMYYYY = [$MMYYYY]" billperiod=`MMYYYYtobillperiod $MMYYYY _` echo "$MMYYYY - billperiod = [$billperiod]" # run additional customer import csv creation if [ -f "invcde.excl_${billperiod}" ]; then . invcde.excl_${billperiod} fi ###################################################################### #if [ "$mcsvoutdir" != "." -a -d "${mcsvoutdir}" ]; then # rm -r "${mcsvoutdir}" # mkdir -p "${mcsvoutdir}" #fi echo "getallmcsv6:" echo " EXCLUDEINVBIT = $EXCLUDEINVBIT" echo "" echo " EXCLUDEBATCHIDBIT = $EXCLUDEBATCHIDBIT" echo "" if [ -z "$mcsvfile" ]; then mcsvfile="mcsv.unl" fi tmp1file="/tmp/gallmcsv6_$$" rm -f "$tmp1file" rm -f "$mcsvfile" rm -f "/tmp/mcsvout$$" IOFFSETDAYS="9" # convert EDATE to YYYYMMDD EYYYYMMDD=`awk -v "ADATE=$EDATE" -v "sep=" ' BEGIN { dd = 0 + substr(ADATE,1,2); mm = 0 + substr(ADATE,4,2); yyyy = 0 + substr(ADATE,7,4); YYYYMMDD = sprintf("%04d%s%02d%s%02d", yyyy, sep, mm, sep, dd); print YYYYMMDD exit }'` echo "EYYYYMMDD=[$EYYYYMMDD]" ###################################################################### . tbsserver_vars # get required bill Periods from TBS invoice tables # based on InvoiceDate ( sqsh -S $server -D $dbname -U $username -P $password < dateadd(dd,$IOFFSETDAYS,'$EYYYYMMDD') and tInvoice.InvoiceDate <= dateadd(mm,1,dateadd(dd,$IOFFSETDAYS,'$EYYYYMMDD')) $EXCLUDEINVBIT $EXCLUDEBATCHIDBIT ORDER BY Period \go -m bcp SQLCMD0 ) | sed 's/\|$//' > "$tmp1file" # loop for each required bill Period cat "$tmp1file" | \ while read aperiod do echo "aperiod=[$aperiod]" ################################### # monthly customer import csv files # getmcsv6 $EYYYYMMDD $IOFFSETDAYS "$aperiod" "$SHIPTO" "$BATCHID" "$INVOICENO" "/tmp/mcsvout$$" g6 $EYYYYMMDD $IOFFSETDAYS "$aperiod" "$SHIPTO" "$BATCHID" "$INVOICENO" "/tmp/mcsvout$$" cat "/tmp/mcsvout$$" >>"$mcsvfile" rm -f "/tmp/mcsvout$$" done # Testing tbssql mcsv.unl exit 0 #---------------------------------- # process unl file and create customer import detail and summary csv files # eg. data #Telco Rentals & Calls|1000PAS|33667|VICTRACK|PAS 570 BOURKE ST||10000|||34572||TELCO RENTAL&CALLS|VicTrack Rent and Calls APR 2010|2010/04|VLP|INV003314|0.05|0.01|0.06|CALL|15937|97|23085|out|1000PAS|VicTrack Rent and Calls|Network Services|CHIEF FINANCIAL OFFICER| if [ "$mcsvoutdir" != "." -a -d "${mcsvoutdir}" ]; then mkdir -p "${mcsvoutdir}" fi if [ -z "$SHIPTO" ]; then SHIPTO="all" fi cat "$mcsvfile" | tr "," ";" | awk -F'|' \ -v"pid=$$" \ -v"thisDIVID=$SHIPTO" \ -v "platinumBATCH=all" \ -v"IYYYYMMDD=$EYYYYMMDD" \ -v"billperiod=$billperiod" \ -v"outdir=$mcsvoutdir" \ -v"outfilepref=$mcsvoutfilepref" ' function trim(s) { sub(/^[ \t]*/,"",s) sub(/[ \t]*$/,"",s) return s } function ld_exwebconf(exwebconffile) { printf("ld_exwebconf(%s)\n", exwebconffile) #noddsupfile = "noddsup.txt"; #while ( (getline custline < noddsupfile) > 0 ) { # split(custline, noddsupgggrid, " "); # noddsuparr[noddsupgggrid[1]] = 1; #} #close(noddsupfile); while ( (getline exwebconfline < exwebconffile) > 0 ) { split(exwebconfline, exwebconfarr, ","); #printf("exwebconfline=%s\n", exwebconfline); #printf("exwebconfarr 1=%s 2=%s 3=%s 4=%s\n", exwebconfarr[1], exwebconfarr[2], exwebconfarr[3], exwebconfarr[4]); exwebconf_parent = trim(exwebconfarr[1]) exwebconf_dialxx = trim(exwebconfarr[2]) exwebconf_email = trim(exwebconfarr[3]) exwebconf_emailyn = trim(exwebconfarr[4]) exwebconf_status1 = trim(exwebconfarr[5]) exwebconf_lastemailed = trim(exwebconfarr[6]) exwebconf_lastemaileddate = trim(exwebconfarr[7]) exwebconf_print = trim(exwebconfarr[8]) exwebconf_cdgroup = trim(exwebconfarr[9]) # skip retired entries if ( exwebconf_status1 == "R" ) continue # flag parent in exwebconf exwebconf_parent_arr[exwebconf_parent] = 1 # if ( platinv_parent_arr[exwebconf_parent] != 1 ) { # print "WARNING: parent = " exwebconf_parent " found in exwebconf, but is not in platinum invoice data" # } # # #printf("noddsuparr[%s] = %d\n", exwebconf_parent, noddsuparr[exwebconf_parent]); # if ( toupper(exwebconf_dialxx) == "N" ) # noddsuparr[exwebconf_parent] = 1; # else # noddsuparr[exwebconf_parent] = 0; # #tmpgggrid = exwebconf_parent; # #if ( noddsuparr[tmpgggrid] == 1 ) # # printf(" NO DD SUPPRESS\n"); # #else # # printf(" DO DD SUPPRESS\n"); # # store parent grouping exwebconf_parent_to_cdgroup_arr[exwebconf_parent] = exwebconf_cdgroup } close(exwebconffile); } BEGIN { f = 0 fldname_arr[++f] = "Element" fldname_arr[++f] = "ServiceIDDesc" fldname_arr[++f] = "Batch" fldname_arr[++f] = "Supplier" fldname_arr[++f] = "Location" fldname_arr[++f] = "Person" fldname_arr[++f] = "Centre" fldname_arr[++f] = "Activity" fldname_arr[++f] = "Element1" fldname_arr[++f] = "SubLedger" fldname_arr[++f] = "PayType" fldname_arr[++f] = "ServiceType" fldname_arr[++f] = "InvoiceDescription" fldname_arr[++f] = "Period" fldname_arr[++f] = "ShipTo" fldname_arr[++f] = "Invoice" fldname_arr[++f] = "ExGST" fldname_arr[++f] = "GST" fldname_arr[++f] = "IncGST" fldname_arr[++f] = "TxnGrp" fldname_arr[++f] = "Var01" fldname_arr[++f] = "Var02" fldname_arr[++f] = "Var03" fldname_arr[++f] = "Var04" fldname_arr[++f] = "Var05" fldname_arr[++f] = "Var06" fldname_arr[++f] = "Var07" fldname_arr[++f] = "Var08" fldname_arr[++f] = "Var09" fldname_arr[++f] = "Var10" fldname_arr[++f] = "Var11" fldname_arr[++f] = "Var12" fldname_arr[++f] = "Var13" fldname_arr[++f] = "Var14" fldname_arr[++f] = "Var15" fldname_arr[++f] = "BatchType" fldname_arr[++f] = "Group" fldname_arr[++f] = "Dept" fldname_arr[++f] = "Service" # IYYYYMMDD IYYYY = substr(IYYYYMMDD,1,4) IMM = substr(IYYYYMMDD,5,2) IDD = substr(IYYYYMMDD,7,2) # bilmax V3 (before move of logdir) monthdir = "topdat" "/" billperiod targdir = monthdir "/" platinumBATCH "_" thisDIVID batchtag = billperiod "_" platinumBATCH "_" thisDIVID logdir = monthdir "/log_" batchtag exwebconffile = logdir "/exwebconf_" batchtag ".csv" ## bilmax V4 #exwebconffile = "indata" "/" billperiod "/" "exwebconf.csv" ld_exwebconf(exwebconffile) } { #print $0 # load record for ( i = 1; i <= (NF-1); ++i ) { fldname = fldname_arr[i] fldvalue = trim($i) fldvalue_arr[fldname] = fldvalue } ShipTo = fldvalue_arr["ShipTo"] Invoice = fldvalue_arr["Invoice"] # handle detail detail_ofile = outfilepref "_" ShipTo "_" billperiod "_" Invoice "_detail.csv" divgroup = exwebconf_parent_to_cdgroup_arr[ShipTo] if ( divgroup == "" ) divgroup = ShipTo pardir = billperiod "/" platinumBATCH "_" thisDIVID divdir = pardir "/" divgroup "/" ShipTo dirpath = outdir "/" divdir #dirpath = outdir ofile = dirpath "/" detail_ofile # create file with header if ( done_header[ofile] == "" ) { cmd = sprintf("[ ! -d \"%s\" ] && mkdir -p \"%s\"", dirpath, dirpath); system(cmd); print "ofile=[" ofile "]" system("rm -f \"" ofile "\"") f = 0 for ( i = 1; i <= (NF-1); ++i ) { fldname = fldname_arr[i] if ( i > 1 ) printf(",") >> ofile printf("%s", fldname) >> ofile } printf("\n") >> ofile close(ofile) done_header[ofile] = "1" } # output record for ( i = 1; i <= (NF-1); ++i ) { fldname = fldname_arr[i] fldvalue = trim($i) fldvalue_arr[fldname] = fldvalue if ( i > 1 ) printf(",") >> ofile printf("%s", fldvalue) >> ofile } printf("\n") >> ofile close(ofile) # create summary #The Monthly summary groups and shows the following fields from the above dataset: #. Invoice (Platinum Invoice) #. Cost Centre (tServiceID!CustomerCentre) #. Cost Centre Description (tDepartment.Description AS Dept) #. Activity #. Element #. SubLedger (tServiceID.CustomerSubLedgerID) #. PayType #. Sum of ExGST #. Sum of GST #. Sum of IncGST # ... Centre = fldvalue_arr["Centre"] Dept = fldvalue_arr["Dept"] Activity = fldvalue_arr["Activity"] Element1 = fldvalue_arr["Element1"] SubLedger = fldvalue_arr["SubLedger"] PayType = fldvalue_arr["PayType"] ExGST = fldvalue_arr["ExGST"] GST = fldvalue_arr["GST"] IncGST = fldvalue_arr["IncGST"] atag = ShipTo "|" Invoice "|" Centre "|" Dept "|" Activity "|" Element1 "|" SubLedger "|" PayType atag_arr[atag] = 1 ExGST_total_arr[atag] += ExGST GST_total_arr[atag] += GST IncGST_total_arr[atag] += IncGST } END { # create temp sorted atag file tmpatagfile = "/tmp/getmcsvtmpatag_" pid system("rm -f " tmpatagfile) sortcmd = "sort >" tmpatagfile for ( atag in atag_arr ) { print atag | sortcmd } close(sortcmd) # output summary while ( (getline atag < tmpatagfile) > 0 ) { split(atag,a_arr,"|") f = 0 ShipTo = a_arr[++f] Invoice = a_arr[++f] Centre = a_arr[++f] Dept = a_arr[++f] Activity = a_arr[++f] Element1 = a_arr[++f] SubLedger = a_arr[++f] PayType = a_arr[++f] ExGST_total = ExGST_total_arr[atag] GST_total = GST_total_arr[atag] IncGST_total = IncGST_total_arr[atag] #print "atag=[" atag "]" " totals ExGST=[" ExGST_total "]" " GST=[" GST_total "]" " IncGST=[" IncGST_total "]" >"sumtots" summary_ofile = outfilepref "_" ShipTo "_" billperiod "_" Invoice "_summary.csv" divgroup = exwebconf_parent_to_cdgroup_arr[ShipTo] if ( divgroup == "" ) divgroup = ShipTo pardir = billperiod "/" thisDIVID "_" platinumBATCH divdir = pardir "/" divgroup "/" ShipTo dirpath = outdir "/" divdir #dirpath = outdir ofile = dirpath "/" summary_ofile # create file with header if ( done_header[ofile] == "" ) { cmd = sprintf("[ ! -d \"%s\" ] && mkdir -p \"%s\"", dirpath, dirpath); system(cmd); print "ofile=[" ofile "]" system("rm -f \"" ofile "\"") printf("%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n", "Invoice", "Centre", "Dept", "Activity", "Element", "SubLedger", "PayType", "ExGST", "GST", "IncGST") > ofile done_header[ofile] = "1" } # output record printf("%s,%s,%s,%s,%s,%s,%s,%0.2f,%0.2f,%0.2f\n", Invoice, Centre, Dept, Activity, Element1, SubLedger, PayType, ExGST_total, GST_total, IncGST_total) >> ofile close(ofile) } close(tmpatagfile) system("rm -f " tmpatagfile) } ' rm -f "$tmp1file" exit 0