From 96c00b773bc522eefcda56aa3b1ecf1eff0c1383 Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Tue, 18 Feb 2014 13:23:45 +0000 Subject: [PATCH] issue #0001541 : Delete line to remove duplicates --- library/Metier/Infogreffe/InfogreffeAc.php | 42 +++++++++++-------- library/Metier/Infogreffe/InfogreffeBi.php | 47 ++++++++++++++++------ 2 files changed, 60 insertions(+), 29 deletions(-) diff --git a/library/Metier/Infogreffe/InfogreffeAc.php b/library/Metier/Infogreffe/InfogreffeAc.php index f1e786d9..b0f97ace 100644 --- a/library/Metier/Infogreffe/InfogreffeAc.php +++ b/library/Metier/Infogreffe/InfogreffeAc.php @@ -44,9 +44,12 @@ class Metier_Infogreffe_Ac extends Metier_Infogreffe $this->mode_diffusion = 'XL'; $this->reference_client = 'list-' . $this->siren; + $actesM = new Application_Model_JoGreffesActes($this->db); + //Requete WebService $actesXML = null; if ( $onlyDb === false ) { + $actesM->update(array('actif' => 0), 'siren='.$this->siren); //Infogreffe webservice try { $xml = $this->callRequest(); @@ -59,9 +62,9 @@ class Metier_Infogreffe_Ac extends Metier_Infogreffe } //Lecture de la base de données - $actesM = new Application_Model_JoGreffesActes($this->db); $sql = $actesM->select() ->where('siren=?', $this->siren) + ->where('actif=1') ->order('date_depot DESC') ->order('num_depot DESC') ->order('num_acte ASC') @@ -443,26 +446,29 @@ class Metier_Infogreffe_Ac extends Metier_Infogreffe 'decision_nature' => empty($depot['decision']['nature']) ? '' : $depot['decision']['nature'] , 'decision_libelle' => empty($depot['decision']['libelle']) ? '' : $depot['decision']['libelle'] , 'mode_diffusion' => join(',',$depot['mode_diffusion']), + 'actif' => 1, ); //Only new element are inserted try { $acteM = new Application_Model_JoGreffesActes($this->db); $sql = $acteM->select() - ->where('siren=?', $list['num_siren']) - ->where('num_depot=?', $list['num_depot']) - //->where('date_depot=?', $list['date_depot']) - //->where('date_acte=?', $depot['date_acte']) - ->where('num_acte=?', intval($depot['num_acte'])) - ->order('dateInsert DESC'); + ->where('siren=?', $list['num_siren']) + ->where('num_depot=?', $list['num_depot']) + //->where('date_depot=?', $list['date_depot']) + //->where('date_acte=?', $depot['date_acte']) + ->where('num_acte=?', intval($depot['num_acte'])) + ->order('dateInsert DESC'); $rows = $acteM->fetchAll($sql); } catch(Zend_Db_Adapter_Exception $e) { - throw new Exception('ERR', $e->getMessage()); + throw new Exception($e->getMessage()); } //Insert new element if ( count($rows)==0 ) { try { + //Add dateInsert + $data['dateInsert'] = date('YmdHis'); $result = $acteM->insert($data); } catch(Zend_Exception $e) { throw new Exception($e->getMessage()); @@ -474,19 +480,21 @@ class Metier_Infogreffe_Ac extends Metier_Infogreffe $item = $rows[0]; if ( count($rows) > 1 ) { try { - $result = $acteM->delete('id='.$item->id); + $result = $acteM->delete(array( + 'siren='.$this->siren, + 'num_depot='.$list['num_depot'], + 'num_acte='.intval($depot['num_acte']), + 'id!='.$item->id, + )); } catch(Zend_Exception $e) { throw new Exception($e->getMessage()); } - $item = $rows[1]; } - //Correct type - if ( $depot['type_acte'] != $item->type_acte ) { - try { - $result = $acteM->update($data, 'id='.$item->id); - } catch(Zend_Exception $e) { - throw new Exception($e->getMessage()); - } + + try { + $result = $acteM->update($data, 'id='.$item->id); + } catch(Zend_Exception $e) { + throw new Exception($e->getMessage()); } } diff --git a/library/Metier/Infogreffe/InfogreffeBi.php b/library/Metier/Infogreffe/InfogreffeBi.php index 6e93d5ee..02b43f95 100644 --- a/library/Metier/Infogreffe/InfogreffeBi.php +++ b/library/Metier/Infogreffe/InfogreffeBi.php @@ -57,7 +57,7 @@ class Metier_Infogreffe_Bi extends Metier_Infogreffe $bilansXML = null; if ( $onlyDb === false ) { //Set All line state to 0 - + $bilansM->update(array('actif' => 0), 'siren='.$this->siren); //Infogreffe webservice try { $xml = $this->callRequest(); @@ -71,6 +71,7 @@ class Metier_Infogreffe_Bi extends Metier_Infogreffe //Lecture de la base de données $sql = $bilansM->select() ->where('siren=?', $this->siren) + ->where('actif=1') ->order('date_cloture DESC') ->order('num_depot DESC') ->order('dateInsert DESC'); @@ -426,28 +427,50 @@ class Metier_Infogreffe_Bi extends Metier_Infogreffe $sql = $bilanM->select() ->where('siren=?', $this->siren) ->where('date_cloture=?', $list['date_cloture_iso']) - ->where('type_comptes=?', $list['type_comptes']); - $test = $bilanM->fetchRow($sql); - if ( null === $test ) { - //Add dateInsert - $data['dateInsert'] = date('YmdHis'); - $result = $bilanM->insert($data); - } else { - $result = $bilanM->update($data, 'id='.$test->id); - } + ->where('type_comptes=?', $list['type_comptes']) + ->order('dateInsert DESC'); + $rows = $bilanM->fetchAll($sql); } catch(Zend_Db_Adapter_Exception $e) { throw new Exception($e->getMessage()); } catch(Zend_Db_Exception $e) { - echo $query = $this->db->getProfiler()->getLastQueryProfile()->getQuery(); + /*echo $query = $this->db->getProfiler()->getLastQueryProfile()->getQuery(); echo "\n"; $queryParams = $this->db->getProfiler()->getLastQueryProfile()->getQueryParams(); print_r($queryParams); - echo "\n"; + echo "\n";*/ throw new Exception($e->getMessage()); } $this->db->getProfiler()->setEnabled(false); + if ( count($rows) == 0 ) { + //Add dateInsert + $data['dateInsert'] = date('YmdHis'); + $result = $bilanM->insert($data); + } else { + //Correct multiple item + $item = $rows[0]; + if ( count($rows) > 1 ) { + try { + $result = $bilanM->delete(array( + 'siren='.$this->siren, + 'num_depot='.$list['num_depot'], + 'date_cloture='.$list['date_cloture_iso'], + 'type_comptes='.$list['type_comptes'], + 'id!='.$item->id, + )); + } catch(Zend_Exception $e) { + throw new Exception($e->getMessage()); + } + } + + try { + $result = $bilanM->update($data, 'id='.$item->id); + } catch(Zend_Exception $e) { + throw new Exception($e->getMessage()); + } + } + if ($result) { return true; }