Fix: error sql

Fix: don't delete order if shipping exist
Fix: uniformize code
This commit is contained in:
Regis Houssin 2011-04-22 17:31:28 +00:00
parent cdf52cafcf
commit a39c95e3b4
2 changed files with 23 additions and 36 deletions

View File

@ -1461,9 +1461,11 @@ class Commande extends CommonObject
function nb_expedition() function nb_expedition()
{ {
$sql = 'SELECT count(*)'; $sql = 'SELECT count(*)';
$sql.= ' FROM '.MAIN_DB_PREFIX.'expedition as e,'; $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.= ', '.MAIN_DB_PREFIX.'element_element as el';
$sql.= " WHERE el.fk_source = ".$this->id; $sql.= ' WHERE el.fk_source = '.$this->id;
$sql.= " AND el.fk_target = e.rowid";
$sql.= " AND el.targettype = 'shipping'";
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)

View File

@ -1865,18 +1865,14 @@ else
// Valid // Valid
if ($object->statut == 0 && $object->total_ttc >= 0 && $numlines > 0 && $user->rights->commande->valider) if ($object->statut == 0 && $object->total_ttc >= 0 && $numlines > 0 && $user->rights->commande->valider)
{ {
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=validate"'; print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=validate">'.$langs->trans('Validate').'</a>';
print '>'.$langs->trans('Validate').'</a>';
} }
// Edit // Edit
if ($object->statut == 1) if ($object->statut == 1 && $user->rights->commande->creer)
{
if ($user->rights->commande->creer)
{ {
print '<a class="butAction" href="fiche.php?id='.$object->id.'&amp;action=modif">'.$langs->trans('Modify').'</a>'; print '<a class="butAction" href="fiche.php?id='.$object->id.'&amp;action=modif">'.$langs->trans('Modify').'</a>';
} }
}
// Send // Send
if ($object->statut > 0) if ($object->statut > 0)
@ -1893,24 +1889,16 @@ else
} }
// Ship // Ship
$numshipping=0;
if ($conf->expedition->enabled) if ($conf->expedition->enabled)
{ {
$numshipping = $object->nb_expedition();
if ($object->statut > 0 && $object->statut < 3 && $object->getNbOfProductsLines() > 0) if ($object->statut > 0 && $object->statut < 3 && $object->getNbOfProductsLines() > 0)
{ {
if ($user->rights->expedition->creer) if ($user->rights->expedition->creer)
{ {
// Chargement des permissions
/*$error = $user->load_entrepots(); deprecated
if (sizeof($user->entrepots) === 1)
{
print '<a class="butAction" href="'.DOL_URL_ROOT.'/expedition/fiche.php?id='.$id.'&amp;action=create&amp;commande_id='.$id.'&entrepot_id='.$user->entrepots[0]['id'].'">';
print $langs->trans('ShipProduct').'</a>';
}
else
{*/
print '<a class="butAction" href="'.DOL_URL_ROOT.'/expedition/shipment.php?id='.$object->id.'">'.$langs->trans('ShipProduct').'</a>'; print '<a class="butAction" href="'.DOL_URL_ROOT.'/expedition/shipment.php?id='.$object->id.'">'.$langs->trans('ShipProduct').'</a>';
//}
} }
else else
{ {
@ -1940,13 +1928,9 @@ else
} }
// Close // 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 '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=close">'.$langs->trans('Close').'</a>';
{
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=close"';
print '>'.$langs->trans('Close').'</a>';
}
} }
// Clone // Clone
@ -1956,21 +1940,22 @@ else
} }
// Cancel order // Cancel order
if ($object->statut == 1) if ($object->statut == 1 && $user->rights->commande->annuler)
{ {
$nb_expedition = $object->nb_expedition(); print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=cancel">'.$langs->trans('Cancel').'</a>';
if ($user->rights->commande->annuler && $nb_expedition == 0)
{
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=cancel"';
print '>'.$langs->trans('Cancel').'</a>';
}
} }
// Delete order // Delete order
if ($user->rights->commande->supprimer) if ($user->rights->commande->supprimer)
{ {
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete"'; if ($numshipping == 0)
print '>'.$langs->trans('Delete').'</a>'; {
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete">'.$langs->trans('Delete').'</a>';
}
else
{
print '<a class="butActionRefused" href="#" title="'.$langs->trans("ShippingExist").'">'.$langs->trans("Delete").'</a>';
}
} }
print '</div>'; print '</div>';