|
@@ -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
|
|
@@ -740,6 +741,28 @@ func FindAllDrugWarehousingList(orgId int64, page int64, limit int64, startTime
|
740
|
741
|
return
|
741
|
742
|
}
|
742
|
743
|
|
|
744
|
+func FindAllDrugWarehousingListOne(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string, ids []int64) (list []*VMDrugWarehouse, total int64, err error) {
|
|
745
|
+ db := readDb.Model(&VMDrugWarehouse{})
|
|
746
|
+ db = db.Where("xt_drug_warehouse.org_id = ? AND xt_drug_warehouse.status = 1", orgId)
|
|
747
|
+ db = db.Preload("Manufacturers", "status = 1 AND org_id = ?", orgId)
|
|
748
|
+ db = db.Preload("Dealers", "status = 1 AND org_id = ?", orgId)
|
|
749
|
+ if len(keywords) > 0 {
|
|
750
|
+ likeKey := "%" + keywords + "%"
|
|
751
|
+ db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_drug_warehouse.creater")
|
|
752
|
+ 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")
|
|
753
|
+ }
|
|
754
|
+ if startTime > 0 {
|
|
755
|
+ db = db.Where("xt_drug_warehouse.operation_time >=?", startTime)
|
|
756
|
+ }
|
|
757
|
+ if endTime > 0 {
|
|
758
|
+ db = db.Where("xt_drug_warehouse.operation_time<= ?", endTime)
|
|
759
|
+ }
|
|
760
|
+ db = db.Count(&total)
|
|
761
|
+ offset := (page - 1) * limit
|
|
762
|
+ err = db.Offset(offset).Limit(limit).Order("xt_drug_warehouse.ctime desc").Find(&list).Error
|
|
763
|
+ return
|
|
764
|
+}
|
|
765
|
+
|
743
|
766
|
func FindWarehousingInfoById(id int64) (list []*models.WarehousingInfo, err error) {
|
744
|
767
|
err = readDb.Model(&models.WarehousingInfo{}).Where("warehousing_id = ? AND status = 1", id).Preload("GoodInfo").Find(&list).Error
|
745
|
768
|
return list, err
|
|
@@ -766,7 +789,7 @@ func FindDrugWarehousingInfoByIdOne(id []string, org_id int64) (list []*models.S
|
766
|
789
|
if org_id > 0 {
|
767
|
790
|
db = db.Where("x.org_id = ?", org_id)
|
768
|
791
|
}
|
769
|
|
- 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.remark,x.batch_number,t.manufacturer,t.dealer,t.drug_name,t.last_price,t.dose_unit,t.dose,t.min_number,t.min_unit,t.max_unit,t.drug_type").Joins("left join xt_base_drug as t on t.id = x.drug_id").Scan(&list).Error
|
|
792
|
+ 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.stock_max_number,x.stock_min_number,x.price,x.remark,x.batch_number,x.batch_number,t.manufacturer,t.dealer,t.drug_name,t.last_price,t.dose_unit,t.dose,t.min_number,t.min_unit,t.max_unit,t.drug_type").Joins("left join xt_base_drug as t on t.id = x.drug_id").Scan(&list).Error
|
770
|
793
|
return list, err
|
771
|
794
|
}
|
772
|
795
|
|
|
@@ -963,7 +986,7 @@ func FindReturnInfoById(id int64) (list []*models.SalesReturnInfo, err error) {
|
963
|
986
|
}
|
964
|
987
|
|
965
|
988
|
func FindCancelStockInfoById(id int64) (list []*models.CancelStockInfo, err error) {
|
966
|
|
- err = readDb.Model(&models.CancelStockInfo{}).Where("cancel_stock_id = ? AND status = 1", id).Find(&list).Error
|
|
989
|
+ err = readDb.Model(&models.CancelStockInfo{}).Where("cancel_stock_id = ? AND status = 1", id).Preload("GoodInfo", "status = 1").Find(&list).Error
|
967
|
990
|
return list, err
|
968
|
991
|
}
|
969
|
992
|
|
|
@@ -1044,11 +1067,11 @@ func CreateWarehousingOutInfo(warehouseOutInfo []*models.WarehouseOutInfo) (err
|
1044
|
1067
|
if len(warehouseOutInfo) > 0 {
|
1045
|
1068
|
utx := writeDb.Begin()
|
1046
|
1069
|
if len(warehouseOutInfo) > 0 {
|
1047
|
|
- 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 "
|
|
1070
|
+ 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 "
|
1048
|
1071
|
insertParams := make([]string, 0)
|
1049
|
1072
|
insertData := make([]interface{}, 0)
|
1050
|
1073
|
for _, info := range warehouseOutInfo {
|
1051
|
|
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
|
|
1074
|
+ insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
|
1052
|
1075
|
insertData = append(insertData, info.WarehouseOutId)
|
1053
|
1076
|
insertData = append(insertData, info.GoodId)
|
1054
|
1077
|
insertData = append(insertData, info.GoodTypeId)
|
|
@@ -1066,6 +1089,7 @@ func CreateWarehousingOutInfo(warehouseOutInfo []*models.WarehouseOutInfo) (err
|
1066
|
1089
|
insertData = append(insertData, info.Dealer)
|
1067
|
1090
|
insertData = append(insertData, info.Manufacturer)
|
1068
|
1091
|
insertData = append(insertData, info.Number)
|
|
1092
|
+ insertData = append(insertData, info.LicenseNumber)
|
1069
|
1093
|
}
|
1070
|
1094
|
thisSQL += strings.Join(insertParams, ", ")
|
1071
|
1095
|
err = utx.Exec(thisSQL, insertData...).Error
|
|
@@ -1084,11 +1108,11 @@ func CreateDrugWarehousingOutInfo(warehouseOutInfo []*models.DrugWarehouseOutInf
|
1084
|
1108
|
if len(warehouseOutInfo) > 0 {
|
1085
|
1109
|
utx := writeDb.Begin()
|
1086
|
1110
|
if len(warehouseOutInfo) > 0 {
|
1087
|
|
- 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 "
|
|
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 "
|
1088
|
1112
|
insertParams := make([]string, 0)
|
1089
|
1113
|
insertData := make([]interface{}, 0)
|
1090
|
1114
|
for _, info := range warehouseOutInfo {
|
1091
|
|
- insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
|
|
1115
|
+ insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
|
1092
|
1116
|
insertData = append(insertData, info.WarehouseOutId)
|
1093
|
1117
|
insertData = append(insertData, info.DrugId)
|
1094
|
1118
|
insertData = append(insertData, info.ProductDate)
|
|
@@ -1106,7 +1130,8 @@ func CreateDrugWarehousingOutInfo(warehouseOutInfo []*models.DrugWarehouseOutInf
|
1106
|
1130
|
insertData = append(insertData, info.Manufacturer)
|
1107
|
1131
|
insertData = append(insertData, info.RetailPrice)
|
1108
|
1132
|
insertData = append(insertData, info.RetailTotalPrice)
|
1109
|
|
-
|
|
1133
|
+ insertData = append(insertData, info.Number)
|
|
1134
|
+ insertData = append(insertData, info.BatchNumber)
|
1110
|
1135
|
}
|
1111
|
1136
|
thisSQL += strings.Join(insertParams, ", ")
|
1112
|
1137
|
err = utx.Exec(thisSQL, insertData...).Error
|
|
@@ -1207,6 +1232,30 @@ func FindAllDrugWarehouseOutList(orgId int64, page int64, limit int64, startTime
|
1207
|
1232
|
|
1208
|
1233
|
}
|
1209
|
1234
|
|
|
1235
|
+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) {
|
|
1236
|
+ db := readDb.Model(&models.DrugWarehouseOut{})
|
|
1237
|
+ db = db.Where("xt_drug_warehouse_out.org_id = ? AND xt_drug_warehouse_out.status = 1 ", orgId)
|
|
1238
|
+
|
|
1239
|
+ if len(keywords) > 0 {
|
|
1240
|
+ likeKey := "%" + keywords + "%"
|
|
1241
|
+ db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_drug_warehouse_out.creater")
|
|
1242
|
+
|
|
1243
|
+ 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")
|
|
1244
|
+ }
|
|
1245
|
+
|
|
1246
|
+ if startTime > 0 {
|
|
1247
|
+ db = db.Where("xt_drug_warehouse_out.ctime >=?", startTime)
|
|
1248
|
+ }
|
|
1249
|
+ if endTime > 0 {
|
|
1250
|
+ db = db.Where("xt_drug_warehouse_out.ctime<= ?", endTime)
|
|
1251
|
+ }
|
|
1252
|
+ db = db.Count(&total)
|
|
1253
|
+ offset := (page - 1) * limit
|
|
1254
|
+ err = db.Offset(offset).Limit(limit).Order("xt_drug_warehouse_out.ctime desc").Find(&list).Error
|
|
1255
|
+ return list, total, err
|
|
1256
|
+
|
|
1257
|
+}
|
|
1258
|
+
|
1210
|
1259
|
func FindWarehouseOutInfoById(id int64) (list []*models.WarehouseOutInfo, err error) {
|
1211
|
1260
|
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
|
1212
|
1261
|
return list, err
|
|
@@ -1236,6 +1285,8 @@ type DrugWarehouseOutInfo struct {
|
1236
|
1285
|
SysRecordTime int64 `gorm:"column:sys_record_time" json:"sys_record_time" form:"sys_record_time"`
|
1237
|
1286
|
RetailPrice float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
|
1238
|
1287
|
RetailTotalPrice float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
|
|
1288
|
+ Number string `gorm:"column:number" json:"number" form:"number"`
|
|
1289
|
+ BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
|
1239
|
1290
|
Drug *Drug `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug"`
|
1240
|
1291
|
}
|
1241
|
1292
|
|
|
@@ -1955,7 +2006,7 @@ func EditDrugCancelStock(sales models.DrugCancelStock) {
|
1955
|
2006
|
}
|
1956
|
2007
|
|
1957
|
2008
|
func FindCancelStockById(id int64, org_id int64) (cancelStock models.CancelStock, err error) {
|
1958
|
|
- 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
|
|
2009
|
+ err = readDb.Model(&models.CancelStock{}).Where("id = ? AND status = 1", id).First(&cancelStock).Error
|
1959
|
2010
|
return cancelStock, err
|
1960
|
2011
|
|
1961
|
2012
|
}
|
|
@@ -2396,6 +2447,7 @@ type DrugAutomaticReduceDetail struct {
|
2396
|
2447
|
OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
|
2397
|
2448
|
DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
|
2398
|
2449
|
Count int64 `gorm:"column:count" json:"count" form:"count"`
|
|
2450
|
+ CountUnit string `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
|
2399
|
2451
|
Drug *Drug `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug"`
|
2400
|
2452
|
Patients *models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"user"`
|
2401
|
2453
|
}
|
|
@@ -2976,7 +3028,7 @@ func GetStockListById(good_id int64, orgid int64, limit int64, page int64, start
|
2976
|
3028
|
if good_id > 0 {
|
2977
|
3029
|
db = db.Where("x.good_id = ?", good_id)
|
2978
|
3030
|
}
|
2979
|
|
- 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
|
|
3031
|
+ 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
|
2980
|
3032
|
return info, total, err
|
2981
|
3033
|
|
2982
|
3034
|
}
|
|
@@ -2985,6 +3037,7 @@ func GetStockOutList(good_id int64, orgid int64, limit int64, page int64, starti
|
2985
|
3037
|
offset := (page - 1) * limit
|
2986
|
3038
|
|
2987
|
3039
|
db := XTReadDB().Table("xt_warehouse_out_info as x").Where("x.status= 1")
|
|
3040
|
+
|
2988
|
3041
|
if startime > 0 {
|
2989
|
3042
|
db = db.Where("x.ctime>=?", startime)
|
2990
|
3043
|
}
|
|
@@ -3070,7 +3123,7 @@ func GetOrderDetialByOrderId(id int64, orgid int64) (out []*models.WarehouseOutI
|
3070
|
3123
|
if orgid > 0 {
|
3071
|
3124
|
db = db.Where("x.org_id = ?", orgid)
|
3072
|
3125
|
}
|
3073
|
|
- 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
|
|
3126
|
+ 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
|
3074
|
3127
|
return out, err
|
3075
|
3128
|
}
|
3076
|
3129
|
|
|
@@ -3098,7 +3151,7 @@ func GetOrderDetialByOrderIdOne(id []string, orgid int64) (out []*models.Warehou
|
3098
|
3151
|
if orgid > 0 {
|
3099
|
3152
|
db = db.Where("x.org_id = ?", orgid)
|
3100
|
3153
|
}
|
3101
|
|
- 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
|
|
3154
|
+ 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
|
3102
|
3155
|
return out, err
|
3103
|
3156
|
}
|
3104
|
3157
|
|
|
@@ -3139,7 +3192,7 @@ func GetExprotStockList(orgid int64, orderid []string, startime int64, endtime i
|
3139
|
3192
|
if endtime > 0 {
|
3140
|
3193
|
db = db.Where("x.ctime<=?", endtime)
|
3141
|
3194
|
}
|
3142
|
|
- err = db.Select("x.id,x.good_id,x.good_type_id,x.number,x.product_date,x.expiry_date,Sum(x.warehousing_count)as total_count,x.price,x.dealer,x.manufacturer,x.remark,t.good_name,t.packing_unit,t.specification_name,t.manufacturer,t.dealer").Joins("left join xt_good_information as t on t.id = x.good_id").Group("x.good_id").Scan(&info).Error
|
|
3195
|
+ err = db.Select("x.id,x.good_id,x.good_type_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.price,x.dealer,x.manufacturer,x.remark,x.license_number,t.good_name,t.packing_unit,t.specification_name,t.manufacturer,t.dealer").Joins("left join xt_good_information as t on t.id = x.good_id").Scan(&info).Error
|
3143
|
3196
|
|
3144
|
3197
|
return info, err
|
3145
|
3198
|
}
|
|
@@ -3182,7 +3235,7 @@ func GetOutExprotList(orgid int64, ids []string, startime int64, endtime int64)
|
3182
|
3235
|
db = db.Where("x.ctime<=?", endtime)
|
3183
|
3236
|
}
|
3184
|
3237
|
|
3185
|
|
- err = db.Select("x.id,x.warehouse_out_id,x.good_id,x.good_type_id,x.warehousing_out_target,Sum(x.count) as count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.remark,x.number,t.good_name,t.specification_name,t.min_number,t.packing_price,t.min_unit,t.packing_unit,t.manufacturer,t.dealer").Joins("left join xt_good_information as t on t.id = x.good_id").Group("x.good_id").Scan(&out).Error
|
|
3238
|
+ err = db.Select("x.id,x.warehouse_out_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.remark,x.number,x.license_number,t.good_name,t.specification_name,t.min_number,t.packing_price,t.min_unit,t.packing_unit,t.manufacturer,t.dealer").Joins("left join xt_good_information as t on t.id = x.good_id").Scan(&out).Error
|
3186
|
3239
|
return out, err
|
3187
|
3240
|
|
3188
|
3241
|
}
|
|
@@ -3216,3 +3269,191 @@ func FindeDrugWarehouseOutDetail(ids []string, orgid int64) (info []*models.VmDr
|
3216
|
3269
|
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
|
3217
|
3270
|
return info, err
|
3218
|
3271
|
}
|
|
3272
|
+
|
|
3273
|
+func GetDrugNameByKeyword(keyword string, orgid int64) (basedrug []*models.XtBaseDrug, err error) {
|
|
3274
|
+
|
|
3275
|
+ db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1")
|
|
3276
|
+ likeKey := "%" + keyword + "%"
|
|
3277
|
+ if len(keyword) > 0 {
|
|
3278
|
+ db = db.Where("x.drug_name like ?", likeKey)
|
|
3279
|
+ }
|
|
3280
|
+ if orgid > 0 {
|
|
3281
|
+ db = db.Where("x.org_id = ?", orgid)
|
|
3282
|
+ }
|
|
3283
|
+ err = db.Find(&basedrug).Error
|
|
3284
|
+
|
|
3285
|
+ return basedrug, err
|
|
3286
|
+
|
|
3287
|
+}
|
|
3288
|
+
|
|
3289
|
+func GetDrugWarehouseOrderDetail(ids []int64, orgid int64, startime int64, endtime int64) (info []*models.XtDrugWarehouseOutInfo, err error) {
|
|
3290
|
+
|
|
3291
|
+ db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
|
|
3292
|
+
|
|
3293
|
+ if len(ids) > 0 {
|
|
3294
|
+ db = db.Where("x.drug_id in(?)", ids)
|
|
3295
|
+ }
|
|
3296
|
+
|
|
3297
|
+ if orgid > 0 {
|
|
3298
|
+ db = db.Where("x.org_id = ?", orgid)
|
|
3299
|
+ }
|
|
3300
|
+ if startime > 0 {
|
|
3301
|
+ db = db.Where("x.ctime>=?", startime)
|
|
3302
|
+ }
|
|
3303
|
+ if endtime > 0 {
|
|
3304
|
+ db = db.Where("x.ctime<=?", endtime)
|
|
3305
|
+ }
|
|
3306
|
+
|
|
3307
|
+ err = db.Find(&info).Error
|
|
3308
|
+ return info, err
|
|
3309
|
+}
|
|
3310
|
+
|
|
3311
|
+func GetDrugWarehouseOrderDetailTwo(ids []int64, orgid int64, startime int64, endtime int64) (info []*models.XtDrugWarehouseInfo, err error) {
|
|
3312
|
+
|
|
3313
|
+ db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
|
|
3314
|
+
|
|
3315
|
+ if len(ids) > 0 {
|
|
3316
|
+ db = db.Where("x.drug_id in(?)", ids)
|
|
3317
|
+ }
|
|
3318
|
+
|
|
3319
|
+ if orgid > 0 {
|
|
3320
|
+ db = db.Where("x.org_id = ?", orgid)
|
|
3321
|
+ }
|
|
3322
|
+ if startime > 0 {
|
|
3323
|
+ db = db.Where("x.ctime>=?", startime)
|
|
3324
|
+ }
|
|
3325
|
+ if endtime > 0 {
|
|
3326
|
+ db = db.Where("x.ctime<=?", endtime)
|
|
3327
|
+ }
|
|
3328
|
+
|
|
3329
|
+ err = db.Find(&info).Error
|
|
3330
|
+ return info, err
|
|
3331
|
+}
|
|
3332
|
+
|
|
3333
|
+func GetDrugTotalCount(drugid int64, orgid int64) (info models.VmDrugWarehouseInfo, err error) {
|
|
3334
|
+
|
|
3335
|
+ db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
|
|
3336
|
+ if drugid > 0 {
|
|
3337
|
+ db = db.Where("x.drug_id = ?", drugid)
|
|
3338
|
+ }
|
|
3339
|
+ if orgid > 0 {
|
|
3340
|
+ db = db.Where("x.org_id = ?", orgid)
|
|
3341
|
+ }
|
|
3342
|
+ err = db.Select("x.drug_id,sum(x.stock_max_number) as count").Find(&info).Error
|
|
3343
|
+ return info, err
|
|
3344
|
+}
|
|
3345
|
+
|
|
3346
|
+func GetDrugByGoodId(drugid int64) (models.BaseDrugLib, error) {
|
|
3347
|
+
|
|
3348
|
+ lib := models.BaseDrugLib{}
|
|
3349
|
+ err := XTReadDB().Model(&lib).Where("id = ? and status = 1", drugid).Find(&lib).Error
|
|
3350
|
+ return lib, err
|
|
3351
|
+}
|
|
3352
|
+
|
|
3353
|
+func GetWarehoureOrderInfoList(goodid int64, orgid int64) (info []*models.WarehousingInfo, err error) {
|
|
3354
|
+
|
|
3355
|
+ db := XTReadDB().Table("xt_warehouse_info as x").Where("x.status = 1")
|
|
3356
|
+
|
|
3357
|
+ if goodid > 0 {
|
|
3358
|
+ db = db.Where("x.good_id = ?", goodid)
|
|
3359
|
+ }
|
|
3360
|
+
|
|
3361
|
+ if orgid > 0 {
|
|
3362
|
+ db = db.Where("x.org_id = ?", orgid)
|
|
3363
|
+ }
|
|
3364
|
+
|
|
3365
|
+ 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,x.org_id").Find(&info).Error
|
|
3366
|
+ return info, err
|
|
3367
|
+}
|
|
3368
|
+
|
|
3369
|
+func UpdateWarehousingCount(info *models.WarehousingInfo, goodid int64, orgid int64, warehousingId int64) error {
|
|
3370
|
+
|
|
3371
|
+ err := XTWriteDB().Model(&info).Where("good_id = ? and org_id = ? and status =1 and warehousing_id = ?", goodid, orgid, warehousingId).Updates(map[string]interface{}{"stock_count": info.StockCount}).Error
|
|
3372
|
+ return err
|
|
3373
|
+}
|
|
3374
|
+
|
|
3375
|
+func GetSingleCancelOrder(id int64, orgid int64) (info []*models.CancelStockInfo, err error) {
|
|
3376
|
+
|
|
3377
|
+ err = XTReadDB().Where("cancel_stock_id = ? and status = 1 and org_id = ?", id, orgid).Preload("GoodInfo", "status = 1").Find(&info).Error
|
|
3378
|
+ return info, err
|
|
3379
|
+}
|
|
3380
|
+
|
|
3381
|
+func UpdateCancelOut(list []*models.WarehousingInfo, count int64) error {
|
|
3382
|
+
|
|
3383
|
+ //遍历循环入库数据
|
|
3384
|
+ for i, item := range list {
|
|
3385
|
+ //计算每个批次剩余库存与入库数据的差 然后和退库数量比较
|
|
3386
|
+ if (item.WarehousingCount - item.StockCount) >= count {
|
|
3387
|
+ //如果差距大于退库数量,则直接把退库数量增加到该批次中
|
|
3388
|
+ info := models.WarehousingInfo{
|
|
3389
|
+ GoodId: item.GoodId,
|
|
3390
|
+ OrgId: item.OrgId,
|
|
3391
|
+ WarehousingId: item.WarehousingId,
|
|
3392
|
+ StockCount: item.StockCount + count,
|
|
3393
|
+ }
|
|
3394
|
+ UpdateWarehousingCount(&info, item.GoodId, item.OrgId, item.WarehousingId)
|
|
3395
|
+ break
|
|
3396
|
+ }
|
|
3397
|
+
|
|
3398
|
+ if (item.WarehousingCount - item.StockCount) < count {
|
|
3399
|
+
|
|
3400
|
+ //如果该批次小于退库数量,则先出库该相差数量
|
|
3401
|
+ var countOne = item.WarehousingCount - item.StockCount
|
|
3402
|
+
|
|
3403
|
+ infoOne := models.WarehousingInfo{
|
|
3404
|
+ GoodId: item.GoodId,
|
|
3405
|
+ OrgId: item.OrgId,
|
|
3406
|
+ WarehousingId: item.WarehousingId,
|
|
3407
|
+ StockCount: countOne + item.StockCount,
|
|
3408
|
+ }
|
|
3409
|
+
|
|
3410
|
+ err := UpdateWarehousingCount(&infoOne, item.GoodId, item.OrgId, item.WarehousingId)
|
|
3411
|
+ if err == nil {
|
|
3412
|
+ //剩余的出库到第二个批次
|
|
3413
|
+ var countTwo = count - countOne
|
|
3414
|
+ infos := append(list, list[i+1])
|
|
3415
|
+ var idArray []*models.WarehousingInfo
|
|
3416
|
+ for _, it := range infos {
|
|
3417
|
+ if it.WarehousingId != item.WarehousingId {
|
|
3418
|
+ idArray = append(idArray, it)
|
|
3419
|
+ }
|
|
3420
|
+ }
|
|
3421
|
+ //查询更新后的库存
|
|
3422
|
+ UpdateCancelOut(idArray, countTwo)
|
|
3423
|
+ return err
|
|
3424
|
+ } else {
|
|
3425
|
+ return err
|
|
3426
|
+ }
|
|
3427
|
+
|
|
3428
|
+ }
|
|
3429
|
+ }
|
|
3430
|
+
|
|
3431
|
+ return err
|
|
3432
|
+}
|
|
3433
|
+
|
|
3434
|
+func GetCancelStockOrderPrint(idstr []string) (info []*models.CancelStockInfo, err error) {
|
|
3435
|
+
|
|
3436
|
+ if len(idstr) > 0 {
|
|
3437
|
+ err = XTReadDB().Model(&info).Where("cancel_stock_id in(?)", idstr).Preload("GoodInfo", "status = 1").Find(&info).Error
|
|
3438
|
+ } else {
|
|
3439
|
+ err = XTReadDB().Model(&info).Preload("GoodInfo", "status = 1").Find(&info).Error
|
|
3440
|
+ }
|
|
3441
|
+ return info, err
|
|
3442
|
+}
|
|
3443
|
+
|
|
3444
|
+func GetCancelOutTotalCount(startime int64, endtime int64, orgid int64) (info []*models.VmCancelStockInfo, err error) {
|
|
3445
|
+
|
|
3446
|
+ db := XTReadDB().Table("xt_cancel_stock_info as x").Where("x.status = 1")
|
|
3447
|
+
|
|
3448
|
+ if startime > 0 {
|
|
3449
|
+ db = db.Where("x.ctime >=?", startime)
|
|
3450
|
+ }
|
|
3451
|
+ if endtime > 0 {
|
|
3452
|
+ db = db.Where("x.ctime <= ?", endtime)
|
|
3453
|
+ }
|
|
3454
|
+ if orgid > 0 {
|
|
3455
|
+ db = db.Where("x.org_id = ?", orgid)
|
|
3456
|
+ }
|
|
3457
|
+ err = db.Select("x.good_id,sum(x.count) as count").Group("x.good_id").Scan(&info).Error
|
|
3458
|
+ return info, err
|
|
3459
|
+}
|