/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@buy-addons.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author    Buy-addons    <contact@buy-addons.com>
* @copyright 2007-2020 Buy-addons
* @license   http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*/

function reload_product(json_product){
	var html_pr = '';
	var html_tt = '';
			html_pr+= '<table class="table" id="orderProducts">';
			html_pr+= 	'<thead>';
			html_pr+= 		'<tr>';
			html_pr+= 			'<th></th>';
			html_pr+= 			'<th><span class="title_box ">'+table_header_product+'</span></th>';
			html_pr+= 			'<th>';
			html_pr+= 				'<span class="title_box ">'+table_header_sku+'</span>';
			html_pr+= 			'</th>';	
			html_pr+= 			'<th>';	
			html_pr+= 				'<span class="title_box ">'+table_header_UP+'</span>';	
			html_pr+= 			'</th>';	
			html_pr+= 			'<th><span class="title_box ">'+table_header_Qty+'</span></th>';	
			html_pr+= 			'<th>';	
			html_pr+= 				'<span class="title_box ">'+table_header_Total_1+'</span>';
			html_pr+= 			'</th>';
			html_pr+= 			'<th colspan="2"></th>';	
			html_pr+=			'<th></th>';
			html_pr+= 			'</tr>';
			html_pr+= 	'</thead>';
			
	for(i=0;i<json_product['number_product'];i++){				
			html_pr+= 	'<tbody >';
			html_pr+= 		'<tr height="52">';
			html_pr+= 			'<td><img src="'+json_product[i].link_img+'" alt="" class="imgm img-thumbnail" style = "width: 60px;"></td>';				
			html_pr+= 			'<td><a href="'+json_product[i].link_product+'">';				
			html_pr+= 				'<span>'+json_product[i].product_name+'</span>';					
			html_pr+= 				'</a>';
			html_pr+= 				'<div>'+json_product[i].combination+'</div>';
			html_pr+= 			'</td>';
			html_pr+= 			'<td>';
			html_pr+= 				'<span>'+json_product[i].reference+'</span>';
			html_pr+= 			'</td>';				
			html_pr+= 			'<td>';
			html_pr+= 				'<span>';
			html_pr+= 					sign_currency + parseFloat(json_product[i].product_pri).toFixed(2);
			html_pr+= 				'</span>';
			html_pr+= 			'</td>';
			html_pr+= 			'<td>';
			html_pr+= 				'<span>'+json_product[i].product_qty+'</span>';
			html_pr+= 			'</td>';
			html_pr+= 			'<td>';
			html_pr+= 				sign_currency + parseFloat(json_product[i].total_pri).toFixed(2);
			html_pr+= 			'</td>';
			html_pr+= 			'<td colspan="2">&nbsp;</td>';
			html_pr+= 			'<td class="text-right">';
			html_pr+= 				'<div class="btn-group">';
			html_pr+= 					'<a onclick="del_product_view('+parseInt(json_product[i].id_combination)+','+json_product[i].id_quote+','+json_product[i].id_product+',this)" href="javascript:void(0);" name = "btn_del_view" value = "'+json_product[i].id_combination+'_'+json_product[i].id_product+'" class="btn btn-default del_product_view">';
			html_pr+= 						'<i class="icon-trash"></i> ';
			html_pr+=						table_header_delete;
			html_pr+= 					'</a>';
			html_pr+= 				'</div>';
			html_pr+= 			'</td>';
			html_pr+= 		'</tr>';
			html_pr+= 	'</tbody>';		
						
	}		
			html_pr+= '</table>';
	
			html_tt+= 	'<table class="table">';
			html_tt+= 		'<tbody>';
			html_tt+= 			'<tr>';
			html_tt+= 				'<td class="text-right">'+table_header_Total_2+'</td>';	
			html_tt+= 				'<td class="text-right">';
			if(json_product['number_product'] > 0)
			{	
				html_tt+= 				sign_currency + parseFloat(json_product['total_price']).toFixed(2);
			}else
			{
				html_tt+= 	sign_currency + '0,00 ';
			}
			html_tt+= 			'</td>';
			html_tt+= 		'</tr>';
			html_tt+= 	'</tbody>';			
			html_tt+='</table>';
			
	jQuery(".total_price").html(html_tt);			
    jQuery(".list_product").html(html_pr);
}

function reload_mess(json_mess){
	var html = '';
	for(i=0;i<json_mess['number_mess'];i++){
		if(json_mess[i]['type'] == 0)
		{
			html+= '<div class = "message_quote_adm">';
			html+= 		'<div class = "box_chat">';
			html+= 			'<span class = "text_chat">'+json_mess[i].content_mes+'</span>';				
			html+= 		'</div>';				
			html+= 		'<div class = "date_info">';					
			html+= 			'added on '+jQuery.format.date(json_mess[i].date_send,'MMM dd,yyyy')+' at '+jQuery.format.date(json_mess[i].date_send,'HH:MMa')+' pm by '+json_mess[i].email+'   <a onclick="del_message('+json_mess[i].id+','+json_mess[i].id_quote+')" href="javascript:void(0);" type="submit" class = "del_message" id = "'+json_mess[i].id_quote+'" value = "'+json_mess[i].id+'">'+table_header_delete_messa+'</a>';
			html+= 		'</div>';
			html+= '</div>';
		}else
		{
			html+= '<div class = "message_quote_adm" >';
			html+= 		'<div class = "box_chat" style = "background-color:#e8d6b7;">';
			html+= 			'<span class = "text_chat">'+json_mess[i].content_mes+'</span>';				
			html+= 		'</div>';
			html+= 		'<div class = "date_info">';
			html+= 			'added on '+jQuery.format.date(json_mess[i].date_send,'MMM dd,yyyy')+' at '+jQuery.format.date(json_mess[i].date_send,'HH:MMa')+' pm by '+json_mess[i].email+'   <a onclick="del_message('+json_mess[i].id+','+json_mess[i].id_quote+')" href="javascript:void(0);" type="submit" class = "del_message" id = "'+json_mess[i].id_quote+'" value = "'+json_mess[i].id+'">'+table_header_delete_messa+'</a>';
			html+= 		'</div>';
			html+= '</div>';					
		}			
	}			
    jQuery(".box_message").html(html);
}
function del_message(id_mess,id_quote){
	var conditation = 0;
	var baseurl = window.location.hostname;
	var demoMod = demo_mod;
	if(demoMod == 1){
    	jQuery(".show_demoMod").show();
    	return false;
    }	
	jQuery.ajax({
	
			type: 'POST',//phương thức gửi
			jscrossDomain: window.location.hostname,
			crossDomain: true,
			url: '../index.php?controller=delmessagedbboo&fc=module&module=askforaquotemodul', // lấy link của controller mới
			data:'id_mess=' + id_mess + '&id_quote=' + id_quote + '&conditation=' + conditation + '&quote_token=' + token_askaquotemodule + '&ajax=1',  // lấy dữ liệu từ id product ở trên định nghĩa
			dataType:"json",
			success: function(json_mess,textStatus,jqXHR)
			{
				reload_mess(json_mess);
				jQuery(".show_message").show();
				jQuery(".show_message").fadeOut(5000);
            },
			error: function(XMLHttpRequest, textStatus, errorThrown)
			{
			}
			
	});
	
}
function del_product_view(id_combi_view,id_quote,id_product_view,ob){
	var conditation = 1;
	var baseurl = window.location.hostname;
	var demoMod = demo_mod;
	if(demoMod == 1){
    	jQuery(".show_demoMod").show();
    	return false;
    }
	jQuery.ajax({
		type: 'POST',//phương thức gửi
		jscrossDomain: window.location.hostname,
		crossDomain: true,
		url: '../index.php?controller=delmessagedbboo&fc=module&module=askforaquotemodul', // lấy link của controller mới
		data:'id_quote=' + id_quote + '&id_combination=' + id_combi_view + '&conditation=' + conditation + '&id_product_view_dbboo=' + id_product_view + '&demoMod=' + demoMod + '&quote_token=' + token_askaquotemodule + '&ajax=1',  // lấy dữ liệu từ id product ở trên định nghĩa
		dataType:"json",
		beforeSend: function() {
			$(ob).parent().find(".icon-trash").removeClass("icon-trash").addClass("icon-refresh icon-spin");
		},
		success: function(json_product,textStatus,jqXHR)
		{
			$(ob).closest('tr').remove();
			$('.total_price_quote_dbboo span').text(json_product['total_price_formatted']);
			$('#td_totalprice_newquote, .td_fixed_total_price').val(json_product['total_price']);
			$('.batotalproducts').val(json_product['total_price']);
			jQuery(".show_message").show();
			jQuery(".show_message").fadeOut(5000);
			
		}
	});
	
}
