public function statusmethodsupplyAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(true);
     $methodModel = new MethodModel();
     $cdmethod = $this->_request->getParam("cdmethod");
     $status = $this->_request->getParam("activeStatus");
     $array = array();
     $methodModel->getAdapter()->beginTransaction();
     try {
         if (isset($cdmethod) && $status == '1') {
             $array['fgactive'] = '2';
         } else {
             if (isset($cdmethod) && $status == '2') {
                 $array['fgactive'] = '1';
             }
         }
         $methodModel->update($array, "cdmethod = {$cdmethod}");
         $methodModel->getAdapter()->commit();
     } catch (Exception $e) {
         $methodModel->getAdapter()->rollback();
     }
 }
 public function printviewAction()
 {
     require_once 'fpdf/pdf.php';
     $cdrequest = $_GET["cdrequest"];
     $Request = new RequestModel();
     $Factor = new FactorModel();
     $Method = new MethodModel();
     $Comment = new AppraisalcommentModel();
     $Patterntext = new PatterntextModel();
     $array = array();
     $req = $Request->fetchAll($Request->getAllRequestData($cdrequest));
     if (count($req) <= 0) {
         die;
     }
     foreach ($req as $row) {
         $dtbirth = new Zend_Date($row['dtbirth'], 'dd-MM-YYYY');
         $dtrequest = new Zend_Date($row['dtrequest'], 'dd-MM-YYYY HH:mm:ss');
         $year = $dtbirth->toString('YYYY');
         $month = $dtbirth->toString('MM');
         $day = $dtbirth->toString('dd');
         $today = new Zend_Date();
         $tdYear = $today->toString('YYYY');
         $tdMonth = $today->toString('MM');
         $tdDay = $today->toString('dd');
         $nrage = 0;
         $nrage = GslabUtils::calcAgeDifference($row['dtbirth']);
         $idade = GslabUtils::calcula_idade($row['dtbirth']);
         if ($tdMonth < $month || $tdMonth == $month && $tdDay < $day) {
             $nrage--;
         }
         if ($row['fgsex'] == 1) {
             $fgsex = "Masculino";
         } else {
             $fgsex = "Feminino";
         }
         $array['nmclient'] = $row['nmclient'];
         $array['nmforward'] = $row['nmforward'];
         $array['nmcompany'] = $row['nmcompany'];
         $array['nmbarcodesample'] = $row['nmbarcodesample'];
         $array['nmcovenant'] = $row['nmcovenant'];
         $array['dtrequest'] = $dtrequest;
         $array['idade'] = $nrage;
         $array['sexo'] = $fgsex;
     }
     $GLOBALS = $array;
     $ano = explode(" ", $nrage);
     $pdf = new PDF();
     $pdf->AddPage();
     $pdf->ln(30);
     $pdf->AliasNbPages('{total}');
     $req2 = $Request->fetchAll($Request->getAllRequestData($cdrequest));
     foreach ($req2 as $rows) {
         $comentario_text = '';
         /* COMENTÁRIO DOS EXAMES */
         $comments = $Comment->fetchRow($Comment->getAppraisalComments($rows['cdrequestexamination']));
         if (count($comments) > 0) {
             $dscomment = explode(',', $comments->dscomment);
             foreach ($dscomment as $comm) {
                 $comentario = $Patterntext->fetchRow($Patterntext->getPatterntextById($comm));
                 $comentario_text .= utf8_decode($comentario->dspatterntext) . "\n";
             }
         } else {
             $comentario_text = '';
         }
         /* MÉTODO DOS EXAMES */
         $method = $Method->fetchRow($Method->getMethodByCd($rows['cdmethod']));
         $metodo = utf8_decode("Método: " . $method->nmmethod);
         $fgstatus = true;
         /* NOME DO EXAME */
         $pdf->SetFont('Courier', 'BI', 11);
         $pdf->Cell(0, 10, strtoupper(utf8_decode($rows['nmexamination'])), 0, 2, 'L');
         $pdf->SetFont('Courier', '', 9);
         $pdf->Cell(0, 0, utf8_decode("Material: " . strtoupper($rows['nmmaterial'])), 0, 0, 'L');
         $pdf->Cell(-30, 0, $metodo, 0, 1, 'R');
         $pdf->ln(2);
         $pdf->ln(2);
         $sons = $this->getExamSons($rows['cdexamination'], $cdrequest);
         if (count($sons) > 0) {
             for ($aux_i = 0; $aux_i < count($sons); $aux_i++) {
                 $pdf->SetFont('Courier', '', 9);
                 $pdf->Cell(-15, 5, strtoupper(utf8_decode($sons[$aux_i]['nmexamination'])), 0, 0, 'L');
                 /* NOME DO ATRIBUTO E VALOR */
                 $attributes = $this->getAttrValues($sons[$aux_i]['cdrequestexamination'], $sons[$aux_i]['cdexaminationmaterial']);
                 if ($sons[$aux_i]['fgpercentage'] == 1) {
                     $soma = 0;
                     foreach ($attributes as $sum) {
                         $soma = $soma + $sum['vlattribute'];
                     }
                     $valor_calc = $soma / 100;
                     $pdf->SetFont('Courier', 'B', 9);
                     $pdf->Cell(100, 5, "%", 0, 0, 'R');
                 }
                 $fgstatus = true;
                 foreach ($attributes as $attr) {
                     if ($sons[$aux_i]['fgpercentage'] == 1) {
                         $valor = round($attr['vlattribute'] / $valor_calc, 1);
                         $n = explode(".", $valor);
                         if ($n[1] < 5 && $n[1] != 5) {
                             $vl_at = floor($valor);
                         } else {
                             if ($n[1] > 5 && $n[1] != 5) {
                                 $vl_at = ceil($valor);
                             } else {
                                 if ($n[1] == 5) {
                                     $vl_at = $valor;
                                 }
                             }
                         }
                     } else {
                         $vl_at = '';
                         $valor = '';
                     }
                     $pdf->SetFont('Courier', '', 9);
                     $pdf->ln();
                     $pdf->Cell(40, 5, "    " . str_pad(utf8_decode($attr['nmattribute']), 18, "."), 0, 0, 'L');
                     $pdf->SetFont('Courier', 'B', 9);
                     $pdf->Cell(65, 5, str_pad(utf8_decode($attr['vlattribute']) . " " . utf8_decode($attr['idnotation']), 15, ".", STR_PAD_LEFT) . "     " . $vl_at, 0, 0, 'L');
                     $ref = $Factor->fetchAll($Factor->getAllFactors($attr['cdattribute']));
                     //                        var_dump($ref);die;
                     foreach ($ref as $vlref) {
                         if ($vlref['fgfactor'] == 1) {
                             $fator = "Idade            Valores referenciais";
                         } else {
                             if ($vlref['fgfactor'] == 2) {
                                 $fator = "Masculino                    Feminino";
                             } else {
                                 if ($vlref['fgfactor'] == 3) {
                                     $fator = "Idade       Masculino        Feminino";
                                 }
                             }
                         }
                     }
                     if ($fgstatus == true) {
                         $pdf->Cell(-1);
                         $pdf->Cell(1, -5, $fator, 0, 0, 'L');
                         $fgstatus = false;
                     }
                     /* VALORES DE REFERÊNCIA */
                     foreach ($ref as $vlref) {
                         /*
                          * AQUI SÃO DEFINIDAS AS REGRAS DE EXIBIÇÃO DO PDF, COLUNAS POR IDADE, SEXO OU AMBOS:
                          * 
                          * fgfactor = 1
                          * ATRIBUTO........VALOR        IDADE    REFERÊNCIA
                          * 
                          * fgfactor = 2
                          * ATRIBUTO........VALOR        MASCULINO    FEMININO
                          * 
                          * fgfactor = 3
                          * ATRIBUTO........VALOR        IDADE    MASCULINO    FEMININO
                          * 
                          */
                         $pdf->SetFont('Courier', '', 8);
                         /* DEFINE QUAL CAMPO DA TABELA ESTÁ PREENCHIDO (VALOR OU NUMÉRICO) E ALOCA À UMA VARIÁVEL */
                         if ($vlref['nrminvalue'] == '' && $vlref['nrmaxvalue'] == '' && $vlref['vlminvalue'] != '' && $vlref['vlmaxvalue'] != '') {
                             $minvalue = $vlref['vlminvalue'];
                             $maxvalue = $vlref['vlmaxvalue'];
                         } else {
                             if ($vlref['nrminvalue'] != '' && $vlref['nrmaxvalue'] != '' && $vlref['vlminvalue'] == '' && $vlref['vlmaxvalue'] == '') {
                                 $minvalue = $vlref['nrminvalue'];
                                 $maxvalue = $vlref['nrmaxvalue'];
                             }
                         }
                         if ($vlref['fgfactor'] == 1) {
                             //SEPARADOS PELA IDADE, DEFINE UMA COLUNA DE RESULTADOS
                             if ($vlref['nrminage'] <= $ano[0] && $vlref['nrmaxage'] >= $ano[0]) {
                                 $pdf->Cell(12, 5, utf8_decode($vlref['nrminage'] . " à " . $vlref['nrmaxage'] . " " . $vlref['nmtimetype']), 0, 0, 'R');
                                 $pdf->Cell(67, 5, utf8_decode($minvalue . " à " . $maxvalue), 0, 0, 'R');
                             }
                         } else {
                             if ($vlref['fgfactor'] == 2) {
                                 //SEPARADOS PELO SEXO, DEFINE DUAS COLUNAS DE RESULTADOS
                                 if ($vlref['fggender'] == 1) {
                                     // MASCULINO
                                     $pdf->Cell(20, 5, utf8_decode($vlref['vlminvalue'] . " à " . $vlref['vlmaxvalue']), 0, 0, 'R');
                                 } else {
                                     if ($vlref['fggender'] == 2) {
                                         // FEMININO
                                         $pdf->Cell(60, 5, utf8_decode($vlref['vlminvalue'] . " à " . $vlref['vlmaxvalue']), 0, 0, 'R');
                                     }
                                 }
                             } else {
                                 if ($vlref['fgfactor'] == 3) {
                                     //SEPARADOS PELO SEXO E IDADE, DEFINE TRÊS COLUNAS DE RESULTADOS
                                     if ($vlref['fggender'] == 1) {
                                         // MASCULINO
                                         $pdf->Cell(12, 5, utf8_decode($vlref['nrminage'] . " à " . $vlref['nrmaxage'] . " " . $vlref['nmtimetype']), 0, 0, 'R');
                                         $pdf->Cell(33, 5, utf8_decode($vlref['vlminvalue'] . " à " . $vlref['vlmaxvalue']), 0, 0, 'R');
                                     } else {
                                         if ($vlref['fggender'] == 2) {
                                             // FEMININO
                                             $pdf->Cell(35, 5, utf8_decode($vlref['vlminvalue'] . " à " . $vlref['vlmaxvalue']), 0, 0, 'R');
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 $pdf->ln();
                 $pdf->ln();
             }
         } else {
             $examination = $this->getExam($rows['cdexamination'], $cdrequest);
             for ($aux_i = 0; $aux_i < count($examination); $aux_i++) {
                 /* NOME DO ATRIBUTO E VALOR */
                 $attributes = $this->getAttrValues($examination[$aux_i]['cdrequestexamination'], $examination[$aux_i]['cdexaminationmaterial']);
                 if ($examination[$aux_i]['fgpercentage'] == 1) {
                     $soma = 0;
                     foreach ($attributes as $sum) {
                         $soma = $soma + $sum['vlattribute'];
                     }
                     $valor_calc = $soma / 100;
                     $pdf->SetFont('Courier', 'B', 9);
                     $pdf->Cell(83, 5, "%", 0, 0, 'R');
                 }
                 $rangeruleCount = count($attributes);
                 $fgstatus = true;
                 foreach ($attributes as $attr) {
                     if ($examination[$aux_i]['fgpercentage'] == 1) {
                         $valor = round($attr['vlattribute'] / $valor_calc, 1);
                         $n = explode(".", $valor);
                         if ($n[1] < 5 && $n[1] != 5) {
                             $vl_at = floor($valor);
                         } else {
                             if ($n[1] > 5 && $n[1] != 5) {
                                 $vl_at = ceil($valor);
                             } else {
                                 if ($n[1] == 5) {
                                     $vl_at = $valor;
                                 }
                             }
                         }
                     } else {
                         $vl_at = '';
                         $valor = '';
                     }
                     $pdf->SetFont('Courier', '', 9);
                     $pdf->ln();
                     $pdf->Cell(40, 15, "    " . str_pad(utf8_decode($attr['nmattribute']), 18, "."), 0, 0, 'L');
                     $pdf->SetFont('Courier', 'B', 9);
                     $pdf->Cell(65, 15, str_pad($attr['vlattribute'] . " " . $attr['idnotation'], 15, ".", STR_PAD_LEFT) . "     " . $vl_at, 0, 0, 'L');
                     $ref = $Factor->fetchAll($Factor->getAllFactors($attr['cdattribute']));
                     foreach ($ref as $vlref) {
                         if ($vlref['fgfactor'] == 1) {
                             $fator = "Idade            Valores referenciais";
                         } else {
                             if ($vlref['fgfactor'] == 2) {
                                 $fator = "Masculino                    Feminino";
                             } else {
                                 if ($vlref['fgfactor'] == 3) {
                                     $fator = "Idade       Masculino        Feminino";
                                 }
                             }
                         }
                     }
                     if ($fgstatus == true) {
                         $pdf->Cell(-1);
                         $pdf->Cell(1, 5, $fator, 0, 0, 'L');
                         $fgstatus = false;
                     }
                     /* VALORES DE REFERÊNCIA */
                     foreach ($ref as $vlref) {
                         /*
                          * AQUI SÃO DEFINIDAS AS REGRAS DE EXIBIÇÃO DO PDF, COLUNAS POR IDADE, SEXO OU AMBOS:
                          * 
                          * fgfactor = 1
                          * ATRIBUTO........VALOR        IDADE    REFERÊNCIA
                          * 
                          * fgfactor = 2
                          * ATRIBUTO........VALOR        MASCULINO    FEMININO
                          * 
                          * fgfactor = 3
                          * ATRIBUTO........VALOR        IDADE    MASCULINO    FEMININO
                          * 
                          */
                         $pdf->SetFont('Courier', '', 8);
                         $imgRR = "./images/result/rangerule_img-" . $attr['cdrequestexamination'] . "_" . $rows['cdexamination'] . "_" . $attr['cdattribute'] . "_" . $examination[$aux_i]['cdexaminationmaterial'] . ".png";
                         /* DEFINE QUAL CAMPO DA TABELA ESTÁ PREENCHIDO (VALOR OU NUMÉRICO) E ALOCA À UMA VARIÁVEL */
                         if ($vlref['nrminvalue'] == '' && $vlref['nrmaxvalue'] == '' && $vlref['vlminvalue'] != '' && $vlref['vlmaxvalue'] != '') {
                             $minvalue = $vlref['vlminvalue'];
                             $maxvalue = $vlref['vlmaxvalue'];
                         } else {
                             if ($vlref['nrminvalue'] != '' && $vlref['nrmaxvalue'] != '' && $vlref['vlminvalue'] == '' && $vlref['vlmaxvalue'] == '') {
                                 $minvalue = $vlref['nrminvalue'];
                                 $maxvalue = $vlref['nrmaxvalue'];
                             }
                         }
                         if ($vlref['fgfactor'] == 1) {
                             //SEPARADOS PELA IDADE, DEFINE UMA COLUNA DE RESULTADOS
                             if ($vlref['nrminage'] <= $ano[0] && $vlref['nrmaxage'] >= $ano[0]) {
                                 $pdf->Cell(12, 15, utf8_decode($vlref['nrminage'] . " à " . $vlref['nrmaxage'] . " " . $vlref['nmtimetype']), 0, 0, 'R');
                                 if ($rangeruleCount == 1) {
                                     $pdf->Cell(40, 50, $pdf->Image($imgRR, $pdf->GetX() + 5, $pdf->GetY() + 6, 70), 0, 0, 'L', false);
                                 }
                                 $pdf->Cell(67, 8, utf8_decode($minvalue . " à " . $maxvalue), 0, 0, 'R');
                             }
                         } else {
                             if ($vlref['fgfactor'] == 2) {
                                 //SEPARADOS PELO SEXO, DEFINE DUAS COLUNAS DE RESULTADOS
                                 if ($vlref['fggender'] == 1) {
                                     // MASCULINO
                                     $pdf->Cell(20, 5, utf8_decode($vlref['vlminvalue'] . " à " . $vlref['vlmaxvalue']), 0, 0, 'R');
                                 } else {
                                     if ($vlref['fggender'] == 2) {
                                         // FEMININO
                                         $pdf->Cell(60, 5, utf8_decode($vlref['vlminvalue'] . " à " . $vlref['vlmaxvalue']), 0, 1, 'R');
                                     }
                                 }
                             } else {
                                 if ($vlref['fgfactor'] == 3) {
                                     //SEPARADOS PELO SEXO E IDADE, DEFINE TRÊS COLUNAS DE RESULTADOS
                                     if ($vlref['fggender'] == 1) {
                                         // MASCULINO
                                         $pdf->Cell(12, 5, utf8_decode($vlref['nrminage'] . " à " . $vlref['nrmaxage'] . " " . $vlref['nmtimetype']), 0, 0, 'R');
                                         $pdf->Cell(33, 5, utf8_decode($vlref['vlminvalue'] . " à " . $vlref['vlmaxvalue']), 0, 0, 'R');
                                     } else {
                                         if ($vlref['fggender'] == 2) {
                                             // FEMININO
                                             $pdf->Cell(35, 5, utf8_decode($vlref['vlminvalue'] . " à " . $vlref['vlmaxvalue']), 0, 1, 'R');
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 $pdf->ln();
                 $pdf->ln();
             }
         }
         if (count($comments) > 0) {
             $pdf->SetFont('Courier', 'B', 9);
             $pdf->Cell(5, 2, utf8_decode("Observações: "), 0, 1, 'L');
             $pdf->ln();
             $pdf->SetFont('Courier', '', 7);
             $pdf->Multicell(0, 3, $comentario_text);
             $pdf->ln();
         }
     }
     $pdf->Output();
     //IMPRIME O PDF NA TELA
     $pdf->Output('teste.pdf', "D");
     //IMPRIME O PDF NO ARQUIVO
 }
 public function dadosmethodAction()
 {
     $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");
     $methodModel = new MethodModel();
     $methodData = $methodModel->fetchAll($methodModel->getMethodByEachSupply());
     $count = count($methodData);
     if ($count > 0) {
         $total_pages = ceil($count / $limit);
     } else {
         $total_pages = 0;
     }
     if ($page > $total_pages) {
         $page = $total_pages;
     }
     $methodData = $methodModel->fetchAll(null, "{$sidx} {$sord}", $limit, $page * $limit - $limit);
     $responce = new stdClass();
     $responce->page = $page;
     $responce->total = $total_pages;
     $responce->records = $count;
     $i = 0;
     var_dump($methodData);
     foreach ($methodData as $row) {
         $responce->rows[$i]['cdmethod'] = $row->cdmethod;
         $responce->rows[$i]['cell'] = array($row->cdmethod, $row->nmmethod, $row->cdequipment, '', $row->cddocument);
         $i++;
     }
     $this->view->dadosmethod = $responce;
 }
 public function equipmentmethodAction()
 {
     $cdequipment = $_GET['cdequipment'];
     $methodModel = new MethodModel();
     $equipmentmethod = $methodModel->getEquipmentMethod($cdequipment);
     $equipmentmethodData = array();
     $i = 0;
     foreach ($equipmentmethod as $key) {
         foreach ($key as $column => $value) {
             $equipmentmethodData[$i][$column] = $value;
         }
         $i++;
     }
     $this->view->equipmentmethoddata = $equipmentmethodData;
 }