From 3cdbd04104907bc7b77a489db4c93a9420f51e77 Mon Sep 17 00:00:00 2001 From: Mo Farouk <122031508+fmido88@users.noreply.github.com> Date: Sun, 4 Feb 2024 00:37:04 +0200 Subject: [PATCH] V5` --- amd/build/balance.min.js.map | 2 +- amd/build/cdiscount.min.js.map | 2 +- amd/src/balance.js | 4 ++-- amd/src/cdiscount.js | 23 ++--------------------- templates/display.mustache | 18 ++++++++++++++++-- tests/coupons_test.php | 2 +- tests/turn_non_refundable_test.php | 2 +- tests/util/instance_test.php | 2 +- 8 files changed, 25 insertions(+), 30 deletions(-) diff --git a/amd/build/balance.min.js.map b/amd/build/balance.min.js.map index fe551a5f..c361f363 100644 --- a/amd/build/balance.min.js.map +++ b/amd/build/balance.min.js.map @@ -1 +1 @@ -{"version":3,"file":"balance.min.js","sources":["../src/balance.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 * module balance\n *\n * @module enrol_wallet/balance\n * @copyright 2024 2024, Mohammad Farouk \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Ajax from 'core/ajax';\n\nlet holder;\nlet button;\nlet form;\nlet userInput;\n\n/**\n * Get the balance data through ajax call.\n */\nfunction get_data() {\n let userid = parseInt(userInput.value);\n\n if (userid && !isNaN(userid)) {\n\n let request = Ajax.call([{\n methodname: 'enrol_wallet_get_balance_details',\n args: {\n userid: userid\n }\n }]);\n\n request[0].catch((e) => {\n holder.innerHTML = '
' + e.message + e.backtrace + '
';\n });\n request[0].done((data) => {\n holder.innerHTML = data.details;\n let uniqIdHolder = holder.querySelector('[data-identifier=uniqid');\n let uniqId = uniqIdHolder.getAttribute('data-uniqid');\n require(['enrol_wallet/expenders'], function(ex) {\n ex.init(uniqId);\n });\n });\n }\n}\nexport const init = (formid) => {\n form = document.getElementById(formid);\n holder = form.querySelector(\"[data-purpose=balance-holder]\");\n button = form.querySelector(\"[name=displaybalance]\");\n userInput = form.querySelector(\"[name=userlist]\");\n\n button.onclick = () => {\n get_data();\n };\n userInput.onchange = () => {\n holder.innerHTML = '';\n };\n};\n"],"names":["holder","button","form","userInput","formid","document","getElementById","querySelector","onclick","userid","parseInt","value","isNaN","request","Ajax","call","methodname","args","catch","e","innerHTML","message","backtrace","done","data","details","uniqId","getAttribute","require","ex","init","get_data","onchange"],"mappings":";;;;;;;SAyBIA,OACAC,OACAC,KACAC,yJA8BiBC,SACjBF,KAAOG,SAASC,eAAeF,QAC/BJ,OAASE,KAAKK,cAAc,iCAC5BN,OAASC,KAAKK,cAAc,yBAC5BJ,UAAYD,KAAKK,cAAc,mBAE/BN,OAAOO,QAAU,qBA9BbC,OAASC,SAASP,UAAUQ,UAE5BF,SAAWG,MAAMH,QAAS,KAEtBI,QAAUC,cAAKC,KAAK,CAAC,CACGC,WAAY,mCACZC,KAAM,CACFR,OAAQA,WAIxCI,QAAQ,GAAGK,OAAOC,IACdnB,OAAOoB,UAAY,QAAUD,EAAEE,QAAUF,EAAEG,UAAY,YAE3DT,QAAQ,GAAGU,MAAMC,OACbxB,OAAOoB,UAAYI,KAAKC,YAEpBC,OADe1B,OAAOO,cAAc,2BACdoB,aAAa,eACvCC,QAAQ,CAAC,2BAA2B,SAASC,IACzCA,GAAGC,KAAKJ,eAYhBK,IAEJ5B,UAAU6B,SAAW,KACjBhC,OAAOoB,UAAY"} \ No newline at end of file +{"version":3,"file":"balance.min.js","sources":["../src/balance.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 * module balance\n *\n * @module enrol_wallet/balance\n * @copyright 2024 2024, Mohammad Farouk \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Ajax from 'core/ajax';\n\nlet holder;\nlet button;\nlet form;\nlet userInput;\n\n/**\n * Get the balance data through ajax call.\n */\nfunction getData() {\n let userid = parseInt(userInput.value);\n\n if (userid && !isNaN(userid)) {\n\n let request = Ajax.call([{\n methodname: 'enrol_wallet_get_balance_details',\n args: {\n userid: userid\n }\n }]);\n\n request[0].catch((e) => {\n holder.innerHTML = '
' + e.message + e.backtrace + '
';\n });\n request[0].done((data) => {\n holder.innerHTML = data.details;\n let uniqIdHolder = holder.querySelector('[data-identifier=uniqid');\n let uniqId = uniqIdHolder.getAttribute('data-uniqid');\n require(['enrol_wallet/expenders'], function(ex) {\n ex.init(uniqId);\n });\n });\n }\n}\nexport const init = (formid) => {\n form = document.getElementById(formid);\n holder = form.querySelector(\"[data-purpose=balance-holder]\");\n button = form.querySelector(\"[name=displaybalance]\");\n userInput = form.querySelector(\"[name=userlist]\");\n\n button.onclick = () => {\n getData();\n };\n userInput.onchange = () => {\n holder.innerHTML = '';\n };\n};\n"],"names":["holder","button","form","userInput","formid","document","getElementById","querySelector","onclick","userid","parseInt","value","isNaN","request","Ajax","call","methodname","args","catch","e","innerHTML","message","backtrace","done","data","details","uniqId","getAttribute","require","ex","init","getData","onchange"],"mappings":";;;;;;;SAyBIA,OACAC,OACAC,KACAC,yJA8BiBC,SACjBF,KAAOG,SAASC,eAAeF,QAC/BJ,OAASE,KAAKK,cAAc,iCAC5BN,OAASC,KAAKK,cAAc,yBAC5BJ,UAAYD,KAAKK,cAAc,mBAE/BN,OAAOO,QAAU,qBA9BbC,OAASC,SAASP,UAAUQ,UAE5BF,SAAWG,MAAMH,QAAS,KAEtBI,QAAUC,cAAKC,KAAK,CAAC,CACGC,WAAY,mCACZC,KAAM,CACFR,OAAQA,WAIxCI,QAAQ,GAAGK,OAAOC,IACdnB,OAAOoB,UAAY,QAAUD,EAAEE,QAAUF,EAAEG,UAAY,YAE3DT,QAAQ,GAAGU,MAAMC,OACbxB,OAAOoB,UAAYI,KAAKC,YAEpBC,OADe1B,OAAOO,cAAc,2BACdoB,aAAa,eACvCC,QAAQ,CAAC,2BAA2B,SAASC,IACzCA,GAAGC,KAAKJ,eAYhBK,IAEJ5B,UAAU6B,SAAW,KACjBhC,OAAOoB,UAAY"} \ No newline at end of file diff --git a/amd/build/cdiscount.min.js.map b/amd/build/cdiscount.min.js.map index b4c74179..e7ec4534 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;\n// let conditions = [];\n// let discounts = [];\n// let categories = [];\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 // for (let i = 1; ; i++) {\n // let element = form.querySelector(\"[name=condition\"+ i +\"]\");\n // if (!element) {\n // break;\n // }\n // conditions.push(parseFloat(element.value));\n // }\n\n // for (let i = 1; ; i++) {\n // let element = form.querySelector(\"[name=category\"+ i +\"]\");\n // if (!element) {\n // break;\n // }\n // categories.push(parseInt(element.value));\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,GAKhBC,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,QAAU,iBAyBpCC,qBACLtB,qBAAuBL,KAAK4B,cAAc,kCAC1C1B,QAAUF,KAAK4B,cAAc,aAnB7B3B,WAAW4B,iBAAiB,UAAU,KAClCrB,qBAEJP,WAAW4B,iBAAiB,SAAS,KACjCrB,qBAEJN,QAAQ2B,iBAAiB,UAAU,KAC/BrB,qBAEJL,cAAc0B,iBAAiB,UAAU,KACrCrB,yCAWO,iBAAkB,gBAAgBsB,MAAMC,OAC/CzB,cAAgByB,iBAOfC,yBACDvB,MAAQC,WAAWT,WAAWQ,OAC9BG,IAAMC,SAASV,cAAcM,OAC7BK,YAAc,EACTE,EAAI,EAAGA,EAAIT,MAAMU,OAAQD,IAAK,IACpBT,MAAMS,GAAGE,WACPN,SAGbO,SAAWZ,MAAMS,GAAGG,SAGpBV,OAFYF,MAAMS,GAAGK,WAECF,SAAWL,cACjCA,YAAcK,eAIlBJ,gBAAkBN,MAASA,MAAQK,YACvCV,gBAAgBK,MAAQM,yBAMnBkB,0BACDxB,MAAQC,WAAWN,gBAAgBK,OACnCG,IAAMC,SAASV,cAAcM,OAC7BK,YAAc,EACTE,EAAI,EAAGA,EAAIT,MAAMU,OAAQD,IAAK,IACpBT,MAAMS,GAAGE,WACPN,SAGbO,SAAWZ,MAAMS,GAAGG,SAGNV,OAAS,EAAIU,WAFfZ,MAAMS,GAAGK,WAGOF,SAAWL,cACvCA,YAAcK,eAIlBe,gBAAkBzB,OAAS,EAAIK,aACnCb,WAAWQ,MAAQyB,yBAgBdC,mBACL/B,gBAAkBJ,KAAK4B,cAAc,sBAVrC3B,WAAWmC,SAAWJ,eACtB/B,WAAWoC,QAAUL,eACrB5B,gBAAgBgC,SAAWH,gBAC3B7B,gBAAgBiC,QAAUJ,8BAWV,CAACK,OAAQC,YACzBvC,KAAOwC,SAASC,eAAeH,QAC/BrC,WAAaD,KAAK4B,cAAc,gBAChCzB,cAAgBH,KAAK4B,cAAc,uBAE9B,IAAIZ,EAAI,GAAKA,IAAK,KACf0B,QAAU1C,KAAK4B,cAAc,uBAAwBZ,EAAG,SACvD0B,kBAGDC,OAASC,KAAKC,MAAMH,QAAQjC,OAChCkC,OAAOtB,UAAYX,WAAWiC,OAAOtB,WACrCsB,OAAOxB,SAAWT,WAAWiC,OAAOxB,UACpCwB,OAAOzB,SAAWL,SAAS8B,OAAOzB,UAClCX,MAAMuC,KAAKH,QAmBC,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 */\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,QAAU,iBAyBpCC,qBACLtB,qBAAuBL,KAAK4B,cAAc,kCAC1C1B,QAAUF,KAAK4B,cAAc,aAnB7B3B,WAAW4B,iBAAiB,UAAU,KAClCrB,qBAEJP,WAAW4B,iBAAiB,SAAS,KACjCrB,qBAEJN,QAAQ2B,iBAAiB,UAAU,KAC/BrB,qBAEJL,cAAc0B,iBAAiB,UAAU,KACrCrB,yCAWO,iBAAkB,gBAAgBsB,MAAMC,OAC/CzB,cAAgByB,iBAOfC,yBACDvB,MAAQC,WAAWT,WAAWQ,OAC9BG,IAAMC,SAASV,cAAcM,OAC7BK,YAAc,EACTE,EAAI,EAAGA,EAAIT,MAAMU,OAAQD,IAAK,IACpBT,MAAMS,GAAGE,WACPN,SAGbO,SAAWZ,MAAMS,GAAGG,SAGpBV,OAFYF,MAAMS,GAAGK,WAECF,SAAWL,cACjCA,YAAcK,eAIlBJ,gBAAkBN,MAASA,MAAQK,YACvCV,gBAAgBK,MAAQM,yBAMnBkB,0BACDxB,MAAQC,WAAWN,gBAAgBK,OACnCG,IAAMC,SAASV,cAAcM,OAC7BK,YAAc,EACTE,EAAI,EAAGA,EAAIT,MAAMU,OAAQD,IAAK,IACpBT,MAAMS,GAAGE,WACPN,SAGbO,SAAWZ,MAAMS,GAAGG,SAGNV,OAAS,EAAIU,WAFfZ,MAAMS,GAAGK,WAGOF,SAAWL,cACvCA,YAAcK,eAIlBe,gBAAkBzB,OAAS,EAAIK,aACnCb,WAAWQ,MAAQyB,yBAgBdC,mBACL/B,gBAAkBJ,KAAK4B,cAAc,sBAVrC3B,WAAWmC,SAAWJ,eACtB/B,WAAWoC,QAAUL,eACrB5B,gBAAgBgC,SAAWH,gBAC3B7B,gBAAgBiC,QAAUJ,8BAWV,CAACK,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/balance.js b/amd/src/balance.js index 55388d4e..15b899ed 100644 --- a/amd/src/balance.js +++ b/amd/src/balance.js @@ -31,7 +31,7 @@ let userInput; /** * Get the balance data through ajax call. */ -function get_data() { +function getData() { let userid = parseInt(userInput.value); if (userid && !isNaN(userid)) { @@ -63,7 +63,7 @@ export const init = (formid) => { userInput = form.querySelector("[name=userlist]"); button.onclick = () => { - get_data(); + getData(); }; userInput.onchange = () => { holder.innerHTML = ''; diff --git a/amd/src/cdiscount.js b/amd/src/cdiscount.js index 2a14b712..8801397d 100644 --- a/amd/src/cdiscount.js +++ b/amd/src/cdiscount.js @@ -29,9 +29,6 @@ let categoryInput; let valueAfterInput; let chargingLabel = ''; let calculateValueHolder; -// let conditions = []; -// let discounts = []; -// let categories = []; let rules = []; /** @@ -88,7 +85,7 @@ function addListenersChargerForm() { } /** - * continue the procedure of the charger form. + * Continue the procedure of the charger form. */ function proceedChargerForm() { calculateValueHolder = form.querySelector("[data-holder=calculated-value]"); @@ -172,7 +169,7 @@ export const init = (formid, formType) => { categoryInput = form.querySelector("[name=category]"); for (let i = 1; ; i++) { - let element = form.querySelector("[name=discount_rule_"+ i +"]"); + let element = form.querySelector("[name=discount_rule_" + i + "]"); if (!element) { break; } @@ -183,22 +180,6 @@ export const init = (formid, formType) => { rules.push(object); } - // for (let i = 1; ; i++) { - // let element = form.querySelector("[name=condition"+ i +"]"); - // if (!element) { - // break; - // } - // conditions.push(parseFloat(element.value)); - // } - - // for (let i = 1; ; i++) { - // let element = form.querySelector("[name=category"+ i +"]"); - // if (!element) { - // break; - // } - // categories.push(parseInt(element.value)); - // } - if (formType == 'charge') { proceedChargerForm(); } else { diff --git a/templates/display.mustache b/templates/display.mustache index a12db53d..1b6c1e93 100644 --- a/templates/display.mustache +++ b/templates/display.mustache @@ -33,7 +33,21 @@ "norefund": 30, "policy": "something", "transfer": "transfer", - "referral": "referral" + "referral": "referral", + "currentuser": true, + "catdetails": [ + { + name: "some category", + refundable: 20, + nonrefundable: 100, + total: 120 + }, + { + name: "Another one", + refundable: 10, + nonrefundable: 5, + total: 15 + }] } }} @@ -43,7 +57,7 @@

{{# str }} mywallet, enrol_wallet {{/ str }}

{{/ currentuser}}

-

{{#currentuser}}{{# str }} youhavebalance, enrol_wallet {{/ str }}{{/currentuser}}
+
{{# currentuser}}{{# str }} youhavebalance, enrol_wallet {{/ str }}{{/ currentuser}}
{{balance}} {{currency}}
{{#currentuser}}{{# str }} inyourwallet, enrol_wallet {{/ str }}
{{/currentuser}} {{# str }} mainbalance, enrol_wallet {{/ str }} {{main}} {{currency}}
diff --git a/tests/coupons_test.php b/tests/coupons_test.php index ddf3c789..0a7db843 100644 --- a/tests/coupons_test.php +++ b/tests/coupons_test.php @@ -693,7 +693,7 @@ protected function setUp() :void { $this->wallet->update_status($instance, ENROL_INSTANCE_ENABLED); $inst = 'inst' . $i; $this->$inst = $instance; - if ($i <= 4) { + if ($i <= 3) { $record = new \stdClass; $record->section = 1; $record->course = $this->$var->id; diff --git a/tests/turn_non_refundable_test.php b/tests/turn_non_refundable_test.php index 74d5907a..34023816 100644 --- a/tests/turn_non_refundable_test.php +++ b/tests/turn_non_refundable_test.php @@ -141,7 +141,7 @@ public function test_check_transform_validation(): void { $this->assertEquals($output2, 200); // Not transform what already used. - $op->debit(50); + $op->debit(50, $op::OTHER); $output3 = $task->check_transform_validation($data, $trace); $this->assertEquals($output3, 150); diff --git a/tests/util/instance_test.php b/tests/util/instance_test.php index 1b9cb282..98a518b7 100644 --- a/tests/util/instance_test.php +++ b/tests/util/instance_test.php @@ -142,7 +142,7 @@ public function test_get_cost_after_discount(): void { * Testing discounts after first and second repurchase * @covers ::get_cost_after_discount */ - public function test_repurchase_discount_and_function() { + public function test_repurchase_discount_and_function():void { global $DB; $this->resetAfterTest(); $wallet = new enrol_wallet_plugin;