mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
feat[BE]: integrate kandang repository into expense bridge for enhanced expense management
This commit is contained in:
@@ -17,6 +17,7 @@ import (
|
||||
expenseDto "gitlab.com/mbugroup/lti-api.git/internal/modules/expenses/dto"
|
||||
expenseSvc "gitlab.com/mbugroup/lti-api.git/internal/modules/expenses/services"
|
||||
expenseValidation "gitlab.com/mbugroup/lti-api.git/internal/modules/expenses/validations"
|
||||
kandangRepo "gitlab.com/mbugroup/lti-api.git/internal/modules/master/kandangs/repositories"
|
||||
projectFlockKandangRepo "gitlab.com/mbugroup/lti-api.git/internal/modules/production/project_flocks/repositories"
|
||||
rPurchase "gitlab.com/mbugroup/lti-api.git/internal/modules/purchases/repositories"
|
||||
"gitlab.com/mbugroup/lti-api.git/internal/utils"
|
||||
@@ -53,6 +54,7 @@ type expenseBridge struct {
|
||||
db *gorm.DB
|
||||
purchaseRepo rPurchase.PurchaseRepository
|
||||
projectFlockKandangRepo projectFlockKandangRepo.ProjectFlockKandangRepository
|
||||
kandangRepo kandangRepo.KandangRepository
|
||||
expenseSvc expenseSvc.ExpenseService
|
||||
}
|
||||
|
||||
@@ -60,12 +62,14 @@ func NewExpenseBridge(
|
||||
db *gorm.DB,
|
||||
purchaseRepo rPurchase.PurchaseRepository,
|
||||
projectFlockKandangRepo projectFlockKandangRepo.ProjectFlockKandangRepository,
|
||||
kandangRepo kandangRepo.KandangRepository,
|
||||
expenseSvc expenseSvc.ExpenseService,
|
||||
) PurchaseExpenseBridge {
|
||||
return &expenseBridge{
|
||||
db: db,
|
||||
purchaseRepo: purchaseRepo,
|
||||
projectFlockKandangRepo: projectFlockKandangRepo,
|
||||
kandangRepo: kandangRepo,
|
||||
expenseSvc: expenseSvc,
|
||||
}
|
||||
}
|
||||
@@ -550,6 +554,16 @@ func (b *expenseBridge) createExpenseViaService(
|
||||
return nil, fiber.NewError(fiber.StatusBadRequest, "Warehouse not connect to kandangs")
|
||||
}
|
||||
|
||||
kandang, err := b.kandangRepo.GetByID(ctx, *kandangID, func(db *gorm.DB) *gorm.DB {
|
||||
return db.Select("id, location_id")
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fiber.NewError(fiber.StatusNotFound, fmt.Sprintf("Kandang not found: %d", *kandangID))
|
||||
}
|
||||
if kandang == nil {
|
||||
return nil, fiber.NewError(fiber.StatusNotFound, fmt.Sprintf("Kandang not found: %d", *kandangID))
|
||||
}
|
||||
|
||||
costItems := make([]expenseValidation.CostItem, 0, len(items))
|
||||
for _, gi := range items {
|
||||
note := fmt.Sprintf("purchase_item:%d", gi.payload.PurchaseItemID)
|
||||
@@ -570,6 +584,7 @@ func (b *expenseBridge) createExpenseViaService(
|
||||
TransactionDate: utils.FormatDate(expenseDate),
|
||||
Category: "BOP",
|
||||
SupplierID: uint64(supplierID),
|
||||
LocationID: uint64(kandang.LocationId),
|
||||
ExpenseNonstocks: []expenseValidation.ExpenseNonstock{{
|
||||
KandangID: func() *uint64 { id := uint64(*kandangID); return &id }(),
|
||||
CostItems: costItems,
|
||||
|
||||
Reference in New Issue
Block a user