/** * Caculate the total rates with margins * and company fees */ public function obStep2Action() { // params $out = ''; $params = $this->getRequest()->getParams(); // Company $user = (array) Zend_Auth::getInstance()->getIdentity(); $company = $this->getCompanies()->getById($user['company_id']); $company = !is_null($company) ? $company->toArray() : array(); // Calculate rate $type = $params['type']; $rate = $this->getRates()->getById($params['rate_id']); $rate = !is_null($rate) ? $rate->toArray() : array(); $margins = $this->getMargins()->getFeeByRateCode($rate['c_code']); $payment_type = $params['payment_type']; AjaxObController::calculateRate($type, $rate, $margins, $company, $payment_type); // Total self::$_amount = (double) $params['amount']; self::$_uk_amount = (double) $params['uk_amount']; $byUkAmount = !empty($params['uk_amount']) ? true : false; // If not by uk_amount if (!$byUkAmount) { self::$_uk_amount = self::$_amount / self::$_rate; } if ($byUkAmount && $type == 'buyback') { self::$_amount = self::$_uk_amount * self::$_rate; } $ob_type = $type == 'order' ? 's' : 'b'; $company_fee_type = $company[$payment_type . '_' . $ob_type . '_fee_type']; $company_fee_flat = $company[$payment_type . '_' . $ob_type . '_flat_fee']; $company_fee_percentage = $company[$payment_type . '_' . $ob_type . '_percentage_fee']; $company_fee_minimum = $company[$payment_type . '_' . $ob_type . '_minimum_fee']; // Flat if ($company_fee_type == 'flat') { if ($type == 'order') { if ($byUkAmount) { self::$_uk_amount -= $company_fee_flat; $cf_symbol = '-'; } else { self::$_uk_amount += $company_fee_flat; $cf_symbol = '+'; } } elseif ($type == 'buyback') { if ($byUkAmount) { self::$_uk_amount += $company_fee_flat; $cf_symbol = '+'; } else { self::$_uk_amount -= $company_fee_flat; $cf_symbol = '-'; } } // Percentage } else { if ($company_fee_type == 'percentage') { $company_fee_percentage_out = self::$_uk_amount * $company_fee_percentage / 100; if ($type == 'order') { if ($byUkAmount) { self::$_uk_amount -= $company_fee_percentage_out; $cf_symbol = '-'; } else { self::$_uk_amount += $company_fee_percentage_out; $cf_symbol = '+'; } } elseif ($type == 'buyback') { if ($byUkAmount) { self::$_uk_amount += $company_fee_percentage_out; $cf_symbol = '+'; } else { self::$_uk_amount -= $company_fee_percentage_out; $cf_symbol = '-'; } } } } // Caluclate minimum if ($company_fee_percentage < $company_fee_minimum) { if ($type == 'order') { if ($byUkAmount) { self::$_uk_amount -= $company_fee_minimum; $cf_symbol = '-'; } else { self::$_uk_amount += $company_fee_minimum; $cf_symbol = '+'; } } elseif ($type == 'buyback') { if ($byUkAmount) { self::$_uk_amount += $company_fee_minimum; $cf_symbol = '+'; } else { self::$_uk_amount -= $company_fee_minimum; $cf_symbol = '-'; } } $company_fee_type = 'minimum'; } // If by uk_amount if ($byUkAmount && $type == 'order') { self::$_amount = self::$_uk_amount * self::$_rate; } // Other vars $rate_text = $type == 'order' ? 'Selling' : 'Buying'; $note = $type == 'order' ? $rate['s_note'] : $rate['b_note']; $c_code = '£'; // Render rate & total $out .= ' <h3>Total: </h3> <hr /> <table class="table"> <tr> <td><label>' . $rate_text . ' Rate <span style="color: #ff0000;">*</span></label></td> <td><input type="text" value="' . round2Nr(self::$_rate) . '" disabled /></td> </tr>' . ($company_fee_type == 'flat' && $company_fee_flat != 0 ? '<tr> <td><label>Company "' . $company['name'] . '"<br /> flat fee</label></td> <td><input type="text" value=" ' . $cf_symbol . ' ' . $c_code . ' ' . round2Nr($company_fee_flat) . '" disabled /></td> </tr>' : "") . ($company_fee_type == 'percentage' && $company_fee_percentage != 0 ? '<tr> <td><label>Company "' . $company['name'] . '"<br /> percentage fee</label></td> <td><input type="text" value="' . $cf_symbol . ' % ' . round2Nr($company_fee_percentage) . ' = ' . $c_code . ' ' . round2Nr($company_fee_percentage_out) . '" disabled /></td> </tr>' : "") . ($company_fee_type == 'minimum' && $company_fee_minimum != 0 ? '<tr> <td><label>Company "' . $company['name'] . '"<br /> minimum fee</label></td> <td><input type="text" value="' . $cf_symbol . ' ' . $c_code . ' ' . round2Nr($company_fee_minimum) . '" disabled /></td> </tr>' : "") . '<tr> <td><label>Amount</label></td> <td><input type="text" value="' . $rate['c_code'] . ' ' . round2Nr(self::$_amount) . '" disabled /></td> <input type="hidden" name="amount" value="' . round2Nr(self::$_amount) . '" disabled /> </tr> <tr> <td><label>UK Amount</label></td> <td><input type="text" value="' . $c_code . ' ' . round2Nr(self::$_uk_amount) . '" disabled /></td> <input type="hidden" name="uk_amount" value="' . round2Nr(self::$_uk_amount) . '" disabled /> </tr>' . (!empty($note) && !is_null($note) ? '<tr> <td><label>Note</label></td> <td><textarea disabled>' . $note . '</textarea></td> </tr>' : '') . '</table>'; // Inputs $out .= NL_Render::renderInputText('text', 'Traveller Name', 'traveller_name', array(), '', 'required'); $out .= NL_Render::renderTextarea('text', 'Comment', 'comment', array()); $out .= NL_Render::renderInputHidden('hidden', 'date_delivery', array(), isset($params['date_delivery']) ? $params['date_delivery'] : date('d/m/Y')); $out .= NL_Render::renderInputHidden('hidden', 'type', array(), $type); $out .= '<span style="color: #ff0000;">*Rates are indicative only and subject to change</span>'; // Bottom js $out .= '<hr /> <div class="content-step3"></div> <input type="submit" name="process_ob" id="process_ob" class="btn btn-lg btn-default submit" value="Process ' . ucfirst($type) . '" /> <script> $(document).ready(function(){ $(\'input[type="radio"]\').prop("disabled", true); $("#rate_id").prop("disabled", true); $("#amount").prop("disabled", true); $("#uk_amount").prop("disabled", true); $("#modifyForm").validate({ errorElement: "span", errorClass: "error", rules: { traveller_name: { required: true, } } }); $("#modifyForm").unbind("submit"); $("#modifyForm").submit(function(e){ if ($("#modifyForm").valid()) { $(".submit").hide(); $("#al").show(); $("#modifyForm input").prop("disabled", false); $("#modifyForm select").prop("disabled", false); $("#modifyForm textarea").prop("disabled", false); var postData = $("#modifyForm").serializeArray(); $(".content-step3").load("ajax-ob/ob-step3", postData, function(){ $("#al").hide(); $("#modifyForm input").prop("disabled", true); $("#modifyForm select").prop("disabled", true); $("#modifyForm textarea").prop("disabled", true); }); } e.preventDefault(); }); }); </script>'; echo $out; }