diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php
index ba1a8f0e000..d37989d9935 100644
--- a/htdocs/commande/fiche.php
+++ b/htdocs/commande/fiche.php
@@ -24,10 +24,10 @@
*/
/**
- \file htdocs/commande/fiche.php
- \ingroup commande
- \brief Fiche commande client
- \version $Revision$
+ \file htdocs/commande/fiche.php
+ \ingroup commande
+ \brief Fiche commande client
+ \version $Revision$
*/
require('./pre.inc.php');
@@ -57,612 +57,615 @@ if (!$user->rights->commande->lire) accessforbidden();
$socid=0;
if ($user->societe_id > 0)
{
- $action = '';
- $socid = $user->societe_id;
+ $action = '';
+ $socid = $user->societe_id;
}
// Récupération de l'id de projet
$projetid = 0;
if ($_GET["projetid"])
{
- $projetid = $_GET["projetid"];
+ $projetid = $_GET["projetid"];
}
/*
- * Actions
- */
+* Actions
+*/
// Categorisation dans projet
if ($_POST['action'] == 'classin' && $user->rights->commande->creer)
{
- $commande = new Commande($db);
- $commande->fetch($_GET['id']);
- $commande->classin($_POST['projetid']);
+ $commande = new Commande($db);
+ $commande->fetch($_GET['id']);
+ $commande->classin($_POST['projetid']);
}
// Ajout commande
if ($_POST['action'] == 'add' && $user->rights->commande->creer)
{
- $datecommande='';
- $datecommande = @mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
- $datelivraison = @mktime(12, 0, 0, $_POST['liv_month'],$_POST['liv_day'],$_POST['liv_year']);
+ $datecommande='';
+ $datecommande = @mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
+ $datelivraison = @mktime(12, 0, 0, $_POST['liv_month'],$_POST['liv_day'],$_POST['liv_year']);
- $commande = new Commande($db);
- $commande->socid=$_POST['socid'];
- $commande->fetch_client();
+ $commande = new Commande($db);
+ $commande->socid=$_POST['socid'];
+ $commande->fetch_client();
- $db->begin();
+ $db->begin();
- $commande->date_commande = $datecommande;
- $commande->note = $_POST['note'];
- $commande->source = $_POST['source_id'];
- $commande->projetid = $_POST['projetid'];
- //$commande->remise_absolue = $_POST['remise_absolue']; //la remise était appliquée sur les lignes et sur le total
- //$commande->remise_percent = $_POST['remise_percent'];
- $commande->ref_client = $_POST['ref_client'];
- $commande->modelpdf = $_POST['model'];
- $commande->cond_reglement_id = $_POST['cond_reglement_id'];
- $commande->mode_reglement_id = $_POST['mode_reglement_id'];
- $commande->date_livraison = $datelivraison;
- $commande->adresse_livraison_id = $_POST['adresse_livraison_id'];
- $commande->contactid = $_POST['contactidp'];
+ $commande->date_commande = $datecommande;
+ $commande->note = $_POST['note'];
+ $commande->source = $_POST['source_id'];
+ $commande->projetid = $_POST['projetid'];
+ //$commande->remise_absolue = $_POST['remise_absolue']; //la remise était appliquée sur les lignes et sur le total
+ //$commande->remise_percent = $_POST['remise_percent'];
+ $commande->ref_client = $_POST['ref_client'];
+ $commande->modelpdf = $_POST['model'];
+ $commande->cond_reglement_id = $_POST['cond_reglement_id'];
+ $commande->mode_reglement_id = $_POST['mode_reglement_id'];
+ $commande->date_livraison = $datelivraison;
+ $commande->adresse_livraison_id = $_POST['adresse_livraison_id'];
+ $commande->contactid = $_POST['contactidp'];
- $commande->add_product($_POST['idprod1'],$_POST['qty1'],$_POST['remise_percent1']);
- $commande->add_product($_POST['idprod2'],$_POST['qty2'],$_POST['remise_percent2']);
- $commande->add_product($_POST['idprod3'],$_POST['qty3'],$_POST['remise_percent3']);
- $commande->add_product($_POST['idprod4'],$_POST['qty4'],$_POST['remise_percent4']);
- $commande->add_product($_POST['idprod5'],$_POST['qty5'],$_POST['remise_percent5']);
- $commande->add_product($_POST['idprod6'],$_POST['qty6'],$_POST['remise_percent6']);
- $commande->add_product($_POST['idprod7'],$_POST['qty7'],$_POST['remise_percent7']);
- $commande->add_product($_POST['idprod8'],$_POST['qty8'],$_POST['remise_percent8']);
+ $commande->add_product($_POST['idprod1'],$_POST['qty1'],$_POST['remise_percent1']);
+ $commande->add_product($_POST['idprod2'],$_POST['qty2'],$_POST['remise_percent2']);
+ $commande->add_product($_POST['idprod3'],$_POST['qty3'],$_POST['remise_percent3']);
+ $commande->add_product($_POST['idprod4'],$_POST['qty4'],$_POST['remise_percent4']);
+ $commande->add_product($_POST['idprod5'],$_POST['qty5'],$_POST['remise_percent5']);
+ $commande->add_product($_POST['idprod6'],$_POST['qty6'],$_POST['remise_percent6']);
+ $commande->add_product($_POST['idprod7'],$_POST['qty7'],$_POST['remise_percent7']);
+ $commande->add_product($_POST['idprod8'],$_POST['qty8'],$_POST['remise_percent8']);
- $commande_id = $commande->create($user);
+ $commande_id = $commande->create($user);
- if ($commande_id > 0)
- {
- // Insertion contact par defaut si défini
- if ($_POST["contactidp"])
+ if ($commande_id > 0)
{
- $result=$commande->add_contact($_POST["contactidp"],'CUSTOMER','external');
-
- if ($result > 0)
- {
- $error=0;
- }
- else
- {
- $mesg = '
'.$langs->trans("ErrorFailedToAddContact").'
';
- $error=1;
- }
- }
-
- $_GET['id'] = $commande->id;
- $action = '';
- }
+ // Insertion contact par defaut si défini
+ if ($_POST["contactidp"])
+ {
+ $result=$commande->add_contact($_POST["contactidp"],'CUSTOMER','external');
- // Fin création facture, on l'affiche
- if ($commande_id > 0 && ! $error)
- {
- $db->commit();
- }
- else
- {
- $db->rollback();
- $_GET["action"]='create';
- $_GET['socid']=$_POST['socid'];
- if (! $mesg) $mesg=''.$commande->error.'
';
- }
+ if ($result > 0)
+ {
+ $error=0;
+ }
+ else
+ {
+ $mesg = ''.$langs->trans("ErrorFailedToAddContact").'
';
+ $error=1;
+ }
+ }
+
+ $_GET['id'] = $commande->id;
+ $action = '';
+ }
+
+ // Fin création facture, on l'affiche
+ if ($commande_id > 0 && ! $error)
+ {
+ $db->commit();
+ }
+ else
+ {
+ $db->rollback();
+ $_GET["action"]='create';
+ $_GET['socid']=$_POST['socid'];
+ if (! $mesg) $mesg=''.$commande->error.'
';
+ }
}
// Positionne ref commande client
if ($_POST['action'] == 'set_ref_client' && $user->rights->commande->creer)
{
- $commande = new Commande($db);
- $commande->fetch($_GET['id']);
- $commande->set_ref_client($user, $_POST['ref_client']);
+ $commande = new Commande($db);
+ $commande->fetch($_GET['id']);
+ $commande->set_ref_client($user, $_POST['ref_client']);
}
if ($_POST['action'] == 'setremise' && $user->rights->commande->creer)
{
- $commande = new Commande($db);
- $commande->fetch($_GET['id']);
- $commande->set_remise($user, $_POST['remise']);
+ $commande = new Commande($db);
+ $commande->fetch($_GET['id']);
+ $commande->set_remise($user, $_POST['remise']);
}
if ($_POST['action'] == "setabsolutediscount" && $user->rights->propale->creer)
{
- if ($_POST["remise_id"])
- {
- $com = new Commande($db);
- $com->id=$_GET['id'];
- $ret=$com->fetch($_GET['id']);
- if ($ret > 0)
+ if ($_POST["remise_id"])
{
- $com->insert_discount($_POST["remise_id"]);
+ $com = new Commande($db);
+ $com->id=$_GET['id'];
+ $ret=$com->fetch($_GET['id']);
+ if ($ret > 0)
+ {
+ $com->insert_discount($_POST["remise_id"]);
+ }
+ else
+ {
+ dolibarr_print_error($db,$com->error);
+ }
}
- else
- {
- dolibarr_print_error($db,$com->error);
- }
- }
}
if ($_POST['action'] == 'setdate_livraison' && $user->rights->commande->creer)
{
- $datelivraison=@mktime(0, 0, 0, $_POST['liv_month'], $_POST['liv_day'], $_POST['liv_year']);
- $commande = new Commande($db);
- $commande->fetch($_GET['id']);
- $result=$commande->set_date_livraison($user,$datelivraison);
- if ($result < 0)
- {
- $mesg=''.$commande->error.'
';
- }
+ $datelivraison=@mktime(0, 0, 0, $_POST['liv_month'], $_POST['liv_day'], $_POST['liv_year']);
+ $commande = new Commande($db);
+ $commande->fetch($_GET['id']);
+ $result=$commande->set_date_livraison($user,$datelivraison);
+ if ($result < 0)
+ {
+ $mesg=''.$commande->error.'
';
+ }
}
if ($_POST['action'] == 'setdeliveryadress' && $user->rights->commande->creer)
{
- $commande = new Commande($db);
- $commande->fetch($_GET['id']);
- $commande->set_adresse_livraison($user,$_POST['adresse_livraison_id']);
+ $commande = new Commande($db);
+ $commande->fetch($_GET['id']);
+ $commande->set_adresse_livraison($user,$_POST['adresse_livraison_id']);
}
if ($_POST['action'] == 'setmode' && $user->rights->commande->creer)
{
- $commande = new Commande($db);
- $commande->fetch($_GET['id']);
- $result=$commande->mode_reglement($_POST['mode_reglement_id']);
- if ($result < 0) dolibarr_print_error($db,$commande->error);
+ $commande = new Commande($db);
+ $commande->fetch($_GET['id']);
+ $result=$commande->mode_reglement($_POST['mode_reglement_id']);
+ if ($result < 0) dolibarr_print_error($db,$commande->error);
}
if ($_POST['action'] == 'setconditions' && $user->rights->commande->creer)
{
- $commande = new Commande($db);
- $commande->fetch($_GET['id']);
- $result=$commande->cond_reglement($_POST['cond_reglement_id']);
- if ($result < 0) dolibarr_print_error($db,$commande->error);
+ $commande = new Commande($db);
+ $commande->fetch($_GET['id']);
+ $result=$commande->cond_reglement($_POST['cond_reglement_id']);
+ if ($result < 0) dolibarr_print_error($db,$commande->error);
}
if ($_REQUEST['action'] == 'setremisepercent' && $user->rights->facture->creer)
{
- $commande = new Commande($db);
- $commande->fetch($_REQUEST['id']);
- $result = $commande->set_remise($user, $_POST['remise_percent']);
- $_GET['id']=$_REQUEST['id'];
+ $commande = new Commande($db);
+ $commande->fetch($_REQUEST['id']);
+ $result = $commande->set_remise($user, $_POST['remise_percent']);
+ $_GET['id']=$_REQUEST['id'];
}
if ($_REQUEST['action'] == 'setremiseabsolue' && $user->rights->facture->creer)
{
- $commande = new Commande($db);
- $commande->fetch($_REQUEST['id']);
- $result = $commande->set_remise_absolue($user, $_POST['remise_absolue']);
- $_GET['id']=$_REQUEST['id'];
+ $commande = new Commande($db);
+ $commande->fetch($_REQUEST['id']);
+ $result = $commande->set_remise_absolue($user, $_POST['remise_absolue']);
+ $_GET['id']=$_REQUEST['id'];
}
/*
- * Ajout d'une ligne produit dans la commande
- */
+* Ajout d'une ligne produit dans la commande
+*/
if ($_POST['action'] == 'addligne' && $user->rights->commande->creer)
{
- if ($_POST['qty'] && (($_POST['pu'] && $_POST['desc']) || $_POST['idprod']))
- {
- $commande = new Commande($db);
- $ret=$commande->fetch($_POST['id']);
- $soc = new Societe($db, $commande->socid);
- $soc->fetch($commande->socid);
-
- if ($ret < 0)
+ if ($_POST['qty'] && (($_POST['pu'] && $_POST['desc']) || $_POST['idprod']))
{
- dolibarr_print_error($db,$commande->error);
- exit;
+ $commande = new Commande($db);
+ $ret=$commande->fetch($_POST['id']);
+ $soc = new Societe($db, $commande->socid);
+ $soc->fetch($commande->socid);
+
+ if ($ret < 0)
+ {
+ dolibarr_print_error($db,$commande->error);
+ exit;
+ }
+
+ // Ecrase $pu par celui du produit
+ // Ecrase $desc par celui du produit
+ // Ecrase $txtva par celui du produit
+ if ($_POST['idprod'])
+ {
+ $prod = new Product($db, $_POST['idprod']);
+ $prod->fetch($_POST['idprod']);
+
+ $libelle = $prod->libelle;
+
+ // multiprix
+ if ($conf->global->PRODUIT_MULTIPRICES == 1)
+ {
+ $pu = $prod->multiprices[$soc->price_level];
+ }
+ else
+ {
+ $pu=$prod->price;
+ }
+
+ // La description de la ligne est celle saisie ou
+ // celle du produit si (non saisi + PRODUIT_CHANGE_PROD_DESC défini)
+ // \todo Ne faut-il pas rendre $conf->global->PRODUIT_CHANGE_PROD_DESC toujours a on
+ $desc=$_POST['np_desc'];
+ if (! $desc && $conf->global->PRODUIT_CHANGE_PROD_DESC)
+ {
+ $desc = $prod->description;
+ }
+
+ $tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx);
+ }
+ else
+ {
+ $pu=$_POST['pu'];
+ $tva_tx=$_POST['tva_tx'];
+ $desc=$_POST['desc'];
+ }
+
+ $commande->addline(
+ $_POST['id'],
+ $desc,
+ $pu,
+ $_POST['qty'],
+ $tva_tx,
+ $_POST['idprod'],
+ $_POST['remise_percent']
+ );
+
+ if ($_REQUEST['lang_id'])
+ {
+ $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
+ $outputlangs->setDefaultLang($_REQUEST['lang_id']);
+ }
+ commande_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs);
}
-
- // Ecrase $pu par celui du produit
- // Ecrase $desc par celui du produit
- // Ecrase $txtva par celui du produit
- if ($_POST['idprod'])
- {
- $prod = new Product($db, $_POST['idprod']);
- $prod->fetch($_POST['idprod']);
-
- $libelle = $prod->libelle;
-
- // multiprix
- if ($conf->global->PRODUIT_MULTIPRICES == 1)
- {
- $pu = $prod->multiprices[$soc->price_level];
- }
- else
- {
- $pu=$prod->price;
- }
-
- // La description de la ligne est celle saisie ou
- // celle du produit si (non saisi + PRODUIT_CHANGE_PROD_DESC défini)
- // \todo Ne faut-il pas rendre $conf->global->PRODUIT_CHANGE_PROD_DESC toujours a on
- $desc=$_POST['np_desc'];
- if (! $desc && $conf->global->PRODUIT_CHANGE_PROD_DESC)
- {
- $desc = $prod->description;
- }
-
- $tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx);
- }
- else
- {
- $pu=$_POST['pu'];
- $tva_tx=$_POST['tva_tx'];
- $desc=$_POST['desc'];
- }
-
- $commande->addline(
- $_POST['id'],
- $desc,
- $pu,
- $_POST['qty'],
- $tva_tx,
- $_POST['idprod'],
- $_POST['remise_percent']
- );
-
- if ($_REQUEST['lang_id'])
- {
- $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
- $outputlangs->setDefaultLang($_REQUEST['lang_id']);
- }
- commande_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs);
- }
}
/*
- * Mise à jour d'une ligne dans la propale
- */
+* Mise à jour d'une ligne dans la propale
+*/
if ($_POST['action'] == 'updateligne' && $user->rights->commande->creer && $_POST['save'] == $langs->trans('Save'))
{
- $commande = new Commande($db,'',$_POST['id']);
- if (! $commande->fetch($_POST['id']) > 0) dolibarr_print_error($db);
+ $commande = new Commande($db,'',$_POST['id']);
+ if (! $commande->fetch($_POST['id']) > 0) dolibarr_print_error($db);
- $result = $commande->updateline($_POST['elrowid'],
- $_POST['eldesc'],
- $_POST['pu'],
- $_POST['qty'],
- $_POST['elremise_percent'],
- $_POST['tva_tx']
- );
+ $result = $commande->updateline($_POST['elrowid'],
+ $_POST['eldesc'],
+ $_POST['pu'],
+ $_POST['qty'],
+ $_POST['elremise_percent'],
+ $_POST['tva_tx']
+ );
- if ($result >= 0)
- {
- if ($_REQUEST['lang_id'])
+ if ($result >= 0)
{
- $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
- $outputlangs->setDefaultLang($_REQUEST['lang_id']);
+ if ($_REQUEST['lang_id'])
+ {
+ $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
+ $outputlangs->setDefaultLang($_REQUEST['lang_id']);
+ }
+ commande_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs);
+ }
+ else
+ {
+ dolibarr_print_error($db,$commande->error);
+ exit;
}
- commande_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs);
- }
- else
- {
- dolibarr_print_error($db,$commande->error);
- exit;
- }
- $_GET['id']=$_POST['id']; // Pour réaffichage de la fiche en cours d'édition
+ $_GET['id']=$_POST['id']; // Pour réaffichage de la fiche en cours d'édition
}
if ($_POST['action'] == 'updateligne' && $user->rights->commande->creer && $_POST['cancel'] == $langs->trans('Cancel'))
{
- Header('Location: fiche.php?id='.$_POST['id']); // Pour réaffichage de la fiche en cours d'édition
- exit;
+ Header('Location: fiche.php?id='.$_POST['id']); // Pour réaffichage de la fiche en cours d'édition
+ exit;
}
if ($_GET['action'] == 'deleteline' && $user->rights->commande->creer && !$conf->global->PRODUIT_CONFIRM_DELETE_LINE)
{
- $commande = new Commande($db);
- $commande->fetch($_GET['id']);
- $result = $commande->delete_line($_GET['lineid']);
- if ($_REQUEST['lang_id'])
- {
- $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
- $outputlangs->setDefaultLang($_REQUEST['lang_id']);
- }
- commande_pdf_create($db, $_GET['id'], $commande->modelpdf, $outputlangs);
- Header('Location: fiche.php?id='.$_GET['id']);
- exit;
+ $commande = new Commande($db);
+ $commande->fetch($_GET['id']);
+ $result = $commande->delete_line($_GET['lineid']);
+ if ($_REQUEST['lang_id'])
+ {
+ $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
+ $outputlangs->setDefaultLang($_REQUEST['lang_id']);
+ }
+ commande_pdf_create($db, $_GET['id'], $commande->modelpdf, $outputlangs);
+ Header('Location: fiche.php?id='.$_GET['id']);
+ exit;
}
if ($_POST['action'] == 'confirm_valid' && $_POST['confirm'] == 'yes' && $user->rights->commande->valider)
{
- $commande = new Commande($db);
- $commande->fetch($_GET['id']);
- $soc = new Societe($db);
- $soc->fetch($commande->socid);
- $result = $commande->valid($user);
+ $commande = new Commande($db);
+ $commande->fetch($_GET['id']);
+ $soc = new Societe($db);
+ $soc->fetch($commande->socid);
+ $result = $commande->valid($user);
}
if ($_POST['action'] == 'confirm_close' && $_POST['confirm'] == 'yes' && $user->rights->commande->creer)
{
- $commande = new Commande($db);
- $commande->fetch($_GET['id']);
- $result = $commande->cloture($user);
+ $commande = new Commande($db);
+ $commande->fetch($_GET['id']);
+ $result = $commande->cloture($user);
}
if ($_POST['action'] == 'confirm_cancel' && $_POST['confirm'] == 'yes' && $user->rights->commande->valider)
{
- $commande = new Commande($db);
- $commande->fetch($_GET['id']);
- $result = $commande->cancel($user);
+ $commande = new Commande($db);
+ $commande->fetch($_GET['id']);
+ $result = $commande->cancel($user);
}
if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes')
{
- if ($user->rights->commande->supprimer )
- {
- $commande = new Commande($db);
- $commande->fetch($_GET['id']);
- $commande->delete();
- Header('Location: index.php');
- exit;
- }
+ if ($user->rights->commande->supprimer )
+ {
+ $commande = new Commande($db);
+ $commande->fetch($_GET['id']);
+ $commande->delete();
+ Header('Location: index.php');
+ exit;
+ }
}
if ($_POST['action'] == 'confirm_deleteproductline' && $_POST['confirm'] == 'yes' && $conf->global->PRODUIT_CONFIRM_DELETE_LINE)
{
- if ($user->rights->commande->creer)
- {
- $commande = new Commande($db);
- $commande->fetch($_GET['id']);
- $commande->delete_line($_GET['lineid']);
- if ($_REQUEST['lang_id'])
+ if ($user->rights->commande->creer)
{
- $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
- $outputlangs->setDefaultLang($_REQUEST['lang_id']);
+ $commande = new Commande($db);
+ $commande->fetch($_GET['id']);
+ $commande->delete_line($_GET['lineid']);
+ if ($_REQUEST['lang_id'])
+ {
+ $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
+ $outputlangs->setDefaultLang($_REQUEST['lang_id']);
+ }
+ commande_pdf_create($db, $_GET['id'], $commande->modelpdf, $outputlangs);
}
- commande_pdf_create($db, $_GET['id'], $commande->modelpdf, $outputlangs);
- }
- Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$_GET['id']);
- exit;
+ Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$_GET['id']);
+ exit;
}
if ($_GET['action'] == 'modif' && $user->rights->commande->creer)
{
- /*
- * Repasse la commande en mode brouillon
- */
- $commande = new Commande($db);
- $commande->fetch($_GET['id']);
- $commande->set_draft($user->id);
+ /*
+ * Repasse la commande en mode brouillon
+ */
+ $commande = new Commande($db);
+ $commande->fetch($_GET['id']);
+ $commande->set_draft($user->id);
}
/*
- * Ordonnancement des lignes
- */
+* Ordonnancement des lignes
+*/
if ($_GET['action'] == 'up' && $user->rights->commande->creer)
{
- $commande = new Commande($db,'',$_GET['id']);
- $commande->fetch($_GET['id']);
- $commande->line_up($_GET['rowid']);
- if ($_REQUEST['lang_id'])
- {
- $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
- $outputlangs->setDefaultLang($_REQUEST['lang_id']);
- }
- commande_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs);
- Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$_GET["id"].'#'.$_GET['rowid']);
+ $commande = new Commande($db,'',$_GET['id']);
+ $commande->fetch($_GET['id']);
+ $commande->line_up($_GET['rowid']);
+ if ($_REQUEST['lang_id'])
+ {
+ $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
+ $outputlangs->setDefaultLang($_REQUEST['lang_id']);
+ }
+ commande_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs);
+ Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$_GET["id"].'#'.$_GET['rowid']);
+ exit;
}
if ($_GET['action'] == 'down' && $user->rights->commande->creer)
{
- $commande = new Commande($db,'',$_GET['id']);
- $commande->fetch($_GET['id']);
- $commande->line_down($_GET['rowid']);
- if ($_REQUEST['lang_id'])
- {
- $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
- $outputlangs->setDefaultLang($_REQUEST['lang_id']);
- }
- commande_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs);
- Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$_GET["id"].'#'.$_GET['rowid']);
+ $commande = new Commande($db,'',$_GET['id']);
+ $commande->fetch($_GET['id']);
+ $commande->line_down($_GET['rowid']);
+ if ($_REQUEST['lang_id'])
+ {
+ $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
+ $outputlangs->setDefaultLang($_REQUEST['lang_id']);
+ }
+ commande_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs);
+ Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$_GET["id"].'#'.$_GET['rowid']);
+ exit;
}
if ($_REQUEST['action'] == 'builddoc') // En get ou en post
{
- /*
- * Generation de la commande
- * définit dans /includes/modules/commande/modules_commande.php
- */
+ /*
+ * Generation de la commande
+ * définit dans /includes/modules/commande/modules_commande.php
+ */
- // Sauvegarde le dernier modèle choisi pour générer un document
- $commande = new Commande($db, 0, $_REQUEST['id']);
- $commande->fetch($_REQUEST['id']);
- if ($_REQUEST['model'])
- {
- $commande->set_pdf_model($user, $_REQUEST['model']);
- }
+ // Sauvegarde le dernier modèle choisi pour générer un document
+ $commande = new Commande($db, 0, $_REQUEST['id']);
+ $commande->fetch($_REQUEST['id']);
+ if ($_REQUEST['model'])
+ {
+ $commande->set_pdf_model($user, $_REQUEST['model']);
+ }
- if ($_REQUEST['lang_id'])
- {
- $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
- $outputlangs->setDefaultLang($_REQUEST['lang_id']);
- }
- $result=commande_pdf_create($db, $commande->id,$commande->modelpdf,$outputlangs);
- if ($result <= 0)
- {
- dolibarr_print_error($db,$result);
- exit;
- }
- else
- {
- Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$commande->id.'#builddoc');
- }
+ if ($_REQUEST['lang_id'])
+ {
+ $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
+ $outputlangs->setDefaultLang($_REQUEST['lang_id']);
+ }
+ $result=commande_pdf_create($db, $commande->id,$commande->modelpdf,$outputlangs);
+ if ($result <= 0)
+ {
+ dolibarr_print_error($db,$result);
+ exit;
+ }
+ else
+ {
+ Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$commande->id.'#builddoc');
+ exit;
+ }
}
// Efface les fichiers
if ($action=='remove_file')
{
- $com = new Commande($db);
+ $com = new Commande($db);
- if ($com->fetch($id))
- {
- $upload_dir = $conf->commande->dir_output . "/";
- $file = $upload_dir . '/' . urldecode($_GET['file']);
- dol_delete_file($file);
- $mesg = ''.$langs->trans("FileWasRemoved").'
';
- }
+ if ($com->fetch($id))
+ {
+ $upload_dir = $conf->commande->dir_output . "/";
+ $file = $upload_dir . '/' . urldecode($_GET['file']);
+ dol_delete_file($file);
+ $mesg = ''.$langs->trans("FileWasRemoved").'
';
+ }
}
/*
- * Envoi de la commande par mail
- */
+* Envoi de la commande par mail
+*/
if ($_POST['action'] == 'send')
{
- $langs->load('mails');
+ $langs->load('mails');
- $commande= new Commande($db);
- if ( $commande->fetch($_POST['orderid']) )
- {
- $orderref = sanitize_string($commande->ref);
- $file = $conf->commande->dir_output . '/' . $orderref . '/' . $orderref . '.pdf';
-
- if (is_readable($file))
- {
- $commande->fetch_client();
+ $commande= new Commande($db);
+ if ( $commande->fetch($_POST['orderid']) )
+ {
+ $orderref = sanitize_string($commande->ref);
+ $file = $conf->commande->dir_output . '/' . $orderref . '/' . $orderref . '.pdf';
- if ($_POST['sendto'])
- {
- // Le destinataire a été fourni via le champ libre
- $sendto = $_POST['sendto'];
- $sendtoid = 0;
- }
- elseif ($_POST['receiver'])
- {
- // Le destinataire a été fourni via la liste déroulante
- if ($_POST['receiver'] < 0) // Id du tiers
+ if (is_readable($file))
{
- $sendto = $commande->client->email;
- $sendtoid = 0;
+ $commande->fetch_client();
+
+ if ($_POST['sendto'])
+ {
+ // Le destinataire a été fourni via le champ libre
+ $sendto = $_POST['sendto'];
+ $sendtoid = 0;
+ }
+ elseif ($_POST['receiver'])
+ {
+ // Le destinataire a été fourni via la liste déroulante
+ if ($_POST['receiver'] < 0) // Id du tiers
+ {
+ $sendto = $commande->client->email;
+ $sendtoid = 0;
+ }
+ else // Id du contact
+ {
+ $sendto = $commande->client->contact_get_email($_POST['receiver']);
+ $sendtoid = $_POST['receiver'];
+ }
+ }
+
+ if (strlen($sendto))
+ {
+ $from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>';
+ $replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>';
+ $message = $_POST['message'];
+ $sendtocc = $_POST['sendtocc'];
+ $deliveryreceipt = $_POST['deliveryreceipt'];
+
+ if ($_POST['action'] == 'send')
+ {
+ $subject = $_POST['subject'];
+
+ if($subject == '')
+ {
+ $subject = $langs->trans('Order').' '.$commande->ref;
+ }
+
+ $actiontypeid=8;
+ $actionmsg ='Mail envoyé par '.$from.' à '.$sendto.'. ';
+
+ if ($message)
+ {
+ $actionmsg.='Texte utilisé dans le corps du message: ';
+ $actionmsg.=$message;
+ }
+
+ $actionmsg2='Envoi commande par mail';
+ }
+
+ $filepath[0] = $file;
+ $filename[0] = $commande->ref.'.pdf';
+ $mimetype[0] = 'application/pdf';
+ if ($_FILES['addedfile']['tmp_name'])
+ {
+ $filepath[1] = $_FILES['addedfile']['tmp_name'];
+ $filename[1] = $_FILES['addedfile']['name'];
+ $mimetype[1] = $_FILES['addedfile']['type'];
+ }
+
+ // Envoi de la commande
+ $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt);
+ if ($mailfile->error)
+ {
+ $mesg=''.$mailfile->error.'
';
+ }
+ else
+ {
+ $result=$mailfile->sendfile();
+ if ($result)
+ {
+ $mesg=''.$langs->trans('MailSuccessfulySent',$from,$sendto).'.
';
+
+ // Insertion action
+ require_once(DOL_DOCUMENT_ROOT."/contact.class.php");
+ require_once(DOL_DOCUMENT_ROOT.'/actioncomm.class.php');
+ $actioncomm = new ActionComm($db);
+ $actioncomm->type_id = $actiontypeid;
+ $actioncomm->label = $actionmsg2;
+ $actioncomm->note = $actionmsg;
+ $actioncomm->date = time(); // L'action est faite maintenant
+ $actioncomm->percent = 100;
+ $actioncomm->contact = new Contact($db,$sendtoid);
+ $actioncomm->societe = new Societe($db,$commande->socid);
+ $actioncomm->user = $user; // User qui a fait l'action
+ $actioncomm->orderrowid = $commande->id;
+
+ $ret=$actioncomm->add($user); // User qui saisit l'action
+ if ($ret < 0)
+ {
+ dolibarr_print_error($db);
+ }
+ else
+ {
+ // Renvoie sur la fiche
+ Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$commande->id.'&msg='.urlencode($mesg));
+ exit;
+ }
+ }
+ else
+ {
+ $langs->load("other");
+ $mesg='';
+ if ($mailfile->error)
+ {
+ $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
+ $mesg.=' '.$mailfile->error;
+ }
+ else
+ {
+ $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
+ }
+ $mesg.='
';
+ }
+ }
+ }
+ else
+ {
+ $langs->load("other");
+ $mesg=''.$langs->trans('ErrorMailRecipientIsEmpty').' !
';
+ dolibarr_syslog('Recipient email is empty');
+ }
}
- else // Id du contact
+ else
{
- $sendto = $commande->client->contact_get_email($_POST['receiver']);
- $sendtoid = $_POST['receiver'];
+ $langs->load("other");
+ $mesg=''.$langs->trans('ErrorCantReadFile',$file).'
';
+ dolibarr_syslog('Failed to read file: '.$file);
}
- }
-
- if (strlen($sendto))
- {
- $from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>';
- $replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>';
- $message = $_POST['message'];
- $sendtocc = $_POST['sendtocc'];
- $deliveryreceipt = $_POST['deliveryreceipt'];
-
- if ($_POST['action'] == 'send')
- {
- $subject = $_POST['subject'];
-
- if($subject == '')
- {
- $subject = $langs->trans('Order').' '.$commande->ref;
- }
-
- $actiontypeid=8;
- $actionmsg ='Mail envoyé par '.$from.' à '.$sendto.'. ';
-
- if ($message)
- {
- $actionmsg.='Texte utilisé dans le corps du message: ';
- $actionmsg.=$message;
- }
-
- $actionmsg2='Envoi commande par mail';
- }
-
- $filepath[0] = $file;
- $filename[0] = $commande->ref.'.pdf';
- $mimetype[0] = 'application/pdf';
- if ($_FILES['addedfile']['tmp_name'])
- {
- $filepath[1] = $_FILES['addedfile']['tmp_name'];
- $filename[1] = $_FILES['addedfile']['name'];
- $mimetype[1] = $_FILES['addedfile']['type'];
- }
-
- // Envoi de la commande
- $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt);
- if ($mailfile->error)
- {
- $mesg=''.$mailfile->error.'
';
- }
- else
- {
- $result=$mailfile->sendfile();
- if ($result)
- {
- $mesg=''.$langs->trans('MailSuccessfulySent',$from,$sendto).'.
';
-
- // Insertion action
- require_once(DOL_DOCUMENT_ROOT."/contact.class.php");
- require_once(DOL_DOCUMENT_ROOT.'/actioncomm.class.php');
- $actioncomm = new ActionComm($db);
- $actioncomm->type_id = $actiontypeid;
- $actioncomm->label = $actionmsg2;
- $actioncomm->note = $actionmsg;
- $actioncomm->date = time(); // L'action est faite maintenant
- $actioncomm->percent = 100;
- $actioncomm->contact = new Contact($db,$sendtoid);
- $actioncomm->societe = new Societe($db,$commande->socid);
- $actioncomm->user = $user; // User qui a fait l'action
- $actioncomm->orderrowid = $commande->id;
-
- $ret=$actioncomm->add($user); // User qui saisit l'action
- if ($ret < 0)
- {
- dolibarr_print_error($db);
- }
- else
- {
- // Renvoie sur la fiche
- Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$commande->id.'&msg='.urlencode($mesg));
- exit;
- }
- }
- else
- {
- $langs->load("other");
- $mesg='';
- if ($mailfile->error)
- {
- $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
- $mesg.=' '.$mailfile->error;
- }
- else
- {
- $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
- }
- $mesg.='
';
- }
- }
- }
- else
- {
- $langs->load("other");
- $mesg=''.$langs->trans('ErrorMailRecipientIsEmpty').' !
';
- dolibarr_syslog('Recipient email is empty');
- }
- }
- else
- {
- $langs->load("other");
- $mesg=''.$langs->trans('ErrorCantReadFile',$file).'
';
- dolibarr_syslog('Failed to read file: '.$file);
- }
- }
- else
- {
- $langs->load("other");
- $mesg=''.$langs->trans('ErrorFailedToReadEntity',$langs->trans("Invoice")).'
';
- dolibarr_syslog('Impossible de lire les données de la facture. Le fichier facture n\'a peut-être pas été généré.');
- }
+ }
+ else
+ {
+ $langs->load("other");
+ $mesg=''.$langs->trans('ErrorFailedToReadEntity',$langs->trans("Invoice")).'
';
+ dolibarr_syslog('Impossible de lire les données de la facture. Le fichier facture n\'a peut-être pas été généré.');
+ }
}
@@ -672,1264 +675,1264 @@ llxHeader('',$langs->trans('Order'),'Commande');
$html = new Form($db);
/*********************************************************************
- *
- * Mode creation
- *
- *********************************************************************/
+*
+* Mode creation
+*
+*********************************************************************/
if ($_GET['action'] == 'create' && $user->rights->commande->creer)
{
- print_titre($langs->trans('CreateOrder'));
+ print_titre($langs->trans('CreateOrder'));
- if ($mesg) print $mesg.' ';
+ if ($mesg) print $mesg.' ';
- $new_commande = new Commande($db);
+ $new_commande = new Commande($db);
- if ($propalid)
- {
- $sql = 'SELECT s.nom, s.prefix_comm, s.idp, p.price, p.remise, p.remise_percent, p.tva, p.total, p.ref, p.fk_cond_reglement, p.fk_mode_reglement, '.$db->pdate('p.datep').' as dp, c.id as statut, c.label as lst';
- $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'propal as p, '.MAIN_DB_PREFIX.'c_propalst as c';
- $sql .= ' WHERE p.fk_soc = s.idp AND p.fk_statut = c.id';
- $sql .= ' AND p.rowid = '.$propalid;
- }
- else
- {
- $sql = 'SELECT s.nom, s.prefix_comm, s.idp, s.mode_reglement, s.cond_reglement ';
- $sql .= 'FROM '.MAIN_DB_PREFIX.'societe as s ';
- $sql .= 'WHERE s.idp = '.$_GET['socid'];
- }
- $resql = $db->query($sql);
- if ( $resql )
- {
- $num = $db->num_rows($resql);
- if ($num)
+ if ($propalid)
{
- $obj = $db->fetch_object($resql);
-
- $soc = new Societe($db);
- $soc->fetch($obj->idp);
-
- $nbrow=7;
-
- print '';
-
- if ($propalid)
- {
- /*
- * Produits
- */
- print_titre($langs->trans('Products'));
- print '';
- print ''.$langs->trans('Ref').' '.$langs->trans('Product').' ';
- print ''.$langs->trans('Price').' ';
- print ''.$langs->trans('Qty').' ';
- print ''.$langs->trans('Reductionshort').' ';
- print ' ';
-
- $var=false;
-
- $sql = 'SELECT pt.rowid, p.label as product, p.ref, pt.price, pt.qty, p.rowid as prodid, pt.remise_percent';
- $sql .= ' FROM '.MAIN_DB_PREFIX.'propaldet as pt, '.MAIN_DB_PREFIX.'product as p WHERE pt.fk_product = p.rowid AND pt.fk_propal = '.$propalid;
- $sql .= ' ORDER BY pt.rowid ASC';
- $result = $db->query($sql);
- if ($result)
- {
- $num = $db->num_rows($result);
- $i = 0;
- while ($i < $num)
- {
- $objp = $db->fetch_object($result);
- $var=!$var;
- print '['.$objp->ref.'] ';
- print ''.img_object($langs->trans('ShowProduct'),'product').' '.$objp->product.' ';
- print ''.price($objp->price).' ';
- print ''.$objp->qty.' ';
- print ''.$objp->remise_percent.'% ';
- $i++;
- }
- }
-
- $sql = 'SELECT pt.rowid, pt.description as product, pt.price, pt.qty, pt.remise_percent';
- $sql .= ' FROM '.MAIN_DB_PREFIX.'propaldet as pt WHERE pt.fk_propal = '.$propalid.' AND pt.fk_product = 0';
- $sql .= ' ORDER BY pt.rowid ASC';
- if ($db->query($sql))
- {
- $num = $db->num_rows();
- $i = 0;
- while ($i < $num)
- {
- $objp = $db->fetch_object();
- $var=!$var;
- print ' ';
- print ''.img_object($langs->trans('ShowProduct'),'product').' '.$objp->product.' ';
- print ''.price($objp->price).' ';
- print ''.$objp->qty.' ';
- print ''.$objp->remise_percent.'% ';
- $i++;
- }
- }
- else
- {
- dolibarr_print_error($db);
- }
-
- print '
';
- }
+ $sql = 'SELECT s.nom, s.prefix_comm, s.idp, p.price, p.remise, p.remise_percent, p.tva, p.total, p.ref, p.fk_cond_reglement, p.fk_mode_reglement, '.$db->pdate('p.datep').' as dp, c.id as statut, c.label as lst';
+ $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'propal as p, '.MAIN_DB_PREFIX.'c_propalst as c';
+ $sql .= ' WHERE p.fk_soc = s.idp AND p.fk_statut = c.id';
+ $sql .= ' AND p.rowid = '.$propalid;
+ }
+ else
+ {
+ $sql = 'SELECT s.nom, s.prefix_comm, s.idp, s.mode_reglement, s.cond_reglement ';
+ $sql .= 'FROM '.MAIN_DB_PREFIX.'societe as s ';
+ $sql .= 'WHERE s.idp = '.$_GET['socid'];
+ }
+ $resql = $db->query($sql);
+ if ( $resql )
+ {
+ $num = $db->num_rows($resql);
+ if ($num)
+ {
+ $obj = $db->fetch_object($resql);
+
+ $soc = new Societe($db);
+ $soc->fetch($obj->idp);
+
+ $nbrow=7;
+
+ print '';
+ print ' ';
+ print ' ' ."\n";
+ print ' ';
+ print ' ';
+
+ print '';
+
+ // Reference
+ print ''.$langs->trans('Ref').' '.$langs->trans("Draft").' ';
+ print ''.$langs->trans('NotePublic').' ';
+
+ // Reference client
+ print ''.$langs->trans('RefCustomer').' ';
+ print ' ';
+ print ' ';
+ print ' ';
+
+ // Client
+ print ''.$langs->trans('Customer').' '.$soc->getNomUrl(1).' ';
+ print ' ';
+
+ /*
+ * Contact de la propale
+ */
+ print "".$langs->trans("DefaultContact").' ';
+ $html->select_contacts($soc->id,$setcontact,'contactidp',1);
+ print ' ';
+
+ // Ligne info remises tiers
+ print ''.$langs->trans('Discounts').' ';
+ if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client);
+ else print $langs->trans("CompanyHasNoRelativeDiscount");
+ $absolute_discount=$soc->getCurrentDiscount();
+ print '. ';
+ if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie));
+ else print $langs->trans("CompanyHasNoAbsoluteDiscount");
+ print '.';
+ print ' ';
+
+ // Date
+ print ''.$langs->trans('Date').' ';
+ $html->select_date('','re','','','',"crea_commande");
+ print ' ';
+
+ // Date de livraison
+ if ($conf->expedition->enabled)
+ {
+ print "".$langs->trans("DateDelivery")." ";
+ if ($conf->global->DATE_LIVRAISON_WEEK_DELAY)
+ {
+ $tmpdte = time() + ((7*$conf->global->DATE_LIVRAISON_WEEK_DELAY) * 24 * 60 * 60);
+ $html->select_date($tmpdte,'liv_','','',1,"crea_commande");
+ }
+ else
+ {
+ $html->select_date(-1,'liv_','','',1,"crea_commande");
+ }
+ print " ";
+
+ // Adresse de livraison
+ print ''.$langs->trans('DeliveryAddress').' ';
+ $numaddress = $html->select_adresse_livraison($soc->adresse_livraison_id, $_GET['socid'],'adresse_livraison_id',1);
+
+ if ($numaddress==0)
+ {
+ print ' '.$langs->trans("AddAddress").' ';
+ }
+
+ print ' ';
+ }
+
+ // Conditions de réglement
+ print ''.$langs->trans('PaymentConditionsShort').' ';
+ $html->select_conditions_paiements($soc->cond_reglement,'cond_reglement_id',-1,1);
+ print ' ';
+
+ // Mode de réglement
+ print ''.$langs->trans('PaymentMode').' ';
+ $html->select_types_paiements($soc->mode_reglement,'mode_reglement_id');
+ print ' ';
+
+ // Réductions relatives (Remises-Ristournes-Rabbais)
+ /* Une réduction doit s'appliquer obligatoirement sur des lignes de factures
+ et non globalement
+ $relative_discount=$soc->remise_client;
+ print ''.$langs->trans("CustomerRelativeDiscount").' ';
+ print '';
+ print ' %';
+ print ' '.img_info().' ';
+ if ($relative_discount)
+ {
+ print $langs->trans("CompanyHasRelativeDiscount",$relative_discount);
+ }
+ else
+ {
+ print $langs->trans("CompanyHasNoRelativeDiscount");
+ }
+ print ' ';
+ */
+
+ // Réductions (Remises-Ristournes-Rabbais)
+ /* Les remises absolues doivent s'appliquer par ajout de lignes spécialisées
+ $absolute_discount=$soc->getCurrentDiscount();
+ print ''.$langs->trans("CustomerAbsoluteDiscount").' ';
+ print '';
+ print ' '.$langs->trans("Currency".$conf->monnaie);
+ print ' '.img_info().' ';
+ if ($absolute_discount)
+ {
+ print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie));
+ }
+ else
+ {
+ print $langs->trans("CompanyHasNoAbsoluteDiscount");
+ }
+ print ' ';
+ */
+
+ // Projet
+ if ($conf->projet->enabled)
+ {
+ print ''.$langs->trans('Project').' ';
+ $numprojet=$html->select_projects($soc->id,$projetid,'projetid');
+ if ($numprojet==0)
+ {
+ print ' id.'&action=create>'.$langs->trans("AddProject").' ';
+ }
+ print ' ';
+ }
+
+ print ''.$langs->trans('Source').' ';
+ $html->selectSourcesCommande('','source_id',1);
+ print ' ';
+ print ''.$langs->trans('Model').' ';
+ print '';
+ // pdf
+ include_once(DOL_DOCUMENT_ROOT.'/includes/modules/commande/modules_commande.php');
+ $model=new ModelePDFCommandes();
+ $liste=$model->liste_modeles($db);
+ $html->select_array('model',$liste,$conf->global->COMMANDE_ADDON_PDF);
+ print " ";
+
+ if ($propalid > 0)
+ {
+ $amount = ($obj->price);
+ print ' '."\n";
+ print ' '."\n";
+ print ' '."\n";
+ print ' '."\n";
+ print ' '."\n";
+ print ' ';
+
+ print ''.$langs->trans('Ref').' '.$obj->ref.' ';
+ print ''.$langs->trans('TotalTTC').' '.price($amount).' ';
+ print ''.$langs->trans('VAT').' '.price($obj->tva).' ';
+ print ''.$langs->trans('TotalTTC').' '.price($obj->total).' ';
+ }
+ else
+ {
+ if ($conf->global->PRODUCT_SHOW_WHEN_CREATE)
+ {
+ /*
+ * Services/produits prédéfinis
+ */
+ $NBLINES=8;
+
+ print '';
+
+ print '';
+ print ' ';
+ }
+ }
+
+ /*
+ *
+ */
+ print ' ';
+ print '
';
+
+ print ' ';
+
+ if ($propalid)
+ {
+ /*
+ * Produits
+ */
+ print_titre($langs->trans('Products'));
+ print '';
+ print ''.$langs->trans('Ref').' '.$langs->trans('Product').' ';
+ print ''.$langs->trans('Price').' ';
+ print ''.$langs->trans('Qty').' ';
+ print ''.$langs->trans('Reductionshort').' ';
+ print ' ';
+
+ $var=false;
+
+ $sql = 'SELECT pt.rowid, p.label as product, p.ref, pt.price, pt.qty, p.rowid as prodid, pt.remise_percent';
+ $sql .= ' FROM '.MAIN_DB_PREFIX.'propaldet as pt, '.MAIN_DB_PREFIX.'product as p WHERE pt.fk_product = p.rowid AND pt.fk_propal = '.$propalid;
+ $sql .= ' ORDER BY pt.rowid ASC';
+ $result = $db->query($sql);
+ if ($result)
+ {
+ $num = $db->num_rows($result);
+ $i = 0;
+ while ($i < $num)
+ {
+ $objp = $db->fetch_object($result);
+ $var=!$var;
+ print '['.$objp->ref.'] ';
+ print ''.img_object($langs->trans('ShowProduct'),'product').' '.$objp->product.' ';
+ print ''.price($objp->price).' ';
+ print ''.$objp->qty.' ';
+ print ''.$objp->remise_percent.'% ';
+ $i++;
+ }
+ }
+
+ $sql = 'SELECT pt.rowid, pt.description as product, pt.price, pt.qty, pt.remise_percent';
+ $sql .= ' FROM '.MAIN_DB_PREFIX.'propaldet as pt WHERE pt.fk_propal = '.$propalid.' AND pt.fk_product = 0';
+ $sql .= ' ORDER BY pt.rowid ASC';
+ if ($db->query($sql))
+ {
+ $num = $db->num_rows();
+ $i = 0;
+ while ($i < $num)
+ {
+ $objp = $db->fetch_object();
+ $var=!$var;
+ print ' ';
+ print ''.img_object($langs->trans('ShowProduct'),'product').' '.$objp->product.' ';
+ print ''.price($objp->price).' ';
+ print ''.$objp->qty.' ';
+ print ''.$objp->remise_percent.'% ';
+ $i++;
+ }
+ }
+ else
+ {
+ dolibarr_print_error($db);
+ }
+
+ print '
';
+ }
+ }
+ }
+ else
+ {
+ dolibarr_print_error($db);
}
- }
- else
- {
- dolibarr_print_error($db);
- }
}
else
{
- /* *************************************************************************** */
- /* */
- /* Mode vue et edition */
- /* */
- /* *************************************************************************** */
- $id = $_GET['id'];
- if ($id > 0)
- {
- if ($mesg) print $mesg.' ';
-
- $commande = new Commande($db);
- if ( $commande->fetch($_GET['id']) > 0)
+ /* *************************************************************************** */
+ /* */
+ /* Mode vue et edition */
+ /* */
+ /* *************************************************************************** */
+ $id = $_GET['id'];
+ if ($id > 0)
{
- $soc = new Societe($db);
- $soc->fetch($commande->socid);
-
- $author = new User($db);
- $author->id = $commande->user_author_id;
- $author->fetch();
-
- $head = commande_prepare_head($commande);
- dolibarr_fiche_head($head, 'order', $langs->trans("CustomerOrder"));
-
- /*
- * Confirmation de la suppression de la commande
- */
- if ($_GET['action'] == 'delete')
- {
- $html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete');
- print ' ';
- }
-
- /*
- * Confirmation de la validation
- */
- if ($_GET['action'] == 'valid')
- {
- // on vérifie si la facture est en numérotation provisoire
- $ref = substr($commande->ref, 1, 4);
- if ($ref == 'PROV')
+ if ($mesg) print $mesg.' ';
+
+ $commande = new Commande($db);
+ if ( $commande->fetch($_GET['id']) > 0)
{
- $num = $commande->getNextNumRef($soc);
- }
- else
- {
- $num = $commande->ref;
- }
-
- $text=$langs->trans('ConfirmValidateOrder',$num);
- $html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('ValidateOrder'), $text, 'confirm_valid');
- print ' ';
- }
-
- /*
- * Confirmation de la cloture
- */
- if ($_GET['action'] == 'cloture')
- {
- //$numfa = commande_get_num($soc);
- $html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('CloseOrder'), $langs->trans('ConfirmCloseOrder'), 'confirm_close');
- print ' ';
- }
-
- /*
- * Confirmation de l'annulation
- */
- if ($_GET['action'] == 'annuler')
- {
- $html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('Cancel'), $langs->trans('ConfirmCancelOrder'), 'confirm_cancel');
- print ' ';
- }
-
- /*
- * Confirmation de la suppression d'une ligne produit
- */
- if ($_GET['action'] == 'delete_product_line' && $conf->global->PRODUIT_CONFIRM_DELETE_LINE)
- {
- $html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id.'&lineid='.$_GET["lineid"], $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteproductline');
- print ' ';
- }
-
- /*
- * Commande
- */
- $nbrow=8;
- if ($conf->projet->enabled) $nbrow++;
-
- print '';
-
- // Ref
- print ''.$langs->trans('Ref').' ';
- print ''.$commande->ref.' ';
- print ''.$langs->trans('Author').' : '.$author->fullname.' ';
- print ' ';
-
- // Ref commande client
- print '';
- print '';
- print $langs->trans('RefCustomer').' ';
- print ' ';
- if ($_GET['action'] != 'RefCustomerOrder' && $commande->brouillon) print ''.img_edit($langs->trans('Edit')).' ';
- print '
';
- print ' ';
- if ($user->rights->commande->creer && $_GET['action'] == 'RefCustomerOrder')
- {
- print '';
- print ' ';
- print ' ';
- print ' ';
- print ' ';
- }
- else
- {
- print $commande->ref_client;
- }
- print ' ';
- print ' ';
-
-
- // Société
- print ''.$langs->trans('Company').' ';
- print ''.$soc->getNomUrl(1).' ';
- print ' ';
-
- // Ligne info remises tiers
- print ''.$langs->trans('Discounts').' ';
- if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client);
- else print $langs->trans("CompanyHasNoRelativeDiscount");
- $absolute_discount=$soc->getCurrentDiscount();
- print '. ';
- if ($absolute_discount)
- {
- if ($commande->statut > 0)
- {
- print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie));
- }
- else
- {
- print ' ';
- print $html->form_remise_dispo($_SERVER["PHP_SELF"].'?id='.$commande->id,0,'remise_id',$soc->id,$absolute_discount);
- }
- }
- else print $langs->trans("CompanyHasNoAbsoluteDiscount").'.';
- print ' ';
-
- // Date
- print ''.$langs->trans('Date').' ';
- print ''.dolibarr_print_date($commande->date,'%A %d %B %Y').' ';
- print ''.$langs->trans('Source').' : ' . $commande->sources[$commande->source] ;
- if ($commande->source == 0)
- {
- // Si source = propal
- $propal = new Propal($db);
- $propal->fetch($commande->propale_id);
- print ' -> '.$propal->ref.' ';
- }
- print ' ';
- print ' ';
+ $soc = new Societe($db);
+ $soc->fetch($commande->socid);
- // Date de livraison
- if ($conf->expedition->enabled)
- {
- print '';
- print '';
- print $langs->trans('DateDelivery');
- print ' ';
+ $author = new User($db);
+ $author->id = $commande->user_author_id;
+ $author->fetch();
- if ($_GET['action'] != 'editdate_livraison' && $commande->brouillon) print 'id.'">'.img_edit($langs->trans('SetDateDelivery'),1).' ';
- print '
';
- print ' ';
- if ($_GET['action'] == 'editdate_livraison')
- {
- print 'id.'" method="post">';
- print ' ';
- $html->select_date($commande->date_livraison,'liv_','','','',"setdate_livraison");
- print ' ';
- print ' ';
- }
- else
- {
- print dolibarr_print_date($commande->date_livraison,'%A %d %B %Y');
- }
- print ' ';
- print ''.$langs->trans('NotePublic').' : ';
- print nl2br($commande->note_public);
- print ' ';
- print ' ';
+ $head = commande_prepare_head($commande);
+ dolibarr_fiche_head($head, 'order', $langs->trans("CustomerOrder"));
-
- // Adresse de livraison
- print '';
- print '';
- print ' ';
-
- if ($_GET['action'] == 'editdelivery_adress')
- {
- $html->form_adresse_livraison($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->adresse_livraison_id,$_GET['socid'],'adresse_livraison_id','commande',$commande->id);
- }
- else
- {
- $html->form_adresse_livraison($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->adresse_livraison_id,$_GET['socid'],'none','commande',$commande->id);
- }
- print ' ';
- }
-
- // Conditions et modes de réglement
- print '';
- print '';
- print ' ';
- if ($_GET['action'] == 'editconditions')
- {
- $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->cond_reglement_id,'cond_reglement_id');
- }
- else
- {
- $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->cond_reglement_id,'none');
- }
- print ' ';
- print '';
- print '';
- print ' ';
- if ($_GET['action'] == 'editmode')
- {
- $html->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->mode_reglement_id,'mode_reglement_id');
- }
- else
- {
- $html->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->mode_reglement_id,'none');
- }
- print ' ';
-
- // Projet
- if ($conf->projet->enabled)
- {
- $langs->load('projects');
- print '';
- print '';
- print ' ';
- if ($_GET['action'] == 'classer')
- {
- $html->form_project($_SERVER['PHP_SELF'].'?id='.$commande->id, $commande->socid, $commande->projet_id, 'projetid');
- }
- else
- {
- $html->form_project($_SERVER['PHP_SELF'].'?id='.$commande->id, $commande->socid, $commande->projet_id, 'none');
- }
- print ' ';
- }
-
- // Lignes de 3 colonnes
-
- // Total HT
- print ''.$langs->trans('AmountHT').' ';
- print ''.price($commande->total_ht).' ';
- print ''.$langs->trans('Currency'.$conf->monnaie).' ';
-
- // Total TVA
- print ''.$langs->trans('AmountVAT').' '.price($commande->total_tva).' ';
- print ''.$langs->trans('Currency'.$conf->monnaie).' ';
-
- // Total TTC
- print ''.$langs->trans('AmountTTC').' '.price($commande->total_ttc).' ';
- print ''.$langs->trans('Currency'.$conf->monnaie).' ';
-
- // Statut
- print ''.$langs->trans('Status').' ';
- print ''.$commande->getLibStatut(4).' ';
- print ' ';
-
- print '
';
- print "\n";
-
- /*
- * Lignes de commandes
- */
- $sql = 'SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice, l.info_bits,';
- $sql.= ' p.label as product, p.ref, p.fk_product_type, p.rowid as prodid, ';
- $sql.= ' p.description as product_desc';
- $sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet as l';
- $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product=p.rowid';
- $sql.= ' WHERE l.fk_commande = '.$commande->id;
- $sql.= ' ORDER BY l.rang ASC, l.rowid';
-
- $resql = $db->query($sql);
- if ($resql)
- {
- $num = $db->num_rows($resql);
- $i = 0; $total = 0;
-
- print '';
- if ($num)
- {
- print '';
- print ''.$langs->trans('Description').' ';
- print ''.$langs->trans('VAT').' ';
- print ''.$langs->trans('PriceUHT').' ';
- print ''.$langs->trans('Qty').' ';
- print ''.$langs->trans('ReductionShort').' ';
- print ''.$langs->trans('AmountHT').' ';
- print ' ';
- print ' ';
- print ' ';
- print " \n";
- }
- $var=true;
- while ($i < $num)
- {
- $objp = $db->fetch_object($resql);
- $var=!$var;
-
- // Ligne en mode visu
- if ($_GET['action'] != 'editline' || $_GET['rowid'] != $objp->rowid)
- {
- print '';
- if ($objp->fk_product > 0)
+ /*
+ * Confirmation de la suppression de la commande
+ */
+ if ($_GET['action'] == 'delete')
{
- print '';
- print ' '; // ancre pour retourner sur la ligne
- print '';
- if ($objp->fk_product_type) print img_object($langs->trans('ShowService'),'service');
- else print img_object($langs->trans('ShowProduct'),'product');
- print ' '.$objp->ref.' - '.nl2br($objp->product);
- print ($objp->description && $objp->description!=$objp->product)?' '.nl2br($objp->description):'';
- // \todo Ne faut-il pas rendre $conf->global->PRODUIT_CHANGE_PROD_DESC toujours a on
- if ($conf->global->PRODUIT_DESC_IN_FORM && !$conf->global->PRODUIT_CHANGE_PROD_DESC)
- {
- print ' '.nl2br($objp->product_desc);
- }
- print ' ';
- }
- else
- {
- print '';
- print ' '; // ancre pour retourner sur la ligne
- if (($objp->info_bits & 2) == 2)
- {
- print '';
- print img_object($langs->trans("ShowReduc"),'reduc').' '.$langs->trans("Discount");
- print ' ';
- if ($objp->description) print ' - '.nl2br($objp->description);
- }
- else
- {
- print nl2br($objp->description);
- }
- print ' ';
+ $html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete');
+ print ' ';
}
- print ''.$objp->tva_tx.'% ';
- print ''.price($objp->subprice).' ';
- print '';
- if (($objp->info_bits & 2) != 2)
+ /*
+ * Confirmation de la validation
+ */
+ if ($_GET['action'] == 'valid')
{
- print $objp->qty;
+ // on vérifie si la facture est en numérotation provisoire
+ $ref = substr($commande->ref, 1, 4);
+ if ($ref == 'PROV')
+ {
+ $num = $commande->getNextNumRef($soc);
+ }
+ else
+ {
+ $num = $commande->ref;
+ }
+
+ $text=$langs->trans('ConfirmValidateOrder',$num);
+ $html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('ValidateOrder'), $text, 'confirm_valid');
+ print ' ';
}
- else print ' ';
- print ' ';
- if ($objp->remise_percent > 0)
+
+ /*
+ * Confirmation de la cloture
+ */
+ if ($_GET['action'] == 'cloture')
{
- print ''.$objp->remise_percent.'% ';
+ //$numfa = commande_get_num($soc);
+ $html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('CloseOrder'), $langs->trans('ConfirmCloseOrder'), 'confirm_close');
+ print ' ';
}
- else
+
+ /*
+ * Confirmation de l'annulation
+ */
+ if ($_GET['action'] == 'annuler')
{
- print ' ';
+ $html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('Cancel'), $langs->trans('ConfirmCancelOrder'), 'confirm_cancel');
+ print ' ';
}
- print ''.price($objp->subprice*$objp->qty*(100-$objp->remise_percent)/100).' ';
- // Icone d'edition et suppression
- if ($commande->statut == 0 && $user->rights->commande->creer)
+ /*
+ * Confirmation de la suppression d'une ligne produit
+ */
+ if ($_GET['action'] == 'delete_product_line' && $conf->global->PRODUIT_CONFIRM_DELETE_LINE)
{
- print 'rowid.'#'.$objp->rowid.'">';
- print img_edit();
- print ' ';
- if ($conf->global->PRODUIT_CONFIRM_DELETE_LINE)
- {
- print 'rowid.'">';
- }
- else
- {
- print ' rowid.'">';
- }
- print img_delete();
- print ' ';
- print '';
- if ($i > 0)
- {
- print 'id.'&action=up&rowid='.$objp->rowid.'">';
- print img_up();
- print ' ';
- }
- if ($i < $num-1)
- {
- print 'id.'&action=down&rowid='.$objp->rowid.'">';
- print img_down();
- print ' ';
- }
- print ' ';
+ $html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id.'&lineid='.$_GET["lineid"], $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteproductline');
+ print ' ';
}
- else
+
+ /*
+ * Commande
+ */
+ $nbrow=8;
+ if ($conf->projet->enabled) $nbrow++;
+
+ print '';
+
+ // Ref
+ print ''.$langs->trans('Ref').' ';
+ print ''.$commande->ref.' ';
+ print ''.$langs->trans('Author').' : '.$author->fullname.' ';
+ print ' ';
+
+ // Ref commande client
+ print '';
+ print '';
+ print $langs->trans('RefCustomer').' ';
+ print ' ';
+ if ($_GET['action'] != 'RefCustomerOrder' && $commande->brouillon) print ''.img_edit($langs->trans('Edit')).' ';
+ print '
';
+ print ' ';
+ if ($user->rights->commande->creer && $_GET['action'] == 'RefCustomerOrder')
{
- print ' ';
+ print '';
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' ';
}
- print ' ';
- }
-
- // Ligne en mode update
- if ($_GET['action'] == 'editline' && $user->rights->commande->creer && $_GET['rowid'] == $objp->rowid)
- {
- print 'rowid.'" method="post">';
- print ' ';
- print ' ';
- print ' ';
- print '';
- print '';
- print ' '; // ancre pour retourner sur la ligne
- if ($objp->fk_product > 0)
+ else
{
- print '';
- if ($objp->fk_product_type) print img_object($langs->trans('ShowService'),'service');
- else print img_object($langs->trans('ShowProduct'),'product');
- print ' '.$objp->ref.' ';
- print ' - '.nl2br($objp->product);
- print ' ';
+ print $commande->ref_client;
}
- // éditeur wysiwyg
- if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS)
+ print ' ';
+ print ' ';
+
+
+ // Sociét
+ print ''.$langs->trans('Company').' ';
+ print ''.$soc->getNomUrl(1).' ';
+ print ' ';
+
+ // Ligne info remises tiers
+ print ''.$langs->trans('Discounts').' ';
+ if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client);
+ else print $langs->trans("CompanyHasNoRelativeDiscount");
+ $absolute_discount=$soc->getCurrentDiscount();
+ print '. ';
+ if ($absolute_discount)
{
- require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php");
- $doleditor=new DolEditor('eldesc',$objp->description,200,'dolibarr_details');
- $doleditor->Create();
+ if ($commande->statut > 0)
+ {
+ print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie));
+ }
+ else
+ {
+ print ' ';
+ print $html->form_remise_dispo($_SERVER["PHP_SELF"].'?id='.$commande->id,0,'remise_id',$soc->id,$absolute_discount);
+ }
}
- else
+ else print $langs->trans("CompanyHasNoAbsoluteDiscount").'.';
+ print ' ';
+
+ // Date
+ print ''.$langs->trans('Date').' ';
+ print ''.dolibarr_print_date($commande->date,'%A %d %B %Y').' ';
+ print ''.$langs->trans('Source').' : ' . $commande->sources[$commande->source] ;
+ if ($commande->source == 0)
{
- print ''.$objp->description.' ';
- }
- print ' ';
- print '';
- if($soc->tva_assuj == "0")
- print ' 0';
- else
- print $html->select_tva('tva_tx',$objp->tva_tx,$mysoc,$soc);
- print ' ';
- print ' ';
- print '';
- if (($objp->info_bits & 2) != 2)
- {
- print ' ';
+ // Si source = propal
+ $propal = new Propal($db);
+ $propal->fetch($commande->propale_id);
+ print ' -> '.$propal->ref.' ';
}
- else print ' ';
- print ' ';
- print '';
- if (($objp->info_bits & 2) != 2)
+ print ' ';
+ print ' ';
+
+ // Date de livraison
+ if ($conf->expedition->enabled)
{
- print ' %';
+ print '';
+ print '';
+ print ' ';
+ if ($_GET['action'] == 'editdate_livraison')
+ {
+ print 'id.'" method="post">';
+ print ' ';
+ $html->select_date($commande->date_livraison,'liv_','','','',"setdate_livraison");
+ print ' ';
+ print ' ';
+ }
+ else
+ {
+ print dolibarr_print_date($commande->date_livraison,'%A %d %B %Y');
+ }
+ print ' ';
+ print ''.$langs->trans('NotePublic').' : ';
+ print nl2br($commande->note_public);
+ print ' ';
+ print ' ';
+
+
+ // Adresse de livraison
+ print '';
+ print '';
+ print ' ';
+
+ if ($_GET['action'] == 'editdelivery_adress')
+ {
+ $html->form_adresse_livraison($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->adresse_livraison_id,$_GET['socid'],'adresse_livraison_id','commande',$commande->id);
+ }
+ else
+ {
+ $html->form_adresse_livraison($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->adresse_livraison_id,$_GET['socid'],'none','commande',$commande->id);
+ }
+ print ' ';
}
- else print ' ';
- print '';
- print ' ';
- print ' ';
- print '';
- print ' ';
- }
- $total = $total + ($objp->qty * $objp->price);
- $i++;
- }
- $db->free($resql);
- }
- else
- {
- dolibarr_print_error($db);
- }
+ // Conditions et modes de réglement
+ print '';
+ print '';
+ print $langs->trans('PaymentConditionsShort');
+ print ' ';
- /*
- * Lignes de remise
- */
-
- // Réductions relatives (Remises-Ristournes-Rabbais)
- /* Une réduction doit s'appliquer obligatoirement sur des lignes de factures
- et non globalement
- $var=!$var;
- print '';
- print ' ';
- print ' ';
- print '';
- print $langs->trans('CustomerRelativeDiscount');
- if ($commande->brouillon) print ' ('.($soc->remise_client?$langs->trans("CompanyHasRelativeDiscount",$soc->remise_client):$langs->trans("CompanyHasNoRelativeDiscount")).') ';
- print ' ';
- print ' ';
- print ' ';
- print ' ';
- print '';
- if ($_GET['action'] == 'editrelativediscount')
- {
- print ' %';
- }
- else
- {
- print $commande->remise_percent?$commande->remise_percent.'%':' ';
- }
- print ' ';
- print '';
- if ($_GET['action'] != 'editrelativediscount') print $commande->remise_percent?'-'.price($commande->remise_percent*$total/100):$langs->trans("DiscountNone");
- else print ' ';
- print ' ';
- if ($_GET['action'] != 'editrelativediscount')
- {
- if ($commande->brouillon && $user->rights->facture->creer)
- {
- print 'id.'">'.img_edit($langs->trans('SetRelativeDiscount'),1).' ';
- }
- else
- {
- print ' ';
- }
- if ($commande->brouillon && $user->rights->facture->creer && $commande->remise_percent)
- {
- print 'id.'&action=setremisepercent&rowid='.$objp->rowid.'">';
- print img_delete();
- print ' ';
- }
- else
- {
- print ' ';
- }
- print ' ';
- }
- else
- {
- print ' ';
- }
- print ' ';
- print ' ';
- */
-
- // Remise absolue
- /* Les remises absolues doivent s'appliquer par ajout de lignes spécialisées
- $var=!$var;
- print '';
- print ' ';
- print ' ';
- print '';
- print $langs->trans('CustomerAbsoluteDiscount');
- if ($commande->brouillon) print ' ('.($avoir_en_cours?$langs->trans("CompanyHasAbsoluteDiscount",$avoir_en_cours,$langs->trans("Currency".$conf->monnaie)):$langs->trans("CompanyHasNoAbsoluteDiscount")).') ';
- print ' ';
- print ' ';
- print ' ';
- print ' ';
- print ' ';
- print '';
- if ($_GET['action'] == 'editabsolutediscount')
- {
- print '- ';
- }
- else
- {
- print $commande->remise_absolue?'-'.price($commande->remise_absolue):$langs->trans("DiscountNone");
- }
- print ' ';
- if ($_GET['action'] != 'editabsolutediscount')
- {
- if ($commande->brouillon && $user->rights->facture->creer)
- {
- print 'id.'">'.img_edit($langs->trans('SetAbsoluteDiscount'),1).' ';
- }
- else
- {
- print ' ';
- }
- if ($commande->brouillon && $user->rights->facture->creer && $commande->remise_absolue)
- {
- print 'id.'&action=setremiseabsolue&rowid='.$objp->rowid.'">';
- print img_delete();
- print ' ';
- }
- else
- {
- print ' ';
- }
- print ' ';
- }
- else
- {
- print ' ';
- }
- print ' ';
- print ' ';
- */
-
- /*
- * Ajouter une ligne
- */
- if ($commande->statut == 0 && $user->rights->commande->creer && $_GET["action"] <> 'editline')
- {
- print '';
- print '';
- print ' '; // ancre
- print $langs->trans('Description').' ';
- print ''.$langs->trans('VAT').' ';
- print ''.$langs->trans('PriceUHT').' ';
- print ''.$langs->trans('Qty').' ';
- print ''.$langs->trans('ReductionShort').' ';
- print ' ';
- print ' ';
- print ' ';
- print ' ';
- print ' ';
-
- // Ajout produit produits/services personalisés
- print '';
- print ' ';
- print ' ';
-
- $var=true;
- print '';
- print ' ';
- print '';
- if($soc->tva_assuj == "0")
- print ' 0';
- else
- print $html->select_tva('tva_tx',$conf->defaulttx,$mysoc,$soc);
- print ' ';
- print ' ';
- print ' ';
- print ' % ';
- print ' ';
- print ' ';
-
- print ' ';
-
- // Ajout de produits/services prédéfinis
- print '';
- print ' ';
- print ' ';
-
- $var=!$var;
- print '';
- print '';
- // multiprix
- if($conf->global->PRODUIT_MULTIPRICES == 1)
- $html->select_produits('','idprod','',$conf->produit->limit_size,$soc->price_level);
- else
- $html->select_produits('','idprod','',$conf->produit->limit_size);
- if (! $conf->use_ajax) print ' ';
- print ' ';
- print ' ';
- print ' ';
- print ' ';
- print ' % ';
- print ' ';
- print ' ';
-
- print ' ';
- }
- print '
';
- print '';
-
- /*
- * Boutons actions
- */
- if ($user->societe_id == 0)
- {
- print '';
-
- // Valid
- if ($commande->statut == 0)
- {
- if ($user->rights->commande->valider)
- {
- print '
'.$langs->trans('Valid').' ';
- }
- }
-
- // Edit
- if ($commande->statut == 1)
- {
- if ($user->rights->commande->creer)
- {
- print '
'.$langs->trans('Edit').' ';
- }
- }
-
- // Build PDF
- if ($user->rights->commande->creer && $commande->statut < 3)
- {
- print '
'.$langs->trans("BuildPDF").' ';
- }
-
- // ReBuild PDF
- if ($user->rights->commande->creer && $commande->statut >= 3)
- {
- print '
'.$langs->trans("RebuildPDF").' ';
- }
-
- // Send
- if ($commande->statut > 0)
- {
- if ($user->rights->commande->envoyer)
- {
- $comref = sanitize_string($commande->ref);
- $file = $conf->commande->dir_output . '/'.$comref.'/'.$comref.'.pdf';
- if (file_exists($file))
+ if ($_GET['action'] != 'editconditions' && $commande->brouillon) print '
id.'">'.img_edit($langs->trans('SetConditions'),1).' ';
+ print '
';
+ print '';
+ if ($_GET['action'] == 'editconditions')
{
- print ''.$langs->trans('SendByMail').' ';
+ $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->cond_reglement_id,'cond_reglement_id');
}
- }
- }
+ else
+ {
+ $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->cond_reglement_id,'none');
+ }
+ print ' ';
+ print '';
+ print '';
+ print ' ';
+ if ($_GET['action'] == 'editmode')
+ {
+ $html->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->mode_reglement_id,'mode_reglement_id');
+ }
+ else
+ {
+ $html->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->mode_reglement_id,'none');
+ }
+ print ' ';
- // Ship
- if ($commande->statut > 0 && $commande->statut < 3 && $user->rights->expedition->creer
- && $commande->getNbOfProductsLines() > 0)
+ // Projet
+ if ($conf->projet->enabled)
+ {
+ $langs->load('projects');
+ print '';
+ print '';
+ print ' ';
+ if ($_GET['action'] == 'classer')
+ {
+ $html->form_project($_SERVER['PHP_SELF'].'?id='.$commande->id, $commande->socid, $commande->projet_id, 'projetid');
+ }
+ else
+ {
+ $html->form_project($_SERVER['PHP_SELF'].'?id='.$commande->id, $commande->socid, $commande->projet_id, 'none');
+ }
+ print ' ';
+ }
+
+ // Lignes de 3 colonnes
+
+ // Total HT
+ print ''.$langs->trans('AmountHT').' ';
+ print ''.price($commande->total_ht).' ';
+ print ''.$langs->trans('Currency'.$conf->monnaie).' ';
+
+ // Total TVA
+ print ''.$langs->trans('AmountVAT').' '.price($commande->total_tva).' ';
+ print ''.$langs->trans('Currency'.$conf->monnaie).' ';
+
+ // Total TTC
+ print ''.$langs->trans('AmountTTC').' '.price($commande->total_ttc).' ';
+ print ''.$langs->trans('Currency'.$conf->monnaie).' ';
+
+ // Statut
+ print ''.$langs->trans('Status').' ';
+ print ''.$commande->getLibStatut(4).' ';
+ print ' ';
+
+ print '
';
+ print "\n";
+
+ /*
+ * Lignes de commandes
+ */
+ $sql = 'SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice, l.info_bits,';
+ $sql.= ' p.label as product, p.ref, p.fk_product_type, p.rowid as prodid, ';
+ $sql.= ' p.description as product_desc';
+ $sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet as l';
+ $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product=p.rowid';
+ $sql.= ' WHERE l.fk_commande = '.$commande->id;
+ $sql.= ' ORDER BY l.rang ASC, l.rowid';
+
+ $resql = $db->query($sql);
+ if ($resql)
+ {
+ $num = $db->num_rows($resql);
+ $i = 0; $total = 0;
+
+ print '';
+ if ($num)
+ {
+ print '';
+ print ''.$langs->trans('Description').' ';
+ print ''.$langs->trans('VAT').' ';
+ print ''.$langs->trans('PriceUHT').' ';
+ print ''.$langs->trans('Qty').' ';
+ print ''.$langs->trans('ReductionShort').' ';
+ print ''.$langs->trans('AmountHT').' ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print " \n";
+ }
+ $var=true;
+ while ($i < $num)
+ {
+ $objp = $db->fetch_object($resql);
+ $var=!$var;
+
+ // Ligne en mode visu
+ if ($_GET['action'] != 'editline' || $_GET['rowid'] != $objp->rowid)
+ {
+ print '';
+ if ($objp->fk_product > 0)
+ {
+ print '';
+ print ' '; // ancre pour retourner sur la ligne
+ print '';
+ if ($objp->fk_product_type) print img_object($langs->trans('ShowService'),'service');
+ else print img_object($langs->trans('ShowProduct'),'product');
+ print ' '.$objp->ref.' - '.nl2br($objp->product);
+ print ($objp->description && $objp->description!=$objp->product)?' '.nl2br($objp->description):'';
+ // \todo Ne faut-il pas rendre $conf->global->PRODUIT_CHANGE_PROD_DESC toujours a on
+ if ($conf->global->PRODUIT_DESC_IN_FORM && !$conf->global->PRODUIT_CHANGE_PROD_DESC)
+ {
+ print ' '.nl2br($objp->product_desc);
+ }
+ print ' ';
+ }
+ else
+ {
+ print '';
+ print ' '; // ancre pour retourner sur la ligne
+ if (($objp->info_bits & 2) == 2)
+ {
+ print '';
+ print img_object($langs->trans("ShowReduc"),'reduc').' '.$langs->trans("Discount");
+ print ' ';
+ if ($objp->description) print ' - '.nl2br($objp->description);
+ }
+ else
+ {
+ print nl2br($objp->description);
+ }
+ print ' ';
+ }
+
+ print ''.$objp->tva_tx.'% ';
+ print ''.price($objp->subprice).' ';
+ print '';
+ if (($objp->info_bits & 2) != 2)
+ {
+ print $objp->qty;
+ }
+ else print ' ';
+ print ' ';
+ if ($objp->remise_percent > 0)
+ {
+ print ''.$objp->remise_percent.'% ';
+ }
+ else
+ {
+ print ' ';
+ }
+ print ''.price($objp->subprice*$objp->qty*(100-$objp->remise_percent)/100).' ';
+
+ // Icone d'edition et suppression
+ if ($commande->statut == 0 && $user->rights->commande->creer)
+ {
+ print 'rowid.'#'.$objp->rowid.'">';
+ print img_edit();
+ print ' ';
+ if ($conf->global->PRODUIT_CONFIRM_DELETE_LINE)
+ {
+ print 'rowid.'">';
+ }
+ else
+ {
+ print ' rowid.'">';
+ }
+ print img_delete();
+ print ' ';
+ print '';
+ if ($i > 0)
+ {
+ print 'id.'&action=up&rowid='.$objp->rowid.'">';
+ print img_up();
+ print ' ';
+ }
+ if ($i < $num-1)
+ {
+ print 'id.'&action=down&rowid='.$objp->rowid.'">';
+ print img_down();
+ print ' ';
+ }
+ print ' ';
+ }
+ else
+ {
+ print ' ';
+ }
+ print ' ';
+ }
+
+ // Ligne en mode update
+ if ($_GET['action'] == 'editline' && $user->rights->commande->creer && $_GET['rowid'] == $objp->rowid)
+ {
+ print 'rowid.'" method="post">';
+ print ' ';
+ print ' ';
+ print ' ';
+ print '';
+ print '';
+ print ' '; // ancre pour retourner sur la ligne
+ if ($objp->fk_product > 0)
+ {
+ print '';
+ if ($objp->fk_product_type) print img_object($langs->trans('ShowService'),'service');
+ else print img_object($langs->trans('ShowProduct'),'product');
+ print ' '.$objp->ref.' ';
+ print ' - '.nl2br($objp->product);
+ print ' ';
+ }
+ // éditeur wysiwyg
+ if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS)
+ {
+ require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php");
+ $doleditor=new DolEditor('eldesc',$objp->description,200,'dolibarr_details');
+ $doleditor->Create();
+ }
+ else
+ {
+ print ''.$objp->description.' ';
+ }
+ print ' ';
+ print '';
+ if($soc->tva_assuj == "0")
+ print ' 0';
+ else
+ print $html->select_tva('tva_tx',$objp->tva_tx,$mysoc,$soc);
+ print ' ';
+ print ' ';
+ print '';
+ if (($objp->info_bits & 2) != 2)
+ {
+ print ' ';
+ }
+ else print ' ';
+ print ' ';
+ print '';
+ if (($objp->info_bits & 2) != 2)
+ {
+ print ' %';
+ }
+ else print ' ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' ';
+ }
+
+ $total = $total + ($objp->qty * $objp->price);
+ $i++;
+ }
+ $db->free($resql);
+ }
+ else
+ {
+ dolibarr_print_error($db);
+ }
+
+ /*
+ * Lignes de remise
+ */
+
+ // Réductions relatives (Remises-Ristournes-Rabbais)
+ /* Une réduction doit s'appliquer obligatoirement sur des lignes de factures
+ et non globalement
+ $var=!$var;
+ print '';
+ print ' ';
+ print ' ';
+ print '';
+ print $langs->trans('CustomerRelativeDiscount');
+ if ($commande->brouillon) print ' ('.($soc->remise_client?$langs->trans("CompanyHasRelativeDiscount",$soc->remise_client):$langs->trans("CompanyHasNoRelativeDiscount")).') ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print '';
+ if ($_GET['action'] == 'editrelativediscount')
+ {
+ print ' %';
+ }
+ else
+ {
+ print $commande->remise_percent?$commande->remise_percent.'%':' ';
+ }
+ print ' ';
+ print '';
+ if ($_GET['action'] != 'editrelativediscount') print $commande->remise_percent?'-'.price($commande->remise_percent*$total/100):$langs->trans("DiscountNone");
+ else print ' ';
+ print ' ';
+ if ($_GET['action'] != 'editrelativediscount')
+ {
+ if ($commande->brouillon && $user->rights->facture->creer)
+ {
+ print 'id.'">'.img_edit($langs->trans('SetRelativeDiscount'),1).' ';
+ }
+ else
+ {
+ print ' ';
+ }
+ if ($commande->brouillon && $user->rights->facture->creer && $commande->remise_percent)
+ {
+ print 'id.'&action=setremisepercent&rowid='.$objp->rowid.'">';
+ print img_delete();
+ print ' ';
+ }
+ else
+ {
+ print ' ';
+ }
+ print ' ';
+ }
+ else
+ {
+ print ' ';
+ }
+ print ' ';
+ print ' ';
+ */
+
+ // Remise absolue
+ /* Les remises absolues doivent s'appliquer par ajout de lignes spécialisées
+ $var=!$var;
+ print '';
+ print ' ';
+ print ' ';
+ print '';
+ print $langs->trans('CustomerAbsoluteDiscount');
+ if ($commande->brouillon) print ' ('.($avoir_en_cours?$langs->trans("CompanyHasAbsoluteDiscount",$avoir_en_cours,$langs->trans("Currency".$conf->monnaie)):$langs->trans("CompanyHasNoAbsoluteDiscount")).') ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print '';
+ if ($_GET['action'] == 'editabsolutediscount')
+ {
+ print '- ';
+ }
+ else
+ {
+ print $commande->remise_absolue?'-'.price($commande->remise_absolue):$langs->trans("DiscountNone");
+ }
+ print ' ';
+ if ($_GET['action'] != 'editabsolutediscount')
+ {
+ if ($commande->brouillon && $user->rights->facture->creer)
+ {
+ print 'id.'">'.img_edit($langs->trans('SetAbsoluteDiscount'),1).' ';
+ }
+ else
+ {
+ print ' ';
+ }
+ if ($commande->brouillon && $user->rights->facture->creer && $commande->remise_absolue)
+ {
+ print 'id.'&action=setremiseabsolue&rowid='.$objp->rowid.'">';
+ print img_delete();
+ print ' ';
+ }
+ else
+ {
+ print ' ';
+ }
+ print ' ';
+ }
+ else
+ {
+ print ' ';
+ }
+ print ' ';
+ print ' ';
+ */
+
+ /*
+ * Ajouter une ligne
+ */
+ if ($commande->statut == 0 && $user->rights->commande->creer && $_GET["action"] <> 'editline')
+ {
+ print '';
+ print '';
+ print ' '; // ancre
+ print $langs->trans('Description').' ';
+ print ''.$langs->trans('VAT').' ';
+ print ''.$langs->trans('PriceUHT').' ';
+ print ''.$langs->trans('Qty').' ';
+ print ''.$langs->trans('ReductionShort').' ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' ';
+
+ // Ajout produit produits/services personalisés
+ print '';
+ print ' ';
+ print ' ';
+
+ $var=true;
+ print '';
+ print ' ';
+ print '';
+ if($soc->tva_assuj == "0")
+ print ' 0';
+ else
+ print $html->select_tva('tva_tx',$conf->defaulttx,$mysoc,$soc);
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' % ';
+ print ' ';
+ print ' ';
+
+ print ' ';
+
+ // Ajout de produits/services prédéfinis
+ print '';
+ print ' ';
+ print ' ';
+
+ $var=!$var;
+ print '';
+ print '';
+ // multiprix
+ if($conf->global->PRODUIT_MULTIPRICES == 1)
+ $html->select_produits('','idprod','',$conf->produit->limit_size,$soc->price_level);
+ else
+ $html->select_produits('','idprod','',$conf->produit->limit_size);
+ if (! $conf->use_ajax) print ' ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' % ';
+ print ' ';
+ print ' ';
+
+ print ' ';
+ }
+ print '
';
+ print '';
+
+ /*
+ * Boutons actions
+ */
+ if ($user->societe_id == 0)
+ {
+ print '';
+
+ // Valid
+ if ($commande->statut == 0)
+ {
+ if ($user->rights->commande->valider)
+ {
+ print '
'.$langs->trans('Valid').' ';
+ }
+ }
+
+ // Edit
+ if ($commande->statut == 1)
+ {
+ if ($user->rights->commande->creer)
+ {
+ print '
'.$langs->trans('Edit').' ';
+ }
+ }
+
+ // Build PDF
+ if ($user->rights->commande->creer && $commande->statut < 3)
+ {
+ print '
'.$langs->trans("BuildPDF").' ';
+ }
+
+ // ReBuild PDF
+ if ($user->rights->commande->creer && $commande->statut >= 3)
+ {
+ print '
'.$langs->trans("RebuildPDF").' ';
+ }
+
+ // Send
+ if ($commande->statut > 0)
+ {
+ if ($user->rights->commande->envoyer)
+ {
+ $comref = sanitize_string($commande->ref);
+ $file = $conf->commande->dir_output . '/'.$comref.'/'.$comref.'.pdf';
+ if (file_exists($file))
+ {
+ print '
'.$langs->trans('SendByMail').' ';
+ }
+ }
+ }
+
+ // Ship
+ if ($commande->statut > 0 && $commande->statut < 3 && $user->rights->expedition->creer
+ && $commande->getNbOfProductsLines() > 0)
+ {
+
+ // Chargement des permissions
+ $error = $user->load_entrepots();
+ if (sizeof($user->entrepots) === 1)
+ {
+ print '
entrepots[0]['id'].'">';
+ print $langs->trans('ShipProduct').' ';
+
+ }
+ else
+ {
+ print '
'.$langs->trans('ShipProduct').' ';
+ }
+ }
+
+ if ($commande->statut == 1 || $commande->statut == 2)
+ {
+ if ($user->rights->commande->cloturer)
+ {
+ print '
'.$langs->trans('Close').' ';
+ }
+ }
+
+ if ($commande->statut == 1)
+ {
+ $nb_expedition = $commande->nb_expedition();
+ if ($user->rights->commande->annuler && $nb_expedition == 0)
+ {
+ print '
'.$langs->trans('CancelOrder').' ';
+ }
+ }
+
+ if ($commande->statut == 0 && $user->rights->commande->supprimer)
+ {
+ print '
'.$langs->trans('Delete').' ';
+ }
+
+ print '
';
+ }
+ print ' ';
+
+
+ print '';
+ print ' '; // ancre
+
+ /*
+ * Documents générés
+ *
+ */
+ $comref = sanitize_string($commande->ref);
+ $file = $conf->commande->dir_output . '/' . $comref . '/' . $comref . '.pdf';
+ $relativepath = $comref.'/'.$comref.'.pdf';
+ $filedir = $conf->commande->dir_output . '/' . $comref;
+ $urlsource=$_SERVER["PHP_SELF"]."?id=".$commande->id;
+ $genallowed=$user->rights->commande->creer;
+ $delallowed=$user->rights->commande->supprimer;
+
+ $somethingshown=$html->show_documents('commande',$comref,$filedir,$urlsource,$genallowed,$delallowed,$commande->modelpdf);
+
+ /*
+ * Liste des factures
+ */
+ $sql = 'SELECT f.rowid,f.facnumber, f.total_ttc, '.$db->pdate('f.datef').' as df';
+ $sql .= ' FROM '.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'co_fa as cf';
+ $sql .= ' WHERE f.rowid = cf.fk_facture AND cf.fk_commande = '. $commande->id;
+
+ $result = $db->query($sql);
+ if ($result)
+ {
+ $num = $db->num_rows($result);
+ if ($num)
+ {
+ print ' ';
+ print_titre($langs->trans('RelatedBills'));
+ $i = 0; $total = 0;
+ print '';
+ print ''.$langs->trans('Ref')." ";
+ print ''.$langs->trans('Date').' ';
+ print ''.$langs->trans('Price').' ';
+ print ' ';
+
+ $var=True;
+ while ($i < $num)
+ {
+ $objp = $db->fetch_object($result);
+ $var=!$var;
+ print '';
+ print ''.img_object($langs->trans('ShowBill'),'bill').' '.$objp->facnumber.' ';
+ print ''.dolibarr_print_date($objp->df).' ';
+ print ''.$objp->total_ttc.' ';
+ $i++;
+ }
+ print '
';
+ }
+ }
+ else
+ {
+ dolibarr_print_error($db);
+ }
+ print ' ';
+
+ /*
+ * Liste des actions propres à la commande
+ */
+ $sql = 'SELECT id, '.$db->pdate('a.datea'). ' as da, label, note, fk_user_author' ;
+ $sql .= ' FROM '.MAIN_DB_PREFIX.'actioncomm as a';
+ $sql .= ' WHERE a.fk_commande = '.$commande->id ;
+ if ($socid) $sql .= ' AND a.fk_soc = '.$socid;
+ $resql = $db->query($sql);
+ if ($resql)
+ {
+ $num = $db->num_rows($resql);
+ if ($num)
+ {
+ //print ' ';
+ print_titre($langs->trans('ActionsOnOrder'));
+ $i = 0;
+ $total = 0;
+ $var=true;
+
+ print '';
+ print ''.$langs->trans('Ref').' '.$langs->trans('Date').' '.$langs->trans('Action').' '.$langs->trans('By').' ';
+ print "\n";
+
+ while ($i < $num)
+ {
+ $objp = $db->fetch_object($resql);
+ $var=!$var;
+ print '';
+ print ''.img_object($langs->trans('ShowTask'),'task').' '.$objp->id.' ';
+ print ''.dolibarr_print_date($objp->da)." \n";
+ print ''.stripslashes($objp->label).' ';
+ $authoract = new User($db);
+ $authoract->id = $objp->fk_user_author;
+ $authoract->fetch('');
+ print ''.$authoract->code.' ';
+ print " \n";
+ $i++;
+ }
+ print '
';
+ }
+ }
+ else
+ {
+ dolibarr_print_error($db);
+ }
+
+ print '
';
+
+
+
+ /*
+ * Action presend
+ *
+ */
+ if ($_GET['action'] == 'presend')
+ {
+ $orderref = sanitize_string($commande->ref);
+ $file = $conf->commande->dir_output . '/' . $orderref . '/' . $orderref . '.pdf';
+
+ // Construit PDF si non existant
+ if (! is_readable($file))
+ {
+ if ($_REQUEST['lang_id'])
+ {
+ $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
+ $outputlangs->setDefaultLang($_REQUEST['lang_id']);
+ }
+ $result=commande_pdf_create($db, $_REQUEST['id'], '', $_REQUEST['model'], $outputlangs);
+ if ($result <= 0)
+ {
+ dolibarr_print_error($db,$result);
+ exit;
+ }
+ }
+
+ print ' ';
+ print_titre($langs->trans('SendOrderByMail'));
+
+ $soc = new Societe($db);
+ $soc->fetch($commande->socid);
+
+ $liste[0]=" ";
+ foreach ($soc->thirdparty_and_contact_email_array() as $key=>$value)
+ {
+ $liste[$key]=$value;
+ }
+
+ // Créé l'objet formulaire mail
+ include_once('../html.formmail.class.php');
+ $formmail = new FormMail($db);
+ $formmail->fromname = $user->fullname;
+ $formmail->frommail = $user->email;
+ $formmail->withfrom=1;
+ $formmail->withto=$liste;
+ $formmail->withcc=1;
+ $formmail->withtopic=$langs->trans('SendOrderRef','__ORDERREF__');
+ $formmail->withfile=1;
+ $formmail->withbody=1;
+ $formmail->withdeliveryreceipt=1;
+ // Tableau des substitutions
+ $formmail->substit['__ORDERREF__']=$commande->ref;
+ // Tableau des paramètres complémentaires
+ $formmail->param['action']='send';
+ $formmail->param['models']='order_send';
+ $formmail->param['orderid']=$commande->id;
+ $formmail->param['returnurl']=DOL_URL_ROOT.'/commande/fiche.php?id='.$commande->id;
+
+ $formmail->show_form();
+
+ print ' ';
+ }
+ }
+ else
{
-
- // Chargement des permissions
- $error = $user->load_entrepots();
- if (sizeof($user->entrepots) === 1)
- {
- print 'entrepots[0]['id'].'">';
- print $langs->trans('ShipProduct').' ';
-
- }
- else
- {
- print ''.$langs->trans('ShipProduct').' ';
- }
+ // Commande non trouvée
+ dolibarr_print_error($db);
}
-
- if ($commande->statut == 1 || $commande->statut == 2)
- {
- if ($user->rights->commande->cloturer)
- {
- print ''.$langs->trans('Close').' ';
- }
- }
-
- if ($commande->statut == 1)
- {
- $nb_expedition = $commande->nb_expedition();
- if ($user->rights->commande->annuler && $nb_expedition == 0)
- {
- print ''.$langs->trans('CancelOrder').' ';
- }
- }
-
- if ($commande->statut == 0 && $user->rights->commande->supprimer)
- {
- print ''.$langs->trans('Delete').' ';
- }
-
- print '';
- }
- print ' ';
-
-
- print '';
- print ' '; // ancre
-
- /*
- * Documents générés
- *
- */
- $comref = sanitize_string($commande->ref);
- $file = $conf->commande->dir_output . '/' . $comref . '/' . $comref . '.pdf';
- $relativepath = $comref.'/'.$comref.'.pdf';
- $filedir = $conf->commande->dir_output . '/' . $comref;
- $urlsource=$_SERVER["PHP_SELF"]."?id=".$commande->id;
- $genallowed=$user->rights->commande->creer;
- $delallowed=$user->rights->commande->supprimer;
-
- $somethingshown=$html->show_documents('commande',$comref,$filedir,$urlsource,$genallowed,$delallowed,$commande->modelpdf);
-
- /*
- * Liste des factures
- */
- $sql = 'SELECT f.rowid,f.facnumber, f.total_ttc, '.$db->pdate('f.datef').' as df';
- $sql .= ' FROM '.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'co_fa as cf';
- $sql .= ' WHERE f.rowid = cf.fk_facture AND cf.fk_commande = '. $commande->id;
-
- $result = $db->query($sql);
- if ($result)
- {
- $num = $db->num_rows($result);
- if ($num)
- {
- print ' ';
- print_titre($langs->trans('RelatedBills'));
- $i = 0; $total = 0;
- print '';
- print ''.$langs->trans('Ref')." ";
- print ''.$langs->trans('Date').' ';
- print ''.$langs->trans('Price').' ';
- print ' ';
-
- $var=True;
- while ($i < $num)
- {
- $objp = $db->fetch_object($result);
- $var=!$var;
- print '';
- print ''.img_object($langs->trans('ShowBill'),'bill').' '.$objp->facnumber.' ';
- print ''.dolibarr_print_date($objp->df).' ';
- print ''.$objp->total_ttc.' ';
- $i++;
- }
- print '
';
- }
- }
- else
- {
- dolibarr_print_error($db);
- }
- print ' ';
-
- /*
- * Liste des actions propres à la commande
- */
- $sql = 'SELECT id, '.$db->pdate('a.datea'). ' as da, label, note, fk_user_author' ;
- $sql .= ' FROM '.MAIN_DB_PREFIX.'actioncomm as a';
- $sql .= ' WHERE a.fk_commande = '.$commande->id ;
- if ($socid) $sql .= ' AND a.fk_soc = '.$socid;
- $resql = $db->query($sql);
- if ($resql)
- {
- $num = $db->num_rows($resql);
- if ($num)
- {
- //print ' ';
- print_titre($langs->trans('ActionsOnOrder'));
- $i = 0;
- $total = 0;
- $var=true;
-
- print '';
- print ''.$langs->trans('Ref').' '.$langs->trans('Date').' '.$langs->trans('Action').' '.$langs->trans('By').' ';
- print "\n";
-
- while ($i < $num)
- {
- $objp = $db->fetch_object($resql);
- $var=!$var;
- print '';
- print ''.img_object($langs->trans('ShowTask'),'task').' '.$objp->id.' ';
- print ''.dolibarr_print_date($objp->da)." \n";
- print ''.stripslashes($objp->label).' ';
- $authoract = new User($db);
- $authoract->id = $objp->fk_user_author;
- $authoract->fetch('');
- print ''.$authoract->code.' ';
- print " \n";
- $i++;
- }
- print '
';
- }
- }
- else
- {
- dolibarr_print_error($db);
- }
-
- print '
';
-
-
-
- /*
- * Action presend
- *
- */
- if ($_GET['action'] == 'presend')
- {
- $orderref = sanitize_string($commande->ref);
- $file = $conf->commande->dir_output . '/' . $orderref . '/' . $orderref . '.pdf';
-
- // Construit PDF si non existant
- if (! is_readable($file))
- {
- if ($_REQUEST['lang_id'])
- {
- $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
- $outputlangs->setDefaultLang($_REQUEST['lang_id']);
- }
- $result=commande_pdf_create($db, $_REQUEST['id'], '', $_REQUEST['model'], $outputlangs);
- if ($result <= 0)
- {
- dolibarr_print_error($db,$result);
- exit;
- }
- }
-
- print ' ';
- print_titre($langs->trans('SendOrderByMail'));
-
- $soc = new Societe($db);
- $soc->fetch($commande->socid);
-
- $liste[0]=" ";
- foreach ($soc->thirdparty_and_contact_email_array() as $key=>$value)
- {
- $liste[$key]=$value;
- }
-
- // Créé l'objet formulaire mail
- include_once('../html.formmail.class.php');
- $formmail = new FormMail($db);
- $formmail->fromname = $user->fullname;
- $formmail->frommail = $user->email;
- $formmail->withfrom=1;
- $formmail->withto=$liste;
- $formmail->withcc=1;
- $formmail->withtopic=$langs->trans('SendOrderRef','__ORDERREF__');
- $formmail->withfile=1;
- $formmail->withbody=1;
- $formmail->withdeliveryreceipt=1;
- // Tableau des substitutions
- $formmail->substit['__ORDERREF__']=$commande->ref;
- // Tableau des paramètres complémentaires
- $formmail->param['action']='send';
- $formmail->param['models']='order_send';
- $formmail->param['orderid']=$commande->id;
- $formmail->param['returnurl']=DOL_URL_ROOT.'/commande/fiche.php?id='.$commande->id;
-
- $formmail->show_form();
-
- print ' ';
- }
}
- else
- {
- // Commande non trouvée
- dolibarr_print_error($db);
- }
- }
}
$db->close();
diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php
index 8bc33516764..c8c38733ac1 100644
--- a/htdocs/fourn/commande/fiche.php
+++ b/htdocs/fourn/commande/fiche.php
@@ -1,39 +1,44 @@
- * Copyright (C) 2004-2006 Laurent Destailleur
- * Copyright (C) 2005 Eric Seigne
+/* Copyright (C) 2004-2005 Rodolphe Quiedeville
+ * Copyright (C) 2004-2006 Laurent Destailleur
+ * Copyright (C) 2005 Eric Seigne
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful,
+ * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*/
/**
- \file htdocs/fourn/commande/fiche.php
- \ingroup commande
- \brief Fiche commande
- \version $Revision$
+ \file htdocs/fourn/commande/fiche.php
+ \ingroup commande
+ \brief Fiche commande
+ \version $Revision$
*/
-require("./pre.inc.php");
-require_once(DOL_DOCUMENT_ROOT."/project.class.php");
-require_once(DOL_DOCUMENT_ROOT."/propal.class.php");
-require_once(DOL_DOCUMENT_ROOT ."/fourn/commande/modules/modules_commandefournisseur.php");
+require('./pre.inc.php');
+require_once(DOL_DOCUMENT_ROOT.'/fourn/commande/modules/modules_commandefournisseur.php');
+if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT.'/project.class.php');
-$langs->load("orders");
+$langs->load('orders');
+$langs->load('sendings');
+$langs->load('companies');
+$langs->load('bills');
+$langs->load('propal');
+$langs->load('deliveries');
+$langs->load('products');
$user->getrights("fournisseur");
@@ -41,12 +46,19 @@ if (!$user->rights->fournisseur->commande->lire) accessforbidden();
$comclientid = isset($_GET["comid"])?$_GET["comid"]:'';
-// Sécurité accés client
+// Sécurité accés client
$socid=0;
-if ($user->societe_id > 0)
+if ($user->societe_id > 0)
{
- $action = '';
- $socid = $user->societe_id;
+ $action = '';
+ $socid = $user->societe_id;
+}
+
+// Récupération de l'id de projet
+$projetid = 0;
+if ($_GET["projetid"])
+{
+ $projetid = $_GET["projetid"];
}
$mesg='';
@@ -54,702 +66,1143 @@ $mesg='';
/*
* Actions
- */
-if ($_POST["action"] == 'classin')
+ */
+
+// Categorisation dans projet
+if ($_POST['action'] == 'classin' && $user->rights->fournisseur->commande->creer)
{
- $commande = new CommandeFournisseur($db);
+ $commande = new CommandeFournisseur($db);
$commande->fetch($_GET["id"]);
$commande->classin($_POST["projetid"]);
}
-if ($_POST["action"] == 'setremise' && $user->rights->commande->creer)
+if ($_REQUEST['action'] == 'setremisepercent' && $user->rights->fournisseur->commande->creer)
{
- $commande = new CommandeFournisseur($db);
- $commande->fetch($id);
-
- $commande->set_remise($user, $_POST["remise"]);
-}
+ $commande = new CommandeFournisseur($db);
+ $commande->fetch($_REQUEST['id']);
+ $result = $commande->set_remise($user, $_POST['remise_percent']);
+ $_GET['id']=$_REQUEST['id'];
+}
/*
- *
+ * Ajout d'une ligne produit dans la commande
*/
-if ($_POST["action"] == 'addligne' && $user->rights->fournisseur->commande->creer)
+if ($_POST['action'] == 'addligne' && $user->rights->fournisseur->commande->creer)
{
- $comf = new CommandeFournisseur($db);
- $comf->fetch($_GET["id"]);
+ if ($_POST['qty'] && (($_POST['pu'] && $_POST['desc']) || $_POST['idprod']))
+ {
+ $commande = new CommandeFournisseur($db);
+ $ret=$commande->fetch($_POST["id"]);
- if ($_POST["p_idprod"] > 0)
- {
- $result = $comf->addline($_POST["desc"],
- $_POST["pu"],
- $_POST["pqty"],
- $_POST["tva_tx"],
- $_POST["p_idprod"],
- $_POST["premise"]);
- }
- else
- {
- $result = $comf->addline($_POST["desc"],
- $_POST["pu"],
- $_POST["qty"],
- $_POST["tva_tx"],
- 0,
- $_POST["remise_percent"]);
- }
+ $soc = new Societe($db, $commande->socid);
+ $soc->fetch($commande->socid);
+ if ($ret < 0)
+ {
+ dolibarr_print_error($db,$commande->error);
+ exit;
+ }
- if ($result >= 0)
- {
- Header("Location: fiche.php?id=".$_GET["id"]);
- exit;
- }
- else
- {
- $mesg=''.$comf->error.'
';
- }
+ // Ecrase $pu par celui du produit
+ // Ecrase $desc par celui du produit
+ // Ecrase $txtva par celui du produit
+ if ($_POST["idprod"] > 0)
+ {
+ $prod = new Product($db, $_POST['idprod']);
+ $prod->fetch($_POST['idprod']);
+
+ $libelle = $prod->libelle;
+
+ // La description de la ligne est celle saisie ou
+ // celle du produit si (non saisi + PRODUIT_CHANGE_PROD_DESC défini)
+ // \todo Ne faut-il pas rendre $conf->global->PRODUIT_CHANGE_PROD_DESC toujours a on
+ $desc=$_POST['np_desc'];
+ if (! $desc && $conf->global->PRODUIT_CHANGE_PROD_DESC)
+ {
+ $desc = $prod->description;
+ }
+
+ $tva_tx = get_default_tva($soc,$mysoc,$prod->tva_tx);
+ }
+ else
+ {
+ $pu=$_POST['pu'];
+ $tva_tx=$_POST['tva_tx'];
+ $desc=$_POST['desc'];
+ }
+
+ $result=$commande->addline(
+ $desc,
+ $pu,
+ $_POST['qty'],
+ $tva_tx,
+ $_POST['idprod'],
+ $_POST['remise_percent']
+ );
+
+ if ($result > 0)
+ {
+ if ($_REQUEST['lang_id'])
+ {
+ $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
+ $outputlangs->setDefaultLang($_REQUEST['lang_id']);
+ }
+ commande_supplier_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs);
+ }
+ else
+ {
+ $mesg=''.$commande->error.'
';
+ }
+ }
}
-if ($_POST["action"] == 'updateligne' && $user->rights->commande->creer && $_POST['save'] == $langs->trans('Save'))
+/*
+ * Mise à jour d'une ligne dans la propale
+ */
+if ($_POST['action'] == 'updateligne' && $user->rights->fournisseur->commande->creer && $_POST['save'] == $langs->trans('Save'))
{
- $commande = new CommandeFournisseur($db,"",$_POST["id"]);
- $commande->fetch($_POST["id"]);
+ $commande = new CommandeFournisseur($db,"",$_POST["id"]);
+ if ($commande->fetch($_POST['id']) < 0) dolibarr_print_error($db);
- $result = $commande->updateline($_POST["elrowid"],
- $_POST["eldesc"],
- $_POST["elprice"],
- $_POST["elqty"],
- $_POST["elremise_percent"],
- $_POST["tva_tx"]
- );
+ $result = $commande->updateline($_POST['elrowid'],
+ $_POST['desc'],
+ $_POST['pu'],
+ $_POST['qty'],
+ $_POST['remise_percent'],
+ $_POST['tva_tx']
+ );
+ if ($result >= 0)
+ {
+ if ($_REQUEST['lang_id'])
+ {
+ $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
+ $outputlangs->setDefaultLang($_REQUEST['lang_id']);
+ }
+ commande_supplier_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs);
+ }
+ else
+ {
+ dolibarr_print_error($db,$commande->error);
+ exit;
+ }
+
+ $_GET['id']=$_POST['id']; // Pour réaffichage de la fiche en cours d'édition
}
-if ($_GET["action"] == 'deleteline' && $user->rights->fournisseur->commande->creer)
+if ($_POST['action'] == 'updateligne' && $user->rights->fournisseur->commande->creer && $_POST['cancel'] == $langs->trans('Cancel'))
{
- $comf = new CommandeFournisseur($db);
- $comf->fetch($_GET["id"]);
- $result = $comf->delete_line($_GET["lineid"]);
+ Header('Location: fiche.php?id='.$_POST['id']); // Pour réaffichage de la fiche en cours d'édition
+ exit;
}
-if ($_POST["action"] == 'confirm_valid' && $_POST["confirm"] == 'yes' && $user->rights->fournisseur->commande->valider)
-{
- $commande = new CommandeFournisseur($db);
- $commande->fetch($_GET["id"]);
- $soc = new Societe($db);
- $soc->fetch($commande->socid);
- $result = $commande->valid($user);
- if ($result >= 0)
- {
- Header("Location: fiche.php?id=".$_GET["id"]);
- exit;
- }
-}
-
-if ($_POST["action"] == 'confirm_approve' && $_POST["confirm"] == 'yes' && $user->rights->fournisseur->commande->approuver)
-{
- $commande = new CommandeFournisseur($db);
- $commande->fetch($_GET["id"]);
- $result = $commande->approve($user);
- Header("Location: fiche.php?id=".$_GET["id"]);
- exit;
-}
-
-if ($_POST["action"] == 'confirm_refuse' && $_POST["confirm"] == 'yes' && $user->rights->fournisseur->commande->approuver)
-{
- $commande = new CommandeFournisseur($db);
- $commande->fetch($_GET["id"]);
- $result = $commande->refuse($user);
- Header("Location: fiche.php?id=".$_GET["id"]);
-}
-
-if ($_POST["action"] == 'confirm_commande' && $_POST["confirm"] == 'yes' && $user->rights->fournisseur->commande->commander)
-{
- $commande = new CommandeFournisseur($db);
- $commande->fetch($_GET["id"]);
- $result = $commande->commande($user, $_GET["datecommande"], $_GET["methode"]);
- Header("Location: fiche.php?id=".$_GET["id"]);
- exit;
-}
-
-
-if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes' && $user->rights->fournisseur->commande->creer )
-{
- $commande = new CommandeFournisseur($db);
- $commande->id = $_GET["id"];
- $commande->delete();
- Header("Location: index.php");
- exit;
-}
-
-if ($_POST["action"] == 'livraison' && $user->rights->fournisseur->commande->receptionner)
-{
- $commande = new CommandeFournisseur($db);
- $commande->fetch($_GET["id"]);
-
- $date_liv = mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]);
-
- $result = $commande->Livraison($user, $date_liv, $_POST["type"]);
- Header("Location: fiche.php?id=".$_GET["id"]);
- exit;
-}
-
-
-if ($_POST["action"] == 'confirm_cancel' && $_POST["confirm"] == yes && $user->rights->fournisseur->commande->annuler)
-{
- $commande = new CommandeFournisseur($db);
- $commande->fetch($_GET["id"]);
- $result = $commande->cancel($user);
- Header("Location: fiche.php?id=".$_GET["id"]);
- exit;
-}
-
- /*
- * Generation de la commande
- * définit dans /fourn/commande/modules/modules_commandefournisseur.php
- */
-if ($_POST['action'] == 'builddoc')
+if ($_GET['action'] == 'deleteline' && $user->rights->fournisseur->commande->creer)
{
+ $commande = new CommandeFournisseur($db);
+ $commande->fetch($_GET['id']);
+ $result = $commande->delete_line($_GET['lineid']);
if ($_REQUEST['lang_id'])
{
$outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
$outputlangs->setDefaultLang($_REQUEST['lang_id']);
}
- commande_supplier_pdf_create($db, $_GET['id'],$_POST['model'],$outputlangs);
+ commande_supplier_pdf_create($db, $_GET['id'], $commande->modelpdf, $outputlangs);
+ Header('Location: fiche.php?id='.$_GET['id']);
+ exit;
}
-if($_GET['action'] == 'builddoc')
+
+if ($_POST['action'] == 'confirm_valid' && $_POST['confirm'] == 'yes' && $user->rights->fournisseur->commande->valider)
+{
+ $commande = new CommandeFournisseur($db);
+ $commande->fetch($_GET['id']);
+ $soc = new Societe($db);
+ $soc->fetch($commande->socid);
+ $result = $commande->valid($user);
+ if ($result >= 0)
+ {
+ Header("Location: fiche.php?id=".$_GET["id"]);
+ exit;
+ }
+}
+
+if ($_POST['action'] == 'confirm_approve' && $_POST["confirm"] == 'yes' && $user->rights->fournisseur->commande->approuver)
+{
+ $commande = new CommandeFournisseur($db);
+ $commande->fetch($_GET['id']);
+ $result = $commande->approve($user);
+ if ($result >= 0)
+ {
+ Header("Location: fiche.php?id=".$_GET["id"]);
+ exit;
+ }
+}
+
+if ($_POST['action'] == 'confirm_refuse' && $_POST['confirm'] == 'yes' && $user->rights->fournisseur->commande->approuver)
{
$commande = new CommandeFournisseur($db);
$commande->fetch($_GET['id']);
+ $result = $commande->refuse($user);
+ if ($result >= 0)
+ {
+ Header("Location: fiche.php?id=".$_GET["id"]);
+ exit;
+ }
+}
+
+if ($_POST['action'] == 'confirm_commande' && $_POST['confirm'] == 'yes' && $user->rights->fournisseur->commande->commander)
+{
+ $commande = new CommandeFournisseur($db);
+ $commande->fetch($_GET["id"]);
+ $result = $commande->commande($user, $_GET["datecommande"], $_GET["methode"]);
+ Header("Location: fiche.php?id=".$_GET["id"]);
+ exit;
+}
+
+
+if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes' && $user->rights->fournisseur->commande->supprimer)
+{
+ if ($user->rights->commande->supprimer )
+ {
+ $commande = new CommandeFournisseur($db);
+ $commande->id = $_GET['id'];
+ $commande->delete();
+ Header('Location: index.php');
+ exit;
+ }
+}
+
+if ($_POST["action"] == 'livraison' && $user->rights->fournisseur->commande->receptionner)
+{
+ $commande = new CommandeFournisseur($db);
+ $commande->fetch($_GET["id"]);
+
+ $date_liv = mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]);
+
+ $result = $commande->Livraison($user, $date_liv, $_POST["type"]);
+ Header("Location: fiche.php?id=".$_GET["id"]);
+ exit;
+}
+
+
+if ($_POST["action"] == 'confirm_cancel' && $_POST["confirm"] == yes && $user->rights->fournisseur->commande->annuler)
+{
+ $commande = new CommandeFournisseur($db);
+ $commande->fetch($_GET["id"]);
+ $result = $commande->cancel($user);
+ Header("Location: fiche.php?id=".$_GET["id"]);
+ exit;
+}
+
+/*
+ * Ordonnancement des lignes
+ */
+
+if ($_GET['action'] == 'up' && $user->rights->fournisseur->commande->creer)
+{
+ $commande = new CommandeFournisseur($db,'',$_GET['id']);
+ $commande->fetch($_GET['id']);
+ $commande->line_up($_GET['rowid']);
if ($_REQUEST['lang_id'])
{
$outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
$outputlangs->setDefaultLang($_REQUEST['lang_id']);
}
- commande_supplier_pdf_create($db, $_GET['id'],$commande->modelpdf,$outputlangs);
+ commande_supplier_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs);
+ Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$_GET["id"].'#'.$_GET['rowid']);
+ exit;
}
+if ($_GET['action'] == 'down' && $user->rights->fournisseur->commande->creer)
+{
+ $commande = new CommandeFournisseur($db,'',$_GET['id']);
+ $commande->fetch($_GET['id']);
+ $commande->line_down($_GET['rowid']);
+ if ($_REQUEST['lang_id'])
+ {
+ $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
+ $outputlangs->setDefaultLang($_REQUEST['lang_id']);
+ }
+ commande_supplier_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs);
+ Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$_GET["id"].'#'.$_GET['rowid']);
+ exit;
+}
+
+
+if ($_REQUEST['action'] == 'builddoc') // En get ou en post
+{
+ /*
+ * Generation de la commande
+ * définit dans /includes/modules/commande/modules_commande.php
+ */
+
+ // Sauvegarde le dernier modèle choisi pour générer un document
+ $commande = new CommandeFournisseur($db, 0, $_REQUEST['id']);
+ $commande->fetch($_REQUEST['id']);
+ if ($_REQUEST['model'])
+ {
+ $commande->set_pdf_model($user, $_REQUEST['model']);
+ }
+
+ if ($_REQUEST['lang_id'])
+ {
+ $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
+ $outputlangs->setDefaultLang($_REQUEST['lang_id']);
+ }
+ $result=commande_supplier_pdf_create($db, $commande->id,$commande->modelpdf,$outputlangs);
+ if ($result <= 0)
+ {
+ dolibarr_print_error($db,$result);
+ exit;
+ }
+ else
+ {
+ Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$commande->id.'#builddoc');
+ exit;
+ }
+}
+
+// Efface les fichiers
+if ($action=='remove_file')
+{
+ $commande = new CommandeFournisseur($db);
+
+ if ($commande->fetch($id))
+ {
+ $upload_dir = $conf->commande->dir_output . "/";
+ $file = $upload_dir . '/' . urldecode($_GET['file']);
+ dol_delete_file($file);
+ $mesg = ''.$langs->trans("FileWasRemoved").'
';
+ }
+}
+
+
/*
- * Créé une commande
+ * Créé une commande
*/
-if ($_GET["action"] == 'create')
+if ($_GET["action"] == 'create')
{
- $fourn = new Fournisseur($db);
- $fourn->fetch($_GET["socid"]);
- $commande->modelpdf = muscadet; //test
+ $fourn = new Fournisseur($db);
+ $fourn->fetch($_GET["socid"]);
+ $commande->modelpdf = 'muscadet'; //test
- if ($fourn->create_commande($user) > 0)
- {
- $idc = $fourn->single_open_commande;
-
- if ($comclientid != '')
- {
- $fourn->updateFromCommandeClient($user,$idc,$comclientid);
- }
+ if ($fourn->create_commande($user) > 0)
+ {
+ $idc = $fourn->single_open_commande;
- Header("Location:fiche.php?id=".$idc);
- exit;
- }
- else
- {
- $mesg=$fourn->error;
- }
+ if ($comclientid != '')
+ {
+ $fourn->updateFromCommandeClient($user,$idc,$comclientid);
+ }
+
+ Header("Location:fiche.php?id=".$idc);
+ exit;
+ }
+ else
+ {
+ $mesg=$fourn->error;
+ }
}
-
-/* *************************************************************************** */
-/* */
-/* Mode vue et edition */
-/* */
-/* *************************************************************************** */
-
llxHeader('',$langs->trans("OrderCard"),"CommandeFournisseur");
-$html = new Form($db);
-if ($_GET["id"] > 0)
+$html = new Form($db);
+
+/*********************************************************************
+ *
+ * Mode creation
+ *
+ *********************************************************************/
+if ($_GET['action'] == 'create' && $user->rights->fournisseur->commande->creer)
{
- // if ($mesg) print $mesg;
- $commande = new CommandeFournisseur($db);
-
- if ( $commande->fetch($_GET["id"]) == 0)
+ // Gerer par autre page
+}
+else
+{
+
+ /* *************************************************************************** */
+ /* */
+ /* Mode vue et edition */
+ /* */
+ /* *************************************************************************** */
+
+ $id = $_GET['id'];
+ if ($id > 0)
{
- $soc = new Societe($db);
- $soc->fetch($commande->socid);
-
- $author = new User($db);
- $author->id = $commande->user_author_id;
- $author->fetch();
-
- $h = 0;
- $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/fiche.php?id='.$commande->id;
- $head[$h][1] = $langs->trans("OrderCard");
- $a = $h;
- $h++;
-
- $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/note.php?id='.$commande->id;
- $head[$h][1] = $langs->trans("Note");
- $h++;
-
- $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/history.php?id='.$commande->id;
- $head[$h][1] = $langs->trans("OrderFollow");
- $h++;
-
- $title=$langs->trans("SupplierOrder");
- dolibarr_fiche_head($head, $a, $title);
-
- /*
- * Confirmation de la suppression de la commande
- *
- */
- if ($_GET["action"] == 'delete')
+ //if ($mesg) print $mesg.' ';
+
+ $commande = new CommandeFournisseur($db);
+ if ( $commande->fetch($_GET['id']) >= 0)
{
- $html->form_confirm("fiche.php?id=$commande->id",$langs->trans("DeleteOrder"),"Etes-vous sûr de vouloir supprimer cette commande ?","confirm_delete");
- print ' ';
- }
+ $soc = new Societe($db);
+ $soc->fetch($commande->socid);
- /*
- * Confirmation de la validation
- *
- */
- if ($_GET["action"] == 'valid')
- {
- // on vérifie si la commande est en numérotation provisoire
- $ref = substr($commande->ref, 1, 4);
- if ($ref == 'PROV')
+ $author = new User($db);
+ $author->id = $commande->user_author_id;
+ $author->fetch();
+
+ $h = 0;
+ $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/fiche.php?id='.$commande->id;
+ $head[$h][1] = $langs->trans("OrderCard");
+ $a = $h;
+ $h++;
+
+ $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/note.php?id='.$commande->id;
+ $head[$h][1] = $langs->trans("Note");
+ $h++;
+
+ $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/history.php?id='.$commande->id;
+ $head[$h][1] = $langs->trans("OrderFollow");
+ $h++;
+
+
+ $title=$langs->trans("SupplierOrder");
+ dolibarr_fiche_head($head, $a, $title);
+
+ /*
+ * Confirmation de la suppression de la commande
+ */
+ if ($_GET['action'] == 'delete')
{
- $newref = $commande->getNextNumRef($soc);
+ $html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete');
+ print ' ';
+ }
+
+ /*
+ * Confirmation de la validation
+ */
+ if ($_GET['action'] == 'valid')
+ {
+ // on vérifie si la commande est en numérotation provisoire
+ $ref = substr($commande->ref, 1, 4);
+ if ($ref == 'PROV')
+ {
+ $newref = $commande->getNextNumRef($soc);
+ }
+ else
+ {
+ $newref = $commande->ref;
+ }
+
+ $text=$langs->trans('ConfirmValidateOrder',$newref);
+ if ($conf->notification->enabled)
+ {
+ require_once(DOL_DOCUMENT_ROOT ."/notify.class.php");
+ $notify=new Notify($db);
+ $text.=' ';
+ $text.=$notify->confirmMessage(3,$commande->socid);
+ }
+
+ $html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('ValidateOrder'), $text, 'confirm_valid');
+ print ' ';
+ }
+ /*
+ * Confirmation de l'approbation
+ *
+ */
+ if ($_GET['action'] == 'approve')
+ {
+ $html->form_confirm("fiche.php?id=$commande->id","Approuver la commande","Etes-vous sûr de vouloir approuver cette commande ?","confirm_approve");
+ print ' ';
+ }
+ /*
+ * Confirmation de la desapprobation
+ *
+ */
+ if ($_GET['action'] == 'refuse')
+ {
+ $html->form_confirm("fiche.php?id=$commande->id","Refuser la commande","Etes-vous sûr de vouloir refuser cette commande ?","confirm_refuse");
+ print ' ';
+ }
+ /*
+ * Confirmation de l'annulation
+ */
+ if ($_GET['action'] == 'cancel')
+ {
+ $html->form_confirm("fiche.php?id=$commande->id",$langs->trans("Cancel"),"Etes-vous sûr de vouloir annuler cette commande ?","confirm_cancel");
+ print ' ';
+ }
+
+ /*
+ * Confirmation de l'envoi de la commande
+ */
+ if ($_GET["action"] == 'commande')
+ {
+ $date_com = mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]);
+ $html->form_confirm("fiche.php?id=".$commande->id."&datecommande=".$date_com."&methode=".$_POST["methodecommande"],
+ $langs->trans("MakeOrder"),$langs->trans("ConfirmMakeOrder",dolibarr_print_date($date_com,'day')),"confirm_commande");
+ print ' ';
+ }
+
+ /*
+ * Commande
+ */
+ $nbrow=8;
+ if ($conf->projet->enabled) $nbrow++;
+ print '';
+
+ // Ref
+ print ''.$langs->trans("Ref").' ';
+ print ''.$commande->ref.' ';
+ print ' ';
+
+ // Fournisseur
+ print ''.$langs->trans("Supplier")." ";
+ print '';
+ print '';
+ print img_object($langs->trans("ShowSupplier"),'company').' '.$soc->nom.' ';
+ print ' ';
+
+ // Statut
+ print '';
+ print ''.$langs->trans("Status").' ';
+ print '';
+ print $commande->getLibStatut(4);
+ print " ";
+
+ if ($commande->methode_commande_id > 0)
+ {
+ print ''.$langs->trans("Date").' ';
+
+ if ($commande->date_commande)
+ {
+ print dolibarr_print_date($commande->date_commande,"%A %d %B %Y")."\n";
+ }
+
+ print ' ';
+ if ($commande->methode_commande)
+ {
+ print "Méthode : " .$commande->methode_commande;
+ }
+ print " ";
+ }
+
+ // Auteur
+ print ''.$langs->trans("AuthorRequest").' ';
+ print ''.$author->getNomUrl(1).' ';
+ print '';
+ print " ";
+
+ // Ligne de 3 colonnes
+ print ''.$langs->trans("AmountHT").' ';
+ print ''.price($commande->total_ht).' ';
+ print ''.$langs->trans("Currency".$conf->monnaie).' ';
+ print ''.$langs->trans("AmountVAT").' '.price($commande->total_tva).' ';
+ print ''.$langs->trans("Currency".$conf->monnaie).' ';
+
+ print ''.$langs->trans("AmountTTC").' '.price($commande->total_ttc).' ';
+ print ''.$langs->trans("Currency".$conf->monnaie).' ';
+
+ print "
";
+
+ if ($mesg) print $mesg;
+ else print ' ';
+
+ /*
+ * Lignes de commandes
+ */
+ print '';
+
+ $sql = "SELECT l.ref, l.fk_product, l.description, l.price, l.qty";
+ $sql.= ", l.rowid, l.tva_tx, l.remise_percent, l.subprice";
+ $sql.= ", p.label";
+ $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as l";
+ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON l.fk_product = p.rowid";
+ $sql.= " WHERE l.fk_commande = $commande->id";
+ $sql.= " ORDER BY l.rowid";
+
+ $resql = $db->query($sql);
+ if ($resql)
+ {
+ $num = $db->num_rows($resql);
+ $i = 0; $total = 0;
+
+ if ($num)
+ {
+ print '';
+ print ''.$langs->trans("Description").' ';
+ print ''.$langs->trans("VAT").' ';
+ print ''.$langs->trans("Qty").' ';
+ print ''.$langs->trans("ReductionShort").' ';
+ print ''.$langs->trans("PriceU").' ';
+ print ' ';
+ print " \n";
+ }
+ $var=false;
+ while ($i < $num)
+ {
+ $objp = $db->fetch_object($resql);
+ print "";
+ print '';
+ print ''.img_object($langs->trans("ShowProduct"),'product').' '.$objp->ref.' ';
+ print ' - '.$objp->label;
+ if ($objp->description) print ' '.nl2br($objp->description);
+ print " ";
+ print ''.$objp->tva_tx.'% ';
+ print ''.$objp->qty.' ';
+ if ($objp->remise_percent > 0)
+ {
+ print ''.$objp->remise_percent."% \n";
+ }
+ else
+ {
+ print ' ';
+ }
+ print ''.price($objp->subprice)." \n";
+ if ($commande->statut == 0 && $user->rights->fournisseur->commande->creer && $_GET["action"] <> 'valid' && $_GET["action"] != 'editline')
+ {
+ print 'id.'&action=editline&rowid='.$objp->rowid.'#'.$objp->rowid.'">';
+ print img_edit();
+ print ' ';
+
+ print 'id.'&action=deleteline&lineid='.$objp->rowid.'">';
+ print img_delete();
+ print ' ';
+ }
+ else
+ {
+ print ' ';
+ }
+ print " ";
+
+ if ($_GET["action"] == 'editline' && $_GET["rowid"] == $objp->rowid)
+ {
+ print "id\" method=\"post\">";
+ print ' ';
+ print ' ';
+ print ' ';
+ print "";
+ print ''.$objp->description.' ';
+ print ' ';
+ print ' ';
+ print ' % ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' ' . "\n";
+ print " \n";
+ }
+ $i++;
+ $var=!$var;
+ }
+ $db->free();
}
else
{
- $newref = $commande->ref;
+ dolibarr_print_error($db);
}
-
- $text=$langs->trans('ConfirmValidateOrder',$newref);
- if ($conf->notification->enabled)
+
+ /*
+ * Ajouter une ligne
+ */
+ if ($commande->statut == 0 && $user->rights->fournisseur->commande->creer && ($_GET["action"] <> 'valid' || $_GET['action'] == 'builddoc'))
{
- require_once(DOL_DOCUMENT_ROOT ."/notify.class.php");
- $notify=new Notify($db);
- $text.=' ';
- $text.=$notify->confirmMessage(3,$commande->socid);
- }
+ print '';
+ print ' ';
+ print ' ';
- $html->form_confirm("fiche.php?id=".$commande->id,$langs->trans("ValidateOrder"),$text,"confirm_valid");
- print ' ';
- }
- /*
- * Confirmation de l'approbation
- *
- */
- if ($_GET["action"] == 'approve')
- {
- $html->form_confirm("fiche.php?id=$commande->id","Approuver la commande","Etes-vous sûr de vouloir approuver cette commande ?","confirm_approve");
- print ' ';
- }
- /*
- * Confirmation de l'approbation
- *
- */
- if ($_GET["action"] == 'refuse')
- {
- $html->form_confirm("fiche.php?id=$commande->id","Refuser la commande","Etes-vous sûr de vouloir refuser cette commande ?","confirm_refuse");
- print ' ';
- }
- /*
- * Confirmation de l'annulation
- *
- */
- if ($_GET["action"] == 'cancel')
- {
- $html->form_confirm("fiche.php?id=$commande->id",$langs->trans("Cancel"),"Etes-vous sûr de vouloir annuler cette commande ?","confirm_cancel");
- print ' ';
- }
-
- /*
- * Confirmation de l'envoi de la commande
- *
- */
- if ($_GET["action"] == 'commande')
- {
- $date_com = mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]);
- $html->form_confirm("fiche.php?id=".$commande->id."&datecommande=".$date_com."&methode=".$_POST["methodecommande"],
- $langs->trans("MakeOrder"),$langs->trans("ConfirmMakeOrder",dolibarr_print_date($date_com,'day')),"confirm_commande");
- print ' ';
- }
-
- /*
- * Commande
- */
- print '';
-
- // Ref
- print ''.$langs->trans("Ref").' ';
- print ''.$commande->ref.' ';
- print ' ';
-
- // Fournisseur
- print ''.$langs->trans("Supplier")." ";
- print '';
- print '';
- print img_object($langs->trans("ShowSupplier"),'company').' '.$soc->nom.' ';
- print ' ';
-
- // Statut
- print '';
- print ''.$langs->trans("Status").' ';
- print '';
- print $commande->getLibStatut(4);
- print " ";
-
- if ($commande->methode_commande_id > 0)
- {
- print ''.$langs->trans("Date").' ';
-
- if ($commande->date_commande)
- {
- print dolibarr_print_date($commande->date_commande,"%A %d %B %Y")."\n";
- }
-
- print ' ';
- if ($commande->methode_commande)
- {
- print "Méthode : " .$commande->methode_commande;
- }
- print " ";
- }
-
- // Auteur
- print ''.$langs->trans("AuthorRequest").' ';
- print ''.$author->getNomUrl(1).' ';
- print '';
- print " ";
-
- // Ligne de 3 colonnes
- print ''.$langs->trans("AmountHT").' ';
- print ''.price($commande->total_ht).' ';
- print ''.$langs->trans("Currency".$conf->monnaie).' ';
- print ''.$langs->trans("AmountVAT").' '.price($commande->total_tva).' ';
- print ''.$langs->trans("Currency".$conf->monnaie).' ';
-
- print ''.$langs->trans("AmountTTC").' '.price($commande->total_ttc).' ';
- print ''.$langs->trans("Currency".$conf->monnaie).' ';
-
- print "
";
-
- if ($mesg) print $mesg;
- else print ' ';
-
- /*
- * Lignes de commandes
- */
- print '';
-
- $sql = "SELECT l.ref, l.fk_product, l.description, l.price, l.qty";
- $sql.= ", l.rowid, l.tva_tx, l.remise_percent, l.subprice";
- $sql.= ", p.label";
- $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as l";
- $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON l.fk_product = p.rowid";
- $sql.= " WHERE l.fk_commande = $commande->id";
- $sql.= " ORDER BY l.rowid";
-
- $resql = $db->query($sql);
- if ($resql)
- {
- $num_lignes = $db->num_rows($resql);
- $i = 0; $total = 0;
-
- if ($num_lignes)
- {
print '';
- print ''.$langs->trans("Ref").' ';
- print ''.$langs->trans("Label").' ';
print ''.$langs->trans("Description").' ';
print ''.$langs->trans("VAT").' ';
print ''.$langs->trans("Qty").' ';
print ''.$langs->trans("ReductionShort").' ';
print ''.$langs->trans("PriceU").' ';
- print ' ';
+ print ' '." \n";
+
+ $var=false;
+ print "".'';
+ $html->select_produits_fournisseurs($commande->fourn_id,'','idprod',$filtre);
+ print ' ';
+ print ' ';
+ print ' % ';
+ print ' ';
+ print ' ';
print "\n";
+
+ print "";
}
- $var=false;
- while ($i < $num_lignes)
+
+ print "
";
+ print '';
+
+
+ /**
+ * Boutons actions
+ */
+ if ($user->societe_id == 0 && $commande->statut < 3 && ($_GET["action"] <> 'valid' || $_GET['action'] == 'builddoc'))
{
- $objp = $db->fetch_object($resql);
- print "";
- print ''.img_object($langs->trans("ShowProduct"),'product').' '.$objp->ref.' ';
- print "".$objp->label." ";
- print "".nl2br($objp->description)." ";
- print ''.$objp->tva_tx.'% ';
- print ''.$objp->qty.' ';
- if ($objp->remise_percent > 0)
+ print '';
+
+ if ($commande->statut == 0 && $num > 0)
{
- print '
'.$objp->remise_percent."% \n";
+ if ($user->rights->fournisseur->commande->valider)
+
+
+
+
+
+
+
+
+ {
+ print '
'.$langs->trans("Valid").' ';
+ }
+
+
+
+
+
}
- else
+
+ if ($commande->statut == 1)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
{
- print '
';
+ if ($user->rights->fournisseur->commande->approuver)
+ {
+ print '
'.$langs->trans("ApproveOrder").' ';
+
+ print '
'.$langs->trans("RefuseOrder").' ';
+
+
+
+
+
+
+
+
+
+
+
+
+
+ }
+
+ if ($user->rights->fournisseur->commande->annuler)
+ {
+ print '
'.$langs->trans("CancelOrder").' ';
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ }
+
}
- print '
'.price($objp->subprice)." \n";
- if ($commande->statut == 0 && $user->rights->fournisseur->commande->creer && $_GET["action"] <> 'valid' && $_GET["action"] != 'editline')
+
+
+
+
+
+
+
+
+
+ if ($commande->statut == 2)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
{
- print '
id.'&action=editline&rowid='.$objp->rowid.'#'.$objp->rowid.'">';
- print img_edit();
- print ' ';
-
- print '
id.'&action=deleteline&lineid='.$objp->rowid.'">';
- print img_delete();
- print ' ';
+ if ($user->rights->fournisseur->commande->annuler)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {
+ print '
'.$langs->trans("CancelOrder").' ';
+ }
+
+
+
+
+
}
- else
+
+
+
+
+ if ($commande->statut == 0)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
{
- print '
';
+ if ($user->rights->fournisseur->commande->creer)
+
+
+
+
+
+
+
+
+
+ {
+ print '
'.$langs->trans("Delete").' ';
+ }
+
}
- print "
";
-
- if ($_GET["action"] == 'editline' && $_GET["rowid"] == $objp->rowid)
+
+
+ // Build PDF
+ if ($commande->statut > 0)
{
- print " id\" method=\"post\">";
- print ' ';
- print ' ';
- print ' ';
- print "";
- print ''.stripslashes($objp->description).' ';
- print ' ';
- print ' ';
- print ' % ';
- print ' ';
- print ' ';
- print ' ';
- print ' ' . "\n";
- print " \n";
+ if ($user->rights->fournisseur->commande->creer)
+ {
+ print ''.$langs->trans("BuildPDF").' ';
+ }
+
}
- $i++;
- $var=!$var;
+ print "";
}
- $db->free();
+
+
+ print '';
+
+
+
+ /*
+ * Documents générés
+ *
+ */
+ $comfournref = sanitize_string($commande->ref);
+ $file = $conf->fournisseur->commande->dir_output . '/' . $comfournref . '/' . $comfournref . '.pdf';
+ $relativepath = $comfournref.'/'.$comfournref.'.pdf';
+ $filedir = $conf->fournisseur->commande->dir_output . '/' . $comfournref;
+ $urlsource=$_SERVER["PHP_SELF"]."?id=".$commande->id;
+ $genallowed=$user->rights->fournisseur->commande->creer;
+ $delallowed=$user->rights->fournisseur->commande->supprimer;
+
+ $somethingshown=$html->show_documents('commande_fournisseur',$comfournref,$filedir,$urlsource,$commande->statut>0?1:0,$delallowed,$commande->modelpdf);
+
+
+ print ' ';
+
+ /*
+ *
+ *
+ */
+ if ($_GET["action"] == 'classer')
+ {
+ print '';
+ print ' ';
+ print ' ';
+ }
+
+ /*
+ *
+ *
+ */
+ if ( $user->rights->fournisseur->commande->commander && $commande->statut == 2)
+ {
+ /**
+ * Commander
+ */
+ $form = new Form($db);
+
+ print ' ';
+ print '';
+ print '';
+ print ' ';
+ }
+
+ /*
+ *
+ *
+ */
+ if ( $user->rights->fournisseur->commande->receptionner && ($commande->statut == 3 ||$commande->statut == 4 ))
+ {
+ /**
+ * Réceptionner
+ */
+ $form = new Form($db);
+
+ print ' ';
+ print '';
+ print ' ';
+ print '\n";
+ print " \n";
+ }
+ print '
';
}
else
{
- print $db->error();
+ // Commande non trouvée
+ dolibarr_print_error($db);
}
-
- /*
- * Ajouter une ligne
- */
- if ($commande->statut == 0 && $user->rights->fournisseur->commande->creer && ($_GET["action"] <> 'valid' || $_GET['action'] == 'builddoc'))
- {
- print '';
- print ' ';
-
- print '';
- print ''.$langs->trans("Description").' ';
- if ($num_lignes) print ' ';
- print ''.$langs->trans("VAT").' ';
- print ''.$langs->trans("Qty").' ';
- print ''.$langs->trans("ReductionShort").' ';
- print ''.$langs->trans("PriceU").' ';
- print ' '." \n";
-
- $var=false;
- print "".'';
- $html->select_produits_fournisseurs($commande->fourn_id,'','p_idprod',$filtre);
- print ' ';
- print ' ';
- print ' % ';
- print ' ';
- print ' ';
- print "\n";
-
- print " ";
- }
-
- print "
";
- print '';
-
- /**
- * Boutons actions
- */
- if ($user->societe_id == 0 && $commande->statut < 3 && ($_GET["action"] <> 'valid' || $_GET['action'] == 'builddoc'))
- {
- print '";
- }
-
-
-
- print '';
-
- /*
- * Documents générés
- *
- */
- $comfournref = sanitize_string($commande->ref);
- $file = $conf->fournisseur->commande->dir_output . '/' . $comfournref . '/' . $comfournref . '.pdf';
- $relativepath = $comfournref.'/'.$comfournref.'.pdf';
- $filedir = $conf->fournisseur->commande->dir_output . '/' . $comfournref;
- $urlsource=$_SERVER["PHP_SELF"]."?id=".$commande->id;
- $genallowed=$user->rights->fournisseur->commande->creer;
- $delallowed=$user->rights->fournisseur->commande->supprimer;
-
- $var=true;
- /*
- if (file_exists($file))
- {
- print_titre($langs->trans('Documents'));
- print '';
- print ''.$langs->trans('Order').' PDF ';
- print ''.$commande->ref.'.pdf ';
- print ''.filesize($file). ' bytes ';
- print ''.strftime('%d %b %Y %H:%M:%S',filemtime($file)).' ';
- print ' ';
- print '
';
- print ' ';
- }
- */
- $somethingshown=$html->show_documents('commande_fournisseur',$comfournref,$filedir,$urlsource,$commande->statut>0?1:0,$delallowed,$commande->modelpdf);
-
-
- print ' ';
-
- /*
- *
- *
- */
- if ($_GET["action"] == 'classer')
- {
- print '';
- print ' ';
- print ' ';
- }
-
- /*
- *
- *
- */
- if ( $user->rights->fournisseur->commande->commander && $commande->statut == 2)
- {
- /**
- * Commander
- */
- $form = new Form($db);
-
- print ' ';
- print '';
- print '';
- print ' ';
- }
-
- /*
- *
- *
- */
- if ( $user->rights->fournisseur->commande->receptionner && ($commande->statut == 3 ||$commande->statut == 4 ))
- {
- /**
- * Réceptionner
- */
- $form = new Form($db);
-
- print ' ';
- print '';
- print ' ';
- print '\n";
- print " \n";
- }
- print '
';
}
- else
- {
- /* Commande non trouvée */
- print "Commande inexistante";
- }
-}
+}
$db->close();
-llxFooter('$Date$ - $Revision$');
+llxFooter('$Date$ - $Revision$');
?>
diff --git a/htdocs/fourn/commande/history.php b/htdocs/fourn/commande/history.php
index b715a6c9754..7f55705a3fa 100644
--- a/htdocs/fourn/commande/history.php
+++ b/htdocs/fourn/commande/history.php
@@ -49,7 +49,7 @@ if ($_GET["id"] > 0)
$soc = new Societe($db);
$commande = new CommandeFournisseur($db);
- if ( $commande->fetch($_GET["id"]) == 0)
+ if ( $commande->fetch($_GET["id"]) >= 0)
{
$soc->fetch($commande->socid);
diff --git a/htdocs/fourn/commande/note.php b/htdocs/fourn/commande/note.php
index bc0d732d807..96d69b60106 100644
--- a/htdocs/fourn/commande/note.php
+++ b/htdocs/fourn/commande/note.php
@@ -70,7 +70,7 @@ $html = new Form($db);
if ($_GET["id"] > 0)
{
$commande = new CommandeFournisseur($db);
- if ( $commande->fetch($_GET["id"]) == 0)
+ if ( $commande->fetch($_GET["id"]) >= 0)
{
$soc = new Societe($db);
$soc->fetch($commande->socid);
diff --git a/htdocs/fourn/fournisseur.commande.class.php b/htdocs/fourn/fournisseur.commande.class.php
index 936c58c7cf5..c1d77d56aa1 100644
--- a/htdocs/fourn/fournisseur.commande.class.php
+++ b/htdocs/fourn/fournisseur.commande.class.php
@@ -65,48 +65,48 @@ class CommandeFournisseur extends Commande
/**
* Lit une commande
*/
- function fetch ($id)
- {
- $sql = "SELECT c.rowid, c.date_creation, c.ref, c.fk_soc, c.fk_user_author, c.fk_statut, c.amount_ht, c.total_ht, c.total_ttc, c.tva,";
- $sql .= " ".$this->db->pdate("c.date_commande")." as date_commande, c.fk_projet, c.remise_percent, c.source, c.fk_methode_commande,";
- $sql .= " c.note, c.note_public,";
- $sql .= " cm.libelle as methode_commande";
- $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c";
- $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_methode_commande_fournisseur as cm ON cm.rowid = c.fk_methode_commande";
- $sql .= " WHERE c.rowid = ".$id;
-
- $result = $this->db->query($sql) ;
- if ($result)
- {
- $obj = $this->db->fetch_object();
-
- $this->id = $obj->rowid;
- $this->ref = $obj->ref;
- $this->socid = $obj->fk_soc;
- $this->fourn_id = $obj->fk_soc;
- $this->statut = $obj->fk_statut;
- $this->user_author_id = $obj->fk_user_author;
- $this->total_ht = $obj->total_ht;
- $this->total_tva = $obj->tva;
- $this->total_ttc = $obj->total_ttc;
- $this->date_commande = $obj->date_commande; // date à laquelle la commande a été transmise
- $this->date = $obj->date_creation;
- $this->remise_percent = $obj->remise_percent;
- $this->methode_commande_id = $obj->fk_methode_commande;
- $this->methode_commande = $obj->methode_commande;
-
- $this->source = $obj->source;
- $this->facturee = $obj->facture;
- $this->projet_id = $obj->fk_projet;
- $this->note = $obj->note;
- $this->note_public = $obj->note_public;
-
- $this->db->free();
-
- if ($this->statut == 0) $this->brouillon = 1;
-
-// export pdf -----------
-
+ function fetch($id)
+ {
+ $sql = "SELECT c.rowid, c.date_creation, c.ref, c.fk_soc, c.fk_user_author, c.fk_statut, c.amount_ht, c.total_ht, c.total_ttc, c.tva,";
+ $sql .= " ".$this->db->pdate("c.date_commande")." as date_commande, c.fk_projet, c.remise_percent, c.source, c.fk_methode_commande,";
+ $sql .= " c.note, c.note_public,";
+ $sql .= " cm.libelle as methode_commande";
+ $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c";
+ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_methode_commande_fournisseur as cm ON cm.rowid = c.fk_methode_commande";
+ $sql .= " WHERE c.rowid = ".$id;
+
+ $resql = $this->db->query($sql) ;
+ if ($resql)
+ {
+ $obj = $this->db->fetch_object($resql);
+
+ $this->id = $obj->rowid;
+ $this->ref = $obj->ref;
+ $this->socid = $obj->fk_soc;
+ $this->fourn_id = $obj->fk_soc;
+ $this->statut = $obj->fk_statut;
+ $this->user_author_id = $obj->fk_user_author;
+ $this->total_ht = $obj->total_ht;
+ $this->total_tva = $obj->tva;
+ $this->total_ttc = $obj->total_ttc;
+ $this->date_commande = $obj->date_commande; // date à laquelle la commande a été transmise
+ $this->date = $obj->date_creation;
+ $this->remise_percent = $obj->remise_percent;
+ $this->methode_commande_id = $obj->fk_methode_commande;
+ $this->methode_commande = $obj->methode_commande;
+
+ $this->source = $obj->source;
+ $this->facturee = $obj->facture;
+ $this->projet_id = $obj->fk_projet;
+ $this->note = $obj->note;
+ $this->note_public = $obj->note_public;
+
+ $this->db->free();
+
+ if ($this->statut == 0) $this->brouillon = 1;
+
+ // export pdf -----------
+
$this->lignes = array();
$sql = 'SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice,';
$sql.= ' p.label, p.description as product_desc, p.ref, p.fk_product_type, p.rowid as prodid';
@@ -115,45 +115,52 @@ class CommandeFournisseur extends Commande
$sql.= ' WHERE l.fk_commande = '.$this->id;
$sql.= ' ORDER BY l.rowid';
$result = $this->db->query($sql);
- if ($result)
- {
- $num = $this->db->num_rows($result);
- $i = 0;
-
- while ($i < $num)
- {
- $objp = $this->db->fetch_object($result);
-
- $ligne = new CommandeFournisseurLigne();
-
- $ligne->desc = $objp->description; // Description ligne
- $ligne->qty = $objp->qty;
- $ligne->tva_tx = $objp->tva_tx;
- $ligne->subprice = $objp->subprice;
- $ligne->remise_percent = $objp->remise_percent;
- $ligne->price = $objp->price;
- $ligne->fk_product = $objp->fk_product;
-
- $ligne->libelle = $objp->label; // Label produit
- $ligne->product_desc = $objp->product_desc; // Description produit
- $ligne->ref = $objp->ref;
-
- $this->lignes[$i] = $ligne;
- //dolibarr_syslog("1 ".$ligne->desc);
- //dolibarr_syslog("2 ".$ligne->product_desc);
- $i++;
- }
- $this->db->free($result);
-
- }
- else
- {
- dolibarr_syslog("CommandeFournisseur::Fetch Error $sql");
- dolibarr_syslog("CommandeFournisseur::Fetch Error ".$this->db->error());
- return -1;
- }
- }
-}
+ if ($result)
+ {
+ $num = $this->db->num_rows($result);
+ $i = 0;
+
+ while ($i < $num)
+ {
+ $objp = $this->db->fetch_object($result);
+
+ $ligne = new CommandeFournisseurLigne();
+
+ $ligne->desc = $objp->description; // Description ligne
+ $ligne->qty = $objp->qty;
+ $ligne->tva_tx = $objp->tva_tx;
+ $ligne->subprice = $objp->subprice;
+ $ligne->remise_percent = $objp->remise_percent;
+ $ligne->price = $objp->price;
+ $ligne->fk_product = $objp->fk_product;
+
+ $ligne->libelle = $objp->label; // Label produit
+ $ligne->product_desc = $objp->product_desc; // Description produit
+ $ligne->ref = $objp->ref;
+
+ $this->lignes[$i] = $ligne;
+ //dolibarr_syslog("1 ".$ligne->desc);
+ //dolibarr_syslog("2 ".$ligne->product_desc);
+ $i++;
+ }
+ $this->db->free($result);
+
+ return 0;
+ }
+ else
+ {
+ $this->error=$this->db->error()." sql=".$sql;
+ dolibarr_syslog("CommandeFournisseur::Fetch ".$this->error);
+ return -1;
+ }
+ }
+ else
+ {
+ $this->error=$this->db->error()." sql=".$sql;
+ dolibarr_syslog("CommandeFournisseur::Fetch ".$this->error);
+ return -1;
+ }
+ }
/**
* \brief Insère ligne de log
@@ -621,7 +628,7 @@ class CommandeFournisseur extends Commande
$desc = trim($desc);
$remise_percent = price2num($remise_percent);
- dolibarr_syslog("Fournisseur_Commande.class.php::addline $desc, $pu, $qty, $txtva, $fk_product, $remise_percent");
+ dolibarr_syslog("Fournisseur.Commande.class::addline $desc, $pu, $qty, $txtva, $fk_product, $remise_percent");
if ($qty < 1 && ! $fk_product)
{
@@ -639,7 +646,7 @@ class CommandeFournisseur extends Commande
if ($prod->fetch($fk_product) > 0)
{
$result=$prod->get_buyprice($this->fourn_id,$qty);
- if ($result)
+ if ($result > 0)
{
$label = $prod->libelle;
$desc = $prod->description;
@@ -647,13 +654,25 @@ class CommandeFournisseur extends Commande
$pu = $prod->fourn_pu;
$ref = $prod->ref;
}
- else
+ if ($result == 0 || $result == -1)
{
$this->error="Aucun tarif trouvé pour cette quantité. Quantité saisie insuffisante ?";
$this->db->rollback();
- dolibarr_syslog($this->error);
+ dolibarr_syslog("Fournisseur.commande.class::addline result=".$result." - ".$this->error);
return -1;
}
+ if ($result < -1)
+ {
+ $this->error=$prod->error;
+ $this->db->rollback();
+ dolibarr_syslog("Fournisseur.commande.class::addline result=".$result." - ".$this->error);
+ return -1;
+ }
+ }
+ else
+ {
+ $this->error=$this->db->error();
+ return -1;
}
}
@@ -668,7 +687,9 @@ class CommandeFournisseur extends Commande
$sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseurdet (fk_commande,label,description,fk_product, price, qty, tva_tx, remise_percent, subprice, remise, ref)";
$sql .= " VALUES ($this->id, '" . addslashes($label) . "','" . addslashes($desc) . "',".$fk_product.",".price2num($price).", '$qty', $txtva, $remise_percent,'".price2num($subprice)."','".price2num($remise)."','".$ref."') ;";
- if ( $this->db->query( $sql) )
+ dolibarr_syslog('Fournisseur.commande.class::addline sql='.$sql);
+ $resql=$this->db->query($sql);
+ if ($resql)
{
$this->update_price();
@@ -683,28 +704,35 @@ class CommandeFournisseur extends Commande
}
}
- /**
- * Supprime une ligne de la commande
- *
- */
- function delete_line($idligne)
- {
- if ($this->statut == 0)
+ /**
+ * Supprime une ligne de la commande
+ *
+ */
+ function delete_line($idligne)
{
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseurdet WHERE rowid = ".$idligne;
-
- if ($this->db->query($sql) )
- {
- $this->update_price();
-
- return 0;
- }
- else
- {
- return -1;
- }
+ if ($this->statut == 0)
+ {
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseurdet WHERE rowid = ".$idligne;
+ $resql=$this->db->query($sql);
+
+ dolibarr_syslog("Fournisseur.commande.class::delete_line sql=".$sql);
+ if ($resql)
+ {
+ $result=$this->update_price();
+ return 0;
+ }
+ else
+ {
+ $this->error=$this->db->error();
+ return -1;
+ }
+ }
+ else
+ {
+ return -1;
+ }
}
- }
+
/**
* Mettre à jour le prix
*
@@ -1150,6 +1178,7 @@ class CommandeFournisseur extends Commande
else
{
$this->error=$this->db->error();
+ dolibarr_syslog("Commande.fournisseur.class::updateline ".$this->error);
$this->db->rollback();
return -1;
}
@@ -1157,6 +1186,7 @@ class CommandeFournisseur extends Commande
else
{
$this->error="Commande::updateline Order status makes operation forbidden";
+ dolibarr_syslog("Commande.fournisseur.class::updateline ".$this->error);
return -2;
}
}
diff --git a/htdocs/product.class.php b/htdocs/product.class.php
index 75efe59d6b9..1f9848de63c 100644
--- a/htdocs/product.class.php
+++ b/htdocs/product.class.php
@@ -559,71 +559,73 @@ class Product
}
- /**
- * \brief Lit le prix pratiqué par un fournisseur
- * \param fourn_id Id du fournisseur
- * \param qty Quantite recherchée
- * \return int <0 si ko, 0 si ok mais rien trouvé, 1 si ok et trouvé
- */
- function get_buyprice($fourn_id, $qty)
- {
- $result = 0;
- $sql = "SELECT pf.price as price, pf.quantity as quantity";
- $sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pf";
- $sql.= " WHERE pf.fk_soc = ".$fourn_id;
- $sql.= " AND pf.fk_product =" .$this->id;
- $sql.= " AND quantity <= ".$qty;
- $sql.= " ORDER BY quantity DESC";
- $sql.= " LIMIT 1";
-
- dolibarr_syslog("Product::get_buyprice $fourn_id,$qty sql=$sql");
-
- $resql = $this->db->query($sql);
- if ($resql)
- {
- $obj = $this->db->fetch_object($resql);
- if ($obj && $obj->quantity > 0)
- {
- $this->buyprice = $obj->price; // \deprecated
- $this->fourn_pu = $obj->price / $obj->quantity; // Prix unitaire du produit pour le fournisseur $fourn_id
- return 1;
- }
- else
- {
- // On refait le meme select mais sans critere de quantite
- $sql = "SELECT pf.price as price, pf.quantity as quantity";
- $sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pf";
- $sql.= " WHERE pf.fk_soc = ".$fourn_id;
- $sql.= " AND pf.fk_product =" .$this->id;
- //$sql.= " AND quantity <= ".$qty;
- $sql.= " ORDER BY quantity DESC";
- $sql.= " LIMIT 1";
-
- $resql = $this->db->query($sql);
- if ($resql)
- {
- $num=$this->db->num_rows($result);
- if ($num)
- {
- return -1; // Ce produit existe chez ce fournisseur mais qté insuffisante
- }
+ /**
+ * \brief Lit le prix pratiqué par un fournisseur
+ * \param fourn_id Id du fournisseur
+ * \param qty Quantite recherchée
+ * \return int <0 si ko, 0 si ok mais rien trouvé, 1 si ok et trouvé
+ */
+ function get_buyprice($fourn_id, $qty)
+ {
+ $result = 0;
+ $sql = "SELECT pf.price as price, pf.quantity as quantity";
+ $sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pf";
+ $sql.= " WHERE pf.fk_soc = ".$fourn_id;
+ $sql.= " AND pf.fk_product =" .$this->id;
+ $sql.= " AND quantity <= ".$qty;
+ $sql.= " ORDER BY quantity DESC";
+ $sql.= " LIMIT 1";
+
+ dolibarr_syslog("Product::get_buyprice $fourn_id,$qty sql=$sql");
+
+ $resql = $this->db->query($sql);
+ if ($resql)
+ {
+ $obj = $this->db->fetch_object($resql);
+ if ($obj && $obj->quantity > 0)
+ {
+ $this->buyprice = $obj->price; // \deprecated
+ $this->fourn_pu = $obj->price / $obj->quantity; // Prix unitaire du produit pour le fournisseur $fourn_id
+ return 1;
+ }
+ else
+ {
+ // On refait le meme select mais sans critere de quantite
+ $sql = "SELECT pf.price as price, pf.quantity as quantity";
+ $sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pf";
+ $sql.= " WHERE pf.fk_soc = ".$fourn_id;
+ $sql.= " AND pf.fk_product =" .$this->id;
+ //$sql.= " AND quantity <= ".$qty;
+ $sql.= " ORDER BY quantity DESC";
+ $sql.= " LIMIT 1";
+
+ $resql = $this->db->query($sql);
+ if ($resql)
+ {
+ $num=$this->db->num_rows($result);
+ if ($num)
+ {
+ return -1; // Ce produit existe chez ce fournisseur mais qté insuffisante
+ }
+ else
+ {
+ return 0; // Ce produit n'existe pas chez ce fournisseur
+ }
+ }
+ else
+ {
+ $this->error=$this->db->error();
+ return -3;
+ }
+ }
+ }
else
- {
- return 0; // Ce produit n'existe pas chez ce fournisseur
- }
- }
- else
- {
- return -3;
- }
- }
- }
- else
- {
- return -2;
- }
- return $result;
- }
+ {
+ $this->error=$this->db->error();
+ return -2;
+ }
+ return $result;
+ }
/**