= '2013-08-21 00:00:00'
// and invoice_date <= '2013-08-21 23:59:59'
// 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);
$results[]=$row;
$i++;
}
echo '
';
echo "
";
echo "SQL : ".$sql. " ";
echo $i.' commandes trouvés pour la période : invoice_date >= "'.$dayNOW_INF.'" and invoice_date <= "'.$dayNOW_SUP.'"';
echo " ";
$txt = '
';
// 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=htmlspecialchars(utf8_encode($row['gift_message']));
$LIVCOMM=nl2br($LIVCOMM);
$LIVCOMM=str_replace(' ','
',$LIVCOMM);
$LIVCOMM=str_replace(' ','
',$LIVCOMM);
$LIVCOMM=str_replace(' ','
',$LIVCOMM);
$LIVCOMM=str_replace('\r\n','
',$LIVCOMM);
$LIVCOMM=str_replace('\n','
',$LIVCOMM);
$LIVCOMM=str_replace('
','
',$LIVCOMM);
$LIVCOMM=str_replace('\r','
',$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.="
";
}
mysql_close($conn);
$txt.="
";
echo $txt;
// if($txt!=''){
// $file = "CMDCLI".date('YmdHis').".xml";
// $ar=fopen('archives/'.$file,'w') or die("Probleme de création");
// fputs($ar,$txt);
// fclose($ar);
// echo "Voir le XML local ";
// $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/";
// if($result_login = ftp_login($id_con, $ftp_USER, $ftp_PASSWORD))
// echo "LOGIN OK";
// if(ftp_put($id_con, $ftp_dossier_serveur.$fileFTP, $ftp_dossier_local.$file, FTP_BINARY))
// echo " Le fichier ".$file." a bien été ajouté dans le dossier /IN sur le FTP de L4LOGISTICS";
// else
// echo " Problème dans la copie du backup dans le ftp distant IN ";
// function listeFichier( $dir,$id_con )
// {
// $ftp_dossier_serveur = "/IN/";
// $dossier = opendir( $dir );
// while ( $fichier = readdir( $dossier ) ){
// if ( $fichier != "." && $fichier != ".."){
// if ( !is_dir( $dir . "/" . $fichier ) ){
// $ftp_dossier_local = 'PDF/';
// if(ftp_put($id_con, $ftp_dossier_serveur.$fichier, $ftp_dossier_local.$fichier, FTP_BINARY)){
// echo " Le fichier ".$file." a bien été ajouté dans le dossier /IN sur le FTP de L4LOGISTICS";
// unlink( str_replace("./","",$dir) . "/" . $fichier );
// }
// else
// echo " ".$ftp_dossier_serveur.$fichier." ".$ftp_dossier_local.$fichier;
// }
// else listeFichier( $dir . "/" . $fichier,$id_con );
// }
// }
// }
// listeFichier( "PDF",$id_con);
// ftp_close($id_con);
// }
// foreach($results as $row){
// include_once('../config/config.inc.php');
// $history = new OrderHistory();
// $history->id_order = $row['id_order'];
// $history->id_employee = 3;
// $use_existings_payment = false;
// $history->changeIdOrderState2(3, $row['id_order'], $use_existings_payment);
// if ($history->addWithemail(true, $templateVars))
// {
// $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);
// // echo "Voir les logs ";
// }else{
// $file3 = "LOG_COMMANDES_entre_5H_12H.txt";
// }
// }