Skip to content

Commit

Permalink
#72 [SQL] add: address data model
Browse files Browse the repository at this point in the history
  • Loading branch information
evarisk-micka committed Jul 12, 2023
1 parent d9abd3c commit 9bd9b5a
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 1 deletion.
15 changes: 14 additions & 1 deletion core/modules/modEasyCRM.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,20 @@ public function init($options = ''): int
return -1; // Do not activate module if error 'not allowed' returned when loading module SQL queries (the _load_table run sql with run_sql with the error allowed parameter set to 'default')
}

$sql = [];
$sql = [];

// Load sql sub folders
$sqlFolder = scandir(__DIR__ . '/../../sql');
foreach ($sqlFolder as $subFolder) {
if ( ! preg_match('/\./', $subFolder)) {
$this->_load_tables('/easycrm/sql/' . $subFolder . '/');
}
}

$result = $this->_load_tables('/easycrm/sql/');
if ($result < 0) {
return -1; // Do not activate module if error 'not allowed' returned when loading module SQL queries (the _load_table run sql with run_sql with the error allowed parameter set to 'default')
}

dolibarr_set_const($this->db, 'EASYCRM_VERSION', $this->version, 'chaine', 0, '', $conf->entity);
dolibarr_set_const($this->db, 'EASYCRM_DB_VERSION', $this->version, 'chaine', 0, '', $conf->entity);
Expand Down
2 changes: 2 additions & 0 deletions sql/address/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
//Silence is golden
24 changes: 24 additions & 0 deletions sql/address/llx_c_address_type.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-- Copyright (C) 2022-2023 EVARISK <technique@evarisk.com>
--
-- 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 3 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 https://www.gnu.org/licenses/.

CREATE TABLE llx_c_address_type(
rowid integer AUTO_INCREMENT PRIMARY KEY NOT NULL,
entity integer default 1,
ref varchar(128),
label varchar(255),
description text,
active tinyint(4) DEFAULT 1,
position integer DEFAULT 0
) ENGINE=innodb;
18 changes: 18 additions & 0 deletions sql/address/llx_easycrm_address.key.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- Copyright (C) 2023 EVARISK <technique@evarisk.com>
--
-- 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 3 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 https://www.gnu.org/licenses/.

ALTER TABLE llx_easycrm_address ADD INDEX idx_easycrm_address_rowid (rowid);
ALTER TABLE llx_easycrm_address ADD INDEX idx_easycrm_address_status (status);
ALTER TABLE llx_easycrm_address ADD INDEX idx_easycrm_address_element_id (element_id);
40 changes: 40 additions & 0 deletions sql/address/llx_easycrm_address.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
-- Copyright (C) 2023 EVARISK <technique@evarisk.com>
--
-- 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 3 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 https://www.gnu.org/licenses/.

CREATE TABLE llx_easycrm_address(
rowid integer AUTO_INCREMENT PRIMARY KEY NOT NULL,
entity integer DEFAULT 1 NOT NULL,
date_creation datetime NOT NULL,
tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
import_key varchar(14),
status integer NOT NULL,
element_type varchar(255),
element_id integer NOT NULL,
name varchar(255),
type varchar(255),
fk_country integer,
fk_region integer,
fk_department integer,
town varchar(255),
zip integer(5),
address varchar(255),
latitude double(24,8) DEFAULT 0 NOT NULL,
longitude double(24,8) DEFAULT 0 NOT NULL,
osm_id bigint(20),
osm_category varchar(255),
osm_type varchar(255),
fk_user_creat integer NOT NULL,
fk_user_modif integer
) ENGINE=innodb;
25 changes: 25 additions & 0 deletions sql/data.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-- Copyright (C) 2023 EVARISK <technique@evarisk.com>
--
-- 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 3 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 https://www.gnu.org/licenses/.

INSERT INTO llx_c_address_type (entity, ref, label, description, active, position) VALUES ('0', 'Workplace', 'Workplace', '', '1', '0');
INSERT INTO llx_c_address_type (entity, ref, label, description, active, position) VALUES ('0', 'Home', 'Home', '', '1', '0');
INSERT INTO llx_c_address_type (entity, ref, label, description, active, position) VALUES ('0', 'PrincipalResidence', 'PrincipalResidence', '', '1', '0');
INSERT INTO llx_c_address_type (entity, ref, label, description, active, position) VALUES ('0', 'SecondaryResidence', 'SecondaryResidence', '', '1', '0');
INSERT INTO llx_c_address_type (entity, ref, label, description, active, position) VALUES ('0', 'Office', 'Office', '', '1', '0');
INSERT INTO llx_c_address_type (entity, ref, label, description, active, position) VALUES ('0', 'BranchOffice', 'BranchOffice', '', '1', '0');
INSERT INTO llx_c_address_type (entity, ref, label, description, active, position) VALUES ('0', 'WorkSite', 'WorkSite', '', '1', '0');
INSERT INTO llx_c_address_type (entity, ref, label, description, active, position) VALUES ('0', 'Factory', 'Factory', '', '1', '0');
INSERT INTO llx_c_address_type (entity, ref, label, description, active, position) VALUES ('0', 'Warehouse', 'Warehouse', '', '1', '0');
INSERT INTO llx_c_address_type (entity, ref, label, description, active, position) VALUES ('0', 'Headquarters', 'Headquarters', '', '1', '0');

0 comments on commit 9bd9b5a

Please sign in to comment.