/** * Load data for box to show them later * * @param int $max Maximum number of records to load * @return void */ function loadBox($max = 5) { global $user, $langs, $db, $conf; $this->max = $max; include_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php'; $actionstatic = new ActionComm($db); $this->info_box_head = array('text' => $langs->trans("BoxTitleLastActionsToDo", $max)); if ($user->rights->agenda->myactions->read) { $sql = "SELECT a.id, a.label, a.datep as dp, a.percent as percentage,"; $sql .= " ta.code,"; $sql .= " s.nom, s.rowid as socid"; $sql .= " FROM (" . MAIN_DB_PREFIX . "c_actioncomm AS ta, "; $sql .= MAIN_DB_PREFIX . "actioncomm AS a)"; if (!$user->rights->societe->client->voir && !$user->societe_id) { $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON a.fk_soc = sc.fk_soc"; } $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as s ON a.fk_soc = s.rowid"; $sql .= " WHERE a.fk_action = ta.id"; $sql .= " AND a.entity = " . $conf->entity; $sql .= " AND a.percent >= 0 AND a.percent < 100"; if (!$user->rights->societe->client->voir && !$user->societe_id) { $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = "******")"; } if ($user->societe_id) { $sql .= " AND s.rowid = " . $user->societe_id; } if (!$user->rights->agenda->allactions->read) { $sql .= " AND (a.fk_user_author = " . $user->id . " OR a.fk_user_action = " . $user->id . " OR a.fk_user_done = " . $user->id . ")"; } $sql .= " ORDER BY a.datec DESC"; $sql .= $db->plimit($max, 0); dol_syslog("Box_actions::loadBox sql=" . $sql, LOG_DEBUG); $result = $db->query($sql); if ($result) { $now = dol_now(); $delay_warning = $conf->global->MAIN_DELAY_ACTIONS_TODO * 24 * 60 * 60; $num = $db->num_rows($result); $i = 0; while ($i < $num) { $late = ''; $objp = $db->fetch_object($result); $datelimite = $db->jdate($objp->dp); if ($objp->percentage >= 0 && $objp->percentage < 100 && $datelimite < $now - $delay_warning) { $late = img_warning($langs->trans("Late")); } //($langs->transnoentities("Action".$objp->code)!=("Action".$objp->code) ? $langs->transnoentities("Action".$objp->code) : $objp->label) $label = $objp->label; $this->info_box_contents[$i][0] = array('td' => 'align="left" width="16"', 'logo' => "action", 'url' => DOL_URL_ROOT . "/comm/action/fiche.php?id=" . $objp->id); $this->info_box_contents[$i][1] = array('td' => 'align="left"', 'text' => dol_trunc($label, 32), 'text2' => $late, 'url' => DOL_URL_ROOT . "/comm/action/fiche.php?id=" . $objp->id); $this->info_box_contents[$i][2] = array('td' => 'align="left" width="16"', 'logo' => $objp->socid ? 'company' : '', 'url' => $objp->socid ? DOL_URL_ROOT . "/societe/soc.php?socid=" . $objp->socid : ''); $this->info_box_contents[$i][3] = array('td' => 'align="left"', 'text' => dol_trunc($objp->nom, 24), 'url' => DOL_URL_ROOT . "/societe/soc.php?socid=" . $objp->socid); $this->info_box_contents[$i][4] = array('td' => 'align="left" class="nowrap"', 'text' => dol_print_date($datelimite, "dayhour")); $this->info_box_contents[$i][5] = array('td' => 'align="right"', 'text' => $objp->percentage >= 0 ? $objp->percentage . '%' : ''); $this->info_box_contents[$i][6] = array('td' => 'align="right" width="18"', 'text' => $actionstatic->LibStatut($objp->percentage, 3)); $i++; } if ($num == 0) { $this->info_box_contents[$i][0] = array('td' => 'align="center"', 'text' => $langs->trans("NoActionsToDo")); } $db->free($result); } else { $this->info_box_contents[0][0] = array('td' => 'align="left"', 'maxlength' => 500, 'text' => $db->error() . ' sql=' . $sql); } } else { $this->info_box_contents[0][0] = array('align' => 'left', 'text' => $langs->trans("ReadPermissionNotAllowed")); } }
if ($obj->fk_contact > 0) { $contactstatic->lastname = $obj->lastname; $contactstatic->firstname = $obj->firstname; $contactstatic->id = $obj->fk_contact; print $contactstatic->getNomUrl(1, '', 10); } else { print " "; } print '</td>'; // User to do print '<td align="left">'; if ($obj->fk_user_action > 0) { $userstatic->fetch($obj->fk_user_action); print $userstatic->getLoginUrl(1); } else { print ' '; } print '</td>'; // Status/Percent print '<td align="right" class="nowrap">' . $actionstatic->LibStatut($obj->percent, 6) . '</td>'; print "</tr>\n"; $i++; } print "</table>"; print '</form>'; $db->free($resql); } else { dol_print_error($db); } llxFooter(); $db->close();
/** * Show last actions array * * @param int $max Max nb of records * @return void */ function show_array_last_actions_done($max = 5) { global $langs, $conf, $user, $db, $bc, $socid; $now = dol_now(); $sql = "SELECT a.id, a.percent, a.datep as da, a.datep2 as da2, a.fk_user_author, a.label,"; $sql .= " c.code, c.libelle,"; $sql .= " s.rowid, s.nom as sname, s.client"; $sql .= " FROM " . MAIN_DB_PREFIX . "c_actioncomm as c LEFT JOIN "; $sql .= " " . MAIN_DB_PREFIX . "actioncomm as a ON c.id = a.fk_action "; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as s ON a.fk_soc = s.rowid"; if (!$user->rights->societe->client->voir && !$socid) { $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; } $sql .= " WHERE a.entity = " . $conf->entity; $sql .= " AND (a.percent >= 100 OR (a.percent = -1 AND a.datep2 <= '" . $db->idate($now) . "'))"; if (!$user->rights->societe->client->voir && !$socid) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = "******" AND s.rowid = " . $socid; } $sql .= " ORDER BY a.datep2 DESC"; $sql .= $db->plimit($max, 0); $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); print '<table class="noborder" width="100%">'; print '<tr class="liste_titre"><td colspan="2">' . $langs->trans("LastDoneTasks", $max) . '</td>'; print '<td colspan="2" align="right"><a href="' . DOL_URL_ROOT . '/comm/action/listactions.php?status=done">' . $langs->trans("FullList") . '</a>'; print '</tr>'; $var = true; $i = 0; $staticaction = new ActionComm($db); $customerstatic = new Societe($db); while ($i < $num) { $obj = $db->fetch_object($resql); $var = !$var; print '<tr ' . $bc[$var] . '>'; $staticaction->type_code = $obj->code; $staticaction->libelle = $obj->label; $staticaction->id = $obj->id; print '<td>' . $staticaction->getNomUrl(1, 34) . '</td>'; //print '<td>'.dol_trunc($obj->label,24).'</td>'; print '<td>'; if ($obj->rowid > 0) { $customerstatic->id = $obj->rowid; $customerstatic->name = $obj->sname; $customerstatic->client = $obj->client; print $customerstatic->getNomUrl(1, '', 24); } print '</td>'; // Date print '<td width="100" align="right">' . dol_print_date($db->jdate($obj->da2), 'day'); print "</td>"; // Statut print "<td align=\"right\" width=\"14\">" . $staticaction->LibStatut($obj->percent, 3) . "</td>\n"; print "</tr>\n"; $i++; } // TODO Ajouter rappel pour "il y a des contrats a mettre en service" // TODO Ajouter rappel pour "il y a des contrats qui arrivent a expiration" print "</table><br>"; $db->free($resql); } else { dol_print_error($db); } }
/** * Show html area with actions done * * @param Conf $conf Object conf * @param Translate $langs Object langs * @param DoliDB $db Object db * @param Object $object Object third party or member * @param Contact $objcon Object contact * @param int $noprint Return string but does not output it * @return mixed Return html part or void if noprint is 1 * TODO change function to be able to list event linked to an object. */ function show_actions_done($conf, $langs, $db, $object, $objcon = '', $noprint = 0) { global $bc, $user; // Check parameters if (!is_object($object)) { dol_print_error('', 'BadParameter'); } $out = ''; $histo = array(); $numaction = 0; $now = dol_now('tzuser'); if (!empty($conf->agenda->enabled)) { // Recherche histo sur actioncomm $sql = "SELECT a.id, a.label,"; $sql .= " a.datep as dp,"; $sql .= " a.datep2 as dp2,"; $sql .= " a.note, a.percent,"; $sql .= " a.fk_element, a.elementtype,"; $sql .= " a.fk_user_author, a.fk_contact,"; $sql .= " c.code as acode, c.libelle,"; $sql .= " u.login, u.rowid as user_id"; if (get_class($object) == 'Adherent') { $sql .= ", m.lastname, m.firstname"; } if (get_class($object) == 'Societe') { $sql .= ", sp.lastname, sp.firstname"; } $sql .= " FROM " . MAIN_DB_PREFIX . "c_actioncomm as c, " . MAIN_DB_PREFIX . "user as u, " . MAIN_DB_PREFIX . "actioncomm as a"; if (get_class($object) == 'Adherent') { $sql .= ", " . MAIN_DB_PREFIX . "adherent as m"; } if (get_class($object) == 'Societe') { $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "socpeople as sp ON a.fk_contact = sp.rowid"; } $sql .= " WHERE u.rowid = a.fk_user_author"; $sql .= " AND a.entity IN (" . getEntity('agenda', 1) . ")"; if (get_class($object) == 'Adherent') { $sql .= " AND a.fk_element = m.rowid AND a.elementtype = 'member'"; } if (get_class($object) == 'Adherent' && $object->id) { $sql .= " AND a.fk_element = " . $object->id; } if (get_class($object) == 'Societe' && $object->id) { $sql .= " AND a.fk_soc = " . $object->id; } if (is_object($objcon) && $objcon->id) { $sql .= " AND a.fk_contact = " . $objcon->id; } $sql .= " AND c.id=a.fk_action"; $sql .= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '" . $db->idate($now) . "'))"; $sql .= " ORDER BY a.datep DESC, a.id DESC"; dol_syslog("company.lib::show_actions_done sql=" . $sql, LOG_DEBUG); $resql = $db->query($sql); if ($resql) { $i = 0; $num = $db->num_rows($resql); $var = true; while ($i < $num) { $obj = $db->fetch_object($resql); $histo[$numaction] = array('type' => 'action', 'id' => $obj->id, 'datestart' => $db->jdate($obj->dp), 'date' => $db->jdate($obj->dp2), 'note' => $obj->label, 'percent' => $obj->percent, 'acode' => $obj->acode, 'libelle' => $obj->libelle, 'userid' => $obj->user_id, 'login' => $obj->login, 'contact_id' => $obj->fk_contact, 'lastname' => $obj->lastname, 'firstname' => $obj->firstname, 'fk_element' => $obj->fk_element, 'elementtype' => $obj->elementtype); $numaction++; $i++; } } else { dol_print_error($db); } } if (!empty($conf->mailing->enabled) && !empty($objcon->email)) { $langs->load("mails"); // Recherche histo sur mailing $sql = "SELECT m.rowid as id, mc.date_envoi as da, m.titre as note, '100' as percentage,"; $sql .= " 'AC_EMAILING' as acode,"; $sql .= " u.rowid as user_id, u.login"; // User that valid action $sql .= " FROM " . MAIN_DB_PREFIX . "mailing as m, " . MAIN_DB_PREFIX . "mailing_cibles as mc, " . MAIN_DB_PREFIX . "user as u"; $sql .= " WHERE mc.email = '" . $db->escape($objcon->email) . "'"; // Search is done on email. $sql .= " AND mc.statut = 1"; $sql .= " AND u.rowid = m.fk_user_valid"; $sql .= " AND mc.fk_mailing=m.rowid"; $sql .= " ORDER BY mc.date_envoi DESC, m.rowid DESC"; dol_syslog("company.lib::show_actions_done sql=" . $sql, LOG_DEBUG); $resql = $db->query($sql); if ($resql) { $i = 0; $num = $db->num_rows($resql); $var = true; while ($i < $num) { $obj = $db->fetch_object($resql); $histo[$numaction] = array('type' => 'mailing', 'id' => $obj->id, 'date' => $db->jdate($obj->da), 'note' => $obj->note, 'percent' => $obj->percentage, 'acode' => $obj->acode, 'userid' => $obj->user_id, 'login' => $obj->login); $numaction++; $i++; } $db->free($resql); } else { dol_print_error($db); } } if (!empty($conf->agenda->enabled) || !empty($conf->mailing->enabled) && !empty($objcon->email)) { require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php'; require_once DOL_DOCUMENT_ROOT . '/comm/propal/class/propal.class.php'; require_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php'; require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php'; $actionstatic = new ActionComm($db); $userstatic = new User($db); $contactstatic = new Contact($db); // TODO uniformize $propalstatic = new Propal($db); $orderstatic = new Commande($db); $facturestatic = new Facture($db); $out .= "\n"; $out .= '<table class="noborder" width="100%">'; $out .= '<tr class="liste_titre">'; $out .= '<td colspan="2">'; if (get_class($object) == 'Societe') { $out .= '<a href="' . DOL_URL_ROOT . '/comm/action/listactions.php?socid=' . $object->id . '&status=done">'; } $out .= $langs->trans("ActionsDoneShort"); if (get_class($object) == 'Societe') { $out .= '</a>'; } $out .= '</td>'; $out .= '<td colspan="5" align="right">'; $permok = $user->rights->agenda->myactions->create; if ((!empty($object->id) || !empty($objcon->id)) && $permok) { $out .= '<a href="' . DOL_URL_ROOT . '/comm/action/fiche.php?action=create'; if (get_class($object) == 'Societe') { $out .= '&socid=' . $object->id; } $out .= (!empty($objcon->id) ? '&contactid=' . $objcon->id : '') . '&backtopage=1&percentage=-1">'; $out .= $langs->trans("AddAnAction") . ' '; $out .= img_picto($langs->trans("AddAnAction"), 'filenew'); $out .= "</a>"; } $out .= '</td>'; $out .= '</tr>'; foreach ($histo as $key => $value) { $var = !$var; $out .= "<tr " . $bc[$var] . ">"; // Champ date $out .= '<td width="120" class="nowrap">'; if ($histo[$key]['date']) { $out .= dol_print_date($histo[$key]['date'], 'dayhour'); } else { if ($histo[$key]['datestart']) { $out .= dol_print_date($histo[$key]['datestart'], 'dayhour'); } } $out .= "</td>\n"; // Picto $out .= '<td width="16"> </td>'; // Action $out .= '<td>'; if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'action') { $actionstatic->type_code = $histo[$key]['acode']; $transcode = $langs->trans("Action" . $histo[$key]['acode']); $libelle = $transcode != "Action" . $histo[$key]['acode'] ? $transcode : $histo[$key]['libelle']; //$actionstatic->libelle=$libelle; $actionstatic->libelle = $histo[$key]['note']; $actionstatic->id = $histo[$key]['id']; $out .= $actionstatic->getNomUrl(1, 40); } if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'mailing') { $out .= '<a href="' . DOL_URL_ROOT . '/comm/mailing/fiche.php?id=' . $histo[$key]['id'] . '">' . img_object($langs->trans("ShowEMailing"), "email") . ' '; $transcode = $langs->trans("Action" . $histo[$key]['acode']); $libelle = $transcode != "Action" . $histo[$key]['acode'] ? $transcode : 'Send mass mailing'; $out .= dol_trunc($libelle, 40); } $out .= '</td>'; // Title of event //$out.='<td>'.dol_trunc($histo[$key]['note'], 40).'</td>'; // Objet lie // TODO uniformize $out .= '<td>'; if (isset($histo[$key]['elementtype'])) { if ($histo[$key]['elementtype'] == 'propal' && !empty($conf->propal->enabled)) { $propalstatic->ref = $langs->trans("ProposalShort"); $propalstatic->id = $histo[$key]['fk_element']; $out .= $propalstatic->getNomUrl(1); } elseif ($histo[$key]['elementtype'] == 'commande' && !empty($conf->commande->enabled)) { $orderstatic->ref = $langs->trans("Order"); $orderstatic->id = $histo[$key]['fk_element']; $out .= $orderstatic->getNomUrl(1); } elseif ($histo[$key]['elementtype'] == 'facture' && !empty($conf->facture->enabled)) { $facturestatic->ref = $langs->trans("Invoice"); $facturestatic->id = $histo[$key]['fk_element']; $facturestatic->type = $histo[$key]['ftype']; $out .= $facturestatic->getNomUrl(1, 'compta'); } else { $out .= ' '; } } else { $out .= ' '; } $out .= '</td>'; // Contact pour cette action if (!empty($objcon->id) && isset($histo[$key]['contact_id']) && $histo[$key]['contact_id'] > 0) { $contactstatic->lastname = $histo[$key]['lastname']; $contactstatic->firstname = $histo[$key]['firstname']; $contactstatic->id = $histo[$key]['contact_id']; $out .= '<td width="120">' . $contactstatic->getNomUrl(1, '', 10) . '</td>'; } else { $out .= '<td> </td>'; } // Auteur $out .= '<td class="nowrap" width="80">'; $userstatic->id = $histo[$key]['userid']; $userstatic->login = $histo[$key]['login']; $out .= $userstatic->getLoginUrl(1); $out .= '</td>'; // Statut $out .= '<td class="nowrap" width="20">' . $actionstatic->LibStatut($histo[$key]['percent'], 3) . '</td>'; $out .= "</tr>\n"; $i++; } $out .= "</table>\n"; $out .= "<br>\n"; } if ($noprint) { return $out; } else { print $out; } }