diff --git a/src/apps/定期申込予約/index.tsx b/src/apps/定期申込予約/index.tsx index 594c76e..732751b 100644 --- a/src/apps/定期申込予約/index.tsx +++ b/src/apps/定期申込予約/index.tsx @@ -10,7 +10,7 @@ import { } from "@/middleware/swal"; import { getCreateUrl, getDetailUrl } from "@/rest-api/url"; import { 入金予定結果フィールド名 } from "@/types/入金予定結果"; -import { 定期申込予約 } from "@/types/定期申込予約"; +import { 定期申込予約, 状態Dropdown } from "@/types/定期申込予約"; import { setup } from ".."; import { 申込 } from "./自動承認"; @@ -21,7 +21,13 @@ setup(() => { const record: 定期申込予約 = event.record; await initMenuBox(); - if (!record.auto_confirm_status.value) { + + const S = 状態Dropdown; + if ( + [S.新規, S.選考当選, S.予約, S.空き待ち].find((status) => { + return status === record.status.value; + }) + ) { setHeaderButton( "自動承認", apptemplate(async ({ setEvent, needReloadAtEnd }) => { @@ -59,7 +65,6 @@ setup(() => { { // 車室情報管理アプリ画面オープン const url = getDetailUrl(AppID.車室情報管理, 契約.$id.value); - console.log(url, param); window.open(url, "_blank"); } @@ -68,6 +73,28 @@ setup(() => { }) ); } + + if ( + !!record.自動承認契約情報.value && + [S.承認_手動, S.承認_自動承認].find((status) => { + return status === record.status.value; + }) + ) { + setHeaderButton( + "初回入金予定作成", + apptemplate(async () => { + // 車室情報管理アプリ画面オープン + const param = new URLSearchParams({ + [入金予定結果フィールド名.車室情報管理レコード番号]: + record.自動承認契約情報.value, + [入金予定結果フィールド名.初回振り込み関連申込レコード番号]: + record.$id.value, + }); + const url = getCreateUrl(AppID.入金予定結果, param); + window.open(url, "_blank"); + }) + ); + } }) ); }); diff --git a/src/apps/定期申込予約/自動承認.ts b/src/apps/定期申込予約/自動承認.ts index a389853..b4ff5da 100644 --- a/src/apps/定期申込予約/自動承認.ts +++ b/src/apps/定期申込予約/自動承認.ts @@ -26,6 +26,7 @@ import { sprintf } from "sprintf"; import { CancelError, Message } from "@/exception"; import { dateParse, now } from "@/common/datetime"; import bulkRequest from "@/rest-api/bulk"; +import apiClient from "@/middleware/api-client"; export class 申込 { private 定期申込予約: 定期申込予約; @@ -243,15 +244,26 @@ export class 申込 { private async 申込情報完了() { if (this.プラン === null) throw new Error(); const F = 定期申込予約フィールド名; - bulkRequest.update({ - app: AppID.定期申込予約, - id: this.定期申込予約.$id.value, - record: makeRecordData({ - [F.状態]: 状態Dropdown.承認_自動承認, - [F.自動承認ステータス]: 自動承認ステータスDropdown.承認済, - [F.定期駐車料金]: this.プラン.契約金額.value, - }), - }); + bulkRequest.update( + { + app: AppID.定期申込予約, + id: this.定期申込予約.$id.value, + record: makeRecordData({ + [F.状態]: 状態Dropdown.承認_自動承認, + [F.自動承認ステータス]: 自動承認ステータスDropdown.承認済, + [F.定期駐車料金]: this.プラン.契約金額.value, + }), + }, + async () => { + await apiClient.record.updateRecord({ + app: AppID.定期申込予約, + id: this.定期申込予約.$id.value, + record: makeRecordData({ + [F.自動承認契約情報]: this.作成後契約?.$id.value ?? "", + }), + }); + } + ); } private get契約開始日() { diff --git a/src/common/header-button.ts b/src/common/header-button.ts index a9b146e..0b7b91b 100644 --- a/src/common/header-button.ts +++ b/src/common/header-button.ts @@ -45,7 +45,6 @@ export const initMenuBox = () => { }; export const setHeaderButton = (title: string, onClick: VoidFunction) => { - console.log("setHeaderButton", title); const menu = getMenu(); if (!menu) return; @@ -60,5 +59,4 @@ export const setHeaderButton = (title: string, onClick: VoidFunction) => { button.appendChild(label); menu.appendChild(button); - console.log("setHeaderButton", title, "complete"); }; diff --git a/src/middleware/api-client.ts b/src/middleware/api-client.ts new file mode 100644 index 0000000..44dc8ff --- /dev/null +++ b/src/middleware/api-client.ts @@ -0,0 +1,5 @@ +import { KintoneRestAPIClient } from "@kintone/rest-api-client"; + +const apiClient = new KintoneRestAPIClient(); + +export default apiClient; diff --git a/src/types/定期申込予約.ts b/src/types/定期申込予約.ts index aa53c1d..5a7f28e 100644 --- a/src/types/定期申込予約.ts +++ b/src/types/定期申込予約.ts @@ -13,6 +13,7 @@ const F = { 請求対象分_月: "請求対象分_月", 請求対象分_金額: "請求対象分_金額", 初回振り込み合計額: "初回振り込み合計額", + 自動承認契約情報: "自動承認契約情報", } as const; export const 状態Dropdown = { @@ -73,4 +74,5 @@ export type 定期申込予約 = AppRecord & { 支払方法: KintoneRecordField.Dropdown; [F.自動承認ステータス]: KintoneRecordField.SingleLineText; [F.状態]: KintoneRecordField.Dropdown; + [F.自動承認契約情報]: KintoneRecordField.Number; };