コード例 #1
13
 /**
  *	Function to build pdf onto disk
  *
  *	@param		Object		$object			Object expedition to generate (or id if old method)
  *	@param		Translate	$outputlangs		Lang output object
  *  @param		string		$srctemplatepath	Full path of source filename for generator using a template file
  *  @param		int			$hidedetails		Do not show line details
  *  @param		int			$hidedesc			Do not show desc
  *  @param		int			$hideref			Do not show ref
  *  @return     int         	    			1=OK, 0=KO
  */
 function write_file(&$object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
 {
     global $user, $conf, $langs, $hookmanager;
     $object->fetch_thirdparty();
     if (!is_object($outputlangs)) {
         $outputlangs = $langs;
     }
     // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
     if (!empty($conf->global->MAIN_USE_FPDF)) {
         $outputlangs->charset_output = 'ISO-8859-1';
     }
     $outputlangs->load("main");
     $outputlangs->load("dict");
     $outputlangs->load("companies");
     $outputlangs->load("bills");
     $outputlangs->load("products");
     $outputlangs->load("propal");
     $outputlangs->load("deliveries");
     $outputlangs->load("sendings");
     if ($conf->expedition->dir_output) {
         // Definition de $dir et $file
         if ($object->specimen) {
             $dir = $conf->expedition->dir_output . "/sending";
             $file = $dir . "/SPECIMEN.pdf";
         } else {
             $expref = dol_sanitizeFileName($object->ref);
             $dir = $conf->expedition->dir_output . "/sending/" . $expref;
             $file = $dir . "/" . $expref . ".pdf";
         }
         if (!file_exists($dir)) {
             if (dol_mkdir($dir) < 0) {
                 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
                 return 0;
             }
         }
         if (file_exists($dir)) {
             $nblignes = count($object->lines);
             $pdf = pdf_getInstance($this->format);
             $default_font_size = pdf_getPDFFontSize($outputlangs);
             $heightforinfotot = 0;
             // Height reserved to output the info and total part
             $heightforfreetext = isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5;
             // Height reserved to output the free text on last page
             $heightforfooter = $this->marge_basse + 8;
             // Height reserved to output the footer (value include bottom margin)
             $pdf->SetAutoPageBreak(1, 0);
             if (class_exists('TCPDF')) {
                 $pdf->setPrintHeader(false);
                 $pdf->setPrintFooter(false);
             }
             $pdf->SetFont(pdf_getPDFFont($outputlangs));
             // Set path to the background PDF File
             if (empty($conf->global->MAIN_DISABLE_FPDI) && !empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
                 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output . '/' . $conf->global->MAIN_ADD_PDF_BACKGROUND);
                 $tplidx = $pdf->importPage(1);
             }
             $pdf->Open();
             $pagenb = 0;
             $pdf->SetDrawColor(128, 128, 128);
             if (method_exists($pdf, 'AliasNbPages')) {
                 $pdf->AliasNbPages();
             }
             $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
             $pdf->SetSubject($outputlangs->transnoentities("Shipment"));
             $pdf->SetCreator("Dolibarr " . DOL_VERSION);
             $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
             $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref) . " " . $outputlangs->transnoentities("Shipment"));
             if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
                 $pdf->SetCompression(false);
             }
             $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
             // Left, Top, Right
             // New page
             $pdf->AddPage();
             if (!empty($tplidx)) {
                 $pdf->useTemplate($tplidx);
             }
             $pagenb++;
             $this->_pagehead($pdf, $object, 1, $outputlangs);
             $pdf->SetFont('', '', $default_font_size - 1);
             $pdf->MultiCell(0, 3, '');
             // Set interline to 3
             $pdf->SetTextColor(0, 0, 0);
             $tab_top = 90;
             $tab_top_newpage = empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 : 10;
             $tab_height = 130;
             $tab_height_newpage = 150;
             if (!empty($object->note_public) || !empty($object->tracking_number) && !empty($object->shipping_method_id)) {
                 $tab_top = 88;
                 $tab_top_alt = $tab_top;
                 // Tracking number
                 if (!empty($object->tracking_number)) {
                     $object->GetUrlTrackingStatus($object->tracking_number);
                     if (!empty($object->tracking_url)) {
                         if ($object->shipping_method_id > 0) {
                             // Get code using getLabelFromKey
                             $code = $outputlangs->getLabelFromKey($this->db, $object->shipping_method_id, 'c_shipment_mode', 'rowid', 'code');
                             $label = $outputlangs->trans("LinkToTrackYourPackage") . "<br>";
                             $label .= $outputlangs->trans("SendingMethod" . strtoupper($code)) . " :";
                             $pdf->SetFont('', 'B', $default_font_size - 2);
                             $pdf->writeHTMLCell(60, 7, $this->posxdesc - 1, $tab_top - 1, $label . " " . $object->tracking_url, 0, 1, false, true, 'L');
                             $tab_top_alt += 7;
                         }
                     }
                 }
                 // Affiche notes
                 if (!empty($object->note_public)) {
                     $pdf->SetFont('', '', $default_font_size - 1);
                     // Dans boucle pour gerer multi-page
                     $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top_alt, dol_htmlentitiesbr($object->note_public), 0, 1);
                 }
                 $nexY = $pdf->GetY();
                 $height_note = $nexY - $tab_top;
                 // Rect prend une longueur en 3eme param
                 $pdf->SetDrawColor(192, 192, 192);
                 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
                 $tab_height = $tab_height - $height_note;
                 $tab_top = $nexY + 6;
             } else {
                 $height_note = 0;
             }
             $iniY = $tab_top + 7;
             $curY = $tab_top + 7;
             $nexY = $tab_top + 7;
             $num = count($object->lines);
             // Loop on each lines
             for ($i = 0; $i < $num; $i++) {
                 $curY = $nexY;
                 $pdf->SetFont('', '', $default_font_size - 1);
                 // Into loop to work with multipage
                 $pdf->SetTextColor(0, 0, 0);
                 $pdf->setTopMargin($tab_top_newpage);
                 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
                 // The only function to edit the bottom margin of current page to set it.
                 $pageposbefore = $pdf->getPage();
                 // Description de la ligne produit
                 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxqtyordered - 10, 3, $this->posxdesc, $curY, 0, 1);
                 $nexY = $pdf->GetY();
                 $pageposafter = $pdf->getPage();
                 $pdf->setPage($pageposbefore);
                 $pdf->setTopMargin($this->marge_haute);
                 $pdf->setPageOrientation('', 1, 0);
                 // The only function to edit the bottom margin of current page to set it.
                 // We suppose that a too long description is moved completely on next page
                 if ($pageposafter > $pageposbefore) {
                     $pdf->setPage($pageposafter);
                     $curY = $tab_top_newpage;
                 }
                 $pdf->SetFont('', '', $default_font_size - 1);
                 // On repositionne la police par defaut
                 $pdf->SetXY($this->posxqtyordered, $curY);
                 $pdf->MultiCell($this->posxqtytoship - $this->posxqtyordered, 3, $object->lines[$i]->qty_asked, '', 'C');
                 $pdf->SetXY($this->posxqtytoship, $curY);
                 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxqtytoship, 3, $object->lines[$i]->qty_shipped, '', 'C');
                 // Add line
                 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < $nblignes - 1) {
                     $pdf->setPage($pageposafter);
                     $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(210, 210, 210)));
                     //$pdf->SetDrawColor(190,190,200);
                     $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
                     $pdf->SetLineStyle(array('dash' => 0));
                 }
                 $nexY += 2;
                 // Passe espace entre les lignes
                 // Detect if some page were added automatically and output _tableau for past pages
                 while ($pagenb < $pageposafter) {
                     $pdf->setPage($pagenb);
                     if ($pagenb == 1) {
                         $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
                     } else {
                         $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
                     }
                     $this->_pagefoot($pdf, $object, $outputlangs, 1);
                     $pagenb++;
                     $pdf->setPage($pagenb);
                     $pdf->setPageOrientation('', 1, 0);
                     // The only function to edit the bottom margin of current page to set it.
                 }
                 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
                     if ($pagenb == 1) {
                         $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
                     } else {
                         $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
                     }
                     $this->_pagefoot($pdf, $object, $outputlangs, 1);
                     // New page
                     $pdf->AddPage();
                     if (!empty($tplidx)) {
                         $pdf->useTemplate($tplidx);
                     }
                     $pagenb++;
                 }
             }
             // Show square
             if ($pagenb == 1) {
                 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext - $heightforinfotot, 0, $outputlangs, 0, 0);
                 $bottomlasttab = $this->page_hauteur - $heightforfooter - $heightforfreetext - $heightforinfotot + 1;
             } else {
                 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter - $heightforfreetext - $heightforinfotot, 0, $outputlangs, 1, 0);
                 $bottomlasttab = $this->page_hauteur - $heightforfooter - $heightforfreetext - $heightforinfotot + 1;
             }
             // Pied de page
             $this->_pagefoot($pdf, $object, $outputlangs);
             if (method_exists($pdf, 'AliasNbPages')) {
                 $pdf->AliasNbPages();
             }
             $pdf->Close();
             $pdf->Output($file, 'F');
             if (!empty($conf->global->MAIN_UMASK)) {
                 @chmod($file, octdec($conf->global->MAIN_UMASK));
             }
             return 1;
         } else {
             $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
             return 0;
         }
     } else {
         $this->error = $langs->transnoentities("ErrorConstantNotDefined", "EXP_OUTPUTDIR");
         return 0;
     }
     $this->error = $langs->transnoentities("ErrorUnknown");
     return 0;
     // Erreur par defaut
 }
コード例 #2
0
	/**
	 *		\brief      Fonction generant le document sur le disque
	 *		\param	    object			Objet expedition a generer (ou id si ancienne methode)
	 *		\param		outputlangs		Lang output object
	 * 	 	\return	    int     		1=ok, 0=ko
	 */
	function write_file(&$object, $outputlangs)
	{
		global $user,$conf,$langs;
		$default_font_size = pdf_getPDFFontSize($outputlangs);

		$object->fetch_thirdparty();

		if (! is_object($outputlangs)) $outputlangs=$langs;
		// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
		if (!class_exists('TCPDF')) $outputlangs->charset_output='ISO-8859-1';

		$outputlangs->load("main");
		$outputlangs->load("dict");
		$outputlangs->load("companies");
		$outputlangs->load("bills");
		$outputlangs->load("products");
		$outputlangs->load("propal");
		$outputlangs->load("deliveries");
        $outputlangs->load("sendings");

		if ($conf->expedition->dir_output)
		{
			// Definition de $dir et $file
			if ($object->specimen)
			{
				$dir = $conf->expedition->dir_output."/sending";
				$file = $dir . "/SPECIMEN.pdf";
			}
			else
			{
				$expref = dol_sanitizeFileName($object->ref);
				$dir = $conf->expedition->dir_output."/sending/" . $expref;
				$file = $dir . "/" . $expref . ".pdf";
			}

			if (! file_exists($dir))
			{
				if (create_exdir($dir) < 0)
				{
					$this->error=$outputlangs->transnoentities("ErrorCanNotCreateDir",$dir);
					return 0;
				}
			}

			if (file_exists($dir))
			{
                $pdf=pdf_getInstance($this->format);

                if (class_exists('TCPDF'))
                {
                    $pdf->setPrintHeader(false);
                    $pdf->setPrintFooter(false);
                }
                $pdf->SetFont(pdf_getPDFFont($outputlangs));

				$pdf->Open();
				$pagenb=0;
				$pdf->SetDrawColor(128,128,128);

				$pdf->AliasNbPages();

				$pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
				$pdf->SetSubject($outputlangs->transnoentities("Sending"));
				$pdf->SetCreator("Dolibarr ".DOL_VERSION);
				$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
				$pdf->SetKeyWords($outputlangs->convToOutputCharset($fac->ref)." ".$outputlangs->transnoentities("Sending"));
				if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) $pdf->SetCompression(false);

				$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
				$pdf->SetAutoPageBreak(1,0);

				// New page
				$pdf->AddPage();
				$pagenb++;
				$this->_pagehead($pdf, $object, 1, $outputlangs);
				$pdf->SetFont('','', $default_font_size - 1);
				$pdf->MultiCell(0, 3, '');		// Set interline to 3
				$pdf->SetTextColor(0,0,0);

				$tab_top = 90;
				$tab_height = 170;
				
				if (! empty($object->note_public) || ! empty($object->tracking_number))
				{
					$tab_top = 88;
					
					// Tracking number
					if (! empty($object->tracking_number))
					{
						$object->GetUrlTrackingStatus($object->tracking_number);
						if (! empty($object->tracking_url))
						{
							if ($object->expedition_method_id > 0)
							{
								// Get code using getLabelFromKey
								$code=$outputlangs->getLabelFromKey($this->db,$object->expedition_method_id,'c_shipment_mode','rowid','code');
								$label=$outputlangs->trans("LinkToTrackYourPackage")."<br>";
								$label.=$outputlangs->trans("SendingMethod".strtoupper($code))." :";
								$pdf->SetFont('','B', $default_font_size - 2);
								$pdf->writeHTMLCell(60, 4, $this->posxdesc-1, $tab_top-1, $label." ".$object->tracking_url, 0, 1, false, true, 'L');
							}
						}
					}

					// Affiche notes
					if (! empty($object->note_public))
					{
						$pdf->SetFont('','', $default_font_size - 1);   // Dans boucle pour gerer multi-page
						$pdf->SetXY ($this->posxdesc-1, $tab_top);
						$pdf->MultiCell(190, 3, $outputlangs->convToOutputCharset($object->note_public), 0, 'L');
					}
					
					$nexY = $pdf->GetY();
					$height_note=$nexY-$tab_top;

					// Rect prend une longueur en 3eme param
					$pdf->SetDrawColor(192,192,192);
					$pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
					
					$tab_height = $tab_height - $height_note;
					$tab_top = $nexY+6;
				}
				else
				{
					$height_note=0;
				}
				
				$this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs);

				$nexY = $tab_top + 7;

				for ($i = 0 ; $i < sizeof($object->lines) ; $i++)
				{
					$curY = $nexY;

					$pdf->SetFont('','', $default_font_size - 1);   // Dans boucle pour gerer multi-page

					// Description de la ligne produit
					pdf_writelinedesc($pdf,$object,$i,$outputlangs,150,3,$this->posxdesc,$curY,0,1);

					$pdf->SetFont('','', $default_font_size - 1);   // On repositionne la police par defaut
					$nexY = $pdf->GetY();

					$pdf->SetXY ($this->posxqtyordered+5, $curY);
					$pdf->MultiCell(30, 3, $object->lines[$i]->qty_asked,'','C');

					$pdf->SetXY ($this->posxqtytoship+5, $curY);
					$pdf->MultiCell(30, 3, $object->lines[$i]->qty_shipped,'','C');

					$nexY+=2;    // Passe espace entre les lignes
				}


				// Pied de page
				$this->_pagefoot($pdf,$object,$outputlangs);
				$pdf->AliasNbPages();

				$pdf->Close();

				$pdf->Output($file,'F');
				if (! empty($conf->global->MAIN_UMASK))
				@chmod($file, octdec($conf->global->MAIN_UMASK));

				return 1;
			}
			else
			{
				$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
				return 0;
			}
		}
		else
		{
			$this->error=$langs->transnoentities("ErrorConstantNotDefined","EXP_OUTPUTDIR");
			return 0;
		}
		$this->error=$langs->transnoentities("ErrorUnknown");
		return 0;   // Erreur par defaut
	}
 /**
  *  Function to build pdf onto disk
  *
  *  @param		Object		$object				Object to generate
  *  @param		Translate	$outputlangs		Lang output object
  *  @param		string		$srctemplatepath	Full path of source filename for generator using a template file
  *  @param		int			$hidedetails		Do not show line details
  *  @param		int			$hidedesc			Do not show desc
  *  @param		int			$hideref			Do not show ref
  *  @param		object		$hookmanager		Hookmanager object
  *  @return     int         	    			1=OK, 0=KO
  */
 function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0, $hookmanager = false)
 {
     global $user, $langs, $conf, $mysoc, $db;
     if (!is_object($outputlangs)) {
         $outputlangs = $langs;
     }
     // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
     if (!empty($conf->global->MAIN_USE_FPDF)) {
         $outputlangs->charset_output = 'ISO-8859-1';
     }
     $outputlangs->load("main");
     $outputlangs->load("dict");
     $outputlangs->load("companies");
     $outputlangs->load("bills");
     $outputlangs->load("products");
     if ($conf->facture->dir_output) {
         $object->fetch_thirdparty();
         $deja_regle = $object->getSommePaiement();
         $amount_credit_notes_included = $object->getSumCreditNotesUsed();
         $amount_deposits_included = $object->getSumDepositsUsed();
         // Definition of $dir and $file
         if ($object->specimen) {
             $dir = $conf->facture->dir_output;
             $file = $dir . "/SPECIMEN.pdf";
         } else {
             $objectref = dol_sanitizeFileName($object->ref);
             $dir = $conf->facture->dir_output . "/" . $objectref;
             $file = $dir . "/" . $objectref . ".pdf";
         }
         if (!file_exists($dir)) {
             if (dol_mkdir($dir) < 0) {
                 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
                 return 0;
             }
         }
         if (file_exists($dir)) {
             $nblignes = count($object->lines);
             $pdf = pdf_getInstance($this->format);
             $default_font_size = pdf_getPDFFontSize($outputlangs);
             // Must be after pdf_getInstance
             $heightforinfotot = 50;
             // Height reserved to output the info and total part
             $heightforfreetext = isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5;
             // Height reserved to output the free text on last page
             $heightforfooter = $this->marge_basse + 8;
             // Height reserved to output the footer (value include bottom margin)
             $pdf->SetAutoPageBreak(1, 0);
             if (class_exists('TCPDF')) {
                 $pdf->setPrintHeader(false);
                 $pdf->setPrintFooter(false);
             }
             $pdf->SetFont(pdf_getPDFFont($outputlangs));
             // Set path to the background PDF File
             if (empty($conf->global->MAIN_DISABLE_FPDI) && !empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
                 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output . '/' . $conf->global->MAIN_ADD_PDF_BACKGROUND);
                 $tplidx = $pdf->importPage(1);
             }
             $pdf->Open();
             $pagenb = 0;
             $pdf->SetDrawColor(128, 128, 128);
             $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
             $pdf->SetSubject($outputlangs->transnoentities("Invoice"));
             $pdf->SetCreator("Dolibarr " . DOL_VERSION);
             $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
             $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref) . " " . $outputlangs->transnoentities("Invoice"));
             if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
                 $pdf->SetCompression(false);
             }
             $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
             // Left, Top, Right
             // Positionne $this->atleastonediscount si on a au moins une remise
             for ($i = 0; $i < $nblignes; $i++) {
                 if ($object->lines[$i]->remise_percent) {
                     $this->atleastonediscount++;
                 }
             }
             // New page
             $pdf->AddPage();
             if (!empty($tplidx)) {
                 $pdf->useTemplate($tplidx);
             }
             $pagenb++;
             $this->_pagehead($pdf, $object, 1, $outputlangs, $hookmanager);
             $pdf->SetFont('', '', $default_font_size - 1);
             $pdf->MultiCell(0, 3, '');
             // Set interline to 3
             $pdf->SetTextColor(0, 0, 0);
             $tab_top = 90;
             $tab_top_newpage = empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 : 10;
             $tab_height = 130;
             $tab_height_newpage = 150;
             // Affiche notes
             if (!empty($object->note_public)) {
                 $tab_top = 88;
                 $pdf->SetFont('', '', $default_font_size - 1);
                 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($object->note_public), 0, 1);
                 $nexY = $pdf->GetY();
                 $height_note = $nexY - $tab_top;
                 // Rect prend une longueur en 3eme param
                 $pdf->SetDrawColor(192, 192, 192);
                 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
                 $tab_height = $tab_height - $height_note;
                 $tab_top = $nexY + 6;
             } else {
                 $height_note = 0;
             }
             $iniY = $tab_top + 7;
             $curY = $tab_top + 7;
             $nexY = $tab_top + 7;
             // Loop on each lines
             for ($i = 0; $i < $nblignes; $i++) {
                 $curY = $nexY;
                 $pdf->SetFont('', '', $default_font_size - 1);
                 // Into loop to work with multipage
                 $pdf->SetTextColor(0, 0, 0);
                 $pdf->setTopMargin($tab_top_newpage);
                 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
                 // The only function to edit the bottom margin of current page to set it.
                 $pageposbefore = $pdf->getPage();
                 // Description of product line
                 $curX = $this->posxdesc - 1;
                 $showpricebeforepagebreak = 1;
                 $pdf->startTransaction();
                 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 3, $curX, $curY, $hideref, $hidedesc, 0, $hookmanager);
                 $pageposafter = $pdf->getPage();
                 if ($pageposafter > $pageposbefore) {
                     $pdf->rollbackTransaction(true);
                     $pageposafter = $pageposbefore;
                     //print $pageposafter.'-'.$pageposbefore;exit;
                     $pdf->setPageOrientation('', 1, $heightforfooter);
                     // The only function to edit the bottom margin of current page to set it.
                     pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 4, $curX, $curY, $hideref, $hidedesc, 0, $hookmanager);
                     $pageposafter = $pdf->getPage();
                     $posyafter = $pdf->GetY();
                     //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
                     if ($posyafter > $this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot)) {
                         if ($i == $nblignes - 1) {
                             $pdf->AddPage('', '', true);
                             if (!empty($tplidx)) {
                                 $pdf->useTemplate($tplidx);
                             }
                             if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
                                 $this->_pagehead($pdf, $object, 0, $outputlangs, $hookmanager);
                             }
                             $pdf->setPage($pagenb + 1);
                         }
                     } else {
                         // We found a page break
                         $showpricebeforepagebreak = 0;
                     }
                 } else {
                     $pdf->commitTransaction();
                 }
                 $nexY = $pdf->GetY();
                 $pageposafter = $pdf->getPage();
                 $pdf->setPage($pageposbefore);
                 $pdf->setTopMargin($this->marge_haute);
                 $pdf->setPageOrientation('', 1, 0);
                 // The only function to edit the bottom margin of current page to set it.
                 // We suppose that a too long description is moved completely on next page
                 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
                     $pdf->setPage($pageposafter);
                     $curY = $tab_top_newpage;
                 }
                 $pdf->SetFont('', '', $default_font_size - 1);
                 // On repositionne la police par defaut
                 // VAT Rate
                 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
                     $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails, $hookmanager);
                     $pdf->SetXY($this->posxtva, $curY);
                     $pdf->MultiCell($this->posxup - $this->posxtva - 1, 3, $vat_rate, 0, 'R');
                 }
                 // Unit price before discount
                 $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails, $hookmanager);
                 $pdf->SetXY($this->posxup, $curY);
                 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 3, $up_excl_tax, 0, 'R', 0);
                 // Quantity
                 $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails, $hookmanager);
                 $pdf->SetXY($this->posxqty, $curY);
                 $pdf->MultiCell($this->posxdiscount - $this->posxqty - 1, 3, $qty, 0, 'R');
                 // Enough for 6 chars
                 // Discount on line
                 if ($object->lines[$i]->remise_percent) {
                     $pdf->SetXY($this->posxdiscount - 2, $curY);
                     $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails, $hookmanager);
                     $pdf->MultiCell($this->postotalht - $this->posxdiscount + 2, 3, $remise_percent, 0, 'R');
                 }
                 // Total HT line
                 $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails, $hookmanager);
                 $pdf->SetXY($this->postotalht, $curY);
                 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
                 // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
                 $tvaligne = $object->lines[$i]->total_tva;
                 $localtax1ligne = $object->lines[$i]->total_localtax1;
                 $localtax2ligne = $object->lines[$i]->total_localtax2;
                 $localtax1_rate = $object->lines[$i]->localtax1_tx;
                 $localtax2_rate = $object->lines[$i]->localtax2_tx;
                 $localtax1_type = $object->lines[$i]->localtax1_type;
                 $localtax2_type = $object->lines[$i]->localtax2_type;
                 if ($object->remise_percent) {
                     $tvaligne -= $tvaligne * $object->remise_percent / 100;
                 }
                 if ($object->remise_percent) {
                     $localtax1ligne -= $localtax1ligne * $object->remise_percent / 100;
                 }
                 if ($object->remise_percent) {
                     $localtax2ligne -= $localtax2ligne * $object->remise_percent / 100;
                 }
                 $vatrate = (string) $object->lines[$i]->tva_tx;
                 // TODO : store local taxes types into object lines and remove this
                 $localtax1_array = getLocalTaxesFromRate($vatrate, 1, $mysoc);
                 $localtax2_array = getLocalTaxesFromRate($vatrate, 2, $mysoc);
                 if (!isset($localtax1_type)) {
                     $localtax1_type = $localtax1_array[0];
                 }
                 if (!isset($localtax2_type)) {
                     $localtax2_type = $localtax2_array[0];
                 }
                 //end TODO
                 // retrieve global local tax
                 if ($localtax1_type == '7') {
                     $localtax1_rate = $localtax1_array[1];
                 }
                 if ($localtax2_type == '7') {
                     $localtax2_rate = $localtax2_array[1];
                 }
                 if ($localtax1_type && ($localtax1ligne != 0 || $localtax1_type == '7')) {
                     $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
                 }
                 if ($localtax2_type && ($localtax2ligne != 0 || $localtax2_type == '7')) {
                     $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
                 }
                 if (($object->lines[$i]->info_bits & 0x1) == 0x1) {
                     $vatrate .= '*';
                 }
                 if (!isset($this->tva[$vatrate])) {
                     $this->tva[$vatrate] = '';
                 }
                 $this->tva[$vatrate] += $tvaligne;
                 // Add line
                 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < $nblignes - 1) {
                     $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(210, 210, 210)));
                     //$pdf->SetDrawColor(190,190,200);
                     $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
                     $pdf->SetLineStyle(array('dash' => 0));
                 }
                 $nexY += 2;
                 // Passe espace entre les lignes
                 // Detect if some page were added automatically and output _tableau for past pages
                 while ($pagenb < $pageposafter) {
                     $pdf->setPage($pagenb);
                     if ($pagenb == 1) {
                         $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
                     } else {
                         $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
                     }
                     $this->_pagefoot($pdf, $object, $outputlangs, 1);
                     $pagenb++;
                     $pdf->setPage($pagenb);
                     $pdf->setPageOrientation('', 1, 0);
                     // The only function to edit the bottom margin of current page to set it.
                     if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
                         $this->_pagehead($pdf, $object, 0, $outputlangs, $hookmanager);
                     }
                 }
                 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
                     if ($pagenb == 1) {
                         $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
                     } else {
                         $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
                     }
                     $this->_pagefoot($pdf, $object, $outputlangs, 1);
                     // New page
                     $pdf->AddPage();
                     if (!empty($tplidx)) {
                         $pdf->useTemplate($tplidx);
                     }
                     $pagenb++;
                     if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
                         $this->_pagehead($pdf, $object, 0, $outputlangs, $hookmanager);
                     }
                 }
             }
             // Show square
             if ($pagenb == 1) {
                 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
                 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
             } else {
                 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
                 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
             }
             // Affiche zone infos
             $posy = $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
             // Affiche zone totaux
             $posy = $this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
             // Affiche zone versements
             if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included) {
                 $posy = $this->_tableau_versements($pdf, $object, $posy, $outputlangs);
             }
             // Pied de page
             $this->_pagefoot($pdf, $object, $outputlangs);
             //$pdf->AliasNbPages();
             $pdf->Close();
             $pdf->Output($file, 'F');
             // Add pdfgeneration hook
             if (!is_object($hookmanager)) {
                 include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
                 $hookmanager = new HookManager($this->db);
             }
             $hookmanager->initHooks(array('pdfgeneration'));
             $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
             global $action;
             $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action);
             // Note that $action and $object may have been modified by some hooks
             if (!empty($conf->global->MAIN_UMASK)) {
                 @chmod($file, octdec($conf->global->MAIN_UMASK));
             }
             return 1;
             // Pas d'erreur
         } else {
             $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
             return 0;
         }
     } else {
         $this->error = $langs->trans("ErrorConstantNotDefined", "FAC_OUTPUTDIR");
         return 0;
     }
     $this->error = $langs->trans("ErrorUnknown");
     return 0;
     // Erreur par defaut
 }
 /**
  *	Function to build pdf onto disk
  *
  *	@param		Object		&$object			Object expedition to generate (or id if old method)
  *	@param		Translate	$outputlangs		Lang output object
  *  @param		string		$srctemplatepath	Full path of source filename for generator using a template file
  *  @param		int			$hidedetails		Do not show line details
  *  @param		int			$hidedesc			Do not show desc
  *  @param		int			$hideref			Do not show ref
  *  @return     int         	    			1=OK, 0=KO
  */
 function write_file(&$object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
 {
     global $user, $conf, $langs, $mysoc, $hookmanager;
     $object->fetch_thirdparty();
     if (!is_object($outputlangs)) {
         $outputlangs = $langs;
     }
     // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
     if (!empty($conf->global->MAIN_USE_FPDF)) {
         $outputlangs->charset_output = 'ISO-8859-1';
     }
     $outputlangs->load("main");
     $outputlangs->load("dict");
     $outputlangs->load("companies");
     $outputlangs->load("bills");
     $outputlangs->load("products");
     $outputlangs->load("propal");
     $outputlangs->load("deliveries");
     $outputlangs->load("sendings");
     if ($conf->expedition->dir_output) {
         $object->fetch_thirdparty();
         $origin = $object->origin;
         //Creation de l expediteur
         $this->expediteur = $mysoc;
         //Creation du destinataire
         $idcontact = $object->{$origin}->getIdContact('external', 'SHIPPING');
         $this->destinataire = new Contact($this->db);
         if (!empty($idcontact[0])) {
             $this->destinataire->fetch($idcontact[0]);
         }
         //Creation du livreur
         $idcontact = $object->{$origin}->getIdContact('internal', 'LIVREUR');
         $this->livreur = new User($this->db);
         if (!empty($idcontact[0])) {
             $this->livreur->fetch($idcontact[0]);
         }
         // Definition de $dir et $file
         if ($object->specimen) {
             $dir = $conf->expedition->dir_output . "/sending";
             $file = $dir . "/SPECIMEN.pdf";
         } else {
             $expref = dol_sanitizeFileName($object->ref);
             $dir = $conf->expedition->dir_output . "/sending/" . $expref;
             $file = $dir . "/" . $expref . ".pdf";
         }
         if (!file_exists($dir)) {
             if (dol_mkdir($dir) < 0) {
                 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
                 return 0;
             }
         }
         if (file_exists($dir)) {
             $nblignes = count($object->lines);
             $pdf = pdf_getInstance($this->format, 'mm', 'l');
             $default_font_size = pdf_getPDFFontSize($outputlangs);
             $heightforinfotot = 0;
             // Height reserved to output the info and total part
             $heightforfreetext = isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5;
             // Height reserved to output the free text on last page
             $heightforfooter = $this->marge_basse + 8;
             // Height reserved to output the footer (value include bottom margin)
             $pdf->SetAutoPageBreak(1, 0);
             if (class_exists('TCPDF')) {
                 $pdf->setPrintHeader(false);
                 $pdf->setPrintFooter(false);
             }
             $pdf->SetFont(pdf_getPDFFont($outputlangs));
             // Set path to the background PDF File
             if (empty($conf->global->MAIN_DISABLE_FPDI) && !empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
                 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output . '/' . $conf->global->MAIN_ADD_PDF_BACKGROUND);
                 $tplidx = $pdf->importPage(1);
             }
             $pdf->Open();
             $pagenb = 0;
             $pdf->SetDrawColor(128, 128, 128);
             //$pdf->AliasNbPages();
             $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
             $pdf->SetSubject($outputlangs->transnoentities("Sending"));
             $pdf->SetCreator("Dolibarr " . DOL_VERSION);
             $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
             $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref) . " " . $outputlangs->transnoentities("Sending"));
             if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
                 $pdf->SetCompression(false);
             }
             $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
             // Left, Top, Right
             // New page
             $pdf->AddPage();
             $pagenb++;
             $this->_pagehead($pdf, $object, 1, $outputlangs);
             $pdf->SetFont('', '', $default_font_size - 3);
             $pdf->MultiCell(0, 3, '');
             // Set interline to 3
             $pdf->SetTextColor(0, 0, 0);
             $tab_top = 52;
             $tab_top_newpage = empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 : 10;
             $tab_height = $this->page_hauteur - $tab_top - $heightforfooter;
             $tab_height_newpage = $this->page_hauteur - $tab_top_newpage - $heightforfooter;
             // Affiche notes
             if (!empty($object->note_public)) {
                 $pdf->SetFont('', '', $default_font_size - 1);
                 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $tab_top, dol_htmlentitiesbr($object->note_public), 0, 1);
                 $nexY = $pdf->GetY();
                 $height_note = $nexY - $tab_top;
                 // Rect prend une longueur en 3eme param
                 $pdf->SetDrawColor(192, 192, 192);
                 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
                 $tab_height = $tab_height - $height_note;
                 $tab_top = $nexY + 6;
             } else {
                 $height_note = 0;
             }
             $pdf->SetFillColor(240, 240, 240);
             $pdf->SetTextColor(0, 0, 0);
             $pdf->SetXY(10, $tab_top + 5);
             $iniY = $tab_top + 7;
             $curY = $tab_top + 7;
             $nexY = $tab_top + 7;
             $num = count($object->lines);
             // Loop on each lines
             for ($i = 0; $i < $num; $i++) {
                 $curY = $nexY;
                 $pdf->SetFont('', '', $default_font_size - 3);
                 $pdf->SetTextColor(0, 0, 0);
                 $pdf->setTopMargin($tab_top_newpage);
                 $pdf->setPageOrientation('', 1, $heightforfooter);
                 // The only function to edit the bottom margin of current page to set it.
                 $pageposbefore = $pdf->getPage();
                 // Description de la ligne produit
                 $libelleproduitservice = pdf_writelinedesc($pdf, $object, $i, $outputlangs, 90, 3, 50, $curY, 0, 1);
                 $nexY = $pdf->GetY();
                 $pageposafter = $pdf->getPage();
                 $pdf->setPage($pageposbefore);
                 $pdf->setTopMargin($this->marge_haute);
                 $pdf->setPageOrientation('', 1, 0);
                 // The only function to edit the bottom margin of current page to set it.
                 // We suppose that a too long description is moved completely on next page
                 if ($pageposafter > $pageposbefore) {
                     $pdf->setPage($pageposafter);
                     $curY = $tab_top_newpage;
                 }
                 $pdf->SetFont('', '', $default_font_size - 3);
                 //Creation des cases a cocher
                 $pdf->Rect(10 + 3, $curY, 3, 3);
                 $pdf->Rect(20 + 3, $curY, 3, 3);
                 //Insertion de la reference du produit
                 $pdf->SetXY(30, $curY);
                 $pdf->SetFont('', 'B', $default_font_size - 3);
                 $pdf->MultiCell(24, 3, $outputlangs->convToOutputCharset($object->lines[$i]->ref), 0, 'L', 0);
                 $pdf->SetXY(140, $curY);
                 $pdf->MultiCell(30, 3, $object->lines[$i]->qty_asked, 0, 'C', 0);
                 $pdf->SetXY(170, $curY);
                 $pdf->MultiCell(30, 3, $object->lines[$i]->qty_shipped, 0, 'C', 0);
                 // Add line
                 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < $nblignes - 1) {
                     $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(210, 210, 210)));
                     //$pdf->SetDrawColor(190,190,200);
                     $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
                     $pdf->SetLineStyle(array('dash' => 0));
                 }
                 $nexY += 2;
                 // Passe espace entre les lignes
                 // Detect if some page were added automatically and output _tableau for past pages
                 while ($pagenb < $pageposafter) {
                     $pdf->setPage($pagenb);
                     if ($pagenb == 1) {
                         $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
                     } else {
                         $this->_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
                     }
                     $this->_pagefoot($pdf, $object, $outputlangs, 1);
                     $pagenb++;
                     $pdf->setPage($pagenb);
                     $pdf->setPageOrientation('', 1, 0);
                     // The only function to edit the bottom margin of current page to set it.
                 }
                 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
                     if ($pagenb == 1) {
                         $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
                     } else {
                         $this->_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
                     }
                     $this->_pagefoot($pdf, $object, $outputlangs, 1);
                     // New page
                     $pdf->AddPage();
                     $pagenb++;
                 }
             }
             // Show square
             if ($pagenb == 1) {
                 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
                 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
             } else {
                 $this->_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
                 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
             }
             // Pied de page
             $this->_pagefoot($pdf, $object, $outputlangs);
             //$pdf->AliasNbPages();
             $pdf->Close();
             $pdf->Output($file, 'F');
             if (!empty($conf->global->MAIN_UMASK)) {
                 @chmod($file, octdec($conf->global->MAIN_UMASK));
             }
             return 1;
         } else {
             $this->error = $outputlangs->transnoentities("ErrorCanNotCreateDir", $dir);
             return 0;
         }
     } else {
         $this->error = $outputlangs->transnoentities("ErrorConstantNotDefined", "EXP_OUTPUTDIR");
         return 0;
     }
     $this->error = $outputlangs->transnoentities("ErrorUnknown");
     return 0;
     // Erreur par defaut
 }
コード例 #5
0
	/**
     *  Function to build pdf onto disk
     *  @param      object          Id of object to generate
     *  @param      outputlangs     Lang output object
     *  @param      srctemplatepath Full path of source filename for generator using a template file
     *  @param      hidedetails     Do not show line details
     *  @param      hidedesc        Do not show desc
     *  @param      hideref         Do not show ref
     *  @return     int             1=OK, 0=KO
	 */
	function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0)
	{
		global $user,$conf,$langs,$mysoc;

		if (! is_object($outputlangs)) $outputlangs=$langs;
		// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
		if (!class_exists('TCPDF')) $outputlangs->charset_output='ISO-8859-1';

		$outputlangs->load("main");
		$outputlangs->load("dict");
		$outputlangs->load("companies");
		$outputlangs->load("bills");
		$outputlangs->load("products");
        $outputlangs->load("orders");

		$default_font_size = pdf_getPDFFontSize($outputlangs);

		if ($conf->commande->dir_output)
		{
			// Definition of $dir and $file
			if ($object->specimen)
			{
				$dir = $conf->commande->dir_output;
				$file = $dir . "/SPECIMEN.pdf";
			}
			else
			{
				$objectref = dol_sanitizeFileName($object->ref);
				$dir = $conf->commande->dir_output . "/" . $objectref;
				$file = $dir . "/" . $objectref . ".pdf";
			}

			if (! file_exists($dir))
			{
				if (create_exdir($dir) < 0)
				{
					$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
					return 0;
				}
			}

			if (file_exists($dir))
			{
                $pdf=pdf_getInstance($this->format);

                if (class_exists('TCPDF'))
                {
                    $pdf->setPrintHeader(false);
                    $pdf->setPrintFooter(false);
                }
                $pdf->SetFont(pdf_getPDFFont($outputlangs));

				$pdf->Open();
				$pagenb=0;
				$pdf->SetDrawColor(128,128,128);

				$pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
				$pdf->SetSubject($outputlangs->transnoentities("Order"));
				$pdf->SetCreator("Dolibarr ".DOL_VERSION);
				$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
				$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Order"));
				if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) $pdf->SetCompression(false);

				$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
				$pdf->SetAutoPageBreak(1,0);

				// New page
				$pdf->AddPage();
				$pagenb++;
				$this->_pagehead($pdf, $object, 1, $outputlangs);
				$pdf->SetFont('','', $default_font_size - 1);
				$pdf->MultiCell(0, 3, '');		// Set interline to 3
				$pdf->SetTextColor(0,0,0);


				$tab_top = 100;
				$tab_height = 140;

				$pdf->SetFillColor(220,220,220);

				$pdf->SetTextColor(0,0,0);
				$pdf->SetFont('','', $default_font_size - 1);

				$pdf->SetXY (10, $tab_top + 10 );

				$iniY = $pdf->GetY();
				$curY = $pdf->GetY();
				$nexY = $pdf->GetY();
				$nblignes = sizeof($object->lines);

				for ($i = 0 ; $i < $nblignes ; $i++)
				{
					$curY = $nexY;

					$pdf->SetFont('','', $default_font_size - 1);   // Dans boucle pour gerer multi-page

					// Description de la ligne produit
					pdf_writelinedesc($pdf,$object,$i,$outputlangs,100,3,30,$curY,1,$hidedesc);
					//$pdf->writeHTMLCell(100, 3, 30, $curY, $outputlangs->convToOutputCharset($libelleproduitservice), 0, 1);

					$pdf->SetFont('','', $default_font_size - 1);   // On repositionne la police par defaut
					$nexY = $pdf->GetY();

					$ref = pdf_getlineref($object, $i, $outputlangs);
					$pdf->SetXY (10, $curY);
					$pdf->MultiCell(20, 3, $ref, 0, 'C');

					$vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
					$pdf->SetXY (133, $curY);
					$pdf->MultiCell(12, 3, $vat_rate, 0, 'C');

					$qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
					$pdf->SetXY (145, $curY);
					$pdf->MultiCell(10, 3, $qty, 0, 'C');

					$up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
					$pdf->SetXY (156, $curY);
					$pdf->MultiCell(18, 3, $up_excl_tax, 0, 'R', 0);

					$total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
					$pdf->SetXY (174, $curY);
					$pdf->MultiCell(26, 3, $total_excl_tax, 0, 'R', 0);

					$nexY+=2;    // Passe espace entre les lignes

					// cherche nombre de lignes a venir pour savoir si place suffisante
					if ($i < ($nblignes - 1) && empty($hidedesc))	// If it's not last line
					{
						//on recupere la description du produit suivant
						$follow_descproduitservice = $object->lines[$i+1]->desc;
						//on compte le nombre de ligne afin de verifier la place disponible (largeur de ligne 52 caracteres)
						$nblineFollowDesc = (dol_nboflines_bis($follow_descproduitservice,52,$outputlangs->charset_output)*4);
					}
					else	// If it's last line
					{
						$nblineFollowDesc = 0;
					}

					if (($nexY+$nblineFollowDesc) > ($tab_top+$tab_height) && $i < ($nblignes - 1))
					{
						$this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs);

						// New page
						$pdf->AddPage();
						$pagenb++;
						$this->_pagehead($pdf, $object, 0, $outputlangs);
						$pdf->SetFont('','', $default_font_size - 1);
						$pdf->MultiCell(0, 3, '');		// Set interline to 3
						$pdf->SetTextColor(0,0,0);

						$nexY = $tab_top + 8;
					}
				}

				$this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs);

				$bottomlasttab=$tab_top + $tab_height + 1;

				// Affiche zone infos
				$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);

				// Affiche zone totaux
				$tab2_top = 241;
				$tab2_lh = 4;

				$pdf->SetFont('','', $default_font_size);

				$pdf->SetXY (132, $tab2_top + 0);
				$pdf->MultiCell(42, $tab2_lh, $langs->transnoentities("TotalHT"), 0, 'R', 0);

				$pdf->SetXY (132, $tab2_top + $tab2_lh);
				$pdf->MultiCell(42, $tab2_lh, $langs->transnoentities("TotalVAT"), 0, 'R', 0);

				$pdf->SetXY (132, $tab2_top + ($tab2_lh*2));
				$pdf->MultiCell(42, $tab2_lh, $langs->transnoentities("TotalTTC"), 1, 'R', 1);

				$pdf->SetXY (174, $tab2_top + 0);
				$pdf->MultiCell(26, $tab2_lh, price($object->total_ht), 0, 'R', 0);

				$pdf->SetXY (174, $tab2_top + $tab2_lh);
				$pdf->MultiCell(26, $tab2_lh, price($object->total_tva), 0, 'R', 0);

				$pdf->SetXY (174, $tab2_top + ($tab2_lh*2));
				$pdf->MultiCell(26, $tab2_lh, price($object->total_ttc), 1, 'R', 1);

				// Pied de page
				$this->_pagefoot($pdf,$object,$outputlangs);
				$pdf->AliasNbPages();

				$pdf->Close();

				$pdf->Output($file,'F');
				if (! empty($conf->global->MAIN_UMASK))
					@chmod($file, octdec($conf->global->MAIN_UMASK));

				return 1;
			}
		}
		else
		{
			$this->error=$langs->transnoentities("ErrorConstantNotDefined","COMMANDE_OUTPUTDIR");
			return 0;
		}

		$this->error=$langs->transnoentities("ErrorUnknown");
		return 0;   // Erreur par defaut
	}
コード例 #6
0
 /**
  *	Fonction generant le bon de livraison sur le disque
  *
  *	@param	Object		$object   		Object livraison a generer
  *	@param	Translate	$outputlangs	Lang output object
  *	@return	int         				1 if OK, <=0 if KO
  */
 function write_file($object, $outputlangs)
 {
     global $user, $langs, $conf;
     $default_font_size = pdf_getPDFFontSize($outputlangs);
     if (!is_object($outputlangs)) {
         $outputlangs = $langs;
     }
     // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
     if (!empty($conf->global->MAIN_USE_FPDF)) {
         $outputlangs->charset_output = 'ISO-8859-1';
     }
     $outputlangs->load("main");
     $outputlangs->load("dict");
     $outputlangs->load("companies");
     $outputlangs->load("bills");
     $outputlangs->load("products");
     $outputlangs->load("deliveries");
     $outputlangs->load("sendings");
     if ($conf->expedition->dir_output . "/receipt") {
         $object->fetch_thirdparty();
         $nblines = count($object->lines);
         $objectref = dol_sanitizeFileName($object->ref);
         $dir = $conf->expedition->dir_output . "/receipt";
         if (!preg_match('/specimen/i', $objectref)) {
             $dir .= "/" . $objectref;
         }
         $file = $dir . "/" . $objectref . ".pdf";
         if (!file_exists($dir)) {
             if (dol_mkdir($dir) < 0) {
                 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
                 return 0;
             }
         }
         if (file_exists($dir)) {
             $pdf = pdf_getInstance($this->format);
             if (class_exists('TCPDF')) {
                 $pdf->setPrintHeader(false);
                 $pdf->setPrintFooter(false);
             }
             $pdf->SetFont(pdf_getPDFFont($outputlangs));
             // Set path to the background PDF File
             if (empty($conf->global->MAIN_DISABLE_FPDI) && !empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
                 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output . '/' . $conf->global->MAIN_ADD_PDF_BACKGROUND);
                 $tplidx = $pdf->importPage(1);
             }
             // Complete object by loading several other informations
             $expedition = new Expedition($this->db);
             $result = $expedition->fetch($object->expedition_id);
             $commande = new Commande($this->db);
             if ($expedition->origin == 'commande') {
                 $commande->fetch($expedition->origin_id);
             }
             $object->commande = $commande;
             $pdf->Open();
             $pagenb = 0;
             $pdf->SetDrawColor(128, 128, 128);
             $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
             $pdf->SetSubject($outputlangs->transnoentities("DeliveryOrder"));
             $pdf->SetCreator("Dolibarr " . DOL_VERSION);
             $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
             $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref) . " " . $outputlangs->transnoentities("DeliveryOrder"));
             if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) {
                 $pdf->SetCompression(false);
             }
             $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
             // Left, Top, Right
             $pdf->SetAutoPageBreak(1, 0);
             /*
             // Positionne $this->atleastonediscount si on a au moins une remise
             for ($i = 0 ; $i < $nblignes ; $i++)
             {
             if ($object->lines[$i]->remise_percent)
             {
             $this->atleastonediscount++;
             }
             }
             */
             // New page
             $pdf->AddPage();
             if (!empty($tplidx)) {
                 $pdf->useTemplate($tplidx);
             }
             $pagenb++;
             $this->_pagehead($pdf, $object, 1, $outputlangs);
             $pdf->SetFont('', '', $default_font_size - 1);
             $pdf->MultiCell(0, 3, '');
             // Set interline to 3
             $pdf->SetTextColor(0, 0, 0);
             $tab_top = 90;
             $tab_top_newpage = 50;
             $tab_height = 110;
             $tab_height_newpage = 150;
             // Affiche notes
             if (!empty($object->note_public)) {
                 $tab_top = 88;
                 $pdf->SetFont('', '', $default_font_size - 1);
                 // Dans boucle pour gerer multi-page
                 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($object->note_public), 0, 1);
                 $nexY = $pdf->GetY();
                 $height_note = $nexY - $tab_top;
                 // Rect prend une longueur en 3eme param
                 $pdf->SetDrawColor(192, 192, 192);
                 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
                 $tab_height = $tab_height - $height_note;
                 $tab_top = $nexY + 6;
             } else {
                 $height_note = 0;
             }
             $iniY = $tab_top + 7;
             $curY = $tab_top + 7;
             $nexY = $tab_top + 7;
             // Boucle sur les lignes
             for ($i = 0; $i < $nblines; $i++) {
                 $curY = $nexY;
                 $pdf->SetFont('', '', $default_font_size - 1);
                 // Dans boucle pour gerer multi-page
                 // Description de la ligne produit
                 //$libelleproduitservice=pdf_getlinedesc($object,$i,$outputlangs);
                 pdf_writelinedesc($pdf, $object, $i, $outputlangs, 108, 3, $this->posxdesc - 1, $curY);
                 //$pdf->writeHTMLCell(108, 3, $this->posxdesc-1, $curY, $outputlangs->convToOutputCharset($libelleproduitservice), 0, 1);
                 $pdf->SetFont('', '', $default_font_size - 1);
                 // On repositionne la police par defaut
                 $nexY = $pdf->GetY();
                 /*
                 // TVA
                 $pdf->SetXY($this->posxtva, $curY);
                 $pdf->MultiCell(10, 4, ($object->lines[$i]->tva_tx < 0 ? '*':'').abs($object->lines[$i]->tva_tx), 0, 'R');
                 
                 // Prix unitaire HT avant remise
                 $pdf->SetXY($this->posxup, $curY);
                 $pdf->MultiCell(20, 4, price($object->lines[$i]->subprice), 0, 'R', 0);
                 */
                 // Quantity
                 $pdf->SetXY($this->posxqty, $curY);
                 $pdf->MultiCell(30, 3, $object->lines[$i]->qty_shipped, 0, 'R');
                 /*
                 // Remise sur ligne
                 $pdf->SetXY($this->posxdiscount, $curY);
                 if ($object->lines[$i]->remise_percent)
                 {
                 $pdf->MultiCell(14, 3, $object->lines[$i]->remise_percent."%", 0, 'R');
                 }
                 
                 // Total HT ligne
                 $pdf->SetXY($this->postotalht, $curY);
                 $total = price($object->lines[$i]->price * $object->lines[$i]->qty);
                 $pdf->MultiCell(23, 3, $total, 0, 'R', 0);
                 
                 // Collecte des totaux par valeur de tva
                 // dans le tableau tva["taux"]=total_tva
                 $tvaligne=$object->lines[$i]->price * $object->lines[$i]->qty;
                 if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
                 $this->tva[ (string) $object->lines[$i]->tva_tx ] += $tvaligne;
                 */
                 $nexY += 2;
                 // Passe espace entre les lignes
                 // Cherche nombre de lignes a venir pour savoir si place suffisante
                 if ($i < $nblines - 1 && empty($hidedesc)) {
                     //on recupere la description du produit suivant
                     $follow_descproduitservice = $object->lines[$i + 1]->desc;
                     //on compte le nombre de ligne afin de verifier la place disponible (largeur de ligne 52 caracteres)
                     $nblineFollowDesc = dol_nboflines_bis($follow_descproduitservice, 52, $outputlangs->charset_output) * 4;
                 } else {
                     $nblineFollowDesc = 0;
                 }
                 // Test if a new page is required
                 if ($pagenb == 1) {
                     $tab_top_in_current_page = $tab_top;
                     $tab_height_in_current_page = $tab_height;
                 } else {
                     $tab_top_in_current_page = $tab_top_newpage;
                     $tab_height_in_current_page = $tab_height_newpage;
                 }
                 if ($nexY + $nblineFollowDesc > $tab_top_in_current_page + $tab_height_in_current_page && $i < $nblines - 1) {
                     if ($pagenb == 1) {
                         $this->_tableau($pdf, $tab_top, $tab_height + 20, $nexY, $outputlangs);
                     } else {
                         $this->_tableau($pdf, $tab_top_newpage, $tab_height_newpage, $nexY, $outputlangs);
                     }
                     $this->_pagefoot($pdf, $object, $outputlangs);
                     // New page
                     $pdf->AddPage();
                     $pagenb++;
                     $this->_pagehead($pdf, $object, 0, $outputlangs);
                     $pdf->SetFont('', '', $default_font_size - 1);
                     $pdf->MultiCell(0, 3, '');
                     // Set interline to 3
                     $pdf->SetTextColor(0, 0, 0);
                     $nexY = $tab_top_newpage + 7;
                 }
             }
             // Show square
             if ($pagenb == 1) {
                 $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs);
                 $bottomlasttab = $tab_top + $tab_height + 1;
             } else {
                 $this->_tableau($pdf, $tab_top_newpage, $tab_height_newpage, $nexY, $outputlangs);
                 $bottomlasttab = $tab_top_newpage + $tab_height_newpage + 1;
             }
             /*
              * Pied de page
              */
             $this->_pagefoot($pdf, $object, $outputlangs);
             // Check product remaining to be delivered
             // TODO doit etre modifie
             //$waitingDelivery = $object->getRemainingDelivered();
             $waitingDelivery = '';
             if (is_array($waitingDelivery) & !empty($waitingDelivery)) {
                 $pdf->AddPage('P', 'A4');
                 $this->_pagehead($pdf, $object, 1, $outputlangs);
                 $pdf->SetY(90);
                 $w = array(40, 100, 50);
                 $header = array($outputlangs->transnoentities('Reference'), $outputlangs->transnoentities('Label'), $outputlangs->transnoentities('Qty'));
                 // Header
                 $num = count($header);
                 for ($i = 0; $i < $num; $i++) {
                     $pdf->Cell($w[$i], 7, $header[$i], 1, 0, 'C');
                 }
                 $pdf->Ln();
                 // Data
                 foreach ($waitingDelivery as $value) {
                     $pdf->Cell($w[0], 6, $value['ref'], 1, 0, 'L');
                     $pdf->Cell($w[1], 6, $value['label'], 1, 0, 'L');
                     $pdf->Cell($w[2], 6, $value['qty'], 1, 1, 'R');
                     if ($pdf->GetY() > 250) {
                         $this->_pagefoot($pdf, $object, $outputlangs);
                         $pdf->AddPage('P', 'A4');
                         $pdf->SetFont('', '', $default_font_size - 1);
                         $this->_pagehead($pdf, $object, 0, $outputlangs);
                         $pdf->SetY(40);
                         $num = count($header);
                         for ($i = 0; $i < $num; $i++) {
                             $pdf->Cell($w[$i], 7, $header[$i], 1, 0, 'C');
                         }
                         $pdf->Ln();
                     }
                 }
                 $this->_pagefoot($pdf, $object, $outputlangs);
             }
             $pdf->AliasNbPages();
             $pdf->Close();
             $pdf->Output($file, 'F');
             if (!empty($conf->global->MAIN_UMASK)) {
                 @chmod($file, octdec($conf->global->MAIN_UMASK));
             }
             return 1;
             // Pas d'erreur
         } else {
             $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
             return 0;
         }
     }
     $this->error = $langs->transnoentities("ErrorConstantNotDefined", "LIVRAISON_OUTPUTDIR");
     return 0;
 }
コード例 #7
0
 /**
  *  Function to build pdf onto disk
  *
  *  @param		Object		$object				Object to generate
  *  @param		Translate	$outputlangs		Lang output object
  *  @param		string		$srctemplatepath	Full path of source filename for generator using a template file
  *  @param		int			$hidedetails		Do not show line details
  *  @param		int			$hidedesc			Do not show desc
  *  @param		int			$hideref			Do not show ref
  *  @return     int             			1=OK, 0=KO
  */
 function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
 {
     global $user, $langs, $conf, $mysoc, $hookmanager;
     if (!is_object($outputlangs)) {
         $outputlangs = $langs;
     }
     // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
     if (!empty($conf->global->MAIN_USE_FPDF)) {
         $outputlangs->charset_output = 'ISO-8859-1';
     }
     $outputlangs->load("main");
     $outputlangs->load("dict");
     $outputlangs->load("companies");
     $outputlangs->load("bills");
     $outputlangs->load("products");
     $outputlangs->load("deliveries");
     $outputlangs->load("sendings");
     if ($conf->expedition->dir_output) {
         $object->fetch_thirdparty();
         // Definition of $dir and $file
         if ($object->specimen) {
             $dir = $conf->expedition->dir_output . "/receipt";
             $file = $dir . "/SPECIMEN.pdf";
         } else {
             $objectref = dol_sanitizeFileName($object->ref);
             $dir = $conf->expedition->dir_output . "/receipt/" . $objectref;
             $file = $dir . "/" . $objectref . ".pdf";
         }
         if (!file_exists($dir)) {
             if (dol_mkdir($dir) < 0) {
                 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
                 return 0;
             }
         }
         if (file_exists($dir)) {
             // Add pdfgeneration hook
             if (!is_object($hookmanager)) {
                 include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
                 $hookmanager = new HookManager($this->db);
             }
             $hookmanager->initHooks(array('pdfgeneration'));
             $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
             global $action;
             $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action);
             // Note that $action and $object may have been modified by some hooks
             $nblines = count($object->lines);
             // Create pdf instance
             $pdf = pdf_getInstance($this->format);
             $default_font_size = pdf_getPDFFontSize($outputlangs);
             // Must be after pdf_getInstance
             $heightforinfotot = 30;
             // Height reserved to output the info and total part
             $heightforfreetext = isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5;
             // Height reserved to output the free text on last page
             $heightforfooter = $this->marge_basse + 8;
             // Height reserved to output the footer (value include bottom margin)
             $pdf->SetAutoPageBreak(1, 0);
             if (class_exists('TCPDF')) {
                 $pdf->setPrintHeader(false);
                 $pdf->setPrintFooter(false);
             }
             $pdf->SetFont(pdf_getPDFFont($outputlangs));
             // Set path to the background PDF File
             if (empty($conf->global->MAIN_DISABLE_FPDI) && !empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
                 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output . '/' . $conf->global->MAIN_ADD_PDF_BACKGROUND);
                 $tplidx = $pdf->importPage(1);
             }
             // We get the shipment that is the origin of delivery receipt
             $expedition = new Expedition($this->db);
             $result = $expedition->fetch($object->origin_id);
             // Now we get the order that is origin of shipment
             $commande = new Commande($this->db);
             if ($expedition->origin == 'commande') {
                 $commande->fetch($expedition->origin_id);
             }
             $object->commande = $commande;
             // We set order of shipment onto delivery.
             $object->commande->loadExpeditions();
             $pdf->Open();
             $pagenb = 0;
             $pdf->SetDrawColor(128, 128, 128);
             $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
             $pdf->SetSubject($outputlangs->transnoentities("DeliveryOrder"));
             $pdf->SetCreator("Dolibarr " . DOL_VERSION);
             $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
             $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref) . " " . $outputlangs->transnoentities("DeliveryOrder"));
             if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
                 $pdf->SetCompression(false);
             }
             $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
             // Left, Top, Right
             /*
             // Positionne $this->atleastonediscount si on a au moins une remise
             for ($i = 0 ; $i < $nblines ; $i++)
             {
              	if ($object->lines[$i]->remise_percent)
              	{
              		$this->atleastonediscount++;
              	}
             }
              				if (empty($this->atleastonediscount))
             {
             	$this->posxpicture+=($this->postotalht - $this->posxdiscount);
             	$this->posxtva+=($this->postotalht - $this->posxdiscount);
             	$this->posxup+=($this->postotalht - $this->posxdiscount);
             	$this->posxqty+=($this->postotalht - $this->posxdiscount);
             	$this->posxdiscount+=($this->postotalht - $this->posxdiscount);
             	//$this->postotalht;
             }
             */
             // New page
             $pdf->AddPage();
             if (!empty($tplidx)) {
                 $pdf->useTemplate($tplidx);
             }
             $pagenb++;
             $this->_pagehead($pdf, $object, 1, $outputlangs);
             $pdf->SetFont('', '', $default_font_size - 1);
             $pdf->MultiCell(0, 3, '');
             // Set interline to 3
             $pdf->SetTextColor(0, 0, 0);
             $tab_top = 90;
             $tab_top_newpage = empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 : 10;
             $tab_height = 130;
             $tab_height_newpage = 150;
             // Affiche notes
             if (!empty($object->note_public)) {
                 $tab_top = 88;
                 $pdf->SetFont('', '', $default_font_size - 1);
                 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($object->note_public), 0, 1);
                 $nexY = $pdf->GetY();
                 $height_note = $nexY - $tab_top;
                 // Rect prend une longueur en 3eme param
                 $pdf->SetDrawColor(192, 192, 192);
                 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
                 $tab_height = $tab_height - $height_note;
                 $tab_top = $nexY + 6;
             } else {
                 $height_note = 0;
             }
             $iniY = $tab_top + 7;
             $curY = $tab_top + 7;
             $nexY = $tab_top + 7;
             // Loop on each lines
             for ($i = 0; $i < $nblines; $i++) {
                 $curY = $nexY;
                 $pdf->SetFont('', '', $default_font_size - 1);
                 // Into loop to work with multipage
                 $pdf->SetTextColor(0, 0, 0);
                 $pdf->setTopMargin($tab_top_newpage);
                 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
                 // The only function to edit the bottom margin of current page to set it.
                 $pageposbefore = $pdf->getPage();
                 // Description of product line
                 $curX = $this->posxdesc - 1;
                 $showpricebeforepagebreak = 1;
                 $pdf->startTransaction();
                 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxcomm - $curX, 3, $curX, $curY, $hideref, $hidedesc);
                 $pageposafter = $pdf->getPage();
                 if ($pageposafter > $pageposbefore) {
                     $pdf->rollbackTransaction(true);
                     $pageposafter = $pageposbefore;
                     //print $pageposafter.'-'.$pageposbefore;exit;
                     $pdf->setPageOrientation('', 1, $heightforfooter);
                     // The only function to edit the bottom margin of current page to set it.
                     pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxcomm - $curX, 4, $curX, $curY, $hideref, $hidedesc);
                     $posyafter = $pdf->GetY();
                     if ($posyafter > $this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot)) {
                         if ($i == $nblines - 1) {
                             $pdf->AddPage('', '', true);
                             if (!empty($tplidx)) {
                                 $pdf->useTemplate($tplidx);
                             }
                             if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
                                 $this->_pagehead($pdf, $object, 0, $outputlangs);
                             }
                             $pdf->setPage($pageposafter + 1);
                         }
                     } else {
                         // We found a page break
                         $showpricebeforepagebreak = 0;
                     }
                 } else {
                     $pdf->commitTransaction();
                 }
                 $nexY = $pdf->GetY();
                 $pageposafter = $pdf->getPage();
                 $pdf->setPage($pageposbefore);
                 $pdf->setTopMargin($this->marge_haute);
                 $pdf->setPageOrientation('', 1, 0);
                 // The only function to edit the bottom margin of current page to set it.
                 // We suppose that a too long description is moved completely on next page
                 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
                     $pdf->setPage($pageposafter);
                     $curY = $tab_top_newpage;
                 }
                 $pdf->SetFont('', '', $default_font_size - 1);
                 // On repositionne la police par defaut
                 /*
                 // TVA
                 $pdf->SetXY($this->posxcomm, $curY);
                 $pdf->MultiCell(10, 4, ($object->lines[$i]->tva_tx < 0 ? '*':'').abs($object->lines[$i]->tva_tx), 0, 'R');
                 
                 // Prix unitaire HT avant remise
                 $pdf->SetXY($this->posxup, $curY);
                 $pdf->MultiCell(20, 4, price($object->lines[$i]->subprice), 0, 'R', 0);
                 */
                 // Quantity
                 //$qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
                 $pdf->SetXY($this->posxqty, $curY);
                 $pdf->MultiCell($this->posxremainingqty - $this->posxqty, 3, $object->lines[$i]->qty_shipped, 0, 'R');
                 // Remaining to ship
                 $pdf->SetXY($this->posxremainingqty, $curY);
                 $qtyRemaining = $object->lines[$i]->qty_asked - $object->commande->expeditions[$object->lines[$i]->fk_origin_line];
                 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxremainingqty, 3, $qtyRemaining, 0, 'R');
                 /*
                 // Remise sur ligne
                 $pdf->SetXY($this->posxdiscount, $curY);
                 if ($object->lines[$i]->remise_percent)
                 {
                 $pdf->MultiCell(14, 3, $object->lines[$i]->remise_percent."%", 0, 'R');
                 }
                 
                 // Total HT ligne
                 $pdf->SetXY($this->postotalht, $curY);
                 $total = price($object->lines[$i]->price * $object->lines[$i]->qty);
                 $pdf->MultiCell(23, 3, $total, 0, 'R', 0);
                 
                 // Collecte des totaux par valeur de tva
                 // dans le tableau tva["taux"]=total_tva
                 $tvaligne=$object->lines[$i]->price * $object->lines[$i]->qty;
                 if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
                 $this->tva[ (string) $object->lines[$i]->tva_tx ] += $tvaligne;
                 */
                 // Add line
                 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < $nblines - 1) {
                     $pdf->setPage($pageposafter);
                     $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(210, 210, 210)));
                     //$pdf->SetDrawColor(190,190,200);
                     $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
                     $pdf->SetLineStyle(array('dash' => 0));
                 }
                 $nexY += 2;
                 // Passe espace entre les lignes
                 // Detect if some page were added automatically and output _tableau for past pages
                 while ($pagenb < $pageposafter) {
                     $pdf->setPage($pagenb);
                     if ($pagenb == 1) {
                         $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
                     } else {
                         $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
                     }
                     $this->_pagefoot($pdf, $object, $outputlangs, 1);
                     $pagenb++;
                     $pdf->setPage($pagenb);
                     $pdf->setPageOrientation('', 1, 0);
                     // The only function to edit the bottom margin of current page to set it.
                     if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
                         $this->_pagehead($pdf, $object, 0, $outputlangs);
                     }
                 }
                 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
                     if ($pagenb == 1) {
                         $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
                     } else {
                         $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
                     }
                     $this->_pagefoot($pdf, $object, $outputlangs, 1);
                     // New page
                     $pdf->AddPage();
                     if (!empty($tplidx)) {
                         $pdf->useTemplate($tplidx);
                     }
                     $pagenb++;
                     if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
                         $this->_pagehead($pdf, $object, 0, $outputlangs);
                     }
                 }
             }
             // Show square
             if ($pagenb == 1) {
                 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
                 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
             } else {
                 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
                 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
             }
             // Affiche zone infos
             $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
             // Pied de page
             $this->_pagefoot($pdf, $object, $outputlangs);
             if (method_exists($pdf, 'AliasNbPages')) {
                 $pdf->AliasNbPages();
             }
             // Check product remaining to be delivered
             // TODO doit etre modifie
             //$waitingDelivery = $object->getRemainingDelivered();
             /*
             				$waitingDelivery='';
             
             				if (is_array($waitingDelivery) & !empty($waitingDelivery))
             				{
             					$pdf->AddPage();
             
             					$this->_pagehead($pdf, $object, 1, $outputlangs);
             					$pdf-> SetY(90);
             
             					$w=array(40,100,50);
             					$header=array($outputlangs->transnoentities('Reference'),
             								  $outputlangs->transnoentities('Label'),
             								  $outputlangs->transnoentities('Qty')
             								  );
             
                 				// Header
                 				$num = count($header);
                					for($i = 0; $i < $num; $i++)
                					{
                						$pdf->Cell($w[$i],7,$header[$i],1,0,'C');
                					}
             
             			    	$pdf->Ln();
             
             			    	// Data
             					foreach($waitingDelivery as $value)
             					{
             						$pdf->Cell($w[0], 6, $value['ref'], 1, 0, 'L');
             						$pdf->Cell($w[1], 6, $value['label'], 1, 0, 'L');
             						$pdf->Cell($w[2], 6, $value['qty'], 1, 1, 'R');
             
             						if ($pdf->GetY() > 250)
             						{
             							$this->_pagefoot($pdf,$object,$outputlangs,1);
             
             							$pdf->AddPage('P', 'A4');
             
             							$pdf->SetFont('','', $default_font_size - 1);
             							$this->_pagehead($pdf, $object, 0, $outputlangs);
             
             							$pdf-> SetY(40);
             
             							$num = count($header);
             							for($i = 0; $i < $num; $i++)
             							{
             								$pdf->Cell($w[$i],7,$header[$i],1,0,'C');
             							}
             
             							$pdf->Ln();
             						}
             					}
             
             					$this->_pagefoot($pdf,$object,$outputlangs);
             
             					if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
             				}*/
             $pdf->Close();
             $pdf->Output($file, 'F');
             // Add pdfgeneration hook
             if (!is_object($hookmanager)) {
                 include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
                 $hookmanager = new HookManager($this->db);
             }
             $hookmanager->initHooks(array('pdfgeneration'));
             $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
             global $action;
             $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action);
             // Note that $action and $object may have been modified by some hooks
             if (!empty($conf->global->MAIN_UMASK)) {
                 @chmod($file, octdec($conf->global->MAIN_UMASK));
             }
             return 1;
             // pas d'erreur
         } else {
             $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
             return 0;
         }
     }
     $this->error = $langs->transnoentities("ErrorConstantNotDefined", "LIVRAISON_OUTPUTDIR");
     return 0;
 }
コード例 #8
0
 /**
  *  Function to build pdf onto disk
  *
  *  @param		int		$object				Id of object to generate
  *  @param		object	$outputlangs		Lang output object
  *  @param		string	$srctemplatepath	Full path of source filename for generator using a template file
  *  @param		int		$hidedetails		Do not show line details
  *  @param		int		$hidedesc			Do not show desc
  *  @param		int		$hideref			Do not show ref
  *  @param		object	$hookmanager		Hookmanager object
  *  @return     int             			1=OK, 0=KO
  */
 function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0, $hookmanager = false)
 {
     global $user, $conf, $langs, $mysoc;
     $default_font_size = pdf_getPDFFontSize($outputlangs);
     if (!is_object($outputlangs)) {
         $outputlangs = $langs;
     }
     // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
     if (!empty($conf->global->MAIN_USE_FPDF)) {
         $outputlangs->charset_output = 'ISO-8859-1';
     }
     $outputlangs->load("main");
     $outputlangs->load("dict");
     $outputlangs->load("companies");
     $outputlangs->load("bills");
     $outputlangs->load("products");
     $outputlangs->load("orders");
     if ($conf->commande->dir_output) {
         // Definition of $dir and $file
         if ($object->specimen) {
             $dir = $conf->commande->dir_output;
             $file = $dir . "/SPECIMEN.pdf";
         } else {
             $objectref = dol_sanitizeFileName($object->ref);
             $dir = $conf->commande->dir_output . "/" . $objectref;
             $file = $dir . "/" . $objectref . ".pdf";
         }
         if (!file_exists($dir)) {
             if (dol_mkdir($dir) < 0) {
                 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
                 return 0;
             }
         }
         if (file_exists($dir)) {
             $nblignes = count($object->lines);
             $pdf = pdf_getInstance($this->format);
             if (class_exists('TCPDF')) {
                 $pdf->setPrintHeader(false);
                 $pdf->setPrintFooter(false);
             }
             $pdf->SetFont(pdf_getPDFFont($outputlangs));
             // Set path to the background PDF File
             if (empty($conf->global->MAIN_DISABLE_FPDI) && !empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
                 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output . '/' . $conf->global->MAIN_ADD_PDF_BACKGROUND);
                 $tplidx = $pdf->importPage(1);
             }
             $pdf->Open();
             $pagenb = 0;
             $pdf->SetDrawColor(128, 128, 128);
             $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
             $pdf->SetSubject($outputlangs->transnoentities("Order"));
             $pdf->SetCreator("Dolibarr " . DOL_VERSION);
             $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
             $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref) . " " . $outputlangs->transnoentities("Order"));
             if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) {
                 $pdf->SetCompression(false);
             }
             $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
             // Left, Top, Right
             $pdf->SetAutoPageBreak(1, 0);
             // New page
             $pdf->AddPage();
             if (!empty($tplidx)) {
                 $pdf->useTemplate($tplidx);
             }
             $pagenb++;
             $this->_pagehead($pdf, $object, 1, $outputlangs, $hookmanager);
             $pdf->SetFont('', '', $default_font_size - 1);
             $pdf->MultiCell(0, 3, '');
             // Set interline to 3
             $pdf->SetTextColor(0, 0, 0);
             $tab_top = 100;
             $tab_height = 140;
             $pdf->SetFillColor(220, 220, 220);
             $pdf->SetTextColor(0, 0, 0);
             $pdf->SetFont('', '', $default_font_size - 1);
             $pdf->SetXY(10, $tab_top + 10);
             $iniY = $pdf->GetY();
             $curY = $pdf->GetY();
             $nexY = $pdf->GetY();
             $nblignes = count($object->lines);
             for ($i = 0; $i < $nblignes; $i++) {
                 $curY = $nexY;
                 $pdf->SetFont('', '', $default_font_size - 1);
                 // Dans boucle pour gerer multi-page
                 // Description of product line
                 pdf_writelinedesc($pdf, $object, $i, $outputlangs, 100, 3, 30, $curY, 1, $hidedesc, 0, $hookmanager);
                 $pdf->SetFont('', '', $default_font_size - 1);
                 // On repositionne la police par defaut
                 $nexY = $pdf->GetY();
                 $ref = pdf_getlineref($object, $i, $outputlangs, $hidedetails, $hookmanager);
                 $pdf->SetXY(10, $curY);
                 $pdf->MultiCell(20, 3, $ref, 0, 'C');
                 $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails, $hookmanager);
                 $pdf->SetXY(133, $curY);
                 $pdf->MultiCell(12, 3, $vat_rate, 0, 'C');
                 $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails, $hookmanager);
                 $pdf->SetXY(145, $curY);
                 $pdf->MultiCell(10, 3, $qty, 0, 'C');
                 $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails, $hookmanager);
                 $pdf->SetXY(156, $curY);
                 $pdf->MultiCell(18, 3, $up_excl_tax, 0, 'R', 0);
                 $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails, $hookmanager);
                 $pdf->SetXY(174, $curY);
                 $pdf->MultiCell(26, 3, $total_excl_tax, 0, 'R', 0);
                 $nexY += 2;
                 // Passe espace entre les lignes
                 // cherche nombre de lignes a venir pour savoir si place suffisante
                 if ($i < $nblignes - 1 && empty($hidedesc)) {
                     //on recupere la description du produit suivant
                     $follow_descproduitservice = $object->lines[$i + 1]->desc;
                     //on compte le nombre de ligne afin de verifier la place disponible (largeur de ligne 52 caracteres)
                     $nblineFollowDesc = dol_nboflines_bis($follow_descproduitservice, 52, $outputlangs->charset_output) * 4;
                 } else {
                     $nblineFollowDesc = 0;
                 }
                 if ($nexY + $nblineFollowDesc > $tab_top + $tab_height && $i < $nblignes - 1 || isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
                     $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs);
                     // New page
                     $pdf->AddPage();
                     if (!empty($tplidx)) {
                         $pdf->useTemplate($tplidx);
                     }
                     $pagenb++;
                     $this->_pagehead($pdf, $object, 0, $outputlangs, $hookmanager);
                     $pdf->SetFont('', '', $default_font_size - 1);
                     $pdf->MultiCell(0, 3, '');
                     // Set interline to 3
                     $pdf->SetTextColor(0, 0, 0);
                     $nexY = $tab_top + 8;
                 }
             }
             $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs);
             $bottomlasttab = $tab_top + $tab_height + 1;
             // Affiche zone infos
             $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
             // Affiche zone totaux
             $tab2_top = 241;
             $tab2_lh = 4;
             $pdf->SetFont('', '', $default_font_size);
             $pdf->SetXY(132, $tab2_top + 0);
             $pdf->MultiCell(42, $tab2_lh, $langs->transnoentities("TotalHT"), 0, 'R', 0);
             $pdf->SetXY(132, $tab2_top + $tab2_lh);
             $pdf->MultiCell(42, $tab2_lh, $langs->transnoentities("TotalVAT"), 0, 'R', 0);
             $pdf->SetXY(132, $tab2_top + $tab2_lh * 2);
             $pdf->MultiCell(42, $tab2_lh, $langs->transnoentities("TotalTTC"), 1, 'R', 1);
             $pdf->SetXY(174, $tab2_top + 0);
             $pdf->MultiCell(26, $tab2_lh, price($object->total_ht), 0, 'R', 0);
             $pdf->SetXY(174, $tab2_top + $tab2_lh);
             $pdf->MultiCell(26, $tab2_lh, price($object->total_tva), 0, 'R', 0);
             $pdf->SetXY(174, $tab2_top + $tab2_lh * 2);
             $pdf->MultiCell(26, $tab2_lh, price($object->total_ttc), 1, 'R', 1);
             // Pied de page
             $this->_pagefoot($pdf, $object, $outputlangs);
             $pdf->AliasNbPages();
             $pdf->Close();
             $pdf->Output($file, 'F');
             // Actions on extra fields (by external module or standard code)
             if (!is_object($hookmanager)) {
                 include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
                 $hookmanager = new HookManager($this->db);
             }
             $hookmanager->initHooks(array('pdfgeneration'));
             $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
             global $action;
             $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action);
             // Note that $action and $object may have been modified by some hooks
             if (!empty($conf->global->MAIN_UMASK)) {
                 @chmod($file, octdec($conf->global->MAIN_UMASK));
             }
             return 1;
         }
     } else {
         $this->error = $langs->transnoentities("ErrorConstantNotDefined", "COMMANDE_OUTPUTDIR");
         return 0;
     }
     $this->error = $langs->transnoentities("ErrorUnknown");
     return 0;
     // Erreur par defaut
 }
コード例 #9
0
	/**
	 *		\brief      Fonction generant le document sur le disque
	 *		\param	    object			Objet expedition a generer (ou id si ancienne methode)
	 *		\param		outputlangs		Lang output object
	 * 	 	\return	    int     		1=ok, 0=ko
	 */
	function write_file(&$object, $outputlangs)
	{
		global $user,$conf,$langs,$mysoc;
		$default_font_size = pdf_getPDFFontSize($outputlangs);

		$object->fetch_thirdparty();

		if (! is_object($outputlangs)) $outputlangs=$langs;
		// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
		if (!class_exists('TCPDF')) $outputlangs->charset_output='ISO-8859-1';

		$outputlangs->load("main");
		$outputlangs->load("dict");
		$outputlangs->load("companies");
		$outputlangs->load("bills");
		$outputlangs->load("products");
		$outputlangs->load("propal");
		$outputlangs->load("sendings");
		$outputlangs->load("deliveries");

		//Generation de la fiche
		$this->expe = $object;

		//Verification de la configuration
		if ($conf->expedition->dir_output)
		{
			$object->fetch_thirdparty();

			$origin = $object->origin;

			//Creation de l expediteur
			$this->expediteur = $mysoc;

			//Creation du destinataire
			$idcontact = $object->$origin->getIdContact('external','SHIPPING');
            $this->destinataire = new Contact($this->db);
			if ($idcontact[0]) $this->destinataire->fetch($idcontact[0]);

			//Creation du livreur
			$idcontact = $object->$origin->getIdContact('internal','LIVREUR');
			$this->livreur = new User($this->db);
			if ($idcontact[0]) $this->livreur->fetch($idcontact[0]);


			// Definition de $dir et $file
			if ($object->specimen)
			{
				$dir = $conf->expedition->dir_output."/sending";
				$file = $dir . "/SPECIMEN.pdf";
			}
			else
			{
				$expref = dol_sanitizeFileName($object->ref);
				$dir = $conf->expedition->dir_output . "/sending/" . $expref;
				$file = $dir . "/" . $expref . ".pdf";
			}

			if (! file_exists($dir))
			{
				if (create_exdir($dir) < 0)
				{
					$this->error=$outputlangs->transnoentities("ErrorCanNotCreateDir",$dir);
					return 0;
				}
			}

			//Si le dossier existe
			if (file_exists($dir))
			{
                $pdf=pdf_getInstance($this->format,'mm','l');

			    if (class_exists('TCPDF'))
                {
                    $pdf->setPrintHeader(false);
                    $pdf->setPrintFooter(false);
                }
                $pdf->SetFont(pdf_getPDFFont($outputlangs));

				$pdf->Open();
				$pagenb=0;
				$pdf->SetDrawColor(128,128,128);

				//Generation de l entete du fichier
				$pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
				$pdf->SetSubject($outputlangs->transnoentities("Sending"));
				$pdf->SetCreator("Dolibarr ".DOL_VERSION);
				$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
				$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Sending"));
				if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) $pdf->SetCompression(false);

				$pdf->SetMargins(10, 10, 10);
				$pdf->SetAutoPageBreak(1,0);

				$pdf->SetFont('','', $default_font_size - 3);

				// New page
				$pdf->AddPage();
				$pagenb++;
				$this->_pagehead($pdf, $this->expe, $outputlangs);
				$pdf->SetFont('','', $default_font_size - 3);
				$pdf->MultiCell(0, 3, '');		// Set interline to 3
				$pdf->SetTextColor(0,0,0);

				//Initialisation des coordonnees
				$tab_top = 53;
				$tab_height = 70;
				$pdf->SetFillColor(240,240,240);
				$pdf->SetTextColor(0,0,0);
				$pdf->SetFont('','',  $default_font_size - 3);
				$pdf->SetXY (10, $tab_top + 5 );
				$iniY = $pdf->GetY();
				$curY = $pdf->GetY();
				$nexY = $pdf->GetY();
				//Generation du tableau
				$this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs);

				$nblignes = sizeof($object->lines);

				for ($i = 0 ; $i < $nblignes ; $i++)
				{
					// Description de la ligne produit

					//Creation des cases a cocher
					$pdf->rect(10+3, $curY+1, 3, 3);
					$pdf->rect(20+3, $curY+1, 3, 3);
					//Insertion de la reference du produit
					$pdf->SetXY (30, $curY+1 );
					$pdf->SetFont('','B', $default_font_size - 3);
					$pdf->MultiCell(24, 3, $outputlangs->convToOutputCharset($object->lines[$i]->ref), 0, 'L', 0);
					//Insertion du libelle
					$pdf->SetFont('','', $default_font_size - 3);
					$pdf->SetXY (50, $curY+1 );
                    //$libelleproduitservice=pdf_getlinedesc($object->$origin,$i,$outputlangs);
					$libelleproduitservice = pdf_writelinedesc($pdf,$object->$origin,$i,$outputlangs,90,3,50,$curY+1,1);
					//$pdf->writeHTMLCell(90, 3, 50, $curY+1, $outputlangs->convToOutputCharset($libelleproduitservice), 0, 'L', 0);
					//Insertion de la quantite commandee
					$pdf->SetFont('','', $default_font_size - 3);
					$pdf->SetXY (140, $curY+1 );
					$pdf->MultiCell(30, 3, $object->lines[$i]->qty_asked, 0, 'C', 0);
					//Insertion de la quantite a envoyer
					$pdf->SetFont('','', $default_font_size - 3);
					$pdf->SetXY (170, $curY+1 );
					$pdf->MultiCell(30, 3, $object->lines[$i]->qty_shipped, 0, 'C', 0);

					//Generation de la page 2
					$curY += (dol_nboflines_bis($libelleproduitservice,0,$outputlangs->charset_output)*3+1);
					$nexY = $curY;
					if ($nexY > ($tab_top+$tab_height-10) && $i < $nblignes - 1)
					{
						$this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs);
						$this->_pagefoot($pdf, $object, $outputlangs);
						$pdf->AliasNbPages();

						$curY = $iniY;

						// New page
						$pdf->AddPage();
						$pagenb++;
						$this->_pagehead($pdf, $this->expe, $outputlangs);
						$pdf->MultiCell(0, 3, '');		// Set interline to 3
						$pdf->SetTextColor(0,0,0);
						$pdf->SetFont('','', $default_font_size - 3);
					}
				}
				//Insertion du pied de page
				$this->_pagefoot($pdf, $object, $outputlangs);

				$pdf->AliasNbPages();

				$pdf->Close();

				$pdf->Output($file,'F');
                if (! empty($conf->global->MAIN_UMASK))
                    @chmod($file, octdec($conf->global->MAIN_UMASK));

				return 1;
			}
			else
			{
				$this->error=$outputlangs->transnoentities("ErrorCanNotCreateDir",$dir);
				return 0;
			}
		}
		else
		{
			$this->error=$outputlangs->transnoentities("ErrorConstantNotDefined","EXP_OUTPUTDIR");
			return 0;
		}
		$this->error=$outputlangs->transnoentities("ErrorUnknown");
		return 0;   // Erreur par defaut

	}
コード例 #10
0
	/**
     *  Function to build pdf onto disk
     *  @param      object          Id of object to generate
     *  @param      outputlangs     Lang output object
     *  @param      srctemplatepath Full path of source filename for generator using a template file
     *  @param      hidedetails     Do not show line details
     *  @param      hidedesc        Do not show desc
     *  @param      hideref         Do not show ref
     *  @return     int             1=OK, 0=KO
	 */
	function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0)
	{
		global $user,$langs,$conf;
		$default_font_size = pdf_getPDFFontSize($outputlangs);

		if (! is_object($outputlangs)) $outputlangs=$langs;
		// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
		$sav_charset_output=$outputlangs->charset_output;
		if (!class_exists('TCPDF')) $outputlangs->charset_output='ISO-8859-1';

		$outputlangs->load("main");
		$outputlangs->load("dict");
		$outputlangs->load("companies");
		$outputlangs->load("bills");
		$outputlangs->load("propal");
		$outputlangs->load("products");

		if ($conf->propale->dir_output)
		{
			$object->fetch_thirdparty();

			$deja_regle = "";

			// Definition de $dir et $file
			if ($object->specimen)
			{
				$dir = $conf->propale->dir_output;
				$file = $dir . "/SPECIMEN.pdf";
			}
			else
			{
				$objectref = dol_sanitizeFileName($object->ref);
				$dir = $conf->propale->dir_output . "/" . $objectref;
				$file = $dir . "/" . $objectref . ".pdf";
			}

			if (! file_exists($dir))
			{
				if (create_exdir($dir) < 0)
				{
					$this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
					return 0;
				}
			}

			if (file_exists($dir))
			{
				$nblignes = sizeof($object->lines);

				// Create pdf instance
                $pdf=pdf_getInstance($this->format);

                if (class_exists('TCPDF'))
                {
                    $pdf->setPrintHeader(false);
                    $pdf->setPrintFooter(false);
                }
                $pdf->SetFont(pdf_getPDFFont($outputlangs));

				$pdf->Open();
				$pagenb=0;
				$pdf->SetDrawColor(128,128,128);

				$pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
				$pdf->SetSubject($outputlangs->transnoentities("CommercialProposal"));
				$pdf->SetCreator("Dolibarr ".DOL_VERSION);
				$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
				$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("CommercialProposal"));
				if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) $pdf->SetCompression(false);

				$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
				$pdf->SetAutoPageBreak(1,0);

				// Positionne $this->atleastonediscount si on a au moins une remise
				for ($i = 0 ; $i < $nblignes ; $i++)
				{
					if ($object->lines[$i]->remise_percent)
					{
						$this->atleastonediscount++;
					}
				}

				// New page
				$pdf->AddPage();
				$pagenb++;
				$this->_pagehead($pdf, $object, 1, $outputlangs);
				$pdf->SetFont('','', $default_font_size - 1);
				$pdf->MultiCell(0, 4, '');		// Set interline to 4
				$pdf->SetTextColor(0,0,0);

				$tab_top = 90;
				$tab_top_middlepage = 50;
				$tab_top_newpage = 50;
				$tab_height = 130;
				$tab_height_middlepage = 200;
				$tab_height_endpage = 170;

				// Affiche notes
				if (! empty($object->note_public))
				{
					$tab_top = 88;

					$pdf->SetFont('','', $default_font_size - 1);   // Dans boucle pour gerer multi-page
					$pdf->SetXY ($this->posxdesc-1, $tab_top);
					$pdf->MultiCell(190, 4, $outputlangs->convToOutputCharset($object->note_public), 0, 'L');
					$nexY = $pdf->GetY();
					$height_note=$nexY-$tab_top;

					// Rect prend une longueur en 3eme param
					$pdf->SetDrawColor(192,192,192);
					$pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);

					$tab_height = $tab_height - $height_note;
					$tab_top = $nexY+6;
				}
				else
				{
					$height_note=0;
				}

				$iniY = $tab_top + 7;
				$curY = $tab_top + 7;
				$nexY = $tab_top + 7;

				// Loop on each lines
				for ($i = 0 ; $i < $nblignes ; $i++)
				{
					$curY = $nexY;

					$pdf->SetFont('','', $default_font_size - 1);   // Dans boucle pour gerer multi-page

					// Description de la ligne produit
					$curX = $this->posxdesc-1;
					pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,4,$curX,$curY,$hideref,$hidedesc);

					$pdf->SetFont('','', $default_font_size - 1);   // On repositionne la police par defaut
					$nexY = $pdf->GetY();

					// TVA
					if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
					{
						$vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
						$pdf->SetXY ($this->posxtva, $curY);
						$pdf->MultiCell($this->posxup-$this->posxtva-1, 4, $vat_rate, 0, 'R');
					}

					// Prix unitaire HT avant remise
					$up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
					$pdf->SetXY ($this->posxup, $curY);
					$pdf->MultiCell($this->posxqty-$this->posxup-1, 4, $up_excl_tax, 0, 'R', 0);

					// Quantity
					$qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
					$pdf->SetXY ($this->posxqty, $curY);
					$pdf->MultiCell($this->posxdiscount-$this->posxqty-1, 4, $qty, 0, 'R');

					// Remise sur ligne
					$pdf->SetXY ($this->posxdiscount, $curY);
					if ($object->lines[$i]->remise_percent)
					{
						$remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
						$pdf->MultiCell($this->postotalht-$this->posxdiscount-1, 4, $remise_percent, 0, 'R');
					}

					// Total HT ligne
					$total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
					$pdf->SetXY ($this->postotalht, $curY);
					$pdf->MultiCell(26, 4, $total_excl_tax, 0, 'R', 0);

					// Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
					$tvaligne=$object->lines[$i]->total_tva;
					$localtax1ligne=$object->lines[$i]->total_localtax1;
					$localtax2ligne=$object->lines[$i]->total_localtax2;

					if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
					if ($object->remise_percent) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
					if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;

					$vatrate=(string) $object->lines[$i]->tva_tx;
					$localtax1rate=(string) $object->lines[$i]->localtax1_tx;
					$localtax2rate=(string) $object->lines[$i]->localtax2_tx;

					if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';

					$this->tva[$vatrate] += $tvaligne;
					$this->localtax1[$localtax1rate]+=$localtax1ligne;
					$this->localtax2[$localtax2rate]+=$localtax2ligne;

					$nexY+=2;    // Passe espace entre les lignes

					// Cherche nombre de lignes a venir pour savoir si place suffisante
					if ($i < ($nblignes - 1) && empty($hidedesc))	// If it's not last line
					{
						//on recupere la description du produit suivant
						$follow_descproduitservice = $object->lines[$i+1]->desc;
						//on compte le nombre de ligne afin de verifier la place disponible (largeur de ligne 52 caracteres)
						$nblineFollowDesc = (dol_nboflines_bis($follow_descproduitservice,52,$outputlangs->charset_output)*4);
					}
					else	// If it's last line
					{
						$nblineFollowDesc = 0;
					}

					// Test if a new page is required
					if ($pagenb == 1)
					{
						$tab_top_in_current_page=$tab_top;
						$tab_height_in_current_page=$tab_height;
					}
					else
					{
						$tab_top_in_current_page=$tab_top_newpage;
						$tab_height_in_current_page=$tab_height_middlepage;
					}
					if (($nexY+$nblineFollowDesc) > ($tab_top_in_current_page+$tab_height_in_current_page) && $i < ($nblignes - 1))
					{
						if ($pagenb == 1)
						{
							$this->_tableau($pdf, $tab_top, $tab_height + 20, $nexY, $outputlangs);
						}
						else
						{
							$this->_tableau($pdf, $tab_top_newpage, $tab_height_middlepage, $nexY, $outputlangs);
						}

						$this->_pagefoot($pdf,$object,$outputlangs);

						// New page
						$pdf->AddPage();
						$pagenb++;
						$this->_pagehead($pdf, $object, 0, $outputlangs);
						$pdf->SetFont('','', $default_font_size - 1);
						$pdf->MultiCell(0, 3, '');		// Set interline to 3
						$pdf->SetTextColor(0,0,0);

						$nexY = $tab_top_newpage + 7;
					}

				}

				// Show square
				if ($pagenb == 1)
				{
					$this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs);
					$bottomlasttab=$tab_top + $tab_height + 1;
				}
				else
				{
					$this->_tableau($pdf, $tab_top_newpage, $tab_height_endpage, $nexY, $outputlangs);
					$bottomlasttab=$tab_top_newpage + $tab_height_endpage + 1;
				}

				// Affiche zone infos
				$posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);

				// Affiche zone totaux
				$posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);

				// Affiche zone versements
				if ($deja_regle)
				{
					$posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs);
				}

				// Pied de page
				$this->_pagefoot($pdf,$object,$outputlangs);
				$pdf->AliasNbPages();

				$pdf->Close();

				$pdf->Output($file,'F');
				if (! empty($conf->global->MAIN_UMASK))
				@chmod($file, octdec($conf->global->MAIN_UMASK));

				// Add external file
				//$pdfConcat = new concat_pdf();
				//$pdfConcat->setFiles(array($file, DOL_DOCUMENT_ROOT."/includes/modules/propale/morefile.pdf"));
				//$pdfConcat->concat();
				//$pdf->AliasNbPages();
				//$pdfConcat->Output($file,'F');

				$outputlangs->charset_output=$sav_charset_output;
				return 1;   // Pas d'erreur
			}
			else
			{
				$this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
				return 0;
			}
		}
		else
		{
			$this->error=$langs->trans("ErrorConstantNotDefined","PROP_OUTPUTDIR");
			return 0;
		}

		$this->error=$langs->trans("ErrorUnknown");
		return 0;   // Erreur par defaut
	}
コード例 #11
0
 /**
  *	Function to build pdf onto disk
  *
  *	@param		Object		$object			Object expedition to generate (or id if old method)
  *	@param		Translate	$outputlangs		Lang output object
  *  @param		string		$srctemplatepath	Full path of source filename for generator using a template file
  *  @param		int			$hidedetails		Do not show line details
  *  @param		int			$hidedesc			Do not show desc
  *  @param		int			$hideref			Do not show ref
  *  @return     int         	    			1=OK, 0=KO
  */
 function write_file(&$object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
 {
     global $user, $conf, $langs, $hookmanager;
     $object->fetch_thirdparty();
     if (!is_object($outputlangs)) {
         $outputlangs = $langs;
     }
     // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
     if (!empty($conf->global->MAIN_USE_FPDF)) {
         $outputlangs->charset_output = 'ISO-8859-1';
     }
     $outputlangs->load("main");
     $outputlangs->load("dict");
     $outputlangs->load("companies");
     $outputlangs->load("bills");
     $outputlangs->load("products");
     $outputlangs->load("propal");
     $outputlangs->load("deliveries");
     $outputlangs->load("sendings");
     $nblignes = count($object->lines);
     // Loop on each lines to detect if there is at least one image to show
     $realpatharray = array();
     if (!empty($conf->global->MAIN_GENERATE_SHIPMENT_WITH_PICTURE)) {
         $objphoto = new Product($this->db);
         for ($i = 0; $i < $nblignes; $i++) {
             if (empty($object->lines[$i]->fk_product)) {
                 continue;
             }
             $objphoto->fetch($object->lines[$i]->fk_product);
             //var_dump($objphoto->ref);exit;
             if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) {
                 $pdir[0] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product') . $objphoto->id . "/photos/";
                 $pdir[1] = get_exdir(0, 0, 0, 0, $objphoto, 'product') . dol_sanitizeFileName($objphoto->ref) . '/';
             } else {
                 $pdir[0] = get_exdir(0, 0, 0, 0, $objphoto, 'product') . dol_sanitizeFileName($objphoto->ref) . '/';
                 // default
                 $pdir[1] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product') . $objphoto->id . "/photos/";
                 // alternative
             }
             $arephoto = false;
             foreach ($pdir as $midir) {
                 if (!$arephoto) {
                     $dir = $conf->product->dir_output . '/' . $midir;
                     foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
                         if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES)) {
                             if ($obj['photo_vignette']) {
                                 $filename = $obj['photo_vignette'];
                             } else {
                                 $filename = $obj['photo'];
                             }
                         } else {
                             $filename = $obj['photo'];
                         }
                         $realpath = $dir . $filename;
                         $arephoto = true;
                     }
                 }
             }
             if ($realpath && $arephoto) {
                 $realpatharray[$i] = $realpath;
             }
         }
     }
     if (count($realpatharray) == 0) {
         $this->posxpicture = $this->posxqtyordered;
     }
     if ($conf->expedition->dir_output) {
         // Definition de $dir et $file
         if ($object->specimen) {
             $dir = $conf->expedition->dir_output . "/sending";
             $file = $dir . "/SPECIMEN.pdf";
         } else {
             $expref = dol_sanitizeFileName($object->ref);
             $dir = $conf->expedition->dir_output . "/sending/" . $expref;
             $file = $dir . "/" . $expref . ".pdf";
         }
         if (!file_exists($dir)) {
             if (dol_mkdir($dir) < 0) {
                 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
                 return 0;
             }
         }
         if (file_exists($dir)) {
             // Add pdfgeneration hook
             if (!is_object($hookmanager)) {
                 include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
                 $hookmanager = new HookManager($this->db);
             }
             $hookmanager->initHooks(array('pdfgeneration'));
             $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
             global $action;
             $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action);
             // Note that $action and $object may have been modified by some hooks
             $pdf = pdf_getInstance($this->format);
             $default_font_size = pdf_getPDFFontSize($outputlangs);
             $heightforinfotot = 0;
             // Height reserved to output the info and total part
             $heightforfreetext = isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5;
             // Height reserved to output the free text on last page
             $heightforfooter = $this->marge_basse + 8;
             // Height reserved to output the footer (value include bottom margin)
             $pdf->SetAutoPageBreak(1, 0);
             if (class_exists('TCPDF')) {
                 $pdf->setPrintHeader(false);
                 $pdf->setPrintFooter(false);
             }
             $pdf->SetFont(pdf_getPDFFont($outputlangs));
             // Set path to the background PDF File
             if (empty($conf->global->MAIN_DISABLE_FPDI) && !empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
                 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output . '/' . $conf->global->MAIN_ADD_PDF_BACKGROUND);
                 $tplidx = $pdf->importPage(1);
             }
             $pdf->Open();
             $pagenb = 0;
             $pdf->SetDrawColor(128, 128, 128);
             if (method_exists($pdf, 'AliasNbPages')) {
                 $pdf->AliasNbPages();
             }
             $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
             $pdf->SetSubject($outputlangs->transnoentities("Shipment"));
             $pdf->SetCreator("Dolibarr " . DOL_VERSION);
             $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
             $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref) . " " . $outputlangs->transnoentities("Shipment"));
             if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
                 $pdf->SetCompression(false);
             }
             $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
             // Left, Top, Right
             // New page
             $pdf->AddPage();
             if (!empty($tplidx)) {
                 $pdf->useTemplate($tplidx);
             }
             $pagenb++;
             $this->_pagehead($pdf, $object, 1, $outputlangs);
             $pdf->SetFont('', '', $default_font_size - 1);
             $pdf->MultiCell(0, 3, '');
             // Set interline to 3
             $pdf->SetTextColor(0, 0, 0);
             $tab_top = 90;
             $tab_top_newpage = empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 : 10;
             $tab_height = 130;
             $tab_height_newpage = 150;
             // Incoterm
             $height_incoterms = 0;
             if ($conf->incoterm->enabled) {
                 $desc_incoterms = $object->getIncotermsForPDF();
                 if ($desc_incoterms) {
                     $tab_top = 88;
                     $pdf->SetFont('', '', $default_font_size - 1);
                     $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
                     $nexY = $pdf->GetY();
                     $height_incoterms = $nexY - $tab_top;
                     // Rect prend une longueur en 3eme param
                     $pdf->SetDrawColor(192, 192, 192);
                     $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
                     $tab_top = $nexY + 6;
                     $height_incoterms += 4;
                 }
             }
             if (!empty($object->note_public) || !empty($object->tracking_number)) {
                 $tab_top = 88 + $height_incoterms;
                 $tab_top_alt = $tab_top;
                 $pdf->SetFont('', 'B', $default_font_size - 2);
                 $pdf->writeHTMLCell(60, 4, $this->posxdesc - 1, $tab_top - 1, $outputlangs->transnoentities("TrackingNumber") . " : " . $object->tracking_number, 0, 1, false, true, 'L');
                 $tab_top_alt = $pdf->GetY();
                 //$tab_top_alt += 1;
                 // Tracking number
                 if (!empty($object->tracking_number)) {
                     $object->GetUrlTrackingStatus($object->tracking_number);
                     if (!empty($object->tracking_url)) {
                         if ($object->shipping_method_id > 0) {
                             // Get code using getLabelFromKey
                             $code = $outputlangs->getLabelFromKey($this->db, $object->shipping_method_id, 'c_shipment_mode', 'rowid', 'code');
                             $label = '';
                             if ($object->tracking_url != $object->tracking_number) {
                                 $label .= $outputlangs->trans("LinkToTrackYourPackage") . "<br>";
                             }
                             $label .= $outputlangs->trans("SendingMethod") . ": " . $outputlangs->trans("SendingMethod" . strtoupper($code));
                             //var_dump($object->tracking_url != $object->tracking_number);exit;
                             if ($object->tracking_url != $object->tracking_number) {
                                 $label .= " : ";
                                 $label .= $object->tracking_url;
                             }
                             $pdf->SetFont('', 'B', $default_font_size - 2);
                             $pdf->writeHTMLCell(60, 4, $this->posxdesc - 1, $tab_top_alt, $label, 0, 1, false, true, 'L');
                             $tab_top_alt = $pdf->GetY();
                         }
                     }
                 }
                 // Notes
                 if (!empty($object->note_public)) {
                     $pdf->SetFont('', '', $default_font_size - 1);
                     // Dans boucle pour gerer multi-page
                     $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top_alt, dol_htmlentitiesbr($object->note_public), 0, 1);
                 }
                 $nexY = $pdf->GetY();
                 $height_note = $nexY - $tab_top;
                 // Rect prend une longueur en 3eme param
                 $pdf->SetDrawColor(192, 192, 192);
                 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
                 $tab_height = $tab_height - $height_note;
                 $tab_top = $nexY + 6;
             } else {
                 $height_note = 0;
             }
             $iniY = $tab_top + 7;
             $curY = $tab_top + 7;
             $nexY = $tab_top + 7;
             // Loop on each lines
             for ($i = 0; $i < $nblignes; $i++) {
                 $curY = $nexY;
                 $pdf->SetFont('', '', $default_font_size - 1);
                 // Into loop to work with multipage
                 $pdf->SetTextColor(0, 0, 0);
                 // Define size of image if we need it
                 $imglinesize = array();
                 if (!empty($realpatharray[$i])) {
                     $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
                 }
                 $pdf->setTopMargin($tab_top_newpage);
                 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
                 // The only function to edit the bottom margin of current page to set it.
                 $pageposbefore = $pdf->getPage();
                 $showpricebeforepagebreak = 1;
                 $posYAfterImage = 0;
                 $posYAfterDescription = 0;
                 // We start with Photo of product line
                 if (isset($imglinesize['width']) && isset($imglinesize['height']) && $curY + $imglinesize['height'] > $this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot)) {
                     $pdf->AddPage('', '', true);
                     if (!empty($tplidx)) {
                         $pdf->useTemplate($tplidx);
                     }
                     if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
                         $this->_pagehead($pdf, $object, 0, $outputlangs);
                     }
                     $pdf->setPage($pageposbefore + 1);
                     $curY = $tab_top_newpage;
                     $showpricebeforepagebreak = 0;
                 }
                 if (isset($imglinesize['width']) && isset($imglinesize['height'])) {
                     $curX = $this->posxpicture - 1;
                     $pdf->Image($realpatharray[$i], $curX + ($this->posxqtyordered - $this->posxpicture - $imglinesize['width']) / 2, $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300);
                     // Use 300 dpi
                     // $pdf->Image does not increase value return by getY, so we save it manually
                     $posYAfterImage = $curY + $imglinesize['height'];
                 }
                 // Description of product line
                 $curX = $this->posxdesc - 1;
                 $pdf->startTransaction();
                 // Description de la ligne produit
                 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX, 3, $curX, $curY, $hideref, $hidedesc);
                 $pageposafter = $pdf->getPage();
                 if ($pageposafter > $pageposbefore) {
                     $pdf->rollbackTransaction(true);
                     $pageposafter = $pageposbefore;
                     //print $pageposafter.'-'.$pageposbefore;exit;
                     $pdf->setPageOrientation('', 1, $heightforfooter);
                     // The only function to edit the bottom margin of current page to set it.
                     pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX, 3, $curX, $curY, $hideref, $hidedesc);
                     $pageposafter = $pdf->getPage();
                     $posyafter = $pdf->GetY();
                     //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
                     if ($posyafter > $this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot)) {
                         if ($i == $nblignes - 1) {
                             $pdf->AddPage('', '', true);
                             if (!empty($tplidx)) {
                                 $pdf->useTemplate($tplidx);
                             }
                             if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
                                 $this->_pagehead($pdf, $object, 0, $outputlangs);
                             }
                             $pdf->setPage($pageposafter + 1);
                         }
                     } else {
                         // We found a page break
                         $showpricebeforepagebreak = 0;
                     }
                 } else {
                     $pdf->commitTransaction();
                 }
                 $posYAfterDescription = $pdf->GetY();
                 $nexY = $pdf->GetY();
                 $pageposafter = $pdf->getPage();
                 $pdf->setPage($pageposbefore);
                 $pdf->setTopMargin($this->marge_haute);
                 $pdf->setPageOrientation('', 1, 0);
                 // The only function to edit the bottom margin of current page to set it.
                 // We suppose that a too long description or photo were moved completely on next page
                 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
                     $pdf->setPage($pageposafter);
                     $curY = $tab_top_newpage;
                 }
                 // We suppose that a too long description is moved completely on next page
                 if ($pageposafter > $pageposbefore) {
                     $pdf->setPage($pageposafter);
                     $curY = $tab_top_newpage;
                 }
                 $pdf->SetFont('', '', $default_font_size - 1);
                 // On repositionne la police par defaut
                 $pdf->SetXY($this->posxqtyordered, $curY);
                 $pdf->MultiCell($this->posxqtytoship - $this->posxqtyordered, 3, $object->lines[$i]->qty_asked, '', 'C');
                 $pdf->SetXY($this->posxqtytoship, $curY);
                 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxqtytoship, 3, $object->lines[$i]->qty_shipped, '', 'C');
                 // Add line
                 if ($conf->global->MAIN_PDF_DASH_BETWEEN_LINES && $i < $nblignes - 1) {
                     $pdf->setPage($pageposafter);
                     $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
                     //$pdf->SetDrawColor(190,190,200);
                     $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
                     $pdf->SetLineStyle(array('dash' => 0));
                 }
                 $nexY += 2;
                 // Passe espace entre les lignes
                 // Detect if some page were added automatically and output _tableau for past pages
                 while ($pagenb < $pageposafter) {
                     $pdf->setPage($pagenb);
                     if ($pagenb == 1) {
                         $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
                     } else {
                         $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
                     }
                     $this->_pagefoot($pdf, $object, $outputlangs, 1);
                     $pagenb++;
                     $pdf->setPage($pagenb);
                     $pdf->setPageOrientation('', 1, 0);
                     // The only function to edit the bottom margin of current page to set it.
                 }
                 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
                     if ($pagenb == 1) {
                         $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
                     } else {
                         $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
                     }
                     $this->_pagefoot($pdf, $object, $outputlangs, 1);
                     // New page
                     $pdf->AddPage();
                     if (!empty($tplidx)) {
                         $pdf->useTemplate($tplidx);
                     }
                     $pagenb++;
                 }
             }
             // Show square
             if ($pagenb == 1) {
                 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext - $heightforinfotot, 0, $outputlangs, 0, 0);
                 $bottomlasttab = $this->page_hauteur - $heightforfooter - $heightforfreetext - $heightforinfotot + 1;
             } else {
                 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter - $heightforfreetext - $heightforinfotot, 0, $outputlangs, 1, 0);
                 $bottomlasttab = $this->page_hauteur - $heightforfooter - $heightforfreetext - $heightforinfotot + 1;
             }
             // Pied de page
             $this->_pagefoot($pdf, $object, $outputlangs);
             if (method_exists($pdf, 'AliasNbPages')) {
                 $pdf->AliasNbPages();
             }
             $pdf->Close();
             $pdf->Output($file, 'F');
             // Add pdfgeneration hook
             if (!is_object($hookmanager)) {
                 include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
                 $hookmanager = new HookManager($this->db);
             }
             $hookmanager->initHooks(array('pdfgeneration'));
             $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
             global $action;
             $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action);
             // Note that $action and $object may have been modified by some hooks
             if (!empty($conf->global->MAIN_UMASK)) {
                 @chmod($file, octdec($conf->global->MAIN_UMASK));
             }
             return 1;
         } else {
             $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
             return 0;
         }
     } else {
         $this->error = $langs->transnoentities("ErrorConstantNotDefined", "EXP_OUTPUTDIR");
         return 0;
     }
     $this->error = $langs->transnoentities("ErrorUnknown");
     return 0;
     // Erreur par defaut
 }
コード例 #12
0
	/**
     *  Function to build pdf onto disk
     *  @param      object          Id of object to generate
     *  @param      outputlangs     Lang output object
     *  @param      srctemplatepath Full path of source filename for generator using a template file
     *  @param      hidedetails     Do not show line details
     *  @param      hidedesc        Do not show desc
     *  @param      hideref         Do not show ref
     *  @return     int             1=OK, 0=KO
	 */
	function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0)
	{
		global $user,$langs,$conf;

		if (! is_object($outputlangs)) $outputlangs=$langs;
		// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
		if (!class_exists('TCPDF')) $outputlangs->charset_output='ISO-8859-1';

		$default_font_size = pdf_getPDFFontSize($outputlangs);

		$outputlangs->load("main");
		$outputlangs->load("dict");
		$outputlangs->load("companies");
		$outputlangs->load("bills");
		$outputlangs->load("products");

		if ($conf->facture->dir_output)
		{
			$object->fetch_thirdparty();

			$deja_regle = $object->getSommePaiement();
			$amount_credit_notes_included = $object->getSumCreditNotesUsed();
			$amount_deposits_included = $object->getSumDepositsUsed();

			// Definition of $dir and $file
			if ($object->specimen)
			{
				$dir = $conf->facture->dir_output;
				$file = $dir . "/SPECIMEN.pdf";
			}
			else
			{
				$objectref = dol_sanitizeFileName($object->ref);
				$dir = $conf->facture->dir_output . "/" . $objectref;
				$file = $dir . "/" . $objectref . ".pdf";
			}

			if (! file_exists($dir))
			{
				if (create_exdir($dir) < 0)
				{
					$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
					return 0;
				}
			}

			if (file_exists($dir))
			{
                $pdf=pdf_getInstance($this->format);

                if (class_exists('TCPDF'))
                {
                    $pdf->setPrintHeader(false);
                    $pdf->setPrintFooter(false);
                }
                $pdf->SetFont(pdf_getPDFFont($outputlangs));

				$pdf->Open();
				$pagenb=0;
				$pdf->SetDrawColor(128,128,128);

				$pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
				$pdf->SetSubject($outputlangs->transnoentities("Invoice"));
				$pdf->SetCreator("Dolibarr ".DOL_VERSION);
				$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
				$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Invoice"));
				if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) $pdf->SetCompression(false);

				$pdf->SetMargins(10, 10, 10);
				$pdf->SetAutoPageBreak(1,0);

				// New page
				$pdf->AddPage();
				$pagenb++;
				$this->_pagehead($pdf, $object, 1, $outputlangs);
				$pdf->SetFont('','', $default_font_size - 1);
				$pdf->MultiCell(0, 3, '');		// Set interline to 3
				$pdf->SetTextColor(0,0,0);

				$tab_top = $this->marges['h']+90;
				$tab_height = 110;

				$pdf->SetFillColor(220,220,220);
				$pdf->SetFont('','', $default_font_size - 1);
				$pdf->SetXY ($this->marges['g'], $tab_top + $this->marges['g'] );

				$iniY = $pdf->GetY();
				$curY = $pdf->GetY();
				$nexY = $pdf->GetY();
				$nblignes = sizeof($object->lines);

				// Loop on each lines
				for ($i = 0 ; $i < $nblignes ; $i++)
				{
					$curY = $nexY;

					// Description of product line
                    pdf_writelinedesc($pdf,$object,$i,$outputlangs,108,3,$this->posxdesc-1,$curY+1,$hideref,$hidedesc);

					$nexY = $pdf->GetY();

					// TVA
					if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
					{
						if ($this->franchise!=1)
						{
							$vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
							$pdf->SetXY ($this->marges['g']+118, $curY);
							$pdf->MultiCell(12, 3, $vat_rate, 0, 'R');
						}
					}

					// Prix unitaire HT avant remise
					$up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
					$pdf->SetXY ($this->marges['g']+132, $curY);
					$pdf->MultiCell(16, 3, $up_excl_tax, 0, 'R', 0);

					// Quantity
					$qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
					$pdf->SetXY ($this->marges['g']+150, $curY);
					$pdf->MultiCell(10, 3, $qty, 0, 'R');

					// Remise sur ligne
					$pdf->SetXY ($this->marges['g']+160, $curY);
					if ($object->lines[$i]->remise_percent) {
						$remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
						$pdf->MultiCell(14, 3, $remise_percent, 0, 'R');
					}

					// Total HT
					$total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
					$pdf->SetXY ($this->marges['g']+168, $curY);
					$pdf->MultiCell(21, 3, $total_excl_tax, 0, 'R', 0);


					if ($nexY > 200 && $i < $nblignes - 1)
					{
						$this->_tableau($pdf, $tab_top, $tab_height, $nexY, $object, $outputlangs);
						$nexY = $iniY;

						// New page
						$pdf->AddPage();
						$pagenb++;
						$this->_pagehead($pdf, $object, 0, $outputlangs);
						$pdf->SetFont('','', $default_font_size - 1);
						$pdf->MultiCell(0, 3, '');		// Set interline to 3
						$pdf->SetTextColor(0,0,0);
					}

				}
				$posy=$this->_tableau($pdf, $tab_top, $tab_height, $nexY, $object, $outputlangs);
				$bottomlasttab=$tab_top + $tab_height + 1;

				// Affiche zone infos
				$posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);

				// Affiche zone totaux
				$posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);

				// Affiche zone versements
				if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included)
				{
					$posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs);
				}

				// Pied de page
				$this->_pagefoot($pdf, $object, $outputlangs);
				$pdf->AliasNbPages();

				$pdf->Close();

				$pdf->Output($file,'F');
				if (! empty($conf->global->MAIN_UMASK))
				@chmod($file, octdec($conf->global->MAIN_UMASK));

				return 1;   // Pas d'erreur
			}
			else
			{
				$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
				return 0;
			}
		}
		else
		{
			$this->error=$langs->transnoentities("ErrorConstantNotDefined","FAC_OUTPUTDIR");
			return 0;
		}
		$this->error=$langs->transnoentities("ErrorUnknown");
		return 0;   // Erreur par defaut
	}
コード例 #13
0
 /**
  *	Fonction generant le bon de livraison sur le disque
  *
  *	@param	Object		$object   		Object livraison a generer
  *	@param	Translate	$outputlangs	Lang output object
  *	@return	int         				1 if OK, <=0 if KO
  */
 function write_file($object, $outputlangs)
 {
     global $user, $conf, $langs;
     $default_font_size = pdf_getPDFFontSize($outputlangs);
     if (!is_object($outputlangs)) {
         $outputlangs = $langs;
     }
     // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
     if (!empty($conf->global->MAIN_USE_FPDF)) {
         $outputlangs->charset_output = 'ISO-8859-1';
     }
     $outputlangs->load("main");
     $outputlangs->load("dict");
     $outputlangs->load("bills");
     $outputlangs->load("products");
     $outputlangs->load("deliveries");
     $outputlangs->load("sendings");
     if ($conf->expedition->dir_output . "/receipt") {
         $object->fetch_thirdparty();
         $nblines = count($object->lines);
         $objectref = dol_sanitizeFileName($object->ref);
         $dir = $conf->expedition->dir_output . "/receipt";
         if (!preg_match('/specimen/i', $objectref)) {
             $dir .= "/" . $objectref;
         }
         $file = $dir . "/" . $objectref . ".pdf";
         if (!file_exists($dir)) {
             if (dol_mkdir($dir) < 0) {
                 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
                 return 0;
             }
         }
         if (file_exists($dir)) {
             $pdf = pdf_getInstance($this->format);
             if (class_exists('TCPDF')) {
                 $pdf->setPrintHeader(false);
                 $pdf->setPrintFooter(false);
             }
             $pdf->SetFont(pdf_getPDFFont($outputlangs));
             // Set path to the background PDF File
             if (empty($conf->global->MAIN_DISABLE_FPDI) && !empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
                 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output . '/' . $conf->global->MAIN_ADD_PDF_BACKGROUND);
                 $tplidx = $pdf->importPage(1);
             }
             // Complete object by loading several other informations
             $expedition = new Expedition($this->db);
             $result = $expedition->fetch($object->expedition_id);
             $commande = new Commande($this->db);
             if ($expedition->origin == 'commande') {
                 $commande->fetch($expedition->origin_id);
             }
             $object->commande = $commande;
             $pdf->Open();
             $pagenb = 0;
             $pdf->SetDrawColor(128, 128, 128);
             $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
             $pdf->SetSubject($outputlangs->transnoentities("DeliveryOrder"));
             $pdf->SetCreator("Dolibarr " . DOL_VERSION);
             $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
             $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref) . " " . $outputlangs->transnoentities("DeliveryOrder"));
             if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) {
                 $pdf->SetCompression(false);
             }
             $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
             // Left, Top, Right
             $pdf->SetAutoPageBreak(1, 0);
             // New page
             $pdf->AddPage();
             if (!empty($tplidx)) {
                 $pdf->useTemplate($tplidx);
             }
             $pagenb++;
             $this->_pagehead($pdf, $object, 1, $outputlangs);
             $pdf->SetFont('', '', $default_font_size - 1);
             $pdf->MultiCell(0, 3, '');
             // Set interline to 3
             $pdf->SetTextColor(0, 0, 0);
             $tab_top = 100;
             $tab_top_newpage = 50;
             $tab_height = 140;
             $tab_height_newpage = 190;
             $iniY = $tab_top + 7;
             $curY = $tab_top + 7;
             $nexY = $tab_top + 7;
             for ($i = 0; $i < $nblines; $i++) {
                 $curY = $nexY;
                 $pdf->SetFont('', '', $default_font_size - 1);
                 // Dans boucle pour gerer multi-page
                 // Description de la ligne produit
                 //$libelleproduitservice=pdf_getlinedesc($object,$i,$outputlangs);
                 pdf_writelinedesc($pdf, $object, $i, $outputlangs, 100, 3, 30, $curY, 1);
                 //$pdf->writeHTMLCell(100, 3, 30, $curY, $outputlangs->convToOutputCharset($libelleproduitservice), 0, 1);
                 $pdf->SetFont('', '', $default_font_size - 1);
                 // Dans boucle pour gerer multi-page
                 $nexY = $pdf->GetY();
                 $pdf->SetXY(10, $curY);
                 $pdf->MultiCell(20, 3, $outputlangs->convToOutputCharset($object->lines[$i]->ref), 0, 'C');
                 // TODO Field not yet saved in database
                 //$pdf->SetXY(133, $curY );
                 //$pdf->MultiCell(10, 5, $object->lines[$i]->tva_tx, 0, 'C');
                 $pdf->SetXY(145, $curY);
                 $pdf->MultiCell(10, 3, $object->lines[$i]->qty_shipped, 0, 'C');
                 // TODO Field not yet saved in database
                 //$pdf->SetXY(156, $curY );
                 //$pdf->MultiCell(20, 3, price($object->lines[$i]->price), 0, 'R', 0);
                 // TODO Field not yet saved in database
                 //$pdf->SetXY(174, $curY );
                 //$total = price($object->lines[$i]->price * $object->lines[$i]->qty_shipped);
                 //$pdf->MultiCell(26, 3, $total, 0, 'R', 0);
                 $pdf->line(10, $curY - 1, 200, $curY - 1);
                 $nexY += 2;
                 // Passe espace entre les lignes
                 // Cherche nombre de lignes a venir pour savoir si place suffisante
                 if ($i < $nblines - 1 && empty($hidedesc)) {
                     //on recupere la description du produit suivant
                     $follow_descproduitservice = $object->lines[$i + 1]->desc;
                     //on compte le nombre de ligne afin de verifier la place disponible (largeur de ligne 52 caracteres)
                     $nblineFollowDesc = dol_nboflines_bis($follow_descproduitservice, 52, $outputlangs->charset_output) * 4;
                 } else {
                     $nblineFollowDesc = 0;
                 }
                 // Test if a new page is required
                 if ($pagenb == 1) {
                     $tab_top_in_current_page = $tab_top;
                     $tab_height_in_current_page = $tab_height;
                 } else {
                     $tab_top_in_current_page = $tab_top_newpage;
                     $tab_height_in_current_page = $tab_height_newpage;
                 }
                 if ($nexY + $nblineFollowDesc > $tab_top_in_current_page + $tab_height_in_current_page && $i < $nblines - 1) {
                     if ($pagenb == 1) {
                         $this->_tableau($pdf, $tab_top, $tab_height + 20, $nexY, $outputlangs);
                     } else {
                         $this->_tableau($pdf, $tab_top_newpage, $tab_height_newpage, $nexY, $outputlangs);
                     }
                     $this->_pagefoot($pdf, $object, $outputlangs);
                     // New page
                     $pdf->AddPage();
                     $pagenb++;
                     $this->_pagehead($pdf, $object, 0, $outputlangs);
                     $pdf->SetFont('', '', $default_font_size - 1);
                     $pdf->MultiCell(0, 3, '');
                     // Set interline to 3
                     $pdf->SetTextColor(0, 0, 0);
                     $nexY = $tab_top_newpage + 7;
                 }
             }
             // Show square
             if ($pagenb == 1) {
                 $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs);
                 $bottomlasttab = $tab_top + $tab_height + 1;
             } else {
                 $this->_tableau($pdf, $tab_top_newpage, $tab_height_newpage, $nexY, $outputlangs);
                 $bottomlasttab = $tab_top_newpage + $tab_height_newpage + 1;
             }
             /*
              * Pied de page
              */
             $this->_pagefoot($pdf, $object, $outputlangs);
             $pdf->AliasNbPages();
             $pdf->Close();
             $pdf->Output($file, 'F');
             if (!empty($conf->global->MAIN_UMASK)) {
                 @chmod($file, octdec($conf->global->MAIN_UMASK));
             }
             return 1;
         }
     } else {
         $this->error = $langs->transnoentities("ErrorConstantNotDefined", "LIVRAISON_OUTPUTDIR");
         return 0;
     }
 }
コード例 #14
0
 /**
  *  Function to build pdf onto disk
  *
  *  @param		Object		$object				Object to generate
  *  @param		Translate	$outputlangs		Lang output object
  *  @param		string		$srctemplatepath	Full path of source filename for generator using a template file
  *  @param		int			$hidedetails		Do not show line details
  *  @param		int			$hidedesc			Do not show desc
  *  @param		int			$hideref			Do not show ref
  *  @return     int         	    			1=OK, 0=KO
  */
 function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
 {
     global $user, $langs, $conf, $mysoc, $db, $hookmanager;
     if (!is_object($outputlangs)) {
         $outputlangs = $langs;
     }
     // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
     if (!empty($conf->global->MAIN_USE_FPDF)) {
         $outputlangs->charset_output = 'ISO-8859-1';
     }
     $outputlangs->load("main");
     $outputlangs->load("dict");
     $outputlangs->load("companies");
     $outputlangs->load("bills");
     $outputlangs->load("products");
     $nblignes = count($object->lines);
     // Loop on each lines to detect if there is at least one image to show
     $realpatharray = array();
     if (!empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE)) {
         for ($i = 0; $i < $nblignes; $i++) {
             if (empty($object->lines[$i]->fk_product)) {
                 continue;
             }
             $objphoto = new Product($this->db);
             $objphoto->fetch($object->lines[$i]->fk_product);
             $pdir = get_exdir($object->lines[$i]->fk_product, 2, 0, 0, $objphoto, 'product') . $object->lines[$i]->fk_product . "/photos/";
             $dir = $conf->product->dir_output . '/' . $pdir;
             $realpath = '';
             foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
                 $filename = $obj['photo'];
                 //if ($obj['photo_vignette']) $filename='thumbs/'.$obj['photo_vignette'];
                 $realpath = $dir . $filename;
                 break;
             }
             if ($realpath) {
                 $realpatharray[$i] = $realpath;
             }
         }
     }
     if (count($realpatharray) == 0) {
         $this->posxpicture = $this->posxtva;
     }
     if ($conf->facture->dir_output) {
         $object->fetch_thirdparty();
         $deja_regle = $object->getSommePaiement();
         $amount_credit_notes_included = $object->getSumCreditNotesUsed();
         $amount_deposits_included = $object->getSumDepositsUsed();
         // Definition of $dir and $file
         if ($object->specimen) {
             $dir = $conf->facture->dir_output;
             $file = $dir . "/SPECIMEN.pdf";
         } else {
             $objectref = dol_sanitizeFileName($object->ref);
             $dir = $conf->facture->dir_output . "/" . $objectref;
             $file = $dir . "/" . $objectref . ".pdf";
         }
         if (!file_exists($dir)) {
             if (dol_mkdir($dir) < 0) {
                 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
                 return 0;
             }
         }
         if (file_exists($dir)) {
             // Add pdfgeneration hook
             if (!is_object($hookmanager)) {
                 include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
                 $hookmanager = new HookManager($this->db);
             }
             $hookmanager->initHooks(array('pdfgeneration'));
             $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
             global $action;
             $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action);
             // Note that $action and $object may have been modified by some hooks
             // Set nblignes with the new facture lines content after hook
             $nblignes = count($object->lines);
             // Create pdf instance
             $pdf = pdf_getInstance($this->format);
             $default_font_size = pdf_getPDFFontSize($outputlangs);
             // Must be after pdf_getInstance
             $heightforinfotot = 50;
             // Height reserved to output the info and total part
             $heightforfreetext = isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5;
             // Height reserved to output the free text on last page
             $heightforfooter = $this->marge_basse + 8;
             // Height reserved to output the footer (value include bottom margin)
             $pdf->SetAutoPageBreak(1, 0);
             if (class_exists('TCPDF')) {
                 $pdf->setPrintHeader(false);
                 $pdf->setPrintFooter(false);
             }
             $pdf->SetFont(pdf_getPDFFont($outputlangs));
             // Set path to the background PDF File
             if (empty($conf->global->MAIN_DISABLE_FPDI) && !empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
                 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output . '/' . $conf->global->MAIN_ADD_PDF_BACKGROUND);
                 $tplidx = $pdf->importPage(1);
             }
             $pdf->Open();
             $pagenb = 0;
             $pdf->SetDrawColor(128, 128, 128);
             $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
             $pdf->SetSubject($outputlangs->transnoentities("Invoice"));
             $pdf->SetCreator("Dolibarr " . DOL_VERSION);
             $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
             $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref) . " " . $outputlangs->transnoentities("Invoice"));
             if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
                 $pdf->SetCompression(false);
             }
             $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
             // Left, Top, Right
             // Positionne $this->atleastonediscount si on a au moins une remise
             for ($i = 0; $i < $nblignes; $i++) {
                 if ($object->lines[$i]->remise_percent) {
                     $this->atleastonediscount++;
                 }
             }
             if (empty($this->atleastonediscount) && empty($conf->global->PRODUCT_USE_UNITS)) {
                 $this->posxpicture += $this->postotalht - $this->posxdiscount;
                 $this->posxtva += $this->postotalht - $this->posxdiscount;
                 $this->posxup += $this->postotalht - $this->posxdiscount;
                 $this->posxqty += $this->postotalht - $this->posxdiscount;
                 $this->posxdiscount += $this->postotalht - $this->posxdiscount;
                 //$this->postotalht;
             }
             // Situation invoice handling
             if ($object->situation_cycle_ref) {
                 $this->situationinvoice = True;
                 $progress_width = 14;
                 $this->posxtva -= $progress_width;
                 $this->posxup -= $progress_width;
                 $this->posxqty -= $progress_width;
                 $this->posxdiscount -= $progress_width;
                 $this->posxprogress -= $progress_width;
             }
             // New page
             $pdf->AddPage();
             if (!empty($tplidx)) {
                 $pdf->useTemplate($tplidx);
             }
             $pagenb++;
             $this->_pagehead($pdf, $object, 1, $outputlangs);
             $pdf->SetFont('', '', $default_font_size - 1);
             $pdf->MultiCell(0, 3, '');
             // Set interline to 3
             $pdf->SetTextColor(0, 0, 0);
             $tab_top = 90;
             $tab_top_newpage = empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 : 10;
             $tab_height = 130;
             $tab_height_newpage = 150;
             // Incoterm
             $height_incoterms = 0;
             if ($conf->incoterm->enabled) {
                 $desc_incoterms = $object->getIncotermsForPDF();
                 if ($desc_incoterms) {
                     $tab_top = 88;
                     $pdf->SetFont('', '', $default_font_size - 1);
                     $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
                     $nexY = $pdf->GetY();
                     $height_incoterms = $nexY - $tab_top;
                     // Rect prend une longueur en 3eme param
                     $pdf->SetDrawColor(192, 192, 192);
                     $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
                     $tab_top = $nexY + 6;
                     $height_incoterms += 4;
                 }
             }
             // Affiche notes
             $notetoshow = empty($object->note_public) ? '' : $object->note_public;
             if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) {
                 // Get first sale rep
                 if (is_object($object->thirdparty)) {
                     $salereparray = $object->thirdparty->getSalesRepresentatives($user);
                     $salerepobj = new User($this->db);
                     $salerepobj->fetch($salereparray[0]['id']);
                     if (!empty($salerepobj->signature)) {
                         $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
                     }
                 }
             }
             if ($notetoshow) {
                 $tab_top = 88 + $height_incoterms;
                 $pdf->SetFont('', '', $default_font_size - 1);
                 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
                 $nexY = $pdf->GetY();
                 $height_note = $nexY - $tab_top;
                 // Rect prend une longueur en 3eme param
                 $pdf->SetDrawColor(192, 192, 192);
                 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
                 $tab_height = $tab_height - $height_note;
                 $tab_top = $nexY + 6;
             } else {
                 $height_note = 0;
             }
             $iniY = $tab_top + 7;
             $curY = $tab_top + 7;
             $nexY = $tab_top + 7;
             // Loop on each lines
             for ($i = 0; $i < $nblignes; $i++) {
                 $curY = $nexY;
                 $pdf->SetFont('', '', $default_font_size - 1);
                 // Into loop to work with multipage
                 $pdf->SetTextColor(0, 0, 0);
                 // Define size of image if we need it
                 $imglinesize = array();
                 if (!empty($realpatharray[$i])) {
                     $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
                 }
                 $pdf->setTopMargin($tab_top_newpage);
                 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
                 // The only function to edit the bottom margin of current page to set it.
                 $pageposbefore = $pdf->getPage();
                 $showpricebeforepagebreak = 1;
                 $posYAfterImage = 0;
                 $posYAfterDescription = 0;
                 // We start with Photo of product line
                 if (isset($imglinesize['width']) && isset($imglinesize['height']) && $curY + $imglinesize['height'] > $this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot)) {
                     $pdf->AddPage('', '', true);
                     if (!empty($tplidx)) {
                         $pdf->useTemplate($tplidx);
                     }
                     if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
                         $this->_pagehead($pdf, $object, 0, $outputlangs);
                     }
                     $pdf->setPage($pageposbefore + 1);
                     $curY = $tab_top_newpage;
                     $showpricebeforepagebreak = 0;
                 }
                 if (isset($imglinesize['width']) && isset($imglinesize['height'])) {
                     $curX = $this->posxpicture - 1;
                     $pdf->Image($realpatharray[$i], $curX + ($this->posxtva - $this->posxpicture - $imglinesize['width']) / 2, $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300);
                     // Use 300 dpi
                     // $pdf->Image does not increase value return by getY, so we save it manually
                     $posYAfterImage = $curY + $imglinesize['height'];
                 }
                 // Description of product line
                 $curX = $this->posxdesc - 1;
                 $pdf->startTransaction();
                 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX, 3, $curX, $curY, $hideref, $hidedesc);
                 $pageposafter = $pdf->getPage();
                 if ($pageposafter > $pageposbefore) {
                     $pdf->rollbackTransaction(true);
                     $pageposafter = $pageposbefore;
                     //print $pageposafter.'-'.$pageposbefore;exit;
                     $pdf->setPageOrientation('', 1, $heightforfooter);
                     // The only function to edit the bottom margin of current page to set it.
                     pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX, 3, $curX, $curY, $hideref, $hidedesc);
                     $pageposafter = $pdf->getPage();
                     $posyafter = $pdf->GetY();
                     //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
                     if ($posyafter > $this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot)) {
                         if ($i == $nblignes - 1) {
                             $pdf->AddPage('', '', true);
                             if (!empty($tplidx)) {
                                 $pdf->useTemplate($tplidx);
                             }
                             if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
                                 $this->_pagehead($pdf, $object, 0, $outputlangs);
                             }
                             $pdf->setPage($pageposafter + 1);
                         }
                     } else {
                         // We found a page break
                         $showpricebeforepagebreak = 0;
                     }
                 } else {
                     $pdf->commitTransaction();
                 }
                 $posYAfterDescription = $pdf->GetY();
                 $nexY = $pdf->GetY();
                 $pageposafter = $pdf->getPage();
                 $pdf->setPage($pageposbefore);
                 $pdf->setTopMargin($this->marge_haute);
                 $pdf->setPageOrientation('', 1, 0);
                 // The only function to edit the bottom margin of current page to set it.
                 // We suppose that a too long description or photo were moved completely on next page
                 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
                     $pdf->setPage($pageposafter);
                     $curY = $tab_top_newpage;
                 }
                 $pdf->SetFont('', '', $default_font_size - 1);
                 // On repositionne la police par defaut
                 // VAT Rate
                 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
                     $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
                     $pdf->SetXY($this->posxtva, $curY);
                     $pdf->MultiCell($this->posxup - $this->posxtva - 0.8, 3, $vat_rate, 0, 'R');
                 }
                 // Unit price before discount
                 $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
                 $pdf->SetXY($this->posxup, $curY);
                 $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0, 'R', 0);
                 // Quantity
                 $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
                 $pdf->SetXY($this->posxqty, $curY);
                 // Enough for 6 chars
                 if ($conf->global->PRODUCT_USE_UNITS) {
                     $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0, 'R');
                 } else {
                     $pdf->MultiCell($this->posxdiscount - $this->posxqty - 0.8, 4, $qty, 0, 'R');
                 }
                 // Unit
                 if ($conf->global->PRODUCT_USE_UNITS) {
                     $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
                     $pdf->SetXY($this->posxunit, $curY);
                     $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0, 'L');
                 }
                 // Discount on line
                 if ($object->lines[$i]->remise_percent) {
                     $pdf->SetXY($this->posxdiscount - 2, $curY);
                     $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
                     $pdf->MultiCell($this->posxprogress - $this->posxdiscount + 2, 3, $remise_percent, 0, 'R');
                 }
                 if ($this->situationinvoice) {
                     // Situation progress
                     $progress = pdf_getlineprogress($object, $i, $outputlangs, $hidedetails);
                     $pdf->SetXY($this->posxprogress, $curY);
                     $pdf->MultiCell($this->postotalht - $this->posxprogress, 3, $progress, 0, 'R');
                 }
                 // Total HT line
                 $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
                 $pdf->SetXY($this->postotalht, $curY);
                 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
                 // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
                 $prev_progress = $object->lines[$i]->get_prev_progress();
                 if ($prev_progress > 0) {
                     if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) {
                         $tvaligne = $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
                     } else {
                         $tvaligne = $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
                     }
                 } else {
                     if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) {
                         $tvaligne = $object->lines[$i]->multicurrency_total_tva;
                     } else {
                         $tvaligne = $object->lines[$i]->total_tva;
                     }
                 }
                 $localtax1ligne = $object->lines[$i]->total_localtax1;
                 $localtax2ligne = $object->lines[$i]->total_localtax2;
                 $localtax1_rate = $object->lines[$i]->localtax1_tx;
                 $localtax2_rate = $object->lines[$i]->localtax2_tx;
                 $localtax1_type = $object->lines[$i]->localtax1_type;
                 $localtax2_type = $object->lines[$i]->localtax2_type;
                 if ($object->remise_percent) {
                     $tvaligne -= $tvaligne * $object->remise_percent / 100;
                 }
                 if ($object->remise_percent) {
                     $localtax1ligne -= $localtax1ligne * $object->remise_percent / 100;
                 }
                 if ($object->remise_percent) {
                     $localtax2ligne -= $localtax2ligne * $object->remise_percent / 100;
                 }
                 $vatrate = (string) $object->lines[$i]->tva_tx;
                 // Retrieve type from database for backward compatibility with old records
                 if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
                     $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
                     $localtax1_type = $localtaxtmp_array[0];
                     $localtax2_type = $localtaxtmp_array[2];
                 }
                 // retrieve global local tax
                 if ($localtax1_type && $localtax1ligne != 0) {
                     $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
                 }
                 if ($localtax2_type && $localtax2ligne != 0) {
                     $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
                 }
                 if (($object->lines[$i]->info_bits & 0x1) == 0x1) {
                     $vatrate .= '*';
                 }
                 if (!isset($this->tva[$vatrate])) {
                     $this->tva[$vatrate] = '';
                 }
                 $this->tva[$vatrate] += $tvaligne;
                 if ($posYAfterImage > $posYAfterDescription) {
                     $nexY = $posYAfterImage;
                 }
                 // Add line
                 if ($conf->global->MAIN_PDF_DASH_BETWEEN_LINES && $i < $nblignes - 1) {
                     $pdf->setPage($pageposafter);
                     $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
                     //$pdf->SetDrawColor(190,190,200);
                     $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
                     $pdf->SetLineStyle(array('dash' => 0));
                 }
                 $nexY += 2;
                 // Passe espace entre les lignes
                 // Detect if some page were added automatically and output _tableau for past pages
                 while ($pagenb < $pageposafter) {
                     $pdf->setPage($pagenb);
                     if ($pagenb == 1) {
                         $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
                     } else {
                         $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
                     }
                     $this->_pagefoot($pdf, $object, $outputlangs, 1);
                     $pagenb++;
                     $pdf->setPage($pagenb);
                     $pdf->setPageOrientation('', 1, 0);
                     // The only function to edit the bottom margin of current page to set it.
                     if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
                         $this->_pagehead($pdf, $object, 0, $outputlangs);
                     }
                 }
                 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
                     if ($pagenb == 1) {
                         $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
                     } else {
                         $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
                     }
                     $this->_pagefoot($pdf, $object, $outputlangs, 1);
                     // New page
                     $pdf->AddPage();
                     if (!empty($tplidx)) {
                         $pdf->useTemplate($tplidx);
                     }
                     $pagenb++;
                     if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
                         $this->_pagehead($pdf, $object, 0, $outputlangs);
                     }
                 }
             }
             // Show square
             if ($pagenb == 1) {
                 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
                 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
             } else {
                 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
                 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
             }
             // Affiche zone infos
             $posy = $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
             // Affiche zone totaux
             $posy = $this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
             // Affiche zone versements
             if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included) {
                 $posy = $this->_tableau_versements($pdf, $object, $posy, $outputlangs);
             }
             // Pied de page
             $this->_pagefoot($pdf, $object, $outputlangs);
             if (method_exists($pdf, 'AliasNbPages')) {
                 $pdf->AliasNbPages();
             }
             $pdf->Close();
             $pdf->Output($file, 'F');
             // Add pdfgeneration hook
             $hookmanager->initHooks(array('pdfgeneration'));
             $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
             global $action;
             $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action);
             // Note that $action and $object may have been modified by some hooks
             if (!empty($conf->global->MAIN_UMASK)) {
                 @chmod($file, octdec($conf->global->MAIN_UMASK));
             }
             return 1;
             // Pas d'erreur
         } else {
             $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
             return 0;
         }
     } else {
         $this->error = $langs->trans("ErrorConstantNotDefined", "FAC_OUTPUTDIR");
         return 0;
     }
     $this->error = $langs->trans("ErrorUnknown");
     return 0;
     // Erreur par defaut
 }
コード例 #15
0
 /**
  *  Build document onto disk
  *
  *  @param	Object		$object         Object invoice to build (or id if old method)
  *  @param  Translate	$outputlangs    Lang object for output language
  *  @return int             			1=OK, 0=KO
  */
 function write_file($object, $outputlangs = '')
 {
     global $user, $langs, $conf, $mysoc;
     if (!is_object($outputlangs)) {
         $outputlangs = $langs;
     }
     // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
     if (!empty($conf->global->MAIN_USE_FPDF)) {
         $outputlangs->charset_output = 'ISO-8859-1';
     }
     $outputlangs->load("main");
     $outputlangs->load("dict");
     $outputlangs->load("companies");
     $outputlangs->load("bills");
     $outputlangs->load("products");
     $default_font_size = pdf_getPDFFontSize($outputlangs);
     if ($conf->fournisseur->dir_output . '/facture') {
         $object->fetch_thirdparty();
         $deja_regle = $object->getSommePaiement();
         //$amount_credit_notes_included = $object->getSumCreditNotesUsed();
         //$amount_deposits_included = $object->getSumDepositsUsed();
         // Definition de $dir et $file
         if ($object->specimen) {
             $dir = $conf->fournisseur->facture->dir_output;
             $file = $dir . "/SPECIMEN.pdf";
         } else {
             $objectref = dol_sanitizeFileName($object->ref);
             $dir = $conf->fournisseur->facture->dir_output . '/' . get_exdir($object->id, 2) . $objectref;
             $file = $dir . "/" . $objectref . ".pdf";
         }
         if (!file_exists($dir)) {
             if (dol_mkdir($dir) < 0) {
                 $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
                 return 0;
             }
         }
         if (file_exists($dir)) {
             $nblignes = count($object->lines);
             $pdf = pdf_getInstance($this->format);
             if (class_exists('TCPDF')) {
                 $pdf->setPrintHeader(false);
                 $pdf->setPrintFooter(false);
             }
             $pdf->SetFont(pdf_getPDFFont($outputlangs));
             // Set path to the background PDF File
             if (empty($conf->global->MAIN_DISABLE_FPDI) && !empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
                 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output . '/' . $conf->global->MAIN_ADD_PDF_BACKGROUND);
                 $tplidx = $pdf->importPage(1);
             }
             $pdf->Open();
             $pagenb = 0;
             $pdf->SetDrawColor(128, 128, 128);
             $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
             $pdf->SetSubject($outputlangs->transnoentities("Invoice"));
             $pdf->SetCreator("Dolibarr " . DOL_VERSION);
             $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
             $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref) . " " . $outputlangs->transnoentities("Order"));
             if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) {
                 $pdf->SetCompression(false);
             }
             $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
             // Left, Top, Right
             $pdf->SetAutoPageBreak(1, 0);
             // Positionne $this->atleastonediscount si on a au moins une remise
             for ($i = 0; $i < $nblignes; $i++) {
                 if ($object->lines[$i]->remise_percent) {
                     $this->atleastonediscount++;
                 }
             }
             // New page
             $pdf->AddPage();
             if (!empty($tplidx)) {
                 $pdf->useTemplate($tplidx);
             }
             $pagenb++;
             $this->_pagehead($pdf, $object, 1, $outputlangs);
             $pdf->SetFont('', '', $default_font_size - 1);
             $pdf->MultiCell(0, 3, '');
             // Set interline to 3
             $pdf->SetTextColor(0, 0, 0);
             $tab_top = 90;
             $tab_top_newpage = 50;
             $tab_height = 110;
             $tab_height_newpage = 150;
             // Affiche notes
             if (!empty($object->note_public)) {
                 $tab_top = 88;
                 $pdf->SetFont('', '', $default_font_size - 1);
                 // Dans boucle pour gerer multi-page
                 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($object->note_public), 0, 1);
                 $nexY = $pdf->GetY();
                 $height_note = $nexY - $tab_top;
                 // Rect prend une longueur en 3eme param
                 $pdf->SetDrawColor(192, 192, 192);
                 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
                 $tab_height = $tab_height - $height_note;
                 $tab_top = $nexY + 6;
             } else {
                 $height_note = 0;
             }
             $iniY = $tab_top + 7;
             $curY = $tab_top + 7;
             $nexY = $tab_top + 7;
             // Boucle sur les lignes
             for ($i = 0; $i < $nblignes; $i++) {
                 $curY = $nexY;
                 $pdf->SetFont('', '', $default_font_size - 1);
                 // Dans boucle pour gerer multi-page
                 // Description of product line
                 $pdf->SetFont('', '', $default_font_size - 1);
                 // Into loop to work with multipage
                 $curX = $this->posxdesc - 1;
                 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 3, $curX, $curY, 0, 0, 1);
                 $pdf->SetFont('', '', $default_font_size - 1);
                 // On repositionne la police par defaut
                 $nexY = $pdf->GetY();
                 // VAT rate
                 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
                     $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs);
                     $pdf->SetXY($this->posxtva, $curY);
                     $pdf->MultiCell($this->posxup - $this->posxtva - 1, 3, $vat_rate, 0, 'R');
                 }
                 // Unit price before discount
                 $pdf->SetXY($this->posxup, $curY);
                 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 3, price($object->lines[$i]->pu_ht), 0, 'R', 0);
                 // Quantity
                 $pdf->SetXY($this->posxqty, $curY);
                 $pdf->MultiCell($this->posxdiscount - $this->posxqty - 1, 3, $object->lines[$i]->qty, 0, 'R');
                 // Discount on line
                 $pdf->SetXY($this->posxdiscount, $curY);
                 if ($object->lines[$i]->remise_percent) {
                     $pdf->MultiCell($this->postotalht - $this->posxdiscount - 1, 3, $object->lines[$i]->remise_percent . "%", 0, 'R');
                 }
                 // Total HT line
                 $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs);
                 $pdf->SetXY($this->postotalht, $curY);
                 $pdf->MultiCell(26, 3, $total_excl_tax, 0, 'R', 0);
                 // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
                 $tvaligne = $object->lines[$i]->total_tva;
                 $localtax1ligne = $object->lines[$i]->total_localtax1;
                 $localtax2ligne = $object->lines[$i]->total_localtax2;
                 if ($object->remise_percent) {
                     $tvaligne -= $tvaligne * $object->remise_percent / 100;
                 }
                 $vatrate = (string) $object->lines[$i]->tva_tx;
                 $localtax1rate = (string) $object->lines[$i]->localtax1_tx;
                 $localtax2rate = (string) $object->lines[$i]->localtax2_tx;
                 if (($object->lines[$i]->info_bits & 0x1) == 0x1) {
                     $vatrate .= '*';
                 }
                 $this->tva[$vatrate] += $tvaligne;
                 $this->localtax1[$localtax1rate] += $localtax1ligne;
                 $this->localtax2[$localtax2rate] += $localtax2ligne;
                 $nexY += 2;
                 // Passe espace entre les lignes
                 // Cherche nombre de lignes a venir pour savoir si place suffisante
                 if ($i < $nblignes - 1 && empty($hidedesc)) {
                     //on recupere la description du produit suivant
                     $follow_descproduitservice = $object->lines[$i + 1]->desc;
                     //on compte le nombre de ligne afin de verifier la place disponible (largeur de ligne 52 caracteres)
                     $nblineFollowDesc = dol_nboflines_bis($follow_descproduitservice, 52, $outputlangs->charset_output) * 4;
                     // Et si on affiche dates de validite, on ajoute encore une ligne
                     if ($object->lines[$i]->date_start && $object->lines[$i]->date_end) {
                         $nblineFollowDesc += 4;
                     }
                 } else {
                     $nblineFollowDesc = 0;
                 }
                 // Test if a new page is required
                 if ($pagenb == 1) {
                     $tab_top_in_current_page = $tab_top;
                     $tab_height_in_current_page = $tab_height;
                 } else {
                     $tab_top_in_current_page = $tab_top_newpage;
                     $tab_height_in_current_page = $tab_height_newpage;
                 }
                 if ($nexY + $nblineFollowDesc > $tab_top_in_current_page + $tab_height_in_current_page && $i < $nblignes - 1) {
                     if ($pagenb == 1) {
                         $this->_tableau($pdf, $tab_top, $tab_height + 20, $nexY, $outputlangs);
                     } else {
                         $this->_tableau($pdf, $tab_top_newpage, $tab_height_newpage, $nexY, $outputlangs);
                     }
                     $this->_pagefoot($pdf, $object, $outputlangs);
                     // New page
                     $pdf->AddPage();
                     if (!empty($tplidx)) {
                         $pdf->useTemplate($tplidx);
                     }
                     $pagenb++;
                     $this->_pagehead($pdf, $object, 0, $outputlangs);
                     $pdf->SetFont('', '', $default_font_size - 1);
                     $pdf->MultiCell(0, 3, '');
                     // Set interline to 3
                     $pdf->SetTextColor(0, 0, 0);
                     $nexY = $tab_top_newpage + 7;
                 }
             }
             // Show square
             if ($pagenb == 1) {
                 $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs);
                 $bottomlasttab = $tab_top + $tab_height + 1;
             } else {
                 $this->_tableau($pdf, $tab_top_newpage, $tab_height_newpage, $nexY, $outputlangs);
                 $bottomlasttab = $tab_top_newpage + $tab_height_newpage + 1;
             }
             // Affiche zone totaux
             $posy = $this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
             $amount_credit_notes_included = 0;
             $amount_deposits_included = 0;
             if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included) {
                 $posy = $this->_tableau_versements($pdf, $object, $posy, $outputlangs);
             }
             // Pied de page
             $this->_pagefoot($pdf, $object, $outputlangs);
             $pdf->AliasNbPages();
             $pdf->Close();
             $pdf->Output($file, 'F');
             // Actions on extra fields (by external module or standard code)
             if (!is_object($hookmanager)) {
                 include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
                 $hookmanager = new HookManager($this->db);
             }
             $hookmanager->initHooks(array('pdfgeneration'));
             $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
             global $action;
             $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action);
             // Note that $action and $object may have been modified by some hooks
             if (!empty($conf->global->MAIN_UMASK)) {
                 @chmod($file, octdec($conf->global->MAIN_UMASK));
             }
             return 1;
             // Pas d'erreur
         } else {
             $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
             return 0;
         }
     } else {
         $this->error = $langs->trans("ErrorConstantNotDefined", "SUPPLIER_OUTPUTDIR");
         return 0;
     }
     $this->error = $langs->trans("ErrorUnknown");
     return 0;
     // Erreur par defaut
 }
コード例 #16
0
	/**
     *      Write the invoice as a document onto disk
     *      @param      object          Object invoice to build (or id if old method)
     *      @param      outputlangs     Lang object for output language
     *      @return     int             1=OK, 0=KO
	 */
	function write_file($object,$outputlangs='')
	{
		global $user,$langs,$conf,$mysoc;

		if (! is_object($outputlangs)) $outputlangs=$langs;
		// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
		if (!class_exists('TCPDF')) $outputlangs->charset_output='ISO-8859-1';

		$outputlangs->load("main");
		$outputlangs->load("dict");
		$outputlangs->load("companies");
		$outputlangs->load("bills");
		$outputlangs->load("products");

		$default_font_size = pdf_getPDFFontSize($outputlangs);

		if ($conf->fournisseur->dir_output.'/facture')
		{
			$object->fetch_thirdparty();

			$deja_regle = $object->getSommePaiement();
            //$amount_credit_notes_included = $object->getSumCreditNotesUsed();
            //$amount_deposits_included = $object->getSumDepositsUsed();

			// Definition de $dir et $file
			if ($object->specimen)
			{
				$dir = $conf->fournisseur->facture->dir_output;
				$file = $dir . "/SPECIMEN.pdf";
			}
			else
			{
				$objectref = dol_sanitizeFileName($object->ref);
                $dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$objectref;
				$file = $dir . "/" . $objectref . ".pdf";
			}

			if (! file_exists($dir))
			{
				if (create_exdir($dir) < 0)
				{
					$this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
					return 0;
				}

			}

			if (file_exists($dir))
			{
				$nblignes = sizeof($object->lines);

                $pdf=pdf_getInstance($this->format);

                if (class_exists('TCPDF'))
                {
                    $pdf->setPrintHeader(false);
                    $pdf->setPrintFooter(false);
                }
                $pdf->SetFont(pdf_getPDFFont($outputlangs));

				$pdf->Open();
				$pagenb=0;
				$pdf->SetDrawColor(128,128,128);

				$pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
				$pdf->SetSubject($outputlangs->transnoentities("Invoice"));
				$pdf->SetCreator("Dolibarr ".DOL_VERSION);
				$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
				$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Order"));
				if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) $pdf->SetCompression(false);

				$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
				$pdf->SetAutoPageBreak(1,0);

			    // Positionne $this->atleastonediscount si on a au moins une remise
                for ($i = 0 ; $i < $nblignes ; $i++)
                {
                    if ($object->lines[$i]->remise_percent)
                    {
                        $this->atleastonediscount++;
                    }
                }

                // New page
				$pdf->AddPage();
				$pagenb++;
				$this->_pagehead($pdf, $object, 1, $outputlangs);
				$pdf->SetFont('','', $default_font_size - 1);
				$pdf->MultiCell(0, 3, '');		// Set interline to 3
				$pdf->SetTextColor(0,0,0);

				$tab_top = 90;
				$tab_top_newpage = 50;
				$tab_height = 110;
				$tab_height_newpage = 150;

				// Affiche notes
				if (! empty($object->note_public))
				{
					$tab_top = 88;

					$pdf->SetFont('','', $default_font_size - 1);   // Dans boucle pour gerer multi-page
					$pdf->SetXY ($this->posxdesc-1, $tab_top);
					$pdf->MultiCell(190, 3, $outputlangs->convToOutputCharset($object->note_public), 0, 'L');
					$nexY = $pdf->GetY();
					$height_note=$nexY-$tab_top;

					// Rect prend une longueur en 3eme param
					$pdf->SetDrawColor(192,192,192);
					$pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);

					$tab_height = $tab_height - $height_note;
					$tab_top = $nexY+6;
				}
				else
				{
					$height_note=0;
				}

				$iniY = $tab_top + 7;
				$curY = $tab_top + 7;
				$nexY = $tab_top + 7;

				// Boucle sur les lignes
				for ($i = 0 ; $i < $nblignes ; $i++)
				{
					$curY = $nexY;

                    $pdf->SetFont('','', $default_font_size - 1);   // Dans boucle pour gerer multi-page

                    // Description of product line
                    $pdf->SetFont('','', $default_font_size - 1);   // Into loop to work with multipage
                    $curX = $this->posxdesc-1;
                    pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,0,0,1);

					$pdf->SetFont('','', $default_font_size - 1);   // On repositionne la police par defaut
					$nexY = $pdf->GetY();

					// VAT rate
                    if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
                    {
    					$vat_rate = pdf_getlinevatrate($object, $i, $outputlangs);
                        $pdf->SetXY ($this->posxtva, $curY);
	       				$pdf->MultiCell($this->posxup-$this->posxtva-1, 3, $vat_rate, 0, 'R');
                    }

					// Unit price before discount
					$pdf->SetXY ($this->posxup, $curY);
					$pdf->MultiCell($this->posxqty-$this->posxup-1, 3, price($object->lines[$i]->pu_ht), 0, 'R', 0);

					// Quantity
					$pdf->SetXY ($this->posxqty, $curY);
					$pdf->MultiCell($this->posxdiscount-$this->posxqty-1, 3, $object->lines[$i]->qty, 0, 'R');

					// Discount on line
					$pdf->SetXY ($this->posxdiscount, $curY);
					if ($object->lines[$i]->remise_percent)
					{
						$pdf->MultiCell($this->postotalht-$this->posxdiscount-1, 3, $object->lines[$i]->remise_percent."%", 0, 'R');
					}

					// Total HT line
                    $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs);
                    $pdf->SetXY ($this->postotalht, $curY);
                    $pdf->MultiCell(26, 3, $total_excl_tax, 0, 'R', 0);

					// Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
					$tvaligne=$object->lines[$i]->total_tva;

					$localtax1ligne=$object->lines[$i]->total_localtax1;
					$localtax2ligne=$object->lines[$i]->total_localtax2;

					if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;

					$vatrate=(string) $object->lines[$i]->tva_tx;
					$localtax1rate=(string) $object->lines[$i]->localtax1_tx;
					$localtax2rate=(string) $object->lines[$i]->localtax2_tx;

					if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
					$this->tva[$vatrate] += $tvaligne;
					$this->localtax1[$localtax1rate]+=$localtax1ligne;
					$this->localtax2[$localtax2rate]+=$localtax2ligne;

					$nexY+=2;    // Passe espace entre les lignes

					// Test if a new page is required
					if ($pagenb == 1)
					{
						$tab_top_in_current_page=$tab_top;
						$tab_height_in_current_page=$tab_height;
					}
					else
					{
						$tab_top_in_current_page=$tab_top_newpage;
						$tab_height_in_current_page=$tab_height_newpage;
					}
					if (($nexY+$nblineFollowDesc) > ($tab_top_in_current_page+$tab_height_in_current_page) && $i < ($nblignes - 1))
					{
						if ($pagenb == 1)
						{
							$this->_tableau($pdf, $tab_top, $tab_height + 20, $nexY, $outputlangs);
						}
						else
						{
							$this->_tableau($pdf, $tab_top_newpage, $tab_height_newpage, $nexY, $outputlangs);
						}

						$this->_pagefoot($pdf, $object, $outputlangs);

						// New page
						$pdf->AddPage();
						$pagenb++;
						$this->_pagehead($pdf, $object, 0, $outputlangs);
						$pdf->SetFont('','', $default_font_size - 1);
						$pdf->MultiCell(0, 3, '');		// Set interline to 3
						$pdf->SetTextColor(0,0,0);

						$nexY = $tab_top_newpage + 7;
					}

				}

				// Show square
				if ($pagenb == 1)
				{
					$this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs);
					$bottomlasttab=$tab_top + $tab_height + 1;
				}
				else
				{
					$this->_tableau($pdf, $tab_top_newpage, $tab_height_newpage, $nexY, $outputlangs);
					$bottomlasttab=$tab_top_newpage + $tab_height_newpage + 1;
				}

				// Affiche zone totaux
				$posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);

				if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included)
				{
					$posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs);
				}

				// Pied de page
				$this->_pagefoot($pdf, $object, $outputlangs);
				$pdf->AliasNbPages();

				$pdf->Close();

				$pdf->Output($file,'F');
				if (! empty($conf->global->MAIN_UMASK))
				@chmod($file, octdec($conf->global->MAIN_UMASK));

				return 1;   // Pas d'erreur
			}
			else
			{
				$this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
				return 0;
			}
		}
		else
		{
			$this->error=$langs->trans("ErrorConstantNotDefined","SUPPLIER_OUTPUTDIR");
			return 0;
		}
		$this->error=$langs->trans("ErrorUnknown");
		return 0;   // Erreur par defaut
	}
 /**
  *  Function to build pdf onto disk
  *
  *  @param		Object		$object				Object to generate
  *  @param		Translate	$outputlangs		Lang output object
  *  @param		string		$srctemplatepath	Full path of source filename for generator using a template file
  *  @param		int			$hidedetails		Do not show line details
  *  @param		int			$hidedesc			Do not show desc
  *  @param		int			$hideref			Do not show ref
  *  @return     int             			1=OK, 0=KO
  */
 function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
 {
     global $user, $langs, $conf, $mysoc, $db, $hookmanager;
     if (!is_object($outputlangs)) {
         $outputlangs = $langs;
     }
     // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
     if (!empty($conf->global->MAIN_USE_FPDF)) {
         $outputlangs->charset_output = 'ISO-8859-1';
     }
     $outputlangs->load("main");
     $outputlangs->load("dict");
     $outputlangs->load("companies");
     $outputlangs->load("bills");
     $outputlangs->load("products");
     $outputlangs->load("orders");
     $outputlangs->load("deliveries");
     $nblignes = count($object->lines);
     if ($conf->commande->dir_output) {
         $object->fetch_thirdparty();
         $deja_regle = "";
         // Definition of $dir and $file
         if ($object->specimen) {
             $dir = $conf->commande->dir_output;
             $file = $dir . "/SPECIMEN.pdf";
         } else {
             $objectref = dol_sanitizeFileName($object->ref);
             $dir = $conf->commande->dir_output . "/" . $objectref;
             $file = $dir . "/" . $objectref . ".pdf";
         }
         if (!file_exists($dir)) {
             if (dol_mkdir($dir) < 0) {
                 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
                 return 0;
             }
         }
         if (file_exists($dir)) {
             // Add pdfgeneration hook
             if (!is_object($hookmanager)) {
                 include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
                 $hookmanager = new HookManager($this->db);
             }
             $hookmanager->initHooks(array('pdfgeneration'));
             $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
             global $action;
             $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action);
             // Note that $action and $object may have been modified by some hooks
             // Create pdf instance
             $pdf = pdf_getInstance($this->format);
             $default_font_size = pdf_getPDFFontSize($outputlangs);
             // Must be after pdf_getInstance
             $heightforinfotot = 50;
             // Height reserved to output the info and total part
             $heightforfreetext = isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5;
             // Height reserved to output the free text on last page
             $heightforfooter = $this->marge_basse + 8;
             // Height reserved to output the footer (value include bottom margin)
             $pdf->SetAutoPageBreak(1, 0);
             if (class_exists('TCPDF')) {
                 $pdf->setPrintHeader(false);
                 $pdf->setPrintFooter(false);
             }
             $pdf->SetFont(pdf_getPDFFont($outputlangs));
             // Set path to the background PDF File
             if (empty($conf->global->MAIN_DISABLE_FPDI) && !empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
                 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output . '/' . $conf->global->MAIN_ADD_PDF_BACKGROUND);
                 $tplidx = $pdf->importPage(1);
             }
             $pdf->Open();
             $pagenb = 0;
             $pdf->SetDrawColor(128, 128, 128);
             $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
             $pdf->SetSubject($outputlangs->transnoentities("Order"));
             $pdf->SetCreator("Dolibarr " . DOL_VERSION);
             $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
             $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref) . " " . $outputlangs->transnoentities("Order"));
             if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
                 $pdf->SetCompression(false);
             }
             $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
             // Left, Top, Right
             // Positionne $this->atleastonediscount si on a au moins une remise
             for ($i = 0; $i < $nblignes; $i++) {
                 if ($object->lines[$i]->remise_percent) {
                     $this->atleastonediscount++;
                 }
             }
             if (empty($this->atleastonediscount)) {
                 $this->posxpicture += $this->postotalht - $this->posxdiscount;
                 $this->posxtva += $this->postotalht - $this->posxdiscount;
                 $this->posxup += $this->postotalht - $this->posxdiscount;
                 $this->posxqty += $this->postotalht - $this->posxdiscount;
                 $this->posxdiscount += $this->postotalht - $this->posxdiscount;
                 //$this->postotalht;
             }
             // New page
             $pdf->AddPage();
             if (!empty($tplidx)) {
                 $pdf->useTemplate($tplidx);
             }
             $pagenb++;
             $this->_pagehead($pdf, $object, 1, $outputlangs);
             $pdf->SetFont('', '', $default_font_size - 1);
             $pdf->MultiCell(0, 3, '');
             // Set interline to 3
             $pdf->SetTextColor(0, 0, 0);
             $tab_top = 90;
             $tab_top_newpage = empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 : 10;
             $tab_height = 130;
             $tab_height_newpage = 150;
             // Affiche notes
             $notetoshow = empty($object->note_public) ? '' : $object->note_public;
             if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) {
                 // Get first sale rep
                 if (is_object($object->thirdparty)) {
                     $salereparray = $object->thirdparty->getSalesRepresentatives($user);
                     $salerepobj = new User($this->db);
                     $salerepobj->fetch($salereparray[0]['id']);
                     if (!empty($salerepobj->signature)) {
                         $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
                     }
                 }
             }
             if ($notetoshow) {
                 $tab_top = 88;
                 $pdf->SetFont('', '', $default_font_size - 1);
                 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
                 $nexY = $pdf->GetY();
                 $height_note = $nexY - $tab_top;
                 // Rect prend une longueur en 3eme param
                 $pdf->SetDrawColor(192, 192, 192);
                 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
                 $tab_height = $tab_height - $height_note;
                 $tab_top = $nexY + 6;
             } else {
                 $height_note = 0;
             }
             $iniY = $tab_top + 7;
             $curY = $tab_top + 7;
             $nexY = $tab_top + 7;
             $inPackage = false;
             $TPackageInfos = array();
             $TChilds = array();
             $package_qty = 0;
             $TStack = array();
             // Loop on each lines
             for ($i = 0; $i < $nblignes; $i++) {
                 $package_qty = $TStack[count($TStack) - 1]['package_qty'];
                 $inPackage = count($TStack) > 0;
                 // Ligne de titre
                 if ($object->lines[$i]->product_type == 9 && $object->lines[$i]->qty < 97 && $object->lines[$i]->fk_product > 0) {
                     $inPackage = true;
                     if ($conf->global->SUBTOTAL_SHOW_QTY_ON_TITLES) {
                         if (!empty($object->lines[$i]->fk_product)) {
                             $product = new Product($db);
                             $product->fetch($object->lines[$i]->fk_product);
                             $TChilds = $product->getChildsArbo($product->id);
                             $TStack[count($TStack)] = array('childs' => $TChilds, 'package' => array(), 'package_qty' => 0);
                             // Si on se trouvait déjà dans un package, on rajoute ce produit à la liste des produits
                             // du précédent package
                             if (count($TStack) > 1) {
                                 $TStack[count($TStack) - 2]['package'][$object->lines[$i]->fk_product] += $object->lines[$i]->qty;
                             }
                         }
                     }
                 }
                 if ($conf->global->SUBTOTAL_SHOW_QTY_ON_TITLES) {
                     if ($inPackage && $object->lines[$i]->product_type != 9 && $object->lines[$i]->fk_product > 0) {
                         $TStack[count($TStack) - 1]['package'][$object->lines[$i]->fk_product] += $object->lines[$i]->qty;
                     }
                 }
                 // Ligne de sous-total
                 if ($inPackage && $object->lines[$i]->product_type == 9 && $object->lines[$i]->qty >= 97) {
                     if (count($TStack) <= 1) {
                         $inPackage = false;
                     }
                     if ($conf->global->SUBTOTAL_SHOW_QTY_ON_TITLES) {
                         // Comparaison pour déterminer la quantité de package
                         $TProducts = array_keys($TStack[count($TStack) - 1]['package']);
                         $TProductsChilds = array_keys($TStack[count($TStack) - 1]['childs']);
                         if ($TProductsChilds == $TProducts) {
                             // Il s'agit d'un package
                             // On récupére la quantité
                             $first_child_id = $TProducts[0];
                             $document_qty = $TStack[count($TStack) - 1]['package'][$first_child_id];
                             $base_qty = $TStack[count($TStack) - 1]['childs'][$first_child_id][1];
                             $TStack[count($TStack) - 1]['package_qty'] = $document_qty / $base_qty;
                             $package_qty = $TStack[count($TStack) - 1]['package_qty'];
                         }
                         array_pop($TStack);
                     }
                 }
                 $curY = $nexY;
                 $pdf->SetFont('', '', $default_font_size - 1);
                 // Into loop to work with multipage
                 $pdf->SetTextColor(0, 0, 0);
                 $pdf->setTopMargin($tab_top_newpage);
                 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
                 // The only function to edit the bottom margin of current page to set it.
                 $pageposbefore = $pdf->getPage();
                 // Description of product line
                 $curX = $this->posxdesc - 1;
                 $showpricebeforepagebreak = 1;
                 $pdf->startTransaction();
                 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 3, $curX, $curY, $hideref, $hidedesc);
                 $pageposafter = $pdf->getPage();
                 if ($pageposafter > $pageposbefore) {
                     $pdf->rollbackTransaction(true);
                     $pageposafter = $pageposbefore;
                     //print $pageposafter.'-'.$pageposbefore;exit;
                     $pdf->setPageOrientation('', 1, $heightforfooter);
                     // The only function to edit the bottom margin of current page to set it.
                     pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 4, $curX, $curY, $hideref, $hidedesc);
                     $pageposafter = $pdf->getPage();
                     $posyafter = $pdf->GetY();
                     if ($posyafter > $this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot)) {
                         if ($i == $nblignes - 1) {
                             $pdf->AddPage('', '', true);
                             if (!empty($tplidx)) {
                                 $pdf->useTemplate($tplidx);
                             }
                             if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
                                 $this->_pagehead($pdf, $object, 0, $outputlangs);
                             }
                             $pdf->setPage($pageposafter + 1);
                         }
                     } else {
                         // We found a page break
                         $showpricebeforepagebreak = 0;
                     }
                 } else {
                     $pdf->commitTransaction();
                 }
                 $nexY = $pdf->GetY();
                 $pageposafter = $pdf->getPage();
                 $pdf->setPage($pageposbefore);
                 $pdf->setTopMargin($this->marge_haute);
                 $pdf->setPageOrientation('', 1, 0);
                 // The only function to edit the bottom margin of current page to set it.
                 // We suppose that a too long description is moved completely on next page
                 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
                     $pdf->setPage($pageposafter);
                     $curY = $tab_top_newpage;
                 }
                 $pdf->SetFont('', '', $default_font_size - 1);
                 // On repositionne la police par defaut
                 // VAT Rate
                 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
                     // Si on ne doit masquer que les sous-produits
                     if ($hidedetails && !$inPackage && $conf->global->SUBTOTAL_ONLY_HIDE_SUBPRODUCTS_PRICES) {
                         $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, 0);
                     } else {
                         $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
                     }
                     $pdf->SetXY($this->posxtva, $curY);
                     $pdf->MultiCell($this->posxup - $this->posxtva - 0.8, 3, $vat_rate, 0, 'R');
                 }
                 // Unit price before discount
                 if ($hidedetails && !$inPackage && $conf->global->SUBTOTAL_ONLY_HIDE_SUBPRODUCTS_PRICES) {
                     $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, 0);
                 } else {
                     $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
                 }
                 $pdf->SetXY($this->posxup, $curY);
                 $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0, 'R', 0);
                 // Booléen pour déterminer s'il s'agit d'une ligne de titre ou non
                 $isTitle = false;
                 // Quantity
                 // Récupération de la quantité à afficher
                 if ($conf->global->SUBTOTAL_IF_HIDE_PRICES_SHOW_QTY) {
                     if ($conf->global->SUBTOTAL_SHOW_QTY_ON_TITLES && $package_qty > 0) {
                         $qty = $package_qty;
                     } else {
                         $qty = pdf_getlineqty($object, $i, $outputlangs, 0);
                     }
                 } else {
                     if ($conf->global->SUBTOTAL_SHOW_QTY_ON_TITLES && $package_qty > 0) {
                         $qty = $package_qty;
                     } else {
                         $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
                     }
                 }
                 $pdf->SetXY($this->posxqty, $curY);
                 $pdf->MultiCell($this->posxdiscount - $this->posxqty - 0.8, 3, $qty, 0, 'R');
                 // Enough for 6 chars
                 // Discount on line
                 if ($object->lines[$i]->remise_percent) {
                     $pdf->SetXY($this->posxdiscount - 2, $curY);
                     $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
                     $pdf->MultiCell($this->postotalht - $this->posxdiscount + 2, 3, $remise_percent, 0, 'R');
                 }
                 // Total HT line
                 if ($hidedetails && !$inPackage && $conf->global->SUBTOTAL_ONLY_HIDE_SUBPRODUCTS_PRICES) {
                     $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, 0);
                 } else {
                     $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
                 }
                 $pdf->SetXY($this->postotalht, $curY);
                 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
                 // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
                 $tvaligne = $object->lines[$i]->total_tva;
                 $localtax1ligne = $object->lines[$i]->total_localtax1;
                 $localtax2ligne = $object->lines[$i]->total_localtax2;
                 $localtax1_rate = $object->lines[$i]->localtax1_tx;
                 $localtax2_rate = $object->lines[$i]->localtax2_tx;
                 $localtax1_type = $object->lines[$i]->localtax1_type;
                 $localtax2_type = $object->lines[$i]->localtax2_type;
                 if ($object->remise_percent) {
                     $tvaligne -= $tvaligne * $object->remise_percent / 100;
                 }
                 if ($object->remise_percent) {
                     $localtax1ligne -= $localtax1ligne * $object->remise_percent / 100;
                 }
                 if ($object->remise_percent) {
                     $localtax2ligne -= $localtax2ligne * $object->remise_percent / 100;
                 }
                 $vatrate = (string) $object->lines[$i]->tva_tx;
                 // Retrieve type from database for backward compatibility with old records
                 if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
                     $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
                     $localtax1_type = $localtaxtmp_array[0];
                     $localtax2_type = $localtaxtmp_array[2];
                 }
                 // retrieve global local tax
                 if ($localtax1_type && $localtax1ligne != 0) {
                     $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
                 }
                 if ($localtax2_type && $localtax2ligne != 0) {
                     $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
                 }
                 if (($object->lines[$i]->info_bits & 0x1) == 0x1) {
                     $vatrate .= '*';
                 }
                 if (!isset($this->tva[$vatrate])) {
                     $this->tva[$vatrate] = '';
                 }
                 $this->tva[$vatrate] += $tvaligne;
                 // Add line
                 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < $nblignes - 1) {
                     $pdf->setPage($pageposafter);
                     $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(210, 210, 210)));
                     //$pdf->SetDrawColor(190,190,200);
                     $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
                     $pdf->SetLineStyle(array('dash' => 0));
                 }
                 $nexY += 2;
                 // Passe espace entre les lignes
                 // Detect if some page were added automatically and output _tableau for past pages
                 while ($pagenb < $pageposafter) {
                     $pdf->setPage($pagenb);
                     if ($pagenb == 1) {
                         $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
                     } else {
                         $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
                     }
                     $this->_pagefoot($pdf, $object, $outputlangs, 1);
                     $pagenb++;
                     $pdf->setPage($pagenb);
                     $pdf->setPageOrientation('', 1, 0);
                     // The only function to edit the bottom margin of current page to set it.
                     if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
                         $this->_pagehead($pdf, $object, 0, $outputlangs);
                     }
                 }
                 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
                     if ($pagenb == 1) {
                         $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
                     } else {
                         $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
                     }
                     $this->_pagefoot($pdf, $object, $outputlangs, 1);
                     // New page
                     $pdf->AddPage();
                     if (!empty($tplidx)) {
                         $pdf->useTemplate($tplidx);
                     }
                     $pagenb++;
                     if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
                         $this->_pagehead($pdf, $object, 0, $outputlangs);
                     }
                 }
             }
             // Show square
             if ($pagenb == 1) {
                 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
                 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
             } else {
                 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
                 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
             }
             // Affiche zone infos
             $posy = $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
             if (!$conf->global->SUBTOTAL_HIDE_DOCUMENT_TOTAL) {
                 // Affiche zone totaux
                 $posy = $this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
             }
             // Affiche zone versements
             if ($deja_regle) {
                 $posy = $this->_tableau_versements($pdf, $object, $posy, $outputlangs);
             }
             // Pied de page
             $this->_pagefoot($pdf, $object, $outputlangs);
             if (method_exists($pdf, 'AliasNbPages')) {
                 $pdf->AliasNbPages();
             }
             $pdf->Close();
             $pdf->Output($file, 'F');
             // Add pdfgeneration hook
             $hookmanager->initHooks(array('pdfgeneration'));
             $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
             global $action;
             $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action);
             // Note that $action and $object may have been modified by some hooks
             if (!empty($conf->global->MAIN_UMASK)) {
                 @chmod($file, octdec($conf->global->MAIN_UMASK));
             }
             return 1;
             // Pas d'erreur
         } else {
             $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
             return 0;
         }
     } else {
         $this->error = $langs->trans("ErrorConstantNotDefined", "COMMANDE_OUTPUTDIR");
         return 0;
     }
     $this->error = $langs->trans("ErrorUnknown");
     return 0;
     // Erreur par defaut
 }