<?php
global $w_hora;

$w_hora = date("Y-m-d H:i:s"); 
echo "\n", $w_hora; 
echo " - Inicio del Proceso\n";   

$connection = new PDO('dblib:host=192.168.10.15;dbname=Fidelitas;charset=utf8','sa','KraDQlo');

$w_hora = date("Y-m-d H:i:s"); 
echo "\n", $w_hora;  

$stmt  = $connection->prepare("EXEC procesamiento_insur_salida");
$stmt->setFetchMode(PDO::FETCH_OBJ); 
if ($stmt) {
  $stmt->execute();
}
/*
    Posicion 1 a 11      CUIT    -> 11
    Posicion 12 a 189    NOMBRE  -> 178
    Posicion 190 al 396  DETALLE -> 207
*/
$balances = $stmt->fetchAll();
$file = '';
foreach($balances as $info){
        $line =
        $info->cuit .
        $info->nombre .
        $info->detalle;
        $file .= $line."\n";
}
$file_txt  = '/var/www/html/compartido/insur/out/salida_insur_'.date("Ymd").'.txt';
file_put_contents($file_txt, $file);

$w_hora = date("Y-m-d H:i:s"); 
echo "\n\n", $w_hora; 
echo " - Fin del Proceso\n\n"; 

?>


