Commit 2b224ef8 authored by Guillaume Heurtier's avatar Guillaume Heurtier
Browse files

FEAT #14753 TIME 2:05 added contact address sector field

parent ab158def
......@@ -15,6 +15,6 @@
<img src="assets/spinner.gif"/>
</div>
</app-root>
<script src="runtime-es2015.94857ed5d4e94e394ba2.js" type="module"></script><script src="runtime-es5.94857ed5d4e94e394ba2.js" nomodule defer></script><script src="polyfills-es5.c174c1516561194600a5.js" nomodule defer></script><script src="polyfills-es2015.b86be9c6fde12488a69f.js" type="module"></script><script src="scripts.b9f328a06b6423d59d32.js" defer></script><script src="main-es2015.61db9a7e2506c71cd363.js" type="module"></script><script src="main-es5.61db9a7e2506c71cd363.js" nomodule defer></script></body>
<script src="runtime-es2015.94857ed5d4e94e394ba2.js" type="module"></script><script src="runtime-es5.94857ed5d4e94e394ba2.js" nomodule defer></script><script src="polyfills-es5.c174c1516561194600a5.js" nomodule defer></script><script src="polyfills-es2015.b86be9c6fde12488a69f.js" type="module"></script><script src="scripts.b9f328a06b6423d59d32.js" defer></script><script src="main-es2015.8d5a3bfeac14d6350293.js" type="module"></script><script src="main-es5.8d5a3bfeac14d6350293.js" nomodule defer></script></body>
</html>
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
-- *************************************************************************--
-- --
-- --
-- Model migration script - 21.03.4 to 21.03.5 --
-- --
-- --
-- *************************************************************************--
DROP TABLE IF EXISTS address_sectors;
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);
ALTER TABLE contacts DROP COLUMN IF EXISTS sector;
ALTER TABLE contacts ADD COLUMN sector CHARACTER VARYING(256);
DELETE FROM contacts_parameters WHERE identifier = 'sector';
INSERT INTO contacts_parameters (identifier, mandatory, filling, searchable, displayable) VALUES ('sector', false, false, false, false);
UPDATE parameters SET param_value_string = '21.03.5' WHERE id = 'database_version';
{
"name": "maarchcourrier",
"version": "21.03.4",
"version": "21.03.5",
"description": "MaarchCourrier",
"scripts": {
"build-prod": "ng build --prod",
......
......@@ -148,6 +148,7 @@ $app->put('/watermark/configuration', \Configuration\controllers\ConfigurationCo
//Contacts
$app->get('/contacts', \Contact\controllers\ContactController::class . ':get');
$app->post('/contacts', \Contact\controllers\ContactController::class . ':create');
$app->get('/contacts/sector', \Contact\controllers\ContactController::class . ':getSectorFromAddress');
$app->get('/contacts/{id}', \Contact\controllers\ContactController::class . ':getById');
$app->put('/contacts/export', \Contact\controllers\ContactController::class . ':exportContacts');
$app->put('/contacts/import', \Contact\controllers\ContactController::class . ':importContacts');
......
......@@ -821,7 +821,7 @@ INSERT INTO parameters (id, param_value_string, param_value_int, param_value_dat
INSERT INTO parameters (id, param_value_string, param_value_int, param_value_date) VALUES ('folder_id_increment', '', 200, NULL);
INSERT INTO parameters (id, param_value_string, param_value_int, param_value_date) VALUES ('work_batch_autoimport_id', NULL, 1, NULL);
INSERT INTO parameters (id, param_value_string, param_value_int, param_value_date) VALUES ('postindexing_workbatch', NULL, 1, NULL);
INSERT INTO parameters (id, param_value_string, param_value_int, param_value_date) VALUES ('database_version', '21.03.4', NULL, NULL);
INSERT INTO parameters (id, param_value_string, param_value_int, param_value_date) VALUES ('database_version', '21.03.5', NULL, NULL);
INSERT INTO parameters (id, param_value_string, param_value_int, param_value_date) VALUES ('user_quota', '', 0, NULL);
INSERT INTO parameters (id, description, param_value_string, param_value_int, param_value_date) VALUES ('defaultDepartment', 'Département par défaut sélectionné dans le formulaire des adresses', NULL, 75, NULL);
INSERT INTO parameters (id, description, param_value_string) VALUES ('homepage_message', 'Texte apparaissant dans la bannière sur la page d''accueil, mettre un espace pour supprimer la bannière.', 'Bienvenue dans votre <b>G</b>estion <b>E</b>lectronique du <b>C</b>ourrier.');
......
......@@ -247,6 +247,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 (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 (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 (2, 'Adresse d''intervention', 'banAutocomplete', 'form', '[]');
......@@ -736,7 +737,7 @@ INSERT INTO notifications (notification_sid, notification_id, description, is_en
INSERT INTO notifications (notification_sid, notification_id, description, is_enabled, event_id, notification_mode, template_id, diffusion_type, diffusion_properties, attachfor_type, attachfor_properties) VALUES (100, 'QUOTA', 'Alerte lorsque le quota est dépassé', 'Y', 'user_quota', 'EMAIL', 110, 'user', 'superadmin', NULL, NULL);
INSERT INTO parameters (id, description, param_value_string, param_value_int, param_value_date) VALUES ('work_batch_autoimport_id', NULL, NULL, 1, NULL);
INSERT INTO parameters (id, description, param_value_string, param_value_int, param_value_date) VALUES ('database_version', NULL, '21.03.4', NULL, NULL);
INSERT INTO parameters (id, description, param_value_string, param_value_int, param_value_date) VALUES ('database_version', NULL, '21.03.5', NULL, NULL);
INSERT INTO parameters (id, description, param_value_string, param_value_int, param_value_date) VALUES ('user_quota', NULL, '', 0, NULL);
INSERT INTO parameters (id, description, param_value_string, param_value_int, param_value_date) VALUES ('defaultDepartment', 'Département par défaut sélectionné dans les autocomplétions de la Base Adresse Nationale', NULL, 75, NULL);
INSERT INTO parameters (id, description, param_value_string, param_value_int, param_value_date) VALUES ('thumbnailsSize', 'Résolution des imagettes', '750x900', NULL, NULL);
......
......@@ -766,6 +766,7 @@ CREATE TABLE contacts
enabled boolean NOT NULL DEFAULT TRUE,
custom_fields jsonb DEFAULT '{}',
external_id jsonb DEFAULT '{}',
sector CHARACTER VARYING(256),
CONSTRAINT contacts_pkey PRIMARY KEY (id)
)
WITH (OIDS=FALSE);
......@@ -1537,3 +1538,17 @@ CREATE TABLE tiles
CONSTRAINT tiles_pkey PRIMARY KEY (id)
)
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;
use AcknowledgementReceipt\models\AcknowledgementReceiptModel;
use Attachment\models\AttachmentModel;
use Contact\models\ContactAddressSectorModel;
use Contact\models\ContactCivilityModel;
use Contact\models\ContactCustomFieldListModel;
use Contact\models\ContactFillingModel;
......@@ -58,7 +59,8 @@ class ContactController
'addressCountry' => 'address_country',
'email' => 'email',
'phone' => 'phone',
'notes' => 'notes'
'notes' => 'notes',
'sector' => 'sector'
];
public function get(Request $request, Response $response)
......@@ -92,7 +94,7 @@ class ContactController
'select' => [
'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_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,
'data' => $requestData['data'] ?? null,
......@@ -169,6 +171,8 @@ class ContactController
$externalId = '{}';
}
$sector = ContactController::getAddressSector($body);
$id = ContactModel::create([
'civility' => $body['civility'] ?? null,
'firstname' => $body['firstname'] ?? null,
......@@ -190,7 +194,8 @@ class ContactController
'creator' => $GLOBALS['id'],
'enabled' => 'true',
'custom_fields' => !empty($body['customFields']) ? json_encode($body['customFields']) : '{}',
'external_id' => $externalId
'external_id' => $externalId,
'sector' => $sector['label'] ?? null
]);
$historyInfoContact = '';
......@@ -253,7 +258,8 @@ class ContactController
'creationDate' => $rawContact['creation_date'],
'modificationDate' => $rawContact['modification_date'],
'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'])) {
......@@ -341,6 +347,8 @@ class ContactController
$externalId = '{}';
}
$sector = ContactController::getAddressSector($body);
ContactModel::update([
'set' => [
'civility' => $body['civility'] ?? null,
......@@ -362,7 +370,8 @@ class ContactController
'notes' => $body['notes'] ?? null,
'modification_date' => 'CURRENT_TIMESTAMP',
'custom_fields' => !empty($body['customFields']) ? json_encode($body['customFields']) : null,
'external_id' => $externalId
'external_id' => $externalId,
'sector' => $sector['label'] ?? null
],
'where' => ['id = ?'],
'data' => [$args['id']]
......@@ -1135,6 +1144,7 @@ class ContactController
'enabled' => 'enabled',
'customFields' => 'custom_fields',
'externalId' => 'external_id',
'sector' => 'sector'
];
$contactCustoms = ContactCustomFieldListModel::get(['select' => ['id']]);
......@@ -1389,6 +1399,27 @@ class ContactController
return $response->withJson($return);
}
public function getSectorFromAddress(Request $request, Response $response)
{
$queryParams = $request->getQueryParams();
if (empty($queryParams)) {
return $response->withStatus(400)->withJson(['errors' => 'Query is not set or empty']);
} elseif (!empty($queryParams['addressNumber']) && !Validator::stringType()->validate($queryParams['addressNumber'])) {
return $response->withStatus(400)->withJson(['errors' => 'Query addressNumber is not a string']);
} elseif (!empty($queryParams['addressStreet']) && !Validator::stringType()->notEmpty()->validate($queryParams['addressStreet'])) {
return $response->withStatus(400)->withJson(['errors' => 'Query addressStreet is not a string']);
} elseif (!empty($queryParams['addressPostcode']) && !Validator::stringType()->notEmpty()->validate($queryParams['addressPostcode'])) {
return $response->withStatus(400)->withJson(['errors' => 'Query addressPostcode is not a string']);
} elseif (!empty($queryParams['addressTown']) && !Validator::stringType()->notEmpty()->validate($queryParams['addressTown'])) {
return $response->withStatus(400)->withJson(['errors' => 'Query addressTown is not a string']);
}
$sector = ContactController::getAddressSector($queryParams);
return $response->withJson(['sector' => $sector]);
}
public static function getParsedContacts(array $args)
{
ValidatorModel::notEmpty($args, ['resId', 'mode']);
......@@ -1445,7 +1476,8 @@ class ContactController
'creationDate' => $contactRaw['creation_date'],
'modificationDate' => $contactRaw['modification_date'],
'customFields' => !empty($contactRaw['custom_fields']) ? json_decode($contactRaw['custom_fields'], true) : null,
'externalId' => json_decode($contactRaw['external_id'], true)
'externalId' => json_decode($contactRaw['external_id'], true),
'sector' => $contactRaw['sector']
];
if (!empty($contactRaw['communication_means'])) {
......@@ -1743,7 +1775,10 @@ class ContactController
$address.= $args['contact']['address_town'] . ' ';
}
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 = '';
......@@ -1858,6 +1893,9 @@ class ContactController
if (in_array('notes', $displayableStdParameters)) {
$contact['notes'] = $rawContact['notes'];
}
if (in_array('sector', $displayableStdParameters)) {
$contact['sector'] = $rawContact['sector'];
}
if (!empty($displayableCstParameters)) {
$contact['customFields'] = [];
......@@ -1907,4 +1945,52 @@ class ContactController
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 @@
</button>
</mat-list-item>
<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">
<p mat-line class="contact-content" *ngIf="field.display">
<mat-form-field>
......
......@@ -255,6 +255,17 @@ export class ContactsFormComponent implements OnInit {
filling: false,
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',
unit: 'maarch2maarch',
......@@ -505,11 +516,6 @@ export class ContactsFormComponent implements OnInit {
});
}
private _filter(value: string): string[] {
const filterValue = value.toLowerCase();
return this.countries.filter((option: any) => option.toLowerCase().includes(filterValue));
}
selectCountry(ev: any) {
const indexFieldAddressCountry = this.contactForm.map(field => field.id).indexOf('addressCountry');
this.contactForm[indexFieldAddressCountry].control.setValue(ev.option.value);
......@@ -806,6 +812,15 @@ export class ContactsFormComponent implements OnInit {
}
});
this.checkFilling();
this.http.get('../rest/contacts/sector', {params: {'addressNumber': contact['addressNumber'], 'addressStreet': contact['addressStreet'], 'addressPostcode': contact['addressPostcode'], 'addressTown': contact['addressTown']}}).pipe(
tap((data: any) => {
if (data.sector !== null) {
const sectorIndex = this.contactForm.findIndex(element => element.id === 'sector');
this.contactForm[sectorIndex].control.setValue(data.sector.label);
this.contactForm[sectorIndex].display = true;
}
}),
).subscribe();
this.addressBANMode = disableBan ? false : true;
}
......@@ -1112,4 +1127,9 @@ export class ContactsFormComponent implements OnInit {
}
}, 100);
}
private _filter(value: string): string[] {
const filterValue = value.toLowerCase();
return this.countries.filter((option: any) => option.toLowerCase().includes(filterValue));
}
}
......@@ -136,7 +136,7 @@
</mat-header-cell>
<mat-cell *matCellDef="let element">
<mat-slide-toggle style="margin-left:11px" color="primary"
[disabled]="element.identifier == 'lastname' || element.identifier == 'company'"
[disabled]="element.identifier == 'lastname' || element.identifier == 'company' || element.identifier == 'sector'"
title="{{'lang.mandatory' | translate}}"
(change)="addCriteria($event, element, 'mandatory')" [checked]="element.mandatory">
</mat-slide-toggle>
......@@ -186,4 +186,4 @@
</div>
</div>
</mat-sidenav-content>
</mat-sidenav-container>
\ No newline at end of file
</mat-sidenav-container>
......@@ -73,6 +73,8 @@
{{option.addressTown}} </p>
<p mat-line class="contact-content" *ngIf="!empty(option.addressCountry)"
[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 class="contact-item" *ngIf="!empty(option.notes)">
<mat-icon mat-list-icon class="contact-group far fa-sticky-note" [title]="'lang.note' | translate">
......
......@@ -76,6 +76,11 @@
<p mat-line class="contact-content" *ngIf="!functionsService.empty(contact.addressCountry)"
[class.newData]="isNewValue('addressCountry')"> {{contact.addressCountry}} </p>
</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-expansion-panel *ngIf="!emptyOtherInfo(contact)" [expanded]="selectable">
<mat-expansion-panel-header>
......
......@@ -2482,5 +2482,6 @@
"clientId": "Client ID",
"clientSecret": "Client Secret",
"siteUrl": "Sharepoint Online site URL",
"office365sharepointDesc": "<a href=\"https://www.office.com/\" target=\"_blank\"> Office 365 </a> is the online office suite from Microsoft. The editing is done via Sharepoint Online."
"office365sharepointDesc": "<a href=\"https://www.office.com/\" target=\"_blank\"> Office 365 </a> is the online office suite from Microsoft. The editing is done via Sharepoint Online.",
"contactsParameters_sector": "Sector"
}
......@@ -2477,5 +2477,6 @@
"clientId": "Client ID",
"clientSecret": "Client Secret",
"siteUrl": "URL de l'espace Sharepoint Online",
"office365sharepointDesc": "<a href=\"https://www.office.com/\" target=\"_blank\"> Office 365 </a> est la suite bureautique en ligne de Microsoft. L'édition se fait via Sharepoint Online."
"office365sharepointDesc": "<a href=\"https://www.office.com/\" target=\"_blank\"> Office 365 </a> est la suite bureautique en ligne de Microsoft. L'édition se fait via Sharepoint Online.",
"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