From 7a17c43b262bfcf565fea6922b33d574020ebe4e Mon Sep 17 00:00:00 2001 From: atm-josselin Date: Mon, 24 Jun 2019 16:05:24 +0200 Subject: [PATCH 01/13] FIX : filepath of generated documents doesn't handle products with special characters --- htdocs/core/class/html.formfile.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 679989a75a0..522804b601c 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -764,7 +764,7 @@ class FormFile // Show file name with link to download $out.= ''; - $out.= ' Date: Mon, 1 Jul 2019 09:31:01 +0200 Subject: [PATCH 02/13] Sanitize at creation of the product instead of the creation of the filepath --- htdocs/core/class/html.formfile.class.php | 2 +- htdocs/product/class/product.class.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 522804b601c..679989a75a0 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -764,7 +764,7 @@ class FormFile // Show file name with link to download $out.= ''; - $out.= 'ref = dol_string_nospecial(trim($this->ref)); + $this->ref = dol_sanitizeFileName(dol_string_nospecial(trim($this->ref))); $this->label = trim($this->label); $this->price_ttc=price2num($this->price_ttc); $this->price=price2num($this->price); From 75ae611f9e49fead3aa825249b55734a5088cab4 Mon Sep 17 00:00:00 2001 From: "atm-florian.m" Date: Wed, 10 Jul 2019 17:53:14 +0200 Subject: [PATCH 03/13] FIX: calculation of $products_dispatched After the DB retrieval method was changed from fetch_row to fetch_object, the indices used became wrong. --- htdocs/fourn/commande/dispatch.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/fourn/commande/dispatch.php b/htdocs/fourn/commande/dispatch.php index 4b15f04faa0..e6fa2937e0b 100644 --- a/htdocs/fourn/commande/dispatch.php +++ b/htdocs/fourn/commande/dispatch.php @@ -482,7 +482,7 @@ if ($id > 0 || ! empty($ref)) { if ($num) { while ( $i < $num ) { $objd = $db->fetch_object($resql); - $products_dispatched[$objd->rowid] = price2num($objd->qty, 5); + $products_dispatched[$objd->fk_product] = price2num($objd->qty, 5); $i++; } } @@ -540,7 +540,7 @@ if ($id > 0 || ! empty($ref)) { if (! $objp->fk_product > 0) { $nbfreeproduct++; } else { - $remaintodispatch = price2num($objp->qty - (( float ) $products_dispatched[$objp->rowid]), 5); // Calculation of dispatched + $remaintodispatch = price2num($objp->qty - (( float ) $products_dispatched[$objp->fk_product]), 5); // Calculation of dispatched if ($remaintodispatch < 0) $remaintodispatch = 0; From b155fdc014caaeea15848605ae75e82823819c1f Mon Sep 17 00:00:00 2001 From: Florian Mortgat Date: Fri, 12 Jul 2019 15:04:47 +0200 Subject: [PATCH 04/13] FIX: wrong display (and hidden input) for already dispatched quantity --- htdocs/fourn/commande/dispatch.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/fourn/commande/dispatch.php b/htdocs/fourn/commande/dispatch.php index e6fa2937e0b..966be778773 100644 --- a/htdocs/fourn/commande/dispatch.php +++ b/htdocs/fourn/commande/dispatch.php @@ -556,7 +556,7 @@ if ($id > 0 || ! empty($ref)) { print '' . "\n"; // hidden fields for js function print ''; - print ''; + print ''; print ''; $linktoprod = '' . img_object($langs->trans("ShowProduct"), 'product') . ' ' . $objp->ref . ''; @@ -598,7 +598,7 @@ if ($id > 0 || ! empty($ref)) { print '' . $objp->qty . ''; // Already dispatched - print '' . $products_dispatched[$objp->rowid] . ''; + print '' . (float) $products_dispatched[$objp->fk_product] . ''; if (! empty($conf->productbatch->enabled) && $objp->tobatch == 1) { $type = 'batch'; From 770b4197699d0a9a23ac25b99e2fc60281ba8c7b Mon Sep 17 00:00:00 2001 From: Florian Mortgat Date: Thu, 18 Jul 2019 17:00:46 +0200 Subject: [PATCH 05/13] Revert "FIX: wrong display (and hidden input) for already dispatched quantity" This reverts commit b155fdc014caaeea15848605ae75e82823819c1f. --- htdocs/fourn/commande/dispatch.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/fourn/commande/dispatch.php b/htdocs/fourn/commande/dispatch.php index 966be778773..e6fa2937e0b 100644 --- a/htdocs/fourn/commande/dispatch.php +++ b/htdocs/fourn/commande/dispatch.php @@ -556,7 +556,7 @@ if ($id > 0 || ! empty($ref)) { print '' . "\n"; // hidden fields for js function print ''; - print ''; + print ''; print ''; $linktoprod = '' . img_object($langs->trans("ShowProduct"), 'product') . ' ' . $objp->ref . ''; @@ -598,7 +598,7 @@ if ($id > 0 || ! empty($ref)) { print '' . $objp->qty . ''; // Already dispatched - print '' . (float) $products_dispatched[$objp->fk_product] . ''; + print '' . $products_dispatched[$objp->rowid] . ''; if (! empty($conf->productbatch->enabled) && $objp->tobatch == 1) { $type = 'batch'; From e404069d264afb2e5078aa92de029d8dd7c1da95 Mon Sep 17 00:00:00 2001 From: Florian Mortgat Date: Thu, 18 Jul 2019 17:00:57 +0200 Subject: [PATCH 06/13] Revert "FIX: calculation of $products_dispatched" This reverts commit 75ae611f9e49fead3aa825249b55734a5088cab4. --- htdocs/fourn/commande/dispatch.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/fourn/commande/dispatch.php b/htdocs/fourn/commande/dispatch.php index e6fa2937e0b..4b15f04faa0 100644 --- a/htdocs/fourn/commande/dispatch.php +++ b/htdocs/fourn/commande/dispatch.php @@ -482,7 +482,7 @@ if ($id > 0 || ! empty($ref)) { if ($num) { while ( $i < $num ) { $objd = $db->fetch_object($resql); - $products_dispatched[$objd->fk_product] = price2num($objd->qty, 5); + $products_dispatched[$objd->rowid] = price2num($objd->qty, 5); $i++; } } @@ -540,7 +540,7 @@ if ($id > 0 || ! empty($ref)) { if (! $objp->fk_product > 0) { $nbfreeproduct++; } else { - $remaintodispatch = price2num($objp->qty - (( float ) $products_dispatched[$objp->fk_product]), 5); // Calculation of dispatched + $remaintodispatch = price2num($objp->qty - (( float ) $products_dispatched[$objp->rowid]), 5); // Calculation of dispatched if ($remaintodispatch < 0) $remaintodispatch = 0; From dbd68027f86329bc6ad061adb9d9b870f39f807f Mon Sep 17 00:00:00 2001 From: Florian Mortgat Date: Thu, 18 Jul 2019 16:57:52 +0200 Subject: [PATCH 07/13] =?UTF-8?q?New=20script=20that=20links=20"orphaned"?= =?UTF-8?q?=20dispatch=20lines=20to=20order=20lines=20(the=20"orphans"=20a?= =?UTF-8?q?re=20dispatch=20lines=20that=20were=20created=20in=20old=20vers?= =?UTF-8?q?ions=20of=20Dolibarr=20which=20didn=E2=80=99t=20have=20fk=5Fcom?= =?UTF-8?q?mandefourndet=20in=20llx=5Fcommande=5Ffournisseur=5Fdispatch)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ..._commande_fournisseur_dispatch_3.6-9.0.php | 165 ++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 htdocs/fourn/commande/script/repair_llx_commande_fournisseur_dispatch_3.6-9.0.php diff --git a/htdocs/fourn/commande/script/repair_llx_commande_fournisseur_dispatch_3.6-9.0.php b/htdocs/fourn/commande/script/repair_llx_commande_fournisseur_dispatch_3.6-9.0.php new file mode 100644 index 00000000000..fec3c82cb56 --- /dev/null +++ b/htdocs/fourn/commande/script/repair_llx_commande_fournisseur_dispatch_3.6-9.0.php @@ -0,0 +1,165 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * This script is meant to be run when upgrading from a dolibarr version < 3.8 + * to a newer version. + * + * Version 3.8 introduces a new column in llx_commande_fournisseur_dispatch, which + * matches the dispatch to a specific supplier order line (so that if there are + * several with the same product, the user can specifically tell which products of + * which line were dispatched where). + * + * However when migrating, the new column has a default value of 0, which means that + * old supplier orders whose lines were dispatched using the old dolibarr version + * have unspecific dispatch lines, which are not taken into account by the new version, + * thus making the order look like it was never dispatched at all. + * + * This scripts sets this foreign key to the first matching supplier order line whose + * product (and supplier order of course) are the same as the dispatch’s. + * + * If the dispatched quantity is more than indicated on the order line (this happens if + * there are several order lines for the same product), it creates new dispatch lines + * pointing to the other order lines accordingly, until all the dispatched quantity is + * accounted for. + */ + +// Dolibarr environment +$path_dir = '../../'; +$main_inc_file = 'main.inc.php'; +while ((false == @include($path_dir . $main_inc_file)) && 3*10 > strlen($path_dir)) { + $path_dir = '../' . $path_dir; + if (strlen($path_dir) > 20) { + echo 'Error: unable to include "' . $main_inc_file . '" from any of the parent directories.'; + exit; + } +} + +// Access control +if (!$user->admin) { + accessforbidden(); +} + +echo '

Repair llx_commande_fournisseur_dispatch.fk_commandefourndet

'; +echo '

Repair in progress. This may take a while.

'; + +echo '
';
+//$sql = 'UPDATE ' . MAIN_DB_PREFIX . 'commande_fournisseur_dispatch AS dispatch SET dispatch.fk_commandefourndet =
+//           ( SELECT rowid FROM ' . MAIN_DB_PREFIX . 'commande_fournisseurdet AS line
+//            WHERE line.fk_commande = dispatch.fk_commande LIMIT 1) WHERE dispatch.fk_commandefourndet = 0;';
+
+$sql_dispatch = 'SELECT * FROM ' . MAIN_DB_PREFIX . 'commande_fournisseur_dispatch WHERE COALESCE(fk_commandefourndet, 0) = 0';
+//$sql_dispatch = 'SELECT * FROM ' . MAIN_DB_PREFIX . 'commande_fournisseur_dispatch WHERE fk_commandefourndet = 0 OR fk_commandefourndet IS NULL';
+$db->begin();
+$resql_dispatch = $db->query($sql_dispatch);
+$n_processed_rows = 0;
+$errors = array();
+if ($resql_dispatch) {
+    if ($db->num_rows($resql_dispatch) == 0) {
+        echo 'Nothing to do.'; exit;
+    };
+    while ($obj_dispatch = $db->fetch_object($resql_dispatch)) {
+        $sql_line = 'SELECT line.rowid, line.qty FROM ' . MAIN_DB_PREFIX . 'commande_fournisseurdet AS line'
+            .  ' WHERE line.fk_commande = ' . $obj_dispatch->fk_commande
+            .  ' AND line.fk_product = ' . $obj_dispatch->fk_product;
+        $resql_line = $db->query($sql_line);
+
+        // s’il y a plusieurs lignes avec le même produit sur cette commande fournisseur,
+        // on divise la ligne de dispatch en autant de lignes qu’on en a sur la commande pour le produit
+        // et on met la quantité de la ligne dans la limite du "budget" indiqué par dispatch.qty
+
+        $remaining_qty = $obj_dispatch->qty;
+        $first_iteration = true;
+        if (!$resql_line) {
+            echo 'Unable to find a matching supplier order line for dispatch #' . $obj_dispatch->rowid . "\n";
+            $errors[] = $sql_line;
+            $n_processed_rows++;
+            continue;
+        }
+        if ($db->num_rows($resql_line) == 0) continue;
+        while ($obj_line = $db->fetch_object($resql_line)) {
+            if (!$remaining_qty) break;
+            if (!$obj_line->rowid) {
+                continue;
+            }
+            $qty_for_line = min($remaining_qty, $obj_line->qty);
+            if ($first_iteration) {
+                $sql_attach = 'UPDATE ' . MAIN_DB_PREFIX . 'commande_fournisseur_dispatch'
+                    . ' SET fk_commandefourndet = ' . $obj_line->rowid . ', qty = ' . $qty_for_line
+                    . ' WHERE rowid = ' . $obj_dispatch->rowid;
+                $first_iteration = false;
+            } else {
+                $sql_attach_values = array(
+                    $obj_dispatch->fk_commande,
+                    $obj_dispatch->fk_product,
+                    $obj_line->rowid,
+                    $qty_for_line,
+                    $obj_dispatch->fk_entrepot,
+                    $obj_dispatch->fk_user,
+                    $obj_dispatch->datec ? '"' . $db->escape($obj_dispatch->datec) . '"' : 'NULL',
+                    $obj_dispatch->comment ? '"' . $db->escape($obj_dispatch->comment) . '"' : 'NULL',
+                    $obj_dispatch->status ?: 'NULL',
+                    $obj_dispatch->tms ? '"' . $db->escape($obj_dispatch->tms) . '"': 'NULL',
+                    $obj_dispatch->batch ?: 'NULL',
+                    $obj_dispatch->eatby ? '"' . $db->escape($obj_dispatch->eatby) . '"': 'NULL',
+                    $obj_dispatch->sellby ? '"' . $db->escape($obj_dispatch->sellby) . '"': 'NULL'
+                );
+                $sql_attach_values = join(', ', $sql_attach_values);
+
+                $sql_attach = 'INSERT INTO ' . MAIN_DB_PREFIX . 'commande_fournisseur_dispatch'
+                    . ' (fk_commande, fk_product, fk_commandefourndet, qty, fk_entrepot, fk_user, datec, comment, status, tms, batch, eatby, sellby)'
+                    . ' VALUES (' . $sql_attach_values . ')';
+            }
+            $resql_attach = $db->query($sql_attach);
+            if ($resql_attach) {
+                $remaining_qty -= $qty_for_line;
+            } else {
+                $errors[] = $sql_attach;
+            }
+            $first_iteration = false;
+        }
+        $n_processed_rows++;
+
+        // report progress every 256th row
+        if (!($n_processed_rows & 0xff)) {
+            echo 'Processed ' . $n_processed_rows . ' rows with ' . count($errors) . ' errors…' . "\n";
+            flush();
+            ob_flush();
+        }
+
+    }
+} else {
+    echo 'Unable to find any dispatch without an fk_commandefourndet.' . "\n";
+    echo $sql_dispatch . "\n";
+}
+echo 'Fixed ' . $n_processed_rows . ' rows with ' . count($errors) . ' errors…' . "\n";
+echo 'DONE.' . "\n";
+echo '
'; + +if (count($errors)) { + $db->rollback(); + echo 'The transaction was rolled back due to errors: nothing was changed by the script.'; +} else { + $db->commit(); +} +$db->close(); + + +echo '

SQL queries with errors:

'; +echo '
  • ' . join('
  • ', $errors) . '
'; + From c9e70ed1c1d4f544e773cc9b703aace0b712c9a4 Mon Sep 17 00:00:00 2001 From: Florian Mortgat Date: Mon, 22 Jul 2019 09:30:43 +0200 Subject: [PATCH 08/13] Fix problems detected by travis-ci --- .../repair_llx_commande_fournisseur_dispatch_3.6-9.0.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/htdocs/fourn/commande/script/repair_llx_commande_fournisseur_dispatch_3.6-9.0.php b/htdocs/fourn/commande/script/repair_llx_commande_fournisseur_dispatch_3.6-9.0.php index fec3c82cb56..0c4b006664c 100644 --- a/htdocs/fourn/commande/script/repair_llx_commande_fournisseur_dispatch_3.6-9.0.php +++ b/htdocs/fourn/commande/script/repair_llx_commande_fournisseur_dispatch_3.6-9.0.php @@ -42,7 +42,7 @@ // Dolibarr environment $path_dir = '../../'; $main_inc_file = 'main.inc.php'; -while ((false == @include($path_dir . $main_inc_file)) && 3*10 > strlen($path_dir)) { +while ((false == (@include $path_dir . $main_inc_file)) && 3*10 > strlen($path_dir)) { $path_dir = '../' . $path_dir; if (strlen($path_dir) > 20) { echo 'Error: unable to include "' . $main_inc_file . '" from any of the parent directories.'; @@ -141,7 +141,6 @@ if ($resql_dispatch) { flush(); ob_flush(); } - } } else { echo 'Unable to find any dispatch without an fk_commandefourndet.' . "\n"; From 3ef257f4f2a82de116588ef568046de81922e004 Mon Sep 17 00:00:00 2001 From: Florian Mortgat Date: Wed, 31 Jul 2019 09:21:00 +0200 Subject: [PATCH 09/13] Removed commented out code from the new migration script --- .../repair_llx_commande_fournisseur_dispatch_3.6-9.0.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/htdocs/fourn/commande/script/repair_llx_commande_fournisseur_dispatch_3.6-9.0.php b/htdocs/fourn/commande/script/repair_llx_commande_fournisseur_dispatch_3.6-9.0.php index 0c4b006664c..95cf50aabbf 100644 --- a/htdocs/fourn/commande/script/repair_llx_commande_fournisseur_dispatch_3.6-9.0.php +++ b/htdocs/fourn/commande/script/repair_llx_commande_fournisseur_dispatch_3.6-9.0.php @@ -59,12 +59,8 @@ echo '

Repair llx_commande_fournisseur_dispatch.fk_commandefourndet

'; echo '

Repair in progress. This may take a while.

'; echo '
';
-//$sql = 'UPDATE ' . MAIN_DB_PREFIX . 'commande_fournisseur_dispatch AS dispatch SET dispatch.fk_commandefourndet =
-//           ( SELECT rowid FROM ' . MAIN_DB_PREFIX . 'commande_fournisseurdet AS line
-//            WHERE line.fk_commande = dispatch.fk_commande LIMIT 1) WHERE dispatch.fk_commandefourndet = 0;';
 
 $sql_dispatch = 'SELECT * FROM ' . MAIN_DB_PREFIX . 'commande_fournisseur_dispatch WHERE COALESCE(fk_commandefourndet, 0) = 0';
-//$sql_dispatch = 'SELECT * FROM ' . MAIN_DB_PREFIX . 'commande_fournisseur_dispatch WHERE fk_commandefourndet = 0 OR fk_commandefourndet IS NULL';
 $db->begin();
 $resql_dispatch = $db->query($sql_dispatch);
 $n_processed_rows = 0;

From fa29415e6a16d5bab7afc9a9c342d75cfc6f07c3 Mon Sep 17 00:00:00 2001
From: Florian Mortgat 
Date: Thu, 22 Aug 2019 14:06:18 +0200
Subject: [PATCH 10/13] Moved repair payload from a specific script to
 install/repair.php

---
 ..._commande_fournisseur_dispatch_3.6-9.0.php | 160 ------------------
 htdocs/install/repair.php                     | 125 ++++++++++++++
 2 files changed, 125 insertions(+), 160 deletions(-)
 delete mode 100644 htdocs/fourn/commande/script/repair_llx_commande_fournisseur_dispatch_3.6-9.0.php

diff --git a/htdocs/fourn/commande/script/repair_llx_commande_fournisseur_dispatch_3.6-9.0.php b/htdocs/fourn/commande/script/repair_llx_commande_fournisseur_dispatch_3.6-9.0.php
deleted file mode 100644
index 95cf50aabbf..00000000000
--- a/htdocs/fourn/commande/script/repair_llx_commande_fournisseur_dispatch_3.6-9.0.php
+++ /dev/null
@@ -1,160 +0,0 @@
-
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see .
- */
-
-/**
- * This script is meant to be run when upgrading from a dolibarr version < 3.8
- * to a newer version.
- *
- * Version 3.8 introduces a new column in llx_commande_fournisseur_dispatch, which
- * matches the dispatch to a specific supplier order line (so that if there are
- * several with the same product, the user can specifically tell which products of
- * which line were dispatched where).
- *
- * However when migrating, the new column has a default value of 0, which means that
- * old supplier orders whose lines were dispatched using the old dolibarr version
- * have unspecific dispatch lines, which are not taken into account by the new version,
- * thus making the order look like it was never dispatched at all.
- *
- * This scripts sets this foreign key to the first matching supplier order line whose
- * product (and supplier order of course) are the same as the dispatch’s.
- *
- * If the dispatched quantity is more than indicated on the order line (this happens if
- * there are several order lines for the same product), it creates new dispatch lines
- * pointing to the other order lines accordingly, until all the dispatched quantity is
- * accounted for.
- */
-
-// Dolibarr environment
-$path_dir = '../../';
-$main_inc_file = 'main.inc.php';
-while ((false == (@include $path_dir . $main_inc_file)) && 3*10 > strlen($path_dir)) {
-    $path_dir = '../' . $path_dir;
-    if (strlen($path_dir) > 20) {
-        echo 'Error: unable to include "' . $main_inc_file . '" from any of the parent directories.';
-        exit;
-    }
-}
-
-// Access control
-if (!$user->admin) {
-    accessforbidden();
-}
-
-echo '

Repair llx_commande_fournisseur_dispatch.fk_commandefourndet

'; -echo '

Repair in progress. This may take a while.

'; - -echo '
';
-
-$sql_dispatch = 'SELECT * FROM ' . MAIN_DB_PREFIX . 'commande_fournisseur_dispatch WHERE COALESCE(fk_commandefourndet, 0) = 0';
-$db->begin();
-$resql_dispatch = $db->query($sql_dispatch);
-$n_processed_rows = 0;
-$errors = array();
-if ($resql_dispatch) {
-    if ($db->num_rows($resql_dispatch) == 0) {
-        echo 'Nothing to do.'; exit;
-    };
-    while ($obj_dispatch = $db->fetch_object($resql_dispatch)) {
-        $sql_line = 'SELECT line.rowid, line.qty FROM ' . MAIN_DB_PREFIX . 'commande_fournisseurdet AS line'
-            .  ' WHERE line.fk_commande = ' . $obj_dispatch->fk_commande
-            .  ' AND line.fk_product = ' . $obj_dispatch->fk_product;
-        $resql_line = $db->query($sql_line);
-
-        // s’il y a plusieurs lignes avec le même produit sur cette commande fournisseur,
-        // on divise la ligne de dispatch en autant de lignes qu’on en a sur la commande pour le produit
-        // et on met la quantité de la ligne dans la limite du "budget" indiqué par dispatch.qty
-
-        $remaining_qty = $obj_dispatch->qty;
-        $first_iteration = true;
-        if (!$resql_line) {
-            echo 'Unable to find a matching supplier order line for dispatch #' . $obj_dispatch->rowid . "\n";
-            $errors[] = $sql_line;
-            $n_processed_rows++;
-            continue;
-        }
-        if ($db->num_rows($resql_line) == 0) continue;
-        while ($obj_line = $db->fetch_object($resql_line)) {
-            if (!$remaining_qty) break;
-            if (!$obj_line->rowid) {
-                continue;
-            }
-            $qty_for_line = min($remaining_qty, $obj_line->qty);
-            if ($first_iteration) {
-                $sql_attach = 'UPDATE ' . MAIN_DB_PREFIX . 'commande_fournisseur_dispatch'
-                    . ' SET fk_commandefourndet = ' . $obj_line->rowid . ', qty = ' . $qty_for_line
-                    . ' WHERE rowid = ' . $obj_dispatch->rowid;
-                $first_iteration = false;
-            } else {
-                $sql_attach_values = array(
-                    $obj_dispatch->fk_commande,
-                    $obj_dispatch->fk_product,
-                    $obj_line->rowid,
-                    $qty_for_line,
-                    $obj_dispatch->fk_entrepot,
-                    $obj_dispatch->fk_user,
-                    $obj_dispatch->datec ? '"' . $db->escape($obj_dispatch->datec) . '"' : 'NULL',
-                    $obj_dispatch->comment ? '"' . $db->escape($obj_dispatch->comment) . '"' : 'NULL',
-                    $obj_dispatch->status ?: 'NULL',
-                    $obj_dispatch->tms ? '"' . $db->escape($obj_dispatch->tms) . '"': 'NULL',
-                    $obj_dispatch->batch ?: 'NULL',
-                    $obj_dispatch->eatby ? '"' . $db->escape($obj_dispatch->eatby) . '"': 'NULL',
-                    $obj_dispatch->sellby ? '"' . $db->escape($obj_dispatch->sellby) . '"': 'NULL'
-                );
-                $sql_attach_values = join(', ', $sql_attach_values);
-
-                $sql_attach = 'INSERT INTO ' . MAIN_DB_PREFIX . 'commande_fournisseur_dispatch'
-                    . ' (fk_commande, fk_product, fk_commandefourndet, qty, fk_entrepot, fk_user, datec, comment, status, tms, batch, eatby, sellby)'
-                    . ' VALUES (' . $sql_attach_values . ')';
-            }
-            $resql_attach = $db->query($sql_attach);
-            if ($resql_attach) {
-                $remaining_qty -= $qty_for_line;
-            } else {
-                $errors[] = $sql_attach;
-            }
-            $first_iteration = false;
-        }
-        $n_processed_rows++;
-
-        // report progress every 256th row
-        if (!($n_processed_rows & 0xff)) {
-            echo 'Processed ' . $n_processed_rows . ' rows with ' . count($errors) . ' errors…' . "\n";
-            flush();
-            ob_flush();
-        }
-    }
-} else {
-    echo 'Unable to find any dispatch without an fk_commandefourndet.' . "\n";
-    echo $sql_dispatch . "\n";
-}
-echo 'Fixed ' . $n_processed_rows . ' rows with ' . count($errors) . ' errors…' . "\n";
-echo 'DONE.' . "\n";
-echo '
'; - -if (count($errors)) { - $db->rollback(); - echo 'The transaction was rolled back due to errors: nothing was changed by the script.'; -} else { - $db->commit(); -} -$db->close(); - - -echo '

SQL queries with errors:

'; -echo '
  • ' . join('
  • ', $errors) . '
'; - diff --git a/htdocs/install/repair.php b/htdocs/install/repair.php index 4d3e28a38d3..b7f3f9eb5b6 100644 --- a/htdocs/install/repair.php +++ b/htdocs/install/repair.php @@ -78,6 +78,7 @@ print 'Option rebuild_product_thumbs (0 or \'test\' or \'confirmed\') is '.(GETP print 'Option force_disable_of_modules_not_found (0 or \'test\' or \'confirmed\') is '.(GETPOST('force_disable_of_modules_not_found','alpha')?GETPOST('force_disable_of_modules_not_found','alpha'):'0').'
'."\n"; print 'Option clean_perm_table (0 or \'test\' or \'confirmed\') is '.(GETPOST('clean_perm_table','alpha')?GETPOST('clean_perm_table','alpha'):'0').'
'."\n"; print 'Option force_utf8_on_tables, for mysql/mariadb only (0 or \'test\' or \'confirmed\') is '.(GETPOST('force_utf8_on_tables','alpha')?GETPOST('force_utf8_on_tables','alpha'):'0').'
'."\n"; +print 'Option repair_link_dispatch_lines_supplier_order_lines, (0 or \'test\' or \'confirmed\') is '.(GETPOST('repair_link_dispatch_lines_supplier_order_lines','alpha')?GETPOST('repair_link_dispatch_lines_supplier_order_lines','alpha'):'0').'
'."\n"; print '
'; print ''; @@ -1122,6 +1123,130 @@ if ($ok && GETPOST('force_utf8_on_tables','alpha')) } } +// +if ($ok && GETPOST('repair_link_dispatch_lines_supplier_order_lines')) { + /* + * This script is meant to be run when upgrading from a dolibarr version < 3.8 + * to a newer version. + * + * Version 3.8 introduces a new column in llx_commande_fournisseur_dispatch, which + * matches the dispatch to a specific supplier order line (so that if there are + * several with the same product, the user can specifically tell which products of + * which line were dispatched where). + * + * However when migrating, the new column has a default value of 0, which means that + * old supplier orders whose lines were dispatched using the old dolibarr version + * have unspecific dispatch lines, which are not taken into account by the new version, + * thus making the order look like it was never dispatched at all. + * + * This scripts sets this foreign key to the first matching supplier order line whose + * product (and supplier order of course) are the same as the dispatch’s. + * + * If the dispatched quantity is more than indicated on the order line (this happens if + * there are several order lines for the same product), it creates new dispatch lines + * pointing to the other order lines accordingly, until all the dispatched quantity is + * accounted for. + */ + echo ''; + echo ''; + + $sql_dispatch = 'SELECT * FROM ' . MAIN_DB_PREFIX . 'commande_fournisseur_dispatch WHERE COALESCE(fk_commandefourndet, 0) = 0'; + $db->begin(); + $resql_dispatch = $db->query($sql_dispatch); + $n_processed_rows = 0; + $errors = array(); + if ($resql_dispatch) { + if ($db->num_rows($resql_dispatch) == 0) { + echo ''; + exit; + } + while ($obj_dispatch = $db->fetch_object($resql_dispatch)) { + $sql_line = 'SELECT line.rowid, line.qty FROM ' . MAIN_DB_PREFIX . 'commande_fournisseurdet AS line' + . ' WHERE line.fk_commande = ' . $obj_dispatch->fk_commande + . ' AND line.fk_product = ' . $obj_dispatch->fk_product; + $resql_line = $db->query($sql_line); + + // s’il y a plusieurs lignes avec le même produit sur cette commande fournisseur, + // on divise la ligne de dispatch en autant de lignes qu’on en a sur la commande pour le produit + // et on met la quantité de la ligne dans la limite du "budget" indiqué par dispatch.qty + + $remaining_qty = $obj_dispatch->qty; + $first_iteration = true; + if (!$resql_line) { + echo ''; + $errors[] = $sql_line; + $n_processed_rows++; + continue; + } + if ($db->num_rows($resql_line) == 0) continue; + while ($obj_line = $db->fetch_object($resql_line)) { + if (!$remaining_qty) break; + if (!$obj_line->rowid) { + continue; + } + $qty_for_line = min($remaining_qty, $obj_line->qty); + if ($first_iteration) { + $sql_attach = 'UPDATE ' . MAIN_DB_PREFIX . 'commande_fournisseur_dispatch' + . ' SET fk_commandefourndet = ' . $obj_line->rowid . ', qty = ' . $qty_for_line + . ' WHERE rowid = ' . $obj_dispatch->rowid; + $first_iteration = false; + } else { + $sql_attach_values = array( + $obj_dispatch->fk_commande, + $obj_dispatch->fk_product, + $obj_line->rowid, + $qty_for_line, + $obj_dispatch->fk_entrepot, + $obj_dispatch->fk_user, + $obj_dispatch->datec ? '"' . $db->escape($obj_dispatch->datec) . '"' : 'NULL', + $obj_dispatch->comment ? '"' . $db->escape($obj_dispatch->comment) . '"' : 'NULL', + $obj_dispatch->status ?: 'NULL', + $obj_dispatch->tms ? '"' . $db->escape($obj_dispatch->tms) . '"': 'NULL', + $obj_dispatch->batch ?: 'NULL', + $obj_dispatch->eatby ? '"' . $db->escape($obj_dispatch->eatby) . '"': 'NULL', + $obj_dispatch->sellby ? '"' . $db->escape($obj_dispatch->sellby) . '"': 'NULL' + ); + $sql_attach_values = join(', ', $sql_attach_values); + + $sql_attach = 'INSERT INTO ' . MAIN_DB_PREFIX . 'commande_fournisseur_dispatch' + . ' (fk_commande, fk_product, fk_commandefourndet, qty, fk_entrepot, fk_user, datec, comment, status, tms, batch, eatby, sellby)' + . ' VALUES (' . $sql_attach_values . ')'; + } + $resql_attach = $db->query($sql_attach); + if ($resql_attach) { + $remaining_qty -= $qty_for_line; + } else { + $errors[] = $sql_attach; + } + $first_iteration = false; + } + $n_processed_rows++; + + // report progress every 256th row + if (!($n_processed_rows & 0xff)) { + echo '\n"; + flush(); + ob_flush(); + } + } + } else { + echo '\n"; + echo $sql_dispatch . "\n"; + } + echo '\n"; + echo '\n"; + + if (count($errors)) { + $db->rollback(); + echo ''; + } else { + $db->commit(); + } + $db->close(); + + echo ''; + echo ''; +} print '
Repair llx_commande_fournisseur_dispatch.fk_commandefourndet
Repair in progress. This may take a while.
Nothing to do.
Unable to find a matching supplier order line for dispatch #' . $obj_dispatch->rowid . '
Processed ' . $n_processed_rows . ' rows with ' . count($errors) . ' errors…' . "
Unable to find any dispatch without an fk_commandefourndet.' . "
Fixed ' . $n_processed_rows . ' rows with ' . count($errors) . ' errors…' . "
DONE.' . "
The transaction was rolled back due to errors: nothing was changed by the script.

SQL queries with errors:

' . join('
', $errors) . '
'; From c2f570ae604d486971a8f4317323c4bf04039709 Mon Sep 17 00:00:00 2001 From: John Botella Date: Tue, 27 Aug 2019 11:54:20 +0200 Subject: [PATCH 11/13] FIX: remove disabled product type from product list --- htdocs/core/class/html.form.class.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 8f0af0a5004..ac92e93751c 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -1785,6 +1785,15 @@ class Form $price_level = (! empty($price_level) ? $price_level : 0); + if(strval($filtertype) === '' && (!empty($conf->product->enabled) || !empty($conf->service->enabled))){ + if(!empty($conf->product->enabled) && empty($conf->service->enabled)){ + $filtertype = '0'; + } + elseif(empty($conf->product->enabled) && !empty($conf->service->enabled)){ + $filtertype = '1'; + } + } + if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) { $placeholder=''; From 14b9460de0126f00eae02c17dbc3b84f10a3705c Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Thu, 29 Aug 2019 16:27:25 +0200 Subject: [PATCH 12/13] FIX Sens of the balance (Debit - Credit in accountancy not contrary) --- htdocs/accountancy/bookkeeping/balance.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/htdocs/accountancy/bookkeeping/balance.php b/htdocs/accountancy/bookkeeping/balance.php index de7fa495770..6c4a8175195 100644 --- a/htdocs/accountancy/bookkeeping/balance.php +++ b/htdocs/accountancy/bookkeeping/balance.php @@ -1,7 +1,7 @@ * Copyright (C) 2016 Florian Henry - * Copyright (C) 2016-2018 Alexandre Spangaro + * Copyright (C) 2016-2019 Alexandre Spangaro * Copyright (C) 2018 Frédéric France * * This program is free software; you can redistribute it and/or modify @@ -164,7 +164,7 @@ if ($action == 'export_csv') print $object->get_compte_desc($line->numero_compte) . $sep; print price($line->debit) . $sep; print price($line->credit) . $sep; - print price($line->credit - $line->debit) . $sep; + print price($line->debit - $line->credit) . $sep; print "\n"; } @@ -235,7 +235,7 @@ if ($action != 'export_csv') print $langs->trans('to'); print $formaccounting->select_account($search_accountancy_code_end, 'search_accountancy_code_end', 1, array(), 1, 1, ''); print ''; - print ''; + print ''; $searchpicto=$form->showFilterAndCheckAddButtons(0); print $searchpicto; print ''; @@ -274,7 +274,7 @@ if ($action != 'export_csv') { // Affiche un Sous-Total par compte comptable if ($displayed_account != "") { - print '' . $langs->trans("SubTotal") . ':' . price($sous_total_debit) . '' . price($sous_total_credit) . '' . price(price2num($sous_total_credit - $sous_total_debit)) . ''; + print '' . $langs->trans("SubTotal") . ':' . price($sous_total_debit) . '' . price($sous_total_credit) . '' . price(price2num($sous_total_credit - $sous_total_debit)) . ''; print " \n"; print ''; } @@ -293,10 +293,10 @@ if ($action != 'export_csv') print '' . length_accountg($line->numero_compte) . ''; print '' . $description . ''; - print '' . price($line->debit) . ''; - print '' . price($line->credit) . ''; - print '' . price($line->credit - $line->debit) . ''; - print '' . $link; + print '' . price($line->debit) . ''; + print '' . price($line->credit) . ''; + print '' . price($line->debit - $line->credit) . ''; + print '' . $link; print ''; print "\n"; @@ -305,11 +305,11 @@ if ($action != 'export_csv') $sous_total_credit += $line->credit; } - print '' . $langs->trans("SubTotal") . ':' . price($sous_total_debit) . '' . price($sous_total_credit) . '' . price(price2num($sous_total_credit - $sous_total_debit)) . ''; + print '' . $langs->trans("SubTotal") . ':' . price($sous_total_debit) . '' . price($sous_total_credit) . '' . price(price2num($sous_total_debit - $sous_total_credit)) . ''; print " \n"; print ''; - print '' . $langs->trans("AccountBalance") . ':' . price($total_debit) . '' . price($total_credit) . '' . price(price2num($total_credit - $total_debit)) . ''; + print '' . $langs->trans("AccountBalance") . ':' . price($total_debit) . '' . price($total_credit) . '' . price(price2num($total_debit - $total_credit)) . ''; print " \n"; print ''; From 4a76dfa6ffa36f9006f2aad96663ddbf99edec06 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 30 Aug 2019 18:23:43 +0200 Subject: [PATCH 13/13] Fix link to setup --- htdocs/comm/mailing/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/comm/mailing/card.php b/htdocs/comm/mailing/card.php index 50f0b761c57..e2f32edc3d3 100644 --- a/htdocs/comm/mailing/card.php +++ b/htdocs/comm/mailing/card.php @@ -835,7 +835,7 @@ else { // EMailing feature may be a spam problem, so when you host several users/instance, having this option may force each user to use their own SMTP agent. // You ensure that every user is using its own SMTP server when using the mass emailing module. - $linktoadminemailbefore=''; + $linktoadminemailbefore=''; $linktoadminemailend=''; setEventMessages($langs->trans("MailSendSetupIs", $listofmethods[$sendingmode]), null, 'warnings'); setEventMessages($langs->trans("MailSendSetupIs2", $linktoadminemailbefore, $linktoadminemailend, $langs->transnoentitiesnoconv("MAIN_MAIL_SENDMODE"), $listofmethods['smtps']), null, 'warnings');