333 lines
10 KiB
PHP
333 lines
10 KiB
PHP
<?php
|
|
$conn = mysql_connect('localhost', 'garancia_prod', 'yoeLB4Znn1E1');
|
|
mysql_select_db('garancia_prod');
|
|
$dateAnnneMois=date('Ymd');
|
|
$dayNOW=date('Y-m-d');
|
|
// $dayPRECEDENT=date('Y-m-d', strtotime("-1 day"));
|
|
|
|
$dayNOW_INF=date('Y-m-d')." 5:00:00";
|
|
$dayNOW_SUP=date('Y-m-d')." 12:00:00";
|
|
|
|
$sql = "SELECT o.*,c.name as carrier_name
|
|
from ps_orders o
|
|
left join ps_carrier c on (o.id_carrier=c.id_carrier)
|
|
where (o.id_order BETWEEN 2463 AND 2474) OR (o.id_order BETWEEN 2476 AND 2489)
|
|
and valid = 1 ";
|
|
|
|
//die($sql);
|
|
|
|
$res = mysql_query($sql, $conn);
|
|
$results=array();
|
|
$i=0;
|
|
while($row = mysql_fetch_array($res))
|
|
{
|
|
$sql='SELECT * from ps_order_history oh where id_order='.$row['id_order'].' order by id_order_history desc limit 0,1';
|
|
//die($sql);
|
|
$result = mysql_query($sql, $conn);
|
|
$id_order_state = mysql_fetch_array($result);
|
|
//var_dump($id_order_state['id_order_state']); exit;
|
|
if($id_order_state['id_order_state']==13 || $id_order_state['id_order_state']==12 || $id_order_state['id_order_state']==2 || $id_order_state['id_order_state']==3 )
|
|
{
|
|
$results[]=$row;
|
|
$i++;
|
|
}
|
|
}
|
|
//print_r($results); exit;
|
|
echo '
|
|
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />';
|
|
echo "<fieldset class='debug'>";
|
|
echo "SQL : ".$sql. "<br/>";
|
|
echo $i.' commandes trouvés pour la période : invoice_date >= "'.$dayNOW_INF.'" and invoice_date <= "'.$dayNOW_SUP.'"';
|
|
echo "</fieldset>";
|
|
$txt = '<?xml version="1.0" encoding="UTF-8"?>
|
|
<ORDERS>';
|
|
|
|
// die();
|
|
$i=0;
|
|
/*
|
|
Code possibles dans le champ TRPGEST suivant le mode de livraison :
|
|
-COLISSIMO EXPERT FR GAR
|
|
-UPS SAVER GAR
|
|
-MONDIAL RELAY 24R GAR
|
|
-IMX GAR
|
|
*/
|
|
foreach($results as $row)
|
|
{
|
|
$carrier_name=$row['carrier_name'];
|
|
$carrier_name=utf8_encode($carrier_name);
|
|
if($carrier_name=="Mondial Relay")
|
|
$carrier_name='MONDIAL RELAY 24R GAR';
|
|
elseif($carrier_name=="Livraison Colissimo")
|
|
$carrier_name='COLISSIMO EXPERT FR GAR';
|
|
elseif($carrier_name=="UPS")
|
|
$carrier_name='UPS SAVER GAR';
|
|
elseif($carrier_name=="IMX")
|
|
$carrier_name='IMX GAR';
|
|
else
|
|
$carrier_name='IMX GAR';
|
|
|
|
// COLISSIMO EXPERT FR GAR
|
|
// IMX GAR
|
|
// MONDIAL RELAY R24 GAR
|
|
// UPS SAVER GARCOLISSIMO EXPERT FR GAR
|
|
// IMX GAR
|
|
// MONDIAL RELAY R24 GAR
|
|
// UPS SAVER GAR
|
|
|
|
$sql = "SELECT * from ps_address where id_address = '".$row['id_address_delivery']."'";
|
|
|
|
$resultAdress = mysql_query($sql, $conn);
|
|
$rowAdress = mysql_fetch_array($resultAdress);
|
|
|
|
$sql = "SELECT * from ps_customer where id_customer = '".$row['id_customer']."'";
|
|
$resultClient = mysql_query($sql, $conn);
|
|
$rowClient = mysql_fetch_array($resultClient);
|
|
|
|
$MondialRelay="";
|
|
$sql = "SELECT MR_Selected_Pays,MR_Selected_Num FROM `ps_mr_selected` where id_order=".$row['id_order'];
|
|
$MR = mysql_query($sql, $conn);
|
|
if($MondialR = mysql_fetch_array($MR))
|
|
$MondialRelay=$MondialR['MR_Selected_Pays'].$MondialR['MR_Selected_Num'];
|
|
|
|
$sql = "SELECT * from ps_country where id_country = '".$rowAdress['id_country']."'";
|
|
$resultPays = mysql_query($sql, $conn);
|
|
$rowPays = mysql_fetch_array($resultPays);
|
|
|
|
$reference=strtoupper($row['id_order']);
|
|
$nom=strtoupper(utf8_encode(($rowAdress['firstname'])));
|
|
$prenom=strtoupper(utf8_encode(($rowAdress['lastname'])));
|
|
$company=strtoupper(utf8_encode(($rowAdress['company'])));
|
|
// $address1=$rowAdress['address1'];
|
|
// $address2=$rowAdress['address2'];
|
|
$address1=str_pad(utf8_encode($rowAdress['address1']), 35, " ", STR_PAD_RIGHT);
|
|
$address2=str_pad(utf8_encode($rowAdress['address2']), 35, " ", STR_PAD_RIGHT);
|
|
$codpost=strtoupper(utf8_encode($rowAdress['postcode']));
|
|
$ville=$rowAdress['city'];
|
|
$pays=strtoupper(utf8_encode($rowPays['country']));
|
|
$isoPays=strtoupper($rowPays['iso_code']);
|
|
$transporteur=strtoupper(" ");
|
|
$express=" ";
|
|
|
|
if($rowAdress['phone']!="")
|
|
$telephone=strtoupper($rowAdress['phone']);
|
|
else
|
|
$telephone=strtoupper(utf8_encode($rowAdress['phone_mobile']));
|
|
|
|
// $mail=strtoupper($rowAdress['phone']);
|
|
// if($telephone=='')
|
|
// $telephone=strtoupper($rowAdress['phone']);
|
|
// $phone=strtoupper($rowAdress['phone']);
|
|
// $mail=strtoupper($rowClient['email']);
|
|
// $instructions=$rowAdress['other'];
|
|
// $instructions=str_replace('\n',' ',$rowAdress['other']);
|
|
// $instructions=str_replace('\r',' ',$instructions);
|
|
|
|
$INSTPRP="";
|
|
$LIVCOMM="";
|
|
|
|
if($row['gift']==1)
|
|
{
|
|
$INSTPRP="CADEAU";
|
|
$LIVCOMM=str_pad(htmlspecialchars(utf8_encode($row['gift_message'])), 100, " ", STR_PAD_RIGHT);
|
|
$LIVCOMM=str_replace('<br/>','
',$LIVCOMM);
|
|
$LIVCOMM=str_replace('<br />','
',$LIVCOMM);
|
|
$LIVCOMM=str_replace('<br>','
',$LIVCOMM);
|
|
$LIVCOMM=str_replace('\n','
',$LIVCOMM);
|
|
$LIVCOMM=str_replace('
|
|
','
',$LIVCOMM);
|
|
$LIVCOMM=str_replace('\r','
',$LIVCOMM);
|
|
$LIVCOMM=str_replace("\'","'",$LIVCOMM);
|
|
$LIVCOMM=str_replace('
|
|
','
',$LIVCOMM);
|
|
}
|
|
|
|
// $LIVCOMM=stripslashes($LIVCOMM);
|
|
$invoice_date=str_replace(' ','T',$row['invoice_date']);
|
|
|
|
|
|
$txt.='
|
|
<ORDER>
|
|
<!-- Entête de commande -->
|
|
<CODACTI>GAR</CODACTI>
|
|
<LIBACTI>Garancia-GAR</LIBACTI>
|
|
<IDORDER>'.$row['id_order'].$dateAnnneMois.$lettre.'</IDORDER>
|
|
<DATECDE>'.$invoice_date.'</DATECDE>
|
|
<!-- Données de livraison -->
|
|
<LIVRNOM>'.str_replace('&','&',$nom).'</LIVRNOM>
|
|
<LIVPNOM>'.str_replace('&','&',$prenom).'</LIVPNOM>
|
|
<LIVSCTE>'.str_replace('&','&',$company).'</LIVSCTE>
|
|
<LIVADR1>'.str_replace('&','&',$address1).'</LIVADR1>
|
|
<LIVADR2>'.str_replace('&','&',$address2).'</LIVADR2>
|
|
<LIVADR3>'.str_replace('&','&',$instructions).'</LIVADR3>
|
|
<LIVCPOS>'.$codpost.'</LIVCPOS>
|
|
<LIVVILL>'.str_replace('&','&',utf8_encode($ville)).'</LIVVILL>
|
|
<LIVPAYS>'.$isoPays.'</LIVPAYS>
|
|
<LIVRTEL>'.$telephone.'</LIVRTEL>
|
|
<LIVMAIL></LIVMAIL>
|
|
<LIVCOMM>'.$LIVCOMM.'</LIVCOMM>
|
|
<!--Nom du transporteur-->
|
|
<TRPGEST>'.str_replace('&','&',$carrier_name).'</TRPGEST>
|
|
<!-- Point relais -->
|
|
<IDPOINT>'.$MondialRelay.'</IDPOINT>
|
|
<!-- cadeau -->
|
|
<INSTPRP>'.$INSTPRP.'</INSTPRP>
|
|
';
|
|
|
|
|
|
$sql = "SELECT product_reference, product_quantity, product_ean13,product_name from ps_order_detail where id_order = '".$row['id_order']."'";
|
|
$lettre="";
|
|
$i=0;
|
|
|
|
if($resultProd = mysql_query($sql, $conn))
|
|
{
|
|
// $txt.= "<!--\n nb:".count($resultProd)."-->\n";
|
|
// print_r($rowProd);
|
|
$ligne=0;
|
|
|
|
while($rowProd = mysql_fetch_array($resultProd))
|
|
{
|
|
$ligne++;
|
|
$product_reference=$rowProd['product_reference'];
|
|
$product_name=utf8_encode($rowProd['product_name']);
|
|
$product_name=str_replace('&','&',$product_name);
|
|
$qty=$rowProd['product_quantity'];
|
|
$txt.='
|
|
<LIGNE>
|
|
<IDLIGNE>'.$ligne.'</IDLIGNE>
|
|
<CODARTI>'.$product_reference.'</CODARTI>
|
|
<QTTECDE>'.$qty.'</QTTECDE>
|
|
<DESLANG>'.$product_name.'</DESLANG>
|
|
</LIGNE>';
|
|
}
|
|
}
|
|
$txt.="
|
|
</ORDER>";
|
|
|
|
$log=date('Y\-m-d')." Commande #".$row['id_order']." ajouté dans le XML \n";
|
|
$file3 = "LOG_COMMANDES_entre_5H_12H.txt";
|
|
$ar3=fopen('logs/'.$file3,'a+');
|
|
fputs($ar3,$log);
|
|
fclose($ar3);
|
|
}
|
|
mysql_close($conn);
|
|
$txt.="
|
|
</ORDERS>
|
|
";
|
|
|
|
if($txt!='')
|
|
{
|
|
|
|
$file = "CMDCLI".date('YmdHis').".xml";
|
|
$ar=fopen('archives/'.$file,'w') or die("Probleme de création");
|
|
fputs($ar,$txt);
|
|
fclose($ar);
|
|
|
|
//echo "<br/><a href='archives/".$file."' target='_blank'>Voir le XML local</a>";
|
|
$fileFTP = "CMDCLI".date('YmdHis').".xml";
|
|
//echo $fileFTP;
|
|
/*
|
|
$serveur_FTP = "ftp.l4-logistics.fr";
|
|
$id_con = ftp_connect($serveur_FTP);
|
|
|
|
/* DEV
|
|
// $ftp_USER = "Gar_test";
|
|
// $ftp_PASSWORD = "Rsk33As*!";
|
|
// /* PROD */
|
|
/*
|
|
$ftp_USER = "Gar_log";
|
|
$ftp_PASSWORD = "ZAnP49*!";
|
|
|
|
$ftp_dossier_local = 'archives/';
|
|
$ftp_dossier_serveur = "/IN/";
|
|
$result_login = ftp_login($id_con, $ftp_USER, $ftp_PASSWORD);
|
|
|
|
// var_dump($result_login);
|
|
// die();
|
|
// if(ftp_put($id_con, $ftp_dossier_serveur.$fileFTP, $ftp_dossier_local.$file, FTP_BINARY))
|
|
// echo "<br/><br/>Le fichier ".$file." a bien été ajouté dans le dossier /IN sur le FTP de L4LOGISTICS";
|
|
// else
|
|
// echo "<br/><br/>Problème dans la copie du backup dans le ftp distant IN<br>";
|
|
/*
|
|
if(ftp_put($id_con, $ftp_dossier_serveur.$fileFTP, $ftp_dossier_local.$file, FTP_BINARY))
|
|
{
|
|
//echo "<br/><br/>Le fichier ".$file." a bien été ajouté dans le dossier /IN sur le FTP de L4LOGISTICS";
|
|
$log=date('Y\-m\-d')." Le fichier ".$file." a bien été ajouté dans le dossier /IN sur le FTP de L4LOGISTICS\n";
|
|
}
|
|
else
|
|
{
|
|
//echo "<br/><br/>Le fichier ".$file." n a pas été ajouté dans le ftp distant IN<br>";
|
|
$log=date('Y\-m\-d')." Le fichier ".$file." n a pas été ajouté dans le ftp distant IN\n";
|
|
}
|
|
*/
|
|
|
|
// $log=date('Y\-m-d')." Commande en cours de préparation :#".$row['id_order']." \n";
|
|
$file3 = "LOG_COMMANDES_entre_5H_12H.txt";
|
|
$ar3=fopen('logs/'.$file3,'a+');
|
|
fputs($ar3,$log);
|
|
fclose($ar3);
|
|
}
|
|
|
|
$log="TEST 1 - ".count($results)."\n\n";
|
|
$file3 = "LOG_COMMANDES_entre_5H_12H.txt";
|
|
$ar3=fopen('logs/'.$file3,'a+');
|
|
fputs($ar3,$log);
|
|
fclose($ar3);
|
|
include(dirname(__FILE__) .'/../config/config.inc.php');
|
|
|
|
foreach($results as $row)
|
|
{
|
|
$IDORDER= $row['id_order'];
|
|
$log="TEST2 #".$IDORDER." \n\n";
|
|
$file3 = "LOG_COMMANDES_entre_5H_12H.txt";
|
|
$ar3=fopen('logs/'.$file3,'a+');
|
|
fputs($ar3,$log);
|
|
fclose($ar3);
|
|
|
|
$history = new OrderHistory();
|
|
$log="TEST 3\n";
|
|
$file3 = "LOG_COMMANDES_entre_5H_12H.txt";
|
|
$ar3=fopen('logs/'.$file3,'a+');
|
|
fputs($ar3,$log);
|
|
fclose($ar3);
|
|
|
|
$history->id_order = $IDORDER;
|
|
$history->id_employee = 3;
|
|
$use_existings_payment = false;
|
|
|
|
$log="TEST 4\n";
|
|
$file3 = "LOG_COMMANDES_entre_5H_12H.txt";
|
|
$ar3=fopen('logs/'.$file3,'a+');
|
|
fputs($ar3,$log);
|
|
fclose($ar3);
|
|
|
|
$order = new Order($IDORDER);
|
|
$current_order_state=$order->current_state;
|
|
|
|
if($current_order_state!=3)
|
|
{
|
|
$history->changeIdOrderState2(3, $IDORDER, $use_existings_payment);
|
|
if ($history->addWithemail(true, $templateVars))
|
|
{
|
|
$log="TEST 5\n";
|
|
$file3 = "LOG_COMMANDES_entre_5H_12H.txt";
|
|
$ar3=fopen('logs/'.$file3,'a+');
|
|
fputs($ar3,$log);
|
|
fclose($ar3);
|
|
// echo "<br/><br/><a href='logs/".$file3."' target='_blank'>Voir les logs</a>";
|
|
}
|
|
}
|
|
|
|
$log=date('Ymd')." Commande en cours de préparation :#".$IDORDER." \n";
|
|
$file3 = "LOG_COMMANDES_entre_5H_12H.txt";
|
|
$ar3=fopen('logs/'.$file3,'a+');
|
|
fputs($ar3,$log);
|
|
fclose($ar3);
|
|
}
|
|
|
|
$log="\n";
|
|
$file3 = "LOG_COMMANDES_entre_5H_12H.txt";
|
|
$ar3=fopen('logs/'.$file3,'a+');
|
|
fputs($ar3,$log);
|
|
fclose($ar3);
|
|
// ftp_close($id_con);
|
|
?>
|