jQuery(document).ready(function($) {
console.log("dev.mpaqt.io");
$('#setup-form').on('submit', function(e) {
e.preventDefault();
var $form = $(this);
$.post($form.attr('action'), $form.serialize(), function(data) {
console.log("posting data");
console.log(data);
$("#mpaqtFormWrapper").fadeOut();
//alert('This is data returned from the server ' + data);
console.log(data);
console.log(data.data);
console.log("object keys " + Object.keys(data.data)[0]);
/*
var uKey = Object.keys(data.data.user)[0];
console.log("array access " );
console.log(data.user[uKey]);
console.log(data.user[uKey].email);
var affiliate_url = $("#affiliate_url").val();
console.log("page " + page);
$.each(data.user, function(index, value) {
console.log(index);
console.log(value);
});
*/
// var ut = $.data( document.body, "driver_enabled" );
if($('#host_preference').prop('checked')) {
var ut = 1;
} else {
var ut = 0;
}
if($('#optin').prop('checked')) {
var oi = 1;
} else {
var oi = 0;
}
console.log("ut " + ut);
var msgOut = "
Success!
";
if(ut==1) {
msgOut += "Please complete registering by finalizing Host Details
";
} else {
msgOut += "Please complete registering by finalizing Merchant Details
";
}
if(oi==1) {
msgOut += "You will receive a text message to confirm your opt-in for SMS communications
";
}
$("#mpaqtSuccessMessage").html(msgOut);
$("#mpaqtSuccessMessage").fadeIn();
}, 'json');
});
$('#host_preference').bootstrapToggle({
on: 'Host',
off: 'Merchant'
});
$('#host_preference').change(function() {
console.log( $(this).prop('checked'));
if($(this).prop('checked')) {
$("#termsLink").attr("href", "/host-agreement");
} else {
$("#termsLink").attr("href", "/merchant-agreement");
}
});
$( '.change_trigger' ).change(function() {
console.log( $(this).val() );
console.log( $(this).attr("id") );
valueCalculator();
});
$( ".fulfillment_options" ).change(function() {
const msg = [];
msg["label"]= service[3]['description'] + " - " + formatter.format(service[3]['unit_cost'])+ " / " + service[3]['recurrence'];
msg["pickup"]= service[2]['description'] + " - " + formatter.format(service[2]['unit_cost'])+ " / " + service[2]['recurrence'];
msg["flex"]= service[1]['description'] + " - " + formatter.format(service[1]['unit_cost'])+ " / " + service[1]['recurrence'];
selected_value = $("input[name='fulfillment_options']:checked").val();
$("#fulfillment_msg").html(""+msg[selected_value]+"
");
});
function valueCalculator () {
console.log("go crunch");
var items_stored = $("#items_stored").val();
var days_stored = $("#days_stored").val();
var unit_height = $("#unit_height").val();
var unit_width = $("#unit_width").val();
var unit_depth = $("#unit_depth").val();
var variety_count = $("#variety_count").val();
var restock_count = $("#restock_count").val();
var order_count = $("#order_count").val();
var item_count = $("#item_count").val();
var box_count = $("#box_count").val();
var restock_items = $("#restock_items").val();
var item_storage_cost = service[5]['unit_cost'];
var restock_cost = service[7]['unit_cost'];
// var restock_item_cost = service[7]['unit_cost'];
var restock_box_cost = service[11]['unit_cost'];
var pack_box_cost = service[4]['unit_cost'];
var pack_item_cost = service[6]['unit_cost'];
var fulfill_order_cost = service[9]['unit_cost'];
var fulfill_box_cost = service[10]['unit_cost'];
console.log("storage cost" + item_storage_cost);
console.log("height" + unit_height);
console.log("width " + unit_width);
if(days_stored > 30.3) {
var days_rounded = 30;
} else {
var days_rounded = days_stored;
}
var size_calc = (unit_height * unit_width * unit_depth) * items_stored;
var storage_calc = size_calc * days_rounded * item_storage_cost;
var receiving_box_calc = 1 + restock_count / variety_count;
var receiving_item_calc = restock_items * restock_count * restock_cost;
console.log("receiving_box_calc" + receiving_box_calc);
//var receiving_calc = restock_count * restock_cost;
var receiving_cost_calc = receiving_item_calc + receiving_box_calc;
var packing_box_calc = pack_box_cost * box_count;
var packing_item_calc = item_count * pack_item_cost;
var packing_cost_calc = packing_box_calc + packing_item_calc;
var fulfillment_box_calc = box_count * fulfill_box_cost;
var fulfillment_order_calc = order_count * fulfill_order_cost;
var fulfillment_cost_calc = fulfillment_order_calc + fulfillment_box_calc;
var total_cost = packing_cost_calc+receiving_cost_calc+storage_calc+fulfillment_cost_calc;
outMsg = "";
outMsg += "Monthly Storage Cost: " + formatter.format(storage_calc) + "
";
outMsg += "Receiving Cost: " + formatter.format(receiving_cost_calc) + "
";
outMsg += "Packing Cost: " + formatter.format( packing_cost_calc )+ "
";
outMsg += "Order Preparation Cost: " + formatter.format(fulfillment_cost_calc) + "
";
outMsg += "Fulfillment Cost: Based on selected fulfillment method
";
outMsg += "Total Cost: " + formatter.format(total_cost) + "
";
$("#mpaqt_item_price_message").html(outMsg);
console.log("storage calc" + storage_calc);
}
$( ".serviceDescription" ).tooltip();
});