Esempio n. 1
0
 public function indexAction()
 {
     try {
         $order_form = new Application_Form_OrdersForm();
         $this->view->form = $order_form;
         $ordersMapper = new Application_Model_OrdersMapper();
         $order = new Application_Model_Orders();
         $model = new Application_Model_OrdersMapper();
         $orderItem = new Application_Model_OrderItems();
         $request = $this->getRequest();
         if ($request->isPost()) {
             $request_type = $request->getParam("request_type", false);
             if ($request_type) {
                 if ($request_type == "add") {
                     $params = $request->getParams();
                     //                        echo '<pre>'; print_r(get_class_methods($order_form)); exit('Macro die');
                     //                        echo '<pre>'; print_r($order_form->getErrors($params)); exit('Macro die');
                     if ($order_form->isValid($params)) {
                         foreach ($params as $param => $value) {
                             if ($param == 'order_service_type') {
                                 $value = implode(',', $value);
                             }
                             $order->__set($param, $value);
                         }
                         $post = $params;
                         //add package
                         if ($params['order_type'] == 'package') {
                             //get package details
                             $packageDetails = new Application_Model_PackagesMapper();
                             $packageDetails = $packageDetails->getPackageById($params['order_package']);
                             $validity = $packageDetails->__get('validity');
                             $userTrack = new Application_Model_UserTrack();
                             $userTrackMapper = new Application_Model_UserTrackMapper();
                             $userTrack->__set('usertrack_user_id', $params['order_user_id']);
                             $userTrack->__set('track_type', 'package');
                             $userTrack->__set('usertrack_package_id', $params['order_package']);
                             $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', $params['order_address']);
                             //                                    $userTrack->__set('usertrack_locality', $laundryCart->address[1]);
                             $userTrack->__set('usertrack_city', $params['order_city']);
                             $userTrackMapper->addNewTrack($userTrack);
                         } else {
                             //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($post['order_delivery_type'])) {
                                 $deliveryType = 'Regular';
                             } else {
                                 $deliveryType = $post['order_delivery_type'];
                             }
                             $totalPrice = 0;
                             foreach ($post['item'] as $key => $qty) {
                                 $totalPrice += $post['itemprice'][$key] * $qty;
                             }
                             if ($totalPrice < 200) {
                                 $deliveryCharge = 50;
                             } else {
                                 $deliveryCharge = 0;
                             }
                             $serviceTax = 14 * $totalPrice / 100;
                             $orders = new Application_Model_Orders();
                             $orders->__set('order_user_id', $post['order_user_id']);
                             $orders->__set('order_first_name', $post['order_first_name']);
                             $orders->__set('order_last_name', $post['order_last_name']);
                             $orders->__set('order_address', $post['order_address']);
                             $orders->__set('order_city', $post['order_city']);
                             $orders->__set('order_delivery_type', $deliveryArr[$deliveryType]);
                             $orders->__set('order_pickup', date('Y-m-d', strtotime($post['order_pickup'])));
                             $orders->__set('order_delivery', date('Y-m-d', strtotime($post['order_delivery'])));
                             $orders->__set('order_delivery_time', $post['order_delivery_time']);
                             $orders->__set('order_pickup_time', $post['order_pickup_time']);
                             $orders->__set('order_amount', $totalPrice);
                             $orders->__set('order_payment_type', 'cash on delivery');
                             $orders->__set('delivery_charge', $deliveryCharge);
                             $orders->__set('service_tax', $serviceTax);
                             $orders->__set('order_payment_status', 'unpaid');
                             $orders->__set('order_service_type', implode(',', $post['order_service_type']));
                             $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');
                             $itemModel = new Application_Model_ItemsMapper();
                             $itemPrice = new Application_Model_ItemPriceMapper();
                             $orderItemModel = new Application_Model_OrderItemsMapper();
                             if ($orderId = $model->addNewOrder($orders)) {
                                 //add products now
                                 if (isset($post['item'])) {
                                     foreach ($post['item'] as $item => $quantity) {
                                         if ((int) $quantity < 1) {
                                             continue;
                                         }
                                         //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', $post['itemservice'][$item]);
                                         $orderItem->__set('order_category_name', $post['itemcategory'][$item]);
                                         $orderItem->__set('unit_price', $post['itemprice'][$item]);
                                         $orderItem->__set('total_price', $post['itemprice'][$item] * $post['item'][$item]);
                                         $orderItem->__set('quantity', $post['item'][$item]);
                                         $orderItemModel->addNewOrderItem($orderItem);
                                     }
                                 }
                                 $this->view->message = "Order successfully completed";
                                 $this->view->hasMessage = true;
                                 $this->view->messageType = "success";
                                 $this->_redirect('admin/orders');
                             } else {
                                 $this->view->message = "Error occured while adding. Please try again";
                                 $this->view->hasMessage = true;
                                 $this->view->messageType = "danger";
                             }
                         }
                         $this->view->message = "Order added successfully";
                         $this->view->hasMessage = true;
                         $this->view->messageType = "success";
                     } else {
                         $this->view->message = "Error occured while Adding. Please fill form correctly";
                         $this->view->hasMessage = true;
                         $this->view->messageType = "danger";
                     }
                 } elseif ($request_type == "delete") {
                     $id = $request->getParam("id");
                     if ($ordersMapper->deleteOrderById($id)) {
                         $this->view->hasMessage = true;
                         $this->view->messageType = "success";
                         $this->view->message = "Order deleted successfully.";
                     } else {
                         $this->view->hasMessage = true;
                         $this->view->messageType = "danger";
                         $this->view->message = "Error occured while deleting. Please try again.";
                     }
                 }
             }
         }
         $orders = $ordersMapper->getAllOrders();
         $this->view->orders = $orders;
         $this->authorised = true;
     } catch (Exception $ex) {
         $this->authorised = false;
         $this->view->hasMessage = true;
         $this->view->messageType = "danger";
         $this->view->message = $ex->getMessage();
     }
 }
Esempio n. 2
0
 public function editAction()
 {
     try {
         //$admins = new Application_Model_Admins;
         $itemPriceMapper = new Application_Model_ItemPriceMapper();
         $request = $this->getRequest();
         $item_price_form = new Application_Form_ItemPriceForm();
         $this->view->form = $item_price_form;
         $elements = $item_price_form->getElements();
         $item_price_id = $request->getParam("id");
         $secure = new My_Secure();
         $id = $item_price_id;
         //$id = $secure->decode($item_price_id);
         //echo $id;
         $item_price = $itemPriceMapper->getItemPriceById($id);
         //print_r($item_price);exit;
         foreach ($elements as $element) {
             $element->setValue($item_price->__get($element->getName()));
         }
         if ($request->isPost()) {
             $request_type = $request->getParam("request_type", false);
             if ($request_type) {
                 if ($request_type == "edit") {
                     $params = $request->getParams();
                     if ($item_price_form->isValid($params)) {
                         foreach ($params as $param => $value) {
                             $item_price->__set($param, $value);
                         }
                         if ($itemPriceMapper->updateItemPrice($item_price)) {
                             $this->view->message = "Item Price Updated successfully";
                             $this->view->hasMessage = true;
                             $this->view->messageType = "success";
                         } else {
                             $this->view->message = "Error occured while updating. Please try again";
                             $this->view->hasMessage = true;
                             $this->view->messageType = "danger";
                         }
                     } else {
                         $this->view->message = "Error occured while updating. Please fill form correctly";
                         $this->view->hasMessage = true;
                         $this->view->messageType = "danger";
                     }
                 }
             }
         }
         $this->authorised = true;
     } catch (Exception $ex) {
         $this->authorised = false;
         $this->view->hasMessage = true;
         $this->view->messageType = "danger";
         $this->view->message = $ex->getMessage();
     }
 }
Esempio n. 3
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");
     }
 }