From a39c95e3b4f0fb483d8d3eac2a08b1c24c20480e Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 22 Apr 2011 17:31:28 +0000 Subject: [PATCH] Fix: error sql Fix: don't delete order if shipping exist Fix: uniformize code --- htdocs/commande/class/commande.class.php | 8 ++-- htdocs/commande/fiche.php | 51 +++++++++--------------- 2 files changed, 23 insertions(+), 36 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index f4ac06719a6..83b2c719e81 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1461,9 +1461,11 @@ class Commande extends CommonObject function nb_expedition() { $sql = 'SELECT count(*)'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'expedition as e,'; - $sql.= ' '.MAIN_DB_PREFIX."element_element as el ON el.fk_target = e.rowid AND el.targettype = 'shipping'"; - $sql.= " WHERE el.fk_source = ".$this->id; + $sql.= ' FROM '.MAIN_DB_PREFIX.'expedition as e'; + $sql.= ', '.MAIN_DB_PREFIX.'element_element as el'; + $sql.= ' WHERE el.fk_source = '.$this->id; + $sql.= " AND el.fk_target = e.rowid"; + $sql.= " AND el.targettype = 'shipping'"; $resql = $this->db->query($sql); if ($resql) diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index b6710612085..5a6e568e630 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -1865,17 +1865,13 @@ else // Valid if ($object->statut == 0 && $object->total_ttc >= 0 && $numlines > 0 && $user->rights->commande->valider) { - print ''.$langs->trans('Validate').''; + print ''.$langs->trans('Validate').''; } // Edit - if ($object->statut == 1) + if ($object->statut == 1 && $user->rights->commande->creer) { - if ($user->rights->commande->creer) - { - print ''.$langs->trans('Modify').''; - } + print ''.$langs->trans('Modify').''; } // Send @@ -1893,24 +1889,16 @@ else } // Ship + $numshipping=0; if ($conf->expedition->enabled) { + $numshipping = $object->nb_expedition(); + if ($object->statut > 0 && $object->statut < 3 && $object->getNbOfProductsLines() > 0) { if ($user->rights->expedition->creer) { - // Chargement des permissions - /*$error = $user->load_entrepots(); deprecated - if (sizeof($user->entrepots) === 1) - { - print ''; - print $langs->trans('ShipProduct').''; - - } - else - {*/ print ''.$langs->trans('ShipProduct').''; - //} } else { @@ -1940,13 +1928,9 @@ else } // Close - if ($object->statut == 1 || $object->statut == 2) + if (($object->statut == 1 || $object->statut == 2) && $user->rights->commande->cloturer) { - if ($user->rights->commande->cloturer) - { - print ''.$langs->trans('Close').''; - } + print ''.$langs->trans('Close').''; } // Clone @@ -1956,21 +1940,22 @@ else } // Cancel order - if ($object->statut == 1) + if ($object->statut == 1 && $user->rights->commande->annuler) { - $nb_expedition = $object->nb_expedition(); - if ($user->rights->commande->annuler && $nb_expedition == 0) - { - print ''.$langs->trans('Cancel').''; - } + print ''.$langs->trans('Cancel').''; } // Delete order if ($user->rights->commande->supprimer) { - print ''.$langs->trans('Delete').''; + if ($numshipping == 0) + { + print ''.$langs->trans('Delete').''; + } + else + { + print ''.$langs->trans("Delete").''; + } } print '';