mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
[FEAT/BE] Add field purchase response get all
This commit is contained in:
@@ -743,8 +743,6 @@ func (s *fifoService) releaseUsagePortion(
|
|||||||
if expectedWarehouseID == 0 || alloc.ProductWarehouseId == expectedWarehouseID {
|
if expectedWarehouseID == 0 || alloc.ProductWarehouseId == expectedWarehouseID {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fmt.Printf("WARN[FIFO] ALLOC WAREHOUSE MISMATCH usable_key=%s usable_id=%d alloc_id=%d expected_pw=%d actual_pw=%d\n",
|
|
||||||
usableKey.String(), usableID, alloc.Id, expectedWarehouseID, alloc.ProductWarehouseId)
|
|
||||||
if err := tx.Model(&entities.StockAllocation{}).
|
if err := tx.Model(&entities.StockAllocation{}).
|
||||||
Where("id = ?", alloc.Id).
|
Where("id = ?", alloc.Id).
|
||||||
Update("product_warehouse_id", expectedWarehouseID).Error; err != nil {
|
Update("product_warehouse_id", expectedWarehouseID).Error; err != nil {
|
||||||
@@ -848,6 +846,44 @@ func (s *fifoService) fetchPendingCandidates(ctx context.Context, tx *gorm.DB, p
|
|||||||
cfg.Columns.CreatedAt,
|
cfg.Columns.CreatedAt,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if cfg.Columns.CreatedAt == cfg.Columns.ID {
|
||||||
|
var rows []struct {
|
||||||
|
ID uint
|
||||||
|
Pending float64
|
||||||
|
CreatedAt int64
|
||||||
|
}
|
||||||
|
|
||||||
|
query := tx.Table(cfg.Table).
|
||||||
|
Select(selectStmt).
|
||||||
|
Where(fmt.Sprintf("%s = ?", cfg.Columns.ProductWarehouseID), productWarehouseID).
|
||||||
|
Where(fmt.Sprintf("%s > 0", cfg.Columns.PendingQuantity)).
|
||||||
|
Limit(s.pendingBatchPerUsable)
|
||||||
|
|
||||||
|
if cfg.Scope != nil {
|
||||||
|
query = cfg.Scope(query)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, order := range s.orderClauses(cfg.OrderBy) {
|
||||||
|
query = query.Order(order)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := query.Find(&rows).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, row := range rows {
|
||||||
|
if row.Pending <= 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
candidates = append(candidates, pendingCandidate{
|
||||||
|
UsableKey: key,
|
||||||
|
Config: cfg,
|
||||||
|
UsableID: row.ID,
|
||||||
|
Pending: row.Pending,
|
||||||
|
CreatedAt: time.Unix(0, row.CreatedAt),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
var rows []struct {
|
var rows []struct {
|
||||||
ID uint
|
ID uint
|
||||||
Pending float64
|
Pending float64
|
||||||
@@ -885,6 +921,7 @@ func (s *fifoService) fetchPendingCandidates(ctx context.Context, tx *gorm.DB, p
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if len(candidates) == 0 {
|
if len(candidates) == 0 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package dto
|
package dto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
||||||
@@ -27,6 +28,11 @@ type PurchaseListDTO struct {
|
|||||||
Supplier *supplierDTO.SupplierRelationDTO `json:"supplier"`
|
Supplier *supplierDTO.SupplierRelationDTO `json:"supplier"`
|
||||||
DueDate *time.Time `json:"due_date"`
|
DueDate *time.Time `json:"due_date"`
|
||||||
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
|
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
|
||||||
|
RequesterName string `json:"requester_name"`
|
||||||
|
PoExpedition []string `json:"po_expedition"`
|
||||||
|
Products []productDTO.ProductRelationDTO `json:"products"`
|
||||||
|
Location *locationDTO.LocationRelationDTO `json:"location"`
|
||||||
|
Area *areaDTO.AreaRelationDTO `json:"area"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
LatestApproval *approvalDTO.ApprovalRelationDTO `json:"latest_approval"`
|
LatestApproval *approvalDTO.ApprovalRelationDTO `json:"latest_approval"`
|
||||||
@@ -146,6 +152,10 @@ func ToPurchaseListDTO(p entity.Purchase) PurchaseListDTO {
|
|||||||
mapped := userDTO.ToUserRelationDTO(p.CreatedUser)
|
mapped := userDTO.ToUserRelationDTO(p.CreatedUser)
|
||||||
createdUser = &mapped
|
createdUser = &mapped
|
||||||
}
|
}
|
||||||
|
requesterName := ""
|
||||||
|
if createdUser != nil {
|
||||||
|
requesterName = createdUser.Name
|
||||||
|
}
|
||||||
|
|
||||||
var latestApproval *approvalDTO.ApprovalRelationDTO
|
var latestApproval *approvalDTO.ApprovalRelationDTO
|
||||||
if p.LatestApproval != nil && p.LatestApproval.Id != 0 {
|
if p.LatestApproval != nil && p.LatestApproval.Id != 0 {
|
||||||
@@ -153,11 +163,53 @@ func ToPurchaseListDTO(p entity.Purchase) PurchaseListDTO {
|
|||||||
latestApproval = &mapped
|
latestApproval = &mapped
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
poExpedition []string
|
||||||
|
location *locationDTO.LocationRelationDTO
|
||||||
|
area *areaDTO.AreaRelationDTO
|
||||||
|
)
|
||||||
|
productMap := make(map[uint]productDTO.ProductRelationDTO)
|
||||||
|
expeditionRefSet := make(map[string]struct{})
|
||||||
|
for i := range p.Items {
|
||||||
|
item := p.Items[i]
|
||||||
|
if item.Product != nil && item.Product.Id != 0 {
|
||||||
|
if _, exists := productMap[item.Product.Id]; !exists {
|
||||||
|
productMap[item.Product.Id] = productDTO.ToProductRelationDTO(*item.Product)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if item.ExpenseNonstock != nil && item.ExpenseNonstock.Expense != nil {
|
||||||
|
ref := strings.TrimSpace(item.ExpenseNonstock.Expense.ReferenceNumber)
|
||||||
|
if ref != "" {
|
||||||
|
if _, exists := expeditionRefSet[ref]; !exists {
|
||||||
|
expeditionRefSet[ref] = struct{}{}
|
||||||
|
poExpedition = append(poExpedition, ref)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if location == nil && item.Warehouse != nil && item.Warehouse.Location != nil && item.Warehouse.Location.Id != 0 {
|
||||||
|
loc := locationDTO.ToLocationRelationDTO(*item.Warehouse.Location)
|
||||||
|
location = &loc
|
||||||
|
}
|
||||||
|
if area == nil && item.Warehouse != nil && item.Warehouse.Area.Id != 0 {
|
||||||
|
ar := areaDTO.ToAreaRelationDTO(item.Warehouse.Area)
|
||||||
|
area = &ar
|
||||||
|
}
|
||||||
|
}
|
||||||
|
products := make([]productDTO.ProductRelationDTO, 0, len(productMap))
|
||||||
|
for _, prod := range productMap {
|
||||||
|
products = append(products, prod)
|
||||||
|
}
|
||||||
|
|
||||||
return PurchaseListDTO{
|
return PurchaseListDTO{
|
||||||
PurchaseRelationDTO: ToPurchaseRelationDTO(&p),
|
PurchaseRelationDTO: ToPurchaseRelationDTO(&p),
|
||||||
Supplier: supplier,
|
Supplier: supplier,
|
||||||
DueDate: p.DueDate,
|
DueDate: p.DueDate,
|
||||||
CreatedUser: createdUser,
|
CreatedUser: createdUser,
|
||||||
|
RequesterName: requesterName,
|
||||||
|
PoExpedition: poExpedition,
|
||||||
|
Products: products,
|
||||||
|
Location: location,
|
||||||
|
Area: area,
|
||||||
CreatedAt: p.CreatedAt,
|
CreatedAt: p.CreatedAt,
|
||||||
UpdatedAt: p.UpdatedAt,
|
UpdatedAt: p.UpdatedAt,
|
||||||
LatestApproval: latestApproval,
|
LatestApproval: latestApproval,
|
||||||
|
|||||||
Reference in New Issue
Block a user