Skip to content

Commit

Permalink
Ajout de la gestion de l'adresse de facturation à la création du compte
Browse files Browse the repository at this point in the history
  • Loading branch information
noelmugnier committed Oct 12, 2021
1 parent c858802 commit 1ccdcde
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 13 deletions.
113 changes: 103 additions & 10 deletions src/routes/register/owner/FormCompany.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
<input
id="company_legalName"
type="text"
placeholder="ex : G.A.E.C des balmettes"
placeholder="ex : EARL xxxxx"
use:bindClass={{ form, name: "legalName" }}
bind:value={$company.name}
/>
Expand All @@ -156,21 +156,23 @@
<input
id="name"
type="text"
placeholder="ex : La ferme des balmettes"
placeholder="ex : O'légumes d'autrefois"
use:bindClass={{ form, name: "commercialName" }}
bind:value={$company.commercialName}
/>
<ErrorContainer field={$form.fields.commercialName} />
</div>
{#if !isStore}
<div class="mt-2 mb-2">
<label class="cursor-pointer">
<InputCheckbox
checked={$company.notSubjectToVat}
onClick={() => ($company.notSubjectToVat = !$company.notSubjectToVat)}
/>
Mon entreprise n'est pas assujettie à la TVA
</label>
<div class="w-full form-control">
<div class="mt-2 mb-2">
<label class="cursor-pointer">
<InputCheckbox
checked={$company.notSubjectToVat}
onClick={() => ($company.notSubjectToVat = !$company.notSubjectToVat)}
/>
Mon entreprise n'est pas assujettie à la TVA
</label>
</div>
</div>
{/if}
{#if !$company.notSubjectToVat}
Expand Down Expand Up @@ -219,10 +221,16 @@
/>
<ErrorContainer field={$form.fields.phone} />
</div>
{#if isStore}
<small class="text-gray-600"
><Icon data={faInfoCircle} scale="0.8" class="mr-2" />Seuls l'équipe Sheaft et les producteurs partenaires peuvent voir votre mail et votre téléphone.</small
>
{:else}
<small class="text-gray-600"
><Icon data={faInfoCircle} scale="0.8" class="mr-2" />Seuls l'équipe Sheaft et les clients ayant
commandé auprès de vous peuvent voir votre mail et votre téléphone.</small
>
{/if}
</div>
<div class="px-5 py-3 bg-white lg:w-6/12 w-full">
<div
Expand Down Expand Up @@ -330,6 +338,91 @@
{errorsHandler}
/>
</div>
</div><div class="px-5 py-3 bg-white w-full">
<div
class="-my-3 -mx-5 px-5 py-3 mb-4 bg-gray-100 border-b border-gray-400 lg:rounded-t font-semibold flex justify-between items-center"
>
<p>Adresse de Facturation</p>
</div>
<div class="w-full form-control">
<div class="mt-2 mb-2">
<label class="cursor-pointer">
<InputCheckbox
checked={!$company.differentBillingAddress}
onClick={() => ($company.differentBillingAddress = !$company.differentBillingAddress)}
/>
Mon adresse de facturation est identique à celle du siège social
</label>
</div>
</div>
{#if $company.differentBillingAddress}
<div class="w-full form-control">
<label for="billingName">Nom de la structure *</label>
<input
id="billingName"
placeholder="ex : SARL xxxxx"
use:bindClass={{ form, name: "billingName" }}
bind:value={$company.billing.name}
autocomplete="name"
/>
<ErrorContainer field={$form.fields.billingLine1} />
</div>
<div class="w-full form-control">
<label for="billingLine1">Adresse *</label>
<input
id="billingLine1"
placeholder="ex : 210 Avenue de la Liberté"
use:bindClass={{ form, name: "billingLine1" }}
bind:value={$company.billing.line1}
autocomplete="address-line1"
/>
<ErrorContainer field={$form.fields.billingLine1} />
</div>
<div class="w-full form-control">
<label for="billingLine2">Complément d'adresse</label>
<input
id="billingLine2"
placeholder="ex : Appartement 15"
bind:value={$company.billing.line2}
autocomplete="address-line2"
/>
</div>
<div class="form-control">
<div class="flex flex-wrap lg:flex-row lg:flex-no-wrap w-full">
<div class="w-full pr-0 lg:pr-2">
<label for="billingPostcode">Code postal *</label>
<input
id="billingPostcode"
placeholder="ex : 74000"
bind:value={$company.billing.zipcode}
use:bindClass={{ form, name: "billingZipcode" }}
autocomplete="postal-code"
/>
<ErrorContainer field={$form.fields.billingZipcode} />
</div>
<div class="w-full">
<label for="billingCity">Ville *</label>
<input
id="billingCity"
placeholder="ex : Annecy"
bind:value={$company.billing.city}
use:bindClass={{ form, name: "billingCity" }}
autocomplete="address-level2"
/>
<ErrorContainer field={$form.fields.billingCity} />
</div>
</div>
</div>
<div class="w-full form-control" style="display: block">
<label for="billingCountry">Pays *</label>
<CountrySelect
bind:selectedValue={$company.billing.country}
formName={form}
name="billingCountry"
{errorsHandler}
/>
</div>
{/if}
</div>
</div>
</fieldset>
Expand Down
26 changes: 23 additions & 3 deletions src/routes/register/registerCompanyForm.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { getDefaultFields } from "../../stores/form";
import formatISO from "date-fns/formatISO";
import { normalizeOpeningHours, getDefaultDenormalizedOpeningHours } from "../../helpers/app";

import { writable, get } from "svelte/store";

import omit from "lodash/omit";

import RegistrationKind from "../../enums/RegistrationKind";
import { normalizeOpeningHours, getDefaultDenormalizedOpeningHours } from "../../helpers/app";
import { getDefaultFields } from "../../stores/form";

export const siret = writable(null);

Expand All @@ -13,6 +16,7 @@ export const companyInitialValues = {
vatIdentifier: null,
kind: null,
notSubjectToVat: false,
differentBillingAddress: false,
email: null, //$authUserAccount?.profile?.email ||
phone: null, // $authUserAccount?.profile?.phone
address: {
Expand All @@ -22,6 +26,14 @@ export const companyInitialValues = {
zipcode: null,
country: "FR",
},
billing: {
name: null,
line1: null,
line2: null,
city: null,
zipcode: null,
country: "FR",
},
registrationKind: null,
registrationCode: null,
registrationCity: null,
Expand Down Expand Up @@ -76,6 +88,10 @@ export const companyValidators = (values) => ({
city: { value: values.address.city, validators: ["required"], enabled: true },
zipcode: { value: values.address.zipcode, validators: ["required"], enabled: true },
line1: { value: values.address.line1, validators: ["required"], enabled: true },
billingCity: { value: values.billing.city, validators: ["required"], enabled: values.differentBillingAddress },
billingZipcode: { value: values.billing.zipcode, validators: ["required"], enabled: values.differentBillingAddress },
billingLine1: { value: values.billing.line1, validators: ["required"], enabled: values.differentBillingAddress },
billingName: { value: values.billing.name, validators: ["required"], enabled: values.differentBillingAddress },
});

export const normalizeCompany = (profile) => {
Expand All @@ -96,12 +112,16 @@ export const normalizeCompany = (profile) => {
picture: profile.picture || null,
address: { ...omit(get(productionSite).address, ["insee", "id"]), country: "FR" },
legals: {
...omit(companyInfos, ["commercialName", "notSubjectToVat", "phone"]),
...omit(companyInfos, ["commercialName", "notSubjectToVat", "phone", "differentBillingAddress"]),
siret: get(siret).toString(),
address: companyInfos.address ? {
...companyInfos.address,
country: companyInfos.address?.country?.code || (companyInfos.address?.country ?? "FR"),
} : null,
billing: companyInfos.differentBillingAddress ? {
...companyInfos.billing,
country: companyInfos.billing?.country?.code || (companyInfos.billing?.country ?? "FR")
} : null,
vatIdentifier:
companyInfos.vatIdentifier && !companyInfos.notSubjectToVat
? "FR" + companyInfos.vatIdentifier + get(siret).toString().substring(0, 9)
Expand Down

0 comments on commit 1ccdcde

Please sign in to comment.