Fix: uniformize code

This commit is contained in:
Regis Houssin 2011-05-09 09:44:06 +00:00
parent 7416eeea9b
commit 970a488f7c

View File

@ -51,6 +51,7 @@ $langs->load('stocks');
$id = GETPOST("id"); $id = GETPOST("id");
$ref = GETPOST("ref"); $ref = GETPOST("ref");
$action = GETPOST("action"); $action = GETPOST("action");
$confirm = GETPOST("confirm");
$comclientid = GETPOST("comid"); $comclientid = GETPOST("comid");
$socid = GETPOST("socid"); $socid = GETPOST("socid");
$projectid = GETPOST("projectid"); $projectid = GETPOST("projectid");
@ -61,6 +62,8 @@ $result = restrictedArea($user, 'commande_fournisseur', $id,'');
$mesg=''; $mesg='';
$object = new CommandeFournisseur($db);
/* /*
* Actions * Actions
@ -69,32 +72,28 @@ $mesg='';
// conditions de reglement // conditions de reglement
if ($action == 'setconditions' && $user->rights->fournisseur->commande->creer) if ($action == 'setconditions' && $user->rights->fournisseur->commande->creer)
{ {
$commande = new CommandeFournisseur($db); $object->fetch($id);
$commande->fetch($id); $result=$object->cond_reglement($_POST['cond_reglement_id']);
$result=$commande->cond_reglement($_POST['cond_reglement_id']);
} }
// mode de reglement // mode de reglement
if ($action == 'setmode' && $user->rights->fournisseur->commande->creer) if ($action == 'setmode' && $user->rights->fournisseur->commande->creer)
{ {
$commande = new CommandeFournisseur($db); $object->fetch($id);
$commande->fetch($id); $result=$object->mode_reglement($_POST['mode_reglement_id']);
$result=$commande->mode_reglement($_POST['mode_reglement_id']);
} }
// Set project // Set project
if ($action == 'classin') if ($action == 'classin')
{ {
$commande = new CommandeFournisseur($db); $object->fetch($id);
$commande->fetch($id); $object->setProject($projectid);
$commande->setProject($_POST["projectid"]);
} }
if ($action == 'setremisepercent' && $user->rights->fournisseur->commande->creer) if ($action == 'setremisepercent' && $user->rights->fournisseur->commande->creer)
{ {
$commande = new CommandeFournisseur($db); $object->fetch($id);
$commande->fetch($id); $result = $object->set_remise($user, $_POST['remise_percent']);
$result = $commande->set_remise($user, $_POST['remise_percent']);
} }
if ($action == 'reopen' && $user->rights->fournisseur->commande->approuver) if ($action == 'reopen' && $user->rights->fournisseur->commande->approuver)
@ -128,11 +127,10 @@ if ($action == 'addline' && $user->rights->fournisseur->commande->creer)
{ {
if (($_POST['qty'] || $_POST['pqty']) && (($_POST['pu'] && ($_POST['np_desc'] || $_POST['dp_desc'])) || $_POST['idprodfournprice'])) if (($_POST['qty'] || $_POST['pqty']) && (($_POST['pu'] && ($_POST['np_desc'] || $_POST['dp_desc'])) || $_POST['idprodfournprice']))
{ {
$commande = new CommandeFournisseur($db); $ret=$object->fetch($id);
$ret=$commande->fetch($id);
if ($ret < 0) if ($ret < 0)
{ {
dol_print_error($db,$commande->error); dol_print_error($db,$object->error);
exit; exit;
} }
@ -147,10 +145,10 @@ if ($action == 'addline' && $user->rights->fournisseur->commande->creer)
$idprod=$product->get_buyprice($_POST['idprodfournprice'], $qty); $idprod=$product->get_buyprice($_POST['idprodfournprice'], $qty);
//$societe=''; //$societe='';
if ($commande->socid) if ($object->socid)
{ {
$societe=new Societe($db); $societe=new Societe($db);
$societe->fetch($commande->socid); $societe->fetch($object->socid);
} }
if ($idprod > 0) if ($idprod > 0)
@ -174,7 +172,7 @@ if ($action == 'addline' && $user->rights->fournisseur->commande->creer)
$localtax1_tx= get_localtax($tva_tx, 1, $societe); $localtax1_tx= get_localtax($tva_tx, 1, $societe);
$localtax2_tx= get_localtax($tva_tx, 2, $societe); $localtax2_tx= get_localtax($tva_tx, 2, $societe);
$result=$commande->addline( $result=$object->addline(
$desc, $desc,
$pu, $pu,
$qty, $qty,
@ -216,14 +214,14 @@ if ($action == 'addline' && $user->rights->fournisseur->commande->creer)
{ {
$price_base_type = 'HT'; $price_base_type = 'HT';
$ht = price2num($_POST['pu']); $ht = price2num($_POST['pu']);
$result=$commande->addline($desc, $ht, $_POST['qty'], $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $_POST['remise_percent'], $price_base_type, 0, $type); $result=$object->addline($desc, $ht, $_POST['qty'], $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $_POST['remise_percent'], $price_base_type, 0, $type);
} }
else else
{ {
$ttc = price2num($_POST['amountttc']); $ttc = price2num($_POST['amountttc']);
$ht = $ttc / (1 + ($tauxtva / 100)); $ht = $ttc / (1 + ($tauxtva / 100));
$price_base_type = 'HT'; $price_base_type = 'HT';
$result=$commande->addline($desc, $ht, $_POST['qty'], $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $_POST['remise_percent'], $price_base_type, $ttc, $type); $result=$object->addline($desc, $ht, $_POST['qty'], $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $_POST['remise_percent'], $price_base_type, $ttc, $type);
} }
} }
} }
@ -237,7 +235,7 @@ if ($action == 'addline' && $user->rights->fournisseur->commande->creer)
$outputlangs = new Translate("",$conf); $outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($_REQUEST['lang_id']); $outputlangs->setDefaultLang($_REQUEST['lang_id']);
} }
supplier_order_pdf_create($db, $commande, $commande->modelpdf, $outputlangs); supplier_order_pdf_create($db, $object, $object->modelpdf, $outputlangs);
unset($_POST['qty']); unset($_POST['qty']);
unset($_POST['type']); unset($_POST['type']);
@ -252,7 +250,7 @@ if ($action == 'addline' && $user->rights->fournisseur->commande->creer)
} }
else if (empty($mesg)) else if (empty($mesg))
{ {
$mesg='<div class="error">'.$commande->error.'</div>'; $mesg='<div class="error">'.$object->error.'</div>';
} }
} }
} }
@ -267,16 +265,16 @@ if ($action == 'updateligne' && $user->rights->fournisseur->commande->creer && $
{ {
if ($product->fetch($_POST["elrowid"]) < 0) dol_print_error($db); if ($product->fetch($_POST["elrowid"]) < 0) dol_print_error($db);
} }
$commande = new CommandeFournisseur($db,"",$id);
if ($commande->fetch($id) < 0) dol_print_error($db); if ($object->fetch($id) < 0) dol_print_error($db);
$societe=new Societe($db); $societe=new Societe($db);
$societe->fetch($commande->socid); $societe->fetch($object->socid);
$localtax1_tx=get_localtax($_POST['tva_tx'],1,$societe); $localtax1_tx=get_localtax($_POST['tva_tx'],1,$societe);
$localtax2_tx=get_localtax($_POST['tva_tx'],2,$societe); $localtax2_tx=get_localtax($_POST['tva_tx'],2,$societe);
$result = $commande->updateline($_POST['elrowid'], $result = $object->updateline($_POST['elrowid'],
$_POST['eldesc'], $_POST['eldesc'],
$_POST['pu'], $_POST['pu'],
$_POST['qty'], $_POST['qty'],
@ -297,22 +295,21 @@ if ($action == 'updateligne' && $user->rights->fournisseur->commande->creer && $
$outputlangs = new Translate("",$conf); $outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($_REQUEST['lang_id']); $outputlangs->setDefaultLang($_REQUEST['lang_id']);
} }
supplier_order_pdf_create($db, $commande, $commande->modelpdf, $outputlangs); supplier_order_pdf_create($db, $object, $object->modelpdf, $outputlangs);
} }
else else
{ {
dol_print_error($db,$commande->error); dol_print_error($db,$object->error);
exit; exit;
} }
} }
if ($action == 'confirm_deleteproductline' && $_REQUEST['confirm'] == 'yes') if ($action == 'confirm_deleteproductline' && $confirm == 'yes')
{ {
if ($user->rights->fournisseur->commande->creer) if ($user->rights->fournisseur->commande->creer)
{ {
$commande = new CommandeFournisseur($db); $object->fetch($id);
$commande->fetch($id); $result = $object->deleteline($_GET['lineid']);
$result = $commande->deleteline($_GET['lineid']);
$outputlangs = $langs; $outputlangs = $langs;
if (! empty($_REQUEST['lang_id'])) if (! empty($_REQUEST['lang_id']))
@ -320,17 +317,16 @@ if ($action == 'confirm_deleteproductline' && $_REQUEST['confirm'] == 'yes')
$outputlangs = new Translate("",$conf); $outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($_REQUEST['lang_id']); $outputlangs->setDefaultLang($_REQUEST['lang_id']);
} }
supplier_order_pdf_create($db, $commande, $commande->modelpdf, $outputlangs); supplier_order_pdf_create($db, $object, $object->modelpdf, $outputlangs);
} }
} }
if ($action == 'confirm_valid' && $_REQUEST['confirm'] == 'yes' && $user->rights->fournisseur->commande->valider) if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->fournisseur->commande->valider)
{ {
$commande = new CommandeFournisseur($db); $object->fetch($id);
$commande->fetch($id);
$commande->date_commande=dol_now(); $object->date_commande=dol_now();
$result = $commande->valid($user); $result = $object->valid($user);
if ($result >= 0) if ($result >= 0)
{ {
$outputlangs = $langs; $outputlangs = $langs;
@ -339,11 +335,11 @@ if ($action == 'confirm_valid' && $_REQUEST['confirm'] == 'yes' && $user->rights
$outputlangs = new Translate("",$conf); $outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($_REQUEST['lang_id']); $outputlangs->setDefaultLang($_REQUEST['lang_id']);
} }
supplier_order_pdf_create($db, $commande, $commande->modelpdf, $outputlangs); supplier_order_pdf_create($db, $object, $object->modelpdf, $outputlangs);
} }
else else
{ {
$mesg=$commande->error; $mesg=$object->error;
} }
// If we have permission, we go directly on approved step // If we have permission, we go directly on approved step
@ -353,11 +349,10 @@ if ($action == 'confirm_valid' && $_REQUEST['confirm'] == 'yes' && $user->rights
} }
} }
if ($action == 'confirm_approve' && $_REQUEST["confirm"] == 'yes' && $user->rights->fournisseur->commande->approuver) if ($action == 'confirm_approve' && $confirm == 'yes' && $user->rights->fournisseur->commande->approuver)
{ {
$commande = new CommandeFournisseur($db); $object->fetch($id);
$commande->fetch($id); $result = $object->approve($user);
$result = $commande->approve($user);
if ($result > 0) if ($result > 0)
{ {
Header("Location: fiche.php?id=".$id); Header("Location: fiche.php?id=".$id);
@ -365,15 +360,14 @@ if ($action == 'confirm_approve' && $_REQUEST["confirm"] == 'yes' && $user->righ
} }
else else
{ {
$mesg=$commande->error; $mesg=$object->error;
} }
} }
if ($action == 'confirm_refuse' && $_REQUEST['confirm'] == 'yes' && $user->rights->fournisseur->commande->approuver) if ($action == 'confirm_refuse' && $confirm == 'yes' && $user->rights->fournisseur->commande->approuver)
{ {
$commande = new CommandeFournisseur($db); $object->fetch($id);
$commande->fetch($id); $result = $object->refuse($user);
$result = $commande->refuse($user);
if ($result > 0) if ($result > 0)
{ {
Header("Location: fiche.php?id=".$id); Header("Location: fiche.php?id=".$id);
@ -381,15 +375,14 @@ if ($action == 'confirm_refuse' && $_REQUEST['confirm'] == 'yes' && $user->right
} }
else else
{ {
$mesg=$commande->error; $mesg=$object->error;
} }
} }
if ($action == 'confirm_commande' && $_REQUEST['confirm'] == 'yes' && $user->rights->fournisseur->commande->commander) if ($action == 'confirm_commande' && $confirm == 'yes' && $user->rights->fournisseur->commande->commander)
{ {
$commande = new CommandeFournisseur($db); $object->fetch($id);
$commande->fetch($id); $result = $object->commande($user, $_REQUEST["datecommande"], $_REQUEST["methode"], $_REQUEST['comment']);
$result = $commande->commande($user, $_REQUEST["datecommande"], $_REQUEST["methode"], $_REQUEST['comment']);
if ($result > 0) if ($result > 0)
{ {
Header("Location: fiche.php?id=".$id); Header("Location: fiche.php?id=".$id);
@ -397,16 +390,15 @@ if ($action == 'confirm_commande' && $_REQUEST['confirm'] == 'yes' && $user->rig
} }
else else
{ {
$mesg=$commande->error; $mesg=$object->error;
} }
} }
if ($action == 'confirm_delete' && $_REQUEST['confirm'] == 'yes' && $user->rights->fournisseur->commande->supprimer) if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fournisseur->commande->supprimer)
{ {
$commande = new CommandeFournisseur($db); $object->fetch($id);
$commande->fetch($id); $result=$object->delete($user);
$result=$commande->delete($user);
if ($result > 0) if ($result > 0)
{ {
Header("Location: ".DOL_URL_ROOT.'/fourn/commande/liste.php'); Header("Location: ".DOL_URL_ROOT.'/fourn/commande/liste.php');
@ -414,21 +406,20 @@ if ($action == 'confirm_delete' && $_REQUEST['confirm'] == 'yes' && $user->right
} }
else else
{ {
$mesg=$commande->error; $mesg=$object->error;
} }
} }
// Receive // Receive
if ($_POST["action"] == 'livraison' && $user->rights->fournisseur->commande->receptionner) if ($action == 'livraison' && $user->rights->fournisseur->commande->receptionner)
{ {
$commande = new CommandeFournisseur($db); $object->fetch($id);
$commande->fetch($id);
if ($_POST["type"]) if ($_POST["type"])
{ {
$date_liv = dol_mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]); $date_liv = dol_mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]);
$result = $commande->Livraison($user, $date_liv, $_POST["type"], $_POST["comment"]); $result = $object->Livraison($user, $date_liv, $_POST["type"], $_POST["comment"]);
if ($result > 0) if ($result > 0)
{ {
Header("Location: fiche.php?id=".$id); Header("Location: fiche.php?id=".$id);
@ -440,7 +431,7 @@ if ($_POST["action"] == 'livraison' && $user->rights->fournisseur->commande->rec
} }
else else
{ {
dol_print_error($db,$commande->error); dol_print_error($db,$object->error);
exit; exit;
} }
} }
@ -450,11 +441,10 @@ if ($_POST["action"] == 'livraison' && $user->rights->fournisseur->commande->rec
} }
} }
if ($action == 'confirm_cancel' && $_REQUEST["confirm"] == 'yes' && $user->rights->fournisseur->commande->commander) if ($action == 'confirm_cancel' && $confirm == 'yes' && $user->rights->fournisseur->commande->commander)
{ {
$commande = new CommandeFournisseur($db); $object->fetch($id);
$commande->fetch($id); $result = $object->cancel($user);
$result = $commande->cancel($user);
if ($result > 0) if ($result > 0)
{ {
Header("Location: fiche.php?id=".$id); Header("Location: fiche.php?id=".$id);
@ -462,7 +452,7 @@ if ($action == 'confirm_cancel' && $_REQUEST["confirm"] == 'yes' && $user->right
} }
else else
{ {
$mesg=$commande->error; $mesg=$object->error;
} }
} }
@ -470,9 +460,8 @@ if ($action == 'confirm_cancel' && $_REQUEST["confirm"] == 'yes' && $user->right
if ($action == 'up' && $user->rights->fournisseur->commande->creer) if ($action == 'up' && $user->rights->fournisseur->commande->creer)
{ {
$commande = new CommandeFournisseur($db,'',$id); $object->fetch($id);
$commande->fetch($id); $object->line_up($_GET['rowid']);
$commande->line_up($_GET['rowid']);
$outputlangs = $langs; $outputlangs = $langs;
if (! empty($_REQUEST['lang_id'])) if (! empty($_REQUEST['lang_id']))
@ -480,16 +469,15 @@ if ($action == 'up' && $user->rights->fournisseur->commande->creer)
$outputlangs = new Translate("",$conf); $outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($_REQUEST['lang_id']); $outputlangs->setDefaultLang($_REQUEST['lang_id']);
} }
supplier_order_pdf_create($db, $commande, $commande->modelpdf, $outputlangs); supplier_order_pdf_create($db, $object, $object->modelpdf, $outputlangs);
Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#'.$_GET['rowid'])); Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#'.$_GET['rowid']));
exit; exit;
} }
if ($action == 'down' && $user->rights->fournisseur->commande->creer) if ($action == 'down' && $user->rights->fournisseur->commande->creer)
{ {
$commande = new CommandeFournisseur($db,'',$id); $object->fetch($id);
$commande->fetch($id); $object->line_down($_GET['rowid']);
$commande->line_down($_GET['rowid']);
$outputlangs = $langs; $outputlangs = $langs;
if (! empty($_REQUEST['lang_id'])) if (! empty($_REQUEST['lang_id']))
@ -497,7 +485,7 @@ if ($action == 'down' && $user->rights->fournisseur->commande->creer)
$outputlangs = new Translate("",$conf); $outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($_REQUEST['lang_id']); $outputlangs->setDefaultLang($_REQUEST['lang_id']);
} }
supplier_order_pdf_create($db, $commande, $commande->modelpdf, $outputlangs); supplier_order_pdf_create($db, $object, $object->modelpdf, $outputlangs);
Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#'.$_GET['rowid'])); Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#'.$_GET['rowid']));
exit; exit;
} }
@ -508,11 +496,10 @@ if ($action == 'builddoc') // En get ou en post
// Build document // Build document
// Sauvegarde le dernier module choisi pour generer un document // Sauvegarde le dernier module choisi pour generer un document
$commande = new CommandeFournisseur($db); $object->fetch($_REQUEST['id']);
$commande->fetch($_REQUEST['id']);
if ($_REQUEST['model']) if ($_REQUEST['model'])
{ {
$commande->setDocModel($user, $_REQUEST['model']); $object->setDocModel($user, $_REQUEST['model']);
} }
$outputlangs = $langs; $outputlangs = $langs;
@ -521,7 +508,7 @@ if ($action == 'builddoc') // En get ou en post
$outputlangs = new Translate("",$conf); $outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($_REQUEST['lang_id']); $outputlangs->setDefaultLang($_REQUEST['lang_id']);
} }
$result=supplier_order_pdf_create($db, $commande,$commande->modelpdf,$outputlangs); $result=supplier_order_pdf_create($db, $object,$object->modelpdf,$outputlangs);
if ($result <= 0) if ($result <= 0)
{ {
dol_print_error($db,$result); dol_print_error($db,$result);
@ -529,7 +516,7 @@ if ($action == 'builddoc') // En get ou en post
} }
else else
{ {
Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$commande->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc')); Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
exit; exit;
} }
} }
@ -538,9 +525,8 @@ if ($action == 'builddoc') // En get ou en post
if ($action=='remove_file') if ($action=='remove_file')
{ {
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
$commande = new CommandeFournisseur($db);
if ($commande->fetch($id)) if ($object->fetch($id))
{ {
$upload_dir = $conf->fournisseur->commande->dir_output . "/"; $upload_dir = $conf->fournisseur->commande->dir_output . "/";
$file = $upload_dir . '/' . $_GET['file']; $file = $upload_dir . '/' . $_GET['file'];
@ -596,8 +582,7 @@ if ($_POST['addfile'])
$mesg=dol_add_file_process($upload_dir,0,0); $mesg=dol_add_file_process($upload_dir,0,0);
$_GET["action"]='presend'; $action='presend';
$_POST["action"]='presend';
} }
/* /*
@ -613,24 +598,22 @@ if (! empty($_POST['removedfile']))
$mesg=dol_remove_file_process($_POST['removedfile'],0); $mesg=dol_remove_file_process($_POST['removedfile'],0);
$_GET["action"]='presend'; $action='presend';
$_POST["action"]='presend';
} }
/* /*
* Send mail * Send mail
*/ */
if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_POST['cancel']) if ($action == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_POST['cancel'])
{ {
$langs->load('mails'); $langs->load('mails');
$commande= new CommandeFournisseur($db); $result=$object->fetch($_POST['orderid']);
$result=$commande->fetch($_POST['orderid']); $result=$object->fetch_thirdparty();
$result=$commande->fetch_thirdparty();
if ($result > 0) if ($result > 0)
{ {
$ref = dol_sanitizeFileName($commande->ref); $ref = dol_sanitizeFileName($object->ref);
$file = $conf->fournisseur->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf'; $file = $conf->fournisseur->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf';
if (is_readable($file)) if (is_readable($file))
@ -646,12 +629,12 @@ if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile']
// Le destinataire a ete fourni via la liste deroulante // Le destinataire a ete fourni via la liste deroulante
if ($_POST['receiver'] < 0) // Id du tiers if ($_POST['receiver'] < 0) // Id du tiers
{ {
$sendto = $commande->client->email; $sendto = $object->client->email;
$sendtoid = 0; $sendtoid = 0;
} }
else // Id du contact else // Id du contact
{ {
$sendto = $commande->client->contact_get_property($_POST['receiver'],'email'); $sendto = $object->client->contact_get_property($_POST['receiver'],'email');
$sendtoid = $_POST['receiver']; $sendtoid = $_POST['receiver'];
} }
} }
@ -666,10 +649,10 @@ if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile']
$sendtocc = $_POST['sendtocc']; $sendtocc = $_POST['sendtocc'];
$deliveryreceipt = $_POST['deliveryreceipt']; $deliveryreceipt = $_POST['deliveryreceipt'];
if ($_POST['action'] == 'send') if ($action == 'send')
{ {
if (dol_strlen($_POST['subject'])) $subject=$_POST['subject']; if (dol_strlen($_POST['subject'])) $subject=$_POST['subject'];
else $subject = $langs->transnoentities('CustomerOrder').' '.$commande->ref; else $subject = $langs->transnoentities('CustomerOrder').' '.$object->ref;
$actiontypecode='AC_SUP_ORD'; $actiontypecode='AC_SUP_ORD';
$actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto.".\n"; $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto.".\n";
if ($message) if ($message)
@ -707,16 +690,16 @@ if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile']
$error=0; $error=0;
// Initialisation donnees // Initialisation donnees
$commande->sendtoid=$sendtoid; $object->sendtoid=$sendtoid;
$commande->actiontypecode=$actiontypecode; $object->actiontypecode=$actiontypecode;
$commande->actionmsg = $actionmsg; $object->actionmsg = $actionmsg;
$commande->actionmsg2= $actionmsg2; $object->actionmsg2= $actionmsg2;
$commande->supplierorderrowid=$commande->id; $object->supplierorderrowid=$object->id;
// Appel des triggers // Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
$interface=new Interfaces($db); $interface=new Interfaces($db);
$result=$interface->run_triggers('ORDER_SUPPLIER_SENTBYMAIL',$commande,$user,$langs,$conf); $result=$interface->run_triggers('ORDER_SUPPLIER_SENTBYMAIL',$object,$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
@ -728,7 +711,7 @@ if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile']
{ {
// Redirect here // Redirect here
// This avoid sending mail twice if going out and then back to page // This avoid sending mail twice if going out and then back to page
Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$commande->id.'&mesg='.urlencode($mesg)); Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&mesg='.urlencode($mesg));
exit; exit;
} }
} }
@ -753,7 +736,7 @@ if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile']
{ {
$langs->load("other"); $langs->load("other");
$mesg='<div class="error">'.$langs->trans('ErrorMailRecipientIsEmpty').' !</div>'; $mesg='<div class="error">'.$langs->trans('ErrorMailRecipientIsEmpty').' !</div>';
$_GET["action"]='presend'; $action='presend';
dol_syslog('Recipient email is empty'); dol_syslog('Recipient email is empty');
} }
} }
@ -797,18 +780,16 @@ if ($id > 0 || ! empty($ref))
{ {
//if ($mesg) print $mesg.'<br>'; //if ($mesg) print $mesg.'<br>';
$commande = new CommandeFournisseur($db); $result=$object->fetch($id,$ref);
$result=$commande->fetch($id,$ref);
if ($result >= 0) if ($result >= 0)
{ {
$soc = new Societe($db); $soc = new Societe($db);
$soc->fetch($commande->socid); $soc->fetch($object->socid);
$author = new User($db); $author = new User($db);
$author->fetch($commande->user_author_id); $author->fetch($object->user_author_id);
$head = ordersupplier_prepare_head($commande); $head = ordersupplier_prepare_head($object);
$title=$langs->trans("SupplierOrder"); $title=$langs->trans("SupplierOrder");
dol_fiche_head($head, 'card', $title, 0, 'order'); dol_fiche_head($head, 'card', $title, 0, 'order');
@ -827,11 +808,11 @@ if ($id > 0 || ! empty($ref))
*/ */
if ($action == 'valid') if ($action == 'valid')
{ {
$commande->date_commande=gmmktime(); $object->date_commande=gmmktime();
// We check if number is temporary number // We check if number is temporary number
if (preg_match('/^[\(]?PROV/i',$commande->ref)) $newref = $commande->getNextNumRef($soc); if (preg_match('/^[\(]?PROV/i',$object->ref)) $newref = $object->getNextNumRef($soc);
else $newref = $commande->ref; else $newref = $object->ref;
$text=$langs->trans('ConfirmValidateOrder',$newref); $text=$langs->trans('ConfirmValidateOrder',$newref);
if ($conf->notification->enabled) if ($conf->notification->enabled)
@ -839,7 +820,7 @@ if ($id > 0 || ! empty($ref))
require_once(DOL_DOCUMENT_ROOT ."/core/class/notify.class.php"); require_once(DOL_DOCUMENT_ROOT ."/core/class/notify.class.php");
$notify=new Notify($db); $notify=new Notify($db);
$text.='<br>'; $text.='<br>';
$text.=$notify->confirmMessage(3,$commande->socid); $text.=$notify->confirmMessage(3,$object->socid);
} }
$ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('ValidateOrder'), $text, 'confirm_valid', '', 0, 1); $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('ValidateOrder'), $text, 'confirm_valid', '', 0, 1);
@ -850,7 +831,7 @@ if ($id > 0 || ! empty($ref))
*/ */
if ($action == 'approve') if ($action == 'approve')
{ {
$ret=$html->form_confirm("fiche.php?id=$commande->id",$langs->trans("ApproveThisOrder"),$langs->trans("ConfirmApproveThisOrder",$commande->ref),"confirm_approve", '', 1, 1); $ret=$html->form_confirm("fiche.php?id=$object->id",$langs->trans("ApproveThisOrder"),$langs->trans("ConfirmApproveThisOrder",$object->ref),"confirm_approve", '', 1, 1);
if ($ret == 'html') print '<br>'; if ($ret == 'html') print '<br>';
} }
/* /*
@ -858,7 +839,7 @@ if ($id > 0 || ! empty($ref))
*/ */
if ($action == 'refuse') if ($action == 'refuse')
{ {
$ret=$html->form_confirm("fiche.php?id=$commande->id",$langs->trans("DenyingThisOrder"),$langs->trans("ConfirmDenyingThisOrder",$commande->ref),"confirm_refuse", '', 0, 1); $ret=$html->form_confirm("fiche.php?id=$object->id",$langs->trans("DenyingThisOrder"),$langs->trans("ConfirmDenyingThisOrder",$object->ref),"confirm_refuse", '', 0, 1);
if ($ret == 'html') print '<br>'; if ($ret == 'html') print '<br>';
} }
/* /*
@ -866,17 +847,17 @@ if ($id > 0 || ! empty($ref))
*/ */
if ($action == 'cancel') if ($action == 'cancel')
{ {
$ret=$html->form_confirm("fiche.php?id=$commande->id",$langs->trans("Cancel"),$langs->trans("ConfirmCancelThisOrder",$commande->ref),"confirm_cancel", '', 0, 1); $ret=$html->form_confirm("fiche.php?id=$object->id",$langs->trans("Cancel"),$langs->trans("ConfirmCancelThisOrder",$object->ref),"confirm_cancel", '', 0, 1);
if ($ret == 'html') print '<br>'; if ($ret == 'html') print '<br>';
} }
/* /*
* Confirmation de l'envoi de la commande * Confirmation de l'envoi de la commande
*/ */
if ($_GET["action"] == 'commande') if ($action == 'commande')
{ {
$date_com = dol_mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]); $date_com = dol_mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]);
$ret=$html->form_confirm("fiche.php?id=".$commande->id."&datecommande=".$date_com."&methode=".$_POST["methodecommande"]."&comment=".urlencode($_POST["comment"]), $ret=$html->form_confirm("fiche.php?id=".$object->id."&datecommande=".$date_com."&methode=".$_POST["methodecommande"]."&comment=".urlencode($_POST["comment"]),
$langs->trans("MakeOrder"),$langs->trans("ConfirmMakeOrder",dol_print_date($date_com,'day')),"confirm_commande",'',0,2); $langs->trans("MakeOrder"),$langs->trans("ConfirmMakeOrder",dol_print_date($date_com,'day')),"confirm_commande",'',0,2);
if ($ret == 'html') print '<br>'; if ($ret == 'html') print '<br>';
} }
@ -886,7 +867,7 @@ if ($id > 0 || ! empty($ref))
*/ */
if ($action == 'delete_product_line') if ($action == 'delete_product_line')
{ {
$ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$commande->id.'&lineid='.$_GET["lineid"], $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteproductline','',0,2); $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$_GET["lineid"], $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteproductline','',0,2);
if ($ret == 'html') print '<br>'; if ($ret == 'html') print '<br>';
} }
@ -908,13 +889,13 @@ if ($id > 0 || ! empty($ref))
// Ref // Ref
print '<tr><td width="20%">'.$langs->trans("Ref").'</td>'; print '<tr><td width="20%">'.$langs->trans("Ref").'</td>';
print '<td colspan="2">'; print '<td colspan="2">';
print $html->showrefnav($commande,'ref','',1,'ref','ref'); print $html->showrefnav($object,'ref','',1,'ref','ref');
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
// Ref supplier // Ref supplier
/* print '<tr><td>'.$langs->trans("RefSupplier")."</td>"; /* print '<tr><td>'.$langs->trans("RefSupplier")."</td>";
print '<td colspan="2">'.$commande->ref_supplier.'</td>'; print '<td colspan="2">'.$object->ref_supplier.'</td>';
print '</tr>'; print '</tr>';
*/ */
// Fournisseur // Fournisseur
@ -926,22 +907,22 @@ if ($id > 0 || ! empty($ref))
print '<tr>'; print '<tr>';
print '<td>'.$langs->trans("Status").'</td>'; print '<td>'.$langs->trans("Status").'</td>';
print '<td colspan="2">'; print '<td colspan="2">';
print $commande->getLibStatut(4); print $object->getLibStatut(4);
print "</td></tr>"; print "</td></tr>";
// Date // Date
if ($commande->methode_commande_id > 0) if ($object->methode_commande_id > 0)
{ {
print '<tr><td>'.$langs->trans("Date").'</td><td colspan="2">'; print '<tr><td>'.$langs->trans("Date").'</td><td colspan="2">';
if ($commande->date_commande) if ($object->date_commande)
{ {
print dol_print_date($commande->date_commande,"dayhourtext")."\n"; print dol_print_date($object->date_commande,"dayhourtext")."\n";
} }
print "</td></tr>"; print "</td></tr>";
if ($commande->methode_commande) if ($object->methode_commande)
{ {
print '<tr><td>'.$langs->trans("Method").'</td><td colspan="2">'.$commande->methode_commande.'</td></tr>'; print '<tr><td>'.$langs->trans("Method").'</td><td colspan="2">'.$object->methode_commande.'</td></tr>';
} }
} }
@ -957,16 +938,16 @@ if ($id > 0 || ! empty($ref))
print '<table width="100%" class="nobordernopadding"><tr><td nowrap>'; print '<table width="100%" class="nobordernopadding"><tr><td nowrap>';
print $langs->trans('PaymentConditions'); print $langs->trans('PaymentConditions');
print '<td>'; print '<td>';
if ($action != 'editconditions') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editconditions&amp;id='.$commande->id.'">'.img_edit($langs->trans('SetConditions'),1).'</a></td>'; if ($action != 'editconditions') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editconditions&amp;id='.$object->id.'">'.img_edit($langs->trans('SetConditions'),1).'</a></td>';
print '</tr></table>'; print '</tr></table>';
print '</td><td colspan="2">'; print '</td><td colspan="2">';
if ($action == 'editconditions') if ($action == 'editconditions')
{ {
$html->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$commande->id, $commande->cond_reglement_id,'cond_reglement_id'); $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id,'cond_reglement_id');
} }
else else
{ {
$html->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$commande->id, $commande->cond_reglement_id,'none'); $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id,'none');
} }
print "</td>"; print "</td>";
print '</tr>'; print '</tr>';
@ -978,16 +959,16 @@ if ($id > 0 || ! empty($ref))
print '<table width="100%" class="nobordernopadding"><tr><td nowrap>'; print '<table width="100%" class="nobordernopadding"><tr><td nowrap>';
print $langs->trans('PaymentMode'); print $langs->trans('PaymentMode');
print '</td>'; print '</td>';
if ($action != 'editmode') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editmode&amp;id='.$commande->id.'">'.img_edit($langs->trans('SetMode'),1).'</a></td>'; if ($action != 'editmode') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editmode&amp;id='.$object->id.'">'.img_edit($langs->trans('SetMode'),1).'</a></td>';
print '</tr></table>'; print '</tr></table>';
print '</td><td colspan="2">'; print '</td><td colspan="2">';
if ($action == 'editmode') if ($action == 'editmode')
{ {
$html->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->mode_reglement_id,'mode_reglement_id'); $html->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->mode_reglement_id,'mode_reglement_id');
} }
else else
{ {
$html->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->mode_reglement_id,'none'); $html->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->mode_reglement_id,'none');
} }
print '</td></tr>'; print '</td></tr>';
@ -999,17 +980,17 @@ if ($id > 0 || ! empty($ref))
print '<table class="nobordernopadding" width="100%"><tr><td>'; print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('Project'); print $langs->trans('Project');
print '</td>'; print '</td>';
if ($action != 'classer') print '<td align="right"><a href="'.$_SERVER['PHP_SELF'].'?action=classer&amp;id='.$commande->id.'">'.img_edit($langs->trans('SetProject')).'</a></td>'; if ($action != 'classer') print '<td align="right"><a href="'.$_SERVER['PHP_SELF'].'?action=classer&amp;id='.$object->id.'">'.img_edit($langs->trans('SetProject')).'</a></td>';
print '</tr></table>'; print '</tr></table>';
print '</td><td colspan="2">'; print '</td><td colspan="2">';
//print "$commande->id, $commande->socid, $commande->fk_project"; //print "$object->id, $object->socid, $object->fk_project";
if ($action == 'classer') if ($action == 'classer')
{ {
$html->form_project($_SERVER['PHP_SELF'].'?id='.$commande->id, $commande->socid, $commande->fk_project, 'projectid'); $html->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'projectid');
} }
else else
{ {
$html->form_project($_SERVER['PHP_SELF'].'?id='.$commande->id, $commande->socid, $commande->fk_project, 'none'); $html->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none');
} }
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
@ -1017,10 +998,10 @@ if ($id > 0 || ! empty($ref))
// Ligne de 3 colonnes // Ligne de 3 colonnes
print '<tr><td>'.$langs->trans("AmountHT").'</td>'; print '<tr><td>'.$langs->trans("AmountHT").'</td>';
print '<td align="right"><b>'.price($commande->total_ht).'</b></td>'; print '<td align="right"><b>'.price($object->total_ht).'</b></td>';
print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>'; print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
print '<tr><td>'.$langs->trans("AmountVAT").'</td><td align="right">'.price($commande->total_tva).'</td>'; print '<tr><td>'.$langs->trans("AmountVAT").'</td><td align="right">'.price($object->total_tva).'</td>';
print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>'; print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
// Amount Local Taxes // Amount Local Taxes
@ -1029,17 +1010,17 @@ if ($id > 0 || ! empty($ref))
if ($mysoc->localtax1_assuj=="1") //Localtax1 RE if ($mysoc->localtax1_assuj=="1") //Localtax1 RE
{ {
print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->pays_code).'</td>'; print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->pays_code).'</td>';
print '<td align="right">'.price($commande->total_localtax1).'</td>'; print '<td align="right">'.price($object->total_localtax1).'</td>';
print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>'; print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
} }
if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF
{ {
print '<tr><td>'.$langs->transcountry("AmountLT2",$mysoc->pays_code).'</td>'; print '<tr><td>'.$langs->transcountry("AmountLT2",$mysoc->pays_code).'</td>';
print '<td align="right">'.price($commande->total_localtax2).'</td>'; print '<td align="right">'.price($object->total_localtax2).'</td>';
print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>'; print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
} }
} }
print '<tr><td>'.$langs->trans("AmountTTC").'</td><td align="right">'.price($commande->total_ttc).'</td>'; print '<tr><td>'.$langs->trans("AmountTTC").'</td><td align="right">'.price($object->total_ttc).'</td>';
print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>'; print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
print "</table>"; print "</table>";
@ -1052,7 +1033,7 @@ if ($id > 0 || ! empty($ref))
*/ */
print '<table class="noborder" width="100%">'; print '<table class="noborder" width="100%">';
$num = sizeof($commande->lines); $num = sizeof($object->lines);
$i = 0; $total = 0; $i = 0; $total = 0;
if ($num) if ($num)
@ -1070,7 +1051,7 @@ if ($id > 0 || ! empty($ref))
$var=true; $var=true;
while ($i < $num) while ($i < $num)
{ {
$line = $commande->lines[$i]; $line = $object->lines[$i];
$var=!$var; $var=!$var;
// Show product and description // Show product and description
@ -1134,14 +1115,14 @@ if ($id > 0 || ! empty($ref))
} }
print '<td align="right" nowrap="nowrap">'.price($line->total_ht).'</td>'; print '<td align="right" nowrap="nowrap">'.price($line->total_ht).'</td>';
if ($commande->statut == 0 && $user->rights->fournisseur->commande->creer) if ($object->statut == 0 && $user->rights->fournisseur->commande->creer)
{ {
print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?id='.$commande->id.'&amp;action=editline&amp;rowid='.$line->id.'#'.$line->id.'">'; print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=editline&amp;rowid='.$line->id.'#'.$line->id.'">';
print img_edit(); print img_edit();
print '</a></td>'; print '</a></td>';
$actiondelete='delete_product_line'; $actiondelete='delete_product_line';
print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?id='.$commande->id.'&amp;action='.$actiondelete.'&amp;lineid='.$line->id.'">'; print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action='.$actiondelete.'&amp;lineid='.$line->id.'">';
print img_delete(); print img_delete();
print '</a></td>'; print '</a></td>';
} }
@ -1153,13 +1134,13 @@ if ($id > 0 || ! empty($ref))
} }
// Ligne en mode update // Ligne en mode update
if ($_GET["action"] == 'editline' && $user->rights->fournisseur->commande->creer && ($_GET["rowid"] == $line->id)) if ($action == 'editline' && $user->rights->fournisseur->commande->creer && ($_GET["rowid"] == $line->id))
{ {
print "\n"; print "\n";
print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$commande->id.'&amp;etat=1&amp;ligne_id='.$line->id.'" method="post">'; print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;etat=1&amp;ligne_id='.$line->id.'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="updateligne">'; print '<input type="hidden" name="action" value="updateligne">';
print '<input type="hidden" name="id" value="'.$commande->id.'">'; print '<input type="hidden" name="id" value="'.$object->id.'">';
print '<input type="hidden" name="elrowid" value="'.$_GET['rowid'].'">'; print '<input type="hidden" name="elrowid" value="'.$_GET['rowid'].'">';
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
print '<td>'; print '<td>';
@ -1208,7 +1189,7 @@ if ($id > 0 || ! empty($ref))
/* /*
* Form to add new line * Form to add new line
*/ */
if ($commande->statut == 0 && $user->rights->fournisseur->commande->creer && $_GET["action"] <> 'editline') if ($object->statut == 0 && $user->rights->fournisseur->commande->creer && $action <> 'editline')
{ {
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td>'; print '<td>';
@ -1222,10 +1203,10 @@ if ($id > 0 || ! empty($ref))
print '</tr>'; print '</tr>';
// Add free products/services form // Add free products/services form
print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$commande->id.'#add" method="post">'; print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'#add" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="addline">'; print '<input type="hidden" name="action" value="addline">';
print '<input type="hidden" name="id" value="'.$commande->id.'">'; print '<input type="hidden" name="id" value="'.$object->id.'">';
$var=true; $var=true;
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
@ -1278,15 +1259,15 @@ if ($id > 0 || ! empty($ref))
print '<td colspan="4">&nbsp;</td>'; print '<td colspan="4">&nbsp;</td>';
print '</tr>'; print '</tr>';
print '<form id="addpredefinedproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$commande->id.'#add" method="post">'; print '<form id="addpredefinedproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'#add" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="addline">'; print '<input type="hidden" name="action" value="addline">';
print '<input type="hidden" name="id" value="'.$commande->id.'">'; print '<input type="hidden" name="id" value="'.$object->id.'">';
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
print '<td colspan="3">'; print '<td colspan="3">';
$html->select_produits_fournisseurs($commande->fourn_id,'','idprodfournprice','',$filtre); $html->select_produits_fournisseurs($object->fourn_id,'','idprodfournprice','',$filtre);
if (! $conf->global->PRODUIT_USE_SEARCH_TO_SELECT) print '<br>'; if (! $conf->global->PRODUIT_USE_SEARCH_TO_SELECT) print '<br>';
@ -1321,22 +1302,22 @@ if ($id > 0 || ! empty($ref))
print '<div class="tabsAction">'; print '<div class="tabsAction">';
// Validate // Validate
if ($commande->statut == 0 && $num > 0) if ($object->statut == 0 && $num > 0)
{ {
if ($user->rights->fournisseur->commande->valider) if ($user->rights->fournisseur->commande->valider)
{ {
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$commande->id.'&amp;action=valid"'; print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=valid"';
print '>'.$langs->trans('Validate').'</a>'; print '>'.$langs->trans('Validate').'</a>';
} }
} }
// Approve // Approve
if ($commande->statut == 1) if ($object->statut == 1)
{ {
if ($user->rights->fournisseur->commande->approuver) if ($user->rights->fournisseur->commande->approuver)
{ {
print '<a class="butAction" href="fiche.php?id='.$commande->id.'&amp;action=approve">'.$langs->trans("ApproveOrder").'</a>'; print '<a class="butAction" href="fiche.php?id='.$object->id.'&amp;action=approve">'.$langs->trans("ApproveOrder").'</a>';
print '<a class="butAction" href="fiche.php?id='.$commande->id.'&amp;action=refuse">'.$langs->trans("RefuseOrder").'</a>'; print '<a class="butAction" href="fiche.php?id='.$object->id.'&amp;action=refuse">'.$langs->trans("RefuseOrder").'</a>';
} }
else else
{ {
@ -1346,34 +1327,34 @@ if ($id > 0 || ! empty($ref))
} }
// Send // Send
if (in_array($commande->statut,array(2,3,4,5))) if (in_array($object->statut,array(2,3,4,5)))
{ {
if ($user->rights->fournisseur->commande->commander) if ($user->rights->fournisseur->commande->commander)
{ {
$comref = dol_sanitizeFileName($commande->ref); $comref = dol_sanitizeFileName($object->ref);
$file = $conf->fournisseur->commande->dir_output . '/'.$comref.'/'.$comref.'.pdf'; $file = $conf->fournisseur->commande->dir_output . '/'.$comref.'/'.$comref.'.pdf';
if (file_exists($file)) if (file_exists($file))
{ {
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$commande->id.'&amp;action=presend&amp;mode=init">'.$langs->trans('SendByMail').'</a>'; print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=presend&amp;mode=init">'.$langs->trans('SendByMail').'</a>';
} }
} }
} }
// Reopen // Reopen
if ($commande->statut == 5 || $commande->statut == 6 || $commande->statut == 7 || $commande->statut == 9) if ($object->statut == 5 || $object->statut == 6 || $object->statut == 7 || $object->statut == 9)
{ {
if ($user->rights->fournisseur->commande->commander) if ($user->rights->fournisseur->commande->commander)
{ {
print '<a class="butAction" href="fiche.php?id='.$commande->id.'&amp;action=reopen">'.$langs->trans("ReOpen").'</a>'; print '<a class="butAction" href="fiche.php?id='.$object->id.'&amp;action=reopen">'.$langs->trans("ReOpen").'</a>';
} }
} }
// Create bill // Create bill
if ($conf->fournisseur->enabled && $commande->statut >= 2) // 2 means accepted if ($conf->fournisseur->enabled && $object->statut >= 2) // 2 means accepted
{ {
if ($user->rights->fournisseur->facture->creer) if ($user->rights->fournisseur->facture->creer)
{ {
print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/facture/fiche.php?action=create&amp;origin='.$commande->element.'&amp;originid='.$commande->id.'&amp;socid='.$commande->socid.'">'.$langs->trans("CreateBill").'</a>'; print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/facture/fiche.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid.'">'.$langs->trans("CreateBill").'</a>';
} }
//if ($user->rights->fournisseur->commande->creer && $object->statut > 2) //if ($user->rights->fournisseur->commande->creer && $object->statut > 2)
@ -1383,18 +1364,18 @@ if ($id > 0 || ! empty($ref))
} }
// Cancel // Cancel
if ($commande->statut == 2) if ($object->statut == 2)
{ {
if ($user->rights->fournisseur->commande->commander) if ($user->rights->fournisseur->commande->commander)
{ {
print '<a class="butActionDelete" href="fiche.php?id='.$commande->id.'&amp;action=cancel">'.$langs->trans("CancelOrder").'</a>'; print '<a class="butActionDelete" href="fiche.php?id='.$object->id.'&amp;action=cancel">'.$langs->trans("CancelOrder").'</a>';
} }
} }
// Delete // Delete
if ($user->rights->fournisseur->commande->supprimer) if ($user->rights->fournisseur->commande->supprimer)
{ {
print '<a class="butActionDelete" href="fiche.php?id='.$commande->id.'&amp;action=delete">'.$langs->trans("Delete").'</a>'; print '<a class="butActionDelete" href="fiche.php?id='.$object->id.'&amp;action=delete">'.$langs->trans("Delete").'</a>';
} }
@ -1408,17 +1389,17 @@ if ($id > 0 || ! empty($ref))
/* /*
* Documents generes * Documents generes
*/ */
$comfournref = dol_sanitizeFileName($commande->ref); $comfournref = dol_sanitizeFileName($object->ref);
$file = $conf->fournisseur->dir_output . '/commande/' . $comfournref . '/' . $comfournref . '.pdf'; $file = $conf->fournisseur->dir_output . '/commande/' . $comfournref . '/' . $comfournref . '.pdf';
$relativepath = $comfournref.'/'.$comfournref.'.pdf'; $relativepath = $comfournref.'/'.$comfournref.'.pdf';
$filedir = $conf->fournisseur->dir_output . '/commande/' . $comfournref; $filedir = $conf->fournisseur->dir_output . '/commande/' . $comfournref;
$urlsource=$_SERVER["PHP_SELF"]."?id=".$commande->id; $urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id;
$genallowed=$user->rights->fournisseur->commande->creer; $genallowed=$user->rights->fournisseur->commande->creer;
$delallowed=$user->rights->fournisseur->commande->supprimer; $delallowed=$user->rights->fournisseur->commande->supprimer;
$somethingshown=$formfile->show_documents('commande_fournisseur',$comfournref,$filedir,$urlsource,$genallowed,$delallowed,$commande->modelpdf); $somethingshown=$formfile->show_documents('commande_fournisseur',$comfournref,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf);
$object=$commande; $object=$object;
/* /*
* Linked object block * Linked object block
@ -1428,13 +1409,13 @@ if ($id > 0 || ! empty($ref))
print '</td><td valign="top" width="50%">'; print '</td><td valign="top" width="50%">';
if ( $user->rights->fournisseur->commande->commander && $commande->statut == 2) if ( $user->rights->fournisseur->commande->commander && $object->statut == 2)
{ {
/** /**
* Commander (action=commande) * Commander (action=commande)
*/ */
print '<br>'; print '<br>';
print '<form name="commande" action="fiche.php?id='.$commande->id.'&amp;action=commande" method="post">'; print '<form name="commande" action="fiche.php?id='.$object->id.'&amp;action=commande" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="commande">'; print '<input type="hidden" name="action" value="commande">';
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
@ -1454,13 +1435,13 @@ if ($id > 0 || ! empty($ref))
print '</form>'; print '</form>';
} }
if ( $user->rights->fournisseur->commande->receptionner && ($commande->statut == 3 ||$commande->statut == 4 )) if ( $user->rights->fournisseur->commande->receptionner && ($object->statut == 3 || $object->statut == 4 ))
{ {
/** /**
* Receptionner (action=livraison) * Receptionner (action=livraison)
*/ */
print '<br>'; print '<br>';
print '<form action="fiche.php?id='.$commande->id.'" method="post">'; print '<form action="fiche.php?id='.$object->id.'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="livraison">'; print '<input type="hidden" name="action" value="livraison">';
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
@ -1491,7 +1472,7 @@ if ($id > 0 || ! empty($ref))
print '<br>'; print '<br>';
include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'); include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php');
$formactions=new FormActions($db); $formactions=new FormActions($db);
$somethingshown=$formactions->showactions($commande,'order_supplier',$socid); $somethingshown=$formactions->showactions($object,'order_supplier',$socid);
*/ */
print '</td></tr></table>'; print '</td></tr></table>';
@ -1505,7 +1486,7 @@ if ($id > 0 || ! empty($ref))
*/ */
if ($action == 'presend') if ($action == 'presend')
{ {
$ref = dol_sanitizeFileName($commande->ref); $ref = dol_sanitizeFileName($object->ref);
$file = $conf->fournisseur->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf'; $file = $conf->fournisseur->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf';
print '<br>'; print '<br>';
@ -1531,12 +1512,12 @@ if ($id > 0 || ! empty($ref))
$formmail->withdeliveryreceipt=1; $formmail->withdeliveryreceipt=1;
$formmail->withcancel=1; $formmail->withcancel=1;
// Tableau des substitutions // Tableau des substitutions
$formmail->substit['__ORDERREF__']=$commande->ref; $formmail->substit['__ORDERREF__']=$object->ref;
// Tableau des parametres complementaires // Tableau des parametres complementaires
$formmail->param['action']='send'; $formmail->param['action']='send';
$formmail->param['models']='order_supplier_send'; $formmail->param['models']='order_supplier_send';
$formmail->param['orderid']=$commande->id; $formmail->param['orderid']=$object->id;
$formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$commande->id; $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id;
// Init list of files // Init list of files
if (! empty($_REQUEST["mode"]) && $_REQUEST["mode"]=='init') if (! empty($_REQUEST["mode"]) && $_REQUEST["mode"]=='init')