Library Update
This commit is contained in:
parent
7abb183e7a
commit
19e3e26644
@ -16,16 +16,15 @@ D. 067 200 329 I 2010-06-30 La CS est valide jusq'au 30/06/2010... Quid
|
||||
*/
|
||||
class Metier_Partenaires_MFacto
|
||||
{
|
||||
public $risqueImpaye=false; // Y a t'il un risque d'impayé ?
|
||||
public $risqueImpayeMois=0;
|
||||
public $profilPayeur=0; // 0:N/D, 1:Excellent, 2=Bon, 3=Normal, 4=Lent, 5=Mauvais ou Défaut
|
||||
public $risqueImpaye = false; // Y a t'il un risque d'impayé ?
|
||||
public $risqueImpayeMois = 0;
|
||||
public $profilPayeur = 0; // 0:N/D, 1:Excellent, 2=Bon, 3=Normal, 4=Lent, 5=Mauvais ou Défaut
|
||||
|
||||
private $typeFlux = 0; // Type de flux en chargement 0:Acheteur, 1=CS, 2=Paiements
|
||||
private $iDb;
|
||||
|
||||
public $DELAIPAY=0;
|
||||
public $DELAIPAYp='';
|
||||
public $DELAIPAY_MMAA='';
|
||||
public $DELAIPAY = 0;
|
||||
public $DELAIPAYp = '';
|
||||
public $DELAIPAY_MMAA = '';
|
||||
|
||||
private $tabInfoCS = array(
|
||||
'_00' => array('risque'=>0,'type'=>'OK', 'libInt'=>'Néant', 'libExt'=>'Aucune difficulté significative ne nous a été signalée'),
|
||||
@ -65,33 +64,35 @@ class Metier_Partenaires_MFacto
|
||||
);
|
||||
|
||||
private $tabTranches = array(
|
||||
0=>6,
|
||||
30=>36,
|
||||
60=>66,
|
||||
90=>96,
|
||||
120=>126,
|
||||
150=>156,
|
||||
180=>999,
|
||||
0 => 6,
|
||||
30 => 36,
|
||||
60 => 66,
|
||||
90 => 96,
|
||||
120 => 126,
|
||||
150 => 156,
|
||||
180 => 999,
|
||||
);
|
||||
|
||||
private $tabMontants = array(
|
||||
1=>500,
|
||||
2=>2000,
|
||||
10=>10000,
|
||||
20=>20000,
|
||||
50=>50000,
|
||||
100=>100000,
|
||||
200=>200000,
|
||||
999=>999999
|
||||
1 => 500,
|
||||
2 => 2000,
|
||||
10 => 10000,
|
||||
20 => 20000,
|
||||
50 => 50000,
|
||||
100 => 100000,
|
||||
200 => 200000,
|
||||
999 => 999999
|
||||
);
|
||||
|
||||
public function __construct($db = null)
|
||||
/**
|
||||
* PDO Connection with Doctrine
|
||||
* @var \Doctrine\DBAL\Connection
|
||||
*/
|
||||
protected $conn;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
if ($db === null) {
|
||||
$this->iDb = new Metier_Util_Db();
|
||||
} else {
|
||||
$this->iDb = $db;
|
||||
}
|
||||
$this->conn = Zend_Registry::get('doctrine');
|
||||
}
|
||||
|
||||
public function setTypeFic($typeFic)
|
||||
@ -104,145 +105,167 @@ class Metier_Partenaires_MFacto
|
||||
switch ($this->typeFlux) {
|
||||
case 0: // Acheteur GESCDCLT - Line length (120 + CRLF = 122)
|
||||
$tab = array(
|
||||
'NUMACH'=> trim(substr($a, 0, 7)), // 0-7 | 7
|
||||
'SIRENE'=> trim(substr($a, 7, 9)), // 7-16 | 9
|
||||
'RAISOC'=> trim(substr($a, 16, 35)), // 16-51 | 35
|
||||
'NUMVOI'=> trim(substr($a, 51, 4)), // 51-55 | 4
|
||||
'TYPVOI'=> trim(substr($a, 55, 3)), // 55-58 | 3
|
||||
'LIBVOI'=> trim(substr($a, 58, 30)), // 58-88 | 30
|
||||
'VILLE'=> trim(substr($a, 88, 26)), // 88-114 | 26
|
||||
'CODPOS'=> trim(substr($a, 114, 5)), // 114-119 | 5
|
||||
'FILLER'=> trim(substr($a, 119, 2)), // 119-120 | 1
|
||||
'NUMACH' => trim(substr($a, 0, 7)), // 0-7 | 7
|
||||
'SIRENE' => trim(substr($a, 7, 9)), // 7-16 | 9
|
||||
'RAISOC' => trim(substr($a, 16, 35)), // 16-51 | 35
|
||||
'NUMVOI' => trim(substr($a, 51, 4)), // 51-55 | 4
|
||||
'TYPVOI' => trim(substr($a, 55, 3)), // 55-58 | 3
|
||||
'LIBVOI' => trim(substr($a, 58, 30)), // 58-88 | 30
|
||||
'VILLE' => trim(substr($a, 88, 26)), // 88-114 | 26
|
||||
'CODPOS' => trim(substr($a, 114, 5)),// 114-119 | 5
|
||||
'FILLER' => trim(substr($a, 119, 2)),// 119-120 | 1
|
||||
);
|
||||
break;
|
||||
case 1: // CS - GESDACH - Line Length (19 + CRLF = 21)
|
||||
$tab = array(
|
||||
'siren' => trim(substr($a, 0, 9)), // 0-9 | 9
|
||||
'cs' => trim(substr($a, 9, 2)), // 9-11 | 2
|
||||
'dateFin'=> trim(substr($a, 11, 8)), // 11-9 | 8
|
||||
'siren' => trim(substr($a, 0, 9)), // 0-9 | 9
|
||||
'cs' => trim(substr($a, 9, 2)), // 9-11 | 2
|
||||
'dateFin'=> trim(substr($a, 11, 8)), // 11-9 | 8
|
||||
);
|
||||
break;
|
||||
case 2: // Paiements - GESCDMVT - Line length (73 + CRLF = 75)
|
||||
$tab = array(
|
||||
'NUMACH'=> trim(substr($a, 0, 7)), // 0-7 | 7
|
||||
'DATPIE'=> substr($a, 7, 8), // 7-15 | 8
|
||||
'DATECH'=> substr($a, 15, 8), // 15-23 | 8
|
||||
'DATPAI'=> substr($a, 23, 8), // 23-31 | 8
|
||||
'MNTPIE'=> trim(substr($a, 31, 13)), // 31-44 | 13
|
||||
'MNTFRF'=> trim(substr($a, 44, 13)), // 44-57 | 13
|
||||
'MNTLIT'=> trim(substr($a, 57, 13)), // 57-70 | 13
|
||||
'CODDEV'=> trim(substr($a, 70, 3)), // 70-73 | 3
|
||||
'NUMACH' => trim(substr($a, 0, 7)), // 0-7 | 7
|
||||
'DATPIE' => substr($a, 7, 8), // 7-15 | 8
|
||||
'DATECH' => substr($a, 15, 8), // 15-23 | 8
|
||||
'DATPAI' => substr($a, 23, 8), // 23-31 | 8
|
||||
'MNTPIE' => trim(substr($a, 31, 13)), // 31-44 | 13
|
||||
'MNTFRF' => trim(substr($a, 44, 13)), // 44-57 | 13
|
||||
'MNTLIT' => trim(substr($a, 57, 13)), // 57-70 | 13
|
||||
'CODDEV' => trim(substr($a, 70, 3)), // 70-73 | 3
|
||||
);
|
||||
break;
|
||||
}
|
||||
return $tab;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $siren
|
||||
* @return array
|
||||
*/
|
||||
public function getCoteSpeciale($siren)
|
||||
{
|
||||
$ret=$this->iDb->select(
|
||||
'sdv1.ge_cs2',
|
||||
'siren, cs, dateFin, dateInsert, dateConf',
|
||||
"siren=$siren AND (dateSuppr=0 OR dateConf>dateSuppr) AND (dateFin=0 OR dateFin>NOW()) AND cs NOT IN (20,22,27,33,34) ORDER BY dateConf DESC, dateInsert DESC", false, MYSQL_ASSOC);
|
||||
$tabRet=array();
|
||||
foreach ($ret as $i=>$tabCS) {
|
||||
$dateEven=$tabCS['dateConf'];
|
||||
if ($dateEven=='0000-00-00') {
|
||||
$dateEven=$tabCS['dateInsert'];
|
||||
$sql = "SELECT siren, cs, dateFin, dateInsert, dateConf FROM sdv1.ge_cs2
|
||||
WHERE siren=:siren AND (dateSuppr=0 OR dateConf>dateSuppr)
|
||||
AND (dateFin=0 OR dateFin>NOW()) AND cs NOT IN (20,22,27,33,34)
|
||||
ORDER BY dateConf DESC, dateInsert DESC";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('siren', $siren);
|
||||
$stmt->execute();
|
||||
$tabRet = array();
|
||||
if ($stmt->rowCount() > 0) {
|
||||
while ($tabCS = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$dateEven = $tabCS['dateConf'];
|
||||
if ($dateEven == '0000-00-00') {
|
||||
$dateEven = $tabCS['dateInsert'];
|
||||
}
|
||||
$tabRet[] = array(
|
||||
'DateEven' => $dateEven,
|
||||
'DateFin' => $tabCS['dateFin'],
|
||||
'CoteCS' => $tabCS['cs'],
|
||||
//'CoteCSpre' => $tabCS['CSAVAN'],
|
||||
'LibCS' => $this->tabInfoCS['_'.$tabCS['cs']]['libExt'],
|
||||
//'LibCSpre' => $this->tabInfoCS[$tabCS['CSAVAN']*1]['libExt'],
|
||||
'NivRisque' => $this->tabInfoCS['_'.$tabCS['cs']]['risque'],
|
||||
//'NivRisquePre'=> $this->tabInfoCS[$tabCS['CSAVAN']*1]['risque'],
|
||||
'CodeRisque' => $this->tabInfoCS['_'.$tabCS['cs']]['type'],
|
||||
);
|
||||
}
|
||||
$tabRet[]=array(
|
||||
'DateEven' => $dateEven,
|
||||
'DateFin' => $tabCS['dateFin'],
|
||||
'CoteCS' => $tabCS['cs'],
|
||||
//'CoteCSpre' => $tabCS['CSAVAN'],
|
||||
'LibCS' => $this->tabInfoCS['_'.$tabCS['cs']]['libExt'],
|
||||
//'LibCSpre' => $this->tabInfoCS[$tabCS['CSAVAN']*1]['libExt'],
|
||||
'NivRisque' => $this->tabInfoCS['_'.$tabCS['cs']]['risque'],
|
||||
//'NivRisquePre' => $this->tabInfoCS[$tabCS['CSAVAN']*1]['risque'],
|
||||
'CodeRisque' => $this->tabInfoCS['_'.$tabCS['cs']]['type'],
|
||||
);
|
||||
}
|
||||
|
||||
return $tabRet;
|
||||
}
|
||||
|
||||
public function getCoteSpecialeOld($siren)
|
||||
{
|
||||
$ret=$this->iDb->select('sdv1.ge_cs c LEFT JOIN sdv1.ge_acheteurs a ON a.NUMACH=c.NUMGFH',
|
||||
'DATMAJ1, NUMGFH, CSAVAN, CSAPRE, SIRENE',
|
||||
"a.SIRENE=$siren ORDER BY a.SIRENE ASC, c.DATMAJ1 DESC", false, MYSQL_ASSOC);
|
||||
$tabRet=array();
|
||||
foreach ($ret as $i=>$tabCS) {
|
||||
$tabRet[]=array(
|
||||
'DateEven' => $tabCS['DATMAJ1'],
|
||||
'CoteCS' => $tabCS['CSAPRE'],
|
||||
'CoteCSpre' => $tabCS['CSAVAN'],
|
||||
'LibCS' => $this->tabInfoCS[$tabCS['CSAPRE']*1]['libExt'],
|
||||
'LibCSpre' => $this->tabInfoCS[$tabCS['CSAVAN']*1]['libExt'],
|
||||
'NivRisque' => $this->tabInfoCS[$tabCS['CSAPRE']*1]['risque'],
|
||||
'NivRisquePre' => $this->tabInfoCS[$tabCS['CSAVAN']*1]['risque'],
|
||||
'CodeRisque' => $this->tabInfoCS[$tabCS['CSAPRE']*1]['type'],
|
||||
);
|
||||
$sql = "SELECT DATMAJ1, NUMGFH, CSAVAN, CSAPRE, SIRENE
|
||||
FROM sdv1.ge_cs c LEFT JOIN sdv1.ge_acheteurs a ON a.NUMACH=c.NUMGFH
|
||||
WHERE a.SIRENE=:siren ORDER BY a.SIRENE ASC, c.DATMAJ1 DESC";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('siren', $siren);
|
||||
$stmt->execute();
|
||||
|
||||
$tabRet = array();
|
||||
if ($stmt->rowCount() > 0) {
|
||||
while ($tabCS = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$tabRet[] = array(
|
||||
'DateEven' => $tabCS['DATMAJ1'],
|
||||
'CoteCS' => $tabCS['CSAPRE'],
|
||||
'CoteCSpre' => $tabCS['CSAVAN'],
|
||||
'LibCS' => $this->tabInfoCS[$tabCS['CSAPRE']*1]['libExt'],
|
||||
'LibCSpre' => $this->tabInfoCS[$tabCS['CSAVAN']*1]['libExt'],
|
||||
'NivRisque' => $this->tabInfoCS[$tabCS['CSAPRE']*1]['risque'],
|
||||
'NivRisquePre' => $this->tabInfoCS[$tabCS['CSAVAN']*1]['risque'],
|
||||
'CodeRisque' => $this->tabInfoCS[$tabCS['CSAPRE']*1]['type'],
|
||||
);
|
||||
}
|
||||
}
|
||||
return $tabRet;
|
||||
}
|
||||
|
||||
public function getPaiements($siren, $echelle='mois')
|
||||
public function getPaiements($siren, $echelle = 'mois')
|
||||
{
|
||||
if ($echelle=='jour') {
|
||||
$strGroupBy="GROUP BY p.DATPIE ";
|
||||
} elseif ($echelle=='' || $echelle=='mois') {
|
||||
$strGroupBy="GROUP BY mois HAVING nbPieces>2 ";
|
||||
} elseif ($echelle=='trim') {
|
||||
$strGroupBy="GROUP BY trimestre HAVING nbPieces>2 ";
|
||||
} else { // En mois par défaut
|
||||
$strGroupBy="GROUP BY mois HAVING nbPieces>2 ";
|
||||
if ($echelle == 'jour') {
|
||||
$strGroupBy = "GROUP BY p.DATPIE ";
|
||||
} elseif ($echelle == '' || $echelle == 'mois') {
|
||||
$strGroupBy = "GROUP BY mois HAVING nbPieces>2 ";
|
||||
} elseif ($echelle == 'trim') {
|
||||
$strGroupBy = "GROUP BY trimestre HAVING nbPieces>2 ";
|
||||
} else { // En mois par défaut
|
||||
$strGroupBy = "GROUP BY mois HAVING nbPieces>2 ";
|
||||
}
|
||||
|
||||
$ret=$this->iDb->select('sdv1.ge_paiements p LEFT JOIN sdv1.ge_acheteurs a ON a.NUMACH=p.NUMACH',
|
||||
"p.NUMACH, DATE_FORMAT(p.DATPIE, '%Y-%m') AS mois,
|
||||
CONCAT(DATE_FORMAT(p.DATPIE,'%Y'),'-',IF(DATE_FORMAT(p.DATPIE,'%m')<4,1,IF(DATE_FORMAT(p.DATPIE,'%m')<7,2,IF(DATE_FORMAT(p.DATPIE,'%m')<10,3,4)))) AS trimestre,
|
||||
count(*) AS nbPieces,
|
||||
AVG(DATEDIFF(NOW(), p.DATECH)) AS nbJourRetard, AVG(DATEDIFF(p.DATPAI, p.DATECH)) AS nbJourPaiement,
|
||||
ROUND(AVG(DATEDIFF(NOW(), p.DATECH) - DATEDIFF(p.DATPAI, p.DATECH))) AS nbJourMoyens,
|
||||
IF(AVG(DATEDIFF(NOW(), p.DATECH) - DATEDIFF( p.DATPAI, p.DATECH ) ) <6, 0, if( AVG( DATEDIFF( NOW( ) , p.DATECH ) - DATEDIFF( p.DATPAI, p.DATECH ) ) <36, 30, if( AVG( DATEDIFF( NOW( ) , p.DATECH ) - DATEDIFF( p.DATPAI, p.DATECH ) ) <66, 60, if( AVG( DATEDIFF( NOW( ) , p.DATECH ) - DATEDIFF( p.DATPAI, p.DATECH ) ) <96, 90, 120 ) ) ) ) AS nbJours,
|
||||
SUM(p.MNTPIE) AS mtPieces, SUM(p.MNTFRF) AS mtPaiements, SUM(p.MNTLIT) AS mtLitiges,
|
||||
p.CODDEV, a.SIRENE, a.RAISOC, a.CODPOS, a.VILLE",
|
||||
"a.SIRENE=$siren AND DATEDIFF(NOW(),p.DATECH)<736 AND p.DATECH<NOW() $strGroupBy ORDER BY p.DATPIE DESC", false, MYSQL_ASSOC);
|
||||
$tabRet=array();
|
||||
foreach ($ret as $i=>$tabPai) {
|
||||
$nbJoursMoyen=$tabPai['nbJourRetard']-$tabPai['nbJourPaiement'];
|
||||
if ($nbJoursMoyen<6) {
|
||||
$tranche=0;
|
||||
} elseif ($nbJoursMoyen<36) {
|
||||
$tranche=30;
|
||||
} elseif ($nbJoursMoyen<66) {
|
||||
$tranche=60;
|
||||
} elseif ($nbJoursMoyen<96) {
|
||||
$tranche=90;
|
||||
} elseif ($nbJoursMoyen<126) {
|
||||
$tranche=120;
|
||||
} elseif ($nbJoursMoyen<156) {
|
||||
$tranche=150;
|
||||
} else {
|
||||
$tranche=180;
|
||||
}
|
||||
$sql = "SELECT p.NUMACH,
|
||||
DATE_FORMAT(p.DATPIE, '%Y-%m') AS mois,
|
||||
CONCAT(DATE_FORMAT(p.DATPIE,'%Y'),'-',IF(DATE_FORMAT(p.DATPIE,'%m')<4,1,IF(DATE_FORMAT(p.DATPIE,'%m')<7,2,IF(DATE_FORMAT(p.DATPIE,'%m')<10,3,4)))) AS trimestre,
|
||||
count(*) AS nbPieces,
|
||||
AVG(DATEDIFF(NOW(), p.DATECH)) AS nbJourRetard,
|
||||
AVG(DATEDIFF(p.DATPAI, p.DATECH)) AS nbJourPaiement,
|
||||
ROUND(AVG(DATEDIFF(NOW(), p.DATECH) - DATEDIFF(p.DATPAI, p.DATECH))) AS nbJourMoyens,
|
||||
IF(AVG(DATEDIFF(NOW(), p.DATECH) - DATEDIFF( p.DATPAI, p.DATECH ) ) <6, 0, if( AVG( DATEDIFF( NOW( ) , p.DATECH ) - DATEDIFF( p.DATPAI, p.DATECH ) ) <36, 30, if( AVG( DATEDIFF( NOW( ) , p.DATECH ) - DATEDIFF( p.DATPAI, p.DATECH ) ) <66, 60, if( AVG( DATEDIFF( NOW( ) , p.DATECH ) - DATEDIFF( p.DATPAI, p.DATECH ) ) <96, 90, 120 ) ) ) ) AS nbJours,
|
||||
SUM(p.MNTPIE) AS mtPieces, SUM(p.MNTFRF) AS mtPaiements, SUM(p.MNTLIT) AS mtLitiges,
|
||||
p.CODDEV, a.SIRENE, a.RAISOC, a.CODPOS, a.VILLE
|
||||
FROM dv1.ge_paiements p LEFT JOIN sdv1.ge_acheteurs a ON a.NUMACH=p.NUMACH
|
||||
WHERE a.SIRENE=:siren AND DATEDIFF(NOW(),p.DATECH)<736 AND p.DATECH<NOW() $strGroupBy ORDER BY p.DATPIE DESC";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('siren', $siren);
|
||||
$stmt->execute();
|
||||
if ($stmt->rowCount() > 0) {
|
||||
while ($tabPai = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$nbJoursMoyen = $tabPai['nbJourRetard'] - $tabPai['nbJourPaiement'];
|
||||
if ($nbJoursMoyen < 6) {
|
||||
$tranche = 0;
|
||||
} elseif ($nbJoursMoyen < 36) {
|
||||
$tranche = 30;
|
||||
} elseif ($nbJoursMoyen < 66) {
|
||||
$tranche = 60;
|
||||
} elseif ($nbJoursMoyen < 96) {
|
||||
$tranche = 90;
|
||||
} elseif ($nbJoursMoyen < 126) {
|
||||
$tranche = 120;
|
||||
} elseif ($nbJoursMoyen < 156) {
|
||||
$tranche = 150;
|
||||
} else {
|
||||
$tranche = 180;
|
||||
}
|
||||
|
||||
$tabRet[]=array(
|
||||
'trimestre' => $tabPai['trimestre'],
|
||||
'mois' => $tabPai['mois'],
|
||||
'nbPieces' => $tabPai['nbPieces'],
|
||||
'nbJourRetard' => $tabPai['nbJourRetard'],
|
||||
'nbJourPaiement'=> $tabPai['nbJourPaiement'],
|
||||
'nbJourMoyen' => $nbJoursMoyen,
|
||||
'nbJourMoyen2' => $tabPai['nbJourMoyens'],
|
||||
'tranchePaiement'=>$tranche,
|
||||
'tranchePaie90' =>$tabPai['nbJours'],
|
||||
'mtPieces' => $tabPai['mtPieces'],
|
||||
'mtPaiements' => $tabPai['mtPaiements'],
|
||||
'mtLitiges' => $tabPai['mtLitiges'],
|
||||
'devise' => $tabPai['CODDEV'],
|
||||
);
|
||||
$tabRet[] = array(
|
||||
'trimestre' => $tabPai['trimestre'],
|
||||
'mois' => $tabPai['mois'],
|
||||
'nbPieces' => $tabPai['nbPieces'],
|
||||
'nbJourRetard' => $tabPai['nbJourRetard'],
|
||||
'nbJourPaiement' => $tabPai['nbJourPaiement'],
|
||||
'nbJourMoyen' => $nbJoursMoyen,
|
||||
'nbJourMoyen2' => $tabPai['nbJourMoyens'],
|
||||
'tranchePaiement' => $tranche,
|
||||
'tranchePaie90' => $tabPai['nbJours'],
|
||||
'mtPieces' => $tabPai['mtPieces'],
|
||||
'mtPaiements' => $tabPai['mtPaiements'],
|
||||
'mtLitiges' => $tabPai['mtLitiges'],
|
||||
'devise' => $tabPai['CODDEV'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $tabRet;
|
||||
@ -250,128 +273,132 @@ class Metier_Partenaires_MFacto
|
||||
|
||||
public function getProfilPayeur($siren)
|
||||
{
|
||||
if ($siren<1000) {
|
||||
if ($siren < 1000) {
|
||||
return '';
|
||||
}
|
||||
$libProfil='';
|
||||
$libProfil = '';
|
||||
/*if ($this->siren==$siren)
|
||||
$tabPaie=$this->tabPaiements;
|
||||
else*/
|
||||
$tabPaie=$this->getPaiements($siren);
|
||||
if (count($tabPaie)>=3) {
|
||||
$tabProfil=array();
|
||||
$paie_min=180;
|
||||
$paie_max=$totFactures=$totPaiements=$totLitiges=0;
|
||||
foreach ($tabPaie as $i=>$tabPai) {
|
||||
if ($i==0) {
|
||||
$this->risqueImpayeMois=$tabPai['mois'];
|
||||
// Dernier délai de paiement en jour
|
||||
$this->DELAIPAY=$tabPai['tranchePaiement'];
|
||||
} elseif ($this->DELAIPAYp=='' && $tabPai['tranchePaiement']<>$this->DELAIPAY) {
|
||||
$this->DELAIPAYp=$tabPai['tranchePaiement'];
|
||||
$this->DELAIPAY_MMAA=$tabPai['mois'];
|
||||
$tabPaie = $this->getPaiements($siren);
|
||||
if (count($tabPaie) >= 3) {
|
||||
$tabProfil = array();
|
||||
$paie_min = 180;
|
||||
$paie_max = $totFactures = $totPaiements = $totLitiges = 0;
|
||||
foreach ($tabPaie as $i => $tabPai) {
|
||||
if ($i == 0) {
|
||||
$this->risqueImpayeMois = $tabPai['mois'];
|
||||
// Dernier délai de paiement en jour
|
||||
$this->DELAIPAY = $tabPai['tranchePaiement'];
|
||||
} elseif ($this->DELAIPAYp == '' && $tabPai['tranchePaiement'] != $this->DELAIPAY) {
|
||||
$this->DELAIPAYp = $tabPai['tranchePaiement'];
|
||||
$this->DELAIPAY_MMAA = $tabPai['mois'];
|
||||
}
|
||||
$tabProfil[$i]=$tabPai['tranchePaiement'];
|
||||
$totFactures+=$tabPai['mtPieces'];
|
||||
$totPaiements+=$tabPai['mtPaiements'];
|
||||
$totLitiges+=$tabPai['mtLitiges'];
|
||||
if ($tabPai['tranchePaiement']<$paie_min) {
|
||||
$paie_min=$tabPai['tranchePaiement'];
|
||||
$tabProfil[$i] = $tabPai['tranchePaiement'];
|
||||
$totFactures+= $tabPai['mtPieces'];
|
||||
$totPaiements+= $tabPai['mtPaiements'];
|
||||
$totLitiges+= $tabPai['mtLitiges'];
|
||||
if ($tabPai['tranchePaiement'] < $paie_min) {
|
||||
$paie_min = $tabPai['tranchePaiement'];
|
||||
}
|
||||
if ($tabPai['tranchePaiement']>$paie_max) {
|
||||
$paie_max=$tabPai['tranchePaiement'];
|
||||
if ($tabPai['tranchePaiement'] > $paie_max) {
|
||||
$paie_max = $tabPai['tranchePaiement'];
|
||||
}
|
||||
}
|
||||
$tauxLitige=$totLitiges/$totFactures;
|
||||
$tauxLitige = $totLitiges / $totFactures;
|
||||
|
||||
if ($tauxLitige>=0.5) {
|
||||
$libProfil.='Litiges très importants. ';
|
||||
} elseif ($tauxLitige>0.25) {
|
||||
$libProfil.='Litiges importants. ';
|
||||
} elseif ($tauxLitige>0.05) {
|
||||
$libProfil.='Présence de litiges. ';
|
||||
if ($tauxLitige >= 0.5) {
|
||||
$libProfil.= 'Litiges très importants. ';
|
||||
} elseif ($tauxLitige > 0.25) {
|
||||
$libProfil.= 'Litiges importants. ';
|
||||
} elseif ($tauxLitige > 0.05) {
|
||||
$libProfil.= 'Présence de litiges. ';
|
||||
}
|
||||
|
||||
if ($tabProfil[0]==$tabProfil[1] && $tabProfil[1]==$tabProfil[2]) {
|
||||
if ($tranche=0) {
|
||||
$libProfil.='Paiements à échéance';
|
||||
$this->profilPayeur=1;
|
||||
} elseif ($tranche<=30) {
|
||||
$libProfil.='Paiements à 30 jours maximum';
|
||||
$this->profilPayeur=2;
|
||||
} elseif ($tranche<=60) {
|
||||
$libProfil.='Paiements à 60 jours maximum';
|
||||
$this->profilPayeur=3;
|
||||
} elseif ($tranche<=90) {
|
||||
$libProfil.='Paiements à 90 jours maximum';
|
||||
$this->profilPayeur=4;
|
||||
$this->risqueImpaye=true;
|
||||
if ($tabProfil[0] == $tabProfil[1] && $tabProfil[1] == $tabProfil[2]) {
|
||||
if ($tranche = 0) {
|
||||
$libProfil.= 'Paiements à échéance';
|
||||
$this->profilPayeur = 1;
|
||||
} elseif ($tranche <= 30) {
|
||||
$libProfil.= 'Paiements à 30 jours maximum';
|
||||
$this->profilPayeur = 2;
|
||||
} elseif ($tranche <= 60) {
|
||||
$libProfil.= 'Paiements à 60 jours maximum';
|
||||
$this->profilPayeur = 3;
|
||||
} elseif ($tranche <= 90) {
|
||||
$libProfil.= 'Paiements à 90 jours maximum';
|
||||
$this->profilPayeur = 4;
|
||||
$this->risqueImpaye = true;
|
||||
} else {
|
||||
$libProfil.='Paiements à plus de 90 jours';
|
||||
$this->profilPayeur=4;
|
||||
$this->risqueImpaye=true;
|
||||
$libProfil.= 'Paiements à plus de 90 jours';
|
||||
$this->profilPayeur = 4;
|
||||
$this->risqueImpaye = true;
|
||||
}
|
||||
} elseif (($tabProfil[0]<>$tabProfil[1] && $tabProfil[1]==$tabProfil[2]) ||
|
||||
($tabProfil[0]==$tabProfil[1] && $tabProfil[1]<>$tabProfil[2])) {
|
||||
} elseif (($tabProfil[0] != $tabProfil[1] && $tabProfil[1] == $tabProfil[2])
|
||||
|| ($tabProfil[0] == $tabProfil[1] && $tabProfil[1] != $tabProfil[2])) {
|
||||
// Récent changement de profil payeur
|
||||
$tranche=$tabProfil[0];
|
||||
$tr_prec=$tabProfil[1];
|
||||
$tr_prec2=$tabProfil[2];
|
||||
if ($tranche<$tr_prec) {
|
||||
$libProfil.='Amélioration des délais. ';
|
||||
} elseif ($tranche==$tr_prec && $tr_prec<$tr_prec2) {
|
||||
$libProfil.='Amélioration des délais. ';
|
||||
$tranche = $tabProfil[0];
|
||||
$tr_prec = $tabProfil[1];
|
||||
$tr_prec2 = $tabProfil[2];
|
||||
if ($tranche < $tr_prec) {
|
||||
$libProfil.= 'Amélioration des délais. ';
|
||||
} elseif ($tranche == $tr_prec && $tr_prec < $tr_prec2) {
|
||||
$libProfil.= 'Amélioration des délais. ';
|
||||
} else {
|
||||
$this->risqueImpaye=true;
|
||||
$libProfil.='Allongement des délais. ';
|
||||
$this->risqueImpaye = true;
|
||||
$libProfil.= 'Allongement des délais. ';
|
||||
}
|
||||
|
||||
if ($tranche=0) {
|
||||
$libProfil.='Paiements à échéance';
|
||||
$this->profilPayeur=1;
|
||||
} elseif ($tranche<=30) {
|
||||
$libProfil.='Paiements à 30 jours maximum';
|
||||
$this->profilPayeur=2;
|
||||
if ($tranche = 0) {
|
||||
$libProfil.= 'Paiements à échéance';
|
||||
$this->profilPayeur = 1;
|
||||
} elseif ($tranche <= 30) {
|
||||
$libProfil.= 'Paiements à 30 jours maximum';
|
||||
$this->profilPayeur = 2;
|
||||
} elseif ($tranche<=60) {
|
||||
$libProfil.='Paiements à 60 jours maximum';
|
||||
$this->profilPayeur=3;
|
||||
} elseif ($tranche<=90) {
|
||||
$libProfil.='Paiements à 90 jours maximum';
|
||||
$this->profilPayeur=4;
|
||||
$this->risqueImpaye=true;
|
||||
$libProfil.= 'Paiements à 60 jours maximum';
|
||||
$this->profilPayeur = 3;
|
||||
} elseif ($tranche <= 90) {
|
||||
$libProfil.= 'Paiements à 90 jours maximum';
|
||||
$this->profilPayeur = 4;
|
||||
$this->risqueImpaye = true;
|
||||
} else {
|
||||
$libProfil.='Paiements à plus de 90 jours';
|
||||
$this->profilPayeur=4;
|
||||
$this->risqueImpaye=true;
|
||||
$libProfil.= 'Paiements à plus de 90 jours';
|
||||
$this->profilPayeur = 4;
|
||||
$this->risqueImpaye = true;
|
||||
}
|
||||
} else {
|
||||
if ($paie_max<=30) {
|
||||
$this->profilPayeur=1;
|
||||
} elseif ($paie_max<=60) {
|
||||
$this->profilPayeur=2;
|
||||
} elseif ($paie_max<=90) {
|
||||
$this->profilPayeur=3;
|
||||
} elseif ($paie_max>90) {
|
||||
$this->profilPayeur=4;
|
||||
if ($paie_max <= 30) {
|
||||
$this->profilPayeur = 1;
|
||||
} elseif ($paie_max <= 60) {
|
||||
$this->profilPayeur = 2;
|
||||
} elseif ($paie_max <= 90) {
|
||||
$this->profilPayeur = 3;
|
||||
} elseif ($paie_max > 90) {
|
||||
$this->profilPayeur = 4;
|
||||
}
|
||||
$libProfil.="Paiements entre $paie_min et $paie_max jour(s)";
|
||||
$libProfil.= "Paiements entre $paie_min et $paie_max jour(s)";
|
||||
}
|
||||
}
|
||||
|
||||
if (trim($libProfil)=='' && $siren<>552100554 && $siren<>552144503 && $siren<>479974115
|
||||
&& $siren<>0 && $siren<>494967938) {
|
||||
$ret=$this->iDb->select('jo.surveillances_listes',
|
||||
'ref, dateAjout, dateConf, dateSuppr, dateDerEnvoi',
|
||||
"idClient='SURBODPRDFTSRECOCASH' AND siren=$siren AND dateSuppr=0
|
||||
AND ABS(DATEDIFF(dateAjout, NOW()))<365
|
||||
ORDER BY dateConf DESC, dateAjout DESC", false, MYSQL_ASSOC);
|
||||
foreach ($ret as $i=>$tabCS) {
|
||||
$dateMAJ = Metier_Util_Date::dateT('Y-m-d', 'M Y', $tabCS['dateAjout']);
|
||||
$libProfil="En date du $dateMAJ : Contentieux importants.";
|
||||
$this->risqueImpaye=true;
|
||||
$this->risqueImpayeMois=Metier_Util_Date::dateT('Y-m', 'Ym', $tabCS['dateAjout']);
|
||||
$this->profilPayeur=4;
|
||||
break;
|
||||
if (trim($libProfil) == '' && !in_array($siren, array(0, 552144503, 552100554, 479974115, 494967938))) {
|
||||
$sql = "SELECT ref, dateAjout, dateConf, dateSuppr, dateDerEnvoi
|
||||
FROM jo.surveillances_listes
|
||||
WHERE idClient='SURBODPRDFTSRECOCASH' AND siren=:siren AND dateSuppr=0
|
||||
AND ABS(DATEDIFF(dateAjout, NOW()))<365
|
||||
ORDER BY dateConf DESC, dateAjout DESC";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('siren', $siren);
|
||||
$stmt->execute();
|
||||
if ($stmt->rowCount() > 0) {
|
||||
while ($tabCS = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$dateMAJ = Metier_Util_Date::dateT('Y-m-d', 'M Y', $tabCS['dateAjout']);
|
||||
$libProfil = "En date du $dateMAJ : Contentieux importants.";
|
||||
$this->risqueImpaye = true;
|
||||
$this->risqueImpayeMois = Metier_Util_Date::dateT('Y-m', 'Ym', $tabCS['dateAjout']);
|
||||
$this->profilPayeur = 4;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -380,41 +407,41 @@ class Metier_Partenaires_MFacto
|
||||
|
||||
public function getTabPaiements($siren)
|
||||
{
|
||||
if ($siren<1000) {
|
||||
if ($siren < 1000) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$tabNbr=array(); // Tableau de travail du nombre de factures par trimestre et par tranches de délais de paiements
|
||||
$tabMtAn=array(); // Tableau de travail du nombre de factures par montant et par tranches de délais de paiements
|
||||
$tabNbr = array(); // Tableau de travail du nombre de factures par trimestre et par tranches de délais de paiements
|
||||
$tabMtAn = array(); // Tableau de travail du nombre de factures par montant et par tranches de délais de paiements
|
||||
|
||||
$tabNbr2=array(); // Tableau retour du nombre de factures par trimestre et par tranches de délais de paiements
|
||||
$tabMtAn2=array(); // Tableau retour du nombre de factures par montant et par tranches de délais de paiements
|
||||
$tabNbr2 = array(); // Tableau retour du nombre de factures par trimestre et par tranches de délais de paiements
|
||||
$tabMtAn2 = array(); // Tableau retour du nombre de factures par montant et par tranches de délais de paiements
|
||||
|
||||
$tabPaie=$this->getPaiements($siren, 'jour');
|
||||
foreach ($tabPaie as $i=>$tabPai) {
|
||||
@$tabNbr[$tabPai['trimestre']]['d='.$tabPai['tranchePaiement']]+=$tabPai['nbPieces'];
|
||||
$tabPaie = $this->getPaiements($siren, 'jour');
|
||||
foreach ($tabPaie as $i => $tabPai) {
|
||||
@$tabNbr[$tabPai['trimestre']]['d='.$tabPai['tranchePaiement']]+= $tabPai['nbPieces'];
|
||||
@$tabNbr[$tabPai['trimestre']]['all']+=$tabPai['nbPieces'];
|
||||
$mt=$tabPai['mtPieces']/$tabPai['nbPieces'];
|
||||
$mt = $tabPai['mtPieces']/$tabPai['nbPieces'];
|
||||
//echo "$i\t".$tabPai['trimestre']." (".$tabPai['tranchePaiement']." j)\t$mt=".$tabPai['mtPieces'].'/'.$tabPai['nbPieces'].PHP_EOL;
|
||||
if ($mt<500) {
|
||||
if ($mt < 500) {
|
||||
@$tabMtAn[1]['d='.$tabPai['tranchePaiement']]++;
|
||||
@$tabMtAn[1]['all']++;
|
||||
} elseif ($mt<2000) {
|
||||
} elseif ($mt < 2000) {
|
||||
@$tabMtAn[2]['d='.$tabPai['tranchePaiement']]++;
|
||||
@$tabMtAn[2]['all']++;
|
||||
} elseif ($mt<10000) {
|
||||
} elseif ($mt < 10000) {
|
||||
@$tabMtAn[10]['d='.$tabPai['tranchePaiement']]++;
|
||||
@$tabMtAn[10]['all']++;
|
||||
} elseif ($mt<20000) {
|
||||
} elseif ($mt < 20000) {
|
||||
@$tabMtAn[20]['d='.$tabPai['tranchePaiement']]++;
|
||||
@$tabMtAn[20]['all']++;
|
||||
} elseif ($mt<50000) {
|
||||
} elseif ($mt < 50000) {
|
||||
@$tabMtAn[50]['d='.$tabPai['tranchePaiement']]++;
|
||||
@$tabMtAn[50]['all']++;
|
||||
} elseif ($mt<100000) {
|
||||
} elseif ($mt < 100000) {
|
||||
@$tabMtAn[100]['d='.$tabPai['tranchePaiement']]++;
|
||||
@$tabMtAn[100]['all']++;
|
||||
} elseif ($mt<200000) {
|
||||
} elseif ($mt < 200000) {
|
||||
@$tabMtAn[200]['d='.$tabPai['tranchePaiement']]++;
|
||||
@$tabMtAn[200]['all']++;
|
||||
} else {
|
||||
@ -463,8 +490,8 @@ class Metier_Partenaires_MFacto
|
||||
}
|
||||
|
||||
return array(
|
||||
'parMont'=>$tabMtAn2,
|
||||
'parTrim'=>$tabNbr2
|
||||
'parMont' => $tabMtAn2,
|
||||
'parTrim' => $tabNbr2
|
||||
);
|
||||
}
|
||||
|
||||
@ -472,8 +499,8 @@ class Metier_Partenaires_MFacto
|
||||
{
|
||||
return array(
|
||||
'CoteCS' => $cs,
|
||||
'LibCS' => $this->tabInfoCS["_$cs"]['libExt'],
|
||||
'NivRisque' => $this->tabInfoCS["_$cs"]['risque'],
|
||||
'LibCS' => $this->tabInfoCS["_$cs"]['libExt'],
|
||||
'NivRisque' => $this->tabInfoCS["_$cs"]['risque'],
|
||||
'CodeRisque' => $this->tabInfoCS["_$cs"]['type'],
|
||||
);
|
||||
}
|
||||
|
@ -2740,7 +2740,7 @@ function calculIndiScore($siren, $nic=0, $accesDist=false, $cycleClient=2, $mail
|
||||
$DEFAUT_MMAA=$LCASSUR_MMAA=$RISQUEIMPAYE_MMAA=$CSFACTO_MMAA='';
|
||||
$COTEOK=$IMPAYE=$PRIVILEGES=$RISQUEGROUPE=$DEFAUT=$LCASSUR=$RISQUEIMPAYE=$CSFACTO=false;
|
||||
$MODIFPAIDATE=0;
|
||||
$iFacto = new Metier_Partenaires_MFacto($iDb);
|
||||
$iFacto = new Metier_Partenaires_MFacto();
|
||||
$infoFacto = $iFacto->getCoteSpeciale($siren);
|
||||
$timer['factoCS']=microtime(true);
|
||||
|
||||
|
@ -2683,7 +2683,7 @@ class Metier_Scoring_Base extends Metier_Scoring_Vars
|
||||
$this->COTEOK=$this->IMPAYE=$this->PRIVILEGES=$this->RISQUEGROUPE=$this->DEFAUT=$this->LCASSUR=$this->RISQUEIMPAYE=$this->CSFACTO=false;
|
||||
$this->MODIFPAIDATE=0;
|
||||
|
||||
$iFacto = new Metier_Partenaires_MFacto($this->db);
|
||||
$iFacto = new Metier_Partenaires_MFacto();
|
||||
$infoFacto = $iFacto->getCoteSpeciale($siren);
|
||||
$timer['factoCS']=microtime(true);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user