static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $job) { global $CFG_GLPI, $DB; $ID = $job->getField('id'); //////////////followups/////////// $query = "SELECT *\n FROM `glpi_ticketcosts`\n WHERE `tickets_id` = '{$ID}'\n ORDER BY `begin_date`"; $result = $DB->query($query); if (!$DB->numrows($result)) { $pdf->setColumnsSize(100); $pdf->displayLine(__('No ticket cost for this ticket', 'pdf')); } else { $pdf->setColumnsSize(60, 20, 20); $pdf->displayTitle("<b>" . TicketCost::getTypeName($DB->numrows($result)), __('Ticket duration'), CommonITILObject::getActionTime($job->fields['actiontime']) . "</b>"); $pdf->setColumnsSize(20, 10, 10, 10, 10, 10, 10, 10, 10); $pdf->setColumnsAlign('center', 'center', 'center', 'left', 'right', 'right', 'right', 'right', 'right'); $pdf->displayTitle("<b><i>" . __('Name') . "</i></b>", "<b><i>" . __('Begin date') . "</i></b>", "<b><i>" . __('End date') . "</i></b>", "<b><i>" . __('Budget') . "</i></b>", "<b><i>" . __('Duration') . "</i></b>", "<b><i>" . __('Time cost') . "</i></b>", "<b><i>" . __('Fixed cost') . "</i></b>", "<b><i>" . __('Material cost') . "</i></b>", "<b><i>" . __('Total cost') . "</i></b>"); while ($data = $DB->fetch_array($result)) { $cost = TicketCost::computeTotalCost($data['actiontime'], $data['cost_time'], $data['cost_fixed'], $data['cost_material']); $pdf->displayLine($data['name'], Html::convDate($data['begin_date']), Html::convDate($data['end_date']), Dropdown::getDropdownName('glpi_budgets', $data['budgets_id']), CommonITILObject::getActionTime($data['actiontime']), Html::formatNumber($data['cost_time']), Html::formatNumber($data['cost_fixed']), Html::formatNumber($data['cost_material']), Html::formatNumber($cost)); $total_time += $data['actiontime']; $total_costtime += $data['actiontime'] * $data['cost_time'] / HOUR_TIMESTAMP; $total_fixed += $data['cost_fixed']; $total_material += $data['cost_material']; $total += $cost; } $pdf->setColumnsSize(50, 10, 10, 10, 10, 10); $pdf->setColumnsAlign('right', 'right', 'right', 'right', 'right', 'right'); $pdf->displayLine('<b>' . __('Total'), CommonITILObject::getActionTime($total_time), Html::formatNumber($total_costtime), Html::formatNumber($total_fixed), Html::formatNumber($total_material), Html::formatNumber($total)); } $pdf->displaySpace(); }
function showForm($ID, $options = array()) { global $CFG_GLPI, $DB; if (!static::canView()) { return false; } // In percent $colsize1 = '13'; $colsize2 = '37'; $default_use_notif = Entity::getUsedConfig('is_notif_enable_default', $_SESSION['glpiactive_entity'], '', 1); // Set default options if (!$ID) { $values = array('_users_id_requester' => Session::getLoginUserID(), '_users_id_requester_notif' => array('use_notification' => $default_use_notif, 'alternative_email' => ''), '_groups_id_requester' => 0, '_users_id_assign' => 0, '_users_id_assign_notif' => array('use_notification' => $default_use_notif, 'alternative_email' => ''), '_groups_id_assign' => 0, '_users_id_observer' => 0, '_users_id_observer_notif' => array('use_notification' => $default_use_notif, 'alternative_email' => ''), '_suppliers_id_assign_notif' => array('use_notification' => $default_use_notif, 'alternative_email' => ''), '_groups_id_observer' => 0, '_suppliers_id_assign' => 0, 'priority' => 3, 'urgency' => 3, 'impact' => 3, 'content' => '', 'entities_id' => $_SESSION['glpiactive_entity'], 'name' => '', 'itilcategories_id' => 0); foreach ($values as $key => $val) { if (!isset($options[$key])) { $options[$key] = $val; } } if (isset($options['tickets_id'])) { $ticket = new Ticket(); if ($ticket->getFromDB($options['tickets_id'])) { $options['content'] = $ticket->getField('content'); $options['name'] = $ticket->getField('name'); $options['impact'] = $ticket->getField('impact'); $options['urgency'] = $ticket->getField('urgency'); $options['priority'] = $ticket->getField('priority'); $options['itilcategories_id'] = $ticket->getField('itilcategories_id'); $options['due_date'] = $ticket->getField('due_date'); } } if (isset($options['problems_id'])) { $problem = new Problem(); if ($problem->getFromDB($options['problems_id'])) { $options['content'] = $problem->getField('content'); $options['name'] = $problem->getField('name'); $options['impact'] = $problem->getField('impact'); $options['urgency'] = $problem->getField('urgency'); $options['priority'] = $problem->getField('priority'); $options['itilcategories_id'] = $problem->getField('itilcategories_id'); $options['due_date'] = $problem->getField('due_date'); } } } if ($ID > 0) { $this->check($ID, READ); } else { // Create item $this->check(-1, CREATE, $options); } $showuserlink = 0; if (User::canView()) { $showuserlink = 1; } $this->showFormHeader($options); echo "<tr class='tab_bg_1'>"; echo "<th class='left' width='{$colsize1}%'>" . __('Opening date') . "</th>"; echo "<td class='left' width='{$colsize2}%'>"; if (isset($options['tickets_id'])) { echo "<input type='hidden' name='_tickets_id' value='" . $options['tickets_id'] . "'>"; } if (isset($options['problems_id'])) { echo "<input type='hidden' name='_problems_id' value='" . $options['problems_id'] . "'>"; } $date = $this->fields["date"]; if (!$ID) { $date = date("Y-m-d H:i:s"); } Html::showDateTimeField("date", array('value' => $date, 'timestep' => 1, 'maybeempty' => false)); echo "</td>"; echo "<th width='{$colsize1}%'>" . __('Due date') . "</th>"; echo "<td width='{$colsize2}%' class='left'>"; if ($this->fields["due_date"] == 'NULL') { $this->fields["due_date"] = ''; } Html::showDateTimeField("due_date", array('value' => $this->fields["due_date"], 'timestep' => 1)); echo "</td></tr>"; if ($ID) { echo "<tr class='tab_bg_1'><th>" . __('By') . "</th><td>"; User::dropdown(array('name' => 'users_id_recipient', 'value' => $this->fields["users_id_recipient"], 'entity' => $this->fields["entities_id"], 'right' => 'all')); echo "</td>"; echo "<th>" . __('Last update') . "</th>"; echo "<td>" . Html::convDateTime($this->fields["date_mod"]) . "\n"; if ($this->fields['users_id_lastupdater'] > 0) { printf(__('%1$s: %2$s'), __('By'), getUserName($this->fields["users_id_lastupdater"], $showuserlink)); } echo "</td></tr>"; } if ($ID && (in_array($this->fields["status"], $this->getSolvedStatusArray()) || in_array($this->fields["status"], $this->getClosedStatusArray()))) { echo "<tr class='tab_bg_1'>"; echo "<th>" . __('Date of solving') . "</th>"; echo "<td>"; Html::showDateTimeField("solvedate", array('value' => $this->fields["solvedate"], 'timestep' => 1, 'maybeempty' => false)); echo "</td>"; if (in_array($this->fields["status"], $this->getClosedStatusArray())) { echo "<th>" . __('Closing date') . "</th>"; echo "<td>"; Html::showDateTimeField("closedate", array('value' => $this->fields["closedate"], 'timestep' => 1, 'maybeempty' => false)); echo "</td>"; } else { echo "<td colspan='2'> </td>"; } echo "</tr>"; } echo "</table>"; echo "<table class='tab_cadre_fixe' id='mainformtable2'>"; echo "<tr class='tab_bg_1'>"; echo "<th width='{$colsize1}%'>" . __('Status') . "</th>"; echo "<td width='{$colsize2}%'>"; self::dropdownStatus(array('value' => $this->fields["status"], 'showtype' => 'allowed')); ChangeValidation::alertValidation($this, 'status'); echo "</td>"; echo "<th width='{$colsize1}%'>" . __('Urgency') . "</th>"; echo "<td width='{$colsize2}%'>"; // Only change during creation OR when allowed to change priority OR when user is the creator $idurgency = self::dropdownUrgency(array('value' => $this->fields["urgency"])); echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<th>" . __('Category') . "</th>"; echo "<td >"; $opt = array('value' => $this->fields["itilcategories_id"], 'entity' => $this->fields["entities_id"], 'condition' => "`is_change`='1'"); ITILCategory::dropdown($opt); echo "</td>"; echo "<th>" . __('Impact') . "</th>"; echo "<td>"; $idimpact = self::dropdownImpact(array('value' => $this->fields["impact"])); echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<th>" . __('Total duration') . "</th>"; echo "<td>" . parent::getActionTime($this->fields["actiontime"]) . "</td>"; echo "<th class='left'>" . __('Priority') . "</th>"; echo "<td>"; $idpriority = parent::dropdownPriority(array('value' => $this->fields["priority"], 'withmajor' => true)); $idajax = 'change_priority_' . mt_rand(); echo " <span id='{$idajax}' style='display:none'></span>"; $params = array('urgency' => '__VALUE0__', 'impact' => '__VALUE1__', 'priority' => 'dropdown_priority' . $idpriority); Ajax::updateItemOnSelectEvent(array('dropdown_urgency' . $idurgency, 'dropdown_impact' . $idimpact), $idajax, $CFG_GLPI["root_doc"] . "/ajax/priority.php", $params); echo "</td>"; echo "</tr>"; echo "</table>"; $this->showActorsPartForm($ID, $options); echo "<table class='tab_cadre_fixe' id='mainformtable3'>"; echo "<tr class='tab_bg_1'>"; echo "<th width='{$colsize1}%'>" . __('Title') . "</th>"; echo "<td colspan='3'>"; echo "<input type='text' size='90' maxlength=250 name='name' " . " value=\"" . Html::cleanInputText($this->fields["name"]) . "\">"; echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<th>" . __('Description') . "</th>"; echo "<td colspan='3'>"; $rand = mt_rand(); echo "<textarea id='content{$rand}' name='content' cols='90' rows='6'>" . Html::clean(Html::entity_decode_deep($this->fields["content"])) . "</textarea>"; echo "</td>"; echo "</tr>"; $options['colspan'] = 3; $this->showFormButtons($options); return true; }
/** * @param $ID * @param $options array **/ function showForm($ID, $options = array()) { global $CFG_GLPI, $DB; if (!static::canView()) { return false; } // In percent $colsize1 = '13'; $colsize2 = '37'; // Set default options if (!$ID) { $values = array('_users_id_requester' => Session::getLoginUserID(), '_users_id_requester_notif' => array('use_notification' => 1, 'alternative_email' => ''), '_groups_id_requester' => 0, '_users_id_assign' => 0, '_users_id_assign_notif' => array('use_notification' => 1, 'alternative_email' => ''), '_groups_id_assign' => 0, '_users_id_observer' => 0, '_users_id_observer_notif' => array('use_notification' => 1, 'alternative_email' => ''), '_groups_id_observer' => 0, '_suppliers_id_assign' => 0, 'priority' => 3, 'urgency' => 3, 'impact' => 3, 'content' => '', 'name' => '', 'entities_id' => $_SESSION['glpiactive_entity'], 'itilcategories_id' => 0); foreach ($values as $key => $val) { if (!isset($options[$key])) { $options[$key] = $val; } } if (isset($options['tickets_id'])) { $ticket = new Ticket(); if ($ticket->getFromDB($options['tickets_id'])) { $options['content'] = $ticket->getField('content'); $options['name'] = $ticket->getField('name'); $options['impact'] = $ticket->getField('impact'); $options['urgency'] = $ticket->getField('urgency'); $options['priority'] = $ticket->getField('priority'); $options['itilcategories_id'] = $ticket->getField('itilcategories_id'); } } } $this->initForm($ID, $options); $showuserlink = 0; if (Session::haveRight('user', 'r')) { $showuserlink = 1; } $this->showTabs($options); $this->showFormHeader($options); echo "<tr class='tab_bg_1'>"; echo "<th class='left' width='{$colsize1}%'>" . __('Opening date') . "</th>"; echo "<td class='left' width='{$colsize2}%'>"; if (isset($options['tickets_id'])) { echo "<input type='hidden' name='_tickets_id' value='" . $options['tickets_id'] . "'>"; } $date = $this->fields["date"]; if (!$ID) { $date = date("Y-m-d H:i:s"); } Html::showDateTimeFormItem("date", $date, 1, false); echo "</td>"; echo "<th width='{$colsize1}%'>" . __('Due date') . "</th>"; echo "<td width='{$colsize2}%' class='left'>"; if ($this->fields["due_date"] == 'NULL') { $this->fields["due_date"] = ''; } Html::showDateTimeFormItem("due_date", $this->fields["due_date"], 1, true); echo "</td></tr>"; if ($ID) { echo "<tr class='tab_bg_1'><th>" . __('By') . "</th><td>"; User::dropdown(array('name' => 'users_id_recipient', 'value' => $this->fields["users_id_recipient"], 'entity' => $this->fields["entities_id"], 'right' => 'all')); echo "</td>"; echo "<th>" . __('Last update') . "</th>"; echo "<td>" . Html::convDateTime($this->fields["date_mod"]) . "\n"; if ($this->fields['users_id_lastupdater'] > 0) { printf(__('%1$s: %2$s'), __('By'), getUserName($this->fields["users_id_lastupdater"], $showuserlink)); } echo "</td></tr>"; } if ($ID && (in_array($this->fields["status"], $this->getSolvedStatusArray()) || in_array($this->fields["status"], $this->getClosedStatusArray()))) { echo "<tr class='tab_bg_1'>"; echo "<th>" . __('Date of solving') . "</th>"; echo "<td>"; Html::showDateTimeFormItem("solvedate", $this->fields["solvedate"], 1, false); echo "</td>"; if (in_array($this->fields["status"], $this->getClosedStatusArray())) { echo "<th>" . __('Closing date') . "</th>"; echo "<td>"; Html::showDateTimeFormItem("closedate", $this->fields["closedate"], 1, false); echo "</td>"; } else { echo "<td colspan='2'> </td>"; } echo "</tr>"; } echo "</table>"; echo "<table class='tab_cadre_fixe' id='mainformtable2'>"; echo "<tr class='tab_bg_1'>"; echo "<th width='{$colsize1}%'>" . __('Status') . "</th>"; echo "<td width='{$colsize2}%'>"; self::dropdownStatus(array('value' => $this->fields["status"], 'showtype' => 'allowed')); echo "</td>"; echo "<th width='{$colsize1}%'>" . __('Urgency') . "</th>"; echo "<td width='{$colsize2}%'>"; // Only change during creation OR when allowed to change priority OR when user is the creator $idurgency = self::dropdownUrgency(array('value' => $this->fields["urgency"])); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<th>" . __('Category') . "</th>"; echo "<td >"; $opt = array('value' => $this->fields["itilcategories_id"], 'entity' => $this->fields["entities_id"], 'condition' => "`is_problem`='1'"); ITILCategory::dropdown($opt); echo "</td>"; echo "<th>" . __('Impact') . "</th>"; echo "<td>"; $idimpact = self::dropdownImpact(array('value' => $this->fields["impact"])); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<th>" . __('Total duration') . "</th>"; echo "<td>" . parent::getActionTime($this->fields["actiontime"]) . "</td>"; echo "<th class='left'>" . __('Priority') . "</th>"; echo "<td>"; $idpriority = parent::dropdownPriority(array('value' => $this->fields["priority"], 'withmajor' => true)); $idajax = 'change_priority_' . mt_rand(); echo " <span id='{$idajax}' style='display:none'></span>"; $params = array('urgency' => '__VALUE0__', 'impact' => '__VALUE1__', 'priority' => $idpriority); Ajax::updateItemOnSelectEvent(array($idurgency, $idimpact), $idajax, $CFG_GLPI["root_doc"] . "/ajax/priority.php", $params); echo "</td>"; echo "</tr>"; echo "</table>"; $this->showActorsPartForm($ID, $options); echo "<table class='tab_cadre_fixe' id='mainformtable3'>"; echo "<tr class='tab_bg_1'>"; echo "<th width='{$colsize1}%'>" . __('Title') . "</th>"; echo "<td colspan='3'>"; $rand = mt_rand(); echo "<script type='text/javascript' >\n"; echo "function showName{$rand}() {\n"; echo "Ext.get('name{$rand}').setDisplayed('none');"; $params = array('maxlength' => 250, 'size' => 110, 'name' => 'name', 'data' => rawurlencode($this->fields["name"])); Ajax::updateItemJsCode("viewname{$rand}", $CFG_GLPI["root_doc"] . "/ajax/inputtext.php", $params); echo "}"; echo "</script>\n"; echo "<div id='name{$rand}' class='tracking left' onClick='showName{$rand}()'>\n"; if (empty($this->fields["name"])) { _e('Without title'); } else { echo $this->fields["name"]; } echo "</div>\n"; echo "<div id='viewname{$rand}'></div>\n"; if (!$ID) { echo "<script type='text/javascript' >\n\n showName{$rand}();\n </script>"; } echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<th>" . __('Description') . "</th>"; echo "<td colspan='3'>"; $rand = mt_rand(); echo "<script type='text/javascript' >\n"; echo "function showDesc{$rand}() {\n"; echo "Ext.get('desc{$rand}').setDisplayed('none');"; $params = array('rows' => 6, 'cols' => 110, 'name' => 'content', 'data' => rawurlencode($this->fields["content"])); Ajax::updateItemJsCode("viewdesc{$rand}", $CFG_GLPI["root_doc"] . "/ajax/textarea.php", $params); echo "}"; echo "</script>\n"; echo "<div id='desc{$rand}' class='tracking' onClick='showDesc{$rand}()'>\n"; if (!empty($this->fields["content"])) { echo nl2br($this->fields["content"]); } else { _e('Empty description'); } echo "</div>\n"; echo "<div id='viewdesc{$rand}'></div>\n"; if (!$ID) { echo "<script type='text/javascript' >\n\n showDesc{$rand}();\n </script>"; } echo "</td></tr>"; if ($ID) { echo "<tr class='tab_bg_1'>"; echo "<th colspan='2' width='" . ($colsize1 + $colsize2) . "%'>"; $docnb = Document_Item::countForItem($this); echo "<a href=\"" . $this->getLinkURL() . "&forcetab=Document_Item\$1\">"; //TRANS: %d is the document number echo sprintf(_n('%d associated document', '%d associated documents', $docnb), $docnb); echo "</a></th>"; echo "<td colspan='2'></td>"; echo "</tr>"; } $options['colspan'] = 2; $this->showFormButtons($options); $this->addDivForTabs(); return true; }
/** * Print the item costs * * @param $item CommonITILObject object or Project * @param $withtemplate boolean Template or basic item (default '') * * @return total cost **/ static function showForObject($item, $withtemplate = '') { global $DB, $CFG_GLPI; $forproject = false; if (Toolbox::is_a($item, 'Project')) { $forproject = true; } $ID = $item->fields['id']; if (!$item->getFromDB($ID) || !$item->canViewItem() || !static::canView()) { return false; } $canedit = false; if (!$forproject) { $canedit = $item->canUpdateItem(); } echo "<div class='center'>"; $condition = "= '{$ID}'"; if ($forproject) { $condition = " IN ('" . implode("','", ProjectTask::getAllTicketsForProject($ID)) . "')"; } $query = "SELECT *\n FROM `" . static::getTable() . "`\n WHERE `" . static::$items_id . "` {$condition}\n ORDER BY `begin_date`"; $rand = mt_rand(); if ($canedit) { echo "<div id='viewcost" . $ID . "_{$rand}'></div>\n"; echo "<script type='text/javascript' >\n"; echo "function viewAddCost" . $ID . "_{$rand}() {\n"; $params = array('type' => static::getType(), 'parenttype' => static::$itemtype, static::$items_id => $ID, 'id' => -1); Ajax::updateItemJsCode("viewcost" . $ID . "_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params); echo "};"; echo "</script>\n"; if (static::canCreate()) { echo "<div class='center firstbloc'>" . "<a class='vsubmit' href='javascript:viewAddCost" . $ID . "_{$rand}();'>"; echo __('Add a new cost') . "</a></div>\n"; } } $total = 0; $total_time = 0; $total_costtime = 0; $total_fixed = 0; $total_material = 0; if ($result = $DB->query($query)) { echo "<table class='tab_cadre_fixehov'>"; echo "<tr class='noHover'>"; if ($forproject) { echo "<th colspan='10'>" . _n('Ticket cost', 'Ticket costs', $DB->numrows($result)) . "</th>"; } else { echo "<th colspan='7'>" . self::getTypeName($DB->numrows($result)) . "</th>"; echo "<th>" . __('Item duration') . "</th>"; echo "<th>" . CommonITILObject::getActionTime($item->fields['actiontime']) . "</th>"; } echo "</tr>"; if ($DB->numrows($result)) { echo "<tr>"; if ($forproject) { echo "<th>" . __('Ticket') . "</th>"; $ticket = new Ticket(); } echo "<th>" . __('Name') . "</th>"; echo "<th>" . __('Begin date') . "</th>"; echo "<th>" . __('End date') . "</th>"; echo "<th>" . __('Budget') . "</th>"; echo "<th>" . __('Duration') . "</th>"; echo "<th>" . __('Time cost') . "</th>"; echo "<th>" . __('Fixed cost') . "</th>"; echo "<th>" . __('Material cost') . "</th>"; echo "<th>" . __('Total cost') . "</th>"; echo "</tr>"; Session::initNavigateListItems(static::getType(), sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); while ($data = $DB->fetch_assoc($result)) { echo "<tr class='tab_bg_2' " . ($canedit ? "style='cursor:pointer' onClick=\"viewEditCost" . $data[static::$items_id] . "_" . $data['id'] . "_{$rand}();\"" : '') . ">"; $name = empty($data['name']) ? sprintf(__('%1$s (%2$s)'), $data['name'], $data['id']) : $data['name']; if ($forproject) { $ticket->getFromDB($data['tickets_id']); echo "<td>" . $ticket->getLink() . "</td>"; } echo "<td>"; printf(__('%1$s %2$s'), $name, Html::showToolTip($data['comment'], array('display' => false))); if ($canedit) { echo "\n<script type='text/javascript' >\n"; echo "function viewEditCost" . $data[static::$items_id] . "_" . $data["id"] . "_{$rand}() {\n"; $params = array('type' => static::getType(), 'parenttype' => static::$itemtype, static::$items_id => $data[static::$items_id], 'id' => $data["id"]); Ajax::updateItemJsCode("viewcost" . $ID . "_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params); echo "};"; echo "</script>\n"; } echo "</td>"; echo "<td>" . Html::convDate($data['begin_date']) . "</td>"; echo "<td>" . Html::convDate($data['end_date']) . "</td>"; echo "<td>" . Dropdown::getDropdownName('glpi_budgets', $data['budgets_id']) . "</td>"; echo "<td>" . CommonITILObject::getActionTime($data['actiontime']) . "</td>"; $total_time += $data['actiontime']; echo "<td class='numeric'>" . Html::formatNumber($data['cost_time']) . "</td>"; $total_costtime += $data['actiontime'] * $data['cost_time'] / HOUR_TIMESTAMP; echo "<td class='numeric'>" . Html::formatNumber($data['cost_fixed']) . "</td>"; $total_fixed += $data['cost_fixed']; echo "<td class='numeric'>" . Html::formatNumber($data['cost_material']) . "</td>"; $total_material += $data['cost_material']; $cost = self::computeTotalCost($data['actiontime'], $data['cost_time'], $data['cost_fixed'], $data['cost_material']); echo "<td class='numeric'>" . Html::formatNumber($cost) . "</td>"; $total += $cost; echo "</tr>"; Session::addToNavigateListItems(static::getType(), $data['id']); } $colspan = 4; if ($forproject) { $colspan++; } echo "<tr class='b noHover'><td colspan='{$colspan}' class='right'>" . __('Total') . '</td>'; echo "<td>" . CommonITILObject::getActionTime($total_time) . "</td>"; echo "<td class='numeric'>" . Html::formatNumber($total_costtime) . "</td>"; echo "<td class='numeric'>" . Html::formatNumber($total_fixed) . '</td>'; echo "<td class='numeric'>" . Html::formatNumber($total_material) . '</td>'; echo "<td class='numeric'>" . Html::formatNumber($total) . '</td></tr>'; } else { echo "<tr><th colspan='9'>" . __('No item found') . "</th></tr>"; } echo "</table>"; } echo "</div><br>"; return $total; }
/** * Print the ticket costs * * @param $ticket Ticket object * @param $withtemplate boolean Template or basic item (default '') * * @return Nothing (call to classes members) **/ static function showForTicket(Ticket $ticket, $withtemplate = '') { global $DB, $CFG_GLPI; $ID = $ticket->fields['id']; if (!$ticket->getFromDB($ID) || !$ticket->can($ID, "r") || !Session::haveRight('ticketcost', 'r')) { return false; } $canedit = Session::haveRight('ticketcost', 'w'); echo "<div class='center'>"; $query = "SELECT *\n FROM `glpi_ticketcosts`\n WHERE `tickets_id` = '{$ID}'\n ORDER BY `begin_date`"; $rand = mt_rand(); if ($canedit) { echo "<div id='viewcost" . $ID . "_{$rand}'></div>\n"; echo "<script type='text/javascript' >\n"; echo "function viewAddCost" . $ID . "_{$rand}() {\n"; $params = array('type' => __CLASS__, 'parenttype' => 'Ticket', 'tickets_id' => $ID, 'id' => -1); Ajax::updateItemJsCode("viewcost" . $ID . "_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params); echo "};"; echo "</script>\n"; echo "<div class='center firstbloc'>" . "<a class='vsubmit' href='javascript:viewAddCost" . $ID . "_{$rand}();'>"; echo __('Add a new cost') . "</a></div>\n"; } if ($result = $DB->query($query)) { echo "<table class='tab_cadre_fixehov'>"; echo "<tr><th colspan='7'>" . self::getTypeName($DB->numrows($result)) . "</th>"; echo "<th>" . __('Ticket duration') . "</th>"; echo "<th>" . CommonITILObject::getActionTime($ticket->fields['actiontime']) . "</th>"; echo "</tr>"; if ($DB->numrows($result)) { echo "<tr><th>" . __('Name') . "</th>"; echo "<th>" . __('Begin date') . "</th>"; echo "<th>" . __('End date') . "</th>"; echo "<th>" . __('Budget') . "</th>"; echo "<th>" . __('Duration') . "</th>"; echo "<th>" . __('Time cost') . "</th>"; echo "<th>" . __('Fixed cost') . "</th>"; echo "<th>" . __('Material cost') . "</th>"; echo "<th>" . __('Total cost') . "</th>"; echo "</tr>"; Session::initNavigateListItems(__CLASS__, sprintf(__('%1$s = %2$s'), Ticket::getTypeName(1), $ticket->getName())); $total = 0; $total_time = 0; $total_costtime = 0; $total_fixed = 0; $total_material = 0; while ($data = $DB->fetch_assoc($result)) { echo "<tr class='tab_bg_2' " . ($canedit ? "style='cursor:pointer' onClick=\"viewEditCost" . $data['tickets_id'] . "_" . $data['id'] . "_{$rand}();\"" : '') . ">"; $name = empty($data['name']) ? sprintf(__('%1$s (%2$s)'), $data['name'], $data['id']) : $data['name']; echo "<td>"; printf(__('%1$s %2$s'), $name, Html::showToolTip($data['comment'], array('display' => false))); if ($canedit) { echo "\n<script type='text/javascript' >\n"; echo "function viewEditCost" . $data['tickets_id'] . "_" . $data["id"] . "_{$rand}() {\n"; $params = array('type' => __CLASS__, 'parenttype' => 'Ticket', 'tickets_id' => $data["tickets_id"], 'id' => $data["id"]); Ajax::updateItemJsCode("viewcost" . $ID . "_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params); echo "};"; echo "</script>\n"; } echo "</td>"; echo "<td>" . Html::convDate($data['begin_date']) . "</td>"; echo "<td>" . Html::convDate($data['end_date']) . "</td>"; echo "<td>" . Dropdown::getDropdownName('glpi_budgets', $data['budgets_id']) . "</td>"; echo "<td>" . CommonITILObject::getActionTime($data['actiontime']) . "</td>"; $total_time += $data['actiontime']; echo "<td class='numeric'>" . Html::formatNumber($data['cost_time']) . "</td>"; $total_costtime += $data['actiontime'] * $data['cost_time'] / HOUR_TIMESTAMP; echo "<td class='numeric'>" . Html::formatNumber($data['cost_fixed']) . "</td>"; $total_fixed += $data['cost_fixed']; echo "<td class='numeric'>" . Html::formatNumber($data['cost_material']) . "</td>"; $total_material += $data['cost_material']; $cost = self::computeTotalCost($data['actiontime'], $data['cost_time'], $data['cost_fixed'], $data['cost_material']); echo "<td class='numeric'>" . Html::formatNumber($cost) . "</td>"; $total += $cost; echo "</tr>"; Session::addToNavigateListItems(__CLASS__, $data['id']); } echo "<tr class='b'><td colspan='4' class='right'>" . __('Total') . '</td>'; echo "<td>" . CommonITILObject::getActionTime($total_time) . "</td>"; echo "<td class='numeric'>" . Html::formatNumber($total_costtime) . "</td>"; echo "<td class='numeric'>" . Html::formatNumber($total_fixed) . '</td>'; echo "<td class='numeric'>" . Html::formatNumber($total_material) . '</td>'; echo "<td class='numeric'>" . Html::formatNumber($total) . '</td></tr>'; } else { echo "<tr><th colspan='9'>" . __('No item found') . "</th></tr>"; } echo "</table>"; } echo "</div><br>"; }