예제 #1
0
 public function indexAction()
 {
     /**
      * @var \Library\Authentication\BackofficeAuthenticationService $authService
      * @var \DDD\Service\WHOrder\Order $orderService
      * @var \DDD\Service\User $userService
      * @var \DDD\Dao\User\UserManager $userDao
      */
     $authService = $this->getServiceLocator()->get('library_backoffice_auth');
     $orderService = $this->getServiceLocator()->get('service_wh_order_order');
     $userService = $this->getServiceLocator()->get('service_user');
     $userDao = $this->getServiceLocator()->get('dao_user_user_manager');
     $statusShipping = $orderService->getStatusShippingForSelectize(OrderService::getStatusesShipping());
     // check roles
     $hasRole = $authService->hasRole(Roles::ROLE_WH_ORDER_MANAGEMENT);
     $hasGlobalRole = $authService->hasRole(Roles::ROLE_WH_ORDER_MANAGEMENT_GLOBAL);
     if ($hasRole && !$hasGlobalRole) {
         $userId = $authService->getIdentity()->id;
         $users[] = $userDao->findUserById($userId);
     } else {
         $users = iterator_to_array($userService->getUsersList(false, true));
     }
     // get by default available statuses for search
     $defaultStatuses = [];
     foreach ($statusShipping as $key => $status) {
         if ($status['id'] != Order::STATUS_CANCELED && $status['id'] != Order::STATUS_RETURNED && $status['id'] != Order::STATUS_RECEIVED) {
             $defaultStatuses[] = $status['id'];
         }
     }
     return ['users' => $users, 'statuses' => OrderService::getStatusesByText(), 'statusShipping' => json_encode($statusShipping), 'defaultStatuses' => $defaultStatuses, 'hasRole' => $hasRole, 'hasGlobalRole' => $hasGlobalRole];
 }
    public function getOrdersCreatedByMeAction()
    {
        $auth = $this->getServiceLocator()->get('library_backoffice_auth');
        /** @var Order $orderService */
        $orderService = $this->getServiceLocator()->get('service_wh_order_order');
        $dataSet = $orderService->getOrdersCreatedByMe($auth->getIdentity()->id);
        $preparedData = [];
        $actionsColumn = '';
        if ($dataSet && count($dataSet)) {
            $isOrderManager = $auth->hasRole(Roles::ROLE_WH_ORDER_MANAGEMENT) || $auth->hasRole(Roles::ROLE_WH_ORDER_MANAGEMENT_GLOBAL);
            foreach ($dataSet as $row) {
                $receivedColumn = " ";
                if ($isOrderManager) {
                    $actionsColumn = '
					<a href="/orders/edit/' . $row->getId() . '" class="btn btn-xs btn-primary" target="_blank" data-html-content="View"></a>';
                }
                $archiveColumn = '<a href="javascript:void(0)"' . ' onClick="archiveOrders(this, ' . $row->getId() . ', event)" class="btn btn-xs btn-primary">Archive</a>';
                if ($row->getStatus() == Order::STATUS_ORDER_APPROVED && ($row->getStatusShipping() == Order::STATUS_ORDERED || $row->getStatusShipping() == Order::STATUS_SHIPPED || $row->getStatusShipping() == Order::STATUS_DELIVERED || $row->getStatusShipping() == Order::STATUS_PARTIALLY_RECEIVED || $row->getStatusShipping() == Order::STATUS_ISSUE)) {
                    $receivedColumn = '<a href="javascript:void(0)"' . ' onClick="markAsReceivedOrders(this, ' . $row->getId() . ', event)" class="btn btn-xs btn-success">Mark as Received</a>';
                }
                $status = Order::getStatusesByText()[$row->getStatus()];
                $classStatusShippingColor = Order::getStatusesColor()[$row->getStatusShipping()];
                $statusShipping = Order::getStatusesShipping()[$row->getStatusShipping()];
                $preparedData[] = [$row->getTitle(), '<span class="label ' . $status[1] . '">' . $status[0] . '</span>', '<span class="label label-' . $classStatusShippingColor . '">' . $statusShipping . '</span>', $row->getQuantity(), Order::getLabelForTargetType($row->getTargetType()) . $row->getLocationName(), $row->getOrderDate() ? date(Constants::GLOBAL_DATE_FORMAT, strtotime($row->getOrderDate())) : '', $row->getEstimatedDateStart() && $row->getEstimatedDateEnd() ? date(Constants::GLOBAL_DATE_FORMAT, strtotime($row->getEstimatedDateStart())) . ' - ' . date(Constants::GLOBAL_DATE_FORMAT, strtotime($row->getEstimatedDateEnd())) : '', $row->getTrackingUrl() ? '<a href="' . $row->getTrackingUrl() . '" class="btn btn-xs btn-success" target="_blank">Track</a>' : '', $receivedColumn, $archiveColumn, $actionsColumn];
            }
        }
        return new JsonModel(["aaData" => $preparedData]);
    }
예제 #3
0
파일: Order.php 프로젝트: arbi/MyCode
 /**
  * @param $offset
  * @param $limit
  * @param $sortCol
  * @param $sortDir
  * @param string $like
  * @param array $filters
  * @return array|bool
  */
 public function getDatatableData($offset, $limit, $sortCol, $sortDir, $like = '', $filters = [])
 {
     try {
         $orderDao = $this->getOrderDao();
         if (!empty($filters['status_shipping'])) {
             $filters['status_shipping'] = explode(',', $filters['status_shipping']);
         }
         /**
          * @var \Library\Authentication\BackofficeAuthenticationService $authService
          * @var \DDD\Dao\Team\TeamStaff $teamStaffDao
          */
         $authService = $this->getServiceLocator()->get('library_backoffice_auth');
         if (!$authService->hasRole(Roles::ROLE_WH_ORDER_MANAGEMENT_GLOBAL)) {
             $userId = $authService->getIdentity()->id;
             $query = DbTables::TBL_WM_ORDERS . '.creator_id = ' . $userId;
             /**
              * @var Procurement $teamUsageProcurementService
              */
             $teamUsageProcurementService = $this->getServiceLocator()->get('service_team_usages_procurement');
             $userProcurementTeams = $teamUsageProcurementService->getUserProcurementTeams($userId);
             $userProcurementTeamsIds = [];
             foreach ($userProcurementTeams as $userProcurementTeam) {
                 $userProcurementTeamsIds[] = $userProcurementTeam->getId();
             }
             if (!empty($userProcurementTeamsIds)) {
                 $ids = implode(",", $userProcurementTeamsIds);
                 $query .= ' OR ' . DbTables::TBL_WM_ORDERS . '.team_id in (' . $ids . ')';
             }
             $filters['users_or_teams'] = $query;
         }
         $result = $orderDao->getAllOrders($offset, $limit, $sortCol, $sortDir, $like, $filters);
         $ordersList = $result['orders_list'];
         $ordersTotalCount = $result['total_count'];
         $data = [];
         if ($ordersList->count()) {
             /**
              * @var \DDD\Dao\Apartment\General $apartmentDao
              * @var \DDD\Dao\Warehouse\Storage $storageDao
              * @var \DDD\Dao\Office\OfficeManager $officeDao
              * @var \DDD\Dao\Finance\Supplier $supplierDao
              * @var \DDD\Dao\ApartmentGroup\ApartmentGroup $buildingDao
              */
             $apartmentDao = $this->getServiceLocator()->get('dao_apartment_general');
             $storageDao = $this->getServiceLocator()->get('dao_warehouse_storage');
             $officeDao = $this->getServiceLocator()->get('dao_office_office_manager');
             $supplierDao = $this->getServiceLocator()->get('dao_finance_supplier');
             $buildingDao = $this->getServiceLocator()->get('dao_apartment_group_apartment_group');
             $assetsCategoryColors = [AssetsCategory::CATEGORY_TYPE_CONSUMABLE => 'success', AssetsCategory::CATEGORY_TYPE_VALUABLE => 'primary'];
             foreach ($ordersList as $order) {
                 $location = $category = '';
                 switch ($order['target_type']) {
                     case self::ORDER_LOCATION_TYPE_APARTMENT:
                         $apartmentData = $apartmentDao->getApartmentGeneralInfo($order['target_id']);
                         $location = '<span class="label label-success" title="Apartment">A</span> ' . ' ' . $apartmentData['name'];
                         break;
                     case self::ORDER_LOCATION_TYPE_STORAGE:
                         $storageData = $storageDao->getStorageDetails($order['target_id'], false);
                         $location = '<span class="label label-primary" title="Storage">S</span> ' . ' ' . $storageData['name'];
                         break;
                     case self::ORDER_LOCATION_TYPE_OFFICE:
                         $officeData = $officeDao->getOfficeDetailsById($order['target_id'], false);
                         $location = '<span class="label label-info" title="Office">O</span> ' . ' ' . $officeData['name'];
                         break;
                     case self::ORDER_LOCATION_TYPE_BUILDING:
                         $buildingData = $buildingDao->fetchOne(['id' => $order['target_id']], ['name']);
                         $location = '<span class="label label-warning" title="Building">B</span> ' . ' ' . $buildingData->getName();
                         break;
                 }
                 $shippingStatus = '<span class="label label-' . self::getStatusesColor()[$order['status_shipping']] . '"' . ' title="' . self::getStatusesShipping()[$order['status_shipping']] . '">' . self::getShortShippingStatuses()[$order['status_shipping']] . '</span>';
                 if ($order['category_type']) {
                     $category = '<span class="label label-' . $assetsCategoryColors[$order['category_type']] . '"' . ' title="' . AssetsCategory::$categoryTypes[$order['category_type']] . '">' . ' ' . substr(AssetsCategory::$categoryTypes[$order['category_type']], 0, 1) . '</span> ' . $order['category_name'];
                 }
                 $urlBtn = '';
                 if (!empty($order['url'])) {
                     if ((stristr($order['url'], 'http://') || stristr($order['url'], 'https://')) === false) {
                         $order['url'] = 'http://' . $order['url'];
                     }
                     $urlBtn = '<a href="' . $order['url'] . '" target="_blank" class="btn btn-xs btn-info pull-left"><i class="glyphicon glyphicon-globe"></i> <span class="hidden-sm hidden-xs">URL</span></a>';
                 }
                 $editBtn = '<a href="/orders/edit/' . $order['id'] . '" target="_blank" class="btn btn-xs btn-primary pull-left">Edit</a>';
                 $status = Order::getStatusesByText()[$order['status']];
                 $data[] = ['<span class="label ' . $status[1] . '">' . $status[0] . '</span>', $shippingStatus, $order['title'], $category, $location, !empty($order['estimated_date_start']) ? date(Constants::GLOBAL_DATE_FORMAT, strtotime($order['estimated_date_start'])) : '', !empty($order['estimated_date_end']) ? date(Constants::GLOBAL_DATE_FORMAT, strtotime($order['estimated_date_end'])) : '', $urlBtn, $editBtn];
             }
         }
         return ['data' => $data, 'total' => $ordersTotalCount];
     } catch (\Exception $e) {
         $this->gr2logException($e, 'Cannot get Orders from datatable', ['offset' => $offset, 'limit' => $limit, 'sort_column' => $sortCol, 'sort_dir' => $sortDir, 'like' => $like]);
     }
     return false;
 }