/**
  * 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;
 }
<h1>Bandeja de intercambio de DTE</h1>
<p>Aquí podrá revisar, aceptar o rechazar aquellos DTE que otros contribuyentes han envíado a <?php 
echo $Emisor->razon_social;
?>
</p>

<div class="text-right">
    <a href="dte_intercambios/actualizar" class="btn btn-default">
        <span class="fa fa-refresh"></span>
        Actualizar bandeja de intercambio: <?php 
echo $Emisor->intercambio_user;
?>
    </a>
    <br/><br/>
</div>

<?php 
foreach ($intercambios as &$i) {
    $acciones = '<a href="dte_intercambios/ver/' . $i['codigo'] . '" title="Ver detalles del intercambio"><span class="fa fa-search btn btn-default"></span></a>';
    $acciones .= ' <a href="dte_intercambios/pdf/' . $i['codigo'] . '" title="Descargar PDF del intercambio"><span class="fa fa-file-pdf-o btn btn-default"></span></a>';
    $i[] = $acciones;
    if (is_numeric($i['emisor'])) {
        $i['emisor'] = \sowerphp\app\Utility_Rut::addDV($i['emisor']);
    }
}
array_unshift($intercambios, ['Código', 'Recibido', 'Email', 'Emisor', 'DTEs', 'Estado', 'Usuario', 'Acciones']);
$t = new \sowerphp\general\View_Helper_Table();
$t->setColsWidth([null, null, null, null, null, null, null, 100]);
echo $t->generate($intercambios);
Example #3
0
 /**
  * Método que valida que el dato sea un RUT válido
  * @param data Dato que se quiere validar
  * @return =true si es un RUT válido
  * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]delaf.cl)
  * @version 2016-08-28
  */
 public static function check_rut($data)
 {
     if (!class_exists('\\sowerphp\\app\\Utility_Rut')) {
         return false;
     }
     return \sowerphp\app\Utility_Rut::check($data);
 }
echo $f->input(['type' => 'select', 'name' => 'dte', 'label' => 'Tipo DTE', 'options' => ['' => 'Seleccionar un tipo de documento'] + $dtes, 'value' => $dte, 'check' => 'notempty']);
echo $f->input(['name' => 'folio', 'label' => 'Folio DTE', 'check' => 'notempty integer']);
echo $f->input(['type' => 'date', 'name' => 'fecha', 'label' => 'Fecha emisión', 'check' => 'notempty date']);
echo $f->input(['name' => 'total', 'label' => 'Monto total', 'check' => 'notempty integer']);
echo $f->end('Consultar DTE');
// si se encontró un DTE se muestra
if (isset($DteEmitido)) {
    ?>
<h2><?php 
    echo $DteEmitido->getTipo()->tipo;
    ?>
 #<?php 
    echo $DteEmitido->folio;
    ?>
 a <?php 
    echo \sowerphp\app\Utility_Rut::addDV($DteEmitido->receptor);
    ?>
</h2>
<div class="row">
    <div class="col-md-9">
<?php 
    new \sowerphp\general\View_Helper_Table([['Documento', 'Folio', 'Receptor', 'Exento', 'Neto', 'IVA', 'Total'], [$DteEmitido->getTipo()->tipo, $DteEmitido->folio, $DteEmitido->getReceptor()->razon_social, num($DteEmitido->exento), num($DteEmitido->neto), num($DteEmitido->iva), num($DteEmitido->total)]]);
    ?>
        <div class="row">
            <div class="col-md-6">
                <a class="btn btn-default btn-lg btn-block" href="<?php 
    echo $_base;
    ?>
/dte/dte_emitidos/pdf/<?php 
    echo $DteEmitido->dte;
    ?>
<a href="<?php 
echo $_base;
?>
/dte/dte_recibidos/listar" title="Volver a los documentos recibidos" class="pull-right"><span class="btn btn-default">Volver a DTE recibidos</span></a>

<h1>Editar documento <?php 
echo $DteRecibido->getTipo()->tipo;
?>
 N° <?php 
echo $DteRecibido->folio;
?>
</h1>
<?php 
$f = new \sowerphp\general\View_Helper_Form();
echo $f->begin(['onsubmit' => 'Form.check()']);
echo $f->input(['name' => 'emisor', 'label' => 'RUT emisor', 'value' => \sowerphp\app\Utility_Rut::addDV($DteRecibido->emisor), 'check' => 'notempty rut']);
echo $f->input(['type' => 'select', 'name' => 'dte', 'label' => 'Documento', 'options' => ['' => 'Seleccionar tipo de DTE'] + $tipos_documentos, 'value' => $DteRecibido->dte, 'check' => 'notempty']);
echo $f->input(['name' => 'folio', 'label' => 'Folio', 'value' => $DteRecibido->folio, 'check' => 'notempty integer']);
echo $f->input(['type' => 'date', 'name' => 'fecha', 'label' => 'Fecha documento', 'value' => $DteRecibido->fecha, 'check' => 'notempty date']);
echo $f->input(['name' => 'tasa', 'label' => 'Tasa IVA', 'value' => $DteRecibido->tasa, 'check' => 'integer']);
echo $f->input(['name' => 'exento', 'label' => 'Monto exento', 'value' => $DteRecibido->exento, 'check' => 'integer']);
echo $f->input(['name' => 'neto', 'label' => 'Neto', 'value' => $DteRecibido->neto, 'check' => 'integer']);
echo $f->input(['name' => 'iva_uso_comun', 'label' => 'IVA uso común', 'check' => 'integer', 'value' => $DteRecibido->iva_uso_comun, 'help' => 'Si el IVA es de uso común aquí va el factor de proporcionalidad']);
echo $f->input(['type' => 'select', 'name' => 'iva_no_recuperable', 'label' => 'IVA no recuperable', 'options' => ['' => 'El IVA es recuperable'] + $iva_no_recuperables, 'value' => $DteRecibido->iva_no_recuperable]);
echo $f->input(['type' => 'select', 'name' => 'impuesto_adicional', 'label' => 'Impuesto adicional', 'options' => ['' => 'Sin impuesto adicional'] + $impuesto_adicionales, 'value' => $DteRecibido->impuesto_adicional]);
echo $f->input(['name' => 'impuesto_adicional_tasa', 'label' => 'Tasa Imp. adic.', 'value' => $DteRecibido->impuesto_adicional_tasa, 'check' => 'integer', 'help' => 'Tasa del impuesto adicional (obligatorio si hay impuesto adicional)']);
echo $f->input(['type' => 'select', 'name' => 'impuesto_tipo', 'label' => 'Tipo de impuesto', 'value' => $DteRecibido->impuesto_tipo, 'options' => [1 => 'IVA', 2 => 'Ley 18211']]);
echo $f->input(['type' => 'checkbox', 'name' => 'anulado', 'checked' => $DteRecibido->anulado == 'A' ? true : false, 'label' => '¿Anulado?']);
echo $f->input(['name' => 'impuesto_sin_credito', 'label' => 'Impuesto sin crédito', 'value' => $DteRecibido->impuesto_sin_credito, 'check' => 'integer']);
echo $f->input(['name' => 'monto_activo_fijo', 'label' => 'Monto activo fijo', 'value' => $DteRecibido->monto_activo_fijo, 'check' => 'integer']);
echo $f->input(['name' => 'monto_iva_activo_fijo', 'label' => 'IVA activo fijo', 'value' => $DteRecibido->monto_iva_activo_fijo, 'check' => 'integer']);
 /**
  * Método que corrige los datos de los contribuyentes existentes, cargando:
  *  - razon social
  *  - giro
  *  - actividad económica
  * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
  * @version 2015-12-31
  */
 private function corregir()
 {
     $db =& \sowerphp\core\Model_Datasource_Database::get();
     $contribuyentes = $db->getCol('
         SELECT rut
         FROM contribuyente
         WHERE
             usuario IS NULL
             AND (
                 giro IS NULL
                 OR actividad_economica IS NULL
                 OR REPLACE(razon_social, \'.\', \'\') = ' . $db->concat('rut', '-', 'dv') . '
             )
     ');
     $registros = num(count($contribuyentes));
     $procesados = 0;
     $actualizados = 0;
     foreach ($contribuyentes as $rut) {
         $Contribuyente = new \website\Dte\Model_Contribuyente($rut);
         $response = \sowerphp\core\Network_Http_Socket::get('https://sasco.cl/api/servicios/enlinea/sii/actividad_economica/' . $Contribuyente->rut . '/' . $Contribuyente->dv);
         if ($response['status']['code'] == 200) {
             $info = json_decode($response['body'], true);
             $procesados++;
             if ($this->verbose) {
                 $this->out('Procesando ' . num($procesados) . '/' . $registros . ': contribuyente ' . $Contribuyente->rut . '-' . $Contribuyente->dv);
             }
             $cambios = false;
             if ($Contribuyente->razon_social == \sowerphp\app\Utility_Rut::addDV($Contribuyente->rut) and !empty($info['razon_social'])) {
                 $Contribuyente->razon_social = substr($info['razon_social'], 0, 100);
                 $cambios = true;
             }
             if (!$Contribuyente->actividad_economica and !empty($info['actividades'][0]['codigo'])) {
                 $Contribuyente->actividad_economica = $info['actividades'][0]['codigo'];
                 $cambios = true;
             }
             if (!$Contribuyente->giro and !empty($info['actividades'][0]['glosa'])) {
                 $Contribuyente->giro = substr($info['actividades'][0]['glosa'], 0, 80);
                 $cambios = true;
             }
             if ($cambios) {
                 try {
                     if ($Contribuyente->save()) {
                         $actualizados++;
                     }
                 } catch (\sowerphp\core\Exception_Model_Datasource_Database $e) {
                 }
             }
         }
     }
     $this->out('Se actualizaron ' . num($actualizados) . ' contribuyentes de un total de ' . $registros);
 }
Example #7
0
 /**
  * Método que genera el formulario de la configuración del módulo
  * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
  * @version 2016-01-30
  */
 private function displayForm()
 {
     // Get default language
     $default_lang = (int) Configuration::get('PS_LANG_DEFAULT');
     // campos del formulario
     $fields_form[0]['form'] = ['legend' => ['title' => $this->l('Configuración básica')], 'input' => [['type' => 'text', 'label' => $this->l('URL LibreDTE'), 'name' => 'LIBREDTE_URL', 'size' => 255, 'required' => true], ['type' => 'text', 'label' => $this->l('RUT contribuyente'), 'name' => 'LIBREDTE_CONTRIBUYENTE', 'size' => 12, 'required' => true], ['type' => 'text', 'label' => $this->l('Hash usuario'), 'name' => 'LIBREDTE_PREAUTH_HASH', 'size' => 32, 'required' => true]], 'submit' => ['title' => $this->l('Save'), 'class' => 'button']];
     $helper = new HelperForm();
     // módulo, token e índice actual
     $helper->module = $this;
     $helper->name_controller = $this->name;
     $helper->token = Tools::getAdminTokenLite('AdminModules');
     $helper->currentIndex = AdminController::$currentIndex . '&configure=' . $this->name;
     // idioma
     $helper->default_form_language = $default_lang;
     $helper->allow_employee_form_lang = $default_lang;
     // título y barra de herramientas
     $helper->title = $this->displayName;
     $helper->show_toolbar = true;
     $helper->toolbar_scroll = true;
     $helper->submit_action = 'submit' . $this->name;
     $helper->toolbar_btn = ['save' => ['desc' => $this->l('Save'), 'href' => AdminController::$currentIndex . '&configure=' . $this->name . '&save' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules')], 'back' => ['href' => AdminController::$currentIndex . '&token=' . Tools::getAdminTokenLite('AdminModules'), 'desc' => $this->l('Back to list')]];
     // asignar valores para el formulario y entregar vista
     foreach ($this->defaultConfig as $key => $value) {
         $helper->fields_value[$key] = Configuration::get($key);
     }
     if ($helper->fields_value['LIBREDTE_CONTRIBUYENTE']) {
         $helper->fields_value['LIBREDTE_CONTRIBUYENTE'] = \sowerphp\app\Utility_Rut::addDV($helper->fields_value['LIBREDTE_CONTRIBUYENTE']);
     }
     return $helper->generateForm($fields_form);
 }
 /**
  * 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;
     }
 }