Merge branch 'ticket-14436-excel-format' into develop
This commit is contained in:
commit
b98a8c9d4a
@ -484,13 +484,14 @@ class AdminAntWp extends AdminTab
|
|||||||
$params['lines'] = $products;
|
$params['lines'] = $products;
|
||||||
if(!empty($params['lines'])){
|
if(!empty($params['lines'])){
|
||||||
$wp = new GenerateWp();
|
$wp = new GenerateWp();
|
||||||
|
$wp->excludedProducts = $exclude_ids;
|
||||||
$wp->generate($params, $timer_table, $callStartTime);
|
$wp->generate($params, $timer_table, $callStartTime);
|
||||||
$filename = str_replace(' ', '_', $filename);
|
$filename = str_replace(' ', '_', $filename);
|
||||||
$wp->objWriter->save(__DIR__ .'/'.$filename.'.xlsx');
|
$wp->objWriter->save(__DIR__ .'/'.$filename.'.xlsx');
|
||||||
$timer_table_formatted = implode('<br>', $timer_table);
|
$timer_table_formatted = implode('<br>', $timer_table);
|
||||||
$duplicated_formatted = '';
|
$duplicated_formatted = '';
|
||||||
if (!empty($this->report[self::DUPLICATED_REFS])) {
|
if (!empty($this->report[self::DUPLICATED_REFS])) {
|
||||||
$duplicated_formatted = '<hr>Duplications de Reférences<br><p style="color:darkred">' . implode('<br>', $this->report[self::DUPLICATED_REFS]). '</p>';
|
$duplicated_formatted = '<hr>Duplications de Références<br><p style="color:darkred">' . implode('<br>', $this->report[self::DUPLICATED_REFS]). '</p>';
|
||||||
}
|
}
|
||||||
if (!empty($this->report[self::DUPLICATED_REFS_AND_EAN])) {
|
if (!empty($this->report[self::DUPLICATED_REFS_AND_EAN])) {
|
||||||
$duplicated_formatted .= '<hr>Duplications d\'EANs<br><p style="color:darkred">' . implode('<br>', $this->report[self::DUPLICATED_REFS_AND_EAN]) . '</p>';
|
$duplicated_formatted .= '<hr>Duplications d\'EANs<br><p style="color:darkred">' . implode('<br>', $this->report[self::DUPLICATED_REFS_AND_EAN]) . '</p>';
|
||||||
|
@ -6,6 +6,7 @@ class GenerateWp
|
|||||||
public $objWriter;
|
public $objWriter;
|
||||||
public $columns;
|
public $columns;
|
||||||
public $columns_es;
|
public $columns_es;
|
||||||
|
public $excludedProducts;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
@ -72,6 +73,7 @@ class GenerateWp
|
|||||||
'AS' => 'Custom code',
|
'AS' => 'Custom code',
|
||||||
'AT' => 'Pays de fabrication',
|
'AT' => 'Pays de fabrication',
|
||||||
'AU' => 'Date de la vente');
|
'AU' => 'Date de la vente');
|
||||||
|
$this->excludedProducts = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static $FORMAT_DARK_BLUE = '214A7B';
|
public static $FORMAT_DARK_BLUE = '214A7B';
|
||||||
@ -380,7 +382,7 @@ class GenerateWp
|
|||||||
https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-11.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.'&"-12.jpg,
|
||||||
https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-13.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,
|
IF(R'.$i.'=15,"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.'&"-1.jpg,
|
||||||
https://static.bebeboutik.com/img_import/"&AP1&"/"&D'.$i.'&"-2.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.'&"-3.jpg,
|
||||||
@ -442,35 +444,19 @@ class GenerateWp
|
|||||||
}
|
}
|
||||||
$price = Product::getPriceStatic($row['id_product'],TRUE, NULL, 2, NULL, FALSE, FALSE);
|
$price = Product::getPriceStatic($row['id_product'],TRUE, NULL, 2, NULL, FALSE, FALSE);
|
||||||
$price2 = Product::getPriceStatic($row['id_product'],TRUE, NULL, 2);
|
$price2 = Product::getPriceStatic($row['id_product'],TRUE, NULL, 2);
|
||||||
if(isset($row['id_product_attribute'])){
|
if(isset($row['ean']) && trim($row['ean']) !== ''){
|
||||||
$quantity_sold = (int) Db::getInstance()->getValue('
|
$best_sales = Product::getBestSales(array('ean'=>$row['ean']), $this->excludedProducts, true);
|
||||||
SELECT SUM(d.`product_quantity` - d.`product_quantity_reinjected`)
|
}elseif(isset($row['supplier_ref']) && trim($row['supplier_ref']) !== ''){
|
||||||
FROM `'._DB_PREFIX_.'order_detail` d
|
$best_sales = Product::getBestSales(array('ean'=>$row['supplier_ref']), $this->excludedProducts, true);
|
||||||
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){
|
if(count($best_sales) > 0){
|
||||||
|
$quantity_sold = $best_sales[0]['quantity_sold'];
|
||||||
|
$total_revenue = Tools::ps_round($quantity_sold * $row['wholesale_price'], 2);
|
||||||
|
}else{
|
||||||
$quantity_sold = '';
|
$quantity_sold = '';
|
||||||
$total_revenue = '';
|
$total_revenue = '';
|
||||||
}else{
|
|
||||||
$total_revenue = Tools::ps_round(($quantity_sold * $row['wholesale_price']),2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$this->objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$i, (String)$row['ean'])
|
$this->objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$i, (String)$row['ean'])
|
||||||
->setCellValue('C'.$i, (String)$row['supplier_ref'])
|
->setCellValue('C'.$i, (String)$row['supplier_ref'])
|
||||||
->setCellValue('D'.$i, (String)$row['supplier_reference'])
|
->setCellValue('D'.$i, (String)$row['supplier_reference'])
|
||||||
@ -677,8 +663,8 @@ class GenerateWp
|
|||||||
$this->objPHPExcel->getActiveSheet()
|
$this->objPHPExcel->getActiveSheet()
|
||||||
->getStyle('AM5:AM' . $lastLine)
|
->getStyle('AM5:AM' . $lastLine)
|
||||||
->getFont()->setBold(true);
|
->getFont()->setBold(true);
|
||||||
//Conditionnal formating for column L
|
//Conditionnal formating for column M
|
||||||
$nb_max_char = 64;
|
$nb_max_char = 50;
|
||||||
$objConditional1 = new PHPExcel_Style_Conditional();
|
$objConditional1 = new PHPExcel_Style_Conditional();
|
||||||
$objConditional1->setConditionType(PHPExcel_Style_Conditional::CONDITION_EXPRESSION)
|
$objConditional1->setConditionType(PHPExcel_Style_Conditional::CONDITION_EXPRESSION)
|
||||||
->addCondition('M5>'.$nb_max_char);
|
->addCondition('M5>'.$nb_max_char);
|
||||||
@ -702,7 +688,7 @@ class GenerateWp
|
|||||||
$this->objPHPExcel->getActiveSheet()->getStyle('M5:M'.$lastLine)->setConditionalStyles($conditionalStyles);
|
$this->objPHPExcel->getActiveSheet()->getStyle('M5:M'.$lastLine)->setConditionalStyles($conditionalStyles);
|
||||||
|
|
||||||
$nb_max_char = 17;
|
$nb_max_char = 17;
|
||||||
//Conditionnal formating for column T
|
//Conditionnal formating for column U
|
||||||
$objConditional1 = new PHPExcel_Style_Conditional();
|
$objConditional1 = new PHPExcel_Style_Conditional();
|
||||||
$objConditional1->setConditionType(PHPExcel_Style_Conditional::CONDITION_EXPRESSION)
|
$objConditional1->setConditionType(PHPExcel_Style_Conditional::CONDITION_EXPRESSION)
|
||||||
->addCondition('U5>'.$nb_max_char);
|
->addCondition('U5>'.$nb_max_char);
|
||||||
|
@ -307,4 +307,84 @@ class Product extends ProductCore
|
|||||||
|
|
||||||
return $quantity;
|
return $quantity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns quantity sold during the last 5 sales for a single product
|
||||||
|
* ordered by best to last
|
||||||
|
* @param array $params array which contains an array with either ean or ref as key ['ean':'012345678901245'] or ['ref':'my-ref']
|
||||||
|
* @param array $excluded_ids array which contains product exclusions
|
||||||
|
* @param bool $use_cache set if the function uses the cache
|
||||||
|
* @return array containing information about the best sales
|
||||||
|
* output structure :
|
||||||
|
* [
|
||||||
|
{
|
||||||
|
"quantity_sold": "12",
|
||||||
|
"id_sale": "662",
|
||||||
|
"product_id": "28624",
|
||||||
|
"name": "Gigoteuse 70 cm - Jungle Pistache"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
[...]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
*/
|
||||||
|
public static function getBestSales($params, $excluded_ids, $use_cache = true)
|
||||||
|
{
|
||||||
|
$returnedArray = array();
|
||||||
|
$ean = false;
|
||||||
|
$ref = false;
|
||||||
|
if (isset($params['ean'])) {
|
||||||
|
$ean = $params['ean'];
|
||||||
|
}
|
||||||
|
if (isset($params['ref'])) {
|
||||||
|
$ref = $params['ref'];
|
||||||
|
}
|
||||||
|
if (empty($excluded_ids)) {
|
||||||
|
$excluded_ids = getBraderieProducts();
|
||||||
|
}
|
||||||
|
|
||||||
|
$order_states = explode(',', Configuration::get('PS_IT_OF_ORDER_STATES'));
|
||||||
|
|
||||||
|
if ($ref) {
|
||||||
|
//get related products
|
||||||
|
$sql = 'SELECT p.id_product, p.reference FROM `' . _DB_PREFIX_ . 'product` p
|
||||||
|
WHERE p.`supplier_reference` = \'' . pSQL($ref) . '\'
|
||||||
|
ORDER BY id_product';
|
||||||
|
testonecho('sql ' . $sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($ean) {
|
||||||
|
//get related products
|
||||||
|
$sql = 'SELECT id_product, reference FROM `' . _DB_PREFIX_ . 'product`
|
||||||
|
WHERE ean13 = \'' . pSQL($ean) . '\'
|
||||||
|
ORDER BY id_product';
|
||||||
|
}
|
||||||
|
$result = Db::getInstance()->ExecuteS($sql, true, $use_cache, __METHOD__);
|
||||||
|
$product_id_array = array();
|
||||||
|
if ($result) {
|
||||||
|
foreach ($result as $row) {
|
||||||
|
if (!in_array((int)$row['id_product'], $excluded_ids, true)) {
|
||||||
|
$product_id_array[] = (int)$row['id_product'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//get related sales
|
||||||
|
$sql = 'SELECT SUM(d.`product_quantity` - d.`product_quantity_reinjected`) as quantity_sold, ppc.`id_sale`, d.`product_id`, pl.name
|
||||||
|
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`
|
||||||
|
LEFT JOIN `' . _DB_PREFIX_ . 'product_ps_cache` ppc ON ppc.`id_product` = d.`product_id`
|
||||||
|
LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON pl.`id_product` = d.`product_id` AND pl.id_lang = 2
|
||||||
|
WHERE d.`product_id` IN (' . implode(',', $product_id_array) . ')
|
||||||
|
AND d.`product_attribute_id` = 0
|
||||||
|
AND sc.`id_order_state` IN ("' . implode('","', $order_states) . '")
|
||||||
|
GROUP BY ppc.`id_sale`, d.`product_id`
|
||||||
|
ORDER BY quantity_sold DESC
|
||||||
|
LIMIT 5';
|
||||||
|
$returnedArray = Db::getInstance()->ExecuteS($sql, true, $use_cache, __METHOD__);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return $returnedArray;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user