429 lines
23 KiB
PHP
429 lines
23 KiB
PHP
<?php
|
|
require_once(dirname(dirname(__FILE__)).'/config/config.inc.php');
|
|
|
|
if (isset($_GET['secure_key']))
|
|
{
|
|
$secureKey = md5(_COOKIE_KEY_.Configuration::get('PS_SHOP_NAME'));
|
|
if (!empty($secureKey) AND $secureKey === $_GET['secure_key'])
|
|
{
|
|
|
|
$log = "-- START --------------------------------------\n".date('Y-m-d-H:i:s')." - retour_commandes.php\n";
|
|
$dateAnnneMois = date('Ym');
|
|
$nom_fichier = "";
|
|
$serveur_ftp = "ftp.l4-logistics.fr";
|
|
$id_con = ftp_connect($serveur_ftp);
|
|
$ftp_user = "Gar_log";
|
|
$ftp_pw = "ZAnP49*!";
|
|
$result_login = ftp_login($id_con, $ftp_user, $ftp_pw);
|
|
$tableau = ftp_nlist($id_con,'OUT');
|
|
$tableau2 = ftp_nlist($id_con,'OUT/Archives');
|
|
$nombre = count($tableau);
|
|
$i = 0;
|
|
|
|
while ($i<count($tableau))
|
|
{
|
|
$item = $tableau[$i];
|
|
$explod = explode('.',$item);
|
|
if ($explod[1] == "xml")
|
|
{
|
|
if(ftp_get($id_con, "OUT/".$tableau[$i], "OUT/".$tableau[$i], FTP_BINARY))
|
|
{
|
|
echo "OK<br/>";
|
|
ftp_rename($id_con, "OUT/".$tableau[$i], "OUT/Archives/".$tableau[$i]);
|
|
}
|
|
else
|
|
{
|
|
echo "NOK<br/>";
|
|
}
|
|
}
|
|
$i++;
|
|
}
|
|
ftp_close($id_con);
|
|
|
|
//Données de connection garanciax
|
|
$conn = mysql_connect('localhost', 'garanciab_prod', 'yoeLB4Znn1E1');
|
|
mysql_select_db('garanciab_prod');
|
|
|
|
if (!$dossier = opendir("OUT"))
|
|
{
|
|
$log.="ERR - Ouverture Dossier OUT impossible\n";
|
|
exit;
|
|
}
|
|
|
|
$nbItems=0;
|
|
$nbItemsTRACOL=0;
|
|
$nb_treated=0;
|
|
while ( $fichier = readdir($dossier))
|
|
{
|
|
if ($fichier!='Archives' && $fichier!='..' && $fichier!='.')
|
|
{
|
|
|
|
|
|
//if($nb_treated < 3)
|
|
//{
|
|
//
|
|
|
|
$items=explode('CRPCMD',$fichier);
|
|
|
|
if (count($items)==2)
|
|
{
|
|
$nbItems++;
|
|
$document_xml = new DomDocument();
|
|
$resultat_html = '';
|
|
$document_xml->load('OUT/'.$fichier);
|
|
|
|
$elements = $document_xml->getElementsByTagName('CRORDERS');
|
|
$element = $elements->item(0);
|
|
$crorders = $element->childNodes;
|
|
|
|
foreach ($crorders as $crorder) {
|
|
if ($crorder->hasChildNodes() == true) {
|
|
$rows = $crorder->childNodes;
|
|
$tab_order = array();
|
|
$key_colis = 0;
|
|
|
|
foreach($rows as $row) {
|
|
$name_row = $row->nodeName;
|
|
|
|
if ($name_row == 'CODACTI') {
|
|
$tab_order['CODACTI'] = $row->nodeValue;
|
|
}
|
|
|
|
if ($name_row == 'IDORDER') {
|
|
$IDORDER = $row->nodeValue;
|
|
$id = explode(date('Y'),$IDORDER);
|
|
|
|
if (count($id) == 1) {
|
|
$id = explode(date('Y', strtotime('-1 year') ),$IDORDER);
|
|
}
|
|
$tab_order['IDORDER'] = $id[0];
|
|
}
|
|
|
|
if ($name_row == 'DATETRT') {
|
|
$tab_order['DATETRT'] = $row->nodeValue;
|
|
}
|
|
|
|
if ($name_row == 'ETAPREP') {
|
|
$tab_order['ETAPREP'] = $row->nodeValue;
|
|
}
|
|
|
|
if ($name_row == 'COLIS') {
|
|
if ($row->hasChildNodes() == true) {
|
|
$colis = $row->childNodes;
|
|
|
|
foreach($colis as $row_colis) {
|
|
$name_row_colis = $row_colis->nodeName;
|
|
|
|
if ($name_row_colis == 'IDCOLIS') {
|
|
$tab_order['IDCOLIS'][$key_colis] = $row_colis->nodeValue;
|
|
}
|
|
}
|
|
}
|
|
$key_colis++;
|
|
}
|
|
}
|
|
|
|
if( strlen($tab_order['IDORDER']) > 5) {
|
|
continue;
|
|
}
|
|
|
|
if ($tab_order['ETAPREP'] == "10") {
|
|
|
|
foreach ($tab_order['IDCOLIS'] as $shipping_number) {
|
|
$sql = "update ps_orders set shipping_number = '".$shipping_number."' where id_order = ".(int)$tab_order['IDORDER'];
|
|
if ($result = mysql_query($sql, $conn)) {
|
|
echo "<br/>Mise a jour effectuee pour la commande tracking #".$tab_order['IDORDER']." : ID COLIS = ".$shipping_number." ( ".$sql.")";
|
|
}
|
|
|
|
$sql = "update ps_order_carrier set tracking_number = '".$shipping_number."' where id_order = ".(int)$tab_order['IDORDER'];
|
|
if ($result = mysql_query($sql, $conn)) {
|
|
echo "<br/>Mise a jour effectuee pour la commande livraison #".$tab_order['IDORDER']." : ID COLIS = ".$shipping_number." ( ".$sql.")<br/><br/>";
|
|
}
|
|
}
|
|
|
|
|
|
include_once(dirname(__FILE__) .'/../config/config.inc.php');
|
|
$history = new OrderHistory();
|
|
$history->id_order = $tab_order['IDORDER'];
|
|
$history->id_employee = 7;
|
|
$use_existings_payment = false;
|
|
|
|
$e_order = new Order($tab_order['IDORDER']);
|
|
$e_current_order_state=$e_order->current_state;
|
|
|
|
// commande envoyée
|
|
if($e_current_order_state != 4
|
|
&& $e_current_order_state != 5
|
|
&& $e_current_order_state != 6
|
|
&& $e_current_order_state != 7
|
|
&& $e_current_order_state != 8)
|
|
{
|
|
$templateVars = array();
|
|
$history->changeIdOrderState2(4, $tab_order['IDORDER'], $use_existings_payment);
|
|
$history->addWithemail(true, $templateVars);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$items=explode('TRACOL',$fichier);
|
|
|
|
if(count($items)==2)
|
|
{
|
|
$nbItemsTRACOL++;
|
|
$document_xml = new DomDocument();
|
|
$resultat_html = '';
|
|
$document_xml->load('OUT/'.$fichier);
|
|
$elements = $document_xml->getElementsByTagName('COL');
|
|
$i=0;
|
|
foreach($elements as $row)
|
|
{
|
|
$element = $elements->item($i);
|
|
$i++;
|
|
$enfants = $element->childNodes;
|
|
|
|
$IDCOLIS="";
|
|
$DATEEVT="";
|
|
$CODEEVT="";
|
|
$CODETRP="";
|
|
$COMMTRP="";
|
|
|
|
foreach($enfants as $enfant2)
|
|
{
|
|
if($enfant2->hasChildNodes() == true)
|
|
{
|
|
$nom = $enfant2->nodeName;
|
|
|
|
if ($nom == 'CODACTI')
|
|
$CODACTI= $enfant2->nodeValue;
|
|
|
|
if ($nom == 'IDORDER')
|
|
{
|
|
$IDORDER= $enfant2->nodeValue;
|
|
|
|
$id=explode(date('Y'),$IDORDER);
|
|
if(count($id) == 1){
|
|
$id=explode(date('Y', strtotime('-1 year') ),$IDORDER);
|
|
}
|
|
$IDORDER=$id[0];
|
|
}
|
|
|
|
if ($nom == 'IDCOLIS'){
|
|
$IDCOLIS= $enfant2->nodeValue;
|
|
|
|
// $log.="CRPCMD traité pour la commande #".$IDORDER.", tracking_number = ".$IDCOLIS."\n";
|
|
}
|
|
|
|
if ($nom == 'DATEEVT')
|
|
$DATEEVT= $enfant2->nodeValue;
|
|
|
|
if ($nom == 'CODEEVT')
|
|
$CODEEVT= $enfant2->nodeValue;
|
|
|
|
if ($nom == 'CODETRP')
|
|
$CODETRP= $enfant2->nodeValue;
|
|
|
|
if ($nom == 'COMMTRP')
|
|
{
|
|
$COMMTRP= $enfant2->nodeValue;
|
|
if($CODEEVT=="OK-IN-TRANST"
|
|
|| $CODEEVT=="OK-DELIVERED"
|
|
|| $CODEEVT=="TDCSG-ABSENT"
|
|
|| $CODEEVT=="OK-WITHDRAWA"
|
|
|| $CODEEVT=="ADM")
|
|
{
|
|
include_once(dirname(__FILE__) .'/../config/config.inc.php');
|
|
|
|
$order = new Order($IDORDER);
|
|
|
|
// $sql="update ps_orders set shipping_number='".$IDCOLIS."' where id_order=".(int)$IDORDER;
|
|
// if($result = mysql_query($sql, $conn))
|
|
// echo "<br/>Mise a jour effectuee pour la commande tracking #".$IDORDER." : ID COLIS = ".$IDCOLIS." ( ".$sql.")";
|
|
|
|
// $sql="update ps_order_carrier set tracking_number='".$IDCOLIS."' where id_order=".(int)$IDORDER;
|
|
|
|
// if($result = mysql_query($sql, $conn))
|
|
// echo "<br/>Mise a jour effectuee pour la commande livraison #".$IDORDER." : ID COLIS = ".$IDCOLIS." ( ".$sql.")<br/><br/>";
|
|
|
|
$current_order_state=$order->current_state;
|
|
if($current_order_state!=5 && $current_order_state!=6 && $current_order_state!=7)
|
|
{
|
|
$history = new OrderHistory();
|
|
$history->id_order = $IDORDER;
|
|
$history->id_employee = 7; // Specific employe for L4 Logistics
|
|
$use_existings_payment = false;
|
|
|
|
$templateVars = array(
|
|
'{commentaire}' => $CODETRP."<br/>".$COMMTRP
|
|
);
|
|
|
|
if($CODEEVT=="OK-WITHDRAWA"
|
|
&& $current_order_state != 16
|
|
&& $current_order_state != 17)// commande envoyée
|
|
{
|
|
$sql="select * from ps_mr_selected where id_order=".(int)$IDORDER;
|
|
$nbCompteur=0;
|
|
if($results = mysql_query($sql, $conn))
|
|
{
|
|
while ($result = mysql_fetch_array($results))
|
|
{
|
|
$adresse_point_relais=$result['MR_Selected_LgAdr1'];
|
|
if ($result['MR_Selected_LgAdr2'] != "")
|
|
$adresse_point_relais .= "<br />".$result['MR_Selected_LgAdr2'];
|
|
|
|
if ($result['MR_Selected_LgAdr3'] != "")
|
|
$adresse_point_relais .= "<br />".$result['MR_Selected_LgAdr3'];
|
|
|
|
if ($result['MR_Selected_LgAdr3'] != "")
|
|
$adresse_point_relais .= "<br />".$result['MR_Selected_CP']." ".$result['MR_Selected_Ville'];
|
|
|
|
if ($result['MR_Selected_Pays'] != "FR")
|
|
$adresse_point_relais .= "<br />".$result['MR_Selected_Pays'];
|
|
|
|
$templateVars = array('{adresse_point_relais}' => $adresse_point_relais);
|
|
$nbCompteur++;
|
|
}
|
|
}
|
|
|
|
if($nbCompteur>0)
|
|
{
|
|
$history->changeIdOrderState2(16, $IDORDER, $use_existings_payment);
|
|
if ($history->addWithemail(true, $templateVars)){}
|
|
}
|
|
else
|
|
{
|
|
$history->changeIdOrderState2(17, $IDORDER, $use_existings_payment);
|
|
if ($history->addWithemail(true, $templateVars)){}
|
|
}
|
|
|
|
}
|
|
//AJOUT DES STATUS 16 ET 17 POUR PARLIER AU BUG D ENVOIE DE DOUBLE MAIL DE "COMMANDE ENVOYE"
|
|
//POSSIBLE BUG SI LES COMMANDES PEUVENT ETRE PARTIEMMENT ENVOYE (IL FAUT AUTORISER A REVENIR A COMMANDE ENVOYEE)
|
|
elseif($CODEEVT=="OK-IN-TRANST"
|
|
&& $current_order_state != 16
|
|
&& $current_order_state != 17
|
|
&& $current_order_state != 4
|
|
&& $current_order_state != 5
|
|
&& $current_order_state != 6
|
|
&& $current_order_state != 7
|
|
&& $current_order_state != 8)
|
|
{
|
|
$history->changeIdOrderState2(4, $IDORDER, $use_existings_payment);
|
|
if ($history->addWithemail(true, $templateVars)){}
|
|
}
|
|
elseif($CODEEVT=="OK-DELIVERED"
|
|
&& $current_order_state != 5)
|
|
{
|
|
$history->changeIdOrderState2(5, $IDORDER, $use_existings_payment);
|
|
if ($history->addWithemail(true, $templateVars)){}
|
|
}
|
|
elseif($CODEEVT=="ADM"
|
|
&& $CODETRP=="COMCFM / Avis de transfert vers Coliposte recu du client"
|
|
&& $current_order_state != 4
|
|
&& $current_order_state != 5
|
|
&& $current_order_state != 6
|
|
&& $current_order_state != 7
|
|
&& $current_order_state != 8)
|
|
{
|
|
$history->changeIdOrderState2(4, $IDORDER, $use_existings_payment);
|
|
if ($history->addWithemail(true, $templateVars)){}
|
|
}
|
|
elseif($CODEEVT=="ADM"
|
|
&& $CODETRP=="SMSDIR / SMS / Disponible au relais"
|
|
&& $current_order_state != 16)
|
|
{
|
|
$sql="select * from ps_mr_selected where id_order=".(int)$IDORDER;
|
|
|
|
if($results = mysql_query($sql, $conn))
|
|
{
|
|
while ($result = mysql_fetch_array($results))
|
|
{
|
|
$adresse_point_relais=$result['MR_Selected_LgAdr1'];
|
|
|
|
if($result['MR_Selected_LgAdr2']!="")
|
|
$adresse_point_relais.="<br />".$result['MR_Selected_LgAdr2'];
|
|
|
|
if($result['MR_Selected_LgAdr3']!="")
|
|
$adresse_point_relais.="<br />".$result['MR_Selected_LgAdr3'];
|
|
|
|
if($result['MR_Selected_LgAdr3']!="")
|
|
$adresse_point_relais.="<br />".$result['MR_Selected_CP']." ".$result['MR_Selected_Ville'];
|
|
|
|
if($result['MR_Selected_Pays']!="FR")
|
|
$adresse_point_relais.="<br />".$result['MR_Selected_Pays'];
|
|
|
|
$templateVars = array(
|
|
'{adresse_point_relais}' => $adresse_point_relais
|
|
);
|
|
}
|
|
}
|
|
$history->changeIdOrderState2(16, $IDORDER, $use_existings_payment);
|
|
if ($history->addWithemail(true, $templateVars)){}
|
|
|
|
}
|
|
$log.="TRACOL traité pour la commande #".$IDORDER.", CODEEVT = ".$CODEEVT."\n";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$log.="Code CODEEVT non prévu : ".$CODEEVT." pour la commande #".$IDORDER."\n";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
rename(dirname(__FILE__).'/OUT/'.$fichier,dirname(__FILE__).'/OUT/Archives/'.$fichier);
|
|
$nom_fichier=$fichier;
|
|
$log.="Fichier renomme : ".$nom_fichier." et place dans /OUT/Archives/".$nom_fichier."\n";
|
|
//}
|
|
//else
|
|
//{
|
|
// echo 'On va pas traiter plus de fichier';
|
|
//}
|
|
//$nb_treated++;
|
|
}
|
|
}
|
|
|
|
if($nbItems==0 && $nbItemsTRACOL==0)
|
|
{
|
|
$log.="ERR - Fichier XML deja traite\n";
|
|
}
|
|
else
|
|
{
|
|
$nbItems++;
|
|
$log.="OK - ".$nbItems." commandes mises à jour avec succes\n";
|
|
|
|
$nbItemsTRACOL++;
|
|
|
|
if($nbItemsTRACOL>1)
|
|
$log.="OK - ".$nbItemsTRACOL." commandes mises à jour avec succes\n";
|
|
|
|
}
|
|
|
|
$log.="-- STOP --------------------------------------\n\n";
|
|
|
|
if($log!='')
|
|
{
|
|
$file3 = "LOG_RETOURCOMMANDE_".date('ymd').".txt";
|
|
$ar3=fopen(dirname(__FILE__).'/logs/'.$file3,'a+') or die("Probleme de création");
|
|
fputs($ar3,$log);
|
|
fclose($ar3);
|
|
}
|
|
|
|
|
|
function parsage($document)
|
|
{
|
|
$document_xml = new DomDocument;
|
|
$document_xml->load($document);
|
|
$elements = $document_xml->getElementsByTagName('zcode');
|
|
$resultat_html = '';
|
|
$arbre = $elements->item(0);
|
|
$resultat_html = parsage_enfant($arbre);
|
|
}
|
|
}
|
|
}
|
|
?>
|