
  $("#quotationprintoption").css("width","500px");
var quotation_id;
var optionappend=0;
    $("#quotations").on("click", ".printInvoice", function(){
     quotation_id=$(this).data('id');
    
	
    var appendoption="";
	
	if(quotation_id.slice(0,1) == 'v'){
		
			quotation_id = quotation_id.substring(1);
		   printQuotation(optionappend ,quotation_id,1);
	}else{
			quotation_id = quotation_id.substring(1);
			appendoption=appendoption+'<label class="control-label"> Select Print Option </label>'+'<select class="form-control printoption_select" id="printoption_select" style="width: 100%;">'+'<option value="0" disabled selected value >- Select print option -</option>'+'<option value="1">Print with logo</option>'+'<option value="2">Print without logo</option>'+'</select>';

			$('#selectappend').html(appendoption);
			$("#quotation_printoption").modal('show');
	}
});
			$('.printoption_submit').on('click',function(){
            $("#quotation_printoption").modal('hide');
            optionappend=$('#printoption_select').find(':selected').val();
            printQuotation(optionappend ,quotation_id,0);
	});
          
      $('#close_printoptionquotation').on('click',function(){
        
        $('#selectappend').empty();
      });



 


function printQuotation(optionappend,quotation_id,isViewOnly){
	var result="";var invoice="";var billaddress_line3="";var shipaddress_line3="";var header = "";
    var mysty='<style> .invoice { border: 2px solid black; height: 1250px; width: 1050px; }.invoice-header{border-bottom: 2px solid black;  height: 150px;width: 100%;}.invoice-address{border-bottom: 2px solid black;height: 250px;width: 100%;padding-left:13px;}.invoice-table{border-bottom: 2px solid black;height: 600px;width: 100%;}.invoice-total{border-bottom: 2px solid black;}.address-col{border-right: 2px solid black;height: 220px;}#product_table{max-height: 650px;margin-left: 13px;table-layout:fixed;}#product_table thead{border-bottom: 2px solid black;}.total-row{border-bottom: 2px solid black;}.gst-info{border-right: 2px solid black;}.bank-payment{border-bottom: 2px solid black;}.gst-total{border-bottom: 2px solid black;}.empty-head{height: 200px;}.empty-foot{height: 135px;}</style>';
	
	
  $.ajaxSetup({
    headers: {
      'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
  });  
    
  $.ajax({

    url:url_getquotationdetail,

    method:"POST",

    data:
    {id:quotation_id},
    success:function(data){
		result=productrowcalculaton(data);
        var title = data.data['quotation_no'];
		if(optionappend == 1 || isViewOnly){
		    mysty='<style> .invoice { border: 2px solid black; height: 1490px; width: 1050px; } .invoice-header {  height: 143px; width: 100%; } .invoice-address { border-bottom: 2px solid black; height: 250px; width: 100%;padding-left:13px; } .invoice-table { border-bottom: 2px solid black; height: 600px; width: 100%; padding-left:13px } .invoice-total { border-bottom: 2px solid black; } .address-col { border-right: 2px solid black; height: 220px; } .total-row { border-bottom: 2px solid black; } .gst-info { border-right: 2px solid black; } .bank-payment { border-bottom: 2px solid black; } .gst-total { border-bottom: 2px solid black; } #product_table { max-height: 600px; table-layout:fixed; } </style>';
			header = printHeader();
		}
		else{
			invoice ='<div class="empty-head"></div>';
		}
		
		  invoice= invoice+
          '<div class="invoice">'
		  + header 
		  + getBillingShippingAddress(data,'Quotation') 
		  + productData(result)
			+
            getFootData(result , data,'')
			+printFooter('');
            
          $("#printdivision").html(invoice);
		  if(!isViewOnly){
				printCustom(mysty,title);
				
		  }else{
			  var mystyle1 ="<style> .invoice { border: 2px solid black; height: 1250px; width: 1050px; }.invoice-header{border-bottom: 2px solid black;  height: 150px;width: 100%;}.invoice-address{border-bottom: 2px solid black;height: 250px;width: 100%;padding-left:13px;}.invoice-table{border-bottom: 2px solid black;height: 600px;width: 100%;}.invoice-total{border-bottom: 2px solid black;}.address-col{border-right: 2px solid black;height: 220px;}#product_table{max-height: 650px;margin-left: 13px;table-layout:fixed;}#product_table thead{border-bottom: 2px solid black;}.total-row{border-bottom: 2px solid black;}.gst-info{border-right: 2px solid black;}.bank-payment{border-bottom: 2px solid black;}.gst-total{border-bottom: 2px solid black;}.empty-head{height: 200px;}.empty-foot{height: 135px;}</style>";
	
				$("#printdivisionqv").html(invoice);
				$('.custom-modal-title').html('Quotation');
				$("#quotation_view").modal('show');
		  }
	}	
  });
  

}

function printCustom(mysty,title){
	  var mystyle='<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">';
	  var divContents = document.getElementById("printdiv").innerHTML;
	  var a = window.open('', '', 'height=3508, width=2480');
	  a.document.write('<html><body style="margin-left:30px;">');
	  a.document.write(mystyle);
	  a.document.write(mysty);
	  a.document.write(divContents);
	  a.document.title = title;
	  a.document.write('</body></html>');
	  a.document.close();
	  setTimeout(function(){
		a.print();
	  }, 500);

	  $('#printdivision').empty();
	  }


function printHeader(){
	var header = 
            '<div class="invoice-header">'+
              '<div class="row">'+
                '<div class="col-8 col-md-8" style="padding-left: 30px;">'+
                  '<table>'+
                    '<thead>'+
                      '<tr>'+
                        '<th colspan="2" style="padding-top: 10px; text-align: center; "><h2>Tanna TechBiz LLP</h2></th>'+
                      '</tr>'+
                    '</thead>'+
                    '<tbody>'+
                      '<tr>'+
                        '<td style="width: 50%;"><p style="font-size: 13px;"> Regi. office<br><b>INDIA.</b><br><i class="far fa-map-marker-alt"></i> Vraj-Bhoomi, 22 New Jagnath Plot, Rajkot, Gujarat, 360 001<br><i class="far fa-phone-square"></i> +91-281 6623999</p></td>'+
                        '<td style="width: 50%;"><p style="font-size: 13px;"> Network Ofiice<br><b>USA.</b><br><i class="far fa-map-marker-alt"></i> 1111 Alta Mira Dr,Unit A, Santa Clara,California,95051<br><i class="far fa-phone-square"></i> +1-408-991-5892<br><i class="far fa-envelope"></i> info@tannatechbiz.com</p></td>'+
                      '</tr>'+
                    '</tbody>'+
                  '</table>'+
                '</div>'+ 
                '<div class="col-4" style="padding-top: 5px;">'+
                  '<table>'+
                    '<tbody>'+
                      '<tr>'+
                        '<td style="padding-left: 70px;">'+
                          '<a target="_blank" href="https://www.tannatechbiz.com/">'+
                            '<img src="'+ttb_logo+'" width="200px" height="120px"/>'+
                          '</a>'+
                        '</td>'+
                      '</tr>'+
                    '</tbody>'+
                  '</table>'+
                '</div>'+
              '</div>'+
            '</div>';
			
			return header;
}

function getBillingShippingAddress(data,printDocType){
		  var date = new Date(data.data.created_at);
          var printdate=(date.getDate()+ '/' +(date.getMonth() + 1)+ '/' +date.getFullYear());

          if(data.billing['address_line3']=='null')
          {
            billaddress_line3=" ";
          }
          else
          {
            billaddress_line3=data.billing['address_line3'];
          }
          if(data.shipping['address_line3']=='null')
          {
            shipaddress_line3=" ";
          }
          else
          {
            shipaddress_line3=data.shipping['address_line3'];
          }
         
          var billingShippingData = '<div class="invoice-address">'+
              '<div class="row custom-heading" style="border:2px solid black; height: 32px; width: 1050px; background-color:	#F0F0F0;">'+
                '<table>'+
                  '<tbody>'+
                    '<tr>'+
                      '<td>';
                       if(printDocType== "Invoice"){
                        billingShippingData=billingShippingData+'<p style="padding-left:450px; font-size:1.50rem;"><b>Tax '+printDocType+'</b></p>';
          }else{
                        billingShippingData=billingShippingData+'<p style="padding-left:450px; font-size:1.50rem;"><b>'+printDocType+'</b></p>';
          }
             billingShippingData = billingShippingData+         '</td>'+
                    '</tr>'+
                  '</tbody>'+
                '</table>'+
              '</div>'+
              
              '<div class="row">'+
                '<div class="col-8 col-md-8 address-col">'+
                  '<div class="row" >'+
                    '<table style="width: 100%; height: 100%; border-bottom: 2px solid black;">'+
                      '<tbody>'+
                        '<tr>'+
                          '<td style="width: 50%; padding-left: 15px;"><b>To: '+data.company['name']+'</b></td>'+
                          '<td style="width: 50%;"><b>Company Code: '+data.company['company_code']+'</b></td>'+
                        '</tr>'+
                      '</tbody>'+
                    '</table>'+
                  '</div>'+
                  '<div class="row">'+
                    '<div class="col-6 col-md-6" style="border-right: 2px solid black;height: 191px;">'+
                      '<table style="width: 340px; height: 180px;" >'+
                        '<thead>'+
                          '<tr>'+
                            '<th>Billing Address</th>'+
                          '</tr>'+
                        '</thead>'+
                        '<tbody>'+
                          '<tr>'+
                            '<td>'+data.company['name']+'</td>'+
                          '</tr>'+
                          '<tr>'+
                            '<td>'+data.billing['address_line1']+','+data.billing['address_line2']+','+billaddress_line3+'</td>'+
                          '</tr>'+
                          '<tr>'+
                            '<td>'+data.billing['name']+','+data.billing['state_title']+'-'+data.billing['pincode']+'</td>'+
                          '</tr>'+
                          '<tr>'+
                            '<td><b>GSTIN: '+data.company['gstin']+'</b></td>'+
                          '</tr>'+
                        '</tbody>'+
                      '</table>'+
                    '</div>'+
                    '<div class="col-6 col-md-6" >'+
                      '<table style="width: 100%; height: 180px;">'+
                        '<thead>'+
                          '<tr>'+
                            '<th>Shipping Address</th>'+
                          '</tr>'+
                        '</thead>'+
                        '<tbody >'+
                          '<tr>'+
                            '<td>'+data.shipping['person_name']+'</td>'+
                          '</tr>'+
                          '<tr>'+
                            '<td>'+data.shipping['ship_company_name']+'</td>'+
                          '</tr>'+
                          '<tr>'+
                            '<td>'+data.shipping['address_line1']+','+data.shipping['address_line2']+','+shipaddress_line3+'</td>'+
                          '</tr>'+
                          '<tr>'+
                            '<td>'+data.shipping['name']+','+data.shipping['state_title']+'-'+data.shipping['pincode']+'</td>'+
                          '</tr>'+
                          '<tr>'+
                            '<td>Mobile No:-'+data.shipping['mobile']+'</td>'+
                          '</tr>'+
                        '</tbody>'+
                      '</table>'+
                    '</div>'+
                  '</div>'+
                '</div>'+

                '<div class="col-4 col-md-4">'+
                  '<div class="row">'+
                    '<table style="width: 340px; height: 50px; border-bottom: 2px solid black;">'+
                      '<tbody>'+
                        '<tr>';
						if(printDocType =="Quotation")
						{
							billingShippingData = billingShippingData+
                          '<td><b>Quotation No: '+data.data['quotation_no']+'</b></td>';
						}
						else if(printDocType =="Pro-Forma Invoice"){
							billingShippingData = billingShippingData+
                          '<td><b>PI No: '+data.data['pi_no']+'</b></td>';
						}
						else if(printDocType =="Invoice"){
							billingShippingData = billingShippingData+
                          '<td><b>Invoice No: '+data.data['invoice_no']+'</b></td>';
						}
						console.log(data);
						billingShippingData = billingShippingData+
                        '</tr>'+
                        '<tr>'+
                          '<td><b>Date:'+printdate+'</b></td>'+
                        '</tr>'+
                      '</tbody>'+
                    '</table>'+
                  '</div>'+
                  '<div class="row">'+
                    '<table style="width: 346px; height: 150px;">';
					if(printDocType =="Invoice" ){
						billingShippingData = billingShippingData+'<tbody>'+
                        '<tr>'+
                          '<td colspan="2"><b>PO Number: '+data.pi_info['po_number']+'</b></td>'+
                        '</tr>'+
                        '<tr>'+
                          '<td colspan="2"><b>Payment Term: '+data.pi_info['paymnet_term']+'</b></td>'+
                        '</tr>'+
                        '<tr>';
						if(data.invoice['courier_name'] !== 'null'){
							billingShippingData = billingShippingData+
                          '<td colspan="2"><b>Courier: '+data.invoice['courier_name']	+'</b></td>'+
                        '</tr>'+
                        '<tr>'+
                          '<td><b>Tracking Id:</b>'+data.invoice['tracking_id'] +'</td>'+
                          '<td><b>Date:</b>'+data.invoice['shipping_date'] +'</td>'+
                        '</tr>'+
                        '<tr>';
						}
							billingShippingData = billingShippingData+
                          '<td colspan="2"><b>Sales Person: '+ data.invoice['sales_person']+'</b></td>'+
                        '</tr>'+
                      '</tbody>';
                        }
                        
                        if(printDocType =="Pro-Forma Invoice" ){
                            
                            	billingShippingData = billingShippingData+'<tbody>'+
                        '<tr>'+
                          '<td colspan="2"><b>PO Number: '+data.data['po_number']+'</b></td>'+
                        '</tr>'+
                        '<tr>'+
                          '<td colspan="2"><b>Payment Term: '+data.data['paymnet_term']+'</b></td>'+
                        '</tr>'+
                        '<tr>';
                        }
                        
						
				
                    billingShippingData = billingShippingData+'</table>'+
                  '</div>'+
                '</div>'+
              '</div>'+
            '</div>';
			
			return billingShippingData;
}

function productData(result){
	console.log(result);
	var productData = '<div class="invoice-table">'+
              '<div class="row">'+
                '<table id="product_table" style="border: 2px solid black; height: 600px; width: 1050px;">'+
                  '<thead style="border-bottom:2px solid black;">'+
                    '<tr>'+
                      '<th style="border-right: 1px solid black; width: 50px; text-align: center;">Sr NO.</th>'+
                      '<th style="border-right: 1px solid black; width: 543px; text-align: center;">Product Name</th>'+
                      '<th style="border-right: 1px solid black; width: 95px; text-align: center;">HSN</th>'+
                      '<th style="border-right: 1px solid black; width: 80px; text-align: center; ">GST(%)</th>'+
                      '<th style="border-right: 1px solid black; width: 80px; text-align: center;">Quantity</th>'+
                      '<th style="border-right: 1px solid black; width: 100px; text-align: center;">Unit Cost</th>'+
                      '<th style="border-right: 1px solid black; width: 100px; text-align: center;">Total</th>'+
                    '</tr>'+
                  '</thead>'+
                  '<tbody>'+
                
                  (result.productrows)+

                  '</tbody>'+
                '</table>'+
              '</div>'+
            '</div>';
	return productData;
}

function getFootData(result, data,printDocType){
	var footData = '<div class="invoice-total " style="padding-left: 15px;">'+
              '<div class="row child-invoice-total" style="height: 368px; width: 1063px;">'+
                '<div class="row" style=" height: 40px; width: 1047px; border-bottom: 2px solid black; margin-left: 0px;">'+
                  '<table>'+
                    '<tbody>'+
                      '<tr>'+
                        '<td style="padding-left: 5px;"><b>OUR GSTIN: 24AALFT2125L1Z3 </b></td>'+
                      '</tr>'+
                    '</tbody>'+
                  '</table>'+
                '</div>'+
				'<div class="col-9 col-md-9" style="border-right: 2px solid black;margin-top: -60px;">';
				if(printDocType == "Pro-Forma Invoice" || printDocType == "Invoice"){
					footData = footData+
					'<div class="row" style="border-bottom: 2px solid black; height: 60px; ">'+
                  '<table style="height: 60px; width: 100%;">'+
                    '<thead style="font-size: 12px;">'+
                      '<tr>'+
                        '<th>Bank Details</th>'+
                      '</tr>'+
                    '</thead>'+
                    '<tbody style="font-size: 12px;">'+
                      '<tr>'+
                        '<td><b>Bank Name: '+data.bank['bank_name']+'</b></td>'+
                        '<td><b>A/C No: '+data.bank['ac_no']+'</b></td>'+
                      '</tr>'+
                      '<tr>'+
                        '<td><b>Branch Name: '+data.bank['bank_branch']+'</b></td>'+
                        '<td><b>IFSC Code:'+data.bank['bank_ifsc']+'</b></td>'+
                      '</tr>'+
                    '</tbody>'+
                  '</table>'+
                '</div>';
				}
				console.log('note : '+data.data['note'] );
			footData = footData +	
                
				'<div class="row" style="height: 145px; ">'+   
				'<table style="height: 60px; width: 100%;font-size: x-small !important;">'+
						'<tr><td><b>NOTE:</b></td></tr>'+
						'<tr><td>'+(data.data['note'] ? data.data['note']: "" )+'</td></tr>'+
                    '</table>'+
                  '</div>';
                  /*+
                  '<div class="row" style="height: 60px; ">'+
                    '<table style="height: 60px; width: 100%;">'+

                    '</table>'+
                  '</div>';*/
				if(printDocType == "Pro-Forma Invoice"){
					footData = footData +	 
                  '<div class="row" style="height: 53px; width: 100%;">';
				 }
				 else if(printDocType =="Invoice"){
					  if((result.i_show)==1){
						  gstdata=getGSTSummary(data);
						  console.log(gstdata);
					 footData = footData +	 
                  '<div class="row " style="height: 53px; width: 100%;margin-left:0px">'+
						'<table style="width: 100%;    border-top: 2px solid black;border-bottom: 2px solid black;">'+
                          '<thead style="font-size: 12px; border-bottom: 2px solid black;">'+
                            '<tr>'+
                              '<th style="border-right: 2px solid black; text-align: center;">GST Summary</th>'+
                              '<th style="border-right: 2px solid black; text-align: center;">Taxable amt</th>'+
                              '<th style="border-right: 2px solid black; text-align: center;">IGST</th>'+
                              '<th style="border-right: 2px solid black; text-align: center;">IGST AMT</th>'+
                              '<th style="text-align: center;">Total GST</th>'+
                            '</tr>'+
                          '</thead>'+
                          '<tbody style="font-size: 12px;">'+
                        gstdata.gst_summary
                          '</tbody>'+
                          '<tfoot style="font-size: 12px; border-top: 2px solid black;">'+
                            '<tr>'+
                              '<th style="border-right:2px solid black; text-align: left;">Total:</th>'+
                              '<th style="border-right:2px solid black; text-align: right; padding-right:3px;">₹'+gstdata.subttl+'</th>'+
                              '<th style="border-right:2px solid black; text-align: right;"></th>'+
                              '<th style="border-right:2px solid black; text-align: right; padding-right:3px;">₹'+gstdata.gstttl+'</th>'+
                              '<th style="text-align: right; padding-right:3px;">₹'+gstdata.gstttl+'</th>'+
                            '</tr>'+
                          '</tfoot>'+
                        '</table>';
						
					  }else{
					gstdata=getGSTSummary(data);
					footData = footData +	
                  '<div class="row " style="height: 53px; width: 100%;margin-left:0px">'+
						'<table style="width: 100%;    border-top: 2px solid black;border-bottom: 2px solid black;">'+
                      '<thead style="font-size: 12px; border-bottom: 2px solid black;">'+
                        '<tr>'+
                          '<th style="border-right: 2px solid black; text-align: center;">GST Summary</th>'+
                          '<th style="border-right: 2px solid black; text-align: center;">Taxable amt</th>'+
                          '<th style="border-right: 2px solid black; text-align: center;">SGST(%)</th>'+
                          '<th style="border-right: 2px solid black; text-align: center;">SGST AMT</th>'+
                          '<th style="border-right: 2px solid black; text-align: center;">CGST(%)</th>'+
                          '<th style="border-right: 2px solid black; text-align: center;">CGST AMT</th>'+
                          '<th style="text-align: center;">Total GST</th>'+
                        '</tr>'+
                      '</thead>'+
                      '<tbody style="font-size: 12px;">'+
                        gstdata.gst_summary
                      '</tbody>'+
                      '<tfoot style="font-size: 12px; border-top: 2px solid black;">'+
                        '<tr>'+
                          '<th style="border-right:2px solid black; text-align: left;">Total:</th>'+
                          '<th style="border-right:2px solid black; text-align: right; padding-right:3px;">₹'+gstdata.subttl+'</th>'+
                          '<th style="border-right:2px solid black; text-align: right;"></th>'+
                          '<th style="border-right:2px solid black; text-align: right; padding-right:3px;">₹'+(gstdata.gstttl/2)+'</th>'+
                          '<th style="border-right:2px solid black; text-align: right;"></th>'+
                          '<th style="border-right:2px solid black; text-align: right; padding-right:3px;">₹'+(gstdata.gstttl/2)+'</th>'+
                          '<th style="text-align: right; padding-right:3px;">₹'+gstdata.gstttl+'</th>'+
                        '</tr>'+
                      '</tfoot>'+
                    '</table>';
					  }
				 }
				 else{
					 footData = footData +	 
                  '<div class="row" style="height: 115px; width: 100%;">';
				 }
                 footData = footData +	 '</div>'+
                  '<div class="row" style="border-top: 2px solid black; padding-left: 15px;">'+
                    '<table>'+
                      '<tbody>'+
                        '<tr>'+
                          '<td><b>RS '+(result.words)+'. </b></td>'+
                        '</tr>'+
                      '</tbody>'+
                    '</table>'+
                  '</div>'+
                '</div>'+

                '<div class="col-3" style="padding-left: 0px;">'+
                  '<table style="height: 205px; width: 250px;">'+
                    '<tbody>'+ 
                      '<tr>'+
                        '<td style="width: 50%; text-align: right;"><b>Sub Total:</b></td>'+
                        '<td style="width: 50%; text-align: right; padding-right:3px;"><b>₹'+(result.subttl)+'</b></td>'+
                      '</tr>';
					  
					  if((result.i_show)==1){
						   footData = footData +
						   '<tr>'+
                        '<td style="width: 50%; text-align: right;"><b>IGST:</b></td>'+
                        '<td style="width: 50%; text-align: right; padding-right:3px;"><b>₹'+(result.gstttl)+'<b></td>'+
                      '</tr>';
					  }else{
						  footData = footData +
					  
                      '<tr>'+
                        '<td style="width: 50%; text-align: right;"><b>SGST:</b></td>'+
                        '<td style="width: 50%; text-align: right; padding-right:3px;"><b>₹'+(result.gstttl/2).toFixed(2)+'<b></td>'+
                      '</tr>'+
                      '<tr>'+
                        '<td style="width: 50%; text-align: right;"><b>CGST:</b></td>'+
                        '<td style="width: 50%; text-align: right; padding-right:3px;"><b>₹'+(result.gstttl/2).toFixed(2)+'<b></td>'+
                      '</tr>';
					  }
					 
					  footData = footData  +
                      '<tr style="border-bottom: 2px solid black;">'+
                        '<td style="width: 50%; text-align: right;"><b>Round Off:</b></td>'+
                        '<td style="width: 50%; text-align: right; padding-right:3px;"><b>₹'+(result.roundedValue).toFixed(2)+'</b></td>'+
                      '</tr>'+
                      '<tr>'+
                        '<td style="width: 50%; text-align: right;"><b>Grand Total:</b></td>'+
                        '<td style="width: 50%; text-align: right; padding-right:3px;"><b>₹'+(result.grndttl)+'</b></td>'+
                      '</tr>'+
                    '</tbody>'+
                  '</table>'+
                '</div>'+
              '</div>'+
            '</div>';
			return footData;
}
function printFooter(printDocType){
	
         var footer =   '<div class="invoice-term" style=" height: 150px; width: 100%;">'+
              '<div class="row">'+
                '<div class="col-9 col-md-9" >';
				
				if(printDocType=='Pro-Forma Invoice' || printDocType=='Invoice' ){
			footer= footer+		
                '<table style="font-size: 12px;">'+
                  '<thead >'+
                    '<tr>'+
                      '<th colspan="2">'+
                        '<b>Terms & Conditions:</b>'+
                      '</th>'+
                    '</tr>'+
                  '</thead>'+
                  '<tbody >'+
                    '<tr>'+
                      '<td>1)Goods once sold will not be taken back.</td>'+
                      '<td style="padding-left:3px;">5)"Subject to "RAJKOT" Jurisdiction only. E.&.O.E".</td>'+
                    '</tr>'+
                    '<tr>'+
                      '<td>2)Interest @18% p.a. will be charged if payment is not made within due date.</td>'+
                    '</tr>'+
                    '<tr>'+
                      '<td>3)Our risk and responsibility ceases as soon as the goods leave our premises</td>'+
                    '</tr>'+
                    '<tr>'+
                      '<td>4)Warranty As per Company.</td>'+
                    '</tr>'+
                  '</tbody>'+
                '</table>';
              
				}
				
				
             footer= footer +'</div>'+
                '<div class="col-3" style="margin-left: -13px;">'+
                  '<table>'+
                    '<thead>'+
                      '<tr>'+
                        '<th style="text-align: center; padding-left: 35px;">For, Tanna TechBiz LLP</th>'+
                      '</tr>';
                      if(optionappend == 1){
                          footer= footer + '<tr>'+
                        '<th style="text-align: center; padding-left: 35px;"><img src="public/dist/img/TTB_Stamp.jpg" width="50" height="50"></th>'+
                      '</tr>';
                      }
                       footer= footer +'</thead>'+
                  '</table>'+
                '</div>'+
              '</div>'+
            '</div>'+
          '</div>';
		  return footer;
}
function productrowcalculaton(data)
{
	console.log(data);
  var productrows=""; var words="";var count=10;var no=1;
  var subttl=0; var gstttl=0; var grndttl=0; var i_show=0; var cs_show=0;

  var countofproduct=(data.product).length;
  var reamainrow=count-countofproduct;
  
  for(var i=0;i<countofproduct;i++)
  {
    if(data.product[i]['i_gst']=='null')
    {
        var price=parseFloat(data.product[i]['unit_cost']);
        var quantity=parseFloat(data.product[i]['quantity']);
        price=(price.toFixed(2));

        cs_show=1;
        var test=(data.product[i]['c_s_gst']).replace(/[\*\^\'\!\%\+\.]/g, '').split(' ')[0];
        var rowgst=(test*2);
       
        total=(price*quantity);
        total=(total.toFixed(2));
        
        gst=((((price/100)*(((data.product[i]['c_s_gst']).replace(/[\*\^\'\!\%\+]/g, '').split(' ')[0]))*2)*quantity));
        gst=(gst.toFixed(2));
        

        subttl=(parseFloat(subttl)+parseFloat(total)).toFixed(2);
        gstttl=(parseFloat(gstttl)+parseFloat(gst)).toFixed(2);
        

        if(rowgst==50){rowgst=5;}

        productrows=productrows+
          '<tr style="height: 15px;">'+
            '<td style="border-right: 1px solid black; width: 50px; text-align: center;">'+no+'</td>'+
            '<td style="border-right: 1px solid black; width: 543px; padding-left:2px; text-align: justify max-width: 80ch !important;word-break: break-word !important;hyphens: auto !important;;">'+data.product[i]['name']+'</td>'+
            '<td style="border-right: 1px solid black; width: 95px; text-align: center;">'+data.product[i]['HSN']+'</td>'+
            '<td style="border-right: 1px solid black; width: 80px; text-align: center;">'+rowgst+'%</td>'+
            '<td style="border-right: 1px solid black; width: 80px; text-align: center;">'+quantity+'</td>'+
            '<td style="border-right: 1px solid black; width: 100px; text-align: right; padding-right:3px;">₹'+price+'</td>'+
            '<td style="border-right: 1px solid black; width: 100px; text-align: right; padding-right:3px;">₹'+total+'</td>'+                  
          '</tr>';

    }
    else if(data.product[i]['c_s_gst']=='null')
    {
      var price=parseFloat(data.product[i]['unit_cost']);
      var quantity=parseFloat(data.product[i]['quantity']);
      price=(price.toFixed(2));

        var test1=(data.product[i]['i_gst']).replace(/[^a-z0-9\s]/gi, '');
        
        i_show=1;
        total=parseFloat(price*quantity);
        total=(total.toFixed(2));
        
        gst=parseFloat(((price/100)*(data.product[i]['i_gst'].replace(/[\*\^\'\!\%\+\.]/g, '')))*quantity);
        gst=(gst.toFixed(2));
        
        
        subttl=(parseFloat(subttl)+parseFloat(total)).toFixed(2);
        gstttl=(parseFloat(gstttl)+parseFloat(gst)).toFixed(2);

        

        productrows=productrows+
          '<tr style="height: 15px;">'+
            '<td style="border-right: 1px solid black; width: 50px; text-align: center;">'+no+'</td>'+
            '<td style="border-right: 1px solid black; width: 543px; padding-left:2px; text-align: justify max-width: 80ch !important;word-break: break-word !important;hyphens: auto !important;;">'+data.product[i]['name']+'</td>'+
            // '<td style="border-right: 1px solid black; width: 125px; text-align: center;">ABC-XYZ-12345</td>'+
            '<td style="border-right: 1px solid black; width: 95px; text-align: center;">'+data.product[i]['HSN']+'</td>'+
            '<td style="border-right: 1px solid black; width: 80px; text-align: center;">'+data.product[i]['i_gst']+'</td>'+
            '<td style="border-right: 1px solid black; width: 80px; text-align: center;">'+quantity+'</td>'+
            '<td style="border-right: 1px solid black; width: 100px; text-align: right; padding-right:3px;">₹'+price+'</td>'+
            '<td style="border-right: 1px solid black; width: 100px; text-align: right; padding-right:3px;">₹'+total+'</td>'+                  
          '</tr>';

    }
    no++;
  }
  
  var roundedValue=0;
  grndttl=(parseFloat(subttl)+parseFloat(gstttl)).toFixed(2);
  grndttl=Roundoff(grndttl);
  roundedValue=(grndttl.roundoff);
  grndttl=((grndttl.grandtotal).toFixed(2));
  
  if(grndttl!=0)
  {
    words=convertNumberToWords(grndttl);
    words=words+'only';
  }
  for(var i=0;i<reamainrow;i++)
  {
            productrows=productrows+
            '<tr style="height: 15px;">'+
                '<td style="border-right: 1px solid black; width: 50px; text-align: center;"></td>'+
                '<td style="border-right: 1px solid black; padding-left:2px; text-align: justify max-width: 80ch !important;word-break: break-word !important;hyphens: auto !important;;"></td>'+
                '<td style="border-right: 1px solid black; width: 125px; text-align: justify;"></td>'+
                '<td style="border-right: 1px solid black; width: 95px; text-align: justify;"></td>'+
                '<td style="border-right: 1px solid black; width: 80px; text-align: justify;"></td>'+
                '<td style="border-right: 1px solid black; width: 80px; text-align: justify;"></td>'+
                '<td style="border-right: 1px solid black; width: 100px; text-align: justify;"></td>'+
                '<td style="border-right: 1px solid black; width: 100px; text-align: right;"></td>'+                  
              '</tr>';
  }

  return {'productrows':productrows,'subttl':subttl,'gstttl':gstttl,'roundedValue':roundedValue,'grndttl':grndttl,'words':words,'i_show':i_show,'cs_show':cs_show}

}

function productSerialNoData(data){
	console.log(data.serialNo.length);
var productSerailData =	'<div class="invoice-table">'+
              '<div class="row">'+
                '<table id="product_table" style="border: 2px solid black; height: 600px; width: 1050px;">'+
                  '<thead style="border-bottom:2px solid black;">'+
                    '<tr>'+
                      '<th style="border-right: 1px solid black; width: 50px; text-align: center;">Sr NO.</th>'+
                      '<th style="border-right: 1px solid black; width: 400px; text-align: center;">Product Name</th>'+
                      '<th style="border-right: 1px solid black; width: 543px; text-align: center;">Serial No</th>'+
                      
                    '</tr>'+
                  '</thead>'+
                  '<tbody>';
					for(var i=0;i<data.serialNo.length;i++){
					productSerailData= productSerailData+ 	'<tr>'+
                      '<td style="border-right: 1px solid black; width: 50px; text-align: center;">'+(i+1)+'</td>'+
                      '<td style="border-right: 1px solid black; width: 400px; text-align: center;">'+data.serialNo[i]['name']+'</td>'+
                      '<td style="border-right: 1px solid black; width: 543px; text-align: center ;word-wrap: break-word !important;">'+(data.serialNo[i]['serial_no'] == null ? ' - ' :data.serialNo[i]['serial_no'] )+'</td>'+
                    '</tr>';
					}
                 productSerailData= productSerailData+ '</tbody>'+
                '</table>'+
              '</div>'+
            '</div>';
			return productSerailData;
}
function Roundoff(grndttl)
{
  var finalvalue=0;
  var originalValue = grndttl;
  var roundedValue = Math.round(originalValue);
  

  var newValue = Math.round((parseFloat(originalValue) - parseFloat(roundedValue)) * 100) / 100;


  if (newValue < 0) {
      finalvalue=parseFloat(originalValue)+(-(parseFloat(newValue)));
      newValue=-newValue;
      return {'grandtotal':finalvalue,'roundoff':newValue};
  }
  else if (newValue > 0) {
    finalvalue=parseFloat(originalValue)-((parseFloat(newValue)));
    newValue=-newValue;
    return {'grandtotal':finalvalue,'roundoff':newValue};
  }
  else
  {
    finalvalue=parseFloat(originalValue)+parseFloat(newValue);
    
    return {'grandtotal':finalvalue,'roundoff':newValue};
  }

}

function convertNumberToWords(amount) {

    var words = new Array();
    words[0] = '';
    words[1] = 'One';
    words[2] = 'Two';
    words[3] = 'Three';
    words[4] = 'Four';
    words[5] = 'Five';
    words[6] = 'Six';
    words[7] = 'Seven';
    words[8] = 'Eight';
    words[9] = 'Nine';
    words[10] = 'Ten';
    words[11] = 'Eleven';
    words[12] = 'Twelve';
    words[13] = 'Thirteen';
    words[14] = 'Fourteen';
    words[15] = 'Fifteen';
    words[16] = 'Sixteen';
    words[17] = 'Seventeen';
    words[18] = 'Eighteen';
    words[19] = 'Nineteen';
    words[20] = 'Twenty';
    words[30] = 'Thirty';
    words[40] = 'Forty';
    words[50] = 'Fifty';
    words[60] = 'Sixty';
    words[70] = 'Seventy';
    words[80] = 'Eighty';
    words[90] = 'Ninety';
    amount = amount.toString();
    var atemp = amount.split(".");
    var number = atemp[0].split(",").join("");
    var n_length = number.length;
    var words_string = "";
    if (n_length <= 9) {
        var n_array = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0);
        var received_n_array = new Array();
        for (var i = 0; i < n_length; i++) {
            received_n_array[i] = number.substr(i, 1);
        }
        for (var i = 9 - n_length, j = 0; i < 9; i++, j++) {
            n_array[i] = received_n_array[j];
        }
        for (var i = 0, j = 1; i < 9; i++, j++) {
            if (i == 0 || i == 2 || i == 4 || i == 7) {
                if (n_array[i] == 1) {
                    n_array[j] = 10 + parseInt(n_array[j]);
                    n_array[i] = 0;
                }
            }
        }
        value = "";
        for (var i = 0; i < 9; i++) {
            if (i == 0 || i == 2 || i == 4 || i == 7) {
                value = n_array[i] * 10;
            } else {
                value = n_array[i];
            }
            if (value != 0) {
                words_string += words[value] + " ";
            }
            if ((i == 1 && value != 0) || (i == 0 && value != 0 && n_array[i + 1] == 0)) {
                words_string += "Crores ";
            }
            if ((i == 3 && value != 0) || (i == 2 && value != 0 && n_array[i + 1] == 0)) {
                words_string += "Lakhs ";
            }
            if ((i == 5 && value != 0) || (i == 4 && value != 0 && n_array[i + 1] == 0)) {
                words_string += "Thousand ";
            }
            if (i == 6 && value != 0 && (n_array[i + 1] != 0 && n_array[i + 2] != 0)) {
                words_string += "Hundred and ";
            } else if (i == 6 && value != 0) {
                words_string += "Hundred ";
            }
        }
        words_string = words_string.split("  ").join(" ");
    }
    return words_string;
}

function getGSTSummary(data){
	console.log('here is fun');
  var countofproduct=(data.product).length;
  var test;
var subttl=0; var gstttl=0; var grndttl=0; var i_show=0; var cs_show=0;
    var tax25=0; var unit25=0; var tax6=0;var unit6=0; var tax9=0; var unit9=0; var tax14=0; var unit14=0;
    var tax5=0; var unit5=0; var tax12=0; var unit12=0; var tax18=0; var unit18=0; var tax28=0; var unit28=0;
    var gst_summary="";
    var gsttype;
  for(var i=0;i<countofproduct;i++)
  {
            if(data.product[i]['i_gst']=='null'){
                gsttype = 'c_s_gst';
			  test = (data.product[i]['c_s_gst']).replace(/[\*\^\'\!\%\+\.]/g, '').split(' ')[0];
			  var rowgst=(test*2);
						if(rowgst==50){rowgst=5;}
						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;
						
						if(test==25)
							{
							  tax25=tax25+(gst/2);
							  unit25=unit25+total;
							}
							if(test==6)
							{
							  tax6=tax6+(gst/2);
							  unit6=unit6+total;
							}
							if(test==9)
							{
							  tax9=tax9+(gst/2);
							  unit9=unit9+total;
							}
							if(test==14)
							{
							  tax14=tax14+(gst/2);
							  unit14=unit14+total;
							}

			  }
			  else{
				                  gsttype = 'gst';

				   var test1=(data.product[i]['i_gst']).replace(/[^a-z0-9\s]/gi, '');
				   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;
								if(test1==5)
								{
								  tax5=tax5+gst;
								  unit5=unit5+total;
								  console.log(unit5);
								}
								if(test1==12)
								{
								  tax12=tax12+gst;
								  unit12=unit12+total;
								  console.log(unit12);
								}
								if(test1==18)
								{
								  tax18=tax18+gst;
								  unit18=unit18+total;
								  console.log(unit18);
								}
								if(test1==28)
								{
								  tax28=tax28+gst;
								  unit28=unit28+total;
								}
			  }
			  
		grndttl=subttl+gstttl;
         /* if(grndttl!=0)
          {
            var a = ['','one ','two ','three ','four ', 'five ','six ','seven ','eight ','nine ','ten ','eleven ','twelve ','thirteen ','fourteen ','fifteen ','sixteen ','seventeen ','eighteen ','nineteen '];
            var b = ['', '', 'twenty','thirty','forty','fifty', 'sixty','seventy','eighty','ninety'];
          
              if ((num = grndttl.toString()).length > 9) ;
              n = ('000000000' + num).substr(-9).match(/^(\d{2})(\d{2})(\d{2})(\d{1})(\d{2})$/);
              if (!n) return; var str = '';
              str += (n[1] != 0) ? (a[Number(n[1])] || b[n[1][0]] + ' ' + a[n[1][1]]) + 'crore ' : '';
              str += (n[2] != 0) ? (a[Number(n[2])] || b[n[2][0]] + ' ' + a[n[2][1]]) + 'lakh ' : '';
              str += (n[3] != 0) ? (a[Number(n[3])] || b[n[3][0]] + ' ' + a[n[3][1]]) + 'thousand ' : '';
              str += (n[4] != 0) ? (a[Number(n[4])] || b[n[4][0]] + ' ' + a[n[4][1]]) + 'hundred ' : '';
              str += (n[5] != 0) ? ((str != '') ? 'and ' : '') + (a[Number(n[5])] || b[n[5][0]] + ' ' + a[n[5][1]]) + 'only ' : '';
              words=str;
          }*/
		  		

  }    
    if(gsttype == 'c_s_gst'){
            gst_summary=gst_summary+
            '<tr style="height: 18px;">'+
                          '<td style="border-right: 2px solid black; text-align: center;">GST @5</td>'+
                          '<td style="border-right: 2px solid black; text-align: right; padding-right:3px;">₹'+unit25+'</td>'+
                          '<td style="border-right: 2px solid black; text-align: center;"> 2.5% </td>'+
                          '<td style="border-right: 2px solid black; text-align: right; padding-right:3px;">₹'+tax25.toFixed(2)+'</td>'+
                          '<td style="border-right: 2px solid black; text-align: center;"> 2.5% </td>'+
                          '<td style="border-right: 2px solid black; text-align: right; padding-right:3px;">₹'+tax25.toFixed(2)+'</td>'+
                          '<td style="text-align: right; padding-right:3px;">₹'+(tax25*2).toFixed(2)+'</td>'+
                        '</tr>';
         
            gst_summary=gst_summary+
            '<tr style="height: 18px;">'+
                          '<td style="border-right: 2px solid black; text-align: center;">GST @6</td>'+
                          '<td style="border-right: 2px solid black; text-align: right; padding-right:3px;">₹'+unit6+'</td>'+
                          '<td style="border-right: 2px solid black; text-align: center;"> 6% </td>'+
                          '<td style="border-right: 2px solid black; text-align: right; padding-right:3px;">₹'+tax6.toFixed(2)+'</td>'+
                          '<td style="border-right: 2px solid black; text-align: center;"> 6% </td>'+
                          '<td style="border-right: 2px solid black; text-align: right; padding-right:3px;">₹'+tax6.toFixed(2)+'</td>'+
                          '<td style="text-align: right; padding-right:3px;">₹'+(tax6*2).toFixed(2)+'</td>'+
                        '</tr>';
        
            gst_summary=gst_summary+
            '<tr style="height: 18px;">'+
                          '<td style="border-right: 2px solid black; text-align: center;">GST @9</td>'+
                          '<td style="border-right: 2px solid black; text-align: right; padding-right:3px;">₹'+unit9+'</td>'+
                          '<td style="border-right: 2px solid black; text-align: center;"> 9% </td>'+
                          '<td style="border-right: 2px solid black; text-align: right; padding-right:3px;">₹'+tax9.toFixed(2)+'</td>'+
                          '<td style="border-right: 2px solid black; text-align: center;"> 9% </td>'+
                          '<td style="border-right: 2px solid black; text-align: right; padding-right:3px;">₹'+tax9.toFixed(2)+'</td>'+
                          '<td style="text-align: right; padding-right:3px;">₹'+(tax9*2).toFixed(2)+'</td>'+
                        '</tr>';
          

            gst_summary=gst_summary+
            '<tr style="height: 18px;">'+
                          '<td style="border-right: 2px solid black; text-align: center;">GST @28</td>'+
                          '<td style="border-right: 2px solid black; text-align: right; padding-right:3px;">₹'+unit14+'</td>'+
                          '<td style="border-right: 2px solid black; text-align: center;"> 14% </td>'+
                          '<td style="border-right: 2px solid black; text-align: right; padding-right:3px;">₹'+tax14.toFixed(2)+'</td>'+
                          '<td style="border-right: 2px solid black; text-align: center;"> 14% </td>'+
                          '<td style="border-right: 2px solid black; text-align: right; padding-right:3px;">₹'+tax14.toFixed(2)+'</td>'+
                          '<td style="text-align: right; padding-right:3px;">₹'+(tax14*2).toFixed(2)+'</td>'+
                        '</tr>';
         
        }else{
               gst_summary=gst_summary+
            '<tr style="height: 18px;">'+
                          '<td style="border-right: 2px solid black; text-align: center;">GST @5</td>'+
                          '<td style="border-right: 2px solid black; text-align: right; padding-right:3px;">₹'+unit5+'</td>'+
                          '<td style="border-right: 2px solid black; text-align: center;"> 5% </td>'+
                          '<td style="border-right: 2px solid black; text-align: right; padding-right:3px;">₹'+tax5.toFixed(2)+'</td>'+
                          '<td style="text-align: right; padding-right:3px;">₹'+tax5.toFixed(2)+'</td>'+
                        '</tr>';
          
            gst_summary=gst_summary+
            '<tr style="height: 18px;">'+
                          '<td style="border-right: 2px solid black; text-align: center;">GST @12</td>'+
                          '<td style="border-right: 2px solid black; text-align: right; padding-right:3px;">₹'+unit12+'</td>'+
                          '<td style="border-right: 2px solid black; text-align: center;"> 12% </td>'+
                          '<td style="border-right: 2px solid black; text-align: right; padding-right:3px;">₹'+tax12.toFixed(2)+'</td>'+
                          '<td style="text-align: right; padding-right:3px;">₹'+tax12.toFixed(2)+'</td>'+
                        '</tr>';
          
            gst_summary=gst_summary+
            '<tr style="height: 18px;">'+
                          '<td style="border-right: 2px solid black; text-align: center;">GST @18</td>'+
                          '<td style="border-right: 2px solid black; text-align: right; padding-right:3px;">₹'+unit18+'</td>'+
                          '<td style="border-right: 2px solid black; text-align: center;"> 18% </td>'+
                          '<td style="border-right: 2px solid black; text-align: right; padding-right:3px;">₹'+tax18.toFixed(2)+'</td>'+
                          '<td style="text-align: right; padding-right:3px;">₹'+tax18.toFixed(2)+'</td>'+
                        '</tr>';
          
            gst_summary=gst_summary+
            '<tr style="height: 18px;">'+
                          '<td style="border-right: 2px solid black; text-align: center;">GST @28</td>'+
                          '<td style="border-right: 2px solid black; text-align: right; padding-right:3px;">₹'+unit28+'</td>'+
                          '<td style="border-right: 2px solid black; text-align: center;"> 5% </td>'+
                          '<td style="border-right: 2px solid black; text-align: right; padding-right:3px;">₹'+tax28.toFixed(2)+'</td>'+
                          '<td style="text-align: right; padding-right:3px;">₹'+tax28.toFixed(2)+'</td>'+
                        '</tr>';
          }
         
  
				return {'gst_summary':gst_summary,'grndttl':grndttl,'subttl':subttl};

	
}

