diff --git a/htdocs/margin/agentMargins.php b/htdocs/margin/agentMargins.php
index e00eb4ae18b..6c3a246ad0d 100644
--- a/htdocs/margin/agentMargins.php
+++ b/htdocs/margin/agentMargins.php
@@ -34,14 +34,6 @@ $langs->load("bills");
$langs->load("products");
$langs->load("margins");
-// Security check
-
-if ($user->rights->margins->read->all) {
- $agentid = GETPOST('agentid', 'int');
-} else {
- $agentid = $user->id;
-}
-
$mesg = '';
// Load variable for pagination
@@ -69,6 +61,23 @@ if (!empty($_POST['startdatemonth']))
if (!empty($_POST['enddatemonth']))
$enddate = dol_mktime(23, 59, 59, $_POST['enddatemonth'], $_POST['enddateday'], $_POST['enddateyear']);
+// Security check
+if ($user->rights->margins->read->all) {
+ $agentid = GETPOST('agentid', 'int');
+} else {
+ $agentid = $user->id;
+}
+$result=restrictedArea($user,'margins');
+
+
+/*
+ * Actions
+ */
+
+// None
+
+
+
/*
* View
*/
diff --git a/htdocs/margin/checkMargins.php b/htdocs/margin/checkMargins.php
index c576b3ce4a6..ab6394eb74c 100644
--- a/htdocs/margin/checkMargins.php
+++ b/htdocs/margin/checkMargins.php
@@ -34,72 +34,35 @@ $langs->load("bills");
$langs->load("products");
$langs->load("margins");
-// Security check
-
-if ($user->rights->margins->creer) {
- $agentid = $user->id;
-} else {
- accessforbidden();
-}
-
-$sortfield = GETPOST("sortfield", 'alpha');
-$sortorder = GETPOST("sortorder", 'alpha');
-if (! $sortorder)
- $sortorder = "DESC";
-if (! $sortfield) {
- $sortfield = 'f.facnumber';
-}
-$page = GETPOST("page", 'int');
-if ($page == - 1) {
- $page = 0;
-}
-$offset = $conf->liste_limit * $page;
+// Load variable for pagination
+$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
+$sortfield = GETPOST('sortfield','alpha');
+$sortorder = GETPOST('sortorder','alpha');
+$page = GETPOST('page','int');
+if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
+$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
-
-// Both test are required to be compatible with all browsers
-if (GETPOST("button_search_x") || GETPOST("button_search")) {
- $action = 'search';
-} elseif (GETPOST("button_updatemagins_x") || GETPOST("button_updatemagins")) {
- $action = 'update';
-}
-
-if ($action == 'update') {
- $datapost = $_POST;
-
- foreach ( $datapost as $key => $value ) {
- if (strpos($key, 'buyingprice_') !== false) {
- $tmp_array = explode('_', $key);
- if (count($tmp_array) > 0) {
- $invoicedet_id = $tmp_array[1];
- if (! empty($invoicedet_id)) {
- $sql = 'UPDATE ' . MAIN_DB_PREFIX . 'facturedet';
- $sql .= ' SET buy_price_ht=\'' . price2num($value) . '\'';
- $sql .= ' WHERE rowid=' . $invoicedet_id;
- $result = $db->query($sql);
- if (!$result) {
- setEventMessages($db->lasterror, null, 'errors');
- }
- }
- }
- }
- }
-}
+if (! $sortorder) $sortorder = "DESC";
+if (! $sortfield) $sortfield = 'f.facnumber';
$startdate = $enddate = '';
$startdate = dol_mktime(0, 0, 0, GETPOST('startdatemonth', 'int'), GETPOST('startdateday', 'int'), GETPOST('startdateyear', 'int'));
$enddate = dol_mktime(23, 59, 59, GETPOST('enddatemonth', 'int'), GETPOST('enddateday', 'int'), GETPOST('enddateyear', 'int'));
-if (! empty($startdate)) {
- $options .= '&startdatemonth=' . GETPOST('startdatemonth', 'int') . '&startdateday=' . GETPOST('startdateday', 'int') . '&startdateyear=' . GETPOST('startdateyear', 'int');
-}
-if (! empty($enddate)) {
- $options .= '&enddatemonth=' . GETPOST('enddatemonth', 'int') . '&enddateday=' . GETPOST('enddateday', 'int') . '&enddateyear=' . GETPOST('enddateyear', 'int');
-}
-
$search_ref = GETPOST('search_ref','alpha');
+// Security check
+$result=restrictedArea($user,'margins');
+
+// Both test are required to be compatible with all browsers
+if (GETPOST("button_search_x") || GETPOST("button_search")) {
+ $action = 'search';
+} elseif (GETPOST("button_updatemagins_x") || GETPOST("button_updatemagins")) {
+ $action = 'update';
+}
+
/*
* Actions
@@ -117,6 +80,28 @@ if (empty($reshook))
// Selection of new fields
include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
+ if ($action == 'update') {
+ $datapost = $_POST;
+
+ foreach ( $datapost as $key => $value ) {
+ if (strpos($key, 'buyingprice_') !== false) {
+ $tmp_array = explode('_', $key);
+ if (count($tmp_array) > 0) {
+ $invoicedet_id = $tmp_array[1];
+ if (! empty($invoicedet_id)) {
+ $sql = 'UPDATE ' . MAIN_DB_PREFIX . 'facturedet';
+ $sql .= ' SET buy_price_ht=\'' . price2num($value) . '\'';
+ $sql .= ' WHERE rowid=' . $invoicedet_id;
+ $result = $db->query($sql);
+ if (!$result) {
+ setEventMessages($db->lasterror, null, 'errors');
+ }
+ }
+ }
+ }
+ }
+ }
+
// 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
{
@@ -155,6 +140,17 @@ llxHeader('', $title);
// print_fiche_titre($text);
+$param='';
+if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
+if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
+if (! empty($startdate)) {
+ $param .= '&startdatemonth=' . GETPOST('startdatemonth', 'int') . '&startdateday=' . GETPOST('startdateday', 'int') . '&startdateyear=' . GETPOST('startdateyear', 'int');
+}
+if (! empty($enddate)) {
+ $param .= '&enddatemonth=' . GETPOST('enddatemonth', 'int') . '&enddateday=' . GETPOST('enddateday', 'int') . '&enddateyear=' . GETPOST('enddateyear', 'int');
+}
+if ($optioncss != '') $param.='&optioncss='.$optioncss;
+
// Show tabs
$head = marges_prepare_head($user);
$picto = 'margin';
@@ -202,7 +198,7 @@ $sql .= $db->order($sortfield, $sortorder);
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
-
+
dol_syslog(__FILE__, LOG_DEBUG);
$result = $db->query($sql);
if ($result) {
@@ -212,31 +208,30 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
}
}
-$sql .= $db->plimit($conf->liste_limit + 1, $offset);
+$sql .= $db->plimit($limit+1, $offset);
-dol_syslog(__FILE__, LOG_DEBUG);
$result = $db->query($sql);
if ($result) {
$num = $db->num_rows($result);
-
+
print '
';
- print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num, $nbtotalofrecords, '');
-
+ print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '', 0, '', '', $limit);
+
if ($conf->global->MARGIN_TYPE == "1")
$labelcostprice=$langs->trans('BuyingPrice');
else // value is 'costprice' or 'pmp'
$labelcostprice=$langs->trans('CostPrice');
-
+
$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 ' | '; @@ -249,66 +244,66 @@ if ($result) { print $searchpitco; print ''; print " | |||||
| '; - $result_inner = $invoicestatic->fetch($objp->invoiceid); - if ($result_inner < 0) { - setEventMessages($invoicestatic->error, null, 'errors'); - } else { - print $invoicestatic->getNomUrl(1); - } - print ' | '; - print ''; - if (! empty($objp->fk_product)) { - $result_inner = $productstatic->fetch($objp->fk_product); - if ($result_inner < 0) { - setEventMessages($productstatic->error, null, 'errors'); - } else { - print $productstatic->getNomUrl(1); - } - } else { - print $objp->label; - print ' '; - print $objp->description; - } - print ' | '; - print ''; - print price($objp->subprice); - print ' | '; - print ''; - print ''; - print ' | '; - print ''; - print $objp->qty; - print ' | '; - print ''; - print price($objp->total_ht); - print ' | '; - print ''; - - print " |
| '; + $result_inner = $invoicestatic->fetch($objp->invoiceid); + if ($result_inner < 0) { + setEventMessages($invoicestatic->error, null, 'errors'); + } else { + print $invoicestatic->getNomUrl(1); } + print ' | '; + print ''; + if (! empty($objp->fk_product)) { + $result_inner = $productstatic->fetch($objp->fk_product); + if ($result_inner < 0) { + setEventMessages($productstatic->error, null, 'errors'); + } else { + print $productstatic->getNomUrl(1); + } + } else { + print $objp->label; + print ' '; + print $objp->description; + } + print ' | '; + print ''; + print price($objp->subprice); + print ' | '; + print ''; + print ''; + print ' | '; + print ''; + print $objp->qty; + print ' | '; + print ''; + print price($objp->total_ht); + print ' | '; + print ''; + + print " |