Commande de saisie de bilan
This commit is contained in:
parent
b03da5d6e8
commit
30bf34da4a
@ -688,128 +688,119 @@ class FinanceController extends Zend_Controller_Action
|
||||
}
|
||||
|
||||
/**
|
||||
* Envoi de bilan pour saisie
|
||||
* L'envoi se déroule en plusieurs étapes
|
||||
* 1 - Saisie des informations
|
||||
* 2 - Validation du formulaire
|
||||
* 3 -
|
||||
* Commande de la saisie de bilan
|
||||
* Enregistrement des caractéristiques, obtention référence commande puis upload fichier
|
||||
*/
|
||||
public function saisiebilanAction()
|
||||
{
|
||||
$this->_helper->layout()->disableLayout();
|
||||
|
||||
$request = $this->getRequest();
|
||||
$user = new Scores_Utilisateur();
|
||||
$params = $request->getParams();
|
||||
$request = $this->getRequest();
|
||||
$user = new Scores_Utilisateur();
|
||||
$params = $request->getParams();
|
||||
|
||||
$bilanSaisie = new Application_Model_BilanSaisie();
|
||||
|
||||
$this->view->assign('email', $user->getEmail());
|
||||
$this->view->assign('siren', $params['siren']);
|
||||
|
||||
$ref = $params['ref'];
|
||||
if ($request->isPost())
|
||||
{
|
||||
//Validation du formulaire
|
||||
$valideField = true;
|
||||
if ( empty($params['siren']))
|
||||
{
|
||||
$valideField = false;
|
||||
}
|
||||
if ( empty($params['dateCloture'])
|
||||
&& !preg_match('/^[0-9]{2}\/[0-9]{2}\/[0-9]{4}/', $params['dateCloture'])
|
||||
&& !checkdate(substr($params['dateCloture'],3,2),substr($params['dateCloture'],0,2),substr($params['dateCloture'],6,2)))
|
||||
{
|
||||
$valideField = false;
|
||||
}
|
||||
if ( empty($params['dureeExercice']))
|
||||
{
|
||||
$valideField = false;
|
||||
}
|
||||
if ($valideField === true)
|
||||
{
|
||||
$ws = new Scores_Ws_Client('order', '0.1');
|
||||
$parameters = new stdClass();
|
||||
$parameters->siren = $params['siren'];
|
||||
$parameters->date = substr($params['dateCloture'],6,4).'-'.substr($params['dateCloture'],3,2).'-'.substr($params['dateCloture'],0,2);
|
||||
$parameters->type = $params['format'];
|
||||
$parameters->source = 'extranet';
|
||||
$parameters->private = $params['confidentiel'];
|
||||
$result = $ws->setBilanInput($parameters);
|
||||
if ($result === false) {
|
||||
$this->view->msg = "Erreur lors de l'enregistrement des informations";
|
||||
} else {
|
||||
Zend_Registry::get('firebug')->info($result);
|
||||
$this->view->ref = strtoupper($result);
|
||||
$this->view->fileref = $params['siren'] . '_' . $params['format'] . '_' .
|
||||
substr($params['dateCloture'],6,4) . substr($params['dateCloture'],3,2) .
|
||||
substr($params['dateCloture'],0,2) . '_' . strtoupper($result);
|
||||
$session = new Scores_Session_Entreprise($params['siren']);
|
||||
$this->view->raisonSociale = $session->getRaisonSociale();
|
||||
$this->view->bilanCloture = $params['dateCloture'];
|
||||
$this->view->bilanDuree = $params['dureeExercice'];
|
||||
switch($params['format']){
|
||||
case 'C':
|
||||
$this->view->type = 'consolidé';
|
||||
break;
|
||||
case 'N':
|
||||
$this->view->type = 'réel normal (liasse 2050)';
|
||||
break;
|
||||
case 'S':
|
||||
$this->view->type = 'simplifié (liasse 2033)';
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->view->msg = "Formulaire invalide.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Annulation de la saisie
|
||||
if ($params['annule'])
|
||||
{
|
||||
$data = array( 'fichier' => '' );
|
||||
$bilanSaisie->update($data, "ref='$ref'");
|
||||
echo 'Saisie bilan annulé';
|
||||
exit;
|
||||
}
|
||||
//Envoi du fichier @todo ça passe pas
|
||||
elseif ($params['upload'])
|
||||
{
|
||||
if ( count($_FILES)==1 ){
|
||||
$n = $_FILES['fichier']['name'];
|
||||
$s = $_FILES['fichier']['size'];
|
||||
$tmp_name = $_FILES['fichier']['tmp_name'];
|
||||
//Vérifier que l'extension du fichier est bien correcte
|
||||
$extValide = array('pdf', 'tiff');
|
||||
$extension = strrchr($n,'.');
|
||||
$extension = strtolower(substr($extension,1));
|
||||
if ( in_array($extension, $extValide) ) {
|
||||
//Lecture dans la bdd des informations
|
||||
$infos = $bilanSaisie->getInfosBilan($ref);
|
||||
$name = $infos['ref'].'-'.$infos['siren'].'.'.$extension;
|
||||
$c = Zend_Registry::get('config');
|
||||
$file = realpath($c->profil->path->data).'/bilanclient/'.$name;
|
||||
if ( move_uploaded_file($tmp_name, $file) ){
|
||||
$bilanSaisie->setFilename($ref, $name);
|
||||
switch($infos['format']){
|
||||
case 'C':
|
||||
$type = 'consolidé';
|
||||
break;
|
||||
case 'N':
|
||||
$type = 'réel normal';
|
||||
break;
|
||||
case 'S':
|
||||
$type = 'simplifié';
|
||||
break;
|
||||
}
|
||||
$session = new Scores_Session_Entreprise($params['siren']);
|
||||
$this->view->assign('raisonSociale', $session->getRaisonSociale());
|
||||
$this->view->assign('size', filesize($file));
|
||||
$this->view->assign('name', $name);
|
||||
$this->view->assign('infos', $infos);
|
||||
$this->view->assign('ref', $ref);
|
||||
$this->view->assign('upload', true);
|
||||
} else {
|
||||
$this->view->assign('upload', false);
|
||||
$this->view->assign('errMsg', "<br/>Erreur lors de l'envoi du fichier!");
|
||||
}
|
||||
} else {
|
||||
$this->view->assign('upload', false);
|
||||
$this->view->assign('errMsg', "Extension de fichier invalide.");
|
||||
}
|
||||
} else {
|
||||
$this->view->assign('upload', false);
|
||||
$this->view->assign('errMsg', "<br/>Erreur.");
|
||||
}
|
||||
$this->renderScript('finance/saisiebilan-upload.phtml');
|
||||
}
|
||||
//Validation du formulaire
|
||||
elseif (isset($params['method']))
|
||||
{
|
||||
$valideField = true;
|
||||
if ( empty($params['email'])) {
|
||||
$valideField = false;
|
||||
}
|
||||
if ( empty($params['method'])) {
|
||||
$valideField = false;
|
||||
}
|
||||
if ( empty($params['siren'])) {
|
||||
$valideField = false;
|
||||
}
|
||||
if ( empty($params['dateCloture'])
|
||||
&& !preg_match('/^[0-9]{2}\/[0-9]{2}\/[0-9]{4}/', $params['dateCloture'])
|
||||
&& checkdate(substr($params['dateCloture'],3,2),substr($params['dateCloture'],0,2),substr($params['dateCloture'],6,2))){
|
||||
$valideField = false;
|
||||
}
|
||||
if ( empty($params['dureeExercice'])) {
|
||||
$valideField = false;
|
||||
}
|
||||
if ($valideField){
|
||||
$ref = $bilanSaisie->setInformations(
|
||||
$user->getIdClient(),
|
||||
$user->getId(),
|
||||
$user->getLogin(),
|
||||
$params['email'],
|
||||
$params['method'],
|
||||
$params['confidentiel'],
|
||||
$params['siren'],
|
||||
$params['dateCloture'],
|
||||
$params['format'],
|
||||
$params['dureeExercice']
|
||||
);
|
||||
$this->view->assign('ref', $ref);
|
||||
if ($params['method']=='courrier'){
|
||||
$this->renderScript('finance/saisiebilan-courrier.phtml');
|
||||
} elseif ($params['method']=='fichier') {
|
||||
$this->renderScript('finance/saisiebilan-upload.phtml');
|
||||
}
|
||||
}
|
||||
}
|
||||
public function saisiebilanupAction()
|
||||
{
|
||||
$this->_helper->layout()->disableLayout();
|
||||
|
||||
$request = $this->getRequest();
|
||||
$ref = $request->getParam('ref');
|
||||
$fileref = $request->getParam('fileref');
|
||||
|
||||
if ($request->isPost()) {
|
||||
if (count($_FILES)==1 ) {
|
||||
$n = $_FILES['fichier']['name'];
|
||||
$s = $_FILES['fichier']['size'];
|
||||
$tmp_name = $_FILES['fichier']['tmp_name'];
|
||||
//Vérifier que l'extension du fichier est bien correcte
|
||||
$extValide = array('pdf', 'tiff');
|
||||
$extension = strrchr($n,'.');
|
||||
$extension = strtolower(substr($extension,1));
|
||||
if ( in_array($extension, $extValide) ) {
|
||||
$name = $fileref.'.'.$extension;
|
||||
$c = Zend_Registry::get('config');
|
||||
$file = realpath($c->profil->path->data).'/bilanclient/'.$name;
|
||||
if ( move_uploaded_file($tmp_name, $file) ) {
|
||||
$ws = new Scores_Ws_Client('order', '0.1');
|
||||
$parameters = new stdClass();
|
||||
$parameters->ref = $ref;
|
||||
$parameters->filename = $name;
|
||||
$result = $ws->setBilanInputFile($parameters);
|
||||
$this->view->assign('upload', true);
|
||||
$this->view->file = $name;
|
||||
} else {
|
||||
$this->view->assign('upload', false);
|
||||
$this->view->assign('errMsg', "<br/>Erreur lors de l'envoi du fichier!");
|
||||
}
|
||||
} else {
|
||||
$this->view->assign('upload', false);
|
||||
$this->view->assign('errMsg', "Extension de fichier invalide.");
|
||||
}
|
||||
} else {
|
||||
$this->view->assign('upload', false);
|
||||
$this->view->assign('errMsg', "<br/>Erreur.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,28 +1,64 @@
|
||||
<form id="formEnvoiBilan" name="formEnvoiBilan" method="post" action="<?=$this->url(array('controller'=>'finance', 'action'=>'saisiebilan'), 'default', true)?>">
|
||||
<input type="hidden" name="siren" value="<?=$this->siren?>" />
|
||||
<label>Votre email :</label>
|
||||
<input type="text" name="email" size="40" value="<?=$this->email?>">
|
||||
<?php if ($this->msg) {?>
|
||||
<div style="padding: 0 .7em;" class="ui-state-error ui-corner-all">
|
||||
<p><span style="float: left; margin-right: .3em;" class="ui-icon ui-icon-alert"></span>
|
||||
<strong>Alert:</strong> <?=$this->msg?></p>
|
||||
</div>
|
||||
<?php }?>
|
||||
|
||||
<?php if ($this->ref) {?>
|
||||
|
||||
Votre référence : BS-<?=strtoupper($this->ref)?>
|
||||
<br/><br/>
|
||||
Saisie du bilan de la Société <?=$this->raisonSociale?> clôturé le <?=$this->bilanCloture?> au format <?=$this->type?>
|
||||
<br/><br/>
|
||||
<style>
|
||||
#progressbar { border:none; }
|
||||
.ui-progressbar-value { background-image: url(/themes/default/images/finance/pbar-ani.gif); }
|
||||
</style>
|
||||
<form id="uploadForm" name="uploadForm" action="<?=$this->url(array('controller'=>'finance', 'action'=>'saisiebilanup'))?>" method="post" enctype="multipart/form-data">
|
||||
<input type="hidden" name="ref" value="<?=$this->ref?>" />
|
||||
<input type="hidden" name="fileref" value="<?=$this->fileref?>" />
|
||||
<input type="hidden" name="MAX_FILE_SIZE" value="50000000" />
|
||||
Votre fichier : <input type="file" name="fichier" />
|
||||
<input type="submit" name="upload" value="Envoyer" />
|
||||
</form>
|
||||
<div id="uploadOutput"></div>
|
||||
<script type="text/javascript" src="/libs/form/jquery.form.min.js" />
|
||||
<script>
|
||||
$('#uploadForm').ajaxForm({
|
||||
beforeSubmit: function() {
|
||||
$('#uploadOutput').html('Envoi en cours...');
|
||||
},
|
||||
success: function(data) {
|
||||
$('#uploadOutput').html(data);
|
||||
}
|
||||
});
|
||||
$('#dialogbilanclient').dialog({ buttons: [ {
|
||||
text: "Quitter",
|
||||
click: function() { $(this).dialog("close"); }
|
||||
} ] });
|
||||
</script>
|
||||
|
||||
<?php } else {?>
|
||||
|
||||
<form id="formEnvoiBilan" name="formEnvoiBilan" method="post" action="<?=$this->url(array('controller'=>'finance',
|
||||
'action'=>'saisiebilan'), 'default', true)?>">
|
||||
<input type="hidden" name="mode" value="order" />
|
||||
<input type="hidden" name="siren" value="<?=$this->siren?>" />
|
||||
<label>Format : </label><br/>
|
||||
<input type="radio" name="format" value="N" checked> Réel normal (Liasse 2050)<br/>
|
||||
<input type="radio" name="format" value="S"> Simplifé (Liasse 2033)<br/>
|
||||
<input type="radio" name="format" value="C"> Consolidé<br/>
|
||||
<br/>
|
||||
<label>Date de clôture du bilan : </label>
|
||||
<input type="text" name="dateCloture" value="" size="10" maxlength="10" id="datepicker">
|
||||
(JJ/MM/AAAA)
|
||||
<br/><br/>
|
||||
<label>Format : </label>
|
||||
<input type="radio" name="format" value="N" checked> Réel normal (Liasse 2050)
|
||||
<input type="radio" name="format" value="S" checked> Simplifié (Liasse 2033)
|
||||
<input type="radio" name="format" value="C"> Consolidé
|
||||
<br/><br/>
|
||||
<label>Durée de l'exercice (en mois) : </label>
|
||||
<select name="dureeExercice">
|
||||
<?php
|
||||
for ( $i=0; $i<23; $i++){
|
||||
$select = '';
|
||||
if ($i==11) $select = 'selected';
|
||||
?>
|
||||
<option value="<?=$i+1?>" <?=$select?>><?=$i+1?></option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<?php for ($i=1; $i<24; $i++) { $select = ''; if ($i == 12) { $select = 'selected'; } ?>
|
||||
<option value="<?=$i?>" <?=$select?>><?=$i?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
<br/><br/>
|
||||
<label>Confidentialité : </label><br/>
|
||||
@ -31,29 +67,33 @@ Ce bilan n'est pas confidentiel (saisie gratuite)
|
||||
<br/>
|
||||
<input type="radio" name="confidentiel" value="1">
|
||||
Ce bilan est confidentiel et ne doit être utilisé que pour les utilisateurs
|
||||
de votre société (+5€ HT par bilan saisi)
|
||||
<br/><br/>
|
||||
<label>Mode d'envoi du bilan : </label><br/>
|
||||
<input type="radio" name="method" value="fichier" checked>
|
||||
Instantané par le site : envoi du bilan au format numérique
|
||||
<br/>
|
||||
<input type="radio" name="method" value="courrier">
|
||||
Par courrier
|
||||
de votre société (+7€ HT par bilan saisi)
|
||||
<br/><br/>
|
||||
<span><i>
|
||||
Vous obtiendrez une référence à l'étape suivante avec au choix l'adresse du
|
||||
service Production de Scores & Décisions pour un envoi postal ou la possibilité
|
||||
Vous obtiendrez une référence à l'étape suivante avec la possibilité
|
||||
de nous transmettre directement par Internet votre bilan au format numérique (PDF, TIFF)
|
||||
</i></span>
|
||||
<br/>
|
||||
<br/><br/>
|
||||
<span><i>
|
||||
Si le bilan communiqué n'est pas conforme aux formulaires CERFA de la DGI des
|
||||
frais de traitement de 10€ vous seront facturés en sus.
|
||||
</i></span>
|
||||
|
||||
</form>
|
||||
<script type="text/javascript" src="/libs/form/jquery.form.min.js" />
|
||||
<script type="text/javascript">
|
||||
$('#dialogbilanclient').dialog({ buttons: {
|
||||
'Valider': function() {
|
||||
var url = $('#dialogbilanclient form#formEnvoiBilan').attr('action');
|
||||
$.post(url, $('#dialogbilanclient form#formEnvoiBilan').serialize(), function(data){
|
||||
$('div#dialogbilanclient.ui-dialog-content').html(data);
|
||||
});
|
||||
},
|
||||
'Annuler': function() { $(this).dialog('close'); }
|
||||
}, });
|
||||
|
||||
$('#datepicker').datepicker( $.datepicker.regional['fr'] );
|
||||
$('#datepicker').datepicker( "option", "dateFormat", 'dd/mm/yy' );
|
||||
$('#datepicker').datepicker( "option", "defaultDate", '31/12/<?=date('Y')-1?>' );
|
||||
</script>
|
||||
</script>
|
||||
|
||||
<?php }?>
|
||||
|
@ -0,0 +1,19 @@
|
||||
<?php if (isset($this->upload) && $this->upload == true){?>
|
||||
|
||||
<strong>Fichier envoyé <a href="<?=$this->url(array('controller'=>'fichier', 'action'=>'bilanclient',
|
||||
'fichier'=>$this->file),'default',true)?>"></a></strong>
|
||||
<script>
|
||||
$('#dialogbilanclient').dialog({ buttons: [ {
|
||||
text: "Quitter",
|
||||
click: function() { $(this).dialog("close"); }
|
||||
} ] });
|
||||
</script>
|
||||
|
||||
<?php } elseif (isset($this->upload) && $this->upload == false) {?>
|
||||
|
||||
<div style="padding: 0 .7em;" class="ui-state-error ui-corner-all">
|
||||
<p><span style="float: left; margin-right: .3em;" class="ui-icon ui-icon-alert"></span>
|
||||
<strong>Alert:</strong> <?=$this->errMsg?></p>
|
||||
</div>
|
||||
|
||||
<?php } ?>
|
11
library/Application/Model/BilanInput.php
Normal file
11
library/Application/Model/BilanInput.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
class Application_Model_BilanInput extends Zend_Db_Table_Abstract
|
||||
{
|
||||
protected $_name = 'bilaninput';
|
||||
|
||||
public function setFlagSent($file)
|
||||
{
|
||||
$data = array('sent' => 1);
|
||||
return $this->update($data, "file='$file'");
|
||||
}
|
||||
}
|
9
library/Scores/Ws/Client/Order.php
Normal file
9
library/Scores/Ws/Client/Order.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
return array(
|
||||
'0.1' => array(
|
||||
'setBilanInput' => array(
|
||||
'debug' => true,
|
||||
),
|
||||
'setBilanInputFile' => null,
|
||||
)
|
||||
);
|
@ -62,7 +62,6 @@ $(document).ready(function()
|
||||
$(this).load(url);
|
||||
},
|
||||
buttons: {
|
||||
Valider: function() { formEnvoiBilanSubmit(); },
|
||||
Annuler: function() { $(this).dialog('close'); }
|
||||
},
|
||||
close: function() { $('#dialogbilanclient').remove(); }
|
||||
|
19
scripts/build/config/_sql/structure/bilaninput.sql
Normal file
19
scripts/build/config/_sql/structure/bilaninput.sql
Normal file
@ -0,0 +1,19 @@
|
||||
--
|
||||
-- Structure de la table `bilaninput`
|
||||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `bilaninput` (
|
||||
`file` varchar(255) NOT NULL COMMENT 'Nom du fichier',
|
||||
`sent` tinyint(1) NOT NULL DEFAULT '0' COMMENT '1 si fichier envoyé',
|
||||
`dateUpdate` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Liste des bilans à transférer pour la saisie';
|
||||
|
||||
--
|
||||
-- Index pour les tables exportées
|
||||
--
|
||||
|
||||
--
|
||||
-- Index pour la table `bilaninput`
|
||||
--
|
||||
ALTER TABLE `bilaninput`
|
||||
ADD KEY `file` (`file`), ADD KEY `sent` (`sent`);
|
5
scripts/build/etc/cron.d/bilaninput
Normal file
5
scripts/build/etc/cron.d/bilaninput
Normal file
@ -0,0 +1,5 @@
|
||||
# Envoi commande bilan
|
||||
0 * * * * root php /home/vhosts/extranet/scripts/jobs/bilaninput.php --send
|
||||
|
||||
# Suppression fichier
|
||||
0 10 1 * * root php /home/vhosts/extranet/scripts/jobs/bilaninput.php --delete
|
1
scripts/build/etc/incron.d/bilaninput
Normal file
1
scripts/build/etc/incron.d/bilaninput
Normal file
@ -0,0 +1 @@
|
||||
/home/vhosts/data/bilanclient IN_CLOSE_WRITE php /home/vhosts/extranet/scripts/jobs/bilaninput.php --save $#
|
172
scripts/jobs/bilaninput.php
Normal file
172
scripts/jobs/bilaninput.php
Normal file
@ -0,0 +1,172 @@
|
||||
<?php
|
||||
/**
|
||||
* @todo :
|
||||
* Faire en sorte que chaque extranet récupére la liste des bilans à traiter, depuis le webservice
|
||||
* pour envoyer sur le ftp
|
||||
*/
|
||||
|
||||
// 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(),
|
||||
)));
|
||||
|
||||
//Use classmap autoloader - useful with opcode and realpath cache
|
||||
require_once 'Zend/Loader/AutoloaderFactory.php';
|
||||
require_once 'Zend/Loader/ClassMapAutoloader.php';
|
||||
Zend_Loader_AutoloaderFactory::factory(array(
|
||||
'Zend_Loader_ClassMapAutoloader' => array(
|
||||
__DIR__ . '/../../library/Zend/autoload_classmap.php',
|
||||
__DIR__ . '/../../library/Application/autoload_classmap.php',
|
||||
__DIR__ . '/../../library/Scores/autoload_classmap.php',
|
||||
__DIR__ . '/../../application/autoload_classmap.php',
|
||||
),
|
||||
'Zend_Loader_StandardAutoloader' => array(
|
||||
'prefixes' => array(
|
||||
'Zend' => __DIR__ . '/../../library/Zend',
|
||||
'Application' => __DIR__ . '/../../library/Application',
|
||||
'Scores' => __DIR__ . '/../../library/Scores',
|
||||
'Metier' => __DIR__ . '/../../library/Metier',
|
||||
),
|
||||
'fallback_autoloader' => true
|
||||
)
|
||||
));
|
||||
|
||||
// Zend_Application - Use it if you don't have autoloaders
|
||||
//require_once 'Zend/Application.php';
|
||||
|
||||
// Create application, bootstrap, and run
|
||||
$application = new Zend_Application(
|
||||
APPLICATION_ENV,
|
||||
APPLICATION_PATH . '/configs/application.ini'
|
||||
);
|
||||
|
||||
try {
|
||||
$opts = new Zend_Console_Getopt(
|
||||
//Options
|
||||
array(
|
||||
'help|?' => "Affiche l'aide.",
|
||||
'send-s' => "Envoi tous les fichiers non traité par FTP (si nom du fichier fourni force l'envoi).",
|
||||
'delete' => "Supprime les anciens fichiers et leurs références",
|
||||
'save=s' => "Enregistre la présence d'un fichier"
|
||||
));
|
||||
$opts->parse();
|
||||
} catch (Zend_Console_Getopt_Exception $e) {
|
||||
echo $e->getUsageMessage();
|
||||
exit;
|
||||
}
|
||||
|
||||
//Usage
|
||||
if(count($opts->getOptions())==0 || isset($opts->help))
|
||||
{
|
||||
echo "Bilan en commande saisi.";
|
||||
echo "\n\n";
|
||||
echo $opts->getUsageMessage();
|
||||
echo "\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
$test = false;
|
||||
if ( isset($opts->list) ) {
|
||||
$test = true;
|
||||
}
|
||||
|
||||
$c = new Zend_Config($application->getOptions());
|
||||
Zend_Registry::set('config', $c);
|
||||
|
||||
define ('PATH_DATA', $c->profil->path->data);
|
||||
|
||||
define('FTP_HOST', 'ftp.scores-decisions.com');
|
||||
define('FTP_USER', 'bilansext');
|
||||
define('FTP_PASS', 'j12azt78');
|
||||
define('FTP_DIR', 'send');
|
||||
|
||||
// --- Functions
|
||||
function sendToFtp($localFile, $remoteFile)
|
||||
{
|
||||
$conn_id = ftp_connect(FTP_HOST);
|
||||
$login_result = ftp_login($conn_id, FTP_USER, FTP_PASS);
|
||||
ftp_chdir($conn_id, FTP_DIR);
|
||||
$return = false;
|
||||
if (ftp_put($conn_id, $remoteFile, $localFile, FTP_BINARY)) {
|
||||
$return = true;
|
||||
}
|
||||
ftp_close($conn_id);
|
||||
return $return;
|
||||
}
|
||||
|
||||
// --- Connexion à la base de données
|
||||
$db = Zend_Db::factory($c->profil->db->sdv1);
|
||||
Zend_Db_Table_Abstract::setDefaultAdapter($db);
|
||||
|
||||
$model = new Application_Model_BilanInput();
|
||||
|
||||
// --- Suppression des fichiers traités
|
||||
if ( $opts->delete ) {
|
||||
echo date('Y-m-d H:i:s')." - Suppression fichier.\n";
|
||||
try {
|
||||
$sql = $model->select()->where('sent=?', 1)->where('DATE_SUB(CURDATE(),INTERVAL 30 DAY) >= dateUpdate');
|
||||
$result = $model->fetchAll($sql);
|
||||
if (count($result) > 0) {
|
||||
foreach ($result as $item) {
|
||||
if( unlink(PATH_DATA . '/bilanclient/' . $item->file) ){
|
||||
$model->delete("file='".$item->file."'");
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch(Zend_Db_Exception $e) {
|
||||
echo date('Y-m-d H:i:s')." - ".$e->getMessage().".\n";
|
||||
}
|
||||
echo date('Y-m-d H:i:s')." - Suppression fichier FIN.\n";
|
||||
}
|
||||
|
||||
if ( $opts->save ) {
|
||||
echo date('Y-m-d H:i:s')." - Enregistrement fichier.\n";
|
||||
$model->insert(array('file' => $opts->save, 'sent' => 0));
|
||||
echo date('Y-m-d H:i:s')." - Enregistrement fichier FIN.\n";
|
||||
}
|
||||
|
||||
// --- Envoi
|
||||
if ( $opts->send ) {
|
||||
|
||||
echo date('Y-m-d H:i:s')." - Envoi fichier.\n";
|
||||
|
||||
$tabFichier = array();
|
||||
|
||||
// --- Selection fichier
|
||||
if ( $opts->send !== true ) {
|
||||
$tabFichier[] = basename($opts->send);
|
||||
} else {
|
||||
$sql = $model->select()->where('sent=?', 0);
|
||||
$result = $model->fetchAll($sql);
|
||||
if (count($result) > 0) {
|
||||
foreach($result as $item) {
|
||||
$tabFichier[] = $item->file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- Envoi sur le FTP
|
||||
if (count($tabFichier) > 0) {
|
||||
foreach ($tabFichier as $fichier) {
|
||||
echo date('Y-m-d H:i:s')." - Envoi fichier ";
|
||||
if ( sendToFtp(PATH_DATA.'/bilanclient/'.$fichier, $fichier) ) {
|
||||
$model->setFlagSent($fichier);
|
||||
echo $fichier." - OK";
|
||||
} else {
|
||||
echo $fichier." - Erreur";
|
||||
}
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
|
||||
echo date('Y-m-d H:i:s')." - Envoi fichier FIN.\n";
|
||||
}
|
Loading…
Reference in New Issue
Block a user