Foros del Web » Programando para Internet » PHP »

ayuda con pasar a pdf

Estas en el tema de ayuda con pasar a pdf en el foro de PHP en Foros del Web. necesito mucha ayuda, es que baje del hosting de el jefe este pequeño sistema, pero al momento de verlo en el pdf ya no se ...
  #1 (permalink)  
Antiguo 23/02/2009, 09:47
 
Fecha de Ingreso: septiembre-2008
Mensajes: 58
Antigüedad: 15 años, 6 meses
Puntos: 0
ayuda con pasar a pdf

necesito mucha ayuda, es que baje del hosting de el jefe este pequeño sistema, pero al momento de verlo en el pdf ya no se ve bien, se corre la fecha y tambien
la cantidad, unidad, descripcion, etc, salen juntitas, y no salen separadas como en el hosting, me podrian decir porque ha ocurrido esto?
me arrojaba algunos errores, pero era que solo tenia que redirigir algunas cosas
aqui esta el codigo

<?php
include_once('config.php');
include_once('include/cantidadTexto.class.php');
include_once('include/myMySQL.class.php');
include_once( $GLOBAL_Path_local . $GLOBAL_MySQL_conector );
$MySQL = new MySQL( $GLOBAL_MySQL_host, $GLOBAL_MySQL_usr, $GLOBAL_MySQL_pwd, $GLOBAL_MySQL_db );
$cantidadLetra = new EnLetras();

$id_venta_activa = 0;
$b_imprime_factura = $_GET["b_imprime_factura"]?$_GET["b_imprime_factura"]:0;

$vc_select_cliente = $_POST["ctrl_select_cliente"]?$_POST["ctrl_select_cliente"]:0;

// Si recibimos valores en estas variables por POST, guardar en BD y setearlas a 0 inmediatamente
$in_carga_cantidad = $_POST["in_carga_cantidad"]?$_POST["in_carga_cantidad"]:0;
$in_carga_unidad = $_POST["in_carga_unidad"]?$_POST["in_carga_unidad"]:0;
$in_carga_descripcion = $_POST["in_carga_descripcion"]?$_POST["in_carga_descripcion"]:'';
$in_carga_precio_unitario = $_POST["in_carga_precio_unitario"]?$_POST["in_carga_precio_unitario"]:0;
$in_carga_importe = $_POST["in_carga_importe"]?$_POST["in_carga_importe"]:0;

$in_carga_dia = $_POST["in_carga_dia"]?$_POST["in_carga_dia"]:date('d');
$in_carga_mes = $_POST["in_carga_mes"]?$_POST["in_carga_mes"]:date('m');
$in_carga_anio = $_POST["in_carga_anio"]?$_POST["in_carga_anio"]:date('Y');

$arr_clientes = array();
$arr_venta = array();
$arr_venta_articulo = array();
$values = array();
$v = array();

$arr_ventas_pdf = array();
$arr_clientes_pdf = array();
$dec_importe_pdf = 0;

$vc_nombre_cliente = '';
$vc_domicilio = '';
$vc_ciudad = '';
$vc_telefono = '';
$vc_rfc = '';

$id_last_insert_id = 0;

$dec_precio_subtotal = 0;
$dec_precio_iva = 0;
$dec_precio_total = 0;

$id_coordenada = 0;


function textJustify($dec_num, $int_spaces) {
if ( strlen(number_format($dec_num, 2, ".", ",")) <= $int_spaces ) {
return str_repeat(" ", $int_spaces - strlen(number_format($dec_num, 2, ".", ",")) ) . number_format($dec_num, 2, ".", ",");
} else { return strlen(number_format($dec_num, 2, ".", ",")) ; }
}
function intJustify($dec_num, $int_spaces) {
if ( strlen(trim($dec_num)) <= $int_spaces ) {
return str_repeat(" ", $int_spaces - strlen(trim($dec_num)) ) . trim($dec_num);
} else { return strlen(trim($dec_num)); }
}
function rightTextJustify ( $txt_texto, $int_spaces ) {
$txt_texto = substr( $txt_texto, 0, $int_spaces);
return $txt_texto . str_repeat( " ", $int_spaces - strlen($txt_texto) );
}

$vc_query = "select id_venta, id_cliente, b_status from tb_venta order by id_venta desc limit 1";
$MySQL->query( $GLOBAL_MySQL_host, $vc_query, 0 );
$arr_venta = $MySQL->arr;

// Impide cambiar de cliente si la venta está activa
if ( isset( $arr_venta ) && $arr_venta[0]["b_status"] == -1 ) {
//echo 'pasaste por aqui';
$id_venta_activa = $arr_venta[0]["id_venta"]; $vc_select_cliente = $arr_venta[0]["id_cliente"];
}

// Si no recibimos los campos de POST en 0 entonces guardamos los resultados y seteamos a 0
if ( $in_carga_cantidad != 0 && $in_carga_unidad != 0 && $in_carga_descripcion != '' && $in_carga_precio_unitario > 0 && $in_carga_importe > 0 ) {
// solo agregamos reginstros a la venta
if ( $id_venta_activa > 0 && $vc_select_cliente > 0 ) {
$vc_query = " insert into tb_venta_articulo (id_venta, int_cantidad, int_unidad, vc_descripcion, dec_precio_unitario, dec_precio_importe, dtm_fecha_venta_articulo)
values ('$id_venta_activa', '$in_carga_cantidad', '$in_carga_unidad', '$in_carga_descripcion', '$in_carga_precio_unitario', '$in_carga_importe', NOW())
";
$MySQL->query( $GLOBAL_MySQL_host, $vc_query, 0 );

} else // si no, iniciamos una venta
{
if ( $vc_select_cliente > 0 ) {
$vc_query = "insert into tb_venta ( id_cliente, dtm_fecha_venta, b_status ) values ( '$vc_select_cliente', now(), '-1' )";
$MySQL->query( $GLOBAL_MySQL_host, $vc_query, 0 );
$id_last_insert_id = $MySQL->query( $GLOBAL_MySQL_host, "select last_insert_id() ", 1 );
$vc_query = " insert into tb_venta_articulo
(id_venta, int_cantidad, int_unidad, vc_descripcion, dec_precio_unitario, dec_precio_importe, dtm_fecha_venta_articulo)
values ('$id_last_insert_id', '$in_carga_cantidad', '$in_carga_unidad', '$in_carga_descripcion', '$in_carga_precio_unitario', '$in_carga_importe', NOW())";
$MySQL->query( $GLOBAL_MySQL_host, $vc_query, 0 );
$id_venta_activa = $id_last_insert_id;
}
}


}


$vc_query = " select id_cliente, concat( id_cliente, ' - ', vc_cliente ) as 'cliente',
vc_cliente, vc_domicilio, vc_ciudad, vc_telefono, vc_rfc
from tb_cliente where b_status = 1 ";
$MySQL->query( $GLOBAL_MySQL_host, $vc_query, 0 );

$arr_clientes = $MySQL->arr;

if ($vc_select_cliente > 0 && isset($arr_clientes) ) {
$vc_nombre_cliente=$arr_clientes[$vc_select_cliente-1]["vc_cliente"];
$vc_domicilio=$arr_clientes[$vc_select_cliente-1]["vc_domicilio"];
$vc_ciudad=$arr_clientes[$vc_select_cliente-1]["vc_ciudad"];
$vc_telefono=$arr_clientes[$vc_select_cliente-1]["vc_telefono"];
$vc_rfc=$arr_clientes[$vc_select_cliente-1]["vc_rfc"];
}

// imprime factura
if ( $b_imprime_factura == 1 && $vc_select_cliente > 0 && $id_venta_activa > 0 ) {
include_once('include/pdfclass/class.ezpdf.php');
$pdf = new Cezpdf();
$pdf->selectFont('pdfclass/fonts/Helvetica.afm');
$pdf->addJpegFromFile('facturacarpi.jpg',25,50,550);

$vc_query = "select * from tb_cliente where id_cliente = '$vc_select_cliente' limit 1";
$MySQL->query( $GLOBAL_MySQL_host, $vc_query, 0 );
$arr_clientes_pdf = $MySQL->arr[0];

$vc_query = "select * from tb_venta_articulo where id_venta = '$id_venta_activa'";
$MySQL->query( $GLOBAL_MySQL_host, $vc_query, 0 );
$arr_ventas_pdf = $MySQL->arr;

$dec_importe_pdf = $MySQL->query( $GLOBAL_MySQL_host, " select sum(dec_precio_importe) from tb_venta_articulo where id_venta = '$id_venta_activa' ", 1 );
$dec_importe_pdf = $dec_importe_pdf?$dec_importe_pdf:0;

$MySQL->query( $GLOBAL_MySQL_host, " update tb_venta set b_status = '0', dec_precio_total = '$dec_importe_pdf' * 1.15 where id_venta = '$id_venta_activa' limit 1 ", 0 );

// --------- IMPRESION DE LA FACTURA --------- IMPRESION DE LA FACTURA --------- IMPRESION DE LA FACTURA --------- IMPRESION DE LA FACTURA ---------

$pdf->selectFont('include/pdfclass/Courier.afm');
//$pdf->addJpegFromFile('facturacarpi.jpg',25,50,550);
$pdf->ezSetY(667);
$pdf->ezText(
str_repeat( " ", 12 ) .
rightTextJustify( $arr_clientes_pdf['vc_cliente'], 50 ) .
str_repeat( " ", 6 ) .
$in_carga_dia .
str_repeat( " ", 5 ) .
$in_carga_mes .
str_repeat( " ", 5 ) .
$in_carga_anio
);
$pdf->ezSetY(651);
$pdf->ezText( str_repeat( " ", 12 ) . rightTextJustify( $arr_clientes_pdf['vc_domicilio'], 50 ) );
$pdf->ezSetY(632);
$pdf->ezText( str_repeat( " ", 12 ) . rightTextJustify( $arr_clientes_pdf['vc_ciudad'], 50 ) );s
$pdf->ezSetY(614);
$pdf->ezText(
str_repeat( " ", 12 ) . rightTextJustify( $arr_clientes_pdf['vc_telefono'], 15 ) .
str_repeat( " ", 1 ) . rightTextJustify( $arr_clientes_pdf['vc_rfc'], 16 ) .
str_repeat( " ", 8 ) . intJustify( $arr_clientes_pdf['id_cliente'], 6 )
);

if ( isset ( $arr_ventas_pdf ) ) {
$id_coordenada = 570;
foreach ( $arr_ventas_pdf as $v ) {
$pdf->ezSetY($id_coordenada);
$pdf->ezText( str_repeat( " ", 3 ) .
intJustify( $v["int_cantidad"], 8 ) .
str_repeat( " ", 1 ) .
intJustify( $v["int_unidad"], 6 ) .
str_repeat( " ", 2 ) .
rightTextJustify( $v["vc_descripcion"], 43 ) .
textJustify( $v['dec_precio_unitario'], 11 ) .
str_repeat( " ", 2 ) .
textJustify( $v['dec_precio_importe'], 11 ) );
$id_coordenada = $id_coordenada - 20;
}
}

$pdf->ezSetY(264);
$pdf->ezText( str_repeat( " ", 162 ) . textJustify( $dec_importe_pdf, 14 ) );
$pdf->ezSetY(238);
$pdf->ezText( str_repeat( " ", 162 ) . textJustify( $dec_importe_pdf * 0.15, 14 ) );
$pdf->ezSetY(212);
$pdf->ezText( str_repeat( " ", 162 ) . textJustify( $dec_importe_pdf * 1.15, 14 ) );

// orp, dividimos el texto del importa para imprimirlo en el espacio de la factura
list($vc_pesos, $vc_centavos) = explode(' Pesos', $cantidadLetra->ValorEnLetras($dec_importe_pdf * 1.15," Pesos"));
$vc_pesos.=' Pesos'; $vc_centavos=trim($vc_centavos);

$pdf->ezSetY(245);
$pdf->ezText( str_repeat( " ", 18 ) . $vc_pesos);
$pdf->ezSetY(230);
$pdf->ezText( str_repeat( " ", 18 ) . $vc_centavos);
$pdf->ezStream();

// --------- IMPRESION DE LA FACTURA --------- IMPRESION DE LA FACTURA --------- IMPRESION DE LA FACTURA --------- IMPRESION DE LA FACTURA ---------

die;
}

?>
  #2 (permalink)  
Antiguo 23/02/2009, 09:55
 
Fecha de Ingreso: septiembre-2008
Mensajes: 58
Antigüedad: 15 años, 6 meses
Puntos: 0
Respuesta: ayuda con pasar a pdf

y aka esta el html
<html>
<head>
<title></title>
</head>
<body topmargin="1" style="text-align: center">
<form method="POST" action="factura.php">
<table border="0" width="740" height="160" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF" id="table3">
<tr>
<td height="15" width="740" align="center" colspan="2">
<img border="0" src="images/line_03.jpg" width="740" height="15"></td>
</tr>
<tr>
<td height="40" width="740" align="left"><b>
<font face="Arial" size="2" color="#333333">&nbsp;No. Cliente:
<?php
if ( $id_venta_activa == 0 ) {
echo ' <select size="1" name="ctrl_select_cliente">
<option value="0">-- Seleccione al Cliente --</option>';
if (isset($arr_clientes)) {
foreach( $arr_clientes as $values ){
echo '<option value="'.$values["id_cliente"].'">'.$values["cliente"].'</option>';
}
}
echo '</select>';
} else { echo '<font face="Arial" size="2" color="#FF0000">'.$vc_select_cliente.'</font>';}
?>
</font></b></td>
<td height="40" width="740" align="left"><b>
<font face="Arial" size="2" color="#333333">&nbsp;Nombre del Cliente: <?php echo $vc_nombre_cliente; ?></font></b></td>
</tr>
<tr>
<td height="40" width="740" align="left"><b>
<font face="Arial" size="2" color="#333333">&nbsp;Domicilio: <?php echo $vc_domicilio; ?></font></b></td>
<td height="40" width="740" align="left"><b>
<font face="Arial" size="2" color="#333333">&nbsp;Ciudad: <?php echo $vc_ciudad; ?></font></b></td>
</tr>
<tr>
<td height="40" width="740" align="left"><b>
<font face="Arial" size="2" color="#333333">&nbsp;Telefono: <?php echo $vc_telefono; ?></font></b></td>
<td height="40" width="740" align="left"><b>
<font face="Arial" size="2" color="#333333">&nbsp;R.F.C: <?php echo $vc_rfc; ?></font></b></td>
</tr>
<tr>
<td height="15" width="740" align="left" colspan="2">
<img border="0" src="images/line_03.jpg" width="740" height="15"></td>
</tr>
<tr>
<td height="15" width="740" align="left" colspan="2">
<input type="submit" value="Cargar Cliente" name="B1" style="float: right"></td>
</tr>
</table>
</form>
<form method="POST" action="factura.php">
<table border="0" width="740" height="15" cellspacing="0" cellpadding="0" id="table21">
<tr>
<td height="15" width="320" align="left"><b>
<font face="Arial" size="2" color="#333333">N&uacute;mero de Venta: </font>
<font face="Arial" size="2" color="#FF0000"><?php echo $id_venta_activa>0?$id_venta_activa:'No Hay venta Activa.'; ?></b></font>
</td>
</table>
<table border="0" width="740" height="35" cellspacing="0" cellpadding="0" background="images/line_04.jpg" id="table16">
<tr>
<td height="35" width="148" align="center"><b>
<font face="Arial" size="2" color="#FFFFFF">Cantidad</font></b></td>
<td height="35" width="148" align="center"><b>
<font face="Arial" size="2" color="#FFFFFF">Unidad</font></b></td>
<td height="35" width="148" align="center"><b>
<font face="Arial" size="2" color="#FFFFFF">Descripci&oacute;n</font></b></td>
<td height="35" width="148" align="center"><b>
<font face="Arial" size="2" color="#FFFFFF">P. Unitario</font></b></td>
<td height="35" width="148" align="center"><b>
<font face="Arial" size="2" color="#FFFFFF">Importe</font></b></td>
</tr>
<tr>
<td height="35" width="148" align="center">
<input type="text" name="in_carga_cantidad" size="18"></td>
<td height="35" width="148" align="center">
<input type="text" name="in_carga_unidad" size="18"></td>
<td height="35" width="148" align="center">
<input type="text" name="in_carga_descripcion" size="18"></td>
<td height="35" width="148" align="center">
<input type="text" name="in_carga_precio_unitario" size="18"></td>
<td height="35" width="148" align="center">
<input type="text" name="in_carga_importe" size="18"></td>
</tr>
</table>
<table border="0" width="740" height="35" cellspacing="0" cellpadding="0" id="table17">
<tr>
<!-- DIA, MES Y AÑO -->
<td height="17" width="370" align="center">
<p align="left"><b>
<font face="Arial" size="2" color="#333333">D&iacute;a: </font></b>
<input name="in_carga_dia" size="2" value=<?php echo $in_carga_dia; ?>><b>
<font face="Arial" size="2" color="#333333">Mes: </font></b>
<input name="in_carga_mes" size="12" value=<?php echo $in_carga_mes; ?>><b>
<font face="Arial" size="2" color="#333333">A&ntilde;o: </font></b>
<input name="in_carga_anio" size="4" value=<?php echo $in_carga_anio; ?>>
<!-- PASAMOS LA VARIABLE DE NUMERO DE CLIENTE POR POST -->
<input type="hidden" name="ctrl_select_cliente" value=<?php echo $vc_select_cliente; ?> />
</td>
<td height="17" width="370" align="center">
<input type="submit" value="Registrar Venta" name="registrar_venta" style="float: right">
</td>
</tr>
</table>
</form>
<table border="0" width="740" height="35" cellspacing="0" cellpadding="0" id="table12">
<tr>
<td height="25" width="740" align="center" valign="top">
<p align="left">
<img border="0" src="images/line_03.jpg" width="740" height="15"></td>
</tr>
</table>
<table border="0" width="740" height="35" cellspacing="0" cellpadding="0" background="images/line_04.jpg" id="table13">
<tr>
<td height="35" width="148" align="center"><b>
<font face="Arial" size="2" color="#FFFFFF">Cantidad</font></b></td>
<td height="35" width="148" align="center"><b>
<font face="Arial" size="2" color="#FFFFFF">Unidad</font></b></td>
<td height="35" width="148" align="center"><b>
<font face="Arial" size="2" color="#FFFFFF">Descripción</font></b></td>
<td height="35" width="148" align="center"><b>
<font face="Arial" size="2" color="#FFFFFF">P. Unitario</font></b></td>
<td height="35" width="148" align="center"><b>
<font face="Arial" size="2" color="#FFFFFF">Importe</font></b></td>
</tr>
</table>
<table border="1" width="740" height="35" cellspacing="0" cellpadding="0" id="table14" bordercolor="#6B381B">
<?php
$vc_query = "select * from tb_venta_articulo where id_venta = '$id_venta_activa' order by id_venta_articulo ";
$MySQL->query( $GLOBAL_MySQL_host, $vc_query, 0 );
$arr_venta_articulo = $MySQL->arr;
if ( isset($arr_venta_articulo) ) {
foreach( $arr_venta_articulo as $values ) {
echo'
<!-- replica desde aqui -->
<tr>
<td height="35" width="148" align="center">
<font face="Arial" size="2" color="#333333"><b>'.$values["int_cantidad"].'</b></font></td>
<td height="35" width="148" align="center">
<font face="Arial" size="2" color="#333333"><b>'.$values["int_unidad"].'</b></font></td>
<td height="35" width="148" align="center">
<font face="Arial" size="2" color="#333333"><b>'.$values["vc_descripcion"].'</b></font></td>
<td height="35" width="148" align="center">
<font face="Arial" size="2" color="#333333"><b>'.number_format($values["dec_precio_unitario"], 2, ".", ",").'</b></font></td>
<td height="35" width="148" align="center">
<font face="Arial" size="2" color="#333333"><b>'.number_format($values["dec_precio_importe"], 2, ".", ",").'</b></font></td>
</tr>
<!-- replica hasta aqui -->
';
}
}
?>
</table>
<div align="center">
<table border="0" width="740" height="81" cellspacing="0" cellpadding="0" id="table15">
<tr>
<td height="20" width="444">&nbsp;</td>
<td height="20" width="296" align="right" colspan="2">&nbsp;</td>
</tr>
<tr>
<td height="41" width="444"><font face="Arial"><b>
<font size="2" color="#333333">Importe con letra:</font></b></font></td>
<td height="41" width="148" align="right"><b>
<font face="Arial" size="2" color="#333333">Subtotal: </font></b>
<font color="#333333" face="Arial">
&nbsp;&nbsp;
</font></td>
<td height="41" width="148" align="right">
<font face="Arial" size="2" color="#333333">$
<?php
$dec_precio_subtotal = $MySQL->query( $GLOBAL_MySQL_host, " select sum(dec_precio_importe) from tb_venta_articulo where id_venta = '$id_venta_activa' ", 1 );
echo number_format($dec_precio_subtotal, 2, ".", ",")
?>
</font></td>
</tr>
<tr>
<td height="40" width="444"><b>
<font size="2" face="Arial" color="#333333"><?php echo $cantidadLetra->ValorEnLetras($dec_precio_subtotal * 1.15," Pesos") ?></font></b></td>
<td height="40" width="148" align="right"><b>
<font face="Arial" size="2" color="#333333">IVA: </font></b>
<font color="#333333" face="Arial">
&nbsp;&nbsp;
</font></td>
<td height="40" width="148" align="right">
<font face="Arial" size="2" color="#333333">$ <?php $dec_precio_iva = $dec_precio_subtotal * 0.15; echo number_format($dec_precio_iva, 2, ".", ","); ?> </font></td>
</tr>
<tr>
<td height="40" width="444">&nbsp;</td>
<td height="40" width="148" align="right"><b>
<font face="Arial" size="2" color="#333333">Total: </font></b>
<font color="#333333" face="Arial">
&nbsp;&nbsp;
</font></td>
<td height="40" width="148" align="right">
<font face="Arial" size="2" color="#333333">$ <?php $dec_precio_total = $dec_precio_iva + $dec_precio_subtotal; echo number_format($dec_precio_total, 2, ".", ","); ?> </font></td>
</tr>
<tr>
<td height="40" width="444">&nbsp;</td>
<td height="40" width="296" align="right" colspan="2">
<a target="_self" href="factura.php?b_imprime_factura=1">
<img border="0" src="images/btn_enviar.jpg" width="90" height="30"></a></td>
</tr>
<tr>
<td height="15" width="740" colspan="3">
<img border="0" src="images/line_03.jpg" width="740" height="15"></td>
</tr>
</table>
</div>
</body>
</html>
esta todo seguido el anterior esta junto con este muchas gracias . en el anterior en la impresion de factura ay una s, ese error es mio =S onde le andube moviendo
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 03:37.