objPHPExcel = new PHPExcel(); $this->columns_es = array( 'B' => 'EAN', 'C' => 'Ref fournisseur', 'D' => 'Id produit', 'E' => 'Nom du produit', 'F' => 'Catégorie', 'G' => 'Sous-catégorie', 'H' => 'Sous-sous-catégorie', 'I' => 'Description courte', 'J' => 'Bon à savoir', 'K' => 'Les plus', 'L' => 'Vidéos', 'M' => 'Livraison', ); $this->columns = array( 'B' => 'EAN', 'C' => 'Ref fournisseur', 'D' => 'Ref modifiée', 'E' => 'Nom du produit', 'F' => 'Type de produit', 'G' => 'Nom / Collection', 'H' => 'Coloris / Déclinaison', 'I' => 'Taille HA', 'J' => 'Taille (old)', 'K' => 'Nom du produit HA', 'L' => 'Nom du produit (old)', 'M' => 'Nb de caract. Titre', 'N' => 'Order', 'O' => 'Catégorie', 'P' => 'Sous-catégorie', 'Q' => 'Sous-sous-catégorie', 'R' => 'Nb de photos', 'S' => 'Ordre Logistique', 'T' => 'Ref Bébé Boutik', 'U' => 'Nb de caract. Ref', 'V' => 'Description courte', 'W' => 'Bon à savoir', 'X' => 'Les plus', 'Y' => 'Vidéo', 'Z' => 'Livraison', 'AA'=> 'Poids', 'AB' => 'Vente old', 'AC' => 'BDC old', 'AD' => 'Quantité réservée', 'AE' => 'Taille', 'AF' => 'TVA appliquée', 'AG' => 'PPC TTC', 'AH' => 'PPC old', 'AI' => 'Prix achat HT', 'AJ' => 'Prix HA old', 'AK' => 'Différence', 'AL' => 'PV 3BTK appliqué', 'AM' => 'Prix vente old', 'AN' => 'Remise membre', 'AO' => 'Marge', 'AP' => 'Photos', 'AQ' => 'Photos old', 'AR' => 'BDC Potentiel', 'AS' => 'Custom code', 'AT' => 'Pays de fabrication', 'AU' => 'Date de la vente'); } public static $FORMAT_DARK_BLUE = '214A7B'; public static $FORMAT_LIGHT_BLUE = '6C8DCD'; public static $FORMAT_LIGHTER_DARK_BLUE = 'C6D9F0'; public static $FORMAT_BG_LIGHT_RED = 'FEC7CE'; public static $FORMAT_BG_DARK_RED = 'FF9A0511'; public static $FORMAT_BG_LIGHT_GREEN = 'C7EECF'; public static $FORMAT_BG_DARK_GREEN = 'FF09600B'; public static $FORMAT_BG_LIGHT_YELLOW = 'FEEAA0'; public static $FORMAT_BG_DARK_YELLOW = 'FFA36415'; public function generate($params, &$timer_table, $callStartTime) { $sheets = array(0,1); $lastLine = count($params['lines'])+4; $this->objPHPExcel->removeSheetByIndex(0); $borders_style = array( 'borders' => array( 'allborders' => array( 'style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array( 'rgb' => '000000' ) ) ) ); $borders_style_none = array( 'borders' => array( 'allborders' => array( 'style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array( 'rgb' => 'FFFFFF' ) ) ) ); $darker_light_blue_style = array( 'type' => PHPExcel_Style_Fill::FILL_SOLID, 'rotation' => 0, 'startcolor' => array( 'rgb' => self::$FORMAT_LIGHTER_DARK_BLUE ), 'endcolor' => array( 'rgb' => self::$FORMAT_LIGHTER_DARK_BLUE ) ); foreach ($sheets as $key => $sheet) { $this->objPHPExcel->createSheet(); $this->objPHPExcel->setActiveSheetIndex($key); $this->objPHPExcel->setActiveSheetIndex($key)->setCellValue('A1','Vente - '.(String)$params['marque']); $activeSheet = $this->objPHPExcel->getActiveSheet(); $activeSheet->mergeCells('A1:B1'); if($key === 0){ $activeSheet->setTitle('WP-Vente FR'); $activeSheet->setCellValue('AP1',(String)$params['marque']); $activeSheet->getStyle('AP1')->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_WHITE); $activeSheet->getStyle('AP1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $activeSheet->getStyle('AP1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER); $activeSheet->getStyle('AP1')->getFill()->applyFromArray( array( 'type' => PHPExcel_Style_Fill::FILL_SOLID, 'rotation' => 0, 'startcolor' => array( 'rgb' => '000000' ), 'endcolor' => array( 'rgb' => '000000' ) ) ); }elseif($key === 1){ $activeSheet->setTitle('WP-Vente ES'); } $activeSheet->getStyle('A1:AZ'.($lastLine+20))->applyFromArray($borders_style_none); $activeSheet->getStyle('A1:AU'.$lastLine)->getFont()->setSize(10); $activeSheet->getStyle('A1:AU'.$lastLine)->getFont()->setName('calibri'); $activeSheet->getColumnDimension('A')->setWidth(3); $activeSheet->freezePane('E5'); } $timer_table[] = 'Excel sheet format done for the 3 first lines in '.(microtime(true)-$callStartTime); $i=4; foreach ($this->columns as $key => $value) { $this->objPHPExcel->setActiveSheetIndex(0); $activeSheet = $this->objPHPExcel->getActiveSheet(); $activeSheet->getRowDimension($i)->setRowHeight(25); if(in_array($key, array('B','C','D','O','P','Q','T','W','X','Y','Z'), true)){ $activeSheet->getColumnDimension($key)->setWidth(16); } elseif(in_array($key, array('F','G','H','I','J','K','L'), true)){ $activeSheet->getColumnDimension($key)->setWidth(20); } elseif(in_array($key, array('M','N','R','S','U'), true)){ $activeSheet->getColumnDimension($key)->setWidth(10); } elseif(in_array($key, array('AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM','AN','AO'), true)){ $activeSheet->getColumnDimension($key)->setWidth(11); } elseif(in_array($key, array('V','AP'), true)){ $activeSheet->getColumnDimension($key)->setWidth(45); } elseif(in_array($key, array('AR','AS','AT', 'AU'), true)){ $activeSheet->getColumnDimension($key)->setWidth(12); } elseif('E' === $key){ $activeSheet->getColumnDimension($key)->setWidth(25); } elseif('AQ' === $key){ $activeSheet->getColumnDimension($key)->setWidth(40); } // elseif(in_array($key,array('U','AO','AP'))) { // $activeSheet->getColumnDimension($key)->setWidth(35); // } elseif(in_array($key,array('D'))) { // $activeSheet->getColumnDimension($key)->setWidth(25); // } elseif(in_array($key,array('E','F','G','H','I','J','K'))) { // $activeSheet->getColumnDimension($key)->setWidth(20); // } elseif(in_array($key,array('Z','AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM','AN','AQ','AR','AS','AT'))) { // $activeSheet->getColumnDimension($key)->setWidth(8); // } elseif(in_array($key,array('L','M','Q','R','T'))){ // $activeSheet->getColumnDimension($key)->setWidth(7); // } else { // $activeSheet->getColumnDimension($key)->setWidth(13); // } $activeSheet->setCellValue($key.$i,$value); $activeSheet->getStyle($key.$i)->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_WHITE); $activeSheet->getStyle($key.$i)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $activeSheet->getStyle($key.$i)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER); $activeSheet->getStyle($key.$i)->getAlignment()->setWrapText(true); $activeSheet->getStyle($key.$i)->applyFromArray($borders_style); if(in_array($key,array('AB','AC','AH','AJ','AK','AM'),true)){ $activeSheet->getStyle($key.$i)->getFill()->applyFromArray( array( 'type' => PHPExcel_Style_Fill::FILL_SOLID, 'rotation' => 0, 'startcolor' => array( 'rgb' => self::$FORMAT_DARK_BLUE //dark blue ), 'endcolor' => array( 'rgb' => self::$FORMAT_DARK_BLUE //dark blue ) ) ); }else{ $activeSheet->getStyle($key.$i)->getFill()->applyFromArray( array( 'type' => PHPExcel_Style_Fill::FILL_SOLID, 'rotation' => 0, 'startcolor' => array( 'rgb' => self::$FORMAT_LIGHT_BLUE //light blue ), 'endcolor' => array( 'rgb' => self::$FORMAT_LIGHT_BLUE //light blue ) ) ); } } foreach ($this->columns_es as $key => $value) { $this->objPHPExcel->setActiveSheetIndex(1); $activeSheet = $this->objPHPExcel->getActiveSheet(); $activeSheet->getRowDimension($i)->setRowHeight(25); if(in_array($key, array('B','C','D','E','G','H','I'), true)) { $activeSheet->getColumnDimension($key)->setWidth(13); } elseif(in_array($key, array('F','K'), true)) { $activeSheet->getColumnDimension($key)->setWidth(25); } elseif('J' === $key) { $activeSheet->getColumnDimension($key)->setWidth(35); } else { $activeSheet->getColumnDimension($key)->setWidth(8); } $activeSheet->setCellValue($key.$i,$value); $activeSheet->getStyle($key.$i)->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_WHITE); $activeSheet->getStyle($key.$i)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $activeSheet->getStyle($key.$i)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER); $activeSheet->getStyle($key.$i)->getAlignment()->setWrapText(true); $activeSheet->getStyle($key.$i)->applyFromArray($borders_style); $activeSheet->getStyle($key.$i)->getFill()->applyFromArray( array( 'type' => PHPExcel_Style_Fill::FILL_SOLID, 'rotation' => 0, 'startcolor' => array( 'rgb' => self::$FORMAT_LIGHT_BLUE ), 'endcolor' => array( 'rgb' => self::$FORMAT_LIGHT_BLUE ) ) ); } $timer_table[] = 'Excel sheet format done for the 4 first lines in '.(microtime(true)-$callStartTime); $i++; $sales = array(); $order_states = explode(',', Configuration::get('PS_IT_OF_ORDER_STATES')); foreach ($params['lines'] as $key => $row) { $image_line = '=IF(R'.$i.'="","",IF(R'.$i.'=1, "https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&".jpg", IF(R'.$i.'=2, "https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&".jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-1.jpg", IF(R'.$i.'=3, "https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&".jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-1.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-2.jpg", IF(R'.$i.'=4, "https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&".jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-1.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-2.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-3.jpg", IF(R'.$i.'=5,"https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&".jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-1.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-2.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-3.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-4.jpg", IF(R'.$i.'=6,"https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&".jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-1.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-2.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-3.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-4.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-5.jpg", IF(R'.$i.'=7,"https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&".jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-1.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-2.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-3.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-4.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-5.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-6.jpg", IF(R'.$i.'=8,"https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&".jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-1.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-2.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-3.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-4.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-5.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-6.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-7.jpg", IF(R'.$i.'=9,"https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&".jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-1.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-2.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-3.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-4.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-5.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-6.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-7.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-8.jpg", IF(R'.$i.'=10,"https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&".jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-1.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-2.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-3.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-4.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-5.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-6.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-7.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-8.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-9.jpg", IF(R'.$i.'=11,"https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&".jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-1.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-2.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-3.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-4.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-5.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-6.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-7.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-8.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-9.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-10.jpg", IF(R'.$i.'=12,"https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&".jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-1.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-2.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-3.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-4.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-5.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-6.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-7.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-8.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-9.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-10.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-11.jpg", IF(R'.$i.'=13,"https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&".jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-1.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-2.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-3.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-4.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-5.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-6.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-7.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-8.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-9.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-10.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-11.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-12.jpg", IF(R'.$i.'=14,"https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&".jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-1.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-2.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-3.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-4.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-5.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-6.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-7.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-8.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-9.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-10.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-11.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-12.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-13.jpg", IF(R'.$i.'=1'.$i.',"https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&".jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-1.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-2.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-3.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-4.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-5.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-6.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-7.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-8.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-9.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-10.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-11.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-12.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-13.jpg, https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-14.jpg"))))))))))))))))'; $image_line = str_replace(array("\r", "\n", ' '), '', $image_line); if(isset($row['id_product'])){ $id_categories = array(); foreach(Db::getInstance()->ExecuteS(' SELECT `id_category` FROM `'._DB_PREFIX_.'category_product` WHERE `id_product` = '.(int) $row['id_product'].' ') as $cat) { $id_categories[] = (int) $cat['id_category']; } sort($id_categories); if(!isset($sales[$id_categories[0]])){ $sales[$id_categories[0]] = Db::getInstance()->getValue(' SELECT `date_start` FROM `'._DB_PREFIX_.'privatesale` WHERE `id_category` = '.(int) $id_categories[0].' '); } $categories_title = array(2 => array(0 => '', 1 => '', 2 => ''), 3 => array(0 => '', 1 => '', 2 => '')); foreach ($id_categories as $key_cat => $id_category) { foreach (Db::getInstance()->executeS(' SELECT `name`,`id_lang` FROM `'._DB_PREFIX_.'category_lang` WHERE `id_category` = '.(int) $id_category.' AND (`id_lang` = 2 OR `id_lang` = 3) ') as $title) { $categories_title[$title['id_lang']][$key_cat] = $title['name']; } } $images = array(); foreach(Db::getInstance()->ExecuteS(' SELECT i.`id_image`, l.`legend` FROM `'._DB_PREFIX_.'image` i LEFT JOIN `'._DB_PREFIX_.'image_lang` l ON l.`id_image` = i.`id_image` WHERE l.`id_lang` = 2 AND i.`id_product` = '.(int) $row['id_product'].' ORDER BY i.`position` ') as $img) { $link_image = str_split($img['id_image']); $images[] = 'https://static.bebeboutik.com/img/p/'.implode('/', $link_image) .'/'. $img['id_image'].'.jpg'; } $price = Product::getPriceStatic($row['id_product'],TRUE, NULL, 2, NULL, FALSE, FALSE); $price2 = Product::getPriceStatic($row['id_product'],TRUE, NULL, 2); if(isset($row['id_product_attribute'])){ $quantity_sold = (int) Db::getInstance()->getValue(' SELECT SUM(d.`product_quantity` - d.`product_quantity_reinjected`) FROM `'._DB_PREFIX_.'order_detail` d LEFT JOIN `'._DB_PREFIX_.'orders` o ON o.`id_order` = d.`id_order` lEFT JOIN `'._DB_PREFIX_.'order_state_current` sc ON sc.`id_order` = d.`id_order` WHERE d.`product_id` = '.(int)$row['id_product'].' AND d.`product_attribute_id` = '.(int)$row['id_product_attribute'].' AND sc.id_order_state IN ("'.implode('","', $order_states).'") '); } else { $quantity_sold = (int) Db::getInstance()->getValue(' SELECT SUM(d.`product_quantity` - d.`product_quantity_reinjected`) FROM `'._DB_PREFIX_.'order_detail` d LEFT JOIN `'._DB_PREFIX_.'orders` o ON o.`id_order` = d.`id_order` lEFT JOIN `'._DB_PREFIX_.'order_state_current` sc ON sc.`id_order` = d.`id_order` WHERE d.`product_id` = '.(int)$row['id_product'].' AND d.`product_attribute_id` = 0 AND sc.id_order_state IN ("'.implode('","', $order_states).'") '); } if($quantity_sold === 0){ $quantity_sold = ''; $total_revenue = ''; }else{ $total_revenue = Tools::ps_round(($quantity_sold * $row['wholesale_price']),2); } $this->objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$i, (String)$row['ean']) ->setCellValue('C'.$i, (String)$row['supplier_ref']) ->setCellValue('D'.$i, (String)$row['supplier_reference']) ->setCellValue('E'.$i, '=IF(AND(F'.$i.'="",G'.$i.'="",H'.$i.'=""),"",F'.$i.'&" "&G'.$i.'&" - "&H'.$i.')') ->setCellValue('F'.$i, '') ->setCellValue('G'.$i, '') ->setCellValue('H'.$i, '') ->setCellValue('I'.$i, $row['name_attribute_ha']) ->setCellValue('J'.$i, (isset($row['attribute_name'])?$row['attribute_name']:'')) ->setCellValue('K'.$i, $row['name_ha']) ->setCellValue('L'.$i, $row['lang'][2]['name']) ->setCellValue('M'.$i, '=LEN(E'.$i.')') ->setCellValue('N'.$i, (int)$row['position']) ->setCellValue('O'.$i, $categories_title[2][0]) ->setCellValue('P'.$i, $categories_title[2][1]) ->setCellValue('Q'.$i, $categories_title[2][2]) ->setCellValue('R'.$i, count($images)) ->setCellValue('S'.$i, '') ->setCellValue('T'.$i, '=AP1&"-"&S'.$i.'&"-"&LEFT(D'.$i.',9)') ->setCellValue('U'.$i, '=IF(T'.$i.'="","",LEN(T'.$i.'))') ->setCellValue('V'.$i, $row['lang'][2]['description_short']) ->setCellValue('W'.$i, $row['lang'][2]['description']) ->setCellValue('X'.$i, $row['lang'][2]['description_more']) ->setCellValue('Y'.$i, $row['lang'][2]['videos']) ->setCellValue('Z'.$i, $row['lang'][2]['description_delivery']) ->setCellValue('AA'.$i, $row['weight']) ->setCellValue('AB'.$i, $quantity_sold) ->setCellValue('AC'.$i, $total_revenue) ->setCellValue('AD'.$i, $row['quantity']) ->setCellValue('AE'.$i, $row['height']) ->setCellValue('AF'.$i, $row['id_tax_rules_group']) ->setCellValue('AG'.$i, $row['ppc']) ->setCellValue('AH'.$i, Product::getPriceStatic($row['id_product'],TRUE, NULL, 2, NULL, FALSE, FALSE)) ->setCellValue('AI'.$i, $row['prix_ha']) ->setCellValue('AJ'.$i, Tools::ps_round($row['wholesale_price'], 2)) ->setCellValue('AK'.$i, '=IF(AJ'.$i.'="","",IF((AI'.$i.'-AJ'.$i.')>0,"ATTENTION",IF((AI'.$i.'-AJ'.$i.')<0,"COOL",IF((AI'.$i.'-AJ'.$i.')=0,"OK",""))))') ->setCellValue('AL'.$i, '=IF(AI'.$i.'="","",(AI'.$i.'*1.85))') ->setCellValue('AM'.$i, $price2) ->setCellValue('AN'.$i, '=IF(AND(AG'.$i.'="",AL'.$i.'=""),"",ROUND((1-AL'.$i.'/AG'.$i.')*100,4))') ->setCellValue('AO'.$i, '=IF(AND(AI'.$i.'="",AL'.$i.'=""),"",1-AI'.$i.'/(AL'.$i.'/1.2))') ->setCellValue('AP'.$i, $image_line) ->setCellValue('AQ'.$i, implode(', ', $images)) ->setCellValue('AR'.$i, '=AD'.$i.'*AI'.$i) ->setCellValue('AS'.$i, isset($row['nc8'])?$row['nc8']:"") ->setCellValue('AT'.$i, isset($row['id_country'])?$row['id_country']:"") ->setCellValue('AU'.$i, date('d/m/Y',strtotime($sales[$id_categories[0]]))); $this->objPHPExcel->setActiveSheetIndex(0)->getStyle('B'.$i.':AU'.$i.'')->applyFromArray($borders_style); $this->objPHPExcel->setActiveSheetIndex(1)->setCellValue('B'.$i, (String)$row['ean']) ->setCellValue('C'.$i, (String)$row['supplier_reference']) ->setCellValue('D'.$i, '') ->setCellValue('E'.$i, $row['lang'][3]['name']) ->setCellValue('F'.$i, $categories_title[3][0]) ->setCellValue('G'.$i, $categories_title[3][1]) ->setCellValue('H'.$i, $categories_title[3][2]) ->setCellValue('I'.$i, $row['lang'][3]['description_short']) ->setCellValue('J'.$i, $row['lang'][3]['description']) ->setCellValue('K'.$i, $row['lang'][3]['description_more']) ->setCellValue('L'.$i, $row['lang'][3]['videos']) ->setCellValue('M'.$i, $row['lang'][3]['description_delivery']); $this->objPHPExcel->setActiveSheetIndex(1)->getStyle('B'.$i.':M'.$i.'')->applyFromArray($borders_style); } else { $this->objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$i, (String)$row['ean']) ->setCellValue('C'.$i, (String)$row['supplier_ref']) ->setCellValue('D'.$i, (String)$row['supplier_reference']) ->setCellValue('E'.$i, '=IF(AND(F'.$i.'="",G'.$i.'="",H'.$i.'=""),"",F'.$i.'&" "&G'.$i.'&" - "&H'.$i.')') ->setCellValue('F'.$i, '') ->setCellValue('G'.$i, '') ->setCellValue('H'.$i, '') ->setCellValue('I'.$i, $row['name_attribute_ha']) ->setCellValue('J'.$i, '') ->setCellValue('K'.$i, $row['name_ha']) ->setCellValue('L'.$i, '') ->setCellValue('M'.$i, '=LEN(E'.$i.')') ->setCellValue('N'.$i, '') ->setCellValue('O'.$i, '') ->setCellValue('P'.$i, '') ->setCellValue('Q'.$i, '') ->setCellValue('R'.$i, '') ->setCellValue('S'.$i, '') ->setCellValue('T'.$i, '=AP1&"-"&S'.$i.'&"-"&LEFT(D'.$i.',9)') ->setCellValue('U'.$i, '=IF(T'.$i.'="","",LEN(T'.$i.'))') ->setCellValue('V'.$i, '') ->setCellValue('W'.$i, '') ->setCellValue('X'.$i, '') ->setCellValue('Y'.$i, '') ->setCellValue('Z'.$i, '') ->setCellValue('AA'.$i, '') ->setCellValue('AB'.$i, '') ->setCellValue('AC'.$i, '') ->setCellValue('AD'.$i, $row['quantity']) ->setCellValue('AE'.$i, '') ->setCellValue('AF'.$i, '') ->setCellValue('AG'.$i, $row['ppc']) ->setCellValue('AH'.$i, '') ->setCellValue('AI'.$i, $row['prix_ha']) ->setCellValue('AJ'.$i, '') ->setCellValue('AK'.$i, '=IF(AJ'.$i.'="","",IF((AI'.$i.'-AJ'.$i.')>0,"ATTENTION",IF((AI'.$i.'-AJ'.$i.')<0,"COOL",IF((AI'.$i.'-AJ'.$i.')=0,"OK",""))))') ->setCellValue('AL'.$i, '=IF(AI'.$i.'="","",(AI'.$i.'*1.85))') ->setCellValue('AM'.$i, '') ->setCellValue('AN'.$i, '=IF(AND(AG'.$i.'="",AL'.$i.'=""),"",ROUND((1-AL'.$i.'/AG'.$i.')*100,4))') ->setCellValue('AO'.$i, '=IF(AND(AI'.$i.'="",AL'.$i.'=""),"",1-AI'.$i.'/(AL'.$i.'/1.2))') ->setCellValue('AP'.$i, $image_line) ->setCellValue('AQ'.$i, '') ->setCellValue('AR'.$i, '=AD'.$i.'*AI'.$i) ->setCellValue('AS'.$i, '') ->setCellValue('AT'.$i, '') ->setCellValue('AU'.$i, ''); $this->objPHPExcel->setActiveSheetIndex(0)->getStyle('B'.$i.':AU'.$i.'')->applyFromArray($borders_style); $this->objPHPExcel->setActiveSheetIndex(1)->setCellValue('B'.$i, (String)$row['ean']) ->setCellValue('C'.$i, $row['supplier_ref']) ->setCellValue('D'.$i, '') ->setCellValue('E'.$i, '') ->setCellValue('F'.$i, '') ->setCellValue('G'.$i, '') ->setCellValue('H'.$i, '') ->setCellValue('I'.$i, '') ->setCellValue('J'.$i, '') ->setCellValue('K'.$i, '') ->setCellValue('L'.$i, '') ->setCellValue('M'.$i, ''); $this->objPHPExcel->setActiveSheetIndex(1)->getStyle('B'.$i.':M'.$i.'')->applyFromArray($borders_style); } $i++; } $timer_table[] = 'Excel sheet data inserted after '.(microtime(true)-$callStartTime); $this->objPHPExcel->setActiveSheetIndex(0); $this->objPHPExcel->getActiveSheet() ->getStyle('B5:B'.$lastLine) ->getNumberFormat() ->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER); $this->objPHPExcel->getActiveSheet() ->getStyle('D5:D'.$lastLine) ->getNumberFormat() ->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT); $this->objPHPExcel->getActiveSheet() ->getStyle('I5:I'.$lastLine) ->getNumberFormat() ->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER); $this->objPHPExcel->getActiveSheet() ->getStyle('I5:I'.$lastLine) ->getAlignment() ->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $this->objPHPExcel->getActiveSheet() ->getStyle('S5:S'.$lastLine) ->getNumberFormat() ->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT); $this->objPHPExcel->getActiveSheet() ->getStyle('U5:U'.$lastLine) ->getNumberFormat() ->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER); $this->objPHPExcel->getActiveSheet() ->getStyle('U5:U'.$lastLine) ->getAlignment() ->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $this->objPHPExcel->getActiveSheet() ->getStyle('AC5:AC'.$lastLine) ->getNumberFormat() ->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR); $this->objPHPExcel->getActiveSheet() ->getStyle('AG5:AG'.$lastLine) ->getNumberFormat() ->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR); $this->objPHPExcel->getActiveSheet() ->getStyle('AH5:AH'.$lastLine) ->getNumberFormat() ->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR); $this->objPHPExcel->getActiveSheet() ->getStyle('AB5:AB' . $lastLine) ->getFill()->applyFromArray($darker_light_blue_style); $this->objPHPExcel->getActiveSheet() ->getStyle('AC5:AC' . $lastLine) ->getFill()->applyFromArray($darker_light_blue_style); $this->objPHPExcel->getActiveSheet() ->getStyle('AH5:AH' . $lastLine) ->getFill()->applyFromArray($darker_light_blue_style); $this->objPHPExcel->getActiveSheet() ->getStyle('AJ5:AJ' . $lastLine) ->getFill()->applyFromArray($darker_light_blue_style); $this->objPHPExcel->getActiveSheet() ->getStyle('AK5:AK' . $lastLine) ->getFill()->applyFromArray($darker_light_blue_style); $this->objPHPExcel->getActiveSheet() ->getStyle('AM5:AM' . $lastLine) ->getFill()->applyFromArray($darker_light_blue_style); $this->objPHPExcel->getActiveSheet() ->getStyle('AB5:AB' . $lastLine) ->getFont()->setBold(true); $this->objPHPExcel->getActiveSheet() ->getStyle('AC5:AC' . $lastLine) ->getFont()->setBold(true); $this->objPHPExcel->getActiveSheet() ->getStyle('AH5:AH' . $lastLine) ->getFont()->setBold(true); $this->objPHPExcel->getActiveSheet() ->getStyle('AJ5:AJ' . $lastLine) ->getFont()->setBold(true); $this->objPHPExcel->getActiveSheet() ->getStyle('AK5:AK' . $lastLine) ->getFont()->setBold(true); $this->objPHPExcel->getActiveSheet() ->getStyle('AM5:AM' . $lastLine) ->getFont()->setBold(true); //Conditionnal formating for column L $nb_max_char = 64; $objConditional1 = new PHPExcel_Style_Conditional(); $objConditional1->setConditionType(PHPExcel_Style_Conditional::CONDITION_EXPRESSION) ->addCondition('M5>'.$nb_max_char); $objConditional1->getStyle()->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getEndColor()->setARGB(self::$FORMAT_BG_LIGHT_RED); $objConditional1->getStyle()->getFont()->setColor(new PHPExcel_Style_Color(self::$FORMAT_BG_DARK_RED)); $objConditional2 = new PHPExcel_Style_Conditional(); $objConditional2->setConditionType(PHPExcel_Style_Conditional::CONDITION_EXPRESSION) ->addCondition('M5='.$nb_max_char); $objConditional2->getStyle()->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getEndColor()->setARGB(self::$FORMAT_BG_LIGHT_YELLOW); $objConditional2->getStyle()->getFont()->setColor(new PHPExcel_Style_Color(self::$FORMAT_BG_DARK_YELLOW)); $objConditional3 = new PHPExcel_Style_Conditional(); $objConditional3->setConditionType(PHPExcel_Style_Conditional::CONDITION_EXPRESSION) ->addCondition('M5<'.$nb_max_char); $objConditional3->getStyle()->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getEndColor()->setARGB(self::$FORMAT_BG_LIGHT_GREEN); $objConditional3->getStyle()->getFont()->setColor(new PHPExcel_Style_Color(self::$FORMAT_BG_DARK_GREEN)); $conditionalStyles = $this->objPHPExcel->getActiveSheet()->getStyle('M5:M'.$lastLine)->getConditionalStyles(); $conditionalStyles[] = $objConditional1; $conditionalStyles[] = $objConditional2; $conditionalStyles[] = $objConditional3; $this->objPHPExcel->getActiveSheet()->getStyle('M5:M'.$lastLine)->setConditionalStyles($conditionalStyles); $nb_max_char = 17; //Conditionnal formating for column T $objConditional1 = new PHPExcel_Style_Conditional(); $objConditional1->setConditionType(PHPExcel_Style_Conditional::CONDITION_EXPRESSION) ->addCondition('U5>'.$nb_max_char); $objConditional1->getStyle()->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getEndColor()->setARGB(self::$FORMAT_BG_LIGHT_RED); $objConditional1->getStyle()->getFont()->setColor(new PHPExcel_Style_Color(self::$FORMAT_BG_DARK_RED)); $objConditional2 = new PHPExcel_Style_Conditional(); $objConditional2->setConditionType(PHPExcel_Style_Conditional::CONDITION_EXPRESSION) ->addCondition('U5='.$nb_max_char); $objConditional2->getStyle()->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getEndColor()->setARGB(self::$FORMAT_BG_LIGHT_YELLOW); $objConditional2->getStyle()->getFont()->setColor(new PHPExcel_Style_Color(self::$FORMAT_BG_DARK_YELLOW)); $objConditional3 = new PHPExcel_Style_Conditional(); $objConditional3->setConditionType(PHPExcel_Style_Conditional::CONDITION_EXPRESSION) ->addCondition('U5<'.$nb_max_char); $objConditional3->getStyle()->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getEndColor()->setARGB(self::$FORMAT_BG_LIGHT_GREEN); $objConditional3->getStyle()->getFont()->setColor(new PHPExcel_Style_Color(self::$FORMAT_BG_DARK_GREEN)); $conditionalStyles = $this->objPHPExcel->getActiveSheet()->getStyle('U5:U'.$lastLine)->getConditionalStyles(); $conditionalStyles[] = $objConditional1; $conditionalStyles[] = $objConditional2; $conditionalStyles[] = $objConditional3; $this->objPHPExcel->getActiveSheet()->getStyle('U5:U'.$lastLine)->setConditionalStyles($conditionalStyles); //Conditionnal formating for column AJ $objConditional1 = new PHPExcel_Style_Conditional(); $objConditional1->setConditionType(PHPExcel_Style_Conditional::CONDITION_CONTAINSTEXT) ->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_CONTAINSTEXT) ->setText('ATTENTION'); $objConditional1->getStyle()->getFont()->setColor(new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_RED)); $objConditional2 = new PHPExcel_Style_Conditional(); $objConditional2->setConditionType(PHPExcel_Style_Conditional::CONDITION_CONTAINSTEXT) ->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_CONTAINSTEXT) ->setText('COOL'); $objConditional2->getStyle()->getFont()->setColor(new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_GREEN)); $conditionalStyles = $this->objPHPExcel->getActiveSheet()->getStyle('AK5:AK'.$lastLine)->getConditionalStyles(); $conditionalStyles[] = $objConditional1; $conditionalStyles[] = $objConditional2; $this->objPHPExcel->getActiveSheet()->getStyle('AK5:AK'.$lastLine)->setConditionalStyles($conditionalStyles); $this->objPHPExcel->getActiveSheet() ->getStyle('AI5:AI'.$lastLine) ->getNumberFormat() ->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR); $this->objPHPExcel->getActiveSheet() ->getStyle('AJ5:AJ'.$lastLine) ->getNumberFormat() ->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR); $this->objPHPExcel->getActiveSheet() ->getStyle('AL5:AL'.$lastLine) ->getNumberFormat() ->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR); $this->objPHPExcel->getActiveSheet() ->getStyle('AM5:AM'.$lastLine) ->getNumberFormat() ->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR); $this->objPHPExcel->getActiveSheet() ->getStyle('AN5:AN'.$lastLine) ->getNumberFormat() ->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_00); $this->objPHPExcel->getActiveSheet() ->getStyle('AO5:AO'.$lastLine) ->getNumberFormat() ->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE_00); $this->objPHPExcel->getActiveSheet() ->getStyle('AR5:AR'.$lastLine) ->getNumberFormat() ->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR); $this->objPHPExcel->getActiveSheet() ->getStyle('AR5:AR'.$lastLine) ->getAlignment() ->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $this->objPHPExcel->getActiveSheet() ->getStyle('AU5:AU'.$lastLine) ->getNumberFormat() ->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_DDMMYYYY); $this->objPHPExcel->setActiveSheetIndex(1); $this->objPHPExcel->getActiveSheet() ->getStyle('B5:B'.$lastLine) ->getNumberFormat() ->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER); $this->objPHPExcel->setActiveSheetIndex(0); $this->objWriter = PHPExcel_IOFactory::createWriter($this->objPHPExcel, 'Excel2007'); $timer_table[] = 'Excel sheet process done after '.(microtime(true)-$callStartTime); } }