From 0c19ce18fe50eeeeabbe524f29222cbff634277b Mon Sep 17 00:00:00 2001 From: "sosuke.iwabuchi" Date: Mon, 20 May 2024 09:27:30 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=90=E3=83=B3=E3=82=AF=E3=83=81=E3=82=A7?= =?UTF-8?q?=E3=83=83=E3=82=AF=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 4 +- .../バンクチェック登録ボタン.ts | 104 ++++++++++++++++++ src/apps/定期申込予約/index.tsx | 2 + src/common/appids.ts | 1 + src/config/kintone.ts | 3 + src/rest-api/入金プール.ts | 27 +++++ src/rest-api/入金予定結果.ts | 30 +++++ src/types/入金プール.ts | 18 +++ yarn.lock | 5 + 9 files changed, 193 insertions(+), 1 deletion(-) create mode 100644 src/apps/定期申込予約/buttons/バンクチェック登録ボタン.ts create mode 100644 src/rest-api/入金プール.ts create mode 100644 src/rest-api/入金予定結果.ts create mode 100644 src/types/入金プール.ts diff --git a/package.json b/package.json index fc279f8..ecf0c13 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "@kintone/rest-api-client": "^2.0.17", "@types/lodash": "^4.14.202", "@types/sprintf": "^0.1.2", + "@types/uuid": "^9.0.8", "core-js": "^3.6.4", "date-fns": "^2.30.0", "kintone-ui-component": "^1.14.0", @@ -56,6 +57,7 @@ "react-dom": "^18.2.0", "sprintf": "^0.1.5", "sweetalert2": "^11.10.1", - "sweetalert2-react-content": "^5.0.7" + "sweetalert2-react-content": "^5.0.7", + "uuid": "^9.0.1" } } diff --git a/src/apps/定期申込予約/buttons/バンクチェック登録ボタン.ts b/src/apps/定期申込予約/buttons/バンクチェック登録ボタン.ts new file mode 100644 index 0000000..f1b9aa1 --- /dev/null +++ b/src/apps/定期申込予約/buttons/バンクチェック登録ボタン.ts @@ -0,0 +1,104 @@ +import { apptemplate } from "@/common/app-template"; +import { DEFAULT_DATE_FORMAT, formatToStr, now } from "@/common/datetime"; +import { setHeaderButton } from "@/common/header-button"; +import { Message } from "@/exception"; +import { get入金予定結果一覧 } from "@/rest-api/入金予定結果"; +import { 初回入金予定Checkbox, 定期申込予約 } from "@/types/定期申込予約"; +import { sprintf } from "sprintf"; +import { v4 as uuidV4 } from "uuid"; + +const 表示判定 = (record: 定期申込予約): boolean => { + if (!record.自動承認契約情報.value) { + return false; + } + + if (!!record.IC定期駐車場利用方法.value) { + return false; + } + + if ( + record.初回入金予定_必要分.value.includes(初回入金予定Checkbox.初月分) && + !record.初回入金予定_初月分入金予定.value + ) { + return false; + } + if ( + record.初回入金予定_必要分.value.includes(初回入金予定Checkbox.日割り分) && + !record.初回入金予定_日割り分入金予定.value + ) { + return false; + } + if ( + record.初回入金予定_必要分.value.includes(初回入金予定Checkbox.保証金) && + !record.初回入金予定_保証金入金予定.value + ) { + return false; + } + + return true; +}; + +export default function バンクチェック登録ボタン(record: 定期申込予約) { + if (表示判定(record)) { + setHeaderButton( + "バンクチェック登録", + apptemplate(async () => { + // 請求金額の取得 + const 入金予定結果一覧 = await get入金予定結果一覧({ + 申込レコード番号: record.$id.value, + }); + if (入金予定結果一覧.length === 0) { + throw new Message("入金予定結果が登録されていません"); + } + + let totalAmount = 0; + 入金予定結果一覧.forEach((ele) => { + totalAmount += Number(ele.payment_plan_amount.value); + }); + + if (totalAmount === 0) { + throw new Message("請求が0円です"); + } + + const 顧客コード = 入金予定結果一覧[0].customer_code.value; + + const getInput = (name: string, val: string) => { + const input = document.createElement("input"); + input.type = "hidden"; + input.name = name; + input.value = val; + return input; + }; + + const metaTag = document.createElement("meta"); + metaTag.name = "referrer"; + metaTag.content = "origin"; + document.head.appendChild(metaTag); + + const today = formatToStr(now(), DEFAULT_DATE_FORMAT); + const shopCode = sprintf("%s-%s", today, uuidV4()); + + const form = document.createElement("form"); + + form.target = "_blank"; + form.method = "POST"; + form.action = "https://credit.j-payment.co.jp/link/bankcheck"; + form.appendChild(getInput("aid", "128522")); + form.appendChild(getInput("cod", shopCode)); + form.appendChild(getInput("jb", "CAPTURE")); + form.appendChild(getInput("am", String(totalAmount))); + form.appendChild(getInput("tx", "0")); + form.appendChild(getInput("sf", "0")); + form.appendChild(getInput("customer_code", 顧客コード)); + form.appendChild(getInput("token", "Aiurhieyubfiusygy8387gbjkh")); + form.appendChild(getInput("entry_record_no", record.$id.value)); + + document.getElementById("record-gaia")?.appendChild(form); + + form.submit(); + + form.remove(); + }) + ); + } +} diff --git a/src/apps/定期申込予約/index.tsx b/src/apps/定期申込予約/index.tsx index 4b51b62..dfd8edc 100644 --- a/src/apps/定期申込予約/index.tsx +++ b/src/apps/定期申込予約/index.tsx @@ -10,6 +10,7 @@ import 日割り入金予定作成ボタン from "./buttons/日割り入金予 import 自動承認ボタン from "./buttons/自動承認ボタン"; import 承認メール送信ボタン from "./buttons/承認メール送信ボタン"; import 定期駐車場プラン入力 from "./buttons/定期駐車場プラン入力"; +import バンクチェック登録ボタン from "./buttons/バンクチェック登録ボタン"; setup(() => { kintone.events.on( @@ -26,6 +27,7 @@ setup(() => { 受付メール送信ボタン(record); 承認メール送信ボタン(record); 定期駐車場プラン入力(record); + バンクチェック登録ボタン(record); }) ); }); diff --git a/src/common/appids.ts b/src/common/appids.ts index e0dd77b..ffb7748 100644 --- a/src/common/appids.ts +++ b/src/common/appids.ts @@ -14,5 +14,6 @@ export const AppID = { 自動承認グループ: APP_ID.自動承認グループ, 定期駐車場プランマスタ: APP_ID.定期駐車場プランマスタ, ParkingNavi駐車場プラン: APP_ID.ParkingNavi駐車場プラン, + 入金プール: APP_ID.入金プール, } as const; export type AppID = (typeof AppID)[keyof typeof AppID]; diff --git a/src/config/kintone.ts b/src/config/kintone.ts index 9ac94a4..d48a68c 100644 --- a/src/config/kintone.ts +++ b/src/config/kintone.ts @@ -11,6 +11,7 @@ export type KintoneConfig = { 自動承認グループ: number; 定期駐車場プランマスタ: number; ParkingNavi駐車場プラン: number; + 入金プール: number; }; }; @@ -29,6 +30,7 @@ export const kintoneConfig = (): KintoneConfig => { 自動承認グループ: 286, 定期駐車場プランマスタ: 257, ParkingNavi駐車場プラン: 297, + 入金プール: 323, }, }; } else if (process.env.NODE_ENV === "production") { @@ -45,6 +47,7 @@ export const kintoneConfig = (): KintoneConfig => { 自動承認グループ: 869, 定期駐車場プランマスタ: 259, ParkingNavi駐車場プラン: 866, + 入金プール: 870, }, }; } else { diff --git a/src/rest-api/入金プール.ts b/src/rest-api/入金プール.ts new file mode 100644 index 0000000..fc218ee --- /dev/null +++ b/src/rest-api/入金プール.ts @@ -0,0 +1,27 @@ +import { AppID } from "@/common/appids"; +import { 入金プール, 入金プールフィールド名 } from "@/types/入金プール"; +import { KintoneRestAPIClient } from "@kintone/rest-api-client"; +import { QueryBuilder } from "./query"; + +const client = new KintoneRestAPIClient(); + +const app = AppID.入金プール; + +type get入金予定結果オプション = { + 顧客コード: number | string; +}; +export const get入金プール一覧 = async ({ + 顧客コード, +}: get入金予定結果オプション): Promise<入金プール[]> => { + const builder = new QueryBuilder(); + if (顧客コード) { + builder.where(入金プールフィールド名.顧客コード, 顧客コード); + } + + const { records } = await client.record.getRecords<入金プール>({ + app, + query: builder.build(), + }); + + return records; +}; diff --git a/src/rest-api/入金予定結果.ts b/src/rest-api/入金予定結果.ts new file mode 100644 index 0000000..8a24554 --- /dev/null +++ b/src/rest-api/入金予定結果.ts @@ -0,0 +1,30 @@ +import { AppID } from "@/common/appids"; +import { 入金予定結果, 入金予定結果フィールド名 } from "@/types/入金予定結果"; +import { KintoneRestAPIClient } from "@kintone/rest-api-client"; +import { QueryBuilder } from "./query"; + +const client = new KintoneRestAPIClient(); + +const app = AppID.入金予定結果; + +type get入金予定結果オプション = { + 申込レコード番号: number | string; +}; +export const get入金予定結果一覧 = async ({ + 申込レコード番号, +}: get入金予定結果オプション): Promise<入金予定結果[]> => { + const builder = new QueryBuilder(); + if (申込レコード番号) { + builder.where( + 入金予定結果フィールド名.初回振り込み関連申込レコード番号, + 申込レコード番号 + ); + } + + const { records } = await client.record.getRecords<入金予定結果>({ + app, + query: builder.build(), + }); + + return records; +}; diff --git a/src/types/入金プール.ts b/src/types/入金プール.ts new file mode 100644 index 0000000..faee4a9 --- /dev/null +++ b/src/types/入金プール.ts @@ -0,0 +1,18 @@ +import { KintoneRecordField } from "@kintone/rest-api-client"; +import { AppRecord } from "."; + +const F = { + 顧客コード: "顧客コード", + 顧客コード重複チェック: "顧客コード重複チェック", + 顧客名: "顧客名", + プール金: "プール金", +} as const; + +export const 入金プールフィールド名 = F; + +export type 入金プール = AppRecord & { + [F.顧客コード]: KintoneRecordField.Number; + [F.顧客コード重複チェック]: KintoneRecordField.Number; + [F.顧客名]: KintoneRecordField.SingleLineText; + [F.プール金]: KintoneRecordField.Number; +}; diff --git a/yarn.lock b/yarn.lock index 9a0f7bf..fdd7da5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1395,6 +1395,11 @@ resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-9.0.7.tgz#b14cebc75455eeeb160d5fe23c2fcc0c64f724d8" integrity sha512-WUtIVRUZ9i5dYXefDEAI7sh9/O7jGvHg7Df/5O/gtH3Yabe5odI3UWopVR1qbPXQtvOxWu3mM4XxlYeZtMWF4g== +"@types/uuid@^9.0.8": + version "9.0.8" + resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-9.0.8.tgz#7545ba4fc3c003d6c756f651f3bf163d8f0f29ba" + integrity sha512-jg+97EGIcY9AGHJJRaaPVgetKDsrTgbRjQ5Msgjh/DQKEFl0DtyRr/VCOyD1T2R1MNeWPK/u7JoGhlDZnKBAfA== + "@types/ws@^8.5.5": version "8.5.10" resolved "https://registry.yarnpkg.com/@types/ws/-/ws-8.5.10.tgz#4acfb517970853fa6574a3a6886791d04a396787"