From e9b25e506e54eb3675c52777b5d80595b7504aa4 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@users.sourceforge.net>
Date: Thu, 25 May 2006 20:07:09 +0000
Subject: [PATCH] =?UTF-8?q?Fix:=20Acc=E8s=20=E0=20l'onglet=20pour=20passer?=
 =?UTF-8?q?=20une=20commande=20=E0=20facturer=20n'=E9tait=20pas=20possible?=
 =?UTF-8?q?=20si=20module=20compta=20non=20actif.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 htdocs/commande/commande.class.php            |  6 ++---
 htdocs/commande/liste.php                     | 11 ++++++---
 htdocs/compta/commande/fiche.php              | 24 +++++++++++++++----
 htdocs/compta/commande/liste.php              |  2 +-
 .../menus/barre_left/eldy_backoffice.php      |  2 +-
 htdocs/lib/order.lib.php                      |  3 ++-
 6 files changed, 35 insertions(+), 13 deletions(-)

diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php
index e9d2da60461..7b336d35692 100644
--- a/htdocs/commande/commande.class.php
+++ b/htdocs/commande/commande.class.php
@@ -643,7 +643,7 @@ class Commande
 	{
 		$sql = 'SELECT c.rowid, c.date_creation, c.ref, c.fk_soc, c.fk_user_author, c.fk_statut, c.amount_ht, c.total_ht, c.total_ttc, c.tva, c.fk_cond_reglement, c.fk_mode_reglement,';
 		$sql.= ' '.$this->db->pdate('c.date_commande').' as date_commande, '.$this->db->pdate('c.date_livraison').' as date_livraison,';
-		$sql.= ' c.fk_projet, c.remise_percent, c.remise, c.remise_absolue, c.source, c.facture, c.note, c.note_public, c.ref_client, c.model_pdf, c.fk_adresse_livraison';
+		$sql.= ' c.fk_projet, c.remise_percent, c.remise, c.remise_absolue, c.source, c.facture as facturee, c.note, c.note_public, c.ref_client, c.model_pdf, c.fk_adresse_livraison';
 		$sql.= ' FROM '.MAIN_DB_PREFIX.'commande as c';
 		$sql.= ' WHERE c.rowid = '.$id;
 
@@ -666,7 +666,7 @@ class Commande
 			$this->remise_percent       = $obj->remise_percent;
 			$this->remise_absolue       = $obj->remise_absolue;
 			$this->source               = $obj->source;
-			$this->facturee             = $obj->facture;
+			$this->facturee             = $obj->facturee;
 			$this->note                 = $obj->note;
 			$this->note_public          = $obj->note_public;
 			$this->projet_id            = $obj->fk_projet;
@@ -1723,7 +1723,7 @@ class Commande
 	 */
 	function getLibStatut($mode)
 	{
-		return $this->LibStatut($this->statut,$this->facture,$mode);
+		return $this->LibStatut($this->statut,$this->facturee,$mode);
 	}
 
 	/**
diff --git a/htdocs/commande/liste.php b/htdocs/commande/liste.php
index c4b18f6ebc4..71b8f233c7f 100644
--- a/htdocs/commande/liste.php
+++ b/htdocs/commande/liste.php
@@ -50,6 +50,10 @@ if ($user->societe_id > 0)
 }
 
 
+/*
+ * Affichage page
+ */
+ 
 llxHeader();
 
 $begin=$_GET['begin'];
@@ -62,7 +66,8 @@ if (! $sortorder) $sortorder='DESC';
 $limit = $conf->liste_limit;
 $offset = $limit * $_GET['page'] ;
 
-$sql = 'SELECT s.nom, s.idp, c.rowid, c.ref, c.total_ht,'.$db->pdate('c.date_commande').' as date_commande, c.fk_statut';
+$sql = 'SELECT s.nom, s.idp, c.rowid, c.ref, c.total_ht,';
+$sql.= ' '.$db->pdate('c.date_commande').' as date_commande, c.fk_statut, c.facture as facturee';
 if (!$user->rights->commercial->client->voir && !$socidp) $sql .= ", sc.fk_soc, sc.fk_user";
 $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'commande as c';
 if (!$user->rights->commercial->client->voir && !$socidp) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
@@ -95,7 +100,7 @@ if (isset($_GET['status']))
 {
 	$sql .= " AND fk_statut = ".$_GET['status'];
 }
-if (isset($_GET['afacturer']))
+if (isset($_GET['afacturer']) && $_GET['afacturer'] == 1)
 {
 	$sql .= ' AND c.facture = 0';
 }
@@ -178,7 +183,7 @@ if ($resql)
 		print strftime('%Y',$objp->date_commande).'</a>';
 		if (($objp->fk_statut > 0) && ($objp->fk_statut < 3) && $objp->date_commande < (time() - $conf->commande->warning_delay)) print img_picto($langs->trans("Late"),"warning");
 		print '</td>';
-		print '<td align="right">'.$generic_commande->LibStatut($objp->fk_statut,5).'</td>';
+		print '<td align="right">'.$generic_commande->LibStatut($objp->fk_statut,$objp->facturee,5).'</td>';
 		print '</tr>';
 		$total = $total + $objp->price;
 		$subtotal = $subtotal + $objp->price;
diff --git a/htdocs/compta/commande/fiche.php b/htdocs/compta/commande/fiche.php
index dd5e8ce48b3..73548222616 100644
--- a/htdocs/compta/commande/fiche.php
+++ b/htdocs/compta/commande/fiche.php
@@ -126,10 +126,22 @@ if ($_GET["id"] > 0)
 
 			// Soci�t�
 			print '<tr><td>'.$langs->trans('Company').'</td>';
-			print '<td colspan="2">';
+			print '<td colspan="3">';
 			print '<a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$soc->id.'">'.$soc->nom.'</a></td>';
 			print '</tr>';
 
+			// Ligne info remises tiers
+            print '<tr><td>'.$langs->trans('Info').'</td><td colspan="3">';
+			if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client);
+			else print $langs->trans("CompanyHasNoRelativeDiscount");
+			$aboslute_discount=$soc->getCurrentDiscount();
+			print '. ';
+			if ($aboslute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount);
+			else print $langs->trans("CompanyHasNoAbsoluteDiscount");
+			print '.';
+			print '</td></tr>';
+    
+			// Date
 			print '<tr><td>'.$langs->trans('Date').'</td>';
 			print '<td colspan="2">'.dolibarr_print_date($commande->date,'%A %d %B %Y').'</td>';
 			print '<td width="50%">'.$langs->trans('Source').' : ' . $commande->sources[$commande->source] ;
@@ -373,7 +385,9 @@ if ($_GET["id"] > 0)
 			 * Lignes de remise
 			 */
 			
-			// Remise relative
+    		// R�ductions relatives (Remises-Ristournes-Rabbais)
+/* Une r�duction doit s'appliquer obligatoirement sur des lignes de factures
+   et non globalement
 			$var=!$var;
 			print '<form name="updateligne" action="'.$_SERVER["PHP_SELF"].'" method="post">';
 			print '<input type="hidden" name="action" value="setremisepercent">';
@@ -427,8 +441,10 @@ if ($_GET["id"] > 0)
 			}
 			print '</tr>';
 			print '</form>';
+*/
 
-			// Remise absolue
+	        // R�ductions (Remises-Ristournes-Rabbais)
+/* Les remises absolues doivent s'appliquer par ajout de lignes sp�cialis�es
 			$var=!$var;
 			print '<form name="updateligne" action="'.$_SERVER["PHP_SELF"].'" method="post">';
 			print '<input type="hidden" name="action" value="setremiseabsolue">';
@@ -479,7 +495,7 @@ if ($_GET["id"] > 0)
 			}
 			print '</tr>';
 			print '</form>';
-
+*/
 
         print '</table>';
 
diff --git a/htdocs/compta/commande/liste.php b/htdocs/compta/commande/liste.php
index d8325a0a0a7..d4f5e407286 100644
--- a/htdocs/compta/commande/liste.php
+++ b/htdocs/compta/commande/liste.php
@@ -77,7 +77,7 @@ if (isset($_GET["status"]))
 {
     $sql .= " AND fk_statut = ".$_GET["status"];
 }
-if (isset($_GET["afacturer"]))
+if (isset($_GET["afacturer"]) && $_GET['afacturer'] == 1)
 {
     $sql .= " AND fk_statut >=1	AND c.facture = 0";
 }
diff --git a/htdocs/includes/menus/barre_left/eldy_backoffice.php b/htdocs/includes/menus/barre_left/eldy_backoffice.php
index 6ff5951489e..4e9b8ea65ba 100644
--- a/htdocs/includes/menus/barre_left/eldy_backoffice.php
+++ b/htdocs/includes/menus/barre_left/eldy_backoffice.php
@@ -333,7 +333,7 @@ class MenuLeft {
                 if ($conf->commande->enabled ) 
                 {
                   $langs->load("orders");
-                  if ($conf->facture->enabled) $newmenu->add(DOL_URL_ROOT."/compta/commande/liste.php?leftmenu=orders&status=3", $langs->trans("MenuOrdersToBill"), 0, $user->rights->commande->lire);
+                  if ($conf->facture->enabled) $newmenu->add(DOL_URL_ROOT."/compta/commande/liste.php?leftmenu=orders&status=3&afacturer=1", $langs->trans("MenuOrdersToBill"), 0, $user->rights->commande->lire);
 //                  if ($leftmenu=="orders") $newmenu->add_submenu(DOL_URL_ROOT."/commande/", $langs->trans("StatusOrderToBill"), 1 ,$user->rights->commande->lire);
                 }
 
diff --git a/htdocs/lib/order.lib.php b/htdocs/lib/order.lib.php
index e6e677f58fe..acfcc86fbd6 100644
--- a/htdocs/lib/order.lib.php
+++ b/htdocs/lib/order.lib.php
@@ -53,7 +53,8 @@ function commande_prepare_head($commande)
         $h++;
     }
 
-    if ($conf->compta->enabled || $conf->comptaexpert->enabled)
+    // Commande � facturer
+    if ($conf->facture->enabled)
     {
         $head[$h][0] = DOL_URL_ROOT.'/compta/commande/fiche.php?id='.$commande->id;
         $head[$h][1] = $langs->trans("ComptaCard");
-- 
GitLab