mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-24 15:25:43 +00:00
Feat[BE-222]: Completed SO and DO API
This commit is contained in:
@@ -4,111 +4,37 @@ import (
|
||||
"time"
|
||||
|
||||
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
||||
approvalDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/approvals/dto"
|
||||
customerDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/customers/dto"
|
||||
productDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/products/dto"
|
||||
warehouseDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/warehouses/dto"
|
||||
userDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/users/dto"
|
||||
"gitlab.com/mbugroup/lti-api.git/internal/utils"
|
||||
approvalutils "gitlab.com/mbugroup/lti-api.git/internal/utils/approvals"
|
||||
productWarehouseDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/inventory/product-warehouses/dto"
|
||||
)
|
||||
|
||||
// === DTO Structs ===
|
||||
|
||||
type SalesOrdersBaseDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type MarketingProductDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Qty float64 `json:"qty"`
|
||||
UnitPrice float64 `json:"unit_price"`
|
||||
AvgWeight float64 `json:"avg_weight"`
|
||||
TotalWeight float64 `json:"total_weight"`
|
||||
TotalPrice float64 `json:"total_price"`
|
||||
ProductWarehouse *struct {
|
||||
Id uint `json:"id"`
|
||||
Product *productDTO.ProductBaseDTO `json:"product,omitempty"`
|
||||
Warehouse *warehouseDTO.WarehouseBaseDTO `json:"warehouse,omitempty"`
|
||||
} `json:"product_warehouse,omitempty"`
|
||||
DeliveryProduct *MarketingDeliveryProductDTO `json:"delivery_product,omitempty"`
|
||||
}
|
||||
|
||||
type MarketingDeliveryProductDTO struct {
|
||||
Id uint `json:"id"`
|
||||
MarketingProductId uint `json:"marketing_product_id"`
|
||||
Qty float64 `json:"qty"`
|
||||
UnitPrice float64 `json:"unit_price"`
|
||||
TotalWeight float64 `json:"total_weight"`
|
||||
AvgWeight float64 `json:"avg_weight"`
|
||||
TotalPrice float64 `json:"total_price"`
|
||||
DeliveryDate *time.Time `json:"delivery_date"`
|
||||
VehicleNumber string `json:"vehicle_number"`
|
||||
Id uint `json:"id"`
|
||||
Qty float64 `json:"qty"`
|
||||
UnitPrice float64 `json:"unit_price"`
|
||||
AvgWeight float64 `json:"avg_weight"`
|
||||
TotalWeight float64 `json:"total_weight"`
|
||||
TotalPrice float64 `json:"total_price"`
|
||||
ProductWarehouse *productWarehouseDTO.ProductWarehousNestedDTO `json:"product_warehouse,omitempty"`
|
||||
}
|
||||
|
||||
type SalesOrdersListDTO struct {
|
||||
SalesOrdersBaseDTO
|
||||
CustomerId uint `json:"customer_id,omitempty"`
|
||||
Customer *customerDTO.CustomerBaseDTO `json:"customer,omitempty"`
|
||||
SoDate *time.Time `json:"so_date,omitempty"`
|
||||
SalesPersonId uint `json:"sales_person_id,omitempty"`
|
||||
Notes string `json:"notes,omitempty"`
|
||||
MarketingProducts []MarketingProductDTO `json:"marketing_products,omitempty"`
|
||||
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Approval approvalDTO.ApprovalBaseDTO `json:"approval"`
|
||||
}
|
||||
|
||||
type SalesOrdersDetailDTO struct {
|
||||
SalesOrdersListDTO
|
||||
Id uint `json:"id"`
|
||||
SoNumber string `json:"so_number"`
|
||||
SoDate time.Time `json:"so_date"`
|
||||
Notes string `json:"notes,omitempty"`
|
||||
SalesOrder []MarketingProductDTO `json:"sales_order,omitempty"`
|
||||
}
|
||||
|
||||
// === Mapper Functions ===
|
||||
|
||||
func ToSalesOrdersBaseDTO(e entity.SalesOrders) SalesOrdersBaseDTO {
|
||||
return SalesOrdersBaseDTO{
|
||||
Id: e.Id,
|
||||
Name: e.Name,
|
||||
}
|
||||
}
|
||||
|
||||
func ToMarketingProductDTO(e entity.MarketingProduct) MarketingProductDTO {
|
||||
var productWarehouse *struct {
|
||||
Id uint `json:"id"`
|
||||
Product *productDTO.ProductBaseDTO `json:"product,omitempty"`
|
||||
Warehouse *warehouseDTO.WarehouseBaseDTO `json:"warehouse,omitempty"`
|
||||
}
|
||||
var productWarehouse *productWarehouseDTO.ProductWarehousNestedDTO
|
||||
|
||||
if e.ProductWarehouse.Id != 0 {
|
||||
product := (*productDTO.ProductBaseDTO)(nil)
|
||||
if e.ProductWarehouse.Product.Id != 0 {
|
||||
mapped := productDTO.ToProductBaseDTO(e.ProductWarehouse.Product)
|
||||
product = &mapped
|
||||
}
|
||||
|
||||
warehouse := (*warehouseDTO.WarehouseBaseDTO)(nil)
|
||||
if e.ProductWarehouse.Warehouse.Id != 0 {
|
||||
mapped := warehouseDTO.ToWarehouseBaseDTO(e.ProductWarehouse.Warehouse)
|
||||
warehouse = &mapped
|
||||
}
|
||||
|
||||
productWarehouse = &struct {
|
||||
Id uint `json:"id"`
|
||||
Product *productDTO.ProductBaseDTO `json:"product,omitempty"`
|
||||
Warehouse *warehouseDTO.WarehouseBaseDTO `json:"warehouse,omitempty"`
|
||||
}{
|
||||
Id: e.ProductWarehouse.Id,
|
||||
Product: product,
|
||||
Warehouse: warehouse,
|
||||
}
|
||||
}
|
||||
|
||||
var deliveryProduct *MarketingDeliveryProductDTO
|
||||
if e.DeliveryProduct != nil && e.DeliveryProduct.Id != 0 {
|
||||
mapped := ToMarketingDeliveryProductDTO(*e.DeliveryProduct)
|
||||
deliveryProduct = &mapped
|
||||
mapped := productWarehouseDTO.ToProductWarehouseNestedDTO(e.ProductWarehouse)
|
||||
productWarehouse = &mapped
|
||||
}
|
||||
|
||||
return MarketingProductDTO{
|
||||
@@ -119,139 +45,38 @@ func ToMarketingProductDTO(e entity.MarketingProduct) MarketingProductDTO {
|
||||
TotalWeight: e.TotalWeight,
|
||||
TotalPrice: e.TotalPrice,
|
||||
ProductWarehouse: productWarehouse,
|
||||
DeliveryProduct: deliveryProduct,
|
||||
}
|
||||
}
|
||||
|
||||
func ToMarketingDeliveryProductDTO(e entity.MarketingDeliveryProduct) MarketingDeliveryProductDTO {
|
||||
return MarketingDeliveryProductDTO{
|
||||
Id: e.Id,
|
||||
MarketingProductId: e.MarketingProductId,
|
||||
Qty: e.Qty,
|
||||
UnitPrice: e.UnitPrice,
|
||||
TotalWeight: e.TotalWeight,
|
||||
AvgWeight: e.AvgWeight,
|
||||
TotalPrice: e.TotalPrice,
|
||||
DeliveryDate: e.DeliveryDate,
|
||||
VehicleNumber: e.VehicleNumber,
|
||||
}
|
||||
}
|
||||
|
||||
func defaultSalesOrdersLatestApproval(e entity.SalesOrders) approvalDTO.ApprovalBaseDTO {
|
||||
result := approvalDTO.ApprovalBaseDTO{}
|
||||
|
||||
step := utils.MarketingStepPengajuan
|
||||
if step > 0 {
|
||||
result.StepNumber = uint16(step)
|
||||
if label, ok := approvalutils.ApprovalStepName(utils.ApprovalWorkflowMarketing, step); ok {
|
||||
result.StepName = label
|
||||
} else if label, ok := utils.MarketingApprovalSteps[step]; ok {
|
||||
result.StepName = label
|
||||
}
|
||||
}
|
||||
|
||||
if e.CreatedUser.Id != 0 {
|
||||
result.ActionBy = userDTO.ToUserBaseDTO(e.CreatedUser)
|
||||
} else if e.CreatedBy != 0 {
|
||||
result.ActionBy = userDTO.UserBaseDTO{
|
||||
Id: e.CreatedBy,
|
||||
IdUser: int64(e.CreatedBy),
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func ToSalesOrdersListDTO(e entity.SalesOrders) SalesOrdersListDTO {
|
||||
var createdUser *userDTO.UserBaseDTO
|
||||
if e.CreatedUser.Id != 0 {
|
||||
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
|
||||
createdUser = &mapped
|
||||
}
|
||||
|
||||
approval := defaultSalesOrdersLatestApproval(e)
|
||||
if e.LatestApproval != nil {
|
||||
approval = approvalDTO.ToApprovalDTO(*e.LatestApproval)
|
||||
}
|
||||
|
||||
return SalesOrdersListDTO{
|
||||
SalesOrdersBaseDTO: ToSalesOrdersBaseDTO(e),
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
CreatedUser: createdUser,
|
||||
Approval: approval,
|
||||
Id: e.Id,
|
||||
SoNumber: e.Name,
|
||||
SoDate: time.Time{},
|
||||
Notes: "",
|
||||
SalesOrder: []MarketingProductDTO{},
|
||||
}
|
||||
}
|
||||
|
||||
func ToSalesOrdersListDTOFromMarketing(e entity.Marketing) SalesOrdersListDTO {
|
||||
var createdUser *userDTO.UserBaseDTO
|
||||
if e.CreatedUser.Id != 0 {
|
||||
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
|
||||
createdUser = &mapped
|
||||
}
|
||||
|
||||
var marketingProducts []MarketingProductDTO
|
||||
var salesOrder []MarketingProductDTO
|
||||
if len(e.Products) > 0 {
|
||||
marketingProducts = make([]MarketingProductDTO, len(e.Products))
|
||||
salesOrder = make([]MarketingProductDTO, len(e.Products))
|
||||
for i, product := range e.Products {
|
||||
marketingProducts[i] = ToMarketingProductDTO(product)
|
||||
salesOrder[i] = ToMarketingProductDTO(product)
|
||||
}
|
||||
}
|
||||
|
||||
var customerSummary *customerDTO.CustomerBaseDTO
|
||||
if e.Customer.Id != 0 {
|
||||
mapped := customerDTO.ToCustomerBaseDTO(e.Customer)
|
||||
customerSummary = &mapped
|
||||
}
|
||||
|
||||
approval := defaultSalesOrdersLatestApprovalFromMarketing(e)
|
||||
if e.LatestApproval != nil {
|
||||
approval = approvalDTO.ToApprovalDTO(*e.LatestApproval)
|
||||
}
|
||||
|
||||
return SalesOrdersListDTO{
|
||||
SalesOrdersBaseDTO: SalesOrdersBaseDTO{
|
||||
Id: e.Id,
|
||||
Name: e.SoNumber,
|
||||
},
|
||||
CustomerId: e.Customer.Id,
|
||||
Customer: customerSummary,
|
||||
SoDate: &e.SoDate,
|
||||
SalesPersonId: e.SalesPersonId,
|
||||
Notes: e.Notes,
|
||||
MarketingProducts: marketingProducts,
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
CreatedUser: createdUser,
|
||||
Approval: approval,
|
||||
Id: e.Id,
|
||||
SoNumber: e.SoNumber,
|
||||
SoDate: e.SoDate,
|
||||
Notes: e.Notes,
|
||||
SalesOrder: salesOrder,
|
||||
}
|
||||
}
|
||||
|
||||
func defaultSalesOrdersLatestApprovalFromMarketing(e entity.Marketing) approvalDTO.ApprovalBaseDTO {
|
||||
result := approvalDTO.ApprovalBaseDTO{}
|
||||
|
||||
step := utils.MarketingStepPengajuan
|
||||
if step > 0 {
|
||||
result.StepNumber = uint16(step)
|
||||
if label, ok := approvalutils.ApprovalStepName(utils.ApprovalWorkflowMarketing, step); ok {
|
||||
result.StepName = label
|
||||
} else if label, ok := utils.MarketingApprovalSteps[step]; ok {
|
||||
result.StepName = label
|
||||
}
|
||||
}
|
||||
|
||||
if e.CreatedUser.Id != 0 {
|
||||
result.ActionBy = userDTO.ToUserBaseDTO(e.CreatedUser)
|
||||
} else if e.CreatedBy != 0 {
|
||||
result.ActionBy = userDTO.UserBaseDTO{
|
||||
Id: e.CreatedBy,
|
||||
IdUser: int64(e.CreatedBy),
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func ToSalesOrdersListDTOsFromMarketing(e []entity.Marketing) []SalesOrdersListDTO {
|
||||
result := make([]SalesOrdersListDTO, len(e))
|
||||
for i, r := range e {
|
||||
@@ -259,17 +84,3 @@ func ToSalesOrdersListDTOsFromMarketing(e []entity.Marketing) []SalesOrdersListD
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func ToSalesOrdersListDTOs(e []entity.SalesOrders) []SalesOrdersListDTO {
|
||||
result := make([]SalesOrdersListDTO, len(e))
|
||||
for i, r := range e {
|
||||
result[i] = ToSalesOrdersListDTO(r)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func ToSalesOrdersDetailDTO(e entity.SalesOrders) SalesOrdersDetailDTO {
|
||||
return SalesOrdersDetailDTO{
|
||||
SalesOrdersListDTO: ToSalesOrdersListDTO(e),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user