public function autosearchAction()
 {
     $this->_helper->viewRenderer->setNoRender(true);
     $nmcenter = $this->_request->getParam('term');
     $cdfrom = $this->_request->getParam('cdcentrefrom');
     if (isset($cdfrom) && $cdfrom != '') {
         $where = " AND cdsupplycentre <> " . $cdfrom;
     } else {
         $where = '';
     }
     $centerModel = new CenterModel();
     $centerData = $centerModel->fetchAll('idsupplycentre like "%' . $nmcenter . '%" ' . $where);
     $json = '[';
     $first = true;
     foreach ($centerData as $row) {
         if (!$first) {
             $json .= ',';
         } else {
             $first = false;
         }
         $json .= '{"id":"' . $row['cdsupplycentre'] . '", "value":"' . $row['idsupplycentre'] . '"}';
     }
     $json .= ']';
     echo $json;
 }
 public function dadosAction()
 {
     $this->_helper->layout->disableLayout();
     $page = $this->_request->getParam("page", 1);
     $limit = $this->_request->getParam("rows");
     $sidx = $this->_request->getParam("sidx", 1);
     $sord = $this->_request->getParam("sord");
     $centerModel = new CenterModel();
     $supplycentre = $centerModel->fetchAll();
     $count = count($supplycentre);
     if ($count > 0 && $limit != 0) {
         $total_pages = ceil($count / $limit);
     } else {
         $total_pages = 0;
     }
     if ($page > $total_pages) {
         $page = $total_pages;
     }
     $supplycentre = $centerModel->fetchAll(null, "{$sidx} {$sord}", $limit, $page * $limit - $limit);
     $responce = new stdClass();
     $responce->page = $page;
     $responce->total = $total_pages;
     $responce->records = $count;
     $i = 0;
     $companyModel = new CompanyModel();
     $physicallocationModel = new PhysicallocationModel();
     foreach ($supplycentre as $row) {
         $fgtype = '';
         switch ($row->fgsupplycentretype) {
             case 1:
                 $fgtype = 'Estocagem';
                 break;
             case 2:
                 $fgtype = 'Consumo';
                 break;
         }
         $fgactive = '';
         switch ($row->fgactive) {
             case 1:
                 $fgactive = 'Ativo';
                 break;
             case 2:
                 $fgactive = 'Inativo';
                 break;
         }
         $company = '';
         $physicallocation = '';
         $responce->rows[$i]['cdsupplycentre'] = $row->cdsupplycentre;
         if ($row->cdcompany != '' && $row->cdcompany != null) {
             $nmcompany = $companyModel->getNmCopanyByCdCompany($row->cdcompany);
             $company = $nmcompany->nmcompany;
         }
         if ($row->cdphysicallocation != null && $row->cdphysicallocation != '') {
             $nmphysicallocation = $physicallocationModel->getColorParentPhysicallocation($row->cdphysicallocation);
             $physicallocation = $nmphysicallocation->nmphysicallocation;
         }
         $responce->rows[$i]['cell'] = array($row->cdsupplycentre, $row->idsupplycentre, $fgtype, $company, $physicallocation, $fgactive, $row->cdcompany, $row->cdphysicallocation, $row->fgsupplycentretype);
         $i++;
     }
     $this->view->dados = $responce;
 }