|
@@ -418,11 +418,11 @@ func CreateDrugWarehousingInfo(warehousingInfo []*models.DrugWarehouseInfo) (err
|
418
|
418
|
if len(warehousingInfo) > 0 {
|
419
|
419
|
utx := writeDb.Begin()
|
420
|
420
|
if len(warehousingInfo) > 0 {
|
421
|
|
- thisSQL := "INSERT INTO xt_drug_warehouse_info (warehousing_id, drug_id, number, product_date,expiry_date,warehousing_count,price,total_price,dealer,manufacturer,remark,ctime,mtime,status,org_id,warehousing_order,type,retail_price,retail_total_price,stock_max_number,max_unit,min_unit) VALUES "
|
|
421
|
+ thisSQL := "INSERT INTO xt_drug_warehouse_info (warehousing_id, drug_id, number, product_date,expiry_date,warehousing_count,price,total_price,dealer,manufacturer,remark,ctime,mtime,status,org_id,warehousing_order,type,retail_price,retail_total_price,stock_max_number,max_unit,min_unit,batch_number) VALUES "
|
422
|
422
|
insertParams := make([]string, 0)
|
423
|
423
|
insertData := make([]interface{}, 0)
|
424
|
424
|
for _, info := range warehousingInfo {
|
425
|
|
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
|
|
425
|
+ insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
|
426
|
426
|
insertData = append(insertData, info.WarehousingId)
|
427
|
427
|
insertData = append(insertData, info.DrugId)
|
428
|
428
|
insertData = append(insertData, info.Number)
|
|
@@ -445,6 +445,7 @@ func CreateDrugWarehousingInfo(warehousingInfo []*models.DrugWarehouseInfo) (err
|
445
|
445
|
insertData = append(insertData, info.StockMaxNumber)
|
446
|
446
|
insertData = append(insertData, info.MaxUnit)
|
447
|
447
|
insertData = append(insertData, info.MinUnit)
|
|
448
|
+ insertData = append(insertData, info.BatchNumber)
|
448
|
449
|
}
|
449
|
450
|
thisSQL += strings.Join(insertParams, ", ")
|
450
|
451
|
err = utx.Exec(thisSQL, insertData...).Error
|
|
@@ -694,6 +695,28 @@ func FindAllDrugWarehousingList(orgId int64, page int64, limit int64, startTime
|
694
|
695
|
return
|
695
|
696
|
}
|
696
|
697
|
|
|
698
|
+func FindAllDrugWarehousingListOne(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string, ids []int64) (list []*VMDrugWarehouse, total int64, err error) {
|
|
699
|
+ db := readDb.Model(&VMDrugWarehouse{})
|
|
700
|
+ db = db.Where("xt_drug_warehouse.org_id = ? AND xt_drug_warehouse.status = 1", orgId)
|
|
701
|
+ db = db.Preload("Manufacturers", "status = 1 AND org_id = ?", orgId)
|
|
702
|
+ db = db.Preload("Dealers", "status = 1 AND org_id = ?", orgId)
|
|
703
|
+ if len(keywords) > 0 {
|
|
704
|
+ likeKey := "%" + keywords + "%"
|
|
705
|
+ db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_drug_warehouse.creater")
|
|
706
|
+ db = db.Where(" sgj_user_admin_role.user_name LIKE ? OR xt_drug_warehouse.warehousing_order LIKE ? OR xt_drug_warehouse.id in(?)", likeKey, likeKey, ids).Group("xt_drug_warehouse.id")
|
|
707
|
+ }
|
|
708
|
+ if startTime > 0 {
|
|
709
|
+ db = db.Where("xt_drug_warehouse.operation_time >=?", startTime)
|
|
710
|
+ }
|
|
711
|
+ if endTime > 0 {
|
|
712
|
+ db = db.Where("xt_drug_warehouse.operation_time<= ?", endTime)
|
|
713
|
+ }
|
|
714
|
+ db = db.Count(&total)
|
|
715
|
+ offset := (page - 1) * limit
|
|
716
|
+ err = db.Offset(offset).Limit(limit).Order("xt_drug_warehouse.ctime desc").Find(&list).Error
|
|
717
|
+ return
|
|
718
|
+}
|
|
719
|
+
|
697
|
720
|
func FindWarehousingInfoById(id int64) (list []*models.WarehousingInfo, err error) {
|
698
|
721
|
err = readDb.Model(&models.WarehousingInfo{}).Where("warehousing_id = ? AND status = 1", id).Preload("GoodInfo").Find(&list).Error
|
699
|
722
|
return list, err
|
|
@@ -917,7 +940,7 @@ func FindReturnInfoById(id int64) (list []*models.SalesReturnInfo, err error) {
|
917
|
940
|
}
|
918
|
941
|
|
919
|
942
|
func FindCancelStockInfoById(id int64) (list []*models.CancelStockInfo, err error) {
|
920
|
|
- err = readDb.Model(&models.CancelStockInfo{}).Where("cancel_stock_id = ? AND status = 1", id).Find(&list).Error
|
|
943
|
+ err = readDb.Model(&models.CancelStockInfo{}).Where("cancel_stock_id = ? AND status = 1", id).Preload("GoodInfo", "status = 1").Find(&list).Error
|
921
|
944
|
return list, err
|
922
|
945
|
}
|
923
|
946
|
|
|
@@ -998,11 +1021,11 @@ func CreateWarehousingOutInfo(warehouseOutInfo []*models.WarehouseOutInfo) (err
|
998
|
1021
|
if len(warehouseOutInfo) > 0 {
|
999
|
1022
|
utx := writeDb.Begin()
|
1000
|
1023
|
if len(warehouseOutInfo) > 0 {
|
1001
|
|
- thisSQL := "INSERT INTO xt_warehouse_out_info (warehouse_out_id, good_id, good_type_id, product_date,expiry_date,count,price,total_price,remark,ctime,status,org_id,warehouse_out_order_number,type,dealer,manufacturer,number) VALUES "
|
|
1024
|
+ thisSQL := "INSERT INTO xt_warehouse_out_info (warehouse_out_id, good_id, good_type_id, product_date,expiry_date,count,price,total_price,remark,ctime,status,org_id,warehouse_out_order_number,type,dealer,manufacturer,number,license_number) VALUES "
|
1002
|
1025
|
insertParams := make([]string, 0)
|
1003
|
1026
|
insertData := make([]interface{}, 0)
|
1004
|
1027
|
for _, info := range warehouseOutInfo {
|
1005
|
|
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
|
|
1028
|
+ insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
|
1006
|
1029
|
insertData = append(insertData, info.WarehouseOutId)
|
1007
|
1030
|
insertData = append(insertData, info.GoodId)
|
1008
|
1031
|
insertData = append(insertData, info.GoodTypeId)
|
|
@@ -1020,6 +1043,7 @@ func CreateWarehousingOutInfo(warehouseOutInfo []*models.WarehouseOutInfo) (err
|
1020
|
1043
|
insertData = append(insertData, info.Dealer)
|
1021
|
1044
|
insertData = append(insertData, info.Manufacturer)
|
1022
|
1045
|
insertData = append(insertData, info.Number)
|
|
1046
|
+ insertData = append(insertData, info.LicenseNumber)
|
1023
|
1047
|
}
|
1024
|
1048
|
thisSQL += strings.Join(insertParams, ", ")
|
1025
|
1049
|
err = utx.Exec(thisSQL, insertData...).Error
|
|
@@ -1038,11 +1062,11 @@ func CreateDrugWarehousingOutInfo(warehouseOutInfo []*models.DrugWarehouseOutInf
|
1038
|
1062
|
if len(warehouseOutInfo) > 0 {
|
1039
|
1063
|
utx := writeDb.Begin()
|
1040
|
1064
|
if len(warehouseOutInfo) > 0 {
|
1041
|
|
- 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) VALUES "
|
|
1065
|
+ 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 "
|
1042
|
1066
|
insertParams := make([]string, 0)
|
1043
|
1067
|
insertData := make([]interface{}, 0)
|
1044
|
1068
|
for _, info := range warehouseOutInfo {
|
1045
|
|
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
|
|
1069
|
+ insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
|
1046
|
1070
|
insertData = append(insertData, info.WarehouseOutId)
|
1047
|
1071
|
insertData = append(insertData, info.DrugId)
|
1048
|
1072
|
insertData = append(insertData, info.ProductDate)
|
|
@@ -1060,7 +1084,8 @@ func CreateDrugWarehousingOutInfo(warehouseOutInfo []*models.DrugWarehouseOutInf
|
1060
|
1084
|
insertData = append(insertData, info.Manufacturer)
|
1061
|
1085
|
insertData = append(insertData, info.RetailPrice)
|
1062
|
1086
|
insertData = append(insertData, info.RetailTotalPrice)
|
1063
|
|
-
|
|
1087
|
+ insertData = append(insertData, info.Number)
|
|
1088
|
+ insertData = append(insertData, info.BatchNumber)
|
1064
|
1089
|
}
|
1065
|
1090
|
thisSQL += strings.Join(insertParams, ", ")
|
1066
|
1091
|
err = utx.Exec(thisSQL, insertData...).Error
|
|
@@ -1161,6 +1186,30 @@ func FindAllDrugWarehouseOutList(orgId int64, page int64, limit int64, startTime
|
1161
|
1186
|
|
1162
|
1187
|
}
|
1163
|
1188
|
|
|
1189
|
+func FindAllDrugWarehouseOutListOne(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string, ids []int64) (list []*models.DrugWarehouseOut, total int64, err error) {
|
|
1190
|
+ db := readDb.Model(&models.DrugWarehouseOut{})
|
|
1191
|
+ db = db.Where("xt_drug_warehouse_out.org_id = ? AND xt_drug_warehouse_out.status = 1 ", orgId)
|
|
1192
|
+
|
|
1193
|
+ if len(keywords) > 0 {
|
|
1194
|
+ likeKey := "%" + keywords + "%"
|
|
1195
|
+ db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_drug_warehouse_out.creater")
|
|
1196
|
+
|
|
1197
|
+ db = db.Where("sgj_user_admin_role.user_name LIKE ? OR xt_drug_warehouse_out.warehouse_out_order_number LIKE ? or xt_drug_warehouse_out.id in(?) ", likeKey, likeKey, ids).Group("xt_drug_warehouse_out.id")
|
|
1198
|
+ }
|
|
1199
|
+
|
|
1200
|
+ if startTime > 0 {
|
|
1201
|
+ db = db.Where("xt_drug_warehouse_out.ctime >=?", startTime)
|
|
1202
|
+ }
|
|
1203
|
+ if endTime > 0 {
|
|
1204
|
+ db = db.Where("xt_drug_warehouse_out.ctime<= ?", endTime)
|
|
1205
|
+ }
|
|
1206
|
+ db = db.Count(&total)
|
|
1207
|
+ offset := (page - 1) * limit
|
|
1208
|
+ err = db.Offset(offset).Limit(limit).Order("xt_drug_warehouse_out.ctime desc").Find(&list).Error
|
|
1209
|
+ return list, total, err
|
|
1210
|
+
|
|
1211
|
+}
|
|
1212
|
+
|
1164
|
1213
|
func FindWarehouseOutInfoById(id int64) (list []*models.WarehouseOutInfo, err error) {
|
1165
|
1214
|
err = readDb.Model(&models.WarehouseOutInfo{}).Where("warehouse_out_id = ? AND status = 1 AND count <> 0 AND good_id <> 0", id).Preload("GoodInfo", "status = 1").Order("good_type_id desc").Find(&list).Error
|
1166
|
1215
|
return list, err
|
|
@@ -1190,6 +1239,8 @@ type DrugWarehouseOutInfo struct {
|
1190
|
1239
|
SysRecordTime int64 `gorm:"column:sys_record_time" json:"sys_record_time" form:"sys_record_time"`
|
1191
|
1240
|
RetailPrice float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
|
1192
|
1241
|
RetailTotalPrice float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
|
|
1242
|
+ Number string `gorm:"column:number" json:"number" form:"number"`
|
|
1243
|
+ BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
|
1193
|
1244
|
Drug *Drug `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug"`
|
1194
|
1245
|
}
|
1195
|
1246
|
|
|
@@ -1909,7 +1960,7 @@ func EditDrugCancelStock(sales models.DrugCancelStock) {
|
1909
|
1960
|
}
|
1910
|
1961
|
|
1911
|
1962
|
func FindCancelStockById(id int64, org_id int64) (cancelStock models.CancelStock, err error) {
|
1912
|
|
- err = readDb.Model(&models.CancelStock{}).Preload("Manufacturers", "status = 1 AND org_id = ?", org_id).Preload("Dealers", "status = 1 AND org_id = ?", org_id).Where("id = ? AND status = 1", id).First(&cancelStock).Error
|
|
1963
|
+ err = readDb.Model(&models.CancelStock{}).Where("id = ? AND status = 1", id).First(&cancelStock).Error
|
1913
|
1964
|
return cancelStock, err
|
1914
|
1965
|
|
1915
|
1966
|
}
|
|
@@ -2350,6 +2401,7 @@ type DrugAutomaticReduceDetail struct {
|
2350
|
2401
|
OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
|
2351
|
2402
|
DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
|
2352
|
2403
|
Count int64 `gorm:"column:count" json:"count" form:"count"`
|
|
2404
|
+ CountUnit string `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
|
2353
|
2405
|
Drug *Drug `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug"`
|
2354
|
2406
|
Patients *models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"user"`
|
2355
|
2407
|
}
|
|
@@ -2930,7 +2982,7 @@ func GetStockListById(good_id int64, orgid int64, limit int64, page int64, start
|
2930
|
2982
|
if good_id > 0 {
|
2931
|
2983
|
db = db.Where("x.good_id = ?", good_id)
|
2932
|
2984
|
}
|
2933
|
|
- err = db.Select("x.id,x.warehousing_id,x.good_id,x.good_type_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehousing_unit,x.stock_count,x.price,x.total_price,x.dealer,t.manufacturer,x.remark,x.ctime,x.is_return,x.warehousing_order,x.type,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.min_unit").Joins("left join xt_good_information as t on t.id = x.good_id").Count(&total).Offset(offset).Limit(limit).Scan(&info).Error
|
|
2985
|
+ err = db.Select("x.id,x.warehousing_id,x.good_id,x.good_type_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehousing_unit,x.stock_count,x.price,x.total_price,x.dealer,t.manufacturer,x.remark,x.ctime,x.is_return,x.warehousing_order,x.type,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.min_unit,t.buy_price").Joins("left join xt_good_information as t on t.id = x.good_id").Count(&total).Offset(offset).Limit(limit).Scan(&info).Error
|
2934
|
2986
|
return info, total, err
|
2935
|
2987
|
|
2936
|
2988
|
}
|
|
@@ -2939,6 +2991,7 @@ func GetStockOutList(good_id int64, orgid int64, limit int64, page int64, starti
|
2939
|
2991
|
offset := (page - 1) * limit
|
2940
|
2992
|
|
2941
|
2993
|
db := XTReadDB().Table("xt_warehouse_out_info as x").Where("x.status= 1")
|
|
2994
|
+
|
2942
|
2995
|
if startime > 0 {
|
2943
|
2996
|
db = db.Where("x.ctime>=?", startime)
|
2944
|
2997
|
}
|
|
@@ -3024,7 +3077,7 @@ func GetOrderDetialByOrderId(id int64, orgid int64) (out []*models.WarehouseOutI
|
3024
|
3077
|
if orgid > 0 {
|
3025
|
3078
|
db = db.Where("x.org_id = ?", orgid)
|
3026
|
3079
|
}
|
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
|
|
3080
|
+ 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
|
3028
|
3081
|
return out, err
|
3029
|
3082
|
}
|
3030
|
3083
|
|
|
@@ -3052,7 +3105,7 @@ func GetOrderDetialByOrderIdOne(id []string, orgid int64) (out []*models.Warehou
|
3052
|
3105
|
if orgid > 0 {
|
3053
|
3106
|
db = db.Where("x.org_id = ?", orgid)
|
3054
|
3107
|
}
|
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
|
|
3108
|
+ 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
|
3056
|
3109
|
return out, err
|
3057
|
3110
|
}
|
3058
|
3111
|
|
|
@@ -3170,3 +3223,150 @@ func FindeDrugWarehouseOutDetail(ids []string, orgid int64) (info []*models.VmDr
|
3170
|
3223
|
err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.warehousing_out_target,x.count,x.count_unit,x.price,x.product_date,x.expiry_date,x.number,x.batch_number,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.drug_name").Joins("left join xt_base_drug as t on t.id =x.drug_id").Scan(&info).Error
|
3171
|
3224
|
return info, err
|
3172
|
3225
|
}
|
|
3226
|
+
|
|
3227
|
+func GetDrugNameByKeyword(keyword string, orgid int64) (basedrug []*models.XtBaseDrug, err error) {
|
|
3228
|
+
|
|
3229
|
+ db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1")
|
|
3230
|
+ likeKey := "%" + keyword + "%"
|
|
3231
|
+ if len(keyword) > 0 {
|
|
3232
|
+ db = db.Where("x.drug_name like ?", likeKey)
|
|
3233
|
+ }
|
|
3234
|
+ if orgid > 0 {
|
|
3235
|
+ db = db.Where("x.org_id = ?", orgid)
|
|
3236
|
+ }
|
|
3237
|
+ err = db.Find(&basedrug).Error
|
|
3238
|
+
|
|
3239
|
+ return basedrug, err
|
|
3240
|
+
|
|
3241
|
+}
|
|
3242
|
+
|
|
3243
|
+func GetDrugWarehouseOrderDetail(ids []int64, orgid int64, startime int64, endtime int64) (info []*models.XtDrugWarehouseOutInfo, err error) {
|
|
3244
|
+
|
|
3245
|
+ db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
|
|
3246
|
+
|
|
3247
|
+ if len(ids) > 0 {
|
|
3248
|
+ db = db.Where("x.drug_id in(?)", ids)
|
|
3249
|
+ }
|
|
3250
|
+
|
|
3251
|
+ if orgid > 0 {
|
|
3252
|
+ db = db.Where("x.org_id = ?", orgid)
|
|
3253
|
+ }
|
|
3254
|
+ if startime > 0 {
|
|
3255
|
+ db = db.Where("x.ctime>=?", startime)
|
|
3256
|
+ }
|
|
3257
|
+ if endtime > 0 {
|
|
3258
|
+ db = db.Where("x.ctime<=?", endtime)
|
|
3259
|
+ }
|
|
3260
|
+
|
|
3261
|
+ err = db.Find(&info).Error
|
|
3262
|
+ return info, err
|
|
3263
|
+}
|
|
3264
|
+
|
|
3265
|
+func GetDrugWarehouseOrderDetailTwo(ids []int64, orgid int64, startime int64, endtime int64) (info []*models.XtDrugWarehouseInfo, err error) {
|
|
3266
|
+
|
|
3267
|
+ db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
|
|
3268
|
+
|
|
3269
|
+ if len(ids) > 0 {
|
|
3270
|
+ db = db.Where("x.drug_id in(?)", ids)
|
|
3271
|
+ }
|
|
3272
|
+
|
|
3273
|
+ if orgid > 0 {
|
|
3274
|
+ db = db.Where("x.org_id = ?", orgid)
|
|
3275
|
+ }
|
|
3276
|
+ if startime > 0 {
|
|
3277
|
+ db = db.Where("x.ctime>=?", startime)
|
|
3278
|
+ }
|
|
3279
|
+ if endtime > 0 {
|
|
3280
|
+ db = db.Where("x.ctime<=?", endtime)
|
|
3281
|
+ }
|
|
3282
|
+
|
|
3283
|
+ err = db.Find(&info).Error
|
|
3284
|
+ return info, err
|
|
3285
|
+}
|
|
3286
|
+
|
|
3287
|
+func GetDrugTotalCount(drugid int64, orgid int64) (info models.VmDrugWarehouseInfo, err error) {
|
|
3288
|
+
|
|
3289
|
+ db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
|
|
3290
|
+ if drugid > 0 {
|
|
3291
|
+ db = db.Where("x.drug_id = ?", drugid)
|
|
3292
|
+ }
|
|
3293
|
+ if orgid > 0 {
|
|
3294
|
+ db = db.Where("x.org_id = ?", orgid)
|
|
3295
|
+ }
|
|
3296
|
+ err = db.Select("x.drug_id,sum(x.stock_max_number) as count").Find(&info).Error
|
|
3297
|
+ return info, err
|
|
3298
|
+}
|
|
3299
|
+
|
|
3300
|
+func GetDrugByGoodId(drugid int64) (models.BaseDrugLib, error) {
|
|
3301
|
+
|
|
3302
|
+ lib := models.BaseDrugLib{}
|
|
3303
|
+ err := XTReadDB().Model(&lib).Where("id = ? and status = 1", drugid).Find(&lib).Error
|
|
3304
|
+ return lib, err
|
|
3305
|
+}
|
|
3306
|
+
|
|
3307
|
+func GetWarehoureOrderInfoList(goodid int64, orgid int64) (info []*models.WarehousingInfo, err error) {
|
|
3308
|
+
|
|
3309
|
+ db := XTReadDB().Table("xt_warehouse_info as x").Where("x.status = 1")
|
|
3310
|
+
|
|
3311
|
+ if goodid > 0 {
|
|
3312
|
+ db = db.Where("x.good_id = ?", goodid)
|
|
3313
|
+ }
|
|
3314
|
+
|
|
3315
|
+ if orgid > 0 {
|
|
3316
|
+ db = db.Where("x.org_id = ?", orgid)
|
|
3317
|
+ }
|
|
3318
|
+
|
|
3319
|
+ err = db.Select("x.id,x.warehousing_id,x.good_id,x.good_type_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.price,x.total_price,x.dealer,x.manufacturer,x.remark,x.is_return,x.warehousing_order,x.warehousing_unit,x.stock_count,x.license_number").Order("x.ctime desc").Find(&info).Error
|
|
3320
|
+ return info, err
|
|
3321
|
+}
|
|
3322
|
+
|
|
3323
|
+func UpdateWarehousingCount(info *models.WarehousingInfo, goodid int64, orgid int64, warehousingId int64) error {
|
|
3324
|
+
|
|
3325
|
+ err := XTWriteDB().Model(&info).Where("good_id = ? and org_id = ? and status =1 and warehousing_id = ?", goodid, orgid, warehousingId).Updates(map[string]interface{}{"stock_cout": info.StockCount}).Error
|
|
3326
|
+ return err
|
|
3327
|
+}
|
|
3328
|
+
|
|
3329
|
+func GetSingleCancelOrder(id int64, orgid int64) (info []*models.CancelStockInfo, err error) {
|
|
3330
|
+
|
|
3331
|
+ err = XTReadDB().Where("cancel_stock_id = ? and status = 1 and org_id = ?", id, orgid).Preload("GoodInfo", "status = 1").Find(&info).Error
|
|
3332
|
+ return info, err
|
|
3333
|
+}
|
|
3334
|
+
|
|
3335
|
+func UpdateCancelOut(list []*models.WarehousingInfo, count int64) {
|
|
3336
|
+
|
|
3337
|
+ //遍历循环入库数据
|
|
3338
|
+ for _, item := range list {
|
|
3339
|
+
|
|
3340
|
+ //计算每个批次剩余库存与入库数据的差 然后和退库数量比较
|
|
3341
|
+ if (item.WarehousingCount - item.StockCount) >= count {
|
|
3342
|
+ //如果差距大于退库数量,则直接把退库数量增加到该批次中
|
|
3343
|
+ info := models.WarehousingInfo{
|
|
3344
|
+ GoodId: item.GoodId,
|
|
3345
|
+ OrgId: item.OrgId,
|
|
3346
|
+ WarehousingId: item.WarehousingId,
|
|
3347
|
+ StockCount: count,
|
|
3348
|
+ }
|
|
3349
|
+ UpdateWarehousingCount(&info, item.GoodId, item.OrgId, item.WarehousingId)
|
|
3350
|
+ break
|
|
3351
|
+ }
|
|
3352
|
+
|
|
3353
|
+ if (item.WarehousingCount - item.StockCount) < count {
|
|
3354
|
+
|
|
3355
|
+ //如果该批次小于退库数量,则先出库该相差数量
|
|
3356
|
+ var countOne = item.WarehousingCount - item.StockCount
|
|
3357
|
+ infoOne := models.WarehousingInfo{
|
|
3358
|
+ GoodId: item.GoodId,
|
|
3359
|
+ OrgId: item.OrgId,
|
|
3360
|
+ WarehousingId: item.WarehousingId,
|
|
3361
|
+ StockCount: countOne,
|
|
3362
|
+ }
|
|
3363
|
+
|
|
3364
|
+ UpdateWarehousingCount(&infoOne, item.GoodId, item.OrgId, item.WarehousingId)
|
|
3365
|
+
|
|
3366
|
+ //剩余的出库到第二个批次
|
|
3367
|
+ var countTwo = count - countOne
|
|
3368
|
+ UpdateCancelOut(list, countTwo)
|
|
3369
|
+ }
|
|
3370
|
+ }
|
|
3371
|
+
|
|
3372
|
+}
|