From 21e343b071404c01b291a80be48a479789b4c0bc Mon Sep 17 00:00:00 2001 From: "sosuke.iwabuchi" Date: Tue, 27 Jun 2023 09:56:47 +0900 Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E8=B2=BB=E7=A8=8E=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hello-techno/receipt-issuing-order.ts | 3 ++ .../custom/hello-techno/create.tsx | 1 + .../custom/hello-techno/detail.tsx | 7 ++++ .../hooks/useInputReceiptStep.tsx | 38 +++++++++++++++++++ src/utils/tax.ts | 11 ++++++ 5 files changed, 60 insertions(+) create mode 100644 src/utils/tax.ts diff --git a/src/api/custom/hello-techno/receipt-issuing-order.ts b/src/api/custom/hello-techno/receipt-issuing-order.ts index 290fee1..44dc879 100644 --- a/src/api/custom/hello-techno/receipt-issuing-order.ts +++ b/src/api/custom/hello-techno/receipt-issuing-order.ts @@ -16,6 +16,7 @@ export type CreateReceiptIssuingOrderRequest = { adjust_seq_no?: string | number; receipt_use_date: Date | null; receipt_amount: string | number; + tax_amount: string | number; memo?: string; sms_phone_number: string; }; @@ -43,6 +44,8 @@ export type ReceiptIssuingOrderHTCustom = { customer_name: string; parking_name: string; adjust_seq_no?: number; + tax_rate?: number; + tax_amount?: number; } & ReceiptIssuingOrder; export type ReceiptIssuingOrdersRequest = { diff --git a/src/pages/dashboard/receipt-issuing-order/custom/hello-techno/create.tsx b/src/pages/dashboard/receipt-issuing-order/custom/hello-techno/create.tsx index d291576..e8146c1 100644 --- a/src/pages/dashboard/receipt-issuing-order/custom/hello-techno/create.tsx +++ b/src/pages/dashboard/receipt-issuing-order/custom/hello-techno/create.tsx @@ -136,6 +136,7 @@ export default function ReceiptIssuingOrderCreate() { adjust_seq_no: formData.adjustSeqNo, receipt_use_date: formData.date, receipt_amount: formData.amount, + tax_amount: formData.tax_amount, sms_phone_number: formData.address, memo: formData.memo, }); diff --git a/src/pages/dashboard/receipt-issuing-order/custom/hello-techno/detail.tsx b/src/pages/dashboard/receipt-issuing-order/custom/hello-techno/detail.tsx index 75cb215..3a2dc15 100644 --- a/src/pages/dashboard/receipt-issuing-order/custom/hello-techno/detail.tsx +++ b/src/pages/dashboard/receipt-issuing-order/custom/hello-techno/detail.tsx @@ -112,6 +112,13 @@ export default function ReceiptIssuingOrderDetail() { ? order.receipt_amount.toLocaleString() + "円" : "-", }, + { + title: "消費税(内税)", + value: + isNumber(order.tax_amount) && isNumber(order.tax_rate) + ? order.tax_amount.toLocaleString() + "円(" + order.tax_rate + "%)" + : "-", + }, { title: "備考", value: order.memo }, ]; }, [order]); diff --git a/src/pages/dashboard/receipt-issuing-order/custom/hello-techno/hooks/useInputReceiptStep.tsx b/src/pages/dashboard/receipt-issuing-order/custom/hello-techno/hooks/useInputReceiptStep.tsx index d48b21a..611d51a 100644 --- a/src/pages/dashboard/receipt-issuing-order/custom/hello-techno/hooks/useInputReceiptStep.tsx +++ b/src/pages/dashboard/receipt-issuing-order/custom/hello-techno/hooks/useInputReceiptStep.tsx @@ -16,6 +16,7 @@ import RHFDatePicker from "components/hook-form/RHFDatePicker"; import { useEffect, useMemo, useState } from "react"; import { useForm } from "react-hook-form"; import { dateTimeParse } from "utils/datetime"; +import { calcInnerTax } from "utils/tax"; import * as Yup from "yup"; type AreaBoxProps = { @@ -32,6 +33,7 @@ function AreaBox({ title, children }: AreaBoxProps) { type FormProps = { amount: string; + tax_amount: string; date: Date | null; memo: string; }; @@ -46,6 +48,7 @@ export default function useInputReceiptStep({ onNext, onPrev }: Props) { const form = useForm({ defaultValues: { amount: "", + tax_amount: "", date: null, memo: "", }, @@ -55,6 +58,7 @@ export default function useInputReceiptStep({ onNext, onPrev }: Props) { .required("必須項目です") .typeError("正しく入力してください"), amount: Yup.number().required("必須項目です"), + tax_amount: Yup.number().required("必須項目です"), memo: Yup.string().nullable(), }) ), @@ -77,6 +81,17 @@ export default function useInputReceiptStep({ onNext, onPrev }: Props) { _setAdjustData(data); }; + const canCalcTax = useMemo(() => { + return !adjustData; + }, [adjustData]); + + const calcTax = () => { + if (!canCalcTax) return; + const amount = Number(form.getValues("amount")); + if (!amount) return; + form.setValue("tax_amount", String(calcInnerTax(amount))); + }; + const readOnly = useMemo(() => { return adjustData !== null; }, [adjustData]); @@ -99,6 +114,27 @@ export default function useInputReceiptStep({ onNext, onPrev }: Props) { readOnly={readOnly} /> + + + 円 + ), + }} + sx={{ maxWidth: 150 }} + readOnly={readOnly} + /> + {canCalcTax && ( + + )} + + @@ -116,9 +152,11 @@ export default function useInputReceiptStep({ onNext, onPrev }: Props) { useEffect(() => { if (adjustData) { form.setValue("amount", String(adjustData.amount)); + form.setValue("tax_amount", String(adjustData.tax_charge)); form.setValue("date", dateTimeParse(adjustData.adjust_datetime)); } else { form.setValue("amount", ""); + form.setValue("tax_amount", ""); form.setValue("date", null); } }, [adjustData]); diff --git a/src/utils/tax.ts b/src/utils/tax.ts new file mode 100644 index 0000000..71b023b --- /dev/null +++ b/src/utils/tax.ts @@ -0,0 +1,11 @@ +export const TAX_RATE_DEFAULT = 0.1; + +/** + * 内税計算 + */ +export function calcInnerTax( + totalAmount: number, + rate: number = TAX_RATE_DEFAULT +) { + return Math.floor((totalAmount * rate) / (1 + rate)); +}