Merge branch 'ticket-deplaceExtract' into develop
This commit is contained in:
commit
37c9b988b1
@ -176,20 +176,36 @@ class Parcel {
|
||||
}
|
||||
$dst_address_ws->country = (string) mb_substr($dst_country->name[$cookie->id_lang], 0, 32);
|
||||
|
||||
if(Module::isInstalled('socolissimo') && ($so_data = Db::getInstance()->getRow('
|
||||
if((Module::isInstalled('socolissimo') || Module::isInstalled('soflexibilite')) && ($so_data = Db::getInstance()->getRow('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'socolissimo_delivery_info`
|
||||
WHERE `id_cart` = '.(int) $this->order->id_cart.'
|
||||
AND `id_customer` = '.(int) $this->order->id_customer.'
|
||||
'))) {
|
||||
$unicode_0 = json_decode('"\u0006"');
|
||||
$unicode_1 = json_decode('"\u200b"');
|
||||
$unicode_2 = json_decode('"\u00ad"');
|
||||
|
||||
$dst_address_ws->email = $so_data['ceemail'];
|
||||
$dst_address_ws->Name = mb_substr($so_data['prfirstname'], 0, 32);
|
||||
$dst_address_ws->Surname = mb_substr($so_data['prname'], 0, 32);
|
||||
$dst_address_ws->Name = str_replace(
|
||||
array('Á', '°', 'º', 'º', 'º', 'ª', "\t", "\n", "\r", ' ', '–', '', $unicode_0, $unicode_1, $unicode_2,),
|
||||
array('A', '', '', '', '', 'a', ' ', ' ', ' ', ' ', '-', '', '', '', '',),
|
||||
mb_substr($so_data['prfirstname'], 0, 32)
|
||||
);
|
||||
$dst_address_ws->Surname = str_replace(
|
||||
array('Á', '°', 'º', 'º', 'º', 'ª', "\t", "\n", "\r", ' ', '–', '', $unicode_0, $unicode_1, $unicode_2,),
|
||||
array('A', '', '', '', '', 'a', ' ', ' ', ' ', ' ', '-', '', '', '', '',),
|
||||
mb_substr($so_data['prname'], 0, 32)
|
||||
);
|
||||
|
||||
$address_lines = array();
|
||||
for($i = 1; $i < 5; $i++) {
|
||||
if(($line = (string) mb_substr($so_data['pradress'.$i], 0, 32)) != '') {
|
||||
$address_lines[] = trim($line);
|
||||
$address_lines[] = str_replace(
|
||||
array('Á', '°', 'º', 'º', 'º', 'ª', "\t", "\n", "\r", ' ', '–', '', $unicode_0, $unicode_1, $unicode_2,),
|
||||
array('A', '', '', '', '', 'a', ' ', ' ', ' ', ' ', '-', '', '', '', '',),
|
||||
trim($line)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -229,7 +245,11 @@ class Parcel {
|
||||
$dst_address_ws->DoorCode2 = $doorcode;
|
||||
}
|
||||
|
||||
$this->letter->parcel->Instructions = str_replace(array('°', "\n", "\r"), '', (string) $so_data['cedeliveryinformation']);
|
||||
$this->letter->parcel->Instructions = $address_lines[] = str_replace(
|
||||
array('Á', '°', 'º', 'º', 'º', 'ª', "\t", "\n", "\r", ' ', '–', '', $unicode_0, $unicode_1, $unicode_2,),
|
||||
array('A', '', '', '', '', 'a', ' ', ' ', ' ', ' ', '-', '', '', '', '',),
|
||||
(string) $so_data['cedeliveryinformation']
|
||||
);
|
||||
$this->letter->parcel->DeliveryMode = (string) $so_data['delivery_mode'];
|
||||
if(!in_array($this->letter->parcel->DeliveryMode, array('DOM', 'DOS', 'RDV'))) {
|
||||
$this->letter->parcel->RegateCode = $so_data['prid']; //(string) ltrim($so_data['prid'], '0');
|
||||
|
@ -45,6 +45,11 @@ class AdminPrivateSalesLogistique extends AdminTab {
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
if(Tools::getValue("action") == 'getSaleExport') {
|
||||
$this->getSaleExport();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function _displayHeader()
|
||||
@ -80,7 +85,6 @@ class AdminPrivateSalesLogistique extends AdminTab {
|
||||
showButtonPanel: false
|
||||
});
|
||||
|
||||
|
||||
$("#exportorderform").click(function(){
|
||||
var export_last = $("#export_last").is(":checked"), req;
|
||||
|
||||
@ -98,7 +102,7 @@ class AdminPrivateSalesLogistique extends AdminTab {
|
||||
|
||||
var type = $("#export_form input[name=export_type]:checked").val();
|
||||
|
||||
if(type == 1 || type == 2 || type == 4) {
|
||||
if(type == 1 || type == 2 || type == 4 ) {
|
||||
req += "&type="+type;
|
||||
req += "&lang="+$("input[name=lang]:checked").val();
|
||||
|
||||
@ -106,6 +110,14 @@ class AdminPrivateSalesLogistique extends AdminTab {
|
||||
.attr("href", "../modules/privatesales_logistique/exportOrderForm.php?action=getOrderForm"+req)
|
||||
.attr("target", "_blank");
|
||||
return true;
|
||||
} else if (type == 5) {
|
||||
req += "&type="+type;
|
||||
req += "&lang="+$("input[name=lang]:checked").val();
|
||||
var url_dest = "'.$currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesLogistique').'&action=getSaleExport";
|
||||
|
||||
$(this).attr("href", url_dest+req);
|
||||
console.log($(this).attr("href"));
|
||||
return true;
|
||||
} else {
|
||||
var from = $("#hasDatepicker_1").val();
|
||||
var to = $("#hasDatepicker_2").val();
|
||||
@ -186,7 +198,7 @@ class AdminPrivateSalesLogistique extends AdminTab {
|
||||
$this->_postProcess();
|
||||
$this->_displayHeader();
|
||||
$this->_displayContent();
|
||||
|
||||
|
||||
echo $this->html;
|
||||
}
|
||||
|
||||
@ -469,6 +481,8 @@ class AdminPrivateSalesLogistique extends AdminTab {
|
||||
<input type="radio" name="export_type" value="3"> '.$this->l('Stats de la vente').'
|
||||
<br />
|
||||
<input type="radio" name="export_type" value="4"> '.$this->l('BDC Logistique').'
|
||||
<br />
|
||||
<input type="radio" name="export_type" value="5"> '.$this->l('Exporter la Vente (ne tient pas compte de la date)').'
|
||||
|
||||
<h4>'.$this->l('Selection de la langue').'</h4>
|
||||
<input type="radio" name="lang" value="fr" checked> '.$this->l('Français').'
|
||||
@ -479,8 +493,7 @@ class AdminPrivateSalesLogistique extends AdminTab {
|
||||
|
||||
$html .= '<br /><br />
|
||||
<a href="" class="button" id="exportorderform">'.$this->l('Obtenir le fichier').'</a>
|
||||
</div>';
|
||||
|
||||
</div>';
|
||||
|
||||
$html .= '
|
||||
</div>
|
||||
@ -531,6 +544,258 @@ class AdminPrivateSalesLogistique extends AdminTab {
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function getSaleExport()
|
||||
{
|
||||
global $link, $cookie;
|
||||
|
||||
require_once(_PS_ROOT_DIR_.'/modules/privatesales/Sale.php');
|
||||
|
||||
set_time_limit(300);
|
||||
$id_category = (int)Tools::getValue('id');
|
||||
$id_lang = $cookie->id_lang;
|
||||
$sale = Sale::getSaleFromCategory($id_category);
|
||||
$category = new Category($id_category, $cookie->id_lang);
|
||||
if ($category) {
|
||||
$c = $category;
|
||||
$children = $c->recurseLiteCategTree(5, 0, $id_lang);
|
||||
$ids = $this->_recurse_array(array($children));
|
||||
$products = array();
|
||||
foreach($c->getProductsWs() as $p) {
|
||||
$products[] = $p['id'];
|
||||
}
|
||||
foreach($ids as $id) {
|
||||
$sc = new Category($id, $id_lang);
|
||||
foreach($sc->getProductsWs() as $p) {
|
||||
$products[] = $p['id'];
|
||||
}
|
||||
}
|
||||
$products = array_unique($products);
|
||||
|
||||
$fname = date( "Ymd", strtotime($sale->date_start)).'-'.$sale->title[(int)$id_lang].'.csv';
|
||||
foreach(glob(dirname(__FILE__).'/*.csv') as $filename) {
|
||||
if ($fname == $filename) {
|
||||
unlink($filename);
|
||||
}
|
||||
}
|
||||
$f = fopen(dirname(__FILE__).'/'.$fname, 'w');
|
||||
// uft8 sans bom pour accent
|
||||
$BOM = "\xEF\xBB\xBF"; // UTF-8 BOM
|
||||
fwrite($f, $BOM); // NEW LINE
|
||||
|
||||
fputcsv($f, array(
|
||||
'supplier_reference',
|
||||
'id_product',
|
||||
'id_product_attribute',
|
||||
'position',
|
||||
'poids',
|
||||
'quantity',
|
||||
'product_name',
|
||||
'combination',
|
||||
'ean13',
|
||||
'NC8',
|
||||
'Pays de fabrication',
|
||||
'quantity_sold',
|
||||
'public_price_wt',
|
||||
'price_wt',
|
||||
'wholesale_price',
|
||||
'BDC HT',
|
||||
'id_TVA',
|
||||
'description_short',
|
||||
'description',
|
||||
'images',
|
||||
'nb_images',
|
||||
'categories',
|
||||
'sous-categories',
|
||||
'sous-sous-categories',
|
||||
), ';', '"');
|
||||
foreach($products as $product) {
|
||||
$p = new Product((int) $product, $id_lang);
|
||||
if(!Validate::isLoadedObject($p)) {
|
||||
$output .= '<p class="error">Erreur produit: '.serialize($product).' ce produit ne figure pas dans l\'export</p>';
|
||||
} else {
|
||||
$position = Db::getInstance()->getValue('
|
||||
SELECT `position`
|
||||
FROM `'._DB_PREFIX_.'category_product`
|
||||
WHERE `id_category` = '.(int) $id_category.'
|
||||
AND id_product = '. (int) $p->id . '
|
||||
');
|
||||
$p->position = $position;
|
||||
|
||||
$categories = array();
|
||||
foreach(Db::getInstance()->ExecuteS('
|
||||
SELECT `id_category`
|
||||
FROM `'._DB_PREFIX_.'category_product`
|
||||
WHERE `id_product` = '.(int) $p->id.'
|
||||
') as $cat) {
|
||||
$categories[] = (int) $cat['id_category'];
|
||||
}
|
||||
sort($categories);
|
||||
|
||||
$categories_title = array();
|
||||
foreach ($categories as $category) {
|
||||
$title = Db::getInstance()->getValue('
|
||||
SELECT `name`
|
||||
FROM `'._DB_PREFIX_.'category_lang`
|
||||
WHERE `id_category` = '.(int) $category.'
|
||||
AND id_lang = '. $id_lang . '
|
||||
');
|
||||
$categories_title[(int) $category] = $title;
|
||||
}
|
||||
$categorie_0 = '';
|
||||
$categorie_1 = '';
|
||||
$categorie_2 = '';
|
||||
foreach ($categories as $key => $cat) {
|
||||
if ($key == 0) {
|
||||
$categorie_0 = $categories_title[$cat];
|
||||
} elseif ($key == 1) {
|
||||
$categorie_1 = $categories_title[$cat];
|
||||
} elseif ($key == 2) {
|
||||
$categorie_2 = $categories_title[$cat];
|
||||
}
|
||||
}
|
||||
|
||||
$combinations = array();
|
||||
foreach($p->getAttributeCombinaisons($id_lang) as $combi) {
|
||||
if(!isset($combinations[$combi['id_product_attribute']])) {
|
||||
$combinations[$combi['id_product_attribute']] = array(
|
||||
'qty' => $combi['quantity'],
|
||||
'name' => array($combi['attribute_name']),
|
||||
'ean13' => $combi['ean13'],
|
||||
'location' => empty($combi['location'])? $p->location: $combi['location'],
|
||||
'brand' => $p->manufacturer_name,
|
||||
'supplier_reference' => empty($combi['supplier_reference'])? $p->supplier_reference: $combi['supplier_reference'],
|
||||
);
|
||||
} else {
|
||||
$combinations[$combi['id_product_attribute']]['name'][] = $combi['attribute_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` = '.(int) $id_lang.'
|
||||
AND i.`id_product` = '.(int) $p->id.'
|
||||
') as $img) {
|
||||
$link_image = str_split($img['id_image']);
|
||||
$images[] = 'http://static.bebeboutik.com/img/p/'.implode('/', $link_image) .'/'. $img['id_image'].'.jpg';
|
||||
}
|
||||
|
||||
$customs = Db::getInstance()->getRow('
|
||||
SELECT `nc8`, `id_country`
|
||||
FROM `'._DB_PREFIX_.'product_customs`
|
||||
WHERE `id_product` = '.(int) $p->id
|
||||
);
|
||||
|
||||
if(count($combinations) > 0) {
|
||||
foreach($combinations as $k => $v) {
|
||||
$c_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`
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_attribute_image` a
|
||||
ON a.`id_image` = i.`id_image`
|
||||
WHERE l.`id_lang` = '.(int) $id_lang.'
|
||||
AND a.`id_product_attribute` = '.(int) $k.'
|
||||
ORDER BY i.`position`
|
||||
') as $img) {
|
||||
$link_image = str_split($img['id_image']);
|
||||
$c_images[] = 'http://static.bebeboutik.com/img/p/'.implode('/', $link_image) .'/'. $img['id_image'].'.jpg';
|
||||
}
|
||||
|
||||
$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`
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_history` h
|
||||
ON h.`id_order` = d.`id_order`
|
||||
WHERE d.`product_id` = '.(int) $p->id.'
|
||||
AND d.`product_attribute_id` = '.(int) $k.'
|
||||
AND h.`id_order_state` = 2
|
||||
');
|
||||
|
||||
$names = array_unique($v['name']);
|
||||
sort($names, SORT_STRING);
|
||||
fputcsv($f, array(
|
||||
$v['supplier_reference'],
|
||||
$p->id,
|
||||
$k,
|
||||
$p->position,
|
||||
str_replace('.', ',', $p->weight),
|
||||
$v['qty'],
|
||||
$p->name[$id_lang],
|
||||
implode(' - ', $names),
|
||||
$v['ean13'],
|
||||
$customs['nc8'],
|
||||
$customs['id_country'],
|
||||
$quantity_sold,
|
||||
str_replace('.', ',', $p->getPrice(TRUE, (int) $k, 2, NULL, FALSE, FALSE)),
|
||||
str_replace('.', ',', $p->getPrice(TRUE, (int) $k, 2)),
|
||||
str_replace('.', ',', Tools::ps_round($p->wholesale_price, 2)),
|
||||
str_replace('.', ',', Tools::ps_round(($quantity_sold * $p->wholesale_price),2)),
|
||||
$p->id_tax_rules_group,
|
||||
// $p->active,
|
||||
$p->description_short[$id_lang],
|
||||
$p->description[$id_lang],
|
||||
count($c_images) > 0? implode(', ', $c_images): implode(', ', $images),
|
||||
count($c_images) > 0? count($c_images): count($images),
|
||||
$categorie_0,
|
||||
$categorie_1,
|
||||
$categorie_2,
|
||||
|
||||
), ';', '"');
|
||||
}
|
||||
} else {
|
||||
$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`
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_history` h
|
||||
ON h.`id_order` = d.`id_order`
|
||||
WHERE d.`product_id` = '.(int) $p->id.'
|
||||
AND h.`id_order_state` = 2
|
||||
');
|
||||
|
||||
fputcsv($f, array(
|
||||
$p->supplier_reference,
|
||||
$p->id,
|
||||
0,
|
||||
$p->position,
|
||||
str_replace('.', ',', $p->weight),
|
||||
$p->quantity,
|
||||
$p->name[$id_lang],
|
||||
'',
|
||||
$p->ean13,
|
||||
$customs['nc8'],
|
||||
$customs['id_country'],
|
||||
$quantity_sold,
|
||||
str_replace('.', ',', $p->getPrice(TRUE, NULL, 2, NULL, FALSE, FALSE)),
|
||||
str_replace('.', ',', $p->getPrice(TRUE, NULL, 2)),
|
||||
str_replace('.', ',', Tools::ps_round($p->wholesale_price, 2)),
|
||||
str_replace('.', ',', Tools::ps_round(($quantity_sold * $p->wholesale_price),2)),
|
||||
$p->id_tax_rules_group,
|
||||
$p->description_short[$id_lang],
|
||||
$p->description[$id_lang],
|
||||
implode(', ', $images),
|
||||
count($images),
|
||||
$categorie_0,
|
||||
$categorie_1,
|
||||
$categorie_2,
|
||||
), ';', '"');
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose($f);
|
||||
$this->html .= '<p class="conf">'.$this->l('Export complete.').' <a onclick="window.open(this.href); return false;" href="http://'.$_SERVER['HTTP_HOST'].__PS_BASE_URI__.'modules/privatesales_logistique/'.$fname.'">'.$this->l('Click here to download the file').'</a></p>';
|
||||
}
|
||||
}
|
||||
|
||||
public function getFormOrderFormInfo()
|
||||
{
|
||||
global $cookie;
|
||||
@ -610,6 +875,17 @@ class AdminPrivateSalesLogistique extends AdminTab {
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
private function _recurse_array($array) {
|
||||
$result = array();
|
||||
foreach($array as $i) {
|
||||
$result[] = $i['id'];
|
||||
if(count($i['children']) > 0) {
|
||||
$result = array_merge($result, $this->_recurse_array($i['children']));
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -164,8 +164,8 @@ class ParentOrderController extends ParentOrderControllerCore {
|
||||
// distinction "at home" et "out of home"
|
||||
$carriers_ah = array();
|
||||
$carriers_ooh = array();
|
||||
// $config_carrier_ooh = array(88,89); // prod
|
||||
$config_carrier_ooh = array(47,48); // dev
|
||||
$config_carrier_ooh = array(88,89); // prod
|
||||
// $config_carrier_ooh = array(47,48); // dev
|
||||
// $config_carrier_ooh = array(40,45); // local
|
||||
foreach ($carriers as $carrier) {
|
||||
if (in_array($carrier['id_carrier'], $config_carrier_ooh) ){
|
||||
|
Loading…
Reference in New Issue
Block a user