Beispiel #1
0
 public function consultarGasto($id_gasto)
 {
     $this->id_gasto = $id_gasto;
     $sql = "SELECT * FROM gastos WHERE id = '{$this->id_gasto}' ";
     $result = mysqli_query(Gastos::conetarbd(), $sql) or die(mysqli_error());
     var_dump($result);
     $contar = mysqli_num_rows($result);
     if ($result === "0") {
         echo "No se han encontrado resultados para '<b>" . $this->id_gasto . "</b>'.";
     } else {
         while ($row = $result->fetch_assoc()) {
             echo '<div class="form-group">
       <label for="nombre-gasto">Nombre de gasto:</label>
       <input type="text" class="form-control" id="" value="' . $row["nombre_gasto"] . '">
     </div>
     <div class="form-group">
       <label for="tipo-gasto">Tipo de gasto</label>
       <input type="text" class="form-control" id="tipo-gasto" value="' . $row["nombre_gasto"] . '">
     </div>
     <div class="form-group">
       <label for="cantidad-gasto">Cantidad de gasto</label>
       <input type="text" class="form-control" id="cantidad-gasto">
     </div>
     <button type="submit" class="btn btn-success update">Guardar</button>';
         }
     }
 }
 /**
  * Declares an association between this object and a Gastos object.
  *
  * @param      Gastos $v
  * @return     GastoFijoMensual The current object (for fluent API support)
  * @throws     PropelException
  */
 public function setGastos(Gastos $v = null)
 {
     if ($v === null) {
         $this->setIdGasto(NULL);
     } else {
         $this->setIdGasto($v->getId());
     }
     $this->aGastos = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the Gastos object, it will not be re-added.
     if ($v !== null) {
         $v->addGastoFijoMensual($this);
     }
     return $this;
 }
<?php

/**
 * Obtiene todos los gastos de la base de datos
 */
/**
 * Constantes para construcción de respuesta
 */
const ESTADO = "estado";
const DATOS = "gastos";
const MENSAJE = "mensaje";
const CODIGO_EXITO = 1;
const CODIGO_FALLO = 2;
require '../data/Gastos.php';
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
    // Obtener gastos de la base de datos
    $gastos = Gastos::getAll();
    // Definir tipo de la respuesta
    header('Content-Type: application/json');
    if ($gastos) {
        $datos[ESTADO] = CODIGO_EXITO;
        $datos[DATOS] = $gastos;
        print json_encode($datos);
    } else {
        print json_encode(array(ESTADO => CODIGO_FALLO, MENSAJE => "Ha ocurrido un error"));
    }
}
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      Gastos $value A Gastos object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(Gastos $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
Beispiel #5
0
            break;
        case 'estadisticas':
            require 'gastos.model.php';
            $gastos = new Gastos();
            $gastos->obtener_estadistica();
            break;
        case 'ingresar':
            /*Aquí puedes añadir otro método*/
            $f = $_POST['fecha'];
            $d = $_POST['descripcion'];
            $c = $_POST['categoria'];
            $m = $_POST['medio'];
            $i = $_POST['identificador'];
            $t = $_POST['total'];
            require 'gastos.model.php';
            $gastos = new Gastos();
            $gastos->almacenar_gastos($f, $d, $c, $m, $i, $t);
            break;
        case 'detalle_dia':
            $parametros = $_POST['parametros'];
            require 'gastos.model.php';
            $gastos = new Gastos();
            $gastos->obtener_detalle_gastos($parametros);
            break;
        default:
            echo 'not defined';
            break;
    }
} else {
    echo 'not defined';
}
<?php

/**
 * Insertar un nuevo gasto en la base de datos
 */
// Constantes para construir la respuesta
const ESTADO = 'estado';
const MENSAJE = 'mensaje';
const ID_GASTO = "idGasto";
const CODIGO_EXITO = '1';
const CODIGO_FALLO = '2';
require '../data/Gastos.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    // Decodificando formato Json
    $body = json_decode(file_get_contents("php://input"), true);
    // Insertar gasto
    $idGasto = Gastos::insertRow($body);
    if ($idGasto) {
        // Código de éxito
        print json_encode(array(ESTADO => CODIGO_EXITO, MENSAJE => 'Creación éxitosa', ID_GASTO => $idGasto));
    } else {
        // Código de falla
        print json_encode(array(ESTADO => CODIGO_FALLO, MENSAJE => 'Creación fallida'));
    }
}
?>

Beispiel #7
0
<?php

// Conectando, seleccionando la base de datos+
$mysqli = mysqli_connect("localhost", "root", "", "prueba_ajax");
require '../class/AmdGastosClass.php';
/*$nombre = 	empty( $_POST['name'] ) ? null : $nombre;
		$correo =	empty( $_POST['email'] ) ? null : $correo;

		$nombre_gasto = is_null( $_POST['nombreGasto'] ? false : $nombre_gasto);
		$tipo_gasto = is_null( $_POST['TipoGasto'] ) ? false : $tipo_gasto;
		$valor_gasto = is_null( $_POST['ValorGasto'] ) ? false : $valor_gasto;
*/
$id_gasto = $_POST['id_gasto'];
var_dump($id_gasto);
//Crear nuevos gastos en bases de datos
$gastos = new Gastos();
//$gastos->crearGasto( $nombre_gasto, $tipo_gasto, $valor_gasto );
//Consultar gastos
$gastos->consultarGasto($id_gasto);
// fin de gstos
/*
	$sql = "INSERT INTO usuarios (nombre, correo) VALUES ('$nombre','$correo')";
	$result = mysqli_query( $mysqli, $sql );

	if( $result ){
		return $result;
	}	else { 
		echo "An error occurred!"; 
	}
*/