db = $db;
}
public function getInfoCatalogos($tipo){
global $langs;
$informacion = array();
$sql = "";
switch ($tipo) {
case 1:
$sql = "SELECT * FROM ".MAIN_DB_PREFIX."c_cfdimx_pais WHERE active = 1";
break;
case 2:
$sql = "SELECT * FROM ".MAIN_DB_PREFIX."c_cfdimx_regimen_f WHERE active = 1";
break;
case 3:
$sql = "SELECT * FROM ".MAIN_DB_PREFIX."c_cfdimx_husoh WHERE active = 1";
break;
default:
$sql = "";
break;
}
$resql = $this->db->query($sql);
if($resql){
$num = $this->db->num_rows($resql);
$i = 0;
while($i < $num){
$obj = $this->db->fetch_object($resql);
if($tipo == 3){
$informacion[$obj->label] = $langs->trans($obj->label);
}else{
$informacion[$obj->code] = $obj->code." - ".$obj->label;
}
$i++;
}
}
return $informacion;
}
public function getValueCatalogo($codigo, $diccionario){
$etiqueta = "";
switch($diccionario){
case 1:
$sql = "SELECT * FROM ".MAIN_DB_PREFIX."c_cfdimx_regimen_f WHERE code = '".$codigo."'";
break;
}
$res_sql = $this->db->query($sql);
if($res_sql){
$i = 0 ;
$num = $this->db->num_rows($res_sql);
while ($i < $num){
$obj = $this->db->fetch_object($res_sql);
$etiqueta = $obj->code." - ".$obj->label;
if(dol_strlen($etiqueta) < 50){
$etiqueta = dol_substr($etiqueta, 0, 50);
}
$i++;
}
}
return $etiqueta;
}
public function validacionesDomicilio(){
$this->validaciones = null;
$num_validaciones = 0;
if($this->rfc == '' || $this->rfc == null){
$this->validaciones[] = 'El Campo RFC esta vacio y es obligatorio.';
$num_validaciones++;
}else{
$this->rfc = mb_strtoupper($this->rfc);
}
if($this->nombre == '' || $this->nombre == null){
$this->validaciones[] = 'El Campo Nombre esta vacio y es obligatorio.';
$num_validaciones++;
}else{
$this->nombre = mb_strtoupper($this->nombre);
}
if($this->cp == '' || $this->cp == null){
$this->validaciones[] = 'El Campo Domicilio Fiscal esta vacio y es obligatorio.';
$num_validaciones++;
}
if($this->regimen == -1 || $this->regimen == '' || $this->regimen == null){
$this->validaciones[] = 'El Campo Régimen Fiscal esta vacio y es obligatorio.';
$num_validaciones++;
}
if(strcmp($this->rfc, "XEXX010101000") != 0){
$this->residencia_fiscal = '';
$this->numregidtrib = '';
}
if($this->residencia_fiscal != '' && $this->numregidtrib == ''){
$this->residencia_fiscal = '';
$this->numregidtrib = '';
}
if($this->label != ''){
if(dol_strlen($this->label) > 21){
$this->validaciones[] = 'El Campo Etiqueta tiene mas caracteres de los permitidos.';
$num_validaciones++;
}
}
if($this->email != ''){
$list_tmp_correos = explode(';', $this->email);
if(count($list_tmp_correos) > 0){
for($i = 0; $i < count($list_tmp_correos); $i++){
if (!filter_var($list_tmp_correos[$i], FILTER_VALIDATE_EMAIL)) {
$this->validaciones[] = 'El correo ('.$list_tmp_correos[$i].') no es valido.';
$num_validaciones++;
}
}
}else{
$this->validaciones[] = 'El Campo Correo no contiene un correo valido.';
$num_validaciones++;
}
}
return $num_validaciones;
}
public function createDomicilio(User $user){
global $conf;
$error = 1;
$sql = "INSERT INTO ".MAIN_DB_PREFIX."cfdimx_domicilio_fiscal_receptor";
$sql .= " (";
$sql .= " fk_soc, entity_id, rfc, nombre, regimenfiscal, numregidtrib, direccion, cp, municipio, estado, pais, estatus,";
$sql .= " residencia_fiscal, calle, clave_mpio, noint, noext, clave_col, etiqueta, correo_automatico";
$sql .= " )";
$sql .= " VALUES";
$sql .= " (";
$sql .= "'".($this->fk_soc != '' ? $this->fk_soc : -1)."',";
$sql .= "'".$conf->entity."',";
$sql .= (trim($this->rfc) != '' ? "'".trim($this->db->escape($this->rfc))."'" : "NULL").",";
$sql .= (trim($this->nombre) != '' ? "'".trim($this->db->escape($this->nombre))."'" : "NULL").",";
$sql .= (trim($this->regimen) != '' ? "'".trim($this->regimen)."'" : "NULL").",";
$sql .= (trim($this->numregidtrib) != '' ? "'".trim($this->numregidtrib)."'" : "NULL").",";
$sql .= (trim($this->direccion) != '' ? "'".trim($this->db->escape($this->direccion))."'" : "NULL").",";
$sql .= (trim($this->cp) != '' ? "'".trim($this->cp)."'" : "NULL").",";
$sql .= (trim($this->municipio) != '' ? "'".trim($this->db->escape($this->municipio))."'" : "NULL").",";
$sql .= (trim($this->estado) != '' ? "'".trim($this->db->escape($this->estado))."'" : "NULL").",";
$sql .= (trim($this->pais) != '' ? "'".trim($this->pais)."'" : "NULL").",";
$sql .= (trim($this->estatus) != '' ? "'".trim($this->estatus)."'" : 0).",";
$sql .= (trim($this->residencia_fiscal) != '' ? "'".trim($this->residencia_fiscal)."'" : "NULL").",";
$sql .= (trim($this->cce_calle) != '' ? "'".trim($this->db->escape($this->cce_calle))."'" : "NULL").",";
$sql .= (trim($this->cce_clave_mpio) != '' ? "'".trim($this->cce_clave_mpio)."'" : "NULL").",";
$sql .= (trim($this->cce_noint) != '' ? "'".trim($this->cce_noint)."'" : "NULL").",";
$sql .= (trim($this->cce_noext) != '' ? "'".trim($this->cce_noext)."'" : "NULL").",";
$sql .= (trim($this->cce_clave_col) != '' ? "'".trim($this->cce_clave_col)."'" : "NULL").",";
$sql .= (trim($this->label) != '' ? "'".trim($this->label)."'" : "NULL").",";
$sql .= (trim($this->email) != '' ? "'".trim($this->email)."'" : "NULL");
$sql .= " );";
// print $sql;
$resql = $this->db->query($sql);
if(!$resql){
$this->errors[] = "Error: No se pudo agregar la información del domicilio fiscal.";
$this->errors[] = "SQL GENERADO :: ".$sql;
// $this->errors[] = dol_print_error($this->db);
$error = -1;
}
return $error;
}
public function updateDomicilio(User $user){
$error = 1;
$sql = "UPDATE ".MAIN_DB_PREFIX."cfdimx_domicilio_fiscal_receptor";
$sql .= " SET ";
$sql .= " rfc = ".(trim($this->rfc) != '' ? "'".trim($this->db->escape($this->rfc))."'" : "NULL").",";
$sql .= " nombre = ".(trim($this->nombre) != '' ? "'".trim($this->db->escape($this->nombre))."'" : "NULL").",";
$sql .= " regimenfiscal = ".(trim($this->regimen) != '' ? "'".trim($this->regimen)."'" : "NULL").",";
$sql .= " numregidtrib = ".(trim($this->numregidtrib) != '' ? "'".trim($this->numregidtrib)."'" : "NULL").",";
$sql .= " direccion = ".(trim($this->direccion) != '' ? "'".trim($this->db->escape($this->direccion))."'" : "NULL").",";
$sql .= " cp = ".(trim($this->cp) != '' ? "'".trim($this->cp)."'" : "NULL").",";
$sql .= " municipio = ".(trim($this->municipio) != '' ? "'".trim($this->db->escape($this->municipio))."'" : "NULL").",";
$sql .= " estado = ".(trim($this->estado) != '' ? "'".trim($this->db->escape($this->estado))."'" : "NULL").",";
$sql .= " pais = ".(trim($this->pais) != '' ? "'".trim($this->pais)."'" : "NULL").",";
$sql .= " residencia_fiscal = ".(trim($this->residencia_fiscal) != '' ? "'".trim($this->residencia_fiscal)."'" : "NULL").",";
$sql .= " calle = ".(trim($this->cce_calle) != '' ? "'".trim($this->db->escape($this->cce_calle))."'" : "NULL").",";
$sql .= " clave_mpio = ".(trim($this->cce_clave_mpio) != '' ? "'".trim($this->cce_clave_mpio)."'" : "NULL").",";
$sql .= " noint = ".(trim($this->cce_noint) != '' ? "'".trim($this->cce_noint)."'" : "NULL").",";
$sql .= " noext = ".(trim($this->cce_noext) != '' ? "'".trim($this->cce_noext)."'" : "NULL").",";
$sql .= " clave_col = ".(trim($this->cce_clave_col) != '' ? "'".trim($this->cce_clave_col)."'" : "NULL").",";
$sql .= " etiqueta = ".(trim($this->label) != '' ? "'".trim($this->label)."'" : "NULL").",";
$sql .= " correo_automatico = ".(trim($this->email) != '' ? "'".trim($this->email)."'" : "NULL");
$sql .= " WHERE rowid = ".$this->rowid;
$resql = $this->db->query($sql);
// print $sql;
if(!$resql){
$this->errors[] = "Error: No se pudo actualizar la información del domicilio fiscal.";
$this->errors[] = "SQL GENERADO :: ".$sql;
$error = -1;
}
return $error;
}
public function fetchDomicilio($id_domicilio = 0, $id_cliente = 0){
global $conf;
$condiciones = array();
$sql = "SELECT * FROM ".MAIN_DB_PREFIX."cfdimx_domicilio_fiscal_receptor";
$condiciones[] = " entity_id = ".$conf->entity;
if($id_domicilio > 0){
$condiciones[] = " rowid = ".$id_domicilio;
}
if($id_cliente > 0){
$condiciones[] = " fk_soc = ".$id_cliente;
}
if(is_array($condiciones) && count($condiciones) > 0){
$sql .= " WHERE";
$sql .= implode(" AND ", $condiciones);
}else{
$sql .= " LIMIT 1";
}
$resql = $this->db->query($sql);
if($resql){
$obj = $this->db->fetch_object($resql);
$this->fk_soc = $obj->fk_soc;
$this->entity = $obj->entity_id;
$this->label = $obj->etiqueta;
$this->email = $obj->correo_automatico;
$this->rfc = $obj->rfc;
$this->nombre = $obj->nombre;
$this->cp = $obj->cp;
$this->regimen = $obj->regimenfiscal;
$this->residencia_fiscal = $obj->residencia_fiscal;
$this->numregidtrib = $obj->numregidtrib;
$this->direccion = $obj->direccion;
$this->municipio = $obj->municipio;
$this->estado = $obj->estado;
$this->pais = $obj->pais;
$this->cce_clave_mpio = $obj->clave_mpio;
$this->cce_clave_col = $obj->clave_col;
$this->cce_calle = $obj->calle;
$this->cce_noext = $obj->noext;
$this->cce_noint = $obj->noint;
$this->estatus = $obj->estatus;
}
}
public function fetchDomicilios($id_domicilio = 0, $id_cliente = 0){
}
public function getNumDomicilios($cliente_id, $filtro = 0){
global $conf;
$num_domicilios = 0;
$this->lista_domicilios = null;
//Se busca si tiene domicilios guardados
$sql_domicilios = "SELECT * FROM ".MAIN_DB_PREFIX."cfdimx_domicilio_fiscal_receptor";
$sql_domicilios .= " WHERE fk_soc = ".$cliente_id." AND entity_id = ".$conf->entity;
if($filtro > 0){
$sql_domicilios .= " AND estatus = 1";
}
$res_sql_domicilios = $this->db->query($sql_domicilios);
$num_domicilios = $this->db->num_rows($res_sql_domicilios);
if($num_domicilios > 0){
while ($domicilio = $this->db->fetch_object($res_sql_domicilios)) {
$this->lista_domicilios[] = $domicilio;
}
}
return $num_domicilios;
}
public function getNomUrlDomicilio($cliente_id, $domicilio_id, $withpicto = 0, $option = '', $max = 0, $short = 0, $moretitle = '', $notooltip = 0, $addlinktonotes = 0, $save_lastsearch_value = -1, $target = ''){
global $db, $langs, $conf, $user, $mysoc;
// $factura = new Facture($db);
// $factura->fetch($facid);
// $domicilio = $this->getDomicilioFiscalCliente($cliente_id, $domicilio_id);
$this->fetchDomicilio($domicilio_id, $cliente_id);
if (!empty($conf->dol_no_mouse_hover)) {
$notooltip = 1; // Force disable tooltips
}
$result = '';
$url = $_SERVER["PHP_SELF"].'?socid='.$cliente_id.'&action=view';
if ($option !== 'nolink') {
// Add param to save lastsearch_values or not
$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
$add_save_lastsearch_values = 1;
}
if ($add_save_lastsearch_values) {
$url .= '&save_lastsearch_values=1';
}
}
if ($short) {
return $url;
}
$picto = 'contact';
$label = img_picto('', $picto).' Domicilio Fiscal';
if($this->estatus == 1){
$label .= 'Activo';
}else{
$label .= 'No Activo';
}
if($this->label != ""){
$label .= "
Etiqueta: ".$this->label;
}
if($this->rfc != ""){
$label .= "
R.F.C.: ".$this->rfc;
}
if($this->nombre != ""){
$label .= "
Nombre: ".$this->nombre;
}
if($this->regimen != ""){
$label .= "
Régimen Fiscal: ".$this->getValueCatalogo($this->regimen, 1);
}
if($this->cp != ""){
$label .= "
Domicilio Fiscal (C.P.): ".$this->cp;
}
if($this->residencia_fiscal != ""){
$label .= "
Residencia Fiscal: ".$this->residencia_fiscal;
}
if($this->numregidtrib != ""){
$label .= "
NumRegIdTrib: ".$this->numregidtrib;
}
if($this->direccion != ""){
$label .= "
Dirección: ".$this->direccion;
}
if($this->municipio != ""){
$label .= "
Municipio: ".$this->municipio;
}
if($this->estado != ""){
$label .= "
Estado: ".$this->estado;
}
if($this->pais != "" && $this->pais != -1){
$label .= "
País: ".$this->pais;
}
if($this->email != ""){
$label .= "
Correo: ".$this->email;
}
if($this->cce_clave_mpio != "" || $this->cce_clave_col != "" || $this->cce_calle != "" ||
$this->cce_noint != "" || $this->cce_noext != ""){
$label .= "
".img_picto('', $picto).' Datos para CCE';
if($this->cce_clave_mpio != ""){
$label .= "
Clave Municipio:".$this->cce_clave_mpio;
}
if($this->cce_clave_col != ""){
$label .= "
Clave Colonia:".$this->cce_clave_col;
}
if($this->cce_calle != ""){
$label .= "
Calle:".$this->cce_calle;
}
if($this->cce_noint != ""){
$label .= "
No Int.:".$this->cce_noint;
}
if($this->cce_noext != ""){
$label .= "
No Ext.:".$this->cce_noext;
}
}
$target = "_blank";
$linkclose = ($target ? ' target="'.$target.'"' : '');
$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
$linkclose .= ' class="classfortooltip"';
$linkstart = '';
$linkend = '';
if ($option == 'nolink') {
$linkstart = '';
$linkend = '';
}
$result .= $linkstart;
$result .= "".$this->label."";
$result .= $linkend;
return $result;
}
public function getDatosXML($ref = '', $uuid = '', $tipo = 0){
global $conf;
$archivos = 1;
$ruta_xml = $conf->facture->dir_output."/".$ref."/".$uuid.".xml";
if($tipo == 1){
$ruta_xml = $conf->facture->dir_output."/".$ref."/Pago_".$uuid.".xml";
}
// print 'ruta_xml::'.$ruta_xml.'::
';
if(file_exists($ruta_xml)){
$xml = simplexml_load_string(file_get_contents($ruta_xml));
$ns = $xml->getNamespaces(true);
$xml->registerXPathNamespace('c', $ns['cfdi']);
$xml->registerXPathNamespace('t', $ns['tfd']);
$emisor_rfc = "";
$receptor_rfc = "";
foreach ($xml->xpath('//cfdi:Comprobante//cfdi:Emisor') as $Emisor){
$emisor_rfc = (String)$Emisor["Rfc"];
}
foreach ($xml->xpath('//cfdi:Comprobante//cfdi:Receptor') as $Receptor){
$receptor_rfc = (String)$Receptor["Rfc"];
}
$informacion_xml = array();
if($emisor_rfc != "" && $receptor_rfc != ""){
$this->datos_xml = array(
"emisor_rfc" => $emisor_rfc,
"receptor_rfc" => $receptor_rfc
);
}
}else{
$archivos = -1;
}
return $archivos;
}
/**
* Inicia Metodos para Comercio Exterior (CCE)
* file: /societe/card_cce.php
*/
public function createHeadCCE(){
global $conf;
$error = 1;
$sql = "INSERT INTO ".MAIN_DB_PREFIX."cfdimx_facture_cce_receptor";
$sql .= " (";
$sql .= "fk_societe,";
$sql .= "entity,";
$sql .= "motivo_traslado,";
$sql .= "tipo_operacion,";
$sql .= "clv_pedimento,";
$sql .= "no_exportador,";
$sql .= "incoterm,";
$sql .= "observaciones,";
$sql .= "certificadoorigen,";
$sql .= "num_certificadoorigen,";
$sql .= "subdivision,";
$sql .= "num_identificacion";
$sql .= " )";
$sql .= " VALUES";
$sql .= " (";
$sql .= "'".$this->fk_soc."',";
$sql .= "'".$conf->entity."',";
$sql .= "'".$this->info_head_cce["motivo_traslado"]."',";
$sql .= "'".$this->info_head_cce["tipo_operacion"]."',";
$sql .= "'".$this->info_head_cce["clv_pedimento"]."',";
$sql .= "'".$this->info_head_cce["no_exportador"]."',";
$sql .= "'".$this->info_head_cce["incoterm"]."',";
$sql .= "'".$this->info_head_cce["observaciones"]."',";
$sql .= "'".$this->info_head_cce["certificadoorigen"]."',";
$sql .= "'".$this->info_head_cce["num_certificadoorigen"]."',";
$sql .= "'".$this->info_head_cce["subdivision"]."',";
$sql .= "'".$this->info_head_cce["num_identificacion"]."'";
$sql .= " )";
// print $sql."
";
$resql = $this->db->query($sql);
if(!$resql){
$this->errors[] = "Error 1001: No se pudo guardar la Información de Comercio Exterior";
$this->errors[] = $sql;
$error = -1;
}
// if($resql){
// return 1;
// }else{
// $this->error_head_receptor[] = dol_print_error($this->db);
// return -1;
// }
return $error;
}
public function fetchHeadCCE($fk_soc){
global $conf;
$sql = "SELECT * FROM ".MAIN_DB_PREFIX."cfdimx_facture_cce_receptor";
$sql .= " WHERE";
$sql .= " fk_societe = ".$fk_soc;
$sql .= " AND entity = ".$conf->entity;
// print $sql.'
';
$resql = $this->db->query($sql);
if($resql){
while($obj = $this->db->fetch_object($resql)){
$this->info_head_cce["rowid"] = $obj->rowid;
$this->info_head_cce["motivo_traslado"] = $obj->motivo_traslado;
$this->info_head_cce["tipo_operacion"] = $obj->tipo_operacion;
$this->info_head_cce["clv_pedimento"] = $obj->clv_pedimento;
$this->info_head_cce["no_exportador" ] = $obj->no_exportador;
$this->info_head_cce["incoterm"] = $obj->incoterm;
$this->info_head_cce["observaciones"] = $obj->observaciones;
$this->info_head_cce["certificadoorigen"] = $obj->certificadoorigen;
$this->info_head_cce["num_certificadoorigen"] = $obj->num_certificadoorigen;
$this->info_head_cce["subdivision"] = $obj->subdivision;
$this->info_head_cce["num_identificacion"] = $obj->num_identificacion;
}
}
}
public function updateHeadCCE(){
$error = 1;
$sql = "UPDATE ".MAIN_DB_PREFIX."cfdimx_facture_cce_receptor";
$sql .= " SET";
$sql .= " motivo_traslado = '".$this->info_head_cce["motivo_traslado"]."',";
$sql .= " tipo_operacion = '".$this->info_head_cce["tipo_operacion"]."',";
$sql .= " clv_pedimento = '".$this->info_head_cce["clv_pedimento"]."',";
$sql .= " no_exportador = '".$this->info_head_cce["no_exportador"]."',";
$sql .= " incoterm = '".$this->info_head_cce["incoterm"]."',";
$sql .= " observaciones = '".$this->info_head_cce["observaciones"]."',";
$sql .= " certificadoorigen ='".$this->info_head_cce["certificadoorigen"]."',";
$sql .= " num_certificadoorigen = '".$this->info_head_cce["num_certificadoorigen"]."',";
$sql .= " subdivision = '".$this->info_head_cce["subdivision"]."',";
$sql .= " num_identificacion = '".$this->info_head_cce["num_identificacion"]."'";
$sql .= " WHERE";
$sql .= " rowid = ".$this->info_head_cce["rowid"];
// print $sql."
";
$resql = $this->db->query($sql);
if(!$resql){
$this->errors[] = "Error 1001: No se pudo actualizar la información de Comercio Exterior.";
$this->errors[] = $sql;
$error = -1;
}
return $error;
}
/**
* Termina Metodos para Comercio Exterior (CCE)
*/
}
?>