|
@@ -2,9 +2,285 @@ package service
|
2
|
2
|
|
3
|
3
|
import (
|
4
|
4
|
"XT_New/models"
|
|
5
|
+ "github.com/jinzhu/gorm"
|
|
6
|
+ "strconv"
|
5
|
7
|
"time"
|
6
|
8
|
)
|
7
|
9
|
|
|
10
|
+//根据供应商编号获取首要联系人
|
|
11
|
+func FindName(code string) (fistname models.SpSupplierContacts, err error) {
|
|
12
|
+ err = XTReadDB().Model(&models.SpSupplierContacts{}).Where("supplier_code = ? and status = 1", code).First(&fistname).Error
|
|
13
|
+ return fistname, err
|
|
14
|
+}
|
|
15
|
+
|
|
16
|
+//供应商分页
|
|
17
|
+func GetSupplyList(ctype int64, page int64, limit int64, code string, sname string, cname string) (supplylist []*models.SpSupplierName, total int64, err error) {
|
|
18
|
+ db := XTReadDB().Model(&supplylist).Where("sgj_xt.xt_supplier_name.status = 1 ")
|
|
19
|
+
|
|
20
|
+ offset := (page - 1) * limit
|
|
21
|
+
|
|
22
|
+ if cname != "" {
|
|
23
|
+ cname = "%" + cname + "%" //联系人
|
|
24
|
+ db = db.Joins("join sgj_xt.xt_supplier_contacts on sgj_xt.xt_supplier_contacts.supplier_code = sgj_xt.xt_supplier_name.supplier_code")
|
|
25
|
+ db = db.Where("sgj_xt.xt_supplier_contacts.name like ? and sgj_xt.xt_supplier_contacts.status = 1 ", cname).Group("sgj_xt.xt_supplier_name.id")
|
|
26
|
+ }
|
|
27
|
+ if ctype > 0 {
|
|
28
|
+ db = db.Where("sgj_xt.xt_supplier_name.supplier_type = ?", ctype)
|
|
29
|
+ }
|
|
30
|
+ if code != "" {
|
|
31
|
+ code = "%" + code + "%" //供应商编码
|
|
32
|
+ db = db.Where("sgj_xt.xt_supplier_name.supplier_code = ?", code)
|
|
33
|
+ }
|
|
34
|
+ if sname != "" {
|
|
35
|
+ sname = "%" + sname + "%" //供应商名称
|
|
36
|
+ db = db.Where("sgj_xt.xt_supplier_name.supplier_name = ?", sname)
|
|
37
|
+ }
|
|
38
|
+ err = db.Count(&total).Offset(offset).Limit(limit).Find(&supplylist).Error
|
|
39
|
+ return supplylist, total, err
|
|
40
|
+}
|
|
41
|
+
|
|
42
|
+//修改供应商和联系人
|
|
43
|
+func UpdateSupplyAndContact(thisStockIn []interface{}, suid, orgId, supplierType, tcreater int64, supplierCode, supplierName, number, bank, bankAccount string, vatRate float64) error {
|
|
44
|
+ tx := XTWriteDB().Begin()
|
|
45
|
+ defer func() {
|
|
46
|
+ if err != nil {
|
|
47
|
+ tx.Rollback()
|
|
48
|
+ } else {
|
|
49
|
+ tx.Commit()
|
|
50
|
+ }
|
|
51
|
+ }()
|
|
52
|
+ for _, item := range thisStockIn {
|
|
53
|
+ items := item.(map[string]interface{})
|
|
54
|
+ //查询是否
|
|
55
|
+ id, _ := strconv.ParseInt(items["id"].(string), 10, 64)
|
|
56
|
+ name := items["name"].(string)
|
|
57
|
+ phone := items["phone"].(string)
|
|
58
|
+ address := items["address"].(string)
|
|
59
|
+ isfirst, _ := strconv.ParseInt(items["isfirst"].(string), 10, 64)
|
|
60
|
+ updatecontacts := models.SpSupplierContacts{
|
|
61
|
+ ID: id,
|
|
62
|
+ Name: name,
|
|
63
|
+ Phone: phone,
|
|
64
|
+ Address: address,
|
|
65
|
+ IsFirst: isfirst,
|
|
66
|
+ SupplierCode: supplierCode,
|
|
67
|
+ UserOrgId: orgId,
|
|
68
|
+ Status: 1,
|
|
69
|
+ Ctime: 0,
|
|
70
|
+ Mtime: time.Now().Unix(),
|
|
71
|
+ }
|
|
72
|
+ if id == 0 {
|
|
73
|
+ spcontacts := models.SpSupplierContacts{
|
|
74
|
+ Name: name,
|
|
75
|
+ Phone: phone,
|
|
76
|
+ Address: address,
|
|
77
|
+ IsFirst: isfirst,
|
|
78
|
+ SupplierCode: supplierCode,
|
|
79
|
+ UserOrgId: orgId,
|
|
80
|
+ Status: 1,
|
|
81
|
+ Ctime: time.Now().Unix(),
|
|
82
|
+ Mtime: 0,
|
|
83
|
+ }
|
|
84
|
+ err = SaveContacts(spcontacts, tx)
|
|
85
|
+ if err != nil {
|
|
86
|
+ return err
|
|
87
|
+ }
|
|
88
|
+ } else {
|
|
89
|
+ err = UpdateContact(updatecontacts, tx)
|
|
90
|
+ }
|
|
91
|
+ var tmpid int64
|
|
92
|
+ if isfirst == 1 {
|
|
93
|
+ if id == 0 {
|
|
94
|
+ var spconid []*models.SpSupplierContacts
|
|
95
|
+ spconid, err = SaveContactsId(tx)
|
|
96
|
+
|
|
97
|
+ if err != nil {
|
|
98
|
+ return err
|
|
99
|
+ }
|
|
100
|
+ tmpid = spconid[0].ID
|
|
101
|
+ } else {
|
|
102
|
+ tmpid = id
|
|
103
|
+ }
|
|
104
|
+ //更新供应商
|
|
105
|
+ upsupply := models.SpSupplierName{
|
|
106
|
+ ID: suid,
|
|
107
|
+ SupplierCode: supplierCode,
|
|
108
|
+ SupplierName: supplierName,
|
|
109
|
+ SupplierType: supplierType,
|
|
110
|
+ VatRate: vatRate,
|
|
111
|
+ Number: number,
|
|
112
|
+ Bank: bank,
|
|
113
|
+ BankAccount: bankAccount,
|
|
114
|
+ UserOrgId: orgId,
|
|
115
|
+ Status: 1,
|
|
116
|
+ ContactsId: tmpid,
|
|
117
|
+ Mtime: time.Now().Unix(),
|
|
118
|
+ Modify: tcreater,
|
|
119
|
+ }
|
|
120
|
+ err = UpdateSupplyName(upsupply, tx)
|
|
121
|
+ if err != nil {
|
|
122
|
+ return err
|
|
123
|
+ }
|
|
124
|
+ }
|
|
125
|
+
|
|
126
|
+ }
|
|
127
|
+ return err
|
|
128
|
+}
|
|
129
|
+
|
|
130
|
+//更新一条供应商的信息
|
|
131
|
+func UpdateSupplyName(upsupply models.SpSupplierName, tx *gorm.DB) error {
|
|
132
|
+ err := tx.Model(&models.SpSupplierName{}).Where("id = ? and status = 1", upsupply.ID).Updates(map[string]interface{}{"supplier_code": upsupply.SupplierCode, "supplier_name": upsupply.SupplierName, "supplier_type": upsupply.SupplierType, "vat_rate": upsupply.VatRate, "number": upsupply.Number, "bank": upsupply.Bank, "bank_account": upsupply.BankAccount, "user_org_id": upsupply.UserOrgId, "status": upsupply.Status, "contacts_id": upsupply.ContactsId, "mtime": upsupply.Mtime, "modify": upsupply.Modify}).Error
|
|
133
|
+ return err
|
|
134
|
+}
|
|
135
|
+
|
|
136
|
+//更新一条联系人的信息
|
|
137
|
+func UpdateContact(updatecontacts models.SpSupplierContacts, tx *gorm.DB) error {
|
|
138
|
+ err := tx.Model(&models.SpSupplierContacts{}).Where("id = ? and status = 1", updatecontacts.ID).Updates(map[string]interface{}{"name": updatecontacts.Name, "phone": updatecontacts.Phone, "address": updatecontacts.Address, "is_first": updatecontacts.IsFirst, "supplier_code": updatecontacts.SupplierCode, "user_org_id": updatecontacts.UserOrgId, "status": updatecontacts.Status, "mtime": updatecontacts.Mtime}).Error
|
|
139
|
+ return err
|
|
140
|
+}
|
|
141
|
+
|
|
142
|
+//查询供应商单条记录
|
|
143
|
+func GetSupplyOne(id int64) (supply models.SpSupplierName, err error) {
|
|
144
|
+ err = XTReadDB().Model(&models.SpSupplierName{}).Where("id = ? and status = 1", id).First(&supply).Error
|
|
145
|
+ return supply, err
|
|
146
|
+}
|
|
147
|
+
|
|
148
|
+//删除单条联系人记录
|
|
149
|
+func DelContactOne(id int64) error {
|
|
150
|
+ err := XTWriteDB().Model(&models.SpSupplierContacts{}).Where("id = ?", id).Update("status", 0).Error
|
|
151
|
+ return err
|
|
152
|
+}
|
|
153
|
+
|
|
154
|
+//获取单条供应商和涉及到的联系人记录
|
|
155
|
+func GetSupplyAndContactOne(id int64) (supply models.SpSupplierName, contact []*models.SpSupplierContacts, err error) {
|
|
156
|
+ err = XTReadDB().Model(&models.SpSupplierName{}).Where("id = ? and status = 1", id).First(&supply).Error
|
|
157
|
+ code := supply.SupplierCode
|
|
158
|
+ err = XTReadDB().Model(&models.SpSupplierContacts{}).Where("supplier_code = ? and status = 1", code).Find(&contact).Error
|
|
159
|
+ return supply, contact, err
|
|
160
|
+}
|
|
161
|
+
|
|
162
|
+//删除供应商及联系人
|
|
163
|
+func DelSupply(supply models.SpSupplierName) error {
|
|
164
|
+ err := XTWriteDB().Model(&supply).Update("status", 0).Error
|
|
165
|
+ return err
|
|
166
|
+}
|
|
167
|
+
|
|
168
|
+//保存供应商和联系人
|
|
169
|
+func SaveSupplyAndContact(thisStockIn []interface{}, orgId, supplierType, tcreater int64, supplierCode, supplierName, number, bank, bankAccount string, vatRate float64) error {
|
|
170
|
+ tx := XTWriteDB().Begin()
|
|
171
|
+ defer func() {
|
|
172
|
+ if err != nil {
|
|
173
|
+ tx.Rollback()
|
|
174
|
+ } else {
|
|
175
|
+ tx.Commit()
|
|
176
|
+ }
|
|
177
|
+ }()
|
|
178
|
+ for _, item := range thisStockIn {
|
|
179
|
+ items := item.(map[string]interface{})
|
|
180
|
+ name := items["name"].(string)
|
|
181
|
+ phone := items["phone"].(string)
|
|
182
|
+ address := items["address"].(string)
|
|
183
|
+ isfirst, _ := strconv.ParseInt(items["isfirst"].(string), 10, 64)
|
|
184
|
+
|
|
185
|
+ spcontacts := models.SpSupplierContacts{
|
|
186
|
+ Name: name,
|
|
187
|
+ Phone: phone,
|
|
188
|
+ Address: address,
|
|
189
|
+ IsFirst: isfirst,
|
|
190
|
+ SupplierCode: supplierCode,
|
|
191
|
+ UserOrgId: orgId,
|
|
192
|
+ Status: 1,
|
|
193
|
+ Ctime: time.Now().Unix(),
|
|
194
|
+ Mtime: 0,
|
|
195
|
+ }
|
|
196
|
+ err = SaveContacts(spcontacts, tx)
|
|
197
|
+ if isfirst == 1 {
|
|
198
|
+ var spconid []*models.SpSupplierContacts
|
|
199
|
+ spconid, err = SaveContactsId(tx)
|
|
200
|
+
|
|
201
|
+ if err != nil {
|
|
202
|
+ return err
|
|
203
|
+ }
|
|
204
|
+ tmpid := spconid[0].ID
|
|
205
|
+ //保存供应商
|
|
206
|
+ supply := models.SpSupplierName{
|
|
207
|
+ SupplierCode: supplierCode,
|
|
208
|
+ SupplierName: supplierName,
|
|
209
|
+ SupplierType: supplierType,
|
|
210
|
+ VatRate: vatRate,
|
|
211
|
+ Number: number,
|
|
212
|
+ Bank: bank,
|
|
213
|
+ BankAccount: bankAccount,
|
|
214
|
+ UserOrgId: orgId,
|
|
215
|
+ Status: 1,
|
|
216
|
+ ContactsId: tmpid,
|
|
217
|
+ Ctime: time.Now().Unix(),
|
|
218
|
+ Mtime: 0,
|
|
219
|
+ Creater: tcreater,
|
|
220
|
+ Modify: tcreater,
|
|
221
|
+ }
|
|
222
|
+ err = SaveSupply(supply, tx)
|
|
223
|
+ if err != nil {
|
|
224
|
+ return err
|
|
225
|
+ }
|
|
226
|
+
|
|
227
|
+ }
|
|
228
|
+ if err != nil {
|
|
229
|
+ return err
|
|
230
|
+ }
|
|
231
|
+ }
|
|
232
|
+ return err
|
|
233
|
+}
|
|
234
|
+
|
|
235
|
+//获取供应商编码
|
|
236
|
+func GetSuppliyCode() (spcode []*models.SpSupplierName, err error) {
|
|
237
|
+
|
|
238
|
+ err = XTReadDB().Model(&models.SpSupplierName{}).Select("supplier_code").Where("supplier_code like 'gys%' and status = 1 ").Order("supplier_code desc").First(&spcode).Error
|
|
239
|
+ return spcode, err
|
|
240
|
+}
|
|
241
|
+
|
|
242
|
+//查询供应商的名字是否有重复
|
|
243
|
+func FindSupplierName(supplierName string) (sbool bool, err error) {
|
|
244
|
+ var total int
|
|
245
|
+ err = XTReadDB().Model(&models.SpSupplierName{}).Where("supplier_name = ? and status = 1", supplierName).Count(&total).Error
|
|
246
|
+ if total != 0 {
|
|
247
|
+ sbool = true
|
|
248
|
+ } else {
|
|
249
|
+ sbool = false
|
|
250
|
+ }
|
|
251
|
+ return sbool, err
|
|
252
|
+}
|
|
253
|
+
|
|
254
|
+//查询供应商的编号是否有重复
|
|
255
|
+func FindSupplierCode(supplierCode string) (codebool bool, err error) {
|
|
256
|
+ var total int
|
|
257
|
+ err = XTReadDB().Model(&models.SpSupplierName{}).Where("supplier_name = ? and status = 1", supplierCode).Count(&total).Error
|
|
258
|
+ if total != 0 {
|
|
259
|
+ codebool = true
|
|
260
|
+ } else {
|
|
261
|
+ codebool = false
|
|
262
|
+ }
|
|
263
|
+ return codebool, err
|
|
264
|
+}
|
|
265
|
+
|
|
266
|
+//保存一条供应商数据
|
|
267
|
+func SaveSupply(supply models.SpSupplierName, tx *gorm.DB) error {
|
|
268
|
+ err := tx.Create(&supply).Error
|
|
269
|
+ return err
|
|
270
|
+}
|
|
271
|
+
|
|
272
|
+//获取联系人的id
|
|
273
|
+func SaveContactsId(tx *gorm.DB) (spconid []*models.SpSupplierContacts, err error) {
|
|
274
|
+ err = tx.Model(&models.SpSupplierContacts{}).Select("id").Where("and status = 1").Order("id desc").First(&spconid).Error
|
|
275
|
+ return
|
|
276
|
+}
|
|
277
|
+
|
|
278
|
+//保存一条联系人数据
|
|
279
|
+func SaveContacts(spcontacts models.SpSupplierContacts, tx *gorm.DB) error {
|
|
280
|
+ err := tx.Create(&spcontacts).Error
|
|
281
|
+ return err
|
|
282
|
+}
|
|
283
|
+
|
8
|
284
|
func GetSupplyDrugList(orgid int64) (drug []*models.SpBaseDrug, err error) {
|
9
|
285
|
|
10
|
286
|
db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1")
|
|
@@ -61,27 +337,27 @@ func CreateSupplyWarehousingOrder(order *models.SupplierWarehousingInfoOrder) er
|
61
|
337
|
|
62
|
338
|
func GetAllPurchaseOrderList(check_id int64, startime int64, endtime int64, keyword string, page int64, limit int64, orgid int64) (info []*models.VmSupplierWarehouseInfo, total int64, err error) {
|
63
|
339
|
|
64
|
|
- db := XTReadDB().Model(&info).Where("status = 1")
|
|
340
|
+ db := XTReadDB().Model(&info).Where("sgj_xt.xt_supplier_warehouse_info.status = 1")
|
65
|
341
|
likeKey := "%" + keyword + "%"
|
66
|
342
|
offset := (page - 1) * limit
|
67
|
343
|
if check_id > 0 {
|
68
|
|
- db = db.Where("xt_supplier_warehouse_info.is_check = ?", check_id)
|
|
344
|
+ db = db.Where("sgj_xt.xt_supplier_warehouse_info.is_check = ?", check_id)
|
69
|
345
|
}
|
70
|
346
|
if startime > 0 {
|
71
|
|
- db = db.Where("xt_supplier_warehouse_info.record_date >= ?", startime)
|
|
347
|
+ db = db.Where("sgj_xt.xt_supplier_warehouse_info.record_date >= ?", startime)
|
72
|
348
|
}
|
73
|
349
|
if endtime > 0 {
|
74
|
|
- db = db.Where("xt_supplier_warehouse_info.record_date<=?", endtime)
|
|
350
|
+ db = db.Where("sgj_xt.xt_supplier_warehouse_info.record_date<=?", endtime)
|
75
|
351
|
}
|
76
|
352
|
|
77
|
353
|
if len(keyword) > 0 {
|
78
|
|
- db.Joins("join xt_supplier_name on xt_supplier_name.id = xt_supplier_warehouse_info.supplier_id")
|
79
|
|
- db = db.Where("xt_supplier_warehouse_info.number like ? or xt_supplier_name.supplier_name like ? ", likeKey, likeKey).Group("xt_supplier_warehouse_info.id")
|
|
354
|
+ db = db.Joins("join sgj_xt.xt_supplier_name on sgj_xt.xt_supplier_name.id = sgj_xt.xt_supplier_warehouse_info.supplier_id")
|
|
355
|
+ db = db.Where("sgj_xt.xt_supplier_warehouse_info.number like ? or sgj_xt.xt_supplier_name.supplier_name like ? ", likeKey, likeKey).Group("sgj_xt.xt_supplier_warehouse_info.id")
|
80
|
356
|
}
|
81
|
357
|
if orgid > 0 {
|
82
|
|
- db = db.Where("xt_supplier_warehouse_info.user_org_id = ?", orgid)
|
|
358
|
+ db = db.Where("sgj_xt.xt_supplier_warehouse_info.user_org_id = ?", orgid)
|
83
|
359
|
}
|
84
|
|
- err = db.Count(&total).Offset(offset).Limit(limit).Preload("SupplierWarehousingInfoOrder", "status= 1 and user_org_id = ?", orgid).Find(&info).Error
|
|
360
|
+ err = db.Count(&total).Offset(offset).Limit(limit).Preload("SupplierWarehousingInfoOrder", "status= 1 and user_org_id = ?", orgid).Preload("SpSupplierWarehouseOut", "status = 1 and user_org_id =?", orgid).Find(&info).Error
|
85
|
361
|
return info, total, err
|
86
|
362
|
}
|
87
|
363
|
|
|
@@ -91,6 +367,12 @@ func GetSupplyWarehousingOrderInfo(id int64) (order []*models.SupplierWarehousin
|
91
|
367
|
return order, err
|
92
|
368
|
}
|
93
|
369
|
|
|
370
|
+func GetSupplyWarehousingOrderInfoTwo(id int64, ids []string) (order []*models.SupplierWarehousingInfoOrder, err error) {
|
|
371
|
+
|
|
372
|
+ err = XTReadDB().Where("warehousing_id = ? and status = 1 and project_id in(?)", id, ids).Find(&order).Error
|
|
373
|
+ return order, err
|
|
374
|
+}
|
|
375
|
+
|
94
|
376
|
func ModefySupplyWarehouseInfo(id int64, info models.SupplierWarehouseInfo) error {
|
95
|
377
|
|
96
|
378
|
err := XTWriteDB().Model(&models.SupplierWarehouseInfo{}).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"rate_of_concession": info.RateOfConcession, "discount_amount": info.DiscountAmount, "document_date": info.DocumentDate, "delivery_date": info.DeliveryDate, "supplier_id": info.SupplierId}).Error
|
|
@@ -99,7 +381,7 @@ func ModefySupplyWarehouseInfo(id int64, info models.SupplierWarehouseInfo) erro
|
99
|
381
|
|
100
|
382
|
func ModifySupplyWarehouseOrder(order *models.SupplierWarehousingInfoOrder) error {
|
101
|
383
|
|
102
|
|
- err := XTWriteDB().Model(&models.SupplierWarehousingInfoOrder{}).Where("id = ? and status = 1", order.ID).Updates(map[string]interface{}{}).Updates(map[string]interface{}{"is_source": order.IsSource, "count": order.Count, "price": order.Price, "amount": order.Amount, "remark": order.Remark, "project_id": order.ProjectId, "supply_license_number": order.SupplyLicenseNumber, "supply_type": order.SupplyType, "supply_specification_name": order.SupplySpecificationName, "supply_total": order.SupplyTotal, "supply_manufacturer": order.SupplyManufacturer, "name": order.Name, "supply_unit": order.SupplyUnit}).Error
|
|
384
|
+ err := XTWriteDB().Model(&models.SupplierWarehousingInfoOrder{}).Where("id = ? and status = 1", order.ID).Updates(map[string]interface{}{}).Updates(map[string]interface{}{"is_source": order.IsSource, "count": order.Count, "price": order.Price, "amount": order.Amount, "remark": order.Remark, "project_id": order.ProjectId, "supply_license_number": order.SupplyLicenseNumber, "supply_type": order.SupplyType, "supply_specification_name": order.SupplySpecificationName, "supply_total": order.SupplyTotal, "supply_manufacturer": order.SupplyManufacturer, "name": order.Name, "supply_unit": order.SupplyUnit, "manufacturer_id": order.ManufacturerId}).Error
|
103
|
385
|
return err
|
104
|
386
|
}
|
105
|
387
|
|
|
@@ -115,3 +397,124 @@ func GetPurchaseOrderDetail(id int64) (models.SupplierWarehouseInfo, error) {
|
115
|
397
|
err := XTReadDB().Model(&info).Where("id =? and status =1", id).Find(&info).Error
|
116
|
398
|
return info, err
|
117
|
399
|
}
|
|
400
|
+
|
|
401
|
+func FindAllSupplyWarehouseOutOrder(orgid int64) (total int64, err error) {
|
|
402
|
+ err = XTReadDB().Model(&models.SpSupplierWarehouseOut{}).Where("user_org_id = ? and status = 1", orgid).Count(&total).Error
|
|
403
|
+ return total, err
|
|
404
|
+}
|
|
405
|
+
|
|
406
|
+func FindSupplyWarehouseOutById(orgid int64) (models.SpSupplierWarehouseOut, error) {
|
|
407
|
+ out := models.SpSupplierWarehouseOut{}
|
|
408
|
+ err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Last(&out).Error
|
|
409
|
+ return out, err
|
|
410
|
+}
|
|
411
|
+
|
|
412
|
+func CreateSupplyWarehouseOut(out models.SpSupplierWarehouseOut) error {
|
|
413
|
+
|
|
414
|
+ err := XTWriteDB().Create(&out).Error
|
|
415
|
+ return err
|
|
416
|
+}
|
|
417
|
+
|
|
418
|
+func CreateSupplyWarehousOutOrder(order *models.SpSupplierWarehousingOutOrder) error {
|
|
419
|
+
|
|
420
|
+ err := XTWriteDB().Create(&order).Error
|
|
421
|
+ return err
|
|
422
|
+}
|
|
423
|
+
|
|
424
|
+func GetSupplyWarehouseOutById(id int64, user_org_id int64) (order []*models.SpSupplierWarehousingOutOrder, err error) {
|
|
425
|
+
|
|
426
|
+ err = XTReadDB().Where("warehouse_out_id = ? and status = 1 and user_org_id = ?", id, user_org_id).Find(&order).Error
|
|
427
|
+ return order, err
|
|
428
|
+}
|
|
429
|
+
|
|
430
|
+func GetAllGoodOderList(check_id int64, keyword string, page int64, limit int64, startime int64, endtime int64, orgid int64) (out []*models.VmSupplierWarehouseOut, total int64, err error) {
|
|
431
|
+ db := XTReadDB().Model(&out).Where("status = 1")
|
|
432
|
+ likeKey := "%" + keyword + "%"
|
|
433
|
+ offset := (page - 1) * limit
|
|
434
|
+ if check_id > 0 {
|
|
435
|
+ db = db.Where("xt_supplier_warehouse_out.is_check = ?", check_id)
|
|
436
|
+ }
|
|
437
|
+ if startime > 0 {
|
|
438
|
+ db = db.Where("xt_supplier_warehouse_out.record_date >= ?", startime)
|
|
439
|
+ }
|
|
440
|
+ if endtime > 0 {
|
|
441
|
+ db = db.Where("xt_supplier_warehouse_out.record_date<=?", endtime)
|
|
442
|
+ }
|
|
443
|
+
|
|
444
|
+ if len(keyword) > 0 {
|
|
445
|
+ db.Joins("join xt_supplier_name on xt_supplier_name.id = xt_supplier_warehouse_out.supplier_id")
|
|
446
|
+ db = db.Where("xt_supplier_warehouse_out.number like ? or xt_supplier_name.supplier_name like ? ", likeKey, likeKey).Group("xt_supplier_warehouse_out.id")
|
|
447
|
+ }
|
|
448
|
+ if orgid > 0 {
|
|
449
|
+ db = db.Where("xt_supplier_warehouse_out.user_org_id = ?", orgid)
|
|
450
|
+ }
|
|
451
|
+ err = db.Count(&total).Offset(offset).Limit(limit).Preload("SpSupplierWarehousingOutOrder", "status= 1 and user_org_id = ?", orgid).Find(&out).Error
|
|
452
|
+ return out, total, err
|
|
453
|
+}
|
|
454
|
+
|
|
455
|
+func GetGoodOrderDetail(id int64, orgid int64) (models.SpSupplierWarehouseOut, error) {
|
|
456
|
+ out := models.SpSupplierWarehouseOut{}
|
|
457
|
+ err := XTReadDB().Where("id = ? and user_org_id = ? and status = 1", id, orgid).Find(&out).Error
|
|
458
|
+ return out, err
|
|
459
|
+}
|
|
460
|
+
|
|
461
|
+func UpdateGoodWarehouseOut(id int64, out models.SpSupplierWarehouseOut) error {
|
|
462
|
+
|
|
463
|
+ err := XTWriteDB().Model(&out).Where("id=? and status = 1", id).Updates(map[string]interface{}{"arrearage": out.Arrearage, "payment": out.Payment, "rate_of_concession": out.RateOfConcession, "discount_amount": out.DiscountAmount, "document_date": out.DocumentDate}).Error
|
|
464
|
+ return err
|
|
465
|
+}
|
|
466
|
+
|
|
467
|
+func UpdateGoodWarehouseOutOrder(order *models.SpSupplierWarehousingOutOrder) error {
|
|
468
|
+
|
|
469
|
+ err := XTWriteDB().Model(&order).Where("id = ? and status = 1", order.ID).Updates(map[string]interface{}{"project_id": order.ProjectId, "is_source": order.IsSource, "count": order.Count, "price": order.Count, "amount": order.Amount, "remark": order.Amount, "supply_batch_number": order.SupplyBatchNumber, "supply_product_date": order.SupplyProductDate, "supply_expiry_date": order.SupplyExpiryDate, "supply_type": order.SupplyType, "supply_specification_name": order.SupplySpecificationName, "supply_total": order.SupplySpecificationName, "supply_manufacturer": order.SupplyManufacturer, "name": order.Name, "supply_unit": order.SupplyUnit, "manufacturer_id": order.ManufacturerId, "supply_license_number": order.SupplyLicenseNumber}).Error
|
|
470
|
+ return err
|
|
471
|
+}
|
|
472
|
+
|
|
473
|
+func DeletePurchOrder(id int64, orgid int64) error {
|
|
474
|
+
|
|
475
|
+ err := XTWriteDB().Model(&models.SupplierWarehouseInfo{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
|
|
476
|
+ err = XTWriteDB().Model(&models.SupplierWarehousingInfoOrder{}).Where("warehousing_id =? and user_org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
|
|
477
|
+ return err
|
|
478
|
+}
|
|
479
|
+
|
|
480
|
+func GetAllPurcaseOrderById(id int64, orgid int64) (order []*models.VSupplierWarehousingInfoOrder, err error) {
|
|
481
|
+
|
|
482
|
+ err = XTReadDB().Model(&order).Where("warehousing_id = ? and user_org_id = ? and status =1", id, orgid).Find(&order).Error
|
|
483
|
+ return order, err
|
|
484
|
+}
|
|
485
|
+
|
|
486
|
+func GetAllGoodOrderById(id int64, orgid int64) (order []*models.VSpSupplierWarehousingOutOrder, err error) {
|
|
487
|
+ db := XTReadDB().Table("xt_supplier_warehousing_out_order as o").Where("o.status = 1")
|
|
488
|
+ if id > 0 {
|
|
489
|
+ db = db.Where("o.warehousing_id = ?", id)
|
|
490
|
+ }
|
|
491
|
+ if orgid > 0 {
|
|
492
|
+ db = db.Where("o.user_org_id =?", orgid)
|
|
493
|
+ }
|
|
494
|
+ err = db.Select("o.id,o.order_number,o.project_id,o.count as count,o.supply_unit,o.is_source").Find(&order).Error
|
|
495
|
+ return order, err
|
|
496
|
+}
|
|
497
|
+
|
|
498
|
+func GetAllGoodOrderByIdTwo(id int64, orgid int64) (order []*models.SpSupplierWarehousingOutOrder, err error) {
|
|
499
|
+
|
|
500
|
+ err = XTReadDB().Where("warehousing_id = ? and user_org_id = ? and status = 1", id, orgid).Find(&order).Error
|
|
501
|
+ return order, err
|
|
502
|
+}
|
|
503
|
+
|
|
504
|
+func GetGoodOrderList(id int64, orgid int64) (info []*models.SpSupplierWarehouseOut, err error) {
|
|
505
|
+
|
|
506
|
+ err = XTReadDB().Where("warehousing_id = ? and status = 1 and user_org_id = ?", id, orgid).Find(&info).Error
|
|
507
|
+ return info, err
|
|
508
|
+}
|
|
509
|
+
|
|
510
|
+func GetReturnOrder(id int64, orgid int64) error {
|
|
511
|
+
|
|
512
|
+ err := XTWriteDB().Model(&models.SupplierWarehouseInfo{}).Where("id = ? and status = 1 and user_org_id = ?", id, orgid).Updates(map[string]interface{}{"is_check": 2, "mtime": time.Now().Unix(), "check_time": 0, "checker": 0}).Error
|
|
513
|
+ return err
|
|
514
|
+}
|
|
515
|
+
|
|
516
|
+func CheckGoodOrder(id int64, orgid int64, out models.SpSupplierWarehouseOut) error {
|
|
517
|
+
|
|
518
|
+ err := XTWriteDB().Model(&models.SpSupplierWarehouseOut{}).Where("id = ? and user_org_id =? and status = 1", id, orgid).Updates(map[string]interface{}{"is_check": out.IsCheck, "checker": out.Checker, "check_time": out.CheckTime, "mtime": time.Now().Unix()}).Error
|
|
519
|
+ return err
|
|
520
|
+}
|