';
output += moment(value.date).format('ddd, D MMM YYYY');
//output += ''+moment(value.date).format('dddd, D MMMM YYYY')+'';
output += ' ';
if(key==0) {
output += ""+moment(value.date).fromNow(true)+" since today";
}
else {
output += ""+moment(value.date).from(dates[(key-1)], true)+"";
}
output += ' | '+value.quantity;
output += ' ';
if(key!=(json_data.length-1)) {
var quantity_difference = (value.quantity - json_data[(key+1)].quantity);
if(quantity_difference==0) output += "-";
else {
if(quantity_difference>0) output += '+';
else output += '';
output += quantity_difference+'';
}
}
output += ' | $'+Number(value.unit_price).toFixed(2);
output += ' ';
if(key!=(json_data.length-1)) {
var unit_price_difference = (value.unit_price - json_data[(key+1)].unit_price).toFixed(2);
if(unit_price_difference==0) output += "-";
else {
if(unit_price_difference>0) output += '$'+unit_price_difference+'';
else output += '-$'+Math.abs(unit_price_difference)+'';
}
}
var sub_total = (value.unit_price * value.quantity).toFixed(2);
output += ' | $'+sub_total;
output += ' ';
if(key!=(json_data.length-1)) {
var sub_total_difference = (sub_total - (json_data[(key+1)].unit_price * json_data[(key+1)].quantity).toFixed(2)).toFixed(2);
if(sub_total_difference==0) output += "-";
else {
if(sub_total_difference>0) output += '$'+sub_total_difference+'';
else output += '-$'+Math.abs(sub_total_difference)+'';
}
}
output += ' | ';
});
output = '
Order history of '+$el.attr("data-product_id")+' (latest 10)
Date | Quantity | Unit Price | Sub total |
'+output+'
';
$el.attr('data-order_history', output);
show_order_history(output);
});
}
else {
// toggle table
//$el.find('table').toggleClass('hidden');
var output = $el.attr('data-order_history');
show_order_history(output);
}
}
$('#product').data('el', $el);
$('#product').modal('show');
}
});
$('.products .product[data-product_id]').click(function(e) {
if($(e.target).parents('.toggle_wrap').length) return true;
if($(this).hasClass('product')) {
var $el = $(this);
// console.log('el hasClass product', $el);
}
else {
var $el = $(this).parents('.product');
// console.log('found el product', $el);
}
$('#product').find('div[data-order_history_output]').remove();
if($el.find('.order_history').length) {
// check if order history has been loaded
if(!$el.attr('data-order_history')) {
// run ajax query to get most recent order dates, qty, unit price
var output = "";
$.get("https://www.aquabluedistribution.com.au/api_get_orders.php", { CustomerID: $el.attr("data-CustomerID"), ProductID: $el.attr("data-product_id"), limit: 10 } )
.done(function(data) {
var dates = [];
var json_data = $.parseJSON(data);
$.each(json_data, function(key, value) {
dates[key] = value.date;
output += '
';
output += moment(value.date).format('ddd, D MMM YYYY');
//output += ''+moment(value.date).format('dddd, D MMMM YYYY')+'';
output += ' ';
if(key==0) {
output += ""+moment(value.date).fromNow(true)+" since today";
}
else {
output += ""+moment(value.date).from(dates[(key-1)], true)+"";
}
output += ' | '+value.quantity;
output += ' ';
if(key!=(json_data.length-1)) {
var quantity_difference = (value.quantity - json_data[(key+1)].quantity);
if(quantity_difference==0) output += "-";
else {
if(quantity_difference>0) output += '+';
else output += '';
output += quantity_difference+'';
}
}
output += ' | $'+Number(value.unit_price).toFixed(2);
output += ' ';
if(key!=(json_data.length-1)) {
var unit_price_difference = (value.unit_price - json_data[(key+1)].unit_price).toFixed(2);
if(unit_price_difference==0) output += "-";
else {
if(unit_price_difference>0) output += '$'+unit_price_difference+'';
else output += '-$'+Math.abs(unit_price_difference)+'';
}
}
var sub_total = (value.unit_price * value.quantity).toFixed(2);
output += ' | $'+sub_total;
output += ' ';
if(key!=(json_data.length-1)) {
var sub_total_difference = (sub_total - (json_data[(key+1)].unit_price * json_data[(key+1)].quantity).toFixed(2)).toFixed(2);
if(sub_total_difference==0) output += "-";
else {
if(sub_total_difference>0) output += '$'+sub_total_difference+'';
else output += '-$'+Math.abs(sub_total_difference)+'';
}
}
output += ' |
';
});
output = '
Order history of '+$el.attr("data-product_id")+' (latest 10)
Date | Quantity | Unit Price | Sub total |
'+output+'
';
$el.attr('data-order_history', output);
show_order_history(output);
});
}
else {
// toggle table
//$el.find('table').toggleClass('hidden');
var output = $el.attr('data-order_history');
show_order_history(output);
}
}
$('#product').data('el', $el);
$('#product').modal('show');
});
function show_order_history(output) {
$('#product .modal-body .blurb').after(output);
// $('#product').modal('show');
}
$('#product').on('show.bs.modal', function() {
var $el = $('#product').data('el');
$('#product .image').html('');
$.getJSON('https://www.aquabluedistribution.com.au/api_product_images.php?ProductID='+$el.attr('data-product_id'), function(response) {
// check for successful response
if(response.success) {
$('#product .image').html(response.success);
}
});
$('#product').attr('data-product_id', $el.attr('data-product_id'));
if($el.find('h2').length) $('#product .description').text($el.find('h2').text());
else $('#product .description').text($el.find('.product_title').text());
$('#product .ProductID').text($el.attr('data-product_id'));
if($el.attr('data-blurb')!='') $('#product .blurb').html($el.attr('data-blurb')).show();
else $('#product .blurb').hide();
if($el.attr('data-brand')!='') $('#product .brand').text($el.attr('data-brand')).show();
else $('#product .brand').hide();
if($el.attr('data-discounts')) {
if($el.attr('data-discounts')!='') {
$('#product .discounts table > tbody > tr').remove();
var discounts = $.parseJSON($el.attr('data-discounts'));
$.each(discounts, function(discount, discount_details) {
$.each(discount_details, function(k, v) {
if(v.discount_quantity_to == null) v.discount_quantity_to = '-';
$('#product .discounts table > tbody').append('
'+discount+' | '+v.discount_quantity_from+' | '+v.discount_quantity_to+' | '+num_format(v.discount_percent)+'% | $'+v.discount_price+' + GST |
');
});
});
$('#product .discounts').show();
}
}
else $('#product .discounts').hide();
$('#product .stock_status').html($el.attr('data-stock_status'));
$('#product .CartonQty').text(num_format($el.attr('data-CartonQty')));
$('#product .cost_amount').text(parseFloat($el.attr('data-DefaultPrice')).toFixed(2));
var step = $el.attr('data-step');
if(step) {
$('#product .quantity input[name="quantity"]').attr('step', step);
$('#product .quantity input[name="quantity"]').val(step);
} else {
$('#product .quantity input[name="quantity"]').attr('step', 1);
$('#product .quantity input[name="quantity"]').val(1);
}
$('#product .quantity input[name="quantity"]').attr('data-CartonQty', $el.attr('data-CartonQty'));
$('#product .quantity input[name="quantity"]').attr('data-ProductID', $el.attr('data-product_id'));
$('#product .add_to_cart').attr('data-ProductID', $el.attr('data-product_id'));
if($el.hasClass('frozen')) {
$('#product .quantity').addClass('hidden');
$('#product .add_to_cart').addClass('hidden');
} else {
$('#product .quantity').removeClass('hidden');
$('#product .add_to_cart').removeClass('hidden');
}
});
function num_format(the_number) {
if(parseInt(the_number)==the_number) return parseInt(the_number);
else return parseFloat(the_number).toFixed(2);
}
function generateUUID() {
var d = new Date().getTime();
var uuid = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
var r = (d + Math.random()*16)%16 | 0;
d = Math.floor(d/16);
return (c=="x" ? r : (r&0x7|0x8)).toString(16);
});
return uuid;
}
function pluralise(count) {
if(parseInt(count) != 1) return 's';
else return '';
}
// contact form
$('a[href="contact_form"]').click(function(e) {
e.preventDefault();
$('#form').modal('show');
});
$('#contact_form').validate({
submitHandler: function(form) {
$.ajax({
type:'post',
method:'post',
url:'https://www.aquabluedistribution.com.au/process.php',
data: $('#contact_form').serialize(),
success: function(data) {
$("#form_send_error").remove();
if(data=='success') {
$("#contact_form .row").remove();
$('#contact_form h2').text('Thanks for your enquiry');
$('#contact_form p').text('Will contact you shortly.');
}
else {
var IS_JSON = true;
try {
var response_json = JSON.parse(data);
}
catch(ex) {
IS_JSON = false;
}
if(IS_JSON) {
$('#contact_form input[type="submit"]').before('
');
$.each(response_json.error.errors, function(k, v) {
console.log(k, v);
$('#form_send_error').append('
'+v+'
');
});
}
else {
alert('error - '+data);
if($('#form_send_error').length==0) {
$('#contact_form input[type="submit"]').after('
');
}
}
}
},
error:function(a,b,c) {
if($('#form_send_error').length==0) $('#contact_form input[type="submit"]').after('
');
//console.log(a,b,c);
}
});
}
});
// $('#contact_form').validate({
// submitHandler: function(form) {
// $.ajax({
// method:'post',
// url:'process.php',
// data: $('#contact_form').serialize(),
// success: function(data) {
// if(data=='success') {
// $("#contact_form .row").not(":eq(0)").remove();
// $('#contact_form div.h2').text('Thanks for your enquiry');
// $('#contact_form p').text('A Aqua Blue Distribution expert will contact you shortly.');
// }
// else {
// if($('#form_send_error').length==0) $('#contact_form input[type="submit"]').after('
');
// }
// },
// error:function(a,b,c) {
// if($('#form_send_error').length==0) $('#contact_form input[type="submit"]').after('
');
// //console.log(a,b,c);
// }
// });
// }
// });
function set_nav() {
$('#navbar-header > .navbar-header').css('height', 'auto');
$('#navbar-header > .navbar-header').height($('.navbar').height());
$('.navbar-brand').css('line-height', $('.navbar').height()+'px');
var the_margin = $("#navbar-header > .navbar-header").height()-50;
if(the_margin<=0) the_margin = 5;
$("#wrap").first().css("margin-top", the_margin);
}
$(window).resize(function() {
set_nav();
});
$(window).scroll(function() {
set_nav();
// if($(document).scrollTop() > 50) {
// $('body').addClass('scrolled');
// }
// else {
// $('body').removeClass('scrolled');
// }
});
set_nav();
});