From 3465ecad0f481e5634cf430bdadbde2eaa83ed93 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@users.sourceforge.net>
Date: Sun, 14 Jun 2009 17:48:08 +0000
Subject: [PATCH] Use contact if defined by default  for address instead of
 third party.

---
 htdocs/admin/commande.php                     |  4 +-
 htdocs/admin/facture.php                      |  2 +
 htdocs/admin/propale.php                      |  2 +
 .../modules/commande/pdf_edison.modules.php   | 72 ++++++++++++++++---
 .../modules/commande/pdf_einstein.modules.php |  6 +-
 .../pdf/pdf_expedition_merou.modules.php      |  4 +-
 .../pdf/pdf_expedition_rouget.modules.php     |  3 +-
 .../modules/facture/pdf_crabe.modules.php     |  6 +-
 .../modules/facture/pdf_oursin.modules.php    |  6 +-
 .../propale/pdf_propale_azur.modules.php      | 10 +--
 .../propale/pdf_propale_jaune.modules.php     | 10 +--
 11 files changed, 91 insertions(+), 34 deletions(-)

diff --git a/htdocs/admin/commande.php b/htdocs/admin/commande.php
index c7bd0d112b3..92c83a1ac36 100644
--- a/htdocs/admin/commande.php
+++ b/htdocs/admin/commande.php
@@ -104,7 +104,7 @@ if ($_GET["action"] == 'del')
 	$sql.= " WHERE nom = '".$_GET["value"];
 	$sql.= " AND type = '".$type."'";
 	$sql.= " AND entity = ".$conf->entity;
-	
+
 	if ($db->query($sql))
 	{
 
@@ -447,6 +447,7 @@ print '</form>';
 */
 
 // Utiliser le contact de la commande dans le document
+/*
 $var=! $var;
 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
@@ -457,6 +458,7 @@ print '<td width="60" align="center">'.$html->selectyesno("use_customer_contact_
 print '<td align="right"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
 print '</tr>';
 print '</form>';
+*/
 
 $var=! $var;
 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
diff --git a/htdocs/admin/facture.php b/htdocs/admin/facture.php
index 2c819d1885d..d3ab550b58d 100644
--- a/htdocs/admin/facture.php
+++ b/htdocs/admin/facture.php
@@ -597,6 +597,7 @@ print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">'
 print "</td></tr>\n";
 print '</form>';
 
+/*
 $var=! $var;
 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
@@ -609,6 +610,7 @@ print '</td><td align="right">';
 print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
 print "</td></tr>\n";
 print '</form>';
+*/
 
 $var=! $var;
 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
diff --git a/htdocs/admin/propale.php b/htdocs/admin/propale.php
index a8e94cdd061..cab744ef8b7 100644
--- a/htdocs/admin/propale.php
+++ b/htdocs/admin/propale.php
@@ -435,6 +435,7 @@ print '<td align="right"><input type="submit" class="button" value="'.$langs->tr
 print '</tr>';
 print '</form>';
 
+/*
 $var=! $var;
 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
@@ -447,6 +448,7 @@ print '</td><td align="right">';
 print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
 print "</td></tr>\n";
 print '</form>';
+*/
 
 if ($conf->commande->enabled)
 {
diff --git a/htdocs/includes/modules/commande/pdf_edison.modules.php b/htdocs/includes/modules/commande/pdf_edison.modules.php
index 524db2e7a05..3776156e141 100644
--- a/htdocs/includes/modules/commande/pdf_edison.modules.php
+++ b/htdocs/includes/modules/commande/pdf_edison.modules.php
@@ -347,13 +347,13 @@ class pdf_edison extends ModelePDFCommandes
 	}
 
 
-	function _pagehead(&$pdf, $com, $showaddress=1, $outputlangs)
+	function _pagehead(&$pdf, $object, $showaddress=1, $outputlangs)
 	{
 		global $conf,$langs,$mysoc;
 		$langs->load("orders");
 
 		//Affiche le filigrane brouillon - Print Draft Watermark
-		if($com->statut==0 && (! empty($conf->global->COMMANDE_DRAFT_WATERMARK)) )
+		if($object->statut==0 && (! empty($conf->global->COMMANDE_DRAFT_WATERMARK)) )
 		{
 			$watermark_angle=atan($this->page_hauteur/$this->page_largeur);
 			$watermark_x=5;
@@ -421,23 +421,75 @@ class pdf_edison extends ModelePDFCommandes
 		$pdf->MultiCell(80, 4, $carac_emetteur);
 
 		// Client destinataire
+		$client = new Societe($this->db);
+		$client->fetch($object->socid);
+		$object->client = $client;
+
+		// If CUSTOMER contact defined on invoice, we use it
+		$usecontact=false;
+		//if ($conf->global->COMMANDE_USE_CUSTOMER_CONTACT_AS_RECIPIENT)
+		//{
+			$arrayidcontact=$object->getIdContact('external','CUSTOMER');
+			if (sizeof($arrayidcontact) > 0)
+			{
+				$usecontact=true;
+				$result=$object->fetch_contact($arrayidcontact[0]);
+			}
+		//}
+
+		if ($usecontact)
+		{
+			// Nom societe
+			$carac_client_name=$outputlangs->convToOutputCharset($object->client->nom);
+
+			// Customer name
+			$carac_client = "\n".$object->contact->getFullName($outputlangs,1,1);
+
+			// Customer properties
+			$carac_client.="\n".$outputlangs->convToOutputCharset($object->contact->address);
+			$carac_client.="\n".$outputlangs->convToOutputCharset($object->contact->cp) . " " . $outputlangs->convToOutputCharset($object->contact->ville)."\n";
+			if ($object->contact->pays_code != $this->emetteur->pays_code) $carac_client.=$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$object->contact->pays_code))."\n";
+		}
+		else
+		{
+			// Customer name
+			$carac_client_name=$outputlangs->convToOutputCharset($object->client->nom);
+
+			// Nom du contact suivi commande si c'est une soci�t�
+			$arrayidcontact = $object->getIdContact('external','CUSTOMER');
+			if (sizeof($arrayidcontact) > 0)
+			{
+				$object->fetch_contact($arrayidcontact[0]);
+				// On verifie si c'est une societe ou un particulier
+				if( !preg_match('#'.$object->contact->getFullName($outputlangs,1).'#isU',$object->client->nom) )
+				{
+					$carac_client .= "\n".$object->contact->getFullName($outputlangs,1,1);
+				}
+			}
+
+			// Caracteristiques client
+			$carac_client.="\n".$outputlangs->convToOutputCharset($object->client->adresse);
+			$carac_client.="\n".$outputlangs->convToOutputCharset($object->client->cp) . " " . $outputlangs->convToOutputCharset($object->client->ville)."\n";
+			if ($object->client->pays_code != $this->emetteur->pays_code) $carac_client.=$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$object->client->pays_code))."\n";
+		}
+		// Numero TVA intracom
+		if ($object->client->tva_intra) $carac_client.="\n".$outputlangs->transnoentities("VATIntraShort").': '.$outputlangs->convToOutputCharset($object->client->tva_intra);
+
+		// Show customer/recipient
 		$pdf->SetTextColor(0,0,0);
 		$pdf->SetFont('Arial','B',12);
-		$client = new Societe($this->db);
-		$client->fetch($com->socid);
-		$com->client = $client;
 		$pdf->SetXY(102,42);
-		$pdf->MultiCell(96, 5, $outputlangs->convToOutputCharset($com->client->nom));
+		$pdf->MultiCell(96, 5, $carac_client_name);
 		$pdf->SetFont('Arial','',11);
 		$pdf->SetXY(102,$pdf->GetY());
-		$pdf->MultiCell(96, 5, $outputlangs->convToOutputCharset($com->client->adresse) . "\n" . $outputlangs->convToOutputCharset($com->client->cp) . " " . $outputlangs->convToOutputCharset($com->client->ville));
-		$pdf->rect(100, 40, 100, 40);
+		$pdf->MultiCell(96, 5, $carac_client);
 
+		$pdf->rect(100, 40, 100, 40);
 
 		$pdf->SetTextColor(200,0,0);
 		$pdf->SetFont('Arial','B',12);
-		$pdf->Text(11, 88, $outputlangs->transnoentities("Date")." : " . dol_print_date($com->date,'day',false,$outputlangs));
-		$pdf->Text(11, 94, $outputlangs->transnoentities("Order")." ".$outputlangs->convToOutputCharset($com->ref));
+		$pdf->Text(11, 88, $outputlangs->transnoentities("Date")." : " . dol_print_date($object->date,'day',false,$outputlangs));
+		$pdf->Text(11, 94, $outputlangs->transnoentities("Order")." ".$outputlangs->convToOutputCharset($object->ref));
 	}
 
     /*
diff --git a/htdocs/includes/modules/commande/pdf_einstein.modules.php b/htdocs/includes/modules/commande/pdf_einstein.modules.php
index a7f24d9f465..0399fc2a192 100644
--- a/htdocs/includes/modules/commande/pdf_einstein.modules.php
+++ b/htdocs/includes/modules/commande/pdf_einstein.modules.php
@@ -827,15 +827,15 @@ class pdf_einstein extends ModelePDFCommandes
 
 			// If CUSTOMER contact defined on invoice, we use it
 			$usecontact=false;
-			if ($conf->global->COMMANDE_USE_CUSTOMER_CONTACT_AS_RECIPIENT)
-			{
+			//if ($conf->global->COMMANDE_USE_CUSTOMER_CONTACT_AS_RECIPIENT)
+			//{
 				$arrayidcontact=$object->getIdContact('external','CUSTOMER');
 				if (sizeof($arrayidcontact) > 0)
 				{
 					$usecontact=true;
 					$result=$object->fetch_contact($arrayidcontact[0]);
 				}
-			}
+			//}
 
 			if ($usecontact)
 			{
diff --git a/htdocs/includes/modules/expedition/pdf/pdf_expedition_merou.modules.php b/htdocs/includes/modules/expedition/pdf/pdf_expedition_merou.modules.php
index 4030bb232d8..7e11233a22c 100644
--- a/htdocs/includes/modules/expedition/pdf/pdf_expedition_merou.modules.php
+++ b/htdocs/includes/modules/expedition/pdf/pdf_expedition_merou.modules.php
@@ -483,9 +483,7 @@ Class pdf_expedition_merou extends ModelePdfExpedition
 
 		$object->fetch_client();
 
-		/**********************************/
-		//Emplacement Informations Destinataire
-		/**********************************/
+		// If SHIPPING contact defined on invoice, we use it
 		$usecontact=false;
 		//if ($conf->global->FACTURE_USE_BILL_CONTACT_AS_RECIPIENT)
 		//{
diff --git a/htdocs/includes/modules/expedition/pdf/pdf_expedition_rouget.modules.php b/htdocs/includes/modules/expedition/pdf/pdf_expedition_rouget.modules.php
index 68cb51cfdd3..76a7793f26c 100644
--- a/htdocs/includes/modules/expedition/pdf/pdf_expedition_rouget.modules.php
+++ b/htdocs/includes/modules/expedition/pdf/pdf_expedition_rouget.modules.php
@@ -75,7 +75,8 @@ Class pdf_expedition_rouget extends ModelePdfExpedition
 	 */
 	function _pagehead(&$pdf, $object, $showadress=1, $outputlangs)
 	{
-		global $conf;
+		global $conf,$langs,$mysoc;
+		$langs->load("orders");
 
 		if ($conf->barcode->enabled)
 		{
diff --git a/htdocs/includes/modules/facture/pdf_crabe.modules.php b/htdocs/includes/modules/facture/pdf_crabe.modules.php
index 2a2cf3e2263..dec54dd21b8 100644
--- a/htdocs/includes/modules/facture/pdf_crabe.modules.php
+++ b/htdocs/includes/modules/facture/pdf_crabe.modules.php
@@ -1104,15 +1104,15 @@ class pdf_crabe extends ModelePDFFactures
 
 			// If BILLING contact defined on invoice, we use it
 			$usecontact=false;
-			if ($conf->global->FACTURE_USE_BILL_CONTACT_AS_RECIPIENT)
-			{
+			//if ($conf->global->FACTURE_USE_BILL_CONTACT_AS_RECIPIENT)
+			//{
 				$arrayidcontact=$object->getIdContact('external','BILLING');
 				if (sizeof($arrayidcontact) > 0)
 				{
 					$usecontact=true;
 					$result=$object->fetch_contact($arrayidcontact[0]);
 				}
-			}
+			//}
 			if ($usecontact)
 			{
 				// On peut utiliser le nom de la societe du contact
diff --git a/htdocs/includes/modules/facture/pdf_oursin.modules.php b/htdocs/includes/modules/facture/pdf_oursin.modules.php
index 9d8f1e62961..8189ed7a009 100644
--- a/htdocs/includes/modules/facture/pdf_oursin.modules.php
+++ b/htdocs/includes/modules/facture/pdf_oursin.modules.php
@@ -883,15 +883,15 @@ class pdf_oursin extends ModelePDFFactures
 
 		// If BILLING contact defined on invoice, we use it
 		$usecontact=false;
-		if ($conf->global->FACTURE_USE_BILL_CONTACT_AS_RECIPIENT)
-		{
+		//if ($conf->global->FACTURE_USE_BILL_CONTACT_AS_RECIPIENT)
+		//{
 			$arrayidcontact=$object->getIdContact('external','BILLING');
 			if (sizeof($arrayidcontact) > 0)
 			{
 				$usecontact=true;
 				$result=$object->fetch_contact($arrayidcontact[0]);
 			}
-		}
+		//}
 		if ($usecontact)
 		{
 			// On peut utiliser le nom de la societe du contact facturation
diff --git a/htdocs/includes/modules/propale/pdf_propale_azur.modules.php b/htdocs/includes/modules/propale/pdf_propale_azur.modules.php
index 6877cbd55c8..ccdeef7dbee 100644
--- a/htdocs/includes/modules/propale/pdf_propale_azur.modules.php
+++ b/htdocs/includes/modules/propale/pdf_propale_azur.modules.php
@@ -897,19 +897,19 @@ class pdf_propale_azur extends ModelePDFPropales
 			// Cadre client destinataire
 			$pdf->rect(100, $posy, 100, $hautcadre);
 
-
-			// If BILLING contact defined, we use it
 			$pdf->SetTextColor(0,0,0);
+
+			// If CUSTOMER contact defined, we use it
 			$usecontact=false;
-			if ($conf->global->PROPALE_USE_CUSTOMER_CONTACT_AS_RECIPIENT)
-			{
+			//if ($conf->global->PROPALE_USE_CUSTOMER_CONTACT_AS_RECIPIENT)
+			//{
 				$arrayidcontact=$object->getIdContact('external','CUSTOMER');
 				if (sizeof($arrayidcontact) > 0)
 				{
 					$usecontact=true;
 					$result=$object->fetch_contact($arrayidcontact[0]);
 				}
-			}
+			//}
 			if ($usecontact)
 			{
 				// On peut utiliser le nom de la societe du contact
diff --git a/htdocs/includes/modules/propale/pdf_propale_jaune.modules.php b/htdocs/includes/modules/propale/pdf_propale_jaune.modules.php
index 2b4d68df0a5..7b755c8d9bb 100644
--- a/htdocs/includes/modules/propale/pdf_propale_jaune.modules.php
+++ b/htdocs/includes/modules/propale/pdf_propale_jaune.modules.php
@@ -436,19 +436,19 @@ class pdf_propale_jaune extends ModelePDFPropales
 
 		$posy=39;
 
-
-		// If BILLING contact defined, we use it
 		$pdf->SetTextColor(0,0,0);
+
+		// If CUSTOMER contact defined, we use it
 		$usecontact=false;
-		if ($conf->global->PROPALE_USE_CUSTOMER_CONTACT_AS_RECIPIENT)
-		{
+		//if ($conf->global->PROPALE_USE_CUSTOMER_CONTACT_AS_RECIPIENT)
+		//{
 			$arrayidcontact=$object->getIdContact('external','CUSTOMER');
 			if (sizeof($arrayidcontact) > 0)
 			{
 				$usecontact=true;
 				$result=$object->fetch_contact($arrayidcontact[0]);
 			}
-		}
+		//}
 		if ($usecontact)
 		{
 			// Nom societe
-- 
GitLab