From c42cff043c049c0b12aca91bca31cd0799ea6f7a Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期五, 11 八月 2023 13:54:19 +0800 Subject: [PATCH] 增删改收款单时更改销售明细和服务合同应收金额 --- model/serviceContract.go | 37 ++ constvar/receipt.go | 13 model/interface.go | 8 model/salesDetails.go | 42 +++ docs/swagger.yaml | 153 ++++++++++ docs/docs.go | 236 ++++++++++++++++ docs/swagger.json | 236 ++++++++++++++++ service/receipt.go | 62 +++ model/receipt.go | 25 + 9 files changed, 783 insertions(+), 29 deletions(-) diff --git a/constvar/receipt.go b/constvar/receipt.go index df8e86e..d0d04a8 100644 --- a/constvar/receipt.go +++ b/constvar/receipt.go @@ -1,4 +1,5 @@ package constvar + type ReceiptQueryClass string const ( @@ -8,5 +9,15 @@ type ReceiptKeywordType string const ( - ReceiptKeywordCustomerName ReceiptKeywordType = "" + ReceiptKeywordCustomerName ReceiptKeywordType = "" +) + +type ReceiptSourceType int //鏉ユ簮绫诲瀷锛�1閿�鍞槑缁嗗崟2鏈嶅姟鍚堝悓3閿�鍞彂绁�4鏀舵璁″垝5鍑哄簱鍗曪級 + +const ( + ReceiptSourceTypeSalesDetails ReceiptSourceType = 1 + ReceiptSourceTypeServiceContract ReceiptSourceType = 2 + ReceiptSourceTypeInvoice ReceiptSourceType = 3 + ReceiptSourceTypeCollectionPlan ReceiptSourceType = 4 + ReceiptSourceTypeChuKuDan ReceiptSourceType = 5 ) diff --git a/docs/docs.go b/docs/docs.go index ab95e71..e018b2a 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -8341,6 +8341,169 @@ } } }, + "/api/serviceOrderStatus/add": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "鏈嶅姟鍗曠姸鎬�" + ], + "summary": "娣诲姞鏈嶅姟鍗曠姸鎬�", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.AddServiceOrderStatus" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/contextx.Response" + } + } + } + } + }, + "/api/serviceOrderStatus/delete/{id}": { + "delete": { + "produces": [ + "application/json" + ], + "tags": [ + "鏈嶅姟鍗曠姸鎬�" + ], + "summary": "鍒犻櫎鏈嶅姟鍗曠姸鎬�", + "parameters": [ + { + "type": "integer", + "description": "鏌ヨ鍙傛暟", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/contextx.Response" + } + } + } + } + }, + "/api/serviceOrderStatus/list": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "鏈嶅姟鍗曠姸鎬�" + ], + "summary": "鑾峰彇鏈嶅姟鍗曠姸鎬佸垪琛�", + "parameters": [ + { + "type": "string", + "name": "keyword", + "in": "query" + }, + { + "enum": [ + "" + ], + "type": "string", + "x-enum-varnames": [ + "ServiceOrderStatusKeywordCustomerName" + ], + "name": "keywordType", + "in": "query" + }, + { + "type": "integer", + "description": "椤电爜", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "description": "姣忛〉澶у皬", + "name": "pageSize", + "in": "query" + }, + { + "enum": [ + "" + ], + "type": "string", + "x-enum-varnames": [ + "ServiceOrderStatusQueryClassExpireLessThen60Days" + ], + "name": "queryClass", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/response.ListResponse" + }, + { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/model.ServiceOrderStatus" + } + } + } + } + ] + } + } + } + } + }, + "/api/serviceOrderStatus/update": { + "put": { + "produces": [ + "application/json" + ], + "tags": [ + "鏈嶅姟鍗曠姸鎬�" + ], + "summary": "鏇存柊鏈嶅姟鍗曠姸鎬�", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.UpdateServiceOrderStatus" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/contextx.Response" + } + } + } + } + }, "/api/serviceType/add": { "post": { "produces": [ @@ -10008,6 +10171,24 @@ "ServiceOrderQueryClassExpireLessThen60Days" ] }, + "constvar.ServiceOrderStatusKeywordType": { + "type": "string", + "enum": [ + "" + ], + "x-enum-varnames": [ + "ServiceOrderStatusKeywordCustomerName" + ] + }, + "constvar.ServiceOrderStatusQueryClass": { + "type": "string", + "enum": [ + "" + ], + "x-enum-varnames": [ + "ServiceOrderStatusQueryClassExpireLessThen60Days" + ] + }, "constvar.UserType": { "type": "integer", "enum": [ @@ -11050,6 +11231,10 @@ "model.Receipt": { "type": "object", "properties": { + "amount": { + "description": "鏀舵閲戦", + "type": "string" + }, "bankAccountId": { "description": "璐︽埛id", "type": "integer" @@ -11660,6 +11845,9 @@ "clientId": { "type": "integer" }, + "contact": { + "$ref": "#/definitions/model.Contact" + }, "contactId": { "type": "integer" }, @@ -11862,11 +12050,11 @@ "type": "string" }, "carFare": { - "description": "浜ら�氳垂", + "description": "浜ら�氳垂 // 浜ら�氳垂", "type": "number" }, "chargeAmount": { - "description": "鏀惰垂閲戦", + "description": "鏀惰垂閲戦 // 鏀惰垂閲戦", "type": "number" }, "client": { @@ -11959,6 +12147,9 @@ "description": "鏈嶅姟鍗曠紪鍙�", "type": "string" }, + "serviceOrderStatus": { + "$ref": "#/definitions/model.ServiceOrderStatus" + }, "serviceType": { "$ref": "#/definitions/model.ServiceType" }, @@ -11991,6 +12182,17 @@ "timeSpentId": { "description": "鑺辫垂鏃堕棿", "type": "integer" + } + } + }, + "model.ServiceOrderStatus": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" } } }, @@ -12858,6 +13060,10 @@ "request.AddReceipt": { "type": "object", "properties": { + "amount": { + "description": "鏀舵閲戦", + "type": "string" + }, "bankAccountId": { "description": "璐︽埛id", "type": "integer" @@ -13601,6 +13807,17 @@ "timeSpentId": { "description": "鑺辫垂鏃堕棿", "type": "integer" + } + } + }, + "request.AddServiceOrderStatus": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" } } }, @@ -15703,6 +15920,10 @@ "request.UpdateReceipt": { "type": "object", "properties": { + "amount": { + "description": "鏀舵閲戦", + "type": "string" + }, "bankAccountId": { "description": "璐︽埛id", "type": "integer" @@ -16698,6 +16919,17 @@ } } }, + "request.UpdateServiceOrderStatus": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, "request.UpdateServiceType": { "type": "object", "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index ee2af69..ed88e15 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -8329,6 +8329,169 @@ } } }, + "/api/serviceOrderStatus/add": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "鏈嶅姟鍗曠姸鎬�" + ], + "summary": "娣诲姞鏈嶅姟鍗曠姸鎬�", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.AddServiceOrderStatus" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/contextx.Response" + } + } + } + } + }, + "/api/serviceOrderStatus/delete/{id}": { + "delete": { + "produces": [ + "application/json" + ], + "tags": [ + "鏈嶅姟鍗曠姸鎬�" + ], + "summary": "鍒犻櫎鏈嶅姟鍗曠姸鎬�", + "parameters": [ + { + "type": "integer", + "description": "鏌ヨ鍙傛暟", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/contextx.Response" + } + } + } + } + }, + "/api/serviceOrderStatus/list": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "鏈嶅姟鍗曠姸鎬�" + ], + "summary": "鑾峰彇鏈嶅姟鍗曠姸鎬佸垪琛�", + "parameters": [ + { + "type": "string", + "name": "keyword", + "in": "query" + }, + { + "enum": [ + "" + ], + "type": "string", + "x-enum-varnames": [ + "ServiceOrderStatusKeywordCustomerName" + ], + "name": "keywordType", + "in": "query" + }, + { + "type": "integer", + "description": "椤电爜", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "description": "姣忛〉澶у皬", + "name": "pageSize", + "in": "query" + }, + { + "enum": [ + "" + ], + "type": "string", + "x-enum-varnames": [ + "ServiceOrderStatusQueryClassExpireLessThen60Days" + ], + "name": "queryClass", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/response.ListResponse" + }, + { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/model.ServiceOrderStatus" + } + } + } + } + ] + } + } + } + } + }, + "/api/serviceOrderStatus/update": { + "put": { + "produces": [ + "application/json" + ], + "tags": [ + "鏈嶅姟鍗曠姸鎬�" + ], + "summary": "鏇存柊鏈嶅姟鍗曠姸鎬�", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.UpdateServiceOrderStatus" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/contextx.Response" + } + } + } + } + }, "/api/serviceType/add": { "post": { "produces": [ @@ -9996,6 +10159,24 @@ "ServiceOrderQueryClassExpireLessThen60Days" ] }, + "constvar.ServiceOrderStatusKeywordType": { + "type": "string", + "enum": [ + "" + ], + "x-enum-varnames": [ + "ServiceOrderStatusKeywordCustomerName" + ] + }, + "constvar.ServiceOrderStatusQueryClass": { + "type": "string", + "enum": [ + "" + ], + "x-enum-varnames": [ + "ServiceOrderStatusQueryClassExpireLessThen60Days" + ] + }, "constvar.UserType": { "type": "integer", "enum": [ @@ -11038,6 +11219,10 @@ "model.Receipt": { "type": "object", "properties": { + "amount": { + "description": "鏀舵閲戦", + "type": "string" + }, "bankAccountId": { "description": "璐︽埛id", "type": "integer" @@ -11648,6 +11833,9 @@ "clientId": { "type": "integer" }, + "contact": { + "$ref": "#/definitions/model.Contact" + }, "contactId": { "type": "integer" }, @@ -11850,11 +12038,11 @@ "type": "string" }, "carFare": { - "description": "浜ら�氳垂", + "description": "浜ら�氳垂 // 浜ら�氳垂", "type": "number" }, "chargeAmount": { - "description": "鏀惰垂閲戦", + "description": "鏀惰垂閲戦 // 鏀惰垂閲戦", "type": "number" }, "client": { @@ -11947,6 +12135,9 @@ "description": "鏈嶅姟鍗曠紪鍙�", "type": "string" }, + "serviceOrderStatus": { + "$ref": "#/definitions/model.ServiceOrderStatus" + }, "serviceType": { "$ref": "#/definitions/model.ServiceType" }, @@ -11979,6 +12170,17 @@ "timeSpentId": { "description": "鑺辫垂鏃堕棿", "type": "integer" + } + } + }, + "model.ServiceOrderStatus": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" } } }, @@ -12846,6 +13048,10 @@ "request.AddReceipt": { "type": "object", "properties": { + "amount": { + "description": "鏀舵閲戦", + "type": "string" + }, "bankAccountId": { "description": "璐︽埛id", "type": "integer" @@ -13589,6 +13795,17 @@ "timeSpentId": { "description": "鑺辫垂鏃堕棿", "type": "integer" + } + } + }, + "request.AddServiceOrderStatus": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" } } }, @@ -15691,6 +15908,10 @@ "request.UpdateReceipt": { "type": "object", "properties": { + "amount": { + "description": "鏀舵閲戦", + "type": "string" + }, "bankAccountId": { "description": "璐︽埛id", "type": "integer" @@ -16686,6 +16907,17 @@ } } }, + "request.UpdateServiceOrderStatus": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, "request.UpdateServiceType": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 2a99e5b..bd69224 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -264,6 +264,18 @@ type: string x-enum-varnames: - ServiceOrderQueryClassExpireLessThen60Days + constvar.ServiceOrderStatusKeywordType: + enum: + - "" + type: string + x-enum-varnames: + - ServiceOrderStatusKeywordCustomerName + constvar.ServiceOrderStatusQueryClass: + enum: + - "" + type: string + x-enum-varnames: + - ServiceOrderStatusQueryClassExpireLessThen60Days constvar.UserType: enum: - 1 @@ -951,6 +963,9 @@ type: object model.Receipt: properties: + amount: + description: 鏀舵閲戦 + type: string bankAccountId: description: 璐︽埛id type: integer @@ -1360,6 +1375,8 @@ $ref: '#/definitions/model.Client' clientId: type: integer + contact: + $ref: '#/definitions/model.Contact' contactId: type: integer endTime: @@ -1494,10 +1511,12 @@ description: 棰勭害涓婇棬鏃堕棿 type: string carFare: - description: 浜ら�氳垂 + description: 浜ら�氳垂 // + 浜ら�氳垂 type: number chargeAmount: - description: 鏀惰垂閲戦 + description: 鏀惰垂閲戦 // + 鏀惰垂閲戦 type: number client: $ref: '#/definitions/model.Client' @@ -1564,6 +1583,8 @@ serviceNumber: description: 鏈嶅姟鍗曠紪鍙� type: string + serviceOrderStatus: + $ref: '#/definitions/model.ServiceOrderStatus' serviceType: $ref: '#/definitions/model.ServiceType' serviceTypeId: @@ -1588,6 +1609,13 @@ timeSpentId: description: 鑺辫垂鏃堕棿 type: integer + type: object + model.ServiceOrderStatus: + properties: + id: + type: integer + name: + type: string type: object model.ServiceType: properties: @@ -2168,6 +2196,9 @@ type: object request.AddReceipt: properties: + amount: + description: 鏀舵閲戦 + type: string bankAccountId: description: 璐︽埛id type: integer @@ -2678,6 +2709,13 @@ timeSpentId: description: 鑺辫垂鏃堕棿 type: integer + type: object + request.AddServiceOrderStatus: + properties: + id: + type: integer + name: + type: string type: object request.AddServiceType: properties: @@ -4108,6 +4146,9 @@ type: object request.UpdateReceipt: properties: + amount: + description: 鏀舵閲戦 + type: string bankAccountId: description: 璐︽埛id type: integer @@ -4786,6 +4827,13 @@ timeSpentId: description: 鑺辫垂鏃堕棿 type: integer + type: object + request.UpdateServiceOrderStatus: + properties: + id: + type: integer + name: + type: string type: object request.UpdateServiceType: properties: @@ -10615,6 +10663,107 @@ summary: 鏇存柊鏈嶅姟鍗� tags: - 鏈嶅姟鍗曠鐞� + /api/serviceOrderStatus/add: + post: + parameters: + - description: 鏌ヨ鍙傛暟 + in: body + name: object + required: true + schema: + $ref: '#/definitions/request.AddServiceOrderStatus' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/contextx.Response' + summary: 娣诲姞鏈嶅姟鍗曠姸鎬� + tags: + - 鏈嶅姟鍗曠姸鎬� + /api/serviceOrderStatus/delete/{id}: + delete: + parameters: + - description: 鏌ヨ鍙傛暟 + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/contextx.Response' + summary: 鍒犻櫎鏈嶅姟鍗曠姸鎬� + tags: + - 鏈嶅姟鍗曠姸鎬� + /api/serviceOrderStatus/list: + get: + parameters: + - in: query + name: keyword + type: string + - enum: + - "" + in: query + name: keywordType + type: string + x-enum-varnames: + - ServiceOrderStatusKeywordCustomerName + - description: 椤电爜 + in: query + name: page + type: integer + - description: 姣忛〉澶у皬 + in: query + name: pageSize + type: integer + - enum: + - "" + in: query + name: queryClass + type: string + x-enum-varnames: + - ServiceOrderStatusQueryClassExpireLessThen60Days + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/response.ListResponse' + - properties: + data: + items: + $ref: '#/definitions/model.ServiceOrderStatus' + type: array + type: object + summary: 鑾峰彇鏈嶅姟鍗曠姸鎬佸垪琛� + tags: + - 鏈嶅姟鍗曠姸鎬� + /api/serviceOrderStatus/update: + put: + parameters: + - description: 鏌ヨ鍙傛暟 + in: body + name: object + required: true + schema: + $ref: '#/definitions/request.UpdateServiceOrderStatus' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/contextx.Response' + summary: 鏇存柊鏈嶅姟鍗曠姸鎬� + tags: + - 鏈嶅姟鍗曠姸鎬� /api/serviceType/add: post: parameters: diff --git a/model/interface.go b/model/interface.go index c7b70d4..2b8847d 100644 --- a/model/interface.go +++ b/model/interface.go @@ -6,8 +6,8 @@ ) type MoneyAdder interface { - AmountReceivableAdd(*gorm.DB, decimal.Decimal) - AmountReceivedAdd(*gorm.DB, decimal.Decimal) - AmountInvoicedAdd(*gorm.DB, decimal.Decimal) - AmountNotInvoicedAdd(*gorm.DB, decimal.Decimal) + AmountReceivableAdd(tx *gorm.DB, id int, amount decimal.Decimal) error + AmountReceivedAdd(tx *gorm.DB, id int, amount decimal.Decimal) error + AmountInvoicedAdd(tx *gorm.DB, id int, amount decimal.Decimal) error + AmountNotInvoicedAdd(tx *gorm.DB, id int, amount decimal.Decimal) error } diff --git a/model/receipt.go b/model/receipt.go index 60d1d2a..bd862ba 100644 --- a/model/receipt.go +++ b/model/receipt.go @@ -5,23 +5,26 @@ "aps_crm/pkg/mysqlx" "errors" "fmt" + "github.com/shopspring/decimal" "gorm.io/gorm" ) type ( // Receipt 鏀舵鍗� Receipt struct { - Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` - ClientId int `gorm:"client_id" json:"clientId"` // 瀹㈡埛id - SourceType int `gorm:"source_type" json:"sourceType"` // 鏉ユ簮绫诲瀷锛�1閿�鍞槑缁嗗崟2鏈嶅姟鍚堝悓3閿�鍞彂绁�4鏀舵璁″垝5鍑哄簱鍗曪級 - SourceId int `gorm:"source_id" json:"sourceId"` // 婧愬崟id - PrincipalId int `gorm:"principal_id" json:"principalId"` // 璐熻矗浜篿d - ReceiptDate string `gorm:"receipt_date" json:"receiptDate"` // 鏀舵鏃ユ湡 - MoneyType string `gorm:"money_type" json:"moneyType"` // 甯佺 - PaymentTypeId int `gorm:"payment_type_id" json:"paymentTypeId"` // 鏀舵鏂瑰紡ID - BankAccountId int `gorm:"bank_account_id" json:"bankAccountId"` // 璐︽埛id - Remark string `gorm:"remark" json:"remark"` // 澶囨敞 - FileId int `gorm:"file_id" json:"fileId"` // 闄勪欢id + Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` + ClientId int `gorm:"column:client_id;type:int;not null;default 0;comment:瀹㈡埛id" json:"clientId"` // 瀹㈡埛id + SourceType constvar.ReceiptSourceType `gorm:"column:source_type;type:int;not null;default 0;comment:鏉ユ簮绫诲瀷锛�1閿�鍞槑缁嗗崟2鏈嶅姟鍚堝悓3閿�鍞彂绁�4鏀舵璁″垝5鍑哄簱鍗曪級" json:"sourceType"` // 鏉ユ簮绫诲瀷锛�1閿�鍞槑缁嗗崟2鏈嶅姟鍚堝悓3閿�鍞彂绁�4鏀舵璁″垝5鍑哄簱鍗曪級 + SourceId int `gorm:"column:source_id;type:int;not null;default 0;comment:婧愬崟id " json:"sourceId"` // 婧愬崟id + PrincipalId int `gorm:"column:principal_id;type:int;not null;default 0;comment:璐熻矗浜篿d" json:"principalId"` // 璐熻矗浜篿d + ReceiptDate string `gorm:"column:receipt_date;type:varchar(255);not null;default '';comment:鏀舵鏃ユ湡" json:"receiptDate"` // 鏀舵鏃ユ湡 + MoneyType string `gorm:"column:money_type;type:varchar(255);not null;default '';comment:甯佺" json:"moneyType"` // 甯佺 + Amount decimal.Decimal `gorm:"column:amount;type:decimal(12,2);not null;default '0.00';comment:鏀舵閲戦" json:"amount"` // 鏀舵閲戦 + PaymentTypeId int `gorm:"column:payment_type_id;type:int;not null;default 0;comment:鏀舵鏂瑰紡ID" json:"paymentTypeId"` // 鏀舵鏂瑰紡ID + BankAccountId int `gorm:"column:bank_account_id;type:int;not null;default 0;comment:璐︽埛id" json:"bankAccountId"` // 璐︽埛id + Remark string `gorm:"column:remark;type:varchar(255);not null;default '';comment:澶囨敞" json:"remark"` // 澶囨敞 + FileId int `gorm:"column:file_id;type:int;not null;default 0;comment:闄勪欢id" json:"fileId"` // 闄勪欢id + gorm.Model `json:"-"` } // ReceiptSearch 鏀舵鍗曟悳绱㈡潯浠� diff --git a/model/salesDetails.go b/model/salesDetails.go index ff92423..301794b 100644 --- a/model/salesDetails.go +++ b/model/salesDetails.go @@ -173,3 +173,45 @@ return nil } + +func (slf *SalesDetailsSearch) SetOrm(tx *gorm.DB) *SalesDetailsSearch { + slf.Orm = tx + return slf +} + +func (slf *SalesDetailsSearch) AmountReceivableAdd(tx *gorm.DB, id int, amount decimal.Decimal) error { + slf.Orm = tx + record, err := slf.SetId(id).First() + if err != nil { + return err + } + amount = record.AmountReceivable.Add(amount) + return slf.UpdateByMap(map[string]interface{}{"amount_receivable": amount}) +} +func (slf *SalesDetailsSearch) AmountReceivedAdd(tx *gorm.DB, id int, amount decimal.Decimal) error { + slf.Orm = tx + record, err := slf.SetId(id).First() + if err != nil { + return err + } + amount = record.AmountReceived.Add(amount) + return slf.UpdateByMap(map[string]interface{}{"amount_received": amount}) +} +func (slf *SalesDetailsSearch) AmountInvoicedAdd(tx *gorm.DB, id int, amount decimal.Decimal) error { + slf.Orm = tx + record, err := slf.SetId(id).First() + if err != nil { + return err + } + amount = record.AmountInvoiced.Add(amount) + return slf.UpdateByMap(map[string]interface{}{"amount_invoiced": amount}) +} +func (slf *SalesDetailsSearch) AmountNotInvoicedAdd(tx *gorm.DB, id int, amount decimal.Decimal) error { + slf.Orm = tx + record, err := slf.SetId(id).First() + if err != nil { + return err + } + amount = record.AmountUnInvoiced.Add(amount) + return slf.UpdateByMap(map[string]interface{}{"amount_not_invoiced": amount}) +} diff --git a/model/serviceContract.go b/model/serviceContract.go index 5eff55e..93ec9c8 100644 --- a/model/serviceContract.go +++ b/model/serviceContract.go @@ -216,3 +216,40 @@ return record, nil } + +func (slf *ServiceContractSearch) AmountReceivableAdd(tx *gorm.DB, id int, amount decimal.Decimal) error { + slf.Orm = tx + record, err := slf.SetId(id).First() + if err != nil { + return err + } + amount = record.AmountReceivable.Add(amount) + return slf.UpdateByMap(map[string]interface{}{"amount_receivable": amount}) +} +func (slf *ServiceContractSearch) AmountReceivedAdd(tx *gorm.DB, id int, amount decimal.Decimal) error { + slf.Orm = tx + record, err := slf.SetId(id).First() + if err != nil { + return err + } + amount = record.AmountReceived.Add(amount) + return slf.UpdateByMap(map[string]interface{}{"amount_received": amount}) +} +func (slf *ServiceContractSearch) AmountInvoicedAdd(tx *gorm.DB, id int, amount decimal.Decimal) error { + slf.Orm = tx + record, err := slf.SetId(id).First() + if err != nil { + return err + } + amount = record.AmountInvoiced.Add(amount) + return slf.UpdateByMap(map[string]interface{}{"amount_invoiced": amount}) +} +func (slf *ServiceContractSearch) AmountNotInvoicedAdd(tx *gorm.DB, id int, amount decimal.Decimal) error { + slf.Orm = tx + record, err := slf.SetId(id).First() + if err != nil { + return err + } + amount = record.AmountUnInvoiced.Add(amount) + return slf.UpdateByMap(map[string]interface{}{"amount_not_invoiced": amount}) +} diff --git a/service/receipt.go b/service/receipt.go index 834c6df..386beb5 100644 --- a/service/receipt.go +++ b/service/receipt.go @@ -1,9 +1,12 @@ package service import ( + "aps_crm/constvar" "aps_crm/model" "aps_crm/model/request" "aps_crm/pkg/ecode" + "github.com/shopspring/decimal" + "gorm.io/gorm" ) type ReceiptService struct{} @@ -13,16 +16,45 @@ } func (ReceiptService) AddReceipt(receipt *model.Receipt) int { - err := model.NewReceiptSearch().Create(receipt) + var moneyAdder model.MoneyAdder + switch receipt.SourceType { + case constvar.ReceiptSourceTypeSalesDetails: + moneyAdder = model.NewSalesDetailsSearch() + case constvar.ReceiptSourceTypeServiceContract: + moneyAdder = model.NewServiceContractSearch() + } + err := model.WithTransaction(func(db *gorm.DB) error { + err := model.NewReceiptSearch().SetOrm(db).Create(receipt) + if err != nil { + return err + } + return moneyAdder.AmountReceivableAdd(db, receipt.SourceId, decimal.Zero.Sub(receipt.Amount).Round(2)) + }) if err != nil { return ecode.DBErr } - return ecode.OK } func (ReceiptService) DeleteReceipt(id int) int { - err := model.NewReceiptSearch().SetId(id).Delete() + receipt, err := model.NewReceiptSearch().SetId(id).First() + if err != nil { + return ecode.DBErr + } + var moneyAdder model.MoneyAdder + switch receipt.SourceType { + case constvar.ReceiptSourceTypeSalesDetails: + moneyAdder = model.NewSalesDetailsSearch() + case constvar.ReceiptSourceTypeServiceContract: + moneyAdder = model.NewServiceContractSearch() + } + err = model.WithTransaction(func(db *gorm.DB) error { + err := model.NewReceiptSearch().SetId(id).Delete() + if err != nil { + return err + } + return moneyAdder.AmountReceivableAdd(db, receipt.SourceId, receipt.Amount.Round(2)) + }) if err != nil { return ecode.DBErr } @@ -46,9 +78,7 @@ return ecode.DBErr } - err = model.NewReceiptSearch().SetId(v.Id).Updates(map[string]interface{}{ - - }) + err = model.NewReceiptSearch().SetId(v.Id).Updates(map[string]interface{}{}) if err != nil { return ecode.DBErr } @@ -58,9 +88,27 @@ } func (ReceiptService) UpdateReceipt(receipt *model.Receipt) int { + old, err := model.NewReceiptSearch().SetId(receipt.Id).First() + if err != nil { + return ecode.DBErr + } + var moneyAdder model.MoneyAdder + switch receipt.SourceType { + case constvar.ReceiptSourceTypeSalesDetails: + moneyAdder = model.NewSalesDetailsSearch() + case constvar.ReceiptSourceTypeServiceContract: + moneyAdder = model.NewServiceContractSearch() + } + err = model.WithTransaction(func(db *gorm.DB) error { err := model.NewReceiptSearch().SetId(receipt.Id).Save(receipt) if err != nil { - return ecode.DBErr + return err } + diffAmount := receipt.Amount.Sub(old.Amount) + return moneyAdder.AmountReceivableAdd(db, receipt.SourceId, diffAmount.Round(2)) + }) + if err != nil { + return ecode.DBErr + } return ecode.OK } -- Gitblit v1.8.0