Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.03 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4. include("conexion.php");
  5.  
  6. $institucion= $_GET['institucion'];
  7. //header('Content-disposition: attachment; filename="'.$_SESSION['institucion'].date("Ymd",strtotime("+1 day")).'.TXT');
  8. //header('Content-type: text/plain');
  9.  
  10.  
  11. $conn = conectar();
  12. $resultados = sqlsrv_query($conn,"select 1 ,'0782300202'+
  13. cast(year(getdate()) as varchar)+
  14. right(100+month(getdate()),2)+
  15. right(100+day(getdate()+1),2)+
  16. 'SERVIPAG'+
  17. right(cast((COUNT(saldo)+1000000000) as varchar),6) +
  18. right(cast((sum(montoTotal)+1000000000000000) As numeric),14)+ ' ' as col1
  19. from
  20. (
  21. select saldo,
  22. case -- monto: SUMA EL SALDO MAS LOS INTERESES Y SI LA DIF EN DIAS ES > 30 TAMBIEN LO SUMA
  23. when DATEDIFF(day,fecha_vencimiento,getdate())<= 0 then
  24. saldo
  25. when DATEDIFF(day,fecha_vencimiento,getdate())>30 then
  26. saldo+round(((saldo*5)/100),0)+
  27. (round((((saldo*1.2)/100)/30)*DATEDIFF(day,fecha_vencimiento,getdate()),0))
  28. else -- SUMA EL SALDO MAS LOS INTERESES (no contempla g.cobrazas)
  29. saldo+(round((((saldo*1.2)/100)/30)*DATEDIFF(day,fecha_vencimiento,getdate()),0))
  30.  
  31. end
  32. as montoTotal
  33. from servipag)
  34. x
  35. -- + ' ' from servipag
  36.  
  37. union
  38.  
  39. select 2
  40. rut,right('000'+substring(rut,1,len(rut)-2),10)+right('000'+substring(rut,1,len(rut)-2),10)+ SUBSTRING(rut,LEN(rut),1)+
  41. '00000000000000000000'+ -- DIRECCION
  42. '3'+ -- TIPO DOCUMENTO
  43. RIGHT(cast(numero_cuota+10000000000000 as varchar),12)+ -- NUMERO DE DOCUMENTO
  44. --case -- monto: fecha proxima a vencer
  45. --when DATEDIFF(day,fecha_vencimiento,getdate())<= 0 then
  46. --cast(cast((saldo+0) As numeric)AS varchar)
  47. --end+
  48. case -- monto: SUMA EL SALDO MAS LOS INTERESES Y SI LA DIF EN DIAS ES > 30 TAMBIEN LO SUMA
  49. when DATEDIFF(day,fecha_vencimiento,getdate())<= 0 then
  50. right(cast(cast((saldo+10000000000000) As numeric)AS varchar),8)
  51. when DATEDIFF(day,fecha_vencimiento,getdate())>30 then
  52. RIGHT(cast(saldo+10000000000000+cast(round(((saldo*5)/100),0) as numeric)+
  53. cast(round((((saldo*1.2)/100)/30)*DATEDIFF(day,fecha_vencimiento,getdate()),0) as numeric) as varchar),8)
  54. else -- SUMA EL SALDO MAS LOS INTERESES (no contempla g.cobrazas)
  55. RIGHT(cast(saldo+1000000000000+cast(round((((saldo*1.2)/100)/30)*DATEDIFF(day,fecha_vencimiento,getdate()),0) as numeric) as varchar),8)
  56. end+
  57. '00000000'+ -- SALDO ANTERIOR
  58. cast(year(fecha_vencimiento) as varchar)+right(cast((month(fecha_vencimiento))+100 as varchar),2)+right(cast((100+day(fecha_vencimiento)) as varchar),2)+ -- FECHA VCTO YYYYMMAA
  59. case -- CALCULO interes
  60. when DATEDIFF(day,fecha_vencimiento,getdate())<=0 then '00000000'
  61. when DATEDIFF(day,fecha_vencimiento,getdate())>0 then right(cast(round((((saldo*1.2)/100)/30)*DATEDIFF(day,fecha_vencimiento,getdate()),0) as numeric)+1000000000,8)
  62. end +
  63. case -- CALCULO G.cobranzas
  64. when DATEDIFF(day,fecha_vencimiento,getdate())<=30 then '00000000'
  65. when DATEDIFF(day,fecha_vencimiento,getdate())>30 then right(cast(round((((saldo*5)/100)),0) as numeric)+1000000000,8)
  66. end+
  67. --'0'+
  68. --right(numeral_cuota,2)+ -- NÚMERO DE CUOTA
  69. RIGHT(cast(numeral_cuota+100000 as varchar),3)+
  70. RIGHT(cast(saldo+10000000000000 as varchar),8)-- SALDO
  71. as col1
  72. from servipag");//, array(), array("Scrollable"=>"buffered"));
  73. $i = 0;
  74.  
  75. $file = fopen('\\\\NB_RGRAF\\archivosExportados\\'.$_SESSION['institucion'].date("Ymd",strtotime("+1 day")).'.TXT', "w");
  76.  
  77.  
  78. while ($datos = sqlsrv_fetch_array($resultados))
  79. {
  80. $i++;
  81. $row_count = sqlsrv_num_rows( $resultados);
  82.  
  83. if($row_count != $i)
  84. {
  85. fwrite($file, $datos['col1']."\n");
  86. }
  87. else
  88. {
  89. fwrite($file, $datos['col1']);
  90. }
  91. }
  92.  
  93.  
  94. fclose($file);
  95. desconectar($conn);
  96.  
  97. //echo" Archivo creado Correctamente, $i Datos Exportados. ";
  98.  
  99. //echo" I : $i";
  100. //echo " Row Count: $row_count";
  101. //echo " datos: $datos";
  102.  
  103. ?>
  104. <div align="center" >
  105. <img src="img/completed.gif" width="100" height="100" />
  106. <p>Archivo creado Correctamente...</p>
  107.  
  108. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement