|
@@ -44,17 +44,36 @@ func AutoCreateStockJob() {
|
44
|
44
|
|
45
|
45
|
information, _ := FindAlLGoodInformation(item.UserOrgId)
|
46
|
46
|
for _, ite := range information {
|
47
|
|
- countList, _ := FindAllGoodInformationTotalCount(ite.ID)
|
48
|
|
- for _, it := range countList {
|
49
|
|
- if ite.ID == it.GoodId {
|
50
|
|
- formatInt := strconv.FormatInt(it.StockCount, 10)
|
51
|
|
- total, _ := strconv.ParseFloat(formatInt, 64)
|
52
|
|
- info := models.GoodInfo{
|
53
|
|
- Total: total,
|
54
|
|
- }
|
55
|
|
- UpdateStockTotal(it.GoodId, info)
|
56
|
|
- }
|
|
47
|
+ //countList, _ := FindAllGoodInformationTotalCount(ite.ID)
|
|
48
|
+ //查询入库数量
|
|
49
|
+ warehouseInfo, _ := FindAllGoodWarehouseInfoCount(ite.ID)
|
|
50
|
+
|
|
51
|
+ //查询自动出库数量
|
|
52
|
+ autoWarehouseOut, _ := FindAutoGoodWarehouseInfoCount(ite.ID)
|
|
53
|
+
|
|
54
|
+ //查询手动出库
|
|
55
|
+ warehouseOut, _ := FindGoodWarehouseOutCount(ite.ID)
|
|
56
|
+
|
|
57
|
+ var total int64
|
|
58
|
+
|
|
59
|
+ total = warehouseInfo.WarehousingCount - autoWarehouseOut.Count - warehouseOut.Count
|
|
60
|
+ formatInt := strconv.FormatInt(total, 10)
|
|
61
|
+ totalfloat, _ := strconv.ParseFloat(formatInt, 64)
|
|
62
|
+ info := models.GoodInfo{
|
|
63
|
+ Total: totalfloat,
|
57
|
64
|
}
|
|
65
|
+ UpdateStockTotal(ite.ID, info)
|
|
66
|
+
|
|
67
|
+ //for _, it := range countList {
|
|
68
|
+ // if ite.ID == it.GoodId {
|
|
69
|
+ // formatInt := strconv.FormatInt(it.StockCount, 10)
|
|
70
|
+ // total, _ := strconv.ParseFloat(formatInt, 64)
|
|
71
|
+ // info := models.GoodInfo{
|
|
72
|
+ // Total: total,
|
|
73
|
+ // }
|
|
74
|
+ // UpdateStockTotal(it.GoodId, info)
|
|
75
|
+ // }
|
|
76
|
+ //}
|
58
|
77
|
}
|
59
|
78
|
|
60
|
79
|
}
|
|
@@ -85,3 +104,36 @@ func UpdateStockTotal(id int64, lib models.GoodInfo) error {
|
85
|
104
|
err := XTWriteDB().Model(&lib).Where("id=? and status = 1", id).Updates(map[string]interface{}{"total": lib.Total}).Error
|
86
|
105
|
return err
|
87
|
106
|
}
|
|
107
|
+
|
|
108
|
+func FindAllGoodWarehouseInfoCount(good_id int64) (models.WarehousingInfo, error) {
|
|
109
|
+
|
|
110
|
+ info := models.WarehousingInfo{}
|
|
111
|
+ db := XTReadDB().Table("xt_warehouse_info as x").Where("x.status = 1")
|
|
112
|
+ if good_id > 0 {
|
|
113
|
+ db = db.Where("x.good_id = ? and x.warehousing_count <> 0", good_id)
|
|
114
|
+ }
|
|
115
|
+ err = db.Select("x.good_id,sum(x.warehousing_count) as warehousing_count").Find(&info).Error
|
|
116
|
+ return info, err
|
|
117
|
+}
|
|
118
|
+
|
|
119
|
+func FindAutoGoodWarehouseInfoCount(good_id int64) (models.AutomaticReduceDetail, error) {
|
|
120
|
+
|
|
121
|
+ detail := models.AutomaticReduceDetail{}
|
|
122
|
+ db := XTReadDB().Table("xt_automatic_reduce_detail as x").Where("x.status = 1")
|
|
123
|
+ if good_id > 0 {
|
|
124
|
+ db = db.Where("x.good_id = ? and x.count<> 0", good_id)
|
|
125
|
+ }
|
|
126
|
+ err := db.Select("x.good_id,sum(x.count) as count").Find(&detail).Error
|
|
127
|
+ return detail, err
|
|
128
|
+}
|
|
129
|
+
|
|
130
|
+func FindGoodWarehouseOutCount(good_id int64) (models.WarehouseOutInfo, error) {
|
|
131
|
+
|
|
132
|
+ out := models.WarehouseOutInfo{}
|
|
133
|
+ db := XTReadDB().Table("xt_warehouse_out_info as x").Where("x.status = 1")
|
|
134
|
+ if good_id > 0 {
|
|
135
|
+ db = db.Where("x.good_id = ? and x.is_sys = 0 and x.count<> 0", good_id)
|
|
136
|
+ }
|
|
137
|
+ err := db.Select("x.good_id,sum(x.count) as count").Find(&out).Error
|
|
138
|
+ return out, err
|
|
139
|
+}
|