Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class MySQL {
- /**
- * MySQL server hostname
- * @access private
- * @var string
- */
- var $host;
- /**
- * MySQL username
- * @access private
- * @var string
- */
- var $dbUser;
- /**
- * MySQL user's password
- * @access private
- * @var string
- */
- var $dbPass;
- /**
- * Name of database to use
- * @access private
- * @var string
- */
- var $dbName;
- /**
- * MySQL Resource link identifier stored here
- * @access private
- * @var string
- */
- var $dbConn;
- /**
- * Stores error messages for connection errors
- * @access private
- * @var string
- */
- var $connectError;
- /**
- * MySQL constructor
- * @param string host (MySQL server hostname)
- * @param string dbUser (MySQL User Name)
- * @param string dbPass (MySQL User Password)
- * @param string dbName (Database to select)
- * @access public
- */
- var $transaccion;
- function MySQL () {
- /*
- $host = 'localhost';
- $dbUser = 'root';
- $dbPass = '';
- $dbName = 'rectoria_news';
- */
- $host = 'localhost';
- $dbUser = 'root';
- $dbPass = '1234';
- $dbName = 'unioncamioneros2';
- $this->host=$host;
- $this->dbUser=$dbUser;
- $this->dbPass=$dbPass;
- $this->dbName=$dbName;
- $this->connectToDb();
- }
- /**
- * Establishes connection to MySQL and selects a database
- * @return void
- * @access private
- */
- function connectToDb ()
- {
- // Make connection to MySQL server
- if (!$this->dbConn = @mysql_connect($this->host,
- $this->dbUser,
- $this->dbPass)) {
- trigger_error('Could not connect to server');
- $this->connectError=true;
- // Select database
- } else if ( !@mysql_select_db($this->dbName,$this->dbConn) ) {
- trigger_error('Could not select database');
- $this->connectError=true;
- }
- }
- function Transaccion()
- {
- $this->transaccion = new Transaccion($this->dbConn);
- }
- /**
- * Checks for MySQL errors
- * @return boolean
- * @access public
- */
- function isError ()
- {
- if ( $this->connectError )
- return true;
- $error=mysql_error ($this->dbConn);
- if ( empty ($error) )
- return false;
- else
- return true;
- }
- /**
- * Returns an instance of MySQLResult to fetch rows with
- * @param $sql string the database query to run
- * @return MySQLResult
- * @access public
- */
- function & query($sql)
- {
- if (!$queryResource=mysql_query($sql,$this->dbConn))
- {
- trigger_error ('Query failed: '.mysql_error($this->dbConn).' SQL: '.$sql);
- }
- return new MySQLResult($this,$queryResource);
- }
- }//end class mysql
- /**
- * MySQLResult Data Fetching Class
- * @access public
- * @package SPLIB
- */
- class MySQLResult
- {
- /**
- * Instance of MySQL providing database connection
- * @access private
- * @var MySQL
- */
- var $mysql;
- /**
- * Query resource
- * @access private
- * @var resource
- */
- var $query;
- /**
- * MySQLResult constructor
- * @param object mysql (instance of MySQL class)
- * @param resource query (MySQL query resource)
- * @access public
- */
- function MySQLResult(& $mysql,$query)
- {
- $this->mysql=& $mysql;
- $this->query=$query;
- }
- /**
- * Fetches a row from the result
- * @return array
- * @access public
- */
- function fetch ()
- {
- if ( $row=mysql_fetch_array($this->query,MYSQL_ASSOC) )
- {
- return $row;
- } else if ( $this->size() > 0 )
- {
- mysql_data_seek($this->query,0);
- return false;
- } else
- {
- return false;
- }
- }//end fetch
- function fetchRow()
- {
- if ( $row=mysql_fetch_row($this->query) )
- {
- return $row;
- } else if ( $this->size() > 0 )
- {
- mysql_data_seek($this->query,0);
- return false;
- } else
- {
- return false;
- }
- }//end fetchRow
- /**
- * Returns the number of rows selected
- * @return int
- * @access public
- */
- function size ()
- {
- return mysql_num_rows($this->query);
- }
- /**
- * Returns the number of rows affected
- * @return int
- * @access public
- */
- function affectedRows ()
- {
- return mysql_affected_rows($this->mysql->dbConn);
- }
- /**
- * Returns the ID of the last row inserted
- * @return int
- * @access public
- */
- function insertID ()
- {
- return mysql_insert_id($this->mysql->dbConn);
- }
- /**
- * Checks for MySQL errors
- * @return boolean
- * @access public
- */
- function isError ()
- {
- return $this->mysql->isError();
- }
- }//end mysqlResult
- /**********************************************************************************/
- /* Transacciones con PHP - MYSQL */
- /**********************************************************************************/
- class Transaccion/* Nombre de la clase */
- {
- private $Cnn; /* Variable de conexxion */
- /****************************************/
- function Transaccion($Con)
- {
- //mysql_disconnect($this->Cnn); /* Desconecta la conexion a la BD */
- $this->Cnn=$Con;
- //
- }
- /****************************************/
- function begin()
- {
- mysql_query("BEGIN",$this->Cnn); /* Abre la transaccion */
- }
- /****************************************/
- function rollback()
- {
- mysql_query("ROLLBACK",$this->Cnn); /* Deshace la transaccion */
- }
- /****************************************/
- function commit()
- {
- mysql_query("COMMIT ", $this->Cnn); /* Ejecuta la transaccion */
- }
- }//end Class
- ?>
- <?
- class Precio
- {
- private $db;
- function Precio(&$db)
- {
- $this->db=&$db;
- }
- function lsPrecios()
- {
- $SQL="SELECT * FROM precios";
- $resultado=$this->db->query($SQL);
- return $resultado;
- }
- function registrarPrecio($kilometro,$precio)
- {
- $e = false;
- $this->db->Transaccion();
- $this->db->transaccion->begin();
- $SQL="INSERT INTO precios SET kilometro=".$kilometro.",
- precio=".$precio."";
- $resultado=$this->db->query($SQL);
- if($resultado->affectedRows()>0)
- $e = true;
- if($e)
- $this->db->transaccion->commit();
- else
- $this->db->transaccion->rollback();
- }
- function actualizarPrecio($datos)
- {
- $e = false;
- $this->db->Transaccion();
- $this->db->transaccion->begin();
- $id_precio=trim($datos['txtid_precio']);
- $precio=trim($datos['_txtprecio']);
- $SQL="UPDATE precios SET precio=".$precio." WHERE id_precio=".$id_precio."";
- echo "La sentencia es la siguiente: ".$SQL;
- $resultado=$this->db->query($SQL);
- if($resultado->affectedRows()>0)
- $e = true;
- if($e)
- $this->db->transaccion->commit();
- else
- $this->db->transaccion->rollback();
- }
- function buscarPrecio($datos)
- {
- $id_precio=trim($datos['id']);
- $SQL="SELECT * FROM precios WHERE id_precio=".$id_precio."";
- $resultado=$this->db->query($SQL);
- return $resultado;
- }
- function buscarValor($kilometros,$capacidad)
- {
- $precio=0;
- $SQL="SELECT precio FROM precios WHERE kilometro=".$kilometros."";
- $resultado=$this->db->query($SQL);
- while($rec=$resultado->fetch())
- {
- $precio=$rec['precio'];
- }
- if($capacidad==14)
- {
- $precio=$precio*2;
- }
- return $precio;
- }
- }//
- ?>
- <?php
- class Factura
- {
- var $db;
- var $id_generado;
- function Factura(&$Con)
- {
- $this->db=&$Con;
- }//
- function lsFacturas()
- {
- $SQL = "SELECT facturas.id_factura,facturas.folio AS folio_factura,contrarecibos.*,clientes.nombre,camiones.numero_camion ,
- (SELECT (SUM(viajes) * precio_unitario ) FROM detalle_contrarecibo
- WHERE id_contrarecibo = contrarecibos.id_contrarecibo) AS importe
- FROM contrarecibos
- INNER JOIN clientes ON contrarecibos.id_cliente=clientes.id_cliente
- INNER JOIN camiones ON contrarecibos.id_camion = camiones.id_camion
- INNER JOIN detalle_contrarecibo ON contrarecibos.id_contrarecibo = detalle_contrarecibo.id_contrarecibo
- INNER JOIN detalle_factura ON detalle_Factura.id_contrarecibo=contrarecibos.id_contrarecibo
- INNER JOIN facturas ON detalle_factura.id_factura=facturas.id_factura
- WHERE contrarecibos.id_contrarecibo IN (SELECT id_contrarecibo FROM detalle_factura)
- GROUP BY folio ORDER BY folio";
- return $this->db->query($SQL);
- }
- function actualizarFolio($Datos)
- {
- $SQL="UPDATE facturas SET folio=".$Datos['txtfolio']." WHERE id_factura=".$Datos['id_factura']."";
- $resultado=$this->db->query($SQL);
- if($resultado->affectedRows()>0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- function Guardar($Datos)
- {
- $this->db->Transaccion();
- $this->db->transaccion->begin();
- $e=false;
- $SQL="INSERT INTO facturas SET
- folio='".$Datos['folio']."',
- fecha ='".$Datos['fecha']."',
- id_cliente='".$Datos['id_cliente']."',
- retencion=".$Datos['retencion']."
- ";
- //exit();
- $Resultado = $this->db->query($SQL);
- if($Resultado->affectedRows()>0)
- {
- $this->id_generado = $Resultado->insertID();
- $A=array();
- $A=array_chunk($Datos['Detallado'],5);
- $IdFactura =$Resultado->insertID();
- for( $i = 0 ; $i < count($A) ; $i++ )
- {
- $A[$i]['id_factura'] = $IdFactura;
- if($this->guardarDetallado($A[$i]))
- {
- $e=true;
- }else
- {
- $e=false;
- break;
- }
- }//end for
- }//end size
- if($e)
- $this->db->transaccion->commit();
- else
- $this->db->transaccion->rollback();
- return $e;
- }//
- function guardarDetallado($Datos)
- {
- $e=false;
- //print_r($Datos);
- $SQL="
- INSERT INTO detalle_factura SET
- id_factura = ".$Datos['id_factura'].",
- id_contrarecibo = ".$Datos[1];
- $Resultado=$this->db->query($SQL);
- if($Resultado->affectedRows()>0)
- $e=true;
- else
- $e=false;
- return $e;
- }//
- function generarFactura($IdFactura)
- {
- $SQL="
- SELECT sum(viajes),capacidad,SUM(precio_unitario * viajes)
- FROM facturas
- INNER JOIN detalle_factura ON facturas.id_factura = detalle_factura.id_factura
- INNER JOIN detalle_contrarecibo ON detalle_contrarecibo.id_contrarecibo = detalle_factura.id_contrarecibo
- WHERE facturas.id_factura = $IdFactura
- GROUP BY viajes,capacidad
- ";
- }//generarFactura
- function verDatos($IdFactura)
- {
- $SQL="SELECT * FROM facturas INNER JOIN clientes ON facturas.id_cliente = clientes.id_cliente WHERE id_factura = $IdFactura";
- return $this->db->query($SQL);
- }//
- function verDetalles($IdFactura)
- {
- $SQL="SELECT contrarecibos.*,capacidad,kilometros,SUM(viajes) AS viajes,SUM(precio_unitario*viajes) AS total,detalle_contrarecibo.precio_unitario
- FROM detalle_factura
- INNER JOIN contrarecibos ON detalle_factura.id_contrarecibo = contrarecibos.id_contrarecibo
- INNER JOIN detalle_contrarecibo ON contrarecibos.id_contrarecibo = detalle_contrarecibo.id_contrarecibo
- WHERE detalle_factura.id_factura = $IdFactura GROUP BY capacidad,kilometros";
- return $this->db->query($SQL);
- }//
- function borrarFactura($Id_Factura)
- {
- $SQL="DELETE FROM detalle_factura WHERE id_factura=".$Id_Factura."";
- $Resultado=$this->db->query($SQL);
- if($Resultado->affectedRows()>0)
- {
- $SQL="DELETE FROM facturas WHERE id_factura=".$Id_Factura."";
- $Resultado=$this->db->query($SQL);
- if($Resultado->affectedRows()>0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- else
- {
- return false;
- }
- }//
- }//end class
- ?>
- <ul>
- <?php
- //$pagina = $_SERVER['HTTP_REFERER'];
- switch($_GET['seccion'])
- {
- case "clientes":
- ?>
- <li><a href="index.php?seccion=clientes&subseccion=regCliente">Registrar Cliente</a></li>
- <li><a href="index.php?seccion=clientes&subseccion=lsClientes">Listar Cliente</a></li>
- <li><a href="index.php?seccion=clientes&subseccion=reporteClienteId">Reporte por ID</a></li>
- <li><a href="index.php?seccion=clientes&subseccion=reporteCamionNombre">Reporte por Nombre </a></li>
- <li><a href="index.php?seccion=clientes&subseccion=reporteCamionCiudad">Reporte por Ciudad </a></li>
- <?php
- break;
- case "propietarios":
- ?>
- <li><a href="index.php?seccion=propietarios&subseccion=regPropietario">Registrar Propietario</a></li>
- <li><a href="index.php?seccion=propietarios&subseccion=lsPropietario">Listar Propietario</a></li>
- <li><a href="index.php?seccion=propietarios&subseccion=reportePropietarioId">Reporte por ID</a></li>
- <li><a href="index.php?seccion=propietarios&subseccion=reportePropietarioNombre">Reporte por Nombre</a></li>
- <li><a href="index.php?seccion=propietarios&subseccion=reportePropietarioRFC">Reporte por RFC</a></li>
- <?php
- break;
- case "camiones":
- ?>
- <li><a href="index.php?seccion=camiones&subseccion=regCamion">Registrar Camión</a></li>
- <li><a href="index.php?seccion=camiones&subseccion=lsCamion">Listar Camión</a></li>
- <li><a href="index.php?seccion=camiones&subseccion=reporteCamionId">Reporte por ID</a></li>
- <li><a href="index.php?seccion=camiones&subseccion=reporteCamionProp">Reporte Por Propietario</a></li>
- <?php
- break;
- case "factura":
- ?>
- <li><a href="index.php?seccion=facturas&subseccion=lsFacturas">Listar Facturas</a></li>
- <?php
- break;
- case "precios":
- ?>
- <li><a href="index.php?seccion=precios&subseccion=lsprecios">Listar precios</a></li>
- <?php
- break;
- case "contrarecibos": ?>
- <li><a href="index.php?seccion=contrarecibos&subseccion=regContrarecibo">Registrar Contrarecibo</a></li>
- <li><a href="index.php?seccion=contrarecibos&subseccion=lsContrareciboNoFacturado">Contrarecibos Sin Facturar</a></li>
- <li><a href="index.php?seccion=contrarecibos&subseccion=lsContrareciboFacturado">Contrarecibos Facturados</a></li>
- <?php
- break;
- case "recibos":
- ?>
- <li><a href="index.php?seccion=recibos&subseccion=regRecibo">Registrar Recibo</a></li>
- <li><a href="index.php?seccion=recibos&subseccion=lsRecibo">Listar Recibos</a></li>
- <li><a href="index.php?seccion=recibos&subseccion=reporteRecibosId">Reporte por ID </a></li>
- <li><a href="index.php?seccion=recibos&subseccion=reporteRecibosProp">Reporte por Propietario</a></li>
- <li><a href="index.php?seccion=recibos&subseccion=reporteRecibosFecha">Reporte por Fecha</a></li>
- <li><a href="index.php?seccion=recibos&subseccion=imprimirRecibo">Imprimir Recibo</a></li>
- <?
- break;
- case "relaciones":
- ?>
- <li><a href="index.php?seccion=relaciones&subseccion=regRelacion">Registrar Relacion de Pagos</a></li>
- <li><a href="index.php?seccion=relaciones&subseccion=lsRelacion">Listado de Relaciones</a></li>
- <?
- }//end switch
- ?>
- </ul>
- <?php
- session_start();
- include ('../../connections/MySQL.php');
- include ('../../clases/classCliente.php');
- include ('../../utilerias/pdf/classPDF.php');
- //
- $db = &new MySQL();
- $cliente = new Cliente(&$db);
- $pdf = new PDF();
- $result = $cliente->Listar("SELECT * FROM clientes");
- $pdf->addPage();
- $pdf->SetFillColor(255,0,0);
- $pdf->SetTextColor(255);
- $pdf->SetDrawColor(128,0,0);
- $pdf->SetLineWidth(.3);
- $pdf->SetFont('Arial','','10');
- //Cabecera
- //Restauración de colores y fuentes
- $pdf->SetFillColor(224,235,255);
- $pdf->SetTextColor(0);
- $pdf->SetFont('');
- //Datos
- $fill=false;
- while($row=$result->fetch()){
- //$pdf->MultiCell(190,12,"",0,'C',$fill);
- //$pdf->Cell($w[0],6,$row['nombre'],'LR',0,'L',$fill);
- $pdf->setFont('Arial', 'B', '14');
- $pdf->Cell(160,8,$row['nombre'],'B',0,'L',false);
- $pdf->setFont('Arial','','10');
- $pdf->Ln();
- $pdf->Cell(40,6,$row['razonsocial'],'0',0,'L',false);
- $pdf->Ln(4);
- $pdf->Cell(40,6,$row['rfc'],'0',0,'L',false);
- $pdf->Ln(4);
- $pdf->Cell(40,6,$row['domicilio'],'0',0,'L',false);
- $pdf->Ln(4);
- $pdf->Cell(40,6,$row['ciudad']. ", C.P. ". $row['cp'],'0',0,'L',false);
- $pdf->Ln(4);
- $pdf->Cell(40,6,"Telefono Oficina: ".$row['telefono'] . ", Correo: " . $row['correo'],'0',0,'L',false);
- $pdf->Ln(4);
- $pdf->Cell(40,6,"Telefono Particular: ".$row['telefono2']. ", Celular. ". $row['celular'],'0',0,'L',false);
- $pdf->Ln(4);
- $pdf->Ln(10);
- }
- $pdf->Output();
- ?>
- <?php
- if(isset($_POST['btnEnviar']) && $_SESSION['Time']!=$_POST['hdTime'])
- {
- $Datos = array();
- $Datos['nombre']=$_POST['txtNombre'];
- $Datos['apellidos'] = $_POST['txtApellidos'];
- $Datos['rfc'] = $_POST['txtRFC'];
- $Datos['domicilio'] = $_POST['txtDomicilio'];
- $Datos['ciudad'] = $_POST['txtCiudad'];
- $resultado=$Cliente->registrarCliente($Datos);
- if($resultado)
- {
- ?>
- <script type="text/javascript">
- alert("Cliente registrado");
- </script>
- <?
- }
- else
- {
- ?>
- <script type="text/javascript">
- alert("Error al registrar...");
- </script>
- <?
- }
- }
- ?>
- <form name="frmregistrocliente" method="post" action="<? $_SERVER['PHP_SELF'];?>">
- <fieldset><legend>Registrar Cliente</legend>
- <table class="datatable">
- <tr>
- <td>Nombre: </td>
- <td><input type="text" name="txtNombre" class="txt2" size="50"/></td>
- </tr>
- <tr>
- <td>Domicilio: </td>
- <td><input type="text" name="txtDomicilio" class="txt2" size="65" /></td>
- </tr>
- <tr>
- <td>Ciudad: </td>
- <td><input type="text" name="txtCiudad" class="txt2" size="40"/></td>
- </tr>
- <tr>
- <td>RFC: </td>
- <td><input type="text" name="txtRFC" class="txt2" /></td>
- </tr>
- <tr>
- <td align="center" colspan="2">
- <input type="hidden" name="hdTime" value="<?=time();?>" />
- <input type="submit" name="btnEnviar" value="Registrar" />
- </td>
- </tr>
- </table>
- </fieldset>
- </form>
- <h3>CATÁLOGO DE CLIENTES</h3>
- <table class="datatable" width="90%" align="center">
- <tr>
- <th>Modificar</th>
- <th>Eliminar</th>
- <th>Id </th>
- <th>Nombre</th>
- <th>RFC</th>
- <th>Domicilio</th>
- <th>Ciudad</th>
- </tr>
- <?php
- $resultado=$Cliente->lsClientes();
- if($resultado->size()>0)
- {
- while($rec=$resultado->fetch())
- {
- ?>
- <tr <?php if($i%2==1){?> class="altrow"<?php }$i++; ?>>
- <td align="center" width="10">
- <a href="index.php?seccion=clientes&subseccion=editarCliente&id=<?=$rec['id_cliente'];?>" ><img src="layout/imagenes/b_edit.png" alt="Editar" /></a>
- </td>
- <td align="center" width="10">
- <a href="index.php?seccion=clientes&subseccion=eliminarCliente&id=<?=$rec['id_cliente']?>"><img src="layout/imagenes/b_drop.png" alt="Eliminar" /></a>
- </td>
- <td><?=$rec['id_cliente'];?></td>
- <td><?=htmlentities($rec['nombre']);?></td>
- <td><?=htmlentities($rec['rfc']);?></td>
- <td><?=htmlentities($rec['domicilio']);?></td>
- <td><?=$rec['ciudad'];?></td>
- </tr>
- <?
- }//fin while
- }//fin size()
- ?>
- <tr bgcolor="#eaeaea">
- <td colspan="7" align="center">Fin del Reporte</td>
- </tr>
- </table>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement