Srv Bebeboutik 6c0978166c add modules
2016-01-04 12:49:26 +01:00

881 lines
36 KiB
PHP
Executable File

<?php
require_once(dirname(__FILE__).'/../../config/config.inc.php');
require_once(dirname(__FILE__).'/../../init.php');
require_once(_PS_MODULE_DIR_.'privatesales/Sale.php');
require_once('AdminPrivateSalesLogistique.php');
require_once dirname(__FILE__).'/classes/SaleStats.php';
set_include_path(get_include_path() . PATH_SEPARATOR . _PS_MODULE_DIR_.'privatesales_logistique/classes/');
include_once('PHPExcel.php');
include_once('PHPExcel/Writer/Excel2007.php');
include_once('PHPExcel/Style/NumberFormat.php');
include_once('PHPExcel/Worksheet/Drawing.php');
include_once('PHPExcel/Style/Alignment.php');
include_once('PHPExcel/Style/Font.php');
$tax = new Tax(1);
$TVA = number_format($tax->rate, 2);
if(Tools::getValue('action') == 'getOrderForm' && ( ( $id_category = Tools::getValue('id', false) ) || ( Validate::isInt(Tools::getValue('id_exportorderform', false)) && Validate::isLoadedObject( $OrderForm = new OrderForm( Tools::getValue('id_exportorderform') ) ) ) ) )
{
$array_service = array(
1, //1 : bon de commande
2, //2 : état des ventes
3, //3 : stats des ventes
);
$lang_id = Tools::getValue('lang', 'fr');
$array_lang = array(
'en' => array(
'Product ID' => 'Product ID',
'EAN' => 'EAN',
'Reference BB' => 'BB Boutik ID',
'Product Name' => 'Product Name',
'Attribute' => 'Size',
'Quantity' => 'Quantity',
'Total quantity' => 'Total quantity',
'Remaining quantity' => 'Remaining Quantity',
'Unit Price' => 'Unit Price',
'Total Amount' => 'Total Amount',
'Purchase order' => 'Purchase order',
'State order' => 'Sales report',
'The number below must be present on each document regarding this order, delivery note, invoice :' => 'The number below must be present on each document regarding this order, delivery note, invoice :',
'PURCHASE ORDER NUMBER' => 'PURCHASE ORDER NUMBER',
'Delivery adress' => 'Delivery address',
'PURCHASE ORDER DATE' => 'PURCHASE ORDER DATE',
'DELIVERY DUTY PAID' => 'DELIVERY DUTY PAID',
'YES' => 'YES',
),
'fr' => array(
'Product ID' => 'Référence',
'EAN' => 'EAN',
'Reference BB' => 'Référence BBB',
'Product Name' => 'Nom du produit',
'Attribute' => 'Déclinaison',
'Quantity' => 'Quantité',
'Total quantity' => 'Stock initial',
'Remaining quantity' => 'Restant',
'Unit Price' => 'PU HT',
'Total Amount' => 'Prix Total HT',
'Purchase order' => 'Bon de commande',
'State order' => 'Etat des ventes',
'YES' => 'OUI',
'PURCHASE ORDER NUMBER' => 'NUMERO DE BON DE COMMANDE',
'Delivery adress' => 'Adresse de livraison',
'PURCHASE ORDER DATE' => 'DATE DU BON DE COMMANDE',
'DELIVERY DUTY PAID' => 'FRANCO DE PORT',
'The number below must be present on each document regarding this order, delivery note, invoice :' => 'Le numéro suivant doit apparaître sur toute la correspondance annexe, les papiers de livraison et les factures :',
)
);
$lang = $array_lang[$lang_id];
if(!Tools::getValue('type') || !in_array( ($type = Tools::getValue('type')), $array_service ))
die('Vous devez saisir un type valide');
$test = (bool) ( Tools::getValue('test', false) );
if(!Validate::isLoadedObject($OrderForm))
{
$loaded = false;
if(Tools::getValue('last') !== false)
{
$date = OrderForm::getLastByCategory($id_category);
$date_from = new DateManager($date);
$date_from->updateDate(1);
$date_to = new DateManager(date('Y-m-d H:i:s'));
}
else
{
$date_from = new DateManager(Tools::getValue('from'));
$date_to = new DateManager(Tools::getValue('to'));
}
if($type == 1)
{
if(!Validate::isDate($date_from->getDate('SQL')) || !Validate::isDate($date_to->getDate('SQL')))
die('Une des deux dates est invalide');
$OrderForm = new OrderForm();
$OrderForm->from = $date_from->getDate('SQL');
$OrderForm->to = $date_to->getDate('SQL');
$OrderForm->id_category = $id_category;
$OrderForm->save();
}
}
else
{
$date_from = new DateManager($OrderForm->from);
$date_to = new DateManager($OrderForm->to);
$id_category = $OrderForm->id_category;
$loaded = true;
}
$date_from->setLangue(strtoupper($lang_id));
$date_to->setLangue(strtoupper($lang_id));
if(!Validate::isDate($date_from->getDate('SQL')) || !Validate::isDate($date_to->getDate('SQL')))
die('Une des deux dates est invalide');
$date_to_sql = $date_to;
$sale = Sale::getSaleFromCategory($id_category);
$category = new Category($id_category, $cookie->id_lang);
$products = MakeStats::getProductsByCat($id_category);
$lines = array();
$array_product = array();
if($type == 1 || $type == 2 || $type == 3) {
$arrayProduct = array();
foreach($products as $product)
$array_product[$product['id_product']] = $arrayProduct[$product['id_product']] = new Product($product['id_product']);
$order_states = explode(',', Configuration::get('PS_IT_OF_ORDER_STATES'));
$lines = MakeStats::getOrdersByIdsProduct(array_keys($arrayProduct), $order_states, $date_from->getDate('SQL'), $date_to->getDate('SQL'));
// for stats
$lines_tmp = $lines;
$lines = MakeStats::getArrayLines($lines);
} else {
die("Type d'export invalide");
}
if ($type == 3) {
$stats = new SaleStats($sale, $category);
$stats->loadData();
$total_sale_product = array();
$total_bdc_ht = 0;
foreach ($lines_tmp as $key => $order_line) {
$id_product = $order_line['product_id'];
$id_product_attribute = $order_line['product_attribute_id'];
$current_product = $array_product[$id_product];
if($id_product_attribute != 0) {
$combination = new Combination($id_product_attribute);
if($combination->wholesale_price == 0) {
$wholesale_price = $current_product->wholesale_price;
} else {
$wholesale_price = $combination->wholesale_price;
}
} else {
$wholesale_price = $current_product->wholesale_price;
}
$quantity_to_cmd = $order_line['product_quantity'] - $order_line['product_quantity_reinjected'];
$total_sale_ht += $quantity_to_cmd * $wholesale_price;
if (!is_array($total_sale_product[(int)$id_product.'-'.(int) $id_product_attribute]) ){
$total_sale_product[(int)$id_product.'-'.(int) $id_product_attribute] = array();
$total_sale_product[(int)$id_product.'-'.(int) $id_product_attribute]['total_ht'] = 0;
$total_sale_product[(int)$id_product.'-'.(int) $id_product_attribute]['quantiy'] = 0;
$total_sale_product[(int)$id_product.'-'.(int) $id_product_attribute]['name'] = $current_product->name[2];
}
$price_ht = $current_product->getPrice(false, $id_product_attribute, 2);
$price_ttc = $current_product->getPrice(true, $id_product_attribute, 2);
$total_sale_product[(int)$id_product.'-'.(int) $id_product_attribute]['total_ht'] += $price_ht;
$total_sale_product[(int)$id_product.'-'.(int) $id_product_attribute]['quantiy'] += $quantity_to_cmd;
}
$stats->addToStats('total_bdc_ht', $total_sale_ht);
$bestsales = MakeStats::orderMultiArray($total_sale_product, 'total_ht');
$bestsales_extract = array_slice($bestsales, 0, 3);
$i = 1;
foreach ($bestsales_extract as $key => $bestsalesProduct) {
$stats->addToStats('bestsale_'.$i.'_product', $bestsalesProduct['name']);
$stats->addToStats('bestsale_'.$i.'_quantity', $bestsalesProduct['quantiy']);
$stats->addToStats('bestsale_'.$i.'_ca', $bestsalesProduct['total_ht']);
$i++;
}
$stats->loadDataForSubCategory();
// export
$stats->export();
die;
}
if(count($lines) == 0)
die ("Aucune vente pour cette vente privée");
// $authorized_ip = array(
// '80.13.158.176',
// '88.120.248.124'
// );
// if(in_array($_SERVER['REMOTE_ADDR'], $authorized_ip))
// {
// p($lines);
// die;
// }
$arrayTmp = array();
foreach($lines as $id_product => $arrayProduct)
{
foreach($arrayProduct as $id_product_attribute => $values)
{
$arrayTmp[$values['line']['product_id']][$values['line']['product_attribute_id']] = $values;
}
}
// associate position
$arrayTmp2 = array();
foreach ($products as $key => $product_order) {
$arrayTmp2[] = $arrayTmp[$product_order['id_product']];
}
// $lines2 = $arrayTmp;
$lines2 = $arrayTmp2;
// ksort($lines2);
$have_declinaison = false;
foreach($lines2 as $lines_attributes)
{
foreach($lines_attributes as $values)
{
if($values['line']['product_attribute_name_base'] != '') {
$have_declinaison = true;
break 2;
}
}
}
switch($type)
{
case '1':
$title = $lang['Purchase order'].' '. $category->name .' - Bébé Boutik '. $date_from->getNomMois() .' '.$date_from->getAnnee();
break;
case '2':
$extrafields = Category::getSalesInfos(array((int)$category->id_category));
$title = $lang['State order'] .' '. $category->name . ' - ' . $extrafields[(int)$category->id_category]['sales'][1];
break;
}
$firstColumn = 'A';
if($have_declinaison === true)
{
if ($type == 1) {
$lastColumn = 'H';
} else {
$lastColumn = 'J';
}
$letter_bdc_title = 'C';
$letter_end_address = 'B';
$letter_date = 'C';
$letter_franco = 'D';
$letter_condition = 'E';
$letter_product_ean = 'B';
$letter_product_ref_interne = 'C';
$letter_product_name = 'D';
$letter_product_attribute_name = 'E';
$letter_product_qty = 'F';
if ($type == 1) {
$letter_product_ht = 'G';
$letter_product_total = 'H';
} else {
$letter_product_total_qty = 'G';
$letter_product_remaining_qty = 'H';
$letter_product_ht = 'I';
$letter_product_total = 'J';
}
}
else
{
if ($type == 1) {
$lastColumn = 'G';
} else {
$lastColumn = 'I';
}
$letter_bdc_title = 'C';
$letter_end_address = 'B';
$letter_date = 'C';
$letter_franco = 'D';
$letter_condition = 'E';
$letter_product_ean = 'B';
$letter_product_ref_interne = 'C';
$letter_product_name = 'D';
// $letter_product_attribute_name = 'C';
$letter_product_qty = 'E';
if ($type == 1) {
$letter_product_ht = 'F';
$letter_product_total = 'G';
} else {
$letter_product_total_qty = 'F';
$letter_product_remaining_qty = 'G';
$letter_product_ht = 'H';
$letter_product_total = 'I';
}
}
// if($loaded === true)
// {
// header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
// header('Content-Disposition: attachment;filename="'.$title.'.xlsx"');
// echo file_get_contents($OrderForm->getFile());
// exit;
// }
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setCreator("Antadis");
$objPHPExcel->getProperties()->setTitle( $title );
$objPHPExcel->getProperties()->setSubject( $title );
$objPHPExcel->getProperties()->setDescription( $title );
$objPHPExcel->getActiveSheet()->getStyle($firstColumn.'1:'.$lastColumn.'300')->getFont()->setSize(10);
$objPHPExcel->getActiveSheet()->getStyle($firstColumn.'1:'.$lastColumn.'300')->getFont()->setName('calibri');
// $objPHPExcel->getFont()->setSize(10);
// $objPHPExcel->getFont()->setName('Colibri');
$arrayBorder = array(
'borders' => array(
'allborders' => array(
'style' => PHPExcel_Style_Border::BORDER_THIN,
'color' => array(
'rgb' => '000000'
)
)
)
);
$arrayBorderAutour = array(
'borders' => array(
'left' => array(
'style' => PHPExcel_Style_Border::BORDER_THIN,
),
'right' => array(
'style' => PHPExcel_Style_Border::BORDER_THIN,
),
'bottom' => array(
'style' => PHPExcel_Style_Border::BORDER_THIN,
),
'top' => array(
'style' => PHPExcel_Style_Border::BORDER_THIN,
)
)
);
$arrayConfig = array(
'PS_IT_OF_ORGANISATION_'.$lang_id,
'PS_IT_OF_ADDRESS_'.$lang_id,
'PS_IT_OF_ADDRESS_2_'.$lang_id,
'PS_IT_OF_CP_CITY_'.$lang_id,
'PS_IT_OF_NUMBER_PHONE_'.$lang_id
);
if(!Configuration::get('PS_IT_OF_ADDRESS_2_'.$lang_id))
unset($arrayConfig[array_search('PS_IT_OF_ADDRESS_2_'.$lang_id, $arrayConfig)]);
$activeSheet = $objPHPExcel->getActiveSheet();
$i = 1;
if($type == 1)
{
//LOGO
// $activeSheet->getRowDimension($i)->setRowHeight(80);
// $objDrawing = new PHPExcel_Worksheet_Drawing();
// $objDrawing->setWorksheet($activeSheet);
// $objDrawing->setName("name");
// $objDrawing->setDescription("Description");
// $objDrawing->setPath(_PS_IMG_DIR_.'logo.jpg');
// $objDrawing->setCoordinates($firstColumn.$i);
// $objDrawing->setOffsetX(1);
// $objDrawing->setOffsetY(5);
//ADRESSE DE LIVRAISON
// $activeSheet->SetCellValue($firstColumn.$i, 'Adresse de livraison : ');
// $activeSheet->getStyle($firstColumn.$i)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_TOP);
// $activeSheet->getStyle($firstColumn.$i)->getFont()->setBold(true);
// $activeSheet->getStyle($firstColumn.$i)->getFont()->setSize(12);
// $activeSheet->getStyle($firstColumn.$i)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
// $styleArray = array(
// 'font' => array(
// 'underline' => PHPExcel_Style_Font::UNDERLINE_SINGLE
// )
// );
// $activeSheet->getStyle($firstColumn.$i)->applyFromArray($styleArray);
// $objPHPExcel->getActiveSheet()->getStyle('A1')->applyFromArray($styleArray);
$iOri = $i;
foreach($arrayConfig as $k => $cfg)
{
$activeSheet->SetCellValue($firstColumn.$i, Configuration::get($cfg) );
$activeSheet->getStyle($firstColumn.$i)->getFont()->setSize(10);
$activeSheet->getStyle($firstColumn.$i)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
$activeSheet->mergeCells($firstColumn.$i.':'.$letter_end_address.$i );
if($k == 0)
{
$activeSheet->getStyle($firstColumn.$i)->getFont()->setBold(true);
$i++;
$activeSheet->SetCellValue($firstColumn.$i, Configuration::get('PS_IT_OF_SLOGAN_'.$lang_id) );
$activeSheet->getStyle($firstColumn.$i)->getFont()->setSize(10);
$activeSheet->getStyle($firstColumn.$i)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
$activeSheet->mergeCells($firstColumn.$i.':'.$letter_end_address.$i );
$i++;
}
$i++;
}
$activeSheet->SetCellValue($firstColumn.$i, Configuration::get('PS_IT_OF_EMAIL_'.$lang_id) );
$activeSheet->getStyle($firstColumn.$i)->getFont()->setSize(10);
$activeSheet->getStyle($firstColumn.$i)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
$activeSheet->mergeCells($firstColumn.$i.':'.$letter_end_address.$i );
$i++;
$activeSheet->SetCellValue($firstColumn.$i, Configuration::get('PS_IT_OF_TVA_'.$lang_id) );
$activeSheet->getStyle($firstColumn.$i)->getFont()->setSize(10);
$activeSheet->getStyle($firstColumn.$i)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
$activeSheet->mergeCells($firstColumn.$i.':'.$letter_end_address.$i );
$i++;
//BON DE COMMANDE
$activeSheet->getCell($letter_bdc_title.$iOri)->setValue($lang['Purchase order'].' '.chr(13).' '.$category->name);
$activeSheet->getStyle($letter_bdc_title.$iOri)->getAlignment()->setWrapText(true);
$activeSheet->getStyle($letter_bdc_title.$iOri)->getFont()->setBold(true);
$activeSheet->getStyle($letter_bdc_title.$iOri)->getFont()->setSize(18);
$activeSheet->getStyle($letter_bdc_title.$iOri)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
$activeSheet->getStyle($letter_bdc_title.$iOri)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$activeSheet->mergeCells($letter_bdc_title.$iOri.':'.$lastColumn.($i-1));
// $activeSheet->getStyle($firstColumn.($iOri).':'.$lastColumn.($i-1))->applyFromArray($arrayBorderAutour);
$i++;
//TEXTE
$activeSheet->SetCellValue($firstColumn.$i, $lang['The number below must be present on each document regarding this order, delivery note, invoice :']);
$activeSheet->mergeCells($firstColumn.$i.':'.$letter_end_address.$i );
$activeSheet->getStyle($firstColumn.$i)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_JUSTIFY);
$activeSheet->getRowDimension($i)->setRowHeight(30);
$i++;
$activeSheet->SetCellValue($firstColumn.$i, $lang['PURCHASE ORDER NUMBER'] . ' : '. $OrderForm->id);
$activeSheet->getStyle($firstColumn.$i)->getFont()->setSize(10);
// $activeSheet->getStyle($firstColumn.$i)->getFont()->getColor()->setRGB('FF0000');
$activeSheet->getStyle($firstColumn.$i)->getFont()->setBold(true);
$activeSheet->getStyle($firstColumn.$i)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_JUSTIFY);
$activeSheet->mergeCells($firstColumn.$i.':'.$letter_end_address.$i );
$i++;
//ADRESSE DE LIVRAISON BIS
$letter = 'D';
$activeSheet->SetCellValue($letter.$i, $lang['Delivery adress'].' :');
$activeSheet->getStyle($letter.$i)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_TOP);
$activeSheet->getStyle($letter.$i)->getFont()->setBold(true);
$activeSheet->getStyle($letter.$i)->getFont()->setSize(12);
$activeSheet->getStyle($letter.$i)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
// $styleArray = array(
// 'font' => array(
// 'underline' => PHPExcel_Style_Font::UNDERLINE_SINGLE
// )
// );
// $activeSheet->getStyle($letter.$i)->applyFromArray($styleArray);
$activeSheet->mergeCells($letter.$i.':'.$lastColumn.$i );
$i++;
$iOri = $i;
foreach($arrayConfig as $cfg)
{
$activeSheet->SetCellValue($letter.$i, Configuration::get($cfg) );
$activeSheet->getStyle($letter.$i)->getFont()->setSize(10);
$activeSheet->mergeCells($letter.$i.':'.$lastColumn.$i );
$activeSheet->getStyle($letter.$i)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
$i++;
}
$i++;
$activeSheet->SetCellValue($letter_date.$i, $lang['PURCHASE ORDER DATE'] );
$activeSheet->SetCellValue($letter_franco.$i, $lang['DELIVERY DUTY PAID'] );
$activeSheet->SetCellValue($letter_condition.$i, 'CONDITIONS' );
$activeSheet->getStyle($letter_date.$i.':'.$letter_condition.$i)->getFont()->setBold(true);
$activeSheet->getStyle($letter_date.$i.':'.$letter_condition.$i)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_JUSTIFY);
$activeSheet->getStyle($letter_date.$i.':'.$letter_condition.$i)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$i ++;
$activeSheet->SetCellValue($letter_date.$i, date('d/m/Y'));
$activeSheet->SetCellValue($letter_franco.$i, $lang['YES'] );
$activeSheet->SetCellValue($letter_condition.$i, 'N/A' );
$activeSheet->getStyle($letter_date.($i-1).':'.$letter_condition.$i)->applyFromArray($arrayBorderAutour);
$activeSheet->getStyle($letter_date.$i.':'.$letter_condition.$i)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$i ++;
if(isset(Sale::$otherVar))
{
$iOriSaleVar = $i;
$value = '';
/*$activeSheet->SetCellValue($firstColumn.$i, 'Fournisseur : ');
$activeSheet->getStyle($firstColumn.$i)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_TOP);
$activeSheet->getStyle($firstColumn.$i)->getFont()->setBold(true);
$activeSheet->getStyle($firstColumn.$i)->getFont()->setSize(13);
$activeSheet->getStyle($firstColumn.$i)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);*/
$p = 0;
foreach(Sale::$otherVar as $var)
if(!empty($sale->$var))
{
$value = $sale->$var;
$activeSheet->getCell($firstColumn.$i)->setValue($value);
if($var == 'supplier_name')
{
$activeSheet->getStyle($firstColumn.$i)->getFont()->setSize(14);
$activeSheet->getStyle($firstColumn.$i)->getFont()->setBold(true);
$activeSheet->getRowDimension($i)->setRowHeight(20);
}
$activeSheet->getStyle($firstColumn.$i)->getAlignment()->setWrapText(true);
$activeSheet->getStyle($firstColumn.$i)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_TOP);
$activeSheet->mergeCells($firstColumn.$i.':F'.$i);
$i++;
$p++;
}
if($p == 0)
{
$activeSheet->getCell($firstColumn.$i)->setValue('Aucune information fournisseur');
$activeSheet->getStyle($firstColumn.$i)->getAlignment()->setWrapText(true);
$activeSheet->getStyle($firstColumn.$i)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_TOP);
$activeSheet->mergeCells($firstColumn.$i.':F'.$i);
$i++;
}
$activeSheet->getStyle($firstColumn.($i-1))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$activeSheet->getStyle($firstColumn.($i-1).':'.$lastColumn.($i-1))->applyFromArray($arrayBorderAutour);
if($iOriSaleVar != $i)
$activeSheet->mergeCells($firstColumn.$iOriSaleVar.':'.$firstColumn.($i-1) );
// if(!empty($value))
// {
// $activeSheet->getCell('C'.$i)->setValue($value);
// $activeSheet->getStyle('C'.$i)->getFont()->setSize(13);
// $activeSheet->getStyle('C'.$i)->getAlignment()->setWrapText(true);
// $activeSheet->getStyle('C'.$i)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_TOP);
// $activeSheet->mergeCells('C'.$i.':F'.$i);
// $activeSheet->getRowDimension($i)->setRowHeight(90);
// $i++;
// }
}
$i ++;
}
$activeSheet->SetCellValue($firstColumn.$i, $lang['Product ID']);
$activeSheet->SetCellValue($letter_product_ean.$i, $lang['EAN']);
$activeSheet->SetCellValue($letter_product_ref_interne.$i, $lang['Reference BB']);
//$activeSheet->getStyle('E'.$i)->getBorders()->setBold(true);
$activeSheet->SetCellValue($letter_product_name.$i, $lang['Product Name']);
if($have_declinaison === true)
$activeSheet->SetCellValue($letter_product_attribute_name.$i, $lang['Attribute']);
$activeSheet->SetCellValue($letter_product_qty.$i, $lang['Quantity']);
$activeSheet->getStyle($letter_product_qty.$i)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
if ($type == 2) {
$activeSheet->SetCellValue($letter_product_total_qty.$i, $lang['Total quantity']);
$activeSheet->getStyle($letter_product_total_qty.$i)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$activeSheet->SetCellValue($letter_product_remaining_qty.$i, $lang['Remaining quantity']);
$activeSheet->getStyle($letter_product_remaining_qty.$i)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
}
$activeSheet->setCellValue($letter_product_ht.$i, $lang['Unit Price']);
$activeSheet->getStyle($letter_product_ht.$i)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$activeSheet->setCellValue($letter_product_total.$i, $lang['Total Amount']);
$activeSheet->getStyle($letter_product_total.$i)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$i++;
$iOri = $i;
//p(count($lines));
$count = 0;
if($type == 1 || $type == 2)
foreach($lines as $line)
foreach($line as $l)
$count += $l['total'];
switch($type)
{
case '2':
foreach($lines2 as $lines_attributes)
{
foreach($lines_attributes as $values)
{
$id_product_attribute = $values['line']['product_attribute_id'];
$id_product = $values['line']['product_id'];
$current_product = $array_product[$id_product];
if($id_product_attribute != 0)
{
$combination = new Combination($id_product_attribute);
if($combination->wholesale_price == 0)
$wholesale_price = $current_product->wholesale_price;
else
$wholesale_price = $combination->wholesale_price;
}
else
{
$wholesale_price = $current_product->wholesale_price;
}
$activeSheet->SetCellValue($firstColumn.$i, $values['line']['product_supplier_reference']);
$activeSheet->getStyle($firstColumn.$i)->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_TEXT );
$activeSheet->SetCellValue($letter_product_ean.$i, $values['line']['product_ean13']);
$activeSheet->getStyle($letter_product_ean)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER);
$activeSheet->getStyle($letter_product_ean.$i)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER);
$activeSheet->getStyle($letter_product_ean.$i)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
$activeSheet->SetCellValue($letter_product_ref_interne.$i, $values['line']['product_reference']);
$activeSheet->SetCellValue($letter_product_name.$i, $values['line']['product_name_base']);
if($have_declinaison === true)
$activeSheet->SetCellValue($letter_product_attribute_name.$i, $values['line']['product_attribute_name_base']);
$activeSheet->SetCellValue($letter_product_qty.$i, $values['total']);
$activeSheet->getStyle($letter_product_qty.$i)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$activeSheet->SetCellValue($letter_product_total_qty.$i, ($values['line']['product_quantity']+$values['total']));
$activeSheet->getStyle($letter_product_total_qty.$i)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$activeSheet->SetCellValue($letter_product_remaining_qty.$i, $values['line']['product_quantity']);
$activeSheet->getStyle($letter_product_remaining_qty.$i)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$activeSheet->setCellValue($letter_product_ht.$i, (float)$wholesale_price );
$activeSheet->setCellValue($letter_product_total.$i, '='.$letter_product_qty.$i.'*'.$letter_product_ht.$i);
$activeSheet->getStyle($letter_product_ht.$i)->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR );
$activeSheet->getStyle($letter_product_total.$i)->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR );
$i++;
}
}
break;
case '1':
foreach($lines2 as $lines_attributes)
{
foreach($lines_attributes as $values)
{
$id_product_attribute = $values['line']['product_attribute_id'];
$id_product = $values['line']['product_id'];
$current_product = $array_product[$id_product];
if($id_product_attribute != 0)
{
$combination = new Combination($id_product_attribute);
if($combination->wholesale_price == 0)
$wholesale_price = $current_product->wholesale_price;
else
$wholesale_price = $combination->wholesale_price;
}
else
{
$wholesale_price = $current_product->wholesale_price;
}
$activeSheet->SetCellValue($firstColumn.$i, $values['line']['product_supplier_reference']);
$activeSheet->getStyle($firstColumn.$i)->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_TEXT );
$activeSheet->SetCellValue($letter_product_ean.$i, $values['line']['product_ean13']);
$activeSheet->getStyle($letter_product_ean)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER);
$activeSheet->getStyle($letter_product_ean.$i)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER);
$activeSheet->getStyle($letter_product_ean.$i)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
$activeSheet->SetCellValue($letter_product_ref_interne.$i, $values['line']['product_reference']);
$activeSheet->SetCellValue($letter_product_name.$i, $values['line']['product_name_base']);
if($have_declinaison === true)
$activeSheet->SetCellValue($letter_product_attribute_name.$i, $values['line']['product_attribute_name_base']);
$activeSheet->SetCellValue($letter_product_qty.$i, $values['total']);
$activeSheet->getStyle($letter_product_qty.$i)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$activeSheet->setCellValue($letter_product_ht.$i, (float)$wholesale_price );
$activeSheet->setCellValue($letter_product_total.$i, '='.$letter_product_qty.$i.'*'.$letter_product_ht.$i);
$activeSheet->getStyle($letter_product_ht.$i)->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR );
$activeSheet->getStyle($letter_product_total.$i)->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR );
$i++;
}
}
break;
}
$activeSheet->SetCellValue($firstColumn.$i, $lang['Quantity']);
$activeSheet->getStyle($firstColumn.$i)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
$activeSheet->getStyle($firstColumn.$i)->getFont()->setBold(true);
$activeSheet->SetCellValue($letter_product_qty.$i, '=SUM('.$letter_product_qty.($iOri).':'.$letter_product_qty.($i-1).')');
$activeSheet->getStyle($letter_product_qty.$i)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$activeSheet->getStyle($letter_product_qty.$i)->getFont()->setBold(true);
if ($type == 2) {
$activeSheet->SetCellValue($letter_product_total_qty.$i, '=SUM('.$letter_product_total_qty.($iOri).':'.$letter_product_total_qty.($i-1).')');
$activeSheet->getStyle($letter_product_total_qty.$i)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$activeSheet->getStyle($letter_product_total_qty.$i)->getFont()->setBold(true);
$activeSheet->SetCellValue($letter_product_remaining_qty.$i, '=SUM('.$letter_product_remaining_qty.($iOri).':'.$letter_product_remaining_qty.($i-1).')');
$activeSheet->getStyle($letter_product_remaining_qty.$i)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$activeSheet->getStyle($letter_product_remaining_qty.$i)->getFont()->setBold(true);
}
$activeSheet->getStyle($firstColumn.($iOri-1).':'.$lastColumn.$i)->applyFromArray($arrayBorder);
$i++;
$activeSheet->setCellValue($letter_product_ht.$i, $lang['Total Amount']);
$activeSheet->getStyle($letter_product_ht.$i)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
if($type == 1)
$activeSheet->getStyle($letter_product_ht.$i)->getFont()->setBold(true);
$activeSheet->setCellValue($letter_product_total.$i, '=SUM('.$letter_product_total.($iOri).':'.$letter_product_total.($i-2).')');
$activeSheet->getStyle($letter_product_total.$i)->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR );
if($lang_id != 'en')
{
$i++;
$activeSheet->setCellValue($letter_product_ht.$i, 'TVA '.$TVA);
$activeSheet->getStyle($letter_product_ht.$i)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
if($type == 1)
$activeSheet->getStyle($letter_product_ht.$i)->getFont()->setBold(true);
$activeSheet->setCellValue($letter_product_total.$i, '='.$letter_product_total.($i-1).'*'.($TVA/100) );
$activeSheet->getStyle($letter_product_total.$i)->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR );
$i++;
$activeSheet->setCellValue($letter_product_ht.$i, 'TOTAL TTC');
$activeSheet->getStyle($letter_product_ht.$i)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
$activeSheet->getStyle($letter_product_ht.$i)->getFont()->setBold(true);
$activeSheet->setCellValue($letter_product_total.$i, '='.$letter_product_total.($i-1).'+'.$letter_product_total.($i-2) );
$activeSheet->getStyle($letter_product_total.$i)->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR );
$activeSheet->getStyle($letter_product_total.$i)->getFont()->setBold(true);
$activeSheet->getStyle($letter_product_ht.($i-3).':'.$lastColumn.$i)->applyFromArray($arrayBorder);
}
else
{
$activeSheet->getStyle($letter_product_ht.($i-1).':'.$lastColumn.$i)->applyFromArray($arrayBorder);
}
if($type == 1)
{
$value = Configuration::get('PS_IT_OF_BAS_PAGE_'.$lang_id);
if($value != '')
{
$i++;
$value = str_replace('<br />', ' ' , nl2br($value));
$activeSheet->setCellValue($firstColumn.$i, $value);
$activeSheet->mergeCells($firstColumn.$i.':'.$lastColumn.$i );
$activeSheet->getRowDimension($i)->setRowHeight(80);
$activeSheet->getStyle($firstColumn.$i)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_TOP);
$activeSheet->getStyle($firstColumn.$i)->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_TEXT );
$activeSheet->getStyle($firstColumn.$i)->getAlignment()->setWrapText(true);
}
$value = Configuration::get('PS_IT_OF_BAS_PAGE_BIS_'.$lang_id);
if($value != '')
{
$i++;
$value = str_replace('<br />', ' ' , nl2br($value));
$activeSheet->setCellValue($firstColumn.$i, $value);
$activeSheet->mergeCells($firstColumn.$i.':'.$lastColumn.$i );
$activeSheet->getRowDimension($i)->setRowHeight(80);
$activeSheet->getStyle($firstColumn.$i)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_TOP);
$activeSheet->getStyle($firstColumn.$i)->getAlignment()->setWrapText(true);
$activeSheet->getStyle($firstColumn.$i)->getFont()->getColor()->setRGB('FF0000');
$activeSheet->getStyle($firstColumn.$i)->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_TEXT );
}
}
$activeSheet->getColumnDimension($firstColumn)->setWidth(25);
$activeSheet->getColumnDimension($letter_product_ean)->setWidth(25);
$activeSheet->getColumnDimension($letter_product_ref_interne)->setWidth(25);
$activeSheet->getColumnDimension($letter_product_qty)->setWidth(18);
$activeSheet->getColumnDimension($letter_product_name)->setWidth(40);
if($have_declinaison === true)
$activeSheet->getColumnDimension($letter_product_attribute_name)->setWidth(20);
$activeSheet->getColumnDimension($letter_product_qty)->setWidth(13);
if ($type == 2) {
$activeSheet->getColumnDimension($letter_product_total_qty)->setWidth(13);
$activeSheet->getColumnDimension($letter_product_remaining_qty)->setWidth(13);
}
$activeSheet->getColumnDimension($letter_product_ht)->setWidth(13);
$activeSheet->getColumnDimension($letter_product_total)->setWidth(13);
$i++;
$activeSheet->setCellValue($firstColumn.$i, '');
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="'.$title.'.xlsx"');
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
if($type == 1 &&
Validate::isLoadedObject($OrderForm))
{
$objWriter->save($OrderForm->getFile());
echo file_get_contents($OrderForm->getFile());
}
else
{
$objWriter->save('php://output');
}
exit;
}