From eed57e813e723bb914089d822debf34de95b49c7 Mon Sep 17 00:00:00 2001 From: "sosuke.iwabuchi" Date: Thu, 21 Dec 2023 14:27:54 +0900 Subject: [PATCH] =?UTF-8?q?=E5=90=84=E7=A8=AE=E7=94=B3=E8=AB=8B=E3=81=AE?= =?UTF-8?q?=E3=83=95=E3=82=A3=E3=83=BC=E3=83=AB=E3=83=89=E9=96=8B=E9=96=89?= =?UTF-8?q?=E9=9D=9E=E8=A1=A8=E7=A4=BA=E3=81=AE=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apps/各種申請/index.tsx | 504 +++++++++++++------------------- src/common/app-template.ts | 1 - src/types/各種申請.ts | 13 + 3 files changed, 223 insertions(+), 295 deletions(-) diff --git a/src/apps/各種申請/index.tsx b/src/apps/各種申請/index.tsx index 536beba..33a4af2 100644 --- a/src/apps/各種申請/index.tsx +++ b/src/apps/各種申請/index.tsx @@ -4,13 +4,8 @@ import { initMenuBox, setHeaderButton } from "@/common/header-button"; import { KintoneEvent } from "@/common/kintone-event"; import { makeRecordData } from "@/common/rest-api-client"; import { 契約情報更新イベント } from "@/event/契約情報更新"; -import { - ConfirmDialog, - ErrorDialog, - ShowConfirmDialog, - SuccessDialog, - showLoadingDialog, -} from "@/middleware/swal"; +import { Message } from "@/exception"; +import { ShowConfirmDialog, SuccessDialog } from "@/middleware/swal"; import { EmailID, sendEmail } from "@/mypage/メール"; import bulkRequest from "@/rest-api/bulk"; import { get車室情報管理 } from "@/rest-api/車室情報管理"; @@ -20,16 +15,15 @@ import { 各種申請フィールド名, 状況Dropdown, 申請種別Dropdown, + 申請詳細グループ, } from "@/types/各種申請"; import { 車室情報管理フィールド名 } from "@/types/車室情報管理"; import { 顧客マスタフィールド名 } from "@/types/顧客マスタ"; -import { KintoneRestAPIClient } from "@kintone/rest-api-client"; import { setup } from ".."; - -const client = new KintoneRestAPIClient(); +import { get } from "lodash"; const 各種申請完了 = (record: 各種申請) => { - return client.record.updateRecord({ + bulkRequest.update({ app: AppID.各種申請, id: record.$id.value, record: makeRecordData({ @@ -37,307 +31,229 @@ const 各種申請完了 = (record: 各種申請) => { }), }); }; -const 各種申請処理中 = (record: 各種申請) => { - return client.record.updateRecord({ - app: AppID.各種申請, - id: record.$id.value, - record: makeRecordData({ - [各種申請フィールド名.状況]: 状況Dropdown.処理中, - }), - }); -}; - -const 口座変更申請承認 = async (record: 各種申請) => { - const customer = await get顧客マスタ({ - 顧客コード: Number(record.顧客コード.value), - }); - if (customer === null) throw new Error("顧客不正"); - - // 顧客マスタへの反映 - await client.record.updateRecord({ - app: AppID.顧客マスタ, - id: customer.$id.value, - record: makeRecordData({ - [顧客マスタフィールド名.口座登録催促予定日時]: "", - [顧客マスタフィールド名.銀行支店コード]: - record.口座変更申請_変更後_銀行支店ID.value, - [顧客マスタフィールド名.引落預金種別]: - record.口座変更申請_変更後_口座種目.value, - [顧客マスタフィールド名.引落口座名義人カナ]: - record.口座変更申請_変更後_口座名義カナ.value, - [顧客マスタフィールド名.引落口座番号]: - record.口座変更申請_変更後_口座番号.value, - [顧客マスタフィールド名.ゆうちょ口座記号]: - record.口座変更申請_変更後_ゆうちょ口座記号.value, - [顧客マスタフィールド名.ゆうちょ口座番号]: - record.口座変更申請_変更後_ゆうちょ口座番号.value, - }), - }); - - // 各種申請の完了 - await 各種申請完了(record); -}; - -const getCallBack口座変更申請承認 = (record: 各種申請) => { - return async () => { - const confirm = await ConfirmDialog.fire({ - title: "承認しますか", - }); - if (!confirm.isConfirmed) return; - try { - await showLoadingDialog(); - await 口座変更申請承認(record); - } catch (e) { - console.error(e); - ErrorDialog.fire(); - return; - } - - SuccessDialog.fire().then(() => { - location.reload(); - }); - }; -}; - -const 解約申請承認 = async (record: 各種申請) => { - // 車室情報管理への反映 - bulkRequest.update({ - app: AppID.車室情報管理, - id: record.契約情報.value, - record: makeRecordData({ - [車室情報管理フィールド名.解約日]: record.解約申請_解約希望日.value ?? "", - }), - }); - - // 申請の完了 - await 各種申請完了(record); - - // データ保存 - await bulkRequest.save(); - - // メールの送信 - const email = await sendEmail(EmailID.解約承認, { - application_no: record.申請番号.value, - }); - if (!email) { - throw new Error("メール送信失敗"); +const 解約承認ボタン = (record: 各種申請) => { + if ( + record.状況.value !== 状況Dropdown.完了 && + record.申請種別.value === 申請種別Dropdown.解約申請 + ) { + setHeaderButton( + "解約申請 承認", + apptemplate(async ({ setEvent, needReloadAtEnd }) => { + const confirm = await ShowConfirmDialog({ title: "承認しますか" }); + if (!confirm.isConfirmed) return; + // 車室情報管理への反映 + bulkRequest.update({ + app: AppID.車室情報管理, + id: record.契約情報.value, + record: makeRecordData({ + [車室情報管理フィールド名.解約日]: + record.解約申請_解約希望日.value ?? "", + }), + }); + + // 申請の完了 + await 各種申請完了(record); + + // データ保存 + await bulkRequest.save(); + + // メールの送信 + const email = await sendEmail(EmailID.解約承認, { + application_no: record.申請番号.value, + }); + if (!email) { + throw new Error("メール送信失敗"); + } + + const 契約 = await get車室情報管理(record.契約情報.value); + setEvent(new 契約情報更新イベント().getEvent(契約)); + + await SuccessDialog.fire(); + needReloadAtEnd(true); + }) + ); } }; -const getCallBack解約申請承認 = (record: 各種申請) => { - return async () => { - const confirm = await ConfirmDialog.fire({ - title: "承認しますか", - }); - if (!confirm.isConfirmed) return; - - try { - await showLoadingDialog(); - await 解約申請承認(record); - } catch (e) { - console.error(e); - ErrorDialog.fire(); - return; - } - - SuccessDialog.fire().then(() => { - location.reload(); - }); - }; -}; - -const 利用者情報変更申請承認 = async (record: 各種申請) => { - // 顧客マスタへの反映 - const customer = await get顧客マスタ({ - 顧客コード: Number(record.顧客コード.value), - }); - if (customer === null) throw new Error("顧客不正"); - bulkRequest.update({ - app: AppID.顧客マスタ, - id: customer.$id.value, - record: makeRecordData({ - [顧客マスタフィールド名.顧客名]: - record.利用者情報変更申請_変更後_氏名.value ?? "", - [顧客マスタフィールド名.顧客名カナ]: - record.利用者情報変更申請_変更後_氏名カナ.value ?? "", - [顧客マスタフィールド名.契約者_郵便番号]: - record.利用者情報変更申請_変更後_郵便番号.value ?? "", - [顧客マスタフィールド名.住所]: - record.利用者情報変更申請_変更後_住所.value ?? "", - [顧客マスタフィールド名.電話番号]: - record.利用者情報変更申請_変更後_電話番号.value ?? "", - }), - }); - - // 申請の完了 - await 各種申請完了(record); - - // データ保存 - await bulkRequest.save(); - - // メールの送信 - const email = await sendEmail(EmailID.利用者情報変更完了, { - application_no: record.申請番号.value, - }); - if (!email) { - throw new Error("メール送信失敗"); +const 口座変更承認ボタン = (record: 各種申請) => { + if ( + record.状況.value !== 状況Dropdown.完了 && + record.申請種別.value === 申請種別Dropdown.口座変更申請 + ) { + setHeaderButton( + "口座変更申請 承認", + apptemplate(async ({ needReloadAtEnd }) => { + const confirm = await ShowConfirmDialog({ title: "承認しますか" }); + if (!confirm.isConfirmed) return; + + const customer = await get顧客マスタ({ + 顧客コード: Number(record.顧客コード.value), + }); + if (customer === null) throw new Error("顧客不正"); + + // 顧客マスタへの反映 + await bulkRequest.update({ + app: AppID.顧客マスタ, + id: customer.$id.value, + record: makeRecordData({ + [顧客マスタフィールド名.口座登録催促予定日時]: "", + [顧客マスタフィールド名.銀行支店コード]: + record.口座変更申請_変更後_銀行支店ID.value, + [顧客マスタフィールド名.引落預金種別]: + record.口座変更申請_変更後_口座種目.value, + [顧客マスタフィールド名.引落口座名義人カナ]: + record.口座変更申請_変更後_口座名義カナ.value, + [顧客マスタフィールド名.引落口座番号]: + record.口座変更申請_変更後_口座番号.value, + [顧客マスタフィールド名.ゆうちょ口座記号]: + record.口座変更申請_変更後_ゆうちょ口座記号.value, + [顧客マスタフィールド名.ゆうちょ口座番号]: + record.口座変更申請_変更後_ゆうちょ口座番号.value, + }), + }); + + // 各種申請の完了 + await 各種申請完了(record); + + // 保存 + await bulkRequest.save(); + + await SuccessDialog.fire(); + needReloadAtEnd(true); + }) + ); } }; - -const getCallBack利用者情報変更申請承認 = (record: 各種申請) => { - return async () => { - const confirm = await ConfirmDialog.fire({ - title: "承認しますか", - }); - if (!confirm.isConfirmed) return; - - try { - await showLoadingDialog(); - await 利用者情報変更申請承認(record); - } catch (e) { - console.error(e); - ErrorDialog.fire(); - return; - } - - SuccessDialog.fire().then(() => { - location.reload(); - }); - }; -}; -const 車両番号_防犯登録番号変更申請承認 = async (record: 各種申請) => { - // 車室情報管理アプリへの反映 - const F = 車室情報管理フィールド名; - bulkRequest.update({ - app: AppID.車室情報管理, - id: record.$id.value, - record: makeRecordData({ - [F.車両番号]: - record.車両番号_防犯番号変更申請_変更後_車両番号.value ?? "", - [F.防犯登録番号]: - record.車両番号_防犯番号変更申請_変更後_防犯登録番号.value ?? "", - }), - }); - - // 申請の完了 - await 各種申請完了(record); - - // データ保存 - await bulkRequest.save(); - - // メールの送信 - const email = await sendEmail(EmailID.車両番号_防犯登録番号変更完了, { - application_no: record.申請番号.value, - }); - if (!email) { - throw new Error("メール送信失敗"); +const 利用者情報変更承認ボタン = (record: 各種申請) => { + if ( + record.状況.value !== 状況Dropdown.完了 && + record.申請種別.value === 申請種別Dropdown.利用者情報変更 + ) { + setHeaderButton( + "利用者情報変更申請 承認", + apptemplate(async ({ needReloadAtEnd }) => { + const confirm = await ShowConfirmDialog({ title: "承認しますか" }); + if (!confirm.isConfirmed) return; + // 顧客マスタへの反映 + const customer = await get顧客マスタ({ + 顧客コード: Number(record.顧客コード.value), + }); + if (customer === null) throw new Error("顧客不正"); + bulkRequest.update({ + app: AppID.顧客マスタ, + id: customer.$id.value, + record: makeRecordData({ + [顧客マスタフィールド名.顧客名]: + record.利用者情報変更申請_変更後_氏名.value ?? "", + [顧客マスタフィールド名.顧客名カナ]: + record.利用者情報変更申請_変更後_氏名カナ.value ?? "", + [顧客マスタフィールド名.契約者_郵便番号]: + record.利用者情報変更申請_変更後_郵便番号.value ?? "", + [顧客マスタフィールド名.住所]: + record.利用者情報変更申請_変更後_住所.value ?? "", + [顧客マスタフィールド名.電話番号]: + record.利用者情報変更申請_変更後_電話番号.value ?? "", + }), + }); + + // 申請の完了 + await 各種申請完了(record); + + // データ保存 + await bulkRequest.save(); + + // メールの送信 + const email = await sendEmail(EmailID.利用者情報変更完了, { + application_no: record.申請番号.value, + }); + if (!email) { + throw new Message("メール送信失敗 データは反映済み"); + } + + await SuccessDialog.fire(); + needReloadAtEnd(true); + }) + ); } }; - -const getCallBack車両番号_防犯登録番号変更申請承認 = (record: 各種申請) => { - return async () => { - const confirm = await ConfirmDialog.fire({ - title: "承認しますか", - }); - if (!confirm.isConfirmed) return; - - try { - await showLoadingDialog(); - await 車両番号_防犯登録番号変更申請承認(record); - } catch (e) { - console.error(e); - ErrorDialog.fire(); - return; - } - - SuccessDialog.fire().then(() => { - location.reload(); - }); - }; +const 車両番号変更承認ボタン = (record: 各種申請) => { + if ( + record.状況.value !== 状況Dropdown.完了 && + record.申請種別.value === 申請種別Dropdown.車両番号_防犯登録番号変更 + ) { + setHeaderButton( + "車両番号・防犯登録番号変更申請 承認", + apptemplate(async ({ needReloadAtEnd }) => { + const confirm = await ShowConfirmDialog({ title: "承認しますか" }); + if (!confirm.isConfirmed) return; + // 車室情報管理アプリへの反映 + const F = 車室情報管理フィールド名; + bulkRequest.update({ + app: AppID.車室情報管理, + id: record.$id.value, + record: makeRecordData({ + [F.車両番号]: + record.車両番号_防犯番号変更申請_変更後_車両番号.value ?? "", + [F.防犯登録番号]: + record.車両番号_防犯番号変更申請_変更後_防犯登録番号.value ?? "", + }), + }); + + // 申請の完了 + await 各種申請完了(record); + + // データ保存 + await bulkRequest.save(); + + // メールの送信 + const email = await sendEmail(EmailID.車両番号_防犯登録番号変更完了, { + application_no: record.申請番号.value, + }); + if (!email) { + throw new Message("メール送信失敗 データは反映済み"); + } + + await SuccessDialog.fire(); + needReloadAtEnd(true); + }) + ); + } }; setup(() => { kintone.events.on( [KintoneEvent.詳細.レコード詳細画面を表示した後], eventHnalder(async (event) => { - const currentRecord = event.record as 各種申請; + const record = event.record as 各種申請; await initMenuBox(); // 各種ボタンの設置 - if ( - currentRecord.状況.value !== 状況Dropdown.完了 && - currentRecord.申請種別.value === 申請種別Dropdown.口座変更申請 - ) { - setHeaderButton( - "口座変更申請 承認", - apptemplate(getCallBack口座変更申請承認(currentRecord)) - ); - } - if ( - currentRecord.状況.value !== 状況Dropdown.完了 && - currentRecord.申請種別.value === 申請種別Dropdown.解約申請 - ) { - setHeaderButton( - "解約申請 承認", - apptemplate(async ({ setEvent, needReloadAtEnd }) => { - getCallBack解約申請承認(currentRecord)(); - - const confirm = await ShowConfirmDialog({ title: "承認しますか" }); - if (!confirm.isConfirmed) return; - // 車室情報管理への反映 - bulkRequest.update({ - app: AppID.車室情報管理, - id: currentRecord.契約情報.value, - record: makeRecordData({ - [車室情報管理フィールド名.解約日]: - currentRecord.解約申請_解約希望日.value ?? "", - }), - }); - - // 申請の完了 - await 各種申請完了(currentRecord); - - // データ保存 - await bulkRequest.save(); - - // メールの送信 - const email = await sendEmail(EmailID.解約承認, { - application_no: currentRecord.申請番号.value, - }); - if (!email) { - throw new Error("メール送信失敗"); - } - - const 契約 = await get車室情報管理(currentRecord.契約情報.value); - setEvent(new 契約情報更新イベント().getEvent(契約)); + 口座変更承認ボタン(record); + 解約承認ボタン(record); + 利用者情報変更承認ボタン(record); + 車両番号変更承認ボタン(record); + }) + ); - await SuccessDialog.fire(); - needReloadAtEnd(true); - }) - ); - } - if ( - currentRecord.状況.value !== 状況Dropdown.完了 && - currentRecord.申請種別.value === 申請種別Dropdown.利用者情報変更 - ) { - setHeaderButton( - "利用者情報変更申請 承認", - apptemplate(getCallBack利用者情報変更申請承認(currentRecord)) - ); - } - if ( - currentRecord.状況.value !== 状況Dropdown.完了 && - currentRecord.申請種別.value === - 申請種別Dropdown.車両番号_防犯登録番号変更 - ) { - setHeaderButton( - "車両番号・防犯登録番号変更申請 承認", - apptemplate( - getCallBack車両番号_防犯登録番号変更申請承認(currentRecord) - ) - ); - } + kintone.events.on( + [KintoneEvent.詳細.レコード詳細画面を表示した後], + eventHnalder(async (event) => { + const record = event.record as 各種申請; + + const 申請種別 = record.申請種別.value; + + // 申請の詳細フィールドの制御 + Object.keys(申請詳細グループ).forEach((種別) => { + const グループ: string = get(申請詳細グループ, 種別); + if (申請種別 === 種別) { + console.log("グループオープン", グループ); + kintone.app.record.setGroupFieldOpen(グループ, true); + } else { + console.log("グループ非表示", グループ); + kintone.app.record.setFieldShown(グループ, false); + } + }); }) ); }); diff --git a/src/common/app-template.ts b/src/common/app-template.ts index fef2b12..5d06750 100644 --- a/src/common/app-template.ts +++ b/src/common/app-template.ts @@ -104,7 +104,6 @@ export const eventHnalder = ( console.log("canceled"); return false; } else if (e instanceof Message) { - console.error("message", e.message); ErrorDialog.fire({ text: e.message, }); diff --git a/src/types/各種申請.ts b/src/types/各種申請.ts index 09b09ac..c33bd10 100644 --- a/src/types/各種申請.ts +++ b/src/types/各種申請.ts @@ -27,6 +27,19 @@ export const 申請種別Dropdown = { export type 申請種別Dropdown = (typeof 申請種別Dropdown)[keyof typeof 申請種別Dropdown]; +export const 申請詳細グループ = { + [申請種別Dropdown.解約申請]: "解約申請", + [申請種別Dropdown.車庫証明発行申請]: "車庫証明発行申請", + [申請種別Dropdown.シール再発行申請]: "シール再発行申請", + [申請種別Dropdown.定期券再発行申請]: "定期券再発行申請", + [申請種別Dropdown.車両番号_防犯登録番号変更]: "車両番号・防犯番号変更申請", + [申請種別Dropdown.利用者情報変更]: "利用者情報変更申請", + [申請種別Dropdown.口座変更申請]: "口座変更申請", + [申請種別Dropdown.プラン変更]: "プラン変更申請", +} as const; +export type 申請詳細グループ = + (typeof 申請詳細グループ)[keyof typeof 申請詳細グループ]; + export const 各種申請フィールド名 = F; export type 各種申請 = AppRecord & {