FPSMS-frontend
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

85 lines
2.2 KiB

  1. import dayjs, { ConfigType } from "dayjs";
  2. import { Uom } from "../api/settings/uom";
  3. import { ListIterateeCustom, every, isArray, isNaN, isNull, isUndefined, take } from "lodash";
  4. export const manhourFormatter = new Intl.NumberFormat("en-HK", {
  5. minimumFractionDigits: 2,
  6. maximumFractionDigits: 2,
  7. });
  8. export const moneyFormatter = new Intl.NumberFormat("en-HK", {
  9. style: "currency",
  10. currency: "HKD",
  11. });
  12. export const decimalFormatter = new Intl.NumberFormat("en-HK", {
  13. minimumFractionDigits: 2,
  14. })
  15. export const integerFormatter = new Intl.NumberFormat("en-HK", {
  16. })
  17. export const INPUT_DATE_FORMAT = "YYYY-MM-DD";
  18. export const OUTPUT_DATE_FORMAT = "YYYY/MM/DD";
  19. export const OUTPUT_TIME_FORMAT = "HH:mm:ss";
  20. export const arrayToDayjs = (arr: ConfigType | (number | undefined)[]) => {
  21. const isValidNumber = (item: ListIterateeCustom<number | undefined, boolean>): boolean =>
  22. typeof item === "number" && !isNaN(item) && isFinite(item)
  23. let tempArr = arr;
  24. if (isArray(arr) && every(arr, isValidNumber) && arr.length >= 3) {
  25. // [year, month, day]
  26. tempArr = take(arr, 3)
  27. }
  28. return dayjs(tempArr as ConfigType)
  29. }
  30. export const arrayToDateString = (arr: ConfigType | (number | undefined)[]) => {
  31. return arrayToDayjs(arr).format(OUTPUT_DATE_FORMAT)
  32. }
  33. export const dateStringToDayjs = (date: string) => {
  34. // Format: YYYY/MM/DD
  35. return dayjs(date, OUTPUT_DATE_FORMAT)
  36. }
  37. export const dateTimeStringToDayjs = (dateTime: string) => {
  38. // Format: YYYY/MM/DD HH:mm:ss
  39. return dayjs(dateTime, `${OUTPUT_DATE_FORMAT} ${OUTPUT_TIME_FORMAT}`)
  40. }
  41. export const stockInLineStatusMap: { [status: string]: number } = {
  42. "draft": 0,
  43. "pending": 1,
  44. "qc": 2,
  45. "determine1": 3,
  46. "determine2": 4,
  47. "determine3": 5,
  48. "receiving": 6,
  49. "received": 7,
  50. "completed": 8,
  51. "rejected": 9,
  52. };
  53. export const pickOrderStatusMap: { [status: string]: number } = {
  54. "pending": 1,
  55. "consolidated": 2,
  56. "released": 3,
  57. "completed": 4,
  58. };
  59. export const calculateWeight = (qty: number, uom: Uom) => {
  60. return qty * (uom.unit2Qty || 1) * (uom.unit3Qty || 1) * (uom.unit4Qty || 1);
  61. }
  62. export const returnWeightUnit = (uom: Uom) => {
  63. return uom.unit4 || uom.unit3 || uom.unit2 || uom.unit1;
  64. }