220 lines
4.6 KiB
PHP
220 lines
4.6 KiB
PHP
|
<?php
|
||
|
require_once 'dbbootstrap.php';
|
||
|
require_once 'infogreffe/constantes.php';
|
||
|
|
||
|
/**
|
||
|
* Recherche les commandes suivant le numéro de commande et/ou le siren
|
||
|
* @param unknown_type $type
|
||
|
* @param $siren
|
||
|
* @param $num
|
||
|
*/
|
||
|
function commandesRecherche($num, $siren, $type = '-'){
|
||
|
setDbConn('sdv1');
|
||
|
$q = Doctrine_Query::create();
|
||
|
|
||
|
//Recherche par numéro de commande
|
||
|
if (!empty($num)){
|
||
|
$table = tableNumCommande($num);
|
||
|
$identifiant = identifiantTable($table);
|
||
|
//@todo : gérer les cas G ou vide et C
|
||
|
$q->from($table)->where($identifiant.' = ?', substr($num,1));
|
||
|
|
||
|
//Recherche par numéro siren et type de commande
|
||
|
} elseif (!empty($siren)) {
|
||
|
$table = tableTypeCommande($type);
|
||
|
$q->from($table)->where('siren = ?', $siren);
|
||
|
}
|
||
|
|
||
|
//Résultat
|
||
|
$commandes = $q->execute();
|
||
|
FB::log($commandes->toArray(), 'commandes');
|
||
|
|
||
|
//Filtrage
|
||
|
if($type!='-' && count($commandes)>0){
|
||
|
$outputCommandes = array();
|
||
|
foreach ($commandes as $commande){
|
||
|
FB::log($commande->refDocument, 'ref');
|
||
|
if (filtreTypeCommande($type, $commande->refDocument)){
|
||
|
$outputCommandes[] = $commande;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return $outputCommandes;
|
||
|
}
|
||
|
|
||
|
function filtreTypeCommande($type, $ref){
|
||
|
$return = false;
|
||
|
switch($type){
|
||
|
case 'greffe-actes':
|
||
|
if (preg_match('/^([0-9a-zA-Z]{2}-).*?$/', $ref, $matches)){
|
||
|
$return = true;
|
||
|
}
|
||
|
break;
|
||
|
case 'greffe-bilans':
|
||
|
if (preg_match('/^([0-9]{4}_).*?$/', $ref, $matches)){
|
||
|
$return = true;
|
||
|
}
|
||
|
break;
|
||
|
case 'greffe-kbis':
|
||
|
|
||
|
break;
|
||
|
case 'greffe-priv':
|
||
|
|
||
|
break;
|
||
|
}
|
||
|
return $return;
|
||
|
}
|
||
|
|
||
|
function tableNumCommande($num){
|
||
|
switch(substr($num,0,1)){
|
||
|
case 'G':
|
||
|
case 'C':
|
||
|
$table = 'Commandes';
|
||
|
break;
|
||
|
}
|
||
|
return $table;
|
||
|
}
|
||
|
|
||
|
function identifiantTable($nomTable){
|
||
|
switch($nomTable){
|
||
|
case 'Commandes':
|
||
|
$identifiant = 'idCommande';
|
||
|
break;
|
||
|
case 'CommandesPieces':
|
||
|
$identifiant = 'id';
|
||
|
break;
|
||
|
}
|
||
|
return $identifiant;
|
||
|
}
|
||
|
|
||
|
function tableTypeCommande($type){
|
||
|
switch($type){
|
||
|
case 'greffe-actes':
|
||
|
case 'greffe-bilans':
|
||
|
$table = 'Commandes';
|
||
|
break;
|
||
|
case 'greffe-kbis':
|
||
|
case 'greffe-priv':
|
||
|
$table = 'CommandesPieces';
|
||
|
break;
|
||
|
}
|
||
|
return $table;
|
||
|
}
|
||
|
|
||
|
function documentLib($ref, $info, $type){
|
||
|
switch($type){
|
||
|
case 'greffe-actes':
|
||
|
//preg_match('/^([0-9a-zA-Z]{2}-).*?$/', $ref, $matches)
|
||
|
break;
|
||
|
case 'greffe-bilans':
|
||
|
preg_match('/^([0-9]{4}).*?$/', $ref, $matches);
|
||
|
$lib = 'Bilans de '.$matches[1];
|
||
|
break;
|
||
|
case 'greffe-kbis':
|
||
|
|
||
|
break;
|
||
|
case 'greffe-priv':
|
||
|
|
||
|
break;
|
||
|
}
|
||
|
return $lib;
|
||
|
}
|
||
|
|
||
|
function documentInfo($ref, $info, $type){}
|
||
|
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
* @param unknown_type $type
|
||
|
* @param unknown_type $etat
|
||
|
* @param unknown_type $date
|
||
|
*/
|
||
|
function commandesListe($type, $etat, $date){
|
||
|
setDbConn('sdv1');
|
||
|
$table = tableTypeCommande($type);
|
||
|
|
||
|
$dateTDebut = mktime(0, 0, 0, date('m', $date), 0, date('Y', $date));
|
||
|
$dateTFin = mktime(0, 0, 0, date('m', $date)+1, 0, date('Y', $date));
|
||
|
|
||
|
$dateDebut = date('Y-m-d H:i:s',$dateTDebut);
|
||
|
$dateFin = date('Y-m-d H:i:s',$dateTFin);
|
||
|
|
||
|
$q = Doctrine_Query::create()
|
||
|
->from($table)
|
||
|
->where('statutCommande = ?', 0)
|
||
|
->andWhere('dateCommande > ? ', $dateDebut)
|
||
|
->andWhere('dateCommande < ? ', $dateFin);
|
||
|
|
||
|
FB::log($q->getSql(), 'sql');
|
||
|
FB::log($q->getFlattenedParams(), 'Params');
|
||
|
//Résultat
|
||
|
$commandes = $q->execute();
|
||
|
FB::log($commandes->toArray(), 'commandes');
|
||
|
|
||
|
//Filtrage
|
||
|
if($type!='-' && count($commandes)>0){
|
||
|
$outputCommandes = array();
|
||
|
foreach ($commandes as $commande){
|
||
|
FB::log($commande->refDocument, 'ref');
|
||
|
if (filtreTypeCommande($type, $commande->refDocument)){
|
||
|
$outputCommandes[] = $commande;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return $outputCommandes;
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
return $commandes;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Retourne la raison sociale à partir du siren
|
||
|
* @param unknown_type $siren
|
||
|
*/
|
||
|
function raisonSociale($siren){
|
||
|
|
||
|
|
||
|
|
||
|
return $rs;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Retourne le contenu HTML pour l'affichage de la commande
|
||
|
* @param unknown_type $commande
|
||
|
*/
|
||
|
function afficheCommande($commande, $type){
|
||
|
|
||
|
if ($commande->typeCommande=='' || $commande->typeCommande=='G'){
|
||
|
$typeCommande = 'G';
|
||
|
} elseif ($commande->typeCommande=='C'){
|
||
|
$typeCommande = 'C';
|
||
|
}
|
||
|
|
||
|
$documentLib = documentLib(
|
||
|
$commande->refDocument,
|
||
|
$commande->libDocument,
|
||
|
$type);
|
||
|
|
||
|
|
||
|
$output =
|
||
|
'<tr><td colspan="3">'.$typeCommande.$commande->idCommande.'</td></tr>'.
|
||
|
'<tr>'.
|
||
|
' <td>'.
|
||
|
' <div>'.$commande->siren.'</div>'.
|
||
|
' <div>(RS)</div>'.
|
||
|
' </td>'.
|
||
|
' <td>'.
|
||
|
' <div><u>Document : </u>'.$documentLib.'</div>'.
|
||
|
' <div>Informations : '.$commande->libDocument.'</div>'.
|
||
|
' </td>'.
|
||
|
' <td>'.
|
||
|
' <div>Email : '.$commande->emailCommande.'</div>'.
|
||
|
' <div>Etat : En cours...</div>'.
|
||
|
' <div>Date de commande : '.$commande->dateCommande.'</div>'.
|
||
|
' <div>Date de reception : '.$commande->dateReception.'</div>'.
|
||
|
' </td>'.
|
||
|
'</tr>';
|
||
|
return $output;
|
||
|
}
|