diff --git a/amd/build/balance.min.js.map b/amd/build/balance.min.js.map index c361f363..08602dc8 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 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 +{"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}\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,yJA+BiBC,SACjBF,KAAOG,SAASC,eAAeF,QAC/BJ,OAASE,KAAKK,cAAc,iCAC5BN,OAASC,KAAKK,cAAc,yBAC5BJ,UAAYD,KAAKK,cAAc,mBAE/BN,OAAOO,QAAU,qBA/BbC,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,eAahBK,IAEJ5B,UAAU6B,SAAW,KACjBhC,OAAOoB,UAAY"} \ No newline at end of file diff --git a/amd/build/expenders.min.js b/amd/build/expenders.min.js index 64b865ad..4d83b857 100644 --- a/amd/build/expenders.min.js +++ b/amd/build/expenders.min.js @@ -1,3 +1,3 @@ -define("enrol_wallet/expenders",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0;_exports.init=uniqid=>{var enrolWalletPolicyUrl=document.getElementById("enrol_wallet_transactions-policy-url-"+uniqid);enrolWalletPolicyUrl&&enrolWalletPolicyUrl.addEventListener("click",(function(){var policy=document.getElementById("enrol_wallet_transactions-policy-"+uniqid);"none"===policy.style.display?policy.style.display="block":policy.style.display="none"}));var moreBalanceDetails=document.getElementById("more-details-"+uniqid);moreBalanceDetails&&moreBalanceDetails.addEventListener("click",(function(){var details=document.getElementById("balance-details-"+uniqid);"none"===details.style.display?details.style.display="flex":details.style.display="none"}))}})); +define("enrol_wallet/expenders",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0;_exports.init=uniqid=>{var enrolWalletPolicyUrl=document.getElementById("enrol_wallet_transactions-policy-url-"+uniqid),policy=document.getElementById("enrol_wallet_transactions-policy-"+uniqid);enrolWalletPolicyUrl&&policy&&enrolWalletPolicyUrl.addEventListener("click",(function(){"none"===policy.style.display?policy.style.display="block":policy.style.display="none"}));var moreBalanceDetails=document.getElementById("more-details-"+uniqid),details=document.getElementById("balance-details-"+uniqid);moreBalanceDetails&&details&&moreBalanceDetails.addEventListener("click",(function(){"none"===details.style.display?details.style.display="flex":details.style.display="none"}));var walletPolicyAgreed=document.getElementById("wallet_topup_policy_confirm_"+uniqid),topUpBox=document.getElementById("enrol_wallet_topup_box_"+uniqid);if(walletPolicyAgreed&&topUpBox){setTimeout((function(){showHideTopUp()})),walletPolicyAgreed.addEventListener("change",(function(){showHideTopUp()}));const showHideTopUp=()=>{1==walletPolicyAgreed.checked?topUpBox.style.display="block":topUpBox.style.display="none"}}}})); //# sourceMappingURL=expenders.min.js.map \ No newline at end of file diff --git a/amd/build/expenders.min.js.map b/amd/build/expenders.min.js.map index c1469e55..bf48a9a9 100644 --- a/amd/build/expenders.min.js.map +++ b/amd/build/expenders.min.js.map @@ -1 +1 @@ -{"version":3,"file":"expenders.min.js","sources":["../src/expenders.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 expenders\n *\n * @module enrol_wallet/expenders\n * @copyright 2024 Mohammad Farouk \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nexport const init = (uniqid) => {\n var enrolWalletPolicyUrl = document.getElementById('enrol_wallet_transactions-policy-url-' + uniqid);\n if (enrolWalletPolicyUrl) {\n enrolWalletPolicyUrl.addEventListener(\"click\", function() {\n var policy = document.getElementById('enrol_wallet_transactions-policy-' + uniqid);\n if (policy.style.display === \"none\") {\n policy.style.display = \"block\";\n } else {\n policy.style.display = \"none\";\n }\n });\n }\n var moreBalanceDetails = document.getElementById('more-details-' + uniqid);\n if (moreBalanceDetails) {\n moreBalanceDetails.addEventListener(\"click\", function() {\n var details = document.getElementById('balance-details-' + uniqid);\n if (details.style.display === \"none\") {\n details.style.display = \"flex\";\n } else {\n details.style.display = \"none\";\n }\n });\n }\n};"],"names":["uniqid","enrolWalletPolicyUrl","document","getElementById","addEventListener","policy","style","display","moreBalanceDetails","details"],"mappings":"2JAuBqBA,aACbC,qBAAuBC,SAASC,eAAe,wCAA0CH,QACzFC,sBACAA,qBAAqBG,iBAAiB,SAAS,eACvCC,OAASH,SAASC,eAAe,oCAAsCH,QAC9C,SAAzBK,OAAOC,MAAMC,QACbF,OAAOC,MAAMC,QAAU,QAEvBF,OAAOC,MAAMC,QAAU,cAI/BC,mBAAqBN,SAASC,eAAe,gBAAkBH,QAC/DQ,oBACAA,mBAAmBJ,iBAAiB,SAAS,eACrCK,QAAUP,SAASC,eAAe,mBAAqBH,QAC7B,SAA1BS,QAAQH,MAAMC,QACdE,QAAQH,MAAMC,QAAU,OAExBE,QAAQH,MAAMC,QAAU"} \ No newline at end of file +{"version":3,"file":"expenders.min.js","sources":["../src/expenders.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 expenders\n *\n * @module enrol_wallet/expenders\n * @copyright 2024 Mohammad Farouk \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nexport const init = (uniqid) => {\n // Manual refund policy.\n var enrolWalletPolicyUrl = document.getElementById('enrol_wallet_transactions-policy-url-' + uniqid);\n var policy = document.getElementById('enrol_wallet_transactions-policy-' + uniqid);\n if (enrolWalletPolicyUrl && policy) {\n enrolWalletPolicyUrl.addEventListener(\"click\", function() {\n if (policy.style.display === \"none\") {\n policy.style.display = \"block\";\n } else {\n policy.style.display = \"none\";\n }\n });\n }\n\n // More balance details.\n var moreBalanceDetails = document.getElementById('more-details-' + uniqid);\n var details = document.getElementById('balance-details-' + uniqid);\n if (moreBalanceDetails && details) {\n moreBalanceDetails.addEventListener(\"click\", function() {\n if (details.style.display === \"none\") {\n details.style.display = \"flex\";\n } else {\n details.style.display = \"none\";\n }\n });\n }\n\n // Show top up options after confirm the agreement.\n var walletPolicyAgreed = document.getElementById('wallet_topup_policy_confirm_' + uniqid);\n var topUpBox = document.getElementById('enrol_wallet_topup_box_' + uniqid);\n if (walletPolicyAgreed && topUpBox) {\n // As the user may click the check box while the page not loaded yet.\n setTimeout(function() {\n showHideTopUp();\n });\n\n walletPolicyAgreed.addEventListener('change', function() {\n showHideTopUp();\n });\n\n const showHideTopUp = () => {\n if (walletPolicyAgreed.checked == true) {\n topUpBox.style.display = 'block';\n } else {\n topUpBox.style.display = 'none';\n }\n };\n }\n};"],"names":["uniqid","enrolWalletPolicyUrl","document","getElementById","policy","addEventListener","style","display","moreBalanceDetails","details","walletPolicyAgreed","topUpBox","setTimeout","showHideTopUp","checked"],"mappings":"2JAuBqBA,aAEbC,qBAAuBC,SAASC,eAAe,wCAA0CH,QACzFI,OAASF,SAASC,eAAe,oCAAsCH,QACvEC,sBAAwBG,QACxBH,qBAAqBI,iBAAiB,SAAS,WACd,SAAzBD,OAAOE,MAAMC,QACbH,OAAOE,MAAMC,QAAU,QAEvBH,OAAOE,MAAMC,QAAU,cAM/BC,mBAAqBN,SAASC,eAAe,gBAAkBH,QAC/DS,QAAUP,SAASC,eAAe,mBAAqBH,QACvDQ,oBAAsBC,SACtBD,mBAAmBH,iBAAiB,SAAS,WACX,SAA1BI,QAAQH,MAAMC,QACdE,QAAQH,MAAMC,QAAU,OAExBE,QAAQH,MAAMC,QAAU,cAMhCG,mBAAqBR,SAASC,eAAe,+BAAiCH,QAC9EW,SAAWT,SAASC,eAAe,0BAA4BH,WAC/DU,oBAAsBC,SAAU,CAEhCC,YAAW,WACPC,mBAGJH,mBAAmBL,iBAAiB,UAAU,WAC1CQ,yBAGEA,cAAgB,KACgB,GAA9BH,mBAAmBI,QACnBH,SAASL,MAAMC,QAAU,QAEzBI,SAASL,MAAMC,QAAU"} \ No newline at end of file diff --git a/amd/src/balance.js b/amd/src/balance.js index 15b899ed..6a9df676 100644 --- a/amd/src/balance.js +++ b/amd/src/balance.js @@ -56,6 +56,7 @@ function getData() { }); } } + export const init = (formid) => { form = document.getElementById(formid); holder = form.querySelector("[data-purpose=balance-holder]"); diff --git a/amd/src/expenders.js b/amd/src/expenders.js index 80ad7355..4c618e3c 100644 --- a/amd/src/expenders.js +++ b/amd/src/expenders.js @@ -22,10 +22,11 @@ */ export const init = (uniqid) => { + // Manual refund policy. var enrolWalletPolicyUrl = document.getElementById('enrol_wallet_transactions-policy-url-' + uniqid); - if (enrolWalletPolicyUrl) { + var policy = document.getElementById('enrol_wallet_transactions-policy-' + uniqid); + if (enrolWalletPolicyUrl && policy) { enrolWalletPolicyUrl.addEventListener("click", function() { - var policy = document.getElementById('enrol_wallet_transactions-policy-' + uniqid); if (policy.style.display === "none") { policy.style.display = "block"; } else { @@ -33,10 +34,12 @@ export const init = (uniqid) => { } }); } + + // More balance details. var moreBalanceDetails = document.getElementById('more-details-' + uniqid); - if (moreBalanceDetails) { + var details = document.getElementById('balance-details-' + uniqid); + if (moreBalanceDetails && details) { moreBalanceDetails.addEventListener("click", function() { - var details = document.getElementById('balance-details-' + uniqid); if (details.style.display === "none") { details.style.display = "flex"; } else { @@ -44,4 +47,26 @@ export const init = (uniqid) => { } }); } + + // Show top up options after confirm the agreement. + var walletPolicyAgreed = document.getElementById('wallet_topup_policy_confirm_' + uniqid); + var topUpBox = document.getElementById('enrol_wallet_topup_box_' + uniqid); + if (walletPolicyAgreed && topUpBox) { + // As the user may click the check box while the page not loaded yet. + setTimeout(function() { + showHideTopUp(); + }); + + walletPolicyAgreed.addEventListener('change', function() { + showHideTopUp(); + }); + + const showHideTopUp = () => { + if (walletPolicyAgreed.checked == true) { + topUpBox.style.display = 'block'; + } else { + topUpBox.style.display = 'none'; + } + }; + } }; \ No newline at end of file diff --git a/classes/api/instance.php b/classes/api/instance.php index d143e6b7..e492c70b 100644 --- a/classes/api/instance.php +++ b/classes/api/instance.php @@ -31,7 +31,7 @@ */ class instance extends external_api { /** - * Returns description of get_balance_details() parameters + * Returns description of get_cost() parameters * * @return external_function_parameters */ @@ -43,7 +43,7 @@ public static function get_cost_parameters() { } /** - * Returns the balance details for a single user. + * Returns the cost of an instance to the given user. * * @param int $instanceid * @param int $userid @@ -60,7 +60,7 @@ public static function get_cost($instanceid, $userid) { } /** - * Returns description of get_balance_details() result value. + * Returns description of get_cost() result value. * * @return external_single_structure */ diff --git a/classes/api/offers_form.php b/classes/api/offers_form.php index 14628a16..d16d3a01 100644 --- a/classes/api/offers_form.php +++ b/classes/api/offers_form.php @@ -24,15 +24,15 @@ use enrol_wallet\util\offers; /** - * Class balance_op + * Class offers form. * * @package enrol_wallet - * @copyright 2024 2024, Mohammad Farouk + * @copyright 2024 Mohammad Farouk * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class offers_form extends external_api { /** - * Returns description of get_balance_details() parameters + * Returns description of get_form_fragment() parameters * * @return external_function_parameters */ @@ -45,7 +45,7 @@ public static function get_form_fragment_parameters() { } /** - * Returns the balance details for a single user. + * Return an html fragment of form elements used in offers editing. * * @param string $type * @param int $increment @@ -65,7 +65,7 @@ public static function get_form_fragment($type, $increment, $courseid) { } /** - * Returns description of get_balance_details() result value. + * Returns description of get_form_fragment() result value. * * @return external_description */ diff --git a/classes/category/operations.php b/classes/category/operations.php index 989099e3..e091dce5 100644 --- a/classes/category/operations.php +++ b/classes/category/operations.php @@ -190,8 +190,9 @@ public function add($amount, $refundable = true, $free = false) { 'refundable' => $this->details[$this->catid]->refundable ?? 0, 'nonrefundable' => $this->details[$this->catid]->nonrefundable ?? 0, 'free' => $this->details[$this->catid]->free ?? 0, - 'balance' => $this->details[$this->catid]->balance ?? 0, ]; + $catobj->balance = $this->details[$this->catid]->balance + ?? $catobj->refundable + $catobj->nonrefundable; if ($refundable) { $this->refundable += $amount; $catobj->refundable += $amount; diff --git a/classes/form/transfer_form.php b/classes/form/transfer_form.php index 03dcec42..0ce80b3c 100644 --- a/classes/form/transfer_form.php +++ b/classes/form/transfer_form.php @@ -99,7 +99,8 @@ protected function definition() { $category = core_course_category::get($id, IGNORE_MISSING); if (!empty($category)) { $name = $category->get_nested_name(false); - $mform->addElement('static', 'cat'.$id, $name, number_format($obj->balance, 2)); + $catbalance = $obj->balance ?? $obj->refundable + $obj->nonrefundable; + $mform->addElement('static', 'cat'.$id, $name, number_format($catbalance, 2)); $options[$id] = $name; } } diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index 847eb6aa..232e0e4d 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -96,7 +96,7 @@ public static function get_metadata(collection $collection): collection { "nonrefundable" => "privacy:metadata:enrol_wallet_balance:nonrefundable", 'cat_balance' => "privacy:metadata:enrol_wallet_balance:catbalance", 'freegift' => "privacy:metadata:enrol_wallet_balance:freegift", - ], "privacy:metadata:enrol_wallet_balance",); + ], "privacy:metadata:enrol_wallet_balance"); $collection->add_database_table('enrol_wallet_cond_discount', [ 'usermodified' => "privacy:metadata:enrol_wallet_cond_discount:usermodified", diff --git a/classes/util/balance.php b/classes/util/balance.php index d80ffcc5..17793db4 100644 --- a/classes/util/balance.php +++ b/classes/util/balance.php @@ -123,6 +123,8 @@ public function __construct($userid = 0, $category = 0) { if (!empty($this->catid) && $this->catid > 0) { $this->catop = new operations($this->catid, $this->userid); } + } else { + $this->catid = 0; } $this->set_details_from_cache(); @@ -260,8 +262,8 @@ protected function update_record() { private function format_cat_balance() { $catbalance = []; foreach ($this->details['catbalance'] as $id => $obj) { - unset($obj->balance); $catbalance[$id] = $obj; + unset($catbalance[$id]->balance); } return json_encode($catbalance); } diff --git a/classes/util/balance_op.php b/classes/util/balance_op.php index d0f9540e..ed4c93d8 100644 --- a/classes/util/balance_op.php +++ b/classes/util/balance_op.php @@ -169,13 +169,13 @@ class balance_op extends balance { public function __construct($userid = 0, $category = 0) { parent::__construct($userid, $category); if (empty($category)) { - unset($this->catid); + $this->catid = 0; unset($this->catop); } } /** - * Cut amount from the main balance, this is not checking for negative blance. + * Cut amount from the main balance, this is not checking for negative balance. * Which means that the balance could be negative, so before using this validate if the new balance * could be negative of not. * @@ -818,7 +818,7 @@ private function trigger_transaction_event($type, $charger, $desc, $refundable) 'type' => $type, 'amount' => $this->amount, 'refundable' => $refundable, - 'freecut' => $type === self::DEBIT ? $this->get_free_cut() : 0, + 'freecut' => $type === self::DEBIT ? $this->get_free_cut(false) : 0, 'desc' => $desc, ], ]; @@ -909,6 +909,15 @@ public function transfer_to_other($data, $mform = null) { $amount = $data->amount; $catid = $data->category ?? 0; + if ($this->catid != $catid) { + $this->catid = $catid; + if (!empty($this->catid)) { + $this->catop = new operations($this->catid, $this->userid); + } else { + unset($this->catop); + } + } + $receiver = \core_user::get_user_by_email($email); list($debit, $credit) = $mform->get_debit_credit($amount); @@ -920,6 +929,7 @@ public function transfer_to_other($data, $mform = null) { return $unknownerror; } + $this->get_free_cut(); // Credit the receiver. $a = [ 'fee' => $fee, diff --git a/lang/en/enrol_wallet.php b/lang/en/enrol_wallet.php index a79f53d8..f485fd4f 100644 --- a/lang/en/enrol_wallet.php +++ b/lang/en/enrol_wallet.php @@ -352,7 +352,7 @@ $string['fixedcoupondisabled'] = 'Fixed value coupons are disabled in this website.'; $string['fixedvaluecoupon'] = 'Fixed value coupon'; $string['freecourses'] = 'Free courses in this website'; -$string['frontpageoffers'] = 'Offers page link in frontpage navegation'; +$string['frontpageoffers'] = 'Offers page link in frontpage navigation'; $string['frontpageoffers_desc'] = 'Add a link to offers page in front page navigation'; @@ -473,7 +473,7 @@ $string['paymentaccount'] = 'Payment account'; $string['paymentaccount_help'] = 'choose the payment account in which you will accept payments'; $string['paymentrequired'] = 'You can pay for this course directly using available payment methods'; -$string['paymenttopup_desc'] = 'Payment to topup the wallet'; +$string['paymenttopup_desc'] = 'Payment to top up the wallet'; $string['percentcoupondisabled'] = 'Discount coupons disabled in this website.'; $string['percentdiscountcoupon'] = 'Percentage discount coupon'; $string['pluginname'] = 'Wallet enrolment'; @@ -555,7 +555,7 @@ $string['referral_program_desc'] = 'Existence users can refer new user to join this website and both receive a referral gift.'; $string['referral_remain'] = 'Remained Referrals.'; $string['referral_remain_help'] = 'Remained times available to receive the referral gift.'; -$string['referral_site_desc'] = 'This site has a referral program, where you can send the referal code to your friend and when join us in at least one of our course both will get a gift on your wallets, for more information '; +$string['referral_site_desc'] = 'This site has a referral program, where you can send the referral code to your friend and when join us in at least one of our course both will get a gift on your wallets, for more information '; $string['referral_timecreated'] = 'Signed up time'; $string['referral_timereleased'] = 'Gifted at:'; $string['referral_topup'] = 'Due to referral for user: {$a}.'; @@ -576,13 +576,13 @@ $string['refunduponunenrol_desc'] = 'Refunded by amount of {$a->credit} after deduction un-enrol fee of {$a->fee} in the course: {$a->coursename}.'; $string['repurchase'] = 'Repurchase'; $string['repurchase_desc'] = 'Settings for repurchase the courses. If enabled, the users can repurchase the lectures again after the enrol date end.'; -$string['repurchase_firstdis'] = 'First Repurchase Discount'; +$string['repurchase_firstdis'] = 'First repurchase discount'; $string['repurchase_firstdis_desc'] = 'If specified, the users will get discount by this percentage value (0 - 100) for the second time they purchase the course.'; -$string['repurchase_seconddis'] = 'Second Repurchase Discount'; +$string['repurchase_seconddis'] = 'Second repurchase discount'; $string['repurchase_seconddis_desc'] = 'For the third time the users purchase (second repurchase) the course, they will get discounted by this value. (should be between 0 - 100)'; $string['restrictionenabled'] = 'Enable restriction.'; $string['restrictionenabled_desc'] = 'If disabled, not restrictions will be checked.'; -$string['restrictions'] = 'Enrolment Restrictions'; +$string['restrictions'] = 'Enrolment restrictions'; $string['restrictions_desc'] = 'Like sections and course modules, now Wallet Enrollments offers an option to add restriction to the enrolment, not all availability plugins tested well, so you can choose from here what works fine and please report ant error so we can improve this functionality.'; $string['role'] = 'Default assigned role'; @@ -602,7 +602,7 @@ $string['sourcemoodle'] = 'Internal moodle wallet'; $string['sourcewordpress'] = 'External Tera-wallet (WooWallet)'; $string['status'] = 'Allow existing enrollments'; -$string['status_desc'] = 'Enable Wallet enrolment method in new courses.'; +$string['status_desc'] = 'Enable wallet enrolment method in new courses.'; $string['status_help'] = 'If enabled together with \'Allow new enrollments\' disabled, only users who enrolled previously can access the course. If disabled, this enrolment method is effectively disabled, since all existing enrollments are suspended and new users cannot enrol.'; $string['submit_coupongenerator'] = 'Create'; $string['syncenrolmentstask'] = 'Wallet enrolment synchronize enrollments task'; @@ -611,22 +611,22 @@ $string['tellermen'] = 'Teller men to be displayed'; $string['tellermen_desc'] = 'Users selected here will be public displayed on the topping up options to let users know who to ask to charging their wallets. (Select none will display nothing)'; $string['tellermen_display_guide'] = 'Need help charging your wallet? Ask one of our wallet administrator to charge your wallet manually or to assist you with the procedure.'; -$string['tellermen_heading'] = 'Teller Men'; +$string['tellermen_heading'] = 'Teller men'; $string['tellermen_heading_desc'] = 'All users with capabilities to credit or debit users wallets, this determine whom will be displayed on the topup form to let users know who to as for charging their wallets'; $string['topup'] = 'topup'; $string['topupafterdiscount'] = 'Actual payment'; $string['topupafterdiscount_help'] = 'The amount after discount.'; $string['topupbycoupon'] = 'Using Coupons'; $string['topupbypayment'] = 'Using Payment'; -$string['topupbytellerman'] = 'Manually from ourside'; +$string['topupbytellerman'] = 'Manually from our side'; $string['topupbyvc'] = 'Using transfer to mobile wallet or instapay'; $string['topupcoupon_desc'] = 'by coupon code {$a}'; -$string['topupoffers'] = 'Wallet Topping Up offers'; +$string['topupoffers'] = 'Wallet topping up offers'; $string['topupoffers_desc'] = 'By topping up your wallet by one or greater than the given values you will be discounted by the specified amount and only have to pay less than this amount by this percentage value.'; $string['topuppayment_desc'] = 'Topping up the wallet by payment of {$a} using payment gateway.'; -$string['topupvalue'] = 'TopUp Value'; +$string['topupvalue'] = 'TopUp value'; $string['topupvalue_help'] = 'Value to topup your wallet by using payment methods'; -$string['transactions'] = 'Wallet Transactions'; +$string['transactions'] = 'Wallet transactions'; $string['transaction_perpage'] = 'Transactions per page'; $string['transaction_type'] = 'Type of transaction'; $string['transfer'] = 'Transfer balance to other user'; @@ -649,37 +649,37 @@ $string['turn_not_refundable_task'] = 'Turn balance to non-refundable.'; -$string['unenrol'] = 'Unenrol user'; -$string['unenrollimitafter'] = 'Cannot unenrol self after:'; +$string['unenrol'] = 'Un-enrol user'; +$string['unenrollimitafter'] = 'Cannot un-enrol self after:'; $string['unenrollimitafter_desc'] = 'Users cannot enrol themselves after this period from enrolment start date. 0 means unlimited.'; -$string['unenrollimitbefor'] = 'Cannot unenrol self before:'; -$string['unenrollimitbefor_desc'] = 'Users cannot unenrol themselves before this period from enrolment end date. 0 means no limit.'; -$string['unenrolrefund'] = 'Refund upon unenrol?'; +$string['unenrollimitbefor'] = 'Cannot un-enrol self before:'; +$string['unenrollimitbefor_desc'] = 'Users cannot un-enrol themselves before this period from enrolment end date. 0 means no limit.'; +$string['unenrolrefund'] = 'Refund upon un-enrol?'; $string['unenrolrefundfee'] = 'Refund percentage fee'; -$string['unenrolrefundfee_desc'] = 'Choose a percentage amount that will not be refunded after unenrol as a fee.'; -$string['unenrolrefundperiod'] = 'Refund upon unenrol grace period'; +$string['unenrolrefundfee_desc'] = 'Choose a percentage amount that will not be refunded after un-enrol as a fee.'; +$string['unenrolrefundperiod'] = 'Refund upon un-enrol grace period'; $string['unenrolrefundperiod_desc'] = 'If the user unenrolled within this period from the enrol start date he will be refunded.'; -$string['unenrolrefundpolicy'] = 'Unenrol Refunding Policy'; -$string['unenrolrefundpolicy_default'] = '

Conditions for refunding upon unenrol:

+$string['unenrolrefundpolicy'] = 'Un-enrol refunding policy'; +$string['unenrolrefundpolicy_default'] = '

Conditions for refunding upon un-enrol:

If you are unenrolled from the course within {period} days from the start date you will be refunded with the amount you pay after deducting a {fee}% from the paid amount. This amount will return to your wallet and can use it to enrol in other courses but not be able to be manually refunded.
By pressing purchase means you have agreed to these conditions.

'; -$string['unenrolrefundpolicy_help'] = 'If refunding upon unenrol enabled, this policy will be visible to users before enrol themselves to courses using wallet enrolment.
+$string['unenrolrefundpolicy_help'] = 'If refunding upon un-enrol enabled, this policy will be visible to users before enrol themselves to courses using wallet enrolment.
placing {fee} in the policy will be replaced by the percentage fee.
placing {period} will be replaced by the grace period in days.'; $string['unenrolrefund_desc'] = 'If enabled, users will be refunded if they unenrolled from the course.'; -$string['unenrolrefund_head'] = 'Refund users upon unenrol.'; -$string['unenrolrefund_head_desc'] = 'Return the paid fee of a course after unenrol from the course.'; -$string['unenrolselfconfirm'] = 'Do you really want to unenrol yourself from course "{$a}"?'; -$string['unenrolselfenabled'] = 'Enable self unenrol'; -$string['unenrolselfenabled_desc'] = 'If enable, then users are allowed to unenrol themselves from the course.'; -$string['unenrolself_notallowed'] = 'You are not unenrol yourself from this course.'; -$string['unenroluser'] = 'Do you really want to unenrol "{$a->user}" from course "{$a->course}"?'; -$string['unenrolusers'] = 'Unenrol users'; +$string['unenrolrefund_head'] = 'Refund users upon un-enrol.'; +$string['unenrolrefund_head_desc'] = 'Return the paid fee of a course after un-enrol from the course.'; +$string['unenrolselfconfirm'] = 'Do you really want to un-enrol yourself from course "{$a}"?'; +$string['unenrolselfenabled'] = 'Enable self un-enrol'; +$string['unenrolselfenabled_desc'] = 'If enable, then users are allowed to un-enrol themselves from the course.'; +$string['unenrolself_notallowed'] = 'You are not un-enrol yourself from this course.'; +$string['unenroluser'] = 'Do you really want to un-enrol "{$a->user}" from course "{$a->course}"?'; +$string['unenrolusers'] = 'Un-enrol users'; $string['uploadcsvfilerequired'] = 'Please upload the csv file.'; -$string['upload_coupons'] = 'Upload Coupons'; +$string['upload_coupons'] = 'Upload coupons'; $string['upload_coupons_help'] = 'Upload coupons in a csv file to bulk add or edit wallet coupons, the csv file should contain two primary columns:
\'code\': The code of the coupon to be added or updated.
\'value\': The value of the coupon and may be left 0 only if the type is (enrol).
@@ -705,18 +705,18 @@ $string['wallet:bulkedit'] = 'Bulk edit the enrollments in all courses'; -$string['wallet:config'] = 'Configure Wallet enrol instances'; +$string['wallet:config'] = 'Configure wallet enrol instances'; $string['wallet:createcoupon'] = 'Creating wallet coupons'; -$string['wallet:creditdebit'] = 'Credit and Debit other users'; +$string['wallet:creditdebit'] = 'Credit and debit other users'; $string['wallet:deletecoupon'] = 'Deleting wallet coupon'; $string['wallet:downloadcoupon'] = 'Downloading wallet coupons'; -$string['wallet:editcoupon'] = 'Edit Coupons'; +$string['wallet:editcoupon'] = 'Edit coupons'; $string['wallet:enrolself'] = 'Purchase a course through enrol wallet instance'; $string['wallet:manage'] = 'Manage enrolled users'; $string['wallet:transaction'] = 'View the transaction table'; $string['wallet:transfer'] = 'Transfer wallet balance to another user'; -$string['wallet:unenrol'] = 'Unenrol users from course'; -$string['wallet:unenrolself'] = 'Unenrol self from the course'; +$string['wallet:unenrol'] = 'Un-enrol users from course'; +$string['wallet:unenrolself'] = 'Un-enrol self from the course'; $string['wallet:viewcoupon'] = 'View wallet coupons table'; $string['wallet:viewotherbalance'] = 'View the wallet balance of others'; $string['walletbulk'] = 'Wallet enrol instances bulk edit'; diff --git a/templates/manualpolicy.mustache b/templates/manualpolicy.mustache index f012384f..ef4ba3b2 100644 --- a/templates/manualpolicy.mustache +++ b/templates/manualpolicy.mustache @@ -41,26 +41,8 @@ {{/topup}} - {{#js}} - var urlPolicy = document.getElementById('enrol_wallet_transactions-policy-url-{{{id}}}'); - urlPolicy.addEventListener("click", function() { - var policy = document.getElementById('enrol_wallet_transactions-policy-{{{id}}}'); - if (policy.style.display === "none") { - policy.style.display = "block"; - } else { - policy.style.display = "none"; - } - }); - {{#topup}} - var walletPolicyAgreed = document.getElementById('wallet_topup_policy_confirm_{{id}}'); - walletPolicyAgreed.addEventListener('change', function() { - var topUpBox = document.getElementById('enrol_wallet_topup_box_{{id}}'); - if (walletPolicyAgreed.checked == true) { - topUpBox.style.display = 'block'; - } else { - topUpBox.style.display = 'none'; - } + require(['enrol_wallet/expenders'], function(ex) { + ex.init('{{id}}'); }); - {{/topup}} -{{/js}} \ No newline at end of file +{{/js}}