<?php

include 'database.php';

class Productos extends DataBase{
    
    public function __construct() {
        parent::__construct();
    }
    
    public function buscar($producto, $bodega){

if(isset($_SESSION['datos'])){
unset($_SESSION['datos']);
}else{

$_SESSION['datos'] = array();
$sth = $this->prepare('SELECT * FROM productos WHERE descripcion LIKE "%'.$producto.'%" AND bodega LIKE "%'.$bodega.'%" ORDER BY descripcion');
$sth->execute();
$result = $sth->fetchAll();
        foreach ($result as $key => $value) {
$_SESSION['datos'][] = array("value" => $value['descripcion'],
                "codigoProducto" => $value['codigo'],
                "precioProducto" => $value['precio1'],
                "costoProducto" => $value['costo'],
                "ivaProducto" => $value['iva'],
                "saldoProducto" => $value['saldo']);
        }
}

        
        return $_SESSION['datos'];



    }
    
}

