🌹🏠🌹？》《》？《》？
<?php
class rem_cab extends Base
{
public $empresa;
public $tdoc;
public $letra;
public $sucur;
public $numero;
public $codigo_cliente;
public $nro_factura;
public $nro_pd;
public $codigo_cliente_final;
public $vendedor;
public $nro_oc;
public $fecha_doc;
public $fecha_ing;
public $fecha_disp;
public $fecha_difer;
public $fecha_difer_cliente;
public $fecha_libera;
public $fecha_libera_log;
public $fecha_ini_comp;
public $fecha_prev_ent;
public $dias_demora_prev;
public $fecha_ruteo;
public $fecha_certifica;
public $fecha_conf_alcance;
public $fecha_conf_ent;
public $fecha_conf_ent_app;
public $fecha_entrega;
public $dias_demora;
public $dias_demora_certi;
public $dias_demora_int;
public $interior;
public $espera;
public $espera_logistica;
public $espera_acceso;
public $contado;
public $retira;
public $turno;
public $fecha_pedido_turno;
public $fecha_turno;
public $hoja_ruta;
public $estado;
public $bultos;
public $unidades;
public $volumen;
public $otros;
public $valor_declarado;
public $nro_lote;
public $hora_pactada;
public $hora_entregada;
public $fc_concepto;
public $nro_track;

// Solo detalle para OR.
public $d_itm;
public $d_articulo;
public $d_bultos;
public $d_unidades;
public $d_volumen;
public $d_otros;
public $d_estado;
public $d_causa;

// rem_obser
public $o_obser;
public $o_obser_gl;
public $o_prioridad;

// rem_historial
public $h_fecha;
public $h_hoja_ruta;
public $h_causa;
public $h_bultos;
public $h_unidades;
public $h_volumen;
public $h_otros;
public $h_estado;
public $h_obser;

public $todos;
public $error = 0; // falso
public $msg_error;

function __construct($r_empresa,$r_tdoc,$r_letra,$r_sucur,$r_numero)
{  
//$this->conexion        = $r_base;
$this->empresa         = $r_empresa;
$this->tdoc            = $r_tdoc;
$this->letra           = $r_letra;
$this->sucur           = $r_sucur;
$this->numero          = $r_numero;
$this->nro_pd          = $r_numero;
$this->nro_oc         = "0";
$this->vendedor       = "0";
$this->fecha_difer    = '';
$this->fecha_difer_cliente = '';
$this->fecha_disp     = '';
$this->fecha_libera   = '';
$this->fecha_libera_log = '';
$this->fecha_ini_comp = '';
$this->fecha_prev_ent = '';
$this->dias_demora_prev = 0;
$this->fecha_ruteo    = '';
$this->fecha_certifica = '';
$this->fecha_conf_alcance = '';
$this->fecha_conf_ent = '';
$this->fecha_conf_ent_app = '';
$this->fecha_entrega  = '';
$this->dias_demora    = 0;
$this->dias_demora_certi = 0;
$this->dias_demora_int = 0 ;
$this->contado        = "N";
$this->bultos         = 0;
$this->unidades       = 0;
$this->volumen        = 0;
$this->otros          = 0;
$this->estado         = 2;
$this->valor_declarado = 0;
$this->nro_lote       = 0;
$this->hora_entrega   = '';
$this->d_causa        = 0;
$this->o_obser        = "";
$this->o_obser_gl     = "";
$this->o_prioridad    = 0;
$this->todos          = 'S';
if ($r_tdoc == 'RTO'){
   $this->nro_track      =  str_pad($r_empresa,3,'0',STR_PAD_LEFT).
                            $r_letra.
                            str_pad($r_sucur,5,'0',STR_PAD_LEFT).
                            str_pad($r_numero,10,'0',STR_PAD_LEFT);
}
else{
   $this->nro_track      =  str_pad($r_empresa,3,'0',STR_PAD_LEFT).
                            $r_letra.
                            str_pad($r_sucur,5,'0',STR_PAD_LEFT).
                            str_pad($r_numero,10,'0',STR_PAD_LEFT).'O';
}

} 

function r_select_rem_cab()
{ 
$this->error     = 0;
$this->msg_error = "";
$p_sql_r="select * from ".$this->base_web."rem_cab     
       where empresa  = '{$this->empresa}'
         and tdoc     = '{$this->tdoc}'
         and letra    = '{$this->letra}'
         and sucur    = '{$this->sucur}'
         and numero   = '{$this->numero}' ";
$resultado=@odbc_exec($this->conexion,$p_sql_r);
if (!$resultado){
  $this->error     = 2;
  $this->msg_error = "01- Error. No se pudo leer [rem_cab]";
  return;
}
$row=odbc_fetch_array($resultado);
if (!$row){
  $this->error     = 1;
  $this->msg_error = "02- Error. No se pudo leer [rem_cab]";
  return;
}
$this->nro_factura    = $row['nro_factura'];
$this->codigo_cliente = $row['codigo_cliente'];
$this->codigo_cliente_final = $row['codigo_cliente_final'];
$this->vendedor       = trim( (string)$row['vendedor']);
$this->nro_oc         = trim( (string)$row['nro_oc']);
$this->fecha_doc      = date("d-m-Y",strtotime($row['fecha_doc']));
$this->fecha_ing      = date("d-m-Y",strtotime($row['fecha_ing']));
$this->fecha_disp     = "";
if (strlen($row['fecha_disp']) > 0 && $row['fecha_disp'] != '1900-01-01'){
  $this->fecha_disp     = date("d-m-Y",strtotime($row['fecha_disp']));
}
$this->fecha_difer    = "";
if (strlen($row['fecha_difer']) > 0 && $row['fecha_difer'] != '1900-01-01'){
  $this->fecha_difer  = date("d-m-Y",strtotime($row['fecha_difer']));
}
$this->fecha_difer_cliente = "";
if (strlen($row['fecha_difer_cliente']) > 0 && $row['fecha_difer_cliente'] != '1900-01-01'){
  $this->fecha_difer_cliente = date("d-m-Y",strtotime($row['fecha_difer_cliente']));
}
$this->fecha_libera   = "";
if (strlen($row['fecha_libera']) > 0 && $row['fecha_libera'] != '1900-01-01'){
  $this->fecha_libera = date("d-m-Y",strtotime($row['fecha_libera']));
}
$this->fecha_libera_log = "";
if (strlen($row['fecha_libera_log']) > 0 && $row['fecha_libera_log'] != '1900-01-01'){
  $this->fecha_libera_log = date("d-m-Y",strtotime($row['fecha_libera_log']));
}
$this->fecha_ini_comp = "";
if (strlen($row['fecha_ini_comp']) > 0 && $row['fecha_ini_comp'] != '1900-01-01'){
  $this->fecha_ini_comp = date("d-m-Y",strtotime($row['fecha_ini_comp']));  
}
$this->fecha_prev_ent = "";
if (strlen($row['fecha_prev_ent']) > 0 && $row['fecha_prev_ent'] != '1900-01-01'){
  $this->fecha_prev_ent = date("d-m-Y",strtotime($row['fecha_prev_ent']));
}
$this->dias_demora_prev = $row['dias_demora_prev'];
$this->fecha_ruteo      = "";
if (strlen($row['fecha_ruteo']) > 0 && $row['fecha_ruteo'] != '1900-01-01'){
  $this->fecha_ruteo    = date("d-m-Y",strtotime($row['fecha_ruteo']));
}
$this->fecha_certifica    = "";
if (strlen($row['fecha_certifica']) > 0 && $row['fecha_certifica'] != '1900-01-01'){
  $this->fecha_certifica  = date("d-m-Y",strtotime($row['fecha_certifica']));
}
$this->fecha_conf_alcance = "";
if (strlen($row['fecha_conf_alcance']) > 0 && $row['fecha_conf_alcance'] != '1900-01-01'){
  $this->fecha_conf_alcance = date("d-m-Y",strtotime($row['fecha_conf_alcance']));
}
$this->fecha_conf_ent     = "";
if (strlen($row['fecha_conf_ent']) > 0 && $row['fecha_conf_ent'] != '1900-01-01'){
  $this->fecha_conf_ent   = date("d-m-Y",strtotime($row['fecha_conf_ent']));  
}
$this->fecha_conf_ent_app = "";
if (strlen($row['fecha_conf_ent_app']) > 0 && $row['fecha_conf_ent_app'] != '1900-01-01'){
  $this->fecha_conf_ent_app = date("d-m-Y",strtotime($row['fecha_conf_ent_app']));  
}
$this->fecha_entrega = "";
if (strlen($row['fecha_entrega']) > 0  && $row['fecha_entrega'] != '1900-01-01'){
  $this->fecha_entrega = date("d-m-Y",strtotime($row['fecha_entrega'])); 
}
$this->interior      = $row['interior'];
$this->espera        = $row['espera'];
$this->espera_logistica = $row['espera_logistica'];
$this->espera_acceso    = $row['espera_acceso'];
$this->contado       = $row['contado'];
$this->retira        = $row['retira'];
$this->turno         = $row['turno'];
$this->fecha_pedido_turno = "";
if (strlen($row['fecha_pedido_turno']) > 0 && $row['fecha_pedido_turno'] != '1900-01-01'){
  $this->fecha_pedido_turno = date("d-m-Y",strtotime($row['fecha_pedido_turno']));
}
$this->fecha_turno   = "";
if (strlen($row['fecha_turno']) > 0 && $row['fecha_turno'] != '1900-01-01'){
  $this->fecha_turno   = date("d-m-Y",strtotime($row['fecha_turno']));
}
$this->hoja_ruta     = $row['hoja_ruta'];
$this->estado        = $row['estado'];
$this->bultos        = $row['bultos'];
$this->unidades      = $row['unidades'];
$this->volumen       = $row['volumen'];
$this->otros         = $row['otros'];
$this->valor_declarado = $row['valor_declarado'];
$this->nro_lote      = $row['nro_lote'];
$this->hora_pactada  = $row['hora_pactada'];
$this->hora_entrega  = $row['hora_entrega'];
$this->fc_concepto   = $row['fc_concepto'];
$this->nro_track     = $row['nro_track'];
$this->nro_pd        = $row['nro_pd'];

odbc_free_result($resultado);

$this->o_obser = "";
$this->o_obser_gl = "";
$p_sql_r="select * from ".$this->base_web."rem_obser
           where empresa  = '{$this->empresa}'
             and tdoc     = '{$this->tdoc}'
             and letra    = '{$this->letra}'
             and sucur    = '{$this->sucur}'
             and numero   = '{$this->numero}' ";
$resultado=@odbc_exec($this->conexion,$p_sql_r);
if (!$resultado){
  $this->error     = 2;
  $this->msg_error = "03- Error. No se pudo leer [rem_obser]";
  return;
}
$row=odbc_fetch_array($resultado);
if ($row){
  $this->obser    = trim( (string)$row['obser']);
  $this->obser_gl = trim( (string)$row['obser_gl']);
}

return;
}  

function r_insert_rem_cab() 
{

$this->error     = 0;
$this->msg_error = "";

$this->fecha_ing = GLSA::r_reviso_fecha($this->fecha_ing,"Ymd");
$this->fecha_doc = GLSA::r_reviso_fecha($this->fecha_doc,"Ymd");
if ( strlen($this->fecha_difer) > 0 && date("Y",strtotime($this->fecha_difer)) > 1900 ){
    $this->fecha_difer = GLSA::r_reviso_fecha($this->fecha_difer,"Ymd");
}
else{
    $this->fecha_difer = '';
}
if ( strlen($this->fecha_disp) > 0 && date("Y",strtotime($this->fecha_disp)) > 1900 ){
    $this->fecha_disp = GLSA::r_reviso_fecha($this->fecha_disp,"Ymd");
}
else{
    $this->fecha_disp = '';
}
if ( strlen($this->fecha_ini_comp) > 0 && date("Y",strtotime($this->fecha_ini_comp)) > 1900 ){
    $this->fecha_ini_comp = GLSA::r_reviso_fecha($this->fecha_ini_comp,"Ymd");
}
else{
    $this->fecha_ini_comp = '';
}
if ( date("Y",strtotime($this->fecha_pedido_turno)) > 1969 ){
    $this->fecha_pedido_turno = GLSA::r_reviso_fecha($this->fecha_pedido_turno,"Ymd");
}
else{
    $this->fecha_pedido_turno = '';
}

if ( date("Y",strtotime($this->fecha_turno)) > 1969 ){
    $this->fecha_turno = GLSA::r_reviso_fecha($this->fecha_turno,"Ymd");
}
else{
    $this->fecha_turno = '';
}

$p_sql_r="insert into ".$this->base_web."rem_cab values 
          ( '{$this->empresa}','{$this->tdoc}' ,'{$this->letra}','{$this->sucur}','{$this->numero}',
            '{$this->nro_factura}','{$this->codigo_cliente}','{$this->codigo_cliente_final}',
            '{$this->nro_oc}','{$this->vendedor}',
            '{$this->fecha_doc}','{$this->fecha_ing}','{$this->fecha_disp}',
            '{$this->fecha_difer}','{$this->fecha_difer_cliente}',
            '{$this->fecha_libera}','{$this->fecha_libera_log}',
            '{$this->fecha_ini_comp}','{$this->fecha_prev_ent}',
            '{$this->dias_demora_prev}','{$this->fecha_ruteo}',
            '{$this->fecha_certifica}','{$this->fecha_conf_alcance}',
            '{$this->fecha_conf_ent}','{$this->fecha_conf_ent_app}','{$this->fecha_entrega}',
            '{$this->dias_demora}','{$this->dias_demora_certi}',
            '{$this->interior}','{$this->espera}','{$this->espera_logistica}',
            '{$this->contado}','{$this->retira}','{$this->turno}','{$this->fecha_pedido_turno}',
            '{$this->fecha_turno}','{$this->hoja_ruta}','{$this->estado}',
            '{$this->bultos}','{$this->unidades}','{$this->volumen}','{$this->otros}',
            '{$this->valor_declarado}','{$this->nro_lote}',
            '{$this->hora_pactada}','{$this->hora_entregada}','{$this->dias_demora_int}',
            '{$this->espera_acceso}','{$this->fc_concepto}','{$this->nro_track}',
            '{$this->nro_pd}','0')";
            //echo "<pre> ".$p_sql_r; die();
$resultado=@odbc_exec($this->conexion,$p_sql_r);
if (!$resultado) {
  $this->error     = 1;
  $this->msg_error = "03- Error. No se pudo insertar [rem_cab] $p_sql_r ";
  return;
}
if (odbc_num_rows($resultado) != 1){
  $this->error     = 1;
  $this->msg_error = "04- Error. No se pudo insertar [rem_cab]";
  return;  
}
odbc_free_result($resultado);

return;
}

function r_insert_rem_det() 
{
$this->error = 0;
$this->msg_error = '';

$p_sql_r="insert into ".$this->base_web."rem_det values 
      ( '{$this->empresa}','{$this->tdoc}' ,'{$this->letra}','{$this->sucur}','{$this->numero}',
        '{$this->d_articulo}' ,'{$this->d_bultos}','{$this->d_unidades}','{$this->d_volumen}',
        '{$this->d_otros}', '{$this->d_estado}' ,'{$this->d_causa}','{$this->d_itm}')" ;
$resultado=@odbc_exec($this->conexion,$p_sql_r);
if (!$resultado) {
  $this->error     = 1;
  $this->msg_error = "05- Error. No se pudo insertar [rem_det]";
  return;
}
if (odbc_num_rows($resultado) != 1){
  $this->error     = 1;
  $this->msg_error = "06- Error. No se pudo insertar [rem_det]";
  return;  
}
odbc_free_result($resultado);

return;
}

function r_update_rem_cab() 
{
$this->error = 0;
$this->msg_error = '';

if ($this->tipo_base != 'I'){
   if (strlen($this->fecha_disp) > 0 )          $this->fecha_disp          = GLSA::r_reviso_fecha($this->fecha_disp,"Ymd");
   if (strlen($this->fecha_ini_comp) > 0 )      $this->fecha_ini_comp      = GLSA::r_reviso_fecha($this->fecha_ini_comp,"Ymd");
   if (strlen($this->fecha_ruteo) > 0 )         $this->fecha_ruteo         = GLSA::r_reviso_fecha($this->fecha_ruteo,"Ymd");
   if (strlen($this->fecha_certifica) > 0 )     $this->fecha_certifica     = GLSA::r_reviso_fecha($this->fecha_certifica,"Ymd");
   if (strlen($this->fecha_conf_alcance) > 0 )  $this->fecha_conf_alcance  = GLSA::r_reviso_fecha($this->fecha_conf_alcance,"Ymd");
   if (strlen($this->fecha_conf_ent) > 0 )      $this->fecha_conf_ent      = GLSA::r_reviso_fecha($this->fecha_conf_ent,"Ymd");
   if (strlen($this->fecha_difer_cliente) > 0 ) $this->fecha_difer_cliente = GLSA::r_reviso_fecha($this->fecha_difer_cliente,"Ymd");
   if (strlen($this->fecha_entrega) > 0 )       $this->fecha_entrega       = GLSA::r_reviso_fecha($this->fecha_entrega,"Ymd");
   if (strlen($this->fecha_pedido_turno) > 0 )  $this->fecha_pedido_turno  = GLSA::r_reviso_fecha($this->fecha_pedido_turno,"Ymd");
}
else {
   if (strlen($this->fecha_disp) > 0 )          $this->fecha_disp          = date("d-m-Y",strtotime($this->fecha_disp));
   if (strlen($this->fecha_ini_comp) > 0 )      $this->fecha_ini_comp      = date("d-m-Y",strtotime($this->fecha_ini_comp));
   if (strlen($this->fecha_ruteo) > 0 )         $this->fecha_ruteo         = date("d-m-Y",strtotime($this->fecha_ruteo));
   if (strlen($this->fecha_certifica) > 0 )     $this->fecha_certifica     = date("d-m-Y",strtotime($this->fecha_certifica));
   if (strlen($this->fecha_conf_alcance) > 0 )  $this->fecha_conf_alcance  = date("d-m-Y",strtotime($this->fecha_conf_alcance));
   if (strlen($this->fecha_conf_ent) > 0 )      $this->fecha_conf_ent      = date("d-m-Y",strtotime($this->fecha_conf_ent));
   if (strlen($this->fecha_difer_cliente) > 0 ) $this->fecha_difer_cliente = date("d-m-Y",strtotime($this->fecha_difer_cliente));
   if (strlen($this->fecha_entrega) > 0 )       $this->fecha_entrega       = date("d-m-Y",strtotime($this->fecha_entrega));
   if (strlen($this->fecha_pedido_turno) > 0 )  $this->fecha_pedido_turno  = date("d-m-Y",strtotime($this->fecha_pedido_turno));
}
$p_vol = sprintf("%0.6f",$this->volumen);
$p_otr = sprintf("%0.6f",$this->otros);
$p_sql_r="update ".$this->base_web."rem_cab set bultos      = '{$this->bultos}',
                                            unidades    = '{$this->unidades}',
                                            volumen     = '$p_vol',
                                            otros       = '$p_otr',
                                            estado      = '{$this->estado}',
                                            codigo_cliente = '{$this->codigo_cliente}',
                                            codigo_cliente_final = '{$this->codigo_cliente_final}',
                                            nro_oc      = '{$this->nro_oc}',
                                            nro_factura = '{$this->nro_factura}',
                                            retira      = '{$this->retira}',
                                            espera      = '{$this->espera}',
                                            espera_logistica = '{$this->espera_logistica}',
                                            espera_acceso    = '{$this->espera_acceso}',
                                            interior    = '{$this->interior}',
                                            contado     = '{$this->contado}',
                                            valor_declarado = '{$this->valor_declarado}',
                                            fecha_disp  = '{$this->fecha_disp}',
                                            fecha_ini_comp = '{$this->fecha_ini_comp}',
                                            fecha_ruteo = '{$this->fecha_ruteo}',
                                            fecha_certifica     = '{$this->fecha_certifica}',
                                            fecha_conf_alcance  = '{$this->fecha_conf_alcance}',
                                            fecha_conf_ent      = '{$this->fecha_conf_ent}',
                                            fecha_entrega       = '{$this->fecha_entrega}',
                                            fecha_difer_cliente = '{$this->fecha_difer_cliente}',
                                            dias_demora         = '{$this->dias_demora}',
                                            dias_demora_prev    = '{$this->dias_demora_prev}',
                                            dias_demora_certi   = '{$this->dias_demora_certi}',
                                            dias_demora_int     = '{$this->dias_demora_int}',
                                            nro_lote            = '{$this->nro_lote}',
                                            hoja_ruta           = '{$this->hoja_ruta}',
                                            fecha_pedido_turno  = '{$this->fecha_pedido_turno}',
                                            turno               = '{$this->turno}',
                                            nro_track           = '{$this->nro_track}'

       where empresa  = '{$this->empresa}'
         and tdoc     = '{$this->tdoc}'
         and letra    = '{$this->letra}'
         and sucur    = '{$this->sucur}'
         and numero   = '{$this->numero}' ";
$resultado=@odbc_exec($this->conexion,$p_sql_r);
if (!$resultado) {
  $this->error     = 1;
  $this->msg_error = "07- Error. No se pudo actualizar [rem_cab]";
  return;
}
if (odbc_num_rows($resultado) != 1){
  $this->error     = 1;
  $this->msg_error = "08- Error. No se pudo actualizar [rem_cab]";
  return;  
}
odbc_free_result($resultado);

return;
}

function r_update_rem_det()
{
$p_cancel=false;
$this->error = 0;
$this->msg_error = '';
$p_sql_r="update ".$this->base_web."rem_det set estado = '{$this->d_estado}',
                                                causa  = '{$this->d_causa}'
       where empresa  = '{$this->empresa}'
         and tdoc     = '{$this->tdoc}'
         and letra    = '{$this->letra}'
         and sucur    = '{$this->sucur}'
         and numero   = '{$this->numero}' 
         and estado not in ( 11,99 ) ";
$resultado=@odbc_exec($this->conexion,$p_sql_r);
if (!$resultado) {
   $this->error     = 1;
   $this->msg_error = "10- Error. No se pudo actualizar [rem_det] !! ";
   return;
}
if (odbc_num_rows($resultado) <= 0){
   $this->error     = 1;
   $this->msg_error = "11- Error. No se pudo actualizar [rem_det] !! ";
   return;
}
odbc_free_result($resultado);

return;
}

function r_update_rem_det_estado()
{
$this->error = 0;
$this->msg_error = '';
$p_sql_r="update ".$this->base_web."rem_det set estado = '{$this->d_estado}'
           where empresa  = '{$this->empresa}'
             and tdoc     = '{$this->tdoc}'
             and letra    = '{$this->letra}'
             and sucur    = '{$this->sucur}'
             and numero   = '{$this->numero}' 
             and estado not in ( 11,99 ) ";
$resultado=@odbc_exec($this->conexion,$p_sql_r);
if (!$resultado) {
   $this->error     = 1;
   $this->msg_error = "12- Error. No se pudo actualizar [rem_det] !! ";
   return;
}
if (odbc_num_rows($resultado) <= 0){
   $this->error     = 1;
   $this->msg_error = "14- Error. No se pudo actualizar [rem_det] !! ";
   return;
}
odbc_free_result($resultado);

return;
}

function r_update_rem_det_cantidad()
{
$this->error = 0;
$this->msg_error = '';
$p_sql_r="update ".$this->base_web."rem_det set bultos   = bultos   + '{$this->d_bultos}',
                                                unidades = unidades + '{$this->d_unidades}',
                                                volumen  = volumen  + '{$this->d_volumen}',
                                                otros    = otros    + '{$this->d_otros}'
           where empresa  = '{$this->empresa}'
             and tdoc     = '{$this->tdoc}'
             and letra    = '{$this->letra}'
             and sucur    = '{$this->sucur}'
             and numero   = '{$this->numero}' 
             and articulo = '{$this->d_articulo}'
             and estado   = '{$this->d_estado}' ";
$resultado=@odbc_exec($this->conexion,$p_sql_r);
if (!$resultado) {
    $this->error     = 1;
    $this->msg_error = "10- Error. No se pudo actualizar [rem_det] !! ";
    return;
}
if (odbc_num_rows($resultado) <= 0){
    $this->error     = 1;
    $this->msg_error = "11- Error. No se pudo actualizar [rem_det] !! ";
    return;
}
odbc_free_result($resultado);

return;
}

function r_delete_rem_det()
{
$this->error = 0;
$this->msg_error = '';

$p_sql_r="delete from ".$this->base_web."rem_det 
           where empresa  = '{$this->empresa}'
             and tdoc     = '{$this->tdoc}'
             and letra    = '{$this->letra}'
             and sucur    = '{$this->sucur}'
             and numero   = '{$this->numero}' ";
if ($this->todos == 'N'){
   $p_sql_r.="and estado not in ( 99 ) ";
}
$resultado=@odbc_exec($this->conexion,$p_sql_r);
if (!$resultado) {
  $this->error     = 1;
  $this->msg_error = "15- Error. No se pudo actualizar [rem_det] !! ";
  return;
}
if (odbc_num_rows($resultado) <= 0){
  $this->error     = 1;
  $this->msg_error = "16- Error. No se pudo actualizar [rem_det] !! ";
  return;  
}
odbc_free_result($resultado);

}

function r_delete_rem_det_cero()
{
$this->error = 0;
$this->msg_error = '';

$p_sql_r="delete from ".$this->base_web."rem_det 
           where empresa  = '{$this->empresa}'
             and tdoc     = '{$this->tdoc}'
             and letra    = '{$this->letra}'
             and sucur    = '{$this->sucur}'
             and numero   = '{$this->numero}'
             and bultos   = 0 ";
if ($this->todos == 'N'){
    $p_sql_r.="and estado not in ( 99 ) ";
}
$resultado=@odbc_exec($this->conexion,$p_sql_r);
if (!$resultado) {
    $this->error     = 1;
    $this->msg_error = "17- Error. No se pudo actualizar [rem_det] !! ";
    return;
}
odbc_free_result($resultado);

}

function r_delete_rem_cab()
{
$this->error = 0;
$this->msg_error = '';

$p_sql_r="delete from ".$this->base_web."rem_cab
           where empresa  = '{$this->empresa}'
             and tdoc     = '{$this->tdoc}'
             and letra    = '{$this->letra}'
             and sucur    = '{$this->sucur}'
             and numero   = '{$this->numero}' ";
$resultado=@odbc_exec($this->conexion,$p_sql_r);
if (!$resultado) {
  $this->error     = 1;
  $this->msg_error = "19- Error. No se pudo actualizar [rem_cab] !! ";
  return;
}
if (odbc_num_rows($resultado) <= 0){
  $this->error     = 1;
  $this->msg_error = "20- Error. No se pudo actualizar [rem_cab] !! ";
  return;  
}
odbc_free_result($resultado);

}

function r_insert_rem_obser() 
{

$this->error     = 0;
$this->msg_error = "";

if (strlen($this->o_obser) == 0 && strlen($this->o_obser_gl) == 0 ){
  return;
}

$p_sql_r="insert into ".$this->base_web."rem_obser values 
          ( '{$this->empresa}','{$this->tdoc}' ,'{$this->letra}','{$this->sucur}','{$this->numero}',
            '{$this->o_obser}','{$this->o_obser_gl}','{$this->o_prioridad}',
            '{$this->estado}' ) ";
$resultado=@odbc_exec($this->conexion,$p_sql_r);
if (!$resultado) {
  $this->error     = 1;
  $this->msg_error = "21- Error. No se pudo insertar [rem_obser] !! ";
  return;
}
if (odbc_num_rows($resultado) != 1){
  $this->error     = 1;
  $this->msg_error = "22- Error. No se pudo insertar [rem_obser] !! ";
  return;  
}
odbc_free_result($resultado);

return;
}

function r_delete_rem_obser()
{
$this->error = 0;
$this->msg_error = '';
$p_sql_r="delete from ".$this->base_web."rem_obser
           where empresa  = '{$this->empresa}'
             and tdoc     = '{$this->tdoc}'
             and letra    = '{$this->letra}'
             and sucur    = '{$this->sucur}'
             and numero   = '{$this->numero}' ";
$resultado=@odbc_exec($this->conexion,$p_sql_r);
if (!$resultado) {
   $this->error     = 1;
   $this->msg_error = "23- Error. No se pudo actualizar [rem_obser] !! ";
   return;
}
/*
if (odbc_num_rows($resultado) <= 0){
   $this->error     = 1;
   $this->msg_error = "17- Error. No se pudo actualizar [rem_obser] !! ";
   return;
}
*/
odbc_free_result($resultado);

}

function r_upd_rem_historial()
{
$this->error = 0;
$this->msg_error = '';

if ($this->tipo_base == 'S'){
   $this->h_fecha = GLSA::r_reviso_fecha($this->h_fecha,"Ymd");
}
else{
   $this->h_fecha = date("d-m-Y",strtotime($this->h_fecha));
}
$p_sql_r="select * from {$this->base_web}rem_historial
           where empresa = '{$this->empresa}'
             and tdoc    = '{$this->tdoc}'
             and letra   = '{$this->letra}'
             and sucur   = '{$this->sucur}'
             and numero  = '{$this->numero}'
             and hoja_ruta = '{$this->h_hoja_ruta}'
             and causa   = '{$this->h_causa}' ";
$this->r_select_fila($p_sql_r,"rem_historial");
if ($this->error == 0){
   $p_sql_r="update {$this->base_web}rem_historial set bultos   = bultos   + '{$this->h_bultos}' ,
                                                     unidades = unidades + '{$this->h_unidades}', 
                                                     volumen  = volumen + '{$this->h_volumen}', 
                                                     otros = otros + '{$this->h_otros}'
               where empresa = '{$this->empresa}'
                 and tdoc    = '{$this->tdoc}'
                 and letra   = '{$this->letra}'
                 and sucur   = '{$this->sucur}'
                 and numero  = '{$this->numero}'
                 and hoja_ruta = '{$this->h_hoja_ruta}'
                 and causa   = '{$this->h_causa}' ";
}
else{
   $this->error = 0;
   $this->msg_error = '';
   $p_sql_r="insert into ".$this->base_web."rem_historial values 
          ( '{$this->empresa}','{$this->tdoc}' ,'{$this->letra}','{$this->sucur}','{$this->numero}',
            '{$this->h_fecha}','{$this->h_hoja_ruta}','{$this->h_causa}',
            '{$this->h_bultos}','{$this->h_unidades}','{$this->h_volumen}','{$this->h_otros}',
            '{$this->h_estado}','{$this->h_obser}' )";

}
$resultado=@odbc_exec($this->conexion,$p_sql_r);
if (!$resultado) {
   $this->error     = 1;
   $this->msg_error = "24- Error. No se pudo insertar [rem_historial] !!";
   return;
}
if (odbc_num_rows($resultado) != 1){
   $this->error     = 1;
   $this->msg_error = "25- Error. No se pudo insertar [rem_historial] !!";
   return;
}
odbc_free_result($resultado);

return;
}

function __destruct()
{
  //odbc_close($this->conexion);
}
}
?>