= '".$dayNOW_INF."'
and invoice_date <= '".$dayNOW_SUP."'
and valid = 1 ";
$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';
$result = mysql_query($sql, $conn);
$id_order_state = mysql_fetch_array($result);
if((int) $id_order_state['id_order_state'] == 13 || (int) $id_order_state['id_order_state'] == 12 || (int) $id_order_state['id_order_state'] == 2 )
{
$results[]=$row;
$i++;
}
}
echo '
';
echo "
";
$txt = '
';
$i=0;
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';
$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=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']));
$INSTPRP="";
$LIVCOMM="";
if($row['gift']==1)
{
$INSTPRP="CADEAU";
$LIVCOMM=str_pad(htmlspecialchars(utf8_encode($row['gift_message'])), 100, " ", STR_PAD_RIGHT);
$LIVCOMM=str_replace('
','
',$LIVCOMM);
$LIVCOMM=str_replace('
','
',$LIVCOMM);
$LIVCOMM=str_replace('
','
',$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.='
GAR
Garancia-GAR
'.$row['id_order'].$dateAnnneMois.$lettre.'
'.$invoice_date.'
'.str_replace('&','&',$nom).'
'.str_replace('&','&',$prenom).'
'.str_replace('&','&',$company).'
'.str_replace('&','&',$address1).'
'.str_replace('&','&',$address2).'
'.str_replace('&','&',$instructions).'
'.$codpost.'
'.str_replace('&','&',utf8_encode($ville)).'
'.$isoPays.'
'.$telephone.'
'.$LIVCOMM.'
'.str_replace('&','&',$carrier_name).'
'.$MondialRelay.'
'.$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";
// 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.'
'.$product_reference.'
'.$qty.'
'.$product_name.'
';
}
}
$txt.="
";
$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);
}
//Log de vérification des dernières commandes
$sql_log = "
SELECT o . * , c.name AS carrier_name, oh.id_order_state
FROM ps_orders o
LEFT JOIN ps_carrier c ON ( o.id_carrier = c.id_carrier )
LEFT JOIN ps_order_history oh ON ( oh.id_order = o.id_order ) AND oh.date_add = (
SELECT max(date_add) FROM ps_order_history WHERE id_order = o.id_order
)
ORDER BY `o`.`id_order`
DESC LIMIT 0 , 30
";
$res = mysql_query($sql_log, $conn);
$log_verif = '';
while($row = mysql_fetch_array($res)) {
foreach($row as $field => $data) {
if(!is_numeric($field))
{
$log_verif .= '' . $field . ' : ' . $data . '
';
}
}
$log_verif .= '
**********************************************************
';
}
file_put_contents('logs/verif_'.date('d-m-Y-h').'.html', $log_verif);
mysql_close($conn);
$txt.="
";
if($txt!='')
{
$file = "CMDCLI".date('YmdHis').".xml";
$ar=fopen('archives/'.$file,'w') or die("Probleme de création");
fputs($ar,$txt);
fclose($ar);
$fileFTP = "CMDCLI".date('YmdHis').".xml";
$serveur_FTP = "ftp.l4-logistics.fr";
$id_con = ftp_connect($serveur_FTP);
$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);
if(ftp_put($id_con, $ftp_dossier_serveur.$fileFTP, $ftp_dossier_local.$file, FTP_BINARY))
$log=date('Y\-m\-d')." Le fichier ".$file." a bien été ajouté dans le dossier /IN sur le FTP de L4LOGISTICS\n";
else
$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 = 7;
$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 "
Voir les logs";
}
}
$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);
function anta_log($msg='')
{
$file = dirname(dirname(__FILE__)).'/logs/log_'.date("d-m-Y_H-i").'.txt';
if($fp = fopen($file, 'a+') )
{
fseek($fp, SEEK_END);
if($msg == '')
fputs($fp,''."\n");
else
fputs($fp, '['.date('d/m/y - h:i:s'). '] # '.$msg."\n");
}
}
?>