diff --git a/htdocs/comm/mailing/cibles.php b/htdocs/comm/mailing/cibles.php
index dd8ba5902ce..95639a25997 100644
--- a/htdocs/comm/mailing/cibles.php
+++ b/htdocs/comm/mailing/cibles.php
@@ -404,7 +404,7 @@ if ($object->fetch($id) >= 0) {
}
print '
';
- if ($nbofrecipient >= 0) {
+ if ($nbofrecipient === '' || $nbofrecipient >= 0) {
print $nbofrecipient;
} else {
print $langs->trans("Error").' '.img_error($obj->error);
diff --git a/htdocs/core/modules/mailings/advthirdparties.modules.php b/htdocs/core/modules/mailings/advthirdparties.modules.php
index 8c5491918dd..688db8b8e7f 100644
--- a/htdocs/core/modules/mailings/advthirdparties.modules.php
+++ b/htdocs/core/modules/mailings/advthirdparties.modules.php
@@ -200,8 +200,8 @@ class mailing_advthirdparties extends MailingTargets
* For example if this selector is used to extract 500 different
* emails from a text file, this function must return 500.
*
- * @param string $sql Not use here
- * @return int Nb of recipients
+ * @param string $sql Not use here
+ * @return int|string Nb of recipient, or <0 if error, or '' if NA
*/
public function getNbOfRecipients($sql = '')
{
@@ -212,8 +212,7 @@ class mailing_advthirdparties extends MailingTargets
$sql .= " WHERE s.email != ''";
$sql .= " AND s.entity IN (".getEntity('societe').")";
- // La requete doit retourner un champ "nb" pour etre comprise
- // par parent::getNbOfRecipients
+ // La requete doit retourner un champ "nb" pour etre comprise par parent::getNbOfRecipients
return parent::getNbOfRecipients($sql);
}
diff --git a/htdocs/core/modules/mailings/contacts1.modules.php b/htdocs/core/modules/mailings/contacts1.modules.php
index 04bc4131f69..e3e349d2a17 100644
--- a/htdocs/core/modules/mailings/contacts1.modules.php
+++ b/htdocs/core/modules/mailings/contacts1.modules.php
@@ -94,8 +94,8 @@ class mailing_contacts1 extends MailingTargets
* For example if this selector is used to extract 500 different
* emails from a text file, this function must return 500.
*
- * @param string $sql Requete sql de comptage
- * @return int
+ * @param string $sql Requete sql de comptage
+ * @return int|string Nb of recipient, or <0 if error, or '' if NA
*/
public function getNbOfRecipients($sql = '')
{
diff --git a/htdocs/core/modules/mailings/example.modules.php b/htdocs/core/modules/mailings/example.modules.php
index bd553e1fd5d..739ab773196 100644
--- a/htdocs/core/modules/mailings/example.modules.php
+++ b/htdocs/core/modules/mailings/example.modules.php
@@ -111,8 +111,8 @@ class mailing_example extends MailingTargets
* For example if this selector is used to extract 500 different
* emails from a text file, this function must return 500.
*
- * @param string $sql Requete sql de comptage
- * @return int|string Number of recipient or '?'
+ * @param string $sql Requete sql de comptage
+ * @return int|string Nb of recipient, or <0 if error, or '' if NA
*/
public function getNbOfRecipients($sql = '')
{
diff --git a/htdocs/core/modules/mailings/fraise.modules.php b/htdocs/core/modules/mailings/fraise.modules.php
index b5b4f249107..992539cc303 100644
--- a/htdocs/core/modules/mailings/fraise.modules.php
+++ b/htdocs/core/modules/mailings/fraise.modules.php
@@ -93,8 +93,8 @@ class mailing_fraise extends MailingTargets
* For example if this selector is used to extract 500 different
* emails from a text file, this function must return 500.
*
- * @param string $sql Requete sql de comptage
- * @return int Nb of recipients
+ * @param string $sql Requete sql de comptage
+ * @return int|string Nb of recipient, or <0 if error, or '' if NA
*/
public function getNbOfRecipients($sql = '')
{
@@ -102,8 +102,7 @@ class mailing_fraise extends MailingTargets
$sql .= " FROM ".MAIN_DB_PREFIX."adherent as a";
$sql .= " WHERE (a.email IS NOT NULL AND a.email != '') AND a.entity IN (".getEntity('member').")";
- // La requete doit retourner un champ "nb" pour etre comprise
- // par parent::getNbOfRecipients
+ // La requete doit retourner un champ "nb" pour etre comprise par parent::getNbOfRecipients
return parent::getNbOfRecipients($sql);
}
diff --git a/htdocs/core/modules/mailings/modules_mailings.php b/htdocs/core/modules/mailings/modules_mailings.php
index dae8d1a12bf..2064613d1e9 100644
--- a/htdocs/core/modules/mailings/modules_mailings.php
+++ b/htdocs/core/modules/mailings/modules_mailings.php
@@ -99,8 +99,8 @@ class MailingTargets // This can't be abstract as it is used for some method
/**
* Retourne nombre de destinataires
*
- * @param string $sql Sql request to count
- * @return int Nb of recipient, or <0 if error
+ * @param string $sql Sql request to count
+ * @return int|string Nb of recipient, or <0 if error, or '' if NA
*/
public function getNbOfRecipients($sql)
{
diff --git a/htdocs/core/modules/mailings/partnership.modules.php b/htdocs/core/modules/mailings/partnership.modules.php
index bb8e00a179f..7813d93f54d 100644
--- a/htdocs/core/modules/mailings/partnership.modules.php
+++ b/htdocs/core/modules/mailings/partnership.modules.php
@@ -166,8 +166,8 @@ class mailing_partnership extends MailingTargets
* For example if this selector is used to extract 500 different
* emails from a text file, this function must return 500.
*
- * @param string $sql Requete sql de comptage
- * @return int Nb of recipients
+ * @param string $sql Requete sql de comptage
+ * @return int|string Nb of recipient, or <0 if error, or '' if NA
*/
public function getNbOfRecipients($sql = '')
{
@@ -187,8 +187,7 @@ class mailing_partnership extends MailingTargets
//print $sql;
- // La requete doit retourner un champ "nb" pour etre comprise
- // par parent::getNbOfRecipients
+ // La requete doit retourner un champ "nb" pour etre comprise par parent::getNbOfRecipients
return parent::getNbOfRecipients($sql);
}
diff --git a/htdocs/core/modules/mailings/pomme.modules.php b/htdocs/core/modules/mailings/pomme.modules.php
index 56d62449bcf..7fdcdeb0c60 100644
--- a/htdocs/core/modules/mailings/pomme.modules.php
+++ b/htdocs/core/modules/mailings/pomme.modules.php
@@ -89,8 +89,8 @@ class mailing_pomme extends MailingTargets
* For example if this selector is used to extract 500 different
* emails from a text file, this function must return 500.
*
- * @param string $sql SQL request to use to count
- * @return int Number of recipients
+ * @param string $sql SQL request to use to count
+ * @return int|string Nb of recipient, or <0 if error, or '' if NA
*/
public function getNbOfRecipients($sql = '')
{
@@ -101,8 +101,7 @@ class mailing_pomme extends MailingTargets
$sql .= " WHERE u.email != ''"; // u.email IS NOT NULL est implicite dans ce test
$sql .= " AND u.entity IN (0,".$conf->entity.")";
- // La requete doit retourner un champ "nb" pour etre comprise
- // par parent::getNbOfRecipients
+ // La requete doit retourner un champ "nb" pour etre comprise par parent::getNbOfRecipients
return parent::getNbOfRecipients($sql);
}
diff --git a/htdocs/core/modules/mailings/thirdparties.modules.php b/htdocs/core/modules/mailings/thirdparties.modules.php
index afd8a05db02..073d45439eb 100644
--- a/htdocs/core/modules/mailings/thirdparties.modules.php
+++ b/htdocs/core/modules/mailings/thirdparties.modules.php
@@ -211,8 +211,8 @@ class mailing_thirdparties extends MailingTargets
* For example if this selector is used to extract 500 different
* emails from a text file, this function must return 500.
*
- * @param string $sql Requete sql de comptage
- * @return int Nb of recipients
+ * @param string $sql Requete sql de comptage
+ * @return int|string Nb of recipient, or <0 if error, or '' if NA
*/
public function getNbOfRecipients($sql = '')
{
@@ -223,8 +223,7 @@ class mailing_thirdparties extends MailingTargets
$sql .= " WHERE s.email <> ''";
$sql .= " AND s.entity IN (".getEntity('societe').")";
- // La requete doit retourner un champ "nb" pour etre comprise
- // par parent::getNbOfRecipients
+ // La requete doit retourner un champ "nb" pour etre comprise par parent::getNbOfRecipients
return parent::getNbOfRecipients($sql);
}
diff --git a/htdocs/core/modules/mailings/thirdparties_services_expired.modules.php b/htdocs/core/modules/mailings/thirdparties_services_expired.modules.php
index 9b417ecd95f..b5dec9cbbe0 100644
--- a/htdocs/core/modules/mailings/thirdparties_services_expired.modules.php
+++ b/htdocs/core/modules/mailings/thirdparties_services_expired.modules.php
@@ -184,8 +184,8 @@ class mailing_thirdparties_services_expired extends MailingTargets
* For example if this selector is used to extract 500 different
* emails from a text file, this function must return 500.
*
- * @param string $sql SQL request to use to count
- * @return int Number of recipients
+ * @param string $sql SQL request to use to count
+ * @return int|string Nb of recipient, or <0 if error, or '' if NA
*/
public function getNbOfRecipients($sql = '')
{
diff --git a/htdocs/core/modules/mailings/xinputfile.modules.php b/htdocs/core/modules/mailings/xinputfile.modules.php
index 3ece88d4c1d..77044ddb29e 100644
--- a/htdocs/core/modules/mailings/xinputfile.modules.php
+++ b/htdocs/core/modules/mailings/xinputfile.modules.php
@@ -77,8 +77,8 @@ class mailing_xinputfile extends MailingTargets
* For example if this selector is used to extract 500 different
* emails from a text file, this function must return 500.
*
- * @param string $sql Sql request to count
- * @return string '' means NA
+ * @param string $sql Sql request to count
+ * @return int|string Nb of recipient, or <0 if error, or '' if NA
*/
public function getNbOfRecipients($sql = '')
{
diff --git a/htdocs/core/modules/mailings/xinputuser.modules.php b/htdocs/core/modules/mailings/xinputuser.modules.php
index b2874b43ca0..117a5722c3c 100644
--- a/htdocs/core/modules/mailings/xinputuser.modules.php
+++ b/htdocs/core/modules/mailings/xinputuser.modules.php
@@ -77,8 +77,8 @@ class mailing_xinputuser extends MailingTargets
* For example if this selector is used to extract 500 different
* emails from a text file, this function must return 500.
*
- * @param string $sql Sql request to count
- * @return string '' means NA
+ * @param string $sql Sql request to count
+ * @return int|string Nb of recipient, or <0 if error, or '' if NA
*/
public function getNbOfRecipients($sql = '')
{
diff --git a/htdocs/product/reassortlot.php b/htdocs/product/reassortlot.php
index 031ef60ff6e..690d3f3f261 100644
--- a/htdocs/product/reassortlot.php
+++ b/htdocs/product/reassortlot.php
@@ -96,6 +96,7 @@ if (!$sortorder) {
$sortorder = "ASC";
}
+
// Initialize array of search criterias
$search = array();
foreach ($object->fields as $key => $val) {
@@ -107,6 +108,12 @@ foreach ($object->fields as $key => $val) {
$search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int'));
}
}
+$key = 'sellby';
+$search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int'));
+$search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int'));
+$key = 'eatby';
+$search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int'));
+$search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int'));
// Get object canvas (By default, this is not defined, so standard usage of dolibarr)
$canvas = GETPOST("canvas");
@@ -155,6 +162,10 @@ if (empty($reshook)) {
$search[$key.'_dtend'] = '';
}
}
+ $search['sellby_dtstart'] = '';
+ $search['eatby_dtstart'] = '';
+ $search['sellby_dtend'] = '';
+ $search['eatby_dtend'] = '';
$sref = "";
$snom = "";
$sall = "";
@@ -268,6 +279,37 @@ if ($search_warehouse) {
if ($search_batch) {
$sql .= natural_search("pb.batch", $search_batch);
}
+
+foreach ($search as $key => $val) {
+ if (array_key_exists($key, $object->fields)) {
+ if ($key == 'status' && $search[$key] == -1) {
+ continue;
+ }
+ $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
+ if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
+ if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
+ $search[$key] = '';
+ }
+ $mode_search = 2;
+ }
+ if ($search[$key] != '') {
+ $sql .= natural_search("t.".$db->escape($key), $search[$key], (($key == 'status') ? 2 : $mode_search));
+ }
+ } else {
+ if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
+ $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
+ if ($columnName == 'eatby' || $columnName == 'sellby') {
+ if (preg_match('/_dtstart$/', $key)) {
+ $sql .= " AND pl.".$db->escape($columnName)." >= '".$db->idate($search[$key])."'";
+ }
+ if (preg_match('/_dtend$/', $key)) {
+ $sql .= " AND pl.".$db->escape($columnName)." <= '".$db->idate($search[$key])."'";
+ }
+ }
+ }
+ }
+}
+
$sql .= " GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type, p.entity,";
$sql .= " p.fk_product_type, p.tms,";
$sql .= " p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte, p.desiredstock, p.stock, p.tosell, p.tobuy, p.tobatch,";
@@ -293,10 +335,13 @@ if (!empty($sql_having)) {
$sql .= $sql_having;
}
+//print $sql;
+
+// Count total nb of records
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
- $result = $db->query($sql);
- $nbtotalofrecords = $db->num_rows($result);
+ $resql = $db->query($sql);
+ $nbtotalofrecords = $db->num_rows($resql);
if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
$page = 0;
@@ -339,9 +384,29 @@ if (isset($type)) {
$texte .= ' ('.$langs->trans("StocksByLotSerial").')';
$param = '';
+if (!empty($mode)) {
+ $param .= '&mode='.urlencode($mode);
+}
+if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
+ $param .= '&contextpage='.urlencode($contextpage);
+}
if ($limit > 0 && $limit != $conf->liste_limit) {
$param .= '&limit='.urlencode($limit);
}
+foreach ($search as $key => $val) {
+ if (is_array($search[$key]) && count($search[$key])) {
+ foreach ($search[$key] as $skey) {
+ if ($skey != '') {
+ $param .= '&search_'.$key.'[]='.urlencode($skey);
+ }
+ }
+ } elseif ($search[$key] != '') {
+ $param .= '&search_'.$key.'='.urlencode($search[$key]);
+ }
+}
+if ($optioncss != '') {
+ $param .= '&optioncss='.urlencode($optioncss);
+}
if ($sall) {
$param .= "&sall=".urlencode($sall);
}
@@ -389,11 +454,18 @@ if ($sellby) $param.="&sellby=".$sellby;*/
llxHeader("", $title, $helpurl, $texte);
-print '