<?php
session_start();
require_once "main.php";
//ini_set('display_errors', 1);
//error_reporting(E_ALL);
require_once('tcpdf/config/lang/eng.php');
require_once('tcpdf/tcpdf.php');
Logger::configure('log4php.xml');
$log = Logger::getLogger('printbatch');
global $db;
$_SESSION['batch'] = $_GET['id'];
if ($_GET['submitType']=='printbatch') {
$result = bill_get_customers($_SESSION['comnum']);
//print_r($result);
ob_end_clean();
$log->info($_GET['submitType'].' - user = '.$_SESSION['user'].' - '.$_SESSION['comnum'].' = '.$_GET['id']);
$pdf = new TCPDF("P", "pt", "USLETTER", true, 'UTF-8', false);
$pdf->SetAutoPageBreak("true");
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('ProTekBill');
$pdf->SetTitle('Account Report');
$pdf->SetSubject($_GET['id']);
$pdf->SetKeywords('ProTekBill');
$style = array(
	'position' => '',
	'align' => 'L',
	'stretch' => false,
	'fitwidth' => false,
	'cellfitalign' => '',
	'border' => true,
	'hpadding' => 'auto',
	'vpadding' => 'auto',
	'fgcolor' => array(0,0,0),
	'bgcolor' => false, //array(255,255,255),
	'text' => false,
	'font' => 'helvetica',
	'fontsize' => 10,
	'stretchtext' => 4
);
$pdf->setFontSubsetting(true);
$pdf->SetFont('helvetica', '', 6);
$resolution= array(792,612);//array(792, 612);
$pdf->AddPage("P", $resolution);


$rep1 = '<center><h2>Meter Reading Worksheet for batch # : '.testx($_SESSION['batch']).'</h2></center>
    <table cellpadding="3" cellspacing="1" border="1" style="text-align:center;">
    <tr>
        <td>Account</td>
        <td>Name</td>
        <td>Meter Address</td>
        <td>2M Reading</td>
        <td>Last Reading</td>
        <td>Reading</td>
    </tr>';
$rep2 = '';
for ($i=0;$i<count($result);$i++) {
$rep2 = $rep2 .'
    <tr>
       <td>'.testx($result[$i]['account']).'</td>
       <td>'.testx($result[$i]['name']).'</td>
       <td>'.testx($result[$i]['maddr']).'</td>
       <td>'.testx($result[$i]['lmread']).'</td>
       <td>'.testx($result[$i]['lread']).'</td>
       <td></td>
    </tr>';
}
$rep3=$rep1.$rep2.'</table>';
        $pdf->SetFont('helvetica', '', 10);
        $pdf->writeHTML($rep3, true, false, true, false, '');
        //$pdf->writeHTML($rep2, true, false, true, false, '');
        //$pdf->writeHTMLcell(0,0,5,5,$rep1, false, true, false, false, false, '');//address
        $pdf->lastPage();
       
$pdf->Output('MeterReadWKSHT.pdf', 'I');
} else if ($_GET['submitType']=='reread') {
$result = bill_get_reread($_SESSION['comnum'], $_SESSION['batch']);
//print_r($result);
ob_end_clean();
$log->info($_GET['submitType'].' - user = '.$_SESSION['user'].' - '.$_SESSION['comnum'].' = '.$_GET['id']);
$pdf = new TCPDF("P", "pt", "USLETTER", true, 'UTF-8', false);
$pdf->SetAutoPageBreak("true");
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('ProTekBill');
$pdf->SetTitle('Account Report');
$pdf->SetSubject($_GET['id']);
$pdf->SetKeywords('ProTekBill');
$style = array(
	'position' => '',
	'align' => 'L',
	'stretch' => false,
	'fitwidth' => false,
	'cellfitalign' => '',
	'border' => true,
	'hpadding' => 'auto',
	'vpadding' => 'auto',
	'fgcolor' => array(0,0,0),
	'bgcolor' => false, //array(255,255,255),
	'text' => false,
	'font' => 'helvetica',
	'fontsize' => 10,
	'stretchtext' => 4
);
$pdf->setFontSubsetting(true);
$pdf->SetFont('helvetica', '', 6);
$resolution= array(792,612);//array(792, 612);
$pdf->AddPage("P", $resolution);


$rep1 = '<center><h2>ReRead Worksheet for batch # : '.testx($_SESSION['batch']).'</h2></center>
    <table cellpadding="3" cellspacing="1" border="1" style="text-align:center;">
    <tr>
        <td>Account</td>
        <td>Name</td>
        <td>Meter Address</td>
        <td>2M Reading</td>
        <td>Last Reading</td>
        <td>Reading</td>
    </tr>';
$rep2 = '';
for ($i=0;$i<count($result);$i++) {
$rep2 = $rep2 .'
    <tr>
       <td>'.testx($result[$i]['account']).'</td>
       <td>'.testx($result[$i]['name']).'</td>
       <td>'.testx($result[$i]['maddr']).'</td>
       <td>'.testx($result[$i]['lmread']).'</td>
       <td>'.testx($result[$i]['lread']).'</td>
       <td></td>
    </tr>';
}
$rep3=$rep1.$rep2.'</table>';
        $pdf->SetFont('helvetica', '', 10);
        $pdf->writeHTML($rep3, true, false, true, false, '');
        //$pdf->writeHTML($rep2, true, false, true, false, '');
        //$pdf->writeHTMLcell(0,0,5,5,$rep1, false, true, false, false, false, '');//address
        $pdf->lastPage();
       
$pdf->Output('MeterReadWKSHT.pdf', 'I');    
}
?>
