11<?php
22
3+ /**
4+ * -------------------------------------------------------------------------
5+ * Credit plugin for GLPI
6+ * -------------------------------------------------------------------------
7+ *
8+ * LICENSE
9+ *
10+ * This file is part of Credit.
11+ *
12+ * Credit is free software; you can redistribute it and/or modify
13+ * it under the terms of the GNU General Public License as published by
14+ * the Free Software Foundation; either version 3 of the License, or
15+ * (at your option) any later version.
16+ *
17+ * Credit is distributed in the hope that it will be useful,
18+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
19+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+ * GNU General Public License for more details.
21+ *
22+ * You should have received a copy of the GNU General Public License
23+ * along with Credit. If not, see <http://www.gnu.org/licenses/>.
24+ * -------------------------------------------------------------------------
25+ * @author François Legastelois
26+ * @copyright Copyright (C) 2017-2023 by Credit plugin team.
27+ * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
28+ * @link https://github.com/pluginsGLPI/credit
29+ * -------------------------------------------------------------------------
30+ */
31+
32+
33+
334/**
435 * -------------------------------------------------------------------------
536 * Credit plugin for GLPI
@@ -44,6 +75,10 @@ public function addDataForTemplate($event, $options = [])
4475 /** @var DBmysql $DB */
4576 global $ DB ;
4677
78+ if (!($ this ->obj instanceof CommonDBTM)) {
79+ return ;
80+ }
81+
4782 $ this ->data ['##credit.name## ' ] = $ this ->obj ->getField ('name ' );
4883 $ this ->data ['##credit.quantity_sold## ' ] = $ this ->obj ->getField ('quantity ' );
4984 $ this ->data ['##credit.begindate## ' ] = $ this ->obj ->getField ('begin_date ' );
@@ -63,8 +98,8 @@ public function addDataForTemplate($event, $options = [])
6398 ],
6499 );
65100 $ data = $ req ->current ();
66- $ this ->data ['##credit.quantity_remaining## ' ] = (int ) $ this ->obj ->getField ('quantity ' ) - (int ) $ data ['consumed_total ' ];
67- $ this ->data ['##credit.quantity_consumed## ' ] = (int ) $ data ['consumed_total ' ];
101+ $ this ->data ['##credit.quantity_remaining## ' ] = (string ) (( int ) $ this ->obj ->getField ('quantity ' ) - (int ) $ data ['consumed_total ' ]) ;
102+ $ this ->data ['##credit.quantity_consumed## ' ] = (string ) $ data ['consumed_total ' ];
68103
69104 $ this ->data ['##credit.entity## ' ] = Dropdown::getDropdownName (
70105 'glpi_entities ' ,
0 commit comments