Skip to content

Instantly share code, notes, and snippets.

@dperussina
Created January 9, 2017 19:47
Show Gist options
  • Save dperussina/bd2330726865dfeef71ddf4b00e4f774 to your computer and use it in GitHub Desktop.
Save dperussina/bd2330726865dfeef71ddf4b00e4f774 to your computer and use it in GitHub Desktop.
var client = require('./http');
var qs = require('querystring');
var u = require('./u/u')
function main() {
var startDate = $("#start-date-input");
var endDate = $("#end-date-input");
var searchBtn = $("#search-btn");
var exportBtn = $("#export-btn");
var status = $("#status-fill")
exportBtn.click(function(e){
e.preventDefault();
var table = $("table").html();
table = table.replace('<thead>', '');
table = table.replace('</thead>', '');
table = table.replace('<tbody>', '');
table = table.replace('</tbody>', '');
window.open('data:application/vnd.ms-excel,' +"<table>"+table+"</table>");
});
searchBtn.click(function(e){
e.preventDefault();
status.text('Searching...');
if(startDate.val() == "" || endDate.val() == ""){
status.text('Error! Invalid date range...');
return;
}
var query = qs.stringify({startDate:startDate.val(), endDate:endDate.val()});
client.get('/api/GetOnHandByDateRange?'+query, function(err, res){
u.log('/api/GetOnHandByDateRange?'+query, err, res);
if(err){
status.text('Error! Something went wrong...'+ res.toString());
return;
}
status.text('Success! Loading '+res.data.length+' results..');
processResults(res.data);
//u.log('/api/GetOnHandByDateRange?'+query, err, res);
});
});
function processResults(data){
var html = "";
u.log('[processResults] ', data.length);
data.forEach(function(e, i, a){
html +="<tr>";
html +="<td>";
html +=e.PartnerPrimaryOrderID;
html +="</td>";
html +="<td>";
html +=e.JobControlNumber;
html +="</td>";
html +="<td>";
html +=e.PUCity;
html +="</td>";
html +="<td>";
html +=e.DLCity;
html +="</td>";
html +="<td>";
html +=formatDate(e.DateAdded);
html +="</td>";
html +="<td>";
if(e.NoteCodeRE.NoteDate){
html +=formatDate(e.NoteCodeRE.NoteDate);
}else{
html +="N/A";
}
html +="</td>";
html +="<td>";
if(e.NoteCode1C.NoteDate){
html +=formatDate(e.NoteCode1C.NoteDate);
}else{
html +="N/A";
}
html +="</td>";
html +="<td>";
if(e.NoteCode2C.NoteDate){
html +=formatDate(e.NoteCode2C.NoteDate);
}else{
html +="N/A";
}
html +="</td>";
html +="<td>";
if(e.NoteCode3C.NoteDate){
html +=formatDate(e.NoteCode3C.NoteDate);
}else{
html +="N/A";
}
html +="</td>";
html +="<td>";
if(e.NoteCodeMC.NoteDate){
html +=formatDate(e.NoteCodeMC.NoteDate);
}else{
html +="N/A";
}
html +="</td>";
html +="<td>";
if(e.DeliveryDateSchedueled.LogDate){
html +=formatDate(e.DeliveryDateSchedueled.LogDate);
}else{
html +="N/A";
}
html +="</td>";
html +="<td>";
if(e.DLActualArrive !== null){
html +=formatDate(e.DLActualArrive);
}else{
html +="N/A";
}
html +="</td>";
html +="<td>";
if(e.NoteCodeRE.NumDays !== null){
html +=e.NoteCodeRE.NumDays;
}else{
html +="N/A";
}
html +="</td>";
html +="<td>";
if(e.NoteCode1C.NumDays !== null){
html +=e.NoteCode1C.NumDays;
}else{
html +="N/A";
}
html +="</td>";
html +="<td>";
if(e.NoteCode2C.NumDays !== null){
html +=e.NoteCode2C.NumDays;
}else{
html +="N/A";
}
html +="</td>";
html +="<td>";
if(e.NoteCode3C.NumDays !== null){
html +=e.NoteCode3C.NumDays;
}else{
html +="N/A";
}
html +="</td>";
html +="<td>";
if(e.NoteCodeMC.NumDays !== null){
html +=e.NoteCodeMC.NumDays;
}else{
html +="N/A";
}
html +="</td>";
html +="<td>";
if(e.DeliveryDateSchedueled.NumDays !== null){
html +=e.DeliveryDateSchedueled.NumDays;
}else{
html +="N/A";
}
html +="</td>";
html +="<td>";
if(e.DaysFromREtoPOD !== null){
html +=e.DaysFromREtoPOD;
}else{
html +="N/A";
}
html +="</td>";
html +="</tr>";
});
$("#results-fill").html(html);
status.text('Done! Order data processed successfully!')
}
}
function formatDate(date){
return date.split('T')[0];
}
$(function(){
main();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment