/** * Show Infocom form for an item (not a standard showForm) * * @param $item CommonDBTM object * @param $withtemplate integer template or basic item (default '') **/ static function showForItem(CommonDBTM $item, $withtemplate = '') { global $CFG_GLPI; // Show Infocom or blank form if (!Session::haveRight("infocom", "r")) { return false; } if (!$item) { echo "<div class='spaced'>" . __('Requested item not found') . "</div>"; } else { $date_tax = $CFG_GLPI["date_tax"]; $dev_ID = $item->getField('id'); $ic = new self(); $option = ""; if ($withtemplate == 2) { $option = " readonly "; } if (!strpos($_SERVER['PHP_SELF'], "infocoms-show") && in_array($item->getType(), array('CartridgeItem', 'ConsumableItem', 'Software'))) { echo "<div class='firstbloc center'>" . __('For this type of item, the financial and administrative information are only a model for the items which you should add.') . "</div>"; } if (!$ic->getFromDBforDevice($item->getType(), $dev_ID)) { $input = array('itemtype' => $item->getType(), 'items_id' => $dev_ID, 'entities_id' => $item->getEntityID()); if ($ic->can(-1, "w", $input) && $withtemplate != 2) { echo "<div class='spaced b'>"; echo "<table class='tab_cadre_fixe'><tr class='tab_bg_1'><th>"; echo sprintf(__('%1$s - %2$s'), $item->getTypeName(1), $item->getName()) . "</th></tr>"; echo "<tr class='tab_bg_1'><td class='center'>"; Html::showSimpleForm($CFG_GLPI["root_doc"] . "/front/infocom.form.php", 'add', __('Enable the financial and administrative information'), array('itemtype' => $item->getType(), 'items_id' => $dev_ID)); echo "</td></tr></table></div>"; } } else { // getFromDBforDevice $canedit = $ic->can($ic->fields['id'], "w") && $withtemplate != 2; if ($canedit) { echo "<form name='form_ic' method='post' action='" . $CFG_GLPI["root_doc"] . "/front/infocom.form.php'>"; } echo "<div class='spaced'>"; echo "<table class='tab_cadre" . (!strpos($_SERVER['PHP_SELF'], "infocoms-show") ? "_fixe" : "") . "'>"; echo "<tr><th colspan='4'>" . __('Financial and administrative information') . "</th></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Supplier') . "</td>"; echo "<td>"; if ($withtemplate == 2) { echo Dropdown::getDropdownName("glpi_suppliers", $ic->fields["suppliers_id"]); } else { Supplier::dropdown(array('value' => $ic->fields["suppliers_id"], 'entity' => $item->getEntityID())); } echo "</td>"; if (Session::haveRight("budget", "r")) { echo "<td>" . __('Budget') . "</td><td >"; Budget::dropdown(array('value' => $ic->fields["budgets_id"], 'entity' => $item->getEntityID(), 'comments' => 1)); } else { echo "<td colspan='2'>"; } echo "</td></tr>"; // Can edit calendar ? $editcalendar = $withtemplate != 2; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Order number') . "</td>"; echo "<td >"; Html::autocompletionTextField($ic, "order_number", array('option' => $option)); echo "</td>"; echo "<td>" . __('Order date') . "</td><td>"; Html::showDateFormItem("order_date", $ic->fields["order_date"], true, $editcalendar); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; $istemplate = ''; if ($item->isTemplate() || in_array($item->getType(), array('CartridgeItem', 'ConsumableItem', 'Software'))) { $istemplate = '*'; } echo "<td>" . sprintf(__('%1$s%2$s'), __('Immobilization number'), $istemplate) . "</td>"; echo "<td>"; $objectName = autoName($ic->fields["immo_number"], "immo_number", $withtemplate == 2, 'Infocom', $item->getEntityID()); Html::autocompletionTextField($ic, "immo_number", array('value' => $objectName, 'option' => $option)); echo "</td>"; echo "<td>" . __('Date of purchase') . "</td><td>"; Html::showDateFormItem("buy_date", $ic->fields["buy_date"], true, $editcalendar); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Invoice number') . "</td>"; echo "<td>"; Html::autocompletionTextField($ic, "bill", array('option' => $option)); echo "</td>"; echo "<td>" . __('Delivery date') . "</td><td>"; Html::showDateFormItem("delivery_date", $ic->fields["delivery_date"], true, $editcalendar); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Delivery form') . "</td><td>"; Html::autocompletionTextField($ic, "delivery_number", array('option' => $option)); echo "</td>"; echo "<td>" . __('Startup date') . "</td><td>"; Html::showDateFormItem("use_date", $ic->fields["use_date"], true, $editcalendar); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Value') . "</td>"; echo "<td><input type='text' name='value' {$option} value='" . Html::formatNumber($ic->fields["value"], true) . "' size='14'></td>"; echo "</td>"; echo "<td>" . __('Date of last physical inventory') . "</td><td>"; Html::showDateFormItem("inventory_date", $ic->fields["inventory_date"], true, $editcalendar); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Warranty extension value') . "</td>"; echo "<td><input type='text' {$option} name='warranty_value' value='" . Html::formatNumber($ic->fields["warranty_value"], true) . "' size='14'></td>"; echo "<td rowspan='5'>" . __('Comments') . "</td>"; echo "<td rowspan='5' class='middle'>"; echo "<textarea cols='45' rows='9' name='comment' >" . $ic->fields["comment"]; echo "</textarea></td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Account net value') . "</td><td>"; echo Html::formatNumber(self::Amort($ic->fields["sink_type"], $ic->fields["value"], $ic->fields["sink_time"], $ic->fields["sink_coeff"], $ic->fields["warranty_date"], $ic->fields["use_date"], $date_tax, "n")); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Amortization type') . "</td><td >"; if ($withtemplate == 2) { echo self::getAmortTypeName($ic->fields["sink_type"]); } else { self::dropdownAmortType("sink_type", $ic->fields["sink_type"]); } echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Amortization duration') . "</td><td>"; if ($withtemplate == 2) { printf(_n('%d year', '%d years', $ic->fields["sink_time"]), $ic->fields["sink_time"]); } else { Dropdown::showNumber("sink_time", array('value' => $ic->fields["sink_time"], 'max' => 15, 'unit' => 'year')); } echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Amortization coefficient') . "</td>"; echo "<td>"; Html::autocompletionTextField($ic, "sink_coeff", array('size' => 14, 'option' => $option)); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; if (!in_array($item->getType(), array('Cartridge', 'CartridgeItem', 'Consumable', 'ConsumableItem', 'Software', 'SoftwareLicense'))) { echo "<td>" . __('TCO (value + tracking cost)') . "</td><td>"; echo self::showTco($item->getField('ticket_tco'), $ic->fields["value"]); } else { echo "<td colspan='2'>"; } echo "</td>"; if (!in_array($item->getType(), array('Cartridge', 'CartridgeItem', 'Consumable', 'ConsumableItem', 'Software', 'SoftwareLicense'))) { echo "<td>" . __('Monthly TCO') . "</td><td>"; echo self::showTco($item->getField('ticket_tco'), $ic->fields["value"], $ic->fields["warranty_date"]); } else { echo "<td colspan='2'>"; } echo "</td></tr>"; echo "<tr><th colspan='4'>" . __('Warranty information') . "</th></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Start date of warranty') . "</td><td>"; Html::showDateFormItem("warranty_date", $ic->fields["warranty_date"], true, $editcalendar); echo "</td>"; echo "<td>" . __('Warranty duration') . "</td><td>"; if ($withtemplate == 2) { // -1 = life if ($ic->fields["warranty_duration"] == -1) { _e('Lifelong'); } else { printf(_n('%d month', '%d months', $ic->fields["warranty_duration"]), $ic->fields["warranty_duration"]); } } else { Dropdown::showInteger("warranty_duration", $ic->fields["warranty_duration"], 0, 120, 1, array(-1 => __('Lifelong')), array('unit' => 'month')); } $tmpdat = self::getWarrantyExpir($ic->fields["warranty_date"], $ic->fields["warranty_duration"], 0, true); if ($tmpdat) { echo "<span class='small_space'>" . sprintf(__('Valid to %s'), $tmpdat) . "</span>"; } echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Warranty information') . "</td>"; echo "<td >"; Html::autocompletionTextField($ic, "warranty_info", array('option' => $option)); echo "</td>"; if ($CFG_GLPI['use_mailing']) { echo "<td>" . __('Alarms on financial and administrative information') . "</td>"; echo "<td>"; self::dropdownAlert(array('name' => "alert", 'value' => $ic->fields["alert"])); Alert::displayLastAlert('Infocom', $ic->fields['id']); echo "</td>"; } else { echo "</td><td colspan='2'>"; } echo "</td></tr>"; if ($canedit) { echo "<tr>"; echo "<td class='tab_bg_2 center' colspan='2'>"; echo "<input type='hidden' name='id' value='" . $ic->fields['id'] . "'>"; echo "<input type='submit' name='update' value=\"" . _sx('button', 'Save') . "\"\n class='submit'>"; echo "</td>"; echo "<td class='tab_bg_2 center' colspan='2'>"; echo "<input type='submit' name='delete' value=\"" . _sx('button', 'Delete permanently') . "\"\n class='submit'>"; echo "</td></tr>"; echo "</table></div>"; Html::closeForm(); } else { echo "</table></div>"; } } } }
/** * Print the contract cost form * * @param $ID integer ID of the item * @param $options array options used **/ function showForm($ID, $options = array()) { if ($ID > 0) { $this->check($ID, READ); } else { // Create item $options['contracts_id'] = $options['parent']->getField('id'); $this->check(-1, CREATE, $options); $this->initBasedOnPrevious(); } $this->showFormHeader($options); echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Name') . "</td>"; echo "<td>"; echo "<input type='hidden' name='contracts_id' value='" . $this->fields['contracts_id'] . "'>"; Html::autocompletionTextField($this, 'name'); echo "</td>"; echo "<td>" . __('Cost') . "</td>"; echo "<td>"; echo "<input type='text' name='cost' value='" . Html::formatNumber($this->fields["cost"], true) . "'\n size='14'>"; echo "</td></tr>"; echo "<tr class='tab_bg_1'><td>" . __('Begin date') . "</td>"; echo "<td>"; Html::showDateField("begin_date", array('value' => $this->fields['begin_date'])); echo "</td>"; $rowspan = 3; echo "<td rowspan='{$rowspan}'>" . __('Comments') . "</td>"; echo "<td rowspan='{$rowspan}' class='middle'>"; echo "<textarea cols='45' rows='" . ($rowspan + 3) . "' name='comment' >" . $this->fields["comment"] . "</textarea>"; echo "</td></tr>\n"; echo "<tr class='tab_bg_1'><td>" . __('End date') . "</td>"; echo "<td>"; Html::showDateField("end_date", array('value' => $this->fields['end_date'])); echo "</td></tr>"; echo "<tr class='tab_bg_1'><td>" . __('Budget') . "</td>"; echo "<td>"; Budget::dropdown(array('value' => $this->fields["budgets_id"])); echo "</td></tr>"; $this->showFormButtons($options); return true; }
/** * Print the item cost form * * @param $ID integer ID of the item * @param $options array options used **/ function showForm($ID, $options = array()) { if (isset($options['parent']) && !empty($options['parent'])) { $item = $options['parent']; } if ($ID > 0) { $this->check($ID, READ); } else { // Create item $options[static::$items_id] = $item->getField('id'); $this->check(-1, CREATE, $options); $this->initBasedOnPrevious(); } if ($ID > 0) { $items_id = $this->fields[static::$items_id]; } else { $items_id = $options['parent']->fields["id"]; } $item = new static::$itemtype(); if (!$item->getFromDB($items_id)) { return false; } $this->showFormHeader($options); echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Name') . "</td>"; echo "<td>"; echo "<input type='hidden' name='" . static::$items_id . "' value='" . $item->fields['id'] . "'>"; Html::autocompletionTextField($this, 'name'); echo "</td>"; echo "<td>" . __('Begin date') . "</td>"; echo "<td>"; Html::showDateField("begin_date", array('value' => $this->fields['begin_date'])); echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Duration') . "</td>"; echo "<td>"; Dropdown::showTimeStamp('actiontime', array('value' => $this->fields['actiontime'], 'addfirstminutes' => true)); echo "</td>"; echo "<td>" . __('End date') . "</td>"; echo "<td>"; Html::showDateField("end_date", array('value' => $this->fields['end_date'])); echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Time cost') . "</td><td>"; echo "<input type='text' size='15' name='cost_time' value='" . Html::formatNumber($this->fields["cost_time"], true) . "'>"; echo "</td>"; $rowspan = 4; echo "<td rowspan='{$rowspan}'>" . __('Comments') . "</td>"; echo "<td rowspan='{$rowspan}' class='middle'>"; echo "<textarea cols='45' rows='" . ($rowspan + 3) . "' name='comment' >" . $this->fields["comment"] . "</textarea>"; echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Fixed cost') . "</td><td>"; echo "<input type='text' size='15' name='cost_fixed' value='" . Html::formatNumber($this->fields["cost_fixed"], true) . "'>"; echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Material cost') . "</td><td>"; echo "<input type='text' size='15' name='cost_material' value='" . Html::formatNumber($this->fields["cost_material"], true) . "'>"; echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'><td>" . __('Budget') . "</td>"; echo "<td>"; Budget::dropdown(array('value' => $this->fields["budgets_id"], 'entity' => $this->fields["entities_id"])); echo "</td></tr>"; $this->showFormButtons($options); return true; }