fix_autoliquidation.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Copyright (C) 2024 Mathieu Moulin <mathieu@iprospective.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file mmishipping/fix_autoliquidation.php
  20. * \ingroup mmishipping
  21. */
  22. // Load Dolibarr environment
  23. require_once 'env.inc.php';
  24. require_once 'main_load.inc.php';
  25. // BLocage
  26. die();
  27. // Recherche doublons d'envois de lignes de commande
  28. // Groupage par expédition : pas deux fois la même ligne de commande dans des expéditions dépôt 7
  29. $sql = 'SELECT DISTINCT GROUP_CONCAT(el.rowid) el_rowids, COUNT(*) nb, el.fk_expedition, el.fk_origin_line, el.qty, e.rowid, e.ref, e.fk_soc, e.ref_customer, e.date_valid, cl.qty cl_qty, cl.fk_commande, c.ref commande_ref
  30. FROM `llx_expeditiondet` el
  31. INNER JOIN `llx_expedition` e ON e.rowid=el.fk_expedition
  32. LEFT JOIN `llx_commandedet` cl ON cl.rowid=el.fk_origin_line
  33. LEFT JOIN `llx_commande` c ON c.rowid=cl.fk_commande
  34. WHERE el.fk_entrepot = 7
  35. GROUP BY el.fk_expedition, el.fk_origin_line
  36. HAVING COUNT(*)>1';
  37. $q = $db->query($sql);
  38. if ($q) while($row=$q->fetch_assoc()) {
  39. var_dump($row);
  40. }
  41. // Recherche expé sans réceptions
  42. // Groupage par expédition : pas deux fois la même ligne de commande dans des expéditions dépôt 7
  43. $sql = 'SELECT DISTINCT GROUP_CONCAT(el.rowid) el_rowids, COUNT(*) nb, el.fk_expedition, el.fk_origin_line, el.qty, e.rowid, e.ref, e.fk_soc, e.ref_customer, e.date_valid, cl.qty cl_qty, cl.fk_commande, c.ref commande_ref
  44. FROM `llx_expeditiondet` el
  45. INNER JOIN `llx_expedition` e ON e.rowid=el.fk_expedition
  46. LEFT JOIN `llx_commandedet` cl ON cl.rowid=el.fk_origin_line
  47. LEFT JOIN `llx_commande` c ON c.rowid=cl.fk_commande
  48. LEFT JOIN `llx_commande` c ON c.rowid=cl.fk_commande
  49. WHERE el.fk_entrepot = 7
  50. GROUP BY el.fk_expedition, el.fk_origin_line
  51. HAVING COUNT(*)>1';
  52. $q = $db->query($sql);
  53. if ($q) while($row=$q->fetch_assoc()) {
  54. var_dump($row);
  55. }
  56. // Recherche réceptions sans expé