Mbilans : listes

This commit is contained in:
Michael RICOIS 2017-01-04 12:04:31 +01:00
parent 7402364ed5
commit d04eb4d3e2

View File

@ -280,14 +280,7 @@ class Metier_Partenaires_MBilans
*/
public function __construct($siren, $db = null)
{
if ($db === null) {
$this->iDb = new Metier_Util_Db();
} else {
$this->iDb = $db;
}
$this->conn = Zend_Registry::get('doctrine');
$this->siren = $siren;
}
@ -306,16 +299,26 @@ class Metier_Partenaires_MBilans
*/
public function listeBilansDepose($accesPartenaire = false)
{
$where = "siren='$this->siren' AND Rubrique='comptes' ORDER BY dateEffet DESC";
$where = "siren=:siren AND Rubrique='comptes'";
if ($this->companyEvenDateStop !== null) {
$where = "siren='$this->siren' AND Rubrique='comptes' AND dateEffet<'".$this->companyEvenDateStop."' ORDER BY dateEffet DESC";
$where = " AND dateEffet<'".$this->companyEvenDateStop."'";
}
$result = $this->iDb->select('jo.bodacc_detail', 'Bodacc_Date_Parution, dateEffet, typeEven', $where, false, MYSQL_ASSOC);
if (count($result) > 0) {
$dateDerDepot = Metier_Util_Date::dateT('Y-m-d', 'Ymd', $result[0]['dateEffet'])*1;
$where.= " ORDER BY dateEffet DESC LIMIT 0,1";
$fields = "Bodacc_Date_Parution, dateEffet, typeEven";
$listeSql = "SELECT $fields FROM jo.bodacc_detail WHERE $where";
try {
$listeStmt = $this->conn->prepare($listeSql);
$listeStmt->bindValue('siren', $this->siren);
$listeStmt->execute();
} catch(\Doctrine\DBAL\DBALException $e) {
}
if ($listeStmt->rowCount() > 0) {
$listResult = $listeStmt->fetch(\PDO::FETCH_ASSOC);
$dateDerDepot = Metier_Util_Date::dateT('Y-m-d', 'Ymd', $listResult['dateEffet'])*1;
if ($dateDerDepot != 0) {
$this->dernierExerciceDepose = Metier_Util_Date::dateT('Y-m-d', 'd/m/Y', $result[0]['dateEffet']);
$this->dernierExerciceDeposeLe = Metier_Util_Date::dateT('Y-m-d', 'd/m/Y', $result[0]['Bodacc_Date_Parution']);
$this->dernierExerciceDepose = Metier_Util_Date::dateT('Y-m-d', 'd/m/Y', $listResult['dateEffet']);
$this->dernierExerciceDeposeLe = Metier_Util_Date::dateT('Y-m-d', 'd/m/Y', $listResult['Bodacc_Date_Parution']);
}
}
}
@ -333,64 +336,68 @@ class Metier_Partenaires_MBilans
$dateDerDepot = 0;
$tabRet = $tabRet2 = $tabRet3 = array();
if ($nbMaxBilans>0) {
$limit="LIMIT 0, $nbMaxBilans";
} else {
$limit='';
$where = "siren=:siren";
if ($this->companyEvenDateStop !== null) {
$where.= " AND dateExercice<'".$this->companyEvenDateStop."'";
}
$where.= " ORDER BY dateExercice DESC, CASE typeBilan WHEN 'N' THEN 1 WHEN 'S' THEN 2 ELSE 3 END";
if ($nbMaxBilans > 0) {
$where.= " LIMIT 0, $nbMaxBilans";
}
$where = "siren='$this->siren' ORDER BY dateExercice DESC, CASE typeBilan WHEN 'N' THEN 1 WHEN 'S' THEN 2 ELSE 3 END $limit";
if ($this->companyEvenDateStop !== null) {
$where = "siren='$this->siren' AND dateExercice<'".$this->companyEvenDateStop."' ORDER BY dateExercice DESC, CASE typeBilan WHEN 'N' THEN 1 WHEN 'S' THEN 2 ELSE 3 END $limit";
$fields = "typeBilan, dateProvPartenaire, dateExercice, dateExercicePre, dureeExercice, dureeExercicePre, monnaieOrigine, dateInsert, partenaire";
try {
$listeSql = "SELECT $fields FROM jo.bilans WHERE $where";
$listeStmt = $this->conn->prepare($listeSql);
$listeStmt->bindValue('siren', $this->siren);
$listeStmt->execute();
} catch(\Doctrine\DBAL\DBALException $e) {
}
$ret = $this->iDb->select('jo.bilans',
'typeBilan, dateProvPartenaire, dateExercice, dateExercicePre, dureeExercice, dureeExercicePre, monnaieOrigine, dateInsert, partenaire',
$where, false, MYSQL_ASSOC);
$tabTri = array();
if (count($ret) > 0) {
foreach ($ret as $i => $bil) {
if ($listeStmt->rowCount() > 0) {
while($bil = $listeStmt->fetch(\PDO::FETCH_ASSOC)) {
$millesime = Metier_Util_Date::dateT('Ymd', 'd/m/Y', $bil['dateExercice']);
$tabRet[''.$bil['typeBilan'].$millesime] = array(
'dateProvPartenaire' => $bil['dateProvPartenaire'],
'dateInsert' => strtr($bil['dateInsert'], array(' '=>'', ':'=>'', '-'=>'')),
'typeBilan' => $bil['typeBilan'], // NEW
'dureeExercice' => $bil['dureeExercice'],// NEW
'dateExercice' => $bil['dateExercice'],
'dateProvPartenaire' => $bil['dateProvPartenaire'],
'dateInsert' => strtr($bil['dateInsert'], array(' '=>'', ':'=>'', '-'=>'')),
'typeBilan' => $bil['typeBilan'],
'dureeExercice' => $bil['dureeExercice'],
'dateExercice' => $bil['dateExercice'],
'millesime' => substr($bil['dateExercice'], 0, 4),
'dateExercicePre' => $bil['dateExercicePre'],
'dureeExercicePre' => $bil['dureeExercicePre'],
'monnaie' => $bil['monnaieOrigine'],
'source' => $bil['partenaire'],
'dateExercicePre' => $bil['dateExercicePre'],
'dureeExercicePre' => $bil['dureeExercicePre'],
'monnaie' => $bil['monnaieOrigine'],
'source' => $bil['partenaire'],
);
$tabTri[''.$bil['dateExercice'].'-'.$bil['typeBilan']] = $bil['typeBilan'].$millesime;
}
krsort($tabTri);
$exercicePre = $typePre = $tmpPre = false;
$refPre='';
$refPre = '';
foreach ($tabTri as $tmp => $typeMillesime) {
$exercice = substr($tmp, 0, 8);
$type = substr($tmp, 9, 1);
$ref = $tabRet[''.$typeMillesime]['ref'];
if ($exercice==$exercicePre && $type=='N' && $typePre=='S' && $refPre=='') {
if ($exercice == $exercicePre && $type == 'N' && $typePre == 'S' && $refPre == '') {
// Suppression du bilan RN de la liste si Réel Normal et Réel Simplifiés présents en base
unset($tabTri[$tmp]);
} elseif ($exercice==$exercicePre && $type=='N' && $typePre=='S' && $refPre<>'') {
} elseif ($exercice == $exercicePre && $type == 'N' && $typePre == 'S' && $refPre != '') {
// Suppression du bilan RS de la liste si Réel Normal Présent en base et réel simplifié non encore en base
if ($tmpPre<>false) {
if ($tmpPre !== false) {
unset($tabTri[$tmpPre]);
}
}
$exercicePre=$exercice;
$exercicePre = $exercice;
$typePre = $type;
$refPre = @trim($ref);
$tmpPre = $tmp;
}
krsort($tabTri);
$tabRet3=array();
$tabRet3 = array();
foreach ($tabTri as $tmp => $typeMillesime) {
$tabRet3[''.$typeMillesime] = $tabRet[''.$typeMillesime];
}