0202-финиш перед десктопом

пересчет поправил
редактирование с перепроведением
галка автопроведения работает
рекомендации починил
This commit is contained in:
2026-02-02 13:53:38 +03:00
parent 10882f55c8
commit 88620f3fb6
37 changed files with 1905 additions and 11162 deletions

View File

@@ -8,6 +8,7 @@ import (
"github.com/shopspring/decimal"
"go.uber.org/zap"
"rmser/internal/domain/account"
"rmser/internal/domain/drafts"
invDomain "rmser/internal/domain/invoices"
"rmser/internal/domain/suppliers"
@@ -19,16 +20,18 @@ type Service struct {
repo invDomain.Repository
draftsRepo drafts.Repository
supplierRepo suppliers.Repository
accountRepo account.Repository
rmsFactory *rms.Factory
// Здесь можно добавить репозитории каталога и контрагентов для валидации,
// но для краткости пока опустим глубокую валидацию.
}
func NewService(repo invDomain.Repository, draftsRepo drafts.Repository, supplierRepo suppliers.Repository, rmsFactory *rms.Factory) *Service {
func NewService(repo invDomain.Repository, draftsRepo drafts.Repository, supplierRepo suppliers.Repository, accountRepo account.Repository, rmsFactory *rms.Factory) *Service {
return &Service{
repo: repo,
draftsRepo: draftsRepo,
supplierRepo: supplierRepo,
accountRepo: accountRepo,
rmsFactory: rmsFactory,
}
}
@@ -99,6 +102,13 @@ func (s *Service) SendInvoiceToRMS(req CreateRequestDTO, userID uuid.UUID) (stri
return docNum, nil
}
// InvoiceStatsDTO - DTO для статистики накладных
type InvoiceStatsDTO struct {
Total int64 `json:"total"`
LastMonth int64 `json:"last_month"`
Last24h int64 `json:"last_24h"`
}
// InvoiceDetailsDTO - DTO для ответа на запрос деталей накладной
type InvoiceDetailsDTO struct {
ID uuid.UUID `json:"id"`
@@ -145,7 +155,7 @@ func (s *Service) GetInvoice(id uuid.UUID) (*InvoiceDetailsDTO, error) {
Number: inv.DocumentNumber,
Date: inv.DateIncoming.Format("2006-01-02"),
Status: "COMPLETED", // Для синхронизированных накладных статус всегда COMPLETED
Items: make([]struct {
Items: make([]struct {
Name string `json:"name"`
Quantity float64 `json:"quantity"`
Price float64 `json:"price"`
@@ -166,3 +176,32 @@ func (s *Service) GetInvoice(id uuid.UUID) (*InvoiceDetailsDTO, error) {
return dto, nil
}
// GetStats возвращает статистику по накладным для пользователя
func (s *Service) GetStats(userID uuid.UUID) (*InvoiceStatsDTO, error) {
// Получаем активный сервер пользователя
server, err := s.accountRepo.GetActiveServer(userID)
if err != nil {
return nil, fmt.Errorf("ошибка получения активного сервера: %w", err)
}
if server == nil {
return &InvoiceStatsDTO{
Total: 0,
LastMonth: 0,
Last24h: 0,
}, nil
}
// Получаем статистику из репозитория
total, lastMonth, last24h, err := s.repo.GetStats(server.ID)
if err != nil {
return nil, fmt.Errorf("ошибка получения статистики: %w", err)
}
return &InvoiceStatsDTO{
Total: total,
LastMonth: lastMonth,
Last24h: last24h,
}, nil
}