I have been in contact with webmerge, If you are looking to create a small invoice you can successfully use URI request. However if you are like me, you need to pull 500-1000 line items on to a single invoice, to do it professionally you (like me) want to use Webmerge......
Only trouble is that you must convert your successful Javascript into an $.Ajax call and you cannot figure it out......
HELP !!
1. AJAX version (my attempt)
2. Javascript (fully functional unless I need more that a single PDF page) No changes here, just wanted everyone to see I have a working version just struggling with the conversion.
------------------- AJAX, Need some help, not working -------------------------------------------
$(document).on('knack-scene-render.scene_404', function(event, scene) {
$('#view_719 .view-header').after('<div style="padding:15px"><a href="#" id="webmerge" class="kn-button">Create Report</a></div>');
// link hander: Print Report
$('#webmerge').click(function(event) {
event.preventDefault();
// get data
var data = Knack.models['view_708'].toJSON();
var data = Knack.models['view_721'].toJSON();
var models = Knack.models['view_705'].data.models;
var items =[];
for(var x = 0; x < models.length; x++){
items.push({
startservice: models[x].attributes.field_85,
item: models[x].attributes.field_326,
position: models[x].attributes.field_401,
endservice: models[x].attributes.field_196,
qty: models[x].attributes.field_197,
rate: models[x].attributes.field_194,
contractrate: models[x].attributes.field_277,
discounted: models[x].attributes.field_286,
amount: models[x].attributes.field_287
});
}
log('data!');log(incidents);
Knack.showSpinner();
$.ajax({
url = 'https://www.webmerge.me/merge/123456',
data: {
items: items
clientname: data.field_895,
clientpoc: data.field_644,
clientaddress: data.field_549,
clientpocemail: data.field_648,
clientpocnumber: data.field_649,
clientponumber: data.field_720,
projectname: data.field_692,
projectaddress: data.field_549,
retainerdue: data.field_772,
retaineramount: data.field_773,
invoicenumber: data.field_580,
invoicedue: data.field_719,
agreedamount: data.field_899,
applieddiscount: data.field_900,
discountedtotal: data.field_901,
regulatedservice: data.field_902,
specialtyrisk: data.field_903,
recoveryfee: data.field_904,
salestax: data.field_905,
totalamount: data.field_893
},
type: 'POST',
success: function() {
alert('Report Created!');
Knack.hideSpinner();
},
error: function() {
alert('There was an error creating the report');
}
});
});
});
------------------- END, AJAX, Need some help, not working -------------------------------------------
Below is the version that works but cannot handle the load hence the AJAX
------------------- FUNCTIONING JAVA, I am trying to convert -------------------------------------------
$(document).on('knack-scene-render.scene_404', function(event, scene) {
// link hander: send invoice to webmerge
$('#view_719').submit(function(event) {
event.preventDefault();
// get data
var data_view_708 = Knack.models['view_708'].toJSON();
var data_view_721 = Knack.models['view_721’].toJSON();
var data_view_705 = Knack.models['view_705'].data.toJSON();
url = 'https://www.webmerge.me/merge/123456_use_get=1&download=1';
url += '&companyname=' + encodeURI(data_view_708.field_551);
url += '&address=' + encodeURI(data_view_708.field_62);
url += '&projectname=' + encodeURI(data_view_708.field_642);
url += '&projectaddress=' + encodeURI(data_view_708.field_549);
url += '&duedate=' + encodeURI(data_view_708.field_719);
url += '&invoicenumber=' + encodeURI(data_view_708.field_580);
url += '&totalamountdue=' + encodeURI(data_view_708.field_756);
for(x = 0; x < data_view_705.length; x++){
item = data_view_705[x];
url += '&items[' + x + '][startservice]=' + encodeURI(item.field_85);
url += '&items[' + x + '][item]=' + encodeURI(item.field_326);
url += '&items[' + x + '][position]=' + encodeURI(item.field_401);
url += '&items[' + x + '][endservice]=' + encodeURI(item.field_196);
url += '&items[' + x + '][qty]=' + encodeURI(item.field_197);
url += '&items[' + x + '][rate]=' + encodeURI(item.field_194);
url += '&items[' + x + '][contractrate]=' + encodeURI(item.field_277);
url += '&items[' + x + '][discounted]=' + encodeURI(item.field_286);
url += '&items[' + x + '][amount]=' + encodeURI(item.field_287);
}
window.location = url;
});
});
PLEASE HELP!!