mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
[FIX/BE-US] fix closing count sapronak,expense notes purchase
This commit is contained in:
@@ -45,10 +45,7 @@ type groupedItem struct {
|
||||
projectFK *uint
|
||||
kandangID *uint
|
||||
totalPrice float64
|
||||
}
|
||||
|
||||
func groupingKey(supplierID uint, date time.Time, warehouseID uint) string {
|
||||
return fmt.Sprintf("%d:%s:%d", supplierID, utils.FormatDate(date), warehouseID)
|
||||
poNumber string
|
||||
}
|
||||
|
||||
type expenseBridge struct {
|
||||
@@ -222,6 +219,7 @@ func (b *expenseBridge) OnItemsReceived(c *fiber.Ctx, purchaseID uint, updates [
|
||||
purchase, err := b.purchaseRepo.GetByID(ctx, purchaseID, func(db *gorm.DB) *gorm.DB {
|
||||
return db.
|
||||
Preload("Items").
|
||||
Preload("Items.Product").
|
||||
Preload("Items.Warehouse").
|
||||
Preload("Items.Warehouse.Kandang")
|
||||
})
|
||||
@@ -309,7 +307,7 @@ func (b *expenseBridge) OnItemsReceived(c *fiber.Ctx, purchaseID uint, updates [
|
||||
|
||||
// If supplier/date unchanged, update nonstock in place.
|
||||
if oldSupplier == supplierID && oldDate.Equal(newDate) {
|
||||
note := fmt.Sprintf("purchase_item:%d", payload.PurchaseItemID)
|
||||
note := purchaseItemDisplayNote(item, payload.PurchaseItemID, purchasePoNumber(purchase))
|
||||
if err := b.db.WithContext(ctx).
|
||||
Model(&entity.ExpenseNonstock{}).
|
||||
Where("id = ?", link.ExpenseNonstockID).
|
||||
@@ -340,7 +338,7 @@ func (b *expenseBridge) OnItemsReceived(c *fiber.Ctx, purchaseID uint, updates [
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
note := fmt.Sprintf("purchase_item:%d", payload.PurchaseItemID)
|
||||
note := purchaseItemDisplayNote(item, payload.PurchaseItemID, purchasePoNumber(purchase))
|
||||
if err := b.db.WithContext(ctx).
|
||||
Model(&entity.Expense{}).
|
||||
Where("id = ?", link.ExpenseID).
|
||||
@@ -392,6 +390,7 @@ func (b *expenseBridge) OnItemsReceived(c *fiber.Ctx, purchaseID uint, updates [
|
||||
projectFK: projectFK,
|
||||
kandangID: kandangID,
|
||||
totalPrice: totalPrice,
|
||||
poNumber: purchasePoNumber(purchase),
|
||||
}
|
||||
|
||||
newNonstockID, err := b.findExpeditionNonstockID(ctx, supplierID)
|
||||
@@ -410,7 +409,7 @@ func (b *expenseBridge) OnItemsReceived(c *fiber.Ctx, purchaseID uint, updates [
|
||||
createdNonstockID = noteMap[payload.PurchaseItemID]
|
||||
}
|
||||
|
||||
note := fmt.Sprintf("purchase_item:%d", payload.PurchaseItemID)
|
||||
note := purchaseItemDisplayNote(item, payload.PurchaseItemID, purchasePoNumber(purchase))
|
||||
updateBody := map[string]interface{}{
|
||||
"expense_id": expenseDetail.Id,
|
||||
"qty": payload.ReceivedQty,
|
||||
@@ -483,6 +482,7 @@ func (b *expenseBridge) OnItemsReceived(c *fiber.Ctx, purchaseID uint, updates [
|
||||
projectFK: projectFK,
|
||||
kandangID: kandangID,
|
||||
totalPrice: totalPrice,
|
||||
poNumber: purchasePoNumber(purchase),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -679,6 +679,14 @@ func (b *expenseBridge) linkExpenseNonstocksToItems(ctx context.Context, detail
|
||||
Update("expense_nonstock_id", expenseNonstockID).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
note := purchaseItemDisplayNote(gi.item, gi.payload.PurchaseItemID, gi.poNumber)
|
||||
if err := b.db.WithContext(ctx).
|
||||
Model(&entity.ExpenseNonstock{}).
|
||||
Where("id = ?", expenseNonstockID).
|
||||
Update("notes", note).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -709,3 +717,22 @@ func mapExpenseNotes(detail *expenseDto.ExpenseDetailDTO) map[uint]uint64 {
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func purchaseItemDisplayNote(item *entity.PurchaseItem, itemID uint, poNumber string) string {
|
||||
poLabel := "PO"
|
||||
if strings.TrimSpace(poNumber) != "" {
|
||||
poLabel = strings.TrimSpace(poNumber)
|
||||
}
|
||||
productName := fmt.Sprintf("Item %d", itemID)
|
||||
if item != nil && item.Product != nil && strings.TrimSpace(item.Product.Name) != "" {
|
||||
productName = item.Product.Name
|
||||
}
|
||||
return fmt.Sprintf("%s (%s)", poLabel, productName)
|
||||
}
|
||||
|
||||
func purchasePoNumber(purchase *entity.Purchase) string {
|
||||
if purchase == nil || purchase.PoNumber == nil {
|
||||
return ""
|
||||
}
|
||||
return *purchase.PoNumber
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user