Fix a lot of bug in "source" field:

- missing creation table
- autoselect when creating order from proposal
- do not show proposal as origin when creating proposal
- use code instead of id
- use label in english
Also renamed table demand_reason into input_reason to match other table input_method.
This commit is contained in:
Laurent Destailleur
2011-05-07 11:36:47 +00:00
parent f4ed30f2dd
commit ff6182f62f
10 changed files with 137 additions and 84 deletions

View File

@@ -77,7 +77,7 @@ $tabname[18]= MAIN_DB_PREFIX."c_shipment_mode";
$tabname[19]= MAIN_DB_PREFIX."c_effectif";
$tabname[20]= MAIN_DB_PREFIX."c_input_method";
$tabname[21]= MAIN_DB_PREFIX."c_availability";
$tabname[22]= MAIN_DB_PREFIX."c_demand_reason";
$tabname[22]= MAIN_DB_PREFIX."c_input_reason";
// Dictionary labels
$tablib[1] = "DictionnaryCompanyJuridicalType";
@@ -125,7 +125,7 @@ $tabsql[18]= "SELECT rowid as rowid, code, libelle, active FROM ".MAIN_DB_PREF
$tabsql[19]= "SELECT id as rowid, code, libelle, active FROM ".MAIN_DB_PREFIX."c_effectif";
$tabsql[20]= "SELECT rowid as rowid, code, libelle, active FROM ".MAIN_DB_PREFIX."c_input_method";
$tabsql[21]= "SELECT c.rowid as rowid, code, label, active FROM ".MAIN_DB_PREFIX."c_availability AS c";
$tabsql[22]= "SELECT rowid as rowid, code, label, active FROM ".MAIN_DB_PREFIX."c_demand_reason";
$tabsql[22]= "SELECT rowid as rowid, code, label, active FROM ".MAIN_DB_PREFIX."c_input_reason";
// Critere de tri du dictionnaire
$tabsqlsort[1] ="pays ASC, code ASC";

View File

@@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2011 Philippe Grand <philippe.grand@atoo-net.com>
@@ -43,6 +43,13 @@ $langs->load("bills");
$langs->load("orders");
$langs->load("deliveries");
/*
* Actions
*/
// None
/*
* View
@@ -55,9 +62,7 @@ print_fiche_titre($langs->trans("NewProp"));
$html=new Form($db);
/*
* Creation d'une nouvelle propale
*/
// Add new proposal
if ($_GET["action"] == 'create')
{
$soc = new Societe($db);
@@ -127,9 +132,7 @@ if ($_GET["action"] == 'create')
print '</td>';
print '</tr>';
/*
* Contact de la propale
*/
// Contacts
print "<tr><td>".$langs->trans("DefaultContact")."</td><td colspan=\"2\">\n";
$html->select_contacts($soc->id,$setcontact,'contactidp',1);
print '</td></tr>';
@@ -162,14 +165,14 @@ if ($_GET["action"] == 'create')
$html->select_types_paiements($soc->mode_reglement,'mode_reglement_id');
print '</td></tr>';
// Source de propale
// What trigger creation
print '<tr><td>'.$langs->trans('Source').'</td><td>';
$html->select_demand_reason($soc->demand_reason,'demand_reason_id');
$html->select_demand_reason($propal->demand_reason,'demand_reason_id',"SRC_PROP",1);
print '</td></tr>';
// delai de livraison
print '<tr><td>'.$langs->trans('AvailabilityPeriod').'</td><td colspan="2">';
$html->select_availability($soc->availability,'availability_id');
$html->select_availability($propal->availability,'availability_id');
print '</td></tr>';
// Delivery date (or manufacturing)

View File

@@ -1321,9 +1321,10 @@ if ($id > 0 || ! empty($ref))
if ($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="3">';
//print $object->demand_reason_id;
if ($action == 'editdemandreason')
{
$html->form_demand_reason($_SERVER['PHP_SELF'].'?id='.$object->id,$object->demand_reason_id,'demand_reason_id');
$html->form_demand_reason($_SERVER['PHP_SELF'].'?id='.$object->id,$object->demand_reason_id,'demand_reason_id',1);
}
else
{

View File

@@ -971,7 +971,7 @@ class Propal extends CommonObject
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as cp ON p.fk_mode_reglement = cp.id';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as cr ON p.fk_cond_reglement = cr.rowid';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_availability as ca ON p.fk_availability = ca.rowid';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_demand_reason as dr ON p.fk_demand_reason = dr.rowid';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_input_reason as dr ON p.fk_demand_reason = dr.rowid';
$sql.= " WHERE p.fk_statut = c.id";
$sql.= " AND p.entity = ".$conf->entity;
if ($ref) $sql.= " AND p.ref='".$ref."'";

View File

@@ -1180,7 +1180,7 @@ class Commande extends CommonObject
$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.'c_input_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."'";

View File

@@ -1274,15 +1274,15 @@ 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');
$html->select_availability($propal->availability,'availability_id');
print '</td></tr>';
// Source de commande
// What trigger creation
print '<tr><td>'.$langs->trans('Source').'</td><td>';
$html->select_demand_reason($soc->demand_reason,'demand_reason_id');
$html->select_demand_reason((GETPOST("origin")=='propal'?'SRC_COMM':''),'demand_reason_id','',1);
print '</td></tr>';
// Projet
// Project
if ($conf->projet->enabled)
{
$projectid = 0;
@@ -1297,10 +1297,6 @@ if ($action == 'create' && $user->rights->commande->creer)
print '</td></tr>';
}
print '<tr><td>'.$langs->trans('Source').'</td><td colspan="2">';
$formorder->selectSourcesCommande((GETPOST("origin")=='propal'?'0':''),'source_id',1);
print '</td></tr>';
print '<tr><td>'.$langs->trans('Model').'</td>';
print '<td colspan="2">';
// pdf
@@ -1770,7 +1766,7 @@ else
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');
$html->form_demand_reason($_SERVER['PHP_SELF'].'?id='.$object->id,$object->demand_reason_id,'demand_reason_id',1);
}
else
{

View File

@@ -1535,17 +1535,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
* Load into cache cache_demand_reason, array of input reasons
* @return int Nb of lines loaded, 0 if already loaded, <0 if ko
*/
function load_cache_demand_reason()
{
global $langs;
if (sizeof($this->cache_demand_reason)) return 0; // Cache deja charge
if (sizeof($this->cache_demand_reason)) return 0; // Cache already loaded
$sql = "SELECT rowid, code, label";
$sql.= " FROM ".MAIN_DB_PREFIX.'c_demand_reason';
$sql.= " FROM ".MAIN_DB_PREFIX.'c_input_reason';
$sql.= " WHERE active=1";
$sql.= " ORDER BY rowid";
dol_syslog('Form::load_cache_demand_reason sql='.$sql,LOG_DEBUG);
@@ -1554,16 +1554,21 @@ class Form
{
$num = $this->db->num_rows($resql);
$i = 0;
$tmparray=array();
while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
// Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
$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;
$tmparray[$obj->rowid]['id'] =$obj->rowid;
$tmparray[$obj->rowid]['code'] =$obj->code;
$tmparray[$obj->rowid]['label']=$label;
$i++;
}
$this->cache_demand_reason=dol_sort_array($tmparray,'label');
//var_dump($this->cache_demand_reason);exit;
unset($tmparray);
return 1;
}
else {
@@ -1573,29 +1578,31 @@ class Form
}
/**
* \brief Retourne la liste des types d'origine de propal/commande possibles
* \param selected Id du type d'origine pre-selectionne
* \param htmlname Nom de la zone select
* \param filtertype Pour filtre
* \param addempty Ajoute entree vide
* Return list of events that triggered an object creation
* @param selected Id du type d'origine pre-selectionne
* @param htmlname Nom de la zone select
* @param exclude To exclude a code value (Example: SRC_PROP)
* @param addempty Add an empty entry
*/
function select_demand_reason($selected='',$htmlname='demandreasonid',$filtertype='',$addempty=0)
function select_demand_reason($selected='',$htmlname='demandreasonid',$exclude='',$addempty=0)
{
global $langs,$user;
$this->load_cache_demand_reason();
print '<select class="flat" name="'.$htmlname.'">';
if ($addempty) print '<option value="0">&nbsp;</option>';
if ($addempty) print '<option value="0"'.(empty($selected)?' selected="selected"':'').'>&nbsp;</option>';
foreach($this->cache_demand_reason as $id => $arraydemandreason)
{
if ($selected == $id)
if ($arraydemandreason['code']==$exclude) continue;
if ($selected == $arraydemandreason['id'])
{
print '<option value="'.$id.'" selected="selected">';
print '<option value="'.$arraydemandreason['id'].'" selected="selected">';
}
else
{
print '<option value="'.$id.'">';
print '<option value="'.$arraydemandreason['id'].'">';
}
print $arraydemandreason['label'];
print '</option>';
@@ -2235,11 +2242,11 @@ class Form
}
/**
* \brief Affiche formulaire de selection d'origine de propal/commande
* \param page Page
* \param selected Id condition pre-selectionne
* \param htmlname Name of select html field
* \param addempty Ajoute entree vide
* Affiche formulaire de selection d'origine de propal/commande
* @param page Page
* @param selected Id condition pre-selectionne
* @param htmlname Name of select html field
* @param addempty Ajoute entree vide
*/
function form_demand_reason($page, $selected='', $htmlname='demandreason', $addempty=0)
{
@@ -2261,7 +2268,14 @@ class Form
if ($selected)
{
$this->load_cache_demand_reason();
print $this->cache_demand_reason[$selected]['label'];
foreach ($this->cache_demand_reason as $key => $val)
{
if ($val['id'] == $selected)
{
print $val['label'];
break;
}
}
} else {
print "&nbsp;";
}

View File

@@ -0,0 +1,32 @@
-- Copyright (C) 2011 Laurent Destailleur <eldy@users.sourceforge.net>
-- Copyright (C) 2011 Philippe Grand
--
-- 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,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- 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.
--
-- $Id$
--
--
-- Ne pas placer de commentaire en fin de ligne, ce fichier est parsé lors
-- de l'install et tous les sigles '--' sont supprimés.
--
INSERT INTO llx_c_input_reason (rowid,code,label,active) VALUES (1, 'SRC_INTE', 'Web site', 1);
INSERT INTO llx_c_input_reason (rowid,code,label,active) VALUES (2, 'SRC_CAMP_MAIL', 'Mailing campaign', 1);
INSERT INTO llx_c_input_reason (rowid,code,label,active) VALUES (3, 'SRC_CAMP_PHO', 'Phone campaign', 1);
INSERT INTO llx_c_input_reason (rowid,code,label,active) VALUES (4, 'SRC_CAMP_FAX', 'Fax campaign', 1);
INSERT INTO llx_c_input_reason (rowid,code,label,active) VALUES (5, 'SRC_COMM', 'Commercial contact', 1);
INSERT INTO llx_c_input_reason (rowid,code,label,active) VALUES (6, 'SRC_SHOP', 'Shop contact', 1);
INSERT INTO llx_c_input_reason (rowid,code,label,active) VALUES (7, 'SRC_CAMP_EMAIL', 'EMailing campaign', 1);

View File

@@ -65,15 +65,24 @@ CREATE TABLE llx_c_availability
)ENGINE=innodb;
CREATE TABLE llx_c_demand_reason
-- Use table name input_reason to match also input_method
DROP table llx_c_demand_reason;
CREATE TABLE llx_c_input_reason
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
code varchar(30) NOT NULL,
label varchar(60) NOT NULL,
active tinyint DEFAULT 1 NOT NULL
)ENGINE=innodb;
INSERT INTO llx_c_input_reason (rowid,code,label,active) VALUES (1, 'SRC_INTE', 'Web site', 1);
INSERT INTO llx_c_input_reason (rowid,code,label,active) VALUES (2, 'SRC_CAMP_MAIL', 'Mailing campaign', 1);
INSERT INTO llx_c_input_reason (rowid,code,label,active) VALUES (3, 'SRC_CAMP_PHO', 'Phone campaign', 1);
INSERT INTO llx_c_input_reason (rowid,code,label,active) VALUES (4, 'SRC_CAMP_FAX', 'Fax campaign', 1);
INSERT INTO llx_c_input_reason (rowid,code,label,active) VALUES (5, 'SRC_COMM', 'Commercial contact', 1);
INSERT INTO llx_c_input_reason (rowid,code,label,active) VALUES (6, 'SRC_SHOP', 'Shop contact', 1);
INSERT INTO llx_c_input_reason (rowid,code,label,active) VALUES (7, 'SRC_CAMP_EMAIL', 'EMailing campaign', 1);
ALTER TABLE llx_propal CHANGE COLUMN delivery fk_availability integer NULL;
ALTER TABLE llx_propal ADD COLUMN fk_availability integer NULL AFTER date_livraison;
ALTER TABLE llx_commande ADD COLUMN fk_availability integer NULL AFTER date_livraison;
@@ -83,14 +92,6 @@ INSERT INTO llx_c_availability (rowid,code,label,active) VALUES (2, 'AV_1W', '1
INSERT INTO llx_c_availability (rowid,code,label,active) VALUES (3, 'AV_2W', '2 weeks', 1);
INSERT INTO llx_c_availability (rowid,code,label,active) VALUES (4, 'AV_3W', '3 weeks', 1);
INSERT INTO llx_c_demand_reason (rowid,code,label,active) VALUES (1, 'SRC_00', 'Proposition commerciale', 1);
INSERT INTO llx_c_demand_reason (rowid,code,label,active) VALUES (2, 'SRC_01', 'Internet', 1);
INSERT INTO llx_c_demand_reason (rowid,code,label,active) VALUES (3, 'SRC_02', 'Campagne courrier', 1);
INSERT INTO llx_c_demand_reason (rowid,code,label,active) VALUES (4, 'SRC_03', 'Campagne téléphone', 1);
INSERT INTO llx_c_demand_reason (rowid,code,label,active) VALUES (5, 'SRC_04', 'Campagne fax', 1);
INSERT INTO llx_c_demand_reason (rowid,code,label,active) VALUES (6, 'SRC_05', 'Commercial', 1);
INSERT INTO llx_c_demand_reason (rowid,code,label,active) VALUES (7, 'SRC_06', 'Magasin', 1);
ALTER TABLE llx_actioncomm ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER id;
ALTER TABLE llx_propaldet ADD INDEX idx_propaldet_fk_product (fk_product);

View File

@@ -3512,6 +3512,12 @@ function dol_htmloutput_errors($mesgstring='', $mesgarray='', $keepembedded=0)
* ascending (default) or descending output and uses optionally
* natural case insensitive sorting (which can be optionally case
* sensitive as well).
* @param array Array to sort
* @param index
* @param order
* @param natsort
* @param cas_sensitive
* @return Sorted array
*/
function dol_sort_array(&$array, $index, $order='asc', $natsort, $case_sensitive)
{