mirror of
https://github.com/serty2005/rmser.git
synced 2026-02-04 19:02:33 -06:00
добавил редактируемую сумму и пересчет треугольником
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"rmser/internal/domain/drafts"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/shopspring/decimal"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -56,7 +55,7 @@ func (r *pgRepository) Update(draft *drafts.DraftInvoice) error {
|
||||
return r.db.Model(draft).Updates(map[string]interface{}{
|
||||
"status": draft.Status,
|
||||
"document_number": draft.DocumentNumber,
|
||||
"incoming_document_number": draft.IncomingDocumentNumber, // Добавлено поле для входящего номера документа
|
||||
"incoming_document_number": draft.IncomingDocumentNumber,
|
||||
"date_incoming": draft.DateIncoming,
|
||||
"supplier_id": draft.SupplierID,
|
||||
"store_id": draft.StoreID,
|
||||
@@ -82,27 +81,27 @@ func (r *pgRepository) DeleteItem(itemID uuid.UUID) error {
|
||||
return r.db.Delete(&drafts.DraftInvoiceItem{}, itemID).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 != nil
|
||||
// GetItemByID - новый метод
|
||||
func (r *pgRepository) GetItemByID(itemID uuid.UUID) (*drafts.DraftInvoiceItem, error) {
|
||||
var item drafts.DraftInvoiceItem
|
||||
err := r.db.Where("id = ?", itemID).First(&item).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &item, nil
|
||||
}
|
||||
|
||||
// UpdateItem - обновленный метод, принимает map
|
||||
func (r *pgRepository) UpdateItem(itemID uuid.UUID, updates map[string]interface{}) error {
|
||||
return r.db.Model(&drafts.DraftInvoiceItem{}).
|
||||
Where("id = ?", itemID).
|
||||
Updates(map[string]interface{}{
|
||||
"product_id": productID,
|
||||
"container_id": containerID,
|
||||
"quantity": qty,
|
||||
"price": price,
|
||||
"sum": sum,
|
||||
"is_matched": isMatched,
|
||||
}).Error
|
||||
Updates(updates).Error
|
||||
}
|
||||
|
||||
func (r *pgRepository) Delete(id uuid.UUID) error {
|
||||
return r.db.Delete(&drafts.DraftInvoice{}, id).Error
|
||||
}
|
||||
|
||||
// GetActive возвращает черновики для конкретного СЕРВЕРА
|
||||
func (r *pgRepository) GetActive(serverID uuid.UUID) ([]drafts.DraftInvoice, error) {
|
||||
var list []drafts.DraftInvoice
|
||||
|
||||
@@ -116,14 +115,13 @@ func (r *pgRepository) GetActive(serverID uuid.UUID) ([]drafts.DraftInvoice, err
|
||||
err := r.db.
|
||||
Preload("Items").
|
||||
Preload("Store").
|
||||
Where("rms_server_id = ? AND status IN ?", serverID, activeStatuses). // Фильтр по серверу
|
||||
Where("rms_server_id = ? AND status IN ?", serverID, activeStatuses).
|
||||
Order("created_at DESC").
|
||||
Find(&list).Error
|
||||
|
||||
return list, err
|
||||
}
|
||||
|
||||
// GetRMSInvoiceIDToPhotoURLMap возвращает мапу rms_invoice_id -> sender_photo_url для сервера, где rms_invoice_id не NULL
|
||||
func (r *pgRepository) GetRMSInvoiceIDToPhotoURLMap(serverID uuid.UUID) (map[uuid.UUID]string, error) {
|
||||
var draftsList []drafts.DraftInvoice
|
||||
err := r.db.
|
||||
|
||||
Reference in New Issue
Block a user