public function addAction()
 {
     if (!$this->_hasParam('id')) {
         return $this->_redirect('/analysis/index/page/1');
     }
     $convert = new Application_Model_Letras();
     $model = new Application_Model_Payments();
     $datos = new Application_Model_Analysis();
     $row = $datos->getRow($this->_getParam('id'));
     if ($row) {
         $data = $row->toArray();
         $contact = new Application_Model_Contacts();
         $customer = $contact->getRow($data['applicant_id'])->toArray();
         $paciente = $customer['first_name'] . ' ' . $customer['last_name'];
         $exa = $datos->BySpecialties($this->_getParam('id'));
         $monto = 0;
         foreach ($exa as $key) {
             $monto = $monto + $key['amount'];
         }
         $datos->actualiza_total($this->_getParam('id'), $monto);
         $this->view->paginator = $exa;
         $this->view->letras = $convert->num2letras($monto);
         $this->view->paciente = $paciente;
         $this->view->data = $data;
         $this->view->monto = $monto;
     }
 }
 public function pdfAction()
 {
     require_once '/Zend/Pdf.php';
     require_once '/PS/utils.php';
     if (!$this->_hasParam('id')) {
         return $this->_redirect('/analysis/index/page/1');
     }
     $datos = new Application_Model_Analysis();
     $row = $datos->getRow($this->_getParam('id'));
     if ($row) {
         $data = $row->toArray();
         $contact = new Application_Model_Contacts();
         $results = new Application_Model_Results();
         $exa = $datos->BySpecialties($this->_getParam('id'));
         $customer = $contact->getRow($data['applicant_id'])->toArray();
         $medico = $contact->getRow($data['medic_id'])->toArray();
         $this->_helper->layout->disableLayout();
         $this->_helper->viewRenderer->setNoRender();
         //$pdf = new Zend_Pdf();
         if ($data['name'] == 1) {
             $pdf = Zend_Pdf::load('img/2.pdf');
         } else {
             $pdf = Zend_Pdf::load('img/1.pdf');
         }
         $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
         //$pdf->pages[] = $page;
         $page = $pdf->pages[0];
         /*
         //specify color
         $color = new Zend_Pdf_Color_HTML("navy");
         $page->setFillColor($color);
         */
         $fontT = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_TIMES);
         $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 10);
         $page->drawText($customer['first_name'] . ' ' . $customer['last_name'], 125, 712);
         $page->drawText(date('Y-m-d', strtotime($data['date_entered'])), 455, 712);
         $page->drawText(birthday($customer['birthdate']), 125, 700);
         $page->drawText($customer['gender'], 455, 700);
         $page->drawText($medico['first_name'] . ' ' . $medico['last_name'], 125, 685);
         $posY = 670;
         foreach ($exa as $key) {
             $posY -= 50;
             $page->setLineWidth(0.5);
             $page->drawLine(50, $posY + 15, 530, $posY + 15);
             $page->setLineWidth(0.5);
             $page->drawLine(50, $posY - 10, 530, $posY - 10);
             $page->drawText('Examen', 50, $posY);
             $page->drawText('Resultado', 280, $posY);
             $page->drawText('U.M.', 360, $posY);
             $page->drawText('Valores de Referencia', 400, $posY);
             $page->drawText($key['name'], 50, $posY - 25);
             $res = $results->getBy(array('analysis_id =?' => $key['analysis_id'], 'test_id =?' => $key['itest_id']))->toArray();
             $posY -= 38.4;
             foreach ($res as $keyd) {
                 $page->drawText($keyd['item_name'], 60, $posY);
                 $page->drawText($keyd['result'], 280, $posY);
                 $page->drawText($keyd['ref_val_unit'], 350, $posY);
                 $page->drawText($keyd['ref_val_value'], 420, $posY);
                 $posY -= 14.2;
             }
             $posY -= 20.2;
             $page->drawText('MUESTRA:', 280, $posY);
             $page->drawText('METODO DE PROCESO:', 280, $posY - 14);
         }
         if ($posY < 400) {
             $page2 = new Zend_Pdf_Page($page);
             $pdf->pages[] = $page2;
         }
         $page->drawText('OBSERVACIONES:', 50, 170);
         $page->drawText($data['note'], 50, 155);
         $this->getResponse()->setHeader('Content-Disposition', 'attachment; filename=result.pdf')->setHeader('Content-type', 'application/x-pdf');
         echo $pdf->render();
     }
 }