public function detailAction() { $this->view->headTitle(Vi_Language::translate('Detail Order')); $this->view->menu = array('order'); $config = Vi_Registry::getConfig(); $numRowPerPage = Vi_Registry::getConfig("defaultNumberRowPerPage"); $currentPage = $this->_getParam("page", 1); $displayNum = $this->_getParam('displayNum', false); $id = $this->_getParam('id', false); if (false == $id) { $this->_redirect('order/admin/manager'); } /** * Load all details */ $objDetail = new Models_OrderDetail(); $allDetails = $objDetail->getByColumnName(array('order_id=?' => $id))->toArray(); /** * Get order */ $objOrder = new Models_Order(); $order = $objOrder->find($id)->toArray(); $order = current($order); $this->view->order = $order; /** * Get restaurant */ $objRes = new Models_Restaurant(); $res = $objRes->find($order['restaurant_id'])->toArray(); $res = current($res); $this->view->res = $res; /** * Set values for tempalte */ $this->view->allMeals = $allDetails; }
/** * List all meal follow restaurant */ public function indexAction() { $this->view->headTitle('Cart information'); $order_id = session_id(); if (!isset($_SESSION['cart'][$order_id])) { $this->_redirect(''); } /** * Get restaurant */ $objRes = new Models_Restaurant(); $res = $objRes->find($_SESSION['cart'][$order_id]['restaurant_id'])->toArray(); $res = current($res); // echo '<pre>';print_r($_SESSION);//die; // echo '<pre>';print_r($res);die; if (false == $res) { $this->_redirect(''); } $this->view->session_cart = $_SESSION['cart'][$order_id]; $this->view->subtotal = $_SESSION['cart'][$order_id]['subtotal']; $this->view->tax = $_SESSION['cart'][$order_id]['tax']; $this->view->shipping = $_SESSION['cart'][$order_id]['shipping']; $this->view->ordertotal = $_SESSION['cart'][$order_id]['ordertotal']; $this->view->mark = strtoupper($_SESSION['cart'][$order_id]['order_service']); $this->view->date = $_SESSION['cart'][$order_id]['date']; $this->view->time = $_SESSION['cart'][$order_id]['time']; $data_info = $this->_getParam('data', false); $confirm = $this->_getParam('confirm', false); /** * Remember customer's infomation */ if (false !== $data_info) { $_SESSION['cart_customer'] = $data_info; } $data_info = $_SESSION['cart_customer']; $this->view->full_name = $data_info['full_name']; $this->view->address = $data_info['address']; $this->view->zip_code = $data_info['zip_code']; $this->view->phone = $data_info['phone1'] . "." . $data_info['phone2'] . "." . $data_info['phone3']; $this->view->cardType = $_SESSION['cart_customer']['card_type']; $cardNumber = $_SESSION['cart_customer']['card_number']; $cardNumber[4] = 'X'; $cardNumber[5] = 'X'; $cardNumber[6] = 'X'; $cardNumber[7] = 'X'; $cardNumber[8] = 'X'; $cardNumber[9] = 'X'; $cardNumber[10] = 'X'; $cardNumber[11] = 'X'; $this->view->cardNumber = $cardNumber; $error = ''; /** * Store to DB and redirect */ if (false != $confirm) { /************************************************************************** * Make payment */ require_once 'libs/paypal/CallerService.php'; /** * Fist name, last name */ $firstName = trim(substr($data_info['full_name'], 0, strpos($data_info['full_name'] . ' ', ' ') + 1)); $lastName = trim(substr($data_info['full_name'], strlen($firstName))); /** * Get required parameters from the web form for the request */ $paymentType = urlencode('Sale'); $firstName = urlencode($firstName); $lastName = urlencode($lastName); $creditCardType = urlencode($data_info['card_type']); $creditCardNumber = urlencode($data_info['card_number']); $expDateMonth = urlencode($data_info['card_month']); // Month must be padded with leading zero $padDateMonth = str_pad($expDateMonth, 2, '0', STR_PAD_LEFT); $expDateYear = urlencode($data_info['card_year']); $cvv2Number = urlencode($data_info['card_cvv']); $address1 = urlencode($data_info['address']); $address2 = urlencode(''); $city = urlencode($data_info['city']); $state = urlencode($data_info['state']); $zip = urlencode($data_info['zip_code']); $amount = urlencode(number_format($_SESSION['cart'][$order_id]['ordertotal'], 2, '.', '')); $currencyCode = "CAD"; // $state = 'NL'; $country = 'CA'; /* Construct the request string that will be sent to PayPal. The variable $nvpstr contains all the variables and is a name value pair string with & as a delimiter */ $nvpstr = "&PAYMENTACTION={$paymentType}&AMT={$amount}&CREDITCARDTYPE={$creditCardType}&ACCT={$creditCardNumber}&EXPDATE=" . $padDateMonth . $expDateYear . "&CVV2={$cvv2Number}&FIRSTNAME={$firstName}&LASTNAME={$lastName}&STREET={$address1}&CITY={$city}&STATE={$state}" . "&ZIP={$zip}&COUNTRYCODE={$country}&CURRENCYCODE={$currencyCode}"; // echo $nvpstr;die; /* Make the API call to PayPal, using API signature. The API response is stored in an associative array called $resArray */ $resArray = hash_call("doDirectPayment", $nvpstr); // echo '<pre>';print_r($resArray);die; /* Display the API response back to the browser. If the response from PayPal was a success, display the response parameters' If the response was an error, display the errors received using APIError.php. */ $ack = strtoupper($resArray["ACK"]); if ($ack != "SUCCESS") { $_SESSION['card_error_msg'] = @$resArray['L_LONGMESSAGE0']; $this->_redirect('restaurant/ship'); } /** * End payment **************************************************************************/ //-- begin save into db: vi_order and vi_order_detail $arr_order = array('sub_total' => $_SESSION['cart'][$order_id]['subtotal'], 'sales_tax' => $_SESSION['cart'][$order_id]['tax'], 'shipping_fee' => $_SESSION['cart'][$order_id]['shipping'], 'order_total' => $_SESSION['cart'][$order_id]['ordertotal'], 'date' => $_SESSION['cart'][$order_id]['date'], 'time' => $_SESSION['cart'][$order_id]['time'], 'order_service' => $_SESSION['cart'][$order_id]['order_service'], 'full_name' => $data_info['full_name'], 'address' => $data_info['address'], 'suite' => $data_info['note'], 'city' => $data_info['city'], 'state' => $data_info['state'], 'zip_code' => $data_info['zip_code'], 'phone' => $data_info['phone1'] . "." . $data_info['phone2'] . "." . $data_info['phone3'], 'email' => $data_info['email'], 'created_date' => time(), 'restaurant_id' => $_SESSION['cart'][$order_id]['restaurant_id']); $objOrder = new Models_Order(); $bResultOrder = $objOrder->insert($arr_order); foreach ($_SESSION['cart'][$order_id] as $key => $value) { $arr_order_detail = array('order_id' => $bResultOrder, 'meal_id' => $value['meal_id'], 'name' => $value['name'], 'description' => $value['description'], 'price' => $value['price'], 'quantity' => $value['quantity'], 'total' => $value['total_money']); if (!empty($value['name'])) { $objOrderDetail = new Models_OrderDetail(); $objOrderDetail->insert($arr_order_detail); } } //-- end save into db: vi_order and vi_order_detail /** * Send email to admin and user */ $objUser = new Models_User(); $objMail = new Models_Mail(); $data = $arr_order; $config = Vi_Registry::getConfig(); $data['created_date'] = date($config['dateFormat'], $data['created_date']); $data['card_type'] = $this->view->cardType; $data['card_number'] = $this->view->cardNumber; // echo '<pre>';print_r($data);die; $cartDetail = "\n <table width='90%'>\n <tr>\n <td width='55%'></td>\n <td width='15%'></td>\n <td width='15%'></td>\n <td width='15%'></td>\n </tr>\n <tr>\n <td style='color: #442006; font-weight: bold;'>SHIPPING ADDRESS</td>\n <td colspan='3' style='color: #442006; font-weight: bold;'>PAYMENT METHOD</td>\n </tr> \n <tr>\n <td valign='top'>\n <br/>\n <table width='400px;'>\n\n <tr>\n <td width='30%' align='right' style='background-color: #EEEEEE;'>Full Name:</td>\n <td width='70%' style='color: #442006;'>{$data['full_name']}</td>\n </tr>\n <tr>\n <td align='right' style='background-color: #EEEEEE;'>Address:</td>\n <td style='color: #442006;'>{$data['address']}</td>\n\n </tr>\n <tr>\n <td align='right' style='background-color: #EEEEEE;'>Postal Code:</td>\n <td style='color: #442006;'>{$data['zip_code']}</td>\n </tr>\n <tr>\n <td align='right' style='background-color: #EEEEEE;'>Phone:</td>\n\n <td style='color: #442006;'>{$data['phone']}</td>\n </tr>\n </table>\n <br/>\n \n </td>\n <td valign='top'>\n <br/>\n <table width='400px;'>\n\n <tr>\n <td width='30%' align='right' style='background-color: #EEEEEE;'>Name:</td>\n <td width='70%' style='color: #442006;'>{$res['name']}</td>\n </tr>\n <tr>\n <td align='right' style='background-color: #EEEEEE;'>Address:</td>\n <td style='color: #442006;'>{$res['street']}, {$res['city']}, {$res['state']}</td>\n </tr>\n <tr>\n <td width='30%' align='right' style='background-color: #EEEEEE;'>Phone:</td>\n <td width='70%' style='color: #442006;'>{$res['phone']}</td>\n </tr>\n \n <tr>\n <td colspan='2' style='color: #442006; font-weight: bold;'><br/>PAYMENT METHOD</td>\n </tr>\n <tr>\n <td align='right' colspan='2'>{$data['card_type']}: {$data['card_number']}</td>\n </tr>\n \n </table>\n <br/>\n </td>\n\n </tr>\n \n </table>\n <table>\n \n <tr style='background-color: #DDDDDD;'>\n <td style='color: #AD5B21; font-weight: bold;'> Meal</td>\n <td style='color: #AD5B21; font-weight: bold;'> </td>\n <td style='color: #AD5B21; font-weight: bold;'> Quanlity</td>\n <td style='color: #AD5B21; font-weight: bold;'> Price</td>\n <td style='color: #AD5B21; font-weight: bold;'> Total</td>\n </tr> "; foreach ($_SESSION['cart'][$order_id] as $key => $meal) { if (null == $meal['meal_id']) { continue; } $mealImage = Vi_Registry::getConfig('liveSite') . '/' . $meal['image']; if (null != $meal['image']) { $mealImage = '<img src="' . $mealImage . '" style="max-width: 100px;">'; } else { $mealImage = ''; } if (is_numeric($key)) { $cartDetail .= "\n\t <tr>\n\t <td style='border-bottom: 1px solid #DDDDDD;'>\n\t {$mealImage}\n\t </td>\n\t <td style='border-bottom: 1px solid #DDDDDD;'>\n\t <b>{$meal['name']}</b>\n\t\n\t <br/>\n\t <p>{$meal['description']}</p>\n\t </td>\n\t <td style='border-bottom: 1px solid #DDDDDD;'>{$meal['quantity']}</td>\n\t <td style='border-bottom: 1px solid #DDDDDD;'>\$" . number_format($meal['price'] * 1.0, 2) . "</td>\n\t <td style='border-bottom: 1px solid #DDDDDD;'>\$" . number_format($meal['total_money'] * 1.0, 2) . "</td>\n\t </tr>"; } } $cartDetail .= " \n <tr>\n <td colspan='2'> </td>\n <td> Subtotal </td>\n <td>\$" . number_format($data['sub_total'], 2) . "</td>\n\n </tr>\n <tr>\n <td colspan='2'> </td>\n <td> Tax </td>\n <td>\$" . number_format($data['sales_tax'], 2) . "</td>\n </tr>\n <tr>\n <td colspan='2'> </td>\n <td> Shipping fee </td>\n\n <td>\$" . number_format($data['shipping_fee'], 2) . "</td>\n </tr>\n <tr>\n <td colspan='2'> </td>\n <td> Order total </td>\n <td style='color: #AD5B21; font-weight: bold;'>\$" . number_format($data['order_total'], 2) . "</td>\n </tr>\n </table>\n "; $data['card_detail'] = $cartDetail; // echo '<pre>';print_r($data);die; $admin = $objUser->getByUserName('admin'); $objMail->sendHtmlMail('meal_order', $data, array($admin['email'], $data['email'], $res['owner_email'])); /** * Clear session */ unset($_SESSION['cart']); unset($_SESSION['cart_customer']); /** * Redirec to success page */ $objContent = new Models_ScontentLang(); $this->_redirect($objContent->getUrlWithoutAppBaseUrl(21)); return; } }
public function editAction() { /** * Get all provice CODE */ $objCountry = new Models_Country(); $this->view->allProvinces = $objCountry->getAllProvinces(); /** * Get some list */ $objCat = new Models_Category(); $this->view->leadTimeNormal = $objCat->getAllValues('lead_time_normal'); $this->view->leadTimeCatering = $objCat->getAllValues('lead_time_catering'); // echo '<pre>';print_r($this->view->allProvinces);die; /** * Get data */ $objRes = new Models_Restaurant(); $objUser = new Models_User(); $data = $this->_getParam('data', false); $id = $this->_getParam('id', false); $error = ''; if (false != $data) { /** * Insert new restaurant */ $newRes = $data; /** * Modify date */ $dateArr = array('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'); foreach ($dateArr as $item) { if ('1' != @$newRes["date_{$item}"]) { unset($newRes["date_{$item}_start"]); unset($newRes["date_{$item}_end"]); } else { /** * Change correct time */ if (null == @$newRes["date_{$item}_start"]) { $newRes["date_{$item}_start"] = '00:00'; //0 hours } else { $tmp = explode(':', $newRes["date_{$item}_start"]); /** * Hour */ if (null == @$tmp[0]) { $tmp[0] = 0; } $tmp[0] = '00' . abs(intval($tmp[0])); $tmp[0] = substr($tmp[0], -2, 2); if (23 < intval($tmp[0])) { $tmp[0] = '00'; } /** * Minute */ if (null == @$tmp[1]) { $tmp[1] = 0; } $tmp[1] = '00' . abs(intval($tmp[1])); $tmp[1] = substr($tmp[1], -2, 2); if (59 < intval($tmp[1])) { $tmp[1] = '00'; } $newRes["date_{$item}_start"] = $tmp[0] . ':' . $tmp[1]; } if (null == @$newRes["date_{$item}_end"]) { $newRes["date_{$item}_end"] = 24 * 3600 - 60; //23:59:59 hours } else { $tmp = explode(':', $newRes["date_{$item}_end"]); /** * Hour */ if (null == @$tmp[0]) { $tmp[0] = 23; } $tmp[0] = '00' . abs(intval($tmp[0])); $tmp[0] = substr($tmp[0], -2, 2); if (23 < intval($tmp[0])) { $tmp[0] = '23'; } /** * Minute */ if (null == @$tmp[1]) { $tmp[1] = 59; } $tmp[1] = '00' . abs(intval($tmp[1])); $tmp[1] = substr($tmp[1], -2, 2); if (59 < intval($tmp[1])) { $tmp[1] = '59'; } $newRes["date_{$item}_end"] = $tmp[0] . ':' . $tmp[1]; } } } /** * Modify data */ if ('1' != @$newRes['check']['pickup']) { unset($newRes['pickup']); } if ('1' != @$newRes['check']['curbside']) { unset($newRes['curbside']); } if ('1' != @$newRes['check']['delivery']) { unset($newRes['delivery']); unset($newRes['delivery_limit_hour']); unset($newRes['delivery_charge']); unset($newRes['delivery_minimum']); } if ('1' != @$newRes['check']['catering_pickup']) { unset($newRes['catering_pickup']); } if ('1' != @$newRes['check']['catering_delivery']) { unset($newRes['catering_delivery']); unset($newRes['catering_delivery_limit_hour']); unset($newRes['catering_delivery_charge']); unset($newRes['catering_delivery_minimum']); } /** * Remove tempory data */ unset($newRes['check']); if (null != $newRes['image']) { $newRes['image'] = $this->_getImagePath($newRes['image']); } // echo '<pre>';print_r($newRes);die; $objRes->update($newRes, array('restaurant_id=?' => $id)); // /** // * Update user if activating user // */ // if ('1' == $newRes['enabled'] && false != $this->_getParam('user_id', false)) { // /** // * Active user // */ // $objUser->update(array('enabled' => 1), array('user_id=?' => $this->_getParam('user_id', false))); // } $this->session->restaurantMessage = array('success' => true, 'message' => Vi_Language::translate('Edit restaurant successfully')); $this->_redirect('restaurant/admin/manager#listofrestaurant'); } else { /** * Loading data */ $data = $objRes->find($id)->toArray(); $data = current($data); if (false == $data) { $this->_redirect('restaurant/admin/manager'); } /** * Load user */ $user = $objUser->find($data['user_id'])->toArray(); $user = current($user); } $this->view->isNumberCuisine = is_numeric($data['cuisine']); $cuisines = $objCat->getAllValues('cuisine'); $this->view->cuisines = $cuisines; $this->view->data = $data; $this->view->error = $error; $this->view->user = $user; $this->view->headTitle('Edit Restaurant'); $this->view->menu = array('restaurant'); }
public function newMealAction() { $rid = Vi_Registry::getRestaurantIdFromLoggedUser(); if (false == $rid) { $this->_redirect('restaurant/meal/manager'); } $objRes = new Models_Restaurant(); $res = $objRes->find($rid)->toArray(); $res = current($res); if (false == $res) { $this->_redirect(''); } /** * Get data */ $objMeal = new Models_Meal(); $data = $this->_getParam('data', false); $error = ''; if (false != $data) { /** * Insert new meal */ $newMeal = $data; $newMeal['price'] = number_format($newMeal['price'], 2, '.', ''); if (null != $newMeal['image']) { $newMeal['image'] = $this->getImagePath($newMeal['image']); $newMeal['image_thumb'] = $this->getThumbnailImagePath($newMeal['image']); } $newMeal['created_date'] = time(); $newMeal['restaurant_id'] = $rid; // echo '<pre>';print_r($newMeal);die; $objMeal->insert($newMeal); $this->session->mealMessage = 'New meal is created successfully'; $this->_redirect('restaurant/meal/manager/type/' . $data['type']); } $this->view->data = $data; $this->view->error = $error; $this->view->res = $res; $this->view->headTitle('New Meal'); $this->view->menu = array('meal-manager'); }
public function deleteReservationAction() { $resId = Vi_Registry::getRestaurantIdFromLoggedUser(); if (false == $resId) { $this->_redirect('access/index/login'); } $objRes = new Models_Restaurant(); $res = $objRes->find($resId)->toArray(); $res = current($res); if (false == $res) { $this->_redirect(''); } $id = $this->_getParam('id', false); if (false == $id) { $this->_redirect('restaurant/admin/reservation'); } $ids = explode('_', trim($id, '_')); $objReser = new Models_Reservation(); try { foreach ($ids as $id) { $objReser->delete(array('reservation_id=?' => $id, 'restaurant_id=?' => $resId)); } $this->session->reserMessage = array('success' => true, 'message' => 'Reservation is deleted successfully'); } catch (Exception $e) { $this->session->reserMessage = array('success' => false, 'message' => 'Can NOT delete this reservation. Please try again'); } $this->_redirect('restaurant/reservation/manager'); }