<?php
ob_start();
session_start();//ob_start();
if($_SESSION['admin_code']=="")
		header("Location: ../../index.php");
		

require_once('../../../../config/config.php');


class COMMON {

	public $database;
	public $con;
	



/** 
*  Function:   convert_number 
*
*  Description: 
*  Converts a given integer (in range [0..1T-1], inclusive) into 
*  alphabetical format ("one", "two", etc.)
*
*  @int
*
*  @return string
*
*/ 
		
		function fetchfromtable_one($table,$code,$data)
		{
			 $sql 	=	"SELECT * FROM ".$table." WHERE ".$code."=".$data."  ";
			$res 	= 	mysql_query($sql);
			$result = mysql_fetch_assoc($res);
			return $result;
		}
		
		function fetch_order_details($id)
		{	
			 $qry = "SELECT * from customer_order_items where order_no='".$id."'";
			  
			$result = mysql_query($qry);
			while( $rows = mysql_fetch_assoc($result))		
			{
				$fetech[]=$rows;			
				
			}		
			return $fetech;
		}
		
		function fetch_cust_details($id)
		{	
			 $qry = "SELECT * from customer where code='".$id."'";
			
			$result = mysql_query($qry);
			return $rows = mysql_fetch_assoc($result);
		}
		

function convert_number($number) 
{ 
    if (($number < 0) || ($number > 999999999)) 
    { 
    throw new Exception("Number is out of range");
    } 

    $Gn = floor($number / 1000000);  /* Millions (giga) */ 
    $number -= $Gn * 1000000; 
    $kn = floor($number / 1000);     /* Thousands (kilo) */ 
    $number -= $kn * 1000; 
    $Hn = floor($number / 100);      /* Hundreds (hecto) */ 
    $number -= $Hn * 100; 
    $Dn = floor($number / 10);       /* Tens (deca) */ 
    $n = $number % 10;               /* Ones */ 

    $res = ""; 

    if ($Gn) 
    { 
        $res .= $this->convert_number($Gn) . " Million"; 
    } 

    if ($kn) 
    { 
        $res .= (empty($res) ? "" : " ") . 
            $this->convert_number($kn) . " Thousand"; 
    } 

    if ($Hn) 
    { 
        $res .= (empty($res) ? "" : " ") . 
            $this->convert_number($Hn) . " Hundred"; 
    } 

    $ones = array("", "One", "Two", "Three", "Four", "Five", "Six", 
        "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", 
        "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eightteen", 
        "Nineteen"); 
    $tens = array("", "", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", 
        "Seventy", "Eigthy", "Ninety"); 

    if ($Dn || $n) 
    { 
        if (!empty($res)) 
        { 
            $res .= " and "; 
        } 

        if ($Dn < 2) 
        { 
            $res .= $ones[$Dn * 10 + $n]; 
        } 
        else 
        { 
            $res .= $tens[$Dn]; 

            if ($n) 
            { 
                $res .= "-" . $ones[$n]; 
            } 
        } 
    } 

    if (empty($res)) 
    { 
        $res = "zero"; 
    } 

    return $res; 
}

////////////////////////////////////////////


	function __CONSTRUCT()
	{	
		//$this->con=mysql_connect("localhost","root","");
		//$this->database = mysql_select_db("money");
		$this->con = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
		$this->database = mysql_select_db(DB_DATABASE);
	}
	
	
	
	
	
	
	
}	#class ends 


require('fpdf.php');

$comm = new COMMON;


class PDF extends FPDF
{
//Load data
function LoadData($file)
{
    //Read file lines
    $lines=file($file);
    $data=array();
    foreach($lines as $line)
        $data[]=explode(';',chop($line));
    return $data;
}

//Simple table
function CasicTable($header,$data)
{
    //Header
    foreach($header as $col)
        $this->Cell(40,7,$col,1);
    $this->Ln();
    $data=array();
    foreach($data as $row)
    {
        foreach($row as $col)
            $this->Cell(40,6,"abc",1);
        $this->Ln();
    }
}




//Cetter table
function ImprovedTable($header,$data)
{
    //Column widths
    $w=array(40,35,40,45);
    //Header
    for($i=0;$i<count($header);$i++)
        $this->Cell($w[$i],7,$header[$i],1,0,'C');
    $this->Ln();
    //Data
    foreach($data as $row)
    {
        $this->Cell($w[0],6,$row[0],'LR');
        $this->Cell($w[1],6,$row[1],'LR');
        $this->Cell($w[2],6,number_format($row[2]),'LR',0,'R');
        $this->Cell($w[3],6,number_format($row[3]),'LR',0,'R');
        $this->Ln();
    }
    //Closure line
    $this->Cell(array_sum($w),0,'','T');
}

//Colored table
function FancyTable($header,$data)
{
    //Colors, line width and bold font
    $this->SetFillColor(255,0,0);
    $this->SetTextColor(255);
    $this->SetDrawColor(128,0,0);
    $this->SetLineWidth(.3);
    $this->SetFont('','C');
    //Header
    $w=array(40,35,40,45);
    for($i=0;$i<count($header);$i++)
        $this->Cell($w[$i],7,$header[$i],1,0,'C',true);
    $this->Ln();
    //Color and font restoration
    $this->SetFillColor(224,235,255);
    $this->SetTextColor(0);
    $this->SetFont('');
    //Data
    $fill=false;
    foreach($data as $row)
    {
        $this->Cell($w[0],6,$row[0],'LR',0,'L',$fill);
        $this->Cell($w[1],6,$row[1],'LR',0,'L',$fill);
        $this->Cell($w[2],6,number_format($row[2]),'LR',0,'R',$fill);
        $this->Cell($w[3],6,number_format($row[3]),'LR',0,'R',$fill);
        $this->Ln();
        $fill=!$fill;
    }
    $this->Cell(array_sum($w),0,'','T');
}
}

$pdf=new PDF();
//Column titles
$he =2;
$cc =new COMMON();


		$pdf->AddPage();
		
		
				$order = $comm->fetchfromtable_one("customer_orders","code",$_REQUEST['code']);
				
				
				//$customer_d = $comm->fetchfromtable_one("customer","code",$order['code']);
				
				$data2 = $comm->fetch_order_details($order['code']);
				 
				//$d = $comm->fetch_cust_details($order['cust_id']); 
				$d = $order;
			
				 
				$order['display_symbol'] = '$';
				 $order['multyply_by'] = '1';
				
				
				
		//if($d['c_status']=="" or $d['c_status']=="W")
		//	die();
		//$pdf->Image('bg.gif',0,0,200);
		
		
		
				 $pdf->Image('logo.gif',140,10,56);	
				
			//	$pdf->SetFillColor(153,176,192);
				
				    //$pdf->SetFillColor(122,139,149);
					
					$pdf->SetFont('Arial','',13);
					$pdf->SetTextColor(0,0,0);
					
				 
					
					$h=5;
					
					$pdf->Cell(5,$h,"","LT",0,'C',false);
					$pdf->Cell(120,$h,"","T",0,'R',false);
					$pdf->Cell(60,$h,"","T",0,'L',false);
					$pdf->Cell(5,$h,"","TR",0,'C',false);	 
					$pdf->ln();
					
					 
					
					$pdf->Cell(5,$h,"","L",0,'C',false);
					$pdf->Cell(120,$h,"","",0,'R',false);
					$pdf->Cell(60,$h,'',"",0,'R',false);
					$pdf->Cell(5,$h,"","R",0,'C',false); 
					$pdf->ln();
					$pdf->Cell(5,$h,"","L",0,'C',false); 
					$pdf->Cell(180,$h,("TAX INVOICE"),"",0,'L',false);
					$pdf->Cell(5,$h,"","R",0,'C',false); 
					$pdf->ln();
					
					$pdf->SetFont('Arial','',8);
					$pdf->SetTextColor(55,42,19);
					$pdf->Cell(5,$h,"","L",0,'C',false); 
					$pdf->Cell(180,$h,'',"",0,'L',false);
					$pdf->Cell(5,$h,"","R",0,'C',false); 
					$pdf->ln();
					$h=10;
					$pdf->Cell(5,$h,"","L",0,'C',false); 
					$pdf->Cell(180,$h,(""),"",0,'L',false);
					$pdf->Cell(5,$h,"","R",0,'C',false); 
					$pdf->ln();
					
					$h=4; 
										
					
					$pdf->Cell(5,$h,"","L",0,'C',false);$pdf->SetFont('Arial','b',8); 
					$pdf->SetFont('Arial','',10)	;		 
					$pdf->Cell(90,$h,("Net Payable : ".' Rs. '.number_format(($order['paid_after_did']),2)),"",0,'L',false);
					$pdf->SetFont('Arial','b',8);
					$pdf->Cell(90,$h,("JShine Souk Private Limited"),"",0,'R',false);
					$pdf->Cell(5,$h,"","R",0,'C',false); 
					$pdf->ln();
					$pdf->SetFont('Arial','',12);
					   
					 
					$sql 	=	"SELECT * FROM admin_users WHERE admin_id=".$order['admin_id']."  ";
					$res 	= 	mysql_query($sql);
					$user_det = mysql_fetch_assoc($res);
				
					if($user_det['store_code']<=0)
						$user_det['store_code'] = 1;
					$sql 	=	"SELECT * FROM store_master WHERE code=".$user_det['store_code']."  ";
					$res 	= 	mysql_query($sql);
					$store_add = mysql_fetch_assoc($res); 
					 
					   
					$pdf->Cell(5,$h,"","L",0,'C',false);				 
					$pdf->Cell(90,$h,'',"",0,'L',false);	
					$pdf->SetFont('Arial','',8);
					$pdf->Cell(90,$h,($store_add['address_1']),"",0,'R',false);
					$pdf->Cell(5,$h,"","R",0,'C',false); 
					$pdf->ln();
					
					
					
					$pdf->Cell(5,$h,"","L",0,'C',false);				 
					$pdf->SetFont('Arial','b',8);$pdf->Cell(90,$h,(""),"",0,'L',false);	
					$pdf->SetFont('Arial','',8);
					$pdf->Cell(90,$h,($store_add['address_2']),"",0,'R',false);
					$pdf->Cell(5,$h,"","R",0,'C',false); 
					$pdf->ln();
					
					 
					$pdf->Cell(5,$h,"","L",0,'C',false);	
					$pdf->SetFont('Arial','',10)	;		 
					$pdf->Cell(90,$h,"Invoice Number : ".$order['order_no'],"",0,'L',false);	
					$pdf->SetFont('Arial','',8);
					$pdf->Cell(90,$h,($store_add['address_3']),"",0,'R',false);
					$pdf->Cell(5,$h,"","R",0,'C',false); 
					$pdf->ln();
					
					
					$pdf->Cell(5,$h,"","L",0,'C',false);				 
					$pdf->SetFont('Arial','b',8);$pdf->Cell(90,$h,'',"",0,'L',false);	
					$pdf->SetFont('Arial','',8);
					$pdf->Cell(90,$h,("Email: contact@jshine.in"),"",0,'R',false);
					$pdf->Cell(5,$h,"","R",0,'C',false); 
					$pdf->ln();
					
					
					$pdf->Cell(5,$h,"","L",0,'C',false);				 
					$pdf->SetFont('Arial','b',8);$pdf->Cell(90,$h,'',"",0,'L',false);	
					$pdf->SetFont('Arial','',8);
					$pdf->Cell(90,$h,(''),"",0,'R',false);
					$pdf->Cell(5,$h,"","R",0,'C',false); 
					$pdf->ln();
					
					
					
					$pdf->Cell(5,$h,"","L",0,'C',false);				 
					$pdf->Cell(90,$h,'',"",0,'L',false);	
					$pdf->Cell(90,$h,("CIN: U52601PB2017PTC046630"),"",0,'R',false);
					$pdf->Cell(5,$h,"","R",0,'C',false);  
					$pdf->ln();
					
					$pdf->Cell(5,$h,"","L",0,'C',false);				 
					$pdf->Cell(90,$h,'',"",0,'L',false);	
					$pdf->Cell(90,$h,("GSTIN: 03AAECJ0107E1ZF"),"",0,'R',false);
					$pdf->Cell(5,$h,"","R",0,'C',false);  
					$pdf->ln();
					
					
					$pdf->Cell(5,$h,"","L",0,'C',false);				 
					$pdf->SetFont('Arial','b',8);$pdf->Cell(90,$h,("Bill To : "),"",0,'L',false);	
					$pdf->SetFont('Arial','',8);
					$pdf->Cell(90,$h,("PAN: AAECJ0107E"),"",0,'R',false);
					$pdf->Cell(5,$h,"","R",0,'C',false); 
					$pdf->ln();
										 
					$pdf->Cell(5,$h,"","L",0,'C',false);				 
					$pdf->SetFont('Arial','b',8);
					$pdf->Cell(90,$h,(strtoupper($order['billing_name'])).' ('.$order['customer_code'].')',"",0,'L',false);	
					$pdf->SetFont('Arial','',8);
					$pdf->Cell(90,$h,(""),"",0,'R',false);
					$pdf->Cell(5,$h,"","R",0,'C',false); 
					$pdf->ln();
					
					$pdf->Cell(5,$h,"","L",0,'C',false);				 
					$pdf->Cell(90,$h,$order['billing_add_1'].' '.$order['billing_add_2'],"",0,'L',false);	
					$pdf->Cell(65,$h,"Invoice Date : ","",0,'R',false);
					$pdf->Cell(25,$h,date("d-M-Y",strtotime($order['c_date'])),"",0,'R',false);
					$pdf->Cell(5,$h,"","R",0,'C',false);  
					$pdf->ln();
					
					
					$pdf->Cell(5,$h,"","L",0,'C',false);				 
					$pdf->Cell(90,$h,$order['billing_city'].', '.$order['billing_state'].', '.$order['billing_country'].', '.$order['billing_pin_code'],"",0,'L',false);	
					$pdf->Cell(65,$h,"Due Date : ","",0,'R',false);
					$pdf->Cell(25,$h,"Immediately","",0,'R',false);
					
					$pdf->Cell(5,$h,"","R",0,'C',false); ; 
					$pdf->ln();
					  
					
					$pdf->Cell(5,$h,"","L",0,'C',false);				 
					$pdf->Cell(90,$h,'Mobile : '.$order['billing_mobile'],"",0,'L',false);	
					$pdf->Cell(65,$h,"User : ","",0,'R',false);
					
					
					$sql 	=	"SELECT * FROM admin_users WHERE admin_id=".$order['admin_id']."  ";
					$res 	= 	mysql_query($sql);
					$result = mysql_fetch_assoc($res);
					
					
			
					$pdf->Cell(25,$h,$result['name'],"",0,'R',false);
				
				
				
				 
					 
					$pdf->Cell(5,$h,"","R",0,'C',false); 
					$pdf->ln();
					
					 
					 
					
					$h=5;
					$pdf->Cell(190,$h,"","LR",0,'C',false);
					$pdf->ln();
					
					$h=5;
					
					
					  
					
					
					
					
					$hh = 2;
					$h = 6;
					
					$pdf->SetFont('Arial','B',8);
					$pdf->SetFillColor(66,66,66);
					$pdf->SetDrawColor(66,66,66);
					$pdf->SetTextColor(255,255,255);
					
					
					$pdf->Cell(5,$h,"","L",0,'C',false);
					
					$pdf->Cell(10,$h,"#","LRBT",0,'L',true);
					
					
					$pdf->Cell(90,$h," Item","LRBT",0,'L',true);					 
					$pdf->Cell(20,$h,"Qty","LRBT",0,'C',true);
					$pdf->Cell(20,$h,"Amount","LRBT",0,'C',true);
					$pdf->Cell(20,$h,"TAX","LRBT",0,'C',true);					
					$pdf->Cell(20,$h,"Total","LRBT",0,'C',true);
					
					$pdf->SetDrawColor(0,0,0);
					$pdf->Cell(5,$h,"","R",0,'C',false);			
					$pdf->ln();
					 
					$pdf->SetFillColor(255,255,255);
					$pdf->SetTextColor(0,0,0);
					$pdf->SetFont('Arial','',8);
					$i=1;
					$h = 2;
							$pdf->SetDrawColor(0,0,0);
							$pdf->Cell(5,$h,"","L",0,'C',false); 
							$pdf->Cell(10,$h,'',"LR",0,'L',true);
							
									$t_print = '';
							$pdf->SetFont('Arial','',6);		
							
							$pdf->Cell(90,$h,$t_print,"LR",0,'L',true);
									$t_print = '';
							 
							$pdf->Cell(20,$h,$t_print,"LR",0,'R',true);
							$pdf->Cell(20,$h,'',"LR",0,'C',true);
							$pdf->Cell(20,$h,'',"LR",0,'C',true);
							$pdf->Cell(20,$h,$t_print,"LR",0,'R',true);
							$pdf->SetDrawColor(0,0,0);
							$pdf->Cell(5,$h,"","R",0,'C',false);			
							$pdf->ln();
							
							
					if(count($data2)>0)
					{
					
					foreach($data2 as $s)
					{
							$discount_p = 0;
							$h = 5;
							$pdf->SetFont('Arial','',8);
							//print_r($data2);
							$pdf->SetDrawColor(0,0,0);
							$pdf->Cell(5,$h,"","L",0,'C',false); 
							$pdf->Cell(10,$h,$i,"LR",0,'L',true);$i++;
							$pdf->SetFont('Arial','B',8);
							
							$t_print = ' '.$s['product_name'].' ('.$s['product_sku'].')';
							$pdf->Cell(90,$h,$t_print,"LR",0,'L',true);
							
							$pdf->SetFont('Arial','',8);
												
							$t_print = '';
							 					
							
							 $t_print = '   Diamond('.$s['diamond_name'].' @ '.$s['diamond_total_weight'].'ct) X ';
							  
							 if($s['diamond_discount_percentage']>0)
							 {	
							 	$d = ($s['diamond_rate']*$s['diamond_total_weight']) - $s['diamond_total'];
								$t_print.= number_format($s['diamond_total'],2).' ('.$s['diamond_discount_percentage']."% discount ".number_format($d,2).")";
							 	$discount_p+=$d;
								$discount_t+=$d;
								
							 }else
							 {
							 	$t_print.= number_format($s['diamond_total'],2);
							 	//$t_print.=' -----'.$s['diamond_discount_percentage'];
							 
							 }
							 $print_line_1 = $t_print;
							
							
							
							
							
							$t_print = $s['qty'];
							$pdf->Cell(20,$h,$t_print,"LR",0,'C',true);							
								
							
							if($order['code']<=76) 	
								$price = ($s['net_amount']+$discount_p);
							else
							{	
								$ptax=($s['t_cgst']+$s['t_sgst']+$s['t_igst']);
								$price = ($s['net_amount']+$discount_p+$ptax);
							}
								
							$total_net_amount+= $price;
								$t_print = number_format($price,2);
							
							
							
							$pdf->Cell(20,$h,$t_print,"LR",0,'C',true);
							
							
								$tt = $price*$s['qty'];
								
								$tax_p = round(($tt*3)/100,2);
							
							$total+=($tt-$discount_p);
								
								$t_print = number_format($tt,2);
                            $pdf->Cell(20,$h,number_format($tax_p,2),"LR",0,'C',true);
							$pdf->Cell(20,$h,$t_print,"LR",0,'R',true);
							$pdf->SetDrawColor(0,0,0);
							$pdf->Cell(5,$h,"","R",0,'C',false);			
							$pdf->ln();
							
							
							$h =3;
							$pdf->SetDrawColor(0,0,0);
							
							$pdf->Cell(5,$h,"","L",0,'C',false); 
							$pdf->Cell(10,$h,'',"LR",0,'L',true);
							
									
							
							$pdf->SetFont('Arial','',7);		
							
							/*if($s['discount_type']>0)
								$t_print = 'Discount @ '.number_format($s['discount_type'],2).'%';		
							else
								$t_print = '';
							
							*/
							$t_print = '   Certificate # '.$s['certificate_number'];
							$pdf->Cell(90,$h,$t_print,"LR",0,'L',true);
							$t_print = '';
							$pdf->Cell(20,$h,'',"LR",0,'R',true);
							$pdf->Cell(20,$h,'',"LR",0,'C',true);
							$pdf->Cell(20,$h,'',"LR",0,'R',true);
							$pdf->Cell(20,$h,'',"LR",0,'R',true);
							$pdf->SetDrawColor(0,0,0);
							$pdf->Cell(5,$h,"","R",0,'C',false);			
							$pdf->ln();
							
							$pdf->Cell(5,$h,"","L",0,'C',false); 
							$pdf->Cell(10,$h,'',"LR",0,'L',true);
							
									
							
							 $pdf->SetFont('Arial','',7);		
							 	
							$pdf->Cell(90,$h,$print_line_1,"LR",0,'L',true);
							$t_print = '';
							$pdf->Cell(20,$h,$t_print,"LR",0,'R',true);
							$pdf->Cell(20,$h,'',"LR",0,'C',true);
							$pdf->Cell(20,$h,'',"LR",0,'R',true);
							$pdf->Cell(20,$h,$t_print,"LR",0,'R',true);
							$pdf->SetDrawColor(0,0,0);
							$pdf->Cell(5,$h,"","R",0,'C',false);			
							$pdf->ln();
							$pdf->Cell(5,$h,"","L",0,'C',false); 
							$pdf->Cell(10,$h,'',"LR",0,'L',true);
							
									
							
							$pdf->SetFont('Arial','',7);		
							
							/*if($s['discount_type']>0)
								$t_print = 'Discount @ '.number_format($s['discount_type'],2).'%';		
							else
								$t_print = '';
							
							*/
							$t_print = '   Gold('.$s['metal_name'].' @ '.$s['metal_total_weight'].'gm) X '.number_format($s['metal_rate']*$s['metal_total_weight'],2); 
							 $pdf->Cell(90,$h,$t_print,"LR",0,'L',true);
							$t_print = '';
							$pdf->Cell(20,$h,$t_print,"LR",0,'R',true);
							$pdf->Cell(20,$h,'',"LR",0,'C',true);
							$pdf->Cell(20,$h,'',"LR",0,'R',true);
							$pdf->Cell(20,$h,$t_print,"LR",0,'R',true);
							$pdf->SetDrawColor(0,0,0);
							$pdf->Cell(5,$h,"","R",0,'C',false);			
							$pdf->ln();
							
							 
							$pdf->SetDrawColor(0,0,0);
							$pdf->Cell(5,$h,"","L",0,'C',false); 
							$pdf->Cell(10,$h,'',"LR",0,'L',true);
							
								if($s['gem_name']<>"")
									$t_print = '   Other('.$s['gem_name'].' @ '.$s['gem_total_weight'].'gm) X '.number_format($s['gem_rate'],2);
								else
									$t_print = '   Making Charges : '.number_format($s['making_charges'],2);	
							$pdf->SetFont('Arial','',7);		
							
							$pdf->Cell(90,$h,$t_print,"LR",0,'L',true);
							$t_print = '';
							 
							$pdf->Cell(20,$h,$t_print,"LR",0,'R',true);
							$pdf->Cell(20,$h,'',"LR",0,'C',true);
							$pdf->Cell(20,$h,'',"LR",0,'R',true);
							$pdf->Cell(20,$h,$t_print,"LR",0,'R',true);
							$pdf->SetDrawColor(0,0,0);
							$pdf->Cell(5,$h,"","R",0,'C',false);			
							$pdf->ln();
							
							
							$pdf->SetDrawColor(0,0,0);
							$pdf->Cell(5,$h,"","L",0,'C',false); 
							$pdf->Cell(10,$h,'',"LR",0,'L',true);
							
								 if($s['gem_name']<>"")
									$t_print = '   Making Charges : '.number_format($s['making_charges'],2);	
							$pdf->SetFont('Arial','',7);		
							
							$pdf->Cell(90,$h,$t_print,"LR",0,'L',true);
							$t_print = '';
							 
							$pdf->Cell(20,$h,$t_print,"LR",0,'R',true);
							$pdf->Cell(20,$h,'',"LR",0,'C',true);
							$pdf->Cell(20,$h,'',"LR",0,'R',true);
							$pdf->Cell(20,$h,$t_print,"LR",0,'R',true);
							$pdf->SetDrawColor(0,0,0);
							$pdf->Cell(5,$h,"","R",0,'C',false);			
							$pdf->ln();
							
							
							
							
							
                         }}
					
					while($i<=4)
					{
							$h = 5;
							$pdf->SetFont('Arial','',8);
							//print_r($data2);
							$pdf->SetDrawColor(0,0,0);
							$pdf->Cell(5,$h,"","L",0,'C',false); 
							$pdf->Cell(10,$h,'',"LR",0,'L',true);
							
									$t_print = '';
							$pdf->Cell(90,$h,$t_print,"LR",0,'L',true);
									 
							 	
								 						
							$pdf->Cell(20,$h,$t_print,"LR",0,'R',true);						
							$pdf->Cell(20,$h,'',"LR",0,'C',true);
							$pdf->Cell(20,$h,'',"LR",0,'R',true);
								
								 
                            $pdf->Cell(20,$h,$t_print,"LR",0,'R',true);
							$pdf->SetDrawColor(0,0,0);
							$pdf->Cell(5,$h,"","R",0,'C',false);			
							$pdf->ln();
							
							
							$h =3;
							$pdf->SetDrawColor(0,0,0);
							$pdf->Cell(5,$h,"","L",0,'C',false); 
							$pdf->Cell(10,$h,'',"LR",0,'L',true);
							
									 
							$pdf->SetFont('Arial','',6);		
							
							$pdf->Cell(90,$h,$t_print,"LR",0,'L',true);
									$t_print = '';
							 $pdf->Cell(20,$h,$t_print,"LR",0,'R',true);
							$pdf->Cell(20,$h,'',"LR",0,'C',true);
							$pdf->Cell(20,$h,'',"LR",0,'R',true);
							$pdf->Cell(20,$h,$t_print,"LR",0,'R',true);
							$pdf->SetDrawColor(0,0,0);
							$pdf->Cell(5,$h,"","R",0,'C',false);			
							$pdf->ln();
							
							
							$h =3;
							$pdf->SetDrawColor(0,0,0);
							$pdf->Cell(5,$h,"","L",0,'C',false); 
							$pdf->Cell(10,$h,'',"LR",0,'L',true);
							
									 
							$pdf->SetFont('Arial','',6);		
							
							$pdf->Cell(90,$h,$t_print,"LR",0,'L',true);
									$t_print = '';
							 $pdf->Cell(20,$h,$t_print,"LR",0,'R',true);
							$pdf->Cell(20,$h,'',"LR",0,'C',true);
							$pdf->Cell(20,$h,'',"LR",0,'R',true);
							$pdf->Cell(20,$h,$t_print,"LR",0,'R',true);
							$pdf->SetDrawColor(0,0,0);
							$pdf->Cell(5,$h,"","R",0,'C',false);			
							$pdf->ln();
							
							 
							$pdf->SetDrawColor(0,0,0);
							$pdf->Cell(5,$h,"","L",0,'C',false); 
							$pdf->Cell(10,$h,'',"LR",0,'L',true);
							
									$t_print = '';
							$pdf->SetFont('Arial','',6);		
							
							$pdf->Cell(90,$h,$t_print,"LR",0,'L',true);
									$t_print = '';
							 $pdf->Cell(20,$h,$t_print,"LR",0,'R',true);
							$pdf->Cell(20,$h,'',"LR",0,'C',true);
							$pdf->Cell(20,$h,'',"LR",0,'R',true);
							$pdf->Cell(20,$h,$t_print,"LR",0,'R',true);
							$pdf->SetDrawColor(0,0,0);
							$pdf->Cell(5,$h,"","R",0,'C',false);			
							$pdf->ln();
							$i++;
					}
					
						$pdf->SetDrawColor(0,0,0);
						$pdf->Cell(5,$h,"","L",0,'C',false); 
						$pdf->Cell(10,$h,'',"LRB",0,'L',true);
						
								$t_print = '';
						$pdf->SetFont('Arial','',6);		
						
						$pdf->Cell(90,$h,$t_print,"LRB",0,'L',true);
								$t_print = '';
						 $pdf->Cell(20,$h,$t_print,"LRB",0,'R',true);
						$pdf->Cell(20,$h,'',"LRB",0,'C',true);
						$pdf->Cell(20,$h,'',"LRB",0,'R',true);
						$pdf->Cell(20,$h,$t_print,"LRB",0,'R',true);
						$pdf->SetDrawColor(0,0,0);
						$pdf->Cell(5,$h,"","R",0,'C',false);			
						$pdf->ln();
							
					$pdf->SetFont('Arial','',8);		
							
					$h =5;		
					
					$pdf->Cell(5,$h,"","L",0,'C',false);
					$pdf->SetFont('Arial','',7);	
					$pdf->Cell(120,$h,"","TL",0,'L',true);
					$pdf->SetFont('Arial','',8);	
					$pdf->Cell(40,$h,"Sub Total :","TLR",0,'L',true);
					$pdf->Cell(20,$h,number_format(($total_net_amount),2),"LRT",0,'R',true);
					$pdf->Cell(5,$h,"","R",0,'C',false);			
					$pdf->ln();
					
					
					
					$pdf->SetFont('Arial','',7);
					 $ttt='';
						
					$pdf->Cell(5,$h,"","L",0,'C',false);
					$pdf->SetFont('Arial','',7);	
					$pdf->Cell(120,$h," ","L",0,'L',true);
					$pdf->SetFont('Arial','',8);
					
					
					
					
					
					if($order['code']<=76){ 
					
						 
						
						$pdf->SetFont('Arial','',8);
						$pdf->Cell(40,$h,'Adjustment(+/-)',"TLRB",0,'L',true);
						$pdf->Cell(20,$h,''.'-'.number_format(0,2),"TLRB",0,'R',true);
						$pdf->Cell(5,$h,"","R",0,'C',false);
						$pdf->ln();
					
					}else
					{
					
						$discount_t = $discount_t + $order['discount'];
						$pdf->SetFont('Arial','',8);
						$pdf->Cell(40,$h,'DHS Voucher:',"TLRB",0,'L',true);
						$pdf->Cell(20,$h,''.'-'.number_format($order['policy_amount'],2),"TLRB",0,'R',true);
						$pdf->Cell(5,$h,"","R",0,'C',false);
						$pdf->ln();
						$order['discount']+=$order['policy_amount'];
					}
					
				
					$pdf->Cell(5,$h,"","L",0,'C',false);
					
					$pdf->SetFont('Arial','',7);	
					$pdf->Cell(120,$h,"","L",0,'L',true);
					$pdf->SetFont('Arial','',8);
					
					$discount_t = $discount_t;
					$pdf->Cell(40,$h,"Discount: ".$order['discount_name']."","TLRB",0,'L',true);
					$pdf->Cell(20,$h,''.number_format($discount_t,2),"TLRB",0,'R',true);
					$pdf->Cell(5,$h,"","R",0,'C',false);
					$pdf->ln();
					
					/*$pdf->Cell(5,$h,"","L",0,'C',false);
					$pdf->SetFont('Arial','',7);	
					$pdf->Cell(120,$h,"  3. Please don't buy if no certificate of authenticity","L",0,'L',true);
					$pdf->SetFont('Arial','',8);
					$pdf->Cell(40,$h,"Shipping (+):","TLRB",0,'L',true);
					$pdf->Cell(20,$h,number_format($order['shiping'],2),"TLRB",0,'R',true);
					$pdf->Cell(5,$h,"","R",0,'C',false);
					$pdf->ln();*/
					
					$tax = 0;//$order['t_sgst']+$order['t_cgst']+$order['t_igst'];
					$st = $total - $order['discount'];
					if($order['code']<=76){ 
					
						$pdf->Cell(5,$h,"","L",0,'C',false);
						$pdf->SetFont('Arial','',7);	
						$pdf->Cell(120,$h,"  1. All products are Hallmarked and Authenticated","L",0,'L',true);
						$pdf->SetFont('Arial','',8);
						$pdf->Cell(40,$h,"Taxable Amount:","TLRB",0,'L',true);
						$pdf->Cell(20,$h,''.number_format($st,2),"TLRB",0,'R',true);
						$pdf->Cell(5,$h,"","R",0,'C',false);
						$pdf->ln();
					
					}else{
					
						$pdf->Cell(5,$h,"","L",0,'C',false);
						$pdf->SetFont('Arial','',7);	
						$pdf->Cell(120,$h,"  1. All products are Hallmarked and Authenticated","L",0,'L',true);
						$pdf->SetFont('Arial','',8);
						$pdf->Cell(40,$h,"Taxable Amount:","TLRB",0,'L',true);
						$pdf->Cell(20,$h,''.number_format($order['paid_after_did'] - $tax,2),"TLRB",0,'R',true);
						$pdf->Cell(5,$h,"","R",0,'C',false);
						$pdf->ln();
						
					}
					
					
					$te =array();
					$te[1] = '  2. Kindly ensure the products and certificates before leaving';
					$te[2] = '  3. This bill is final after complete audit and clearance';
					$te[3] = '  4. Terms and Conditions apply';
					$te[4] = '  ';
					$te[5] = ' ';
					 
					$jj = 1;
					
					/*$total_tax+= $order['t_igst']; 
					 
						$pdf->Cell(5,$h,"","L",0,'C',false);$pdf->SetFont('Arial','',7);
						$pdf->Cell(120,$h,$te[$jj],"L",0,'L',true);$pdf->SetFont('Arial','',8);
						$pdf->Cell(40,$h,"IGST(".$order['igst']."%):","TLRB",0,'L',true);
						$pdf->Cell(20,$h,''.number_format($order['t_igst'],2),"TLRB",0,'R',true);
						//$tax_amt=($order['net_amount'])*($order['igst']/100);
						//$pdf->Cell(20,$h,''.number_format($tax_amt, 2),"TLRB",0,'R',true);
						$pdf->Cell(5,$h,"","R",0,'C',false);
						$pdf->ln();
						$jj++;
					 
					
					$total_tax+= $order['t_cgst'];
					 
						$pdf->Cell(5,$h,"","L",0,'C',false);
						$pdf->SetFont('Arial','',7);$pdf->Cell(120,$h,$te[$jj],"L",0,'L',true);$pdf->SetFont('Arial','',8);
						$pdf->Cell(40,$h,"CGST(".$order['cgst']."%):","TLRB",0,'L',true);
						$pdf->Cell(20,$h,''.number_format($order['t_cgst'],2),"TLRB",0,'R',true);
						//$tax_amt=($order['net_amount'])*($order['cgst']/100);
						//$pdf->Cell(20,$h,''.number_format($tax_amt, 2),"TLRB",0,'R',true);
						$pdf->Cell(5,$h,"","R",0,'C',false);
						$pdf->ln();
						$jj++;
					 
					$total_tax+= $order['t_sgst'];
					 
						$pdf->Cell(5,$h,"","L",0,'C',false);
						$pdf->SetFont('Arial','',7);$pdf->Cell(120,$h,$te[$jj],"L",0,'L',true);$pdf->SetFont('Arial','',8);
						$pdf->Cell(40,$h,"SGST(".$order['sgst']."%):","TLRB",0,'L',true);
						$pdf->Cell(20,$h,''.number_format($order['t_sgst'],2),"TLRB",0,'R',true);
						//$tax_amt=($order['net_amount'])*($order['sgst']/100);
						//$pdf->Cell(20,$h,''.number_format($tax_amt, 2),"TLRB",0,'R',true);
						$pdf->Cell(5,$h,"","R",0,'C',false);
						$pdf->ln();
						$jj++;*/
					 
					if($order['igst'] && $order['igst']==3)
					{
						$pdf->Cell(5,$h,"","L",0,'C',false);$pdf->SetFont('Arial','',7);
						$pdf->Cell(120,$h,$te[$jj],"L",0,'L',true);$pdf->SetFont('Arial','',8);
						$pdf->Cell(40,$h,"GST(".$order['igst']."%):","TLRB",0,'L',true);
						$tax_amt=($order['net_amount'])*($order['igst']/100);
						$pdf->Cell(20,$h,''.number_format($tax_amt, 2),"TLRB",0,'R',true);
						$pdf->Cell(5,$h,"","R",0,'C',false);
						$pdf->ln();
						$jj++;
					}
					else if(($order['cgst'] && $order['sgst']) && (($order['cgst']+$order['sgst'])==3))
					{
						$pdf->Cell(5,$h,"","L",0,'C',false);
						$pdf->SetFont('Arial','',7);$pdf->Cell(120,$h,$te[$jj],"L",0,'L',true);$pdf->SetFont('Arial','',8);
						$pdf->Cell(40,$h,"CGST(".$order['cgst']."%):","TLRB",0,'L',true);
						$tax_amt1=($order['net_amount'])*($order['cgst']/100);
						$pdf->Cell(20,$h,''.number_format($tax_amt1, 2),"TLRB",0,'R',true);
						$pdf->Cell(5,$h,"","R",0,'C',false);
						$pdf->ln();
						$jj++;
					 	
					 
						$pdf->Cell(5,$h,"","L",0,'C',false);
						$pdf->SetFont('Arial','',7);$pdf->Cell(120,$h,$te[$jj],"L",0,'L',true);$pdf->SetFont('Arial','',8);
						$pdf->Cell(40,$h,"SGST(".$order['sgst']."%):","TLRB",0,'L',true);
						$tax_amt2=($order['net_amount'])*($order['sgst']/100);
						$pdf->Cell(20,$h,''.number_format($tax_amt2, 2),"TLRB",0,'R',true);
						$pdf->Cell(5,$h,"","R",0,'C',false);
						$pdf->ln();
						$jj++;
						
						$tax_amt=$tax_amt1+$tax_amt2;
					}
					
					/*$pdf->Cell(5,$h,"","L",0,'C',false);$pdf->SetFont('Arial','',7);
					$pdf->Cell(120,$h,$te[$jj],"L",0,'L',true);$pdf->SetFont('Arial','',8);
					$pdf->Cell(40,$h,"Payable Total:","TLRB",0,'L',true);
					$pdf->Cell(20,$h,''.number_format(($st+$total_tax),2),"TLRB",0,'R',true);
					$pdf->Cell(5,$h,"","R",0,'C',false);
					$pdf->ln();
					$jj++;*/
					
					if($order['code']<=76){ 
					
						$pdf->Cell(5,$h,"","L",0,'C',false);$pdf->SetFont('Arial','',7);
						$pdf->Cell(120,$h,$te[$jj],"L",0,'L',true);$pdf->SetFont('Arial','',8);
						$pdf->Cell(40,$h,"Advance Payment:","TLRB",0,'L',true);
						$pdf->Cell(20,$h,'-'.number_format($order['policy_amount'],2),"TLRB",0,'R',true);
						$pdf->Cell(5,$h,"","R",0,'C',false);
						$pdf->ln();
						$jj++;
					}
					
					$pdf->Cell(5,$h,"","L",0,'C',false);$pdf->SetFont('Arial','',7);
						$pdf->Cell(120,$h,$te[$jj],"L",0,'L',true);$pdf->SetFont('Arial','',8);
					
					$pdf->SetFont('Arial','B',8);
					$pdf->SetFillColor(66,66,66);
					$pdf->SetDrawColor(0,0,0);
					$pdf->SetTextColor(255,255,255);
					
					$pdf->Cell(40,$h,"Net Payable:","TLRB",0,'L',true);
				
					//$pdf->Cell(20,$h,''.number_format($order['paid_after_did'],2),"TLRB",0,'R',true);
					//$pdf->Cell(20,$h,''.number_format(($order['paid_after_did']+$order['t_cgst']+$order['t_sgst']+$order['t_igst']),2),"TLRB",0,'R',true);
					$pdf->Cell(20,$h,''.number_format($order['paid_after_did']+$tax_amt,2),"TLRB",0,'R',true);
					
					$pdf->SetFont('Arial','',7);
					$pdf->Cell(5,$h,"","R",0,'C',false);
					$pdf->ln();
					  
					$pdf->SetFillColor(255,255,255);
					//$pdf->SetDrawColor(66,66,66);
					$pdf->SetTextColor(0,0,0);
					
					
					
					
					
					$pdf->SetFont('Arial','b',8);
					if($order['product_taking_for']=='other')
						$ttt= 'Product Received by : '.$order['receiver_name'].' ('.$order['receiver_mobile'].')';
					else
						$ttt= '';
					
					if($order['policy_amount']>0)
					{	
						if($ttt<>"")
						   $ttt = ' - ';
						if($order['code']<=76){
						
						 $ttt.= 'Note: This booking has been adjusted in this invoice';
						 $ttt2= 'Booking Ref. #'.str_replace("Against Booking No :","",$order['policy_remarks']).' (Total Rs. '.number_format($order['policy_amount'],2).')';	
						 }
						 else
						 {
						 	$ttt.= 'Note: These DHS Coupons has been adjusted in this invoice';
						 	$ttt2= 'DHS Coupons Ref. #'.str_replace("Against DHS Coupons No :","",$order['policy_remarks']).' (Total Rs. '.number_format($order['policy_amount'],2).')';	
							$ttt = '';
						  	$ttt2 = '';
						 }
					}else
						$ttt.='';
						
					$pdf->Cell(5,$h,"","L",0,'C',false);	
					$pdf->Cell(180,$h,$ttt,"T",0,'L',true);					 		  		
					$pdf->Cell(5,$h,"","R",0,'C',false);		
					$pdf->ln();
					
					$pdf->Cell(5,$h,"","L",0,'C',false);	
					$pdf->Cell(180,$h,"".$ttt2,"",0,'L',true);					 		  		
					$pdf->Cell(5,$h,"","R",0,'C',false);		
					$pdf->ln();
					
					
					 
					 
					$pdf->SetFont('Arial','',7);
					$pdf->Cell(5,$h,"","LB",0,'C',false);	
					$pdf->Cell(180,$h,"Computer generated invoice requires no signature and stamp","B",0,'C',true);					 		  		
					$pdf->Cell(5,$h,"","RB",0,'C',false);		
					$pdf->ln();
					
					 
										
				 
					 $pdf->SetTextColor(99,99,99);
					 
					$pdf->SetFont('Arial','',7);
					//$pdf->Cell(190,$h,"Computer generated Invoice requires no signature and stamp","",0,'C',false);$pdf->ln();
					 	
 
					
				ob_end_clean();	
				//$pdf->Output("Invoice_".$order['code'].".pdf");//,"D"
				 $pdf->Output();
?>