public function obMultipleAction() { $identity = (array) Zend_Auth::getInstance()->getIdentity(); $params = $this->getRequest()->getParams(); $this->view->assign('type', $params['type']); $center = $this->getCenters()->getById($identity['center_id']); $center = !is_null($center) ? $center->toArray() : array(); $company = $this->getCompanies()->getById($identity['company_id']); $company = !is_null($company) ? $company->toArray() : array(); $toEmailCenter = $center['email']; $toEmailCompany = $company['email']; // Submited request if (isset($params['process_ob'])) { $uid = mt_rand(100000, 999999); $date_created = date('Y-m-d H:i:s'); $date_delivery = isset($params['date_delivery']) ? $params['date_delivery'] : date('d/m/Y'); $date_delivery = convertUKtoUSdate($date_delivery); $company_id = $identity['company_id']; $center_id = $identity['center_id']; $customer_id = $identity['customer_id']; $amount = null; $uk_amount = $params['total']; $created_user_id = $identity['id']; $payment_type = $params['payment_type']; $traveller_name = $params['traveller_name']; $comment = $params['comment']; $type = $params['type']; $is_multiple = 1; $status = $company['with_check'] ? Table_Abstract::STATUS_PENDING : Table_Abstract::STATUS_UNPROCESSED; $ob = $this->getOrders()->createRow(); $ob_id = $ob->setUid($uid)->setDateCreated($date_created)->setDateDelivery($date_delivery)->setCompanyId($company_id)->setCenterId($center_id)->setCustomerId($customer_id)->setAmount($amount)->setUkAmount($uk_amount)->setCreatedUserId($created_user_id)->setPaymentType($payment_type)->setTravellerName($traveller_name)->setComment($comment)->setType($type)->setIsMultiple($is_multiple)->setStatus($status)->save(); // add to ob multiple foreach ($params['rate_id'] as $k => $rate_id) { $rate = $params['rate'][$k]; $amount = $params['amount'][$k]; $uk_amount = $params['uk_amount'][$k]; $ob_multiple = $this->getObMultiple()->createRow(); $ob_multiple->setObId($ob_id)->setRateId($rate_id)->setRate($rate)->setPaymentType($payment_type)->setAmount($amount)->setUkAmount($uk_amount)->save(); } /** * Get order by uid * @var mixed */ $ob = $this->getOrders()->getByUid($uid); $join_in = array(array('customers', 'customer_id'), array('companies', 'company_id'), array('centers', 'center_id'), array('rates', 'rate_id'), array('users', 'created_user_id'), array('users', 'response_user_id')); $ob = $this->_buildJoinTbl(array($ob), $join_in); $ob = $ob[0]; $ob['company'] = $company; // Ob multiple $ob_multiple = array(); $_ob_multiple = $this->getObMultiple()->geByOrderId($ob['id'])->toArray(); foreach ($_ob_multiple as $obm) { $ob_multiple[$obm['id']] = $obm; $ob_multiple[$obm['id']]['rate_detail'] = $this->getRates()->getById($obm['rate_id'])->toArray(); } $ob['multiple'] = $ob_multiple; /** * Send mail to processing center with order * @var NL_HtmlMailer */ $is_error = false; $email = new NL_HtmlMailer(); $email->sendOb($ob, $toEmailCenter); /** @var Send mail to approvers $approversTable */ $approversTable = new Table_Approvers(); $approvers = $approversTable->getByCompanyId($company['id']); foreach ($approvers->toArray() as $approver) { if (!is_null($approver['email']) && !empty($approver['email'])) { $email->sendOb($ob, $approver['email']); } } /** send to company if with approve */ if ($company['with_check']) { $email->sendOb($ob, $toEmailCompany); } // MESSAGE if (!$is_error) { // Success promotional message include APPLICATION_PATH . DIRECTORY_SEPARATOR . 'controllers' . DIRECTORY_SEPARATOR . 'AjaxObController.php'; $out = AjaxObController::renderSuccessMessage($type, $uid, $payment_type, $is_multiple = true); } else { // error message $out = NL_Render::renderErrorMessage(); } echo $out; $this->view->assign('show_view', false); } else { $this->view->assign('show_view', true); } }
/** * Render CRUD Table * * @param mixed $table * @param mixed $s_text * @param mixed $icon_class * @param mixed $del_in_value * @param mixed $array_in * @param mixed $array_nv */ public static function renderCrudTable($thisss, $table = '', $s_text = '', $icon_class = '', $del_in_value = '', $array_in = array(), $array_nv = array(), $other_status = false, $extra_text = '', $show_add = true, $show_edit = true, $show_delete = true, $inFront = false, $extra_html = '', $extra_columns = array(), $withApproveReject = false) { include APPLICATION_PATH . '/views/helpers/ShowStatusChange.php'; $sscHelper = new Zend_View_Helper_ShowStatusChange(); $_table = $s_text == 'order' || $s_text == 'buyback' ? $table . '?type=' . $s_text : $table; $_title = $s_text == 'order' || $s_text == 'buyback' ? $s_text : $table; $out = '<header>'; if ($show_add) { $out .= '<a href="#" class="btn btn-primary pull-right ajax-add-item" data-table="' . $_table . '" data-title="' . $_title . '"> <span class="glyphicon glyphicon-plus"></span> Add ' . ucfirst($s_text) . '</a>'; } $out .= '<h2><span class="' . $icon_class . '"></span> ' . (!empty($extra_text) ? $extra_text : ucfirst($table)) . '</h2>'; $out .= !empty($extra_html) ? $extra_html : ''; $out .= '<hr /> </header>'; if (!empty($array_in)) { if ($withApproveReject) { $out .= '<form enctype="multipart/form-data" method="post" action="' . $thisss->baseUrl('approve-reject-ob') . '" class="pullLeft" id="arObForm"> <div class="pull-left"> <button type="submit" name="' . $s_text . '_approved" class="btn btn-primary mr10"> <span class="glyphicon glyphicon-ok"></span> Approve selected</button> <button type="submit" name="' . $s_text . '_rejected" class="btn btn-primary mr10 reject-selected"> <span class="glyphicon glyphicon-remove"></span> Reject selected</button> <a href="#" class="btn btn-primary mr10 check-all">Check all</a> <a href="#" class="btn btn-primary mr10 uncheck-all">Uncheck all</a> </div> <div class="clearfix"> </div> '; } $out .= ' <table class="table table-striped"> <thead>'; if ($inFront) { if (!empty($extra_columns)) { foreach ($extra_columns as $column) { $out .= '<th>' . $column['column_name'] . '</th>'; } } if ($withApproveReject) { $out .= '<th style="text-align: center;">Check</th>'; $out .= '<th style="text-align: center;">Approve</th>'; $out .= '<th style="text-align: center;">Reject</th>'; } if ($show_delete) { $out .= '<th style="text-align: center;">Delete</th>'; } if ($show_edit) { $out .= '<th style="text-align: center;">Edit</th>'; } if (!$other_status) { $out .= '<th style="text-align: center;">Status</th>'; } } foreach ($array_nv as $i) { $text = $i[0]; $name = $i[1]; $type = $i[2]; $out .= '<th>' . $text . '</th>'; } if (!$inFront) { if (!empty($extra_columns)) { foreach ($extra_columns as $column) { $out .= '<th>' . $column['column_name'] . '</th>'; } } if ($withApproveReject) { $out .= '<th style="text-align: center;">Check</th>'; $out .= '<th style="text-align: center;">Approve</th>'; $out .= '<th style="text-align: center;">Reject</th>'; } if (!$other_status) { $out .= '<th style="text-align: center;">Status</th>'; } if ($show_edit) { $out .= '<th style="text-align: center;">Edit</th>'; } if ($show_delete) { $out .= '<th style="text-align: center;">Delete</th>'; } } $out .= '</thead> <tbody>'; foreach ($array_in as $a) { $out .= '<tr>'; if ($inFront) { if (!empty($extra_columns)) { foreach ($extra_columns as $column) { $out .= '<td style="text-align: center;">' . $column['column_content'] . '</td>'; } } if ($withApproveReject) { $out .= '<td style="text-align: center;"> <input type="checkbox" name="uid[' . $a['uid'] . ']" class="uid-checkbox" /> </td> <td style="text-align: center;"> <a href="' . $thisss->baseUrl('approve-reject-ob?type=' . $s_text . '&uid=' . $a['uid'] . '&status=approved&single_uid=true') . '"> <span class="glyphicon glyphicon-ok"> </span> </a> </td>'; $out .= '<td style="text-align: center;"> <a href="' . $thisss->baseUrl('approve-reject-ob?type=' . $s_text . '&uid=' . $a['uid'] . '&status=rejected&single_uid=true') . '"> <span class="glyphicon glyphicon-remove"> </span> </a> </td>'; } if ($show_delete) { $out .= '<td style="text-align: center;">' . $sscHelper->showStatusChange($thisss, $a['id'], $table, 'deleted', $a[$del_in_value]) . '</td>'; } if ($show_edit) { $out .= '<td style="text-align: center;"><a data-table="' . $_table . '" data-title="' . $_title . '" data-id="' . $a['id'] . '" class="ajax ajax-edit-item"><img src="img/edit.png" class="img-30" /></a></td>'; } if (!$other_status) { $out .= '<td style="text-align: center;">' . $sscHelper->showStatusChange($thisss, $a['id'], $table, $a['status']) . '</td>'; } } foreach ($array_nv as $i) { $text = $i[0]; $name = $i[1]; $type = $i[2]; switch ($type) { case 'text': $out .= '<td' . (!empty($a[$name]) && !is_null($a[$name]) ? '>' . $a[$name] : ' style="text-align: center;">-') . '</td>'; break; case 'round': $out .= '<td' . (!empty($a[$name]) && !is_null($a[$name]) ? '>' . round2Nr($a[$name]) : ' style="text-align: center;">-') . '</td>'; break; case 'check': $out .= '<td>' . ($a[$name] == 1 ? '<b>Yes</b>' : 'No') . '</td>'; break; case 'date': $out .= '<td' . (!empty($a[$name]) && !is_null($a[$name]) ? '>' . convertUStoUKdate($a[$name]) : ' style="text-align: center;">-') . '</td>'; break; case 'image': $out .= '<td>' . NL_Render::renderImageInTbl($a[$name]) . '</td>'; break; case 'bg_color': $out .= '<td style="background-color: ' . $a[$name] . '"></td>'; break; case 'array': $out .= '<td' . (!empty($a[$name][$i[3]]) && !is_null($a[$name][$i[3]]) ? '>' . $a[$name][$i[3]] : ' style="text-align: center;">-') . '</td>'; break; case 'link': $out .= '<td' . (!empty($a[$name]) && !is_null($a[$name]) ? '>' . '<a href="' . $i[3] . $a[$name] . '" target="_blank"> <span class="glyphicon glyphicon-print"></span> ' . $a[$name] . '</a>' : ' style="text-align: center;">-') . '</td>'; } } if (!$inFront) { if (!empty($extra_columns)) { foreach ($extra_columns as $column) { $out .= '<td style="text-align: center;">' . $column['column_content'] . '</td>'; } } if (!$other_status) { $out .= '<td style="text-align: center;">' . $sscHelper->showStatusChange($thisss, $a['id'], $table, $a['status']) . '</td>'; } if ($show_edit) { $out .= '<td style="text-align: center;"><a data-table="' . $_table . '" data-title="' . $_title . '" data-id="' . $a['id'] . '" class="ajax ajax-edit-item"><img src="img/edit.png" class="img-30" /></a></td>'; } if ($show_delete) { $out .= '<td style="text-align: center;">' . $sscHelper->showStatusChange($thisss, $a['id'], $table, 'deleted', $a[$del_in_value]) . '</td>'; } } $out .= '</tr>'; } $out .= '</tbody> </table>'; } else { $out .= '<div class="panel"> <h4 style="margin-left: 10px;">No ' . (!empty($extra_text) ? strtolower($extra_text) : $table) . ' listed</h5> </div>'; } if ($withApproveReject) { $out .= "</form>\n <script>\n \$(document).ready(function(){\n \$('.check-all').on('click', function(){\n \$('.uid-checkbox').prop('checked', true);\n });\n\n \$('.uncheck-all').on('click', function(){\n \$('.uid-checkbox').prop('checked', false);\n });\n });\n </script>"; } return $out; }
/** * Multiple tr */ public function loadObMultipleTrAction() { include APPLICATION_PATH . '/views/helpers/GetTableSelect.php'; $tsHelper = new Zend_View_Helper_GetTableSelect(); $view = new Zend_View(); // Rates according to payment type $params = $this->getRequest()->getParams(); $rate = array(); // Cash if (isset($params['payment_type']) && $params['payment_type'] == 'cash') { $rates = $tsHelper->getTableSelect('rates', 'country', true); // TC } elseif ($params['payment_type'] == 'tc') { $rates_array = $this->getRates()->getTcRates(); $rates[''] = '-'; foreach ($rates_array as $r) { $rates[$r['id']] = $r['country']; } } $out = '<tr> <td>' . NL_Render::renderSelect('select', 'Foreign Currency', 'rate_id', array(), $rates, $view, 'rate_id', 'required', '', true) . '</td> <td>' . NL_Render::renderInputText('number', 'Rate', 'rate', array(), '', 'readonly', '', false, true) . '</td> <td>' . NL_Render::renderInputText('number', 'Foreign Amount', 'amount', array(), '', 'readonly', '', false, true) . '</td> <td>' . NL_Render::renderInputText('number', 'UK Equivalent', 'uk_amount', array(), '', 'readonly', '', false, true) . '</td> ' . ($params['with_delete_option'] == 'true' ? '<td><button class="removeCurrency">X</button>' : '') . ' <script> // Calculate uk total function calculateUkTotal() { var new_val = 0; $("#total").val(0); $(".uk_amount").each(function(e){ new_val = parseFloat(new_val) + parseFloat($(this).val()); }); if (!isNaN(new_val)) { $("#total").val(new_val); } } // Remove currency $(".removeCurrency").on("click", function(e){ e.preventDefault(); uk_amount = $(this).parents("tr:first").find(".uk_amount"); if (uk_amount.val() != "") { var new_val = parseFloat($("#total").val()) - parseFloat(uk_amount.val()); $("#total").val(new_val); } if ($(".ob tr").length == 1) { $("#addCurrency").prop("disabled", false); } $(this).parents("tr:first").remove(); }); // Calculate rate $(".rate_id").on("change", function(e){ var self = $(this); var rate = self.parents("tr:first").find(".rate"); var amount = self.parents("tr:first").find(".amount"); var uk_amount = self.parents("tr:first").find(".uk_amount"); var payment_type = ""; var pt_cash = $("#payment_type-cash").prop("checked"); var pt_tc = $("#payment_type-tc").prop("checked"); if (pt_cash == true) payment_type = "cash"; else if (pt_tc == true) payment_type = "tc"; if (self.val() != "") { $.ajax({ url: "ajax-ob/calculate-rate-ajax", method: "GET", dataType: "html", data: { type: "' . $params['type'] . '", payment_type: payment_type, rate_id: self.val() }, beforeSend: function(){ $("#al").show(); }, complete: function(result) { $("#al").hide(); rate.val(result.responseText); amount.prop("readonly", false); uk_amount.prop("readonly", false); $("#addCurrency").prop("disabled", true); if (uk_amount.val() != "") { var new_val = parseFloat($("#total").val()) - parseFloat(uk_amount.val()); $("#total").val(new_val); } amount.val(""); uk_amount.val(""); } }); } }); // Restore $(".amount, .uk_amount").on("click", function(e) { var self = $(this); var amount = self.parents("tr:first").find(".amount"); var uk_amount = self.parents("tr:first").find(".uk_amount"); $("#addCurrency").prop("disabled", true); if (uk_amount.val() != "") { var new_val = parseFloat($("#total").val()) - parseFloat(uk_amount.val()); $("#total").val(new_val); } amount.val(""); uk_amount.val(""); }); // Calculate totals var totals_timer = null; $(".amount, .uk_amount").on("keyup", function(e){ if(totals_timer) { clearTimeout(totals_timer); } e.preventDefault(); var self = $(this); $("#addCurrency").prop("disabled", false); var amount = self.parents("tr:first").find(".amount");; var uk_amount = self.parents("tr:first").find(".uk_amount"); var rate = self.parents("tr:first").find(".rate"); totals_timer = setTimeout(function(){ $.ajax({ url: "ajax-ob/calculate-totals", method: "GET", dataType: "json", data: { type: "' . $params['type'] . '", amount: amount.val(), uk_amount: uk_amount.val(), rate: rate.val(), active_el: $(document.activeElement).attr("id") }, beforeSend: function(){ $("#al").show(); }, complete: function(result) { $("#al").hide(); var r = result.responseJSON; amount.val(r.amount); uk_amount.val(r.uk_amount); rate.val(r.rate); calculateUkTotal(); } }) }, 500); }); </script> </tr> '; echo $out; }