public function saveorderAction()
 {
     //check session
     $laundryCart = new Zend_Session_Namespace('laundryCart');
     $userInfo = new Zend_Session_Namespace('userInfo');
     $model = new Application_Model_OrdersMapper();
     $itemModel = new Application_Model_ItemsMapper();
     $itemPrice = new Application_Model_ItemPriceMapper();
     $orders = new Application_Model_Orders();
     $orderItem = new Application_Model_OrderItems();
     $orderItemModel = new Application_Model_OrderItemsMapper();
     if (isset($laundryCart->service)) {
         $totalPrice = 0;
         foreach ($laundryCart->itemprice as $key => $prices) {
             $totalPrice += $prices * $laundryCart->items[$key];
         }
         //                && isset($userInfo)){
         $orders->__set('order_user_id', 9);
         $orders->__set('order_first_name', 'Ankit');
         $orders->__set('order_last_name', 'Sharma');
         $orders->__set('order_user_email', '*****@*****.**');
         $orders->__set('order_address', 'AH 70');
         //            $orders->__set('order_phone', '123456455');
         $orders->__set('order_city', 'Ghaziabad');
         $orders->__set('order_pincode', '123456');
         $orders->__set('order_delivery_type', $laundryCart->delivery_type);
         $orders->__set('order_pickup', date('Y-m-d', strtotime($laundryCart->pickup_date)));
         $orders->__set('order_delivery', date('Y-m-d', strtotime($laundryCart->delivery_date)));
         $orders->__set('order_delivery_time', $laundryCart->delivery);
         $orders->__set('order_pickup_time', $laundryCart->pickup);
         $orders->__set('order_amount', $totalPrice);
         $orders->__set('order_payment_type', 'cash on delivery');
         $orders->__set('order_payment_status', 'unpaid');
         $orders->__set('order_service_type', implode(',', $laundryCart->service));
         if ($orderId = $model->addNewOrder($orders)) {
             //add products now
             if (isset($laundryCart->items)) {
                 foreach ($laundryCart->items as $item => $quantity) {
                     //get item details
                     $itemDetails = $itemModel->getItemById($item);
                     //save product item
                     $orderItem->__set('order_id', $orderId);
                     $orderItem->__set('order_product_name', $itemDetails->__get('item_name'));
                     $orderItem->__set('order_item_id', $itemDetails->__get('item_id'));
                     $orderItem->__set('order_type', 'service');
                     $orderItem->__set('order_service_name', $laundryCart->itemservice[$item]);
                     $orderItem->__set('order_category_name', $laundryCart->itemcategory[$item]);
                     $orderItem->__set('unit_price', $laundryCart->itemprice[$item]);
                     $orderItem->__set('total_price', $laundryCart->itemprice[$item] * $quantity);
                     $orderItem->__set('quantity', $quantity);
                     $orderItemModel->addNewOrderItem($orderItem);
                 }
             }
             $this->view->message = "Admin added successfully";
             $this->view->hasMessage = true;
             $this->view->messageType = "success";
             //session destroy
             $laundryCart->unsetAll();
             $this->_redirect('');
         } else {
             $this->view->message = "Error occured while adding. Please try again";
             $this->view->hasMessage = true;
             $this->view->messageType = "danger";
         }
     } else {
         exit("error occurred");
     }
 }
Exemplo n.º 2
0
 public function checkoutAction()
 {
     $user_id = 0;
     if ($this->_auth->hasIdentity()) {
         $user_id = $this->_auth->getIdentity()->user_id;
         $this->view->user_id = $user_id;
     }
     $errors = array();
     $request = $this->getRequest();
     //$delivery_type = $request->getParam("delivery_type");
     //$service_name = $request->getParam("service_name");
     //$pickup_date = $request->getParam("pickup_date");
     //$pickup_time = $request->getParam("pickup_time");
     //$delivery_date = $request->getParam("del_date");
     //$delivery_time = $request->getParam("del_time");
     $date_session = new Zend_Session_Namespace("date");
     //print_r($_SESSION);exit;
     $pickup_date = $date_session->pick_date;
     $pickup_time = $date_session->pick_time;
     $delivery_date = $date_session->del_date;
     $delivery_time = $date_session->del_time;
     $service_name = $date_session->service_id;
     $delivery_type = $date_session->del_name;
     $user_package_id = $request->getParam("user_package_id");
     $this->view->user_package_id = $user_package_id;
     //$this->view->del_name = $delivery_type;
     //$this->view->service_id = $service_name;
     //$this->view->date = $pickup_date;
     //$this->view->time = $pickup_time;
     //$this->view->del_time = $delivery_time;
     //$this->view->del_date = $delivery_date;
     $request_type = $request->getParam("request_type", false);
     $addressMapper = new Application_Model_SavedAddressesMapper();
     $usersWalletMapper = new Application_Model_UserWalletMapper();
     $userWallet = new Application_Model_UserWallet();
     $payment_type = $request->getParam("payment_type");
     if ($user_id) {
         $credit_amount = $usersWalletMapper->getUserWalletCreditByUserId($user_id);
         $debit_amount = $usersWalletMapper->getUserWalletDebitByUserId($user_id);
         $wallet_amount = $credit_amount - $debit_amount;
         $wallet_session = new Zend_Session_Namespace("wallet");
         $wallet_session->amount = $wallet_amount;
         $this->view->wallet_amount = $wallet_amount;
         $userPackagesMapper = new Application_Model_UserPackagesMapper();
         $userPackages = $userPackagesMapper->getUserPackageByUserId($user_id);
         $this->view->userPackages = $userPackages;
     }
     if ($request_type) {
         if ($request_type == "item_details") {
             $session_quantity = $request->getParam("qty");
             $session_price = $request->getParam("price");
             $session_items = $request->getParam("items");
             //print_r($session_items);exit;
             $session = new Zend_Session_Namespace("order");
             //print_r($session_quantity);
             $total = 0;
             $i = 0;
             $quantity_total = 0;
             $actual_items = array();
             $actual_qty = array();
             $actual_price = array();
             foreach ($session_items as $item) {
                 $item_id = $item;
                 $qty = $session_quantity[$i];
                 $new_price = $session_price[$i];
                 if ($qty != 0) {
                     $actual_items[] = $item_id;
                     $actual_qty[] = $qty;
                     $actual_price[] = $new_price;
                 }
                 $item_total = $qty * $new_price;
                 $total += $item_total;
                 $quantity_total += $qty;
                 $i++;
             }
             $session->quantity = $actual_qty;
             $session->price = $actual_price;
             $session->items = $actual_items;
             $session->total = $total;
             $session->quantity_total = $quantity_total;
             //print_r($actual_items);exit;
             //print_r($actual_qty);exit;
             //$this->view->actual_qty = $actual_qty;
             //$this->view->actual_items = $actual_items;
             //print_r($_SESSION);
             //exit;
         } elseif ($request_type == "payment_type") {
             $ordersMapper = new Application_Model_OrdersMapper();
             $orders = new Application_Model_Orders();
             $orderItemsMapper = new Application_Model_OrderItemsMapper();
             $orderItems = new Application_Model_OrderItems();
             $savedAddressMapper = new Application_Model_SavedAddressesMapper();
             $session = new Zend_Session_Namespace("order");
             $quantity = $session->quantity;
             $price = $session->price;
             $items = $session->items;
             //print_r($items);exit;
             $i = 0;
             if (empty($payment_type)) {
                 $errors[] = "Select a Payment Type";
             }
             if (count($errors) == 0) {
                 $add_session = new Zend_Session_Namespace("address");
                 $user_name = $add_session->username;
                 $pincode = $add_session->pincode;
                 $landmark = $add_session->landmark;
                 $city = $add_session->city;
                 $address = $add_session->address;
                 $state = $add_session->state;
                 $number = $add_session->phone;
                 $guest_email = $add_session->email;
                 $revised_amount = $request->getParam("revised_amount");
                 $discount_amount = $request->getParam("discount_amount");
                 //$number = $saved->__get("contact_person_phn");
                 //$address = $saved->__get("saved_address");
                 //$locality = $saved->__get("address_locality");
                 //$landmark = $saved->__get("address_landmark");
                 //$city = $saved->__get("address_city");
                 //$state- = $saved->__get("address_state");
                 //$pincode = $saved->__get("address_pincode");
                 //$country = $saved->__get("address_country");
                 if ($user_id) {
                     $usersMapper = new Application_Model_UsersMapper();
                     $user = $usersMapper->getUserById($user_id);
                     $fname = $user->__get("user_fname");
                     $lname = $user->__get("user_lname");
                     $user_email = $user->__get("user_email");
                     $number = $user->__get("user_number");
                     $orders->__set("user_fname", $fname);
                     $orders->__set("user_lname", $lname);
                     $orders->__set("user_email", $user_email);
                     $orders->__set("user_phn_number", $number);
                     $orders->__set("user_address", $address);
                     $orders->__set("address_locality", "");
                     $orders->__set("address_street", "");
                     $orders->__set("address_landmark", $landmark);
                     $orders->__set("address_city", $city);
                     $orders->__set("address_state", $state);
                     $orders->__set("address_country", "India");
                     $orders->__set("address_pincode", $pincode);
                     $orders->__set("payment_method", $payment_type);
                     $orders->__set("payment_status", "Unpaid");
                     $orders->__set("order_status", "New");
                     $orders->__set("order_total", 0);
                     $orders->__set("delivery_type", $delivery_type);
                     $orders->__set("service", $service_name);
                     //echo $pickup_date;exit;
                     $zend_date = new Zend_Date($pickup_date, "dd/MM/yyyy");
                     $pickup_date_new = $zend_date->toString("dd-MMM-yyyy");
                     $orders->__set("pickup_date", $pickup_date_new);
                     $orders->__set("pickup_time", $pickup_time);
                     if ($delivery_type == "Regular") {
                         $zendDate = new Zend_Date($delivery_date, "dd/MM/yyyy");
                         $delivery_date_new = $zendDate->toString("dd-MMM-yyyy");
                     } else {
                         $z_date = $zend_date->addDay(1);
                         $delivery_date_new = $z_date->toString("dd-MMM-yyyy");
                     }
                     if ($delivery_type == "Regular") {
                         $delivery_time = $delivery_time;
                     } else {
                         //$zendDate = new Zend_Date($pickup_time);
                         $delivery_time = "";
                         //echo $delivery_time;exit;
                     }
                     $orders->__set("delivery_date", $delivery_date_new);
                     $orders->__set("delivery_time", $delivery_time);
                 } else {
                     $orders->__set("user_fname", $user_name);
                     $orders->__set("user_lname", "");
                     $orders->__set("user_email", $guest_email);
                     $orders->__set("user_phn_number", $number);
                     $orders->__set("user_address", $address);
                     $orders->__set("address_locality", "");
                     $orders->__set("address_street", "");
                     $orders->__set("address_landmark", $landmark);
                     $orders->__set("address_city", $city);
                     $orders->__set("address_state", $state);
                     $orders->__set("address_country", "India");
                     $orders->__set("address_pincode", $pincode);
                     $orders->__set("payment_method", $payment_type);
                     $orders->__set("payment_status", "Unpaid");
                     $orders->__set("order_status", "New");
                     $orders->__set("order_total", 0);
                     $orders->__set("delivery_type", $delivery_type);
                     $orders->__set("service", $service_name);
                     $zend_date = new Zend_Date($pickup_date, "dd/MM/yyyy");
                     $pickup_date_new = $zend_date->toString("dd-MMM-yyyy");
                     $orders->__set("pickup_date", $pickup_date_new);
                     $orders->__set("pickup_time", $pickup_time);
                     if ($delivery_type == "Regular") {
                         $zendDate = new Zend_Date($delivery_date, "dd/MM/yyyy");
                         $delivery_date_new = $zendDate->toString("dd-MMM-yyyy");
                     } else {
                         $z_date = $zend_date->addDay(1);
                         $delivery_date_new = $z_date->toString("dd-MMM-yyyy");
                     }
                     if ($delivery_type == "Regular") {
                         $delivery_time = $delivery_time;
                     } else {
                         //$zendDate = new Zend_Date($pickup_time);
                         $delivery_time = "";
                         //echo $delivery_time;exit;
                     }
                     $orders->__set("delivery_date", $delivery_date_new);
                     $orders->__set("delivery_time", $delivery_time);
                 }
                 if ($payment_type == "wallet") {
                     $session = new Zend_Session_Namespace("order");
                     $total = $session->total;
                     $q_total = $total = $session->quantity_total;
                     if ($total > $wallet_amount) {
                         $this->view->hasMessage = true;
                         $this->view->messageType = "Danger";
                         $this->view->message = "Insufficient Fund in your Wallet.";
                     } else {
                         $order_id = $ordersMapper->addNewOrder($orders);
                         $total = 0;
                         foreach ($items as $item) {
                             $item_id = $item;
                             $qty = $quantity[$i];
                             $new_price = $price[$i];
                             $item_total = $qty * $new_price;
                             $total += $item_total;
                             $i++;
                             if ($order_id) {
                                 $orderItems->__set("order_id", $order_id);
                                 $orderItems->__set("item_id", $item_id);
                                 $orderItems->__set("quantity", $qty);
                                 $orderItems->__set("total_price", $item_total);
                                 $orderItems->__set("unit_price", $new_price);
                                 $orderItemsMapper->addNewOrderItem($orderItems);
                             }
                         }
                         $orders = $ordersMapper->getOrderById($order_id);
                         if ($total <= 100) {
                             $total_new = $total + 50;
                         } else {
                             $total_new = $total;
                         }
                         $orders->__set("order_total", $total_new);
                         $orders->__set("payment_status", "Paid");
                         $service = $orders->__get("service");
                         $d_date = $orders->__get("delivery_date");
                         if ($discount_amount && $revised_amount) {
                             $orders->__set("discount_price", $discount_amount);
                             $orders->__set("revised_price", $revised_amount);
                             $total_new = $revised_amount;
                         }
                         $sms = "Dear " . $fname . ", Your order " . $order_id . " with QTY " . $q_total . " and amount " . $total_new . " will be ready on " . $d_date . ". Thanks LaundryWala";
                         $sms_result = $this->_smsNotification($number, $sms);
                         $userWallet->__set("user_id", $user_id);
                         $userWallet->__set("entry_type", "DEBIT");
                         $userWallet->__set("entry_amount", $total);
                         $usersWalletMapper->addNewUserWallet($userWallet);
                         $subject = "Order Details From LaundryWala";
                         $message = "<table style='font-size:12px;'>";
                         $message .= "<tbody>";
                         $message .= "<tr><td>Dear Customer ,<br><br></td></tr>";
                         $message .= "<tr><td>Thank you for your association with LaundryWala.We are pleased to provide you details around your recent transaction with us.<br><br></td></tr>";
                         $message .= "<tr><td><strong>Invoice No :</strong>" . $order_id . "</td></tr>";
                         $message .= "<tr><td><strong>Customer Name :</strong>" . $fname . "</td></tr>";
                         $message .= "<tr><td><strong>Address :</strong>" . $address . "</td></tr>";
                         $message .= "<tr><td><strong>Phone No. :</strong><a>" . $number . "</a></td></tr>";
                         if ($orders) {
                             $email = $orders->__get("user_email");
                             $address = $orders->__get("user_address");
                             $city = $orders->__get("address_city");
                             $state = $orders->__get("address_state");
                             $pincode = $orders->__get("address_pincode");
                             $date = $orders->__get("timestamp");
                             $zendDate = new Zend_Date($date, "dd-MMM-yyyy");
                             $date_new = $zendDate->toString("dd-MMM-yyyy");
                             $number = $orders->__get("user_phn_number");
                             $method = $orders->__get("payment_method");
                             $del_date = $orders->__get("delivery_date");
                             $message .= "<tr><td><strong>Booking Date :</strong>" . $date_new . "<br><strong>Payment Mode:</strong>" . $method . "</td></tr>";
                             $message .= "<tr><td><strong>Total Amount Due Rs.:</strong>" . $total_new . "<br></td></tr>";
                             $message .= "<tr><td><strong>Due Delivery Date :</strong>" . $del_date . "</td></tr>";
                             $message .= "<tr><td><strong>Total Pcs. :</strong>" . $q_total . "</td></tr>";
                             $message .= "<tr style='font-size:12px'>";
                             $message .= "<td colspan='4'>";
                             $message .= "<table style='width:7.9in'>";
                             $message .= "<tbody>";
                             $message .= "<tr>";
                             $message .= "<td style='width:0.5in;font-weight:bold;font-size:12px'>S.No.</td>";
                             $message .= "<td style='width:0.5in;font-weight:bold;font-size:12px'>Qty</td>";
                             $message .= "<td style='width:5.0in;font-weight:bold;font-size:12px' align='left'>Particular's</td>";
                             $message .= "<td style='width:1.0in;font-weight:bold' align='right'></td>";
                             $message .= "<td style='width:1.0in;font-weight:bold;font-size:12px' align='right'>Amount</td>";
                             $message .= "</tr>";
                             $message .= "<tr style='font-size:9px'>";
                             $message .= "<td colspan='5' style='font-weight:bold;border-top-style:solid;border-top-width:thin;border-top-color:#000000'></td>";
                             $message .= "</tr>";
                             $orderItemsMapper = new Application_Model_OrderItemsMapper();
                             $items_new = $orderItemsMapper->getOrderItemByOrderId($orders->__get("order_id"));
                             $i = 1;
                             if ($items_new) {
                                 foreach ($items_new as $item) {
                                     $itemsMapper = new Application_Model_ItemsMapper();
                                     $item_name = $itemsMapper->getItemById($item->__get("item_id"));
                                     if ($item_name) {
                                         $name = $item_name->__get("item_name");
                                     } else {
                                         $name = "None";
                                     }
                                     $message .= "<tr style='font-size:12px'>";
                                     $message .= "<td>" . $i++ . "</td>";
                                     $message .= "<td>" . $item->__get("quantity") . "</td>";
                                     $message .= "<td colspan='2'><span style='font-family:arial black;font-size:11px'>" . $name . "</span></td>";
                                     //$message.= "<td align='right'></td>";
                                     $message .= "<td align='right'>Rs." . $item->__get("total_price") . "&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;</td>";
                                     $message .= "</tr>";
                                 }
                             }
                         }
                         $message .= "<tr style='font-size:10px'><td colspan='5'></td></tr>";
                         $message .= "<tr style='font-size:10px'>";
                         $message .= "<td colspan='2'></td>";
                         $message .= "<td align='right' style='font-size:12px;font-weight:bold'>Subtotal</td>";
                         $message .= "<td align='right' style='font-size:12px;font-weight:bold'>Rs." . $total . "</td>";
                         $message .= "</tr>";
                         if ($total <= 100) {
                             $message .= "<tr style='font-size:10px'>";
                             $message .= "<td colspan='3'></td>";
                             $message .= "<td align='right' style='font-size:12px;font-weight:bold'>Amount after Delivery Charges</td>";
                             $message .= "<td align='right' style='font-size:12px;font-weight:bold'>Rs." . $total_new . "</td>";
                             $message .= "</tr>";
                         } else {
                             $message .= "<tr style='font-size:10px'>";
                             $message .= "<td colspan='3'></td>";
                             $message .= "<td align='right' style='font-size:12px;font-weight:bold'>Amount after Discount</td>";
                             if ($discount_amount) {
                                 $message .= "<td align='right' style='font-size:12px;font-weight:bold'>Rs." . $revised_amount . "</td>";
                             } else {
                                 $message .= "<td align='right' style='font-size:12px;font-weight:bold'>Rs." . $total_new . "</td>";
                             }
                             $message .= "</tr>";
                         }
                         $message .= "<tr style='font-size:10px'>";
                         $message .= "<td colspan='3'></td>";
                         $message .= "<td align='right' style='font-size:12px;font-weight:bold'><br></td>";
                         $message .= "<td align='right' style='font-size:12px;font-weight:bold'><br></td>";
                         $message .= "</tr>";
                         $message .= "<tr><td nowrap='' colspan='3'>Assuring you of our best service.</td></tr>";
                         $message .= "<tr><td colspan='3'>Warm Regards.</td></tr>";
                         $message .= "<tr><td colspan='3'>LaundryWala</td></tr>";
                         $message .= "</tbody></table></td></tr></tbody></table>";
                         $this->getMailAction($email, $subject, $message);
                         $this->getMailAction("*****@*****.**", $subject, $message);
                         if ($ordersMapper->updateOrder($orders)) {
                             $this->_helper->redirector('notification', 'checkout');
                             $this->view->hasMessage = true;
                             $this->view->messageType = "success";
                             $this->view->message = "Your Order added sucessfully";
                         } else {
                             $this->view->hasMessage = true;
                             $this->view->messageType = "danger";
                             $this->view->message = "Error";
                         }
                     }
                 } elseif ($payment_type == "package") {
                     $session = new Zend_Session_Namespace("order");
                     $total = $session->total;
                     $quantity_total = $session->quantity_total;
                     if ($user_package_id) {
                         $userPackage = $userPackagesMapper->getUserPackageById($user_package_id);
                         if ($userPackage) {
                             $number_clothes = $userPackage->__get("clothes_left");
                             $number_pickups = $userPackage->__get("pickups_left");
                             if ($quantity_total > $number_clothes) {
                                 $this->view->hasMessage = true;
                                 $this->view->messageType = "Danger";
                                 $this->view->message = "Insufficient Number of clothes.";
                             } else {
                                 $order_id = $ordersMapper->addNewOrder($orders);
                                 $total = 0;
                                 foreach ($items as $item) {
                                     $item_id = $item;
                                     $qty = $quantity[$i];
                                     $new_price = $price[$i];
                                     $item_total = $qty * $new_price;
                                     $total += $item_total;
                                     $i++;
                                     if ($order_id) {
                                         $orderItems->__set("order_id", $order_id);
                                         $orderItems->__set("item_id", $item_id);
                                         $orderItems->__set("quantity", $qty);
                                         $orderItems->__set("total_price", $item_total);
                                         $orderItems->__set("unit_price", $new_price);
                                         $orderItemsMapper->addNewOrderItem($orderItems);
                                     }
                                 }
                                 $orders = $ordersMapper->getOrderById($order_id);
                                 if ($total <= 100) {
                                     $total_new = $total + 50;
                                 } else {
                                     $total_new = $total;
                                 }
                                 $orders->__set("order_total", $total_new);
                                 $orders->__set("payment_status", "Paid");
                                 $service = $orders->__get("service");
                                 $d_date = $orders->__get("delivery_date");
                                 if ($discount_amount && $revised_amount) {
                                     $orders->__set("discount_price", $discount_amount);
                                     $orders->__set("revised_price", $revised_amount);
                                     $total_new = $revised_amount;
                                 }
                                 $sms = "Dear " . $fname . ", Your order " . $order_id . " with QTY " . $quantity_total . " and amount " . $total_new . " will be ready on " . $d_date . ". Thanks LaundryWala";
                                 //$sms_result = $this->_smsNotification($number, $sms);
                                 $clothes_left = $number_clothes - $quantity_total;
                                 $pickups_left = $number_pickups - 1;
                                 $userPackage->__set("clothes_left", $clothes_left);
                                 $userPackage->__set("pickups_left", $pickups_left);
                                 $userPackagesMapper->updateUserPackage($userPackage);
                                 $subject = "Order Details From LaundryWala";
                                 $message = "<table style='font-size:12px;'>";
                                 $message .= "<tbody>";
                                 $message .= "<tr><td>Dear Customer ,<br><br></td></tr>";
                                 $message .= "<tr><td>Thank you for your association with LaundryWala.We are pleased to provide you details around your recent transaction with us.<br><br></td></tr>";
                                 $message .= "<tr><td><strong>Invoice No :</strong>" . $order_id . "</td></tr>";
                                 $message .= "<tr><td><strong>Customer Name :</strong>" . $fname . "</td></tr>";
                                 $message .= "<tr><td><strong>Address :</strong>" . $address . "</td></tr>";
                                 $message .= "<tr><td><strong>Phone No. :</strong><a>" . $number . "</a></td></tr>";
                                 if ($orders) {
                                     $email = $orders->__get("user_email");
                                     $address = $orders->__get("user_address");
                                     $city = $orders->__get("address_city");
                                     $state = $orders->__get("address_state");
                                     $pincode = $orders->__get("address_pincode");
                                     $date = $orders->__get("timestamp");
                                     $zendDate = new Zend_Date($date, "dd-MMM-yyyy");
                                     $date_new = $zendDate->toString("dd-MMM-yyyy");
                                     $number = $orders->__get("user_phn_number");
                                     $method = $orders->__get("payment_method");
                                     $del_date = $orders->__get("delivery_date");
                                     $message .= "<tr><td><strong>Booking Date :</strong>" . $date_new . "<br><strong>Payment Mode:</strong>" . $method . "</td></tr>";
                                     $message .= "<tr><td><strong>Total Amount Due Rs.:</strong>" . $total_new . "<br></td></tr>";
                                     $message .= "<tr><td><strong>Due Delivery Date :</strong>" . $del_date . "</td></tr>";
                                     $message .= "<tr><td><strong>Total Pcs. :</strong>" . $quantity_total . "</td></tr>";
                                     $message .= "<tr style='font-size:12px'>";
                                     $message .= "<td colspan='4'>";
                                     $message .= "<table style='width:7.9in'>";
                                     $message .= "<tbody>";
                                     $message .= "<tr>";
                                     $message .= "<td style='width:0.5in;font-weight:bold;font-size:12px'>S.No.</td>";
                                     $message .= "<td style='width:0.5in;font-weight:bold;font-size:12px'>Qty</td>";
                                     $message .= "<td style='width:5.0in;font-weight:bold;font-size:12px' align='left'>Particular's</td>";
                                     $message .= "<td style='width:1.0in;font-weight:bold' align='right'></td>";
                                     $message .= "<td style='width:1.0in;font-weight:bold;font-size:12px' align='right'>Amount</td>";
                                     $message .= "</tr>";
                                     $message .= "<tr style='font-size:9px'>";
                                     $message .= "<td colspan='5' style='font-weight:bold;border-top-style:solid;border-top-width:thin;border-top-color:#000000'></td>";
                                     $message .= "</tr>";
                                     $orderItemsMapper = new Application_Model_OrderItemsMapper();
                                     $items_new = $orderItemsMapper->getOrderItemByOrderId($orders->__get("order_id"));
                                     $i = 1;
                                     if ($items_new) {
                                         foreach ($items_new as $item) {
                                             $itemsMapper = new Application_Model_ItemsMapper();
                                             $item_name = $itemsMapper->getItemById($item->__get("item_id"));
                                             if ($item_name) {
                                                 $name = $item_name->__get("item_name");
                                             } else {
                                                 $name = "None";
                                             }
                                             $message .= "<tr style='font-size:12px'>";
                                             $message .= "<td>" . $i++ . "</td>";
                                             $message .= "<td>" . $item->__get("quantity") . "</td>";
                                             $message .= "<td><span style='font-family:arial black;font-size:11px'>" . $name . "</span></td>";
                                             $message .= "<td align='right'></td>";
                                             $message .= "<td align='right'>Rs." . $item->__get("total_price") . "&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;</td>";
                                             $message .= "</tr>";
                                         }
                                     }
                                 }
                                 $message .= "<tr style='font-size:10px'><td colspan='5'></td></tr>";
                                 $message .= "<tr style='font-size:10px'>";
                                 $message .= "<td colspan='3'></td>";
                                 $message .= "<td align='right' style='font-size:12px;font-weight:bold'>Subtotal</td>";
                                 $message .= "<td align='right' style='font-size:12px;font-weight:bold'>Rs." . $total . "</td>";
                                 $message .= "</tr>";
                                 if ($total <= 100) {
                                     $message .= "<tr style='font-size:10px'>";
                                     $message .= "<td colspan='3'></td>";
                                     $message .= "<td align='right' style='font-size:12px;font-weight:bold'>Amount after Delivery Charges</td>";
                                     $message .= "<td align='right' style='font-size:12px;font-weight:bold'>Rs." . $total_new . "</td>";
                                     $message .= "</tr>";
                                 } else {
                                     $message .= "<tr style='font-size:10px'>";
                                     $message .= "<td colspan='3'></td>";
                                     $message .= "<td align='right' style='font-size:12px;font-weight:bold'>Amount after Discount</td>";
                                     if ($discount_amount) {
                                         $message .= "<td align='right' style='font-size:12px;font-weight:bold'>Rs." . $revised_amount . "</td>";
                                     } else {
                                         $message .= "<td align='right' style='font-size:12px;font-weight:bold'>Rs." . $total_new . "</td>";
                                     }
                                     $message .= "</tr>";
                                 }
                                 $message .= "<tr style='font-size:10px'>";
                                 $message .= "<td colspan='3'></td>";
                                 $message .= "<td align='right' style='font-size:12px;font-weight:bold'><br></td>";
                                 $message .= "<td align='right' style='font-size:12px;font-weight:bold'><br></td>";
                                 $message .= "</tr>";
                                 $message .= "<tr><td nowrap='' colspan='3'>Assuring you of our best service.</td></tr>";
                                 $message .= "<tr><td colspan='3'>Warm Regards.</td></tr>";
                                 $message .= "<tr><td colspan='3'>LaundryWala</td></tr>";
                                 $message .= "</tbody></table></td></tr></tbody></table>";
                                 $this->getMailAction($email, $subject, $message);
                                 $this->getMailAction("*****@*****.**", $subject, $message);
                                 if ($ordersMapper->updateOrder($orders)) {
                                     $this->_helper->redirector('notification', 'checkout');
                                     $this->view->hasMessage = true;
                                     $this->view->messageType = "success";
                                     $this->view->message = "Your Order added sucessfully";
                                 } else {
                                     $this->view->hasMessage = true;
                                     $this->view->messageType = "danger";
                                     $this->view->message = "Error";
                                 }
                             }
                         }
                     } else {
                         echo "<script>alert('No Package Selected or Available');</script>";
                     }
                     //print_r($userPackage);exit;
                 } elseif ($payment_type == "online-payment") {
                     $session = new Zend_Session_Namespace("order");
                     $total = $session->total;
                     $q_total = $total = $session->quantity_total;
                     $order_id = $ordersMapper->addNewOrder($orders);
                     $total = 0;
                     foreach ($items as $item) {
                         $item_id = $item;
                         $qty = $quantity[$i];
                         $new_price = $price[$i];
                         $item_total = $qty * $new_price;
                         $total += $item_total;
                         $i++;
                         if ($order_id) {
                             $orderItems->__set("order_id", $order_id);
                             $orderItems->__set("item_id", $item_id);
                             $orderItems->__set("quantity", $qty);
                             $orderItems->__set("total_price", $item_total);
                             $orderItems->__set("unit_price", $new_price);
                             $orderItemsMapper->addNewOrderItem($orderItems);
                         }
                     }
                     $orders = $ordersMapper->getOrderById($order_id);
                     if ($total <= 100) {
                         $total_new = $total + 50;
                     } else {
                         $total_new = $total;
                     }
                     $orders->__set("order_total", $total_new);
                     $orders->__set("payment_status", "Unpaid");
                     $service = $orders->__get("service");
                     $d_date = $orders->__get("delivery_date");
                     if ($discount_amount && $revised_amount) {
                         $orders->__set("discount_price", $discount_amount);
                         $orders->__set("revised_price", $revised_amount);
                         $total_new = $revised_amount;
                     }
                     $sms = "Dear " . $fname . ", Your order " . $order_id . " with QTY " . $q_total . " and amount " . $total_new . " will be ready on " . $d_date . ". Thanks LaundryWala";
                     $sms_result = $this->_smsNotification($number, $sms);
                     $subject = "Order Details From LaundryWala";
                     $message = "<table style='font-size:12px;'>";
                     $message .= "<tbody>";
                     $message .= "<tr><td>Dear Customer ,<br><br></td></tr>";
                     $message .= "<tr><td>Thank you for your association with LaundryWala.We are pleased to provide you details around your recent transaction with us.<br><br></td></tr>";
                     $message .= "<tr><td><strong>Invoice No :</strong>" . $order_id . "</td></tr>";
                     $message .= "<tr><td><strong>Customer Name :</strong>" . $fname . "</td></tr>";
                     $message .= "<tr><td><strong>Address :</strong>" . $address . "</td></tr>";
                     $message .= "<tr><td><strong>Phone No. :</strong><a>" . $number . "</a></td></tr>";
                     if ($orders) {
                         $email = $orders->__get("user_email");
                         $address = $orders->__get("user_address");
                         $city = $orders->__get("address_city");
                         $state = $orders->__get("address_state");
                         $pincode = $orders->__get("address_pincode");
                         $date = $orders->__get("timestamp");
                         $zendDate = new Zend_Date($date, "dd-MMM-yyyy");
                         $date_new = $zendDate->toString("dd-MMM-yyyy");
                         $number = $orders->__get("user_phn_number");
                         $method = $orders->__get("payment_method");
                         $del_date = $orders->__get("delivery_date");
                         $message .= "<tr><td><strong>Booking Date :</strong>" . $date_new . "<br><strong>Payment Mode:</strong>" . $method . "</td></tr>";
                         $message .= "<tr><td><strong>Total Amount Due Rs.:</strong>" . $total_new . "<br></td></tr>";
                         $message .= "<tr><td><strong>Due Delivery Date :</strong>" . $del_date . "</td></tr>";
                         $message .= "<tr><td><strong>Total Pcs. :</strong>" . $q_total . "</td></tr>";
                         $message .= "<tr style='font-size:12px'>";
                         $message .= "<td colspan='4'>";
                         $message .= "<table style='width:7.9in'>";
                         $message .= "<tbody>";
                         $message .= "<tr>";
                         $message .= "<td style='width:0.5in;font-weight:bold;font-size:12px'>S.No.</td>";
                         $message .= "<td style='width:0.5in;font-weight:bold;font-size:12px'>Qty</td>";
                         $message .= "<td style='width:5.0in;font-weight:bold;font-size:12px' align='left'>Particular's</td>";
                         $message .= "<td style='width:1.0in;font-weight:bold' align='right'></td>";
                         $message .= "<td style='width:1.0in;font-weight:bold;font-size:12px' align='right'>Amount</td>";
                         $message .= "</tr>";
                         $message .= "<tr style='font-size:9px'>";
                         $message .= "<td colspan='5' style='font-weight:bold;border-top-style:solid;border-top-width:thin;border-top-color:#000000'></td>";
                         $message .= "</tr>";
                         $orderItemsMapper = new Application_Model_OrderItemsMapper();
                         $items_new = $orderItemsMapper->getOrderItemByOrderId($orders->__get("order_id"));
                         $i = 1;
                         if ($items_new) {
                             foreach ($items_new as $item) {
                                 $itemsMapper = new Application_Model_ItemsMapper();
                                 $item_name = $itemsMapper->getItemById($item->__get("item_id"));
                                 if ($item_name) {
                                     $name = $item_name->__get("item_name");
                                 } else {
                                     $name = "None";
                                 }
                                 $message .= "<tr style='font-size:12px'>";
                                 $message .= "<td>" . $i++ . "</td>";
                                 $message .= "<td>" . $item->__get("quantity") . "</td>";
                                 $message .= "<td><span style='font-family:arial black;font-size:11px'>" . $name . "</span></td>";
                                 $message .= "<td align='right'></td>";
                                 $message .= "<td align='right'>Rs." . $item->__get("total_price") . "&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;</td>";
                                 $message .= "</tr>";
                             }
                         }
                     }
                     $message .= "<tr style='font-size:10px'><td colspan='5'></td></tr>";
                     $message .= "<tr style='font-size:10px'>";
                     $message .= "<td colspan='3'></td>";
                     $message .= "<td align='right' style='font-size:12px;font-weight:bold'>Subtotal</td>";
                     $message .= "<td align='right' style='font-size:12px;font-weight:bold'>Rs." . $total . "</td>";
                     $message .= "</tr>";
                     if ($total <= 100) {
                         $message .= "<tr style='font-size:10px'>";
                         $message .= "<td colspan='3'></td>";
                         $message .= "<td align='right' style='font-size:12px;font-weight:bold'>Amount after Delivery Charges</td>";
                         $message .= "<td align='right' style='font-size:12px;font-weight:bold'>Rs." . $total_new . "</td>";
                         $message .= "</tr>";
                     } else {
                         $message .= "<tr style='font-size:10px'>";
                         $message .= "<td colspan='3'></td>";
                         $message .= "<td align='right' style='font-size:12px;font-weight:bold'>Amount after Discount</td>";
                         if ($discount_amount) {
                             $message .= "<td align='right' style='font-size:12px;font-weight:bold'>Rs." . $revised_amount . "</td>";
                         } else {
                             $message .= "<td align='right' style='font-size:12px;font-weight:bold'>Rs." . $total_new . "</td>";
                         }
                         $message .= "</tr>";
                     }
                     $message .= "<tr style='font-size:10px'>";
                     $message .= "<td colspan='3'></td>";
                     $message .= "<td align='right' style='font-size:12px;font-weight:bold'><br></td>";
                     $message .= "<td align='right' style='font-size:12px;font-weight:bold'><br></td>";
                     $message .= "</tr>";
                     $message .= "<tr><td nowrap='' colspan='3'>Assuring you of our best service.</td></tr>";
                     $message .= "<tr><td colspan='3'>Warm Regards.</td></tr>";
                     $message .= "<tr><td colspan='3'>LaundryWala</td></tr>";
                     $message .= "</tbody></table></td></tr></tbody></table>";
                     $this->getMailAction($email, $subject, $message);
                     $this->getMailAction("*****@*****.**", $subject, $message);
                     if ($ordersMapper->updateOrder($orders)) {
                         $this->view->hasMessage = true;
                         $this->view->messageType = "success";
                         $this->view->message = "Your Order added sucessfully";
                     } else {
                         $this->view->hasMessage = true;
                         $this->view->messageType = "danger";
                         $this->view->message = "Error";
                     }
                     if ($guest_email) {
                         $this->_redirect('/payment/index/order_id/' . $order_id . '/email/' . $guest_email . '/name/' . $user_name . '/number/' . $number);
                     } else {
                         $this->_redirect('/payment/index/order_id/' . $order_id);
                     }
                 } else {
                     $order_id = $ordersMapper->addNewOrder($orders);
                     $session = new Zend_Session_Namespace("order");
                     $q_total = $total = $session->quantity_total;
                     $total = 0;
                     foreach ($items as $item) {
                         $item_id = $item;
                         $qty = $quantity[$i];
                         $new_price = $price[$i];
                         $item_total = $qty * $new_price;
                         $total += $item_total;
                         $i++;
                         $amount_session = new Zend_Session_Namespace("total_amount");
                         $amount_session->total_amount = $total;
                         if ($order_id) {
                             $orderItems->__set("order_id", $order_id);
                             $orderItems->__set("item_id", $item_id);
                             $orderItems->__set("quantity", $qty);
                             $orderItems->__set("total_price", $item_total);
                             $orderItems->__set("unit_price", $new_price);
                             $orderItemsMapper->addNewOrderItem($orderItems);
                         }
                     }
                     $orders = $ordersMapper->getOrderById($order_id);
                     if ($total <= 100) {
                         $total_new = $total + 50;
                     } else {
                         $total_new = $total;
                     }
                     $orders->__set("order_total", $total_new);
                     $orders->__set("payment_status", "Unpaid");
                     $service = $orders->__get("service");
                     $d_date = $orders->__get("delivery_date");
                     if ($discount_amount && $revised_amount) {
                         $orders->__set("discount_price", $discount_amount);
                         $orders->__set("revised_price", $revised_amount);
                         $total_new = $revised_amount;
                     }
                     $sms = "Dear " . $fname . ", Your order " . $order_id . " with QTY " . $q_total . " and amount Rs. " . $total_new . " will be ready on " . $d_date . ". Thanks LaundryWala";
                     //$sms = "Dear Divya, Your order 12 with QTY 12 and amount Rs. 200 will be ready on 12. Thanks LaundryWala";
                     $sms_result = $this->_smsNotification($number, $sms);
                     $subject = "Order Details From LaundryWala";
                     $message = "<table style='font-size:12px;'>";
                     $message .= "<tbody>";
                     $message .= "<tr><td>Dear Customer ,<br><br></td></tr>";
                     $message .= "<tr><td>Thank you for your association with LaundryWala.We are pleased to provide you details around your recent transaction with us.<br><br></td></tr>";
                     $message .= "<tr><td><strong>Invoice No :</strong>" . $order_id . "</td></tr>";
                     $message .= "<tr><td><strong>Customer Name :</strong>" . $fname . "</td></tr>";
                     $message .= "<tr><td><strong>Address :</strong>" . $address . "</td></tr>";
                     $message .= "<tr><td><strong>Phone No. :</strong><a>" . $number . "</a></td></tr>";
                     if ($orders) {
                         $email = $orders->__get("user_email");
                         $address = $orders->__get("user_address");
                         $city = $orders->__get("address_city");
                         $state = $orders->__get("address_state");
                         $pincode = $orders->__get("address_pincode");
                         $date = $orders->__get("timestamp");
                         $zendDate = new Zend_Date($date, "dd-MMM-yyyy");
                         $date_new = $zendDate->toString("dd-MMM-yyyy");
                         $number = $orders->__get("user_phn_number");
                         $method = $orders->__get("payment_method");
                         $del_date = $orders->__get("delivery_date");
                         $message .= "<tr><td><strong>Booking Date :</strong>" . $date_new . "<br><strong>Payment Mode:</strong>" . $method . "</td></tr>";
                         $message .= "<tr><td><strong>Total Amount Due Rs.:</strong>" . $total_new . "<br></td></tr>";
                         $message .= "<tr><td><strong>Due Delivery Date :</strong>" . $del_date . "</td></tr>";
                         $message .= "<tr><td><strong>Total Pcs. :</strong>" . $q_total . "</td></tr>";
                         $message .= "<tr style='font-size:12px'>";
                         $message .= "<td colspan='4'>";
                         $message .= "<table style='width:7.9in'>";
                         $message .= "<tbody>";
                         $message .= "<tr>";
                         $message .= "<td style='width:0.5in;font-weight:bold;font-size:12px'>S.No.</td>";
                         $message .= "<td style='width:0.5in;font-weight:bold;font-size:12px'>Qty</td>";
                         $message .= "<td style='width:5.0in;font-weight:bold;font-size:12px' align='left'>Particular's</td>";
                         $message .= "<td style='width:1.0in;font-weight:bold' align='right'></td>";
                         $message .= "<td style='width:1.0in;font-weight:bold;font-size:12px' align='right'>Amount</td>";
                         $message .= "</tr>";
                         $message .= "<tr style='font-size:9px'>";
                         $message .= "<td colspan='5' style='font-weight:bold;border-top-style:solid;border-top-width:thin;border-top-color:#000000'></td>";
                         $message .= "</tr>";
                         $orderItemsMapper = new Application_Model_OrderItemsMapper();
                         $items_new = $orderItemsMapper->getOrderItemByOrderId($orders->__get("order_id"));
                         $i = 1;
                         if ($items_new) {
                             foreach ($items_new as $item) {
                                 $itemsMapper = new Application_Model_ItemsMapper();
                                 $item_name = $itemsMapper->getItemById($item->__get("item_id"));
                                 if ($item_name) {
                                     $name = $item_name->__get("item_name");
                                 } else {
                                     $name = "None";
                                 }
                                 $message .= "<tr style='font-size:12px'>";
                                 $message .= "<td>" . $i++ . "</td>";
                                 $message .= "<td>" . $item->__get("quantity") . "</td>";
                                 $message .= "<td><span style='font-family:arial black;font-size:11px'>" . $name . "</span></td>";
                                 $message .= "<td align='right'></td>";
                                 $message .= "<td align='right'>Rs." . $item->__get("total_price") . "&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;</td>";
                                 $message .= "</tr>";
                             }
                         }
                     }
                     $message .= "<tr style='font-size:10px'><td colspan='5'></td></tr>";
                     $message .= "<tr style='font-size:10px'>";
                     $message .= "<td colspan='3'></td>";
                     $message .= "<td align='right' style='font-size:12px;font-weight:bold'>Subtotal</td>";
                     $message .= "<td align='right' style='font-size:12px;font-weight:bold'>Rs." . $total . "</td>";
                     $message .= "</tr>";
                     if ($total <= 100) {
                         $message .= "<tr style='font-size:10px'>";
                         $message .= "<td colspan='3'></td>";
                         $message .= "<td align='right' style='font-size:12px;font-weight:bold'>Amount after Delivery Charges</td>";
                         $message .= "<td align='right' style='font-size:12px;font-weight:bold'>Rs." . $total_new . "</td>";
                         $message .= "</tr>";
                     } else {
                         $message .= "<tr style='font-size:10px'>";
                         $message .= "<td colspan='3'></td>";
                         $message .= "<td align='right' style='font-size:12px;font-weight:bold'>Amount after Discount</td>";
                         if ($discount_amount) {
                             $message .= "<td align='right' style='font-size:12px;font-weight:bold'>Rs." . $revised_amount . "</td>";
                         } else {
                             $message .= "<td align='right' style='font-size:12px;font-weight:bold'>Rs." . $total_new . "</td>";
                         }
                         $message .= "</tr>";
                     }
                     $message .= "<tr style='font-size:10px'>";
                     $message .= "<td colspan='3'></td>";
                     $message .= "<td align='right' style='font-size:12px;font-weight:bold'><br></td>";
                     $message .= "<td align='right' style='font-size:12px;font-weight:bold'><br></td>";
                     $message .= "</tr>";
                     $message .= "<tr><td nowrap='' colspan='3'>Assuring you of our best service.</td></tr>";
                     $message .= "<tr><td colspan='3'>Warm Regards.</td></tr>";
                     $message .= "<tr><td colspan='3'>LaundryWala</td></tr>";
                     $message .= "</tbody></table></td></tr></tbody></table>";
                     $this->getMailAction($email, $subject, $message);
                     $this->getMailAction("*****@*****.**", $subject, $message);
                     if ($ordersMapper->updateOrder($orders)) {
                         $this->_helper->redirector('notification', 'checkout');
                         $this->view->hasMessage = true;
                         $this->view->messageType = "success";
                         $this->view->message = "Your Order added sucessfully";
                     } else {
                         $this->view->hasMessage = true;
                         $this->view->messageType = "danger";
                         $this->view->message = "Error";
                     }
                 }
             } else {
                 $errorString = "";
                 foreach ($errors as $error) {
                     $errorString .= $error . "<br/>";
                 }
                 $this->view->hasMessage = true;
                 $this->view->messageType = "danger";
                 $this->view->message = $errorString;
             }
         }
     }
 }
Exemplo n.º 3
0
 public function editAction()
 {
     try {
         $ordersMapper = new Application_Model_OrdersMapper();
         $orderItemsMapper = new Application_Model_OrderItemsMapper();
         $request = $this->getRequest();
         $order_id = $request->getParam("id");
         $this->view->order_id = $order_id;
         $orders = $ordersMapper->getOrderById($order_id);
         $this->view->orders = $orders;
         if ($orders) {
             if ($request->isPost()) {
                 $request_type = $request->getParam("request_type", false);
                 if ($request_type) {
                     if ($request_type == "update_order_info") {
                         $user_name = $request->getParam("user_name");
                         $user_address = $request->getParam("user_address");
                         $user_number = $request->getParam("user_number");
                         $delivery_type = $request->getParam("delivery_type");
                         $service_id = $request->getParam("service_id");
                         $errors = array();
                         if (empty($user_name)) {
                             $errors[] = "Username is empty";
                         }
                         if (empty($user_number)) {
                             $errors[] = "Phone number is empty";
                         }
                         if (empty($user_address)) {
                             $errors[] = "Address is empty";
                         }
                         if (empty($delivery_type)) {
                             $errors[] = "Delivering Type is not selected";
                         }
                         if (empty($service_id)) {
                             $errors[] = "Service is not selected";
                         }
                         if (count($errors) == 0) {
                             $orders->__set("user_fname", $user_name);
                             $orders->__set("user_phn_number", $user_number);
                             $orders->__set("user_address", $user_address);
                             $orders->__set("delivery_type", $delivery_type);
                             $orders->__set("service", $service_id);
                             if ($ordersMapper->updateOrder($orders)) {
                                 $this->view->hasMessage = true;
                                 $this->view->messageType = "success";
                                 $this->view->message = "Successfully update order info";
                             } else {
                                 $this->view->hasMessage = true;
                                 $this->view->messageType = "dnager";
                                 $this->view->message = "Error while updating the order info";
                             }
                         } else {
                             $errorString = "";
                             foreach ($errors as $error) {
                                 $errorString .= $error . "<br/>";
                             }
                             $this->view->hasMessage = true;
                             $this->view->messageType = "danger";
                             $this->view->message = $errorString;
                         }
                     } elseif ($request_type == "update_qty") {
                         $total_price = 0;
                         $order_item_id = $request->getParam("order_item_id");
                         $qty = $request->getParam("qty");
                         $order_item = $orderItemsMapper->getOrderItemById($order_item_id);
                         if ($order_item) {
                             if ($qty) {
                                 $unit_price = $order_item->__get("unit_price");
                                 $new_price = $qty * $unit_price;
                                 $new_qty = $qty;
                                 $order_item->__set("quantity", $qty);
                                 $order_item->__set("total_price", $new_price);
                                 if ($orderItemsMapper->updateOrderItem($order_item)) {
                                     $orderItems = $orderItemsMapper->getOrderItemByOrderId($order_id);
                                     foreach ($orderItems as $item) {
                                         $total_price += $item->__get("total_price");
                                     }
                                     $orders->__set("order_total", $total_price);
                                     $ordersMapper->updateOrder($orders);
                                     $this->view->hasMessage = true;
                                     $this->view->messageType = "success";
                                     $this->view->message = "Successfully update Item quantity";
                                 } else {
                                     $this->view->hasMessage = true;
                                     $this->view->messageType = "success";
                                     $this->view->message = "error while updating qty";
                                 }
                             }
                         }
                     } elseif ($request_type == "delete") {
                         $item_id = $request->getParam("item_id");
                         $order_item = $orderItemsMapper->getOrderItemById($item_id);
                         $price = $order_item->__get("total_price");
                         $order_total = $orders->__get("order_total");
                         if ($orderItemsMapper->deleteOrderItemById($item_id)) {
                             $new_price = $order_total - $price;
                             $orders->__set("order_total", $new_price);
                             $ordersMapper->updateOrder($orders);
                             $this->view->hasMessage = true;
                             $this->view->messageType = "success";
                             $this->view->message = "Successfully deleted item";
                         } else {
                             $this->view->hasMessage = true;
                             $this->view->messageType = "success";
                             $this->view->message = "Error while deleting";
                         }
                     } elseif ($request_type == "order_item_add") {
                         $total_price = 0;
                         $category_id = $request->getParam("category_id");
                         $service_id = $request->getParam("service_id");
                         $item_id = $request->getParam("item_id");
                         $quantity = $request->getParam("quantity");
                         $itemPriceMapper = new Application_Model_ItemPriceMapper();
                         $orderItems = new Application_Model_OrderItems();
                         $errors = array();
                         if ($category_id == "none") {
                             $errors[] = "Please Select a category";
                         }
                         if ($service_id == "none") {
                             $errors[] = "Please Select a service";
                         }
                         if ($item_id == "none") {
                             $errors[] = "Please Select a item";
                         }
                         if (empty($quantity)) {
                             $errors[] = "Please enter quantity";
                         }
                         if (count($errors) == 0) {
                             $itemPrice = $itemPriceMapper->getItemPriceByItemId($item_id);
                             $item_price = $itemPrice->__get("price");
                             $price = $item_price * $quantity;
                             $orderItems->__set("order_id", $order_id);
                             $orderItems->__set("item_id", $item_id);
                             $orderItems->__set("quantity", $quantity);
                             $orderItems->__set("unit_price", $item_price);
                             $orderItems->__set("total_price", $price);
                             if ($orderItemsMapper->addNewOrderItem($orderItems)) {
                                 $orderItems = $orderItemsMapper->getOrderItemByOrderId($order_id);
                                 foreach ($orderItems as $item) {
                                     $total_price += $item->__get("total_price");
                                 }
                                 $orders->__set("order_total", $total_price);
                                 $ordersMapper->updateOrder($orders);
                                 $this->view->hasMessage = true;
                                 $this->view->messageType = "success";
                                 $this->view->message = "Successfully add";
                             } else {
                                 $this->view->hasMessage = true;
                                 $this->view->messageType = "danger";
                                 $this->view->message = "Error while add";
                             }
                         } else {
                             $errorString = "";
                             foreach ($errors as $error) {
                                 $errorString .= $error . "<br/>";
                             }
                             $this->view->hasMessage = true;
                             $this->view->messageType = "danger";
                             $this->view->message = $errorString;
                         }
                     }
                 }
             }
         }
         $orderItems = $orderItemsMapper->getOrderItemByOrderId($order_id);
         $this->view->orderItems = $orderItems;
         $this->authorised = true;
     } catch (Exception $ex) {
         $this->authorised = false;
         $this->view->hasMessage = true;
         $this->view->messageType = "danger";
         $this->view->message = $ex->getMessage();
     }
 }
Exemplo n.º 4
0
 public function orderpackageAction()
 {
     if ($this->getRequest()->isPost()) {
         $post = $this->getRequest()->getPost();
         $userTrackId = $post['trackId'];
         $userInfo = new Zend_Session_Namespace('userInfo');
         $model = new Application_Model_OrdersMapper();
         //get usertrack details
         $userTrackModel = new Application_Model_UserTrackMapper();
         $userTrackDetail = $userTrackModel->getUserPackageById($userTrackId);
         //get order package details
         $packageDetails = new Application_Model_PackagesMapper();
         $packageDetails = $packageDetails->getPackageById($userTrackDetail->usertrack_package_id);
         $orders = new Application_Model_Orders();
         $orders->__set('order_user_id', $userInfo->user_id);
         $orders->__set('order_first_name', $userInfo->user_fname);
         $orders->__set('order_last_name', $userInfo->user_lname);
         //            $orders->__set('order_user_email', '*****@*****.**');
         $orders->__set('order_address', $userTrackDetail->usertrack_house . " ," . $userTrackDetail->usertrack_locality);
         $orders->__set('order_city', $userTrackDetail->usertrack_city);
         //TO DO - dynamic delivery type
         $orders->__set('order_delivery_type', 5);
         $orders->__set('order_pickup', date('Y-m-d', strtotime($post['pickupDate'])));
         $orders->__set('order_delivery', date('Y-m-d', strtotime($post['deliveryDate'])));
         $orders->__set('order_delivery_time', $post['deliveryTimeSlot']);
         $orders->__set('order_pickup_time', $post['pickupTimeSlot']);
         //            $orders->__set('order_amount', $post['order_amount']);
         $orders->__set('order_payment_type', 'cash on delivery');
         $orders->__set('order_payment_status', 'paid');
         $orders->__set('order_service_type', $packageDetails->package_service_type);
         $orders->__set('order_type', 'package');
         if ($orderId = $model->addNewOrder($orders)) {
             $orderItem = new Application_Model_OrderItems();
             $orderItemModel = new Application_Model_OrderItemsMapper();
             //save product item
             $orderItem->__set('order_id', $orderId);
             $orderItem->__set('order_product_name', $packageDetails->__get('package_name'));
             $orderItem->__set('order_item_id', $packageDetails->__get('package_id'));
             $orderItem->__set('order_package_id', $packageDetails->__get('package_id'));
             $orderItem->__set('order_type', 'package');
             //                $orderItem->__set('order_service_name',$laundryCart->itemservice[$item]);
             //                $orderItem->__set('order_category_name',$laundryCart->itemcategory[$item]);
             //                $orderItem->__set('unit_price',$laundryCart->itemprice[$item]);
             //                $orderItem->__set('total_price',$laundryCart->itemprice[$item]*$quantity);
             //                $orderItem->__set('quantity',$quantity);
             $orderItemModel->addNewOrderItem($orderItem);
             $this->_redirect('index/orderlist');
         } else {
             $this->view->message = "Error occured while adding. Please try again";
             $this->view->hasMessage = true;
             $this->view->messageType = "danger";
         }
         //            $userTrackDetail->usertrack_package_id
         //            echo '<pre>'; print_r($post); exit('Macro die');
     } else {
     }
 }
Exemplo n.º 5
0
 public function saveorderAction()
 {
     //check session
     $laundryCart = new Zend_Session_Namespace('laundryCart');
     $userInfo = new Zend_Session_Namespace('userInfo');
     $model = new Application_Model_OrdersMapper();
     $itemModel = new Application_Model_ItemsMapper();
     $itemPrice = new Application_Model_ItemPriceMapper();
     $orderItem = new Application_Model_OrderItems();
     $orderItemModel = new Application_Model_OrderItemsMapper();
     $post = $this->getRequest()->getPost();
     if ($laundryCart->orderType == 'service' && $this->getRequest()->isPost()) {
         //get delivery type
         $deliveryTypeMaster = new Application_Model_DeliveryTypeMasterMapper();
         $deliveryTypes = $deliveryTypeMaster->getAllDeliveryTypeMaster();
         $deliveryArr = array();
         foreach ($deliveryTypes as $del) {
             $deliveryArr[$del->__get('delivery_type_name')] = $del->__get('delivery_type_id');
         }
         if (!isset($laundryCart->delivery_type)) {
             $laundryCart->delivery_type = 'Regular';
         }
         $totalPrice = 0;
         foreach ($laundryCart->itemprice as $key => $prices) {
             $totalPrice += $prices * $laundryCart->items[$key];
         }
         $orders = new Application_Model_Orders();
         //                && isset($userInfo)){
         $orders->__set('order_user_id', $userInfo->user_id);
         $orders->__set('order_first_name', $userInfo->user_fname);
         $orders->__set('order_last_name', $userInfo->user_lname);
         //            $orders->__set('order_user_email', '*****@*****.**');
         $orders->__set('order_address', implode(",", $laundryCart->address));
         //            $orders->__set('order_phone', '123456455');
         $orders->__set('order_city', $laundryCart->city);
         //            $orders->__set('order_pincode', '123456');
         $orders->__set('order_delivery_type', $deliveryArr[$laundryCart->delivery_type]);
         $orders->__set('order_pickup', date('Y-m-d', strtotime($laundryCart->pickup_date)));
         $orders->__set('order_delivery', date('Y-m-d', strtotime($laundryCart->delivery_date)));
         $orders->__set('order_delivery_time', $laundryCart->delivery);
         $orders->__set('order_pickup_time', $laundryCart->pickup);
         $orders->__set('order_amount', $post['order_amount']);
         $orders->__set('order_payment_type', 'cash on delivery');
         $orders->__set('delivery_charge', $post['delivery_charge']);
         $orders->__set('service_tax', $post['service_tax']);
         $orders->__set('order_payment_status', 'unpaid');
         $orders->__set('order_service_type', implode(',', $laundryCart->service));
         $orders->__set('order_type', 'service');
         $orders->__set('order_mobile_number', $post['order_mobile_number']);
         //TO DO - delivery boy allotted
         $orders->__set('order_pickup_boy', '1');
         $orders->__set('order_delivery_boy', '1');
         /* Apply coupon code */
         if ($post['couponcode'] != "") {
             $couponCode = $post['couponcode'];
             $CouponsMapperModel = new Application_Model_CouponsMapper();
             $couponData = $CouponsMapperModel->getCouponByCouponCode($couponCode);
             $namespace = new Zend_Session_Namespace('userInfo');
             if (!empty($couponData)) {
                 $isAllowedResult = $this->isCouponAllowedToUse($namespace->user_id, $couponData->__get("coupon_id"));
                 if ($isAllowedResult->allowed === true) {
                     if ($post['order_amount'] >= $couponData->__get("coupon_min_billing")) {
                         $discountAmount = $couponData->__get("coupon_value");
                         if ($couponData->__get("coupon_type") == "percentage") {
                             $discountAmount = $post['order_amount'] * $couponData->__get("coupon_value") / 100;
                         }
                         if ($discountAmount > $couponData->__get("coupon_max_discount") && $couponData->__get("coupon_max_discount") > 0) {
                             $discountAmount = $couponData->__get("coupon_max_discount");
                         }
                         $orders->__set('order_coupon_id', $couponData->__get("coupon_id"));
                         $orders->__set('order_coupon_dis', $discountAmount);
                     }
                 }
             }
         }
         /* Apply coupon code */
         if ($orderId = $model->addNewOrder($orders)) {
             //add products now
             if (isset($laundryCart->items)) {
                 foreach ($laundryCart->items as $item => $quantity) {
                     //get item details
                     $itemDetails = $itemPrice->getItemPriceById($item);
                     $itemDetails = $itemModel->getItemById($itemDetails->__get('item_id'));
                     //save product item
                     $orderItem->__set('order_id', $orderId);
                     $orderItem->__set('order_product_name', $itemDetails->__get('item_name'));
                     $orderItem->__set('order_item_id', $itemDetails->__get('item_id'));
                     $orderItem->__set('order_type', 'service');
                     $orderItem->__set('order_service_name', $laundryCart->itemservice[$item]);
                     $orderItem->__set('order_category_name', $laundryCart->itemcategory[$item]);
                     $orderItem->__set('unit_price', $laundryCart->itemprice[$item]);
                     $orderItem->__set('total_price', $laundryCart->itemprice[$item] * $quantity);
                     $orderItem->__set('quantity', $quantity);
                     $orderItemModel->addNewOrderItem($orderItem);
                 }
             }
             $this->view->message = "Order successfully completed";
             $this->view->hasMessage = true;
             $this->view->messageType = "success";
             //session destroy
             $laundryCart->unsetAll();
             if (isset($post['onlinepayment']) && $post['onlinepayment'] == 'false') {
                 $this->_redirect('index/orderlist');
             } else {
                 $this->_redirect('payment/index?order_id=' . $orderId . '&transaction_type=Online');
             }
         } else {
             $this->view->message = "Error occured while adding. Please try again";
             $this->view->hasMessage = true;
             $this->view->messageType = "danger";
         }
     } elseif ($laundryCart->orderType == 'package' && $this->getRequest()->isPost()) {
         //get package details
         $packageDetails = new Application_Model_PackagesMapper();
         $packageDetails = $packageDetails->getPackageById($laundryCart->package[0]);
         $validity = $packageDetails->__get('validity');
         $userTrack = new Application_Model_UserTrack();
         $userTrackMapper = new Application_Model_UserTrackMapper();
         $userTrack->__set('usertrack_user_id', $userInfo->user_id);
         $userTrack->__set('track_type', 'package');
         $userTrack->__set('usertrack_package_id', $laundryCart->package[0]);
         $userTrack->__set('clothes_left', $packageDetails->__get('no_of_clothes'));
         $userTrack->__set('clothes_availed', $packageDetails->__get('no_of_clothes'));
         $userTrack->__set('pickups_left', $packageDetails->__get('no_of_pickups'));
         $userTrack->__set('pickups_availed', $packageDetails->__get('no_of_pickups'));
         $userTrack->__set('usertrack_start_date', date('Y-m-d'));
         $userTrack->__set('usertrack_expiry_date', date('Y-m-d', strtotime("+{$validity} Month " . date('Y-m-d'))));
         $userTrack->__set('usertrack_house', $laundryCart->address[0]);
         $userTrack->__set('usertrack_locality', $laundryCart->address[1]);
         $userTrack->__set('usertrack_city', $laundryCart->address[2]);
         $userTrackMapper->addNewTrack($userTrack);
         $this->view->message = "Package successfully subscribed";
         $this->view->hasMessage = true;
         $this->view->messageType = "success";
         //session destroy
         $laundryCart->unsetAll();
         $orderSession->unsetAll();
         if (isset($post['onlinepayment']) && $post['onlinepayment'] == 'false') {
             $this->_redirect('index/orderlist');
         } else {
             $this->_redirect('payment/index?&package_id=' . $laundryCart->package[0] . '&transaction_type=Package');
         }
     } else {
         exit("error occurred");
     }
 }