: !/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 BATCHID env var # $5 will override INVOICENO env var # $6 will override default outdir splitserviceids="1" ############################# # Testing #SDATE="01/04/2010" #EDATE="30/04/2010" IYYYYMMDD="20100430" IOFFSETDAYS="9" APERIOD="2010/04" BATCHID="33795" INVOICENO="INV003314" splitserviceids="0" outdir="." ############################# tbsbillingperiod="$APERIOD" echo "tbsbillingperiod=[$tbsbillingperiod]" YYYYMM=`echo "$tbsbillingperiod" | sed 's/\///'` echo "YYYYMM=[$YYYYMM]" #transactiontable="tFinalisedTransaction" transactiontable="tFinalisedTransaction${YYYYMM}" #echo "transactiontable=[$transactiontable]" ############################# 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 if [ -n "$4" -a "$4" != "all" ]; then BATCHID="$4" 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 "$5" -a "$5" != "all" ]; then INVOICENO="$5" 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 "$6" ]; then outdir="$6" else if [ -z "$outdir" ]; then #outdir="detail_${APERIOD}_${BATCHID}" #outdir="detail_${IYYYYMMDD}_${BATCHID}" outdir="detail_${IYYYYMM}_${BATCHID}" fi fi #outfile="$0_${YYYYMM}_${BATCHID}.unl" #outfile="$0_${YYYYMM}" outfile="detail_${IYYYYMM}" echo "$0: for $IYYYYMMDD, $IOFFSETDAYS, $APERIOD, batchid [$BATCHID], invoiceno [$INVOICENO] to outdir [$outdir] outfile prefix [$outfile] splitserviceids [$splitserviceids]" . tbsserver_vars #if [ "$outdir" != "." ]; then # rm -r "${outdir}" # mkdir -p "${outdir}" #fi #-------------------------------------------------------------- # 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 tInvoice.PlatinumInvoiceNo, tBatch.ID, tServiceID.ServiceID, ${transactiontable}.Var01 \go -m bcp SQLCMD0 #) | tr "," ";" >$outfile #) | tr "," ";" | split -b1024m - $outfile ) | tr "," ";" | awk -F'|' \ -v"splitserviceids=$splitserviceids" \ -v"outfile=$outfile" \ -v"outdir=$outdir" ' { invoiceno = $14 batchid = $1 serviceid = $6 var01 = $38 if ( splitserviceids == "1" ) { # cant have "/" in SID (re: filenames) gsub("/",".",serviceid) #ofile = outdir "/" outfile "_" batchid "_" serviceid "_" var01 ".unl" ofile = outdir "/" outfile "_" batchid "_" serviceid ".unl" } else { ofile = outdir "/" outfile "_" 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" 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\n", "01_tBatch_ID", "02_tBatch_BillingPeriod", "03_tBatchType_SupplierID", "04_tBatchType_Description", "05_tSupplier_SupplierName", "06_tServiceID_ServiceID", "07_tServiceID_Service", "08_tServiceType_Code", "09_tServiceType_Description", "10_tInvoice_InvoiceDate", "11_tTransactionTableYYYYMM_TxnDate", "12_tReportGroup_GroupDesc", "13_tInvoice_PlatinumFileName", "14_tInvoice_PlatinumInvoiceNo", "15_tCustomer_ShipTo", "16_tCustomer_FullName", "17_tCentre_Description", "18_tActivity_Description", "19_tElement_ElementCode", "20_tElement_Description", "21_tElement_1_ElementCode", "22_tElement_1_Description", "23_tElement_2_ElementCode", "24_tElement_2_Description", "25_tSubledger_Description", "26_tDepartment_Description", "27_tLocation_Description", "28_tPerson_Person", "29_tOrigin_Description", "30_tDestination_Description", "31_tRateDescription_Description", "32_tTransactionType_Description", "33_tTransactionGroup_Description", "34_tDialledNumber_Description", "35_tTransactionTableYYYYMM_Duration", "36_tTransactionTableYYYYMM_AmountExGST", "37_tBatchType_Var01Description", "38_tTransactionTableYYYYMM_Var01", "39_tBatchType_Var02Description", "40_tTransactionTableYYYYMM_Var02", "41_tBatchType_Var03Description", "42_tTransactionTableYYYYMM_Var03", "43_tBatchType_Var04Description", "44_tTransactionTableYYYYMM_Var04", "45_tBatchType_Var05Description", "46_tTransactionTableYYYYMM_Var05", "47_tBatchType_Var06Description", "48_tTransactionTableYYYYMM_Var06", "49_tBatchType_Var07Description", "50_tTransactionTableYYYYMM_Var07", "51_tBatchType_Var08Description", "52_tTransactionTableYYYYMM_Var08", "53_tBatchType_Var09Description", "54_tTransactionTableYYYYMM_Var09", "55_tBatchType_Var10Description", "56_tTransactionTableYYYYMM_Var10", "57_tBatchType_Var11Description", "58_tTransactionTableYYYYMM_Var11", "59_tBatchType_Var12Description", "60_tTransactionTableYYYYMM_Var12", "61_tBatchType_Var13Description", "62_tTransactionTableYYYYMM_Var13", "63_tBatchType_Var14Description", "64_tTransactionTableYYYYMM_Var14", "65_tBatchType_Var15Description", "66_tTransactionTableYYYYMM_Var15") >> ofile } } #print $0 >> ofile for ( i = 1; i <= 66; ++i ) { if ( i > 1 ) printf(",") >> ofile printf("%02d: %s,", i, $i) >> ofile } printf("\n") >> ofile }' #29|29|1|27270|0430GTD|TQ|TELCO RENTAL&CALLS|VICTRACK|P|Feb_2008|Feb 29 2008 12:00AM||||Call|CALL||0|0.0000|13131|45|0|in|||||||||||| #cat $outfile #find "$outdir" -type f -exec wc -l {} \; | sort -nr >"gd5.cnt"