京都のkintone用javascript
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

216 lignes
7.6KB

  1. import { eventHnalder } from "@/common/app-template";
  2. import { AppID } from "@/common/appids";
  3. import { formatDateStr, today } from "@/common/datetime";
  4. import { initMenuBox, setHeaderButton } from "@/common/header-button";
  5. import { KintoneEvent, 値設定 } from "@/common/kintone-event";
  6. import { makeRecordData } from "@/common/rest-api-client";
  7. import { Message } from "@/exception";
  8. import { EmailID, sendEmail } from "@/mypage/メール";
  9. import { makeReceipt } from "@/mypage/領収証発行";
  10. import bulkRequest from "@/rest-api/bulk";
  11. import { get定期申込予約 } from "@/rest-api/定期申込予約";
  12. import { get顧客マスタ } from "@/rest-api/顧客マスタ";
  13. import { 入金予定結果, 入金予定結果フィールド名 } from "@/types/入金予定結果";
  14. import { 定期申込予約フィールド名 } from "@/types/定期申込予約";
  15. import { 顧客マスタフィールド名 } from "@/types/顧客マスタ";
  16. import { KintoneRestAPIClient } from "@kintone/rest-api-client";
  17. import { addDays, format, setHours } from "date-fns";
  18. import Swal from "sweetalert2";
  19. const client = new KintoneRestAPIClient();
  20. const 承認メール送信 = (record: 入金予定結果) => {
  21. return sendEmail(EmailID.申込承認, {
  22. season_ticket_contract_entry_record_no: Number(
  23. record[入金予定結果フィールド名.初回振り込み関連申込レコード番号].value
  24. ),
  25. });
  26. };
  27. const 領収証作成 = () => {
  28. return makeReceipt([Number(kintone.app.record.getId())]);
  29. };
  30. const テスト充当 = async (record: 入金予定結果) => {
  31. await client.record.updateRecord({
  32. app: AppID.入金予定結果,
  33. id: kintone.app.record.getId() ?? "",
  34. record: makeRecordData({
  35. [入金予定結果フィールド名.入金日]: format(new Date(), "yyyy-MM-dd"),
  36. [入金予定結果フィールド名.入金額]:
  37. record[入金予定結果フィールド名.支払予定金額].value,
  38. [入金予定結果フィールド名.残金]: "0",
  39. }),
  40. });
  41. await 領収証作成();
  42. if (
  43. !!record[入金予定結果フィールド名.初回振り込み関連申込レコード番号].value
  44. ) {
  45. await 承認メール送信(record);
  46. }
  47. Swal.fire({
  48. title: "テスト充当完了",
  49. icon: "success",
  50. timer: 1000,
  51. timerProgressBar: true,
  52. }).then((result) => {
  53. location.reload();
  54. });
  55. };
  56. const getCallbackFillAmount = (record: 入金予定結果) => {
  57. return async () => {
  58. Swal.fire({
  59. title: "テスト充当",
  60. text: "!注意!テスト用の機能",
  61. showCancelButton: true,
  62. confirmButtonText: "実行",
  63. cancelButtonText: "キャンセル",
  64. }).then((result) => {
  65. if (result.isConfirmed) {
  66. テスト充当(record);
  67. }
  68. });
  69. };
  70. };
  71. // クエリパラメータよりフィールドに値をセットする
  72. const setData = (event: any, targets: string[]) => {
  73. const param = new URLSearchParams(location.search.replace("?", ""));
  74. targets.forEach((target) => {
  75. const value = param.get(target);
  76. if (value === null) return;
  77. 値設定(event, target, value, true);
  78. });
  79. };
  80. (() => {
  81. console.info("script build at " + process.env.BUILD_TIME);
  82. kintone.events.on(
  83. [KintoneEvent.詳細.レコード詳細画面を表示した後],
  84. eventHnalder(async (event) => {
  85. const currentRecord = event.record as 入金予定結果;
  86. await initMenuBox();
  87. // 各種ボタンの設置
  88. if (currentRecord[入金予定結果フィールド名.残金].value !== "0") {
  89. if (currentRecord.parking_name.value.startsWith("TP")) {
  90. setHeaderButton("テスト充当", getCallbackFillAmount(currentRecord));
  91. }
  92. }
  93. })
  94. );
  95. const 初回請求金額確定チェック = (record: 入金予定結果) => {
  96. if (!record.first_payment_entry_record_no.value) {
  97. throw new Message("初回振り込み関連申込レコード番号が入力されていません");
  98. }
  99. // 申込の初回振り込み情報を入力する
  100. const F = 定期申込予約フィールド名;
  101. const 支払予定日 = record.payment_plan_date.value;
  102. if (!支払予定日) {
  103. throw new Message("支払予定日が入力されていません");
  104. }
  105. const 支払予定金額 = record.payment_plan_amount.value;
  106. if (!支払予定金額) {
  107. throw new Message("支払予定金額が入力されていません");
  108. }
  109. };
  110. const 初回請求金額確定 = async (record: 入金予定結果) => {
  111. 初回請求金額確定チェック(record);
  112. const 申込 = await get定期申込予約(
  113. record.first_payment_entry_record_no.value
  114. );
  115. // 申込の初回振り込み情報を入力する
  116. const F = 定期申込予約フィールド名;
  117. const 支払予定日 = record.payment_plan_date.value ?? "";
  118. const 支払予定金額 = record.payment_plan_amount.value ?? "";
  119. const 日割り金額 = Number(支払予定金額) - Number(申込.定期駐車料金.value);
  120. const 日割り月 = (() => {
  121. if (日割り金額 === 0) return "";
  122. let month = Number(record.target_month.value) - 1;
  123. if (month === 0) {
  124. month = 12;
  125. }
  126. return String(month);
  127. })();
  128. bulkRequest.update({
  129. app: AppID.定期申込予約,
  130. id: record.first_payment_entry_record_no.value,
  131. record: makeRecordData({
  132. [F.振込期日]: 支払予定日,
  133. [F.初回振り込み合計額]: 支払予定金額,
  134. [F.請求対象分_月]: record.target_month.value,
  135. [F.請求対象分_金額]: 申込.定期駐車料金.value,
  136. [F.日割り分_金額]: String(日割り金額),
  137. [F.日割り分_月]: 日割り月,
  138. }),
  139. });
  140. await bulkRequest.save();
  141. };
  142. kintone.events.on(
  143. KintoneEvent.追加.レコード追加画面を表示した後,
  144. eventHnalder(async (event) => {
  145. setData(event, [
  146. 入金予定結果フィールド名.車室情報管理レコード番号,
  147. 入金予定結果フィールド名.初回振り込み関連申込レコード番号,
  148. ]);
  149. return event;
  150. })
  151. );
  152. kintone.events.on(
  153. KintoneEvent.追加.保存するとき,
  154. eventHnalder(async (event: any) => {
  155. const record = event.record as 入金予定結果;
  156. // 初回請求確定時にはメールを送信する
  157. if (
  158. record[入金予定結果フィールド名.初回振り込み関連申込レコード番号].value
  159. ) {
  160. await 初回請求金額確定(record);
  161. }
  162. })
  163. );
  164. kintone.events.on(
  165. KintoneEvent.追加.保存に成功した後,
  166. eventHnalder(async (event: any) => {
  167. const record = event.record as 入金予定結果;
  168. // 初回請求確定時にはメールを送信する
  169. if (
  170. record[入金予定結果フィールド名.初回振り込み関連申込レコード番号].value
  171. ) {
  172. // メール送信
  173. sendEmail(EmailID.申込受付, {
  174. season_ticket_contract_entry_record_no: Number(
  175. record[入金予定結果フィールド名.初回振り込み関連申込レコード番号]
  176. .value
  177. ),
  178. });
  179. // 口座振替登録催促日時を設定する
  180. const 口座登録催促日時 = (() => {
  181. return formatDateStr(setHours(addDays(today(), 5), 9));
  182. })();
  183. const 顧客 = await get顧客マスタ({
  184. 顧客コード: Number(record.customer_code.value),
  185. });
  186. bulkRequest.update({
  187. app: AppID.顧客マスタ,
  188. id: 顧客?.$id.value,
  189. record: makeRecordData({
  190. [顧客マスタフィールド名.口座登録催促予定日時]: 口座登録催促日時,
  191. }),
  192. });
  193. }
  194. })
  195. );
  196. })();