Merge branch 'ticket-newExtract' into develop

This commit is contained in:
Marion Muszynski 2016-04-25 17:17:05 +02:00
commit f72b207fc0

View File

@ -678,6 +678,7 @@ class AdminBulkUpdate extends AdminTab {
'Mode de transport',
'Département '
), ';', '"');
$pos = 0;
foreach($products as $product) {
$p = new Product((int) $product, $id_lang);
if(!Validate::isLoadedObject($p)) {
@ -731,10 +732,11 @@ class AdminBulkUpdate extends AdminTab {
}
}
$quantity_sold = 0;
if(count($combinations) > 0) {
foreach($combinations as $k => $v) {
$quantity_sold = (int) Db::getInstance()->getValue('
$quantity_sold += (int) Db::getInstance()->getValue('
SELECT SUM(d.`product_quantity`)
FROM `'._DB_PREFIX_.'order_detail` d
LEFT JOIN `'._DB_PREFIX_.'orders` o ON o.`id_order` = d.`id_order`
@ -748,7 +750,7 @@ class AdminBulkUpdate extends AdminTab {
) NOT IN (1,6,8,9,10,11,14,15,18)
');
if ($quantity_sold == 0) {
/*if ($quantity_sold == 0) {
continue;
}
@ -772,11 +774,11 @@ class AdminBulkUpdate extends AdminTab {
11,
3,
31
), ';', '"');
), ';', '"');*/
}
} else {
$quantity_sold = (int) Db::getInstance()->getValue('
$quantity_sold += (int) Db::getInstance()->getValue('
SELECT SUM(d.`product_quantity`)
FROM `'._DB_PREFIX_.'order_detail` d
LEFT JOIN `'._DB_PREFIX_.'orders` o ON o.`id_order` = d.`id_order`
@ -789,29 +791,53 @@ class AdminBulkUpdate extends AdminTab {
) NOT IN (1,6,8,9,10,11,14,15,18)
');
if ($quantity_sold == 0) {
/*if ($quantity_sold == 0) {
continue;
}
fputcsv($f, array(
$p->position,
$category_properties[$p->id]['country'],
$category_properties[$p->id]['name'],
$category_properties[$p->id]['month'],
$p->supplier_reference,
$p->name[$id_lang],
$customs['nc8'],
'',
$customs['id_country'],
str_replace('.', ',', Tools::ps_round(($quantity_sold * $p->wholesale_price),2)),
11,
str_replace('.', ',', Tools::ps_round(($p->weight * $quantity_sold),2)),
$quantity_sold,
11,
3,
31
), ';', '"');
//$p->position,
$pos,
$category_properties[$p->id]['country'],
$category_properties[$p->id]['name'],
$category_properties[$p->id]['month'],
$p->supplier_reference,
$p->name[$id_lang],
$customs['nc8'],
'',
$customs['id_country'],
str_replace('.', ',', Tools::ps_round(($quantity_sold * $p->wholesale_price),2)),
11,
str_replace('.', ',', Tools::ps_round(($p->weight * $quantity_sold),2)),
$quantity_sold,
11,
3,
31
), ';', '"');*/
}
if ($quantity_sold == 0) {
continue;
}
$pos++;
fputcsv($f, array(
//$p->position,
$pos,
$category_properties[$p->id]['country'],
$category_properties[$p->id]['name'],
$category_properties[$p->id]['month'],
$p->supplier_reference,
$p->name[$id_lang],
$customs['nc8'],
'',
$customs['id_country'],
str_replace('.', ',', Tools::ps_round(($quantity_sold * $p->wholesale_price),2)),
11,
str_replace('.', ',', Tools::ps_round(($p->weight * $quantity_sold),2)),
$quantity_sold,
11,
3,
31
), ';', '"');
}
}
fclose($f);
@ -823,7 +849,7 @@ class AdminBulkUpdate extends AdminTab {
// Seulement les expeditions vers Espagne et Belgique
$orders = Db::getInstance()->ExecuteS('
SELECT DISTINCT od.`id_order_detail`, od.`product_id`, psc.`id_sale`
SELECT DISTINCT od.`id_order_detail`, od.`product_id`, psc.`id_sale`, a.`id_country` as country_exp
FROM `'._DB_PREFIX_.'order_detail` od
LEFT JOIN `'._DB_PREFIX_.'orders` o ON (o.`id_order` = od.`id_order`)
LEFT JOIN `'._DB_PREFIX_.'product_ps_cache` psc ON (psc.`id_product` = od.`product_id`)
@ -838,6 +864,7 @@ class AdminBulkUpdate extends AdminTab {
) NOT IN (1,6,8,9,10,11,14,15,18)
ORDER BY od.`product_id` ASC
');
if (!$orders) {
$output .= '<p class="error">Erreur produit: Pas de commandes trouvées pour ces dates</p>';
break;
@ -846,12 +873,12 @@ class AdminBulkUpdate extends AdminTab {
setlocale(LC_TIME, "fr_FR");
$products = array();
$orders_detail = array();
$category_properties = array();
$row_properties = array();
$by_sale = array();
foreach($orders as $order) {
$products[] = $order['product_id'];
$orders_detail[] = $order['id_order_detail'];
if (!isset($category_properties[(int)$order['product_id']])) {
if (!isset($row_properties[(int)$order['product_id']])) {
$by_sale[(int)$order['id_sale']] = array();
$privatesale = new Sale((int) $order['id_sale']);
@ -859,12 +886,14 @@ class AdminBulkUpdate extends AdminTab {
if ($privatesale->id_country > 0) {
$country_ps = Country::getNameById((int)$id_lang,(int)$privatesale->id_country);
}
$category_properties[(int)$order['product_id']] = array(
$country_exp = Country::getNameById((int)$id_lang,(int)$order['country_exp']);
$row_properties[(int)$order['product_id']] = array(
'name' => $privatesale->title[(int)$id_lang],
'country' => $country_ps,
'month' => strftime("%B", strtotime($privatesale->date_start)),
'date' => strtotime($privatesale->date_start),
'id_sale' => (int) $order['id_sale'],
'country_exp' => $country_exp
);
}
}
@ -894,7 +923,7 @@ class AdminBulkUpdate extends AdminTab {
'Produit',
'Nomenclature',
'NGP9',
//'Pays dorigine',
'Pays de destination',
'Valeur',
'Régime',
'Masse',
@ -941,10 +970,11 @@ class AdminBulkUpdate extends AdminTab {
}
}
$quantity_sold = 0;
if(count($combinations) > 0) {
foreach($combinations as $k => $v) {
$quantity_sold = (int) Db::getInstance()->getValue('
$quantity_sold += (int) Db::getInstance()->getValue('
SELECT SUM(d.`product_quantity`)
FROM `'._DB_PREFIX_.'order_detail` d
WHERE d.`product_id` = '.(int) $p->id.'
@ -952,7 +982,7 @@ class AdminBulkUpdate extends AdminTab {
AND d.`id_order_detail` IN ('.(count($orders_detail)>1?implode(',',$orders_detail):$orders_detail[0]).')
');
if ($quantity_sold == 0) {
/*if ($quantity_sold == 0) {
continue;
}
@ -961,13 +991,14 @@ class AdminBulkUpdate extends AdminTab {
$products_detail[] = array(
'position' => $p->position,
'sale_country' => $category_properties[$p->id]['country'],
'sale_name' => $category_properties[$p->id]['name'],
'sale_month' => $category_properties[$p->id]['month'],
'sale_country' => $row_properties[$p->id]['country'],
'sale_name' => $row_properties[$p->id]['name'],
'sale_month' => $row_properties[$p->id]['month'],
'supplier_reference' => $v['supplier_reference'],
'product_name' => $p->name[$id_lang].' - '.implode(' ', $names),
'nc8' => $customs['nc8'],
'NGP9' => '',
'id_country' => $customs['id_country'],
'value' => str_replace('.', ',', ($quantity_sold * $p->wholesale_price)),
'regime' => 21,
'weight' => str_replace('.', ',', Tools::ps_round(($p->weight * $quantity_sold),2)),
@ -975,33 +1006,34 @@ class AdminBulkUpdate extends AdminTab {
'transaction_type' => 11,
'transport' => 3,
'department' => 31,
'sale_date' => $category_properties[$p->id]['date'],
'id_sale' => $category_properties[$p->id]['id_sale'],
);
'sale_date' => $row_properties[$p->id]['date'],
'id_sale' => $row_properties[$p->id]['id_sale'],
);*/
}
} else {
$quantity_sold = (int) Db::getInstance()->getValue('
$quantity_sold += (int) Db::getInstance()->getValue('
SELECT SUM(d.`product_quantity`)
FROM `'._DB_PREFIX_.'order_detail` d
WHERE d.`product_id` = '.(int) $p->id.'
AND d.`id_order_detail` IN ('.(count($orders_detail)>1?implode(',',$orders_detail):$orders_detail[0]).')
');
if ($quantity_sold == 0) {
/* if ($quantity_sold == 0) {
continue;
}
$products_detail[] = array(
'position' => $p->position,
'sale_country' => $category_properties[$p->id]['country'],
'sale_name' => $category_properties[$p->id]['name'],
'sale_month' => $category_properties[$p->id]['month'],
'sale_country' => $row_properties[$p->id]['country'],
'sale_name' => $row_properties[$p->id]['name'],
'sale_month' => $row_properties[$p->id]['month'],
'supplier_reference' => $p->supplier_reference,
'product_name' => $p->name[$id_lang],
'nc8' => $customs['nc8'],
'NGP9' => '',
'id_country' => $customs['id_country'],
'value' => str_replace('.', ',', ($quantity_sold * $p->wholesale_price)),
'regime' => 21,
'weight' => str_replace('.', ',', Tools::ps_round(($p->weight * $quantity_sold),2)),
@ -1009,11 +1041,35 @@ class AdminBulkUpdate extends AdminTab {
'transaction_type' => 11,
'transport' => 3,
'department' => 31,
'sale_date' => $category_properties[$p->id]['date'],
'id_sale' => $category_properties[$p->id]['id_sale'],
);
'sale_date' => $row_properties[$p->id]['date'],
'id_sale' => $row_properties[$p->id]['id_sale'],
);*/
}
if ($quantity_sold == 0) {
continue;
}
$products_detail[] = array(
'position' => $p->position,
'sale_country' => $row_properties[$p->id]['country'],
'sale_name' => $row_properties[$p->id]['name'],
'sale_month' => $row_properties[$p->id]['month'],
'supplier_reference' => $p->supplier_reference,
'product_name' => $p->name[$id_lang],
'nc8' => $customs['nc8'],
'NGP9' => '',
'country_exp' => $row_properties[$p->id]['country_exp'],
'value' => str_replace('.', ',', ($quantity_sold * $p->wholesale_price)),
'regime' => 21,
'weight' => str_replace('.', ',', Tools::ps_round(($p->weight * $quantity_sold),2)),
'quantity_sold' => $quantity_sold,
'transaction_type' => 11,
'transport' => 3,
'department' => 31,
'sale_date' => $row_properties[$p->id]['date'],
'id_sale' => $row_properties[$p->id]['id_sale'],
);
}
}
@ -1022,9 +1078,12 @@ class AdminBulkUpdate extends AdminTab {
$sale_date[$key] = (int)$row['sale_date'];
}
array_multisort($sale_date, SORT_ASC, $id_sale, SORT_DESC, $products_detail);
$pos = 0;
foreach ($products_detail as $key => $product_d) {
$pos++;
fputcsv($f, array(
$product_d['position'],
//$product_d['position'],
$pos,
$product_d['sale_country'],
$product_d['sale_name'],
$product_d['sale_month'],
@ -1032,7 +1091,7 @@ class AdminBulkUpdate extends AdminTab {
$product_d['product_name'],
$product_d['nc8'],
$product_d['NGP9'],
//$product_d['id_country'],
$product_d['country_exp'],
$product_d['value'],
$product_d['regime'],
$product_d['weight'],