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