* Copyright (C) 2023 SuperAdmin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file cfdimx/admin/emisores.php * \ingroup cfdimx * \brief Emisores page of module CFDIMX. */ // Load Dolibarr environment $res = 0; // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined) if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) { $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php"; } // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1; while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; } if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) { $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php"; } if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) { $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php"; } // Try main.inc.php using relative path if (!$res && file_exists("../../main.inc.php")) { $res = @include "../../main.inc.php"; } if (!$res && file_exists("../../../main.inc.php")) { $res = @include "../../../main.inc.php"; } if (!$res && file_exists("../../../../main.inc.php")) { $res = @include "../../../../main.inc.php"; } if (!$res) { die("Include of main fails"); } // Libraries require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; dol_include_once('/cfdimx/class/admin.class.php'); dol_include_once('/cfdimx/class/societe.class.php'); dol_include_once('/cfdimx/lib/cfdimxadmin.lib.php'); // Translations $langs->loadLangs(array("errors", "admin", "cfdimx@cfdimx")); // Access control if (!$user->admin) { accessforbidden(); } // Parameters $action = GETPOST('action', 'aZ09'); $backtopage = GETPOST('backtopage', 'alpha'); $config = new ConfiguracionCFDIMX($db); $societe = new SocieteCFDIMX($db); /* * Actions */ if($action == "confirm_emisor"){ $tipo_operacion = GETPOST("tipo_operacion"); if(in_array($tipo_operacion, array(1, 2, 3))){ $emisor = array( "rfc" => GETPOST('rfc'), "regimen_fiscal" => GETPOST('regimen'), "razon_social" => GETPOST('nombre'), "direccion" => GETPOST('direccion'), "huso_horario" => GETPOST('huso_horario'), "rowid" => GETPOST("rowid"), "delmpio" => GETPOST('delmpio'), "clave_mpio" => GETPOST('clave_mpio'), "colonia" => GETPOST('colonia'), "clave_col" => GETPOST('clave_col'), "calle" => GETPOST('calle'), "noext" => GETPOST('noext'), "noint" => GETPOST('noint'), "predeterminado" => GETPOST('predeterminado') ); $config->emisores_info = $emisor; if($tipo_operacion == 1 && GETPOST("rowid") == -1){ $res = $config->createEmisor($user); if($res > 0){ setEventMessage("Se agrego correctamente el Emisor.", 'mesgs'); }else{ setEventMessage($config->errors, 'errors'); } } if($tipo_operacion == 2 && GETPOST("rowid") > 0){ $res = $config->updateEmisor($user); if($res > 0){ setEventMessage("Se actualizo correctamente el Emisor.", 'mesgs'); }else{ setEventMessage($config->errors, 'errors'); } } if($tipo_operacion == 3 && GETPOST("rowid") > 0){ $res = $config->deleteEmisor($user); if($res > 0){ setEventMessage("Se elimino correctamente el Emisor.", 'mesgs'); }else{ setEventMessage($config->errors, 'errors'); } } header("Location: ".$_SERVER['PHP_SELF']); exit(); } } if($action == 'confirm_predeterminado'){ $valor = (GETPOST('valor') == 1 ? 0 : 1); $rowid = GETPOST('rowid'); $res = $config->estatusEmisor($rowid, $valor); if($res > 0){ setEventMessage("Se actulizo correctamente el Emisor Predeterminado.", 'mesgs'); }else{ setEventMessage($config->errors, 'errors'); } header("Location: ".$_SERVER['PHP_SELF']); exit(); } /* * View */ $num_emisores = $config->fetchEmisores(); $lista_regimenes = $societe->getInfoCatalogos(2); $lista_husohorarios = $societe->getInfoCatalogos(3); if($num_emisores == 0){ $action = "emisor"; } $form = new Form($db); $help_url = ''; $page_name = "CFDIMX - Emisores"; $arrayofjs = array('/cfdimx/js/cfdimx.js.php'); llxHeader('', $langs->trans($page_name), $help_url, '', 0, 0, $arrayofjs); // Subheader $linkback = ''.$langs->trans("BackToModuleList").''; print load_fiche_titre($langs->trans($page_name), $linkback, 'group'); // Configuration header $head = cfdimxAdminPrepareHead(); print dol_get_fiche_head($head, 'cfdimx', $langs->trans($page_name), 0, 'tools'); $head = cfdimxAdminConfigPrepareHead(); print dol_get_fiche_head($head, 'emisores', $langs->trans($page_name), 0, 'group'); $formconfirm = ''; if($action == "emisor"){ $formquestion = array(); $tipo_operacion = GETPOST("tipo_operacion"); $rowid = (GETPOST("rowid") != "" ? GETPOST("rowid") : -1); $label_emisor = ($rowid == -1 ? $langs->trans('AddEmisor') : $langs->trans("UpdateEmisor")); $info_detail = $config->getLabelEmisor($rowid); if(in_array($tipo_operacion, array(1, 2)) || $rowid == -1){ if($rowid == -1){ $tipo_operacion = 1; $config->emisores_info["predeterminado"] = 0; } $label_direccion = "Dirección ".img_picto('', 'state'); $label_codmpio = "Código Municipio ".$form->textwithpicto('', $langs->trans("CodMpio"), 1, 'help', '', 0, 3); $label_codcolonia = "Código Colonia ".$form->textwithpicto('', $langs->trans("CodColonia"), 1, 'help', '', 0, 3); $label_calle = "Calle ".img_picto('', 'fa-road'); $label_husohorario = "Huso Horario ".img_picto('', 'fa-clock-o'); $formquestion = array( array('type' => 'hidden', 'name' => 'tipo_operacion', 'value' => $tipo_operacion), array('type' => 'hidden', 'name' => 'rowid', 'value' => $rowid), array('type' => 'hidden', 'name' => 'predeterminado', 'value' => $config->emisores_info["predeterminado"]), array('type' => 'text', 'name' => 'rfc', 'label' => 'R.F.C.', 'value' => $config->emisores_info["MAIN_INFO_SIREN"], 'tdclass' => 'fieldrequired', 'moreattr' => 'required placeholder="EKU9003173C9"'), array('type' => 'text', 'name' => 'nombre', 'label' => 'Nombre', 'value' => $config->emisores_info["CFDIMX_RAZON_SOCIAL"], 'tdclass' => 'fieldrequired', 'moreattr' => 'required placeholder="Esucela Kemper"'), array('type' => 'select', 'name' => 'regimen', 'label' => 'Régimen Fiscal','default' => $config->emisores_info["CFDIMX_REGIMEN_FISCAL"], 'values' => $lista_regimenes, 'tdclass' => 'fieldrequired', 'moreattr' => 'required', 'morecss' => 'minwidth500', 'select_show_empty' => 'Selecciona Régimen Fiscal'), array('type' => 'text', 'name' => 'direccion', 'label' => $label_direccion, 'value' => $config->emisores_info["CFDIMX_DIRECCION"], 'tdclass' => 'fieldrequired', 'moreattr' => 'required placeholder="Direccion 12, cale 2"'), array('type' => 'text', 'name' => 'delmpio', 'label' => 'Delegación/Municipio', 'value' => $config->emisores_info["delmpio"], 'moreattr' => ' placeholder="Miguel Hidalgo"'), array('type' => 'text', 'name' => 'clave_mpio', 'label' => $label_codmpio, 'value' => $config->emisores_info["clave_mpio"], 'moreattr' => 'placeholder="123"'), array('type' => 'text', 'name' => 'colonia', 'label' => 'Colonia', 'value' => $config->emisores_info["colonia"], 'moreattr' => 'placeholder="Robles 12"'), array('type' => 'text', 'name' => 'clave_col', 'label' => $label_codcolonia, 'value' => $config->emisores_info["clave_col"], 'moreattr' => 'placeholder="Robles 12"'), array('type' => 'text', 'name' => 'calle', 'label' => $label_calle, 'value' => $config->emisores_info["calle"], 'moreattr' => 'placeholder="Robles 12"'), array('type' => 'text', 'name' => 'noext', 'label' => 'No. Exterior', 'value' => $config->emisores_info["noext"], 'moreattr' => 'placeholder="29212"'), array('type' => 'text', 'name' => 'noint', 'label' => 'No. Interior', 'value' => $config->emisores_info["noint"], 'moreattr' => 'placeholder="12"'), array('type' => 'select', 'name' => 'huso_horario', 'label' => $label_husohorario, 'default' => $config->emisores_info["CFDIMX_HUSO_HORARIO"], 'values' => $lista_husohorarios, 'tdclass' => 'fieldrequired', 'moreattr' => 'required', 'morecss' => 'minwidth500', 'select_show_empty' => 'Selecciona Huso Horario'), ); }else{ if($tipo_operacion == 4){ $label_emisor = $langs->trans('ViewEmisor'); $formquestion = array( array('type' => 'hidden', 'name' => 'tipo_operacion', 'value' => $tipo_operacion), array('type' => 'hidden', 'name' => 'rowid', 'value' => $rowid), array('type' => 'onecolumn', 'value' => $info_detail) ); }else{ $label_emisor = $langs->trans('DeleteEmisor'); $formquestion = array( array('type' => 'hidden', 'name' => 'tipo_operacion', 'value' => $tipo_operacion), array('type' => 'hidden', 'name' => 'rowid', 'value' => $rowid), array('type' => 'onecolumn', 'value' => '¿Estas seguro de Eliminar la Informacíón del Emisor?'), array('type' => 'onecolumn', 'value' => $info_detail) ); } } $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"], $label_emisor, '', 'confirm_emisor', $formquestion, 1, 1, 480, 750); } print $formconfirm; if($num_emisores > 0){ print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; foreach ($config->emisores_list as $key => $value) { print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; } print '
#EstatusR.F.C.NombreRégimen Fiscal 
'.($key+1).''; if($conf->global->CFDIMX_ADMIN_LISTA_EMISORES == 0 || $value->predeterminado == 1){ print img_picto('Emisor('.$value->emisor_rfc.') Activo', 'switch_on'); }else{ $url = $_SERVER['PHP_SELF'].'?action=confirm_predeterminado&rowid='.$value->rowid.'&valor='.$value->predeterminado; if((int)DOL_VERSION > 15){ $url .= "&token=".newToken(); } $icono_boton = ($value->predeterminado == 1 ? 'switch_on' : 'switch_off'); $label_boton = ($value->predeterminado == 0 ? 'Activar Emisor ('.$value->emisor_rfc.')' : 'Desactivar Emisor ('.$value->emisor_rfc.')'); print ''; print img_picto($label_boton, $icono_boton); print ''; } print ''.$value->emisor_rfc.''.$value->razon_social.''.$lista_regimenes[$value->regimen].''; $url_view = $_SERVER['PHP_SELF'].'?action=emisor&rowid='.$value->rowid.'&tipo_operacion=4'; if((int)DOL_VERSION > 15){ $url_view .= "&token=".newToken(); } print ''; print ''; print ''; print '  '; $url_update = $_SERVER['PHP_SELF'].'?action=emisor&rowid='.$value->rowid.'&tipo_operacion=2'; if((int)DOL_VERSION > 15){ $url_update .= "&token=".newToken(); } print ''; print ''; print ''; print '  '; if($conf->global->CFDIMX_ADMIN_LISTA_EMISORES == 1 && $num_emisores > 1 && $value->predeterminado == 0){ $url_delete = $_SERVER['PHP_SELF'].'?action=emisor&rowid='.$value->rowid.'&tipo_operacion=3'; if((int)DOL_VERSION > 15){ $url_delete .= "&token=".newToken(); } print ''; print ''; print ''; } print '
'; if($conf->global->CFDIMX_ADMIN_LISTA_EMISORES == 1){ print '
'; $url = $_SERVER['PHP_SELF'].'?&action=emisor&tipo_operacion=1'; if((int)DOL_VERSION > 15){ $url .= "&token=".newToken(); } print ''; print ''; print ' Nuevo emisor'; print ''; print '
'; } print '
'; } // Page end print dol_get_fiche_end(); llxFooter(); $db->close();