garancia/L4/generation-PDF.php

116 lines
3.4 KiB
PHP
Raw Permalink Normal View History

<?php
define('_PS_ADMIN_DIR_', getcwd().'/../BO');
define('_forL4_', 1);
require(_PS_ADMIN_DIR_.'/../config/config.inc.php');
require(_PS_ADMIN_DIR_.'/functions.php');
if (isset($_GET['secure_key']))
{
$secureKey = md5(_COOKIE_KEY_.Configuration::get('PS_SHOP_NAME'));
if (!empty($secureKey) AND $secureKey === $_GET['secure_key'])
{
$conn = mysql_connect('localhost', 'garanciab_prod', 'yoeLB4Znn1E1');
mysql_select_db('garanciab_prod');
$dateAnnneMois=date('Ymd');
// $dayNOW=date('Y-m-d');
// $dayNOW_INF=date('Y-m-d', strtotime("-10 day"));
if(date('H')>=11)
{
$dayNOW_INF=date('Y-m-d', strtotime("-4 day"));
$dayNOW_SUP=date('Y-m-d')." 12:00:00";
}
else
{
$dayNOW_INF=date('Y-m-d', strtotime("-1 day"))." 12:00:00";
$dayNOW_SUP=date('Y-m-d')." 5:00:00";
}
$sql = "SELECT o.id_order,o.id_address_delivery,a.id_country,co.id_zone
from ps_orders o
left join ps_address a on(o.id_address_delivery=a.id_address)
left join ps_country co on(co.id_country=a.id_country)
where invoice_date >= '".$dayNOW_INF."'
and invoice_date <= '".$dayNOW_SUP."'
and (co.id_zone!=10 && co.id_zone!=1)
and valid = 1 ";
// ( id_country!=8 pour hors de la france )
$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 ($id_order_state['id_order_state']==13
|| $id_order_state['id_order_state']==12
|| $id_order_state['id_order_state']==2)
{
$results[]=$row;
$i++;
}
}
mysql_close($conn);
foreach($results as $row)
{
$id_order=$row['id_order'];
define('_forL4IDORDER_', $id_order);
$order = new Order((int)$id_order);
if (Validate::isLoadedObject($order))
{
$order_invoice_list = $order->getInvoicesCollection();
Hook::exec('actionPDFInvoiceRender', array('order_invoice_list' => $order_invoice_list));
$pdf = new PDF($order_invoice_list, PDF::TEMPLATE_INVOICE, Context::getContext()->smarty);
$pdf->render('F');
}
}
$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";
listeFichier( "PDF",$id_con);
}else{
echo 'LOGIN NOK';
}
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 "<br/><br/>Le fichier ".$fichier." a bien été ajouté dans le dossier /IN sur le FTP de L4LOGISTICS";
unlink( str_replace("./","",$dir) . "/" . $fichier );
}
else
echo "<br/><br/>".$ftp_dossier_serveur.$fichier." ".$ftp_dossier_local.$fichier;
}
else listeFichier( $dir . "/" . $fichier,$id_con );
}
}
}
}
}