京都のkintone用javascript
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 line
3.1KB

  1. import { apptemplate, eventHnalder } from "@/common/app-template";
  2. import { initMenuBox, setHeaderButton } from "@/common/header-button";
  3. import { KintoneEvent } from "@/common/kintone-event";
  4. import {
  5. ShowConfirmDialog,
  6. SuccessDialog,
  7. WarningDialog,
  8. } from "@/middleware/swal";
  9. import { saveReceipt } from "@/mypage/領収証発行";
  10. import { 領収証 } from "@/types/領収証";
  11. import { setup } from "..";
  12. import { 車室情報2, 車室情報2フィールド名 } from "@/types/車室情報2";
  13. import { 契約状況同期 } from "@/logic/契約状況同期";
  14. import bulkRequest from "@/rest-api/bulk";
  15. import { KintoneRestAPIClient } from "@kintone/rest-api-client";
  16. import { AppID } from "@/common/appids";
  17. import { QueryBuilder } from "@/rest-api/query";
  18. import { 定期申込予約フィールド名, 状態Dropdown } from "@/types/定期申込予約";
  19. import { getCreateUrl } from "@/rest-api/url";
  20. import { 定期予約選考フィールド名 } from "@/types/定期予約選考";
  21. const client = new KintoneRestAPIClient();
  22. setup(() => {
  23. const 申込確認 = async (record: 車室情報2) => {
  24. const query = new QueryBuilder();
  25. query
  26. .whereIn(定期申込予約フィールド名.状態, [
  27. 状態Dropdown.予約,
  28. 状態Dropdown.空き待ち,
  29. ])
  30. .where(定期申込予約フィールド名.駐車場名, record.定期駐車場.value);
  31. const { records } = await client.record.getRecords({
  32. app: AppID.定期申込予約,
  33. query: query.build(),
  34. });
  35. return records.length !== 0;
  36. };
  37. kintone.events.on(
  38. [KintoneEvent.詳細.レコード詳細画面を表示した後],
  39. eventHnalder(async (event) => {
  40. const record = event.record as 車室情報2;
  41. await initMenuBox();
  42. // 契約状況同期
  43. setHeaderButton(
  44. "契約状況同期",
  45. apptemplate(async ({ needReloadAtEnd }) => {
  46. const confirm = await ShowConfirmDialog({
  47. text: "契約状況を同期しますか",
  48. });
  49. if (!confirm.isConfirmed) return;
  50. await 契約状況同期(record.定期駐車場.value, record.車室番号.value);
  51. await bulkRequest.save();
  52. await SuccessDialog.fire();
  53. needReloadAtEnd(true);
  54. })
  55. );
  56. // 選考開始
  57. setHeaderButton(
  58. "空き募集",
  59. apptemplate(async () => {
  60. // 候補者がいるか確認
  61. const 申込有無 = await 申込確認(record);
  62. if (!申込有無) {
  63. await WarningDialog.fire({
  64. title: "申込者がいないため募集できません",
  65. });
  66. return;
  67. }
  68. const url = getCreateUrl(
  69. AppID.定期予約選考,
  70. new URLSearchParams({
  71. [定期予約選考フィールド名.対象車室一覧_車室レコード番号]:
  72. record.$id.value,
  73. [定期予約選考フィールド名.駐車場名]: record.定期駐車場.value,
  74. })
  75. );
  76. window.open(url, "_blank");
  77. })
  78. );
  79. })
  80. );
  81. });