package drafts import ( "time" "rmser/internal/domain/catalog" "github.com/google/uuid" "github.com/shopspring/decimal" ) const ( StatusProcessing = "PROCESSING" StatusReadyToVerify = "READY_TO_VERIFY" StatusCompleted = "COMPLETED" StatusError = "ERROR" StatusCanceled = "CANCELED" StatusDeleted = "DELETED" ) type DraftInvoice struct { ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"` // Привязка к аккаунту и серверу UserID uuid.UUID `gorm:"type:uuid;not null;index" json:"user_id"` // Кто загрузил (автор) RMSServerID uuid.UUID `gorm:"type:uuid;not null;index" json:"rms_server_id"` // К какому серверу относится SenderPhotoURL string `gorm:"type:text" json:"photo_url"` Status string `gorm:"type:varchar(50);default:'PROCESSING'" json:"status"` DocumentNumber string `gorm:"type:varchar(100)" json:"document_number"` DateIncoming *time.Time `json:"date_incoming"` SupplierID *uuid.UUID `gorm:"type:uuid" json:"supplier_id"` StoreID *uuid.UUID `gorm:"type:uuid" json:"store_id"` Store *catalog.Store `gorm:"foreignKey:StoreID" json:"store,omitempty"` Comment string `gorm:"type:text" json:"comment"` RMSInvoiceID *uuid.UUID `gorm:"type:uuid" json:"rms_invoice_id"` Items []DraftInvoiceItem `gorm:"foreignKey:DraftID;constraint:OnDelete:CASCADE" json:"items"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } type DraftInvoiceItem struct { ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"` DraftID uuid.UUID `gorm:"type:uuid;not null;index" json:"draft_id"` RawName string `gorm:"type:varchar(255);not null" json:"raw_name"` RawAmount decimal.Decimal `gorm:"type:numeric(19,4)" json:"raw_amount"` RawPrice decimal.Decimal `gorm:"type:numeric(19,4)" json:"raw_price"` ProductID *uuid.UUID `gorm:"type:uuid;index" json:"product_id"` Product *catalog.Product `gorm:"foreignKey:ProductID" json:"product,omitempty"` ContainerID *uuid.UUID `gorm:"type:uuid;index" json:"container_id"` Container *catalog.ProductContainer `gorm:"foreignKey:ContainerID" json:"container,omitempty"` Quantity decimal.Decimal `gorm:"type:numeric(19,4);default:0" json:"quantity"` Price decimal.Decimal `gorm:"type:numeric(19,4);default:0" json:"price"` Sum decimal.Decimal `gorm:"type:numeric(19,4);default:0" json:"sum"` IsMatched bool `gorm:"default:false" json:"is_matched"` } type Repository interface { Create(draft *DraftInvoice) error GetByID(id uuid.UUID) (*DraftInvoice, error) Update(draft *DraftInvoice) error CreateItems(items []DraftInvoiceItem) error UpdateItem(itemID uuid.UUID, productID *uuid.UUID, containerID *uuid.UUID, qty, price decimal.Decimal) error CreateItem(item *DraftInvoiceItem) error DeleteItem(itemID uuid.UUID) error Delete(id uuid.UUID) error // GetActive возвращает активные черновики для СЕРВЕРА (а не юзера) GetActive(serverID uuid.UUID) ([]DraftInvoice, error) }