Skip to content

Commit

Permalink
New - Permettre à un producteur de ne pas renseigner de TVA
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffreymugnier committed Nov 8, 2020
1 parent e2baaa1 commit 5c60390
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/routes/cart/DeliveryModePicker.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
storeCartItems = newCartItems;
} else {
$cartItems = newCartItems;
localStorage.setItem("user_cart", JSON.stringify($cartItems));
}
}
};
Expand Down
1 change: 0 additions & 1 deletion src/routes/products/CreateProduct.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import { onMount, getContext } from "svelte";
import Icon from "svelte-awesome";
import { faChevronLeft } from "@fortawesome/free-solid-svg-icons";
import TransitionWrapper from "./../../components/TransitionWrapper.svelte";
import GetGraphQLInstance from "./../../services/SheaftGraphQL.js";
import GetRouterInstance from "./../../services/SheaftRouter.js";
Expand Down
5 changes: 0 additions & 5 deletions src/routes/products/EditProduct.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,6 @@
</div>
</div>
<div class="flex mt-2">
<button
class={`btn btn-lg bg-white border mr-2 hover:text-white ${product.available ? 'text-orange-500 border-orange-500 hover:bg-orange-500' : 'text-green-500 border-green-500 hover:bg-green-500'}`}
on:click={showSetAvailabilityModal}>
{product.available ? 'Désactiver' : 'Activer'}
</button>
<button
class="btn btn-lg bg-white text-red-500 border border-red-500 hover:bg-red-500 hover:text-white"
on:click={showDeleteModal}>
Expand Down
27 changes: 22 additions & 5 deletions src/routes/products/ProductForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,22 @@
import ReturnableSelectItem from "./ReturnableSelectItem.svelte";
import CreateReturnable from "./../returnables/CreateReturnable.svelte";
import TagKind from "./../../enums/TagKind.js";
import { GET_RETURNABLES, GET_TAGS } from "./queries.js";
import { GET_RETURNABLES, GET_TAGS, GET_PRODUCER_DETAILS } from "./queries.js";
import ChangeImage from "./ChangeImage.svelte";
import { form, bindClass } from "../../../vendors/svelte-forms/src/index";
import UnitKind from "../../enums/UnitKind";
import ConditioningKind from "../../enums/ConditioningKind";
import GetAuthInstance from "../../services/SheaftAuth";
export let submit, product, isLoading;
const { open } = getContext("modal");
const graphQLInstance = GetGraphQLInstance();
const authInstance = GetAuthInstance();
let isLoadingTags = false;
let isLoadingReturnables = false;
let notSubjectToVat = false;
let selectedCategory = null;
let returnables = [];
Expand All @@ -45,7 +48,7 @@
validators: ["required", "min:0.01"],
enabled: true,
},
vat: { value: product.vat, validators: ["required"], enabled: true },
vat: { value: product.vat, validators: ["required"], enabled: !notSubjectToVat },
unit: { value: product.unit, validators: ["required"], enabled: product.conditioning == ConditioningKind.Bulk.Value},
conditioning: {
value: product.conditioning,
Expand Down Expand Up @@ -128,11 +131,25 @@
onMount(async () => {
isLoading = true;
await getProducer();
await getTags();
await getReturnables();
isLoading = false;
});
const getProducer = async () => {
var res = await graphQLInstance.query(GET_PRODUCER_DETAILS, {
id: authInstance.user.profile.sub
});
if (!res.success) {
//TODO
return;
}
notSubjectToVat = res.data.notSubjectToVat;
}
const getReturnables = async () => {
isLoadingReturnables = true;
var res = await graphQLInstance.query(GET_RETURNABLES);
Expand Down Expand Up @@ -228,8 +245,8 @@
</div>
<div class="form-control">
<div class="flex w-full">
<div class="w-full pr-2">
<label for="grid-price">Prix HT *</label>
<div class="w-full" class:pr-2={!notSubjectToVat}>
<label for="grid-price">{notSubjectToVat ? 'Prix *' : 'Prix HT *'}</label>
<input
bind:value={product.wholeSalePricePerUnit}
use:bindClass={{ form: productForm, name: 'wholeSalePricePerUnit' }}
Expand All @@ -242,7 +259,7 @@
placeholder="ex : 2.49" />
<ErrorContainer field={$productForm.fields.wholeSalePricePerUnit} />
</div>
<div class="w-full">
<div class="w-full" class:hidden={notSubjectToVat}>
<label for="grid-vat">TVA *</label>
<div
class="w-full text-lg justify-center button-group"
Expand Down
8 changes: 8 additions & 0 deletions src/routes/products/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ export const GET_PRODUCT_DETAILS = gql`
}
`;

export const GET_PRODUCER_DETAILS = gql`
query GetProducerDetails($id: ID!) {
producer(input: $id) {
notSubjectToVat
}
}
`

export const GET_PRODUCT_RATINGS = gql`
query GetProductRatings($id: ID!) {
product(input: $id) {
Expand Down
1 change: 1 addition & 0 deletions src/routes/register/RegisterOwner.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
let company = {
name: null,
openForNewBusiness: true,
notSubjectToVat: false,
address: {
line1: null,
line2: null,
Expand Down
13 changes: 12 additions & 1 deletion src/routes/register/owner/FormCompany.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { faInfoCircle } from "@fortawesome/free-solid-svg-icons";
import Cleave from "cleave.js";
import "cleave.js/dist/addons/cleave-phone.fr";
import InputCheckbox from "./../../../components/controls/InputCheckbox.svelte";
export let company, vat, isStore = false, stepper = 1, errorsHandler = null, invalidSiret = false;
Expand Down Expand Up @@ -187,7 +188,17 @@
<label for="country">Pays *</label>
<CountrySelect bind:selectedValue={company.legals.address.country} formName={companyForm} name="country" {errorsHandler} />
</div>
</div>
{#if !isStore}
<div class="mt-2">
<label class="cursor-pointer">
<InputCheckbox
checked={company.notSubjectToVat}
onClick={() => (company.notSubjectToVat = !company.notSubjectToVat)} />
Mon entreprise n'est pas assujettie à la TVA
</label>
</div>
{/if}
</div>
</div>
</fieldset>
</form>
Expand Down

0 comments on commit 5c60390

Please sign in to comment.