Laravel post request doesn't return correct data - javascript

My form is not updating the information when I manually change the textbox fields. When i get a confirmation email I get the wrong calculation in this example. When i process the information in my controllers it gets put correct in the database but incorrect in the email to my customer. even though it uses the same information.
$('#two-inputs').dateRangePicker(
{
separator : ' tot ',
startDate: '{{$start_date->start_date}}',
endDate: '{{$end_date->end_date}}',
beforeShowDay: function(date){
var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
return [ disabled.indexOf(string) == -1 ]
},
getValue: function()
{
if ($('#date-range200').val() && $('#date-range201').val() )
return $('#date-range200').val() + ' to ' + $('#date-range201').val();
else
return '';
},
setValue: function(s,s1,s2)
{
var total = 0;
var temp_s1 = s1.split("-");
var temp_s2 = s2.split("-");
$('#date-range200').val(temp_s1[2] + "-" + temp_s1[1] + "-" + temp_s1[0]);
$('#date-range201').val(temp_s2[2] + "-" + temp_s2[1] + "-" + temp_s2[0]);
var start_date = s1;
var s1 = s1.split('-');
var s1 = new Date(s1[0], s1[1] - 1, s1[2]);
var s2 = s2.split('-');
var s2 = new Date(s2[0], s2[1] - 1, s2[2]);
//alert(datediff(s1, s2));
if(obj[$('#date-range200').val()] == null){
var prijs = {{$highest_price->name}};
} else {
var prijs = obj[$('#date-range200').val()];
}
var extra_kosten = {{$blog->schoonmaak}};
total += extra_kosten;
total += datediff(s1, s2)*prijs;
$("#aantal_nachten").val(datediff(s1, s2));
$("#prijs_per_nacht").val(prijs);
$("#totaal_prijs_nachten").val(total);
$("#prijs").html(prijs);
$("#nachten").html(datediff(s1, s2));
$("#prijs_nachten").html(datediff(s1, s2)*prijs);
$("#extra_kosten").html(extra_kosten);
$("#totaal_prijs").html(total);
//alert(start_date);
//alert(obj[$('#date-range200').val()]);
$("#prijstable").slideDown( "slow");
}
});
Screenshot of the input fields
Screenshot of what i get in the email i receive
Screenshot of how it shows in my database

Related

log file not created when date change nodejs

i have problem when i try make log for everytime date change it make new file and stop log when end date , for example
20200709_Chatlog.txt for
2020-07-09 21:56:12:91 - connect null
2020-07-09 21:56:15:952 - a user connected
20200710_Chatlog.txt for
2020-07-10 21:56:12:91 - connect null
2020-07-10 21:56:15:952 - a user connected
but my file is always overwrite in the same file date like this
20200709_Chatlog.txt
2020-07-09 21:56:12:91 - connect null
2020-07-09 21:56:15:952 - a user connected
2020-07-10 21:56:12:91 - connect null
2020-07-10 21:56:15:952 - a user connected
, but everytime i restart the server new file created
my code is
function addZero(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
function logDate(){
var d = new Date();
var yy = addZero(d.getFullYear());
var mm = addZero(d.getMonth() + 1);
var dd = addZero(d.getDate());
var h = addZero(d.getHours());
var m = addZero(d.getMinutes());
var s = addZero(d.getSeconds());
var ms = addZero(d.getMilliseconds(), 3);
var tanggal = "";
return tanggal = +yy+ "-" +mm+ "-" +dd+ " " +h+ ":" +m+ ":" +s+ ":" +ms + " ";
}
function fileDate(){
var d = new Date();
var yy = addZero(d.getFullYear());
var mm = addZero(d.getMonth() + 1);
var dd = addZero(d.getDate());
var tanggal = "";
return tanggal = +yy+ "" +mm+ "" +dd+ "_";
}
var fs = require('fs');
var util = require('util');
var logFile = fs.createWriteStream(fileDate()+'Chatlog.txt', { flags: 'a' }); // 'w' to truncate
var logStdout = process.stdout;
console.log = function () {
logFile.write(logDate()+" - " + util.format.apply(null, arguments)+ '\n');
logStdout.write(logDate()+" - " + util.format.apply(null, arguments) + '\n');
}
console.error = console.log;
am i do something wrong, please help , and thanks for helping , sorry if my english bad

Resolve 'Parsing Error: Please check your selector. (line XX)' Javascript/AWQL

First off, let me say that I am not a developer, nor do I really code beyond basic HTML. So I appreciate your patience. :)
I'm working with a script that is for AdWords, but I believe it's more or less written in Javascript. (I've included the script below.)
Basically, I'm receiving the error message 'Parsing Error: Please check your selector. (line XX)' when I preview the script.
I've searched all around for hours and have yet to find a solution.
I think it may be that a query being returned contains either a single or double quote, and may be messing up the code? Though I can't actually prove that.
Also, yes, I was sure to update lines 17-21 with the correct details.
Any help would be much appreciated!
Thanks!
John
/*
// AdWords Script: Put Data From AdWords Report In Google Sheets
// --------------------------------------------------------------
// Copyright 2017 Optmyzr Inc., All Rights Reserved
//
// This script takes a Google spreadsheet as input. Based on the column headers, data filters, and date range specified
// on this sheet, it will generate different reports.
//
// The goal is to let users create custom automatic reports with AdWords data that they can then include in an automated reporting
// tool like the one offered by Optmyzr.
//
//
// For more PPC management tools, visit www.optmyzr.com
//
*/
var DEBUG = 0; // set to 1 to get more details about what the script does while it runs; default = 0
var REPORT_SHEET_NAME = "report"; // the name of the tab where the report data should go
var SETTINGS_SHEET_NAME = "settings"; // the name of the tab where the filters and date range are specified
var SPREADSHEET_URL = "https://docs.google.com/spreadsheets/d/1dttJTb547L81XYKdTQ56LcfO9hHhbb9wm06ZY5mKhEo/edit#gid=0"; // The URL to the Google spreadsheet with your report template
var EMAIL_ADDRESSES = "example#example.com"; // Get notified by email at this address when a new report is ready
function main() {
var currentSetting = new Object();
currentSetting.ss = SPREADSHEET_URL;
// Read Settings Sheet
var settingsSheet = SpreadsheetApp.openByUrl(currentSetting.ss).getSheetByName(SETTINGS_SHEET_NAME);
var rows = settingsSheet.getDataRange();
var numRows = rows.getNumRows();
var numCols = rows.getNumColumns();
var values = rows.getValues();
var numSettingsRows = numRows - 1;
var sortString = "";
var filters = new Array();
for(var i = 0; i < numRows; i++) {
var row = values[i];
var settingName = row[0];
var settingOperator = row[1];
var settingValue = row[2];
var dataType = row[3];
debug(settingName + " " + settingOperator + " " + settingValue);
if(settingName.toLowerCase().indexOf("report type") != -1) {
var reportType = settingValue;
} else if(settingName.toLowerCase().indexOf("date range") != -1) {
var dateRange = settingValue;
} else if(settingName.toLowerCase().indexOf("sort order") != -1) {
var sortDirection = dataType || "DESC";
if(settingValue) var sortString = "ORDER BY " + settingValue + " " + sortDirection;
var sortColumnIndex = 1;
}else {
if(settingOperator && settingValue) {
if(dataType.toLowerCase().indexOf("long") != -1 || dataType.toLowerCase().indexOf("double") != -1 || dataType.toLowerCase().indexOf("money") != -1 || dataType.toLowerCase().indexOf("integer") != -1) {
var filter = settingName + " " + settingOperator + " " + settingValue;
} else {
if(settingValue.indexOf("'") != -1) {
var filter = settingName + " " + settingOperator + ' "' + settingValue + '"';
} else if(settingValue.indexOf("'") != -1) {
var filter = settingName + " " + settingOperator + " '" + settingValue + "'";
} else {
var filter = settingName + " " + settingOperator + " '" + settingValue + "'";
}
}
debug("filter: " + filter)
filters.push(filter);
}
}
}
// Process the report sheet and fill in the data
var reportSheet = SpreadsheetApp.openByUrl(currentSetting.ss).getSheetByName(REPORT_SHEET_NAME);
var rows = reportSheet.getDataRange();
var numRows = rows.getNumRows();
var numCols = rows.getNumColumns();
var values = rows.getValues();
var numSettingsRows = numRows - 1;
// Read Header Row and match names to settings
var headerNames = new Array();
var row = values[0];
for(var i = 0; i < numCols; i++) {
var value = row[i];
headerNames.push(value);
//debug(value);
}
if(reportType.toLowerCase().indexOf("performance") != -1) {
var dateString = ' DURING ' + dateRange;
} else {
var dateString = "";
}
if(filters.length) {
var query = 'SELECT ' + headerNames.join(",") + ' FROM ' + reportType + ' WHERE ' + filters.join(" AND ") + dateString + " " + sortString;
} else {
var query = 'SELECT ' + headerNames.join(",") + ' FROM ' + reportType + dateString + " " + sortString;
}
debug(query);
var report = AdWordsApp.report(query); //THIS IS LINE 103 WITH THE ERROR
try {
report.exportToSheet(reportSheet);
var subject = "Your " + reportType + " for " + dateRange + " for " + AdWordsApp.currentAccount().getName() + " is ready";
var body = "currentSetting.ss<br>You can now add this data to <a href='https://www.optmyzr.com'>Optmyzr</a> or another reporting system.";
MailApp.sendEmail(EMAIL_ADDRESSES, subject, body);
Logger.log("Your report is ready at " + currentSetting.ss);
Logger.log("You can include this in your scheduled Optmyzr reports or another reporting tool.");
} catch (e) {
debug("error: " + e);
}
}
function debug(text) {
if(DEBUG) Logger.log(text);
}
The area between SELECT and FROM is the selector. You're not selecting any fields with that query. That's happening because the headerNames array is empty. Verify the value of REPORT_SHEET_NAME

Google Apps Script Execution API: Script error message: Script function not found:【JavaScript】

I am an absolute beginner of web development.
I would like to implement Google Apps Script Execution API into my project.
I have two questions on Google Apps Script Execution API to ask.
(1) I have no idea how to solve the error below.
Script error message: Script function not found: make_date_array(month)
Although my Google Apps Script has the function 'make_date_array(month)' in it, the error above comes out when I call google apps execution api. So I just don't know what to do.
function send_mail() {
var date = new Date()
date.setDate(new Date().getDate())
date = date.getFullYear() + "-" + zero_padding(date.getMonth() + 1)
runSingleRowQuery(0, date)
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getSheetByName("Data");
var message = "";
var tmp_message = sheet.getRange(1,1,58 ,2).getValues();
for(var i = 0;i < tmp_message.length ;i++){
message += tmp_message[i][0] + ":" + tmp_message[i][1] + "<br>"
}
MailApp.sendEmail({
to: 'I put my email address here'
subject: 'BigQuery',
htmlBody: message
});
}
function runSingleRowQuery(develop_mode, target_month) {
// Replace this value with the project ID listed in the Google
// Developers Console project.
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var queries_sheet = spreadsheet.getSheetByName("Single row queries");
var result_sheet = spreadsheet.getSheetByName("Data");
if(target_month == null){
var target_month = queries_sheet.getRange(1, 2).getValue();
}
make_date_array(target_month);
result_sheet.getRange(1, 2).setValue(queries_sheet.getRange(1, 2).getValue())
for (var i = 2; i <= queries_sheet.getLastRow(); i++) {
var query = queries_sheet.getRange(i, 2).getValue();
if (query_variation(query) != false) {
query = query_variation(query)
Logger.log(queries_sheet.getRange(i, 1).getValue());
Logger.log("# run query: \n " + query);
if (develop_mode != 1) {
Logger.log('\n#####################Run Query#########################');
var request = {
query: query
};
var queryResults = BigQuery.Jobs.query(request, projectId);
var jobId = queryResults.jobReference.jobId;
// Check on status of the Query Job.
var sleepTimeMs = 500;
while (!queryResults.jobComplete) {
Utilities.sleep(sleepTimeMs);
sleepTimeMs *= 2;
queryResults = BigQuery.Jobs.getQueryResults(projectId, jobId);
}
// Get all the rows of results.
var rows = queryResults.rows;
while (queryResults.pageToken) {
queryResults = BigQuery.Jobs.getQueryResults(projectId, jobId, {
pageToken: queryResults.pageToken
});
rows = rows.concat(queryResults.rows);
}
result_sheet.getRange(i, 2).setValue(rows[0].f[0].v);
result_sheet.getRange(i, 1).setValue(queries_sheet.getRange(i, 1).getValue());
result_sheet.getRange(i, 3).setValue(queries_sheet.getRange(i, 3).getValue());
}
}
else {
result_sheet.getRange(i, 1).setValue(queries_sheet.getRange(i, 1).getValue());
result_sheet.getRange(i, 2).setValue(queries_sheet.getRange(i, 2).getFormula());
}
}
}
function make_date_array(month) {
month = month.split('-');
var last_month = {};
var more_last_month = {};
Logger.log((parseFloat(month[0] - 1).toFixed(0)))
if (parseFloat(month[1] - 1).toFixed(0) < 1) {
last_month[0] = (parseFloat(month[0]) - 1).toFixed(0);
last_month[1] = 12;
} else {
last_month[0] = (parseFloat(month[0])).toFixed(0);
last_month[1] = (parseFloat(month[1]) - 1).toFixed(0);
}
if (last_month[1] < 10) {
last_month[1] = '0' + last_month[1];
}
if (parseFloat(last_month[1] - 1).toFixed(0) < 1) {
more_last_month[0] = (parseFloat(last_month[0]) - 1).toFixed(0);
more_last_month[1] = 12;
} else {
more_last_month[0] = (parseFloat(last_month[0])).toFixed(0);
more_last_month[1] = (parseFloat(last_month[1]) - 1).toFixed(0);
}
if (more_last_month[1] < 10) {
more_last_month[1] = '0' + more_last_month[1];
}
date_array['Ym01'] = month[0] + month[1] + '01';
date_array['last_Ym01'] = last_month[0] + last_month[1] + '01';
date_array['more_last_Ym01'] = more_last_month[0] + more_last_month[1] + '01';
date_array['y-m-10_h:s'] = month[0] + '-' + month[1] + '-' + '10 00:00';
date_array['last_y-m-10_h:s'] = last_month[0] + '-' + last_month[1] + '-' + '10 00:00';
date_array['more_last_y-m-10_h:s'] = more_last_month[0] + '-' + more_last_month[1] + '-' + '01 00:00';
date_array['y-m-10'] = month[0] + '-' + month[1] + '-' + '10';
date_array['last_y-m-10'] = last_month[0] + '-' + last_month[1] + '-' + '10';
Logger.log(date_array['last_y-m-10'])
}
(2) Does anyone know how I am supposed to call multiple functions? I used the sample code provided by Google. However, I am not sure if I follow the right way to call several functions.
// Create an execution request object.
var request = {
'function': 'send_mail',
'function': 'runSingleRowQuery(develop_mode, target_month)',
'function': 'make_date_array(month)',
};
If you have had similar problems before, could you please help deal with the two issues above? English is not my first language, so if this post does not make sense to you or need more information, please leave your comments. Any advise would be appreciated. Thanks in advance.
In additional to link in the comment I think this code
if(target_month == null){
var target_month = queries_sheet.getRange(1, 2).getValue();
}
You have to change to (no var)
if(target_month == null){
target_month = queries_sheet.getRange(1, 2).getValue();
}

Firefox addon could not convert to bootstrap

Below I have the code for xul addon which works expectedly.
i.e. shows username and password input at the browser startup and whenever the topic is http-on-examine-response it validates and write in specified file.
But when I try to convert it to a bootstrapped extension it won't even show the username password input at the browser startup and nothing is showing in the console when I compile and run.
I couldn't figure out the wrong thing after I changed the components... to Cu/Cc/etc.
I referred below links
https://developer.mozilla.org/en/Add-ons/Bootstrapped_extensions
What does paragraph about figuring out XUL elements mean in MDN document: "How to convert an overlay extension to restartless"
https://github.com/Noitidart/l10n/tree/xhtml-xul
Below is my code:
const {Cc, Ci, Cu, components} = require("chrome");
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
function Tdatacounter() {
var Tdatacounter = {
observe: function(subject, topic, data) {
if (topic == "http-on-examine-response") {
var httpChannel = subject.QueryInterface(Ci.nsIHttpChannel);
if (httpChannel.responseStatusText == "OK")
{
var buffer = httpChannel.URI.spec;
var pw = buffer.search("pub.tdata.com/releasepic");
if (pw > 0)
{
var date = new Date();
var TimeStamp = date.toLocaleString();
var pfum = buffer.search("flag=unmap");
if (pfum > 0 )
{
var flagname = "unmap";
var flagnum = 4;
}
if (flagnum > 0)
{
buffer += "^" + ThisUserName + "^" + ThisComputerName + "^" + TimeStamp + "^" + flagname + "\r\n";
fos.write(buffer, buffer.length);
}
}
}
}
}
};
var nsIEnvironment = Cc["#mozilla.org/process/environment;1"]
.getService(Ci.nsIEnvironment);
var prompts = Cc["#mozilla.org/embedcomp/prompt-service;1"]
.getService(Ci.nsIPromptService);
var usernamelist = ["user1","user2","user3"];
var passlist = ["e%cd1","kowgirl23","bhava1204"];
var ThisUserName = null;
var username = {value: "UserName"}; // default the username to user
var password = {value: "pass"}; // default the password to pass
var check = {value: false}; // default the checkbox to true
var GetUserName = prompts.promptUsernameAndPassword(null, "ProcName", "Enter username and password:", username, password, null, check);
while (GetUserName === true) {
var a = usernamelist.indexOf(username.value);
var b = passlist[a];
if (password.value == b) {
var ThisUserName = username.value;
break;
} else {
var GetUserName = prompts.promptUsernameAndPassword(null, "ProcName", "Enter username and password:", username, password, null, check);
}
}
if (ThisUserName !== null) {
var ThisComputerName = nsIEnvironment.get("ComputerName");
var FileUtils = Cu.import("resource://gre/modules/FileUtils.jsm").FileUtils;
var d = new Date();
var dd = d.getDate();
if (dd < 10)
dd = "0" + dd;
var mm = (d.getMonth()+1);
if (mm < 10)
mm = "0" + mm;
var yyyy = d.getFullYear();
var file = new FileUtils.File( "\\\\STJ\\Proc1\\-\\" + yyyy + "\\" + mm + "\\" + dd );
if (!file.exists()) {
file.create(file.DIRECTORY_TYPE, 0755);
}
var filename = "HM_" + ThisUserName + yyyy + "-" + mm + "-" + dd + ".txt";
file.append(filename);
var fos = Cc["#mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);
// PR_WRONLY | PR_CREATE_FILE | PR_APPEND
fos.init(file, 0x02 | 0x08 | 0x10, -1, 0);
var date = new Date();
var TimeStamp = date.toLocaleString();
var StartTime = "LoginTime=" + TimeStamp + " at " + ThisComputerName + "\r\n";
fos.write(StartTime, StartTime.length);
var observerService = Cc["#mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
observerService.addObserver(Tdatacounter, "http-on-examine-response", false);
}}
Tdatacounter.prototype.classID = components.ID('{d4a9bb50-b9b2-11e0-a4dd-0800200c9a66}');
Tdatacounter.prototype.classDescription = 'tdata Counter';
Tdatacounter.prototype.contractID = '#tdata/TdataCounter;1';
var NSGetFactory = XPCOMUtils.generateNSGetFactory([TdataCounter]);
I figured out what I've missed. As a beginner in firefox javascript, I missed to add 'register', 'unregister' functions. What a silly mistake I did? Phew. anyhow I hope this answer will be helpful for the novices like me.
Thank you.

Google Script Invalid Assignment left-hand side

Ok so I have this code. Sorry, I didn't know where the problem is so I pasted it all. It says: Invalid assignment left-hand side. (line 1, file "Code"). I know the problem cannot be on line one but have no idea where it is.
function send(sheet, email, row){
var tmp = GmailApp.getAliases();
var alias = tmp[0];
var subject = "Thank you for signing up for "+ sheet.getSheetName()+ "!";
var body = "Hello "+ sheet.getRange(row,3).getValue() + " " + sheet.getRange(row,4).getValue() + "," + '\n'+'\n';
var temp = 2;
var bool = "TRUE";
while (bool == "TRUE"){
if (sheet.getRange(temp,11).getValue() != ''){
body += '\n' + sheet.getRange(temp,11);
temp += 1;
}
if (sheet.getRange(temp + 1,11).getValue() != '')
body += '\n' + body += '\n' + sheet.getRange(temp + 1,11);
else {bool = "FALSE"}
}
Logger.log(body);
if ( sheet.getRange('L2').getValue() != ""){
var html = sheet.getRange('L2').getValue(); // Place HTML code here
try {
GmailApp.sendEmail(email, subject, body, {'from': alias, 'htmlbody': html});
sheet.getRange(row, 9).setBackground("green");
sheet.getRange(row, 9).setValue("Yes");
sheet.getRange("J2").setValue(row - 2);
} catch (e) {
var me = Session.getActiveUser().getEmail();
MailApp.sendEmail(me, "Autoreply error", "There was a problem sending an email to: " + email +".");
}
}
else{
try {
GmailApp.sendEmail(email, subject, body, {'from': alias});
sheet.getRange(row, 9).setBackground("green");
sheet.getRange(row, 9).setValue("Yes");
sheet.getRange("J2").setValue(row - 2);
} catch (e) {
MailApp.sendEmail(me, "Autoreply error", "There was a problem sending an email to: " + email +".");
}
}
}
function main(){
var ss = SpreadsheetApp.openById("1a2xvZ6hx69hst0CoLnCc8V5Igi-V5_HaNm6GTpEU8B4"); // Unique ID for the 'Responses' spreadsheet
var sheet = ss.getActiveSheet();
if ( sheet.getRange('J2').getValue() == "" ){
sheet.getRange('I1').setValue("Sent"); // Initialize labels
sheet.getRange('J1').setValue("Count");
sheet.getRange('K1').setValue("Email body");
sheet.getRange('L1').setValue("HTML body");
var row = 2;
} else {
var row = sheet.getRange("J2").getValue() + 2;
}
while ( (sheet.getRange(row,9).getValue() != '') && (sheet.getRange(row,2).getValue() != '')) {
var email = sheet.getRange(row, 2).getValue();
send(sheet, email, row);
row += 1;
}
}
You cannot write a line like this : ( 2 x += in the same statement)
body += '\n' + body += '\n' + sheet.getRange(temp + 1,11); // this throws the error
I'd suggest to use an intermediate variable like this :
var xxx = '\n' + sheet.getRange(temp + 1,11);
body+= '\n'+ body + xxx ;
if this is really what you want to do... but it seems strange to me...
Shouldn't it be something like this : body+= '\n'+sheet.getRange(temp + 1,11);

Categories

Resources