: !/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/04/2010" #EDATE="30/04/2010" #IYYYYMMDD="20100430" #IOFFSETDAYS="9" #APERIOD="2010/04" #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 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 tbsbillingperiod="$APERIOD" echo "tbsbillingperiod=[$tbsbillingperiod]" YYYYMM=`echo "$tbsbillingperiod" | sed 's/\///'` echo "YYYYMM=[$YYYYMM]" #transactiontable="tFinalisedTransaction" transactiontable="tFinalisedTransaction${YYYYMM}" #echo "transactiontable=[$transactiontable]" 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_${YYYYMM}_${BATCHID}.unl" #outfilepref="$0_${YYYYMM}" 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 mkdir -p "${outdir}" #-------------------------------------------------------------- # Bilmax21 standard internal mobile call data format # first in 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) # RENT / OTHER / (also has CALL summary) #sdate_str = "CHARGE_DESC" #btxt_origin = "RENT" ( #cat < 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')) $EXCLUDEINVBIT $EXCLUDEBATCHIDBIT $EXCLUDEINVBIT $EXCLUDEBATCHIDBIT --# and tServiceID.ServiceID = "0407-326077 ORDER BY tCustomer.ShipTo, tInvoice.PlatinumInvoiceNo, tBatch.ID, tServiceID.ServiceID, ${transactiontable}.Var01, tReportGroup.ID \go -m bcp SQLCMD0 ) | tr "," ";" | awk -F'|' \ -v"splitby=$splitby" \ -v"outfilepref=$outfilepref" \ -v"outdir=$outdir" ' { batchid = $1 batchtypeid = $3 serviceid = $7 reportgroupid = $13 invoiceno = $16 shipto = $17 var01 = $40 if ( splitby == "" ) splitby = "0" dosplitby = splitby # to determine if its a mobile sid (but not Call Diversion) # 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 not Victrack Call Diversion if ( batchtypeid != 141 ) { dosplitby = "1" } } #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 ( 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 printf("%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n", sprintf("%02d_",++f) "tBatch_ID", sprintf("%02d_",++f) "tBatch_BillingPeriod", sprintf("%02d_",++f) "tBatchType_ID", sprintf("%02d_",++f) "tBatchType_SupplierID", sprintf("%02d_",++f) "tBatchType_Description", sprintf("%02d_",++f) "tSupplier_SupplierName", sprintf("%02d_",++f) "tServiceID_ServiceID", sprintf("%02d_",++f) "tServiceID_Service", sprintf("%02d_",++f) "tServiceType_Code", sprintf("%02d_",++f) "tServiceType_Description", sprintf("%02d_",++f) "tInvoice_InvoiceDate", sprintf("%02d_",++f) "tTransactionTableYYYYMM_TxnDate", sprintf("%02d_",++f) "tReportGroupID", sprintf("%02d_",++f) "tReportGroup_GroupDesc", sprintf("%02d_",++f) "tInvoice_PlatinumFileName", sprintf("%02d_",++f) "tInvoice_PlatinumInvoiceNo", sprintf("%02d_",++f) "tCustomer_ShipTo", sprintf("%02d_",++f) "tCustomer_FullName", sprintf("%02d_",++f) "tCentre_Description", sprintf("%02d_",++f) "tActivity_Description", sprintf("%02d_",++f) "tElement_ElementCode", sprintf("%02d_",++f) "tElement_Description", sprintf("%02d_",++f) "tElement_1_ElementCode", sprintf("%02d_",++f) "tElement_1_Description", sprintf("%02d_",++f) "tElement_2_ElementCode", sprintf("%02d_",++f) "tElement_2_Description", sprintf("%02d_",++f) "tSubledger_Description", sprintf("%02d_",++f) "tDepartment_Description", sprintf("%02d_",++f) "tLocation_Description", sprintf("%02d_",++f) "tPerson_Person", sprintf("%02d_",++f) "tApplication_ID", sprintf("%02d_",++f) "tApplication_Description", sprintf("%02d_",++f) "tOrigin_Description", sprintf("%02d_",++f) "tDestination_Description", sprintf("%02d_",++f) "tRateDescription_Description", sprintf("%02d_",++f) "tTransactionType_Description", sprintf("%02d_",++f) "tTransactionGroup_Description", sprintf("%02d_",++f) "tDialledNumber_Description", sprintf("%02d_",++f) "tTransactionTableYYYYMM_Duration", sprintf("%02d_",++f) "tTransactionTableYYYYMM_AmountExGST", sprintf("%02d_",++f) "tBatchType_Var01Description", sprintf("%02d_",++f) "tTransactionTableYYYYMM_Var01", sprintf("%02d_",++f) "tBatchType_Var02Description", sprintf("%02d_",++f) "tTransactionTableYYYYMM_Var02", sprintf("%02d_",++f) "tBatchType_Var03Description", sprintf("%02d_",++f) "tTransactionTableYYYYMM_Var03", sprintf("%02d_",++f) "tBatchType_Var04Description", sprintf("%02d_",++f) "tTransactionTableYYYYMM_Var04", sprintf("%02d_",++f) "tBatchType_Var05Description", sprintf("%02d_",++f) "tTransactionTableYYYYMM_Var05", sprintf("%02d_",++f) "tBatchType_Var06Description", sprintf("%02d_",++f) "tTransactionTableYYYYMM_Var06", sprintf("%02d_",++f) "tBatchType_Var07Description", sprintf("%02d_",++f) "tTransactionTableYYYYMM_Var07", sprintf("%02d_",++f) "tBatchType_Var08Description", sprintf("%02d_",++f) "tTransactionTableYYYYMM_Var08", sprintf("%02d_",++f) "tBatchType_Var09Description", sprintf("%02d_",++f) "tTransactionTableYYYYMM_Var09", sprintf("%02d_",++f) "tBatchType_Var10Description", sprintf("%02d_",++f) "tTransactionTableYYYYMM_Var10", sprintf("%02d_",++f) "tBatchType_Var11Description", sprintf("%02d_",++f) "tTransactionTableYYYYMM_Var11", sprintf("%02d_",++f) "tBatchType_Var12Description", sprintf("%02d_",++f) "tTransactionTableYYYYMM_Var12", sprintf("%02d_",++f) "tBatchType_Var13Description", sprintf("%02d_",++f) "tTransactionTableYYYYMM_Var13", sprintf("%02d_",++f) "tBatchType_Var14Description", sprintf("%02d_",++f) "tTransactionTableYYYYMM_Var14", sprintf("%02d_",++f) "tBatchType_Var15Description", sprintf("%02d_",++f) "tTransactionTableYYYYMM_Var15") >> ofile } } #print $0 >> ofile for ( i = 1; i <= (NF-1); ++i ) { if ( i > 1 ) printf(",") >> ofile printf("%02d: %s", i, $i) >> ofile } printf("\n") >> ofile }'