Advertisement
Guest User

Untitled

a guest
Sep 18th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. <?php
  2.  
  3. function piscofins($valor) {
  4. return(strtr($valor, array('S' => 'T', 'N' => 'F')));
  5. }
  6.  
  7. function tipo_iva($valor2) {
  8. return(strtr($valor2, array('IVA' => 'P', 'Pauta' => 'F')));
  9. }
  10.  
  11.  
  12. //Abre o arquivo
  13. $fp = fopen ("tributos.csv","r");
  14.  
  15. if (!$fp) {echo "<p>Não foi possível abrir o arquivo.</p>"; exit;}
  16.  
  17. while (!feof($fp)):
  18. $line = fgets($fp, 2048);
  19. $out = array($line);
  20.  
  21. // aqui vc coloca os campos da sua tabela
  22. list (
  23. $id,
  24. $descritivo,
  25. $classificacao_fiscal,
  26. $piscofins,
  27. $tributacao_venda,
  28. $icms_venda,
  29. $reducao_venda,
  30. $tipo_iva,
  31. $iva,
  32. $st_venda,
  33. ) = split (";", $out[0]);
  34.  
  35.  
  36. $classificacao_fiscal;
  37. $piscofins = trim(piscofins($piscofins));
  38. $tipo_iva = trim(tipo_iva($tipo_iva));
  39. $tributacao_venda = trim($tributacao_venda);
  40. $icms_venda =($icms_venda)/100;
  41. $reducao = trim($reducao_venda)/100;
  42. $acerto = str_replace(".",",","$reducao");
  43. $iva =trim($iva)/100;
  44. $acerto2 = str_replace(".",",","$iva");
  45.  
  46. //$trim = trim($st_venda);
  47. $st_venda = trim(str_replace(" ","","$st_venda"));
  48. $st_venda = str_pad($st_venda, 3, "0", STR_PAD_LEFT);
  49.  
  50.  
  51. //Conexão com banco Oracle
  52.  
  53. $user = "proreg"; // Nome de usuário do banco de dados
  54. $pass = "automa"; // Senha do banco de dados
  55. $host = "192.168.56.102"; // Host onde se encontra o banco Oracle
  56. $port = "1521"; // Porta que é liberada para conectar ao banco
  57. $servico = "arius"; // Servico do banco de dados que será acessado, configurado no client.
  58. $db = "(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = $host)(PORT = $port)))(CONNECT_DATA = (SERVICE_NAME = $servico)))";
  59. $c = OCILogon($user,$pass,$db) or die ("Não foi possível conectar no banco de dados");
  60.  
  61. //Drop da Tebela teste se existir
  62. //$s = OCIParse($c, "drop table teste");
  63. //OCICommit($c);
  64.  
  65. //Cria a tabela temporária teste
  66. $cria = OCIParse($c, "create table teste as
  67. select
  68. p.id,
  69. p.descritivo,
  70. p.classificacao_fiscal,
  71. p.piscofins,
  72. pe.tributacao_venda,
  73. pe.icms_venda,
  74. pe.reducao_venda,
  75. pe.tipo_iva,
  76. pe.iva,
  77. pe.st_venda
  78. from produtos p, produtos_estado pe, deptos d");
  79. OCIExecute($cria, OCI_DEFAULT);
  80. OCICommit($c);
  81.  
  82. //Inserção dos dados no banco oracle
  83. $s = OCIParse($c, "insert into teste (id, descritivo, classificacao_fiscal, piscofins, tributacao_venda, icms_venda, reducao_venda, tipo_iva,iva, st_venda )
  84. values ('$id','$descritivo','$classificacao_fiscal','$piscofins','$tributacao_venda','$icms_venda','$acerto','$tipo_iva','$acerto2','$st_venda')");
  85.  
  86. OCIExecute($s, OCI_DEFAULT);
  87. //Commit e save changes...
  88. OCICommit($c);
  89.  
  90. //Update das taelas oficiais do banco
  91.  
  92.  
  93. //Gerar erros
  94. $err = OCIError($s);
  95. $message = "Message: " . $err["message"] . "" ;
  96. $message2 = "Statement: " . $err["sqltext"] . "--";
  97.  
  98. //print $message;
  99. //print $message2;
  100.  
  101. //gerar arquivo de erros
  102. //$fp = fopen("./erros/erros.txt", "w");
  103. //fwrite($fp, "$s,$c"); // grava a string no arquivo. Se o arquivo não existir ele será criado
  104. //fclose($fp);
  105.  
  106. $fp++;
  107. endwhile;
  108. fclose($fp);
  109.  
  110. ?>
  111.  
  112. <?php
  113. echo"
  114. <META HTTP-EQUIV=REFRESH CONTENT='0; URL=index.php'>
  115. <script type=\"text/javascript\">
  116. alert(\"Arquivos Importados Verifique Arquivos de Erros\");
  117. </script>
  118. ";
  119. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement