XMLWAN 3 anni fa
parent
commit
02f9833c11

+ 6 - 6
controllers/base_api_controller.go Vedi File

@@ -73,8 +73,8 @@ func (this *BaseAuthAPIController) Prepare() {
73 73
 		userAdmin.Id = 1448
74 74
 		userAdmin.Mobile = "13318599895"
75 75
 
76
-		//userAdmin.Id = 597
77
-		//userAdmin.Mobile = "19874122664"
76
+		userAdmin.Id = 597
77
+		userAdmin.Mobile = "19874122664"
78 78
 		userAdmin.IsSuperAdmin = false
79 79
 		userAdmin.Status = 1
80 80
 		userAdmin.CreateTime = 1530786071
@@ -97,8 +97,8 @@ func (this *BaseAuthAPIController) Prepare() {
97 97
 		adminUserInfo.Subscibes = subscibes
98 98
 		this.SetSession("admin_user_info", &adminUserInfo)
99 99
 
100
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
101
-		this.StopRun()
100
+		//this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
101
+		//this.StopRun()
102 102
 
103 103
 	}
104 104
 
@@ -319,8 +319,8 @@ func (this *BaseServeAPIController) Prepare() {
319 319
 		userAdmin.Id = 1448
320 320
 		userAdmin.Mobile = "13318599895"
321 321
 
322
-		//userAdmin.Id = 597
323
-		//userAdmin.Mobile = "19874122664"
322
+		userAdmin.Id = 597
323
+		userAdmin.Mobile = "19874122664"
324 324
 		userAdmin.IsSuperAdmin = false
325 325
 		userAdmin.Status = 1
326 326
 		userAdmin.CreateTime = 1530786071

+ 278 - 147
controllers/drug_stock_api_contorller.go Vedi File

@@ -66,6 +66,8 @@ func DrugStockManagerApiRegistRouters() {
66 66
 
67 67
 	beego.Router("/api/drugstock/get", &StockDrugApiController{}, "get:GetAllDrugStock")
68 68
 
69
+	beego.Router("/api/drug/getcanceldrugorderprint", &StockDrugApiController{}, "get:GetCancelDrugOrderPrint")
70
+	beego.Router("/api/drug/drugcancelexportlist", &StockDrugApiController{}, "get:GetDrugCancelExportList")
69 71
 }
70 72
 
71 73
 func (c *StockDrugApiController) CreateDrugWarehouse() {
@@ -110,7 +112,7 @@ func (c *StockDrugApiController) CreateDrugWarehouse() {
110 112
 	}
111 113
 
112 114
 	var warehousingInfo []*models.DrugWarehouseInfo
113
-
115
+	var drugFlow []*models.DrugFlow
114 116
 	if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
115 117
 		thisStockIn, _ := dataBody["stockIn"].([]interface{})
116 118
 		if len(thisStockIn) > 0 {
@@ -227,10 +229,43 @@ func (c *StockDrugApiController) CreateDrugWarehouse() {
227 229
 				}
228 230
 				warehousingInfo = append(warehousingInfo, warehouseInfo)
229 231
 
232
+				drugflow := &models.DrugFlow{
233
+					WarehousingOrder: warehousing.WarehousingOrder,
234
+					WarehousingId:    warehousing.ID,
235
+					DrugId:           drug_id,
236
+					Number:           number,
237
+					ProductDate:      productDates,
238
+					ExpireDate:       expiryDates,
239
+					Count:            warehousing_count,
240
+					Price:            last_price,
241
+					Status:           1,
242
+					Ctime:            ctime,
243
+					UserOrgId:        adminUserInfo.CurrentOrgId,
244
+					Manufacturer:     manufacturer,
245
+					Dealer:           dealer,
246
+					BatchNumber:      batch_number,
247
+					MaxUnit:          max_unit,
248
+					MinUnit:          min_unit,
249
+					ConsumableType:   1,
250
+					IsEdit:           1,
251
+					Creator:          adminUserInfo.AdminUser.Id,
252
+					IsSys:            0,
253
+				}
254
+
255
+				drugFlow = append(drugFlow, drugflow)
256
+
230 257
 			}
231 258
 		}
232 259
 	}
260
+	//创建入库单
233 261
 	errs := service.CreateDrugWarehousingInfo(warehousingInfo)
262
+	if errs == nil {
263
+		//更改库存
264
+		service.UpdateDrugInfo(warehousingInfo)
265
+	}
266
+	//创建流水单
267
+	service.CreateDrugFlow(drugFlow)
268
+
234 269
 	info, _ := service.FindLastDrugWarehousingInfo(warehousing.WarehousingOrder)
235 270
 
236 271
 	if errs != nil {
@@ -244,141 +279,6 @@ func (c *StockDrugApiController) CreateDrugWarehouse() {
244 279
 		"warehousing_order": warehousing_order,
245 280
 		"info":              info,
246 281
 	})
247
-	//}
248
-
249
-	//else {
250
-	//	warehouse, err1 := service.FindWareHouseByOrderNumber(warehousing_order)
251
-	//	if (err1 != nil) {
252
-	//		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
253
-	//		return
254
-	//	}
255
-	//
256
-	//	dataBody := make(map[string]interface{}, 0)
257
-	//	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
258
-	//	if err != nil {
259
-	//		utils.ErrorLog(err.Error())
260
-	//		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
261
-	//		return
262
-	//	}
263
-	//
264
-	//	var warehousingInfo []*models.WarehousingInfo
265
-	//
266
-	//	if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
267
-	//		thisStockIn, _ := dataBody["stockIn"].([]interface{})
268
-	//		if len(thisStockIn) > 0 {
269
-	//			for _, item := range thisStockIn {
270
-	//				items := item.(map[string]interface{})
271
-	//
272
-	//				if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
273
-	//					utils.ErrorLog("good_id")
274
-	//					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
275
-	//					return
276
-	//				}
277
-	//				good_id := int64(items["good_id"].(float64))
278
-	//
279
-	//				if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
280
-	//					utils.ErrorLog("good_type_id")
281
-	//					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
282
-	//					return
283
-	//				}
284
-	//				good_type_id := int64(items["good_type_id"].(float64))
285
-	//
286
-	//				if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
287
-	//					utils.ErrorLog("warehousing_count")
288
-	//					c.ServeFailJSONWithSGJErrorCod  Fe(enums.ErrorCodeParamWrong)
289
-	//					return
290
-	//				}
291
-	//
292
-	//				warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
293
-	//
294
-	//				if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
295
-	//					utils.ErrorLog("price")
296
-	//					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
297
-	//					return
298
-	//				}
299
-	//				price, _ := strconv.ParseFloat(items["price"].(string), 64)
300
-	//				total := float64(warehousing_count) * price
301
-	//
302
-	//				if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
303
-	//					utils.ErrorLog("expiry_date")
304
-	//					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
305
-	//					return
306
-	//				}
307
-	//
308
-	//				expiryDate, _ := items["expiry_date"].(string)
309
-	//				if len(expiryDate) == 0 {
310
-	//					utils.ErrorLog("len(expiry_date) == 0")
311
-	//					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
312
-	//
313
-	//					return
314
-	//				}
315
-	//
316
-	//				expiry_date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
317
-	//				if parseDateErr != nil {
318
-	//					c.ErrorLog("日期(%v)解析错误:%v", expiry_date, parseDateErr)
319
-	//				}
320
-	//
321
-	//				var productDates int64
322
-	//
323
-	//				if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
324
-	//					productDates = 0;
325
-	//				} else {
326
-	//					productDate, _ := items["product_date"].(string)
327
-	//					product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
328
-	//					productDates = product_date.Unix()
329
-	//
330
-	//				}
331
-	//
332
-	//				if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
333
-	//					utils.ErrorLog("number")
334
-	//					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
335
-	//					return
336
-	//				}
337
-	//				number, _ := items["number"].(string)
338
-	//
339
-	//				var remark string
340
-	//				if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
341
-	//					remark = ""
342
-	//				} else {
343
-	//					remark = items["remark"].(string)
344
-	//				}
345
-	//
346
-	//				warehouseInfo := &models.WarehousingInfo{
347
-	//					WarehousingOrder: warehousing_order,
348
-	//					WarehousingId:    warehouse.ID,
349
-	//					GoodId:           good_id,
350
-	//					Number:           number,
351
-	//					GoodTypeId:       good_type_id,
352
-	//					ProductDate:      productDates,
353
-	//					ExpiryDate:       expiry_date.Unix(),
354
-	//					WarehousingCount: warehousing_count,
355
-	//					Price:            price,
356
-	//					TotalPrice:       total,
357
-	//					Status:           1,
358
-	//					Ctime:            ctime,
359
-	//					Remark:           remark,
360
-	//					OrgId:            adminUserInfo.CurrentOrgId,
361
-	//				}
362
-	//				warehousingInfo = append(warehousingInfo, warehouseInfo)
363
-	//
364
-	//			}
365
-	//		}
366
-	//	}
367
-	//	errs := service.CreateWarehousingInfo(warehousingInfo)
368
-	//	info, _ := service.FindLastWarehousingInfo(warehousing_order)
369
-	//
370
-	//	if (errs != nil) {
371
-	//		utils.ErrorLog(errs.Error())
372
-	//		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
373
-	//		return
374
-	//	}
375
-	//
376
-	//	c.ServeSuccessJSON(map[string]interface{}{
377
-	//		"msg":  "入库成功",
378
-	//		"info": info,
379
-	//	})
380
-	//
381
-	//}
382 282
 
383 283
 }
384 284
 func (c *StockDrugApiController) GetDrugWarehouseList() {
@@ -522,7 +422,7 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
522 422
 
523 423
 	var warehousingInfo []*models.DrugWarehouseInfo
524 424
 	var upDateWarehousingInfo []*models.DrugWarehouseInfo
525
-
425
+	var drugFlow []*models.DrugFlow
526 426
 	if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
527 427
 		thisStockIn, _ := dataBody["stockIn"].([]interface{})
528 428
 
@@ -671,18 +571,73 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
671 571
 						BatchNumber:      batch_number,
672 572
 					}
673 573
 					upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
574
+
575
+					drugflow := &models.DrugFlow{
576
+						WarehousingOrder: warehousing.WarehousingOrder,
577
+						WarehousingId:    warehousing.ID,
578
+						DrugId:           drug_id,
579
+						Number:           number,
580
+						ProductDate:      productDates,
581
+						ExpireDate:       expiryDates,
582
+						Count:            warehousing_count,
583
+						Price:            last_price,
584
+						Status:           1,
585
+						Ctime:            ctime,
586
+						UserOrgId:        adminUserInfo.CurrentOrgId,
587
+						Manufacturer:     manufacturer,
588
+						Dealer:           dealer,
589
+						BatchNumber:      batch_number,
590
+						MaxUnit:          max_unit,
591
+						MinUnit:          min_unit,
592
+						ConsumableType:   1,
593
+						IsEdit:           1,
594
+						Creator:          adminUserInfo.AdminUser.Id,
595
+						IsSys:            0,
596
+					}
597
+
598
+					drugFlow = append(drugFlow, drugflow)
674 599
 				}
675 600
 			}
676 601
 		}
677 602
 	}
678 603
 	var errs error
679 604
 	if len(warehousingInfo) > 0 {
605
+
680 606
 		errs = service.CreateDrugWarehousingInfo(warehousingInfo)
607
+		if errs == nil {
608
+			service.CreateDrugFlow(drugFlow)
609
+			//更改库存
610
+			service.UpdateDrugInfo(warehousingInfo)
611
+
612
+		}
613
+
681 614
 	}
682 615
 
683 616
 	if len(upDateWarehousingInfo) > 0 {
617
+		var total int64
618
+		var minNumber float64
619
+		var allTotal int64
684 620
 		for _, item := range upDateWarehousingInfo {
621
+			//查询修改的记录
622
+			orderInfo, _ := service.GetDrugWarehouseOrderOne(id, item.DrugId)
623
+
624
+			info, _ := service.FindeDrugInfo(item.DrugId)
625
+
626
+			total = orderInfo.StockMaxNumber * info.MinNumber
627
+
628
+			allTotal = item.WarehousingCount*info.MinNumber - total
629
+
630
+			str := strconv.FormatInt(allTotal, 10)
631
+			minFloat, _ := strconv.ParseFloat(str, 64)
632
+
633
+			minNumber = info.Total + minFloat
634
+
635
+			lib := models.BaseDrugLib{
636
+				Total: minNumber,
637
+			}
638
+			service.UpdateBaseDrug(&lib, item.DrugId)
685 639
 			errs = service.UpDateDrugWarehousingInfo(item)
640
+			service.CreateDrugFlow(drugFlow)
686 641
 		}
687 642
 	}
688 643
 
@@ -1151,6 +1106,8 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1151 1106
 
1152 1107
 	var warehousingOutInfo []*models.DrugWarehouseOutInfo
1153 1108
 
1109
+	var drugFlow []*models.DrugFlow
1110
+
1154 1111
 	if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
1155 1112
 		thisStockIn, _ := dataBody["stockOut"].([]interface{})
1156 1113
 
@@ -1253,6 +1210,28 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1253 1210
 				}
1254 1211
 				warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1255 1212
 
1213
+				drugflow := &models.DrugFlow{
1214
+					WarehouseOutId:          warehouseOut.ID,
1215
+					WarehouseOutOrderNumber: warehousing_out_order,
1216
+					DrugId:                  drug_id,
1217
+					Number:                  number,
1218
+					ProductDate:             productDates,
1219
+					ExpireDate:              expiryDates,
1220
+					Count:                   count,
1221
+					Price:                   price,
1222
+					Status:                  1,
1223
+					Ctime:                   ctime,
1224
+					UserOrgId:               adminUserInfo.CurrentOrgId,
1225
+					Manufacturer:            manufacturer,
1226
+					Dealer:                  dealer,
1227
+					BatchNumber:             batch_number,
1228
+					MaxUnit:                 max_unit,
1229
+					ConsumableType:          2,
1230
+					IsEdit:                  1,
1231
+					Creator:                 adminUserInfo.AdminUser.Id,
1232
+					IsSys:                   0,
1233
+				}
1234
+				drugFlow = append(drugFlow, drugflow)
1256 1235
 			}
1257 1236
 		}
1258 1237
 	}
@@ -1276,6 +1255,7 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1276 1255
 			return
1277 1256
 		} else {
1278 1257
 			service.AddSigleDrugWarehouseOut(&warehouseOut)
1258
+			service.CreateDrugFlow(drugFlow)
1279 1259
 			// 出库流程
1280 1260
 			// 1.查询改药品在药品库的规格信息,并将处方里的规格进行换算(尽量将拆零单位转换成包装单位)
1281 1261
 			drup, _ := service.FindBaseDrugLibRecord(item.OrgId, item.DrugId)
@@ -1460,7 +1440,7 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1460 1440
 
1461 1441
 	var warehousingOutInfo []*models.DrugWarehouseOutInfo
1462 1442
 	var upDateWarehouseOutInfos []*models.DrugWarehouseOutInfo
1463
-
1443
+	//var drugFlow  []*models.DrugFlow
1464 1444
 	if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
1465 1445
 		thisStockOut, _ := dataBody["stockOut"].([]interface{})
1466 1446
 		if len(thisStockOut) > 0 {
@@ -1482,13 +1462,15 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1482 1462
 
1483 1463
 				count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
1484 1464
 
1465
+				count_unit, _ := items["count_unit"].(string)
1466
+
1485 1467
 				if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
1486 1468
 					utils.ErrorLog("price")
1487 1469
 					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1488 1470
 					return
1489 1471
 				}
1490 1472
 				price, _ := strconv.ParseFloat(items["price"].(string), 64)
1491
-				fmt.Println("price23223232323232323232323232322322", price)
1473
+
1492 1474
 				if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
1493 1475
 					utils.ErrorLog("retail_price")
1494 1476
 					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
@@ -1566,9 +1548,35 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1566 1548
 						Number:                  number,
1567 1549
 						ProductDate:             productDates,
1568 1550
 						ExpiryDate:              expiryDates,
1551
+						CountUnit:               count_unit,
1569 1552
 					}
1570 1553
 					warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1571 1554
 
1555
+					//drugflow := &models.DrugFlow{
1556
+					//  WarehousingOrder: warehousing.WarehousingOrder,
1557
+					//  WarehousingId:    warehousing.ID,
1558
+					//  DrugId:           drug_id,
1559
+					//  Number:           number,
1560
+					//  ProductDate:      productDates,
1561
+					//  ExpireDate:       expiryDates,
1562
+					//  Count:            warehousing_count,
1563
+					//  Price:            last_price,
1564
+					//  Status:           1,
1565
+					//  Ctime:            ctime,
1566
+					//  UserOrgId:        adminUserInfo.CurrentOrgId,
1567
+					//  Manufacturer:     manufacturer,
1568
+					//  Dealer:           dealer,
1569
+					//  BatchNumber:      batch_number,
1570
+					//  MaxUnit:          max_unit,
1571
+					//  MinUnit:          min_unit,
1572
+					//  ConsumableType:   1,
1573
+					//  IsEdit:           1,
1574
+					//  Creator:          adminUserInfo.AdminUser.Id,
1575
+					//  IsSys:0,
1576
+					//}
1577
+					//
1578
+					//drugFlow = append(drugFlow,drugflow)
1579
+
1572 1580
 				} else {
1573 1581
 					if items["is_sys"] == nil || reflect.TypeOf(items["is_sys"]).String() != "float64" {
1574 1582
 						utils.ErrorLog("is_sys")
@@ -1608,6 +1616,7 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1608 1616
 						Number:                  number,
1609 1617
 						ProductDate:             productDates,
1610 1618
 						ExpiryDate:              expiryDates,
1619
+						CountUnit:               count_unit,
1611 1620
 					}
1612 1621
 					upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
1613 1622
 				}
@@ -1723,6 +1732,47 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
1723 1732
 				retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
1724 1733
 				retail_price_total := float64(count) * retail_price
1725 1734
 
1735
+				register_account, _ := items["register_account"].(string)
1736
+
1737
+				remark, _ := items["remark"].(string)
1738
+
1739
+				var productDates int64
1740
+				var expiryDates int64
1741
+
1742
+				if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
1743
+					expiryDates = 0
1744
+				} else {
1745
+					if len(items["expiry_date"].(string)) == 0 {
1746
+						expiryDates = 0
1747
+
1748
+					} else {
1749
+						expiryDate, _ := items["expiry_date"].(string)
1750
+						expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
1751
+						expiryDates = expiry_date.Unix()
1752
+
1753
+					}
1754
+
1755
+				}
1756
+				if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
1757
+					productDates = 0
1758
+				} else {
1759
+					if len(items["product_date"].(string)) == 0 {
1760
+						productDates = 0
1761
+
1762
+					} else {
1763
+						productDate, _ := items["product_date"].(string)
1764
+						product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
1765
+						productDates = product_date.Unix()
1766
+					}
1767
+
1768
+				}
1769
+
1770
+				manufacturer, _ := items["manufacturer"].(string)
1771
+
1772
+				dealer, _ := items["dealer"].(string)
1773
+
1774
+				batch_number := items["batch_number"].(string)
1775
+				max_unit := items["max_unit"].(string)
1726 1776
 				cancelStockInfo := &models.DrugCancelStockInfo{
1727 1777
 					OrderNumber:      cancelStock.OrderNumber,
1728 1778
 					CancelStockId:    cancelStock.ID,
@@ -1732,12 +1782,18 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
1732 1782
 					Ctime:            ctime,
1733 1783
 					OrgId:            adminUserInfo.CurrentOrgId,
1734 1784
 					Type:             types,
1735
-					Manufacturer:     manufacturer_id,
1736
-					Dealer:           dealer_id,
1785
+					Manufacturer:     manufacturer,
1786
+					Dealer:           dealer,
1737 1787
 					Total:            total,
1738 1788
 					RetailPrice:      retail_price,
1739 1789
 					RetailTotalPrice: retail_price_total,
1740 1790
 					Price:            price,
1791
+					RegisterAccount:  register_account,
1792
+					Remark:           remark,
1793
+					BatchNumber:      batch_number,
1794
+					MaxUnit:          max_unit,
1795
+					ProductDate:      productDates,
1796
+					ExpiryDate:       expiryDates,
1741 1797
 				}
1742 1798
 				cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
1743 1799
 
@@ -1914,8 +1970,6 @@ func (c *StockDrugApiController) EditDrugCancelStock() {
1914 1970
 
1915 1971
 				count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
1916 1972
 
1917
-				//count, _ := strconv.ParseInt(return_count, 10, 64)
1918
-
1919 1973
 				if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
1920 1974
 					utils.ErrorLog("price")
1921 1975
 					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
@@ -1939,6 +1993,48 @@ func (c *StockDrugApiController) EditDrugCancelStock() {
1939 1993
 				}
1940 1994
 				id := int64(items["id"].(float64))
1941 1995
 
1996
+				max_unit := items["max_unit"].(string)
1997
+				batch_number := items["batch_number"].(string)
1998
+
1999
+				register_account := items["register_account"].(string)
2000
+
2001
+				remark := items["remark"].(string)
2002
+
2003
+				manufacturer := items["manufacturer"].(string)
2004
+
2005
+				dealer := items["dealer"].(string)
2006
+
2007
+				var productDates int64
2008
+				var expiryDates int64
2009
+
2010
+				if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
2011
+					expiryDates = 0
2012
+				} else {
2013
+					if len(items["expiry_date"].(string)) == 0 {
2014
+						expiryDates = 0
2015
+
2016
+					} else {
2017
+						expiryDate, _ := items["expiry_date"].(string)
2018
+						expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
2019
+						expiryDates = expiry_date.Unix()
2020
+
2021
+					}
2022
+
2023
+				}
2024
+				if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
2025
+					productDates = 0
2026
+				} else {
2027
+					if len(items["product_date"].(string)) == 0 {
2028
+						productDates = 0
2029
+
2030
+					} else {
2031
+						productDate, _ := items["product_date"].(string)
2032
+						product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
2033
+						productDates = product_date.Unix()
2034
+					}
2035
+
2036
+				}
2037
+
1942 2038
 				if id == 0 {
1943 2039
 					cancelStockInfo := &models.DrugCancelStockInfo{
1944 2040
 						DrugId:           drug_id,
@@ -1950,12 +2046,18 @@ func (c *StockDrugApiController) EditDrugCancelStock() {
1950 2046
 						CancelStockId:    cancelStock.ID,
1951 2047
 						Mtime:            time.Now().Unix(),
1952 2048
 						Type:             types,
1953
-						Manufacturer:     manufacturer_id,
1954
-						Dealer:           dealer_id,
1955 2049
 						RetailPrice:      retail_price,
1956 2050
 						RetailTotalPrice: retail_price_total,
1957 2051
 						Price:            price,
1958 2052
 						Total:            total,
2053
+						Manufacturer:     manufacturer,
2054
+						Dealer:           dealer,
2055
+						RegisterAccount:  register_account,
2056
+						MaxUnit:          max_unit,
2057
+						BatchNumber:      batch_number,
2058
+						Remark:           remark,
2059
+						ProductDate:      productDates,
2060
+						ExpiryDate:       expiryDates,
1959 2061
 					}
1960 2062
 					cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
1961 2063
 
@@ -1971,12 +2073,18 @@ func (c *StockDrugApiController) EditDrugCancelStock() {
1971 2073
 						CancelStockId:    cancelStock.ID,
1972 2074
 						Mtime:            time.Now().Unix(),
1973 2075
 						Type:             types,
1974
-						Manufacturer:     manufacturer_id,
1975
-						Dealer:           dealer_id,
1976 2076
 						RetailPrice:      retail_price,
1977 2077
 						RetailTotalPrice: retail_price_total,
1978 2078
 						Price:            price,
1979 2079
 						Total:            total,
2080
+						Manufacturer:     manufacturer,
2081
+						Dealer:           dealer,
2082
+						RegisterAccount:  register_account,
2083
+						MaxUnit:          max_unit,
2084
+						BatchNumber:      batch_number,
2085
+						Remark:           remark,
2086
+						ProductDate:      productDates,
2087
+						ExpiryDate:       expiryDates,
1980 2088
 					}
1981 2089
 					upDateCancelStockInfos = append(upDateCancelStockInfos, cancelStockInfo)
1982 2090
 				}
@@ -2096,3 +2204,26 @@ func (this *StockDrugApiController) GetUserDetailInfo() {
2096 2204
 	}
2097 2205
 
2098 2206
 }
2207
+
2208
+func (this *StockDrugApiController) GetCancelDrugOrderPrint() {
2209
+
2210
+	orderId := this.GetString("order_id")
2211
+	ids := strings.Split(orderId, ",")
2212
+	orgId := this.GetAdminUserInfo().CurrentOrgId
2213
+	list, _ := service.GetCancelDrugOrderPrint(ids, orgId)
2214
+	this.ServeSuccessJSON(map[string]interface{}{
2215
+		"list": list,
2216
+	})
2217
+}
2218
+
2219
+func (this *StockDrugApiController) GetDrugCancelExportList() {
2220
+
2221
+	orderId := this.GetString("order_id")
2222
+	fmt.Println("order_id2323232323223", orderId)
2223
+	ids := strings.Split(orderId, ",")
2224
+	orgId := this.GetAdminUserInfo().CurrentOrgId
2225
+	list, _ := service.GetDrugCancelExportList(ids, orgId)
2226
+	this.ServeSuccessJSON(map[string]interface{}{
2227
+		"list": list,
2228
+	})
2229
+}

+ 87 - 0
controllers/gobal_config_api_controller.go Vedi File

@@ -102,6 +102,10 @@ func GobalConfigRegistRouters() {
102 102
 	beego.Router("/api/drug/getdrugorderinprint", &GobalConfigApiController{}, "Get:GetDrugOrderInPrint")
103 103
 	beego.Router("/api/drug/getdrugoutorderdetailprint", &GobalConfigApiController{}, "Get:GetDrugOutOrderPrint")
104 104
 	beego.Router("/api/drug/getdrugbatchnumber", &GobalConfigApiController{}, "Get:GetDrugBatchNumber")
105
+	beego.Router("/api/drug/exportdruglist", &GobalConfigApiController{}, "Get:ExportDrugList")
106
+	beego.Router("/api/drug/getexportoutorderdruglist", &GobalConfigApiController{}, "Get:GetExportOutOrderDrugList")
107
+	beego.Router("/api/drug/getdrugflow", &GobalConfigApiController{}, "Get:GetDrugFlow")
108
+	beego.Router("/api/drug/getcancelstockdetail", &GobalConfigApiController{}, "Get:GetCancelStockDetail")
105 109
 }
106 110
 
107 111
 //provinces, _ := service.GetDistrictsByUpid(0)21
@@ -2101,3 +2105,86 @@ func (c *GobalConfigApiController) GetDrugBatchNumber() {
2101 2105
 		"list": list,
2102 2106
 	})
2103 2107
 }
2108
+
2109
+func (c *GobalConfigApiController) ExportDrugList() {
2110
+
2111
+	orderId := c.GetString("order_id")
2112
+	ids := strings.Split(orderId, ",")
2113
+	list, _ := service.ExportDrugList(ids)
2114
+	orgId := c.GetAdminUserInfo().CurrentOrgId
2115
+	manufacturerList, _ := service.GetAllManufacturerList(orgId)
2116
+	dealerList, _ := service.GetAllDealerList(orgId)
2117
+	c.ServeSuccessJSON(map[string]interface{}{
2118
+		"list":             list,
2119
+		"manufacturerList": manufacturerList,
2120
+		"dealerList":       dealerList,
2121
+	})
2122
+}
2123
+
2124
+func (c *GobalConfigApiController) GetExportOutOrderDrugList() {
2125
+
2126
+	orderId := c.GetString("order_id")
2127
+	ids := strings.Split(orderId, ",")
2128
+	orgId := c.GetAdminUserInfo().CurrentOrgId
2129
+	list, _ := service.GetExportOutOrderDrugList(ids)
2130
+	manufacturerList, _ := service.GetAllManufacturerList(orgId)
2131
+	dealerList, _ := service.GetAllDealerList(orgId)
2132
+	c.ServeSuccessJSON(map[string]interface{}{
2133
+		"list":             list,
2134
+		"manufacturerList": manufacturerList,
2135
+		"dealerList":       dealerList,
2136
+	})
2137
+}
2138
+
2139
+func (c *GobalConfigApiController) GetDrugFlow() {
2140
+
2141
+	start_time := c.GetString("start_time")
2142
+	end_time := c.GetString("end_time")
2143
+
2144
+	timeLayout := "2006-01-02"
2145
+	loc, _ := time.LoadLocation("Local")
2146
+	var startTime int64
2147
+	if len(start_time) > 0 {
2148
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
2149
+		if err != nil {
2150
+			fmt.Println(err)
2151
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
2152
+			return
2153
+		}
2154
+		startTime = theTime.Unix()
2155
+	}
2156
+	var endTime int64
2157
+	if len(end_time) > 0 {
2158
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
2159
+		if err != nil {
2160
+			utils.ErrorLog(err.Error())
2161
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
2162
+			return
2163
+		}
2164
+		endTime = theTime.Unix()
2165
+	}
2166
+	orgId := c.GetAdminUserInfo().CurrentOrgId
2167
+	drug_id, _ := c.GetInt64("drug_id")
2168
+	page, _ := c.GetInt64("page")
2169
+	limit, _ := c.GetInt64("limit")
2170
+	stock_type, _ := c.GetInt64("stock_type")
2171
+
2172
+	list, total, _ := service.GetDrugFlow(drug_id, orgId, limit, page, startTime, endTime, stock_type)
2173
+	manufacturerList, _ := service.GetAllManufacturerList(orgId)
2174
+	dealerList, _ := service.GetAllDealerList(orgId)
2175
+	c.ServeSuccessJSON(map[string]interface{}{
2176
+		"list":             list,
2177
+		"total":            total,
2178
+		"manufacturerList": manufacturerList,
2179
+		"dealerList":       dealerList,
2180
+	})
2181
+}
2182
+
2183
+func (c *GobalConfigApiController) GetCancelStockDetail() {
2184
+
2185
+	id, _ := c.GetInt64("id")
2186
+	list, _ := service.GetCancelStockDetail(id)
2187
+	c.ServeSuccessJSON(map[string]interface{}{
2188
+		"list": list,
2189
+	})
2190
+}

File diff suppressed because it is too large
+ 576 - 365
controllers/mobile_api_controllers/dialysis_api_controller.go


+ 535 - 190
controllers/stock_in_api_controller.go Vedi File

@@ -95,6 +95,10 @@ func StockManagerApiRegistRouters() {
95 95
 	beego.Router("/api/stock/getcancelstockorderprint", &StockManagerApiController{}, "Get:GetCancelStockOrderPrint")
96 96
 	beego.Router("/api/stock/getstockbatchnumber", &StockManagerApiController{}, "Get:GetStockBatchNumber")
97 97
 
98
+	beego.Router("/api/stock/getstockflow", &StockManagerApiController{}, "Get:GetStockFlow")
99
+
100
+	beego.Router("/api/cancel/getcancelexportlist", &StockManagerApiController{}, "Get:GetCancelExportList")
101
+
98 102
 }
99 103
 
100 104
 func (c *StockManagerApiController) CreateWarehouse() {
@@ -140,6 +144,7 @@ func (c *StockManagerApiController) CreateWarehouse() {
140 144
 
141 145
 	var warehousingInfo []*models.WarehousingInfo
142 146
 
147
+	var stockFlow []*models.VmStockFlow
143 148
 	if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
144 149
 		thisStockIn, _ := dataBody["stockIn"].([]interface{})
145 150
 		if len(thisStockIn) > 0 {
@@ -179,8 +184,6 @@ func (c *StockManagerApiController) CreateWarehouse() {
179 184
 				var productDates int64
180 185
 				var expiryDates int64
181 186
 
182
-				fmt.Println()
183
-
184 187
 				if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
185 188
 					expiryDates = 0
186 189
 				} else {
@@ -217,6 +220,7 @@ func (c *StockManagerApiController) CreateWarehouse() {
217 220
 				dealer := int64(items["dealer"].(float64))
218 221
 
219 222
 				license_number, _ := items["license_number"].(string)
223
+				//入库单表格
220 224
 				warehouseInfo := &models.WarehousingInfo{
221 225
 					WarehousingOrder: warehousing.WarehousingOrder,
222 226
 					WarehousingId:    warehousing.ID,
@@ -240,10 +244,38 @@ func (c *StockManagerApiController) CreateWarehouse() {
240 244
 				}
241 245
 				warehousingInfo = append(warehousingInfo, warehouseInfo)
242 246
 
247
+				flow := &models.VmStockFlow{
248
+					WarehousingOrder:    warehousing.WarehousingOrder,
249
+					WarehousingId:       warehousing.ID,
250
+					GoodId:              good_id,
251
+					Number:              number,
252
+					ProductDate:         productDates,
253
+					ExpireDate:          expiryDates,
254
+					Count:               warehousing_count,
255
+					Price:               price,
256
+					Status:              1,
257
+					Ctime:               ctime,
258
+					UserOrgId:           adminUserInfo.CurrentOrgId,
259
+					Manufacturer:        manufacturer,
260
+					Dealer:              dealer,
261
+					LicenseNumber:       license_number,
262
+					IsEdit:              1,
263
+					Creator:             adminUserInfo.AdminUser.Id,
264
+					SystemTime:          operation_time,
265
+					ConsumableType:      1,
266
+					WarehousingDetailId: warehouseInfo.ID,
267
+				}
268
+				stockFlow = append(stockFlow, flow)
243 269
 			}
244 270
 		}
245 271
 	}
272
+
273
+	//入库单创建成功
246 274
 	errs := service.CreateWarehousingInfo(warehousingInfo)
275
+
276
+	//创建入库单流水
277
+	service.CreateStockFlow(stockFlow)
278
+
247 279
 	info, _ := service.FindLastWarehousingInfo(warehousing.WarehousingOrder)
248 280
 
249 281
 	if errs != nil {
@@ -257,141 +289,6 @@ func (c *StockManagerApiController) CreateWarehouse() {
257 289
 		"warehousing_order": warehousing_order,
258 290
 		"info":              info,
259 291
 	})
260
-	//}
261
-
262
-	//else {
263
-	//	warehouse, err1 := service.FindWareHouseByOrderNumber(warehousing_order)
264
-	//	if (err1 != nil) {
265
-	//		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
266
-	//		return
267
-	//	}
268
-	//
269
-	//	dataBody := make(map[string]interface{}, 0)
270
-	//	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
271
-	//	if err != nil {
272
-	//		utils.ErrorLog(err.Error())
273
-	//		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
274
-	//		return
275
-	//	}
276
-	//
277
-	//	var warehousingInfo []*models.WarehousingInfo
278
-	//
279
-	//	if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
280
-	//		thisStockIn, _ := dataBody["stockIn"].([]interface{})
281
-	//		if len(thisStockIn) > 0 {
282
-	//			for _, item := range thisStockIn {
283
-	//				items := item.(map[string]interface{})
284
-	//
285
-	//				if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
286
-	//					utils.ErrorLog("good_id")
287
-	//					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
288
-	//					return
289
-	//				}
290
-	//				good_id := int64(items["good_id"].(float64))
291
-	//
292
-	//				if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
293
-	//					utils.ErrorLog("good_type_id")
294
-	//					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
295
-	//					return
296
-	//				}
297
-	//				good_type_id := int64(items["good_type_id"].(float64))
298
-	//
299
-	//				if items["warehousing_count"] == nil || reflect.TypeOf(items["warehousing_count"]).String() != "string" {
300
-	//					utils.ErrorLog("warehousing_count")
301
-	//					c.ServeFailJSONWithSGJErrorCod  Fe(enums.ErrorCodeParamWrong)
302
-	//					return
303
-	//				}
304
-	//
305
-	//				warehousing_count, _ := strconv.ParseInt(items["warehousing_count"].(string), 10, 64)
306
-	//
307
-	//				if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
308
-	//					utils.ErrorLog("price")
309
-	//					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
310
-	//					return
311
-	//				}
312
-	//				price, _ := strconv.ParseFloat(items["price"].(string), 64)
313
-	//				total := float64(warehousing_count) * price
314
-	//
315
-	//				if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
316
-	//					utils.ErrorLog("expiry_date")
317
-	//					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
318
-	//					return
319
-	//				}
320
-	//
321
-	//				expiryDate, _ := items["expiry_date"].(string)
322
-	//				if len(expiryDate) == 0 {
323
-	//					utils.ErrorLog("len(expiry_date) == 0")
324
-	//					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
325
-	//
326
-	//					return
327
-	//				}
328
-	//
329
-	//				expiry_date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
330
-	//				if parseDateErr != nil {
331
-	//					c.ErrorLog("日期(%v)解析错误:%v", expiry_date, parseDateErr)
332
-	//				}
333
-	//
334
-	//				var productDates int64
335
-	//
336
-	//				if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
337
-	//					productDates = 0;
338
-	//				} else {
339
-	//					productDate, _ := items["product_date"].(string)
340
-	//					product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
341
-	//					productDates = product_date.Unix()
342
-	//
343
-	//				}
344
-	//
345
-	//				if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
346
-	//					utils.ErrorLog("number")
347
-	//					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
348
-	//					return
349
-	//				}
350
-	//				number, _ := items["number"].(string)
351
-	//
352
-	//				var remark string
353
-	//				if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
354
-	//					remark = ""
355
-	//				} else {
356
-	//					remark = items["remark"].(string)
357
-	//				}
358
-	//
359
-	//				warehouseInfo := &models.WarehousingInfo{
360
-	//					WarehousingOrder: warehousing_order,
361
-	//					WarehousingId:    warehouse.ID,
362
-	//					GoodId:           good_id,
363
-	//					Number:           number,
364
-	//					GoodTypeId:       good_type_id,
365
-	//					ProductDate:      productDates,
366
-	//					ExpiryDate:       expiry_date.Unix(),
367
-	//					WarehousingCount: warehousing_count,
368
-	//					Price:            price,
369
-	//					TotalPrice:       total,
370
-	//					Status:           1,
371
-	//					Ctime:            ctime,
372
-	//					Remark:           remark,
373
-	//					OrgId:            adminUserInfo.CurrentOrgId,
374
-	//				}
375
-	//				warehousingInfo = append(warehousingInfo, warehouseInfo)
376
-	//
377
-	//			}
378
-	//		}
379
-	//	}
380
-	//	errs := service.CreateWarehousingInfo(warehousingInfo)
381
-	//	info, _ := service.FindLastWarehousingInfo(warehousing_order)
382
-	//
383
-	//	if (errs != nil) {
384
-	//		utils.ErrorLog(errs.Error())
385
-	//		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
386
-	//		return
387
-	//	}
388
-	//
389
-	//	c.ServeSuccessJSON(map[string]interface{}{
390
-	//		"msg":  "入库成功",
391
-	//		"info": info,
392
-	//	})
393
-	//
394
-	//}
395 292
 
396 293
 }
397 294
 func (c *StockManagerApiController) GetWarehouseList() {
@@ -525,6 +422,7 @@ func (c *StockManagerApiController) EditWarehouse() {
525 422
 
526 423
 	var warehousingInfo []*models.WarehousingInfo
527 424
 	var upDateWarehousingInfo []*models.WarehousingInfo
425
+	var stockFlow []*models.VmStockFlow
528 426
 
529 427
 	if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
530 428
 		thisStockIn, _ := dataBody["stockIn"].([]interface{})
@@ -631,6 +529,30 @@ func (c *StockManagerApiController) EditWarehouse() {
631 529
 					}
632 530
 					warehousingInfo = append(warehousingInfo, warehouseInfo)
633 531
 
532
+					flow := &models.VmStockFlow{
533
+						WarehousingOrder:    warehousing.WarehousingOrder,
534
+						WarehousingId:       warehousing.ID,
535
+						GoodId:              good_id,
536
+						Number:              number,
537
+						ProductDate:         productDates,
538
+						ExpireDate:          expiryDates,
539
+						Count:               warehousing_count,
540
+						Price:               price,
541
+						Status:              1,
542
+						Ctime:               ctime,
543
+						UserOrgId:           adminUserInfo.CurrentOrgId,
544
+						Manufacturer:        manufacturer,
545
+						Dealer:              dealer,
546
+						LicenseNumber:       license_number,
547
+						IsEdit:              1,
548
+						Creator:             adminUserInfo.AdminUser.Id,
549
+						SystemTime:          ctime,
550
+						ConsumableType:      1,
551
+						WarehousingDetailId: warehouseInfo.ID,
552
+					}
553
+
554
+					stockFlow = append(stockFlow, flow)
555
+
634 556
 				} else {
635 557
 					warehouseInfo := &models.WarehousingInfo{
636 558
 						ID:               id,
@@ -655,6 +577,30 @@ func (c *StockManagerApiController) EditWarehouse() {
655 577
 						LicenseNumber:    license_number,
656 578
 					}
657 579
 					upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
580
+
581
+					flow := &models.VmStockFlow{
582
+						WarehousingOrder:    warehousing.WarehousingOrder,
583
+						WarehousingId:       warehousing.ID,
584
+						GoodId:              good_id,
585
+						Number:              number,
586
+						ProductDate:         productDates,
587
+						ExpireDate:          expiryDates,
588
+						Count:               warehousing_count,
589
+						Price:               price,
590
+						Status:              1,
591
+						Ctime:               ctime,
592
+						UserOrgId:           adminUserInfo.CurrentOrgId,
593
+						Manufacturer:        manufacturer,
594
+						Dealer:              dealer,
595
+						LicenseNumber:       license_number,
596
+						IsEdit:              2,
597
+						Creator:             adminUserInfo.AdminUser.Id,
598
+						SystemTime:          ctime,
599
+						ConsumableType:      1,
600
+						WarehousingDetailId: warehouseInfo.ID,
601
+					}
602
+
603
+					stockFlow = append(stockFlow, flow)
658 604
 				}
659 605
 			}
660 606
 		}
@@ -662,11 +608,26 @@ func (c *StockManagerApiController) EditWarehouse() {
662 608
 	var errs error
663 609
 	if len(warehousingInfo) > 0 {
664 610
 		errs = service.CreateWarehousingInfo(warehousingInfo)
611
+		service.CreateStockFlow(stockFlow)
665 612
 	}
666 613
 
667 614
 	if len(upDateWarehousingInfo) > 0 {
615
+
668 616
 		for _, item := range upDateWarehousingInfo {
617
+			var total int64
618
+			var all_total int64
619
+			//获取该批次该型号的库存
620
+			info, _ := service.GetLastWarehousingById(item.WarehousingId, item.GoodId)
621
+
622
+			//判断 该批次的入库数量
623
+			total = item.WarehousingCount - info.WarehousingCount
624
+
625
+			all_total = info.StockCount + total
626
+
627
+			item.StockCount = all_total
669 628
 			errs = service.UpDateWarehousingInfo(item)
629
+
630
+			service.CreateStockFlow(stockFlow)
670 631
 		}
671 632
 	}
672 633
 
@@ -1110,6 +1071,7 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1110 1071
 	var warehousingOutInfo []*models.WarehouseOutInfo
1111 1072
 	var beforePrepares []*models.DialysisBeforePrepareGoods
1112 1073
 	var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
1074
+
1113 1075
 	if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
1114 1076
 		thisStockIn, _ := dataBody["stockOut"].([]interface{})
1115 1077
 		if len(thisStockIn) > 0 {
@@ -1143,7 +1105,7 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1143 1105
 					return
1144 1106
 				}
1145 1107
 				price, _ := strconv.ParseFloat(items["price"].(string), 64)
1146
-				fmt.Println("999999992932323232323223232322323", price)
1108
+
1147 1109
 				count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
1148 1110
 
1149 1111
 				total := float64(count) * price
@@ -1234,12 +1196,12 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1234 1196
 			})
1235 1197
 			return
1236 1198
 		} else {
1237
-			fmt.Println("jiage223444444444444444444", item.Price)
1199
+
1238 1200
 			_, errcodes := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
1239 1201
 			if errcodes == gorm.ErrRecordNotFound {
1240 1202
 				service.AddSigleWarehouseOut(&warehouseOut)
1241 1203
 			}
1242
-			parseDateErr := service.ConsumablesDeliveryOne(adminUserInfo.CurrentOrgId, warehousingOutDate.Unix(), item, &warehouseOut, item.Count)
1204
+			parseDateErr := service.ConsumablesDeliveryOne(adminUserInfo.CurrentOrgId, warehousingOutDate.Unix(), item, &warehouseOut, item.Count, creater)
1243 1205
 			if parseDateErr != nil {
1244 1206
 				utils.ErrorLog(parseDateErr.Error())
1245 1207
 				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
@@ -1464,10 +1426,11 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1464 1426
 				number := items["number"].(string)
1465 1427
 
1466 1428
 				license_number := items["license_number"].(string)
1467
-				fmt.Println("hhh23h2h32h3h232h3h23h2h3h23h2h3h23h2h3", license_number)
1429
+
1468 1430
 				timeLayout := "2006-01-02"
1469 1431
 				loc, _ := time.LoadLocation("Local")
1470 1432
 				expiry_date := items["expiry_date"].(string)
1433
+
1471 1434
 				var expiryDate int64
1472 1435
 				if len(expiry_date) > 0 {
1473 1436
 					theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
@@ -1480,6 +1443,8 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1480 1443
 
1481 1444
 				product_date := items["product_date"].(string)
1482 1445
 
1446
+				warehouse_info_id := int64(items["warehouse_info_id"].(float64))
1447
+
1483 1448
 				var productDate int64
1484 1449
 				if len(product_date) > 0 {
1485 1450
 					theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
@@ -1512,6 +1477,8 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1512 1477
 						Dealer:                  dealer,
1513 1478
 						Manufacturer:            manufacturer,
1514 1479
 						LicenseNumber:           license_number,
1480
+						ConsumableType:          1,
1481
+						WarehouseInfotId:        warehouse_info_id,
1515 1482
 					}
1516 1483
 					warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1517 1484
 
@@ -1553,6 +1520,8 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1553 1520
 						ProductDate:             productDate,
1554 1521
 						Dealer:                  dealer,
1555 1522
 						LicenseNumber:           license_number,
1523
+						ConsumableType:          2,
1524
+						WarehouseInfotId:        warehouse_info_id,
1556 1525
 					}
1557 1526
 					upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
1558 1527
 				}
@@ -1561,12 +1530,191 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1561 1530
 	}
1562 1531
 	var errs error
1563 1532
 	if len(warehousingOutInfo) > 0 {
1533
+
1564 1534
 		errs = service.CreateWarehousingOutInfo(warehousingOutInfo)
1565 1535
 	}
1566 1536
 
1567 1537
 	if len(upDateWarehouseOutInfos) > 0 {
1568 1538
 		for _, item := range upDateWarehouseOutInfos {
1569
-			errs = service.UpDateWarehouseOutInfo(item)
1539
+
1540
+			//1.查询该耗材该批次的最后一次出库记录
1541
+			lastGood, _ := service.GetLastGoodInformationByGoodId(item.GoodId, item.WarehouseInfotId, adminUserInfo.CurrentOrgId)
1542
+
1543
+			// 退库的库存和该耗材该批次最后一次出库数量进行比较
1544
+			//如果退库数量大于 最后一次批次的数量(要么要进行出库)
1545
+
1546
+			if item.Count > lastGood.Count {
1547
+
1548
+				//查询该耗材是否还有库存
1549
+				warehouseinfo, _ := service.GetTotalCountByGoodId(item.GoodId)
1550
+				fmt.Println("hhhhhh23h2323232", warehouseinfo.StockCount)
1551
+				//无库存
1552
+				if warehouseinfo.StockCount <= 0 {
1553
+					c.ServeSuccessJSON(map[string]interface{}{
1554
+						"msg": "5",
1555
+					})
1556
+					return
1557
+				}
1558
+
1559
+				//有库存,进行出库,调用出库接口
1560
+				if warehouseinfo.StockCount > 0 {
1561
+					var total int64
1562
+					var stock_cout int64
1563
+					var total_count int64
1564
+					//计算和最后一次出库数据的差
1565
+					total = item.Count - lastGood.Count
1566
+					fmt.Println("total22323232", total)
1567
+					//获取该耗材该批次的剩余库存量
1568
+					info, _ := service.GetLastGoodCountById(item.GoodId, item.WarehouseInfotId)
1569
+					fmt.Println("info2232323232323", info)
1570
+					//判断该批次的剩余库存 和出库的库存进行比较
1571
+					//如果出库的库存大于该批次的剩余库存,那么需要出库下一批次的库存
1572
+
1573
+					if item.Count > info.StockCount {
1574
+						//计算出库和该批次相差的库存
1575
+						total_count = item.Count - info.StockCount
1576
+						//清空本批次次库存
1577
+						service.DeleteWarehouseInfo(item.WarehouseInfotId)
1578
+						//调用出库逻辑
1579
+						service.ConsumablesDeliveryTwo(item.OrgId, item, total_count)
1580
+					}
1581
+					//如果出库的库存小于或等于于该批次的剩余库存,那么需要该批次出库
1582
+					if item.Count <= info.StockCount {
1583
+						stock_cout = lastGood.Count + total
1584
+						fmt.Println("232323223232323232323232", stock_cout)
1585
+						//扣减库存
1586
+						warehouse := models.WarehousingInfo{
1587
+							StockCount: info.StockCount - total,
1588
+						}
1589
+						errs := service.UpdateWarehousingInfo(warehouse, info.ID)
1590
+
1591
+						warehouseOutInfo := &models.WarehouseOutInfo{
1592
+							WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1593
+							WarehouseOutId:          id,
1594
+							WarehouseInfotId:        item.WarehouseInfotId,
1595
+							Status:                  1,
1596
+							Ctime:                   time.Now().Unix(),
1597
+							Remark:                  item.Remark,
1598
+							OrgId:                   item.OrgId,
1599
+							Type:                    1,
1600
+							Manufacturer:            item.Manufacturer,
1601
+							Dealer:                  item.Dealer,
1602
+							IsSys:                   0,
1603
+							SysRecordTime:           item.SysRecordTime,
1604
+							GoodTypeId:              item.GoodTypeId,
1605
+							GoodId:                  item.GoodId,
1606
+							ExpiryDate:              item.ExpiryDate,
1607
+							ProductDate:             item.ProductDate,
1608
+							Number:                  item.Number,
1609
+							Price:                   item.Price,
1610
+							LicenseNumber:           item.LicenseNumber,
1611
+							Count:                   item.Count,
1612
+							ConsumableType:          2,
1613
+						}
1614
+
1615
+						//查询是否存在
1616
+						_, errcode := service.GetWarehouseOutInfoIsExist(item.ID)
1617
+						if errcode == gorm.ErrRecordNotFound {
1618
+							errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
1619
+							if errOne != nil {
1620
+								utils.ErrorLog(errs.Error())
1621
+								c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
1622
+								return
1623
+							}
1624
+							c.ServeSuccessJSON(map[string]interface{}{
1625
+								"msg": "编辑成功",
1626
+							})
1627
+						} else if errcode == nil {
1628
+							service.UpDateWarehouseOutInfo(item)
1629
+						}
1630
+
1631
+					}
1632
+				}
1633
+			}
1634
+
1635
+			var last_count int64
1636
+			var all_total int64
1637
+			var stock_total int64
1638
+			//如果退库数量小于最后一次批次的数量(要么要进行退库)
1639
+			if item.Count < lastGood.Count {
1640
+				fmt.Println("hh232323h2h3hh23hh23hh2h3h23")
1641
+				//退库数量和最后一次出库数据进行计算
1642
+				last_count = lastGood.Count - item.Count
1643
+				fmt.Println("last_count", last_count)
1644
+				//获取该耗材该批次的剩余库存量
1645
+				infoInfo, _ := service.GetLastGoodCountById(item.GoodId, item.WarehouseInfotId)
1646
+
1647
+				//退库数量和最后一次出库数据进行计算的差 加上 剩余库存的数量与 该批次的入库数量进行比较
1648
+				all_total = last_count + infoInfo.StockCount
1649
+				fmt.Println("all_total", all_total)
1650
+				//如果库存大于总数量,则退回到这个批次
1651
+				fmt.Println("inf232323", infoInfo.WarehousingCount)
1652
+
1653
+				if infoInfo.WarehousingCount > all_total {
1654
+					stock_total = last_count + infoInfo.StockCount
1655
+					fmt.Println("经历323232323232232", last_count, stock_total)
1656
+					//退回该批次,计算数量
1657
+					warehousingInfoOne := models.WarehousingInfo{
1658
+						StockCount: stock_total,
1659
+						ID:         item.WarehouseInfotId,
1660
+						OrgId:      item.OrgId,
1661
+					}
1662
+					fmt.Println("********************", warehousingInfoOne, item.WarehouseInfotId)
1663
+					parseDateErr := service.UpdateWarehousingInfo(warehousingInfoOne, item.WarehouseInfotId)
1664
+					fmt.Println("parseDateErr2323232322323", parseDateErr)
1665
+					//插入一条新纪录
1666
+					warehouseOutInfoThree := &models.WarehouseOutInfo{
1667
+						WarehouseOutOrderNumber: item.WarehouseOutOrderNumber,
1668
+						WarehouseOutId:          id,
1669
+						WarehouseInfotId:        item.WarehouseInfotId,
1670
+						Status:                  1,
1671
+						Ctime:                   time.Now().Unix(),
1672
+						Remark:                  item.Remark,
1673
+						OrgId:                   item.OrgId,
1674
+						Type:                    1,
1675
+						Manufacturer:            item.Manufacturer,
1676
+						Dealer:                  item.Dealer,
1677
+						IsSys:                   0,
1678
+						GoodTypeId:              item.GoodTypeId,
1679
+						GoodId:                  item.GoodId,
1680
+						ExpiryDate:              item.ExpiryDate,
1681
+						ProductDate:             item.ProductDate,
1682
+						Number:                  item.Number,
1683
+						Price:                   item.Price,
1684
+						LicenseNumber:           item.LicenseNumber,
1685
+						ConsumableType:          2,
1686
+						Count:                   item.Count,
1687
+					}
1688
+					//查询是否存在
1689
+					_, errcode := service.GetWarehouseOutInfoIsExist(item.ID)
1690
+					if errcode == gorm.ErrRecordNotFound {
1691
+						errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfoThree)
1692
+						if errOne != nil {
1693
+							utils.ErrorLog(errs.Error())
1694
+							c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
1695
+							return
1696
+						}
1697
+						c.ServeSuccessJSON(map[string]interface{}{
1698
+							"msg": "编辑成功",
1699
+						})
1700
+					} else if errcode == nil {
1701
+						service.UpDateWarehouseOutInfo(item)
1702
+					}
1703
+				}
1704
+
1705
+				//如果库存小于总数量,则报错提醒,该批次的退库数据大于入库数据了无法退库,则需要退库到另一个批次
1706
+				if infoInfo.WarehousingCount < all_total {
1707
+					c.ServeSuccessJSON(map[string]interface{}{
1708
+						"msg": "6",
1709
+					})
1710
+					return
1711
+				}
1712
+			}
1713
+
1714
+			if item.Count == lastGood.Count {
1715
+				errs = service.UpDateWarehouseOutInfo(item)
1716
+			}
1717
+
1570 1718
 		}
1571 1719
 	}
1572 1720
 
@@ -1577,14 +1725,13 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1577 1725
 	}
1578 1726
 
1579 1727
 	c.ServeSuccessJSON(map[string]interface{}{
1580
-		"msg": "编辑成功",
1728
+		"msg": "1",
1581 1729
 	})
1582 1730
 
1583 1731
 }
1584 1732
 
1585 1733
 func (c *StockManagerApiController) CreateCancelStock() {
1586
-	dealer_id, _ := c.GetInt64("dealer_id", 0)
1587
-	manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
1734
+
1588 1735
 	cancel_stock_time := c.GetString("time")
1589 1736
 	types, _ := c.GetInt64("type", 0)
1590 1737
 
@@ -1607,16 +1754,14 @@ func (c *StockManagerApiController) CreateCancelStock() {
1607 1754
 	orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
1608 1755
 
1609 1756
 	cancelStock := models.CancelStock{
1610
-		OrderNumber:  orderNumber,
1611
-		OperaTime:    operation_time,
1612
-		OrgId:        adminUserInfo.CurrentOrgId,
1613
-		Creater:      creater,
1614
-		Ctime:        ctime,
1615
-		Status:       1,
1616
-		ReturnTime:   cancelStockDate.Unix(),
1617
-		Dealer:       dealer_id,
1618
-		Manufacturer: manufacturer_id,
1619
-		Type:         types,
1757
+		OrderNumber: orderNumber,
1758
+		OperaTime:   operation_time,
1759
+		OrgId:       adminUserInfo.CurrentOrgId,
1760
+		Creater:     creater,
1761
+		Ctime:       ctime,
1762
+		Status:      1,
1763
+		ReturnTime:  cancelStockDate.Unix(),
1764
+		Type:        types,
1620 1765
 	}
1621 1766
 	service.AddSigleCancelStock(&cancelStock)
1622 1767
 	dataBody := make(map[string]interface{}, 0)
@@ -1659,18 +1804,71 @@ func (c *StockManagerApiController) CreateCancelStock() {
1659 1804
 
1660 1805
 				count, _ := strconv.ParseInt(return_count, 10, 64)
1661 1806
 
1807
+				number := items["number"].(string)
1808
+
1809
+				register_account := items["register_account"].(string)
1810
+
1811
+				manufacturer, _ := items["manufacturer"].(string)
1812
+
1813
+				dealer, _ := items["dealer"].(string)
1814
+
1815
+				//productDate, _ := items["product_date"].(string)
1816
+				//product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
1817
+				//
1818
+				//expiryDate, _ := items["expiry_date"].(string)
1819
+				//expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
1820
+				var expiryDates int64
1821
+				if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
1822
+					expiryDates = 0
1823
+				} else {
1824
+					if len(items["expiry_date"].(string)) == 0 {
1825
+						expiryDates = 0
1826
+
1827
+					} else {
1828
+						expiryDate, _ := items["expiry_date"].(string)
1829
+						expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
1830
+						expiryDates = expiry_date.Unix()
1831
+
1832
+					}
1833
+				}
1834
+
1835
+				var productDates int64
1836
+				if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
1837
+					productDates = 0
1838
+				} else {
1839
+					if len(items["product_date"].(string)) == 0 {
1840
+						productDates = 0
1841
+
1842
+					} else {
1843
+						productDate, _ := items["product_date"].(string)
1844
+						product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
1845
+						productDates = product_date.Unix()
1846
+
1847
+					}
1848
+				}
1849
+
1850
+				remark := items["remark"].(string)
1851
+
1852
+				retail_prices := items["price"].(string)
1853
+				price, _ := strconv.ParseFloat(retail_prices, 64)
1662 1854
 				cancelStockInfo := &models.CancelStockInfo{
1663
-					OrderNumber:   cancelStock.OrderNumber,
1664
-					CancelStockId: cancelStock.ID,
1665
-					GoodId:        good_id,
1666
-					GoodTypeId:    good_type_id,
1667
-					Count:         count,
1668
-					Status:        1,
1669
-					Ctime:         ctime,
1670
-					OrgId:         adminUserInfo.CurrentOrgId,
1671
-					Type:          types,
1672
-					Manufacturer:  manufacturer_id,
1673
-					Dealer:        dealer_id,
1855
+					OrderNumber:     cancelStock.OrderNumber,
1856
+					CancelStockId:   cancelStock.ID,
1857
+					GoodId:          good_id,
1858
+					GoodTypeId:      good_type_id,
1859
+					Count:           count,
1860
+					Status:          1,
1861
+					Ctime:           ctime,
1862
+					OrgId:           adminUserInfo.CurrentOrgId,
1863
+					Type:            types,
1864
+					Manufacturer:    manufacturer,
1865
+					Dealer:          dealer,
1866
+					Number:          number,
1867
+					ProductDate:     productDates,
1868
+					ExpiryDate:      expiryDates,
1869
+					RegisterAccount: register_account,
1870
+					Remark:          remark,
1871
+					Price:           price,
1674 1872
 				}
1675 1873
 				cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
1676 1874
 
@@ -1726,10 +1924,13 @@ func (c *StockManagerApiController) GetCancelStockInfoList() {
1726 1924
 
1727 1925
 	cancelStockInfoList, _ := service.FindCancelStockInfoById(id)
1728 1926
 	info, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
1729
-
1927
+	manufacturerList, _ := service.GetAllManufacturerList(c.GetAdminUserInfo().CurrentOrgId)
1928
+	dealerList, _ := service.GetAllDealerList(c.GetAdminUserInfo().CurrentOrgId)
1730 1929
 	c.ServeSuccessJSON(map[string]interface{}{
1731
-		"list": cancelStockInfoList,
1732
-		"info": info,
1930
+		"list":             cancelStockInfoList,
1931
+		"info":             info,
1932
+		"manufacturerList": manufacturerList,
1933
+		"dealerList":       dealerList,
1733 1934
 	})
1734 1935
 
1735 1936
 }
@@ -1886,33 +2087,95 @@ func (c *StockManagerApiController) EditCancelStock() {
1886 2087
 					return
1887 2088
 				}
1888 2089
 				id := int64(items["id"].(float64))
2090
+				number := items["number"].(string)
2091
+
2092
+				register_account := items["register_account"].(string)
1889 2093
 
2094
+				manufacturer, _ := items["manufacturer"].(string)
2095
+
2096
+				dealer, _ := items["dealer"].(string)
2097
+
2098
+				remark := items["remark"].(string)
2099
+
2100
+				var productDates int64
2101
+				if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
2102
+					productDates = 0
2103
+				} else {
2104
+					if len(items["product_date"].(string)) == 0 {
2105
+						productDates = 0
2106
+
2107
+					} else {
2108
+						productDate, _ := items["product_date"].(string)
2109
+						product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
2110
+						productDates = product_date.Unix()
2111
+
2112
+					}
2113
+
2114
+				}
2115
+				var expiryDates int64
2116
+				if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
2117
+					expiryDates = 0
2118
+				} else {
2119
+					if len(items["expiry_date"].(string)) == 0 {
2120
+						expiryDates = 0
2121
+
2122
+					} else {
2123
+						expiryDate, _ := items["expiry_date"].(string)
2124
+						expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
2125
+						expiryDates = expiry_date.Unix()
2126
+
2127
+					}
2128
+
2129
+				}
2130
+
2131
+				if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
2132
+					utils.ErrorLog("price")
2133
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
2134
+					return
2135
+				}
2136
+				price, _ := strconv.ParseFloat(items["price"].(string), 64)
1890 2137
 				if id == 0 {
1891 2138
 					cancelStockInfo := &models.CancelStockInfo{
1892
-						GoodId:        good_id,
1893
-						GoodTypeId:    good_type_id,
1894
-						Count:         count,
1895
-						Status:        1,
1896
-						Ctime:         ctime,
1897
-						OrgId:         adminUserInfo.CurrentOrgId,
1898
-						OrderNumber:   cancelStock.OrderNumber,
1899
-						CancelStockId: cancelStock.ID,
1900
-						Mtime:         time.Now().Unix(),
2139
+						GoodId:          good_id,
2140
+						GoodTypeId:      good_type_id,
2141
+						Count:           count,
2142
+						Status:          1,
2143
+						Ctime:           ctime,
2144
+						OrgId:           adminUserInfo.CurrentOrgId,
2145
+						OrderNumber:     cancelStock.OrderNumber,
2146
+						CancelStockId:   cancelStock.ID,
2147
+						Mtime:           time.Now().Unix(),
2148
+						Number:          number,
2149
+						RegisterAccount: register_account,
2150
+						Manufacturer:    manufacturer,
2151
+						Dealer:          dealer,
2152
+						ProductDate:     productDates,
2153
+						ExpiryDate:      expiryDates,
2154
+						Remark:          remark,
2155
+						Price:           price,
1901 2156
 					}
1902 2157
 					cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
1903 2158
 
1904 2159
 				} else {
1905 2160
 					cancelStockInfo := &models.CancelStockInfo{
1906
-						ID:            id,
1907
-						GoodId:        good_id,
1908
-						GoodTypeId:    good_type_id,
1909
-						Count:         count,
1910
-						Status:        1,
1911
-						Ctime:         ctime,
1912
-						OrgId:         adminUserInfo.CurrentOrgId,
1913
-						OrderNumber:   cancelStock.OrderNumber,
1914
-						CancelStockId: cancelStock.ID,
1915
-						Mtime:         time.Now().Unix(),
2161
+						ID:              id,
2162
+						GoodId:          good_id,
2163
+						GoodTypeId:      good_type_id,
2164
+						Count:           count,
2165
+						Status:          1,
2166
+						Ctime:           ctime,
2167
+						OrgId:           adminUserInfo.CurrentOrgId,
2168
+						OrderNumber:     cancelStock.OrderNumber,
2169
+						CancelStockId:   cancelStock.ID,
2170
+						Mtime:           time.Now().Unix(),
2171
+						Number:          number,
2172
+						RegisterAccount: register_account,
2173
+						Manufacturer:    manufacturer,
2174
+						Dealer:          dealer,
2175
+						ProductDate:     productDates,
2176
+						ExpiryDate:      expiryDates,
2177
+						Remark:          remark,
2178
+						Price:           price,
1916 2179
 					}
1917 2180
 					upDateCancelStockInfos = append(upDateCancelStockInfos, cancelStockInfo)
1918 2181
 				}
@@ -3968,15 +4231,18 @@ func (this *StockManagerApiController) GetStockDrugCount() {
3968 4231
 
3969 4232
 func (this *StockManagerApiController) GetOrderDetialByOrderId() {
3970 4233
 
3971
-	//id, _ := this.GetInt64("id")
3972 4234
 	ids := this.GetString("id")
3973 4235
 	idsArray := strings.Split(ids, ",")
3974 4236
 	orgId := this.GetAdminUserInfo().CurrentOrgId
3975 4237
 	order, _ := service.GetWarehouseOutOrder(idsArray, orgId)
3976 4238
 	list, _ := service.GetOrderDetialByOrderIdOne(idsArray, orgId)
4239
+	//获取该耗材的最后一条数据
4240
+	info, _ := service.GetLastWarehouseOutInfo(idsArray, orgId)
4241
+	fmt.Println("info323e2342342342432342342432", info)
3977 4242
 	this.ServeSuccessJSON(map[string]interface{}{
3978 4243
 		"order": order,
3979 4244
 		"list":  list,
4245
+		"info":  info,
3980 4246
 	})
3981 4247
 }
3982 4248
 
@@ -4106,7 +4372,8 @@ func (this *StockManagerApiController) GetSingleCancelOrder() {
4106 4372
 func (this *StockManagerApiController) GetCancelStockOrderPrint() {
4107 4373
 	id := this.GetString("id")
4108 4374
 	idStr := strings.Split(id, ",")
4109
-	list, _ := service.GetCancelStockOrderPrint(idStr)
4375
+	orgId := this.GetAdminUserInfo().CurrentOrgId
4376
+	list, _ := service.GetCancelStockOrderPrintOne(idStr, orgId)
4110 4377
 	this.ServeSuccessJSON(map[string]interface{}{
4111 4378
 		"list": list,
4112 4379
 	})
@@ -4121,3 +4388,81 @@ func (this *StockManagerApiController) GetStockBatchNumber() {
4121 4388
 		"list": list,
4122 4389
 	})
4123 4390
 }
4391
+
4392
+func (this *StockManagerApiController) GetStockFlow() {
4393
+
4394
+	limit, _ := this.GetInt64("limit")
4395
+	page, _ := this.GetInt64("page")
4396
+	good_id, _ := this.GetInt64("good_id")
4397
+	consumable_type, _ := this.GetInt64("is_sys")
4398
+	adminUserInfo := this.GetAdminUserInfo()
4399
+	orgId := adminUserInfo.CurrentOrgId
4400
+	timeLayout := "2006-01-02"
4401
+	loc, _ := time.LoadLocation("Local")
4402
+	start_time := this.GetString("start_time")
4403
+	end_time := this.GetString("end_time")
4404
+
4405
+	var startTime int64
4406
+	if len(start_time) > 0 {
4407
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
4408
+		if err != nil {
4409
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
4410
+			return
4411
+		}
4412
+		startTime = theTime.Unix()
4413
+	}
4414
+	var endTime int64
4415
+	if len(end_time) > 0 {
4416
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
4417
+		if err != nil {
4418
+			utils.ErrorLog(err.Error())
4419
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
4420
+			return
4421
+		}
4422
+		endTime = theTime.Unix()
4423
+	}
4424
+
4425
+	list, total, _ := service.GetStockFlowList(limit, page, consumable_type, orgId, startTime, endTime, good_id)
4426
+	manufacturerList, _ := service.GetAllManufacturerList(orgId)
4427
+	this.ServeSuccessJSON(map[string]interface{}{
4428
+		"list":             list,
4429
+		"total":            total,
4430
+		"manufacturerList": manufacturerList,
4431
+	})
4432
+}
4433
+
4434
+func (this *StockManagerApiController) GetCancelExportList() {
4435
+
4436
+	adminUserInfo := this.GetAdminUserInfo()
4437
+	orgId := adminUserInfo.CurrentOrgId
4438
+	timeLayout := "2006-01-02"
4439
+	loc, _ := time.LoadLocation("Local")
4440
+	start_time := this.GetString("start_time")
4441
+	end_time := this.GetString("end_time")
4442
+	idArray := this.GetString("order_id")
4443
+	fmt.Println("232323232323232232", idArray)
4444
+	ids := strings.Split(idArray, ",")
4445
+	var startTime int64
4446
+	if len(start_time) > 0 {
4447
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
4448
+		if err != nil {
4449
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
4450
+			return
4451
+		}
4452
+		startTime = theTime.Unix()
4453
+	}
4454
+	var endTime int64
4455
+	if len(end_time) > 0 {
4456
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
4457
+		if err != nil {
4458
+			utils.ErrorLog(err.Error())
4459
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
4460
+			return
4461
+		}
4462
+		endTime = theTime.Unix()
4463
+	}
4464
+	list, _ := service.GetCancelExportList(startTime, endTime, ids, orgId)
4465
+	this.ServeSuccessJSON(map[string]interface{}{
4466
+		"list": list,
4467
+	})
4468
+}

+ 5 - 0
controllers/stock_warrhouse_contorller.go Vedi File

@@ -0,0 +1,5 @@
1
+package controllers
2
+
3
+func main() {
4
+
5
+}

+ 2 - 0
main.go Vedi File

@@ -17,5 +17,7 @@ func main() {
17 17
 	//service.BeginAutoCreatePlanJob()
18 18
 	//service.AutoClearSchedules()
19 19
 	//service.BeginAutoCreateStaffScheduleJob()
20
+	//service.BeginAutoCreateDrugJob()
21
+	//service.BeginAutoCreateStockJob()
20 22
 	beego.Run()
21 23
 }

+ 153 - 34
models/drug_stock.go Vedi File

@@ -1,5 +1,7 @@
1 1
 package models
2 2
 
3
+import "gdyb/models"
4
+
3 5
 type DrugWarehouse struct {
4 6
 	ID               int64  `gorm:"column:id" json:"id" form:"id"`
5 7
 	WarehousingOrder string `gorm:"column:warehousing_order" json:"warehousing_order" form:"warehousing_order"`
@@ -20,6 +22,36 @@ func (DrugWarehouse) TableName() string {
20 22
 	return "xt_drug_warehouse"
21 23
 }
22 24
 
25
+type DrugWarehouseInfoSix struct {
26
+	ID               int64   `gorm:"column:id" json:"id" form:"id"`
27
+	WarehousingId    int64   `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
28
+	DrugId           int64   `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
29
+	Number           string  `gorm:"column:number" json:"number" form:"number"`
30
+	ProductDate      int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
31
+	ExpiryDate       int64   `gorm:"column:expiry_date" json:"expiry_date" form:"expiry_date"`
32
+	WarehousingCount int64   `gorm:"column:warehousing_count" json:"warehousing_count" form:"warehousing_count"`
33
+	Price            float64 `gorm:"column:price" json:"price" form:"price"`
34
+	TotalPrice       float64 `gorm:"column:total_price" json:"total_price" form:"total_price"`
35
+	Dealer           int64   `gorm:"column:dealer" json:"dealer" form:"dealer"`
36
+	Manufacturer     int64   `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
37
+	Remark           string  `gorm:"column:remark" json:"remark" form:"remark"`
38
+	Ctime            int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
39
+	Mtime            int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
40
+	Status           int64   `gorm:"column:status" json:"status" form:"status"`
41
+	OrgId            int64   `gorm:"column:org_id" json:"org_id" form:"org_id"`
42
+	IsReturn         int64   `gorm:"column:is_return" json:"is_return" form:"is_return"`
43
+	WarehousingOrder string  `gorm:"column:warehousing_order" json:"warehousing_order" form:"warehousing_order"`
44
+	Type             int64   `gorm:"column:type" json:"type" form:"type"`
45
+	RetailPrice      float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
46
+	RetailTotalPrice float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
47
+	BatchNumber      string  `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
48
+	MaxUnit          string  `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
49
+	MinUnit          string  `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
50
+	StockMaxNumber   int64   `gorm:"column:stock_max_number" json:"stock_max_number" form:"stock_max_number"`
51
+	StockMinNumber   int64   `gorm:"column:stock_min_number" json:"stock_min_number" form:"stock_min_number"`
52
+	MinNumber        int64   `json:"min_number"`
53
+}
54
+
23 55
 type DrugWarehouseInfo struct {
24 56
 	ID               int64   `gorm:"column:id" json:"id" form:"id"`
25 57
 	WarehousingId    int64   `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
@@ -105,6 +137,7 @@ type DrugWarehouseOutInfo struct {
105 137
 	Number                  string  `gorm:"column:number" json:"number" form:"number"`
106 138
 	BatchNumber             string  `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
107 139
 	PatientId               int64   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
140
+	WarehouseInfoId         int64   `gorm:"column:warehouse_info_id" json:"warehouse_info_id" form:"warehouse_info_id"`
108 141
 }
109 142
 
110 143
 func (DrugWarehouseOutInfo) TableName() string {
@@ -160,21 +193,22 @@ func (DrugSalesReturnInfo) TableName() string {
160 193
 }
161 194
 
162 195
 type DrugCancelStock struct {
163
-	ID            int64         `gorm:"column:id" json:"id" form:"id"`
164
-	OrderNumber   string        `gorm:"column:order_number" json:"order_number" form:"order_number"`
165
-	OperaTime     int64         `gorm:"column:opera_time" json:"opera_time" form:"opera_time"`
166
-	Total         int64         `gorm:"column:total" json:"total" form:"total"`
167
-	Creater       int64         `gorm:"column:creater" json:"creater" form:"creater"`
168
-	Ctime         int64         `gorm:"column:ctime" json:"ctime" form:"ctime"`
169
-	Mtime         int64         `gorm:"column:mtime" json:"mtime" form:"mtime"`
170
-	Status        int64         `gorm:"column:status" json:"status" form:"status"`
171
-	OrgId         int64         `gorm:"column:org_id" json:"org_id" form:"org_id"`
172
-	ReturnTime    int64         `gorm:"column:return_time" json:"return_time" form:"return_time"`
173
-	Dealer        int64         `gorm:"column:dealer" json:"dealer" form:"dealer"`
174
-	Manufacturer  int64         `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
175
-	Type          int64         `gorm:"column:type" json:"type" form:"type"`
176
-	Manufacturers *Manufacturer `gorm:"ForeignKey:Manufacturer;AssociationForeignKey:ID" json:"manufacturers"`
177
-	Dealers       *Dealer       `gorm:"ForeignKey:Dealer;AssociationForeignKey:ID" json:"dealers"`
196
+	ID                  int64                         `gorm:"column:id" json:"id" form:"id"`
197
+	OrderNumber         string                        `gorm:"column:order_number" json:"order_number" form:"order_number"`
198
+	OperaTime           int64                         `gorm:"column:opera_time" json:"opera_time" form:"opera_time"`
199
+	Total               int64                         `gorm:"column:total" json:"total" form:"total"`
200
+	Creater             int64                         `gorm:"column:creater" json:"creater" form:"creater"`
201
+	Ctime               int64                         `gorm:"column:ctime" json:"ctime" form:"ctime"`
202
+	Mtime               int64                         `gorm:"column:mtime" json:"mtime" form:"mtime"`
203
+	Status              int64                         `gorm:"column:status" json:"status" form:"status"`
204
+	OrgId               int64                         `gorm:"column:org_id" json:"org_id" form:"org_id"`
205
+	ReturnTime          int64                         `gorm:"column:return_time" json:"return_time" form:"return_time"`
206
+	Dealer              int64                         `gorm:"column:dealer" json:"dealer" form:"dealer"`
207
+	Manufacturer        int64                         `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
208
+	Type                int64                         `gorm:"column:type" json:"type" form:"type"`
209
+	Manufacturers       *Manufacturer                 `gorm:"ForeignKey:Manufacturer;AssociationForeignKey:ID" json:"manufacturers"`
210
+	Dealers             *Dealer                       `gorm:"ForeignKey:Dealer;AssociationForeignKey:ID" json:"dealers"`
211
+	DrugCancelStockInfo []*models.DrugCancelStockInfo `gorm:"ForeignKey:CancelStockId;AssociationForeignKey:ID" json:"drugCancelStockInfo"`
178 212
 }
179 213
 
180 214
 func (DrugCancelStock) TableName() string {
@@ -182,25 +216,30 @@ func (DrugCancelStock) TableName() string {
182 216
 }
183 217
 
184 218
 type DrugCancelStockInfo struct {
185
-	ID               int64   `gorm:"column:id" json:"id" form:"id"`
186
-	DrugId           int64   `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
187
-	CancelStockId    int64   `gorm:"column:cancel_stock_id" json:"cancel_stock_id" form:"cancel_stock_id"`
188
-	Count            int64   `gorm:"column:count" json:"count" form:"count"`
189
-	Price            float64 `gorm:"column:price" json:"price" form:"price"`
190
-	Total            float64 `gorm:"column:total" json:"total" form:"total"`
191
-	ProductDate      int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
192
-	ExpiryDate       int64   `gorm:"column:expiry_date" json:"expiry_date" form:"expiry_date"`
193
-	Ctime            int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
194
-	Mtime            int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
195
-	Status           int64   `gorm:"column:status" json:"status" form:"status"`
196
-	OrgId            int64   `gorm:"column:org_id" json:"org_id" form:"org_id"`
197
-	OrderNumber      string  `gorm:"column:order_number" json:"order_number" form:"order_number"`
198
-	Type             int64   `gorm:"column:type" json:"type" form:"type"`
199
-	Dealer           int64   `gorm:"column:dealer" json:"dealer" form:"dealer"`
200
-	Manufacturer     int64   `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
201
-	RetailPrice      float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
202
-	RetailTotalPrice float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
203
-	Number           string  `gorm:"column:number" json:"number" form:"number"`
219
+	ID               int64       `gorm:"column:id" json:"id" form:"id"`
220
+	DrugId           int64       `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
221
+	CancelStockId    int64       `gorm:"column:cancel_stock_id" json:"cancel_stock_id" form:"cancel_stock_id"`
222
+	Count            int64       `gorm:"column:count" json:"count" form:"count"`
223
+	Price            float64     `gorm:"column:price" json:"price" form:"price"`
224
+	Total            float64     `gorm:"column:total" json:"total" form:"total"`
225
+	ProductDate      int64       `gorm:"column:product_date" json:"product_date" form:"product_date"`
226
+	ExpiryDate       int64       `gorm:"column:expiry_date" json:"expiry_date" form:"expiry_date"`
227
+	Ctime            int64       `gorm:"column:ctime" json:"ctime" form:"ctime"`
228
+	Mtime            int64       `gorm:"column:mtime" json:"mtime" form:"mtime"`
229
+	Status           int64       `gorm:"column:status" json:"status" form:"status"`
230
+	OrgId            int64       `gorm:"column:org_id" json:"org_id" form:"org_id"`
231
+	OrderNumber      string      `gorm:"column:order_number" json:"order_number" form:"order_number"`
232
+	Type             int64       `gorm:"column:type" json:"type" form:"type"`
233
+	Dealer           string      `gorm:"column:dealer" json:"dealer" form:"dealer"`
234
+	Manufacturer     string      `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
235
+	RetailPrice      float64     `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
236
+	RetailTotalPrice float64     `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
237
+	Number           string      `gorm:"column:number" json:"number" form:"number"`
238
+	RegisterAccount  string      `gorm:"column:register_account" json:"register_account" form:"register_account"`
239
+	Remark           string      `gorm:"column:remark" json:"remark" form:"remark"`
240
+	BatchNumber      string      `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
241
+	MaxUnit          string      `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
242
+	BaseDrugLib      BaseDrugLib `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId" `
204 243
 }
205 244
 
206 245
 func (DrugCancelStockInfo) TableName() string {
@@ -240,3 +279,83 @@ type VmDrugWarehouseInfo struct {
240 279
 	DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
241 280
 	Count  int64 `gorm:"column:count" json:"count" form:"count"`
242 281
 }
282
+
283
+type StDrugWarehouseOutInfo struct {
284
+	ID                      int64   `gorm:"column:id" json:"id" form:"id"`
285
+	WarehouseOutId          int64   `gorm:"column:warehouse_out_id" json:"warehouse_out_id" form:"warehouse_out_id"`
286
+	DrugId                  int64   `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
287
+	WarehousingOutTarget    int64   `gorm:"column:warehousing_out_target" json:"warehousing_out_target" form:"warehousing_out_target"`
288
+	Count                   int64   `gorm:"column:count" json:"count" form:"count"`
289
+	CountUnit               string  `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
290
+	Price                   float64 `gorm:"column:price" json:"price" form:"price"`
291
+	TotalPrice              float64 `gorm:"column:total_price" json:"total_price" form:"total_price"`
292
+	ProductDate             int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
293
+	ExpiryDate              int64   `gorm:"column:expiry_date" json:"expiry_date" form:"expiry_date"`
294
+	Mtime                   int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
295
+	Ctime                   int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
296
+	Status                  int64   `gorm:"column:status" json:"status" form:"status"`
297
+	OrgId                   int64   `gorm:"column:org_id" json:"org_id" form:"org_id"`
298
+	Remark                  string  `gorm:"column:remark" json:"remark" form:"remark"`
299
+	IsCancel                int64   `gorm:"column:is_cancel" json:"is_cancel" form:"is_cancel"`
300
+	WarehouseOutOrderNumber string  `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
301
+	Type                    int64   `gorm:"column:type" json:"type" form:"type"`
302
+	Dealer                  int64   `gorm:"column:dealer" json:"dealer" form:"dealer"`
303
+	Manufacturer            int64   `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
304
+	IsSys                   int64   `gorm:"column:is_sys" json:"is_sys" form:"is_sys"`
305
+	SysRecordTime           int64   `gorm:"column:sys_record_time" json:"sys_record_time" form:"sys_record_time"`
306
+	RetailPrice             float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
307
+	RetailTotalPrice        float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
308
+	Number                  string  `gorm:"column:number" json:"number" form:"number"`
309
+	BatchNumber             string  `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
310
+	PatientId               int64   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
311
+	DrugName                string  `json:"drug_name"`
312
+	DrugType                int64   `json:"drug_type"`
313
+	MaxUnit                 string  `json:"max_unit"`
314
+	MinUnit                 string  `json:"min_unit"`
315
+	MinNumber               int64   `json:"min_number"`
316
+	MinPrice                float64 `json:"min_price"`
317
+	Dose                    float64 `json:"dose"`
318
+	DoseUnit                string  `json:"dose_unit"`
319
+	LastPrice               string  `json:"last_price"`
320
+	PackingUnit             string  `json:"packing_unit"`
321
+	Dosage                  int64   `json:"dosage"`
322
+}
323
+
324
+type DrugFlow struct {
325
+	ID                      int64   `gorm:"column:id" json:"id" form:"id"`
326
+	WarehousingId           int64   `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
327
+	DrugId                  int64   `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
328
+	Number                  string  `gorm:"column:number" json:"number" form:"number"`
329
+	BatchNumber             string  `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
330
+	Count                   int64   `gorm:"column:count" json:"count" form:"count"`
331
+	UserOrgId               int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
332
+	PatientId               int64   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
333
+	SystemTime              int64   `gorm:"column:system_time" json:"system_time" form:"system_time"`
334
+	ConsumableType          int64   `gorm:"column:consumable_type" json:"consumable_type" form:"consumable_type"`
335
+	IsSys                   int64   `gorm:"column:is_sys" json:"is_sys" form:"is_sys"`
336
+	WarehousingOrder        string  `gorm:"column:warehousing_order" json:"warehousing_order" form:"warehousing_order"`
337
+	WarehouseOutId          int64   `gorm:"column:warehouse_out_id" json:"warehouse_out_id" form:"warehouse_out_id"`
338
+	WarehouseOutOrderNumber string  `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
339
+	IsEdit                  int64   `gorm:"column:is_edit" json:"is_edit" form:"is_edit"`
340
+	CancelStockId           int64   `gorm:"column:cancel_stock_id" json:"cancel_stock_id" form:"cancel_stock_id"`
341
+	CancelOrderNumber       int64   `gorm:"column:cancel_order_number" json:"cancel_order_number" form:"cancel_order_number"`
342
+	Manufacturer            int64   `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
343
+	Dealer                  int64   `gorm:"column:dealer" json:"dealer" form:"dealer"`
344
+	Creator                 int64   `gorm:"column:creator" json:"creator" form:"creator"`
345
+	UpdateCreator           int64   `gorm:"column:update_creator" json:"update_creator" form:"update_creator"`
346
+	Status                  int64   `gorm:"column:status" json:"status" form:"status"`
347
+	Ctime                   int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
348
+	Mtime                   int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
349
+	Price                   float64 `gorm:"column:price" json:"price" form:"price"`
350
+	WarehousingDetailId     int64   `gorm:"column:warehousing_detail_id" json:"warehousing_detail_id" form:"warehousing_detail_id"`
351
+	WarehouseOutDetailId    int64   `gorm:"column:warehouse_out_detail_id" json:"warehouse_out_detail_id" form:"warehouse_out_detail_id"`
352
+	CancelOutDetailId       int64   `gorm:"column:cancel_out_detail_id" json:"cancel_out_detail_id" form:"cancel_out_detail_id"`
353
+	ExpireDate              int64   `gorm:"column:expire_date" json:"expire_date" form:"expire_date"`
354
+	ProductDate             int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
355
+	MaxUnit                 string  `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
356
+	MinUnit                 string  `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
357
+}
358
+
359
+func (DrugFlow) TableName() string {
360
+	return "xt_drug_flow"
361
+}

+ 116 - 35
models/stock_models.go Vedi File

@@ -1,5 +1,7 @@
1 1
 package models
2 2
 
3
+import "XT/models"
4
+
3 5
 type Manufacturer struct {
4 6
 	ID               int64  `gorm:"column:id" json:"id"`
5 7
 	ManufacturerName string `gorm:"column:manufacturer_name" json:"manufacturer_name"`
@@ -222,6 +224,7 @@ type WarehouseOutInfo struct {
222 224
 	PatientId               int64        `gorm:"column:patient_id" json:"patient_id"`
223 225
 	Number                  string       `gorm:"column:number" json:"number" form:"number"`
224 226
 	LicenseNumber           string       `gorm:"column:license_number" json:"license_number" form:"license_number"`
227
+	ConsumableType          int64        `gorm:"column:consumable_type" json:"consumable_type" form:"consumable_type"`
225 228
 }
226 229
 
227 230
 func (WarehouseOutInfo) TableName() string {
@@ -281,25 +284,28 @@ type VmCancelStockInfo struct {
281 284
 }
282 285
 
283 286
 type CancelStockInfo struct {
284
-	ID            int64       `gorm:"column:id" json:"id"`
285
-	GoodId        int64       `gorm:"column:good_id" json:"good_id"`
286
-	CancelStockId int64       `gorm:"column:cancel_stock_id" json:"cancel_stock_id"`
287
-	GoodTypeId    int64       `gorm:"column:good_type_id" json:"good_type_id"`
288
-	Count         int64       `gorm:"column:count" json:"count"`
289
-	Price         float64     `gorm:"column:price" json:"price"`
290
-	Total         float64     `gorm:"column:total" json:"total"`
291
-	ProductDate   int64       `gorm:"column:product_date" json:"product_date"`
292
-	ExpiryDate    int64       `gorm:"column:expiry_date" json:"expiry_date"`
293
-	Ctime         int64       `gorm:"column:ctime" json:"ctime"`
294
-	Mtime         int64       `gorm:"column:mtime" json:"mtime"`
295
-	Status        int64       `gorm:"column:status" json:"status"`
296
-	OrgId         int64       `gorm:"column:org_id" json:"org_id"`
297
-	OrderNumber   string      `gorm:"column:order_number" json:"order_number"`
298
-	Type          int64       `gorm:"column:type" json:"type"`
299
-	CancelStock   CancelStock `ForeignKey:CancelStockId json:"CancelStock"`
300
-	Dealer        int64       `gorm:"column:dealer" json:"dealer"`
301
-	Manufacturer  int64       `gorm:"column:manufacturer" json:"manufacturer"`
302
-	GoodInfo      GoodInfo    `gorm:"ForeignKey:ID;AssociationForeignKey:GoodId" `
287
+	ID              int64       `gorm:"column:id" json:"id"`
288
+	GoodId          int64       `gorm:"column:good_id" json:"good_id"`
289
+	CancelStockId   int64       `gorm:"column:cancel_stock_id" json:"cancel_stock_id"`
290
+	GoodTypeId      int64       `gorm:"column:good_type_id" json:"good_type_id"`
291
+	Count           int64       `gorm:"column:count" json:"count"`
292
+	Price           float64     `gorm:"column:price" json:"price"`
293
+	Total           float64     `gorm:"column:total" json:"total"`
294
+	ProductDate     int64       `gorm:"column:product_date" json:"product_date"`
295
+	ExpiryDate      int64       `gorm:"column:expiry_date" json:"expiry_date"`
296
+	Ctime           int64       `gorm:"column:ctime" json:"ctime"`
297
+	Mtime           int64       `gorm:"column:mtime" json:"mtime"`
298
+	Status          int64       `gorm:"column:status" json:"status"`
299
+	OrgId           int64       `gorm:"column:org_id" json:"org_id"`
300
+	OrderNumber     string      `gorm:"column:order_number" json:"order_number"`
301
+	Type            int64       `gorm:"column:type" json:"type"`
302
+	CancelStock     CancelStock `ForeignKey:CancelStockId json:"CancelStock"`
303
+	Dealer          string      `gorm:"column:dealer" json:"dealer"`
304
+	Manufacturer    string      `gorm:"column:manufacturer" json:"manufacturer"`
305
+	GoodInfo        GoodInfo    `gorm:"ForeignKey:ID;AssociationForeignKey:GoodId" `
306
+	Number          string      `gorm:"column:number" json:"number" form:"number"`
307
+	RegisterAccount string      `gorm:"column:register_account" json:"register_account" form:"register_account"`
308
+	Remark          string      `gorm:"column:remark" json:"remark" form:"remark"`
303 309
 }
304 310
 
305 311
 func (CancelStockInfo) TableName() string {
@@ -307,19 +313,20 @@ func (CancelStockInfo) TableName() string {
307 313
 }
308 314
 
309 315
 type CancelStock struct {
310
-	ID           int64  `gorm:"column:id" json:"id"`
311
-	OrderNumber  string `gorm:"column:order_number" json:"order_number"`
312
-	OperaTime    int64  `gorm:"column:opera_time" json:"opera_time"`
313
-	Total        int64  `gorm:"column:total" json:"total"`
314
-	Creater      int64  `gorm:"column:creater" json:"creater"`
315
-	Ctime        int64  `gorm:"column:ctime" json:"ctime"`
316
-	Mtime        int64  `gorm:"column:mtime" json:"mtime"`
317
-	Status       int64  `gorm:"column:status" json:"status"`
318
-	OrgId        int64  `gorm:"column:org_id" json:"org_id"`
319
-	ReturnTime   int64  `gorm:"column:return_time" json:"return_time"`
320
-	Dealer       int64  `gorm:"column:dealer" json:"dealer"`
321
-	Manufacturer int64  `gorm:"column:manufacturer" json:"manufacturer"`
322
-	Type         int64  `gorm:"column:type" json:"type"`
316
+	ID              int64  `gorm:"column:id" json:"id"`
317
+	OrderNumber     string `gorm:"column:order_number" json:"order_number"`
318
+	OperaTime       int64  `gorm:"column:opera_time" json:"opera_time"`
319
+	Total           int64  `gorm:"column:total" json:"total"`
320
+	Creater         int64  `gorm:"column:creater" json:"creater"`
321
+	Ctime           int64  `gorm:"column:ctime" json:"ctime"`
322
+	Mtime           int64  `gorm:"column:mtime" json:"mtime"`
323
+	Status          int64  `gorm:"column:status" json:"status"`
324
+	OrgId           int64  `gorm:"column:org_id" json:"org_id"`
325
+	ReturnTime      int64  `gorm:"column:return_time" json:"return_time"`
326
+	Dealer          int64  `gorm:"column:dealer" json:"dealer"`
327
+	Manufacturer    int64  `gorm:"column:manufacturer" json:"manufacturer"`
328
+	Type            int64  `gorm:"column:type" json:"type"`
329
+	CancelStockInfo []*models.CancelStockInfo
323 330
 }
324 331
 
325 332
 func (CancelStock) TableName() string {
@@ -401,9 +408,10 @@ type VmWarehouseOutInfo struct {
401 408
 }
402 409
 
403 410
 type VmWarehouseInfo struct {
404
-	GoodId int64 `gorm:"column:good_id" json:"good_id"`
405
-	Count  int64 `gorm:"column:count" json:"count"`
406
-	OrgId  int64 `gorm:"column:org_id" json:"org_id"`
411
+	GoodId     int64 `gorm:"column:good_id" json:"good_id"`
412
+	Count      int64 `gorm:"column:count" json:"count"`
413
+	OrgId      int64 `gorm:"column:org_id" json:"org_id"`
414
+	StockCount int64 `gorm:"column:stock_count" json:"stock_count"`
407 415
 }
408 416
 
409 417
 type WarehouseOutInfoOne struct {
@@ -475,3 +483,76 @@ type WarehouseOutInfoTwo struct {
475 483
 	PackingUnit             string               `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
476 484
 	StWarehousingInfo       []*StWarehousingInfo `gorm:"ForeignKey:good_id;AssociationForeignKey:GoodId" json:"xt_warehouse_info"`
477 485
 }
486
+
487
+type WarehouseOutInfoSix struct {
488
+	ID                      int64        `gorm:"column:id" json:"id"`
489
+	WarehouseOutId          int64        `gorm:"column:warehouse_out_id" json:"warehouse_out_id"`
490
+	WarehouseInfotId        int64        `gorm:"column:warehouse_info_id" json:"warehouse_info_id"`
491
+	GoodId                  int64        `gorm:"column:good_id" json:"good_id"`
492
+	GoodTypeId              int64        `gorm:"column:good_type_id" json:"good_type_id"`
493
+	WarehousingOutTarget    int64        `gorm:"column:warehousing_out_target" json:"warehousing_out_target"`
494
+	Count                   int64        `gorm:"column:count" json:"count"`
495
+	Price                   float64      `gorm:"column:price" json:"price"`
496
+	TotalPrice              float64      `gorm:"column:total_price" json:"total_price"`
497
+	ProductDate             int64        `gorm:"column:product_date" json:"product_date"`
498
+	ExpiryDate              int64        `gorm:"column:expiry_date" json:"expiry_date"`
499
+	Mtime                   int64        `gorm:"column:mtime" json:"mtime"`
500
+	Ctime                   int64        `gorm:"column:ctime" json:"ctime"`
501
+	Status                  int64        `gorm:"column:status" json:"status"`
502
+	OrgId                   int64        `gorm:"column:org_id" json:"org_id"`
503
+	Remark                  string       `gorm:"column:remark" json:"remark"`
504
+	IsCancel                int64        `gorm:"column:is_cancel" json:"is_cancel"`
505
+	WarehouseOut            WarehouseOut `ForeignKey:WarehouseOutId json:"WarehouseOut"`
506
+	WarehouseOutOrderNumber string       `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number"`
507
+	Type                    int64        `gorm:"column:type" json:"type"`
508
+	Dealer                  int64        `gorm:"column:dealer" json:"dealer"`
509
+	Manufacturer            int64        `gorm:"column:manufacturer" json:"manufacturer"`
510
+	IsSys                   int64        `gorm:"column:is_sys" json:"is_sys"`
511
+	SysRecordTime           int64        `gorm:"column:sys_record_time" json:"sys_record_time"`
512
+	PatientId               int64        `gorm:"column:patient_id" json:"patient_id"`
513
+	Number                  string       `gorm:"column:number" json:"number" form:"number"`
514
+	LicenseNumber           string       `gorm:"column:license_number" json:"license_number" form:"license_number"`
515
+	ConsumableType          int64        `gorm:"column:consumable_type" json:"consumable_type" form:"consumable_type"`
516
+	GoodInfo                GoodInfo     `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
517
+}
518
+
519
+func (WarehouseOutInfoSix) TableName() string {
520
+	return "xt_warehouse_out_info"
521
+}
522
+
523
+type VmStockFlow struct {
524
+	ID                      int64   `gorm:"column:id" json:"id" form:"id"`
525
+	WarehousingId           int64   `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
526
+	GoodId                  int64   `gorm:"column:good_id" json:"good_id" form:"good_id"`
527
+	Number                  string  `gorm:"column:number" json:"number" form:"number"`
528
+	LicenseNumber           string  `gorm:"column:license_number" json:"license_number" form:"license_number"`
529
+	Count                   int64   `gorm:"column:count" json:"count" form:"count"`
530
+	UserOrgId               int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
531
+	PatientId               int64   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
532
+	SystemTime              int64   `gorm:"column:system_time" json:"system_time" form:"system_time"`
533
+	ConsumableType          int64   `gorm:"column:consumable_type" json:"consumable_type" form:"consumable_type"`
534
+	IsSys                   int64   `gorm:"column:is_sys" json:"is_sys" form:"is_sys"`
535
+	WarehousingOrder        string  `gorm:"column:warehousing_order" json:"warehousing_order" form:"warehousing_order"`
536
+	WarehouseOutId          int64   `gorm:"column:warehouse_out_id" json:"warehouse_out_id" form:"warehouse_out_id"`
537
+	WarehouseOutOrderNumber string  `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
538
+	IsEdit                  int64   `gorm:"column:is_edit" json:"is_edit" form:"is_edit"`
539
+	CancelStockId           int64   `gorm:"column:cancel_stock_id" json:"cancel_stock_id" form:"cancel_stock_id"`
540
+	CancelOrderNumber       int64   `gorm:"column:cancel_order_number" json:"cancel_order_number" form:"cancel_order_number"`
541
+	Manufacturer            int64   `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
542
+	Dealer                  int64   `gorm:"column:dealer" json:"dealer" form:"dealer"`
543
+	Creator                 int64   `gorm:"column:creator" json:"creator" form:"creator"`
544
+	UpdateCreator           int64   `gorm:"column:update_creator" json:"update_creator" form:"update_creator"`
545
+	Status                  int64   `gorm:"column:status" json:"status" form:"status"`
546
+	Ctime                   int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
547
+	Mtime                   int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
548
+	Price                   float64 `gorm:"column:price" json:"price" form:"price"`
549
+	WarehousingDetailId     int64   `gorm:"column:warehousing_detail_id" json:"warehousing_detail_id" form:"warehousing_detail_id"`
550
+	WarehouseOutDetailId    int64   `gorm:"column:warehouse_out_detail_id" json:"warehouse_out_detail_id" form:"warehouse_out_detail_id"`
551
+	CancelOutDetailId       int64   `gorm:"column:cancel_out_detail_id" json:"cancel_out_detail_id" form:"cancel_out_detail_id"`
552
+	ProductDate             int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
553
+	ExpireDate              int64   `gorm:"column:expire_date" json:"expire_date" form:"expire_date"`
554
+}
555
+
556
+func (VmStockFlow) TableName() string {
557
+	return "xt_stock_flow"
558
+}

+ 110 - 0
service/auto_create_drug.go Vedi File

@@ -0,0 +1,110 @@
1
+package service
2
+
3
+import (
4
+	"XT_New/models"
5
+	"XT_New/utils"
6
+	"fmt"
7
+	"github.com/robfig/cron"
8
+	"strconv"
9
+	"time"
10
+)
11
+
12
+var createDrugCronJob *cron.Cron
13
+
14
+func init() {
15
+	createDrugCronJob = cron.New()
16
+	utils.InfoLog("开启自动更新药品库存定时任务")
17
+	spec := "0 */1 * * * ?" // 每1分钟执行一次
18
+	//spec := "0 55 23 * * ?" // 每天23点55执行一次
19
+	//spec := "0 0 0 ? * Sun"
20
+	createDrugCronJob.AddFunc(spec, func() {
21
+		AutoCreateDrugJob()
22
+	})
23
+
24
+}
25
+
26
+func BeginAutoCreateDrugJob() {
27
+
28
+	createDrugCronJob.Start()
29
+}
30
+
31
+func AutoCreateDrugJob() {
32
+
33
+	timeStr := time.Now().Format("2006-01-02")
34
+	timeLayout := "2006-01-02 15:04:05"
35
+	fmt.Println("timeStr:", timeStr)
36
+	timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
37
+	timenow := timeStringToTime.Unix()
38
+	fmt.Println("timenow是什么", timenow)
39
+	//查询当天排班所有机构
40
+	org, errs := GetAllOrgName(timenow)
41
+	fmt.Print("错误是什么", errs)
42
+	fmt.Println("查询有机构失败", err)
43
+
44
+	var total int64
45
+	for _, item := range org {
46
+		fmt.Println("hhhh2h3h2323232323232323", item.UserOrgId)
47
+		//查询该机构下的所有药品信息
48
+		list, _ := FindAllDrugList(item.UserOrgId)
49
+		for _, ite := range list {
50
+			countList, _ := FindAllDrugTotalCount(ite.ID)
51
+			for _, it := range countList {
52
+				if ite.ID == it.DrugId {
53
+					//转为拆零数量
54
+					it.StockMaxNumber = it.StockMaxNumber * it.MinNumber
55
+
56
+					total = it.StockMaxNumber + it.StockMinNumber
57
+					fmt.Println(it.StockMaxNumber)
58
+					fmt.Println(it.StockMinNumber)
59
+					fmt.Println("total223232323232323232323", total)
60
+					formatInt := strconv.FormatInt(total, 10)
61
+					float, _ := strconv.ParseFloat(formatInt, 64)
62
+					fmt.Println("min_number2323232323232", float)
63
+					lib := models.BaseDrugLib{
64
+						Total: float,
65
+					}
66
+					UpdateDrugTotal(it.DrugId, lib)
67
+				}
68
+			}
69
+		}
70
+	}
71
+
72
+}
73
+
74
+//查询当天有排班的所有机构
75
+func GetAllOrgName(time int64) (schedule []*models.XtSchedule, err error) {
76
+
77
+	err = XTReadDB().Raw("select user_org_id,id,partition_id,bed_id,patient_id,schedule_date,schedule_type,schedule_week,mode_id from xt_schedule where schedule_date = ?  group by user_org_id", time).Scan(&schedule).Error
78
+
79
+	return schedule, err
80
+}
81
+
82
+//根据机构ID查询药品信息
83
+func FindAllDrugList(orgid int64) (lib []*models.BaseDrugLib, err error) {
84
+
85
+	err = XTReadDB().Where("org_id = ? and status = 1", orgid).Find(&lib).Error
86
+	return lib, err
87
+}
88
+
89
+//根据药品ID统计该药品的库存
90
+func FindAllDrugTotalCount(drug_id int64) (info []*models.DrugWarehouseInfoSix, err error) {
91
+
92
+	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
93
+	table := XTReadDB().Table("xt_base_drug as b").Where("b.status = 1")
94
+	fmt.Println(table)
95
+	if drug_id > 0 {
96
+		db = db.Where("x.drug_id = ?", drug_id)
97
+	}
98
+
99
+	err = db.Select("x.drug_id,sum(x.stock_max_number) as stock_max_number,sum(x.stock_min_number) as stock_min_number,b.min_number").Joins("left join xt_base_drug as b on b.id = x.drug_id").Scan(&info).Error
100
+
101
+	return info, err
102
+}
103
+
104
+//更新药品库的total字段
105
+
106
+func UpdateDrugTotal(id int64, lib models.BaseDrugLib) error {
107
+
108
+	err := XTWriteDB().Model(&lib).Where("id=? and status = 1", id).Updates(map[string]interface{}{"total": lib.Total}).Error
109
+	return err
110
+}

+ 1 - 0
service/auto_create_staff_schedule_service.go Vedi File

@@ -33,6 +33,7 @@ import (
33 33
 var createStaffScheduleCronJob *cron.Cron
34 34
 
35 35
 func init() {
36
+
36 37
 	createStaffScheduleCronJob = cron.New()
37 38
 	//spec := "0 */1 * * * ?" // 每1分钟执行一次
38 39
 	//spec := "0 55 23 * * ?" // 每天23点55执行一次

+ 87 - 0
service/auto_create_stock.go Vedi File

@@ -0,0 +1,87 @@
1
+package service
2
+
3
+import (
4
+	"XT_New/models"
5
+	"XT_New/utils"
6
+	"fmt"
7
+	"github.com/robfig/cron"
8
+	"strconv"
9
+	"time"
10
+)
11
+
12
+var createStockCronJob *cron.Cron
13
+
14
+func init() {
15
+	utils.InfoLog("开启自动更新耗材库存定时任务")
16
+	createStockCronJob = cron.New()
17
+	spec := "0 */5 * * * ?" // 每1分钟执行一次
18
+	//spec := "0 55 23 * * ?" // 每天23点55执行一次
19
+	//spec := "0 0 0 ? * Sun"
20
+	createStockCronJob.AddFunc(spec, func() {
21
+		AutoCreateStockJob()
22
+	})
23
+}
24
+
25
+func BeginAutoCreateStockJob() {
26
+
27
+	createStockCronJob.Start()
28
+}
29
+
30
+func AutoCreateStockJob() {
31
+
32
+	timeStr := time.Now().Format("2006-01-02")
33
+	timeLayout := "2006-01-02 15:04:05"
34
+	fmt.Println("timeStr:", timeStr)
35
+	timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
36
+	timenow := timeStringToTime.Unix()
37
+	fmt.Println("timenow是什么", timenow)
38
+	//查询当天排班所有机构
39
+	org, errs := GetAllOrgName(timenow)
40
+	fmt.Print("错误是什么", errs)
41
+	fmt.Println("查询有机构失败", err)
42
+
43
+	for _, item := range org {
44
+
45
+		information, _ := FindAlLGoodInformation(item.UserOrgId)
46
+		for _, ite := range information {
47
+			countList, _ := FindAllGoodInformationTotalCount(ite.ID)
48
+			for _, it := range countList {
49
+				if ite.ID == it.GoodId {
50
+					formatInt := strconv.FormatInt(it.StockCount, 10)
51
+					total, _ := strconv.ParseFloat(formatInt, 64)
52
+					info := models.GoodInfo{
53
+						Total: total,
54
+					}
55
+					UpdateStockTotal(it.GoodId, info)
56
+				}
57
+			}
58
+		}
59
+
60
+	}
61
+}
62
+
63
+//查询所有的耗材信息
64
+func FindAlLGoodInformation(orgid int64) (info []*models.GoodInfo, err error) {
65
+
66
+	err = XTReadDB().Where("org_id = ? and status = 1", orgid).Find(&info).Error
67
+	return info, err
68
+}
69
+
70
+func FindAllGoodInformationTotalCount(good_id int64) (info []*models.WarehousingInfo, err error) {
71
+
72
+	db := XTReadDB().Table("xt_warehouse_info as x").Where("x.status =1")
73
+
74
+	if good_id > 0 {
75
+		db = db.Where("x.good_id = ?", good_id)
76
+	}
77
+	err = db.Select("x.good_id,sum(x.stock_count) as stock_count,x.warehousing_count").Find(&info).Error
78
+	return info, err
79
+}
80
+
81
+//更新耗材库的total字段
82
+
83
+func UpdateStockTotal(id int64, lib models.GoodInfo) error {
84
+
85
+	err := XTWriteDB().Model(&lib).Where("id=? and status = 1", id).Updates(map[string]interface{}{"total": lib.Total}).Error
86
+	return err
87
+}

+ 32 - 0
service/drug_stock_service.go Vedi File

@@ -159,3 +159,35 @@ func FindAllDrugStockInfo(orgId int64, page int64, limit int64, keyword string,
159 159
 	err = db.Offset(offset).Limit(limit).Order("ctime desc").Find(&list).Error
160 160
 	return
161 161
 }
162
+
163
+func GetCancelDrugOrderPrint(id []string, orgid int64) (info []*models.DrugCancelStock, err error) {
164
+
165
+	db := XTReadDB().Model(&info)
166
+
167
+	if len(id) > 0 {
168
+		db = db.Where("id in(?)", id)
169
+	}
170
+	if orgid > 0 {
171
+		db = db.Where("org_id= ?", orgid)
172
+	}
173
+
174
+	err = db.Preload("DrugCancelStockInfo", func(db *gorm.DB) *gorm.DB {
175
+		return db.Where("status = 1 AND org_id = ?", orgid).Preload("BaseDrugLib", "status = 1 AND org_id= ?", orgid)
176
+	}).Find(&info).Error
177
+
178
+	return info, err
179
+}
180
+
181
+func GetDrugCancelExportList(orderid []string, orgid int64) (info []*models.DrugCancelStockInfo, err error) {
182
+
183
+	db := XTReadDB().Model(&info)
184
+	if len(orderid) > 0 {
185
+		db = db.Where("cancel_stock_id in(?)", orderid)
186
+	}
187
+	if orgid > 0 {
188
+		db = db.Where("org_id = ?", orgid)
189
+	}
190
+	db = db.Preload("BaseDrugLib", "status = 1 and org_id = ?", orgid)
191
+	err = db.Find(&info).Error
192
+	return info, err
193
+}

+ 1 - 1
service/mobile_dialysis_service.go Vedi File

@@ -1522,7 +1522,7 @@ func FindConsumablesByDateTwo(orgID int64, patient_id int64, recordDate int64) (
1522 1522
 }
1523 1523
 
1524 1524
 func FindConsumablesByDateThree(orgID int64, patient_id int64, recordDate int64) (consumables []*models.BloodAutomaticReduceDetail, err error) {
1525
-	err = readDb.Model(&models.BloodAutomaticReduceDetail{}).Where("user_org_id = ? AND patient_id = ? AND record_time = ? AND status = 1 AND count > 0", orgID, patient_id, recordDate).Find(&consumables).Error
1525
+	err = readDb.Model(&models.BloodAutomaticReduceDetail{}).Where("org_id = ? AND patient_id = ? AND record_time = ? AND status = 1 AND count > 0", orgID, patient_id, recordDate).Find(&consumables).Error
1526 1526
 	return
1527 1527
 }
1528 1528
 

+ 501 - 17
service/stock_service.go Vedi File

@@ -457,7 +457,108 @@ func CreateDrugWarehousingInfo(warehousingInfo []*models.DrugWarehouseInfo) (err
457 457
 		utx.Commit()
458 458
 	}
459 459
 	return
460
+}
461
+
462
+func UpdateDrugInfo(warehousingInfo []*models.DrugWarehouseInfo) (err error) {
463
+	var total float64
464
+	var min_number int64
465
+	for _, item := range warehousingInfo {
466
+		//查询刚入库耗材的库存
467
+		count, _ := FindDrugWaresingCount(item.DrugId, item.OrgId)
468
+		//更新药品库的总量
469
+		info, _ := FindeDrugInfo(item.DrugId)
470
+
471
+		min_number = count.StockMaxNumber * info.MinNumber
472
+		str := strconv.FormatInt(min_number, 10)
473
+		minFloat, _ := strconv.ParseFloat(str, 64)
474
+		total = info.Total + minFloat
475
+		lib := models.BaseDrugLib{
476
+			Total: total,
477
+		}
478
+		UpdateBaseDrug(&lib, item.ID)
479
+	}
480
+	return err
481
+}
482
+
483
+func FindDrugWaresingCount(drug_id int64, orgid int64) (models.XtDrugWarehouseInfo, error) {
484
+
485
+	info := models.XtDrugWarehouseInfo{}
486
+	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
487
+	err = db.Select("x.stock_max_number,x.drug_id").Where("x.drug_id = ? and x.org_id = ? and x.status =1", drug_id, orgid).Last(&info).Error
488
+	return info, err
489
+}
490
+
491
+func FindeDrugInfo(drug_id int64) (models.BaseDrugLib, error) {
492
+
493
+	lib := models.BaseDrugLib{}
494
+	err := XTReadDB().Model(&lib).Where("id = ?", drug_id).Find(&lib).Error
495
+	return lib, err
496
+}
497
+
498
+func UpdateBaseDrug(lib *models.BaseDrugLib, id int64) error {
499
+
500
+	err := XTWriteDB().Model(&lib).Where("id = ?", id).Updates(map[string]interface{}{"total": lib.Total}).Error
501
+	return err
502
+}
503
+
504
+func CreateDrugFlow(drugflow []*models.DrugFlow) (err error) {
505
+	if len(drugflow) > 0 {
506
+		utx := writeDb.Begin()
507
+		if len(drugflow) > 0 {
508
+			thisSQL := "INSERT INTO xt_drug_flow (warehousing_id, drug_id, number,batch_number,count,user_org_id,patient_id,system_time,consumable_type,is_sys,warehousing_order,warehouse_out_id,warehouse_out_order_number,is_edit,cancel_stock_id,cancel_order_number,manufacturer,dealer,creator,update_creator,status,ctime,mtime,price,warehousing_detail_id,warehouse_out_detail_id,cancel_out_detail_id,expire_date,product_date,max_unit,min_unit ) VALUES "
509
+			insertParams := make([]string, 0)
510
+			insertData := make([]interface{}, 0)
511
+			for _, info := range drugflow {
512
+				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
513
+				insertData = append(insertData, info.WarehousingId)
514
+				insertData = append(insertData, info.DrugId)
515
+				insertData = append(insertData, info.Number)
516
+				insertData = append(insertData, info.BatchNumber)
517
+				insertData = append(insertData, info.Count)
518
+				insertData = append(insertData, info.UserOrgId)
519
+				insertData = append(insertData, info.PatientId)
520
+				insertData = append(insertData, info.SystemTime)
521
+				insertData = append(insertData, info.ConsumableType)
522
+				insertData = append(insertData, info.IsSys)
523
+				insertData = append(insertData, info.WarehousingOrder)
524
+				insertData = append(insertData, info.WarehouseOutId)
525
+				insertData = append(insertData, info.WarehouseOutOrderNumber)
526
+
527
+				insertData = append(insertData, info.IsEdit)
528
+				insertData = append(insertData, info.CancelStockId)
529
+				insertData = append(insertData, info.CancelOrderNumber)
530
+				insertData = append(insertData, info.Manufacturer)
531
+				insertData = append(insertData, info.Dealer)
532
+				insertData = append(insertData, info.Creator)
533
+				insertData = append(insertData, info.UpdateCreator)
534
+				insertData = append(insertData, info.Status)
535
+				insertData = append(insertData, info.Ctime)
536
+				insertData = append(insertData, info.Mtime)
537
+				insertData = append(insertData, info.Price)
538
+				insertData = append(insertData, info.WarehousingDetailId)
539
+				insertData = append(insertData, info.WarehouseOutDetailId)
540
+				insertData = append(insertData, info.CancelOutDetailId)
541
+				insertData = append(insertData, info.ExpireDate)
542
+				insertData = append(insertData, info.ProductDate)
543
+				insertData = append(insertData, info.MaxUnit)
544
+				insertData = append(insertData, info.MinUnit)
545
+			}
546
+			thisSQL += strings.Join(insertParams, ", ")
547
+			err = utx.Exec(thisSQL, insertData...).Error
548
+			if err != nil {
549
+				utx.Rollback()
550
+				return
551
+			}
552
+		}
553
+		utx.Commit()
554
+	}
555
+	return
556
+}
557
+
558
+func CreateDrugFlowOne(flow models.DrugFlow) error {
460 559
 
560
+	err := XTWriteDB().Create(&flow).Error
561
+	return err
461 562
 }
462 563
 
463 564
 func FindLastWarehousingInfo(order string) (info models.WarehousingInfo, err error) {
@@ -467,10 +568,6 @@ func FindLastWarehousingInfo(order string) (info models.WarehousingInfo, err err
467 568
 
468 569
 }
469 570
 
470
-//func FindFirstWarehousingInfoByStock(good_id int64,good_type_id int64) (info models.WarehousingInfo, err error) {
471
-//	err = readDb.Model(&models.WarehousingInfo{}).Where("good_id = ? AND good_type_id = ? AND status = 1 and stock_count > 0", order).Order("ctime").First(&info).Error
472
-//	return info, err
473
-//}
474 571
 func FindFirstWarehousingInfoByStock(good_id int64, good_type_id int64) (info models.WarehousingInfo, err error) {
475 572
 	err = readDb.Model(&models.WarehousingInfo{}).Where("good_id = ? AND good_type_id = ? AND status = 1 and stock_count > 0", good_id, good_type_id).Order("ctime").First(&info).Error
476 573
 	return info, err
@@ -1005,11 +1102,15 @@ type DrugCancelStockInfo struct {
1005 1102
 	OrgId            int64   `gorm:"column:org_id" json:"org_id" form:"org_id"`
1006 1103
 	OrderNumber      string  `gorm:"column:order_number" json:"order_number" form:"order_number"`
1007 1104
 	Type             int64   `gorm:"column:type" json:"type" form:"type"`
1008
-	Dealer           int64   `gorm:"column:dealer" json:"dealer" form:"dealer"`
1009
-	Manufacturer     int64   `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
1105
+	Dealer           string  `gorm:"column:dealer" json:"dealer" form:"dealer"`
1106
+	Manufacturer     string  `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
1010 1107
 	RetailPrice      float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
1011 1108
 	RetailTotalPrice float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
1012 1109
 	Number           string  `gorm:"column:number" json:"number" form:"number"`
1110
+	RegisterAccount  string  `gorm:"column:register_account" json:"register_account" form:"register_account"`
1111
+	Remark           string  `gorm:"column:remark" json:"remark" form:"remark"`
1112
+	BatchNumber      string  `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
1113
+	MaxUnit          string  `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
1013 1114
 	Drug             *Drug   `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug"`
1014 1115
 }
1015 1116
 
@@ -1108,11 +1209,11 @@ func CreateDrugWarehousingOutInfo(warehouseOutInfo []*models.DrugWarehouseOutInf
1108 1209
 	if len(warehouseOutInfo) > 0 {
1109 1210
 		utx := writeDb.Begin()
1110 1211
 		if len(warehouseOutInfo) > 0 {
1111
-			thisSQL := "INSERT INTO xt_drug_warehouse_out_info (warehouse_out_id, drug_id, product_date,expiry_date,count,price,total_price,remark,ctime,status,org_id,warehouse_out_order_number,type,dealer,manufacturer,retail_price,retail_total_price,number,batch_number) VALUES "
1212
+			thisSQL := "INSERT INTO xt_drug_warehouse_out_info (warehouse_out_id, drug_id, product_date,expiry_date,count,price,total_price,remark,ctime,status,org_id,warehouse_out_order_number,type,dealer,manufacturer,retail_price,retail_total_price,number,batch_number,count_unit) VALUES "
1112 1213
 			insertParams := make([]string, 0)
1113 1214
 			insertData := make([]interface{}, 0)
1114 1215
 			for _, info := range warehouseOutInfo {
1115
-				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
1216
+				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
1116 1217
 				insertData = append(insertData, info.WarehouseOutId)
1117 1218
 				insertData = append(insertData, info.DrugId)
1118 1219
 				insertData = append(insertData, info.ProductDate)
@@ -1132,6 +1233,7 @@ func CreateDrugWarehousingOutInfo(warehouseOutInfo []*models.DrugWarehouseOutInf
1132 1233
 				insertData = append(insertData, info.RetailTotalPrice)
1133 1234
 				insertData = append(insertData, info.Number)
1134 1235
 				insertData = append(insertData, info.BatchNumber)
1236
+				insertData = append(insertData, info.CountUnit)
1135 1237
 			}
1136 1238
 			thisSQL += strings.Join(insertParams, ", ")
1137 1239
 			err = utx.Exec(thisSQL, insertData...).Error
@@ -1363,11 +1465,11 @@ func CreateCancelStockInfo(cancelStockInfo []*models.CancelStockInfo) (err error
1363 1465
 	if len(cancelStockInfo) > 0 {
1364 1466
 		utx := writeDb.Begin()
1365 1467
 		if len(cancelStockInfo) > 0 {
1366
-			thisSQL := "INSERT INTO xt_cancel_stock_info (good_id, cancel_stock_id, good_type_id, count, price,total,ctime,status,org_id,order_number,type,dealer,manufacturer) VALUES "
1468
+			thisSQL := "INSERT INTO xt_cancel_stock_info (good_id, cancel_stock_id, good_type_id, count, price,total,ctime,status,org_id,order_number,type,dealer,manufacturer,number,register_account,remark,product_date,expiry_date) VALUES "
1367 1469
 			insertParams := make([]string, 0)
1368 1470
 			insertData := make([]interface{}, 0)
1369 1471
 			for _, info := range cancelStockInfo {
1370
-				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?)")
1472
+				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
1371 1473
 				insertData = append(insertData, info.GoodId)
1372 1474
 				insertData = append(insertData, info.CancelStockId)
1373 1475
 				insertData = append(insertData, info.GoodTypeId)
@@ -1381,6 +1483,11 @@ func CreateCancelStockInfo(cancelStockInfo []*models.CancelStockInfo) (err error
1381 1483
 				insertData = append(insertData, info.Type)
1382 1484
 				insertData = append(insertData, info.Dealer)
1383 1485
 				insertData = append(insertData, info.Manufacturer)
1486
+				insertData = append(insertData, info.Number)
1487
+				insertData = append(insertData, info.RegisterAccount)
1488
+				insertData = append(insertData, info.Remark)
1489
+				insertData = append(insertData, info.ProductDate)
1490
+				insertData = append(insertData, info.ExpiryDate)
1384 1491
 			}
1385 1492
 			thisSQL += strings.Join(insertParams, ", ")
1386 1493
 			err = utx.Exec(thisSQL, insertData...).Error
@@ -1399,11 +1506,11 @@ func CreateDrugCancelStockInfo(cancelStockInfo []*models.DrugCancelStockInfo) (e
1399 1506
 	if len(cancelStockInfo) > 0 {
1400 1507
 		utx := writeDb.Begin()
1401 1508
 		if len(cancelStockInfo) > 0 {
1402
-			thisSQL := "INSERT INTO xt_drug_cancel_stock_info (drug_id,cancel_stock_id, count, price,total,ctime,status,org_id,order_number,type,dealer,manufacturer,retail_price,retail_total_price) VALUES "
1509
+			thisSQL := "INSERT INTO xt_drug_cancel_stock_info (drug_id,cancel_stock_id, count, price,total,ctime,status,org_id,order_number,type,dealer,manufacturer,retail_price,retail_total_price,register_account,batch_number,remark,max_unit,product_date,expiry_date) VALUES "
1403 1510
 			insertParams := make([]string, 0)
1404 1511
 			insertData := make([]interface{}, 0)
1405 1512
 			for _, info := range cancelStockInfo {
1406
-				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
1513
+				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
1407 1514
 				insertData = append(insertData, info.DrugId)
1408 1515
 				insertData = append(insertData, info.CancelStockId)
1409 1516
 				insertData = append(insertData, info.Count)
@@ -1418,7 +1525,12 @@ func CreateDrugCancelStockInfo(cancelStockInfo []*models.DrugCancelStockInfo) (e
1418 1525
 				insertData = append(insertData, info.Manufacturer)
1419 1526
 				insertData = append(insertData, info.RetailPrice)
1420 1527
 				insertData = append(insertData, info.RetailTotalPrice)
1421
-
1528
+				insertData = append(insertData, info.RegisterAccount)
1529
+				insertData = append(insertData, info.BatchNumber)
1530
+				insertData = append(insertData, info.Remark)
1531
+				insertData = append(insertData, info.MaxUnit)
1532
+				insertData = append(insertData, info.ProductDate)
1533
+				insertData = append(insertData, info.ExpiryDate)
1422 1534
 			}
1423 1535
 			thisSQL += strings.Join(insertParams, ", ")
1424 1536
 			err = utx.Exec(thisSQL, insertData...).Error
@@ -1672,6 +1784,13 @@ func FindAllWarehouseByKeyword(orgId int64, page int64, limit int64, keywords st
1672 1784
 	return
1673 1785
 }
1674 1786
 
1787
+func GetLastWarehousingById(warehousing_id int64, orgid int64) (models.WarehousingInfo, error) {
1788
+
1789
+	info := models.WarehousingInfo{}
1790
+	err = XTReadDB().Model(&info).Where("warehousing_id = ? and good_id = ? and status = 1", warehousing_id, orgid).Find(&info).Error
1791
+	return info, err
1792
+}
1793
+
1675 1794
 func UpDateWarehousingInfo(info *models.WarehousingInfo) (err error) {
1676 1795
 	err = writeDb.Save(&info).Error
1677 1796
 	return err
@@ -1682,6 +1801,20 @@ func UpDateDrugWarehousingInfo(info *models.DrugWarehouseInfo) (err error) {
1682 1801
 	return err
1683 1802
 }
1684 1803
 
1804
+func GetDrugWarehouseOrderOne(id int64, drug_id int64) (models.DrugWarehouseInfo, error) {
1805
+
1806
+	info := models.DrugWarehouseInfo{}
1807
+	err = XTReadDB().Model(&info).Where("warehousing_id = ? and drug_id = ?", id, drug_id).Find(&info).Error
1808
+	return info, err
1809
+}
1810
+
1811
+func GetDrugWarehouseOrder(id int64) (models.DrugWarehouseInfo, error) {
1812
+
1813
+	info := models.DrugWarehouseInfo{}
1814
+	err = XTReadDB().Model(&info).Where("id = ?", id).Find(&info).Error
1815
+	return info, err
1816
+}
1817
+
1685 1818
 func EditWarehousing(warehouse models.Warehousing) {
1686 1819
 	err = readDb.Model(&models.Warehousing{}).Where("warehousing_order = ? AND status = 1", warehouse.WarehousingOrder).Update(map[string]interface{}{"mtime": time.Now().Unix(), "warehousing_time": warehouse.WarehousingTime, "modifier": warehouse.Modifier, "dealer": warehouse.Dealer, "manufacturer": warehouse.Manufacturer}).Error
1687 1820
 
@@ -2310,7 +2443,6 @@ func FindDrugStockOutByIsSys(org_id int64, is_sys int, record_time int64) (out m
2310 2443
 func FindLastStockInInfoRecord(good_id int64, org_id int64) (in models.WarehousingInfo, err error) {
2311 2444
 	err = readDb.Model(&models.WarehousingInfo{}).Where("status = 1 AND org_id = ? AND good_id = ?", org_id, good_id).Last(&in).Error
2312 2445
 	return
2313
-
2314 2446
 }
2315 2447
 
2316 2448
 func FindLastDrugStockInInfoRecord(drug_id int64, org_id int64) (in models.DrugWarehouseOutInfo, err error) {
@@ -2415,6 +2547,12 @@ func FindStockOutInfoByStockOne(org_id int64, good_type_id int64, good_id int64,
2415 2547
 	return
2416 2548
 }
2417 2549
 
2550
+func FindStockOutInfoByStockTwo(org_id int64, good_type_id int64, good_id int64, record_date int64, patient_id int64) (models.WarehouseOutInfo, error) {
2551
+	info := models.WarehouseOutInfo{}
2552
+	err = readDb.Model(&info).Where("status = 1 AND org_id = ? AND good_type_id = ? AND good_id = ? AND is_sys = 1 AND sys_record_time = ? and patient_id = ?", org_id, good_type_id, good_id, record_date, patient_id).Order("ctime desc").Find(&info).Error
2553
+	return info, err
2554
+}
2555
+
2418 2556
 func FindDrugStockOutInfoByTypeId(org_id int64, drug_id int64, out_id int64, number string) (out models.DrugWarehouseOutInfo, err error) {
2419 2557
 	err = readDb.Model(&models.DrugWarehouseOutInfo{}).Where("status = 1 AND org_id = ? AND  drug_id = ? AND is_sys = 1 AND  (warehouse_out_id = ? or warehouse_out_order_number = ?)", org_id, drug_id, out_id, number).First(&out).Error
2420 2558
 	return
@@ -2964,6 +3102,11 @@ func UpDateWarehouseInfoByStockDelete(id int64, count int64) (err error) {
2964 3102
 	return err
2965 3103
 }
2966 3104
 
3105
+func UpDateWarehouseInfoByStockDeleteOne(id int64, count int64) (err error) {
3106
+	err = writeDb.Model(&models.WarehousingInfo{}).Where("id = ?", id).UpdateColumn("stock_count", gorm.Expr("stock_count - ?", count)).Error
3107
+	return err
3108
+}
3109
+
2967 3110
 func GetAutoDialysisBefor(goodid int64, goodtypeid int64, patientid int64, orgid int64, recorddate int64) (*models.BloodAutomaticReduceDetail, error) {
2968 3111
 
2969 3112
 	var autoreduece models.BloodAutomaticReduceDetail
@@ -3059,7 +3202,7 @@ func GetStockOutList(good_id int64, orgid int64, limit int64, page int64, starti
3059 3202
 	if is_sys == 3 {
3060 3203
 		db = db.Where("x.is_sys = 0")
3061 3204
 	}
3062
-	err = db.Select("x.id,x.warehouse_out_id,x.warehouse_info_id,x.good_id,x.good_type_id,x.warehousing_out_target,x.count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.warehouse_out_order_number,x.is_sys,x.number,x.dealer,x.manufacturer").Offset(offset).Count(&total).Scan(&info).Error
3205
+	err = db.Select("x.id,x.warehouse_out_id,x.warehouse_info_id,x.good_id,x.good_type_id,x.warehousing_out_target,x.count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.warehouse_out_order_number,x.is_sys,x.number,x.dealer,x.manufacturer,x.consumable_type").Offset(offset).Count(&total).Scan(&info).Error
3063 3206
 	return info, total, err
3064 3207
 }
3065 3208
 
@@ -3076,7 +3219,7 @@ func GetStockDrugCount(startime int64, endtime int64, orgid int64) (info []*mode
3076 3219
 		db = db.Where("x.org_id = ?", orgid)
3077 3220
 	}
3078 3221
 
3079
-	err = db.Select("sum(x.warehousing_count) as count,x.good_id").Group("x.good_id").Scan(&info).Error
3222
+	err = db.Select("sum(x.warehousing_count) as count,sum(x.stock_count) as stock_count,x.good_id").Group("x.good_id").Scan(&info).Error
3080 3223
 	return info, err
3081 3224
 }
3082 3225
 
@@ -3125,7 +3268,7 @@ func GetOrderDetialByOrderId(id int64, orgid int64) (out []*models.WarehouseOutI
3125 3268
 	if orgid > 0 {
3126 3269
 		db = db.Where("x.org_id = ?", orgid)
3127 3270
 	}
3128
-	err = db.Select("x.id,x.warehouse_out_id,x.good_id,sum(x.count) as count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,x.is_sys,x.sys_record_time,x.number,x.remark,x.license_number,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.packing_unit,t.min_unit").Joins("left join xt_good_information as t on t.id=x.good_id").Group("x.good_id").Order("x.ctime desc").Scan(&out).Error
3271
+	err = db.Select("x.id,x.warehouse_out_id,x.warehouse_info_id,x.good_id,sum(x.count) as count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,x.is_sys,x.sys_record_time,x.number,x.remark,x.license_number,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.packing_unit,t.min_unit").Joins("left join xt_good_information as t on t.id=x.good_id").Group("x.good_id").Order("x.ctime desc").Scan(&out).Error
3129 3272
 	return out, err
3130 3273
 }
3131 3274
 
@@ -3158,6 +3301,15 @@ func GetOrderDetialByOrderIdOne(id []string, orgid int64) (out []*models.Warehou
3158 3301
 	return out, err
3159 3302
 }
3160 3303
 
3304
+func GetLastWarehouseOutInfo(ids []string, orgId int64) (info []*models.WarehouseOutInfoSix, err error) {
3305
+
3306
+	db := XTReadDB().Model(&info)
3307
+	db = db.Preload("GoodInfo", "status = 1")
3308
+	err = db.Raw("select * from(SELECT * FROM xt_warehouse_out_info WHERE warehouse_out_id IN(?) AND org_id = ? and status = 1  ORDER BY id DESC LIMIT 1000) a group by good_id", ids, orgId).Find(&info).Error
3309
+
3310
+	return info, err
3311
+}
3312
+
3161 3313
 func FindUserDetailByIdOne(good_id int64, record_time int64, org_id int64) (user []*models.AutomaticReduceDetail, err error, total int64) {
3162 3314
 	db := readDb.Model(&models.AutomaticReduceDetail{})
3163 3315
 	db = db.Preload("GoodInfo", "org_id = ? AND status = 1", org_id)
@@ -3446,6 +3598,17 @@ func GetCancelStockOrderPrint(idstr []string) (info []*models.CancelStockInfo, e
3446 3598
 	return info, err
3447 3599
 }
3448 3600
 
3601
+func GetCancelStockOrderPrintOne(idstr []string, orgid int64) (info []*models.CancelStock, err error) {
3602
+
3603
+	if len(idstr) > 0 {
3604
+		err = XTReadDB().Model(&info).Where("id in(?)", idstr).
3605
+			Preload("CancelStockInfo", func(db *gorm.DB) *gorm.DB {
3606
+				return XTReadDB().Where("org_id=? and status = 1", orgid).Preload("GoodInfo", "status = 1 and org_id = ?", orgid)
3607
+			}).Find(&info).Error
3608
+	}
3609
+	return info, err
3610
+}
3611
+
3449 3612
 func GetCancelOutTotalCount(startime int64, endtime int64, orgid int64) (info []*models.VmCancelStockInfo, err error) {
3450 3613
 
3451 3614
 	db := XTReadDB().Table("xt_cancel_stock_info as x").Where("x.status = 1")
@@ -3507,3 +3670,324 @@ func GetDrugBatchNumber(drug_id int64, orgid int64) (info []*models.DrugWarehous
3507 3670
 	err = XTReadDB().Model(&info).Where("drug_id = ? and org_id = ? and status = 1 and batch_number <>''", drug_id, orgid).Find(&info).Error
3508 3671
 	return info, err
3509 3672
 }
3673
+
3674
+func ExportDrugList(warehouse_out_id []string) (out []*models.StDrugWarehouseInfo, err error) {
3675
+
3676
+	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status =1")
3677
+
3678
+	table := XTReadDB().Table("xt_base_drug as b").Where("b.status = 1")
3679
+	fmt.Println("table", table)
3680
+	if len(warehouse_out_id) > 0 {
3681
+		db = db.Where("x.warehousing_id in(?)", warehouse_out_id)
3682
+	}
3683
+	err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.max_unit,x.min_unit,x.stock_max_number,x.stock_min_number,x.price,x.dealer,x.manufacturer,x.warehousing_order,x.batch_number,b.dose,b.dose_unit,b.min_number,b.min_unit,b.max_unit,b.drug_name,b.drug_type").Joins("left join xt_base_drug as b on b.id = x.drug_id").Scan(&out).Error
3684
+	return out, err
3685
+}
3686
+
3687
+func GetExportOutOrderDrugList(warehouse_out_id []string) (out []*models.StDrugWarehouseOutInfo, err error) {
3688
+
3689
+	db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
3690
+	table := XTReadDB().Table("xt_base_drug as b").Where("b.status = 1")
3691
+	fmt.Println("table", table)
3692
+	if len(warehouse_out_id) > 0 {
3693
+		db = db.Where("x.warehouse_out_id in(?)", warehouse_out_id)
3694
+	}
3695
+	err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.count,x.count_unit,x.price,x.product_date,x.expiry_date,x.warehouse_out_order_number,x.dealer,x.manufacturer,x.is_sys,x.sys_record_time,x.warehouse_info_id,x.number,x.batch_number,x.patient_id,b.dose,b.dose_unit,b.min_number,b.min_unit,b.max_unit,b.drug_name,b.drug_type,b.min_price").Joins("left join xt_base_drug as b on b.id = x.drug_id").Scan(&out).Error
3696
+	return out, err
3697
+}
3698
+
3699
+func GetLastGoodInformationByGoodId(goodid int64, warehouse_info_id int64, orgid int64) (models.WarehouseOutInfo, error) {
3700
+
3701
+	info := models.WarehouseOutInfo{}
3702
+	err := XTReadDB().Where("good_id = ? and warehouse_info_id= ? and status =1", goodid, warehouse_info_id).Last(&info).Error
3703
+	return info, err
3704
+}
3705
+
3706
+func GetTotalCountByGoodId(goodid int64) (models.WarehousingInfo, error) {
3707
+
3708
+	info := models.WarehousingInfo{}
3709
+
3710
+	db := XTReadDB().Table("xt_warehouse_info as x").Where("x.status = 1")
3711
+	if goodid > 0 {
3712
+		db = db.Where("x.good_id = ?", goodid)
3713
+	}
3714
+
3715
+	err := db.Select("x.good_id,sum(x.stock_count) as stock_count").Scan(&info).Error
3716
+	return info, err
3717
+}
3718
+
3719
+func GetLastGoodCountById(goodid int64, warehouse_info_id int64) (models.WarehousingInfo, error) {
3720
+
3721
+	info := models.WarehousingInfo{}
3722
+
3723
+	err := XTReadDB().Where("good_id = ? and id= ? and status = 1", goodid, warehouse_info_id).First(&info).Error
3724
+	return info, err
3725
+}
3726
+
3727
+func UpdateWarehousingInfo(info models.WarehousingInfo, id int64) error {
3728
+
3729
+	err = XTWriteDB().Model(&info).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"stock_count": info.StockCount}).Error
3730
+	return err
3731
+}
3732
+
3733
+func FindFirstWarehousingInfoByGoodId(good_id int64, id int64) (info models.WarehousingInfo, err error) {
3734
+	err = readDb.Model(&models.WarehousingInfo{}).Where("good_id = ? AND status = 1 and id<>?", good_id, id).Order("ctime").First(&info).Error
3735
+	return info, err
3736
+}
3737
+
3738
+func CreateStockFlow(warehousingInfo []*models.VmStockFlow) (err error) {
3739
+	if len(warehousingInfo) > 0 {
3740
+		utx := writeDb.Begin()
3741
+		if len(warehousingInfo) > 0 {
3742
+			thisSQL := "INSERT INTO xt_stock_flow (warehousing_id, good_id, number, license_number, count,user_org_id,patient_id,system_time,consumable_type,is_sys,warehousing_order,warehouse_out_id,warehouse_out_order_number,is_edit,cancel_stock_id,cancel_order_number,manufacturer,dealer,creator,update_creator,status,ctime,mtime,price,warehousing_detail_id,warehouse_out_detail_id,cancel_out_detail_id,expire_date,product_date) VALUES "
3743
+			insertParams := make([]string, 0)
3744
+			insertData := make([]interface{}, 0)
3745
+			for _, info := range warehousingInfo {
3746
+				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
3747
+				insertData = append(insertData, info.WarehousingId)
3748
+				insertData = append(insertData, info.GoodId)
3749
+				insertData = append(insertData, info.Number)
3750
+				insertData = append(insertData, info.LicenseNumber)
3751
+				insertData = append(insertData, info.Count)
3752
+				insertData = append(insertData, info.UserOrgId)
3753
+				insertData = append(insertData, info.PatientId)
3754
+				insertData = append(insertData, info.SystemTime)
3755
+				insertData = append(insertData, info.ConsumableType)
3756
+				insertData = append(insertData, info.IsSys)
3757
+				insertData = append(insertData, info.WarehousingOrder)
3758
+				insertData = append(insertData, info.WarehouseOutId)
3759
+				insertData = append(insertData, info.WarehouseOutOrderNumber)
3760
+				insertData = append(insertData, info.IsEdit)
3761
+				insertData = append(insertData, info.CancelStockId)
3762
+				insertData = append(insertData, info.CancelOrderNumber)
3763
+				insertData = append(insertData, info.Manufacturer)
3764
+				insertData = append(insertData, info.Dealer)
3765
+				insertData = append(insertData, info.Creator)
3766
+				insertData = append(insertData, info.UpdateCreator)
3767
+				insertData = append(insertData, info.Status)
3768
+				insertData = append(insertData, info.Ctime)
3769
+				insertData = append(insertData, info.Mtime)
3770
+				insertData = append(insertData, info.Price)
3771
+				insertData = append(insertData, info.WarehousingDetailId)
3772
+				insertData = append(insertData, info.WarehouseOutDetailId)
3773
+				insertData = append(insertData, info.CancelOutDetailId)
3774
+				insertData = append(insertData, info.ExpireDate)
3775
+				insertData = append(insertData, info.ProductDate)
3776
+			}
3777
+			thisSQL += strings.Join(insertParams, ", ")
3778
+			err = utx.Exec(thisSQL, insertData...).Error
3779
+			if err != nil {
3780
+				utx.Rollback()
3781
+				return
3782
+			}
3783
+		}
3784
+		utx.Commit()
3785
+	}
3786
+	return
3787
+
3788
+}
3789
+
3790
+func CreateStockFlowOne(flow models.VmStockFlow) error {
3791
+
3792
+	err := XTWriteDB().Create(&flow).Error
3793
+	return err
3794
+}
3795
+
3796
+func GetWarehouseOutInfoIsExist(id int64) (*models.WarehouseOutInfo, error) {
3797
+
3798
+	info := models.WarehouseOutInfo{}
3799
+	var err error
3800
+	err = XTReadDB().Model(&info).Where("id = ? and status = 1", id).Find(&info).Error
3801
+	if err == gorm.ErrRecordNotFound {
3802
+		return nil, err
3803
+	}
3804
+	if err != nil {
3805
+		return nil, err
3806
+	}
3807
+	return &info, nil
3808
+}
3809
+
3810
+func GetWarehouseOutInfoIsExistOne(good_id int64, patient_id int64, record_time int64) (*models.WarehouseOutInfo, error) {
3811
+
3812
+	info := models.WarehouseOutInfo{}
3813
+	var err error
3814
+	err = XTReadDB().Model(&info).Where("good_id = ? and sys_record_time = ? and status = 1 and patient_id = ?", good_id, record_time, patient_id).Find(&info).Error
3815
+	if err == gorm.ErrRecordNotFound {
3816
+		return nil, err
3817
+	}
3818
+	if err != nil {
3819
+		return nil, err
3820
+	}
3821
+	return &info, nil
3822
+}
3823
+
3824
+func GetStockFlowList(limit int64, page int64, consumable_type int64, orgId int64, startTime int64, endTime int64, good_id int64) (flow []*models.VmStockFlow, total int64, err error) {
3825
+
3826
+	offset := (page - 1) * limit
3827
+	db := XTReadDB().Model(&flow)
3828
+	if consumable_type > 0 {
3829
+		//入库
3830
+		if consumable_type == 1 {
3831
+			db = db.Where("consumable_type = ?", consumable_type)
3832
+		}
3833
+		//2 手动出库
3834
+		if consumable_type == 2 {
3835
+
3836
+			db = db.Where(" consumable_type = ? and is_sys = 0", consumable_type)
3837
+		}
3838
+
3839
+		//3.自动出库
3840
+		if consumable_type == 3 {
3841
+			db = db.Where(" consumable_type = ? and is_sys = 1", consumable_type)
3842
+		}
3843
+	}
3844
+	if orgId > 0 {
3845
+		db = db.Where("user_org_id = ?", orgId)
3846
+	}
3847
+
3848
+	if startTime > 0 {
3849
+		db = db.Where("ctime >= ?", startTime)
3850
+	}
3851
+
3852
+	if endTime > 0 {
3853
+		db = db.Where("ctime<=?", endTime)
3854
+	}
3855
+
3856
+	if good_id > 0 {
3857
+		db = db.Where("good_id = ?", good_id)
3858
+	}
3859
+
3860
+	err = db.Count(&total).Offset(offset).Limit(limit).Find(&flow).Error
3861
+
3862
+	return flow, total, err
3863
+}
3864
+
3865
+func GetLastGoodListByPatientId(recordtime int64, patientid int64, goodid int64, goodtypeid int64) (models.AutomaticReduceDetail, error) {
3866
+
3867
+	detail := models.AutomaticReduceDetail{}
3868
+
3869
+	err := XTReadDB().Model(&detail).Where("record_time = ? and patient_id = ? and good_id = ? and good_type_id = ? and status = 1", recordtime, patientid, goodid, goodtypeid).Last(&detail).Error
3870
+	return detail, err
3871
+}
3872
+
3873
+func GetLastGoodListByPatientIdOne(recordtime int64, patientid int64, goodid int64, goodtypeid int64) (models.WarehouseOutInfo, error) {
3874
+
3875
+	detail := models.WarehouseOutInfo{}
3876
+
3877
+	err := XTReadDB().Model(&detail).Where("sys_record_time = ? and patient_id = ? and good_id = ? and good_type_id = ? and status = 1", recordtime, patientid, goodid, goodtypeid).Last(&detail).Error
3878
+	return detail, err
3879
+}
3880
+
3881
+func UpdatedWarehouseOutInfo(info *models.WarehouseOutInfo, good_id int64, patient_id int64, record_time int64) error {
3882
+
3883
+	outInfo := models.WarehouseOutInfo{}
3884
+	err := XTWriteDB().Model(&outInfo).Where("good_id = ? and patient_id = ? and sys_record_time  =? and status = 1", good_id, patient_id, record_time).Updates(map[string]interface{}{"warehouse_out_id": info.WarehouseOutId, "WarehouseOutOrderNumber": info.WarehouseOutOrderNumber, "sys_record_time": info.SysRecordTime, "good_type_id": info.GoodTypeId, "patient_id": info.PatientId, "consumable_type": info.ConsumableType, "count": info.Count, "price": info.Price, "dealer": info.Dealer, "manufacturer": info.Manufacturer, "number": info.Number, "license_number": info.LicenseNumber}).Error
3885
+	return err
3886
+}
3887
+
3888
+func GetLastWarehouOutInfoByPatientId(orgid int64, patient_id int64, record_time int64, goodid int64, good_type_id int64) (models.WarehouseOutInfo, error) {
3889
+
3890
+	info := models.WarehouseOutInfo{}
3891
+
3892
+	err = XTReadDB().Model(&info).Where("org_id = ? and patient_id = ? and sys_record_time = ? and good_id = ? and good_type_id = ? and status = 1", orgid, patient_id, record_time, goodid, good_type_id).Last(&info).Error
3893
+	return info, err
3894
+}
3895
+
3896
+func GetLastStockOut(id int64) (models.WarehousingInfo, error) {
3897
+
3898
+	info := models.WarehousingInfo{}
3899
+
3900
+	err := XTReadDB().Model(&info).Where("id = ? and status = 1", id).Find(&info).Error
3901
+	return info, err
3902
+}
3903
+
3904
+func GetDrugFlow(drugid int64, orgid int64, limit int64, page int64, startTime int64, endTime int64, stock_type int64) (drug_flow []*models.DrugFlow, total int64, err error) {
3905
+
3906
+	offset := (page - 1) * limit
3907
+	db := XTReadDB().Model(drug_flow)
3908
+	if drugid > 0 {
3909
+		db = db.Where("drug_id = ?", drugid)
3910
+	}
3911
+	if orgid > 0 {
3912
+		db = db.Where("user_org_id = ?", orgid)
3913
+	}
3914
+	if startTime > 0 {
3915
+		db = db.Where("ctime >=? ", startTime)
3916
+	}
3917
+	if endTime > 0 {
3918
+		db = db.Where("ctime<=?", endTime)
3919
+	}
3920
+	if stock_type > 0 {
3921
+
3922
+		//手动入库
3923
+		if stock_type == 1 {
3924
+			db = db.Where("consumable_type = 1")
3925
+		}
3926
+
3927
+		//手动出库
3928
+		if stock_type == 2 {
3929
+			db = db.Where("consumable_type = 2 and is_sys = 0")
3930
+		}
3931
+
3932
+		//自动出库
3933
+		if stock_type == 3 {
3934
+			db = db.Where("consumable_type = 3 and is_sys = 1")
3935
+		}
3936
+	}
3937
+	err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&drug_flow).Error
3938
+	return drug_flow, total, err
3939
+}
3940
+
3941
+func GetDrugWarehouseOutInfoIsExit(drug_id int64, patient_id int64, recordtime int64) (*models.DrugWarehouseOutInfo, error) {
3942
+
3943
+	outInfo := models.DrugWarehouseOutInfo{}
3944
+	var err error
3945
+	err = XTReadDB().Model(&outInfo).Where("drug_id = ? and patient_id = ? and status = 1 and sys_record_time = ?", drug_id, patient_id, recordtime).Find(&outInfo).Error
3946
+	if err == gorm.ErrRecordNotFound {
3947
+		return nil, err
3948
+	}
3949
+	if err != nil {
3950
+		return nil, err
3951
+	}
3952
+	return &outInfo, nil
3953
+}
3954
+
3955
+func UpdatedDrugWarehouseOutInfo(info *models.DrugWarehouseOutInfo, drug_id int64, patient_id int64, record_date int64, orgid int64) error {
3956
+
3957
+	outInfo := models.DrugWarehouseOutInfo{}
3958
+
3959
+	err := XTWriteDB().Model(&outInfo).Where("drug_id = ? and patient_id = ? and sys_record_time = ? and org_id = ?", drug_id, patient_id, record_date, orgid).Updates(map[string]interface{}{"warehouse_out_id": info.WarehouseOutId, "drug_id": info.DrugId, "count": info.Count, "count_unit": info.CountUnit, "price": info.Price, "product_date": info.ProductDate, "expiry_date": info.ExpiryDate, "mtime": info.Mtime, "ctime": info.Ctime, "org_id": info.OrgId, "warehouse_out_order_number": info.WarehouseOutOrderNumber, "dealer": info.Dealer, "manufacturer": info.Manufacturer, "is_sys": info.IsSys, "sys_record_time": info.SysRecordTime, "warehouse_info_id": info.WarehouseInfoId, "number": info.Number, "batch_number": info.BatchNumber, "patient_id": info.PatientId}).Error
3960
+
3961
+	return err
3962
+}
3963
+
3964
+func GetCancelExportList(startime int64, endtime int64, ids []string, orgid int64) (cancle []*models.CancelStockInfo, err error) {
3965
+
3966
+	db := XTReadDB().Model(&cancle).Where("status = 1")
3967
+	if startime > 0 {
3968
+		db = db.Where("ctime >=?", startime)
3969
+	}
3970
+	if endtime > 0 {
3971
+		db = db.Where("ctime <=?", endtime)
3972
+	}
3973
+	if len(ids) > 0 {
3974
+		db = db.Where("cancel_stock_id in(?)", ids)
3975
+	}
3976
+	if orgid > 0 {
3977
+		db = db.Where("org_id = ?", orgid)
3978
+	}
3979
+	db = db.Preload("GoodInfo", "status =1 and org_id = ?", orgid)
3980
+	err = db.Find(&cancle).Error
3981
+	return cancle, err
3982
+}
3983
+
3984
+func GetCancelStockDetail(id int64) (info []*models.DrugCancelStockInfo, err error) {
3985
+
3986
+	db := XTReadDB().Model(&info)
3987
+	if id > 0 {
3988
+		db = db.Where("cancel_stock_id = ?", id)
3989
+	}
3990
+	db = db.Preload("BaseDrugLib")
3991
+	err = db.Find(&info).Error
3992
+	return info, err
3993
+}

File diff suppressed because it is too large
+ 841 - 370
service/warhouse_service.go