XMLWAN 3 lat temu
rodzic
commit
1921be1a12

+ 130 - 24
controllers/stock_in_api_controller.go Wyświetl plik

212
 
212
 
213
 				manufacturer := int64(items["manufacturer"].(float64))
213
 				manufacturer := int64(items["manufacturer"].(float64))
214
 				dealer := int64(items["dealer"].(float64))
214
 				dealer := int64(items["dealer"].(float64))
215
+
216
+				license_number, _ := items["license_number"].(string)
215
 				warehouseInfo := &models.WarehousingInfo{
217
 				warehouseInfo := &models.WarehousingInfo{
216
 					WarehousingOrder: warehousing.WarehousingOrder,
218
 					WarehousingOrder: warehousing.WarehousingOrder,
217
 					WarehousingId:    warehousing.ID,
219
 					WarehousingId:    warehousing.ID,
231
 					Manufacturer:     manufacturer,
233
 					Manufacturer:     manufacturer,
232
 					StockCount:       warehousing_count,
234
 					StockCount:       warehousing_count,
233
 					Dealer:           dealer,
235
 					Dealer:           dealer,
236
+					LicenseNumber:    license_number,
234
 				}
237
 				}
235
 				warehousingInfo = append(warehousingInfo, warehouseInfo)
238
 				warehousingInfo = append(warehousingInfo, warehouseInfo)
236
 
239
 
429
 			goodids = append(goodids, item.ID)
432
 			goodids = append(goodids, item.ID)
430
 			//入库详情但里面查询
433
 			//入库详情但里面查询
431
 		}
434
 		}
432
-		info, _ := service.GetWarehoureOrderInfoByGoodId(goodids, startTime, endTime, adminUserInfo.CurrentOrgId)
433
-		for _, it := range info {
434
-			ids = append(ids, it.WarehousingId)
435
+		if len(goodids) > 0 {
436
+			info, _ := service.GetWarehoureOrderInfoByGoodId(goodids, startTime, endTime, adminUserInfo.CurrentOrgId)
437
+			for _, it := range info {
438
+				ids = append(ids, it.WarehousingId)
439
+			}
435
 		}
440
 		}
436
 	}
441
 	}
437
 
442
 
446
 	}
451
 	}
447
 }
452
 }
448
 func (c *StockManagerApiController) GetWarehouseInfoList() {
453
 func (c *StockManagerApiController) GetWarehouseInfoList() {
449
-	//id, _ := c.GetInt64("id", 0)
450
 
454
 
451
 	id := c.GetString("id")
455
 	id := c.GetString("id")
452
-
453
 	idArray := strings.Split(id, ",")
456
 	idArray := strings.Split(id, ",")
454
 	warehousing, err := service.FindWarehousingByIdOne(idArray)
457
 	warehousing, err := service.FindWarehousingByIdOne(idArray)
455
 
458
 
595
 
598
 
596
 				manufacturer := int64(items["manufacturer"].(float64))
599
 				manufacturer := int64(items["manufacturer"].(float64))
597
 				dealer := int64(items["dealer"].(float64))
600
 				dealer := int64(items["dealer"].(float64))
598
-
601
+				license_number, _ := items["license_number"].(string)
599
 				if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
602
 				if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
600
 					utils.ErrorLog("id")
603
 					utils.ErrorLog("id")
601
 					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
604
 					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
623
 						Manufacturer:     manufacturer,
626
 						Manufacturer:     manufacturer,
624
 						Dealer:           dealer,
627
 						Dealer:           dealer,
625
 						StockCount:       warehousing_count,
628
 						StockCount:       warehousing_count,
629
+						LicenseNumber:    license_number,
626
 					}
630
 					}
627
 					warehousingInfo = append(warehousingInfo, warehouseInfo)
631
 					warehousingInfo = append(warehousingInfo, warehouseInfo)
628
 
632
 
647
 						Manufacturer:     manufacturer,
651
 						Manufacturer:     manufacturer,
648
 						Dealer:           dealer,
652
 						Dealer:           dealer,
649
 						StockCount:       warehousing_count,
653
 						StockCount:       warehousing_count,
654
+						LicenseNumber:    license_number,
650
 					}
655
 					}
651
 					upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
656
 					upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
652
 				}
657
 				}
1082
 	operation_time := time.Now().Unix()
1087
 	operation_time := time.Now().Unix()
1083
 	creater := adminUserInfo.AdminUser.Id
1088
 	creater := adminUserInfo.AdminUser.Id
1084
 
1089
 
1090
+	_, errcode := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
1085
 	warehouseOut := models.WarehouseOut{
1091
 	warehouseOut := models.WarehouseOut{
1086
 		WarehouseOutOrderNumber: warehousing_out_order,
1092
 		WarehouseOutOrderNumber: warehousing_out_order,
1087
 		OperationTime:           operation_time,
1093
 		OperationTime:           operation_time,
1092
 		WarehouseOutTime:        warehousingOutDate.Unix(),
1098
 		WarehouseOutTime:        warehousingOutDate.Unix(),
1093
 		Type:                    types,
1099
 		Type:                    types,
1094
 	}
1100
 	}
1095
-	service.AddSigleWarehouseOut(&warehouseOut)
1101
+	if errcode == gorm.ErrRecordNotFound {
1102
+		service.AddSigleWarehouseOut(&warehouseOut)
1103
+	}
1104
+
1096
 	dataBody := make(map[string]interface{}, 0)
1105
 	dataBody := make(map[string]interface{}, 0)
1097
 	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
1106
 	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
1098
 	if err != nil {
1107
 	if err != nil {
1145
 
1154
 
1146
 				manufacturer := int64(items["manufacturer"].(float64))
1155
 				manufacturer := int64(items["manufacturer"].(float64))
1147
 
1156
 
1157
+				dealer := int64(items["dealer"].(float64))
1148
 				number := items["number"].(string)
1158
 				number := items["number"].(string)
1149
-				fmt.Println("number22222222222222", number)
1159
+
1160
+				expiry_date := items["expiry_date"].(string)
1161
+
1162
+				timeLayout := "2006-01-02"
1163
+				loc, _ := time.LoadLocation("Local")
1164
+				var expiryDate int64
1165
+				if len(expiry_date) > 0 {
1166
+					theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
1167
+					if err != nil {
1168
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1169
+						return
1170
+					}
1171
+					expiryDate = theTime.Unix()
1172
+				}
1173
+
1174
+				product_date := items["product_date"].(string)
1175
+
1176
+				var productDate int64
1177
+				if len(product_date) > 0 {
1178
+					theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
1179
+					if err != nil {
1180
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1181
+						return
1182
+					}
1183
+					productDate = theTime.Unix()
1184
+				}
1185
+
1150
 				warehouseOutInfo := &models.WarehouseOutInfo{
1186
 				warehouseOutInfo := &models.WarehouseOutInfo{
1151
 					WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1187
 					WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1152
 					WarehouseOutId:          warehouseOut.ID,
1188
 					WarehouseOutId:          warehouseOut.ID,
1162
 					Type:                    types,
1198
 					Type:                    types,
1163
 					Manufacturer:            manufacturer,
1199
 					Manufacturer:            manufacturer,
1164
 					Number:                  number,
1200
 					Number:                  number,
1201
+					ExpiryDate:              expiryDate,
1202
+					ProductDate:             productDate,
1203
+					Dealer:                  dealer,
1165
 				}
1204
 				}
1166
 				warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1205
 				warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1167
 
1206
 
1183
 		}
1222
 		}
1184
 	}
1223
 	}
1185
 
1224
 
1186
-	//查询库存
1225
+	//出库逻辑
1187
 	for _, item := range warehousingOutInfo {
1226
 	for _, item := range warehousingOutInfo {
1188
-		parseDateErr := service.ConsumablesDeliveryOne(adminUserInfo.CurrentOrgId, warehousingOutDate.Unix(), item, &warehouseOut, item.Count)
1189
-		fmt.Println(parseDateErr)
1190
-	}
1227
+		//查询库存
1228
+		warehouse, err := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId)
1229
+		fmt.Println("库存数量组吗", warehouse.Count)
1230
+		if err != nil {
1231
+			goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
1232
+			c.ServeSuccessJSON(map[string]interface{}{
1233
+				"msg":                "1",
1234
+				"good_name":          goodObj.GoodName,
1235
+				"specification_name": goodObj.SpecificationName,
1236
+			})
1237
+			return
1238
+		} else {
1239
+			parseDateErr := service.ConsumablesDeliveryOne(adminUserInfo.CurrentOrgId, warehousingOutDate.Unix(), item, &warehouseOut, item.Count)
1240
+			fmt.Println(parseDateErr)
1241
+			if parseDateErr != nil {
1242
+				utils.ErrorLog(parseDateErr.Error())
1243
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
1244
+				return
1245
+			}
1246
+
1247
+			c.ServeSuccessJSON(map[string]interface{}{
1248
+				"msg":                "2",
1249
+				"good_name":          "",
1250
+				"specification_name": "",
1251
+			})
1252
+		}
1191
 
1253
 
1192
-	errs := service.CreateWarehousingOutInfo(warehousingOutInfo)
1193
-	info, _ := service.FindLastWarehousingOutInfo(warehouseOut.WarehouseOutOrderNumber)
1194
-	if errs != nil {
1195
-		utils.ErrorLog(errs.Error())
1196
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
1197
-		return
1198
 	}
1254
 	}
1199
 
1255
 
1200
-	c.ServeSuccessJSON(map[string]interface{}{
1201
-		"msg":                   "出库成功",
1202
-		"info":                  info,
1203
-		"warehousing_out_order": warehousing_out_order,
1204
-	})
1256
+	//errs := service.CreateWarehousingOutInfo(warehousingOutInfo)
1257
+	//info, _ := service.FindLastWarehousingOutInfo(warehouseOut.WarehouseOutOrderNumber)
1205
 
1258
 
1206
 }
1259
 }
1207
 func (c *StockManagerApiController) GetWarehouseOutList() {
1260
 func (c *StockManagerApiController) GetWarehouseOutList() {
1235
 	}
1288
 	}
1236
 
1289
 
1237
 	adminUserInfo := c.GetAdminUserInfo()
1290
 	adminUserInfo := c.GetAdminUserInfo()
1238
-	warehouseOutList, total, err := service.FindAllWarehouseOutList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
1291
+	var ids []int64
1292
+	var goodids []int64
1293
+	if len(keywords) > 0 {
1294
+		//查询商品名称
1295
+		list, _ := service.GetGoodInforByGoodName(keywords, adminUserInfo.CurrentOrgId)
1296
+		for _, item := range list {
1297
+			goodids = append(goodids, item.ID)
1298
+		}
1299
+
1300
+		if len(goodids) > 0 {
1301
+			//出库详情但里面查询
1302
+			info, _ := service.GetWarehoureOrderOutByGoodId(goodids, startTime, endTime, adminUserInfo.CurrentOrgId)
1303
+			for _, it := range info {
1304
+				ids = append(ids, it.WarehouseOutId)
1305
+			}
1306
+		}
1307
+
1308
+	}
1309
+	warehouseOutList, total, err := service.FindAllWarehouseOutListOne(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, ids)
1239
 	fmt.Println(err)
1310
 	fmt.Println(err)
1240
 	if err == nil {
1311
 	if err == nil {
1241
 		c.ServeSuccessJSON(map[string]interface{}{
1312
 		c.ServeSuccessJSON(map[string]interface{}{
1386
 
1457
 
1387
 				manufacturer := int64(items["manufacturer"].(float64))
1458
 				manufacturer := int64(items["manufacturer"].(float64))
1388
 
1459
 
1460
+				dealer := int64(items["dealer"].(float64))
1461
+
1389
 				number := items["number"].(string)
1462
 				number := items["number"].(string)
1463
+
1464
+				timeLayout := "2006-01-02"
1465
+				loc, _ := time.LoadLocation("Local")
1466
+				expiry_date := items["expiry_date"].(string)
1467
+				var expiryDate int64
1468
+				if len(expiry_date) > 0 {
1469
+					theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
1470
+					if err != nil {
1471
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1472
+						return
1473
+					}
1474
+					expiryDate = theTime.Unix()
1475
+				}
1476
+
1477
+				product_date := items["product_date"].(string)
1478
+
1479
+				var productDate int64
1480
+				if len(product_date) > 0 {
1481
+					theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
1482
+					if err != nil {
1483
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1484
+						return
1485
+					}
1486
+					productDate = theTime.Unix()
1487
+				}
1488
+
1390
 				if id == 0 {
1489
 				if id == 0 {
1391
 					warehouseOutInfo := &models.WarehouseOutInfo{
1490
 					warehouseOutInfo := &models.WarehouseOutInfo{
1392
 						WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1491
 						WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1404
 						IsSys:                   0,
1503
 						IsSys:                   0,
1405
 						SysRecordTime:           0,
1504
 						SysRecordTime:           0,
1406
 						Number:                  number,
1505
 						Number:                  number,
1506
+						ExpiryDate:              expiryDate,
1507
+						ProductDate:             productDate,
1508
+						Dealer:                  dealer,
1509
+						Manufacturer:            manufacturer,
1407
 					}
1510
 					}
1408
 					warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1511
 					warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1409
 
1512
 
1441
 						IsSys:                   is_sys,
1544
 						IsSys:                   is_sys,
1442
 						SysRecordTime:           sys_record_time,
1545
 						SysRecordTime:           sys_record_time,
1443
 						Number:                  number,
1546
 						Number:                  number,
1547
+						ExpiryDate:              expiryDate,
1548
+						ProductDate:             productDate,
1549
+						Dealer:                  dealer,
1444
 					}
1550
 					}
1445
 					upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
1551
 					upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
1446
 				}
1552
 				}

+ 2 - 0
models/stock_models.go Wyświetl plik

128
 	WarehousingOrder string      `gorm:"column:warehousing_order" json:"warehousing_order"`
128
 	WarehousingOrder string      `gorm:"column:warehousing_order" json:"warehousing_order"`
129
 	GoodInfo         GoodInfo    `gorm:"ForeignKey:ID;AssociationForeignKey:GoodId" `
129
 	GoodInfo         GoodInfo    `gorm:"ForeignKey:ID;AssociationForeignKey:GoodId" `
130
 	Type             int64       `gorm:"column:type" json:"type"`
130
 	Type             int64       `gorm:"column:type" json:"type"`
131
+	LicenseNumber    string      `gorm:"column:license_number" json:"license_number" form:"license_number"`
131
 }
132
 }
132
 
133
 
133
 func (WarehousingInfo) TableName() string {
134
 func (WarehousingInfo) TableName() string {
163
 	SpecificationName string      `gorm:"column:specification_name" json:"specification_name" form:"specification_name"`
164
 	SpecificationName string      `gorm:"column:specification_name" json:"specification_name" form:"specification_name"`
164
 	MinNumber         int64       `gorm:"column:min_number" json:"min_number" form:"min_number"`
165
 	MinNumber         int64       `gorm:"column:min_number" json:"min_number" form:"min_number"`
165
 	PackingUnit       string      `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
166
 	PackingUnit       string      `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
167
+	Count             int64       `gorm:json:"count"`
166
 }
168
 }
167
 
169
 
168
 type WarehouseOut struct {
170
 type WarehouseOut struct {

+ 5 - 5
service/gobal_config_service.go Wyświetl plik

602
 		db = db.Where("x.ctime >=?", startime)
602
 		db = db.Where("x.ctime >=?", startime)
603
 	}
603
 	}
604
 	if endtime > 0 {
604
 	if endtime > 0 {
605
-		db = db.Where("c.time<=?", endtime)
605
+		db = db.Where("x.ctime<=?", endtime)
606
 	}
606
 	}
607
 	if orgid > 0 {
607
 	if orgid > 0 {
608
 		db = db.Where("x.org_id = ?", orgid)
608
 		db = db.Where("x.org_id = ?", orgid)
618
 		db = db.Where("x.ctime >=?", startime)
618
 		db = db.Where("x.ctime >=?", startime)
619
 	}
619
 	}
620
 	if endtime > 0 {
620
 	if endtime > 0 {
621
-		db = db.Where("c.time<=?", endtime)
621
+		db = db.Where("x.ctime<=?", endtime)
622
 	}
622
 	}
623
 	if orgid > 0 {
623
 	if orgid > 0 {
624
 		db = db.Where("x.org_id = ?", orgid)
624
 		db = db.Where("x.org_id = ?", orgid)
634
 		db = db.Where("x.ctime >=?", startime)
634
 		db = db.Where("x.ctime >=?", startime)
635
 	}
635
 	}
636
 	if endtime > 0 {
636
 	if endtime > 0 {
637
-		db = db.Where("c.time<=?", endtime)
637
+		db = db.Where("x.ctime<=?", endtime)
638
 	}
638
 	}
639
 	if orgid > 0 {
639
 	if orgid > 0 {
640
 		db = db.Where("x.org_id = ?", orgid)
640
 		db = db.Where("x.org_id = ?", orgid)
643
 	return info, err
643
 	return info, err
644
 }
644
 }
645
 
645
 
646
-func GetAutoDrugCountList(startime int64, endtime int64, orgid int64) (info []*models.VmDrugWarehouseInfo, err error) {
646
+func GetAutoDrugCountList(startime int64, endtime int64, orgid int64) (info []*models.DrugAutomaticReduceDetail, err error) {
647
 	db := XTReadDB().Table("xt_drug_automatic_reduce_detail as x").Where("x.status = 1")
647
 	db := XTReadDB().Table("xt_drug_automatic_reduce_detail as x").Where("x.status = 1")
648
 
648
 
649
 	if startime > 0 {
649
 	if startime > 0 {
650
 		db = db.Where("x.record_time >=?", startime)
650
 		db = db.Where("x.record_time >=?", startime)
651
 	}
651
 	}
652
 	if endtime > 0 {
652
 	if endtime > 0 {
653
-		db = db.Where("c.record_time<=?", endtime)
653
+		db = db.Where("x.record_time<=?", endtime)
654
 	}
654
 	}
655
 	if orgid > 0 {
655
 	if orgid > 0 {
656
 		db = db.Where("x.org_id = ?", orgid)
656
 		db = db.Where("x.org_id = ?", orgid)

+ 59 - 5
service/stock_service.go Wyświetl plik

375
 	if len(warehousingInfo) > 0 {
375
 	if len(warehousingInfo) > 0 {
376
 		utx := writeDb.Begin()
376
 		utx := writeDb.Begin()
377
 		if len(warehousingInfo) > 0 {
377
 		if len(warehousingInfo) > 0 {
378
-			thisSQL := "INSERT INTO xt_warehouse_info (warehousing_id, good_id, good_type_id, number, product_date,expiry_date,warehousing_count,price,total_price,dealer,manufacturer,remark,ctime,mtime,status,org_id,warehousing_order,type,stock_count) VALUES "
378
+			thisSQL := "INSERT INTO xt_warehouse_info (warehousing_id, good_id, good_type_id, number, product_date,expiry_date,warehousing_count,price,total_price,dealer,manufacturer,remark,ctime,mtime,status,org_id,warehousing_order,type,stock_count,license_number) VALUES "
379
 			insertParams := make([]string, 0)
379
 			insertParams := make([]string, 0)
380
 			insertData := make([]interface{}, 0)
380
 			insertData := make([]interface{}, 0)
381
 			for _, info := range warehousingInfo {
381
 			for _, info := range warehousingInfo {
382
-				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
382
+				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
383
 				insertData = append(insertData, info.WarehousingId)
383
 				insertData = append(insertData, info.WarehousingId)
384
 				insertData = append(insertData, info.GoodId)
384
 				insertData = append(insertData, info.GoodId)
385
 				insertData = append(insertData, info.GoodTypeId)
385
 				insertData = append(insertData, info.GoodTypeId)
399
 				insertData = append(insertData, info.WarehousingOrder)
399
 				insertData = append(insertData, info.WarehousingOrder)
400
 				insertData = append(insertData, info.Type)
400
 				insertData = append(insertData, info.Type)
401
 				insertData = append(insertData, info.WarehousingCount)
401
 				insertData = append(insertData, info.WarehousingCount)
402
-
402
+				insertData = append(insertData, info.LicenseNumber)
403
 			}
403
 			}
404
 			thisSQL += strings.Join(insertParams, ", ")
404
 			thisSQL += strings.Join(insertParams, ", ")
405
 			err = utx.Exec(thisSQL, insertData...).Error
405
 			err = utx.Exec(thisSQL, insertData...).Error
475
 	return info, err
475
 	return info, err
476
 }
476
 }
477
 
477
 
478
+func FindFirstWarehousingInfoByStockTwo(good_id int64, good_type_id int64) (info models.VmWarehousingInfo, err error) {
479
+	db := XTReadDB().Table("xt_warehouse_info as x").Where("x.status = 1")
480
+	if good_id > 0 {
481
+		db = db.Where("x.good_id = ?", good_id)
482
+	}
483
+	if good_type_id > 0 {
484
+		db = db.Where("x.good_type_id = ?", good_type_id)
485
+	}
486
+	err = db.Select("sum(x.stock_count) as count").Scan(&info).Error
487
+	return info, err
488
+}
489
+
478
 //药品先进先出,找出最先入库的批次
490
 //药品先进先出,找出最先入库的批次
479
 
491
 
480
 func FindLastDrugWarehousingInfoByID(drug_id int64) (info models.XtDrugWarehouseInfo, err error) {
492
 func FindLastDrugWarehousingInfoByID(drug_id int64) (info models.XtDrugWarehouseInfo, err error) {
561
 	return info, err
573
 	return info, err
562
 }
574
 }
563
 
575
 
576
+func GetWarehoureOrderOutByGoodId(good_id []int64, startime int64, endtime int64, orgid int64) (info []*models.WarehouseOutInfo, err error) {
577
+
578
+	db := XTReadDB().Model(&info).Where("status =1")
579
+	if len(good_id) > 0 {
580
+		db = db.Where("good_id in (?)", good_id)
581
+	}
582
+	if startime > 0 {
583
+		db = db.Where("ctime >=?", startime)
584
+	}
585
+	if endtime > 0 {
586
+		db = db.Where("ctime<=?", endtime)
587
+	}
588
+	if orgid > 0 {
589
+		db = db.Where("org_id = ?", orgid)
590
+	}
591
+	err = db.Find(&info).Error
592
+	return info, err
593
+}
594
+
564
 type VMDrugWarehouse struct {
595
 type VMDrugWarehouse struct {
565
 	ID               int64                `gorm:"column:id" json:"id" form:"id"`
596
 	ID               int64                `gorm:"column:id" json:"id" form:"id"`
566
 	WarehousingOrder string               `gorm:"column:warehousing_order" json:"warehousing_order" form:"warehousing_order"`
597
 	WarehousingOrder string               `gorm:"column:warehousing_order" json:"warehousing_order" form:"warehousing_order"`
1082
 
1113
 
1083
 }
1114
 }
1084
 
1115
 
1116
+func FindAllWarehouseOutListOne(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string, ids []int64) (list []*models.WarehouseOut, total int64, err error) {
1117
+	db := readDb.Model(&models.WarehouseOut{})
1118
+	db = db.Where("xt_warehouse_out.org_id = ? AND xt_warehouse_out.status = 1 AND xt_warehouse_out.type = ?", orgId, types)
1119
+
1120
+	if len(keywords) > 0 {
1121
+		likeKey := "%" + keywords + "%"
1122
+		db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_warehouse_out.creater")
1123
+		db = db.Where("sgj_user_admin_role.user_name LIKE ? OR xt_warehouse_out.warehouse_out_order_number LIKE ? or xt_warehouse_out.id in(?)", likeKey, likeKey, ids).Group("xt_warehouse_out.id")
1124
+	}
1125
+
1126
+	if startTime > 0 {
1127
+		db = db.Where("xt_warehouse_out.ctime >=?", startTime)
1128
+	}
1129
+	if endTime > 0 {
1130
+		db = db.Where("xt_warehouse_out.ctime<= ?", endTime)
1131
+	}
1132
+	db = db.Count(&total)
1133
+	offset := (page - 1) * limit
1134
+	err = db.Offset(offset).Limit(limit).Order("xt_warehouse_out.ctime desc").Find(&list).Error
1135
+	return list, total, err
1136
+
1137
+}
1138
+
1085
 func FindAllDrugWarehouseOutList(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string) (list []*models.DrugWarehouseOut, total int64, err error) {
1139
 func FindAllDrugWarehouseOutList(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string) (list []*models.DrugWarehouseOut, total int64, err error) {
1086
 	db := readDb.Model(&models.DrugWarehouseOut{})
1140
 	db := readDb.Model(&models.DrugWarehouseOut{})
1087
 	db = db.Where("xt_drug_warehouse_out.org_id = ? AND xt_drug_warehouse_out.status = 1 ", orgId)
1141
 	db = db.Where("xt_drug_warehouse_out.org_id = ? AND xt_drug_warehouse_out.status = 1 ", orgId)
2970
 	if orgid > 0 {
3024
 	if orgid > 0 {
2971
 		db = db.Where("x.org_id = ?", orgid)
3025
 		db = db.Where("x.org_id = ?", orgid)
2972
 	}
3026
 	}
2973
-	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,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
3027
+	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,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
2974
 	return out, err
3028
 	return out, err
2975
 }
3029
 }
2976
 
3030
 
2998
 	if orgid > 0 {
3052
 	if orgid > 0 {
2999
 		db = db.Where("x.org_id = ?", orgid)
3053
 		db = db.Where("x.org_id = ?", orgid)
3000
 	}
3054
 	}
3001
-	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,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
3055
+	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,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
3002
 	return out, err
3056
 	return out, err
3003
 }
3057
 }
3004
 
3058
 

+ 36 - 78
service/warhouse_service.go Wyświetl plik

1086
 	// 根据先进先出原则,查询最先入库的批次,进行出库
1086
 	// 根据先进先出原则,查询最先入库的批次,进行出库
1087
 	// 如果没有对应的库存,则报错
1087
 	// 如果没有对应的库存,则报错
1088
 	warehouse, err := FindFirstWarehousingInfoByStock(goods.GoodId, goods.GoodTypeId)
1088
 	warehouse, err := FindFirstWarehousingInfoByStock(goods.GoodId, goods.GoodTypeId)
1089
-
1089
+	fmt.Println("err222222222222222222222", warehouse.StockCount)
1090
 	if err != nil {
1090
 	if err != nil {
1091
+		fmt.Println("232323232323进来")
1091
 		return err
1092
 		return err
1092
 	}
1093
 	}
1093
 
1094
 
1094
 	// 将该批次的剩余库存数量转换为拆零数量
1095
 	// 将该批次的剩余库存数量转换为拆零数量
1095
 	stock_number = warehouse.StockCount
1096
 	stock_number = warehouse.StockCount
1096
-
1097
+	fmt.Println("3434343434343434", stock_number)
1098
+	fmt.Println("8888888888888888888", deliver_number)
1097
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
1099
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
1098
 	if stock_number >= deliver_number {
1100
 	if stock_number >= deliver_number {
1099
 		warehouseOutInfo := &models.WarehouseOutInfo{
1101
 		warehouseOutInfo := &models.WarehouseOutInfo{
1102
 			WarehouseInfotId:        warehouse.ID,
1104
 			WarehouseInfotId:        warehouse.ID,
1103
 			Status:                  1,
1105
 			Status:                  1,
1104
 			Ctime:                   time.Now().Unix(),
1106
 			Ctime:                   time.Now().Unix(),
1105
-			Remark:                  "",
1107
+			Remark:                  goods.Remark,
1106
 			OrgId:                   orgID,
1108
 			OrgId:                   orgID,
1107
 			Type:                    1,
1109
 			Type:                    1,
1108
-			Manufacturer:            0,
1109
-			Dealer:                  0,
1110
+			Manufacturer:            goods.Manufacturer,
1111
+			Dealer:                  goods.Dealer,
1110
 			IsSys:                   0,
1112
 			IsSys:                   0,
1111
 			SysRecordTime:           record_time,
1113
 			SysRecordTime:           record_time,
1112
 			GoodTypeId:              goods.GoodTypeId,
1114
 			GoodTypeId:              goods.GoodTypeId,
1113
 			GoodId:                  goods.GoodId,
1115
 			GoodId:                  goods.GoodId,
1116
+			ExpiryDate:              goods.ExpiryDate,
1117
+			ProductDate:             goods.ProductDate,
1118
+			Number:                  goods.Number,
1119
+			Price:                   goods.Price,
1114
 		}
1120
 		}
1115
 		warehouseOutInfo.Count = goods.Count
1121
 		warehouseOutInfo.Count = goods.Count
1116
 		stockInInfo, _ := FindLastStockInInfoRecord(goods.GoodId, orgID)
1122
 		stockInInfo, _ := FindLastStockInInfoRecord(goods.GoodId, orgID)
1117
 		warehouseOutInfo.Price = stockInInfo.Price
1123
 		warehouseOutInfo.Price = stockInInfo.Price
1118
 
1124
 
1119
-		//判断当前耗材是否有出库详情记录
1120
-		_, errcode := GetStockInRecoredByGoodIdOne(goods.GoodId, goods.GoodTypeId, record_time, orgID)
1121
-		if errcode == gorm.ErrRecordNotFound {
1122
-			errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
1123
-			if errOne != nil {
1124
-				return errOne
1125
-			}
1126
-		} else if errcode == nil {
1127
-			warehouseOutInfo := &models.WarehouseOutInfo{
1128
-				WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1129
-				WarehouseOutId:          warehouseOut.ID,
1130
-				WarehouseInfotId:        warehouse.ID,
1131
-				Status:                  1,
1132
-				Ctime:                   time.Now().Unix(),
1133
-				Remark:                  "",
1134
-				OrgId:                   orgID,
1135
-				Type:                    1,
1136
-				Manufacturer:            0,
1137
-				Dealer:                  0,
1138
-				IsSys:                   0,
1139
-				SysRecordTime:           record_time,
1140
-				GoodTypeId:              goods.GoodTypeId,
1141
-				GoodId:                  goods.GoodId,
1142
-			}
1143
-			warehouseOutInfo.Count = goods.Count
1144
-
1125
+		errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
1126
+		if errOne != nil {
1127
+			return errOne
1145
 		}
1128
 		}
1146
 
1129
 
1147
 		maxNumber = goods.Count
1130
 		maxNumber = goods.Count
1152
 
1135
 
1153
 		warehouse.StockCount = warehouse.StockCount - maxNumber
1136
 		warehouse.StockCount = warehouse.StockCount - maxNumber
1154
 		warehouse.Mtime = time.Now().Unix()
1137
 		warehouse.Mtime = time.Now().Unix()
1155
-
1156
 		if warehouse.StockCount < 0 {
1138
 		if warehouse.StockCount < 0 {
1139
+			fmt.Println("进来33232323232232323233232", warehouse.StockCount)
1157
 			return errors.New("库存数量不足")
1140
 			return errors.New("库存数量不足")
1158
 		}
1141
 		}
1159
-		errThree := UpDateWarehouseInfoByStock(&warehouse)
1160
-		if errThree != nil {
1161
-			return errThree
1162
-		}
1163
-
1164
 		return nil
1142
 		return nil
1165
 	} else {
1143
 	} else {
1166
 		// 当改批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
1144
 		// 当改批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
1170
 			WarehouseInfotId:        warehouse.ID,
1148
 			WarehouseInfotId:        warehouse.ID,
1171
 			Status:                  1,
1149
 			Status:                  1,
1172
 			Ctime:                   time.Now().Unix(),
1150
 			Ctime:                   time.Now().Unix(),
1173
-			Remark:                  "",
1151
+			Remark:                  goods.Remark,
1174
 			OrgId:                   orgID,
1152
 			OrgId:                   orgID,
1175
 			Type:                    1,
1153
 			Type:                    1,
1176
-			Manufacturer:            0,
1177
-			Dealer:                  0,
1154
+			Manufacturer:            goods.Manufacturer,
1155
+			Dealer:                  goods.Dealer,
1178
 			IsSys:                   0,
1156
 			IsSys:                   0,
1179
 			SysRecordTime:           record_time,
1157
 			SysRecordTime:           record_time,
1180
 			GoodTypeId:              goods.GoodTypeId,
1158
 			GoodTypeId:              goods.GoodTypeId,
1181
 			GoodId:                  goods.GoodId,
1159
 			GoodId:                  goods.GoodId,
1160
+			ExpiryDate:              goods.ExpiryDate,
1161
+			ProductDate:             goods.ProductDate,
1162
+			Number:                  goods.Number,
1163
+			Price:                   goods.Price,
1182
 		}
1164
 		}
1183
 		warehouseOutInfo.Count = stock_number
1165
 		warehouseOutInfo.Count = stock_number
1184
 		stockInInfo, _ := service.FindLastStockInInfoRecord(goods.GoodId, orgID)
1166
 		stockInInfo, _ := service.FindLastStockInInfoRecord(goods.GoodId, orgID)
1185
 		warehouseOutInfo.Price = stockInInfo.Price
1167
 		warehouseOutInfo.Price = stockInInfo.Price
1186
 
1168
 
1187
-		_, errcode := GetStockInRecoredByGoodIdOne(goods.GoodId, goods.GoodTypeId, record_time, orgID)
1188
-		if errcode == gorm.ErrRecordNotFound {
1189
-			errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
1190
-
1191
-			if errOne != nil {
1192
-				return errOne
1193
-			}
1194
-			// 出库完成后,要将该批次库存清零
1195
-			warehouse.StockCount = 0
1196
-			warehouse.Mtime = time.Now().Unix()
1197
-			errThree := UpDateWarehouseInfoByStock(&warehouse)
1198
-			if errThree != nil {
1199
-				return errThree
1200
-			}
1201
-			// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
1202
-			goods.Count = deliver_number - stock_number
1169
+		errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
1203
 
1170
 
1204
-			ConsumablesDeliveryOne(orgID, record_time, goods, warehouseOut, count)
1205
-		} else if errcode == nil {
1206
-
1207
-			warehouseOutInfo := &models.WarehouseOutInfo{
1208
-				WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1209
-				WarehouseOutId:          warehouseOut.ID,
1210
-				WarehouseInfotId:        warehouse.ID,
1211
-				Status:                  1,
1212
-				Ctime:                   time.Now().Unix(),
1213
-				Remark:                  "",
1214
-				OrgId:                   orgID,
1215
-				Type:                    1,
1216
-				Manufacturer:            0,
1217
-				Dealer:                  0,
1218
-				IsSys:                   0,
1219
-				SysRecordTime:           record_time,
1220
-				GoodTypeId:              goods.GoodTypeId,
1221
-				GoodId:                  goods.GoodId,
1222
-			}
1223
-			warehouseOutInfo.Count = goods.Count
1224
-			//更新入库详情表
1225
-			UpdateAutoMaticReduceDetailOne(goods.GoodId, goods.GoodTypeId, record_time, orgID, warehouseOutInfo)
1171
+		if errOne != nil {
1172
+			return errOne
1226
 		}
1173
 		}
1174
+		// 出库完成后,要将该批次库存清零
1175
+		warehouse.StockCount = 0
1176
+		warehouse.Mtime = time.Now().Unix()
1177
+		errThree := UpDateWarehouseInfoByStock(&warehouse)
1178
+		if errThree != nil {
1179
+			return errThree
1180
+		}
1181
+		// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
1182
+		goods.Count = deliver_number - stock_number
1183
+
1184
+		ConsumablesDeliveryOne(orgID, record_time, goods, warehouseOut, count)
1227
 
1185
 
1228
 	}
1186
 	}
1229
 	return nil
1187
 	return nil