示例#1
0
<?php

/**
 * $Id: ajax_print_journal.php 20881 2013-11-06 11:41:49Z aurelie17 $
 *
 * @package    Mediboard
 * @subpackage dPfacturation
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision: 20881 $
 */
CCanDo::checkEdit();
$journal_id = CValue::get("journal_id");
$uniq_checklist = CValue::get("uniq_checklist");
$journal = new CJournalBill();
$journal->load($journal_id);
$user = CMediusers::get();
$printer_bvr = new CPrinter();
$printer_bvr->function_id = $user->function_id;
$printer_bvr->label = "bvr";
$printer_bvr->loadMatchingObject();
if (!$printer_bvr->_id) {
    CAppUI::setMsg("Les imprimantes ne sont pas paramétrées", UI_MSG_ERROR);
    echo CAppUI::getMsg();
    return false;
} else {
    $file = new CFile();
    $file->object_id = $journal->checklist_id;
    $file->object_class = "CJournalBill";
    $file->loadMatchingObject();
    $printer_bvr->loadRefSource()->sendDocument($file);
 /**
  * Edition des journaux selon le type
  *
  * @param bool $read           lecture
  * @param bool $create_journal Création du journal
  *
  * @return void
  */
 function editJournal($read = true, $create_journal = true)
 {
     if ($create_journal) {
         $journal = new CJournalBill();
         $journal->type = $this->type_pdf;
         $journal->nom = "Journal_" . $this->type_pdf . "_" . CMbDT::date();
         $journal->_factures = $this->factures;
         if ($msg = $journal->store()) {
             mbTrace($msg);
         } else {
             $this->journal_id = $journal->_id;
         }
     }
     // Creation du PDF
     $this->pdf = new CMbPdf('l', 'mm');
     $this->pdf->setPrintHeader(false);
     $this->pdf->setPrintFooter(false);
     $this->font = "vera";
     $this->fontb = $this->font . "b";
     $this->pdf->setFont($this->font, '', 8);
     $this->page = 0;
     $this->editEntete();
     switch ($this->type_pdf) {
         case "paiement":
             $this->editPaiements();
             break;
         case "debiteur":
             $this->editDebiteur();
             break;
         case "rappel":
             $this->editRappel();
             break;
         case "checklist":
             $this->editCheckList();
             break;
     }
     if ($create_journal) {
         $file = new CFile();
         $file->file_name = $journal->nom . ".pdf";
         $file->file_type = "application/pdf";
         $file->author_id = CMediusers::get()->_id;
         $file->file_category_id = 1;
         $file->setObject($journal);
         $file->fillFields();
         $file->putContent($this->pdf->Output('Factures.pdf', "S"));
         if ($msg = $file->store()) {
             echo $msg;
         }
         if ($this->type_pdf == "checklist") {
             $user = CMediusers::get();
             $printer = new CPrinter();
             $printer->function_id = $user->function_id;
             $printer->label = "justif";
             $printer->loadMatchingObject();
             if (!$printer->_id) {
                 CAppUI::setMsg("Les imprimantes ne sont pas paramétrées", UI_MSG_ERROR);
                 echo CAppUI::getMsg();
                 return false;
             }
             $file = new CFile();
             $pdf = $this->pdf->Output('Factures.pdf', "S");
             $file_path = tempnam("tmp", "facture");
             $file->_file_path = $file_path;
             file_put_contents($file_path, $pdf);
             $printer->loadRefSource()->sendDocument($file);
             unlink($file_path);
         }
     }
     if ($read) {
         //Affichage du fichier pdf
         $this->pdf->Output('Factures.pdf', "I");
     }
 }