mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-23 23:05:44 +00:00
Merge branch 'feat/BE/Sprint-7' of https://gitlab.com/mbugroup/lti-api into dev/teguh
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"gitlab.com/mbugroup/lti-api.git/internal/modules/repports/dto"
|
||||
repportRepo "gitlab.com/mbugroup/lti-api.git/internal/modules/repports/repositories"
|
||||
validation "gitlab.com/mbugroup/lti-api.git/internal/modules/repports/validations"
|
||||
"gitlab.com/mbugroup/lti-api.git/internal/utils"
|
||||
|
||||
@@ -15,6 +16,8 @@ import (
|
||||
recordingRepo "gitlab.com/mbugroup/lti-api.git/internal/modules/production/recordings/repositories"
|
||||
purchaseRepo "gitlab.com/mbugroup/lti-api.git/internal/modules/purchases/repositories"
|
||||
|
||||
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/sirupsen/logrus"
|
||||
@@ -24,6 +27,7 @@ import (
|
||||
type RepportService interface {
|
||||
GetExpense(ctx *fiber.Ctx, params *validation.ExpenseQuery) ([]dto.RepportExpenseListDTO, int64, error)
|
||||
GetMarketing(ctx *fiber.Ctx, params *validation.MarketingQuery) ([]dto.RepportMarketingItemDTO, int64, error)
|
||||
GetPurchaseSupplier(ctx *fiber.Ctx, params *validation.PurchaseSupplierQuery) ([]dto.PurchaseSupplierDTO, int64, error)
|
||||
}
|
||||
|
||||
type repportService struct {
|
||||
@@ -35,9 +39,19 @@ type repportService struct {
|
||||
ChickinRepo chickinRepo.ProjectChickinRepository
|
||||
RecordingRepo recordingRepo.RecordingRepository
|
||||
ApprovalSvc approvalService.ApprovalService
|
||||
PurchaseSupplierRepo repportRepo.PurchaseSupplierRepository
|
||||
}
|
||||
|
||||
func NewRepportService(validate *validator.Validate, expenseRealizationRepo expenseRepo.ExpenseRealizationRepository, marketingDeliveryRepo marketingRepo.MarketingDeliveryProductRepository, purchaseRepo purchaseRepo.PurchaseRepository, chickinRepo chickinRepo.ProjectChickinRepository, recordingRepo recordingRepo.RecordingRepository, approvalSvc approvalService.ApprovalService) RepportService {
|
||||
func NewRepportService(
|
||||
validate *validator.Validate,
|
||||
expenseRealizationRepo expenseRepo.ExpenseRealizationRepository,
|
||||
marketingDeliveryRepo marketingRepo.MarketingDeliveryProductRepository,
|
||||
purchaseRepo purchaseRepo.PurchaseRepository,
|
||||
chickinRepo chickinRepo.ProjectChickinRepository,
|
||||
recordingRepo recordingRepo.RecordingRepository,
|
||||
approvalSvc approvalService.ApprovalService,
|
||||
purchaseSupplierRepo repportRepo.PurchaseSupplierRepository,
|
||||
) RepportService {
|
||||
return &repportService{
|
||||
Log: utils.Log,
|
||||
Validate: validate,
|
||||
@@ -47,6 +61,7 @@ func NewRepportService(validate *validator.Validate, expenseRealizationRepo expe
|
||||
ChickinRepo: chickinRepo,
|
||||
RecordingRepo: recordingRepo,
|
||||
ApprovalSvc: approvalSvc,
|
||||
PurchaseSupplierRepo: purchaseSupplierRepo,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,3 +210,58 @@ func (s *repportService) getTotalProjectCost(ctx context.Context, projectFlockID
|
||||
|
||||
return cost
|
||||
}
|
||||
|
||||
func (s *repportService) GetPurchaseSupplier(c *fiber.Ctx, params *validation.PurchaseSupplierQuery) ([]dto.PurchaseSupplierDTO, int64, error) {
|
||||
if err := s.Validate.Struct(params); err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
offset := (params.Page - 1) * params.Limit
|
||||
if offset < 0 {
|
||||
offset = 0
|
||||
}
|
||||
|
||||
suppliers, totalSuppliers, err := s.PurchaseSupplierRepo.GetSuppliersWithPurchases(c.Context(), offset, params.Limit, params)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
if totalSuppliers == 0 || len(suppliers) == 0 {
|
||||
return []dto.PurchaseSupplierDTO{}, totalSuppliers, nil
|
||||
}
|
||||
|
||||
supplierMap := make(map[uint]entity.Supplier, len(suppliers))
|
||||
supplierIDs := make([]uint, 0, len(suppliers))
|
||||
for _, supplier := range suppliers {
|
||||
supplierMap[supplier.Id] = supplier
|
||||
supplierIDs = append(supplierIDs, supplier.Id)
|
||||
}
|
||||
|
||||
items, err := s.PurchaseSupplierRepo.GetItemsBySuppliers(c.Context(), supplierIDs, params)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
itemsBySupplier := make(map[uint][]entity.PurchaseItem)
|
||||
for _, item := range items {
|
||||
if item.Purchase == nil {
|
||||
continue
|
||||
}
|
||||
supplierID := item.Purchase.SupplierId
|
||||
itemsBySupplier[supplierID] = append(itemsBySupplier[supplierID], item)
|
||||
}
|
||||
|
||||
result := make([]dto.PurchaseSupplierDTO, 0, len(supplierIDs))
|
||||
for _, supplierID := range supplierIDs {
|
||||
supplier, exists := supplierMap[supplierID]
|
||||
if !exists {
|
||||
continue
|
||||
}
|
||||
|
||||
supplierItems := itemsBySupplier[supplierID]
|
||||
dtoItem := dto.ToPurchaseSupplierDTO(supplier, supplierItems)
|
||||
result = append(result, dtoItem)
|
||||
}
|
||||
|
||||
return result, totalSuppliers, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user