Skip to content

Instantly share code, notes, and snippets.

@jamescarr
Created April 13, 2017 05:23
Show Gist options
  • Save jamescarr/2f5a2b2d54dca463555e768078c190dd to your computer and use it in GitHub Desktop.
Save jamescarr/2f5a2b2d54dca463555e768078c190dd to your computer and use it in GitHub Desktop.
fill("01/15/2016", "12/20/2016")
var work = {
addressLine1: "",
city: "",
country: "",
state: "",
postalCode: ""
}
var home = {
addressLine1: "",
city: "",
country: "",
state: "",
postalCode: ""
}
var request = {
business: true,
tripMiles: "FILL THIS IN",
vehicleId: 1111111 // find this by logging a mileage entry and inspecting the network tab for `mileagelog`
}
function fill(startDate, endDate) {
var start = new Date(startDate);
var end = new Date(endDate);
while(start < end){
if(start.getDay() > 0 && start.getDay() < 6) {
logEntry(start)
}
var newDate = start.setDate(start.getDate() + 1);
start = new Date(newDate);
}
}
function logEntry(date) {
var recordDate = date.toISOString().split('T')[0]
var to = $.extend(true, {
startAddress: home,
endAddress: work,
description: "Travel to client site",
tripLocalDateTime: recordDate
}, request);
var from = $.extend(true, {
startAddress: work,
endAddress: home,
description: "Travel from client site",
tripLocalDateTime: recordDate
}, request);
logMileage(to);
logMileage(from);
}
function logMileage(entry) {
$.ajax({
type: 'POST',
url: '/secure/mileagelog',
data: JSON.stringify(entry),
dataType: 'json',
success: function(data, status) {
console.log(status);
console.log(data);
},
headers: {
'Content-Type': 'application/json',
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment