language) || !is_object($context->language)) ? (int)Configuration::get('PS_LANG_DEFAULT') : (int)$context->language->id; $stocks = Db::getInstance()->ExecuteS(' SELECT sa.id_stock_available, sa.id_product, sa.id_product_attribute, sa.parcels, pl.name, al.name as declinaison FROM `'._DB_PREFIX_.'stock_available` sa INNER JOIN '._DB_PREFIX_.'product p ON(p.id_product = sa.id_product) INNER JOIN '._DB_PREFIX_.'product_lang pl ON(pl.id_product = sa.id_product AND pl.id_lang = '.$id_lang.') LEFT JOIN '._DB_PREFIX_.'product_attribute pa ON(pa.id_product = sa.id_product) LEFT JOIN '._DB_PREFIX_.'product_attribute_combination pac ON(pac.id_product_attribute = sa.id_product_attribute) LEFT JOIN '._DB_PREFIX_.'attribute a ON(a.id_attribute = pac.id_attribute) LEFT JOIN '._DB_PREFIX_.'attribute_lang al ON(al.id_attribute = pac.id_attribute AND al.id_lang = pl.id_lang) WHERE sa.parcels != "" AND p.active = 1 GROUP BY sa.id_product, sa.id_product_attribute '); $alerts = array(); foreach($stocks as $stock) { $parcels = unserialize($stock['parcels']); foreach($parcels as $key => $parcel) { $alert = array(); $parcel_date = explode('-', $key); $date = strtotime('01-'.$parcel_date[1].'-'.$parcel_date[0]); $today = strtotime(date('d-n-Y')); $days = round(($date - $today) / 86400); if($days > 90) { continue; } if($days <= 0) { $alert['info'] = 'DLC dépassée pour le produit '.$stock['id_product'].' : '.$stock['name'].' - '.$stock['declinaison']; $alert['date'] = $parcel['date']; $alert['qty'] = $parcel['quantity']; $alert['days'] = $days; $alerts[0][] = $alert; } if($days > 0 && $days <= 30) { $alert['info'] = 'DLC à moins de 30 jours pour le produit '.$stock['id_product'].' : '.$stock['name'].' - '.$stock['declinaison']; $alert['date'] = $parcel['date']; $alert['qty'] = $parcel['quantity']; $alert['days'] = $days; $alerts[30][] = $alert; } if($days > 30 && $days <= 90) { $alert['info'] = 'DLC à moins de 3 mois pour le produit '.$stock['id_product'].' : '.$stock['name'].' - '.$stock['declinaison']; $alert['date'] = $parcel['date']; $alert['qty'] = $parcel['quantity']; $alert['days'] = $days; $alerts[90][] = $alert; } } } ksort($alerts); $html = '

Bonjour

Veuillez trouver ci-dessous la liste des lots à contrôler.

'; if($alerts) { $html .= ''; $bg = array(0 => '#e25555', 30 => '#e2a455', 90 => '#e2c555'); foreach($alerts as $key => $alert) { foreach($alert as $value) { $html .= ''; } } $html .= '
Produit DLC / DLUO Jours restants Quantité
'.$value['info'].' '.$value['date'].' '.$value['days'].' '.$value['qty'].'

'; $html .= '
Contrôle effectué par le service de surveillance automatique des stocks
'; echo $html; if(!Tools::getValue('display')) { $eol = "\r\n"; $subject= "=?utf-8?b?".base64_encode('Alerte DLC/DLUO')."?="; $headers = "MIME-Version: 1.0".$eol; $headers .= "Content-Type: text/html; charset=ISO-8859-1".$eol; $headers .= "From: =?utf-8?b?".base64_encode(Configuration::get("PS_SHOP_NAME")." - Stock Service")."?= <".Configuration::get("PS_SHOP_EMAIL").">".$eol; $headers .= "Reply-To: <".Configuration::get("PS_SHOP_EMAIL").">".$eol; $headers .= "Return-Path: <".Configuration::get("PS_SHOP_EMAIL").">".$eol; $headers .= "X-Mailer: PHP v ".phpversion().$eol; $headers .= "Content-Transfer-Encoding: 7bit".$eol.$eol; if(!mail(Configuration::get('PS_SHOP_EMAIL'), $subject, utf8_decode($html), $headers)) echo 'Erreur: Envoi du mail impossible !'; } } else { echo 'Tous les lots enregistrés ont une date de validité supérieure à 3 mois :-)'; } exit();