Browse Source

耗材参数

XMLWAN 3 years ago
parent
commit
1921be1a12

+ 130 - 24
controllers/stock_in_api_controller.go View File

@@ -212,6 +212,8 @@ func (c *StockManagerApiController) CreateWarehouse() {
212 212
 
213 213
 				manufacturer := int64(items["manufacturer"].(float64))
214 214
 				dealer := int64(items["dealer"].(float64))
215
+
216
+				license_number, _ := items["license_number"].(string)
215 217
 				warehouseInfo := &models.WarehousingInfo{
216 218
 					WarehousingOrder: warehousing.WarehousingOrder,
217 219
 					WarehousingId:    warehousing.ID,
@@ -231,6 +233,7 @@ func (c *StockManagerApiController) CreateWarehouse() {
231 233
 					Manufacturer:     manufacturer,
232 234
 					StockCount:       warehousing_count,
233 235
 					Dealer:           dealer,
236
+					LicenseNumber:    license_number,
234 237
 				}
235 238
 				warehousingInfo = append(warehousingInfo, warehouseInfo)
236 239
 
@@ -429,9 +432,11 @@ func (c *StockManagerApiController) GetWarehouseList() {
429 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,10 +451,8 @@ func (c *StockManagerApiController) GetWarehouseList() {
446 451
 	}
447 452
 }
448 453
 func (c *StockManagerApiController) GetWarehouseInfoList() {
449
-	//id, _ := c.GetInt64("id", 0)
450 454
 
451 455
 	id := c.GetString("id")
452
-
453 456
 	idArray := strings.Split(id, ",")
454 457
 	warehousing, err := service.FindWarehousingByIdOne(idArray)
455 458
 
@@ -595,7 +598,7 @@ func (c *StockManagerApiController) EditWarehouse() {
595 598
 
596 599
 				manufacturer := int64(items["manufacturer"].(float64))
597 600
 				dealer := int64(items["dealer"].(float64))
598
-
601
+				license_number, _ := items["license_number"].(string)
599 602
 				if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
600 603
 					utils.ErrorLog("id")
601 604
 					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
@@ -623,6 +626,7 @@ func (c *StockManagerApiController) EditWarehouse() {
623 626
 						Manufacturer:     manufacturer,
624 627
 						Dealer:           dealer,
625 628
 						StockCount:       warehousing_count,
629
+						LicenseNumber:    license_number,
626 630
 					}
627 631
 					warehousingInfo = append(warehousingInfo, warehouseInfo)
628 632
 
@@ -647,6 +651,7 @@ func (c *StockManagerApiController) EditWarehouse() {
647 651
 						Manufacturer:     manufacturer,
648 652
 						Dealer:           dealer,
649 653
 						StockCount:       warehousing_count,
654
+						LicenseNumber:    license_number,
650 655
 					}
651 656
 					upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
652 657
 				}
@@ -1082,6 +1087,7 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1082 1087
 	operation_time := time.Now().Unix()
1083 1088
 	creater := adminUserInfo.AdminUser.Id
1084 1089
 
1090
+	_, errcode := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
1085 1091
 	warehouseOut := models.WarehouseOut{
1086 1092
 		WarehouseOutOrderNumber: warehousing_out_order,
1087 1093
 		OperationTime:           operation_time,
@@ -1092,7 +1098,10 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1092 1098
 		WarehouseOutTime:        warehousingOutDate.Unix(),
1093 1099
 		Type:                    types,
1094 1100
 	}
1095
-	service.AddSigleWarehouseOut(&warehouseOut)
1101
+	if errcode == gorm.ErrRecordNotFound {
1102
+		service.AddSigleWarehouseOut(&warehouseOut)
1103
+	}
1104
+
1096 1105
 	dataBody := make(map[string]interface{}, 0)
1097 1106
 	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
1098 1107
 	if err != nil {
@@ -1145,8 +1154,35 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1145 1154
 
1146 1155
 				manufacturer := int64(items["manufacturer"].(float64))
1147 1156
 
1157
+				dealer := int64(items["dealer"].(float64))
1148 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 1186
 				warehouseOutInfo := &models.WarehouseOutInfo{
1151 1187
 					WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1152 1188
 					WarehouseOutId:          warehouseOut.ID,
@@ -1162,6 +1198,9 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1162 1198
 					Type:                    types,
1163 1199
 					Manufacturer:            manufacturer,
1164 1200
 					Number:                  number,
1201
+					ExpiryDate:              expiryDate,
1202
+					ProductDate:             productDate,
1203
+					Dealer:                  dealer,
1165 1204
 				}
1166 1205
 				warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1167 1206
 
@@ -1183,25 +1222,39 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1183 1222
 		}
1184 1223
 	}
1185 1224
 
1186
-	//查询库存
1225
+	//出库逻辑
1187 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 1260
 func (c *StockManagerApiController) GetWarehouseOutList() {
@@ -1235,7 +1288,25 @@ func (c *StockManagerApiController) GetWarehouseOutList() {
1235 1288
 	}
1236 1289
 
1237 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 1310
 	fmt.Println(err)
1240 1311
 	if err == nil {
1241 1312
 		c.ServeSuccessJSON(map[string]interface{}{
@@ -1386,7 +1457,35 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1386 1457
 
1387 1458
 				manufacturer := int64(items["manufacturer"].(float64))
1388 1459
 
1460
+				dealer := int64(items["dealer"].(float64))
1461
+
1389 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 1489
 				if id == 0 {
1391 1490
 					warehouseOutInfo := &models.WarehouseOutInfo{
1392 1491
 						WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
@@ -1404,6 +1503,10 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1404 1503
 						IsSys:                   0,
1405 1504
 						SysRecordTime:           0,
1406 1505
 						Number:                  number,
1506
+						ExpiryDate:              expiryDate,
1507
+						ProductDate:             productDate,
1508
+						Dealer:                  dealer,
1509
+						Manufacturer:            manufacturer,
1407 1510
 					}
1408 1511
 					warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1409 1512
 
@@ -1441,6 +1544,9 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1441 1544
 						IsSys:                   is_sys,
1442 1545
 						SysRecordTime:           sys_record_time,
1443 1546
 						Number:                  number,
1547
+						ExpiryDate:              expiryDate,
1548
+						ProductDate:             productDate,
1549
+						Dealer:                  dealer,
1444 1550
 					}
1445 1551
 					upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
1446 1552
 				}

+ 2 - 0
models/stock_models.go View File

@@ -128,6 +128,7 @@ type WarehousingInfo struct {
128 128
 	WarehousingOrder string      `gorm:"column:warehousing_order" json:"warehousing_order"`
129 129
 	GoodInfo         GoodInfo    `gorm:"ForeignKey:ID;AssociationForeignKey:GoodId" `
130 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 134
 func (WarehousingInfo) TableName() string {
@@ -163,6 +164,7 @@ type VmWarehousingInfo struct {
163 164
 	SpecificationName string      `gorm:"column:specification_name" json:"specification_name" form:"specification_name"`
164 165
 	MinNumber         int64       `gorm:"column:min_number" json:"min_number" form:"min_number"`
165 166
 	PackingUnit       string      `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
167
+	Count             int64       `gorm:json:"count"`
166 168
 }
167 169
 
168 170
 type WarehouseOut struct {

+ 5 - 5
service/gobal_config_service.go View File

@@ -602,7 +602,7 @@ func GetDrugCountList(startime int64, endtime int64, orgid int64) (info []*model
602 602
 		db = db.Where("x.ctime >=?", startime)
603 603
 	}
604 604
 	if endtime > 0 {
605
-		db = db.Where("c.time<=?", endtime)
605
+		db = db.Where("x.ctime<=?", endtime)
606 606
 	}
607 607
 	if orgid > 0 {
608 608
 		db = db.Where("x.org_id = ?", orgid)
@@ -618,7 +618,7 @@ func GetMinCountList(startime int64, endtime int64, orgid int64) (info []*models
618 618
 		db = db.Where("x.ctime >=?", startime)
619 619
 	}
620 620
 	if endtime > 0 {
621
-		db = db.Where("c.time<=?", endtime)
621
+		db = db.Where("x.ctime<=?", endtime)
622 622
 	}
623 623
 	if orgid > 0 {
624 624
 		db = db.Where("x.org_id = ?", orgid)
@@ -634,7 +634,7 @@ func GetOutDrugCountList(startime int64, endtime int64, orgid int64) (info []*mo
634 634
 		db = db.Where("x.ctime >=?", startime)
635 635
 	}
636 636
 	if endtime > 0 {
637
-		db = db.Where("c.time<=?", endtime)
637
+		db = db.Where("x.ctime<=?", endtime)
638 638
 	}
639 639
 	if orgid > 0 {
640 640
 		db = db.Where("x.org_id = ?", orgid)
@@ -643,14 +643,14 @@ func GetOutDrugCountList(startime int64, endtime int64, orgid int64) (info []*mo
643 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 647
 	db := XTReadDB().Table("xt_drug_automatic_reduce_detail as x").Where("x.status = 1")
648 648
 
649 649
 	if startime > 0 {
650 650
 		db = db.Where("x.record_time >=?", startime)
651 651
 	}
652 652
 	if endtime > 0 {
653
-		db = db.Where("c.record_time<=?", endtime)
653
+		db = db.Where("x.record_time<=?", endtime)
654 654
 	}
655 655
 	if orgid > 0 {
656 656
 		db = db.Where("x.org_id = ?", orgid)

+ 59 - 5
service/stock_service.go View File

@@ -375,11 +375,11 @@ func CreateWarehousingInfo(warehousingInfo []*models.WarehousingInfo) (err error
375 375
 	if len(warehousingInfo) > 0 {
376 376
 		utx := writeDb.Begin()
377 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 379
 			insertParams := make([]string, 0)
380 380
 			insertData := make([]interface{}, 0)
381 381
 			for _, info := range warehousingInfo {
382
-				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
382
+				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
383 383
 				insertData = append(insertData, info.WarehousingId)
384 384
 				insertData = append(insertData, info.GoodId)
385 385
 				insertData = append(insertData, info.GoodTypeId)
@@ -399,7 +399,7 @@ func CreateWarehousingInfo(warehousingInfo []*models.WarehousingInfo) (err error
399 399
 				insertData = append(insertData, info.WarehousingOrder)
400 400
 				insertData = append(insertData, info.Type)
401 401
 				insertData = append(insertData, info.WarehousingCount)
402
-
402
+				insertData = append(insertData, info.LicenseNumber)
403 403
 			}
404 404
 			thisSQL += strings.Join(insertParams, ", ")
405 405
 			err = utx.Exec(thisSQL, insertData...).Error
@@ -475,6 +475,18 @@ func FindFirstWarehousingInfoByStock(good_id int64, good_type_id int64) (info mo
475 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 492
 func FindLastDrugWarehousingInfoByID(drug_id int64) (info models.XtDrugWarehouseInfo, err error) {
@@ -561,6 +573,25 @@ func GetWarehoureOrderInfoByGoodId(good_id []int64, startime int64, endtime int6
561 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 595
 type VMDrugWarehouse struct {
565 596
 	ID               int64                `gorm:"column:id" json:"id" form:"id"`
566 597
 	WarehousingOrder string               `gorm:"column:warehousing_order" json:"warehousing_order" form:"warehousing_order"`
@@ -1082,6 +1113,29 @@ func FindAllWarehouseOutList(orgId int64, page int64, limit int64, startTime int
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 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 1140
 	db := readDb.Model(&models.DrugWarehouseOut{})
1087 1141
 	db = db.Where("xt_drug_warehouse_out.org_id = ? AND xt_drug_warehouse_out.status = 1 ", orgId)
@@ -2970,7 +3024,7 @@ func GetOrderDetialByOrderId(id int64, orgid int64) (out []*models.WarehouseOutI
2970 3024
 	if orgid > 0 {
2971 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 3028
 	return out, err
2975 3029
 }
2976 3030
 
@@ -2998,7 +3052,7 @@ func GetOrderDetialByOrderIdOne(id []string, orgid int64) (out []*models.Warehou
2998 3052
 	if orgid > 0 {
2999 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 3056
 	return out, err
3003 3057
 }
3004 3058
 

+ 36 - 78
service/warhouse_service.go View File

@@ -1086,14 +1086,16 @@ func ConsumablesDeliveryOne(orgID int64, record_time int64, goods *models.Wareho
1086 1086
 	// 根据先进先出原则,查询最先入库的批次,进行出库
1087 1087
 	// 如果没有对应的库存,则报错
1088 1088
 	warehouse, err := FindFirstWarehousingInfoByStock(goods.GoodId, goods.GoodTypeId)
1089
-
1089
+	fmt.Println("err222222222222222222222", warehouse.StockCount)
1090 1090
 	if err != nil {
1091
+		fmt.Println("232323232323进来")
1091 1092
 		return err
1092 1093
 	}
1093 1094
 
1094 1095
 	// 将该批次的剩余库存数量转换为拆零数量
1095 1096
 	stock_number = warehouse.StockCount
1096
-
1097
+	fmt.Println("3434343434343434", stock_number)
1098
+	fmt.Println("8888888888888888888", deliver_number)
1097 1099
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
1098 1100
 	if stock_number >= deliver_number {
1099 1101
 		warehouseOutInfo := &models.WarehouseOutInfo{
@@ -1102,46 +1104,27 @@ func ConsumablesDeliveryOne(orgID int64, record_time int64, goods *models.Wareho
1102 1104
 			WarehouseInfotId:        warehouse.ID,
1103 1105
 			Status:                  1,
1104 1106
 			Ctime:                   time.Now().Unix(),
1105
-			Remark:                  "",
1107
+			Remark:                  goods.Remark,
1106 1108
 			OrgId:                   orgID,
1107 1109
 			Type:                    1,
1108
-			Manufacturer:            0,
1109
-			Dealer:                  0,
1110
+			Manufacturer:            goods.Manufacturer,
1111
+			Dealer:                  goods.Dealer,
1110 1112
 			IsSys:                   0,
1111 1113
 			SysRecordTime:           record_time,
1112 1114
 			GoodTypeId:              goods.GoodTypeId,
1113 1115
 			GoodId:                  goods.GoodId,
1116
+			ExpiryDate:              goods.ExpiryDate,
1117
+			ProductDate:             goods.ProductDate,
1118
+			Number:                  goods.Number,
1119
+			Price:                   goods.Price,
1114 1120
 		}
1115 1121
 		warehouseOutInfo.Count = goods.Count
1116 1122
 		stockInInfo, _ := FindLastStockInInfoRecord(goods.GoodId, orgID)
1117 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 1130
 		maxNumber = goods.Count
@@ -1152,15 +1135,10 @@ func ConsumablesDeliveryOne(orgID int64, record_time int64, goods *models.Wareho
1152 1135
 
1153 1136
 		warehouse.StockCount = warehouse.StockCount - maxNumber
1154 1137
 		warehouse.Mtime = time.Now().Unix()
1155
-
1156 1138
 		if warehouse.StockCount < 0 {
1139
+			fmt.Println("进来33232323232232323233232", warehouse.StockCount)
1157 1140
 			return errors.New("库存数量不足")
1158 1141
 		}
1159
-		errThree := UpDateWarehouseInfoByStock(&warehouse)
1160
-		if errThree != nil {
1161
-			return errThree
1162
-		}
1163
-
1164 1142
 		return nil
1165 1143
 	} else {
1166 1144
 		// 当改批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
@@ -1170,60 +1148,40 @@ func ConsumablesDeliveryOne(orgID int64, record_time int64, goods *models.Wareho
1170 1148
 			WarehouseInfotId:        warehouse.ID,
1171 1149
 			Status:                  1,
1172 1150
 			Ctime:                   time.Now().Unix(),
1173
-			Remark:                  "",
1151
+			Remark:                  goods.Remark,
1174 1152
 			OrgId:                   orgID,
1175 1153
 			Type:                    1,
1176
-			Manufacturer:            0,
1177
-			Dealer:                  0,
1154
+			Manufacturer:            goods.Manufacturer,
1155
+			Dealer:                  goods.Dealer,
1178 1156
 			IsSys:                   0,
1179 1157
 			SysRecordTime:           record_time,
1180 1158
 			GoodTypeId:              goods.GoodTypeId,
1181 1159
 			GoodId:                  goods.GoodId,
1160
+			ExpiryDate:              goods.ExpiryDate,
1161
+			ProductDate:             goods.ProductDate,
1162
+			Number:                  goods.Number,
1163
+			Price:                   goods.Price,
1182 1164
 		}
1183 1165
 		warehouseOutInfo.Count = stock_number
1184 1166
 		stockInInfo, _ := service.FindLastStockInInfoRecord(goods.GoodId, orgID)
1185 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 1187
 	return nil