<?php

include_once "invoice_includes.php";
////////////////////// CORE FUNCTION | MODULE FUNCTION (c) i2d Technologies //////////////////////////////////
////////////////////// CORE FUNCTION | MODULE FUNCTION (c) i2d Technologies //////////////////////////////////
//include_once('tcpdf_vars.php');

//include_once('tcpdf_proposal_fetch.php');

require_once('tcpdf_include.php');


if(!empty($_REQUEST['type'])){
$type=$_REQUEST['type'];
}

if(!empty($_REQUEST['id'])){
$rec_id=$_REQUEST['id'];
}

if(!empty($_REQUEST['alias'])){
$alias_found=$_REQUEST['alias'];
}


///////////////////////////////////////////////////


//$ref="expense_entry";


//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
$li_link=uplink();
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////

$title="Detail Sheet";

class MYPDF extends TCPDF {



    //Page header
    public function Header() {
        global $title;
		$this->SetFont('helvetica', 'B', 14);
        // Title
		$this->Cell(0, 15, $title, 0, false, 'C', 0, '', 0, false, 'M', 'M');
		$this->SetFont('helvetica', 'B', 10);
        $this->Cell(0, 15, "i2d Technologies MIS System v3.3", 0, false, 'R', 0, '', 0, false, 'M', 'M');
		 
    }

    // Page footer
    public function Footer() {
        // Position at 15 mm from bottom
        $this->SetY(-15);
        // Set font
        $this->SetFont('helvetica', 'I', 8);
        // Page number
        $this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
    }
}

$pdf = new MYPDF('L', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('i2d Technologies');
$pdf->SetTitle($title);
$pdf->SetSubject('billing@i2dtechnologies.com');
$pdf->SetKeywords('i2d technologies');
$font_size = $pdf->pixelsToUnits('25');

// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
    require_once(dirname(__FILE__).'/lang/eng.php');
    $pdf->setLanguageArray($l);
}

$pdf->SetFont ('helvetica', '', $font_size , '', 'default', true );


$pdf->SetMargins(3,15,3);





$pdf->AddPage();

$tbl_header = '<table border="1"  cellpadding="2" cellspacing="3" align="left" nobr="true">
<thead>
 <tr style="background-color:#000000;color:#FFFFFF;">
  <td width="40"><b>SNo</b></td>
  <td width="110"><b>DATED</b></td>
  <td width="110"><b>Business</b></td>
  <td><b>Domain</b></td>
  <td><b>Type</b></td>
  <td><b>Details</b></td>
  </tr>
  </thead>';
$tbl_footer = '</table>';

//update_id,sys_status,ref,lead_ref,date_time,update_detail,type 
$query="SELECT * from sys_updates WHERE type IN('76','19','66') AND update_id > 2318 ORDER by update_id DESC";

$query_li=$li_link->query($query); 
if($query_li){
$printitem[] = $query_li->fetch_array();
}

//var_dump($printitem);

$tbl ='';

//foreach ($printitem as $row)
while (($row = mysqli_fetch_assoc($query_li)))

  {
  $id = $row["update_id"];
  $dated = $row["date_time"];
  $business=db_ref('master','id',$row["lead_ref"],'col1');
  $domain=db_ref('master','id',$row["lead_ref"],'col10');
  $type=db_ref('child','id',$row["type"],'title');
  $detail=$row["update_detail"];
    
  
$tbl .= '<tr><td width="40">' . $id . '</td>
<td width="110">' . $dated . '</td><td width="110">' . $business . '</td><td>' . $domain . '</td><td>' . $type . '</td><td  width="210">' . $detail . '</td>';
}


echo $tbl_header . $tbl . $tbl_footer;

// Print text using writeHTMLCell()

//$pdf->writeHTML($tbl_header . $tbl . $tbl_footer, true, false, false, false, '');
// ---------------------------------------------------------
// Close and output PDF document
// This method has several options, check the source code documentation for more information.

//$total1=mysql_query("SELECT SUM(Amount) FROM acc_expenses");


$file="report"."pdf";
//$pdf->Output($file , 'I');

ob_flush();


















?>