Merge pull request #7860 from IonAgorria/resources-country

Add country to resource
This commit is contained in:
Laurent Destailleur 2017-11-24 16:35:52 +01:00 committed by GitHub
commit e22d13cf55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 1 deletions

View File

@ -586,3 +586,7 @@ ALTER TABLE llx_societe MODIFY COLUMN capital double(24,8);
ALTER TABLE llx_tva MODIFY COLUMN amount double(24,8);
ALTER TABLE llx_subscription MODIFY COLUMN subscription double(24,8);
ALTER TABLE llx_resource ADD fk_country integer DEFAULT NULL;
ALTER TABLE llx_resource ADD INDEX idx_resource_fk_country (fk_country);
ALTER TABLE llx_resource ADD CONSTRAINT fk_resource_fk_country FOREIGN KEY (fk_country) REFERENCES llx_c_country (rowid);

View File

@ -17,4 +17,7 @@
ALTER TABLE llx_resource ADD UNIQUE INDEX uk_resource_ref (ref, entity);
ALTER TABLE llx_resource ADD INDEX fk_code_type_resource_idx (fk_code_type_resource);
ALTER TABLE llx_resource ADD INDEX fk_code_type_resource_idx (fk_code_type_resource);
ALTER TABLE llx_resource ADD INDEX idx_resource_fk_country (fk_country);
ALTER TABLE llx_resource ADD CONSTRAINT fk_resource_fk_country FOREIGN KEY (fk_country) REFERENCES llx_c_country (rowid);

1
htdocs/install/mysql/tables/llx_resource.sql Executable file → Normal file
View File

@ -33,5 +33,6 @@ CREATE TABLE llx_resource
note_private text,
import_key varchar(14),
extraparams varchar(255), -- for stock other parameters with json format
fk_country integer DEFAULT NULL, -- Optional id of original country
tms timestamp
)ENGINE=innodb;

View File

@ -32,6 +32,7 @@ require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
require_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php';
require_once DOL_DOCUMENT_ROOT.'/resource/class/html.formresource.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/resource.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
// Load traductions files requiredby by page
@ -48,6 +49,7 @@ $ref = GETPOST('ref','alpha');
$description = GETPOST('description');
$confirm = GETPOST('confirm');
$fk_code_type_resource = GETPOST('fk_code_type_resource','alpha');
$country_id = GETPOST('country_id', 'int');
// Protection if external user
if ($user->socid > 0)
@ -111,6 +113,7 @@ if (empty($reshook))
$object->ref = $ref;
$object->description = $description;
$object->fk_code_type_resource = $fk_code_type_resource;
$object->country_id = $country_id;
// Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
@ -157,6 +160,7 @@ if (empty($reshook))
$object->ref = $ref;
$object->description = $description;
$object->fk_code_type_resource = $fk_code_type_resource;
$object->country_id = $country_id;
// Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels, $object);
@ -271,6 +275,12 @@ if ($action == 'create' || $object->fetch($id) > 0)
$doleditor->Create();
print '</td></tr>';
// Origin country
print '<tr><td>'.$langs->trans("CountryOrigin").'</td><td>';
print $form->select_country($object->country_id,'country_id');
if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
print '</td></tr>';
// Other attributes
$parameters=array('objectsrc' => $objectsrc);
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
@ -345,6 +355,14 @@ if ($action == 'create' || $object->fetch($id) > 0)
print '</tr>';
// Origin country code
print '<tr>';
print '<td>'.$langs->trans("CountryOrigin").'</td>';
print '<td>';
print getCountry($object->country_id,0,$db);
print '</td>';
print '</tr>';
print '</table>';
print '</div>';

View File

@ -73,6 +73,7 @@ class Dolresource extends CommonObject
if (isset($this->ref)) $this->ref=trim($this->ref);
if (isset($this->description)) $this->description=trim($this->description);
if (!is_numeric($this->country_id)) $this->country_id = 0;
if (isset($this->fk_code_type_resource)) $this->fk_code_type_resource=trim($this->fk_code_type_resource);
if (isset($this->note_public)) $this->note_public=trim($this->note_public);
if (isset($this->note_private)) $this->note_private=trim($this->note_private);
@ -84,6 +85,7 @@ class Dolresource extends CommonObject
$sql.= "entity,";
$sql.= "ref,";
$sql.= "description,";
$sql.= "fk_country,";
$sql.= "fk_code_type_resource,";
$sql.= "note_public,";
$sql.= "note_private";
@ -93,6 +95,7 @@ class Dolresource extends CommonObject
$sql.= $conf->entity.", ";
$sql.= " ".(! isset($this->ref)?'NULL':"'".$this->db->escape($this->ref)."'").",";
$sql.= " ".(! isset($this->description)?'NULL':"'".$this->db->escape($this->description)."'").",";
$sql.= " ".($this->country_id > 0 ? $this->country_id : 'null').",";
$sql.= " ".(! isset($this->fk_code_type_resource)?'NULL':"'".$this->db->escape($this->fk_code_type_resource)."'").",";
$sql.= " ".(! isset($this->note_public)?'NULL':"'".$this->db->escape($this->note_public)."'").",";
$sql.= " ".(! isset($this->note_private)?'NULL':"'".$this->db->escape($this->note_private)."'");
@ -181,6 +184,7 @@ class Dolresource extends CommonObject
$sql.= " t.entity,";
$sql.= " t.ref,";
$sql.= " t.description,";
$sql.= " t.fk_country,";
$sql.= " t.fk_code_type_resource,";
$sql.= " t.note_public,";
$sql.= " t.note_private,";
@ -203,6 +207,7 @@ class Dolresource extends CommonObject
$this->entity = $obj->entity;
$this->ref = $obj->ref;
$this->description = $obj->description;
$this->country_id = $obj->fk_country;
$this->fk_code_type_resource = $obj->fk_code_type_resource;
$this->note_public = $obj->note_public;
$this->note_private = $obj->note_private;
@ -228,6 +233,7 @@ class Dolresource extends CommonObject
}
}
/**
* Update object into database
*
@ -244,6 +250,7 @@ class Dolresource extends CommonObject
if (isset($this->ref)) $this->ref=trim($this->ref);
if (isset($this->fk_code_type_resource)) $this->fk_code_type_resource=trim($this->fk_code_type_resource);
if (isset($this->description)) $this->description=trim($this->description);
if (!is_numeric($this->country_id)) $this->country_id = 0;
if (empty($this->oldcopy))
{
@ -256,6 +263,7 @@ class Dolresource extends CommonObject
$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET";
$sql.= " ref=".(isset($this->ref)?"'".$this->db->escape($this->ref)."'":"null").",";
$sql.= " description=".(isset($this->description)?"'".$this->db->escape($this->description)."'":"null").",";
$sql.= " fk_country=".($this->country_id > 0 ? $this->country_id :"null").",";
$sql.= " fk_code_type_resource=".(isset($this->fk_code_type_resource)?"'".$this->db->escape($this->fk_code_type_resource)."'":"null").",";
$sql.= " tms=".(dol_strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null')."";
$sql.= " WHERE rowid=".$this->id;
@ -555,6 +563,7 @@ class Dolresource extends CommonObject
$line->id = $obj->rowid;
$line->ref = $obj->ref;
$line->description = $obj->description;
$line->country_id = $obj->fk_country;
$line->fk_code_type_resource = $obj->fk_code_type_resource;
$line->type_label = $obj->type_label;