public function selectedpricingAction()
 {
     $this->_helper->layout->disableLayout();
     $covenantModel = new CovenantpricingModel();
     $examinationModel = new ExaminationModel();
     $cdcovenant = $this->_request->getParam('cdcovenant');
     $examinationDados = $covenantModel->fetchAll($covenantModel->getCovenantExamination($cdcovenant));
     $examinationDadosNN = $examinationModel->fetchAll($examinationModel->getCovenantExaminationNN($cdcovenant));
     $opt = '';
     $i = 0;
     $response = new stdClass();
     if ($examinationDadosNN->count() > 0) {
         foreach ($examinationDadosNN as $examination) {
             $opt .= "<option value='" . $examination['cdexamination'] . "'>" . $examination['nmexamination'] . "</option>";
         }
         foreach ($examinationDados as $row) {
             if ($row['fgauthrequired'] == '2') {
                 $fg = '0';
             } else {
                 $fg = '1';
             }
             $response->rows[$i]['cell'] = array($row['cdcovenant'], $row['cdexamination'], $row['idcovenant'] . " - " . $row['nmcovenant'], $row['nmexamination'], $row['vlexamination'], $row['vlchdefault'], $row['fgbasevalexamination'], $row['nrdeadline'], $fg);
             $i++;
             $response->chvalue = $row['vlchvalue'];
         }
         $response->options = $opt;
         $result = json_encode($response);
         print_r($result);
         return $result;
     } else {
         $response = new stdClass();
         $response->options = "empty";
         $response->rows = "empty";
         $result = json_encode($response);
         print_r($result);
         return $result;
     }
 }
 public function searchAction()
 {
     $examat = json_decode($_POST['dados'], true);
     $covenant = $_POST['covenant'];
     $lol = array();
     foreach ($covenant as $key => $values) {
         $lol[] = (int) $values;
     }
     foreach ($examat as $e) {
         $array[] = $e['code'];
     }
     $j = 0;
     $PricingModel = new CovenantpricingModel();
     $PricingData = $PricingModel->fetchAll($PricingModel->getExaminationCovenant($array, $covenant));
     if (!empty($PricingData)) {
         $col = array("Código", "Exame");
         foreach ($PricingData as $coluna) {
             $col[] = $coluna['nmcovenant'];
         }
         foreach ($lol as $p) {
             $concat[] = "GROUP_CONCAT( if (covenantpricing.cdcovenant = " . $p . ", vlexamination, NULL) ) AS 'convenio" . $j . "'";
             $j++;
         }
         $bootstrap = $this->getInvokeArg('bootstrap');
         $gslab_db = $bootstrap->getResource('db');
         $query = $gslab_db->query("select examination.*, covenant.*, covenantpricing.*, " . implode(',', $concat) . " \r\n                , coalesce(covenantpricing.cdexamination, 0) as 'examination'\r\n                from covenantpricing\r\n                inner join examination on examination.cdexamination = covenantpricing.cdexamination\r\n                inner join covenant on covenant.cdcovenant = covenantpricing.cdcovenant\r\n                where covenantpricing.cdexamination in (" . implode(',', $array) . ")\r\n                and covenantpricing.cdcovenant in (" . implode(',', $covenant) . ")\r\n                group by covenantpricing.cdexamination;");
         $result = $query->fetchAll();
         $i = 0;
         $total = 0;
         $total2 = 0;
         $total3 = 0;
         if ($j == 1) {
             foreach ($result as $ALELUIA) {
                 $response->rows[$i]['cell'] = array($ALELUIA['idexamination'], $ALELUIA['nmexamination'], $ALELUIA['convenio0']);
                 $total += $ALELUIA['convenio0'];
                 $i++;
             }
         } else {
             if ($j == 2) {
                 foreach ($result as $ALELUIA) {
                     $response->rows[$i]['cell'] = array($ALELUIA['idexamination'], $ALELUIA['nmexamination'], $ALELUIA['convenio0'], $ALELUIA['convenio1']);
                     $total += $ALELUIA['convenio0'];
                     $total2 += $ALELUIA['convenio1'];
                     $i++;
                 }
             } else {
                 if ($j == 3) {
                     foreach ($result as $ALELUIA) {
                         $response->rows[$i]['cell'] = array($ALELUIA['idexamination'], $ALELUIA['nmexamination'], $ALELUIA['convenio0'], $ALELUIA['convenio1'], $ALELUIA['convenio2']);
                         $total += $ALELUIA['convenio0'];
                         $total2 += $ALELUIA['convenio1'];
                         $total3 += $ALELUIA['convenio2'];
                         $i++;
                     }
                 }
             }
         }
         //print_r($ALELUIA);die;
         $response->userdata['covenant1'] = $total;
         $response->userdata['covenant2'] = $total2;
         $response->userdata['covenant3'] = $total3;
         $response->userdata['examination'] = 'Total:';
         $response->size = sizeof($col) - 2;
         $response->cols = $col;
     } else {
         $response->rows = "Sem resultado";
         $response->size = 0;
         $response->cols = $col;
     }
     $response = json_encode($response);
     print_r($response);
     return $response;
 }