Skip to content

Commit

Permalink
fix: create invoice
Browse files Browse the repository at this point in the history
  • Loading branch information
NLNM-0-0 committed Jan 13, 2024
1 parent c0742f2 commit e2b510d
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 51 deletions.
16 changes: 8 additions & 8 deletions backend/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5089,6 +5089,14 @@ const docTemplate = `{
"invoicemodel.Invoice": {
"type": "object",
"properties": {
"amountPriceUsePoint": {
"type": "integer",
"example": 20000
},
"amountReceived": {
"type": "integer",
"example": 100000
},
"createdAt": {
"type": "string",
"example": "2023-12-03T15:02:19.62113565Z"
Expand Down Expand Up @@ -5117,14 +5125,6 @@ const docTemplate = `{
"type": "integer",
"example": 20000
},
"qtyPriceUsePoint": {
"type": "integer",
"example": 20000
},
"qtyReceived": {
"type": "integer",
"example": 100000
},
"totalPrice": {
"type": "integer",
"example": 120000
Expand Down
16 changes: 8 additions & 8 deletions backend/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -5083,6 +5083,14 @@
"invoicemodel.Invoice": {
"type": "object",
"properties": {
"amountPriceUsePoint": {
"type": "integer",
"example": 20000
},
"amountReceived": {
"type": "integer",
"example": 100000
},
"createdAt": {
"type": "string",
"example": "2023-12-03T15:02:19.62113565Z"
Expand Down Expand Up @@ -5111,14 +5119,6 @@
"type": "integer",
"example": 20000
},
"qtyPriceUsePoint": {
"type": "integer",
"example": 20000
},
"qtyReceived": {
"type": "integer",
"example": 100000
},
"totalPrice": {
"type": "integer",
"example": 120000
Expand Down
12 changes: 6 additions & 6 deletions backend/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,12 @@ definitions:
type: object
invoicemodel.Invoice:
properties:
amountPriceUsePoint:
example: 20000
type: integer
amountReceived:
example: 100000
type: integer
createdAt:
example: "2023-12-03T15:02:19.62113565Z"
type: string
Expand All @@ -1054,12 +1060,6 @@ definitions:
pointUse:
example: 20000
type: integer
qtyPriceUsePoint:
example: 20000
type: integer
qtyReceived:
example: 100000
type: integer
totalPrice:
example: 120000
type: integer
Expand Down
2 changes: 1 addition & 1 deletion backend/module/dashboard/dashboardrepo/see_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (repo *seeDashboardRepo) SeeDashboard(
for _, invoice := range allInvoices {
chartSale := dashboardmodel.ChartComponent{
Time: *invoice.CreatedAt,
Value: invoice.QuantityReceived - invoice.TotalImportPrice,
Value: invoice.AmountReceived - invoice.TotalImportPrice,
}
listProfit = append(listProfit, chartSale)

Expand Down
8 changes: 4 additions & 4 deletions backend/module/invoice/invoicebiz/create_invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ func (biz *createInvoiceBiz) CreateInvoice(
}

priceUseForPointInt := common.RoundToInt(priceUseForPoint)
data.QuantityReceived = data.TotalPrice - priceUseForPointInt
data.QuantityPriceUseForPoint = priceUseForPointInt
data.AmountReceived = data.TotalPrice - priceUseForPointInt
data.AmountPriceUseForPoint = priceUseForPointInt

pointReceive := common.RoundToInt(float32(data.QuantityReceived) * general.AccumulatePointPercent)
pointReceive := common.RoundToInt(float32(data.AmountReceived) * general.AccumulatePointPercent)

data.PointUse = pointUse
data.PointReceive = pointReceive
Expand All @@ -112,7 +112,7 @@ func (biz *createInvoiceBiz) CreateInvoice(
}

} else {
data.QuantityReceived = data.TotalPrice
data.AmountReceived = data.TotalPrice
if data.IsUsePoint {
return invoicemodel.ErrInvoiceNotHaveCustomerToUsePoint
}
Expand Down
26 changes: 13 additions & 13 deletions backend/module/invoice/invoicemodel/invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ import (
)

type Invoice struct {
Id string `json:"id" gorm:"column:id;" example:"123"`
CustomerId string `json:"-" gorm:"column:customerId;"`
Customer *SimpleCustomer `json:"customer" gorm:"foreignKey:CustomerId;references:Id"`
TotalPrice int `json:"totalPrice" gorm:"column:totalPrice;" example:"120000"`
TotalImportPrice int `json:"-" gorm:"column:totalImportPrice;" example:"100000"`
QuantityReceived int `json:"qtyReceived" gorm:"column:qtyReceived" example:"100000"`
QuantityPriceUseForPoint int `json:"qtyPriceUsePoint" gorm:"column:qtyPriceUsePoint" example:"20000"`
PointUse int `json:"pointUse" gorm:"column:pointUse;" example:"20000"`
PointReceive int `json:"pointReceive" gorm:"column:pointReceive;" example:"10000"`
CreatedBy string `json:"-" gorm:"column:createdBy;" example:"admin"`
CreatedByUser usermodel.SimpleUser `json:"createdBy" gorm:"foreignKey:CreatedBy"`
CreatedAt *time.Time `json:"createdAt" gorm:"column:createdAt;" example:"2023-12-03T15:02:19.62113565Z"`
Details []invoicedetailmodel.InvoiceDetail `json:"details"`
Id string `json:"id" gorm:"column:id;" example:"123"`
CustomerId string `json:"-" gorm:"column:customerId;"`
Customer *SimpleCustomer `json:"customer" gorm:"foreignKey:CustomerId;references:Id"`
TotalPrice int `json:"totalPrice" gorm:"column:totalPrice;" example:"120000"`
TotalImportPrice int `json:"-" gorm:"column:totalImportPrice;" example:"100000"`
AmountReceived int `json:"amountReceived" gorm:"column:amountReceived" example:"100000"`
AmountPriceUsePoint int `json:"amountPriceUsePoint" gorm:"column:amountPriceUsePoint" example:"20000"`
PointUse int `json:"pointUse" gorm:"column:pointUse;" example:"20000"`
PointReceive int `json:"pointReceive" gorm:"column:pointReceive;" example:"10000"`
CreatedBy string `json:"-" gorm:"column:createdBy;" example:"admin"`
CreatedByUser usermodel.SimpleUser `json:"createdBy" gorm:"foreignKey:CreatedBy"`
CreatedAt *time.Time `json:"createdAt" gorm:"column:createdAt;" example:"2023-12-03T15:02:19.62113565Z"`
Details []invoicedetailmodel.InvoiceDetail `json:"details"`
}

func (*Invoice) TableName() string {
Expand Down
22 changes: 11 additions & 11 deletions backend/module/invoice/invoicemodel/req_create_invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import (
)

type ReqCreateInvoice struct {
Id string `json:"-" gorm:"column:id;"`
CustomerId string `json:"customerId" gorm:"column:customerId;"`
IsUsePoint bool `json:"isUsePoint" gorm:"-"`
TotalPrice int `json:"-" gorm:"column:totalPrice;"`
TotalImportPrice int `json:"-" gorm:"column:totalImportPrice;"`
QuantityReceived int `json:"-" gorm:"column:qtyReceived"`
QuantityPriceUseForPoint int `json:"-" gorm:"column:qtyPriceUsePoint"`
PointUse int `json:"-" gorm:"column:pointUse;"`
PointReceive int `json:"-" gorm:"column:pointReceive;"`
CreatedBy string `json:"-" gorm:"column:createdBy;"`
InvoiceDetails []invoicedetailmodel.ReqCreateInvoiceDetail `json:"details" gorm:"-"`
Id string `json:"-" gorm:"column:id;"`
CustomerId string `json:"customerId" gorm:"column:customerId;"`
IsUsePoint bool `json:"isUsePoint" gorm:"-"`
TotalPrice int `json:"-" gorm:"column:totalPrice;"`
TotalImportPrice int `json:"-" gorm:"column:totalImportPrice;"`
AmountReceived int `json:"-" gorm:"column:amountReceived"`
AmountPriceUseForPoint int `json:"-" gorm:"column:amountPriceUsePoint"`
PointUse int `json:"-" gorm:"column:pointUse;"`
PointReceive int `json:"-" gorm:"column:pointReceive;"`
CreatedBy string `json:"-" gorm:"column:createdBy;"`
InvoiceDetails []invoicedetailmodel.ReqCreateInvoiceDetail `json:"details" gorm:"-"`
}

func (*ReqCreateInvoice) TableName() string {
Expand Down

0 comments on commit e2b510d

Please sign in to comment.