New: add "extraparams" field for stock extra parameters with json

This commit is contained in:
Regis Houssin 2012-03-16 14:32:37 +01:00
parent 1622a86d71
commit 391ce8490f
10 changed files with 156 additions and 30 deletions

View File

@ -96,6 +96,7 @@ class Propal extends CommonObject
var $demand_reason_code;
var $products=array();
var $extraparams=array();
var $lines = array();
var $line;
@ -945,25 +946,25 @@ class Propal extends CommonObject
{
global $conf;
$sql = "SELECT p.rowid,ref,remise,remise_percent,remise_absolue,fk_soc";
$sql.= ", total, tva, localtax1, localtax2, total_ht";
$sql.= ", datec";
$sql.= ", date_valid as datev";
$sql.= ", datep as dp";
$sql.= ", fin_validite as dfv";
$sql.= ", date_livraison as date_livraison";
$sql.= ", ca.code as availability_code, ca.label as availability";
$sql.= ", dr.code as demand_reason_code, dr.label as demand_reason";
$sql.= ", model_pdf, ref_client";
$sql.= ", note as note_private, note_public";
$sql.= ", fk_projet, fk_statut";
$sql.= ", fk_user_author, fk_user_valid, fk_user_cloture";
$sql.= ", fk_adresse_livraison";
$sql = "SELECT p.rowid, p.ref, p.remise, p.remise_percent, p.remise_absolue, p.fk_soc";
$sql.= ", p.total, p.tva, p.localtax1, p.localtax2, p.total_ht";
$sql.= ", p.datec";
$sql.= ", p.date_valid as datev";
$sql.= ", p.datep as dp";
$sql.= ", p.fin_validite as dfv";
$sql.= ", p.date_livraison as date_livraison";
$sql.= ", p.model_pdf, p.ref_client, p.extraparams";
$sql.= ", p.note as note_private, p.note_public";
$sql.= ", p.fk_projet, p.fk_statut";
$sql.= ", p.fk_user_author, p.fk_user_valid, p.fk_user_cloture";
$sql.= ", p.fk_adresse_livraison";
$sql.= ", p.fk_availability";
$sql.= ", p.fk_demand_reason";
$sql.= ", p.fk_cond_reglement";
$sql.= ", p.fk_mode_reglement";
$sql.= ", c.label as statut_label";
$sql.= ", ca.code as availability_code, ca.label as availability";
$sql.= ", dr.code as demand_reason_code, dr.label as demand_reason";
$sql.= ", cr.code as cond_reglement_code, cr.libelle as cond_reglement, cr.libelle_facture as cond_reglement_libelle_doc";
$sql.= ", cp.code as mode_reglement_code, cp.libelle as mode_reglement";
$sql.= " FROM ".MAIN_DB_PREFIX."c_propalst as c, ".MAIN_DB_PREFIX."propal as p";
@ -1023,13 +1024,15 @@ class Propal extends CommonObject
$this->fk_delivery_address = $obj->fk_adresse_livraison; // TODO obsolete
$this->fk_address = $obj->fk_adresse_livraison;
$this->mode_reglement_id = $obj->fk_mode_reglement;
$this->mode_reglement_code = $obj->mode_reglement_code;
$this->mode_reglement = $obj->mode_reglement;
$this->cond_reglement_id = $obj->fk_cond_reglement;
$this->cond_reglement_code = $obj->cond_reglement_code;
$this->cond_reglement = $obj->cond_reglement;
$this->cond_reglement_doc = $obj->cond_reglement_libelle_doc;
$this->mode_reglement_id = $obj->fk_mode_reglement;
$this->mode_reglement_code = $obj->mode_reglement_code;
$this->mode_reglement = $obj->mode_reglement;
$this->cond_reglement_id = $obj->fk_cond_reglement;
$this->cond_reglement_code = $obj->cond_reglement_code;
$this->cond_reglement = $obj->cond_reglement;
$this->cond_reglement_doc = $obj->cond_reglement_libelle_doc;
$this->extraparams = (array) dol_json_decode($obj->extraparams, true);
$this->user_author_id = $obj->fk_user_author;
$this->user_valid_id = $obj->fk_user_valid;

View File

@ -86,6 +86,7 @@ class Commande extends CommonObject
var $note; // deprecated
var $note_private;
var $note_public;
var $extraparams=array();
var $origin;
var $origin_id;
@ -1224,7 +1225,7 @@ class Commande extends CommonObject
$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';
$sql.= ', c.note as note_private, c.note_public, c.ref_client, c.ref_ext, c.ref_int, c.model_pdf, c.fk_adresse_livraison';
$sql.= ', c.note as note_private, c.note_public, c.ref_client, c.ref_ext, c.ref_int, c.model_pdf, c.fk_adresse_livraison, c.extraparams';
$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';
@ -1288,6 +1289,8 @@ class Commande extends CommonObject
$this->date_livraison = $this->db->jdate($obj->date_livraison);
$this->fk_delivery_address = $obj->fk_adresse_livraison;
$this->propale_id = $obj->fk_source;
$this->extraparams = (array) dol_json_decode($obj->extraparams, true);
$this->lines = array();

View File

@ -102,6 +102,7 @@ class Facture extends CommonObject
var $products=array(); // deprecated
var $lines=array();
var $line;
var $extraparams=array();
//! Pour board
var $nbtodo;
var $nbtodolate;
@ -766,7 +767,7 @@ class Facture extends CommonObject
$sql.= ', f.tms as datem';
$sql.= ', f.note as note_private, f.note_public, f.fk_statut, f.paye, f.close_code, f.close_note, f.fk_user_author, f.fk_user_valid, f.model_pdf';
$sql.= ', f.fk_facture_source';
$sql.= ', f.fk_mode_reglement, f.fk_cond_reglement, f.fk_projet';
$sql.= ', f.fk_mode_reglement, f.fk_cond_reglement, f.fk_projet, f.extraparams';
$sql.= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
$sql.= ', c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_doc';
$sql.= ' FROM '.MAIN_DB_PREFIX.'facture as f';
@ -825,6 +826,8 @@ class Facture extends CommonObject
$this->user_author = $obj->fk_user_author;
$this->user_valid = $obj->fk_user_valid;
$this->modelpdf = $obj->model_pdf;
$this->extraparams = (array) dol_json_decode($obj->extraparams, true);
if ($this->statut == 0) $this->brouillon = 1;

View File

@ -0,0 +1,70 @@
<?php
/* Copyright (C) 2012 Regis Houssin <regis@dolibarr.fr>
*
* 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, see <http://www.gnu.org/licenses/>.
*/
/**
* \file /htdocs/core/ajax/showhide.php
* \brief File to return Ajax response on set show/hide element
*/
if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Disables token renewal
if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
include("../../main.inc.php");
$id = GETPOST('id','int');
$element = GETPOST('element','alpha');
$htmlelement = GETPOST('htmlelement','alpha');
$type = GETPOST('type', 'alpha');
/*
* View
*/
top_httphead();
print '<!-- Ajax page called with url '.$_SERVER["PHP_SELF"].'?'.$_SERVER["QUERY_STRING"].' -->'."\n";
// Registering the location of boxes
if(! empty($id) && ! empty($element) && ! empty($htmlelement) && ! empty($type))
{
$value = GETPOST('value','alpha');
$params=array();
dol_syslog("AjaxSetExtraParameters id=".$id." element=".$element." htmlelement=".$htmlelement." type=".$type." value=".$value, LOG_DEBUG);
// For compatibility
if ($element == 'order' || $element == 'commande') { $element = $subelement = 'commande'; }
if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; }
if ($element == 'facture') { $element = 'compta/facture'; $subelement = 'facture'; }
if ($element == 'contract') { $element = $subelement = 'contrat'; }
if ($element == 'shipping') { $element = $subelement = 'expedition'; }
dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
$classname = ucfirst($subelement);
$object = new $classname($db);
$object->id = $id;
$params[$htmlelement] = array($type => $value);
$result=$object->setExtraParameters($params);
}
?>

View File

@ -2127,6 +2127,38 @@ abstract class CommonObject
dol_syslog(get_class($this).'::hasProductsOrServices we found '.$nb.' qualified lines of products/servcies');
return $nb;
}
/**
* Set extra parameters
*
* @param array $params Extra parameters
*/
function setExtraParameters($params)
{
$this->db->begin();
$this->extraparams = array_merge($this->extraparams, (array) $params);
$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
$sql.= ' SET extraparams = "'.$this->db->escape(dol_json_encode($this->extraparams)).'"';
$sql.= ' WHERE rowid = '.$this->id;
dol_syslog(get_class($this)."::setExtraParameters sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql);
if (! $resql)
{
$this->error=$this->db->lasterror();
dol_syslog(get_class($this)."::setExtraParameters ".$this->error, LOG_ERR);
$this->db->rollback();
return -1;
}
else
{
$this->db->commit();
return 1;
}
}
// --------------------
// TODO: All functions here must be redesigned and moved as they are not business functions but output functions

View File

@ -16,6 +16,7 @@
*
*/
$hide = $object->extraparams['notes']['showhide'];
$module = $object->element;
if ($module == 'propal') $module = 'propale';
@ -38,14 +39,17 @@ $(document).ready(function() {
$("#hide-notes").show();
});
function setShowHide(status) {
var id = <?php echo $object->id; ?>;
var element = '<?php echo $object->element; ?>';
//$.get("<?php echo dol_buildpath('/core/ajax/showhide.php', 1); ?>?id="+id+"&element="+element+"&status="+status);
var id = <?php echo $object->id; ?>;
var element = '<?php echo $object->element; ?>';
var htmlelement = 'notes';
var type = 'showhide';
$.get("<?php echo dol_buildpath('/core/ajax/extraparams.php', 1); ?>?id="+id+"&element="+element+"&htmlelement="+htmlelement+"&type="+type+"&value="+status);
}
});
</script>
<table class="border" width="100%">
<table class="border allwidth">
<tr class="liste_titre">
<td colspan="2">

View File

@ -434,4 +434,10 @@ ALTER TABLE llx_product_fournisseur_price DROP INDEX idx_product_fournisseur_pri
--ALTER TABLE llx_product_fournisseur_price DROP COLUMN fk_product_fournisseur;
ALTER TABLE llx_product_fournisseur_price ADD COLUMN tva_tx double(6,3) NOT NULL DEFAULT 0 AFTER unitprice;
UPDATE llx_c_departements SET ncc='JUJUY', nom = 'Jujuy' WHERE code_departement='2302' and fk_region='2301';
UPDATE llx_c_departements SET ncc='JUJUY', nom = 'Jujuy' WHERE code_departement='2302' and fk_region='2301';
ALTER TABLE llx_propal ADD COLUMN import_key varchar(14) AFTER fk_demand_reason;
ALTER TABLE llx_propal ADD COLUMN extraparams varchar(255) AFTER import_key;
ALTER TABLE llx_commande ADD COLUMN extraparams varchar(255) AFTER import_key;
ALTER TABLE llx_facture ADD COLUMN extraparams varchar(255) AFTER import_key;

View File

@ -64,6 +64,7 @@ create table llx_commande
fk_availability integer NULL,
fk_demand_reason integer, -- should be named fk_input_reason
fk_adresse_livraison integer, -- delivery address (deprecated)
import_key varchar(14)
import_key varchar(14),
extraparams varchar(255) -- for stock other parameters with json format
)ENGINE=innodb;

View File

@ -70,6 +70,7 @@ create table llx_facture
note text,
note_public text,
model_pdf varchar(255),
import_key varchar(14)
import_key varchar(14),
extraparams varchar(255) -- for stock other parameters with json format
)ENGINE=innodb;

View File

@ -63,5 +63,8 @@ create table llx_propal
date_livraison date DEFAULT NULL, -- delivery date
fk_availability integer NULL,
fk_demand_reason integer,
import_key varchar(14),
extraparams varchar(255), -- for stock other parameters with json format
fk_adresse_livraison integer -- delivery address (deprecated)
)ENGINE=innodb;