package dto import ( "github.com/Caknoooo/go-gin-clean-starter/database/entities" pkgdto "github.com/Caknoooo/go-gin-clean-starter/pkg/dto" "github.com/Caknoooo/go-gin-clean-starter/pkg/utils" "github.com/google/uuid" ) const ( MESSAGE_FAILED_CREATE_INVENTORY_REQUEST = "failed create inventory request" MESSAGE_FAILED_CREATE_INVENTORY_REQUEST_LINE = "failed create inventory request line" MESSAGE_SUCCESS_CREATE_INVENTORY_REQUEST = "success create inventory request" MESSAGE_SUCCESS_CREATE_INVENTORY_REQUEST_LINE = "success create inventory request line" MESSAGE_FAILED_GET_INVENTORY_REQUEST = "failed get inventory request" MESSAGE_SUCCESS_GET_INVENTORY_REQUEST = "success get inventory request" MESSAGE_FAILED_UPDATE_INVENTORY_REQUEST = "failed update inventory request" MESSAGE_FAILED_UPDATE_INVENTORY_REQUEST_LINE = "failed update inventory request line" MESSAGE_SUCCESS_UPDATE_INVENTORY_REQUEST = "success update inventory request" MESSAGE_SUCCESS_UPDATE_INVENTORY_REQUEST_LINE = "success update inventory request line" MESSAGE_FAILED_DELETE_INVENTORY_REQUEST = "failed delete inventory request" MESSAGE_FAILED_DELETE_INVENTORY_REQUEST_LINE = "failed delete inventory request line" MESSAGE_SUCCESS_DELETE_INVENTORY_REQUEST = "success delete inventory request" MESSAGE_SUCCESS_DELETE_INVENTORY_REQUEST_LINE = "success delete inventory request line" MESSAGE_FAILED_GET_DATA_FROM_BODY = "failed get data from body" MESSAGE_FAILED_GET_INVENTORY_REQUEST_LINE = "failed get inventory request line" MESSAGE_SUCCESS_GET_INVENTORY_REQUEST_LINE = "success get inventory request line" ) type InventoryRequestCreateRequest struct { ReferenceNumber string `json:"reference_number"` // DocumentNumber string `json:"document_number"` DueDate string `json:"due_date"` RequestType string `json:"request_type"` Note string `json:"note"` ClientID string `json:"client_id" binding:"required"` Status string `json:"status"` RequestLines []InventoryRequestLineCreateRequest `json:"request_lines,omitempty" binding:"dive"` } type InventoryRequestLineCreateRequest struct { Quantity float64 `json:"quantity"` ProductID string `json:"product_id"` ClientID string `json:"client_id"` } type InventoryRequestUpdateRequest struct { ReferenceNumber string `json:"reference_number"` DocumentNumber string `json:"document_number"` DueDate string `json:"due_date"` RequestType string `json:"request_type"` Note string `json:"note"` Status string `json:"status"` } type InventoryRequestResponse struct { ID string `json:"id"` ReferenceNumber string `json:"reference_number"` DocumentNumber string `json:"document_number"` DueDate string `json:"due_date"` RequestType string `json:"request_type"` Note string `json:"note"` Status string `json:"status"` Client pkgdto.IdNameResponse `json:"client"` // RequestLines []InventoryRequestLineResponse `json:"request_lines"` // LineCount int `json:"line_count"` Assignment *AssignmentResponse `json:"assignment"` } type AssignmentResponse struct { ID string `json:"id"` DocumentType string `json:"document_type"` DocumentID string `json:"document_id"` AssignmentUsers []AssignmentUserResponse `json:"assignment_users"` } type AssignmentUserResponse struct { ID string `json:"id"` TaskType string `json:"task_type"` User pkgdto.IdNameResponse `json:"user"` Role pkgdto.IdNameResponse `json:"role"` } type InventoryRequestLineResponse struct { ID string `json:"id"` Quantity float64 `json:"quantity"` CurrentStock float64 `json:"current_stock"` Product InventoryRequestLineProductResponse `json:"product"` ClientID string `json:"client_id"` } type InventoryRequestLineProductResponse struct { ID string `json:"id"` Name string `json:"name"` RefNumber string `json:"ref_number"` Uom pkgdto.IdNameResponse `json:"uom"` } type InventoryRequestLineUpdateRequest struct { Quantity *float64 `json:"quantity"` ProductID *string `json:"product_id"` } func ToAssignmentResponse(e entities.TAssignmentEntity) AssignmentResponse { users := make([]AssignmentUserResponse, 0) for _, user := range e.AssignmentUsers { userResp := AssignmentUserResponse{ ID: user.ID.String(), TaskType: user.TaskType, User: pkgdto.IdNameResponse{ID: user.User.ID.String(), Name: user.User.Name}, Role: pkgdto.IdNameResponse{ID: user.Role.ID.String(), Name: user.Role.Name}, } users = append(users, userResp) } return AssignmentResponse{ ID: e.ID.String(), DocumentType: e.DocumentType, DocumentID: e.DocumentID.String(), AssignmentUsers: users, } } func ToInventoryRequestResponse(e entities.TInventoryRequestEntity) InventoryRequestResponse { client := pkgdto.IdNameResponse{} if e.Client.ID != uuid.Nil { client = pkgdto.IdNameResponse{ ID: e.Client.ID.String(), Name: e.Client.Name, } } // lines := make([]InventoryRequestLineResponse, 0) // for _, line := range e.RequestLines { // product := InventoryRequestLineProductResponse{} // if line.Product.ID != uuid.Nil { // product = InventoryRequestLineProductResponse{ // ID: line.Product.ID.String(), // Name: line.Product.Name, // RefNumber: line.Product.RefNumber, // Uom: pkgdto.IdNameResponse{ // ID: line.Product.Uom.ID.String(), // Name: line.Product.Uom.Name, // }, // } // } // lines = append(lines, InventoryRequestLineResponse{ // ID: line.ID.String(), // Quantity: line.Quantity, // // CurrentStock: line.Product.CurrentStock, // Product: product, // ClientID: line.ClientID.String(), // }) // } var assignment *AssignmentResponse if e.Assignment.ID != uuid.Nil { ass := ToAssignmentResponse(e.Assignment) assignment = &ass } else { assignment = nil } return InventoryRequestResponse{ ID: e.ID.String(), ReferenceNumber: e.ReferenceNumber, DocumentNumber: e.DocumentNumber, DueDate: utils.DateTimeToString(e.DueDate), RequestType: e.RequestType, Note: e.Note, Status: e.Status, Client: client, // LineCount: len(lines), // RequestLines: lines, Assignment: assignment, } } func ToInventoryRequestLineResponse(e entities.TInventoryRequestLineEntity) InventoryRequestLineResponse { product := InventoryRequestLineProductResponse{} if e.Product.ID != uuid.Nil { product = InventoryRequestLineProductResponse{ ID: e.Product.ID.String(), Name: e.Product.Name, RefNumber: e.Product.RefNumber, Uom: pkgdto.IdNameResponse{ ID: e.Product.Uom.ID.String(), Name: e.Product.Uom.Name, }, } } return InventoryRequestLineResponse{ ID: e.ID.String(), Quantity: e.Quantity, // CurrentStock: e.CurrentStock, Product: product, ClientID: e.ClientID.String(), } } func ToInventoryRequestLineResponses(linesEntity []entities.TInventoryRequestLineEntity) []InventoryRequestLineResponse { lines := make([]InventoryRequestLineResponse, 0) for _, line := range linesEntity { product := InventoryRequestLineProductResponse{} if line.Product.ID != uuid.Nil { product = InventoryRequestLineProductResponse{ ID: line.Product.ID.String(), Name: line.Product.Name, RefNumber: line.Product.RefNumber, Uom: pkgdto.IdNameResponse{ ID: line.Product.Uom.ID.String(), Name: line.Product.Uom.Name, }, } } lines = append(lines, InventoryRequestLineResponse{ ID: line.ID.String(), Quantity: line.Quantity, Product: product, ClientID: line.ClientID.String(), }) } return lines }