This commit is contained in:
@@ -80,7 +80,6 @@ async def create_contract(
|
|||||||
recurrents = list(map(lambda x: {"product": x.product, "quantity": x.quantity}, filter(lambda contract_product: contract_product.product.type == models.ProductType.RECCURENT, new_contract.products)))
|
recurrents = list(map(lambda x: {"product": x.product, "quantity": x.quantity}, filter(lambda contract_product: contract_product.product.type == models.ProductType.RECCURENT, new_contract.products)))
|
||||||
recurrent_price = compute_recurrent_prices(recurrents, len(new_contract.form.shipments))
|
recurrent_price = compute_recurrent_prices(recurrents, len(new_contract.form.shipments))
|
||||||
price = recurrent_price + compute_occasional_prices(occasionals)
|
price = recurrent_price + compute_occasional_prices(occasionals)
|
||||||
total_price = '{:10.2f}'.format(price)
|
|
||||||
cheques = list(map(lambda x: {"name": x.name, "value": x.value}, new_contract.cheques))
|
cheques = list(map(lambda x: {"name": x.name, "value": x.value}, new_contract.cheques))
|
||||||
# TODO: send contract to referer
|
# TODO: send contract to referer
|
||||||
|
|
||||||
@@ -90,8 +89,8 @@ async def create_contract(
|
|||||||
cheques,
|
cheques,
|
||||||
occasionals,
|
occasionals,
|
||||||
recurrents,
|
recurrents,
|
||||||
recurrent_price,
|
'{:10.2f}'.format(recurrent_price),
|
||||||
total_price
|
'{:10.2f}'.format(price)
|
||||||
)
|
)
|
||||||
pdf_file = io.BytesIO(pdf_bytes)
|
pdf_file = io.BytesIO(pdf_bytes)
|
||||||
contract_id = f'{new_contract.firstname}_{new_contract.lastname}_{new_contract.form.productor.type}_{new_contract.form.season}'
|
contract_id = f'{new_contract.firstname}_{new_contract.lastname}_{new_contract.form.productor.type}_{new_contract.form.season}'
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import {
|
|||||||
Title,
|
Title,
|
||||||
} from "@mantine/core";
|
} from "@mantine/core";
|
||||||
import { useForm } from "@mantine/form";
|
import { useForm } from "@mantine/form";
|
||||||
import { IconMail, IconPhone, IconUser } from "@tabler/icons-react";
|
import { IconDownload, IconMail, IconPhone, IconUser } from "@tabler/icons-react";
|
||||||
import { useCallback, useMemo, useRef } from "react";
|
import { useCallback, useMemo, useRef } from "react";
|
||||||
import { useParams } from "react-router";
|
import { useParams } from "react-router";
|
||||||
import { computePrices } from "./price";
|
import { computePrices } from "./price";
|
||||||
@@ -140,6 +140,7 @@ export function Contract() {
|
|||||||
products: tranformProducts(withDefaultValues(inputForm.getValues().products)),
|
products: tranformProducts(withDefaultValues(inputForm.getValues().products)),
|
||||||
};
|
};
|
||||||
await createContractMutation.mutateAsync(contract);
|
await createContractMutation.mutateAsync(contract);
|
||||||
|
window.location.href = '/';
|
||||||
} else {
|
} else {
|
||||||
const firstErrorField = Object.keys(errors.errors)[0];
|
const firstErrorField = Object.keys(errors.errors)[0];
|
||||||
const ref = inputRefs.current[firstErrorField];
|
const ref = inputRefs.current[firstErrorField];
|
||||||
@@ -316,8 +317,10 @@ export function Contract() {
|
|||||||
currency: "EUR",
|
currency: "EUR",
|
||||||
}).format(price)}
|
}).format(price)}
|
||||||
</Text>
|
</Text>
|
||||||
<Button aria-label={t("submit contract")} onClick={handleSubmit}>
|
<Button
|
||||||
{t("submit contract")}
|
leftSection={<IconDownload/>}
|
||||||
|
aria-label={t("submit contracts")} onClick={handleSubmit}>
|
||||||
|
{t("submit contract", {capfirst: true})}
|
||||||
</Button>
|
</Button>
|
||||||
</Overlay>
|
</Overlay>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|||||||
@@ -752,7 +752,6 @@ export function useGetAllContractFile() {
|
|||||||
disposition && disposition?.includes("filename=")
|
disposition && disposition?.includes("filename=")
|
||||||
? disposition.split("filename=")[1].replace(/"/g, "")
|
? disposition.split("filename=")[1].replace(/"/g, "")
|
||||||
: `contract_${form_id}.zip`;
|
: `contract_${form_id}.zip`;
|
||||||
console.log(disposition);
|
|
||||||
return { blob, filename };
|
return { blob, filename };
|
||||||
},
|
},
|
||||||
onSuccess: ({ blob, filename }) => {
|
onSuccess: ({ blob, filename }) => {
|
||||||
@@ -770,20 +769,28 @@ export function useCreateContract() {
|
|||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (newContract: ContractCreate) => {
|
mutationFn: async (newContract: ContractCreate) => {
|
||||||
return fetch(`${Config.backend_uri}/contracts`, {
|
const res = await fetch(`${Config.backend_uri}/contracts`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify(newContract),
|
body: JSON.stringify(newContract),
|
||||||
}).then(async (res) => await res.blob());
|
}).then((res) => res);
|
||||||
|
if (!res.ok) throw new Error();
|
||||||
|
const blob = await res.blob();
|
||||||
|
const disposition = res.headers.get("Content-Disposition");
|
||||||
|
const filename =
|
||||||
|
disposition && disposition?.includes("filename=")
|
||||||
|
? disposition.split("filename=")[1].replace(/"/g, "")
|
||||||
|
: `contract_${newContract.form_id}.pdf`;
|
||||||
|
return { blob, filename };
|
||||||
},
|
},
|
||||||
onSuccess: async (pdfBlob) => {
|
onSuccess: async ({ blob, filename }) => {
|
||||||
const url = URL.createObjectURL(pdfBlob);
|
const url = URL.createObjectURL(blob);
|
||||||
const link = document.createElement("a");
|
const link = document.createElement("a");
|
||||||
link.href = url;
|
link.href = url;
|
||||||
link.download = `contract.pdf`;
|
link.download = filename;
|
||||||
link.click();
|
link.click();
|
||||||
URL.revokeObjectURL(url);
|
URL.revokeObjectURL(url);
|
||||||
await queryClient.invalidateQueries({ queryKey: ["contracts"] });
|
await queryClient.invalidateQueries({ queryKey: ["contracts"] });
|
||||||
|
|||||||
Reference in New Issue
Block a user