suite export remb
This commit is contained in:
parent
cb3cca72c9
commit
84fe835cc1
@ -38,10 +38,12 @@ class AdminStatsLogistic extends AdminTab {
|
||||
$ps = new Sale((int)$sale['id_sale']);
|
||||
$product_ids = $ps->getProducts();
|
||||
$products = $this->getSaleDetails($product_ids);
|
||||
$reasons= array();
|
||||
|
||||
//echo "<pre>";var_dump($products);echo "</pre>";die();
|
||||
if ($products) {
|
||||
$result[(int)$sale['id_sale']] = array(
|
||||
'name' => $ps->title[2],
|
||||
'date' => $ps->date_start,
|
||||
'ca_ttc' => 0,
|
||||
'ca_refund' => 0,
|
||||
'percent_ca_refund' => 0,
|
||||
@ -49,7 +51,42 @@ class AdminStatsLogistic extends AdminTab {
|
||||
'quantity_refund' => 0,
|
||||
'percent_refund' => 0
|
||||
);
|
||||
$reasons = array(3,6,8,12,11,1,4,5,9,10,7,99);
|
||||
foreach ($reasons as $key => $reason_id) {
|
||||
$result[(int)$sale['id_sale']][(int)$reason_id] = array(
|
||||
'ca_refund' => 0,
|
||||
'percent_ca_refund' => 0,
|
||||
'quantity_refund' => 0,
|
||||
'percent_refund' => 0,
|
||||
);
|
||||
}
|
||||
$id_orders = array();
|
||||
$id_orders_error = array();
|
||||
$shipping_numbers = array();
|
||||
$result[(int)$sale['id_sale']]['nb_orders'] = 0;
|
||||
$result[(int)$sale['id_sale']]['nb_orders_error_log'] = 0;
|
||||
$result[(int)$sale['id_sale']]['percent_error_log'] = 0;
|
||||
$result[(int)$sale['id_sale']]['nb_package'] = 0;
|
||||
$result[(int)$sale['id_sale']]['nb_pole_1'] = 0;
|
||||
$result[(int)$sale['id_sale']]['nb_pole_2'] = 0;
|
||||
$result[(int)$sale['id_sale']]['nb_pole_3'] = 0;
|
||||
$result[(int)$sale['id_sale']]['nb_pole_4'] = 0;
|
||||
$result[(int)$sale['id_sale']]['nb_pole_5'] = 0;
|
||||
$result[(int)$sale['id_sale']]['nb_pole_6'] = 0;
|
||||
foreach($products as $row) {
|
||||
if (!in_array((int)$row['id_order'],$id_orders)) {
|
||||
$id_orders[] = (int)$row['id_order'];
|
||||
}
|
||||
if(isset($row['id_employee']) && !isset($shipping_numbers[(int)$row['id_employee']])) {
|
||||
$shipping_numbers[(int)$row['id_employee']] = array();
|
||||
}
|
||||
if ( isset($row['shipping_number'])
|
||||
&& is_array($shipping_numbers[(int)$row['id_employee']])
|
||||
&& !in_array($row['shipping_number'],$shipping_numbers[(int)$row['id_employee']])
|
||||
) {
|
||||
$shipping_numbers[(int)$row['id_employee']][] = $row['shipping_number'];
|
||||
}
|
||||
|
||||
$price = (isset($row['product_quantity_discount']) && $row['product_quantity_discount']!=0)?(float)$row['product_quantity_discount']:(float)$row['product_price'];
|
||||
$result[(int)$sale['id_sale']]['ca_ttc'] += (((int)$row['product_quantity'] - (int)$row['product_quantity_reinjected'])*$price);
|
||||
$result[(int)$sale['id_sale']]['quantity_sold'] += ((int)$row['product_quantity'] - (int)$row['product_quantity_reinjected']);
|
||||
@ -62,8 +99,9 @@ class AdminStatsLogistic extends AdminTab {
|
||||
if (!isset($row['id_reason'])) {
|
||||
$row['id_reason'] = 99;
|
||||
}
|
||||
if(!in_array((int)$row['id_reason'], $reasons)) {
|
||||
$reasons[] = (int) $row['id_reason'];
|
||||
|
||||
if ((int)$row['id_reason'] == 6 && !in_array((int)$row['id_order'],$id_orders_error)) {
|
||||
$id_orders_error[] = (int)$row['id_order'];
|
||||
}
|
||||
|
||||
if(!isset($result[(int)$sale['id_sale']][(int)$row['id_reason']])) {
|
||||
@ -89,11 +127,59 @@ class AdminStatsLogistic extends AdminTab {
|
||||
$result[(int)$sale['id_sale']][$reason_id]['percent_refund'] += ($result[(int)$sale['id_sale']][$reason_id]['quantity_refund'] / $result[(int)$sale['id_sale']]['quantity_sold'])*100;
|
||||
}
|
||||
}
|
||||
|
||||
$result[(int)$sale['id_sale']]['nb_orders'] = count($id_orders);
|
||||
$result[(int)$sale['id_sale']]['nb_orders_error_log'] = count($id_orders_error);
|
||||
$result[(int)$sale['id_sale']]['percent_error_log'] = ($result[(int)$sale['id_sale']]['nb_orders_error_log'] / $result[(int)$sale['id_sale']]['nb_orders'])*100;
|
||||
|
||||
$nb_package = 0;
|
||||
foreach ($shipping_numbers as $id_employee => $value) {
|
||||
$nb_package += count($value);
|
||||
switch ($id_employee) {
|
||||
case '52':
|
||||
$result[(int)$sale['id_sale']]['nb_pole_1'] += count($value);
|
||||
break;
|
||||
case '22':
|
||||
case '24':
|
||||
$result[(int)$sale['id_sale']]['nb_pole_2'] += count($value);
|
||||
break;
|
||||
case '25':
|
||||
case '44':
|
||||
$result[(int)$sale['id_sale']]['nb_pole_3'] += count($value);
|
||||
break;
|
||||
case '47':
|
||||
case '48':
|
||||
$result[(int)$sale['id_sale']]['nb_pole_4'] += count($value);
|
||||
break;
|
||||
case '35':
|
||||
case '36':
|
||||
$result[(int)$sale['id_sale']]['nb_pole_5'] += count($value);
|
||||
break;
|
||||
case '28':
|
||||
default:
|
||||
$result[(int)$sale['id_sale']]['nb_pole_6'] += count($value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$result[(int)$sale['id_sale']]['nb_package'] = $nb_package;
|
||||
$result[(int)$sale['id_sale']]['nb_pole_1'] = ($result[(int)$sale['id_sale']]['nb_pole_1'] / $nb_package)*100;
|
||||
$result[(int)$sale['id_sale']]['nb_pole_2'] = ($result[(int)$sale['id_sale']]['nb_pole_2'] / $nb_package)*100;
|
||||
$result[(int)$sale['id_sale']]['nb_pole_3'] = ($result[(int)$sale['id_sale']]['nb_pole_3'] / $nb_package)*100;
|
||||
$result[(int)$sale['id_sale']]['nb_pole_4'] = ($result[(int)$sale['id_sale']]['nb_pole_4'] / $nb_package)*100;
|
||||
$result[(int)$sale['id_sale']]['nb_pole_5'] = ($result[(int)$sale['id_sale']]['nb_pole_5'] / $nb_package)*100;
|
||||
$result[(int)$sale['id_sale']]['nb_pole_6'] = ($result[(int)$sale['id_sale']]['nb_pole_6'] / $nb_package)*100;
|
||||
}
|
||||
}
|
||||
echo "<pre>";var_dump($result);echo "</pre>";die();
|
||||
if ($result) {
|
||||
$this->exportCSV($result);
|
||||
//echo "<pre>";var_dump($result);echo "</pre>";die();
|
||||
$fname = 'export-remb-'.$this->date_export_begin.'-'.$this->date_export_end.'.csv';
|
||||
foreach(glob(dirname(__FILE__).'/*.csv') as $filename) {
|
||||
if ($fname == $filename) {
|
||||
unlink($filename);
|
||||
}
|
||||
}
|
||||
$this->exportCSV($result, $fname);
|
||||
echo '<p class="conf">'.$this->l('Export complete.').' <a onclick="window.open(this.href); return false;" href="http://'.$_SERVER['HTTP_HOST'].__PS_BASE_URI__.'modules/stats_logistic/'.$fname.'">'.$this->l('Click here to download the file').'</a></p>';
|
||||
}
|
||||
} else {
|
||||
die('pas de vente trouvée');
|
||||
@ -412,20 +498,21 @@ class AdminStatsLogistic extends AdminTab {
|
||||
|
||||
public function getSaleDetails($product_ids) {
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT od.*, rr.`id_reason`
|
||||
SELECT od.*, rr.`id_reason`, pws.`id_employee`, pws.`shipping_number`
|
||||
FROM `'._DB_PREFIX_.'order_detail` od
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_slip` os ON (os.`id_order` = od.`id_order`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'lapostews` pws ON (pws.`id_order_detail` = od.`id_order_detail`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'refundreason` rr ON (rr.`id_order_slip` = os.`id_order_slip`)
|
||||
WHERE od.`product_id` IN ('.implode(',', $product_ids).')
|
||||
-- AND od.`product_quantity_refunded`>0
|
||||
ORDER BY rr.`id_reason`
|
||||
');
|
||||
return Db::getInstance()->ExecuteS('
|
||||
/*return Db::getInstance()->ExecuteS('
|
||||
SELECT od.*
|
||||
FROM `'._DB_PREFIX_.'order_detail` od
|
||||
WHERE od.`product_id` IN ('.implode(',', $product_ids).')
|
||||
|
||||
');
|
||||
');*/
|
||||
}
|
||||
|
||||
public function getSales() {
|
||||
@ -444,21 +531,92 @@ class AdminStatsLogistic extends AdminTab {
|
||||
');
|
||||
}
|
||||
|
||||
public function exportCSV () {
|
||||
$fp = fopen("php://output", 'w+');
|
||||
public function exportCSV ($result, $filename) {
|
||||
//$fp = fopen("php://output", 'w');
|
||||
$fp = fopen(dirname(__FILE__).'/'.$filename, 'w');
|
||||
$delim = ';';
|
||||
|
||||
$row_1 = array("","","","","","","","");
|
||||
$row_2 = array("Marque","Date de Debut","CA produit TTC","CA remb TTC","% remb valeur","Quantite vendue","Quantite remb","% remb volume");
|
||||
|
||||
$data=array();
|
||||
foreach ($row_definition as $col) {
|
||||
$data[] = $col;
|
||||
$reasons = array();
|
||||
$reasons[] = array(
|
||||
'id_reason' => 3,
|
||||
'name' => "BBB : Erreur Achat / Prod",
|
||||
);
|
||||
$reasons[] = array(
|
||||
'id_reason' => 6,
|
||||
'name' => "BBB : Erreur Logistique",
|
||||
);
|
||||
$reasons[] = array(
|
||||
'id_reason' => 8,
|
||||
'name' => "BBB : Pbme Site / Paiment",
|
||||
);
|
||||
$reasons[] = array(
|
||||
'id_reason' => 12,
|
||||
'name' => "BBB : Suspicion de fraude",
|
||||
);
|
||||
$reasons[] = array(
|
||||
'id_reason' => 11,
|
||||
'name' => "CLIENT : Annulation pour re-achat",
|
||||
);
|
||||
$reasons[] = array(
|
||||
'id_reason' => 1,
|
||||
'name' => "CLIENT : Annulation pre-envoi",
|
||||
);
|
||||
/* $reasons[] = array(
|
||||
'id_reason' => 2,
|
||||
'name' => "CLIENT : Rétractation post-envoi",
|
||||
);*/
|
||||
$reasons[] = array(
|
||||
'id_reason' => 4,
|
||||
'name' => "FEUR : Probleme SAV",
|
||||
);
|
||||
$reasons[] = array(
|
||||
'id_reason' => 5,
|
||||
'name' => "FEUR : Produit manquant",
|
||||
);
|
||||
$reasons[] = array(
|
||||
'id_reason' => 9,
|
||||
'name' => "TRANS : Colis detruit",
|
||||
);
|
||||
$reasons[] = array(
|
||||
'id_reason' => 10,
|
||||
'name' => "TRANS : Colis perdu",
|
||||
);
|
||||
$reasons[] = array(
|
||||
'id_reason' => 7,
|
||||
'name' => "Autre",
|
||||
);
|
||||
$reasons[] = array(
|
||||
'id_reason' => 99,
|
||||
'name' => "Vide",
|
||||
);
|
||||
foreach ($reasons as $key => $reason) {
|
||||
$row_1[] = $reason['name'] ;
|
||||
$row_1[] = "" ;
|
||||
$row_1[] = "" ;
|
||||
$row_1[] = "" ;
|
||||
|
||||
$row_2[] = "CA remb TTC";
|
||||
$row_2[] = "% remb valeur";
|
||||
$row_2[] = "Quantite remb";
|
||||
$row_2[] = "% remb volume";
|
||||
}
|
||||
fputcsv ($fp,$data,$delim);
|
||||
foreach ($items as $item) {
|
||||
$row_2 = array_merge($row_2,array("Nb commande","Nb commande erreur log","% erreur","NB colis","% colis Pole 1","% colis Pole 2","% colis Pole 3","% colis Pole 4","% colis Pole 5","% colis Pole 6"));
|
||||
fputcsv ($fp,$row_1,$delim);
|
||||
fputcsv ($fp,$row_2,$delim);
|
||||
|
||||
foreach ($result as $key => $row) {
|
||||
$data = array();
|
||||
foreach ($row_definition as $key => $col) {
|
||||
$data[] = (isset($item->$key) ? $item->$key : '');
|
||||
foreach ($row as $k => $value) {
|
||||
if (is_array($value)){
|
||||
foreach ($value as $key => $val) {
|
||||
$data[] = $val;
|
||||
}
|
||||
} else {
|
||||
$data[] = $value;
|
||||
}
|
||||
}
|
||||
fputcsv ($fp,array_map('utf8_decode',array_values($data)),$delim);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user