mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-24 07:15:43 +00:00
feat[BE-127]: create available qty API and inisiate sales order and delivery order
This commit is contained in:
+49
-14
@@ -1,6 +1,7 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
|
||||
@@ -24,16 +25,8 @@ func NewTransferLayingController(transferLayingService service.TransferLayingSer
|
||||
|
||||
func (u *TransferLayingController) GetAll(c *fiber.Ctx) error {
|
||||
query := &validation.Query{
|
||||
Page: c.QueryInt("page", 1),
|
||||
Limit: c.QueryInt("limit", 10),
|
||||
SourceProjectFlockId: uint(c.QueryInt("source_project_flock_id", 0)),
|
||||
TargetProjectFlockId: uint(c.QueryInt("target_project_flock_id", 0)),
|
||||
TransferDateFrom: c.Query("transfer_date_from", ""),
|
||||
TransferDateTo: c.Query("transfer_date_to", ""),
|
||||
ApprovalStatus: c.Query("approval_status", ""),
|
||||
TransferNumber: c.Query("transfer_number", ""),
|
||||
Sort: c.Query("sort", "created_at"),
|
||||
Order: c.Query("order", "desc"),
|
||||
Page: c.QueryInt("page", 1),
|
||||
Limit: c.QueryInt("limit", 10),
|
||||
}
|
||||
|
||||
if query.Page < 1 || query.Limit < 1 {
|
||||
@@ -45,8 +38,13 @@ func (u *TransferLayingController) GetAll(c *fiber.Ctx) error {
|
||||
return err
|
||||
}
|
||||
|
||||
data := make([]dto.TransferLayingDetailDTO, len(result))
|
||||
for i, transfer := range result {
|
||||
data[i] = dto.ToTransferLayingDetailDTOWithSingleApproval(transfer, transfer.LatestApproval)
|
||||
}
|
||||
|
||||
return c.Status(fiber.StatusOK).
|
||||
JSON(response.SuccessWithPaginate[dto.TransferLayingListDTO]{
|
||||
JSON(response.SuccessWithPaginate[dto.TransferLayingDetailDTO]{
|
||||
Code: fiber.StatusOK,
|
||||
Status: "success",
|
||||
Message: "Get all transferLayings successfully",
|
||||
@@ -56,7 +54,7 @@ func (u *TransferLayingController) GetAll(c *fiber.Ctx) error {
|
||||
TotalPages: int64(math.Ceil(float64(totalResults) / float64(query.Limit))),
|
||||
TotalResults: totalResults,
|
||||
},
|
||||
Data: dto.ToTransferLayingListDTOs(result),
|
||||
Data: data,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -113,7 +111,7 @@ func (u *TransferLayingController) UpdateOne(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
if err := c.BodyParser(req); err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid request body")
|
||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("Invalid request body: %s", err.Error()))
|
||||
}
|
||||
|
||||
result, err := u.TransferLayingService.UpdateOne(c, req, uint(id))
|
||||
@@ -126,7 +124,7 @@ func (u *TransferLayingController) UpdateOne(c *fiber.Ctx) error {
|
||||
Code: fiber.StatusOK,
|
||||
Status: "success",
|
||||
Message: "Update transferLaying successfully",
|
||||
Data: dto.ToTransferLayingListDTO(*result),
|
||||
Data: dto.ToTransferLayingDetailDTOWithSingleApproval(*result, result.LatestApproval),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -180,3 +178,40 @@ func (u *TransferLayingController) Approval(c *fiber.Ctx) error {
|
||||
Data: data,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
func (u *TransferLayingController) GetAvailableQtyPerKandang(c *fiber.Ctx) error {
|
||||
projectFlockID, err := strconv.ParseUint(c.Params("project_flock_id"), 10, 32)
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid project_flock_id")
|
||||
}
|
||||
|
||||
pf, kandangQtyMap, err := u.TransferLayingService.GetAvailableQtyPerKandang(c, uint(projectFlockID))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Build kandang list response
|
||||
kandangs := make([]dto.KandangAvailableQtyDTO, 0, len(kandangQtyMap))
|
||||
for kandangPFID, qty := range kandangQtyMap {
|
||||
kandangs = append(kandangs, dto.KandangAvailableQtyDTO{
|
||||
ProjectFlockKandangId: kandangPFID,
|
||||
AvailableQty: qty,
|
||||
})
|
||||
}
|
||||
|
||||
resp := dto.AvailableQtyForTransferDTO{
|
||||
ProjectFlockId: pf.Id,
|
||||
ProjectFlockCode: pf.FlockName,
|
||||
Category: pf.Category,
|
||||
Kandangs: kandangs,
|
||||
}
|
||||
|
||||
return c.Status(fiber.StatusOK).
|
||||
JSON(response.Success{
|
||||
Code: fiber.StatusOK,
|
||||
Status: "success",
|
||||
Message: "Get available quantity successfully",
|
||||
Data: resp,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user