CFIF statements qualifying based on currentRow vs previous row value? - coldfusion

Attempting to create a page with tables on it and have ColdFusion create a new table based on a value in the returned query changing.
Data
pay_year pay_period bm_sold sales
2019 1 ABC 123
2019 1 EFG 123
2019 1 HIJ 123
<cfset prevRep="">
<cfset rowCount=#getCommReportB2Bitem.recordCount#>
<cfdump var="#rowCount#">
<cfloop query="getCommReportB2Bitem" startrow="1" endrow="#rowCount#">
<div class="contentbox">
<cfset curRep=#getCommReportB2Bitem.bm_sold#>
<cfif curRep NEQ prevRep>
<div class="panelheader"><cfoutput>B2B Report Results: Rep #getCommReportB2Bitem.bm_sold#, Pay Period #form.ppd#, #form.payyear#</cfoutput></div>
<div class="panelcontent">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="paneltable tablesorter" id="reportTable1">
<thead>
<tr>
<th class="paneltableheader">Year</th>
<th class="paneltableheader">PPD</th>
<th class="paneltableheader">BM</th>
<th class="paneltableheader">Part Div</th>
<th class="paneltableheader">Net Sales</th>
<th class="paneltableheader">Comm Rate</th>
<th class="paneltableheader">Commission</th>
</tr>
</thead>
<tbody>
<cfoutput query="getCommReportB2Bitem">
<tr>
<td class="#IIF(getCommReportB2Bitem.CurrentRow MOD 2, DE("paneltablecellodd"), DE("paneltablecell"))#">#pay_year#</td>
<td class="#IIF(getCommReportB2Bitem.CurrentRow MOD 2, DE("paneltablecellodd"), DE("paneltablecell"))#">#pay_period#</td>
<td class="#IIF(getCommReportB2Bitem.CurrentRow MOD 2, DE("paneltablecellodd"), DE("paneltablecell"))#">#UCASE(bm_sold)#</td>
<td class="#IIF(getCommReportB2Bitem.CurrentRow MOD 2, DE("paneltablecellodd"), DE("paneltablecell"))#">#part_div#</td>
<td class="#IIF(getCommReportB2Bitem.CurrentRow MOD 2, DE("paneltablecellodd"), DE("paneltablecell"))#" align="right">#DollarFormat(sales)#</td>
<td class="#IIF(getCommReportB2Bitem.CurrentRow MOD 2, DE("paneltablecellodd"), DE("paneltablecell"))#" align="right">#NumberFormat(comm_rate * 100, "99.00")#%</td>
<td class="#IIF(getCommReportB2Bitem.CurrentRow MOD 2, DE("paneltablecellodd"), DE("paneltablecell"))#" align="right">#DollarFormat(commission)#</td>
</tr>
<cfset prevRep=#bm_sold#>
</cfoutput>
</tbody>
</table>
</div>
</div>
<cfelse>
<cfoutput query="getCommReportB2Bitem">
<tr>
<td class="#IIF(getCommReportB2Bitem.CurrentRow MOD 2, DE("paneltablecellodd"), DE("paneltablecell"))#">#pay_year#</td>
<td class="#IIF(getCommReportB2Bitem.CurrentRow MOD 2, DE("paneltablecellodd"), DE("paneltablecell"))#">#pay_period#</td>
<td class="#IIF(getCommReportB2Bitem.CurrentRow MOD 2, DE("paneltablecellodd"), DE("paneltablecell"))#">#UCASE(bm_sold)#</td>
<td class="#IIF(getCommReportB2Bitem.CurrentRow MOD 2, DE("paneltablecellodd"), DE("paneltablecell"))#">#part_div#</td>
<td class="#IIF(getCommReportB2Bitem.CurrentRow MOD 2, DE("paneltablecellodd"), DE("paneltablecell"))#" align="right">#DollarFormat(sales)#</td>
<td class="#IIF(getCommReportB2Bitem.CurrentRow MOD 2, DE("paneltablecellodd"), DE("paneltablecell"))#" align="right">#NumberFormat(comm_rate * 100, "99.00")#%</td>
<td class="#IIF(getCommReportB2Bitem.CurrentRow MOD 2, DE("paneltablecellodd"), DE("paneltablecell"))#" align="right">#DollarFormat(commission)#</td>
</tr>
<cfset prevRep=#bm_sold#>
</cfoutput>
</tbody>
</table>
</div>
</div>
</cfif>
</cfloop>
Currently it appears to be looping over the query and starting new tables however after testing it seems it is outputting the first section over and over never reaching the "cfelse" as it should. Am I doing this correctly? Any better method to achieve this desired result?
EDIT -
Try to display desired output as best I can per comment.
Query data in:
pay_year pay_period bm_sold sales
2019 1 ABC 123
2019 1 EFG 789
2019 1 EFG 123
2019 1 HIJ 901
2019 1 HIJ 456
Desired Output:
BM Sold: ABC
Pay Year Pay Period Sales
2019 1 123
BM Sold: EFG
Pay Year Pay Period Sales
2019 1 789
2019 1 123
BM Sold: HIJ
Pay Year Pay Period Sales
2019 1 901
2019 1 456

Related

Conditional Printing with Netsuite Advanced PDF/HTML Template (Zero Value)

I have inherited a custom NetSuite Advanced PDF/HTML Template which is the primary default for the majority of our invoicing.
We would like to have an expenses line not print when value is $0.00. Searches online and of Stack Overflow have not provided clear direction. It appears #if/#else might be solution, but I am unclear on how to integrate into the existing code. I have some HTML/CSS experience, but am new to Freemarker.
The current code looks to wrap instructions for printing line items that are not entered as expenses within the Billable Expenses instructions?
<#if record.item?has_content>
<#assign totalBillableExpense = 0>
<table class="itemtable" style="width: 100%; margin-top: 10px;"><!-- start items -->
<#list record.item as item>
<#if item_index==0>
<thead>
<tr>
<th colspan="20" align="left">${item.description#label}</th>
<!--th align="center" colspan="3">${item.quantity#label}</th-->
<!--th align="right" colspan="4">${item.rate#label}</th-->
<th align="right" colspan="4">${item.amount#label}</th>
</tr>
</thead>
</#if>
<tr>
<#if item.custcol_ns_print_pdf?string == "Yes">
<td colspan="20">
<!--#if item.itemtype?contains("Description") || item.itemtype?contains("Subtotal")-->
<!--/#if-->
${item.description}</td>
<!--td align="center" colspan="3" line-height="150%">${item.quantity}</td-->
<!--td align="right" colspan="4">${item.rate}</td-->
<td align="right" colspan="4">${item.amount}</td>
</#if>
<#if item.description?contains("Total Billable Expenses")>
<#assign totalBillableExpense = totalBillableExpense + item.amount>
</#if>
</tr>
</#list><!-- end items -->
<tr>
<td colspan="20">Billable Expenses </td>
<td align="right" colspan="4">${totalBillableExpense?string.currency}</td>
</tr>
This might be what you are asking:
<#if totalBillableExpense gt 0>
<tr>
<td colspan="20">Billable Expenses </td>
<td align="right" colspan="4">${totalBillableExpense?string.currency}</td>
</tr>
</#if>
Also to avoid a potential issue with empty <tr/> tags you should reformulate this:
<tr>
<#if item.custcol_ns_print_pdf?string == "Yes">
....
</#if>
<#if item.description?contains("Total Billable Expenses")>
<#assign totalBillableExpense = totalBillableExpense + item.amount>
</#if>
</tr>
to something like:
<#if item.description?contains("Total Billable Expenses")>
<#assign totalBillableExpense = totalBillableExpense + item.amount>
</#if>
<#if item.custcol_ns_print_pdf?string == "Yes">
<tr>
....
</tr>
</#if>

How to output a message when query result is [empty string] in ColdFusion?

I have a query written in a stored procedure and the data is dumping just fine. Some of the results return [empty string] and in those cases, I'm trying to output a different message. Here's what I have thus far:
Looping through the query:
<cfloop query="#inactiveAdmins#">
<tr>
<td class="text-left">#Admin_Name#</td>
<td class="text-left">#Dept_Name#</td>
<td class="text-left">#Acad_Lead#</td>
<td class="text-left">#Acad_Lead_Email#</td>
<td class="text-right">#dateFormat(Last_Logon, 'mmm dd, yyyy')#</td>
</tr>
</cfloop>
At the top of the page, I'm running this cfif statement.
<cfif #inactiveAdmins.Last_Logon# eq "">
Never Logged On
<cfelse>
#inactiveAdmins.Last_Logon#
</cfif>
But, in my output, I'm still getting a display with no message.
When I try to run the condition inside the loop, I get the following:
Is this supposed to be inside your table? Make sure you wrap it inside a tr and td.
<cfloop query="#inactiveAdmins#">
<tr>
<td class="text-left">#Admin_Name#</td>
<td class="text-left">#Dept_Name#</td>
<td class="text-left">#Acad_Lead#</td>
<td class="text-left">#Acad_Lead_Email#</td>
<td class="text-right">#(Len(Last_Logon) ? dateFormat(Last_Logon, 'mmm dd, yyyy') : 'Never Logged On')#</td>
</tr>
</cfloop>
Or the long form:
<cfloop query="#inactiveAdmins#">
<tr>
<td class="text-left">#Admin_Name#</td>
<td class="text-left">#Dept_Name#</td>
<td class="text-left">#Acad_Lead#</td>
<td class="text-left">#Acad_Lead_Email#</td>
<td class="text-right">
<cfif Len(Last_Logon)>
#dateFormat(Last_Logon, 'mmm dd, yyyy')#
<cfelse>
Never Logged On
</cfif>
</td>
</tr>
</cfloop>

BeautifulSoup my for loop is printing all the data from the td tag. I would like to exclude the last section of the td tag

I have the following sample HTML table from a html file.
<table>
<tr>
<th>Class</th>
<th class="failed">Fail</th>
<th class="failed">Error</th>
<th>Skip</th>
<th>Success</th>
<th>Total</th>
</tr>
<tr>
<td>Regression_TestCase.RegressionProject_TestCase2.RegressionProject_TestCase2</td>
<td class="failed">1</td>
<td class="failed">9</td>
<td>0</td>
<td>219</td>
<td>229</td>
</tr>
<tr>
<td><strong>Total</strong></td>
<td class="failed">1</td>
<td class="failed">9</td>
<td>0</td>
<td>219</td>
<td>229</td>
</tr>
</table>
I am trying to print the text from the <td> tags where <td> starts from:
Regression_TestCase.RegressionProject_TestCase2.RegressionProject_TestCase2
I do not want to include the text from the <td> tags where <td> starts from:
<td><strong>Total</strong></td>
My code is printing the text from every single <td> tag:
def extract_data_from_report():
html_report = open(r"E:\SeleniumTestReport.html",'r').read()
soup = BeautifulSoup(html_report, "html.parser")
th = soup.find_all('th')
td = soup.find_all('td')
for item in th:
print item.text,
print "\n"
for item in td:
print item.text,
My desired output:
Class Fail Error Skip Success Total
Regression_TestCase 1 9 0 219 229
You can find all rows (tr elements) except the first one (to skip the headers) and the last one - the "total" row. Sample implementation that produces a list of dictionaries as a result:
from pprint import pprint
from bs4 import BeautifulSoup
data = """
<table>
<tr>
<th>Class</th>
<th class="failed">Fail</th>
<th class="failed">Error</th>
<th>Skip</th>
<th>Success</th>
<th>Total</th>
</tr>
<tr>
<td>Regression_TestCase.RegressionProject_TestCase2.RegressionProject_TestCase2</td>
<td class="failed">1</td>
<td class="failed">9</td>
<td>0</td>
<td>219</td>
<td>229</td>
</tr>
<tr>
<td><strong>Total</strong></td>
<td class="failed">1</td>
<td class="failed">9</td>
<td>0</td>
<td>219</td>
<td>229</td>
</tr>
</table>"""
soup = BeautifulSoup(data, "html.parser")
headers = [header.get_text(strip=True) for header in soup.find_all("th")]
rows = [dict(zip(headers, [td.get_text(strip=True) for td in row.find_all("td")]))
for row in soup.find_all("tr")[1:-1]]
pprint(rows)
Prints:
[{u'Class': u'Regression_TestCase.RegressionProject_TestCase2.RegressionProject_TestCase2',
u'Error': u'9',
u'Fail': u'1',
u'Skip': u'0',
u'Success': u'219',
u'Total': u'229'}]

get values from table with BeautifulSoup Python

I have a table where I am extracting links and text. Although I can only do one or the other. Any idea how to get both?
Essentially I need to pull the text: "TEXT TO EXTRACT HERE"
for tr in rows:
cols = tr.findAll('td')
count = len(cols)
if len(cols) >1:
third_column = tr.findAll('td')[2].contents
third_column_text = str(third_column)
third_columnSoup = BeautifulSoup(third_column_text)
#issue starts here. How can I get either the text of the elm <td>text here</td> or the href texttext here
for elm in third_columnSoup.findAll("a"):
#print elm.text, third_columnSoup
item = { "code": random.upper(),
"name": elm.text }
items.insert(item )
The HTML Code is the following
<table cellpadding="2" cellspacing="0" id="ListResults">
<tbody>
<tr class="even">
<td colspan="4">sort results: <a href=
"/~/search/af.aspx?some=LOL&Category=All&Page=0&string=&s=a"
rel="nofollow" title=
"sort results in alphabetical order">alphabetical</a> | <strong>rank</strong> ?</td>
</tr>
<tr class="even">
<th>aaa</th>
<th>vvv.</th>
<th>gdfgd</th>
<td></td>
</tr>
<tr class="odd">
<td align="right" width="32">******</td>
<td nowrap width="60"><a href="/aaa.html" title=
"More info and direct link for this meaning...">AAA</a></td>
<td>TEXT TO EXTRACT HERE</td>
<td width="24"></td>
</tr>
<tr class="even">
<td align="right" width="32">******</td>
<td nowrap width="60"><a href="/someLink.html"
title="More info and direct link for this meaning...">AAA</a></td>
<td><a href=
"http://www.fdssfdfdsa.com/aaa">TEXT TO EXTRACT HERE</a></td>
<td width="24">
<a href=
"/~/search/google.aspx?q=lhfjl&f=a&cx=partner-pub-2259206618774155:1712475319&cof=FORID:10&ie=UTF-8"><img border="0"
height="21" src="/~/st/i/find2.gif" width="21"></a>
</td>
</tr>
<tr>
<td width="24"></td>
</tr>
<tr>
<td align="center" colspan="4" style="padding-top:6pt">
<b>Note:</b> We have 5575 other definitions for <strong><a href=
"http://www.ddfsadfsa.com/aaa.html">aaa</a></strong> in our
database</td>
</tr>
</tbody>
</table>
You can just use the text property on a td element:
from bs4 import BeautifulSoup
html = """HERE GOES THE HTML"""
soup = BeautifulSoup(html, 'html.parser')
for tr in soup.find_all('tr'):
columns = tr.find_all('td')
if len(columns) > 2:
print columns[2].text
prints:
TEXT TO EXTRACT HERE
TEXT TO EXTRACT HERE
Hope that helps.
The way to do it is by doing the following:
third_column = tr.find_all('td')[2].contents
third_column_text = str(third_column)
third_columnSoup = BeautifulSoup(third_column_text)
if third_columnSoup:
print third_columnSoup.text

JQuery - Problem with selectors (siblings, parents...)

I got a coldfusion query where the result is grouped on country names. With a click on this one, I try to open or close the list under the country. But i cannot work correctly with this siblings and this parents. The result is, if i click on a country name, the fourth one, for example, it close all childrens, and the three country name which are before too.
Can someone help me to choose the right selectors ?
Thank you in advance ,
Michel
The code:
<script type="text/javascript" language="javascript">
$(document).ready(function(){
var toggleMinus = '<cfoutput>#variables.strWebAddress#</cfoutput>/images/bullet_toggle_minus.png';
var togglePlus = '<cfoutput>#variables.strWebAddress#</cfoutput>/images/bullet_toggle_plus.png';
var $subHead = $('table#categorylist tbody th:first-child');
$subHead.prepend('<img src="' +toggleMinus+ '" alt="collapse this section" /> ');
$('img', $subHead).addClass('clickable').click(function(){
var toggleSrc = $(this).attr('src');
if(toggleSrc == toggleMinus){
$(this).attr('src',togglePlus).parents('.country').siblings().fadeOut('fast');
}else{
$(this).attr('src',toggleMinus).parents('.country').siblings().fadeIn('fast');
}
});
});
</script>
<table width="95%" border="0" cellspacing="2" cellpadding="2" align="center id="categorylist">
<thead>
<tr>
<th class="text3" width="15%">
<cfmodule template="../custom_tags/get_message.cfm" keyName="L_ACTOR_CODENUMBER">
</th>
<th class="text3" width="15%">
<cfmodule template="../custom_tags/get_message.cfm" keyName="L_ACTOR_CODE">
</th>
<th class="text3" width="55%">
<cfmodule template="../custom_tags/get_message.cfm" keyName="L_ACTOR_NAME">
</th>
<th class="text3" width="15%">
<cfmodule template="../custom_tags/get_message.cfm" keyName="L_ACTIVE">
</th>
</tr>
</thead>
<tbody id="content">
<cfoutput query="qryCategoryUrl" group="country_name" groupcasesensitive="false">
<tr class="country">
<th style="font-weight:bold; text-align:left;" colspan="4">#country_name#</th>
</tr>
<cfoutput>
<tr>
<td valign="top" class="text3">#Replace(ACTOR_CODENUMBER, Chr(13) & Chr(10), "<br>", "ALL")# </td>
<td valign="top" class="text3">#Replace(ACTOR_CODE, Chr(13) & Chr(10), "<br>", "ALL")# </td>
<td valign="top" class="text3">#Replace(ACTOR_NAME, Chr(13) & Chr(10), "<br>", "ALL")# </td>
<td valign="top" class="text3"><cfmodule template="../custom_tags//get_message.cfm" keyName="#ACTIVE_display(qryCategoryUrl.ACTIVE)#"></td>
</tr>
</cfoutput>
</cfoutput>
</tbody>
</table>
Instead of:
.parents('.country').siblings().fadeOut('fast');
Try this:
.closest('.country').nextUntil('.country').fadeOut('fast');
And of course, apply the same change to the .fadeIn(). You might also look into .fadeToggle()docs.
Here's a (reduced) example: http://jsfiddle.net/redler/5sqJz/. While it doesn't affect the example, presumably you would be setting the initial state of those detail rows as hidden.
woah all that cfmodule usage, cfmodule can be a memory hog.
Although what I always recommend is that people try their pages in whatever browser, and use the SelectorGadget bookmarklet at http://www.selectorgadget.com/
This makes it easier to test and check the correct selector, for your app needs.