diff --git a/internal/modules/purchases/services/purchase.service.go b/internal/modules/purchases/services/purchase.service.go index 5703cb8e..728c0e2b 100644 --- a/internal/modules/purchases/services/purchase.service.go +++ b/internal/modules/purchases/services/purchase.service.go @@ -713,6 +713,12 @@ func (s *purchaseService) ApproveManagerPurchase(c *fiber.Ctx, id uint, req *val } now := time.Now().UTC() + poDateToSet := now + if req.PoDate != nil && strings.TrimSpace(*req.PoDate) != "" { + if parsed, parseErr := utils.ParseDateString(strings.TrimSpace(*req.PoDate)); parseErr == nil { + poDateToSet = parsed.UTC() + } + } hasExistingPO := purchase.PoNumber != nil && strings.TrimSpace(*purchase.PoNumber) != "" var generatedNumber string @@ -725,7 +731,7 @@ func (s *purchaseService) ApproveManagerPurchase(c *fiber.Ctx, id uint, req *val return err } updateData["po_number"] = code - updateData["po_date"] = now + updateData["po_date"] = poDateToSet generatedNumber = code } @@ -770,7 +776,7 @@ func (s *purchaseService) ApproveManagerPurchase(c *fiber.Ctx, id uint, req *val if generatedNumber != "" { purchase.PoNumber = &generatedNumber - purchase.PoDate = &now + purchase.PoDate = &poDateToSet } updated, err := s.PurchaseRepo.GetByID(c.Context(), purchase.Id, s.withRelations) diff --git a/internal/modules/purchases/validations/purchase.validation.go b/internal/modules/purchases/validations/purchase.validation.go index a16390ef..780b2911 100644 --- a/internal/modules/purchases/validations/purchase.validation.go +++ b/internal/modules/purchases/validations/purchase.validation.go @@ -35,6 +35,7 @@ type ApproveStaffPurchaseRequest struct { type ApproveManagerPurchaseRequest struct { Action string `json:"action" validate:"required,oneof=APPROVED REJECTED"` Notes *string `json:"notes,omitempty" validate:"omitempty,max=500"` + PoDate *string `json:"po_date,omitempty" validate:"omitempty,datetime=2006-01-02"` } type ReceivePurchaseItemRequest struct {