You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 lines
6.6 KiB

4 years ago
  1. #!/usr/bin/php
  2. <?php
  3. require_once "/var/www/html/prgdmug/F_DMUG.php";
  4. require_once "/var/www/html/prgdmug/inc/AppConfig.php";
  5. require_once "/var/www/html/prgdmug/inc/PostgreClass.php";
  6. require_once "/var/www/html/prgdmug/inc/ObtieneDatosPg.php";
  7. $salida = shell_exec( "/root/countfphp.sh" );
  8. echo "Salida $salida\n";
  9. if( $salida >= 4 ){
  10. system( "/usr/bin/killall InterFacFis.php" );
  11. }
  12. $fec = date('l jS \of F Y h:i:s A');
  13. echo "$fec:Inicia Proceso InterFactFis ....\n";
  14. $server= "192.168.1.5";
  15. $port = 1030; //1030
  16. $hs = "DEMIURGO10-MCANET";
  17. $user = "general";
  18. $pass = "123456789";
  19. $pid = getmypid();
  20. $limit = 50;
  21. $veces_error_server = 0;
  22. $appConfig =& new AppConfig;
  23. /* Crea un objeto para el manejo postgres */
  24. $dataBD_PG =& $appConfig->BASE_DATOS_PG;
  25. $manejaBD_PG =& new PostgreClass($dataBD_PG["host"], $dataBD_PG["name"],
  26. $dataBD_PG["user"], $dataBD_PG["pass"]);
  27. $obtieneDatos_pg = & new ObtieneDatos_PG($appConfig, $manejaBD_PG);
  28. $pg_sql_factu = "SELECT * FROM forumvta.factu WHERE fac_trans = 0 AND (fac_tip = 'PV' OR fac_tip = 'PN') AND fac_nexti > 0 LIMIT $limit";
  29. $v_FACTU = $obtieneDatos_pg->obtenerDatos($pg_sql_factu);
  30. $v_i=0;
  31. $control = count( $v_FACTU[0] );
  32. //echo "control = $control\n";//responde 101 campos si leyo OK
  33. if ( $control < 10 )
  34. {
  35. echo "NO HAY FACTURAS PARA TRANSFERIR\n";
  36. Finalizar();
  37. }
  38. for( $v_i=0 ; $v_FACTU[$v_i]['fac_nro'] ; $v_i++ )
  39. {
  40. $FAC_SUC = $v_FACTU[$v_i]['fac_suc'] ;
  41. $FAC_TIP = $v_FACTU[$v_i]['fac_tip'] ;
  42. $FAC_STIP= $v_FACTU[$v_i]['fac_stip'] ;
  43. $FAC_NRO = $v_FACTU[$v_i]['fac_nro'] ;
  44. $NROEXT = $v_FACTU[$v_i]['fac_nexti'];
  45. $fec = date('l jS \of F Y h:i:s A');
  46. echo "$fec .... FACTURA pos = $v_i sucu = $FAC_SUC tip=$FAC_TIP nro = $FAC_NRO NEXT = $NROEXT \n";
  47. $ConDMUG = new ConexDMUG( $server , $port , $hs ,$user , $pass );
  48. $ConDMUG->SetProgram( "Interfaz_FacFisPG_Forum" );
  49. Carga_CABECERA( $ConDMUG , $v_FACTU , $v_i );
  50. $ConDMUG->SetParameter( "CANTIDAD_CABECERAS" , 1 );
  51. $ConDMUG->SetParameter( "FECHA_TRASMITE" , date() );
  52. $ConDMUG->SetParameter( "HORA_TRASMITE" , time() );
  53. if ( $ConDMUG->Execute_DMUG() < 0)
  54. {
  55. $fec = date('l jS \of F Y h:i:s A');
  56. echo "$fec : ERROR EN CONEXION CON SERVER , esperando 3 segundos para continuar ....\n";
  57. $veces_error_server++;
  58. if ( $veces_error_server > 2 )
  59. {
  60. $fec = date('l jS \of F Y h:i:s A');
  61. echo "$fec :FINALIZA POR ERROR DE CONEXION CON SERVER !!!!!!!!!!\n";
  62. Finalizar();
  63. }
  64. sleep(3);
  65. continue;
  66. }
  67. $RESULTADO = $ConDMUG->GetChild( "STRERROR" );
  68. echo "RESULTADO:".$RESULTADO."\n" ;
  69. echo "ERROR:".$ConDMUG->GetChild( "ERROR" )."\n" ;
  70. echo "INFORME :".$ConDMUG->GetChild( "INFO1" )."\n" ;
  71. echo "INFORME :".$ConDMUG->GetChild( "INFO2" )."\n" ;
  72. echo "PUTRECORD:".$ConDMUG->GetChild( "PUTRECORD" )."\n" ;
  73. echo "REGISTROS:".$ConDMUG->GetChild( "REGISTROS" )."\n" ;
  74. $ConDMUG->CloseConex();
  75. if ( $RESULTADO== "EXACTO" )
  76. {
  77. echo "Se marca FACTU $FAC_NRO en PG TRANS es 1 \n";
  78. Marca_CABECERA( $obtieneDatos_pg , $v_FACTU , $v_i );
  79. }
  80. else
  81. {
  82. echo "ERROR en $FAC_NRO \n";
  83. }
  84. echo "-------------------------------------------------------\n";
  85. sleep(1);
  86. }
  87. unset($v_FACTU);
  88. Finalizar();
  89. /***********************************************************************/
  90. function Finalizar()
  91. {
  92. system( "/bin/rm /tmp/InterFactFis.blk" );
  93. exit();
  94. }
  95. /***********************************************************************/
  96. /*----------------------- function Carga_CABECERA ---------------------*/
  97. /***********************************************************************/
  98. function Carga_CABECERA( $ConDMUG , $p_FACTU , $v_i )
  99. {
  100. # define FACTU_FAC_SUC (dbfield) 0x0a01 /* Integer /
  101. $ConDMUG->SetParameter("FAC_SUC" , $p_FACTU[$v_i]['fac_suc'] );
  102. if ( $p_FACTU[$v_i]['fac_tip']== "PV" )
  103. $FAC_TIP = "pv" ;
  104. if ( $p_FACTU[$v_i]['fac_tip']== "PN" )
  105. $FAC_TIP = "pn" ;
  106. echo "FACTURA pos tip=$FAC_TIP \n";
  107. # define FACTU_FAC_TIP (dbfield) 0x0a02 /* String
  108. # $ConDMUG->SetParameter("FAC_TIP" , $p_FACTU[$v_i]['fac_tip'] );
  109. $ConDMUG->SetParameter("FAC_TIP" , $FAC_TIP );
  110. # define FACTU_FAC_STIP (dbfield) 0x0a03 /* Integer
  111. $ConDMUG->SetParameter("FAC_STIP" , $p_FACTU[$v_i]['fac_stip'] );
  112. # define FACTU_FAC_NRO (dbfield) 0x0a04 /* Long
  113. $ConDMUG->SetParameter("FAC_NRO" , $p_FACTU[$v_i]['fac_nro'] );
  114. # define FACTU_FAC_SEXT (dbfield) 0x0a47 /* String /
  115. $ConDMUG->SetParameter("FAC_SEXT" , $p_FACTU[$v_i]['fac_sext'] );
  116. # define FACTU_FAC_NEXTI (dbfield) 0x0a48 /* Long /
  117. $ConDMUG->SetParameter("FAC_NEXTI", $p_FACTU[$v_i]['fac_nexti'] );
  118. # define FACTU_FAC_NEXTF (dbfield) 0x0a49 /* Long /
  119. $ConDMUG->SetParameter("FAC_NEXTF", $p_FACTU[$v_i]['fac_nextf'] );
  120. # define FACTU_FAC_EMP (dbfield) 0x0a60 /* Integer /
  121. $ConDMUG->SetParameter("FAC_EMP" , $p_FACTU[$v_i]['fac_emp'] );
  122. # define FACTU_FAC_FEXT (dbfield) 0x0a44 /* Date /
  123. $ConDMUG->SetParameter("FAC_FEXT" , $p_FACTU[$v_i]['fac_fext'] );
  124. # define FACTU_FAC_TEXT (dbfield) 0x0a45 /* String /
  125. $ConDMUG->SetParameter("FAC_TEXT" , $p_FACTU[$v_i]['fac_text'] );
  126. # define FACTU_FAC_LEXT (dbfield) 0x0a46 /* Integer /
  127. $ConDMUG->SetParameter("FAC_LEXT" , $p_FACTU[$v_i]['fac_lext'] );
  128. }
  129. /***********************************************************************/
  130. /*----------------------- function Carga_CABECERA ---------------------*/
  131. /***********************************************************************/
  132. function Marca_CABECERA( $obtieneDatos_pg , $p_FACTU , $v_i )
  133. {
  134. $SUC = $p_FACTU[$v_i]['fac_suc'];
  135. $TIP = $p_FACTU[$v_i]['fac_tip'];
  136. $STIP = $p_FACTU[$v_i]['fac_stip'];
  137. $NRO = $p_FACTU[$v_i]['fac_nro'];
  138. echo "FACTURA sucu = $SUC tip=$TIP nro = $NRO STIP = $STIP \n";
  139. $pg_sql_factu = "UPDATE forumvta.factu SET fac_trans = 1 WHERE fac_suc = $SUC AND fac_tip = '$TIP' ";
  140. $pg_sql_factu .="AND fac_stip = $STIP AND fac_nro = $NRO ";
  141. $obtieneDatos_pg->obtenerDatos( $pg_sql_factu );
  142. return 1;
  143. }
  144. ?>