diff --git a/src/apps/各種申請/index.tsx b/src/apps/各種申請/index.tsx index 8e5581f..536beba 100644 --- a/src/apps/各種申請/index.tsx +++ b/src/apps/各種申請/index.tsx @@ -1,10 +1,13 @@ +import { apptemplate, eventHnalder } from "@/common/app-template"; import { AppID } from "@/common/appids"; -import { setHeaderButton } from "@/common/header-button"; +import { initMenuBox, setHeaderButton } from "@/common/header-button"; +import { KintoneEvent } from "@/common/kintone-event"; import { makeRecordData } from "@/common/rest-api-client"; -import { 契約状況同期 } from "@/logic/契約状況同期"; +import { 契約情報更新イベント } from "@/event/契約情報更新"; import { ConfirmDialog, ErrorDialog, + ShowConfirmDialog, SuccessDialog, showLoadingDialog, } from "@/middleware/swal"; @@ -21,6 +24,7 @@ import { import { 車室情報管理フィールド名 } from "@/types/車室情報管理"; import { 顧客マスタフィールド名 } from "@/types/顧客マスタ"; import { KintoneRestAPIClient } from "@kintone/rest-api-client"; +import { setup } from ".."; const client = new KintoneRestAPIClient(); @@ -253,46 +257,87 @@ const getCallBack車両番号_防犯登録番号変更申請承認 = (record: }; }; -(() => { - console.info("script build at " + process.env.BUILD_TIME); - - kintone.events.on("app.record.detail.show", (event) => { - const currentRecord = event.record as 各種申請; - - // 各種ボタンの設置 - if ( - currentRecord.状況.value !== 状況Dropdown.完了 && - currentRecord.申請種別.value === 申請種別Dropdown.口座変更申請 - ) { - setHeaderButton( - "口座変更申請 承認", - getCallBack口座変更申請承認(currentRecord) - ); - } - if ( - currentRecord.状況.value !== 状況Dropdown.完了 && - currentRecord.申請種別.value === 申請種別Dropdown.解約申請 - ) { - setHeaderButton("解約申請 承認", getCallBack解約申請承認(currentRecord)); - } - if ( - currentRecord.状況.value !== 状況Dropdown.完了 && - currentRecord.申請種別.value === 申請種別Dropdown.利用者情報変更 - ) { - setHeaderButton( - "利用者情報変更申請 承認", - getCallBack利用者情報変更申請承認(currentRecord) - ); - } - if ( - currentRecord.状況.value !== 状況Dropdown.完了 && - currentRecord.申請種別.value === - 申請種別Dropdown.車両番号_防犯登録番号変更 - ) { - setHeaderButton( - "車両番号・防犯登録番号変更申請 承認", - getCallBack車両番号_防犯登録番号変更申請承認(currentRecord) - ); - } - }); -})(); +setup(() => { + kintone.events.on( + [KintoneEvent.詳細.レコード詳細画面を表示した後], + eventHnalder(async (event) => { + const currentRecord = 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(契約)); + + 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) + ) + ); + } + }) + ); +}); diff --git a/src/common/app-template.ts b/src/common/app-template.ts index 47c079f..fef2b12 100644 --- a/src/common/app-template.ts +++ b/src/common/app-template.ts @@ -37,11 +37,10 @@ export const apptemplate = ( } await eventManager.waitEnd(); console.log("イベント処理終了"); - } - - // 保存処理 - if (!bulkRequest.isSaved()) { - await bulkRequest.save(); + // 保存処理 + if (!bulkRequest.isSaved()) { + await bulkRequest.save(); + } } // 再読込