<?php
/*
JOHNN GUTIERREZ,
FECHA DE CREACION   2021-01-28
ULTIMA MODIFICASION 2022-03-17
 */
include 'conn_obj/conn_param.php';
include 'conn_obj/utiles_pdo.php';
date_default_timezone_set("America/Panama");
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
#error_reporting(E_ALL);

session_start();
$_SESSION['db_name'] = $_POST['db_name'];
$_SESSION['cod_suc'] = $_POST['cod_suc'];
$_SESSION['cod_dep'] = $_POST['cod_dep'];

$cDb_Name = $_SESSION['db_name'];
$cCod_Suc = $_SESSION['cod_suc'];
$cCod_Dep = $_SESSION['cod_dep'];

$conn = new Utiles($cDb_Name, $Srv_Info['hostname'], $Srv_Info['username'], $Srv_Info['password']);

$cSql_Cmd = "SELECT
                suc_id,
                dep_id,
                UPPER(TRIM(IFNULL(dep_descripcion,''))) AS dep_descripcion,
                IFNULL(dep_activo,0) AS dep_activo,
                IFNULL(dep_abrev,'') AS dep_abrev,
                IFNULL(dep_orden,0) AS dep_orden,
                1 as dep_prec_sel,
                ifnull(para_la_venta,0) as para_la_venta
              FROM `$cDb_Name`.depositos
              WHERE (IFNULL(dep_activo   ,0)=1)
              AND   (IFNULL(para_la_venta,0)=1)  
              AND   ".(( ($cCod_Suc=='%') || ($cCod_Suc=='*') || ($cCod_Suc==''))?"true":"suc_id='$cCod_Suc'")."
              AND   ".(( ($cCod_Dep=='%') || ($cCod_Dep=='*') || ($cCod_Dep==''))?"true":"dep_id='$cCod_Dep'")."
              ORDER BY UPPER(TRIM(IFNULL(dep_descripcion,''))) ";
//ORDER BY suc_id, UPPER(TRIM(IFNULL(dep_descripcion,""))) ';


$conn->query($cSql_Cmd);
$oData = $conn->fetchAll();

header('content-type: application/json');
echo json_encode($oData);
@mysqli_close($conn);
?>
