diff --git a/htdocs/install/mysql/migration/6.0.0-7.0.0.sql b/htdocs/install/mysql/migration/6.0.0-7.0.0.sql
index dbbc382acf3..bc73e5835b8 100644
--- a/htdocs/install/mysql/migration/6.0.0-7.0.0.sql
+++ b/htdocs/install/mysql/migration/6.0.0-7.0.0.sql
@@ -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);
+
diff --git a/htdocs/install/mysql/tables/llx_resource.key.sql b/htdocs/install/mysql/tables/llx_resource.key.sql
index 4912b02b1f9..d90f5c00f94 100644
--- a/htdocs/install/mysql/tables/llx_resource.key.sql
+++ b/htdocs/install/mysql/tables/llx_resource.key.sql
@@ -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);
\ No newline at end of file
+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);
diff --git a/htdocs/install/mysql/tables/llx_resource.sql b/htdocs/install/mysql/tables/llx_resource.sql
old mode 100755
new mode 100644
index afb73e9fd5f..5da0872eb21
--- a/htdocs/install/mysql/tables/llx_resource.sql
+++ b/htdocs/install/mysql/tables/llx_resource.sql
@@ -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;
diff --git a/htdocs/resource/card.php b/htdocs/resource/card.php
index 0dccd9fab13..6e3d1896a71 100644
--- a/htdocs/resource/card.php
+++ b/htdocs/resource/card.php
@@ -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 '';
+ // Origin country
+ print '
| '.$langs->trans("CountryOrigin").' | ';
+ print $form->select_country($object->country_id,'country_id');
+ if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
+ print ' |
';
+
// 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 '';
+ // Origin country code
+ print '';
+ print '| '.$langs->trans("CountryOrigin").' | ';
+ print '';
+ print getCountry($object->country_id,0,$db);
+ print ' | ';
+ print '
';
+
print '';
print '';
diff --git a/htdocs/resource/class/dolresource.class.php b/htdocs/resource/class/dolresource.class.php
index 59a5412b0c7..c880f9538c7 100644
--- a/htdocs/resource/class/dolresource.class.php
+++ b/htdocs/resource/class/dolresource.class.php
@@ -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;