Files
ezbookkeeping/pkg/validators/fiscal_year_start_date.go
T
Sebastian Reategui b94dc8eb83 Feature - Add support for a fiscal year period defined in user settings.
* Add "This fiscal year", "Last fiscal year" as date range options in Transaction Details to filter transactions to those periods
* Add fiscal year ranges to Statistics & Trend Analysis
* Add "fiscal year start date" to user profile settings, allowing the user to select any date of the calendar year as the start of the fiscal year
* Add "fiscal year format" to user profile settings, allowing the user to specify how financial year date labels should appear

Implementation notes:
* The default fiscal year start is January 1 and the default fiscal year display format is "FY 2025"
* Fiscal year start date (month number & day number) are stored together in db as a uint16, high byte & low byte respectively
* February 29 is disallowed as a fiscal year start date, since it is never used as a convention in any country
* Jest is added to the project as a dev dependency, for unit tests in frontend

Signed-off-by: Sebastian Reategui <seb.reategui@gmail.com>
2025-06-07 22:04:47 +08:00

27 lines
747 B
Go

package validators
import (
"github.com/gin-gonic/gin/binding"
"github.com/go-playground/validator/v10"
"github.com/mayswind/ezbookkeeping/pkg/core"
)
// ValidateFiscalYearStart validates if a fiscal year start date is valid
func ValidateFiscalYearStart(fl validator.FieldLevel) bool {
date, ok := fl.Field().Interface().(core.FiscalYearStart)
if !ok {
return false
}
// Use the core functionality to validate
_, _, err := date.GetMonthDay()
return err == nil
}
// RegisterFiscalYearStartValidator registers the fiscal year start date validator
func RegisterFiscalYearStartValidator() {
if v, ok := binding.Validator.Engine().(*validator.Validate); ok {
v.RegisterValidation("validFiscalYearStart", ValidateFiscalYearStart)
}
}