GSheet Appscript unsuccessful loops output - loops

I successfully created two functions which are to build data report in my template based on a certain data (invoice) and to auto-download the report as a PDF file.
But when I tried to loop those functions because I have many invoices to be downloaded as pdf files. This is my function:
function downloadNota() {
var ws = SpreadsheetApp.getActiveSpreadsheet();
var xs = ws.getSheetByName('Print Nota');
var lr = xs.getLastRow();
var nota = xs.getRange('B2:B' + lr).getValues();
var number = nota.map(function (r) { return r.toString().replace('\[ | \]', '') });
number.forEach(function (invoice) {
printInvoice(+invoice)
});
downloadPdf(noInvoice)
}
But when I run the function, data in the template become blank (image attached).
Here is my function to fill the data in my template:
function printInvoice(noInvoice) {
var ws = SpreadsheetApp.getActiveSpreadsheet();
var ss = ws.getSheetByName('NOTA INVOICE2');
var dd = ws.getSheetByName('GABUNGAN');
ss.getRange('B10').setValue(noInvoice);
ss.getRange('A14:G120').activate();
ss.getActiveRangeList().clear({ contentsOnly: true, skipFilteredRows: true })
.setBackground(null)
.setBorder(false, false, false, false, false, false)
.setFontWeight(null)
.setFontColor(null)
.breakApart();
var allData = dd.getRange('A5:S').getValues();
var dataString = allData.filter(String);
var listData = dataString.map(function (r) { return r; });
var neededData = listData.filter(listData => listData[2] === noInvoice);
var nData = neededData.length;
var data = [];
if (!neededData) return;
for (var i = 0; i < nData; i++) {
newData = [neededData[i][5], neededData[i][6], neededData[i][8], neededData[i][9], neededData[i][7], (neededData[i][8] - neededData[i][9]) * neededData[i][7]];
data.push(newData);
}
ss.getRange(14, 6, nData, 2).mergeAcross();
ss.getRange(14, 1, nData, 7).activate();
ss.getActiveRangeList()
.setBorder(true, true, true, true, true, true, '#000000', SpreadsheetApp.BorderStyle.SOLID)
ss.getRange(14, 1, nData + 8, 7).activate();
ss.getActiveRangeList()
.setHorizontalAlignment("right");
ss.getRange(14, 1, nData, 2).activate();
ss.getActiveRangeList()
.setHorizontalAlignment("center");
ss.getRange(14, 5, nData, 1).activate();
ss.getActiveRangeList()
.setHorizontalAlignment("center");
ss.getRange(14 + nData + 1, 2, 4, 1).activate();
ss.getActiveRangeList()
.setHorizontalAlignment("left");
ss.getRange(14 + nData + 5, 1, 1, 7).activate();
ss.getActiveRangeList().setBorder(true, false, false, false, false, false, '#000000', SpreadsheetApp.BorderStyle.SOLID);
ss.getRange(14, 1, nData, 6).setValues(data);
ss.getRange(14 + nData + 2, 1).setValue('Status Pengiriman:');
ss.getRange(14 + nData + 2, 2).setValue('SUDAH DIKIRIM');
ss.getRange(14 + nData + 3, 1).setValue('Status Pembayaran:');
ss.getRange(14 + nData + 3, 2).setValue('PAID');
ss.getRange(14 + nData + 1, 6).setValue('SUBTOTAL :');
ss.getRange(14 + nData + 1, 7).setFormulaR1C1("=SUM(R[-2]C[-1]:R[-" + (nData + 1) + "]C[-1])");
ss.getRange(14 + nData + 2, 6).setValue('DPP :');
ss.getRange(14 + nData + 2, 7).setFormula('=VLOOKUP(B10,{GABUNGAN!C5:C,GABUNGAN!Q5:Q},2,false)');
ss.getRange(14 + nData + 3, 6).setValue('PPN (11%) :');
ss.getRange(14 + nData + 3, 7).setFormula('=VLOOKUP(B10,{GABUNGAN!C5:C,GABUNGAN!R5:R},2,false)');
ss.getRange(14 + nData + 4, 6).setValue('BIAYA PENGIRIMAN :');
ss.getRange(14 + nData + 4, 7).setFormula('=VLOOKUP(B10,{GABUNGAN!C5:C,GABUNGAN!N5:N},2,false)');
ss.getRange(14 + nData + 5, 6).setValue('GRAND TOTAL :');
ss.getRange(14 + nData + 5, 7).setFormulaR1C1("=SUM(R[-2]C[0]:R[-4]C[0])");
ss.getRange('B10').activate();
}
Here is what I hope to get as a PDF file downloaded:

Rewrite the entire function without using activeRange or activate().
exp :
ss.getRange(14, 1, nData + 8, 7).activate();
ss.getActiveRangeList()
.setHorizontalAlignment("right");
REWRITE
var a = ss.getRange(14, 1, nData + 8, 7);
a.setHorizontalAlignment("right");

Related

How do I get the camera to focus on the object and keep it in center focus using Babylonjs?

What I really want is to put the mesh on the object and have the camera focus on that mesh. I think they do this with the lookAt function, but I don't know how to use it correctly.
I got help from this page : https://www.babylonjs-playground.com/#1CSVHO#12
I tried some function demos.
setCamera_Mesh = () => {
let { currentWidth, currentDepth, rowCount } = this.currentConfig;
let sphere = Mesh.CreateSphere("sphere", 1, this.scene);
let referenceBox = Mesh.CreateBox("referenceBox", { width: 1, height: 1, depth: 1, updatable: true });
sphere.scaling = new Vector3(0.1, 0.1, 0.1);
sphere.position = this.scene.cameras[0].position;
sphere.parent = this.scene.cameras[0];
this.referenceBox && this.referenceBox.dispose()
referenceBox.position = new Vector3(0, 0, 0.08);
referenceBox.enableEdgesRendering();
referenceBox.edgesWidth = 1;
referenceBox.edgesColor = new Color4(0, 0, 1, 0.05);
referenceBox.visibility = 0.5;
referenceBox.scaling = new Vector3(currentDepth / 40, rowCount / 3, currentWidth / 100);
this.referenceBox = referenceBox;
sphere.lookAt(referenceBox.position);
}
I had to use setParent () instead of .parent where I added the camera as parent.
When I edit the code as below, it worked correctly.
setCameraToMesh = () => {
let { currentWidth, currentDepth, rowCount } = this.currentConfig;
let sphere = MeshBuilder.CreateSphere("referenceSphere", this.scene);
let referenceBox = MeshBuilder.CreateBox("referenceBox", { width: 0.1, height: 0.1, depth: 0.1, updatable: true });
sphere.scaling = new Vector3(0.1, 0.1, 0.1);
sphere.position = this.scene.cameras[0].position;
sphere.setParent(this.scene.cameras[0]);
this.referenceBox && this.referenceBox.dispose()
referenceBox.position = new Vector3(0, rowCount / 500, 0.08);
referenceBox.enableEdgesRendering();
referenceBox.edgesWidth = 1;
referenceBox.edgesColor = new Color4(0, 0, 1, 0.05);
referenceBox.visibility = 0.05;
referenceBox.scaling = new Vector3(currentDepth / 40, rowCount / 3, currentWidth / 100);
this.referenceBox = referenceBox;
sphere.lookAt(referenceBox.absolutePosition);
this.scene.cameras[0].focusOn([referenceBox], true);
}

React Native dynamically adjustable Pie Chart

I'm building a react native app where the user should be able to move an adjuster around a pie chart to adjust the start and end angles of the pie slices. I'm using 3 panResponders and used the idea by /users/681830/val:
react native circle transform translate animation
I'm calculating the shortest distance to either of the 36 snapshots then set the animated value to that point however it is super inefficient and laggy. Can anyone suggest any better performing solution?
'''
this._panResponder1 = PanResponder.create(
{
onStartShouldSetPanResponder: (evt, gesture) =>true,
onPanResponderMove: (evt, gesture) => {
//we need the distance between the points and get the index of the minimum distance
distances = [];
for(var i = 0; i < 36; i++){
var a = this.outputRangeX[i] - gesture.moveX;
var b = this.outputRangeY[i] - gesture.moveY + 120;
distances.push(Math.sqrt(a*a + b*b));
}
var minInd = distances.indexOf(Math.min(...distances));
this.setState({indexOfAdj1 : minInd});
this.adj1Anim.setValue((1/36)* minInd);
var isPos1 = minInd/36;
var isPos2 = (minInd)/36;
if(minInd>24){
isPos1 = -1 * ((36-minInd)/36);
isPos2 = minInd/36;
this.setState({data: [
{
number: 1,
startAngle: isPos1* Math.PI * 2,
endAngle: this.state.data[0].endAngle,
},
{
number: 30,
startAngle: this.state.data[1].startAngle,
endAngle: this.state.data[1].endAngle,
},
{
number: 1,
startAngle: this.state.data[1].endAngle,
endAngle: isPos2* Math.PI * 2,
},
]});
}else{
this.setState({data: [
{
number: 1,
startAngle: isPos1* Math.PI * 2,
endAngle: this.state.data[0].endAngle,
},
{
number: 30,
startAngle: this.state.data[1].startAngle,
endAngle: this.state.data[1].endAngle,
},
{
number: 1,
startAngle: -((Math.PI * 2)-this.state.data[1].endAngle),
endAngle: isPos2* Math.PI * 2,
},
]});
}
}
'''

Charts do not render unless I reroute to another page and go back to my charts route

I am working on dashboard chart. I am using chartjs for my charts and angularjs http.get method to get data from the server to my charts. I checked the console and the data is loaded and working properly, but the charts won't render unless I reroute to another page and then go back to my charts route page.
This is the code:
$scope.tripTotalts = "";
$scope.tripdstatus = "";
$scope.tripddstatus = "";
$scope.tripcstatus = "";
$scope.totalshow = "";
$scope.tripStatus = function() {
$http.get("/api/statusDispatched").success(function(response) {
dispatched = response;
$scope.tripdstatus = response[0];
});
$http.get("/api/statusDelivered").success(function(response) {
delivered = response;
$scope.tripddstatus = response[0];
});
$http.get("/api/totalTripsintheSystem").success(function(response) {
$scope.tripTotalts = response[0];
totalFleetTrips = response[0];
});
$http.get("/api/statusCompleted").success(function(response) {
completed = response;
$scope.tripcstatus = response[0];
});
$scope.totalshow = Math.round(((dispatched+delivered+completed) / totalFleetTrips) * 100)
console.log("CHECKOUT HERE");
console.log(dispatched);
console.log(delivered);
console.log(completed);
var tstatid = $("#tstatusChart");
tstatid.attr('height', 100);
var tripsatusChartInitiate = new Chart(tstatid, {
type: 'pie',
data: {
datasets: [{
data: [dispatched, delivered, completed],
backgroundColor: [
"rgba(" + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + ", 1)",
"rgba(" + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + ", 1)",
"rgba(" + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + ", 1)"
],
borderColor: [
"rgba(" + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + ", 1)",
"rgba(" + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + ", 1)",
"rgba(" + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + ", 1)"
], borderWidth: 1
}],
labels: ["Dispatched", "Delivered", "Completed"]
},
options: {
tooltips: {
callbacks: {
label: function(tooltipItem, data) {
var allData = data.datasets[tooltipItem.datasetIndex].data;
var tooltipLabel = data.labels[tooltipItem.index];
var tooltipData = allData[tooltipItem.index];
var total = 0;
for (var i in allData) {
total += allData[i];
}
var tooltipPercentage = Math.round((tooltipData / total) * 100);
return '[Day: ' +tooltipLabel + '] Data: ' + tooltipData + ' [Percentage: ' + tooltipPercentage + '%]';
}
}
},
animation: {
duration: 0
}
}
});
}

Openseadragon - Custom Tiles, there is navigator do not showing the image

i am using OpenSeaDragon, there is Customtiles to showup the images, i can not see the the image exactly for the navigation... please check the issue for the screenshot : http://screencast.com/t/BeP6nyA6M
The code is here :
<script type="text/javascript">
var viewer = OpenSeadragon({
id: "example-custom-tilesource",
//debugMode: true,
navigatorSizeRatio: 0.25,
wrapHorizontal: true,
showNavigator: true,
tileSources: {
height: 512 * 256,
width: 512 * 256,
tileSize: 256,
minLevel: 8,
getTileUrl: function (level, x, y) {
console.log("URL::->" + "http://s3.amazonaws.com/com.modestmaps.bluemarble/" + (level - 8) + "-r" + y + "-c" + x + ".jpg")
return "http://s3.amazonaws.com/com.modestmaps.bluemarble/" +
(level - 8) + "-r" + y + "-c" + x + ".jpg";
}
}
});
</script>
This issue is discussed in https://github.com/openseadragon/openseadragon/issues/325. It's a bug in OpenSeadragon, but you can fix it by removing the minLevel and adjusting getTileUrl so it works for all levels.

Cannot read property 'length' of undefined

I have a problem with my angular JS function
when I first call this function, everything is good. But my next attempts cause an error and stops it from working.
My js code:
$scope.updateUptimeCalendar = function() {
$scope.loadHeatMap();
$scope.getMonthHeatMap(new Date().getFullYear(), new Date().getMonth());
};
$scope.loadHeatMapData = function (date) {
var time = date.getTime();
var isMonthLoaded = false;
var eps = 1000 * 60 * 60 * 6; // epsilont +-6 hours
angular.forEach($scope.heatMatData, function (record) {
if (!isMonthLoaded) {
if (Math.abs(record.date - time) < eps) {
isMonthLoaded = true;
}
}
});
if (!isMonthLoaded) {
$scope.getMonthHeatMap(date.getFullYear(), date.getMonth());
};
};
$scope.getMonthHeatMap = function(fullYear, month) {
$scope.setLoadingState(true);
var monthStart = new Date(Date.UTC(fullYear, month, 1));
var monthEnd;
if (month == 12) {
monthEnd = new Date(Date.UTC(fullYear + 1, 1, 1));
} else {
monthEnd = new Date(Date.UTC(fullYear, month + 1, 1));
};
monthStart = monthStart.getTime();
monthEnd = monthEnd.getTime();
var turnOnDuration;
$http.post('Statistic/GetClientStateStatisticByDays', {
clientId: $scope.$parent.clientForStatistic.ClientId,
stateId: 1,
beginPeriod: monthStart,
endPeriod: monthEnd
}).success(function(data) {
$scope.$parent.processResponse(data);
angular.forEach(data, function(record) {
turnOnDuration = record.Duration / (1000 * 60 * 60);
$scope.heatMatData.push({
date: record.AvarageTime,
value: Number((turnOnDuration).toFixed(0)),
});
});
$scope.heatMatData.sort(function(a, b) {
return a.date - b.date;
});
//todo: fixed this when try to get null data values DK
$scope.setLoadingState(false);
$scope.cal.update($scope.heatMatData);
});
};
$scope.heatMapDateParser = function (data) {
var stats = {};
for (var d in data) {
stats[data[d].date / 1000] = data[d].value;
}
return stats;
};
$scope.loadHeatMap = function () {
$('#statistic-modal-chart-container').empty();
$('#statistic-modal-chart-container-calendar').empty();
$scope.cal = new CalHeatMap();
$scope.cal.init({
data: $scope.heatMatData,
afterLoadData: $scope.heatMapDateParser,
considerMissingDataAsZero: true,
//todo: use to set visible dates interval. MR
//minDate: new Date(2014, 9),
//maxDate: new Date(),
itemSelector: "#statistic-modal-chart-container-calendar",
domain: "month",
domainLabelFormat: "%b %Y",
subDomain: "x_day",
subDomainTextFormat: "%d",
itemName: "Hour",
cellSize: 35,
range: 1,
displayLegend: true,
legend: [0, 4, 8, 12, 16, 20, 25],
legendColors: {
base: '#ededed',
empty: '#ededed',
min: '#FFFFFF',
max: '#3366FF'
},
legendHorizontalPosition: "center",
previousSelector: "#uptime-calendar-prev",
nextSelector: "#uptime-calendar-next",
afterLoadNextDomain: function (date) {
$scope.loadHeatMapData(date);
},
afterLoadPreviousDomain: function (date) {
$scope.loadHeatMapData(date);
},
itemNamespace: "animationDuration-a",
tooltip: true
});
};
If I use debug, the error occurs in this row $scope.cal.update($scope.heatMatData);
I get this error
my error:
TypeError: Cannot read property 'length' of undefined
at e (http:/Scripts/d3.min.js:3:10447)
at Array.pa.data (http://Scripts/d3.min.js:3:11196)
at Object.CalHeatMap.fill (http://Scripts/cal-heatmap.min.js:8:20667)
at http://Scripts/cal-heatmap.min.js:9:4615
at h (http:/Scripts/cal-heatmap.min.js:9:1605)
at Object.CalHeatMap.getDatas (http:/Scripts/cal-heatmap.min.js:9:1940)
at Object.CalHeatMap.update (http://Scripts/cal-heatmap.min.js:9:4537)
at http://Scripts/Controllers/statistic-ctrl.js:355:24
at http://Scripts/angular.min.js:72:45
at L (http:/Scripts/angular.min.js:99:469) angular.min.js:92
(anonymous function) angular.min.js:92
(anonymous function) angular.min.js:68
L angular.min.js:99
L angular.min.js:99
(anonymous function) angular.min.js:101
k.$eval angular.min.js:111
k.$digest angular.min.js:108
k.$apply angular.min.js:112
h angular.min.js:72
w angular.min.js:77
A.onreadystatechange
please anybody help me!
Put
$scope.heatMatData = [];
as first instruction

Resources