/**
  * Edition de la liste de contrôle
  *
  * @return void
  */
 function editCheckList()
 {
     $colonnes = array("Nom" => 20, "Prenom" => 20, "Dossier" => 25, "Type" => 15, "Entree" => 15, "Sortie" => 15, "Statut" => 20, "Montant" => 25);
     $this->editTableau($colonnes, 5, 25);
     $debut_lignes = 30;
     $ligne = 0;
     $montant_total = 0;
     foreach ($this->factures as $facture) {
         $this->pdf->setX(5);
         $ligne++;
         $valeurs = array("Nom" => $facture->_ref_patient->nom, "Prenom" => $facture->_ref_patient->prenom, "Dossier" => $facture->_view . " " . $facture->_ref_last_sejour->type, "Type" => $facture->type_facture, "Entree" => CMbDT::transform("", $facture->_ref_last_sejour->entree_prevue, '%d/%m/%Y'), "Sortie" => CMbDT::transform("", $facture->_ref_last_sejour->sortie_prevue, '%d/%m/%Y'), "Statut" => $facture->envoi_xml ? "Facture électronique" : "", "Montant" => sprintf("%.2f", $facture->_montant_avec_remise));
         $x = 0;
         foreach ($colonnes as $key => $value) {
             $cote = $key == "Montant" ? "R" : "L";
             $this->editCell($this->pdf->getX() + $x, $debut_lignes + $ligne * 4, $value, $valeurs[$key], $cote);
             $x = $value;
         }
         if ($debut_lignes + $ligne * 4 >= 200) {
             $ligne = $this->ajoutPage($colonnes);
         }
         $montant_total += $facture->_montant_avec_remise;
     }
     $ligne += 2;
     $pos_ligne = $debut_lignes + $ligne * 4;
     $this->editCell(180, $pos_ligne, 80, "Montant total:", "R");
     $this->editCell(210, $pos_ligne, 80, $montant_total, "R");
 }
 /**
  * Création du second type d'en-tête possible d'un justificatif, celui-ci étant plus léger 
  * 
  * @param int $nb le numéro de la page
  * 
  * @return void
  */
 function ajoutEntete2($nb)
 {
     $this->pdf->setFont($this->fontb, '', 12);
     $this->pdf->WriteHTML("<h4>Justificatif de remboursement</h4>");
     $this->pdf->setFont($this->font, '', 8);
     $this->pdf->SetFillColor(255, 255, 255);
     $this->pdf->SetDrawColor(0);
     $this->pdf->Rect(10, 18, 180, 20);
     $auteur = substr($this->auteur["adresse1"], 0, 29) . " " . $this->auteur["cp"] . " " . $this->auteur["ville"];
     $presta = $this->fourn_presta;
     $presta_adresse = substr($presta["adresse1"], 0, 29) . " " . $presta["0"]->cp . " " . $presta["0"]->ville;
     $lignes = array(array("Document", "Identification", $this->facture->_id . " " . CMbDT::format(null, "%d.%m.%Y %H:%M:%S"), "", "Page {$nb}"), array("Auteur", "N° EAN(B)", $this->auteur["EAN"], $this->auteur["nom"], " Tél: " . $this->auteur["tel"]), array("Facture", "N° RCC(B)", $this->auteur["RCC"], $auteur, "Fax: " . $this->auteur["fax"]), array("Four.de", "N° EAN(P)", $presta["EAN"], $presta["nom_dr"], " Tél: " . $presta["0"]->tel), array("prestations", "N° RCC(B)", $presta["RCC"], $presta_adresse, "Fax: " . $presta["0"]->fax));
     $this->pdf->setXY(10, $this->pdf->getY() - 4);
     foreach ($lignes as $ligne) {
         $this->pdf->setXY(10, $this->pdf->getY() + 4);
         foreach ($ligne as $key => $value) {
             $this->pdf->Cell($this->colonnes[$key], "", $value);
         }
     }
 }
 * @subpackage Stock
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision: 26699 $
 */
CCanDo::checkRead();
$reception_id = CValue::get('reception_id');
$lot_id = CValue::get('lot_id');
$force_print = CValue::get('force_print');
$reception = new CProductReception();
if ($reception_id) {
    $reception->load($reception_id);
    $reception->loadRefsFwd();
    $reception->loadRefsBack();
}
$pdf = new CMbPdf();
$pdf->setFont("vera", '', "10");
// Définition des marges de la pages
//$pdf->SetMargins(15, 15);
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->SetAutoPageBreak(0);
// Creation d'une nouvelle page
$pdf->AddPage();
if ($reception->_id) {
    $lots = $reception->_ref_reception_items;
} else {
    $lot = new CProductOrderItemReception();
    $lot->load($lot_id);
    $lots = array($lot);
}
 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");
         }
     }
 }