mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
192 lines
6.6 KiB
Go
192 lines
6.6 KiB
Go
package dto
|
|
|
|
import (
|
|
"time"
|
|
|
|
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
|
approvalDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/approvals/dto"
|
|
areaDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/areas/dto"
|
|
locationDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/locations/dto"
|
|
productDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/products/dto"
|
|
supplierDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/suppliers/dto"
|
|
warehouseDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/warehouses/dto"
|
|
userDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/users/dto"
|
|
)
|
|
|
|
type PurchaseRelationDTO struct {
|
|
Id uint `json:"id"`
|
|
PrNumber string `json:"pr_number"`
|
|
PoNumber *string `json:"po_number"`
|
|
PoDate *time.Time `json:"po_date"`
|
|
Notes *string `json:"notes"`
|
|
}
|
|
|
|
type PurchaseListDTO struct {
|
|
PurchaseRelationDTO
|
|
Supplier *supplierDTO.SupplierRelationDTO `json:"supplier"`
|
|
DueDate *time.Time `json:"due_date"`
|
|
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
LatestApproval *approvalDTO.ApprovalRelationDTO `json:"latest_approval"`
|
|
}
|
|
|
|
type PurchaseDetailDTO struct {
|
|
PurchaseRelationDTO
|
|
Supplier *supplierDTO.SupplierRelationDTO `json:"supplier"`
|
|
DueDate *time.Time `json:"due_date"`
|
|
Items []PurchaseItemDTO `json:"items"`
|
|
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
LatestApproval *approvalDTO.ApprovalRelationDTO `json:"latest_approval"`
|
|
}
|
|
|
|
|
|
type PurchaseItemDTO struct {
|
|
Id uint `json:"id"`
|
|
ProductID uint `json:"product_id"`
|
|
Product *productDTO.ProductRelationDTO `json:"product"`
|
|
WarehouseID uint `json:"warehouse_id"`
|
|
Warehouse *warehouseDTO.WarehouseRelationDTO `json:"warehouse"`
|
|
ProductWarehouseID *uint `json:"product_warehouse_id"`
|
|
SubQty float64 `json:"sub_qty"`
|
|
TotalQty float64 `json:"total_qty"`
|
|
TotalUsed float64 `json:"total_used"`
|
|
Price float64 `json:"price"`
|
|
TotalPrice float64 `json:"total_price"`
|
|
ReceivedDate *time.Time `json:"received_date"`
|
|
TravelNumber *string `json:"travel_number"`
|
|
TravelDocumentPath *string `json:"travel_document_path"`
|
|
VehicleNumber *string `json:"vehicle_number"`
|
|
}
|
|
|
|
|
|
func ToPurchaseRelationDTO(p *entity.Purchase) PurchaseRelationDTO {
|
|
return PurchaseRelationDTO{
|
|
Id: p.Id,
|
|
PrNumber: p.PrNumber,
|
|
PoNumber: p.PoNumber,
|
|
PoDate: p.PoDate,
|
|
Notes: p.Notes,
|
|
}
|
|
}
|
|
|
|
func ToPurchaseItemDTO(item entity.PurchaseItem) PurchaseItemDTO {
|
|
dto := PurchaseItemDTO{
|
|
Id: item.Id,
|
|
ProductID: item.ProductId,
|
|
ProductWarehouseID: item.ProductWarehouseId,
|
|
WarehouseID: item.WarehouseId,
|
|
SubQty: item.SubQty,
|
|
TotalQty: item.TotalQty,
|
|
TotalUsed: item.TotalUsed,
|
|
Price: item.Price,
|
|
TotalPrice: item.TotalPrice,
|
|
ReceivedDate: item.ReceivedDate,
|
|
TravelNumber: item.TravelNumber,
|
|
TravelDocumentPath: item.TravelNumberDocs,
|
|
VehicleNumber: item.VehicleNumber,
|
|
}
|
|
|
|
if item.Product != nil && item.Product.Id != 0 {
|
|
summary := productDTO.ToProductRelationDTO(*item.Product)
|
|
dto.Product = &summary
|
|
}
|
|
|
|
if item.Warehouse != nil && item.Warehouse.Id != 0 {
|
|
summary := warehouseDTO.ToWarehouseRelationDTO(*item.Warehouse)
|
|
if item.Warehouse.Area.Id != 0 {
|
|
areaSummary := areaDTO.ToAreaRelationDTO(item.Warehouse.Area)
|
|
summary.Area = &areaSummary
|
|
}
|
|
if item.Warehouse.Location != nil && item.Warehouse.Location.Id != 0 {
|
|
locationSummary := locationDTO.ToLocationRelationDTO(*item.Warehouse.Location)
|
|
summary.Location = &locationSummary
|
|
}
|
|
dto.Warehouse = &summary
|
|
}
|
|
|
|
return dto
|
|
}
|
|
|
|
func ToPurchaseItemDTOs(items []entity.PurchaseItem) []PurchaseItemDTO {
|
|
result := make([]PurchaseItemDTO, len(items))
|
|
for i, item := range items {
|
|
result[i] = ToPurchaseItemDTO(item)
|
|
}
|
|
return result
|
|
}
|
|
|
|
func ToPurchaseListDTO(p entity.Purchase) PurchaseListDTO {
|
|
var supplier *supplierDTO.SupplierRelationDTO
|
|
if p.Supplier.Id != 0 {
|
|
mapped := supplierDTO.ToSupplierRelationDTO(p.Supplier)
|
|
supplier = &mapped
|
|
}
|
|
|
|
var createdUser *userDTO.UserRelationDTO
|
|
if p.CreatedUser.Id != 0 {
|
|
mapped := userDTO.ToUserRelationDTO(p.CreatedUser)
|
|
createdUser = &mapped
|
|
}
|
|
|
|
var latestApproval *approvalDTO.ApprovalRelationDTO
|
|
if p.LatestApproval != nil && p.LatestApproval.Id != 0 {
|
|
mapped := approvalDTO.ToApprovalDTO(*p.LatestApproval)
|
|
latestApproval = &mapped
|
|
}
|
|
|
|
return PurchaseListDTO{
|
|
PurchaseRelationDTO: ToPurchaseRelationDTO(&p),
|
|
Supplier: supplier,
|
|
DueDate: p.DueDate,
|
|
CreatedUser: createdUser,
|
|
CreatedAt: p.CreatedAt,
|
|
UpdatedAt: p.UpdatedAt,
|
|
LatestApproval: latestApproval,
|
|
}
|
|
}
|
|
|
|
func ToPurchaseListDTOs(items []entity.Purchase) []PurchaseListDTO {
|
|
if len(items) == 0 {
|
|
return make([]PurchaseListDTO, 0)
|
|
}
|
|
result := make([]PurchaseListDTO, len(items))
|
|
for i, item := range items {
|
|
result[i] = ToPurchaseListDTO(item)
|
|
}
|
|
return result
|
|
}
|
|
|
|
func ToPurchaseDetailDTO(p entity.Purchase) PurchaseDetailDTO {
|
|
var supplier *supplierDTO.SupplierRelationDTO
|
|
if p.Supplier.Id != 0 {
|
|
mapped := supplierDTO.ToSupplierRelationDTO(p.Supplier)
|
|
supplier = &mapped
|
|
}
|
|
|
|
var createdUser *userDTO.UserRelationDTO
|
|
if p.CreatedUser.Id != 0 {
|
|
mapped := userDTO.ToUserRelationDTO(p.CreatedUser)
|
|
createdUser = &mapped
|
|
}
|
|
|
|
var latestApproval *approvalDTO.ApprovalRelationDTO
|
|
if p.LatestApproval != nil && p.LatestApproval.Id != 0 {
|
|
mapped := approvalDTO.ToApprovalDTO(*p.LatestApproval)
|
|
latestApproval = &mapped
|
|
}
|
|
|
|
return PurchaseDetailDTO{
|
|
PurchaseRelationDTO: ToPurchaseRelationDTO(&p),
|
|
Supplier: supplier,
|
|
DueDate: p.DueDate,
|
|
Items: ToPurchaseItemDTOs(p.Items),
|
|
CreatedUser: createdUser,
|
|
CreatedAt: p.CreatedAt,
|
|
UpdatedAt: p.UpdatedAt,
|
|
LatestApproval: latestApproval,
|
|
}
|
|
}
|