mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
Compare commits
500 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 77a7b6ccf8 | |||
| 0ac14fe342 | |||
| 00eed01cea | |||
| 6702dd7dc6 | |||
| a526772e02 | |||
| b486d25a8b | |||
| b73b452621 | |||
| 4f4787e088 | |||
| f32024d19a | |||
| 3b666a924f | |||
| 021df11600 | |||
| d306fad40c | |||
| ebc12638ff | |||
| 437dd75934 | |||
| e1c0701629 | |||
| 96a5eb1be5 | |||
| 7add41ea5a | |||
| 548dfd19e5 | |||
| f0a6dd4a5a | |||
| 7159114733 | |||
| e300a60b5a | |||
| 4cbd83a6fa | |||
| b39202111e | |||
| a891608d13 | |||
| aff05c6b1a | |||
| 70eac011f3 | |||
| 10e843aebf | |||
| a24f51dad3 | |||
| 9245285fe2 | |||
| eb1337292b | |||
| aa114c164b | |||
| 0f9849c0ac | |||
| 36b167dafb | |||
| 1002c6c437 | |||
| 25352659f3 | |||
| dfac7f84ff | |||
| c099314bdb | |||
| 404019f181 | |||
| 8afd8c6382 | |||
| ef4ad07547 | |||
| 31aa8e7652 | |||
| 994967e940 | |||
| 90eef08f9b | |||
| def2167803 | |||
| bf834cf79b | |||
| 470add1563 | |||
| 114658f198 | |||
| d01bfe33a8 | |||
| 47ba16b20a | |||
| d6c6211937 | |||
| 536b1c5b01 | |||
| f84fcb78b8 | |||
| aec5c89979 | |||
| f46a0610f5 | |||
| d879acc001 | |||
| 8516929056 | |||
| 595f2b5e9b | |||
| 6a4e8776bd | |||
| ec16c6c47e | |||
| 2b2dd0a026 | |||
| a8c12d0c92 | |||
| 334bd08e60 | |||
| ddd9a3d2da | |||
| 2b1d5290f3 | |||
| 935588b30e | |||
| 677025b4a2 | |||
| 0da9f9d651 | |||
| c752cad057 | |||
| cdfb59a70b | |||
| 91fcbffab6 | |||
| 33e3b86b82 | |||
| a012707bae | |||
| 00bc644ea9 | |||
| 126346dc52 | |||
| 777b06c690 | |||
| 1f96100390 | |||
| 7e5898a253 | |||
| 86651d3f3f | |||
| ebd3e14f0e | |||
| e9a1f4298f | |||
| cc8f258c41 | |||
| f60a07bc5b | |||
| 6dc93b1065 | |||
| 76c68d0d79 | |||
| f1ed22ff22 | |||
| d478ef5e22 | |||
| 6643fe5a60 | |||
| 7a6b003cb9 | |||
| e6cee4a93a | |||
| c61ef5471b | |||
| c9c618e3f8 | |||
| ceb7cb6b2d | |||
| f765895988 | |||
| b1715172db | |||
| d84b2583d8 | |||
| f38cebc0d9 | |||
| 7951754722 | |||
| 4fc689898f | |||
| 69d7f65b76 | |||
| b626c2805f | |||
| 97c16ce596 | |||
| 88e3ec7bbc | |||
| 3ce30115f8 | |||
| 4fdfe63dc9 | |||
| badb1e141a | |||
| c894f26d18 | |||
| 3b9599d169 | |||
| 9a9a9c0cb5 | |||
| b69126ed84 | |||
| 91b0bf7c27 | |||
| 1b2a45f9ac | |||
| cb62416552 | |||
| d2781b0a89 | |||
| 325f3f1bd8 | |||
| 346c731c42 | |||
| 61766d3255 | |||
| 0898892f15 | |||
| 3dd4a9cebc | |||
| 549e15499c | |||
| a4a07f2ce9 | |||
| 6930696692 | |||
| 7df9559f35 | |||
| eeeb0a404c | |||
| b3c4a438ad | |||
| a9e6f7155e | |||
| 3d94474d7c | |||
| 4872a53a25 | |||
| 662dec38bc | |||
| 9f0cefe91c | |||
| 3cb6bfcf52 | |||
| 7d4869fbdc | |||
| 4ae36ee3f0 | |||
| 21acb09f0c | |||
| f17bc1493b | |||
| 6943cd3903 | |||
| 14b63dd0f1 | |||
| db4d9ad38c | |||
| 06dd9a3609 | |||
| 5ba58c92d4 | |||
| d44de5a363 | |||
| b70ae164e1 | |||
| f89236bb5e | |||
| 4759a82034 | |||
| 866bd90b3d | |||
| b0dfc7f31c | |||
| 561a9fe186 | |||
| dbdfd2c50b | |||
| afc102e618 | |||
| 7736fce5bb | |||
| 04dcf110a3 | |||
| 53bca6170f | |||
| 20e27dccc1 | |||
| 965dc01e86 | |||
| 64a0a9c8a8 | |||
| 0ed30e184b | |||
| 13205ca80a | |||
| 0d6e229ee5 | |||
| 319afa3faf | |||
| 6da6cf699f | |||
| ca830f8e3d | |||
| 22be41058f | |||
| c4debcecce | |||
| 6fdff6706d | |||
| d5b4111ae4 | |||
| 2df86e7be8 | |||
| 6efe44ba55 | |||
| c766f53753 | |||
| 38dfeec892 | |||
| cf8ed9ccad | |||
| 90c61cbdf6 | |||
| bfcdb9883d | |||
| b0a1b837d0 | |||
| 09ae619829 | |||
| 59f4528841 | |||
| d049f6c34f | |||
| 8b7ed9e46b | |||
| e6172be81e | |||
| 324b9b14ef | |||
| a10c20394d | |||
| ff2d53a0b7 | |||
| 42d8896ab7 | |||
| 50d499005d | |||
| b421bc48d0 | |||
| f7986149e8 | |||
| 309a9ecc86 | |||
| d30979f5cd | |||
| 43cd3abe02 | |||
| 770f363c60 | |||
| 88c6c863e7 | |||
| ba84e718cb | |||
| fed2bf7878 | |||
| 6f90bd604a | |||
| fa199e4879 | |||
| 46c06ea548 | |||
| fd868eaa0c | |||
| 8dfccf25d8 | |||
| 5d8dfca3b5 | |||
| aee0ad8a20 | |||
| 2fa086bb32 | |||
| 0af612703a | |||
| f22c4e4798 | |||
| 841aadc107 | |||
| f31a80340b | |||
| 727fd2ad43 | |||
| a4275f4b66 | |||
| 9ac5e0ee76 | |||
| 24499d110a | |||
| c24aebe02d | |||
| fd32b55ad9 | |||
| d2b19cbd7b | |||
| 2c29cffa45 | |||
| 476cf2fa29 | |||
| 1797498df2 | |||
| f7d1beffcf | |||
| ac6e7c6d36 | |||
| d7ef86e24b | |||
| 3dff72b0f0 | |||
| eea76e77a8 | |||
| 11f9a685a8 | |||
| c863ebc2af | |||
| e8aea0a27e | |||
| 79cf777b11 | |||
| 203782c258 | |||
| 0a0a1a23f9 | |||
| f9f4c5b67c | |||
| 98107373e8 | |||
| 9838cf347b | |||
| f183ee5c7a | |||
| 2ab2cd6d99 | |||
| 1571d79685 | |||
| 5e3648b385 | |||
| 62b05bf9c0 | |||
| 7579cd5533 | |||
| 174e5ed1a3 | |||
| c6e9e98ce1 | |||
| 9562ce7b40 | |||
| 57fa67c05a | |||
| eadb08879d | |||
| 50b8b77f22 | |||
| 045913d05f | |||
| b53c8b99a0 | |||
| f23d369e02 | |||
| d6b8b10183 | |||
| 1c77deeee7 | |||
| 6a3d2c0dcd | |||
| b1f4b4dc4b | |||
| a518895096 | |||
| 046fb74cab | |||
| 00f09364b1 | |||
| 02c5cddc94 | |||
| 9f079c1e52 | |||
| c32074d72c | |||
| 7d46e3dc2e | |||
| e7b53efa4b | |||
| aebb9a0b28 | |||
| 4ec62c936e | |||
| f7ae1f835f | |||
| 3769309ce3 | |||
| 15b3151c5f | |||
| b0707db551 | |||
| 1a8d794a66 | |||
| 1b7e8a342f | |||
| f08fae4f77 | |||
| 6cd09a413d | |||
| 84eb34a9dd | |||
| 37317ed95c | |||
| 201c9249cc | |||
| 46dfacae23 | |||
| d856b35e24 | |||
| 28c94e3e1d | |||
| a1e8f582ba | |||
| f3f552bd16 | |||
| 5af00faa32 | |||
| f0dcb6b8ca | |||
| e32b9ddcb2 | |||
| 57ef4109f7 | |||
| ef3611e7fc | |||
| 0090961ec0 | |||
| 640cf26970 | |||
| d1d0692e2e | |||
| 6b13794ee5 | |||
| 8e88355894 | |||
| 1b98e5d4d8 | |||
| d8daf09844 | |||
| 0bb9aee139 | |||
| 306b8d3bf3 | |||
| 2bf764a05c | |||
| 6c3285f624 | |||
| afb79b0589 | |||
| 4f571f1c16 | |||
| 81ca60a09b | |||
| 23453eb8f5 | |||
| 3dc32da834 | |||
| f089492830 | |||
| 3412994d15 | |||
| 6eaa92dfd4 | |||
| 8d668429e1 | |||
| 8d1a3b665e | |||
| 7b99bae197 | |||
| dad169d854 | |||
| f985c041e4 | |||
| 5326eff293 | |||
| d66bd8c606 | |||
| ea5ad20684 | |||
| 23ee8828f0 | |||
| 0dd2edfe01 | |||
| 6edc278bdf | |||
| f81c49becb | |||
| 03a9451fc8 | |||
| cc0b051a0a | |||
| 865438e3fb | |||
| d39b71e759 | |||
| 5e6b03ef08 | |||
| c291ba3246 | |||
| ab2e7db9d0 | |||
| 13c1a82142 | |||
| 6185fafb57 | |||
| 2ab7c10d5d | |||
| bc6ebcfeda | |||
| 10fb9fc990 | |||
| 28639516d5 | |||
| 2bf0f2874e | |||
| a81a61135f | |||
| d2e88c2061 | |||
| 8f4f3d93b8 | |||
| 7daca04cc1 | |||
| 2c5168badf | |||
| 73f4b486c0 | |||
| ed7ee1a268 | |||
| 4e7b91a7b4 | |||
| 7c0581728e | |||
| 52cb440cb3 | |||
| 7c64870fed | |||
| 7290f242f4 | |||
| 9be09ae281 | |||
| 32088b916f | |||
| f51236fcfc | |||
| c385c42c8f | |||
| 02dc624036 | |||
| 4e5f9c710c | |||
| 2712821f4e | |||
| d6849a48d2 | |||
| 2e44371c6c | |||
| 98ae56a1aa | |||
| 7fcab4d295 | |||
| 550bcc426b | |||
| 844ac01b70 | |||
| 9ef232bac5 | |||
| 34ec650a01 | |||
| 1d27781c02 | |||
| e81c0a3baf | |||
| be0bdcd299 | |||
| 7e73c99074 | |||
| 0f86ba0f2d | |||
| 10a37fde75 | |||
| 6ad1a3349b | |||
| 3bb5d5e5a5 | |||
| 3279fb30ce | |||
| 34eae71b44 | |||
| 4f168b51c7 | |||
| ded1cc1f62 | |||
| 39f2fc48a8 | |||
| a72b22da6e | |||
| dc4e569453 | |||
| 17a6cee1e3 | |||
| 5e32724d40 | |||
| cd3a5ad441 | |||
| 11bd8b27b5 | |||
| 9a1a6a7e41 | |||
| d02f919b76 | |||
| 4529ee50e3 | |||
| cd42bd6bc0 | |||
| 4ed1e4f8b5 | |||
| ea7f8a68f4 | |||
| 11a63f76b7 | |||
| cd41d5daab | |||
| 9f2fcbf154 | |||
| 70d9b4d8ed | |||
| 39f70bd71b | |||
| 817f8a7010 | |||
| 2276df2790 | |||
| 8ec76af012 | |||
| 9f0dc8c644 | |||
| 2d0c8dbd3f | |||
| 8224dbf8ec | |||
| 6e4462e217 | |||
| b1ccad081d | |||
| c0a818af7e | |||
| e0371b0884 | |||
| 8a6f78ef84 | |||
| b2c09bb7c7 | |||
| c550922974 | |||
| 432d837aaf | |||
| b24fb54856 | |||
| f37eea687a | |||
| 77b05c6440 | |||
| 731bec5a94 | |||
| 6ea25aa3b1 | |||
| d4f4505405 | |||
| bd653851e2 | |||
| c8f47c741a | |||
| 78486be3ea | |||
| fe04bf5692 | |||
| 3c29b8bc77 | |||
| 45d65024db | |||
| fd2077c68b | |||
| 819b709f7e | |||
| 549a710a8d | |||
| ec8ae7561d | |||
| 5f68c05acc | |||
| b9b349aa7a | |||
| 0a447f93c1 | |||
| 6ec6323bbc | |||
| c44e63bd2b | |||
| 500c30c2bc | |||
| 507c4005af | |||
| d49bca1d40 | |||
| e4d75dad68 | |||
| 4f22024c82 | |||
| 751c27b73e | |||
| 0d77aa4a5f | |||
| 6fde6b180a | |||
| 663c1dea14 | |||
| 4aab54981e | |||
| 04c987b86b | |||
| 800739bd4f | |||
| e0ee846106 | |||
| 84b49d2ac6 | |||
| ec95ddbddd | |||
| 6d2057842d | |||
| 1843a47d59 | |||
| 9e0d3e2bbf | |||
| e6a38c3f65 | |||
| f58cb43801 | |||
| 517e8c758c | |||
| 97c5917401 | |||
| 4be719b9d8 | |||
| 31a9828661 | |||
| 580c357667 | |||
| 1152cd2bef | |||
| f1227c9dcb | |||
| 5f3c3be1f3 | |||
| ae00f49e64 | |||
| d9322cc17d | |||
| f5f154883b | |||
| 8c21883aa9 | |||
| 4ddd1dc8e3 | |||
| 879702d31d | |||
| 8c95dc8327 | |||
| f0eb3fcf52 | |||
| df6c1ae49d | |||
| 42a56a08d7 | |||
| 871f0403ad | |||
| b57a0fcc90 | |||
| 6ef9c1338f | |||
| ea4dd29bbf | |||
| d591c89cac | |||
| 22d24af41c | |||
| 6ed7dcfa6d | |||
| dda29e10d1 | |||
| 20d124504b | |||
| b9c1989cae | |||
| 5fae7752f2 | |||
| 9d9b9d93db | |||
| f41899dbc9 | |||
| 9e5d878e82 | |||
| 035f187bac | |||
| cb78ec4990 | |||
| 3a2fac013e | |||
| 3b2e11fd41 | |||
| 414d617341 | |||
| 0774200aa5 | |||
| 5dd64b9907 | |||
| 8fc5d42bb8 | |||
| 36ff6d04ee | |||
| f23a0144b0 | |||
| de63b6721a | |||
| a200dac23c | |||
| 09dd907f88 | |||
| 33b8d0a8b0 | |||
| 398282b3bf | |||
| 035482accc | |||
| fcfd2fb576 | |||
| 2c28d0a831 | |||
| 907afbb062 | |||
| addfaff692 | |||
| ecdbb764d5 | |||
| a3be3de338 | |||
| 9e895af62a | |||
| 1f9992c1c8 | |||
| 574fb3b371 | |||
| 4643a39c3e | |||
| 88b8767ca4 | |||
| de19cc5de2 | |||
| b9dad3094c | |||
| ff427d13cc | |||
| 8295943b82 | |||
| a3169d582d | |||
| dd6c6263e7 | |||
| 5d03b68576 |
+21
-25
@@ -2,6 +2,17 @@ stages:
|
|||||||
- build
|
- build
|
||||||
- deploy
|
- deploy
|
||||||
|
|
||||||
|
# ==========================================================
|
||||||
|
# ✅ Global defaults
|
||||||
|
# ==========================================================
|
||||||
|
default:
|
||||||
|
tags:
|
||||||
|
- server-development-biznet
|
||||||
|
interruptible: true
|
||||||
|
|
||||||
|
# ==========================================================
|
||||||
|
# 🏗️ Build Template
|
||||||
|
# ==========================================================
|
||||||
.build_template: &build_template
|
.build_template: &build_template
|
||||||
stage: build
|
stage: build
|
||||||
image: node:20-alpine
|
image: node:20-alpine
|
||||||
@@ -39,6 +50,9 @@ stages:
|
|||||||
- out/
|
- out/
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
|
|
||||||
|
# ==========================================================
|
||||||
|
# 🚀 Deploy Template
|
||||||
|
# ==========================================================
|
||||||
.deploy_template: &deploy_template
|
.deploy_template: &deploy_template
|
||||||
stage: deploy
|
stage: deploy
|
||||||
image:
|
image:
|
||||||
@@ -82,11 +96,11 @@ stages:
|
|||||||
if [ "$STATUS" = "success" ]; then
|
if [ "$STATUS" = "success" ]; then
|
||||||
COLOR=3066993
|
COLOR=3066993
|
||||||
TITLE="✅ Deployment ${ENVIRONMENT_NAME} Succeeded"
|
TITLE="✅ Deployment ${ENVIRONMENT_NAME} Succeeded"
|
||||||
DESC="Deployment job on branch \`${CI_COMMIT_REF_NAME}\` completed successfully."
|
DESC="Deployment job on branch \${CI_COMMIT_REF_NAME}\ completed successfully."
|
||||||
else
|
else
|
||||||
COLOR=15158332
|
COLOR=15158332
|
||||||
TITLE="❌ Deployment ${ENVIRONMENT_NAME} Failed"
|
TITLE="❌ Deployment ${ENVIRONMENT_NAME} Failed"
|
||||||
DESC="Deployment job on branch \`${CI_COMMIT_REF_NAME}\` encountered issues."
|
DESC="Deployment job on branch \${CI_COMMIT_REF_NAME}\ encountered issues."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
jq -n \
|
jq -n \
|
||||||
@@ -114,7 +128,9 @@ stages:
|
|||||||
|
|
||||||
curl -sS -H "Content-Type: application/json" -d @payload.json "$DISCORD_WEBHOOK_URL"
|
curl -sS -H "Content-Type: application/json" -d @payload.json "$DISCORD_WEBHOOK_URL"
|
||||||
|
|
||||||
# ====== DEVELOPMENT (Branch development) ======
|
# ==========================================================
|
||||||
|
# ==== DEVELOPMENT (Branch development) ======
|
||||||
|
# ==========================================================
|
||||||
build:dev:
|
build:dev:
|
||||||
<<: *build_template
|
<<: *build_template
|
||||||
rules:
|
rules:
|
||||||
@@ -140,7 +156,9 @@ deploy:dev:
|
|||||||
name: development
|
name: development
|
||||||
url: https://dev-lti-erp.mbugroup.id
|
url: https://dev-lti-erp.mbugroup.id
|
||||||
|
|
||||||
|
# ==========================================================
|
||||||
# ====== STAGING (Branch staging) ======
|
# ====== STAGING (Branch staging) ======
|
||||||
|
# ==========================================================
|
||||||
build:staging:
|
build:staging:
|
||||||
<<: *build_template
|
<<: *build_template
|
||||||
rules:
|
rules:
|
||||||
@@ -165,25 +183,3 @@ deploy:staging:
|
|||||||
environment:
|
environment:
|
||||||
name: staging
|
name: staging
|
||||||
url: https://stg-lti-erp.mbugroup.id
|
url: https://stg-lti-erp.mbugroup.id
|
||||||
# ====== PRODUCTION ======
|
|
||||||
# build:production:
|
|
||||||
# <<: *build_template
|
|
||||||
# rules:
|
|
||||||
# # pilih salah satu: pakai branch master ATAU pakai tags rilis
|
|
||||||
# - if: '$CI_COMMIT_BRANCH == "master"'
|
|
||||||
# # - if: '$CI_COMMIT_TAG' # kalau mau rilis via tag, uncomment ini dan hapus baris di atas
|
|
||||||
# environment:
|
|
||||||
# name: production
|
|
||||||
|
|
||||||
# deploy:production:
|
|
||||||
# <<: *deploy_template
|
|
||||||
# needs: ["build:production"]
|
|
||||||
# rules:
|
|
||||||
# - if: '$CI_COMMIT_BRANCH == "master"'
|
|
||||||
# # - if: '$CI_COMMIT_TAG' # selaras dengan rule di build:production
|
|
||||||
# variables:
|
|
||||||
# S3_BUCKET: "lti-erp.mbugroup.id"
|
|
||||||
# CLOUDFRONT_DISTRIBUTION_ID: "ddfd"
|
|
||||||
# environment:
|
|
||||||
# name: production
|
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,3 +1,3 @@
|
|||||||
npm run format
|
npm run format
|
||||||
npm run lint
|
npm run lint
|
||||||
npm run build
|
npx tsc --noEmit
|
||||||
Generated
+3211
-30
File diff suppressed because it is too large
Load Diff
+14
-2
@@ -15,22 +15,34 @@
|
|||||||
"@tanstack/match-sorter-utils": "^8.19.4",
|
"@tanstack/match-sorter-utils": "^8.19.4",
|
||||||
"@tanstack/react-table": "^8.21.3",
|
"@tanstack/react-table": "^8.21.3",
|
||||||
"axios": "^1.12.2",
|
"axios": "^1.12.2",
|
||||||
|
"class-variance-authority": "^0.7.1",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
|
"cmdk": "^1.1.1",
|
||||||
|
"embla-carousel-react": "^8.6.0",
|
||||||
"formik": "^2.4.6",
|
"formik": "^2.4.6",
|
||||||
|
"input-otp": "^1.4.2",
|
||||||
"jspdf": "^3.0.4",
|
"jspdf": "^3.0.4",
|
||||||
"jspdf-autotable": "^5.0.2",
|
"jspdf-autotable": "^5.0.2",
|
||||||
|
"lucide-react": "^0.562.0",
|
||||||
"moment": "^2.30.1",
|
"moment": "^2.30.1",
|
||||||
"next": "15.5.9",
|
"next": "15.5.9",
|
||||||
"react": "19.1.0",
|
"next-themes": "^0.4.6",
|
||||||
|
"radix-ui": "^1.4.3",
|
||||||
|
"react": "^19.1.2",
|
||||||
"react-day-picker": "^9.11.1",
|
"react-day-picker": "^9.11.1",
|
||||||
"react-dom": "19.1.0",
|
"react-dom": "^19.1.2",
|
||||||
"react-dropzone": "^14.3.8",
|
"react-dropzone": "^14.3.8",
|
||||||
|
"react-hook-form": "^7.70.0",
|
||||||
"react-hot-toast": "^2.6.0",
|
"react-hot-toast": "^2.6.0",
|
||||||
"react-number-format": "^5.4.4",
|
"react-number-format": "^5.4.4",
|
||||||
|
"react-resizable-panels": "2.1.7",
|
||||||
"react-select": "^5.10.2",
|
"react-select": "^5.10.2",
|
||||||
|
"recharts": "^3.6.0",
|
||||||
|
"sonner": "^2.0.7",
|
||||||
"swr": "^2.3.6",
|
"swr": "^2.3.6",
|
||||||
"tailwind-merge": "^3.3.1",
|
"tailwind-merge": "^3.3.1",
|
||||||
"use-debounce": "^10.0.6",
|
"use-debounce": "^10.0.6",
|
||||||
|
"vaul": "^1.1.2",
|
||||||
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz",
|
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz",
|
||||||
"yup": "^1.7.0",
|
"yup": "^1.7.0",
|
||||||
"zustand": "^5.0.8"
|
"zustand": "^5.0.8"
|
||||||
|
|||||||
@@ -7,18 +7,33 @@ import ClosingDetail from '@/components/pages/closing/ClosingDetail';
|
|||||||
|
|
||||||
import { ClosingApi } from '@/services/api/closing';
|
import { ClosingApi } from '@/services/api/closing';
|
||||||
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
||||||
|
import { FlockApi } from '@/services/api/master-data';
|
||||||
|
import { ProjectFlockApi } from '@/services/api/production/project-flock';
|
||||||
|
import { ProjectFlockKandangApi } from '@/services/api/production';
|
||||||
|
|
||||||
const ClosingDetailPage = () => {
|
const ClosingDetailPage = () => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
|
|
||||||
const closingId = searchParams.get('closingId');
|
const closingId = searchParams.get('closingId');
|
||||||
|
const kandangId = searchParams.get('kandangId'); // project flock kandang ID
|
||||||
|
|
||||||
const { data: closing, isLoading: isLoadingClosing } = useSWR(
|
const { data: closing, isLoading: isLoadingClosing } = useSWR(
|
||||||
closingId,
|
closingId,
|
||||||
(id: number) => ClosingApi.getGeneralInfo(id)
|
(id: number) => ClosingApi.getGeneralInfo(id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// WORKAROUND - get flock data from closing ID
|
||||||
|
const { data: projectData, isLoading: isLoadingProject } = useSWR(
|
||||||
|
`flock-${closingId}`,
|
||||||
|
() => ProjectFlockApi.getSingle(Number(closingId))
|
||||||
|
);
|
||||||
|
// WORKAROUND - get kandang data from closing ID
|
||||||
|
const { data: kandangData, isLoading: isLoadingKandang } = useSWR(
|
||||||
|
kandangId ? `kandang-${closingId}-${kandangId}` : null,
|
||||||
|
() => ProjectFlockKandangApi.getSingle(Number(kandangId))
|
||||||
|
);
|
||||||
|
|
||||||
const { data: salesData, isLoading: isLoadingSales } = useSWR(
|
const { data: salesData, isLoading: isLoadingSales } = useSWR(
|
||||||
closingId ? `sales-${closingId}` : null,
|
closingId ? `sales-${closingId}` : null,
|
||||||
() => ClosingApi.getPenjualan(Number(closingId))
|
() => ClosingApi.getPenjualan(Number(closingId))
|
||||||
@@ -44,7 +59,12 @@ const ClosingDetailPage = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isLoading = isLoadingClosing || isLoadingSales || isLoadingHppEkspedisi;
|
const isLoading =
|
||||||
|
isLoadingClosing ||
|
||||||
|
isLoadingSales ||
|
||||||
|
isLoadingHppEkspedisi ||
|
||||||
|
isLoadingProject ||
|
||||||
|
isLoadingKandang;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='w-full p-4 flex flex-row justify-center'>
|
<div className='w-full p-4 flex flex-row justify-center'>
|
||||||
@@ -60,6 +80,12 @@ const ClosingDetailPage = () => {
|
|||||||
? hppEkspedisiData.data
|
? hppEkspedisiData.data
|
||||||
: undefined
|
: undefined
|
||||||
}
|
}
|
||||||
|
projectData={
|
||||||
|
isResponseSuccess(projectData) ? projectData.data : undefined
|
||||||
|
}
|
||||||
|
kandangData={
|
||||||
|
isResponseSuccess(kandangData) ? kandangData.data : undefined
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { DailyChecklistContent } from '@/figma-make/components/pages/daily-checklist/DailyChecklistContent';
|
||||||
|
|
||||||
|
const DailyChecklistPage = () => {
|
||||||
|
return (
|
||||||
|
<section className='w-full'>
|
||||||
|
<DailyChecklistContent />
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DailyChecklistPage;
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { Dashboard as DashboardDailyChecklist } from '@/figma-make/components/pages/dashboard/Dashboard';
|
||||||
|
|
||||||
|
const DailyChecklistDashboardPage = () => {
|
||||||
|
return (
|
||||||
|
<section className='w-full'>
|
||||||
|
<DashboardDailyChecklist />
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DailyChecklistDashboardPage;
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { DetailDailyChecklistContent } from '@/figma-make/components/pages/list-daily-checklist/detail/DetailDailyChecklistContent';
|
||||||
|
|
||||||
|
const ListDailyChecklistDetailPage = () => {
|
||||||
|
return (
|
||||||
|
<section className='w-full'>
|
||||||
|
<DetailDailyChecklistContent />
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ListDailyChecklistDetailPage;
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { ListDailyChecklistContent } from '@/figma-make/components/pages/list-daily-checklist/ListDailyChecklistContent';
|
||||||
|
|
||||||
|
const ListDailyChecklistPage = () => {
|
||||||
|
return (
|
||||||
|
<section className='w-full'>
|
||||||
|
<ListDailyChecklistContent />
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ListDailyChecklistPage;
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { MasterAktivitasContent } from '@/figma-make/components/pages/master-data/activity/MasterAktivitasContent';
|
||||||
|
|
||||||
|
const MasterAktivitasPage = () => {
|
||||||
|
return (
|
||||||
|
<section className='w-full'>
|
||||||
|
<MasterAktivitasContent />
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default MasterAktivitasPage;
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { MasterConfigurationContent } from '@/figma-make/components/pages/master-data/configuration/MasterConfigurationContent';
|
||||||
|
|
||||||
|
const MasterConfigurationPage = () => {
|
||||||
|
return (
|
||||||
|
<section className='w-full'>
|
||||||
|
<MasterConfigurationContent />
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default MasterConfigurationPage;
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { MasterEmployeeContent } from '@/figma-make/components/pages/master-data/employee/MasterEmployeeContent';
|
||||||
|
|
||||||
|
const MasterEmployeePage = () => {
|
||||||
|
return (
|
||||||
|
<section className='w-full'>
|
||||||
|
<MasterEmployeeContent />
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default MasterEmployeePage;
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { DailyChecklistReportsContent } from '@/figma-make/components/pages/reports/DailyChecklistReportsContent';
|
||||||
|
|
||||||
|
const DailyChecklistReportsPage = () => {
|
||||||
|
return (
|
||||||
|
<section className='w-full'>
|
||||||
|
<DailyChecklistReportsContent />
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DailyChecklistReportsPage;
|
||||||
@@ -1,9 +1,7 @@
|
|||||||
|
import DashboardProduction from '@/components/pages/dashboard/DashboardProduction';
|
||||||
|
|
||||||
const Dashboard = () => {
|
const Dashboard = () => {
|
||||||
return (
|
return <DashboardProduction />;
|
||||||
<section className='w-full p-4'>
|
|
||||||
<h1 className='text-3xl font-bold text-primary'>Dashboard</h1>
|
|
||||||
</section>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Dashboard;
|
export default Dashboard;
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ const ExpenseRealization = () => {
|
|||||||
const isExpenseCanBeRealized =
|
const isExpenseCanBeRealized =
|
||||||
isResponseSuccess(expense) &&
|
isResponseSuccess(expense) &&
|
||||||
expense.data.latest_approval.action !== 'REJECTED' &&
|
expense.data.latest_approval.action !== 'REJECTED' &&
|
||||||
expense.data.latest_approval.step_number === 3;
|
expense.data.latest_approval.step_number === 4;
|
||||||
|
|
||||||
if (isResponseSuccess(expense) && !isExpenseCanBeRealized) {
|
if (isResponseSuccess(expense) && !isExpenseCanBeRealized) {
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
const FinanceAdjust = () => {
|
||||||
|
return <div>Finance Adjust</div>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default FinanceAdjust;
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import FormFinanceAddInitialBalance from '@/components/pages/finance/add/initial-balance/FormFinanceAddInitialBalance';
|
||||||
|
|
||||||
|
const FinanceAddInitialBalancePage = () => {
|
||||||
|
return <FormFinanceAddInitialBalance type='add' />;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default FinanceAddInitialBalancePage;
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import FormFinanceInjection from '@/components/pages/finance/add/injection/FormFinanceInjection';
|
||||||
|
|
||||||
|
const FinanceAddInjectionPage = () => {
|
||||||
|
return <FormFinanceInjection type='add' />;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default FinanceAddInjectionPage;
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import FormFinanceAdd from '@/components/pages/finance/add/FormFinanceAdd';
|
||||||
|
|
||||||
|
const FinanceAddPage = () => {
|
||||||
|
return <FormFinanceAdd />;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default FinanceAddPage;
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useRouter, useSearchParams } from 'next/navigation';
|
||||||
|
import useSWR from 'swr';
|
||||||
|
import { FinanceApi } from '@/services/api/finance';
|
||||||
|
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
||||||
|
import FormFinanceAddInitialBalance from '@/components/pages/finance/add/initial-balance/FormFinanceAddInitialBalance';
|
||||||
|
|
||||||
|
const EditFinanceInitialBalancePage = () => {
|
||||||
|
const router = useRouter();
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
|
||||||
|
const financeId = searchParams.get('financeId');
|
||||||
|
|
||||||
|
const { data: finance, isLoading: isLoadingFinance } = useSWR(
|
||||||
|
financeId,
|
||||||
|
(id: number) => FinanceApi.getSingle(id)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!financeId) {
|
||||||
|
router.back();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='w-full flex flex-row justify-center items-center p-4'>
|
||||||
|
<span className='loading loading-spinner loading-xl' />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isLoadingFinance && (!finance || isResponseError(finance))) {
|
||||||
|
router.replace('/404');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='w-full p-4 flex flex-row justify-center'>
|
||||||
|
{isLoadingFinance && (
|
||||||
|
<span className='loading loading-spinner loading-xl' />
|
||||||
|
)}
|
||||||
|
|
||||||
|
{!isLoadingFinance && (
|
||||||
|
<FormFinanceAddInitialBalance
|
||||||
|
type='edit'
|
||||||
|
initialValues={isResponseSuccess(finance) ? finance.data : undefined}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default EditFinanceInitialBalancePage;
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useRouter, useSearchParams } from 'next/navigation';
|
||||||
|
import useSWR from 'swr';
|
||||||
|
import { FinanceApi } from '@/services/api/finance';
|
||||||
|
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
||||||
|
import FormFinanceInjection from '@/components/pages/finance/add/injection/FormFinanceInjection';
|
||||||
|
|
||||||
|
const EditFinanceInjectionPage = () => {
|
||||||
|
const router = useRouter();
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
|
||||||
|
const financeId = searchParams.get('financeId');
|
||||||
|
|
||||||
|
const { data: finance, isLoading: isLoadingFinance } = useSWR(
|
||||||
|
financeId,
|
||||||
|
(id: number) => FinanceApi.getSingle(id)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!financeId) {
|
||||||
|
router.back();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='w-full flex flex-row justify-center items-center p-4'>
|
||||||
|
<span className='loading loading-spinner loading-xl' />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isLoadingFinance && (!finance || isResponseError(finance))) {
|
||||||
|
router.replace('/404');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='w-full p-4 flex flex-row justify-center'>
|
||||||
|
{isLoadingFinance && (
|
||||||
|
<span className='loading loading-spinner loading-xl' />
|
||||||
|
)}
|
||||||
|
|
||||||
|
{!isLoadingFinance && (
|
||||||
|
<FormFinanceInjection
|
||||||
|
type='edit'
|
||||||
|
initialValues={isResponseSuccess(finance) ? finance.data : undefined}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default EditFinanceInjectionPage;
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useRouter, useSearchParams } from 'next/navigation';
|
||||||
|
import useSWR from 'swr';
|
||||||
|
import { FinanceApi } from '@/services/api/finance';
|
||||||
|
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
||||||
|
import FormFinanceAdd from '@/components/pages/finance/add/FormFinanceAdd';
|
||||||
|
import FormFinanceAddInitialBalance from '@/components/pages/finance/add/initial-balance/FormFinanceAddInitialBalance';
|
||||||
|
|
||||||
|
const EditFinanceTransactionPage = () => {
|
||||||
|
const router = useRouter();
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
|
||||||
|
const financeId = searchParams.get('financeId');
|
||||||
|
|
||||||
|
const { data: finance, isLoading: isLoadingFinance } = useSWR(
|
||||||
|
financeId,
|
||||||
|
(id: number) => FinanceApi.getSingle(id)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!financeId) {
|
||||||
|
router.back();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='w-full flex flex-row justify-center items-center p-4'>
|
||||||
|
<span className='loading loading-spinner loading-xl' />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isLoadingFinance && (!finance || isResponseError(finance))) {
|
||||||
|
router.replace('/404');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='w-full p-4 flex flex-row justify-center'>
|
||||||
|
{isLoadingFinance && (
|
||||||
|
<span className='loading loading-spinner loading-xl' />
|
||||||
|
)}
|
||||||
|
|
||||||
|
{!isLoadingFinance && (
|
||||||
|
<FormFinanceAdd
|
||||||
|
type='edit'
|
||||||
|
initialValues={isResponseSuccess(finance) ? finance.data : undefined}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default EditFinanceTransactionPage;
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import SuspenseHelper from '@/components/helper/SuspenseHelper';
|
||||||
|
|
||||||
|
const Layout = ({
|
||||||
|
children,
|
||||||
|
}: Readonly<{
|
||||||
|
children: React.ReactNode;
|
||||||
|
}>) => {
|
||||||
|
return <SuspenseHelper>{children}</SuspenseHelper>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Layout;
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import FinanceDetail from '@/components/pages/finance/FinanceDetail';
|
||||||
|
import useSWR from 'swr';
|
||||||
|
import { useRouter, useSearchParams } from 'next/navigation';
|
||||||
|
import { FinanceApi } from '@/services/api/finance';
|
||||||
|
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
||||||
|
|
||||||
|
const FinanceDetailPage = () => {
|
||||||
|
const router = useRouter();
|
||||||
|
const financeId = useSearchParams().get('financeId');
|
||||||
|
|
||||||
|
const { data: finance } = useSWR(financeId, () =>
|
||||||
|
FinanceApi.getSingle(Number(financeId))
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!financeId) {
|
||||||
|
router.back();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='w-full flex flex-row justify-center items-center p-4'>
|
||||||
|
<span className='loading loading-spinner loading-xl' />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(finance);
|
||||||
|
|
||||||
|
// if (!finance || isResponseError(finance)) {
|
||||||
|
// router.replace('/404');
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{isResponseSuccess(finance) && <FinanceDetail finance={finance.data} />}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default FinanceDetailPage;
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import FinanceTable from '@/components/pages/finance/FinanceTable';
|
||||||
|
|
||||||
|
const Finance = () => {
|
||||||
|
return (
|
||||||
|
<section className='size-full p-6'>
|
||||||
|
<div className='flex flex-row gap-4'></div>
|
||||||
|
<FinanceTable />
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Finance;
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
@import 'tailwindcss';
|
@import 'tailwindcss';
|
||||||
@plugin "daisyui";
|
@plugin "daisyui";
|
||||||
@import '../styles/daisyui.css';
|
@import '../styles/daisyui.css';
|
||||||
|
@import '../figma-make/styles/theme.css';
|
||||||
|
|
||||||
@plugin "daisyui/theme" {
|
@plugin "daisyui/theme" {
|
||||||
name: 'lti';
|
name: 'lti';
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { Inter } from 'next/font/google';
|
|||||||
import '@/app/globals.css';
|
import '@/app/globals.css';
|
||||||
|
|
||||||
import { Toaster } from 'react-hot-toast';
|
import { Toaster } from 'react-hot-toast';
|
||||||
|
import { Toaster as SonnerToaster } from '@/figma-make/components/base/sonner';
|
||||||
import MainDrawer from '@/components/MainDrawer';
|
import MainDrawer from '@/components/MainDrawer';
|
||||||
import RequireAuth from '@/components/helper/RequireAuth';
|
import RequireAuth from '@/components/helper/RequireAuth';
|
||||||
|
|
||||||
@@ -35,6 +36,7 @@ export default function RootLayout({
|
|||||||
</RequireAuth>
|
</RequireAuth>
|
||||||
|
|
||||||
<Toaster />
|
<Toaster />
|
||||||
|
<SonnerToaster position='top-right' />
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import ProductionStandardForm from '@/components/pages/master-data/production-standard/form/ProductionStandardForm';
|
||||||
|
|
||||||
|
const AddProductionStandardPage = () => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<ProductionStandardForm formType='add' />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default AddProductionStandardPage;
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import ProductionStandardForm from '@/components/pages/master-data/production-standard/form/ProductionStandardForm';
|
||||||
|
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
||||||
|
import { ProductionStandardApi } from '@/services/api/master-data';
|
||||||
|
import { useRouter, useSearchParams } from 'next/navigation';
|
||||||
|
import useSWR from 'swr';
|
||||||
|
|
||||||
|
const EditProductionStandardPage = () => {
|
||||||
|
const router = useRouter();
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
|
||||||
|
// Get Query Params
|
||||||
|
const productionStandardId = searchParams.get('productionStandardId');
|
||||||
|
|
||||||
|
// Fetch Data
|
||||||
|
const { data: productionStandard, isLoading: isLoadingProductionStandard } =
|
||||||
|
useSWR(productionStandardId, (id: number) =>
|
||||||
|
ProductionStandardApi.getSingle(id)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!productionStandardId) {
|
||||||
|
router.back();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='w-full flex flex-row justify-center items-center p-4'>
|
||||||
|
<span className='loading loading-spinner loading-xl' />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
!isLoadingProductionStandard &&
|
||||||
|
(!productionStandard || isResponseError(productionStandard))
|
||||||
|
) {
|
||||||
|
router.replace('/404');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{isLoadingProductionStandard && (
|
||||||
|
<span className='loading loading-spinner loading-xl' />
|
||||||
|
)}
|
||||||
|
{!isLoadingProductionStandard &&
|
||||||
|
isResponseSuccess(productionStandard) && (
|
||||||
|
<ProductionStandardForm
|
||||||
|
formType='edit'
|
||||||
|
initialValue={productionStandard.data}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default EditProductionStandardPage;
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import SuspenseHelper from '@/components/helper/SuspenseHelper';
|
||||||
|
|
||||||
|
const Layout = ({
|
||||||
|
children,
|
||||||
|
}: Readonly<{
|
||||||
|
children: React.ReactNode;
|
||||||
|
}>) => {
|
||||||
|
return <SuspenseHelper>{children}</SuspenseHelper>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Layout;
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import ProductionStandardForm from '@/components/pages/master-data/production-standard/form/ProductionStandardForm';
|
||||||
|
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
||||||
|
import { ProductionStandardApi } from '@/services/api/master-data';
|
||||||
|
import { useRouter, useSearchParams } from 'next/navigation';
|
||||||
|
import useSWR from 'swr';
|
||||||
|
|
||||||
|
const DetailProductionStandardPage = () => {
|
||||||
|
const router = useRouter();
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
|
||||||
|
// Get Query Params
|
||||||
|
const productionStandardId = searchParams.get('productionStandardId');
|
||||||
|
|
||||||
|
// Fetch Data
|
||||||
|
const { data: productionStandard, isLoading: isLoadingProductionStandard } =
|
||||||
|
useSWR(productionStandardId, (id: number) =>
|
||||||
|
ProductionStandardApi.getSingle(id)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!productionStandardId) {
|
||||||
|
router.back();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='w-full flex flex-row justify-center items-center p-4'>
|
||||||
|
<span className='loading loading-spinner loading-xl' />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
!isLoadingProductionStandard &&
|
||||||
|
(!productionStandard || isResponseError(productionStandard))
|
||||||
|
) {
|
||||||
|
router.replace('/404');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{isLoadingProductionStandard && (
|
||||||
|
<span className='loading loading-spinner loading-xl' />
|
||||||
|
)}
|
||||||
|
{!isLoadingProductionStandard &&
|
||||||
|
isResponseSuccess(productionStandard) && (
|
||||||
|
<ProductionStandardForm
|
||||||
|
formType='detail'
|
||||||
|
initialValue={productionStandard.data}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DetailProductionStandardPage;
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import ProductionStandardTable from '@/components/pages/master-data/production-standard/ProductionStandardTable';
|
||||||
|
|
||||||
|
const ProductionStandardPage = () => {
|
||||||
|
return (
|
||||||
|
<div className='w-full'>
|
||||||
|
<ProductionStandardTable />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ProductionStandardPage;
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { FormHeader } from '@/components/helper/form/FormHeader';
|
|
||||||
import ProjectFlockChickinDetail from '@/components/pages/production/project-flock/chickin/ProjectFlockChickinDetail';
|
|
||||||
import { useSearchParams } from 'next/navigation';
|
|
||||||
|
|
||||||
const AddChickin = () => {
|
|
||||||
const searchParams = useSearchParams();
|
|
||||||
const projectFlockId = searchParams.get('projectFlockId');
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<section className='w-full'>
|
|
||||||
<ProjectFlockChickinDetail projectFlockId={Number(projectFlockId)} />
|
|
||||||
</section>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default AddChickin;
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
import ChickinTable from '@/components/pages/production/chickin/ChickinTable';
|
|
||||||
|
|
||||||
const Chickin = () => {
|
|
||||||
return (
|
|
||||||
<section className='w-full'>
|
|
||||||
<ChickinTable />
|
|
||||||
</section>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
export default Chickin;
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import UniformityForm from '@/components/pages/production/uniformity/form/UniformityForm';
|
||||||
|
|
||||||
|
const AddUniformity = () => {
|
||||||
|
return <UniformityForm formType='add' />;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default AddUniformity;
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import UniformityDetail from '@/components/pages/production/uniformity/detail/UniformityDetail';
|
||||||
|
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
||||||
|
import { UniformityApi } from '@/services/api/uniformity';
|
||||||
|
import { useRouter, useSearchParams } from 'next/navigation';
|
||||||
|
import useSWR from 'swr';
|
||||||
|
|
||||||
|
const UniformityDetailPage = () => {
|
||||||
|
const router = useRouter();
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
|
||||||
|
const uniformityId = searchParams.get('uniformityId');
|
||||||
|
|
||||||
|
const { data: uniformity, isLoading: isLoadingUniformity } = useSWR(
|
||||||
|
uniformityId,
|
||||||
|
(id: string) => UniformityApi.getUniformityDetail(parseInt(id))
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!uniformityId) {
|
||||||
|
router.back();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='w-full flex flex-row justify-center items-center p-4'>
|
||||||
|
<span className='loading loading-spinner loading-xl' />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isLoadingUniformity && (!uniformity || isResponseError(uniformity))) {
|
||||||
|
router.replace('/404');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='w-full h-full flex flex-col justify-center'>
|
||||||
|
{isLoadingUniformity && (
|
||||||
|
<div className='w-full flex flex-row justify-center items-center p-4 min-h-screen'>
|
||||||
|
<span className='loading loading-spinner loading-xl' />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{isResponseSuccess(uniformity) && (
|
||||||
|
<UniformityDetail initialValues={uniformity.data} />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default UniformityDetailPage;
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { ReactNode } from 'react';
|
||||||
|
import UniformityPageWrapper from '@/components/pages/production/uniformity/UniformityPageWrapper';
|
||||||
|
|
||||||
|
export default function UniformityLayout({
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
children: ReactNode;
|
||||||
|
}) {
|
||||||
|
return <UniformityPageWrapper>{children}</UniformityPageWrapper>;
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import UniformityTable from '@/components/pages/production/uniformity/UniformityTable';
|
||||||
|
|
||||||
|
const Uniformity = () => {
|
||||||
|
return <UniformityTable />;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Uniformity;
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import FinanceTabs from '@/components/pages/report/finance/FinanceTabs';
|
||||||
|
|
||||||
|
const Finance = () => {
|
||||||
|
return <FinanceTabs />;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Finance;
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import ProductionResultContent from '@/components/pages/report/production-result/ProductionResultContent';
|
||||||
|
|
||||||
|
const ProductionResultReportPage = () => {
|
||||||
|
return (
|
||||||
|
<section className='w-full max-w-7xl pb-16'>
|
||||||
|
<ProductionResultContent />
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ProductionResultReportPage;
|
||||||
+34
-14
@@ -3,29 +3,25 @@
|
|||||||
import { HTMLAttributes, ReactNode } from 'react';
|
import { HTMLAttributes, ReactNode } from 'react';
|
||||||
|
|
||||||
import { cn } from '@/lib/helper';
|
import { cn } from '@/lib/helper';
|
||||||
|
import type { Color, Variant, Size } from '@/types/theme';
|
||||||
|
|
||||||
export interface BadgeProps
|
export interface BadgeProps
|
||||||
extends Omit<HTMLAttributes<HTMLSpanElement>, 'className'> {
|
extends Omit<HTMLAttributes<HTMLSpanElement>, 'className'> {
|
||||||
children?: ReactNode;
|
children?: ReactNode;
|
||||||
className?: {
|
className?: {
|
||||||
badge?: string;
|
badge?: string;
|
||||||
|
status?: string;
|
||||||
};
|
};
|
||||||
variant?: 'default' | 'outline' | 'ghost' | 'soft' | 'dash';
|
statusIndicator?: boolean;
|
||||||
color?:
|
variant?: Variant;
|
||||||
| 'neutral'
|
color?: Color;
|
||||||
| 'primary'
|
size?: Size;
|
||||||
| 'secondary'
|
|
||||||
| 'accent'
|
|
||||||
| 'info'
|
|
||||||
| 'success'
|
|
||||||
| 'warning'
|
|
||||||
| 'error';
|
|
||||||
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Badge = ({
|
const Badge = ({
|
||||||
children,
|
children,
|
||||||
className,
|
className,
|
||||||
|
statusIndicator = false,
|
||||||
variant = 'default',
|
variant = 'default',
|
||||||
color,
|
color,
|
||||||
size = 'md',
|
size = 'md',
|
||||||
@@ -34,7 +30,7 @@ const Badge = ({
|
|||||||
const getBadgeClasses = () => {
|
const getBadgeClasses = () => {
|
||||||
const baseClasses = 'badge';
|
const baseClasses = 'badge';
|
||||||
|
|
||||||
const variantClasses = {
|
const variantClasses: Record<Variant, string> = {
|
||||||
default: '',
|
default: '',
|
||||||
outline: 'badge-outline',
|
outline: 'badge-outline',
|
||||||
ghost: 'badge-ghost',
|
ghost: 'badge-ghost',
|
||||||
@@ -42,7 +38,7 @@ const Badge = ({
|
|||||||
dash: 'badge-dash',
|
dash: 'badge-dash',
|
||||||
};
|
};
|
||||||
|
|
||||||
const colorClasses = {
|
const colorClasses: Record<Color, string> = {
|
||||||
neutral: 'badge-neutral',
|
neutral: 'badge-neutral',
|
||||||
primary: 'badge-primary',
|
primary: 'badge-primary',
|
||||||
secondary: 'badge-secondary',
|
secondary: 'badge-secondary',
|
||||||
@@ -51,9 +47,10 @@ const Badge = ({
|
|||||||
success: 'badge-success',
|
success: 'badge-success',
|
||||||
warning: 'badge-warning',
|
warning: 'badge-warning',
|
||||||
error: 'badge-error',
|
error: 'badge-error',
|
||||||
|
none: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
const sizeClasses = {
|
const sizeClasses: Record<Size, string> = {
|
||||||
xs: 'badge-xs',
|
xs: 'badge-xs',
|
||||||
sm: 'badge-sm',
|
sm: 'badge-sm',
|
||||||
md: 'badge-md',
|
md: 'badge-md',
|
||||||
@@ -70,8 +67,31 @@ const Badge = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getStatusClasses = () => {
|
||||||
|
if (!statusIndicator) return '';
|
||||||
|
|
||||||
|
const statusIndicatorClasses: Record<Color, string> = {
|
||||||
|
neutral: 'bg-neutral',
|
||||||
|
primary: 'bg-primary',
|
||||||
|
secondary: 'bg-secondary',
|
||||||
|
accent: 'bg-accent',
|
||||||
|
info: 'bg-info',
|
||||||
|
success: 'bg-success',
|
||||||
|
warning: 'bg-warning',
|
||||||
|
error: 'bg-error',
|
||||||
|
none: '',
|
||||||
|
};
|
||||||
|
|
||||||
|
return cn(
|
||||||
|
'w-2.5 h-2.5 rounded-full',
|
||||||
|
color && statusIndicatorClasses[color],
|
||||||
|
className?.status
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span className={getBadgeClasses()} {...props}>
|
<span className={getBadgeClasses()} {...props}>
|
||||||
|
{statusIndicator && <span className={getStatusClasses()} />}
|
||||||
{children}
|
{children}
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ interface DrawerProps {
|
|||||||
className?: DrawerClassName;
|
className?: DrawerClassName;
|
||||||
onBackdropClick?: () => void;
|
onBackdropClick?: () => void;
|
||||||
closeOnBackdropClick?: boolean;
|
closeOnBackdropClick?: boolean;
|
||||||
|
expandedContent?: ReactNode;
|
||||||
|
expandedWidth?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
type DrawerClassName = {
|
type DrawerClassName = {
|
||||||
@@ -36,6 +38,8 @@ const Drawer = ({
|
|||||||
className,
|
className,
|
||||||
onBackdropClick,
|
onBackdropClick,
|
||||||
closeOnBackdropClick = true,
|
closeOnBackdropClick = true,
|
||||||
|
expandedContent,
|
||||||
|
expandedWidth = 'w-[400px]',
|
||||||
}: DrawerProps) => {
|
}: DrawerProps) => {
|
||||||
const getDrawerClassNames = (): DrawerClassName => {
|
const getDrawerClassNames = (): DrawerClassName => {
|
||||||
const baseClassNames = {
|
const baseClassNames = {
|
||||||
@@ -46,12 +50,21 @@ const Drawer = ({
|
|||||||
drawerSidebarContent: 'min-h-full bg-base-100',
|
drawerSidebarContent: 'min-h-full bg-base-100',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getSidebarWidth = () => {
|
||||||
|
if (variant === 'sidebar') {
|
||||||
|
return expandedContent
|
||||||
|
? 'w-full lg:min-w-[600px] lg:max-w-[600px]'
|
||||||
|
: 'w-full max-w-[300px] lg:w-[300px]';
|
||||||
|
}
|
||||||
|
return 'w-full sm:min-w-120 sm:w-fit';
|
||||||
|
};
|
||||||
|
|
||||||
if (variant === 'sidebar') {
|
if (variant === 'sidebar') {
|
||||||
return {
|
return {
|
||||||
...baseClassNames,
|
...baseClassNames,
|
||||||
drawerSidebarContent: cn(
|
drawerSidebarContent: cn(
|
||||||
baseClassNames.drawerSidebarContent,
|
baseClassNames.drawerSidebarContent,
|
||||||
'w-full max-w-[300px] lg:w-[300px]'
|
getSidebarWidth()
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
} else if (variant === 'right') {
|
} else if (variant === 'right') {
|
||||||
@@ -60,11 +73,11 @@ const Drawer = ({
|
|||||||
drawer: cn(baseClassNames.drawer, 'drawer-end'),
|
drawer: cn(baseClassNames.drawer, 'drawer-end'),
|
||||||
drawerSide: cn(
|
drawerSide: cn(
|
||||||
baseClassNames.drawerSide,
|
baseClassNames.drawerSide,
|
||||||
'border-l border-solid border-gray-200 drawer-side w-screen top-0 right-0 fixed z-21'
|
'border-l border-solid border-gray-200 sm:drawer-side w-screen top-0 right-0 fixed z-21'
|
||||||
),
|
),
|
||||||
drawerSidebarContent: cn(
|
drawerSidebarContent: cn(
|
||||||
baseClassNames.drawerSidebarContent,
|
baseClassNames.drawerSidebarContent,
|
||||||
'w-full min-w-120 sm:w-fit'
|
getSidebarWidth()
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
} else if (variant === 'left') {
|
} else if (variant === 'left') {
|
||||||
@@ -76,7 +89,7 @@ const Drawer = ({
|
|||||||
),
|
),
|
||||||
drawerSidebarContent: cn(
|
drawerSidebarContent: cn(
|
||||||
baseClassNames.drawerSidebarContent,
|
baseClassNames.drawerSidebarContent,
|
||||||
'w-full min-w-120 sm:w-fit'
|
getSidebarWidth()
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -138,14 +151,37 @@ const Drawer = ({
|
|||||||
onClick={closeDrawer}
|
onClick={closeDrawer}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* Sidebar Content */}
|
{/* Sidebar Content - Full height container */}
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
varianClassName?.drawerSidebarContent,
|
'flex h-screen bg-base-100 overflow-hidden',
|
||||||
className?.drawerContent
|
variant === 'right' && 'flex-row'
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{sidebarContent}
|
{/* Primary Sidebar Content */}
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
varianClassName?.drawerSidebarContent,
|
||||||
|
className?.drawerContent,
|
||||||
|
'overflow-y-auto'
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{sidebarContent}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Expanded Drawer (Right side, side-by-side) */}
|
||||||
|
{expandedContent && (
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
'border-l border-gray-200 bg-white flex flex-col h-full',
|
||||||
|
expandedWidth
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<div className='overflow-y-auto flex-1 h-full'>
|
||||||
|
{expandedContent}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import Tooltip from '@/components/Tooltip';
|
|||||||
import { cn } from '@/lib/helper';
|
import { cn } from '@/lib/helper';
|
||||||
import { Icon } from '@iconify/react';
|
import { Icon } from '@iconify/react';
|
||||||
|
|
||||||
|
import { useAuth } from '@/services/hooks/useAuth';
|
||||||
|
|
||||||
type FloatingActionsButtonProps = {
|
type FloatingActionsButtonProps = {
|
||||||
actions: {
|
actions: {
|
||||||
action: 'DETAIL' | 'EDIT' | 'DELETE';
|
action: 'DETAIL' | 'EDIT' | 'DELETE';
|
||||||
@@ -13,6 +15,7 @@ type FloatingActionsButtonProps = {
|
|||||||
onClick?: () => void;
|
onClick?: () => void;
|
||||||
hidden?: boolean;
|
hidden?: boolean;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
|
permissions?: string | string[];
|
||||||
}[];
|
}[];
|
||||||
approvals: {
|
approvals: {
|
||||||
action: 'APPROVED' | 'REJECTED';
|
action: 'APPROVED' | 'REJECTED';
|
||||||
@@ -20,6 +23,7 @@ type FloatingActionsButtonProps = {
|
|||||||
label?: string;
|
label?: string;
|
||||||
onClick?: () => void;
|
onClick?: () => void;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
|
permissions?: string | string[];
|
||||||
}[];
|
}[];
|
||||||
selectedRowIds: number[];
|
selectedRowIds: number[];
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
@@ -31,11 +35,12 @@ const FloatingActionsButton = ({
|
|||||||
selectedRowIds,
|
selectedRowIds,
|
||||||
onClose,
|
onClose,
|
||||||
}: FloatingActionsButtonProps) => {
|
}: FloatingActionsButtonProps) => {
|
||||||
|
const { permissionCheck } = useAuth();
|
||||||
// Jika tidak ada baris yang dipilih, jangan tampilkan FAB
|
// Jika tidak ada baris yang dipilih, jangan tampilkan FAB
|
||||||
const positionStyles =
|
const positionStyles =
|
||||||
selectedRowIds.length > 0
|
selectedRowIds.length > 0
|
||||||
? 'bottom-[10%] opacity-100'
|
? 'bottom-[5%] opacity-100'
|
||||||
: 'bottom-[-10%] opacity-0';
|
: 'bottom-[-5%] opacity-0';
|
||||||
|
|
||||||
// Helper untuk menentukan gaya warna tombol approval
|
// Helper untuk menentukan gaya warna tombol approval
|
||||||
const getApprovalColor = (action: 'APPROVED' | 'REJECTED') => {
|
const getApprovalColor = (action: 'APPROVED' | 'REJECTED') => {
|
||||||
@@ -55,7 +60,7 @@ const FloatingActionsButton = ({
|
|||||||
// Container utama FAB
|
// Container utama FAB
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
`absolute ${positionStyles} inset-x-1/2 -translate-x-1/2 z-50`,
|
`fixed ${positionStyles} inset-x-1/2 -translate-x-1/2 z-50`,
|
||||||
'mx-auto w-full max-w-sm sm:mx-0 bg-base-300 p-4 rounded-xl shadow-md transition-all duration-300 transform',
|
'mx-auto w-full max-w-sm sm:mx-0 bg-base-300 p-4 rounded-xl shadow-md transition-all duration-300 transform',
|
||||||
'bg-slate-950 backdrop-blur-md'
|
'bg-slate-950 backdrop-blur-md'
|
||||||
)}
|
)}
|
||||||
@@ -71,7 +76,18 @@ const FloatingActionsButton = ({
|
|||||||
<div className='flex gap-4 items-center'>
|
<div className='flex gap-4 items-center'>
|
||||||
{/* Render Aksi dari props.actions */}
|
{/* Render Aksi dari props.actions */}
|
||||||
{actions
|
{actions
|
||||||
.filter((action) => !action.hidden)
|
.filter((action) => {
|
||||||
|
if (action.hidden) return false;
|
||||||
|
if (action.permissions) {
|
||||||
|
if (typeof action.permissions === 'string') {
|
||||||
|
return permissionCheck(action.permissions);
|
||||||
|
}
|
||||||
|
return action.permissions.some((permission) =>
|
||||||
|
permissionCheck(permission)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
})
|
||||||
.map((action, index) => {
|
.map((action, index) => {
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
@@ -111,29 +127,41 @@ const FloatingActionsButton = ({
|
|||||||
|
|
||||||
{/* === BARIS BAWAH: Approval Buttons (Approve/Reject) === */}
|
{/* === BARIS BAWAH: Approval Buttons (Approve/Reject) === */}
|
||||||
<div className={`grid grid-cols-${approvals.length} gap-3`}>
|
<div className={`grid grid-cols-${approvals.length} gap-3`}>
|
||||||
{approvals.map((approval, index) => (
|
{approvals
|
||||||
<Button
|
.filter((approval) => {
|
||||||
key={index}
|
if (approval.permissions) {
|
||||||
onClick={approval.onClick}
|
if (typeof approval.permissions === 'string') {
|
||||||
className={cn(
|
return permissionCheck(approval.permissions);
|
||||||
'btn btn-lg w-full',
|
}
|
||||||
'bg-white/20 border-white/30',
|
return approval.permissions.some((permission) =>
|
||||||
'text-white/50 font-semibold flex items-center gap-2 rounded-lg transition-all duration-200',
|
permissionCheck(permission)
|
||||||
approval.disabled
|
);
|
||||||
? 'cursor-not-allowed'
|
}
|
||||||
: 'hover:text-white/100 hover:bg-white/40 hover:border-white/50'
|
return true;
|
||||||
)}
|
})
|
||||||
disabled={approval.disabled}
|
.map((approval, index) => (
|
||||||
>
|
<Button
|
||||||
<Icon
|
key={index}
|
||||||
icon={approval.icon}
|
onClick={approval.onClick}
|
||||||
width={20}
|
className={cn(
|
||||||
height={20}
|
'btn btn-lg w-full',
|
||||||
className={`text-${getApprovalColor(approval.action)}`}
|
'bg-white/20 border-white/30',
|
||||||
/>
|
'text-white/50 font-semibold flex items-center gap-2 rounded-lg transition-all duration-200',
|
||||||
{approval.label || approval.action}
|
approval.disabled
|
||||||
</Button>
|
? 'cursor-not-allowed'
|
||||||
))}
|
: 'hover:text-white/100 hover:bg-white/40 hover:border-white/50'
|
||||||
|
)}
|
||||||
|
disabled={approval.disabled}
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
icon={approval.icon}
|
||||||
|
width={20}
|
||||||
|
height={20}
|
||||||
|
className={`text-${getApprovalColor(approval.action)}`}
|
||||||
|
/>
|
||||||
|
{approval.label || approval.action}
|
||||||
|
</Button>
|
||||||
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -9,10 +9,13 @@ import Drawer from '@/components/Drawer';
|
|||||||
import Navbar from '@/components/Navbar';
|
import Navbar from '@/components/Navbar';
|
||||||
import Button from '@/components/Button';
|
import Button from '@/components/Button';
|
||||||
import SidebarMenu from '@/components/molecules/SidebarMenu';
|
import SidebarMenu from '@/components/molecules/SidebarMenu';
|
||||||
|
import PermissionNotFound from '@/components/helper/PermissionNotFound';
|
||||||
|
|
||||||
import { useUiStore } from '@/stores/ui/ui.store';
|
import { useUiStore } from '@/stores/ui/ui.store';
|
||||||
import { MAIN_DRAWER_LINKS } from '@/config/constant';
|
import { MAIN_DRAWER_LINKS } from '@/config/constant';
|
||||||
import { isPathActive } from '@/lib/helper';
|
import { isPathActive } from '@/lib/helper';
|
||||||
|
import { ROUTE_PERMISSIONS } from '@/config/route-permission';
|
||||||
|
import { useAuth } from '@/services/hooks/useAuth';
|
||||||
|
|
||||||
const MainDrawerContent = () => {
|
const MainDrawerContent = () => {
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
@@ -62,6 +65,13 @@ const MainDrawer = ({
|
|||||||
}>) => {
|
}>) => {
|
||||||
const { mainDrawerOpen, setMainDrawerOpen } = useUiStore();
|
const { mainDrawerOpen, setMainDrawerOpen } = useUiStore();
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
|
const { permissionCheck } = useAuth();
|
||||||
|
|
||||||
|
const formattedPathname = pathname.endsWith('/') ? pathname : `${pathname}/`;
|
||||||
|
|
||||||
|
const isPermitted = ROUTE_PERMISSIONS[formattedPathname]?.some((permission) =>
|
||||||
|
permissionCheck(permission)
|
||||||
|
);
|
||||||
|
|
||||||
const getPageTitle = useCallback(() => {
|
const getPageTitle = useCallback(() => {
|
||||||
let title = '';
|
let title = '';
|
||||||
@@ -101,6 +111,10 @@ const MainDrawer = ({
|
|||||||
setMainDrawerOpen(!mainDrawerOpen);
|
setMainDrawerOpen(!mainDrawerOpen);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (!isPermitted) {
|
||||||
|
return <PermissionNotFound />;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Drawer
|
<Drawer
|
||||||
open={mainDrawerOpen}
|
open={mainDrawerOpen}
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
const PermissionNotFound = () => {
|
||||||
|
return (
|
||||||
|
<div className='w-full h-screen flex flex-col justify-center items-center gap-4'>
|
||||||
|
<h2 className='text-2xl font-bold text-error'>Permission Not Found</h2>
|
||||||
|
<p className='text-gray-600 text-center'>
|
||||||
|
You do not have permission to access this page.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PermissionNotFound;
|
||||||
@@ -5,6 +5,7 @@ import useSWR from 'swr';
|
|||||||
|
|
||||||
import { useAuth } from '@/services/hooks/useAuth';
|
import { useAuth } from '@/services/hooks/useAuth';
|
||||||
import { httpClientFetcher, SWRHttpKey } from '@/services/http/client';
|
import { httpClientFetcher, SWRHttpKey } from '@/services/http/client';
|
||||||
|
import { AuthApi } from '@/services/api/auth';
|
||||||
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
||||||
import { BaseApiResponse, GetMeResponse } from '@/types/api/api-general';
|
import { BaseApiResponse, GetMeResponse } from '@/types/api/api-general';
|
||||||
import { AxiosError } from 'axios';
|
import { AxiosError } from 'axios';
|
||||||
@@ -28,8 +29,8 @@ const RequireAuth = ({ children }: RequireAuthProps) => {
|
|||||||
>('/sso/userinfo', httpClientFetcher, {
|
>('/sso/userinfo', httpClientFetcher, {
|
||||||
shouldRetryOnError: false,
|
shouldRetryOnError: false,
|
||||||
|
|
||||||
// refresh every 13 minutes
|
// refresh every 12 minutes
|
||||||
refreshInterval: 13 * 60 * 1000,
|
refreshInterval: 12 * 60 * 1000,
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -55,6 +56,25 @@ const RequireAuth = ({ children }: RequireAuthProps) => {
|
|||||||
setIsLoadingUser(isLoadingUserResponse);
|
setIsLoadingUser(isLoadingUserResponse);
|
||||||
}, [isLoadingUserResponse]);
|
}, [isLoadingUserResponse]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const interval = setInterval(
|
||||||
|
async () => {
|
||||||
|
await AuthApi.refresh();
|
||||||
|
},
|
||||||
|
12 * 60 * 1000
|
||||||
|
);
|
||||||
|
|
||||||
|
return () => clearInterval(interval);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const refreshUserSession = async () => {
|
||||||
|
await AuthApi.refresh();
|
||||||
|
};
|
||||||
|
|
||||||
|
refreshUserSession();
|
||||||
|
}, []);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(isLoadingUserResponse && !userResponse && !userErrorResponse) ||
|
(isLoadingUserResponse && !userResponse && !userErrorResponse) ||
|
||||||
(!userResponse && !userErrorResponse)
|
(!userResponse && !userErrorResponse)
|
||||||
@@ -66,7 +86,7 @@ const RequireAuth = ({ children }: RequireAuthProps) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userErrorResponse) {
|
if (!isLoadingUserResponse && userErrorResponse) {
|
||||||
return (
|
return (
|
||||||
<div className='w-full h-screen flex flex-col justify-center items-center gap-4'>
|
<div className='w-full h-screen flex flex-col justify-center items-center gap-4'>
|
||||||
<h2 className='text-2xl font-bold text-error'>Authentication Failed</h2>
|
<h2 className='text-2xl font-bold text-error'>Authentication Failed</h2>
|
||||||
@@ -74,10 +94,7 @@ const RequireAuth = ({ children }: RequireAuthProps) => {
|
|||||||
Please try refreshing the page or contact support if the problem
|
Please try refreshing the page or contact support if the problem
|
||||||
persists.
|
persists.
|
||||||
</p>
|
</p>
|
||||||
<button
|
<button className='btn btn-primary' onClick={() => redirectToSSO()}>
|
||||||
className='btn btn-primary'
|
|
||||||
onClick={() => window.location.reload()}
|
|
||||||
>
|
|
||||||
Retry
|
Retry
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useAuth } from '@/services/hooks/useAuth';
|
||||||
|
|
||||||
|
interface RequirePermissionProps {
|
||||||
|
children: React.ReactNode;
|
||||||
|
permissions: string | string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
const RequirePermission = ({
|
||||||
|
children,
|
||||||
|
permissions,
|
||||||
|
}: RequirePermissionProps) => {
|
||||||
|
const { permissionCheck } = useAuth();
|
||||||
|
|
||||||
|
const isPermitted =
|
||||||
|
typeof permissions === 'string'
|
||||||
|
? permissionCheck(permissions)
|
||||||
|
: permissions.some((permission) => permissionCheck(permission));
|
||||||
|
|
||||||
|
if (!isPermitted) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return <>{children}</>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default RequirePermission;
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
import Alert from '@/components/Alert';
|
||||||
|
import Button from '@/components/Button';
|
||||||
|
import { Icon } from '@iconify/react';
|
||||||
|
import { useState } from 'react';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alert Unique Error List
|
||||||
|
* @param formErrorList - Array of error messages
|
||||||
|
* @param onClose - Function to close the alert
|
||||||
|
*/
|
||||||
|
const AlertErrorList = ({
|
||||||
|
formErrorList,
|
||||||
|
onClose,
|
||||||
|
}: {
|
||||||
|
formErrorList: string[];
|
||||||
|
onClose: () => void;
|
||||||
|
}) => {
|
||||||
|
if (formErrorList.length === 0) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Alert color='error' className='w-full flex flex-col gap-2 px-4 m-4'>
|
||||||
|
<div className='flex justify-between items-center gap-2 w-full'>
|
||||||
|
<div className='flex items-center gap-2'>
|
||||||
|
<Icon icon='material-symbols:error-outline' width={24} height={24} />
|
||||||
|
<span className='font-semibold'>
|
||||||
|
Terdapat {formErrorList.length} error pada form:
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
onClick={onClose}
|
||||||
|
variant='link'
|
||||||
|
className='ml-auto p-0 w-fit text-white'
|
||||||
|
color='none'
|
||||||
|
>
|
||||||
|
<Icon icon='material-symbols:close' width={24} height={24} />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<ul className='list-disc list-inside pl-8 space-y-1 w-full'>
|
||||||
|
{formErrorList.map((error, index) => (
|
||||||
|
<li key={index} className='text-sm'>
|
||||||
|
{error}
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</Alert>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default AlertErrorList;
|
||||||
@@ -33,6 +33,7 @@ const FileInput = ({
|
|||||||
isError,
|
isError,
|
||||||
errorMessage,
|
errorMessage,
|
||||||
disabled = false,
|
disabled = false,
|
||||||
|
required = false,
|
||||||
onChange,
|
onChange,
|
||||||
onBlur,
|
onBlur,
|
||||||
readOnly = false,
|
readOnly = false,
|
||||||
@@ -56,6 +57,13 @@ const FileInput = ({
|
|||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{label}
|
{label}
|
||||||
|
{required && (
|
||||||
|
<>
|
||||||
|
<span className='tooltip tooltip-error' data-tip='required'>
|
||||||
|
<span className='text-error'> *</span>
|
||||||
|
</span>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</label>
|
</label>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
@@ -8,10 +8,13 @@ import Button, { ButtonProps } from '@/components/Button';
|
|||||||
|
|
||||||
import { cn } from '@/lib/helper';
|
import { cn } from '@/lib/helper';
|
||||||
|
|
||||||
|
export type IconPosition = 'left' | 'center' | 'right';
|
||||||
|
|
||||||
export interface ConfirmationModalProps {
|
export interface ConfirmationModalProps {
|
||||||
ref: RefObject<HTMLDialogElement | null>;
|
ref: RefObject<HTMLDialogElement | null>;
|
||||||
type?: 'info' | 'success' | 'error';
|
type?: 'info' | 'success' | 'error';
|
||||||
text?: string;
|
text?: string;
|
||||||
|
subtitleText?: string;
|
||||||
closeOnBackdrop?: boolean;
|
closeOnBackdrop?: boolean;
|
||||||
primaryButton?: ButtonProps & {
|
primaryButton?: ButtonProps & {
|
||||||
text?: string;
|
text?: string;
|
||||||
@@ -24,17 +27,84 @@ export interface ConfirmationModalProps {
|
|||||||
modalBox?: string;
|
modalBox?: string;
|
||||||
};
|
};
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
|
iconSize?: number;
|
||||||
|
iconPosition?: IconPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const iconConfig = {
|
||||||
|
info: {
|
||||||
|
icon: 'material-symbols:info-outline-rounded',
|
||||||
|
iconClassName: 'text-info-content',
|
||||||
|
bgClassName: 'bg-info',
|
||||||
|
outerRingClassName: 'bg-info/20',
|
||||||
|
borderClassName: 'border-info',
|
||||||
|
},
|
||||||
|
success: {
|
||||||
|
icon: 'heroicons:check',
|
||||||
|
iconClassName: 'text-white',
|
||||||
|
bgClassName: 'bg-[#00D390]',
|
||||||
|
outerRingClassName: 'bg-[#00D3901F]',
|
||||||
|
borderClassName: 'border-[#CCF7EB]',
|
||||||
|
},
|
||||||
|
error: {
|
||||||
|
icon: 'solar:danger-triangle-linear',
|
||||||
|
iconClassName: 'text-error-content',
|
||||||
|
bgClassName: 'bg-[#f03338]',
|
||||||
|
outerRingClassName: 'bg-[#f3cdcd]',
|
||||||
|
borderClassName: 'border-[#fff0ef]',
|
||||||
|
},
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
const ConfirmationModalIcon = ({
|
||||||
|
type,
|
||||||
|
size = 24,
|
||||||
|
}: {
|
||||||
|
type: 'info' | 'success' | 'error';
|
||||||
|
size?: number;
|
||||||
|
}) => {
|
||||||
|
const config = iconConfig[type];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='flex items-center justify-center p-2'>
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
'rounded-full border-4 p-1',
|
||||||
|
config.outerRingClassName,
|
||||||
|
config.borderClassName
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<div className={cn('rounded-full p-1', config.outerRingClassName)}>
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
'rounded-full p-3 flex items-center justify-center',
|
||||||
|
config.bgClassName
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
icon={config.icon}
|
||||||
|
width={size}
|
||||||
|
height={size}
|
||||||
|
className={config.iconClassName}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const ConfirmationModal = ({
|
const ConfirmationModal = ({
|
||||||
ref,
|
ref,
|
||||||
type = 'info',
|
type = 'info',
|
||||||
text,
|
text,
|
||||||
|
subtitleText,
|
||||||
closeOnBackdrop,
|
closeOnBackdrop,
|
||||||
primaryButton,
|
primaryButton,
|
||||||
secondaryButton,
|
secondaryButton,
|
||||||
className,
|
className,
|
||||||
children,
|
children,
|
||||||
|
iconSize = 32,
|
||||||
|
iconPosition = 'center',
|
||||||
}: ConfirmationModalProps) => {
|
}: ConfirmationModalProps) => {
|
||||||
const [isPrimaryButtonLoading, setIsPrimaryButtonLoading] = useState(false);
|
const [isPrimaryButtonLoading, setIsPrimaryButtonLoading] = useState(false);
|
||||||
|
|
||||||
@@ -55,47 +125,44 @@ const ConfirmationModal = ({
|
|||||||
return (
|
return (
|
||||||
<Modal ref={ref} closeOnBackdrop={closeOnBackdrop} className={className}>
|
<Modal ref={ref} closeOnBackdrop={closeOnBackdrop} className={className}>
|
||||||
<div className='w-full flex flex-col gap-4'>
|
<div className='w-full flex flex-col gap-4'>
|
||||||
<div
|
{iconPosition === 'center' ? (
|
||||||
className={cn(
|
<>
|
||||||
'w-fit p-4 mx-auto flex flex-row justify-center items-center rounded-full',
|
<div className='w-fit mx-auto'>
|
||||||
{
|
<ConfirmationModalIcon type={type} size={iconSize} />
|
||||||
'bg-error': type === 'error',
|
</div>
|
||||||
'bg-info': type === 'info',
|
|
||||||
'bg-success': type === 'success',
|
|
||||||
}
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{type === 'info' && (
|
|
||||||
<Icon
|
|
||||||
icon='material-symbols:info-outline-rounded'
|
|
||||||
width={64}
|
|
||||||
height={64}
|
|
||||||
className='text-info-content'
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{type === 'success' && (
|
<p className='text-center font-medium'>
|
||||||
<Icon
|
{text ?? 'Apakah anda yakin ingin melakukan hal ini?'}
|
||||||
icon='qlementine-icons:success-12'
|
</p>
|
||||||
width={64}
|
|
||||||
height={64}
|
|
||||||
className='text-success-content'
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{type === 'error' && (
|
{subtitleText && (
|
||||||
<Icon
|
<p className='text-center text-sm text-gray-400'>
|
||||||
icon='solar:danger-triangle-linear'
|
{subtitleText}
|
||||||
width={64}
|
</p>
|
||||||
height={64}
|
)}
|
||||||
className='text-error-content'
|
</>
|
||||||
/>
|
) : (
|
||||||
)}
|
<div
|
||||||
</div>
|
className={cn('flex flex-row items-center gap-4', {
|
||||||
|
'flex-row': iconPosition === 'left',
|
||||||
|
'flex-row-reverse': iconPosition === 'right',
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<div className='w-fit'>
|
||||||
|
<ConfirmationModalIcon type={type} size={iconSize} />
|
||||||
|
</div>
|
||||||
|
|
||||||
<p className='text-center font-medium'>
|
<div className='flex flex-col gap-1'>
|
||||||
{text ?? 'Apakah anda yakin ingin melakukan hal ini?'}
|
<p className='font-medium'>
|
||||||
</p>
|
{text ?? 'Apakah anda yakin ingin melakukan hal ini?'}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
{subtitleText && (
|
||||||
|
<p className='text-sm text-gray-400'>{subtitleText}</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{children && <div className='w-full'>{children}</div>}
|
{children && <div className='w-full'>{children}</div>}
|
||||||
|
|
||||||
@@ -103,7 +170,7 @@ const ConfirmationModal = ({
|
|||||||
{secondaryButton && secondaryButton.text && (
|
{secondaryButton && secondaryButton.text && (
|
||||||
<Button
|
<Button
|
||||||
{...secondaryButton}
|
{...secondaryButton}
|
||||||
variant='ghost'
|
variant='outline'
|
||||||
color={secondaryButton?.color}
|
color={secondaryButton?.color}
|
||||||
isLoading={secondaryButton?.isLoading}
|
isLoading={secondaryButton?.isLoading}
|
||||||
disabled={
|
disabled={
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import Link from 'next/link';
|
|||||||
import Menu from '@/components/menu/Menu';
|
import Menu from '@/components/menu/Menu';
|
||||||
import { Icon } from '@iconify/react';
|
import { Icon } from '@iconify/react';
|
||||||
import { cn, isPathActive } from '@/lib/helper';
|
import { cn, isPathActive } from '@/lib/helper';
|
||||||
|
import { useAuth } from '@/services/hooks/useAuth';
|
||||||
|
|
||||||
export interface SidebarMenuItem {
|
export interface SidebarMenuItem {
|
||||||
type?: 'item' | 'title';
|
type?: 'item' | 'title';
|
||||||
@@ -9,6 +10,7 @@ export interface SidebarMenuItem {
|
|||||||
link: string;
|
link: string;
|
||||||
icon?: string;
|
icon?: string;
|
||||||
submenu?: SidebarMenuItem[];
|
submenu?: SidebarMenuItem[];
|
||||||
|
permission?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SidebarMenuItemProps {
|
interface SidebarMenuItemProps {
|
||||||
@@ -22,8 +24,17 @@ interface SidebarMenuProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const SidebarMenuItem = ({ item, activeLink }: SidebarMenuItemProps) => {
|
const SidebarMenuItem = ({ item, activeLink }: SidebarMenuItemProps) => {
|
||||||
|
const { permissionCheck } = useAuth();
|
||||||
const isItemActive = isPathActive(activeLink, item.link);
|
const isItemActive = isPathActive(activeLink, item.link);
|
||||||
|
|
||||||
|
const isUserPermitted = item.permission
|
||||||
|
? item.permission?.some((permissionName) => permissionCheck(permissionName))
|
||||||
|
: true;
|
||||||
|
|
||||||
|
if (!isUserPermitted) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const menuItemWithoutSubmenu = (
|
const menuItemWithoutSubmenu = (
|
||||||
<li>
|
<li>
|
||||||
<Link
|
<Link
|
||||||
@@ -78,13 +89,15 @@ const SidebarMenuItem = ({ item, activeLink }: SidebarMenuItemProps) => {
|
|||||||
const SidebarMenu = ({ menu, activeLink }: SidebarMenuProps) => {
|
const SidebarMenu = ({ menu, activeLink }: SidebarMenuProps) => {
|
||||||
return (
|
return (
|
||||||
<Menu>
|
<Menu>
|
||||||
{menu.map((menuItem, menuIdx) => (
|
{menu.map((menuItem, menuIdx) => {
|
||||||
<SidebarMenuItem
|
return (
|
||||||
key={menuIdx}
|
<SidebarMenuItem
|
||||||
item={menuItem}
|
key={menuIdx}
|
||||||
activeLink={activeLink}
|
item={menuItem}
|
||||||
/>
|
activeLink={activeLink}
|
||||||
))}
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
</Menu>
|
</Menu>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -309,7 +309,7 @@ const useApprovalSteps = ({
|
|||||||
moduleId: string;
|
moduleId: string;
|
||||||
params?: {
|
params?: {
|
||||||
page?: number;
|
page?: number;
|
||||||
limit: number;
|
limit: number | string;
|
||||||
search?: string;
|
search?: string;
|
||||||
group_step_number?: boolean;
|
group_step_number?: boolean;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -19,12 +19,16 @@ import ClosingOverheadTabContent from '@/components/pages/closing/ClosingOverhea
|
|||||||
import ClosingFinanceTabContent from '@/components/pages/closing/ClosingFinanceTabContent';
|
import ClosingFinanceTabContent from '@/components/pages/closing/ClosingFinanceTabContent';
|
||||||
import SalesReportTable from '@/components/pages/closing/sale/SalesReportTable';
|
import SalesReportTable from '@/components/pages/closing/sale/SalesReportTable';
|
||||||
import HppExpeditionReportTable from './hpp-ekspedisi/HppExpeditionReportTable';
|
import HppExpeditionReportTable from './hpp-ekspedisi/HppExpeditionReportTable';
|
||||||
|
import ClosingKandangList from '@/components/pages/closing/ClosingKandangList';
|
||||||
|
import { ProjectFlock } from '@/types/api/production/project-flock';
|
||||||
|
import { ProjectFlockKandang } from '@/types/api/production/project-flock-kandang';
|
||||||
interface ClosingDetailProps {
|
interface ClosingDetailProps {
|
||||||
id: number;
|
id: number;
|
||||||
initialValue?: ClosingGeneralInformation;
|
initialValue?: ClosingGeneralInformation;
|
||||||
salesData?: BaseClosingSales;
|
salesData?: BaseClosingSales;
|
||||||
hppExpeditionData?: ClosingHppExpedition;
|
hppExpeditionData?: ClosingHppExpedition;
|
||||||
|
projectData?: ProjectFlock;
|
||||||
|
kandangData?: ProjectFlockKandang;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ClosingDetail: React.FC<ClosingDetailProps> = ({
|
const ClosingDetail: React.FC<ClosingDetailProps> = ({
|
||||||
@@ -32,6 +36,8 @@ const ClosingDetail: React.FC<ClosingDetailProps> = ({
|
|||||||
initialValue,
|
initialValue,
|
||||||
salesData,
|
salesData,
|
||||||
hppExpeditionData,
|
hppExpeditionData,
|
||||||
|
projectData,
|
||||||
|
kandangData,
|
||||||
}) => {
|
}) => {
|
||||||
const [activeTab, setActiveTab] = useState<string>('sapronak');
|
const [activeTab, setActiveTab] = useState<string>('sapronak');
|
||||||
|
|
||||||
@@ -45,7 +51,12 @@ const ClosingDetail: React.FC<ClosingDetailProps> = ({
|
|||||||
{
|
{
|
||||||
id: 'perhitunganSapronak',
|
id: 'perhitunganSapronak',
|
||||||
label: 'Perhitungan Sapronak',
|
label: 'Perhitungan Sapronak',
|
||||||
content: <ClosingSapronakCalculationTabContent projectFlockId={id} />,
|
content: (
|
||||||
|
<ClosingSapronakCalculationTabContent
|
||||||
|
closingGeneralInformation={initialValue}
|
||||||
|
projectFlockId={id}
|
||||||
|
/>
|
||||||
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'penjualan',
|
id: 'penjualan',
|
||||||
@@ -82,7 +93,9 @@ const ClosingDetail: React.FC<ClosingDetailProps> = ({
|
|||||||
<section className='w-full max-w-7xl pb-16'>
|
<section className='w-full max-w-7xl pb-16'>
|
||||||
<header className='flex flex-col gap-4'>
|
<header className='flex flex-col gap-4'>
|
||||||
<Button
|
<Button
|
||||||
href='/closing'
|
href={
|
||||||
|
!kandangData ? '/closing' : `/closing/detail/?closingId=${id}`
|
||||||
|
}
|
||||||
variant='link'
|
variant='link'
|
||||||
className='w-fit p-0 text-primary'
|
className='w-fit p-0 text-primary'
|
||||||
>
|
>
|
||||||
@@ -93,7 +106,18 @@ const ClosingDetail: React.FC<ClosingDetailProps> = ({
|
|||||||
<h1 className='text-2xl font-bold text-center'>Detail Closing</h1>
|
<h1 className='text-2xl font-bold text-center'>Detail Closing</h1>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<ClosingGeneralInformationTable initialValue={initialValue} />
|
<ClosingGeneralInformationTable
|
||||||
|
initialValue={initialValue}
|
||||||
|
projectData={projectData}
|
||||||
|
kandangData={kandangData}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{!kandangData && (
|
||||||
|
<ClosingKandangList
|
||||||
|
initialValue={initialValue}
|
||||||
|
projectData={projectData}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
<Tabs
|
<Tabs
|
||||||
activeTabId={activeTab}
|
activeTabId={activeTab}
|
||||||
|
|||||||
@@ -23,6 +23,14 @@ type HppTableRow =
|
|||||||
type?: never;
|
type?: never;
|
||||||
budgeting?: never;
|
budgeting?: never;
|
||||||
realization?: never;
|
realization?: never;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
type: string;
|
||||||
|
group_name: string;
|
||||||
|
group_index: number;
|
||||||
|
isGroupHeader: false;
|
||||||
|
budgeting?: { rp_per_bird: number; rp_per_kg: number; amount: number };
|
||||||
|
realization?: { rp_per_bird: number; rp_per_kg: number; amount: number };
|
||||||
};
|
};
|
||||||
|
|
||||||
type ProfitLossTableRow =
|
type ProfitLossTableRow =
|
||||||
@@ -52,25 +60,117 @@ const ClosingFinanceTable = ({
|
|||||||
() => ClosingApi.getFinance(projectFlockId)
|
() => ClosingApi.getFinance(projectFlockId)
|
||||||
);
|
);
|
||||||
|
|
||||||
const hppTableData: HppTableRow[] = isResponseSuccess(finance)
|
const staticHppRows: Array<{
|
||||||
? finance.data.hpp_purchases.hpp.flatMap((hpp, groupIndex) => [
|
group_name: string;
|
||||||
// Group header row
|
type: string;
|
||||||
{
|
group_index: number;
|
||||||
group_name: hpp.group_name,
|
}> = [
|
||||||
group_index: groupIndex,
|
{
|
||||||
isGroupHeader: true as const,
|
group_name: 'HPP dan Pengeluaran',
|
||||||
},
|
type: 'Pembelian PAKAN',
|
||||||
// Data rows
|
group_index: 0,
|
||||||
...hpp.data.map((item) => ({
|
},
|
||||||
group_name: hpp.group_name,
|
{
|
||||||
group_index: groupIndex,
|
group_name: 'HPP dan Pengeluaran',
|
||||||
type: item.type,
|
type: 'Pembelian STARTER',
|
||||||
budgeting: item.budgeting,
|
group_index: 0,
|
||||||
realization: item.realization,
|
},
|
||||||
|
{
|
||||||
|
group_name: 'HPP dan Pengeluaran',
|
||||||
|
type: 'Pembelian DOC',
|
||||||
|
group_index: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
group_name: 'HPP dan Pengeluaran',
|
||||||
|
type: 'Pembelian PULLET',
|
||||||
|
group_index: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
group_name: 'HPP dan Pengeluaran',
|
||||||
|
type: 'Pembelian LAYER',
|
||||||
|
group_index: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
group_name: 'HPP dan Bahan Baku',
|
||||||
|
type: 'Pengeluaran Overhead',
|
||||||
|
group_index: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
group_name: 'HPP dan Bahan Baku',
|
||||||
|
type: 'Beban Ekspedisi',
|
||||||
|
group_index: 1,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const hppTableData: HppTableRow[] = [
|
||||||
|
{
|
||||||
|
group_name: 'HPP dan Pengeluaran',
|
||||||
|
group_index: 0,
|
||||||
|
isGroupHeader: true as const,
|
||||||
|
},
|
||||||
|
...staticHppRows
|
||||||
|
.filter((row) => row.group_index === 0)
|
||||||
|
.map((staticRow) => {
|
||||||
|
const apiData = isResponseSuccess(finance)
|
||||||
|
? finance.data.hpp_purchases.hpp
|
||||||
|
.find((g) => g.group_name === staticRow.group_name)
|
||||||
|
?.data.find((d) => d.type === staticRow.type)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
return {
|
||||||
|
group_name: staticRow.group_name,
|
||||||
|
group_index: staticRow.group_index,
|
||||||
|
type: staticRow.type,
|
||||||
|
budgeting: apiData?.budgeting || {
|
||||||
|
rp_per_bird: 0,
|
||||||
|
rp_per_kg: 0,
|
||||||
|
amount: 0,
|
||||||
|
},
|
||||||
|
realization: apiData?.realization || {
|
||||||
|
rp_per_bird: 0,
|
||||||
|
rp_per_kg: 0,
|
||||||
|
amount: 0,
|
||||||
|
},
|
||||||
isGroupHeader: false as const,
|
isGroupHeader: false as const,
|
||||||
})),
|
};
|
||||||
])
|
}),
|
||||||
: [];
|
{
|
||||||
|
group_name: 'HPP dan Bahan Baku',
|
||||||
|
group_index: 1,
|
||||||
|
isGroupHeader: true as const,
|
||||||
|
},
|
||||||
|
...staticHppRows
|
||||||
|
.filter((row) => row.group_index === 1)
|
||||||
|
.map((staticRow) => {
|
||||||
|
const apiData = isResponseSuccess(finance)
|
||||||
|
? finance.data.hpp_purchases.hpp
|
||||||
|
.find((g) => g.group_name === staticRow.group_name)
|
||||||
|
?.data.find((d) => d.type === staticRow.type)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
return {
|
||||||
|
group_name: staticRow.group_name,
|
||||||
|
group_index: staticRow.group_index,
|
||||||
|
type: staticRow.type,
|
||||||
|
budgeting: apiData?.budgeting || {
|
||||||
|
rp_per_bird: 0,
|
||||||
|
rp_per_kg: 0,
|
||||||
|
amount: 0,
|
||||||
|
},
|
||||||
|
realization: apiData?.realization || {
|
||||||
|
rp_per_bird: 0,
|
||||||
|
rp_per_kg: 0,
|
||||||
|
amount: 0,
|
||||||
|
},
|
||||||
|
isGroupHeader: false as const,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
group_name: 'HPP',
|
||||||
|
group_index: 2,
|
||||||
|
isGroupHeader: true as const,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
const profitLossTableData: ProfitLossTableRow[] = isResponseSuccess(finance)
|
const profitLossTableData: ProfitLossTableRow[] = isResponseSuccess(finance)
|
||||||
? [
|
? [
|
||||||
@@ -217,8 +317,8 @@ const ClosingFinanceTable = ({
|
|||||||
return props.column.id === 'budgeting_rp_per_bird' &&
|
return props.column.id === 'budgeting_rp_per_bird' &&
|
||||||
isResponseSuccess(finance)
|
isResponseSuccess(finance)
|
||||||
? formatCurrency(
|
? formatCurrency(
|
||||||
finance.data.hpp_purchases.summary_hpp.budgeting
|
finance.data.hpp_purchases.summary_hpp?.budgeting
|
||||||
.rp_per_bird || 0
|
?.rp_per_bird || 0
|
||||||
)
|
)
|
||||||
: '-';
|
: '-';
|
||||||
},
|
},
|
||||||
@@ -233,8 +333,8 @@ const ClosingFinanceTable = ({
|
|||||||
return props.column.id === 'budgeting_rp_per_kg' &&
|
return props.column.id === 'budgeting_rp_per_kg' &&
|
||||||
isResponseSuccess(finance)
|
isResponseSuccess(finance)
|
||||||
? formatCurrency(
|
? formatCurrency(
|
||||||
finance.data.hpp_purchases.summary_hpp.budgeting
|
finance.data.hpp_purchases.summary_hpp?.budgeting
|
||||||
.rp_per_kg || 0
|
?.rp_per_kg || 0
|
||||||
)
|
)
|
||||||
: '-';
|
: '-';
|
||||||
},
|
},
|
||||||
@@ -249,8 +349,8 @@ const ClosingFinanceTable = ({
|
|||||||
return props.column.id === 'budgeting_amount' &&
|
return props.column.id === 'budgeting_amount' &&
|
||||||
isResponseSuccess(finance)
|
isResponseSuccess(finance)
|
||||||
? formatCurrency(
|
? formatCurrency(
|
||||||
finance.data.hpp_purchases.summary_hpp.budgeting
|
finance.data.hpp_purchases.summary_hpp?.budgeting
|
||||||
.amount || 0
|
?.amount || 0
|
||||||
)
|
)
|
||||||
: '-';
|
: '-';
|
||||||
},
|
},
|
||||||
@@ -271,8 +371,8 @@ const ClosingFinanceTable = ({
|
|||||||
return props.column.id === 'realization_rp_per_bird' &&
|
return props.column.id === 'realization_rp_per_bird' &&
|
||||||
isResponseSuccess(finance)
|
isResponseSuccess(finance)
|
||||||
? formatCurrency(
|
? formatCurrency(
|
||||||
finance.data.hpp_purchases.summary_hpp.realization
|
finance.data.hpp_purchases.summary_hpp
|
||||||
.rp_per_bird || 0
|
?.realization?.rp_per_bird || 0
|
||||||
)
|
)
|
||||||
: '-';
|
: '-';
|
||||||
},
|
},
|
||||||
@@ -287,8 +387,8 @@ const ClosingFinanceTable = ({
|
|||||||
return props.column.id === 'realization_rp_per_kg' &&
|
return props.column.id === 'realization_rp_per_kg' &&
|
||||||
isResponseSuccess(finance)
|
isResponseSuccess(finance)
|
||||||
? formatCurrency(
|
? formatCurrency(
|
||||||
finance.data.hpp_purchases.summary_hpp.realization
|
finance.data.hpp_purchases.summary_hpp
|
||||||
.rp_per_kg || 0
|
?.realization?.rp_per_kg || 0
|
||||||
)
|
)
|
||||||
: '-';
|
: '-';
|
||||||
},
|
},
|
||||||
@@ -303,8 +403,8 @@ const ClosingFinanceTable = ({
|
|||||||
return props.column.id === 'realization_amount' &&
|
return props.column.id === 'realization_amount' &&
|
||||||
isResponseSuccess(finance)
|
isResponseSuccess(finance)
|
||||||
? formatCurrency(
|
? formatCurrency(
|
||||||
finance.data.hpp_purchases.summary_hpp.realization
|
finance.data.hpp_purchases.summary_hpp
|
||||||
.amount || 0
|
?.realization?.amount || 0
|
||||||
)
|
)
|
||||||
: '-';
|
: '-';
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,12 +1,29 @@
|
|||||||
import { ClosingGeneralInformation } from '@/types/api/closing';
|
import { ClosingGeneralInformation } from '@/types/api/closing';
|
||||||
|
import { ProjectFlock } from '@/types/api/production/project-flock';
|
||||||
|
import { ProjectFlockKandang } from '@/types/api/production/project-flock-kandang';
|
||||||
|
import { useMemo } from 'react';
|
||||||
|
|
||||||
interface ClosingGeneralInformationProps {
|
interface ClosingGeneralInformationProps {
|
||||||
initialValue?: ClosingGeneralInformation;
|
initialValue?: ClosingGeneralInformation;
|
||||||
|
projectData?: ProjectFlock;
|
||||||
|
kandangData?: ProjectFlockKandang;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ClosingGeneralInformationTable = ({
|
const ClosingGeneralInformationTable = ({
|
||||||
initialValue,
|
initialValue,
|
||||||
|
projectData,
|
||||||
|
kandangData,
|
||||||
}: ClosingGeneralInformationProps) => {
|
}: ClosingGeneralInformationProps) => {
|
||||||
|
const chickinPopulation = useMemo(() => {
|
||||||
|
if (kandangData) {
|
||||||
|
return kandangData?.chickins?.reduce(
|
||||||
|
(acc, chickin) => acc + chickin.usage_qty,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}, [kandangData]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='w-full my-4 @container'>
|
<div className='w-full my-4 @container'>
|
||||||
<div className='flex flex-col @sm:flex-row gap-4'>
|
<div className='flex flex-col @sm:flex-row gap-4'>
|
||||||
@@ -17,7 +34,9 @@ const ClosingGeneralInformationTable = ({
|
|||||||
<tr>
|
<tr>
|
||||||
<td>Lokasi</td>
|
<td>Lokasi</td>
|
||||||
<td>:</td>
|
<td>:</td>
|
||||||
<td>{initialValue?.location_name}</td>
|
<td>
|
||||||
|
{initialValue?.location_name ?? projectData?.location?.name}
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Periode</td>
|
<td>Periode</td>
|
||||||
@@ -25,14 +44,22 @@ const ClosingGeneralInformationTable = ({
|
|||||||
<td>{initialValue?.period}</td>
|
<td>{initialValue?.period}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Kategori</td>
|
<td>Project Flock</td>
|
||||||
<td>:</td>
|
<td>:</td>
|
||||||
<td>{initialValue?.project_category}</td>
|
<td>
|
||||||
|
{initialValue?.project_flock?.name ??
|
||||||
|
projectData?.flock_name}
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Populasi</td>
|
<td>Populasi</td>
|
||||||
<td>:</td>
|
<td>:</td>
|
||||||
<td>{initialValue?.population} Ekor</td>
|
<td>
|
||||||
|
{!kandangData
|
||||||
|
? (initialValue?.population ?? 0)
|
||||||
|
: (chickinPopulation ?? 0)}{' '}
|
||||||
|
Ekor
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Jenis Project</td>
|
<td>Jenis Project</td>
|
||||||
@@ -40,9 +67,13 @@ const ClosingGeneralInformationTable = ({
|
|||||||
<td>{initialValue?.project_type}</td>
|
<td>{initialValue?.project_type}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr className='table-row @sm:hidden'>
|
<tr className='table-row @sm:hidden'>
|
||||||
<td>Kandang Aktif</td>
|
<td>Kandang {!kandangData && 'Aktif'}</td>
|
||||||
<td>:</td>
|
<td>:</td>
|
||||||
<td>{initialValue?.active_house_count} Kandang</td>
|
<td>
|
||||||
|
{!kandangData
|
||||||
|
? `${initialValue?.active_house_count} Kandang`
|
||||||
|
: kandangData?.kandang?.name}
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr className='table-row @sm:hidden'>
|
<tr className='table-row @sm:hidden'>
|
||||||
<td>Status Pembayaran Penjualan</td>
|
<td>Status Pembayaran Penjualan</td>
|
||||||
@@ -69,9 +100,13 @@ const ClosingGeneralInformationTable = ({
|
|||||||
<table className='table table-zebra table-sm'>
|
<table className='table table-zebra table-sm'>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Kandang Aktif</td>
|
<td>Kandang {!kandangData && 'Aktif'}</td>
|
||||||
<td>:</td>
|
<td>:</td>
|
||||||
<td>{initialValue?.active_house_count} Kandang</td>
|
<td>
|
||||||
|
{!kandangData
|
||||||
|
? `${initialValue?.active_house_count} Kandang`
|
||||||
|
: kandangData?.kandang?.name}
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Status Pembayaran Penjualan</td>
|
<td>Status Pembayaran Penjualan</td>
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import Button from '@/components/Button';
|
||||||
|
import { ClosingGeneralInformation } from '@/types/api/closing';
|
||||||
|
import { ProjectFlock } from '@/types/api/production/project-flock';
|
||||||
|
|
||||||
|
const ClosingKandangList = ({
|
||||||
|
initialValue,
|
||||||
|
projectData,
|
||||||
|
}: {
|
||||||
|
initialValue?: ClosingGeneralInformation;
|
||||||
|
projectData?: ProjectFlock;
|
||||||
|
}) => {
|
||||||
|
return (
|
||||||
|
<div className='w-full my-4 @container'>
|
||||||
|
<div className='flex flex-col @sm:flex-row gap-4'>
|
||||||
|
<div className='w-full'>
|
||||||
|
<div className='overflow-x-auto'>
|
||||||
|
<h1 className='font-bold my-4'>Kandang</h1>
|
||||||
|
<div className='flex flex-wrap gap-2 mb-4'>
|
||||||
|
{projectData?.kandangs?.map((kandang) => (
|
||||||
|
<Button
|
||||||
|
key={kandang.id}
|
||||||
|
variant='outline'
|
||||||
|
href={`/closing/detail/?closingId=${initialValue?.flock_id}&kandangId=${kandang.project_flock_kandang_id}`}
|
||||||
|
className='min-w-32'
|
||||||
|
>
|
||||||
|
{kandang.name}
|
||||||
|
</Button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ClosingKandangList;
|
||||||
@@ -96,11 +96,6 @@ const ClosingProductionDataTabContent = ({
|
|||||||
value={formatNumber(purchase.feed_used)}
|
value={formatNumber(purchase.feed_used)}
|
||||||
unit='Kg'
|
unit='Kg'
|
||||||
/>
|
/>
|
||||||
<DataRow
|
|
||||||
label='Pakan Terpakai per Ekor'
|
|
||||||
value={formatNumber(purchase.feed_used_per_head)}
|
|
||||||
unit='Kg'
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@@ -124,14 +119,12 @@ const ClosingProductionDataTabContent = ({
|
|||||||
/>
|
/>
|
||||||
<DataRow
|
<DataRow
|
||||||
label='Bobot Rata-Rata'
|
label='Bobot Rata-Rata'
|
||||||
value={formatNumber(sales.chicken.average_weight)}
|
value={formatNumber(sales.chicken.avg_weight)}
|
||||||
unit='Kg/Ekor'
|
unit='Kg/Ekor'
|
||||||
/>
|
/>
|
||||||
<DataRow
|
<DataRow
|
||||||
label='Harga Jual Rata-Rata'
|
label='Harga Jual Rata-Rata'
|
||||||
value={formatNumber(
|
value={formatNumber(sales.chicken.avg_selling_price)}
|
||||||
sales.chicken.chicken_average_selling_price
|
|
||||||
)}
|
|
||||||
unit='Rupiah'
|
unit='Rupiah'
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -148,17 +141,17 @@ const ClosingProductionDataTabContent = ({
|
|||||||
/>
|
/>
|
||||||
<DataRow
|
<DataRow
|
||||||
label='Telur (Kg)'
|
label='Telur (Kg)'
|
||||||
value={formatNumber(sales.egg.egg_mass_kg)}
|
value={formatNumber(sales.egg.egg_mass)}
|
||||||
unit='Kg'
|
unit='Kg'
|
||||||
/>
|
/>
|
||||||
<DataRow
|
<DataRow
|
||||||
label='Berat Telur Rata-Rata'
|
label='Berat Telur Rata-Rata'
|
||||||
value={formatNumber(sales.egg.average_egg_weight_kg)}
|
value={formatNumber(sales.egg.avg_egg_weight)}
|
||||||
unit='Kg'
|
unit='Kg'
|
||||||
/>
|
/>
|
||||||
<DataRow
|
<DataRow
|
||||||
label='Harga Jual Telur Rata-Rata'
|
label='Harga Jual Telur Rata-Rata'
|
||||||
value={formatNumber(sales.egg.egg_average_selling_price)}
|
value={formatNumber(sales.egg.avg_selling_price)}
|
||||||
unit='Rupiah'
|
unit='Rupiah'
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -191,17 +184,37 @@ const ClosingProductionDataTabContent = ({
|
|||||||
/>
|
/>
|
||||||
<DataRow
|
<DataRow
|
||||||
label='Mortalitas Std'
|
label='Mortalitas Std'
|
||||||
value={formatNumber(performance.mortality_std)}
|
value={formatNumber(performance.mor_std)}
|
||||||
unitClassName='hidden'
|
unitClassName='hidden'
|
||||||
/>
|
/>
|
||||||
<DataRow
|
<DataRow
|
||||||
label='Mortalitas Act'
|
label='Mortalitas Act'
|
||||||
value={formatNumber(performance.mortality_act)}
|
value={formatNumber(performance.mor_act)}
|
||||||
unitClassName='hidden'
|
unitClassName='hidden'
|
||||||
/>
|
/>
|
||||||
<DataRow
|
<DataRow
|
||||||
label='DEFF Mortalitas'
|
label='DEFF Mortalitas'
|
||||||
value={formatNumber(performance.deff_mortality)}
|
value={formatNumber(performance.mor_diff)}
|
||||||
|
unitClassName='hidden'
|
||||||
|
/>
|
||||||
|
<DataRow
|
||||||
|
label='AWG Std'
|
||||||
|
value={formatNumber(performance.awg_std)}
|
||||||
|
unit='Gr/Hari'
|
||||||
|
/>
|
||||||
|
<DataRow
|
||||||
|
label='AWG Act'
|
||||||
|
value={formatNumber(performance.awg_act)}
|
||||||
|
unit='Gr/Hari'
|
||||||
|
/>
|
||||||
|
<DataRow
|
||||||
|
label='Feed Intake Std'
|
||||||
|
value={formatNumber(performance.feed_intake_std)}
|
||||||
|
unitClassName='hidden'
|
||||||
|
/>
|
||||||
|
<DataRow
|
||||||
|
label='Feed Intake Act'
|
||||||
|
value={formatNumber(performance.feed_intake)}
|
||||||
unitClassName='hidden'
|
unitClassName='hidden'
|
||||||
/>
|
/>
|
||||||
<DataRow
|
<DataRow
|
||||||
@@ -216,14 +229,70 @@ const ClosingProductionDataTabContent = ({
|
|||||||
/>
|
/>
|
||||||
<DataRow
|
<DataRow
|
||||||
label='DEFF FCR'
|
label='DEFF FCR'
|
||||||
value={formatNumber(performance.deff_fcr)}
|
value={formatNumber(performance.fcr_diff)}
|
||||||
unitClassName='hidden'
|
unitClassName='hidden'
|
||||||
/>
|
/>
|
||||||
<DataRow
|
|
||||||
label='AWG'
|
{/* Laying Specific Fields */}
|
||||||
value={formatNumber(performance.awg)}
|
{performance.hen_day_act !== undefined && (
|
||||||
unit='Gr/Hari'
|
<>
|
||||||
/>
|
<DataRow
|
||||||
|
label='Hen Day Std'
|
||||||
|
value={formatNumber(performance.hen_day_std!)}
|
||||||
|
unit='%'
|
||||||
|
/>
|
||||||
|
<DataRow
|
||||||
|
label='Hen Day Act'
|
||||||
|
value={formatNumber(performance.hen_day_act)}
|
||||||
|
unit='%'
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{performance.egg_mass !== undefined && (
|
||||||
|
<>
|
||||||
|
<DataRow
|
||||||
|
label='Egg Mass Std'
|
||||||
|
value={formatNumber(performance.egg_mass_std!)}
|
||||||
|
unit='Kg'
|
||||||
|
/>
|
||||||
|
<DataRow
|
||||||
|
label='Egg Mass Act'
|
||||||
|
value={formatNumber(performance.egg_mass)}
|
||||||
|
unit='Kg'
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{performance.egg_weight !== undefined && (
|
||||||
|
<>
|
||||||
|
<DataRow
|
||||||
|
label='Egg Weight Std'
|
||||||
|
value={formatNumber(performance.egg_weight_std!)}
|
||||||
|
unit='Gr'
|
||||||
|
/>
|
||||||
|
<DataRow
|
||||||
|
label='Egg Weight Act'
|
||||||
|
value={formatNumber(performance.egg_weight)}
|
||||||
|
unit='Gr'
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{performance.hen_housed_act !== undefined && (
|
||||||
|
<>
|
||||||
|
<DataRow
|
||||||
|
label='Hen Housed Std'
|
||||||
|
value={formatNumber(performance.hen_housed_std!)}
|
||||||
|
unit='%'
|
||||||
|
/>
|
||||||
|
<DataRow
|
||||||
|
label='Hen Housed Act'
|
||||||
|
value={formatNumber(performance.hen_housed_act)}
|
||||||
|
unit='%'
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,21 +1,25 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import ClosingIncomingSapronaksTable from '@/components/pages/closing/ClosingIncomingSapronaksTable';
|
|
||||||
import ClosingOutgoingSapronaksTable from '@/components/pages/closing/ClosingOutgoingSapronaksTable';
|
|
||||||
import ClosingSapronakCalculationTable from '@/components/pages/closing/ClosingSapronakCalculationTable';
|
import ClosingSapronakCalculationTable from '@/components/pages/closing/ClosingSapronakCalculationTable';
|
||||||
|
import { ClosingGeneralInformation } from '@/types/api/closing';
|
||||||
|
|
||||||
interface ClosingSapronakCalculationTabContentProps {
|
interface ClosingSapronakCalculationTabContentProps {
|
||||||
projectFlockId?: number;
|
projectFlockId?: number;
|
||||||
|
closingGeneralInformation?: ClosingGeneralInformation;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ClosingSapronakCalculationTabContent = ({
|
const ClosingSapronakCalculationTabContent = ({
|
||||||
projectFlockId,
|
projectFlockId,
|
||||||
|
closingGeneralInformation,
|
||||||
}: ClosingSapronakCalculationTabContentProps) => {
|
}: ClosingSapronakCalculationTabContentProps) => {
|
||||||
return (
|
return (
|
||||||
<div className='flex flex-col gap-4'>
|
<div className='flex flex-col gap-4'>
|
||||||
{projectFlockId && (
|
{projectFlockId && (
|
||||||
<>
|
<>
|
||||||
<ClosingSapronakCalculationTable projectFlockId={projectFlockId} />
|
<ClosingSapronakCalculationTable
|
||||||
|
closingGeneralInformation={closingGeneralInformation}
|
||||||
|
projectFlockId={projectFlockId}
|
||||||
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
import Card from '@/components/Card';
|
import Card from '@/components/Card';
|
||||||
|
|
||||||
import Table from '@/components/Table';
|
import Table from '@/components/Table';
|
||||||
import { cn, formatCurrency, formatNumber } from '@/lib/helper';
|
import { formatCurrency, formatDate, formatNumber } from '@/lib/helper';
|
||||||
import {
|
import {
|
||||||
RowSapronakCalculation,
|
RowSapronakCalculation,
|
||||||
TotalSapronakCalculation,
|
TotalSapronakCalculation,
|
||||||
@@ -13,19 +13,24 @@ import { useMemo } from 'react';
|
|||||||
import useSWR from 'swr';
|
import useSWR from 'swr';
|
||||||
import { ClosingApi } from '@/services/api/closing';
|
import { ClosingApi } from '@/services/api/closing';
|
||||||
import { isResponseSuccess } from '@/lib/api-helper';
|
import { isResponseSuccess } from '@/lib/api-helper';
|
||||||
|
import { ClosingGeneralInformation } from '@/types/api/closing';
|
||||||
|
import { useSearchParams } from 'next/navigation';
|
||||||
|
|
||||||
interface ClosingSapronakCalculationTableProps {
|
interface ClosingSapronakCalculationTableProps {
|
||||||
type?: 'detail';
|
|
||||||
projectFlockId: number;
|
projectFlockId: number;
|
||||||
|
closingGeneralInformation?: ClosingGeneralInformation;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ClosingSapronakCalculationTable = ({
|
const ClosingSapronakCalculationTable = ({
|
||||||
type,
|
|
||||||
projectFlockId,
|
projectFlockId,
|
||||||
|
closingGeneralInformation,
|
||||||
}: ClosingSapronakCalculationTableProps) => {
|
}: ClosingSapronakCalculationTableProps) => {
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
const kandangId = searchParams.get('kandangId');
|
||||||
|
|
||||||
const { data: sapronakCalculation, isLoading } = useSWR(
|
const { data: sapronakCalculation, isLoading } = useSWR(
|
||||||
`/closing/sapronak-calculation/${projectFlockId}`,
|
`/closing/sapronak-calculation/${projectFlockId}${kandangId ? `/${kandangId}` : ''}`,
|
||||||
() => ClosingApi.getPerhitunganSapronak(projectFlockId),
|
() => ClosingApi.getPerhitunganSapronak(projectFlockId, Number(kandangId)),
|
||||||
{
|
{
|
||||||
keepPreviousData: true,
|
keepPreviousData: true,
|
||||||
}
|
}
|
||||||
@@ -37,101 +42,121 @@ const ClosingSapronakCalculationTable = ({
|
|||||||
): ColumnDef<RowSapronakCalculation>[] => [
|
): ColumnDef<RowSapronakCalculation>[] => [
|
||||||
{
|
{
|
||||||
header: 'Tanggal',
|
header: 'Tanggal',
|
||||||
accessorKey: 'tanggal',
|
accessorKey: 'date',
|
||||||
cell: (props) => (props.getValue() as string) || '-',
|
cell: (props) =>
|
||||||
|
props.row.original.date
|
||||||
|
? formatDate(props.row.original.date, 'DD MMM YYYY')
|
||||||
|
: '-',
|
||||||
footer: 'Total',
|
footer: 'Total',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: 'No. Referensi',
|
header: 'No. Referensi',
|
||||||
accessorKey: 'no_referensi',
|
accessorKey: 'reference_number',
|
||||||
cell: (props) => (props.getValue() as string) || '-',
|
cell: (props) => (props.row.original.reference_number as string) || '-',
|
||||||
footer: '',
|
footer: '',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: 'QTY Masuk',
|
header: 'QTY Masuk',
|
||||||
accessorKey: 'qty_masuk',
|
accessorKey: 'qty_in',
|
||||||
cell: (props) => formatNumber(props.getValue() as number),
|
cell: (props) =>
|
||||||
|
props.row.original.qty_in
|
||||||
|
? formatNumber(props.row.original.qty_in as number)
|
||||||
|
: '0',
|
||||||
footer: total
|
footer: total
|
||||||
? () => (
|
? () => (
|
||||||
<div className='font-semibold text-gray-900'>
|
<div className='font-semibold text-gray-900'>
|
||||||
{formatNumber(total.qty_masuk)}
|
{total?.qty_in ? formatNumber(total?.qty_in) : '0'}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
: '',
|
: '',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: 'QTY Keluar',
|
header: 'QTY Keluar',
|
||||||
accessorKey: 'qty_keluar',
|
accessorKey: 'qty_out',
|
||||||
cell: (props) => formatNumber(props.getValue() as number),
|
cell: (props) =>
|
||||||
|
props.row.original.qty_out
|
||||||
|
? formatNumber(props.row.original.qty_out as number)
|
||||||
|
: '0',
|
||||||
footer: total
|
footer: total
|
||||||
? () => (
|
? () => (
|
||||||
<div className='font-semibold text-gray-900'>
|
<div className='font-semibold text-gray-900'>
|
||||||
{formatNumber(total.qty_keluar)}
|
{total?.qty_out ? formatNumber(total?.qty_out) : '0'}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
: '',
|
: '',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: 'QTY Pakai',
|
header: 'QTY Pakai',
|
||||||
accessorKey: 'qty_pakai',
|
accessorKey: 'qty_used',
|
||||||
cell: (props) => formatNumber(props.getValue() as number),
|
cell: (props) =>
|
||||||
|
props.row.original.qty_used
|
||||||
|
? formatNumber(props.row.original.qty_used as number)
|
||||||
|
: '0',
|
||||||
footer: total
|
footer: total
|
||||||
? () => (
|
? () => (
|
||||||
<div className='font-semibold text-gray-900'>
|
<div className='font-semibold text-gray-900'>
|
||||||
{formatNumber(total.qty_pakai)}
|
{total?.qty_used ? formatNumber(total?.qty_used) : '0'}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
: '',
|
: '',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: 'Uraian',
|
header: 'Uraian',
|
||||||
accessorKey: 'uraian',
|
accessorKey: 'description',
|
||||||
cell: (props) => (props.getValue() as string) || '-',
|
cell: (props) => (props.row.original.description as string) || '-',
|
||||||
footer: '',
|
footer: '',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: 'Kategori Produk',
|
header: 'Kategori Produk',
|
||||||
accessorKey: 'kategori_produk',
|
accessorKey: 'product_category',
|
||||||
cell: (props) => (props.getValue() as string) || '-',
|
cell: (props) => (props.row.original.product_category as string) || '-',
|
||||||
footer: '',
|
footer: '',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: 'Harga Beli/Qty (Rp)',
|
header: 'Harga Beli/Qty (Rp)',
|
||||||
accessorKey: 'harga_beli_per_qty',
|
accessorKey: 'unit_price',
|
||||||
cell: (props) => formatCurrency(props.getValue() as number),
|
cell: (props) =>
|
||||||
|
props.row.original.unit_price
|
||||||
|
? formatCurrency(props.row.original.unit_price as number)
|
||||||
|
: '-',
|
||||||
footer: total
|
footer: total
|
||||||
? () => (
|
? () => (
|
||||||
<div className='font-semibold text-gray-900'>
|
<div className='font-semibold text-gray-900'>
|
||||||
{formatCurrency(total.harga_beli_per_qty)}
|
{total?.avg_unit_price
|
||||||
|
? formatCurrency(total?.avg_unit_price)
|
||||||
|
: '-'}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
: '',
|
: '',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: 'Total Harga (Rp)',
|
header: 'Total Harga (Rp)',
|
||||||
accessorKey: 'total_harga',
|
accessorKey: 'total_amount',
|
||||||
cell: (props) => formatCurrency(props.getValue() as number),
|
cell: (props) =>
|
||||||
|
props.row.original.total_amount
|
||||||
|
? formatCurrency(props.row.original.total_amount as number)
|
||||||
|
: '-',
|
||||||
footer: total
|
footer: total
|
||||||
? () => (
|
? () => (
|
||||||
<div className='font-semibold text-gray-900'>
|
<div className='font-semibold text-gray-900'>
|
||||||
{formatCurrency(total.total_harga)}
|
{total?.total_amount ? formatCurrency(total?.total_amount) : '-'}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
: '',
|
: '',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: 'Keterangan',
|
header: 'Keterangan',
|
||||||
accessorKey: 'keterangan',
|
accessorKey: 'notes',
|
||||||
cell: (props) => (props.getValue() as string) || '-',
|
cell: (props) => (props.row.original.notes as string) || '-',
|
||||||
footer: '',
|
footer: '',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
// Memoize columns untuk setiap kategori
|
// Memoize columns untuk setiap kategori
|
||||||
const docBroilerColumns = useMemo(
|
const docColumns = useMemo(
|
||||||
() =>
|
() =>
|
||||||
isResponseSuccess(sapronakCalculation)
|
isResponseSuccess(sapronakCalculation)
|
||||||
? createColumns(sapronakCalculation.data?.doc_broiler.total)
|
? createColumns(sapronakCalculation.data?.doc?.total)
|
||||||
: createColumns(),
|
: createColumns(),
|
||||||
[sapronakCalculation]
|
[sapronakCalculation]
|
||||||
);
|
);
|
||||||
@@ -139,7 +164,7 @@ const ClosingSapronakCalculationTable = ({
|
|||||||
const ovkColumns = useMemo(
|
const ovkColumns = useMemo(
|
||||||
() =>
|
() =>
|
||||||
isResponseSuccess(sapronakCalculation)
|
isResponseSuccess(sapronakCalculation)
|
||||||
? createColumns(sapronakCalculation.data?.ovk.total)
|
? createColumns(sapronakCalculation.data?.ovk?.total)
|
||||||
: createColumns(),
|
: createColumns(),
|
||||||
[sapronakCalculation]
|
[sapronakCalculation]
|
||||||
);
|
);
|
||||||
@@ -147,15 +172,20 @@ const ClosingSapronakCalculationTable = ({
|
|||||||
const pakanColumns = useMemo(
|
const pakanColumns = useMemo(
|
||||||
() =>
|
() =>
|
||||||
isResponseSuccess(sapronakCalculation)
|
isResponseSuccess(sapronakCalculation)
|
||||||
? createColumns(sapronakCalculation.data?.pakan.total)
|
? createColumns(sapronakCalculation.data?.pakan?.total)
|
||||||
: createColumns(),
|
: createColumns(),
|
||||||
[sapronakCalculation]
|
[sapronakCalculation]
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='flex flex-col gap-4'>
|
<div className='flex flex-col gap-4'>
|
||||||
|
{/* Table DOC jika kategori Project Flock Growing */}
|
||||||
<Card
|
<Card
|
||||||
title='DOC Broiler'
|
title={
|
||||||
|
closingGeneralInformation?.project_type == 'GROWING'
|
||||||
|
? 'DOC'
|
||||||
|
: 'Pullet'
|
||||||
|
}
|
||||||
collapsible
|
collapsible
|
||||||
defaultCollapsed={false}
|
defaultCollapsed={false}
|
||||||
className={{
|
className={{
|
||||||
@@ -166,14 +196,17 @@ const ClosingSapronakCalculationTable = ({
|
|||||||
<Table<RowSapronakCalculation>
|
<Table<RowSapronakCalculation>
|
||||||
data={
|
data={
|
||||||
isResponseSuccess(sapronakCalculation)
|
isResponseSuccess(sapronakCalculation)
|
||||||
? (sapronakCalculation.data?.doc_broiler.rows ?? [])
|
? (sapronakCalculation.data?.doc?.rows ?? [])
|
||||||
: []
|
: []
|
||||||
}
|
}
|
||||||
columns={docBroilerColumns}
|
columns={docColumns}
|
||||||
className={{
|
className={{
|
||||||
containerClassName: 'my-4',
|
containerClassName: 'my-4',
|
||||||
}}
|
}}
|
||||||
renderFooter={isResponseSuccess(sapronakCalculation)}
|
renderFooter={
|
||||||
|
isResponseSuccess(sapronakCalculation) &&
|
||||||
|
sapronakCalculation.data?.doc?.rows.length > 0
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
@@ -189,14 +222,17 @@ const ClosingSapronakCalculationTable = ({
|
|||||||
<Table<RowSapronakCalculation>
|
<Table<RowSapronakCalculation>
|
||||||
data={
|
data={
|
||||||
isResponseSuccess(sapronakCalculation)
|
isResponseSuccess(sapronakCalculation)
|
||||||
? (sapronakCalculation.data?.ovk.rows ?? [])
|
? (sapronakCalculation.data?.ovk?.rows ?? [])
|
||||||
: []
|
: []
|
||||||
}
|
}
|
||||||
columns={ovkColumns}
|
columns={ovkColumns}
|
||||||
className={{
|
className={{
|
||||||
containerClassName: 'my-4',
|
containerClassName: 'my-4',
|
||||||
}}
|
}}
|
||||||
renderFooter={isResponseSuccess(sapronakCalculation)}
|
renderFooter={
|
||||||
|
isResponseSuccess(sapronakCalculation) &&
|
||||||
|
sapronakCalculation.data?.ovk?.rows.length > 0
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
@@ -212,14 +248,17 @@ const ClosingSapronakCalculationTable = ({
|
|||||||
<Table<RowSapronakCalculation>
|
<Table<RowSapronakCalculation>
|
||||||
data={
|
data={
|
||||||
isResponseSuccess(sapronakCalculation)
|
isResponseSuccess(sapronakCalculation)
|
||||||
? (sapronakCalculation.data?.pakan.rows ?? [])
|
? (sapronakCalculation.data?.pakan?.rows ?? [])
|
||||||
: []
|
: []
|
||||||
}
|
}
|
||||||
columns={pakanColumns}
|
columns={pakanColumns}
|
||||||
className={{
|
className={{
|
||||||
containerClassName: 'my-4',
|
containerClassName: 'my-4',
|
||||||
}}
|
}}
|
||||||
renderFooter={isResponseSuccess(sapronakCalculation)}
|
renderFooter={
|
||||||
|
isResponseSuccess(sapronakCalculation) &&
|
||||||
|
sapronakCalculation.data?.pakan?.rows.length > 0
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ import SelectInput, {
|
|||||||
import RowDropdownOptions from '@/components/table/RowDropdownOptions';
|
import RowDropdownOptions from '@/components/table/RowDropdownOptions';
|
||||||
import RowCollapseOptions from '@/components/table/RowCollapseOptions';
|
import RowCollapseOptions from '@/components/table/RowCollapseOptions';
|
||||||
import RowOptionsMenuWrapper from '@/components/table/RowOptionsMenuWrapper';
|
import RowOptionsMenuWrapper from '@/components/table/RowOptionsMenuWrapper';
|
||||||
|
import RequirePermission from '@/components/helper/RequirePermission';
|
||||||
|
|
||||||
import { cn, formatCurrency, formatDate } from '@/lib/helper';
|
import { cn, formatCurrency, formatDate } from '@/lib/helper';
|
||||||
import { isResponseSuccess } from '@/lib/api-helper';
|
import { isResponseSuccess } from '@/lib/api-helper';
|
||||||
import { useTableFilter } from '@/services/hooks/useTableFilter';
|
import { useTableFilter } from '@/services/hooks/useTableFilter';
|
||||||
@@ -43,17 +45,18 @@ const RowOptionsMenu = ({
|
|||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
<RowOptionsMenuWrapper type={type}>
|
<RowOptionsMenuWrapper type={type}>
|
||||||
{/* TODO: apply RBAC */}
|
|
||||||
<div className='w-full max-h-40 overflow-auto flex flex-col gap-1'>
|
<div className='w-full max-h-40 overflow-auto flex flex-col gap-1'>
|
||||||
<Button
|
<RequirePermission permissions='lti.closing.detail'>
|
||||||
href={`/closing/detail/?closingId=${props.row.original.id}`}
|
<Button
|
||||||
variant='ghost'
|
href={`/closing/detail/?closingId=${props.row.original.id}`}
|
||||||
color='primary'
|
variant='ghost'
|
||||||
className='justify-start text-sm'
|
color='primary'
|
||||||
>
|
className='justify-start text-sm'
|
||||||
<Icon icon='mdi:eye-outline' width={16} height={16} />
|
>
|
||||||
Detail
|
<Icon icon='mdi:eye-outline' width={16} height={16} />
|
||||||
</Button>
|
Detail
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
</div>
|
</div>
|
||||||
</RowOptionsMenuWrapper>
|
</RowOptionsMenuWrapper>
|
||||||
);
|
);
|
||||||
@@ -123,28 +126,6 @@ const ClosingsTable = () => {
|
|||||||
accessorKey: 'shed_label',
|
accessorKey: 'shed_label',
|
||||||
header: 'Jumlah Kandang',
|
header: 'Jumlah Kandang',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
accessorKey: 'sales_paid_amount',
|
|
||||||
header: 'Jumlah Sudah Bayar',
|
|
||||||
cell: (props) => (
|
|
||||||
<span className='text-success'>
|
|
||||||
{formatCurrency(props.row.original.sales_paid_amount)}
|
|
||||||
</span>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'sales_remaining_amount',
|
|
||||||
header: 'Jumlah Sisa Bayar',
|
|
||||||
cell: (props) => (
|
|
||||||
<span className='text-error'>
|
|
||||||
{formatCurrency(props.row.original.sales_remaining_amount)}
|
|
||||||
</span>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'sales_payment_status',
|
|
||||||
header: 'Status Pembayaran',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
accessorKey: 'project_status',
|
accessorKey: 'project_status',
|
||||||
header: 'Status',
|
header: 'Status',
|
||||||
|
|||||||
@@ -215,31 +215,31 @@ const SalesReportTable = ({
|
|||||||
return kandang?.name || '-';
|
return kandang?.name || '-';
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
// {
|
||||||
id: 'payment_status',
|
// id: 'payment_status',
|
||||||
accessorKey: 'payment_status',
|
// accessorKey: 'payment_status',
|
||||||
header: 'Status Pembayaran',
|
// header: 'Status Pembayaran',
|
||||||
cell: (props) => {
|
// cell: (props) => {
|
||||||
const status = props.getValue() as string;
|
// const status = props.getValue() as string;
|
||||||
const getStatusColor = (status: string) => {
|
// const getStatusColor = (status: string) => {
|
||||||
if (!status) return 'neutral';
|
// if (!status) return 'neutral';
|
||||||
switch (status.toLowerCase()) {
|
// switch (status.toLowerCase()) {
|
||||||
case 'paid':
|
// case 'paid':
|
||||||
return 'success';
|
// return 'success';
|
||||||
case 'tempo':
|
// case 'tempo':
|
||||||
return 'warning';
|
// return 'warning';
|
||||||
default:
|
// default:
|
||||||
return 'neutral';
|
// return 'neutral';
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
|
|
||||||
return (
|
// return (
|
||||||
<Badge variant='soft' size='sm' color={getStatusColor(status)}>
|
// <Badge variant='soft' size='sm' color={getStatusColor(status)}>
|
||||||
{status || '-'}
|
// {status || '-'}
|
||||||
</Badge>
|
// </Badge>
|
||||||
);
|
// );
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
],
|
],
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,491 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import Button from '@/components/Button';
|
||||||
|
import { Icon } from '@iconify/react';
|
||||||
|
import Modal, { useModal } from '@/components/Modal';
|
||||||
|
import DateInput from '@/components/input/DateInput';
|
||||||
|
import SelectInput, {
|
||||||
|
OptionType,
|
||||||
|
useSelect,
|
||||||
|
} from '@/components/input/SelectInput';
|
||||||
|
import { useState } from 'react';
|
||||||
|
import useSWR from 'swr';
|
||||||
|
import { DashboardApi } from '@/services/api/dashboard';
|
||||||
|
import { useFormik } from 'formik';
|
||||||
|
import { ProjectFlockApi } from '@/services/api/production';
|
||||||
|
import { KandangApi, LocationApi } from '@/services/api/master-data';
|
||||||
|
|
||||||
|
import {
|
||||||
|
DashboardFilterType,
|
||||||
|
getDashboardFilterSchema,
|
||||||
|
} from '@/components/pages/dashboard/filter/DashboardProductionFilter.schema';
|
||||||
|
import DashboardLineChart from '@/components/pages/dashboard/chart/DashboardLineChart';
|
||||||
|
import DashboardLineChartSkeleton from '@/components/pages/dashboard/skeleton/DashboardLineChartSkeleton';
|
||||||
|
import { RadioGroup, RadioGroupItem } from '@/components/input/RadioInput';
|
||||||
|
import {
|
||||||
|
DashboardFilter,
|
||||||
|
DashboardMeta,
|
||||||
|
} from '@/types/api/dashboard/dashboard';
|
||||||
|
import DashboardStats from '@/components/pages/dashboard/chart/DashboardStats';
|
||||||
|
import { isResponseSuccess } from '@/lib/api-helper';
|
||||||
|
import AlertErrorList from '@/components/helper/form/FormErrors';
|
||||||
|
import { useFormikErrorList } from '@/services/hooks/useFormikErrorList';
|
||||||
|
|
||||||
|
// Helper function to normalize values to array
|
||||||
|
const normalizeToArray = (
|
||||||
|
value: OptionType | OptionType[] | null | undefined
|
||||||
|
): number[] => {
|
||||||
|
if (!value) return [];
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
return value.map((v) => Number(v.value));
|
||||||
|
}
|
||||||
|
return [Number(value.value)];
|
||||||
|
};
|
||||||
|
|
||||||
|
const DashboardProduction = () => {
|
||||||
|
const filterModal = useModal();
|
||||||
|
const [analysisMode, setAnalysisMode] = useState<'OVERVIEW' | 'COMPARISON'>(
|
||||||
|
'OVERVIEW'
|
||||||
|
);
|
||||||
|
const [endpointUrl, setEndpointUrl] = useState('/dashboards');
|
||||||
|
const [selectedLocationIds, setSelectedLocationIds] = useState<number[]>([]);
|
||||||
|
|
||||||
|
// ===== FETCH DATA =====
|
||||||
|
const {
|
||||||
|
data: dashboardProductionResponse,
|
||||||
|
isLoading: isLoadingDashboardProductionData,
|
||||||
|
mutate: refreshDashboardProductionData,
|
||||||
|
} = useSWR(endpointUrl, () =>
|
||||||
|
DashboardApi.getDashboardProductionFetcher(endpointUrl)
|
||||||
|
);
|
||||||
|
|
||||||
|
const dashboardProductionData = isResponseSuccess(dashboardProductionResponse)
|
||||||
|
? dashboardProductionResponse.data
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
// ===== SELECT =====
|
||||||
|
const { options: flockOptions, isLoadingOptions: isLoadingFlockOptions } =
|
||||||
|
useSelect(ProjectFlockApi.basePath, 'id', 'flock_name', '', {
|
||||||
|
limit: 'limit',
|
||||||
|
location_id: selectedLocationIds ? selectedLocationIds.toString() : '',
|
||||||
|
});
|
||||||
|
const {
|
||||||
|
options: locationOptions,
|
||||||
|
isLoadingOptions: isLoadingLocationOptions,
|
||||||
|
} = useSelect(LocationApi.basePath, 'id', 'name', '', {
|
||||||
|
limit: 'limit',
|
||||||
|
});
|
||||||
|
const { options: kandangOptions, isLoadingOptions: isLoadingKandangOptions } =
|
||||||
|
useSelect(KandangApi.basePath, 'id', 'name', '', {
|
||||||
|
limit: 'limit',
|
||||||
|
location_id: selectedLocationIds ? selectedLocationIds.toString() : '',
|
||||||
|
});
|
||||||
|
const comparisonTypeOptions = [
|
||||||
|
{ value: 'FARM', label: 'Farm' },
|
||||||
|
{ value: 'FLOCK', label: 'Flock' },
|
||||||
|
{ value: 'KANDANG', label: 'Kandang' },
|
||||||
|
];
|
||||||
|
|
||||||
|
// ===== FORMIK =====
|
||||||
|
const formik = useFormik({
|
||||||
|
initialValues: {
|
||||||
|
startDate: '',
|
||||||
|
endDate: '',
|
||||||
|
flock: [] as OptionType[],
|
||||||
|
location: [] as OptionType[],
|
||||||
|
kandang: [] as OptionType[],
|
||||||
|
analysisMode: analysisMode,
|
||||||
|
comparisonType: '',
|
||||||
|
lokasiIds: [],
|
||||||
|
flockIds: [],
|
||||||
|
kandangIds: [],
|
||||||
|
} as DashboardFilterType,
|
||||||
|
validationSchema: getDashboardFilterSchema(analysisMode),
|
||||||
|
onSubmit: (values) => {
|
||||||
|
console.log(values);
|
||||||
|
|
||||||
|
handleApplyFilter({
|
||||||
|
start_date: values.startDate || '',
|
||||||
|
end_date: values.endDate || '',
|
||||||
|
analysis_mode: values.analysisMode as 'OVERVIEW' | 'COMPARISON',
|
||||||
|
location_ids: normalizeToArray(values.location),
|
||||||
|
flock_ids: normalizeToArray(values.flock),
|
||||||
|
kandang_ids: normalizeToArray(values.kandang),
|
||||||
|
comparison_type: values.comparisonType,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleResetFilter = () => {
|
||||||
|
formik.resetForm();
|
||||||
|
setAnalysisMode('OVERVIEW');
|
||||||
|
setEndpointUrl('/dashboards');
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleApplyFilter = (values: DashboardFilter) => {
|
||||||
|
console.log(values);
|
||||||
|
|
||||||
|
// Build query params object, only include non-empty values
|
||||||
|
const params: Record<string, string> = {};
|
||||||
|
|
||||||
|
if (values.start_date) params.start_date = values.start_date;
|
||||||
|
if (values.end_date) params.end_date = values.end_date;
|
||||||
|
if (values.analysis_mode) params.analysis_mode = values.analysis_mode;
|
||||||
|
if (values.location_ids.length > 0)
|
||||||
|
params.location_ids = values.location_ids.toString();
|
||||||
|
if (values.flock_ids.length > 0)
|
||||||
|
params.flock_ids = values.flock_ids.toString();
|
||||||
|
if (values.kandang_ids.length > 0)
|
||||||
|
params.kandang_ids = values.kandang_ids.toString();
|
||||||
|
if (values.comparison_type) params.comparison_type = values.comparison_type;
|
||||||
|
|
||||||
|
setEndpointUrl(`/dashboards?${new URLSearchParams(params).toString()}`);
|
||||||
|
console.log(endpointUrl);
|
||||||
|
filterModal.closeModal();
|
||||||
|
refreshDashboardProductionData();
|
||||||
|
formik.resetForm();
|
||||||
|
};
|
||||||
|
|
||||||
|
// ===== Formik Error List =====
|
||||||
|
const { formErrorList, close, handleFormSubmit } = useFormikErrorList(formik);
|
||||||
|
|
||||||
|
if (isLoadingDashboardProductionData) {
|
||||||
|
return (
|
||||||
|
<div className='w-full min-h-screen flex items-center justify-center'>
|
||||||
|
<span className='loading loading-spinner loading-xl'></span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<section className='w-full p-4 space-y-6'>
|
||||||
|
<div className='flex flex-col sm:flex-row items-center justify-between gap-4'>
|
||||||
|
<div></div>
|
||||||
|
<div className='flex flex-row justify-end gap-2'>
|
||||||
|
<Button
|
||||||
|
variant='outline'
|
||||||
|
className={`min-w-28 rounded-lg ${
|
||||||
|
isResponseSuccess(dashboardProductionResponse) &&
|
||||||
|
(dashboardProductionResponse.meta as unknown as DashboardMeta)
|
||||||
|
.filters
|
||||||
|
? 'bg-gradient-to-r from-blue-50 to-blue-100 border-blue-500 text-blue-600 hover:from-blue-100 hover:to-blue-200'
|
||||||
|
: ''
|
||||||
|
}`}
|
||||||
|
onClick={() => filterModal.openModal()}
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
icon='heroicons:funnel'
|
||||||
|
width={20}
|
||||||
|
height={20}
|
||||||
|
className={
|
||||||
|
isResponseSuccess(dashboardProductionResponse) &&
|
||||||
|
(dashboardProductionResponse.meta as unknown as DashboardMeta)
|
||||||
|
.filters
|
||||||
|
? 'text-blue-600'
|
||||||
|
: ''
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
Filter
|
||||||
|
{isResponseSuccess(dashboardProductionResponse) &&
|
||||||
|
dashboardProductionResponse.meta &&
|
||||||
|
(dashboardProductionResponse.meta as unknown as DashboardMeta)
|
||||||
|
.filters && (
|
||||||
|
<span className='w-6 h-6 text-white bg-red-500 rounded-lg flex items-center justify-center text-xs'>
|
||||||
|
{(() => {
|
||||||
|
const meta =
|
||||||
|
dashboardProductionResponse.meta as unknown as DashboardMeta;
|
||||||
|
if (!meta.filters) return 0;
|
||||||
|
const count =
|
||||||
|
(meta.filters.location_ids.length > 1
|
||||||
|
? meta.filters.location_ids.length
|
||||||
|
: 0) +
|
||||||
|
(meta.filters.flock_ids.length > 1
|
||||||
|
? meta.filters.flock_ids.length
|
||||||
|
: 0) +
|
||||||
|
(meta.filters.kandang_ids.length > 1
|
||||||
|
? meta.filters.kandang_ids.length
|
||||||
|
: 0);
|
||||||
|
return meta.filters.analysis_mode === 'OVERVIEW'
|
||||||
|
? 1
|
||||||
|
: count;
|
||||||
|
})()}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant='outline'
|
||||||
|
color='neutral'
|
||||||
|
className='min-w-28 rounded-lg'
|
||||||
|
>
|
||||||
|
<Icon icon='heroicons:arrow-down-tray' width={20} height={20} />
|
||||||
|
Export
|
||||||
|
<Icon icon='heroicons:chevron-down' width={20} height={20} />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Dashboard Stats */}
|
||||||
|
<DashboardStats data={dashboardProductionData?.statistics_data ?? []} />
|
||||||
|
|
||||||
|
{/* Use DashboardLineChart component or skeleton */}
|
||||||
|
{isLoadingDashboardProductionData ? (
|
||||||
|
<DashboardLineChartSkeleton />
|
||||||
|
) : dashboardProductionData &&
|
||||||
|
dashboardProductionData.charts &&
|
||||||
|
Object.keys(dashboardProductionData.charts).length > 0 ? (
|
||||||
|
<DashboardLineChart
|
||||||
|
analysisMode={
|
||||||
|
isResponseSuccess(dashboardProductionResponse)
|
||||||
|
? dashboardProductionResponse.meta
|
||||||
|
? (
|
||||||
|
dashboardProductionResponse.meta as unknown as DashboardMeta
|
||||||
|
).filters?.analysis_mode
|
||||||
|
: analysisMode
|
||||||
|
: analysisMode
|
||||||
|
}
|
||||||
|
data={dashboardProductionData}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<DashboardLineChartSkeleton
|
||||||
|
meta={
|
||||||
|
isResponseSuccess(dashboardProductionResponse)
|
||||||
|
? (dashboardProductionResponse.meta as unknown as DashboardMeta)
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
ref={filterModal.ref}
|
||||||
|
className={{
|
||||||
|
modal: 'p-0',
|
||||||
|
modalBox: 'p-0 rounded-xl',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div className='space-y-6'>
|
||||||
|
{/* Modal Header */}
|
||||||
|
<div className='flex items-center justify-between gap-2 py-3 border-b border-gray-300'>
|
||||||
|
<div className='flex items-center gap-2 ms-4'>
|
||||||
|
<Icon icon='heroicons:funnel' width={20} height={20} />
|
||||||
|
<h3 className='font-semibold'>Filter Data</h3>
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
variant='link'
|
||||||
|
onClick={() => filterModal.closeModal()}
|
||||||
|
className='text-gray-500 hover:text-gray-700 me-4 '
|
||||||
|
>
|
||||||
|
<Icon icon='heroicons:x-mark' width={20} height={20} />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form
|
||||||
|
className='space-y-4'
|
||||||
|
onSubmit={handleFormSubmit}
|
||||||
|
onReset={handleResetFilter}
|
||||||
|
>
|
||||||
|
{/* Rentang Waktu */}
|
||||||
|
<div className='px-4'>
|
||||||
|
<label className='flex items-center gap-2 mb-3'>Tanggal</label>
|
||||||
|
<div className='flex items-center gap-2'>
|
||||||
|
<DateInput
|
||||||
|
name='startDate'
|
||||||
|
placeholder='Tanggal Mulai'
|
||||||
|
value={formik.values.startDate}
|
||||||
|
errorMessage={formik.errors.startDate}
|
||||||
|
onChange={formik.handleChange}
|
||||||
|
className={{
|
||||||
|
inputWrapper: 'rounded-lg',
|
||||||
|
}}
|
||||||
|
isError={
|
||||||
|
Boolean(formik.errors.startDate) &&
|
||||||
|
Boolean(formik.touched.startDate)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<span className='hidden md:block text-center'>—</span>
|
||||||
|
<DateInput
|
||||||
|
name='endDate'
|
||||||
|
placeholder='Tanggal Akhir'
|
||||||
|
value={formik.values.endDate}
|
||||||
|
errorMessage={formik.errors.endDate}
|
||||||
|
onChange={formik.handleChange}
|
||||||
|
className={{
|
||||||
|
inputWrapper: 'rounded-lg',
|
||||||
|
}}
|
||||||
|
isError={
|
||||||
|
Boolean(formik.errors.endDate) &&
|
||||||
|
Boolean(formik.touched.endDate)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Analysis Mode */}
|
||||||
|
<div className='px-4'>
|
||||||
|
<label className='block mb-3'>Analysis Mode</label>
|
||||||
|
<RadioGroup
|
||||||
|
name='analysisMode'
|
||||||
|
value={formik.values.analysisMode}
|
||||||
|
onChange={(e) => {
|
||||||
|
formik.handleChange(e);
|
||||||
|
setAnalysisMode(e.target.value as 'OVERVIEW' | 'COMPARISON');
|
||||||
|
// Reset all dependent fields when analysis mode changes
|
||||||
|
formik.setFieldValue('location', []);
|
||||||
|
formik.setFieldValue('flock', []);
|
||||||
|
formik.setFieldValue('kandang', []);
|
||||||
|
formik.setFieldValue('comparisonType', '');
|
||||||
|
setSelectedLocationIds([]);
|
||||||
|
}}
|
||||||
|
color='primary'
|
||||||
|
className={{
|
||||||
|
wrapper: 'w-full my-6 font-semibold text-neutral-500',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<RadioGroupItem
|
||||||
|
color='primary'
|
||||||
|
value='OVERVIEW'
|
||||||
|
label='Performance Overview'
|
||||||
|
/>
|
||||||
|
<RadioGroupItem
|
||||||
|
color='primary'
|
||||||
|
value='COMPARISON'
|
||||||
|
label='Performance Comparison'
|
||||||
|
/>
|
||||||
|
</RadioGroup>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{formik.values.analysisMode === 'COMPARISON' && (
|
||||||
|
<div className='px-4'>
|
||||||
|
<SelectInput
|
||||||
|
label='Compared By'
|
||||||
|
value={comparisonTypeOptions.find(
|
||||||
|
(option) => option.value === formik.values.comparisonType
|
||||||
|
)}
|
||||||
|
onChange={(selected) =>
|
||||||
|
formik.setFieldValue(
|
||||||
|
'comparisonType',
|
||||||
|
selected ? (selected as OptionType).value : ''
|
||||||
|
)
|
||||||
|
}
|
||||||
|
errorMessage={formik.errors.comparisonType as string}
|
||||||
|
options={comparisonTypeOptions}
|
||||||
|
isLoading={isLoadingLocationOptions}
|
||||||
|
isError={
|
||||||
|
Boolean(formik.errors.comparisonType) &&
|
||||||
|
Boolean(formik.touched.comparisonType)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Location */}
|
||||||
|
<div className='px-4'>
|
||||||
|
<SelectInput
|
||||||
|
label='Farm'
|
||||||
|
value={formik.values.location}
|
||||||
|
onChange={(selected) => {
|
||||||
|
formik.setFieldValue('location', selected);
|
||||||
|
// Update selectedLocationIds for kandang filter
|
||||||
|
setSelectedLocationIds(normalizeToArray(selected));
|
||||||
|
// Reset dependent fields when location changes
|
||||||
|
formik.setFieldValue('flock', []);
|
||||||
|
formik.setFieldValue('kandang', []);
|
||||||
|
}}
|
||||||
|
errorMessage={formik.errors.location as string}
|
||||||
|
options={locationOptions}
|
||||||
|
isLoading={isLoadingLocationOptions}
|
||||||
|
isMulti={
|
||||||
|
comparisonTypeOptions.find(
|
||||||
|
(option) => option.value === formik.values.comparisonType
|
||||||
|
)?.value === 'FARM'
|
||||||
|
}
|
||||||
|
isError={
|
||||||
|
Boolean(formik.errors.location) &&
|
||||||
|
Boolean(formik.touched.location)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Flock */}
|
||||||
|
{!(
|
||||||
|
formik.values.analysisMode === 'COMPARISON' &&
|
||||||
|
!(
|
||||||
|
formik.values.comparisonType === 'FLOCK' ||
|
||||||
|
formik.values.comparisonType === 'KANDANG'
|
||||||
|
)
|
||||||
|
) && (
|
||||||
|
<div className='px-4'>
|
||||||
|
<SelectInput
|
||||||
|
label='Flock'
|
||||||
|
value={formik.values.flock}
|
||||||
|
onChange={(selected) =>
|
||||||
|
formik.setFieldValue('flock', selected)
|
||||||
|
}
|
||||||
|
errorMessage={formik.errors.flock as string}
|
||||||
|
options={flockOptions}
|
||||||
|
isLoading={isLoadingFlockOptions}
|
||||||
|
isMulti={
|
||||||
|
comparisonTypeOptions.find(
|
||||||
|
(option) => option.value === formik.values.comparisonType
|
||||||
|
)?.value === 'FLOCK'
|
||||||
|
}
|
||||||
|
isError={
|
||||||
|
Boolean(formik.errors.flock) &&
|
||||||
|
Boolean(formik.touched.flock)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Kandang */}
|
||||||
|
{!(
|
||||||
|
formik.values.analysisMode === 'COMPARISON' &&
|
||||||
|
!(formik.values.comparisonType === 'KANDANG')
|
||||||
|
) && (
|
||||||
|
<div className='px-4'>
|
||||||
|
<SelectInput
|
||||||
|
label='Kandang'
|
||||||
|
value={formik.values.kandang}
|
||||||
|
onChange={(selected) =>
|
||||||
|
formik.setFieldValue('kandang', selected)
|
||||||
|
}
|
||||||
|
errorMessage={formik.errors.kandang as string}
|
||||||
|
options={kandangOptions}
|
||||||
|
isLoading={isLoadingKandangOptions}
|
||||||
|
isMulti={
|
||||||
|
comparisonTypeOptions.find(
|
||||||
|
(option) => option.value === formik.values.comparisonType
|
||||||
|
)?.value === 'KANDANG'
|
||||||
|
}
|
||||||
|
isError={
|
||||||
|
Boolean(formik.errors.kandang) &&
|
||||||
|
Boolean(formik.touched.kandang)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<AlertErrorList formErrorList={formErrorList} onClose={close} />
|
||||||
|
|
||||||
|
{/* Action Buttons */}
|
||||||
|
<div className='flex justify-between gap-4 py-4 mt-8 border-t border-gray-300 bg-gray-100'>
|
||||||
|
<Button
|
||||||
|
type='reset'
|
||||||
|
variant='soft'
|
||||||
|
className='ms-4 min-w-36 rounded-lg'
|
||||||
|
onClick={handleResetFilter}
|
||||||
|
>
|
||||||
|
Reset Filter
|
||||||
|
</Button>
|
||||||
|
<Button type='submit' className='me-4 min-w-36 rounded-lg'>
|
||||||
|
Terapkan Filter
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DashboardProduction;
|
||||||
@@ -0,0 +1,545 @@
|
|||||||
|
import Button from '@/components/Button';
|
||||||
|
import Card from '@/components/Card';
|
||||||
|
import Dropdown from '@/components/Dropdown';
|
||||||
|
import Menu from '@/components/menu/Menu';
|
||||||
|
import MenuItem from '@/components/menu/MenuItem';
|
||||||
|
import {
|
||||||
|
Dashboard,
|
||||||
|
DashboardOverviewCharts,
|
||||||
|
DashboardComparisonCharts,
|
||||||
|
DashboardChartsSeries,
|
||||||
|
DashboardChartsDataset,
|
||||||
|
} from '@/types/api/dashboard/dashboard';
|
||||||
|
import { Icon } from '@iconify/react';
|
||||||
|
import { useState, useEffect } from 'react';
|
||||||
|
import {
|
||||||
|
CartesianGrid,
|
||||||
|
Line,
|
||||||
|
LineChart,
|
||||||
|
ResponsiveContainer,
|
||||||
|
Tooltip,
|
||||||
|
XAxis,
|
||||||
|
YAxis,
|
||||||
|
} from 'recharts';
|
||||||
|
|
||||||
|
type DashboardLineChartProps = {
|
||||||
|
analysisMode: 'OVERVIEW' | 'COMPARISON';
|
||||||
|
data: Dashboard;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Type guard to check if charts is DashboardOverviewCharts
|
||||||
|
function isOverviewCharts(
|
||||||
|
charts: DashboardOverviewCharts | DashboardComparisonCharts
|
||||||
|
): charts is DashboardOverviewCharts {
|
||||||
|
return 'deplesi' in charts;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type guard to check if charts is DashboardComparisonCharts
|
||||||
|
function isComparisonCharts(
|
||||||
|
charts: DashboardOverviewCharts | DashboardComparisonCharts
|
||||||
|
): charts is DashboardComparisonCharts {
|
||||||
|
return 'location' in charts || 'flock' in charts || 'kandang' in charts;
|
||||||
|
}
|
||||||
|
|
||||||
|
const lineColors: Record<string, string> = {
|
||||||
|
body_weight: '#10B981',
|
||||||
|
std_body_weight: '#10B981',
|
||||||
|
act_laying: '#1062B9',
|
||||||
|
std_laying: '#1062B9',
|
||||||
|
act_egg_weight: '#10B981',
|
||||||
|
std_egg_weight: '#10B981',
|
||||||
|
act_feed_intake: '#F52419',
|
||||||
|
std_feed_intake: '#F52419',
|
||||||
|
act_uniformity: '#F59E0B',
|
||||||
|
std_uniformity: '#F59E0B',
|
||||||
|
act_fcr: '#10B981',
|
||||||
|
std_fcr: '#10B981',
|
||||||
|
act_fcr_cum: '#F52419',
|
||||||
|
std_fcr_cum: '#10B981',
|
||||||
|
normal: '#10B981',
|
||||||
|
abnormal: '#F52419',
|
||||||
|
act_deplesi: '#10B981',
|
||||||
|
std_deplesi: '#10B981',
|
||||||
|
};
|
||||||
|
|
||||||
|
const defaultLineColors: string[] = [
|
||||||
|
'#10B981',
|
||||||
|
'#1062B9',
|
||||||
|
'#F52419',
|
||||||
|
'#F59E0B',
|
||||||
|
'#7F56D9',
|
||||||
|
];
|
||||||
|
|
||||||
|
// Helper function to get line color
|
||||||
|
const getLineColor = (
|
||||||
|
seriesId: string | number,
|
||||||
|
index: number,
|
||||||
|
mode: 'OVERVIEW' | 'COMPARISON'
|
||||||
|
): string => {
|
||||||
|
// For COMPARISON mode, use default colors with cycling
|
||||||
|
if (mode === 'COMPARISON') {
|
||||||
|
return defaultLineColors[index % defaultLineColors.length];
|
||||||
|
}
|
||||||
|
|
||||||
|
// For OVERVIEW mode, use predefined colors or fallback to default
|
||||||
|
const predefinedColor = lineColors[seriesId];
|
||||||
|
if (predefinedColor) {
|
||||||
|
return predefinedColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback to default colors with cycling
|
||||||
|
return defaultLineColors[index % defaultLineColors.length];
|
||||||
|
};
|
||||||
|
|
||||||
|
const DashboardLineChart = ({
|
||||||
|
analysisMode,
|
||||||
|
data,
|
||||||
|
}: DashboardLineChartProps) => {
|
||||||
|
const [chartData, setChartData] =
|
||||||
|
useState<keyof DashboardOverviewCharts>('body_weight');
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
// Track which series are visible (by series id)
|
||||||
|
const [visibleSeries, setVisibleSeries] = useState<Set<string | number>>(
|
||||||
|
new Set()
|
||||||
|
);
|
||||||
|
|
||||||
|
// Mapping for chart type labels
|
||||||
|
const chartTypeLabels: Record<keyof DashboardOverviewCharts, string> = {
|
||||||
|
body_weight: 'Body Weight',
|
||||||
|
performance: 'Performance',
|
||||||
|
fcr: 'FCR',
|
||||||
|
quality_control: 'Quality Control',
|
||||||
|
deplesi: 'Deplesi',
|
||||||
|
};
|
||||||
|
|
||||||
|
// Initialize all series as visible when chartData changes
|
||||||
|
useEffect(() => {
|
||||||
|
let seriesData: DashboardChartsSeries[] = [];
|
||||||
|
|
||||||
|
if (analysisMode === 'OVERVIEW' && isOverviewCharts(data.charts)) {
|
||||||
|
seriesData = data.charts[chartData]?.series || [];
|
||||||
|
} else if (
|
||||||
|
analysisMode === 'COMPARISON' &&
|
||||||
|
isComparisonCharts(data.charts)
|
||||||
|
) {
|
||||||
|
const comparisonChart =
|
||||||
|
data.charts.location || data.charts.flock || data.charts.kandang;
|
||||||
|
seriesData = comparisonChart?.series || [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set all series as visible by default
|
||||||
|
const allSeriesIds = new Set(seriesData.map((s) => s.id));
|
||||||
|
setVisibleSeries(allSeriesIds);
|
||||||
|
}, [chartData, analysisMode, data.charts]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card
|
||||||
|
className={{
|
||||||
|
wrapper: 'w-full rounded-lg',
|
||||||
|
}}
|
||||||
|
variant='bordered'
|
||||||
|
>
|
||||||
|
<div className='flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4 mb-6'>
|
||||||
|
<div className='text-lg font-semibold'>
|
||||||
|
Performance{' '}
|
||||||
|
<Icon
|
||||||
|
icon='heroicons:information-circle'
|
||||||
|
width={20}
|
||||||
|
height={20}
|
||||||
|
className='inline text-neutral-500'
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{analysisMode == 'OVERVIEW' && (
|
||||||
|
<Dropdown
|
||||||
|
align='end'
|
||||||
|
direction='bottom'
|
||||||
|
trigger={
|
||||||
|
<Button
|
||||||
|
variant='outline'
|
||||||
|
color='none'
|
||||||
|
className='text-neutral-500 hover:text-neutral-700 rounded-lg px-4 py-2 border-neutral-300'
|
||||||
|
onClick={() => setOpen(!open)}
|
||||||
|
>
|
||||||
|
{chartTypeLabels[chartData]}{' '}
|
||||||
|
<div className='divider divider-horizontal p-0 m-0 before:bg-neutral-300 after:bg-neutral-300'></div>
|
||||||
|
<Icon icon='heroicons:chevron-down' width={20} height={20} />
|
||||||
|
</Button>
|
||||||
|
}
|
||||||
|
className={{
|
||||||
|
content: 'w-52 mt-3',
|
||||||
|
}}
|
||||||
|
controlled={open}
|
||||||
|
>
|
||||||
|
<Menu>
|
||||||
|
<MenuItem
|
||||||
|
title='Body weight'
|
||||||
|
onClick={() => {
|
||||||
|
setChartData('body_weight');
|
||||||
|
setOpen(!open);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<MenuItem
|
||||||
|
title='Performance'
|
||||||
|
onClick={() => {
|
||||||
|
setChartData('performance');
|
||||||
|
setOpen(!open);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<MenuItem
|
||||||
|
title='FCR'
|
||||||
|
onClick={() => {
|
||||||
|
setChartData('fcr');
|
||||||
|
setOpen(!open);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<MenuItem
|
||||||
|
title='Quality Control'
|
||||||
|
onClick={() => {
|
||||||
|
setChartData('quality_control');
|
||||||
|
setOpen(!open);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<MenuItem
|
||||||
|
title='Deplesi'
|
||||||
|
onClick={() => {
|
||||||
|
setChartData('deplesi');
|
||||||
|
setOpen(!open);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Menu>
|
||||||
|
</Dropdown>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Legend - Dynamic based on series data */}
|
||||||
|
<div className='flex flex-wrap gap-3 mb-6'>
|
||||||
|
{(() => {
|
||||||
|
// Get series data based on current mode and chartData
|
||||||
|
let seriesData: DashboardChartsSeries[] = [];
|
||||||
|
|
||||||
|
if (analysisMode === 'OVERVIEW' && isOverviewCharts(data.charts)) {
|
||||||
|
seriesData = data.charts[chartData]?.series || [];
|
||||||
|
} else if (
|
||||||
|
analysisMode === 'COMPARISON' &&
|
||||||
|
isComparisonCharts(data.charts)
|
||||||
|
) {
|
||||||
|
const comparisonChart =
|
||||||
|
data.charts.location || data.charts.flock || data.charts.kandang;
|
||||||
|
seriesData = comparisonChart?.series || [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return seriesData.map((series, index) => {
|
||||||
|
const isVisible = visibleSeries.has(series.id);
|
||||||
|
const isStandard = series.id
|
||||||
|
.toString()
|
||||||
|
.toLowerCase()
|
||||||
|
.includes('std');
|
||||||
|
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
key={series.id}
|
||||||
|
onClick={() => {
|
||||||
|
const newVisible = new Set(visibleSeries);
|
||||||
|
if (isVisible) {
|
||||||
|
newVisible.delete(series.id);
|
||||||
|
} else {
|
||||||
|
newVisible.add(series.id);
|
||||||
|
}
|
||||||
|
setVisibleSeries(newVisible);
|
||||||
|
}}
|
||||||
|
className={`flex items-center gap-2 px-3 py-2 rounded-lg border transition-colors ${
|
||||||
|
isVisible
|
||||||
|
? 'border-neutral-400 bg-neutral-50'
|
||||||
|
: 'border-neutral-300 hover:bg-neutral-50'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className={`w-6 h-0.5 ${
|
||||||
|
isStandard ? 'border-t-2 border-dashed' : ''
|
||||||
|
} ${!isVisible ? 'opacity-30' : ''}`}
|
||||||
|
style={{
|
||||||
|
backgroundColor: isStandard
|
||||||
|
? 'transparent'
|
||||||
|
: getLineColor(series.id, index, analysisMode),
|
||||||
|
borderColor: isStandard
|
||||||
|
? getLineColor(series.id, index, analysisMode)
|
||||||
|
: 'transparent',
|
||||||
|
}}
|
||||||
|
></div>
|
||||||
|
<span
|
||||||
|
className={`text-sm ${isVisible ? 'text-neutral-900 font-medium' : 'text-neutral-700'}`}
|
||||||
|
>
|
||||||
|
{series.label}
|
||||||
|
</span>
|
||||||
|
<Icon
|
||||||
|
icon='heroicons:information-circle'
|
||||||
|
width={16}
|
||||||
|
height={16}
|
||||||
|
className='text-neutral-400'
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
})()}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Chart */}
|
||||||
|
<ResponsiveContainer width='100%' height={350}>
|
||||||
|
<LineChart
|
||||||
|
data={(() => {
|
||||||
|
// Transform data based on analysisMode
|
||||||
|
if (analysisMode === 'OVERVIEW') {
|
||||||
|
// For OVERVIEW mode, use the selected chart data
|
||||||
|
if (isOverviewCharts(data.charts)) {
|
||||||
|
const selectedChartData = data.charts[chartData];
|
||||||
|
if (!selectedChartData || !selectedChartData.dataset) return [];
|
||||||
|
return selectedChartData.dataset;
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
} else {
|
||||||
|
// For COMPARISON mode, use the first available comparison chart
|
||||||
|
if (isComparisonCharts(data.charts)) {
|
||||||
|
const chartData =
|
||||||
|
data.charts.location ||
|
||||||
|
data.charts.flock ||
|
||||||
|
data.charts.kandang;
|
||||||
|
|
||||||
|
if (!chartData || !chartData.dataset) return [];
|
||||||
|
return chartData.dataset;
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
})()}
|
||||||
|
margin={{
|
||||||
|
top: 5,
|
||||||
|
right: 10,
|
||||||
|
left: 0,
|
||||||
|
bottom: 5,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<CartesianGrid strokeDasharray='3 3' stroke='#e5e7eb' />
|
||||||
|
<XAxis
|
||||||
|
dataKey='week'
|
||||||
|
tick={{ fontSize: 11, fill: '#9ca3af' }}
|
||||||
|
tickLine={false}
|
||||||
|
axisLine={{ stroke: '#e5e7eb' }}
|
||||||
|
label={{
|
||||||
|
value: 'Weeks',
|
||||||
|
position: 'insideBottom',
|
||||||
|
offset: -5,
|
||||||
|
style: { fontSize: 12, fill: '#9ca3af' },
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<YAxis
|
||||||
|
tick={{ fontSize: 11, fill: '#9ca3af' }}
|
||||||
|
tickLine={false}
|
||||||
|
axisLine={{ stroke: '#e5e7eb' }}
|
||||||
|
domain={(() => {
|
||||||
|
// Calculate dynamic domain based on visible data
|
||||||
|
let seriesData: DashboardChartsSeries[] = [];
|
||||||
|
let dataset: DashboardChartsDataset[] = [];
|
||||||
|
|
||||||
|
if (
|
||||||
|
analysisMode === 'OVERVIEW' &&
|
||||||
|
isOverviewCharts(data.charts)
|
||||||
|
) {
|
||||||
|
seriesData = data.charts[chartData]?.series || [];
|
||||||
|
dataset = data.charts[chartData]?.dataset || [];
|
||||||
|
} else if (
|
||||||
|
analysisMode === 'COMPARISON' &&
|
||||||
|
isComparisonCharts(data.charts)
|
||||||
|
) {
|
||||||
|
const comparisonChart =
|
||||||
|
data.charts.location ||
|
||||||
|
data.charts.flock ||
|
||||||
|
data.charts.kandang;
|
||||||
|
seriesData = comparisonChart?.series || [];
|
||||||
|
dataset = comparisonChart?.dataset || [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get all values from visible series
|
||||||
|
const visibleSeriesIds = Array.from(visibleSeries);
|
||||||
|
const allValues: number[] = [];
|
||||||
|
|
||||||
|
dataset.forEach((item: DashboardChartsDataset) => {
|
||||||
|
visibleSeriesIds.forEach((seriesId) => {
|
||||||
|
const value = item[seriesId];
|
||||||
|
if (typeof value === 'number') {
|
||||||
|
allValues.push(value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
if (allValues.length === 0) return [0, 100];
|
||||||
|
|
||||||
|
const minValue = Math.min(...allValues);
|
||||||
|
const maxValue = Math.max(...allValues);
|
||||||
|
|
||||||
|
// Add padding (10% on each side)
|
||||||
|
const padding = (maxValue - minValue) * 0.1;
|
||||||
|
const domainMin = Math.floor(Math.max(0, minValue - padding));
|
||||||
|
const domainMax = Math.ceil(maxValue + padding);
|
||||||
|
|
||||||
|
return [domainMin, domainMax];
|
||||||
|
})()}
|
||||||
|
ticks={(() => {
|
||||||
|
// Calculate dynamic ticks based on domain
|
||||||
|
let seriesData: DashboardChartsSeries[] = [];
|
||||||
|
let dataset: DashboardChartsDataset[] = [];
|
||||||
|
|
||||||
|
if (
|
||||||
|
analysisMode === 'OVERVIEW' &&
|
||||||
|
isOverviewCharts(data.charts)
|
||||||
|
) {
|
||||||
|
seriesData = data.charts[chartData]?.series || [];
|
||||||
|
dataset = data.charts[chartData]?.dataset || [];
|
||||||
|
} else if (
|
||||||
|
analysisMode === 'COMPARISON' &&
|
||||||
|
isComparisonCharts(data.charts)
|
||||||
|
) {
|
||||||
|
const comparisonChart =
|
||||||
|
data.charts.location ||
|
||||||
|
data.charts.flock ||
|
||||||
|
data.charts.kandang;
|
||||||
|
seriesData = comparisonChart?.series || [];
|
||||||
|
dataset = comparisonChart?.dataset || [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const visibleSeriesIds = Array.from(visibleSeries);
|
||||||
|
const allValues: number[] = [];
|
||||||
|
|
||||||
|
dataset.forEach((item: DashboardChartsDataset) => {
|
||||||
|
visibleSeriesIds.forEach((seriesId) => {
|
||||||
|
const value = item[seriesId];
|
||||||
|
if (typeof value === 'number') {
|
||||||
|
allValues.push(value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
if (allValues.length === 0) return [0, 25, 50, 75, 100];
|
||||||
|
|
||||||
|
const minValue = Math.min(...allValues);
|
||||||
|
const maxValue = Math.max(...allValues);
|
||||||
|
const padding = (maxValue - minValue) * 0.1;
|
||||||
|
const domainMin = Math.floor(Math.max(0, minValue - padding));
|
||||||
|
const domainMax = Math.ceil(maxValue + padding);
|
||||||
|
|
||||||
|
// Generate 5 evenly spaced ticks
|
||||||
|
const range = domainMax - domainMin;
|
||||||
|
const step = range / 4;
|
||||||
|
|
||||||
|
return [
|
||||||
|
domainMin,
|
||||||
|
Math.round(domainMin + step),
|
||||||
|
Math.round(domainMin + step * 2),
|
||||||
|
Math.round(domainMin + step * 3),
|
||||||
|
domainMax,
|
||||||
|
];
|
||||||
|
})()}
|
||||||
|
/>
|
||||||
|
<Tooltip
|
||||||
|
contentStyle={{
|
||||||
|
backgroundColor: '#1f2937',
|
||||||
|
border: 'none',
|
||||||
|
borderRadius: '8px',
|
||||||
|
padding: '8px 12px',
|
||||||
|
color: 'white',
|
||||||
|
}}
|
||||||
|
labelStyle={{ color: 'white', marginBottom: '4px' }}
|
||||||
|
itemStyle={{ color: 'white', fontSize: '12px' }}
|
||||||
|
labelFormatter={(value) => `Week ${value}`}
|
||||||
|
formatter={(
|
||||||
|
value: number | undefined,
|
||||||
|
name: string | undefined
|
||||||
|
) => {
|
||||||
|
if (value === undefined || name === undefined) return ['', ''];
|
||||||
|
|
||||||
|
// Get series data to find the unit
|
||||||
|
let seriesData: DashboardChartsSeries[] = [];
|
||||||
|
if (
|
||||||
|
analysisMode === 'OVERVIEW' &&
|
||||||
|
isOverviewCharts(data.charts)
|
||||||
|
) {
|
||||||
|
seriesData = data.charts[chartData]?.series || [];
|
||||||
|
} else if (
|
||||||
|
analysisMode === 'COMPARISON' &&
|
||||||
|
isComparisonCharts(data.charts)
|
||||||
|
) {
|
||||||
|
const comparisonChart =
|
||||||
|
data.charts.location ||
|
||||||
|
data.charts.flock ||
|
||||||
|
data.charts.kandang;
|
||||||
|
seriesData = comparisonChart?.series || [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find the series that matches this line's name
|
||||||
|
const series = seriesData.find((s) => s.label === name);
|
||||||
|
const unit = series?.unit || '';
|
||||||
|
|
||||||
|
return [`${value} ${unit}`, name];
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{/* Dynamic Line rendering based on visible series */}
|
||||||
|
{(() => {
|
||||||
|
let seriesData: DashboardChartsSeries[] = [];
|
||||||
|
|
||||||
|
if (analysisMode === 'OVERVIEW' && isOverviewCharts(data.charts)) {
|
||||||
|
seriesData = data.charts[chartData]?.series || [];
|
||||||
|
} else if (
|
||||||
|
analysisMode === 'COMPARISON' &&
|
||||||
|
isComparisonCharts(data.charts)
|
||||||
|
) {
|
||||||
|
const comparisonChart =
|
||||||
|
data.charts.location ||
|
||||||
|
data.charts.flock ||
|
||||||
|
data.charts.kandang;
|
||||||
|
seriesData = comparisonChart?.series || [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return seriesData
|
||||||
|
.filter((series) => visibleSeries.has(series.id))
|
||||||
|
.map((series, index) => {
|
||||||
|
const isStandard = series.id
|
||||||
|
.toString()
|
||||||
|
.toLowerCase()
|
||||||
|
.includes('std');
|
||||||
|
// Use series.id directly as dataKey to match dataset fields
|
||||||
|
const dataKey = series.id.toString();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Line
|
||||||
|
key={series.id}
|
||||||
|
type='monotone'
|
||||||
|
dataKey={dataKey}
|
||||||
|
name={series.label}
|
||||||
|
stroke={getLineColor(series.id, index, analysisMode)}
|
||||||
|
opacity={isStandard ? 0.5 : 1}
|
||||||
|
strokeWidth={2}
|
||||||
|
strokeDasharray={isStandard ? '5 5' : undefined}
|
||||||
|
dot={
|
||||||
|
isStandard
|
||||||
|
? false
|
||||||
|
: {
|
||||||
|
r: 3,
|
||||||
|
fill: '#fff',
|
||||||
|
stroke: getLineColor(
|
||||||
|
series.id,
|
||||||
|
index,
|
||||||
|
analysisMode
|
||||||
|
),
|
||||||
|
strokeWidth: 2,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
activeDot={isStandard ? undefined : { r: 5 }}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
})()}
|
||||||
|
</LineChart>
|
||||||
|
</ResponsiveContainer>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DashboardLineChart;
|
||||||
@@ -0,0 +1,166 @@
|
|||||||
|
import Alert from '@/components/Alert';
|
||||||
|
import Card from '@/components/Card';
|
||||||
|
import { formatNumber } from '@/lib/helper';
|
||||||
|
import { DashboardStatisticsData } from '@/types/api/dashboard/dashboard';
|
||||||
|
import { Icon } from '@iconify/react';
|
||||||
|
|
||||||
|
interface DashboardStatsProps {
|
||||||
|
data: DashboardStatisticsData[];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Konfigurasi untuk setiap kartu
|
||||||
|
const CARD_CONFIG = [
|
||||||
|
{
|
||||||
|
key: 'HPP Global',
|
||||||
|
icon: 'heroicons:banknotes',
|
||||||
|
alertColor: 'warning' as const,
|
||||||
|
suffix: ' /Kg',
|
||||||
|
prefix: 'RP ',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'Avg. Selling Price',
|
||||||
|
icon: 'heroicons:document-currency-dollar',
|
||||||
|
alertColor: 'success' as const,
|
||||||
|
suffix: ' /Kg',
|
||||||
|
prefix: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'FCR',
|
||||||
|
icon: 'heroicons:clipboard-document-list',
|
||||||
|
alertColor: 'info' as const,
|
||||||
|
suffix: '',
|
||||||
|
prefix: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'Mortality',
|
||||||
|
icon: 'heroicons:exclamation-triangle',
|
||||||
|
alertColor: 'error' as const,
|
||||||
|
suffix: ' %',
|
||||||
|
prefix: '',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const DashboardStats = ({ data }: DashboardStatsProps) => {
|
||||||
|
// Helper to get trend icon and color
|
||||||
|
const getTrendDisplay = (percent: number) => {
|
||||||
|
const isPositive = percent >= 0;
|
||||||
|
return {
|
||||||
|
icon: isPositive
|
||||||
|
? 'heroicons:arrow-trending-up'
|
||||||
|
: 'heroicons:arrow-trending-down',
|
||||||
|
color: isPositive ? 'text-success' : 'text-error',
|
||||||
|
value: Math.abs(percent),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Helper to format value
|
||||||
|
const formatValue = (value: number, prefix: string, suffix: string) => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{prefix}
|
||||||
|
{formatNumber(value)}
|
||||||
|
{suffix && (
|
||||||
|
<span className='text-sm font-normal text-neutral-500'>{suffix}</span>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='grid sm:grid-cols-2 xl:grid-cols-4 gap-6'>
|
||||||
|
{CARD_CONFIG.map((config) => {
|
||||||
|
// Find matching data from API
|
||||||
|
const cardData = data.find((item) => item.label === config.key);
|
||||||
|
|
||||||
|
if (!cardData) {
|
||||||
|
// Show placeholder card for missing data (FCR & Mortality)
|
||||||
|
return (
|
||||||
|
<Card
|
||||||
|
key={config.key}
|
||||||
|
className={{
|
||||||
|
wrapper: 'w-full rounded-lg',
|
||||||
|
body: 'p-0',
|
||||||
|
}}
|
||||||
|
variant='bordered'
|
||||||
|
footer={
|
||||||
|
<div className='flex flex-row justify-between px-4 pb-4'>
|
||||||
|
<div className='text-neutral-400 font-semibold text-sm'>
|
||||||
|
From last month
|
||||||
|
</div>
|
||||||
|
<div className='text-neutral-400 font-semibold text-sm'>
|
||||||
|
Filter Required
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<div className='flex flex-row items-center gap-4 px-4 pt-4'>
|
||||||
|
<Alert variant='soft' className='rounded-lg p-3 bg-neutral-100'>
|
||||||
|
<Icon
|
||||||
|
icon={config.icon}
|
||||||
|
width={32}
|
||||||
|
height={32}
|
||||||
|
className='text-neutral-400'
|
||||||
|
/>
|
||||||
|
</Alert>
|
||||||
|
<div>
|
||||||
|
<h3 className='text-neutral-400 font-semibold text-sm'>
|
||||||
|
{config.key}
|
||||||
|
</h3>
|
||||||
|
<p className='text-2xl font-semibold text-neutral-400'>
|
||||||
|
********
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const trend = getTrendDisplay(cardData.percent_last_month);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card
|
||||||
|
key={config.key}
|
||||||
|
className={{
|
||||||
|
wrapper: 'w-full rounded-lg',
|
||||||
|
body: 'p-0',
|
||||||
|
}}
|
||||||
|
variant='bordered'
|
||||||
|
footer={
|
||||||
|
<div className='flex flex-row justify-between px-4 pb-4'>
|
||||||
|
<div className='text-neutral-500 font-semibold text-sm'>
|
||||||
|
From last month
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className={`${trend.color} font-semibold flex flex-row items-center gap-1 text-sm`}
|
||||||
|
>
|
||||||
|
<Icon icon={trend.icon} width={16} height={16} />
|
||||||
|
{trend.value}%
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<div className='flex flex-row items-center gap-4 px-4 pt-4'>
|
||||||
|
<Alert
|
||||||
|
variant='soft'
|
||||||
|
color={config.alertColor}
|
||||||
|
className='rounded-lg p-3'
|
||||||
|
>
|
||||||
|
<Icon icon={config.icon} width={32} height={32} />
|
||||||
|
</Alert>
|
||||||
|
<div>
|
||||||
|
<h3 className='text-neutral-500 font-semibold text-sm'>
|
||||||
|
{cardData.label}
|
||||||
|
</h3>
|
||||||
|
<p className='text-2xl font-semibold'>
|
||||||
|
{formatValue(cardData.value, config.prefix, config.suffix)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DashboardStats;
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
import { OptionType } from '@/components/input/SelectInput';
|
||||||
|
import * as yup from 'yup';
|
||||||
|
|
||||||
|
export type DashboardFilterType = {
|
||||||
|
startDate: string;
|
||||||
|
endDate: string;
|
||||||
|
analysisMode: string;
|
||||||
|
comparisonType: string | undefined;
|
||||||
|
location: OptionType | OptionType[];
|
||||||
|
lokasiIds: number[] | undefined;
|
||||||
|
flock: OptionType | OptionType[] | undefined;
|
||||||
|
flockIds: number[] | undefined;
|
||||||
|
kandang: OptionType | OptionType[] | undefined;
|
||||||
|
kandangIds: number[] | undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Schema untuk mode OVERVIEW - semua field required
|
||||||
|
export const DashboardFilterOverviewSchema: yup.ObjectSchema<DashboardFilterType> =
|
||||||
|
yup.object({
|
||||||
|
startDate: yup.string().required('Start date is required'),
|
||||||
|
endDate: yup.string().required('End date is required'),
|
||||||
|
analysisMode: yup.string().required('Analysis mode is required'),
|
||||||
|
comparisonType: yup.string().when('analysisMode', {
|
||||||
|
is: 'COMPARISON',
|
||||||
|
then: (schema) => schema.required('Compared by is required'),
|
||||||
|
otherwise: (schema) => schema.optional(),
|
||||||
|
}),
|
||||||
|
lokasiIds: yup.array().optional(),
|
||||||
|
flockIds: yup.array().optional(),
|
||||||
|
kandangIds: yup.array().optional(),
|
||||||
|
location: yup
|
||||||
|
.mixed<OptionType | OptionType[]>()
|
||||||
|
.required('Farm is required')
|
||||||
|
.test('is-not-empty', 'Farm is required', (value) => {
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
return value.length > 0;
|
||||||
|
}
|
||||||
|
return !!value;
|
||||||
|
}),
|
||||||
|
flock: yup
|
||||||
|
.mixed<OptionType | OptionType[]>()
|
||||||
|
.required('Flock is required')
|
||||||
|
.test('is-not-empty', 'Flock is required', (value) => {
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
return value.length > 0;
|
||||||
|
}
|
||||||
|
return !!value;
|
||||||
|
}),
|
||||||
|
kandang: yup
|
||||||
|
.mixed<OptionType | OptionType[]>()
|
||||||
|
.required('Kandang is required')
|
||||||
|
.test('is-not-empty', 'Kandang is required', (value) => {
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
return value.length > 0;
|
||||||
|
}
|
||||||
|
return !!value;
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
// Schema untuk mode COMPARISON - conditional validation
|
||||||
|
export const DashboardFilterComparisonSchema: yup.ObjectSchema<DashboardFilterType> =
|
||||||
|
yup.object({
|
||||||
|
startDate: yup.string().required('Start date is required'),
|
||||||
|
endDate: yup.string().required('End date is required'),
|
||||||
|
analysisMode: yup.string().required('Analysis mode is required'),
|
||||||
|
comparisonType: yup.string().when('analysisMode', {
|
||||||
|
is: 'COMPARISON',
|
||||||
|
then: (schema) => schema.required('Compared by is required'),
|
||||||
|
otherwise: (schema) => schema.optional(),
|
||||||
|
}),
|
||||||
|
lokasiIds: yup.array().optional(),
|
||||||
|
flockIds: yup.array().optional(),
|
||||||
|
kandangIds: yup.array().optional(),
|
||||||
|
location: yup
|
||||||
|
.mixed<OptionType | OptionType[]>()
|
||||||
|
.required('Farm is required')
|
||||||
|
.test('is-not-empty', 'Farm is required', (value) => {
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
return value.length > 0;
|
||||||
|
}
|
||||||
|
return !!value;
|
||||||
|
}),
|
||||||
|
flock: yup.mixed<OptionType | OptionType[]>().when('comparisonType', {
|
||||||
|
is: (value: string) => value === 'FLOCK' || value === 'KANDANG',
|
||||||
|
then: (schema) =>
|
||||||
|
schema.test('is-required', 'Flock is required', (value) => {
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
return value.length > 0;
|
||||||
|
}
|
||||||
|
return !!value;
|
||||||
|
}),
|
||||||
|
otherwise: (schema) => schema.optional(),
|
||||||
|
}),
|
||||||
|
kandang: yup.mixed<OptionType | OptionType[]>().when('comparisonType', {
|
||||||
|
is: 'KANDANG',
|
||||||
|
then: (schema) =>
|
||||||
|
schema.test('is-required', 'Kandang is required', (value) => {
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
return value.length > 0;
|
||||||
|
}
|
||||||
|
return !!value;
|
||||||
|
}),
|
||||||
|
otherwise: (schema) => schema.optional(),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
// Helper function untuk mendapatkan schema yang sesuai berdasarkan analysis mode
|
||||||
|
export const getDashboardFilterSchema = (analysisMode?: string) => {
|
||||||
|
return analysisMode === 'OVERVIEW'
|
||||||
|
? DashboardFilterOverviewSchema
|
||||||
|
: DashboardFilterComparisonSchema;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Default schema
|
||||||
|
export const DashboardFilterSchema = DashboardFilterComparisonSchema;
|
||||||
|
|
||||||
|
export type DashboardFilterValues = yup.InferType<typeof DashboardFilterSchema>;
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
import { Icon } from '@iconify/react';
|
||||||
|
import { DashboardMeta } from '@/types/api/dashboard/dashboard';
|
||||||
|
|
||||||
|
const DashboardLineChartSkeleton = ({ meta }: { meta?: DashboardMeta }) => {
|
||||||
|
return (
|
||||||
|
<div className='w-full bg-white rounded-lg shadow-sm border border-gray-200 p-6 relative'>
|
||||||
|
{/* Header with title skeleton */}
|
||||||
|
<div className='text-lg font-semibold'>
|
||||||
|
Performance{' '}
|
||||||
|
<Icon
|
||||||
|
icon='heroicons:information-circle'
|
||||||
|
width={20}
|
||||||
|
height={20}
|
||||||
|
className='inline text-neutral-500'
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Chart area with axes skeleton */}
|
||||||
|
<div className='relative mt-6'>
|
||||||
|
{/* Main chart container */}
|
||||||
|
<div className='flex gap-4'>
|
||||||
|
{/* Y-axis skeleton (left side) */}
|
||||||
|
<div className='flex flex-col justify-between py-4 space-y-4'>
|
||||||
|
{[1, 2, 3, 4, 5, 6].map((item) => (
|
||||||
|
<div
|
||||||
|
key={item}
|
||||||
|
className='h-4 w-12 bg-gray-100 rounded animate-pulse'
|
||||||
|
></div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Chart content area */}
|
||||||
|
<div className='flex-1 relative'>
|
||||||
|
{/* Empty state centered in chart area */}
|
||||||
|
<div className='absolute inset-0 flex flex-col items-center justify-center pb-12'>
|
||||||
|
{!meta?.filters && (
|
||||||
|
<>
|
||||||
|
{/* Filter icon */}
|
||||||
|
<div className='w-12 h-12 bg-blue-500 rounded-xl flex items-center justify-center mb-4'>
|
||||||
|
<Icon
|
||||||
|
icon='heroicons:funnel'
|
||||||
|
className='text-white'
|
||||||
|
width={24}
|
||||||
|
height={24}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Empty state text */}
|
||||||
|
<h3 className='text-gray-900 font-semibold text-base mb-2'>
|
||||||
|
No Filters Selected
|
||||||
|
</h3>
|
||||||
|
<p className='text-gray-500 text-sm text-center max-w-xs'>
|
||||||
|
Please choose filters to narrow down your results and make
|
||||||
|
your search easier.
|
||||||
|
</p>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{meta?.filters && (
|
||||||
|
<>
|
||||||
|
{/* Filter icon */}
|
||||||
|
<div className='w-12 h-12 bg-blue-500 rounded-xl flex items-center justify-center mb-4'>
|
||||||
|
<Icon
|
||||||
|
icon='heroicons:chart-bar'
|
||||||
|
className='text-white'
|
||||||
|
width={24}
|
||||||
|
height={24}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Empty state text */}
|
||||||
|
<h3 className='text-gray-900 font-semibold text-base mb-2'>
|
||||||
|
Data Not Yet Available
|
||||||
|
</h3>
|
||||||
|
<p className='text-gray-500 text-sm text-center max-w-xs'>
|
||||||
|
Please change your filters to get the data.
|
||||||
|
</p>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Placeholder for chart height */}
|
||||||
|
<div className='h-64'></div>
|
||||||
|
|
||||||
|
{/* X-axis skeleton (bottom) */}
|
||||||
|
<div className='flex justify-between pt-4 border-t border-gray-100'>
|
||||||
|
{[1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map((item) => (
|
||||||
|
<div
|
||||||
|
key={item}
|
||||||
|
className='h-4 w-8 bg-gray-100 rounded animate-pulse'
|
||||||
|
></div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DashboardLineChartSkeleton;
|
||||||
@@ -28,7 +28,7 @@ const ExpenseDetail: React.FC<ExpenseDetailProps> = ({ initialValues }) => {
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
initialValues?.latest_approval &&
|
initialValues?.latest_approval &&
|
||||||
initialValues?.latest_approval.step_number >= 4 &&
|
initialValues?.latest_approval.step_number >= 5 &&
|
||||||
initialValues.latest_approval.action !== 'REJECTED'
|
initialValues.latest_approval.action !== 'REJECTED'
|
||||||
) {
|
) {
|
||||||
validTabs.push({
|
validTabs.push({
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import toast from 'react-hot-toast';
|
|||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { Icon } from '@iconify/react';
|
import { Icon } from '@iconify/react';
|
||||||
import Button from '@/components/Button';
|
import Button from '@/components/Button';
|
||||||
|
import RequirePermission from '@/components/helper/RequirePermission';
|
||||||
import Card from '@/components/Card';
|
import Card from '@/components/Card';
|
||||||
import DropFileInput from '@/components/input/DropFileInput';
|
import DropFileInput from '@/components/input/DropFileInput';
|
||||||
|
|
||||||
@@ -15,7 +16,7 @@ import {
|
|||||||
} from '@/components/pages/expense/form/ExpenseRequestForm.schema';
|
} from '@/components/pages/expense/form/ExpenseRequestForm.schema';
|
||||||
import { ExpenseApi } from '@/services/api/expense';
|
import { ExpenseApi } from '@/services/api/expense';
|
||||||
import { isResponseSuccess } from '@/lib/api-helper';
|
import { isResponseSuccess } from '@/lib/api-helper';
|
||||||
import { ACCEPTED_FILE_TYPE } from '@/config/constant';
|
import { ACCEPTED_FILE_TYPE, S3_PUBLIC_BASE_URL } from '@/config/constant';
|
||||||
|
|
||||||
interface ExpenseRealizationContentProps {
|
interface ExpenseRealizationContentProps {
|
||||||
initialValues?: Expense;
|
initialValues?: Expense;
|
||||||
@@ -47,6 +48,13 @@ const ExpenseRealizationContent = ({
|
|||||||
|
|
||||||
const realizationDocumentsChangeHandler = (val: File[]) => {
|
const realizationDocumentsChangeHandler = (val: File[]) => {
|
||||||
formik.setFieldTouched('documents', true);
|
formik.setFieldTouched('documents', true);
|
||||||
|
|
||||||
|
const invalidFiles = val.filter((file) => file.size > 5 * 1024 * 1024);
|
||||||
|
if (invalidFiles.length > 0) {
|
||||||
|
toast.error('Ukuran dokumen maksimal 5 MB!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
formik.setFieldValue('documents', val);
|
formik.setFieldValue('documents', val);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -62,16 +70,17 @@ const ExpenseRealizationContent = ({
|
|||||||
<div>
|
<div>
|
||||||
<div className='w-full max-w-5xl mx-auto flex flex-col sm:flex-row justify-end gap-2'>
|
<div className='w-full max-w-5xl mx-auto flex flex-col sm:flex-row justify-end gap-2'>
|
||||||
<div className='w-full sm:w-fit sm:ml-2 flex flex-row gap-2 items-center'>
|
<div className='w-full sm:w-fit sm:ml-2 flex flex-row gap-2 items-center'>
|
||||||
{/* TODO: apply RBAC */}
|
<RequirePermission permissions='lti.expense.update.realization'>
|
||||||
<Button
|
<Button
|
||||||
type='button'
|
type='button'
|
||||||
color='warning'
|
color='warning'
|
||||||
href={`/expense/realization/edit/?expenseId=${initialValues?.id}`}
|
href={`/expense/realization/edit/?expenseId=${initialValues?.id}`}
|
||||||
className='px-4 grow sm:grow-0'
|
className='px-4 grow sm:grow-0'
|
||||||
>
|
>
|
||||||
<Icon icon='mdi:pencil-outline' width={24} height={24} />
|
<Icon icon='mdi:pencil-outline' width={24} height={24} />
|
||||||
Edit Realisasi
|
Edit Realisasi
|
||||||
</Button>
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -101,59 +110,69 @@ const ExpenseRealizationContent = ({
|
|||||||
initialValues?.realization_docs.length > 0 && (
|
initialValues?.realization_docs.length > 0 && (
|
||||||
<ul className='list-disc'>
|
<ul className='list-disc'>
|
||||||
{initialValues?.realization_docs.map(
|
{initialValues?.realization_docs.map(
|
||||||
(realizationDocument, realizationDocumentIdx) => (
|
(realizationDocument, realizationDocumentIdx) => {
|
||||||
<li key={realizationDocumentIdx}>
|
const path = realizationDocument.path.startsWith(
|
||||||
<Link
|
'/'
|
||||||
href={realizationDocument.path}
|
)
|
||||||
target='_blank'
|
? realizationDocument.path.slice(1)
|
||||||
rel='noopener noreferrer'
|
: realizationDocument.path;
|
||||||
className='text-blue-500 underline'
|
const documentUrl = `${S3_PUBLIC_BASE_URL}/${path}`;
|
||||||
>
|
return (
|
||||||
{realizationDocument.path}{' '}
|
<li key={realizationDocumentIdx}>
|
||||||
<Icon
|
<Link
|
||||||
icon='cuida:open-in-new-tab-outline'
|
href={documentUrl}
|
||||||
width={12}
|
target='_blank'
|
||||||
height={12}
|
rel='noopener noreferrer'
|
||||||
className='inline'
|
className='text-blue-500 underline'
|
||||||
/>
|
>
|
||||||
</Link>
|
{realizationDocument.path}{' '}
|
||||||
</li>
|
<Icon
|
||||||
)
|
icon='cuida:open-in-new-tab-outline'
|
||||||
|
width={12}
|
||||||
|
height={12}
|
||||||
|
className='inline'
|
||||||
|
/>
|
||||||
|
</Link>
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
}
|
||||||
)}
|
)}
|
||||||
</ul>
|
</ul>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className='flex flex-col gap-2'>
|
<RequirePermission permissions='lti.expense.document.realization'>
|
||||||
<DropFileInput
|
<div className='flex flex-col gap-2'>
|
||||||
name='documents'
|
<DropFileInput
|
||||||
values={formik.values.documents}
|
name='documents'
|
||||||
onChange={realizationDocumentsChangeHandler}
|
values={formik.values.documents}
|
||||||
onDelete={realizationDocumentsDeleteHandler}
|
onChange={realizationDocumentsChangeHandler}
|
||||||
accept={{
|
onDelete={realizationDocumentsDeleteHandler}
|
||||||
...ACCEPTED_FILE_TYPE.PDF,
|
accept={{
|
||||||
...ACCEPTED_FILE_TYPE.IMAGE,
|
...ACCEPTED_FILE_TYPE.PDF,
|
||||||
}}
|
...ACCEPTED_FILE_TYPE.IMAGE,
|
||||||
maxFiles={10}
|
}}
|
||||||
className={{
|
maxFiles={10}
|
||||||
wrapper: 'mt-2',
|
className={{
|
||||||
inputWrapper: 'flex items-center',
|
wrapper: 'mt-2',
|
||||||
}}
|
inputWrapper: 'flex items-center',
|
||||||
/>
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
{formik.values.documents &&
|
{formik.values.documents &&
|
||||||
formik.values.documents.length > 0 && (
|
formik.values.documents.length > 0 && (
|
||||||
<Button
|
<Button
|
||||||
onClick={formik.submitForm}
|
onClick={formik.submitForm}
|
||||||
disabled={formik.isSubmitting}
|
disabled={formik.isSubmitting}
|
||||||
isLoading={formik.isSubmitting}
|
isLoading={formik.isSubmitting}
|
||||||
className='w-fit self-end'
|
className='w-fit self-end'
|
||||||
>
|
>
|
||||||
<Icon icon='ic:round-plus' width={24} height={24} />
|
<Icon icon='ic:round-plus' width={24} height={24} />
|
||||||
Tambah
|
Tambah
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
</RequirePermission>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
@@ -207,7 +226,7 @@ const ExpenseRealizationContent = ({
|
|||||||
let expenseGrandTotal = 0;
|
let expenseGrandTotal = 0;
|
||||||
|
|
||||||
kandangExpense.pengajuans?.forEach(
|
kandangExpense.pengajuans?.forEach(
|
||||||
(item) => (expenseGrandTotal += item.price)
|
(item) => (expenseGrandTotal += item.qty * item.price)
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -269,7 +288,7 @@ const ExpenseRealizationContent = ({
|
|||||||
let expenseGrandTotal = 0;
|
let expenseGrandTotal = 0;
|
||||||
|
|
||||||
kandangExpense.realisasi?.forEach(
|
kandangExpense.realisasi?.forEach(
|
||||||
(item) => (expenseGrandTotal += item.price)
|
(item) => (expenseGrandTotal += item.qty * item.price)
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import { useModal } from '@/components/Modal';
|
|||||||
import ConfirmationModal from '@/components/modal/ConfirmationModal';
|
import ConfirmationModal from '@/components/modal/ConfirmationModal';
|
||||||
import ConfirmationModalWithNotes from '@/components/modal/ConfirmationModalWithNotes';
|
import ConfirmationModalWithNotes from '@/components/modal/ConfirmationModalWithNotes';
|
||||||
import ExpensePDFPreviewButton from '@/components/pages/expense//pdf/ExpensePDFButton';
|
import ExpensePDFPreviewButton from '@/components/pages/expense//pdf/ExpensePDFButton';
|
||||||
|
import RequirePermission from '@/components/helper/RequirePermission';
|
||||||
|
|
||||||
import { Expense } from '@/types/api/expense';
|
import { Expense } from '@/types/api/expense';
|
||||||
import { formatCurrency, formatDate } from '@/lib/helper';
|
import { formatCurrency, formatDate } from '@/lib/helper';
|
||||||
@@ -26,7 +27,7 @@ import {
|
|||||||
UploadRequestDocumentsFormSchema,
|
UploadRequestDocumentsFormSchema,
|
||||||
UploadRequestDocumentsFormValues,
|
UploadRequestDocumentsFormValues,
|
||||||
} from '@/components/pages/expense/form/ExpenseRequestForm.schema';
|
} from '@/components/pages/expense/form/ExpenseRequestForm.schema';
|
||||||
import { ACCEPTED_FILE_TYPE } from '@/config/constant';
|
import { ACCEPTED_FILE_TYPE, S3_PUBLIC_BASE_URL } from '@/config/constant';
|
||||||
import { ExpenseApi } from '@/services/api/expense';
|
import { ExpenseApi } from '@/services/api/expense';
|
||||||
import { isResponseSuccess } from '@/lib/api-helper';
|
import { isResponseSuccess } from '@/lib/api-helper';
|
||||||
import { EXPENSE_REQUEST_APPROVAL_LINE } from '@/config/approval-line';
|
import { EXPENSE_REQUEST_APPROVAL_LINE } from '@/config/approval-line';
|
||||||
@@ -58,34 +59,40 @@ const ExpenseRequestContent = ({
|
|||||||
|
|
||||||
const isLatestApprovalRejectedOrDone =
|
const isLatestApprovalRejectedOrDone =
|
||||||
isLatestApprovalRejected ||
|
isLatestApprovalRejected ||
|
||||||
initialValues?.latest_approval.step_number === 5;
|
initialValues?.latest_approval.step_number === 6;
|
||||||
|
|
||||||
const isCurrentApprovalOnManager =
|
const isCurrentApprovalOnHeadArea =
|
||||||
!isLatestApprovalRejected &&
|
!isLatestApprovalRejected &&
|
||||||
initialValues?.latest_approval.step_number === 1;
|
initialValues?.latest_approval.step_number === 1;
|
||||||
|
|
||||||
const isCurrentApprovalOnFinance =
|
const isCurrentApprovalOnUnitVicePresident =
|
||||||
!isLatestApprovalRejected &&
|
!isLatestApprovalRejected &&
|
||||||
initialValues?.latest_approval.step_number === 2;
|
initialValues?.latest_approval.step_number === 2;
|
||||||
|
|
||||||
|
const isCurrentApprovalOnFinance =
|
||||||
|
!isLatestApprovalRejected &&
|
||||||
|
initialValues?.latest_approval.step_number === 3;
|
||||||
|
|
||||||
const isCurrentApprovalOnRealization =
|
const isCurrentApprovalOnRealization =
|
||||||
!isLatestApprovalRejected &&
|
!isLatestApprovalRejected &&
|
||||||
initialValues?.latest_approval.step_number === 4;
|
initialValues?.latest_approval.step_number === 5;
|
||||||
|
|
||||||
const showEditButton =
|
const showEditButton =
|
||||||
initialValues?.latest_approval.step_number !== 5 &&
|
initialValues?.latest_approval.step_number !== 6 &&
|
||||||
(initialValues?.latest_approval.step_number === 1 ||
|
(initialValues?.latest_approval.step_number === 1 ||
|
||||||
initialValues?.latest_approval.step_number === 2 ||
|
initialValues?.latest_approval.step_number === 2 ||
|
||||||
initialValues?.latest_approval.step_number === 3);
|
initialValues?.latest_approval.step_number === 3 ||
|
||||||
|
initialValues?.latest_approval.step_number === 4);
|
||||||
|
|
||||||
const showRejectButton =
|
const showRejectButton =
|
||||||
!isLatestApprovalRejected &&
|
!isLatestApprovalRejected &&
|
||||||
(initialValues?.latest_approval.step_number === 1 ||
|
(initialValues?.latest_approval.step_number === 1 ||
|
||||||
initialValues?.latest_approval.step_number === 2);
|
initialValues?.latest_approval.step_number === 2 ||
|
||||||
|
initialValues?.latest_approval.step_number === 3);
|
||||||
|
|
||||||
const isExpenseCanBeRealized =
|
const isExpenseCanBeRealized =
|
||||||
!isLatestApprovalRejected &&
|
!isLatestApprovalRejected &&
|
||||||
initialValues?.latest_approval.step_number === 3;
|
initialValues?.latest_approval.step_number === 4;
|
||||||
|
|
||||||
// Modal hooks
|
// Modal hooks
|
||||||
const deleteModal = useModal();
|
const deleteModal = useModal();
|
||||||
@@ -139,17 +146,17 @@ const ExpenseRequestContent = ({
|
|||||||
const confirmationModalDeleteClickHandler = async () => {
|
const confirmationModalDeleteClickHandler = async () => {
|
||||||
setIsDeleteLoading(true);
|
setIsDeleteLoading(true);
|
||||||
|
|
||||||
try {
|
const deleteResponse = await ExpenseApi.delete(initialValues?.id as number);
|
||||||
await ExpenseApi.delete(initialValues?.id as number);
|
|
||||||
|
|
||||||
|
if (isResponseSuccess(deleteResponse)) {
|
||||||
toast.success('Berhasil menghapus data biaya operasional!');
|
toast.success('Berhasil menghapus data biaya operasional!');
|
||||||
router.push('/expense');
|
router.push('/expense');
|
||||||
} catch (error) {
|
} else {
|
||||||
toast.error('Gagal menghapus data biaya operasional!');
|
toast.error('Gagal menghapus data biaya operasional!');
|
||||||
} finally {
|
|
||||||
deleteModal.closeModal();
|
|
||||||
setIsDeleteLoading(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deleteModal.closeModal();
|
||||||
|
setIsDeleteLoading(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const confirmationModalCompleteClickHandler = async () => {
|
const confirmationModalCompleteClickHandler = async () => {
|
||||||
@@ -173,8 +180,15 @@ const ExpenseRequestContent = ({
|
|||||||
|
|
||||||
let approveResponse: BaseApiResponse<Expense> | undefined = undefined;
|
let approveResponse: BaseApiResponse<Expense> | undefined = undefined;
|
||||||
|
|
||||||
if (isCurrentApprovalOnManager) {
|
if (isCurrentApprovalOnHeadArea) {
|
||||||
approveResponse = await ExpenseApi.approveManager(
|
approveResponse = await ExpenseApi.approveHeadArea(
|
||||||
|
initialValues.id,
|
||||||
|
notes
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isCurrentApprovalOnUnitVicePresident) {
|
||||||
|
approveResponse = await ExpenseApi.approveUnitVicePresident(
|
||||||
initialValues.id,
|
initialValues.id,
|
||||||
notes
|
notes
|
||||||
);
|
);
|
||||||
@@ -206,8 +220,15 @@ const ExpenseRequestContent = ({
|
|||||||
|
|
||||||
let rejectResponse: BaseApiResponse<Expense> | undefined = undefined;
|
let rejectResponse: BaseApiResponse<Expense> | undefined = undefined;
|
||||||
|
|
||||||
if (isCurrentApprovalOnManager) {
|
if (isCurrentApprovalOnHeadArea) {
|
||||||
rejectResponse = await ExpenseApi.rejectManager(initialValues.id, notes);
|
rejectResponse = await ExpenseApi.rejectHeadArea(initialValues.id, notes);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isCurrentApprovalOnUnitVicePresident) {
|
||||||
|
rejectResponse = await ExpenseApi.rejectUnitVicePresident(
|
||||||
|
initialValues.id,
|
||||||
|
notes
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isCurrentApprovalOnFinance) {
|
if (isCurrentApprovalOnFinance) {
|
||||||
@@ -230,6 +251,13 @@ const ExpenseRequestContent = ({
|
|||||||
|
|
||||||
const requestDocumentsChangeHandler = (val: File[]) => {
|
const requestDocumentsChangeHandler = (val: File[]) => {
|
||||||
formik.setFieldTouched('documents', true);
|
formik.setFieldTouched('documents', true);
|
||||||
|
|
||||||
|
const invalidFiles = val.filter((file) => file.size > 5 * 1024 * 1024);
|
||||||
|
if (invalidFiles.length > 0) {
|
||||||
|
toast.error('Ukuran dokumen maksimal 5 MB!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
formik.setFieldValue('documents', val);
|
formik.setFieldValue('documents', val);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -254,101 +282,135 @@ const ExpenseRequestContent = ({
|
|||||||
{/* TODO: apply RBAC */}
|
{/* TODO: apply RBAC */}
|
||||||
|
|
||||||
<div className='w-full max-w-5xl mx-auto flex flex-col sm:flex-row justify-end gap-2'>
|
<div className='w-full max-w-5xl mx-auto flex flex-col sm:flex-row justify-end gap-2'>
|
||||||
{isCurrentApprovalOnManager && (
|
{isCurrentApprovalOnHeadArea && (
|
||||||
<Button
|
<RequirePermission permissions='lti.expense.approve.head_area'>
|
||||||
variant='outline'
|
<Button
|
||||||
color='info'
|
variant='outline'
|
||||||
onClick={approveClickHandler}
|
color='info'
|
||||||
className='w-full sm:w-fit'
|
onClick={approveClickHandler}
|
||||||
>
|
className='w-full sm:w-fit'
|
||||||
<Icon icon='lucide-lab:farm' width={24} height={24} />
|
>
|
||||||
Approve Manager
|
<Icon icon='lucide-lab:farm' width={24} height={24} />
|
||||||
</Button>
|
Approve Head Area
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{isCurrentApprovalOnUnitVicePresident && (
|
||||||
|
<RequirePermission permissions='lti.expense.approve.unit_vice_president'>
|
||||||
|
<Button
|
||||||
|
variant='outline'
|
||||||
|
color='success'
|
||||||
|
onClick={approveClickHandler}
|
||||||
|
className='w-full sm:w-fit'
|
||||||
|
>
|
||||||
|
<Icon icon='tdesign:money' width={24} height={24} />
|
||||||
|
Approve Unit Vice President
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{isCurrentApprovalOnFinance && (
|
{isCurrentApprovalOnFinance && (
|
||||||
<Button
|
<RequirePermission permissions='lti.expense.approve.finance'>
|
||||||
variant='outline'
|
<Button
|
||||||
color='success'
|
variant='outline'
|
||||||
onClick={approveClickHandler}
|
color='success'
|
||||||
className='w-full sm:w-fit'
|
onClick={approveClickHandler}
|
||||||
>
|
className='w-full sm:w-fit'
|
||||||
<Icon icon='tdesign:money' width={24} height={24} />
|
>
|
||||||
Approve Finance
|
<Icon icon='tdesign:money' width={24} height={24} />
|
||||||
</Button>
|
Approve Finance
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{isCurrentApprovalOnRealization && (
|
{isCurrentApprovalOnRealization && (
|
||||||
<Button
|
<RequirePermission permissions='lti.expense.complete.expense'>
|
||||||
variant='outline'
|
<Button
|
||||||
color='success'
|
variant='outline'
|
||||||
onClick={completeExpenseClickHandler}
|
color='success'
|
||||||
className='w-full sm:w-fit'
|
onClick={completeExpenseClickHandler}
|
||||||
>
|
className='w-full sm:w-fit'
|
||||||
<Icon
|
>
|
||||||
icon='material-symbols:done-all-rounded'
|
<Icon
|
||||||
width={24}
|
icon='material-symbols:done-all-rounded'
|
||||||
height={24}
|
width={24}
|
||||||
/>
|
height={24}
|
||||||
Selesai
|
/>
|
||||||
</Button>
|
Selesai
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{showRejectButton && (
|
{showRejectButton && (
|
||||||
<Button
|
<RequirePermission
|
||||||
variant='outline'
|
permissions={[
|
||||||
color='error'
|
'lti.expense.approve.head_area',
|
||||||
onClick={rejectClickHandler}
|
'lti.expense.approve.unit_vice_president',
|
||||||
className='w-full:w-fit'
|
'lti.expense.approve.finance',
|
||||||
|
]}
|
||||||
>
|
>
|
||||||
<Icon icon='material-symbols:close' width={24} height={24} />
|
<Button
|
||||||
Reject
|
variant='outline'
|
||||||
</Button>
|
color='error'
|
||||||
|
onClick={rejectClickHandler}
|
||||||
|
className='w-full:w-fit'
|
||||||
|
>
|
||||||
|
<Icon icon='material-symbols:close' width={24} height={24} />
|
||||||
|
Reject
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{isExpenseCanBeRealized && (
|
{isExpenseCanBeRealized && (
|
||||||
<Button
|
<RequirePermission permissions='lti.expense.create.realization'>
|
||||||
variant='outline'
|
<Button
|
||||||
color='info'
|
variant='outline'
|
||||||
href={`/expense/realization/?expenseId=${initialValues?.id}`}
|
color='info'
|
||||||
className='w-full sm:w-fit'
|
href={`/expense/realization/?expenseId=${initialValues?.id}`}
|
||||||
>
|
className='w-full sm:w-fit'
|
||||||
<Icon
|
>
|
||||||
icon='material-symbols:money-bag-rounded'
|
<Icon
|
||||||
width={24}
|
icon='material-symbols:money-bag-rounded'
|
||||||
height={24}
|
width={24}
|
||||||
/>
|
height={24}
|
||||||
Realisasi
|
/>
|
||||||
</Button>
|
Realisasi
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className='w-full sm:w-fit sm:ml-2 flex flex-row gap-2 items-center'>
|
<div className='w-full sm:w-fit sm:ml-2 flex flex-row gap-2 items-center'>
|
||||||
{showEditButton && (
|
{showEditButton && (
|
||||||
<Button
|
<RequirePermission permissions='lti.expense.update'>
|
||||||
type='button'
|
<Button
|
||||||
color='warning'
|
type='button'
|
||||||
href={`/expense/detail/edit/?expenseId=${initialValues?.id}`}
|
color='warning'
|
||||||
className='px-4 grow sm:grow-0'
|
href={`/expense/detail/edit/?expenseId=${initialValues?.id}`}
|
||||||
>
|
className='px-4 grow sm:grow-0'
|
||||||
<Icon icon='mdi:pencil-outline' width={24} height={24} />
|
>
|
||||||
Edit
|
<Icon icon='mdi:pencil-outline' width={24} height={24} />
|
||||||
</Button>
|
Edit
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<Button
|
<RequirePermission permissions='lti.expense.delete'>
|
||||||
type='button'
|
<Button
|
||||||
color='error'
|
type='button'
|
||||||
onClick={deleteExpenseClickHandler}
|
color='error'
|
||||||
className='px-4 grow sm:grow-0'
|
onClick={deleteExpenseClickHandler}
|
||||||
>
|
className='px-4 grow sm:grow-0'
|
||||||
<Icon
|
>
|
||||||
icon='material-symbols:delete-outline-rounded'
|
<Icon
|
||||||
width={24}
|
icon='material-symbols:delete-outline-rounded'
|
||||||
height={24}
|
width={24}
|
||||||
className='justify-start text-sm'
|
height={24}
|
||||||
/>
|
className='justify-start text-sm'
|
||||||
Delete
|
/>
|
||||||
</Button>
|
Delete
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -388,9 +450,13 @@ const ExpenseRequestContent = ({
|
|||||||
<th>Kandang</th>
|
<th>Kandang</th>
|
||||||
<th>:</th>
|
<th>:</th>
|
||||||
<td>
|
<td>
|
||||||
{initialValues?.kandangs
|
{initialValues?.kandangs &&
|
||||||
.map((item) => item.name)
|
initialValues?.kandangs.some((k) => k.name)
|
||||||
.join(', ')}
|
? initialValues?.kandangs
|
||||||
|
.filter((item) => item.name)
|
||||||
|
.map((item) => item.name)
|
||||||
|
.join(', ')
|
||||||
|
: '-'}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -428,7 +494,14 @@ const ExpenseRequestContent = ({
|
|||||||
<tr>
|
<tr>
|
||||||
<th>Nominal Biaya</th>
|
<th>Nominal Biaya</th>
|
||||||
<th>:</th>
|
<th>:</th>
|
||||||
<td>{formatCurrency(initialValues?.grand_total ?? 0)}</td>
|
<td>
|
||||||
|
{formatCurrency(
|
||||||
|
initialValues?.latest_approval.step_number === 5 ||
|
||||||
|
initialValues?.latest_approval.step_number === 6
|
||||||
|
? (initialValues?.total_realisasi ?? 0)
|
||||||
|
: (initialValues?.total_pengajuan ?? 0)
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Status Pencairan</th>
|
<th>Status Pencairan</th>
|
||||||
@@ -462,59 +535,73 @@ const ExpenseRequestContent = ({
|
|||||||
initialValues?.documents.length > 0 && (
|
initialValues?.documents.length > 0 && (
|
||||||
<ul className='list-disc'>
|
<ul className='list-disc'>
|
||||||
{initialValues?.documents.map(
|
{initialValues?.documents.map(
|
||||||
(requestDocument, requestDocumentIdx) => (
|
(requestDocument, requestDocumentIdx) => {
|
||||||
<li key={requestDocumentIdx}>
|
const path = requestDocument.path.startsWith(
|
||||||
<Link
|
'/'
|
||||||
href={requestDocument.path}
|
)
|
||||||
target='_blank'
|
? requestDocument.path.slice(1)
|
||||||
rel='noopener noreferrer'
|
: requestDocument.path;
|
||||||
className='text-blue-500 underline'
|
const documentUrl = `${S3_PUBLIC_BASE_URL}/${path}`;
|
||||||
>
|
return (
|
||||||
{requestDocument.path}{' '}
|
<li key={requestDocumentIdx}>
|
||||||
<Icon
|
<Link
|
||||||
icon='cuida:open-in-new-tab-outline'
|
href={documentUrl}
|
||||||
width={12}
|
target='_blank'
|
||||||
height={12}
|
rel='noopener noreferrer'
|
||||||
className='inline'
|
className='text-blue-500 underline'
|
||||||
/>
|
>
|
||||||
</Link>
|
{requestDocument.path}{' '}
|
||||||
</li>
|
<Icon
|
||||||
)
|
icon='cuida:open-in-new-tab-outline'
|
||||||
|
width={12}
|
||||||
|
height={12}
|
||||||
|
className='inline'
|
||||||
|
/>
|
||||||
|
</Link>
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
}
|
||||||
)}
|
)}
|
||||||
</ul>
|
</ul>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className='flex flex-col gap-2'>
|
<RequirePermission permissions='lti.expense.document'>
|
||||||
<DropFileInput
|
<div className='flex flex-col gap-2'>
|
||||||
name='documents'
|
<DropFileInput
|
||||||
values={formik.values.documents}
|
name='documents'
|
||||||
onChange={requestDocumentsChangeHandler}
|
values={formik.values.documents}
|
||||||
onDelete={requestDocumentsDeleteHandler}
|
onChange={requestDocumentsChangeHandler}
|
||||||
accept={{
|
onDelete={requestDocumentsDeleteHandler}
|
||||||
...ACCEPTED_FILE_TYPE.PDF,
|
accept={{
|
||||||
...ACCEPTED_FILE_TYPE.IMAGE,
|
...ACCEPTED_FILE_TYPE.PDF,
|
||||||
}}
|
...ACCEPTED_FILE_TYPE.IMAGE,
|
||||||
maxFiles={10}
|
}}
|
||||||
className={{
|
maxFiles={10}
|
||||||
wrapper: 'mt-2',
|
className={{
|
||||||
inputWrapper: 'flex items-center',
|
wrapper: 'mt-2',
|
||||||
}}
|
inputWrapper: 'flex items-center',
|
||||||
/>
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
{formik.values.documents &&
|
{formik.values.documents &&
|
||||||
formik.values.documents.length > 0 && (
|
formik.values.documents.length > 0 && (
|
||||||
<Button
|
<Button
|
||||||
onClick={formik.submitForm}
|
onClick={formik.submitForm}
|
||||||
disabled={formik.isSubmitting}
|
disabled={formik.isSubmitting}
|
||||||
isLoading={formik.isSubmitting}
|
isLoading={formik.isSubmitting}
|
||||||
className='w-fit self-end'
|
className='w-fit self-end'
|
||||||
>
|
>
|
||||||
<Icon icon='ic:round-plus' width={24} height={24} />
|
<Icon
|
||||||
Tambah
|
icon='ic:round-plus'
|
||||||
</Button>
|
width={24}
|
||||||
)}
|
height={24}
|
||||||
</div>
|
/>
|
||||||
|
Tambah
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</RequirePermission>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
@@ -532,7 +619,7 @@ const ExpenseRequestContent = ({
|
|||||||
let expenseGrandTotal = 0;
|
let expenseGrandTotal = 0;
|
||||||
|
|
||||||
kandangExpense.pengajuans?.forEach(
|
kandangExpense.pengajuans?.forEach(
|
||||||
(item) => (expenseGrandTotal += item.price)
|
(item) => (expenseGrandTotal += item.qty * item.price)
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -547,7 +634,9 @@ const ExpenseRequestContent = ({
|
|||||||
colSpan={5}
|
colSpan={5}
|
||||||
className='font-bold text-center text-base-content text-lg'
|
className='font-bold text-center text-base-content text-lg'
|
||||||
>
|
>
|
||||||
Biaya {kandangExpense.name}
|
{kandangExpense.kandang_id && kandangExpense.name
|
||||||
|
? `Biaya ${kandangExpense.name}`
|
||||||
|
: `Biaya ${initialValues?.location.name || 'Umum'}`}
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ const ExpenseStatusBadge = ({ approval }: ExpenseStatusBadgeProps) => {
|
|||||||
|
|
||||||
switch (latestApprovalStepNumber) {
|
switch (latestApprovalStepNumber) {
|
||||||
case 1:
|
case 1:
|
||||||
expenseStatusPillBadgeColor = 'yellow';
|
expenseStatusPillBadgeColor = 'gray';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
@@ -33,12 +33,16 @@ const ExpenseStatusBadge = ({ approval }: ExpenseStatusBadgeProps) => {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
expenseStatusPillBadgeColor = 'red';
|
expenseStatusPillBadgeColor = 'yellow';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 5:
|
case 5:
|
||||||
expenseStatusPillBadgeColor = 'green';
|
expenseStatusPillBadgeColor = 'green';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 6:
|
||||||
|
expenseStatusPillBadgeColor = 'green';
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLatestApprovalRejected) {
|
if (isLatestApprovalRejected) {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import ExpenseStatusBadge from '@/components/pages/expense/ExpenseStatusBadge';
|
|||||||
import CheckboxInput from '@/components/input/CheckboxInput';
|
import CheckboxInput from '@/components/input/CheckboxInput';
|
||||||
import ConfirmationModalWithNotes from '@/components/modal/ConfirmationModalWithNotes';
|
import ConfirmationModalWithNotes from '@/components/modal/ConfirmationModalWithNotes';
|
||||||
import DateInput from '@/components/input/DateInput';
|
import DateInput from '@/components/input/DateInput';
|
||||||
|
import RequirePermission from '@/components/helper/RequirePermission';
|
||||||
|
|
||||||
import { Expense } from '@/types/api/expense';
|
import { Expense } from '@/types/api/expense';
|
||||||
import { ExpenseApi } from '@/services/api/expense';
|
import { ExpenseApi } from '@/services/api/expense';
|
||||||
@@ -54,71 +55,84 @@ const RowOptionsMenu = ({
|
|||||||
deleteClickHandler: () => void;
|
deleteClickHandler: () => void;
|
||||||
}) => {
|
}) => {
|
||||||
const showEditButton =
|
const showEditButton =
|
||||||
props.row.original.latest_approval.step_number !== 5 &&
|
props.row.original.latest_approval.step_number !== 6 &&
|
||||||
(props.row.original.latest_approval.step_number === 1 ||
|
(props.row.original.latest_approval.step_number === 1 ||
|
||||||
props.row.original.latest_approval.step_number === 2 ||
|
props.row.original.latest_approval.step_number === 2 ||
|
||||||
props.row.original.latest_approval.step_number === 3);
|
props.row.original.latest_approval.step_number === 3 ||
|
||||||
|
props.row.original.latest_approval.step_number === 4);
|
||||||
|
|
||||||
// TODO: apply RBAC
|
// TODO: apply RBAC
|
||||||
const showRealizationButton =
|
const showRealizationButton =
|
||||||
props.row.original.latest_approval.action !== 'REJECTED' &&
|
props.row.original.latest_approval.action !== 'REJECTED' &&
|
||||||
props.row.original.latest_approval.step_number === 3;
|
props.row.original.latest_approval.step_number === 4;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RowOptionsMenuWrapper type={type}>
|
<RowOptionsMenuWrapper type={type}>
|
||||||
<div className='w-full max-h-40 overflow-auto flex flex-col gap-1'>
|
<div className='w-full max-h-40 overflow-auto flex flex-col gap-1'>
|
||||||
<Button
|
<RequirePermission permissions='lti.expense.detail'>
|
||||||
href={`/expense/detail/?expenseId=${props.row.original.id}`}
|
|
||||||
variant='ghost'
|
|
||||||
color='primary'
|
|
||||||
className='justify-start text-sm'
|
|
||||||
>
|
|
||||||
<Icon icon='mdi:eye-outline' width={16} height={16} />
|
|
||||||
Detail
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
{showEditButton && (
|
|
||||||
<Button
|
<Button
|
||||||
href={`/expense/detail/edit/?expenseId=${props.row.original.id}`}
|
href={`/expense/detail/?expenseId=${props.row.original.id}`}
|
||||||
variant='ghost'
|
variant='ghost'
|
||||||
color='warning'
|
color='primary'
|
||||||
className='justify-start text-sm'
|
className='justify-start text-sm'
|
||||||
>
|
>
|
||||||
<Icon icon='material-symbols:edit-outline' width={16} height={16} />
|
<Icon icon='mdi:eye-outline' width={16} height={16} />
|
||||||
Edit
|
Detail
|
||||||
</Button>
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
|
|
||||||
|
{showEditButton && (
|
||||||
|
<RequirePermission permissions='lti.expense.update'>
|
||||||
|
<Button
|
||||||
|
href={`/expense/detail/edit/?expenseId=${props.row.original.id}`}
|
||||||
|
variant='ghost'
|
||||||
|
color='warning'
|
||||||
|
className='justify-start text-sm'
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
icon='material-symbols:edit-outline'
|
||||||
|
width={16}
|
||||||
|
height={16}
|
||||||
|
/>
|
||||||
|
Edit
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{showRealizationButton && (
|
{showRealizationButton && (
|
||||||
<Button
|
<RequirePermission permissions='lti.expense.create.realization'>
|
||||||
href={`/expense/realization/?expenseId=${props.row.original.id}`}
|
<Button
|
||||||
variant='ghost'
|
href={`/expense/realization/?expenseId=${props.row.original.id}`}
|
||||||
color='info'
|
variant='ghost'
|
||||||
className='justify-start text-sm text-info focus-visible:text-info-content hover:text-info-content'
|
color='info'
|
||||||
>
|
className='justify-start text-sm text-info focus-visible:text-info-content hover:text-info-content'
|
||||||
<Icon
|
>
|
||||||
icon='material-symbols:money-bag-rounded'
|
<Icon
|
||||||
width={16}
|
icon='material-symbols:money-bag-rounded'
|
||||||
height={16}
|
width={16}
|
||||||
/>
|
height={16}
|
||||||
Realisasi
|
/>
|
||||||
</Button>
|
Realisasi
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<Button
|
<RequirePermission permissions='lti.expense.delete'>
|
||||||
onClick={deleteClickHandler}
|
<Button
|
||||||
variant='ghost'
|
onClick={deleteClickHandler}
|
||||||
color='error'
|
variant='ghost'
|
||||||
className='justify-start text-sm text-error focus-visible:text-error-content hover:text-error-content'
|
color='error'
|
||||||
>
|
className='justify-start text-sm text-error focus-visible:text-error-content hover:text-error-content'
|
||||||
<Icon
|
>
|
||||||
icon='material-symbols:delete-outline-rounded'
|
<Icon
|
||||||
width={16}
|
icon='material-symbols:delete-outline-rounded'
|
||||||
height={16}
|
width={16}
|
||||||
className='justify-start text-sm'
|
height={16}
|
||||||
/>
|
className='justify-start text-sm'
|
||||||
Delete
|
/>
|
||||||
</Button>
|
Delete
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
</div>
|
</div>
|
||||||
</RowOptionsMenuWrapper>
|
</RowOptionsMenuWrapper>
|
||||||
);
|
);
|
||||||
@@ -180,7 +194,7 @@ const ExpensesTable = () => {
|
|||||||
parseInt(item)
|
parseInt(item)
|
||||||
);
|
);
|
||||||
|
|
||||||
const isAllSelectedRowLatestApprovalOnManager = useMemo(() => {
|
const isAllSelectedRowLatestApprovalOnHeadArea = useMemo(() => {
|
||||||
return selectedRowIds.every((rowId) => {
|
return selectedRowIds.every((rowId) => {
|
||||||
if (!isResponseSuccess(expenses)) return false;
|
if (!isResponseSuccess(expenses)) return false;
|
||||||
|
|
||||||
@@ -189,11 +203,28 @@ const ExpensesTable = () => {
|
|||||||
const isLatestApprovalRejected =
|
const isLatestApprovalRejected =
|
||||||
expenseItem?.latest_approval.action === 'REJECTED';
|
expenseItem?.latest_approval.action === 'REJECTED';
|
||||||
|
|
||||||
const isCurrentApprovalOnManager =
|
const isCurrentApprovalOnHeadArea =
|
||||||
!isLatestApprovalRejected &&
|
!isLatestApprovalRejected &&
|
||||||
expenseItem?.latest_approval.step_number === 1;
|
expenseItem?.latest_approval.step_number === 1;
|
||||||
|
|
||||||
return isCurrentApprovalOnManager;
|
return isCurrentApprovalOnHeadArea;
|
||||||
|
});
|
||||||
|
}, [expenses, selectedRowIds]);
|
||||||
|
|
||||||
|
const isAllSelectedRowLatestApprovalOnUnitVicePresident = useMemo(() => {
|
||||||
|
return selectedRowIds.every((rowId) => {
|
||||||
|
if (!isResponseSuccess(expenses)) return false;
|
||||||
|
|
||||||
|
const expenseItem = expenses.data.find((item) => item.id === rowId);
|
||||||
|
|
||||||
|
const isLatestApprovalRejected =
|
||||||
|
expenseItem?.latest_approval.action === 'REJECTED';
|
||||||
|
|
||||||
|
const isCurrentApprovalOnUnitVicePresident =
|
||||||
|
!isLatestApprovalRejected &&
|
||||||
|
expenseItem?.latest_approval.step_number === 2;
|
||||||
|
|
||||||
|
return isCurrentApprovalOnUnitVicePresident;
|
||||||
});
|
});
|
||||||
}, [expenses, selectedRowIds]);
|
}, [expenses, selectedRowIds]);
|
||||||
|
|
||||||
@@ -208,7 +239,7 @@ const ExpensesTable = () => {
|
|||||||
|
|
||||||
const isCurrentApprovalOnFinance =
|
const isCurrentApprovalOnFinance =
|
||||||
!isLatestApprovalRejected &&
|
!isLatestApprovalRejected &&
|
||||||
expenseItem?.latest_approval.step_number === 2;
|
expenseItem?.latest_approval.step_number === 3;
|
||||||
|
|
||||||
return isCurrentApprovalOnFinance;
|
return isCurrentApprovalOnFinance;
|
||||||
});
|
});
|
||||||
@@ -225,7 +256,7 @@ const ExpensesTable = () => {
|
|||||||
|
|
||||||
const isCurrentApprovalOnRealization =
|
const isCurrentApprovalOnRealization =
|
||||||
!isLatestApprovalRejected &&
|
!isLatestApprovalRejected &&
|
||||||
expenseItem?.latest_approval.step_number === 4;
|
expenseItem?.latest_approval.step_number === 5;
|
||||||
|
|
||||||
return isCurrentApprovalOnRealization;
|
return isCurrentApprovalOnRealization;
|
||||||
});
|
});
|
||||||
@@ -384,7 +415,7 @@ const ExpensesTable = () => {
|
|||||||
) => {
|
) => {
|
||||||
return (
|
return (
|
||||||
row.original.latest_approval.action !== 'REJECTED' &&
|
row.original.latest_approval.action !== 'REJECTED' &&
|
||||||
row.original.latest_approval.step_number !== 5
|
row.original.latest_approval.step_number !== 6
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -407,11 +438,19 @@ const ExpensesTable = () => {
|
|||||||
const confirmationModalDeleteClickHandler = async () => {
|
const confirmationModalDeleteClickHandler = async () => {
|
||||||
setIsDeleteLoading(true);
|
setIsDeleteLoading(true);
|
||||||
|
|
||||||
await ExpenseApi.delete(selectedExpense?.id as number);
|
const deleteResponse = await ExpenseApi.delete(
|
||||||
refreshExpenses();
|
selectedExpense?.id as number
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isResponseSuccess(deleteResponse)) {
|
||||||
|
refreshExpenses();
|
||||||
|
deleteModal.closeModal();
|
||||||
|
toast.success('Berhasil menghapus biaya operasional!');
|
||||||
|
} else {
|
||||||
|
deleteModal.closeModal();
|
||||||
|
toast.error('Gagal menghapus biaya operasional!');
|
||||||
|
}
|
||||||
|
|
||||||
deleteModal.closeModal();
|
|
||||||
toast.success('Berhasil menghapus biaya operasional!');
|
|
||||||
setIsDeleteLoading(false);
|
setIsDeleteLoading(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -420,8 +459,13 @@ const ExpensesTable = () => {
|
|||||||
|
|
||||||
let bulkApproveResponse: BaseApiResponse<Expense> | undefined = undefined;
|
let bulkApproveResponse: BaseApiResponse<Expense> | undefined = undefined;
|
||||||
|
|
||||||
if (isAllSelectedRowLatestApprovalOnManager) {
|
if (isAllSelectedRowLatestApprovalOnHeadArea) {
|
||||||
bulkApproveResponse = await ExpenseApi.bulkApproveManager(
|
bulkApproveResponse = await ExpenseApi.bulkApproveHeadArea(
|
||||||
|
selectedRowIds,
|
||||||
|
notes
|
||||||
|
);
|
||||||
|
} else if (isAllSelectedRowLatestApprovalOnUnitVicePresident) {
|
||||||
|
bulkApproveResponse = await ExpenseApi.bulkApproveUnitVicePresident(
|
||||||
selectedRowIds,
|
selectedRowIds,
|
||||||
notes
|
notes
|
||||||
);
|
);
|
||||||
@@ -457,8 +501,13 @@ const ExpensesTable = () => {
|
|||||||
|
|
||||||
let bulkRejectResponse: BaseApiResponse<Expense> | undefined = undefined;
|
let bulkRejectResponse: BaseApiResponse<Expense> | undefined = undefined;
|
||||||
|
|
||||||
if (isAllSelectedRowLatestApprovalOnManager) {
|
if (isAllSelectedRowLatestApprovalOnHeadArea) {
|
||||||
bulkRejectResponse = await ExpenseApi.bulkRejectManager(
|
bulkRejectResponse = await ExpenseApi.bulkRejectHeadArea(
|
||||||
|
selectedRowIds,
|
||||||
|
notes
|
||||||
|
);
|
||||||
|
} else if (isAllSelectedRowLatestApprovalOnUnitVicePresident) {
|
||||||
|
bulkRejectResponse = await ExpenseApi.bulkRejectUnitVicePresident(
|
||||||
selectedRowIds,
|
selectedRowIds,
|
||||||
notes
|
notes
|
||||||
);
|
);
|
||||||
@@ -559,57 +608,87 @@ const ExpensesTable = () => {
|
|||||||
<div className='flex flex-col gap-2 mb-4'>
|
<div className='flex flex-col gap-2 mb-4'>
|
||||||
<div className='w-full flex flex-col sm:flex-row justify-between items-end sm:items-center gap-4'>
|
<div className='w-full flex flex-col sm:flex-row justify-between items-end sm:items-center gap-4'>
|
||||||
<div className='w-full sm:w-fit flex flex-col sm:flex-row self-start gap-2'>
|
<div className='w-full sm:w-fit flex flex-col sm:flex-row self-start gap-2'>
|
||||||
<Button
|
<RequirePermission permissions='lti.expense.create'>
|
||||||
href='/expense/add'
|
<Button
|
||||||
variant='outline'
|
href='/expense/add'
|
||||||
color='primary'
|
variant='outline'
|
||||||
className='w-full sm:w-fit'
|
color='primary'
|
||||||
>
|
className='w-full sm:w-fit'
|
||||||
<Icon icon='ic:round-plus' width={24} height={24} />
|
>
|
||||||
Tambah
|
<Icon icon='ic:round-plus' width={24} height={24} />
|
||||||
</Button>
|
Tambah
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
|
|
||||||
{selectedRowIds.length > 0 && (
|
{selectedRowIds.length > 0 && (
|
||||||
<>
|
<>
|
||||||
<Button
|
<RequirePermission permissions='lti.expense.approve.head_area'>
|
||||||
variant='outline'
|
<Button
|
||||||
color='info'
|
variant='outline'
|
||||||
onClick={bulkApproveClickHandler}
|
color='info'
|
||||||
disabled={!isAllSelectedRowLatestApprovalOnManager}
|
onClick={bulkApproveClickHandler}
|
||||||
className='w-full sm:w-fit'
|
disabled={!isAllSelectedRowLatestApprovalOnHeadArea}
|
||||||
>
|
className='w-full sm:w-fit'
|
||||||
<Icon icon='lucide-lab:farm' width={24} height={24} />
|
>
|
||||||
Approve Manager
|
<Icon icon='lucide-lab:farm' width={24} height={24} />
|
||||||
</Button>
|
Approve Head Area
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
|
|
||||||
<Button
|
<RequirePermission permissions='lti.expense.approve.unit_vice_president'>
|
||||||
variant='outline'
|
<Button
|
||||||
color='success'
|
variant='outline'
|
||||||
onClick={bulkApproveClickHandler}
|
color='success'
|
||||||
disabled={!isAllSelectedRowLatestApprovalOnFinance}
|
onClick={bulkApproveClickHandler}
|
||||||
className='w-full sm:w-fit'
|
disabled={
|
||||||
>
|
!isAllSelectedRowLatestApprovalOnUnitVicePresident
|
||||||
<Icon icon='tdesign:money' width={24} height={24} />
|
}
|
||||||
Approve Finance
|
className='w-full sm:w-fit'
|
||||||
</Button>
|
>
|
||||||
|
<Icon icon='tdesign:money' width={24} height={24} />
|
||||||
|
Approve Unit Vice President
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
|
|
||||||
<Button
|
<RequirePermission permissions='lti.expense.approve.finance'>
|
||||||
variant='outline'
|
<Button
|
||||||
color='error'
|
variant='outline'
|
||||||
onClick={bulkRejectClickHandler}
|
color='success'
|
||||||
disabled={
|
onClick={bulkApproveClickHandler}
|
||||||
!isAllSelectedRowLatestApprovalOnManager &&
|
disabled={!isAllSelectedRowLatestApprovalOnFinance}
|
||||||
!isAllSelectedRowLatestApprovalOnFinance
|
className='w-full sm:w-fit'
|
||||||
}
|
>
|
||||||
className='w-full sm:w-fit'
|
<Icon icon='tdesign:money' width={24} height={24} />
|
||||||
|
Approve Finance
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
|
|
||||||
|
<RequirePermission
|
||||||
|
permissions={[
|
||||||
|
'lti.expense.approve.head_area',
|
||||||
|
'lti.expense.approve.unit_vice_president',
|
||||||
|
'lti.expense.approve.finance',
|
||||||
|
]}
|
||||||
>
|
>
|
||||||
<Icon
|
<Button
|
||||||
icon='material-symbols:close'
|
variant='outline'
|
||||||
width={24}
|
color='error'
|
||||||
height={24}
|
onClick={bulkRejectClickHandler}
|
||||||
/>
|
disabled={
|
||||||
Reject
|
!isAllSelectedRowLatestApprovalOnHeadArea &&
|
||||||
</Button>
|
!isAllSelectedRowLatestApprovalOnUnitVicePresident &&
|
||||||
|
!isAllSelectedRowLatestApprovalOnFinance
|
||||||
|
}
|
||||||
|
className='w-full sm:w-fit'
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
icon='material-symbols:close'
|
||||||
|
width={24}
|
||||||
|
height={24}
|
||||||
|
/>
|
||||||
|
Reject
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ interface RealizationStatusBadgeProps {
|
|||||||
const RealizationStatusBadge = ({ approval }: RealizationStatusBadgeProps) => {
|
const RealizationStatusBadge = ({ approval }: RealizationStatusBadgeProps) => {
|
||||||
const isLatestApprovalRejected = approval?.action === 'REJECTED';
|
const isLatestApprovalRejected = approval?.action === 'REJECTED';
|
||||||
|
|
||||||
const isExpenseRealized = approval?.step_number && approval.step_number >= 4;
|
const isExpenseRealized = approval?.step_number && approval.step_number >= 5;
|
||||||
|
|
||||||
const realizationStatus = isExpenseRealized
|
const realizationStatus = isExpenseRealized
|
||||||
? 'Sudah Realisasi'
|
? 'Sudah Realisasi'
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ interface ExpenseKandangsTableProps {
|
|||||||
locationId?: number;
|
locationId?: number;
|
||||||
type: 'add' | 'edit' | 'detail';
|
type: 'add' | 'edit' | 'detail';
|
||||||
selectedKandangs: {
|
selectedKandangs: {
|
||||||
id: number;
|
id?: number;
|
||||||
name: string;
|
name?: string;
|
||||||
}[];
|
}[];
|
||||||
onChange: (kandangs: { id: number; name: string }[]) => void;
|
onChange: (kandangs: { id?: number; name?: string }[]) => void;
|
||||||
className?: {
|
className?: {
|
||||||
wrapper?: string;
|
wrapper?: string;
|
||||||
};
|
};
|
||||||
@@ -67,7 +67,11 @@ const ExpenseKandangsTable = ({
|
|||||||
);
|
);
|
||||||
const [sorting, setSorting] = useState<SortingState>([]);
|
const [sorting, setSorting] = useState<SortingState>([]);
|
||||||
const [rowSelection, setRowSelection] = useState<Record<string, boolean>>(
|
const [rowSelection, setRowSelection] = useState<Record<string, boolean>>(
|
||||||
convertRowSelectionArrToObj(selectedKandangs.map((item) => item.id))
|
convertRowSelectionArrToObj(
|
||||||
|
selectedKandangs
|
||||||
|
.map((item) => item.id)
|
||||||
|
.filter((id): id is number => id !== undefined)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
const kandangsColumns: ColumnDef<Kandang>[] = [
|
const kandangsColumns: ColumnDef<Kandang>[] = [
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import * as Yup from 'yup';
|
import * as Yup from 'yup';
|
||||||
import { Expense } from '@/types/api/expense';
|
import { Expense } from '@/types/api/expense';
|
||||||
import { formatDate } from '@/lib/helper';
|
import { formatDate } from '@/lib/helper';
|
||||||
|
import { S3_PUBLIC_BASE_URL } from '@/config/constant';
|
||||||
|
|
||||||
type ExpenseRealizationFormSchemaType = {
|
type ExpenseRealizationFormSchemaType = {
|
||||||
category?: {
|
category?: {
|
||||||
@@ -12,7 +13,7 @@ type ExpenseRealizationFormSchemaType = {
|
|||||||
label: string;
|
label: string;
|
||||||
};
|
};
|
||||||
realization_date?: string;
|
realization_date?: string;
|
||||||
kandangs?: { id: number; name: string }[];
|
kandangs?: { id?: number; name?: string }[];
|
||||||
supplier?: {
|
supplier?: {
|
||||||
value: number;
|
value: number;
|
||||||
label: string;
|
label: string;
|
||||||
@@ -20,7 +21,7 @@ type ExpenseRealizationFormSchemaType = {
|
|||||||
existing_documents?: { name: string; url: string }[];
|
existing_documents?: { name: string; url: string }[];
|
||||||
documents?: File[];
|
documents?: File[];
|
||||||
realizations: {
|
realizations: {
|
||||||
kandang_id: number;
|
kandang_id?: number;
|
||||||
cost_items: {
|
cost_items: {
|
||||||
nonstock?: {
|
nonstock?: {
|
||||||
value: number;
|
value: number;
|
||||||
@@ -49,12 +50,11 @@ export const ExpenseRealizationFormSchema: Yup.ObjectSchema<ExpenseRealizationFo
|
|||||||
kandangs: Yup.array()
|
kandangs: Yup.array()
|
||||||
.of(
|
.of(
|
||||||
Yup.object({
|
Yup.object({
|
||||||
id: Yup.number().required('Kandang wajib dipilih!'),
|
id: Yup.number().optional(),
|
||||||
name: Yup.string().required('Kandang wajib dipilih!'),
|
name: Yup.string().optional(),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.min(1, 'Kandang wajib dipilih!')
|
.optional(),
|
||||||
.required('Kandang wajib dipilih!'),
|
|
||||||
|
|
||||||
supplier: Yup.object({
|
supplier: Yup.object({
|
||||||
value: Yup.number().min(1).required(),
|
value: Yup.number().min(1).required(),
|
||||||
@@ -73,7 +73,7 @@ export const ExpenseRealizationFormSchema: Yup.ObjectSchema<ExpenseRealizationFo
|
|||||||
realizations: Yup.array()
|
realizations: Yup.array()
|
||||||
.of(
|
.of(
|
||||||
Yup.object({
|
Yup.object({
|
||||||
kandang_id: Yup.number().min(1, 'Wajib memilih kandang!').required(),
|
kandang_id: Yup.number().min(1, 'Wajib memilih kandang!').optional(),
|
||||||
cost_items: Yup.array()
|
cost_items: Yup.array()
|
||||||
.of(
|
.of(
|
||||||
Yup.object({
|
Yup.object({
|
||||||
@@ -86,12 +86,12 @@ export const ExpenseRealizationFormSchema: Yup.ObjectSchema<ExpenseRealizationFo
|
|||||||
notes: Yup.string(),
|
notes: Yup.string(),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.min(1, 'Kandang harus memiliki setidaknya 1 biaya!')
|
.min(1, 'Harus memiliki setidaknya 1 biaya!')
|
||||||
.required('Biaya kandang wajib diisi!'),
|
.required('Biaya wajib diisi!'),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.min(1, 'Biaya kandang wajib diisi!')
|
.min(1, 'Biaya wajib diisi!')
|
||||||
.required('Biaya kandang wajib diisi!'),
|
.required('Biaya wajib diisi!'),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const UpdateExpenseRealizationFormSchema = ExpenseRealizationFormSchema;
|
export const UpdateExpenseRealizationFormSchema = ExpenseRealizationFormSchema;
|
||||||
@@ -139,10 +139,13 @@ export const getExpenseRealizationFormInitialValues = (
|
|||||||
label: initialValues.supplier.name,
|
label: initialValues.supplier.name,
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
existing_documents: initialValues?.realization_docs?.map((doc) => ({
|
existing_documents: initialValues?.realization_docs?.map((doc) => {
|
||||||
name: doc.path,
|
const path = doc.path.startsWith('/') ? doc.path.slice(1) : doc.path;
|
||||||
url: doc.path,
|
return {
|
||||||
})),
|
name: doc.path,
|
||||||
|
url: `${S3_PUBLIC_BASE_URL}/${path}`,
|
||||||
|
};
|
||||||
|
}),
|
||||||
documents: [],
|
documents: [],
|
||||||
realizations: initialValues?.kandangs
|
realizations: initialValues?.kandangs
|
||||||
? initialValues.kandangs.map((kandangExpense) => {
|
? initialValues.kandangs.map((kandangExpense) => {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import DateInput from '@/components/input/DateInput';
|
|||||||
import DropFileInput from '@/components/input/DropFileInput';
|
import DropFileInput from '@/components/input/DropFileInput';
|
||||||
import ExpenseKandangsTable from '@/components/pages/expense/form/ExpenseKandangsTable';
|
import ExpenseKandangsTable from '@/components/pages/expense/form/ExpenseKandangsTable';
|
||||||
import ExpenseRealizationKandangDetailExpense from '@/components/pages/expense/form/ExpenseRealizationKandangDetailExpense';
|
import ExpenseRealizationKandangDetailExpense from '@/components/pages/expense/form/ExpenseRealizationKandangDetailExpense';
|
||||||
|
import RequirePermission from '@/components/helper/RequirePermission';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
CreateExpenseRealizationPayload,
|
CreateExpenseRealizationPayload,
|
||||||
@@ -149,25 +150,10 @@ const ExpenseRealizationForm = ({
|
|||||||
formik.setFieldValue('location', val);
|
formik.setFieldValue('location', val);
|
||||||
|
|
||||||
formik.setFieldValue('kandangs', []);
|
formik.setFieldValue('kandangs', []);
|
||||||
formik.setFieldValue('realizations', []);
|
|
||||||
};
|
|
||||||
|
|
||||||
const kandangsChangeHandler = (kandangs: { id: number; name: string }[]) => {
|
// Auto-create realization item for location (without kandang)
|
||||||
formik.setFieldTouched('kandangs', true);
|
formik.setFieldValue('realizations', [
|
||||||
formik.setFieldValue('kandangs', kandangs);
|
{
|
||||||
|
|
||||||
const newRealizations = [...(formik.values.realizations ?? [])];
|
|
||||||
|
|
||||||
// add new realizations
|
|
||||||
kandangs.forEach((kandangItem) => {
|
|
||||||
const isKandangExistInRealization = newRealizations.find(
|
|
||||||
(realizationItem) => realizationItem.kandang_id === kandangItem.id
|
|
||||||
);
|
|
||||||
|
|
||||||
if (isKandangExistInRealization) return;
|
|
||||||
|
|
||||||
newRealizations.push({
|
|
||||||
kandang_id: kandangItem.id,
|
|
||||||
cost_items: [
|
cost_items: [
|
||||||
{
|
{
|
||||||
nonstock: undefined,
|
nonstock: undefined,
|
||||||
@@ -176,25 +162,57 @@ const ExpenseRealizationForm = ({
|
|||||||
notes: '',
|
notes: '',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const kandangsChangeHandler = (
|
||||||
|
kandangs: { id?: number; name?: string }[]
|
||||||
|
) => {
|
||||||
|
formik.setFieldTouched('kandangs', true);
|
||||||
|
formik.setFieldValue('kandangs', kandangs);
|
||||||
|
|
||||||
|
// If no kandangs selected, create realization item for location
|
||||||
|
if (kandangs.length === 0) {
|
||||||
|
formik.setFieldValue('realizations', [
|
||||||
|
{
|
||||||
|
cost_items: [
|
||||||
|
{
|
||||||
|
nonstock: undefined,
|
||||||
|
quantity: undefined,
|
||||||
|
price: undefined,
|
||||||
|
notes: '',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start with empty array when kandangs are selected
|
||||||
|
const newRealizations: typeof formik.values.realizations = [];
|
||||||
|
|
||||||
|
// add new realizations for each kandang
|
||||||
|
kandangs.forEach((kandangItem) => {
|
||||||
|
if (!kandangItem.id) return;
|
||||||
|
|
||||||
|
const existingRealization = formik.values.realizations?.find(
|
||||||
|
(realizationItem) => realizationItem.kandang_id === kandangItem.id
|
||||||
|
);
|
||||||
|
|
||||||
|
newRealizations.push({
|
||||||
|
kandang_id: kandangItem.id,
|
||||||
|
cost_items: existingRealization?.cost_items || [
|
||||||
|
{
|
||||||
|
nonstock: undefined,
|
||||||
|
quantity: undefined,
|
||||||
|
price: undefined,
|
||||||
|
notes: '',
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// prune realizations
|
|
||||||
const kandangIds = new Set(kandangs.map((kandang) => kandang.id));
|
|
||||||
const deletedRealizationsIdx: number[] = [];
|
|
||||||
|
|
||||||
newRealizations.forEach((realization, idx) => {
|
|
||||||
const isRealizationValid = kandangIds.has(realization.kandang_id);
|
|
||||||
|
|
||||||
if (!isRealizationValid) {
|
|
||||||
deletedRealizationsIdx.push(idx);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
deletedRealizationsIdx.forEach((deletedRealizationIdx) => {
|
|
||||||
newRealizations.splice(deletedRealizationIdx, 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
formik.setFieldValue('realizations', newRealizations);
|
formik.setFieldValue('realizations', newRealizations);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -205,6 +223,13 @@ const ExpenseRealizationForm = ({
|
|||||||
|
|
||||||
const realizationDocumentsChangeHandler = (val: File[]) => {
|
const realizationDocumentsChangeHandler = (val: File[]) => {
|
||||||
formik.setFieldTouched('documents', true);
|
formik.setFieldTouched('documents', true);
|
||||||
|
|
||||||
|
const invalidFiles = val.filter((file) => file.size > 5 * 1024 * 1024);
|
||||||
|
if (invalidFiles.length > 0) {
|
||||||
|
toast.error('Ukuran dokumen maksimal 5 MB!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
formik.setFieldValue('documents', val);
|
formik.setFieldValue('documents', val);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -290,21 +315,23 @@ const ExpenseRealizationForm = ({
|
|||||||
className={{ wrapper: 'col-span-12' }}
|
className={{ wrapper: 'col-span-12' }}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<DropFileInput
|
<RequirePermission permissions='lti.expense.document.realization'>
|
||||||
label='Dokumen Realisasi'
|
<DropFileInput
|
||||||
name='documents'
|
label='Dokumen Realisasi'
|
||||||
values={formik.values.documents}
|
name='documents'
|
||||||
onChange={realizationDocumentsChangeHandler}
|
values={formik.values.documents}
|
||||||
onDelete={realizationDocumentsDeleteHandler}
|
onChange={realizationDocumentsChangeHandler}
|
||||||
accept={{
|
onDelete={realizationDocumentsDeleteHandler}
|
||||||
...ACCEPTED_FILE_TYPE.PDF,
|
accept={{
|
||||||
...ACCEPTED_FILE_TYPE.IMAGE,
|
...ACCEPTED_FILE_TYPE.PDF,
|
||||||
}}
|
...ACCEPTED_FILE_TYPE.IMAGE,
|
||||||
className={{
|
}}
|
||||||
wrapper: 'col-span-12',
|
className={{
|
||||||
inputWrapper: 'h-12 flex items-center',
|
wrapper: 'col-span-12',
|
||||||
}}
|
inputWrapper: 'h-12 flex items-center',
|
||||||
/>
|
}}
|
||||||
|
/>
|
||||||
|
</RequirePermission>
|
||||||
|
|
||||||
{formik.values.existing_documents &&
|
{formik.values.existing_documents &&
|
||||||
formik.values.existing_documents.length > 0 && (
|
formik.values.existing_documents.length > 0 && (
|
||||||
@@ -335,7 +362,10 @@ const ExpenseRealizationForm = ({
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
<ExpenseRealizationKandangDetailExpense
|
<ExpenseRealizationKandangDetailExpense
|
||||||
|
type={type}
|
||||||
formik={formik}
|
formik={formik}
|
||||||
|
supplierId={formik.values.supplier?.value as number}
|
||||||
|
location={formik.values.location}
|
||||||
className={{
|
className={{
|
||||||
wrapper: 'col-span-12',
|
wrapper: 'col-span-12',
|
||||||
}}
|
}}
|
||||||
@@ -357,20 +387,22 @@ const ExpenseRealizationForm = ({
|
|||||||
{type !== 'add' && (
|
{type !== 'add' && (
|
||||||
<div className='flex flex-row justify-start gap-2'>
|
<div className='flex flex-row justify-start gap-2'>
|
||||||
{type !== 'edit' && (
|
{type !== 'edit' && (
|
||||||
<Button
|
<RequirePermission permissions='lti.expense.update'>
|
||||||
type='button'
|
<Button
|
||||||
color='warning'
|
type='button'
|
||||||
href={`/expense/detail/edit/?expenseId=${initialValues?.id}`}
|
color='warning'
|
||||||
className='px-4'
|
href={`/expense/detail/edit/?expenseId=${initialValues?.id}`}
|
||||||
>
|
className='px-4'
|
||||||
<Icon
|
>
|
||||||
icon='material-symbols:edit-outline'
|
<Icon
|
||||||
width={24}
|
icon='material-symbols:edit-outline'
|
||||||
height={24}
|
width={24}
|
||||||
className='justify-start text-sm'
|
height={24}
|
||||||
/>
|
className='justify-start text-sm'
|
||||||
Edit
|
/>
|
||||||
</Button>
|
Edit
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -18,6 +18,11 @@ import { Nonstock } from '@/types/api/master-data/nonstock';
|
|||||||
interface ExpenseRealizationKandangDetailExpenseProps {
|
interface ExpenseRealizationKandangDetailExpenseProps {
|
||||||
type?: 'add' | 'edit' | 'detail';
|
type?: 'add' | 'edit' | 'detail';
|
||||||
formik: FormikContextType<ExpenseRealizationFormValues>;
|
formik: FormikContextType<ExpenseRealizationFormValues>;
|
||||||
|
supplierId?: number;
|
||||||
|
location?: {
|
||||||
|
value: number;
|
||||||
|
label: string;
|
||||||
|
};
|
||||||
className?: {
|
className?: {
|
||||||
wrapper?: string;
|
wrapper?: string;
|
||||||
};
|
};
|
||||||
@@ -25,12 +30,18 @@ interface ExpenseRealizationKandangDetailExpenseProps {
|
|||||||
|
|
||||||
const ExpenseRealizationKandangDetailExpense: React.FC<
|
const ExpenseRealizationKandangDetailExpense: React.FC<
|
||||||
ExpenseRealizationKandangDetailExpenseProps
|
ExpenseRealizationKandangDetailExpenseProps
|
||||||
> = ({ type, formik, className }) => {
|
> = ({ type, formik, supplierId, location, className }) => {
|
||||||
const {
|
const {
|
||||||
setInputValue: setNonstockInputValue,
|
setInputValue: setNonstockInputValue,
|
||||||
options: nonstockOptions,
|
options: nonstockOptions,
|
||||||
isLoadingOptions: isLoadingNonstockOptions,
|
isLoadingOptions: isLoadingNonstockOptions,
|
||||||
} = useSelect<Nonstock>(NonstockApi.basePath, 'id', 'name');
|
} = useSelect<Nonstock>(
|
||||||
|
NonstockApi.basePath,
|
||||||
|
'id',
|
||||||
|
'name',
|
||||||
|
'search',
|
||||||
|
supplierId ? { supplier_id: String(supplierId) } : undefined
|
||||||
|
);
|
||||||
|
|
||||||
const nonstockChangeHandler = (
|
const nonstockChangeHandler = (
|
||||||
kandangExpenseIdx: number,
|
kandangExpenseIdx: number,
|
||||||
@@ -82,140 +93,159 @@ const ExpenseRealizationKandangDetailExpense: React.FC<
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className='w-full flex flex-col gap-6'>
|
<div className='w-full flex flex-col gap-6'>
|
||||||
{formik.values.realizations.length === 0 && (
|
{!formik.values.supplier?.value && (
|
||||||
<div>
|
<div>
|
||||||
<p className='text-sm text-gray-400 text-center'>
|
<p className='text-sm text-gray-400 text-center'>
|
||||||
Pilih kandang terlebih dahulu!
|
Pilih supplier terlebih dahulu!
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{formik.values.realizations.map((kandangExpense, kandangExpenseIdx) => {
|
{formik.values.realizations.length === 0 &&
|
||||||
const kandangName = formik.values.kandangs?.find(
|
formik.values.supplier?.value && (
|
||||||
(kandang) => kandang.id === kandangExpense.kandang_id
|
<div>
|
||||||
);
|
<p className='text-sm text-gray-400 text-center'>
|
||||||
|
Belum ada item biaya. Silakan pilih lokasi terlebih dahulu.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
return (
|
{formik.values.realizations.length > 0 &&
|
||||||
kandangName?.name && (
|
formik.values.supplier?.value &&
|
||||||
<div
|
formik.values.realizations.map(
|
||||||
key={`kandangExpense-${kandangExpenseIdx}`}
|
(kandangExpense, kandangExpenseIdx) => {
|
||||||
className='w-full flex flex-col gap-4'
|
const kandangName = kandangExpense.kandang_id
|
||||||
>
|
? formik.values.kandangs?.find(
|
||||||
<div>
|
(kandang) => kandang.id === kandangExpense.kandang_id
|
||||||
<h5 className='mb-2 text-lg font-bold text-center'>
|
)
|
||||||
Biaya {kandangName?.name}
|
: null;
|
||||||
</h5>
|
|
||||||
|
|
||||||
<div className='overflow-x-auto'>
|
return (
|
||||||
<table className='table'>
|
(kandangName?.name || !kandangExpense.kandang_id) && (
|
||||||
<thead>
|
<div
|
||||||
<tr>
|
key={`kandangExpense-${kandangExpenseIdx}`}
|
||||||
<th>Nonstock</th>
|
className='w-full flex flex-col gap-4'
|
||||||
<th>Total Kuantitas</th>
|
>
|
||||||
<th>Harga Satuan</th>
|
<div>
|
||||||
<th>Catatan</th>
|
<h5 className='mb-2 text-lg font-bold text-center'>
|
||||||
</tr>
|
{kandangName?.name
|
||||||
</thead>
|
? `Biaya ${kandangName.name}`
|
||||||
|
: location?.label
|
||||||
|
? `Biaya ${location.label}`
|
||||||
|
: 'Biaya Umum'}
|
||||||
|
</h5>
|
||||||
|
|
||||||
<tbody>
|
<div className='overflow-x-auto'>
|
||||||
{kandangExpense.cost_items.map(
|
<table className='table'>
|
||||||
(expenseItem, expenseIdx) => (
|
<thead>
|
||||||
<tr key={`expense-${expenseIdx}`}>
|
<tr>
|
||||||
<td className='p-2'>
|
<th>Nonstock</th>
|
||||||
<SelectInput
|
<th>Total Kuantitas</th>
|
||||||
placeholder='Pilih Nonstock'
|
<th>Harga Satuan</th>
|
||||||
value={expenseItem.nonstock}
|
<th>Catatan</th>
|
||||||
onChange={(val) => {
|
|
||||||
nonstockChangeHandler(
|
|
||||||
kandangExpenseIdx,
|
|
||||||
expenseIdx,
|
|
||||||
val
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
options={nonstockOptions}
|
|
||||||
isLoading={isLoadingNonstockOptions}
|
|
||||||
onInputChange={setNonstockInputValue}
|
|
||||||
className={{ wrapper: 'min-w-48' }}
|
|
||||||
isDisabled
|
|
||||||
/>
|
|
||||||
</td>
|
|
||||||
|
|
||||||
<td className='p-2'>
|
|
||||||
<NumberInput
|
|
||||||
required
|
|
||||||
name={`realizations[${kandangExpenseIdx}].cost_items[${expenseIdx}].quantity`}
|
|
||||||
placeholder='Masukkan Total Kuantitas'
|
|
||||||
value={
|
|
||||||
formik.values.realizations[
|
|
||||||
kandangExpenseIdx
|
|
||||||
].cost_items[expenseIdx].quantity ?? ''
|
|
||||||
}
|
|
||||||
onChange={formik.handleChange}
|
|
||||||
onBlur={formik.handleBlur}
|
|
||||||
isError={isExpenseRepeaterInputError(
|
|
||||||
'quantity',
|
|
||||||
kandangExpenseIdx,
|
|
||||||
expenseIdx
|
|
||||||
)}
|
|
||||||
className={{ wrapper: 'min-w-24' }}
|
|
||||||
/>
|
|
||||||
</td>
|
|
||||||
|
|
||||||
<td className='p-2'>
|
|
||||||
<NumberInput
|
|
||||||
name={`realizations[${kandangExpenseIdx}].cost_items[${expenseIdx}].price`}
|
|
||||||
placeholder='Masukkan Harga Satuan'
|
|
||||||
value={
|
|
||||||
formik.values.realizations[
|
|
||||||
kandangExpenseIdx
|
|
||||||
].cost_items[expenseIdx].price ?? ''
|
|
||||||
}
|
|
||||||
onChange={formik.handleChange}
|
|
||||||
onBlur={formik.handleBlur}
|
|
||||||
isError={isExpenseRepeaterInputError(
|
|
||||||
'price',
|
|
||||||
kandangExpenseIdx,
|
|
||||||
expenseIdx
|
|
||||||
)}
|
|
||||||
inputPrefix={
|
|
||||||
<span className='text-gray-600 font-medium'>
|
|
||||||
Rp
|
|
||||||
</span>
|
|
||||||
}
|
|
||||||
className={{ wrapper: 'min-w-24' }}
|
|
||||||
/>
|
|
||||||
</td>
|
|
||||||
|
|
||||||
<td className='p-2'>
|
|
||||||
<TextInput
|
|
||||||
name={`realizations[${kandangExpenseIdx}].cost_items[${expenseIdx}].notes`}
|
|
||||||
placeholder='Tuliskan catatan'
|
|
||||||
value={
|
|
||||||
formik.values.realizations[
|
|
||||||
kandangExpenseIdx
|
|
||||||
].cost_items[expenseIdx].notes ?? ''
|
|
||||||
}
|
|
||||||
onChange={formik.handleChange}
|
|
||||||
onBlur={formik.handleBlur}
|
|
||||||
isError={isExpenseRepeaterInputError(
|
|
||||||
'notes',
|
|
||||||
kandangExpenseIdx,
|
|
||||||
expenseIdx
|
|
||||||
)}
|
|
||||||
className={{ wrapper: 'min-w-24' }}
|
|
||||||
/>
|
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
)
|
</thead>
|
||||||
)}
|
|
||||||
</tbody>
|
<tbody>
|
||||||
</table>
|
{kandangExpense.cost_items.map(
|
||||||
|
(expenseItem, expenseIdx) => (
|
||||||
|
<tr key={`expense-${expenseIdx}`}>
|
||||||
|
<td className='p-2'>
|
||||||
|
<SelectInput
|
||||||
|
placeholder='Pilih Nonstock'
|
||||||
|
value={expenseItem.nonstock}
|
||||||
|
onChange={(val) => {
|
||||||
|
nonstockChangeHandler(
|
||||||
|
kandangExpenseIdx,
|
||||||
|
expenseIdx,
|
||||||
|
val
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
options={nonstockOptions}
|
||||||
|
isLoading={isLoadingNonstockOptions}
|
||||||
|
onInputChange={setNonstockInputValue}
|
||||||
|
className={{ wrapper: 'min-w-48' }}
|
||||||
|
isDisabled
|
||||||
|
/>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td className='p-2'>
|
||||||
|
<NumberInput
|
||||||
|
required
|
||||||
|
name={`realizations[${kandangExpenseIdx}].cost_items[${expenseIdx}].quantity`}
|
||||||
|
placeholder='Masukkan Total Kuantitas'
|
||||||
|
value={
|
||||||
|
formik.values.realizations[
|
||||||
|
kandangExpenseIdx
|
||||||
|
].cost_items[expenseIdx].quantity ?? ''
|
||||||
|
}
|
||||||
|
onChange={formik.handleChange}
|
||||||
|
onBlur={formik.handleBlur}
|
||||||
|
isError={isExpenseRepeaterInputError(
|
||||||
|
'quantity',
|
||||||
|
kandangExpenseIdx,
|
||||||
|
expenseIdx
|
||||||
|
)}
|
||||||
|
className={{ wrapper: 'min-w-24' }}
|
||||||
|
/>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td className='p-2'>
|
||||||
|
<NumberInput
|
||||||
|
name={`realizations[${kandangExpenseIdx}].cost_items[${expenseIdx}].price`}
|
||||||
|
placeholder='Masukkan Harga Satuan'
|
||||||
|
value={
|
||||||
|
formik.values.realizations[
|
||||||
|
kandangExpenseIdx
|
||||||
|
].cost_items[expenseIdx].price ?? ''
|
||||||
|
}
|
||||||
|
onChange={formik.handleChange}
|
||||||
|
onBlur={formik.handleBlur}
|
||||||
|
isError={isExpenseRepeaterInputError(
|
||||||
|
'price',
|
||||||
|
kandangExpenseIdx,
|
||||||
|
expenseIdx
|
||||||
|
)}
|
||||||
|
inputPrefix={
|
||||||
|
<span className='text-gray-600 font-medium'>
|
||||||
|
Rp
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
className={{ wrapper: 'min-w-24' }}
|
||||||
|
/>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td className='p-2'>
|
||||||
|
<TextInput
|
||||||
|
name={`realizations[${kandangExpenseIdx}].cost_items[${expenseIdx}].notes`}
|
||||||
|
placeholder='Tuliskan catatan'
|
||||||
|
value={
|
||||||
|
formik.values.realizations[
|
||||||
|
kandangExpenseIdx
|
||||||
|
].cost_items[expenseIdx].notes ?? ''
|
||||||
|
}
|
||||||
|
onChange={formik.handleChange}
|
||||||
|
onBlur={formik.handleBlur}
|
||||||
|
isError={isExpenseRepeaterInputError(
|
||||||
|
'notes',
|
||||||
|
kandangExpenseIdx,
|
||||||
|
expenseIdx
|
||||||
|
)}
|
||||||
|
className={{ wrapper: 'min-w-24' }}
|
||||||
|
/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
)
|
||||||
</div>
|
);
|
||||||
)
|
}
|
||||||
);
|
)}
|
||||||
})}
|
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,32 +1,36 @@
|
|||||||
import * as Yup from 'yup';
|
import * as Yup from 'yup';
|
||||||
import { Expense } from '@/types/api/expense';
|
import { Expense } from '@/types/api/expense';
|
||||||
import { formatDate } from '@/lib/helper';
|
import { formatDate } from '@/lib/helper';
|
||||||
|
import { S3_PUBLIC_BASE_URL } from '@/config/constant';
|
||||||
|
|
||||||
type ExpenseFormSchemaType = {
|
type ExpenseFormSchemaType = {
|
||||||
category?: {
|
category?: {
|
||||||
value: 'BOP' | 'NON-BOP';
|
value: 'BOP' | 'NON-BOP';
|
||||||
label: 'BOP' | 'NON-BOP';
|
label: 'BOP' | 'NON-BOP';
|
||||||
};
|
} | null;
|
||||||
location?: {
|
location?: {
|
||||||
value: number;
|
value: number;
|
||||||
label: string;
|
label: string;
|
||||||
};
|
} | null;
|
||||||
|
location_id: number;
|
||||||
transaction_date?: string;
|
transaction_date?: string;
|
||||||
kandangs?: { id: number; name: string }[];
|
kandangs?: { id?: number; name?: string }[];
|
||||||
supplier?: {
|
supplier?: {
|
||||||
value: number;
|
value: number;
|
||||||
label: string;
|
label: string;
|
||||||
};
|
} | null;
|
||||||
|
supplier_id: number;
|
||||||
existing_documents?: { id: number; name: string; url: string }[];
|
existing_documents?: { id: number; name: string; url: string }[];
|
||||||
deleted_documents?: number[];
|
deleted_documents?: number[];
|
||||||
documents?: File[];
|
documents?: File[];
|
||||||
expense_nonstocks: {
|
expense_nonstocks: {
|
||||||
kandang_id: number;
|
kandang_id?: number;
|
||||||
cost_items: {
|
cost_items: {
|
||||||
nonstock?: {
|
nonstock?: {
|
||||||
value: number;
|
value: number;
|
||||||
label: string;
|
label: string;
|
||||||
};
|
} | null;
|
||||||
|
nonstock_id?: number;
|
||||||
quantity?: number;
|
quantity?: number;
|
||||||
price?: number;
|
price?: number;
|
||||||
notes?: string;
|
notes?: string;
|
||||||
@@ -39,36 +43,54 @@ export const ExpenseRequestFormSchema: Yup.ObjectSchema<ExpenseFormSchemaType> =
|
|||||||
category: Yup.object({
|
category: Yup.object({
|
||||||
value: Yup.string().oneOf(['BOP', 'NON-BOP']).required(),
|
value: Yup.string().oneOf(['BOP', 'NON-BOP']).required(),
|
||||||
label: Yup.string().oneOf(['BOP', 'NON-BOP']).required(),
|
label: Yup.string().oneOf(['BOP', 'NON-BOP']).required(),
|
||||||
}).required('Kategori wajib diisi!'),
|
})
|
||||||
|
.nullable()
|
||||||
|
.optional(),
|
||||||
|
|
||||||
location: Yup.object({
|
location: Yup.object({
|
||||||
value: Yup.number().min(1).required(),
|
value: Yup.number().min(1).required(),
|
||||||
label: Yup.string().required(),
|
label: Yup.string().required(),
|
||||||
}).required('Lokasi wajib diisi!'),
|
})
|
||||||
|
.nullable()
|
||||||
|
.optional(),
|
||||||
|
|
||||||
|
location_id: Yup.number()
|
||||||
|
.required('Lokasi wajib diisi!')
|
||||||
|
.min(1, 'Lokasi wajib diisi!')
|
||||||
|
.typeError('Lokasi wajib diisi!'),
|
||||||
|
|
||||||
transaction_date: Yup.string().required('Tanggal transaksi wajib diisi!'),
|
transaction_date: Yup.string().required('Tanggal transaksi wajib diisi!'),
|
||||||
|
|
||||||
kandangs: Yup.array()
|
kandangs: Yup.array()
|
||||||
.of(
|
.of(
|
||||||
Yup.object({
|
Yup.object({
|
||||||
id: Yup.number().required('Kandang wajib dipilih!'),
|
id: Yup.number().optional(),
|
||||||
name: Yup.string().required('Kandang wajib dipilih!'),
|
name: Yup.string().optional(),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.min(1, 'Kandang wajib dipilih!')
|
.optional(),
|
||||||
.required('Kandang wajib dipilih!'),
|
|
||||||
|
|
||||||
supplier: Yup.object({
|
supplier: Yup.object({
|
||||||
value: Yup.number().min(1).required(),
|
value: Yup.number().min(1).required(),
|
||||||
label: Yup.string().required(),
|
label: Yup.string().required(),
|
||||||
}).required('Vendor wajib diisi!'),
|
})
|
||||||
|
.nullable()
|
||||||
|
.optional(),
|
||||||
|
|
||||||
existing_documents: Yup.array().of(
|
supplier_id: Yup.number()
|
||||||
Yup.object({
|
.required('Vendor wajib diisi!')
|
||||||
id: Yup.number().required(),
|
.min(1, 'Vendor wajib diisi!')
|
||||||
name: Yup.string().required(),
|
.typeError('Vendor wajib diisi!'),
|
||||||
url: Yup.string().required(),
|
|
||||||
})
|
existing_documents: Yup.array()
|
||||||
),
|
.of(
|
||||||
|
Yup.object({
|
||||||
|
id: Yup.number().required(),
|
||||||
|
name: Yup.string().required(),
|
||||||
|
url: Yup.string().required(),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.optional(),
|
||||||
|
|
||||||
deleted_documents: Yup.array().of(Yup.number().required()).optional(),
|
deleted_documents: Yup.array().of(Yup.number().required()).optional(),
|
||||||
|
|
||||||
@@ -77,16 +99,24 @@ export const ExpenseRequestFormSchema: Yup.ObjectSchema<ExpenseFormSchemaType> =
|
|||||||
expense_nonstocks: Yup.array()
|
expense_nonstocks: Yup.array()
|
||||||
.of(
|
.of(
|
||||||
Yup.object({
|
Yup.object({
|
||||||
kandang_id: Yup.number().min(1, 'Wajib memilih kandang!').required(),
|
kandang_id: Yup.number().min(1, 'Wajib memilih kandang!').optional(),
|
||||||
cost_items: Yup.array()
|
cost_items: Yup.array()
|
||||||
.of(
|
.of(
|
||||||
Yup.object({
|
Yup.object({
|
||||||
nonstock: Yup.object({
|
nonstock: Yup.object({
|
||||||
value: Yup.number().min(1).required(),
|
value: Yup.number().min(1).required(),
|
||||||
label: Yup.string().required(),
|
label: Yup.string().required(),
|
||||||
}).required('Nonstock wajib diisi!'),
|
}).nullable(),
|
||||||
quantity: Yup.number().required('Total kuantitas wajib diisi!'),
|
nonstock_id: Yup.number()
|
||||||
price: Yup.number().required('Harga satuan wajib diisi!'),
|
.required('Nonstock wajib diisi!')
|
||||||
|
.min(1, 'Nonstock wajib diisi!')
|
||||||
|
.typeError('Nonstock wajib diisi!'),
|
||||||
|
quantity: Yup.number()
|
||||||
|
.required('Total kuantitas wajib diisi!')
|
||||||
|
.typeError('Total kuantitas wajib diisi!'),
|
||||||
|
price: Yup.number()
|
||||||
|
.required('Harga satuan wajib diisi!')
|
||||||
|
.typeError('Harga satuan wajib diisi!'),
|
||||||
notes: Yup.string(),
|
notes: Yup.string(),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@@ -101,7 +131,16 @@ export const ExpenseRequestFormSchema: Yup.ObjectSchema<ExpenseFormSchemaType> =
|
|||||||
export const UpdateExpenseRequestFormSchema = ExpenseRequestFormSchema;
|
export const UpdateExpenseRequestFormSchema = ExpenseRequestFormSchema;
|
||||||
|
|
||||||
export const UploadRequestDocumentsFormSchema = Yup.object({
|
export const UploadRequestDocumentsFormSchema = Yup.object({
|
||||||
documents: Yup.array().of(Yup.mixed<File>().required()).required(),
|
documents: Yup.array()
|
||||||
|
.of(
|
||||||
|
Yup.mixed<File>()
|
||||||
|
.required()
|
||||||
|
.test('fileSize', 'Ukuran dokumen maksimal 5 MB', (value) => {
|
||||||
|
if (!value || !(value instanceof File)) return true;
|
||||||
|
return value.size <= 5 * 1024 * 1024;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.required(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export type ExpenseRequestFormValues = Yup.InferType<
|
export type ExpenseRequestFormValues = Yup.InferType<
|
||||||
@@ -121,13 +160,14 @@ export const getExpenseFormInitialValues = (
|
|||||||
value: initialValues.category,
|
value: initialValues.category,
|
||||||
label: initialValues.category,
|
label: initialValues.category,
|
||||||
}
|
}
|
||||||
: undefined,
|
: null,
|
||||||
location: initialValues?.location
|
location: initialValues?.location
|
||||||
? {
|
? {
|
||||||
value: initialValues.location.id,
|
value: initialValues.location.id,
|
||||||
label: initialValues.location.name,
|
label: initialValues.location.name,
|
||||||
}
|
}
|
||||||
: undefined,
|
: null,
|
||||||
|
location_id: Number(initialValues?.location.id || 0),
|
||||||
transaction_date: initialValues?.transaction_date
|
transaction_date: initialValues?.transaction_date
|
||||||
? formatDate(initialValues.transaction_date, 'YYYY-MM-DD')
|
? formatDate(initialValues.transaction_date, 'YYYY-MM-DD')
|
||||||
: undefined,
|
: undefined,
|
||||||
@@ -140,12 +180,16 @@ export const getExpenseFormInitialValues = (
|
|||||||
value: initialValues.supplier.id,
|
value: initialValues.supplier.id,
|
||||||
label: initialValues.supplier.name,
|
label: initialValues.supplier.name,
|
||||||
}
|
}
|
||||||
: undefined,
|
: null,
|
||||||
existing_documents: initialValues?.documents?.map((doc) => ({
|
supplier_id: initialValues?.supplier?.id ?? 0,
|
||||||
id: doc.id,
|
existing_documents: initialValues?.documents?.map((doc) => {
|
||||||
name: doc.path,
|
const path = doc.path.startsWith('/') ? doc.path.slice(1) : doc.path;
|
||||||
url: doc.path,
|
return {
|
||||||
})),
|
id: doc.id,
|
||||||
|
name: doc.path,
|
||||||
|
url: `${S3_PUBLIC_BASE_URL}/${path}`,
|
||||||
|
};
|
||||||
|
}),
|
||||||
deleted_documents: [],
|
deleted_documents: [],
|
||||||
documents: [],
|
documents: [],
|
||||||
expense_nonstocks: initialValues?.kandangs
|
expense_nonstocks: initialValues?.kandangs
|
||||||
@@ -157,12 +201,25 @@ export const getExpenseFormInitialValues = (
|
|||||||
value: expenseItem.nonstock.id,
|
value: expenseItem.nonstock.id,
|
||||||
label: expenseItem.nonstock.name,
|
label: expenseItem.nonstock.name,
|
||||||
},
|
},
|
||||||
|
nonstock_id: expenseItem.nonstock.id,
|
||||||
quantity: expenseItem.qty,
|
quantity: expenseItem.qty,
|
||||||
price: expenseItem.price,
|
price: expenseItem.price,
|
||||||
notes: expenseItem.note,
|
notes: expenseItem.note,
|
||||||
}))
|
}))
|
||||||
: [],
|
: [],
|
||||||
}))
|
}))
|
||||||
: [],
|
: [
|
||||||
|
{
|
||||||
|
cost_items: [
|
||||||
|
{
|
||||||
|
nonstock: null,
|
||||||
|
nonstock_id: 0,
|
||||||
|
quantity: undefined,
|
||||||
|
price: undefined,
|
||||||
|
notes: '',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import DateInput from '@/components/input/DateInput';
|
|||||||
import ExpenseKandangsTable from '@/components/pages/expense/form/ExpenseKandangsTable';
|
import ExpenseKandangsTable from '@/components/pages/expense/form/ExpenseKandangsTable';
|
||||||
import DropFileInput from '@/components/input/DropFileInput';
|
import DropFileInput from '@/components/input/DropFileInput';
|
||||||
import ExpenseRequestKandangDetailExpense from '@/components/pages/expense/form/ExpenseRequestKandangDetailExpense';
|
import ExpenseRequestKandangDetailExpense from '@/components/pages/expense/form/ExpenseRequestKandangDetailExpense';
|
||||||
|
import RequirePermission from '@/components/helper/RequirePermission';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ExpenseRequestFormSchema,
|
ExpenseRequestFormSchema,
|
||||||
@@ -36,6 +37,8 @@ import { cn, sleep } from '@/lib/helper';
|
|||||||
import { LocationApi, SupplierApi } from '@/services/api/master-data';
|
import { LocationApi, SupplierApi } from '@/services/api/master-data';
|
||||||
import { ACCEPTED_FILE_TYPE } from '@/config/constant';
|
import { ACCEPTED_FILE_TYPE } from '@/config/constant';
|
||||||
import { Supplier } from '@/types/api/master-data/supplier';
|
import { Supplier } from '@/types/api/master-data/supplier';
|
||||||
|
import { getUniqueFormikErrors } from '@/lib/formik-helper';
|
||||||
|
import AlertErrorList from '@/components/helper/form/FormErrors';
|
||||||
|
|
||||||
interface ExpenseFormProps {
|
interface ExpenseFormProps {
|
||||||
type?: 'add' | 'edit' | 'detail';
|
type?: 'add' | 'edit' | 'detail';
|
||||||
@@ -54,6 +57,7 @@ const ExpenseRequestForm = ({
|
|||||||
const rejectModal = useModal();
|
const rejectModal = useModal();
|
||||||
|
|
||||||
const [expenseFormErrorMessage, setExpenseFormErrorMessage] = useState('');
|
const [expenseFormErrorMessage, setExpenseFormErrorMessage] = useState('');
|
||||||
|
const [formErrorList, setFormErrorList] = useState<string[]>([]);
|
||||||
|
|
||||||
const createExpenseHandler = useCallback(
|
const createExpenseHandler = useCallback(
|
||||||
async (payload: CreateExpensePayload) => {
|
async (payload: CreateExpensePayload) => {
|
||||||
@@ -107,18 +111,24 @@ const ExpenseRequestForm = ({
|
|||||||
|
|
||||||
const expensePayload: CreateExpensePayload = {
|
const expensePayload: CreateExpensePayload = {
|
||||||
category: formik.values.category?.value as 'BOP' | 'NON-BOP',
|
category: formik.values.category?.value as 'BOP' | 'NON-BOP',
|
||||||
|
location_id: values.location_id as number,
|
||||||
transaction_date: values?.transaction_date as string,
|
transaction_date: values?.transaction_date as string,
|
||||||
supplier_id: values.supplier?.value as number,
|
supplier_id: values.supplier?.value as number,
|
||||||
documents: values.documents as File[],
|
documents: values.documents as File[],
|
||||||
expense_nonstocks: values.expense_nonstocks.map((expenseNonstock) => ({
|
expense_nonstocks: values.expense_nonstocks.map((expenseNonstock) => {
|
||||||
kandang_id: expenseNonstock.kandang_id,
|
const basePayload = {
|
||||||
cost_items: expenseNonstock.cost_items.map((costItem) => ({
|
cost_items: expenseNonstock.cost_items.map((costItem) => ({
|
||||||
nonstock_id: costItem.nonstock?.value as number,
|
nonstock_id: costItem.nonstock?.value as number,
|
||||||
quantity: parseFloat(String(costItem.quantity)) as number,
|
quantity: parseFloat(String(costItem.quantity)) as number,
|
||||||
price: parseFloat(String(costItem.price)) as number,
|
price: parseFloat(String(costItem.price)) as number,
|
||||||
notes: costItem.notes ?? '',
|
notes: costItem.notes ?? '',
|
||||||
})),
|
})),
|
||||||
})),
|
};
|
||||||
|
|
||||||
|
return expenseNonstock.kandang_id
|
||||||
|
? { ...basePayload, kandang_id: expenseNonstock.kandang_id }
|
||||||
|
: basePayload;
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@@ -129,19 +139,25 @@ const ExpenseRequestForm = ({
|
|||||||
case 'edit':
|
case 'edit':
|
||||||
const expenseUpdatePayload: UpdateExpensePayload = {
|
const expenseUpdatePayload: UpdateExpensePayload = {
|
||||||
category: formik.values.category?.value as 'BOP' | 'NON-BOP',
|
category: formik.values.category?.value as 'BOP' | 'NON-BOP',
|
||||||
|
location_id: values.location_id as number,
|
||||||
transaction_date: values?.transaction_date as string,
|
transaction_date: values?.transaction_date as string,
|
||||||
supplier_id: values.supplier?.value as number,
|
supplier_id: values.supplier?.value as number,
|
||||||
documents: values.documents as File[],
|
documents: values.documents as File[],
|
||||||
expense_nonstocks: values.expense_nonstocks.map(
|
expense_nonstocks: values.expense_nonstocks.map(
|
||||||
(expenseNonstock) => ({
|
(expenseNonstock) => {
|
||||||
kandang_id: expenseNonstock.kandang_id,
|
const basePayload = {
|
||||||
cost_items: expenseNonstock.cost_items.map((costItem) => ({
|
cost_items: expenseNonstock.cost_items.map((costItem) => ({
|
||||||
nonstock_id: costItem.nonstock?.value as number,
|
nonstock_id: costItem.nonstock?.value as number,
|
||||||
quantity: parseFloat(String(costItem.quantity)) as number,
|
quantity: parseFloat(String(costItem.quantity)) as number,
|
||||||
price: parseFloat(String(costItem.price)) as number,
|
price: parseFloat(String(costItem.price)) as number,
|
||||||
notes: costItem.notes ?? '',
|
notes: costItem.notes ?? '',
|
||||||
})),
|
})),
|
||||||
})
|
};
|
||||||
|
|
||||||
|
return expenseNonstock.kandang_id
|
||||||
|
? { ...basePayload, kandang_id: expenseNonstock.kandang_id }
|
||||||
|
: basePayload;
|
||||||
|
}
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -178,30 +194,67 @@ const ExpenseRequestForm = ({
|
|||||||
formik.setFieldTouched('location', true);
|
formik.setFieldTouched('location', true);
|
||||||
formik.setFieldValue('location', val);
|
formik.setFieldValue('location', val);
|
||||||
|
|
||||||
|
const locationId = Array.isArray(val) ? val[0]?.value : val?.value;
|
||||||
|
formik.setFieldValue('location_id', locationId);
|
||||||
|
|
||||||
formik.setFieldValue('kandangs', []);
|
formik.setFieldValue('kandangs', []);
|
||||||
formik.setFieldValue('expense_nonstocks', []);
|
|
||||||
|
// Auto-create expense item for location (without kandang)
|
||||||
|
formik.setFieldValue('expense_nonstocks', [
|
||||||
|
{
|
||||||
|
cost_items: [
|
||||||
|
{
|
||||||
|
nonstock: null,
|
||||||
|
nonstock_id: 0,
|
||||||
|
quantity: undefined,
|
||||||
|
price: undefined,
|
||||||
|
notes: '',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]);
|
||||||
};
|
};
|
||||||
|
|
||||||
const kandangsChangeHandler = (kandangs: { id: number; name: string }[]) => {
|
const kandangsChangeHandler = (
|
||||||
|
kandangs: { id?: number; name?: string }[]
|
||||||
|
) => {
|
||||||
formik.setFieldTouched('kandangs', true);
|
formik.setFieldTouched('kandangs', true);
|
||||||
formik.setFieldValue('kandangs', kandangs);
|
formik.setFieldValue('kandangs', kandangs);
|
||||||
|
|
||||||
const newExpenseNonstocks = [...(formik.values.expense_nonstocks ?? [])];
|
// If no kandangs selected, create expense item for location
|
||||||
|
if (kandangs.length === 0) {
|
||||||
|
formik.setFieldValue('expense_nonstocks', [
|
||||||
|
{
|
||||||
|
cost_items: [
|
||||||
|
{
|
||||||
|
nonstock: null,
|
||||||
|
nonstock_id: 0,
|
||||||
|
quantity: undefined,
|
||||||
|
price: undefined,
|
||||||
|
notes: '',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const newExpenseNonstocks: typeof formik.values.expense_nonstocks = [];
|
||||||
|
|
||||||
// add new expense_nonstocks
|
|
||||||
kandangs.forEach((kandangItem) => {
|
kandangs.forEach((kandangItem) => {
|
||||||
const isKandangExistInExpenseNonstocks = newExpenseNonstocks.find(
|
if (!kandangItem.id) return;
|
||||||
|
|
||||||
|
const existingExpenseNonstock = formik.values.expense_nonstocks?.find(
|
||||||
(expenseNonstockItem) =>
|
(expenseNonstockItem) =>
|
||||||
expenseNonstockItem.kandang_id === kandangItem.id
|
expenseNonstockItem.kandang_id === kandangItem.id
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isKandangExistInExpenseNonstocks) return;
|
|
||||||
|
|
||||||
newExpenseNonstocks.push({
|
newExpenseNonstocks.push({
|
||||||
kandang_id: kandangItem.id,
|
kandang_id: kandangItem.id,
|
||||||
cost_items: [
|
cost_items: existingExpenseNonstock?.cost_items || [
|
||||||
{
|
{
|
||||||
nonstock: undefined,
|
nonstock: null,
|
||||||
|
nonstock_id: 0,
|
||||||
quantity: undefined,
|
quantity: undefined,
|
||||||
price: undefined,
|
price: undefined,
|
||||||
notes: '',
|
notes: '',
|
||||||
@@ -210,32 +263,26 @@ const ExpenseRequestForm = ({
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// prune expense_nonstocks
|
|
||||||
const kandangIds = new Set(kandangs.map((kandang) => kandang.id));
|
|
||||||
const deletedExpenseNonstocksIdx: number[] = [];
|
|
||||||
|
|
||||||
newExpenseNonstocks.forEach((expenseNonstock, idx) => {
|
|
||||||
const isExpenseNonstockValid = kandangIds.has(expenseNonstock.kandang_id);
|
|
||||||
|
|
||||||
if (!isExpenseNonstockValid) {
|
|
||||||
deletedExpenseNonstocksIdx.push(idx);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
deletedExpenseNonstocksIdx.forEach((deletedExpenseNonstockIdx) => {
|
|
||||||
newExpenseNonstocks.splice(deletedExpenseNonstockIdx, 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
formik.setFieldValue('expense_nonstocks', newExpenseNonstocks);
|
formik.setFieldValue('expense_nonstocks', newExpenseNonstocks);
|
||||||
};
|
};
|
||||||
|
|
||||||
const supplierChangeHandler = (val: OptionType | OptionType[] | null) => {
|
const supplierChangeHandler = (val: OptionType | OptionType[] | null) => {
|
||||||
formik.setFieldTouched('supplier', true);
|
formik.setFieldTouched('supplier', true);
|
||||||
formik.setFieldValue('supplier', val);
|
formik.setFieldValue('supplier', val);
|
||||||
|
|
||||||
|
const supplierId = Array.isArray(val) ? val[0]?.value : val?.value;
|
||||||
|
formik.setFieldValue('supplier_id', supplierId ?? 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
const requestDocumentsChangeHandler = (val: File[]) => {
|
const requestDocumentsChangeHandler = (val: File[]) => {
|
||||||
formik.setFieldTouched('documents', true);
|
formik.setFieldTouched('documents', true);
|
||||||
|
|
||||||
|
const invalidFiles = val.filter((file) => file.size > 5 * 1024 * 1024);
|
||||||
|
if (invalidFiles.length > 0) {
|
||||||
|
toast.error('Ukuran dokumen maksimal 5 MB!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
formik.setFieldValue('documents', val);
|
formik.setFieldValue('documents', val);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -291,6 +338,22 @@ const ExpenseRequestForm = ({
|
|||||||
router.push('/expense');
|
router.push('/expense');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleValidateForm = async () => {
|
||||||
|
const errors = await formik.validateForm();
|
||||||
|
|
||||||
|
if (Object.keys(errors).length > 0) {
|
||||||
|
const errorMessages = getUniqueFormikErrors(errors);
|
||||||
|
setFormErrorList(errorMessages);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleFormSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
||||||
|
e.preventDefault();
|
||||||
|
handleValidateForm();
|
||||||
|
formik.handleSubmit(e);
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
formikSetValues(getExpenseFormInitialValues(initialValues));
|
formikSetValues(getExpenseFormInitialValues(initialValues));
|
||||||
}, [formikSetValues, getExpenseFormInitialValues, initialValues]);
|
}, [formikSetValues, getExpenseFormInitialValues, initialValues]);
|
||||||
@@ -316,10 +379,27 @@ const ExpenseRequestForm = ({
|
|||||||
</header>
|
</header>
|
||||||
|
|
||||||
<form
|
<form
|
||||||
onSubmit={formik.handleSubmit}
|
onSubmit={handleFormSubmit}
|
||||||
onReset={formik.handleReset}
|
onReset={formik.handleReset}
|
||||||
className='w-full mt-8 flex flex-col gap-6'
|
className='w-full mt-8 flex flex-col gap-6'
|
||||||
>
|
>
|
||||||
|
{expenseFormErrorMessage && (
|
||||||
|
<div role='alert' className='alert alert-error'>
|
||||||
|
<Icon
|
||||||
|
icon='material-symbols:error-outline'
|
||||||
|
width={24}
|
||||||
|
height={24}
|
||||||
|
/>
|
||||||
|
<span>{expenseFormErrorMessage}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{formErrorList.length > 0 && (
|
||||||
|
<AlertErrorList
|
||||||
|
formErrorList={formErrorList}
|
||||||
|
onClose={() => setFormErrorList([])}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<div className='grid grid-cols-12 gap-4'>
|
<div className='grid grid-cols-12 gap-4'>
|
||||||
<SelectInput
|
<SelectInput
|
||||||
label='Kategori'
|
label='Kategori'
|
||||||
@@ -385,21 +465,23 @@ const ExpenseRequestForm = ({
|
|||||||
className={{ wrapper: 'col-span-12' }}
|
className={{ wrapper: 'col-span-12' }}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<DropFileInput
|
<RequirePermission permissions='lti.expense.document'>
|
||||||
label='Dokumen Pengajuan'
|
<DropFileInput
|
||||||
name='documents'
|
label='Dokumen Pengajuan'
|
||||||
values={formik.values.documents}
|
name='documents'
|
||||||
onChange={requestDocumentsChangeHandler}
|
values={formik.values.documents}
|
||||||
onDelete={requestDocumentsDeleteHandler}
|
onChange={requestDocumentsChangeHandler}
|
||||||
accept={{
|
onDelete={requestDocumentsDeleteHandler}
|
||||||
...ACCEPTED_FILE_TYPE.PDF,
|
accept={{
|
||||||
...ACCEPTED_FILE_TYPE.IMAGE,
|
...ACCEPTED_FILE_TYPE.PDF,
|
||||||
}}
|
...ACCEPTED_FILE_TYPE.IMAGE,
|
||||||
className={{
|
}}
|
||||||
wrapper: 'col-span-12',
|
className={{
|
||||||
inputWrapper: 'h-12 flex items-center',
|
wrapper: 'col-span-12',
|
||||||
}}
|
inputWrapper: 'h-12 flex items-center',
|
||||||
/>
|
}}
|
||||||
|
/>
|
||||||
|
</RequirePermission>
|
||||||
|
|
||||||
{formik.values.existing_documents &&
|
{formik.values.existing_documents &&
|
||||||
formik.values.existing_documents.length > 0 && (
|
formik.values.existing_documents.length > 0 && (
|
||||||
@@ -451,7 +533,10 @@ const ExpenseRequestForm = ({
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
<ExpenseRequestKandangDetailExpense
|
<ExpenseRequestKandangDetailExpense
|
||||||
|
type={type}
|
||||||
formik={formik}
|
formik={formik}
|
||||||
|
supplierId={formik.values.supplier?.value as number}
|
||||||
|
location={formik.values.location}
|
||||||
className={{
|
className={{
|
||||||
wrapper: 'col-span-12',
|
wrapper: 'col-span-12',
|
||||||
}}
|
}}
|
||||||
@@ -461,48 +546,41 @@ const ExpenseRequestForm = ({
|
|||||||
<div className='flex flex-row justify-between gap-2 flex-wrap'>
|
<div className='flex flex-row justify-between gap-2 flex-wrap'>
|
||||||
{type !== 'add' && (
|
{type !== 'add' && (
|
||||||
<div className='flex flex-row justify-start gap-2'>
|
<div className='flex flex-row justify-start gap-2'>
|
||||||
<Button
|
<RequirePermission permissions='lti.expense.delete'>
|
||||||
type='button'
|
|
||||||
color='error'
|
|
||||||
onClick={deleteExpenseClickHandler}
|
|
||||||
className='px-4'
|
|
||||||
>
|
|
||||||
<Icon
|
|
||||||
icon='material-symbols:delete-outline-rounded'
|
|
||||||
width={24}
|
|
||||||
height={24}
|
|
||||||
className='justify-start text-sm'
|
|
||||||
/>
|
|
||||||
Delete
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
{type !== 'edit' && (
|
|
||||||
<Button
|
<Button
|
||||||
type='button'
|
type='button'
|
||||||
color='warning'
|
color='error'
|
||||||
href={`/expense/detail/edit/?expenseId=${initialValues?.id}`}
|
onClick={deleteExpenseClickHandler}
|
||||||
className='px-4'
|
className='px-4'
|
||||||
>
|
>
|
||||||
<Icon
|
<Icon
|
||||||
icon='material-symbols:edit-outline'
|
icon='material-symbols:delete-outline-rounded'
|
||||||
width={24}
|
width={24}
|
||||||
height={24}
|
height={24}
|
||||||
className='justify-start text-sm'
|
className='justify-start text-sm'
|
||||||
/>
|
/>
|
||||||
Edit
|
Delete
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
</RequirePermission>
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{expenseFormErrorMessage && (
|
{type !== 'edit' && (
|
||||||
<div role='alert' className='alert alert-error w-full'>
|
<RequirePermission permissions='lti.expense.update'>
|
||||||
<Icon
|
<Button
|
||||||
icon='material-symbols:error-outline'
|
type='button'
|
||||||
width={24}
|
color='warning'
|
||||||
height={24}
|
href={`/expense/detail/edit/?expenseId=${initialValues?.id}`}
|
||||||
/>
|
className='px-4'
|
||||||
<span>{expenseFormErrorMessage}</span>
|
>
|
||||||
|
<Icon
|
||||||
|
icon='material-symbols:edit-outline'
|
||||||
|
width={24}
|
||||||
|
height={24}
|
||||||
|
className='justify-start text-sm'
|
||||||
|
/>
|
||||||
|
Edit
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -520,7 +598,7 @@ const ExpenseRequestForm = ({
|
|||||||
type='submit'
|
type='submit'
|
||||||
color='primary'
|
color='primary'
|
||||||
isLoading={formik.isSubmitting}
|
isLoading={formik.isSubmitting}
|
||||||
disabled={!formik.isValid || formik.isSubmitting}
|
disabled={formik.isSubmitting}
|
||||||
className='px-4'
|
className='px-4'
|
||||||
>
|
>
|
||||||
Submit
|
Submit
|
||||||
|
|||||||
@@ -21,6 +21,11 @@ import { removeArrayItemAndSync } from '@/lib/utils/formik';
|
|||||||
interface ExpenseRequestKandangDetailExpenseProps {
|
interface ExpenseRequestKandangDetailExpenseProps {
|
||||||
type?: 'add' | 'edit' | 'detail';
|
type?: 'add' | 'edit' | 'detail';
|
||||||
formik: FormikContextType<ExpenseRequestFormValues>;
|
formik: FormikContextType<ExpenseRequestFormValues>;
|
||||||
|
supplierId?: number;
|
||||||
|
location?: {
|
||||||
|
value: number;
|
||||||
|
label: string;
|
||||||
|
} | null;
|
||||||
className?: {
|
className?: {
|
||||||
wrapper?: string;
|
wrapper?: string;
|
||||||
};
|
};
|
||||||
@@ -28,12 +33,18 @@ interface ExpenseRequestKandangDetailExpenseProps {
|
|||||||
|
|
||||||
const ExpenseRequestKandangDetailExpense: React.FC<
|
const ExpenseRequestKandangDetailExpense: React.FC<
|
||||||
ExpenseRequestKandangDetailExpenseProps
|
ExpenseRequestKandangDetailExpenseProps
|
||||||
> = ({ type, formik, className }) => {
|
> = ({ type, formik, supplierId, location, className }) => {
|
||||||
const {
|
const {
|
||||||
setInputValue: setNonstockInputValue,
|
setInputValue: setNonstockInputValue,
|
||||||
options: nonstockOptions,
|
options: nonstockOptions,
|
||||||
isLoadingOptions: isLoadingNonstockOptions,
|
isLoadingOptions: isLoadingNonstockOptions,
|
||||||
} = useSelect<Nonstock>(NonstockApi.basePath, 'id', 'name');
|
} = useSelect<Nonstock>(
|
||||||
|
NonstockApi.basePath,
|
||||||
|
'id',
|
||||||
|
'name',
|
||||||
|
'search',
|
||||||
|
supplierId ? { supplier_id: String(supplierId) } : undefined
|
||||||
|
);
|
||||||
|
|
||||||
const nonstockChangeHandler = (
|
const nonstockChangeHandler = (
|
||||||
kandangExpenseIdx: number,
|
kandangExpenseIdx: number,
|
||||||
@@ -48,13 +59,20 @@ const ExpenseRequestKandangDetailExpense: React.FC<
|
|||||||
`expense_nonstocks[${kandangExpenseIdx}].cost_items[${expenseIdx}].nonstock`,
|
`expense_nonstocks[${kandangExpenseIdx}].cost_items[${expenseIdx}].nonstock`,
|
||||||
val
|
val
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const nonstockId = Array.isArray(val) ? val[0]?.value : val?.value;
|
||||||
|
formik.setFieldValue(
|
||||||
|
`expense_nonstocks[${kandangExpenseIdx}].cost_items[${expenseIdx}].nonstock_id`,
|
||||||
|
nonstockId ?? 0
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const addExpenseItemHandler = (kandangExpenseIdx: number) => {
|
const addExpenseItemHandler = (kandangExpenseIdx: number) => {
|
||||||
const newExpensesValue = [
|
const newExpensesValue = [
|
||||||
...formik.values.expense_nonstocks[kandangExpenseIdx].cost_items,
|
...formik.values.expense_nonstocks[kandangExpenseIdx].cost_items,
|
||||||
{
|
{
|
||||||
nonstock: undefined,
|
nonstock: null,
|
||||||
|
nonstock_id: 0,
|
||||||
price: undefined,
|
price: undefined,
|
||||||
quantity: undefined,
|
quantity: undefined,
|
||||||
notes: '',
|
notes: '',
|
||||||
@@ -113,41 +131,57 @@ const ExpenseRequestKandangDetailExpense: React.FC<
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className='w-full flex flex-col gap-6'>
|
<div className='w-full flex flex-col gap-6'>
|
||||||
{(formik.values.expense_nonstocks.length === 0 ||
|
{!formik.values.supplier?.value && (
|
||||||
!formik.values.supplier?.value) && (
|
|
||||||
<div>
|
<div>
|
||||||
<p className='text-sm text-gray-400 text-center'>
|
<p className='text-sm text-gray-400 text-center'>
|
||||||
Pilih kandang terlebih dahulu!
|
Pilih supplier terlebih dahulu!
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{formik.values.expense_nonstocks.length === 0 &&
|
||||||
|
formik.values.supplier?.value && (
|
||||||
|
<div>
|
||||||
|
<p className='text-sm text-gray-400 text-center'>
|
||||||
|
Belum ada item biaya. Silakan pilih lokasi terlebih dahulu.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{formik.values.expense_nonstocks.length > 0 &&
|
{formik.values.expense_nonstocks.length > 0 &&
|
||||||
formik.values.supplier?.value &&
|
formik.values.supplier?.value &&
|
||||||
formik.values.expense_nonstocks.map(
|
formik.values.expense_nonstocks.map(
|
||||||
(kandangExpense, kandangExpenseIdx) => {
|
(kandangExpense, kandangExpenseIdx) => {
|
||||||
const kandangName = formik.values.kandangs?.find(
|
const kandangName = kandangExpense.kandang_id
|
||||||
(kandang) => kandang.id === kandangExpense.kandang_id
|
? formik.values.kandangs?.find(
|
||||||
);
|
(kandang) => kandang.id === kandangExpense.kandang_id
|
||||||
|
)
|
||||||
|
: null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
kandangName?.name && (
|
(kandangName?.name || !kandangExpense.kandang_id) && (
|
||||||
<div
|
<div
|
||||||
key={`kandangExpense-${kandangExpenseIdx}`}
|
key={`kandangExpense-${kandangExpenseIdx}`}
|
||||||
className='w-full flex flex-col gap-4'
|
className='w-full flex flex-col gap-4'
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
<h5 className='mb-2 text-lg font-bold text-center'>
|
<h5 className='mb-2 text-lg font-bold text-center'>
|
||||||
Biaya {kandangName?.name}
|
Biaya {kandangName?.name || location?.label || 'Umum'}
|
||||||
</h5>
|
</h5>
|
||||||
|
|
||||||
<div className='overflow-x-auto'>
|
<div className='overflow-x-auto'>
|
||||||
<table className='table'>
|
<table className='table'>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Nonstock</th>
|
<th className='after:content-["*"] after:text-red-500 after:ml-0.5'>
|
||||||
<th>Total Kuantitas</th>
|
Nonstock
|
||||||
<th>Harga Satuan</th>
|
</th>
|
||||||
|
<th className='after:content-["*"] after:text-red-500 after:ml-0.5'>
|
||||||
|
Total Kuantitas
|
||||||
|
</th>
|
||||||
|
<th className='after:content-["*"] after:text-red-500 after:ml-0.5'>
|
||||||
|
Harga Satuan
|
||||||
|
</th>
|
||||||
<th>Catatan</th>
|
<th>Catatan</th>
|
||||||
{type !== 'detail' && <th>Aksi</th>}
|
{type !== 'detail' && <th>Aksi</th>}
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ const ExpensePDF = ({ expense }: ExpensePDFProps) => {
|
|||||||
expense?.latest_approval?.action === 'REJECTED';
|
expense?.latest_approval?.action === 'REJECTED';
|
||||||
const isExpenseRealized =
|
const isExpenseRealized =
|
||||||
expense?.latest_approval?.step_number &&
|
expense?.latest_approval?.step_number &&
|
||||||
expense?.latest_approval.step_number >= 4;
|
expense?.latest_approval.step_number >= 5;
|
||||||
|
|
||||||
const realizationStatus = isExpenseRealized
|
const realizationStatus = isExpenseRealized
|
||||||
? 'Sudah Realisasi'
|
? 'Sudah Realisasi'
|
||||||
@@ -219,7 +219,13 @@ const ExpensePDF = ({ expense }: ExpensePDFProps) => {
|
|||||||
{ label: 'Lokasi', value: expense?.location.name },
|
{ label: 'Lokasi', value: expense?.location.name },
|
||||||
{
|
{
|
||||||
label: 'Kandang',
|
label: 'Kandang',
|
||||||
value: expense?.kandangs.map((item) => item.name).join(', '),
|
value:
|
||||||
|
expense?.kandangs && expense?.kandangs.some((k) => k.name)
|
||||||
|
? expense?.kandangs
|
||||||
|
.filter((item) => item.name)
|
||||||
|
.map((item) => item.name)
|
||||||
|
.join(', ')
|
||||||
|
: '-',
|
||||||
},
|
},
|
||||||
{ label: 'Vendor', value: expense?.supplier.name },
|
{ label: 'Vendor', value: expense?.supplier.name },
|
||||||
{
|
{
|
||||||
@@ -235,7 +241,12 @@ const ExpensePDF = ({ expense }: ExpensePDFProps) => {
|
|||||||
{ label: 'Nama Pengaju', value: expense?.created_user.name },
|
{ label: 'Nama Pengaju', value: expense?.created_user.name },
|
||||||
{
|
{
|
||||||
label: 'Nominal Biaya',
|
label: 'Nominal Biaya',
|
||||||
value: formatCurrency(expense?.grand_total ?? 0),
|
value: formatCurrency(
|
||||||
|
expense?.latest_approval.step_number === 5 ||
|
||||||
|
expense?.latest_approval.step_number === 6
|
||||||
|
? (expense?.total_realisasi ?? 0)
|
||||||
|
: (expense?.total_pengajuan ?? 0)
|
||||||
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Nominal Pengajuan',
|
label: 'Nominal Pengajuan',
|
||||||
@@ -326,7 +337,7 @@ const ExpensePDF = ({ expense }: ExpensePDFProps) => {
|
|||||||
let expenseRequestTotal = 0;
|
let expenseRequestTotal = 0;
|
||||||
|
|
||||||
kandangExpense.pengajuans?.forEach(
|
kandangExpense.pengajuans?.forEach(
|
||||||
(item) => (expenseRequestTotal += item.price)
|
(item) => (expenseRequestTotal += item.qty * item.price)
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -335,7 +346,9 @@ const ExpensePDF = ({ expense }: ExpensePDFProps) => {
|
|||||||
style={ExpensePDFStyle.kandangExpenseContainer}
|
style={ExpensePDFStyle.kandangExpenseContainer}
|
||||||
>
|
>
|
||||||
<Text style={ExpensePDFStyle.kandangExpenseTitle}>
|
<Text style={ExpensePDFStyle.kandangExpenseTitle}>
|
||||||
{kandangExpense.name}
|
{kandangExpense.kandang_id && kandangExpense.name
|
||||||
|
? `Biaya ${kandangExpense.name}`
|
||||||
|
: `Biaya ${expense?.location.name || 'Umum'}`}
|
||||||
</Text>
|
</Text>
|
||||||
|
|
||||||
<View style={ExpensePDFStyle.kandangExpenseTable}>
|
<View style={ExpensePDFStyle.kandangExpenseTable}>
|
||||||
@@ -484,7 +497,7 @@ const ExpensePDF = ({ expense }: ExpensePDFProps) => {
|
|||||||
let expenseRealizationTotal = 0;
|
let expenseRealizationTotal = 0;
|
||||||
|
|
||||||
kandangExpense.realisasi?.forEach(
|
kandangExpense.realisasi?.forEach(
|
||||||
(item) => (expenseRealizationTotal += item.price)
|
(item) => (expenseRealizationTotal += item.qty * item.price)
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -493,7 +506,9 @@ const ExpensePDF = ({ expense }: ExpensePDFProps) => {
|
|||||||
style={ExpensePDFStyle.kandangExpenseContainer}
|
style={ExpensePDFStyle.kandangExpenseContainer}
|
||||||
>
|
>
|
||||||
<Text style={ExpensePDFStyle.kandangExpenseTitle}>
|
<Text style={ExpensePDFStyle.kandangExpenseTitle}>
|
||||||
{kandangExpense.name}
|
{kandangExpense.kandang_id && kandangExpense.name
|
||||||
|
? `Biaya ${kandangExpense.name}`
|
||||||
|
: `Biaya ${expense?.location.name || 'Umum'}`}
|
||||||
</Text>
|
</Text>
|
||||||
|
|
||||||
<View style={ExpensePDFStyle.kandangExpenseTable}>
|
<View style={ExpensePDFStyle.kandangExpenseTable}>
|
||||||
|
|||||||
@@ -0,0 +1,216 @@
|
|||||||
|
import Button from '@/components/Button';
|
||||||
|
import Card from '@/components/Card';
|
||||||
|
import { FormHeader } from '@/components/helper/form/FormHeader';
|
||||||
|
import RequirePermission from '@/components/helper/RequirePermission';
|
||||||
|
import DebouncedTextInput from '@/components/input/DebouncedTextInput';
|
||||||
|
import { useModal } from '@/components/Modal';
|
||||||
|
import ConfirmationModal from '@/components/modal/ConfirmationModal';
|
||||||
|
import Table from '@/components/Table';
|
||||||
|
import {
|
||||||
|
FINANCE_INITIAL_BALANCE_STATUS,
|
||||||
|
FINANCE_TRANSACTION_STATUS,
|
||||||
|
FINANCE_INJECTION_STATUS,
|
||||||
|
} from '@/config/constant';
|
||||||
|
import { formatCurrency, formatDate, formatTitleCase } from '@/lib/helper';
|
||||||
|
import { FinanceApi } from '@/services/api/finance';
|
||||||
|
import { Finance } from '@/types/api/finance/finance';
|
||||||
|
import { Icon } from '@iconify/react';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import { useState } from 'react';
|
||||||
|
import toast from 'react-hot-toast';
|
||||||
|
|
||||||
|
const FinanceDetail = ({ finance }: { finance: Finance }) => {
|
||||||
|
const router = useRouter();
|
||||||
|
const deleteModal = useModal();
|
||||||
|
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
|
||||||
|
const informasiUmum = [
|
||||||
|
{
|
||||||
|
label: 'ID',
|
||||||
|
value: finance.payment_code,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Jenis Transaksi',
|
||||||
|
value: finance.transaction_type,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Pihak',
|
||||||
|
value: finance.party.id ? finance.party.name : '-',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Tanggal',
|
||||||
|
value: formatDate(finance.payment_date, 'DD MMM yyyy'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Metode Pembayaran',
|
||||||
|
value: finance.payment_method,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Catatan',
|
||||||
|
value: finance.notes || '-',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const informasiTransfer = [
|
||||||
|
{
|
||||||
|
label: 'No. Referensi',
|
||||||
|
value: finance.reference_number ?? '-',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Nomor Rekening',
|
||||||
|
value: `${finance.bank.alias} - ${finance.bank.account_number} - ${finance.bank.owner}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: `Rekening ${formatTitleCase(finance.party.type)}`,
|
||||||
|
value: finance.party.account_number,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Nominal',
|
||||||
|
value: formatCurrency(finance.expense_amount),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Sisa',
|
||||||
|
value: formatCurrency(finance.income_amount),
|
||||||
|
},
|
||||||
|
].filter((item) => {
|
||||||
|
// Hide party account number row if transaction type is INJECTION
|
||||||
|
if (
|
||||||
|
FINANCE_INJECTION_STATUS.includes(finance.transaction_type) &&
|
||||||
|
item.label === `Rekening ${formatTitleCase(finance.party.type)}`
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
const confirmationModalDeleteClickHandler = async () => {
|
||||||
|
setIsDeleteLoading(true);
|
||||||
|
|
||||||
|
await FinanceApi.delete(finance.id as number);
|
||||||
|
router.back();
|
||||||
|
|
||||||
|
deleteModal.closeModal();
|
||||||
|
toast.success('Successfully delete Finance!');
|
||||||
|
setIsDeleteLoading(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='flex flex-col gap-6 p-6'>
|
||||||
|
<FormHeader title='' backUrl='/finance' />
|
||||||
|
|
||||||
|
<Card
|
||||||
|
title='Detail Keuangan'
|
||||||
|
className={{
|
||||||
|
wrapper: 'w-full',
|
||||||
|
}}
|
||||||
|
variant='bordered'
|
||||||
|
>
|
||||||
|
<div className='grid grid-cols-2 gap-4 mb-6'>
|
||||||
|
<Table
|
||||||
|
data={informasiUmum}
|
||||||
|
columns={[
|
||||||
|
{
|
||||||
|
header: '',
|
||||||
|
id: 'label',
|
||||||
|
accessorKey: 'label',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: '',
|
||||||
|
id: 'value',
|
||||||
|
accessorKey: 'value',
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
className={{
|
||||||
|
headerRowClassName: 'hidden',
|
||||||
|
paginationClassName: 'hidden',
|
||||||
|
containerClassName: 'mb-0',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Table
|
||||||
|
data={informasiTransfer}
|
||||||
|
columns={[
|
||||||
|
{
|
||||||
|
header: '',
|
||||||
|
id: 'label',
|
||||||
|
accessorKey: 'label',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: '',
|
||||||
|
id: 'value',
|
||||||
|
accessorKey: 'value',
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
className={{
|
||||||
|
headerRowClassName: 'hidden',
|
||||||
|
paginationClassName: 'hidden',
|
||||||
|
containerClassName: 'mb-0',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<div className='flex flex-row gap-2 justify-end'>
|
||||||
|
{FINANCE_TRANSACTION_STATUS.includes(finance.transaction_type) && (
|
||||||
|
<RequirePermission permissions='lti.finance.payments.update'>
|
||||||
|
<Button
|
||||||
|
color='warning'
|
||||||
|
className='min-w-24'
|
||||||
|
href={`/finance/detail/edit?financeId=${finance.id}`}
|
||||||
|
>
|
||||||
|
<Icon icon='mdi:pencil-outline' />
|
||||||
|
Edit
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
|
)}
|
||||||
|
{FINANCE_INITIAL_BALANCE_STATUS.includes(finance.transaction_type) && (
|
||||||
|
<RequirePermission permissions='lti.finance.initial_balances.update'>
|
||||||
|
<Button
|
||||||
|
color='warning'
|
||||||
|
className='min-w-24'
|
||||||
|
href={`/finance/detail/edit/initial-balance?financeId=${finance.id}`}
|
||||||
|
>
|
||||||
|
<Icon icon='mdi:pencil-outline' />
|
||||||
|
Edit
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
|
)}
|
||||||
|
{FINANCE_INJECTION_STATUS.includes(finance.transaction_type) && (
|
||||||
|
<RequirePermission permissions='lti.finance.injections.update'>
|
||||||
|
<Button
|
||||||
|
color='warning'
|
||||||
|
className='min-w-24'
|
||||||
|
href={`/finance/detail/edit/injection?financeId=${finance.id}`}
|
||||||
|
>
|
||||||
|
<Icon icon='mdi:pencil-outline' />
|
||||||
|
Edit
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
|
)}
|
||||||
|
<RequirePermission permissions='lti.finance.transactions.delete'>
|
||||||
|
<Button
|
||||||
|
color='error'
|
||||||
|
className='min-w-24'
|
||||||
|
onClick={() => deleteModal.openModal()}
|
||||||
|
>
|
||||||
|
<Icon icon='mdi:delete-outline' />
|
||||||
|
Delete
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
|
</div>
|
||||||
|
<ConfirmationModal
|
||||||
|
ref={deleteModal.ref}
|
||||||
|
type='error'
|
||||||
|
text={`Apakah anda yakin ingin menghapus data Finance ini (${finance?.payment_code})?`}
|
||||||
|
secondaryButton={{
|
||||||
|
text: 'Tidak',
|
||||||
|
}}
|
||||||
|
primaryButton={{
|
||||||
|
text: 'Ya',
|
||||||
|
color: 'error',
|
||||||
|
isLoading: isDeleteLoading,
|
||||||
|
onClick: confirmationModalDeleteClickHandler,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default FinanceDetail;
|
||||||
@@ -0,0 +1,571 @@
|
|||||||
|
import { ChangeEventHandler, useMemo, useState } from 'react';
|
||||||
|
import { CellContext, Row } from '@tanstack/react-table';
|
||||||
|
import { useSearchParams } from 'next/navigation';
|
||||||
|
import useSWR from 'swr';
|
||||||
|
|
||||||
|
import Button from '@/components/Button';
|
||||||
|
import Card from '@/components/Card';
|
||||||
|
import Dropdown from '@/components/dropdown/Dropdown';
|
||||||
|
import DateInput from '@/components/input/DateInput';
|
||||||
|
import DebouncedTextInput from '@/components/input/DebouncedTextInput';
|
||||||
|
import SelectInput, {
|
||||||
|
OptionType,
|
||||||
|
useSelect,
|
||||||
|
} from '@/components/input/SelectInput';
|
||||||
|
import Menu from '@/components/menu/Menu';
|
||||||
|
import MenuItem from '@/components/menu/MenuItem';
|
||||||
|
import Table from '@/components/Table';
|
||||||
|
import Tooltip from '@/components/Tooltip';
|
||||||
|
import { formatCurrency, formatDate, formatTitleCase } from '@/lib/helper';
|
||||||
|
import { useTableFilter } from '@/services/hooks/useTableFilter';
|
||||||
|
import { Finance } from '@/types/api/finance/finance';
|
||||||
|
import {
|
||||||
|
FINANCE_INITIAL_BALANCE_STATUS,
|
||||||
|
FINANCE_INJECTION_STATUS,
|
||||||
|
FINANCE_TRANSACTION_STATUS,
|
||||||
|
ROWS_OPTIONS,
|
||||||
|
} from '@/config/constant';
|
||||||
|
import { FinanceApi } from '@/services/api/finance';
|
||||||
|
import { isResponseSuccess } from '@/lib/api-helper';
|
||||||
|
import { BankApi, CustomerApi, SupplierApi } from '@/services/api/master-data';
|
||||||
|
import { Bank } from '@/types/api/master-data/bank';
|
||||||
|
import { useModal } from '@/components/Modal';
|
||||||
|
import ConfirmationModal from '@/components/modal/ConfirmationModal';
|
||||||
|
import toast from 'react-hot-toast';
|
||||||
|
import RowOptionsMenuWrapper from '@/components/table/RowOptionsMenuWrapper';
|
||||||
|
import RequirePermission from '@/components/helper/RequirePermission';
|
||||||
|
import { Icon } from '@iconify/react';
|
||||||
|
import RowDropdownOptions from '@/components/table/RowDropdownOptions';
|
||||||
|
import RowCollapseOptions from '@/components/table/RowCollapseOptions';
|
||||||
|
|
||||||
|
const RowOptionsMenu = ({
|
||||||
|
type = 'dropdown',
|
||||||
|
props,
|
||||||
|
deleteClickHandler,
|
||||||
|
}: {
|
||||||
|
type: 'dropdown' | 'collapse';
|
||||||
|
props: CellContext<Finance, unknown>;
|
||||||
|
deleteClickHandler: () => void;
|
||||||
|
}) => {
|
||||||
|
return (
|
||||||
|
<RowOptionsMenuWrapper type={type}>
|
||||||
|
<RequirePermission
|
||||||
|
permissions={[
|
||||||
|
'lti.finance.transactions.detail',
|
||||||
|
'lti.finance.initial_balances.detail',
|
||||||
|
'lti.finance.injections.detail',
|
||||||
|
'lti.finance.payments.detail',
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
href={`/finance/detail?financeId=${props.row.original.id}`}
|
||||||
|
variant='ghost'
|
||||||
|
color='primary'
|
||||||
|
className='justify-start text-sm'
|
||||||
|
>
|
||||||
|
<Icon icon='mdi:eye-outline' width={16} height={16} />
|
||||||
|
Detail
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
|
|
||||||
|
{FINANCE_TRANSACTION_STATUS.includes(
|
||||||
|
props.row.original.transaction_type
|
||||||
|
) && (
|
||||||
|
<RequirePermission permissions='lti.finance.payments.update'>
|
||||||
|
<Button
|
||||||
|
href={`/finance/detail/edit?financeId=${props.row.original.id}`}
|
||||||
|
variant='ghost'
|
||||||
|
color='warning'
|
||||||
|
className='justify-start text-sm'
|
||||||
|
>
|
||||||
|
<Icon icon='material-symbols:edit-outline' width={16} height={16} />
|
||||||
|
Edit
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{FINANCE_INITIAL_BALANCE_STATUS.includes(
|
||||||
|
props.row.original.transaction_type
|
||||||
|
) && (
|
||||||
|
<RequirePermission permissions='lti.finance.initial_balances.update'>
|
||||||
|
<Button
|
||||||
|
href={`/finance/detail/edit/initial-balance?financeId=${props.row.original.id}`}
|
||||||
|
variant='ghost'
|
||||||
|
color='warning'
|
||||||
|
className='justify-start text-sm'
|
||||||
|
>
|
||||||
|
<Icon icon='material-symbols:edit-outline' width={16} height={16} />
|
||||||
|
Edit
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{FINANCE_INJECTION_STATUS.includes(
|
||||||
|
props.row.original.transaction_type
|
||||||
|
) && (
|
||||||
|
<RequirePermission permissions='lti.finance.injections.update'>
|
||||||
|
<Button
|
||||||
|
href={`/finance/detail/edit/injection?financeId=${props.row.original.id}`}
|
||||||
|
variant='ghost'
|
||||||
|
color='warning'
|
||||||
|
className='justify-start text-sm'
|
||||||
|
>
|
||||||
|
<Icon icon='material-symbols:edit-outline' width={16} height={16} />
|
||||||
|
Edit
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<RequirePermission permissions='lti.finance.transactions.delete'>
|
||||||
|
<Button
|
||||||
|
onClick={deleteClickHandler}
|
||||||
|
variant='ghost'
|
||||||
|
color='error'
|
||||||
|
className='text-error hover:text-inherit'
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
icon='material-symbols:delete-outline-rounded'
|
||||||
|
width={16}
|
||||||
|
height={16}
|
||||||
|
className='justify-start text-sm'
|
||||||
|
/>
|
||||||
|
Delete
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
|
</RowOptionsMenuWrapper>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const FinanceTable = () => {
|
||||||
|
const {
|
||||||
|
state: tableFilterState,
|
||||||
|
updateFilter,
|
||||||
|
setPage,
|
||||||
|
setPageSize,
|
||||||
|
toQueryString: getTableFilterQueryString,
|
||||||
|
} = useTableFilter({
|
||||||
|
initial: {
|
||||||
|
search: '',
|
||||||
|
transactionType: '',
|
||||||
|
bankId: '',
|
||||||
|
partyType: '',
|
||||||
|
sortBy: '',
|
||||||
|
startDate: '',
|
||||||
|
endDate: '',
|
||||||
|
},
|
||||||
|
paramMap: {
|
||||||
|
page: 'page',
|
||||||
|
pageSize: 'limit',
|
||||||
|
transactionType: 'transaction_type',
|
||||||
|
bankId: 'bank_id',
|
||||||
|
partyType: 'party_type',
|
||||||
|
sortBy: 'sort_date',
|
||||||
|
startDate: 'start_date',
|
||||||
|
endDate: 'end_date',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// ===== State =====
|
||||||
|
const [searchParams, setSearchParams] = useSearchParams();
|
||||||
|
const deleteModal = useModal();
|
||||||
|
const [pendingFilters, setPendingFilters] = useState({
|
||||||
|
search: '',
|
||||||
|
transactionType: '',
|
||||||
|
bankId: '',
|
||||||
|
partyType: '',
|
||||||
|
sortBy: '',
|
||||||
|
startDate: '',
|
||||||
|
endDate: '',
|
||||||
|
});
|
||||||
|
const [selectedTransactionType, setSelectedTransactionType] =
|
||||||
|
useState<OptionType | null>(null);
|
||||||
|
const [selectedBank, setSelectedBank] = useState<OptionType | null>(null);
|
||||||
|
const [selectedPartyType, setSelectedPartyType] = useState<OptionType | null>(
|
||||||
|
null
|
||||||
|
);
|
||||||
|
const [selectedSortBy, setSelectedSortBy] = useState<OptionType | null>(null);
|
||||||
|
const [selectedFinance, setSelectedFinance] = useState<Finance | null>(null);
|
||||||
|
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
|
||||||
|
|
||||||
|
// ===== Fetch Data =====
|
||||||
|
const {
|
||||||
|
data: finances,
|
||||||
|
isLoading,
|
||||||
|
mutate: refreshFinances,
|
||||||
|
} = useSWR(
|
||||||
|
`${FinanceApi.basePath}/transactions${getTableFilterQueryString()}`,
|
||||||
|
FinanceApi.getAllFetcher
|
||||||
|
);
|
||||||
|
|
||||||
|
// ===== Options =====
|
||||||
|
const transactionTypeOptions = useMemo(() => {
|
||||||
|
return [
|
||||||
|
{ label: 'Transfer', value: 'TRANSFER' },
|
||||||
|
{ label: 'Cash', value: 'CASH' },
|
||||||
|
{ label: 'Card', value: 'CARD' },
|
||||||
|
{ label: 'Cheque', value: 'CHEQUE' },
|
||||||
|
{ label: 'Saldo', value: 'SALDO' },
|
||||||
|
];
|
||||||
|
}, []);
|
||||||
|
const partyTypeOptions = useMemo(() => {
|
||||||
|
return [
|
||||||
|
{ label: 'Customer', value: 'CUSTOMER' },
|
||||||
|
{ label: 'Supplier', value: 'SUPPLIER' },
|
||||||
|
];
|
||||||
|
}, []);
|
||||||
|
const sortByOptions = useMemo(() => {
|
||||||
|
return [
|
||||||
|
{ label: 'Tanggal Pembayaran', value: 'payment_date' },
|
||||||
|
{ label: 'Tanggal Dibuat', value: 'created_at' },
|
||||||
|
];
|
||||||
|
}, []);
|
||||||
|
const { options: bankOptions, rawData: bankRawData } = useSelect<Bank>(
|
||||||
|
BankApi.basePath,
|
||||||
|
'id',
|
||||||
|
'alias',
|
||||||
|
'',
|
||||||
|
{
|
||||||
|
limit: 'limit',
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// ===== Handler =====
|
||||||
|
const searchChangeHandler: ChangeEventHandler<HTMLInputElement> = (e) => {
|
||||||
|
setPendingFilters((prev) => ({ ...prev, search: e.target.value }));
|
||||||
|
};
|
||||||
|
const transactionTypeChangeHandler = (
|
||||||
|
val: OptionType | OptionType[] | null
|
||||||
|
) => {
|
||||||
|
setSelectedTransactionType(val as OptionType);
|
||||||
|
setPendingFilters((prev) => ({
|
||||||
|
...prev,
|
||||||
|
transactionType: val ? ((val as OptionType).value as string) : '',
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
const bankChangeHandler = (val: OptionType | OptionType[] | null) => {
|
||||||
|
setSelectedBank(val as OptionType);
|
||||||
|
setPendingFilters((prev) => ({
|
||||||
|
...prev,
|
||||||
|
bankId: val ? ((val as OptionType).value as string) : '',
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
const partyTypeChangeHandler = (val: OptionType | OptionType[] | null) => {
|
||||||
|
setSelectedPartyType(val as OptionType);
|
||||||
|
setPendingFilters((prev) => ({
|
||||||
|
...prev,
|
||||||
|
partyType: val ? ((val as OptionType).value as string) : '',
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
const sortByChangeHandler = (val: OptionType | OptionType[] | null) => {
|
||||||
|
setSelectedSortBy(val as OptionType);
|
||||||
|
setPendingFilters((prev) => ({
|
||||||
|
...prev,
|
||||||
|
sortBy: val ? ((val as OptionType).value as string) : '',
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
const startDateChangeHandler: ChangeEventHandler<HTMLInputElement> = (e) => {
|
||||||
|
setPendingFilters((prev) => ({ ...prev, startDate: e.target.value }));
|
||||||
|
};
|
||||||
|
const endDateChangeHandler: ChangeEventHandler<HTMLInputElement> = (e) => {
|
||||||
|
setPendingFilters((prev) => ({ ...prev, endDate: e.target.value }));
|
||||||
|
};
|
||||||
|
const pageSizeChangeHandler = (val: OptionType | OptionType[] | null) => {
|
||||||
|
const newVal = val as OptionType;
|
||||||
|
setPageSize(newVal.value as number);
|
||||||
|
};
|
||||||
|
const submitFilterHandler = () => {
|
||||||
|
updateFilter('search', pendingFilters.search);
|
||||||
|
updateFilter('transactionType', pendingFilters.transactionType);
|
||||||
|
updateFilter('bankId', pendingFilters.bankId);
|
||||||
|
updateFilter('partyType', pendingFilters.partyType);
|
||||||
|
updateFilter('sortBy', pendingFilters.sortBy);
|
||||||
|
updateFilter('startDate', pendingFilters.startDate);
|
||||||
|
updateFilter('endDate', pendingFilters.endDate);
|
||||||
|
};
|
||||||
|
const resetFilterHandler = () => {
|
||||||
|
setSelectedTransactionType(null);
|
||||||
|
setSelectedBank(null);
|
||||||
|
setSelectedPartyType(null);
|
||||||
|
setSelectedSortBy(null);
|
||||||
|
|
||||||
|
const emptyFilters = {
|
||||||
|
search: '',
|
||||||
|
transactionType: '',
|
||||||
|
bankId: '',
|
||||||
|
partyType: '',
|
||||||
|
sortBy: '',
|
||||||
|
startDate: '',
|
||||||
|
endDate: '',
|
||||||
|
};
|
||||||
|
setPendingFilters(emptyFilters);
|
||||||
|
|
||||||
|
updateFilter('search', '');
|
||||||
|
updateFilter('transactionType', '');
|
||||||
|
updateFilter('bankId', '');
|
||||||
|
updateFilter('partyType', '');
|
||||||
|
updateFilter('sortBy', '');
|
||||||
|
updateFilter('startDate', '');
|
||||||
|
updateFilter('endDate', '');
|
||||||
|
};
|
||||||
|
const confirmationModalDeleteClickHandler = async () => {
|
||||||
|
setIsDeleteLoading(true);
|
||||||
|
|
||||||
|
await FinanceApi.delete(selectedFinance?.id as number);
|
||||||
|
refreshFinances();
|
||||||
|
|
||||||
|
deleteModal.closeModal();
|
||||||
|
toast.success('Successfully delete Finance!');
|
||||||
|
setIsDeleteLoading(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const columns = useMemo(() => {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
header: 'ID',
|
||||||
|
accessorKey: 'payment_code',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: 'References Number',
|
||||||
|
accessorKey: 'reference_number',
|
||||||
|
cell: (props: CellContext<Finance, unknown>) => {
|
||||||
|
const value = props.row.original.reference_number;
|
||||||
|
return <span>{value ?? '-'}</span>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: 'Jenis Transaksi',
|
||||||
|
accessorKey: 'transaction_type',
|
||||||
|
cell: (props: CellContext<Finance, unknown>) => {
|
||||||
|
const value = props.row.original.transaction_type
|
||||||
|
.split('_')
|
||||||
|
.join(' ');
|
||||||
|
return <span>{formatTitleCase(value)}</span>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: 'Pihak',
|
||||||
|
accessorFn: (finance: Finance) => finance.party.name,
|
||||||
|
cell: (props: CellContext<Finance, unknown>) => {
|
||||||
|
if (props.row.original.party.id) {
|
||||||
|
return <span>{props.row.original.party.name}</span>;
|
||||||
|
}
|
||||||
|
return <span>{'-'}</span>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: 'Tanggal',
|
||||||
|
accessorFn: (finance: Finance) =>
|
||||||
|
formatDate(finance.payment_date, 'DD MMM YYYY'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: 'Metode Pembayaran',
|
||||||
|
accessorKey: 'payment_method',
|
||||||
|
cell: (props: CellContext<Finance, unknown>) => {
|
||||||
|
const value = props.row.original.payment_method.split('_').join(' ');
|
||||||
|
return <span>{formatTitleCase(value)}</span>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: 'Bank',
|
||||||
|
accessorFn: (finance: Finance) =>
|
||||||
|
`${finance.bank.alias} - ${finance.bank.account_number} - ${finance.bank.owner}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: 'Pengeluaran (Rp)',
|
||||||
|
accessorFn: (finance: Finance) =>
|
||||||
|
formatCurrency(finance.expense_amount),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: 'Pemasukan (Rp)',
|
||||||
|
accessorFn: (finance: Finance) => formatCurrency(finance.income_amount),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: 'Aksi',
|
||||||
|
cell: (props: CellContext<Finance, unknown>) => {
|
||||||
|
const currentPageSize =
|
||||||
|
props.table.getPaginationRowModel().rows.length;
|
||||||
|
const currentPageRows = props.table.getPaginationRowModel().flatRows;
|
||||||
|
const currentRowRelativeIndex =
|
||||||
|
currentPageRows.findIndex((r) => r.id === props.row.id) + 1;
|
||||||
|
|
||||||
|
const isLast2Rows = currentRowRelativeIndex > currentPageSize - 2;
|
||||||
|
|
||||||
|
const deleteClickHandler = () => {
|
||||||
|
setSelectedFinance(props.row.original);
|
||||||
|
deleteModal.openModal();
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{currentPageSize > 2 && (
|
||||||
|
<RowDropdownOptions isLast2Rows={isLast2Rows}>
|
||||||
|
<RowOptionsMenu
|
||||||
|
type='dropdown'
|
||||||
|
props={props}
|
||||||
|
deleteClickHandler={deleteClickHandler}
|
||||||
|
/>
|
||||||
|
</RowDropdownOptions>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{currentPageSize <= 2 && (
|
||||||
|
<RowCollapseOptions>
|
||||||
|
<RowOptionsMenu
|
||||||
|
type='collapse'
|
||||||
|
props={props}
|
||||||
|
deleteClickHandler={deleteClickHandler}
|
||||||
|
/>
|
||||||
|
</RowCollapseOptions>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}, []);
|
||||||
|
return (
|
||||||
|
<section className='size-full p-6 flex flex-col gap-6'>
|
||||||
|
<div className='flex justify-end gap-2'>
|
||||||
|
<RequirePermission permissions='lti.finance.injections.create'>
|
||||||
|
<Button
|
||||||
|
color='warning'
|
||||||
|
className='min-w-24'
|
||||||
|
href='/finance/add/injection'
|
||||||
|
>
|
||||||
|
Injection Saldo Bank
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
|
<RequirePermission permissions='lti.finance.initial_balances.create'>
|
||||||
|
<Button
|
||||||
|
color='info'
|
||||||
|
className='text-white min-w-24'
|
||||||
|
href='/finance/add/initial-balance'
|
||||||
|
>
|
||||||
|
Saldo Awal
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
|
<RequirePermission permissions='lti.finance.payments.create'>
|
||||||
|
<Button color='primary' className='min-w-24' href='/finance/add'>
|
||||||
|
Tambah
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
|
</div>
|
||||||
|
<Card
|
||||||
|
variant='bordered'
|
||||||
|
className={{
|
||||||
|
wrapper: 'w-full',
|
||||||
|
}}
|
||||||
|
footer={
|
||||||
|
<div className='flex justify-end gap-2'>
|
||||||
|
<Button
|
||||||
|
color='warning'
|
||||||
|
className='min-w-24'
|
||||||
|
onClick={resetFilterHandler}
|
||||||
|
>
|
||||||
|
Reset
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
color='primary'
|
||||||
|
className='min-w-24'
|
||||||
|
onClick={submitFilterHandler}
|
||||||
|
>
|
||||||
|
Cari
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<div className='grid grid-cols-4 gap-6'>
|
||||||
|
<SelectInput
|
||||||
|
options={transactionTypeOptions}
|
||||||
|
label='Jenis Transaksi'
|
||||||
|
value={selectedTransactionType}
|
||||||
|
onChange={transactionTypeChangeHandler}
|
||||||
|
isClearable
|
||||||
|
/>
|
||||||
|
<SelectInput
|
||||||
|
options={
|
||||||
|
isResponseSuccess(bankRawData)
|
||||||
|
? bankOptions.map((bank) => ({
|
||||||
|
label:
|
||||||
|
bankRawData.data.find((data) => data.id === bank.value)
|
||||||
|
?.alias +
|
||||||
|
' - ' +
|
||||||
|
bankRawData.data.find((data) => data.id === bank.value)
|
||||||
|
?.account_number +
|
||||||
|
' - ' +
|
||||||
|
bankRawData.data.find((data) => data.id === bank.value)
|
||||||
|
?.owner,
|
||||||
|
value: bank.value,
|
||||||
|
}))
|
||||||
|
: []
|
||||||
|
}
|
||||||
|
label='Bank'
|
||||||
|
value={selectedBank}
|
||||||
|
onChange={bankChangeHandler}
|
||||||
|
isClearable
|
||||||
|
/>
|
||||||
|
<SelectInput
|
||||||
|
options={partyTypeOptions}
|
||||||
|
label='Pihak'
|
||||||
|
value={selectedPartyType}
|
||||||
|
onChange={partyTypeChangeHandler}
|
||||||
|
isClearable
|
||||||
|
/>
|
||||||
|
<DebouncedTextInput
|
||||||
|
name='search'
|
||||||
|
label='Cari'
|
||||||
|
placeholder='Cari'
|
||||||
|
value={pendingFilters.search}
|
||||||
|
onChange={searchChangeHandler}
|
||||||
|
/>
|
||||||
|
<SelectInput
|
||||||
|
options={sortByOptions}
|
||||||
|
label='Urutkan Berdasarkan'
|
||||||
|
value={selectedSortBy}
|
||||||
|
onChange={sortByChangeHandler}
|
||||||
|
isClearable
|
||||||
|
/>
|
||||||
|
<DateInput
|
||||||
|
name='startDate'
|
||||||
|
label='Periode Tanggal (Mulai)'
|
||||||
|
value={pendingFilters.startDate}
|
||||||
|
onChange={startDateChangeHandler}
|
||||||
|
/>
|
||||||
|
<DateInput
|
||||||
|
name='endDate'
|
||||||
|
label='Periode Tanggal (Akhir)'
|
||||||
|
value={pendingFilters.endDate}
|
||||||
|
onChange={endDateChangeHandler}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
<Table<Finance>
|
||||||
|
data={isResponseSuccess(finances) ? finances.data : []}
|
||||||
|
columns={columns}
|
||||||
|
pageSize={tableFilterState.pageSize}
|
||||||
|
page={tableFilterState.page}
|
||||||
|
onPageChange={setPage}
|
||||||
|
onPageSizeChange={setPageSize}
|
||||||
|
totalItems={
|
||||||
|
isResponseSuccess(finances) ? finances.meta?.total_results : 0
|
||||||
|
}
|
||||||
|
isLoading={isLoading}
|
||||||
|
/>
|
||||||
|
<ConfirmationModal
|
||||||
|
ref={deleteModal.ref}
|
||||||
|
type='error'
|
||||||
|
text={`Apakah anda yakin ingin menghapus data Finance ini (${selectedFinance?.payment_code})?`}
|
||||||
|
secondaryButton={{
|
||||||
|
text: 'Tidak',
|
||||||
|
}}
|
||||||
|
primaryButton={{
|
||||||
|
text: 'Ya',
|
||||||
|
color: 'error',
|
||||||
|
isLoading: isDeleteLoading,
|
||||||
|
onClick: confirmationModalDeleteClickHandler,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default FinanceTable;
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
import * as Yup from 'yup';
|
||||||
|
import { OptionType } from '@/components/input/SelectInput';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API Payload format:
|
||||||
|
* {
|
||||||
|
"party_id": 1,
|
||||||
|
"party_type": "CUSTOMER",
|
||||||
|
"payment_date": "2025-11-21",
|
||||||
|
"payment_method": "Transfer",
|
||||||
|
"bank_id": 1,
|
||||||
|
"reference_number": "DO.MBU.123",
|
||||||
|
"nominal": 25000000,
|
||||||
|
"notes": "Pembayaran piutang penjualan telur"
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Type for form values (includes option objects for SelectInput)
|
||||||
|
export type FinanceFormValues = {
|
||||||
|
party_type_option: OptionType | null;
|
||||||
|
party_id_option: OptionType | null;
|
||||||
|
party_account_number: string;
|
||||||
|
payment_date: string;
|
||||||
|
payment_method_option: OptionType | null;
|
||||||
|
bank_id_option: OptionType | null;
|
||||||
|
reference_number: string;
|
||||||
|
nominal: string;
|
||||||
|
notes: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const FinanceFormSchema = Yup.object().shape({
|
||||||
|
party_type_option: Yup.mixed()
|
||||||
|
.nullable()
|
||||||
|
.test(
|
||||||
|
'is-valid-option',
|
||||||
|
'Jenis transaksi wajib diisi',
|
||||||
|
(value) => value !== null && value !== undefined
|
||||||
|
),
|
||||||
|
party_id_option: Yup.mixed()
|
||||||
|
.nullable()
|
||||||
|
.test(
|
||||||
|
'is-valid-option',
|
||||||
|
'Pihak wajib diisi',
|
||||||
|
(value) => value !== null && value !== undefined
|
||||||
|
),
|
||||||
|
party_account_number: Yup.string().required('Nomor rekening wajib diisi'),
|
||||||
|
payment_date: Yup.string().required('Tanggal pembayaran wajib diisi'),
|
||||||
|
payment_method_option: Yup.mixed()
|
||||||
|
.nullable()
|
||||||
|
.test(
|
||||||
|
'is-valid-option',
|
||||||
|
'Metode pembayaran wajib diisi',
|
||||||
|
(value) => value !== null && value !== undefined
|
||||||
|
),
|
||||||
|
bank_id_option: Yup.mixed()
|
||||||
|
.nullable()
|
||||||
|
.test(
|
||||||
|
'is-valid-option',
|
||||||
|
'Bank wajib diisi',
|
||||||
|
(value) => value !== null && value !== undefined
|
||||||
|
),
|
||||||
|
reference_number: Yup.string().required('Nomor referensi wajib diisi'),
|
||||||
|
nominal: Yup.string().required('Nominal wajib diisi'),
|
||||||
|
notes: Yup.string().required('Catatan wajib diisi'),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const UpdateFinanceFormSchema = FinanceFormSchema;
|
||||||
@@ -0,0 +1,417 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import Button from '@/components/Button';
|
||||||
|
import AlertErrorList from '@/components/helper/form/FormErrors';
|
||||||
|
import { FormHeader } from '@/components/helper/form/FormHeader';
|
||||||
|
import DateInput from '@/components/input/DateInput';
|
||||||
|
import NumberInput from '@/components/input/NumberInput';
|
||||||
|
import SelectInput, {
|
||||||
|
OptionType,
|
||||||
|
useSelect,
|
||||||
|
} from '@/components/input/SelectInput';
|
||||||
|
import TextArea from '@/components/input/TextArea';
|
||||||
|
import TextInput from '@/components/input/TextInput';
|
||||||
|
import {
|
||||||
|
FinanceFormSchema,
|
||||||
|
FinanceFormValues,
|
||||||
|
} from '@/components/pages/finance/add/FormFinanceAdd.schema';
|
||||||
|
import {
|
||||||
|
FINANCE_PARTY_TYPE_OPTIONS,
|
||||||
|
FINANCE_PAYMENT_METHOD_OPTIONS,
|
||||||
|
} from '@/config/constant';
|
||||||
|
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
||||||
|
import { formatDate, formatTitleCase } from '@/lib/helper';
|
||||||
|
import { useFormikErrorList } from '@/services/hooks/useFormikErrorList';
|
||||||
|
import { FinanceApi } from '@/services/api/finance';
|
||||||
|
import { BankApi, CustomerApi, SupplierApi } from '@/services/api/master-data';
|
||||||
|
import {
|
||||||
|
CreateFinancePayment,
|
||||||
|
Finance,
|
||||||
|
UpdateFinancePayment,
|
||||||
|
} from '@/types/api/finance/finance';
|
||||||
|
import { Bank } from '@/types/api/master-data/bank';
|
||||||
|
import { useFormik } from 'formik';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import { useCallback, useMemo } from 'react';
|
||||||
|
import toast from 'react-hot-toast';
|
||||||
|
|
||||||
|
interface FormFinanceAddProps {
|
||||||
|
type?: 'add' | 'edit';
|
||||||
|
initialValues?: Finance;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PartyCommonProps {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
account_number: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const FormFinanceAdd = ({
|
||||||
|
type = 'add',
|
||||||
|
initialValues,
|
||||||
|
}: FormFinanceAddProps) => {
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
// ===== Formik =====
|
||||||
|
const formikInitialValues = useMemo((): FinanceFormValues => {
|
||||||
|
return {
|
||||||
|
party_type_option:
|
||||||
|
FINANCE_PARTY_TYPE_OPTIONS.find(
|
||||||
|
(option) => option.value === initialValues?.party.type
|
||||||
|
) || null,
|
||||||
|
party_id_option: initialValues?.party
|
||||||
|
? {
|
||||||
|
label: initialValues?.party.name || '',
|
||||||
|
value: initialValues?.party.id || 0,
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
payment_date: initialValues?.payment_date || '',
|
||||||
|
payment_method_option:
|
||||||
|
FINANCE_PAYMENT_METHOD_OPTIONS.find(
|
||||||
|
(option) => option.value === initialValues?.payment_method
|
||||||
|
) || null,
|
||||||
|
bank_id_option: initialValues?.bank
|
||||||
|
? {
|
||||||
|
label: initialValues.bank.name,
|
||||||
|
value: initialValues.bank.id,
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
party_account_number: initialValues?.party.account_number || '',
|
||||||
|
reference_number: initialValues?.reference_number || '',
|
||||||
|
nominal: initialValues?.nominal.toString() || '',
|
||||||
|
notes: initialValues?.notes || '',
|
||||||
|
};
|
||||||
|
}, [initialValues]);
|
||||||
|
|
||||||
|
const formik = useFormik<FinanceFormValues>({
|
||||||
|
initialValues: formikInitialValues,
|
||||||
|
validationSchema: FinanceFormSchema,
|
||||||
|
validateOnChange: true,
|
||||||
|
validateOnBlur: true,
|
||||||
|
onSubmit: async (values) => {
|
||||||
|
const payload = transformFormValuesToPayload(values);
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case 'add':
|
||||||
|
await createFinance(payload);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'edit':
|
||||||
|
if (initialValues?.id) {
|
||||||
|
await updateFinance(initialValues.id, payload);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// ===== Formik Error List =====
|
||||||
|
const { formErrorList, close, handleFormSubmit } = useFormikErrorList(formik);
|
||||||
|
|
||||||
|
// ===== Options =====
|
||||||
|
const {
|
||||||
|
options: partyOptions,
|
||||||
|
isLoadingOptions: isLoadingPartyOptions,
|
||||||
|
rawData: partyRawData,
|
||||||
|
} = useSelect<PartyCommonProps>(
|
||||||
|
formik.values.party_type_option?.value === 'CUSTOMER'
|
||||||
|
? CustomerApi.basePath
|
||||||
|
: SupplierApi.basePath,
|
||||||
|
'id',
|
||||||
|
'name',
|
||||||
|
'',
|
||||||
|
{ limit: 'limit' }
|
||||||
|
);
|
||||||
|
const {
|
||||||
|
options: bankOptions,
|
||||||
|
rawData: bankRawData,
|
||||||
|
isLoadingOptions: isLoadingBankOptions,
|
||||||
|
} = useSelect<Bank>(BankApi.basePath, 'id', 'name', '', { limit: 'limit' });
|
||||||
|
|
||||||
|
// ===== Helper Functions =====
|
||||||
|
const transformFormValuesToPayload = (
|
||||||
|
values: FinanceFormValues
|
||||||
|
): CreateFinancePayment => {
|
||||||
|
return {
|
||||||
|
party_id: Number(values.party_id_option?.value) || 0,
|
||||||
|
party_type: (values.party_type_option?.value as string) || '',
|
||||||
|
payment_date: formatDate(values.payment_date, 'YYYY-MM-DD'),
|
||||||
|
payment_method: (values.payment_method_option?.value as string) || '',
|
||||||
|
bank_id: Number(values.bank_id_option?.value) || 0,
|
||||||
|
reference_number: values.reference_number,
|
||||||
|
nominal: Number(values.nominal.replace(/\D/g, '')) || 0,
|
||||||
|
notes: values.notes,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// ===== Handler =====
|
||||||
|
const createFinance = useCallback(
|
||||||
|
async (payload: CreateFinancePayment) => {
|
||||||
|
const response = await FinanceApi.create(payload);
|
||||||
|
|
||||||
|
if (isResponseError(response)) {
|
||||||
|
toast.error(response.message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
toast.success('Data berhasil ditambahkan');
|
||||||
|
router.refresh();
|
||||||
|
router.push('/finance');
|
||||||
|
},
|
||||||
|
[router]
|
||||||
|
);
|
||||||
|
const updateFinance = useCallback(
|
||||||
|
async (financeId: number, payload: UpdateFinancePayment) => {
|
||||||
|
const response = await FinanceApi.update(financeId, payload);
|
||||||
|
|
||||||
|
if (isResponseError(response)) {
|
||||||
|
toast.error(response.message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
toast.success('Data berhasil diperbarui');
|
||||||
|
router.refresh();
|
||||||
|
router.push('/finance');
|
||||||
|
},
|
||||||
|
[router]
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<section className='w-full max-w-xl mx-auto'>
|
||||||
|
<div className='flex flex-col gap-6 p-6'>
|
||||||
|
<FormHeader
|
||||||
|
title={`${type === 'add' ? 'Tambah' : 'Ubah'} Data Keuangan`}
|
||||||
|
backUrl='/finance'
|
||||||
|
/>
|
||||||
|
<form className='flex flex-col gap-4' onSubmit={handleFormSubmit}>
|
||||||
|
<SelectInput
|
||||||
|
label='Jenis Transaksi'
|
||||||
|
placeholder='Pilih jenis transaksi'
|
||||||
|
options={FINANCE_PARTY_TYPE_OPTIONS}
|
||||||
|
value={formik.values.party_type_option}
|
||||||
|
onChange={(value) => {
|
||||||
|
formik.setFieldValue('party_type_option', value);
|
||||||
|
formik.setFieldValue('party_id_option', null);
|
||||||
|
formik.setFieldValue('party_account_number', '');
|
||||||
|
}}
|
||||||
|
isError={Boolean(
|
||||||
|
formik.touched.party_type_option &&
|
||||||
|
formik.errors.party_type_option
|
||||||
|
)}
|
||||||
|
errorMessage={
|
||||||
|
formik.touched.party_type_option &&
|
||||||
|
formik.errors.party_type_option
|
||||||
|
? formik.errors.party_type_option
|
||||||
|
: ''
|
||||||
|
}
|
||||||
|
required
|
||||||
|
isClearable
|
||||||
|
/>
|
||||||
|
<SelectInput
|
||||||
|
label={
|
||||||
|
formik.values.party_type_option?.value
|
||||||
|
? formatTitleCase(
|
||||||
|
formik.values.party_type_option.value as string
|
||||||
|
)
|
||||||
|
: 'Pilih Jenis Transaksi Dahulu'
|
||||||
|
}
|
||||||
|
placeholder={`Pilih ${formik.values.party_type_option?.value ? formatTitleCase(formik.values.party_type_option.value as string) : 'jenis transaksi dahulu'}`}
|
||||||
|
options={partyOptions}
|
||||||
|
value={formik.values.party_id_option}
|
||||||
|
onChange={(value) => {
|
||||||
|
formik.setFieldValue('party_id_option', value);
|
||||||
|
if (isResponseSuccess(partyRawData) && value) {
|
||||||
|
formik.setFieldValue(
|
||||||
|
'party_account_number',
|
||||||
|
partyRawData.data?.find(
|
||||||
|
(item) => item.id === (value as OptionType)?.value
|
||||||
|
)?.account_number || ''
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
isLoading={isLoadingPartyOptions}
|
||||||
|
isError={Boolean(
|
||||||
|
formik.touched.party_id_option && formik.errors.party_id_option
|
||||||
|
)}
|
||||||
|
errorMessage={
|
||||||
|
formik.touched.party_id_option && formik.errors.party_id_option
|
||||||
|
? formik.errors.party_id_option
|
||||||
|
: ''
|
||||||
|
}
|
||||||
|
required
|
||||||
|
isClearable
|
||||||
|
isDisabled={!formik.values.party_type_option?.value}
|
||||||
|
/>
|
||||||
|
<DateInput
|
||||||
|
label='Tanggal'
|
||||||
|
placeholder='Pilih tanggal'
|
||||||
|
name='payment_date'
|
||||||
|
value={formik.values.payment_date}
|
||||||
|
onChange={formik.handleChange}
|
||||||
|
onBlur={formik.handleBlur}
|
||||||
|
isError={Boolean(
|
||||||
|
formik.touched.payment_date && formik.errors.payment_date
|
||||||
|
)}
|
||||||
|
errorMessage={
|
||||||
|
formik.touched.payment_date && formik.errors.payment_date
|
||||||
|
? formik.errors.payment_date
|
||||||
|
: ''
|
||||||
|
}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<SelectInput
|
||||||
|
label='Metode Pembayaran'
|
||||||
|
placeholder='Pilih metode pembayaran'
|
||||||
|
options={FINANCE_PAYMENT_METHOD_OPTIONS}
|
||||||
|
value={formik.values.payment_method_option}
|
||||||
|
onChange={(value) => {
|
||||||
|
formik.setFieldValue('payment_method_option', value);
|
||||||
|
}}
|
||||||
|
isError={Boolean(
|
||||||
|
formik.touched.payment_method_option &&
|
||||||
|
formik.errors.payment_method_option
|
||||||
|
)}
|
||||||
|
errorMessage={
|
||||||
|
formik.touched.payment_method_option &&
|
||||||
|
formik.errors.payment_method_option
|
||||||
|
? formik.errors.payment_method_option
|
||||||
|
: ''
|
||||||
|
}
|
||||||
|
required
|
||||||
|
isClearable
|
||||||
|
/>
|
||||||
|
<SelectInput
|
||||||
|
label='Bank'
|
||||||
|
placeholder='Pilih bank'
|
||||||
|
options={
|
||||||
|
isResponseSuccess(bankRawData)
|
||||||
|
? bankOptions.map((option) => ({
|
||||||
|
label:
|
||||||
|
bankRawData.data?.find(
|
||||||
|
(item) => item.id === option.value
|
||||||
|
)?.alias +
|
||||||
|
' - ' +
|
||||||
|
bankRawData.data?.find(
|
||||||
|
(item) => item.id === option.value
|
||||||
|
)?.account_number +
|
||||||
|
' - ' +
|
||||||
|
bankRawData.data?.find(
|
||||||
|
(item) => item.id === option.value
|
||||||
|
)?.owner,
|
||||||
|
value: option.value,
|
||||||
|
}))
|
||||||
|
: []
|
||||||
|
}
|
||||||
|
value={formik.values.bank_id_option}
|
||||||
|
onChange={(value) => {
|
||||||
|
formik.setFieldValue('bank_id_option', value);
|
||||||
|
}}
|
||||||
|
isLoading={isLoadingBankOptions}
|
||||||
|
isError={Boolean(
|
||||||
|
formik.touched.bank_id_option && formik.errors.bank_id_option
|
||||||
|
)}
|
||||||
|
errorMessage={
|
||||||
|
formik.touched.bank_id_option && formik.errors.bank_id_option
|
||||||
|
? formik.errors.bank_id_option
|
||||||
|
: ''
|
||||||
|
}
|
||||||
|
required
|
||||||
|
isClearable
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
label={`Nomor Rekening ${formik.values.party_type_option?.value ? formatTitleCase(formik.values.party_type_option.value as string) : 'Pihak'}`}
|
||||||
|
placeholder={`Masukkan nomor rekening ${formik.values.party_type_option?.value ? formatTitleCase(formik.values.party_type_option.value as string) : 'pihak'}`}
|
||||||
|
name='party_account_number'
|
||||||
|
value={formik.values.party_account_number}
|
||||||
|
onChange={formik.handleChange}
|
||||||
|
onBlur={formik.handleBlur}
|
||||||
|
isError={Boolean(
|
||||||
|
formik.touched.party_account_number &&
|
||||||
|
formik.errors.party_account_number
|
||||||
|
)}
|
||||||
|
errorMessage={
|
||||||
|
formik.touched.party_account_number &&
|
||||||
|
formik.errors.party_account_number
|
||||||
|
? formik.errors.party_account_number
|
||||||
|
: ''
|
||||||
|
}
|
||||||
|
required
|
||||||
|
readOnly
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
label='Nomor Referensi'
|
||||||
|
placeholder='Masukkan nomor referensi'
|
||||||
|
name='reference_number'
|
||||||
|
value={formik.values.reference_number}
|
||||||
|
onChange={formik.handleChange}
|
||||||
|
onBlur={formik.handleBlur}
|
||||||
|
isError={Boolean(
|
||||||
|
formik.touched.reference_number &&
|
||||||
|
formik.errors.reference_number
|
||||||
|
)}
|
||||||
|
errorMessage={
|
||||||
|
formik.touched.reference_number &&
|
||||||
|
formik.errors.reference_number
|
||||||
|
? formik.errors.reference_number
|
||||||
|
: ''
|
||||||
|
}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<NumberInput
|
||||||
|
label='Nominal'
|
||||||
|
placeholder='Masukkan nominal'
|
||||||
|
name='nominal'
|
||||||
|
value={formik.values.nominal}
|
||||||
|
onChange={formik.handleChange}
|
||||||
|
onBlur={formik.handleBlur}
|
||||||
|
isError={Boolean(formik.touched.nominal && formik.errors.nominal)}
|
||||||
|
errorMessage={
|
||||||
|
formik.touched.nominal && formik.errors.nominal
|
||||||
|
? formik.errors.nominal
|
||||||
|
: ''
|
||||||
|
}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<TextArea
|
||||||
|
label='Catatan'
|
||||||
|
placeholder='Masukkan catatan'
|
||||||
|
name='notes'
|
||||||
|
value={formik.values.notes}
|
||||||
|
onChange={formik.handleChange}
|
||||||
|
onBlur={formik.handleBlur}
|
||||||
|
isError={Boolean(formik.touched.notes && formik.errors.notes)}
|
||||||
|
errorMessage={
|
||||||
|
formik.touched.notes && formik.errors.notes
|
||||||
|
? formik.errors.notes
|
||||||
|
: ''
|
||||||
|
}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<AlertErrorList formErrorList={formErrorList} onClose={close} />
|
||||||
|
<div className='flex justify-center gap-4'>
|
||||||
|
<Button
|
||||||
|
type='reset'
|
||||||
|
color='warning'
|
||||||
|
className='w-min-24'
|
||||||
|
onClick={() => formik.resetForm()}
|
||||||
|
disabled={formik.isSubmitting}
|
||||||
|
>
|
||||||
|
Reset
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type='submit'
|
||||||
|
className='w-min-24'
|
||||||
|
disabled={formik.isSubmitting || !formik.isValid}
|
||||||
|
>
|
||||||
|
Submit
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default FormFinanceAdd;
|
||||||
+49
@@ -0,0 +1,49 @@
|
|||||||
|
import * as Yup from 'yup';
|
||||||
|
import { OptionType } from '@/components/input/SelectInput';
|
||||||
|
|
||||||
|
// Type for form values (includes option objects for SelectInput)
|
||||||
|
export type InitialBalanceFormValues = {
|
||||||
|
party_type_option: OptionType | null;
|
||||||
|
party_id_option: OptionType | null;
|
||||||
|
bank_id_option: OptionType | null;
|
||||||
|
reference_number: string;
|
||||||
|
initial_balance_type_option: OptionType | null;
|
||||||
|
nominal: string;
|
||||||
|
note: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const InitialBalanceFormSchema = Yup.object().shape({
|
||||||
|
party_type_option: Yup.mixed()
|
||||||
|
.nullable()
|
||||||
|
.test(
|
||||||
|
'is-valid-option',
|
||||||
|
'Jenis pihak wajib diisi',
|
||||||
|
(value) => value !== null && value !== undefined
|
||||||
|
),
|
||||||
|
party_id_option: Yup.mixed()
|
||||||
|
.nullable()
|
||||||
|
.test(
|
||||||
|
'is-valid-option',
|
||||||
|
'Pihak wajib diisi',
|
||||||
|
(value) => value !== null && value !== undefined
|
||||||
|
),
|
||||||
|
bank_id_option: Yup.mixed()
|
||||||
|
.nullable()
|
||||||
|
.test(
|
||||||
|
'is-valid-option',
|
||||||
|
'Bank wajib diisi',
|
||||||
|
(value) => value !== null && value !== undefined
|
||||||
|
),
|
||||||
|
reference_number: Yup.string().required('Nomor referensi wajib diisi'),
|
||||||
|
initial_balance_type_option: Yup.mixed()
|
||||||
|
.nullable()
|
||||||
|
.test(
|
||||||
|
'is-valid-option',
|
||||||
|
'Tipe saldo awal wajib diisi',
|
||||||
|
(value) => value !== null && value !== undefined
|
||||||
|
),
|
||||||
|
nominal: Yup.string().required('Nominal wajib diisi'),
|
||||||
|
note: Yup.string().required('Catatan wajib diisi'),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const UpdateInitialBalanceFormSchema = InitialBalanceFormSchema;
|
||||||
@@ -0,0 +1,383 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import Button from '@/components/Button';
|
||||||
|
import AlertErrorList from '@/components/helper/form/FormErrors';
|
||||||
|
import { FormHeader } from '@/components/helper/form/FormHeader';
|
||||||
|
import NumberInput from '@/components/input/NumberInput';
|
||||||
|
import SelectInput, { useSelect } from '@/components/input/SelectInput';
|
||||||
|
import TextArea from '@/components/input/TextArea';
|
||||||
|
import TextInput from '@/components/input/TextInput';
|
||||||
|
import {
|
||||||
|
InitialBalanceFormSchema,
|
||||||
|
InitialBalanceFormValues,
|
||||||
|
} from '@/components/pages/finance/add/initial-balance/FormFinanceAddInitialBalance.schema';
|
||||||
|
import {
|
||||||
|
FINANCE_INITIAL_BALANCE_TYPE_OPTIONS,
|
||||||
|
FINANCE_PARTY_TYPE_OPTIONS,
|
||||||
|
} from '@/config/constant';
|
||||||
|
import { useFormikErrorList } from '@/services/hooks/useFormikErrorList';
|
||||||
|
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
||||||
|
import { formatTitleCase } from '@/lib/helper';
|
||||||
|
import { FinanceApi } from '@/services/api/finance';
|
||||||
|
import { BankApi, CustomerApi, SupplierApi } from '@/services/api/master-data';
|
||||||
|
import {
|
||||||
|
CreateInitialBalance,
|
||||||
|
Finance,
|
||||||
|
UpdateInitialBalance,
|
||||||
|
} from '@/types/api/finance/finance';
|
||||||
|
import { Bank } from '@/types/api/master-data/bank';
|
||||||
|
import { Icon } from '@iconify/react';
|
||||||
|
import { useFormik } from 'formik';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import { useCallback, useMemo } from 'react';
|
||||||
|
import toast from 'react-hot-toast';
|
||||||
|
|
||||||
|
interface FormFinanceAddInitialBalanceProps {
|
||||||
|
type?: 'add' | 'edit';
|
||||||
|
initialValues?: Finance;
|
||||||
|
}
|
||||||
|
|
||||||
|
const FormFinanceAddInitialBalance = ({
|
||||||
|
type = 'add',
|
||||||
|
initialValues,
|
||||||
|
}: FormFinanceAddInitialBalanceProps) => {
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
// ===== Formik =====
|
||||||
|
const formikInitialValues = useMemo((): InitialBalanceFormValues => {
|
||||||
|
// Type assertion to handle potential initial_balance_type field
|
||||||
|
const extendedInitialValues = initialValues as Finance & {
|
||||||
|
initial_balance_type?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
party_type_option:
|
||||||
|
FINANCE_PARTY_TYPE_OPTIONS.find(
|
||||||
|
(option) => option.value === initialValues?.party.type
|
||||||
|
) || null,
|
||||||
|
party_id_option: initialValues?.party
|
||||||
|
? {
|
||||||
|
label: initialValues.party.name,
|
||||||
|
value: initialValues.party.id,
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
bank_id_option: initialValues?.bank
|
||||||
|
? {
|
||||||
|
label: initialValues.bank.name,
|
||||||
|
value: initialValues.bank.id,
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
reference_number: initialValues?.reference_number || '',
|
||||||
|
initial_balance_type_option:
|
||||||
|
(initialValues?.nominal ?? 0) < 0
|
||||||
|
? FINANCE_INITIAL_BALANCE_TYPE_OPTIONS.find(
|
||||||
|
(option) => option.value === 'NEGATIVE'
|
||||||
|
) || null
|
||||||
|
: FINANCE_INITIAL_BALANCE_TYPE_OPTIONS.find(
|
||||||
|
(option) => option.value === 'POSITIVE'
|
||||||
|
) || null,
|
||||||
|
nominal: initialValues?.nominal?.toString() || '',
|
||||||
|
note: initialValues?.notes || '',
|
||||||
|
};
|
||||||
|
}, [initialValues]);
|
||||||
|
|
||||||
|
const formik = useFormik<InitialBalanceFormValues>({
|
||||||
|
initialValues: formikInitialValues,
|
||||||
|
validationSchema: InitialBalanceFormSchema,
|
||||||
|
validateOnChange: true,
|
||||||
|
validateOnBlur: true,
|
||||||
|
onSubmit: async (values) => {
|
||||||
|
const payload = transformFormValuesToPayload(values);
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case 'add':
|
||||||
|
await createInitialBalance(payload);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'edit':
|
||||||
|
if (initialValues?.id) {
|
||||||
|
await updateInitialBalance(initialValues.id, payload);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// ===== Options =====
|
||||||
|
const { options: partyOptions, isLoadingOptions: isLoadingPartyOptions } =
|
||||||
|
useSelect(
|
||||||
|
formik.values.party_type_option?.value === 'CUSTOMER'
|
||||||
|
? CustomerApi.basePath
|
||||||
|
: SupplierApi.basePath,
|
||||||
|
'id',
|
||||||
|
'name',
|
||||||
|
'',
|
||||||
|
{ limit: 'limit' }
|
||||||
|
);
|
||||||
|
const {
|
||||||
|
options: bankOptions,
|
||||||
|
rawData: bankRawData,
|
||||||
|
isLoadingOptions: isLoadingBankOptions,
|
||||||
|
} = useSelect<Bank>(BankApi.basePath, 'id', 'name', '', { limit: 'limit' });
|
||||||
|
|
||||||
|
// ===== Helper Functions =====
|
||||||
|
const transformFormValuesToPayload = (
|
||||||
|
values: InitialBalanceFormValues
|
||||||
|
): CreateInitialBalance => {
|
||||||
|
return {
|
||||||
|
party_type: (values.party_type_option?.value as string) || '',
|
||||||
|
party_id: Number(values.party_id_option?.value) || 0,
|
||||||
|
bank_id: Number(values.bank_id_option?.value) || 0,
|
||||||
|
reference_number: values.reference_number,
|
||||||
|
initial_balance_type:
|
||||||
|
(values.initial_balance_type_option?.value as string) || '',
|
||||||
|
nominal: Number(values.nominal.replace(/\D/g, '')) || 0,
|
||||||
|
note: values.note,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// ===== Handler =====
|
||||||
|
const createInitialBalance = useCallback(
|
||||||
|
async (payload: CreateInitialBalance) => {
|
||||||
|
const response = await FinanceApi.createInitialBalances(payload);
|
||||||
|
|
||||||
|
if (isResponseError(response)) {
|
||||||
|
toast.error(response.message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
toast.success('Saldo awal berhasil ditambahkan');
|
||||||
|
router.refresh();
|
||||||
|
router.push('/finance');
|
||||||
|
},
|
||||||
|
[router]
|
||||||
|
);
|
||||||
|
|
||||||
|
const updateInitialBalance = useCallback(
|
||||||
|
async (financeId: number, payload: UpdateInitialBalance) => {
|
||||||
|
const response = await FinanceApi.updateInitialBalances(
|
||||||
|
financeId,
|
||||||
|
payload
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isResponseError(response)) {
|
||||||
|
toast.error(response.message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
toast.success('Saldo awal berhasil diperbarui');
|
||||||
|
router.refresh();
|
||||||
|
router.push('/finance');
|
||||||
|
},
|
||||||
|
[router]
|
||||||
|
);
|
||||||
|
|
||||||
|
// ===== Formik Error List =====
|
||||||
|
const { formErrorList, close, handleFormSubmit } = useFormikErrorList(formik);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<section className='w-full max-w-xl mx-auto'>
|
||||||
|
<div className='flex flex-col gap-6 p-6'>
|
||||||
|
<FormHeader
|
||||||
|
title={`${type === 'add' ? 'Tambah' : 'Ubah'} Saldo Awal`}
|
||||||
|
backUrl='/finance'
|
||||||
|
/>
|
||||||
|
<form className='flex flex-col gap-4' onSubmit={handleFormSubmit}>
|
||||||
|
<SelectInput
|
||||||
|
label='Jenis Pihak'
|
||||||
|
placeholder='Pilih jenis pihak'
|
||||||
|
options={FINANCE_PARTY_TYPE_OPTIONS}
|
||||||
|
value={formik.values.party_type_option}
|
||||||
|
onChange={(value) => {
|
||||||
|
formik.setFieldValue('party_type_option', value);
|
||||||
|
formik.setFieldValue('party_id_option', null);
|
||||||
|
formik.setFieldValue('party_account_number', '');
|
||||||
|
}}
|
||||||
|
isError={Boolean(
|
||||||
|
formik.touched.party_type_option &&
|
||||||
|
formik.errors.party_type_option
|
||||||
|
)}
|
||||||
|
errorMessage={
|
||||||
|
formik.touched.party_type_option &&
|
||||||
|
formik.errors.party_type_option
|
||||||
|
? formik.errors.party_type_option
|
||||||
|
: ''
|
||||||
|
}
|
||||||
|
required
|
||||||
|
isClearable
|
||||||
|
/>
|
||||||
|
<SelectInput
|
||||||
|
label={
|
||||||
|
formik.values.party_type_option?.value
|
||||||
|
? formatTitleCase(
|
||||||
|
formik.values.party_type_option.value as string
|
||||||
|
)
|
||||||
|
: 'Pilih Jenis Pihak Dahulu'
|
||||||
|
}
|
||||||
|
placeholder={`Pilih ${formik.values.party_type_option?.value ? formatTitleCase(formik.values.party_type_option.value as string) : 'jenis pihak dahulu'}`}
|
||||||
|
options={partyOptions}
|
||||||
|
value={formik.values.party_id_option}
|
||||||
|
onChange={(value) => {
|
||||||
|
formik.setFieldValue('party_id_option', value);
|
||||||
|
}}
|
||||||
|
isLoading={isLoadingPartyOptions}
|
||||||
|
isError={Boolean(
|
||||||
|
formik.touched.party_id_option && formik.errors.party_id_option
|
||||||
|
)}
|
||||||
|
errorMessage={
|
||||||
|
formik.touched.party_id_option && formik.errors.party_id_option
|
||||||
|
? formik.errors.party_id_option
|
||||||
|
: ''
|
||||||
|
}
|
||||||
|
required
|
||||||
|
isClearable
|
||||||
|
isDisabled={!formik.values.party_type_option?.value}
|
||||||
|
/>
|
||||||
|
<SelectInput
|
||||||
|
label='Bank'
|
||||||
|
placeholder='Pilih bank'
|
||||||
|
options={
|
||||||
|
isResponseSuccess(bankRawData)
|
||||||
|
? bankOptions.map((option) => ({
|
||||||
|
label:
|
||||||
|
bankRawData.data?.find(
|
||||||
|
(item) => item.id === option.value
|
||||||
|
)?.alias +
|
||||||
|
' - ' +
|
||||||
|
bankRawData.data?.find(
|
||||||
|
(item) => item.id === option.value
|
||||||
|
)?.account_number +
|
||||||
|
' - ' +
|
||||||
|
bankRawData.data?.find(
|
||||||
|
(item) => item.id === option.value
|
||||||
|
)?.owner,
|
||||||
|
value: option.value,
|
||||||
|
}))
|
||||||
|
: []
|
||||||
|
}
|
||||||
|
value={formik.values.bank_id_option}
|
||||||
|
onChange={(value) => {
|
||||||
|
formik.setFieldValue('bank_id_option', value);
|
||||||
|
}}
|
||||||
|
isLoading={isLoadingBankOptions}
|
||||||
|
isError={Boolean(
|
||||||
|
formik.touched.bank_id_option && formik.errors.bank_id_option
|
||||||
|
)}
|
||||||
|
errorMessage={
|
||||||
|
formik.touched.bank_id_option && formik.errors.bank_id_option
|
||||||
|
? formik.errors.bank_id_option
|
||||||
|
: ''
|
||||||
|
}
|
||||||
|
required
|
||||||
|
isClearable
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
label='Nomor Referensi'
|
||||||
|
placeholder='Masukkan nomor referensi'
|
||||||
|
name='reference_number'
|
||||||
|
value={formik.values.reference_number}
|
||||||
|
onChange={formik.handleChange}
|
||||||
|
onBlur={formik.handleBlur}
|
||||||
|
isError={Boolean(
|
||||||
|
formik.touched.reference_number &&
|
||||||
|
formik.errors.reference_number
|
||||||
|
)}
|
||||||
|
errorMessage={
|
||||||
|
formik.touched.reference_number &&
|
||||||
|
formik.errors.reference_number
|
||||||
|
? formik.errors.reference_number
|
||||||
|
: ''
|
||||||
|
}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<SelectInput
|
||||||
|
label='Tipe Saldo Awal'
|
||||||
|
placeholder='Pilih tipe saldo awal'
|
||||||
|
options={FINANCE_INITIAL_BALANCE_TYPE_OPTIONS}
|
||||||
|
value={formik.values.initial_balance_type_option}
|
||||||
|
onChange={(value) => {
|
||||||
|
formik.setFieldValue('initial_balance_type_option', value);
|
||||||
|
}}
|
||||||
|
isError={Boolean(
|
||||||
|
formik.touched.initial_balance_type_option &&
|
||||||
|
formik.errors.initial_balance_type_option
|
||||||
|
)}
|
||||||
|
errorMessage={
|
||||||
|
formik.touched.initial_balance_type_option &&
|
||||||
|
formik.errors.initial_balance_type_option
|
||||||
|
? formik.errors.initial_balance_type_option
|
||||||
|
: ''
|
||||||
|
}
|
||||||
|
required
|
||||||
|
isClearable
|
||||||
|
/>
|
||||||
|
<NumberInput
|
||||||
|
label='Nominal'
|
||||||
|
placeholder='Masukkan nominal'
|
||||||
|
name='nominal'
|
||||||
|
value={formik.values.nominal}
|
||||||
|
onChange={formik.handleChange}
|
||||||
|
onBlur={formik.handleBlur}
|
||||||
|
isError={Boolean(formik.touched.nominal && formik.errors.nominal)}
|
||||||
|
errorMessage={
|
||||||
|
formik.touched.nominal && formik.errors.nominal
|
||||||
|
? formik.errors.nominal
|
||||||
|
: ''
|
||||||
|
}
|
||||||
|
allowNegative={false}
|
||||||
|
startAdornment={
|
||||||
|
formik.values.initial_balance_type_option?.value ===
|
||||||
|
'POSITIVE' ? (
|
||||||
|
<Icon icon='mdi:plus' />
|
||||||
|
) : formik.values.initial_balance_type_option?.value ===
|
||||||
|
'NEGATIVE' ? (
|
||||||
|
<Icon icon='mdi:minus' />
|
||||||
|
) : (
|
||||||
|
''
|
||||||
|
)
|
||||||
|
}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<TextArea
|
||||||
|
label='Catatan'
|
||||||
|
placeholder='Masukkan catatan'
|
||||||
|
name='note'
|
||||||
|
value={formik.values.note}
|
||||||
|
onChange={formik.handleChange}
|
||||||
|
onBlur={formik.handleBlur}
|
||||||
|
isError={Boolean(formik.touched.note && formik.errors.note)}
|
||||||
|
errorMessage={
|
||||||
|
formik.touched.note && formik.errors.note
|
||||||
|
? formik.errors.note
|
||||||
|
: ''
|
||||||
|
}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<AlertErrorList formErrorList={formErrorList} onClose={close} />
|
||||||
|
<div className='flex justify-center gap-4'>
|
||||||
|
<Button
|
||||||
|
type='reset'
|
||||||
|
color='warning'
|
||||||
|
className='w-min-24'
|
||||||
|
onClick={() => formik.resetForm()}
|
||||||
|
disabled={formik.isSubmitting}
|
||||||
|
>
|
||||||
|
Reset
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type='submit'
|
||||||
|
className='w-min-24'
|
||||||
|
disabled={formik.isSubmitting || !formik.isValid}
|
||||||
|
>
|
||||||
|
Submit
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default FormFinanceAddInitialBalance;
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { OptionType } from '@/components/input/SelectInput';
|
||||||
|
import * as Yup from 'yup';
|
||||||
|
|
||||||
|
// Type for form values (includes option objects for SelectInput)
|
||||||
|
export type InjectionFormValues = {
|
||||||
|
bank_id_option: OptionType | null;
|
||||||
|
adjustment_date: string;
|
||||||
|
nominal: string;
|
||||||
|
note: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const InjectionFormSchema = Yup.object<InjectionFormValues>({
|
||||||
|
bank_id_option: Yup.mixed()
|
||||||
|
.nullable()
|
||||||
|
.test(
|
||||||
|
'is-valid-option',
|
||||||
|
'Bank wajib diisi',
|
||||||
|
(value) => value !== null && value !== undefined
|
||||||
|
),
|
||||||
|
adjustment_date: Yup.string().required('Tanggal penyesuaian wajib diisi'),
|
||||||
|
nominal: Yup.string().required('Nominal wajib diisi'),
|
||||||
|
note: Yup.string().required('Catatan wajib diisi'),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const UpdateInjectionFormSchema = InjectionFormSchema;
|
||||||
@@ -0,0 +1,254 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import Button from '@/components/Button';
|
||||||
|
import AlertErrorList from '@/components/helper/form/FormErrors';
|
||||||
|
import { FormHeader } from '@/components/helper/form/FormHeader';
|
||||||
|
import DateInput from '@/components/input/DateInput';
|
||||||
|
import NumberInput from '@/components/input/NumberInput';
|
||||||
|
import SelectInput, { useSelect } from '@/components/input/SelectInput';
|
||||||
|
import TextArea from '@/components/input/TextArea';
|
||||||
|
import {
|
||||||
|
InjectionFormSchema,
|
||||||
|
InjectionFormValues,
|
||||||
|
} from '@/components/pages/finance/add/injection/FormFinanceInjection.schema';
|
||||||
|
import { useFormikErrorList } from '@/services/hooks/useFormikErrorList';
|
||||||
|
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
||||||
|
import { formatDate } from '@/lib/helper';
|
||||||
|
import { FinanceApi } from '@/services/api/finance';
|
||||||
|
import { BankApi } from '@/services/api/master-data';
|
||||||
|
import {
|
||||||
|
CreateInjection,
|
||||||
|
Finance,
|
||||||
|
UpdateInjection,
|
||||||
|
} from '@/types/api/finance/finance';
|
||||||
|
import { Bank } from '@/types/api/master-data/bank';
|
||||||
|
import { useFormik } from 'formik';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import { useCallback, useMemo } from 'react';
|
||||||
|
import toast from 'react-hot-toast';
|
||||||
|
|
||||||
|
interface FormFinanceInjectionProps {
|
||||||
|
type?: 'add' | 'edit';
|
||||||
|
initialValues?: Finance;
|
||||||
|
}
|
||||||
|
|
||||||
|
const FormFinanceInjection = ({
|
||||||
|
type = 'add',
|
||||||
|
initialValues,
|
||||||
|
}: FormFinanceInjectionProps) => {
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
// ===== Formik =====
|
||||||
|
const formikInitialValues = useMemo((): InjectionFormValues => {
|
||||||
|
return {
|
||||||
|
bank_id_option: initialValues?.bank
|
||||||
|
? {
|
||||||
|
label: initialValues.bank.name,
|
||||||
|
value: initialValues.bank.id,
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
adjustment_date: initialValues?.payment_date || '',
|
||||||
|
nominal: initialValues?.nominal?.toString() || '',
|
||||||
|
note: initialValues?.notes || '',
|
||||||
|
};
|
||||||
|
}, [initialValues]);
|
||||||
|
|
||||||
|
const formik = useFormik<InjectionFormValues>({
|
||||||
|
initialValues: formikInitialValues,
|
||||||
|
validationSchema: InjectionFormSchema,
|
||||||
|
validateOnChange: true,
|
||||||
|
validateOnBlur: true,
|
||||||
|
onSubmit: async (values) => {
|
||||||
|
const payload = transformFormValuesToPayload(values);
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case 'add':
|
||||||
|
await createInjection(payload);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'edit':
|
||||||
|
if (initialValues?.id) {
|
||||||
|
await updateInjection(initialValues.id, payload);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// ===== Options =====
|
||||||
|
const {
|
||||||
|
options: bankOptions,
|
||||||
|
rawData: bankRawData,
|
||||||
|
isLoadingOptions: isLoadingBankOptions,
|
||||||
|
} = useSelect<Bank>(BankApi.basePath, 'id', 'name', '', { limit: 'limit' });
|
||||||
|
|
||||||
|
// ===== Helper Functions =====
|
||||||
|
const transformFormValuesToPayload = (
|
||||||
|
values: InjectionFormValues
|
||||||
|
): CreateInjection => {
|
||||||
|
return {
|
||||||
|
bank_id: Number(values.bank_id_option?.value) || 0,
|
||||||
|
adjustment_date: formatDate(values.adjustment_date, 'YYYY-MM-DD'),
|
||||||
|
nominal: Number(values.nominal.replace(/\D/g, '')) || 0,
|
||||||
|
notes: values.note,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// ===== Handler =====
|
||||||
|
const createInjection = useCallback(
|
||||||
|
async (payload: CreateInjection) => {
|
||||||
|
const response = await FinanceApi.createInjections(payload);
|
||||||
|
|
||||||
|
if (isResponseError(response)) {
|
||||||
|
toast.error(response.message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
toast.success('Injeksi dana berhasil ditambahkan');
|
||||||
|
router.refresh();
|
||||||
|
router.push('/finance');
|
||||||
|
},
|
||||||
|
[router]
|
||||||
|
);
|
||||||
|
|
||||||
|
const updateInjection = useCallback(
|
||||||
|
async (financeId: number, payload: UpdateInjection) => {
|
||||||
|
const response = await FinanceApi.updateInjections(financeId, payload);
|
||||||
|
|
||||||
|
if (isResponseError(response)) {
|
||||||
|
toast.error(response.message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
toast.success('Injeksi dana berhasil diperbarui');
|
||||||
|
router.refresh();
|
||||||
|
router.push('/finance');
|
||||||
|
},
|
||||||
|
[router]
|
||||||
|
);
|
||||||
|
|
||||||
|
// ===== Formik Error List =====
|
||||||
|
const { formErrorList, close, handleFormSubmit } = useFormikErrorList(formik);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<section className='w-full max-w-xl mx-auto'>
|
||||||
|
<div className='flex flex-col gap-6 p-6'>
|
||||||
|
<FormHeader
|
||||||
|
title={`${type === 'add' ? 'Tambah' : 'Ubah'} Injeksi Dana`}
|
||||||
|
backUrl='/finance'
|
||||||
|
/>
|
||||||
|
<form className='flex flex-col gap-4' onSubmit={handleFormSubmit}>
|
||||||
|
<SelectInput
|
||||||
|
label='Bank'
|
||||||
|
placeholder='Pilih bank'
|
||||||
|
options={
|
||||||
|
isResponseSuccess(bankRawData)
|
||||||
|
? bankOptions.map((option) => ({
|
||||||
|
label:
|
||||||
|
bankRawData.data?.find(
|
||||||
|
(item) => item.id === option.value
|
||||||
|
)?.alias +
|
||||||
|
' - ' +
|
||||||
|
bankRawData.data?.find(
|
||||||
|
(item) => item.id === option.value
|
||||||
|
)?.account_number +
|
||||||
|
' - ' +
|
||||||
|
bankRawData.data?.find(
|
||||||
|
(item) => item.id === option.value
|
||||||
|
)?.owner,
|
||||||
|
value: option.value,
|
||||||
|
}))
|
||||||
|
: []
|
||||||
|
}
|
||||||
|
value={formik.values.bank_id_option}
|
||||||
|
onChange={(value) => {
|
||||||
|
formik.setFieldValue('bank_id_option', value);
|
||||||
|
}}
|
||||||
|
isLoading={isLoadingBankOptions}
|
||||||
|
isError={Boolean(
|
||||||
|
formik.touched.bank_id_option && formik.errors.bank_id_option
|
||||||
|
)}
|
||||||
|
errorMessage={
|
||||||
|
formik.touched.bank_id_option && formik.errors.bank_id_option
|
||||||
|
? formik.errors.bank_id_option
|
||||||
|
: ''
|
||||||
|
}
|
||||||
|
required
|
||||||
|
isClearable
|
||||||
|
/>
|
||||||
|
<DateInput
|
||||||
|
label='Tanggal Penyesuaian'
|
||||||
|
placeholder='Pilih tanggal penyesuaian'
|
||||||
|
name='adjustment_date'
|
||||||
|
value={formik.values.adjustment_date}
|
||||||
|
onChange={formik.handleChange}
|
||||||
|
onBlur={formik.handleBlur}
|
||||||
|
isError={Boolean(
|
||||||
|
formik.touched.adjustment_date && formik.errors.adjustment_date
|
||||||
|
)}
|
||||||
|
errorMessage={
|
||||||
|
formik.touched.adjustment_date && formik.errors.adjustment_date
|
||||||
|
? formik.errors.adjustment_date
|
||||||
|
: ''
|
||||||
|
}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<NumberInput
|
||||||
|
label='Nominal'
|
||||||
|
placeholder='Masukkan nominal'
|
||||||
|
name='nominal'
|
||||||
|
value={formik.values.nominal}
|
||||||
|
onChange={formik.handleChange}
|
||||||
|
onBlur={formik.handleBlur}
|
||||||
|
isError={Boolean(formik.touched.nominal && formik.errors.nominal)}
|
||||||
|
errorMessage={
|
||||||
|
formik.touched.nominal && formik.errors.nominal
|
||||||
|
? formik.errors.nominal
|
||||||
|
: ''
|
||||||
|
}
|
||||||
|
allowNegative={true}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<TextArea
|
||||||
|
label='Catatan'
|
||||||
|
placeholder='Masukkan catatan'
|
||||||
|
name='note'
|
||||||
|
value={formik.values.note}
|
||||||
|
onChange={formik.handleChange}
|
||||||
|
onBlur={formik.handleBlur}
|
||||||
|
isError={Boolean(formik.touched.note && formik.errors.note)}
|
||||||
|
errorMessage={
|
||||||
|
formik.touched.note && formik.errors.note
|
||||||
|
? formik.errors.note
|
||||||
|
: ''
|
||||||
|
}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<AlertErrorList formErrorList={formErrorList} onClose={close} />
|
||||||
|
<div className='flex justify-center gap-4'>
|
||||||
|
<Button
|
||||||
|
type='reset'
|
||||||
|
color='warning'
|
||||||
|
className='w-min-24'
|
||||||
|
onClick={() => formik.resetForm()}
|
||||||
|
disabled={formik.isSubmitting}
|
||||||
|
>
|
||||||
|
Reset
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type='submit'
|
||||||
|
className='w-min-24'
|
||||||
|
disabled={formik.isSubmitting || !formik.isValid}
|
||||||
|
>
|
||||||
|
Submit
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default FormFinanceInjection;
|
||||||
@@ -4,6 +4,7 @@ import Badge from '@/components/Badge';
|
|||||||
import Button from '@/components/Button';
|
import Button from '@/components/Button';
|
||||||
import SelectInput, { OptionType } from '@/components/input/SelectInput';
|
import SelectInput, { OptionType } from '@/components/input/SelectInput';
|
||||||
import Table from '@/components/Table';
|
import Table from '@/components/Table';
|
||||||
|
import RequirePermission from '@/components/helper/RequirePermission';
|
||||||
import { ROWS_OPTIONS } from '@/config/constant';
|
import { ROWS_OPTIONS } from '@/config/constant';
|
||||||
import { isResponseSuccess } from '@/lib/api-helper';
|
import { isResponseSuccess } from '@/lib/api-helper';
|
||||||
import { cn } from '@/lib/helper';
|
import { cn } from '@/lib/helper';
|
||||||
@@ -14,6 +15,7 @@ import { Icon } from '@iconify/react';
|
|||||||
import { ColumnDef, ColumnSort, SortingState } from '@tanstack/react-table';
|
import { ColumnDef, ColumnSort, SortingState } from '@tanstack/react-table';
|
||||||
import { useCallback, useEffect, useState } from 'react';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
import useSWR from 'swr';
|
import useSWR from 'swr';
|
||||||
|
import { useFormikErrorList } from '@/services/hooks/useFormikErrorList';
|
||||||
|
|
||||||
const InventoryAdjustmentTable = () => {
|
const InventoryAdjustmentTable = () => {
|
||||||
const {
|
const {
|
||||||
@@ -78,18 +80,6 @@ const InventoryAdjustmentTable = () => {
|
|||||||
year: 'numeric',
|
year: 'numeric',
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
// {
|
|
||||||
// id: 'before_quantity',
|
|
||||||
// header: 'Stok Sebelum',
|
|
||||||
// accessorFn: (row) =>
|
|
||||||
// formatNumber(String(row.product_warehouse?.quantity)),
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// id: 'after_quantity',
|
|
||||||
// header: 'Stok Sesudah',
|
|
||||||
// accessorFn: (row) =>
|
|
||||||
// formatNumber(String(row.product_warehouse?.quantity)),
|
|
||||||
// },
|
|
||||||
{
|
{
|
||||||
id: 'quantity',
|
id: 'quantity',
|
||||||
header: 'Kuantitas',
|
header: 'Kuantitas',
|
||||||
@@ -175,23 +165,17 @@ const InventoryAdjustmentTable = () => {
|
|||||||
<div className='flex flex-col gap-2 mb-4'>
|
<div className='flex flex-col gap-2 mb-4'>
|
||||||
<div className='w-full flex flex-col sm:flex-row justify-between items-end sm:items-center gap-2'>
|
<div className='w-full flex flex-col sm:flex-row justify-between items-end sm:items-center gap-2'>
|
||||||
<div className='w-full flex flex-row'>
|
<div className='w-full flex flex-row'>
|
||||||
<Button
|
<RequirePermission permissions='lti.inventory.create'>
|
||||||
href='/inventory/adjustment/add'
|
<Button
|
||||||
variant='outline'
|
href='/inventory/adjustment/add'
|
||||||
color='primary'
|
variant='outline'
|
||||||
className='w-full sm:w-fit'
|
color='primary'
|
||||||
>
|
className='w-full sm:w-fit'
|
||||||
<Icon icon='ic:round-plus' width={24} height={24} />
|
>
|
||||||
Tambah
|
<Icon icon='ic:round-plus' width={24} height={24} />
|
||||||
</Button>
|
Tambah
|
||||||
|
</Button>
|
||||||
{/* <DebouncedTextInput
|
</RequirePermission>
|
||||||
name='search'
|
|
||||||
placeholder='Cari Stock Adjustment'
|
|
||||||
value={tableFilterState.search}
|
|
||||||
onChange={searchChangeHandler}
|
|
||||||
className={{ wrapper: 'sm:max-w-3xs' }}
|
|
||||||
/> */}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className='flex flex-row justify-end'>
|
<div className='flex flex-row justify-end'>
|
||||||
|
|||||||
@@ -1,26 +1,42 @@
|
|||||||
import * as Yup from 'yup';
|
import * as Yup from 'yup';
|
||||||
|
import { OptionType } from '@/components/input/SelectInput';
|
||||||
|
|
||||||
export const InventoryAdjustmentFormSchema = Yup.object({
|
export const InventoryAdjustmentFormSchema = Yup.object({
|
||||||
product_category: Yup.object({
|
product_category: Yup.mixed<OptionType>()
|
||||||
value: Yup.number().required('ID Kategori Produk wajib diisi!'),
|
.nullable()
|
||||||
label: Yup.string().required('Nama Kategori Produk wajib diisi!'),
|
.test(
|
||||||
}).nullable(),
|
'is-valid-option',
|
||||||
|
'Kategori Produk wajib diisi!',
|
||||||
|
(value) => value !== null && value !== undefined
|
||||||
|
),
|
||||||
|
|
||||||
product_category_id: Yup.number().nullable(),
|
product_category_id: Yup.number().nullable(),
|
||||||
|
|
||||||
product: Yup.object({
|
product: Yup.mixed<OptionType>()
|
||||||
value: Yup.number().required('ID Produk wajib diisi!'),
|
.nullable()
|
||||||
label: Yup.string().required('Nama Produk wajib diisi!'),
|
.test(
|
||||||
}).nullable(),
|
'is-valid-option',
|
||||||
|
'Produk wajib diisi!',
|
||||||
|
(value) => value !== null && value !== undefined
|
||||||
|
),
|
||||||
|
|
||||||
product_id: Yup.number().nullable(),
|
product_id: Yup.number()
|
||||||
|
.nullable()
|
||||||
|
.required('Produk wajib diisi!')
|
||||||
|
.min(1, 'Produk wajib diisi!'),
|
||||||
|
|
||||||
warehouse: Yup.object({
|
warehouse: Yup.mixed<OptionType>()
|
||||||
value: Yup.number().required('ID Gudang wajib diisi!'),
|
.nullable()
|
||||||
label: Yup.string().required('Nama Gudang wajib diisi!'),
|
.test(
|
||||||
}).nullable(),
|
'is-valid-option',
|
||||||
|
'Warehouse wajib diisi!',
|
||||||
|
(value) => value !== null && value !== undefined
|
||||||
|
),
|
||||||
|
|
||||||
warehouse_id: Yup.number().nullable(),
|
warehouse_id: Yup.number()
|
||||||
|
.nullable()
|
||||||
|
.required('Warehouse wajib diisi!')
|
||||||
|
.min(1, 'Warehouse wajib diisi!'),
|
||||||
|
|
||||||
transaction_type: Yup.string()
|
transaction_type: Yup.string()
|
||||||
.oneOf(['increase', 'decrease'], 'Tipe transaksi tidak valid')
|
.oneOf(['increase', 'decrease'], 'Tipe transaksi tidak valid')
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ import SelectInput, { OptionType } from '@/components/input/SelectInput';
|
|||||||
import TextInput from '@/components/input/TextInput';
|
import TextInput from '@/components/input/TextInput';
|
||||||
import { RadioGroup } from '@/components/input/RadioInput';
|
import { RadioGroup } from '@/components/input/RadioInput';
|
||||||
import TextArea from '@/components/input/TextArea';
|
import TextArea from '@/components/input/TextArea';
|
||||||
|
import { useFormikErrorList } from '@/services/hooks/useFormikErrorList';
|
||||||
|
import AlertErrorList from '@/components/helper/form/FormErrors';
|
||||||
|
|
||||||
interface InventoryAdjustmentFormProps {
|
interface InventoryAdjustmentFormProps {
|
||||||
type?: 'add' | 'edit' | 'detail';
|
type?: 'add' | 'edit' | 'detail';
|
||||||
@@ -125,6 +127,7 @@ const InventoryAdjustmentForm = ({
|
|||||||
|
|
||||||
const warehouseUrl = `${WarehouseApi.basePath}?${new URLSearchParams({
|
const warehouseUrl = `${WarehouseApi.basePath}?${new URLSearchParams({
|
||||||
search: '',
|
search: '',
|
||||||
|
limit: '100',
|
||||||
}).toString()}`;
|
}).toString()}`;
|
||||||
const { data: warehouses, isLoading: isLoadingWarehouses } = useSWR(
|
const { data: warehouses, isLoading: isLoadingWarehouses } = useSWR(
|
||||||
warehouseUrl,
|
warehouseUrl,
|
||||||
@@ -244,6 +247,9 @@ const InventoryAdjustmentForm = ({
|
|||||||
return decimal ? `${formattedInteger}.${decimal}` : formattedInteger;
|
return decimal ? `${formattedInteger}.${decimal}` : formattedInteger;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ===== Formik Error List =====
|
||||||
|
const { formErrorList, close, handleFormSubmit } = useFormikErrorList(formik);
|
||||||
|
|
||||||
// Render
|
// Render
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -265,7 +271,7 @@ const InventoryAdjustmentForm = ({
|
|||||||
</header>
|
</header>
|
||||||
|
|
||||||
<form
|
<form
|
||||||
onSubmit={formik.handleSubmit}
|
onSubmit={handleFormSubmit}
|
||||||
onReset={formik.handleReset}
|
onReset={formik.handleReset}
|
||||||
className='w-full mt-8 flex flex-col gap-6'
|
className='w-full mt-8 flex flex-col gap-6'
|
||||||
>
|
>
|
||||||
@@ -389,6 +395,7 @@ const InventoryAdjustmentForm = ({
|
|||||||
readOnly={type === 'detail'}
|
readOnly={type === 'detail'}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<AlertErrorList formErrorList={formErrorList} onClose={close} />
|
||||||
<div className='flex flex-row justify-between gap-2 flex-wrap'>
|
<div className='flex flex-row justify-between gap-2 flex-wrap'>
|
||||||
{type !== 'detail' && (
|
{type !== 'detail' && (
|
||||||
<div className='flex flex-row justify-end gap-2'>
|
<div className='flex flex-row justify-end gap-2'>
|
||||||
@@ -404,11 +411,7 @@ const InventoryAdjustmentForm = ({
|
|||||||
type='submit'
|
type='submit'
|
||||||
color='primary'
|
color='primary'
|
||||||
isLoading={formik.isSubmitting}
|
isLoading={formik.isSubmitting}
|
||||||
disabled={
|
disabled={formik.isSubmitting}
|
||||||
!formik.isValid ||
|
|
||||||
formik.isSubmitting ||
|
|
||||||
formik.values.product == undefined
|
|
||||||
}
|
|
||||||
className='px-4'
|
className='px-4'
|
||||||
>
|
>
|
||||||
Submit
|
Submit
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import SelectInput from '@/components/input/SelectInput';
|
|||||||
import RowDropdownOptions from '@/components/table/RowDropdownOptions';
|
import RowDropdownOptions from '@/components/table/RowDropdownOptions';
|
||||||
import RowCollapseOptions from '@/components/table/RowCollapseOptions';
|
import RowCollapseOptions from '@/components/table/RowCollapseOptions';
|
||||||
import RowOptionsMenuWrapper from '@/components/table/RowOptionsMenuWrapper';
|
import RowOptionsMenuWrapper from '@/components/table/RowOptionsMenuWrapper';
|
||||||
|
import RequirePermission from '@/components/helper/RequirePermission';
|
||||||
|
|
||||||
const RowOptionsMenu = ({
|
const RowOptionsMenu = ({
|
||||||
type = 'dropdown',
|
type = 'dropdown',
|
||||||
@@ -28,15 +29,17 @@ const RowOptionsMenu = ({
|
|||||||
props: CellContext<Movement, unknown>;
|
props: CellContext<Movement, unknown>;
|
||||||
}) => (
|
}) => (
|
||||||
<RowOptionsMenuWrapper type={type}>
|
<RowOptionsMenuWrapper type={type}>
|
||||||
<Button
|
<RequirePermission permissions='lti.inventory.transfer.detail'>
|
||||||
href={`/inventory/movement/detail/?movementId=${props.row.original.id}`}
|
<Button
|
||||||
variant='ghost'
|
href={`/inventory/movement/detail/?movementId=${props.row.original.id}`}
|
||||||
color='primary'
|
variant='ghost'
|
||||||
className='justify-start text-sm'
|
color='primary'
|
||||||
>
|
className='justify-start text-sm'
|
||||||
<Icon icon='mdi:eye-outline' width={16} height={16} />
|
>
|
||||||
Detail
|
<Icon icon='mdi:eye-outline' width={16} height={16} />
|
||||||
</Button>
|
Detail
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
</RowOptionsMenuWrapper>
|
</RowOptionsMenuWrapper>
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -145,15 +148,17 @@ const MovementTable = () => {
|
|||||||
<div className='flex flex-col gap-2 mb-4'>
|
<div className='flex flex-col gap-2 mb-4'>
|
||||||
<div className='w-full flex flex-col sm:flex-row justify-between items-end sm:items-center gap-2'>
|
<div className='w-full flex flex-col sm:flex-row justify-between items-end sm:items-center gap-2'>
|
||||||
<div className='w-full flex flex-row gap-2'>
|
<div className='w-full flex flex-row gap-2'>
|
||||||
<Button
|
<RequirePermission permissions='lti.inventory.transfer.create'>
|
||||||
href='/inventory/movement/add'
|
<Button
|
||||||
variant='outline'
|
href='/inventory/movement/add'
|
||||||
color='primary'
|
variant='outline'
|
||||||
className='w-full sm:w-fit'
|
color='primary'
|
||||||
>
|
className='w-full sm:w-fit'
|
||||||
<Icon icon='ic:round-plus' width={24} height={24} />
|
>
|
||||||
Tambah
|
<Icon icon='ic:round-plus' width={24} height={24} />
|
||||||
</Button>
|
Tambah
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<DebouncedTextInput
|
<DebouncedTextInput
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import * as Yup from 'yup';
|
import * as Yup from 'yup';
|
||||||
import { Movement } from '@/types/api/inventory/movement';
|
import { Movement, MovementDocument } from '@/types/api/inventory/movement';
|
||||||
|
|
||||||
type MovementFormSchemaType = {
|
type MovementFormSchemaType = {
|
||||||
transfer_reason: string;
|
transfer_reason: string;
|
||||||
@@ -29,7 +29,7 @@ type MovementFormSchemaType = {
|
|||||||
deliveries: {
|
deliveries: {
|
||||||
delivery_cost?: number | string;
|
delivery_cost?: number | string;
|
||||||
delivery_cost_per_item?: number | string;
|
delivery_cost_per_item?: number | string;
|
||||||
document?: File | string | null;
|
document?: File | MovementDocument | null;
|
||||||
document_path?: string | null;
|
document_path?: string | null;
|
||||||
driver_name: string;
|
driver_name: string;
|
||||||
vehicle_plate: string;
|
vehicle_plate: string;
|
||||||
@@ -61,7 +61,7 @@ export type ProductSchema = {
|
|||||||
export type DeliverySchema = {
|
export type DeliverySchema = {
|
||||||
delivery_cost?: number | string;
|
delivery_cost?: number | string;
|
||||||
delivery_cost_per_item?: number | string;
|
delivery_cost_per_item?: number | string;
|
||||||
document?: File | string | null;
|
document?: File | MovementDocument | null;
|
||||||
document_path?: string | null;
|
document_path?: string | null;
|
||||||
driver_name: string;
|
driver_name: string;
|
||||||
vehicle_plate: string;
|
vehicle_plate: string;
|
||||||
@@ -85,7 +85,10 @@ const ProductObjectSchema: Yup.ObjectSchema<ProductSchema> = Yup.object({
|
|||||||
value: Yup.number().min(1).required(),
|
value: Yup.number().min(1).required(),
|
||||||
label: Yup.string().required(),
|
label: Yup.string().required(),
|
||||||
}).nullable(),
|
}).nullable(),
|
||||||
product_id: Yup.number().required('Produk wajib diisi!'),
|
product_id: Yup.number()
|
||||||
|
.required('Produk wajib diisi!')
|
||||||
|
.min(1, 'Produk wajib diisi!')
|
||||||
|
.typeError('Produk wajib diisi!'),
|
||||||
product_qty: Yup.number()
|
product_qty: Yup.number()
|
||||||
.required('Qty wajib diisi!')
|
.required('Qty wajib diisi!')
|
||||||
.min(1, 'Qty minimal 1!')
|
.min(1, 'Qty minimal 1!')
|
||||||
@@ -97,7 +100,10 @@ const DeliveryProductObjectSchema = Yup.object({
|
|||||||
value: Yup.number().min(1).required(),
|
value: Yup.number().min(1).required(),
|
||||||
label: Yup.string().required(),
|
label: Yup.string().required(),
|
||||||
}).nullable(),
|
}).nullable(),
|
||||||
product_id: Yup.number().required('Produk wajib diisi!'),
|
product_id: Yup.number()
|
||||||
|
.required('Produk wajib diisi!')
|
||||||
|
.min(1, 'Produk wajib diisi!')
|
||||||
|
.typeError('Produk wajib diisi!'),
|
||||||
product_qty: Yup.number()
|
product_qty: Yup.number()
|
||||||
.required('Qty wajib diisi!')
|
.required('Qty wajib diisi!')
|
||||||
.min(1, 'Qty minimal 1!')
|
.min(1, 'Qty minimal 1!')
|
||||||
@@ -127,15 +133,14 @@ const DeliveryObjectSchema: Yup.ObjectSchema<DeliverySchema> = Yup.object({
|
|||||||
(delivery_cost !== undefined && delivery_cost > 0)
|
(delivery_cost !== undefined && delivery_cost > 0)
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
document_path: Yup.string().optional(),
|
document_path: Yup.string().nullable().optional(),
|
||||||
document_index: Yup.number().optional(),
|
document_index: Yup.number().optional(),
|
||||||
document: Yup.mixed<File | string>()
|
document: Yup.mixed<File | MovementDocument>()
|
||||||
.nullable()
|
.nullable()
|
||||||
.test('fileSize', 'Ukuran dokumen maksimal 2 MB', (value) => {
|
.test('fileSize', 'Ukuran dokumen maksimal 5 MB', (value) => {
|
||||||
if (!value) return true;
|
if (!value) return true;
|
||||||
if (typeof value === 'string') return true;
|
if (value instanceof File) return value.size <= 5 * 1024 * 1024;
|
||||||
if (value instanceof File) return value.size <= 2 * 1024 * 1024;
|
return true;
|
||||||
return false;
|
|
||||||
}),
|
}),
|
||||||
driver_name: Yup.string().required('Nama sopir wajib diisi!'),
|
driver_name: Yup.string().required('Nama sopir wajib diisi!'),
|
||||||
vehicle_plate: Yup.string().required('Plat nomor wajib diisi!'),
|
vehicle_plate: Yup.string().required('Plat nomor wajib diisi!'),
|
||||||
@@ -143,7 +148,10 @@ const DeliveryObjectSchema: Yup.ObjectSchema<DeliverySchema> = Yup.object({
|
|||||||
value: Yup.number().min(1).required(),
|
value: Yup.number().min(1).required(),
|
||||||
label: Yup.string().required(),
|
label: Yup.string().required(),
|
||||||
}).nullable(),
|
}).nullable(),
|
||||||
supplier_id: Yup.number().required('Supplier wajib diisi!'),
|
supplier_id: Yup.number()
|
||||||
|
.required('Supplier wajib diisi!')
|
||||||
|
.min(1, 'Supplier wajib diisi!')
|
||||||
|
.typeError('Supplier wajib diisi!'),
|
||||||
products: Yup.array()
|
products: Yup.array()
|
||||||
.of(DeliveryProductObjectSchema)
|
.of(DeliveryProductObjectSchema)
|
||||||
.min(1, 'Minimal harus ada 1 produk!')
|
.min(1, 'Minimal harus ada 1 produk!')
|
||||||
@@ -162,6 +170,7 @@ export const MovementFormSchema: Yup.ObjectSchema<MovementFormSchemaType> =
|
|||||||
}).nullable(),
|
}).nullable(),
|
||||||
source_warehouse_id: Yup.number()
|
source_warehouse_id: Yup.number()
|
||||||
.required('Gudang asal wajib diisi!')
|
.required('Gudang asal wajib diisi!')
|
||||||
|
.min(1, 'Gudang asal wajib diisi!')
|
||||||
.typeError('Gudang asal wajib diisi!'),
|
.typeError('Gudang asal wajib diisi!'),
|
||||||
destination_warehouse: Yup.object({
|
destination_warehouse: Yup.object({
|
||||||
value: Yup.number().min(1).required(),
|
value: Yup.number().min(1).required(),
|
||||||
@@ -171,6 +180,7 @@ export const MovementFormSchema: Yup.ObjectSchema<MovementFormSchemaType> =
|
|||||||
}).nullable(),
|
}).nullable(),
|
||||||
destination_warehouse_id: Yup.number()
|
destination_warehouse_id: Yup.number()
|
||||||
.required('Gudang tujuan wajib diisi!')
|
.required('Gudang tujuan wajib diisi!')
|
||||||
|
.min(1, 'Gudang tujuan wajib diisi!')
|
||||||
.typeError('Gudang tujuan wajib diisi!')
|
.typeError('Gudang tujuan wajib diisi!')
|
||||||
.test(
|
.test(
|
||||||
'different-warehouse',
|
'different-warehouse',
|
||||||
@@ -227,41 +237,62 @@ export const getMovementFormInitialValues = (
|
|||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
destination_warehouse_id: initialValues?.destination_warehouse?.id ?? 0,
|
destination_warehouse_id: initialValues?.destination_warehouse?.id ?? 0,
|
||||||
products:
|
products: initialValues?.details?.map((detail) => ({
|
||||||
initialValues?.details?.map((detail) => ({
|
product: {
|
||||||
product: {
|
value: detail.product.id,
|
||||||
value: detail.product.id,
|
label: detail.product.name,
|
||||||
label: detail.product.name,
|
},
|
||||||
},
|
product_id: detail.product.id,
|
||||||
product_id: detail.product.id,
|
product_qty: detail.quantity,
|
||||||
product_qty: detail.quantity,
|
})) ?? [
|
||||||
})) ?? [],
|
{
|
||||||
deliveries:
|
product: null,
|
||||||
initialValues?.deliveries?.map((d) => ({
|
product_id: 0,
|
||||||
delivery_cost: d.shipping_cost_total ?? undefined,
|
product_qty: '',
|
||||||
delivery_cost_per_item: d.shipping_cost_item ?? undefined,
|
},
|
||||||
document_number: d.document_number ?? '',
|
],
|
||||||
document: d.document_path ?? null,
|
deliveries: initialValues?.deliveries?.map((d) => ({
|
||||||
document_path: d.document_path ?? null,
|
delivery_cost: d.shipping_cost_total ?? undefined,
|
||||||
driver_name: d.driver_name ?? '',
|
delivery_cost_per_item: d.shipping_cost_item ?? undefined,
|
||||||
vehicle_plate: d.vehicle_plate ?? '',
|
document: d.document ?? null,
|
||||||
supplier: d.supplier
|
document_path: d.document_path ?? null,
|
||||||
? { value: d.supplier.id, label: d.supplier.name }
|
driver_name: d.driver_name ?? '',
|
||||||
: null,
|
vehicle_plate: d.vehicle_plate ?? '',
|
||||||
supplier_id: d.supplier?.id ?? 0,
|
supplier: d.supplier
|
||||||
products:
|
? { value: d.supplier.id, label: d.supplier.name }
|
||||||
d.items?.map((item) => {
|
: null,
|
||||||
const productData = detailIdToProductId.get(
|
supplier_id: d.supplier?.id ?? 0,
|
||||||
item.stock_transfer_detail_id
|
products:
|
||||||
);
|
d.items?.map((item) => {
|
||||||
return {
|
const productData = detailIdToProductId.get(
|
||||||
product: productData
|
item.stock_transfer_detail_id
|
||||||
? { value: productData.id, label: productData.name }
|
);
|
||||||
: null,
|
return {
|
||||||
product_id: productData?.id ?? 0,
|
product: productData
|
||||||
product_qty: item.quantity,
|
? { value: productData.id, label: productData.name }
|
||||||
};
|
: null,
|
||||||
}) ?? [],
|
product_id: productData?.id ?? 0,
|
||||||
})) ?? [],
|
product_qty: item.quantity,
|
||||||
|
};
|
||||||
|
}) ?? [],
|
||||||
|
})) ?? [
|
||||||
|
{
|
||||||
|
delivery_cost: undefined,
|
||||||
|
delivery_cost_per_item: undefined,
|
||||||
|
document: null,
|
||||||
|
document_path: null,
|
||||||
|
driver_name: '',
|
||||||
|
vehicle_plate: '',
|
||||||
|
supplier: null,
|
||||||
|
supplier_id: 0,
|
||||||
|
products: [
|
||||||
|
{
|
||||||
|
product: null,
|
||||||
|
product_id: 0,
|
||||||
|
product_qty: '',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -35,6 +35,9 @@ import FileInput from '@/components/input/FileInput';
|
|||||||
import CheckboxInput from '@/components/input/CheckboxInput';
|
import CheckboxInput from '@/components/input/CheckboxInput';
|
||||||
import Badge from '@/components/Badge';
|
import Badge from '@/components/Badge';
|
||||||
import Card from '@/components/Card';
|
import Card from '@/components/Card';
|
||||||
|
import { S3_PUBLIC_BASE_URL } from '@/config/constant';
|
||||||
|
import { getUniqueFormikErrors } from '@/lib/formik-helper';
|
||||||
|
import AlertErrorList from '@/components/helper/form/FormErrors';
|
||||||
|
|
||||||
interface MovementFormProps {
|
interface MovementFormProps {
|
||||||
type?: 'add' | 'edit' | 'detail';
|
type?: 'add' | 'edit' | 'detail';
|
||||||
@@ -52,19 +55,12 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
|||||||
] = useState('');
|
] = useState('');
|
||||||
const [selectedProducts, setSelectedProducts] = useState<number[]>([]);
|
const [selectedProducts, setSelectedProducts] = useState<number[]>([]);
|
||||||
const [selectedDeliveries, setSelectedDeliveries] = useState<number[]>([]);
|
const [selectedDeliveries, setSelectedDeliveries] = useState<number[]>([]);
|
||||||
|
const [formErrorList, setFormErrorList] = useState<string[]>([]);
|
||||||
|
|
||||||
// ===== FORM HANDLERS =====
|
// ===== FORM HANDLERS =====
|
||||||
const createMovementHandler = useCallback(
|
const createMovementHandler = useCallback(
|
||||||
async (payload: CreateMovementPayload, documents: File[] = []) => {
|
async (payload: CreateMovementPayload) => {
|
||||||
const formData = new FormData();
|
const res = await MovementApi.createMovement(payload);
|
||||||
formData.append('data', JSON.stringify(payload));
|
|
||||||
documents.forEach((file, index) => {
|
|
||||||
formData.append(`documents[${index}]`, file);
|
|
||||||
});
|
|
||||||
|
|
||||||
const res = await MovementApi.create(
|
|
||||||
formData as unknown as CreateMovementPayload
|
|
||||||
);
|
|
||||||
if (isResponseError(res)) {
|
if (isResponseError(res)) {
|
||||||
setMovementFormErrorMessage(res.message);
|
setMovementFormErrorMessage(res.message);
|
||||||
return;
|
return;
|
||||||
@@ -193,12 +189,45 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const documents: File[] = [];
|
const documents: File[] = [];
|
||||||
|
const documentNameToIndex = new Map<string, number>();
|
||||||
|
let sequentialDocumentIndex = 0;
|
||||||
|
|
||||||
const deliveriesPayload = values.deliveries.map((d) => {
|
const deliveriesPayload = values.deliveries.map((d) => {
|
||||||
let documentIndex = 0;
|
let documentIndex = -1;
|
||||||
|
|
||||||
if (d.document && d.document instanceof File) {
|
if (d.document && d.document instanceof File) {
|
||||||
documents.push(d.document);
|
const fileName = d.document.name;
|
||||||
documentIndex = documents.length - 1;
|
|
||||||
|
if (documentNameToIndex.has(fileName)) {
|
||||||
|
documentIndex = documentNameToIndex.get(fileName)!;
|
||||||
|
} else {
|
||||||
|
documents.push(d.document);
|
||||||
|
documentIndex = sequentialDocumentIndex;
|
||||||
|
documentNameToIndex.set(fileName, documentIndex);
|
||||||
|
sequentialDocumentIndex++;
|
||||||
|
}
|
||||||
|
} else if (d.document_path) {
|
||||||
|
const pathFileName =
|
||||||
|
d.document_path.split('/').pop() || d.document_path;
|
||||||
|
|
||||||
|
if (documentNameToIndex.has(pathFileName)) {
|
||||||
|
documentIndex = documentNameToIndex.get(pathFileName)!;
|
||||||
|
} else {
|
||||||
|
documentIndex = sequentialDocumentIndex;
|
||||||
|
documentNameToIndex.set(pathFileName, documentIndex);
|
||||||
|
sequentialDocumentIndex++;
|
||||||
|
}
|
||||||
|
} else if (d.document && !(d.document instanceof File)) {
|
||||||
|
const existingDocFileName =
|
||||||
|
d.document.path.split('/').pop() || d.document.path;
|
||||||
|
|
||||||
|
if (documentNameToIndex.has(existingDocFileName)) {
|
||||||
|
documentIndex = documentNameToIndex.get(existingDocFileName)!;
|
||||||
|
} else {
|
||||||
|
documentIndex = sequentialDocumentIndex;
|
||||||
|
documentNameToIndex.set(existingDocFileName, documentIndex);
|
||||||
|
sequentialDocumentIndex++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -206,7 +235,6 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
|||||||
delivery_cost_per_item:
|
delivery_cost_per_item:
|
||||||
parseInt((d.delivery_cost_per_item || '').toString()) || 0,
|
parseInt((d.delivery_cost_per_item || '').toString()) || 0,
|
||||||
document_index: documentIndex,
|
document_index: documentIndex,
|
||||||
document_path: d.document_path,
|
|
||||||
driver_name: d.driver_name,
|
driver_name: d.driver_name,
|
||||||
vehicle_plate: d.vehicle_plate,
|
vehicle_plate: d.vehicle_plate,
|
||||||
supplier_id: d.supplier_id,
|
supplier_id: d.supplier_id,
|
||||||
@@ -218,20 +246,23 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const payload: CreateMovementPayload = {
|
const payload: CreateMovementPayload = {
|
||||||
transfer_reason: values.transfer_reason,
|
data: {
|
||||||
transfer_date: values.transfer_date,
|
transfer_reason: values.transfer_reason,
|
||||||
source_warehouse_id: values.source_warehouse_id,
|
transfer_date: values.transfer_date,
|
||||||
destination_warehouse_id: values.destination_warehouse_id,
|
source_warehouse_id: values.source_warehouse_id,
|
||||||
products: values.products.map((p) => ({
|
destination_warehouse_id: values.destination_warehouse_id,
|
||||||
product_id: p.product_id,
|
products: values.products.map((p) => ({
|
||||||
product_qty: parseInt(p.product_qty.toString()) || 0,
|
product_id: p.product_id,
|
||||||
})),
|
product_qty: parseInt(p.product_qty.toString()) || 0,
|
||||||
deliveries: deliveriesPayload,
|
})),
|
||||||
|
deliveries: deliveriesPayload,
|
||||||
|
},
|
||||||
|
documents: documents.length > 0 ? documents : undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'add':
|
case 'add':
|
||||||
await createMovementHandler(payload, documents);
|
await createMovementHandler(payload);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -765,8 +796,36 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
|||||||
type !== 'edit' &&
|
type !== 'edit' &&
|
||||||
type !== 'detail'
|
type !== 'detail'
|
||||||
) {
|
) {
|
||||||
formik.setFieldValue('products', []);
|
if (formik.values.products.length === 0) {
|
||||||
formik.setFieldValue('deliveries', []);
|
formik.setFieldValue('products', [
|
||||||
|
{
|
||||||
|
product: null,
|
||||||
|
product_id: 0,
|
||||||
|
product_qty: '',
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
if (formik.values.deliveries.length === 0) {
|
||||||
|
formik.setFieldValue('deliveries', [
|
||||||
|
{
|
||||||
|
delivery_cost: undefined,
|
||||||
|
delivery_cost_per_item: undefined,
|
||||||
|
document: null,
|
||||||
|
document_path: null,
|
||||||
|
driver_name: '',
|
||||||
|
vehicle_plate: '',
|
||||||
|
supplier: null,
|
||||||
|
supplier_id: 0,
|
||||||
|
products: [
|
||||||
|
{
|
||||||
|
product: null,
|
||||||
|
product_id: 0,
|
||||||
|
product_qty: '',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, [formik.values.source_warehouse_id]);
|
}, [formik.values.source_warehouse_id]);
|
||||||
|
|
||||||
@@ -795,6 +854,22 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
|||||||
formik.errors.destination_warehouse_id,
|
formik.errors.destination_warehouse_id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const handleValidateForm = async () => {
|
||||||
|
const errors = await formik.validateForm();
|
||||||
|
|
||||||
|
if (Object.keys(errors).length > 0) {
|
||||||
|
const errorMessages = getUniqueFormikErrors(errors);
|
||||||
|
setFormErrorList(errorMessages);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleFormSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
||||||
|
e.preventDefault();
|
||||||
|
handleValidateForm();
|
||||||
|
formik.handleSubmit(e);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<section className='w-full'>
|
<section className='w-full'>
|
||||||
@@ -814,10 +889,29 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
|||||||
</h1>
|
</h1>
|
||||||
</header>
|
</header>
|
||||||
<form
|
<form
|
||||||
onSubmit={formik.handleSubmit}
|
onSubmit={handleFormSubmit}
|
||||||
onReset={formik.handleReset}
|
onReset={formik.handleReset}
|
||||||
className='w-full mt-8 flex flex-col gap-6'
|
className='w-full mt-8 flex flex-col gap-6'
|
||||||
>
|
>
|
||||||
|
{movementFormErrorMessage && (
|
||||||
|
<div role='alert' className='alert alert-error'>
|
||||||
|
<Icon
|
||||||
|
icon='material-symbols:error-outline'
|
||||||
|
width={24}
|
||||||
|
height={24}
|
||||||
|
/>
|
||||||
|
<span>{movementFormErrorMessage}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Error List Alert */}
|
||||||
|
{formErrorList.length > 0 && (
|
||||||
|
<AlertErrorList
|
||||||
|
formErrorList={formErrorList}
|
||||||
|
onClose={() => setFormErrorList([])}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Top card - Movement details */}
|
{/* Top card - Movement details */}
|
||||||
<Card
|
<Card
|
||||||
title='Detail Movement'
|
title='Detail Movement'
|
||||||
@@ -1101,7 +1195,7 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
|||||||
<th>
|
<th>
|
||||||
Produk
|
Produk
|
||||||
<span
|
<span
|
||||||
className='tooltip tooltip-error tooltip-bottom z-[9999]'
|
className='tooltip tooltip-error tooltip-bottom z-9999'
|
||||||
data-tip='required'
|
data-tip='required'
|
||||||
>
|
>
|
||||||
<span className='text-error'>*</span>
|
<span className='text-error'>*</span>
|
||||||
@@ -1110,7 +1204,7 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
|||||||
<th>
|
<th>
|
||||||
Qty
|
Qty
|
||||||
<span
|
<span
|
||||||
className='tooltip tooltip-error tooltip-bottom z-[9999]'
|
className='tooltip tooltip-error tooltip-bottom z-9999'
|
||||||
data-tip='required'
|
data-tip='required'
|
||||||
>
|
>
|
||||||
<span className='text-error'>*</span>
|
<span className='text-error'>*</span>
|
||||||
@@ -1123,7 +1217,7 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
|||||||
{formik.values.products?.map((product, idx) => (
|
{formik.values.products?.map((product, idx) => (
|
||||||
<tr key={`product-row-${idx}-${product.product_id}`}>
|
<tr key={`product-row-${idx}-${product.product_id}`}>
|
||||||
{type !== 'detail' && (
|
{type !== 'detail' && (
|
||||||
<td className='!align-middle'>
|
<td className='align-middle!'>
|
||||||
<CheckboxInput
|
<CheckboxInput
|
||||||
name={`product-${idx}`}
|
name={`product-${idx}`}
|
||||||
checked={selectedProducts.includes(idx)}
|
checked={selectedProducts.includes(idx)}
|
||||||
@@ -1315,7 +1409,7 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
|||||||
<th>
|
<th>
|
||||||
Produk
|
Produk
|
||||||
<span
|
<span
|
||||||
className='tooltip tooltip-error tooltip-bottom z-[9999]'
|
className='tooltip tooltip-error tooltip-bottom z-9999'
|
||||||
data-tip='required'
|
data-tip='required'
|
||||||
>
|
>
|
||||||
<span className='text-error'>*</span>
|
<span className='text-error'>*</span>
|
||||||
@@ -1324,7 +1418,7 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
|||||||
<th>
|
<th>
|
||||||
Qty
|
Qty
|
||||||
<span
|
<span
|
||||||
className='tooltip tooltip-error tooltip-bottom z-[9999]'
|
className='tooltip tooltip-error tooltip-bottom z-9999'
|
||||||
data-tip='required'
|
data-tip='required'
|
||||||
>
|
>
|
||||||
<span className='text-error'>*</span>
|
<span className='text-error'>*</span>
|
||||||
@@ -1333,7 +1427,7 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
|||||||
<th>
|
<th>
|
||||||
Supplier
|
Supplier
|
||||||
<span
|
<span
|
||||||
className='tooltip tooltip-error tooltip-bottom z-[9999]'
|
className='tooltip tooltip-error tooltip-bottom z-9999'
|
||||||
data-tip='required'
|
data-tip='required'
|
||||||
>
|
>
|
||||||
<span className='text-error'>*</span>
|
<span className='text-error'>*</span>
|
||||||
@@ -1342,7 +1436,7 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
|||||||
<th>
|
<th>
|
||||||
Plat Nomor
|
Plat Nomor
|
||||||
<span
|
<span
|
||||||
className='tooltip tooltip-error tooltip-bottom z-[9999]'
|
className='tooltip tooltip-error tooltip-bottom z-9999'
|
||||||
data-tip='required'
|
data-tip='required'
|
||||||
>
|
>
|
||||||
<span className='text-error'>*</span>
|
<span className='text-error'>*</span>
|
||||||
@@ -1352,7 +1446,7 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
|||||||
<th>
|
<th>
|
||||||
Biaya Pengiriman (Rp.)
|
Biaya Pengiriman (Rp.)
|
||||||
<span
|
<span
|
||||||
className='tooltip tooltip-error tooltip-bottom z-[9999]'
|
className='tooltip tooltip-error tooltip-bottom z-9999'
|
||||||
data-tip='required'
|
data-tip='required'
|
||||||
>
|
>
|
||||||
<span className='text-error'>*</span>
|
<span className='text-error'>*</span>
|
||||||
@@ -1361,7 +1455,7 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
|||||||
<th>
|
<th>
|
||||||
Biaya Per Item (Rp.)
|
Biaya Per Item (Rp.)
|
||||||
<span
|
<span
|
||||||
className='tooltip tooltip-error tooltip-bottom z-[9999]'
|
className='tooltip tooltip-error tooltip-bottom z-9999'
|
||||||
data-tip='required'
|
data-tip='required'
|
||||||
>
|
>
|
||||||
<span className='text-error'>*</span>
|
<span className='text-error'>*</span>
|
||||||
@@ -1370,7 +1464,7 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
|||||||
<th>
|
<th>
|
||||||
Nama Sopir
|
Nama Sopir
|
||||||
<span
|
<span
|
||||||
className='tooltip tooltip-error tooltip-bottom z-[9999]'
|
className='tooltip tooltip-error tooltip-bottom z-9999'
|
||||||
data-tip='required'
|
data-tip='required'
|
||||||
>
|
>
|
||||||
<span className='text-error'>*</span>
|
<span className='text-error'>*</span>
|
||||||
@@ -1383,7 +1477,7 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
|||||||
{formik.values.deliveries?.map((delivery, idx) => (
|
{formik.values.deliveries?.map((delivery, idx) => (
|
||||||
<tr key={`delivery-row-${idx}`}>
|
<tr key={`delivery-row-${idx}`}>
|
||||||
{type !== 'detail' && (
|
{type !== 'detail' && (
|
||||||
<td className='!align-middle'>
|
<td className='align-middle!'>
|
||||||
<CheckboxInput
|
<CheckboxInput
|
||||||
name={`delivery-${idx}`}
|
name={`delivery-${idx}`}
|
||||||
checked={selectedDeliveries.includes(idx)}
|
checked={selectedDeliveries.includes(idx)}
|
||||||
@@ -1537,37 +1631,64 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
|||||||
{type === 'detail' ? (
|
{type === 'detail' ? (
|
||||||
<>
|
<>
|
||||||
<div className='flex flex-col items-start gap-2'>
|
<div className='flex flex-col items-start gap-2'>
|
||||||
<Button
|
{delivery.document_path ? (
|
||||||
color='primary'
|
<Button
|
||||||
className='w-full min-w-52 flex items-center justify-center gap-2'
|
color='primary'
|
||||||
disabled={!delivery.document_path}
|
className='w-full min-w-52 flex items-center justify-center gap-2'
|
||||||
href={delivery.document_path ?? undefined}
|
href={`${S3_PUBLIC_BASE_URL}/${delivery.document_path.startsWith('/') ? delivery.document_path.slice(1) : delivery.document_path}`}
|
||||||
target='_blank'
|
target='_blank'
|
||||||
rel='noopener noreferrer'
|
rel='noopener noreferrer'
|
||||||
>
|
>
|
||||||
{delivery.document_path ? (
|
<Icon
|
||||||
<>
|
icon='material-symbols:file-open-outline'
|
||||||
<Icon
|
width={20}
|
||||||
icon='material-symbols:file-open-outline'
|
height={20}
|
||||||
width={20}
|
/>
|
||||||
height={20}
|
Lihat Dokumen
|
||||||
/>
|
</Button>
|
||||||
Lihat Dokumen
|
) : delivery.document &&
|
||||||
</>
|
delivery.document instanceof File === false ? (
|
||||||
) : (
|
<Button
|
||||||
'-'
|
color='primary'
|
||||||
)}
|
className='w-full min-w-52 flex items-center justify-center gap-2'
|
||||||
</Button>
|
href={`${S3_PUBLIC_BASE_URL}/${delivery.document.path.startsWith('/') ? delivery.document.path.slice(1) : delivery.document.path}`}
|
||||||
|
target='_blank'
|
||||||
|
rel='noopener noreferrer'
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
icon='material-symbols:file-open-outline'
|
||||||
|
width={20}
|
||||||
|
height={20}
|
||||||
|
/>
|
||||||
|
<span className='truncate max-w-[200px]'>
|
||||||
|
{delivery.document.name}
|
||||||
|
</span>
|
||||||
|
</Button>
|
||||||
|
) : (
|
||||||
|
<Button
|
||||||
|
color='neutral'
|
||||||
|
className='w-full min-w-52 flex items-center justify-center gap-2 cursor-not-allowed'
|
||||||
|
disabled
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
icon='material-symbols:description'
|
||||||
|
width={20}
|
||||||
|
height={20}
|
||||||
|
/>
|
||||||
|
Tidak ada dokumen
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<FileInput
|
<FileInput
|
||||||
|
accept='.pdf,.jpg,.jpeg,.png'
|
||||||
name={`deliveries.${idx}.document`}
|
name={`deliveries.${idx}.document`}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
const file = e.target.files?.[0];
|
const file = e.target.files?.[0];
|
||||||
if (file) {
|
if (file) {
|
||||||
if (file.size > 2 * 1024 * 1024) {
|
if (file.size > 5 * 1024 * 1024) {
|
||||||
toast.error('Ukuran dokumen maksimal 2 MB!');
|
toast.error('Ukuran dokumen maksimal 5 MB!');
|
||||||
e.target.value = '';
|
e.target.value = '';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1724,7 +1845,6 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
|||||||
disabled={
|
disabled={
|
||||||
hasInvalidQty ||
|
hasInvalidQty ||
|
||||||
hasExceededStock ||
|
hasExceededStock ||
|
||||||
!formik.isValid ||
|
|
||||||
formik.isSubmitting ||
|
formik.isSubmitting ||
|
||||||
(formik.values.source_warehouse_id ===
|
(formik.values.source_warehouse_id ===
|
||||||
formik.values.destination_warehouse_id &&
|
formik.values.destination_warehouse_id &&
|
||||||
@@ -1737,17 +1857,6 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{movementFormErrorMessage && (
|
|
||||||
<div role='alert' className='alert alert-error'>
|
|
||||||
<Icon
|
|
||||||
icon='material-symbols:error-outline'
|
|
||||||
width={24}
|
|
||||||
height={24}
|
|
||||||
/>
|
|
||||||
<span>{movementFormErrorMessage}</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</form>
|
</form>
|
||||||
</section>
|
</section>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import Table from '@/components/Table';
|
|||||||
import RowCollapseOptions from '@/components/table/RowCollapseOptions';
|
import RowCollapseOptions from '@/components/table/RowCollapseOptions';
|
||||||
import RowDropdownOptions from '@/components/table/RowDropdownOptions';
|
import RowDropdownOptions from '@/components/table/RowDropdownOptions';
|
||||||
import RowOptionsMenuWrapper from '@/components/table/RowOptionsMenuWrapper';
|
import RowOptionsMenuWrapper from '@/components/table/RowOptionsMenuWrapper';
|
||||||
|
import RequirePermission from '@/components/helper/RequirePermission';
|
||||||
import { ROWS_OPTIONS } from '@/config/constant';
|
import { ROWS_OPTIONS } from '@/config/constant';
|
||||||
import { isResponseSuccess } from '@/lib/api-helper';
|
import { isResponseSuccess } from '@/lib/api-helper';
|
||||||
import { cn, formatCurrency, formatNumber } from '@/lib/helper';
|
import { cn, formatCurrency, formatNumber } from '@/lib/helper';
|
||||||
@@ -31,15 +32,17 @@ const RowOptionsMenu = ({
|
|||||||
props: CellContext<InventoryProduct, unknown>;
|
props: CellContext<InventoryProduct, unknown>;
|
||||||
}) => (
|
}) => (
|
||||||
<RowOptionsMenuWrapper type={type}>
|
<RowOptionsMenuWrapper type={type}>
|
||||||
<Button
|
<RequirePermission permissions='lti.inventory.product_stock.detail'>
|
||||||
href={`/inventory/product/detail?inventoryProductId=${props.row.original.id}`}
|
<Button
|
||||||
variant='ghost'
|
href={`/inventory/product/detail?inventoryProductId=${props.row.original.id}`}
|
||||||
color='primary'
|
variant='ghost'
|
||||||
className='justify-start text-sm'
|
color='primary'
|
||||||
>
|
className='justify-start text-sm'
|
||||||
<Icon icon='mdi:eye-outline' width={16} height={16} />
|
>
|
||||||
Detail
|
<Icon icon='mdi:eye-outline' width={16} height={16} />
|
||||||
</Button>
|
Detail
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
</RowOptionsMenuWrapper>
|
</RowOptionsMenuWrapper>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
import Button from '@/components/Button';
|
import Button from '@/components/Button';
|
||||||
import CheckboxInput from '@/components/input/CheckboxInput';
|
import CheckboxInput from '@/components/input/CheckboxInput';
|
||||||
import SelectInput, { OptionType } from '@/components/input/SelectInput';
|
import SelectInput, {
|
||||||
|
OptionType,
|
||||||
|
useSelect,
|
||||||
|
} from '@/components/input/SelectInput';
|
||||||
import Modal, { useModal } from '@/components/Modal';
|
import Modal, { useModal } from '@/components/Modal';
|
||||||
import ConfirmationModal from '@/components/modal/ConfirmationModal';
|
import ConfirmationModal from '@/components/modal/ConfirmationModal';
|
||||||
import ConfirmationModalWithNotes from '@/components/modal/ConfirmationModalWithNotes';
|
import ConfirmationModalWithNotes from '@/components/modal/ConfirmationModalWithNotes';
|
||||||
@@ -26,6 +29,10 @@ import { useRouter } from 'next/navigation';
|
|||||||
import { useCallback, useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
import toast from 'react-hot-toast';
|
import toast from 'react-hot-toast';
|
||||||
import useSWR from 'swr';
|
import useSWR from 'swr';
|
||||||
|
import RequirePermission from '@/components/helper/RequirePermission';
|
||||||
|
import { useAuth } from '@/services/hooks/useAuth';
|
||||||
|
import { CustomerApi, ProductApi } from '@/services/api/master-data';
|
||||||
|
import { MARKETING_APPROVAL_LINE } from '@/config/approval-line';
|
||||||
|
|
||||||
const RowsOptionsMenu = ({
|
const RowsOptionsMenu = ({
|
||||||
type = 'dropdown',
|
type = 'dropdown',
|
||||||
@@ -50,57 +57,75 @@ const RowsOptionsMenu = ({
|
|||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div className='flex flex-col gap-1'>
|
<div className='flex flex-col gap-1'>
|
||||||
<Button
|
<RequirePermission permissions='lti.marketing.delivery_order.detail'>
|
||||||
href={`/marketing/detail?marketingId=${props.row.original.id}`}
|
|
||||||
variant='ghost'
|
|
||||||
color='primary'
|
|
||||||
className='justify-start text-sm'
|
|
||||||
>
|
|
||||||
<Icon icon='mdi:eye-outline' width={16} height={16} />
|
|
||||||
Detail
|
|
||||||
</Button>
|
|
||||||
{props.row.original.latest_approval.step_number != 1 && (
|
|
||||||
<Button
|
<Button
|
||||||
href={
|
href={`/marketing/detail?marketingId=${props.row.original.id}`}
|
||||||
props.row.original.latest_approval.step_number == 3
|
|
||||||
? `/marketing/detail/delivery-orders/edit?marketingId=${props.row.original.id}`
|
|
||||||
: props.row.original.latest_approval.step_number == 2
|
|
||||||
? `/marketing/add/delivery-orders?marketingId=${props.row.original.id}`
|
|
||||||
: undefined
|
|
||||||
}
|
|
||||||
onClick={() => {
|
|
||||||
if (props.row.original.latest_approval.step_number == 2) {
|
|
||||||
deliveryClickHandler?.();
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
variant='ghost'
|
variant='ghost'
|
||||||
color='success'
|
color='primary'
|
||||||
className='justify-start text-sm'
|
className='justify-start text-sm'
|
||||||
>
|
>
|
||||||
<Icon icon='mdi:truck' width={16} height={16} />
|
<Icon icon='mdi:eye-outline' width={16} height={16} />
|
||||||
Deliver
|
Detail
|
||||||
</Button>
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
|
{props.row.original.latest_approval.step_number != 1 && (
|
||||||
|
<>
|
||||||
|
<RequirePermission
|
||||||
|
permissions={
|
||||||
|
props.row.original.latest_approval.step_number == 3
|
||||||
|
? 'lti.marketing.delivery_order.update'
|
||||||
|
: 'lti.marketing.delivery_order.create'
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
href={
|
||||||
|
props.row.original.latest_approval.step_number == 3
|
||||||
|
? `/marketing/detail/delivery-orders/edit?marketingId=${props.row.original.id}`
|
||||||
|
: props.row.original.latest_approval.step_number == 2
|
||||||
|
? `/marketing/add/delivery-orders?marketingId=${props.row.original.id}`
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
onClick={() => {
|
||||||
|
if (props.row.original.latest_approval.step_number == 2) {
|
||||||
|
deliveryClickHandler?.();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
variant='ghost'
|
||||||
|
color='success'
|
||||||
|
className='justify-start text-sm'
|
||||||
|
>
|
||||||
|
<Icon icon='mdi:truck' width={16} height={16} />
|
||||||
|
Deliver
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
{props.row.original.latest_approval.step_number != 3 && (
|
{props.row.original.latest_approval.step_number != 3 && (
|
||||||
<Button
|
<>
|
||||||
href={`/marketing/detail/sales-orders/edit?marketingId=${props.row.original.id}`}
|
<RequirePermission permissions='lti.marketing.sales_order.update'>
|
||||||
variant='ghost'
|
<Button
|
||||||
color='warning'
|
href={`/marketing/detail/sales-orders/edit?marketingId=${props.row.original.id}`}
|
||||||
className='justify-start text-sm'
|
variant='ghost'
|
||||||
>
|
color='warning'
|
||||||
<Icon icon='mdi:pencil-outline' width={16} height={16} />
|
className='justify-start text-sm'
|
||||||
Edit
|
>
|
||||||
</Button>
|
<Icon icon='mdi:pencil-outline' width={16} height={16} />
|
||||||
|
Edit
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
<Button
|
<RequirePermission permissions='lti.marketing.sales_order.delete'>
|
||||||
onClick={deleteClickHandler}
|
<Button
|
||||||
variant='ghost'
|
onClick={deleteClickHandler}
|
||||||
color='error'
|
variant='ghost'
|
||||||
className='text-error hover:text-inherit justify-start text-sm'
|
color='error'
|
||||||
>
|
className='text-error hover:text-inherit justify-start text-sm'
|
||||||
<Icon icon='mdi:delete-outline' width={16} height={16} />
|
>
|
||||||
Delete
|
<Icon icon='mdi:delete-outline' width={16} height={16} />
|
||||||
</Button>
|
Delete
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -108,32 +133,77 @@ const RowsOptionsMenu = ({
|
|||||||
|
|
||||||
const MarketingTable = () => {
|
const MarketingTable = () => {
|
||||||
const [search, setSearch] = useState('');
|
const [search, setSearch] = useState('');
|
||||||
const [page, setPage] = useState(1);
|
|
||||||
const [pageSize, setPageSize] = useState(10);
|
|
||||||
|
|
||||||
const [approveAction, setApproveAction] = useState<'APPROVED' | 'REJECTED'>(
|
const [approveAction, setApproveAction] = useState<'APPROVED' | 'REJECTED'>(
|
||||||
'APPROVED'
|
'APPROVED'
|
||||||
);
|
);
|
||||||
const [selectedItem, setSelectedItem] = useState<Marketing | null>(null);
|
const [selectedItem, setSelectedItem] = useState<Marketing | null>(null);
|
||||||
const [rowSelection, setRowSelection] = useState<Record<string, boolean>>({});
|
const [rowSelection, setRowSelection] = useState<Record<string, boolean>>({});
|
||||||
|
const { permissionCheck } = useAuth();
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const {
|
|
||||||
data: marketing,
|
|
||||||
isLoading: isLoadingMarketing,
|
|
||||||
mutate: refreshMarketing,
|
|
||||||
} = useSWR(MarketingApi.basePath, MarketingApi.getAllFetcher);
|
|
||||||
|
|
||||||
const deleteModal = useModal();
|
const deleteModal = useModal();
|
||||||
const confirmationModal = useModal();
|
const confirmationModal = useModal();
|
||||||
const productsModal = useModal();
|
const productsModal = useModal();
|
||||||
const deliveryModal = useModal();
|
const deliveryModal = useModal();
|
||||||
|
const {
|
||||||
|
state: tableFilterState,
|
||||||
|
updateFilter,
|
||||||
|
setPage,
|
||||||
|
setPageSize,
|
||||||
|
toQueryString: getTableFilterToQueryString,
|
||||||
|
} = useTableFilter({
|
||||||
|
initial: {
|
||||||
|
search: '',
|
||||||
|
product_ids: '',
|
||||||
|
status: '',
|
||||||
|
customer_id: '',
|
||||||
|
page: 1,
|
||||||
|
limit: 10,
|
||||||
|
},
|
||||||
|
paramMap: {
|
||||||
|
page: 'page',
|
||||||
|
pageSize: 'limit',
|
||||||
|
product_ids: 'product_ids',
|
||||||
|
status: 'status',
|
||||||
|
customer_id: 'customer_id',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// ===== FETCH DATA =====
|
||||||
|
const {
|
||||||
|
data: marketing,
|
||||||
|
isLoading: isLoadingMarketing,
|
||||||
|
mutate: refreshMarketing,
|
||||||
|
} = useSWR(
|
||||||
|
`${MarketingApi.basePath}${getTableFilterToQueryString()}`,
|
||||||
|
MarketingApi.getAllFetcher
|
||||||
|
);
|
||||||
|
|
||||||
|
// ===== OPTIONS =====
|
||||||
|
const {
|
||||||
|
options: productsOptions,
|
||||||
|
isLoadingOptions: isLoadingProductsOptions,
|
||||||
|
} = useSelect(ProductApi.basePath, 'id', 'name', '', {
|
||||||
|
limit: 'limit',
|
||||||
|
});
|
||||||
|
const {
|
||||||
|
options: customersOptions,
|
||||||
|
isLoadingOptions: isLoadingCustomersOptions,
|
||||||
|
} = useSelect(CustomerApi.basePath, 'id', 'name', '', {
|
||||||
|
limit: 'limit',
|
||||||
|
});
|
||||||
|
const statusOptions = MARKETING_APPROVAL_LINE.map((item) => ({
|
||||||
|
value: item.step_number,
|
||||||
|
label: item.step_name,
|
||||||
|
}));
|
||||||
|
|
||||||
|
// ===== HANDLER =====
|
||||||
const searchChangeHandler = useCallback(
|
const searchChangeHandler = useCallback(
|
||||||
(e: React.ChangeEvent<HTMLInputElement>) => {
|
(e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
setSearch(e.target.value);
|
setSearch(e.target.value);
|
||||||
setPage(1);
|
updateFilter('page', 1);
|
||||||
|
updateFilter('search', e.target.value);
|
||||||
},
|
},
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
@@ -141,7 +211,8 @@ const MarketingTable = () => {
|
|||||||
(val: OptionType | OptionType[] | null) => {
|
(val: OptionType | OptionType[] | null) => {
|
||||||
const newVal = val as OptionType;
|
const newVal = val as OptionType;
|
||||||
setPageSize(newVal.value as number);
|
setPageSize(newVal.value as number);
|
||||||
setPage(1);
|
updateFilter('page', 1);
|
||||||
|
updateFilter('limit', newVal.value as number);
|
||||||
},
|
},
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
@@ -246,20 +317,6 @@ const MarketingTable = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const {
|
|
||||||
state: tableFilterState,
|
|
||||||
updateFilter,
|
|
||||||
toQueryString: getTableFilterToQueryString,
|
|
||||||
} = useTableFilter({
|
|
||||||
initial: {
|
|
||||||
search: '',
|
|
||||||
},
|
|
||||||
paramMap: {
|
|
||||||
page: 'page',
|
|
||||||
pageSize: 'limit',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const getRowCanSelect = (row: Row<Marketing>): boolean => {
|
const getRowCanSelect = (row: Row<Marketing>): boolean => {
|
||||||
const approval = row.original.latest_approval;
|
const approval = row.original.latest_approval;
|
||||||
return approval?.step_number === 1 && approval?.action !== 'REJECTED';
|
return approval?.step_number === 1 && approval?.action !== 'REJECTED';
|
||||||
@@ -270,10 +327,14 @@ const MarketingTable = () => {
|
|||||||
<div className='flex flex-col gap-4'>
|
<div className='flex flex-col gap-4'>
|
||||||
<div className='flex flex-col gap-2 mb-4'>
|
<div className='flex flex-col gap-2 mb-4'>
|
||||||
<TableToolbar
|
<TableToolbar
|
||||||
addButton={{
|
addButton={
|
||||||
href: '/marketing/add/sales-orders',
|
permissionCheck('lti.marketing.sales_order.create')
|
||||||
label: 'Tambah Sales Order',
|
? {
|
||||||
}}
|
href: '/marketing/add/sales-orders',
|
||||||
|
label: 'Tambah Sales Order',
|
||||||
|
}
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
search={{
|
search={{
|
||||||
value: search,
|
value: search,
|
||||||
onChange: searchChangeHandler,
|
onChange: searchChangeHandler,
|
||||||
@@ -281,37 +342,64 @@ const MarketingTable = () => {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<div className='flex flex-row gap-2'>
|
<div className='flex flex-row gap-2'>
|
||||||
<Button
|
<RequirePermission permissions='lti.marketing.sales_order.approve'>
|
||||||
color='success'
|
<Button
|
||||||
onClick={approveClickHandler}
|
color='success'
|
||||||
className='justify-start text-sm'
|
onClick={approveClickHandler}
|
||||||
disabled={disableApprove}
|
className='justify-start text-sm'
|
||||||
>
|
disabled={disableApprove}
|
||||||
<Icon icon='material-symbols:check' width={24} height={24} />
|
>
|
||||||
Approve
|
<Icon icon='material-symbols:check' width={24} height={24} />
|
||||||
</Button>
|
Approve
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
|
|
||||||
<Button
|
<RequirePermission permissions='lti.marketing.sales_order.approve'>
|
||||||
color='error'
|
<Button
|
||||||
onClick={rejectClickHandler}
|
color='error'
|
||||||
className='justify-start text-sm'
|
onClick={rejectClickHandler}
|
||||||
disabled={disableReject}
|
className='justify-start text-sm'
|
||||||
>
|
disabled={disableReject}
|
||||||
<Icon icon='material-symbols:close' width={24} height={24} />
|
>
|
||||||
Reject
|
<Icon icon='material-symbols:close' width={24} height={24} />
|
||||||
</Button>
|
Reject
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
</div>
|
</div>
|
||||||
<TableRowSizeSelector
|
<TableRowSizeSelector
|
||||||
value={pageSize}
|
value={tableFilterState.pageSize}
|
||||||
onChange={pageSizeChangeHandler}
|
onChange={pageSizeChangeHandler}
|
||||||
options={ROWS_OPTIONS}
|
options={ROWS_OPTIONS}
|
||||||
|
className='flex sm:flex-row flex-col gap-3 items-end justify-end'
|
||||||
>
|
>
|
||||||
{/* select multiple product */}
|
{/* select multiple product */}
|
||||||
<SelectInput
|
<SelectInput
|
||||||
label='Product'
|
label='Product'
|
||||||
isClearable
|
isClearable
|
||||||
placeholder='Pilih product'
|
placeholder='Pilih product'
|
||||||
options={[]}
|
options={productsOptions}
|
||||||
|
isLoading={isLoadingProductsOptions}
|
||||||
|
value={
|
||||||
|
tableFilterState.product_ids
|
||||||
|
?.split(',')
|
||||||
|
.map((id) =>
|
||||||
|
productsOptions.find(
|
||||||
|
(option) => option.value === Number(id)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.filter(
|
||||||
|
(option): option is { value: number; label: string } =>
|
||||||
|
option !== undefined
|
||||||
|
) ?? null
|
||||||
|
}
|
||||||
|
onChange={(value: OptionType | OptionType[] | null) =>
|
||||||
|
updateFilter(
|
||||||
|
'product_ids',
|
||||||
|
(value as OptionType[])
|
||||||
|
?.map((item: OptionType) => item.value.toString())
|
||||||
|
.join(',') || ''
|
||||||
|
)
|
||||||
|
}
|
||||||
isMulti
|
isMulti
|
||||||
/>
|
/>
|
||||||
{/* select status */}
|
{/* select status */}
|
||||||
@@ -319,14 +407,43 @@ const MarketingTable = () => {
|
|||||||
label='Status'
|
label='Status'
|
||||||
isClearable
|
isClearable
|
||||||
placeholder='Pilih status'
|
placeholder='Pilih status'
|
||||||
options={[]}
|
options={statusOptions}
|
||||||
|
value={
|
||||||
|
tableFilterState.status
|
||||||
|
? statusOptions.find(
|
||||||
|
(option) =>
|
||||||
|
option.value === Number(tableFilterState.status)
|
||||||
|
)
|
||||||
|
: null
|
||||||
|
}
|
||||||
|
onChange={(value: OptionType | OptionType[] | null) =>
|
||||||
|
updateFilter(
|
||||||
|
'status',
|
||||||
|
(value as OptionType)?.value.toString() || ''
|
||||||
|
)
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
{/* select customer */}
|
{/* select customer */}
|
||||||
<SelectInput
|
<SelectInput
|
||||||
label='Customer'
|
label='Customer'
|
||||||
isClearable
|
isClearable
|
||||||
placeholder='Pilih customer'
|
placeholder='Pilih customer'
|
||||||
options={[]}
|
options={customersOptions}
|
||||||
|
isLoading={isLoadingCustomersOptions}
|
||||||
|
value={
|
||||||
|
tableFilterState.customer_id
|
||||||
|
? customersOptions.find(
|
||||||
|
(option) =>
|
||||||
|
option.value === Number(tableFilterState.customer_id)
|
||||||
|
)
|
||||||
|
: null
|
||||||
|
}
|
||||||
|
onChange={(value: OptionType | OptionType[] | null) =>
|
||||||
|
updateFilter(
|
||||||
|
'customer_id',
|
||||||
|
(value as OptionType)?.value.toString() || ''
|
||||||
|
)
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</TableRowSizeSelector>
|
</TableRowSizeSelector>
|
||||||
</div>
|
</div>
|
||||||
@@ -492,8 +609,8 @@ const MarketingTable = () => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
pageSize={pageSize}
|
pageSize={tableFilterState.pageSize}
|
||||||
page={page}
|
page={tableFilterState.page}
|
||||||
onPageChange={setPage}
|
onPageChange={setPage}
|
||||||
className={{
|
className={{
|
||||||
tableWrapperClassName: 'overflow-x-auto min-h-full!',
|
tableWrapperClassName: 'overflow-x-auto min-h-full!',
|
||||||
@@ -565,7 +682,7 @@ const MarketingTable = () => {
|
|||||||
<Modal
|
<Modal
|
||||||
ref={productsModal.ref}
|
ref={productsModal.ref}
|
||||||
className={{
|
className={{
|
||||||
modalBox: 'max-w-2/5 z-100',
|
modalBox: 'xs:max-w-2/5 z-100',
|
||||||
}}
|
}}
|
||||||
closeOnBackdrop
|
closeOnBackdrop
|
||||||
>
|
>
|
||||||
@@ -607,6 +724,7 @@ const MarketingTable = () => {
|
|||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
className={{
|
className={{
|
||||||
|
containerClassName: 'p-6',
|
||||||
tableWrapperClassName: 'overflow-x-auto min-h-full!',
|
tableWrapperClassName: 'overflow-x-auto min-h-full!',
|
||||||
tableClassName: 'font-inter w-full table-auto min-h-full!',
|
tableClassName: 'font-inter w-full table-auto min-h-full!',
|
||||||
headerRowClassName: 'border-b border-b-gray-200',
|
headerRowClassName: 'border-b border-b-gray-200',
|
||||||
@@ -617,6 +735,7 @@ const MarketingTable = () => {
|
|||||||
'px-6 py-3 last:flex last:flex-row last:justify-end',
|
'px-6 py-3 last:flex last:flex-row last:justify-end',
|
||||||
paginationClassName: 'hidden',
|
paginationClassName: 'hidden',
|
||||||
}}
|
}}
|
||||||
|
isLoading={isLoadingMarketing}
|
||||||
/>
|
/>
|
||||||
</Modal>
|
</Modal>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import { useState } from 'react';
|
|||||||
import toast from 'react-hot-toast';
|
import toast from 'react-hot-toast';
|
||||||
import SalesOrderExport from '@/components/pages/marketing/pdf/SalesOrderExport';
|
import SalesOrderExport from '@/components/pages/marketing/pdf/SalesOrderExport';
|
||||||
import DeliveryOrderExport from '@/components/pages/marketing/pdf/DeliveryOrderExport';
|
import DeliveryOrderExport from '@/components/pages/marketing/pdf/DeliveryOrderExport';
|
||||||
|
import RequirePermission from '@/components/helper/RequirePermission';
|
||||||
|
|
||||||
const MarketingDetail = ({
|
const MarketingDetail = ({
|
||||||
initialValues,
|
initialValues,
|
||||||
@@ -76,10 +77,6 @@ const MarketingDetail = ({
|
|||||||
confirmationModal.openModal();
|
confirmationModal.openModal();
|
||||||
};
|
};
|
||||||
|
|
||||||
const deliveryClickHandler = () => {
|
|
||||||
deliveryModal.openModal();
|
|
||||||
};
|
|
||||||
|
|
||||||
const deleteClickHandler = () => {
|
const deleteClickHandler = () => {
|
||||||
deleteModal.openModal();
|
deleteModal.openModal();
|
||||||
};
|
};
|
||||||
@@ -127,52 +124,70 @@ const MarketingDetail = ({
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className='flex flex-col w-full gap-4'>
|
<div className='flex flex-col w-full gap-4'>
|
||||||
<FormHeader title='Detail Sales Order' backUrl='/marketing' />
|
<FormHeader
|
||||||
|
title={`Detail ${Number(initialValues?.latest_approval?.step_number) > 2 ? 'Delivery Order' : 'Sales Order'}`}
|
||||||
|
backUrl='/marketing'
|
||||||
|
/>
|
||||||
{!isLoadingApproval && approvals && (
|
{!isLoadingApproval && approvals && (
|
||||||
<ApprovalSteps approvals={approvals} />
|
<ApprovalSteps approvals={approvals} />
|
||||||
)}
|
)}
|
||||||
<div className='flex-row flex gap-3'>
|
<div className='flex-row flex gap-3'>
|
||||||
{initialValues?.latest_approval?.step_number == 1 && (
|
{initialValues?.latest_approval?.step_number == 1 && (
|
||||||
<>
|
<>
|
||||||
<Button
|
<RequirePermission permissions='lti.marketing.sales_order.approve'>
|
||||||
color='success'
|
<Button
|
||||||
onClick={approveClickHandler}
|
color='success'
|
||||||
disabled={
|
onClick={approveClickHandler}
|
||||||
initialValues?.latest_approval?.step_number == 1 &&
|
disabled={
|
||||||
initialValues?.latest_approval?.action == 'REJECTED'
|
initialValues?.latest_approval?.step_number == 1 &&
|
||||||
}
|
initialValues?.latest_approval?.action == 'REJECTED'
|
||||||
>
|
}
|
||||||
<Icon icon='mdi:check' width={24} height={24} />
|
>
|
||||||
Approve
|
<Icon icon='mdi:check' width={24} height={24} />
|
||||||
</Button>
|
Approve
|
||||||
<Button
|
</Button>
|
||||||
color='error'
|
</RequirePermission>
|
||||||
onClick={rejectClickHandler}
|
|
||||||
disabled={
|
<RequirePermission permissions='lti.marketing.sales_order.approve'>
|
||||||
initialValues?.latest_approval?.step_number == 1 &&
|
<Button
|
||||||
initialValues?.latest_approval?.action == 'REJECTED'
|
color='error'
|
||||||
}
|
onClick={rejectClickHandler}
|
||||||
>
|
disabled={
|
||||||
<Icon icon='mdi:close' width={24} height={24} />
|
initialValues?.latest_approval?.step_number == 1 &&
|
||||||
Reject
|
initialValues?.latest_approval?.action == 'REJECTED'
|
||||||
</Button>
|
}
|
||||||
|
>
|
||||||
|
<Icon icon='mdi:close' width={24} height={24} />
|
||||||
|
Reject
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{initialValues?.latest_approval?.step_number != 1 && (
|
{initialValues?.latest_approval?.step_number != 1 && (
|
||||||
<Button
|
<>
|
||||||
color='success'
|
<RequirePermission
|
||||||
href={
|
permissions={
|
||||||
initialValues?.latest_approval?.step_number == 3
|
initialValues?.latest_approval?.step_number == 3
|
||||||
? `/marketing/detail/delivery-orders/edit?marketingId=${initialValues?.id}`
|
? 'lti.marketing.delivery_order.update'
|
||||||
: `/marketing/add/delivery-orders?marketingId=${initialValues?.id}`
|
: 'lti.marketing.delivery_order.create'
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<Icon icon='mdi:truck' width={24} height={24} />
|
<Button
|
||||||
{initialValues?.latest_approval?.step_number == 3
|
color='success'
|
||||||
? 'Edit '
|
href={
|
||||||
: 'Tambah '}
|
initialValues?.latest_approval?.step_number == 3
|
||||||
Delivery Order
|
? `/marketing/detail/delivery-orders/edit?marketingId=${initialValues?.id}`
|
||||||
</Button>
|
: `/marketing/add/delivery-orders?marketingId=${initialValues?.id}`
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Icon icon='mdi:truck' width={24} height={24} />
|
||||||
|
{initialValues?.latest_approval?.step_number == 3
|
||||||
|
? 'Edit '
|
||||||
|
: 'Tambah '}
|
||||||
|
Delivery Order
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -190,8 +205,23 @@ const MarketingDetail = ({
|
|||||||
No. Sales Order
|
No. Sales Order
|
||||||
</td>
|
</td>
|
||||||
<td>:</td>
|
<td>:</td>
|
||||||
<td width='50%'>{initialValues?.so_number}</td>
|
<td width='50%' className='font-mono'>
|
||||||
|
{initialValues?.so_number}
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{Number(initialValues?.latest_approval?.step_number) > 2 && (
|
||||||
|
<tr>
|
||||||
|
<td width='45%' className='font-semibold'>
|
||||||
|
No. Delivery Order
|
||||||
|
</td>
|
||||||
|
<td>:</td>
|
||||||
|
<td width='50%' className='font-mono'>
|
||||||
|
{initialValues?.delivery_order
|
||||||
|
?.map((item) => item.do_number)
|
||||||
|
.join(', ')}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
<tr>
|
<tr>
|
||||||
<td className='font-semibold'>Nama Pelanggan</td>
|
<td className='font-semibold'>Nama Pelanggan</td>
|
||||||
<td>:</td>
|
<td>:</td>
|
||||||
@@ -218,12 +248,27 @@ const MarketingDetail = ({
|
|||||||
<td>{initialValues?.notes ?? '-'}</td>
|
<td>{initialValues?.notes ?? '-'}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td className='font-semibold'>Dokumen</td>
|
<td className='font-semibold'>Dokumen Penjualan</td>
|
||||||
<td>:</td>
|
<td>:</td>
|
||||||
<td>
|
<td>
|
||||||
<SalesOrderExport data={initialValues} />
|
<SalesOrderExport data={initialValues} />
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{Number(initialValues?.latest_approval?.step_number) > 2 && (
|
||||||
|
<tr>
|
||||||
|
<td className='font-semibold'>Dokumen Pengiriman</td>
|
||||||
|
<td>:</td>
|
||||||
|
<td className='flex flex-wrap gap-2'>
|
||||||
|
{initialValues?.delivery_order?.map((item, index) => (
|
||||||
|
<DeliveryOrderExport
|
||||||
|
key={index}
|
||||||
|
data={initialValues}
|
||||||
|
deliveryOrder={item}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
@@ -413,19 +458,25 @@ const MarketingDetail = ({
|
|||||||
)}
|
)}
|
||||||
<div className='flex flex-row gap-3'>
|
<div className='flex flex-row gap-3'>
|
||||||
{initialValues?.latest_approval?.step_number != 3 && (
|
{initialValues?.latest_approval?.step_number != 3 && (
|
||||||
<Button
|
<>
|
||||||
color='warning'
|
<RequirePermission permissions='lti.marketing.sales_order.update'>
|
||||||
type='button'
|
<Button
|
||||||
href={`/marketing/detail/${initialValues?.latest_approval.step_number == 3 ? 'delivery-orders' : 'sales-orders'}/edit?marketingId=${initialValues?.id}`}
|
color='warning'
|
||||||
>
|
type='button'
|
||||||
<Icon icon='mdi:pencil' width={24} height={24} />
|
href={`/marketing/detail/${initialValues?.latest_approval?.step_number == 3 ? 'delivery-orders' : 'sales-orders'}/edit?marketingId=${initialValues?.id}`}
|
||||||
Edit
|
>
|
||||||
</Button>
|
<Icon icon='mdi:pencil' width={24} height={24} />
|
||||||
|
Edit
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
<Button color='error' onClick={deleteClickHandler}>
|
<RequirePermission permissions='lti.marketing.sales_order.delete'>
|
||||||
<Icon icon='mdi:delete' width={24} height={24} />
|
<Button color='error' onClick={deleteClickHandler}>
|
||||||
Hapus
|
<Icon icon='mdi:delete' width={24} height={24} />
|
||||||
</Button>
|
Hapus
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<ConfirmationModal
|
<ConfirmationModal
|
||||||
|
|||||||
@@ -47,6 +47,9 @@ import DeliveryOrderProductTable from '@/components/pages/marketing/form/table-v
|
|||||||
import DeliveryOrderProductForm from '@/components/pages/marketing/form/repeater/delivery-order/DeliverOrderProduct';
|
import DeliveryOrderProductForm from '@/components/pages/marketing/form/repeater/delivery-order/DeliverOrderProduct';
|
||||||
import { SalesOrderProductFormValues } from '@/components/pages/marketing/form/repeater/sales-order/SalesOrderProduct.schema';
|
import { SalesOrderProductFormValues } from '@/components/pages/marketing/form/repeater/sales-order/SalesOrderProduct.schema';
|
||||||
import { DeliveryOrderProductFormValues } from '@/components/pages/marketing/form/repeater/delivery-order/DeliverOrderProduct.schema';
|
import { DeliveryOrderProductFormValues } from '@/components/pages/marketing/form/repeater/delivery-order/DeliverOrderProduct.schema';
|
||||||
|
import RequirePermission from '@/components/helper/RequirePermission';
|
||||||
|
import AlertErrorList from '@/components/helper/form/FormErrors';
|
||||||
|
import { useFormikErrorList } from '@/services/hooks/useFormikErrorList';
|
||||||
|
|
||||||
const MemoizedSalesOrderProductTable = memo(SalesOrderProductTable);
|
const MemoizedSalesOrderProductTable = memo(SalesOrderProductTable);
|
||||||
const MemoizedSalesOrderProductForm = memo(SalesOrderProductForm);
|
const MemoizedSalesOrderProductForm = memo(SalesOrderProductForm);
|
||||||
@@ -557,11 +560,14 @@ const MarketingForm = ({
|
|||||||
);
|
);
|
||||||
}, [memoSalesOrder]);
|
}, [memoSalesOrder]);
|
||||||
|
|
||||||
|
// ===== Formik Error List =====
|
||||||
|
const { formErrorList, close, handleFormSubmit } = useFormikErrorList(formik);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<form
|
<form
|
||||||
className='flex flex-col gap-4'
|
className='flex flex-col gap-4'
|
||||||
onSubmit={formik.handleSubmit}
|
onSubmit={handleFormSubmit}
|
||||||
onReset={formik.handleReset}
|
onReset={formik.handleReset}
|
||||||
>
|
>
|
||||||
<FormHeader
|
<FormHeader
|
||||||
@@ -575,7 +581,7 @@ const MarketingForm = ({
|
|||||||
wrapper: 'bg-white w-full',
|
wrapper: 'bg-white w-full',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div className='grid grid-cols-2 gap-3 mt-3'>
|
<div className='grid sm:grid-cols-2 gap-3 mt-3'>
|
||||||
<SelectInput
|
<SelectInput
|
||||||
label='Pelanggan'
|
label='Pelanggan'
|
||||||
options={customerOptions}
|
options={customerOptions}
|
||||||
@@ -634,12 +640,6 @@ const MarketingForm = ({
|
|||||||
wrapper: 'bg-white w-full',
|
wrapper: 'bg-white w-full',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{/* <div className='text-blue-500'>
|
|
||||||
{JSON.stringify(formik.values)}
|
|
||||||
</div>
|
|
||||||
<div className='text-red-500'>
|
|
||||||
{JSON.stringify(formik.errors)}
|
|
||||||
</div> */}
|
|
||||||
<MemoizedDeliveryOrderProductTable
|
<MemoizedDeliveryOrderProductTable
|
||||||
formType={formType}
|
formType={formType}
|
||||||
data={deliveryOrderValues}
|
data={deliveryOrderValues}
|
||||||
@@ -650,7 +650,7 @@ const MarketingForm = ({
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Input Notes */}
|
{/* Input Notes */}
|
||||||
<div className='grid grid-cols-2 gap-3'>
|
<div className='grid sm:grid-cols-2 gap-3'>
|
||||||
<DebouncedTextArea
|
<DebouncedTextArea
|
||||||
required
|
required
|
||||||
name='notes'
|
name='notes'
|
||||||
@@ -671,6 +671,8 @@ const MarketingForm = ({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<AlertErrorList formErrorList={formErrorList} onClose={close} />
|
||||||
|
|
||||||
{/* Form Actions */}
|
{/* Form Actions */}
|
||||||
<div className='flex flex-row items-start justify-center gap-2 mt-4'>
|
<div className='flex flex-row items-start justify-center gap-2 mt-4'>
|
||||||
<Button type='reset' color='warning' disabled={formik.isSubmitting}>
|
<Button type='reset' color='warning' disabled={formik.isSubmitting}>
|
||||||
@@ -678,7 +680,7 @@ const MarketingForm = ({
|
|||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
type='submit'
|
type='submit'
|
||||||
disabled={!formik.isValid || formik.isSubmitting}
|
disabled={formik.isSubmitting}
|
||||||
isLoading={formik.isSubmitting}
|
isLoading={formik.isSubmitting}
|
||||||
>
|
>
|
||||||
Submit
|
Submit
|
||||||
@@ -689,15 +691,17 @@ const MarketingForm = ({
|
|||||||
{/* Actions button */}
|
{/* Actions button */}
|
||||||
{formType == 'edit' && (
|
{formType == 'edit' && (
|
||||||
<div className='flex flex-row justify-start'>
|
<div className='flex flex-row justify-start'>
|
||||||
<Button
|
<RequirePermission permissions='lti.marketing.sales_order.delete'>
|
||||||
type='button'
|
<Button
|
||||||
color='error'
|
type='button'
|
||||||
onClick={handleDelete}
|
color='error'
|
||||||
isLoading={isLoading}
|
onClick={handleDelete}
|
||||||
>
|
isLoading={isLoading}
|
||||||
<Icon icon='mdi:trash' width={24} height={24} />
|
>
|
||||||
Hapus
|
<Icon icon='mdi:trash' width={24} height={24} />
|
||||||
</Button>
|
Hapus
|
||||||
|
</Button>
|
||||||
|
</RequirePermission>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
+25
-23
@@ -15,6 +15,9 @@ import { BaseSalesOrder } from '@/types/api/marketing/marketing';
|
|||||||
import Badge from '@/components/Badge';
|
import Badge from '@/components/Badge';
|
||||||
import { SalesProductToFieldValues } from '@/components/pages/marketing/form/MarketingForm';
|
import { SalesProductToFieldValues } from '@/components/pages/marketing/form/MarketingForm';
|
||||||
import * as Yup from 'yup';
|
import * as Yup from 'yup';
|
||||||
|
import { isResponseSuccess } from '@/lib/api-helper';
|
||||||
|
import AlertErrorList from '@/components/helper/form/FormErrors';
|
||||||
|
import { useFormikErrorList } from '@/services/hooks/useFormikErrorList';
|
||||||
|
|
||||||
const DeliveryOrderProductForm = ({
|
const DeliveryOrderProductForm = ({
|
||||||
formState,
|
formState,
|
||||||
@@ -39,6 +42,7 @@ const DeliveryOrderProductForm = ({
|
|||||||
null
|
null
|
||||||
);
|
);
|
||||||
const [currentInput, setCurrentInput] = useState<string>('');
|
const [currentInput, setCurrentInput] = useState<string>('');
|
||||||
|
|
||||||
const salesOrder = salesOrders.find(
|
const salesOrder = salesOrders.find(
|
||||||
(item) => item.id === initialValues?.marketing_product_id
|
(item) => item.id === initialValues?.marketing_product_id
|
||||||
);
|
);
|
||||||
@@ -163,37 +167,23 @@ const DeliveryOrderProductForm = ({
|
|||||||
}
|
}
|
||||||
}, [initialValues]);
|
}, [initialValues]);
|
||||||
|
|
||||||
|
// ===== Formik Error List =====
|
||||||
|
const { formErrorList, close, handleFormSubmit } = useFormikErrorList(formik);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<form
|
<form
|
||||||
className='size-full'
|
className='size-full'
|
||||||
onSubmit={(e) => {
|
onSubmit={handleFormSubmit}
|
||||||
e.preventDefault();
|
|
||||||
handleBlurField(currentInput);
|
|
||||||
formik.handleSubmit(e);
|
|
||||||
}}
|
|
||||||
onReset={handleResetForm}
|
onReset={handleResetForm}
|
||||||
>
|
>
|
||||||
{/* <small className='block text-blue-500'>
|
|
||||||
{JSON.stringify(exisitingValues)}
|
|
||||||
</small>
|
|
||||||
<small className='block text-emerald-500'>
|
|
||||||
{JSON.stringify(formik.values)}
|
|
||||||
</small> */}
|
|
||||||
{/* <small className='block text-red-500'>
|
|
||||||
{JSON.stringify(formik.errors)}
|
|
||||||
</small>
|
|
||||||
<div className='hidden'>
|
|
||||||
{JSON.stringify(formik.values.marketing_product)}
|
|
||||||
</div> */}
|
|
||||||
|
|
||||||
{formikErrorMessage && (
|
{formikErrorMessage && (
|
||||||
<div onClick={() => setFormErrorMessage('')} className='my-3 w-full'>
|
<div onClick={() => setFormErrorMessage('')} className='my-3 w-full'>
|
||||||
<Alert color='error'>{formikErrorMessage}</Alert>
|
<Alert color='error'>{formikErrorMessage}</Alert>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className='grid grid-cols-2 gap-4'>
|
<div className='grid sm:grid-cols-2 gap-4'>
|
||||||
<SelectInput
|
<SelectInput
|
||||||
options={options}
|
options={options}
|
||||||
label='Produk'
|
label='Produk'
|
||||||
@@ -221,7 +211,7 @@ const DeliveryOrderProductForm = ({
|
|||||||
...formik.values,
|
...formik.values,
|
||||||
marketing_product_id: undefined,
|
marketing_product_id: undefined,
|
||||||
marketing_product: null,
|
marketing_product: null,
|
||||||
qty: formik.values.qty || '',
|
qty: '',
|
||||||
unit_price: '',
|
unit_price: '',
|
||||||
total_price: '',
|
total_price: '',
|
||||||
avg_weight: '',
|
avg_weight: '',
|
||||||
@@ -235,7 +225,7 @@ const DeliveryOrderProductForm = ({
|
|||||||
...formik.values,
|
...formik.values,
|
||||||
marketing_product_id: selected.value as number,
|
marketing_product_id: selected.value as number,
|
||||||
marketing_product: SalesProductToFieldValues(so),
|
marketing_product: SalesProductToFieldValues(so),
|
||||||
qty: formik.values.qty || so.qty,
|
qty: so.qty,
|
||||||
unit_price: so.unit_price,
|
unit_price: so.unit_price,
|
||||||
total_price: so.total_price,
|
total_price: so.total_price,
|
||||||
avg_weight: so.avg_weight,
|
avg_weight: so.avg_weight,
|
||||||
@@ -311,8 +301,18 @@ const DeliveryOrderProductForm = ({
|
|||||||
isError={Boolean(formik.errors.qty)}
|
isError={Boolean(formik.errors.qty)}
|
||||||
errorMessage={formik.errors.qty}
|
errorMessage={formik.errors.qty}
|
||||||
placeholder='Masukan Kuantitas'
|
placeholder='Masukan Kuantitas'
|
||||||
|
bottomLabel={
|
||||||
|
formik.values.marketing_product_id
|
||||||
|
? 'Stok dijual: ' +
|
||||||
|
salesOrders?.find(
|
||||||
|
(item) => item.id === formik.values.marketing_product_id
|
||||||
|
)?.qty
|
||||||
|
: ''
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
|
<div className='divider my-6'></div>
|
||||||
|
<div className='grid sm:grid-cols-2 gap-4'>
|
||||||
<NumberInput
|
<NumberInput
|
||||||
required
|
required
|
||||||
label='Avg. Bobot (Kg)'
|
label='Avg. Bobot (Kg)'
|
||||||
@@ -374,6 +374,8 @@ const DeliveryOrderProductForm = ({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<AlertErrorList formErrorList={formErrorList} onClose={close} />
|
||||||
|
|
||||||
<div className='flex flex-row justify-end gap-3 mt-4'>
|
<div className='flex flex-row justify-end gap-3 mt-4'>
|
||||||
<Button type='reset' color='warning'>
|
<Button type='reset' color='warning'>
|
||||||
Reset
|
Reset
|
||||||
@@ -381,7 +383,7 @@ const DeliveryOrderProductForm = ({
|
|||||||
<Button
|
<Button
|
||||||
type='submit'
|
type='submit'
|
||||||
isLoading={formik.isSubmitting}
|
isLoading={formik.isSubmitting}
|
||||||
disabled={!formik.isValid || formik.isSubmitting}
|
disabled={formik.isSubmitting}
|
||||||
>
|
>
|
||||||
Submit
|
Submit
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user