<?php
namespace App\Models;
use CodeIgniter\Model;

class AuditoriaModel extends Model
{
    /*protected $table      = 'x';
    protected $primaryKey = 'x';*/
    protected $db;
    protected function initialize()
    {
        // $this->db = \Config\Database::connect();
        $this->db = db_connect();
    }
    
    public function obtenerPrimerPlanContrato($idContrato)
    {
        $builder = $this->db->table('operadores_planes');
        $builder->select('IDPlan,
        IDOperador,
        Plan,
        PlanOperador,
        PrecioPlan,
        PorcentajeDescuento,
        PrecioFinal');
        $builder->where('IDPlan = (SELECT Valor_ALTER FROM `aud_lineas_contrato` where Campo_ALTER = "IDPlan" AND IDContrato_ALTER = "'.$idContrato.'" ORDER BY FechaModifica ASC LIMIT 1)');
        $sql = $builder->getCompiledSelect();
        $datos = $this->db->query($sql)->getRowArray();
        
        return $datos;
    }
    
}