Fix: uniformize code

This commit is contained in:
Regis Houssin 2012-07-06 13:43:59 +02:00
parent d5060adf9d
commit 3bfd9182e0
3 changed files with 831 additions and 902 deletions

View File

@ -508,18 +508,15 @@ class Commande extends CommonObject
* Cancel an order * Cancel an order
* If stock is decremented on order validation, we must reincrement it * If stock is decremented on order validation, we must reincrement it
* *
* @param User $user Object user
* @param int $idwarehouse Id warehouse to use for stock change. * @param int $idwarehouse Id warehouse to use for stock change.
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function cancel($user, $idwarehouse=-1) function cancel($idwarehouse=-1)
{ {
global $conf,$langs; global $conf,$user,$langs;
$error=0; $error=0;
if ($user->rights->commande->valider)
{
$this->db->begin(); $this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."commande"; $sql = "UPDATE ".MAIN_DB_PREFIX."commande";
@ -544,7 +541,9 @@ class Commande extends CommonObject
$mouvP = new MouvementStock($this->db); $mouvP = new MouvementStock($this->db);
// We increment stock of product (and sub-products) // We increment stock of product (and sub-products)
$result=$mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("OrderCanceledInDolibarr",$this->ref)); $result=$mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("OrderCanceledInDolibarr",$this->ref));
if ($result < 0) { $error++; } if ($result < 0) {
$error++;
}
} }
} }
} }
@ -555,7 +554,9 @@ class Commande extends CommonObject
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
$interface=new Interfaces($this->db); $interface=new Interfaces($this->db);
$result=$interface->run_triggers('ORDER_CANCEL',$this,$user,$langs,$conf); $result=$interface->run_triggers('ORDER_CANCEL',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; } if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers // Fin appel triggers
} }
@ -580,7 +581,6 @@ class Commande extends CommonObject
return -1; return -1;
} }
} }
}
/** /**
* Create order * Create order

View File

@ -73,6 +73,7 @@ $object = new Commande($db);
if ($id > 0 || ! empty($ref)) if ($id > 0 || ! empty($ref))
{ {
$ret=$object->fetch($id, $ref); $ret=$object->fetch($id, $ref);
$ret=$object->fetch_thirdparty();
} }
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
@ -89,7 +90,7 @@ $parameters=array('socid'=>$socid);
$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
// Action clone object // Action clone object
if ($action == 'confirm_clone' && $confirm == 'yes') if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->commande->creer)
{ {
if (1==0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers')) if (1==0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers'))
{ {
@ -97,7 +98,7 @@ if ($action == 'confirm_clone' && $confirm == 'yes')
} }
else else
{ {
if ($object->fetch($id) > 0) if ($object->id > 0)
{ {
$result=$object->createFromClone($socid, $hookmanager); $result=$object->createFromClone($socid, $hookmanager);
if ($result > 0) if ($result > 0)
@ -117,7 +118,6 @@ if ($action == 'confirm_clone' && $confirm == 'yes')
// Reopen a closed order // Reopen a closed order
else if ($action == 'reopen' && $user->rights->commande->creer) else if ($action == 'reopen' && $user->rights->commande->creer)
{ {
$object->fetch($id);
if ($object->statut == 3) if ($object->statut == 3)
{ {
$result = $object->set_reopen($user); $result = $object->set_reopen($user);
@ -134,12 +134,8 @@ else if ($action == 'reopen' && $user->rights->commande->creer)
} }
// Suppression de la commande // Suppression de la commande
else if ($action == 'confirm_delete' && $confirm == 'yes') else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->commande->supprimer)
{ {
if ($user->rights->commande->supprimer)
{
$object->fetch($id);
$object->fetch_thirdparty();
$result=$object->delete($user); $result=$object->delete($user);
if ($result > 0) if ($result > 0)
{ {
@ -151,16 +147,10 @@ else if ($action == 'confirm_delete' && $confirm == 'yes')
$mesg='<div class="error">'.$object->error.'</div>'; $mesg='<div class="error">'.$object->error.'</div>';
} }
} }
}
// Remove a product line // Remove a product line
else if ($action == 'confirm_deleteline' && $confirm == 'yes') else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->commande->creer)
{ {
if ($user->rights->commande->creer)
{
$object->fetch($id);
$object->fetch_thirdparty();
$result = $object->deleteline($lineid); $result = $object->deleteline($lineid);
if ($result > 0) if ($result > 0)
{ {
@ -179,20 +169,19 @@ else if ($action == 'confirm_deleteline' && $confirm == 'yes')
$ret=$object->fetch($id); // Reload to get new records $ret=$object->fetch($id); // Reload to get new records
commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager);
} }
Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
exit;
} }
else else
{ {
$mesg='<div class="error">'.$object->error.'</div>'; $mesg='<div class="error">'.$object->error.'</div>';
} }
} }
Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
exit;
}
// Categorisation dans projet // Categorisation dans projet
else if ($action == 'classin') else if ($action == 'classin' && $user->rights->commande->creer)
{ {
$object->fetch($id);
$object->setProject($_POST['projectid']); $object->setProject($_POST['projectid']);
} }
@ -202,7 +191,7 @@ else if ($action == 'add' && $user->rights->commande->creer)
$datecommande = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); $datecommande = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
$datelivraison = dol_mktime(12, 0, 0, $_POST['liv_month'],$_POST['liv_day'],$_POST['liv_year']); $datelivraison = dol_mktime(12, 0, 0, $_POST['liv_month'],$_POST['liv_day'],$_POST['liv_year']);
$object->socid=GETPOST('socid','int'); $object->socid=$socid;
$object->fetch_thirdparty(); $object->fetch_thirdparty();
$db->begin(); $db->begin();
@ -390,22 +379,19 @@ else if ($action == 'add' && $user->rights->commande->creer)
} }
else if ($action == 'classifybilled') else if ($action == 'classifybilled' && $user->rights->commande->creer)
{ {
$object->fetch($id);
$object->classer_facturee(); $object->classer_facturee();
} }
// Positionne ref commande client // Positionne ref commande client
else if ($action == 'set_ref_client' && $user->rights->commande->creer) else if ($action == 'set_ref_client' && $user->rights->commande->creer)
{ {
$object->fetch($id);
$object->set_ref_client($user, $_POST['ref_client']); $object->set_ref_client($user, $_POST['ref_client']);
} }
else if ($action == 'setremise' && $user->rights->commande->creer) else if ($action == 'setremise' && $user->rights->commande->creer)
{ {
$object->fetch($id);
$object->set_remise($user, $_POST['remise']); $object->set_remise($user, $_POST['remise']);
} }
@ -413,8 +399,7 @@ else if ($action == 'setabsolutediscount' && $user->rights->commande->creer)
{ {
if ($_POST["remise_id"]) if ($_POST["remise_id"])
{ {
$ret=$object->fetch($id); if ($object->id > 0)
if ($ret > 0)
{ {
$object->insert_discount($_POST["remise_id"]); $object->insert_discount($_POST["remise_id"]);
} }
@ -430,7 +415,6 @@ else if ($action == 'setdate' && $user->rights->commande->creer)
//print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year']; //print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year'];
$date=dol_mktime(0, 0, 0, $_POST['order_month'], $_POST['order_day'], $_POST['order_year']); $date=dol_mktime(0, 0, 0, $_POST['order_month'], $_POST['order_day'], $_POST['order_year']);
$object->fetch($id);
$result=$object->set_date($user,$date); $result=$object->set_date($user,$date);
if ($result < 0) if ($result < 0)
{ {
@ -443,7 +427,6 @@ else if ($action == 'setdate_livraison' && $user->rights->commande->creer)
//print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year']; //print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year'];
$datelivraison=dol_mktime(0, 0, 0, $_POST['liv_month'], $_POST['liv_day'], $_POST['liv_year']); $datelivraison=dol_mktime(0, 0, 0, $_POST['liv_month'], $_POST['liv_day'], $_POST['liv_year']);
$object->fetch($id);
$result=$object->set_date_livraison($user,$datelivraison); $result=$object->set_date_livraison($user,$datelivraison);
if ($result < 0) if ($result < 0)
{ {
@ -453,28 +436,24 @@ else if ($action == 'setdate_livraison' && $user->rights->commande->creer)
else if ($action == 'setmode' && $user->rights->commande->creer) else if ($action == 'setmode' && $user->rights->commande->creer)
{ {
$object->fetch($id);
$result = $object->setPaymentMethods(GETPOST('mode_reglement_id','int')); $result = $object->setPaymentMethods(GETPOST('mode_reglement_id','int'));
if ($result < 0) dol_print_error($db,$object->error); if ($result < 0) dol_print_error($db,$object->error);
} }
else if ($action == 'setavailability' && $user->rights->commande->creer) else if ($action == 'setavailability' && $user->rights->commande->creer)
{ {
$object->fetch($id);
$result=$object->availability($_POST['availability_id']); $result=$object->availability($_POST['availability_id']);
if ($result < 0) dol_print_error($db,$object->error); if ($result < 0) dol_print_error($db,$object->error);
} }
else if ($action == 'setdemandreason' && $user->rights->commande->creer) else if ($action == 'setdemandreason' && $user->rights->commande->creer)
{ {
$object->fetch($id);
$result=$object->demand_reason($_POST['demand_reason_id']); $result=$object->demand_reason($_POST['demand_reason_id']);
if ($result < 0) dol_print_error($db,$object->error); if ($result < 0) dol_print_error($db,$object->error);
} }
else if ($action == 'setconditions' && $user->rights->commande->creer) else if ($action == 'setconditions' && $user->rights->commande->creer)
{ {
$object->fetch($id);
$result=$object->setPaymentTerms(GETPOST('cond_reglement_id','int')); $result=$object->setPaymentTerms(GETPOST('cond_reglement_id','int'));
if ($result < 0) if ($result < 0)
{ {
@ -502,26 +481,22 @@ else if ($action == 'setconditions' && $user->rights->commande->creer)
else if ($action == 'setremisepercent' && $user->rights->commande->creer) else if ($action == 'setremisepercent' && $user->rights->commande->creer)
{ {
$object->fetch($id);
$result = $object->set_remise($user, $_POST['remise_percent']); $result = $object->set_remise($user, $_POST['remise_percent']);
} }
else if ($action == 'setremiseabsolue' && $user->rights->commande->creer) else if ($action == 'setremiseabsolue' && $user->rights->commande->creer)
{ {
$object->fetch($id);
$result = $object->set_remise_absolue($user, $_POST['remise_absolue']); $result = $object->set_remise_absolue($user, $_POST['remise_absolue']);
} }
else if ($action == 'setnote_public' && $user->rights->commande->creer) else if ($action == 'setnote_public' && $user->rights->commande->creer)
{ {
$object->fetch($id);
$result=$object->update_note_public(dol_html_entity_decode(GETPOST('note_public'), ENT_QUOTES)); $result=$object->update_note_public(dol_html_entity_decode(GETPOST('note_public'), ENT_QUOTES));
if ($result < 0) dol_print_error($db,$object->error); if ($result < 0) dol_print_error($db,$object->error);
} }
else if ($action == 'setnote' && $user->rights->commande->creer) else if ($action == 'setnote' && $user->rights->commande->creer)
{ {
$object->fetch($id);
$result=$object->update_note(dol_html_entity_decode(GETPOST('note'), ENT_QUOTES)); $result=$object->update_note(dol_html_entity_decode(GETPOST('note'), ENT_QUOTES));
if ($result < 0) dol_print_error($db,$object->error); if ($result < 0) dol_print_error($db,$object->error);
} }
@ -546,14 +521,6 @@ else if ($action == 'addline' && $user->rights->commande->creer)
if ($result >= 0 && $_POST['qty'] && (($_POST['np_price'] != '' && ($_POST['np_desc'] || $_POST['dp_desc'])) || $_POST['idprod'])) if ($result >= 0 && $_POST['qty'] && (($_POST['np_price'] != '' && ($_POST['np_desc'] || $_POST['dp_desc'])) || $_POST['idprod']))
{ {
$ret=$object->fetch($id);
if ($ret < 0)
{
dol_print_error($db,$object->error);
exit;
}
$ret=$object->fetch_thirdparty();
// Clean parameters // Clean parameters
$suffixe = $_POST['idprod'] ? '_predef' : ''; $suffixe = $_POST['idprod'] ? '_predef' : '';
$date_start=dol_mktime(0, 0, 0, $_POST['date_start'.$suffixe.'month'], $_POST['date_start'.$suffixe.'day'], $_POST['date_start'.$suffixe.'year']); $date_start=dol_mktime(0, 0, 0, $_POST['date_start'.$suffixe.'month'], $_POST['date_start'.$suffixe.'day'], $_POST['date_start'.$suffixe.'year']);
@ -716,9 +683,6 @@ else if ($action == 'addline' && $user->rights->commande->creer)
*/ */
else if ($action == 'updateligne' && $user->rights->commande->creer && $_POST['save'] == $langs->trans('Save')) else if ($action == 'updateligne' && $user->rights->commande->creer && $_POST['save'] == $langs->trans('Save'))
{ {
if (! $object->fetch($id) > 0) dol_print_error($db);
$object->fetch_thirdparty();
// Clean parameters // Clean parameters
$date_start=''; $date_start='';
$date_end=''; $date_end='';
@ -802,7 +766,7 @@ else if ($action == 'updateligne' && $user->rights->commande->creer && $_POST['s
} }
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
{ {
$ret=$object->fetch($id); // Reload to get new records $ret=$object->fetch($object->id); // Reload to get new records
commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager);
} }
} }
@ -816,7 +780,7 @@ else if ($action == 'updateligne' && $user->rights->commande->creer && $_POST['s
else if ($action == 'updateligne' && $user->rights->commande->creer && $_POST['cancel'] == $langs->trans('Cancel')) else if ($action == 'updateligne' && $user->rights->commande->creer && $_POST['cancel'] == $langs->trans('Cancel'))
{ {
Header('Location: fiche.php?id='.$id); // Pour reaffichage de la fiche en cours d'edition Header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // Pour reaffichage de la fiche en cours d'edition
exit; exit;
} }
@ -824,9 +788,6 @@ else if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->co
{ {
$idwarehouse=GETPOST('idwarehouse'); $idwarehouse=GETPOST('idwarehouse');
$object->fetch($id); // Load order and lines
$object->fetch_thirdparty();
// Check parameters // Check parameters
if (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1)) if (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1))
{ {
@ -863,9 +824,6 @@ else if ($action == 'confirm_modif' && $user->rights->commande->creer)
{ {
$idwarehouse=GETPOST('idwarehouse'); $idwarehouse=GETPOST('idwarehouse');
$object->fetch($id); // Load order and lines
$object->fetch_thirdparty();
// Check parameters // Check parameters
if (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1)) if (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1))
{ {
@ -894,7 +852,7 @@ else if ($action == 'confirm_modif' && $user->rights->commande->creer)
} }
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
{ {
$ret=$object->fetch($id); // Reload to get new records $ret=$object->fetch($object->id); // Reload to get new records
commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager);
} }
} }
@ -903,8 +861,6 @@ else if ($action == 'confirm_modif' && $user->rights->commande->creer)
else if ($action == 'confirm_close' && $confirm == 'yes' && $user->rights->commande->cloturer) else if ($action == 'confirm_close' && $confirm == 'yes' && $user->rights->commande->cloturer)
{ {
$object->fetch($id); // Load order and lines
$result = $object->cloture($user); $result = $object->cloture($user);
if ($result < 0) $mesgs=$object->errors; if ($result < 0) $mesgs=$object->errors;
} }
@ -913,9 +869,6 @@ else if ($action == 'confirm_cancel' && $confirm == 'yes' && $user->rights->comm
{ {
$idwarehouse=GETPOST('idwarehouse'); $idwarehouse=GETPOST('idwarehouse');
$object->fetch($id); // Load order and lines
$object->fetch_thirdparty();
// Check parameters // Check parameters
if (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1)) if (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1))
{ {
@ -929,7 +882,7 @@ else if ($action == 'confirm_cancel' && $confirm == 'yes' && $user->rights->comm
if (! $error) if (! $error)
{ {
$result = $object->cancel($user,$idwarehouse); $result = $object->cancel($idwarehouse);
} }
} }
@ -940,8 +893,6 @@ else if ($action == 'confirm_cancel' && $confirm == 'yes' && $user->rights->comm
else if ($action == 'up' && $user->rights->commande->creer) else if ($action == 'up' && $user->rights->commande->creer)
{ {
$object->fetch($id);
$object->fetch_thirdparty();
$object->line_up($_GET['rowid']); $object->line_up($_GET['rowid']);
// Define output language // Define output language
@ -957,14 +908,12 @@ else if ($action == 'up' && $user->rights->commande->creer)
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager);
Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id.'#'.$_GET['rowid']); Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.$_GET['rowid']);
exit; exit;
} }
else if ($action == 'down' && $user->rights->commande->creer) else if ($action == 'down' && $user->rights->commande->creer)
{ {
$object->fetch($id);
$object->fetch_thirdparty();
$object->line_down($_GET['rowid']); $object->line_down($_GET['rowid']);
// Define output language // Define output language
@ -979,7 +928,7 @@ else if ($action == 'down' && $user->rights->commande->creer)
} }
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager);
Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id.'#'.$_GET['rowid']); Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.$_GET['rowid']);
exit; exit;
} }
@ -991,9 +940,6 @@ else if ($action == 'builddoc') // In get or post
*/ */
// Sauvegarde le dernier modele choisi pour generer un document // Sauvegarde le dernier modele choisi pour generer un document
$result=$object->fetch($id);
$object->fetch_thirdparty();
if ($_REQUEST['model']) if ($_REQUEST['model'])
{ {
$object->setDocModel($user, $_REQUEST['model']); $object->setDocModel($user, $_REQUEST['model']);
@ -1025,12 +971,10 @@ else if ($action == 'builddoc') // In get or post
// Remove file in doc form // Remove file in doc form
else if ($action == 'remove_file') else if ($action == 'remove_file')
{ {
if ($object->fetch($id)) if ($object->id > 0)
{ {
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php"); require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
$object->fetch_thirdparty();
$langs->load("other"); $langs->load("other");
$upload_dir = $conf->commande->dir_output; $upload_dir = $conf->commande->dir_output;
$file = $upload_dir . '/' . GETPOST('file'); $file = $upload_dir . '/' . GETPOST('file');
@ -1079,10 +1023,7 @@ if ($action == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_P
{ {
$langs->load('mails'); $langs->load('mails');
$result=$object->fetch($id); if ($object->id > 0)
$result=$object->fetch_thirdparty();
if ($result > 0)
{ {
// $ref = dol_sanitizeFileName($object->ref); // $ref = dol_sanitizeFileName($object->ref);
// $file = $conf->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf'; // $file = $conf->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf';
@ -1231,12 +1172,10 @@ if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
{ {
if ($action == 'addcontact' && $user->rights->commande->creer) if ($action == 'addcontact' && $user->rights->commande->creer)
{ {
$result = $object->fetch($id); if ($object->id > 0)
if ($result > 0 && $id > 0)
{ {
$contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid')); $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
$result = $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]); $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
} }
if ($result >= 0) if ($result >= 0)
@ -1261,7 +1200,7 @@ if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
// bascule du statut d'un contact // bascule du statut d'un contact
else if ($action == 'swapstatut' && $user->rights->commande->creer) else if ($action == 'swapstatut' && $user->rights->commande->creer)
{ {
if ($object->fetch($id)) if ($object->id > 0)
{ {
$result=$object->swapContactStatus(GETPOST('ligne')); $result=$object->swapContactStatus(GETPOST('ligne'));
} }
@ -1274,7 +1213,6 @@ if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
// Efface un contact // Efface un contact
else if ($action == 'deletecontact' && $user->rights->commande->creer) else if ($action == 'deletecontact' && $user->rights->commande->creer)
{ {
$object->fetch($id);
$result = $object->delete_contact($lineid); $result = $object->delete_contact($lineid);
if ($result >= 0) if ($result >= 0)
@ -1620,16 +1558,13 @@ else
/* *************************************************************************** */ /* *************************************************************************** */
$now=dol_now(); $now=dol_now();
if ($id > 0 || ! empty($ref)) if ($object->id > 0)
{ {
dol_htmloutput_mesg($mesg,$mesgs); dol_htmloutput_mesg($mesg,$mesgs);
dol_htmloutput_errors('',$errors); dol_htmloutput_errors('',$errors);
$product_static=new Product($db); $product_static=new Product($db);
$result=$object->fetch($id,$ref);
if ($result > 0)
{
$soc = new Societe($db); $soc = new Societe($db);
$soc->fetch($object->socid); $soc->fetch($object->socid);
@ -2346,15 +2281,9 @@ else
print '<br>'; print '<br>';
} }
} }
else
{
// Commande non trouvee
dol_print_error($db);
}
}
} }
$db->close();
llxFooter(); llxFooter();
$db->close();
?> ?>

View File

@ -202,7 +202,7 @@ class CommandeTest extends PHPUnit_Framework_TestCase
$langs=$this->savlangs; $langs=$this->savlangs;
$db=$this->savdb; $db=$this->savdb;
$result=$localobject->cancel($user); $result=$localobject->cancel();
print __METHOD__." id=".$localobject->id." result=".$result."\n"; print __METHOD__." id=".$localobject->id." result=".$result."\n";
$this->assertLessThan($result, 0); $this->assertLessThan($result, 0);