mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-22 22:35:43 +00:00
fix: next period,purchase before bop, integration auth module,fix validation-master data
This commit is contained in:
@@ -10,46 +10,51 @@ import (
|
||||
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 PurchaseListItemDTO struct {
|
||||
Id uint64 `json:"id"`
|
||||
PrNumber string `json:"pr_number"`
|
||||
PoNumber *string `json:"po_number"`
|
||||
Supplier *supplierDTO.SupplierRelationDTO `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.ApprovalRelationDTO `json:"approval"`
|
||||
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"`
|
||||
CreditTerm *int `json:"credit_term"`
|
||||
DueDate *time.Time `json:"due_date"`
|
||||
GrandTotal float64 `json:"grand_total"`
|
||||
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 {
|
||||
Id uint64 `json:"id"`
|
||||
PrNumber string `json:"pr_number"`
|
||||
PoNumber *string `json:"po_number"`
|
||||
Supplier *supplierDTO.SupplierRelationDTO `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.ApprovalRelationDTO `json:"approval"`
|
||||
PurchaseRelationDTO
|
||||
Supplier *supplierDTO.SupplierRelationDTO `json:"supplier"`
|
||||
CreditTerm *int `json:"credit_term"`
|
||||
DueDate *time.Time `json:"due_date"`
|
||||
GrandTotal float64 `json:"grand_total"`
|
||||
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 uint64 `json:"id"`
|
||||
ProductID uint64 `json:"product_id"`
|
||||
Id uint `json:"id"`
|
||||
ProductID uint `json:"product_id"`
|
||||
Product *productDTO.ProductRelationDTO `json:"product"`
|
||||
WarehouseID uint64 `json:"warehouse_id"`
|
||||
WarehouseID uint `json:"warehouse_id"`
|
||||
Warehouse *warehouseDTO.WarehouseRelationDTO `json:"warehouse"`
|
||||
ProductWarehouseID *uint64 `json:"product_warehouse_id"`
|
||||
ProductWarehouseID *uint `json:"product_warehouse_id"`
|
||||
SubQty float64 `json:"sub_qty"`
|
||||
TotalQty float64 `json:"total_qty"`
|
||||
TotalUsed float64 `json:"total_used"`
|
||||
@@ -61,6 +66,17 @@ type PurchaseItemDTO struct {
|
||||
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,
|
||||
@@ -77,10 +93,12 @@ func ToPurchaseItemDTO(item entity.PurchaseItem) PurchaseItemDTO {
|
||||
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 {
|
||||
@@ -93,6 +111,7 @@ func ToPurchaseItemDTO(item entity.PurchaseItem) PurchaseItemDTO {
|
||||
}
|
||||
dto.Warehouse = &summary
|
||||
}
|
||||
|
||||
return dto
|
||||
}
|
||||
|
||||
@@ -104,70 +123,78 @@ func ToPurchaseItemDTOs(items []entity.PurchaseItem) []PurchaseItemDTO {
|
||||
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,
|
||||
func ToPurchaseListDTO(p entity.Purchase) PurchaseListDTO {
|
||||
var supplier *supplierDTO.SupplierRelationDTO
|
||||
if p.Supplier.Id != 0 {
|
||||
mapped := supplierDTO.ToSupplierRelationDTO(p.Supplier)
|
||||
supplier = &mapped
|
||||
}
|
||||
if approval := toPurchaseApprovalDTO(p); approval != nil {
|
||||
dto.Approval = approval
|
||||
|
||||
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,
|
||||
CreditTerm: p.CreditTerm,
|
||||
DueDate: p.DueDate,
|
||||
GrandTotal: p.GrandTotal,
|
||||
CreatedUser: createdUser,
|
||||
CreatedAt: p.CreatedAt,
|
||||
UpdatedAt: p.UpdatedAt,
|
||||
LatestApproval: latestApproval,
|
||||
}
|
||||
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.SupplierRelationDTO {
|
||||
if s.Id == 0 {
|
||||
return nil
|
||||
}
|
||||
summary := supplierDTO.ToSupplierRelationDTO(s)
|
||||
return &summary
|
||||
}
|
||||
|
||||
func ToPurchaseListDTOs(items []entity.Purchase) []PurchaseListItemDTO {
|
||||
func ToPurchaseListDTOs(items []entity.Purchase) []PurchaseListDTO {
|
||||
if len(items) == 0 {
|
||||
return nil
|
||||
return make([]PurchaseListDTO, 0)
|
||||
}
|
||||
result := make([]PurchaseListItemDTO, len(items))
|
||||
result := make([]PurchaseListDTO, len(items))
|
||||
for i, item := range items {
|
||||
result[i] = ToPurchaseListDTO(item)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func toPurchaseApprovalDTO(p entity.Purchase) *approvalDTO.ApprovalRelationDTO {
|
||||
if p.LatestApproval == nil || p.LatestApproval.Id == 0 {
|
||||
return nil
|
||||
func ToPurchaseDetailDTO(p entity.Purchase) PurchaseDetailDTO {
|
||||
var supplier *supplierDTO.SupplierRelationDTO
|
||||
if p.Supplier.Id != 0 {
|
||||
mapped := supplierDTO.ToSupplierRelationDTO(p.Supplier)
|
||||
supplier = &mapped
|
||||
}
|
||||
mapped := approvalDTO.ToApprovalDTO(*p.LatestApproval)
|
||||
return &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,
|
||||
CreditTerm: p.CreditTerm,
|
||||
DueDate: p.DueDate,
|
||||
GrandTotal: p.GrandTotal,
|
||||
Items: ToPurchaseItemDTOs(p.Items),
|
||||
CreatedUser: createdUser,
|
||||
CreatedAt: p.CreatedAt,
|
||||
UpdatedAt: p.UpdatedAt,
|
||||
LatestApproval: latestApproval,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user