mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-16 07:58:38 +00:00
* feat: new banking module (#54720)
* feat: initial SPA setup for banking
* wip: bring over new banking module
* feat: added Espresso design tokens
* feat: button styles
* fix: add all ink colors
* wip: espresso design system changes
* feat: button and badge espresso components
* fix: button styling for reconcile
* feat: Espresso progress bar
* feat: Espresso toggle switch
* feat: Espresso tabs design
* fix: vertical tab support
* fix: button sizing across modals
* feat: Espresso style table layout
* feat: Espresso tooltip
* feat: Espresso elevations and checkbox
* feat: Dialog with Espresso styles
* feat: Espresso textarea
* fix: input styles
* fix: colors on bank picker
* fix: breadcrumb styling
* fix: bank picker styling
* feat: create doctypes and fields for bank reconciliation
* feat: APIs for banking
* fix: use date format parser
* fix: font styling to match Espresso
* wip: settings modal
* feat: settings dialog component
* fix: icons and invalid requests
* feat: preferences tab
* fix: adjust icon stroke width to 1.5
* feat: rule configuration in settings
* fix: remove sheet component
* feat: alert and error banner component
* feat: dropdown in Espresso
* feat: popover and select in Espresso
* fix: cleanup more styles
* fix: match size of link fields
* feat: command styling
* fix: remove unused style tokens
* fix: styles for global date picker dropdown
* fix: styles for match and reconcile
* feat: table Espresso component
* feat: remove all other design tokens
* fix: remove unused tokens
* fix: form elements
* fix: remove unused styles and fix filters in bank transaction list
* feat: fetch bank rec doctypes for filtering
* fix: record payment modal
* feat: support for dark mode switching
* fix: move bank logos to public folder
* feat: add support for RTL
* feat: support for RTL
* chore: send layout direction in dev boot
* fix: make checkbox work in RTL
* feat: dark mode support
* fix: dark mode style
* feat: bank logos in dark mode
* feat: dark mode bank logos
* chore: use dark mode bank logos everywhere
* chore: move rule evaluation to controller
* chore: add tests for bank transaction rules
* fix: move deps to fix actions errors
* fix: move tw-animate-css to deps
* fix: remove shadcn
* fix: do not open modal if no transactions selected
* fix: add translation strings
* feat: add banner on existing bank reconciliation tool
* feat: bank statement import
* fix: translations and layout directions
* fix: validation for transaction matching rule
* fix: styles
* fix: show conflicting transactions in alert
* fix: show help text for new banking module forms
* feat: show total debits and credits
* fix: dark mode colors in automatic config
* feat: add keyboard shortcuts help
* feat: added keyboard shortcut for settings
* fix: decrease size of progress bar
* chore: bump packages
* feat: add tests for statement import
* fix: settings dialog
* fix: show banner on small screens
* fix: show banner when no bank account set
(cherry picked from commit 6de5367f12)
# Conflicts:
# erpnext/accounts/doctype/bank_reconciliation_tool/bank_reconciliation_tool.py
* chore: resolve conflicts
* fix: add type hints to whitelisted methods
---------
Co-authored-by: Nikhil Kothari <nik.kothari22@live.com>
184 lines
5.4 KiB
TypeScript
184 lines
5.4 KiB
TypeScript
import dayjs from 'dayjs';
|
|
import utc from 'dayjs/plugin/utc';
|
|
import timezone from 'dayjs/plugin/timezone';
|
|
import advancedFormat from 'dayjs/plugin/advancedFormat';
|
|
import relativeTime from 'dayjs/plugin/relativeTime';
|
|
import quarterOfYear from 'dayjs/plugin/quarterOfYear'
|
|
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
import _ from '@/lib/translate';
|
|
|
|
dayjs.extend(utc);
|
|
dayjs.extend(timezone);
|
|
dayjs.extend(advancedFormat);
|
|
dayjs.extend(relativeTime);
|
|
dayjs.extend(quarterOfYear);
|
|
dayjs.extend(customParseFormat);
|
|
|
|
const FRAPPE_DATE_FORMAT = "YYYY-MM-DD"
|
|
|
|
export const getUserDateFormat = () => {
|
|
|
|
return window?.frappe?.boot?.user?.defaults?.date_format.toUpperCase() || window?.frappe.boot.sysdefaults.date_format.toUpperCase()
|
|
|
|
}
|
|
// const FRAPPE_DATETIME_FORMAT = "YYYY-MM-DD HH:mm:ss"
|
|
|
|
export type TimePeriod = 'This Week' | 'This Month' | 'This Quarter' | 'This Year' | 'Last Week' | 'Last Month' | 'Last Quarter' | 'Last Year' | 'Date Range'
|
|
|
|
export const AVAILABLE_TIME_PERIODS: TimePeriod[] = [
|
|
'This Month',
|
|
'This Week',
|
|
'This Quarter',
|
|
'This Year',
|
|
'Last Week',
|
|
'Last Month',
|
|
'Last Quarter',
|
|
'Last Year',
|
|
];
|
|
|
|
/**
|
|
* Get the start and end dates for a given time period
|
|
* @param timePeriod - The time period to get the dates for
|
|
* @param format - The date format to use (defaults to FRAPPE_DATE_FORMAT)
|
|
* @param baseDate - Optional base date to use for calculations (defaults to current date)
|
|
* @returns The start and end dates in specified format, or empty strings if invalid
|
|
*/
|
|
export const getDatesForTimePeriod = (
|
|
timePeriod: TimePeriod,
|
|
format: string = FRAPPE_DATE_FORMAT,
|
|
baseDate?: string
|
|
) => {
|
|
|
|
const daysJSObject = baseDate ? dayjs(baseDate) : dayjs()
|
|
|
|
// Based on the time period, get the start and end dates
|
|
|
|
if (timePeriod === 'This Week') {
|
|
return {
|
|
fromDate: daysJSObject.startOf('week').format(format),
|
|
toDate: daysJSObject.endOf('week').format(format),
|
|
format: "Do MMM 'YY",
|
|
translatedLabel: _('This Week')
|
|
}
|
|
}
|
|
|
|
if (timePeriod === 'This Month' || timePeriod === 'Date Range') {
|
|
return {
|
|
fromDate: daysJSObject.startOf('month').format(format),
|
|
toDate: daysJSObject.endOf('month').format(format),
|
|
format: "Do MMM 'YY",
|
|
translatedLabel: _('This Month')
|
|
}
|
|
}
|
|
|
|
if (timePeriod === 'This Quarter') {
|
|
return {
|
|
fromDate: daysJSObject.startOf('quarter').format(format),
|
|
toDate: daysJSObject.endOf('quarter').format(format),
|
|
format: 'MMM YYYY',
|
|
translatedLabel: _('This Quarter')
|
|
}
|
|
}
|
|
|
|
if (timePeriod === 'This Year') {
|
|
return {
|
|
fromDate: daysJSObject.startOf('year').format(format),
|
|
toDate: daysJSObject.endOf('year').format(format),
|
|
format: 'MMM YYYY',
|
|
translatedLabel: _('This Year')
|
|
}
|
|
}
|
|
|
|
if (timePeriod === 'Last Week') {
|
|
const lastWeek = daysJSObject.subtract(1, 'week')
|
|
return {
|
|
fromDate: lastWeek.startOf('week').format(format),
|
|
toDate: lastWeek.endOf('week').format(format),
|
|
format: "Do MMM 'YY",
|
|
translatedLabel: _('Last Week')
|
|
}
|
|
}
|
|
|
|
if (timePeriod === 'Last Month') {
|
|
const lastMonth = daysJSObject.subtract(1, 'month')
|
|
return {
|
|
fromDate: lastMonth.startOf('month').format(format),
|
|
toDate: lastMonth.endOf('month').format(format),
|
|
format: "Do MMM 'YY",
|
|
translatedLabel: _('Last Month')
|
|
}
|
|
}
|
|
|
|
if (timePeriod === 'Last Quarter') {
|
|
const lastQuarter = daysJSObject.subtract(1, 'quarter')
|
|
return {
|
|
fromDate: lastQuarter.startOf('quarter').format(format),
|
|
toDate: lastQuarter.endOf('quarter').format(format),
|
|
format: 'MMM YYYY',
|
|
translatedLabel: _('Last Quarter')
|
|
}
|
|
}
|
|
|
|
if (timePeriod === 'Last Year') {
|
|
const lastYear = daysJSObject.subtract(1, 'year')
|
|
return {
|
|
fromDate: lastYear.startOf('year').format(format),
|
|
toDate: lastYear.endOf('year').format(format),
|
|
format: 'MMM YYYY',
|
|
translatedLabel: _('Last Year')
|
|
}
|
|
}
|
|
|
|
return {
|
|
fromDate: '',
|
|
toDate: '',
|
|
format: 'Do MMM YY',
|
|
translatedLabel: _('Date Range')
|
|
}
|
|
}
|
|
|
|
const toUserTimezone = (timestamp: string) => {
|
|
|
|
const systemTimezone = window.frappe?.boot?.time_zone?.system
|
|
const userTimezone = window.frappe?.boot?.time_zone?.user
|
|
|
|
if (systemTimezone && userTimezone) {
|
|
return dayjs.tz(timestamp, systemTimezone).clone().tz(userTimezone)
|
|
} else {
|
|
return dayjs(timestamp)
|
|
}
|
|
|
|
}
|
|
|
|
export const getTimeago = (date?: string) => {
|
|
if (date) {
|
|
const userDate = toUserTimezone(date)
|
|
return userDate.fromNow()
|
|
}
|
|
return ''
|
|
}
|
|
|
|
export const formatDate = (date?: string | Date, format?: string) => {
|
|
|
|
if (!format) {
|
|
format = getUserDateFormat()
|
|
}
|
|
|
|
if (date) {
|
|
return dayjs(date).format(format)
|
|
}
|
|
return ''
|
|
}
|
|
|
|
/**
|
|
* Utility function to convert a date string to a Date object
|
|
* @param date
|
|
* @returns
|
|
*/
|
|
export const toDate = (date: string, format: string = "YYYY-MM-DD") => {
|
|
return dayjs(date, format).toDate()
|
|
}
|
|
|
|
export const today = () => {
|
|
return dayjs().format(FRAPPE_DATE_FORMAT)
|
|
} |