/** * Get the price of the product * * If there's a refund subtrack to the price (20130409) * @param integer $productid * @param float $refund */ public static function getPrices($productid, $refund = false) { $prices = array(); if (is_numeric($productid)) { $product = self::getAllInfo($productid); // Get the tax percentage $tax = Taxes::getTaxbyProductID($productid); if (!empty($product)) { if (!empty($product['price_1']) && $product['price_1'] > 0) { if ($refund !== false) { $priceToPayWithRefund = $product['price_1'] - $refund; if ($priceToPayWithRefund < 0) { $product['price_1'] = $priceToPayWithRefund; } } // Taxes calculation if (!empty($tax['percentage']) && is_numeric($tax['percentage'])) { $taxincluded = $product['price_1'] * ($tax['percentage'] + 100) / 100; } else { $taxincluded = $product['price_1']; } return array('type' => 'flat', 'value' => $product['price_1'], 'taxincluded' => $taxincluded, 'taxes' => $tax); } else { // Get the price min & max interval tranches $tranches = ProductsTranches::getMinMaxTranches($productid); if (!empty($tranches[1])) { // Refund calculation price if ($refund !== false) { $idBillingCircle = $tranches[0]['BillingCycle']['billing_cycle_id']; $monthBilling = BillingCycle::getMonthsNumber($idBillingCircle); if ($monthBilling > 0) { $priceToPay = $tranches[0]['price'] * $monthBilling; $priceToPayWithRefund = $priceToPay - $refund; if ($priceToPayWithRefund < 0) { $priceToPayWithRefund = $priceToPay; } $tranches[0]['price'] = round($priceToPayWithRefund / $monthBilling, 2); } else { $priceToPayWithRefund = $tranches[0]['price'] - $refund; if ($priceToPayWithRefund > 0) { $tranches[0]['price'] = $priceToPayWithRefund; } } $idBillingCircle = $tranches[1]['BillingCycle']['billing_cycle_id']; $monthBilling = BillingCycle::getMonthsNumber($idBillingCircle); if ($monthBilling > 0) { $priceToPay = $tranches[1]['price'] * $monthBilling; $priceToPayWithRefund = $priceToPay - $refund; if ($priceToPayWithRefund < 0) { $priceToPayWithRefund = $priceToPay; } $tranches[1]['price'] = round($priceToPayWithRefund / $monthBilling, 2); } else { $priceToPayWithRefund = $tranches[1]['price'] - $refund; if ($priceToPayWithRefund > 0) { $tranches[1]['price'] = $priceToPayWithRefund; } } } // Taxes calculation if (!empty($tax['percentage']) && is_numeric($tax['percentage'])) { $minvaluewithtaxes = $tranches[0]['price'] * ($tax['percentage'] + 100) / 100; $maxvaluewithtaxes = $tranches[1]['price'] * ($tax['percentage'] + 100) / 100; } else { $minvaluewithtaxes = $tranches[0]['price']; $maxvaluewithtaxes = $tranches[1]['price']; } $discount = floatval($tranches[1]['price']) - floatval($tranches[0]['price']); $minvalue = $tranches[0]['price']; $maxvalue = $tranches[1]['price']; $data = array('type' => 'multiple', 'measurement' => $tranches[0]['measurement'], 'tranches' => $tranches, 'minvalue' => $minvalue, 'maxvalue' => $maxvalue, 'minvaluewithtaxes' => $minvaluewithtaxes, 'maxvaluewithtaxes' => $maxvaluewithtaxes, 'discount' => $discount, 'taxes' => $tax); return $data; } elseif (!empty($tranches['price'])) { // Taxes calculation if ($refund !== false) { $priceToPayWithRefund = $tranches['price'] - $refund; if ($priceToPayWithRefund < 0) { $tranches['price'] = $priceToPayWithRefund; } } if (!empty($tax['percentage']) && is_numeric($tax['percentage'])) { $minvaluewithtaxes = $tranches['price'] * ($tax['percentage'] + 100) / 100; } else { $minvaluewithtaxes = $tranches['price']; } $price = $tranches['price']; $data = array('type' => 'multiple', 'measurement' => $tranches['measurement'], 'minvalue' => $price, 'maxvalue' => $price, 'taxes' => $tax, 'minvaluewithtaxes' => $minvaluewithtaxes, 'maxvaluewithtaxes' => 0, 'discount' => 0); return $data; } } } } return array('type' => 'flat', 'value' => 0, 'taxincluded' => 0, 'taxes' => 0); }