// --------------------------------------------------------- DATA
$campanias = $venta->getCampaniaNombreByLinealId($in);
if (isset($campanias)) {
    echo '<table>';
    echo '<thead>';
    echo '<tr>';
    echo '<th>Fecha de Creación</th><th width="350">Asesor de Venta</th><th>Acciones </th>';
    echo '</tr>';
    echo '</thead>';
    foreach ($campanias as $row) {
        $in['campania'] = $row['indice'];
        $row = $venta->getVentasPorAprobar($in);
        if (isset($row)) {
            foreach ($row as $r) {
                echo '<tr>';
                echo '<td><center>' . Utilidades::fechas_de_MysqlTimeStamp_a_string_hm($r['fecha']) . '</center></td>';
                echo '<td>' . utf8_encode($r['asesor_venta']) . '</td>';
                echo '<td><a class="aprobar button tiny view no-margin warning" 
                                 title="Aprobar"
                                 campania="' . $in['campania'] . '"
                                 venta_id="' . $r['id'] . '"
                              ><i class="fi-check medium"></i></a> 
                              <a class="edit button tiny view no-margin"
                                 venta_id="' . $r['id'] . '"
                                 campania="' . $in['campania'] . '"
                                 title="Editar"
                                 data-open="venta_listado_modal_div"                                  
                              ><i class="fi-pencil medium"></i></a>
                          </td>';
                echo '</tr>';
            }
$query = mysqli_query($conn, $sql) or die("02");
$totalFiltered = mysqli_num_rows($query);
// when there is a search parameter then we have to modify total number filtered rows as per search result.
$sql .= " ORDER BY " . (intval($requestData['order'][0]['column']) + 1) . " " . $requestData['order'][0]['dir'] . " LIMIT " . $requestData['start'] . " ," . $requestData['length'] . " ";
// print $sql;
/* $requestData['order'][0]['column'] contains colmun index, $requestData['order'][0]['dir'] contains order such as asc/desc  */
$q = mysqli_query($conn, 'SELECT id, nombre FROM venta_estado_real WHERE info_status = 1 AND campania LIKE "%' . $CAMPANIA . '%"') or die("02.5");
$str_combo = '<select class="lista-estado-row no-margin no-padding" campania="" venta="" style="background-color: transparent">';
while ($row = mysqli_fetch_array($q)) {
    $str_combo .= '<option value="' . $row['id'] . '">';
    $str_combo .= utf8_encode($row['nombre']);
    $str_combo .= '</option>';
}
$str_combo .= '</select>';
$query = mysqli_query($conn, $sql) or die("03");
$data = array();
while ($row = mysqli_fetch_array($query)) {
    $nestedData = array();
    $combo_estado = str_replace('option value="' . $row['estado_real_id'] . '"', 'option value="' . $row['estado_real_id'] . '" selected', $str_combo);
    $combo_estado = str_replace('campania=""', 'campania="' . $row['campania'] . '"', $combo_estado);
    $combo_estado = str_replace('venta=""', 'venta="' . $row['venta_id'] . '"', $combo_estado);
    $nestedData[] = $combo_estado;
    $nestedData[] = utf8_encode($row['asesor_venta']);
    $nestedData[] = Utilidades::fechas_de_MysqlTimeStamp_a_string_hm($row['fecha_creacion']);
    $nestedData[] = utf8_encode($row['producto']);
    $nestedData[] = utf8_encode($row['cliente_nombre']);
    $data[] = $nestedData;
}
$json_data = array("draw" => intval($requestData['draw']), "recordsTotal" => intval($totalData), "recordsFiltered" => intval($totalFiltered), "data" => $data, "sql" => $sql);
echo json_encode($json_data);
// send data as json format
// Utilidades::printr($_POST);
// Utilidades::printr($ou);
// ------------------------------------------------------- OUTPUT
if (isset($ou)) {
    foreach ($ou as $row) {
        $pendiente = 'pendiente-no';
        if ($row['pendiente'] == '1') {
            $pendiente = 'pendiente-si';
        }
        if ('' == trim($row['telefono'])) {
            $row['telefono'] = 'Vacio';
        }
        echo '
        <div id="#item-' . $row['id'] . '" class="item column">
          <a data-open="' . $prefix . 'modal"
             class="' . $pendiente . '"
             item="' . $row['id'] . '">
            <p>' . Utilidades::fechas_de_MysqlTimeStamp_a_string_hm($row['info_create_fecha']) . '
               <strong> Teléfono</strong>: ' . utf8_decode($row['telefono']) . '
            </p>
            <div class="resumen">
            ' . html_entity_decode($row['texto']) . '  
            </div>
          </a>
        </div>
        ';
    }
}
?>

     $acciones .= '<a class="button tiny transparencia no-margin warning " venta_id="' . $row['venta_id'] . '" campania="' . $row['campania'] . '" data-open="venta_listado_modal_div3" title="Trasparencia" ><i class="fi-magnifying-glass medium"></i></a>';
 }
 if (validar_permisos('dele', $row)) {
     $acciones .= '<a class="button tiny delete no-margin alert" venta_id="' . $row['venta_id'] . '" campania="' . $row['campania'] . '" title="Eliminar" ><i class="fi-x medium"></i></a>';
 }
 $nestedData[] = '<center class="item-datatable item-datatable-' . $row['venta_id'] . '">' . $acciones . '</center>';
 $nestedData[] = '
 <div class="editable-inline line2" class=""' . $sty_color . '>
   <a></a>
   <span venta_id="' . $row['venta_id'] . '" campo="info_create_fecha">
   ' . Utilidades::fechas_de_MysqlTimeStamp_a_string_hm($row['fecha_creacion']) . '
   </span>
   <div style="display:none"></div>      
 </div>
 ';
 $nestedData[] = '<span' . $sty_color . '>' . Utilidades::fechas_de_MysqlTimeStamp_a_string_hm($row['fecha_actualizacion']) . '</span>';
 $tmp = substr($row['agendado_fecha'], 0, 16);
 if ($tmp == '0000-00-00 00:00') {
     $tmp = '';
 }
 $nestedData[] = utf8_encode('<u' . $sty_color . '>Obs</u>:
                              <div class="editable-inline line2" class="" ' . $sty_color . '>
                                <a></a>
                                <span venta_id="' . $row['venta_id'] . '" campo="agendado_descripcion">
                                ' . $row['agendado_descripcion'] . '
                                </span>
                                <div style="display:none"></div>
                              </div>
                              <u' . $sty_color . '>Fecha</u>:
                              <div class="editable-inline line2" class=""' . $sty_color . '>
                                <a></a>