grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026.
--------------------------------------------------------------------------
*/
/** @file
* @brief
*/
if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access this file directly");
}
/**
* Infocom class
**/
class Infocom extends CommonDBChild {
// From CommonDBChild
static public $itemtype = 'itemtype';
static public $items_id = 'items_id';
public $dohistory = true;
public $auto_message_on_action = false; // Link in message can't work'
static public $logs_for_parent = false;
static $rightname = 'infocom';
//Option to automatically fill dates
const ON_STATUS_CHANGE = 'STATUS';
const COPY_WARRANTY_DATE = 1;
const COPY_BUY_DATE = 2;
const COPY_ORDER_DATE = 3;
const COPY_DELIVERY_DATE = 4;
const ON_ASSET_IMPORT = 5;
/**
* Check if given object can have InfoCom
*
* @since version 0.85
*
* @param $item an object or a string
*
* @return true if $object is an object that can have InfoCom
*
**/
static function canApplyOn($item) {
global $CFG_GLPI;
// All devices are subjects to infocom !
if (Toolbox::is_a($item, 'Item_Devices')) {
return true;
}
// We also allow direct items to check
if ($item instanceof CommonGLPI) {
$item = $item->getType();
}
if (in_array($item, $CFG_GLPI['infocom_types'])){
return true;
}
return false;
}
/**
* Get all the types that can have an infocom
*
* @since version 0.85
*
* @return array of the itemtypes
**/
static function getItemtypesThatCanHave() {
global $CFG_GLPI;
return array_merge($CFG_GLPI['infocom_types'],
Item_Devices::getDeviceTypes());
}
static function getTypeName($nb=0) {
//TRANS: Always plural
return __('Financial and administrative information');
}
function post_getEmpty() {
$this->fields["alert"] = Entity::getUsedConfig("use_infocoms_alert",
$this->fields["entities_id"],
"default_infocom_alert", 0);
}
function getLogTypeID() {
return array($this->fields['itemtype'], $this->fields['items_id']);
}
/**
* @see CommonGLPI::getTabNameForItem()
**/
function getTabNameForItem(CommonGLPI $item, $withtemplate=0) {
// Can exists on template
if (Session::haveRight(self::$rightname, READ)) {
$nb = 0;
switch ($item->getType()) {
case 'Supplier' :
if ($_SESSION['glpishow_count_on_tabs']) {
$nb = self::countForSupplier($item);
}
return self::createTabEntry(_n('Item', 'Items', Session::getPluralNumber()), $nb);
default :
if ($_SESSION['glpishow_count_on_tabs']) {
$nb = countElementsInTable('glpi_infocoms',
"`itemtype` = '".$item->getType()."'
AND `items_id` = '".$item->getID()."'");
}
return self::createTabEntry(__('Management'), $nb);
}
}
return '';
}
/**
* @param $item CommonGLPI object
* @param $tabnum (default 1)
* @param $withtemplate (default 0)
**/
static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) {
switch ($item->getType()) {
case 'Supplier' :
$item->showInfocoms();
break;
default :
self::showForItem($item, $withtemplate);
}
return true;
}
/**
* @param $item Supplier object
**/
static function countForSupplier(Supplier $item) {
$restrict = "`glpi_infocoms`.`suppliers_id` = '".$item->getField('id') ."'
AND `itemtype` NOT IN ('ConsumableItem', 'CartridgeItem', 'Software') ".
getEntitiesRestrictRequest(" AND ", "glpi_infocoms", '',
$_SESSION['glpiactiveentities']);
return countElementsInTable(array('glpi_infocoms'), $restrict);
}
static function getSpecificValueToDisplay($field, $values, array $options=array()) {
if (!is_array($values)) {
$values = array($field => $values);
}
switch ($field) {
case 'sink_type' :
return self::getAmortTypeName($values[$field]);
case 'alert' :
return self::getAlertName($values[$field]);
}
return parent::getSpecificValueToDisplay($field, $values, $options);
}
/**
* @since version 0.84
*
* @param $field
* @param $name (default '')
* @param $values (default '')
* @param $options array
**/
static function getSpecificValueToSelect($field, $name='', $values='', array $options=array()) {
if (!is_array($values)) {
$values = array($field => $values);
}
$options['display'] = false;
switch ($field) {
case "sink_type" :
return self::dropdownAmortType($name, $values[$field], false);
case "alert" :
$options['name'] = $name;
$options['value'] = $values[$field];
return self::dropdownAlert($options);
}
return parent::getSpecificValueToSelect($field, $name, $values, $options);
}
/**
* Retrieve an item from the database for a device
*
* @param $itemtype type of the device to retrieve infocom
* @param $ID ID of the device to retrieve infocom
*
* @return true if succeed else false
**/
function getFromDBforDevice ($itemtype, $ID) {
if ($this->getFromDBByQuery("WHERE `".$this->getTable()."`.`items_id` = '$ID'
AND `".$this->getTable()."`.`itemtype` = '$itemtype'")) {
return true;
}
$this->getEmpty();
$this->fields["items_id"] = $ID;
$this->fields["itemtype"] = $itemtype;
return false;
}
/**
* @see CommonDBChild::prepareInputForAdd()
**/
function prepareInputForAdd($input) {
global $CFG_GLPI;
if (!$this->getFromDBforDevice($input['itemtype'],$input['items_id'])) {
if ($item = static::getItemFromArray(static::$itemtype, static::$items_id, $input)) {
$input['alert'] = Entity::getUsedConfig('default_infocom_alert', $item->getEntityID());
return parent::prepareInputForAdd($input);
}
}
return false;
}
/**
* Fill, if necessary, automatically some dates when status changes
*
* @param item CommonDBTM object: the item whose status have changed
* @param action_add true if object is added, false if updated (true by default)
*
* @return nothing
**/
static function manageDateOnStatusChange(CommonDBTM $item, $action_add=true) {
global $CFG_GLPI;
$itemtype = get_class($item);
$changes = $item->fields;
//Autofill date on item's status change ?
$infocom = new self();
$infocom->getFromDB($changes['id']);
$tmp = array('itemtype' => $itemtype,
'items_id' => $changes['id']);
$add_or_update = false;
//For each date that can be automatically filled
foreach (self::getAutoManagemendDatesFields() as $date => $date_field) {
$resp = array();
$result = Entity::getUsedConfig($date, $changes['entities_id']);
//Date must be filled if status corresponds to the one defined in the config
if (preg_match('/'.self::ON_STATUS_CHANGE.'_(.*)/',$result,$values)
&& ($values[1] == $changes['states_id'])) {
$add_or_update = true;
$tmp[$date_field] = $_SESSION["glpi_currenttime"];
}
}
//One date or more has changed
if ($add_or_update) {
if (!$infocom->getFromDBforDevice($itemtype,$changes['id'])) {
$infocom->add($tmp);
} else {
$tmp['id'] = $infocom->fields['id'];
$infocom->update($tmp);
}
}
}
/**
* Automatically manage copying one date to another is necessary
*
* @param infocoms array of item's infocom to modify
* @param field the date to modify (default '')
* @param action the action to peform (copy from another date) (default 0)
* @param params array of additional parameters needed to perform the task
*
* @return nothing
**/
static function autofillDates(&$infocoms=array(), $field='', $action=0, $params=array()) {
if (isset($infocoms[$field])) {
switch ($action) {
default :
case 0 :
break;
case self::COPY_WARRANTY_DATE :
if (isset($infocoms['warranty_date'])) {
$infocoms[$field] = $infocoms['warranty_date'];
}
break;
case self::COPY_BUY_DATE :
if (isset($infocoms['buy_date'])) {
$infocoms[$field] = $infocoms['buy_date'];
}
break;
case self::COPY_ORDER_DATE :
if (isset($infocoms['order_date'])) {
$infocoms[$field] = $infocoms['order_date'];
}
break;
case self::COPY_DELIVERY_DATE :
if (isset($infocoms['delivery_date'])) {
$infocoms[$field] = $infocoms['delivery_date'];
}
break;
}
}
}
/**
* Return all infocom dates that could be automaticall filled
*
* @return an array with all dates (configuration field & real field)
**/
static function getAutoManagemendDatesFields() {
return array('autofill_buy_date' => 'buy_date',
'autofill_use_date' => 'use_date',
'autofill_delivery_date' => 'delivery_date',
'autofill_warranty_date' => 'warranty_date',
'autofill_order_date' => 'order_date',
'autofill_decommission_date' => 'decommission_date');
}
/**
* @see CommonDBChild::prepareInputForUpdate()
**/
function prepareInputForUpdate($input) {
//Check if one or more dates needs to be updated
foreach (self::getAutoManagemendDatesFields() as $key => $field) {
$result = Entity::getUsedConfig($key, $this->fields['entities_id']);
//Only update date if it's empty in DB. Otherwise do nothing
if (($result > 0)
&& !isset($this->fields[$field])) {
self::autofillDates($input, $field, $result);
}
}
return parent::prepareInputForUpdate($input);
}
function pre_updateInDB() {
// Clean end alert if warranty_date is after old one
// Or if duration is greater than old one
if ((isset($this->oldvalues['warranty_date'])
&& ($this->oldvalues['warranty_date'] < $this->fields['warranty_date']))
|| (isset($this->oldvalues['warranty_duration'])
&& ($this->oldvalues['warranty_duration'] < $this->fields['warranty_duration']))) {
$alert = new Alert();
$alert->clear($this->getType(), $this->fields['id'], Alert::END);
}
// Check budgets link validity
if ((in_array('budgets_id', $this->updates)
|| in_array('buy_date', $this->updates))
&& $this->fields['budgets_id']
&& ($budget = getItemForItemtype('Budget'))
&& $budget->getFromDB($this->fields['budgets_id'])) {
if ((!is_null($budget->fields['begin_date'])
&& $this->fields['buy_date'] < $budget->fields['begin_date'])
|| (!is_null($budget->fields['end_date'])
&& ($this->fields['buy_date'] > $budget->fields['end_date']))) {
$msg = sprintf(__('Purchase date incompatible with the associated budget. %1$s not in budget period: %2$s / %3$s'),
Html::convDate($this->fields['buy_date']),
Html::convDate($budget->fields['begin_date']),
Html::convDate($budget->fields['end_date']));
Session::addMessageAfterRedirect($msg, false, ERROR);
}
}
}
/**
* @since version 0.84
**/
function cleanDBonPurge() {
$class = new Alert();
$class->cleanDBonItemDelete($this->getType(), $this->fields['id']);
}
/**
* @param $name
**/
static function cronInfo($name) {
return array('description' => __('Send alarms on financial and administrative information'));
}
/**
* Cron action on infocom : alert on expired warranty
*
* @param $task to log, if NULL use display (default NULL)
*
* @return 0 : nothing to do 1 : done with success
**/
static function cronInfocom($task=NULL) {
global $DB, $CFG_GLPI;
if (!$CFG_GLPI["use_mailing"]) {
return 0;
}
$message = array();
$cron_status = 0;
$items_infos = array();
$items_messages = array();
foreach (Entity::getEntitiesToNotify('use_infocoms_alert') as $entity => $value) {
$before = Entity::getUsedConfig('send_infocoms_alert_before_delay', $entity);
$query_end = "SELECT `glpi_infocoms`.*
FROM `glpi_infocoms`
LEFT JOIN `glpi_alerts` ON (`glpi_infocoms`.`id` = `glpi_alerts`.`items_id`
AND `glpi_alerts`.`itemtype` = 'Infocom'
AND `glpi_alerts`.`type`='".Alert::END."')
WHERE (`glpi_infocoms`.`alert` & ".pow(2,Alert::END).") >'0'
AND `glpi_infocoms`.`entities_id`='".$entity."'
AND `glpi_infocoms`.`warranty_duration`>'0'
AND `glpi_infocoms`.`warranty_date` IS NOT NULL
AND DATEDIFF(ADDDATE(`glpi_infocoms`.`warranty_date`,
INTERVAL (`glpi_infocoms`.`warranty_duration`)
MONTH),
CURDATE() ) <= '$before'
AND `glpi_alerts`.`date` IS NULL";
foreach ($DB->request($query_end) as $data) {
if ($item_infocom = getItemForItemtype($data["itemtype"])) {
if ($item_infocom->getFromDB($data["items_id"])) {
$entity = $data['entities_id'];
$warranty = self::getWarrantyExpir($data["warranty_date"], $data["warranty_duration"]);
//TRANS: %1$s is a type, %2$s is a name (used in croninfocom)
$name = sprintf(__('%1$s - %2$s'), $item_infocom->getTypeName(1),
$item_infocom->getName());
//TRANS: %1$s is the warranty end date and %2$s the name of the item
$message = sprintf(__('Item reaching the end of warranty on %1$s: %2$s'),
$warranty, $name)."
";
$data['warrantyexpiration'] = $warranty;
$data['item_name'] = $item_infocom->getName();
$items_infos[$entity][$data['id']] = $data;
if (!isset($items_messages[$entity])) {
$items_messages[$entity] = __('No item reaching the end of warranty.')."
";
}
$items_messages[$entity] .= $message;
}
}
}
}
foreach ($items_infos as $entity => $items) {
if (NotificationEvent::raiseEvent("alert", new self(), array('entities_id' => $entity,
'items' => $items))) {
$message = $items_messages[$entity];
$cron_status = 1;
if ($task) {
$task->log(sprintf(__('%1$s: %2$s')."\n",
Dropdown::getDropdownName("glpi_entities", $entity), $message));
$task->addVolume(1);
} else {
Session::addMessageAfterRedirect(sprintf(__('%1$s: %2$s'),
Dropdown::getDropdownName("glpi_entities",
$entity),
$message));
}
$alert = new Alert();
$input["itemtype"] = 'Infocom';
$input["type"] = Alert::END;
foreach ($items as $id => $item) {
$input["items_id"] = $id;
$alert->add($input);
unset($alert->fields['id']);
}
} else {
$entityname = Dropdown::getDropdownName('glpi_entities', $entity);
//TRANS: %s is entity name
$msg = sprintf(__('%1$s: %2$s'), $entityname, __('send infocom alert failed'));
if ($task) {
$task->log($msg);
} else {
Session::addMessageAfterRedirect($msg, false, ERROR);
}
}
}
return $cron_status;
}
/**
* Get the possible value for infocom alert
*
* @since version 0.84 (before in alert.class)
*
* @param $val if not set, ask for all values, else for 1 value (default NULL)
*
* @return array or string
**/
static function getAlertName($val=NULL) {
$tmp[0] = Dropdown::EMPTY_VALUE;
$tmp[pow(2, Alert::END)] = __('Warranty expiration date');
if (is_null($val)) {
return $tmp;
}
// Default value for display
$tmp[0] = ' ';
if (isset($tmp[$val])) {
return $tmp[$val];
}
// If not set and is a string return value
if (is_string($val)) {
return $val;
}
return NOT_AVAILABLE;
}
/**
* @param $options array
**/
static function dropdownAlert($options) {
$p['name'] = 'alert';
$p['value'] = 0;
$p['display'] = true;
$p['inherit_parent'] = false;
if (count($options)) {
foreach ($options as $key => $val) {
$p[$key] = $val;
}
}
$tab = array();
if ($p['inherit_parent']) {
$tab[Entity::CONFIG_PARENT] = __('Inheritance of the parent entity');
}
$tab += self::getAlertName();
return Dropdown::showFromArray($p['name'], $tab, $p);
}
/**
* Dropdown of amortissement type for infocoms
*
* @param $name select name
* @param $value default value (default 0)
* @param $display display or get string (true by default)
**/
static function dropdownAmortType($name, $value=0, $display=true) {
$values = array(2 => __('Linear'),
1 => __('Decreasing'));
return Dropdown::showFromArray($name, $values,
array('value' => $value,
'display' => $display,
'display_emptychoice' => true));
}
/**
* Get amortissement type name for infocoms
*
* @param $value status ID
**/
static function getAmortTypeName($value) {
switch ($value) {
case 2 :
return __('Linear');
case 1 :
return __('Decreasing');
case 0 :
return " ";
}
}
/**
* Calculate TCO and TCO by month for an item
*
* @param $ticket_tco Tco part of tickets
* @param $value
* @param $date_achat (default '')
*
* @return float
**/
static function showTco($ticket_tco, $value, $date_achat="") {
if ($ticket_tco == NOT_AVAILABLE) {
return '-';
}
// Affiche le TCO ou le TCO mensuel pour un matériel
$totalcost = $ticket_tco;
if ($date_achat) { // on veut donc le TCO mensuel
// just to avoid IDE warning
$date_Y = $date_m = $date_d = 0;
sscanf($date_achat, "%4s-%2s-%2s", $date_Y, $date_m, $date_d);
$timestamp2 = mktime(0,0,0, $date_m, $date_d, $date_Y);
$timestamp = mktime(0,0,0, date("m"), date("d"), date("Y"));
$diff = floor(($timestamp - $timestamp2) / (MONTH_TIMESTAMP)); // Mois d'utilisation
if ($diff) {
return Html::formatNumber((($totalcost+$value)/$diff)); // TCO mensuel
}
return "";
}
return Html::formatNumber(($totalcost+$value)); // TCO
}// fin showTCO
/**
* Show infocom link to display modal
*
* @param $itemtype integer item type
* @param $device_id integer item ID
*
* @return float
**/
static function showDisplayLink($itemtype, $device_id) {
global $DB, $CFG_GLPI;
if (!Session::haveRight(self::$rightname, READ)
|| !($item = getItemForItemtype($itemtype))) {
return false;
}
$query = "SELECT COUNT(*)
FROM `glpi_infocoms`
WHERE `items_id` = '$device_id'
AND `itemtype` = '$itemtype'";
$add = "add";
$text = __('Add');
$result = $DB->query($query);
if ($DB->result($result,0,0) > 0) {
$add = "";
$text = _x('button', 'Show');
} else if (!Infocom::canUpdate()) {
return false;
}
if ($item->canView()) {
echo "
";
Ajax::createIframeModalWindow('infocom'.$itemtype.$device_id,
$CFG_GLPI["root_doc"]."/front/infocom.form.php".
"?itemtype=$itemtype&items_id=$device_id",
array('height' => 600));
}
}
/**
* Calculate amortissement for an item
*
* @param $type_amort type d'amortisssment "lineaire=2" ou "degressif=1"
* @param $va valeur d'acquisition
* @param $duree duree d'amortissement
* @param $coef coefficient d'amortissement
* @param $date_achat Date d'achat
* @param $date_use Date d'utilisation
* @param $date_tax date du debut de l'annee fiscale
* @param $view "n" pour l'annee en cours ou "all" pour le tableau complet (default 'n')
*
* @return float or array
**/
static function Amort($type_amort, $va, $duree, $coef, $date_achat, $date_use, $date_tax,
$view="n") {
// By Jean-Mathieu Doleans qui s'est un peu pris le chou :p
// Attention date mise en service/dateachat ->amort lineaire et $prorata en jour !!
// amort degressif au prorata du nombre de mois.
// Son point de depart est le 1er jour du mois d'acquisition et non date de mise en service
if ($type_amort == "2") {
if (!empty($date_use)) {
$date_achat = $date_use;
}
}
$prorata = 0;
$ecartfinmoiscourant = 0;
$ecartmoisexercice = 0;
$date_Y = $date_m = $date_d = $date_H = $date_i = $date_s = 0;
sscanf($date_achat, "%4s-%2s-%2s %2s:%2s:%2s",
$date_Y, $date_m, $date_d,
$date_H, $date_i, $date_s); // un traitement sur la date mysql pour recuperer l'annee
// un traitement sur la date mysql pour les infos necessaires
$date_Y2 = $date_m2 = $date_d2 = $date_H2 = $date_i2 = $date_s2=0;
sscanf($date_tax, "%4s-%2s-%2s %2s:%2s:%2s",
$date_Y2, $date_m2, $date_d2,
$date_H2, $date_i2, $date_s2);
$date_Y2 = date("Y");
switch ($type_amort) {
case "2" :
########################### Calcul amortissement lineaire ###########################
if (($va > 0)
&& ($duree > 0)
&& !empty($date_achat)) {
## calcul du prorata temporis en jour ##
$ecartfinmoiscourant = (30-$date_d); // calcul ecart entre jour date acquis
// ou mise en service et fin du mois courant
// en lineaire on calcule en jour
if ($date_d2 < 30) {
$ecartmoisexercice = (30-$date_d2);
}
if ($date_m > $date_m2) {
$date_m2 = $date_m2+12;
} // si l'annee fiscale debute au dela de l'annee courante
$ecartmois = (($date_m2-$date_m)*30); // calcul ecart entre mois d'acquisition
// et debut annee fiscale
$prorata = $ecartfinmoiscourant+$ecartmois-$ecartmoisexercice;
## calcul tableau d'amortissement ##
$txlineaire = (100/$duree); // calcul du taux lineaire
$annuite = ($va*$txlineaire)/100; // calcul de l'annuitee
$mrt = $va; //
// si prorata temporis la derniere annnuite cours sur la duree n+1
if ($prorata > 0) {
$duree = $duree+1;
}
for($i=1 ; $i<=$duree ; $i++) {
$tab['annee'][$i] = $date_Y+$i-1;
$tab['annuite'][$i] = $annuite;
$tab['vcnetdeb'][$i] = $mrt; // Pour chaque annee on calcul la valeur comptable nette
// de debut d'exercice
$tab['vcnetfin'][$i] = abs(($mrt - $annuite)); // Pour chaque annee on calcule la valeur
// comptable nette de fin d'exercice
// calcul de la premiere annuite si prorata temporis
if ($prorata >0) {
$tab['annuite'][1] = $annuite*($prorata/360);
$tab['vcnetfin'][1] = abs($va - $tab['annuite'][1]);
}
$mrt = $tab['vcnetfin'][$i];
}
// calcul de la derniere annuite si prorata temporis
if ($prorata > 0) {
$tab['annuite'][$duree] = $tab['vcnetdeb'][$duree];
$tab['vcnetfin'][$duree] = $tab['vcnetfin'][$duree-1] - $tab['annuite'][$duree];
}
} else {
return "-";
}
break;
case "1" :
########################### Calcul amortissement degressif ###########################
if (($va > 0)
&& ($duree > 0)
&& ($coef > 1)
&& !empty($date_achat)) {
## calcul du prorata temporis en mois ##
// si l'annee fiscale debute au dela de l'annee courante
if ($date_m > $date_m2) {
$date_m2 = $date_m2+12;
}
$ecartmois = ($date_m2-$date_m)+1; // calcul ecart entre mois d'acquisition
// et debut annee fiscale
$prorata = $ecartfinmoiscourant+$ecartmois-$ecartmoisexercice;
## calcul tableau d'amortissement ##
$txlineaire = (100/$duree); // calcul du taux lineaire virtuel
$txdegressif = $txlineaire*$coef; // calcul du taux degressif
$dureelineaire = (int) (100/$txdegressif); // calcul de la duree de l'amortissement
// en mode lineaire
$dureedegressif = $duree-$dureelineaire; // calcul de la duree de l'amortissement
// en mode degressif
$mrt = $va;
// amortissement degressif pour les premieres annees
for($i=1 ; $i<=$dureedegressif ; $i++) {
$tab['annee'][$i] = $date_Y+$i-1;
$tab['vcnetdeb'][$i] = $mrt; // Pour chaque annee on calcule la valeur comptable nette
// de debut d'exercice
$tab['annuite'][$i] = $tab['vcnetdeb'][$i]*$txdegressif/100;
$tab['vcnetfin'][$i] = $mrt - $tab['annuite'][$i]; //Pour chaque annee on calcule la valeur
//comptable nette de fin d'exercice
// calcul de la premiere annuite si prorata temporis
if ($prorata > 0) {
$tab['annuite'][1] = ($va*$txdegressif/100)*($prorata/12);
$tab['vcnetfin'][1] = $va - $tab['annuite'][1];
}
$mrt = $tab['vcnetfin'][$i];
}
// amortissement en lineaire pour les derneres annees
if ($dureelineaire != 0) {
$txlineaire = (100/$dureelineaire); // calcul du taux lineaire
} else {
$txlineaire = 100;
}
$annuite = ($tab['vcnetfin'][$dureedegressif]*$txlineaire)/100; // calcul de l'annuite
$mrt = $tab['vcnetfin'][$dureedegressif];
for($i=$dureedegressif+1 ; $i<=$dureedegressif+$dureelineaire ; $i++) {
$tab['annee'][$i] = $date_Y+$i-1;
$tab['annuite'][$i] = $annuite;
$tab['vcnetdeb'][$i] = $mrt; // Pour chaque annee on calcule la valeur comptable nette
// de debut d'exercice
$tab['vcnetfin'][$i] = abs(($mrt - $annuite)); // Pour chaque annee on calcule la valeur
// comptable nette de fin d'exercice
$mrt = $tab['vcnetfin'][$i];
}
// calcul de la derniere annuite si prorata temporis
if ($prorata > 0) {
$tab['annuite'][$duree] = $tab['vcnetdeb'][$duree];
if (isset($tab['vcnetfin'][$duree-1])) {
$tab['vcnetfin'][$duree] = ($tab['vcnetfin'][$duree-1] - $tab['annuite'][$duree]);
} else {
$tab['vcnetfin'][$duree] = 0;
}
}
} else {
return "-";
}
break;
default :
return "-";
}
// le return
if ($view == "all") {
// on retourne le tableau complet
return $tab;
}
// on retourne juste la valeur residuelle
// si on ne trouve pas l'annee en cours dans le tableau d'amortissement dans le tableau,
// le materiel est amorti
if (!array_search(date("Y"),$tab["annee"])) {
$vnc = 0;
} else if (mktime(0 , 0 , 0, $date_m2, $date_d2, date("Y"))
- mktime(0 , 0 , 0 , date("m") , date("d") , date("Y")) < 0 ) {
// on a depasse la fin d'exercice de l'annee en cours
//on prend la valeur residuelle de l'annee en cours
$vnc = $tab["vcnetfin"][array_search(date("Y"), $tab["annee"])];
} else {
// on se situe avant la fin d'exercice
// on prend la valeur residuelle de l'annee n-1
$vnc = $tab["vcnetdeb"][array_search(date("Y"), $tab["annee"])];
}
return $vnc;
}
/**
* 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 (!self::canView()) {
return false;
}
if (!$item) {
echo "
| "; echo sprintf(__('%1$s - %2$s'), $item->getTypeName(1), $item->getName())." |
|---|
| "; 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 " |