254 lines
9.4 KiB
Go
254 lines
9.4 KiB
Go
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_ISSUE = "failed create inventory issue"
|
|
MESSAGE_FAILED_CREATE_INVENTORY_ISSUE_LINE = "failed create inventory issue line"
|
|
MESSAGE_SUCCESS_CREATE_INVENTORY_ISSUE = "success create inventory issue"
|
|
MESSAGE_SUCCESS_CREATE_INVENTORY_ISSUE_LINE = "success create inventory issue line"
|
|
MESSAGE_FAILED_GET_INVENTORY_ISSUE = "failed get inventory issue"
|
|
MESSAGE_SUCCESS_GET_INVENTORY_ISSUE = "success get inventory issue"
|
|
MESSAGE_FAILED_UPDATE_INVENTORY_ISSUE = "failed update inventory issue"
|
|
MESSAGE_FAILED_UPDATE_INVENTORY_ISSUE_LINE = "failed update inventory issue line"
|
|
MESSAGE_SUCCESS_UPDATE_INVENTORY_ISSUE = "success update inventory issue"
|
|
MESSAGE_SUCCESS_UPDATE_INVENTORY_ISSUE_LINE = "success update inventory issue line"
|
|
MESSAGE_FAILED_DELETE_INVENTORY_ISSUE = "failed delete inventory issue"
|
|
MESSAGE_FAILED_DELETE_INVENTORY_ISSUE_LINE = "failed delete inventory issue line"
|
|
MESSAGE_SUCCESS_DELETE_INVENTORY_ISSUE = "success delete inventory issue"
|
|
MESSAGE_SUCCESS_DELETE_INVENTORY_ISSUE_LINE = "success delete inventory issue line"
|
|
MESSAGE_FAILED_GET_DATA_FROM_BODY = "failed get data from body"
|
|
MESSAGE_FAILED_GET_INVENTORY_ISSUE_LINE = "failed get inventory issue line"
|
|
MESSAGE_SUCCESS_GET_INVENTORY_ISSUE_LINE = "success get inventory issue line"
|
|
)
|
|
|
|
type InventoryIssueCreateRequest struct {
|
|
DocumentDate string `json:"document_date"`
|
|
DocumentType string `json:"document_type"`
|
|
DueDate string `json:"due_date"`
|
|
IssuerBy string `json:"issuer_by"`
|
|
InvRequestID string `json:"inv_request_id"`
|
|
ClientID string `json:"client_id" binding:"required"`
|
|
Status string `json:"status"`
|
|
IssueLines []InventoryIssueLineCreateRequest `json:"issue_lines,omitempty" binding:"dive"`
|
|
}
|
|
|
|
type InventoryIssueLineCreateRequest struct {
|
|
CurrentStock float64 `json:"current_stock"`
|
|
MinStock float64 `json:"min_stock"`
|
|
RequestQuantity float64 `json:"request_quantity"`
|
|
IssuedQuantity float64 `json:"issued_quantity"`
|
|
Remarks string `json:"remarks"`
|
|
ProductID string `json:"product_id"`
|
|
WarehouseID string `json:"warehouse_id"`
|
|
ClientID string `json:"client_id"`
|
|
}
|
|
|
|
type InventoryIssueUpdateRequest struct {
|
|
DocumentType string `json:"document_type"`
|
|
DocumentDate string `json:"document_date"`
|
|
DueDate string `json:"due_date"`
|
|
Status string `json:"status"`
|
|
}
|
|
|
|
type InventoryIssueLineUpdateRequest struct {
|
|
CurrentStock *float64 `json:"current_stock"`
|
|
MinStock *float64 `json:"min_stock"`
|
|
RequestQuantity *float64 `json:"request_quantity"`
|
|
IssuedQuantity *float64 `json:"issued_quantity"`
|
|
Remarks *string `json:"remarks"`
|
|
ProductID *string `json:"product_id"`
|
|
WarehouseID *string `json:"warehouse_id"`
|
|
ClientID *string `json:"client_id"`
|
|
}
|
|
|
|
type InventoryIssueResponse struct {
|
|
ID string `json:"id"`
|
|
DocumentNumber string `json:"document_number"`
|
|
DocumentType string `json:"document_type"`
|
|
DocumentDate string `json:"document_date"`
|
|
DueDate string `json:"due_date"`
|
|
Status string `json:"status"`
|
|
IssuerBy pkgdto.IdNameResponse `json:"issuer_by"`
|
|
InvRequest pkgdto.IdNameResponse `json:"inv_request"`
|
|
Client pkgdto.IdNameResponse `json:"client"`
|
|
// LineCount int `json:"line_count"`
|
|
// IssueLines []InventoryIssueLineResponse `json:"issue_lines"`
|
|
Assignment AssignmentResponse `json:"assignment,omitempty"`
|
|
}
|
|
|
|
type InventoryIssueLineResponse struct {
|
|
ID string `json:"id"`
|
|
CurrentStock float64 `json:"current_stock"`
|
|
MinStock float64 `json:"min_stock"`
|
|
RequestQuantity float64 `json:"request_quantity"`
|
|
IssuedQuantity float64 `json:"issued_quantity"`
|
|
Remarks string `json:"remarks"`
|
|
Product InventoryIssueProductResponse `json:"product"`
|
|
Warehouse pkgdto.IdNameResponse `json:"warehouse"`
|
|
Client pkgdto.IdNameResponse `json:"client"`
|
|
}
|
|
|
|
type InventoryIssueProductResponse struct {
|
|
ID string `json:"id"`
|
|
RefNumber string `json:"ref_number"`
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
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"`
|
|
}
|
|
|
|
func ToInventoryIssueResponse(e entities.TInventoryIssueEntity) InventoryIssueResponse {
|
|
issuer := pkgdto.IdNameResponse{}
|
|
if e.Issuer.ID != uuid.Nil {
|
|
issuer = pkgdto.IdNameResponse{
|
|
ID: e.Issuer.ID.String(),
|
|
Name: e.Issuer.Name,
|
|
}
|
|
}
|
|
invRequest := pkgdto.IdNameResponse{}
|
|
if e.InvRequest.ID != uuid.Nil {
|
|
invRequest = pkgdto.IdNameResponse{
|
|
ID: e.InvRequest.ID.String(),
|
|
Name: e.InvRequest.DocumentNumber,
|
|
}
|
|
}
|
|
client := pkgdto.IdNameResponse{}
|
|
if e.Client.ID != uuid.Nil {
|
|
client = pkgdto.IdNameResponse{
|
|
ID: e.Client.ID.String(),
|
|
Name: e.Client.Name,
|
|
}
|
|
}
|
|
|
|
assignment := AssignmentResponse{}
|
|
if e.Assignment.ID != uuid.Nil {
|
|
assignment = ToAssignmentResponse(e.Assignment)
|
|
}
|
|
// lines := make([]InventoryIssueLineResponse, 0)
|
|
// for _, line := range e.IssueLines {
|
|
// product := InventoryIssueProductResponse{}
|
|
// if line.Product.ID != uuid.Nil {
|
|
// product = InventoryIssueProductResponse{
|
|
// ID: line.Product.ID.String(),
|
|
// RefNumber: line.Product.RefNumber,
|
|
// Name: line.Product.Name,
|
|
// }
|
|
// }
|
|
// warehouse := pkgdto.IdNameResponse{}
|
|
// if line.Warehouse.ID != uuid.Nil {
|
|
// warehouse = pkgdto.IdNameResponse{
|
|
// ID: line.Warehouse.ID.String(),
|
|
// Name: line.Warehouse.Name,
|
|
// }
|
|
// }
|
|
// clientLine := pkgdto.IdNameResponse{}
|
|
// if line.Client.ID != uuid.Nil {
|
|
// clientLine = pkgdto.IdNameResponse{
|
|
// ID: line.Client.ID.String(),
|
|
// Name: line.Client.Name,
|
|
// }
|
|
// }
|
|
// lines = append(lines, InventoryIssueLineResponse{
|
|
// ID: line.ID.String(),
|
|
// CurrentStock: line.CurrentStock,
|
|
// MinStock: line.MinStock,
|
|
// RequestQuantity: line.RequestQuantity,
|
|
// IssuedQuantity: line.IssuedQuantity,
|
|
// Remarks: line.Remarks,
|
|
// Product: product,
|
|
// Warehouse: warehouse,
|
|
// Client: clientLine,
|
|
// })
|
|
// }
|
|
return InventoryIssueResponse{
|
|
ID: e.ID.String(),
|
|
DocumentNumber: e.DocumentNumber,
|
|
DocumentType: e.DocumentType,
|
|
DocumentDate: utils.DateTimeToString(e.DocumentDate),
|
|
DueDate: utils.DateTimeToString(e.DueDate),
|
|
Status: e.Status,
|
|
IssuerBy: issuer,
|
|
InvRequest: invRequest,
|
|
Client: client,
|
|
// LineCount: len(lines),
|
|
// IssueLines: lines,
|
|
Assignment: assignment,
|
|
}
|
|
}
|
|
|
|
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 ToInventoryIssueLineResponses(lines []entities.TInventoryIssueLineEntity) []InventoryIssueLineResponse {
|
|
responses := make([]InventoryIssueLineResponse, 0)
|
|
for _, line := range lines {
|
|
product := InventoryIssueProductResponse{}
|
|
if line.Product.ID != uuid.Nil {
|
|
product = InventoryIssueProductResponse{
|
|
ID: line.Product.ID.String(),
|
|
RefNumber: line.Product.RefNumber,
|
|
Name: line.Product.Name,
|
|
}
|
|
}
|
|
warehouse := pkgdto.IdNameResponse{}
|
|
if line.Warehouse.ID != uuid.Nil {
|
|
warehouse = pkgdto.IdNameResponse{
|
|
ID: line.Warehouse.ID.String(),
|
|
Name: line.Warehouse.Name,
|
|
}
|
|
}
|
|
clientLine := pkgdto.IdNameResponse{}
|
|
if line.Client.ID != uuid.Nil {
|
|
clientLine = pkgdto.IdNameResponse{
|
|
ID: line.Client.ID.String(),
|
|
Name: line.Client.Name,
|
|
}
|
|
}
|
|
responses = append(responses, InventoryIssueLineResponse{
|
|
ID: line.ID.String(),
|
|
CurrentStock: line.CurrentStock,
|
|
MinStock: line.MinStock,
|
|
RequestQuantity: line.RequestQuantity,
|
|
IssuedQuantity: line.IssuedQuantity,
|
|
Remarks: line.Remarks,
|
|
Product: product,
|
|
Warehouse: warehouse,
|
|
Client: clientLine,
|
|
})
|
|
}
|
|
return responses
|
|
}
|