-2

我正在开发一个发票查看系统,我想在 iframe 中查看单个 PDF 发票。我不知道如何制作查看具有最新到期日期的单张发票的 SQL 脚本。

我正在使用 Zend Framework,数据库是 MySQL。

    public function viewinvoiceemployeeAction()
{
    /** Object variable. Example use: $logger->err("Some error"); */
    $logger = Zend_Registry::get('LOGGER');
    /** Object variable. Example use: $something = $config->database; */
    $config = Zend_Registry::get('config');
    /** Object variable. Example use: print $date->get(); */
    $date = Zend_Registry::get('date');
    /** Object variable. Example use: $stmt = $db->query($sql); */
    $db = Zend_Registry::get('dbAdapter');

    $request = $this->getRequest();

          $id = (integer) $request->getParam('ostoreskontra_id');
          $dateColumn = (string) date("Y-m-d", strtotime("NOW"));
          //select * from yourTable where dateColumn = (select max(dateColumn) from yourTable)

          $db->beginTransaction();

          try {

              $date = (string) date("Y-m-d", strtotime($db->fetchone("SELECT laskun_pvm FROM ostoreskontra WHERE laskunera_pvm = (SELECT MAX(".$db->quote($dateColumn, 'STRING').") FROM ostoreskontra);")));
              $number = (integer) $db->fetchone("SELECT laskun_nro FROM ostoreskontra WHERE laskunera_pvm = (SELECT MAX(".$db->quote($dateColumn, 'STRING').") FROM ostoreskontra);");
              $sublier = (string) str_replace(" ","+",$db->fetchone("SELECT toimittaja.nimi FROM ostoreskontra LEFT JOIN toimittaja ON ostoreskontra.toimittaja_id=toimittaja.toimittaja_id WHERE ostoreskontra.laskunera_pvm = (SELECT MAX(".$db->quote($id, 'STRING').") FROM ostoreskontra);"));

              $file = (string) $date.'_'.$sublier.'_'.$number.'.pdf';

              $db->commit();

              $content = file_get_contents(APPLICATION_PATH."/uploads/ostolaskut/".$file);

              if ($id==0) {

                  header('Content-Type: text/plain');

              } else {

                  header('Content-Type: application/pdf');
                  header("Content-Length: " . strlen($content) );
                  //header('Content-Disposition: attachment; filename='.$file);

                  echo $content;

              }

          } catch (Exception $e) {

          $db->rollBack();
          //$success = array('success' => false, 'msg' => $e->getMessage());
          echo $e->getMessage();

          }

          //print_r($name);

}
4

1 回答 1

0

您没有给我们太多信息,但是...使用它来按日期获取表中的最后一条记录:

select * from yourTable where dateColumn = (select max(dateColumn) from yourTable)
于 2013-05-29T08:52:14.857 回答