MDL-18011 - removing loancalc block from HEAD (2.0) and moving to contrib
This commit is contained in:
@@ -1,203 +0,0 @@
|
||||
<?php
|
||||
|
||||
class block_loancalc extends block_base {
|
||||
|
||||
function init() {
|
||||
$this->title = get_string('pluginname','block_loancalc');
|
||||
$this->content_type = BLOCK_TYPE_TEXT;
|
||||
$this->version = 2007101509;
|
||||
}
|
||||
|
||||
function get_content() {
|
||||
global $CFG, $OUTPUT;
|
||||
|
||||
$calc = $OUTPUT->pix_url('i/calc');
|
||||
|
||||
$this->content->text = '
|
||||
<script type="text/javascript">
|
||||
// <![CDATA[
|
||||
function Next()
|
||||
{
|
||||
submitScreen("Next");
|
||||
document.getElementById("vbankform").submit();
|
||||
}
|
||||
function Back()
|
||||
{
|
||||
submitScreen("Back");
|
||||
document.getElementById("vbankform").submit();
|
||||
}
|
||||
|
||||
function num_format(x) { // format numbers with two digits
|
||||
sgn = (x < 0);
|
||||
x = Math.abs(x);
|
||||
x = Math.floor((x * 100) + .5);
|
||||
i = 3;
|
||||
y = "";
|
||||
while(((i--) > 0) || (x > 0)) {
|
||||
y = (x % 10) + y;
|
||||
x = Math.floor(x / 10);
|
||||
if(i == 1) {
|
||||
y = "." + y;
|
||||
}
|
||||
}
|
||||
if(sgn) {
|
||||
y = "-" + y;
|
||||
}
|
||||
return(y);
|
||||
}
|
||||
function comp(v) { // general entry point for all cases
|
||||
|
||||
// convert all entry fields into variables
|
||||
x = document.getElementById("vbankform");
|
||||
pv = parseFloat(x.LOANAMOUNT.value);
|
||||
lpp = parseFloat(x.LOANPAYPERIOD[x.LOANPAYPERIOD.selectedIndex].value);
|
||||
if (isNaN(pv) && (v != "pv"))
|
||||
{
|
||||
x.LOANAMOUNT.select();
|
||||
x.LOANAMOUNT.focus();
|
||||
alert("Numbers only to be entered");
|
||||
return;
|
||||
}
|
||||
fv = parseFloat("0");
|
||||
yr = parseFloat(x.LOANTERM.value);
|
||||
if (isNaN(yr) && (v != "np"))
|
||||
{
|
||||
x.LOANTERM.select();
|
||||
x.LOANTERM.focus();
|
||||
alert("Numbers only to be entered");
|
||||
return;
|
||||
}
|
||||
np = lpp * yr;
|
||||
pmt = -parseFloat(x.LOANREPAYMENT.value);
|
||||
if (isNaN(pmt) && (v != "pmt"))
|
||||
{
|
||||
x.LOANREPAYMENT.select();
|
||||
x.LOANREPAYMENT.focus();
|
||||
alert("Numbers only to be entered");
|
||||
return;
|
||||
}
|
||||
if(x.LOANINTRATE.value == "") {
|
||||
alert("You must enter an interest rate (ir).");
|
||||
}
|
||||
else {
|
||||
ir = parseFloat(x.LOANINTRATE.value);
|
||||
if (isNaN(ir))
|
||||
{
|
||||
x.LOANINTRATE.select();
|
||||
x.LOANINTRATE.focus();
|
||||
alert("Numbers only to be entered");
|
||||
return;
|
||||
}
|
||||
ir = ((ir / lpp) / 100);
|
||||
|
||||
// test and compute all cases
|
||||
|
||||
if (v == "pv") {
|
||||
if(ir == 0) {
|
||||
pv = -(fv + (pmt * np));
|
||||
}
|
||||
else {
|
||||
q1 = Math.pow(1 + ir,-np);
|
||||
q2 = Math.pow(1 + ir,np);
|
||||
pv = -(q1 * (fv * ir - pmt + q2 * pmt))/ir;
|
||||
}
|
||||
x.LOANAMOUNT.value = num_format(pv);
|
||||
}
|
||||
|
||||
if (v == "np") {
|
||||
if(ir == 0) {
|
||||
if(pmt != 0) {
|
||||
np = - (fv + pv)/pmt;
|
||||
}
|
||||
else {
|
||||
alert("Divide by zero error.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
np = Math.log((-fv * ir + pmt)/(pmt + ir * pv))/ Math.log(1 + ir);
|
||||
}
|
||||
if(np == 0) {
|
||||
alert("Can\'t compute Number of Periods for the present values.");
|
||||
}
|
||||
else {
|
||||
np = (np / lpp)
|
||||
if (isNaN(np)) {
|
||||
alert("The repayment amount is less than the interest. You must increase your repayments to pay off this loan!");
|
||||
} else {
|
||||
x.LOANTERM.value = num_format(np);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (v == "pmt") {
|
||||
if(ir == 0.0) {
|
||||
if(np != 0) {
|
||||
pmt = (fv + pv)/np;
|
||||
}
|
||||
else {
|
||||
alert("Divide by zero error.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
q = Math.pow(1 + ir,np);
|
||||
pmt = ((ir * (fv + q * pv))/(-1 + q));
|
||||
}
|
||||
x.LOANREPAYMENT.value = num_format(pmt);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} // function comp
|
||||
//]]>
|
||||
</script>
|
||||
<form method="post" id="vbankform" action="">
|
||||
<table>
|
||||
<tr>
|
||||
<td colspan="2">'.get_string('amountofloan','block_loancalc').'</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><input name="LOANAMOUNT" id="LOANAMOUNT" size="17" /></td>
|
||||
<td><a href="JavaScript:comp(\'pv\');"><img src="'.$calc.'" alt="calculate" /></a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">'.get_string('repaymentamount','block_loancalc').'</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><input name="LOANREPAYMENT" id="LOANREPAYMENT" size="17" /></td>
|
||||
<td><a href="JavaScript:comp(\'pmt\');"><img src="'.$calc.'" alt="calculate" /></a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">'.get_string('loanterm','block_loancalc').'</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><input name="LOANTERM" id="LOANTERM" size="17" /></td>
|
||||
<td><a href="JavaScript:comp(\'np\');"><img src="'.$calc.'" alt="calculate" /></a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">'.get_string('interestrate','block_loancalc').'</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><input name="LOANINTRATE" id="LOANINTRATE" size="17" /></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">'.get_string('repaymentfreq','block_loancalc').'</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>';
|
||||
$options[52] = get_string('weekly','block_loancalc');
|
||||
$options[26] = get_string('fortnightly','block_loancalc');
|
||||
$options[12] = get_string('monthly','block_loancalc');
|
||||
$this->content->text .= html_writer::select($options,'LOANPAYPERIOD','12');
|
||||
$this->content->text .= '</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>';
|
||||
$this->content->footer = '';
|
||||
|
||||
return $this->content;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Strings for component 'block_loancalc', language 'en', branch 'MOODLE_20_STABLE'
|
||||
*
|
||||
* @package block_loancalc
|
||||
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['amountofloan'] = 'Amount of loan';
|
||||
$string['fortnightly'] = 'Fortnightly';
|
||||
$string['interestrate'] = 'Interest rate';
|
||||
$string['loanterm'] = 'Loan term (years)';
|
||||
$string['monthly'] = 'Monthly';
|
||||
$string['pluginname'] = 'Loan calculator';
|
||||
$string['repaymentamount'] = 'Repayment amount';
|
||||
$string['repaymentfreq'] = 'Repayment frequency';
|
||||
$string['weekly'] = 'Weekly';
|
||||
Reference in New Issue
Block a user