diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 91694fdf8cd96ebf9e4bf4f5b479b16f672d602f..d2482fee4b7e50b28a148f52750e1cc532899550 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -395,10 +395,10 @@ if (empty($reshook))
 		}
 	}
 
-	else if ($action == 'set_ref_client' && $user->rights->facture->creer)
+	else if ($action == 'setref_client' && $user->rights->facture->creer)
 	{
 		$object->fetch($id);
-		$object->set_ref_client($_POST['ref_client']);
+		$object->set_ref_client(GETPOST('ref_client'));
 	}
 
 	// Classify to validated
@@ -2878,11 +2878,61 @@ else if ($id > 0 || ! empty($ref))
 
 	// Invoice content
 
-	print '<table class="border" width="100%">';
-
 	$linkback = '<a href="' . DOL_URL_ROOT . '/compta/facture/list.php' . (! empty($socid) ? '?socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
-
+	
+	
+	$morehtmlref='<div class="refidno">';
+	// Ref customer
+	$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->facture->creer, 'string', '', 0, 1);
+	$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->facture->creer, 'string', '', null, null, '', 1);
+	// Thirdparty
+	$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1);
+	// Project
+	if (! empty($conf->projet->enabled))
+	{
+	    $langs->load("projects");
+	    $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
+	    if ($user->rights->facture->creer)
+	    {
+	        if ($action != 'classify')
+	            $morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
+	            if ($action == 'classify') {
+	                //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
+	                $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
+	                $morehtmlref.='<input type="hidden" name="action" value="classin">';
+	                $morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
+	                $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
+	                $morehtmlref.='<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
+	                $morehtmlref.='</form>';
+	            } else {
+	                $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
+	            }
+	    } else {
+	        if (! empty($object->fk_project)) {
+	            $proj = new Project($db);
+	            $proj->fetch($object->fk_project);
+	            $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
+	            $morehtmlref.=$proj->ref;
+	            $morehtmlref.='</a>';
+	        } else {
+	            $morehtmlref.='';
+	        }
+	    }
+	}
+	$morehtmlref.='</div>';
+	
+	$object->totalpaye = $totalpaye;   // To give a change to dol_banner_tab to use already paid amount to show correct status
+	
+	dol_banner_tab($object, 'ref', $linkback, 1, 'facnumber', 'ref', $morehtmlref, '', 0, '', $morehtmlright);
+	
+	print '<div class="fichecenter">';
+	print '<div class="fichehalfleft">';
+	print '<div class="underbanner clearboth"></div>';
+	
+	print '<table class="border" width="100%">';
+	
 	// Ref
+	/*
 	print '<tr><td class="titlefield">' . $langs->trans('Ref') . '</td>';
 	print '<td colspan="5">';
 	$morehtmlright = '';
@@ -2946,10 +2996,10 @@ else if ($id > 0 || ! empty($ref))
 		}
 		print ')';
 	}
-	print '</tr>';
+	print '</tr>';*/
 
 	// Type
-	print '<tr><td>' . $langs->trans('Type') . '</td><td colspan="5">';
+	print '<tr><td class="titlefield">' . $langs->trans('Type') . '</td><td>';
 	print $object->getLibType();
 	if ($object->type == Facture::TYPE_REPLACEMENT) {
 		$facreplaced = new Facture($db);
@@ -2990,7 +3040,7 @@ else if ($id > 0 || ! empty($ref))
 	$addcreditnote = '<a href="' . DOL_URL_ROOT . '/compta/facture.php?action=create&socid=' . $soc->id . '&type=2&backtopage=' . urlencode($_SERVER["PHP_SELF"]) . '?facid=' . $object->id . '">' . $langs->trans("AddCreditNote") . '</a>';
 
 	print '<tr><td>' . $langs->trans('Discounts');
-	print '</td><td colspan="5">';
+	print '</td><td>';
 	if ($soc->remise_percent)
 		print $langs->trans("CompanyHasRelativeDiscount", $soc->remise_percent);
 	else
@@ -3071,7 +3121,7 @@ else if ($id > 0 || ! empty($ref))
 	if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editinvoicedate' && ! empty($object->brouillon) && $user->rights->facture->creer && empty($conf->global->FAC_FORCE_DATE_VALIDATION))
 		print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editinvoicedate&amp;facid=' . $object->id . '">' . img_edit($langs->trans('SetDate'), 1) . '</a></td>';
 	print '</tr></table>';
-	print '</td><td colspan="3">';
+	print '</td><td>';
 
 	if ($object->type != Facture::TYPE_CREDIT_NOTE) {
 		if ($action == 'editinvoicedate') {
@@ -3084,327 +3134,8 @@ else if ($id > 0 || ! empty($ref))
 	}
 	print '</td>';
 
-	// List of payments
-
-	$sign = 1;
-	if ($object->type == Facture::TYPE_CREDIT_NOTE)
-		$sign = - 1;
-
-	$nbrows = 8;
-	$nbcols = 3;
-	if (! empty($conf->projet->enabled))
-		$nbrows ++;
-	if (! empty($conf->banque->enabled)) {
-		$nbrows ++; $nbcols++;
-	}
-	if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0)
-		$nbrows ++;
-	if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0)
-		$nbrows ++;
-	if ($selleruserevenustamp)
-		$nbrows ++;
-	if (! empty($conf->multicurrency->enabled)) $nbrows+=5;
-	if (! empty($conf->incoterm->enabled)) $nbrows+=1;
-
-	print '<td rowspan="' . $nbrows . '" colspan="2" valign="top">';
-
-	if ($object->type == Facture::TYPE_SITUATION && !empty($conf->global->INVOICE_USE_SITUATION))
-	{
-		if (count($object->tab_previous_situation_invoice) > 0 || count($object->tab_next_situation_invoice) > 0) print '<table class="nobordernopadding paymenttable" width="100%">';
-
-		if (count($object->tab_previous_situation_invoice) > 0)
-		{
-			//List of previous invoices
-			print '<tr class="liste_titre">';
-			print '<td>' . $langs->trans('ListOfPreviousSituationInvoices') . '</td>';
-			print '<td></td>';
-			if (! empty($conf->banque->enabled))
-				print '<td align="right"></td>';
-			print '<td align="right">' . $langs->trans('AmountHT') . '</td>';
-			print '<td align="right">' . $langs->trans('AmountTTC') . '</td>';
-			print '<td width="18">&nbsp;</td>';
-			print '</tr>';
-
-			$total_prev_ht = $total_prev_ttc = 0;
-			$var = true;
-			foreach ($object->tab_previous_situation_invoice as $prev_invoice)
-			{
-				$totalpaye = $prev_invoice->getSommePaiement();
-				$total_prev_ht += $prev_invoice->total_ht;
-				$total_prev_ttc += $prev_invoice->total_ttc;
-				print '<tr '.$bc [$var].'>';
-				print '<td>'.$prev_invoice->getNomUrl(1).'</td>';
-				print '<td></td>';
-				if (! empty($conf->banque->enabled))
-					print '<td align="right"></td>';
-				print '<td align="right">' . price($prev_invoice->total_ht) . '</td>';
-				print '<td align="right">' . price($prev_invoice->total_ttc) . '</td>';
-				print '<td align="right">'.$prev_invoice->getLibStatut(3, $totalpaye).'</td>';
-				print '</tr>';
-
-				$var = !$var;
-			}
-
-			print '<tr '.$bc [$var].'>';
-			print '<td colspan="2" align="right"></td>';
-			print '<td align="right"><b>' . price($total_prev_ht) . '</b></td>';
-			print '<td align="right"><b>' . price($total_prev_ttc) . '</b></td>';
-			print '<td width="18">&nbsp;</td>';
-			print '</tr>';
-		}
-
-		if (count($object->tab_next_situation_invoice) > 0)
-		{
-			//List of next invoices
-			print '<tr class="liste_titre">';
-			print '<td>' . $langs->trans('ListOfNextSituationInvoices') . '</td>';
-			print '<td></td>';
-			if (! empty($conf->banque->enabled))
-				print '<td align="right"></td>';
-			print '<td align="right">' . $langs->trans('AmountHT') . '</td>';
-			print '<td align="right">' . $langs->trans('AmountTTC') . '</td>';
-			print '<td width="18">&nbsp;</td>';
-			print '</tr>';
-
-			$total_next_ht = $total_next_ttc = 0;
-
-			$var = true;
-			foreach ($object->tab_next_situation_invoice as $next_invoice)
-			{
-				$totalpaye = $next_invoice->getSommePaiement();
-				$total_next_ht += $next_invoice->total_ht;
-				$total_next_ttc += $next_invoice->total_ttc;
-				print '<tr '.$bc [$var].'>';
-				print '<td>'.$next_invoice->getNomUrl(1).'</td>';
-				print '<td></td>';
-				if (! empty($conf->banque->enabled))
-					print '<td align="right"></td>';
-				print '<td align="right">' . price($next_invoice->total_ht) . '</td>';
-				print '<td align="right">' . price($next_invoice->total_ttc) . '</td>';
-				print '<td align="right">'.$next_invoice->getLibStatut(3, $totalpaye).'</td>';
-				print '</tr>';
-
-				$var = !$var;
-			}
-
-			print '<tr '.$bc [$var].'>';
-			print '<td colspan="2" align="right"></td>';
-			print '<td align="right"><b>' . price($total_next_ht) . '</b></td>';
-			print '<td align="right"><b>' . price($total_next_ttc) . '</b></td>';
-			print '<td width="18">&nbsp;</td>';
-			print '</tr>';
-		}
-
-		if (count($object->tab_previous_situation_invoice) > 0 || count($object->tab_next_situation_invoice) > 0) print '</table>';
-	}
-
-	print '<table class="nobordernopadding paymenttable" width="100%">';
-
-	// List of payments already done
-	print '<tr class="liste_titre">';
-	print '<td class="liste_titre">' . ($object->type == Facture::TYPE_CREDIT_NOTE ? $langs->trans("PaymentsBack") : $langs->trans('Payments')) . '</td>';
-	print '<td class="liste_titre">' . $langs->trans('Date') . '</td>';
-	print '<td class="liste_titre">' . $langs->trans('Type') . '</td>';
-	if (! empty($conf->banque->enabled))
-		print '<td class="liste_titre" align="right">' . $langs->trans('BankAccount') . '</td>';
-	print '<td class="liste_titre" align="right">' . $langs->trans('Amount') . '</td>';
-	print '<td class="liste_titre" width="18">&nbsp;</td>';
 	print '</tr>';
 
-	$var = true;
-
-	// Payments already done (from payment on this invoice)
-	$sql = 'SELECT p.datep as dp, p.ref, p.num_paiement, p.rowid, p.fk_bank,';
-	$sql .= ' c.code as payment_code, c.libelle as payment_label,';
-	$sql .= ' pf.amount,';
-	$sql .= ' ba.rowid as baid, ba.ref as baref, ba.label';
-	$sql .= ' FROM ' . MAIN_DB_PREFIX . 'c_paiement as c, ' . MAIN_DB_PREFIX . 'paiement_facture as pf, ' . MAIN_DB_PREFIX . 'paiement as p';
-	$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank as b ON p.fk_bank = b.rowid';
-	$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank_account as ba ON b.fk_account = ba.rowid';
-	$sql .= ' WHERE pf.fk_facture = ' . $object->id . ' AND p.fk_paiement = c.id AND pf.fk_paiement = p.rowid';
-	$sql .= ' ORDER BY p.datep, p.tms';
-
-	$result = $db->query($sql);
-	if ($result)
-	{
-		$num = $db->num_rows($result);
-		$i = 0;
-
-		// if ($object->type != 2)
-		// {
-		if ($num > 0)
-		{
-			while ($i < $num)
-			{
-				$objp = $db->fetch_object($result);
-				$var = ! $var;
-				print '<tr ' . $bc [$var] . '><td>';
-				$paymentstatic->id=$objp->rowid;
-				$paymentstatic->datepaye=$db->jdate($objp->dp);
-				$paymentstatic->ref=$objp->ref;
-				$paymentstatic->num_paiement=$objp->num_paiement;
-				$paymentstatic->payment_code=$objp->payment_code;
-				print $paymentstatic->getNomUrl(1);
-				print '</td>';
-				print '<td>'.dol_print_date($db->jdate($objp->dp), 'day') . '</td>';
-				$label = ($langs->trans("PaymentType" . $objp->payment_code) != ("PaymentType" . $objp->payment_code)) ? $langs->trans("PaymentType" . $objp->payment_code) : $objp->payment_label;
-				print '<td>' . $label . ' ' . $objp->num_paiement . '</td>';
-				if (! empty($conf->banque->enabled))
-				{
-					$bankaccountstatic->id = $objp->baid;
-					$bankaccountstatic->ref = $objp->baref;
-					$bankaccountstatic->label = $objp->baref;
-					print '<td align="right">';
-					if ($bankaccountstatic->id)
-						print $bankaccountstatic->getNomUrl(1, 'transactions');
-					print '</td>';
-				}
-				print '<td align="right">' . price($sign * $objp->amount) . '</td>';
-				print '<td>&nbsp;</td>';
-				print '</tr>';
-				$i ++;
-			}
-		} else {
-			print '<tr ' . $bc[false] . '><td colspan="' . $nbcols . '" class="opacitymedium">' . $langs->trans("None") . '</td><td></td><td></td></tr>';
-		}
-		// }
-		$db->free($result);
-	} else {
-		dol_print_error($db);
-	}
-
-	if ($object->type != Facture::TYPE_CREDIT_NOTE)
-	{
-		// Total already paid
-		print '<tr><td colspan="' . $nbcols . '" align="right">';
-		if ($object->type != Facture::TYPE_DEPOSIT)
-			print $langs->trans('AlreadyPaidNoCreditNotesNoDeposits');
-		else
-			print $langs->trans('AlreadyPaid');
-		print ' :</td><td align="right">' . price($totalpaye) . '</td><td>&nbsp;</td></tr>';
-
-		$resteapayeraffiche = $resteapayer;
-
-		// Loop on each credit note or deposit amount applied
-		$creditnoteamount = 0;
-		$depositamount = 0;
-		$sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
-		$sql .= " re.description, re.fk_facture_source";
-		$sql .= " FROM " . MAIN_DB_PREFIX . "societe_remise_except as re";
-		$sql .= " WHERE fk_facture = " . $object->id;
-		$resql = $db->query($sql);
-		if ($resql)
-		{
-			$num = $db->num_rows($resql);
-			$i = 0;
-			$invoice = new Facture($db);
-			while ($i < $num)
-			{
-				$obj = $db->fetch_object($resql);
-				$invoice->fetch($obj->fk_facture_source);
-				print '<tr><td colspan="' . $nbcols . '" align="right">';
-				if ($invoice->type == Facture::TYPE_CREDIT_NOTE)
-					print $langs->trans("CreditNote") . ' ';
-				if ($invoice->type == Facture::TYPE_DEPOSIT)
-					print $langs->trans("Deposit") . ' ';
-				print $invoice->getNomUrl(0);
-				print ' :</td>';
-				print '<td align="right">' . price($obj->amount_ttc) . '</td>';
-				print '<td align="right">';
-				print '<a href="' . $_SERVER["PHP_SELF"] . '?facid=' . $object->id . '&action=unlinkdiscount&discountid=' . $obj->rowid . '">' . img_delete() . '</a>';
-				print '</td></tr>';
-				$i ++;
-				if ($invoice->type == Facture::TYPE_CREDIT_NOTE)
-					$creditnoteamount += $obj->amount_ttc;
-				if ($invoice->type == Facture::TYPE_DEPOSIT)
-					$depositamount += $obj->amount_ttc;
-			}
-		} else {
-			dol_print_error($db);
-		}
-
-		// Paye partiellement 'escompte'
-		if (($object->statut == 2 || $object->statut == 3) && $object->close_code == 'discount_vat') {
-			print '<tr><td colspan="' . $nbcols . '" align="right" class="nowrap">';
-			print $form->textwithpicto($langs->trans("Discount") . ':', $langs->trans("HelpEscompte"), - 1);
-			print '</td><td align="right">' . price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye) . '</td><td>&nbsp;</td></tr>';
-			$resteapayeraffiche = 0;
-		}
-		// Paye partiellement ou Abandon 'badcustomer'
-		if (($object->statut == 2 || $object->statut == 3) && $object->close_code == 'badcustomer') {
-			print '<tr><td colspan="' . $nbcols . '" align="right" class="nowrap">';
-			print $form->textwithpicto($langs->trans("Abandoned") . ':', $langs->trans("HelpAbandonBadCustomer"), - 1);
-			print '</td><td align="right">' . price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye) . '</td><td>&nbsp;</td></tr>';
-			// $resteapayeraffiche=0;
-		}
-		// Paye partiellement ou Abandon 'product_returned'
-		if (($object->statut == 2 || $object->statut == 3) && $object->close_code == 'product_returned') {
-			print '<tr><td colspan="' . $nbcols . '" align="right" class="nowrap">';
-			print $form->textwithpicto($langs->trans("ProductReturned") . ':', $langs->trans("HelpAbandonProductReturned"), - 1);
-			print '</td><td align="right">' . price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye) . '</td><td>&nbsp;</td></tr>';
-			$resteapayeraffiche = 0;
-		}
-		// Paye partiellement ou Abandon 'abandon'
-		if (($object->statut == 2 || $object->statut == 3) && $object->close_code == 'abandon') {
-			print '<tr><td colspan="' . $nbcols . '" align="right" class="nowrap">';
-			$text = $langs->trans("HelpAbandonOther");
-			if ($object->close_note)
-				$text .= '<br><br><b>' . $langs->trans("Reason") . '</b>:' . $object->close_note;
-			print $form->textwithpicto($langs->trans("Abandoned") . ':', $text, - 1);
-			print '</td><td align="right">' . price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye) . '</td><td>&nbsp;</td></tr>';
-			$resteapayeraffiche = 0;
-		}
-
-		// Billed
-		print '<tr><td colspan="' . $nbcols . '" align="right">' . $langs->trans("Billed") . ' :</td><td align="right" style="border: 1px solid;">' . price($object->total_ttc) . '</td><td>&nbsp;</td></tr>';
-
-		// Remainder to pay
-		print '<tr><td colspan="' . $nbcols . '" align="right">';
-		if ($resteapayeraffiche >= 0)
-			print $langs->trans('RemainderToPay');
-		else
-			print $langs->trans('ExcessReceived');
-		print ' :</td>';
-		print '<td align="right" style="border: 1px solid;" bgcolor="#f0f0f0"><b>' . price($resteapayeraffiche) . '</b></td>';
-		print '<td class="nowrap">&nbsp;</td></tr>';
-	}
-	else 	// Credit note
-	{
-		// Total already paid back
-		print '<tr><td colspan="' . $nbcols . '" align="right">';
-		print $langs->trans('AlreadyPaidBack');
-		print ' :</td><td align="right">' . price($sign * $totalpaye) . '</td><td>&nbsp;</td></tr>';
-
-		// Billed
-		print '<tr><td colspan="' . $nbcols . '" align="right">' . $langs->trans("Billed") . ' :</td><td align="right" style="border: 1px solid;">' . price($sign * $object->total_ttc) . '</td><td>&nbsp;</td></tr>';
-
-		// Remainder to pay back
-		print '<tr><td colspan="' . $nbcols . '" align="right">';
-		if ($resteapayeraffiche <= 0)
-			print $langs->trans('RemainderToPayBack');
-		else
-			print $langs->trans('ExcessPaydBack');
-		print ' :</td>';
-		print '<td align="right" style="border: 1px solid;" bgcolor="#f0f0f0"><b>' . price($sign * $resteapayeraffiche) . '</b></td>';
-		print '<td class="nowrap">&nbsp;</td></tr>';
-
-		// Sold credit note
-		// print '<tr><td colspan="'.$nbcols.'" align="right">'.$langs->trans('TotalTTC').' :</td>';
-		// print '<td align="right" style="border: 1px solid;" bgcolor="#f0f0f0"><b>'.price($sign *
-	// $object->total_ttc).'</b></td><td>&nbsp;</td></tr>';
-	}
-
-	print '</table>';
-
-	// Margin Infos
-	if (! empty($conf->margin->enabled))
-	{
-		print '<br>';
-		$formmargin->displayMarginInfos($object, $object->statut > 0);
-	}
-
-	print '</td></tr>';
-
 	if (! empty($conf->global->INVOICE_POINTOFTAX_DATE))
 	{
 		// Date invoice
@@ -3414,7 +3145,7 @@ else if ($id > 0 || ! empty($ref))
 		print '</td>';
 		print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editdate_pointoftax&amp;facid=' . $object->id . '">' . img_edit($langs->trans('SetDate'), 1) . '</a></td>';
 		print '</tr></table>';
-		print '</td><td colspan="3">';
+		print '</td><td>';
 		if ($action == 'editdate_pointoftax') {
 			$form->form_date($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $object->date_pointoftax, 'date_pointoftax');
 		} else {
@@ -3431,7 +3162,7 @@ else if ($id > 0 || ! empty($ref))
 	if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editconditions' && ! empty($object->brouillon) && $user->rights->facture->creer)
 		print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editconditions&amp;facid=' . $object->id . '">' . img_edit($langs->trans('SetConditions'), 1) . '</a></td>';
 	print '</tr></table>';
-	print '</td><td colspan="3">';
+	print '</td><td>';
 	if ($object->type != Facture::TYPE_CREDIT_NOTE)
 	{
 		if ($action == 'editconditions') {
@@ -3452,7 +3183,7 @@ else if ($id > 0 || ! empty($ref))
 	if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editpaymentterm' && ! empty($object->brouillon) && $user->rights->facture->creer)
 		print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editpaymentterm&amp;facid=' . $object->id . '">' . img_edit($langs->trans('SetDate'), 1) . '</a></td>';
 	print '</tr></table>';
-	print '</td><td colspan="3">';
+	print '</td><td>';
 	if ($object->type != Facture::TYPE_CREDIT_NOTE)
 	{
 		if ($action == 'editpaymentterm') {
@@ -3476,7 +3207,7 @@ else if ($id > 0 || ! empty($ref))
 	if ($action != 'editmode' && ! empty($object->brouillon) && $user->rights->facture->creer)
 		print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editmode&amp;facid=' . $object->id . '">' . img_edit($langs->trans('SetMode'), 1) . '</a></td>';
 	print '</tr></table>';
-	print '</td><td colspan="3">';
+	print '</td><td>';
 	if ($action == 'editmode')
 	{
 		$form->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', 'CRDT');
@@ -3499,7 +3230,7 @@ else if ($id > 0 || ! empty($ref))
 		if ($action != 'editmulticurrencycode' && ! empty($object->brouillon))
 			print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editmulticurrencycode&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1) . '</a></td>';
 		print '</tr></table>';
-		print '</td><td colspan="3">';
+		print '</td><td>';
 		if ($action == 'editmulticurrencycode') {
 			$form->form_multicurrency_code($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_code, 'multicurrency_code');
 		} else {
@@ -3516,7 +3247,7 @@ else if ($id > 0 || ! empty($ref))
 		if ($action != 'editmulticurrencyrate' && ! empty($object->brouillon))
 			print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editmulticurrencyrate&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1) . '</a></td>';
 		print '</tr></table>';
-		print '</td><td colspan="3">';
+		print '</td><td>';
 		if ($action == 'editmulticurrencyrate') {
 			$form->form_multicurrency_rate($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_tx, 'multicurrency_tx', $object->multicurrency_code);
 		} else {
@@ -3533,7 +3264,7 @@ else if ($id > 0 || ! empty($ref))
 	if (($action != 'editbankaccount') && $user->rights->facture->creer && ! empty($object->brouillon))
 	    print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&amp;id='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'),1).'</a></td>';
 	print '</tr></table>';
-	print '</td><td colspan="3">';
+	print '</td><td>';
 	if ($action == 'editbankaccount')
 	{
 	    $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
@@ -3566,7 +3297,7 @@ else if ($id > 0 || ! empty($ref))
 			print $object->situation_counter;
 
 			print '</td>';
-			print '<td align="right" colspan="2" class="nowrap">';
+			print '<td align="right" class="nowrap">';
 
 			$prevsits_total_amount = 0;
 			foreach ($prevsits as $situation) {
@@ -3587,7 +3318,7 @@ else if ($id > 0 || ! empty($ref))
 				print $prevsits[$i]->situation_counter;
 				print '</a></td>';
 
-				print '<td align="right" colspan="2" class="nowrap">';
+				print '<td align="right" class="nowrap">';
 				print '- ' . price($prevsits[$i]->total_ht);
 				print '</td>';
 				print '<td>' . $langs->trans('Currency' . $conf->currency) . '</td></tr>';
@@ -3595,71 +3326,8 @@ else if ($id > 0 || ! empty($ref))
 		}
 	}
 
-	// Amount
-	print '<tr><td>' . $langs->trans('AmountHT') . '</td>';
-	print '<td colspan="3" class="nowrap">' . price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency) . '</td></tr>';
-	print '<tr><td>' . $langs->trans('AmountVAT') . '</td><td colspan="3" class="nowrap">' . price($object->total_tva, 1, '', 1, - 1, - 1, $conf->currency) . '</td></tr>';
-	print '</tr>';
-
-	// Amount Local Taxes
-	if (($mysoc->localtax1_assuj == "1" && $mysoc->useLocalTax(1)) || $object->total_localtax1 != 0) 	// Localtax1
-	{
-		print '<tr><td>' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '</td>';
-		print '<td colspan="3" class="nowrap">' . price($object->total_localtax1, 1, '', 1, - 1, - 1, $conf->currency) . '</td></tr>';
-	}
-	if (($mysoc->localtax2_assuj == "1" && $mysoc->useLocalTax(2)) || $object->total_localtax2 != 0) 	// Localtax2
-	{
-		print '<tr><td>' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '</td>';
-		print '<td colspan="3" class=nowrap">' . price($object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency) . '</td></tr>';
-	}
-
-	// Revenue stamp
-	if ($selleruserevenustamp) 	// Test company use revenue stamp
-	{
-		print '<tr><td>';
-		print '<table class="nobordernopadding" width="100%"><tr><td>';
-		print $langs->trans('RevenueStamp');
-		print '</td>';
-		if ($action != 'editrevenuestamp' && ! empty($object->brouillon) && $user->rights->facture->creer)
-			print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editrevenuestamp&amp;facid=' . $object->id . '">' . img_edit($langs->trans('SetRevenuStamp'), 1) . '</a></td>';
-		print '</tr></table>';
-		print '</td><td colspan="3">';
-		if ($action == 'editrevenuestamp') {
-			print '<form action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '" method="post">';
-			print '<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">';
-			print '<input type="hidden" name="action" value="setrevenuestamp">';
-			print $formother->select_revenue_stamp(GETPOST('revenuestamp'), 'revenuestamp', $mysoc->country_code);
-			// print '<input type="text" class="flat" size="4" name="revenuestamp" value="'.price2num($object->revenuestamp).'">';
-			print ' <input type="submit" class="button" value="' . $langs->trans('Modify') . '">';
-			print '</form>';
-		} else {
-			print price($object->revenuestamp, 1, '', 1, - 1, - 1, $conf->currency);
-		}
-		print '</td></tr>';
-	}
-
-	// Total with tax
-	print '<tr><td>' . $langs->trans('AmountTTC') . '</td><td colspan="3" class="nowrap">' . price($object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency) . '</td></tr>';
-
-	if (!empty($conf->multicurrency->enabled))
-	{
-		// Multicurrency Amount HT
-		print '<tr><td height="10">' . fieldLabel('MulticurrencyAmountHT','multicurrency_total_ht') . '</td>';
-		print '<td class="nowrap" colspan="2">' . price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . '</td>';
-		print '</tr>';
-
-		// Multicurrency Amount VAT
-		print '<tr><td height="10">' . fieldLabel('MulticurrencyAmountVAT','multicurrency_total_tva') . '</td>';
-		print '<td class="nowrap" colspan="2">' . price($object->multicurrency_total_tva, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . '</td>';
-		print '</tr>';
-
-		// Multicurrency Amount TTC
-		print '<tr><td height="10">' . fieldLabel('MulticurrencyAmountTTC','multicurrency_total_ttc') . '</td>';
-		print '<td class="nowrap" colspan="2">' . price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . '</td>';
-		print '</tr>';
-	}
-
 	// Statut
+	/*
 	print '<tr><td>' . $langs->trans('Status') . '</td>';
 	print '<td colspan="3">' . ($object->getLibStatut(4, $totalpaye)) . '</td></tr>';
 
@@ -3687,7 +3355,7 @@ else if ($id > 0 || ! empty($ref))
 		}
 		print '</td>';
 		print '</tr>';
-	}
+	}*/
 
 	// Incoterms
 	if (!empty($conf->incoterm->enabled))
@@ -3700,7 +3368,7 @@ else if ($id > 0 || ! empty($ref))
         else print '&nbsp;';
         print '</td></tr></table>';
         print '</td>';
-        print '<td colspan="3">';
+        print '<td>';
 		if ($action != 'editincoterm')
 		{
 			print $form->textwithpicto($object->display_incoterms(), $object->libelle_incoterms, 1);
@@ -3713,11 +3381,401 @@ else if ($id > 0 || ! empty($ref))
 	}
 
 	// Other attributes
-	$cols = 5;
+	$cols = 2;
 	include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
 
-	print '</table><br>';
+	print '</table>';
+	
+	print '</div>';
+	print '<div class="fichehalfright">';
+	print '<div class="ficheaddleft">';
+	print '<div class="underbanner clearboth"></div>';
+	
+	print '<table class="border centpercent">';
+	
+	// Amount
+	print '<tr><td class="titlefield">' . $langs->trans('AmountHT') . '</td>';
+	print '<td class="nowrap">' . price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency) . '</td></tr>';
+	print '<tr><td>' . $langs->trans('AmountVAT') . '</td><td colspan="3" class="nowrap">' . price($object->total_tva, 1, '', 1, - 1, - 1, $conf->currency) . '</td></tr>';
+	print '</tr>';
+	
+	// Amount Local Taxes
+	if (($mysoc->localtax1_assuj == "1" && $mysoc->useLocalTax(1)) || $object->total_localtax1 != 0) 	// Localtax1
+	{
+	    print '<tr><td>' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '</td>';
+	    print '<td class="nowrap">' . price($object->total_localtax1, 1, '', 1, - 1, - 1, $conf->currency) . '</td></tr>';
+	}
+	if (($mysoc->localtax2_assuj == "1" && $mysoc->useLocalTax(2)) || $object->total_localtax2 != 0) 	// Localtax2
+	{
+	    print '<tr><td>' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '</td>';
+	    print '<td class=nowrap">' . price($object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency) . '</td></tr>';
+	}
+	
+	// Revenue stamp
+	if ($selleruserevenustamp) 	// Test company use revenue stamp
+	{
+	    print '<tr><td>';
+	    print '<table class="nobordernopadding" width="100%"><tr><td>';
+	    print $langs->trans('RevenueStamp');
+	    print '</td>';
+	    if ($action != 'editrevenuestamp' && ! empty($object->brouillon) && $user->rights->facture->creer)
+	    {
+	        print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editrevenuestamp&amp;facid=' . $object->id . '">' . img_edit($langs->trans('SetRevenuStamp'), 1) . '</a></td>';
+	    }
+        print '</tr></table>';
+        print '</td><td>';
+        if ($action == 'editrevenuestamp') {
+            print '<form action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '" method="post">';
+            print '<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">';
+            print '<input type="hidden" name="action" value="setrevenuestamp">';
+            print $formother->select_revenue_stamp(GETPOST('revenuestamp'), 'revenuestamp', $mysoc->country_code);
+            // print '<input type="text" class="flat" size="4" name="revenuestamp" value="'.price2num($object->revenuestamp).'">';
+            print ' <input type="submit" class="button" value="' . $langs->trans('Modify') . '">';
+            print '</form>';
+        } else {
+            print price($object->revenuestamp, 1, '', 1, - 1, - 1, $conf->currency);
+        }
+        print '</td></tr>';
+	}
+	
+	// Total with tax
+	print '<tr><td>' . $langs->trans('AmountTTC') . '</td><td class="nowrap">' . price($object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency) . '</td></tr>';
+	
+	if (!empty($conf->multicurrency->enabled))
+	{
+	    // Multicurrency Amount HT
+	    print '<tr><td>' . fieldLabel('MulticurrencyAmountHT','multicurrency_total_ht') . '</td>';
+	    print '<td class="nowrap">' . price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . '</td>';
+	    print '</tr>';
+	
+	    // Multicurrency Amount VAT
+	    print '<tr><td>' . fieldLabel('MulticurrencyAmountVAT','multicurrency_total_tva') . '</td>';
+	    print '<td class="nowrap">' . price($object->multicurrency_total_tva, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . '</td>';
+	    print '</tr>';
+	
+	    // Multicurrency Amount TTC
+	    print '<tr><td>' . fieldLabel('MulticurrencyAmountTTC','multicurrency_total_ttc') . '</td>';
+	    print '<td class="nowrap">' . price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . '</td>';
+	    print '</tr>';
+	}
+	
+	print '</table>';
+	
+	// List of payments
+	
+	$sign = 1;
+	if ($object->type == Facture::TYPE_CREDIT_NOTE) $sign = - 1;
+    $nbrows = 8;
+    $nbcols = 3;
+    if (! empty($conf->projet->enabled))
+        $nbrows ++;
+    if (! empty($conf->banque->enabled)) {
+        $nbrows ++;
+        $nbcols ++;
+    }
+    if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0)
+        $nbrows ++;
+    if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0)
+        $nbrows ++;
+    if ($selleruserevenustamp)
+        $nbrows ++;
+    if (! empty($conf->multicurrency->enabled))
+        $nbrows += 5;
+    if (! empty($conf->incoterm->enabled))
+        $nbrows += 1;
+    
+    if ($object->type == Facture::TYPE_SITUATION && ! empty($conf->global->INVOICE_USE_SITUATION)) 
+    {
+        if (count($object->tab_previous_situation_invoice) > 0 || count($object->tab_next_situation_invoice) > 0)
+            print '<table class="nobordernopadding paymenttable" width="100%">';
+        
+        if (count($object->tab_previous_situation_invoice) > 0) {
+            // List of previous invoices
+            print '<tr class="liste_titre">';
+            print '<td>' . $langs->trans('ListOfPreviousSituationInvoices') . '</td>';
+            print '<td></td>';
+            if (! empty($conf->banque->enabled))
+                print '<td align="right"></td>';
+            print '<td align="right">' . $langs->trans('AmountHT') . '</td>';
+            print '<td align="right">' . $langs->trans('AmountTTC') . '</td>';
+            print '<td width="18">&nbsp;</td>';
+            print '</tr>';
+            
+            $total_prev_ht = $total_prev_ttc = 0;
+            $var = true;
+            foreach ($object->tab_previous_situation_invoice as $prev_invoice) {
+                $totalpaye = $prev_invoice->getSommePaiement();
+                $total_prev_ht += $prev_invoice->total_ht;
+                $total_prev_ttc += $prev_invoice->total_ttc;
+                print '<tr ' . $bc[$var] . '>';
+                print '<td>' . $prev_invoice->getNomUrl(1) . '</td>';
+                print '<td></td>';
+                if (! empty($conf->banque->enabled))
+                    print '<td align="right"></td>';
+                print '<td align="right">' . price($prev_invoice->total_ht) . '</td>';
+                print '<td align="right">' . price($prev_invoice->total_ttc) . '</td>';
+                print '<td align="right">' . $prev_invoice->getLibStatut(3, $totalpaye) . '</td>';
+                print '</tr>';
+                
+                $var = ! $var;
+            }
+            
+            print '<tr ' . $bc[$var] . '>';
+            print '<td colspan="2" align="right"></td>';
+            print '<td align="right"><b>' . price($total_prev_ht) . '</b></td>';
+            print '<td align="right"><b>' . price($total_prev_ttc) . '</b></td>';
+            print '<td width="18">&nbsp;</td>';
+            print '</tr>';
+        }
+        
+        if (count($object->tab_next_situation_invoice) > 0) {
+            // List of next invoices
+            print '<tr class="liste_titre">';
+            print '<td>' . $langs->trans('ListOfNextSituationInvoices') . '</td>';
+            print '<td></td>';
+            if (! empty($conf->banque->enabled))
+                print '<td align="right"></td>';
+            print '<td align="right">' . $langs->trans('AmountHT') . '</td>';
+            print '<td align="right">' . $langs->trans('AmountTTC') . '</td>';
+            print '<td width="18">&nbsp;</td>';
+            print '</tr>';
+            
+            $total_next_ht = $total_next_ttc = 0;
+            
+            $var = true;
+            foreach ($object->tab_next_situation_invoice as $next_invoice) {
+                $totalpaye = $next_invoice->getSommePaiement();
+                $total_next_ht += $next_invoice->total_ht;
+                $total_next_ttc += $next_invoice->total_ttc;
+                print '<tr ' . $bc[$var] . '>';
+                print '<td>' . $next_invoice->getNomUrl(1) . '</td>';
+                print '<td></td>';
+                if (! empty($conf->banque->enabled))
+                    print '<td align="right"></td>';
+                print '<td align="right">' . price($next_invoice->total_ht) . '</td>';
+                print '<td align="right">' . price($next_invoice->total_ttc) . '</td>';
+                print '<td align="right">' . $next_invoice->getLibStatut(3, $totalpaye) . '</td>';
+                print '</tr>';
+                
+                $var = ! $var;
+            }
+            
+            print '<tr ' . $bc[$var] . '>';
+            print '<td colspan="2" align="right"></td>';
+            print '<td align="right"><b>' . price($total_next_ht) . '</b></td>';
+            print '<td align="right"><b>' . price($total_next_ttc) . '</b></td>';
+            print '<td width="18">&nbsp;</td>';
+            print '</tr>';
+        }
+        
+        if (count($object->tab_previous_situation_invoice) > 0 || count($object->tab_next_situation_invoice) > 0)
+            print '</table>';
+    }
+    
+    print '<table class="noborder paymenttable" width="100%">';
+    
+    // List of payments already done
+    print '<tr class="liste_titre">';
+    print '<td class="liste_titre">' . ($object->type == Facture::TYPE_CREDIT_NOTE ? $langs->trans("PaymentsBack") : $langs->trans('Payments')) . '</td>';
+    print '<td class="liste_titre">' . $langs->trans('Date') . '</td>';
+    print '<td class="liste_titre">' . $langs->trans('Type') . '</td>';
+    if (! empty($conf->banque->enabled)) {
+        print '<td class="liste_titre" align="right">' . $langs->trans('BankAccount') . '</td>';
+    }
+    print '<td class="liste_titre" align="right">' . $langs->trans('Amount') . '</td>';
+    print '<td class="liste_titre" width="18">&nbsp;</td>';
+    print '</tr>';
+    
+    $var = true;
+    
+    // Payments already done (from payment on this invoice)
+    $sql = 'SELECT p.datep as dp, p.ref, p.num_paiement, p.rowid, p.fk_bank,';
+    $sql .= ' c.code as payment_code, c.libelle as payment_label,';
+    $sql .= ' pf.amount,';
+    $sql .= ' ba.rowid as baid, ba.ref as baref, ba.label';
+    $sql .= ' FROM ' . MAIN_DB_PREFIX . 'c_paiement as c, ' . MAIN_DB_PREFIX . 'paiement_facture as pf, ' . MAIN_DB_PREFIX . 'paiement as p';
+    $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank as b ON p.fk_bank = b.rowid';
+    $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank_account as ba ON b.fk_account = ba.rowid';
+    $sql .= ' WHERE pf.fk_facture = ' . $object->id . ' AND p.fk_paiement = c.id AND pf.fk_paiement = p.rowid';
+    $sql .= ' ORDER BY p.datep, p.tms';
+    
+    $result = $db->query($sql);
+    if ($result) {
+        $num = $db->num_rows($result);
+        $i = 0;
+        
+        // if ($object->type != 2)
+        // {
+        if ($num > 0) {
+            while ($i < $num) {
+                $objp = $db->fetch_object($result);
+                $var = ! $var;
+                print '<tr ' . $bc[$var] . '><td>';
+                $paymentstatic->id = $objp->rowid;
+                $paymentstatic->datepaye = $db->jdate($objp->dp);
+                $paymentstatic->ref = $objp->ref;
+                $paymentstatic->num_paiement = $objp->num_paiement;
+                $paymentstatic->payment_code = $objp->payment_code;
+                print $paymentstatic->getNomUrl(1);
+                print '</td>';
+                print '<td>' . dol_print_date($db->jdate($objp->dp), 'day') . '</td>';
+                $label = ($langs->trans("PaymentType" . $objp->payment_code) != ("PaymentType" . $objp->payment_code)) ? $langs->trans("PaymentType" . $objp->payment_code) : $objp->payment_label;
+                print '<td>' . $label . ' ' . $objp->num_paiement . '</td>';
+                if (! empty($conf->banque->enabled)) {
+                    $bankaccountstatic->id = $objp->baid;
+                    $bankaccountstatic->ref = $objp->baref;
+                    $bankaccountstatic->label = $objp->baref;
+                    print '<td align="right">';
+                    if ($bankaccountstatic->id)
+                        print $bankaccountstatic->getNomUrl(1, 'transactions');
+                    print '</td>';
+                }
+                print '<td align="right">' . price($sign * $objp->amount) . '</td>';
+                print '<td>&nbsp;</td>';
+                print '</tr>';
+                $i ++;
+            }
+        } else {
+            print '<tr ' . $bc[false] . '><td colspan="' . $nbcols . '" class="opacitymedium">' . $langs->trans("None") . '</td><td></td><td></td></tr>';
+        }
+        // }
+        $db->free($result);
+    } else {
+        dol_print_error($db);
+    }
+    
+    if ($object->type != Facture::TYPE_CREDIT_NOTE) {
+        // Total already paid
+        print '<tr><td colspan="' . $nbcols . '" align="right">';
+        if ($object->type != Facture::TYPE_DEPOSIT)
+            print $langs->trans('AlreadyPaidNoCreditNotesNoDeposits');
+        else
+            print $langs->trans('AlreadyPaid');
+        print ' :</td><td align="right"'.(($totalpaye > 0)?' class="amountalreadypaid"':'').'>' . price($totalpaye) . '</td><td>&nbsp;</td></tr>';
+        
+        $resteapayeraffiche = $resteapayer;
+        
+        // Loop on each credit note or deposit amount applied
+        $creditnoteamount = 0;
+        $depositamount = 0;
+        $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
+        $sql .= " re.description, re.fk_facture_source";
+        $sql .= " FROM " . MAIN_DB_PREFIX . "societe_remise_except as re";
+        $sql .= " WHERE fk_facture = " . $object->id;
+        $resql = $db->query($sql);
+        if ($resql) {
+            $num = $db->num_rows($resql);
+            $i = 0;
+            $invoice = new Facture($db);
+            while ($i < $num) {
+                $obj = $db->fetch_object($resql);
+                $invoice->fetch($obj->fk_facture_source);
+                print '<tr><td colspan="' . $nbcols . '" align="right">';
+                if ($invoice->type == Facture::TYPE_CREDIT_NOTE)
+                    print $langs->trans("CreditNote") . ' ';
+                if ($invoice->type == Facture::TYPE_DEPOSIT)
+                    print $langs->trans("Deposit") . ' ';
+                print $invoice->getNomUrl(0);
+                print ' :</td>';
+                print '<td align="right">' . price($obj->amount_ttc) . '</td>';
+                print '<td align="right">';
+                print '<a href="' . $_SERVER["PHP_SELF"] . '?facid=' . $object->id . '&action=unlinkdiscount&discountid=' . $obj->rowid . '">' . img_delete() . '</a>';
+                print '</td></tr>';
+                $i ++;
+                if ($invoice->type == Facture::TYPE_CREDIT_NOTE)
+                    $creditnoteamount += $obj->amount_ttc;
+                if ($invoice->type == Facture::TYPE_DEPOSIT)
+                    $depositamount += $obj->amount_ttc;
+            }
+        } else {
+            dol_print_error($db);
+        }
+        
+        // Paye partiellement 'escompte'
+        if (($object->statut == 2 || $object->statut == 3) && $object->close_code == 'discount_vat') {
+            print '<tr><td colspan="' . $nbcols . '" align="right" class="nowrap">';
+            print $form->textwithpicto($langs->trans("Discount") . ':', $langs->trans("HelpEscompte"), - 1);
+            print '</td><td align="right">' . price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye) . '</td><td>&nbsp;</td></tr>';
+            $resteapayeraffiche = 0;
+        }
+        // Paye partiellement ou Abandon 'badcustomer'
+        if (($object->statut == 2 || $object->statut == 3) && $object->close_code == 'badcustomer') {
+            print '<tr><td colspan="' . $nbcols . '" align="right" class="nowrap">';
+            print $form->textwithpicto($langs->trans("Abandoned") . ':', $langs->trans("HelpAbandonBadCustomer"), - 1);
+            print '</td><td align="right">' . price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye) . '</td><td>&nbsp;</td></tr>';
+            // $resteapayeraffiche=0;
+        }
+        // Paye partiellement ou Abandon 'product_returned'
+        if (($object->statut == 2 || $object->statut == 3) && $object->close_code == 'product_returned') {
+            print '<tr><td colspan="' . $nbcols . '" align="right" class="nowrap">';
+            print $form->textwithpicto($langs->trans("ProductReturned") . ':', $langs->trans("HelpAbandonProductReturned"), - 1);
+            print '</td><td align="right">' . price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye) . '</td><td>&nbsp;</td></tr>';
+            $resteapayeraffiche = 0;
+        }
+        // Paye partiellement ou Abandon 'abandon'
+        if (($object->statut == 2 || $object->statut == 3) && $object->close_code == 'abandon') {
+            print '<tr><td colspan="' . $nbcols . '" align="right" class="nowrap">';
+            $text = $langs->trans("HelpAbandonOther");
+            if ($object->close_note)
+                $text .= '<br><br><b>' . $langs->trans("Reason") . '</b>:' . $object->close_note;
+            print $form->textwithpicto($langs->trans("Abandoned") . ':', $text, - 1);
+            print '</td><td align="right">' . price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye) . '</td><td>&nbsp;</td></tr>';
+            $resteapayeraffiche = 0;
+        }
+        
+        // Billed
+        print '<tr><td colspan="' . $nbcols . '" align="right">' . $langs->trans("Billed") . ' :</td><td align="right">' . price($object->total_ttc) . '</td><td>&nbsp;</td></tr>';
+        
+        // Remainder to pay
+        print '<tr><td colspan="' . $nbcols . '" align="right">';
+        if ($resteapayeraffiche >= 0)
+            print $langs->trans('RemainderToPay');
+        else
+            print $langs->trans('ExcessReceived');
+        print ' :</td>';
+        print '<td align="right" class="amountremaintopay">' . price($resteapayeraffiche) . '</td>';
+        print '<td class="nowrap">&nbsp;</td></tr>';
+    } 
+    else // Credit note
+    {
+        // Total already paid back
+        print '<tr><td colspan="' . $nbcols . '" align="right">';
+        print $langs->trans('AlreadyPaidBack');
+        print ' :</td><td align="right">' . price($sign * $totalpaye) . '</td><td>&nbsp;</td></tr>';
+        
+        // Billed
+        print '<tr><td colspan="' . $nbcols . '" align="right">' . $langs->trans("Billed") . ' :</td><td align="right">' . price($sign * $object->total_ttc) . '</td><td>&nbsp;</td></tr>';
+        
+        // Remainder to pay back
+        print '<tr><td colspan="' . $nbcols . '" align="right">';
+        if ($resteapayeraffiche <= 0)
+            print $langs->trans('RemainderToPayBack');
+        else
+            print $langs->trans('ExcessPaydBack');
+        print ' :</td>';
+        print '<td align="right" bgcolor="#f0f0f0"><b>' . price($sign * $resteapayeraffiche) . '</b></td>';
+        print '<td class="nowrap">&nbsp;</td></tr>';
+        
+        // Sold credit note
+        // print '<tr><td colspan="'.$nbcols.'" align="right">'.$langs->trans('TotalTTC').' :</td>';
+        // print '<td align="right" style="border: 1px solid;" bgcolor="#f0f0f0"><b>'.price($sign *
+        // $object->total_ttc).'</b></td><td>&nbsp;</td></tr>';
+    }
+    
+    print '</table>';
+	                            
+	// Margin Infos
+	if (! empty($conf->margin->enabled)) {
+	    $formmargin->displayMarginInfos($object);
+	}
+	
 
+	print '</div>';
+	print '</div>';
+	print '</div>';
+	
+	print '<div class="clearboth"></div><br>';
+	
 	if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
 		$blocname = 'contacts';
 		$title = $langs->trans('ContactsAddresses');
diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php
index 32e6ca242ca861a7f864d109ea4a3d367fffb4c3..e0ceb287ea97be41e3fbe1bd9d511dcd422d6404 100644
--- a/htdocs/compta/facture/class/facture.class.php
+++ b/htdocs/compta/facture/class/facture.class.php
@@ -1516,6 +1516,8 @@ class Facture extends CommonInvoice
 	 */
 	function set_ref_client($ref_client, $notrigger=0)
 	{
+	    global $user;
+	    
 		$error=0;
 
 		$this->db->begin();
diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php
index 5b1b935d24d932c510d85fb592997fd4c14019b9..88f6d3179528eb94af820739436cf2bb540d05b6 100644
--- a/htdocs/core/class/extrafields.class.php
+++ b/htdocs/core/class/extrafields.class.php
@@ -657,7 +657,7 @@ class ExtraFields
 	 * @param  string  $moreparam      To add more parametes on html input tag
 	 * @param  string  $keyprefix      Prefix string to add into name and id of field (can be used to avoid duplicate names)
 	 * @param  string  $keysuffix      Suffix string to add into name and id of field (can be used to avoid duplicate names)
-	 * @param  int     $showsize       Value for size attributed
+	 * @param  mixed   $showsize       Value for css to define size. May also be a numeric.
 	 * @param  int     $objectid       Current object id
 	 * @return string
 	 */
@@ -680,23 +680,37 @@ class ExtraFields
 		{
     		if ($type == 'date')
     		{
-    			$showsize=10;
+    			//$showsize=10;
+    		    $showsize = 'minwidth100imp';
     		}
     		elseif ($type == 'datetime')
     		{
-    			$showsize=19;
+    			//$showsize=19;
+    			$showsize = 'minwidth200imp';
     		}
     		elseif (in_array($type,array('int','double')))
     		{
-    			$showsize=10;
+    			//$showsize=10;
+    			$showsize = 'minwidth100imp';
     		}
     		else
     		{
-    			$showsize=round($size);
-    			if ($showsize > 48) $showsize=48;
+    			if (round($size) < 12)
+    			{
+    			    $showsize = 'minwidth100imp';
+    			}
+    			else if (round($size) <= 48)
+    			{
+    			    $showsize = 'minwidth200imp';
+    			}
+    			else 
+    			{
+    			    //$showsize=48;
+    			    $showsize = 'minwidth400imp';
+    			}
     		}
 		}
-
+        
 		if (in_array($type,array('date','datetime')))
 		{
 			$tmp=explode(',',$size);
@@ -718,11 +732,11 @@ class ExtraFields
 		{
 			$tmp=explode(',',$size);
 			$newsize=$tmp[0];
-			$out='<input type="text" class="flat" name="'.$keysuffix.'options_'.$key.$keyprefix.'" size="'.$showsize.'" maxlength="'.$newsize.'" value="'.$value.'"'.($moreparam?$moreparam:'').'>';
+			$out='<input type="text" class="flat '.$showsize.'" name="'.$keysuffix.'options_'.$key.$keyprefix.' maxwidthonsmartphone" " maxlength="'.$newsize.'" value="'.$value.'"'.($moreparam?$moreparam:'').'>';
 		}
 		elseif ($type == 'varchar')
 		{
-			$out='<input type="text" class="flat" name="'.$keysuffix.'options_'.$key.$keyprefix.'" size="'.$showsize.'" maxlength="'.$size.'" value="'.$value.'"'.($moreparam?$moreparam:'').'>';
+			$out='<input type="text" class="flat '.$showsize.'" name="'.$keysuffix.'options_'.$key.$keyprefix.' maxwidthonsmartphone" maxlength="'.$size.'" value="'.$value.'"'.($moreparam?$moreparam:'').'>';
 		}
 		elseif ($type == 'text')
 		{
@@ -738,26 +752,26 @@ class ExtraFields
 			} else {
 				$checked=' value="1" ';
 			}
-			$out='<input type="checkbox" class="flat" name="'.$keysuffix.'options_'.$key.$keyprefix.'" '.$checked.' '.($moreparam?$moreparam:'').'>';
+			$out='<input type="checkbox" class="flat '.$showsize.'" name="'.$keysuffix.'options_'.$key.$keyprefix.'" '.$checked.' '.($moreparam?$moreparam:'').'>';
 		}
 		elseif ($type == 'mail')
 		{
-			$out='<input type="text" class="flat" name="'.$keysuffix.'options_'.$key.$keyprefix.'" size="32" value="'.$value.'" '.($moreparam?$moreparam:'').'>';
+			$out='<input type="text" class="flat '.$showsize.'" name="'.$keysuffix.'options_'.$key.$keyprefix.' maxwidthonsmartphone" value="'.$value.'" '.($moreparam?$moreparam:'').'>';
 		}
 		elseif ($type == 'phone')
 		{
-			$out='<input type="text" class="flat" name="'.$keysuffix.'options_'.$key.$keyprefix.'"  size="20" value="'.$value.'" '.($moreparam?$moreparam:'').'>';
+			$out='<input type="text" class="flat '.$showsize.'" name="'.$keysuffix.'options_'.$key.$keyprefix.' maxwidthonsmartphone" value="'.$value.'" '.($moreparam?$moreparam:'').'>';
 		}
 		elseif ($type == 'price')
 		{
-			$out='<input type="text" class="flat" name="'.$keysuffix.'options_'.$key.$keyprefix.'"  size="6" value="'.price($value).'" '.($moreparam?$moreparam:'').'> '.$langs->getCurrencySymbol($conf->currency);
+			$out='<input type="text" class="flat '.$showsize.'" name="'.$keysuffix.'options_'.$key.$keyprefix.' maxwidthonsmartphone" value="'.price($value).'" '.($moreparam?$moreparam:'').'> '.$langs->getCurrencySymbol($conf->currency);
 		}
 		elseif ($type == 'double')
 		{
 			if (!empty($value)) {
 				$value=price($value);
 			}
-			$out='<input type="text" class="flat" name="'.$keysuffix.'options_'.$key.$keyprefix.'"  size="6" value="'.$value.'" '.($moreparam?$moreparam:'').'> ';
+			$out='<input type="text" class="flat '.$showsize.'" name="'.$keysuffix.'options_'.$key.$keyprefix.' maxwidthonsmartphone" value="'.$value.'" '.($moreparam?$moreparam:'').'> ';
 		}
 		elseif ($type == 'select')
 		{
@@ -768,7 +782,7 @@ class ExtraFields
 				$out.= ajax_combobox($keysuffix.'options_'.$key.$keyprefix, array(), 0);
 			}
 
-			$out.='<select class="flat" name="'.$keysuffix.'options_'.$key.$keyprefix.'" id="options_'.$key.$keyprefix.'" '.($moreparam?$moreparam:'').'>';
+			$out.='<select class="flat '.$showsize.'" name="'.$keysuffix.'options_'.$key.$keyprefix.' maxwidthonsmartphone" id="options_'.$key.$keyprefix.'" '.($moreparam?$moreparam:'').'>';
 			$out.='<option value="0">&nbsp;</option>';
 			foreach ($param['options'] as $key => $val)
 			{
@@ -790,7 +804,7 @@ class ExtraFields
 				$out.= ajax_combobox($keysuffix.'options_'.$key.$keyprefix, array(), 0);
 			}
 
-			$out.='<select class="flat" name="'.$keysuffix.'options_'.$key.$keyprefix.'" id="options_'.$key.$keyprefix.'" '.($moreparam?$moreparam:'').'>';
+			$out.='<select class="flat '.$showsize.'" name="'.$keysuffix.'options_'.$key.$keyprefix.' maxwidthonsmartphone" id="options_'.$key.$keyprefix.'" '.($moreparam?$moreparam:'').'>';
 			if (is_array($param['options']))
 			{
 				$param_list=array_keys($param['options']);
@@ -971,7 +985,7 @@ class ExtraFields
 			$out='';
 			foreach ($param['options'] as $keyopt=>$val )
 			{
-				$out.='<input class="flat" type="radio" name="'.$keysuffix.'options_'.$key.$keyprefix.'" '.($moreparam?$moreparam:'');
+				$out.='<input class="flat '.$showsize.'" type="radio" name="'.$keysuffix.'options_'.$key.$keyprefix.'" '.($moreparam?$moreparam:'');
 				$out.=' value="'.$keyopt.'"';
 				$out.= ($value==$keyopt?'checked':'');
 				$out.='/>'.$val.'<br>';
@@ -1146,7 +1160,7 @@ class ExtraFields
                 if (!empty($value)) $object->fetch($value);
                 $valuetoshow=$object->ref;
                 if ($object->element == 'societe') $valuetoshow=$object->name;  // Special case for thirdparty because ref is id because name is not unique
-                $out.='<input type="text" class="flat" name="'.$keysuffix.'options_'.$key.$keyprefix.'"  size="20" value="'.$valuetoshow.'" >';
+                $out.='<input type="text" class="flat '.$showsize.'" name="'.$keysuffix.'options_'.$key.$keyprefix.'" value="'.$valuetoshow.'" >';
 			}
 			else
 			{
@@ -1156,7 +1170,7 @@ class ExtraFields
 		}
 		elseif ($type == 'password')
 		{
-			$out='<input type="password" class="flat" name="'.$keysuffix.'options_'.$key.$keyprefix.'"  size="'.$showsize.'" value="'.$value.'" '.($moreparam?$moreparam:'').'>';
+			$out='<input type="password" class="flat '.$showsize.'" name="'.$keysuffix.'options_'.$key.$keyprefix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'>';
 		}
 		if (!empty($hidden)) {
 			$out='<input type="hidden" value="'.$value.'" name="'.$keysuffix.'options_'.$key.$keyprefix.'" id="'.$keysuffix.'options_'.$key.$keyprefix.'"/>';
diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index b035095b1a78dd0c82a4c5612a0fff0b26f766fb..910afcdfd9649ea89916df4a2e818b050115abda 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -598,7 +598,7 @@ class Form
         $resql=$this->db->query($sql);
         if ($resql)
         {
-            $out.= '<select id="select'.$htmlname.'" class="flat selectcountry'.($morecss?' '.$morecss:'').'" name="'.$htmlname.'" '.$htmloption.'>';
+            $out.= '<select id="select'.$htmlname.'" class="flat maxwidth200onsmartphone selectcountry'.($morecss?' '.$morecss:'').'" name="'.$htmlname.'" '.$htmloption.'>';
             $num = $this->db->num_rows($resql);
             $i = 0;
             if ($num)
@@ -1444,7 +1444,7 @@ class Form
 		            $nodatarole=($comboenhancement?' data-role="none"':'');
 		        }
 
-                $out.= '<select class="flat'.($morecss?' minwidth100 '.$morecss:' minwidth200').'" id="'.$htmlname.'" name="'.$htmlname.'"'.($disabled?' disabled':'').$nodatarole.'>';
+                $out.= '<select class="flat maxwidth200onsmartphone'.($morecss?' minwidth100 '.$morecss:' minwidth200').'" id="'.$htmlname.'" name="'.$htmlname.'"'.($disabled?' disabled':'').$nodatarole.'>';
                 if ($show_empty) $out.= '<option value="-1"'.((empty($selected) || $selected==-1)?' selected':'').'>&nbsp;</option>'."\n";
 				if ($show_every) $out.= '<option value="-2"'.(($selected==-2)?' selected':'').'>-- '.$langs->trans("Everybody").' --</option>'."\n";
 
diff --git a/htdocs/core/class/html.formcompany.class.php b/htdocs/core/class/html.formcompany.class.php
index 05bbbd941d972a8617b5b9e5471becfbfcb27cd6..70dc0e253c4f76c5c8b1fba96bf7ec4aba36caf1 100644
--- a/htdocs/core/class/html.formcompany.class.php
+++ b/htdocs/core/class/html.formcompany.class.php
@@ -232,7 +232,7 @@ class FormCompany
 		$result=$this->db->query($sql);
 		if ($result)
 		{
-			if (!empty($htmlname)) $out.= '<select id="'.$htmlname.'" class="flat minwidth300" name="'.$htmlname.'">';
+			if (!empty($htmlname)) $out.= '<select id="'.$htmlname.'" class="flat maxwidth200onsmartphone minwidth300" name="'.$htmlname.'">';
 			if ($country_codeid) $out.= '<option value="0">&nbsp;</option>';
 			$num = $this->db->num_rows($result);
 			$i = 0;
@@ -743,7 +743,7 @@ class FormCompany
 			$out.= ajax_multiautocompleter($htmlname,$fields,DOL_URL_ROOT.'/core/ajax/ziptown.php')."\n";
 			$moreattrib.=' autocomplete="off"';
 		}
-		$out.= '<input id="'.$htmlname.'" type="text"'.($moreattrib?' '.$moreattrib:'').' name="'.$htmlname.'" '.$size.' value="'.$selected.'">'."\n";
+		$out.= '<input id="'.$htmlname.'" class="maxwidthonsmartphone" type="text"'.($moreattrib?' '.$moreattrib:'').' name="'.$htmlname.'" '.$size.' value="'.$selected.'">'."\n";
 
 		return $out;
 	}
@@ -792,9 +792,8 @@ class FormCompany
 
         $maxlength=$formlength;
         if (empty($formlength)) { $formlength=24; $maxlength=128; }
-        $formlength=0;
         
-        $out = '<input type="text" '.($morecss?'class="'.$morecss.'" ':'').'name="'.$htmlname.'" id="'.$htmlname.'" size="'.($formlength+1).'" maxlength="'.$maxlength.'" value="'.$selected.'">';
+        $out = '<input type="text" '.($morecss?'class="'.$morecss.'" ':'').'name="'.$htmlname.'" id="'.$htmlname.'" maxlength="'.$maxlength.'" value="'.$selected.'">';
 
         return $out;
     }
diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php
index e52818305b5f11e81222f5d3bb2e0a684fce4ff4..b8fab63f906c90027307ae6f81848d307b2270d7 100644
--- a/htdocs/core/class/html.formfile.class.php
+++ b/htdocs/core/class/html.formfile.class.php
@@ -731,7 +731,7 @@ class FormFile
     }
 
     /**
-     *	Show only Document icon with link
+     *	Show a Document icon with link(s)
      *
      *	@param	string	$modulepart		propal, facture, facture_fourn, ...
      *	@param	string	$modulesubdir	Sub-directory to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if file is not into subdir of module.
@@ -748,6 +748,8 @@ class FormFile
     	$out='';
     	$this->infofiles=array('nboffiles'=>0,'extensions'=>array(),'files'=>array());
 
+    	if (! empty($conf->dol_use_jmobile)) return '';
+    	 
 		$file_list=dol_dir_list($filedir, 'files', 0, preg_quote(basename($modulesubdir),'/').'[^\-]+', '\.meta$|\.png$');	// Get list of files starting with name of ref (but not followed by "-" to discard uploaded files)
 
     	// For ajax treatment
@@ -755,7 +757,7 @@ class FormFile
     	if (! empty($file_list))
     	{
     	    $out='<dl class="dropdown">
-    			<dt><a href="#" onClick="return false;">'.img_picto('', 'listlight').'</a></dt>
+    			<dt><a data-ajax="false" href="#" onClick="return false;">'.img_picto('', 'listlight').'</a></dt>
     			<dd><div class="multichoicedoc"><ul class="ulselectedfields" style="display: none;">';
     	    $tmpout='';
     	    
@@ -782,9 +784,11 @@ class FormFile
     			if (empty($this->infofiles[$ext])) $this->infofiles['extensions'][$ext]=1;
     			else $this->infofiles['extensions'][$ext]++;
     			
+    			// Preview
     			$urladvanced = getAdvancedPreviewUrl($modulepart, $relativepath);
-    		    if ($urladvanced) $tmpout.= '<li><a href="'.$urladvanced.'">'.img_picto('','detail').' '.$langs->trans("Preview").' '.$ext.'</a></li>';
-    			$tmpout.= '<li><a data-ajax="false" class="pictopreview" href="'.DOL_URL_ROOT . '/document.php?modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).'"';
+    		    if ($urladvanced) $tmpout.= '<li><a data-ajax="false" href="'.$urladvanced.'">'.img_picto('','detail').' '.$langs->trans("Preview").' '.$ext.'</a></li>';
+    			// Download
+    		    $tmpout.= '<li><a data-ajax="false" class="pictopreview" href="'.DOL_URL_ROOT . '/document.php?modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).'"';
     			$mime=dol_mimetype($relativepath,'',0);
     			if (preg_match('/text/',$mime)) $tmpout.= ' target="_blank"';
     			$tmpout.= '>';
diff --git a/htdocs/core/class/html.formmargin.class.php b/htdocs/core/class/html.formmargin.class.php
index 99159f6256138f8f1c076634cfdd3e25a4e7d013..0ac6012f271a0d4d2b4d2d3d75a66bf405bb7262 100644
--- a/htdocs/core/class/html.formmargin.class.php
+++ b/htdocs/core/class/html.formmargin.class.php
@@ -209,7 +209,7 @@ class FormMargin
     	    if (!empty($hidemargininfos)) print '<script>$(document).ready(function() {$(".margininfos").hide();});</script>';
 		}
 
-		print '<table class="border margintable" width="100%">';
+		print '<table class="noborder margintable centpercent">';
 		print '<tr class="liste_titre">';
 		print '<td class="liste_titre">'.$langs->trans('Margins').'</td>';
 		print '<td class="liste_titre" align="right">'.$langs->trans('SellingPrice').'</td>';
diff --git a/htdocs/core/lib/cron.lib.php b/htdocs/core/lib/cron.lib.php
index d7a0a57ac3789a445ea1bef73f59e42eccd5ca5e..64a4c5ef03154cee6a8700833dd3f8d48a35ccd6 100644
--- a/htdocs/core/lib/cron.lib.php
+++ b/htdocs/core/lib/cron.lib.php
@@ -104,7 +104,7 @@ function dol_print_cron_urls()
 	print '<u>'.$langs->trans("FileToLaunchCronJobs").':</u><br>';
 
 	$file='/scripts/cron/cron_run_jobs.php'.' '.(empty($conf->global->CRON_KEY)?'securitykey':''.$conf->global->CRON_KEY.'').' '.$user->login.' [cronjobid]';
-	print '<textarea rows="'.ROWS_2.'" cols="120">..'.$file."</textarea><br>\n";
+	print '<textarea class="quatrevingtpercent">..'.$file."</textarea><br>\n";
 	print '<br>';
 
 	// Add note
@@ -116,7 +116,7 @@ function dol_print_cron_urls()
 	{
 		print $langs->trans("CronExplainHowToRunUnix");
 		print '<br>';
-		print '<textarea rows="'.ROWS_1.'" style="width:80%">*/5 * * * * pathtoscript/scripts/cron/cron_run_jobs.php '.(empty($conf->global->CRON_KEY)?'securitykey':''.$conf->global->CRON_KEY.'').' '.$user->login.' &gt; '.DOL_DATA_ROOT.'/cron_run_jobs.php.log</textarea><br>';
+		print '<textarea class="quatrevingtpercent">*/5 * * * * pathtoscript/scripts/cron/cron_run_jobs.php '.(empty($conf->global->CRON_KEY)?'securitykey':''.$conf->global->CRON_KEY.'').' '.$user->login.' &gt; '.DOL_DATA_ROOT.'/cron_run_jobs.php.log</textarea><br>';
 	}
 	else
 	{
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index dfa724e7c64fbefb9ca7ced9e8934b0f90158e06..7c4a19d729b58373388cc83bba0a1b9095e99667 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -986,6 +986,12 @@ function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='r
             $morehtmlright.=$object->getLibStatut(5,1);
         }
 	}
+	elseif ($object->element == 'facture')
+	{
+	    $tmptxt=$object->getLibStatut(6, $object->totalpaye);
+	    if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3)) $tmptxt=$object->getLibStatut(5, $object->totalpaye); 
+		$morehtmlright.=$tmptxt;
+	}
 	else {
 	    $tmptxt=$object->getLibStatut(6);
 	    if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3)) $tmptxt=$object->getLibStatut(5); 
@@ -3117,19 +3123,21 @@ function print_barre_liste($titre, $page, $file, $options='', $sortfield='', $so
 	print '<table width="100%" border="0" class="notopnoleftnoright'.($morecss?' '.$morecss:'').'" style="margin-bottom: 6px;"><tr>';
 
 	// Left
-	if ($picto && $titre) print '<td class="nobordernopadding hideonsmartphone" width="40" align="left" valign="middle">'.img_picto('', $picto, 'id="pictotitle"', $pictoisfullpath).'</td>';
-	print '<td class="nobordernopadding"><div class="titre">'.$titre;
+	//if ($picto && $titre) print '<td class="nobordernopadding hideonsmartphone" width="40" align="left" valign="middle">'.img_picto('', $picto, 'id="pictotitle"', $pictoisfullpath).'</td>';
+	print '<td class="nobordernopadding" style="width: 35%" valign="middle">';
+	if ($picto && $titre) print img_picto('', $picto, 'class="hideonsmartphone valignmiddle" id="pictotitle"', $pictoisfullpath);
+	print '<div class="titre inline-block">'.$titre;
 	if (!empty($titre) && $savtotalnboflines > 0) print ' ('.$totalnboflines.')';
 	print '</div></td>';
 
 	// Center
 	if ($center)
 	{
-		print '<td class="nobordernopadding" align="left" valign="middle">'.$center.'</td>';
+		print '<td class="nobordernopadding center" style="width: 30%" valign="middle">'.$center.'</td>';
 	}
 
 	// Right
-	print '<td class="nobordernopadding" align="right" valign="middle">';
+	print '<td class="nobordernopadding" align="right" style="width: 35%" valign="middle">';
 	if ($sortfield) $options .= "&amp;sortfield=".$sortfield;
 	if ($sortorder) $options .= "&amp;sortorder=".$sortorder;
 	// Show navigation bar
diff --git a/htdocs/cron/admin/cron.php b/htdocs/cron/admin/cron.php
index 697b24fcc1e97f4bb3dde09012785bd95386f322..f41978eb757a87316cd3787aed9c4d2a9cd7ce7a 100644
--- a/htdocs/cron/admin/cron.php
+++ b/htdocs/cron/admin/cron.php
@@ -109,6 +109,7 @@ print '</form>';
 print '<br><br>';
 
 print $langs->trans("UseMenuModuleToolsToAddCronJobs").'<br>';
+if (! empty($conf->global->CRON_WARNING_DELAY_HOURS)) print info_admin($langs->trans("WarningCronDelayed", $conf->global->CRON_WARNING_DELAY_HOURS));
 
 print '<br><br>';
 
diff --git a/htdocs/cron/list.php b/htdocs/cron/list.php
index 69fa486752636feb2dd9878b609fac85f9afc071..49d916d2d9d0e4085101b6c04cd982462c314e36 100644
--- a/htdocs/cron/list.php
+++ b/htdocs/cron/list.php
@@ -275,9 +275,6 @@ print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
 print '<input type="hidden" name="viewstatut" value="'.$viewstatut.'">';
 
-print_barre_liste($pagetitle, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $stringcurrentdate, $num, $nbtotalofrecords, 'title_setup', 0, '', '', $limit);
-
-
 // Line with explanation and button new job
 if (! $user->rights->cron->create)
 {
@@ -287,7 +284,13 @@ else
 {
     $buttontoshow.='<a class="butAction" style="margin-right: 0px;margin-left: 0px;" href="'.DOL_URL_ROOT.'/cron/card.php?action=create">'.$langs->trans("CronCreateJob").'</a>';
 }
-print '<table class="centpercent"><tr><td>'.$langs->trans('CronInfo').'</td><td class="right">'.$buttontoshow.'</td></tr></table>';
+
+print_barre_liste($pagetitle, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $buttontoshow, $num, $nbtotalofrecords, 'title_setup', 0, '', '', $limit);
+
+
+print $langs->trans('CronInfo').'<br>';
+print $stringcurrentdate.'<br>';
+if (! empty($conf->global->CRON_WARNING_DELAY_HOURS)) print info_admin($langs->trans("WarningCronDelayed", $conf->global->CRON_WARNING_DELAY_HOURS));
 print '<br>';
 
 
diff --git a/htdocs/langs/en_US/cron.lang b/htdocs/langs/en_US/cron.lang
index b6d7bcf654505904dc002604ee69cb59833f66ff..6a700aa5760dc7b752e94989c54a573af74c5378 100644
--- a/htdocs/langs/en_US/cron.lang
+++ b/htdocs/langs/en_US/cron.lang
@@ -76,3 +76,4 @@ UseMenuModuleToolsToAddCronJobs=Go into menu "Home - Admin tools - Scheduled job
 JobDisabled=Job disabled
 MakeLocalDatabaseDumpShort=Local database backup
 MakeLocalDatabaseDump=Create a local database dump
+WarningCronDelayed=Attention, for performance purpose, whatever is next date of execution of active jobs, your jobs may be delayed to a maximum of %s hours before being run.
diff --git a/htdocs/paypal/lib/paypal.lib.php b/htdocs/paypal/lib/paypal.lib.php
index 6587e25ecb19077dc688063004945887c4f5c028..1496bb3552e48f80a7f067b4de0f043d708b3411 100644
--- a/htdocs/paypal/lib/paypal.lib.php
+++ b/htdocs/paypal/lib/paypal.lib.php
@@ -209,7 +209,7 @@ function showPaypalPaymentUrl($type,$ref)
     $out='<br><br>';
     $out.=img_picto('','object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePayment",$servicename).'<br>';
     $url=getPaypalPaymentUrl(0,$type,$ref);
-    $out.='<input type="text" id="paypalurl" value="'.$url.'" size="60"><br>';
+    $out.='<input type="text" id="paypalurl" class="quatrevingtpercent" value="'.$url.'"><br>';
     return $out;
 }
 
diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php
index 675544566e8eb5150f3b02a74ffcf6317d212715..22af7a3dae87006429d53518a71874620c3697ea 100644
--- a/htdocs/societe/soc.php
+++ b/htdocs/societe/soc.php
@@ -981,7 +981,7 @@ else
 			print '<span span id="TypeName" class="fieldrequired">'.fieldLabel('ThirdPartyName','name').'</span>';
         }
 	    print '</td><td'.(empty($conf->global->SOCIETE_USEPREFIX)?' colspan="3"':'').'>';
-	    print '<input type="text" size="60" maxlength="128" name="name" id="name" value="'.$object->name.'" autofocus="autofocus"></td>';
+	    print '<input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="'.$object->name.'" autofocus="autofocus"></td>';
 	    if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
 	    {
 		    print '<td>'.$langs->trans('Prefix').'</td><td><input type="text" size="5" maxlength="5" name="prefix_comm" value="'.$object->prefix_comm.'"></td>';
@@ -1001,7 +1001,7 @@ else
 
         // Alias names (commercial, trademark or alias names)
         print '<tr id="name_alias"><td><label for="name_alias_input">'.$langs->trans('AliasNames').'</label></td>';
-	    print '<td colspan="3"><input type="text" size="60" name="name_alias" id="name_alias_input" value="'.$object->name_alias.'" size="32"></td></tr>';
+	    print '<td colspan="3"><input type="text" class="minwidth300" name="name_alias" id="name_alias_input" value="'.$object->name_alias.'"></td></tr>';
 
         // Prospect/Customer
         print '<tr><td class="titlefieldcreate">'.fieldLabel('ProspectCustomer','customerprospect',1).'</td>';
@@ -1015,11 +1015,11 @@ else
         print '<option value="0"'.((string) $selected == '0'?' selected':'').'>'.$langs->trans('NorProspectNorCustomer').'</option>';
         print '</select></td>';
 
-        print '<td>'.fieldLabel('CustomerCode','customer_code').'</td><td width="25%">';
+        print '<td>'.fieldLabel('CustomerCode','customer_code').'</td><td>';
         print '<table class="nobordernopadding"><tr><td>';
 		$tmpcode=$object->code_client;
         if (empty($tmpcode) && ! empty($modCodeClient->code_auto)) $tmpcode=$modCodeClient->getNextValue($object,0);
-        print '<input type="text" name="code_client" id="customer_code" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
+        print '<input type="text" name="code_client" id="customer_code" class="maxwidthonsmartphone" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
         print '</td><td>';
         $s=$modCodeClient->getToolTip($langs,$object,0);
         print $form->textwithpicto('',$s,1);
@@ -1039,7 +1039,7 @@ else
             print '<table class="nobordernopadding"><tr><td>';
             $tmpcode=$object->code_fournisseur;
             if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) $tmpcode=$modCodeFournisseur->getNextValue($object,1);
-            print '<input type="text" name="code_fournisseur" id="supplier_code" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
+            print '<input type="text" name="code_fournisseur" id="supplier_code" class="maxwidthonsmartphone" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
             print '</td><td>';
             $s=$modCodeFournisseur->getToolTip($langs,$object,1);
             print $form->textwithpicto('',$s,1);
@@ -1074,7 +1074,7 @@ else
         print '</td></tr>';
 
         // Country
-        print '<tr><td width="25%">'.fieldLabel('Country','selectcountry_id').'</td><td colspan="3" class="maxwidthonsmartphone">';
+        print '<tr><td>'.fieldLabel('Country','selectcountry_id').'</td><td colspan="3" class="maxwidthonsmartphone">';
         print $form->select_country((GETPOST('country_id')!=''?GETPOST('country_id'):$object->country_id));
         if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
         print '</td></tr>';
@@ -1103,9 +1103,9 @@ else
 
         // Phone / Fax
         print '<tr><td>'.fieldLabel('Phone','phone').'</td>';
-	    print '<td><input type="text" name="phone" id="phone" value="'.$object->phone.'"></td>';
+	    print '<td><input type="text" name="phone" id="phone" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->phone.'"></td>';
         print '<td>'.fieldLabel('Fax','fax').'</td>';
-	    print '<td><input type="text" name="fax" id="fax" value="'.$object->fax.'"></td></tr>';
+	    print '<td><input type="text" name="fax" id="fax" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->fax.'"></td></tr>';
 
         // Prof ids
         $i=1; $j=0;
@@ -1137,7 +1137,7 @@ else
         print '</td>';
         print '<td class="nowrap">'.fieldLabel('VATIntra','intra_vat').'</td>';
         print '<td class="nowrap">';
-        $s = '<input type="text" class="flat" name="tva_intra" id="intra_vat" size="12" maxlength="20" value="'.$object->tva_intra.'">';
+        $s = '<input type="text" class="flat maxwidthonsmartphone" name="tva_intra" id="intra_vat" maxlength="20" value="'.$object->tva_intra.'">';
 
         if (empty($conf->global->MAIN_DISABLEVATCHECK))
         {
@@ -1220,7 +1220,7 @@ else
         if (! empty($conf->global->MAIN_MULTILANGS))
         {
             print '<tr><td>'.fieldLabel('DefaultLang','default_lang').'</td><td colspan="3" class="maxwidthonsmartphone">'."\n";
-            print $formadmin->select_language(($object->default_lang?$object->default_lang:$conf->global->MAIN_LANG_DEFAULT),'default_lang',0,0,1);
+            print $formadmin->select_language(($object->default_lang?$object->default_lang:$conf->global->MAIN_LANG_DEFAULT),'default_lang',0,0,1,0,0,'maxwidth200onsmartphone');
             print '</td>';
             print '</tr>';
         }
@@ -1510,11 +1510,11 @@ else
 
             // Name
             print '<tr><td class="titlefield">'.fieldLabel('ThirdPartyName','name',1).'</td>';
-	        print '<td colspan="3"><input type="text" size="60" maxlength="128" name="name" id="name" value="'.dol_escape_htmltag($object->name).'" autofocus="autofocus"></td></tr>';
+	        print '<td colspan="3"><input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="'.dol_escape_htmltag($object->name).'" autofocus="autofocus"></td></tr>';
 
 	        // Alias names (commercial, trademark or alias names)
 	        print '<tr id="name_alias"><td><label for="name_alias_input">'.$langs->trans('AliasNames').'</label></td>';
-	        print '<td colspan="3"><input type="text" size="60" name="name_alias" id="name_alias_input" value="'.dol_escape_htmltag($object->name_alias).'"></td></tr>';
+	        print '<td colspan="3"><input type="text" class="minwidth300" name="name_alias" id="name_alias_input" value="'.dol_escape_htmltag($object->name_alias).'"></td></tr>';
 
             // Prefix
             if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
@@ -1541,7 +1541,7 @@ else
             if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="1"'.($object->client==1?' selected':'').'>'.$langs->trans('Customer').'</option>';
             print '<option value="0"'.($object->client==0?' selected':'').'>'.$langs->trans('NorProspectNorCustomer').'</option>';
             print '</select></td>';
-            print '<td width="25%">'.fieldLabel('CustomerCode','customer_code').'</td><td width="25%">';
+            print '<td>'.fieldLabel('CustomerCode','customer_code').'</td><td>';
 
             print '<table class="nobordernopadding"><tr><td>';
             if ((!$object->code_client || $object->code_client == -1) && $modCodeClient->code_auto)
@@ -1656,9 +1656,9 @@ else
 
             // Phone / Fax
             print '<tr><td>'.fieldLabel('Phone','phone').'</td>';
-	        print '<td><input type="text" name="phone" id="phone" value="'.$object->phone.'"></td>';
+	        print '<td><input type="text" name="phone" id="phone" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->phone.'"></td>';
             print '<td>'.fieldLabel('Fax','fax').'</td>';
-	        print '<td><input type="text" name="fax" id="fax" value="'.$object->fax.'"></td></tr>';
+	        print '<td><input type="text" name="fax" id="fax" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->fax.'"></td></tr>';
 
             // Prof ids
             $i=1; $j=0;
@@ -1694,7 +1694,7 @@ else
             // VAT Code
             print '<td>'.fieldLabel('VATIntra','intra_vat').'</td>';
             print '<td>';
-            $s ='<input type="text" class="flat" name="tva_intra" id="intra_vat" size="12" maxlength="20" value="'.$object->tva_intra.'">';
+            $s ='<input type="text" class="flat maxwidthonsmartphone" name="tva_intra" id="intra_vat" maxlength="20" value="'.$object->tva_intra.'">';
 
             if (empty($conf->global->MAIN_DISABLEVATCHECK))
             {
@@ -2040,7 +2040,7 @@ else
         {
             $s='';
             $s.=$object->tva_intra;
-            $s.='<input type="hidden" id="tva_intra" name="tva_intra" size="12" maxlength="20" value="'.$object->tva_intra.'">';
+            $s.='<input type="hidden" id="tva_intra" name="tva_intra" maxlength="20" value="'.$object->tva_intra.'">';
 
             if (empty($conf->global->MAIN_DISABLEVATCHECK))
             {
diff --git a/htdocs/theme/eldy/style.css.php b/htdocs/theme/eldy/style.css.php
index 1d860f5f378305dbe1976c769d325a72c79da8c9..8eb7e277a00d12381bed3943526cdaec2a49408b 100644
--- a/htdocs/theme/eldy/style.css.php
+++ b/htdocs/theme/eldy/style.css.php
@@ -277,7 +277,7 @@ input, input.flat, textarea, textarea.flat, form.flat select, select, select.fla
 }
 
 input, textarea, select {
-	border-radius:4px;
+	border-radius: 2px;
 	border:solid 1px rgba(0,0,0,.3);
 	border-top:solid 1px rgba(0,0,0,.3);
 	border-bottom:solid 1px rgba(0,0,0,.2);
@@ -337,7 +337,6 @@ textarea:disabled {
 input[type=checkbox] { background-color: transparent; border: none; box-shadow: none; }
 input[type=radio]    { background-color: transparent; border: none; box-shadow: none; }
 input[type=image]    { background-color: transparent; border: none; box-shadow: none; }
-input[type=text]     { min-width: 20px; }
 input:-webkit-autofill {
 	background-color: <?php echo empty($dol_use_jmobile)?'#FBFFEA':'#FFFFFF' ?> !important;
 	background-image:none !important;
@@ -380,9 +379,9 @@ fieldset { border: 1px solid #AAAAAA !important; }
 	filter: progid:DXImageTransform.Microsoft.gradient(enabled = false);
 	border: 1px solid #bbbbbb;
 	border-bottom-color: #a2a2a2;
-	-webkit-border-radius: 4px;
-	-moz-border-radius: 4px;
-	border-radius: 4px;
+	-webkit-border-radius: 2px;
+	-moz-border-radius: 2px;
+	border-radius: 2px;
 	-webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
 	-moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
 	box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
@@ -581,6 +580,14 @@ div.myavailability {
 .tablelistofcalendars {
 	margin-top: 25px !important;
 }
+.amountalreadypaid {
+	color: #008800;
+	font-weight: bold;
+}
+.amountremaintopay {
+	color: #880000;
+	font-weight: bold;
+}
 
 /* DOL_XXX for future usage (when left menu has been removed). If we do not use datatable */
 .table-responsive {
@@ -599,17 +606,21 @@ div.myavailability {
 .clearboth  { clear:both; }
 .hideobject { display: none; }
 .minwidth50  { min-width: 50px; }
-.minwidth100 { min-width: 100px; }
-.minwidth200 { min-width: 200px; }
-.minwidth300 { min-width: 300px; }
-.minwidth400 { min-width: 400px; }
-.minwidth500 { min-width: 500px; }
-.minwidth50imp  { min-width: 50px !important; }
-.minwidth100imp { min-width: 100px !important; }
-.minwidth200imp { min-width: 200px !important; }
-.minwidth300imp { min-width: 300px !important; }
-.minwidth400imp { min-width: 400px !important; }
-.minwidth500imp { min-width: 500px !important; }
+/* rule to reduce top menu - 3rd reduction */
+@media only screen and (min-width: <?php echo round($nbtopmenuentries * $fontsize * 3.4, 0) + 7; ?>px)
+{
+    .minwidth100 { min-width: 100px; }
+    .minwidth200 { min-width: 200px; }
+    .minwidth300 { min-width: 300px; }
+    .minwidth400 { min-width: 400px; }
+    .minwidth500 { min-width: 500px; }
+    .minwidth50imp  { min-width: 50px !important; }
+    .minwidth100imp { min-width: 100px !important; }
+    .minwidth200imp { min-width: 200px !important; }
+    .minwidth300imp { min-width: 300px !important; }
+    .minwidth400imp { min-width: 400px !important; }
+    .minwidth500imp { min-width: 500px !important; }
+}
 .maxwidth100 { max-width: 100px; }
 .maxwidth150 { max-width: 150px; }
 .maxwidth200 { max-width: 200px; }
@@ -648,6 +659,8 @@ div.myavailability {
 /* Force values for small screen */
 @media only screen and (max-width: 570px)
 {
+	input[type=text]     { min-width: 20px; }
+
     .hideonsmartphone { display: none; }
     .noenlargeonsmartphone { width : 50px !important; display: inline !important; }
     .maxwidthonsmartphone { max-width: 100px; }
@@ -2081,9 +2094,9 @@ span.butAction, span.butActionDelete {
   filter: progid:DXImageTransform.Microsoft.gradient(enabled = false);
   border: 1px solid #bbbbbb;
   border-bottom-color: #a2a2a2;
-  -webkit-border-radius: 4px;
-  -moz-border-radius: 4px;
-  border-radius: 4px;
+  -webkit-border-radius: 2px;
+  -moz-border-radius: 2px;
+  border-radius: 2px;
   -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
   -moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
   box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
@@ -2828,6 +2841,7 @@ tr.liste_sub_total, tr.liste_sub_total td {
 	border-top-width: <?php echo $borderwith ?>px !important;
 	border-top-color: rgb(<?php echo $colortopbordertitle1 ?>) !important;
 	border-top-style: solid !important;
+	margin: 0px 0px 0px 0px !important;
 }
 .paymenttable tr td:first-child, .margintable tr td:first-child
 {
@@ -3959,8 +3973,12 @@ div.dataTables_length select {
 /*  Select2                                                                       */
 /* ============================================================================== */
 
+.select2-container-multi .select2-choices {
+	background-image: none;
+}
 .select2-container .select2-choice {
 	color: #000;
+	border-radius: 0;
 }
 .selectoptiondisabledwhite {
 	background: #FFFFFF !important;
@@ -4287,20 +4305,40 @@ ul.ulmenu {
 }
 
 /* Style for first level menu with jmobile */
+.ui-li .ui-btn-inner a.ui-link-inherit, .ui-li-static.ui-li {
+    padding: .9em 15px;
+    display: block;
+}
+.ui-btn-up-c {
+	font-weight: normal;
+}
+.ui-bar-b {
+    border: 1px solid #888;
+    text-shadow: none;
+}
+.ui-focus, .ui-btn:focus {
+    -moz-box-shadow: none;
+    -webkit-box-shadow: none;
+    box-shadow: none;
+}
 .ui-bar-b, .lilevel0 {
-	border: 1px solid #888 !important;
+/*	border: 1px solid #888 !important; */
     background: rgb(<?php echo $colorbacktitle1; ?>);
     background-repeat: repeat-x;
 
+/*
 	background-image: -o-linear-gradient(bottom, rgba(0,0,0,0.3) 0%, rgba(250,250,250,0.3) 100%);
 	background-image: -moz-linear-gradient(bottom, rgba(0,0,0,0.3) 0%, rgba(250,250,250,0.3) 100%);
 	background-image: -webkit-linear-gradient(bottom, rgba(0,0,0,0.3) 0%, rgba(250,250,250,0.3) 100%);
 	background-image: -ms-linear-gradient(bottom, rgba(0,0,0,0.3) 0%, rgba(250,250,250,0.3) 100%);
-	background-image: linear-gradient(bottom, rgba(0,0,0,0.3) 0%, rgba(250,250,250,0.3) 100%);
+	background-image: linear-gradient(bottom, rgba(0,0,0,0.3) 0%, rgba(250,250,250,0.3) 100%);*/
     font-weight: bold;
 
     color: rgb(<?php echo $colortexttitle; ?>) !important;
 }
+.ui-li.ui-last-child, .ui-li.ui-field-contain.ui-last-child {
+    border-bottom-width: 0px !important;
+}
 .alilevel0 {
     color: rgb(<?php echo $colortexttitle; ?>) !important;
 	text-shadow: 1px 0px 1px #<?php echo $colorshadowtitle; ?>;
@@ -4313,7 +4351,7 @@ ul.ulmenu {
 	text-shadow: none;
 }
 .ui-btn-up-c, .ui-btn-hover-c {
-	border: 1px solid #ccc;
+	/* border: 1px solid #ccc; */
 	text-shadow: none;
 }
 .ui-body-c .ui-link, .ui-body-c .ui-link:visited, .ui-body-c .ui-link:hover {
@@ -4487,7 +4525,7 @@ img.demothumb {
 
 /* nboftopmenuentries = <?php echo $nbtopmenuentries ?>, fontsize=<?php echo $fontsize ?> */
 /* rule to reduce top menu - 1st reduction */
-@media only screen and (max-width: <?php echo round($nbtopmenuentries * $fontsize * 7, 0) + 20; ?>px)
+@media only screen and (max-width: <?php echo round($nbtopmenuentries * $fontsize * 6.9, 0) + 20; ?>px)
 {
 	div.tmenucenter {
 	    max-width: <?php echo round($fontsize * 4); ?>px;	/* size of viewport */
@@ -4533,9 +4571,12 @@ img.demothumb {
     	background-size: 20px auto;
     	margin-top: 2px;
 	}
+	select {
+		width: 100%;
+	}
 }
 /* rule to reduce top menu - 3rd reduction */
-@media only screen and (max-width: 660px)
+@media only screen and (max-width: <?php echo round($nbtopmenuentries * $fontsize * 3.4, 0) + 8; ?>px)
 {
 	/* Reduce login top right info */
 	.usertextatoplogin {
@@ -4588,6 +4629,12 @@ img.demothumb {
 		position: absolute;
 		width: <?php print dol_size(300,'width'); ?>px;
 	}
+	select {
+		width: 100%;
+		max-width: 100px;
+		min-width: 0 !important;
+	}
+	
 }
 
 <?php
diff --git a/htdocs/theme/md/style.css.php b/htdocs/theme/md/style.css.php
index 1db2b6fe7a3e331416c6e33d82ce115b780beb20..a08f2475436401bf2fcac3d1cd23e80c994db332 100644
--- a/htdocs/theme/md/style.css.php
+++ b/htdocs/theme/md/style.css.php
@@ -4169,11 +4169,11 @@ ul.ulmenu {
     background: rgb(<?php echo $colorbacktitle1; ?>);
     background-repeat: repeat-x;
 
-	background-image: -o-linear-gradient(bottom, rgba(0,0,0,0.3) 0%, rgba(250,250,250,0.3) 100%);
+	/*background-image: -o-linear-gradient(bottom, rgba(0,0,0,0.3) 0%, rgba(250,250,250,0.3) 100%);
 	background-image: -moz-linear-gradient(bottom, rgba(0,0,0,0.3) 0%, rgba(250,250,250,0.3) 100%);
 	background-image: -webkit-linear-gradient(bottom, rgba(0,0,0,0.3) 0%, rgba(250,250,250,0.3) 100%);
 	background-image: -ms-linear-gradient(bottom, rgba(0,0,0,0.3) 0%, rgba(250,250,250,0.3) 100%);
-	background-image: linear-gradient(bottom, rgba(0,0,0,0.3) 0%, rgba(250,250,250,0.3) 100%);
+	background-image: linear-gradient(bottom, rgba(0,0,0,0.3) 0%, rgba(250,250,250,0.3) 100%);*/
     font-weight: bold;
 
     color: rgb(<?php echo $colortexttitle; ?>) !important;