From e171ea1a2e523244f3f63b5ca402384e66d521b0 Mon Sep 17 00:00:00 2001 From: "sosuke.iwabuchi" Date: Tue, 21 May 2024 10:18:13 +0900 Subject: [PATCH] =?UTF-8?q?=E8=A6=AA=E5=AD=90=E3=82=A2=E3=82=AB=E3=82=A6?= =?UTF-8?q?=E3=83=B3=E3=83=88=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apps/定期申込予約/自動承認.ts | 34 +++++++++++++++------ src/apps/顧客マスタ/index.ts | 33 ++++++++++++++++++++ src/mypage/IC定期.ts | 2 ++ src/rest-api/顧客マスタ.ts | 9 ++++++ src/types/顧客マスタ.ts | 4 +++ 5 files changed, 72 insertions(+), 10 deletions(-) diff --git a/src/apps/定期申込予約/自動承認.ts b/src/apps/定期申込予約/自動承認.ts index 3cece59..cd0912f 100644 --- a/src/apps/定期申込予約/自動承認.ts +++ b/src/apps/定期申込予約/自動承認.ts @@ -22,7 +22,7 @@ import { 定期駐車場プランマスタ } from "@/types/定期駐車場プラ import { 自動承認グループ } from "@/types/自動承認グループ"; import { 車室情報管理, 車室情報管理フィールド名 } from "@/types/車室情報管理"; import { 車室情報2, 車室情報2モデル } from "@/types/車室情報2"; -import { 顧客マスタフィールド名 } from "@/types/顧客マスタ"; +import { 顧客マスタ, 顧客マスタフィールド名 } from "@/types/顧客マスタ"; import { sprintf } from "sprintf"; import { CancelError, Message } from "@/exception"; import { dateParse, formatDateStr, now } from "@/common/datetime"; @@ -197,10 +197,13 @@ export class 申込 { private async 顧客マスタ取得() { const customer = await get顧客マスタ({ メールアドレス: this.定期申込予約.メールアドレス.value, + 親アカウント: true, 必須: false, }); if (customer) { const confirm = await ShowConfirmDialog({ + showDenyButton: true, + denyButtonText: "子アカウント新規作成", html: sprintf( "

既存顧客[%s]様へ契約を追加しますか

", getDetailUrl(AppID.顧客マスタ, customer.$id.value), @@ -208,20 +211,24 @@ export class 申込 { ), }); - if (!confirm.isConfirmed) throw new CancelError(); - - this.顧客情報.顧客コード = Number( - customer[顧客マスタフィールド名.顧客コード].value - ); - this.顧客情報.IC定期利用者IC = Number( - customer[顧客マスタフィールド名.IC定期関連情報_ユーザーID].value - ); + if (confirm.isConfirmed) { + this.顧客情報.顧客コード = Number( + customer[顧客マスタフィールド名.顧客コード].value + ); + this.顧客情報.IC定期利用者IC = Number( + customer[顧客マスタフィールド名.IC定期関連情報_ユーザーID].value + ); + } else if (confirm.isDenied) { + await this.顧客マスタ作成(customer); + } else { + throw new CancelError(); + } } else { await this.顧客マスタ作成(); } } - private async 顧客マスタ作成() { + private async 顧客マスタ作成(親顧客マスタ?: 顧客マスタ) { const F = 顧客マスタフィールド名; const 顧客コード = await getNext顧客コード(); @@ -248,6 +255,7 @@ export class 申込 { const data = makeRecordData({ [F.顧客コード]: String(顧客コード), + [F.顧客コード親]: 親顧客マスタ?.CustomerCodeParent.value ?? "", [F.顧客名]: this.定期申込予約.氏名.value, [F.顧客名カナ]: this.定期申込予約.フリガナ.value, [F.電話番号]: this.定期申込予約.電話番号.value, @@ -271,6 +279,9 @@ export class 申込 { zip_code: 郵便番号.replace(/-/g, ""), address1: 住所, phone_number: this.定期申込予約.電話番号.value, + parent_user_id: 親顧客マスタ + ? 親顧客マスタ.IC定期関連情報_ユーザーID.value + : undefined, }, message ); @@ -281,6 +292,9 @@ export class 申込 { } const 利用者ID = res.id; data[F.IC定期関連情報_ユーザーID] = { value: String(利用者ID) }; + data[F.IC定期関連情報_親ユーザーID] = { + value: 親顧客マスタ?.IC定期関連情報_親ユーザーID.value ?? "", + }; this.顧客情報.IC定期利用者IC = 利用者ID; } diff --git a/src/apps/顧客マスタ/index.ts b/src/apps/顧客マスタ/index.ts index fad2aa9..663ecbc 100644 --- a/src/apps/顧客マスタ/index.ts +++ b/src/apps/顧客マスタ/index.ts @@ -37,6 +37,7 @@ setup(() => { const res = await 利用者情報更新({ user_id: record.IC定期関連情報_ユーザーID.value, + parent_user_id: record.IC定期関連情報_親ユーザーID.value, email: record[F.メールアドレス].value, first_name: record[F.顧客名].value, first_name_kana: record[F.顧客名カナ].value, @@ -60,4 +61,36 @@ setup(() => { return event; }) ); + + kintone.events.on( + [KintoneEvent.詳細.レコードを削除する前], + eventHnalder(async (event, { setEvent }) => { + const record = event.record as 顧客マスタ; + const F = 顧客マスタフィールド名; + // IC定期処理 + if (!!record.IC定期関連情報_ユーザーID.value) { + await showLoadingDialog(); + const message = new MessageBag(); + const res = await 利用者情報削除( + { + user_id: record.IC定期関連情報_ユーザーID.value, + }, + message + ); + + if (res === false) { + ErrorDialog.fire({ + text: "IC定期連携に失敗しました " + message.getGeneralMessage(), + }); + return false; + } + + await SuccessDialog.fire({ + text: "IC定期連携成功", + }); + } + + return event; + }) + ); }); diff --git a/src/mypage/IC定期.ts b/src/mypage/IC定期.ts index 4955034..3d56925 100644 --- a/src/mypage/IC定期.ts +++ b/src/mypage/IC定期.ts @@ -10,6 +10,7 @@ export type 利用者情報新規作成Request = { zip_code: string; address1: string; phone_number: string; + parent_user_id?: string; }; export type 利用者情報新規作成Response = { id: number; @@ -34,6 +35,7 @@ export type 利用者情報更新Request = { zip_code: string; address1: string; phone_number: string; + parent_user_id?: string; }; export type 利用者情報更新Response = { id: number; diff --git a/src/rest-api/顧客マスタ.ts b/src/rest-api/顧客マスタ.ts index 9ecd366..ec708ca 100644 --- a/src/rest-api/顧客マスタ.ts +++ b/src/rest-api/顧客マスタ.ts @@ -13,6 +13,7 @@ type Props = { 顧客コード?: number; メールアドレス?: string; 電話番号?: string; + 親アカウント?: boolean; 必須?: boolean; }; export const get顧客マスタ = async ({ @@ -20,6 +21,7 @@ export const get顧客マスタ = async ({ 顧客コード, メールアドレス, 電話番号, + 親アカウント, 必須 = true, }: Props): Promise<顧客マスタ | null> => { const builder = new QueryBuilder(); @@ -37,6 +39,13 @@ export const get顧客マスタ = async ({ builder.where(顧客マスタフィールド名.電話番号, 電話番号); } + if (親アカウント === true) { + builder.where(顧客マスタフィールド名.顧客コード親, ""); + } + if (親アカウント === false) { + builder.where(顧客マスタフィールド名.顧客コード親, "", "!="); + } + const { records } = await client.record.getRecords<顧客マスタ>({ app: AppID.顧客マスタ, query: builder.build(), diff --git a/src/types/顧客マスタ.ts b/src/types/顧客マスタ.ts index 9a5d20a..5d172d5 100644 --- a/src/types/顧客マスタ.ts +++ b/src/types/顧客マスタ.ts @@ -3,6 +3,7 @@ import { AppRecord } from "."; const F = { 顧客コード: "CustomerCode", + 顧客コード親: "CustomerCodeParent", 銀行支店コード: "ChargedBankBranchCode", 引落預金種別: "ChargedDepositType", 引落口座名義人カナ: "ChargedAccountsKana", @@ -23,6 +24,7 @@ const F = { 支払方法: "支払方法", IC定期関連情報_ユーザーID: "IC定期関連情報_ユーザーID", + IC定期関連情報_親ユーザーID: "IC定期関連情報_親ユーザーID", } as const; // export const 支払種別Dropdown = { @@ -49,6 +51,7 @@ export type 顧客マスタ = AppRecord & { [F.引落預金種別]: KintoneRecordField.Number; [F.SMBC契約番号]: KintoneRecordField.SingleLineText; [F.顧客コード]: KintoneRecordField.Number; + [F.顧客コード親]: KintoneRecordField.Number; [F.顧客名]: KintoneRecordField.SingleLineText; SMBC口座名義_1: KintoneRecordField.SingleLineText; SMBC処理完了: KintoneRecordField.Dropdown; @@ -90,4 +93,5 @@ export type 顧客マスタ = AppRecord & { 領収書名_入力: KintoneRecordField.SingleLineText; 領収書名: KintoneRecordField.SingleLineText; [F.IC定期関連情報_ユーザーID]: KintoneRecordField.Number; + [F.IC定期関連情報_親ユーザーID]: KintoneRecordField.Number; };