mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
174 lines
6.2 KiB
Go
174 lines
6.2 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"
|
|
)
|
|
|
|
type PurchaseListItemDTO struct {
|
|
Id uint64 `json:"id"`
|
|
PrNumber string `json:"pr_number"`
|
|
PoNumber *string `json:"po_number"`
|
|
Supplier *supplierDTO.SupplierBaseDTO `json:"supplier"`
|
|
CreditTerm *int `json:"credit_term"`
|
|
DueDate *time.Time `json:"due_date"`
|
|
PoDate *time.Time `json:"po_date"`
|
|
GrandTotal float64 `json:"grand_total"`
|
|
Notes *string `json:"notes"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
Approval *approvalDTO.ApprovalBaseDTO `json:"approval"`
|
|
}
|
|
|
|
type PurchaseDetailDTO struct {
|
|
Id uint64 `json:"id"`
|
|
PrNumber string `json:"pr_number"`
|
|
PoNumber *string `json:"po_number"`
|
|
Supplier *supplierDTO.SupplierBaseDTO `json:"supplier"`
|
|
CreditTerm *int `json:"credit_term"`
|
|
DueDate *time.Time `json:"due_date"`
|
|
PoDate *time.Time `json:"po_date"`
|
|
GrandTotal float64 `json:"grand_total"`
|
|
Notes *string `json:"notes"`
|
|
Items []PurchaseItemDTO `json:"items"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
Approval *approvalDTO.ApprovalBaseDTO `json:"approval"`
|
|
}
|
|
|
|
type PurchaseItemDTO struct {
|
|
Id uint64 `json:"id"`
|
|
ProductID uint64 `json:"product_id"`
|
|
Product *productDTO.ProductBaseDTO `json:"product"`
|
|
WarehouseID uint64 `json:"warehouse_id"`
|
|
Warehouse *warehouseDTO.WarehouseBaseDTO `json:"warehouse"`
|
|
ProductWarehouseID *uint64 `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 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.ToProductBaseDTO(*item.Product)
|
|
dto.Product = &summary
|
|
}
|
|
if item.Warehouse != nil && item.Warehouse.Id != 0 {
|
|
summary := warehouseDTO.ToWarehouseBaseDTO(*item.Warehouse)
|
|
if item.Warehouse.Area.Id != 0 {
|
|
areaSummary := areaDTO.ToAreaBaseDTO(item.Warehouse.Area)
|
|
summary.Area = &areaSummary
|
|
}
|
|
if item.Warehouse.Location != nil && item.Warehouse.Location.Id != 0 {
|
|
locationSummary := locationDTO.ToLocationBaseDTO(*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 ToPurchaseDetailDTO(p entity.Purchase) PurchaseDetailDTO {
|
|
dto := PurchaseDetailDTO{
|
|
Id: p.Id,
|
|
PrNumber: p.PrNumber,
|
|
PoNumber: p.PoNumber,
|
|
Supplier: mapSupplier(p.Supplier),
|
|
CreditTerm: p.CreditTerm,
|
|
DueDate: p.DueDate,
|
|
PoDate: p.PoDate,
|
|
GrandTotal: p.GrandTotal,
|
|
Notes: p.Notes,
|
|
Items: ToPurchaseItemDTOs(p.Items),
|
|
CreatedAt: p.CreatedAt,
|
|
UpdatedAt: p.UpdatedAt,
|
|
}
|
|
if approval := toPurchaseApprovalDTO(p); approval != nil {
|
|
dto.Approval = approval
|
|
}
|
|
return dto
|
|
}
|
|
|
|
func ToPurchaseListDTO(p entity.Purchase) PurchaseListItemDTO {
|
|
dto := PurchaseListItemDTO{
|
|
Id: p.Id,
|
|
PrNumber: p.PrNumber,
|
|
PoNumber: p.PoNumber,
|
|
Supplier: mapSupplier(p.Supplier),
|
|
CreditTerm: p.CreditTerm,
|
|
DueDate: p.DueDate,
|
|
PoDate: p.PoDate,
|
|
GrandTotal: p.GrandTotal,
|
|
Notes: p.Notes,
|
|
CreatedAt: p.CreatedAt,
|
|
UpdatedAt: p.UpdatedAt,
|
|
}
|
|
if approval := toPurchaseApprovalDTO(p); approval != nil {
|
|
dto.Approval = approval
|
|
}
|
|
return dto
|
|
}
|
|
|
|
func mapSupplier(s entity.Supplier) *supplierDTO.SupplierBaseDTO {
|
|
if s.Id == 0 {
|
|
return nil
|
|
}
|
|
summary := supplierDTO.ToSupplierBaseDTO(s)
|
|
return &summary
|
|
}
|
|
|
|
func ToPurchaseListDTOs(items []entity.Purchase) []PurchaseListItemDTO {
|
|
if len(items) == 0 {
|
|
return nil
|
|
}
|
|
result := make([]PurchaseListItemDTO, len(items))
|
|
for i, item := range items {
|
|
result[i] = ToPurchaseListDTO(item)
|
|
}
|
|
return result
|
|
}
|
|
|
|
func toPurchaseApprovalDTO(p entity.Purchase) *approvalDTO.ApprovalBaseDTO {
|
|
if p.LatestApproval == nil || p.LatestApproval.Id == 0 {
|
|
return nil
|
|
}
|
|
mapped := approvalDTO.ToApprovalDTO(*p.LatestApproval)
|
|
return &mapped
|
|
}
|