category = new Category(Tools::getValue("id")); } if(Tools::getValue("actionform") == 'delete') { if(Tools::getValue('idorderform') !== false && Validate::isLoadedObject($order_form = new OrderForm((int)Tools::getValue('idorderform')))) { if($order_form->delete()) echo 'Suppression effectuée'; else echo 'Erreur durant la suppression'; } else echo 'Mauvais id de bon de commande'; exit; } } public function _displayHeader() { global $currentIndex; $this->html .= ' '; $this->html .= ''; } public function _displayContent() { global $cookie; //$categories = CategoryCore::getCategories($cookie->id_lang,FALSE); $categories = Category::getCategories($cookie->id_lang, FALSE, true, ' AND c.id_parent = 1', ' ORDER BY c.id_category DESC ', ' LIMIT 500'); $ids = array(); foreach ($categories as $key => $category) { foreach ($category as $key => $data) { $ids[] = $data['infos']['id_category']; } } $extrafields = Category::getSalesInfos($ids); krsort($categories[1]); $this->html .= '
'.$this->l('Inventory Tracking').'

Ventes :

'; if(count($categories) > 0) { $this->html .= ' - Filtre :

'; } else $this->html .= 'Aucune vente'; if(!empty($this->category)) { $this->html .= $this->getFormOrderForm($this->category); $this->html .= '

'; } if( Tools::getIsset('action') && Tools::getValue('action') == 'getStats') { $this->html .= $this->getStatsArray(); $this->html .= '

'; } } public function display() { global $currentIndex; $this->_postProcess(); $this->_displayHeader(); $this->_displayContent(); echo $this->html; } public function getStatsArray() { global $cookie; if (!Tools::getIsset('id')) { return false; } // GET INFO FOR STAT $date_from = new DateManager(Tools::getValue('from')); $date_to = new DateManager(Tools::getValue('to')); $date_from->setLangue(strtoupper($lang_id)); $date_to->setLangue(strtoupper($lang_id)); $id_category = Tools::getValue('id'); $sale = Sale::getSaleFromCategory($id_category); $category = new Category($id_category, $cookie->id_lang); $products = MakeStats::getProductsByCat($id_category); $arrayProduct = array(); foreach($products as $product) $array_product[$product['id_product']] = $arrayProduct[$product['id_product']] = new Product($product['id_product']); $order_states = explode(',', Configuration::get('PS_IT_OF_ORDER_STATES')); $lines = MakeStats::getOrdersByIdsProduct(array_keys($arrayProduct), $order_states, $date_from->getDate('SQL'), $date_to->getDate('SQL')); // for stats $lines_tmp = $lines; $lines = MakeStats::getArrayLines($lines); $stats = new SaleStats($sale, $category); $stats->loadData(); $total_sale_product = array(); $total_bdc_ht = 0; foreach ($lines_tmp as $key => $order_line) { $id_product = $order_line['product_id']; $id_product_attribute = $order_line['product_attribute_id']; $current_product = $array_product[$id_product]; if($id_product_attribute != 0) { $combination = new Combination($id_product_attribute); if($combination->wholesale_price == 0) { $wholesale_price = $current_product->wholesale_price; } else { $wholesale_price = $combination->wholesale_price; } } else { $wholesale_price = $current_product->wholesale_price; } $quantity_to_cmd = $order_line['product_quantity'] - $order_line['product_quantity_reinjected']; $total_sale_ht += $quantity_to_cmd * $wholesale_price; if (!is_array($total_sale_product[(int)$id_product]) ){ $total_sale_product[(int)$id_product] = array(); $total_sale_product[(int)$id_product]['total_ht'] = 0; $total_sale_product[(int)$id_product]['quantiy'] = 0; $total_sale_product[(int)$id_product]['name'] = $current_product->name[2]; } $total_sale_product[(int)$id_product]['total_ht'] += ($wholesale_price * $quantity_to_cmd); $total_sale_product[(int)$id_product]['quantiy'] += $quantity_to_cmd; } $stats->addToStats('total_bdc_ht', $total_sale_ht); $bestsales = MakeStats::orderMultiArray($total_sale_product, 'total_ht'); $bestsales_extract = array_slice($bestsales, 0, 3); $i = 1; foreach ($bestsales_extract as $key => $bestsalesProduct) { $stats->addToStats('bestsale_'.$i.'_product', $bestsalesProduct['name']); $stats->addToStats('bestsale_'.$i.'_quantity', $bestsalesProduct['quantiy']); $stats->addToStats('bestsale_'.$i.'_ca', $bestsalesProduct['total_ht']); $i++; } $stats->loadDataForSubCategory(); $html = '
'.$this->l('Stats').' :'; $html.= '

Rapport de vente : '.$stats->data_stats['name'].'

'; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; for ($i=1; $i <= 3; $i++) { $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; } $html.= '
'.$stats->lang['date_start'].''.$stats->data_stats['date_start'].'
'.$stats->lang['date_end'].''.$stats->data_stats['date_end'].'
'.$stats->lang['duration'].''.$stats->data_stats['duration'].'
STATS VENTES
'.$stats->lang['nb_ref'].''.$stats->data_stats['nb_ref'].'
'.$stats->lang['nb_quantity_start'].''.$stats->data_stats['nb_quantity_start'].'
'.$stats->lang['nb_order_simple'].''.$stats->data_stats['nb_order_simple'].'
'.$stats->lang['nb_order_multi'].''.$stats->data_stats['nb_order_multi'].'
'.$stats->lang['nb_order_total'].''.$stats->data_stats['nb_order_total'].'
'.$stats->lang['taux_multi'].''.$stats->data_stats['taux_multi'].'
'.$stats->lang['quantity_sale'].''.$stats->data_stats['quantity_sale'].'
'.$stats->lang['percent_sale'].''.$stats->data_stats['percent_sale'].'
'.$stats->lang['percent_out_of_stock'].''.$stats->data_stats['percent_out_of_stock'].'
'.$stats->lang['ca_ttc'].''.Tools::displayPrice($stats->data_stats['ca_ttc']).'
'.$stats->lang['total_bdc_ht'].''.Tools::displayPrice($stats->data_stats['total_bdc_ht']).'
'.$stats->lang['marge'].''.$stats->data_stats['marge'].'
BEST SELLERS
'.$stats->lang['bestsale_'.$i.'_product'].''.$stats->data_stats['bestsale_'.$i.'_product'].'
'.$stats->lang['bestsale_'.$i.'_quantity'].''.$stats->data_stats['bestsale_'.$i.'_quantity'].'
'.$stats->lang['bestsale_'.$i.'_ca'].''.Tools::displayPrice($stats->data_stats['bestsale_'.$i.'_ca']).'
'; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $i = 0; foreach ($stats->data_subcategories as $key => $subcategories) { foreach ($subcategories as $key_2 => $subcategory) { if ($i % 4 == 0) { $html.= ''; } else { $html.= ''; } $html.= ''; if ($key_2 == 'total_amount_wholesale_price') { $html.= ''; } else { $html.= ''; } $html.= ''; $i++; } } $html.= '
SOUS CATEGORIES
'.$stats->lang[$key_2].''.Tools::displayPrice($subcategory).''.$subcategory.'
'; return $html; } public function getFormOrderForm($category) { global $link, $cookie; require_once(_PS_ROOT_DIR_.'/modules/privatesales/Sale.php'); $sale = Sale::getSaleFromCategory($category->id); $date = new DateTime($sale->date_start); $date_end = new DateTime($sale->date_end); $date_end->modify('+2 hour'); $date_first_of_month = $date->format('d/m/Y H:i:s'); $date_now = $date_end->format('d/m/Y H:i:s'); $export_list = OrderForm::getByCategorie($category->id); if($export_list && count($export_list) > 0) { $old_date = OrderForm::getLastByCategory($category->id); $old_date = new DateManager($old_date); } $html = '
'.$this->l('Export').' :

'.$this->l('Date d\'import').'

Du
Au '.( count($export_list) > 0 ? '
Ou
'.$this->l('depuis la génération du dernier bon').' : '.$old_date->getDate('STR') : '').'

'.$this->l('Selection du type de fichier').'

'.$this->l('Bon de commande').'
'.$this->l('Etat de la vente').'
'.$this->l('Stats de la vente').'
'.$this->l('BDC Logistique').'

'.$this->l('Selection de la langue').'

'.$this->l('Français').'
'.$this->l('Anglais').' '; $html .= '

'.$this->l('Obtenir le fichier').'
'; $html .= '
'; $html .= $this->getFormOrderFormInfo($category); $html .= '


'; if($export_list && count($export_list) > 0) { $html .= ' '; foreach($export_list as $export) { $html .=''; } $html .= '
'.$this->l('ID').''.$this->l('Date de d\'export').''.$this->l('A partir de').''.$this->l('Jusqu\'a').''.$this->l('Exporter à nouveau').'
'.$export['id_order_form'].' '.$export['date_add'].' '.$export['from'].''.$export['to'].' '; // $html .=' FR EN
'; } else $html .= '

'.$this->l('Il n\'y a pas d\'anciens exports de bon de commande'); $html .= '
'; return $html; } public function getFormOrderFormInfo() { global $cookie; $html = '
Informations sur le bon de commande
'; $array_lang = array( 'fr', 'en' ); $array = array( 'PS_IT_OF_ORGANISATION' => array( 'form_organisation', 'Organisation :' ), 'PS_IT_OF_SLOGAN' => array( 'form_slogan', 'Slogan :' ), 'PS_IT_OF_EMAIL' => array( 'form_email', 'Email :' ), 'PS_IT_OF_TVA' => array( 'form_tva', 'TVA :' ), 'PS_IT_OF_ADDRESS' => array( 'form_address', 'Adresse partie 1 :' ), 'PS_IT_OF_ADDRESS_2' => array( 'form_address_2', 'Adresse partie 2 :' ), 'PS_IT_OF_CP_CITY' => array( 'form_cp_city', 'CP et Ville :' ), 'PS_IT_OF_NUMBER_PHONE' => array( 'form_numero_tel', 'Numéro de téléphone :' ), 'PS_IT_OF_BAS_PAGE' => array( 'form_bas_page', 'Informations bas de page :', true ), 'PS_IT_OF_BAS_PAGE_BIS' => array( 'form_bas_page_bis', 'Informations bas de page Bis:', true ), ); if(Tools::isSubmit('submitFormInfos')) { foreach($array_lang as $lang) { foreach($array as $k => $arr) { if(isset($arr[2])) $html_ = true; else $html_ = false; Configuration::updateValue($k.'_'.$lang, Tools::getValue($arr[0].'_'.$lang), $html_); } } Configuration::updateValue('PS_IT_OF_ORDER_STATES', implode(',', Tools::getValue('states', array() )) ); $html .= '
'.$this->l('Informations Sauvegardé').'
'; } $html .= ' '; return $html; } } ?>