|
29 | 29 | * ------------------------------------------------------------------------- |
30 | 30 | */ |
31 | 31 |
|
32 | | -include("../../../inc/includes.php"); |
33 | 32 | header("Content-Type: text/html; charset=UTF-8"); |
34 | 33 | Html::header_nocache(); |
35 | 34 |
|
36 | | -Session::checkLoginUser(); |
37 | | - |
38 | 35 | /** @var DBmysql $DB */ |
39 | 36 | global $DB; |
40 | 37 |
|
41 | 38 | if (isset($_POST["entity"])) { |
42 | | - $entity_query = [ |
43 | | - 'SELECT' => ['overconsumption_allowed', 'quantity'], |
44 | | - 'FROM' => 'glpi_plugin_credit_entities', |
45 | | - 'WHERE' => [ |
46 | | - 'id' => $_POST['entity'], |
47 | | - ], |
48 | | - ]; |
49 | | - $entity_result = $DB->request($entity_query)->current(); |
50 | | - |
51 | | - $overconsumption_allowed = $entity_result['overconsumption_allowed']; |
52 | | - $quantity_sold = (int)$entity_result['quantity']; |
53 | | - |
54 | | - if (0 !== $quantity_sold && !$overconsumption_allowed) { |
55 | | - $ticket_query = [ |
56 | | - 'SELECT' => [ |
57 | | - 'SUM' => 'consumed AS consumed_total', |
58 | | - ], |
59 | | - 'FROM' => 'glpi_plugin_credit_tickets', |
60 | | - 'WHERE' => [ |
61 | | - 'plugin_credit_entities_id' => $_POST['entity'], |
62 | | - ], |
63 | | - ]; |
64 | | - $ticket_result = $DB->request($ticket_query)->current(); |
65 | | - |
66 | | - $consumed = (int)$ticket_result['consumed_total']; |
67 | | - $max = max(0, $quantity_sold - $consumed); |
68 | | - |
69 | | - Dropdown::showNumber("plugin_credit_quantity", ['value' => '', |
70 | | - 'min' => 0, |
71 | | - 'max' => $max, |
72 | | - 'step' => 1, |
73 | | - ]); |
74 | | - } else { |
75 | | - Dropdown::showNumber("plugin_credit_quantity", ['value' => '', |
76 | | - 'min' => 0, |
77 | | - 'max' => 1000000, |
78 | | - 'step' => 1, |
79 | | - ]); |
80 | | - } |
| 39 | + $max = PluginCreditEntity::getMaximumConsumptionForCredit($_POST["entity"]); |
| 40 | + echo $max; |
81 | 41 | } |
0 commit comments