#!/bin/sh # get Victrack NCR Times echo "Content-type: text/html" echo "" DODBG="false"; export DODBG; SHOWDAILYCEILHOURS="Y" SHOWACTUALHOURS="Y" SHOWGRANDTOTALS="Y" SHOWNCRTOTALS="Y" SHOWNCRGRANDTOTALS="Y" SHOWNCRACTUALGRANDTOTAL="Y" tmpdir=`pwd`"/tmp" echo "tmpdir: $tmpdir" tmpfile1="/$tmpdir/tmp1_${ATIMETAG}_$$.tmp" tmpfile2="/$tmpdir/tmp2_${ATIMETAG}_$$.tmp" rm -f "$tmpfile1" rm -f "$tmpfile2" ############################################## ## Testing ##SDATE="01/06/1996" ##EDATE="03/06/1996" #MONTH="07/2014" #CUSTOMER="Victrack" ##TIMETAG="Time:" #TIMETAG="ALL:" #SHOWDAILYCEILHOURS="Y" #SHOWACTUALHOURS="Y" #SHOWGRANDTOTALS="Y" #SHOWNCRTOTALS="Y" #SHOWNCRGRANDTOTALS="Y" #SHOWNCRACTUALGRANDTOTAL="Y" ##SITEID=ALL ############################################### myprogname=`basename "$0"` mytitle="Extracting data from Telmax21" echo "" echo "" echo "$mytitle" echo "" echo "" echo "

$myprogname

" echo "

$mytitle...

" # set environment variables. #. /u/catcom/catcom_vars ################################################################# lastdayinmonth() # Returns the last day in month, Inputs: $1=mm $2=yyyy { cal $1 $2 | awk '{ if ( NF > 0 ) x=$NF } END { print x }' } ################################### # handle params # stdin post if [ "$REQUEST_METHOD" = "POST" ]; then cmd=`echo "$stdinput" | awk -f wbt_splitqstr.awk` $DODBG && echo "cmd=[$cmd]
" >>"$dbgfile" for cmdtok in `echo "$cmd"` do $DODBG && echo "cmdtok=[$cmdtok]
" >>"$dbgfile" fixcmdtok=`echo "$cmdtok" | ./wbt_fixqstr` $DODBG && echo "fixcmdtok=[$fixcmdtok]
" >>"$dbgfile" eval "$fixcmdtok" done $DODBG && echo "
" >>"$dbgfile" fi # process query string if [ ! -z "$QUERY_STRING" ]; then $DODBG && echo "QUERY_STRING=[$QUERY_STRING]
" >>"$dbgfile" qstr=`echo "$QUERY_STRING" | awk -f wbt_splitqstr.awk` $DODBG && echo "qstr=[$qstr]
" >>"$dbgfile" for qtok in `echo "$qstr"` do $DODBG && echo "qtok=[$qtok]
" >>"$dbgfile" #echo "qtok=[$qtok]" >>/tmp/1 fixqtok=`echo "$qtok" | ./wbt_fixqstr` $DODBG && echo "fixqtok=[$fixqtok]
" >>"$dbgfile" #echo "fixqtok=[$fixqtok]" >>/tmp/1 eval $fixqtok done $DODBG && echo "
" >>"$dbgfile" fi # handle cookies if [ ! -z "$HTTP_COOKIE" ]; then cookie=`echo "$HTTP_COOKIE" | awk -f wbt_splitqstr.awk` $DODBG && echo "cookie=[$cookie]
" >>"$dbgfile" for cookietok in `echo "$cookie"` do $DODBG && echo "cookietok=[$cookietok]
" >>"$dbgfile" fixcookietok=`echo "$cookietok" | ./wbt_fixqstr` fixcookietok="conf_$fixcookietok" $DODBG && echo "fixcookietok=[$fixcookietok]
" >>"$dbgfile" eval $fixcookietok done $DODBG && echo "
" >>"$dbgfile" fi $DODBG && echo "
" ################################### # get lock #LOCKFILE="/tmp/t21websql.lok" #while true #do # if [ ! -f "$LOCKFILE" ]; then # break; # fi # sleep 2 #done #touch $LOCKFILE ################################### if [ -n "$MONTH" ]; then mm=`echo $MONTH | sed -e 's/\/....$//g'` yyyy=`echo $MONTH | sed -e 's/^..\///g'` ldd=`lastdayinmonth $mm $yyyy` SDATE="01/$mm/$yyyy" EDATE="$ldd/$mm/$yyyy" $DODBG && echo "MONTH=[$MONTH] ldd=[$ldd] SDATE=[$SDATE] EDATE=[$EDATE]
" $DODBG && echo "
" fi #if [ -z "$SITEID" -z "$SDATE" -o -z "$EDATE" ]; then # echo "You Must set SITEID, MONTH (mm/yyyy) or SDATE and EDATE (dd/mm/yyyy)" # echo "
" # exit 1 #fi if [ -z "$SITEID" ]; then SITEID="ALL" fi if [ -z "$CUSTOMER" ]; then CUSTOMER="ALL" fi if [ -z "$TIMETAG" ]; then #TIMETAG="Time:" TIMETAG="ALL:" fi if [ -z "$SHOWDAILYCEILHOURS" ]; then SHOWDAILYCEILHOURS="N" fi if [ -z "$SHOWACTUALHOURS" ]; then SHOWACTUALHOURS="Y" fi if [ -z "$SHOWGRANDTOTALS" ]; then SHOWGRANDTOTALS="Y" fi if [ -z "$SHOWNCRTOTALS" ]; then SHOWNCRTOTALS="Y" fi if [ -z "$SHOWNCRGRANDTOTALS" ]; then SHOWNCRGRANDTOTALS="Y" fi if [ -z "$SHOWNCRACTUALGRANDTOTAL" ]; then SHOWNCRACTUALGRANDTOTAL="Y" fi ######## if [ "$SITEID" = "ALL" ]; then SITEBIT="" else SITEBIT="and siteid = $SITEID" fi if [ "$CUSTOMER" = "ALL" -o "$CUSTOMER" = "" ]; then CUSTOMERBIT="" else CUSTOMERBIT="and UPPER(ost_organization.name) = UPPER('$CUSTOMER')" fi ################################################################## getrecontimes() { ATIMETAG="$1" ADESCRIPTION="$2" SQLCMD0=`cat << MYSQL0 SELECT ost_ticket.number, DATE_FORMAT(ost_ticket.created, '%d/%m/%Y'), ost_ticket__cdata.subject, ost_user.name, --# ost_organization.name, --# ost_staff.username, ost_help_topic.topic, DATE_FORMAT(ost_ticket_thread.created, '%d/%m/%Y'), ost_ticket_thread.body FROM ( ost_ticket INNER JOIN ost_ticket__cdata ON ost_ticket.ticket_id = ost_ticket__cdata.ticket_id INNER JOIN ost_ticket_thread ON ost_ticket.ticket_id = ost_ticket_thread.ticket_id AND ost_ticket_thread.thread_type = "N" AND LOWER(ost_ticket_thread.body) REGEXP "$ATIMETAG *[0-9]*" ) LEFT OUTER JOIN ( ost_user LEFT OUTER JOIN ost_organization ON ost_user.org_id = ost_organization.id ) ON ost_user.id = ost_ticket.user_id LEFT OUTER JOIN ost_staff ON ost_staff.staff_id = ost_ticket.staff_id LEFT OUTER JOIN ost_help_topic ON ost_help_topic.topic_id = ost_ticket.topic_id WHERE MONTH(ost_ticket_thread.created)=$mm and YEAR(ost_ticket_thread.created)=$yyyy $CUSTOMERBIT ORDER BY DATE_FORMAT(ost_ticket_thread.created, '%d/%m/%Y'), ost_ticket.number MYSQL0 ` ################################################################## echo "SITEID=[$SITEID] MONTH=[$MONTH] SDATE=[$SDATE] EDATE=[$EDATE]
" echo "
" echo "CUSTOMER=[$CUSTOMER]" echo "
" echo "ATIMETAG=[$ATIMETAG]" echo "
" echo "SHOWDAILYCEILHOURS=[$SHOWDAILYCEILHOURS]" echo "
" echo "SHOWACTUALHOURS=[$SHOWACTUALHOURS]" echo "
" echo "SHOWGRANDTOTALS=[$SHOWGRANDTOTALS]" echo "
" echo "SHOWNCRTOTALS=[$SHOWNCRTOTALS]" echo "
" echo "SHOWNCRGRANDTOTALS=[$SHOWNCRGRANDTOTALS]" echo "
" echo "SHOWNCRACTUALGRANDTOTAL=[$SHOWNCRACTUALGRANDTOTAL]" echo "
" echo "SQLCMD0=[$SQLCMD0]" echo "
" echo "
" sdd=`echo $SDATE | sed -e 's/\/..\/....$//g'` smm=`echo $SDATE | sed -e 's/^..\///g;s/\/....$//g'` syyyy=`echo $SDATE | sed -e 's/^..\/..\///g'` edd=`echo $EDATE | sed -e 's/\/..\/....$//g'` emm=`echo $EDATE | sed -e 's/^..\///g;s/\/....$//g'` eyyyy=`echo $EDATE | sed -e 's/^..\/..\///g'` echo "id: "`id` echo "
" echo "pwd: "`pwd` echo "
" echo "tmpfile1=[$tmpfile1]" echo "
" echo "tmpfile2=[$tmpfile2]" echo "
" # remove tmp files rm -f "$tmpfile1" 2>&1 rm -f "$tmpfile2" 2>&1 #(echo "unload to $tmpfile1 $SQLCMD0" | runisql 2>&1) >$tmpfile2 ( echo "$SQLCMD0 INTO OUTFILE '$tmpfile1' FIELDS TERMINATED BY '|' LINES TERMINATED BY '\n'; " | mysql -u apache -ptimsnart osticket 2>&1 ) >$tmpfile2 #chmod 664 "$tmpfile1" 2>&1 #chmod 664 "$tmpfile2" 2>&1 ##strip tempfile header for improting into excel #sed -i '1d' $tmpfile1 # show errors if [ -s $tmpfile2 ]; then echo "
" echo "SQL Status:" cat $tmpfile2 echo "
" fi ################################## if [ ! -s $tmpfile1 ]; then echo "NO OUTPUT|SQL:[$SQLCMD0]|" >$tmpfile1 echo "ERROR:|$tmpfile2|" >>$tmpfile1 fi cat $tmpfile1 | sed -e 's/|$//' | awk -F'|' \ -v "SDATE=$SDATE" \ -v "EDATE=$EDATE" \ -v "MONTH=$MONTH" \ -v "CUSTOMER=$CUSTOMER" \ -v "ATIMETAG=$ATIMETAG" \ -v "ADESCRIPTION=$ADESCRIPTION" \ -v "SHOWDAILYCEILHOURS=$SHOWDAILYCEILHOURS" \ -v "SHOWACTUALHOURS=$SHOWACTUALHOURS" \ -v "SHOWGRANDTOTALS=$SHOWGRANDTOTALS" \ -v "SHOWNCRTOTALS=$SHOWNCRTOTALS" \ -v "SHOWNCRGRANDTOTALS=$SHOWNCRGRANDTOTALS" \ -v "SHOWNCRACTUALGRANDTOTAL=$SHOWNCRACTUALGRANDTOTAL" \ ' function trim(s) { sub(/^[ \t]*/,"",s) sub(/[ \t]*$/,"",s) gsub(/\,/,";",s) return s } function ceil(n) { return (int(n) == n ? n : (int(n) + 1)) } BEGIN { NROWS = 0 prev_rowid = "" if ( substr(toupper(SHOWDAILYCEILHOURS),1,1) == "N" ) doshowdailyceilhours = 0 else doshowdailyceilhours = 1 if ( substr(toupper(SHOWACTUALHOURS),1,1) == "N" ) doshowactualhours = 0 else doshowactualhours = 1 if ( substr(toupper(SHOWGRANDTOTALS),1,1) == "N" ) doshowgrandtotals = 0 else doshowgrandtotals = 1 if ( substr(toupper(SHOWNCRTOTALS),1,1) == "N" ) doshowncrtotals = 0 else doshowncrtotals = 1 if ( substr(toupper(SHOWNCRGRANDTOTALS),1,1) == "N" ) doshowncrgrandtotals = 0 else doshowncrgrandtotals = 1 if ( substr(toupper(SHOWNCRACTUALGRANDTOTAL),1,1) == "N" ) doshowncractualgrandtotal = 0 else doshowncractualgrandtotal = 1 #print "" } # ussumes data is in datetime order for the Internal Time:/Quote: threads { #print "" #printf("", ++cnt) #for ( i=1; i <= NF; ++i ) { # printf("", $i) #} #print "\n" #print "" NCR = trim($1) NCRdate = trim($2) ticketDesc = trim($3) RequestedBy = trim($4) ServiceType = trim($5) NCRthreaddate = trim($6) threadtext = trim($7) ##if ( NCR != "1722" ) ## next #print $0 "
" rowid = NCR "|" NCRthreaddate NCR_arr[rowid] = NCR NCRcreateddate_arr[NCR] = NCRdate ticketDesc_arr[NCR] = ticketDesc RequestedBy_arr[NCR] = RequestedBy ServiceType_arr[NCR] = ServiceType NCRthreaddate_arr[rowid] = NCRthreaddate threadtext_arr[rowid] = threadtext # add up timese for each day ###i = match(tolower(threadtext), /time: *[0-9]*\.*[0-9]*/) ##re = "/" ATIMETAG " *[0-9]*\.*[0-9]*/" ##i = match(tolower(threadtext), re) #if ( tolower(ATIMETAG) == "quote:" ) # i = match(tolower(threadtext), /quote: *[0-9]*\.*[0-9]*/) #else # i = match(tolower(threadtext), /time: *[0-9]*\.*[0-9]*/) i = index(tolower(threadtext),tolower(ATIMETAG)) if ( i > 0 ) { #print ">>>>" substr(s1, length(ATIMETAG)) "<<<<" j = match(substr(s1, length(ATIMETAG)), / *[0-9]*\.*[0-9]*/) } if ( j > 0 ) { #print " DEBUG: threadtext=[" threadtext "]" #print "
" #s1 = substr(threadtext, RSTART, RLENGTH) s1 = substr(threadtext, i) #print " s1=[" s1 "]" #print "
" split(s1, time_sub, ":") #print " time_sub[1]=[" time_sub[1] "]" #print "
" #print " time_sub[2]=[" time_sub[2] "]" #print "
" hours = 0 + sprintf("%0.2f", time_sub[2]) #printf(" hours=[%0.2f]", hours) #print "
" } else { hours = 0 } #printf("hours = [%f]
", hours) hours_daily_total_arr[rowid] += hours hours_NCR_total_arr[NCR] += hours if ( rowid != prev_rowid ) { proc_order_arr[++NROWS] = rowid #print "DEBUG: proc_order_arr[" NROWS "]=[" proc_order_arr[NROWS] "]" #print "
" } prev_rowid = rowid } END { #print "
%d%s
" #print "
" cols = 6 if ( doshowdailyceilhours ) ++cols if ( doshowactualhours ) cols += 2 print "" if ( ADESCRIPTION != "" ) { printf("") printf("") printf("", ADESCRIPTION) printf("") if ( doshowdailyceilhours ) { printf("") } if ( doshowactualhours ) { printf("") } printf("") } printf("") printf("") printf("") printf("") printf("") printf("") printf("") if ( doshowdailyceilhours ) { printf("") } if ( doshowactualhours ) { printf("") } printf("") print "" dailyceil_grandtotal = 0 actualhours_grandtotal = 0 for ( row = 1; row <= NROWS; ++row ) { rowid = proc_order_arr[row] NCR = NCR_arr[rowid] NCRdate = NCRcreateddate_arr[NCR] ticketDesc = ticketDesc_arr[NCR] RequestedBy = RequestedBy_arr[NCR] ServiceType = ServiceType_arr[NCR] NCRthreaddate = NCRthreaddate_arr[rowid] threadtext = threadtext_arr[rowid] NCR_list_arr[NCR] = 1 hours_daily_total = hours_daily_total_arr[rowid] # ceil hours to next whole number for the day ceil_ticket_hours_for_day = ceil(hours_daily_total) # keep running totla fof dailyn ceil s for NCR daily_ceil_NCR_total_arr[NCR] += ceil_ticket_hours_for_day printf("") printf("", row) printf("", NCR) printf("", NCRthreaddate) printf("", ticketDesc) printf("", RequestedBy) printf("", ServiceType) if ( doshowdailyceilhours ) { printf("", ceil_ticket_hours_for_day) } if ( doshowactualhours ) { printf("", hours_daily_total) } printf("") print "" dailyceil_grandtotal += ceil_ticket_hours_for_day actualhours_grandtotal += hours_daily_total } if ( doshowgrandtotals ) { # Grand Total printf("") printf("", cols) printf("") printf("") printf("") printf("") printf("") printf("") printf("") printf("") if ( doshowdailyceilhours ) { printf("") } if ( doshowactualhours ) { printf("") } printf("") print "" } print "
 

%s

   
_#ReferenceDateTask DescriptionRequested ByProduct/Service TypeDaily Ceil Hours UsedHours Used
%d%s%s%s%s%s%d%0.2f

 

     Total" dailyceil_grandtotal "" actualhours_grandtotal "
" print "
" print "
" if ( doshowncrtotals ) { # NCR Totals print "" #printf("") #printf("", cols) #printf("") printf("") printf("") printf("", ADESCRIPTION) printf("") if ( doshowdailyceilhours ) { printf("") } if ( doshowactualhours ) { printf("") } printf("") printf("") printf("") printf("") printf("") printf("") printf("") printf("") if ( doshowdailyceilhours ) { printf("") } if ( doshowactualhours ) { printf("") printf("") } printf("") print "" NCRceil_grandtotal = 0 NCRactualhours_grandtotal = 0 for ( NCR in NCR_list_arr ) { NCRdate = NCRcreateddate_arr[NCR] ticketDesc = ticketDesc_arr[NCR] RequestedBy = RequestedBy_arr[NCR] ServiceType = ServiceType_arr[NCR] # total for NCR ceiled daily daily_ceil_hours_NCR_total = daily_ceil_NCR_total_arr[NCR] # ceil only for NCR hours_NCR_total = hours_NCR_total_arr[NCR] ceil_hours_NCR_total = ceil(hours_NCR_total) NCRdaily_ceil_hours_NCR_total += daily_ceil_hours_NCR_total NCRceil_grandtotal += ceil_hours_NCR_total NCRactualhours_grandtotal += hours_NCR_total printf("") printf("") printf("", NCR) printf("", NCRdate) printf("", ticketDesc) printf("", RequestedBy) printf("", ServiceType) if ( doshowdailyceilhours ) { printf("", daily_ceil_hours_NCR_total) } if ( doshowactualhours ) { printf("", hours_NCR_total) printf("", ceil_hours_NCR_total ) } printf("") print "" } if ( doshowncrgrandtotals ) { # NCR Grand Total printf("") printf("", cols) printf("") printf("") printf("") printf("") printf("") printf("") printf("") printf("") if ( doshowdailyceilhours ) { printf("") } if ( doshowactualhours ) { if ( doshowncractualgrandtotal ) { printf("") } else { printf("") } } printf("") printf("") print "" } print "

NCR Totals

 

NCR Summary Totals - %s

   
 NCRCreatedDescriptionRequested ByTypeDaily Ceil HoursHours UsedBillable Hours Used
 %s%s%s%s%s%d%0.2f%d

 

     Total" NCRdaily_ceil_hours_NCR_total "" NCRactualhours_grandtotal "" " " "" NCRceil_grandtotal "
" print "
" } } ' rm -f "$tmpfile1" 2>&1 rm -f "$tmpfile2" 2>&1 } if [ "$TIMETAG" = "ALL:" ]; then getrecontimes "Time:" "Maintenance and Support Times" getrecontimes "Quote:" "In-Scope Quote work" else getrecontimes "$TIMETAG" "Maintenance and Support Times" fi #dd=$sdd; mm=$smm; yyyy=$syyyy #while true #do # dodate="$dd/$mm/$yyyy" # tbldate=`echo $dodate | sed -e 's/\//_/g'` # cdrtable="c$tbldate" # $DODBG && echo "dodate=$dodate cdrtable=$cdrtable dd=$dd mm=$mm yyyy=$yyyy" # ############### ############### # # # increment date variables # dd=`expr $dd + 1 | awk '{printf("%02d\n",$1)}'` # if [ $dd -gt `lastdayinmonth $mm $yyyy` ]; then # dd=01 # mm=`expr $mm + 1 | awk '{printf("%02d\n",$1)}'` # if [ $mm -gt 12 ]; then # mm=01 # yyyy=`expr $yyyy + 1 | awk '{printf("%04d\n",$1)}'` # fi # fi # # # break out if we are past end date # if [ $yyyy$mm$dd -gt $eyyyy$emm$edd ]; then # break; # fi # #echo #done rm -f "$tmpfile1" rm -f "$tmpfile2" ############################### # remove lock #rm -f $LOCKFILE ############################### echo "

" echo "Done." echo "" echo "" exit 0