diff --git a/CHANGELOG.md b/CHANGELOG.md index f2a2c23..fb77f34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [UNRELEASED] + +### Fixed + +- Fix SQL error for `lowcredits` task + ## [1.15.1] - 2025-11-18 ### Fixed diff --git a/inc/entity.class.php b/inc/entity.class.php index 7918381..f67849f 100644 --- a/inc/entity.class.php +++ b/inc/entity.class.php @@ -457,7 +457,7 @@ public static function cronLowCredits($task) 'glpi_plugin_credit_entities.is_active' => 1, ], 'GROUPBY' => 'glpi_plugin_credit_entities.id', - 'HAVING' => new QueryExpression('glpi_plugin_credit_entities.quantity - quantity_consumed <= (glpi_plugin_credit_entities.quantity * glpi_plugin_credit_entities.low_credit_alert) / 100'), + 'HAVING' => [new QueryExpression('glpi_plugin_credit_entities.quantity - quantity_consumed <= (glpi_plugin_credit_entities.quantity * glpi_plugin_credit_entities.low_credit_alert) / 100')], ], ); diff --git a/inc/notificationtargetentity.class.php b/inc/notificationtargetentity.class.php index b4ad989..44e839b 100644 --- a/inc/notificationtargetentity.class.php +++ b/inc/notificationtargetentity.class.php @@ -1,5 +1,36 @@ . + * ------------------------------------------------------------------------- + * @author François Legastelois + * @copyright Copyright (C) 2017-2023 by Credit plugin team. + * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html + * @link https://github.com/pluginsGLPI/credit + * ------------------------------------------------------------------------- + */ + + + /** * ------------------------------------------------------------------------- * Credit plugin for GLPI @@ -44,6 +75,10 @@ public function addDataForTemplate($event, $options = []) /** @var DBmysql $DB */ global $DB; + if (!($this->obj instanceof CommonDBTM)) { + return; + } + $this->data['##credit.name##'] = $this->obj->getField('name'); $this->data['##credit.quantity_sold##'] = $this->obj->getField('quantity'); $this->data['##credit.begindate##'] = $this->obj->getField('begin_date'); @@ -63,8 +98,8 @@ public function addDataForTemplate($event, $options = []) ], ); $data = $req->current(); - $this->data['##credit.quantity_remaining##'] = (int) $this->obj->getField('quantity') - (int) $data['consumed_total']; - $this->data['##credit.quantity_consumed##'] = (int) $data['consumed_total']; + $this->data['##credit.quantity_remaining##'] = (string) ((int) $this->obj->getField('quantity') - (int) $data['consumed_total']); + $this->data['##credit.quantity_consumed##'] = (string) $data['consumed_total']; $this->data['##credit.entity##'] = Dropdown::getDropdownName( 'glpi_entities',