MP_Addon_Reporting_Downloads::calculate( array $data )

Calculates the Amortization schedule and returns the results.


Parameters Parameters

$data

(array) (Required) data


Top ↑

Return Return

(mixed)


Top ↑

Source Source

File: calculator-reporting-add-on/MP_Addon_Reporting_Downloads.php

	protected function calculate( $data ) {

		$calculate = new MP_Calculator_MortgageCalculate();

		$price    = $calculate->get_amount( $data['price'] );
		$interest = floatval( $data['interest'] );

		/* down payment percent or amount */
		if ( isset( $this->calculator_settings['down_payment_type'] )
			 && 'amount' === $this->calculator_settings['down_payment_type']
		) { // dollar amount
			$moneydown = $calculate->get_amount( $data['down_payment'] );
			$down      = floatval( ( $moneydown / $price ) * 100 );
			$down      = round( $down, 2 );
		} else {                                                         // percent
			$down      = $data['down'];
			$moneydown = $price * ( $down / 100 );
		}

		$term        = intval( $data['term'] );
		$termcycle   = $data['termcycle'];
		$years_text  = __( 'Years', 'CalculatorsReportingAddon' );
		$months_text = __( 'Months', 'CalculatorsReportingAddon' );
		if ( 'months' === $termcycle ) {
			$cycle_text = $months_text;
		} else {
			$cycle_text = $years_text;
			if ( $term > 50 ) {  // limit years to 50 max
				$term = 50;
			}
		}
		$price2                       = $calculate->format_amount( $price );
		$result                       = $calculate->p_and_i( $price, $price2, $interest, $down, $moneydown, $termcycle, $term );
		$result['vals']['cycle_text'] = $cycle_text;
		$result['vals']['interest']   = $interest;
		$result['vals']['down']       = $down;
		$result['vals']['term']       = $term;

		return $result;

	}

Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0 Introduced.