table = 'stats_logistic'; $this->lang = false; $this->date_begin = date('Y-m-d'); $this->date_end = date('Y-m-d'); $this->date_stock = date('Y-m-d'); $this->date_export_begin = date('Y-m-d'); $this->date_export_end = date('Y-m-d'); if (!empty($_GET['date_begin'])) { $this->date_begin = $_GET['date_begin']; } if (!empty($_GET['date_end'])){ $this->date_end = $_GET['date_end']; } if (!empty($_GET['date_stock'])){ $this->date_stock = $_GET['date_stock']; } parent::__construct(); } public function postProcess() { global $currentIndex, $cookie; if (Tools::getValue('submitExport')) { $this->date_export_begin = Tools::getValue('date_export_begin', $this->date_export_begin); $this->date_export_end = Tools::getValue('date_export_end', $this->date_export_end); $sale_ids = $this->getSales(); if ($sale_ids) { foreach ($sale_ids as $sale) { //$ps = new Sale((int)$sale['id_sale']); //$product_ids = $ps->getProducts(); $product_ids = $this->getProducts((int)$sale['id_sale']); $products = $this->getSaleDetails($product_ids); /*foreach ($products as $key => $product) { $order_detail_ids[] = (int)$product['id_order_detail']; } $packages = $this->getPackageDetails($order_detail_ids);*/ //echo "
";var_dump($products);echo "";die(); if ($products) { $result[(int)$sale['id_sale']] = array( /*'name' => $ps->title[2], 'date' => $ps->date_start,*/ 'name' => $sale['title'], 'date' => $sale['date_start'], 'ca_ttc' => 0, 'ca_refund' => 0, 'percent_ca_refund' => 0, 'quantity_sold' => 0, 'quantity_refund' => 0, 'percent_refund' => 0 ); $reasons = array(3,6,8,12,11,1,2,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']; } /*foreach ($packages as $pack) { if ((int)$pack['id_order_detail'] == (int)$row['id_order_detail']) { if(!isset($shipping_numbers[(int)$pack['id_employee']])) { $shipping_numbers[(int)$pack['id_employee']] = array(); } if (is_array($shipping_numbers[(int)$pack['id_employee']]) && !in_array($pack['shipping_number'],$shipping_numbers[(int)$pack['id_employee']]) ) { $shipping_numbers[(int)$pack['id_employee']][] = $pack['shipping_number']; } } }*/ 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']);*/ $price = (float)$row['price']; $result[(int)$sale['id_sale']]['ca_ttc'] += ((int)$row['real_quantity'] * $price); $result[(int)$sale['id_sale']]['quantity_sold'] += $row['real_quantity']; if ($row['product_quantity_refunded']>0) { $result[(int)$sale['id_sale']]['quantity_refund'] += (int)$row['product_quantity_refunded']; $result[(int)$sale['id_sale']]['ca_refund'] += ((int)$row['product_quantity_refunded']*$price); if (!isset($row['id_reason'])) { $row['id_reason'] = 99; } if ((int)$row['id_reason'] == 6 && !in_array((int)$row['id_order'],$id_orders_error)) { $id_orders_error[] = (int)$row['id_order']; } if (in_array((int)$row['id_reason'], $reasons)) { if(!isset($result[(int)$sale['id_sale']][(int)$row['id_reason']])) { $result[(int)$sale['id_sale']][(int)$row['id_reason']] = array( 'ca_refund' => 0, 'percent_ca_refund' => 0, 'quantity_refund' => 0, 'percent_refund' => 0, ); } $result[(int)$sale['id_sale']][(int)$row['id_reason']]['ca_refund'] += round(((int)$row['product_quantity_refunded']*$price),2); $result[(int)$sale['id_sale']][(int)$row['id_reason']]['quantity_refund'] += round((int)$row['product_quantity_refunded'],2); } } } $result[(int)$sale['id_sale']]['percent_ca_refund'] = number_format(($result[(int)$sale['id_sale']]['ca_refund'] / $result[(int)$sale['id_sale']]['ca_ttc'])*100,2); $result[(int)$sale['id_sale']]['percent_refund'] = number_format(($result[(int)$sale['id_sale']]['quantity_refund'] / $result[(int)$sale['id_sale']]['quantity_sold'])*100,2); foreach ($reasons as $key => $reason_id) { if (isset($result[(int)$sale['id_sale']][$reason_id])) { $result[(int)$sale['id_sale']][$reason_id]['percent_ca_refund'] += round(($result[(int)$sale['id_sale']][$reason_id]['ca_refund'] / $result[(int)$sale['id_sale']]['ca_ttc'])*100,2); $result[(int)$sale['id_sale']][$reason_id]['percent_refund'] += round(($result[(int)$sale['id_sale']][$reason_id]['quantity_refund'] / $result[(int)$sale['id_sale']]['quantity_sold'])*100,2); } } $result[(int)$sale['id_sale']]['ca_ttc'] = round($result[(int)$sale['id_sale']]['ca_ttc'],2); $result[(int)$sale['id_sale']]['ca_refund'] = round($result[(int)$sale['id_sale']]['ca_refund'],2); $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'] = number_format(($result[(int)$sale['id_sale']]['nb_orders_error_log'] / $result[(int)$sale['id_sale']]['nb_orders'])*100,2); $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'] = number_format(($result[(int)$sale['id_sale']]['nb_pole_1'] / $nb_package)*100,2); $result[(int)$sale['id_sale']]['nb_pole_2'] = number_format(($result[(int)$sale['id_sale']]['nb_pole_2'] / $nb_package)*100,2); $result[(int)$sale['id_sale']]['nb_pole_3'] = number_format(($result[(int)$sale['id_sale']]['nb_pole_3'] / $nb_package)*100,2); $result[(int)$sale['id_sale']]['nb_pole_4'] = number_format(($result[(int)$sale['id_sale']]['nb_pole_4'] / $nb_package)*100,2); $result[(int)$sale['id_sale']]['nb_pole_5'] = number_format(($result[(int)$sale['id_sale']]['nb_pole_5'] / $nb_package)*100,2); $result[(int)$sale['id_sale']]['nb_pole_6'] = number_format(($result[(int)$sale['id_sale']]['nb_pole_6'] / $nb_package)*100,2); } } if ($result) { //echo "
";var_dump($result);echo "";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 '
'.$this->l('Export complete.').' '.$this->l('Click here to download the file').'
'; } else { echo ''.$this->l('No result for these dates.').'
'; } } else { echo ''.$this->l('No sale found.').'
'; } } } public function display() { global $currentIndex, $cookie; $date = Configuration::get('MAJ_STAT_LOGISTIC'); echo ' '; echo '' ; $stats = $this->getStats(); $poles = array(); for ($i=0; $i < 6; $i++) { $poles[] = array( 'recap' => array( 'quantity' => 0, 'nb_package' => 0 ), 'employee' => array(), ); } $poles[0]['name'] = 'Pôle 1 : Petites marques'; $poles[1]['name'] = 'Pôle 2 : Marques moyenne'; $poles[2]['name'] = 'Pôle 3 : Grosses marques'; $poles[3]['name'] = 'Pôle 4 : Postes complementaires'; $poles[4]['name'] = 'Pôle 5 : Multi'; $poles[5]['name'] = 'Pôle 6 : Autre'; foreach ($stats as $key => $stat) { if (!isset($stat['id_employee'])) { continue; } switch ($stat['id_employee']) { case '52': $poles[0]['recap']['quantity'] += $stat['quantity']; $poles[0]['recap']['nb_package'] += $stat['nb_package']; $poles[0]['employee'][] = $stat; break; case '22': case '24': $poles[1]['recap']['quantity'] += $stat['quantity']; $poles[1]['recap']['nb_package'] += $stat['nb_package']; $poles[1]['employee'][] = $stat; break; case '25': case '44': $poles[2]['recap']['quantity'] += $stat['quantity']; $poles[2]['recap']['nb_package'] += $stat['nb_package']; $poles[2]['employee'][] = $stat; break; case '47': case '48': $poles[3]['recap']['quantity'] += $stat['quantity']; $poles[3]['recap']['nb_package'] += $stat['nb_package']; $poles[3]['employee'][] = $stat; break; case '35': case '36': $poles[4]['recap']['quantity'] += $stat['quantity']; $poles[4]['recap']['nb_package'] += $stat['nb_package']; $poles[4]['employee'][] = $stat; break; case '28': default: $poles[5]['recap']['quantity'] += $stat['quantity']; $poles[5]['recap']['nb_package'] += $stat['nb_package']; $poles[5]['employee'][] = $stat; break; } $total_quantity += $stat['quantity']; } $total_colis = $this->getTotalColis(); $total_quantity = 0; echo 'Id Employee | Prénom | Nom | Quantité | Nombre de colis | % total | |
---|---|---|---|---|---|---|
'.$pole['name'].' | '.$pole['recap']['quantity'].' | '.$pole['recap']['nb_package'].' | '. number_format(($pole['recap']['nb_package']* 100 / $total_colis), 2) .' % | |||
'.$stat['id_employee'].' | '.$stat['firstname'].' | '.$stat['lastname'].' | '.$stat['email'].' | '.$stat['quantity'].' | '.$stat['nb_package'].' | '. number_format(($stat['nb_package']* 100 / $total_colis), 2) .' % |
Total : | '.$total_quantity.' | '.$total_colis.' | 100 % |
Paiement accepté | Commande partiellement expédiée | ||
---|---|---|---|
'.$report['name'].' | '.date('Y-m-d', strtotime($this->date_stock. ' - '.$k.' days')).' | '.$report['payment'].' | '.$report['partial'].' |