From 0b0d672c3a8c70a29b3e47582a7facae18f54f4e Mon Sep 17 00:00:00 2001
From: Regis Houssin <regis@dolibarr.fr>
Date: Mon, 23 May 2011 19:49:27 +0000
Subject: [PATCH] Works on paypal module Fix: add status

---
 htdocs/langs/en_US/paypal.lang   |  3 +++
 htdocs/langs/fr_FR/paypal.lang   |  3 +++
 htdocs/paypal/lib/paypal.lib.php | 33 ++++++++++++++++++++++++++++++++
 htdocs/paypal/transaction.php    | 16 ++++++++++++++--
 4 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/htdocs/langs/en_US/paypal.lang b/htdocs/langs/en_US/paypal.lang
index d524dae162f..6c9dd0da851 100644
--- a/htdocs/langs/en_US/paypal.lang
+++ b/htdocs/langs/en_US/paypal.lang
@@ -26,6 +26,9 @@ GrossAmount=Gross amount
 FeeAmount=Fee amount
 NetAmount=Net amount
 CustomerDetails=Customer details
+NewTransaction=New transaction
+OrderIsCreated=Order created
+InvoiceIsCreated=Invoice created
 
 # Paypal transaction fields
 PAYERID=Payer ID
diff --git a/htdocs/langs/fr_FR/paypal.lang b/htdocs/langs/fr_FR/paypal.lang
index 389f9c6ed37..6d4bd8d2db6 100644
--- a/htdocs/langs/fr_FR/paypal.lang
+++ b/htdocs/langs/fr_FR/paypal.lang
@@ -26,6 +26,9 @@ GrossAmount=Montant brut
 FeeAmount=Frais Paypal
 NetAmount=Montant net
 CustomerDetails=Détail du client
+NewTransaction=Nouveau paiement
+OrderIsCreated=Commande créée
+InvoiceIsCreated=Facture créée
 
 # Paypal transaction fields
 PAYERID=ID du payeur
diff --git a/htdocs/paypal/lib/paypal.lib.php b/htdocs/paypal/lib/paypal.lib.php
index 6574819ad47..a1f1cac097e 100755
--- a/htdocs/paypal/lib/paypal.lib.php
+++ b/htdocs/paypal/lib/paypal.lib.php
@@ -180,6 +180,39 @@ function getLinkedObjects($transactionID)
 	return $objectArray;
 }
 
+/**
+ *		Renvoi le libelle d'un statut donne
+ *    	@param      statut      Id statut
+ *    	@param      mode        0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
+ *    	@param		url			Object url
+ *    	@return     string		Label of status
+ */
+function getLibStatut($statut,$mode,$url)
+{
+	global $langs;
+	
+	$out='';
+	
+	if ($url) $out.= '<a href="'.$url.'">';
+	if ($mode == 0)
+	{
+		if ($statut==-1) $out.= $langs->trans('Undefined');
+		if ($statut==0) $out.= $langs->trans('NewTransaction');
+		if ($statut==1) $out.= $langs->trans('OrderIsCreated');
+		if ($statut==2) $out.= $langs->trans('InvoiceIsCreated');
+	}
+	if ($mode == 1)
+	{
+		if ($statut==-1) $out.= img_picto($langs->trans('Undefined'),'warning');
+		if ($statut==0) $out.= img_picto($langs->trans('NewTransaction'),'statut0');
+		if ($statut==1) $out.= img_picto($langs->trans('OrderIsCreated'),'statut3');
+		if ($statut==2) $out.= img_picto($langs->trans('InvoiceIsCreated'),'statut4');
+	}
+	if ($url) $out.= '</a>';
+	
+	return $out;
+}
+
 /**
  * Send redirect to paypal to browser
  *
diff --git a/htdocs/paypal/transaction.php b/htdocs/paypal/transaction.php
index 5e9a2d84f78..6fc865d9ee2 100644
--- a/htdocs/paypal/transaction.php
+++ b/htdocs/paypal/transaction.php
@@ -305,7 +305,19 @@ else
 		$feeamount		= $resArray["L_FEEAMT".$i];
 		$netamount		= $resArray["L_NETAMT".$i];
 		$currency 		= $resArray["L_CURRENCYCODE".$i];
-		$status			= $resArray["L_STATUS".$i];
+		
+		$status=-1; $url='';
+		if ($resArray["L_STATUS".$i]=='Completed') $status=0;
+		if (! empty($objects['order']))
+		{
+			$status=1;
+			$url=$objects['order']->getNomUrl(0,'',0,1);
+		}
+		if (! empty($objects['invoice']))
+		{
+			$status=2;
+			$url=$objects['invoice']->getNomUrl(0,'',0,1);
+		}
 
 		print '<tr '.$bc[$var].'>';
 		print '<td><div id="'.$transactionID.'" class="paypal_link" style="font-weight:bold;cursor:pointer;">'.$transactionID.'</div></td>';
@@ -314,7 +326,7 @@ else
 		print '<td align="right">'.$amount.' '.$currency.'</td>';
 		print '<td align="right">'.$feeamount.' '.$currency.'</td>';
 		print '<td align="right">'.$netamount.' '.$currency.'</td>';
-		print '<td align="right">'.$status.'</td>';
+		print '<td align="right">'.getLibStatut($status, 1, $url).'</td>';
 		print '</tr>';
 
 		$i++;
-- 
GitLab