To get source of command on command file

This commit is contained in:
Philippe Grand
2011-04-26 20:59:45 +00:00
parent 14ac9e3f19
commit 09786cabeb
4 changed files with 123 additions and 19 deletions

View File

@@ -64,6 +64,8 @@ class Commande extends CommonObject
var $mode_reglement_code;
var $availability_id;
var $availability_code;
var $demand_reason_id;
var $demand_reason_code;
var $fk_delivery_address;
var $adresse;
var $date; // Date commande
@@ -567,7 +569,7 @@ class Commande extends CommonObject
$sql = "INSERT INTO ".MAIN_DB_PREFIX."commande (";
$sql.= " ref, fk_soc, date_creation, fk_user_author, fk_projet, date_commande, source, note, note_public, ref_client";
$sql.= ", model_pdf, fk_cond_reglement, fk_mode_reglement, fk_availability, date_livraison, fk_adresse_livraison";
$sql.= ", model_pdf, fk_cond_reglement, fk_mode_reglement, fk_availability, fk_demand_reason, date_livraison, fk_adresse_livraison";
$sql.= ", remise_absolue, remise_percent";
$sql.= ", entity";
$sql.= ")";
@@ -580,6 +582,7 @@ class Commande extends CommonObject
$sql.= ", ".($this->cond_reglement_id>0?"'".$this->cond_reglement_id."'":"null");
$sql.= ", ".($this->mode_reglement_id>0?"'".$this->mode_reglement_id."'":"null");
$sql.= ", ".($this->availability_id>0?"'".$this->availability_id."'":"null");
$sql.= ", ".($this->demand_reason_id>0?"'".$this->demand_reason_id."'":"null");
$sql.= ", ".($this->date_livraison?"'".$this->db->idate($this->date_livraison)."'":"null");
$sql.= ", ".($this->fk_delivery_address>0?$this->fk_delivery_address:'NULL');
$sql.= ", ".($this->remise_absolue>0?$this->remise_absolue:'NULL');
@@ -854,6 +857,7 @@ class Commande extends CommonObject
$this->cond_reglement_id = $object->cond_reglement_id;
$this->mode_reglement_id = $object->mode_reglement_id;
$this->availability_id = $object->availability_id;
$this->demand_reason_id = $object->demand_reason_id;
$this->date_livraison = $object->date_livraison;
$this->fk_delivery_address = $object->fk_delivery_address;
$this->contact_id = $object->contactid;
@@ -1142,7 +1146,7 @@ class Commande extends CommonObject
if (empty($id) && empty($ref)) return -1;
$sql = 'SELECT c.rowid, c.date_creation, c.ref, c.fk_soc, c.fk_user_author, c.fk_statut';
$sql.= ', c.amount_ht, c.total_ht, c.total_ttc, c.tva as total_tva, c.localtax1 as total_localtax1, c.localtax2 as total_localtax2, c.fk_cond_reglement, c.fk_mode_reglement, c.fk_availability';
$sql.= ', c.amount_ht, c.total_ht, c.total_ttc, c.tva as total_tva, c.localtax1 as total_localtax1, c.localtax2 as total_localtax2, c.fk_cond_reglement, c.fk_mode_reglement, c.fk_availability, c.fk_demand_reason';
$sql.= ', c.date_commande';
$sql.= ', c.date_livraison';
$sql.= ', c.fk_projet, c.remise_percent, c.remise, c.remise_absolue, c.source, c.facture as facturee';
@@ -1150,11 +1154,13 @@ class Commande extends CommonObject
$sql.= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
$sql.= ', cr.code as cond_reglement_code, cr.libelle as cond_reglement_libelle, cr.libelle_facture as cond_reglement_libelle_doc';
$sql.= ', ca.code as availability_code';
$sql.= ', dr.code as demand_reason_code';
$sql.= ', el.fk_source';
$sql.= ' FROM '.MAIN_DB_PREFIX.'commande as c';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as cr ON (c.fk_cond_reglement = cr.rowid)';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON (c.fk_mode_reglement = p.id)';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_availability as ca ON (c.fk_availability = ca.rowid)';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_demand_reason as dr ON (c.fk_demand_reason = ca.rowid)';
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = c.rowid AND el.targettype = '".$this->element."'";
$sql.= " WHERE c.entity = ".$conf->entity;
if ($ref) $sql.= " AND c.ref='".$ref."'";
@@ -1198,6 +1204,8 @@ class Commande extends CommonObject
$this->cond_reglement_doc = $obj->cond_reglement_libelle_doc;
$this->availability_id = $obj->fk_availability;
$this->availability_code = $obj->availability_code;
$this->demand_reason_id = $obj->fk_demand_reason;
$this->demand_reason_code = $obj->demand_reason_code;
$this->date_livraison = $this->db->jdate($obj->date_livraison);
$this->fk_delivery_address = $obj->fk_adresse_livraison;
$this->propale_id = $obj->fk_source;
@@ -1810,6 +1818,34 @@ class Commande extends CommonObject
}
}
/**
* \brief Set source of demand
* \param user Objet utilisateur qui modifie
* \param delivery delai de livraison
* \return int <0 si ko, >0 si ok
*/
function set_demand_reason($user, $id)
{
if ($user->rights->commande->creer)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."commande ";
$sql.= " SET fk_demand_reason = '".$id."'";
$sql.= " WHERE rowid = ".$this->id;
if ($this->db->query($sql))
{
$this->fk_demand_reason = $id;
return 1;
}
else
{
$this->error=$this->db->error();
dol_syslog("Commande::set_demand_reason Erreur SQL");
return -1;
}
}
}
/**
* \brief Return list of orders (eventuelly filtered on a user) into an array
* \param brouillon 0=non brouillon, 1=brouillon
@@ -1954,6 +1990,39 @@ class Commande extends CommonObject
}
}
/**
* \brief Change la source de la demande
* \param mode Id du nouveau mode
* \return int >0 si ok, <0 si ko
*/
function demand_reason($demand_reason_id)
{
dol_syslog('Commande::demand_reason('.$demand_reason_id.')');
if ($this->statut >= 0)
{
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande';
$sql .= ' SET fk_demand_reason = '.$demand_reason_id;
$sql .= ' WHERE rowid='.$this->id;
if ( $this->db->query($sql) )
{
$this->demand_reason_id = $demand_reason_id;
return 1;
}
else
{
dol_syslog('Commande::demand_reason Erreur '.$sql.' - '.$this->db->error(), LOG_ERR);
$this->error=$this->db->lasterror();
return -1;
}
}
else
{
dol_syslog('Commande::demand_reason, etat facture incompatible', LOG_ERR);
$this->error='Etat commande incompatible '.$this->statut;
return -2;
}
}
/**
* \brief Set customer ref
* \param user User that make change
@@ -2495,6 +2564,7 @@ class Commande extends CommonObject
$this->cond_reglement_code = 'RECEP';
$this->mode_reglement_code = 'CHQ';
$this->availability_code = 'DSP';
$this->demand_reason_code = 'SRC_00';
$this->note_public='This is a comment (public)';
$this->note='This is a comment (private)';
// Lines

View File

@@ -208,6 +208,7 @@ if ($action == 'add' && $user->rights->commande->creer)
$object->cond_reglement_id = $_POST['cond_reglement_id'];
$object->mode_reglement_id = $_POST['mode_reglement_id'];
$object->availability_id = $_POST['availability_id'];
$object->demand_reason_id = $_POST['demand_reason_id'];
$object->date_livraison = $datelivraison;
$object->fk_delivery_address = $_POST['fk_address'];
$object->contactid = $_POST['contactidp'];
@@ -463,6 +464,13 @@ if ($action == 'setavailability' && $user->rights->commande->creer)
if ($result < 0) dol_print_error($db,$object->error);
}
if ($action == 'setdemandreason' && $user->rights->commande->creer)
{
$object->fetch($id);
$result=$object->demand_reason($_POST['demand_reason_id']);
if ($result < 0) dol_print_error($db,$object->error);
}
if ($action == 'setconditions' && $user->rights->commande->creer)
{
$object->fetch($id);
@@ -1161,6 +1169,7 @@ if ($action == 'create' && $user->rights->commande->creer)
$cond_reglement_id = (!empty($objectsrc->cond_reglement_id)?$objectsrc->cond_reglement_id:(!empty($soc->cond_reglement_id)?$soc->cond_reglement_id:1));
$mode_reglement_id = (!empty($objectsrc->mode_reglement_id)?$objectsrc->mode_reglement_id:(!empty($soc->mode_reglement_id)?$soc->mode_reglement_id:0));
$availability_id = (!empty($objectsrc->availability_id)?$objectsrc->availability_id:(!empty($soc->availability_id)?$soc->availability_id:0));
$demand_reason_id = (!empty($objectsrc->demand_reason_id)?$objectsrc->demand_reason_id:(!empty($soc->demand_reason_id)?$soc->demand_reason_id:0));
$remise_percent = (!empty($objectsrc->remise_percent)?$objectsrc->remise_percent:(!empty($soc->remise_percent)?$soc->remise_percent:0));
$remise_absolue = (!empty($objectsrc->remise_absolue)?$objectsrc->remise_absolue:(!empty($soc->remise_absolue)?$soc->remise_absolue:0));
$dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0;
@@ -1174,6 +1183,7 @@ if ($action == 'create' && $user->rights->commande->creer)
$cond_reglement_id = $soc->cond_reglement_id;
$mode_reglement_id = $soc->mode_reglement_id;
$availability_id = $soc->availability_id;
$demand_reason_id = $soc->demand_reason_id;
$remise_percent = $soc->remise_percent;
$remise_absolue = 0;
$dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0;
@@ -1265,6 +1275,11 @@ if ($action == 'create' && $user->rights->commande->creer)
// delai de livraison
print '<tr><td>'.$langs->trans('AvailabilityPeriod').'</td><td>';
$html->select_availability($soc->availability,'availability_id');
print '</td></tr>';
// Source de commande
print '<tr><td>'.$langs->trans('Source').'</td><td>';
$html->select_demand_reason($soc->demand_reason,'demand_reason_id');
print '</td></tr>';
// Projet
@@ -1743,6 +1758,24 @@ else
{
$html->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id,$object->availability_id,'none');
}
print '</td></tr>';
// Origine de la demande
print '<tr><td height="10">';
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('Source');
print '</td>';
if ($_GET['action'] != 'editdemandreason' && $object->brouillon) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdemandreason&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDemandReason'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="2">';
if ($_GET['action'] == 'editdemandreason')
{
$html->form_demand_reason($_SERVER['PHP_SELF'].'?id='.$object->id,$object->demand_reason_id,'demand_reason_id');
}
else
{
$html->form_demand_reason($_SERVER['PHP_SELF'].'?id='.$object->id,$object->demand_reason_id,'none');
}
print '</td></tr>';
// Project

View File

@@ -49,7 +49,7 @@ class Form
var $cache_types_paiements=array();
var $cache_conditions_paiements=array();
var $cache_availability=array();
var $cache_source=array();
var $cache_demand_reason=array();
var $tva_taux_value;
var $tva_taux_libelle;
@@ -1538,17 +1538,17 @@ class Form
* \brief Charge dans cache la liste des origines de commande possibles
* \return int Nb lignes chargees, 0 si deja chargees, <0 si ko
*/
function load_cache_source()
function load_cache_demand_reason()
{
global $langs;
if (sizeof($this->cache_source)) return 0; // Cache deja charge
if (sizeof($this->cache_demand_reason)) return 0; // Cache deja charge
$sql = "SELECT rowid, code, label";
$sql.= " FROM ".MAIN_DB_PREFIX.'c_source';
$sql.= " FROM ".MAIN_DB_PREFIX.'c_demand_reason';
$sql.= " WHERE active=1";
$sql.= " ORDER BY rowid";
dol_syslog('Form::load_cache_source sql='.$sql,LOG_DEBUG);
dol_syslog('Form::load_cache_demand_reason sql='.$sql,LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
@@ -1559,9 +1559,9 @@ class Form
$obj = $this->db->fetch_object($resql);
// Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
$label=($langs->trans("SourceType".$obj->code)!=("SourceType".$obj->code)?$langs->trans("SourceType".$obj->code):($obj->label!='-'?$obj->label:''));
$this->cache_source[$obj->rowid]['code'] =$obj->code;
$this->cache_source[$obj->rowid]['label']=$label;
$label=($langs->trans("DemandReasonType".$obj->code)!=("DemandReasonType".$obj->code)?$langs->trans("DemandReasonType".$obj->code):($obj->label!='-'?$obj->label:''));
$this->cache_demand_reason[$obj->rowid]['code'] =$obj->code;
$this->cache_demand_reason[$obj->rowid]['label']=$label;
$i++;
}
return 1;
@@ -1579,15 +1579,15 @@ class Form
* \param filtertype Pour filtre
* \param addempty Ajoute entree vide
*/
function select_source($selected='',$htmlname='sourceid',$filtertype='',$addempty=0)
function select_demand_reason($selected='',$htmlname='demandreasonid',$filtertype='',$addempty=0)
{
global $langs,$user;
$this->load_cache_source();
$this->load_cache_demand_reason();
print '<select class="flat" name="'.$htmlname.'">';
if ($addempty) print '<option value="0">&nbsp;</option>';
foreach($this->cache_source as $id => $arraysource)
foreach($this->cache_demand_reason as $id => $arraydemandreason)
{
if ($selected == $id)
{
@@ -1597,7 +1597,7 @@ class Form
{
print '<option value="'.$id.'">';
}
print $arraysource['label'];
print $arraydemandreason['label'];
print '</option>';
}
print '</select>';
@@ -2238,17 +2238,17 @@ class Form
* \param htmlname Name of select html field
* \param addempty Ajoute entree vide
*/
function form_source($page, $selected='', $htmlname='source', $addempty=0)
function form_demand_reason($page, $selected='', $htmlname='demandreason', $addempty=0)
{
global $langs;
if ($htmlname != "none")
{
print '<form method="post" action="'.$page.'">';
print '<input type="hidden" name="action" value="setsource">';
print '<input type="hidden" name="action" value="setdemandreason">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
print '<tr><td>';
$this->select_source($selected,$htmlname,-1,$addempty);
$this->select_demand_reason($selected,$htmlname,-1,$addempty);
print '</td>';
print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
print '</tr></table></form>';
@@ -2257,8 +2257,8 @@ class Form
{
if ($selected)
{
$this->load_cache_source();
print $this->cache_source[$selected]['label'];
$this->load_cache_demand_reason();
print $this->cache_demand_reason[$selected]['label'];
} else {
print "&nbsp;";
}

View File

@@ -37,6 +37,7 @@ DELETE FROM llx_const WHERE __DECRYPT('name')__ = 'MAIN_MENUFRONT_BARRELEFT';
ALTER TABLE llx_facture_fourn ADD COLUMN ref_ext varchar(30) AFTER entity;
ALTER TABLE llx_commande_fournisseur ADD COLUMN ref_ext varchar(30) AFTER entity;
ALTER TABLE llx_commande ADD COLUMN fk_demand_reason int(11) AFTER fk_availability;
ALTER TABLE llx_facturedet DROP INDEX uk_fk_remise_except;