* @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}}