From 65831d3194133cda644ce2085627bf118bfefb9a Mon Sep 17 00:00:00 2001 From: Claire DELBOS Date: Tue, 11 Apr 2017 16:37:57 +0200 Subject: [PATCH] SD-35 SD-28 --- .../default/controllers/FinanceController.php | 2 +- .../controllers/JuridiqueController.php | 2 +- .../controllers/RechercheController.php | 2 + .../default/controllers/SaisieController.php | 4 +- .../controllers/SurveillanceController.php | 54 ++++++- .../default/scripts/saisie/ribiban.phtml | 18 ++- .../default/scripts/surveillance/liste.phtml | 8 +- .../surveillance/surveillanceserie.phtml | 70 +++++++++ composer.lock | 73 +++++---- .../Model/CommandesSurveillance.php | 8 + library/Scores/Import/FileCsv.php | 144 ++++++++++++++++++ public/themes/default/styles/bsmain.css | 1 + 12 files changed, 338 insertions(+), 48 deletions(-) create mode 100644 application/modules/default/views/default/scripts/surveillance/surveillanceserie.phtml create mode 100644 library/Application/Model/CommandesSurveillance.php create mode 100644 library/Scores/Import/FileCsv.php create mode 100644 public/themes/default/styles/bsmain.css diff --git a/application/modules/default/controllers/FinanceController.php b/application/modules/default/controllers/FinanceController.php index 4aa606061..5e0872c1e 100644 --- a/application/modules/default/controllers/FinanceController.php +++ b/application/modules/default/controllers/FinanceController.php @@ -1070,7 +1070,7 @@ class FinanceController extends Zend_Controller_Action $entreprise = new Scores_Session_Entreprise($this->siret, $this->id); - $this->view->assign('banques', $infos->result->item); + $this->view->assign('banques', isset($infos->result->item)?$infos->result->item:array()); $this->view->assign('raisonSociale', $entreprise->getRaisonSociale()); $this->view->assign('siren', substr($this->siret, 0, 9)); $this->view->assign('exportObjet', $infos); diff --git a/application/modules/default/controllers/JuridiqueController.php b/application/modules/default/controllers/JuridiqueController.php index e19178aa5..8c66a41e7 100644 --- a/application/modules/default/controllers/JuridiqueController.php +++ b/application/modules/default/controllers/JuridiqueController.php @@ -381,7 +381,7 @@ class JuridiqueController extends Zend_Controller_Action $this->view->msg = "Erreur"; } else { - $this->view->List = $response->List->item; + $this->view->List = isset($response->List->item)?$response->List->item:null; // --- Pagination $nbReponsesTotal = $response->Nb; $pageTotal = $pageCurrent = 1; diff --git a/application/modules/default/controllers/RechercheController.php b/application/modules/default/controllers/RechercheController.php index 6baa9655e..b40a41852 100644 --- a/application/modules/default/controllers/RechercheController.php +++ b/application/modules/default/controllers/RechercheController.php @@ -806,6 +806,8 @@ class RechercheController extends Zend_Controller_Action //Calcul pagination $nbReponses = $reponse->nbReponses; $nbReponsesTotal = $reponse->nbReponsesTotal; + $pagePrev=1; + $pageNext=1; if ($nbReponses < $nbReponsesTotal) { $pageTotal = ceil( $nbReponsesTotal / $nbAffichage ); $pageCurrent = $page; diff --git a/application/modules/default/controllers/SaisieController.php b/application/modules/default/controllers/SaisieController.php index 1c05ba4f9..6b94f572a 100644 --- a/application/modules/default/controllers/SaisieController.php +++ b/application/modules/default/controllers/SaisieController.php @@ -2918,7 +2918,7 @@ class SaisieController extends Zend_Controller_Action $this->view->assign('actif',$result->Actif); $this->view->assign('siren', $siren); $this->view->assign('mode', $mode); - $this->view->assign('banques', $infos->result->item); + $this->view->assign('banques', isset($infos->result->item)?$infos->result->item:array()); $this->view->assign('guichetMod', $guichetMod); $this->view->assign('banqueMod', $banqueMod); @@ -2937,7 +2937,7 @@ class SaisieController extends Zend_Controller_Action $mode = $request->getParam('mode'); - $this->view->assign('code_banque', $guichetMod); + $this->view->assign('code_banque', $codeBanque); $this->view->assign('code_guichet', $codeGuichet); $this->view->assign('num_compte', $numCompte); $this->view->assign('bic_swift', $bicSwift); diff --git a/application/modules/default/controllers/SurveillanceController.php b/application/modules/default/controllers/SurveillanceController.php index 20963e00d..ed0db1051 100644 --- a/application/modules/default/controllers/SurveillanceController.php +++ b/application/modules/default/controllers/SurveillanceController.php @@ -383,7 +383,7 @@ class SurveillanceController extends Zend_Controller_Action $ws = new WsScores(); $infos = $ws->getSurveillances($filtre, $position, $nbAffichage); - $surveillances = $infos->result->item; + $surveillances = isset($infos->result->item)?$infos->result->item:null; $listTrier = array(); if ( count($surveillances)>0 ) { @@ -1155,4 +1155,56 @@ class SurveillanceController extends Zend_Controller_Action $html2pdf->WriteHTML(utf8_decode($output)); $html2pdf->Output(str_replace('.csv', '.pdf', $nomFic), 'D'); } + + /** + * Import surveillance en fichier csv + */ + public function surveillanceserieAction(){ + //echo 'coucou';die; + $request = $this->getRequest(); + if($request->getParam('ref')>""){ + $cs=new Scores_Import_FileCsv(); + $verif=$cs->verifandupload($_FILES,$request); + if($verif['success']){ + $this->view->assign('msg', 'Nous avons enregistré votre fichier de '.$verif['message'].' lignes.

Les surveillances seront enregistrées durant la nuit.'); + $this->view->assign('step', 2); + }else{ + $this->view->assign('msg', $verif['message']); + $this->view->assign('step', 2); + } + return; + } + //Affichage formulaire demande ref et email + $this->_helper->layout->disableLayout(); + $source = $request->getParam('source', ''); + $encours = $request->getParam('encours', 0); + $this->view->pathScript=$this->theme->pathScript; + $this->view->pathStyle=$this->theme->pathStyle; + $user = new Scores_Utilisateur(); + + $request = $this->getRequest(); + $source = $request->getParam('source'); + + $tabSource = array(); + $user = new Scores_Utilisateur(); + + // Main email + $email = $user->getEmail(); + $ref=$user->identity->id . 'www'.Date('YmdHis'); + foreach ($this->sourceDroit as $s => $perm) { + if ($user->checkPerm($perm)) { + $tabSource[] = array( + 'value' => $s, + 'name' => $this->sourceTxt[$s], + 'select' => (!empty($source) && $source==$s) ? ' selected' : '', + ); + } + } + + $this->view->assign('tabSource', $tabSource); + $this->view->assign('email', $email); + $this->view->assign('ref', $ref); + $this->view->assign('encours', $encours); + $this->view->msg="Sélectionnez votre fichier"; + } } \ No newline at end of file diff --git a/application/modules/default/views/default/scripts/saisie/ribiban.phtml b/application/modules/default/views/default/scripts/saisie/ribiban.phtml index a9dca9c90..156bc1da4 100644 --- a/application/modules/default/views/default/scripts/saisie/ribiban.phtml +++ b/application/modules/default/views/default/scripts/saisie/ribiban.phtml @@ -8,7 +8,7 @@ div#dialog fieldset legend {padding:5px; font-weight:bold; }
-mode == add || $this->mode == edit){?> +mode == 'add' || $this->mode == 'edit'){?>
@@ -25,8 +25,10 @@ div#dialog fieldset legend {padding:5px; font-weight:bold; } actif==1){ $checkActive = 'checked'; + $checkInactive = ''; } else { $checkInactive = 'checked'; + $checkActive = ''; } ?>
Active/>
@@ -35,7 +37,7 @@ if ($this->actif==1){
- +
Saisie RIB
@@ -49,7 +51,7 @@ if ($this->actif==1){
- +
@@ -71,19 +73,19 @@ if ($this->actif==1){
- + - +
Saisie BIC/IBAN
- +
- +
@@ -100,7 +102,7 @@ if ($this->actif==1){ - + - diff --git a/application/modules/default/views/default/scripts/surveillance/surveillanceserie.phtml b/application/modules/default/views/default/scripts/surveillance/surveillanceserie.phtml new file mode 100644 index 000000000..71754e011 --- /dev/null +++ b/application/modules/default/views/default/scripts/surveillance/surveillanceserie.phtml @@ -0,0 +1,70 @@ +
+ +step==0)):?> +standardhelptext; +?> +
+

+ +


+
+ + +step==2)):?> +
+

SURVEILLANCE

+
+
msg?> +

+ +

+ Retour +


+
+ + +
+
+ +
+ tabSource as $s) : ?> + /> 
+ +
+ + +
+ + +
+ +
+ +
+ \ No newline at end of file diff --git a/composer.lock b/composer.lock index 8b18c2865..a4111e0b7 100644 --- a/composer.lock +++ b/composer.lock @@ -92,21 +92,21 @@ }, { "name": "guzzlehttp/guzzle", - "version": "6.2.2", + "version": "6.2.3", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "ebf29dee597f02f09f4d5bbecc68230ea9b08f60" + "reference": "8d6c6cc55186db87b7dc5009827429ba4e9dc006" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/ebf29dee597f02f09f4d5bbecc68230ea9b08f60", - "reference": "ebf29dee597f02f09f4d5bbecc68230ea9b08f60", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/8d6c6cc55186db87b7dc5009827429ba4e9dc006", + "reference": "8d6c6cc55186db87b7dc5009827429ba4e9dc006", "shasum": "" }, "require": { "guzzlehttp/promises": "^1.0", - "guzzlehttp/psr7": "^1.3.1", + "guzzlehttp/psr7": "^1.4", "php": ">=5.5" }, "require-dev": { @@ -150,7 +150,7 @@ "rest", "web service" ], - "time": "2016-10-08T15:01:37+00:00" + "time": "2017-02-28T22:50:30+00:00" }, { "name": "guzzlehttp/promises", @@ -205,16 +205,16 @@ }, { "name": "guzzlehttp/psr7", - "version": "1.3.1", + "version": "1.4.2", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "5c6447c9df362e8f8093bda8f5d8873fe5c7f65b" + "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/5c6447c9df362e8f8093bda8f5d8873fe5c7f65b", - "reference": "5c6447c9df362e8f8093bda8f5d8873fe5c7f65b", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/f5b8a8512e2b58b0071a7280e39f14f72e05d87c", + "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c", "shasum": "" }, "require": { @@ -250,29 +250,36 @@ "name": "Michael Dowling", "email": "mtdowling@gmail.com", "homepage": "https://github.com/mtdowling" + }, + { + "name": "Tobias Schultze", + "homepage": "https://github.com/Tobion" } ], - "description": "PSR-7 message implementation", + "description": "PSR-7 message implementation that also provides common utility methods", "keywords": [ "http", "message", + "request", + "response", "stream", - "uri" + "uri", + "url" ], - "time": "2016-06-24T23:00:38+00:00" + "time": "2017-03-20T17:10:46+00:00" }, { "name": "monolog/monolog", - "version": "1.22.0", + "version": "1.22.1", "source": { "type": "git", "url": "https://github.com/Seldaek/monolog.git", - "reference": "bad29cb8d18ab0315e6c477751418a82c850d558" + "reference": "1e044bc4b34e91743943479f1be7a1d5eb93add0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Seldaek/monolog/zipball/bad29cb8d18ab0315e6c477751418a82c850d558", - "reference": "bad29cb8d18ab0315e6c477751418a82c850d558", + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/1e044bc4b34e91743943479f1be7a1d5eb93add0", + "reference": "1e044bc4b34e91743943479f1be7a1d5eb93add0", "shasum": "" }, "require": { @@ -337,7 +344,7 @@ "logging", "psr-3" ], - "time": "2016-11-26T00:15:39+00:00" + "time": "2017-03-13T07:08:03+00:00" }, { "name": "phpoffice/phpexcel", @@ -597,16 +604,16 @@ }, { "name": "symfony/browser-kit", - "version": "v3.2.2", + "version": "v3.2.7", "source": { "type": "git", "url": "https://github.com/symfony/browser-kit.git", - "reference": "548f8230bad9f77463b20b15993a008f03e96db5" + "reference": "2fe0caa60c1a1dfeefd0425741182687a9b382b8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/browser-kit/zipball/548f8230bad9f77463b20b15993a008f03e96db5", - "reference": "548f8230bad9f77463b20b15993a008f03e96db5", + "url": "https://api.github.com/repos/symfony/browser-kit/zipball/2fe0caa60c1a1dfeefd0425741182687a9b382b8", + "reference": "2fe0caa60c1a1dfeefd0425741182687a9b382b8", "shasum": "" }, "require": { @@ -650,20 +657,20 @@ ], "description": "Symfony BrowserKit Component", "homepage": "https://symfony.com", - "time": "2017-01-02T20:32:22+00:00" + "time": "2017-02-21T09:12:04+00:00" }, { "name": "symfony/css-selector", - "version": "v3.2.2", + "version": "v3.2.7", "source": { "type": "git", "url": "https://github.com/symfony/css-selector.git", - "reference": "f0e628f04fc055c934b3211cfabdb1c59eefbfaa" + "reference": "a48f13dc83c168f1253a5d2a5a4fb46c36244c4c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/css-selector/zipball/f0e628f04fc055c934b3211cfabdb1c59eefbfaa", - "reference": "f0e628f04fc055c934b3211cfabdb1c59eefbfaa", + "url": "https://api.github.com/repos/symfony/css-selector/zipball/a48f13dc83c168f1253a5d2a5a4fb46c36244c4c", + "reference": "a48f13dc83c168f1253a5d2a5a4fb46c36244c4c", "shasum": "" }, "require": { @@ -703,20 +710,20 @@ ], "description": "Symfony CssSelector Component", "homepage": "https://symfony.com", - "time": "2017-01-02T20:32:22+00:00" + "time": "2017-02-21T09:12:04+00:00" }, { "name": "symfony/dom-crawler", - "version": "v3.2.2", + "version": "v3.2.7", "source": { "type": "git", "url": "https://github.com/symfony/dom-crawler.git", - "reference": "27d9790840a4efd3b7bb8f5f4f9efc27b36b7024" + "reference": "403944e294cf4ceb3b8447f54cbad88ea7b99cee" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/dom-crawler/zipball/27d9790840a4efd3b7bb8f5f4f9efc27b36b7024", - "reference": "27d9790840a4efd3b7bb8f5f4f9efc27b36b7024", + "url": "https://api.github.com/repos/symfony/dom-crawler/zipball/403944e294cf4ceb3b8447f54cbad88ea7b99cee", + "reference": "403944e294cf4ceb3b8447f54cbad88ea7b99cee", "shasum": "" }, "require": { @@ -759,7 +766,7 @@ ], "description": "Symfony DomCrawler Component", "homepage": "https://symfony.com", - "time": "2017-01-02T20:32:22+00:00" + "time": "2017-02-21T09:12:04+00:00" }, { "name": "symfony/polyfill-mbstring", diff --git a/library/Application/Model/CommandesSurveillance.php b/library/Application/Model/CommandesSurveillance.php new file mode 100644 index 000000000..ff87cd5f0 --- /dev/null +++ b/library/Application/Model/CommandesSurveillance.php @@ -0,0 +1,8 @@ +toArray(); + $config=$ct[APPLICATION_ENV]; + //home/vhosts/data/extranet + $this->filepath=$config['profil']['path']['shared'].'/persist/surveillance/'; + if(!is_dir($this->filepath)){ + mkdir($this->filepath); + } + } + public function verifandupload($file,$request){ + $ref=$request->getParam('ref'); + $user = new Scores_Utilisateur(); + $login = $user->identity->username; + //var_dump($user->identity);die; + $email=$request->getParam('email'); + $sources=$request->getParam('source'); + + $fileinname=$file["fichier"]["name"]; + $fileType = pathinfo($fileinname,PATHINFO_EXTENSION); + if($fileType!='csv'){ + return array('success' => false, 'message' => 'Extension incorrecte'); + } + $fileoutname=$ref.'.csv'; + $target=$this->filepath.$fileoutname; + if (!move_uploaded_file($file["fichier"]["tmp_name"], $target)) { + return array('success' => false, 'message' => 'Le fichier ' + . basename( $file["fichier"]["name"]). ' ne peut pas être chargé.'); + } + $result=$this->verifyformat($fileoutname); + if($result['success']){ + $row=$result['message']; + }else{ + return $result; + } + $result=$this->sendtoftp($fileoutname); + if(!$result['success']){ + return $result; + } + $user = new Scores_Utilisateur(); + + $cmd=new Application_Model_CommandesSurveillance(); + foreach($sources as $source){ + $data= array( + 'ref' => $ref, + 'login' =>$login, + 'email' => $email, + 'filename' => $fileinname, + 'surv_source' => $source, + 'date_created' => Date('Y-m-d') + ); + $cmd->insert($data); + } + return array('success' => true, 'message' => $row); + } + private function verifyformat($filename){ + $handle=fopen($this->filepath.$filename,'r'); + if(!$handle){ + return array('success' => false, 'message' => 'Fichier illisible.'); + } + ini_set("auto_detect_line_endings", true); + $row=1; + while (($data = fgetcsv($handle)) !== FALSE) { + $num = count($data); + if($num!=3){ + return array('success' => false, 'message' => 'Nombre de colonnes erronné à la ligne '.$row.'.'); + } + if($data[0]=='siren' & $row==1){ + continue; + } + $data[0]=trim($data[0]); + if(strlen($data[0])>9){ + return array('success' => false, 'message' => 'Siren mal formaté à la ligne '.$row.'.'); + } + if(!is_numeric($data[0])){ + return array('success' => false, 'message' => 'Siren non numérique '.$data[0].' à la ligne '.$row.'.'); + } + $siren=substr('000000000'.$data[0],-9,9); + if(!$this->estValide($siren)){ + return array('success' => false, 'message' => 'Siren invalide '.$data[0].' à la ligne '.$row.'.'); + } + $row++; + } + fclose($handle); + + return array('success' => true, 'message' => $row); + + } + private function sendtoftp($filename){ + $connection = ftp_connect('ftp.scores-decisions.com',21); + + $login = ftp_login($connection, 'internesd', 'internesd2017'); + + $dest='/send/'.$filename; + + $source=$this->filepath.$filename; + + if (!$connection || !$login) { + return array('success' => false, 'message' => 'Un problement technique est survenu merci de nous contacter avec le code erreur '.__LINE__); + } + + if(!ftp_pasv($connection, true)){ + return array('success' => false, 'message' => 'Un problement technique est survenu merci de nous contacter avec le code erreur '.__LINE__); + } + $upload = ftp_put($connection, $dest, $source, FTP_BINARY); + + if (!$upload) { + return array('success' => false, 'message' => 'Un problement technique est survenu merci de nous contacter avec le code erreur '.__LINE__); + } + + ftp_close($connection); + return array('success' => true, 'message' => ''); + } + private function estValide($siren){ + // Donc le SIREN est un numérique à 9 chiffres + $somme = 0; + for ($cpt = 0; $cpt 9) + $tmp -= 9; // Si le résultat est supérieur à 9, on lui soustrait 9 + } + else + $tmp = substr($siren,$cpt,1); + $somme += (int)$tmp; + } + if (($somme % 10) == 0) + return true; // Si la somme est un multiple de 10 alors le SIREN est valide + else + return false; + + } +} \ No newline at end of file diff --git a/public/themes/default/styles/bsmain.css b/public/themes/default/styles/bsmain.css new file mode 100644 index 000000000..66250b595 --- /dev/null +++ b/public/themes/default/styles/bsmain.css @@ -0,0 +1 @@ +@import url("./../../../libs/bootstrap-3.3.7/css/bootstrap.min.css");