Skip to content

Commit

Permalink
Fix #28 increase the precisions of amounts fields
Browse files Browse the repository at this point in the history
  • Loading branch information
fmido88 authored Jun 16, 2024
1 parent 05ac4f3 commit 4628a87
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 16 deletions.
32 changes: 16 additions & 16 deletions db/install.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="enrol/wallet/db" VERSION="20240226" COMMENT="XMLDB file for Moodle enrol/wallet"
<XMLDB PATH="enrol/wallet/db" VERSION="20240616" COMMENT="XMLDB file for Moodle enrol/wallet"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
<TABLES>
<TABLE NAME="enrol_wallet_items" COMMENT="Fake items added to be purchased during wallet topup">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="cost" TYPE="number" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" DECIMALS="5" COMMENT="the price should be added"/>
<FIELD NAME="cost" TYPE="number" LENGTH="25" NOTNULL="true" DEFAULT="0" SEQUENCE="false" DECIMALS="5" COMMENT="the price should be added"/>
<FIELD NAME="currency" TYPE="char" LENGTH="3" NOTNULL="true" DEFAULT="EGP" SEQUENCE="false" COMMENT="the currency"/>
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="the id of the user doing the operation"/>
<FIELD NAME="instanceid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Enrol Instance id"/>
Expand All @@ -26,7 +26,7 @@
<FIELD NAME="grade" TYPE="number" LENGTH="10" NOTNULL="true" SEQUENCE="false" DECIMALS="5"/>
<FIELD NAME="maxgrade" TYPE="number" LENGTH="10" NOTNULL="true" SEQUENCE="false" DECIMALS="5"/>
<FIELD NAME="percent" TYPE="number" LENGTH="10" NOTNULL="true" SEQUENCE="false" DECIMALS="5"/>
<FIELD NAME="amount" TYPE="number" LENGTH="10" NOTNULL="true" SEQUENCE="false" DECIMALS="5"/>
<FIELD NAME="amount" TYPE="number" LENGTH="25" NOTNULL="true" SEQUENCE="false" DECIMALS="5"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
</FIELDS>
<KEYS>
Expand All @@ -38,12 +38,12 @@
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="type" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="amount" TYPE="number" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" DECIMALS="5"/>
<FIELD NAME="balbefore" TYPE="number" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" DECIMALS="5"/>
<FIELD NAME="balance" TYPE="number" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" DECIMALS="5"/>
<FIELD NAME="norefund" TYPE="number" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" DECIMALS="5"/>
<FIELD NAME="amount" TYPE="number" LENGTH="25" NOTNULL="true" DEFAULT="0" SEQUENCE="false" DECIMALS="5"/>
<FIELD NAME="balbefore" TYPE="number" LENGTH="25" NOTNULL="true" DEFAULT="0" SEQUENCE="false" DECIMALS="5"/>
<FIELD NAME="balance" TYPE="number" LENGTH="25" NOTNULL="true" DEFAULT="0" SEQUENCE="false" DECIMALS="5"/>
<FIELD NAME="norefund" TYPE="number" LENGTH="25" NOTNULL="true" DEFAULT="0" SEQUENCE="false" DECIMALS="5"/>
<FIELD NAME="category" TYPE="int" LENGTH="10" NOTNULL="false" DEFAULT="0" SEQUENCE="false" COMMENT="The category id if the transaction done for a category balance"/>
<FIELD NAME="descripe" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="descripe" TYPE="char" LENGTH="1333" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
</FIELDS>
<KEYS>
Expand All @@ -55,7 +55,7 @@
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="code" TYPE="char" LENGTH="20" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="type" TYPE="char" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="value" TYPE="number" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" DECIMALS="5"/>
<FIELD NAME="value" TYPE="number" LENGTH="25" NOTNULL="true" DEFAULT="0" SEQUENCE="false" DECIMALS="5"/>
<FIELD NAME="category" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="courses" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="maxusage" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
Expand All @@ -76,7 +76,7 @@
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="code" TYPE="char" LENGTH="20" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="type" TYPE="char" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="value" TYPE="number" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" DECIMALS="5"/>
<FIELD NAME="value" TYPE="number" LENGTH="25" NOTNULL="true" DEFAULT="0" SEQUENCE="false" DECIMALS="5"/>
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="instanceid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="timeused" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
Expand All @@ -88,12 +88,12 @@
<TABLE NAME="enrol_wallet_cond_discount" COMMENT="Data for conditional discounts in the website.">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="cond" TYPE="number" LENGTH="10" NOTNULL="true" SEQUENCE="false" DECIMALS="5"/>
<FIELD NAME="cond" TYPE="number" LENGTH="25" NOTNULL="true" SEQUENCE="false" DECIMALS="5"/>
<FIELD NAME="percent" TYPE="number" LENGTH="4" NOTNULL="true" SEQUENCE="false" DECIMALS="2"/>
<FIELD NAME="category" TYPE="int" LENGTH="10" NOTNULL="false" DEFAULT="0" SEQUENCE="false" COMMENT="The id of the category at which the conditional discount applied, 0 mean main balance discount"/>
<FIELD NAME="timefrom" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="timeto" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="bundle" TYPE="number" LENGTH="10" NOTNULL="false" SEQUENCE="false" DECIMALS="2" COMMENT="bundle for quick top up with the discount"/>
<FIELD NAME="bundle" TYPE="number" LENGTH="25" NOTNULL="false" SEQUENCE="false" DECIMALS="5" COMMENT="bundle for quick top up with the discount"/>
<FIELD NAME="bundledesc" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Additional description of the bundle"/>
<FIELD NAME="descformat" TYPE="int" LENGTH="1" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="usermodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
Expand Down Expand Up @@ -126,7 +126,7 @@
<FIELD NAME="referrer" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="referred" TYPE="char" LENGTH="225" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="amount" TYPE="number" LENGTH="10" NOTNULL="true" SEQUENCE="false" DECIMALS="5"/>
<FIELD NAME="amount" TYPE="number" LENGTH="25" NOTNULL="true" SEQUENCE="false" DECIMALS="5"/>
<FIELD NAME="released" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
Expand All @@ -140,9 +140,9 @@
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="refundable" TYPE="number" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" DECIMALS="2" COMMENT="The main refundable balance"/>
<FIELD NAME="nonrefundable" TYPE="number" LENGTH="10" NOTNULL="false" DEFAULT="0" SEQUENCE="false" DECIMALS="2" COMMENT="The nonrefundable main balance"/>
<FIELD NAME="freegift" TYPE="number" LENGTH="10" NOTNULL="false" DEFAULT="0" SEQUENCE="false" DECIMALS="2" COMMENT="free balance added from gift or so"/>
<FIELD NAME="refundable" TYPE="number" LENGTH="25" NOTNULL="true" DEFAULT="0" SEQUENCE="false" DECIMALS="5" COMMENT="The main refundable balance"/>
<FIELD NAME="nonrefundable" TYPE="number" LENGTH="25" NOTNULL="false" DEFAULT="0" SEQUENCE="false" DECIMALS="5" COMMENT="The nonrefundable main balance"/>
<FIELD NAME="freegift" TYPE="number" LENGTH="25" NOTNULL="false" DEFAULT="0" SEQUENCE="false" DECIMALS="5" COMMENT="free balance added from gift or so"/>
<FIELD NAME="cat_balance" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="The category balance details, json data keyed with category id"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
Expand Down
99 changes: 99 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,5 +363,104 @@ function xmldb_enrol_wallet_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2024022619, 'enrol', 'wallet');
}

// Changing all precisions of fields handle cost, balance, ..
if ($oldversion < 2024061600) {

// Changing precision of field cost on table enrol_wallet_items to (25, 5).
$table = new xmldb_table('enrol_wallet_items');
$field = new xmldb_field('cost', XMLDB_TYPE_NUMBER, '25, 5', null, XMLDB_NOTNULL, null, '0', 'id');

// Launch change of precision for field cost.
$dbman->change_field_precision($table, $field);

// Changing precision of field amount on table enrol_wallet_awards to (25, 5).
$table = new xmldb_table('enrol_wallet_awards');
$field = new xmldb_field('amount', XMLDB_TYPE_NUMBER, '25, 5', null, XMLDB_NOTNULL, null, null, 'percent');

// Launch change of precision for field amount.
$dbman->change_field_precision($table, $field);

// Changing precision of field amount on table enrol_wallet_transactions to (25, 5).
$table = new xmldb_table('enrol_wallet_transactions');
$field = new xmldb_field('amount', XMLDB_TYPE_NUMBER, '25, 5', null, XMLDB_NOTNULL, null, '0', 'type');

// Launch change of precision for field amount.
$dbman->change_field_precision($table, $field);
// Changing precision of field balbefore on table enrol_wallet_transactions to (25, 5).

$field = new xmldb_field('balbefore', XMLDB_TYPE_NUMBER, '25, 5', null, XMLDB_NOTNULL, null, '0', 'amount');

// Launch change of precision for field balbefore.
$dbman->change_field_precision($table, $field);
// Changing precision of field balance on table enrol_wallet_transactions to (25, 5).

$field = new xmldb_field('balance', XMLDB_TYPE_NUMBER, '25, 5', null, XMLDB_NOTNULL, null, '0', 'balbefore');

// Launch change of precision for field balance.
$dbman->change_field_precision($table, $field);
// Changing precision of field norefund on table enrol_wallet_transactions to (25, 5).
$field = new xmldb_field('norefund', XMLDB_TYPE_NUMBER, '25, 5', null, XMLDB_NOTNULL, null, '0', 'balance');

// Launch change of precision for field norefund.
$dbman->change_field_precision($table, $field);
// Changing precision of field descripe on table enrol_wallet_transactions to (1333).
$field = new xmldb_field('descripe', XMLDB_TYPE_CHAR, '1333', null, null, null, null, 'category');

// Launch change of precision for field descripe.
$dbman->change_field_precision($table, $field);

// Changing precision of field value on table enrol_wallet_coupons to (25, 5).
$table = new xmldb_table('enrol_wallet_coupons');
$field = new xmldb_field('value', XMLDB_TYPE_NUMBER, '25, 5', null, XMLDB_NOTNULL, null, '0', 'type');

// Launch change of precision for field value.
$dbman->change_field_precision($table, $field);

// Changing precision of field value on table enrol_wallet_coupons_usage to (25, 5).
$table = new xmldb_table('enrol_wallet_coupons_usage');
$field = new xmldb_field('value', XMLDB_TYPE_NUMBER, '25, 5', null, XMLDB_NOTNULL, null, '0', 'type');

// Launch change of precision for field value.
$dbman->change_field_precision($table, $field);

// Changing precision of field cond on table enrol_wallet_cond_discount to (25, 5).
$table = new xmldb_table('enrol_wallet_cond_discount');
$field = new xmldb_field('cond', XMLDB_TYPE_NUMBER, '25, 5', null, XMLDB_NOTNULL, null, null, 'id');

// Launch change of precision for field cond.
$dbman->change_field_precision($table, $field);
// Changing precision of field bundle on table enrol_wallet_cond_discount to (25, 5).
$field = new xmldb_field('bundle', XMLDB_TYPE_NUMBER, '25, 5', null, null, null, null, 'timeto');

// Launch change of precision for field bundle.
$dbman->change_field_precision($table, $field);

// Changing precision of field amount on table enrol_wallet_hold_gift to (25, 5).
$table = new xmldb_table('enrol_wallet_hold_gift');
$field = new xmldb_field('amount', XMLDB_TYPE_NUMBER, '25, 5', null, XMLDB_NOTNULL, null, null, 'courseid');

// Launch change of precision for field amount.
$dbman->change_field_precision($table, $field);

// Changing precision of field refundable on table enrol_wallet_balance to (25, 5).
$table = new xmldb_table('enrol_wallet_balance');
$field = new xmldb_field('refundable', XMLDB_TYPE_NUMBER, '25, 5', null, XMLDB_NOTNULL, null, '0', 'userid');

// Launch change of precision for field refundable.
$dbman->change_field_precision($table, $field);
// Changing precision of field nonrefundable on table enrol_wallet_balance to (25, 5).
$field = new xmldb_field('nonrefundable', XMLDB_TYPE_NUMBER, '25, 5', null, null, null, '0', 'refundable');

// Launch change of precision for field nonrefundable.
$dbman->change_field_precision($table, $field);

// Changing precision of field freegift on table enrol_wallet_balance to (25, 5).
$field = new xmldb_field('freegift', XMLDB_TYPE_NUMBER, '25, 5', null, null, null, '0', 'nonrefundable');

// Launch change of precision for field freegift.
$dbman->change_field_precision($table, $field);
// Wallet savepoint reached.
upgrade_plugin_savepoint(true, 2024061600, 'enrol', 'wallet');
}
return true;
}

0 comments on commit 4628a87

Please sign in to comment.