Cell color based on Status in HTML output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cell color based on Status in HTML output
# 1  
Old 02-12-2018
Cell color based on Status in HTML output

Hi,

I need to get the Status Column in Green if it is approved and Red if it is declined in the HTML output attachment
Code:
#!/bin/bash
 body_csv="/authlistener/ProdA/service/queryRS.csv"
body_html="/authlistener/ProdA/service/queryRS.html"
 attach_csv="/authlistener/ProdA/service/attchment.csv"
attach_html="/authlistener/ProdA/service/attachment.html"
from="venkata.maddela@cgi.com"
to="venkata.maddela@cgi.com"
subject="Monthly Invoice"
boundary="ZZ_/afg6432dfgkl.94531q"
QUERY="SELECT DECODE(SUBSTR(TRAN.iin,5,2),'25','34',mbr.mbr_no) Country_No,
       DECODE(SUBSTR(TRAN.iin,5,2),'25','Hungary',mbr.name) Country_Name,
    CASE TRAN.DENY_fLAG
    WHEN 'N' THEN 'Approved'
    ELSE 'Declined'
   END Status,
     SUM (TRAN.TRAN_AMOUNT) TOTAL_AMOUNT, COUNT(*) TOTALTRANSACTIONS
     FROM TRAN
     LEFT OUTER JOIN MBR ON substr(TRAN.iin,5,2)    = (MBR.mbr_no)
     LEFT OUTER JOIN CONDITION ON TRAN.CONDITION_ID = condition.condition_id
         WHERE POST_DATE BETWEEN  TO_DATE('20170601', 'yyyymmdd')
      AND  TO_DATE('20170630', 'yyyymmdd')
      AND  TRAN.post_ts  BETWEEN TO_DATE('01 JUN 2017 00:00:00', 'DD MON YYYY HH24:MI:SS') AND TO_DATE('30 JUN 2017 23:59:59', 'DD MON YYYY HH24:MI:SS')
     GROUP BY DECODE(SUBSTR(TRAN.iin,5,2),'25','34',mbr.mbr_no),
                  DECODE(SUBSTR(TRAN.iin,5,2),'25','Hungary',mbr.name),
                          TRAN.DENY_fLAG
         ORDER BY Country_Name;"
 ATT_QUERY="SELECT DECODE(SUBSTR(TRAN.iin,5,2),'25','34',mbr.mbr_no) Country_No,
       DECODE(SUBSTR(TRAN.iin,5,2),'25','Hungary',mbr.name) Country_Name,
    CASE TRAN.DENY_fLAG
    WHEN 'N' THEN 'Approved'
    ELSE 'Declined'
   END Status,
     SUM (TRAN.TRAN_AMOUNT) TOTAL_AMOUNT, COUNT(*) TOTALTRANSACTIONS
     FROM TRAN
     LEFT OUTER JOIN MBR ON substr(TRAN.iin,5,2)    = (MBR.mbr_no)
     LEFT OUTER JOIN CONDITION ON TRAN.CONDITION_ID = condition.condition_id
         WHERE POST_DATE BETWEEN  TO_DATE('20170601', 'yyyymmdd')
      AND  TO_DATE('20170630', 'yyyymmdd')
      AND  TRAN.post_ts  BETWEEN TO_DATE('01 JUN 2017 00:00:00', 'DD MON YYYY HH24:MI:SS') AND TO_DATE('30 JUN 2017 23:59:59', 'DD MON YYYY HH24:MI:SS')
     GROUP BY DECODE(SUBSTR(TRAN.iin,5,2),'25','34',mbr.mbr_no),
                  DECODE(SUBSTR(TRAN.iin,5,2),'25','Hungary',mbr.name),
                          TRAN.DENY_fLAG
         ORDER BY Country_Name;"
  
 CON_STRING="atlas/atlas@atlasprd"
 cat > $body_html <<EOF
<!doctype html public .-//w3c//dtd html 4.0 transitional//en.>
<html>
<head>
<style>
table {
    border: 1px solid black;
    border-collapse: collapse;
}
th, td {
    text-align: left;
    padding: 8px;
}
tr:nth-child(even){background-color: #f2f2f2}
th {
if(document.getElementById("STATUS").value='APPROVED'){
    background-color: #4CAF50
        }else{
        background-color: red
        }
    color: white;
}
</style>
</head>
<body>
<p><b>Dear Cindy/Candy,</b></p>
<p>Please find the attached report</p>
EOF
 cat > $attach_html <<EOF
<!doctype html public .-//w3c//dtd html 4.0 transitional//en.>
<html>
<head>
<style>
table {
    border: 1px solid black;
    border-collapse: collapse;
}
th, td {
    text-align: left;
    padding: 8px;
}
tr:nth-child(even){background-color: #f2f2f2}
th {
if(document.getElementById("STATUS").value='APPROVED'){
    background-color: #4CAF50
        }else{
        background-color: red
        }
    color: white;
}
</style>
</head>
<body>
EOF
 getResultSet()
{
sqlplus -s $CON_STRING <<EOF
set term off
set echo off
set underline off
set pagesize 0
set sqlprompt "
set lines 1000 pages 1000
set linesize 1000
set colsep ","
set trimspool on
set heading on
set newpage 0
set headsep off
set feedback off
spool $1
$QUERY
spool off
EOF
}
 getAttachmentResult()
{
sqlplus -s $CON_STRING <<EOF
set term off
set echo off
set underline off
set pagesize 0
set sqlprompt "
set lines 1000 pages 1000
set linesize 1000
set colsep ","
set trimspool on
set heading on
set newpage 0
set headsep off
set feedback off
spool $1
$ATT_QUERY
spool off
EOF
}
 
convertCSV2HTML()
{
[ "$#" -ne 1 ] && exit -1
 file=$1
 echo "<table border=1>"
head -n 1 $file | \
    sed -e 's/^/<tr><th>/' -e 's/,/<\/th><th>/g' -e 's/$/<\/th><\/tr>/'
tail -n +2 $file | \
    sed -e 's/^/<tr><td>/' -e 's/,/<\/td><td>/g' -e 's/$/<\/td><\/tr>/'
echo "</table>"
}
 #trigger SQL Script
getResultSet $body_csv
getAttachmentResult $attach_csv
 #Converting CSV to HTML Table format
convertCSV2HTML $body_csv >> $body_html
convertCSV2HTML $attach_csv >> $attach_html
 body=`cat $body_html`
 get_mimetype(){
  file --mime "$1" | sed 's/.*: //'
}
 sendWithAttachment()
{
declare -a attachments
attachments=( "$1" )
{
printf '%s\n' "From: $from
To: $to
Subject: $subject
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary=\"$boundary\"
 --${boundary}
Content-Type: text/html; charset=\"US-ASCII\"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
 $body
"
for file in "${attachments[@]}"; do
   [ ! -f "$file" ] && echo "Warning: attachment $file not found, skipping" >&2 && continue
   mimetype=$(get_mimetype "$file")
   printf '%s\n' "--${boundary}
Content-Type: $mimetype
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=\"$file\"
"
  base64 "$file"
  echo
done
 printf '%s\n' "--${boundary}--"
 } | sendmail -t -oi   #to send email with attachment as html
}
sendWithAttachment $attach_html
rm $body_csv
rm $body_html
rm $attach_csv
rm $attach_html

.

thanks in advance.

Reagards,
Vamsi.
# 2  
Old 02-12-2018
Just use some logic (if statement) and CSS.
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with awk color codes based on condition

HI i have two files say test and test1 Test.txt Code: Lun01 2TB 1.99TB 99.6% Lun02 2TB 1.99TB 99.5% Lun03 2TB 1.99TB 99.5% Lun04 2TB 1.55TB 89.6% Code: Test1.txt Lun01 2TB 1.99TB 89.5% Lun02 2TB 1.99TB 99.5% Lun03 2TB 1.99TB 99.5% Requirement is to compare... (6 Replies)
Discussion started by: venkitesh
6 Replies

2. UNIX for Beginners Questions & Answers

HTML color code and tabluar issue

input data in a file servic webservice.somthing 200 OK servic1 webservice.somthing 200 OK servic1 webservice.somthing 400 BAD REQEST Below script is making tabular form perfectly. but there are two thing i am not able to achive 1.how can i color the complete row as red when it see '400' in... (12 Replies)
Discussion started by: mirwasim
12 Replies

3. Shell Programming and Scripting

Parse excel file with html on each cell

<DIV><P>Pré-condição aceder ao ecrã Home do MRS.</P></DIV><DIV><P>OK.</P></DIV><DIV><P>Seleccionar Pesquisa de Recepção Directa.</P></DIV><DIV><P>Confirmar que abriu ecrã de Recepção Directa.</P></DIV><DIV> (6 Replies)
Discussion started by: oliveiraum
6 Replies

4. Shell Programming and Scripting

Add Color To html Doc

I have a script which converts a .csv file to html nicely. Trying to add 3 colors, green, yellow and red to the output depending upon the values in the cells. Tried some printf command but just can't seem to get any where. Any ideas would be appreciated. nawk 'BEGIN{ FS="," print ... (7 Replies)
Discussion started by: jimmyf
7 Replies

5. Shell Programming and Scripting

Color line based on first field

Hello, I have a bash script that outputs the following text to a file and then prints that file to the screen: |64 |30 |0 |8 |23:59:14 |38 |57 |2 |14 |00:09:05 |29 |50 |4 |20 |23:58:04 |20 |48 |7 |23 |00:05:44 |18 ... (2 Replies)
Discussion started by: fnj00
2 Replies

6. Shell Programming and Scripting

.bashrc/PS1 command color different color to command output

I have been configuring my .bashrc PS1 to be displayed with some nice colors and in a format that I like, however there is one thing that I cannot figure out (or know if it's even possible). my PS1 line is as follows: export PS1='\\u\@\\h\:\\w\n\\$ \'This makes the command and command output... (0 Replies)
Discussion started by: jelloir
0 Replies

7. Shell Programming and Scripting

get output in each cell from shell script

Hi, I have a code which gives me different values all in a same line. what do i change to make the output have each value in each cell. code: echo $user $firstname $lastname $address done | tee userinfo.xls i want the $user value to be in first cell of excel, $firstname in the... (3 Replies)
Discussion started by: sophos
3 Replies
Login or Register to Ask a Question