Source : Doctrine
This commit is contained in:
parent
a2287cbabf
commit
482685566c
@ -69,16 +69,16 @@ class Source extends Scores_Ws_Server
|
||||
|
||||
|
||||
// --- Insertion dans la bdd
|
||||
|
||||
try {
|
||||
$bilansM = new Application_Model_JoBilans();
|
||||
$sql = $bilansM->select()
|
||||
->where('siren=?', $siren)
|
||||
->where('dateExercice=?', $cloture)
|
||||
->where('typeBilan=?', $type);
|
||||
$row = $bilansM->fetchRow($sql);
|
||||
|
||||
} catch (Zend_Db_Exception $e) {
|
||||
$sql = "SELECT * FROM jo.bilans WHERE siren = :siren
|
||||
AND dateExercie = :cloture AND typeBilan = :type";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('siren', $siren);
|
||||
$stmt->bindValue('cloture', $cloture);
|
||||
$stmt->bindValue('type', $type);
|
||||
$stmt->execute();
|
||||
}
|
||||
catch (\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->User->idClient == 1) {
|
||||
throw new SoapFault('ERR', $e->getMessage());
|
||||
} else {
|
||||
@ -88,18 +88,20 @@ class Source extends Scores_Ws_Server
|
||||
|
||||
$postesDiff = array();
|
||||
|
||||
if ($row !== null) {
|
||||
// --- Update
|
||||
if ($stmt->rowCount() > 0) {
|
||||
$row = $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
|
||||
// --- Make the diff
|
||||
$postesDiff = array_diff(explode(';', $data->postes), explode(';',$row->postes));
|
||||
$postesDiff = array_diff(explode(';', $data->postes), explode(';',$row['postes']));
|
||||
|
||||
// --- Backup in historiques
|
||||
$historiquesM = new Application_Model_HistoriquesBilans();
|
||||
$backupData = $row->toArray();
|
||||
$backupData = $row;
|
||||
unset($backupData['id']);
|
||||
try {
|
||||
$historiquesM->insert($backupData);
|
||||
} catch (Zend_Db_Exception $e) {
|
||||
$this->conn->insert('historiques.bilans', $backupData);
|
||||
}
|
||||
catch (\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->User->idClient == 1) {
|
||||
throw new SoapFault('ERR', $e->getMessage());
|
||||
} else {
|
||||
@ -109,54 +111,59 @@ class Source extends Scores_Ws_Server
|
||||
|
||||
// --- Define data
|
||||
$dataToUpdate = array(
|
||||
'dateProvPartenaire' => date('Ymd'),
|
||||
'dateExercice' => $data->dateCloture,
|
||||
'dateExercicePre' => $data->dateCloturePre,
|
||||
'dureeExercice' => $data->dureeMois,
|
||||
'dureeExercicePre' => $data->dureeMoisPre,
|
||||
'monnaie' => 'EUR',
|
||||
'typeBilan' => $data->typeBilan,
|
||||
'monnaieOrigine' => 'EUR',
|
||||
'unite' => $data->unite,
|
||||
'postes' => $data->postes,
|
||||
'partenaire' => 1,
|
||||
'confidentiel' => 0,
|
||||
'dateInsert' => date('YmdHis'),
|
||||
'dateProvPartenaire' => date('Ymd'),
|
||||
'dateExercice' => $data->dateCloture,
|
||||
'dateExercicePre' => $data->dateCloturePre,
|
||||
'dureeExercice' => $data->dureeMois,
|
||||
'dureeExercicePre' => $data->dureeMoisPre,
|
||||
'monnaie' => 'EUR',
|
||||
'typeBilan' => $data->typeBilan,
|
||||
'monnaieOrigine' => 'EUR',
|
||||
'unite' => $data->unite,
|
||||
'postes' => $data->postes,
|
||||
'partenaire' => 1,
|
||||
'confidentiel' => 0,
|
||||
'dateInsert' => date('YmdHis'),
|
||||
);
|
||||
|
||||
// --- Update
|
||||
try {
|
||||
$id = $bilansM->update($dataToUpdate, 'id = '.$row->id);
|
||||
} catch (Zend_Db_Exception $e) {
|
||||
$nbRow = $this->conn->update('jo.bilans', $dataToUpdate,
|
||||
array('id' => $row['id']));
|
||||
}
|
||||
catch (\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->User->idClient == 1) {
|
||||
throw new SoapFault('ERR', $e->getMessage());
|
||||
} else {
|
||||
throw new SoapFault('ERR', "Application error");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
// --- Insert
|
||||
else {
|
||||
// --- Define data
|
||||
$dataToInsert = array(
|
||||
'siren' => $siren,
|
||||
'dateProvPartenaire' => date('Ymd'),
|
||||
'dateExercice' => $data->dateCloture,
|
||||
'dateExercicePre' => $data->dateCloturePre,
|
||||
'dureeExercice' => $data->dureeMois,
|
||||
'dureeExercicePre' => $data->dureeMoisPre,
|
||||
'monnaie' => 'EUR',
|
||||
'typeBilan' => $data->typeBilan,
|
||||
'monnaieOrigine' => 'EUR',
|
||||
'unite' => $data->unite,
|
||||
'postes' => $data->postes,
|
||||
'partenaire' => 1,
|
||||
'confidentiel' => 0,
|
||||
'dateInsert' => date('YmdHis'),
|
||||
'siren' => $siren,
|
||||
'dateProvPartenaire' => date('Ymd'),
|
||||
'dateExercice' => $data->dateCloture,
|
||||
'dateExercicePre' => $data->dateCloturePre,
|
||||
'dureeExercice' => $data->dureeMois,
|
||||
'dureeExercicePre' => $data->dureeMoisPre,
|
||||
'monnaie' => 'EUR',
|
||||
'typeBilan' => $data->typeBilan,
|
||||
'monnaieOrigine' => 'EUR',
|
||||
'unite' => $data->unite,
|
||||
'postes' => $data->postes,
|
||||
'partenaire' => 1,
|
||||
'confidentiel' => 0,
|
||||
'dateInsert' => date('YmdHis'),
|
||||
);
|
||||
|
||||
// --- Insert
|
||||
try {
|
||||
$id = $bilansM->insert($dataToInsert);
|
||||
} catch (Zend_Db_Exception $e) {
|
||||
$nbRow = $this->conn->insert('jo.bilans', $dataToInsert);
|
||||
}
|
||||
catch (\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->User->idClient == 1) {
|
||||
throw new SoapFault('ERR', $e->getMessage());
|
||||
} else {
|
||||
@ -166,23 +173,23 @@ class Source extends Scores_Ws_Server
|
||||
|
||||
}
|
||||
|
||||
if (empty($id)) {
|
||||
if ($nbRow == 0) {
|
||||
throw new SoapFault('ERR', "Application error");
|
||||
}
|
||||
|
||||
// --- Save user
|
||||
$userM = new Application_Model_JoBilansUser();
|
||||
try {
|
||||
$userM->insert(array(
|
||||
'idUtilisateur' => $this->User->id,
|
||||
'login' => $this->User->login,
|
||||
'siren' => $siren,
|
||||
'dateExercice' => $data->dateCloture,
|
||||
'typeBilan' => $data->typeBilan,
|
||||
'dateAction' => date('YmdHis'),
|
||||
'postesDiff' => implode(';', $postesDiff),
|
||||
));
|
||||
} catch (Zend_Db_Exception $e) {
|
||||
$this->conn->insert('jo.bilans_user', array(
|
||||
'idUtilisateur' => $this->User->id,
|
||||
'login' => $this->User->login,
|
||||
'siren' => $siren,
|
||||
'dateExercice' => $data->dateCloture,
|
||||
'typeBilan' => $data->typeBilan,
|
||||
'dateAction' => date('YmdHis'),
|
||||
'postesDiff' => implode(';', $postesDiff),
|
||||
));
|
||||
}
|
||||
catch (\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->User->idClient == 1) {
|
||||
throw new SoapFault('ERR', $e->getMessage());
|
||||
} else {
|
||||
@ -190,7 +197,7 @@ class Source extends Scores_Ws_Server
|
||||
}
|
||||
}
|
||||
|
||||
return $id;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function setContact(){}
|
||||
|
Loading…
Reference in New Issue
Block a user