Ver Mensaje Individual
  #1 (permalink)  
Antiguo 28/08/2015, 17:21
rtel
 
Fecha de Ingreso: junio-2015
Mensajes: 5
Antigüedad: 8 años, 10 meses
Puntos: 0
No graba registros en base de datos

Buenas,
tengo un programa de facturación en el cual estoy ingresando varios registros a la vez con mysqli pero el programa corre sin errores pero cuando reviso mi base de datos no tengo nada.
ya llevo varios dias viendo que pasa pero me supera ya no se que probar

aca va la pagina edita.php

<?php

include('libreria/motor.php');

if($_POST){
$factura = new factura();
$factura->id = 0;
$factura->rnc = $_POST['txtRNC'];
$factura->ncf = $_POST['txtNCF'];
$factura->cliente = $_POST['txtCliente'];
$factura->fecha = $_POST['txtFecha'];
$factura->concepto = $_POST['txtConcepto'];
$factura->subtotal = $_POST['txtSubTotal'];
$factura->impuestos = $_POST['txtImp'];
$factura->total = $_POST['txtTotal'];

$factura->guardar();
}

$titulo = "Nueva Factura";
include('plantilla.php');

?>
<style>
#divTotales{
float:right;
border:dashed #000000 1px;
}
</style>
<form method="post" action="editar.php">
<table>
<tr>
<th>Cliente</th>
<td><input type="text" name="txtCliente"/></td>
<th>Fecha</th>
<td><input type="text" name="txtFecha"/></td>
</tr>
<tr>
<th>RNC</th>
<td><input type="text" name="txtRNC"/></td>
<th>NCF</th>
<td><input type="text" name="txtNCF"/></td>
</tr>
</table>
<fieldset>
<legend>Concepto</legend>
<textarea class='tblDaata' name="txtConcepto"></textarea>
</fieldset>
<button type='button' onclick="nuevoArticulo();">Add</button>
<table class='tblData'>
<thead>
<tr>
<th>Codigo</th>
<th>Articulo</th>
<th>Cantidad</th>
<th>Precio</th>
<th>Subtotal</th>
<th>act</th>
</tr>
</thead>
<tbody id="tbDetalle">

</tbody>
</table>

<div style="height:150px;">
<button type="submit">Guardar</button>
<button type="button" onClick="cancelar();">Cancelar</button>
<button type="button">Nuevo</button>
<button type="button">Imprimir</button>
<div id="divTotales">
<table>
<tr>
<th>Sub Total:</th>
<td>
<input type="text" name="txtSubTotal" id="txtSubTotal"/>
</td>
</tr>
<tr>
<th>Impuestos:</th>
<td>
<input type="text" name="txtImp" id="txtImp"/>
</td>
</tr>
<tr>
<th>Total:</th>
<td>
<input type="text" name="txtTotal" id="txtTotal"/>
</td>
</tr>
</table>
</div>
</div>
</form>
<script>

function crearCampo(nombre){
td = document.createElement('td');
txt = document.createElement('input');
txt.type = 'text';
txt.setAttribute('name',nombre);
td.appendChild(txt);
return td;
}

function nuevoArticulo(){
destino = document.getElementById('tbDetalle');
tr = document.createElement('tr');
tr.appendChild(crearCampo('det_codigo[]'));
tr.appendChild(crearCampo('det_articulo[]'));
tr.appendChild(crearCampo('det_cantidad[]'));
tr.appendChild(crearCampo('det_precio[]'));
tr.appendChild(crearCampo('det_subtotal[]'));
td = document.createElement('td');
x = document.createElement('button');
x.type='button';
x.innerHTML = 'X';
x.setAttribute('onclick','eliminarFila(this)');
td.appendChild(x);
tr.appendChild(td);
destino.appendChild(tr);
}

function eliminarFila(btn){
if(confirm("Seguro Quiere Borrar la fila?")){
fila = btn.parentNode.parentNode;
fila.parentNode.removeChild(fila);
}
}

function cancelar(){
ok = confirm("Seguro que quiere Cancelar");
if(ok){
window.location = './';
}
}
</script>


y aca va la pagina ok_factura.php que supuestamente inserta los datos creados..

<?php

class factura{

private $id = '';
private $concepto = '';
private $cliente = '';
private $fecha = '';
private $rnc = '';
private $ncf = '';
private $subtotal = '';
private $impuestos = '';
private $total = '';
private $ci = '';

private $detalleFactura;

public function agregarDetalle($codigo, $articulo, $cantidad, $precio){
$this->detalleFactura[] = array(
'codigo'=>$codigo,
'articulo'=>$articulo,
'cantidad'=>$cantidad,
'precio'=>$precio,
'subtotal'=>$cantidad * $precio
);
}

function __construct(){
$this->detalleFactura = array();
}

function __get($prop){

if(isset($this->$prop)){
return $this->$prop;
}
else{
echo "La propiedad {$prop} no existe en la factura";
}
return "";
}

function __set($prop, $val){

if(isset($this->$prop)){
$this->$prop = $val;
}
else{
echo "La propiedad {$prop} no existe en la factura";
}
}

function guardar(){
$this->ci = count($this->detalleFactura);

$con = objCon::obtenerInstancia();
if ($this->id >0){
//Actualizar
}else{
//Insertar

$sql = "INSERT INTO `factura`
('concepto', 'cliente', 'fecha', 'rnc', 'ncf', 'subtotal', 'impuestos', 'total', 'ci')
VALUES
({$this->concepto}',
'{$this->cliente}',
'{$this->fecha}',
'{$this->rnc}',
'{$this->ncf}',
'{$this->subtotal}',
'{$this->impuestos}',
'{$this->total}',
'{$this->ci}');";
mysqli_query($con, $sql);
$this->id = mysqli_insert_id($con);

}

//foreach($this->detalleFactura as $detalle){
//}//

}
}





?>