瀏覽代碼

Merge branch '4.0' of git@github.com:Dolibarr/dolibarr.git into develop

Conflicts:
	htdocs/expensereport/list.php
	htdocs/fourn/facture/card.php
	htdocs/fourn/facture/list.php
Laurent Destailleur 8 年之前
父節點
當前提交
81a3235cf6

+ 1 - 0
htdocs/admin/ihm.php

@@ -39,6 +39,7 @@ $langs->load("products");
 $langs->load("members");
 $langs->load("projects");
 $langs->load("hrm");
+$langs->load("agenda");
 
 if (! $user->admin) accessforbidden();
 

+ 1 - 0
htdocs/comm/propal/class/propal.class.php

@@ -670,6 +670,7 @@ class Propal extends CommonObject
             //Fetch current line from the database and then clone the object and set it in $oldline property
             $line = new PropaleLigne($this->db);
             $line->fetch($rowid);
+			$line->fetch_optionals(); // Fetch extrafields for oldcopy
 
 			$staticline = clone $line;
 

+ 12 - 11
htdocs/compta/facture/list.php

@@ -133,7 +133,7 @@ $search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search
 $fieldstosearchall = array(
     'f.facnumber'=>'Ref',
     'f.ref_client'=>'RefCustomer',
-    'fd.description'=>'Description',
+    'pd.description'=>'Description',
     's.nom'=>"ThirdParty",
     'f.note_public'=>'NotePublic',
 );
@@ -156,7 +156,7 @@ $arrayfields=array(
     'f.total_ht'=>array('label'=>$langs->trans("AmountHT"), 'checked'=>1),
     'f.total_vat'=>array('label'=>$langs->trans("AmountVAT"), 'checked'=>0),
     'f.total_ttc'=>array('label'=>$langs->trans("AmountTTC"), 'checked'=>0),
-    'am'=>array('label'=>$langs->trans("Received"), 'checked'=>0),
+    'dynamount_payed'=>array('label'=>$langs->trans("Received"), 'checked'=>0),
     'rtp'=>array('label'=>$langs->trans("Rest"), 'checked'=>0),
     'f.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
     'f.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
@@ -253,7 +253,9 @@ $sql.= ' f.datec as date_creation, f.tms as date_update,';
 $sql.= ' s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client, ';
 $sql.= " typent.code as typent_code,";
 $sql.= " state.code_departement as state_code, state.nom as state_name";
-if (! $sall) $sql.= ', SUM(pf.amount) as am';   // To be able to sort on status
+// We need dynamount_payed to be able to sort on status (value is surely wrong because we can count several lines several times due to other left join or link with contacts. But what we need is just 0 or > 0)
+// TODO Better solution to be able to sort on already payed or remain to pay is to store amount_payed in a denormalized field.
+if (! $sall) $sql.= ', SUM(pf.amount) as dynamount_payed';   
 // Add fields from extrafields
 foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
 // Add fields from hooks
@@ -267,7 +269,6 @@ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s
 $sql.= ', '.MAIN_DB_PREFIX.'facture as f';
 if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture_extrafields as ef on (f.rowid = ef.fk_object)";
 if (! $sall) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid';
-else $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet as fd ON fd.fk_facture = f.rowid';
 if ($sall || $search_product_category > 0) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet as pd ON f.rowid=pd.fk_facture';
 if ($search_product_category > 0) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product';
 // We'll need this table joined to the select in order to filter by sale
@@ -655,8 +656,8 @@ if ($resql)
     if (! empty($arrayfields['f.total_ht']['checked']))           print_liste_field_titre($arrayfields['f.total_ht']['label'],$_SERVER['PHP_SELF'],'f.total','',$param,'align="right"',$sortfield,$sortorder);
     if (! empty($arrayfields['f.total_vat']['checked']))          print_liste_field_titre($arrayfields['f.total_vat']['label'],$_SERVER['PHP_SELF'],'f.tva','',$param,'align="right"',$sortfield,$sortorder);
     if (! empty($arrayfields['f.total_ttc']['checked']))          print_liste_field_titre($arrayfields['f.total_ttc']['label'],$_SERVER['PHP_SELF'],'f.total_ttc','',$param,'align="right"',$sortfield,$sortorder);
-    if (! empty($arrayfields['am']['checked']))                   print_liste_field_titre($arrayfields['am']['label'],$_SERVER['PHP_SELF'],'am','',$param,'align="right"',$sortfield,$sortorder);
-	if (! empty($arrayfields['rtp']['checked']))                  print_liste_field_titre($arrayfields['rtp']['label'],$_SERVER['PHP_SELF'],'rtp','',$param,'align="right"',$sortfield,$sortorder);
+    if (! empty($arrayfields['dynamount_payed']['checked']))      print_liste_field_titre($arrayfields['dynamount_payed']['label'],$_SERVER['PHP_SELF'],'','',$param,'align="right"',$sortfield,$sortorder);
+	if (! empty($arrayfields['rtp']['checked']))                  print_liste_field_titre($arrayfields['rtp']['label'],$_SERVER['PHP_SELF'],'','',$param,'align="right"',$sortfield,$sortorder);
     // Extra fields
     if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
     {
@@ -675,7 +676,7 @@ if ($resql)
     print $hookmanager->resPrint;
     if (! empty($arrayfields['f.datec']['checked']))     print_liste_field_titre($arrayfields['f.datec']['label'],$_SERVER["PHP_SELF"],"f.datec","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
     if (! empty($arrayfields['f.tms']['checked']))       print_liste_field_titre($arrayfields['f.tms']['label'],$_SERVER["PHP_SELF"],"f.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
-    if (! empty($arrayfields['f.fk_statut']['checked'])) print_liste_field_titre($arrayfields['f.fk_statut']['label'],$_SERVER["PHP_SELF"],"fk_statut,paye,am","",$param,'align="right"',$sortfield,$sortorder);
+    if (! empty($arrayfields['f.fk_statut']['checked'])) print_liste_field_titre($arrayfields['f.fk_statut']['label'],$_SERVER["PHP_SELF"],"fk_statut,paye,type,dynamount_payed","",$param,'align="right"',$sortfield,$sortorder);
     print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="right"',$sortfield,$sortorder,'maxwidthsearch ');
     print "</tr>\n";
 
@@ -786,7 +787,7 @@ if ($resql)
     	print '<input class="flat" type="text" size="5" name="search_montant_ttc" value="'.$search_montant_ttc.'">';
     	print '</td>';
 	}
-    if (! empty($arrayfields['am']['checked']))
+    if (! empty($arrayfields['dynamount_payed']['checked']))
     {
         print '<td class="liste_titre" align="right">';
         print '</td>';
@@ -1025,9 +1026,9 @@ if ($resql)
     		    $totalarray['totalttc'] += $obj->total_ttc;
             }
 
-            if (! empty($arrayfields['am']['checked']))
+            if (! empty($arrayfields['dynamount_payed']['checked']))
             {
-                print '<td align="right">'.(! empty($paiement)?price($paiement,0,$langs):'&nbsp;').'</td>';
+                print '<td align="right">'.(! empty($paiement)?price($paiement,0,$langs):'&nbsp;').'</td>'; // TODO Use a denormalized field
                 if (! $i) $totalarray['nbfield']++;
     		    if (! $i) $totalarray['totalamfield']=$totalarray['nbfield'];
     		    $totalarray['totalam'] += $paiement;
@@ -1035,7 +1036,7 @@ if ($resql)
 
             if (! empty($arrayfields['rtp']['checked']))
             {
-                print '<td align="right">'.(! empty($remaintopay)?price($remaintopay,0,$langs):'&nbsp;').'</td>';
+                print '<td align="right">'.(! empty($remaintopay)?price($remaintopay,0,$langs):'&nbsp;').'</td>'; // TODO Use a denormalized field
                 if (! $i) $totalarray['nbfield']++;
     		    if (! $i) $totalarray['totalrtpfield']=$totalarray['nbfield'];
     		    $totalarray['totalrtp'] += $remaintopay;

+ 2 - 2
htdocs/compta/paiement/cheque/list.php

@@ -171,7 +171,7 @@ if ($resql)
     print '</td>';
 	print '<td class="liste_titre">&nbsp;</td>';
 	print '<td class="liste_titre" align="right">';
-	print '<input class="flat" type="text" size="6" name="search_amount" value="'.$search_amount.'">';
+	print '<input class="flat maxwidth50" type="text" name="search_amount" value="'.$search_amount.'">';
 	print '</td>';
 	print '<td></td>';
     print '<td class="liste_titre" align="right">';
@@ -190,7 +190,7 @@ if ($resql)
     		print "<tr ".$bc[$var].">";
     
     		// Num ref cheque
-    		print '<td width="80">';
+    		print '<td>';
     		$checkdepositstatic->id=$objp->rowid;
     		$checkdepositstatic->ref=($objp->ref?$objp->ref:$objp->rowid);
     		$checkdepositstatic->statut=$objp->statut;

+ 111 - 55
htdocs/compta/resultat/clientfourn.php

@@ -52,6 +52,17 @@ if ($user->societe_id > 0) $socid = $user->societe_id;
 if (! empty($conf->comptabilite->enabled)) $result=restrictedArea($user,'compta','','','resultat');
 if (! empty($conf->accounting->enabled)) $result=restrictedArea($user,'accounting','','','comptarapport');
 
+$limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit;
+$sortfield = GETPOST("sortfield",'alpha');
+$sortorder = GETPOST("sortorder",'alpha');
+$page = GETPOST("page",'int');
+if ($page == -1) { $page = 0; }
+$offset = $limit * $page;
+$pageprev = $page - 1;
+$pagenext = $page + 1;
+if (! $sortfield) $sortfield='s.nom, s.rowid';
+if (! $sortorder) $sortorder='ASC';
+
 // Date range
 $year=GETPOST("year");
 if (empty($year))
@@ -155,12 +166,23 @@ if (! empty($conf->accounting->enabled))
 }
 
 // Show report array
+$param='&modecompta='.$modecompta;
+if ($date_startday) $param.='&date_startday='.$date_startday;
+if ($date_startmonth) $param.='&date_startmonth='.$date_startmonth;
+if ($date_startyear) $param.='&date_startyear='.$date_startyear;
+if ($date_endday) $param.='&date_endday='.$date_endday;
+if ($date_endmonth) $param.='&date_endmonth='.$date_endmonth;
+if ($date_endyear) $param.='&date_endyear='.$date_startyear;
+
 print '<table class="noborder" width="100%">';
 print '<tr class="liste_titre">';
-print '<td width="10%">&nbsp;</td><td>&nbsp;</td>';
+print_liste_field_titre('');
+print_liste_field_titre($langs->trans("Name"), $_SERVER["PHP_SELF"],'s.nom, s.rowid','',$param,'',$sortfield,$sortorder);
 if ($modecompta == 'CREANCES-DETTES')
-	print "<td align=\"right\">".$langs->trans("AmountHT")."</td>";
-print "<td align=\"right\">".$langs->trans("AmountTTC")."</td>";
+{
+	print_liste_field_titre($langs->trans("AmountHT"), $_SERVER["PHP_SELF"],'amount_ht','',$param,'align="right"',$sortfield,$sortorder);
+}
+print_liste_field_titre($langs->trans("AmountTTC"), $_SERVER["PHP_SELF"],'amount_ttc','',$param,'align="right"',$sortfield,$sortorder);
 print "</tr>\n";
 
 /*
@@ -202,7 +224,7 @@ else
 $sql.= " AND f.entity = ".$conf->entity;
 if ($socid) $sql.= " AND f.fk_soc = ".$socid;
 $sql.= " GROUP BY s.nom, s.rowid";
-$sql.= " ORDER BY s.nom, s.rowid";
+$sql.= $db->order($sortfield, $sortorder);
 
 dol_syslog("get customer invoices", LOG_DEBUG);
 $result = $db->query($sql);
@@ -328,7 +350,7 @@ else
 $sql.= " AND f.entity = ".$conf->entity;
 if ($socid) $sql.= " AND f.fk_soc = ".$socid;
 $sql .= " GROUP BY s.nom, s.rowid";
-$sql .= " ORDER BY s.nom, s.rowid";
+$sql.= $db->order($sortfield, $sortorder);
 
 print '<tr><td colspan="4">'.$langs->trans("SuppliersInvoices").'</td></tr>';
 
@@ -413,7 +435,11 @@ else
 }
 $sql.= " AND cs.entity = ".$conf->entity;
 $sql.= " GROUP BY c.libelle, c.id";
-$sql.= " ORDER BY c.libelle, c.id";
+$newsortfield = $sortfield;
+if ($newsortfield == 's.nom, s.rowid') $newsortfield = 'c.libelle, c.id';
+if ($newsortfield == 'amount_ht') $newsortfield = 'amount';
+if ($newsortfield == 'amount_ttc') $newsortfield = 'amount';
+$sql.= $db->order($newsortfield, $sortorder);
 
 dol_syslog("get social contributions deductible=0", LOG_DEBUG);
 $result=$db->query($sql);
@@ -473,8 +499,6 @@ if ($modecompta == 'CREANCES-DETTES')
     if (! empty($date_start) && ! empty($date_end))
     	$sql.= " AND cs.date_ech >= '".$db->idate($date_start)."' AND cs.date_ech <= '".$db->idate($date_end)."'";
     $sql.= " AND cs.entity = ".$conf->entity;
-    $sql.= " GROUP BY c.libelle, c.id";
-    $sql.= " ORDER BY c.libelle, c.id";
 }
 else
 {
@@ -488,9 +512,13 @@ else
     if (! empty($date_start) && ! empty($date_end))
     	$sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
     $sql.= " AND cs.entity = ".$conf->entity;
-    $sql.= " GROUP BY c.libelle, c.id";
-    $sql.= " ORDER BY c.libelle, c.id";
 }
+$sql.= " GROUP BY c.libelle, c.id";
+$newsortfield = $sortfield;
+if ($newsortfield == 's.nom, s.rowid') $newsortfield = 'c.libelle, c.id';
+if ($newsortfield == 'amount_ht') $newsortfield = 'amount';
+if ($newsortfield == 'amount_ttc') $newsortfield = 'amount';
+$sql.= $db->order($newsortfield, $sortorder);
 
 dol_syslog("get social contributions deductible=1", LOG_DEBUG);
 $result=$db->query($sql);
@@ -574,8 +602,12 @@ if (! empty($conf->salaries->enabled))
 		$sql.= " AND $column >= '".$db->idate($date_start)."' AND $column <= '".$db->idate($date_end)."'";
 
 	$sql.= " GROUP BY u.rowid, u.firstname, u.lastname, p.fk_user, p.label, dm";
-	$sql.= " ORDER BY u.firstname";
-
+	$newsortfield = $sortfield;
+    if ($newsortfield == 's.nom, s.rowid') $newsortfield = 'u.firstname, u.lastname';
+    if ($newsortfield == 'amount_ht') $newsortfield = 'amount';
+    if ($newsortfield == 'amount_ttc') $newsortfield = 'amount';
+	$sql.= $db->order($newsortfield, $sortorder);
+	
 	dol_syslog("get payment salaries");
 	$result=$db->query($sql);
 	$subtotal_ht = 0;
@@ -642,7 +674,7 @@ if (! empty($conf->expensereport->enabled))
 
 		$column='p.date_valid';
 	} else {
-		$sql = "SELECT p.rowid, p.ref, u.rowid as userid, u.firstname, u.lastname, date_format(pe.datep,'%Y-%m') as dm, sum(p.total_ht) as amount_ht,sum(p.total_ttc) as amount_ttc";
+		$sql = "SELECT p.rowid, p.ref, u.rowid as userid, u.firstname, u.lastname, date_format(pe.datep,'%Y-%m') as dm, sum(p.total_ht) as amount_ht, sum(p.total_ttc) as amount_ttc";
 		$sql.= " FROM ".MAIN_DB_PREFIX."expensereport as p";
 		$sql.= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid=p.fk_user_author";
 		$sql.= " INNER JOIN ".MAIN_DB_PREFIX."payment_expensereport as pe ON pe.fk_expensereport = p.rowid";
@@ -656,55 +688,59 @@ if (! empty($conf->expensereport->enabled))
 	print '<tr><td colspan="4">'.$langs->trans("ExpenseReport").'</td></tr>';
 
 	if (! empty($date_start) && ! empty($date_end))
+	{
 		$sql.= " AND $column >= '".$db->idate($date_start)."' AND $column <= '".$db->idate($date_end)."'";
+	}
+	
+	$sql.= " GROUP BY u.rowid, p.rowid, p.ref, u.firstname, u.lastname, dm";
+    $newsortfield = $sortfield;
+    if ($newsortfield == 's.nom, s.rowid') $newsortfield = 'p.ref';
+    $sql.= $db->order($newsortfield, $sortorder);
 
-		$sql.= " GROUP BY u.rowid, p.rowid, p.ref, u.firstname, u.lastname, dm";
-		$sql.= " ORDER BY p.ref";
-
-		dol_syslog("get expense report outcome");
-		$result=$db->query($sql);
-		$subtotal_ht = 0;
-		$subtotal_ttc = 0;
-		if ($result)
+	dol_syslog("get expense report outcome");
+	$result=$db->query($sql);
+	$subtotal_ht = 0;
+	$subtotal_ttc = 0;
+	if ($result)
+	{
+		$num = $db->num_rows($result);
+		$var=true;
+		if ($num)
 		{
-			$num = $db->num_rows($result);
-			$var=true;
-			if ($num)
-			{
-				while ($obj = $db->fetch_object($result))
-				{
-					$total_ht -= $obj->amount_ht;
-					$total_ttc -= $obj->amount_ttc;
-					$subtotal_ht += $obj->amount_ht;
-					$subtotal_ttc += $obj->amount_ttc;
-
-					$var = !$var;
-					print "<tr ".$bc[$var]."><td>&nbsp;</td>";
-
-					print "<td>".$langs->trans("ExpenseReport")." <a href=\"".DOL_URL_ROOT."/expensereport/list.php?search_user=".$obj->userid."\">".$obj->firstname." ".$obj->lastname."</a></td>\n";
-
-					if ($modecompta == 'CREANCES-DETTES') print '<td align="right">'.price(-$obj->amount_ht).'</td>';
-					print '<td align="right">'.price(-$obj->amount_ttc).'</td>';
-					print '</tr>';
-				}
-			}
-			else
+			while ($obj = $db->fetch_object($result))
 			{
+				$total_ht -= $obj->amount_ht;
+				$total_ttc -= $obj->amount_ttc;
+				$subtotal_ht += $obj->amount_ht;
+				$subtotal_ttc += $obj->amount_ttc;
+
 				$var = !$var;
 				print "<tr ".$bc[$var]."><td>&nbsp;</td>";
-				print '<td colspan="3" class="opacitymedium">'.$langs->trans("None").'</td>';
+
+				print "<td>".$langs->trans("ExpenseReport")." <a href=\"".DOL_URL_ROOT."/expensereport/list.php?search_user=".$obj->userid."\">".$obj->firstname." ".$obj->lastname."</a></td>\n";
+
+				if ($modecompta == 'CREANCES-DETTES') print '<td align="right">'.price(-$obj->amount_ht).'</td>';
+				print '<td align="right">'.price(-$obj->amount_ttc).'</td>';
 				print '</tr>';
 			}
 		}
 		else
 		{
-			dol_print_error($db);
-		}
-		print '<tr class="liste_total">';
-		if ($modecompta == 'CREANCES-DETTES')
-			print '<td colspan="3" align="right">'.price(-$subtotal_ht).'</td>';
-			print '<td colspan="3" align="right">'.price(-$subtotal_ttc).'</td>';
+			$var = !$var;
+			print "<tr ".$bc[$var]."><td>&nbsp;</td>";
+			print '<td colspan="3" class="opacitymedium">'.$langs->trans("None").'</td>';
 			print '</tr>';
+		}
+	}
+	else
+	{
+		dol_print_error($db);
+	}
+	print '<tr class="liste_total">';
+	if ($modecompta == 'CREANCES-DETTES')
+		print '<td colspan="3" align="right">'.price(-$subtotal_ht).'</td>';
+		print '<td colspan="3" align="right">'.price(-$subtotal_ttc).'</td>';
+		print '</tr>';
 }
 
 /*
@@ -733,7 +769,11 @@ if (! empty($conf->don->enabled))
 	if (! empty($date_start) && ! empty($date_end))
 		$sql.= " AND p.datedon >= '".$db->idate($date_start)."' AND p.datedon <= '".$db->idate($date_end)."'";
 	$sql.= " GROUP BY p.societe, p.firstname, p.lastname, dm";
-	$sql.= " ORDER BY p.societe, p.firstname, p.lastname, dm";
+    $newsortfield = $sortfield;
+    if ($newsortfield == 's.nom, s.rowid') $newsortfield = 'p.societe, p.firstname, p.lastname, dm';
+    if ($newsortfield == 'amount_ht') $newsortfield = 'amount';
+    if ($newsortfield == 'amount_ttc') $newsortfield = 'amount';
+    $sql.= $db->order($newsortfield, $sortorder);
 
 	dol_syslog("get dunning");
 	$result=$db->query($sql);
@@ -808,7 +848,11 @@ if ($modecompta == 'CREANCES-DETTES')
     	$sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
     $sql.= " AND f.entity = ".$conf->entity;
     $sql.= " GROUP BY dm";
-    $sql.= " ORDER BY dm";
+    $newsortfield = $sortfield;
+    if ($newsortfield == 's.nom, s.rowid') $newsortfield = 'dm';
+    if ($newsortfield == 'amount_ht') $newsortfield = 'amount';
+    if ($newsortfield == 'amount_ttc') $newsortfield = 'amount';
+    $sql.= $db->order($newsortfield, $sortorder);
 
     dol_syslog("get vat to pay", LOG_DEBUG);
     $result=$db->query($sql);
@@ -853,7 +897,11 @@ if ($modecompta == 'CREANCES-DETTES')
     	$sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
     $sql.= " AND f.entity = ".$conf->entity;
     $sql.= " GROUP BY dm";
-    $sql.= " ORDER BY dm";
+    $newsortfield = $sortfield;
+    if ($newsortfield == 's.nom, s.rowid') $newsortfield = 'dm';
+    if ($newsortfield == 'amount_ht') $newsortfield = 'amount';
+    if ($newsortfield == 'amount_ttc') $newsortfield = 'amount';
+    $sql.= $db->order($newsortfield, $sortorder);
 
     dol_syslog("get vat received back", LOG_DEBUG);
     $result=$db->query($sql);
@@ -897,7 +945,11 @@ else
     	$sql.= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'";
     $sql.= " AND t.entity = ".$conf->entity;
     $sql.= " GROUP BY dm";
-    $sql.= " ORDER BY dm";
+    $newsortfield = $sortfield;
+    if ($newsortfield == 's.nom, s.rowid') $newsortfield = 'dm';
+    if ($newsortfield == 'amount_ht') $newsortfield = 'amount';
+    if ($newsortfield == 'amount_ttc') $newsortfield = 'amount';
+    $sql.= $db->order($newsortfield, $sortorder);
 
     dol_syslog("get vat really paid", LOG_DEBUG);
     $result=$db->query($sql);
@@ -938,7 +990,11 @@ else
     	$sql.= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'";
     $sql.= " AND t.entity = ".$conf->entity;
     $sql.= " GROUP BY dm";
-    $sql.= " ORDER BY dm";
+    $newsortfield = $sortfield;
+    if ($newsortfield == 's.nom, s.rowid') $newsortfield = 'dm';
+    if ($newsortfield == 'amount_ht') $newsortfield = 'amount';
+    if ($newsortfield == 'amount_ttc') $newsortfield = 'amount';
+    $sql.= $db->order($newsortfield, $sortorder);
 
     dol_syslog("get vat really received back", LOG_DEBUG);
     $result=$db->query($sql);

+ 14 - 3
htdocs/cron/admin/cron.php

@@ -88,9 +88,20 @@ print "</tr>";
 
 print '<tr class="impair">';
 print '<td class="fieldrequired">'.$langs->trans("KeyForCronAccess").'</td>';
-print '<td><input type="text" class="flat" id="CRON_KEY" name="CRON_KEY" value="'. (GETPOST('CRON_KEY')?GETPOST('CRON_KEY'):(! empty($conf->global->CRON_KEY)?$conf->global->CRON_KEY:'')) . '" size="40">';
-if (! empty($conf->use_javascript_ajax))
-	print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
+$disabled='';
+if (! empty($conf->global->CRON_DISABLE_KEY_CHANGE)) $disabled=' disabled="disabled"';
+print '<td>';
+if (empty($conf->global->CRON_DISABLE_KEY_CHANGE)) 
+{
+    print '<input type="text" class="flat minwidth200"'.$disabled.' id="CRON_KEY" name="CRON_KEY" value="'. (GETPOST('CRON_KEY')?GETPOST('CRON_KEY'):(! empty($conf->global->CRON_KEY)?$conf->global->CRON_KEY:'')) . '">';
+    if (! empty($conf->use_javascript_ajax))
+    	print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
+}
+else 
+{
+    print (! empty($conf->global->CRON_KEY)?$conf->global->CRON_KEY:''); 
+    print '<input type="hidden" id="CRON_KEY" name="CRON_KEY" value="'. (GETPOST('CRON_KEY')?GETPOST('CRON_KEY'):(! empty($conf->global->CRON_KEY)?$conf->global->CRON_KEY:'')) . '">'; 
+}
 print '</td>';
 print '<td>&nbsp;</td>';
 print '</tr>';

+ 2 - 1
htdocs/expensereport/card.php

@@ -2225,7 +2225,8 @@ if ($action != 'create' && $action != 'edit')
 	// If bank module is not used	
 	if (($user->rights->expensereport->to_paid || empty($conf->banque->enabled)) && $object->fk_statut == 5)
 	{
-		if ((round($remaintopay) == 0 || empty($conf->banque->enabled)) && $object->paid == 0)
+		//if ((round($remaintopay) == 0 || empty($conf->banque->enabled)) && $object->paid == 0)
+		if ($object->paid == 0)
 		{
 			print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id='.$object->id.'&action=set_paid">'.$langs->trans("ClassifyPaid")."</a></div>";
 		}

+ 1 - 0
htdocs/expensereport/export_csv.php

@@ -128,6 +128,7 @@ if (isset($_POST['action']))
 
 		$sql = "SELECT d.rowid, d.ref, d.total_ht, d.total_tva, d.total_ttc";
 		$sql.= " FROM ".MAIN_DB_PREFIX."expensereport as d";
+        $sql.= ' AND d.entity IN ('.getEntity('expensereport', 1).')';
 		$sql.= " ORDER BY d.rowid";
 
 		$result = $db->query($sql);

+ 1 - 1
htdocs/expensereport/index.php

@@ -147,7 +147,7 @@ $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as d, ".MAIN_DB_PREFIX."user as u"
 if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
 $sql.= " WHERE u.rowid = d.fk_user_author";
 if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)) $sql.=' AND d.fk_user_author IN ('.join(',',$childids).')';
-//$sql.= " AND d.entity = ".$conf->entity;
+$sql.= ' AND d.entity IN ('.getEntity('expensereport', 1).')';
 if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND d.fk_user_author = s.rowid AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 if ($socid) $sql.= " AND d.fk_user_author = ".$socid;
 $sql.= $db->order($sortfield,$sortorder);

+ 1 - 1
htdocs/expensereport/list.php

@@ -203,7 +203,7 @@ $sql.=$hookmanager->resPrint;
 $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as d";
 if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."expensereport_extrafields as ef on (d.rowid = ef.fk_object)";
 $sql.= ", ".MAIN_DB_PREFIX."user as u";
-$sql.= " WHERE d.fk_user_author = u.rowid AND d.entity = ".$conf->entity;
+$sql.= " WHERE d.fk_user_author = u.rowid AND d.entity IN (".getEntity('expensereport', 1).")";
 // Search all
 if (!empty($sall)) $sql.= natural_search(array_keys($fieldstosearchall), $sall);
 // Ref

+ 1 - 1
htdocs/expensereport/payment/card.php

@@ -199,7 +199,7 @@ $disable_delete = 0;
 $sql = 'SELECT er.rowid as did, er.paid, er.total_ttc, per.amount';
 $sql.= ' FROM '.MAIN_DB_PREFIX.'payment_expensereport as per,'.MAIN_DB_PREFIX.'expensereport as er';
 $sql.= ' WHERE per.fk_expensereport = er.rowid';
-$sql.= ' AND er.entity = '.$conf->entity;
+$sql.= ' AND er.entity IN ('.getEntity('expensereport', 1).')';
 $sql.= ' AND per.rowid = '.$id;
 
 dol_syslog("expensereport/payment/card.php", LOG_DEBUG);

+ 3 - 2
htdocs/expensereport/payment/payment.php

@@ -193,8 +193,9 @@ if (GETPOST("action") == 'create')
 	print '<tr><td>'.$langs->trans("Amount").'</td><td colspan="2">'.price($expensereport->total_ttc,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';
 
 	$sql = "SELECT sum(p.amount) as total";
-	$sql.= " FROM ".MAIN_DB_PREFIX."payment_expensereport as p";
-	$sql.= " WHERE p.fk_expensereport = ".$chid;
+	$sql.= " FROM ".MAIN_DB_PREFIX."payment_expensereport as p, ".MAIN_DB_PREFIX."expensereport as e";
+	$sql.= " WHERE p.fk_expensereport = e.rowid AND p.fk_expensereport = ".$chid;
+    $sql.= ' AND e.entity IN ('.getEntity('expensereport', 1).')';
 	$resql = $db->query($sql);
 	if ($resql)
 	{

+ 1 - 0
htdocs/expensereport/synchro_compta.php

@@ -139,6 +139,7 @@ else:
 	$sql.= " FROM ".MAIN_DB_PREFIX."expensereport as d";
 	$sql.= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON d.fk_user_author = u.rowid";
 	$sql.= " WHERE d.fk_statut = 6";
+    $sql.= ' AND d.entity IN ('.getEntity('expensereport', 1).')';
 	$sql.= " ORDER BY d.date_valid DESC";
 
 	$resql=$db->query($sql);

+ 1 - 1
htdocs/fourn/facture/card.php

@@ -2342,7 +2342,7 @@ else
     	            print '<tr '.$bc[$var].'><td>';
     	            $paymentstatic->id=$objp->rowid;
     	            $paymentstatic->datepaye=$db->jdate($objp->dp);
-    	            $paymentstatic->ref=$objp->ref;
+    	            $paymentstatic->ref=($objp->ref ? $objp->ref : $objp->rowid);;
     	            $paymentstatic->num_paiement=$objp->num_paiement;
     	            $paymentstatic->payment_code=$objp->payment_code;
     	            print $paymentstatic->getNomUrl(1);

+ 2 - 2
htdocs/fourn/facture/list.php

@@ -247,9 +247,9 @@ llxHeader('',$langs->trans("SuppliersInvoices"),'EN:Suppliers_Invoices|FR:Factur
 
 $sql = "SELECT";
 if ($search_all || $search_product_category > 0) $sql = 'SELECT DISTINCT';
-$sql.= " f.rowid as facid, f.ref, f.ref_supplier, f.datef, f.date_lim_reglement as datelimite,";
+$sql.= " f.rowid as facid, f.ref, f.ref_supplier, f.datef, f.date_lim_reglement as datelimite, f.fk_mode_reglement,";
 $sql.= " f.total_ht, f.total_ttc, f.total_tva as total_vat, f.paye as paye, f.fk_statut as fk_statut, f.libelle as label,";
-$sql.= ' s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client, ';
+$sql.= " s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client,";
 $sql.= " typent.code as typent_code,";
 $sql.= " state.code_departement as state_code, state.nom as state_name,";
 $sql.= " p.rowid as project_id, p.ref as project_ref";

+ 1 - 1
htdocs/langs/en_US/bills.lang

@@ -41,7 +41,7 @@ ConsumedBy=Consumed by
 NotConsumed=Not consumed
 NoReplacableInvoice=No replacable invoices
 NoInvoiceToCorrect=No invoice to correct
-InvoiceHasAvoir=Corrected by one or several invoices
+InvoiceHasAvoir=Was source of one or several credit notes
 CardBill=Invoice card
 PredefinedInvoices=Predefined Invoices
 Invoice=Invoice

+ 42 - 13
htdocs/projet/element.php

@@ -877,6 +877,8 @@ foreach ($listofreferent as $key => $value)
 				$warning='';
 				if (empty($value['disableamount']))
 				{
+				    $total_ht_by_line=null;
+				    $othermessage='';
 					if ($tablename == 'don') $total_ht_by_line=$element->amount;
 					elseif ($tablename == 'projet_task')
 					{
@@ -893,7 +895,7 @@ foreach ($listofreferent as $key => $value)
 					    }
 					    else
 					    {
-					        print $langs->trans("ModuleDisabled");
+					        $othermessage=$form->textwithpicto($langs->trans("NotAvailable"), $langs->trans("ModuleSalaryToDefineHourlyRateMustBeEnabled"));
 					    }
 					}
 					else
@@ -901,9 +903,13 @@ foreach ($listofreferent as $key => $value)
 						$total_ht_by_line=$element->total_ht;
 					}
 					print '<td align="right">';
-					if (! $qualifiedfortotal) print '<strike>';
-					print (isset($total_ht_by_line)?price($total_ht_by_line):'&nbsp;');
-					if (! $qualifiedfortotal) print '</strike>';
+					if ($othermessage) print $othermessage;
+					if (isset($total_ht_by_line))
+					{
+					   if (! $qualifiedfortotal) print '<strike>';
+					   print price($total_ht_by_line);
+					   if (! $qualifiedfortotal) print '</strike>';
+					}
 					if ($warning) print ' '.img_warning($warning);
 					print '</td>';
 				}
@@ -912,20 +918,33 @@ foreach ($listofreferent as $key => $value)
                 // Amount inc tax
 				if (empty($value['disableamount']))
 				{
+				    $total_ttc_by_line=null;
 					if ($tablename == 'don') $total_ttc_by_line=$element->amount;
 					elseif ($tablename == 'projet_task')
 					{
-						$defaultvat = get_default_tva($mysoc, $mysoc);
-						$total_ttc_by_line = price2num($total_ht_by_line * (1 + ($defaultvat / 100)),'MT');
+					    if (! empty($conf->salaries->enabled))
+					    {
+					        // TODO Permission to read daily rate
+    						$defaultvat = get_default_tva($mysoc, $mysoc);
+    						$total_ttc_by_line = price2num($total_ht_by_line * (1 + ($defaultvat / 100)),'MT');
+					    }
+					    else
+					    {
+					        $othermessage=$form->textwithpicto($langs->trans("NotAvailable"), $langs->trans("ModuleSalaryToDefineHourlyRateMustBeEnabled"));
+					    }					    
 					}
 					else
 					{
 						$total_ttc_by_line=$element->total_ttc;
 					}
 					print '<td align="right">';
-					if (! $qualifiedfortotal) print '<strike>';
-					print (isset($total_ttc_by_line)?price($total_ttc_by_line):'&nbsp;');
-					if (! $qualifiedfortotal) print '</strike>';
+					if ($othermessage) print $othermessage;
+					if (isset($total_ttc_by_line))
+					{
+					   if (! $qualifiedfortotal) print '<strike>';
+					   print price($total_ttc_by_line);
+					   if (! $qualifiedfortotal) print '</strike>';
+					}
 					if ($warning) print ' '.img_warning($warning);
 					print '</td>';
 				}
@@ -988,15 +1007,25 @@ foreach ($listofreferent as $key => $value)
 
 			if ($breakline) print $breakline;
 
+			// Total
 			print '<tr class="liste_total"><td colspan="4">'.$langs->trans("Number").': '.$i.'</td>';
 			//if (empty($value['disableamount']) && ! in_array($tablename, array('projet_task'))) print '<td align="right" width="100">'.$langs->trans("TotalHT").' : '.price($total_ht).'</td>';
 			//elseif (empty($value['disableamount']) && in_array($tablename, array('projet_task'))) print '<td align="right" width="100">'.$langs->trans("Total").' : '.price($total_ht).'</td>';
-			if (empty($value['disableamount'])) print '<td align="right" width="100">'.$langs->trans("TotalHT").' : '.price($total_ht).'</td>';
-			else print '<td></td>';
+			print '<td align="right">';
+			if (empty($value['disableamount'])) 
+			{
+			    if (! empty($conf->salaries->enabled)) print ''.$langs->trans("TotalHT").' : '.price($total_ht);
+			}
+			print '</td>';
 			//if (empty($value['disableamount']) && ! in_array($tablename, array('projet_task'))) print '<td align="right" width="100">'.$langs->trans("TotalTTC").' : '.price($total_ttc).'</td>';
 			//elseif (empty($value['disableamount']) && in_array($tablename, array('projet_task'))) print '<td align="right" width="100"></td>';
-			if (empty($value['disableamount'])) print '<td align="right" width="100">'.$langs->trans("TotalTTC").' : '.price($total_ttc).'</td>';
-			else print '<td></td>';
+			print '<td align="right">';
+			if (empty($value['disableamount'])) 
+			{
+			    
+			    if (! empty($conf->salaries->enabled)) print $langs->trans("TotalTTC").' : '.price($total_ttc);
+			}
+			print '</td>';
 			print '<td>&nbsp;</td>';
 			print '</tr>';
 		}

+ 3 - 0
htdocs/societe/consumption.php

@@ -249,6 +249,7 @@ if ($type_element == 'supplier_invoice')
 	$tables_from = MAIN_DB_PREFIX."facture_fourn as f,".MAIN_DB_PREFIX."facture_fourn_det as d";
 	$where = " WHERE f.fk_soc = s.rowid AND s.rowid = ".$socid;
 	$where.= " AND d.fk_facture_fourn = f.rowid";
+	$where.= " AND f.entity = ".$conf->entity;
 	$dateprint = 'f.datef';
 	$doc_number='f.ref';
 	$thirdTypeSelect='supplier';
@@ -261,6 +262,7 @@ if ($type_element == 'supplier_order')
 	$tables_from = MAIN_DB_PREFIX."commande_fournisseur as c,".MAIN_DB_PREFIX."commande_fournisseurdet as d";
 	$where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".$socid;
 	$where.= " AND d.fk_commande = c.rowid";
+	$where.= " AND c.entity = ".$conf->entity;
 	$dateprint = 'c.date_valid';
 	$doc_number='c.ref';
 	$thirdTypeSelect='supplier';
@@ -274,6 +276,7 @@ if ($type_element == 'contract')
 	$tables_from = MAIN_DB_PREFIX."contrat as c,".MAIN_DB_PREFIX."contratdet as d";
 	$where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".$socid;
 	$where.= " AND d.fk_contrat = c.rowid";
+	$where.= " AND c.entity = ".$conf->entity;
 	$dateprint = 'c.date_valid';
 	$doc_number='c.ref';
 	$thirdTypeSelect='customer';