├── .gitignore ├── config.php ├── img ├── ATM_logo.jpg ├── mandarin.png ├── object_mandarin.png ├── object_mandarin.xcf └── Dolibarr_Preferred_Partner_logo.png ├── script └── create-maj-base.php ├── ChangeLog.md ├── README ├── config.default.php ├── langs ├── en_US │ └── mandarin.lang └── fr_FR │ └── mandarin.lang ├── lib └── mandarin.lib.php ├── class ├── costpricelog.class.php └── actions_mandarin.class.php ├── admin ├── mandarin_about.php └── mandarin_setup.php ├── graph_ca_cumule.php ├── graph_cout_interim.php ├── graph_project_task.php ├── core └── boxes │ └── mandarin_box.php ├── graph_ca_horaire.php ├── graph_effectif.php ├── graph_total_heure.php ├── graph_horaire_moyen.php ├── graph_ca_by_month.php ├── graph_project.php ├── report_repartition_achats_fournisseurs.php ├── graph_timeSpent_exceed.php ├── graph_cost_price.php ├── graph_time_period.php ├── list_diff_by_commercial.php ├── graph_product_receipt_time_average.php ├── graph_action_by_user.php ├── graph_propales_by_commercial.php ├── graph_project_by_user.php ├── graph_sent_products_average.php ├── evo_achats_fournisseurs.php ├── evo_ventes_articles.php ├── evo_achats_articles.php └── graph_propal_facture.php /.gitignore: -------------------------------------------------------------------------------- 1 | .settings/ 2 | .project 3 | .buildpath 4 | *.log 5 | /nbproject -------------------------------------------------------------------------------- /config.php: -------------------------------------------------------------------------------- 1 | init_db_by_vars($PDOdb); 23 | */ 24 | -------------------------------------------------------------------------------- /ChangeLog.md: -------------------------------------------------------------------------------- 1 | # ChangeLog 2 | 3 | # CHANGELOG FOR MANDARIN MODULE 4 | 5 | ## Not Released 6 | 7 | - 1.2.2 : FIX supplier filter on the purchase progression report 8 | is not filtered on suppliers *2021-04-06* - 1.2.2. 9 | - 1.2.1 : FIX menus not enabled for sales / purchases / turnover 10 | progression reports *2021-03-31* - 1.2.1. 11 | 12 | In older Dolibarr versions (pre-13.0), the key `enabled` for menu 13 | descriptors was optional; when not set, the menu was enabled by 14 | default. Now it is mandatory. 15 | 16 | ## 1.2 17 | 18 | - No changelog available 19 | 20 | ## 1.1 21 | 22 | - No changelog available 23 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 ATM Consulting 3 | * 4 | * This program and files/directory inner it is free software: you can 5 | * redistribute it and/or modify it under the terms of the 6 | * GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | 20 | -------------------------------------------------------------------------------- /config.default.php: -------------------------------------------------------------------------------- 1 | trans('AbricotNotFound'). ' : Abricot'; 29 | exit; 30 | } 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /langs/en_US/mandarin.lang: -------------------------------------------------------------------------------- 1 | Module104996Name = mandarin 2 | Module104996Desc = mandarin Descripion 3 | 4 | ATMAbout = This module has been developed by ATM Consulting
You can find the documentation on our wiki

For any question or feedback, contact us on support@atm-consulting.fr

For any commercial question, contact us on contact@atm-consulting.fr or at +33 9 77 19 50 70

Find our other modules on Dolistore 5 | 6 | mandarinSetup = mandarin module setup 7 | mandarinAbout = About mandarin 8 | 9 | UserGroup=User group 10 | 11 | # GRAPH CA CUMULE / GRAPH CA CUMULATES 12 | permGraphCACumule = Allow viewing of the Cumulative AC graph (SIG menu) 13 | linkMenuGraphCACumule = Cumulative turnover graph 14 | titleGraphCACumule = Cumulative turnover N and N-1 15 | subTitleVAxisGraphCACumule = Amount excl. tax 16 | subTitleHAxisGraphCACumule = Weeks 17 | -------------------------------------------------------------------------------- /lib/mandarin.lib.php: -------------------------------------------------------------------------------- 1 | 3 | * Copyright (C) 2015 ATM Consulting 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /** 20 | * \file lib/mandarin.lib.php 21 | * \ingroup mandarin 22 | * \brief This file is an example module library 23 | * Put some comments here 24 | */ 25 | 26 | function mandarinAdminPrepareHead() 27 | { 28 | global $langs, $conf; 29 | 30 | $langs->load("mandarin@mandarin"); 31 | 32 | $h = 0; 33 | $head = array(); 34 | 35 | $head[$h][0] = dol_buildpath("/mandarin/admin/mandarin_setup.php", 1); 36 | $head[$h][1] = $langs->trans("Parameters"); 37 | $head[$h][2] = 'settings'; 38 | $h++; 39 | $head[$h][0] = dol_buildpath("/mandarin/admin/mandarin_about.php", 1); 40 | $head[$h][1] = $langs->trans("About"); 41 | $head[$h][2] = 'about'; 42 | $h++; 43 | 44 | // Show more tabs from modules 45 | // Entries must be declared in modules descriptor with line 46 | //$this->tabs = array( 47 | // 'entity:+tabname:Title:@mandarin:/mandarin/mypage.php?id=__ID__' 48 | //); // to add new tab 49 | //$this->tabs = array( 50 | // 'entity:-tabname:Title:@mandarin:/mandarin/mypage.php?id=__ID__' 51 | //); // to remove a tab 52 | complete_head_from_modules($conf, $langs, $object, $head, $h, 'mandarin'); 53 | 54 | return $head; 55 | } 56 | -------------------------------------------------------------------------------- /class/costpricelog.class.php: -------------------------------------------------------------------------------- 1 | set_table(MAIN_DB_PREFIX.'product_cost_price_log'); 8 | parent::add_champs('fk_supplier,fk_product',array('type'=>'integer','index'=>true)); 9 | parent::add_champs('qty,price',array('type'=>'float')); 10 | parent::add_champs('log_type',array('index'=>true, 'type'=>'string', 'length'=>10)); 11 | 12 | parent::_init_vars(); 13 | parent::start(); 14 | 15 | //log_type : PA, PMP, OF 16 | } 17 | 18 | static function add(&$PDOdb, $fk_product, $qty,$price, $log_type = 'PA', $fk_supplier=0) { 19 | 20 | if(empty($price) || empty($qty)) return false; 21 | 22 | $cpl=new TProductCostPriceLog; 23 | $cpl->fk_product = $fk_product; 24 | $cpl->fk_supplier = $fk_supplier; 25 | $cpl->price = $price; 26 | $cpl->qty = $qty; 27 | $cpl->log_type = $log_type; 28 | return $cpl->save($PDOdb); 29 | 30 | } 31 | 32 | static function getDataForProduct(&$PDOdb, $fk_product) { 33 | 34 | $sql="SELECT log_type, DATE_FORMAT(date_cre,'%Y-%m-%d') as 'date' , (SUM(qty * price) / SUM(qty)) as price 35 | FROM ".MAIN_DB_PREFIX."product_cost_price_log 36 | WHERE fk_product = ".(int)$fk_product." 37 | GROUP BY log_type,DATE_FORMAT(date_cre,'%Y-%m-%d') 38 | ORDER BY date_cre 39 | "; 40 | 41 | $Tab = $PDOdb->ExecuteAsArray($sql); 42 | // var_dump($Tab); 43 | $TData = $Tmp = array(); 44 | foreach($Tab as &$row) { 45 | 46 | if(!isset($Tmp[$row->date])) $Tmp[$row->date] = array('PA'=>0,'PMP'=>0, 'OF'=>0); 47 | 48 | $Tmp[$row->date][$row->log_type] = (double)$row->price; 49 | 50 | } 51 | 52 | self::normalizeArray($Tmp); 53 | 54 | 55 | foreach($Tmp as $date=>$values) { 56 | 57 | $TData[]= array_merge( array('date'=>$date), $values ); 58 | 59 | } 60 | 61 | 62 | return $TData; 63 | 64 | } 65 | 66 | function normalizeArray(&$TData) { 67 | 68 | $previous_line= array(); 69 | 70 | foreach($TData as $kd=>&$row) { 71 | 72 | if(!empty($previous_line)) { 73 | 74 | foreach($row as $k=>&$v) { 75 | 76 | if(empty($v) && !empty($previous_line[$k])) $v = $previous_line[$k]; 77 | 78 | } 79 | 80 | 81 | } 82 | 83 | $previous_line = $row; 84 | 85 | } 86 | 87 | 88 | } 89 | 90 | } -------------------------------------------------------------------------------- /admin/mandarin_about.php: -------------------------------------------------------------------------------- 1 | 3 | * Copyright (C) 2015 ATM Consulting 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /** 20 | * \file admin/about.php 21 | * \ingroup mandarin 22 | * \brief This file is an example about page 23 | * Put some comments here 24 | */ 25 | // Dolibarr environment 26 | $res = @include("../../main.inc.php"); // From htdocs directory 27 | if (! $res) { 28 | $res = @include("../../../main.inc.php"); // From "custom" directory 29 | } 30 | 31 | // Libraries 32 | require_once DOL_DOCUMENT_ROOT . "/core/lib/admin.lib.php"; 33 | require_once '../lib/mandarin.lib.php'; 34 | 35 | // Translations 36 | $langs->load("mandarin@mandarin"); 37 | 38 | // Access control 39 | if (! $user->admin) { 40 | accessforbidden(); 41 | } 42 | 43 | /* 44 | * View 45 | */ 46 | $page_name = "mandarinAbout"; 47 | llxHeader('', $langs->trans($page_name)); 48 | 49 | // Subheader 50 | $linkback = '' 51 | . $langs->trans("BackToModuleList") . ''; 52 | print_fiche_titre($langs->trans($page_name), $linkback); 53 | 54 | // Configuration header 55 | $head = mandarinAdminPrepareHead(); 56 | dol_fiche_head( 57 | $head, 58 | 'about', 59 | $langs->trans("Module104996Name"), 60 | 0, 61 | 'mandarin@mandarin' 62 | ); 63 | 64 | // About page goes here 65 | print '
'; 66 | print '
'.$langs->trans('ATMAbout').'
'; 67 | 68 | dol_fiche_end(); 69 | 70 | print '
'; 71 | print ''; 72 | print '
'; 73 | 74 | llxFooter(); 75 | 76 | $db->close(); -------------------------------------------------------------------------------- /graph_ca_cumule.php: -------------------------------------------------------------------------------- 1 | rights->mandarin->graph->ca_cumule) accessforbidden(); 5 | $langs->load('mandarin@mandarin'); 6 | 7 | $PDOdb = new TPDOdb; 8 | $Tab = $TData = array(); 9 | 10 | $year_n_1 = GETPOST('year_n_1', 'int'); 11 | if (empty($year_n_1)) $year_n_1 = date('Y')-1; 12 | $year_n = GETPOST('year_n', 'int'); 13 | if (empty($year_n)) $year_n = date('Y'); 14 | 15 | // Formatage du tableau de base 16 | for ($i=1; $i<=53; $i++) $TData[$i] = array('week' => $i, $year_n_1 => 0, $year_n => 0); 17 | 18 | $sql_n_1 = 'SELECT WEEKOFYEAR(date_valid) AS `week`, SUM(total) as total_ht 19 | FROM llx_facture 20 | WHERE YEAR(date_valid) = '.$year_n_1.' 21 | GROUP BY `week` 22 | ORDER BY `week` ASC'; 23 | 24 | $resql = $db->query($sql_n_1); 25 | if ($resql) 26 | { 27 | $cumul = 0; 28 | while ($line = $db->fetch_object($resql)) 29 | { 30 | $cumul += $line->total_ht; 31 | $TData[$line->week][$year_n_1] = $cumul; 32 | } 33 | } 34 | 35 | 36 | $sql_n = 'SELECT WEEKOFYEAR(date_valid) AS `week`, SUM(total) as total_ht 37 | FROM llx_facture 38 | WHERE YEAR(date_valid) = '.$year_n.' 39 | GROUP BY `week` 40 | ORDER BY `week` ASC'; 41 | 42 | $resql = $db->query($sql_n); 43 | if ($resql) 44 | { 45 | $cumul = 0; 46 | while ($line = $db->fetch_object($resql)) 47 | { 48 | $cumul += $line->total_ht; 49 | $TData[$line->week][$year_n] = $line->total_ht; 50 | } 51 | } 52 | 53 | for ($i =1; $i < count($TData); $i++) 54 | { 55 | if ($TData[$i][$year_n_1] == 0 && isset($TData[$i-1][$year_n_1])) $TData[$i][$year_n_1] = $TData[$i-1][$year_n_1]; 56 | if ($TData[$i][$year_n] == 0 && isset($TData[$i-1][$year_n])) $TData[$i][$year_n] = $TData[$i-1][$year_n]; 57 | } 58 | 59 | 60 | // Begin of page 61 | llxHeader('', $langs->trans('mandarinTitleGraphCACumule'), ''); 62 | 63 | $explorer = new stdClass(); 64 | $explorer->actions = array("dragToZoom", "rightClickToReset"); 65 | 66 | $listeview = new TListviewTBS('graphCACumule'); 67 | print $listeview->renderArray($PDOdb, $TData 68 | ,array( 69 | 'type' => 'chart' 70 | ,'liste'=>array( 71 | 'titre'=>$langs->transnoentitiesnoconv('titleGraphCACumule') 72 | ) 73 | ,'title'=>array( 74 | 'year' => $langs->transnoentitiesnoconv('Year') 75 | ,'week' => $langs->transnoentitiesnoconv('Week') 76 | ) 77 | ,'xaxis'=>'week' 78 | ,'hAxis'=>array('title'=>$langs->transnoentitiesnoconv('subTitleHAxisGraphCACumule')) 79 | ,'vAxis'=>array('title'=>$langs->transnoentitiesnoconv('subTitleVAxisGraphCACumule')) 80 | ,'explorer'=>$explorer 81 | ) 82 | ); 83 | 84 | // End of page 85 | llxFooter(); -------------------------------------------------------------------------------- /graph_cout_interim.php: -------------------------------------------------------------------------------- 1 | rights->mandarin->graph->cout_interim) accessforbidden(); 5 | $langs->load('mandarin@mandarin'); 6 | 7 | $PDOdb = new TPDOdb; 8 | $TData = array(); 9 | 10 | $year_n_1 = GETPOST('year_n_1', 'int'); 11 | if (empty($year_n_1)) $year_n_1 = date('Y')-1; 12 | $year_n = GETPOST('year_n', 'int'); 13 | if (empty($year_n)) $year_n = date('Y'); 14 | 15 | // Formatage du tableau de base 16 | for ($i=1; $i<=53; $i++) 17 | { 18 | $TData[$i] = array('week' => $i, $year_n_1 => 0, $year_n => 0); 19 | if (!empty($conf->global->MANDARIN_OBJECTIF_COUT_INTERIM)) $TData[$i]['objectif'] = $conf->global->MANDARIN_OBJECTIF_COUT_INTERIM; 20 | } 21 | 22 | $sql_n_1 = 'SELECT WEEKOFYEAR(ppt.task_date) AS `week`, (ue.thm * (SUM(ppt.task_duration) / 3600)) AS total_thm 23 | FROM llx_projet_task_time ppt 24 | INNER JOIN llx_user_extrafields ue ON (ppt.fk_user = ue.fk_object) 25 | WHERE YEAR(ppt.task_date) = '.$year_n_1.' 26 | AND ue.contrat = "interim" 27 | GROUP BY `week` 28 | ORDER BY `week` ASC'; 29 | 30 | $resql = $db->query($sql_n_1); 31 | if ($resql) 32 | { 33 | while ($line = $db->fetch_object($resql)) 34 | { 35 | $TData[$line->week][$year_n_1] = $line->total_thm; 36 | } 37 | } 38 | 39 | 40 | $sql_n = 'SELECT WEEKOFYEAR(ppt.task_date) AS `week`, (ue.thm * (SUM(ppt.task_duration) / 3600)) AS total_thm 41 | FROM llx_projet_task_time ppt 42 | INNER JOIN llx_user_extrafields ue ON (ppt.fk_user = ue.fk_object) 43 | WHERE YEAR(ppt.task_date) = '.$year_n.' 44 | AND ue.contrat = "interim" 45 | GROUP BY `week` 46 | ORDER BY `week` ASC'; 47 | 48 | $resql = $db->query($sql_n); 49 | if ($resql) 50 | { 51 | while ($line = $db->fetch_object($resql)) 52 | { 53 | $TData[$line->week][$year_n] = $line->total_thm; 54 | } 55 | } 56 | 57 | // Begin of page 58 | llxHeader('', $langs->trans('mandarinTitleGraphInterim'), ''); 59 | 60 | $explorer = new stdClass(); 61 | $explorer->actions = array("dragToZoom", "rightClickToReset"); 62 | 63 | $listeview = new TListviewTBS('graphInterim'); 64 | print $listeview->renderArray($PDOdb, $TData 65 | ,array( 66 | 'type' => 'chart' 67 | ,'liste'=>array( 68 | 'titre'=>$langs->transnoentitiesnoconv('titleGraphInterim') 69 | ) 70 | ,'title'=>array( 71 | 'year' => $langs->transnoentitiesnoconv('Year') 72 | ,'week' => $langs->transnoentitiesnoconv('Week') 73 | ) 74 | ,'xaxis'=>'week' 75 | ,'hAxis'=>array('title'=>$langs->transnoentitiesnoconv('subTitleHAxisGraphInterim')) 76 | ,'vAxis'=>array('title'=>$langs->transnoentitiesnoconv('subTitleVAxisGraphInterim')) 77 | ,'explorer'=>$explorer 78 | ) 79 | ); 80 | 81 | // End of page 82 | llxFooter(); -------------------------------------------------------------------------------- /graph_project_task.php: -------------------------------------------------------------------------------- 1 | rights->mandarin->graph->project_task) accessforbidden(); 7 | $langs->load('mandarin@mandarin'); 8 | 9 | $progress_min = GETPOST('progress_min', 'int'); 10 | $progress_max = GETPOST('progress_max', 'int'); 11 | $id = GETPOST('id', 'int'); 12 | $object = new Project($db); 13 | 14 | if ($id > 0) $object->fetch($id); 15 | 16 | $PDOdb = new TPDOdb; 17 | $TData = array(); 18 | 19 | $sql = 'SELECT pt.rowid, pt.label, pt.ref 20 | , SUM(pt.planned_workload) AS temps_prevu 21 | , SUM(pt.planned_workload * (pt.progress / 100)) AS temps_theorique 22 | , SUM(ptt.task_duration) AS temps_reel 23 | FROM '.MAIN_DB_PREFIX.'projet_task pt 24 | LEFT JOIN '.MAIN_DB_PREFIX.'projet_task_time ptt ON (pt.rowid = ptt.fk_task) 25 | WHERE pt.entity = '.$conf->entity.' 26 | AND pt.fk_projet = '.$id; 27 | 28 | if (!empty($progress_min)) $sql .= ' AND pt.progress >= '.$progress_min; 29 | if (!empty($progress_max)) $sql .= ' AND pt.progress >= '.$progress_max; 30 | $sql .= ' GROUP BY pt.rowid ORDER BY pt.progress'; 31 | 32 | $resql = $db->query($sql); 33 | if ($resql) 34 | { 35 | while ($line = $db->fetch_object($resql)) 36 | { 37 | if (empty($line->temps_prevu)) continue; 38 | 39 | $temps_prevu = (!empty($line->temps_prevu) ? $line->temps_prevu : 1); 40 | $progress_reelle = (100 * $line->temps_reel) / $temps_prevu; 41 | $progress_theorique = (100 * $line->temps_theorique) / $temps_prevu; 42 | 43 | $TData[] = array( 44 | 'name' => dol_escape_js($line->label).' ('.$line->ref.')' 45 | ,'Progression réelle' => $progress_reelle 46 | ,'Progression théorique' => $progress_theorique 47 | ); 48 | } 49 | } 50 | 51 | // Begin of page 52 | llxHeader('', $langs->trans('mandarinTitleGraphProjet'), ''); 53 | 54 | $head=project_prepare_head($object); 55 | dol_fiche_head($head, 'mandarin_rapport', $langs->trans("mandarinProjectTask"),0,($object->public?'projectpub':'project')); 56 | 57 | $explorer = new stdClass(); 58 | $explorer->actions = array("dragToZoom", "rightClickToReset"); 59 | 60 | $listeview = new TListviewTBS('graphProjectTask'); 61 | print $listeview->renderArray($PDOdb, $TData 62 | ,array( 63 | 'type' => 'chart' 64 | ,'chartType' => 'ColumnChart' 65 | ,'liste'=>array( 66 | 'titre'=>$langs->transnoentitiesnoconv('titleGraphProjectTask') 67 | ) 68 | ,'xaxis'=>'name' 69 | ,'hAxis'=>array('title'=>$langs->transnoentitiesnoconv('subTitleHAxisGraphProjectTask')) 70 | ,'vAxis'=>array('title'=>$langs->transnoentitiesnoconv('subTitleVAxisGraphProjectTask')) 71 | ,'explorer'=>$explorer 72 | ) 73 | ); 74 | 75 | // End of page 76 | llxFooter(); -------------------------------------------------------------------------------- /core/boxes/mandarin_box.php: -------------------------------------------------------------------------------- 1 | 3 | * Copyright (C) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /** 20 | * \file core/boxes/mybox.php 21 | * \ingroup mandarin 22 | * \brief This file is a sample box definition file 23 | * Put some comments here 24 | */ 25 | include_once DOL_DOCUMENT_ROOT . "/core/boxes/modules_boxes.php"; 26 | 27 | /** 28 | * Class to manage the box 29 | */ 30 | class mandarinbox extends ModeleBoxes 31 | { 32 | 33 | public $boxcode = "mybox"; 34 | public $boximg = "mandarin@mandarin"; 35 | public $boxlabel; 36 | public $depends = array("mandarin"); 37 | public $db; 38 | public $param; 39 | public $info_box_head = array(); 40 | public $info_box_contents = array(); 41 | 42 | /** 43 | * Constructor 44 | */ 45 | public function __construct() 46 | { 47 | global $langs; 48 | $langs->load("boxes"); 49 | 50 | $this->boxlabel = $langs->transnoentitiesnoconv("MyBox"); 51 | } 52 | 53 | /** 54 | * Load data into info_box_contents array to show array later. 55 | * 56 | * @param int $max Maximum number of records to load 57 | * @return void 58 | */ 59 | public function loadBox($max = 5) 60 | { 61 | global $conf, $user, $langs, $db; 62 | 63 | $this->max = $max; 64 | 65 | //include_once DOL_DOCUMENT_ROOT . "/mandarin/class/mandarin.class.php"; 66 | 67 | $text = $langs->trans("MyBoxDescription", $max); 68 | $this->info_box_head = array( 69 | 'text' => $text, 70 | 'limit' => dol_strlen($text) 71 | ); 72 | 73 | $this->info_box_contents[0][0] = array('td' => 'align="left"', 74 | 'text' => $langs->trans("MyBoxContent")); 75 | } 76 | 77 | /** 78 | * Method to show box 79 | * 80 | * @param array $head Array with properties of box title 81 | * @param array $contents Array with properties of box lines 82 | * @return void 83 | */ 84 | public function showBox($head = null, $contents = null) 85 | { 86 | parent::showBox($this->info_box_head, $this->info_box_contents); 87 | } 88 | } -------------------------------------------------------------------------------- /graph_ca_horaire.php: -------------------------------------------------------------------------------- 1 | rights->mandarin->graph->ca_horaire) accessforbidden(); 5 | $langs->load('mandarin@mandarin'); 6 | 7 | $PDOdb = new TPDOdb; 8 | $TData = array(); 9 | $rapport_ca_ht = GETPOST('rapport_ca_ht', 'int'); // Permet de diviser le montant HT pour réduire l'affichage 10 | if (empty($rapport_ca_ht)) $rapport_ca_ht = 1; 11 | 12 | $year_n_1 = GETPOST('year_n_1', 'int'); 13 | if (empty($year_n_1)) $year_n_1 = date('Y')-1; 14 | $year_n = GETPOST('year_n', 'int'); 15 | if (empty($year_n)) $year_n = date('Y'); 16 | 17 | // Formatage du tableau de base 18 | for ($i=1; $i<=53; $i++) $TData[$i] = array('week' => $i, 'CA'.$year_n_1 => 0, 'heures'.$year_n_1 => 0, 'CA'.$year_n => 0, 'heures'.$year_n => 0); 19 | 20 | // ANNEE N-1 21 | $sql_n_1_CA = 'SELECT WEEKOFYEAR(date_valid) AS `week`, SUM(total) as total_ht 22 | FROM llx_facture 23 | WHERE YEAR(date_valid) = '.$year_n_1.' 24 | GROUP BY `week` 25 | ORDER BY `week` ASC'; 26 | 27 | $sql_n_1_heures = 'SELECT WEEKOFYEAR(task_date) AS `week`, SUM(task_duration) AS total_time 28 | FROM llx_projet_task_time 29 | WHERE YEAR(task_date) = '.$year_n_1.' 30 | GROUP BY `week` 31 | ORDER BY `week` ASC'; 32 | 33 | $resql = $db->query($sql_n_1_CA); 34 | if ($resql) 35 | { 36 | while ($line = $db->fetch_object($resql)) 37 | { 38 | $TData[$line->week]['CA'.$year_n_1] = $line->total_ht / $rapport_ca_ht; 39 | } 40 | } 41 | 42 | $resql = $db->query($sql_n_1_heures); 43 | if ($resql) 44 | { 45 | $cumulsecondes = 0; 46 | while ($line = $db->fetch_object($resql)) 47 | { 48 | $nb_heures = $line->total_time / 3600; 49 | $TData[$line->week]['heures'.$year_n_1] = $nb_heures; 50 | 51 | // Calcul du CA / heures 52 | $TData[$line->week]['CA'.$year_n_1] = $TData[$line->week]['CA'.$year_n_1] / $nb_heures; 53 | } 54 | } 55 | // FIN N-1 56 | 57 | // ANNEE N 58 | $sql_n_CA = 'SELECT WEEKOFYEAR(date_valid) AS `week`, SUM(total) as total_ht 59 | FROM llx_facture 60 | WHERE YEAR(date_valid) = '.$year_n.' 61 | GROUP BY `week` 62 | ORDER BY `week` ASC'; 63 | 64 | $sql_n_heures = 'SELECT WEEKOFYEAR(task_date) AS `week`, SUM(task_duration) AS total_time 65 | FROM llx_projet_task_time 66 | WHERE YEAR(task_date) = '.$year_n.' 67 | GROUP BY `week` 68 | ORDER BY `week` ASC'; 69 | 70 | $resql = $db->query($sql_n_CA); 71 | if ($resql) 72 | { 73 | while ($line = $db->fetch_object($resql)) 74 | { 75 | $TData[$line->week]['CA'.$year_n] = $line->total_ht / $rapport_ca_ht; 76 | } 77 | } 78 | 79 | $resql = $db->query($sql_n_heures); 80 | if ($resql) 81 | { 82 | $cumulsecondes = 0; 83 | while ($line = $db->fetch_object($resql)) 84 | { 85 | $nb_heures = $line->total_time / 3600; 86 | $TData[$line->week]['heures'.$year_n] = $nb_heures; 87 | 88 | // Calcul du CA / heures 89 | $TData[$line->week]['CA'.$year_n] = $TData[$line->week]['CA'.$year_n] / $nb_heures; 90 | } 91 | } 92 | // FIN N 93 | 94 | // Begin of page 95 | llxHeader('', $langs->trans('mandarinTitleGraphCAHoraire'), ''); 96 | 97 | $explorer = new stdClass(); 98 | $explorer->actions = array("dragToZoom", "rightClickToReset"); 99 | 100 | $listeview = new TListviewTBS('graphCACumule'); 101 | print $listeview->renderArray($PDOdb, $TData 102 | ,array( 103 | 'type' => 'chart' 104 | ,'liste'=>array( 105 | 'titre'=>$langs->transnoentitiesnoconv('titleGraphCAHoraire') 106 | ) 107 | ,'title'=>array( 108 | 'year' => $langs->transnoentitiesnoconv('Year') 109 | ,'week' => $langs->transnoentitiesnoconv('Week') 110 | ) 111 | ,'xaxis'=>'week' 112 | ,'hAxis'=>array('title'=>$langs->transnoentitiesnoconv('subTitleHAxisGraphCAHoraire')) 113 | ,'vAxis'=>array('title'=>$langs->transnoentitiesnoconv('subTitleVAxisGraphCAHoraire', $rapport_ca_ht)) 114 | ,'explorer'=>$explorer 115 | ) 116 | ); 117 | 118 | // End of page 119 | llxFooter(); -------------------------------------------------------------------------------- /graph_effectif.php: -------------------------------------------------------------------------------- 1 | rights->mandarin->graph->effectif) accessforbidden(); 5 | $langs->load('mandarin@mandarin'); 6 | 7 | $PDOdb = new TPDOdb; 8 | $TData = array(); 9 | 10 | $year_n_1 = GETPOST('year_n_1', 'int'); 11 | if (empty($year_n_1)) $year_n_1 = date('Y')-1; 12 | $year_n = GETPOST('year_n', 'int'); 13 | if (empty($year_n)) $year_n = date('Y'); 14 | 15 | // Formatage du tableau de base 16 | for ($i=1; $i<=53; $i++) $TData[$i] = array('week' => $i, 'permanents'.$year_n_1 => 0, 'effectif'.$year_n_1 => 0, 'permanents'.$year_n => 0, 'effectif'.$year_n => 0); 17 | 18 | $sql_effectif = 'SELECT ue.dda, ue.dds, ue.contrat AS type_contrat 19 | FROM llx_user u 20 | INNER JOIN llx_user_extrafields ue ON (u.rowid = ue.fk_object) 21 | WHERE ue.dda IS NOT NULL'; 22 | 23 | $resql = $db->query($sql_effectif); 24 | $Tab = array(); 25 | if ($resql) 26 | { 27 | while ($line = $db->fetch_object($resql)) 28 | { 29 | $time_date_entree = strtotime($line->dda); 30 | $year_date_entree = date('Y', $time_date_entree); 31 | 32 | $Tab[] = array( 33 | 'time_date_entree' => $time_date_entree 34 | ,'year_date_entree' => $year_date_entree 35 | ,'dda' => $line->dda 36 | ,'dds' => $line->dds 37 | ,'type_contrat' => $line->type_contrat 38 | ); 39 | } 40 | 41 | foreach ($Tab as &$TInfo) 42 | { 43 | $skip_n = $skip_n_1 = false; 44 | 45 | // N-1 46 | if ($TInfo['year_date_entree'] < $year_n_1) $week_start_n_1 = 1; 47 | elseif ($TInfo['year_date_entree'] == $year_n_1) $week_start_n_1 = date('W', $TInfo['time_date_entree']); 48 | else $skip_n_1 = true; 49 | 50 | if (empty($TInfo['dds'])) $week_end_n_1 = 53; 51 | else 52 | { 53 | $time_dds = strtotime($TInfo['dds']); 54 | $year_dds = date('Y', $time_dds); 55 | if ($year_dds < $year_n_1) $skip_n_1 = true; 56 | elseif ($year_dds == $year_n_1) $week_end_n_1 = date('W', $time_dds); 57 | else $week_end_n_1 = 53; 58 | } 59 | 60 | 61 | // N 62 | if ($TInfo['year_date_entree'] < $year_n) $week_start_n = 1; 63 | else $week_start_n = date('W', $TInfo['time_date_entree']); 64 | 65 | if (empty($TInfo['dds'])) $week_end_n = 53; 66 | else 67 | { 68 | $time_dds = strtotime($TInfo['dds']); 69 | $year_dds = date('Y', $time_dds); 70 | if ($year_dds < $year_n) $skip_n = true; 71 | elseif ($year_dds == $year_n) $week_end_n = date('W', $time_dds); 72 | else $week_end_n = 53; 73 | } 74 | 75 | if (!$skip_n_1) 76 | { 77 | for ($i = (int) $week_start_n_1; $i <= (int) $week_end_n_1; $i++) 78 | { 79 | $TData[$i]['effectif'.$year_n_1] += 1; 80 | if ($TInfo['type_contrat'] != 'interim') $TData[$i]['permanents'.$year_n_1] += 1; 81 | } 82 | } 83 | 84 | if (!$skip_n) 85 | { 86 | for ($i = (int) $week_start_n; $i <= (int) $week_end_n; $i++) 87 | { 88 | $TData[$i]['effectif'.$year_n] += 1; 89 | if ($TInfo['type_contrat'] != 'interim') $TData[$i]['permanents'.$year_n] += 1; 90 | } 91 | } 92 | 93 | } 94 | } 95 | 96 | // Begin of page 97 | llxHeader('', $langs->trans('mandarinTitleGraphEffectif'), ''); 98 | 99 | $explorer = new stdClass(); 100 | $explorer->actions = array("dragToZoom", "rightClickToReset"); 101 | 102 | $listeview = new TListviewTBS('graphCACumule'); 103 | print $listeview->renderArray($PDOdb, $TData 104 | ,array( 105 | 'type' => 'chart' 106 | ,'liste'=>array( 107 | 'titre'=>$langs->transnoentitiesnoconv('titleGraphEffectif') 108 | ) 109 | ,'title'=>array( 110 | 'year' => $langs->transnoentitiesnoconv('Year') 111 | ,'week' => $langs->transnoentitiesnoconv('Week') 112 | ) 113 | ,'xaxis'=>'week' 114 | ,'hAxis'=>array('title'=>$langs->transnoentitiesnoconv('subTitleHAxisGraphEffectif')) 115 | ,'vAxis'=>array('title'=>$langs->transnoentitiesnoconv('subTitleVAxisGraphEffectif')) 116 | ,'explorer'=>$explorer 117 | ) 118 | ); 119 | 120 | // End of page 121 | llxFooter(); -------------------------------------------------------------------------------- /graph_total_heure.php: -------------------------------------------------------------------------------- 1 | rights->mandarin->graph->total_heure) accessforbidden(); 5 | $langs->load('mandarin@mandarin'); 6 | 7 | $PDOdb = new TPDOdb; 8 | $TData = array(); 9 | 10 | $year_n_1 = GETPOST('year_n_1', 'int'); 11 | if (empty($year_n_1)) $year_n_1 = date('Y')-1; 12 | $year_n = GETPOST('year_n', 'int'); 13 | if (empty($year_n)) $year_n = date('Y'); 14 | 15 | // Formatage du tableau de base 16 | for ($i=1; $i<=53; $i++) 17 | { 18 | $TData[$i] = array('week' => $i, $year_n_1 => 0, $year_n => 0, 'Dispo CDI' => 0); 19 | } 20 | 21 | $sql_n_1 = 'SELECT WEEKOFYEAR(ppt.task_date) AS `week`, ((SUM(ppt.task_duration) / 3600)) AS total_heure 22 | FROM '.MAIN_DB_PREFIX.'projet_task_time ppt 23 | INNER JOIN '.MAIN_DB_PREFIX.'user_extrafields ue ON (ppt.fk_user = ue.fk_object) 24 | WHERE YEAR(ppt.task_date) = '.$year_n_1.' 25 | AND ue.contrat = "cdi" 26 | GROUP BY `week` 27 | ORDER BY `week` ASC'; 28 | 29 | $resql = $db->query($sql_n_1); 30 | if ($resql) 31 | { 32 | while ($line = $db->fetch_object($resql)) 33 | { 34 | $TData[$line->week][$year_n_1] = $line->total_heure; 35 | } 36 | } 37 | 38 | 39 | $sql_n = 'SELECT WEEKOFYEAR(ppt.task_date) AS `week`, ((SUM(ppt.task_duration) / 3600)) AS total_heure 40 | FROM '.MAIN_DB_PREFIX.'projet_task_time ppt 41 | INNER JOIN '.MAIN_DB_PREFIX.'user_extrafields ue ON (ppt.fk_user = ue.fk_object) 42 | WHERE YEAR(ppt.task_date) = '.$year_n.' 43 | AND ue.contrat = "cdi" 44 | GROUP BY `week` 45 | ORDER BY `week` ASC'; 46 | 47 | $resql = $db->query($sql_n); 48 | if ($resql) 49 | { 50 | while ($line = $db->fetch_object($resql)) 51 | { 52 | $TData[$line->week][$year_n] = $line->total_heure; 53 | } 54 | } 55 | 56 | 57 | $sql_cdi_n = 'SELECT ue.dda, ue.dds, u.weeklyhours 58 | FROM '.MAIN_DB_PREFIX.'user u 59 | INNER JOIN '.MAIN_DB_PREFIX.'user_extrafields ue ON (u.rowid = ue.fk_object) 60 | WHERE ue.contrat = "cdi" 61 | AND u.weeklyhours IS NOT NULL'; 62 | 63 | $resql = $db->query($sql_cdi_n); 64 | $Tab = array(); 65 | if ($resql) 66 | { 67 | while ($line = $db->fetch_object($resql)) 68 | { 69 | $time_date_entree = strtotime($line->dda); 70 | $year_date_entree = date('Y', $time_date_entree); 71 | if ($year_date_entree < $year_n) $week_start = 1; 72 | else $week_start = date('W', $time_date_entree); 73 | 74 | if (empty($line->dds)) $week_end = 53; 75 | else { 76 | $time_dds = strtotime($line->dds); 77 | $year_dds = date('Y', $time_dds); 78 | if ($year_dds < $year_n) continue; 79 | else $week_end = date('W', $time_dds); 80 | } 81 | 82 | $Tab[] = array( 83 | 'week_start' => $week_start 84 | ,'week_end' => $week_end 85 | ,'horaire' => $line->weeklyhours 86 | ); 87 | } 88 | } 89 | 90 | if (count($Tab) > 0) 91 | { 92 | foreach ($Tab as &$TInfo) 93 | { 94 | for ($i=$TInfo['week_start']; $i <= $TInfo['week_end']; $i++) 95 | { 96 | $TData[$i]['Dispo CDI'] += $TInfo['horaire']; // Somme des horaires CDI dispo 97 | } 98 | } 99 | } 100 | 101 | // Begin of page 102 | llxHeader('', $langs->trans('mandarinTitleGraphTotalHeure'), ''); 103 | 104 | $explorer = new stdClass(); 105 | $explorer->actions = array("dragToZoom", "rightClickToReset"); 106 | 107 | $listeview = new TListviewTBS('graphTotalHeure'); 108 | print $listeview->renderArray($PDOdb, $TData 109 | ,array( 110 | 'type' => 'chart' 111 | ,'liste'=>array( 112 | 'titre'=>$langs->transnoentitiesnoconv('titleGraphTotalHeure') 113 | ) 114 | ,'title'=>array( 115 | 'year' => $langs->transnoentitiesnoconv('Year') 116 | ,'week' => $langs->transnoentitiesnoconv('Week') 117 | ) 118 | ,'xaxis'=>'week' 119 | ,'hAxis'=>array('title'=>$langs->transnoentitiesnoconv('subTitleHAxisGraphTotalHeure')) 120 | ,'vAxis'=>array('title'=>$langs->transnoentitiesnoconv('subTitleVAxisGraphTotalHeure')) 121 | ,'explorer'=>$explorer 122 | ) 123 | ); 124 | 125 | // End of page 126 | llxFooter(); -------------------------------------------------------------------------------- /class/actions_mandarin.class.php: -------------------------------------------------------------------------------- 1 | 3 | * Copyright (C) 2015 ATM Consulting 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /** 20 | * \file class/actions_mandarin.class.php 21 | * \ingroup mandarin 22 | * \brief This file is an example hook overload class file 23 | * Put some comments here 24 | */ 25 | 26 | /** 27 | * Class Actionsmandarin 28 | */ 29 | class Actionsmandarin 30 | { 31 | /** 32 | * @var array Hook results. Propagated to $hookmanager->resArray for later reuse 33 | */ 34 | public $results = array(); 35 | 36 | /** 37 | * @var string String displayed by executeHook() immediately after return 38 | */ 39 | public $resprints; 40 | 41 | /** 42 | * @var array Errors 43 | */ 44 | public $errors = array(); 45 | 46 | /** 47 | * Constructor 48 | */ 49 | public function __construct() 50 | { 51 | } 52 | 53 | /** 54 | * Overloading the doActions function : replacing the parent's function with the one below 55 | * 56 | * @param array() $parameters Hook metadatas (context, etc...) 57 | * @param CommonObject &$object The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...) 58 | * @param string &$action Current action (if set). Generally create or edit or null 59 | * @param HookManager $hookmanager Hook manager propagated to allow calling another hook 60 | * @return int < 0 on error, 0 on success, 1 to replace standard code 61 | */ 62 | function addMoreActionsButtons($parameters, &$object, &$action, $hookmanager) 63 | { 64 | 65 | $error = 0; 66 | if (in_array('pricesuppliercard', explode(':', $parameters['context']))) 67 | { 68 | global $conf,$user,$langs; 69 | if ( !empty($conf->global->MANDARIN_TRACE_COST_PRICE) && !empty($user->rights->mandarin->graph->product_cost_price)) { 70 | 71 | 72 | define('INC_FROM_DOLIBARR',true); 73 | dol_include_once('/mandarin/config.php'); 74 | dol_include_once('/mandarin/class/costpricelog.class.php'); 75 | 76 | $PDOdb=new TPDOdb; 77 | 78 | 79 | $TData = TProductCostPriceLog::getDataForProduct($PDOdb, $object->id); 80 | if(!empty($TData)) { 81 | 82 | $l=new TListviewTBS('graphrate'); 83 | echo $l->renderArray($PDOdb, $TData,array( 84 | 'type'=>'chart' 85 | ,'curveType'=>'none' 86 | ,'liste'=>array( 87 | 'titre'=>$langs->trans('GraphTraceCostPrice') 88 | ) 89 | ,'title'=>array( 90 | 'PA'=>$langs->transnoentities('PricePA') 91 | ,'PMP'=>$langs->transnoentities('PricePMP') 92 | ,'OF'=>$langs->transnoentities('PriceOF') 93 | ) 94 | )); 95 | 96 | 97 | ?> 98 | 104 | errors[] = 'Error message'; 121 | return -1; 122 | } 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /graph_horaire_moyen.php: -------------------------------------------------------------------------------- 1 | rights->mandarin->graph->horaire_moyen) accessforbidden(); 5 | $langs->load('mandarin@mandarin'); 6 | 7 | $PDOdb = new TPDOdb; 8 | $TData = array(); 9 | 10 | $year_n_1 = GETPOST('year_n_1', 'int'); 11 | if (empty($year_n_1)) $year_n_1 = date('Y')-1; 12 | $year_n = GETPOST('year_n', 'int'); 13 | if (empty($year_n)) $year_n = date('Y'); 14 | 15 | // Formatage du tableau de base 16 | for ($i=1; $i<=53; $i++) 17 | { 18 | $TData[$i] = array('week' => $i, 'horaire normal'.$year_n_1 => 0, 'horaire normal'.$year_n => 0, 'Dispo CDI' => 0); 19 | } 20 | 21 | $sql_n_1 = 'SELECT WEEKOFYEAR(ppt.task_date) AS `week`, ((SUM(ppt.task_duration) / 3600) / COUNT(DISTINCT ue.fk_object) ) AS total_moyen 22 | FROM llx_projet_task_time ppt 23 | INNER JOIN llx_user_extrafields ue ON (ppt.fk_user = ue.fk_object) 24 | WHERE YEAR(ppt.task_date) = '.$year_n_1.' 25 | AND ue.contrat = "cdi" 26 | GROUP BY `week` 27 | ORDER BY `week` ASC'; 28 | 29 | $resql = $db->query($sql_n_1); 30 | if ($resql) 31 | { 32 | while ($line = $db->fetch_object($resql)) 33 | { 34 | $TData[$line->week]['horaire normal'.$year_n_1] = $line->total_moyen; 35 | } 36 | } 37 | 38 | 39 | $sql_n = 'SELECT WEEKOFYEAR(ppt.task_date) AS `week`, ((SUM(ppt.task_duration) / 3600) / COUNT(DISTINCT ue.fk_object) ) AS total_moyen 40 | FROM llx_projet_task_time ppt 41 | INNER JOIN llx_user_extrafields ue ON (ppt.fk_user = ue.fk_object) 42 | WHERE YEAR(ppt.task_date) = '.$year_n.' 43 | AND ue.contrat = "cdi" 44 | GROUP BY `week` 45 | ORDER BY `week` ASC'; 46 | 47 | $resql = $db->query($sql_n); 48 | if ($resql) 49 | { 50 | while ($line = $db->fetch_object($resql)) 51 | { 52 | $TData[$line->week]['horaire normal'.$year_n] = $line->total_moyen; 53 | } 54 | } 55 | 56 | 57 | $sql_cdi_n = 'SELECT ue.fk_object, ue.dda, ue.dds, u.weeklyhours 58 | FROM llx_user u 59 | INNER JOIN llx_user_extrafields ue ON (u.rowid = ue.fk_object) 60 | WHERE ue.contrat = "cdi" 61 | AND u.weeklyhours IS NOT NULL 62 | AND ue.dda IS NOT NULL'; 63 | 64 | $resql = $db->query($sql_cdi_n); 65 | $Tab = array(); 66 | if ($resql) 67 | { 68 | while ($line = $db->fetch_object($resql)) 69 | { 70 | $time_date_entree = strtotime($line->dda); 71 | $year_date_entree = date('Y', $time_date_entree); 72 | if ($year_date_entree < $year_n) $week_start = 1; 73 | else $week_start = date('W', $time_date_entree); 74 | 75 | if (empty($line->dds)) $week_end = 53; 76 | else { 77 | $time_dds = strtotime($line->dds); 78 | $year_dds = date('Y', $time_dds); 79 | if ($year_dds < $year_n) continue; 80 | else $week_end = date('W', $time_dds); 81 | } 82 | 83 | $Tab[] = array( 84 | 'week_start' => $week_start 85 | ,'week_end' => $week_end 86 | ,'horaire' => $line->weeklyhours 87 | ,'fk_user' => $line->fk_object 88 | ); 89 | } 90 | } 91 | 92 | if (count($Tab) > 0) 93 | { 94 | $NbUserPerWeek = array(); 95 | foreach ($Tab as &$TInfo) 96 | { 97 | for ($i=$TInfo['week_start']; $i <= $TInfo['week_end']; $i++) $NbUserPerWeek[$i][$TInfo['fk_user']] = 1; 98 | } 99 | 100 | foreach ($Tab as &$TInfo) 101 | { 102 | for ($i=$TInfo['week_start']; $i <= $TInfo['week_end']; $i++) 103 | { 104 | $coef = 1; 105 | if (count($NbUserPerWeek[$i]) > 0) $coef = count($NbUserPerWeek[$i]); 106 | $TData[$i]['Dispo CDI'] += $TInfo['horaire'] / $coef; // Somme des horaires CDI dispo 107 | } 108 | } 109 | } 110 | 111 | // Begin of page 112 | llxHeader('', $langs->trans('mandarinTitleGraphHoraireMoyen'), ''); 113 | 114 | $listeview = new TListviewTBS('graphHoraireMoyen'); 115 | print $listeview->renderArray($PDOdb, $TData 116 | ,array( 117 | 'type' => 'chart' 118 | ,'liste'=>array( 119 | 'titre'=>$langs->transnoentitiesnoconv('titleGraphHoraireMoyen') 120 | ) 121 | ,'title'=>array( 122 | 'year' => $langs->transnoentitiesnoconv('Year') 123 | ,'week' => $langs->transnoentitiesnoconv('Week') 124 | ) 125 | ,'xaxis'=>'week' 126 | ,'hAxis'=>array('title'=>$langs->transnoentitiesnoconv('subTitleHAxisGraphHoraireMoyen')) 127 | ,'vAxis'=>array('title'=>$langs->transnoentitiesnoconv('subTitleVAxisGraphHoraireMoyen')) 128 | ) 129 | ); 130 | 131 | // End of page 132 | llxFooter(); -------------------------------------------------------------------------------- /graph_ca_by_month.php: -------------------------------------------------------------------------------- 1 | rights->mandarin->graph->ca_client_month) accessforbidden(); 6 | 7 | llxHeader('', $langs->trans('CAClientMonth'), ''); 8 | 9 | dol_fiche_head(); 10 | 11 | $PDOdb=new TPDOdb; 12 | //$PDOdb->debug=true; 13 | 14 | $year = (int)GETPOST('year'); 15 | if(empty($year))$year=(int)date('Y'); 16 | 17 | $payed=GETPOST('payed'); 18 | $invoiced=GETPOST('invoiced'); 19 | 20 | $TYear = $TMonth = $ColFormat= $ColTotal =array(); 21 | $y = (int)date('Y'); 22 | for($i = $y - 10 ; $i<$y+3; $i++){ $TYear[$i] = $i; } 23 | for($i = 1 ; $i<=12; $i++){ 24 | $TMonth[$i] = $langs->trans('month'. date('M', strtotime(date('Y-'.$i.'-01'))) ).'-'.$year; 25 | $ColFormat[$TMonth[$i]]='number'; 26 | $ColTotal[$TMonth[$i]]='sum'; 27 | 28 | } 29 | $ColFormat['total'] = 'number'; 30 | $ColTotal['total'] = 'sum'; 31 | 32 | $mode = GETPOST('mode'); 33 | 34 | $TData=array(); 35 | 36 | if($mode == 'order') { 37 | //commande non brouillon par date de livraison 38 | $sql = "SELECT commande.fk_soc, SUM(commande.total_ht) as total, MONTH(commande.date_livraison) as 'month' FROM ".MAIN_DB_PREFIX."commande as commande 39 | INNER JOIN ".MAIN_DB_PREFIX."societe as soc ON soc.rowid=commande.fk_soc WHERE commande.fk_statut>0 AND YEAR(commande.date_livraison)=".$year." 40 | ".(empty($invoiced)?'AND facture=0':"AND facture=1")." 41 | GROUP BY commande.fk_soc,soc.nom, MONTH(commande.date_livraison) 42 | ORDER BY soc.nom,MONTH(commande.date_livraison)"; 43 | } 44 | else{ 45 | //facture payée sur date de facturation 46 | $sql = "SELECT fact.fk_soc, SUM(fact.total) as total, MONTH(fact.datef) as 'month' FROM ".MAIN_DB_PREFIX."facture as fact 47 | INNER JOIN ".MAIN_DB_PREFIX."societe as soc ON soc.rowid=fact.fk_soc 48 | WHERE fk_statut>0 ".(empty($payed)?'':"AND paye=1")." AND YEAR(datef)=".$year." 49 | GROUP BY fact.fk_soc,soc.nom, MONTH(fact.datef) 50 | ORDER BY soc.nom,MONTH(fact.datef)"; 51 | } 52 | 53 | $Tab = $PDOdb->ExecuteAsArray($sql); 54 | 55 | foreach($Tab as &$row) { 56 | 57 | if(!isset($TData[$row->fk_soc])) $TData[$row->fk_soc] = _init_line(); 58 | 59 | $TData[$row->fk_soc][$TMonth[(int)$row->month]] = (float)$row->total; 60 | $TData[$row->fk_soc]['total'] += (float)$row->total; 61 | } 62 | 63 | _get_company_object($TData); 64 | //usort($TData, '_sort_company'); 65 | 66 | ?> 67 | 72 | hidden('mode', $mode ); 76 | $headsearch.= $formCore->combo($langs->trans('Year'), 'year', $TYear, $year); 77 | if (empty($mode)) { 78 | $headsearch.= $formCore->checkbox1($langs->trans('Paid'), 'payed', 1, $payed); 79 | } elseif ($mode=='order') { 80 | $headsearch.= $formCore->checkbox1($langs->trans('PropalStatusBilled'), 'invoiced', 1, $invoiced); 81 | } 82 | $headsearch.= $formCore->btsubmit($langs->trans('Ok'),'bt_ok'); 83 | 84 | $listeview = new TListviewTBS('CAClientMonth'); 85 | print $listeview->renderArray($PDOdb, $TData 86 | ,array( 87 | 88 | 'liste'=>array( 89 | 'titre'=>$langs->transnoentitiesnoconv('CAClientMonth') 90 | ,'head_search'=>$headsearch 91 | ) 92 | ,'type'=>$ColFormat 93 | ,'title'=>array( 94 | 'client' => $langs->transnoentitiesnoconv('Company') 95 | ,'total' => $langs->transnoentitiesnoconv('Total') 96 | ,'year' => $langs->transnoentitiesnoconv('Year') 97 | ) 98 | ,'math'=>$ColTotal 99 | ,'export'=>array('CSV') 100 | 101 | ) 102 | ); 103 | 104 | $formCore->end(); 105 | 106 | dol_fiche_end(); 107 | 108 | llxFooter(); 109 | 110 | function _sort_company(&$a, &$b) { 111 | 112 | $r = strcasecmp($a->name, $b->name); 113 | 114 | return empty($r) ? 0 : $r / abs($r); 115 | } 116 | 117 | function _get_company_object(&$TRender){ 118 | global $db,$conf,$langs,$user; 119 | dol_include_once('/societe/class/societe.class.php'); 120 | 121 | foreach($TRender as $fk_soc=>&$line) { 122 | 123 | $s=new Societe($db); 124 | $s->fetch($fk_soc); 125 | 126 | $line['client'] = $s->getNomUrl(); 127 | 128 | } 129 | 130 | } 131 | 132 | function _init_line() { 133 | global $TMonth; 134 | $Tab=array('client'=>''); 135 | 136 | for($i = 1; $i<=12;$i++) { 137 | 138 | $Tab[$TMonth[$i]] = 0; 139 | 140 | } 141 | 142 | $Tab['total'] = 0; 143 | 144 | return $Tab; 145 | 146 | 147 | } 148 | -------------------------------------------------------------------------------- /graph_project.php: -------------------------------------------------------------------------------- 1 | rights->mandarin->graph->project) accessforbidden(); 5 | $langs->load('mandarin@mandarin'); 6 | 7 | $PDOdb = new TPDOdb; 8 | $TData = array(); 9 | 10 | $fk_statut = GETPOST('fk_statut', 'int'); 11 | 12 | $sql = 'SELECT p.rowid, p.ref, p.title, pt.rowid AS fk_task 13 | , (SELECT SUM(task_duration) 14 | FROM '.MAIN_DB_PREFIX.'projet_task_time ptt 15 | LEFT JOIN '.MAIN_DB_PREFIX.'projet_task t ON (t.rowid = ptt.fk_task) 16 | WHERE t.fk_projet = p.rowid) AS temps_reel 17 | , SUM(pt.planned_workload) AS temps_prevu 18 | , SUM(pt.planned_workload * (pt.progress / 100)) AS temps_theorique 19 | FROM '.MAIN_DB_PREFIX.'projet p 20 | LEFT JOIN '.MAIN_DB_PREFIX.'projet_task pt ON (p.rowid = pt.fk_projet) 21 | WHERE p.entity = '.$conf->entity; 22 | 23 | if (!empty($fk_statut)) $sql .= ' AND p.fk_statut = '.$fk_statut; 24 | $sql .= ' GROUP BY p.rowid 25 | ORDER BY p.title'; 26 | 27 | $resql = $db->query($sql); 28 | 29 | if ($resql) 30 | { 31 | while ($line = $db->fetch_object($resql)) 32 | { 33 | 34 | $TData[$line->rowid] = array( 35 | 'name'=>$line->ref.' - '.$line->title 36 | ,'temps_prevu' => $line->temps_prevu 37 | ,'Progression réelle'=>$line->temps_reel 38 | ,'Progression théorique'=> $line->temps_theorique 39 | ); 40 | 41 | } 42 | 43 | $TDataTransform = array(); 44 | foreach ($TData as $fk_project=>&$Tab) 45 | { 46 | $temps_prevu = $Tab['temps_prevu']; 47 | //unset($Tab['temps_prevu']); 48 | 49 | if (empty($temps_prevu)){ 50 | continue; 51 | } 52 | 53 | $TDataTransform[$fk_project] = array( 54 | 'name'=>dol_escape_js($Tab['name']) 55 | 56 | ,'Progression réelle' => $temps_prevu>0 ? round($Tab['Progression réelle'] * 100 / $temps_prevu) : 100 57 | ,'Progression théorique' => $temps_prevu > 0 ? round($Tab['Progression théorique'] * 100 / $temps_prevu) : 100 58 | ); 59 | 60 | $TDataTransform[$fk_project]['Achat'] = _completeAchat($PDOdb, $fk_project); 61 | } 62 | } 63 | //var_dump($TDataTransform); 64 | // Begin of page 65 | llxHeader('', $langs->trans('mandarinTitleGraphProjet'), ''); 66 | 67 | $explorer = new stdClass(); 68 | $explorer->actions = array("dragToZoom", "rightClickToReset"); 69 | 70 | $listeview = new TListviewTBS('graphProject'); 71 | print $listeview->renderArray($PDOdb, $TDataTransform 72 | ,array( 73 | 'type' => 'chart' 74 | ,'chartType' => 'ColumnChart' 75 | ,'liste'=>array( 76 | 'titre'=>$langs->transnoentitiesnoconv('titleGraphProject') 77 | ) 78 | ,'hAxis'=>array('title'=>$langs->transnoentitiesnoconv('subTitleHAxisGraphProject')) 79 | ,'vAxis'=>array('title'=>$langs->transnoentitiesnoconv('subTitleVAxisGraphProject')) 80 | ,'explorer'=>$explorer 81 | ) 82 | ); 83 | 84 | // End of page 85 | llxFooter(); 86 | 87 | function _completeAchat(&$PDOdb, $fk_project) { 88 | //TODO comment calculer les achats théorique / réel ? 89 | 90 | // méthode 1 PA propal / PA Commande Founisseur ? 91 | //TODO methode en conf 92 | 93 | $PDOdb->Execute("SELECT SUM(d.buy_price_ht * d.qty) as total_achat_prevu 94 | FROM ".MAIN_DB_PREFIX."commandedet d 95 | LEFT JOIN ".MAIN_DB_PREFIX."commande p ON (p.rowid=d.fk_commande) 96 | WHERE p.fk_projet=".$fk_project); 97 | $obj = $PDOdb->Get_line(); 98 | $total_achat_prevu = $obj->total_achat_prevu; 99 | 100 | if(empty($total_achat_prevu)) { 101 | $PDOdb->Execute("SELECT SUM(d.buy_price_ht * d.qty) as total_achat_prevu 102 | FROM ".MAIN_DB_PREFIX."propaldet d 103 | LEFT JOIN ".MAIN_DB_PREFIX."propal p ON (p.rowid=d.fk_propal) 104 | WHERE p.fk_projet=".$fk_project); 105 | $obj = $PDOdb->Get_line(); 106 | $total_achat_prevu = $obj->total_achat_prevu; 107 | } 108 | 109 | $PDOdb->Execute("SELECT SUM(d.total_ht) as total_achat_effectue 110 | FROM ".MAIN_DB_PREFIX."commande_fournisseurdet d 111 | LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseur p ON (p.rowid=d.fk_commande) 112 | WHERE p.fk_projet=".$fk_project); 113 | $obj = $PDOdb->Get_line(); 114 | 115 | $total_achat_effectue = $obj->total_achat_effectue; 116 | if(empty($total_achat_effectue)) { 117 | 118 | $PDOdb->Execute("SELECT SUM(d.total_ht) as total_achat_effectue 119 | FROM ".MAIN_DB_PREFIX."facture_fourn_det d 120 | LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn p ON (p.rowid=d.fk_facture_fourn) 121 | WHERE p.fk_projet=".$fk_project); 122 | $obj = $PDOdb->Get_line(); 123 | $total_achat_effectue = $obj->total_achat_effectue; 124 | } 125 | //var_dump($total_achat_effectue , $total_achat_prevu ,round($total_achat_effectue / $total_achat_prevu * 100)); 126 | return $total_achat_prevu>0 ? round($total_achat_effectue / $total_achat_prevu * 100) : 100; 127 | 128 | 129 | return 0; 130 | 131 | } 132 | -------------------------------------------------------------------------------- /report_repartition_achats_fournisseurs.php: -------------------------------------------------------------------------------- 1 | trans('mandarinTitleRepartitionAchatsFournisseurs', strtolower($langs->trans('Supplier'))), ''); 43 | print_fiche_titre($langs->trans('mandarinTitleRepartitionAchatsFournisseurs', strtolower($langs->trans('Supplier')))); 44 | 45 | if(empty($user->rights->mandarin->list->repartition_by_supplier)) accessforbidden('', 0); 46 | 47 | switch ($action) { 48 | case 'report': 49 | _print_form_repartition_achats($date_debut, $date_fin); 50 | _print_repartition_achats($date_debut, $date_fin); 51 | break; 52 | default: 53 | _print_form_repartition_achats($date_debut, $date_fin); 54 | break; 55 | } 56 | 57 | function _print_form_repartition_achats($date_debut, $date_fin) { 58 | 59 | global $db, $form, $formother, $langs; 60 | 61 | print '
'; 62 | print ''; 63 | print $langs->trans('Période d\'analyse').', Du '; 64 | $form->select_date($date_debut, 'date_debut', 0, 0, 0, '', 1, 1); 65 | print 'Au '; 66 | $form->select_date($date_fin, 'date_fin', 0, 0, 0, '', 1, 1); 67 | print ''; 68 | print '
'; 69 | 70 | print '
'; 71 | 72 | } 73 | 74 | function _print_repartition_achats($date_debut, $date_fin) { 75 | 76 | global $conf, $db, $langs, $sortfield, $sortorder, $param, $bc; 77 | 78 | $sql = 'SELECT soc.rowid, soc.nom, SUM(facf.total_ht) as mt_total_ht_fournisseur, (SELECT SUM(facf.total_ht) FROM '.MAIN_DB_PREFIX.'facture_fourn facf WHERE facf.datef BETWEEN "'.$date_debut.'" AND "'.$date_fin.'") as mt_total_ht 79 | FROM '.MAIN_DB_PREFIX.'facture_fourn facf 80 | INNER JOIN '.MAIN_DB_PREFIX.'societe soc ON (soc.rowid = facf.fk_soc) 81 | WHERE facf.datef BETWEEN "'.$date_debut.'" AND "'.$date_fin.'" 82 | GROUP BY soc.rowid'; 83 | 84 | $sql.= $db->order($sortfield,$sortorder); 85 | 86 | $resql = $db->query($sql); 87 | 88 | if(!empty($resql)) { 89 | 90 | print ''; 91 | print ''; 92 | print_liste_field_titre($langs->trans('Supplier'),$_SERVER['PHP_SELF'],'soc.nom','',$param,'',$sortfield,$sortorder); 93 | print_liste_field_titre($langs->trans('TotalHT'),$_SERVER['PHP_SELF'],'mt_total_ht_fournisseur','',$param,'',$sortfield,$sortorder); 94 | print_liste_field_titre($langs->trans('Percent'),$_SERVER['PHP_SELF'],'mt_total_ht_fournisseur','',$param,'',$sortfield,$sortorder); 95 | print ''; 96 | 97 | $var=0; 98 | $soc = new Societe($db); 99 | 100 | while($res = $db->fetch_object($resql)) { 101 | 102 | $percent = $res->mt_total_ht_fournisseur / $res->mt_total_ht * 100; 103 | 104 | if(!empty($conf->global->MANDARIN_POURCENTAGE_ALERTE) 105 | && $percent > $conf->global->MANDARIN_POURCENTAGE_ALERTE) $plus = ' bgcolor="#F5A9A9" style="font-weight:bold;"'; 106 | else $plus = $bc[$var]; 107 | 108 | print ''; 109 | $soc->fetch($res->rowid); 110 | print ''; 111 | 112 | print ''; 113 | print ''; 114 | print ''; 115 | $var=!$var; 116 | 117 | } 118 | 119 | print '
'.$soc->getNomUrl(1).''.price($res->mt_total_ht_fournisseur, 0, $langs, 1, -1, -1, 'EUR').''.price($percent, 0, $langs, 1, -1, 2).' %
'; 120 | 121 | } 122 | 123 | } 124 | -------------------------------------------------------------------------------- /graph_timeSpent_exceed.php: -------------------------------------------------------------------------------- 1 | rights->mandarin->graph->project) accesfobidden(); 7 | 8 | 9 | llxHeader('',$langs->trans('ReportExceed')); 10 | print dol_get_fiche_head('Projets en dépassement'); 11 | print_fiche_titre($langs->trans("Projets en dépassement")); 12 | printRapport(); 13 | 14 | 15 | function printRapport(){ 16 | global $db; 17 | 18 | dol_include_once('/core/lib/date.lib.php'); 19 | $fk_statut=GETPOST("fk_statut"); 20 | 21 | 22 | ?> 23 | 30 | 31 |
32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | fetch($projet->socid); 60 | ?> 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 |
ProjetSociétéDate débutDate FinTemps prévuTemps passéDépassement
getNomUrl(1) ?>getNomUrl(1) ?>date_start)) ?>date_end !=null) ? date('d/m/Y', intval($projet->date_end)) : ""?> > > >
Totaux
86 |
87 | 88 | query($sql); 102 | if ($resql) 103 | { 104 | while ($line = $db->fetch_object($resql)) 105 | { 106 | $timespent=0; 107 | $timeplanned=0; 108 | $exceed=0; 109 | 110 | $projet = new Project($db); 111 | $projet->fetch($line->id); 112 | $TTask = getTaskFromProjet($projet->id); 113 | 114 | foreach ($TTask as $task){ 115 | $timespent+=$task->duration_effective; 116 | $timeplanned+=$task->planned_workload; 117 | $exceed+=$timespent-$timeplanned; 118 | } 119 | 120 | if ($timeplanned != 0)$percentage = ($timespent/$timeplanned)*100; 121 | else if($timespent > $timeplanned)$percentage = 100; 122 | else $percentage = 0; 123 | 124 | if($percentage >= 80){ 125 | $TProject[]= array( 126 | 'projet' => $projet, 127 | 'timespent' => $timespent, 128 | 'timeplanned' => $timeplanned, 129 | 'exceed' => $exceed > 0 ? $exceed : 0, 130 | 'percentage' => $percentage 131 | ); 132 | } 133 | } 134 | } 135 | 136 | //var_dump($sql); 137 | return $TProject; 138 | } 139 | 140 | 141 | function getTaskFromProjet($idProjet){ 142 | global $db; 143 | 144 | $TTask==array(); 145 | 146 | $sql = "SELECT rowid "; 147 | $sql .= "FROM ".MAIN_DB_PREFIX."projet_task "; 148 | $sql .= "WHERE fk_projet=".$idProjet; 149 | $resql = $db->query($sql); 150 | if ($resql) 151 | { 152 | while ($line = $db->fetch_object($resql)) 153 | { 154 | $task = new Task($db); 155 | $task->fetch($line->rowid); 156 | //TODO ajouter cette putain de tache au tableau TTaches 157 | $TTask[]=$task; 158 | } 159 | } 160 | return $TTask; 161 | 162 | 163 | } 164 | -------------------------------------------------------------------------------- /graph_cost_price.php: -------------------------------------------------------------------------------- 1 | rights->mandarin->graph->product_cost_price) accessforbidden(); 5 | 6 | dol_include_once('/product/class/product.class.php'); 7 | 8 | $langs->load('mandarin@mandarin'); 9 | $langs->load('of@of'); 10 | $langs->load('quality@quality'); 11 | $langs->load('nomenclature@nomenclature'); 12 | 13 | $PDOdb = new TPDOdb; 14 | 15 | llxHeader('', $langs->trans('RapportAnalyseCoutProduct'), ''); 16 | dol_fiche_head(); 17 | 18 | $sql="SELECT l.fk_product, ROUND(SUM(l.qty),3) as qty, ROUND(SUM(l.qty_used),3) as qty_used, '' as percent 19 | FROM ".MAIN_DB_PREFIX."assetOf_line l 20 | WHERE l.type='NEEDED' 21 | GROUP BY l.fk_product"; 22 | 23 | $formCore=new TFormCore('auto','formGraph'); 24 | 25 | $listeview = new TListviewTBS('graphCost'); 26 | //$PDOdb->debug=true; 27 | print $listeview->render($PDOdb, $sql,array( 28 | 'liste'=>array( 29 | 'titre'=>$langs->transnoentitiesnoconv('RapportAnalyseCoutProductMP') 30 | ) 31 | ,'eval'=>array( 32 | 33 | 'fk_product'=>'_product_link(@fk_product@)' 34 | ,'percent'=>'_get_percent(@qty@,@qty_used@)' 35 | ) 36 | ,'type'=>array( 37 | 'qty'=>'number' 38 | ,'qty_used'=>'number' 39 | ,'date_maj'=>'date' 40 | ) 41 | ,'title'=>array( 42 | 'fk_product'=>$langs->trans('Product') 43 | ,'qty'=>$langs->trans('Qty') 44 | ,'qty_used'=>$langs->trans('QtyUsed') 45 | ,'percent'=>$langs->trans('Percent') 46 | ,'date_maj'=>$langs->trans('Date') 47 | ) 48 | ,'search'=>array( 49 | 'date_maj'=>array('recherche'=>'calendars','table'=>'l') 50 | ) 51 | )); 52 | 53 | $formCore->end(); 54 | 55 | if(!empty($conf->nomenclature->enabled)) { 56 | echo '
'; 57 | 58 | $formCore=new TFormCore('auto','formGraph2'); 59 | //TODO je présume qu'ils veulent un recalcule des prix en fonction de la période ? 60 | $sql="SELECT l.fk_product, ROUND(SUM(l.qty_used),3) as qty,l.fk_nomenclature"; 61 | 62 | if(!empty($conf->global->NOMENCLATURE_ACTIVATE_DETAILS_COSTS)) { 63 | $sql.=", n.totalPRCMO_PMP,n.totalPRCMO_OF,n.totalPRCMO"; 64 | } 65 | 66 | $sql.=" FROM ".MAIN_DB_PREFIX."assetOf_line l 67 | INNER JOIN ".MAIN_DB_PREFIX."nomenclature n ON (n.rowid=l.fk_nomenclature) 68 | WHERE l.type='TO_MAKE' 69 | GROUP BY l.fk_product,l.fk_nomenclature"; 70 | 71 | 72 | $listeview = new TListviewTBS('graphCost2'); 73 | //$PDOdb->debug=true; 74 | print $listeview->render($PDOdb, $sql,array( 75 | 'liste'=>array( 76 | 'titre'=>$langs->transnoentitiesnoconv('RapportAnalyseCoutProductPF') 77 | ) 78 | ,'link'=>array( 79 | 'fk_nomenclature'=>''.img_picto($langs->trans('Nomenclature'),'object_list').' @val@' 80 | ) 81 | ,'eval'=>array( 82 | 'fk_product'=>'_product_link(@fk_product@)' 83 | ) 84 | ,'type'=>array( 85 | 'qty'=>'number' 86 | ,'totalPRCMO'=>'number' 87 | ,'totalPRCMO_PMP'=>'number' 88 | ,'totalPRCMO_OF'=>'number' 89 | ,'date_maj'=>'date' 90 | ) 91 | ,'title'=>array( 92 | 'fk_product'=>$langs->trans('Product') 93 | ,'qty'=>$langs->trans('Qty') 94 | ,'totalPRCMO'=>$langs->trans('PricePA') 95 | ,'totalPRCMO_PMP'=>$langs->trans('PricePMP') 96 | ,'totalPRCMO_OF'=>$langs->trans('PriceOF') 97 | ,'date_maj'=>$langs->trans('Date') 98 | ,'fk_nomenclature'=>$langs->trans('Nomenclature') 99 | ) 100 | ,'search'=>array( 101 | 'date_maj'=>array('recherche'=>'calendars','table'=>'l') 102 | ) 103 | )); 104 | 105 | $formCore->end(); 106 | 107 | 108 | } 109 | 110 | if(!empty($conf->quality->enabled)) { 111 | echo '
'; 112 | 113 | dol_include_once('/quality/class/quality.class.php'); 114 | 115 | $sql="SELECT l.fk_product, q.code, q.qty, q.date_cre, q.comment 116 | FROM ".MAIN_DB_PREFIX."assetOf_line l 117 | INNER JOIN ".MAIN_DB_PREFIX."quality q ON (q.fk_object = l.rowid AND q.type_object = 'TAssetOFLine') 118 | WHERE l.type='NEEDED' AND q.code!='NORMAL' AND q.qty!=0 119 | "; 120 | 121 | $formCore=new TFormCore('auto','formGraph3'); 122 | 123 | $listeview = new TListviewTBS('graphCost3'); 124 | //$PDOdb->debug=true; 125 | print $listeview->render($PDOdb, $sql,array( 126 | 'liste'=>array( 127 | 'titre'=>$langs->transnoentitiesnoconv('RapportAnalyseMotifRebus') 128 | ) 129 | ,'eval'=>array( 130 | 131 | 'fk_product'=>'_product_link(@fk_product@)' 132 | 133 | ) 134 | ,'translate'=>array( 135 | 'code'=>TC_quality::getAll($PDOdb, true) 136 | ) 137 | ,'type'=>array( 138 | 'qty'=>'number' 139 | ,'date_cre'=>'date' 140 | ) 141 | ,'title'=>array( 142 | 'fk_product'=>$langs->trans('Product') 143 | ,'qty'=>$langs->trans('Qty') 144 | ,'comment'=>$langs->trans('Comment') 145 | ,'code'=>$langs->trans('Code') 146 | ,'date_cre'=>$langs->trans('Date') 147 | ) 148 | ,'search'=>array( 149 | 'date_cre'=>array('recherche'=>'calendars','table'=>'l') 150 | ) 151 | )); 152 | 153 | $formCore->end(); 154 | 155 | } 156 | 157 | dol_fiche_end(); 158 | // End of page 159 | llxFooter(); 160 | 161 | function _get_percent($qty,$qty_used) { 162 | 163 | $percent =( ($qty_used - $qty) / $qty )* 100; 164 | 165 | $color = ''; 166 | if($percent>0.5) $color = 'red'; 167 | else if($percent<-0.5) $color = 'orange'; 168 | 169 | return ''.price($percent,'','',1,2,2).'%'; 170 | } 171 | 172 | function _product_link($fk_product) { 173 | global $db,$langs,$conf; 174 | 175 | $p=new Product($db); 176 | $p->fetch($fk_product); 177 | 178 | return $p->getNomUrl(1).' '.$p->label; 179 | 180 | } 181 | -------------------------------------------------------------------------------- /graph_time_period.php: -------------------------------------------------------------------------------- 1 | trans('RapportCapaciteProduction')); 11 | 12 | 13 | _print_tab_header(); 14 | 15 | print dol_get_fiche_head($langs->trans('RapportCapaciteProduction')); 16 | print_fiche_titre($langs->trans("Capacité de production par période")); 17 | 18 | 19 | _print_filtres(); 20 | print_rapport(); 21 | 22 | 23 | 24 | function print_rapport(){ 25 | global $langs; 26 | 27 | 28 | $date_d=preg_replace('/\//','-',GETPOST('date_deb')); 29 | $date_f=preg_replace('/\//','-',GETPOST('date_fin')); 30 | $date_deb=date('Y-m-d', strtotime($date_d)); 31 | $date_fin=date('Y-m-d', strtotime($date_f)); 32 | 33 | if(empty(GETPOST('date_deb')))$date_deb=date('Y-m-d', strtotime(date('Y-m-d'))-(60*60*24*7)); 34 | if(empty(GETPOST('date_fin')))$date_fin=date('Y-m-d'); 35 | 36 | 37 | 38 | $PDOdb = new TPDOdb; 39 | 40 | $interval = (strtotime($date_fin) - strtotime($date_deb))/3600/24; 41 | $TDataBrut = get_user_capacity_period($date_deb, $date_fin); 42 | $TData = array(); 43 | $total_temps_saisi =0; 44 | 45 | $hours_to_work = _get_hours_to_work($interval); 46 | $capacity = $hours_to_work/$interval; 47 | foreach ($TDataBrut as $ligne){ 48 | $TData[]=array( 49 | 'task_date' => $ligne['task_date'], 50 | 'duree' => $ligne['duree'], 51 | 'capacity' => $capacity 52 | ); 53 | $total_temps_saisi = $ligne['total']; 54 | } 55 | 56 | $explorer = new stdClass(); 57 | $explorer->actions = array("dragToZoom", "rightClickToReset"); 58 | 59 | $listeview = new TListviewTBS('graphProject'); 60 | print $listeview->renderArray($PDOdb, $TData 61 | ,array( 62 | 'type' => 'chart' 63 | ,'chartType' => 'ColumnChart' 64 | ,'liste'=>array( 65 | 'titre'=> $langs->transnoentities('timeInput') 66 | ) 67 | ,'hAxis'=>array('title'=> 'Date') 68 | ,'vAxis'=>array('title'=> 'Temps') 69 | ,'explorer'=>$explorer 70 | ) 71 | ); 72 | 73 | print_fiche_titre($langs->trans("Temps saisis/capacité de production")); 74 | 75 | 76 | $percentage = round(($total_temps_saisi/$hours_to_work) * 100, 2); 77 | ?> 78 |
79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 |
Pourcentage heures saisies/capacité de production :80 ? 'style="font-weight : bold; color : green;"' : 'style="font-weight : bold; color : red;"' ?>> %
87 |
88 | query($sql); 111 | 112 | if ($resql){ 113 | while ($line = $db->fetch_object($resql)){ 114 | $Total_saisi += $line->task_duration/3600; 115 | $TData[$line->rowid] = array( 116 | 'task_date' =>date('d/m/Y', strtotime($line->task_date)) 117 | ,'duree' => $line->task_duration/3600 118 | ,'total' => $Total_saisi 119 | ); 120 | 121 | } 122 | } 123 | return $TData; 124 | } 125 | 126 | 127 | function _print_tab_header(){ 128 | global $db, $langs; 129 | 130 | 131 | $form = new Form($db); 132 | $object=new User($db); 133 | $userId=GETPOST('id'); 134 | $object->fetch($userId); 135 | 136 | if ($dolversion>=3.9) dol_banner_tab($object,'id',$linkback,$user->rights->user->user->lire || $user->admin); 137 | 138 | } 139 | 140 | 141 | function _print_filtres(){ 142 | global $db, $langs; 143 | 144 | $id=(int) GETPOST('id'); 145 | 146 | $Tform = new TFormCore($_SERVER["PHP_SELF"],'formFiltres', 'POST'); 147 | _get_filtre($Tform); 148 | } 149 | 150 | 151 | function _get_filtre($form){ 152 | 153 | print '
'; 154 | print ''; 155 | print ''; 156 | print ''; 157 | print ''; 158 | print ''; 159 | print ''; 160 | print ''; 161 | print ''; 162 | print ''; 163 | 164 | print ''; 165 | print '
Date de début : '.$form->calendrier('', 'date_deb', ($_REQUEST['date_deb'])? $_REQUEST['date_deb'] : '').'
Date de fin : '.$form->calendrier('', 'date_fin', ($_REQUEST['date_fin'])? $_REQUEST['date_fin'] : '').'
'.$form->btsubmit('Valider', '').'
'; 166 | 167 | print '
'; 168 | } 169 | 170 | 171 | function _get_hours_to_work($interval){ 172 | global $db; 173 | 174 | 175 | $sql = 'SELECT usr.rowid FROM '.MAIN_DB_PREFIX.'user usr WHERE usr.statut=1'; 176 | $resql = $db->query($sql); 177 | $total_hourstowork = 0; 178 | if ($resql){ 179 | while ($line = $db->fetch_object($resql)){ 180 | $user = new User($db); 181 | $user->fetch($line->rowid); 182 | $total_hourstowork += ($user->weeklyhours/7)*$interval; 183 | } 184 | } 185 | return $total_hourstowork; 186 | } 187 | -------------------------------------------------------------------------------- /list_diff_by_commercial.php: -------------------------------------------------------------------------------- 1 | rights->mandarin->list->diff_by_commercial) accessforbidden(); 11 | 12 | llxHeader('', $langs->trans('titleGraphByCommercial'), ''); 13 | 14 | dol_fiche_head(); 15 | 16 | $PDOdb=new TPDOdb; 17 | //$PDOdb->debug=true; 18 | 19 | $TUser = array(); 20 | 21 | 22 | 23 | $date_start_p = dol_mktime(0, 0, 0, GETPOST('startpmonth'), GETPOST('startpday'), GETPOST('startpyear')); 24 | $date_end_p = dol_mktime(23, 59, 59, GETPOST('endpmonth'), GETPOST('endpday'), GETPOST('endpyear')); 25 | 26 | $date_start_c = dol_mktime(0, 0, 0, GETPOST('startcmonth'), GETPOST('startcday'), GETPOST('startcyear')); 27 | $date_end_c = dol_mktime(23, 59, 59, GETPOST('endcmonth'), GETPOST('endcday'), GETPOST('endcyear')); 28 | 29 | $TData=array(); 30 | 31 | $sql = 'SELECT p.fk_user_valid, SUM(p.total_ht) as propal_amout_ht, SUM(p.total) as propal_amout_ttc'; 32 | $sql.= ' FROM '.MAIN_DB_PREFIX.'propal p'; 33 | $sql.= ' WHERE p.fk_statut IN ('.Propal::STATUS_SIGNED.', '.Propal::STATUS_BILLED.')'; 34 | if (!empty($date_start_p)) $sql.= ' AND p.date_valid >= "'.date('Y-m-d H:i:s', $date_start_p).'"'; 35 | if (!empty($date_end_p)) $sql.= ' AND p.date_valid <= "'.date('Y-m-d H:i:s', $date_end_p).'"'; 36 | $sql.= ' GROUP BY p.fk_user_valid'; 37 | 38 | $Tab = $PDOdb->ExecuteAsArray($sql); 39 | 40 | foreach($Tab as &$row) 41 | { 42 | if (!isset($TUser[$row->fk_user_valid])) 43 | { 44 | $u = new User($db); 45 | $u->fetch($row->fk_user_valid); 46 | $TUser[$row->fk_user_valid] = $u; 47 | } 48 | 49 | $TData[$row->fk_user_valid] = array( 50 | 'commercial' => $TUser[$row->fk_user_valid]->getNomUrl() 51 | ,'propal_amount_ht' => $row->propal_amout_ht 52 | ,'propal_amount_ttc' => $row->propal_amout_ttc 53 | ); 54 | } 55 | 56 | 57 | $sql = 'SELECT c.fk_user_valid, SUM(c.total_ht) as commande_amout_ht, SUM(c.total_ttc) as commande_amout_ttc'; 58 | $sql.= ' FROM '.MAIN_DB_PREFIX.'commande c'; 59 | $sql.= ' WHERE c.fk_statut IN ('.Commande::STATUS_VALIDATED.', '.Commande::STATUS_ACCEPTED.')'; 60 | if (!empty($date_start_c)) $sql.= ' AND c.date_valid >= "'.date('Y-m-d H:i:s', $date_start_c).'"'; 61 | if (!empty($date_end_c)) $sql.= ' AND c.date_valid <= "'.date('Y-m-d H:i:s', $date_end_c).'"'; 62 | $sql.= ' GROUP BY c.fk_user_valid'; 63 | 64 | $Tab = $PDOdb->ExecuteAsArray($sql); 65 | 66 | 67 | foreach($Tab as &$row) 68 | { 69 | if (!isset($TUser[$row->fk_user_valid])) 70 | { 71 | $u = new User($db); 72 | $u->fetch($row->fk_user_valid); 73 | $TUser[$row->fk_user_valid] = $u; 74 | } 75 | 76 | $TData[$row->fk_user_valid]['commercial'] = $TUser[$row->fk_user_valid]->getNomUrl(); 77 | $TData[$row->fk_user_valid]['commande_amount_ht'] = $row->commande_amout_ht; 78 | $TData[$row->fk_user_valid]['commande_amount_ttc'] = $row->commande_amout_ttc; 79 | } 80 | 81 | foreach ($TData as $fk_user => &$TInfo) 82 | { 83 | if (!isset($TInfo['propal_amount_ht'])) $TInfo['propal_amount_ht'] = 0; 84 | if (!isset($TInfo['propal_amount_ttc'])) $TInfo['propal_amount_ttc'] = 0; 85 | if (!isset($TInfo['commande_amount_ht'])) $TInfo['commande_amount_ht'] = 0; 86 | if (!isset($TInfo['commande_amount_ttc'])) $TInfo['commande_amount_ttc'] = 0; 87 | 88 | $TInfo['diff_ht'] = abs($TInfo['propal_amount_ht'] - $TInfo['commande_amount_ht']); 89 | $TInfo['diff_ttc'] = abs($TInfo['propal_amount_ttc'] - $TInfo['commande_amount_ttc']); 90 | } 91 | 92 | 93 | // TODO terminer l'affichage 94 | 95 | 96 | 97 | $formCore=new TFormCore('auto','form2', 'get'); 98 | 99 | // print 2x datepicker 100 | $form = new Form($db); 101 | 102 | $headsearch='Dates Propal '; 103 | $headsearch.=$form->select_date($date_start_p, 'startp', 0, 0, 1, '', 1, 0, 1, 0); 104 | $headsearch.=$form->select_date($date_end_p, 'endp', 0, 0, 1, '', 1, 0, 1, 0); 105 | 106 | $headsearch.='Dates Commande '; 107 | $headsearch.=$form->select_date($date_start_c, 'startc', 0, 0, 1, '', 1, 0, 1, 0); 108 | $headsearch.=$form->select_date($date_end_c, 'endc', 0, 0, 1, '', 1, 0, 1, 0); 109 | 110 | $headsearch.= $formCore->btsubmit($langs->trans('Ok'),'bt_ok'); 111 | 112 | $ColFormat = array( 113 | 'commercial' => 'string' 114 | ,'propal_amount_ht' => 'number' 115 | ,'propal_amount_ttc' => 'number' 116 | ,'commande_amount_ht' => 'number' 117 | ,'commande_amount_ttc' => 'number' 118 | ,'diff_ht' => 'number' 119 | ,'diff_ttc' => 'number' 120 | ); 121 | $ColTotal = array( 122 | 'propal_amount_ht' => 'sum' 123 | ,'propal_amount_ttc' => 'sum' 124 | ,'commande_amount_ht' => 'sum' 125 | ,'commande_amount_ttc' => 'sum' 126 | ,'diff_ht' => 'sum' 127 | ,'diff_ttc' => 'sum' 128 | ); 129 | 130 | $listeview = new TListviewTBS('titleGraphByCommercial'); 131 | print $listeview->renderArray($PDOdb, $TData 132 | ,array( 133 | 134 | 'liste'=>array( 135 | 'titre'=>$langs->transnoentitiesnoconv('titleGraphByCommercial') 136 | ,'head_search'=>$headsearch 137 | ) 138 | ,'type'=>$ColFormat 139 | ,'title'=>array( 140 | 'commercial' => $langs->transnoentitiesnoconv('commercial') 141 | ,'propal_amount_ht' => $langs->transnoentitiesnoconv('propal_amount_ht') 142 | ,'propal_amount_ttc' => $langs->transnoentitiesnoconv('propal_amount_ttc') 143 | ,'commande_amount_ht' => $langs->transnoentitiesnoconv('commande_amount_ht') 144 | ,'commande_amount_ttc' => $langs->transnoentitiesnoconv('commande_amount_ttc') 145 | ,'diff_ht' => $langs->transnoentitiesnoconv('diff_ht') 146 | ,'diff_ttc' => $langs->transnoentitiesnoconv('diff_ttc') 147 | ) 148 | ,'math'=>$ColTotal 149 | ,'export'=>array('CSV') 150 | 151 | ) 152 | ); 153 | 154 | ?> 155 | 164 | end(); 167 | 168 | dol_fiche_end(); 169 | 170 | llxFooter(); 171 | 172 | -------------------------------------------------------------------------------- /graph_product_receipt_time_average.php: -------------------------------------------------------------------------------- 1 | rights->mandarin->graph->products_receipt_average) accessforbidden(); 8 | $langs->load('mandarin@mandarin'); 9 | 10 | $action = GETPOST('action'); 11 | $fk_soc = GETPOST('fk_soc'); 12 | $date_deb = GETPOST('date_deb'); 13 | $date_fin = GETPOST('date_fin'); 14 | 15 | switch($action) { 16 | 17 | case 'print_data': 18 | llxHeader('', $langs->trans('RapportTempsMoyenReceptionProduits'), ''); 19 | print dol_get_fiche_head('RapportTempsMoyenReceptionProduits'); 20 | print_fiche_titre($langs->trans('RapportTempsMoyenReceptionProduits')); 21 | print_form_filter($date_deb, $date_fin, $fk_soc); 22 | $TData = get_data_tab($date_deb, $date_fin, $fk_soc); 23 | if(!empty($TData)) draw_table($TData); 24 | break; 25 | 26 | case 'download_file': 27 | $TData = get_data_tab($date_deb, $date_fin, $fk_soc); 28 | download_file($TData); 29 | break; 30 | 31 | default: 32 | llxHeader('', $langs->trans('RapportTempsMoyenReceptionProduits'), ''); 33 | print dol_get_fiche_head('RapportTempsMoyenReceptionProduits'); 34 | print_fiche_titre($langs->trans('RapportTempsMoyenReceptionProduits')); 35 | print_form_filter($date_deb, $date_fin, $fk_soc); 36 | 37 | } 38 | 39 | llxFooter(); 40 | 41 | function print_form_filter($date_deb, $date_fin, $fk_soc) { 42 | 43 | global $db, $langs; 44 | 45 | $langs->load('users'); 46 | 47 | $form = new Form($db); 48 | 49 | print '
'; 50 | 51 | print ''; 52 | 53 | print $langs->trans('Supplier').'  '; 54 | print $form->select_company($fk_soc, 'fk_soc', ' fournisseur = 1', 1); 55 | 56 | print '

'; 57 | 58 | $date_deb_t = dol_mktime(0, 0, 0, GETPOST('date_debmonth'), GETPOST('date_debday'), GETPOST('date_debyear')); 59 | $date_fin_t = dol_mktime(0, 0, 0, GETPOST('date_finmonth'), GETPOST('date_finday'), GETPOST('date_finyear')); 60 | 61 | print 'Du  '; 62 | $form->select_date(empty($date_deb) ? false : $date_deb_t, 'date_deb', 0, 0, 0, '', 1, 1); 63 | print '
Au  '; 64 | $form->select_date(empty($date_fin) ? false : $date_fin_t, 'date_fin', 0, 0, 0, '', 1, 1); 65 | print '

'; 66 | 67 | print ''; 68 | 69 | print '
'; 70 | 71 | print '
'; 72 | 73 | } 74 | 75 | function get_data_tab($date_deb, $date_fin, $fk_soc) { 76 | 77 | global $db; 78 | 79 | if(empty($date_deb) || empty($date_fin)){ 80 | setEventMessage('Renseignez une date de début et de fin', 'warnings'); 81 | return 0; 82 | } 83 | 84 | $TData = array(); 85 | 86 | $sql = 'SELECT cfd.fk_product as id_prod, p.label as label_prod, DATEDIFF(cf.date_commande, rec.datec) as nb_days_diff 87 | FROM '.MAIN_DB_PREFIX.'commande_fournisseurdet cfd 88 | INNER JOIN '.MAIN_DB_PREFIX.'commande_fournisseur cf ON(cf.rowid = cfd.fk_commande) 89 | LEFT JOIN '.MAIN_DB_PREFIX.'product p ON(p.rowid = cfd.fk_product) 90 | INNER JOIN '.MAIN_DB_PREFIX.'commande_fournisseur_dispatch rec ON (rec.fk_commandefourndet = cfd.rowid) 91 | WHERE cf.fk_statut >= 3'; 92 | 93 | if($fk_soc > 0) $sql.= ' AND cf.fk_soc = '.$fk_soc; 94 | 95 | $sql.= ' AND cf.date_commande >= "'.$_REQUEST['date_debyear'].'-'.$_REQUEST['date_debmonth'].'-'.$_REQUEST['date_debday'].' 00:00:00"'; 96 | $sql.= ' AND cf.date_commande <= "'.$_REQUEST['date_finyear'].'-'.$_REQUEST['date_finmonth'].'-'.$_REQUEST['date_finday'].' 23:59:59"'; 97 | //echo $sql;exit; 98 | 99 | $resql = $db->query($sql); 100 | 101 | $TResql = array(); 102 | while($res = $db->fetch_object($resql)) $TResql[$res->id_prod][] = abs($res->nb_days_diff); 103 | 104 | $TProdAverage = array(); 105 | foreach($TResql as $id_prod=>$Tab) { 106 | $p = new Product($db); 107 | $p->fetch($id_prod); 108 | $TProdAverage[$id_prod] = array( 109 | 'diff'=>(array_sum($Tab) / count($Tab)) 110 | ,'ref_prod'=>$p->ref 111 | ,'get_nom_url'=>$p->getNomUrl(1) 112 | ,'label_prod'=>$p->label 113 | ); 114 | } 115 | 116 | //var_dump($TProdAverage);exit; 117 | 118 | return $TProdAverage; 119 | 120 | } 121 | 122 | function draw_table(&$TData) { 123 | 124 | global $db, $langs; 125 | 126 | // Je ne fais pas de liste TBS parce que je vais devoir afficher le tableau en base 64 dans la dom pour le poster vers un fichier download.php pour télécharger un csv 127 | print ''; 128 | print ''; 129 | print ''; 130 | print ''; 131 | print ''; 132 | print ''; 133 | 134 | foreach($TData as $Tab) { 135 | print ''; 136 | print ''; 137 | print ''; 138 | print ''; 139 | print ''; 140 | 141 | } 142 | 143 | print '
ProduitLibelléTemps moyen de réception (en jours)
'.$Tab['get_nom_url'].''.$Tab['label_prod'].''.$Tab['diff'].'
'; 144 | 145 | print ''; 154 | 155 | } 156 | 157 | function download_file(&$TData) { 158 | 159 | $name = 'receipt_time_'.$_REQUEST['date_debyear'].$_REQUEST['date_debmonth'].$_REQUEST['date_debday'].'_' 160 | .$_REQUEST['date_finyear'].$_REQUEST['date_finmonth'].$_REQUEST['date_finday'].'.csv'; 161 | $fname = sys_get_temp_dir().'/'.$name; 162 | $f = fopen($fname, 'w+'); 163 | fputcsv($f, array('Produit', 'Libellé', 'Temps moyen de réception (en jours)'), ';'); 164 | 165 | foreach($TData as $Tab) { 166 | 167 | fputcsv($f, array( 168 | $Tab['ref_prod'] 169 | , $Tab['label_prod'] 170 | , $Tab['diff'] 171 | ) 172 | , ';'); 173 | 174 | } 175 | 176 | fclose($f); 177 | 178 | header('Content-Description: File Transfer'); 179 | header('Content-Type: application/CSV'); 180 | header('Content-Disposition: attachment; filename="'.$name.'"'); 181 | header('Expires: 0'); 182 | header('Cache-Control: must-revalidate'); 183 | header('Pragma: public'); 184 | header('Content-Length: ' . filesize($fname)); 185 | readfile($fname); 186 | exit; 187 | 188 | } 189 | -------------------------------------------------------------------------------- /graph_action_by_user.php: -------------------------------------------------------------------------------- 1 | rights->mandarin->graph->action_by_user) accessforbidden(); 7 | $langs->load('mandarin@mandarin'); 8 | 9 | $userid = GETPOST('userid'); 10 | if($userid != 0) $userdefault = $userid; 11 | elseif(user_est_responsable_hierarchique()) $userid = $user->id; 12 | 13 | // Get user group and default 14 | $groupid= GETPOST('groupid', 'int'); 15 | if(empty($groupid) && $conf->global->MANDARIN_COMMERCIAL_GROUP > 0) 16 | { 17 | $groupid=$conf->global->MANDARIN_COMMERCIAL_GROUP; 18 | } 19 | 20 | // Begin of page 21 | llxHeader('', $langs->trans('mandarinTitleGraphEventByUser'), ''); 22 | 23 | print dol_get_fiche_head('RapportEvenementsParCommerciaux'); 24 | print_fiche_titre($langs->trans('RapportEvenementsParCommerciaux')); 25 | 26 | print_form_filter($userid,$groupid); 27 | 28 | $TData = get_data_tab($userid,$groupid); 29 | draw_table($TData, get_list_id_user($TData), get_tab_label_action_comm()); 30 | 31 | print '
'; 32 | draw_graphique($TData, get_tab_label_action_comm()); 33 | 34 | llxFooter(); 35 | 36 | function print_form_filter($userid,$groupid=-1) { 37 | 38 | global $db, $langs; 39 | 40 | $langs->load('users'); 41 | 42 | $form = new Form($db); 43 | 44 | print '
'; 45 | 46 | print $langs->trans('HierarchicalResponsible'); 47 | print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', '', 1); 48 | 49 | // User group filter 50 | print '      '; 51 | print $langs->trans('UserGroup'); 52 | print $form->select_dolgroups($groupid, 'groupid',1); 53 | 54 | print '

'; 55 | 56 | $date_deb = explode('/', $_REQUEST['date_deb']); 57 | $date_deb = implode('/', array_reverse($date_deb)); 58 | $date_fin = explode('/', $_REQUEST['date_fin']); 59 | $date_fin = implode('/', array_reverse($date_fin)); 60 | 61 | print 'Du '; 62 | $form->select_date(strtotime($date_deb), 'date_deb'); 63 | print 'Au '; 64 | $form->select_date(strtotime($date_fin), 'date_fin'); 65 | 66 | print ''; 67 | 68 | print '
'; 69 | 70 | print '
'; 71 | 72 | } 73 | 74 | function user_est_responsable_hierarchique() { 75 | 76 | global $db, $user; 77 | 78 | $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'user WHERE fk_user = '.$user->id; 79 | $resql = $db->query($sql); 80 | $res = $db->fetch_object($resql); 81 | 82 | return $res->rowid > 0; 83 | 84 | } 85 | 86 | function get_data_tab($userid,$groupid=0) { 87 | 88 | global $db, $conf; 89 | 90 | $TData = array(); 91 | 92 | $sql = 'SELECT u.rowid, c.code, COUNT(*) as nb_events 93 | FROM llx_user u 94 | LEFT JOIN llx_actioncomm a ON (a.fk_user_action = u.rowid) 95 | LEFT JOIN llx_c_actioncomm c ON (c.id = a.fk_action) 96 | WHERE u.rowid > 1 97 | AND u.statut = 1'; 98 | 99 | if(!empty($_REQUEST['date_deb'])) $sql.= ' AND a.datep >= "'.$_REQUEST['date_debyear'].'-'.$_REQUEST['date_debmonth'].'-'.$_REQUEST['date_debday'].' 00:00:00"'; 100 | if(!empty($_REQUEST['date_fin'])) $sql.= ' AND a.datep <= "'.$_REQUEST['date_finyear'].'-'.$_REQUEST['date_finmonth'].'-'.$_REQUEST['date_finday'].' 23:59:59"'; 101 | 102 | if($userid > 0 && !empty($conf->global->MANDARIN_graph_action_by_user_SHOW_MANAGER)) 103 | { 104 | // Show selected line manager 105 | $sql.= ' AND ( u.fk_user = '.$userid.' OR u.rowid = '.$userid.' )'; 106 | } 107 | elseif($userid > 0) 108 | { 109 | $sql.= ' AND u.fk_user = '.$userid; 110 | } 111 | 112 | if(!empty($conf->global->MANDARIN_GRAPHACTIONBYUSER_ALLOWED_ACTION_PERCENT)) $sql.= ' AND a.percent >= '.$conf->global->MANDARIN_GRAPHACTIONBYUSER_ALLOWED_ACTION_PERCENT; 113 | 114 | // Filter by user group 115 | if($groupid>0) 116 | { 117 | $sql.=' AND ( u.rowid IN ( SELECT ugu.fk_user FROM '.MAIN_DB_PREFIX.'usergroup_user ugu WHERE ugu.fk_usergroup = '.(int)$groupid.' ) '; 118 | if($userid > 0 && !empty($conf->global->MANDARIN_graph_action_by_user_FORCE_SHOW_MANAGER)) 119 | { 120 | // FORCE display selected line manager independently of group selection 121 | $sql.= ' OR u.rowid = '.$userid.' '; 122 | } 123 | $sql.= ' )'; 124 | } 125 | 126 | $sql.= ' AND a.code NOT IN ("AC_OTH_AUTO") 127 | GROUP BY u.rowid, c.code'; 128 | 129 | $resql = $db->query($sql); 130 | while($res = $db->fetch_object($resql)){ 131 | $TData[$res->code][$res->rowid] = $res->nb_events; 132 | } 133 | return $TData; 134 | 135 | } 136 | 137 | 138 | 139 | function get_tab_label_action_comm() { 140 | 141 | global $db, $langs; 142 | 143 | $TLabel = array(); 144 | 145 | $sql = 'SELECT code, libelle FROM '.MAIN_DB_PREFIX.'c_actioncomm'; 146 | $resql = $db->query($sql); 147 | while($res = $db->fetch_object($resql)) { 148 | $key=$langs->trans("Action".strtoupper($res->code)); 149 | $label=($res->code && $key != "Action".strtoupper($res->code)?$key:$res->libelle); 150 | $TLabel[$res->code] = html_entity_decode($label); 151 | } 152 | 153 | return $TLabel; 154 | 155 | } 156 | 157 | function get_list_id_user(&$TData) { 158 | 159 | global $db; 160 | 161 | $TIDUser = array(); 162 | 163 | foreach($TData as $type_event=>$TDonnes) { 164 | $TIDUser = array_merge(array_keys($TDonnes), $TIDUser); 165 | } 166 | $TIDUser = array_unique($TIDUser); 167 | 168 | ksort($TIDUser); 169 | 170 | return $TIDUser; 171 | 172 | } 173 | 174 | function draw_table(&$TData, &$TIDUser, &$TLabelActionComm) { 175 | 176 | global $db, $langs; 177 | 178 | /*pre($TData,true); 179 | pre($TIDUser,true); 180 | pre($TLabelActionComm,true);*/ 181 | 182 | $langs->load('agenda'); 183 | 184 | print ''; 185 | 186 | $TTypeEvents = array_keys($TData); 187 | asort($TTypeEvents); 188 | 189 | print ''; 190 | print ''; 193 | 194 | foreach($TTypeEvents as $type) print ''; 195 | 196 | print ''; 199 | print ''; 200 | 201 | $u = new User($db); 202 | 203 | $class = array('pair', 'impair'); 204 | $var = true; 205 | 206 | $TNBTotalType = array(); // Contient le nombre d'occurences pour chaque type d'événement, tout user confondu 207 | foreach($TIDUser as $id_user) { 208 | 209 | print ''; 210 | print ''; 214 | 215 | $nb_total_user = 0; // Contient le nombre d'occurences pour chaque user, tout type d'événement confondu 216 | foreach($TTypeEvents as $type) { 217 | print ''; 220 | $nb_total_user+=$TData[$type][$id_user]; 221 | $TNBTotalType[$type]+=$TData[$type][$id_user]; 222 | } 223 | 224 | print ''; 227 | print ''; 228 | 229 | $var = !$var; 230 | 231 | } 232 | 233 | print ''; 234 | print ''; 237 | foreach($TTypeEvents as $type) print ''; 238 | print ''; 239 | print ''; 240 | 241 | print '
'; 191 | print $langs->trans('Users'). ' / '.$langs->trans('EventType'); 192 | print ''.$TLabelActionComm[$type].''; 197 | print 'Total'; 198 | print '
'; 211 | $u->fetch($id_user); 212 | print $u->getNomUrl(1); 213 | print ''; 218 | print ''.$TData[$type][$id_user].''; 219 | print ''; 225 | print ''.$nb_total_user.''; 226 | print '
'; 235 | print 'Total'; 236 | print ''.$TNBTotalType[$type].''.array_sum($TNBTotalType).'
'; 242 | 243 | } 244 | 245 | function draw_graphique(&$TData, &$TabTrad) { 246 | 247 | global $langs; 248 | 249 | $PDOdb = new TPDOdb; 250 | 251 | $TSum = array(); 252 | 253 | foreach($TData as $code=>$Tab) $TSum[] = array($TabTrad[$code], array_sum($Tab)); 254 | 255 | $listeview = new TListviewTBS('graphProjectByType'); 256 | 257 | print $listeview->renderArray($PDOdb, $TSum 258 | ,array( 259 | 'type' => 'chart' 260 | ,'chartType' => 'PieChart' 261 | ,'liste'=>array( 262 | 'titre'=>$langs->transnoentitiesnoconv('titleGraphEventByUser') 263 | ) 264 | ) 265 | ); 266 | 267 | } 268 | -------------------------------------------------------------------------------- /graph_propales_by_commercial.php: -------------------------------------------------------------------------------- 1 | rights->mandarin->graph->propal_commercial) accessforbidden(); 7 | $langs->load('mandarin@mandarin'); 8 | 9 | $userid = GETPOST('userid'); 10 | $ca = (bool)GETPOST('ca'); // Booléen pour afficher le chiffre d'affaire au lieu du nb de propales 11 | 12 | // si l'utilisateur n'est pas admin, il ne voit que c'est chiffre 13 | if(!$user->rights->mandarin->graph->propal_alldata) $userid = $user->id; 14 | 15 | // Begin of page 16 | llxHeader('', $langs->trans('linkMenuPropalesByCommercial'), ''); 17 | 18 | print dol_get_fiche_head('linkMenuPropalesByCommercial'); 19 | print_fiche_titre($langs->trans('linkMenuPropalesByCommercial')); 20 | 21 | // la requête SQL étant dépendante de cette conf, il est important de la renseigner 22 | // je vérifie si >0 pour prendre en compte le cas où il serait égal à -1 si l'utilisateur met la valeur nulle dans le select de configuration 23 | if($conf->global->MANDARIN_COMMERCIAL_GROUP > 0){ 24 | print_form_filter($userid); 25 | 26 | $TData = get_data_tab($userid); 27 | 28 | draw_table($TData, get_list_id_user($TData), get_tab_label_statut()); 29 | 30 | print '
'; 31 | draw_graphique($TData, get_tab_label_statut()); 32 | } 33 | else print ''.$langs->trans('err_NOGROUPCOMM').''; 34 | 35 | //end of page 36 | llxFooter(); 37 | 38 | function print_form_filter($userid) { 39 | 40 | global $db, $langs, $ca; 41 | 42 | $langs->load('users'); 43 | 44 | $form = new Form($db); 45 | 46 | print '
'; 47 | 48 | print $langs->trans('mandarinTitlePropalFactureCommercial'); 49 | 50 | print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', '', 1); 51 | 52 | print '

'; 53 | print ''; 54 | 55 | $date_deb = explode('/', $_REQUEST['date_deb']); 56 | $date_deb = implode('/', array_reverse($date_deb)); 57 | $date_fin = explode('/', $_REQUEST['date_fin']); 58 | $date_fin = implode('/', array_reverse($date_fin)); 59 | 60 | print $langs->trans('propalCreationDate') . ' ' . strtolower($langs->trans('From')) . ' '; 61 | $form->select_date(strtotime($date_deb), 'date_deb'); 62 | print $langs->trans('to') .' '; 63 | $form->select_date(strtotime($date_fin), 'date_fin'); 64 | 65 | print ''; 66 | 67 | print '
'; 68 | 69 | print '
'; 70 | 71 | } 72 | 73 | function get_data_tab($userid) { 74 | 75 | global $db; 76 | 77 | $TData = array(); 78 | 79 | $sql = getSqlForData($userid); 80 | $resql = $db->query($sql); 81 | while($res = $db->fetch_object($resql)) $TData[$res->code][$res->rowid] = $res->propales; 82 | 83 | return $TData; 84 | 85 | } 86 | 87 | function getSqlForData($userid) 88 | { 89 | global $conf, $user, $ca; 90 | 91 | if($ca) $sql = 'SELECT DISTINCT p.fk_statut as code, u.rowid, SUM(p.total_ht) as propales'; 92 | else $sql = 'SELECT p.fk_statut as code, u.rowid, COUNT(*) as propales'; 93 | 94 | 95 | $sql.=' FROM '.MAIN_DB_PREFIX.'propal p 96 | INNER JOIN ' . MAIN_DB_PREFIX . 'societe_commerciaux sc ON sc.fk_soc = p.fk_soc 97 | LEFT JOIN '.MAIN_DB_PREFIX.'user u ON (u.rowid = sc.fk_user) 98 | LEFT JOIN '.MAIN_DB_PREFIX.'usergroup_user ug ON (ug.fk_user = p.fk_user_author)'; 99 | 100 | 101 | $sql.=' WHERE 1=1'; 102 | $sql.=' AND p.entity=' . $conf->entity; 103 | $sql.=' AND ug.fk_usergroup='.$conf->global->MANDARIN_COMMERCIAL_GROUP; 104 | 105 | if(!empty($_REQUEST['date_deb'])) $sql.= ' AND p.datec >= "'.$_REQUEST['date_debyear'].'-'.$_REQUEST['date_debmonth'].'-'.$_REQUEST['date_debday'].' 00:00:00"'; 106 | if(!empty($_REQUEST['date_fin'])) $sql.= ' AND p.datec <= "'.$_REQUEST['date_finyear'].'-'.$_REQUEST['date_finmonth'].'-'.$_REQUEST['date_finday'].' 23:59:59"'; 107 | 108 | if($userid > 0) $sql.= ' AND u.rowid = '.$userid; 109 | 110 | $sql.= ' GROUP BY p.fk_statut, u.rowid'; 111 | 112 | return $sql; 113 | } 114 | 115 | function get_tab_label_statut() { 116 | 117 | global $db, $langs; 118 | 119 | $TLabel = array(); 120 | 121 | $sql = 'SELECT id, code, label, active FROM '.MAIN_DB_PREFIX.'c_propalst'; 122 | $resql = $db->query($sql); 123 | while($res = $db->fetch_object($resql)) { 124 | $label = $res->label; 125 | $TLabel[$res->code] = array('rowid'=>$res->id, 'code'=>$res->code, 'label'=>$label, 'active'=>$res->active); 126 | } 127 | 128 | return $TLabel; 129 | 130 | } 131 | 132 | function get_list_id_user(&$TData) { 133 | 134 | global $db; 135 | 136 | $TIDUser = array(); 137 | 138 | foreach($TData as $type_event=>$TDonnes) { 139 | $TIDUser = array_merge(array_keys($TDonnes), $TIDUser); 140 | } 141 | $TIDUser = array_unique($TIDUser); 142 | 143 | ksort($TIDUser); 144 | 145 | return $TIDUser; 146 | 147 | } 148 | 149 | function draw_table(&$TData, &$TIDUser, &$TLabelStatut) { 150 | 151 | global $db, $langs,$ca; 152 | 153 | $langs->load('agenda'); 154 | 155 | print ''; 156 | 157 | $TFkStatut = array_keys($TLabelStatut); 158 | asort($TFkStatut); 159 | 160 | print ''; 161 | print ''; 164 | 165 | ksort($TFkStatut); 166 | 167 | foreach($TFkStatut as $status) { 168 | print ''; 173 | } 174 | 175 | print ''; 178 | print ''; 179 | 180 | $u = new User($db); 181 | 182 | $class = array('pair', 'impair'); 183 | $var = true; 184 | 185 | $TNBTotalType = array(); // Contient le nombre d'occurences pour chaque type de propal, tout user confondu 186 | foreach($TIDUser as $id_user) { 187 | 188 | print ''; 189 | print ''; 193 | 194 | $nb_total_user = 0; // Contient le nombre d'occurences pour chaque user, tout type d'événement confondu 195 | for($i = 0; $i < count($TFkStatut); $i++) { 196 | print ''; 200 | $nb_total_user+=$TData[$i][$id_user]; 201 | $TNBTotalType[$i]+=$TData[$i][$id_user]; 202 | } 203 | 204 | print ''; 208 | print ''; 209 | 210 | $var = !$var; 211 | 212 | } 213 | 214 | print ''; 215 | print ''; 218 | 219 | foreach($TFkStatut as $k =>$v){ 220 | $unit = ($ca) ? price($TNBTotalType[$k]) : $TNBTotalType[$k]; 221 | print ''; 222 | } 223 | $total = ($ca) ? price(array_sum($TNBTotalType)) : array_sum($TNBTotalType); 224 | print ''; 225 | print ''; 226 | 227 | print '
'; 162 | print $langs->trans('User'); 163 | print ''; 169 | 170 | print $TLabelStatut[$status]['label']; 171 | 172 | print ''; 176 | print 'Total'; 177 | print '
'; 190 | $u->fetch($id_user); 191 | print $u->getNomUrl(1); 192 | print ''; 197 | $unit = ($ca) ? price($TData[$i][$id_user]) : $TData[$i][$id_user]; 198 | print ''. $unit .''; 199 | print ''; 205 | $unit = ($ca) ? price($nb_total_user) : $nb_total_user; 206 | print ''.$unit.''; 207 | print '
'; 216 | print 'Total'; 217 | print ''.$unit.'' . $total . '
'; 228 | 229 | } 230 | 231 | function draw_graphique(&$TData, &$TabTrad) { 232 | 233 | global $langs, $ca; 234 | 235 | $PDOdb = new TPDOdb; 236 | 237 | $TSum = array(); 238 | 239 | foreach($TData as $code=>$Tab) { 240 | foreach ($TabTrad as $k=>$v){ 241 | if($v['rowid'] == $code) $code = $k; 242 | } 243 | if (empty($TabTrad[$code]['label'])) continue; 244 | $TSum[] = array($TabTrad[$code]['label'], array_sum($Tab)); 245 | } 246 | 247 | $listeview = new TListviewTBS('graphPropalByComm'); 248 | 249 | $title = ($ca) ? 'titleGraphCaPropalByComm' : 'titleGraphPropalByComm'; 250 | print $listeview->renderArray($PDOdb, $TSum 251 | ,array( 252 | 'type' => 'chart' 253 | ,'chartType' => 'PieChart' 254 | ,'liste'=>array( 255 | 'titre'=>$langs->transnoentitiesnoconv($title) 256 | ) 257 | ) 258 | ); 259 | 260 | } 261 | -------------------------------------------------------------------------------- /graph_project_by_user.php: -------------------------------------------------------------------------------- 1 | rights->mandarin->graph->project_by_user) accessforbidden(); 7 | $langs->load('mandarin@mandarin'); 8 | 9 | $userid = GETPOST('userid'); 10 | if($userid != 0){ 11 | $userdefault = $userid; 12 | } 13 | elseif(user_est_responsable_hierarchique()){ 14 | $userid = $user->id; 15 | } 16 | 17 | if(!empty($conf->global->GRAPH_PROJECT_BY_USER_HIERARCHYME) && (empty($userid) || $userid < 0)){ 18 | $userid = $user->id; 19 | } 20 | 21 | // Get user group and default 22 | $groupid= GETPOST('groupid', 'int'); 23 | if(empty($groupid) && $conf->global->MANDARIN_COMMERCIAL_GROUP > 0) 24 | { 25 | $groupid=$conf->global->MANDARIN_COMMERCIAL_GROUP; 26 | } 27 | 28 | // Begin of page 29 | llxHeader('', $langs->trans('linkMenuProjectByUserReport'), ''); 30 | 31 | print dol_get_fiche_head('linkMenuProjectByUserReport'); 32 | print_fiche_titre($langs->trans('linkMenuProjectByUserReport')); 33 | 34 | print_form_filter($userid,$groupid); 35 | 36 | $TData = get_data_tab($userid,$groupid); 37 | draw_table($TData, get_list_id_user($TData), get_tab_label_statut_opportunite()); 38 | 39 | print '
'; 40 | draw_graphique($TData, get_tab_label_statut_opportunite()); 41 | 42 | llxFooter(); 43 | 44 | function print_form_filter($userid,$groupid=-1) { 45 | 46 | global $db, $langs, $conf; 47 | 48 | $langs->load('users'); 49 | 50 | $form = new Form($db); 51 | 52 | print '
'; 53 | 54 | print $langs->trans('HierarchicalResponsible'); 55 | 56 | $include = ''; 57 | $show_empty=1; 58 | if(!empty($conf->global->GRAPH_PROJECT_BY_USER_HIERARCHYME)){ 59 | $include = 'hierarchyme'; 60 | $show_empty=0; 61 | } 62 | 63 | print $form->select_dolusers($userid, 'userid', $show_empty, '', 0, $include, '', 0, 0, 0, '', 0, '', '', 1); 64 | 65 | // User group filter 66 | print '      '; 67 | print $langs->trans('UserGroup'); 68 | print $form->select_dolgroups($groupid, 'groupid',1); 69 | 70 | 71 | print '

'; 72 | 73 | $date_deb = explode('/', $_REQUEST['date_deb']); 74 | $date_deb = implode('/', array_reverse($date_deb)); 75 | $date_fin = explode('/', $_REQUEST['date_fin']); 76 | $date_fin = implode('/', array_reverse($date_fin)); 77 | 78 | print 'Du '; 79 | $form->select_date(strtotime($date_deb), 'date_deb'); 80 | print 'Au '; 81 | $form->select_date(strtotime($date_fin), 'date_fin'); 82 | 83 | print ''; 84 | 85 | print '
'; 86 | 87 | print '
'; 88 | 89 | } 90 | 91 | function user_est_responsable_hierarchique() { 92 | 93 | global $db, $user; 94 | 95 | $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'user WHERE fk_user = '.$user->id; 96 | $resql = $db->query($sql); 97 | $res = $db->fetch_object($resql); 98 | 99 | return $res->rowid > 0; 100 | 101 | } 102 | 103 | function get_data_tab($userid,$groupid=0) { 104 | 105 | global $db; 106 | 107 | $TData = array(); 108 | 109 | $sql = getSqlForData($userid,false,false,$groupid); 110 | $resql = $db->query($sql); 111 | if(!empty($resql)){ 112 | while($res = $db->fetch_object($resql)) $TData[$res->code][$res->fk_socpeople] = $res->nb_projects; 113 | } 114 | 115 | $sql = getSqlForData($userid, true,false,$groupid); 116 | $resql = $db->query($sql); 117 | 118 | if(!empty($resql)){ 119 | while($res = $db->fetch_object($resql)) $TData[$res->code][$res->fk_socpeople] = $res->nb_projects; 120 | } 121 | 122 | $sql = getSqlForData($userid, false, true,$groupid); 123 | $resql = $db->query($sql); 124 | 125 | if(!empty($resql)){ 126 | while($res = $db->fetch_object($resql)) $TData[$res->code][$res->fk_socpeople] = $res->nb_projects; 127 | } 128 | 129 | return $TData; 130 | 131 | } 132 | 133 | function getSqlForData($userid, $only_draft=false, $only_close=false,$groupid=0) 134 | { 135 | global $db; 136 | 137 | if (!$only_draft && !$only_close) $sql = 'SELECT ls.code, c.fk_socpeople, COUNT(*) as nb_projects'; 138 | elseif ($only_draft) $sql = 'SELECT "DRAFT" as code, c.fk_socpeople, COUNT(*) as nb_projects'; 139 | elseif ($only_close) $sql = 'SELECT "CLOSE" as code, c.fk_socpeople, COUNT(*) as nb_projects'; 140 | 141 | $sql.=' FROM '.MAIN_DB_PREFIX.'projet p 142 | LEFT JOIN '.MAIN_DB_PREFIX.'c_lead_status ls ON (p.fk_opp_status = ls.rowid) 143 | LEFT JOIN '.MAIN_DB_PREFIX.'element_contact c ON (p.rowid = c.element_id AND fk_c_type_contact IN(160, 161)) 144 | LEFT JOIN '.MAIN_DB_PREFIX.'user u ON (u.rowid = c.fk_socpeople)'; 145 | 146 | if (!$only_draft && !$only_close) $sql.=' WHERE p.fk_statut = 1 AND fk_opp_status > 0'; 147 | elseif ($only_draft) $sql.=' WHERE p.fk_statut = 0'; 148 | elseif ($only_close) $sql.=' WHERE p.fk_statut = 2'; 149 | 150 | $sql.=' AND u.statut = 1'; 151 | 152 | // Filter by user group 153 | if($groupid>0) 154 | { 155 | $sql.=' AND u.rowid IN ( SELECT ugu.fk_user FROM '.MAIN_DB_PREFIX.'usergroup_user ugu WHERE ugu.fk_usergroup = '.(int)$groupid.' ) '; 156 | } 157 | 158 | if(!empty($_REQUEST['date_deb'])) $sql.= ' AND p.dateo >= "'.$_REQUEST['date_debyear'].'-'.$_REQUEST['date_debmonth'].'-'.$_REQUEST['date_debday'].' 00:00:00"'; 159 | if(!empty($_REQUEST['date_fin'])) $sql.= ' AND p.dateo <= "'.$_REQUEST['date_finyear'].'-'.$_REQUEST['date_finmonth'].'-'.$_REQUEST['date_finday'].' 23:59:59"'; 160 | if($userid > 0){ 161 | $userselected = new User($db); 162 | $userselected->fetch($userid); 163 | $TincludeUsers = $userselected->getAllChildIds(1); 164 | if(!empty($TincludeUsers) && is_array($TincludeUsers)){ 165 | $sql.= ' AND c.fk_socpeople IN ('.implode(',',$TincludeUsers).')'; 166 | } 167 | else{ 168 | $sql.= ' AND c.fk_socpeople = '.$userid; 169 | } 170 | 171 | } 172 | 173 | if (!$only_draft && !$only_close) $sql.= ' GROUP BY p.fk_opp_status, c.fk_socpeople'; 174 | else $sql.= ' GROUP BY c.fk_socpeople'; 175 | 176 | $sql .= ' ORDER BY ls.percent'; 177 | 178 | return $sql; 179 | } 180 | 181 | function get_tab_label_statut_opportunite() { 182 | 183 | global $db, $langs; 184 | 185 | $TLabel = array(); 186 | 187 | $sql = 'SELECT rowid, code, label, percent FROM '.MAIN_DB_PREFIX.'c_lead_status'; 188 | $resql = $db->query($sql); 189 | while($res = $db->fetch_object($resql)) { 190 | $label = $langs->transnoentitiesnoconv("OppStatus".$res->code) != "OppStatus".$res->code 191 | ? $langs->transnoentitiesnoconv("OppStatus".$res->code) 192 | : $res->label; 193 | $TLabel[$res->code] = array('rowid'=>$res->rowid, 'code'=>$res->code, 'label'=>$label, 'percent'=>$res->percent); 194 | } 195 | 196 | return $TLabel; 197 | 198 | } 199 | 200 | function get_list_id_user(&$TData) { 201 | 202 | global $db; 203 | 204 | $TIDUser = array(); 205 | 206 | foreach($TData as $type_event=>$TDonnes) { 207 | $TIDUser = array_merge(array_keys($TDonnes), $TIDUser); 208 | } 209 | $TIDUser = array_unique($TIDUser); 210 | 211 | ksort($TIDUser); 212 | 213 | return $TIDUser; 214 | 215 | } 216 | 217 | function draw_table(&$TData, &$TIDUser, &$TLabelStatutOpportunite) { 218 | 219 | global $db, $langs; 220 | 221 | $langs->load('agenda'); 222 | 223 | print ''; 224 | 225 | $TFkStatutOpportunite = array_keys($TData); 226 | asort($TFkStatutOpportunite); 227 | 228 | print ''; 229 | print ''; 232 | 233 | // Rangement par pourcentage croissant 234 | ksort($TFkStatutOpportunite); 235 | 236 | foreach($TFkStatutOpportunite as $status) { 237 | print ''; 251 | } 252 | 253 | print ''; 256 | print ''; 257 | 258 | $u = new User($db); 259 | 260 | $class = array('pair', 'impair'); 261 | $var = true; 262 | 263 | $TNBTotalType = array(); // Contient le nombre d'occurences pour chaque type d'événement, tout user confondu 264 | foreach($TIDUser as $id_user) { 265 | 266 | print ''; 267 | print ''; 271 | 272 | $nb_total_user = 0; // Contient le nombre d'occurences pour chaque user, tout type d'événement confondu 273 | foreach($TFkStatutOpportunite as $status) { 274 | print ''; 277 | $nb_total_user+=$TData[$status][$id_user]; 278 | $TNBTotalType[$status]+=$TData[$status][$id_user]; 279 | } 280 | 281 | print ''; 284 | print ''; 285 | 286 | $var = !$var; 287 | 288 | } 289 | 290 | print ''; 291 | print ''; 294 | foreach($TFkStatutOpportunite as $status) print ''; 295 | print ''; 296 | print ''; 297 | 298 | print '
'; 230 | print $langs->trans('User'). ' / '.$langs->trans('OpportunityStatus'); 231 | print ''; 238 | if ($status != 'DRAFT' && $status != 'CLOSE') 239 | { 240 | print $TLabelStatutOpportunite[$status]['label']; 241 | print ' ('.$TLabelStatutOpportunite[$status]['percent'].')'; 242 | } 243 | elseif ($status == 'DRAFT') { 244 | print $langs->trans('Draft'); 245 | } 246 | elseif ($status == 'CLOSE') { 247 | print $langs->trans('Closed'); 248 | } 249 | 250 | print ''; 254 | print 'Total'; 255 | print '
'; 268 | $u->fetch($id_user); 269 | print $u->getNomUrl(1); 270 | print ''; 275 | print ''.$TData[$status][$id_user].''; 276 | print ''; 282 | print ''.$nb_total_user.''; 283 | print '
'; 292 | print 'Total'; 293 | print ''.$TNBTotalType[$status].''.array_sum($TNBTotalType).'
'; 299 | 300 | } 301 | 302 | function draw_graphique(&$TData, &$TabTrad) { 303 | 304 | global $langs; 305 | 306 | $PDOdb = new TPDOdb; 307 | 308 | $TSum = array(); 309 | 310 | foreach($TData as $code=>$Tab) { 311 | if (empty($TabTrad[$code]['label'])) continue; 312 | $TSum[] = array($TabTrad[$code]['label'], array_sum($Tab)); 313 | } 314 | 315 | $listeview = new TListviewTBS('graphProjectByType'); 316 | 317 | print $listeview->renderArray($PDOdb, $TSum 318 | ,array( 319 | 'type' => 'chart' 320 | ,'chartType' => 'PieChart' 321 | ,'liste'=>array( 322 | 'titre'=>$langs->transnoentitiesnoconv('titleGraphProjectByType') 323 | ) 324 | ) 325 | ); 326 | 327 | } 328 | -------------------------------------------------------------------------------- /graph_sent_products_average.php: -------------------------------------------------------------------------------- 1 | rights->mandarin->graph->products_average) accessforbidden(); 8 | $langs->load('mandarin@mandarin'); 9 | 10 | $action = GETPOST('action'); 11 | $date_deb = GETPOST('date_deb'); 12 | $date_fin = GETPOST('date_fin'); 13 | $type = GETPOST('type'); 14 | 15 | switch($action) { 16 | 17 | case 'print_data': 18 | llxHeader('', $langs->trans('RapportMoyenneProduitsVendusCommandesEnvoyes'), ''); 19 | print dol_get_fiche_head('RapportMoyenneProduitsVendusCommandesEnvoyes'); 20 | print_fiche_titre($langs->trans('RapportMoyenneProduitsVendusCommandesEnvoyes')); 21 | print_form_filter($date_deb, $date_fin, $type); 22 | $TData = get_data_tab($date_deb, $date_fin, $type); 23 | if(!empty($TData)) draw_table($TData); 24 | break; 25 | 26 | case 'download_file': 27 | $TData = get_data_tab($date_deb, $date_fin, $type); 28 | download_file($TData, $type); 29 | break; 30 | 31 | default: 32 | llxHeader('', $langs->trans('RapportMoyenneProduitsVendusCommandesEnvoyes'), ''); 33 | print dol_get_fiche_head('RapportMoyenneProduitsVendusCommandesEnvoyes'); 34 | print_fiche_titre($langs->trans('RapportMoyenneProduitsVendusCommandesEnvoyes')); 35 | print_form_filter($date_deb, $date_fin, $type); 36 | 37 | } 38 | 39 | llxFooter(); 40 | 41 | function print_form_filter($date_deb, $date_fin, $type) { 42 | 43 | global $db, $langs; 44 | 45 | $langs->load('users'); 46 | 47 | $form = new Form($db); 48 | 49 | print '
'; 50 | 51 | print ''; 52 | 53 | print $langs->trans('AnalyzedData').'  '; 54 | print $form->selectarray('type', array('expedition'=>'Expéditions', 'commande'=>'Commandes', 'facture'=>'Factures'), $type); 55 | 56 | print '

'; 57 | 58 | $date_deb_t = dol_mktime(0, 0, 0, GETPOST('date_debmonth'), GETPOST('date_debday'), GETPOST('date_debyear')); 59 | $date_fin_t = dol_mktime(0, 0, 0, GETPOST('date_finmonth'), GETPOST('date_finday'), GETPOST('date_finyear')); 60 | 61 | print 'Du  '; 62 | $form->select_date(empty($date_deb) ? false : $date_deb_t, 'date_deb', 0, 0, 0, '', 1, 1); 63 | print '
Au  '; 64 | $form->select_date(empty($date_fin) ? false : $date_fin_t, 'date_fin', 0, 0, 0, '', 1, 1); 65 | print '

'; 66 | 67 | print ''; 68 | 69 | print '
'; 70 | 71 | print '
'; 72 | 73 | } 74 | 75 | function get_data_tab($date_deb, $date_fin, $type) { 76 | 77 | global $db; 78 | 79 | if(empty($date_deb) || empty($date_fin)){ 80 | setEventMessage('Renseignez une date de début et de fin', 'warnings'); 81 | return 0; 82 | } 83 | 84 | $TData = array(); 85 | 86 | $sql = get_sql($date_deb, $date_fin, $type); 87 | 88 | $resql = $db->query($sql); 89 | while($res = $db->fetch_object($resql)){ 90 | $TData[] = array( 91 | 'semaine'=>$res->semaine 92 | ,'id_prod'=>$res->id_prod 93 | ,'ref_prod'=>$res->ref_prod 94 | ,'nb_products'=>$res->nb_products 95 | ); 96 | } 97 | 98 | get_average($TData, $type); 99 | 100 | return $TData; 101 | 102 | } 103 | 104 | function get_average(&$TData, $type) { 105 | 106 | global $db; 107 | 108 | // On récupère tous les produits différents 109 | $TProds = array(); 110 | foreach($TData as $Tab) $TProds[$Tab['id_prod']] = $Tab['id_prod']; 111 | 112 | // On récupère la moyenne du nombre de produits traités pour la période 113 | $TProdAverage = array(); 114 | foreach($TProds as $id_prod) { 115 | 116 | if($type === 'expedition') { 117 | 118 | $sql = 'SELECT e.rowid, ed.rowid, SUM(ed.qty) as nb_prods 119 | FROM '.MAIN_DB_PREFIX.'expeditiondet ed 120 | INNER JOIN '.MAIN_DB_PREFIX.'expedition e ON (ed.fk_expedition = e.rowid) 121 | INNER JOIN '.MAIN_DB_PREFIX.'commandedet cd ON (cd.rowid = ed.fk_origin_line) 122 | INNER JOIN '.MAIN_DB_PREFIX.'product p ON (p.rowid = cd.fk_product) 123 | WHERE p.rowid = '.$id_prod; 124 | $sql.= ' AND e.date_valid >= "'.$_REQUEST['date_debyear'].'-'.$_REQUEST['date_debmonth'].'-'.$_REQUEST['date_debday'].' 00:00:00"'; 125 | $sql.= ' AND e.date_valid <= "'.$_REQUEST['date_finyear'].'-'.$_REQUEST['date_finmonth'].'-'.$_REQUEST['date_finday'].' 23:59:59"'; 126 | $sql.= ' GROUP BY e.rowid'; 127 | 128 | } elseif($type === 'commande') { 129 | 130 | $sql = 'SELECT SUM(cd.qty) as nb_prods 131 | FROM '.MAIN_DB_PREFIX.'commandedet cd 132 | INNER JOIN '.MAIN_DB_PREFIX.'commande c ON (cd.fk_commande = c.rowid) 133 | INNER JOIN '.MAIN_DB_PREFIX.'product p ON (p.rowid = cd.fk_product) 134 | WHERE p.rowid = '.$id_prod; 135 | $sql.= ' AND c.date_commande >= "'.$_REQUEST['date_debyear'].'-'.$_REQUEST['date_debmonth'].'-'.$_REQUEST['date_debday'].' 00:00:00"'; 136 | $sql.= ' AND c.date_commande <= "'.$_REQUEST['date_finyear'].'-'.$_REQUEST['date_finmonth'].'-'.$_REQUEST['date_finday'].' 23:59:59"'; 137 | $sql.= ' GROUP BY c.rowid'; 138 | 139 | } else { 140 | 141 | $sql = 'SELECT SUM(fd.qty) as nb_prods 142 | FROM '.MAIN_DB_PREFIX.'facturedet fd 143 | INNER JOIN '.MAIN_DB_PREFIX.'facture f ON (fd.fk_facture = f.rowid) 144 | INNER JOIN '.MAIN_DB_PREFIX.'product p ON (p.rowid = fd.fk_product) 145 | WHERE p.rowid = '.$id_prod; 146 | $sql.= ' AND f.datef >= "'.$_REQUEST['date_debyear'].'-'.$_REQUEST['date_debmonth'].'-'.$_REQUEST['date_debday'].' 00:00:00"'; 147 | $sql.= ' AND f.datef <= "'.$_REQUEST['date_finyear'].'-'.$_REQUEST['date_finmonth'].'-'.$_REQUEST['date_finday'].' 23:59:59"'; 148 | $sql.= ' GROUP BY f.rowid'; 149 | 150 | } 151 | //echo $sql.'
';exit; 152 | $resql = $db->query($sql); 153 | $TResql = array(); 154 | while($res = $db->fetch_object($resql)) $TResql[$id_prod][] = $res->nb_prods; 155 | $TProdAverage[$id_prod] = array_sum($TResql[$id_prod]) / count($TResql[$id_prod]); 156 | 157 | } 158 | 159 | foreach($TData as &$Tab) $Tab['avg_products'] = $TProdAverage[$Tab['id_prod']]; 160 | 161 | } 162 | 163 | function get_sql($date_deb, $date_fin, $type) { 164 | 165 | if($type === 'expedition') { 166 | 167 | $field_date = 'e.date_valid'; 168 | $field_date2 = 'e2.date_valid'; 169 | 170 | $sql = 'SELECT WEEK('.$field_date.') as semaine 171 | , '.$field_date.' 172 | , p.rowid as id_prod, p.ref as ref_prod 173 | , SUM(ed.qty) as nb_products 174 | FROM '.MAIN_DB_PREFIX.'expeditiondet ed 175 | INNER JOIN '.MAIN_DB_PREFIX.'expedition e ON (ed.fk_expedition = e.rowid) 176 | INNER JOIN '.MAIN_DB_PREFIX.'commandedet cd ON (cd.rowid = ed.fk_origin_line) 177 | INNER JOIN '.MAIN_DB_PREFIX.'product p ON (p.rowid = cd.fk_product) 178 | WHERE (1)'; 179 | 180 | } elseif($type === 'commande') { 181 | 182 | $field_date = 'c.date_commande'; 183 | $field_date2 = 'c2.date_commande'; 184 | 185 | $sql = 'SELECT WEEK('.$field_date.') as semaine 186 | , '.$field_date.' 187 | , p.rowid as id_prod, p.ref as ref_prod 188 | , SUM(cd.qty) as nb_products 189 | FROM '.MAIN_DB_PREFIX.'commandedet cd 190 | INNER JOIN '.MAIN_DB_PREFIX.'commande c ON (cd.fk_commande = c.rowid) 191 | INNER JOIN '.MAIN_DB_PREFIX.'product p ON (p.rowid = cd.fk_product) 192 | WHERE (1)'; 193 | 194 | } elseif($type === 'facture') { 195 | 196 | $field_date = 'f.datef'; 197 | 198 | $sql = 'SELECT WEEK('.$field_date.') as semaine 199 | , '.$field_date.' 200 | , p.rowid as id_prod, p.ref as ref_prod 201 | , SUM(fd.qty) as nb_products 202 | FROM '.MAIN_DB_PREFIX.'facturedet fd 203 | INNER JOIN '.MAIN_DB_PREFIX.'facture f ON (fd.fk_facture = f.rowid) 204 | INNER JOIN '.MAIN_DB_PREFIX.'product p ON (p.rowid = fd.fk_product) 205 | WHERE (1)'; 206 | 207 | } 208 | 209 | $sql.= ' AND '.$field_date.' >= "'.$_REQUEST['date_debyear'].'-'.$_REQUEST['date_debmonth'].'-'.$_REQUEST['date_debday'].' 00:00:00"'; 210 | $sql.= ' AND '.$field_date.' <= "'.$_REQUEST['date_finyear'].'-'.$_REQUEST['date_finmonth'].'-'.$_REQUEST['date_finday'].' 23:59:59"'; 211 | 212 | $sql.= ' GROUP BY WEEK('.$field_date.'), p.ref'; 213 | //echo $sql;exit; 214 | return $sql; 215 | 216 | } 217 | 218 | function draw_table(&$TData) { 219 | 220 | global $db, $langs; 221 | 222 | // Je ne fais pas de liste TBS parce que je vais devoir afficher le tableau en base 64 dans la dom pour le poster vers un fichier download.php pour télécharger un csv 223 | print ''; 224 | print ''; 225 | print ''; 226 | print ''; 227 | print ''; 228 | print ''; 229 | print ''; 230 | 231 | $p = new Product($db); 232 | foreach($TData as $Tab) { 233 | $p->fetch($Tab['id_prod']); 234 | print ''; 235 | print ''; 236 | print ''; 237 | print ''; 238 | print ''; 239 | print ''; 240 | 241 | } 242 | 243 | print '
SemaineProduitNombre de produitsMoyenne période
'.$Tab['semaine'].''.$p->getNomUrl(1).''.$Tab['nb_products'].''.$Tab['avg_products'].'
'; 244 | 245 | print ''; 253 | 254 | } 255 | 256 | function download_file(&$TData, $type) { 257 | 258 | $name = $type.'_'.$_REQUEST['date_debyear'].$_REQUEST['date_debmonth'].$_REQUEST['date_debday'].'_' 259 | .$_REQUEST['date_finyear'].$_REQUEST['date_finmonth'].$_REQUEST['date_finday'].'.csv'; 260 | $fname = sys_get_temp_dir().'/'.$name; 261 | $f = fopen($fname, 'w+'); 262 | fputcsv($f, array('Semaine', 'Produit', 'Nombre de produits', 'Moyenne période'), ';'); 263 | 264 | foreach($TData as $Tab) { 265 | 266 | fputcsv($f, array($Tab['semaine'] 267 | , $Tab['ref_prod'] 268 | , $Tab['nb_products'] 269 | , $Tab['avg_products'] 270 | ) 271 | , ';'); 272 | 273 | } 274 | 275 | fclose($f); 276 | 277 | header('Content-Description: File Transfer'); 278 | header('Content-Type: application/CSV'); 279 | header('Content-Disposition: attachment; filename="'.$name.'"'); 280 | header('Expires: 0'); 281 | header('Cache-Control: must-revalidate'); 282 | header('Pragma: public'); 283 | header('Content-Length: ' . filesize($fname)); 284 | readfile($fname); 285 | exit; 286 | 287 | } 288 | -------------------------------------------------------------------------------- /langs/fr_FR/mandarin.lang: -------------------------------------------------------------------------------- 1 | Module104996Name = Mandarine 2 | Module104996Desc = Collection de repporting complexe sous forme de graphique 3 | 4 | ATMAbout = Ce module a été développé par ATM Consulting
Vous pouvez retrouver la documentation sur notre wiki

Pour toute question technique ou retour, contactez-nous sur support@atm-consulting.fr

Pour toute question commerciale, contactez-nous sur contact@atm-consulting.fr ou au +33 9 77 19 50 70

Retrouvez nos autres modules sur Dolistore 5 | 6 | mandarinSetup = Configuration du module mandarin 7 | mandarinAbout = A propos du module mandarin 8 | 9 | UserGroup = Groupe utilisateur 10 | 11 | GRAPH_PROJECT_BY_USER_HIERARCHYME = Limiter la vue à l'utilisateur et ces subordonnés (fonctionne sur le rapport : Nombre de projets par statut opportunité et par commercial) 12 | 13 | 14 | # GRAPH CA CUMULE 15 | permGraphCACumule = Autoriser la visualisation du graphique CA cumulé (menu SIG) 16 | linkMenuGraphCACumule = Graphique CA cumulé 17 | titleGraphCACumule = CA cumulé N et N-1 18 | subTitleVAxisGraphCACumule = Montant HT 19 | subTitleHAxisGraphCACumule = Semaines 20 | 21 | 22 | # GRAPH CA HORAIRE 23 | permGraphCAHoraire = Autoriser la visualisation du graphique CA par heures travaillées (menu SIG) 24 | linkMenuGraphCAHoraire = Graphique CA horaire 25 | titleGraphCAHoraire = CA / heures travaillées 26 | subTitleVAxisGraphCAHoraire = CA / %s et Nombre d'heures à la semaine 27 | subTitleHAxisGraphCAHoraire = Semaines 28 | 29 | # GRAPH COUT INTERIM 30 | MANDARIN_OBJECTIF_COUT_INTERIM = Valeur par défaut de l'objectif coût intérim (vide pour ne pas le voir apparaître sur le graphique) 31 | permGraphInterim = Autoriser la visualisation du graphique coût intérim (menu sig) 32 | linkMenuGraphInterim = Graphique coût intérim 33 | titleGraphInterim = Coût intérim 34 | subTitleVAxisGraphInterim = Coût à la semaine 35 | subTitleHAxisGraphInterim = Semaines 36 | 37 | # GRAPH HEURES TRAVAILLEES 38 | permGraphTotalHeure = Autoriser la visualisation du graphique total heures travaillées (menu SIG) 39 | linkMenuGraphTotalHeure = Graphique heures travaillées 40 | titleGraphTotalHeure = Heures travaillées (CDI) 41 | subTitleVAxisGraphTotalHeure = Heures à la semaine 42 | subTitleHAxisGraphTotalHeure = Semaines 43 | 44 | # GRAPH EFFECTIF 45 | permGraphEffectif = Autoriser la visualisation du graphique de l'effectif (menu SIG) 46 | linkMenuGraphEffectif = Graphique effectif 47 | titleGraphEffectif = Effectif 48 | subTitleVAxisGraphEffectif = Personnels 49 | subTitleHAxisGraphEffectif = Semaines 50 | 51 | #GRAPH CAPACITE DE PRODUCTION PERIODE 52 | RapportCapaciteProduction = Capacité de production 53 | timeInput = Temps saisi sur la période 54 | set_MANDARIN_GRAPH_TIME_ON_PERIOD = Afficher le rapport de temps saisi/capacité de production. 55 | 56 | # GRAPH HORAIRE MOYEN 57 | MANDARIN_HORAIRE_MOYEN_NOMAL = Valeur par défaut de l'horaire moyen (vide pour ne pas le voir apparaître sur le graphique) 58 | permGraphHoraireMoyen = Autoriser la visualisation du graphique horaire moyen (menu SIG) 59 | linkMenuGraphHoraireMoyen = Graphique horaire moyen 60 | titleGraphHoraireMoyen = Horaire moyen 61 | subTitleVAxisGraphHoraireMoyen = Heures 62 | subTitleHAxisGraphHoraireMoyen = Semaines 63 | 64 | # GRAPH PROPAL FACTURE 65 | set_MANDARIN_COMMERCIAL_GROUP = Selectionner le groupe d'utilisateur ayant le status de "Commercial" 66 | err_NOGROUPCOMM = Pour utiliser ce rapport, il vous faut choisir un groupe utilisateur "Commerciaux" dans la configuration du module 67 | permGraphPropalFacture = Autoriser la visualisation du rapport concernant les propal/facture par commercial (menu SIG) 68 | permGraphPropalCommercial = Autoriser la visualisation du rapport de ses propales par status 69 | permGraphPropalAllCommercial = Autoriser la visualisation du rapport des propales par status et par commercial 70 | mandarinTitlePropalFactureCommercial = Commercial 71 | mandarinTitlePropalFactureNbPropal = Nb propositions 72 | mandarinTitlePropalFacturePropalPercentNotSigned = Pourcent non signée 73 | mandarinTitlePropalFacturePropalNbClient = Nb clients 74 | mandarinTitlePropalFactureTopClient = Top client 75 | mandarinTitlePropalFactureTopClientPercent = Pourcent 76 | mandarinTitlePropalFactureCA = CA 77 | mandarinTitlePropalFacturePropalPercentCA = Pourcent CA 78 | mandarinPropalsPerCommercial = Propositions par chargé de clientèle 79 | mandarinInvoicesPerCommercial = Factures par chargé de clientèle 80 | linkMenuGraphPropalFacture = Rapport propal/facture par commercial 81 | titleGraphPalmaresPercentCA = Palmares pourcent CA par client (%s) 82 | titleGraphPercentCAPerCC = Pourcent CA par CC (%s) 83 | titleGraphPropalByComm = Graphique du nombre de propositions par statut 84 | titleGraphCaPropalByComm = Graphique du chiffre d'affaire des propositions par statut 85 | noData = Aucune donnée disponible 86 | linkMenuPropalesByCommercial = Nombre Propositions par commercial 87 | linkMenuCAPropalesByCommercial = CA Propositions par commercial 88 | propalCreationDate = Date de création de la proposition 89 | 90 | #GRAPH EXCES TIMPESPENT 91 | permGraphProjectExceed = Autoriser la visualisation des projets en dépassement (menu projet) 92 | linkMenuProjectExceedReport = Projets en dépassement 93 | ReportExceed = Rapport dépassement projet 94 | 95 | # GRAPH PROJECT 96 | permGraphProject = Autoriser la visualisation du graphique projets (menu projets) 97 | linkMenuGraphProject = Graphique projets 98 | titleGraphProject = Etat d'avancement des projets 99 | subTitleVAxisGraphProject = Progression 100 | subTitleHAxisGraphProject = Projets 101 | 102 | # GRAPH PROJECT TASK 103 | permGraphProjectTask = Autoriser la visualisation du graphique des tâches (onglet sur fiche projet) 104 | titleGraphProjectTask = Etat avancement des tâches 105 | subTitleVAxisGraphProjectTask = Progression 106 | subTitleHAxisGraphProjectTask = Tâches 107 | 108 | # RAPPORT EVENEMENTS PAR COMMERCIAUX 109 | permReportActionByUser=Autoriser la visualisation du rapport nombre événements par commerciaux (menu agenda) 110 | Reports=Rapports 111 | RapportEvenementsParCommerciaux=Nombre d'événements par type et par commercial 112 | EventType=Types d'événements 113 | mandarinTitleGraphEventByUser=Nombre d'événements par type et par commercial 114 | titleGraphEventByUser=Graphique du nombre d'événements par type 115 | 116 | # RAPPORT Moyenne des produits commandés, facturés et envoyés 117 | RapportMoyenneProduitsVendusCommandesEnvoyes=Moyenne par période des produits commandés, facturés ou envoyés (menu produit) 118 | AverageProducts=Moyennes par période 119 | AnalyzedData=Données analysées 120 | 121 | # Rapport temps moyen de réception des produits 122 | RapportTempsMoyenReceptionProduits=Temps moyen de réception des produits (menu produit) 123 | AverageReceipProducts=Tps moyen récep. produits 124 | 125 | # GRAPH PROJECT BY USER 126 | linkMenuProjectByUserReport=Nombre de projets par statut opportunité et par commercial 127 | linkMenuProjectByUserReportShort=Nb projets par commercial 128 | permGraphProjectByUser=Autoriser la visualisation du graphique projets par commercial et par statut opportunité (menu projets) 129 | titleGraphProjectByTypeShort=Nombre de projets par statut d'opportunité 130 | titleGraphProjectByType=Graphique du nombre de projets par statut d'opportunité 131 | 132 | #Cost Price 133 | set_MANDARIN_TRACE_COST_PRICE=Tracer les prix de revient 134 | GraphTraceCostPrice=Analyse des prix de revient 135 | RapportAnalyseCoutProductMP=Utilisation des matières premières 136 | RapportAnalyseCoutProduct=Analyse 137 | costPriceTraceGraph=Graphique d'analyse des prix de revient (menu asset) 138 | Percent=Pourcentage 139 | RapportAnalyseCoutProductPF=Fabrication de produit fini 140 | RapportAnalyseMotifRebus=Motif de déchets sur MP 141 | 142 | #CAClientMonth 143 | CAClientMonth=CA par client/mois 144 | permCAClientMonth=CA par client/mois (menu Commandes et Factures client) 145 | monthJan=Jan 146 | monthMar=Mars 147 | monthSep=Sept 148 | monthNov=Nov 149 | monthDec=Dec 150 | monthOct=Oct 151 | monthMay=Mai 152 | monthFeb=Fev 153 | monthApr=Avr 154 | monthJun=Juin 155 | monthJul=Juil 156 | monthAug=Aou 157 | ExportCSV=Export CSV 158 | 159 | # GRAPH DIFF VENTE PAR COMMERCIAL - DIFF ENTRE LES TOTAUX HT ET TTC (PROPAL / COMMANDE) 160 | permGraphDiffByCommercial=Autoriser la visualisation de la liste du diff entre HT/TTC propal/commande par commercial (menu commande) 161 | linkMenuGraphByCommercial=Diff Propal/Cmd 162 | titleGraphByCommercial=Différence HT/TTC des propals/commandes 163 | commercial=Commercial 164 | propal_amount_ht=Montant Propal HT 165 | propal_amount_ttc=Montant Propal TTC 166 | commande_amount_ht=Montant Commande HT 167 | commande_amount_ttc=Montant Commande TTC 168 | diff_ht=Diff HT 169 | diff_ttc=Diff TTC 170 | 171 | # Report Repartition achats fournisseurs 172 | mandarinTitleRepartitionAchatsFournisseurs=Répartition des achats par %s 173 | AnalyseDate=Période d'analyse 174 | MANDARIN_POURCENTAGE_ALERTE=Pourcentage à partir duquel les données sont affichées en rouge 175 | permReportRepartitionBySupplier=Autoriser la visualisation du rapport de répartition des achats par producteur 176 | linkMenuRepartitionAchatsBySupplier=Rapport répartition des achats 177 | 178 | #Export 179 | Bill=Facture 180 | Order=Commande 181 | CustomerOrderAndBills= Export Clients, Commandes et Factures liées 182 | InvoiceDateCreation=Date création facture 183 | DateInvoice=Date de facturation 184 | InvoicePaid=Payé 185 | InvoiceStatus=Statut 186 | InvoiceId=Identifiant facture 187 | OrderId=Identifiant commande 188 | OrderRef=Ref. Commande 189 | OrderDateCreation=Date de création de la commande 190 | DateOrder=Date de commande 191 | OrderStatus=Statut 192 | IncludeAllProducts=Inclure tous les produits 193 | 194 | linkMenuReportCAArticles=Evolution CA articles 195 | linkMenuReportCAArticlesHelp=Chiffre d'affaire réalisé par catégorie d'article, par article et par mois 196 | 197 | linkMenuReportVentesArticles=Evolution ventes articles 198 | linkMenuReportVentesArticlesHelp=Volume total vendu par catégorie d'article, par article et par mois 199 | 200 | linkMenuReportAchatsCAArticles=Evolution CA achats articles 201 | linkMenuReportAchatsCAArticlesHelp=Sommes des factures fournisseurs par catégorie d'article, par article et par mois 202 | 203 | linkMenuReportAchatsArticles=Evolution achats articles 204 | linkMenuReportAchatsArticlesHelp=Volume total acheté par catégorie d'article, par article et par mois 205 | 206 | linkMenuReportAchatsCAFournisseurs=Evolution CA achats fournisseurs 207 | linkMenuReportAchatsCAFournisseursHelp=Sommes des factures fournisseurs par catégorie de fournisseur, par fournisseur et par mois 208 | 209 | linkMenuReportAchatsFournisseurs=Evolution achats fournisseurs 210 | linkMenuReportAchatsFournisseursHelp=Volume total acheté par catégorie de fournisseur, par fournisseur et par mois 211 | -------------------------------------------------------------------------------- /admin/mandarin_setup.php: -------------------------------------------------------------------------------- 1 | 3 | * Copyright (C) 2015 ATM Consulting 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /** 20 | * \file admin/mandarin.php 21 | * \ingroup mandarin 22 | * \brief This file is an example module setup page 23 | * Put some comments here 24 | */ 25 | // Dolibarr environment 26 | $res = @include("../../main.inc.php"); // From htdocs directory 27 | if (! $res) { 28 | $res = @include("../../../main.inc.php"); // From "custom" directory 29 | } 30 | 31 | // Libraries 32 | require_once DOL_DOCUMENT_ROOT . "/core/lib/admin.lib.php"; 33 | require_once '../lib/mandarin.lib.php'; 34 | 35 | // Translations 36 | $langs->load("mandarin@mandarin"); 37 | 38 | // Access control 39 | if (! $user->admin) { 40 | accessforbidden(); 41 | } 42 | 43 | // Parameters 44 | $action = GETPOST('action', 'alpha'); 45 | 46 | /* 47 | * Actions 48 | */ 49 | if (preg_match('/set_(.*)/',$action,$reg)) 50 | { 51 | $code=$reg[1]; 52 | if (dolibarr_set_const($db, $code, GETPOST($code), 'entier', 0, '', $conf->entity) > 0) 53 | { 54 | if($code == 'MANDARIN_TRACE_COST_PRICE' && GETPOST($code) == 'yes') { 55 | define('INC_FROM_DOLIBARR',true); 56 | dol_include_once('/mandarin/config.php'); 57 | dol_include_once('/mandarin/class/costpricelog.class.php'); 58 | $o=new TProductCostPriceLog; 59 | $PDOdb=new TPDOdb; 60 | // $PDOdb->debug =true; 61 | $o->init_db_by_vars($PDOdb); 62 | 63 | } 64 | 65 | header("Location: ".$_SERVER["PHP_SELF"]); 66 | exit; 67 | } 68 | else 69 | { 70 | dol_print_error($db); 71 | } 72 | } 73 | 74 | if (preg_match('/del_(.*)/',$action,$reg)) 75 | { 76 | $code=$reg[1]; 77 | if (dolibarr_del_const($db, $code, 0) > 0) 78 | { 79 | Header("Location: ".$_SERVER["PHP_SELF"]); 80 | exit; 81 | } 82 | else 83 | { 84 | dol_print_error($db); 85 | } 86 | } 87 | 88 | /* 89 | * View 90 | */ 91 | $page_name = "mandarinSetup"; 92 | llxHeader('', $langs->trans($page_name)); 93 | 94 | // Subheader 95 | $linkback = '' 96 | . $langs->trans("BackToModuleList") . ''; 97 | print_fiche_titre($langs->trans($page_name), $linkback); 98 | 99 | // Configuration header 100 | $head = mandarinAdminPrepareHead(); 101 | dol_fiche_head( 102 | $head, 103 | 'settings', 104 | $langs->trans("Module104996Name"), 105 | 0, 106 | "mandarin@mandarin" 107 | ); 108 | 109 | // Setup page goes here 110 | $form=new Form($db); 111 | $var=false; 112 | print ''; 113 | print ''; 114 | print ''."\n"; 115 | print ''; 116 | print ''."\n"; 117 | 118 | 119 | // Example with a yes / no select 120 | /* 121 | $var=!$var; 122 | print ''; 123 | print ''; 124 | print ''; 125 | print ''; 133 | */ 134 | 135 | $var=!$var; 136 | print ''; 137 | print ''; 138 | print ''; 139 | print ''; 147 | 148 | $var=!$var; 149 | print ''; 150 | print ''; 151 | print ''; 152 | print ''; 160 | 161 | $var=!$var; 162 | print ''; 163 | print ''; 164 | print ''; 165 | print ''; 172 | 173 | $var=!$var; 174 | print ''; 175 | print ''; 176 | print ''; 177 | print ''; 186 | 187 | $var=!$var; 188 | print ''; 189 | print ''; 190 | print ''; 191 | print ''; 199 | 200 | $var=!$var; 201 | print ''; 202 | print ''; 203 | print ''; 204 | print ''; 213 | 214 | 215 | _print_on_off('GRAPH_PROJECT_BY_USER_HIERARCHYME'); 216 | 217 | print '
'.$langs->trans("Parameters").' '.$langs->trans("Value").'
'.$langs->trans("ParamLabel").' '; 126 | print '
'; 127 | print ''; 128 | print ''; 129 | print $form->selectyesno("CONSTNAME",$conf->global->CONSTNAME,1); 130 | print ''; 131 | print '
'; 132 | print '
'.$langs->trans("MANDARIN_OBJECTIF_COUT_INTERIM").' '; 140 | print '
'; 141 | print ''; 142 | print ''; 143 | print ''; 144 | print ''; 145 | print '
'; 146 | print '
'.$langs->trans("MANDARIN_HORAIRE_MOYEN_NOMAL").' '; 153 | print '
'; 154 | print ''; 155 | print ''; 156 | print ''; 157 | print ''; 158 | print '
'; 159 | print '
'.$langs->trans("set_MANDARIN_GRAPH_TIME_ON_PERIOD").' '; 166 | print '
'; 167 | print ''; 168 | print ''; 169 | echo ajax_constantonoff('MANDARIN_GRAPH_TIME_ON_PERIOD'); 170 | print '
'; 171 | print '
'.$langs->trans("set_MANDARIN_TRACE_COST_PRICE").' '; 178 | print '
'; 179 | print ''; 180 | print ''; 181 | echo $form->selectyesno('MANDARIN_TRACE_COST_PRICE',$conf->global->MANDARIN_TRACE_COST_PRICE,1); // attention pas ajax car je dois passer en haut 182 | 183 | print ''; 184 | print '
'; 185 | print '
'.$langs->trans("MANDARIN_POURCENTAGE_ALERTE").' '; 192 | print '
'; 193 | print ''; 194 | print ''; 195 | print '%'; 196 | print ''; 197 | print '
'; 198 | print '
'.$langs->trans("set_MANDARIN_COMMERCIAL_GROUP").' '; 205 | print '
'; 206 | print ''; 207 | print ''; 208 | echo $form->select_dolgroups($conf->global->MANDARIN_COMMERCIAL_GROUP, 'MANDARIN_COMMERCIAL_GROUP', 1); 209 | 210 | print ''; 211 | print '
'; 212 | print '
'; 218 | 219 | llxFooter(); 220 | 221 | $db->close(); 222 | 223 | 224 | 225 | 226 | function _print_title($title="") 227 | { 228 | global $langs; 229 | print ''; 230 | print ''.$langs->trans($title).''."\n"; 231 | print ' '; 232 | print ''."\n"; 233 | print ''; 234 | } 235 | 236 | function _print_on_off($confkey, $title = false, $desc ='') 237 | { 238 | global $var, $bc, $langs, $conf; 239 | $var=!$var; 240 | 241 | print ''; 242 | print ''.($title?$title:$langs->trans($confkey)); 243 | if(!empty($desc)) 244 | { 245 | print '
'.$langs->trans($desc).''; 246 | } 247 | print ''; 248 | print ' '; 249 | print ''; 250 | print '
'; 251 | print ''; 252 | print ''; 253 | print ajax_constantonoff($confkey); 254 | print '
'; 255 | print ''; 256 | } 257 | 258 | function _print_input_form_part($confkey, $title = false, $desc ='', $metas = array(), $type='input', $help = false) 259 | { 260 | global $var, $bc, $langs, $conf, $db; 261 | $var=!$var; 262 | 263 | $form=new Form($db); 264 | 265 | $defaultMetas = array( 266 | 'name' => $confkey 267 | ); 268 | 269 | if($type!='textarea'){ 270 | $defaultMetas['type'] = 'text'; 271 | $defaultMetas['value'] = $conf->global->{$confkey}; 272 | } 273 | 274 | 275 | $metas = array_merge ($defaultMetas, $metas); 276 | $metascompil = ''; 277 | foreach ($metas as $key => $values) 278 | { 279 | $metascompil .= ' '.$key.'="'.$values.'" '; 280 | } 281 | 282 | print ''; 283 | print ''; 284 | 285 | if(!empty($help)){ 286 | print $form->textwithtooltip( ($title?$title:$langs->trans($confkey)) , $langs->trans($help),2,1,img_help(1,'')); 287 | } 288 | else { 289 | print $title?$title:$langs->trans($confkey); 290 | } 291 | 292 | if(!empty($desc)) 293 | { 294 | print '
'.$langs->trans($desc).''; 295 | } 296 | 297 | print ''; 298 | print ' '; 299 | print ''; 300 | print '
'; 301 | print ''; 302 | print ''; 303 | if($type=='textarea'){ 304 | print ''; 305 | } 306 | else { 307 | print ''; 308 | } 309 | 310 | print ''; 311 | print '
'; 312 | print ''; 313 | } 314 | -------------------------------------------------------------------------------- /evo_achats_fournisseurs.php: -------------------------------------------------------------------------------- 1 | categorie->enabled)) 13 | require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; 14 | 15 | if (! empty($conf->stock->enabled)) $langs->load("stocks"); 16 | if (! empty($conf->facture->enabled)) $langs->load("bills"); 17 | 18 | $langs->load("products"); 19 | $langs->load("suppliers"); 20 | $langs->load("companies"); 21 | 22 | // extra column because CSV export ignores the last column of the list -> it will ignore this dummy column instead of a real data column. 23 | $dummyColTd = ''; 24 | $dummyColTh = ''; 25 | 26 | $mode = GETPOST('mode'); 27 | $fk_soc = GETPOST('fk_soc'); 28 | $search_categ = GETPOST('search_categ', 'array'); 29 | $date_start=dol_mktime(0,0,0,GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear')); 30 | $date_end=dol_mktime(0,0,0,GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear')); 31 | 32 | // Purge search criteria 33 | if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers 34 | { 35 | $fk_soc=""; 36 | $search_categ=0; 37 | $date_start = strtotime(date("01-01-Y")); 38 | $date_end = strtotime(date("31-12-Y")); 39 | } 40 | 41 | if (empty($date_start)) $date_start = strtotime(date("01-01-Y")); 42 | if (empty($date_end)) $date_end = strtotime(date("31-12-Y")); 43 | 44 | $TYear = array(); 45 | $year = (int) date('Y', $date_start); 46 | $yearend = (int) date('Y', $date_end); 47 | if ($date_start < $date_end) 48 | { 49 | while ($year <= $yearend){ 50 | $TYear[] = $year; 51 | $year++; 52 | } 53 | } 54 | else 55 | { 56 | while ($year >= $yearend){ 57 | $TYear[] = $year; 58 | $year--; 59 | } 60 | 61 | sort($TYear); 62 | } 63 | 64 | $TMonth = array(); 65 | $month = (int) date('m', $date_start); 66 | $numyear = count($TYear); 67 | $monthend = (int) date('m', $date_end); 68 | 69 | foreach ($TYear as $k => $year) 70 | { 71 | $end = 12; 72 | if ($k == 0) $start = $month; 73 | else $start = 1; 74 | 75 | if ($k == $numyear -1) $end = $monthend; 76 | 77 | for ($i = $start; $i<=$end; $i++) 78 | { 79 | $TMonth[$year][$i] = $langs->trans('month'. date('M', strtotime(date('Y-'.$i.'-01'))) ).'-'.$year; 80 | } 81 | if ($i == 12) $start = 1; 82 | 83 | } 84 | 85 | $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; 86 | $sortfield = GETPOST("sortfield",'alpha'); 87 | $sortorder = GETPOST("sortorder",'alpha'); 88 | $page = (GETPOST("page",'int')?GETPOST("page", 'int'):0); 89 | if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 90 | $offset = $limit * $page; 91 | $pageprev = $page - 1; 92 | $pagenext = $page + 1; 93 | if (! $sortfield) $sortfield="p.ref"; 94 | if (! $sortorder) $sortorder="ASC"; 95 | 96 | $form = new Form($db); 97 | $htmlother=new FormOther($db); 98 | 99 | $hookmanager->initHooks(array('mandarinArticleslist')); 100 | $extrafields = new ExtraFields($db); 101 | 102 | $transkey = 'linkMenuReportAchatsFournisseurs'; 103 | if ($mode == "CA") $transkey = 'linkMenuReportAchatsCAFournisseurs'; 104 | 105 | llxHeader('', $langs->trans($transkey), ''); 106 | 107 | //dol_fiche_head(); 108 | 109 | $sql = "SELECT cat.rowid as cat_id, s.rowid as socid"; 110 | 111 | if ($mode == "CA") $numfield = 'd.total_ht'; 112 | else $numfield = "IF(f.type = ".FactureFournisseur::TYPE_CREDIT_NOTE." , -(d.qty), d.qty)"; 113 | 114 | foreach ($TMonth as $year => $month) { 115 | $start = ''; 116 | foreach ($month as $k => $m) 117 | { 118 | if (empty($start)) $firststart = strtotime(" 01-$k-$year"); 119 | $start = strtotime(" 01-$k-$year"); 120 | $end = strtotime("+1 month -1 day", $start); 121 | 122 | $sql.= ", SUM(IF(f.datef >= '".date("Y-m-d 00:00:00",$start)."' AND f.datef <= '".date("Y-m-d 23:59:59", $end)."', ".$numfield.", 0)) as ".str_replace("-", "_", $m); 123 | } 124 | 125 | $sql.= ", SUM(IF(f.datef >= '".date("Y-m-d 00:00:00",$firststart)."' AND f.datef <= '".date("Y-m-d 23:59:59", $end)."', ".$numfield.", 0)) as total_".$year; 126 | 127 | } 128 | $sql.= ", SUM(IF(f.datef >= '".date("Y-m-d 00:00:00",$date_start)."' AND f.datef <= '".date("Y-m-d 23:59:59", $date_end)."', ".$numfield.", 0)) as total_global"; 129 | 130 | $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn_det AS d"; 131 | $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as f ON f.rowid = d.fk_facture_fourn"; 132 | $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc"; 133 | $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_fournisseur AS cf ON cf.fk_soc = s.rowid"; 134 | $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie AS cat ON cat.rowid = cf.fk_categorie"; 135 | 136 | $sql.= " WHERE f.fk_statut > 0"; 137 | $sql.= " AND f.datef >= '".date('Y-m-d 00:00:00', $date_start)."'"; 138 | $sql.= " AND f.datef <= '".date('Y-m-d 23:59:59',$date_end)."'"; 139 | 140 | // filters 141 | if (!empty($search_categ)) 142 | { 143 | $sql.= " AND cat.rowid IN (".implode(',', $search_categ).")"; 144 | } 145 | 146 | if (!empty($fk_soc) && $fk_soc > 0) 147 | { 148 | $sql.= " AND f.fk_soc = " . $fk_soc; 149 | } 150 | 151 | $sql.= " GROUP BY cat.rowid, s.rowid"; 152 | $sql.= " ORDER BY cat.rowid ASC, s.nom ASC"; 153 | 154 | //print $sql; 155 | $resql = $db->query($sql); 156 | 157 | print '
'; 158 | if ($optioncss != '') print ''; 159 | print ''; 160 | print ''; 161 | print ''; 162 | print ''; 163 | print ''; 164 | print ''; 165 | print ''; 166 | 167 | print_barre_liste($langs->trans($transkey), $page, $_SERVER["PHP_SELF"]); 168 | 169 | print '
'; 170 | print ' '; 171 | print $langs->trans($transkey.'Help'); 172 | print '
'; 173 | 174 | $moreforfilter=''; 175 | $moreforfilter.='
'; 176 | if (! empty($conf->categorie->enabled)) 177 | { 178 | $moreforfilter.=''; 179 | $cate_arbo = $form->select_all_categories(Categorie::TYPE_SUPPLIER, '', 'parent', 64, 0, 1); 180 | $moreforfilter.=''; 181 | } 182 | 183 | $moreforfilter.=''; 184 | $moreforfilter.=''; 185 | 186 | $moreforfilter.=''; 187 | $moreforfilter.=''; 188 | $moreforfilter.=''; 189 | 190 | $moreforfilter.='
'.$langs->trans('Categories'). ' : '.$form->multiselectarray('search_categ', $cate_arbo, $search_categ, '', 0, '', 0, '50%').'
'.$langs->trans('Supplier') . ' : '.$form->select_company($fk_soc, 'fk_soc', 's.fournisseur = 1', 1).'
'.$langs->trans('DateInvoice'). ' '.$langs->trans('From'). ' : ' .$form->select_date($date_start, 'date_start', 0,0,0,'',1,0,1) .''.$langs->trans('to'). ' : ' .$form->select_date($date_end, 'date_end', 0,0,0,'',1,0,1).'
'; 191 | 192 | $parameters=array(); 193 | $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook 194 | if (empty($reshook)) $moreforfilter.=$hookmanager->resPrint; 195 | else $moreforfilter=$hookmanager->resPrint; 196 | 197 | if ($moreforfilter) 198 | { 199 | print '
'; 200 | print $moreforfilter; 201 | print '
'; 202 | } 203 | 204 | print '
'; 205 | print ''."\n"; 206 | 207 | print ''; 208 | 209 | $colspan = 4; 210 | 211 | foreach ($TMonth as $year => $month) 212 | { 213 | $colspan+=count($month); 214 | } 215 | 216 | print ''; 217 | print ''; 221 | print $dummyColTd; 222 | print ''; 223 | 224 | print ''; 225 | print ''; 226 | // print ''; 227 | print ''; 228 | print ''; 229 | foreach ($TMonth as $year => $month) { 230 | foreach ($month as $m) 231 | { 232 | print ''; 233 | } 234 | print ''; 235 | } 236 | print ''; 237 | print $dummyColTh; 238 | print ''; 239 | 240 | $lastcat = ''; 241 | $GlobalTabTotal = array(); 242 | 243 | while ($obj = $db->fetch_object($resql)) 244 | { 245 | if ($lastcat !== $obj->cat_id) 246 | { 247 | if (!empty($tabtotal)) 248 | { 249 | //var_dump($tabtotal); 250 | print ""; 251 | // print ""; 252 | print ""; 253 | print ""; 254 | print ""; 255 | foreach ($tabtotal as $tab) 256 | { 257 | if ($mode == "CA") print ""; 258 | else print ""; 259 | } 260 | print $dummyColTd; 261 | print ""; 262 | 263 | foreach ($tabtotal as $k => $v) $GlobalTabTotal[$k] += $v; 264 | } 265 | 266 | $lastcat = $obj->cat_id; 267 | $catprinted = false; 268 | $tabtotal = array(); 269 | } 270 | 271 | print ''; 272 | 273 | if ($catprinted) print ''; 274 | else 275 | { 276 | if (!empty($obj->cat_id)) 277 | { 278 | $cat = new Categorie($db); 279 | $cat->fetch($obj->cat_id); 280 | 281 | // print ""; 282 | print ""; 283 | } 284 | else 285 | { 286 | print ""; 287 | } 288 | 289 | 290 | $catprinted = true; 291 | } 292 | 293 | $soc = new Societe($db); 294 | $soc->fetch($obj->socid); 295 | 296 | print ""; 297 | print ""; 298 | 299 | $totalligne = 0; 300 | foreach($TMonth as $year => $month) 301 | { 302 | foreach ($month as $m) 303 | { 304 | $field = str_replace("-", "_", $m); 305 | $val = price2num($obj->{$field}, 'MT'); 306 | 307 | $tabtotal[$field]+= $val; 308 | 309 | print ''; 310 | } 311 | 312 | //on convertit en prix si évol CA après le calcul du montant 313 | if($mode == "CA") { 314 | foreach($tabtotal as $field =>$val){ 315 | $tabtotal[$field] = price($val); 316 | } 317 | } 318 | 319 | $field = "total_".$year; 320 | $val = price2num($obj->{$field}, 'MT'); 321 | 322 | if (empty($tabtotal[$field])) $tabtotal[$field] = ($mode == "CA") ? price($val) : $val; 323 | else $tabtotal[$field] += ($mode == "CA") ? price($val) : $val; 324 | 325 | if (empty($totalligne)) $totalligne = ($mode == "CA") ? price($val) : $val; 326 | else $totalligne += ($mode == "CA") ? price($val) : $val; 327 | 328 | print ''; 329 | 330 | 331 | } 332 | $tabtotal['ligne'] += price2num(($mode == "CA") ? price($totalligne) : $totalligne, 'MT'); 333 | 334 | print ''; 335 | 336 | print $dummyColTd; 337 | print ''; 338 | 339 | } 340 | 341 | if (!empty($tabtotal)) 342 | { 343 | print ""; 344 | // print ""; 345 | print ""; 346 | print ""; 347 | print ""; 348 | foreach ($tabtotal as $tab) 349 | { 350 | print ""; 351 | } 352 | print $dummyColTd; 353 | print ""; 354 | 355 | foreach ($tabtotal as $k => $v) { 356 | 357 | if(empty($GlobalTabTotal[$k])) $GlobalTabTotal[$k] = 0; 358 | $v = price2num($v); 359 | $GlobalTabTotal[$k] += $v; 360 | } 361 | } 362 | 363 | print ""; 364 | print ""; 365 | print ""; 366 | print ""; 367 | foreach ($GlobalTabTotal as $tab) 368 | { 369 | print ""; 370 | } 371 | print $dummyColTd; 372 | print ""; 373 | 374 | print '
'; 218 | $searchpicto=$form->showFilterButtons(); 219 | print $searchpicto; 220 | print '
'.$langs->trans('Categories').''.$langs->trans('Ref').''.$langs->trans('Supplier').''.$langs->trans('Ref').''.$m.'Total '.$year.'Total global
Total ".(!empty($cat->label) ? $cat->label : 'Sans catégorie')."".price($tab)." €".$tab."
".$cat->description."".$cat->label."Sans catégorie".$soc->name."".$soc->code_fournisseur."'.(($mode == "CA") ? price($val) . " €" : $val).''.(($mode == "CA") ? price($val) . " €" : $val).''.(($mode == "CA") ? price($obj->total_global) ." €" : $obj->total_global).'
Total ".(!empty($cat->label) ? $cat->label : 'Sans catégorie')."".(($mode == "CA") ? price($tab) . " €" : $tab)."
Total Général".(($mode == "CA") ? price($tab) . " €" : $tab)."
'; 375 | print '
'; 376 | print '
'; 377 | 378 | ?> 379 | 384 | categorie->enabled)) 10 | require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; 11 | 12 | if (! empty($conf->stock->enabled)) $langs->load("stocks"); 13 | if (! empty($conf->facture->enabled)) $langs->load("bills"); 14 | 15 | $langs->load("products"); 16 | $langs->load("suppliers"); 17 | $langs->load("companies"); 18 | 19 | // extra column because CSV export ignores the last column of the list -> it will ignore this dummy column instead of a real data column. 20 | $dummyColTd = ''; 21 | $dummyColTh = ''; 22 | 23 | $mode = GETPOST('mode'); 24 | $fk_soc = GETPOST('fk_soc'); 25 | $search_categ = GETPOST('search_categ', 'array'); 26 | $date_start=dol_mktime(0,0,0,GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear')); 27 | $date_end=dol_mktime(0,0,0,GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear')); 28 | $includeAllProducts = boolval(GETPOST('includeAllProducts', 'alpha')); 29 | $product_ref = GETPOST('product_ref', 'nohtml'); 30 | $product_label = GETPOST('product_label', 'nohtml'); 31 | 32 | // Purge search criteria 33 | if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers 34 | { 35 | $fk_soc=""; 36 | $search_categ=0; 37 | $date_start = strtotime(date("01-01-Y")); 38 | $date_end = strtotime(date("31-12-Y")); 39 | } 40 | 41 | if (empty($date_start)) $date_start = strtotime(date("01-01-Y")); 42 | if (empty($date_end)) $date_end = strtotime(date("31-12-Y")); 43 | 44 | $TYear = array(); 45 | $year = (int) date('Y', $date_start); 46 | $yearend = (int) date('Y', $date_end); 47 | if ($date_start < $date_end) 48 | { 49 | while ($year <= $yearend){ 50 | $TYear[] = $year; 51 | $year++; 52 | } 53 | } 54 | else 55 | { 56 | while ($year >= $yearend){ 57 | $TYear[] = $year; 58 | $year--; 59 | } 60 | 61 | sort($TYear); 62 | } 63 | 64 | $TMonth = array(); 65 | $month = (int) date('m', $date_start); 66 | $numyear = count($TYear); 67 | $monthend = (int) date('m', $date_end); 68 | 69 | foreach ($TYear as $k => $year) 70 | { 71 | $end = 12; 72 | if ($k == 0) $start = $month; 73 | else $start = 1; 74 | 75 | if ($k == $numyear -1) $end = $monthend; 76 | 77 | for ($i = $start; $i<=$end; $i++) 78 | { 79 | $TMonth[$year][$i] = $langs->trans('month'. date('M', strtotime(date('Y-'.$i.'-01'))) ).'-'.$year; 80 | } 81 | if ($i == 12) $start = 1; 82 | 83 | } 84 | 85 | $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; 86 | $sortfield = GETPOST("sortfield",'alpha'); 87 | $sortorder = GETPOST("sortorder",'alpha'); 88 | $page = (GETPOST("page",'int')?GETPOST("page", 'int'):0); 89 | if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 90 | $offset = $limit * $page; 91 | $pageprev = $page - 1; 92 | $pagenext = $page + 1; 93 | if (! $sortfield) $sortfield="p.ref"; 94 | if (! $sortorder) $sortorder="ASC"; 95 | 96 | $form = new Form($db); 97 | $htmlother=new FormOther($db); 98 | 99 | $hookmanager->initHooks(array('mandarinArticleslist', 'mandarinevoventearticle')); 100 | $extrafields = new ExtraFields($db); 101 | 102 | $transkey = 'linkMenuReportVentesArticles'; 103 | if ($mode == "CA") $transkey = 'linkMenuReportCAArticles'; 104 | 105 | llxHeader('', $langs->trans($transkey), ''); 106 | 107 | //dol_fiche_head(); 108 | 109 | $sql = "SELECT cat.rowid as cat_id, p.rowid as p_id"; 110 | 111 | if ($mode == "CA") $numfield = 'd.total_ht'; 112 | else $numfield = "IF(f.type = ".Facture::TYPE_CREDIT_NOTE." , -(d.qty), d.qty)"; 113 | 114 | foreach ($TMonth as $year => $month) { 115 | $start = ''; 116 | foreach ($month as $k => $m) 117 | { 118 | if (empty($start)) $firststart = strtotime(" 01-$k-$year"); 119 | $start = strtotime(" 01-$k-$year"); 120 | $end = strtotime("+1 month -1 day", $start); 121 | 122 | $sql.= ", SUM(IF(f.datef >= '".date("Y-m-d 00:00:00",$start)."' AND f.datef <= '".date("Y-m-d 23:59:59", $end)."', ".$numfield.", 0)) as ".str_replace("-", "_", $m); 123 | } 124 | 125 | $sql.= ", SUM(IF(f.datef >= '".date("Y-m-d 00:00:00",$firststart)."' AND f.datef <= '".date("Y-m-d 23:59:59", $end)."', ".$numfield.", 0)) as total_".$year; 126 | 127 | } 128 | 129 | $sql.= ", SUM(IF(f.datef >= '".date("Y-m-d 00:00:00",$date_start)."' AND f.datef <= '".date("Y-m-d 23:59:59", $date_end)."', ".$numfield.", 0)) as total_global"; 130 | $sql.= " FROM ".MAIN_DB_PREFIX."product as p"; 131 | $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.fk_product=p.rowid"; 132 | $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as cat ON cat.rowid=cp.fk_categorie"; 133 | $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facturedet AS d ON d.fk_product = p.rowid"; 134 | $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture AS f ON f.rowid = d.fk_facture"; 135 | 136 | // Add fields from hooks 137 | $parameters=array(); 138 | $reshook=$hookmanager->executeHooks('printFieldListJoin',$parameters); // Note that $action and $object may have been modified by hook 139 | $sql.=$hookmanager->resPrint; 140 | 141 | $sql.= " WHERE "; 142 | $sql.= (!empty($product_ref) ? natural_search("p.ref", $db->escape($product_ref), 0, 1) . ' AND ' : ""); 143 | $sql.= (!empty($product_label) ? natural_search("p.label", $db->escape($product_label), 0, 1) . ' AND ' : ""); 144 | $sql.= ($includeAllProducts ? 'f.rowid IS NULL OR (' : ''); 145 | $sql.= " f.fk_statut > 0"; 146 | $sql.= " AND f.datef >= '".date('Y-m-d 00:00:00', $date_start)."'"; 147 | $sql.= " AND f.datef <= '".date('Y-m-d 23:59:59',$date_end)."'"; 148 | $sql.= ($includeAllProducts ? ')' : ''); 149 | 150 | // filters 151 | if (!empty($search_categ)) 152 | { 153 | $sql.= " AND cat.rowid IN (".implode(',', $search_categ).")"; 154 | } 155 | 156 | if (!empty($fk_soc) && $fk_soc > 0) 157 | { 158 | $sql.= " AND f.fk_soc = " . $fk_soc; 159 | } 160 | 161 | // Add where from hooks 162 | $parameters=array('sql' => $sql); 163 | $reshook=$hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook 164 | $sql.=$hookmanager->resPrint; 165 | 166 | $sql.= " GROUP BY cat.rowid, p.rowid"; 167 | $sql.= " ORDER BY cat.rowid ASC, p.ref ASC"; 168 | 169 | $resql = $db->query($sql); 170 | 171 | if(!$resql){ 172 | dol_print_error($db); 173 | } 174 | 175 | print '
'; 176 | if ($optioncss != '') print ''; 177 | print ''; 178 | print ''; 179 | print ''; 180 | print ''; 181 | print ''; 182 | print ''; 183 | print ''; 184 | 185 | print_barre_liste($langs->trans($transkey), $page, $_SERVER["PHP_SELF"]); 186 | 187 | print '
'; 188 | print ' '; 189 | print $langs->trans($transkey.'Help'); 190 | print '
'; 191 | 192 | $moreforfilter=''; 193 | $moreforfilter.='
'; 194 | if (! empty($conf->categorie->enabled)) 195 | { 196 | $moreforfilter.=''; 197 | $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, '', 'parent', 64, 0, 1); 198 | $moreforfilter.=''; 199 | } 200 | 201 | $moreforfilter.=''; 202 | $moreforfilter.=''; 203 | 204 | $moreforfilter.=''; 205 | $moreforfilter.=''; 206 | 207 | $moreforfilter.=''; 208 | $moreforfilter.=''; 209 | $moreforfilter.=''; 210 | 211 | $moreforfilter.=''; 212 | $moreforfilter.=''; 213 | $moreforfilter.=''; 214 | $moreforfilter.=''; 215 | 216 | $moreforfilter.='
'.$langs->trans('Categories'). ' : '.$form->multiselectarray('search_categ', $cate_arbo, $search_categ, '', 0, '', 0, '50%').'
'.$langs->trans('Customer') . ' : '.$form->select_company($fk_soc, 'fk_soc', '', 1).'
'.$langs->trans('Product') . ' :
'.$langs->trans('DateInvoice'). ' '.$langs->trans('From'). ' : ' .$form->select_date($date_start, 'date_start', 0,0,0,'',1,0,1) .''.$langs->trans('to'). ' : ' .$form->select_date($date_end, 'date_end', 0,0,0,'',1,0,1).'
' . $langs->trans('IncludeAllProducts') . '' . '' . '
'; 217 | 218 | $parameters=array(); 219 | $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook 220 | if (empty($reshook)) $moreforfilter.=$hookmanager->resPrint; 221 | else $moreforfilter=$hookmanager->resPrint; 222 | 223 | if ($moreforfilter) 224 | { 225 | print '
'; 226 | print $moreforfilter; 227 | print '
'; 228 | } 229 | 230 | print '
'; 231 | print ''."\n"; 232 | 233 | print ''; 234 | 235 | $colspan = 4; 236 | 237 | foreach ($TMonth as $year => $month) 238 | { 239 | $colspan+=count($month); 240 | } 241 | 242 | print ''; 243 | print ''; 247 | print $dummyColTd; 248 | print ''; 249 | 250 | print ''; 251 | print ''; 252 | // print ''; 253 | print ''; 254 | print ''; 255 | foreach ($TMonth as $year => $month) { 256 | foreach ($month as $m) 257 | { 258 | print ''; 259 | } 260 | print ''; 261 | } 262 | print ''; 263 | print $dummyColTh; 264 | print ''; 265 | 266 | $lastcat = ''; 267 | $GlobalTabTotal = array(); 268 | 269 | while ($obj = $db->fetch_object($resql)) 270 | { 271 | 272 | if ($lastcat !== $obj->cat_id) 273 | { 274 | if (!empty($tabtotal)) 275 | { 276 | //var_dump($tabtotal); 277 | print ""; 278 | // print ""; 279 | print ""; 280 | print ""; 281 | print ""; 282 | foreach ($tabtotal as $tab) 283 | { 284 | if ($mode == "CA") print ""; 285 | else print ""; 286 | } 287 | print ""; 288 | 289 | foreach ($tabtotal as $k => $v) $GlobalTabTotal[$k] += $v; 290 | } 291 | 292 | $lastcat = $obj->cat_id; 293 | $catprinted = false; 294 | $tabtotal = array(); 295 | } 296 | 297 | print ''; 298 | 299 | if ($catprinted) print ''; 300 | else 301 | { 302 | if (!empty($obj->cat_id)) 303 | { 304 | $cat = new Categorie($db); 305 | $cat->fetch($obj->cat_id); 306 | 307 | // print ""; 308 | print ""; 309 | } 310 | else 311 | { 312 | print ""; 313 | } 314 | 315 | 316 | $catprinted = true; 317 | } 318 | 319 | $prod = new Product($db); 320 | $prod->fetch($obj->p_id); 321 | 322 | print ""; 323 | print ""; 324 | 325 | $totalligne = 0; 326 | foreach($TMonth as $year => $month) { 327 | foreach ($month as $m) { 328 | $field = str_replace("-", "_", $m); 329 | $tabtotal[$field] += price2num(($mode == "CA") ? price($obj->{$field}) : $obj->{$field}); 330 | print ''; 331 | //var_dump($field, price($obj->{$field}), $obj->{$field}); 332 | } 333 | $field = "total_" . $year; 334 | if (empty($tabtotal[$field])) $tabtotal[$field] = price2num(($mode == "CA") ? price($obj->{$field}) : $obj->{$field}); 335 | else $tabtotal[$field] += price2num(($mode == "CA") ? price($obj->{$field}) : $obj->{$field}); 336 | 337 | if (empty($totalligne)) $totalligne = price2num(($mode == "CA") ? price($obj->{$field}) : $obj->{$field}); 338 | else $totalligne += price2num(($mode == "CA") ? price($obj->{$field}) : $obj->{$field}); 339 | 340 | print ''; 341 | //var_dump($field, $tabtotal[$field]); 342 | 343 | } 344 | $tabtotal['ligne'] += price2num(($mode == "CA") ? price($totalligne) : $totalligne); 345 | 346 | print ''; 347 | print $dummyColTd; 348 | print ''; 349 | 350 | } 351 | 352 | if (!empty($tabtotal)) 353 | { 354 | print ""; 355 | // print ""; 356 | print ""; 357 | print ""; 358 | print ""; 359 | foreach ($tabtotal as $tab) 360 | { 361 | print ""; 362 | } 363 | print $dummyColTd; 364 | print ""; 365 | 366 | foreach ($tabtotal as $k => $v) $GlobalTabTotal[$k] += $v; 367 | } 368 | 369 | print ""; 370 | print ""; 371 | print ""; 372 | print ""; 373 | foreach ($GlobalTabTotal as $tab) 374 | { 375 | print ""; 376 | } 377 | print $dummyColTd; 378 | print ""; 379 | 380 | print '
'; 244 | $searchpicto=$form->showFilterButtons(); 245 | print $searchpicto; 246 | print '
'.$langs->trans('Categories').''.$langs->trans('Ref').''.$langs->trans('Product').''.$langs->trans('Ref').''.$m.'Total '.$year.'Total global
Total ".(!empty($cat->label) ? $cat->label : 'Sans catégorie')."".price($tab)." €".$tab."
".$cat->description."".$cat->label."Sans catégorie".$prod->label."".$prod->ref."' . (($mode == "CA") ? price($obj->{$field}) . " €" : $obj->{$field}) . '' . (($mode == "CA") ? price($obj->{$field}) . " €" : $obj->{$field}) . ''.(($mode == "CA") ? price($obj->total_global) ." €" : $obj->total_global).'
Total ".(!empty($cat->label) ? $cat->label : 'Sans catégorie')."".(($mode == "CA") ? price($tab) . " €": $tab)."
Total Général".(($mode == "CA") ? price($tab) . " €" : $tab)."
'; 381 | print '
'; 382 | print '
'; 383 | 384 | ?> 385 | 390 | categorie->enabled)) 11 | require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; 12 | 13 | if (! empty($conf->stock->enabled)) $langs->load("stocks"); 14 | if (! empty($conf->facture->enabled)) $langs->load("bills"); 15 | 16 | $langs->load("products"); 17 | $langs->load("suppliers"); 18 | $langs->load("companies"); 19 | 20 | // extra column because CSV export ignores the last column of the list -> it will ignore this dummy column instead of a real data column. 21 | $dummyColTd = ''; 22 | $dummyColTh = ''; 23 | 24 | $mode = GETPOST('mode'); 25 | $fk_soc = GETPOST('fk_soc'); 26 | $search_categ = GETPOST('search_categ', 'array'); 27 | $date_start=dol_mktime(0,0,0,GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear')); 28 | $date_end=dol_mktime(0,0,0,GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear')); 29 | $includeAllProducts = boolval(GETPOST('includeAllProducts', 'alpha')); 30 | $product_ref = GETPOST('product_ref', 'nohtml'); 31 | $product_label = GETPOST('product_label', 'nohtml'); 32 | 33 | // Purge search criteria 34 | if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers 35 | { 36 | $fk_soc=""; 37 | $search_categ=0; 38 | $date_start = strtotime(date("01-01-Y")); 39 | $date_end = strtotime(date("31-12-Y")); 40 | } 41 | 42 | if (empty($date_start)) $date_start = strtotime(date("01-01-Y")); 43 | if (empty($date_end)) $date_end = strtotime(date("31-12-Y")); 44 | 45 | $TYear = array(); 46 | $year = (int) date('Y', $date_start); 47 | $yearend = (int) date('Y', $date_end); 48 | if ($date_start < $date_end) 49 | { 50 | while ($year <= $yearend){ 51 | $TYear[] = $year; 52 | $year++; 53 | } 54 | } 55 | else 56 | { 57 | while ($year >= $yearend){ 58 | $TYear[] = $year; 59 | $year--; 60 | } 61 | 62 | sort($TYear); 63 | } 64 | 65 | $TMonth = array(); 66 | $month = (int) date('m', $date_start); 67 | $numyear = count($TYear); 68 | $monthend = (int) date('m', $date_end); 69 | 70 | foreach ($TYear as $k => $year) 71 | { 72 | $end = 12; 73 | if ($k == 0) $start = $month; 74 | else $start = 1; 75 | 76 | if ($k == $numyear -1) $end = $monthend; 77 | 78 | for ($i = $start; $i<=$end; $i++) 79 | { 80 | $TMonth[$year][$i] = $langs->trans('month'. date('M', strtotime(date('Y-'.$i.'-01'))) ).'-'.$year; 81 | } 82 | if ($i == 12) $start = 1; 83 | 84 | } 85 | 86 | $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; 87 | $sortfield = GETPOST("sortfield",'alpha'); 88 | $sortorder = GETPOST("sortorder",'alpha'); 89 | $page = (GETPOST("page",'int')?GETPOST("page", 'int'):0); 90 | if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 91 | $offset = $limit * $page; 92 | $pageprev = $page - 1; 93 | $pagenext = $page + 1; 94 | if (! $sortfield) $sortfield="p.ref"; 95 | if (! $sortorder) $sortorder="ASC"; 96 | 97 | $form = new Form($db); 98 | $htmlother=new FormOther($db); 99 | 100 | $hookmanager->initHooks(array('mandarinArticleslist', 'mandarinevoachatarticle')); 101 | $extrafields = new ExtraFields($db); 102 | 103 | $transkey = 'linkMenuReportAchatsArticles'; 104 | if ($mode == "CA") $transkey = 'linkMenuReportAchatsCAArticles'; 105 | 106 | llxHeader('', $langs->trans($transkey), ''); 107 | 108 | //dol_fiche_head(); 109 | 110 | $sql = "SELECT cat.rowid as cat_id, p.rowid as p_id"; 111 | 112 | if ($mode == "CA") $numfield = 'd.total_ht'; 113 | else $numfield = "IF(f.type = ".FactureFournisseur::TYPE_CREDIT_NOTE." , -(d.qty), d.qty)"; 114 | 115 | foreach ($TMonth as $year => $month) { 116 | $start = ''; 117 | foreach ($month as $k => $m) 118 | { 119 | if (empty($start)) $firststart = strtotime(" 01-$k-$year"); 120 | $start = strtotime(" 01-$k-$year"); 121 | $end = strtotime("+1 month -1 day", $start); 122 | 123 | $sql.= ", SUM(IF(f.datef >= '".date("Y-m-d 00:00:00",$start)."' AND f.datef <= '".date("Y-m-d 23:59:59", $end)."', ".$numfield.", 0)) as ".str_replace("-", "_", $m); 124 | } 125 | 126 | $sql.= ", SUM(IF(f.datef >= '".date("Y-m-d 00:00:00",$firststart)."' AND f.datef <= '".date("Y-m-d 23:59:59", $end)."', ".$numfield.", 0)) as total_".$year; 127 | 128 | } 129 | $sql.= ", SUM(IF(f.datef >= '".date("Y-m-d 00:00:00",$date_start)."' AND f.datef <= '".date("Y-m-d 23:59:59", $date_end)."', ".$numfield.", 0)) as total_global"; 130 | $sql.= " FROM ".MAIN_DB_PREFIX."product as p"; 131 | $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.fk_product=p.rowid"; 132 | $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as cat ON cat.rowid=cp.fk_categorie"; 133 | $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn_det AS d ON d.fk_product = p.rowid"; 134 | $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn AS f ON f.rowid = d.fk_facture_fourn"; 135 | 136 | // Add fields from hooks 137 | $parameters=array(); 138 | $reshook=$hookmanager->executeHooks('printFieldListJoin',$parameters); // Note that $action and $object may have been modified by hook 139 | $sql.=$hookmanager->resPrint; 140 | 141 | $sql.= " WHERE "; 142 | $sql.= ($includeAllProducts ? 'f.rowid IS NULL OR (' : ''); 143 | $sql.= " f.fk_statut > 0"; 144 | $sql.= (!empty($product_ref) ? natural_search("p.ref", $db->escape($product_ref), 0): ""); 145 | $sql.= (!empty($product_label) ? natural_search("p.label", $db->escape($product_label), 0): ""); 146 | $sql.= " AND f.datef >= '".date('Y-m-d 00:00:00', $date_start)."'"; 147 | $sql.= " AND f.datef <= '".date('Y-m-d 23:59:59',$date_end)."'"; 148 | $sql.= ($includeAllProducts ? ')' : ''); 149 | 150 | 151 | // filters 152 | if (!empty($search_categ)) 153 | { 154 | $sql.= " AND cat.rowid IN (".implode(',', $search_categ).")"; 155 | } 156 | 157 | if (!empty($fk_soc) && $fk_soc > 0) 158 | { 159 | $sql.= " AND f.fk_soc = " . $fk_soc; 160 | } 161 | 162 | // Add where from hooks 163 | $parameters=array('sql' => $sql); 164 | $reshook=$hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook 165 | $sql.=$hookmanager->resPrint; 166 | 167 | $sql.= " GROUP BY cat.rowid, p.rowid"; 168 | $sql.= " ORDER BY cat.rowid ASC, p.ref ASC"; 169 | 170 | //print $sql; 171 | $resql = $db->query($sql); 172 | 173 | print '
'; 174 | if ($optioncss != '') print ''; 175 | print ''; 176 | print ''; 177 | print ''; 178 | print ''; 179 | print ''; 180 | print ''; 181 | print ''; 182 | 183 | print_barre_liste($langs->trans($transkey), $page, $_SERVER["PHP_SELF"]); 184 | 185 | print '
'; 186 | print ' '; 187 | print $langs->trans($transkey.'Help'); 188 | print '
'; 189 | 190 | $moreforfilter=''; 191 | $moreforfilter.='
'; 192 | if (! empty($conf->categorie->enabled)) 193 | { 194 | $moreforfilter.=''; 195 | $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, '', 'parent', 64, 0, 1); 196 | $moreforfilter.=''; 197 | } 198 | 199 | $moreforfilter.=''; 200 | $moreforfilter.=''; 201 | 202 | $moreforfilter.=''; 203 | $moreforfilter.=''; 204 | 205 | 206 | $moreforfilter.=''; 207 | $moreforfilter.=''; 208 | $moreforfilter.=''; 209 | 210 | $moreforfilter.=''; 211 | $moreforfilter.=''; 212 | $moreforfilter.=''; 213 | $moreforfilter.=''; 214 | 215 | $moreforfilter.='
'.$langs->trans('Categories'). ' : '.$form->multiselectarray('search_categ', $cate_arbo, $search_categ, '', 0, '', 0, '50%').'
'.$langs->trans('Supplier') . ' : '.$form->select_company($fk_soc, 'fk_soc', 's.fournisseur = 1', 1).'
'.$langs->trans('Product') . ' :
'.$langs->trans('DateInvoice'). ' '.$langs->trans('From'). ' : ' .$form->select_date($date_start, 'date_start', 0,0,0,'',1,0,1) .''.$langs->trans('to'). ' : ' .$form->select_date($date_end, 'date_end', 0,0,0,'',1,0,1).'
' . $langs->trans('IncludeAllProducts') . '' . '' . '
'; 216 | 217 | $parameters=array(); 218 | $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook 219 | if (empty($reshook)) $moreforfilter.=$hookmanager->resPrint; 220 | else $moreforfilter=$hookmanager->resPrint; 221 | 222 | if ($moreforfilter) 223 | { 224 | print '
'; 225 | print $moreforfilter; 226 | print '
'; 227 | } 228 | 229 | print '
'; 230 | print ''."\n"; 231 | 232 | print ''; 233 | 234 | $colspan = 4; 235 | 236 | foreach ($TMonth as $year => $month) 237 | { 238 | $colspan+=count($month); 239 | } 240 | 241 | print ''; 242 | print ''; 246 | print $dummyColTd; 247 | print ''; 248 | 249 | print ''; 250 | print ''; 251 | // print ''; 252 | print ''; 253 | print ''; 254 | foreach ($TMonth as $year => $month) { 255 | foreach ($month as $m) 256 | { 257 | print ''; 258 | } 259 | print ''; 260 | } 261 | print ''; 262 | print $dummyColTh; 263 | print ''; 264 | 265 | $lastcat = ''; 266 | $GlobalTabTotal = array(); 267 | 268 | while ($obj = $db->fetch_object($resql)) 269 | { 270 | if ($lastcat !== $obj->cat_id) 271 | { 272 | if (!empty($tabtotal)) 273 | { 274 | //var_dump($tabtotal); 275 | print ""; 276 | // print ""; 277 | print ""; 278 | print ""; 279 | print ""; 280 | foreach ($tabtotal as $tab) 281 | { 282 | if ($mode == "CA") print ""; 283 | else print ""; 284 | } 285 | print $dummyColTd; 286 | print ""; 287 | 288 | foreach ($tabtotal as $k => $v) $GlobalTabTotal[$k] += $v; 289 | } 290 | 291 | $lastcat = $obj->cat_id; 292 | $catprinted = false; 293 | $tabtotal = array(); 294 | } 295 | 296 | print ''; 297 | 298 | if ($catprinted) print ''; 299 | else 300 | { 301 | if (!empty($obj->cat_id)) 302 | { 303 | $cat = new Categorie($db); 304 | $cat->fetch($obj->cat_id); 305 | 306 | // print ""; 307 | print ""; 308 | } 309 | else 310 | { 311 | print ""; 312 | } 313 | 314 | 315 | $catprinted = true; 316 | } 317 | 318 | $prod = new Product($db); 319 | $prod->fetch($obj->p_id); 320 | 321 | print ""; 322 | print ""; 323 | 324 | $totalligne = 0; 325 | foreach($TMonth as $year => $month) 326 | { 327 | foreach ($month as $m) 328 | { 329 | $field = str_replace("-", "_", $m); 330 | $tabtotal[$field]+= price2num(($mode == "CA") ? price($obj->{$field}) : $obj->{$field}, 'MT'); 331 | print ''; 332 | //var_dump($field, price($obj->{$field}), $obj->{$field}); 333 | } 334 | $field = "total_".$year; 335 | 336 | if (empty($tabtotal[$field])) $tabtotal[$field] = price2num(($mode == "CA") ? price($obj->{$field}) : $obj->{$field}, 'MT'); 337 | else $tabtotal[$field] += price2num(($mode == "CA") ? price($obj->{$field}) : $obj->{$field}, 'MT'); 338 | 339 | if (empty($totalligne)) $totalligne = price2num(($mode == "CA") ? price($obj->{$field}) : $obj->{$field}, 'MT'); 340 | else $totalligne += price2num(($mode == "CA") ? price($obj->{$field}) : $obj->{$field}, 'MT'); 341 | 342 | print ''; 343 | //var_dump($field, $tabtotal[$field]); 344 | 345 | } 346 | $tabtotal['ligne'] += price2num(($mode == "CA") ? price($totalligne) : $totalligne, 'MT'); 347 | 348 | print ''; 349 | 350 | print $dummyColTd; 351 | print ''; 352 | 353 | } 354 | 355 | if (!empty($tabtotal)) 356 | { 357 | print ""; 358 | // print ""; 359 | print ""; 360 | print ""; 361 | print ""; 362 | foreach ($tabtotal as $tab) 363 | { 364 | print ""; 365 | } 366 | print $dummyColTd; 367 | print ""; 368 | 369 | foreach ($tabtotal as $k => $v) $GlobalTabTotal[$k] += $v; 370 | } 371 | 372 | print ""; 373 | print ""; 374 | print ""; 375 | print ""; 376 | foreach ($GlobalTabTotal as $tab) 377 | { 378 | print ""; 379 | } 380 | print $dummyColTd; 381 | print ""; 382 | 383 | print '
'; 243 | $searchpicto=$form->showFilterButtons(); 244 | print $searchpicto; 245 | print '
'.$langs->trans('Categories').''.$langs->trans('Ref').''.$langs->trans('Product').''.$langs->trans('Ref').''.$m.'Total '.$year.'Total global
Total ".(!empty($cat->label) ? $cat->label : 'Sans catégorie')."".price($tab)."".$tab."
".$cat->description."".$cat->label."Sans catégorie".$prod->label."".$prod->ref."'.(($mode == "CA") ? price($obj->{$field}) : $obj->{$field}).''.(($mode == "CA") ? price($obj->{$field}) : $obj->{$field}).''.(($mode == "CA") ? price($obj->total_global) ." €" : $obj->total_global).'
Total ".(!empty($cat->label) ? $cat->label : 'Sans catégorie')."".(($mode == "CA") ? price($tab) : $tab)."
Total Général".(($mode == "CA") ? price($tab) . " €" : $tab)."
'; 384 | print '
'; 385 | print '
'; 386 | 387 | ?> 388 | 393 | rights->mandarin->graph->propal_facture) accessforbidden(); 8 | $langs->load('mandarin@mandarin'); 9 | 10 | $PDOdb = new TPDOdb; 11 | $TDataPropal = array(); 12 | 13 | $year_n = GETPOST('year_n', 'int'); 14 | if (empty($year_n)) $year_n = date('Y'); 15 | 16 | // Info sur année N-2, N-1 et N par Commercial (user) 17 | for ($current_year=$year_n-2; $current_year<=$year_n; $current_year++) 18 | { 19 | $sql = 'SELECT u.firstname, u.lastname, p.rowid AS fk_propal, p.fk_statut, p.fk_soc, s.nom AS name 20 | FROM '.MAIN_DB_PREFIX.'user u 21 | INNER JOIN '.MAIN_DB_PREFIX.'propal p ON (u.rowid = p.fk_user_author) 22 | INNER JOIN '.MAIN_DB_PREFIX.'societe s ON (p.fk_soc = s.rowid) 23 | WHERE YEAR(p.date_cloture) = '.$current_year; 24 | 25 | $resql = $db->query($sql); 26 | if ($resql) 27 | { 28 | while ($line = $db->fetch_object($resql)) 29 | { 30 | $index = $line->firstname.' '.$line->lastname; 31 | $TDataPropal[$index]['nbPropal'][$current_year]++; 32 | 33 | if ($line->fk_statut == Propal::STATUS_NOTSIGNED) 34 | { 35 | $TDataPropal[$index]['nbPropalNotSigned'][$current_year]++; 36 | } 37 | 38 | $TDataPropal[$index]['client'][$current_year][$line->name]++; 39 | } 40 | } 41 | } 42 | 43 | foreach ($TDataPropal as $commercial => &$TStat) 44 | { 45 | // Calcul du %tage de non signé 46 | foreach ($TStat['nbPropal'] as $year => $nb) 47 | { 48 | if (!isset($TStat['nbPropalNotSigned'])) $TStat['nbPropalNotSignedPercent'][$year] = 0; 49 | else 50 | { 51 | $nbNotSign = $TStat['nbPropalNotSigned'][$year]; 52 | if ($nbNotSign > 0) $TStat['nbPropalNotSignedPercent'][$year] = (100 * $nbNotSign) / $nb; 53 | else $TStat['nbPropalNotSignedPercent'][$year] = 0; 54 | } 55 | } 56 | 57 | foreach ($TStat['client'] as $year => $Tab) 58 | { 59 | $topClientName = ''; 60 | $topClientCounter = 0; 61 | foreach ($Tab as $name => $nb_propal_assoc) 62 | { 63 | // Pas de test si cas d'égalité, je garde le 1er 64 | if ($nb_propal_assoc > $topClientCounter) 65 | { 66 | $topClientName = $name; 67 | $topClientCounter = $nb_propal_assoc; 68 | } 69 | } 70 | 71 | $percent = 0; 72 | $percent = (100 * $topClientCounter) / $TStat['nbPropal'][$year]; 73 | 74 | $TStat['topClient'][$year] = array('name' => $topClientName, 'percent_presence' => $percent); 75 | } 76 | } 77 | 78 | 79 | $TDataFacture = array(); 80 | $TTotalFacture = array(); 81 | 82 | // Info sur année N-2, N-1 et N par Commercial (user) 83 | for ($current_year=$year_n-2; $current_year<=$year_n; $current_year++) 84 | { 85 | $sql = 'SELECT u.firstname, u.lastname, f.rowid AS fk_facture, f.fk_soc, f.total AS total_ht, s.nom AS name 86 | FROM '.MAIN_DB_PREFIX.'user u 87 | INNER JOIN '.MAIN_DB_PREFIX.'facture f ON (u.rowid = f.fk_user_author) 88 | INNER JOIN '.MAIN_DB_PREFIX.'societe s ON (f.fk_soc = s.rowid) 89 | WHERE YEAR(f.datef) = '.$current_year.' 90 | AND f.date_valid IS NOT NULL 91 | AND f.fk_statut = '.Facture::STATUS_VALIDATED; 92 | 93 | $resql = $db->query($sql); 94 | if ($resql) 95 | { 96 | while ($line = $db->fetch_object($resql)) 97 | { 98 | $index = $line->firstname.' '.$line->lastname; 99 | $TDataFacture[$index]['CA'][$current_year] += $line->total_ht; 100 | $TDataFacture[$index]['client'][$current_year][$line->name] += $line->total_ht; 101 | $TTotalFacture['total_ca'][$current_year] += $line->total_ht; 102 | } 103 | 104 | foreach ($TDataFacture as $commercial => &$TStat) 105 | { 106 | foreach ($TStat['CA'] as $year => $total) 107 | { 108 | $percent = (100 * $total) / $TTotalFacture['total_ca'][$year]; 109 | $TStat['CAPercent'][$year] = $percent; 110 | //if ($year == 2014) var_dump($total, $TTotalFacture['total_ca'][$current_year], $percent); 111 | } 112 | 113 | foreach ($TStat['client'] as $year => $Tab) 114 | { 115 | $topClientName = ''; 116 | $topClientTotalCA = 0; 117 | foreach ($Tab as $name => $totalCA) 118 | { 119 | // Pas de test si cas d'égalité, je garde le 1er 120 | if ($totalCA > $topClientTotalCA) 121 | { 122 | $topClientName = $name; 123 | $topClientTotalCA = $totalCA; 124 | } 125 | } 126 | 127 | $percent = 0; 128 | $percent = (100 * $topClientTotalCA) / $TStat['CA'][$year]; 129 | 130 | $TStat['topClient'][$year] = array('name' => $topClientName, 'percent_ca' => $percent); 131 | } 132 | } 133 | } 134 | } 135 | 136 | 137 | // Begin of page 138 | llxHeader('', $langs->trans('mandarinTitleGraphHoraireMoyen'), ''); 139 | 140 | print_fiche_titre($langs->trans("mandarinPropalsPerCommercial"),'','title_commercial.png'); 141 | 142 | // Print table info propals 143 | print ''; 144 | print ''; 145 | print ''; 146 | print ''; 147 | print ''; 148 | print ''; 149 | print ''; 150 | print ''; // N-2 151 | print ''; 152 | print ''; // N-1 153 | print ''; 154 | print ''; // N 155 | print ''; 156 | print ''; 157 | print ''; 158 | print ''; 159 | print ''; 160 | print ''; 161 | 162 | print ''; 163 | print ''; 164 | print ''; 165 | 166 | print ''; 167 | print ''; 168 | print ''; 169 | 170 | print ''; 171 | print ''; 172 | print ''; 173 | print ''; 174 | 175 | if (count($TDataPropal) > 0) 176 | { 177 | $var = true; 178 | $TTotal = array('nbPropal' => array(), 'nbClient' => array()); 179 | foreach ($TDataPropal as $commercial => &$TStat) 180 | { 181 | //var_dump($TStat);exit; 182 | print ''; 183 | print ''; 184 | 185 | // Nb Propals 186 | for ($current_year=$year_n-2; $current_year<=$year_n; $current_year++) 187 | { 188 | $TTotal['nbPropal'][$current_year] += (double) $TStat['nbPropal'][$current_year]; 189 | print ''; // Nd propals par année sur 3 colonnes 190 | } 191 | 192 | // Nb Propals not signed 193 | for ($current_year=$year_n-2; $current_year<=$year_n; $current_year++) 194 | { 195 | print ''; // % propal no signé par année sur 3 colonnes 196 | } 197 | 198 | // Nb Clients 199 | for ($current_year=$year_n-2; $current_year<=$year_n; $current_year++) 200 | { 201 | $TTotal['nbClient'][$current_year] += count($TStat['client'][$current_year]); 202 | print ''; // Nd clients par année sur 3 colonnes 203 | } 204 | 205 | print ''; // Top client N-2 206 | print ''; 207 | print ''; // Top client N-1 208 | print ''; 209 | print ''; // Top client N 210 | print ''; 211 | 212 | print ''; 213 | 214 | $var = !$var; 215 | } 216 | 217 | print ''; 218 | print ''; 219 | foreach ($TTotal['nbPropal'] as $year => $nb) 220 | { 221 | print ''; 222 | } 223 | print ''; 224 | foreach ($TTotal['nbClient'] as $year => $nb) 225 | { 226 | print ''; 227 | } 228 | print ''; 229 | print ''; 230 | } 231 | else 232 | { 233 | print ''; 234 | } 235 | print '
'.$langs->transnoentitiesnoconv('mandarinTitlePropalFactureCommercial').''.$langs->transnoentitiesnoconv('mandarinTitlePropalFactureNbPropal').''.$langs->transnoentitiesnoconv('mandarinTitlePropalFacturePropalPercentNotSigned').''.$langs->transnoentitiesnoconv('mandarinTitlePropalFacturePropalNbClient').''.$langs->transnoentitiesnoconv('mandarinTitlePropalFactureTopClient').''.$langs->transnoentitiesnoconv('mandarinTitlePropalFactureTopClientPercent').''.$langs->transnoentitiesnoconv('mandarinTitlePropalFactureTopClient').''.$langs->transnoentitiesnoconv('mandarinTitlePropalFactureTopClientPercent').''.$langs->transnoentitiesnoconv('mandarinTitlePropalFactureTopClient').''.$langs->transnoentitiesnoconv('mandarinTitlePropalFactureTopClientPercent').'
'.($year_n-2).''.($year_n-1).''.($year_n).''.($year_n-2).''.($year_n-1).''.($year_n).''.($year_n-2).''.($year_n-1).''.($year_n).''.($year_n-2).''.($year_n-1).''.($year_n).'
'.$commercial.''.(isset($TStat['nbPropal'][$current_year]) ? $TStat['nbPropal'][$current_year] : '-').''.(isset($TStat['nbPropalNotSignedPercent'][$current_year]) ? vatrate(round($TStat['nbPropalNotSignedPercent'][$current_year], 2), 1) : '-').''.(isset($TStat['client'][$current_year]) ? count($TStat['client'][$current_year]) : '-').''.(isset($TStat['topClient'][$year_n-2]['name']) ? $TStat['topClient'][$year_n-2]['name'] : '-').''.(isset($TStat['topClient'][$year_n-2]['percent_presence']) ? vatrate(round($TStat['topClient'][$year_n-2]['percent_presence'], 2), 1) : '-').''.(isset($TStat['topClient'][$year_n-1]['name']) ? $TStat['topClient'][$year_n-1]['name'] : '-').''.(isset($TStat['topClient'][$year_n-1]['percent_presence']) ? vatrate(round($TStat['topClient'][$year_n-1]['percent_presence'], 2), 1) : '-').''.(isset($TStat['topClient'][$year_n]['name']) ? $TStat['topClient'][$year_n]['name'] : '-').''.(isset($TStat['topClient'][$year_n]['percent_presence']) ? vatrate(round($TStat['topClient'][$year_n]['percent_presence'], 2), 1) : '-').'
'.$langs->trans('Total').''.$nb.''.$nb.'
'.$langs->transnoentitiesnoconv('noData').'
'; 236 | // Fin table info propal 237 | 238 | print '

'; 239 | print_fiche_titre($langs->trans("mandarinInvoicesPerCommercial"),'','title_accountancy.png'); 240 | 241 | // Print table info facture 242 | print ''; 243 | print ''; 244 | print ''; 245 | print ''; 246 | print ''; 247 | print ''; 248 | print ''; 249 | print ''; // N-2 250 | print ''; 251 | print ''; // N-1 252 | print ''; 253 | print ''; // N 254 | print ''; 255 | print ''; 256 | print ''; 257 | print ''; 258 | print ''; 259 | print ''; 260 | 261 | print ''; 262 | print ''; 263 | print ''; 264 | 265 | print ''; 266 | print ''; 267 | print ''; 268 | 269 | print ''; 270 | print ''; 271 | print ''; 272 | print ''; 273 | 274 | if (count($TDataFacture) > 0) 275 | { 276 | $var = true; 277 | foreach ($TDataFacture as $commercial => &$TStat) 278 | { 279 | //var_dump($TStat);exit; 280 | print ''; 281 | print ''; 282 | 283 | // Nb Propals 284 | for ($current_year=$year_n-2; $current_year<=$year_n; $current_year++) 285 | { 286 | print ''; // Nd propals par année sur 3 colonnes 287 | } 288 | 289 | // Nb Propals not signed 290 | for ($current_year=$year_n-2; $current_year<=$year_n; $current_year++) 291 | { 292 | print ''; // % propal no signé par année sur 3 colonnes 293 | } 294 | 295 | // Nb Clients 296 | for ($current_year=$year_n-2; $current_year<=$year_n; $current_year++) 297 | { 298 | print ''; // Nd clients par année sur 3 colonnes 299 | } 300 | 301 | print ''; // Top client N-2 302 | print ''; 303 | print ''; // Top client N-1 304 | print ''; 305 | print ''; // Top client N 306 | print ''; 307 | 308 | print ''; 309 | 310 | $var = !$var; 311 | } 312 | 313 | print ''; 314 | print ''; 315 | foreach ($TTotalFacture['total_ca'] as $year => $nb) 316 | { 317 | print ''; 318 | } 319 | print ''; 320 | print ''; 321 | } 322 | else 323 | { 324 | print ''; 325 | } 326 | print '
'.$langs->transnoentitiesnoconv('mandarinTitlePropalFactureCommercial').''.$langs->transnoentitiesnoconv('mandarinTitlePropalFactureCA').''.$langs->transnoentitiesnoconv('mandarinTitlePropalFacturePropalPercentCA').''.$langs->transnoentitiesnoconv('mandarinTitlePropalFacturePropalNbClient').''.$langs->transnoentitiesnoconv('mandarinTitlePropalFactureTopClient').''.$langs->transnoentitiesnoconv('mandarinTitlePropalFactureTopClientPercent').''.$langs->transnoentitiesnoconv('mandarinTitlePropalFactureTopClient').''.$langs->transnoentitiesnoconv('mandarinTitlePropalFactureTopClientPercent').''.$langs->transnoentitiesnoconv('mandarinTitlePropalFactureTopClient').''.$langs->transnoentitiesnoconv('mandarinTitlePropalFactureTopClientPercent').'
'.($year_n-2).''.($year_n-1).''.($year_n).''.($year_n-2).''.($year_n-1).''.($year_n).''.($year_n-2).''.($year_n-1).''.($year_n).''.($year_n-2).''.($year_n-1).''.($year_n).'
'.$commercial.''.(isset($TStat['CA'][$current_year]) ? $TStat['CA'][$current_year] : '-').''.(isset($TStat['CAPercent'][$current_year]) ? vatrate(round($TStat['CAPercent'][$current_year], 2), 1) : '-').''.(isset($TStat['client'][$current_year]) ? count($TStat['client'][$current_year]) : '-').''.(isset($TStat['topClient'][$year_n-2]['name']) ? $TStat['topClient'][$year_n-2]['name'] : '-').''.(isset($TStat['topClient'][$year_n-2]['percent_ca']) ? vatrate(round($TStat['topClient'][$year_n-2]['percent_ca'], 2), 1) : '-').''.(isset($TStat['topClient'][$year_n-1]['name']) ? $TStat['topClient'][$year_n-1]['name'] : '-').''.(isset($TStat['topClient'][$year_n-1]['percent_ca']) ? vatrate(round($TStat['topClient'][$year_n-1]['percent_ca'], 2), 1) : '-').''.(isset($TStat['topClient'][$year_n]['name']) ? $TStat['topClient'][$year_n]['name'] : '-').''.(isset($TStat['topClient'][$year_n]['percent_ca']) ? vatrate(round($TStat['topClient'][$year_n]['percent_ca'], 2), 1) : '-').'
'.$langs->trans('Total').''.$nb.'
'.$langs->transnoentitiesnoconv('noData').'
'; 327 | // Fin table info facture 328 | 329 | 330 | 331 | // Graph %CA par client (7 premiers et le reste dans 'autres') 332 | $year_n_1 = $year_n-1; 333 | 334 | $TPalmaresCAParClient = array(); 335 | $TValue = array(); 336 | 337 | $sql = 'SELECT s.nom AS name, YEAR(f.datef) AS `year`, SUM(f.total) AS total_ht 338 | FROM '.MAIN_DB_PREFIX.'facture f 339 | INNER JOIN '.MAIN_DB_PREFIX.'societe s ON (s.rowid = f.fk_soc) 340 | WHERE YEAR(f.datef) = '.$year_n_1.' 341 | GROUP BY name'; 342 | 343 | $resql = $db->query($sql); 344 | if ($resql) 345 | { 346 | $total_ca; 347 | while ($line = $db->fetch_object($resql)) 348 | { 349 | $TPalmaresCAParClient[$line->name] += $line->total_ht; 350 | $total_ca += $line->total_ht; 351 | } 352 | 353 | arsort($TPalmaresCAParClient); 354 | 355 | 356 | $i=1; 357 | foreach ($TPalmaresCAParClient as $name => $total) 358 | { 359 | if ($i <= 7) $TValue[] = array('name' => $name, 'val' => $total); 360 | else $total_autre += $total; 361 | 362 | $i++; 363 | } 364 | 365 | if (isset($total_autre)) $TValue[] = array('name' => 'autres', 'val' => $total_autre); 366 | } 367 | 368 | //$TValue = array(array('truc'=>'machine', 'val'=>30), array('truc'=>'thomas', 'val'=>70)); 369 | // chartType => PieChart 370 | print '
'; 371 | $listeview = new TListviewTBS('graphPalmaresPercentCA'); 372 | print $listeview->renderArray($PDOdb, $TValue 373 | ,array( 374 | 'type' => 'chart' 375 | ,'chartType' => 'PieChart' 376 | ,'liste'=>array( 377 | 'titre'=>$langs->transnoentitiesnoconv('titleGraphPalmaresPercentCA', $year_n_1) 378 | ) 379 | ) 380 | ); 381 | print '
'; 382 | 383 | 384 | 385 | // Graph %CA par CC 386 | $TPalmaresCAParCC = array(); 387 | $TValue = array(); 388 | 389 | $sql = 'SELECT u.firstname, u.lastname, YEAR(f.datef) AS `year`, SUM(f.total) AS total_ht 390 | FROM '.MAIN_DB_PREFIX.'facture f 391 | INNER JOIN '.MAIN_DB_PREFIX.'user u ON (u.rowid = f.fk_user_author) 392 | WHERE YEAR(f.datef) = '.$year_n_1.' 393 | GROUP BY u.rowid'; 394 | 395 | $resql = $db->query($sql); 396 | if ($resql) 397 | { 398 | $total_ca; 399 | while ($line = $db->fetch_object($resql)) 400 | { 401 | $name = strtoupper($line->lastname[0]).'. '.$line->firstname; 402 | $TPalmaresCAParCC[$name] += $line->total_ht; 403 | $total_ca += $line->total_ht; 404 | } 405 | 406 | arsort($TPalmaresCAParCC); 407 | 408 | foreach ($TPalmaresCAParCC as $name => $total) 409 | { 410 | $TValue[] = array('name' => $name, 'val' => $total); 411 | } 412 | } 413 | 414 | print '
'; 415 | $listeview = new TListviewTBS('graphPercentCAPerCC'); 416 | print $listeview->renderArray($PDOdb, $TValue 417 | ,array( 418 | 'type' => 'chart' 419 | ,'chartType' => 'PieChart' 420 | ,'liste'=>array( 421 | 'titre'=>$langs->transnoentitiesnoconv('titleGraphPercentCAPerCC', $year_n_1) 422 | ) 423 | ) 424 | ); 425 | print '
'; 426 | 427 | // End of page 428 | llxFooter(); --------------------------------------------------------------------------------