Browse Source

Fix: Long name wrapping. Sender address is third party for supplier
order/invoice

Laurent Destailleur 13 years ago
parent
commit
e9292515bc

+ 28 - 26
htdocs/core/modules/commande/doc/pdf_einstein.modules.php

@@ -34,8 +34,7 @@ require_once(DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php');
 
 
 /**
- *	\class      pdf_einstein
- *	\brief      Classe permettant de generer les commandes au modele Einstein
+ *	Classe permettant de generer les commandes au modele Einstein
  */
 class pdf_einstein extends ModelePDFCommandes
 {
@@ -91,16 +90,16 @@ class pdf_einstein extends ModelePDFCommandes
 		$this->option_condreg = 1;                 // Affiche conditions reglement
 		$this->option_codeproduitservice = 1;      // Affiche code produit-service
 		$this->option_multilang = 1;               // Dispo en plusieurs langues
-		$this->option_escompte = 1;                // Affiche si il y a eu escompte
-		$this->option_credit_note = 1;             // Support credit notes
+		$this->option_escompte = 0;                // Affiche si il y a eu escompte
+		$this->option_credit_note = 0;             // Support credit notes
 		$this->option_freetext = 1;				   // Support add of a personalised text
-		$this->option_draft_watermark = 1;		   //Support add of a watermark on drafts
+		$this->option_draft_watermark = 1;		   // Support add of a watermark on drafts
 
 		$this->franchise=!$mysoc->tva_assuj;
 
-		// Recupere emmetteur
+		// Get source company
 		$this->emetteur=$mysoc;
-		if (! $this->emetteur->pays_code) $this->emetteur->pays_code=substr($langs->defaultlang,-2);    // By default, if was not defined
+		if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default, if was not defined
 
 		// Defini position des colonnes
 		$this->posxdesc=$this->marge_gauche+1;
@@ -118,7 +117,7 @@ class pdf_einstein extends ModelePDFCommandes
 	}
 
 	/**
-     *  Function to build pdf onto disk
+     *  Build document onto disk
      *
      *  @param		int		$object				Id of object to generate
      *  @param		object	$outputlangs		Lang output object
@@ -235,12 +234,12 @@ class pdf_einstein extends ModelePDFCommandes
 				{
 					$tab_top = 88;
 
-					$pdf->SetFont('','', $default_font_size - 1);   // Dans boucle pour gerer multi-page
+					$pdf->SetFont('','', $default_font_size - 1);   // Into loop to manage multipages
 					$pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, $outputlangs->convToOutputCharset($object->note_public), 0, 1);
 					$nexY = $pdf->GetY();
 					$height_note=$nexY-$tab_top;
 
-					// Rect prend une longueur en 3eme et 4eme param
+					// 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);
 
@@ -261,16 +260,16 @@ class pdf_einstein extends ModelePDFCommandes
 				{
 					$curY = $nexY;
 
-					$pdf->SetFont('','', $default_font_size - 1);   // Dans boucle pour gerer multi-page
+                    $pdf->SetFont('','', $default_font_size - 1);   // Into loop to work with multipage
 
 					// Description of product line
 					$curX = $this->posxdesc-1;
-					pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,4,$curX,$curY,$hideref,$hidedesc,0,$hookmanager);
+					pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,$hideref,$hidedesc,0,$hookmanager);
 
 					$pdf->SetFont('','',  $default_font_size - 1);   // On repositionne la police par defaut
 					$nexY = $pdf->GetY();
 
-					// TVA
+					// VAT Rate
 					if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
 					{
 						$vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails, $hookmanager);
@@ -278,7 +277,7 @@ class pdf_einstein extends ModelePDFCommandes
 						$pdf->MultiCell($this->posxup-$this->posxtva-1, 3, $vat_rate, 0, 'R');
 					}
 
-					// Prix unitaire HT avant remise
+					// 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);
@@ -288,7 +287,7 @@ class pdf_einstein extends ModelePDFCommandes
 					$pdf->SetXY($this->posxqty, $curY);
 					$pdf->MultiCell($this->posxdiscount-$this->posxqty-1, 3, $qty, 0, 'R');
 
-					// Remise sur ligne
+					// Discount on line
 					$pdf->SetXY($this->posxdiscount, $curY);
 					if ($object->lines[$i]->remise_percent)
 					{
@@ -296,10 +295,10 @@ class pdf_einstein extends ModelePDFCommandes
 						$pdf->MultiCell($this->postotalht-$this->posxdiscount-1, 3, $remise_percent, 0, 'R');
 					}
 
-					// Total HT ligne
+					// Total HT line
 					$total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails, $hookmanager);
 					$pdf->SetXY($this->postotalht, $curY);
-					$pdf->MultiCell(26, 3, $total_excl_tax, 0, 'R', 0);
+					$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;
@@ -307,6 +306,10 @@ class pdf_einstein extends ModelePDFCommandes
 					$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;
@@ -405,7 +408,7 @@ class pdf_einstein extends ModelePDFCommandes
 
 				$pdf->Output($file,'F');
 
-				// Actions on extra fields (by external module or standard code)
+				// Add pdfgeneration hook
 				if (! is_object($hookmanager))
 				{
 					include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
@@ -647,7 +650,7 @@ class pdf_einstein extends ModelePDFCommandes
 					$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
 				}
 			}
-			if (! $this->atleastoneratenotnull) // If not vat at all
+			if (! $this->atleastoneratenotnull) // If no vat at all
 			{
 				$index++;
 				$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
@@ -661,7 +664,7 @@ class pdf_einstein extends ModelePDFCommandes
 				{
 					$index++;
 					$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
-					$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalLT1".$mysoc->pays_code), $useborder, 'L', 1);
+					$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalLT1".$mysoc->country_code), $useborder, 'L', 1);
 					$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
 					$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax1), $useborder, 'R', 1);
 				}
@@ -671,7 +674,7 @@ class pdf_einstein extends ModelePDFCommandes
 				{
 					$index++;
 					$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
-					$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalLT2".$mysoc->pays_code), $useborder, 'L', 1);
+					$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalLT2".$mysoc->country_code), $useborder, 'L', 1);
 					$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
 					$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax2), $useborder, 'R', 1);
 				}
@@ -696,7 +699,7 @@ class pdf_einstein extends ModelePDFCommandes
 								$tvakey=str_replace('*','',$tvakey);
 								$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
 							}
-							$totalvat =$outputlangs->transnoentities("TotalLT1".$mysoc->pays_code).' ';
+							$totalvat =$outputlangs->transnoentities("TotalLT1".$mysoc->country_code).' ';
 							$totalvat.=vatrate($tvakey,1).$tvacompl;
 							$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
 
@@ -709,7 +712,7 @@ class pdf_einstein extends ModelePDFCommandes
 				//Local tax 2
 				if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
 				{
-					foreach( $this->localtax2 as $tvakey => $tvaval )
+				    foreach( $this->localtax2 as $tvakey => $tvaval )
 					{
 						if ($tvakey>0)    // On affiche pas taux 0
 						{
@@ -724,7 +727,7 @@ class pdf_einstein extends ModelePDFCommandes
 								$tvakey=str_replace('*','',$tvakey);
 								$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
 							}
-							$totalvat =$outputlangs->transnoentities("TotalLT2".$mysoc->pays_code).' ';
+							$totalvat =$outputlangs->transnoentities("TotalLT2".$mysoc->country_code).' ';
 							$totalvat.=vatrate($tvakey,1).$tvacompl;
 							$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
 
@@ -748,6 +751,7 @@ class pdf_einstein extends ModelePDFCommandes
 			$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
 			$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc), $useborder, 'R', 1);
 		}
+		$pdf->SetFont('','', $default_font_size - 1);
 		$pdf->SetTextColor(0,0,0);
 
 		if ($deja_regle > 0)
@@ -762,7 +766,6 @@ class pdf_einstein extends ModelePDFCommandes
 
 			$resteapayer = $object->total_ttc - $deja_regle;
 
-
 			$index++;
 			$pdf->SetTextColor(0,0,60);
 			$pdf->SetFillColor(224,224,224);
@@ -772,7 +775,6 @@ class pdf_einstein extends ModelePDFCommandes
 			$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
 			$pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer), $useborder, 'R', 1);
 
-			// Fin
 			$pdf->SetFont('','', $default_font_size - 1);
 			$pdf->SetTextColor(0,0,0);
 		}

+ 14 - 12
htdocs/core/modules/supplier_invoice/modules_facturefournisseur.php

@@ -19,15 +19,14 @@
 
 /**
  *		\file       htdocs/core/modules/supplier_invoice/modules_facturefournisseur.php
- *      \ingroup    facture fourniseur
+ *      \ingroup    facture fournisseur
  *      \brief      File that contain parent class for supplier invoices models
  */
 require_once(DOL_DOCUMENT_ROOT."/core/class/commondocgenerator.class.php");
 
 
 /**
- *	\class      ModelePDFSuppliersInvoices
- *	\brief      Parent class for supplier invoices models
+ *	Parent class for supplier invoices models
  */
 abstract class ModelePDFSuppliersInvoices extends CommonDocGenerator
 {
@@ -57,15 +56,18 @@ abstract class ModelePDFSuppliersInvoices extends CommonDocGenerator
 }
 
 /**
- *	Create object on disk.
+ *	Create a document onto disk according to template module.
  *
- *	@param	    DoliDB		$db  			objet base de donnee
- *	@param	    Object		$object			object supplier invoice
+ *	@param	    DoliDB		$db  			Database handler
+ *	@param	    Object		$object			Object supplier invoice
  *	@param	    string		$modele			Force template to use ('' to not force)
- *	@param		Translate	$outputlangs	objet lang a utiliser pour traduction
+ *	@param		Translate	$outputlangs	Object lang a utiliser pour traduction
+ *  @param      int			$hidedetails    Hide details of lines
+ *  @param      int			$hidedesc       Hide description
+ *  @param      int			$hideref        Hide ref
  *  @return     int         				0 if KO, 1 if OK
  */
-function supplier_invoice_pdf_create($db, $object, $modele, $outputlangs)
+function supplier_invoice_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
 {
 	global $conf, $user, $langs;
 
@@ -81,7 +83,7 @@ function supplier_invoice_pdf_create($db, $object, $modele, $outputlangs)
 
     $srctemplatepath='';
 
-	// Positionne modele sur le nom du modele de invoice fournisseur a utiliser
+	// Positionne le modele sur le nom du modele a utiliser
 	if (! dol_strlen($modele))
 	{
 		if (! empty($conf->global->INVOICE_SUPPLIER_ADDON_PDF))
@@ -102,7 +104,7 @@ function supplier_invoice_pdf_create($db, $object, $modele, $outputlangs)
         $srctemplatepath=$tmp[1];
     }
 
-	// Search template file
+	// Search template files
 	$file=''; $classname=''; $filefound=0;
 	$dirmodels=array('/');
 	if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']);
@@ -134,7 +136,7 @@ function supplier_invoice_pdf_create($db, $object, $modele, $outputlangs)
 		// We save charset_output to restore it because write_file can change it if needed for
 		// output format that does not support UTF8.
 		$sav_charset_output=$outputlangs->charset_output;
-		if ($obj->write_file($object,$outputlangs) > 0)
+		if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc) > 0)
 		{
 			$outputlangs->charset_output=$sav_charset_output;
 
@@ -145,7 +147,7 @@ function supplier_invoice_pdf_create($db, $object, $modele, $outputlangs)
 			// Appel des triggers
 			include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
 			$interface=new Interfaces($db);
-			$result=$interface->run_triggers('BILL_BUILDDOC',$object,$user,$langs,$conf);
+			$result=$interface->run_triggers('SUPPLIER_INVOICE_BUILDDOC',$object,$user,$langs,$conf);
 			if ($result < 0) { $error++; $this->errors=$interface->errors; }
 			// Fin appel triggers
 

+ 5 - 5
htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php

@@ -113,11 +113,11 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
 
 
 	/**
-     *      Write the invoice as a document onto disk
+     *  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
+     *  @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='')
 	{
@@ -873,7 +873,7 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
 			$pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
 
 			// Show sender information
-			$pdf->SetXY($posx+2,$posy+8);
+			$pdf->SetXY($posx+2,$posy+4+(dol_nboflines_bis($this->emetteur->name,44)*4));
 			$pdf->SetFont('','', $default_font_size - 1);
 			$pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
 

+ 19 - 13
htdocs/core/modules/supplier_order/modules_commandefournisseur.php

@@ -23,7 +23,7 @@
 
 /**
  *		\file       htdocs/core/modules/supplier_order/modules_commandefournisseur.php
- *      \ingroup    commande
+ *      \ingroup    commande fournisseur
  *      \brief      File that contain parent class for supplier orders models
  *                  and parent class for supplier orders numbering models
  */
@@ -32,8 +32,7 @@ require_once(DOL_DOCUMENT_ROOT."/compta/bank/class/account.class.php");	// requi
 
 
 /**
- *	\class      ModelePDFSuppliersOrders
- *	\brief      Parent class for supplier orders models
+ *	Parent class for supplier orders models
  */
 abstract class ModelePDFSuppliersOrders extends CommonDocGenerator
 {
@@ -65,8 +64,7 @@ abstract class ModelePDFSuppliersOrders extends CommonDocGenerator
 
 
 /**
- *	\class      ModeleNumRefSuppliersOrders
- *	\brief      Classe mere des modeles de numerotation des references de commandes fournisseurs
+ *	Classe mere des modeles de numerotation des references de commandes fournisseurs
  */
 abstract class ModeleNumRefSuppliersOrders
 {
@@ -140,20 +138,20 @@ abstract class ModeleNumRefSuppliersOrders
 
 
 /**
- *  Create a document onto disk accordign to template module.
+ *  Create a document onto disk according to template module.
  *
- *  @param	    DoliDB		$db  			data base object
- *  @param	    Object		$object			object order
- *  @param	    string		$model			force le modele a utiliser ('' to not force)
- *  @param		Translate	$outputlangs	Objet lang a utiliser pour traduction
+ *  @param	    DoliDB		$db  			Database handler
+ *  @param	    Object		$object			Object supplier order
+ *  @param	    string		$modele			Force template to use ('' to not force)
+ *  @param		Translate	$outputlangs	Object lang a utiliser pour traduction
  *  @param      int			$hidedetails    Hide details of lines
  *  @param      int			$hidedesc       Hide description
  *  @param      int			$hideref        Hide ref
  *  @return     int          				0 if KO, 1 if OK
  */
-function supplier_order_pdf_create($db, $object, $model, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
+function supplier_order_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
 {
-	global $conf,$langs;
+	global $conf, $user, $langs;
 	$langs->load("suppliers");
 
 	$error=0;
@@ -214,7 +212,7 @@ function supplier_order_pdf_create($db, $object, $model, $outputlangs, $hidedeta
 	{
 		require_once($file);
 
-		$obj = new $classname($db);
+		$obj = new $classname($db,$object);
 
 		// We save charset_output to restore it because write_file can change it if needed for
 		// output format that does not support UTF8.
@@ -226,6 +224,14 @@ function supplier_order_pdf_create($db, $object, $model, $outputlangs, $hidedeta
 			// we delete preview files
         	require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
 			dol_delete_preview($object);
+			
+			// Appel des triggers
+			include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
+			$interface=new Interfaces($db);
+			$result=$interface->run_triggers('SUPPLIER_ORDER_BUILDDOC',$object,$user,$langs,$conf);
+			if ($result < 0) { $error++; $this->errors=$interface->errors; }
+			// Fin appel triggers
+
 			return 1;
 		}
 		else

+ 158 - 121
htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php

@@ -34,8 +34,7 @@ require_once(DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php');
 
 
 /**
- *	\class      pdf_muscadet
- *	\brief      Classe permettant de generer les commandes fournisseurs au modele Muscadet
+ *	Class to generate the supplier orders with the muscadet model
  */
 class pdf_muscadet extends ModelePDFSuppliersOrders
 {
@@ -63,7 +62,7 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 	 *
 	 *  @param		DoliDB		$db      Database handler
 	 */
-	function __construct($db)
+	function __construct($db,$object)
 	{
 		global $conf,$langs,$mysoc;
 
@@ -91,12 +90,17 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 		$this->option_condreg = 1;                 // Affiche conditions reglement
 		$this->option_codeproduitservice = 1;      // Affiche code produit-service
 		$this->option_multilang = 1;               // Dispo en plusieurs langues
+		$this->option_escompte = 0;                // Affiche si il y a eu escompte
+		$this->option_credit_note = 0;             // Support credit notes
+		$this->option_freetext = 1;				   // Support add of a personalised text
+		$this->option_draft_watermark = 1;		   // Support add of a watermark on drafts
 
 		$this->franchise=!$mysoc->tva_assuj;
 
-		// Get source company
-		$this->emetteur=$mysoc;
-		if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default, if was not defined
+        // Get source company
+        if (! is_object($object->thirdparty)) $object->fetch_thirdparty();
+        $this->emetteur=$object->thirdparty;
+        if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default, if was not defined
 
 		// Defini position des colonnes
 		$this->posxdesc=$this->marge_gauche+1;
@@ -115,13 +119,18 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 
 
     /**
-     *      Write the order as a document onto disk
+     *  Build document 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='')
+	function write_file($object,$outputlangs='',$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0,$hookmanager=false)
 	{
 		global $user,$langs,$conf;
 
@@ -165,7 +174,7 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 			{
 				if (dol_mkdir($dir) < 0)
 				{
-					$this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
+					$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
 					return 0;
 				}
 
@@ -217,7 +226,7 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 				$pdf->AddPage();
 				if (! empty($tplidx)) $pdf->useTemplate($tplidx);
 				$pagenb++;
-				$this->_pagehead($pdf, $object, 1, $outputlangs);
+				$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);
@@ -232,7 +241,7 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 				{
 					$tab_top = 88;
 
-					$pdf->SetFont('','', $default_font_size - 1);
+					$pdf->SetFont('','', $default_font_size - 1);   // Into loop to manage multipages
 					$pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, $outputlangs->convToOutputCharset($object->note_public), 0, 1);
 					$nexY = $pdf->GetY();
 					$height_note=$nexY-$tab_top;
@@ -258,10 +267,11 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 				{
 					$curY = $nexY;
 
-                    // Description of product line
                     $pdf->SetFont('','', $default_font_size - 1);   // Into loop to work with multipage
+
+					// Description of product line
                     $curX = $this->posxdesc-1;
-                    pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,0,0,1);
+                    pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,0,0,1,$hookmanager);
 
 					$pdf->SetFont('','', $default_font_size - 1);   // On repositionne la police par defaut
 					$nexY = $pdf->GetY();
@@ -269,7 +279,7 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 					// VAT Rate
                     if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
                     {
-                        $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs);
+                        $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');
                     }
@@ -321,7 +331,7 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 						//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;
+						$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)
 						{
@@ -361,7 +371,7 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 						$pdf->AddPage();
 				        if (! empty($tplidx)) $pdf->useTemplate($tplidx);
 						$pagenb++;
-						$this->_pagehead($pdf, $object, 0, $outputlangs);
+						$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);
@@ -436,6 +446,21 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 	}
 
 
+	/**
+	 *  Affiche tableau des versement
+	 *
+	 *  @param	PDF			&$pdf     		Object PDF
+	 *  @param  Object		$object			Object order
+	 *	@param	int			$posy			Position y in PDF
+	 *	@param	Translate	$outputlangs	Object langs for output
+	 *	@return int							<0 if KO, >0 if OK
+	 */
+	function _tableau_versements(&$pdf, $object, $posy, $outputlangs)
+	{
+
+	}
+
+
 	/**
 	 *   Show miscellaneous information (payment mode, payment term, ...)
 	 *
@@ -464,7 +489,7 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 	    }
 
 	    // Show payments conditions
-	    if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement))
+	    if ($object->cond_reglement_code || $object->cond_reglement)
 	    {
 	        $pdf->SetFont('','B', $default_font_size - 2);
 	        $pdf->SetXY($this->marge_gauche, $posy);
@@ -480,96 +505,95 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 	        $posy=$pdf->GetY()+3;
 	    }
 
+        // Check a payment mode is defined
+        /* Not used with orders
+		if (empty($object->mode_reglement_code)
+        	&& ! $conf->global->FACTURE_CHQ_NUMBER
+        	&& ! $conf->global->FACTURE_RIB_NUMBER)
+		{
+            $pdf->SetXY($this->marge_gauche, $posy);
+            $pdf->SetTextColor(200,0,0);
+            $pdf->SetFont('','B', $default_font_size - 2);
+            $pdf->MultiCell(90, 3, $outputlangs->transnoentities("ErrorNoPaiementModeConfigured"),0,'L',0);
+            $pdf->SetTextColor(0,0,0);
+
+            $posy=$pdf->GetY()+1;
+        }
+		*/
+
+	    // Show payment mode
+        if ($object->mode_reglement_code
+	    //    && $object->mode_reglement_code != 'CHQ'
+	    //    && $object->mode_reglement_code != 'VIR'
+	    )
+        {
+            $pdf->SetFont('','B', $default_font_size - 2);
+            $pdf->SetXY($this->marge_gauche, $posy);
+            $titre = $outputlangs->transnoentities("PaymentMode").':';
+            $pdf->MultiCell(80, 4, $titre, 0, 'L');
+
+            $pdf->SetFont('','', $default_font_size - 2);
+	        $pdf->SetXY(52, $posy);
+            $lib_mode_reg=$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code)!=('PaymentType'.$object->mode_reglement_code)?$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code):$outputlangs->convToOutputCharset($object->mode_reglement);
+            $pdf->MultiCell(80, 4, $lib_mode_reg,0,'L');
+
+            $posy=$pdf->GetY()+2;
+        }
+
+        // Show payment mode CHQ
+        /*
+        if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ')
+        {
+            // Si mode reglement non force ou si force a CHQ
+            if ($conf->global->FACTURE_CHQ_NUMBER)
+            {
+                if ($conf->global->FACTURE_CHQ_NUMBER > 0)
+                {
+                    $account = new Account($this->db);
+                    $account->fetch($conf->global->FACTURE_CHQ_NUMBER);
+
+                    $pdf->SetXY($this->marge_gauche, $posy);
+                    $pdf->SetFont('','B', $default_font_size - 2);
+                    $pdf->MultiCell(90, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$account->proprio).':',0,'L',0);
+                    $posy=$pdf->GetY()+1;
+                    $pdf->SetXY($this->marge_gauche, $posy);
+                    $pdf->SetFont('','', $default_font_size - 2);
+                    $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($account->adresse_proprio), 0, 'L', 0);
+                    $posy=$pdf->GetY()+2;
+                }
+                if ($conf->global->FACTURE_CHQ_NUMBER == -1)
+                {
+                    $pdf->SetXY($this->marge_gauche, $posy);
+                    $pdf->SetFont('','B', $default_font_size - 2);
+                    $pdf->MultiCell(90, 3, $outputlangs->transnoentities('PaymentByChequeOrderedToShort').' '.$outputlangs->convToOutputCharset($this->emetteur->name).' '.$outputlangs->transnoentities('SendTo').':',0,'L',0);
+                    $posy=$pdf->GetY()+1;
+
+                    $pdf->SetXY($this->marge_gauche, $posy);
+                    $pdf->SetFont('','', $default_font_size - 2);
+                    $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
+                    $posy=$pdf->GetY()+2;
+                }
+            }
+        }
+
+        // If payment mode not forced or forced to VIR, show payment with BAN
+        if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')
+        {
+            if (! empty($conf->global->FACTURE_RIB_NUMBER))
+            {
+                $account = new Account($this->db);
+                $account->fetch($conf->global->FACTURE_RIB_NUMBER);
+
+                $curx=$this->marge_gauche;
+                $cury=$posy;
+
+                $posy=pdf_bank($pdf,$outputlangs,$curx,$cury,$account);
+
+                $posy+=2;
+            }
+        }
+		*/
 
-	    if ($object->type != 2)
-	    {
-	        // Check a payment mode is defined
-	        /*
-	        if (empty($object->mode_reglement_code)
-	        && ! $conf->global->FACTURE_CHQ_NUMBER
-	        && ! $conf->global->FACTURE_RIB_NUMBER)
-	        {
-	            $pdf->SetXY($this->marge_gauche, $posy);
-	            $pdf->SetTextColor(200,0,0);
-	            $pdf->SetFont('','B', $default_font_size - 2);
-	            $pdf->MultiCell(90, 3, $outputlangs->transnoentities("ErrorNoPaiementModeConfigured"),0,'L',0);
-	            $pdf->SetTextColor(0,0,0);
-
-	            $posy=$pdf->GetY()+1;
-	        }*/
-
-	        // Show payment mode
-	        if ($object->mode_reglement_code)
-//	        && $object->mode_reglement_code != 'CHQ'
-//	        && $object->mode_reglement_code != 'VIR')
-	        {
-	            $pdf->SetFont('','B', $default_font_size - 2);
-	            $pdf->SetXY($this->marge_gauche, $posy);
-	            $titre = $outputlangs->transnoentities("PaymentMode").':';
-	            $pdf->MultiCell(80, 5, $titre, 0, 'L');
-
-	            $pdf->SetFont('','', $default_font_size - 2);
-	            $pdf->SetXY(50, $posy);
-	            $lib_mode_reg=$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code)!=('PaymentType'.$object->mode_reglement_code)?$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code):$outputlangs->convToOutputCharset($object->mode_reglement);
-	            $pdf->MultiCell(80, 5, $lib_mode_reg,0,'L');
-
-	            $posy=$pdf->GetY()+2;
-	        }
-
-	        // Show payment mode CHQ
-/*	        if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ')
-	        {
-	            // Si mode reglement non force ou si force a CHQ
-	            if ($conf->global->FACTURE_CHQ_NUMBER)
-	            {
-	                if ($conf->global->FACTURE_CHQ_NUMBER > 0)
-	                {
-	                    $account = new Account($this->db);
-	                    $account->fetch($conf->global->FACTURE_CHQ_NUMBER);
-
-	                    $pdf->SetXY($this->marge_gauche, $posy);
-	                    $pdf->SetFont('','B', $default_font_size - 2);
-	                    $pdf->MultiCell(90, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$account->proprio).':',0,'L',0);
-	                    $posy=$pdf->GetY()+1;
-
-	                    $pdf->SetXY($this->marge_gauche, $posy);
-	                    $pdf->SetFont('','', $default_font_size - 2);
-	                    $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($account->adresse_proprio), 0, 'L', 0);
-	                    $posy=$pdf->GetY()+2;
-	                }
-	                if ($conf->global->FACTURE_CHQ_NUMBER == -1)
-	                {
-	                    $pdf->SetXY($this->marge_gauche, $posy);
-	                    $pdf->SetFont('','B', $default_font_size - 2);
-	                    $pdf->MultiCell(90, 3, $outputlangs->transnoentities('PaymentByChequeOrderedToShort').' '.$outputlangs->convToOutputCharset($this->emetteur->name).' '.$outputlangs->transnoentities('SendTo').':',0,'L',0);
-	                    $posy=$pdf->GetY()+1;
-
-	                    $pdf->SetXY($this->marge_gauche, $posy);
-	                    $pdf->SetFont('','', $default_font_size - 2);
-	                    $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
-	                    $posy=$pdf->GetY()+2;
-	                }
-	            }
-	        }
-
-	        // If payment mode not forced or forced to VIR, show payment with BAN
-	        if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')
-	        {
-	            if (! empty($conf->global->FACTURE_RIB_NUMBER))
-	            {
-	                $account = new Account($this->db);
-	                $account->fetch($conf->global->FACTURE_RIB_NUMBER);
-
-	                $curx=$this->marge_gauche;
-	                $cury=$posy;
-
-	                $posy=pdf_bank($pdf,$outputlangs,$curx,$cury,$account);
-
-	                $posy+=2;
-	            }
-	        }
-*/
-	    }
 	    return $posy;
 	}
 
@@ -652,7 +676,7 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 				$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
 				$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalLT1".$mysoc->country_code), 0, 'L', 1);
 				$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
-				$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax1), 0, 'R', 1);
+				$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax1), $useborder, 'R', 1);
 			}
 
 			// Total LocalTax2
@@ -662,7 +686,7 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 				$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
 				$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalLT2".$mysoc->country_code), 0, 'L', 1);
 				$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
-				$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax2), 0, 'R', 1);
+				$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax2), $useborder, 'R', 1);
 			}
 		}
 		else
@@ -746,14 +770,16 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 
 		if ($deja_regle > 0)
 		{
-			$index++;
+			// Already paid + Deposits
+		    $index++;
 
 			$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
 			$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid"), 0, 'L', 0);
-
 			$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
 			$pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle), 0, 'R', 0);
 
+			$resteapayer = $object->total_ttc - $deja_regle;
+
 			$index++;
 			$pdf->SetTextColor(0,0,60);
 			$pdf->SetFillColor(224,224,224);
@@ -762,6 +788,7 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 
 			$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
 			$pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer), $useborder, 'R', 1);
+
 			$pdf->SetFont('','', $default_font_size - 1);
 			$pdf->SetTextColor(0,0,0);
 		}
@@ -859,15 +886,23 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 		// Do not add the BACKGROUND as this is for suppliers
 		//pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
 
+		//Affiche le filigrane brouillon - Print Draft Watermark
+		/*if($object->statut==0 && (! empty($conf->global->COMMANDE_DRAFT_WATERMARK)) )
+		{
+            pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->COMMANDE_DRAFT_WATERMARK);
+		}*/
+		//Print content
+
 		$pdf->SetTextColor(0,0,60);
 		$pdf->SetFont('','B',$default_font_size + 3);
 
-		$posy=$this->marge_haute;
 		$posx=$this->page_largeur-$this->marge_droite-100;
+		$posy=$this->marge_haute;
 
 		$pdf->SetXY($this->marge_gauche,$posy);
 
 		// Logo
+		/*
 		$logo=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
 		if ($mysoc->logo)
 		{
@@ -885,33 +920,33 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 			}
 		}
 		else
-		{
+		{*/
 			$text=$this->emetteur->name;
 			$pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
-		}
+		//}
 
-		$pdf->SetFont('','B',$default_font_size + 3);
+		$pdf->SetFont('', 'B', $default_font_size + 3);
 		$pdf->SetXY($posx,$posy);
 		$pdf->SetTextColor(0,0,60);
 		$title=$outputlangs->transnoentities("SupplierOrder");
 		$pdf->MultiCell(100, 3, $title, '', 'R');
 
-		$pdf->SetFont('','B',$default_font_size);
+		$pdf->SetFont('', 'B', $default_font_size + 2);
 
-		$posy+=5;
+		$posy+=6;
 		$pdf->SetXY($posx,$posy);
 		$pdf->SetTextColor(0,0,60);
 		$pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->ref), '', 'R');
 
-		$posy+=1;
+		$posy+=2;
 		$pdf->SetFont('','', $default_font_size -1);
 
-        $posy+=4;
+        $posy+=5;
 		$pdf->SetXY($posx,$posy);
 		if ($object->date_commande)
 		{
 			$pdf->SetTextColor(0,0,60);
-			$pdf->MultiCell(100, 4, $outputlangs->transnoentities("Date")." : " . dol_print_date($object->date_commande,"day",false,$outputlangs,true), '', 'R');
+			$pdf->MultiCell(100, 4, $outputlangs->transnoentities("OrderDate")." : " . dol_print_date($object->date_commande,"day",false,$outputlangs,true), '', 'R');
 		}
 		else
 		{
@@ -919,6 +954,8 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 			$pdf->MultiCell(100, 4, strtolower($outputlangs->transnoentities("OrderToProcess")), '', 'R');
 		}
 
+		$posy+=2;
+
 		if ($showaddress)
 		{
 			// Sender properties
@@ -946,13 +983,13 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 			$pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
 
 			// Show sender information
-			$pdf->SetXY($posx+2,$posy+8);
+			$pdf->SetXY($posx+2,$posy+4+(dol_nboflines_bis($this->emetteur->name,44)*4));
 			$pdf->SetFont('','', $default_font_size - 1);
 			$pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
 
 
 
-			// If BILLING contact defined on invoice, we use it
+			// If BILLING contact defined on order, we use it
 			$usecontact=false;
 			$arrayidcontact=$object->getIdContact('internal','BILLING');
 			if (count($arrayidcontact) > 0)