* 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 facture/card_cfdirel.php * \ingroup auriboxconsulting */ // 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) { 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'; require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; dol_include_once('/cfdimx/lib/complementos.lib.php'); dol_include_once('/cfdimx/class/complementos.class.php'); // Translations $langs->loadLangs(array("errors", "admin", "cfdimx@cfdimx")); $zona_horaria = $conf->global->CFDIMX_HUSO_HORARIO; date_default_timezone_set($zona_horaria); // Access control if (!$user->rights->cfdimx->add_comp_cfdi_rel){ accessforbidden(); } // Parameters $id = GETPOST('id', 'int'); $id_cfdi_rel = GETPOST('id_cfdi_rel','int'); $action = GETPOST('action', 'aZ09'); $backtopage = GETPOST('backtopage', 'alpha'); $object = new ComplementosCFDIMX($db, $id); /* * Actions */ if($action == "updateTipoRel"){ $res = $object->updateTipoRelacion($id, trim(GETPOST("options_cfdidoctiporelacion"))); if($res > 0){ setEventMessage("Se actualizo correctamente el Tipo Relación.", 'mesgs'); }else{ setEventMessage("Error: No se actualizo correctamente el Tipo Relación.", 'errors'); } } if($action == "add_uuid"){ $res = $object->addCFDIRel($id, trim(GETPOST("uuid"))); if($res > 0){ setEventMessage("Se agrego correctamente la Factura seleccionada.", 'mesgs'); }else{ setEventMessage($object->errors, 'errors'); } } if($action == "updatecfdirel"){ $res = $object->updateCFDIRel($id, trim(GETPOST("uuid")), $id_cfdi_rel); if($res > 0){ setEventMessage("Se actualizo correctamente el UUID seleccionado.", 'mesgs'); }else{ setEventMessage($object->errors, 'errors'); } } if($action == "deletecfdirel"){ $res = $object->deleteCFDIRel($id, trim(GETPOST("uuid")), $id_cfdi_rel); if($res > 0){ setEventMessage("Se elimino correctamente el UUID seleccionado.", 'mesgs'); }else{ setEventMessage($object->errors, 'errors'); } } /* * View */ $form = new Form($db); $facture = new Facture($db); $extrafields = new ExtraFields($db); $extrafields->fetch_name_optionals_label($facture->table_element); $facture->fetch($id); $object->fetchCFDIRelacionados($id); $estatus = $object->estatusFactura($id); $help_url = ''; $title_page = $langs->trans("cfdirel")." - ".$facture->getNomUrl(1); $page_name = $langs->trans("cfdirel")." - ".$facture->ref; $arrayofjs = array('/cfdimx/js/complementoscfdimx.js.php'); llxHeader('', $langs->trans($page_name), $help_url, '', 0, 0, $arrayofjs); // Subheader // $linkback = ''.$langs->trans("BackToModuleList").''; $linkback = ''; print load_fiche_titre($langs->trans($title_page), $linkback, 'bill'); // Configuration header $head = cfdimxComplementosPrepareHead(); print dol_get_fiche_head($head, 'cfdirel', $langs->trans($title_page), 0, 'bill'); print '
'; print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
'; print ''; print ' '; print 'Datos del Comprobante'; print '
'; print 'Tipo Relación'; print ''; print '
'; if((int)DOL_VERSION > 15){ print ''; } print ''; print $extrafields->showInputField('cfdidoctiporelacion', $facture->array_options["options_cfdidoctiporelacion"], '', '', '', 0, $facture->id, $facture->table_element); print ''; print '
'; print '
'; print '
'; print '
'; $num_cfdirel = count($object->lista_cfdirel); print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; if($num_cfdirel > 0){ $i = 1; $token = ""; if((int)DOL_VERSION > 15){ $token = newToken(); } foreach ($object->lista_cfdirel as $key => $value) { $facture_static = new Facture($db); $label_facture = "Factura Externa"; $tipo_facture = 1; if(!is_null($value["facid"]) && !empty($value["facid"]) && $value["facid"] > 0){ $facture_static->fetch($value["facid"]); $label_facture = $facture_static->getNomUrl(1); $tipo_facture = 2; } print ''; print ''; print ''; if($estatus == 0){ if($action == "update"){ print ''; }else{ print ''; $url_update = $_SERVER['PHP_SELF'].'?id='.$id.'&id_cfdi_rel='.$value["id"].'&action=update&token='.$token; print ''; $url_delete = $_SERVER['PHP_SELF'].'?id='.$id.'&id_cfdi_rel='.$value["id"].'&uuid='.$value["uuid"].'&action=deletecfdirel&token='.$token; print ''; } }else{ print ''; } print ''; $i++; } }else{ print ''; print ''; print ''; } print '
'; print ''; print ' '; print 'UUID Relacionados ('.$num_cfdirel.')'; print '
#FacturaUUID 
'.$i.''.$label_facture.''; print '
'; if((int)DOL_VERSION > 15){ print ''; } print ''; print ''; print ''; print ''; print '
'; print '
'.$value["uuid"].''; if($tipo_facture == 1){ print ''; print ''; print ''; }else{ print ' '; } print ''; print ''; print ''; print ''; print ' 
'; print 'Ningún UUID Relacionado.'; print '
'; print '
'; print '
'; print '
'; print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; // print ''; // print '<´ $object->fetchFacturasRel($fecha_actual, $fecha_final); print ''; print ''; print '
'; print ''; print ' '; print 'Factura Dolibarr'; print '
'; $fecha_actual = (GETPOST("fecha_inicio") != "" ? GETPOST("fecha_inicio") : date("Y-m-d")); $fecha_final = (GETPOST("fecha_final") != "" ? GETPOST("fecha_final") : date("Y-m-d")); // $fecha_actual = "2023-05-05"; print '
'; if((int)DOL_VERSION > 15){ print ''; } // print ''; print 'Fecha Inicio: '; print '   '; print 'Fecha Final: '; print ''; print '
'; print '
3'; if(count($object->lista_factrel) > 0){ print '
'; if((int)DOL_VERSION > 15){ print ''; } print ''; print $form->selectarray('uuid', $object->lista_factrel, $uuid, 'Selecciona Factura', 0, 0, '', 0, 0, 0, '', 'minwidth400'); print ''; print '
'; }else{ print 'Ningún Factura encontrada, intenta cambiando los Rangos de Fecha.'; } print '
'; print '
'; print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
'; print ''; print ' '; print 'Factura Externa'; print '
'; print '
'; if((int)DOL_VERSION > 15){ print ''; } print ''; print ''; print ''; print '
'; print '
'; print '
'; print '
'; // Page end print dol_get_fiche_end(); llxFooter(); $db->close();