diff --git a/htdocs/margin/checkMargins.php b/htdocs/margin/checkMargins.php
index b3c663ad886..9656fa99fd9 100644
--- a/htdocs/margin/checkMargins.php
+++ b/htdocs/margin/checkMargins.php
@@ -47,7 +47,7 @@ $sortorder = GETPOST("sortorder", 'alpha');
if (! $sortorder)
$sortorder = "DESC";
if (! $sortfield) {
- $sortfield = 'f.rowid';
+ $sortfield = 'f.facnumber';
}
$page = GETPOST("page", 'int');
if ($page == - 1) {
@@ -98,6 +98,46 @@ if (! empty($enddate)) {
$options .= '&enddatemonth=' . GETPOST('enddatemonth', 'int') . '&enddateday=' . GETPOST('enddateday', 'int') . '&enddateyear=' . GETPOST('enddateyear', 'int');
}
+$search_ref = GETPOST('search_ref','alpha');
+
+
+/*
+ * Actions
+ */
+
+if (GETPOST('cancel')) { $action='list'; $massaction=''; }
+if (! GETPOST('confirmmassaction') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; }
+
+$parameters=array();
+$reshook=$hookmanager->executeHooks('doActions',$parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
+if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
+
+if (empty($reshook))
+{
+ // Selection of new fields
+ include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
+
+ // Purge search criteria
+ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All tests are required to be compatible with all browsers
+ {
+ $search_ref='';
+ $search_array_options=array();
+ }
+
+ // Mass actions
+ /*
+ $objectclass='Product';
+ if ((string) $type == '1') { $objectlabel='Services'; }
+ if ((string) $type == '0') { $objectlabel='Products'; }
+
+ $permtoread = $user->rights->produit->lire;
+ $permtodelete = $user->rights->produit->supprimer;
+ $uploaddir = $conf->product->dir_output;
+ include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
+ */
+}
+
+
/*
* View
*/
@@ -125,8 +165,7 @@ dol_fiche_head($head, $langs->trans('checkMargins'), $title, 0, $picto);
print '
';
-// Start date
-print '| ' . $langs->trans('DateStart') . ' (' . $langs->trans("DateValidation") . ') | ';
+print '| ' . $langs->trans('DateStart') . ' (' . $langs->trans("DateValidation") . ') | ';
print '';
$form->select_date($startdate, 'startdate', '', '', 1, "sel", 1, 1);
print ' | ';
@@ -136,12 +175,17 @@ $form->select_date($enddate, 'enddate', '', '', 1, "sel", 1, 1);
print '';
print '';
print '';
-print ' |
';
+print '';
+print '';
print "
";
dol_fiche_end();
+$arrayfields=array();
+$massactionbutton='';
+
+
$sql = "SELECT";
$sql .= " f.facnumber, f.rowid as invoiceid, d.rowid as invoicedetid, d.buy_price_ht, d.total_ht, d.subprice, d.label, d.description , d.qty";
$sql .= " ,d.fk_product";
@@ -150,10 +194,9 @@ $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "facturedet as d ON d.fk_facture = f.
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON d.fk_product = p.rowid";
$sql .= " WHERE f.fk_statut > 0";
$sql .= " AND f.entity = " . getEntity('facture', 1);
-if (! empty($startdate))
- $sql .= " AND f.datef >= '" . $db->idate($startdate) . "'";
-if (! empty($enddate))
- $sql .= " AND f.datef <= '" . $db->idate($enddate) . "'";
+if (! empty($startdate)) $sql .= " AND f.datef >= '" . $db->idate($startdate) . "'";
+if (! empty($enddate)) $sql .= " AND f.datef <= '" . $db->idate($enddate) . "'";
+if ($search_ref) $sql.=natural_search('f.facnumber', $search_ref);
$sql .= " AND d.buy_price_ht IS NOT NULL";
$sql .= $db->order($sortfield, $sortorder);
@@ -186,27 +229,43 @@ if ($result) {
$moreforfilter='';
+ $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
+ //$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
+ //if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
+ $selectedfields='';
+
print '';
print '
'."\n";
+ print '';
+ print ' | ';
+ print ' | ';
+ print ' | ';
+ print ' | ';
+ print ' | ';
+ print ' | ';
+ print '';
+ $searchpitco=$form->showFilterButtons();
+ print $searchpitco;
+ print ' | ';
+ print "
\n";
+
print '';
-
- print_liste_field_titre($langs->trans("Ref"), $_SERVER["PHP_SELF"], "f.ref", "", $options, '', $sortfield, $sortorder);
+ print_liste_field_titre($langs->trans("Ref"), $_SERVER["PHP_SELF"], "f.facnumber", "", $options, '', $sortfield, $sortorder);
print_liste_field_titre($langs->trans("Description"), $_SERVER["PHP_SELF"], "", "", $options, 'width=20%', $sortfield, $sortorder);
print_liste_field_titre($langs->trans("UnitPriceHT"), $_SERVER["PHP_SELF"], "d.subprice", "", $options, 'align="right"', $sortfield, $sortorder);
print_liste_field_titre($labelcostprice, $_SERVER["PHP_SELF"], "d.buy_price_ht", "", $options, 'align="right"', $sortfield, $sortorder);
print_liste_field_titre($langs->trans("Qty"), $_SERVER["PHP_SELF"], "d.qty", "", $options, 'align="right"', $sortfield, $sortorder);
print_liste_field_titre($langs->trans("AmountTTC"), $_SERVER["PHP_SELF"], "d.total_ht", "", $options, 'align="right"', $sortfield, $sortorder);
-
+ print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
print "
\n";
if ($num > 0) {
- $var = true;
-
- while ( $objp = $db->fetch_object($result) ) {
+ while ($objp = $db->fetch_object($result))
+ {
$var = ! $var;
- print "";
+ print '
';
print '| ';
$result_inner = $invoicestatic->fetch($objp->invoiceid);
if ($result_inner < 0) {
@@ -241,7 +300,8 @@ if ($result) {
print ' | ';
print price($objp->total_ht);
print ' | ';
-
+ print ' | ';
+
print "
\n";
$i ++;
@@ -255,8 +315,8 @@ if ($result) {
}
-print '