Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- include("conexion.php");
- $institucion= $_GET['institucion'];
- //header('Content-disposition: attachment; filename="'.$_SESSION['institucion'].date("Ymd",strtotime("+1 day")).'.TXT');
- //header('Content-type: text/plain');
- $conn = conectar();
- $resultados = sqlsrv_query($conn,"select 1 ,'0782300202'+
- cast(year(getdate()) as varchar)+
- right(100+month(getdate()),2)+
- right(100+day(getdate()+1),2)+
- 'SERVIPAG'+
- right(cast((COUNT(saldo)+1000000000) as varchar),6) +
- right(cast((sum(montoTotal)+1000000000000000) As numeric),14)+ ' ' as col1
- from
- (
- select saldo,
- case -- monto: SUMA EL SALDO MAS LOS INTERESES Y SI LA DIF EN DIAS ES > 30 TAMBIEN LO SUMA
- when DATEDIFF(day,fecha_vencimiento,getdate())<= 0 then
- saldo
- when DATEDIFF(day,fecha_vencimiento,getdate())>30 then
- saldo+round(((saldo*5)/100),0)+
- (round((((saldo*1.2)/100)/30)*DATEDIFF(day,fecha_vencimiento,getdate()),0))
- else -- SUMA EL SALDO MAS LOS INTERESES (no contempla g.cobrazas)
- saldo+(round((((saldo*1.2)/100)/30)*DATEDIFF(day,fecha_vencimiento,getdate()),0))
- end
- as montoTotal
- from servipag)
- x
- -- + ' ' from servipag
- union
- select 2
- rut,right('000'+substring(rut,1,len(rut)-2),10)+right('000'+substring(rut,1,len(rut)-2),10)+ SUBSTRING(rut,LEN(rut),1)+
- '00000000000000000000'+ -- DIRECCION
- '3'+ -- TIPO DOCUMENTO
- RIGHT(cast(numero_cuota+10000000000000 as varchar),12)+ -- NUMERO DE DOCUMENTO
- --case -- monto: fecha proxima a vencer
- --when DATEDIFF(day,fecha_vencimiento,getdate())<= 0 then
- --cast(cast((saldo+0) As numeric)AS varchar)
- --end+
- case -- monto: SUMA EL SALDO MAS LOS INTERESES Y SI LA DIF EN DIAS ES > 30 TAMBIEN LO SUMA
- when DATEDIFF(day,fecha_vencimiento,getdate())<= 0 then
- right(cast(cast((saldo+10000000000000) As numeric)AS varchar),8)
- when DATEDIFF(day,fecha_vencimiento,getdate())>30 then
- RIGHT(cast(saldo+10000000000000+cast(round(((saldo*5)/100),0) as numeric)+
- cast(round((((saldo*1.2)/100)/30)*DATEDIFF(day,fecha_vencimiento,getdate()),0) as numeric) as varchar),8)
- else -- SUMA EL SALDO MAS LOS INTERESES (no contempla g.cobrazas)
- RIGHT(cast(saldo+1000000000000+cast(round((((saldo*1.2)/100)/30)*DATEDIFF(day,fecha_vencimiento,getdate()),0) as numeric) as varchar),8)
- end+
- '00000000'+ -- SALDO ANTERIOR
- 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
- case -- CALCULO interes
- when DATEDIFF(day,fecha_vencimiento,getdate())<=0 then '00000000'
- 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)
- end +
- case -- CALCULO G.cobranzas
- when DATEDIFF(day,fecha_vencimiento,getdate())<=30 then '00000000'
- when DATEDIFF(day,fecha_vencimiento,getdate())>30 then right(cast(round((((saldo*5)/100)),0) as numeric)+1000000000,8)
- end+
- --'0'+
- --right(numeral_cuota,2)+ -- NÚMERO DE CUOTA
- RIGHT(cast(numeral_cuota+100000 as varchar),3)+
- RIGHT(cast(saldo+10000000000000 as varchar),8)-- SALDO
- as col1
- from servipag");//, array(), array("Scrollable"=>"buffered"));
- $i = 0;
- $file = fopen('\\\\NB_RGRAF\\archivosExportados\\'.$_SESSION['institucion'].date("Ymd",strtotime("+1 day")).'.TXT', "w");
- while ($datos = sqlsrv_fetch_array($resultados))
- {
- $i++;
- $row_count = sqlsrv_num_rows( $resultados);
- if($row_count != $i)
- {
- fwrite($file, $datos['col1']."\n");
- }
- else
- {
- fwrite($file, $datos['col1']);
- }
- }
- fclose($file);
- desconectar($conn);
- //echo" Archivo creado Correctamente, $i Datos Exportados. ";
- //echo" I : $i";
- //echo " Row Count: $row_count";
- //echo " datos: $datos";
- ?>
- <div align="center" >
- <img src="img/completed.gif" width="100" height="100" />
- <p>Archivo creado Correctamente...</p>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement