<? $message = '';

$connect = new PDO("mysql:host=localhost;dbname=instrume_crm", "instrumexcrm", "Instru#crm@2022");

?><?php
function fetch_customer_data($connect)
{


$querymail = "select * from mst_email_covering where type='quotation_covering' ";
$statement3mail = $connect->prepare($querymail);
$statement3mail->execute();
$resultmail = $statement3mail->fetchAll();
foreach($resultmail as $mail)
{
$note_content = $mail['note_content'];
}

$queryemail = "select * from email_config";
$statementemail = $connect->prepare($queryemail);
$statementemail->execute();
$resultemail = $statementemail->fetchAll();
foreach($resultemail as $email)
{
$sahavas = $email['sahavas'];
}



$querydiscount ="select * from quotation_make_table_1 where customer_id = '".$_REQUEST['customer_id']."' AND quotation_id ='".$_REQUEST['quotation_id']."' ";
$statement2 = $connect->prepare($querydiscount);
$statement2->execute();
$resultdiscount1 = $statement2->fetchAll();
foreach($resultdiscount1 as $row2)
{
$quotation_id=$row2['quotation_id'];
$branch_id=$row2['branch_id'];
$GST_type=$row2['GST_type'];
$gst_type=$row2['GST_type'];
$term_of_payment=$row2['term_of_payment'];
$delivery_note=$row2['delivery_note'];
$date=$row2['date'];
$final_quotation_no=$row2['final_quotation_no'];
$freight_charges=$row2['freight_charges'];
$frieght_terms=$row2['frieght_terms'];
$payment_mode=$row2['payment_mode'];
$sales_person_id=$row2['sales_person_id'];
$billing_address=$row2['billing_address'];

$billing_GST_no=$row2['billing_GST_no'];
$bill_kind_atten=$row2['bill_kind_atten'];
$bill_contact_no=$row2['bill_contact_no'];
$bill_email_id=$row2['bill_email_id'];

$delivery_address=$row2['delivery_address'];

$delivery_GST_no=$row2['delivery_GST_no'];
$del_kind_atten=$row2['del_kind_atten'];
$del_contact_no=$row2['del_contact_no'];
$del_email_id=$row2['del_email_id'];
$our_company=$row2['our_company'];
$qtn_date=$row2['qtn_date'];
$customer_name=$row2['customer_name'];
}
$queryls5 = "select * from mst_branch where branch_id='$branch_id' ";
$statement35 = $connect->prepare($queryls5);
$statement35->execute();
$resultls5 = $statement35->fetchAll();
foreach($resultls5 as $branch_data)
{
$pan_no=$branch_data['pan_no'];
}

$query6 = "select * from quotation_from where quotation_id='$our_company' ";

$statement3 = $connect->prepare($query6);
$statement3->execute();
$result6 = $statement3->fetchAll();
foreach($result6 as $logo_detail)
{
$company_name1=$logo_detail['company_name'];
$MSME_NO=$logo_detail['MSME_NO'];
$note = $logo_detail['note'];
$footer = $logo_detail['footer'];
$quotation_tital=$logo_detail['quotation_tital'];
$bank_name=$logo_detail['bank_name'];
$account_number=$logo_detail['account_number'];
$branch_name=$logo_detail['branch_name'];
$IFSC_code=$logo_detail['IFSC_code'];
$image=$logo_detail['image'];
$Signatory_name=$logo_detail['Signatory_name'];
$company_name=$logo_detail['company_name'];
$company_subtitle=$logo_detail['company_subtitle'];
$CIN=$logo_detail['CIN'];


}
$querylsadd = "select * from mst_branch_manage where invoice_type='$GST_type' and branch_id='$branch_id' ";
$statement4 = $connect->prepare($querylsadd);
$statement4->execute();
$resultlsadd = $statement4->fetchAll();
foreach($resultlsadd as $address_data)
{
$gst_no1=$address_data['gst_no'];
$code=$address_data['code'];
$jurisdiction  = $address_data['jurisdiction'];
$commissionerate=$address_data['commissionerate'];
$dvision=$address_data['dvision'];
$ranges=$address_data['ranges'];
$billing_address_our=$address_data['billing_address'];
$communication_address=$address_data['communication_address']; 
}
$queryl3 = "select * from quotation_extra_note where gst_type_id='$GST_type'  ";
$statement43 = $connect->prepare($queryl3);
$statement43->execute();
$resultl3 = $statement43->fetchAll();
foreach($resultl3 as $extra_note)
{
$extra_note = $extra_note['note'];
}
 if($extra_note=='1'){$extra_note03 = '10. '.$extra_note;  }
//$company_name='Toshio Technology Pvt. Ltd';

$queryl4 = "select * from quotation_from_comapany where com_quotation_id='$our_company'  ";
$statement44 = $connect->prepare($queryl4);
$statement44->execute();
$resultl4 = $statement44->fetchAll();
foreach($resultl4 as $quotation_from_comapany)
{

}


$queryl2 = "select * from mst_customer where c_id='$customer_id'  ";
$statement42 = $connect->prepare($queryl2);
$statement42->execute();
$resultl2 = $statement42->fetchAll();
foreach($resultl2 as $customer)
{

$MSME=$customer['MSME'];

}
$queryls5 = "select * from user_details where user_id='$sales_person_id'  ";

$statement41 = $connect->prepare($queryls5);
$statement41->execute();
$resultls5 = $statement41->fetchAll();
foreach($resultls5 as $user_data)
{
$first_name=$user_data['first_name'];
$last_name=$user_data['last_name'];
$email_id=$user_data['email_id'];
$mobile_no=$user_data['mobile_no'];
}

if($gst_type =='sez'){
	
	$SGST = 0;
	$CGST = 0;
	$IGST = 0;
	
}

if($gst_type =='within_local_export'){
	
	$SGST = 0.05;
	$CGST = 0.05;
	$IGST = 0;
	
}

if($gst_type =='outsite_local_export'){
	
	$SGST = 0;
	$CGST = 0;
	$IGST = 0.1;
	
}

//print_r($branch_data);


///// new code in gst
if($gst_type =='ho'){
	
	//$SGST = $product_type_description[0]['SGST'];
	//$CGST = $product_type_description[0]['CGST'];
	//$IGST = 0;	
	
	$SGST = 0;
	$CGST = 0;
	$IGST = $product_type_description[0]['IGST'];
	 $tax_type='OMS';
	
}
if($gst_type =='within_state'){
	 $SGST = $product_type_description[0]['SGST'];
	$CGST = $product_type_description[0]['CGST'];
	$IGST = 0;
	 $tax_type='Local';
	
}

if($gst_type =='outsite_state'){
	
	$SGST = 0;
	$CGST = 0;
	$IGST = $product_type_description[0]['IGST'];
	$tax_type='OMS';
}




if($gst_type =='DeemedExportWithinState'){
	
	$SGST = 0.05;
	$CGST = 0.05;
	$IGST = 0;
	
}

if($gst_type =='DeemedExportOutsideState'){
	
	$SGST = 0;
	$CGST = 0;
	$IGST = 0.1;
	
}
if($gst_type =='SEZWithinState'){
	
	$SGST = 0.05;
	$CGST = 0.05;
	$IGST = 0;
	
}

if($gst_type =='SEZOutsideState'){
	
	$SGST = 0;
	$CGST = 0;
	$IGST = 0.1;
	
}
if($gst_type =='HSSOutsideState'){
	
	$SGST = 0;
	$CGST = 0;
	$IGST = 0;
	
}
if($gst_type =='HSSWithinState'){
	
	$SGST = 0;
	$CGST = 0;
	$IGST = 0;
	
}

if($gst_type =='DirectExports'){
	
	$SGST = 0;
	$CGST = 0;
	$IGST = 0;
	
}





$query = "select * from quotation_more_product_02 where quotation_id = '".$_REQUEST['quotation_id']."' AND customer_id = '".$_REQUEST['customer_id']."' AND deleted !='YES'  ORDER BY more_product_id desc";
 $i=1;

	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();

	
	$output = '<div align="center"><h3>'.$quotation_tital.'</h3><br />
</div>
		<table border="1" style="border-collapse:collapse" width="100%">
  <tr>
    <td colspan="3" rowspan="3"><img src="http://toshiotechnologyapp.com/upload/company_logo/'.$image.'" style="width: 163px;padding: 10px 10px 10px 10px; "></td>
    <td colspan="3" class="style8"><div align="left"><span style=" text-align: center; "><b>'.$company_name.'</b> <br/>
        <span style="font-size: 12px;">'.$company_subtitle.'</span></span></div></td>
  </tr>
  <tr>
    <td colspan="3" class="style8"><div align="left" style="padding:3px;"><b>Billing Add.:</b>'.$billing_address_our.'</div></td>
  </tr>
  <tr>
    <td colspan="3" valign="top" class="style8"><div align="left" style="padding:3px;"><b>Sales Person details:</b><br/>
          <b>Name:</b> '.$first_name.' &nbsp; '.$last_name.'<br/>
          <b>Email:</b> '.$email_id.'<br/>
          <b>Mobile:</b>'.$mobile_no.'<br/>
    </div></td>
  </tr>
  <tr>
    <td colspan="6"><div align="center" class="style7">Communication Address : '.$communication_address.'</div></td>
  </tr>
  <tr>
    <td colspan="6"><div align="center" class="style7">GSTIN/UIN : '.$gst_no1.' &nbsp; ||&nbsp;    PAN NO : '.$pan_no.' &nbsp;&nbsp;    MSME No: '.$MSME_NO.' &nbsp;&nbsp;    Code :'.$code.' &nbsp;&nbsp;    CIN  : '.$CIN.'</div></td>
  </tr>
  <tr>
    <td><div align="left" class="style5" style="padding:3px;"><strong>Quotation No.</strong></div></td>
    <td><div align="left" class="style5" style="padding:3px;"><strong>:</strong></div></td>
    <td><div align="left" class="style5" style="padding:3px;">'.$final_quotation_no.'</div></td>
    <td><div align="left" class="style5" style="padding:3px;"><strong>Reference</strong></div></td>
    <td><div align="left" class="style5" style="padding:3px;"><strong>:</strong></div></td>
    <td><div align="left" class="style5" style="padding:3px;"></div></td>
  </tr>
  <tr>
    <td><div align="left" class="style5" style="padding:3px;"><strong>Quotation Date</strong> </div></td>
    <td><div align="left" class="style5" style="padding:3px;"><strong>:</strong></div></td>
    <td><div align="left" class="style5" style="padding:3px;">'.$date.'</div></td>
    <td><div align="left" class="style5" style="padding:3px;"><strong>Date</strong></div></td>
    <td><div align="left" class="style5" style="padding:3px;"><strong>:</strong></div></td>
    <td><div align="left" class="style5" style="padding:3px;"></div></td>
  </tr>
  <tr>
    <td colspan="3"><div align="center" class="style5" style="padding:3px;"><strong>Billing Address / To:</strong></div></td>
    <td colspan="3"><div align="center" class="style5" style="padding:3px;"><strong>Delivery Address</strong></div></td>
  </tr>
  <tr>
    <td colspan="3"><div align="left" class="style5" style="padding:3px;">M/s. '.$customer_name.'<br/>		
						'.$billing_address.' ,<br/></div></td>
    <td colspan="3"><div align="left" class="style5" style="padding:3px;">M/s. '.$customer_name.'<br/>		
						'.$delivery_address.' ,</div></td>
  </tr>
  <tr>
    <td colspan="3"><div align="left" class="style5" style="padding:3px;"><strong>Tel NO :</strong> '.$bill_contact_no.'</div></td>
    <td colspan="3"><div align="left" class="style5" style="padding:3px;"><strong>Tel NO : </strong>'.$del_contact_no.'</div></td>
  </tr>
  <tr>
    <td colspan="3"><div align="left" class="style5" style="padding:3px;"><strong>GST IN/ UIN :</strong>'.$billing_GST_no.'</div></td>
    <td colspan="3"><div align="left" class="style5" style="padding:3px;"><strong>GST IN/ UIN :</strong>'.$delivery_GST_no.'</div></td>
  </tr>
  <tr>
    <td colspan="3"><div align="left" class="style5" style="padding:3px;"><strong>MSME :</strong>'.$MSME.'</div></td>
    <td colspan="3"><div align="left" class="style5" style="padding:3px;"><strong>MSME :</strong>'.$MSME.'</div></td>
  </tr>
  <tr>
    <td colspan="3"><div align="left" class="style5" style="padding:3px;"><strong>Email :</strong>'.$bill_email_id.'</div></td>
    <td colspan="3"><div align="left" class="style5" style="padding:3px;"><strong>Email :</strong>'.$del_email_id.'</div></td>
  </tr>
  <tr>
    <td colspan="3"><div align="left" class="style5" style="padding:3px;"><strong>Kind Attn :</strong>'.$bill_kind_atten.'</div></td>
    <td colspan="3"><div align="left" class="style5" style="padding:3px;"><strong>Kind Attn :</strong>'.$del_kind_atten.' </div></td>
  </tr>
  
  <tr>
    <td colspan="6"><table width="100%" border="1" style="border-collapse:collapse">
      <tr>
        <td rowspan="2" valign="top"><div align="left" style="padding:2px;" class="style5">SN</div></td>
        <td rowspan="2" valign="top"><div align="left" style="padding:2px;" class="style5">Description of Goods</div></td>
        <td rowspan="2" valign="top"><div align="left" style="padding:2px;" class="style5">HSN Code</div></td>
        <td rowspan="2" valign="top"><div align="center" style="padding:2px;" class="style5">Qty</div></td>
        <td rowspan="2" valign="top"><div align="left" style="padding:2px;" class="style5">Discounted Price</div></td>
        <td colspan="2" valign="top"><div align="center" style="padding:2px;" class="style5">Packing Charges</div></td>
        <td colspan="2" valign="top"><div align="center" style="padding:2px;" class="style5">Insurance Charges</div></td>
        <td><div align="center" style="padding:2px;" class="style5">Taxable</div></td>
        <td colspan="2"><div align="center" style="padding:2px;" class="style5">CGST</div></td>
        <td colspan="2"><div align="center" style="padding:2px;" class="style5">SGST</div></td>
        <td colspan="2"><div align="center" style="padding:2px;" class="style5">IGST</div></td>
        <td><div align="center" style="padding:2px;" class="style5">Total</div></td>
      </tr>
      <tr>
        <td><div align="center" style="padding:2px;" class="style5">Value</div></td>
        <td><div align="center" style="padding:2px;" class="style5">Rate</div></td>
        <td><div align="center" style="padding:2px;" class="style5">Value</div></td>
        <td><div align="center" style="padding:2px;" class="style5">Rate</div></td>
        <td><div align="center" style="padding:2px;" class="style5">Value</div></td>
        <td><div align="center" style="padding:2px;" class="style5">Value</div></td>
        <td><div align="center" style="padding:2px;" class="style5">Rate</div></td>
        <td><div align="center" style="padding:2px;" class="style5">Value</div></td>
        <td><div align="center" style="padding:2px;" class="style5">Rate</div></td>
        <td><div align="center" style="padding:2px;" class="style5">Value</div></td>
        <td><div align="center" style="padding:2px;" class="style5">Rate</div></td>
        <td>&nbsp;</td>
      </tr>
	';
$k=1;

foreach($result as $row)
{

$product_desc = $row['product_name'];
$product_id = $row['product_id'];
$more_product_id = $row['more_product_id'];
$unit=$row['unit'];
$qty = $row['qty'];
$due_date = $row['due_date'];
$lead_time = $row['lead_time'];
$pro_value= $price*$qty;
$grandtotal+=$pro_value;
$sumqty+=$qty;
$unit =  $row['unit']; 
$qty =  $row['qty']; 
$more_product_id =  $query3['more_product_id']; 
$price =  $row['po_price']; 
$packing_charges01 = $row['packing_charges'];
$insurance_charges01 = $row['insurance_charges'];

$packing_charges = $price*$packing_charges01/100;
$insurance_charges = $price*$insurance_charges01/100;

$HSN_code = $row['HSN_code'];
$qtysum += $qty;
if($tax_type=='Local') {
$CGST = $row['CGST_rate'];
$SGST = $row['SGST_rate'];
}
if($tax_type=='OMS') {
$IGST = $row['IGST_rate'];
}
$UGST = $row['UGST_rate'];
//max($IGST);

$items_max[] = $IGST;

$maxtax =  max($items_max);
$queryls = "select * from product_details where product_id='$product_id'";
$statement1 = $connect->prepare($queryls);
$statement1->execute();
$resultls = $statement1->fetchAll();
foreach($resultls as $row1)
{
$gross_wt = $row1['gross_wt'];
$net_wt = $row1['net_wt'];
$product_type = $row1['product_type'];
}
$query3s = "select * from product_type_rate where id='$product_type'";
$statement11 = $connect->prepare($query3s);
$statement11->execute();
$result3s = $statement11->fetchAll();
foreach($result3s as $row4)
{
$product_type_description = $row4['product_type_description'];
}
$taxvalue= $price;  
$amt02=($taxvalue*$qty)+$packing_charges+$insurance_charges; 
$sumoffer+=$amt02;
$cgstvalue = $amt02*$CGST/100; $sumcgst+=$cgstvalue;
$sgstvalue = $amt02*$SGST/100; $sumsgst+=$sgstvalue;
$igstvalue = $amt02*$IGST/100; 
$sumigst+=$igstvalue;
$total01 = $amt02+$cgstvalue+$sgstvalue+$igstvalue; 
$sumtotal+=$total01;
if (is_numeric($freight_charges)) {
$taxble_value = $freight_charges+$sumoffer;
}
$totalgst = round($sumigst+$sumcgst+$sumsgst,2);

   $no = floor($sumtotal);
   $point = round($sumtotal - $no, 2) * 100;
   $hundred = null;
   $digits_1 = strlen($no);
   $i = 0;
   $str = array();
   $words = array('0' => '', '1' => 'one', '2' => 'two',
    '3' => 'three', '4' => 'four', '5' => 'five', '6' => 'six',
    '7' => 'seven', '8' => 'eight', '9' => 'nine',
    '10' => 'ten', '11' => 'eleven', '12' => 'twelve',
    '13' => 'thirteen', '14' => 'fourteen',
    '15' => 'fifteen', '16' => 'sixteen', '17' => 'seventeen',
    '18' => 'eighteen', '19' =>'nineteen', '20' => 'twenty',
    '30' => 'thirty', '40' => 'forty', '50' => 'fifty',
    '60' => 'sixty', '70' => 'seventy',
    '80' => 'eighty', '90' => 'ninety');
   $digits = array('', 'hundred', 'thousand', 'lakh', 'crore');
   while ($i < $digits_1) {
     $divider = ($i == 2) ? 10 : 100;
     $number = floor($no % $divider);
     $no = floor($no / $divider);
     $i += ($divider == 10) ? 1 : 2;
     if ($number) {
        $plural = (($counter = count($str)) && $number > 9) ? 's' : null;
        $hundred = ($counter == 1 && $str[0]) ? ' and ' : null;
        $str [] = ($number < 21) ? $words[$number] .
            " " . $digits[$counter] . $plural . " " . $hundred
            :
            $words[floor($number / 10) * 10]
            . " " . $words[$number % 10] . " "
            . $digits[$counter] . $plural . " " . $hundred;
     } else $str[] = null;
  }
  $str = array_reverse($str);
  $result = implode('', $str);
  $points = ($point) ?
    "." . $words[$point / 10] . " " . 
          $words[$point = $point % 10] : '';



		$output .= '
		<tr>
        <td><div align="left" style="padding:2px;" class="style5">'.$k.'</div></td>
        <td><div align="left" style="padding:2px; line-height:140%;" class="style5"><strong> '.$product_desc.'</strong><br>'.$product_type_description.'<br>
Gross Wt.  '.$gross_wt.', Net Wt.  '.$net_wt.'</div></td>
        <td><div align="left" style="padding:2px;" class="style5">'.$HSN_code.'</div></td>
        <td><div align="left" style="padding:2px;" class="style5">'.$qty.' '.$unit.'</div></td>
        <td><div align="left" style="padding:2px;" class="style5">'.round($price,0).'</div></td>
        <td><div align="center" style="padding:2px;" class="style5">'.round($packing_charges,0).'</div></td>
        <td><div align="center" style="padding:2px;" class="style5">'.$packing_charges01.'%</div></td>
        <td><div align="center" style="padding:2px;" class="style5">'.round($insurance_charges,0).'</div></td>
        <td><div align="center" style="padding:2px;" class="style5">'.$insurance_charges01.'%</div></td>
        <td><div align="left" style="padding:2px;" class="style5">'.$amt02.'</div></td>
        <td><div align="left" style="padding:2px;" class="style5">'.round($cgstvalue,2).'</div></td>
        <td><div align="left" style="padding:2px;" class="style5">'.$CGST.'%</div></td>
        <td><div align="left" style="padding:2px;" class="style5">'.round($sgstvalue,2).'</div></td>
        <td><div align="left" style="padding:2px;" class="style5">'.$SGST.'%</div></td>
        <td><div align="left" style="padding:2px;" class="style5">'.round($igstvalue,2).'</div></td>
        <td><div align="left" style="padding:2px;" class="style5">'.$IGST.'%</div></td>
        <td><div align="left" style="padding:2px;" class="style5">'.round($total01,2).'</div></td>
      </tr>';
     
      $k++; } 

	$output .= ' <tr>
        <td colspan="10"><div align="left" class="style8" style="padding:3px;">1. Freight : '.$frieght_terms.'</div></td>
        <td colspan="5"><div align="right" class="style8" style="padding:3px;">Net Amount (DISCOUNTED)</div></td>
        <td colspan="2"><div align="right" style="padding:3px;" class="style5">'.round($sumoffer,2).'</div></td>
        </tr>
	   <tr>
	     <td colspan="10"><div align="left" class="style8" style="padding:3px;">2. Payment Term : '.$payment_mode.'</div></td>
	     <td colspan="5"><div align="right" class="style8" style="padding:3px;">Freight Chargess '.$frieght_terms.'</div></td>
	     <td colspan="2"><div align="right" style="padding:3px;" class="style5">'.round($freight_charges,2).'</div></td>
        </tr>
	   <tr>
	     <td colspan="10"><div align="left" class="style8" style="padding:3px;">3. Commissione Rate : '.$commissionerate.'</div></td>
	     <td colspan="5"><div align="right" class="style8" style="padding:3px;">TAXABLE VALUE</div></td>
	     <td colspan="2"><div align="right" style="padding:3px;" class="style5">'.$taxble_value.'</div></td>
        </tr>
	   <tr>
	     <td colspan="10"><div align="left" class="style8" style="padding:3px;">4. Division : '.$dvision.'</div></td>
	     <td colspan="5"><div align="right" class="style8" style="padding:3px;">ADD CGST</div></td>
	     <td colspan="2"><div align="right" style="padding:3px;" class="style5">'.round($sumcgst,2).'</div></td>
        </tr>
	   <tr>
	     <td colspan="10"><div align="left" class="style8" style="padding:3px;">5. Range : '.$ranges.'</div></td>
	     <td colspan="5"><div align="right" class="style8" style="padding:3px;">ADD SGST</div></td>
	     <td colspan="2"><div align="right" style="padding:3px;" class="style5">'.round($sumsgst,2).'</div></td>
        </tr>
	   <tr>
	     <td colspan="10"><div align="left" class="style8" style="padding:3px;">6. Delivery Note : '.$delivery_note.'</div></td>
	     <td colspan="5"><div align="right" class="style8" style="padding:3px;">ADD IGST</div></td>
	     <td colspan="2"><div align="right" style="padding:3px;" class="style5">'.round($sumigst,2).'</div></td>
        </tr>
	   <tr>
	     <td colspan="10" rowspan="2"><div align="left" class="style8" style="padding:3px; line-height:120%;">7. Bank Details : <br />
	       Bank Name : '.$bank_name.'<br />
	       Account No.: '.$account_number.'<br />
	       Branch : '.$branch_name.' <br />
           IFSC Code :'.$IFSC_code.'</div></td>
	     <td colspan="5"><div align="right" style="padding:3px;" class="style5"><strong>TOTAL GST Value</strong></div></td>
	     <td colspan="2"><div align="right" style="padding:3px;" class="style5">'.$totalgst.'</div></td>
        </tr>
	   <tr>
	     <td colspan="5"><div align="right" style="padding:3px;" class="style5"><strong>GRAND TOTAL</strong></div></td>
	     <td colspan="2"><div align="right" style="padding:3px;" class="style5">'.round($sumtotal,0).'</div></td>
        </tr>
	   <tr>
	     <td colspan="17"><div align="left" class="style8" style="padding:3px; line-height:170%; text-transform:capitalize">GRAND TOTAL in Word:  INR   '.$result.'

		 
		</td>
        </tr>
		
		   <tr>
	     <td colspan="17"><div align="right" style="padding:3px;" class="style5"><b>
			'.$Signatory_name.'										
			<br/>
			<br/>
			<br/>
										
			Authorised Signatory										
 </b></div></td>
        </tr>
	   <tr>
	     <td colspan="17" style="color:#000000;"><div align="left" style="padding:3px; color:#000000;" class="style5">Note: </br>
				'.$note.'  '.$jurisdiction.'  </br>
				</br>
				'.$extra_note03.'
			  </div></td>
        </tr>
	   <tr>
	     <td colspan="17"><div align="center" class="style5a"  style="padding:3px;">'.$footer.'</div></td>
        </tr>
		
		
		
		</table>
	';
	return $output;
}

if(isset($_POST["action"]))
{
$quotation_id=$_REQUEST['quotation_id'];
$customer_id=$_REQUEST['customer_id'];

include 'connection.php';


$querymail = "select * from mst_email_covering where type='quotation_covering' ";
$statement3mail = $connect->prepare($querymail);
$statement3mail->execute();
$resultmail = $statement3mail->fetchAll();
foreach($resultmail as $mail)
{
$note_content = $mail['note_content'];
}

$queryemail12 = "select * from email_config";
$statementemail12 = $connect->prepare($queryemail12);
$statementemail12->execute();
$resultemail12 = $statementemail12->fetchAll();
foreach($resultemail12 as $email_mail12)
{
 $sahavas = $email_mail12['sahavas'];
}

$address = explode(',', $sahavas);   

$queryemail_cus = "select * from mst_customer where c_id='$customer_id';";
$statementemailcus = $connect->prepare($queryemail_cus);
$statementemailcus->execute();
$resultemailcust = $statementemailcus->fetchAll();
foreach($resultemailcust as $email_cust)
{
 $email_01=$email_cust['email_id'];
}


$queryemail = "select * from quotation_make_table_1 where quotation_id='$quotation_id';";
$statementemail = $connect->prepare($queryemail);
$statementemail->execute();
$resultemail = $statementemail->fetchAll();
foreach($resultemail as $email)
{
$call_follow_up_id=$email['call_follow_up_id'];
$final_quotation_no = $email['final_quotation_no'];
}

	include('pdf.php');
	//$file_name = md5(rand()) . '.pdf';
	$file_name = $final_quotation_no . '.pdf';
	
	$html_code = '<link rel="stylesheet" href="bootstrap.min.css">';
	$html_code .= fetch_customer_data($connect);
	$pdf = new Pdf();
	$pdf->load_html($html_code);
	//$pdf->setPaper(array(0,0,297,800));
	$pdf->setPaper('A2', 'portrait');
	$pdf->render();
	$file = $pdf->output();
	file_put_contents($file_name, $file);
	
	require 'class/class.phpmailer.php';
	require_once('class/class.smtp.php');
	$mail = new PHPMailer(true);
	$mail->IsSMTP();
	//$mail->SMTPDebug = 2;								//Sets Mailer to send message using SMTP
	$mail->Host = 'mail.toshiotechnologyapp.com';  //Sets the SMTP hosts of your Email hosting, this for Godaddy
 $mail->Port = '587';        //Sets the default SMTP server port
 $mail->SMTPAuth = true;       //Sets SMTP authentication. Utilizes the Username and Password variables
 $mail->Username = 'info@toshiotechnologyapp.com';     //Sets SMTP username
 $mail->Password = 'inf#technoapp@2021';     //Sets SMTP password
 $mail->SMTPSecure = '';       //Sets connection prefix. Options are "", "ssl" or "tls"
 $mail->From = 'info@toshiotechnologyapp.com';   //Sets the From email address for the message
 $mail->FromName = 'toshiotechnologyapp.com'; 
// while (list ($key, $val) = each ($address)) {
 
 foreach($address as $key => $val) {
$mail->AddAddress($val);
}  //Sets the From name of the message
 //$mail->AddAddress("$sahavas");  //Adds a "To" address
  //$mail->AddAddress('webdeveloper@sahavas.com', 'Name');  //Adds a "To" address
  	$mail->AddAddress($email_01);
	$mail->WordWrap = 5000;							//Sets word wrapping on the body of the message to a given number of characters
	$mail->IsHTML(true);							//Sets message type to HTML				
	$mail->AddAttachment($file_name);     				//Adds an attachment from a path on the filesystem
	$mail->Subject = 'Quotation Copy';			//Sets the Subject of the message
	$mail->Body = $note_content;				//An HTML or plain text message body
	if($mail->Send())								//Send an Email. Return true on success or false on error
	{
		$message = '<label class="text-success">Customer Details has been send successfully...</label>';
	}
	//unlink($file_name);
	
 $query12 = "update quotation_make_table_1 set qtn_status ='6',reason='$reason',qtn_status_date='$today' where customer_id = '".$_REQUEST['customer_id']."' AND quotation_id='$quotation_id' " ;
$r1=mysqli_query($conn,$query12);
  $query121 = "update call_follow_up set step ='6' where customer_id = '".$_REQUEST['customer_id']."' AND call_follow_up_id='$call_follow_up_id' " ;
$r11=mysqli_query($conn,$query121);
}

?>
<!DOCTYPE html>
<html>
	<head>
		
		<script src="jquery.min.js"></script>
		<link rel="stylesheet" href="bootstrap.min.css" />
		<script src="bootstrap.min.js"></script>
		<style type="text/css">
<!--
@page { size: 500pt 500pt; }
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
.style5 {font-family: Arial, Helvetica, sans-serif; font-size: 13px; }
.style7 {font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; line-height:210%; }

.style8 {font-family: Arial, Helvetica, sans-serif; font-size: 13px; font-weight: bold; }
</style>
	</head>
	<body>
	<div style="padding:20px;">
		<?php
			echo fetch_customer_data($connect);
			?>	
	</div>
	<div style="padding:20px;">
			<a href="http://toshiotechnologyapp.com/toshio_app/index.php" class="btn btn-primary btn-lg waves-effect waves-light" style="float:right; font-size:28px">Back to Dashboard</a><form method="post">
				<input type="submit" name="action" class="btn btn-danger" value="Send Mail" style="font-size:28px" /><?php echo $message; ?>
			</form> </div>
		
				

	</body>
</html>





