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.'';
// print_r($facture->array_options);
// print '';
// print 'socid :: '.$facture->socid.'';
// 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';
// 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