//cart
function refreshcartqty(obj)
{
var row=obj.parent().parent().parent();
var id=row.attr('id');
var qty=row.find('.qtybox').val();
var pqty=row.find('.pqty').val();
$.get('cart.php',{updatecartid:id,qty:qty,pqty:pqty},function(d)
{
$('.cart-table-area').replaceWith(d);
});
}
function delcartitem(id,obj)
{
obj.parent().parent().hide('slow');
$.get('cart.php',{delcartid:id},function(d)
{
$('.cart-table-area').replaceWith(d);
});
}
//product
function updatepcost()
{
var id=$('#pqty').attr('pid');
var pqty=$('#pqty').val();
$('#priceslab').load('product.php?getslab=' + id + '&pqty=' + pqty,function(){highlightslab()});
}
function selectqty(q)
{
$('#qty').val(q);
highlightslab();
}
function highlightslab()
{
var qty=$('#qty').val();
$('tr').removeClass('focus');
$('.slabrow').each(function()
{
if(qty>=parseInt($(this).attr('floor')))
{
$('tr').removeClass('focus');
$(this).addClass('focus');
}
});
}
function addtocart(id,qty=0,pqty=0,mode=0)
{
if(!qty) qty=$('#qty').val();
if(!pqty) pqty=$('#pqty').val();
var brand=prompt('Enter the name of your brand or creative','');
// $('#main').parent().parent().fadeOut('slow');
if(!qty|| !pqty)return;
$.get('cart.php',{addid:id,qty:qty,pqty:pqty,brand:brand},function(d)
{
//alert(d);
if(mode==1)
alert('Added ' + qty + ' pcs to cart. Please click on Cart on top of page to edit or add');
else
document.location='index.php?cart=1';
// $('#main').parent().hide();
// $('#main').parent().parent().fadeIn('fast').append(d);
});
}
function customqty(obj)
{
if(obj.val()!=='-1')return;
var n=prompt('Enter quantity','1');
if(!n || n<0)return;
obj.find("option:selected").removeAttr("selected");
obj.append("");
}
///transport
function updatetransportmode(v)
{
if(v==1)
{
$("#transportcart").show();
scrollto("#transportcart");
}
else $("#transportcart").hide();
$("#transportcart").append("
Optimzing logistics costs as per selected location and quantities");
$.get('transportcart.php',{updatemode:v},function(d){
$("#transportcart").html(d);
});
}
function processshipments(v,obj)
{
obj.parent().append("
Optimzing logistics costs as per selected location and quantities");
$.get('transportcart.php',{changebatchloc:obj.attr('id'),val:v},function(d)
{
$('#transportcart').html(d);
});
}
function updateshippingbilling(ccid,batch,obj)
{
obj.parent().append("
Optimzing logistics costs as per selected location and quantities");
$.get('transportcart.php',{updateshippingbilling:obj.val(),ccid:ccid,batch:batch},function(d)
{
$('#transportcart').html(d);
});
}
function changebilling(ccid,batch,obj)
{
obj.parent().append("
Optimzing logistics costs as per selected location and quantities");
$.get('transportcart.php',{changebilling:obj.val(),ccid:ccid,batch:batch},function(d)
{
$('#transportcart').html(d);
});
}
function init_selectize()
{
$('.shipmentloc').selectize({
valueField: 'id',
labelField: 'value',
searchField: 'value',
maxItems:1,
options: [],
create: false,
onChange: function(value)
{
processshipments(value,$(this.$input[0]));
},
render: {
option: function(item, escape) {
return '
'
+ '- '+item.name+'
'
+ '- '+item.address+'
'
+ '
';
}
},
load: function(query, callback) {
if (!query.length) return callback();
console.log($(this.$input[0]).attr('clientid'));
$.getJSON({
url: 'shipment_location.php',
data: {
q: query,
clientid:$(this.$input[0]).attr('clientid')
},
error: function() {
callback();
},
success: function(res) {
callback(res);
}
});
}
});
$('.billingloc').selectize({
valueField: 'id',
labelField: 'value',
searchField: 'value',
maxItems:1,
options: [],
create: false,
onChange: function(value)
{
$('#cityid').val(value);
},
render: {
option: function(item, escape) {
return '
'
+ '- '+item.name+'
'
+ '- '+item.address+'
'
+ '
';
}
},
load: function(query, callback) {
if (!query.length) return callback();
$.getJSON({
url: 'shipment_location.php',
data: {
q: query,
},
error: function() {
callback();
},
success: function(res) {
callback(res);
}
});
}
});
$('#billingbox').selectize({
create: false,
render: {
option: function(item, escape) {
return '
'
+ 'Billing: '+item.billingname+' '
+ '
Address: '+item.address+' '
+ '
City: '+item.city+' - ' + item.pincode + ''
+ '
';
},
item: function(item, escape) {
return '
'
+ 'Billing: '+item.billingname+' '
+ '
Address: '+item.address+' '
+ '
City: '+item.city+' - ' + item.pincode + ''
+ '
';
}
}
});
}
function splitshipment(ccid,batch)
{
var n=prompt('How many shipments to split this into?',3);
if(!n)return;
loading('#transportcart');
loading('#distribute');
$.get('transportcart.php',{ccid:ccid,splitbatch:batch,n:n},function(d)
{
$("#transportcart").html(d);
$('#distribute').html('').load('transportcart.php?distribute=1');
});
}
function delbatch(ccid,batch,obj)
{
obj.hide('slow');
loading('#distribute');
$.get('transportcart.php',{ccid:ccid,delbatch:batch},function(d)
{
$("#transportcart").html(d);
$('#distribute').load('transportcart.php?distribute=1');
});
}
function reloadcartsummary()
{
loading('.cart-summary');
$('.cart-summary').load('cart.php?summary=1');
}
function reloadbilling()
{
loading('#billing');
$('#billing').load('billing.php');
}
function reloadshipping()
{
loading('#transportcart');
$('#transportcart').load('transportcart.php');
$('#distribute').load('transportcart.php?distribute=1');
}
function changeshippingmode(batch,val)
{
$('.transportcostfinal').html('Loading...');
$('.grandtotal').html('Loading...');
$.get('transportcart.php',{shippingbatch:batch,val:val},function(d){
$("#transportcart").html(d);
});
}
function editbilling(id)
{
loading('#billeditor');
$('#billeditor').load('billing.php?editbilling='+id);
}
function delbilling(id)
{
loading('#billing');
$('#billing').load('billing.php?delbilling='+id);
}
function addbilling(ccid)
{
loading('#billeditor');
$('#billeditor').load('billing.php?addbilling='+ccid);
}
function ajaxsubmit(form,obj=null)
{
var fd = new FormData(form[0]);
if(obj==null)obj=form.parent()[0];
$(obj).fadeOut('slow',function()
{
$(obj).html("
Please wait.. sending..").fadeIn('slow');
$.ajax({
url: form.attr('action'),
type: form.attr('method'),
data: fd,
success:function(data){
$(obj).html(data);
},
cache: false,
contentType: false,
processData: false
});
});
}
function loading(t)
{
$(t).html("
Loading..");
}