issue #0001350 : Dédoublonnage sans aucun test
This commit is contained in:
parent
7d5546e0d9
commit
0f3992270e
@ -5,18 +5,18 @@ class ProfilController extends Zend_Controller_Action
|
||||
public function indexAction()
|
||||
{
|
||||
$db = Zend_Registry::get('db');
|
||||
|
||||
|
||||
$profilM = new Application_Model_Profil($db);
|
||||
$sql = $profilM->select()->order('reference ASC');
|
||||
$rows = $profilM->fetchAll($sql);
|
||||
$this->view->assign('profils', $rows);
|
||||
}
|
||||
|
||||
|
||||
public function detailAction()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
$id = $request->getParam('id', null);
|
||||
|
||||
|
||||
require_once 'Scores/Enrichissement.php';
|
||||
$data = new Enrichissement();
|
||||
if ( $id != null ) {
|
||||
@ -30,9 +30,9 @@ class ProfilController extends Zend_Controller_Action
|
||||
$this->view->assign('profil', $tmp);
|
||||
$this->view->assign('reference', $profil->current()->reference);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function createAction()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
@ -41,10 +41,12 @@ class ProfilController extends Zend_Controller_Action
|
||||
require_once 'Scores/Enrichissement.php';
|
||||
$data = new Enrichissement();
|
||||
if ( $id != null ) {
|
||||
|
||||
|
||||
$profilM = new Application_Model_Profil();
|
||||
$profil = $profilM->find($id);
|
||||
$criteres = json_decode($profil->current()->criteres, true);
|
||||
$criteres = json_decode($profil->current()->criteres, true);
|
||||
$doublon = json_decode($profil->current->doublon, true);
|
||||
$this->view->assign('doublon', $doublon);
|
||||
$tmp = array();
|
||||
foreach ($criteres as $critere) {
|
||||
$values = false;
|
||||
@ -52,7 +54,7 @@ class ProfilController extends Zend_Controller_Action
|
||||
{
|
||||
$values = $matches[2];
|
||||
}
|
||||
|
||||
|
||||
$pos = strpos($critere, '(');
|
||||
if ($pos === false){
|
||||
$key = $critere;
|
||||
@ -60,7 +62,7 @@ class ProfilController extends Zend_Controller_Action
|
||||
$key = substr($critere, 0, $pos);
|
||||
}
|
||||
Zend_Registry::get('firebug')->info($key);
|
||||
|
||||
|
||||
$tmp[$key] = array(
|
||||
'lib' => $data->getDicoLib($key),
|
||||
'values' => $values,
|
||||
@ -72,23 +74,25 @@ class ProfilController extends Zend_Controller_Action
|
||||
$this->view->assign('id', $id);
|
||||
$this->view->assign('edit', true);
|
||||
$this->view->assign('elements', $data->getDico());
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function saveAction()
|
||||
{
|
||||
$this->_helper->layout()->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender(true);
|
||||
|
||||
|
||||
$request = $this->getRequest();
|
||||
$reference = $request->getParam('reference');
|
||||
$criteres = $request->getParam('criteres');
|
||||
|
||||
$doublon = $request->getParam('doublon');
|
||||
|
||||
$db = Zend_Registry::get('db');
|
||||
$profilM = new Application_Model_Profil($db);
|
||||
$data = array(
|
||||
'reference' => $reference,
|
||||
'criteres' => json_encode($criteres),
|
||||
'doublon' => json_encode($doublon),
|
||||
);
|
||||
|
||||
$id = $request->getParam('id', null);
|
||||
@ -106,29 +110,29 @@ class ProfilController extends Zend_Controller_Action
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function setAction()
|
||||
{
|
||||
$this->_helper->layout()->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender(true);
|
||||
|
||||
|
||||
$request = $this->getRequest();
|
||||
$idprofil = $request->getParam('idprofil');
|
||||
$idfile = $request->getParam('idfile');
|
||||
|
||||
|
||||
$db = Zend_Registry::get('db');
|
||||
|
||||
|
||||
$commandesM = new Application_Model_Commandes($db);
|
||||
|
||||
|
||||
$data = array(
|
||||
'idProfil' => $idprofil,
|
||||
);
|
||||
|
||||
|
||||
if ( $commandesM->update($data, "id=$idfile") ){
|
||||
echo '';
|
||||
} else {
|
||||
echo 'Erreur';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -3,9 +3,9 @@ div#entete {
|
||||
width:45%;
|
||||
float:left;
|
||||
border:1px solid #bebebe;
|
||||
height:500px;
|
||||
height:350px;
|
||||
overflow:auto;
|
||||
margin:5px 0;
|
||||
margin:2px;
|
||||
}
|
||||
|
||||
div#entete li {
|
||||
@ -20,12 +20,12 @@ div#entete li {
|
||||
}
|
||||
|
||||
div#dico {
|
||||
width:45%;
|
||||
width:350px;
|
||||
height:500px;
|
||||
float:right;
|
||||
float:left;
|
||||
border:1px solid #bebebe;
|
||||
overflow:auto;
|
||||
margin:5px 0;
|
||||
margin:2px;
|
||||
}
|
||||
|
||||
div#dico li {
|
||||
@ -39,6 +39,12 @@ div#dico li {
|
||||
color:#000000;
|
||||
}
|
||||
|
||||
div#help {
|
||||
float:left;
|
||||
width:auto;
|
||||
margin:2px;
|
||||
}
|
||||
|
||||
input[type="text"] {
|
||||
border:1px solid;
|
||||
}
|
||||
@ -75,6 +81,17 @@ input[type="text"] {
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div id="help">Aide</div>
|
||||
|
||||
|
||||
<div style="clear:both;">
|
||||
Clé de dédoublonnage : <br/>
|
||||
<input type="checbox" name="doublon[]" value="siret" <?php if(in_array('siret', $this->doublon)) echo ' checked';?>/> SIRET<br/>
|
||||
<input type="checbox" name="doublon[]" value="siren" <?php if(in_array('siren', $this->doublon)) echo ' checked';?>/> SIREN<br/>
|
||||
<input type="checbox" name="doublon[]" value="nic" <?php if(in_array('nic', $this->doublon)) echo ' checked';?>/> NIC<br/>
|
||||
<input type="checbox" name="doublon[]" value="ref" <?php if(in_array('ref', $this->doublon)) echo ' checked';?>/> REF<br/>
|
||||
</div>
|
||||
|
||||
<div style="clear:both;">
|
||||
Référence <input type="text" name="profil" value="<?=$this->reference?>" />
|
||||
|
||||
|
@ -34,6 +34,7 @@ try {
|
||||
'file=s' => "Traitement manuel avec spécification du fichier",
|
||||
'reprise' => "Reprendre un fichier à la ligne n-1",
|
||||
'ask' => "Interaction avec l'utilisateur lors d'une reprise manuelle",
|
||||
'doublon=s' => "Option dédoublonnage par fichier",
|
||||
)
|
||||
);
|
||||
$opts->parse();
|
||||
@ -265,6 +266,16 @@ if ($opts->id) {
|
||||
$profilM = new Application_Model_Profil($db);
|
||||
$profil = $profilM->find($commande->idProfil)->current();
|
||||
$profilEntete = json_decode($profil->criteres, true);
|
||||
|
||||
$profilDoublon = null;
|
||||
if ($profil->doublon!='') {
|
||||
$profilDoublon = json_decode($profil->doublon, true);
|
||||
}
|
||||
} else {
|
||||
$profilDoublon = null;
|
||||
if ($opts->doublon && $opts->doublon!='') {
|
||||
$profilDoublon = explode(' ', $opts->doublon);
|
||||
}
|
||||
}
|
||||
|
||||
//Chargement des classes metier
|
||||
@ -318,6 +329,9 @@ if (($handle = fopen($inFile, 'r')) !== FALSE) {
|
||||
case 'siret':
|
||||
$posKeySiret = $c;
|
||||
break;
|
||||
case 'ref':
|
||||
$posKeyRef = $c;
|
||||
break;
|
||||
}
|
||||
$tabExtract[] = $data[$c];
|
||||
}
|
||||
@ -327,9 +341,11 @@ if (($handle = fopen($inFile, 'r')) !== FALSE) {
|
||||
if ($posKeySiren===false && $posKeySiret===false){
|
||||
die("Aucune clé détecté!");
|
||||
}
|
||||
|
||||
//Traitement des identifiants
|
||||
} else {
|
||||
|
||||
//Gestion des identifiants obligatoire (SIREN, NIC, SIRET)
|
||||
if ( $posKeySiret!==false ){
|
||||
$tabIdentifiant[] = $data[$posKeySiret];
|
||||
} elseif ( $posKeySiren!==false && $posKeyNic!==false ){
|
||||
@ -338,6 +354,7 @@ if (($handle = fopen($inFile, 'r')) !== FALSE) {
|
||||
$tabIdentifiant[] = $data[$posKeySiren];
|
||||
}
|
||||
|
||||
//Gestion des autres colonnes fournies par le client
|
||||
for ($c=0; $c < $num; $c++) {
|
||||
$colname = $tabExtract[$c];
|
||||
if (!in_array(strtolower($colname), array('siren', 'siret', 'nic'))){
|
||||
@ -345,6 +362,20 @@ if (($handle = fopen($inFile, 'r')) !== FALSE) {
|
||||
}
|
||||
}
|
||||
|
||||
//Création clé dédoublonnage
|
||||
if (null != $profilDoublon) {
|
||||
$keyDoublon = '';
|
||||
foreach ($profilDoublon as $item) {
|
||||
switch($item) {
|
||||
case 'siret': $keyDoublon.= $data[$posKeySiret]; break;
|
||||
case 'siren': $keyDoublon.= $data[$posKeySiren]; break;
|
||||
case 'nic': $keyDoublon.= $data[$posKeyNic]; break;
|
||||
case 'ref': $keyDoublon.= $data[$posKeyRef]; break;
|
||||
}
|
||||
}
|
||||
$tabData[$row-1]['keyDoublon'] = $keyDoublon;
|
||||
}
|
||||
|
||||
}
|
||||
$row++;
|
||||
}
|
||||
@ -410,8 +441,12 @@ foreach($tabExtract as $key)
|
||||
}
|
||||
}
|
||||
}
|
||||
//Ajout colonne obligatoire SiretValide
|
||||
//Ajout colonne obligatoire
|
||||
$tabEntete[] = 'SiretValide';
|
||||
if( null != $profilDoublon ) {
|
||||
$tabEntete[] = 'Doublon';
|
||||
}
|
||||
|
||||
unset($tabExtract);
|
||||
|
||||
//Construction de l'entete pour le fichier
|
||||
@ -457,6 +492,7 @@ if ( $opts->reprise ) {
|
||||
}
|
||||
|
||||
$row = 0;
|
||||
$doublonList = array();
|
||||
|
||||
//Vérification et création des données
|
||||
foreach($tabIdentifiant as $item)
|
||||
@ -494,7 +530,7 @@ foreach($tabIdentifiant as $item)
|
||||
}
|
||||
}
|
||||
|
||||
//On définit le tableau de retour
|
||||
//On définit le tableau de retour (les colonnes du fichier client sont déjà présentent)
|
||||
if ( $posKeySiret!==false ){
|
||||
$tabData[$row]['siret'] = $item;
|
||||
} elseif ( $posKeySiren!==false && $posKeyNic!==false ){
|
||||
@ -506,7 +542,15 @@ foreach($tabIdentifiant as $item)
|
||||
|
||||
$tabData[$row]['SiretValide'] = ($siretValide===true) ? 1 : 0;
|
||||
|
||||
if ( $sirenValide===false || intval($siren)==0 ){
|
||||
//Clé de doublon
|
||||
$keyDoublon = null;
|
||||
if ( array_key_exists('keyDoublon', $tabData[$row])) {
|
||||
$keyDoublon = $tabData[$row]['keyDoublon'];
|
||||
}
|
||||
|
||||
if ( null !== $keyDoublon && in_array($keyDoublon, $doublonList) ) {
|
||||
$tabData[$row]['doublon'] = 1;
|
||||
} elseif ( $sirenValide===false || intval($siren)==0 ){
|
||||
//Siren faux
|
||||
} else {
|
||||
|
||||
@ -592,6 +636,11 @@ foreach($tabIdentifiant as $item)
|
||||
|
||||
}
|
||||
|
||||
//Enregistrement clés de doublon pour rappel
|
||||
if ( null !== $keyDoublon ) {
|
||||
$doublonList[] = $keyDoublon;
|
||||
}
|
||||
|
||||
//Trier pour la sortie
|
||||
$tabSortie = array();
|
||||
foreach($tabEntete as $key){
|
||||
|
@ -3,4 +3,4 @@ CREATE TABLE IF NOT EXISTS `profil` (
|
||||
`reference` varchar(50) NOT NULL,
|
||||
`criteres` longtext NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
|
||||
) DEFAULT CHARSET=utf8;
|
Loading…
Reference in New Issue
Block a user