129 lines
4.2 KiB
PHP
129 lines
4.2 KiB
PHP
<?php
|
|
/**
|
|
* Récupère les bilans au format PDF
|
|
* 15 19 * * 1-5 /var/www/batch/fedasoBilans.php -d >> /var/www/log/fedasoBilans.log
|
|
*/
|
|
|
|
// Define path to application directory
|
|
defined('APPLICATION_PATH')
|
|
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
|
|
|
|
// Define application environment
|
|
defined('APPLICATION_ENV')
|
|
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
|
|
|
|
// Ensure library/ is on include_path
|
|
set_include_path(implode(PATH_SEPARATOR, array(
|
|
realpath(APPLICATION_PATH . '/../library'),
|
|
get_include_path(),
|
|
)));
|
|
|
|
/** Zend_Application */
|
|
require_once 'Zend/Application.php';
|
|
|
|
// Create application, bootstrap, and run
|
|
$application = new Zend_Application(
|
|
APPLICATION_ENV,
|
|
APPLICATION_PATH . '/configs/application.ini'
|
|
);
|
|
|
|
//Options
|
|
try {
|
|
$opts = new Zend_Console_Getopt(array(
|
|
'help|?' => "Displays usage information.",
|
|
'source' => "source (extranet)",
|
|
'debug' => "Mode debug",
|
|
));
|
|
$opts->parse();
|
|
} catch (Zend_Console_Getopt_Exception $e) {
|
|
echo $e->getUsageMessage();
|
|
exit;
|
|
}
|
|
|
|
//Usage
|
|
if( isset($opts->help) || count($opts->getOptions())==0 )
|
|
{
|
|
echo "Gestion des échanges de bilan saisie.\n";
|
|
echo $opts->getUsageMessage();
|
|
exit;
|
|
}
|
|
|
|
$c = new Zend_Config($application->getOptions());
|
|
$db = Zend_Db::factory($c->profil->db->metier);
|
|
Zend_Db_Table_Abstract::setDefaultAdapter($db);
|
|
|
|
$pathSend = $c->profil->path->storage . '/clients/bilansext/send';
|
|
$pathBackup = $c->profil->path->storage . '/clients/bilansext/send/done';
|
|
|
|
// Lecture du dossier des dépots de bilans à demander en saisie
|
|
if ($opts->source == 'extranet')
|
|
{
|
|
echo date('Y-m-d H:i:s') ." - Chargement bilan source extranet.\n";
|
|
|
|
$dh = opendir($pathSend);
|
|
while (false !== ($filename = readdir($dh)))
|
|
{
|
|
if ($filename != '.' && $filename != '..' && substr($filename, -4) == '.pdf')
|
|
{
|
|
if (preg_match('/([0-9]{9})_([CNS])([0-9]{8})_([0-9]{2})_([0-9]{1})_([0-9]{1,})_([0-9]{1,}).pdf/', $filename, $t))
|
|
{
|
|
$filetime = date('YmdHis', filectime($pathSend.'/'.$filename));
|
|
|
|
$siren = $t[1];
|
|
$format = $t[2];
|
|
$cloture = $t[3];
|
|
$duree = $t[4];
|
|
$confidentiel = $t[5];
|
|
$userId = $t[6];
|
|
$extranetId = $t[7];
|
|
|
|
if ( false !== ( $file = file_get_contents($pathSend.'/'.$filename) ) )
|
|
{
|
|
//Number of page
|
|
$pages = preg_match_all( "/\/Page\W/", $file, $matches );
|
|
|
|
//Pdf size
|
|
$size = filesize($pathSend.'/'.$filename);
|
|
}
|
|
|
|
$dataInsert = array(
|
|
'siren' => $siren,
|
|
'dateCloture' => $cloture,
|
|
'format' => $format,
|
|
'duree' => $duree,
|
|
'confidentiel' => $confidentiel,
|
|
'idUtilisateur' => $userId,
|
|
'idExtranet' => $extranetId,
|
|
'environnement' => '',
|
|
'refDoc' => $filename,
|
|
'dateEntree' => $filetime,
|
|
'dateEnvoi' => date('YmdHis'),
|
|
'pdfNum' => 0,
|
|
'pdfSize' => $size,
|
|
'pdfPage' => $pages,
|
|
);
|
|
|
|
$insertOk = false;
|
|
try {
|
|
$db->insert('sdv1.fedaso_bilans', $dataInsert);
|
|
$insertOk = true;
|
|
} catch (Zend_Db_Exception $e) {
|
|
//Doublon
|
|
if ($e->getCode() == '1062') {
|
|
$insertOk = false;
|
|
}
|
|
}
|
|
|
|
//Copier le fichier
|
|
if ($insertOk === true) {
|
|
if (!rename($pathSend.'/'.$filename, $pathBackup.'/'.$filename)) {
|
|
echo date('Y-m-d H:i:s') ." - Impossible de déplacer le fichier $filename.\n";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
echo date('Y-m-d H:i:s') ." - FIN du script.\n";
|