/** * This method calculates a fee which is set by Crowdfunding Finance. * * @param $fundingType * @param $fees * @param $txnAmount * * @return float */ protected function calculateFee($fundingType, $fees, $txnAmount) { $result = 0; switch ($fundingType) { case "FIXED": $feePercent = ArrayHelper::getValue($fees, "fixed_campaign_percent", 0, "float"); $feeAmount = ArrayHelper::getValue($fees, "fixed_campaign_amount", 0, "float"); break; case "FLEXIBLE": $feePercent = ArrayHelper::getValue($fees, "flexible_campaign_percent", 0, "float"); $feeAmount = ArrayHelper::getValue($fees, "flexible_campaign_amount", 0, "float"); break; } // Calculate fee based on percent. if (!empty($feePercent)) { // Calculate amount. $math = new Prism\Math(); $math->calculateValueFromPercent($feePercent, $txnAmount); // Add the amount to the result. $feePercentAmount = (string) $math; if ($txnAmount > $feePercentAmount) { $result += (double) $feePercentAmount; } } // Calculate fees based on amount. if (!empty($feeAmount) and $txnAmount > $feeAmount) { $result += $feeAmount; } // Check for invalid value that is less than zero. if ($result < 0) { $result = 0; } return (double) $result; }
/** * Remove amount from current funded one. * Calculate funded percent. * * <code> * $projectId = 1; * $finds = 50; * * $project = new Crowdfunding\Project(\JFactory::getDbo()); * $project->load($projectId); * $project->removeFunds($finds); * $project->store(); * </code> * * @param float $amount */ public function removeFunds($amount) { $this->funded = $this->funded - $amount; // Calculate new percentage $math = new Prism\Math(); $math->calculatePercentage($this->funded, $this->goal, 0); $this->setFundedPercent((string) $math); }