From 2bc973751af5e61c48a7805e02ae882cf742171d Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期五, 11 八月 2023 09:52:50 +0800
Subject: [PATCH] 未开票金额存库,修改

---
 model/serviceContract.go |    8 ++++----
 service/invoice.go       |   13 ++++++++-----
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/model/serviceContract.go b/model/serviceContract.go
index 0b64a4f..1d789f7 100644
--- a/model/serviceContract.go
+++ b/model/serviceContract.go
@@ -34,10 +34,10 @@
 		ServiceTimes            int                   `json:"serviceTimes" gorm:"column:service_times;type:int;comment:鏈嶅姟娆℃暟"`
 		Terms                   string                `json:"terms" gorm:"column:terms;type:text;comment:鏉℃"`
 		Remark                  string                `json:"remark" gorm:"column:remark;type:text;comment:澶囨敞"`
-		AmountReceivable        decimal.Decimal       `gorm:"amount_receivable" json:"amountReceivable"` // 搴旀敹閲戦
-		AmountReceived          decimal.Decimal       `gorm:"amount_received" json:"amountReceived"`     // 宸叉敹閲戦
-		AmountInvoiced          decimal.Decimal       `gorm:"amount_invoiced" json:"amountInvoiced"`     // 宸插紑绁ㄩ噾棰�
-		AmountUnInvoiced        decimal.Decimal       `gorm:"-" json:"amountUnInvoiced"`                 // 鏈紑绁ㄩ噾棰�
+		AmountReceivable        decimal.Decimal       `gorm:"column:amount_receivable;type:decimal(12,2);comment:鏈紑绁ㄩ噾棰�" json:"amountReceivable"`   // 搴旀敹閲戦
+		AmountReceived          decimal.Decimal       `gorm:"column:amount_received;type:decimal(12,2);comment:鏈紑绁ㄩ噾棰�" json:"amountReceived"`       // 宸叉敹閲戦
+		AmountInvoiced          decimal.Decimal       `gorm:"column:amount_invoiced;type:decimal(12,2);comment:鏈紑绁ㄩ噾棰�" json:"amountInvoiced"`       // 宸插紑绁ㄩ噾棰�
+		AmountUnInvoiced        decimal.Decimal       `gorm:"column:amount_not_invoiced;type:decimal(12,2);comment:鏈紑绁ㄩ噾棰�" json:"amountUnInvoiced"` // 鏈紑绁ㄩ噾棰�
 		Products                []*Product            `json:"products" gorm:"many2many:service_contract_product;"`
 		gorm.Model              `json:"-"`
 	}
diff --git a/service/invoice.go b/service/invoice.go
index 59301a9..203d8a8 100644
--- a/service/invoice.go
+++ b/service/invoice.go
@@ -22,22 +22,25 @@
 		if err != nil {
 			return ecode.DBErr
 		}
-		var amountInvoiced decimal.Decimal
+		var amountInvoiced, amountNotInvoiced decimal.Decimal
 		rightProducts := NewProductsService().PickRightProducts(invoice.Products, serviceContract.Products)
 		for _, product := range rightProducts {
 			amountInvoiced = serviceContract.AmountInvoiced.Add(product.Amount.Mul(product.Price))
+			amountNotInvoiced = serviceContract.AmountUnInvoiced.Sub(product.Amount.Mul(product.Price))
 		}
 		amountInvoiced = amountInvoiced.Round(2)
-		if amountInvoiced.GreaterThan(serviceContract.AmountReceivable) {
-			return ecode.SContractInvoiceProductPriceGreaterThanReceivableAmountErr
-		}
+		amountNotInvoiced = amountNotInvoiced.Round(2)
+		//if amountInvoiced.GreaterThan(serviceContract.AmountReceivable) {
+		//	return ecode.SContractInvoiceProductPriceGreaterThanReceivableAmountErr
+		//}
 		err = model.WithTransaction(func(db *gorm.DB) error {
 			err = model.NewInvoiceSearch().Create(invoice)
 			if err != nil {
 				return err
 			}
 			return model.NewServiceContractSearch().SetId(invoice.SourceId).UpdateByMap(map[string]interface{}{
-				"amount_invoiced": amountInvoiced,
+				"amount_invoiced":     amountInvoiced,
+				"amount_not_invoiced": amountNotInvoiced,
 			})
 		})
 		if err != nil {

--
Gitblit v1.8.0