12 Сделать добавление транзакций на фронте, добавить уже сгенерированые экраны в проект

This commit is contained in:
2026-05-30 10:30:26 +03:00
parent debb8e5974
commit 97d923142e
25 changed files with 2178 additions and 144 deletions
+3 -3
View File
@@ -13,9 +13,9 @@ var knownDateFormats = []string{
"02.01.06", // 21.01.2026
"02-01-2006", // 21-01-2026
"02/01/2006", // 21/01/2026
//"2006/01/02", // 2026/01/21
//"2006-01-02", // 2026-01-21
//"2006.01.02", // 2026.01.21
"2006/01/02", // 2026/01/21
"2006-01-02", // 2026-01-21
"2006.01.02", // 2026.01.21
}
func NormalizeDateToISO(input string) (string, error) {
+21 -6
View File
@@ -1,6 +1,10 @@
package utils
import "regexp"
import (
"regexp"
"strings"
"time"
)
type ReceiptMeta struct {
Date string
@@ -10,17 +14,16 @@ type ReceiptMeta struct {
func ExtractReceiptMeta(text string) ReceiptMeta {
result := ReceiptMeta{}
// --- ДАТА ---
datePatterns := []string{
`(\d{2}[./-]\d{2}[./-]\d{4})`, // 25.01.2026
`(\d{2}[./-]\d{2}[./-]\d{2})`, // 25.01.26
`(\d{4}[./-]\d{2}[./-]\d{2})`, // 2026-01-25
`\b\d{2}[./:-]\d{2}[./:-]\d{4}\b`, // 25.01.2026, 25:01.2026
`\b\d{4}[./:-]\d{2}[./:-]\d{2}\b`, // 2026-01-25
`\b\d{2}[./-]\d{2}[./-]\d{2}\b`, // 25.01.26
}
for _, pattern := range datePatterns {
re := regexp.MustCompile(pattern)
if match := re.FindString(text); match != "" {
result.Date = match
result.Date = normalizeOCRDate(match)
break
}
}
@@ -31,3 +34,15 @@ func ExtractReceiptMeta(text string) ReceiptMeta {
return result
}
func normalizeOCRDate(value string) string {
sanitized := strings.NewReplacer(":", ".", "/", ".", "-", ".").Replace(strings.TrimSpace(value))
for _, layout := range knownDateFormats {
if t, err := time.Parse(layout, sanitized); err == nil {
return t.Format("02.01.2006")
}
}
return strings.TrimSpace(value)
}