|
@@ -3,18 +3,19 @@ package service
|
3
|
3
|
import (
|
4
|
4
|
"XT_New/models"
|
5
|
5
|
"github.com/jinzhu/gorm"
|
|
6
|
+ "strings"
|
6
|
7
|
"time"
|
7
|
8
|
)
|
8
|
9
|
|
9
|
10
|
//根据供应商编号获取首要联系人
|
10
|
|
-func FindName(code string) (fistname models.SpSupplierContacts, err error) {
|
11
|
|
- err = XTReadDB().Model(&models.SpSupplierContacts{}).Where("supplier_code = ? and status = 1", code).First(&fistname).Error
|
|
11
|
+func FindName(code string, orgid int64) (fistname models.SpSupplierContacts, err error) {
|
|
12
|
+ err = XTReadDB().Model(&models.SpSupplierContacts{}).Where("supplier_code = ? and status = 1 and is_first = 1 and user_org_id = ?", code, orgid).First(&fistname).Error
|
12
|
13
|
return fistname, err
|
13
|
14
|
}
|
14
|
15
|
|
15
|
16
|
//供应商分页
|
16
|
|
-func GetSupplyList(ctype int64, page int64, limit int64, keyword string) (supplylist []*models.SpSupplierName, total int64, err error) {
|
17
|
|
- db := XTReadDB().Model(&supplylist).Where("xt_supplier_name.status = 1 ")
|
|
17
|
+func GetSupplyList(ctype int64, page int64, limit int64, keyword string, orgid int64) (supplylist []*models.SpSupplierName, total int64, err error) {
|
|
18
|
+ db := XTReadDB().Model(&supplylist).Where("xt_supplier_name.status = 1 and xt_supplier_name.user_org_id = ?", orgid)
|
18
|
19
|
|
19
|
20
|
offset := (page - 1) * limit
|
20
|
21
|
|
|
@@ -42,7 +43,7 @@ func UpdateSupplyAndContact(thisStockIn []interface{}, suid, orgId, supplierType
|
42
|
43
|
}()
|
43
|
44
|
for _, item := range thisStockIn {
|
44
|
45
|
items := item.(map[string]interface{})
|
45
|
|
- //查询是否
|
|
46
|
+ //判断联系人是否为新加的
|
46
|
47
|
if items["id"] == "" || items["id"] == 0 {
|
47
|
48
|
var tmp float64 = 0
|
48
|
49
|
items["id"] = tmp
|
|
@@ -75,7 +76,7 @@ func UpdateSupplyAndContact(thisStockIn []interface{}, suid, orgId, supplierType
|
75
|
76
|
Ctime: 0,
|
76
|
77
|
Mtime: time.Now().Unix(),
|
77
|
78
|
}
|
78
|
|
- if id == 0 {
|
|
79
|
+ if id == 0 { //表示这是新加的
|
79
|
80
|
spcontacts := models.SpSupplierContacts{
|
80
|
81
|
Name: name,
|
81
|
82
|
Phone: phone,
|
|
@@ -86,7 +87,7 @@ func UpdateSupplyAndContact(thisStockIn []interface{}, suid, orgId, supplierType
|
86
|
87
|
Status: 1,
|
87
|
88
|
Ctime: time.Now().Unix(),
|
88
|
89
|
Mtime: 0,
|
89
|
|
- }
|
|
90
|
+ } //保存一条联系人的数据
|
90
|
91
|
err = SaveContacts(spcontacts, tx)
|
91
|
92
|
if err != nil {
|
92
|
93
|
return err
|
|
@@ -96,9 +97,9 @@ func UpdateSupplyAndContact(thisStockIn []interface{}, suid, orgId, supplierType
|
96
|
97
|
}
|
97
|
98
|
var tmpid int64
|
98
|
99
|
if isfirst == 1 {
|
99
|
|
- if id == 0 {
|
|
100
|
+ if id == 0 { //新加的首要联系人
|
100
|
101
|
var spconid []*models.SpSupplierContacts
|
101
|
|
- spconid, err = SaveContactsId(tx)
|
|
102
|
+ spconid, err = SaveContactsId(tx, orgId)
|
102
|
103
|
if err != nil {
|
103
|
104
|
return err
|
104
|
105
|
}
|
|
@@ -122,7 +123,7 @@ func UpdateSupplyAndContact(thisStockIn []interface{}, suid, orgId, supplierType
|
122
|
123
|
Mtime: time.Now().Unix(),
|
123
|
124
|
Modify: tcreater,
|
124
|
125
|
}
|
125
|
|
- err = UpdateSupplyName(upsupply, tx)
|
|
126
|
+ err = UpdateSupplyNameTX(upsupply, tx)
|
126
|
127
|
if err != nil {
|
127
|
128
|
return err
|
128
|
129
|
}
|
|
@@ -132,12 +133,18 @@ func UpdateSupplyAndContact(thisStockIn []interface{}, suid, orgId, supplierType
|
132
|
133
|
return err
|
133
|
134
|
}
|
134
|
135
|
|
135
|
|
-//更新一条供应商的信息
|
136
|
|
-func UpdateSupplyName(upsupply models.SpSupplierName, tx *gorm.DB) error {
|
|
136
|
+//更新一条供应商的信息,添加了事务的
|
|
137
|
+func UpdateSupplyNameTX(upsupply models.SpSupplierName, tx *gorm.DB) error {
|
137
|
138
|
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
|
138
|
139
|
return err
|
139
|
140
|
}
|
140
|
141
|
|
|
142
|
+//更新一条供应商的信息,没有添加事务
|
|
143
|
+func UpdateSupplyName(upsupply models.SpSupplierName) error {
|
|
144
|
+ err := XTWriteDB().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
|
|
145
|
+ return err
|
|
146
|
+}
|
|
147
|
+
|
141
|
148
|
//更新一条联系人的信息
|
142
|
149
|
func UpdateContact(updatecontacts models.SpSupplierContacts, tx *gorm.DB) error {
|
143
|
150
|
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
|
|
@@ -157,16 +164,37 @@ func DelContactOne(id int64) error {
|
157
|
164
|
}
|
158
|
165
|
|
159
|
166
|
//获取单条供应商和涉及到的联系人记录
|
160
|
|
-func GetSupplyAndContactOne(id int64) (supply models.SpSupplierName, contact []*models.SpSupplierContacts, err error) {
|
161
|
|
- err = XTReadDB().Model(&models.SpSupplierName{}).Where("id = ? and status = 1", id).First(&supply).Error
|
|
167
|
+func GetSupplyAndContactOne(id, orgId int64) (supply models.SpSupplierName, contact []*models.SpSupplierContacts, err error) {
|
|
168
|
+ err = XTReadDB().Model(&models.SpSupplierName{}).Where("id = ? and status = 1 and user_org_id = ?", id, orgId).First(&supply).Error
|
162
|
169
|
code := supply.SupplierCode
|
163
|
|
- err = XTReadDB().Model(&models.SpSupplierContacts{}).Where("supplier_code = ? and status = 1", code).Find(&contact).Error
|
|
170
|
+ err = XTReadDB().Model(&models.SpSupplierContacts{}).Where("supplier_code = ? and status = 1 and user_org_id = ?", code, orgId).Find(&contact).Error
|
164
|
171
|
return supply, contact, err
|
165
|
172
|
}
|
166
|
173
|
|
167
|
174
|
//删除供应商及联系人
|
168
|
|
-func DelSupply(supply models.SpSupplierName) error {
|
169
|
|
- err := XTWriteDB().Model(&supply).Update("status", 0).Error
|
|
175
|
+func DelSupply(supply models.SpSupplierName, orgId int64) error {
|
|
176
|
+ tx := XTWriteDB().Begin()
|
|
177
|
+ defer func() {
|
|
178
|
+ if err != nil {
|
|
179
|
+ tx.Rollback()
|
|
180
|
+ } else {
|
|
181
|
+ tx.Commit()
|
|
182
|
+ }
|
|
183
|
+ }()
|
|
184
|
+ //删除供应商
|
|
185
|
+ err := tx.Model(&supply).Update("status", 0).Error
|
|
186
|
+ if err != nil {
|
|
187
|
+ return err
|
|
188
|
+ }
|
|
189
|
+ var spcode models.SpSupplierName
|
|
190
|
+ //获取供应商编号
|
|
191
|
+ err = tx.Model(&models.SpSupplierName{}).Select("supplier_code").Where("user_org_id = ? and id = ?", orgId, supply.ID).First(&spcode).Error
|
|
192
|
+ if err != nil {
|
|
193
|
+ return err
|
|
194
|
+ }
|
|
195
|
+ //删除联系人
|
|
196
|
+ err = tx.Model(&models.SpSupplierContacts{}).Where("supplier_code = ? and user_org_id = ?", spcode.SupplierCode, orgId).Update("status", 0).Error
|
|
197
|
+
|
170
|
198
|
return err
|
171
|
199
|
}
|
172
|
200
|
|
|
@@ -211,7 +239,7 @@ func SaveSupplyAndContact(thisStockIn []interface{}, orgId, supplierType, tcreat
|
211
|
239
|
err = SaveContacts(spcontacts, tx)
|
212
|
240
|
if isfirst == 1 {
|
213
|
241
|
var spconid []*models.SpSupplierContacts
|
214
|
|
- spconid, err = SaveContactsId(tx)
|
|
242
|
+ spconid, err = SaveContactsId(tx, orgId)
|
215
|
243
|
if err != nil {
|
216
|
244
|
return err
|
217
|
245
|
}
|
|
@@ -233,7 +261,7 @@ func SaveSupplyAndContact(thisStockIn []interface{}, orgId, supplierType, tcreat
|
233
|
261
|
Creater: tcreater,
|
234
|
262
|
Modify: tcreater,
|
235
|
263
|
}
|
236
|
|
- err = SaveSupply(supply, tx)
|
|
264
|
+ err = SaveSupplyTx(supply, tx)
|
237
|
265
|
if err != nil {
|
238
|
266
|
return err
|
239
|
267
|
}
|
|
@@ -246,14 +274,13 @@ func SaveSupplyAndContact(thisStockIn []interface{}, orgId, supplierType, tcreat
|
246
|
274
|
}
|
247
|
275
|
|
248
|
276
|
//获取供应商编码
|
249
|
|
-func GetSuppliyCode() (spcode []*models.SpSupplierName, err error) {
|
250
|
|
-
|
251
|
|
- err = XTReadDB().Model(&models.SpSupplierName{}).Select("supplier_code").Where("supplier_code like 'gys%' and status = 1 ").Order("supplier_code desc").First(&spcode).Error
|
|
277
|
+func GetSuppliyCode(orgId int64) (spcode []*models.SpSupplierName, err error) {
|
|
278
|
+ err = XTReadDB().Model(&models.SpSupplierName{}).Select("supplier_code").Where("supplier_code like 'gys%' and status = 1 and user_org_id = ? ", orgId).Order("supplier_code desc").First(&spcode).Error
|
252
|
279
|
return spcode, err
|
253
|
280
|
}
|
254
|
281
|
|
255
|
282
|
//查询供应商的名字是否有重复
|
256
|
|
-func FindSupplierName(supplierName string) (sbool bool, err error) {
|
|
283
|
+func FindSupplierName(supplierName string, orgId int64) (sbool bool, err error) {
|
257
|
284
|
var total int
|
258
|
285
|
err = XTReadDB().Model(&models.SpSupplierName{}).Where("supplier_name = ? and status = 1", supplierName).Count(&total).Error
|
259
|
286
|
if total != 0 {
|
|
@@ -264,11 +291,23 @@ func FindSupplierName(supplierName string) (sbool bool, err error) {
|
264
|
291
|
return sbool, err
|
265
|
292
|
}
|
266
|
293
|
|
267
|
|
-//查询供应商的编号是否有重复
|
268
|
|
-func FindSupplierCode(supplierCode string) (codebool bool, err error) {
|
|
294
|
+//查询供应商的编号是否有重复(用于修改)
|
|
295
|
+func FindSupplierCode(supplierCode string, supplierid, orgid int64) (codebool bool, err error) {
|
269
|
296
|
var total int
|
270
|
|
- err = XTReadDB().Model(&models.SpSupplierName{}).Where("supplier_name = ? and status = 1", supplierCode).Count(&total).Error
|
271
|
|
- if total != 0 {
|
|
297
|
+ err = XTReadDB().Model(&models.SpSupplierName{}).Where("supplier_code = ? and id != ? and user_org_id = ? and status = 1", supplierCode, supplierid, orgid).Count(&total).Error
|
|
298
|
+ if total > 0 {
|
|
299
|
+ codebool = true
|
|
300
|
+ } else {
|
|
301
|
+ codebool = false
|
|
302
|
+ }
|
|
303
|
+ return codebool, err
|
|
304
|
+}
|
|
305
|
+
|
|
306
|
+//查询供应商的编号是否有重复(用于新增)
|
|
307
|
+func FindSupplierCodes(supplierCode string, orgid int64) (codebool bool, err error) {
|
|
308
|
+ var total int
|
|
309
|
+ err = XTReadDB().Model(&models.SpSupplierName{}).Where("supplier_code = ? and status = 1 and user_org_id = ?", supplierCode, orgid).Count(&total).Error
|
|
310
|
+ if total > 0 {
|
272
|
311
|
codebool = true
|
273
|
312
|
} else {
|
274
|
313
|
codebool = false
|
|
@@ -276,15 +315,21 @@ func FindSupplierCode(supplierCode string) (codebool bool, err error) {
|
276
|
315
|
return codebool, err
|
277
|
316
|
}
|
278
|
317
|
|
279
|
|
-//保存一条供应商数据
|
280
|
|
-func SaveSupply(supply models.SpSupplierName, tx *gorm.DB) error {
|
|
318
|
+//保存一条供应商数据加事务的
|
|
319
|
+func SaveSupplyTx(supply models.SpSupplierName, tx *gorm.DB) error {
|
281
|
320
|
err := tx.Create(&supply).Error
|
282
|
321
|
return err
|
283
|
322
|
}
|
284
|
323
|
|
|
324
|
+//保存一条供应商数据没有事务的
|
|
325
|
+func SaveSupply(supply models.SpSupplierName) error {
|
|
326
|
+ err := XTWriteDB().Create(&supply).Error
|
|
327
|
+ return err
|
|
328
|
+}
|
|
329
|
+
|
285
|
330
|
//获取联系人的id
|
286
|
|
-func SaveContactsId(tx *gorm.DB) (spconid []*models.SpSupplierContacts, err error) {
|
287
|
|
- err = tx.Model(&models.SpSupplierContacts{}).Select("id").Where("status = 1").Order("id desc").First(&spconid).Error
|
|
331
|
+func SaveContactsId(tx *gorm.DB, orgid int64) (spconid []*models.SpSupplierContacts, err error) {
|
|
332
|
+ err = tx.Model(&models.SpSupplierContacts{}).Select("id").Where("status = 1 and user_org_id = ?", orgid).Order("id desc").First(&spconid).Error
|
288
|
333
|
return
|
289
|
334
|
}
|
290
|
335
|
|
|
@@ -296,7 +341,7 @@ func SaveContacts(spcontacts models.SpSupplierContacts, tx *gorm.DB) error {
|
296
|
341
|
|
297
|
342
|
func GetSupplyDrugList(orgid int64) (drug []*models.SpBaseDrug, err error) {
|
298
|
343
|
|
299
|
|
- db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1")
|
|
344
|
+ db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1 AND find_in_set('停用',drug_status) = 0")
|
300
|
345
|
|
301
|
346
|
if orgid > 0 {
|
302
|
347
|
db = db.Where("x.org_id = ?", orgid)
|
|
@@ -308,7 +353,7 @@ func GetSupplyDrugList(orgid int64) (drug []*models.SpBaseDrug, err error) {
|
308
|
353
|
|
309
|
354
|
func GetSupplyGoodList(orgid int64) (good []*models.SpGoodInformation, err error) {
|
310
|
355
|
|
311
|
|
- db := XTReadDB().Table("xt_good_information as x").Where("x.status = 1")
|
|
356
|
+ db := XTReadDB().Table("xt_good_information as x").Where("x.status = 1 AND find_in_set('停用',good_status) = 0")
|
312
|
357
|
|
313
|
358
|
if orgid > 0 {
|
314
|
359
|
db = db.Where("x.org_id = ?", orgid)
|
|
@@ -370,7 +415,7 @@ func GetAllPurchaseOrderList(check_id int64, startime int64, endtime int64, keyw
|
370
|
415
|
if orgid > 0 {
|
371
|
416
|
db = db.Where("sgj_xt.xt_supplier_warehouse_info.user_org_id = ?", orgid)
|
372
|
417
|
}
|
373
|
|
- 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
|
|
418
|
+ 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).Order("ctime desc").Find(&info).Error
|
374
|
419
|
return info, total, err
|
375
|
420
|
}
|
376
|
421
|
|
|
@@ -467,7 +512,7 @@ func GetAllGoodOderList(check_id int64, keyword string, page int64, limit int64,
|
467
|
512
|
if orgid > 0 {
|
468
|
513
|
db = db.Where("sgj_xt.xt_supplier_warehouse_out.user_org_id = ?", orgid)
|
469
|
514
|
}
|
470
|
|
- err = db.Count(&total).Offset(offset).Limit(limit).Preload("SpSupplierWarehousingOutOrder", "status= 1 and user_org_id = ?", orgid).Preload("SpSupplierWarehousingCancelOrder", "status= 1 and user_org_id = ?", orgid).Find(&out).Error
|
|
515
|
+ err = db.Count(&total).Offset(offset).Limit(limit).Preload("SpSupplierWarehousingOutOrder", "status= 1 and user_org_id = ?", orgid).Preload("SpSupplierWarehousingCancelOrder", "status= 1 and user_org_id = ?", orgid).Order("ctime desc").Find(&out).Error
|
471
|
516
|
return out, total, err
|
472
|
517
|
}
|
473
|
518
|
|
|
@@ -628,7 +673,7 @@ func GetAllGoodReturnOrderList(checkid int64, keyword string, page int64, limit
|
628
|
673
|
db = db.Where("sgj_xt.xt_supplier_warehouse_cancel.is_check = ?", checkid)
|
629
|
674
|
}
|
630
|
675
|
if len(keyword) > 0 {
|
631
|
|
- db = db.Joins("join sgj_xt.xt_supplier_name on sgj_xt.xt_supplier_name.id = sgj_xt.xt_supplier_warehouse_out.supplier_id")
|
|
676
|
+ db = db.Joins("join sgj_xt.xt_supplier_name on sgj_xt.xt_supplier_name.id = sgj_xt.xt_supplier_warehouse_cancel.supplier_id")
|
632
|
677
|
db = db.Where("sgj_xt.xt_supplier_warehouse_cancel.number like ? or sgj_xt.xt_supplier_name.supplier_name like ? ", likeKey, likeKey).Group("xt_supplier_warehouse_cancel.id")
|
633
|
678
|
}
|
634
|
679
|
if startime > 0 {
|
|
@@ -641,7 +686,7 @@ func GetAllGoodReturnOrderList(checkid int64, keyword string, page int64, limit
|
641
|
686
|
if orgid > 0 {
|
642
|
687
|
db = db.Where("sgj_xt.xt_supplier_warehouse_cancel.user_org_id = ?", orgid)
|
643
|
688
|
}
|
644
|
|
- err = db.Count(&total).Offset(offset).Limit(limit).Preload("SpSupplierWarehousingCancelOrder", "status= 1 and user_org_id = ?", orgid).Find(&order).Error
|
|
689
|
+ err = db.Count(&total).Offset(offset).Limit(limit).Preload("SpSupplierWarehousingCancelOrder", "status= 1 and user_org_id = ?", orgid).Order("ctime desc").Find(&order).Error
|
645
|
690
|
return order, total, err
|
646
|
691
|
}
|
647
|
692
|
|
|
@@ -673,7 +718,7 @@ func GetGoodReturnOrderDetail(id int64, orgid int64) (order []*models.SpSupplier
|
673
|
718
|
|
674
|
719
|
func UpdateWarehouseCancelOrder(order *models.SpSupplierWarehousingCancelOrder) error {
|
675
|
720
|
|
676
|
|
- err = XTWriteDB().Where("id = ? and status = 1", order.ID).Updates(map[string]interface{}{"manufacturer_id": order.ManufacturerId, "order_number": order.OrderNumber, "project_id": order.ProjectId, "is_source": order.IsSource, "count": order.Count, "price": order.Price, "remark": order.Remark, "rate_of_concession": order.RateOfConcession, "discount_amount": order.DiscountAmount, "type": order.Type, "supply_specification_name": order.SupplySpecificationName, "supply_type": order.SupplyType, "supply_total": order.SupplyTotal, "supply_manufacturer": order.SupplyManufacturer, "name": order.Name, "supply_unit": order.SupplyUnit, "supply_license_number": order.SupplyLicenseNumber}).Error
|
|
721
|
+ err = XTWriteDB().Model(&order).Where("id = ? and status = 1", order.ID).Updates(map[string]interface{}{"manufacturer_id": order.ManufacturerId, "order_number": order.OrderNumber, "project_id": order.ProjectId, "is_source": order.IsSource, "count": order.Count, "price": order.Price, "remark": order.Remark, "rate_of_concession": order.RateOfConcession, "discount_amount": order.DiscountAmount, "type": order.Type, "supply_specification_name": order.SupplySpecificationName, "supply_type": order.SupplyType, "supply_total": order.SupplyTotal, "supply_manufacturer": order.SupplyManufacturer, "name": order.Name, "supply_unit": order.SupplyUnit, "supply_license_number": order.SupplyLicenseNumber}).Error
|
677
|
722
|
return err
|
678
|
723
|
}
|
679
|
724
|
|
|
@@ -779,3 +824,172 @@ func GetGoodCanceListById(id int64, orgid int64) (cancel []*models.VmSpSupplierW
|
779
|
824
|
err = XTReadDB().Where("warehouse_out_id = ? and user_org_id = ? and status = 1", id, orgid).Find(&cancel).Error
|
780
|
825
|
return cancel, err
|
781
|
826
|
}
|
|
827
|
+
|
|
828
|
+func CreateDrugFlowSix(drugflow []*models.DrugFlow) (err error) {
|
|
829
|
+ if len(drugflow) > 0 {
|
|
830
|
+ utx := writeDb.Begin()
|
|
831
|
+ if len(drugflow) > 0 {
|
|
832
|
+ thisSQL := "INSERT INTO xt_drug_flow (warehousing_id, drug_id, number,batch_number,count,user_org_id,patient_id,system_time,consumable_type,is_sys,warehousing_order,warehouse_out_id,warehouse_out_order_number,is_edit,cancel_stock_id,cancel_order_number,manufacturer,dealer,creator,update_creator,status,ctime,mtime,price,warehousing_detail_id,warehouse_out_detail_id,cancel_out_detail_id,expire_date,product_date,max_unit,min_unit,supply_warehouse_id,supply_warehouse_detail_info) VALUES "
|
|
833
|
+ insertParams := make([]string, 0)
|
|
834
|
+ insertData := make([]interface{}, 0)
|
|
835
|
+ for _, info := range drugflow {
|
|
836
|
+
|
|
837
|
+ insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
|
|
838
|
+ insertData = append(insertData, info.WarehousingId)
|
|
839
|
+ insertData = append(insertData, info.DrugId)
|
|
840
|
+ insertData = append(insertData, info.Number)
|
|
841
|
+ insertData = append(insertData, info.BatchNumber)
|
|
842
|
+ insertData = append(insertData, info.Count)
|
|
843
|
+ insertData = append(insertData, info.UserOrgId)
|
|
844
|
+ insertData = append(insertData, info.PatientId)
|
|
845
|
+ insertData = append(insertData, info.SystemTime)
|
|
846
|
+ insertData = append(insertData, info.ConsumableType)
|
|
847
|
+ insertData = append(insertData, info.IsSys)
|
|
848
|
+ insertData = append(insertData, info.WarehousingOrder)
|
|
849
|
+ insertData = append(insertData, info.WarehouseOutId)
|
|
850
|
+ insertData = append(insertData, info.WarehouseOutOrderNumber)
|
|
851
|
+
|
|
852
|
+ insertData = append(insertData, info.IsEdit)
|
|
853
|
+ insertData = append(insertData, info.CancelStockId)
|
|
854
|
+ insertData = append(insertData, info.CancelOrderNumber)
|
|
855
|
+ insertData = append(insertData, info.Manufacturer)
|
|
856
|
+ insertData = append(insertData, info.Dealer)
|
|
857
|
+ insertData = append(insertData, info.Creator)
|
|
858
|
+ insertData = append(insertData, info.UpdateCreator)
|
|
859
|
+ insertData = append(insertData, info.Status)
|
|
860
|
+ insertData = append(insertData, info.Ctime)
|
|
861
|
+ insertData = append(insertData, info.Mtime)
|
|
862
|
+ insertData = append(insertData, info.Price)
|
|
863
|
+ insertData = append(insertData, info.WarehousingDetailId)
|
|
864
|
+ insertData = append(insertData, info.WarehouseOutDetailId)
|
|
865
|
+ insertData = append(insertData, info.CancelOutDetailId)
|
|
866
|
+ insertData = append(insertData, info.ExpireDate)
|
|
867
|
+ insertData = append(insertData, info.ProductDate)
|
|
868
|
+ insertData = append(insertData, info.MaxUnit)
|
|
869
|
+ insertData = append(insertData, info.MinUnit)
|
|
870
|
+ insertData = append(insertData, info.SupplyWarehouseId)
|
|
871
|
+ insertData = append(insertData, info.SupplyWarehouseDetailInfo)
|
|
872
|
+ }
|
|
873
|
+ thisSQL += strings.Join(insertParams, ", ")
|
|
874
|
+ err = utx.Exec(thisSQL, insertData...).Error
|
|
875
|
+ if err != nil {
|
|
876
|
+ utx.Rollback()
|
|
877
|
+ return
|
|
878
|
+ }
|
|
879
|
+ }
|
|
880
|
+ utx.Commit()
|
|
881
|
+ }
|
|
882
|
+ return
|
|
883
|
+}
|
|
884
|
+
|
|
885
|
+func CheckReturnOrder(id int64, orgid int64, cancel models.SpSupplierWarehouseCancel) error {
|
|
886
|
+
|
|
887
|
+ err := XTWriteDB().Model(&cancel).Where("id = ? and user_org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"is_check": cancel.IsCheck, "checker": cancel.Checker, "check_time": cancel.CheckTime}).Error
|
|
888
|
+ return err
|
|
889
|
+}
|
|
890
|
+
|
|
891
|
+func GetSupplyCancelOrderDetail(id int64, orgid int64) (cancel []*models.SpSupplierWarehousingCancelOrder, err error) {
|
|
892
|
+
|
|
893
|
+ err = XTReadDB().Where("warehouse_cancel_id = ? and user_org_id = ? and status = 1", id, orgid).Find(&cancel).Error
|
|
894
|
+ return cancel, err
|
|
895
|
+}
|
|
896
|
+
|
|
897
|
+func DeletePurchaseOrder(id int64) error {
|
|
898
|
+
|
|
899
|
+ err := XTWriteDB().Model(&models.SupplierWarehousingInfoOrder{}).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
|
|
900
|
+ return err
|
|
901
|
+}
|
|
902
|
+
|
|
903
|
+func DeleteGoodOrderById(id int64) error {
|
|
904
|
+
|
|
905
|
+ err := XTWriteDB().Model(&models.SpSupplierWarehousingOutOrder{}).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
|
|
906
|
+ return err
|
|
907
|
+}
|
|
908
|
+
|
|
909
|
+func GetlastWarehouseOutById(user_org_id int64, record_date int64) (models.WarehouseOut, error) {
|
|
910
|
+
|
|
911
|
+ out := models.WarehouseOut{}
|
|
912
|
+ err := XTReadDB().Where("org_id = ? and warehouse_out_time = ? and status = 1", user_org_id, record_date).Find(&out).Error
|
|
913
|
+ return out, err
|
|
914
|
+}
|
|
915
|
+
|
|
916
|
+func GetDrugWarehouseOutById(orgid int64, record_date int64) (*models.DrugWarehouseOut, error) {
|
|
917
|
+
|
|
918
|
+ out := models.DrugWarehouseOut{}
|
|
919
|
+ var err error
|
|
920
|
+ err = XTReadDB().Where("org_id = ? and warehouse_out_time = ?", orgid, record_date).Find(&out).Error
|
|
921
|
+ if err == gorm.ErrRecordNotFound {
|
|
922
|
+ return nil, err
|
|
923
|
+ }
|
|
924
|
+ if err != nil {
|
|
925
|
+ return nil, err
|
|
926
|
+ }
|
|
927
|
+ return &out, nil
|
|
928
|
+}
|
|
929
|
+
|
|
930
|
+func GetLastDrugWarehouseById(orgid int64, record_date int64) (models.DrugWarehouseOut, error) {
|
|
931
|
+
|
|
932
|
+ out := models.DrugWarehouseOut{}
|
|
933
|
+ err := XTReadDB().Where("org_id = ? and warehouse_out_time =? and status = 1", orgid, record_date).Find(&out).Error
|
|
934
|
+ return out, err
|
|
935
|
+}
|
|
936
|
+
|
|
937
|
+func UpdateSupplyCancelById(id int64, order models.SpSupplierWarehousingCancelOrder) error {
|
|
938
|
+
|
|
939
|
+ err := XTReadDB().Model(&order).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"source_count": order.SourceCount}).Error
|
|
940
|
+ return err
|
|
941
|
+}
|
|
942
|
+
|
|
943
|
+func DeleteReturnOrder(id int64) error {
|
|
944
|
+
|
|
945
|
+ err := XTWriteDB().Model(&models.SpSupplierWarehouseCancel{}).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
|
|
946
|
+ err = XTWriteDB().Model(&models.SpSupplierWarehousingCancelOrder{}).Where("warehouse_cancel_id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
|
|
947
|
+ return err
|
|
948
|
+}
|
|
949
|
+
|
|
950
|
+func DeleteReturnOrderById(id int64) error {
|
|
951
|
+ err = XTWriteDB().Model(&models.SpSupplierWarehousingCancelOrder{}).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
|
|
952
|
+ return err
|
|
953
|
+}
|
|
954
|
+
|
|
955
|
+func ModefyReturnOrder(id int64) error {
|
|
956
|
+
|
|
957
|
+ cancel := models.SpSupplierWarehouseCancel{}
|
|
958
|
+ err := XTWriteDB().Model(&cancel).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"is_check": 2, "checker": 0, "check_time": 0}).Error
|
|
959
|
+ return err
|
|
960
|
+}
|
|
961
|
+
|
|
962
|
+func UpdateWarehousingInfoById(goodid int64, supply_warehouse_id int64, info models.WarehousingInfo) error {
|
|
963
|
+
|
|
964
|
+ err := XTWriteDB().Model(&info).Where("good_id = ? and supply_warehouse_detail_info = ? and status = 1", goodid, supply_warehouse_id).UpdateColumn("stock_count", gorm.Expr("stock_count - ?", info.StockCount)).Error
|
|
965
|
+ return err
|
|
966
|
+}
|
|
967
|
+
|
|
968
|
+func DeleteGoodWarehouseOut(goodid int64, supply_warehouse_id int64) error {
|
|
969
|
+
|
|
970
|
+ err := XTWriteDB().Model(&models.WarehouseOutInfo{}).Where("good_id = ? and supply_cancel_out_id = ? and status = 1", goodid, supply_warehouse_id).Updates(map[string]interface{}{"status": 0}).Error
|
|
971
|
+
|
|
972
|
+ err = XTWriteDB().Model(&models.VmStockFlow{}).Where("good_id = ? and supply_cancel_out_id = ? and status = 1", goodid, supply_warehouse_id).Updates(map[string]interface{}{"status": 0}).Error
|
|
973
|
+
|
|
974
|
+ return err
|
|
975
|
+}
|
|
976
|
+func UpdateDrugWasehousring(goodid int64, supply_warehouse_id int64, info models.DrugWarehouseInfo) error {
|
|
977
|
+
|
|
978
|
+ err := XTWriteDB().Model(&info).Where("good_id = ? and supply_cancel_out_id = ? and status = 1", goodid, supply_warehouse_id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number - ?", info.StockMaxNumber)).Error
|
|
979
|
+ return err
|
|
980
|
+}
|
|
981
|
+
|
|
982
|
+func UpdateDrugWasehousringOne(goodid int64, supply_warehouse_id int64, info models.DrugWarehouseInfo) error {
|
|
983
|
+
|
|
984
|
+ err := XTWriteDB().Model(&info).Where("good_id = ? and supply_cancel_out_id = ? and status = 1", goodid, supply_warehouse_id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number - ?", info.StockMinNumber)).Error
|
|
985
|
+ return err
|
|
986
|
+}
|
|
987
|
+
|
|
988
|
+func DeleteDrugWarehouseOutNight(goodid int64, supply_warehouse_id int64) error {
|
|
989
|
+
|
|
990
|
+ err := XTWriteDB().Model(&models.DrugWarehouseOutInfo{}).Where("good_id = ? and supply_cancel_out_id = ? and status = 1", goodid, supply_warehouse_id).Updates(map[string]interface{}{"status": 0}).Error
|
|
991
|
+
|
|
992
|
+ err = XTWriteDB().Model(&models.DrugFlow{}).Where("good_id = ? and supply_cancel_out_id = ? and status = 1", goodid, supply_warehouse_id).Updates(map[string]interface{}{"status": 0}).Error
|
|
993
|
+
|
|
994
|
+ return err
|
|
995
|
+}
|