diff --git a/amd/build/cdiscount.min.js.map b/amd/build/cdiscount.min.js.map index e7ec4534..eb900523 100644 --- a/amd/build/cdiscount.min.js.map +++ b/amd/build/cdiscount.min.js.map @@ -1 +1 @@ -{"version":3,"file":"cdiscount.min.js","sources":["../src/cdiscount.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Handling and calculate the values before and after discount in top up form and charger form.\n *\n * @module enrol_wallet/cdiscount\n * @copyright 2024 Mohammad Farouk \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport {get_string} from 'core/str';\n\nlet form;\nlet valueInput;\nlet opInput;\nlet categoryInput;\nlet valueAfterInput;\nlet chargingLabel = '';\nlet calculateValueHolder;\nlet rules = [];\n\n/**\n * For the charger form.\n * calculate the actual charge value and display it.\n */\nfunction calculateCharge() {\n var value = parseFloat(valueInput.value);\n var op = opInput.value;\n var cat = parseInt(categoryInput.value);\n\n var maxDiscount = 0;\n var calculatedValue = value;\n for (var i = 0; i < rules.length; i++) {\n var category = rules[i].category;\n if (category !== cat) {\n continue;\n }\n var discount = rules[i].discount;\n var condition = rules[i].condition;\n var valueBefore = value + (value * discount / (1 - discount));\n\n if (valueBefore >= condition && discount > maxDiscount) {\n maxDiscount = discount;\n calculatedValue = valueBefore;\n }\n }\n\n if (op == \"credit\") {\n calculateValueHolder.innerHTML = chargingLabel + Math.round(calculatedValue * 100) / 100;\n calculateValueHolder.style.display = '';\n } else {\n calculateValueHolder.innerHTML = \"\";\n calculateValueHolder.style.display = 'none';\n }\n}\n\n/**\n * Add listeners for the inputs of charger form.\n */\nfunction addListenersChargerForm() {\n valueInput.addEventListener('change', () => {\n calculateCharge();\n });\n valueInput.addEventListener('keyup', () => {\n calculateCharge();\n });\n opInput.addEventListener('change', () => {\n calculateCharge();\n });\n categoryInput.addEventListener('change', () => {\n calculateCharge();\n });\n}\n\n/**\n * Continue the procedure of the charger form.\n */\nfunction proceedChargerForm() {\n calculateValueHolder = form.querySelector(\"[data-holder=calculated-value]\");\n opInput = form.querySelector(\"[name=op]\");\n addListenersChargerForm();\n get_string('charging_value', 'enrol_wallet').done((data) => {\n chargingLabel = data;\n });\n}\n\n/**\n * Calculate the value after discount and put it in the discounted input.\n */\nfunction calculateAfter() {\n var value = parseFloat(valueInput.value);\n var cat = parseInt(categoryInput.value);\n var maxDiscount = 0;\n for (var i = 0; i < rules.length; i++) {\n var category = rules[i].category;\n if (category !== cat) {\n continue;\n }\n var discount = rules[i].discount;\n var condition = rules[i].condition;\n\n if (value >= condition && discount > maxDiscount) {\n maxDiscount = discount;\n }\n }\n\n var calculatedValue = value - (value * maxDiscount);\n valueAfterInput.value = calculatedValue;\n}\n\n/**\n * Calculate the value before the discount and put it in the value input.\n */\nfunction calculateBefore() {\n var value = parseFloat(valueAfterInput.value);\n var cat = parseInt(categoryInput.value);\n var maxDiscount = 0;\n for (var i = 0; i < rules.length; i++) {\n var category = rules[i].category;\n if (category !== cat) {\n continue;\n }\n var discount = rules[i].discount;\n var condition = rules[i].condition;\n\n var valueBefore = value / (1 - discount);\n if (valueBefore >= condition && discount > maxDiscount) {\n maxDiscount = discount;\n }\n }\n\n var realValueBefore = value / (1 - maxDiscount);\n valueInput.value = realValueBefore;\n}\n\n/**\n * Adding event listeners to the top up form.\n */\nfunction addListenersTopUpForm() {\n valueInput.onchange = calculateAfter;\n valueInput.onkeyup = calculateAfter;\n valueAfterInput.onchange = calculateBefore;\n valueAfterInput.onkeyup = calculateBefore;\n}\n\n/**\n * Continue the procedure for the top up form.\n */\nfunction proceedTopUpForm() {\n valueAfterInput = form.querySelector('[name=value-after]');\n addListenersTopUpForm();\n}\n\nexport const init = (formid, formType) => {\n form = document.getElementById(formid);\n valueInput = form.querySelector(\"[name=value]\");\n categoryInput = form.querySelector(\"[name=category]\");\n\n for (let i = 1; ; i++) {\n let element = form.querySelector(\"[name=discount_rule_\" + i + \"]\");\n if (!element) {\n break;\n }\n var object = JSON.parse(element.value);\n object.condition = parseFloat(object.condition);\n object.discount = parseFloat(object.discount);\n object.category = parseInt(object.category);\n rules.push(object);\n }\n\n if (formType == 'charge') {\n proceedChargerForm();\n } else {\n proceedTopUpForm();\n }\n};"],"names":["form","valueInput","opInput","categoryInput","valueAfterInput","calculateValueHolder","chargingLabel","rules","calculateCharge","value","parseFloat","op","cat","parseInt","maxDiscount","calculatedValue","i","length","category","discount","valueBefore","condition","innerHTML","Math","round","style","display","proceedChargerForm","querySelector","addEventListener","done","data","calculateAfter","calculateBefore","realValueBefore","proceedTopUpForm","onchange","onkeyup","formid","formType","document","getElementById","element","object","JSON","parse","push"],"mappings":";;;;;;;;IAwBIA,KACAC,WACAC,QACAC,cACAC,iGAEAC,qBADAC,cAAgB,GAEhBC,MAAQ,YAMHC,0BACDC,MAAQC,WAAWT,WAAWQ,OAC9BE,GAAKT,QAAQO,MACbG,IAAMC,SAASV,cAAcM,OAE7BK,YAAc,EACdC,gBAAkBN,MACbO,EAAI,EAAGA,EAAIT,MAAMU,OAAQD,IAAK,IACpBT,MAAMS,GAAGE,WACPN,SAGbO,SAAWZ,MAAMS,GAAGG,SAEpBC,YAAcX,MAASA,MAAQU,UAAY,EAAIA,UAE/CC,aAHYb,MAAMS,GAAGK,WAGOF,SAAWL,cACvCA,YAAcK,SACdJ,gBAAkBK,cAIhB,UAANT,IACAN,qBAAqBiB,UAAYhB,cAAgBiB,KAAKC,MAAwB,IAAlBT,iBAAyB,IACrFV,qBAAqBoB,MAAMC,QAAU,KAErCrB,qBAAqBiB,UAAY,GACjCjB,qBAAqBoB,MAAMC,QA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,KAAK4B,cAAc,uBAAyBZ,EAAI,SACzD0B,kBAGDC,OAASC,KAAKC,MAAMH,QAAQjC,OAChCkC,OAAOtB,UAAYX,WAAWiC,OAAOtB,WACrCsB,OAAOxB,SAAWT,WAAWiC,OAAOxB,UACpCwB,OAAOzB,SAAWL,SAAS8B,OAAOzB,UAClCX,MAAMuC,KAAKH,QAGC,UAAZJ,SACAZ,qBAEAQ"} \ No newline at end of file +{"version":3,"file":"cdiscount.min.js","sources":["../src/cdiscount.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Handling and calculate the values before and after discount in top up form and charger form.\n *\n * @module enrol_wallet/cdiscount\n * @copyright 2024 Mohammad Farouk \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n/* eslint-disable camelcase */\nimport {get_string} from 'core/str';\n\nlet form;\nlet valueInput;\nlet opInput;\nlet categoryInput;\nlet valueAfterInput;\nlet chargingLabel = '';\nlet calculateValueHolder;\nlet rules = [];\n\n/**\n * For the charger form.\n * calculate the actual charge value and display it.\n */\nfunction calculateCharge() {\n var value = parseFloat(valueInput.value);\n var op = opInput.value;\n var cat = parseInt(categoryInput.value);\n\n var maxDiscount = 0;\n var calculatedValue = value;\n for (var i = 0; i < rules.length; i++) {\n var category = rules[i].category;\n if (category !== cat) {\n continue;\n }\n var discount = rules[i].discount;\n var condition = rules[i].condition;\n var valueBefore = value + (value * discount / (1 - discount));\n\n if (valueBefore >= condition && discount > maxDiscount) {\n maxDiscount = discount;\n calculatedValue = valueBefore;\n }\n }\n\n if (op == \"credit\") {\n calculateValueHolder.innerHTML = chargingLabel + Math.round(calculatedValue * 100) / 100;\n calculateValueHolder.style.display = '';\n } else {\n calculateValueHolder.innerHTML = \"\";\n calculateValueHolder.style.display = 'none';\n }\n}\n\n/**\n * Add listeners for the inputs of charger form.\n */\nfunction addListenersChargerForm() {\n valueInput.addEventListener('change', () => {\n calculateCharge();\n });\n valueInput.addEventListener('keyup', () => {\n calculateCharge();\n });\n opInput.addEventListener('change', () => {\n calculateCharge();\n });\n categoryInput.addEventListener('change', () => {\n calculateCharge();\n });\n}\n\n/**\n * Continue the procedure of the charger form.\n */\nfunction proceedChargerForm() {\n calculateValueHolder = form.querySelector(\"[data-holder=calculated-value]\");\n opInput = form.querySelector(\"[name=op]\");\n addListenersChargerForm();\n get_string('charging_value', 'enrol_wallet').done((data) => {\n chargingLabel = data;\n });\n}\n\n/**\n * Calculate the value after discount and put it in the discounted input.\n */\nfunction calculateAfter() {\n var value = parseFloat(valueInput.value);\n var cat = parseInt(categoryInput.value);\n var maxDiscount = 0;\n for (var i = 0; i < rules.length; i++) {\n var category = rules[i].category;\n if (category !== cat) {\n continue;\n }\n var discount = rules[i].discount;\n var condition = rules[i].condition;\n\n if (value >= condition && discount > maxDiscount) {\n maxDiscount = discount;\n }\n }\n\n var calculatedValue = value - (value * maxDiscount);\n valueAfterInput.value = calculatedValue;\n}\n\n/**\n * Calculate the value before the discount and put it in the value input.\n */\nfunction calculateBefore() {\n var value = parseFloat(valueAfterInput.value);\n var cat = parseInt(categoryInput.value);\n var maxDiscount = 0;\n for (var i = 0; i < rules.length; i++) {\n var category = rules[i].category;\n if (category !== cat) {\n continue;\n }\n var discount = rules[i].discount;\n var condition = rules[i].condition;\n\n var valueBefore = value / (1 - discount);\n if (valueBefore >= condition && discount > maxDiscount) {\n maxDiscount = discount;\n }\n }\n\n var realValueBefore = value / (1 - maxDiscount);\n valueInput.value = realValueBefore;\n}\n\n/**\n * Adding event listeners to the top up form.\n */\nfunction addListenersTopUpForm() {\n valueInput.onchange = calculateAfter;\n valueInput.onkeyup = calculateAfter;\n valueAfterInput.onchange = calculateBefore;\n valueAfterInput.onkeyup = calculateBefore;\n}\n\n/**\n * Continue the procedure for the top up form.\n */\nfunction proceedTopUpForm() {\n valueAfterInput = form.querySelector('[name=value-after]');\n addListenersTopUpForm();\n}\n\nexport const init = (formid, formType) => {\n form = document.getElementById(formid);\n valueInput = form.querySelector(\"[name=value]\");\n categoryInput = form.querySelector(\"[name=category]\");\n\n for (let i = 1; ; i++) {\n let element = form.querySelector(\"[name=discount_rule_\" + i + \"]\");\n if (!element) {\n break;\n }\n var object = JSON.parse(element.value);\n object.condition = parseFloat(object.condition);\n object.discount = parseFloat(object.discount);\n object.category = parseInt(object.category);\n rules.push(object);\n }\n\n if (formType == 'charge') {\n proceedChargerForm();\n } else {\n proceedTopUpForm();\n }\n};"],"names":["form","valueInput","opInput","categoryInput","valueAfterInput","calculateValueHolder","chargingLabel","rules","calculateCharge","value","parseFloat","op","cat","parseInt","maxDiscount","calculatedValue","i","length","category","discount","valueBefore","condition","innerHTML","Math","round","style","display","proceedChargerForm","querySelector","addEventListener","done","data","calculateAfter","calculateBefore","realValueBefore","proceedTopUpForm","onchange","onkeyup","formid","formType","document","getElementById","element","object","JSON","parse","push"],"mappings":";;;;;;;;IAyBIA,KACAC,WACAC,QACAC,cACAC,iGAEAC,qBADAC,cAAgB,GAEhBC,MAAQ,YAMHC,0BACDC,MAAQC,WAAWT,WAAWQ,OAC9BE,GAAKT,QAAQO,MACbG,IAAMC,SAASV,cAAcM,OAE7BK,YAAc,EACdC,gBAAkBN,MACbO,EAAI,EAAGA,EAAIT,MAAMU,OAAQD,IAAK,IACpBT,MAAMS,GAAGE,WACPN,SAGbO,SAAWZ,MAAMS,GAAGG,SAEpBC,YAAcX,MAASA,MAAQU,UAAY,EAAIA,UAE/CC,aAHYb,MAAMS,GAAGK,WAGOF,SAAWL,cACvCA,YAAcK,SACdJ,gBAAkBK,cAIhB,UAAN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K,OAAQC,YACzBvC,KAAOwC,SAASC,eAAeH,QAC/BrC,WAAaD,KAAK4B,cAAc,gBAChCzB,cAAgBH,KAAK4B,cAAc,uBAE9B,IAAIZ,EAAI,GAAKA,IAAK,KACf0B,QAAU1C,KAAK4B,cAAc,uBAAyBZ,EAAI,SACzD0B,kBAGDC,OAASC,KAAKC,MAAMH,QAAQjC,OAChCkC,OAAOtB,UAAYX,WAAWiC,OAAOtB,WACrCsB,OAAOxB,SAAWT,WAAWiC,OAAOxB,UACpCwB,OAAOzB,SAAWL,SAAS8B,OAAOzB,UAClCX,MAAMuC,KAAKH,QAGC,UAAZJ,SACAZ,qBAEAQ"} \ No newline at end of file diff --git a/amd/src/cdiscount.js b/amd/src/cdiscount.js index 8801397d..dc4d2982 100644 --- a/amd/src/cdiscount.js +++ b/amd/src/cdiscount.js @@ -20,6 +20,7 @@ * @copyright 2024 Mohammad Farouk * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +/* eslint-disable camelcase */ import {get_string} from 'core/str'; let form; diff --git a/classes/util/balance.php b/classes/util/balance.php index e91dc1b0..4b234bc5 100644 --- a/classes/util/balance.php +++ b/classes/util/balance.php @@ -48,17 +48,17 @@ class balance { * The current source of wallet. * @var int */ - protected int $source; + protected $source; /** * The current userid. * @var int */ - protected int $userid; + protected $userid; /** * The current category id. * @var int */ - protected int $catid; + protected $catid; /** * category operation helper class * @var operations @@ -68,22 +68,22 @@ class balance { * The main balance for the user * @var float */ - public float $balance; + public $balance; /** * The whole balance details * @var array */ - public array $details; + public $details; /** * The id of the record in the database. * @var int */ - protected int $recordid; + protected $recordid; /** * The valid balance for the user. * @var float */ - public float $valid; + public $valid; /** * Balance helper object to get all balance data of a given user. * use enrol_wallet\util\balance_op for operations like credit or debit. diff --git a/classes/util/balance_op.php b/classes/util/balance_op.php index 69eeffb0..b299d074 100644 --- a/classes/util/balance_op.php +++ b/classes/util/balance_op.php @@ -135,12 +135,12 @@ class balance_op extends balance { * The amount per transaction. * @var float */ - private float $amount; + private $amount; /** * The course id at which the operation done. * @var int */ - private int $courseid; + private $courseid; /** * Helper calss diff --git a/templates/display.mustache b/templates/display.mustache index 1b6c1e93..9b2dada3 100644 --- a/templates/display.mustache +++ b/templates/display.mustache @@ -37,17 +37,18 @@ "currentuser": true, "catdetails": [ { - name: "some category", - refundable: 20, - nonrefundable: 100, - total: 120 + "name": "some category", + "refundable": 20, + "nonrefundable": 100, + "total": 120 }, { - name: "Another one", - refundable: 10, - nonrefundable: 5, - total: 15 - }] + "name": "Another one", + "refundable": 10, + "nonrefundable": 5, + "total": 15 + } + ] } }}