Exemplo n.º 1
0
 /**
  * Edition de la relance
  *
  * @return void
  */
 function editRelance()
 {
     $this->type_pdf = "relance";
     $this->editFacture();
     if (count($this->factures)) {
         $this->pdf->Output("Relance_" . $this->facture->cloture . "_" . $this->patient->nom . '.pdf', "I");
     } else {
         $this->pdf->Output('Relances.pdf', "I");
     }
 }
Exemplo n.º 2
0
    $lot = new CProductOrderItemReception();
    $lot->load($lot_id);
    $lots = array($lot);
}
$data = array();
$j = 0;
foreach ($lots as &$item) {
    $item->loadRefsBack();
    $item->loadRefsFwd();
    $item->_ref_order_item->loadReference();
    $reference = $item->_ref_order_item->_ref_reference;
    $reference->loadRefsFwd();
    $reference->_ref_product->loadRefsFwd();
    if (!$item->barcode_printed || $force_print) {
        for ($i = 0; $i < $item->quantity / $reference->quantity; $i++) {
            $data[$j] = array();
            $d =& $data[$j];
            $lines = explode("\n", wordwrap($reference->_ref_product->name, 30, "\n", true));
            $d[] = $lines[0];
            $d[] = isset($lines[1]) ? $lines[1] : "";
            $d[] = $reference->_ref_product->code;
            $d[] = "LOT {$item->code}  PER {$item->lapsing_date}";
            $d[] = array('barcode' => "MB" . str_pad($item->_id, 8, "0", STR_PAD_LEFT), 'type' => 'C128B');
            $j++;
        }
    }
}
$pdf->WriteBarcodeGrid(8, 8, 210 - 16, 297 - 16, 3, 10, $data);
// Nom du fichier: prescription-xxxxxxxx.pdf   / I : sortie standard
$pdf->Output("barcodes.pdf", "I");
 /**
  * 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");
     }
 }
Exemplo n.º 4
0
 function printEtiquettes($printer_id = null, $stream = 1)
 {
     // Affectation de la police par défault si aucune n'est choisie
     if ($this->font == "") {
         $this->font = "dejavusansmono";
     }
     // Calcul des dimensions de l'étiquette
     $largeur_etiq = ($this->largeur_page - 2 * $this->marge_horiz) / $this->nb_colonnes;
     $hauteur_etiq = ($this->hauteur_page - 2 * $this->marge_vert) / $this->nb_lignes;
     // Création du PDF
     $pdf = new CMbPdf('P', 'cm', array($this->largeur_page, $this->hauteur_page));
     $pdf->setFont($this->font, '', $this->hauteur_ligne);
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     $pdf->SetMargins($this->marge_horiz, $this->marge_vert, $this->marge_horiz);
     $pdf->SetAutoPageBreak(0, $this->marge_vert);
     $pdf->AddPage();
     $distinct_texts = 1;
     $textes = array();
     $pays = CAppUI::conf("ref_pays");
     // La fonction nl2br ne fait qu'ajouter la balise <br />, elle ne supprime pas le \n.
     // Il faut donc le faire manuellement.
     $textes[1] = preg_replace("/[\t\r\n\f]/", '', utf8_encode(nl2br($this->texte)));
     if ($this->texte_2) {
         $distinct_texts++;
         $textes[] = preg_replace("/[\t\r\n\f]/", '', utf8_encode(nl2br($this->texte_2)));
     }
     if ($this->texte_3) {
         $distinct_texts++;
         $textes[] = preg_replace("/[\t\r\n\f]/", '', utf8_encode(nl2br($this->texte_3)));
     }
     if ($this->texte_4) {
         $distinct_texts++;
         $textes[] = preg_replace("/[\t\r\n\f]/", '', utf8_encode(nl2br($this->texte_4)));
     }
     $nb_etiqs = $this->nb_lignes * $this->nb_colonnes;
     $increment = floor($nb_etiqs / $distinct_texts);
     $current_text = 1;
     // Création de la grille d'étiquettes et écriture du contenu.
     for ($i = 0; $i < $nb_etiqs; $i++) {
         if ($i != 0 && $i % $increment == 0 && isset($textes[$current_text + 1])) {
             $current_text++;
         }
         if (round($pdf->GetX()) >= round($this->largeur_page - 2 * $this->marge_horiz)) {
             $pdf->SetX(0);
             $pdf->SetLeftMargin($this->marge_horiz);
             $pdf->SetY($pdf->GetY() + $hauteur_etiq);
         }
         if ($this->show_border) {
             $pdf->Rect($pdf->GetX(), $pdf->GetY(), $largeur_etiq, $hauteur_etiq, 'D');
         }
         $x = $pdf->GetX();
         $y = $pdf->GetY();
         $pdf->SetLeftMargin($x);
         // On affecte la marge droite de manière à ce que la méthode Write fasse un retour chariot
         // lorsque le contenu écrit va dépasser la largeur de l'étiquette
         $pdf->SetRightMargin($this->largeur_page - $x - $largeur_etiq);
         $fragments = explode("@", $textes[$current_text]);
         $was_barcode = 0;
         CMbArray::removeValue("", $fragments);
         // Evaluation de la hauteur du contenu de la cellule
         // si un alignement spécifique est demandé.
         if ($this->text_align != "top") {
             $pdf_ex = new CMbPdf('p', 'cm', array($largeur_etiq, $hauteur_etiq));
             $pdf_ex->setFont($this->font, '', $this->hauteur_ligne);
             $pdf_ex->SetMargins(0, 0, 0);
             $pdf_ex->setPrintHeader(false);
             $pdf_ex->setPrintFooter(false);
             $pdf_ex->SetAutoPageBreak(false);
             $pdf_ex->AddPage();
             foreach ($fragments as $fragment) {
                 if (preg_match("/BARCODE_(.*)/", $fragment, $matches) == 1) {
                     switch ($pays) {
                         case "2":
                             $save_x = $pdf_ex->getX();
                             $pdf_ex->setY($pdf_ex->getY() + 0.4);
                             $pdf_ex->setX($save_x);
                             $barcode = $matches[1];
                             $pdf_ex->setFont("C39HrP24DhTt", '', 30);
                             $pdf_ex->WriteHTML($barcode, false);
                             $pdf_ex->setFont($this->font, '', $this->hauteur_ligne);
                             break;
                         default:
                             $barcode_x = $pdf_ex->getX() + 0.15;
                             $barcode_y = $pdf_ex->getY();
                             $barcode = $matches[1];
                             $barcode_width = strlen($barcode) * 0.4 + 0.4;
                             $pdf_ex->writeBarcode($barcode_x, $barcode_y, $barcode_width, 0.8, "C128B", 1, null, null, $barcode, 25);
                             $pdf_ex->setX($barcode_x + $barcode_width);
                     }
                     $was_barcode = 1;
                 } else {
                     if ($was_barcode) {
                         $sub_fragments = explode("<br />", $fragment, 2);
                         $pdf_ex->WriteHTML($sub_fragments[0], false);
                         if (isset($sub_fragments[1])) {
                             $actual_y = $pdf_ex->getY();
                             $pdf_ex->setY($actual_y + 0.8);
                             $pdf_ex->WriteHTML($sub_fragments[1], false);
                         }
                     } else {
                         $pdf_ex->WriteHTML($fragment, false);
                     }
                     $was_barcode = 0;
                 }
             }
             $pdf_y = $pdf->getY();
             $pdf_ex_y = $pdf_ex->getY();
             switch ($this->text_align) {
                 case "middle":
                     $pdf->setY($pdf_y - 0.2 + ($hauteur_etiq - $pdf_ex_y) / 2);
                     break;
                 case "bottom":
                     $pdf->setY($pdf_y - 0.4 + $hauteur_etiq - $pdf_ex_y);
             }
         }
         foreach ($fragments as $fragment) {
             if (preg_match("/BARCODE_(.*)/", $fragment, $matches) == 1) {
                 switch ($pays) {
                     case "2":
                         // La position x est à remettre car perdue lors de la méthode setY
                         $save_x = $pdf->getX();
                         $pdf->setY($pdf->getY() + 0.4);
                         $pdf->setX($save_x);
                         $barcode = $matches[1];
                         $pdf->setFont("C39HrP24DhTt", '', 30);
                         $pdf->WriteHTML("*{$barcode}*", false);
                         $pdf->setFont($this->font, '', $this->hauteur_ligne);
                         break;
                     default:
                         $barcode_x = $pdf->getX() + 0.15;
                         $barcode_y = $pdf->getY();
                         $barcode = $matches[1];
                         $barcode_width = strlen($barcode) * 0.4 + 0.4;
                         $pdf->writeBarcode($barcode_x, $barcode_y, $barcode_width, 0.8, "C128B", 1, null, null, $barcode);
                         $pdf->setX($barcode_x + $barcode_width);
                 }
                 $was_barcode = 1;
             } else {
                 if ($was_barcode) {
                     $sub_fragments = explode("<br />", $fragment, 2);
                     $pdf->WriteHTML($sub_fragments[0], false);
                     if (isset($sub_fragments[1])) {
                         $actual_y = $pdf->getY();
                         $pdf->setY($actual_y + 0.8);
                         $pdf->WriteHTML($sub_fragments[1], false);
                     }
                 } else {
                     $pdf->WriteHTML($fragment, false);
                 }
                 $was_barcode = 0;
             }
         }
         $x = $x + $largeur_etiq;
         $pdf->SetY($y);
         $pdf->SetX($x);
     }
     if ($printer_id) {
         $file = new CFile();
         $file->_file_path = tempnam("/tmp", "etiq");
         file_put_contents($file->_file_path, $pdf->Output($this->nom . '.pdf', "S"));
         $printer = new CPrinter();
         $printer->load($printer_id);
         $printer->loadRefSource()->sendDocument($file);
         unlink($file->_file_path);
     } else {
         if ($stream) {
             $pdf->Output($this->nom . '.pdf', "I");
         } else {
             return $pdf->OutPut($this->nom . '.pdf', "S");
         }
     }
 }