0, "motivo_traslado" => "", "tipo_operacion" => "", "clv_pedimento" => "", "no_exportador" => "", "incoterm" => "", "observaciones" => "", "certificadoorigen" => "", "num_certificadoorigen" => "", "subdivision" => "", "num_identificacion" => "" ); public $head = array( "rowid" => 0, "tipo_operacion" => "", "clv_pedimento" => "", "no_exportador" => "", "incoterm" => "", "observaciones" => "", "num_identificacion" => "", "tipocambio" => "", "certificadoorigen" => "", "subdivision" => "", "motivotraslado" => "", "numcertificadoorigen" => "" ); public $productos = array(); public $error_head_receptor = array(); public function __construct($db){ $this->db = $db; // $this->fetchheadCCE_receptor($this->fk_societe); } ##Inicia Funciones para head de CCE en Ficha de Terceros public function createheadCCE_receptor(){ global $conf; $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_societe."',"; $sql .= "'".$conf->entity."',"; $sql .= "'".$this->head_receptor["motivo_traslado"]."',"; $sql .= "'".$this->head_receptor["tipo_operacion"]."',"; $sql .= "'".$this->head_receptor["clv_pedimento"]."',"; $sql .= "'".$this->head_receptor["no_exportador"]."',"; $sql .= "'".$this->head_receptor["incoterm"]."',"; $sql .= "'".$this->head_receptor["observaciones"]."',"; $sql .= "'".$this->head_receptor["certificadoorigen"]."',"; $sql .= "'".$this->head_receptor["num_certificadoorigen"]."',"; $sql .= "'".$this->head_receptor["subdivision"]."',"; $sql .= "'".$this->head_receptor["num_identificacion"]."'"; $sql .= " )"; // print $sql."

"; $resql = $this->db->query($sql); if($resql){ return 1; }else{ $this->error_head_receptor[] = dol_print_error($this->db); return -1; } } public function fetchheadCCE_receptor($fk_societe){ global $conf; $sql = "SELECT * FROM ".MAIN_DB_PREFIX."cfdimx_facture_cce_receptor"; $sql .= " WHERE"; $sql .= " fk_societe = ".$fk_societe; $sql .= " AND entity = ".$conf->entity; // print $sql.'
'; $resql = $this->db->query($sql); if($resql){ while($obj = $this->db->fetch_object($resql)){ $this->head_receptor["rowid"] = $obj->rowid; $this->head_receptor["motivo_traslado"] = $obj->motivo_traslado; $this->head_receptor["tipo_operacion"] = $obj->tipo_operacion; $this->head_receptor["clv_pedimento"] = $obj->clv_pedimento; $this->head_receptor["no_exportador" ] = $obj->no_exportador; $this->head_receptor["incoterm"] = $obj->incoterm; $this->head_receptor["observaciones"] = $obj->observaciones; $this->head_receptor["certificadoorigen"] = $obj->certificadoorigen; $this->head_receptor["num_certificadoorigen"] = $obj->num_certificadoorigen; $this->head_receptor["subdivision"] = $obj->subdivision; $this->head_receptor["num_identificacion"] = $obj->num_identificacion; } } } public function updateheadCCE_receptor(){ global $conf; $sql = "UPDATE ".MAIN_DB_PREFIX."cfdimx_facture_cce_receptor"; $sql .= " SET"; $sql .= " motivo_traslado = '".$this->head_receptor["motivo_traslado"]."',"; $sql .= " tipo_operacion = '".$this->head_receptor["tipo_operacion"]."',"; $sql .= " clv_pedimento = '".$this->head_receptor["clv_pedimento"]."',"; $sql .= " no_exportador = '".$this->head_receptor["no_exportador"]."',"; $sql .= " incoterm = '".$this->head_receptor["incoterm"]."',"; $sql .= " observaciones = '".$this->head_receptor["observaciones"]."',"; $sql .= " certificadoorigen ='".$this->head_receptor["certificadoorigen"]."',"; $sql .= " num_certificadoorigen = '".$this->head_receptor["num_certificadoorigen"]."',"; $sql .= " subdivision = '".$this->head_receptor["subdivision"]."',"; $sql .= " num_identificacion = '".$this->head_receptor["num_identificacion"]."'"; $sql .= " WHERE"; $sql .= " rowid = ".$this->head_receptor["rowid"]; // print $sql."

"; $resql = $this->db->query($sql); } ##Termina Funciones para head de CCE en Ficha de Terceros ##Inicia Funciones para encabezados de CCE public function createheadCCE(){ $sql = "INSERT INTO ".MAIN_DB_PREFIX."cfdimx_facture_comercio_extranjero"; $sql .= " ("; $sql .= " fk_facture, tipo_operacion, clv_pedimento, no_exportador, incoterm, observaciones, num_identificacion,"; $sql .= " tipocambio, certificadoorigen, subdivision, motivotraslado, numcertificadoorigen"; $sql .= " )"; $sql .= " VALUES"; $sql .= " ("; $sql .= "'".$this->fk_facture."',"; $sql .= "'".$this->head["tipo_operacion"]."',"; $sql .= "'".$this->head["clv_pedimento"]."',"; $sql .= "'".$this->head["no_exportador"]."',"; $sql .= "'".$this->head["incoterm"]."',"; $sql .= "'".$this->head["observaciones"]."',"; $sql .= "'".$this->head["num_identificacion"]."',"; $sql .= "'".$this->head["tipocambio"]."',"; $sql .= "'".$this->head["certificadoorigen"]."',"; $sql .= "'".$this->head["subdivision"]."',"; $sql .= "'".$this->head["motivotraslado"]."',"; $sql .= "'".$this->head["numcertificadoorigen"]."'"; $sql .= " )"; // print $sql."

"; $resq = $this->db->query($sql); } public function updateheadCCE(){ $sql = "UPDATE ".MAIN_DB_PREFIX."cfdimx_facture_comercio_extranjero"; $sql .= " SET"; $sql .= " , , , , , , ,"; $sql .= " , , , , "; $sql .= " )"; $sql .= " VALUES"; $sql .= " ("; // $sql .= "'".$this->fk_facture."',"; $sql .= " tipo_operacion = '".$this->head["tipo_operacion"]."',"; $sql .= " clv_pedimento = '".$this->head["clv_pedimento"]."',"; $sql .= " no_exportador = '".$this->head["no_exportador"]."',"; $sql .= " incoterm = '".$this->head["incoterm"]."',"; $sql .= " observaciones = '".$this->head["observaciones"]."',"; $sql .= " num_identificacion = '".$this->head["num_identificacion"]."',"; $sql .= " tipocambio = '".$this->head["tipocambio"]."',"; $sql .= " certificadoorigen = '".$this->head["certificadoorigen"]."',"; $sql .= " subdivision = '".$this->head["subdivision"]."',"; $sql .= " motivotraslado = '".$this->head["motivotraslado"]."',"; $sql .= " numcertificadoorigen = '".$this->head["numcertificadoorigen"]."'"; $sql .= " WHERE"; $sql .= " rowid = ".$this->head["rowid"]; print $sql."

"; } public function fetchheadCCE($id_factura){ } ##Termina Funciones para encabezados de CCE ##Inicia Funciones para productos de CCE public function createproductCCE(){ if(is_array($this->productos) && count($this->productos) > 0){ // print 'crear partidas de Productos
'; $total_usd_global = 0; foreach($this->productos AS $key => $value){ // print '
';
                    //     print_r($value);
                    // print '
'; $sql = "INSERT INTO ".MAIN_DB_PREFIX."cfdimx_facture_comercio_extranjero_mercancia"; $sql .= "("; $sql .= "fk_facture,"; $sql .= "fk_facturedet,"; $sql .= "preciousd,"; $sql .= "noidentificacion,"; $sql .= "unidadcext,"; $sql .= "fraccion_arancelaria,"; $sql .= "valor_unitario,"; $sql .= "cantidad_aduana,"; $sql .= "marca"; $sql .= ")"; $sql .= "VALUES"; $sql .= "("; $sql .= "'".$this->fk_facture."',"; $sql .= "'".$value["line_rowid"]."',"; $sql .= "'".$value["total_usd"]."',"; $sql .= "'".$value["nodo_identificacion"]."',"; $sql .= "'".$value["unidad_aduana"]."',"; $sql .= "'".$value["fraccionarancelaria"]."',"; $sql .= "'".$value["price_uni"]."',"; $sql .= "'".$value["cantidad_aduana"]."',"; $sql .= "'".$value["marca"]."'"; $sql .= ")"; // print $sql.'
'; $res = $this->db->query($sql); if($res){ $total_usd_global += $value["total_usd"]; } // $ttusd+=$_POST['produsd'.$rs4->rowid]; } $update = "UPDATE ".MAIN_DB_PREFIX."cfdimx_facture_comercio_extranjero"; $update .= " SET"; $update .= " totalusd = ".$total_usd_global; $update .= " WHERE"; $update .= " fk_facture = ".$this->fk_facture; $res = $this->db->query($update); } } public function updateproductCCE(){ } public function fetchproductsCCE($id_factura){ } ##Termina Funciones para productos de CCE ##Inicia Funciones para registro automatico public function createCCE($fk_facture){ global $conf; // print 'inicia registro automatico
'; $facture = new Facture($this->db); $facture->fetch($fk_facture); // print '
';
            //     print_r($facture->array_options);
            // print '
'; // print 'socid :: '.$facture->socid.'
'; // print 'eliminar head y list product cce
'; $this->fetchheadCCE_receptor($facture->socid); if($this->head_receptor["rowid"] > 0){ // print 'crear head
'; // print '
';
                //     print_r($this->head_receptor);
                // print '
'; $this->fk_facture = $fk_facture; $this->head["tipo_operacion"] = $this->head_receptor["tipo_operacion"]; $this->head["clv_pedimento"] = $this->head_receptor["clv_pedimento"]; $this->head["no_exportador"] = $this->head_receptor["no_exportador"]; $this->head["incoterm"] = $this->head_receptor["incoterm"]; $this->head["observaciones"] = $this->head_receptor["observaciones"]; $this->head["num_identificacion"] = $this->head_receptor["num_identificacion"]; $this->head["tipocambio"] = 99; $this->head["certificadoorigen"] = $this->head_receptor["certificadoorigen"]; $this->head["subdivision"] = $this->head_receptor["subdivision"]; $this->head["motivotraslado"] = $this->head_receptor["motivo_traslado"]; $this->head["numcertificadoorigen"] = $this->head_receptor["num_certificadoorigen"]; // $res = $this->createheadCCE(); ## // print '
';
                //     print_r($this->head);
                // print '
'; // print 'crear list product
'; if(is_array($facture->lines) && count($facture->lines) > 0){ $tipocambio = $this->tipoCambio($this->fk_facture); foreach ($facture->lines as $key => $value) { // print '
';
                        //     print_r($value);
                        // print '
'; if($conf->global->MAIN_MODULE_MULTICURRENCY){ $precio_total = $value->multicurrency_total_ht; $subprice = $value->multicurrency_subprice; }else{ $precio_total = $value->total_ht; $subprice = $value->subprice; } $rowid_producto = $value->fk_product; $description_producto = $value->description; $nodo_identificacion = ""; $cantidad = $value->qty; // $precio_total = $object->lines[$i]->total_ht; // $subprice = $object->lines[$i]->subprice; $unidad_aduana = $value->array_options["options_uaduana"]; $fraccionarancelaria = $value->array_options["options_f_arancelaria"]; $cantidad_aduana = $cantidad; if(isset($value->array_options["options_marcaaduana"])){ $marca = $value->array_options["options_marcaaduana"]; }else{ $marca = $value->array_options["options_marca"]; } // $marca = ""; $total_usd = $precio_total*$tipocambio; $price_uni = $subprice*$tipocambio; $ref_producto = $value->ref; $label_producto = $value->label; // $description_static = $value->description; if(!is_null($value->fk_product) && $value->fk_product > 0){ $producto = new Product($this->db); if($conf->global->CFDIMX_EXTRAFIELDS_CCE == 1){ $unidad_aduana = $producto->array_options["options_uaduana"]; $fraccionarancelaria = $producto->array_options["options_f_arancelaria"]; $price_uni = $producto->array_options["options_precio_usd"]; $total_usd = $price_uni * $cantidad_aduana; if(isset($producto->array_options["options_marcaaduana"])){ $marca = $producto->array_options["options_marcaaduana"]; }else{ $marca = $producto->array_options["options_marca"]; } } } $this->productos[] = array( "line_rowid" => $value->id, "fk_product" => $rowid_producto, "ref" => $ref_producto, "label" => $label_producto, "description" => $description_producto, "qty" => $cantidad, "total_ttc" => $value->total_ttc, "nodo_identificacion" => $nodo_identificacion, "unidad_aduana" => $unidad_aduana, "fraccionarancelaria" => $fraccionarancelaria, "cantidad_aduana" => $cantidad_aduana, "marca" => $marca, "total_usd" => $total_usd, "price_uni" => $price_uni ); } // print '
';
                    //     print_r($this->productos);
                    // print '
'; $this->createproductCCE(); } } // print 'termina registro automatico
'; } ##Termina Funciones para registro automatico public function tipoCambio($facid){ global $conf; if($conf->global->MAIN_MODULE_MULTICURRENCY){ $sql_divisa = "SELECT multicurrency_code AS divisa FROM ".MAIN_DB_PREFIX."facture WHERE rowid = ".$facid; $res_sql_divisa = $this->db->query($sql_divisa); $obj_divisa = $this->db->fetch_object($res_sql_divisa); $divisa = $obj_divisa->divisa; }else{ $divisa = $conf->currency; } if($divisa!='USD'){ $divisa_2 = 'USD'; $sql_divisa_conversion = " SELECT * FROM ".MAIN_DB_PREFIX."multicurrency AS divisa INNER JOIN ".MAIN_DB_PREFIX."multicurrency_rate AS conversion ON conversion.fk_multicurrency = divisa.rowid WHERE conversion.entity = '".$conf->entity."' AND divisa.code = '".$divisa_2."' ORDER BY conversion.rowid DESC LIMIT 1 "; $res_sql_divisa_conversion = $this->db->query($sql_divisa_conversion); $num_sql_divisa_conversion = $this->db->num_rows($res_sql_divisa_conversion); if($num_sql_divisa_conversion > 0){ $obj_divisa_origen = $this->db->fetch_object($res_sql_divisa_conversion); } $tipocambio = $obj_divisa_origen->rate; $tipocambio=str_replace(",", "",number_format($tipocambio,2)); if($tipocambio2 == ""){ $sql_divisa_conversion = " SELECT * FROM ".MAIN_DB_PREFIX."multicurrency AS divisa INNER JOIN ".MAIN_DB_PREFIX."multicurrency_rate AS conversion ON conversion.fk_multicurrency = divisa.rowid WHERE conversion.entity = '".$conf->entity."' AND divisa.code = '".$divisa."' ORDER BY conversion.rowid DESC LIMIT 1 "; $res_sql_divisa_conversion = $this->db->query($sql_divisa_conversion); $num_sql_divisa_conversion = $this->db->num_rows($res_sql_divisa_conversion); if($num_sql_divisa_conversion > 0){ $obj_divisa_origen = $this->db->fetch_object($res_sql_divisa_conversion); } $tipocambio2 = $obj_divisa_origen->rate; $tipocambio2 = str_replace(",", "",number_format($tipocambio2,2)); } }else{ $tipocambio = 1; } return $tipocambio; } public function catalogo($selected='', $htmlname='', $tipo_catalogo, $tipo_informacion = 0, $show_empty=0, $exclude='', $disabled=0, $include='', $enableonly='', $force_entity=0, $maxlength=0, $showstatus=0, $morefilter='', $show_every=0, $enableonlytext='', $morecss='', $noactive=0, $entrepot=0){ global $conf,$user,$langs,$db; // If no preselected user defined, we take current user if ((is_numeric($selected) && ($selected < -2 || empty($selected))) && empty($conf->global->SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE)) $selected=$user->id; $excludeUsers=null; $includeUsers=null; // Permettre l’exclusion d’utilisateurs if (is_array($exclude)) $excludeUsers = implode("','",$exclude); // Permettre l’inclusion d’utilisateurs if (is_array($include)) $includeUsers = implode("','",$include); else if ($include == 'hierarchy') { // Build list includeUsers to have only hierarchy $userid=$user->id; $include=array(); if (empty($user->users) || ! is_array($user->users)) $user->get_full_tree(); foreach($user->users as $key => $val) { if (preg_match('/'.$userid.'/',$val['fullpath'])) $include[]=$val['id']; } $includeUsers = implode("','",$include); } $out=''; $label_catalogo = ""; switch ($tipo_catalogo) { case 1: $sql = "SELECT * FROM ".MAIN_DB_PREFIX."c_cfdimx_incoterm WHERE active = 1"; $label_catalogo = "Incoterm"; break; case 2: $sql = "SELECT * FROM ".MAIN_DB_PREFIX."c_cfdimx_unidad_aduana WHERE active = 1"; $label_catalogo = "Unidad Aduana"; break; case 3: $sql = "SELECT * FROM ".MAIN_DB_PREFIX."c_cfdimx_f_arancelaria WHERE active = 1"; $label_catalogo = "Fracción Arancelaria"; break; case 4: $sql = "SELECT * FROM ".MAIN_DB_PREFIX."c_cfdimx_motivo_traslado WHERE active = 1"; $label_catalogo = "Motivo Traslado"; break; case 5: $sql = "SELECT * FROM ".MAIN_DB_PREFIX."c_cfdimx_tipo_operacion WHERE active = 1"; $label_catalogo = "Tipo Operación"; break; case 6: $sql = "SELECT * FROM ".MAIN_DB_PREFIX."c_cfdimx_clave_pedimento WHERE active = 1"; $label_catalogo = "Clave Pedimento"; break; default: $sql = ""; break; } if($tipo_informacion == 1) $sql .= " AND code='".$selected."'"; $resql=$db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; if ($num) { // Enhance with select2 $nodatarole=''; if ($conf->use_javascript_ajax) { include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; $comboenhancement = ajax_combobox($htmlname); $out.=$comboenhancement; $nodatarole=($comboenhancement?' data-role="none"':''); } $out.= ''; }else{ // $out.= '