issue #0001541 : Delete line to remove duplicates

This commit is contained in:
Michael RICOIS 2014-02-18 13:23:45 +00:00
parent f7a65e2df3
commit 96c00b773b
2 changed files with 60 additions and 29 deletions

View File

@ -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());
}
}

View File

@ -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;
}