Commit 9e9e3166 authored by Guillaume Heurtier's avatar Guillaume Heurtier
Browse files

FEAT #14753 TIME 6:10 added contact address sector field

parent 43c6c39a
...@@ -248,6 +248,7 @@ INSERT INTO contacts_parameters (id, identifier, mandatory, filling, searchable, ...@@ -248,6 +248,7 @@ INSERT INTO contacts_parameters (id, identifier, mandatory, filling, searchable,
INSERT INTO contacts_parameters (id, identifier, mandatory, filling, searchable, displayable) VALUES (14, 'email', false, true, false, false); INSERT INTO contacts_parameters (id, identifier, mandatory, filling, searchable, displayable) VALUES (14, 'email', false, true, false, false);
INSERT INTO contacts_parameters (id, identifier, mandatory, filling, searchable, displayable) VALUES (15, 'phone', false, true, false, false); INSERT INTO contacts_parameters (id, identifier, mandatory, filling, searchable, displayable) VALUES (15, 'phone', false, true, false, false);
INSERT INTO contacts_parameters (id, identifier, mandatory, filling, searchable, displayable) VALUES (16, 'notes', false, false, false, false); INSERT INTO contacts_parameters (id, identifier, mandatory, filling, searchable, displayable) VALUES (16, 'notes', false, false, false, false);
INSERT INTO contacts_parameters (id, identifier, mandatory, filling, searchable, displayable) VALUES (17, 'sector', false, false, false, false);
INSERT INTO custom_fields (id, label, type, mode, "values") VALUES (1, 'Date de fin de contrat', 'date', 'form', '[]'); INSERT INTO custom_fields (id, label, type, mode, "values") VALUES (1, 'Date de fin de contrat', 'date', 'form', '[]');
INSERT INTO custom_fields (id, label, type, mode, "values") VALUES (2, 'Adresse d''intervention', 'banAutocomplete', 'form', '[]'); INSERT INTO custom_fields (id, label, type, mode, "values") VALUES (2, 'Adresse d''intervention', 'banAutocomplete', 'form', '[]');
......
...@@ -767,6 +767,7 @@ CREATE TABLE contacts ...@@ -767,6 +767,7 @@ CREATE TABLE contacts
enabled boolean NOT NULL DEFAULT TRUE, enabled boolean NOT NULL DEFAULT TRUE,
custom_fields jsonb DEFAULT '{}', custom_fields jsonb DEFAULT '{}',
external_id jsonb DEFAULT '{}', external_id jsonb DEFAULT '{}',
sector CHARACTER VARYING(256),
CONSTRAINT contacts_pkey PRIMARY KEY (id) CONSTRAINT contacts_pkey PRIMARY KEY (id)
) )
WITH (OIDS=FALSE); WITH (OIDS=FALSE);
...@@ -1538,3 +1539,17 @@ CREATE TABLE tiles ...@@ -1538,3 +1539,17 @@ CREATE TABLE tiles
CONSTRAINT tiles_pkey PRIMARY KEY (id) CONSTRAINT tiles_pkey PRIMARY KEY (id)
) )
WITH (OIDS=FALSE); WITH (OIDS=FALSE);
CREATE TABLE address_sectors
(
id SERIAL NOT NULL,
address_number CHARACTER VARYING(256),
address_street CHARACTER VARYING(256),
address_postcode CHARACTER VARYING(256),
address_town CHARACTER VARYING(256),
label CHARACTER VARYING(256),
ban_id CHARACTER VARYING(256),
CONSTRAINT address_sectors_key UNIQUE (address_number, address_street, address_postcode, address_town),
CONSTRAINT address_sectors_pkey PRIMARY KEY (id)
)
WITH (OIDS=FALSE);
...@@ -15,6 +15,7 @@ namespace Contact\controllers; ...@@ -15,6 +15,7 @@ namespace Contact\controllers;
use AcknowledgementReceipt\models\AcknowledgementReceiptModel; use AcknowledgementReceipt\models\AcknowledgementReceiptModel;
use Attachment\models\AttachmentModel; use Attachment\models\AttachmentModel;
use Contact\models\ContactAddressSectorModel;
use Contact\models\ContactCivilityModel; use Contact\models\ContactCivilityModel;
use Contact\models\ContactCustomFieldListModel; use Contact\models\ContactCustomFieldListModel;
use Contact\models\ContactFillingModel; use Contact\models\ContactFillingModel;
...@@ -57,7 +58,8 @@ class ContactController ...@@ -57,7 +58,8 @@ class ContactController
'addressCountry' => 'address_country', 'addressCountry' => 'address_country',
'email' => 'email', 'email' => 'email',
'phone' => 'phone', 'phone' => 'phone',
'notes' => 'notes' 'notes' => 'notes',
'sector' => 'sector'
]; ];
public function get(Request $request, Response $response) public function get(Request $request, Response $response)
...@@ -91,7 +93,7 @@ class ContactController ...@@ -91,7 +93,7 @@ class ContactController
'select' => [ 'select' => [
'id', 'firstname', 'lastname', 'company', 'address_number as "addressNumber"', 'address_street as "addressStreet"', 'id', 'firstname', 'lastname', 'company', 'address_number as "addressNumber"', 'address_street as "addressStreet"',
'address_additional1 as "addressAdditional1"', 'address_additional2 as "addressAdditional2"', 'address_postcode as "addressPostcode"', 'address_additional1 as "addressAdditional1"', 'address_additional2 as "addressAdditional2"', 'address_postcode as "addressPostcode"',
'address_town as "addressTown"', 'address_country as "addressCountry"', 'enabled', 'count(1) OVER()' 'address_town as "addressTown"', 'address_country as "addressCountry"', 'enabled', 'sector', 'count(1) OVER()'
], ],
'where' => $requestData['where'] ?? null, 'where' => $requestData['where'] ?? null,
'data' => $requestData['data'] ?? null, 'data' => $requestData['data'] ?? null,
...@@ -168,6 +170,8 @@ class ContactController ...@@ -168,6 +170,8 @@ class ContactController
$externalId = '{}'; $externalId = '{}';
} }
$sector = ContactController::getAddressSector($body);
$id = ContactModel::create([ $id = ContactModel::create([
'civility' => $body['civility'] ?? null, 'civility' => $body['civility'] ?? null,
'firstname' => $body['firstname'] ?? null, 'firstname' => $body['firstname'] ?? null,
...@@ -189,7 +193,8 @@ class ContactController ...@@ -189,7 +193,8 @@ class ContactController
'creator' => $GLOBALS['id'], 'creator' => $GLOBALS['id'],
'enabled' => 'true', 'enabled' => 'true',
'custom_fields' => !empty($body['customFields']) ? json_encode($body['customFields']) : '{}', 'custom_fields' => !empty($body['customFields']) ? json_encode($body['customFields']) : '{}',
'external_id' => $externalId 'external_id' => $externalId,
'sector' => $sector['label'] ?? null
]); ]);
$historyInfoContact = ''; $historyInfoContact = '';
...@@ -252,7 +257,8 @@ class ContactController ...@@ -252,7 +257,8 @@ class ContactController
'creationDate' => $rawContact['creation_date'], 'creationDate' => $rawContact['creation_date'],
'modificationDate' => $rawContact['modification_date'], 'modificationDate' => $rawContact['modification_date'],
'customFields' => !empty($rawContact['custom_fields']) ? json_decode($rawContact['custom_fields'], true) : null, 'customFields' => !empty($rawContact['custom_fields']) ? json_decode($rawContact['custom_fields'], true) : null,
'externalId' => json_decode($rawContact['external_id'], true) 'externalId' => json_decode($rawContact['external_id'], true),
'sector' => $rawContact['sector']
]; ];
if (!empty($rawContact['civility'])) { if (!empty($rawContact['civility'])) {
...@@ -340,6 +346,8 @@ class ContactController ...@@ -340,6 +346,8 @@ class ContactController
$externalId = '{}'; $externalId = '{}';
} }
$sector = ContactController::getAddressSector($body);
ContactModel::update([ ContactModel::update([
'set' => [ 'set' => [
'civility' => $body['civility'] ?? null, 'civility' => $body['civility'] ?? null,
...@@ -361,7 +369,8 @@ class ContactController ...@@ -361,7 +369,8 @@ class ContactController
'notes' => $body['notes'] ?? null, 'notes' => $body['notes'] ?? null,
'modification_date' => 'CURRENT_TIMESTAMP', 'modification_date' => 'CURRENT_TIMESTAMP',
'custom_fields' => !empty($body['customFields']) ? json_encode($body['customFields']) : null, 'custom_fields' => !empty($body['customFields']) ? json_encode($body['customFields']) : null,
'external_id' => $externalId 'external_id' => $externalId,
'sector' => $sector['label'] ?? null
], ],
'where' => ['id = ?'], 'where' => ['id = ?'],
'data' => [$args['id']] 'data' => [$args['id']]
...@@ -1134,6 +1143,7 @@ class ContactController ...@@ -1134,6 +1143,7 @@ class ContactController
'enabled' => 'enabled', 'enabled' => 'enabled',
'customFields' => 'custom_fields', 'customFields' => 'custom_fields',
'externalId' => 'external_id', 'externalId' => 'external_id',
'sector' => 'sector'
]; ];
$contactCustoms = ContactCustomFieldListModel::get(['select' => ['id']]); $contactCustoms = ContactCustomFieldListModel::get(['select' => ['id']]);
...@@ -1745,7 +1755,10 @@ class ContactController ...@@ -1745,7 +1755,10 @@ class ContactController
$address.= $args['contact']['address_town'] . ' '; $address.= $args['contact']['address_town'] . ' ';
} }
if (!empty($args['contact']['address_country'])) { if (!empty($args['contact']['address_country'])) {
$address.= $args['contact']['address_country']; $address.= $args['contact']['address_country'] . ' ';
}
if (!empty($args['contact']['sector'])) {
$address .= $args['contact']['sector'];
} }
$contactName = ''; $contactName = '';
...@@ -1860,6 +1873,9 @@ class ContactController ...@@ -1860,6 +1873,9 @@ class ContactController
if (in_array('notes', $displayableStdParameters)) { if (in_array('notes', $displayableStdParameters)) {
$contact['notes'] = $rawContact['notes']; $contact['notes'] = $rawContact['notes'];
} }
if (in_array('sector', $displayableStdParameters)) {
$contact['sector'] = $rawContact['sector'];
}
if (!empty($displayableCstParameters)) { if (!empty($displayableCstParameters)) {
$contact['customFields'] = []; $contact['customFields'] = [];
...@@ -1909,4 +1925,52 @@ class ContactController ...@@ -1909,4 +1925,52 @@ class ContactController
return $contactsUsed; return $contactsUsed;
} }
private static function getAddressSector(array $args)
{
ValidatorModel::stringType($args, ['addressNumber', 'addressStreet', 'addressPostcode', 'addressTown']);
$where = [];
$data = [];
if (!empty($args['addressNumber'])) {
$where[] = 'address_number = ?';
$data[] = strtoupper($args['addressNumber']);
} else {
$where[] = 'address_number is null';
}
if (!empty($args['addressStreet'])) {
$where[] = 'address_street = ?';
$data[] = strtoupper($args['addressStreet']);
} else {
$where[] = 'address_street is null';
}
if (!empty($args['addressPostcode'])) {
$where[] = 'address_postcode = ?';
$data[] = strtoupper($args['addressPostcode']);
} else {
$where[] = 'address_postcode is null';
}
if (!empty($args['addressTown'])) {
$where[] = 'address_town = ?';
$data[] = strtoupper($args['addressTown']);
} else {
$where[] = 'address_town is null';
}
$sector = ContactAddressSectorModel::get([
'select' => ['*'],
'where' => $where,
'data' => $data
]);
if (empty($sector[0])) {
return null;
}
return $sector[0];
}
} }
<?php
/**
* Copyright Maarch since 2008 under licence GPLv3.
* See LICENCE.txt file at the root folder for more details.
* This file is part of Maarch software.
*
*/
/**
* @brief Contact Address Sector Model
* @author dev@maarch.org
*/
namespace Contact\models;
use SrcCore\models\DatabaseModel;
use SrcCore\models\ValidatorModel;
class ContactAddressSectorModel
{
public static function get(array $args)
{
ValidatorModel::notEmpty($args, ['select']);
ValidatorModel::arrayType($args, ['select', 'where', 'data', 'orderBy']);
ValidatorModel::intType($args, ['limit']);
$sectors = DatabaseModel::select([
'select' => $args['select'],
'table' => ['address_sectors'],
'where' => empty($args['where']) ? [] : $args['where'],
'data' => empty($args['data']) ? [] : $args['data'],
'order_by' => empty($args['orderBy']) ? [] : $args['orderBy'],
'offset' => empty($args['offset']) ? 0 : $args['offset'],
'limit' => empty($args['limit']) ? 0 : $args['limit']
]);
return $sectors;
}
public static function getById(array $args)
{
ValidatorModel::notEmpty($args, ['id', 'select']);
ValidatorModel::intVal($args, ['id']);
ValidatorModel::arrayType($args, ['select']);
$sector = DatabaseModel::select([
'select' => $args['select'],
'table' => ['address_sectors'],
'where' => ['id = ?'],
'data' => [$args['id']]
]);
if (empty($sector[0])) {
return [];
}
return $sector[0];
}
public static function create(array $args)
{
ValidatorModel::notEmpty($args, ['label', 'abbreviation']);
ValidatorModel::stringType($args, ['label', 'abbreviation']);
$nextSequenceId = DatabaseModel::getNextSequenceValue(['sequenceId' => 'address_sectors_id_seq']);
DatabaseModel::insert([
'table' => 'address_sectors',
'columnsValues' => [
'id' => $nextSequenceId,
'label' => $args['label'],
'abbreviation' => $args['abbreviation']
]
]);
return $nextSequenceId;
}
public static function update(array $args)
{
ValidatorModel::notEmpty($args, ['set' ,'where', 'data']);
ValidatorModel::arrayType($args, ['set', 'where', 'data']);
DatabaseModel::update([
'table' => 'address_sectors',
'set' => $args['set'],
'where' => $args['where'],
'data' => $args['data']
]);
return true;
}
public static function delete(array $args)
{
ValidatorModel::notEmpty($args, ['where', 'data']);
ValidatorModel::arrayType($args, ['where', 'data']);
DatabaseModel::delete([
'table' => 'address_sectors',
'where' => $args['where'],
'data' => $args['data']
]);
return true;
}
}
...@@ -275,7 +275,7 @@ ...@@ -275,7 +275,7 @@
</button> </button>
</mat-list-item> </mat-list-item>
<ng-container <ng-container
*ngIf="unit.id === 'address' && addressBANMode && ['addressAdditional1', 'addressAdditional2'].indexOf(field.id) > -1"> *ngIf="unit.id === 'address' && addressBANMode && ['addressAdditional1', 'addressAdditional2', 'sector'].indexOf(field.id) > -1">
<mat-list-item class="contact-item"> <mat-list-item class="contact-item">
<p mat-line class="contact-content" *ngIf="field.display"> <p mat-line class="contact-content" *ngIf="field.display">
<mat-form-field> <mat-form-field>
......
...@@ -255,6 +255,17 @@ export class ContactsFormComponent implements OnInit { ...@@ -255,6 +255,17 @@ export class ContactsFormComponent implements OnInit {
filling: false, filling: false,
values: [] values: []
}, },
{
id: 'sector',
unit: 'address',
label: this.translate.instant('lang.contactsParameters_sector'),
type: 'string',
control: new FormControl({value: '', disabled: true}),
required: false,
display: true,
filling: false,
values: []
},
{ {
id: 'communicationMeans', id: 'communicationMeans',
unit: 'maarch2maarch', unit: 'maarch2maarch',
......
...@@ -73,6 +73,8 @@ ...@@ -73,6 +73,8 @@
{{option.addressTown}} </p> {{option.addressTown}} </p>
<p mat-line class="contact-content" *ngIf="!empty(option.addressCountry)" <p mat-line class="contact-content" *ngIf="!empty(option.addressCountry)"
[title]="option.addressCountry"> {{option.addressCountry}} </p> [title]="option.addressCountry"> {{option.addressCountry}} </p>
<p mat-line class="contact-content" *ngIf="!empty(option.sector)"
[title]="option.sector"> {{option.sector}} </p>
</mat-list-item> </mat-list-item>
<mat-list-item class="contact-item" *ngIf="!empty(option.notes)"> <mat-list-item class="contact-item" *ngIf="!empty(option.notes)">
<mat-icon mat-list-icon class="contact-group far fa-sticky-note" [title]="'lang.note' | translate"> <mat-icon mat-list-icon class="contact-group far fa-sticky-note" [title]="'lang.note' | translate">
......
...@@ -76,6 +76,11 @@ ...@@ -76,6 +76,11 @@
<p mat-line class="contact-content" *ngIf="!functionsService.empty(contact.addressCountry)" <p mat-line class="contact-content" *ngIf="!functionsService.empty(contact.addressCountry)"
[class.newData]="isNewValue('addressCountry')"> {{contact.addressCountry}} </p> [class.newData]="isNewValue('addressCountry')"> {{contact.addressCountry}} </p>
</mat-list-item> </mat-list-item>
<mat-list-item class="contact-item" *ngIf="!functionsService.empty(contact.sector)">
<mat-icon mat-list-icon class="contact-group fas fa-map-marked-alt" [title]="'lang.contactsParameters_sector' | translate">
</mat-icon>
<p mat-line class="contact-content"> {{contact.sector}}</p>
</mat-list-item>
</mat-list> </mat-list>
<mat-expansion-panel *ngIf="!emptyOtherInfo(contact)" [expanded]="selectable"> <mat-expansion-panel *ngIf="!emptyOtherInfo(contact)" [expanded]="selectable">
<mat-expansion-panel-header> <mat-expansion-panel-header>
......
...@@ -2514,5 +2514,6 @@ ...@@ -2514,5 +2514,6 @@
"youSign": "Yousign", "youSign": "Yousign",
"source": "Source", "source": "Source",
"isRequired": "is required", "isRequired": "is required",
"updateOtp": "Edit external user" "updateOtp": "Edit external user",
} "contactsParameters_sector": "Sector"
\ No newline at end of file }
...@@ -2510,5 +2510,6 @@ ...@@ -2510,5 +2510,6 @@
"suggestedCorrespondents": "Correspondant(s) suggéré(s)", "suggestedCorrespondents": "Correspondant(s) suggéré(s)",
"searchCorrespondent": "Rechercher un correspondant", "searchCorrespondent": "Rechercher un correspondant",
"viewSuggestions": "Voir les suggestions", "viewSuggestions": "Voir les suggestions",
"noSuggestion": "Aucune suggestion" "noSuggestion": "Aucune suggestion",
"contactsParameters_sector": "Secteur"
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment