feat: enhance inventory return line entity and DTOs with return and issued quantity fields
This commit is contained in:
parent
a2e92cf738
commit
b14f2eeafd
|
|
@ -6,7 +6,8 @@ import (
|
||||||
|
|
||||||
type TInventoryReturnLineEntity struct {
|
type TInventoryReturnLineEntity struct {
|
||||||
ID uuid.UUID `gorm:"primaryKey;type:uuid;default:uuid_generate_v4()" json:"id"`
|
ID uuid.UUID `gorm:"primaryKey;type:uuid;default:uuid_generate_v4()" json:"id"`
|
||||||
Quantity float64 `gorm:"type:numeric;default:0" json:"quantity"`
|
ReturnQuantity float64 `gorm:"type:numeric;default:0" json:"return_quantity"`
|
||||||
|
IssuedQuantity float64 `gorm:"type:numeric;default:0" json:"issued_quantity"`
|
||||||
Attachment string `gorm:"type:text;" json:"attachment"`
|
Attachment string `gorm:"type:text;" json:"attachment"`
|
||||||
|
|
||||||
InvReturnID uuid.UUID `gorm:"type:uuid;index;" json:"inv_return_id"`
|
InvReturnID uuid.UUID `gorm:"type:uuid;index;" json:"inv_return_id"`
|
||||||
|
|
|
||||||
|
|
@ -73,12 +73,12 @@ func MigrateFresh(db *gorm.DB) error {
|
||||||
// &entities.MAisleEntity{},
|
// &entities.MAisleEntity{},
|
||||||
// &entities.TAssignmentEntity{},
|
// &entities.TAssignmentEntity{},
|
||||||
// &entities.TAssignmentUserEntity{},
|
// &entities.TAssignmentUserEntity{},
|
||||||
&entities.TInventoryReceiptEntity{},
|
// &entities.TInventoryReceiptEntity{},
|
||||||
&entities.TInventoryReceiptLineEntity{},
|
// &entities.TInventoryReceiptLineEntity{},
|
||||||
&entities.TInventoryRequestEntity{},
|
// &entities.TInventoryRequestEntity{},
|
||||||
&entities.TInventoryRequestLineEntity{},
|
// &entities.TInventoryRequestLineEntity{},
|
||||||
&entities.TInventoryIssueEntity{},
|
// &entities.TInventoryIssueEntity{},
|
||||||
&entities.TInventoryIssueLineEntity{},
|
// &entities.TInventoryIssueLineEntity{},
|
||||||
&entities.TInventoryReturnEntity{},
|
&entities.TInventoryReturnEntity{},
|
||||||
&entities.TInventoryReturnLineEntity{},
|
&entities.TInventoryReturnLineEntity{},
|
||||||
// &entities.InventoryTransactionEntity{},
|
// &entities.InventoryTransactionEntity{},
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,9 @@ package dto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/Caknoooo/go-gin-clean-starter/database/entities"
|
"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/Caknoooo/go-gin-clean-starter/pkg/utils"
|
||||||
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -33,7 +35,8 @@ type InventoryReturnCreateRequest struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type InventoryReturnLineCreateRequest struct {
|
type InventoryReturnLineCreateRequest struct {
|
||||||
Quantity float64 `json:"quantity"`
|
ReturnQuantity float64 `json:"return_quantity"`
|
||||||
|
IssuedQuantity float64 `json:"issued_quantity"`
|
||||||
Attachment string `json:"attachment"`
|
Attachment string `json:"attachment"`
|
||||||
InvReturnID string `json:"inv_return_id"`
|
InvReturnID string `json:"inv_return_id"`
|
||||||
ProductID string `json:"product_id"`
|
ProductID string `json:"product_id"`
|
||||||
|
|
@ -49,7 +52,8 @@ type InventoryReturnUpdateRequest struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type InventoryReturnLineUpdateRequest struct {
|
type InventoryReturnLineUpdateRequest struct {
|
||||||
Quantity *float64 `json:"quantity"`
|
ReturnQuantity *float64 `json:"return_quantity"`
|
||||||
|
IssuedQuantity *float64 `json:"issued_quantity"`
|
||||||
Attachment *string `json:"attachment"`
|
Attachment *string `json:"attachment"`
|
||||||
InvReturnID *string `json:"inv_return_id"`
|
InvReturnID *string `json:"inv_return_id"`
|
||||||
ProductID *string `json:"product_id"`
|
ProductID *string `json:"product_id"`
|
||||||
|
|
@ -62,18 +66,33 @@ type InventoryReturnResponse struct {
|
||||||
DocumentDate string `json:"document_date"`
|
DocumentDate string `json:"document_date"`
|
||||||
Notes string `json:"notes"`
|
Notes string `json:"notes"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
InvIssueID string `json:"inv_issue_id"`
|
InvIssue InvReturnInvIssue `json:"inv_issue"`
|
||||||
ClientID string `json:"client_id"`
|
Client pkgdto.IdNameResponse `json:"client"`
|
||||||
ReturnLines []InventoryReturnLineResponse `json:"return_lines,omitempty"`
|
ReturnLines []InventoryReturnLineResponse `json:"return_lines,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type InvReturnInvIssue struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
DocumentNumber string `json:"document_number"`
|
||||||
|
DocumentDate string `json:"document_date"`
|
||||||
|
IssuerBy pkgdto.IdNameResponse `json:"issuer_by"`
|
||||||
|
}
|
||||||
|
|
||||||
type InventoryReturnLineResponse struct {
|
type InventoryReturnLineResponse struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Quantity float64 `json:"quantity"`
|
IssuedQuantity float64 `json:"issued_quantity"`
|
||||||
|
ReturnQuantity float64 `json:"return_quantity"`
|
||||||
Attachment string `json:"attachment"`
|
Attachment string `json:"attachment"`
|
||||||
InvReturnID string `json:"inv_return_id"`
|
InvReturnID string `json:"inv_return_id"`
|
||||||
ProductID string `json:"product_id"`
|
Product InvReturnProduct `json:"product"`
|
||||||
ClientID string `json:"client_id"`
|
Client pkgdto.IdNameResponse `json:"client"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type InvReturnProduct struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
RefNumber string `json:"ref_number"`
|
||||||
|
Uom pkgdto.IdNameResponse `json:"uom"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper untuk mapping entity ke response
|
// Helper untuk mapping entity ke response
|
||||||
|
|
@ -82,25 +101,77 @@ func ToInventoryReturnResponse(entity entities.TInventoryReturnEntity) Inventory
|
||||||
for _, line := range entity.ReturnLines {
|
for _, line := range entity.ReturnLines {
|
||||||
lines = append(lines, ToInventoryReturnLineResponse(line))
|
lines = append(lines, ToInventoryReturnLineResponse(line))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
client := pkgdto.IdNameResponse{}
|
||||||
|
if entity.Client.ID != uuid.Nil {
|
||||||
|
client = pkgdto.IdNameResponse{
|
||||||
|
ID: entity.Client.ID.String(),
|
||||||
|
Name: entity.Client.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
invIssue := InvReturnInvIssue{}
|
||||||
|
if entity.InvIssue.ID != uuid.Nil {
|
||||||
|
issuer := pkgdto.IdNameResponse{}
|
||||||
|
if entity.InvIssue.IssuerBy != uuid.Nil {
|
||||||
|
issuer = pkgdto.IdNameResponse{
|
||||||
|
ID: entity.InvIssue.IssuerBy.String(),
|
||||||
|
Name: "", // jika ada relasi user, isi nama user
|
||||||
|
}
|
||||||
|
}
|
||||||
|
invIssue = InvReturnInvIssue{
|
||||||
|
ID: entity.InvIssue.ID.String(),
|
||||||
|
DocumentNumber: entity.InvIssue.DocumentNumber,
|
||||||
|
DocumentDate: utils.DateTimeToString(entity.InvIssue.DocumentDate),
|
||||||
|
IssuerBy: issuer,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return InventoryReturnResponse{
|
return InventoryReturnResponse{
|
||||||
ID: entity.ID.String(),
|
ID: entity.ID.String(),
|
||||||
DocumentNumber: entity.DocumentNumber,
|
DocumentNumber: entity.DocumentNumber,
|
||||||
DocumentDate: utils.DateTimeToString(entity.DocumentDate),
|
DocumentDate: utils.DateTimeToString(entity.DocumentDate),
|
||||||
Notes: entity.Notes,
|
Notes: entity.Notes,
|
||||||
Status: entity.Status,
|
Status: entity.Status,
|
||||||
InvIssueID: entity.InvIssueID.String(),
|
InvIssue: invIssue,
|
||||||
ClientID: entity.ClientID.String(),
|
Client: client,
|
||||||
ReturnLines: lines,
|
ReturnLines: lines,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ToInventoryReturnLineResponse(line entities.TInventoryReturnLineEntity) InventoryReturnLineResponse {
|
func ToInventoryReturnLineResponse(line entities.TInventoryReturnLineEntity) InventoryReturnLineResponse {
|
||||||
|
client := pkgdto.IdNameResponse{}
|
||||||
|
if line.Client.ID != uuid.Nil {
|
||||||
|
client = pkgdto.IdNameResponse{
|
||||||
|
ID: line.Client.ID.String(),
|
||||||
|
Name: line.Client.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
product := InvReturnProduct{}
|
||||||
|
if line.Product.ID != uuid.Nil {
|
||||||
|
uom := pkgdto.IdNameResponse{}
|
||||||
|
if line.Product.Uom.ID != uuid.Nil {
|
||||||
|
uom = pkgdto.IdNameResponse{
|
||||||
|
ID: line.Product.Uom.ID.String(),
|
||||||
|
Name: line.Product.Uom.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
product = InvReturnProduct{
|
||||||
|
ID: line.Product.ID.String(),
|
||||||
|
Name: line.Product.Name,
|
||||||
|
RefNumber: line.Product.RefNumber,
|
||||||
|
Uom: uom,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return InventoryReturnLineResponse{
|
return InventoryReturnLineResponse{
|
||||||
ID: line.ID.String(),
|
ID: line.ID.String(),
|
||||||
Quantity: line.Quantity,
|
IssuedQuantity: line.IssuedQuantity, // pastikan field ini ada di entity
|
||||||
|
ReturnQuantity: line.ReturnQuantity, // pastikan field ini ada di entity
|
||||||
Attachment: line.Attachment,
|
Attachment: line.Attachment,
|
||||||
InvReturnID: line.InvReturnID.String(),
|
InvReturnID: line.InvReturnID.String(),
|
||||||
ProductID: line.ProductID.String(),
|
Product: product,
|
||||||
ClientID: line.ClientID.String(),
|
Client: client,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,15 +51,17 @@ func (s *inventoryReturnService) UpdateLine(ctx context.Context, lineId string,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return dtodomain.InventoryReturnLineResponse{}, err
|
return dtodomain.InventoryReturnLineResponse{}, err
|
||||||
}
|
}
|
||||||
|
if req.ReturnQuantity != nil {
|
||||||
if req.Quantity != nil {
|
|
||||||
if product.IsReturnable {
|
if product.IsReturnable {
|
||||||
return dtodomain.InventoryReturnLineResponse{},
|
return dtodomain.InventoryReturnLineResponse{},
|
||||||
fmt.Errorf("product is not returnable, quantity cannot be updated")
|
fmt.Errorf("product is not returnable, quantity cannot be updated")
|
||||||
} else {
|
} else {
|
||||||
line.Quantity = *req.Quantity
|
line.ReturnQuantity = *req.ReturnQuantity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if req.IssuedQuantity != nil {
|
||||||
|
line.IssuedQuantity = *req.IssuedQuantity
|
||||||
|
}
|
||||||
if req.Attachment != nil {
|
if req.Attachment != nil {
|
||||||
line.Attachment = *req.Attachment
|
line.Attachment = *req.Attachment
|
||||||
}
|
}
|
||||||
|
|
@ -133,7 +135,8 @@ func (s *inventoryReturnService) Create(ctx context.Context, req dtodomain.Inven
|
||||||
qty = issueLine.IssuedQuantity
|
qty = issueLine.IssuedQuantity
|
||||||
}
|
}
|
||||||
lines = append(lines, entities.TInventoryReturnLineEntity{
|
lines = append(lines, entities.TInventoryReturnLineEntity{
|
||||||
Quantity: qty,
|
ReturnQuantity: qty,
|
||||||
|
IssuedQuantity: issueLine.IssuedQuantity,
|
||||||
Attachment: "", // isi sesuai kebutuhan
|
Attachment: "", // isi sesuai kebutuhan
|
||||||
InvReturnID: created.ID,
|
InvReturnID: created.ID,
|
||||||
ProductID: issueLine.ProductID,
|
ProductID: issueLine.ProductID,
|
||||||
|
|
@ -237,7 +240,8 @@ func (s *inventoryReturnService) CreateLine(ctx context.Context, returnId string
|
||||||
return dtodomain.InventoryReturnLineResponse{}, err
|
return dtodomain.InventoryReturnLineResponse{}, err
|
||||||
}
|
}
|
||||||
line := entities.TInventoryReturnLineEntity{
|
line := entities.TInventoryReturnLineEntity{
|
||||||
Quantity: req.Quantity,
|
ReturnQuantity: req.ReturnQuantity,
|
||||||
|
IssuedQuantity: req.IssuedQuantity,
|
||||||
Attachment: req.Attachment,
|
Attachment: req.Attachment,
|
||||||
InvReturnID: invReturnUUID,
|
InvReturnID: invReturnUUID,
|
||||||
ProductID: productUUID,
|
ProductID: productUUID,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue