mirror of
https://github.com/serty2005/rmser.git
synced 2026-02-04 19:02:33 -06:00
Перевел на multi-tenant
Добавил поставщиков Накладные успешно создаются из фронта
This commit is contained in:
@@ -27,7 +27,7 @@ func (r *pgRepository) GetByID(id uuid.UUID) (*drafts.DraftInvoice, error) {
|
||||
return db.Order("draft_invoice_items.raw_name ASC")
|
||||
}).
|
||||
Preload("Items.Product").
|
||||
Preload("Items.Product.MainUnit"). // Нужно для отображения единиц
|
||||
Preload("Items.Product.MainUnit").
|
||||
Preload("Items.Container").
|
||||
Where("id = ?", id).
|
||||
First(&draft).Error
|
||||
@@ -39,7 +39,7 @@ func (r *pgRepository) GetByID(id uuid.UUID) (*drafts.DraftInvoice, error) {
|
||||
}
|
||||
|
||||
func (r *pgRepository) Update(draft *drafts.DraftInvoice) error {
|
||||
// Обновляем только основные поля шапки
|
||||
// Обновляем поля шапки + привязки к серверу
|
||||
return r.db.Model(draft).Updates(map[string]interface{}{
|
||||
"status": draft.Status,
|
||||
"document_number": draft.DocumentNumber,
|
||||
@@ -48,6 +48,7 @@ func (r *pgRepository) Update(draft *drafts.DraftInvoice) error {
|
||||
"store_id": draft.StoreID,
|
||||
"comment": draft.Comment,
|
||||
"rms_invoice_id": draft.RMSInvoiceID,
|
||||
"rms_server_id": draft.RMSServerID, // Вдруг поменялся, хотя не должен
|
||||
"updated_at": gorm.Expr("NOW()"),
|
||||
}).Error
|
||||
}
|
||||
@@ -60,34 +61,29 @@ func (r *pgRepository) CreateItems(items []drafts.DraftInvoiceItem) error {
|
||||
}
|
||||
|
||||
func (r *pgRepository) UpdateItem(itemID uuid.UUID, productID *uuid.UUID, containerID *uuid.UUID, qty, price decimal.Decimal) error {
|
||||
// Пересчитываем сумму
|
||||
sum := qty.Mul(price)
|
||||
|
||||
// Определяем статус IsMatched: если productID задан - значит сматчено
|
||||
isMatched := productID != nil
|
||||
|
||||
updates := map[string]interface{}{
|
||||
"product_id": productID,
|
||||
"container_id": containerID,
|
||||
"quantity": qty,
|
||||
"price": price,
|
||||
"sum": sum,
|
||||
"is_matched": isMatched,
|
||||
}
|
||||
|
||||
return r.db.Model(&drafts.DraftInvoiceItem{}).
|
||||
Where("id = ?", itemID).
|
||||
Updates(updates).Error
|
||||
Updates(map[string]interface{}{
|
||||
"product_id": productID,
|
||||
"container_id": containerID,
|
||||
"quantity": qty,
|
||||
"price": price,
|
||||
"sum": sum,
|
||||
"is_matched": isMatched,
|
||||
}).Error
|
||||
}
|
||||
|
||||
func (r *pgRepository) Delete(id uuid.UUID) error {
|
||||
return r.db.Delete(&drafts.DraftInvoice{}, id).Error
|
||||
}
|
||||
|
||||
func (r *pgRepository) GetActive() ([]drafts.DraftInvoice, error) {
|
||||
// GetActive фильтрует по UserID
|
||||
func (r *pgRepository) GetActive(userID uuid.UUID) ([]drafts.DraftInvoice, error) {
|
||||
var list []drafts.DraftInvoice
|
||||
|
||||
// Выбираем статусы, которые считаем "активными"
|
||||
activeStatuses := []string{
|
||||
drafts.StatusProcessing,
|
||||
drafts.StatusReadyToVerify,
|
||||
@@ -96,9 +92,9 @@ func (r *pgRepository) GetActive() ([]drafts.DraftInvoice, error) {
|
||||
}
|
||||
|
||||
err := r.db.
|
||||
Preload("Items"). // Нужны для подсчета суммы и количества
|
||||
Preload("Store"). // Нужно для названия склада
|
||||
Where("status IN ?", activeStatuses).
|
||||
Preload("Items").
|
||||
Preload("Store").
|
||||
Where("user_id = ? AND status IN ?", userID, activeStatuses). // <-- FILTER
|
||||
Order("created_at DESC").
|
||||
Find(&list).Error
|
||||
|
||||
|
||||
Reference in New Issue
Block a user