Merge remote-tracking branch 'origin/master' into issue439_residential_address_otf

This commit is contained in:
2022-02-28 15:11:50 +01:00
166 changed files with 2682 additions and 1555 deletions

View File

@@ -25,7 +25,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use function array_merge;
@@ -140,4 +140,29 @@ final class ThirdPartyController extends CRUDController
return null;
}
/**
* @param $action
* @param ThirdParty $entity
*/
protected function onPostFetchEntity($action, Request $request, $entity): ?Response
{
if ('view' === $action && $entity->getParent() instanceof ThirdParty) {
$params = [
'id' => $entity->getParent()->getId(),
];
if ($request->query->has('returnPath')) {
$params['returnPath'] = $request->query->get('returnPath');
}
if ($request->query->has('returnLabel')) {
$params['returnLabel'] = $request->query->get('returnLabel');
}
return $this->redirectToRoute('chill_crud_3party_3party_view', $params);
}
return null;
}
}

View File

@@ -126,6 +126,21 @@ class ChillThirdPartyExtension extends Extension implements PrependExtensionInte
],
],
],
[
'class' => \Chill\ThirdPartyBundle\Entity\ThirdPartyProfession::class,
// 'controller' => \Chill\MainBundle\Controller\ProfessionApiController::class,
'name' => 'profession',
'base_path' => '/api/1.0/thirdparty/professions',
'base_role' => 'ROLE_USER',
'actions' => [
'_index' => [
'methods' => [
Request::METHOD_GET => true,
Request::METHOD_HEAD => true,
],
],
],
],
],
]);
}

View File

@@ -45,6 +45,41 @@ use function spl_object_hash;
* all users with the right 'CHILL_3PARTY_3PARTY_SEE', 'CHILL_3PARTY_3 to see, select and edit parties for this
* center.
*
* A ThirdParty may have:
*
* * 0, one or more categories;
* * 0, one or more type
* * 1 kind.
*
* ## Kind
*
* The kind indicate if a thirdparty is a:
*
* * company ("personne morale");
* * a contact ("personne morale")
* * a child inside a company ("contact" in French). Only companies may have childs
*
* **take care** the french translation may lead to misinterpretation, as the string "contact" is the translation of
* kind "child".
*
* ## Categories and types
*
* ThirdParty may have zero, one or more categories and/or type.
*
* Categories are managed in the database. The Chill administrator may create or desactivate categories.
*
* Types are also a way to categorize the thirdparties, but this is done **into the code**, through
*
* @see{Chill\ThirdPartyBundle\ThirdPartyType\ThirdPartyTypeProviderInterface}. The type is stored into the
* database by a Php array, mapped by a jsonb into the database. This has one advantage: it is easily searchable.
*
* As the list of type is hardcoded into database, it is more easily searchable. (for chill 2.0, the
* @see{Chill\ThirdPartyBundle\Form\Type\PickThirdPartyDynamicType} does not support it yet, but
* the legacy @see{Chill\ThirdPartyBundle\Form\Type\PickThirdPartyType} does.
*
* The difference between categories and types is transparent for user: they choose the same fields into the UI, without
* noticing a difference.
*
* @ORM\Entity
* @ORM\Table(name="chill_3party.third_party")
* @DiscriminatorMap(typeProperty="type", mapping={
@@ -126,13 +161,14 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
* @var Civility
* @ORM\ManyToOne(targetEntity=Civility::class)
* ORM\JoinColumn(name="civility", referencedColumnName="id", nullable=true)
* @Groups({"docgen:read", "read", "docgen:read:3party:parent"})
* @Groups({"read", "write", "docgen:read", "docgen:read:3party:parent"})
* @Context(normalizationContext={"groups": "docgen:read"}, groups={"docgen:read:3party:parent"})
*/
private ?Civility $civility = null;
/**
* @ORM\Column(name="comment", type="text", nullable=true)
* @Groups({"read", "write"})
*/
private ?string $comment = null;
@@ -165,7 +201,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @Groups({"read", "write", "docgen:read", "docgen:read:3party:parent"})
* @Groups({"read", "docgen:read", "docgen:read:3party:parent"})
*/
private ?int $id = null;
@@ -179,6 +215,8 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
* @var string
* @ORM\Column(name="name", type="string", length=255)
* @Assert\Length(min="2")
* @Assert\NotNull
* @Assert\NotBlank
* @Groups({"read", "write", "docgen:read", "docgen:read:3party:parent"})
*/
private ?string $name = '';
@@ -198,7 +236,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
*
* @ORM\ManyToOne(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty", inversedBy="children")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
* @Groups({"read", "docgen:read"})
* @Groups({"read", "write", "docgen:read"})
* @Context(normalizationContext={"groups": "docgen:read:3party:parent"}, groups={"docgen:read"})
*/
private ?ThirdParty $parent = null;
@@ -209,7 +247,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
* @var ThirdPartyProfession
* @ORM\ManyToOne(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdPartyProfession")
* ORM\JoinColumn(name="profession", referencedColumnName="id", nullable=true)
* @Groups({"docgen:read", "docgen:read:3party:parent"})
* @Groups({"read", "write", "docgen:read", "docgen:read:3party:parent"})
* @Context(normalizationContext={"groups": "docgen:read"}, groups={"docgen:read:3party:parent"})
*/
private ?ThirdPartyProfession $profession = null;
@@ -669,7 +707,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
/**
* @return $this
*/
public function setCivility(Civility $civility): ThirdParty
public function setCivility(?Civility $civility): ThirdParty
{
$this->civility = $civility;
@@ -774,7 +812,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
/**
* @return $this
*/
public function setProfession(ThirdPartyProfession $profession): ThirdParty
public function setProfession(?ThirdPartyProfession $profession): ThirdParty
{
$this->profession = $profession;

View File

@@ -18,11 +18,14 @@ use Symfony\Component\Serializer\Annotation as Serializer;
/**
* @ORM\Table(name="chill_3party.party_profession")
* @ORM\Entity(repositoryClass=ThirdPartyProfessionRepository::class)
* @Serializer\DiscriminatorMap(typeProperty="type", mapping={
* "third_party_profession": ThirdPartyProfession::class})
*/
class ThirdPartyProfession
{
/**
* @ORM\Column(type="boolean")
* @Serializer\Groups({"read"})
*/
private bool $active = true;
@@ -30,13 +33,13 @@ class ThirdPartyProfession
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Serializer\Groups({"docgen:read"})
* @Serializer\Groups({"docgen:read", "read", "write"})
*/
private ?int $id = null;
/**
* @ORM\Column(type="json")
* @Serializer\Groups({"docgen:read"})
* @Serializer\Groups({"docgen:read", "read"})
*/
private array $name = [];

View File

@@ -11,11 +11,11 @@ declare(strict_types=1);
namespace Chill\ThirdPartyBundle\Form;
use Chill\MainBundle\Entity\Civility;
use Chill\MainBundle\Form\Type\ChillCollectionType;
use Chill\MainBundle\Form\Type\ChillTextareaType;
use Chill\MainBundle\Form\Type\PickAddressType;
use Chill\MainBundle\Form\Type\PickCenterType;
use Chill\MainBundle\Form\Type\PickCivilityType;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
@@ -101,16 +101,8 @@ class ThirdPartyType extends AbstractType
// Contact Person ThirdParty (child)
if (ThirdParty::KIND_CONTACT === $options['kind'] || ThirdParty::KIND_CHILD === $options['kind']) {
$builder
->add('civility', EntityType::class, [
->add('civility', PickCivilityType::class, [
'label' => 'thirdparty.Civility',
'class' => Civility::class,
'choice_label' => function (Civility $civility): string {
return $this->translatableStringHelper->localize($civility->getName());
},
'query_builder' => static function (EntityRepository $er): QueryBuilder {
return $er->createQueryBuilder('c')
->where('c.active = true');
},
'placeholder' => 'thirdparty.choose civility',
'required' => false,
])

View File

@@ -22,7 +22,7 @@ use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use function array_diff;
use function array_merge;

View File

@@ -15,7 +15,7 @@ use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
use Chill\ThirdPartyBundle\Security\Voter\ThirdPartyVoter;
use Knp\Menu\MenuItem;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* Add an entry in section to go to third party index page.

View File

@@ -19,46 +19,72 @@
></third-party-render-box>
</div>
</div>
<div v-else-if="action === 'edit' || action === 'create'">
<div class="form-floating mb-3" v-if="thirdparty.kind !== 'child'">
<div class="form-check">
<input class="form-check-input mt-0" type="radio" v-model="kind" value="company" id="tpartyKindInstitution">
<label for="tpartyKindInstitution" class="required">
<badge-entity
:entity="{ type: 'thirdparty', kind: 'company' }"
:options="{ displayLong: true }">
</badge-entity>
</label>
</div>
<div class="form-check">
<input class="form-check-input mt-0" type="radio" v-model="kind" value="contact" id="tpartyKindContact">
<label for="tpartyKindContact" class="required">
<badge-entity
:entity="{ type: 'thirdparty', kind: 'contact' }"
:options="{ displayLong: true }">
</badge-entity>
</label>
</div>
</div>
<div v-else>
<p>Contact de&nbsp;:</p>
<third-party-render-box :thirdparty="thirdparty.parent"
:options="{
addInfo: true,
addEntity: false,
addAltNames: true,
addId: false,
addLink: false,
addAge: false,
hLevel: 4,
addCenter: false,
addNoData: true,
isMultiline: false
<div v-else-if="action === 'edit' || action === 'create' || action === 'addContact'">
<div v-if="parent">
<div class="parent-info">
<i class="fa fa-li fa-hand-o-right"></i>
<b class="me-2">{{ $t('child_of') }}</b>
<span class="chill-entity badge-thirdparty">{{ parent.text }}</span>
</div>
</div>
<div class="form-floating mb-3" v-else-if="kind !== 'child'">
<div class="form-check">
<input class="form-check-input mt-0" type="radio" v-model="kind" value="company" id="tpartyKindInstitution">
<label for="tpartyKindInstitution" class="required">
<badge-entity
:entity="{ type: 'thirdparty', kind: 'company' }"
:options="{ displayLong: true }">
</badge-entity>
</label>
</div>
<div class="form-check">
<input class="form-check-input mt-0" type="radio" v-model="kind" value="contact" id="tpartyKindContact">
<label for="tpartyKindContact" class="required">
<badge-entity
:entity="{ type: 'thirdparty', kind: 'contact' }"
:options="{ displayLong: true }">
</badge-entity>
</label>
</div>
</div>
<div v-else>
<p>Contact de&nbsp;:</p>
<third-party-render-box :thirdparty="thirdparty.parent"
:options="{
addInfo: true,
addEntity: false,
addAltNames: true,
addId: false,
addLink: false,
addAge: false,
hLevel: 4,
addCenter: false,
addNoData: true,
isMultiline: false
}"></third-party-render-box>
</div>
</div>
<div v-if="thirdparty.kind === 'child' || thirdparty.kind === 'contact'">
<div id="child-info">
<div class="input-group mb-3">
<select class="form-select form-select-lg" id="profession"
v-model="thirdparty.civility">
<option selected disabled :value="null" >{{ $t('thirdparty.civility') }}</option>
<option v-for="civility in civilities" :key="civility.id" :value="{type: 'chill_main_civility', id: civility.id }">{{ civility.name.fr }}</option>
</select>
</div>
<div class="input-group mb-3">
<select class="form-select form-select-lg" id="civility"
v-model="thirdparty.profession">
<option selected disabled :value="null">{{ $t('thirdparty.profession') }}</option>
<option v-for="profession in professions" :key="profession.id" :value="{type: 'third_party_profession', id: profession.id }">{{ profession.name.fr }}</option>
</select>
</div>
</div>
</div>
<div class="form-floating mb-3">
<input class="form-control form-control-lg" id="name" v-model="thirdparty.text" v-bind:placeholder="$t('thirdparty.name')" />
<input class="form-control form-control-lg" id="name" v-model="thirdparty.name" v-bind:placeholder="$t('thirdparty.name')" />
<label for="name">{{ $t('thirdparty.name') }}</label>
</div>
<div v-if="query">
@@ -69,16 +95,16 @@
</ul>
</div>
<template
v-if="thirdparty.kind !== 'child'">
<add-address
key="thirdparty"
:context="context"
:options="addAddress.options"
:address-changed-callback="submitAddress"
ref="addAddress">
</add-address>
</template>
<template
v-if="thirdparty.kind !== 'child'">
<add-address
key="thirdparty"
:context="context"
:options="addAddress.options"
:address-changed-callback="submitAddress"
ref="addAddress">
</add-address>
</template>
<div class="input-group mb-3">
<span class="input-group-text" id="email"><i class="fa fa-fw fa-envelope"></i></span>
@@ -98,6 +124,15 @@
aria-describedby="phonenumber" />
</div>
<div v-if="parent">
<div class="input-group mb-3">
<span class="input-group-text" id="comment"><i class="fa fa-fw fa-pencil"></i></span>
<textarea class="form-control form-control-lg"
v-bind:placeholder="$t('thirdparty.comment')"
v-model="thirdparty.comment"
></textarea>
</div>
</div>
</div>
</template>
@@ -106,10 +141,11 @@ import ThirdPartyRenderBox from '../Entity/ThirdPartyRenderBox.vue';
import AddAddress from 'ChillMainAssets/vuejs/Address/components/AddAddress';
import { getThirdparty } from '../../_api/OnTheFly';
import BadgeEntity from 'ChillMainAssets/vuejs/_components/BadgeEntity.vue';
import { makeFetch } from 'ChillMainAssets/lib/api/apiMethods';
export default {
name: "OnTheFlyThirdParty",
props: ['id', 'type', 'action', 'query'],
props: ['id', 'type', 'action', 'query', 'parent'],
components: {
ThirdPartyRenderBox,
AddAddress,
@@ -120,7 +156,15 @@ export default {
//context: {}, <--
thirdparty: {
type: 'thirdparty',
address: null,
kind: 'company',
name: '',
telephone: '',
civility: null,
profession: null,
},
professions: [],
civilities: [],
addAddress: {
options: {
openPanesInModal: true,
@@ -129,27 +173,27 @@ export default {
size: 'btn-sm'
},
title: {
create: 'add_an_address_title',
edit: 'edit_address'
create: 'add_an_address_title',
edit: 'edit_address'
}
}
}
}
},
computed: {
kind: {
get() {
// note: there are also default to 'institution' set in the "mounted" method
if (this.$data.thirdparty.kind !== undefined) {
return this.$data.thirdparty.kind;
} else {
return 'company';
}
},
set(v) {
this.$data.thirdparty.kind = v;
}
},
kind: {
get() {
// note: there are also default to 'institution' set in the "mounted" method
if (this.$data.thirdparty.kind !== undefined) {
return this.$data.thirdparty.kind;
} else {
return 'company';
}
},
set(v) {
this.$data.thirdparty.kind = v;
}
},
context() {
let context = {
target: {
@@ -160,10 +204,10 @@ export default {
addressId: null
};
if ( !(this.thirdparty.address === undefined || this.thirdparty.address === null)
&& this.thirdparty.address.address_id !== null
&& this.thirdparty.address.address_id !== null
) { // to complete
context.addressId = this.thirdparty.address.address_id;
context.edit = true;
context.addressId = this.thirdparty.address.address_id;
context.edit = true;
}
console.log('context', context);
//this.context = context; <--
@@ -172,38 +216,73 @@ export default {
},
methods: {
loadData(){
getThirdparty(this.id).then(thirdparty => new Promise((resolve, reject) => {
return getThirdparty(this.id).then(thirdparty => new Promise((resolve, reject) => {
this.thirdparty = thirdparty;
this.thirdparty.kind = thirdparty.kind;
//console.log('get thirdparty', thirdparty);
console.log('get thirdparty', thirdparty);
if (this.action !== 'show') {
if (thirdparty.address !== null) {
// bof! we force getInitialAddress because addressId not available when mounted
this.$refs.addAddress.getInitialAddress(thirdparty.address.address_id);
}
if (thirdparty.address !== null) {
// bof! we force getInitialAddress because addressId not available when mounted
this.$refs.addAddress.getInitialAddress(thirdparty.address.address_id);
}
}
resolve();
}));
},
loadCivilities() {
const url = `/api/1.0/main/civility.json`;
return makeFetch('GET', url)
.then(response => {
this.$data.civilities = response.results;
return Promise.resolve();
})
.catch((error) => {
console.log(error)
this.$toast.open({message: error.body})
})
},
loadProfessions() {
const url = `/api/1.0/thirdparty/professions.json`;
return makeFetch('GET', url)
.then(response => {
this.$data.professions = response.results;
return Promise.resolve();
})
.catch((error) => {
console.log(error)
this.$toast.open({message: error.body})
})
},
submitAddress(payload) {
console.log('submitAddress', payload);
if (typeof payload.addressId !== 'undefined') { // <--
this.context.edit = true;
this.context.addressId = payload.addressId; // bof! use legacy and not legacy in payload
this.thirdparty.address = payload.address; // <--
console.log('switch address to edit mode', this.context);
}
this.context.edit = true;
this.context.addressId = payload.addressId; // bof! use legacy and not legacy in payload
this.thirdparty.address = payload.address; // <--
console.log('switch address to edit mode', this.context);
}
},
addQuery(query) {
this.thirdparty.text = query;
}
this.thirdparty.name = query;
},
},
mounted() {
//console.log('mounted', this.action);
mounted() {
let dependencies = [];
dependencies.push(this.loadProfessions());
dependencies.push(this.loadCivilities());
if (this.action !== 'create') {
this.loadData();
if (this.id) {
dependencies.push(this.loadData());
// here we can do something when all promises are resolve, with
// Promise.all(dependencies).then(() => { /* do something */ });
}
if (this.action === 'addContact') {
this.$data.thirdparty.kind = 'child'
// this.$data.thirdparty.parent = this.parent.id
this.$data.thirdparty.address = null
}
} else {
this.thirdparty.kind = 'company';
this.thirdparty.kind = 'company';
}
},
}
@@ -224,5 +303,16 @@ dl {
margin-left: 1em;
}
}
.parent-info {
margin-bottom: 1rem;
}
#child-info {
display: flex;
justify-content: space-between;
div {
width: 49%;
}
}
</style>

View File

@@ -4,7 +4,12 @@ const thirdpartyMessages = {
name: "Dénomination",
email: "Courriel",
phonenumber: "Téléphone",
}
comment: "Commentaire",
profession: "Qualité",
civility: "Civilité"
},
child_of: "Contact de: ",
children: "Personnes de contact: ",
}
};

View File

@@ -23,15 +23,15 @@
{{ form_row(form.contactDataAnonymous) }}
{% endif %}
{% if form.address is defined %}
{{ form_row(form.address) }}
{% endif %}
{% if form.activeChildren is defined %}
<h2>{{ 'Contacts'|trans }}</h2>
{{ form_widget(form.activeChildren) }}
{% endif %}
{% if form.address is defined %}
{{ form_row(form.address) }}
{% endif %}
{{ form_row(form.comment) }}
{% if form.centers is defined %}

View File

@@ -87,14 +87,24 @@ class ThirdPartyApiSearch implements SearchApiInterface
foreach ($strs as $str) {
if (!empty($str)) {
$wheres[] = "(LOWER(UNACCENT(?)) <<% tparty.canonicalized OR
tparty.canonicalized LIKE '%' || LOWER(UNACCENT(?)) || '%')";
$whereArgs[] = [$str, $str];
$pertinence[] = 'STRICT_WORD_SIMILARITY(LOWER(UNACCENT(?)), tparty.canonicalized) + ' .
"(tparty.canonicalized LIKE '%s' || LOWER(UNACCENT(?)) || '%')::int + " .
tparty.canonicalized LIKE '%' || LOWER(UNACCENT(?)) || '%')
OR
(LOWER(UNACCENT(?)) <<% parent.canonicalized OR
parent.canonicalized LIKE '%' || LOWER(UNACCENT(?)) || '%')
";
$whereArgs[] = [$str, $str, $str, $str];
$pertinence[] = 'GREATEST(
STRICT_WORD_SIMILARITY(LOWER(UNACCENT(?)), tparty.canonicalized),
STRICT_WORD_SIMILARITY(LOWER(UNACCENT(?)), parent.canonicalized)
) + ' .
"GREATEST(
(tparty.canonicalized LIKE '%s' || LOWER(UNACCENT(?)) || '%')::int,
(parent.canonicalized LIKE '%s' || LOWER(UNACCENT(?)) || '%')::int
) + " .
// take postcode label into account, but lower than the canonicalized field
"COALESCE((LOWER(UNACCENT(cmpc.label)) LIKE '%' || LOWER(UNACCENT(?)) || '%')::int * 0.3, 0) + " .
"COALESCE((LOWER(UNACCENT(cmpc_p.label)) LIKE '%' || LOWER(UNACCENT(?)) || '%')::int * 0.3, 0)";
$pertinenceArgs[] = [$str, $str, $str, $str];
$pertinenceArgs[] = [$str, $str, $str, $str, $str, $str];
}
}

View File

@@ -36,6 +36,7 @@ class ThirdPartyNormalizer implements NormalizerAwareInterface, NormalizerInterf
{
return [
'type' => 'thirdparty',
'name' => $thirdParty->getName(),
'text' => $this->thirdPartyRender->renderString($thirdParty, []),
'id' => $thirdParty->getId(),
'kind' => $thirdParty->getKind(),
@@ -45,6 +46,7 @@ class ThirdPartyNormalizer implements NormalizerAwareInterface, NormalizerInterf
'isChild' => $thirdParty->isChild(),
'parent' => $this->normalizer->normalize($thirdParty->getParent(), $format, $context),
'civility' => $this->normalizer->normalize($thirdParty->getCivility(), $format, $context),
'profession' => $this->normalizer->normalize($thirdParty->getProfession(), $format, $context),
'contactDataAnonymous' => $thirdParty->isContactDataAnonymous(),
];
}

View File

@@ -110,3 +110,14 @@ paths:
description: "OK"
422:
description: "Object with validation errors"
/1.0/thirdparty/professions.json:
get:
tags:
- thirdparty
summary: Return all thirdparty professions
responses:
200:
description: "ok"
401:
description: "Unauthorized"

View File

@@ -1,7 +1,7 @@
services:
Chill\ThirdPartyBundle\Menu\MenuBuilder:
arguments:
$translator: '@Symfony\Component\Translation\TranslatorInterface'
$translator: '@Symfony\Contracts\Translation\TranslatorInterface'
$authorizationChecker: '@Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface'
tags:
- { name: 'chill.menu_builder' }