/** *Standard method to show a box (usage by boxes not mandatory, a box can still use its own showBox function) * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * * @return void */ function showBox($head, $contents) { global $langs, $user, $conf; require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; $MAXLENGTHBOX = 60; // Mettre 0 pour pas de limite $bcx = array(); $bcx[0] = 'class="box_pair"'; $bcx[1] = 'class="box_impair"'; $var = false; $cachetime = 900; // 900 : 15mn $cachedir = DOL_DATA_ROOT . '/boxes/temp'; $fileid = get_class($this) . 'id-' . $this->box_id . '-e' . $conf->entity . '-u' . $user->id . '-s' . $user->societe_id . '.cache'; $filename = '/box-' . $fileid; $refresh = dol_cache_refresh($cachedir, $filename, $cachetime); $out = ''; if ($refresh) { dol_syslog(get_class($this) . '::showBox'); // Define nbcol and nblines of the box to show $nbcol = 0; if (isset($contents[0])) { $nbcol = count($contents[0]); } $nblines = count($contents); $out .= "\n<!-- Box " . get_class($this) . " start -->\n"; $out .= '<div class="box" id="boxto_' . $this->box_id . '">' . "\n"; if (!empty($head['text']) || !empty($head['sublink']) || !empty($head['subpicto']) || $nblines) { $out .= '<table summary="boxtable' . $this->box_id . '" width="100%" class="noborder boxtable">' . "\n"; } // Show box title if (!empty($head['text']) || !empty($head['sublink']) || !empty($head['subpicto'])) { //$out.= '<div id="boxto_'.$this->box_id.'_title">'."\n"; //$out.= '<table summary="boxtabletitle'.$this->box_id.'" width="100%" class="noborder">'."\n"; $out .= '<tr class="box_titre">'; $out .= '<td'; if ($nbcol > 0) { $out .= ' colspan="' . $nbcol . '"'; } $out .= '>'; if ($conf->use_javascript_ajax) { $out .= '<table summary="" class="nobordernopadding" width="100%"><tr><td>'; } if (!empty($head['text'])) { $s = dol_trunc($head['text'], isset($head['limit']) ? $head['limit'] : $MAXLENGTHBOX); $out .= $s; } $out .= ' '; if (!empty($head['sublink'])) { $out .= '<a href="' . $head['sublink'] . '"' . (empty($head['target']) ? ' target="_blank"' : '') . '>'; } if (!empty($head['subpicto'])) { $out .= img_picto($head['subtext'], $head['subpicto'], 'class="' . (empty($head['subclass']) ? '' : $head['subclass']) . '" id="idsubimg' . $this->boxcode . '"'); } if (!empty($head['sublink'])) { '</a>'; } if (!empty($conf->use_javascript_ajax)) { $out .= '</td><td class="nocellnopadd boxclose nowrap">'; // The image must have the class 'boxhandle' beause it's value used in DOM draggable objects to define the area used to catch the full object $out .= img_picto($langs->trans("MoveBox", $this->box_id), 'grip_title', 'class="boxhandle hideonsmartphone" style="cursor:move;"'); $out .= img_picto($langs->trans("Close2", $this->box_id), 'close_title', 'class="boxclose" rel="x:y" style="cursor:pointer;" id="imgclose' . $this->box_id . '"'); $label = $head['text']; if (!empty($head['graph'])) { $label .= ' (' . $langs->trans("Graph") . ')'; } $out .= '<input type="hidden" id="boxlabelentry' . $this->box_id . '" value="' . dol_escape_htmltag($label) . '">'; $out .= '</td></tr></table>'; } $out .= '</td>'; $out .= "</tr>\n"; //$out.= "</table>\n"; //$out.= "</div>\n"; } // Show box lines if ($nblines) { //$out.= '<table summary="boxtablelines'.$this->box_id.'" width="100%" class="noborder">'."\n"; // Loop on each record for ($i = 0, $n = $nblines; $i < $n; $i++) { if (isset($contents[$i])) { $var = !$var; // TR if (isset($contents[$i][0]['tr'])) { $out .= '<tr valign="top" ' . $contents[$i][0]['tr'] . '>'; } else { $out .= '<tr valign="top" ' . $bcx[$var] . '>'; } // Loop on each TD $nbcolthisline = count($contents[$i]); for ($j = 0; $j < $nbcolthisline; $j++) { // Define tdparam $tdparam = ''; if (isset($contents[$i][$j]['td'])) { $tdparam .= ' ' . $contents[$i][$j]['td']; } $text = isset($contents[$i][$j]['text']) ? $contents[$i][$j]['text'] : ''; $textwithnotags = preg_replace('/<([^>]+)>/i', '', $text); $text2 = isset($contents[$i][$j]['text2']) ? $contents[$i][$j]['text2'] : ''; $text2withnotags = preg_replace('/<([^>]+)>/i', '', $text2); $textnoformat = isset($contents[$i][$j]['textnoformat']) ? $contents[$i][$j]['textnoformat'] : ''; //$out.= "xxx $textwithnotags y"; if (empty($contents[$i][$j]['tooltip'])) { $contents[$i][$j]['tooltip'] = ""; } $tooltip = isset($contents[$i][$j]['tooltip']) ? $contents[$i][$j]['tooltip'] : ''; $out .= '<td' . $tdparam . '>' . "\n"; // Url if (!empty($contents[$i][$j]['url']) && empty($contents[$i][$j]['logo'])) { $out .= '<a href="' . $contents[$i][$j]['url'] . '" title="' . dol_escape_htmltag($langs->trans("Show") . ' ' . $tooltip, 1) . '" class="classfortooltip"'; //$out.= ' alt="'.$textwithnotags.'"'; // Pas de alt sur un "<a href>" $out .= isset($contents[$i][$j]['target']) ? ' target="' . $contents[$i][$j]['target'] . '"' : ''; $out .= '>'; } // Logo if (!empty($contents[$i][$j]['logo'])) { $logo = preg_replace("/^object_/i", "", $contents[$i][$j]['logo']); $out .= '<a href="' . $contents[$i][$j]['url'] . '">'; $out .= img_object($langs->trans("Show") . ' ' . $tooltip, $logo, 'class="classfortooltip"'); } $maxlength = $MAXLENGTHBOX; if (!empty($contents[$i][$j]['maxlength'])) { $maxlength = $contents[$i][$j]['maxlength']; } if ($maxlength) { $textwithnotags = dol_trunc($textwithnotags, $maxlength); } if (preg_match('/^<img/i', $text) || !empty($contents[$i][$j]['asis'])) { $out .= $text; } else { $out .= $textwithnotags; } // show text with html cleaning // End Url if (!empty($contents[$i][$j]['url'])) { $out .= '</a>'; } if (preg_match('/^<img/i', $text2) || !empty($contents[$i][$j]['asis2'])) { $out .= $text2; } else { $out .= $text2withnotags; } // show text with html cleaning if (!empty($textnoformat)) { $out .= "\n" . $textnoformat . "\n"; } $out .= "</td>\n"; } $out .= "</tr>\n"; } } } if (!empty($head['text']) || !empty($head['sublink']) || !empty($head['subpicto']) || $nblines) { $out .= "</table>\n"; } // If invisible box with no contents if (empty($head['text']) && empty($head['sublink']) && empty($head['subpicto']) && !$nblines) { $out .= "<br>\n"; } $out .= "</div>\n"; $out .= "<!-- Box " . get_class($this) . " end -->\n\n"; if (!empty($conf->global->MAIN_ACTIVATE_FILECACHE)) { dol_filecache($cachedir, $filename, $out); } } else { dol_syslog(get_class($this) . '::showBoxCached'); $out = dol_readcachefile($cachedir, $filename); print "<!-- Box " . get_class($this) . " from cache -->"; } print $out; }
/** * Charge les donnees en memoire pour affichage ulterieur * * @param int $max Maximum number of records to load * @return void */ function loadBox($max = 5) { global $conf, $user, $langs, $db; include_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php'; include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; $totalMnt = 0; $totalnb = 0; $line = 0; $cachetime = 3600; $fileid = '-e' . $conf->entity . '-u' . $user->id . '-s' . $user->societe_id . '-r' . ($user->rights->societe->client->voir ? '1' : '0') . '.cache'; $now = dol_now(); $nbofyears = 2; if (!empty($conf->global->MAIN_BOX_ACTIVITY_DURATION)) { $nbofyears = $conf->global->MAIN_BOX_ACTIVITY_DURATION; } $textHead = $langs->trans("Activity") . ' - ' . $langs->trans("LastXMonthRolling", $nbofyears * 12); $this->info_box_head = array('text' => $textHead, 'limit' => dol_strlen($textHead)); // compute the year limit to show $tmpdate = dol_time_plus_duree(dol_now(), -1 * $nbofyears, "y"); $cumuldata = array(); // list the summary of the bills if (!empty($conf->facture->enabled) && $user->rights->facture->lire) { include_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php'; $facturestatic = new Facture($db); $cachedir = DOL_DATA_ROOT . '/facture/temp'; $filename = '/boxactivity-invoice' . $fileid; $refresh = dol_cache_refresh($cachedir, $filename, $cachetime); $data = array(); if ($refresh) { $sql = "SELECT f.fk_statut, SUM(f.total_ttc) as Mnttot, COUNT(*) as nb"; $sql .= " FROM (" . MAIN_DB_PREFIX . "societe as s," . MAIN_DB_PREFIX . "facture as f"; if (!$user->rights->societe->client->voir && !$user->societe_id) { $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; } $sql .= ")"; $sql .= " WHERE f.entity = " . $conf->entity; if (!$user->rights->societe->client->voir && !$user->societe_id) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = "******" AND s.rowid = " . $user->societe_id; } $sql .= " AND f.fk_soc = s.rowid"; $sql .= " AND f.datef >= '" . $db->idate($tmpdate) . "' AND paye=1"; $sql .= " GROUP BY f.fk_statut"; $sql .= " ORDER BY f.fk_statut DESC"; $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); $j = 0; while ($j < $num) { $data[$j] = $db->fetch_object($result); $j++; } if (!empty($conf->global->MAIN_ACTIVATE_FILECACHE)) { dol_filecache($cachedir, $filename, $data); } $db->free($result); } else { dol_print_error($db); } } else { $data = dol_readcachefile($cachedir, $filename); } $cumuldata = array_merge($cumuldata, $data); if (!empty($data)) { $j = 0; while ($line < count($cumuldata)) { $billurl = "viewstatut=2&paye=1&year=" . $data[$j]->annee; $this->info_box_contents[$line][0] = array('td' => 'align="left" width="16"', 'tooltip' => $langs->trans('Bills') . ' ' . $facturestatic->LibStatut(1, $data[$j]->fk_statut, 0), 'url' => DOL_URL_ROOT . "/compta/facture/list.php?" . $billurl . "&mainmenu=accountancy&leftmenu=customers_bills", 'logo' => 'bill'); $this->info_box_contents[$line][1] = array('td' => 'align="left"', 'text' => $langs->trans("Bills") . " " . $facturestatic->LibStatut(1, $data[$j]->fk_statut, 0) . " " . $data[$j]->annee); $this->info_box_contents[$line][2] = array('td' => 'align="right"', 'tooltip' => $langs->trans('Bills') . ' ' . $facturestatic->LibStatut(1, $data[$j]->fk_statut, 0), 'text' => $data[$j]->nb, 'url' => DOL_URL_ROOT . "/compta/facture/list.php?" . $billurl . "&mainmenu=accountancy&leftmenu=customers_bills"); $this->info_box_contents[$line][3] = array('td' => 'align="right"', 'text' => price($data[$j]->Mnttot, 1, $langs, 0, 0, -1, $conf->currency)); // We add only for the current year if ($data[$j]->annee == date("Y")) { $totalnb += $data[$j]->nb; $totalMnt += $data[$j]->Mnttot; } $this->info_box_contents[$line][4] = array('td' => 'align="right" width="18"', 'text' => $facturestatic->LibStatut(1, $data[$j]->fk_statut, 3)); $line++; $j++; } if (count($data) == 0) { $this->info_box_contents[$line][0] = array('td' => 'align="center"', 'text' => $langs->trans("NoRecordedInvoices")); } } $cachedir = DOL_DATA_ROOT . '/facture/temp'; $filename = '/boxactivity-invoice2' . $fileid; $refresh = dol_cache_refresh($cachedir, $filename, $cachetime); if ($refresh) { $sql = "SELECT f.fk_statut, SUM(f.total_ttc) as Mnttot, COUNT(*) as nb"; $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s," . MAIN_DB_PREFIX . "facture as f"; $sql .= " WHERE f.entity = " . $conf->entity; $sql .= " AND f.fk_soc = s.rowid"; $sql .= " AND paye=0"; $sql .= " GROUP BY f.fk_statut"; $sql .= " ORDER BY f.fk_statut DESC"; $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); $j = 0; while ($j < $num) { $data[$j] = $db->fetch_object($result); $j++; } if (!empty($conf->global->MAIN_ACTIVATE_FILECACHE)) { dol_filecache($cachedir, $filename, $data); } $db->free($result); } else { dol_print_error($db); } } else { $data = dol_readcachefile($cachedir, $filename); } $cumuldata = array_merge($cumuldata, $data); if (!empty($data)) { $j = 0; while ($line < count($cumuldata)) { $billurl = "viewstatut=" . $data[$j]->fk_statut . "&paye=0"; $this->info_box_contents[$line][0] = array('td' => 'align="left" width="16"', 'tooltip' => $langs->trans('Bills') . ' ' . $facturestatic->LibStatut(0, $data[$j]->fk_statut, 0), 'url' => DOL_URL_ROOT . "/compta/facture/list.php?" . $billurl . "&mainmenu=accountancy&leftmenu=customers_bills", 'logo' => 'bill'); $this->info_box_contents[$line][1] = array('td' => 'align="left"', 'text' => $langs->trans("Bills") . " " . $facturestatic->LibStatut(0, $data[$j]->fk_statut, 0)); $this->info_box_contents[$line][2] = array('td' => 'align="right"', 'text' => $data[$j]->nb, 'tooltip' => $langs->trans('Bills') . ' ' . $facturestatic->LibStatut(0, $data[$j]->fk_statut, 0), 'url' => DOL_URL_ROOT . "/compta/facture/list.php?" . $billurl . "&mainmenu=accountancy&leftmenu=customers_bills"); $totalnb += $data[$j]->nb; $this->info_box_contents[$line][3] = array('td' => 'align="right"', 'text' => price($data[$j]->Mnttot, 1, $langs, 0, 0, -1, $conf->currency)); $totalMnt += $objp->Mnttot; $this->info_box_contents[$line][4] = array('td' => 'align="right" width="18"', 'text' => $facturestatic->LibStatut(0, $data[$j]->fk_statut, 3)); $line++; $j++; } if ($num == 0) { $this->info_box_contents[$line][0] = array('td' => 'align="center"', 'text' => $langs->trans("NoRecordedInvoices")); } } else { $this->info_box_contents[0][0] = array('td' => 'align="left"', 'maxlength' => 500, 'text' => $db->error() . ' sql=' . $sql); } } // list the summary of the orders if (!empty($conf->commande->enabled) && $user->rights->commande->lire) { include_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php'; $commandestatic = new Commande($db); $cachedir = DOL_DATA_ROOT . '/commande/temp'; $filename = '/boxactivity-order' . $fileid; $refresh = dol_cache_refresh($cachedir, $filename, $cachetime); $data = array(); if ($refresh) { $sql = "SELECT c.fk_statut, sum(c.total_ttc) as Mnttot, count(*) as nb"; $sql .= " FROM (" . MAIN_DB_PREFIX . "societe as s, " . MAIN_DB_PREFIX . "commande as c"; if (!$user->rights->societe->client->voir && !$user->societe_id) { $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; } $sql .= ")"; $sql .= " WHERE c.entity = " . $conf->entity; $sql .= " AND c.fk_soc = s.rowid"; if (!$user->rights->societe->client->voir && !$user->societe_id) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = "******" AND s.rowid = " . $user->societe_id; } $sql .= " AND c.date_commande >= '" . $db->idate($tmpdate) . "'"; $sql .= " AND c.facture=0"; $sql .= " GROUP BY c.fk_statut"; $sql .= " ORDER BY c.fk_statut DESC"; $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); $j = 0; while ($j < $num) { $data[$j] = $db->fetch_object($result); $j++; } if (!empty($conf->global->MAIN_ACTIVATE_FILECACHE)) { dol_filecache($cachedir, $filename, $data); } $db->free($result); } else { dol_print_error($db); } } else { $data = dol_readcachefile($cachedir, $filename); } $cumuldata = array_merge($cumuldata, $data); if (!empty($data)) { $j = 0; while ($line < count($cumuldata)) { $this->info_box_contents[$line][0] = array('td' => 'align="left" width="16"', 'url' => DOL_URL_ROOT . "/commande/list.php?mainmenu=commercial&leftmenu=orders&viewstatut=" . $data[$j]->fk_statut, 'tooltip' => $langs->trans("Orders") . " " . $commandestatic->LibStatut($data[$j]->fk_statut, 0, 0), 'logo' => 'object_order'); $this->info_box_contents[$line][1] = array('td' => 'align="left"', 'text' => $langs->trans("Orders") . " " . $commandestatic->LibStatut($data[$j]->fk_statut, 0, 0)); $this->info_box_contents[$line][2] = array('td' => 'align="right"', 'text' => $data[$j]->nb, 'tooltip' => $langs->trans("Orders") . " " . $commandestatic->LibStatut($data[$j]->fk_statut, 0, 0), 'url' => DOL_URL_ROOT . "/commande/list.php?mainmenu=commercial&leftmenu=orders&viewstatut=" . $data[$j]->fk_statut); $totalnb += $data[$j]->nb; $this->info_box_contents[$line][3] = array('td' => 'align="right"', 'text' => price($data[$j]->Mnttot, 1, $langs, 0, 0, -1, $conf->currency)); $totalMnt += $data[$j]->Mnttot; $this->info_box_contents[$line][4] = array('td' => 'align="right" width="18"', 'text' => $commandestatic->LibStatut($data[$j]->fk_statut, 0, 3)); $line++; $j++; } } } // list the summary of the propals if (!empty($conf->propal->enabled) && $user->rights->propal->lire) { include_once DOL_DOCUMENT_ROOT . '/comm/propal/class/propal.class.php'; $propalstatic = new Propal($db); $cachedir = DOL_DATA_ROOT . '/propale/temp'; $filename = '/boxactivity-propal' . $fileid; $refresh = dol_cache_refresh($cachedir, $filename, $cachetime); $data = array(); if ($refresh) { $sql = "SELECT p.fk_statut, SUM(p.total) as Mnttot, COUNT(*) as nb"; $sql .= " FROM (" . MAIN_DB_PREFIX . "societe as s, " . MAIN_DB_PREFIX . "propal as p"; if (!$user->rights->societe->client->voir && !$user->societe_id) { $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; } $sql .= ")"; $sql .= " WHERE p.entity = " . $conf->entity; $sql .= " AND p.fk_soc = s.rowid"; if (!$user->rights->societe->client->voir && !$user->societe_id) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = "******" AND s.rowid = " . $user->societe_id; } $sql .= " AND p.datep >= '" . $db->idate($tmpdate) . "'"; $sql .= " AND p.date_cloture IS NULL"; // just unclosed $sql .= " GROUP BY p.fk_statut"; $sql .= " ORDER BY p.fk_statut DESC"; $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); $j = 0; while ($j < $num) { $data[$j] = $db->fetch_object($result); $j++; } if (!empty($conf->global->MAIN_ACTIVATE_FILECACHE)) { dol_filecache($cachedir, $filename, $data); } $db->free($result); } else { dol_print_error($db); } } else { $data = dol_readcachefile($cachedir, $filename); } $cumuldata = array_merge($cumuldata, $data); if (!empty($data)) { $j = 0; while ($line < count($cumuldata)) { $this->info_box_contents[$line][0] = array('td' => 'align="left" width="16"', 'url' => DOL_URL_ROOT . "/comm/propal/list.php?mainmenu=commercial&leftmenu=propals&viewstatut=" . $data[$j]->fk_statut, 'tooltip' => $langs->trans("Proposals") . " " . $propalstatic->LibStatut($data[$j]->fk_statut, 0), 'logo' => 'object_propal'); $this->info_box_contents[$line][1] = array('td' => 'align="left"', 'text' => $langs->trans("Proposals") . " " . $propalstatic->LibStatut($data[$j]->fk_statut, 0)); $this->info_box_contents[$line][2] = array('td' => 'align="right"', 'text' => $data[$j]->nb, 'tooltip' => $langs->trans("Proposals") . " " . $propalstatic->LibStatut($data[$j]->fk_statut, 0), 'url' => DOL_URL_ROOT . "/comm/propal/list.php?mainmenu=commercial&leftmenu=propals&viewstatut=" . $data[$j]->fk_statut); $totalnb += $data[$j]->nb; $this->info_box_contents[$line][3] = array('td' => 'align="right"', 'text' => price($data[$j]->Mnttot, 1, $langs, 0, 0, -1, $conf->currency)); $totalMnt += $data[$j]->Mnttot; $this->info_box_contents[$line][4] = array('td' => 'align="right" width="18"', 'text' => $propalstatic->LibStatut($data[$j]->fk_statut, 3)); $line++; $j++; } } } // Add the sum in the bottom of the boxes $this->info_box_contents[$line][0] = array('tr' => 'class="liste_total"'); $this->info_box_contents[$line][1] = array('td' => 'align="left" class="liste_total" ', 'text' => $langs->trans("Total") . " " . $textHead); $this->info_box_contents[$line][2] = array('td' => 'align="right" class="liste_total" ', 'text' => $totalnb); $this->info_box_contents[$line][3] = array('td' => 'align="right" class="liste_total" ', 'text' => ''); $this->info_box_contents[$line][4] = array('td' => 'align="right" class="liste_total" ', 'text' => ""); }