Browse Source

11月8日库存管理

XMLWAN 3 years ago
parent
commit
3d9005e3d4

+ 1 - 1
conf/app.conf View File

@@ -1,5 +1,5 @@
1 1
 appname = 血透
2
-httpport = 9531
2
+httpport = 9529
3 3
 runmode = dev
4 4
 
5 5
 #

+ 9 - 13
controllers/his_api_controller.go View File

@@ -2637,7 +2637,7 @@ func (c *HisApiController) CreateHisPatientCaseHistory() {
2637 2637
 
2638 2638
 	blood_sugar := c.GetString("blood_sugar")
2639 2639
 	bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
2640
-	fmt.Println(bloodsugarfloat)
2640
+
2641 2641
 	chief_conplaint := c.GetString("chief_conplaint")
2642 2642
 
2643 2643
 	dbp := c.GetString("dbp")
@@ -2650,11 +2650,11 @@ func (c *HisApiController) CreateHisPatientCaseHistory() {
2650 2650
 	height := c.GetString("height")
2651 2651
 	history_of_present_illness := c.GetString("history_of_present_illness")
2652 2652
 	is_infect, _ := c.GetInt64("is_infect")
2653
-	fmt.Println("is", is_infect)
2653
+
2654 2654
 	past_history := c.GetString("past_history")
2655 2655
 	patient_id, _ := c.GetInt64("patient_id")
2656 2656
 	his_patient_id, _ := c.GetInt64("his_patient_id")
2657
-	fmt.Println("patient_id", patient_id)
2657
+
2658 2658
 	personal_history := c.GetString("personal_history")
2659 2659
 	pulse := c.GetString("pulse")
2660 2660
 	pulsefloat, _ := strconv.ParseFloat(pulse, 64)
@@ -2662,12 +2662,12 @@ func (c *HisApiController) CreateHisPatientCaseHistory() {
2662 2662
 	sbpfloat, _ := strconv.ParseFloat(sbp, 64)
2663 2663
 	heightfloat, _ := strconv.ParseFloat(height, 64)
2664 2664
 	sicktype := c.GetString("sick_type")
2665
-	fmt.Println("sicketype", sicktype)
2665
+
2666 2666
 	sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
2667 2667
 	symptom := c.GetString("symptom")
2668 2668
 	sick_date := c.GetString("sick_date")
2669 2669
 	temperatures := c.GetString("temperature")
2670
-	fmt.Println("temperatures", temperatures)
2670
+
2671 2671
 	temperature, _ := strconv.ParseFloat(temperatures, 64)
2672 2672
 	record_date := c.GetString("record_date")
2673 2673
 	breathing := c.GetString("breathing")
@@ -2688,7 +2688,7 @@ func (c *HisApiController) CreateHisPatientCaseHistory() {
2688 2688
 		return
2689 2689
 	}
2690 2690
 	recordDateTime := theTime.Unix()
2691
-	fmt.Println("recordDataTime", recordDateTime)
2691
+
2692 2692
 	sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
2693 2693
 	if err != nil {
2694 2694
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
@@ -3411,8 +3411,7 @@ func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionPro
3411 3411
 	if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
3412 3412
 		project_id := int64(json["project_id"].(float64))
3413 3413
 		project.ProjectId = project_id
3414
-		fmt.Println(project_id)
3415
-		fmt.Println(project.ProjectId)
3414
+
3416 3415
 	}
3417 3416
 
3418 3417
 	if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
@@ -3572,8 +3571,6 @@ func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditi
3572 3571
 
3573 3572
 func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
3574 3573
 
3575
-	fmt.Println("~~~~~~")
3576
-
3577 3574
 	if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
3578 3575
 		utils.ErrorLog("drug_name")
3579 3576
 		return enums.ErrorCodeParamWrong
@@ -4353,12 +4350,12 @@ func (c *HisApiController) GetUploadInfo() {
4353 4350
 		strconv.FormatInt(his.PatientId, 10)
4354 4351
 
4355 4352
 		var ids []int64
4356
-		fmt.Println(prescriptions)
4353
+
4357 4354
 		for _, item := range prescriptions {
4358 4355
 			ids = append(ids, item.ID)
4359 4356
 		}
4360 4357
 		var total float64
4361
-		fmt.Println(prescriptions)
4358
+
4362 4359
 		for _, item := range prescriptions {
4363 4360
 			fmt.Println(item)
4364 4361
 			if item.Type == 1 { //药品
@@ -6732,7 +6729,6 @@ func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
6732 6729
 
6733 6730
 				prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
6734 6731
 
6735
-				fmt.Println("PrescribingNumber", prescribingNumber)
6736 6732
 				if advice.PrescribingNumberUnit == drug.MaxUnit {
6737 6733
 					warehouseInfo := models.DrugWarehouseInfo{
6738 6734
 						StockMinNumber: prescribingNumber,

+ 512 - 0
controllers/supply_order_api_contorller.go View File

@@ -1,8 +1,17 @@
1 1
 package controllers
2 2
 
3 3
 import (
4
+	"XT_New/enums"
5
+	"XT_New/models"
4 6
 	"XT_New/service"
7
+	"XT_New/utils"
8
+	"encoding/json"
9
+	"fmt"
5 10
 	"github.com/astaxie/beego"
11
+	"reflect"
12
+	"strconv"
13
+	"strings"
14
+	"time"
6 15
 )
7 16
 
8 17
 type SupplyOrderApiController struct {
@@ -12,6 +21,10 @@ type SupplyOrderApiController struct {
12 21
 func SupplyOrderApiRegistRouters() {
13 22
 
14 23
 	beego.Router("/api/supply/getinitorder", &SupplyOrderApiController{}, "get:GetInitOrder")
24
+	beego.Router("/api/supply/savepurchaseorder", &SupplyOrderApiController{}, "post:SavePurchaseOrder")
25
+	beego.Router("/api/supply/getallsupply", &SupplyOrderApiController{}, "get:GetAllSupply")
26
+	beego.Router("/api/supply/getallpurchaseorderlist", &SupplyOrderApiController{}, "get:GetAllPurchaseOrderList")
27
+	beego.Router("/api/supply/updatepurchaseorder", &SupplyOrderApiController{}, "Post:UpdatePurchaseOrder")
15 28
 }
16 29
 
17 30
 func (this *SupplyOrderApiController) GetInitOrder() {
@@ -41,3 +54,502 @@ func (this *SupplyOrderApiController) GetInitOrder() {
41 54
 	})
42 55
 	return
43 56
 }
57
+
58
+func (this *SupplyOrderApiController) SavePurchaseOrder() {
59
+
60
+	supplier_id, _ := this.GetInt64("supplier_name")
61
+	start_time := this.GetString("start_time")
62
+	end_time := this.GetString("end_time")
63
+	timeLayout := "2006-01-02"
64
+	loc, _ := time.LoadLocation("Local")
65
+	var startTime int64
66
+	if len(start_time) > 0 {
67
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
68
+		if err != nil {
69
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
70
+			return
71
+		}
72
+		startTime = theTime.Unix()
73
+	}
74
+	var endTime int64
75
+	if len(end_time) > 0 {
76
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
77
+		if err != nil {
78
+			utils.ErrorLog(err.Error())
79
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
80
+			return
81
+		}
82
+		endTime = theTime.Unix()
83
+	}
84
+
85
+	rate_of_concession := this.GetString("rate_of_concession")
86
+	rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
87
+	discount_amount := this.GetString("discount_amount")
88
+	discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
89
+	fmt.Println("supplier_id23323232323232", supplier_id, startTime, endTime, rate_of_concession, rate_of_concession_float, discount_amount, discount_amount_float)
90
+	dataBody := make(map[string]interface{}, 0)
91
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
92
+	if err != nil {
93
+		utils.ErrorLog(err.Error())
94
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
95
+		return
96
+	}
97
+
98
+	//生成订货单
99
+	timeStr := time.Now().Format("2006-01-02")
100
+	timeArr := strings.Split(timeStr, "-")
101
+	orgId := this.GetAdminUserInfo().CurrentOrgId
102
+	total, _ := service.FindAllSupplyOrder(orgId)
103
+	total = total + 1
104
+	warehousing_order := "CGDD" + timeArr[0] + timeArr[1] + timeArr[2] + "00" + strconv.FormatInt(total, 10)
105
+	recordDateStr := time.Now().Format("2006-01-02")
106
+	recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
107
+	fmt.Scan("parseDateErr", parseDateErr)
108
+	record_date := recordDate.Unix()
109
+	info := models.SupplierWarehouseInfo{
110
+		Number:           warehousing_order,
111
+		UserOrgId:        orgId,
112
+		Creater:          this.GetAdminUserInfo().AdminUser.Id,
113
+		Ctime:            time.Now().Unix(),
114
+		Mtime:            0,
115
+		Status:           1,
116
+		RecordDate:       record_date,
117
+		IsCheck:          2,
118
+		RateOfConcession: rate_of_concession_float,
119
+		DiscountAmount:   discount_amount_float,
120
+		DocumentDate:     startTime,
121
+		DeliveryDate:     endTime,
122
+		SupplierId:       supplier_id,
123
+	}
124
+	err = service.CreateSupplyWarehouse(info)
125
+	warehouseInfo, _ := service.FindLastSupplyWarehouseInfo(orgId)
126
+	var warehousingInfo []*models.SupplierWarehousingInfoOrder
127
+	if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
128
+		thisStockIn, _ := dataBody["stockIn"].([]interface{})
129
+		if len(thisStockIn) > 0 {
130
+			for _, item := range thisStockIn {
131
+				items := item.(map[string]interface{})
132
+
133
+				if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
134
+					utils.ErrorLog("id")
135
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
136
+					return
137
+				}
138
+				id := int64(items["id"].(float64))
139
+
140
+				if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
141
+					utils.ErrorLog("supply_count")
142
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
143
+					return
144
+				}
145
+				supply_count := int64(items["supply_count"].(float64))
146
+
147
+				if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
148
+					utils.ErrorLog("supply_license_number")
149
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
150
+					return
151
+				}
152
+
153
+				supply_license_number := items["supply_license_number"].(string)
154
+
155
+				if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
156
+					utils.ErrorLog("supply_price")
157
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
158
+					return
159
+				}
160
+				supply_price := items["supply_price"].(string)
161
+
162
+				supply_price_float, _ := strconv.ParseFloat(supply_price, 64)
163
+
164
+				if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
165
+					utils.ErrorLog("supply_remake")
166
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
167
+					return
168
+				}
169
+
170
+				supply_remake := items["supply_remake"].(string)
171
+
172
+				if items["supply_total_price"] == nil || reflect.TypeOf(items["supply_total_price"]).String() != "string" {
173
+					utils.ErrorLog("supply_total_price")
174
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
175
+					return
176
+				}
177
+				supply_total_price := items["supply_total_price"].(string)
178
+
179
+				supply_total_price_float, _ := strconv.ParseFloat(supply_total_price, 64)
180
+				if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
181
+					utils.ErrorLog("type")
182
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
183
+					return
184
+				}
185
+				is_source := int64(items["type"].(float64))
186
+
187
+				if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
188
+					utils.ErrorLog("supply_type")
189
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
190
+					return
191
+				}
192
+
193
+				supply_type := items["supply_type"].(string)
194
+
195
+				if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
196
+					utils.ErrorLog("supply_specification_name")
197
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
198
+					return
199
+				}
200
+
201
+				supply_specification_name := items["supply_specification_name"].(string)
202
+
203
+				if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
204
+					utils.ErrorLog("supply_total")
205
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
206
+					return
207
+				}
208
+
209
+				supply_total := items["supply_total"].(string)
210
+
211
+				if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
212
+					utils.ErrorLog("supply_manufacturer")
213
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
214
+					return
215
+				}
216
+
217
+				supply_manufacturer := items["supply_manufacturer"].(string)
218
+
219
+				if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
220
+					utils.ErrorLog("name")
221
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
222
+					return
223
+				}
224
+
225
+				name := items["name"].(string)
226
+
227
+				order := models.SupplierWarehousingInfoOrder{
228
+					OrderNumber:             warehousing_order,
229
+					IsSource:                is_source,
230
+					Count:                   supply_count,
231
+					Price:                   supply_price_float,
232
+					Amount:                  supply_total_price_float,
233
+					Remark:                  supply_remake,
234
+					UserOrgId:               orgId,
235
+					Ctime:                   time.Now().Unix(),
236
+					Status:                  1,
237
+					Mtime:                   0,
238
+					WarehousingId:           warehouseInfo.ID,
239
+					ProjectId:               id,
240
+					SupplyLicenseNumber:     supply_license_number,
241
+					SupplyType:              supply_type,
242
+					SupplySpecificationName: supply_specification_name,
243
+					SupplyTotal:             supply_total,
244
+					SupplyManufacturer:      supply_manufacturer,
245
+					Name:                    name,
246
+				}
247
+
248
+				warehousingInfo = append(warehousingInfo, &order)
249
+			}
250
+		}
251
+	}
252
+
253
+	for _, item := range warehousingInfo {
254
+		err = service.CreateSupplyWarehousingOrder(item)
255
+	}
256
+
257
+	//查询
258
+	orderInfo, err := service.GetSupplyWarehousingOrderInfo(warehouseInfo.ID)
259
+	if err == nil {
260
+		this.ServeSuccessJSON(map[string]interface{}{
261
+			"order":         warehousingInfo,
262
+			"warehouseInfo": warehouseInfo,
263
+			"orderInfo":     orderInfo,
264
+		})
265
+	} else {
266
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
267
+	}
268
+}
269
+
270
+func (this *SupplyOrderApiController) GetAllSupply() {
271
+
272
+	orgId := this.GetAdminUserInfo().CurrentOrgId
273
+	appId := this.GetAdminUserInfo().CurrentAppId
274
+	supplyList, err := service.GetSupplierList(orgId)
275
+	doctorList, err := service.GetAllDoctor(orgId, appId)
276
+	if err == nil {
277
+		this.ServeSuccessJSON(map[string]interface{}{
278
+			"supplyList": supplyList,
279
+			"doctorList": doctorList,
280
+		})
281
+	} else {
282
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
283
+	}
284
+}
285
+
286
+func (this *SupplyOrderApiController) GetAllPurchaseOrderList() {
287
+
288
+	check_id, _ := this.GetInt64("check_id")
289
+	start_time := this.GetString("start_time")
290
+	end_time := this.GetString("end_time")
291
+	timeLayout := "2006-01-02"
292
+	loc, _ := time.LoadLocation("Local")
293
+	var startTime int64
294
+	if len(start_time) > 0 {
295
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
296
+		if err != nil {
297
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
298
+			return
299
+		}
300
+		startTime = theTime.Unix()
301
+	}
302
+	var endTime int64
303
+	if len(end_time) > 0 {
304
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
305
+		if err != nil {
306
+			utils.ErrorLog(err.Error())
307
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
308
+			return
309
+		}
310
+		endTime = theTime.Unix()
311
+	}
312
+	keyword := this.GetString("keyword")
313
+
314
+	page, _ := this.GetInt64("page")
315
+
316
+	limit, _ := this.GetInt64("limit")
317
+	orgId := this.GetAdminUserInfo().CurrentOrgId
318
+	list, total, err := service.GetAllPurchaseOrderList(check_id, startTime, endTime, keyword, page, limit, orgId)
319
+	if err == nil {
320
+		this.ServeSuccessJSON(map[string]interface{}{
321
+			"list":  list,
322
+			"total": total,
323
+		})
324
+	} else {
325
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
326
+	}
327
+}
328
+
329
+func (this *SupplyOrderApiController) UpdatePurchaseOrder() {
330
+	supplier_id, _ := this.GetInt64("supplier_name")
331
+	start_time := this.GetString("start_time")
332
+	end_time := this.GetString("end_time")
333
+	timeLayout := "2006-01-02"
334
+	loc, _ := time.LoadLocation("Local")
335
+	var startTime int64
336
+	if len(start_time) > 0 {
337
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
338
+		if err != nil {
339
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
340
+			return
341
+		}
342
+		startTime = theTime.Unix()
343
+	}
344
+	var endTime int64
345
+	if len(end_time) > 0 {
346
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
347
+		if err != nil {
348
+			utils.ErrorLog(err.Error())
349
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
350
+			return
351
+		}
352
+		endTime = theTime.Unix()
353
+	}
354
+
355
+	rate_of_concession := this.GetString("rate_of_concession")
356
+	rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
357
+	discount_amount := this.GetString("discount_amount")
358
+	discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
359
+	warehousing_id, _ := this.GetInt64("id")
360
+	number := this.GetString("number")
361
+	fmt.Println("supplier_id23323232323232", supplier_id, startTime, endTime, rate_of_concession, rate_of_concession_float, discount_amount, discount_amount_float)
362
+	orgId := this.GetAdminUserInfo().CurrentOrgId
363
+	info := models.SupplierWarehouseInfo{
364
+		RateOfConcession: rate_of_concession_float,
365
+		DiscountAmount:   discount_amount_float,
366
+		DocumentDate:     startTime,
367
+		DeliveryDate:     endTime,
368
+		SupplierId:       supplier_id,
369
+		Mtime:            time.Now().Unix(),
370
+	}
371
+	service.ModefySupplyWarehouseInfo(warehousing_id, info)
372
+	dataBody := make(map[string]interface{}, 0)
373
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
374
+	if err != nil {
375
+		utils.ErrorLog(err.Error())
376
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
377
+		return
378
+	}
379
+	var warehousingInfo []*models.SupplierWarehousingInfoOrder
380
+	var updateWarehousingInfo []*models.SupplierWarehousingInfoOrder
381
+	if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
382
+		thisStockIn, _ := dataBody["stockIn"].([]interface{})
383
+		if len(thisStockIn) > 0 {
384
+			for _, item := range thisStockIn {
385
+				items := item.(map[string]interface{})
386
+
387
+				if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
388
+					utils.ErrorLog("id")
389
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
390
+					return
391
+				}
392
+				id := int64(items["id"].(float64))
393
+
394
+				if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
395
+					utils.ErrorLog("project_id")
396
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
397
+					return
398
+				}
399
+				project_id := int64(items["project_id"].(float64))
400
+
401
+				if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
402
+					utils.ErrorLog("supply_count")
403
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
404
+					return
405
+				}
406
+				supply_count := int64(items["supply_count"].(float64))
407
+
408
+				if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
409
+					utils.ErrorLog("supply_license_number")
410
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
411
+					return
412
+				}
413
+
414
+				supply_license_number := items["supply_license_number"].(string)
415
+
416
+				if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
417
+					utils.ErrorLog("supply_price")
418
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
419
+					return
420
+				}
421
+				supply_price := items["supply_price"].(string)
422
+
423
+				supply_price_float, _ := strconv.ParseFloat(supply_price, 64)
424
+
425
+				if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
426
+					utils.ErrorLog("supply_remake")
427
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
428
+					return
429
+				}
430
+
431
+				supply_remake := items["supply_remake"].(string)
432
+
433
+				if items["supply_total_price"] == nil || reflect.TypeOf(items["supply_total_price"]).String() != "string" {
434
+					utils.ErrorLog("supply_total_price")
435
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
436
+					return
437
+				}
438
+				supply_total_price := items["supply_total_price"].(string)
439
+
440
+				supply_total_price_float, _ := strconv.ParseFloat(supply_total_price, 64)
441
+				if items["is_source"] == nil || reflect.TypeOf(items["is_source"]).String() != "float64" {
442
+					utils.ErrorLog("is_source")
443
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
444
+					return
445
+				}
446
+				is_source := int64(items["is_source"].(float64))
447
+
448
+				if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
449
+					utils.ErrorLog("supply_type")
450
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
451
+					return
452
+				}
453
+
454
+				supply_type := items["supply_type"].(string)
455
+
456
+				if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
457
+					utils.ErrorLog("supply_specification_name")
458
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
459
+					return
460
+				}
461
+
462
+				supply_specification_name := items["supply_specification_name"].(string)
463
+
464
+				if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
465
+					utils.ErrorLog("supply_total")
466
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
467
+					return
468
+				}
469
+
470
+				supply_total := items["supply_total"].(string)
471
+
472
+				if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
473
+					utils.ErrorLog("supply_manufacturer")
474
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
475
+					return
476
+				}
477
+
478
+				supply_manufacturer := items["supply_manufacturer"].(string)
479
+
480
+				if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
481
+					utils.ErrorLog("name")
482
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
483
+					return
484
+				}
485
+
486
+				name := items["name"].(string)
487
+
488
+				if id > 0 {
489
+					order := models.SupplierWarehousingInfoOrder{
490
+						ID:                      id,
491
+						IsSource:                is_source,
492
+						Count:                   supply_count,
493
+						Price:                   supply_price_float,
494
+						Amount:                  supply_total_price_float,
495
+						Remark:                  supply_remake,
496
+						Ctime:                   time.Now().Unix(),
497
+						Status:                  1,
498
+						Mtime:                   0,
499
+						ProjectId:               project_id,
500
+						SupplyLicenseNumber:     supply_license_number,
501
+						SupplyType:              supply_type,
502
+						SupplySpecificationName: supply_specification_name,
503
+						SupplyTotal:             supply_total,
504
+						SupplyManufacturer:      supply_manufacturer,
505
+						Name:                    name,
506
+					}
507
+
508
+					updateWarehousingInfo = append(updateWarehousingInfo, &order)
509
+				}
510
+
511
+				if id == 0 {
512
+
513
+					order := models.SupplierWarehousingInfoOrder{
514
+						OrderNumber:             number,
515
+						IsSource:                is_source,
516
+						Count:                   supply_count,
517
+						Price:                   supply_price_float,
518
+						Amount:                  supply_total_price_float,
519
+						Remark:                  supply_remake,
520
+						UserOrgId:               orgId,
521
+						Ctime:                   time.Now().Unix(),
522
+						Status:                  1,
523
+						Mtime:                   0,
524
+						WarehousingId:           warehousing_id,
525
+						ProjectId:               id,
526
+						SupplyLicenseNumber:     supply_license_number,
527
+						SupplyType:              supply_type,
528
+						SupplySpecificationName: supply_specification_name,
529
+						SupplyTotal:             supply_total,
530
+						SupplyManufacturer:      supply_manufacturer,
531
+						Name:                    name,
532
+					}
533
+					warehousingInfo = append(warehousingInfo, &order)
534
+				}
535
+
536
+			}
537
+		}
538
+		if len(warehousingInfo) > 0 {
539
+			for _, item := range warehousingInfo {
540
+				service.CreateSupplyWarehousingOrder(item)
541
+			}
542
+
543
+		}
544
+		if len(updateWarehousingInfo) > 0 {
545
+			for _, item := range updateWarehousingInfo {
546
+				service.ModifySupplyWarehouseOrder(item)
547
+			}
548
+
549
+		}
550
+		this.ServeSuccessJSON(map[string]interface{}{
551
+			"warehousingInfo": warehousingInfo,
552
+		})
553
+
554
+	}
555
+}

+ 1 - 0
models/stock_models.go View File

@@ -177,6 +177,7 @@ type VmWarehousingInfo struct {
177 177
 	MinNumber         int64       `gorm:"column:min_number" json:"min_number" form:"min_number"`
178 178
 	PackingUnit       string      `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
179 179
 	Count             int64       `gorm:json:"count"`
180
+	PackingPrice      float64     `gorm:"column:packing_price" json:"packing_price" form:"packing_price"`
180 181
 }
181 182
 
182 183
 type WarehouseOut struct {

+ 73 - 0
models/supply.models.go View File

@@ -87,3 +87,76 @@ type SpSupplierName struct {
87 87
 func (SpSupplierName) TableName() string {
88 88
 	return "xt_supplier_name"
89 89
 }
90
+
91
+type SupplierWarehousingInfoOrder struct {
92
+	ID                      int64   `gorm:"column:id" json:"id" form:"id"`
93
+	OrderNumber             string  `gorm:"column:order_number" json:"order_number" form:"order_number"`
94
+	IsSource                int64   `gorm:"column:is_source" json:"is_source" form:"is_source"`
95
+	Count                   int64   `gorm:"column:count" json:"count" form:"count"`
96
+	Price                   float64 `gorm:"column:price" json:"price" form:"price"`
97
+	Amount                  float64 `gorm:"column:amount" json:"amount" form:"amount"`
98
+	Remark                  string  `gorm:"column:remark" json:"remark" form:"remark"`
99
+	UserOrgId               int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
100
+	Ctime                   int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
101
+	Status                  int64   `gorm:"column:status" json:"status" form:"status"`
102
+	Mtime                   int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
103
+	WarehousingId           int64   `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
104
+	ProjectId               int64   `gorm:"column:project_id" json:"project_id" form:"project_id"`
105
+	SupplyLicenseNumber     string  `gorm:"column:supply_license_number" json:"supply_license_number" form:"supply_license_number"`
106
+	SupplyType              string  `gorm:"column:supply_type" json:"supply_type" form:"supply_type"`
107
+	SupplySpecificationName string  `gorm:"column:supply_specification_name" json:"supply_specification_name" form:"supply_specification_name"`
108
+	SupplyTotal             string  `gorm:"column:supply_total" json:"supply_total" form:"supply_total"`
109
+	SupplyManufacturer      string  `gorm:"column:supply_manufacturer" json:"supply_manufacturer" form:"supply_manufacturer"`
110
+	Name                    string  `gorm:"column:name" json:"name" form:"name"`
111
+}
112
+
113
+func (SupplierWarehousingInfoOrder) TableName() string {
114
+	return "xt_supplier_warehousing_info_order"
115
+}
116
+
117
+type SupplierWarehouseInfo struct {
118
+	ID               int64   `gorm:"column:id" json:"id" form:"id"`
119
+	Number           string  `gorm:"column:number" json:"number" form:"number"`
120
+	UserOrgId        int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
121
+	Creater          int64   `gorm:"column:creater" json:"creater" form:"creater"`
122
+	Ctime            int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
123
+	Mtime            int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
124
+	Status           int64   `gorm:"column:status" json:"status" form:"status"`
125
+	RecordDate       int64   `gorm:"column:record_date" json:"record_date" form:"record_date"`
126
+	IsCheck          int64   `gorm:"column:is_check" json:"is_check" form:"is_check"`
127
+	RateOfConcession float64 `gorm:"column:rate_of_concession" json:"rate_of_concession" form:"rate_of_concession"`
128
+	DiscountAmount   float64 `gorm:"column:discount_amount" json:"discount_amount" form:"discount_amount"`
129
+	DocumentDate     int64   `gorm:"column:document_date" json:"document_date" form:"document_date"`
130
+	DeliveryDate     int64   `gorm:"column:delivery_date" json:"delivery_date" form:"delivery_date"`
131
+	SupplierId       int64   `gorm:"column:supplier_id" json:"supplier_id" form:"supplier_id"`
132
+	Checker          int64   `gorm:"column:checker" json:"checker" form:"checker"`
133
+	CheckTime        int64   `gorm:"column:check_time" json:"check_time" form:"check_time"`
134
+}
135
+
136
+func (SupplierWarehouseInfo) TableName() string {
137
+	return "xt_supplier_warehouse_info"
138
+}
139
+
140
+type VmSupplierWarehouseInfo struct {
141
+	ID                           int64                           `gorm:"column:id" json:"id" form:"id"`
142
+	Number                       string                          `gorm:"column:number" json:"number" form:"number"`
143
+	UserOrgId                    int64                           `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
144
+	Creater                      int64                           `gorm:"column:creater" json:"creater" form:"creater"`
145
+	Ctime                        int64                           `gorm:"column:ctime" json:"ctime" form:"ctime"`
146
+	Mtime                        int64                           `gorm:"column:mtime" json:"mtime" form:"mtime"`
147
+	Status                       int64                           `gorm:"column:status" json:"status" form:"status"`
148
+	RecordDate                   int64                           `gorm:"column:record_date" json:"record_date" form:"record_date"`
149
+	IsCheck                      int64                           `gorm:"column:is_check" json:"is_check" form:"is_check"`
150
+	RateOfConcession             float64                         `gorm:"column:rate_of_concession" json:"rate_of_concession" form:"rate_of_concession"`
151
+	DiscountAmount               float64                         `gorm:"column:discount_amount" json:"discount_amount" form:"discount_amount"`
152
+	DocumentDate                 int64                           `gorm:"column:document_date" json:"document_date" form:"document_date"`
153
+	DeliveryDate                 int64                           `gorm:"column:delivery_date" json:"delivery_date" form:"delivery_date"`
154
+	SupplierId                   int64                           `gorm:"column:supplier_id" json:"supplier_id" form:"supplier_id"`
155
+	Checker                      int64                           `gorm:"column:checker" json:"checker" form:"checker"`
156
+	CheckTime                    int64                           `gorm:"column:check_time" json:"check_time" form:"check_time"`
157
+	SupplierWarehousingInfoOrder []*SupplierWarehousingInfoOrder `gorm:"ForeignKey:WarehousingId;AssociationForeignKey:ID" json:"orderInfo"`
158
+}
159
+
160
+func (VmSupplierWarehouseInfo) TableName() string {
161
+	return "xt_supplier_warehouse_info"
162
+}

+ 1 - 1
service/stock_service.go View File

@@ -3732,7 +3732,7 @@ func GetStockListById(good_id int64, orgid int64, limit int64, page int64, start
3732 3732
 	if good_id > 0 {
3733 3733
 		db = db.Where("x.good_id = ?", good_id)
3734 3734
 	}
3735
-	err = db.Select("x.id,x.warehousing_id,x.good_id,x.good_type_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehousing_unit,x.stock_count,x.price,x.total_price,x.dealer,t.manufacturer,x.remark,x.ctime,x.is_return,x.warehousing_order,x.type,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.min_unit,t.buy_price").Joins("left join xt_good_information as t on t.id = x.good_id").Count(&total).Offset(offset).Limit(limit).Scan(&info).Error
3735
+	err = db.Select("x.id,x.warehousing_id,x.good_id,x.good_type_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehousing_unit,x.stock_count,x.price,x.total_price,x.dealer,x.packing_price,t.manufacturer,x.remark,x.ctime,x.is_return,x.warehousing_order,x.type,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.min_unit,t.buy_price").Joins("left join xt_good_information as t on t.id = x.good_id").Count(&total).Offset(offset).Limit(limit).Scan(&info).Error
3736 3736
 	return info, total, err
3737 3737
 
3738 3738
 }

+ 68 - 0
service/supply_service.go View File

@@ -31,3 +31,71 @@ func GetSupplierList(orgid int64) (suppler []*models.SpSupplierName, err error)
31 31
 	err = XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&suppler).Error
32 32
 	return suppler, err
33 33
 }
34
+
35
+func FindAllSupplyOrder(orgid int64) (total int64, err error) {
36
+
37
+	err = XTReadDB().Model(&models.SupplierWarehouseInfo{}).Where("user_org_id = ? and status = 1", orgid).Count(&total).Error
38
+	return total, err
39
+}
40
+
41
+func CreateSupplyWarehouse(info models.SupplierWarehouseInfo) error {
42
+
43
+	err := XTWriteDB().Create(&info).Error
44
+	return err
45
+}
46
+
47
+func FindLastSupplyWarehouseInfo(orgid int64) (models.SupplierWarehouseInfo, error) {
48
+	info := models.SupplierWarehouseInfo{}
49
+	err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Last(&info).Error
50
+	return info, err
51
+}
52
+
53
+func CreateSupplyWarehousingOrder(order *models.SupplierWarehousingInfoOrder) error {
54
+
55
+	err := XTWriteDB().Create(&order).Error
56
+	return err
57
+}
58
+
59
+func GetAllPurchaseOrderList(check_id int64, startime int64, endtime int64, keyword string, page int64, limit int64, orgid int64) (info []*models.VmSupplierWarehouseInfo, total int64, err error) {
60
+
61
+	db := XTReadDB().Model(&info).Where("status = 1")
62
+	likeKey := "%" + keyword + "%"
63
+	offset := (page - 1) * limit
64
+	if check_id > 0 {
65
+		db = db.Where("xt_supplier_warehouse_info.is_check = ?", check_id)
66
+	}
67
+	if startime > 0 {
68
+		db = db.Where("xt_supplier_warehouse_info.record_date >= ?", startime)
69
+	}
70
+	if endtime > 0 {
71
+		db = db.Where("xt_supplier_warehouse_info.record_date<=?", endtime)
72
+	}
73
+
74
+	if len(keyword) > 0 {
75
+		db.Joins("join xt_supplier_name on xt_supplier_name.id = xt_supplier_warehouse_info.supplier_id")
76
+		db = db.Where("xt_supplier_warehouse_info.number like ? or xt_supplier_name.supplier_name like ? ", likeKey, likeKey).Group("xt_supplier_warehouse_info.id")
77
+	}
78
+	if orgid > 0 {
79
+		db = db.Where("xt_supplier_warehouse_info.user_org_id = ?", orgid)
80
+	}
81
+	err = db.Count(&total).Offset(offset).Limit(limit).Preload("SupplierWarehousingInfoOrder", "status= 1 and user_org_id = ?", orgid).Find(&info).Error
82
+	return info, total, err
83
+}
84
+
85
+func GetSupplyWarehousingOrderInfo(id int64) (order []*models.SupplierWarehousingInfoOrder, err error) {
86
+
87
+	err = XTReadDB().Where("warehousing_id = ? and status = 1", id).Find(&order).Error
88
+	return order, err
89
+}
90
+
91
+func ModefySupplyWarehouseInfo(id int64, info models.SupplierWarehouseInfo) error {
92
+
93
+	err := XTWriteDB().Where("id = ? and status = 1", id).Updates(map[string]interface{}{"rate_of_concession": info.RateOfConcession, "discount_amount": info.DiscountAmount, "document_date": info.DocumentDate, "delivery_date": info.DeliveryDate, "supplier_id": info.SupplierId}).Error
94
+	return err
95
+}
96
+
97
+func ModifySupplyWarehouseOrder(order *models.SupplierWarehousingInfoOrder) error {
98
+
99
+	err := XTWriteDB().Model(&order).Where("id = ? and status = 1", order.ID).Updates(map[string]interface{}{}).Updates(map[string]interface{}{"is_source": order.IsSource, "count": order.Count, "price": order.Price, "amount": order.Amount, "remark": order.Remark, "project_id": order.ProjectId, "supply_license_number": order.SupplyLicenseNumber, "supply_type": order.SupplyType, "supply_specification_name": order.SupplySpecificationName, "supply_total": order.SupplyTotal, "supply_manufacturer": order.SupplyManufacturer, "name": order.Name}).Error
100
+	return err
101
+}