<?php
	$sql = "<HTML>";
	$sql.= "<head>";
	$sql.= "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=iso-8859-1\">";
	$sql.= "<link rel=\"stylesheet\" href=\"css/style_print.css\" type=\"text/css\" />";
	$sql.= "</head>";
	$sql.= "<body>";
	$sql.= "<table class=\"tab_print_data\" align=\"center\" >";
	$sql.= "<thead>";
	$sql.= "<tr>";
	$sql.= "<th width=\"35\">FECHA</th>";
	$sql.= "<th width=\"90\">TDOC</th>";
	$sql.= "<th width=\"40\">NRO DOCUMENTO</th>";
	$sql.= "<th>DESCRIPCION</th>";
	$sql.= "<th width=\"25\">CAN. DOC</th>";
	$sql.= "<th width=\"25\">CAN. UNI</th>";
	$sql.= "<th width=\"25\">VENTA</th>";
	$sql.= "<th width=\"25\">PAGOS</th>";
	$sql.= "<th width=\"35\">SALDO</th>";
	$sql.= "</tr>";
	$sql.= "</thead>";
	$sql.= "<tbody>";
	$varSaldo=0;
	while($fila = $obj->FetchArray($rs))	{
		$varSaldo = $varSaldo + $fila["VENTA"] - $fila["PAGOS"];
		$sql.= "<tr>";
		$sql.= "<td align=\"center\">&nbsp;$fila[0]</td>";
		$sql.= "<td>&nbsp;$fila[1]</td>";
		$sql.= "<td align=\"center\">&nbsp;$fila[2]</td>";
		$sql.= "<td>&nbsp;$fila[3]</td>";
		$sql.= "<td align=\"right\">&nbsp;";
		if(!is_null($fila["CAN_DOC"])) $sql.= number_format($fila["CAN_DOC"], 2,'.',',');
		$sql.= "</td>";
		$sql.= "<td  align=\"right\">&nbsp;";
		if(!is_null($fila["CAN_UNI"])) $sql.= number_format($fila["CAN_UNI"], 2,'.',',');
		$sql.= "</td>";
		$sql.= "<td  align=\"right\">&nbsp;";
		if(!is_null($fila["VENTA"])) $sql.= number_format($fila["VENTA"], 2,'.',',');
		$sql.= "</td>";
		$sql.= "<td  align=\"right\">&nbsp;";
		if(!is_null($fila["PAGOS"])) $sql.= number_format($fila["PAGOS"], 2,'.',',');
		$sql.= "</td>";
		$sql.= "<td  align=\"right\"><b>".number_format($varSaldo, 2,'.',',')."</b></td>";
		$sql.= "</tr>";
		}
	$sql.= "</tbody>";
	$sql.= "</table>";	
	$sql.='<script type="text/php">
	if ( isset($pdf) ) {

  $font = Font_Metrics::get_font("verdana");;
  $size = 10;
  $color = array(0,0,0);
  $text_height = Font_Metrics::get_font_height($font, $size);

  $foot = $pdf->open_object();
  
  $w = $pdf->get_width();
  $h = $pdf->get_height();

  // Draw a line along the bottom
  $y = $h - 2 * $text_height - 24;
  $pdf->line(16, $y, $w - 16, $y, $color, 1);

  $y += $text_height;

  $text = "Job: 132-003";
  $pdf->text(16, $y, $text, $font, $size, $color);

  $pdf->close_object();
  $pdf->add_object($foot, "all");

  global $initials;
  $initials = $pdf->open_object();
  
  // Add an initals box
  $text = "Initials:";
  $width = Font_Metrics::get_text_width($text, $font, $size);
  $pdf->text($w - 16 - $width - 38, $y, $text, $font, $size, $color);
  $pdf->rectangle($w - 16 - 36, $y - 2, 36, $text_height + 4, array(0.5,0.5,0.5), 0.5);
    

  $pdf->close_object();
  $pdf->add_object($initials);
 
  // Mark the document as a duplicate
  /*
  $pdf->text(110, $h - 240, "DUPLICADO", Font_Metrics::get_font("verdana", "bold"),
             110, array(0.95, 0.95, 0.95), 0, -52);

  */
  

  // Center the text
  $text = "Pagina {PAGE_NUM} de {PAGE_COUNT}";  
  $width = Font_Metrics::get_text_width("Page 1 of 2", $font, $size);
  $pdf->page_text($w / 2 - $width / 2, $y, $text, $font, $size, $color);
  
}
</script>';
	$sql.= "</body>";
?>