<?php
    $prd_frm = isset($_REQUEST['prd_frm']) ? $_REQUEST['prd_frm'] : "";
    $prd_to = isset($_REQUEST['prd_to']) ? $_REQUEST['prd_to'] : "";
    $sur_id = isset($_REQUEST['sur_id']) ? $_REQUEST['sur_id'] : "";
    $trns_typ = isset($_REQUEST['trns_typ']) ? $_REQUEST['trns_typ'] : "";
    $reimb_typ = isset($_REQUEST['reimb_typ']) ? $_REQUEST['reimb_typ'] : "";
	
	$queryh = "Select reimbrsmnt_vchr_dt AS date, reimbrsmnt_head_id as hid, sum(reimbrsmnt_amt) as amt, sur_title FROM custom_reimbursement 
							INNER JOIN custom_survey_master ON (custom_survey_master.sur_code = custom_reimbursement.reimbrsmnt_survy_id)
                        WHERE reimbrsmnt_vchr_dt BETWEEN '".$common->date_format($prd_frm, DT_FMT, '')."' AND '".$common->date_format($prd_to, DT_FMT, '')."' AND reimbrsmnt_survy_id = '".$sur_id."' AND reimbrsmnt_amt != '0.00' GROUP BY reimbrsmnt_vchr_dt";
	
	$reimb_hds = "Select custom_reimbursement.reimbrsmnt_head_id as hid, reimbrsmnt_head_name, reimbrsmnt_vchr_dt, sum(reimbrsmnt_amt) as amt 
							FROM custom_reimbursement 
							LEFT JOIN custom_reimbursement_heads_master ON (custom_reimbursement_heads_master.reimbrsmnt_head_id = custom_reimbursement.reimbrsmnt_head_id)
                        WHERE reimbrsmnt_vchr_dt BETWEEN '".$common->date_format($prd_frm, DT_FMT, '')."' AND '".$common->date_format($prd_to, DT_FMT, '')."' AND reimbrsmnt_survy_id = '".$sur_id."' AND custom_reimbursement.reimbrsmnt_head_id != 0 GROUP BY reimbrsmnt_vchr_dt, custom_reimbursement.reimbrsmnt_head_id";
	$common->sql->query($reimb_hds, SQL_ALL, SQL_ASSOC);
    $reimb_hds_rec = $common->sql->record;
	
	$reimb_hds = "Select custom_reimbursement.reimbrsmnt_head_id as hid, reimbrsmnt_head_name, sum(reimbrsmnt_amt) as amt FROM custom_reimbursement 
							LEFT JOIN custom_reimbursement_heads_master ON (custom_reimbursement_heads_master.reimbrsmnt_head_id = custom_reimbursement.reimbrsmnt_head_id)
                        WHERE reimbrsmnt_vchr_dt BETWEEN '".$common->date_format($prd_frm, DT_FMT, '')."' AND '".$common->date_format($prd_to, DT_FMT, '')."' AND reimbrsmnt_survy_id = '".$sur_id."' AND custom_reimbursement.reimbrsmnt_head_id = '0' GROUP BY reimbrsmnt_vchr_dt, custom_reimbursement.reimbrsmnt_head_id";
	$common->sql->query($reimb_hds, SQL_ALL, SQL_ASSOC);
    $othr_hds_rec = $common->sql->record;
	
	$query1 = "Select reimbrsmnt_vchr_dt AS date, reg_participant_id as pid, sum(reimbrsmnt_amt) as amt, reimbrsmnt_vchr_no as vchr_no, sur_title FROM custom_participant_registration 
                            INNER JOIN custom_reimbursement 
                                ON (custom_reimbursement.reimbrsmnt_particpnt_id = custom_participant_registration.reg_participant_id)
							INNER JOIN custom_survey_master ON (custom_survey_master.sur_code = custom_participant_registration.reg_survey_id)
                        WHERE reimbrsmnt_vchr_dt BETWEEN '".$common->date_format($prd_frm, DT_FMT, '')."' AND '".$common->date_format($prd_to, DT_FMT, '')."' AND reimbrsmnt_survy_id = '".$sur_id."' AND reimbrsmnt_amt != '0.00' GROUP BY reimbrsmnt_vchr_no";
		
	$query2 = "Select incentive_vchr_dt AS date, reg_participant_id as pid, sum(incentive_amt) as amt, incentive_vchr_no as vchr_no, sur_title FROM custom_participant_registration 
                            INNER JOIN custom_incentive 
                                ON (custom_incentive.incentive_particpnt_id = custom_participant_registration.reg_participant_id)
							INNER JOIN custom_survey_master ON (custom_survey_master.sur_code = custom_participant_registration.reg_survey_id)
                        WHERE incentive_vchr_dt BETWEEN '".$common->date_format($prd_frm, DT_FMT, '')."' AND '".$common->date_format($prd_to, DT_FMT, '')."' AND incentive_survy_id = '".$sur_id."' AND incentive_amt != '0.00' AND incentive_vchr_no != '' GROUP BY incentive_vchr_no";
	
	if($trns_typ == 1)
	{
		$trns_typ_txt = "Reimbursement";
		
		if($reimb_typ == 1)
		{
			$query = $queryh;
			$pdf_hd = "Reimbursement Headwise Summary Report";
		}
		else
		{
			$query = $query1;
			$pdf_hd = "Reimbursement Summary Report";
		}
	}
	elseif($trns_typ == 2)
	{
		$reimb_typ = 2;
		$pdf_hd = "Incentive Summary Report";
		$trns_typ_txt = "Incentives";
		$query = $query2;
	}
	else
		$trns_typ_txt = "";
	
	//echo $query;
	
    $common->sql->query($query, SQL_ALL, SQL_ASSOC);
    $rec = $common->sql->record;
	
	if($attr == "excel")
	{
		require_once PEAR.'/PHPExcel.php';
		$styleThickBrownBorderOutline = array(
			'font'    => array(
				'bold'      => true
			)
		);
		
		$objPHPExcel = new PHPExcel();
		$objPHPExcel->setActiveSheetIndex(0);
		
		$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow(0, 1, $pdf_hd);
		$objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(18);
		$objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
		$objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$objPHPExcel->getActiveSheet()->mergeCells('A1:K1');
		$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow(0, 2, "Protocol");
		$objPHPExcel->getActiveSheet()->getStyle('A2')->getFont()->setBold(true);
		$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow(1, 2, $rec[0]['sur_title']);
		$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow(4, 2, "Report Printed On");
		$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow(5, 2, "=today()");
		$objPHPExcel->getActiveSheet()->getStyle('E2')->getFont()->setBold(true);
		$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow(0, 3, "Report Period");
		$objPHPExcel->getActiveSheet()->getStyle('A3')->getFont()->setBold(true);
		$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow(2, 3, $common->date_format($prd_frm, DT_FMT, ''));
		$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow(3, 3, $common->date_format($prd_to, DT_FMT, ''));
		
		if($reimb_typ == 1)
		{
			$j = 0;
			$row = 5;
			$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow($j, $row, "S. No.");
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($j, $row)->applyFromArray($styleThickBrownBorderOutline);
			$j++;
			$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow($j, $row, "Date");
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($j, $row)->applyFromArray($styleThickBrownBorderOutline);
			$j++;
			$exp_head = "";
			$exp_head_cnt = 0;
			for($i=0; $i<count($reimb_hds_rec);$i++)
			{
				if(($exp_head != $reimb_hds_rec[$i]['reimbrsmnt_head_name']) || $exp_head == "")
				{
					$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow($j, $row, $reimb_hds_rec[$i]['reimbrsmnt_head_name']);
					$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($j, $row)->applyFromArray($styleThickBrownBorderOutline);
					$j++;
					$exp_head_cnt++;
				}
				$exp_head = $reimb_hds_rec[$i]['reimbrsmnt_head_name'];
			}
			$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow($j, $row, "Others");
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($j, $row)->applyFromArray($styleThickBrownBorderOutline);
			$j++;
			$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow($j, $row, "Total");
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($j, $row)->applyFromArray($styleThickBrownBorderOutline);
			$j++;
			
			$sum = 0;
			$row++;
			$exp_head = "";
			for($i=0; $i<count($rec); $i++)
			{
				$j = 0;
				$rsum = 0;
				$sum += $rec[$i]['amt'];
				
				$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow($j, $row, ($i+1));
				$j++;
				$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow($j, $row, $common->date_format($rec[$i]['date'], DT_FMT, true));
				$j++;
				for($k=0; $k<count($reimb_hds_rec);$k++)
				{
					if($rec[$i]['date'] == $reimb_hds_rec[$k]['reimbrsmnt_vchr_dt'])
					{
						$rsum += $reimb_hds_rec[$k]['amt'];
						$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow($j, $row, $reimb_hds_rec[$k]['amt']);
						$j++;
					}
				}
				$rsum += $othr_hds_rec[$i]['amt'];
				$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow($j, $row, $othr_hds_rec[$i]['amt']);
				$j++;
				$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow($j, $row, $rsum);
				$row++;
			}
			$j = 3;
			$j = count($reimb_hds_rec)+2;
			$j = $exp_head_cnt+2;
			$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow($j, $row, "Total");
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($j, $row)->applyFromArray($styleThickBrownBorderOutline);
			$j++;
			$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow($j, $row, $sum);
		}
		else
		{
			$j = 0;
			$row = 5;
			$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow($j, $row, "S. No.");
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($j, $row)->applyFromArray($styleThickBrownBorderOutline);
			$j++;
			$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow($j, $row, "Date");
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($j, $row)->applyFromArray($styleThickBrownBorderOutline);
			$j++;
			$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow($j, $row, "Voucher No.");
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($j, $row)->applyFromArray($styleThickBrownBorderOutline);
			$j++;
			$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow($j, $row, "Participant ID");
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($j, $row)->applyFromArray($styleThickBrownBorderOutline);
			$j++;
			$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow($j, $row, "Amount");
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($j, $row)->applyFromArray($styleThickBrownBorderOutline);
			$j++;
			
			$sum = 0;
			$row++;
			for($i=0; $i<count($rec); $i++)
			{
				$j = 0;
				$sum += $rec[$i]['amt'];
				
				$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow($j, $row, ($i+1));
				$j++;
				$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow($j, $row, $common->date_format($rec[$i]['date'], DT_FMT, true));
				$j++;
				$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow($j, $row, $rec[$i]['vchr_no']);
				$j++;
				$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow($j, $row, $rec[$i]['pid']);
				$j++;
				$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow($j, $row, $rec[$i]['amt']);
				$row++;
			}
			$j = 3;
			$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow($j, $row, "Total");
			$j++;
			$objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow($j, $row, $sum);
		}
		// Rename worksheet
		$objPHPExcel->getActiveSheet()->setTitle($trns_typ_txt);
		$objPHPExcel->getActiveSheet()->getProtection()->setSheet(true);
		
		// Set active sheet index to the first sheet, so Excel opens this as the first sheet
		$objPHPExcel->setActiveSheetIndex(0);
		
		// Redirect output to a client’s web browser (Excel5)
		header('Content-Type: application/vnd.ms-excel');
		header('Content-Disposition: attachment;filename="'.$trns_typ_txt.'.xls"');
		header('Cache-Control: max-age=0');
		
		$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
		$objWriter->save('php://output');
	}
	elseif($attr == "print")
	{
		if($reimb_typ == 1)
		{
			echo '<br/><table border="1" cellpadding="0" cellspacing="0" style="width: 100%; line-height: 15px;" align="center">
				<thead>';
			echo '<tr>
					<td><strong>S. No.</strong></td>
					<td><strong>Date</strong></td>';
					$exp_head = "";
					for($i=0; $i<count($reimb_hds_rec);$i++)
					{
						if(($exp_head != $reimb_hds_rec[$i]['reimbrsmnt_head_name']) || $exp_head == "")
							echo '<td><strong>'.$reimb_hds_rec[$i]['reimbrsmnt_head_name'].'</strong></td>';
						$exp_head = $reimb_hds_rec[$i]['reimbrsmnt_head_name'];
					}
					echo '<td><strong>Others</strong></td>';
					echo '<td><strong>Total</strong></td>';
			echo '</tr>
				</thead>
				<tbody>';
				$sum = 0;
				for($i=0; $i<count($rec); $i++)
				{
					echo '<tr>
							<td>'.($i+1).'.</td>
							<td>'.$common->date_format($rec[$i]['date'], DT_FMT, true).'</td>';
							$rsum = 0;
							for($j=0; $j<count($reimb_hds_rec);$j++)
							{
								if($rec[$i]['date'] == $reimb_hds_rec[$j]['reimbrsmnt_vchr_dt'])
								{
									$rsum += $reimb_hds_rec[$j]['amt'];
									echo '<td style="text-align:right">'.number_format($reimb_hds_rec[$j]['amt'], 2).'</td>';
								}
							}
							$rsum += $othr_hds_rec[$i]['amt'];
							echo '<td style="text-align:right">'.number_format($othr_hds_rec[$i]['amt'], 2).'</td>';
							echo '<td style="text-align:right">'.number_format($rsum, 2).'</td>';
					echo '</tr>';
					$sum += $rec[$i]['amt'];
				}
				echo '</tbody>
						<tfoot>
							<tr>
								<td>&nbsp;&nbsp;&nbsp;</td>';
								$exp_head = "";
								for($j=0; $j<=count($reimb_hds_rec);$j++)
								{
									if(($exp_head != $reimb_hds_rec[$j]['reimbrsmnt_head_name']) || $exp_head == "")
										echo '<td>&nbsp;&nbsp;&nbsp;</td>';
									$exp_head = $reimb_hds_rec[$j]['reimbrsmnt_head_name'];
								}
								echo '<td style="text-align:right">Total&nbsp;&nbsp;</td>
								<td style="text-align:right">'.number_format($sum, 2).'</td>
							</tr>
						</tfoot>';
			echo '
				</table>';
		}
		else
		{
			echo '<br/><table border="1" cellpadding="0" cellspacing="0" style="width: 100%; line-height: 15px;" align="center">
				<thead>';
			echo '<tr>
					<td><strong>S. No.</strong></td>
					<td><strong>Date</strong></td>
					<td><strong>Voucher No.</strong></td>
					<td><strong>Participant ID</strong></td>
					<td><strong>Amount</strong></td>';
			echo '</tr>
				</thead>
				<tbody>';
				$sum = 0;
				for($i=0; $i<count($rec); $i++)
				{
					$sum += $rec[$i]['amt'];
					echo '<tr>
							<td>'.($i+1).'.</td>
							<td>'.$common->date_format($rec[$i]['date'], DT_FMT, true).'</td>
							<td>'.$rec[$i]['vchr_no'].'</td>
							<td>'.$rec[$i]['pid'].'</td>
							<td style="text-align:right">'.number_format($rec[$i]['amt'], 2).'</td>';
					echo '</tr>';
				}
				echo '</tbody>
						<tfoot>
							<tr>
								<td>&nbsp;&nbsp;&nbsp;</td>
								<td>&nbsp;&nbsp;&nbsp;</td>
								<td>&nbsp;&nbsp;&nbsp;</td>
								<td style="text-align:right">Total&nbsp;&nbsp;</td>
								<td style="text-align:right">'.number_format($sum, 2).'</td>
							</tr>
						</tfoot>';
			echo '
				</table>';
		}
	}
	elseif($attr == "pdf")
	{
		$disp_header = '
			<br/><br/>
			<table border="0" cellpadding="0" cellspacing="0" style="width: 100%; line-height: 10px;">
				<tr>
					<th align="center"><font size="13"><strong>'.$pdf_hd.'</strong></font></th>
				</tr>
				<tr>
					<td><font size="10"><strong> Survey Title : </strong> '.$rec[0]['sur_title'].'</font></td>
				</tr>
				<tr>
					<td><font size="10"><strong> Report Period From : </strong> '.$prd_frm.'  <strong>To :</strong> '.$prd_to.'</font></td>
				</tr>
			</table>
			<br><br>';
		if($reimb_typ == 1)
		{
			$disp_table = '<table border="1" cellpadding="0" cellspacing="0" style="width: 100%; line-height: 10px;" align="center">
				<thead>';
			$disp_table .= '<tr>
					<td><strong>S. No.</strong></td>
					<td><strong>Date</strong></td>';
					$exp_head = "";
					for($i=0; $i<count($reimb_hds_rec);$i++)
					{
						if(($exp_head != $reimb_hds_rec[$i]['reimbrsmnt_head_name']) || $exp_head == "")
							$disp_table .= '<td><strong>'.$reimb_hds_rec[$i]['reimbrsmnt_head_name'].'</strong></td>';
						$exp_head = $reimb_hds_rec[$i]['reimbrsmnt_head_name'];
					}
					$disp_table .= '<td><strong>Others</strong></td>';
					$disp_table .= '<td><strong>Total</strong></td>';
			$disp_table .= '</tr>
				</thead>
				<tbody>';
				$sum = 0;
				for($i=0; $i<count($rec); $i++)
				{
					$disp_table .= '<tr>
							<td>'.($i+1).'.</td>
							<td>'.$common->date_format($rec[$i]['date'], DT_FMT, true).'</td>';
							$rsum = 0;
							for($j=0; $j<count($reimb_hds_rec);$j++)
							{
								if($rec[$i]['date'] == $reimb_hds_rec[$j]['reimbrsmnt_vchr_dt'])
								{
									$rsum += $reimb_hds_rec[$j]['amt'];
									$disp_table .= '<td style="text-align:right">'.$reimb_hds_rec[$j]['amt'].'  </td>';
									$exp_head = $reimb_hds_rec[$j]['reimbrsmnt_head_name'];
								}
							}
							$rsum += $othr_hds_rec[$i]['amt'];
							$disp_table .= '<td style="text-align:right">'.$othr_hds_rec[$i]['amt'].'  </td>';
							$disp_table .= '<td style="text-align:right">'.$rsum.'  </td>';
					$disp_table .= '</tr>';
					$sum += $rec[$i]['amt'];
				}
				$disp_table .= '</tbody>
						<tfoot>
							<tr>
								<td>&nbsp;&nbsp;&nbsp;</td>';
								$exp_head = "";
								for($j=0; $j<=count($reimb_hds_rec);$j++)
								{
									if(($exp_head != $reimb_hds_rec[$j]['reimbrsmnt_head_name']) || $exp_head == "")
									{
										$disp_table .= '<td>&nbsp;&nbsp;&nbsp;</td>';
										$exp_head = $reimb_hds_rec[$j]['reimbrsmnt_head_name'];
									}
								}
								$disp_table .= '<td style="text-align:right"><strong>Total</strong>&nbsp;&nbsp;</td>
								<td style="text-align:right">'.$sum.'  </td>
							</tr>
						</tfoot>';
			$disp_table .= '
				</table>';
		}
		else
		{
			$disp_table .= '<table border="1" cellpadding="0" cellspacing="0" style="width: 100%; line-height: 10px;" align="center">
				<thead>';
			$disp_table .= '<tr>
					<td width="20%"><strong>S. No.</strong></td>
					<td width="20%"><strong>Date</strong></td>
					<td width="20%"><strong>Voucher No.</strong></td>
					<td width="20%"><strong>Participant ID</strong></td>
					<td width="20%"><strong>Amount</strong></td>';
			$disp_table .= '</tr>
				</thead>
				<tbody>';
				$sum = 0;
				for($i=0; $i<count($rec); $i++)
				{
					$sum += $rec[$i]['amt'];
					$disp_table .= '<tr>
							<td>'.($i+1).'.</td>
							<td>'.$common->date_format($rec[$i]['date'], DT_FMT, true).'</td>
							<td>'.$rec[$i]['vchr_no'].'</td>
							<td>'.$rec[$i]['pid'].'</td>
							<td style="text-align:right">'.number_format($rec[$i]['amt'], 2).'&nbsp;  </td>';
					$disp_table .= '</tr>';
				}
				$disp_table .= '</tbody>
						<tfoot>
							<tr>
								<td>&nbsp;&nbsp;&nbsp;</td>
								<td>&nbsp;&nbsp;&nbsp;</td>
								<td>&nbsp;&nbsp;&nbsp;</td>
								<td style="text-align:right">Total&nbsp;&nbsp;</td>
								<td style="text-align:right; padding-right: 5px;">'.number_format($sum, 2).'  </td>
							</tr>
						</tfoot>';
			$disp_table .= '
				</table>';
		}
		
		$query = "SELECT * FROM custom_settings";
		$common->sql->query($query, SQL_ALL, SQL_ASSOC);
		$stngs_rec = $common->sql->record[0];
		
		$stngs_org_name = $stngs_rec['stngs_org_name'];
		$stngs_org_addrs = $stngs_rec['stngs_org_addrs'];
		$stngs_org_phone = $stngs_rec['stngs_org_phone'];
		$stngs_org_mail = $stngs_rec['stngs_org_mail'];
		$stngs_org_website = $stngs_rec['stngs_org_website'];
		
		$pdf = '';
		$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
		
		// set document information
		$pdf->SetCreator(PDF_CREATOR);
		$pdf->SetAuthor('YRG Care');
		$pdf->SetTitle('Expense Report');
		$pdf->SetSubject('TCPDF Tutorial');
		$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
		
		// set default header data
		$pdf->SetHeaderData(PDF_HEADER_LOGO, '30', $stngs_org_name, "<font size=\"9\">".$stngs_org_addrs."<br/><b>T : </b>".$stngs_org_phone."<br/><b>E : </b>".$stngs_org_mail."  <b>  Web : </b>".$stngs_org_website."</font>");
		// $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 001', PDF_HEADER_STRING);
		
		// set header and footer fonts
		/*$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', 20, 'L', true));
		$pdf->setHeaderStringFont(Array(PDF_FONT_NAME_MAIN, '', 10, 'L', true));
		$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));*/
		
		$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', 12, '', true));
		$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
		$pdf->setLanguageArray($l);
		
		// ---------------------------------------------------------
		
		// set font
		$pdf->SetFont('dejavusans', '', 8);
		
		// add a page
		$pdf->AddPage('L');
		
		$dt_fmt = str_replace("mm", "m", DT_FMT);
		$dt_fmt = str_replace("dd", "d", $dt_fmt);
		$dt_fmt = str_replace("yyyy", "Y", $dt_fmt);
		$dt = date($dt_fmt);
		
		$title_rght = "<br/><br/><br/><font size=\"9\"><b>Printed from :</b> ".APP_NAME."<br/>
		<b>Printed by : </b>".USRNME."<br/>
		<b>Report Printed on : </b>".$dt."</font>";
		
		// Print text using writeHTMLCell()
		$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $disp_header, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
		$pdf->writeHTML($disp_table, true, false, true, false, '');
		$pdf->MultiCell(0, 10, $title_rght, 0, 'R', 0, 1, '', 5, false, 0, true, true, 0, 'T', false);
		$pdf->lastPage();
		$pdf->Output($trns_typ_txt.".pdf", "D");
	}
	exit;
?>