/**
  * Método que entrega el objeto del emisor del dte recibido
  * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
  * @version 2015-09-28
  */
 public function getEmisor()
 {
     if (!isset($this->Emisor)) {
         $this->Emisor = (new Model_Contribuyentes())->get($this->emisor);
         if (!$this->Emisor->exists()) {
             $this->Emisor->dv = \sowerphp\app\Utility_Rut::dv($this->emisor);
             $this->Emisor->razon_social = \sowerphp\app\Utility_Rut::addDV($this->emisor);
             $this->Emisor->save();
         }
     }
     return $this->Emisor;
 }
 /**
  * Constructor del contribuyente
  * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
  * @version 2015-12-31
  */
 public function __construct($rut = null)
 {
     if (!is_numeric($rut)) {
         $rut = explode('-', str_replace('.', '', $rut))[0];
     }
     if (is_numeric($rut)) {
         parent::__construct($rut);
         if (!$this->exists()) {
             $this->dv = \sowerphp\app\Utility_Rut::dv($this->rut);
             $response = \sowerphp\core\Network_Http_Socket::get('https://sasco.cl/api/servicios/enlinea/sii/actividad_economica/' . $this->rut . '/' . $this->dv);
             if ($response['status']['code'] == 200) {
                 $info = json_decode($response['body'], true);
                 $this->razon_social = substr($info['razon_social'], 0, 100);
                 if (!empty($info['actividades'][0]['codigo'])) {
                     $this->actividad_economica = $info['actividades'][0]['codigo'];
                 }
                 if (!empty($info['actividades'][0]['glosa'])) {
                     $this->giro = substr($info['actividades'][0]['glosa'], 0, 80);
                 }
                 try {
                     $this->save();
                 } catch (\sowerphp\core\Exception_Model_Datasource_Database $e) {
                 }
             }
         }
         $this->contribuyente =& $this->razon_social;
     }
 }