2
0
forked from Wavyzz/dolibarr

Fix: Gestion erreur sur creation commande

Rend date livraison optionnelle
This commit is contained in:
Laurent Destailleur
2006-03-18 19:58:33 +00:00
parent 39ddb8d5ea
commit d0e09f5475
5 changed files with 178 additions and 132 deletions

View File

@@ -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();
}
@@ -222,26 +224,43 @@ class Commande
}
}
}
/**
* Cr<43><72> la commande
*
* \brief Cr<EFBFBD><EFBFBD> la commande
* \param user Id utilisateur qui cr<63>e
*/
function create($user)
{
global $conf;
/* On positionne en mode brouillon la commande */
global $conf,$langs;
// V<>rification param<61>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');
@@ -805,7 +824,7 @@ class Commande
/**
* \brief D<>finit une date de livraison
* \param user Objet utilisateur qui modifie
* \param date_livraison date de livraison
* \param date_livraison Date de livraison
* \return int <0 si ko, >0 si ok
*/
function set_date_livraison($user, $date_livraison)
@@ -1177,6 +1196,7 @@ class Commande
return -1;
}
}
/**
* \brief Classer la commande dans un projet
* \param cat_id Id du projet
@@ -1197,6 +1217,7 @@ class Commande
}
}
/**
* \brief Charge indicateurs this->nbtodo et this->nbtodolate de tableau de bord
* \param user Objet user

View File

@@ -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<69> acc<63>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);
if ($commande_id <= 0)
{
$_GET['action']='create';
$_GET['socidp']=$_POST['soc_id'];
$mesg='<div class="error">'.$commande->error.'</div>';
}
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.'<br>';
$new_commande = new Commande($db);
if ($propalid)
@@ -338,24 +346,23 @@ if ($_GET['action'] == 'create' && $user->rights->commande->creer)
$html->select_date('','re','','','',"crea_commande");
print '</td></tr>';
// date de livraison
// Date de livraison
print "<tr><td>".$langs->trans("DateDelivery")."</td><td>";
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 "</td></tr>";
// Conditions de r<>glement
print '<tr><td nowrap>'.$langs->trans('PaymentConditions').'</td><td>';
$html->select_conditions_paiements($soc->cond_reglement,'cond_reglement_id');
$html->select_conditions_paiements($soc->cond_reglement,'cond_reglement_id',-1,1);
print '</td></tr>';
// Mode de r<>glement
@@ -371,16 +378,15 @@ if ($_GET['action'] == 'create' && $user->rights->commande->creer)
}
print '<tr><td>'.$langs->trans('Source').'</td><td>';
$html->select_array('source_id',$new_commande->sources,2);
$html->selectSourcesCommande('','source_id',1);
print '</td></tr>';
print '<tr><td>Mod<6F>le</td>';
print '<td>';
// 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 "</td></tr>";
if ($propalid > 0)

View File

@@ -220,6 +220,29 @@ class Form
}
}
/**
* \brief Renvoie la liste des sources de commandes
* \param selected Id de la source pr<70>-s<>lectionn<6E>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 '<select class="flat" name="'.$htmlname.'" '.$htmloption.'>';
if ($addempty) print '<option value="-1" selected="true">&nbsp;</option>';
print '<option value="0"'.($selected=='0'?' selected="true"':'').'>'.$langs->trans('OrderSource0').'</option>';
print '<option value="1"'.($selected=='1'?' selected="true"':'').'>'.$langs->trans('OrderSource1').'</option>';
print '<option value="2"'.($selected=='2'?' selected="true"':'').'>'.$langs->trans('OrderSource2').'</option>';
print '<option value="3"'.($selected=='3'?' selected="true"':'').'>'.$langs->trans('OrderSource3').'</option>';
print '<option value="4"'.($selected=='4'?' selected="true"':'').'>'.$langs->trans('OrderSource4').'</option>';
print '<option value="5"'.($selected=='5'?' selected="true"':'').'>'.$langs->trans('OrderSource5').'</option>';
print '</select>';
}
/**
* \brief Retourne la liste d<>roulante des pays actifs, dans la langue de l'utilisateur
* \param selected Code pays pr<70>-s<>lectionn<6E>
@@ -227,7 +250,6 @@ class Form
* \param htmloption Options html sur le select
* \todo trier liste sur noms apr<70>s traduction plutot que avant
*/
function select_pays($selected='',$htmlname='pays_id',$htmloption='')
{
global $conf,$langs;

View File

@@ -399,7 +399,7 @@ function dolibarr_time_plus_duree($time,$duration_value,$duration_unit)
\brief Formattage de la date en fonction de la langue $conf->langage
\param time Date 'timestamp' ou format 'YYYY-MM-DD' ou 'YYYY-MM-DD HH:MM:SS'
\param format Format d'affichage de la date ("%d %b %Y", "%d/%m/%Y", ...)
\return string Date format<61>e ou '?' si time null
\return string Date format<61>e ou '' si time null
*/
function dolibarr_print_date($time,$format='')
{
@@ -408,8 +408,8 @@ function dolibarr_print_date($time,$format='')
// Si format non d<>fini, on prend $conf->format_date_text_short
if (! $format) $format=$conf->format_date_text_short;
// Si date non d<>finie, on renvoie '?'
if (! $time) return '?';
// Si date non d<>finie, on renvoie ''
if (! $time) return '';
// Analyse de la date
if (eregi('^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?',$time,$reg))

View File

@@ -78,10 +78,8 @@ class User
* \param $DB handler acc<63>s base de donn<6E>es
* \param $id id de l'utilisateur (0 par d<>faut)
*/
function User($DB, $id=0)
{
$this->db = $DB;
$this->id = $id;
@@ -90,6 +88,7 @@ class User
$this->clicktodial_enabled = 0;
$this->all_permissions_are_loaded = 0;
$this->admin=0;
return 1;
}
@@ -564,7 +563,8 @@ class User
$this->db->begin();
$sql = "SELECT login FROM ".MAIN_DB_PREFIX."user WHERE login ='".addslashes($this->login)."'";
$sql = "SELECT login FROM ".MAIN_DB_PREFIX."user";
$sql.= " WHERE login ='".addslashes($this->login)."'";
$resql=$this->db->query($sql);
if ($resql)
{
@@ -574,7 +574,7 @@ class User
if ($num)
{
$this->error = $langs->trans("ErrorLoginAlreadyExists");
return -5;
return -6;
}
else
{
@@ -589,19 +589,17 @@ class User
// Set default rights
if ($this->set_default_rights() < 0)
{
$this->db->rollback();
$this->error=$this->db->error();
return -4;
$this->db->rollback();
return -5;
}
// Update minor fields
if ($this->update() < 0)
{
$this->db->rollback();
$this->error=$this->db->error();
return -5;
$this->db->rollback();
return -4;
}
// Appel des triggers
@@ -614,29 +612,27 @@ class User
if (! $error)
{
$this->db->commit();
return $this->id;
}
else
{
$this->db->rollback();
$this->error=$interface->error;
$this->db->rollback();
return -3;
}
}
else
{
$this->db->rollback();
$this->error=$this->db->error();
$this->db->rollback();
return -2;
}
}
}
else
{
$this->db->rollback();
$this->error=$this->db->error();
$this->db->rollback();
return -1;
}
}
@@ -767,6 +763,7 @@ class User
$this->pass=trim($this->pass);
$this->email=trim($this->email);
$this->note=trim($this->note);
$this->admin=$this->admin?$this->admin:0;
$error=0;
@@ -777,7 +774,7 @@ class User
$sql .= ", firstname = '".addslashes($this->prenom)."'";
$sql .= ", login = '".addslashes($this->login)."'";
if ($this->pass) $sql .= ", pass = '".addslashes($this->pass)."'";
$sql .= ", admin = $this->admin";
$sql .= ", admin = ".$this->admin;
$sql .= ", office_phone = '$this->office_phone'";
$sql .= ", office_fax = '$this->office_fax'";
$sql .= ", user_mobile = '$this->user_mobile'";