mirror of
https://github.com/serty2005/rmser.git
synced 2026-02-04 19:02:33 -06:00
добавил редактируемую сумму и пересчет треугольником
This commit is contained in:
@@ -21,7 +21,6 @@ func NewDraftsHandler(service *drafts.Service) *DraftsHandler {
|
||||
return &DraftsHandler{service: service}
|
||||
}
|
||||
|
||||
// GetDraft
|
||||
func (h *DraftsHandler) GetDraft(c *gin.Context) {
|
||||
userID := c.MustGet("userID").(uuid.UUID)
|
||||
idStr := c.Param("id")
|
||||
@@ -39,7 +38,6 @@ func (h *DraftsHandler) GetDraft(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, draft)
|
||||
}
|
||||
|
||||
// GetDictionaries (бывший GetStores)
|
||||
func (h *DraftsHandler) GetDictionaries(c *gin.Context) {
|
||||
userID := c.MustGet("userID").(uuid.UUID)
|
||||
|
||||
@@ -52,12 +50,9 @@ func (h *DraftsHandler) GetDictionaries(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, data)
|
||||
}
|
||||
|
||||
// GetStores - устаревший метод для обратной совместимости
|
||||
// Возвращает массив складов
|
||||
func (h *DraftsHandler) GetStores(c *gin.Context) {
|
||||
userID := c.MustGet("userID").(uuid.UUID)
|
||||
|
||||
// Используем логику из GetDictionaries, но возвращаем только stores
|
||||
dict, err := h.service.GetDictionaries(userID)
|
||||
if err != nil {
|
||||
logger.Log.Error("GetStores error", zap.Error(err))
|
||||
@@ -65,19 +60,19 @@ func (h *DraftsHandler) GetStores(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// dict["stores"] уже содержит []catalog.Store
|
||||
c.JSON(http.StatusOK, dict["stores"])
|
||||
}
|
||||
|
||||
// UpdateItemDTO
|
||||
// UpdateItemDTO обновлен: float64 -> *float64, добавлен edited_field
|
||||
type UpdateItemDTO struct {
|
||||
ProductID *string `json:"product_id"`
|
||||
ContainerID *string `json:"container_id"`
|
||||
Quantity float64 `json:"quantity"`
|
||||
Price float64 `json:"price"`
|
||||
ProductID *string `json:"product_id"`
|
||||
ContainerID *string `json:"container_id"`
|
||||
Quantity *float64 `json:"quantity"`
|
||||
Price *float64 `json:"price"`
|
||||
Sum *float64 `json:"sum"`
|
||||
EditedField string `json:"edited_field"` // "quantity", "price", "sum"
|
||||
}
|
||||
|
||||
// AddDraftItem - POST /api/drafts/:id/items
|
||||
func (h *DraftsHandler) AddDraftItem(c *gin.Context) {
|
||||
draftID, err := uuid.Parse(c.Param("id"))
|
||||
if err != nil {
|
||||
@@ -95,7 +90,6 @@ func (h *DraftsHandler) AddDraftItem(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, item)
|
||||
}
|
||||
|
||||
// DeleteDraftItem - DELETE /api/drafts/:id/items/:itemId
|
||||
func (h *DraftsHandler) DeleteDraftItem(c *gin.Context) {
|
||||
draftID, err := uuid.Parse(c.Param("id"))
|
||||
if err != nil {
|
||||
@@ -122,8 +116,8 @@ func (h *DraftsHandler) DeleteDraftItem(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateItem обновлен
|
||||
func (h *DraftsHandler) UpdateItem(c *gin.Context) {
|
||||
// userID := c.MustGet("userID").(uuid.UUID) // Пока не используется в UpdateItem, но можно добавить проверку владельца
|
||||
draftID, _ := uuid.Parse(c.Param("id"))
|
||||
itemID, _ := uuid.Parse(c.Param("itemId"))
|
||||
|
||||
@@ -141,16 +135,44 @@ func (h *DraftsHandler) UpdateItem(c *gin.Context) {
|
||||
}
|
||||
|
||||
var cID *uuid.UUID
|
||||
if req.ContainerID != nil && *req.ContainerID != "" {
|
||||
if uid, err := uuid.Parse(*req.ContainerID); err == nil {
|
||||
if req.ContainerID != nil {
|
||||
if *req.ContainerID == "" {
|
||||
// Сброс фасовки
|
||||
empty := uuid.Nil
|
||||
cID = &empty
|
||||
} else if uid, err := uuid.Parse(*req.ContainerID); err == nil {
|
||||
cID = &uid
|
||||
}
|
||||
}
|
||||
|
||||
qty := decimal.NewFromFloat(req.Quantity)
|
||||
price := decimal.NewFromFloat(req.Price)
|
||||
qty := decimal.Zero
|
||||
if req.Quantity != nil {
|
||||
qty = decimal.NewFromFloat(*req.Quantity)
|
||||
}
|
||||
|
||||
if err := h.service.UpdateItem(draftID, itemID, pID, cID, qty, price); err != nil {
|
||||
price := decimal.Zero
|
||||
if req.Price != nil {
|
||||
price = decimal.NewFromFloat(*req.Price)
|
||||
}
|
||||
|
||||
sum := decimal.Zero
|
||||
if req.Sum != nil {
|
||||
sum = decimal.NewFromFloat(*req.Sum)
|
||||
}
|
||||
|
||||
// Дефолт, если фронт не прислал (для совместимости)
|
||||
editedField := req.EditedField
|
||||
if editedField == "" {
|
||||
if req.Sum != nil {
|
||||
editedField = "sum"
|
||||
} else if req.Price != nil {
|
||||
editedField = "price"
|
||||
} else {
|
||||
editedField = "quantity"
|
||||
}
|
||||
}
|
||||
|
||||
if err := h.service.UpdateItem(draftID, itemID, pID, cID, qty, price, sum, editedField); err != nil {
|
||||
logger.Log.Error("Failed to update item", zap.Error(err))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
@@ -245,28 +267,14 @@ func (h *DraftsHandler) AddContainer(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"status": "created", "container_id": newID.String()})
|
||||
}
|
||||
|
||||
type DraftListItemDTO struct {
|
||||
ID string `json:"id"`
|
||||
DocumentNumber string `json:"document_number"`
|
||||
DateIncoming string `json:"date_incoming"`
|
||||
Status string `json:"status"`
|
||||
ItemsCount int `json:"items_count"`
|
||||
TotalSum float64 `json:"total_sum"`
|
||||
StoreName string `json:"store_name"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
IsAppCreated bool `json:"is_app_created"`
|
||||
}
|
||||
|
||||
func (h *DraftsHandler) GetDrafts(c *gin.Context) {
|
||||
userID := c.MustGet("userID").(uuid.UUID)
|
||||
|
||||
// Читаем параметры периода из Query (default: 30 days)
|
||||
fromStr := c.DefaultQuery("from", time.Now().AddDate(0, 0, -30).Format("2006-01-02"))
|
||||
toStr := c.DefaultQuery("to", time.Now().Format("2006-01-02"))
|
||||
|
||||
from, _ := time.Parse("2006-01-02", fromStr)
|
||||
to, _ := time.Parse("2006-01-02", toStr)
|
||||
// Устанавливаем конец дня для 'to'
|
||||
to = to.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
|
||||
|
||||
list, err := h.service.GetUnifiedList(userID, from, to)
|
||||
@@ -279,7 +287,6 @@ func (h *DraftsHandler) GetDrafts(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *DraftsHandler) DeleteDraft(c *gin.Context) {
|
||||
// userID := c.MustGet("userID").(uuid.UUID) // Можно добавить проверку владельца
|
||||
idStr := c.Param("id")
|
||||
id, err := uuid.Parse(idStr)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user