diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php index bee7f0be150..93777d950ec 100644 --- a/htdocs/commande/commande.class.php +++ b/htdocs/commande/commande.class.php @@ -40,7 +40,7 @@ class Commande var $db ; var $id ; var $socidp; - var $contactid; + var $contactid; var $brouillon; var $cond_reglement_id; var $cond_reglement_code; @@ -60,6 +60,7 @@ class Commande global $langs; $langs->load('orders'); $this->db = $DB; + $this->statuts[-1] = $langs->trans('StatusOrderCanceled'); $this->statuts[0] = $langs->trans('StatusOrderDraft'); $this->statuts[1] = $langs->trans('StatusOrderValidated'); @@ -78,6 +79,7 @@ class Commande $this->sources[3] = $langs->trans('OrderSource3'); $this->sources[4] = $langs->trans('OrderSource4'); $this->sources[5] = $langs->trans('OrderSource5'); + $this->products = array(); } @@ -107,9 +109,9 @@ class Commande } $this->soc_id = $propal->soc_id; - $this->cond_reglement_id = $propal->cond_reglement_id; - $this->mode_reglement_id = $propal->mode_reglement_id; - $this->date_livraison = $propal->date_livraison; + $this->cond_reglement_id = $propal->cond_reglement_id; + $this->mode_reglement_id = $propal->mode_reglement_id; + $this->date_livraison = $propal->date_livraison; /* Définit la société comme un client */ $soc = new Societe($this->db); @@ -222,26 +224,43 @@ class Commande } } } - /** - * Créé la commande - * - */ + + /** + * \brief Créé la commande + * \param user Id utilisateur qui crée + */ function create($user) { - global $conf; - /* On positionne en mode brouillon la commande */ + global $conf,$langs; + + // Vérification paramètres + if ($this->source < 0) + { + $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Source")); + return -1; + } + + // On positionne en mode brouillon la commande $this->brouillon = 1; if (! $remise) { $remise = 0 ; } - if (! $this->projetid) { $this->projetid = 0; } - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'commande (fk_soc, date_creation, fk_user_author, fk_projet, date_commande, source, note, ref_client, model_pdf, fk_cond_reglement, fk_mode_reglement, date_livraison) '; - $sql .= ' VALUES ('.$this->soc_id.', now(), '.$user->id.', '.$this->projetid.', '.$this->db->idate($this->date_commande).', '.$this->source.', \''.$this->note.'\', \''.$this->ref_client.'\', \''.$this->modelpdf.'\', \''.$this->cond_reglement_id.'\', \''.$this->mode_reglement_id.'\', \''.$this->date_livraison.'\')'; + + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'commande ('; + $sql.= 'fk_soc, date_creation, fk_user_author, fk_projet, date_commande, source, note, ref_client, model_pdf, fk_cond_reglement, fk_mode_reglement, date_livraison) '; + $sql.= ' VALUES ('.$this->soc_id.', now(), '.$user->id.', '.$this->projetid.','; + $sql.= ' '.$this->db->idate($this->date_commande).','; + $sql.= ' '.$this->source.', '; + $sql.= " '".addslashes($this->note)."', "; + $sql.= " '".$this->ref_client."', '".$this->modelpdf.'\', \''.$this->cond_reglement_id.'\', \''.$this->mode_reglement_id.'\','; + $sql.= " ".($this->date_livraison?$this->db->idate($this->date_livraison):'null').")"; + + dolibarr_syslog("Commande.class.php::create sql=$sql"); if ( $this->db->query($sql) ) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'commande'); @@ -565,7 +584,7 @@ class Commande $this->modelpdf = $obj->model_pdf; $this->cond_reglement_id = $obj->fk_cond_reglement; $this->mode_reglement_id = $obj->fk_mode_reglement; - $this->date_livraison = $obj->date_livraison; + $this->date_livraison = $obj->date_livraison; $this->db->free(); if ($this->statut == 0) @@ -804,9 +823,9 @@ class Commande } /** * \brief Définit une date de livraison - * \param user Objet utilisateur qui modifie - * \param date_livraison date de livraison - * \return int <0 si ko, >0 si ok + * \param user Objet utilisateur qui modifie + * \param date_livraison Date de livraison + * \return int <0 si ko, >0 si ok */ function set_date_livraison($user, $date_livraison) { @@ -1177,10 +1196,11 @@ class Commande return -1; } } - /** - * \brief Classer la commande dans un projet - * \param cat_id Id du projet - */ + + /** + * \brief Classer la commande dans un projet + * \param cat_id Id du projet + */ function classin($cat_id) { $sql = 'UPDATE '.MAIN_DB_PREFIX."commande SET fk_projet = $cat_id"; @@ -1197,6 +1217,7 @@ class Commande } } + /** * \brief Charge indicateurs this->nbtodo et this->nbtodolate de tableau de bord * \param user Objet user diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index aeb5875a024..6dd69a3b703 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -32,6 +32,9 @@ require('./pre.inc.php'); require_once(DOL_DOCUMENT_ROOT ."/includes/modules/commande/modules_commande.php"); +if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT.'/project.class.php'); +require_once(DOL_DOCUMENT_ROOT.'/propal.class.php'); +require_once(DOL_DOCUMENT_ROOT.'/commande/commande.class.php'); $langs->load('orders'); $langs->load('sendings'); @@ -44,13 +47,6 @@ $user->getrights('expedition'); if (!$user->rights->commande->lire) accessforbidden(); -if ($conf->projet->enabled) -{ - require_once(DOL_DOCUMENT_ROOT.'/project.class.php'); -} - -require_once(DOL_DOCUMENT_ROOT.'/propal.class.php'); -require_once(DOL_DOCUMENT_ROOT.'/commande/commande.class.php'); // Sécurité accés client $socidp=0; @@ -77,7 +73,8 @@ if ($_POST['action'] == 'classin' && $user->rights->commande->creer) if ($_POST['action'] == 'add' && $user->rights->commande->creer) { $datecommande=''; - $datecommande = @mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); + $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); @@ -91,7 +88,7 @@ if ($_POST['action'] == 'add' && $user->rights->commande->creer) $commande->modelpdf = $_POST['model']; $commande->cond_reglement_id = $_POST['cond_reglement_id']; $commande->mode_reglement_id = $_POST['mode_reglement_id']; - $commande->date_livraison = $_POST['liv_year']."-".$_POST['liv_month']."-".$_POST['liv_day']; + $commande->date_livraison = $datelivraison; $commande->add_product($_POST['idprod1'],$_POST['qty1'],$_POST['remise_percent1']); $commande->add_product($_POST['idprod2'],$_POST['qty2'],$_POST['remise_percent2']); @@ -104,9 +101,17 @@ if ($_POST['action'] == 'add' && $user->rights->commande->creer) $commande_id = $commande->create($user); - $_GET['id'] = $commande->id; - - $action = ''; + if ($commande_id <= 0) + { + $_GET['action']='create'; + $_GET['socidp']=$_POST['soc_id']; + $mesg='
'.$commande->error.'
'; + } + else + { + $_GET['id'] = $commande->id; + $action = ''; + } } // Positionne ref commande client @@ -215,6 +220,7 @@ if ($_GET['action'] == 'deleteline' && $user->rights->commande->creer) $commande->fetch($_GET['id']); $result = $commande->delete_line($_GET['lineid']); Header('Location: fiche.php?id='.$_GET['id']); + exit; } if ($_POST['action'] == 'confirm_valid' && $_POST['confirm'] == 'yes' && $user->rights->commande->valider) @@ -248,6 +254,7 @@ if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes') $commande->id = $_GET['id']; $commande->delete(); Header('Location: index.php'); + exit; } } @@ -271,7 +278,6 @@ if($_GET['action'] == 'builddoc') llxHeader('',$langs->trans('OrderCard'),'Commande'); - $html = new Form($db); /********************************************************************* @@ -283,6 +289,8 @@ if ($_GET['action'] == 'create' && $user->rights->commande->creer) { print_titre($langs->trans('CreateOrder')); + if ($mesg) print $mesg.'
'; + $new_commande = new Commande($db); if ($propalid) @@ -338,30 +346,29 @@ if ($_GET['action'] == 'create' && $user->rights->commande->creer) $html->select_date('','re','','','',"crea_commande"); print ''; - // date de livraison + // Date de livraison print "".$langs->trans("DateDelivery").""; - if(DATE_LIVRAISON_WEEK_DELAY != "") + if ($conf->global->DATE_LIVRAISON_WEEK_DELAY) { - $tmpdte = time() + ((7*DATE_LIVRAISON_WEEK_DELAY) * 24 * 60 * 60); - $syear = date("Y", $tmpdte); - $smonth = date("m", $tmpdte); - $sday = date("d", $tmpdte); - $html->select_date($syear."-".$smonth."-".$sday,'liv_','','','',"crea_commande"); + $tmpdte = time() + ((7*$conf->global->DATE_LIVRAISON_WEEK_DELAY) * 24 * 60 * 60); + $html->select_date($tmpdte,'liv_','','',1,"crea_commande"); } else - $html->select_date('','liv_','','','',"crea_commande"); + { + $html->select_date(-1,'liv_','','',1,"crea_commande"); + } print ""; // Conditions de réglement - print ''.$langs->trans('PaymentConditions').''; - $html->select_conditions_paiements($soc->cond_reglement,'cond_reglement_id'); - print ''; - - // Mode de réglement - print ''.$langs->trans('PaymentMode').''; - $html->select_types_paiements($soc->mode_reglement,'mode_reglement_id'); - print ''; + print ''.$langs->trans('PaymentConditions').''; + $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 ''; if ($conf->projet->enabled) { @@ -371,16 +378,15 @@ if ($_GET['action'] == 'create' && $user->rights->commande->creer) } print ''.$langs->trans('Source').''; - $html->select_array('source_id',$new_commande->sources,2); + $html->selectSourcesCommande('','source_id',1); print ''; print 'Modèle'; print ''; // pdf include_once(DOL_DOCUMENT_ROOT.'/includes/modules/commande/modules_commande.php'); - $form=new Form($db); $model=new ModelePDFCommandes(); $liste=$model->liste_modeles($db); - $form->select_array("model",$liste,$conf->global->COMMANDE_ADDON_PDF); + $html->select_array("model",$liste,$conf->global->COMMANDE_ADDON_PDF); print ""; if ($propalid > 0) diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index 4e74c75997f..f54d2162241 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -220,24 +220,46 @@ class Form } } - /** - * \brief Retourne la liste déroulante des pays actifs, dans la langue de l'utilisateur - * \param selected Code pays pré-sélectionné - * \param htmlname Nom de la liste deroulante - * \param htmloption Options html sur le select - * \todo trier liste sur noms après traduction plutot que avant - */ - - function select_pays($selected='',$htmlname='pays_id',$htmloption='') - { - global $conf,$langs; - $langs->load("dict"); - - $sql = "SELECT rowid, libelle, code, active FROM ".MAIN_DB_PREFIX."c_pays"; - $sql .= " WHERE active = 1"; - $sql .= " ORDER BY code ASC;"; - - if ($this->db->query($sql)) + + /** + * \brief Renvoie la liste des sources de commandes + * \param selected Id de la source pré-sélectionnée + * \param htmlname Nom de la liste deroulante + * \param addempty 0=liste sans valeur nulle, 1=ajoute valeur inconnue + * \return array Tableau des sources de commandes + */ + function selectSourcesCommande($selected='',$htmlname='source_id',$addempty=0) + { + global $conf,$langs; + print ''; + } + + + /** + * \brief Retourne la liste déroulante des pays actifs, dans la langue de l'utilisateur + * \param selected Code pays pré-sélectionné + * \param htmlname Nom de la liste deroulante + * \param htmloption Options html sur le select + * \todo trier liste sur noms après traduction plutot que avant + */ + function select_pays($selected='',$htmlname='pays_id',$htmloption='') + { + global $conf,$langs; + $langs->load("dict"); + + $sql = "SELECT rowid, libelle, code, active FROM ".MAIN_DB_PREFIX."c_pays"; + $sql .= " WHERE active = 1"; + $sql .= " ORDER BY code ASC;"; + + if ($this->db->query($sql)) { print '