helpers.js 839B

123456789101112131415161718192021222324252627282930313233343536373839
  1. export function ppn(price, percent) {
  2. return price + price * (percent / 100)
  3. }
  4. export function profit(price, percent) {
  5. return ppn(price, percent)
  6. }
  7. export function discount(price, percent) {
  8. return price - price * (percent / 100)
  9. }
  10. export const IDRCurrencyFormat = (number, decimal = false) => {
  11. if (number === null) {
  12. return
  13. }
  14. if (decimal) {
  15. return 'Rp' + number.toLocaleString('id') + ',00'
  16. } else {
  17. return 'Rp' + number.toLocaleString('id')
  18. }
  19. }
  20. export function removeParams(...params) {
  21. const urlParams = new URLSearchParams(location.search)
  22. params.forEach((value) => urlParams.delete(value))
  23. history.replaceState({}, '', `${location.pathname}?${urlParams}`)
  24. }
  25. export class FormValidationError extends Error {
  26. constructor(message, errors) {
  27. super(message)
  28. this.errors = errors
  29. }
  30. }