diff --git a/1.2/library/Metier/partenaires/classMBilans.php b/1.2/library/Metier/partenaires/classMBilans.php index f97a3276..0d7ec84f 100644 --- a/1.2/library/Metier/partenaires/classMBilans.php +++ b/1.2/library/Metier/partenaires/classMBilans.php @@ -280,6 +280,24 @@ class MBilans $this->siren = $siren; } + /** + * Défini la date du dernier exercice + * @param string $accesPartenaire + */ + public function listeBilansDepose($accesPartenaire = false) + { + $result = $this->iDb->select('bodacc_detail', 'Bodacc_Date_Parution, dateEffet, typeEven', + "siren='$this->siren' AND Rubrique='comptes' ORDER BY dateEffet DESC",false, MYSQL_ASSOC); + $dateDerDepot = 0; + if ( count($result) > 0 ) { + $dateDerDepot=$classWDate->dateT('Y-m-d','Ymd',$result[0]['dateEffet'])*1; + if ($dateDerDepot<>0) { + $this->dernierExerciceDepose = $classWDate->dateT('Y-m-d','d/m/Y',$result[0]['dateEffet']); + $this->dernierExerciceDeposeLe = $classWDate->dateT('Y-m-d','d/m/Y',$result[0]['Bodacc_Date_Parution']); + } + } + } + /** * Liste les bilans disponibles au format numérique (et non PDF image) pour une entreprise * @param boolean $accesPartenaire @@ -288,58 +306,37 @@ class MBilans * Nombre de bilans maximums retournés * @return array */ - public function listeBilans($accesPartenaire=false, $nbMaxBilans=0) + public function listeBilans($accesPartenaire = false, $nbMaxBilans = 0) { $classWDate = new WDate(); $dateDerDepot = 0; - $tabRet = $tabRet3 = array(); + $tabRet = $tabRet2 = $tabRet3 = array(); if ($nbMaxBilans>0) $limit="LIMIT 0, $nbMaxBilans"; else $limit=''; - $ret = $this->iDb->select( - 'bilans', - 'typeBilan, dateProvPartenaire, dateExercice, dateExercicePre, dureeExercice, dureeExercicePre, monnaieOrigine, dateInsert, partenaire', - "siren='$this->siren' ORDER BY dateExercice DESC $limit",false, MYSQL_ASSOC); - if ( count($ret)>0 ) { - $dateDerExercice=$ret[0]['dateExercice']*1; - } - - //@sendMail('production@scores-decisions.com', 'ylenaour@scores-decisions.com', "listeBilans sur $this->siren en base", print_r($ret, true)); - - $ret2 = $this->iDb->select( - 'bodacc_detail', - 'Bodacc_Date_Parution, dateEffet, typeEven', - "siren='$this->siren' AND Rubrique='comptes' ORDER BY dateEffet DESC",false, MYSQL_ASSOC); - if ( count($ret2)>0 ) { - $dateDerDepot=$classWDate->dateT('Y-m-d','Ymd',$ret2[0]['dateEffet'])*1; - if ($dateDerDepot<>0) { - $this->dernierExerciceDepose = $classWDate->dateT('Y-m-d','d/m/Y',$ret2[0]['dateEffet']); - $this->dernierExerciceDeposeLe = $classWDate->dateT('Y-m-d','d/m/Y',$ret2[0]['Bodacc_Date_Parution']); - } - } + $ret = $this->iDb->select('bilans', + 'typeBilan, dateProvPartenaire, dateExercice, dateExercicePre, dureeExercice, dureeExercicePre, monnaieOrigine, dateInsert, partenaire', + "siren='$this->siren' ORDER BY dateExercice DESC, CASE typeBilan WHEN 'N' THEN 1 WHEN 'S' THEN 2 ELSE 3 END $limit",false, MYSQL_ASSOC); if ($accesPartenaire) { $iGreffe = new MGreffes($this->iDb); - $tabRet=$tabRet2=$iGreffe->getListeBilans($this->siren); - } else { - $tabRet=$tabRet2=array(); + $tabRet = $tabRet2 = $iGreffe->getListeBilans($this->siren); } - $tabTri=array(); + $tabTri = array(); if ( count($tabRet)>0 ) { - foreach ($tabRet as $millesime=>$bil) { + foreach ($tabRet as $millesime => $bil) { $typeBilan = substr($millesime,0,1); - $dateExercice = $classWDate->dateT('d/m/Y','Ymd',substr($millesime,1,10)); - $tabTri[''.$dateExercice.'-'.$typeBilan]=$millesime; + $dateExercice = $classWDate->dateT('d/m/Y','Ymd', substr($millesime,1,10)); + $tabTri[''.$dateExercice.'-'.$typeBilan] = $millesime; } } - //@sendMail('production@scores-decisions.com', 'ylenaour@scores-decisions.com', "listeBilans sur $this->siren après accès partenaire", print_r($tabRet2, true)); - if ( count($ret)>0 ) { - foreach ($ret as $i=>$bil) { - $millesime=$classWDate->dateT('Ymd','d/m/Y',$bil['dateExercice']); + if ( count($ret) > 0 ) { + foreach ($ret as $i => $bil) { + $millesime = $classWDate->dateT('Ymd','d/m/Y',$bil['dateExercice']); $tabRet[''.$bil['typeBilan'].$millesime] = array( 'dateProvPartenaire' => $bil['dateProvPartenaire'], 'dateInsert' => strtr($bil['dateInsert'], array(' '=>'',':'=>'','-'=>'')), @@ -352,44 +349,37 @@ class MBilans 'monnaie' => $bil['monnaieOrigine'], 'source' => $bil['partenaire'], ); - $tabTri[''.$bil['dateExercice'].'-'.$bil['typeBilan']]=$bil['typeBilan'].$millesime; + $tabTri[''.$bil['dateExercice'].'-'.$bil['typeBilan']] = $bil['typeBilan'].$millesime; } krsort($tabTri); - //@sendMail('production@scores-decisions.com', 'ylenaour@scores-decisions.com', "listeBilans sur $this->siren avant le tri", print_r($tabTri, true)); - - $exercicePre=$typePre=$tmpPre=false; + $exercicePre = $typePre = $tmpPre = false; $refPre=''; - $strInfos=''; - foreach ($tabTri as $tmp=>$typeMillesime) { - $exercice=substr($tmp,0,8); - $type=substr($tmp,9,1); - $ref=$tabRet[''.$typeMillesime]['ref']; + 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=='') { // Suppression du bilan RN de la liste si Réel Normal et Réel Simplifiés présents en base unset($tabTri[$tmp]); - $strInfos.="Suppression de '$tmp'".EOL; } 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) { unset($tabTri[$tmpPre]); - $strInfos.="Suppression de '$tmpPre'".EOL; } } $exercicePre=$exercice; - $typePre=$type; - $refPre=@trim($ref); - $tmpPre=$tmp; + $typePre = $type; + $refPre = @trim($ref); + $tmpPre = $tmp; } krsort($tabTri); - //@sendMail('production@scores-decisions.com', 'ylenaour@scores-decisions.com', "listeBilans sur $this->siren après le tri", print_r($tabTri, true).EOL.$strInfos.EOL); $tabRet3=array(); - foreach ($tabTri as $tmp=>$typeMillesime) - $tabRet3[''.$typeMillesime]=$tabRet[''.$typeMillesime]; - - //@sendMail('production@scores-decisions.com', 'ylenaour@scores-decisions.com', "listeBilans sur $this->siren après le tri / retour", print_r($tabRet3, true)); + foreach ($tabTri as $tmp => $typeMillesime) { + $tabRet3[''.$typeMillesime] = $tabRet[''.$typeMillesime]; + } } return $tabRet3; @@ -417,74 +407,74 @@ class MBilans $classWDate = new WDate(); $millesimeDB = $classWDate->dateT('d/m/Y', 'Ymd', $millesime); - if ($accesPartenaire) - { + if ($accesPartenaire) { // On ne veut pas de bilans "Téléchargés" directement sur Internet $strSansBilansWeb=' AND partenaire<>7 '; - } - else - { + } else { $strSansBilansWeb=''; } $bilan = null; - $iGreffe = new MGreffes($this->iDb); $ret = $this->iDb->select('bilans', 'dateProvPartenaire, dateExercice, dateExercicePre, dureeExercice, dureeExercicePre, monnaie, typeBilan, monnaieOrigine, unite, postes, partenaire, id, confidentiel, dateInsert', "siren='$this->siren' AND typeBilan='$typeBilan' AND dateExercice='$millesimeDB' $strSansBilansWeb", false, MYSQL_ASSOC); - if (count($ret)==0 && $accesPartenaire) - { - if ($refPart=='' || $refPart==0) - { - $tabTmp = $iGreffe->getListeBilans($this->siren); - foreach ($tabTmp as $idx=>$bil) - { - $typeBil=substr($idx,0,1); - $millBil=substr($idx,1,10); - if ($typeBil==$typeBilan && $millBil==$millesime) + + if ( $accesPartenaire ) { + $iGreffe = new MGreffes($this->iDb); + if ( count($ret) == 0 ) { + if ($refPart=='' || $refPart==0) { + $tabTmp = $iGreffe->getListeBilans($this->siren); + foreach ($tabTmp as $idx=>$bil) { - $refPart=$bil['ref']; - break; + $typeBil=substr($idx,0,1); + $millBil=substr($idx,1,10); + if ($typeBil==$typeBilan && $millBil==$millesime) + { + $refPart=$bil['ref']; + break; + } + } + } + $tabBilan = $iGreffe->getBilan($this->siren, $refPart); + + if ($tabBilan) + { + $strPostes=''; + foreach ($tabBilan['POSTES'] as $poste=>$valeur) { + $strPostes.="$poste=$valeur;"; + } + + $tabInsert=array( + 'siren' => $this->siren, + 'dateProvPartenaire'=> $tabBilan['DATE_FRAICHE_BILAN'], + 'dateExercice' => $classWDate->dateT('d/m/Y','Ymd',$tabBilan['DATE_CLOTURE']), + 'dateExercicePre' => $classWDate->dateT('d/m/Y','Ymd',$tabBilan['DATE_CLOTURE_PRE']), + 'dureeExercice' => $tabBilan['DUREE_MOIS'], + 'dureeExercicePre' => $tabBilan['DUREE_MOIS_PRE'], + 'monnaie' => $tabBilan['MONNAIE'], + 'typeBilan' => $tabBilan['TYPE_BILAN'], + 'monnaieOrigine' => $tabBilan['MONNAIE_ORI'], + 'unite' => $tabBilan['MONNAIE_LIV_UNITE'], + 'postes' => $strPostes, + 'partenaire' => $tabBilan['SOURCE'], + ); + if (!$this->iDb->insert('bilans', $tabInsert, true)) { + $this->iDb->update('bilans', $tabInsert, "siren='$this->siren' AND typeBilan='$typeBilan' AND dateExercice='$millesimeDB'"); + } + + $ret = $this->iDb->select('bilans', 'dateProvPartenaire, dateExercice, dateExercicePre, dureeExercice, dureeExercicePre, monnaie, typeBilan, monnaieOrigine, unite, postes, partenaire, id, confidentiel, dateInsert', "siren='$this->siren' AND typeBilan='$typeBilan' AND dateExercice='$millesimeDB'", true); + if (count($ret) > 0) { + $bilan = $ret[0]; } } } - $tabBilan = $iGreffe->getBilan($this->siren, $refPart); - - if ($tabBilan) - { - $strPostes=''; - foreach ($tabBilan['POSTES'] as $poste=>$valeur) { - $strPostes.="$poste=$valeur;"; - } - - $tabInsert=array( - 'siren' => $this->siren, - 'dateProvPartenaire'=> $tabBilan['DATE_FRAICHE_BILAN'], - 'dateExercice' => $classWDate->dateT('d/m/Y','Ymd',$tabBilan['DATE_CLOTURE']), - 'dateExercicePre' => $classWDate->dateT('d/m/Y','Ymd',$tabBilan['DATE_CLOTURE_PRE']), - 'dureeExercice' => $tabBilan['DUREE_MOIS'], - 'dureeExercicePre' => $tabBilan['DUREE_MOIS_PRE'], - 'monnaie' => $tabBilan['MONNAIE'], - 'typeBilan' => $tabBilan['TYPE_BILAN'], - 'monnaieOrigine' => $tabBilan['MONNAIE_ORI'], - 'unite' => $tabBilan['MONNAIE_LIV_UNITE'], - 'postes' => $strPostes, - 'partenaire' => $tabBilan['SOURCE'], - ); - if (!$this->iDb->insert('bilans', $tabInsert, true)) { - $this->iDb->update('bilans', $tabInsert, "siren='$this->siren' AND typeBilan='$typeBilan' AND dateExercice='$millesimeDB'"); - } - - $ret = $this->iDb->select('bilans', 'dateProvPartenaire, dateExercice, dateExercicePre, dureeExercice, dureeExercicePre, monnaie, typeBilan, monnaieOrigine, unite, postes, partenaire, id, confidentiel, dateInsert', "siren='$this->siren' AND typeBilan='$typeBilan' AND dateExercice='$millesimeDB'", true); - if (count($ret) > 0) { - $bilan = $ret[0]; - } - } - } else { - $bilan = $ret[0]; } - + + if (count($ret) > 0) { + $bilan = $ret[0]; + } + $tabBilan = $tabBilanPre = $bilanPre = array(); if ($bilan !== null) diff --git a/1.2/library/framework/common/mysql.new.php b/1.2/library/framework/common/mysql.new.php index 21d265cc..e72b0db5 100644 --- a/1.2/library/framework/common/mysql.new.php +++ b/1.2/library/framework/common/mysql.new.php @@ -77,9 +77,9 @@ class WDB $values = str_replace("'NULL'", 'NULL', $values); if ($low_priority) - $query = 'INSERT DELAYED INTO `'.$table.'` (`'.$fields.'`) VALUES ('.$values.');'; + $query = 'INSERT DELAYED INTO '.$table.' ('.$fields.') VALUES ('.$values.');'; else - $query = 'INSERT INTO `'.$table.'` (`'.$fields.'`) VALUES ('.$values.');'; + $query = 'INSERT INTO '.$table.' ('.$fields.') VALUES ('.$values.');'; if ($debug) $tdeb=microtime_float(); @@ -117,12 +117,12 @@ class WDB $values = array_values($update); $i=0; if ($low_priority) - $query='UPDATE LOW_PRIORITY `'.$table.'` SET '; + $query='UPDATE LOW_PRIORITY '.$table.' SET '; else - $query='UPDATE `'.$table.'` SET '; + $query='UPDATE '.$table.' SET '; while(isset($fields[$i])){ if($i>0) { $query.=', '; } - $query.=' '.$fields[$i]."='".$this->db->quote($values[$i])."'"; + $query.=' '.$fields[$i]."=".$this->db->quote($values[$i]); $i++; } $query = str_replace("'NULL'", 'NULL', $query);