$(document).ready(function(){

	sessionStorage.removeItem('quotation_details');
	sessionStorage.removeItem("approval");
	sessionStorage.removeItem('quotation_id');
	sessionStorage.removeItem("quotation");

	$('#invoicecreate').css("width","800px");

	$('.invoice_createbtn').click(function(){
		generateINVOICE_NO();
	  $("#invoice_create").modal('show');
	});

	$(document).on('click', 'div#boxforpi .fa-chevron-down', function () {
		 // $(document).find(".addressblock .fa-chevron-down").toggleClass("rtoate180");
        $(document).find(".boxforpiblock").stop().slideToggle(500);
    });

	$(document).on('click', 'div#boxforbill .fa-chevron-down', function () {
		// $(document).find(".addressblock .fa-chevron-down").toggleClass("rtoate180");
	   $(document).find(".boxforbillblock").stop().slideToggle(500);
   	});

	$(document).on('click', 'div#boxforship .fa-chevron-down', function () {
		// $(document).find(".addressblock .fa-chevron-down").toggleClass("rtoate180");
		$(document).find(".boxforshipblock").stop().slideToggle(500);
   	});

	$(document).on('click', 'div#boxforproduct .fa-chevron-down', function () {
		// $(document).find(".addressblock .fa-chevron-down").toggleClass("rtoate180");
		$(document).find(".boxforproductblock").stop().slideToggle(500);
   	});

	$(document).on('click', 'div#boxfornote .fa-chevron-down', function () {
		// $(document).find(".addressblock .fa-chevron-down").toggleClass("rtoate180");
		$(document).find(".boxfornoteblock").stop().slideToggle(500);
   	});

	invoice_modal();
});   
  $('#closebtn_invoice_without_pi').on('click',function(){
	var sessionforquotation=sessionStorage.getItem("quotation_details");
	console.log(sessionforquotation);
		var popup=confirm("Are you sure!!!");

		if(popup==true)
		{
			
			if(sessionforquotation!=null)
			{
				
				$.ajaxSetup({

					headers: {
			
					'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			
					}
			
				});  
			  	
				$.ajax({
					
							url:url_removeinvoiceunsaved,
			
				  			type:"POST",
			
							data:{sessionforquotation},
			 
				   			success:function(data){
					
								sessionStorage.removeItem('quotation_details');
							
								$('#add_new_invoice_without_pi').modal('hide');
								setTimeout(function(){
									location.reload();
								   }, 200);

					  		}
				 
						});
			}
			
			else
			{
			
				$('#add_new_invoice_without_pi').modal('hide');
			
				setTimeout(function(){
					location.reload();
				   }, 200);
		
			}

		}
	   
   
});
  
  
	function invoice_modal()
  	{
		$("#invoice_create").each(function() {
  
			var element = this;
	
	  		var pages = $(this).find('.modal-split');
  
			if (pages.length != 0)
			
			{
		  		pages.hide();
		  		pages.eq(0).show();
   
		  		var b_button = document.createElement("button");
				b_button.setAttribute("type","button");
				b_button.setAttribute("class","btn btn-primary pull-left");
				b_button.setAttribute("style","display: none;");
				b_button.innerHTML = "Back";
  
		  		var n_button = document.createElement("button");
				n_button.setAttribute("type","button");
				n_button.setAttribute("class","btn btn-primary pull-right testbutton");
				n_button.innerHTML = "Next";
  
		  		$(this).find('.modal-footer').append(b_button).append(n_button);
  
  
		  		var page_track = 0;
  
		  		$(n_button).click(function() {
		  
		  			this.blur();

			  		if(page_track == 0)
			  		{
				  		$(b_button).show();
			  		}

  
			  		if(page_track == pages.length-2)
			  		{								
							$('#quotationselectblock').addClass("hide"); 
							n_button.setAttribute("type","button");  
							n_button.setAttribute("class","btn btn-success pull-right");
							$(n_button).text("Submit");
							
					} 

			  		if(page_track == pages.length-1)
			  		{
						saveinvoice();
						
			  		}
			  
					if(page_track < pages.length-1)
			  		{
				  		page_track++;
						pages.hide();
				  		pages.eq(page_track).show();
			  		}
				
				});
  
		  		$(b_button).click(function() {
  
			  		if(page_track == 1)
			  		{
				  		$(b_button).hide();
			  		}
  
			  		if(page_track == pages.length-3)
			  		{
			
			  		}
			  
					if(page_track == pages.length-1)
			  		{
				
						n_button.removeAttribute("style","display:none;");
						n_button.removeAttribute("type","submit");  
						n_button.removeAttribute("class","btn btn-success");
						n_button.setAttribute("type","button");  
						n_button.setAttribute("class","btn btn-primary testbutton pull-right");
				  		$(n_button).text("Next");
			  		}
  
			  		if(page_track > 0)
			  		{
				  
						page_track--;
						pages.hide();
				  		pages.eq(page_track).show();
			  		}
				
				});
			
			}
  
		});
  	}

	function saveinvoice()
	{
		$('.custom-invoice-overlay').css("display","block");
		var generated_byinvoice=$('#generated_byinvoice').val();
		var invoice_no=$('#generated_invoiceno').val();
		var pi_no=$('#invoice_crepino').val();
		var quotation_no=$('#invoice_quotationno').val();
		var company_id=$('#invoice_companyid').val();
        var note = CKEDITOR.instances['invoice_crenotetextenter'].getData();
        var invoice_type = $('#pi_selectinvoice_type').val();
		var invoice_salesperson = $("#invoice_salesperson").val();
		$.ajaxSetup({

			headers: {
	   
			  'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
	  
			} 
	  
		});
	   
	   
		$.ajax({ 
		  
			url:url_storeinvoice,
	  
			method:"POST",
	   
			data:{
				invoice_no:invoice_no,
				pi_no:pi_no,
				quotation_no:quotation_no,
				company_id:company_id,
				invoice_type : invoice_type,
				generated_byinvoice:generated_byinvoice,
				note:note,
				sales_person : invoice_salesperson
			},
	  
			success:function(result)
	  
			{
			  
				$("#invoice_create").modal('hide');

			  	var success="";

      			success=success+
      
      			'<p style="text-align:center;"><b> Invoice created Successfully !!!</b></p>';
      
      			$('#invoice_success').append(success);
      			$('#invoice_success').removeClass("hide");
      
      			setTimeout(function(){
        			location.reload();
      			}, 200);
			}
		
		});
	}

	function generateINVOICE_NO(type='cpq')
	{
	 $.ajaxSetup({
	
		headers: {
		  
		'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
		  
		}
		  
		});  
		  $.ajax({
		  
			url:url_generatenumber,
		  
			type:"POST",
		  
			data:{
				"invoice_number":"invoice_number",
				"type": type
			},
			 
			success:function(data)
			{
				if(type == 'cpq'){
					if(data.invoice_no==null)
					  {
						var currentyear=new Date().getFullYear() ;
						var final=('GR'+currentyear+'00001');
						$(document).find('#generated_invoiceno').val(final);
					  }
					  else
					  {
						var lastno=data.invoice_no;
						var currentmonth=new Date().getMonth() ;
						var currentyear=new Date().getFullYear() ;

						if(currentmonth in ([0,1,2]))
						{
							--currentyear;
						}
						yearcheck =lastno.substr(2, 4);
						if(currentmonth == 3 && yearcheck != currentyear)
						{							
								tmpNum = '00001';
						}else{						
							var tmpNum = lastno.slice(6);
							//var number=lastno.replace('GR'+currentyear,'');
							tmpNum++;
							//  number++;
						}
						var getfinalnumber=pad(tmpNum,"5");
						var final=('GR'+currentyear+getfinalnumber);
						console.log(final);
						$(document).find('#generated_invoiceno').val(final);
					  }
					
				}
				else{
					if(data.invoice_no==null)
					{
						var currentyear=new Date().getFullYear() ;
						var final=('GRO'+currentyear+'00001');
						$(document).find('#generated_invoiceno').val(final);
					  }
					  else
					  {
						var lastno=data.invoice_no; 
						var currentmonth=new Date().getMonth() ;
						var currentyear=new Date().getFullYear() ;

						if(currentmonth in ([0,1,2]))
						{
							--currentyear;
						}
						yearcheck =lastno.substr(3, 4);
                        console.log(yearcheck);
						if(currentmonth == 3 && yearcheck != currentyear)
						{							
								tmpNum = '00001';
						}else{						
							var tmpNum = lastno.slice(7);
							//var number=lastno.replace('GR'+currentyear,'');
							tmpNum++;
							//  number++;
						}
						
						var getfinalnumber=pad(tmpNum,"5");
						var final=('GRO'+currentyear+getfinalnumber);
						console.log(final);

						$(document).find('#generated_invoiceno').val(final);
					  }
				}
			}
		  });
	}

	function pad (str, max) {
		str = str.toString();
		return str.length < max ? pad("0" + str, max) : str;
	} 
	
//*****************generating invoice without pi/quotation ****************************/	
$(document).ready(function(){
   $("#companyDetails").css("display", "none");
   $("#companybilling_address").css("display", "none");
   $("#companyshipping_address").css("display", "none");
   $("#qwe").css("display", "none");	
   
   prep_modal_invoice();
   $('#invoice_without_pi_creatation').css("width","1200px");
		
		$('.invoice_createbtn_without_PI').click(function(){
				console.log($(this).data('id'));
				
				generateINVOICE_NO($(this).data('id'));
			  $("#add_new_invoice_without_pi").modal('show');
			});
			
});


  function prep_modal_invoice()
  {
	
	$("#add_new_invoice_without_pi").each(function() {
	var element = this;
	var pages = $(this).find('.modal-split');
		console.log(pages.length);
		console.log(pages+"page");

	if (pages.length != 0)
	{
		pages.hide();
		pages.eq(0).show();
  
		var b_button = document.createElement("button");
			b_button.setAttribute("type","button");
			b_button.setAttribute("class","btn btn-primary pull-left");
			b_button.setAttribute("style","display: none;");
			b_button.innerHTML = "Back";
  
		var n_button = document.createElement("button");
		n_button.setAttribute("type","button");
		n_button.setAttribute("class","btn btn-primary pull-right testbutton");
		n_button.innerHTML = "Next";
  
		$(this).find('.modal-footer').append(b_button).append(n_button);
  
  
		var page_track = 0;
  
		$(n_button).click(function() {
		  
		this.blur();

		var quotation_companyid=$('#company_id').val();
		  

		if(quotation_companyid==""){
		
			$('#cnameblock').removeClass("hide");     

			$('#cnameblock').css("color","red");
  
			$('#cnameblock').text('Select company name!!!!');
				
			alert("please select company !!!!")
				
			return false;
			
		}
		
		else
			
		{
				
			$('#cnameblock').addClass("hide"); 
			
		}

		  	
  
		if(page_track == 0)
		
		{
		
			$(b_button).show();
		
		}

		
		if(page_track == pages.length-4)
		
		{
		
			console.log("first");
				
			firstpagedetailsInvoiceWithoutPI();
				
			n_button.removeAttribute("style","display:none;");
			n_button.removeAttribute("type","submit");  
			n_button.removeAttribute("class","btn btn-success");
			n_button.setAttribute("type","button");  
			n_button.setAttribute("class","btn btn-success pull-right");
			$(n_button).text("Save and Next");
				  
		}

			  
		if(page_track == pages.length-3)
		
			{ 
				var quotation_shippingid=$('#shipping_id').val();
				if(quotation_shippingid==""){
						$('#shippingaddressblock').removeClass("hide");     
						$('#shippingaddressblock').css("color","red");
						$('#shippingaddressblock').text('Select Shipping Address!!!!');
						alert("please Shipping Address !!!!")
						return false;
					
					}

					else
					
					{
						
						$('#shippingaddressblock').addClass("hide"); 
							
						console.log("secoend");
							
						secondpagedetailsInvoiceWithoutPI();

						n_button.removeAttribute("style","display:none;");
						n_button.removeAttribute("type","submit");  
						n_button.removeAttribute("class","btn btn-success");
						n_button.setAttribute("type","button");  
						n_button.setAttribute("class","btn btn-success pull-right");
						$(n_button).text("Save and Next");
					}
				  
			}
  
			  if((page_track == pages.length-2) && sessionStorage.getItem("invoice_company_saved") =="Y")
			  {

					var checkpagedata=checkdataofpage();
					console.log(checkpagedata);
					if(checkpagedata=='enterdata')
					{
						alert("Please Enter All Data Properly!");
						return false;
					}
					else if(checkpagedata==false)
					{
						alert("Please Add Data Using Add button!");
						return false;
					}
					else
					{
						thirdpagedetailsInvoiceWithoutPI();
						n_button.setAttribute("type","button");  
						n_button.setAttribute("class","btn btn-success pull-right");
						$(n_button).text("Submit");
					}
				
			  }
			  

			  if(page_track == pages.length-1)
			  {
				console.log("fourth");
				 submit_invoice_without_pi();
				
			  }
			   
		  
  
			  if(page_track < pages.length-1)
			  {
				  
				  page_track++;
  
				  pages.hide();
				  pages.eq(page_track).show();
			  }
  
  
		  });
  
		  $(b_button).click(function() {
  
			  if(page_track == 1)
			  {
				  $(b_button).hide();
			  }
  
			  if(page_track == pages.length-3)
			  {
			
				console.log("backtofirst");

			  }

			  if(page_track == pages.length-2)
			  {
			
				console.log("backtosecoend");

			  } 

			  if(page_track == pages.length-1)
			  {

				console.log("backtothird");
				$("#previewtablebody").empty();
				// n_button.removeAttribute("style","display:none;");
				// n_button.removeAttribute("type","submit");  
				// n_button.removeAttribute("class","btn btn-success");
				n_button.setAttribute("type","button");  
				n_button.setAttribute("class","btn btn-primary testbutton pull-right");
				  $(n_button).text("Next");
			  }
  
			  if(page_track > 0)
			  {
				  page_track--;
  
				  pages.hide();
				  pages.eq(page_track).show();
			  }
  
  
		  });
  
	}
  
	});
  }

function firstpagedetailsInvoiceWithoutPI()
{	
	
	var gstnumber=$('#details_gstno').val();
	var emailid=$('#details_email').val();
	var issuedate=$('#issues_date').val();
	var salesPerson = $("#invoice_salesperson").val();
	$('#preview_companygst').val(gstnumber);
	$('#preview_companyemail').val(emailid);
	$('#preview_issuedate').val(issuedate);

	// var data=gstnumber+","+emailid+","+issuedate;
	// sessionStorage.setItem("firstpage",data);
	
}

function secondpagedetailsInvoiceWithoutPI()
{
	var companyid=$('#Company_select').val();
	var issuedate=$('#issues_date').val();

	var billing_id=$('#billing_id').val();
	var billing_street1=$('#quotation_billadd1').val();
	var billing_street2=$('#quotation_billadd2').val();
	var billing_street3=$('#quotation_billadd3').val();
	var billing_city=$('#quotation_billcity').val();
	var billing_state=$('#quotation_billstate').val();
	var billing_country=$('#quotation_billcountry').val();
	var billing_pincode=$('#quotation_billpincode').val();
	var billing_mobileno=$('#quotation_billmobile').val();

	var shipping_id=$('#shipping_id').val();
	var shipping_street1=$('#quotation_shipadd1').val();
	var shipping_street2=$('#quotation_shipadd2').val();
	var shipping_street3=$('#quotation_shipadd3').val();
	var shipping_city=$('#quotation_shipcity').val();
	var shipping_state=$('#quotation_shipstate').val();
	var shipping_country=$('#quotation_shipcountry').val();
	var shipping_pincode=$('#quotation_shippincode').val();
	var shipping_mobileno=$('#quotation_shipmobile').val();
	var invoice_salesperson = $("#invoice_salesperson").val();

	$('#preview_billingid').val(billing_id);
	$('#preview_billadd1').val(billing_street1);
	$('#preview_billadd2').val(billing_street2);
	$('#preview_billadd3').val(billing_street3);
	$('#preview_billcity').val(billing_city);
	$('#preview_billstate').val(billing_state);
	$('#preview_billcountry').val(billing_country);
	$('#preview_billpincode').val(billing_pincode);
	$('#preview_billmobile').val(billing_mobileno);

	$('#preview_shippingid').val(shipping_id);
	$('#preview_shipadd1').val(shipping_street1);
	$('#preview_shipadd2').val(shipping_street2);
	$('#preview_shipadd3').val(shipping_street3);
	$('#preview_shipcity').val(shipping_city);
	$('#preview_shipstate').val(shipping_state);
	$('#preview_shipcountry').val(shipping_country);
	$('#preview_shippincode').val(shipping_pincode);
	$('#preview_shipmobile').val(shipping_mobileno);
	$("preview_salesperson").val();
	

	var test=sessionStorage.getItem("quotation_details");
	console.log(test+" quotation_details");
	
		
	if(test==null){
					
		save_invoice_details(companyid,issuedate,shipping_id,billing_id,invoice_salesperson);				
		
	}
	

}

function checkdataofpage()
{
	
	var listproduct_id=$('#Product_select').val();
    var listproduct_HSN=$('#product_HSN').val();
    var listproduct_SKU=$('#product_SKU').val();
    var listproduct_unitcost=$('#product_price').val().replace(/[\₹]/g, '');
    var listproduct_quantity=$('#product_quantity').val();
    var listproduct_csgst=$('#c_s_gsttype').val();
    var listproduct_igst=$('#i_gsttype').val();
    var taxvalue=$('#testing').val();
    var listproduct_total=$('#product_total').val();

	var quotation_itemid=[];
	var quotation_itemname=[];
    var quotation_HSN=[];
	var quotation_SKU=[];
    var quotation_unitcost=[];
	var quotation_unitcostcheck=[];
    var quotation_quantity=[];
    var quotation_csgst=[];
    var quotation_igst=[];
	var quotation_gsttotal=[];
	var quotation_rowtotal=[];

	$('.finallistname').each(function(){
		quotation_itemid.push($(this).data('id'));
	});

	$('.finallistname').each(function(){
		quotation_itemname.push($(this).text());
	});
	
	$('.finallistSKU').each(function(){
		quotation_SKU.push($(this).text());
	});

	$('.finallistHSN').each(function(){
		quotation_HSN.push($(this).text());
	});

	$('.finallistunitcost').each(function(){
		quotation_unitcost.push($(this).val());
	});

	$('.finallistunitcost').each(function(){
		quotation_unitcostcheck.push($(this).val().replace(/[\₹]/g, ''));
	});

	$('.finallistquantity').each(function(){
		quotation_quantity.push($(this).val());
	});

	$('.finallistcsgst').each(function(){
		quotation_csgst.push($(this).val());
	});

	$('.finallistigst').each(function(){	
		quotation_igst.push($(this).val());
	});

	$('.taxfield').each(function(){
		quotation_gsttotal.push($(this).val());
	});

	$('.finallisttotal').each(function(){
		quotation_rowtotal.push($(this).val());
	});
	
	if(quotation_itemid==''||quotation_itemname==''||quotation_HSN==''||quotation_SKU==''||quotation_unitcost==''||quotation_quantity==''||quotation_csgst==''&&quotation_igst==''||quotation_gsttotal==''||quotation_rowtotal=='')
	{
		if(listproduct_id==0||listproduct_HSN==''||listproduct_SKU==''||listproduct_unitcost==0||listproduct_quantity==0||listproduct_csgst==null&&listproduct_igst==null||taxvalue==''||listproduct_total=='₹00.00')
		{
			var data="enterdata";
			return data;
		}
		else
		{
			return false;	
		}
		
	}
	else
	{
		return true;
	}

}

function thirdpagedetailsInvoiceWithoutPI()
{

	var quotation_itemid=[];
	var quotation_itemname=[];
    var quotation_HSN=[];
	var quotation_SKU=[];
    var quotation_unitcost=[];
	var quotation_unitcostcheck=[];
    var quotation_quantity=[];
    var quotation_csgst=[];
    var quotation_igst=[];
	var quotation_gsttotal=[];
	var quotation_rowtotal=[];

	$('.finallistname').each(function(){
		quotation_itemid.push($(this).data('id'));
	});

	$('.finallistname').each(function(){
		quotation_itemname.push($(this).text());
	});
	
	var countofproduct=quotation_itemid.length;
	
	$('.finallistSKU').each(function(){
		quotation_SKU.push($(this).text());
	});

	$('.finallistHSN').each(function(){
		quotation_HSN.push($(this).text());
	});

	$('.finallistunitcost').each(function(){
		quotation_unitcost.push($(this).val());
	});

	$('.finallistunitcost').each(function(){
		quotation_unitcostcheck.push($(this).val().replace(/[\₹]/g, ''));
	});

	$('.finallistquantity').each(function(){
		quotation_quantity.push($(this).val());
	});

	$('.finallistcsgst').each(function(){
		quotation_csgst.push($(this).val());
	});

	$('.finallistigst').each(function(){	
		quotation_igst.push($(this).val());
	});

	$('.taxfield').each(function(){
		quotation_gsttotal.push($(this).val());
	});

	$('.finallisttotal').each(function(){
		quotation_rowtotal.push($(this).val());
	});
		for(var i=0;i<countofproduct;i++)
		{		
			var section="";
			if(quotation_csgst[i]=='null')
			{
				section=section+
				'<tr>'+
					'<td class="preview_item" data-id="'+quotation_itemid[i]+'">'+quotation_itemname[i]+'</td>'+
					'<td class="preview_HSN">'+quotation_HSN[i]+'</td>'+
					'<td class="preview_unitcost">'+quotation_unitcost[i]+'</td>'+
					'<td class="preview_quantity">'+quotation_quantity[i]+'</td>'+
					'<td id="finalthcs" class="preview_csgst" style="display:none;">'+quotation_csgst[i]+'</td>'+
					'<td id="finalthi" class="preview_igst">'+quotation_igst[i]+'</td>'+
					'<td class="preview_gsttotal">'+quotation_gsttotal[i]+'</td>'+
					'<td class="preview_rowtotal">'+quotation_rowtotal[i]+
					'</td>'+
				'</tr>';
				checkforproductprice(quotation_itemid[i],(quotation_unitcost[i]).replace(/[\₹]/g, ''));
			}
			else if(quotation_igst[i]=='null')
			{
				section=section+
				'<tr>'+
					'<td class="preview_item" data-id="'+quotation_itemid[i]+'">'+quotation_itemname[i]+'</td>'+
					'<td class="preview_HSN">'+quotation_HSN[i]+'</td>'+
					'<td class="preview_unitcost">'+quotation_unitcost[i]+'</td>'+
					'<td class="preview_quantity">'+quotation_quantity[i]+'</td>'+
					'<td id="finalthcs" class="preview_csgst">'+quotation_csgst[i]+'</td>'+
					'<td id="finalthi" class="preview_igst" style="display:none;">'+quotation_igst[i]+'</td>'+
					'<td class="preview_gsttotal">'+quotation_gsttotal[i]+'</td>'+
					'<td class="preview_rowtotal">'+quotation_rowtotal[i]+'</td>'+
				'</tr>';
				checkforproductprice(quotation_itemid[i],(quotation_unitcost[i]).replace(/[\₹]/g, ''));

			}
			
			$("#previewtablebody").append(section);
			$("#viewQuotationNote").html(CKEDITOR.instances['note-textarea'].getData());
		}			
}

function save_invoice_details(companyid,issuedate,shipping_id,billing_id,invoice_salesperson)
{
		
	var invoice_no=$('#generated_invoiceno').val();
	var generated_byquotation=$('#generated_byquotation').val();
	var note = $("#viewQuotationNote").html();
    var invoice_type = $('#pi_selectinvoice_type_ind').val();
	$.ajaxSetup({

		headers: {
		'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
		}
  
	  });  
	  $.ajax({
  
		  url:url_storecompanydetails_invoice,
	
		  type:"POST",
	
			data:{
			  invoice_no:invoice_no,
			  companyid:companyid,
			  issuedate:issuedate, 
			  shipping_id:shipping_id, 
			  billing_id:billing_id,
			  generated_byquotation:generated_byquotation,
			  note:note,
			  invoice_type : invoice_type,
			  sales_person : invoice_salesperson
		   },
	 
		   success:function(data){
			   console.log(data);
			   if(data.id){
				$('#generated_invoiceno').val(data.invoice_no);
				sessionStorage.setItem("quotation_details",data.id);
				
				sessionStorage.setItem("quotation_id",data.id);			
				sessionStorage.setItem("invoice_company_saved","Y");
			   }else{
			sessionStorage.setItem("invoice_company_saved","N");			

			   }				   
		  	},
			error: function (xhr, status, error) {
			console.log('Error:', error);
			console.log('Status:', status);
			console.log('Response:', xhr.responseText);
			sessionStorage.setItem("invoice_company_saved","N");			

    }
		});
		console.log("session company saved"+sessionStorage.getItem("invoice_company_saved"));

		sessionStorage.removeItem("quotation");
}


function submit_invoice_without_pi()

{
	$('.custom-invoice-overlay').css("display","block");
	var invoice_no=$('#generated_invoiceno').val();	
	
	var quotation_itemid=[];

	var quotation_HSN=[];

	var quotation_unitcost=[];

	var quotation_quantity=[];

	var quotation_csgst=[];

	var quotation_igst=[];

	var note = $("#viewQuotationNote").html();
	$('.finallistname').each(function(){
		quotation_itemid.push($(this).data('id'));
	});

	$('.finallistHSN').each(function(){
		quotation_HSN.push($(this).text());
	});

	$('.finallistunitcost').each(function(){
		quotation_unitcost.push($(this).val().replace(/[\₹]/g, ''));
	});

	$('.finallistquantity').each(function(){
		quotation_quantity.push($(this).val());
	});

	$('.finallistcsgst').each(function(){
		quotation_csgst.push($(this).val());
	});

	$('.finallistigst').each(function(){
		quotation_igst.push($(this).val());
	});
	
	var invoice_without_pi_ponumber = $('#invoice_without_pi_ponumber').val();
	var invoice_without_pi_paymentterm = $('#invoice_without_pi_paymentterm').val();
	var bank_id = $('#inv_without_pi_bank_select').val();
				if(sessionStorage.getItem("invoice_company_saved") =='Y'){
				 
				$.ajaxSetup({

					headers: {
					  
					'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
					  
					}
					  
					});  
						$.ajax({
					  
							   url:url_storeiteminvoice,
						
							  type:"POST",
						
								data:{
									invoice_no:invoice_no,
									quotation_itemid:quotation_itemid,
									quotation_HSN:quotation_HSN,
									quotation_unitcost:quotation_unitcost,
									quotation_quantity:quotation_quantity,
									quotation_csgst:quotation_csgst,
									quotation_igst:quotation_igst,
									note:note,
									invoice_without_pi_ponumber: invoice_without_pi_ponumber,
									invoice_without_pi_paymentterm :invoice_without_pi_paymentterm,
									bank_id : bank_id,
									
							   },
						 
							   success:function(data)
							   {
								  
									if(sessionStorage.getItem("approval")!=null)
									{
										// $('#add_new_quotation').modal('hide');
										$('#add_new_quotation').modal('hide');
											
										sessionStorage.removeItem('quotation_details');
										
										/*setTimeout(function(){
											mailapproval(quotation_no1);
										  }, 200);*/
										
										

										sessionStorage.removeItem("approval");
										success=success+
							
												'<p style="text-align:center;"><b>Invoice Created Successfully !!!</b></p>';
							
												$('#quotation_success').append(success);
												$('#quotation_success').removeClass("hide");
							
												setTimeout(function(){
													location.reload();
												}, 200);

									}
									else
									{
										var quotatioid= sessionStorage.getItem("quotation_id");
											
											sessionStorage.removeItem('quotation_details');
											sessionStorage.removeItem('quotation_id');
											$('#add_new_quotation').modal('hide');

											setapproval(quotatioid);

											
											var success="";

											success=success+
							
												'<p style="text-align:center;"><b>Invoice Created Successfully !!!</b></p>';
							
												$('#quotation_success').append(success);
												$('#quotation_success').removeClass("hide");
							
												setTimeout(function(){
													location.reload();
												}, 200);
											}
								}
							});
					 
				}
				else{
									var sessionforquotation= sessionStorage.getItem("quotation_details");
									console.log(sessionforquotation);
									$.ajaxSetup({

					headers: {
			
					'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			
					}
			
				});  
			  	
				$.ajax({
					
							url:url_removeinvoiceunsaved,
			
				  			type:"POST",
			
							data:{sessionforquotation},
			 
				   			success:function(data){
					
								sessionStorage.removeItem('quotation_details');
							
								$('#add_new_invoice_without_pi').modal('hide');
								setTimeout(function(){
									location.reload();
								   }, 200);

					  		}
				 
						});
									
									alert("Unable to save invoice");
									setTimeout(function(){
													location.reload();
												}, 200);
									return false;
				}
}

function checkforproductprice(quotation_itemid,quotation_unitcostcheck)
{
	var itemid=quotation_itemid;
	
	var unitcost=quotation_unitcostcheck;
			
	$.ajaxSetup({

		headers: 
		{
  
			'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')  

		}
  
	  });  
	  $.ajax({

		url:url_checkfinalprice,
 
	   	type:"POST",
 
		data:
		{
		   itemid:itemid,
		   unitcost:unitcost,
		},
		
		success:function(result)
		{
			console.log(result);
			if(result==0)
			{
				sessionStorage.setItem("approval","goforapproval");
			}
		}
	});
}

function setapproval(id)
{
	$.ajaxSetup({

		headers: 
		{
  
			'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')  

		}
  
	  });  
	  $.ajax({

		url:url_setapproval,
 
	   	type:"POST",
 
		data:
		{ id:id },
		
		success:function(result)
		{
			console.log(result);
		}
	});
}

function mailapproval(quotationno)
{
	var productrows="";
    var subttl=0;
    var gstttl=0;
    var grndttl=0;
    var i_show=0;
    var cs_show=0;

		$.ajaxSetup({

			headers: 
			{
  
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')  

			}
  
	  	});  
	  	$.ajax({

			url:url_getquotationdetail,
 
	   		type:"POST",
 
			data:
			{
				quotationno:quotationno
			},
		
			success:function(data)
			{
				console.log("mansi data");
				console.log(data);
				var countofproduct=(data.product).length;
        	
				var count=1;

				for (var i = 0; i <countofproduct; i++)
				{
						 
					if(data.product[i]['i_gst']=='null')
					{
					cs_show=1;
					total=(data.product[i]['unit_cost']*data.product[i]['quantity']);
					gst=((((data.product[i]['unit_cost']/100)*(((data.product[i]['c_s_gst']).replace(/[\*\^\'\!\%\+]/g, '').split(' ')[0]))*2)*data.product[i]['quantity']));
					subttl=subttl+total;
					gstttl=gstttl+gst;

					
					productrows += '<tr id=products-'+count+'>'+
						'<td align="left" width="5%" style="font-family:  Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 18px; line-height: 28px;">'+count+'</td>'+
						'<td id="vrajesh-testing" align="left" width="20%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 18px; line-height: 28px; ">'+data.product[i]['name']+'</td>'+
						'<td align="left" width="20%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 18px; line-height: 28px;">'+data.product[i]['HSN']+'</td>'+
						'<td align="left" width="10%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 18px; line-height: 28px;">'+data.product[i]['unit_cost']+'</td>'+
						'<td align="left" width="15%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 18px; line-height: 28px;">'+data.product[i]['quantity']+'</td>'+
						'<td align="left" width="15%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 18px; line-height: 28px;">'+data.product[i]['c_s_gst']+'</td>'+
						'<td align="left" width="15%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 18px; line-height: 28px;">₹'+((gst).toFixed(0))+'</td>'+
						'<td align="left" width="10%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 18px; line-height: 28px;">₹'+total+'</td>'+
					'</tr>'
					
					}
					else if(data.product[i]['c_s_gst']=='null')
					{
					i_show=1;
					total=(data.product[i]['unit_cost']*data.product[i]['quantity']);
					gst=(((data.product[i]['unit_cost']/100)*(data.product[i]['i_gst'].replace(/[\*\^\'\!\%\+\.]/g, '')))*data.product[i]['quantity']);
					subttl=subttl+total;
					gstttl=gstttl+gst;

					productrows += '<tr id=products-'+count+'>'+
						'<td align="left" width="5%" style="font-family:  Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 18px; line-height: 28px;">'+count+'</td>'+
						'<td id="vrajesh-testing" align="left" width="20%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 18px; line-height: 28px;">'+data.product[i]['name']+'</td>'+
						'<td align="left" width="20%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 18px; line-height: 28px;">'+data.product[i]['HSN']+'</td>'+
						'<td align="left" width="10%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 18px; line-height: 28px;">'+data.product[i]['unit_cost']+'</td>'+
						'<td align="left" width="15%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 18px; line-height: 28px;">'+data.product[i]['quantity']+'</td>'+
						'<td align="left" width="15%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 18px; line-height: 28px;">'+data.product[i]['i_gst']+'</td>'+
						'<td align="left" width="15%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 18px; line-height: 28px;">₹'+((gst).toFixed(0))+'</td>'+
						'<td align="left" width="10%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 18px; line-height: 28px;">₹'+total+'</td>'+
					'</tr>'

					}
				count++;
				
				}

        		$(document).find('#quotation_ida').val(quotationno);

          		grndttl=subttl+gstttl;

				if(i_show==1)
				{
					$("#quotation-detailsapproval").append( 
					'<table  style="max-width:700px;margin:20px;background-color:#fff;padding:50px;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px;-webkit-box-shadow:0 1px 3px rgba(0,0,0,.12),0 1px 2px rgba(0,0,0,.24);-moz-box-shadow:0 1px 3px rgba(0,0,0,.12),0 1px 2px rgba(0,0,0,.24);box-shadow:0 1px 3px rgba(0,0,0,.12),0 1px 2px rgba(0,0,0,.24); border-top: solid 10px green;">'+
					'<thead>'+
							'<tr>'+
								'<th style="text-align:left;"><a href="https://cpq.tannatechbiz.com/"><img style="max-width: 150px;" src="'+ttb_logo+'" alt="Tanna TechBiz LLP"></a></th>'+
								'<th style=" padding:0 0 0 20px; font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 20px; line-height: 24px; "><storng>TANNA TECH BIZ</storng>'+
									'<p style="margin:0px 0 0 30px;padding:0;font-size:13px; text-align: justify;">Vraj-Bhoomi, 22 New Jagnath Plot,</p>'+
									'<p style="margin:0px 0 0 30px;padding:0;font-size:13px; text-align: justify;">Rajkot, Gujarat, 360 001</p>'+
									'<p style="margin:0px 0 0 30px;padding:0;font-size:14px; text-align: justify;">+919974300810</p>'+
									'<p style="margin:0px 0 0 30px;padding:0;font-size:14px; text-align: justify;">info@tannatechbiz.com</p>'+
								'</th>'+
							'</tr>'+
						'</thead>'+
						'<tbody id="mailquotation">'+
							'<tr>'+
								'<td style="height:35px;"></td>'+
							'</tr>'+
							'<tr>'+
								'<td style="border:solid #ddd;border-width: 1px 0px 0px 1px; width:50%;padding:10px;vertical-align:top">'+
									'<p style="margin:0 0 10px 0;padding:0;font-size:15px;"><span style="display:block;font-weight:bold;font-size:15px">Invoice To:</span>'+data.company['name']+'</p>'+
									'<p style="margin:0 0 10px 0;padding:0;font-size:15px;"><span style="display:block;font-weight:bold;font-size:15px;">GST NO:</span>'+data.company['gstin']+'</p>'+
								'</td>'+
								'<td style="border:solid #ddd;border-width: 1px 1px 0px 0px; width:50%;padding:10px;vertical-align:top">'+
									'<p style="margin:0 0 10px 0;padding:0;font-size:15px;"><span style="display:block;font-weight:bold;font-size:15px;">Quotation No:</span> '+data.data['quotation_no']+'</p>'+
									'<p style="margin:0 0 10px 0;padding:0;font-size:15px;"><span style="display:block;font-weight:bold;font-size:15px;">Date of Invoice</span> '+data.data['issue_date']+'</p>'+
								'</td>'+
							'</tr>'+
							'<tr>'+
								'<td style="border:solid #ddd;border-width: 0px 0px 1px 1px; width:50%;padding:10px;vertical-align:top">'+
									'<p style="margin:0 0 10px 0;padding:0;font-size:15px;"><span style="display:block;font-weight:bold;font-size:15px; max-width: 40ch !important; word-break: break-word !important; ">Billing Address</span>'+data.billing['address_line1']+','+data.billing['address_line2']+','+data.billing['address_line3']+',</br>'+data.billing['name']+','+data.billing['state_title']+','+data.billing['country']+',</br>Pincode:-'+data.billing['pincode']+'</p>'+
									'<p style="margin:0 0 10px 0;padding:0;font-size:15px;"><span style="display:block;font-weight:bold;font-size:15px;">Email Id</span> abc@gmail.com</p>'+
									'<p style="margin:0 0 10px 0;padding:0;font-size:15px;"><span style="display:block;font-weight:bold;font-size:15px;">Phone Number</span> '+data.billing['mobile']+'</p>'+
								'</td>'+
								'<td style="border:solid #ddd;border-width: 0px 1px 1px 0px; width:50%;padding:10px;vertical-align:top">'+
									'<p style="margin:0 0 10px 0;padding:0;font-size:15px;"><span style="display:block;font-weight:bold;font-size:15px; max-width: 40ch !important; word-break: break-word !important;">Shipping Address</span>'+data.shipping['address_line1']+','+data.shipping['address_line2']+','+data.shipping['address_line3']+',</br>'+data.shipping['name']+','+data.shipping['state_title']+','+data.shipping['country']+',</br>Pincode:-'+data.shipping['pincode']+'</p>'+
									'<p style="margin:0 0 10px 0;padding:0;font-size:15px;"><span style="display:block;font-weight:bold;font-size:15px;">Email Id</span> abc@gmail.com</p>'+
									'<p style="margin:0 0 10px 0;padding:0;font-size:15px;"><span style="display:block;font-weight:bold;font-size:15px;">Phone Number</span> '+data.shipping['mobile']+'</p>'+
								'</td>'+
							'</tr>'+
						
							'<tr>'+
								'<td colspan="2" style="font-size:20px;padding:30px 15px 0 0;">Products</td>'+
							'</tr>'+
					
							'<tr>'+
								'<td colspan="2" align="left" bgcolor="#ffffff" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px;">'+
									'<table border="0" cellpadding="0" cellspacing="0" width="100%">'+
										'<tr>'+
											'<td align="left" bgcolor="#D2C7BA" width="5%"  style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px;"><strong>NO</strong></td>'+
											'<td align="left" bgcolor="#D2C7BA" width="20%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px; "><strong>Product Name</strong></td>'+
											'<td align="left" bgcolor="#D2C7BA" width="20%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px;"><strong>HSN</strong></td>'+
											'<td align="left" bgcolor="#D2C7BA" width="10%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px;"><strong>Unit Cost</strong></td>'+
											'<td align="left" bgcolor="#D2C7BA" width="15%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px;"><strong>Quantity</strong></td>'+
											'<td align="left" bgcolor="#D2C7BA" width="15%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px;"><strong>IGST</strong></td>'+
											'<td align="left" bgcolor="#D2C7BA" width="15%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px;"><strong>GST Amount</strong></td>'+
											'<td align="left" bgcolor="#D2C7BA" width="10%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px;"><strong>Total</strong></td>'+
										'</tr>'+
					
										productrows+
				
										'<tr>'+
											'<td colspan="6"></td>'+
											'<td align="left" width="10%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px; border-top: 2px dashed #D2C7BA; border-bottom: 2px dashed #D2C7BA;"><strong>Sub Total</strong></td>'+
											'<td align="left" width="10%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px; border-top: 2px dashed #D2C7BA; border-bottom: 2px dashed #D2C7BA;"><strong>₹'+((subttl).toFixed(0))+'</strong></td>'+
										'</tr>'+
										'<tr>'+
											'<td colspan="6"></td>'+
											'<td align="left" width="10%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px; border-top: 2px dashed #D2C7BA; border-bottom: 2px dashed #D2C7BA;"><strong>GST Total</strong></td>'+
											'<td align="left" width="10%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px; border-top: 2px dashed #D2C7BA; border-bottom: 2px dashed #D2C7BA;"><strong>₹'+((gstttl).toFixed(0))+'</strong></td>'+
										'</tr>'+
										'<tr>'+
											'<td colspan="6"></td>'+
											'<td align="left" width="10%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px; border-top: 2px dashed #D2C7BA; border-bottom: 2px dashed #D2C7BA;"><strong>Total</strong></td>'+
											'<td align="left" width="10%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px; border-top: 2px dashed #D2C7BA; border-bottom: 2px dashed #D2C7BA;"><strong>₹'+((grndttl).toFixed(0))+'</strong></td>'+
										'</tr>'+
									'</table>'+
								'</td>'+
							'</tr>'+
						'</tbody>'+
						'<tfooter>'+
							'<tr>'+
								'<td colspan="2" style="font-size:16px;padding:50px 15px 0 15px;">'+
									'<strong style="display:block;margin:0 0 10px 0;">Note:</strong>'+
									'<p>'+data.company['note']+'</p>'+
								'</td>'+
							'</tr>'+
						'</tfooter>'+
					'</table>'
					
				);
				
				
				}
				else if(cs_show==1)
				{
				$("#quotation-detailsapproval").append(
					
					'<table  style="max-width:700px;margin:20px;background-color:#fff;padding:50px;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px;-webkit-box-shadow:0 1px 3px rgba(0,0,0,.12),0 1px 2px rgba(0,0,0,.24);-moz-box-shadow:0 1px 3px rgba(0,0,0,.12),0 1px 2px rgba(0,0,0,.24);box-shadow:0 1px 3px rgba(0,0,0,.12),0 1px 2px rgba(0,0,0,.24); border-top: solid 10px green;">'+
						'<thead>'+
							'<tr>'+
								'<th style="text-align:left;"><img style="max-width: 150px;" src="https://www.bachanatours.in/book/img/logo.png" alt="bachana tours"></th>'+
								'<th style=" padding:0 0 0 20px; font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 20px; line-height: 24px; "><storng>TANNA TECH BIZ</storng>'+
									'<p style="margin:0px 0 0 30px;padding:0;font-size:13px; text-align: justify;">Vraj-Bhoomi, 22 New Jagnath Plot,</p>'+
									'<p style="margin:0px 0 0 30px;padding:0;font-size:13px; text-align: justify;">Rajkot, Gujarat, 360 001</p>'+
									'<p style="margin:0px 0 0 30px;padding:0;font-size:14px; text-align: justify;">+919974300810</p>'+
									'<p style="margin:0px 0 0 30px;padding:0;font-size:14px; text-align: justify;">info@tannatechbiz.com</p>'+
								'</th>'+
							'</tr>'+
						'</thead>'+
						'<tbody id="mailquotation">'+
							'<tr>'+
								'<td style="height:35px;"></td>'+
							'</tr>'+
							'<tr>'+
								'<td style="border:solid #ddd;border-width: 1px 0px 0px 1px; width:50%;padding:10px;vertical-align:top">'+
									'<p style="margin:0 0 10px 0;padding:0;font-size:15px;"><span style="display:block;font-weight:bold;font-size:15px">Invoice To:</span>'+data.company['name']+'</p>'+
									'<p style="margin:0 0 10px 0;padding:0;font-size:15px;"><span style="display:block;font-weight:bold;font-size:15px;">GST NO:</span>'+data.company['gstin']+'</p>'+
								'</td>'+
								'<td style="border:solid #ddd;border-width: 1px 1px 0px 0px; width:50%;padding:10px;vertical-align:top">'+
									'<p style="margin:0 0 10px 0;padding:0;font-size:15px;"><span style="display:block;font-weight:bold;font-size:15px;">Quotation No:</span> '+data.data['quotation_no']+'</p>'+
									'<p style="margin:0 0 10px 0;padding:0;font-size:15px;"><span style="display:block;font-weight:bold;font-size:15px;">Date of Invoice</span> '+data.data['issue_date']+'</p>'+
								'</td>'+
							'</tr>'+
							'<tr>'+
								'<td style="border:solid #ddd;border-width: 0px 0px 1px 1px; width:50%;padding:10px;vertical-align:top">'+
									'<p style="margin:0 0 10px 0;padding:0;font-size:15px;"><span style="display:block;font-weight:bold;font-size:15px;max-width: 40ch !important; word-break: break-word !important;">Billing Address</span>'+data.billing['address_line1']+','+data.billing['address_line2']+','+data.billing['address_line3']+',</br>'+data.billing['name']+','+data.billing['state_title']+','+data.billing['country']+',</br>Pincode:-'+data.billing['pincode']+'</p>'+
									'<p style="margin:0 0 10px 0;padding:0;font-size:15px;"><span style="display:block;font-weight:bold;font-size:15px;">Email Id</span> abc@gmail.com</p>'+
									'<p style="margin:0 0 10px 0;padding:0;font-size:15px;"><span style="display:block;font-weight:bold;font-size:15px;">Phone Number</span> '+data.billing['mobile']+'</p>'+
								'</td>'+
								'<td style="border:solid #ddd;border-width: 0px 1px 1px 0px; width:50%;padding:10px;vertical-align:top">'+
									'<p style="margin:0 0 10px 0;padding:0;font-size:15px;"><span style="display:block;font-weight:bold;font-size:15px;max-width: 40ch !important; word-break: break-word !important;">Shipping Address</span>'+data.shipping['address_line1']+','+data.shipping['address_line2']+','+data.shipping['address_line3']+',</br>'+data.shipping['name']+','+data.shipping['state_title']+','+data.shipping['country']+',</br>Pincode:-'+data.shipping['pincode']+'</p>'+
									'<p style="margin:0 0 10px 0;padding:0;font-size:15px;"><span style="display:block;font-weight:bold;font-size:15px;">Email Id</span> abc@gmail.com</p>'+
									'<p style="margin:0 0 10px 0;padding:0;font-size:15px;"><span style="display:block;font-weight:bold;font-size:15px;">Phone Number</span> '+data.shipping['mobile']+'</p>'+
								'</td>'+
							'</tr>'+
					
							'<tr>'+
								'<td colspan="2" style="font-size:20px;padding:30px 15px 0 0;">Products</td>'+
							'</tr>'+
					
							'<tr>'+
								'<td colspan="2" align="left" bgcolor="#ffffff" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px;">'+
									'<table border="0" cellpadding="0" cellspacing="0" width="100%">'+
										'<tr>'+
											'<td align="left" bgcolor="#D2C7BA" width="5%"  style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px;"><strong>NO</strong></td>'+
											'<td align="left" bgcolor="#D2C7BA" width="20%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px;"><strong>Product Name</strong></td>'+
											'<td align="left" bgcolor="#D2C7BA" width="20%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px;"><strong>HSN</strong></td>'+
											'<td align="left" bgcolor="#D2C7BA" width="10%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px;"><strong>Unit Cost</strong></td>'+
											'<td align="left" bgcolor="#D2C7BA" width="15%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px;"><strong>Quantity</strong></td>'+
											'<td align="left" bgcolor="#D2C7BA" width="10%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px;"><strong>C_S_GST</strong></td>'+
											'<td align="left" bgcolor="#D2C7BA" width="15%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px;"><strong>GST Amount</strong></td>'+
											'<td align="left" bgcolor="#D2C7BA" width="10%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px;"><strong>Total</strong></td>'+
										'</tr>'+
					
										productrows+
				
										'<tr>'+
											'<td colspan="6"></td>'+
											'<td align="left" width="10%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px; border-top: 2px dashed #D2C7BA; border-bottom: 2px dashed #D2C7BA;"><strong>Sub Total</strong></td>'+
											'<td align="left" width="10%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px; border-top: 2px dashed #D2C7BA; border-bottom: 2px dashed #D2C7BA;"><strong>₹'+((subttl).toFixed(0))+'</strong></td>'+
										'</tr>'+
										'<tr>'+
											'<td colspan="6"></td>'+
											'<td align="left" width="10%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px; border-top: 2px dashed #D2C7BA; border-bottom: 2px dashed #D2C7BA;"><strong>GST Total</strong></td>'+
											'<td align="left" width="10%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px; border-top: 2px dashed #D2C7BA; border-bottom: 2px dashed #D2C7BA;"><strong>₹'+((gstttl).toFixed(0))+'</strong></td>'+
										'</tr>'+
										'<tr>'+
											'<td colspan="6"></td>'+
											'<td align="left" width="10%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px; border-top: 2px dashed #D2C7BA; border-bottom: 2px dashed #D2C7BA;"><strong>Total</strong></td>'+
											'<td align="left" width="10%" style="font-family: Source Sans Pro, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px; border-top: 2px dashed #D2C7BA; border-bottom: 2px dashed #D2C7BA;"><strong>₹'+((grndttl).toFixed(0))+'</strong></td>'+
										'</tr>'+
									'</table>'+
								'</td>'+
							'</tr>'+
						'</tbody>'+
						'<tfooter>'+
							'<tr>'+
								'<td colspan="2" style="font-size:16px;padding:50px 15px 0 15px;">'+
									'<strong style="display:block;margin:0 0 10px 0;">Note:</strong>'+
									'<p>'+data.company['note']+'</p>'+
								'</td>'+
							'</tr>'+
						'</tfooter>'+
					'</table>'
					
				);
				
				
				}     
				sendmailforapp();      
      		}
      
    	});
    
}

function sendmailforapp()
{
	var receiverID="mansi@tannatechbiz.com";
	var mailsubject="New Quotation For Approval # from TANNA TECHBIZ LLP.";
	var quotation_ida=$('#quotation_idapproval').val();
	var mailbody=CKEDITOR.instances['compose-textareaapproval'].getData();
	var mailquotation=$('#quotation-detailsapproval').html();
	
	$.ajaxSetup({

	  headers: {

	  'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')

	  }

	});  
	$.ajax({
 
	  url:url_postemail,

	  method:"POST",

	  data:
	  {
		receiverID:receiverID,
		mailsubject:mailsubject,
		mailbody:mailbody,
		quotation_ida:quotation_ida,
		mailquotation:mailquotation
	  },
	  success:function(data){

		  console.log(data);
		  
		
	  }
	  
	})
}
