NetSuite - Saved Search formula for calculating percentage from summary Total - saved-searches

I would like to create a Saved Search in NetSuite that returns the percentage of Quotation in a specific month. I have achieved month wise count of quotation and in summary total is also showing as a year, I want to calculate monthly percentage based yearly total in another column. enter image description here
enter image description here

I'm afraid the only way to do this is Client side.
if (!window.hereFirst) {
window.hereFirst = true;
window.addEventListener(`load`, (e) => {
let rcs = Array.from(document.querySelectorAll(`[row-count]`));
let tc = rcs.reduce((t, r) => t + Number(r.getAttribute(`row-count`)), 0);
rcs.forEach(r => {
let rp = r.parentElement;
rp.textContent = ((Number(r.getAttribute(`row-count`)) / tc) * 100)
.toFixed(1) + `%`;
rp.classList.add(`listtextrt`);
});
});
}
this goes into an html image onload event.
and produces
Minimum of Formula (Text):
'<img style="display: none;" row-count="'||COUNT(DISTINCT {number})||'" src="/core/media/media.nl?id=#&c=#&h=..." onload="if (!window.hereFirst) { window.hereFirst = true; window.addEventListener(`load`,(e) => { let rcs = Array.from(document.querySelectorAll(`[row-count]`)); let tc = rcs.reduce((t,r) => t+Number(r.getAttribute(`row-count`)),0); rcs.forEach(r => { let rp = r.parentElement; rp.textContent = ((Number(r.getAttribute(`row-count`))/tc)*100).toFixed(1)+`%`; rp.classList.add(`listtextrt`); }); }); }">'
I use my company's logo for the image since the browser is already loading and caching it.

Related

Apps Script Google Sheets Birthday Reminder Range in Array

I'm trying to write an automatic birthday reminder for my team.
It's supposed to check if a persons birthday is today and if so, send a mail to everyone else in the team.
In Google Sheets, the four columns are: name, surname, e-mail and birthday. First row are headers.
This is what I got so far (mostly copied):
`
function main() {
// Load the sheet that contains the birthdays.
var sheet = SpreadsheetApp.getActive().getSheetByName("Geburtstage");
// Get the last row in the sheet that has data.
var numRows = sheet.getLastRow();
// Load data in the first two columns from the second row till the last row.
// Remember: The first row has column headers so we don’t want to load it.
var range = sheet.getRange(2, 1, numRows - 1, 4).getValues();
// Use a for loop to process each row of data
for(var index in range) {
// For each row, get the person’s name and their birthday
var row = range[index];
var name = row[0];
var birthday = row[3];
// Check if the person’s birthday is today
if(isBirthdayToday(birthday)) {
//If yes, send an email reminder
emailReminder(name);
}
}
}
// Check if a person’s birthday is today
function isBirthdayToday(birthday) {
var today = new Date();
if((today.getDate() === birthday.getDate()) &&
(today.getMonth() === birthday.getMonth())) {
return true;
} else {
return false;
}
}
// Function to send the email reminder
function emailReminder(name) {
var subject = "Geburtstagerinnerung: " + name;
var recipient = Session.getActiveUser().getEmail();
var body = name + " hat heute Geburtstag!";
MailApp.sendEmail(recipient, subject, body);
}
`
All that is missing is to replace the recipient by all e-mails in the third column, except for the person whos birthday it is.
My idea is, to save the range of the third column (e-mails) to an array, drop the e-mail whos birthday it is, and pass it to recipient as a comma separated string.
Afterwards reset the array in case two people have the same birthday.
My problem is, that I have no idea what I'm doing and all the solutions I found are overly complicated.
Try this:
function main() {
const dt = new Date();
const dtv = new Date(dt.getFullYear(),dt.getMonth(),dt.getDate()).valueOf();
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName("Sheet0");
const vs = sh.getRange(2, 1, sh.getLastRow() - 1, 4).getValues();
let recipients;
vs.forEach((R,i) => {
let d = new Date(R[3]);
let dv = new Date(d.getFullYear(),d.getMonth(),d.getDate()).valueOf();
if(dv == dtv) {
recipients = vs.filter((r,j) => j != i ).map( r => r[2]).flat().join(",")
GmailApp.sendEmail(recipients,`Todays ${R[0]} Birthday`,"");
}
});
}

material-table: How to make a summary row?

How can I make a summary row like this using a material table?
Please help me, thank you.
If by "Summary row" you're referring to table title, that's a prop "title" you just add to the <MaterialTable /> component.
However, I suspect you need the row with Total result, which I couldn't find in the examples, either.
Here's a custom function you could use to calculate a total by your own, add it to your data set and achieve similar result:
const addTotal = (data, byColumn) => {
let keys = Object.keys(data[0]);
let total = data.reduce((acc, el) => {
return acc += +(el[byColumn]);
}, 0);
let totalRow = {};
let emptyRow = {};
for (let key of keys) {
if (key === keys[0]) {
totalRow[key] = 'Total';
} else if (key === byColumn) {
totalRow[key] = total;
} else {
totalRow[key] = '';
}
emptyRow[key] = '';
}
return [...data, emptyRow, totalRow];
}
This will add an empty row and a total with the argument you put as byColumn. You need to be careful about the values you are summing (i.e. add type checking or validate the column name with hasOwnProperty).
I might be a little late, but here’s another question that reminded me that material table happen to have a footer row api.
You can use it alongside a specific method to sum values (or else) that you can call before setting the datasource for example, or on demand.

Unable to fetch the value of an element in protractor

For one of my protractor script. I want to fetch the value of an element.
Here is the DOM setup:
<h5 class="ng-binding ng-scope" ng-if="editor.special.stock_number !== ''">
<b>Stock Number:</b>
72850
</h5>
I want to fetch the value of Stock Number:
I tried using getText, but it just printed out the Stock Number:
this.get_stock_number = () => {
let stockNumber = stock_number.getText();
stockNumber.then((text) => {
console.log("Stock Number is: " + text);
});
};
I also tried using getAttribute but it is returning null:
this.get_stock_number = () => {
let stockNumber = stock_number.getAttribute('Stock Number:');
stockNumber.then((text) => {
console.log("Stock Number is: " + text);
});
};
I really need this thing to be sorted out. I am kind of stuck here.
Any help will be much appreciated, Thanks.
You can try:
Locate the h5 element with the whole text and extract it
h5element.getText()
so it can return Ex:
<b>Stock Number:</b> 72850
After that just extract the number from the string with regex
let text = `<b>dsadsad</b> 320301`;
let numberPattern = /\d+/g;
let results = text.match(numberPattern);
if (results != null) {
let number = results[0];
console.log(number);
}

How to display time ago when specific table columns updated?

I want to show the time ago when the latitude and longitude last updated in my table.
My code currently shows the time ago of last update (through web
socket). It doesn't show the time ago that the latitude or longitude specifically were updated. How can I solve this? Here is a screen-shot of the table, and the code is below:
componentDidMount() {
let socket = new WebSocket('ws://139.162.2.53:9988');
this.setState({ socket: socket });
this.getSupportInfo();
socket.onmessage = ((message) => {
let socketData = JSON.parse(message.data);
//console.log(socketData[0] );
let device_id = socketData[0].device_id;
let updatedSupportInfo = this.state.supportInfo;
let now = new Date();
let uSupport = updatedSupportInfo.map(function(item){
if(device_id == item.device_id){
// console.log(item);
item.current_pos = socketData[0].current_pos;
item["latlng"] = item.current_pos.x + ',' + item.current_pos.y;
let time = new Date(socketData[0].timestamp)
let a = moment(time);
let b = moment(now);
//let timeAgo = a.from(b);
let timeAgo = b.diff(a, 'minutes')
//console.log("a", a);
//console.log("b", b);
//console.log("timeAgo", timeAgo);
item["timeAgo"] = timeAgo;
}
return item;
});
this.setState({supportInfo:uSupport})
});
}
I am using react bootstrap table:
<TableHeaderColumn dataField="timeAgo" dataSort={true}>Time Ago(mins)</TableHeaderColumn>

How to modify the label of Category Field in amCharts

I am using amCharts in my AngularJS application and I am looking for a way to rename the label of the category field. Following is my code:
var configChart = function () {
employeeChart = new AmCharts.AmSerialChart();
employeeChart.categoryField = "empId";
var yAxis = new AmCharts.ValueAxis();
yAxis.position = "left";
employeeChart.addValueAxis(yAxis);
mcfBarGraph = new AmCharts.AmGraph();
mcfBarGraph.valueField = "employeeRating";
mcfBarGraph.type = "column";
mcfBarGraph.fillAlphas = 1;
mcfBarGraph.lineColor = "#f0ab00";
mcfBarGraph.valueAxis = yAxis;
employeeChart.addGraph(empBarGraph);
employeeChart.write('employee');
}
In the above coode if you observe the categoryField is empId so on the x-axis it shows employee Id's, I want to make it "dept-empId". For example if the department number is 1, on the x-axis it show display 1-1,1-2 etc. The department Id is not in the data provider but is one of the scope variables in my controller. Could you let me know how I could achieve this.
You can define a labelFunction in your chart object's categoryAxis to get the formatting you want.
var categoryAxis = employeeChart.categoryAxis;
categoryAxis.labelFunction = function(valueText) {
return dept + '-' + valueText;
};
Here's a fiddle that uses your setup with some dummy data to illustrate this: https://jsfiddle.net/by7grqjm/2/

Resources