supply_service.go 41KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012
  1. package service
  2. import (
  3. "XT_New/models"
  4. "github.com/jinzhu/gorm"
  5. "strings"
  6. "time"
  7. )
  8. //根据供应商编号获取首要联系人
  9. func FindName(code string, orgid int64) (fistname models.SpSupplierContacts, err error) {
  10. err = XTReadDB().Model(&models.SpSupplierContacts{}).Where("supplier_code = ? and status = 1 and is_first = 1 and user_org_id = ?", code, orgid).First(&fistname).Error
  11. return fistname, err
  12. }
  13. //供应商分页
  14. func GetSupplyList(ctype int64, page int64, limit int64, keyword string, orgid int64) (supplylist []*models.SpSupplierName, total int64, err error) {
  15. db := XTReadDB().Model(&supplylist).Where("xt_supplier_name.status = 1 and xt_supplier_name.user_org_id = ?", orgid)
  16. offset := (page - 1) * limit
  17. if len(keyword) > 0 {
  18. keyword = "%" + keyword + "%" //联系人
  19. db = db.Joins("join xt_supplier_contacts on xt_supplier_contacts.supplier_code = xt_supplier_name.supplier_code")
  20. db = db.Where("xt_supplier_contacts.name like ? or xt_supplier_name.supplier_code like ? or xt_supplier_name.supplier_name like ? ", keyword, keyword, keyword).Group("xt_supplier_name.id")
  21. }
  22. if ctype > 0 {
  23. db = db.Where("xt_supplier_name.supplier_type = ?", ctype)
  24. }
  25. err = db.Count(&total).Offset(offset).Order("xt_supplier_name.id desc").Limit(limit).Find(&supplylist).Error
  26. return supplylist, total, err
  27. }
  28. //修改供应商和联系人
  29. func UpdateSupplyAndContact(thisStockIn []interface{}, suid, orgId, supplierType, tcreater int64, supplierCode, supplierName, number, bank, bankAccount string, vatRate float64) error {
  30. tx := XTWriteDB().Begin()
  31. defer func() {
  32. if err != nil {
  33. tx.Rollback()
  34. } else {
  35. tx.Commit()
  36. }
  37. }()
  38. for _, item := range thisStockIn {
  39. items := item.(map[string]interface{})
  40. //判断联系人是否为新加的
  41. if items["id"] == "" || items["id"] == 0 {
  42. var tmp float64 = 0
  43. items["id"] = tmp
  44. }
  45. id := int64(items["id"].(float64))
  46. name := items["name"].(string)
  47. phone := items["phone"].(string)
  48. address := items["address"].(string)
  49. var tmpfirst int64
  50. switch items["is_first"].(type) {
  51. case int:
  52. var aint int = items["is_first"].(int)
  53. tmpfirst = int64(aint)
  54. case float64:
  55. tmpfirst = int64(items["is_first"].(float64))
  56. }
  57. isfirst := tmpfirst
  58. updatecontacts := models.SpSupplierContacts{
  59. ID: id,
  60. Name: name,
  61. Phone: phone,
  62. Address: address,
  63. IsFirst: isfirst,
  64. SupplierCode: supplierCode,
  65. UserOrgId: orgId,
  66. Status: 1,
  67. Ctime: 0,
  68. Mtime: time.Now().Unix(),
  69. }
  70. if id == 0 { //表示这是新加的
  71. spcontacts := models.SpSupplierContacts{
  72. Name: name,
  73. Phone: phone,
  74. Address: address,
  75. IsFirst: isfirst,
  76. SupplierCode: supplierCode,
  77. UserOrgId: orgId,
  78. Status: 1,
  79. Ctime: time.Now().Unix(),
  80. Mtime: 0,
  81. } //保存一条联系人的数据
  82. err = SaveContacts(spcontacts, tx)
  83. if err != nil {
  84. return err
  85. }
  86. } else {
  87. err = UpdateContact(updatecontacts, tx)
  88. }
  89. var tmpid int64
  90. if isfirst == 1 {
  91. if id == 0 { //新加的首要联系人
  92. var spconid []*models.SpSupplierContacts
  93. spconid, err = SaveContactsId(tx, orgId)
  94. if err != nil {
  95. return err
  96. }
  97. tmpid = spconid[0].ID
  98. } else {
  99. tmpid = id
  100. }
  101. //更新供应商
  102. upsupply := models.SpSupplierName{
  103. ID: suid,
  104. SupplierCode: supplierCode,
  105. SupplierName: supplierName,
  106. SupplierType: supplierType,
  107. VatRate: vatRate,
  108. Number: number,
  109. Bank: bank,
  110. BankAccount: bankAccount,
  111. UserOrgId: orgId,
  112. Status: 1,
  113. ContactsId: tmpid,
  114. Mtime: time.Now().Unix(),
  115. Modify: tcreater,
  116. }
  117. err = UpdateSupplyNameTX(upsupply, tx)
  118. if err != nil {
  119. return err
  120. }
  121. }
  122. }
  123. return err
  124. }
  125. //更新一条供应商的信息,添加了事务的
  126. func UpdateSupplyNameTX(upsupply models.SpSupplierName, tx *gorm.DB) error {
  127. 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
  128. return err
  129. }
  130. //更新一条供应商的信息,没有添加事务
  131. func UpdateSupplyName(upsupply models.SpSupplierName) error {
  132. 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
  133. return err
  134. }
  135. //更新一条联系人的信息
  136. func UpdateContact(updatecontacts models.SpSupplierContacts, tx *gorm.DB) error {
  137. 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
  138. return err
  139. }
  140. //查询供应商单条记录
  141. func GetSupplyOne(id int64) (supply models.SpSupplierName, err error) {
  142. err = XTReadDB().Model(&models.SpSupplierName{}).Where("id = ? and status = 1", id).First(&supply).Error
  143. return supply, err
  144. }
  145. //删除单条联系人记录
  146. func DelContactOne(id int64) error {
  147. err := XTWriteDB().Model(&models.SpSupplierContacts{}).Where("id = ?", id).Update("status", 0).Error
  148. return err
  149. }
  150. //获取单条供应商和涉及到的联系人记录
  151. func GetSupplyAndContactOne(id, orgId int64) (supply models.SpSupplierName, contact []*models.SpSupplierContacts, err error) {
  152. err = XTReadDB().Model(&models.SpSupplierName{}).Where("id = ? and status = 1 and user_org_id = ?", id, orgId).First(&supply).Error
  153. code := supply.SupplierCode
  154. err = XTReadDB().Model(&models.SpSupplierContacts{}).Where("supplier_code = ? and status = 1 and user_org_id = ?", code, orgId).Find(&contact).Error
  155. return supply, contact, err
  156. }
  157. //删除供应商及联系人
  158. func DelSupply(supply models.SpSupplierName, orgId int64) error {
  159. tx := XTWriteDB().Begin()
  160. defer func() {
  161. if err != nil {
  162. tx.Rollback()
  163. } else {
  164. tx.Commit()
  165. }
  166. }()
  167. //删除供应商
  168. err := tx.Model(&supply).Update("status", 0).Error
  169. if err != nil {
  170. return err
  171. }
  172. var spcode models.SpSupplierName
  173. //获取供应商编号
  174. err = tx.Model(&models.SpSupplierName{}).Select("supplier_code").Where("user_org_id = ? and id = ?", orgId, supply.ID).First(&spcode).Error
  175. if err != nil {
  176. return err
  177. }
  178. //删除联系人
  179. err = tx.Model(&models.SpSupplierContacts{}).Where("supplier_code = ? and user_org_id = ?", spcode.SupplierCode, orgId).Update("status", 0).Error
  180. return err
  181. }
  182. //保存供应商和联系人
  183. func SaveSupplyAndContact(thisStockIn []interface{}, orgId, supplierType, tcreater int64, supplierCode, supplierName, number, bank, bankAccount string, vatRate float64) error {
  184. tx := XTWriteDB().Begin()
  185. defer func() {
  186. if err != nil {
  187. tx.Rollback()
  188. } else {
  189. tx.Commit()
  190. }
  191. }()
  192. for _, item := range thisStockIn {
  193. items := item.(map[string]interface{})
  194. name := items["name"].(string)
  195. phone := items["phone"].(string)
  196. address := items["address"].(string)
  197. //isfirst := int64(items["is_first"].(float64))
  198. var tmpfirst int64
  199. //tmptype := reflect.TypeOf(items["is_first"])
  200. switch items["is_first"].(type) {
  201. case int:
  202. var aint int = items["is_first"].(int)
  203. tmpfirst = int64(aint)
  204. case float64:
  205. tmpfirst = int64(items["is_first"].(float64))
  206. }
  207. isfirst := tmpfirst
  208. spcontacts := models.SpSupplierContacts{
  209. Name: name,
  210. Phone: phone,
  211. Address: address,
  212. IsFirst: isfirst,
  213. SupplierCode: supplierCode,
  214. UserOrgId: orgId,
  215. Status: 1,
  216. Ctime: time.Now().Unix(),
  217. Mtime: 0,
  218. }
  219. err = SaveContacts(spcontacts, tx)
  220. if isfirst == 1 {
  221. var spconid []*models.SpSupplierContacts
  222. spconid, err = SaveContactsId(tx, orgId)
  223. if err != nil {
  224. return err
  225. }
  226. tmpid := spconid[0].ID
  227. //保存供应商
  228. supply := models.SpSupplierName{
  229. SupplierCode: supplierCode,
  230. SupplierName: supplierName,
  231. SupplierType: supplierType,
  232. VatRate: vatRate,
  233. Number: number,
  234. Bank: bank,
  235. BankAccount: bankAccount,
  236. UserOrgId: orgId,
  237. Status: 1,
  238. ContactsId: tmpid,
  239. Ctime: time.Now().Unix(),
  240. Mtime: 0,
  241. Creater: tcreater,
  242. Modify: tcreater,
  243. }
  244. err = SaveSupplyTx(supply, tx)
  245. if err != nil {
  246. return err
  247. }
  248. }
  249. if err != nil {
  250. return err
  251. }
  252. }
  253. return err
  254. }
  255. //获取供应商编码
  256. func GetSuppliyCode(orgId int64) (spcode []*models.SpSupplierName, err error) {
  257. 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
  258. return spcode, err
  259. }
  260. //查询供应商的名字是否有重复
  261. func FindSupplierName(supplierName string, orgId int64) (sbool bool, err error) {
  262. var total int
  263. err = XTReadDB().Model(&models.SpSupplierName{}).Where("supplier_name = ? and user_org_id = ? and status = 1", supplierName, orgId).Count(&total).Error
  264. if total != 0 {
  265. sbool = true
  266. } else {
  267. sbool = false
  268. }
  269. return sbool, err
  270. }
  271. //查询供应商的编号是否有重复(用于修改)
  272. func FindSupplierCode(supplierCode string, supplierid, orgid int64) (codebool bool, err error) {
  273. var total int
  274. err = XTReadDB().Model(&models.SpSupplierName{}).Where("supplier_code = ? and id != ? and user_org_id = ? and status = 1", supplierCode, supplierid, orgid).Count(&total).Error
  275. if total > 0 {
  276. codebool = true
  277. } else {
  278. codebool = false
  279. }
  280. return codebool, err
  281. }
  282. //查询供应商的编号是否有重复(用于新增)
  283. func FindSupplierCodes(supplierCode string, orgid int64) (codebool bool, err error) {
  284. var total int
  285. err = XTReadDB().Model(&models.SpSupplierName{}).Where("supplier_code = ? and status = 1 and user_org_id = ?", supplierCode, orgid).Count(&total).Error
  286. if total > 0 {
  287. codebool = true
  288. } else {
  289. codebool = false
  290. }
  291. return codebool, err
  292. }
  293. //保存一条供应商数据加事务的
  294. func SaveSupplyTx(supply models.SpSupplierName, tx *gorm.DB) error {
  295. err := tx.Create(&supply).Error
  296. return err
  297. }
  298. //保存一条供应商数据没有事务的
  299. func SaveSupply(supply models.SpSupplierName) error {
  300. err := XTWriteDB().Create(&supply).Error
  301. return err
  302. }
  303. //获取联系人的id
  304. func SaveContactsId(tx *gorm.DB, orgid int64) (spconid []*models.SpSupplierContacts, err error) {
  305. err = tx.Model(&models.SpSupplierContacts{}).Select("id").Where("status = 1 and user_org_id = ?", orgid).Order("id desc").First(&spconid).Error
  306. return
  307. }
  308. //保存一条联系人数据
  309. func SaveContacts(spcontacts models.SpSupplierContacts, tx *gorm.DB) error {
  310. err := tx.Create(&spcontacts).Error
  311. return err
  312. }
  313. func GetSupplyDrugList(orgid int64) (drug []*models.SpBaseDrug, err error) {
  314. db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1 AND find_in_set('停用',drug_status) = 0")
  315. if orgid > 0 {
  316. db = db.Where("x.org_id = ?", orgid)
  317. }
  318. err = db.Preload("DrugWarehouseInfo", "status = 1 and org_id = ? and (stock_max_number >0 or stock_min_number>0)", orgid).Find(&drug).Error
  319. return drug, err
  320. }
  321. func GetSupplyGoodList(orgid int64) (good []*models.SpGoodInformation, err error) {
  322. db := XTReadDB().Table("xt_good_information as x").Where("x.status = 1 AND find_in_set('停用',good_status) = 0")
  323. if orgid > 0 {
  324. db = db.Where("x.org_id = ?", orgid)
  325. }
  326. err = db.Preload("GoodWarehouseInfo", "status = 1 and org_id = ?", orgid).Find(&good).Error
  327. return good, err
  328. }
  329. func GetSupplierList(orgid int64) (suppler []*models.SpSupplierName, err error) {
  330. err = XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&suppler).Error
  331. return suppler, err
  332. }
  333. func FindAllSupplyOrder(orgid int64) (total int64, err error) {
  334. err = XTReadDB().Model(&models.SupplierWarehouseInfo{}).Where("user_org_id = ?", orgid).Count(&total).Error
  335. return total, err
  336. }
  337. func CreateSupplyWarehouse(info models.SupplierWarehouseInfo) error {
  338. err := XTWriteDB().Create(&info).Error
  339. return err
  340. }
  341. func FindLastSupplyWarehouseInfo(orgid int64) (models.SupplierWarehouseInfo, error) {
  342. info := models.SupplierWarehouseInfo{}
  343. err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Last(&info).Error
  344. return info, err
  345. }
  346. func CreateSupplyWarehousingOrder(order *models.SupplierWarehousingInfoOrder) error {
  347. err := XTWriteDB().Create(&order).Error
  348. return err
  349. }
  350. func GetAllPurchaseOrderList(check_id int64, startime int64, endtime int64, keyword string, page int64, limit int64, orgid int64) (info []*models.VmSupplierWarehouseInfo, total int64, err error) {
  351. db := XTReadDB().Model(&info).Where("sgj_xt.xt_supplier_warehouse_info.status = 1")
  352. likeKey := "%" + keyword + "%"
  353. offset := (page - 1) * limit
  354. if check_id > 0 {
  355. db = db.Where("sgj_xt.xt_supplier_warehouse_info.is_check = ?", check_id)
  356. }
  357. if startime > 0 {
  358. db = db.Where("sgj_xt.xt_supplier_warehouse_info.record_date >= ?", startime)
  359. }
  360. if endtime > 0 {
  361. db = db.Where("sgj_xt.xt_supplier_warehouse_info.record_date<=?", endtime)
  362. }
  363. if len(keyword) > 0 {
  364. db = db.Joins("join sgj_xt.xt_supplier_name on sgj_xt.xt_supplier_name.id = sgj_xt.xt_supplier_warehouse_info.supplier_id")
  365. 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")
  366. }
  367. if orgid > 0 {
  368. db = db.Where("sgj_xt.xt_supplier_warehouse_info.user_org_id = ?", orgid)
  369. }
  370. 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
  371. return info, total, err
  372. }
  373. func GetSupplyWarehousingOrderInfo(id int64) (order []*models.SupplierWarehousingInfoOrder, err error) {
  374. err = XTReadDB().Where("warehousing_id = ? and status = 1", id).Find(&order).Error
  375. return order, err
  376. }
  377. func GetSupplyWarehousingOrderInfoTwo(id int64, ids []string) (order []*models.SupplierWarehousingInfoOrder, err error) {
  378. err = XTReadDB().Where("warehousing_id = ? and status = 1 and project_id in(?)", id, ids).Find(&order).Error
  379. return order, err
  380. }
  381. func ModefySupplyWarehouseInfo(id int64, info models.SupplierWarehouseInfo) error {
  382. 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, "return_remake": info.ReturnRemake}).Error
  383. return err
  384. }
  385. func ModifySupplyWarehouseOrder(order *models.SupplierWarehousingInfoOrder) error {
  386. 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
  387. return err
  388. }
  389. func UpdateSupplyWaresing(id int64, info models.SupplierWarehouseInfo) error {
  390. err := XTWriteDB().Model(&models.SupplierWarehouseInfo{}).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"is_check": info.IsCheck, "checker": info.Checker, "check_time": info.CheckTime, "mtime": time.Now().Unix()}).Error
  391. return err
  392. }
  393. func GetPurchaseOrderDetail(id int64) (models.SupplierWarehouseInfo, error) {
  394. info := models.SupplierWarehouseInfo{}
  395. err := XTReadDB().Model(&info).Where("id =? and status =1", id).Find(&info).Error
  396. return info, err
  397. }
  398. func FindAllSupplyWarehouseOutOrder(orgid int64) (total int64, err error) {
  399. err = XTReadDB().Model(&models.SpSupplierWarehouseOut{}).Where("user_org_id = ?", orgid).Count(&total).Error
  400. return total, err
  401. }
  402. func FindSupplyWarehouseOutById(orgid int64) (models.SpSupplierWarehouseOut, error) {
  403. out := models.SpSupplierWarehouseOut{}
  404. err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Last(&out).Error
  405. return out, err
  406. }
  407. func CreateSupplyWarehouseOut(out models.SpSupplierWarehouseOut) error {
  408. err := XTWriteDB().Create(&out).Error
  409. return err
  410. }
  411. func CreateSupplyWarehousOutOrder(order *models.SpSupplierWarehousingOutOrder) error {
  412. err := XTWriteDB().Create(&order).Error
  413. return err
  414. }
  415. func GetSupplyWarehouseOutById(id int64, user_org_id int64) (order []*models.SpSupplierWarehousingOutOrder, err error) {
  416. err = XTReadDB().Where("warehouse_out_id = ? and status = 1 and user_org_id = ?", id, user_org_id).Find(&order).Error
  417. return order, err
  418. }
  419. func GetSupplyWarehouseOutByIdOne(id int64, user_org_id int64, ids []string) (order []*models.SpSupplierWarehousingOutOrder, err error) {
  420. err = XTReadDB().Where("warehouse_out_id = ? and status = 1 and user_org_id = ? and project_id in(?)", id, user_org_id, ids).Find(&order).Error
  421. return order, err
  422. }
  423. func GetAllGoodOderList(check_id int64, keyword string, page int64, limit int64, startime int64, endtime int64, orgid int64) (out []*models.VmSupplierWarehouseOut, total int64, err error) {
  424. db := XTReadDB().Model(&out).Where("sgj_xt.xt_supplier_warehouse_out.status = 1")
  425. likeKey := "%" + keyword + "%"
  426. offset := (page - 1) * limit
  427. if check_id > 0 {
  428. db = db.Where("sgj_xt.xt_supplier_warehouse_out.is_check = ?", check_id)
  429. }
  430. if startime > 0 {
  431. db = db.Where("sgj_xt.xt_supplier_warehouse_out.record_date >= ?", startime)
  432. }
  433. if endtime > 0 {
  434. db = db.Where("sgj_xt.xt_supplier_warehouse_out.record_date<=?", endtime)
  435. }
  436. if len(keyword) > 0 {
  437. db = db.Joins("join sgj_xt.xt_supplier_name on sgj_xt.xt_supplier_name.id = sgj_xt.xt_supplier_warehouse_out.supplier_id")
  438. db = db.Where("sgj_xt.xt_supplier_warehouse_out.good_number like ? or sgj_xt.xt_supplier_name.supplier_name like ? ", likeKey, likeKey).Group("xt_supplier_warehouse_out.id")
  439. }
  440. if orgid > 0 {
  441. db = db.Where("sgj_xt.xt_supplier_warehouse_out.user_org_id = ?", orgid)
  442. }
  443. 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
  444. return out, total, err
  445. }
  446. func GetGoodOrderDetail(id int64, orgid int64) (models.SpSupplierWarehouseOut, error) {
  447. out := models.SpSupplierWarehouseOut{}
  448. err := XTReadDB().Where("id = ? and user_org_id = ? and status = 1", id, orgid).Find(&out).Error
  449. return out, err
  450. }
  451. func UpdateGoodWarehouseOut(id int64, out models.SpSupplierWarehouseOut) error {
  452. 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, "return_remake": out.ReturnRemake, "supplier_id": out.SupplierId}).Error
  453. return err
  454. }
  455. func UpdateGoodWarehouseOutOrder(order *models.SpSupplierWarehousingOutOrder) error {
  456. 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.Price, "remark": order.Remark, "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.SupplyTotal, "supply_manufacturer": order.SupplyManufacturer, "name": order.Name, "supply_unit": order.SupplyUnit, "manufacturer_id": order.ManufacturerId, "supply_license_number": order.SupplyLicenseNumber, "warehousing_id": order.WarehousingId, "warehouse_info_id": order.WarehouseInfoId, "min_price": order.MinPrice}).Error
  457. return err
  458. }
  459. func DeletePurchOrder(id int64, orgid int64) error {
  460. err := XTWriteDB().Model(&models.SupplierWarehouseInfo{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  461. 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
  462. return err
  463. }
  464. func GetAllPurcaseOrderById(id int64, orgid int64) (order []*models.VSupplierWarehousingInfoOrder, err error) {
  465. err = XTReadDB().Model(&order).Where("warehousing_id = ? and user_org_id = ? and status =1", id, orgid).Find(&order).Error
  466. return order, err
  467. }
  468. func GetAllGoodOrderById(id int64, orgid int64) (order []*models.VSpSupplierWarehousingOutOrder, err error) {
  469. db := XTReadDB().Table("xt_supplier_warehousing_out_order as o").Where("o.status = 1")
  470. if id > 0 {
  471. db = db.Where("o.warehousing_id = ?", id)
  472. }
  473. if orgid > 0 {
  474. db = db.Where("o.user_org_id =?", orgid)
  475. }
  476. err = db.Select("o.id,o.order_number,o.project_id,o.count as count,o.supply_unit,o.is_source").Find(&order).Error
  477. return order, err
  478. }
  479. func GetAllGoodOrderByIdTwo(id int64, orgid int64) (order []*models.SpSupplierWarehousingOutOrder, err error) {
  480. err = XTReadDB().Where("warehousing_id = ? and user_org_id = ? and status = 1", id, orgid).Find(&order).Error
  481. return order, err
  482. }
  483. func GetGoodOrderList(id int64, orgid int64) (info []*models.SpSupplierWarehouseOut, err error) {
  484. err = XTReadDB().Where("warehousing_id = ? and status = 1 and user_org_id = ?", id, orgid).Find(&info).Error
  485. return info, err
  486. }
  487. func GetReturnOrder(id int64, orgid int64) error {
  488. 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
  489. return err
  490. }
  491. func CheckGoodOrder(id int64, orgid int64, out models.SpSupplierWarehouseOut) error {
  492. 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
  493. return err
  494. }
  495. func ModefySupplyWarehousing(is_warehose int64, warehousing_id int64, orgid int64) error {
  496. err := XTWriteDB().Model(&models.SupplierWarehouseInfo{}).Where("id = ? and status = 1 and user_org_id =?", warehousing_id, orgid).Updates(map[string]interface{}{"is_warehouse": is_warehose, "mtime": time.Now().Unix()}).Error
  497. return err
  498. }
  499. func GetAllDoctorSix(orgid int64, appid int64) (appRole []*models.App_Role, err error) {
  500. err = UserReadDB().Where("org_id = ? AND app_id = ? AND status = 1", orgid, appid).Find(&appRole).Error
  501. return appRole, err
  502. }
  503. func GetSingleDrugWarehouseOrder(record_date int64, orgid int64) (*models.DrugWarehouse, error) {
  504. warehouse := models.DrugWarehouse{}
  505. var err error
  506. err = XTReadDB().Model(&warehouse).Where("warehousing_time = ? and org_id = ? and status = 1", record_date, orgid).Find(&warehouse).Error
  507. if err == gorm.ErrRecordNotFound {
  508. return nil, err
  509. }
  510. if err != nil {
  511. return nil, err
  512. }
  513. return &warehouse, nil
  514. }
  515. func GetSindleWarehouse(record_date int64, orgid int64) (*models.Warehousing, error) {
  516. warehousing := models.Warehousing{}
  517. var err error
  518. err = XTReadDB().Model(&warehousing).Where("warehousing_time = ? and org_id = ? and status = 1", record_date, orgid).Find(&warehousing).Error
  519. if err == gorm.ErrRecordNotFound {
  520. return nil, err
  521. }
  522. if err != nil {
  523. return nil, err
  524. }
  525. return &warehousing, nil
  526. }
  527. func GetLastWarehouseInfoByInfo(orgid int64) (models.Warehousing, error) {
  528. warehousing := models.Warehousing{}
  529. err := XTReadDB().Where("org_id = ? and status = 1", orgid).Find(&warehousing).Error
  530. return warehousing, err
  531. }
  532. func GetSupplyCancelOrder(orgid int64) (total int64, err error) {
  533. err = XTReadDB().Model(&models.SpSupplierWarehouseCancel{}).Where("user_org_id = ?", orgid).Count(&total).Error
  534. return total, err
  535. }
  536. func CreateReturnCacelOrder(cancel models.SpSupplierWarehouseCancel) error {
  537. err := XTWriteDB().Create(&cancel).Error
  538. return err
  539. }
  540. func GetLastReturnCancelOrder(orgid int64) (models.SpSupplierWarehouseCancel, error) {
  541. cancel := models.SpSupplierWarehouseCancel{}
  542. err := XTReadDB().Where("user_org_id =? and status = 1", orgid).Find(&cancel).Error
  543. return cancel, err
  544. }
  545. func CreateCancelReturnOrder(order *models.SpSupplierWarehousingCancelOrder) error {
  546. err := XTWriteDB().Create(&order).Error
  547. return err
  548. }
  549. func GetReturnCancelOrder(id int64, orgid int64) (models.SpSupplierWarehouseCancel, error) {
  550. cancel := models.SpSupplierWarehouseCancel{}
  551. err := XTReadDB().Where("id = ? and status= 1 and user_org_id =?", id, orgid).Find(&cancel).Error
  552. return cancel, err
  553. }
  554. func GetReturnCancelOrderList(id int64, orgid int64) (order models.SpSupplierWarehousingCancelOrder, err error) {
  555. err = XTReadDB().Where("warehouse_cancel_id = ? and user_org_id =? and status = 1", id, orgid).Find(&order).Error
  556. return order, err
  557. }
  558. func GetAllGoodReturnOrderList(checkid int64, keyword string, page int64, limit int64, startime int64, endtime int64, orgid int64) (order []*models.VmSpSupplierWarehouseCancel, total int64, err error) {
  559. db := XTReadDB().Table("sgj_xt.xt_supplier_warehouse_cancel").Where("sgj_xt.xt_supplier_warehouse_cancel.status = 1")
  560. likeKey := "%" + keyword + "%"
  561. offset := (page - 1) * limit
  562. if checkid > 0 {
  563. db = db.Where("sgj_xt.xt_supplier_warehouse_cancel.is_check = ?", checkid)
  564. }
  565. if len(keyword) > 0 {
  566. db = db.Joins("join sgj_xt.xt_supplier_name on sgj_xt.xt_supplier_name.id = sgj_xt.xt_supplier_warehouse_cancel.supplier_id")
  567. 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")
  568. }
  569. if startime > 0 {
  570. db = db.Where("sgj_xt.xt_supplier_warehouse_cancel.record_date >= ?", startime)
  571. }
  572. if endtime > 0 {
  573. db = db.Where("sgj_xt.xt_supplier_warehouse_cancel.record_date <= ?", endtime)
  574. }
  575. if orgid > 0 {
  576. db = db.Where("sgj_xt.xt_supplier_warehouse_cancel.user_org_id = ?", orgid)
  577. }
  578. err = db.Count(&total).Offset(offset).Limit(limit).Preload("SpSupplierWarehousingCancelOrder", "status= 1 and user_org_id = ?", orgid).Order("ctime desc").Find(&order).Error
  579. return order, total, err
  580. }
  581. func GetGoodReturnDetail(id int64, orgid int64) (models.VmSpSupplierWarehouseCancel, error) {
  582. cancel := models.VmSpSupplierWarehouseCancel{}
  583. db := XTReadDB().Model(&cancel).Where("status = 1")
  584. if id > 0 {
  585. db = db.Where("id = ?", id)
  586. }
  587. if orgid > 0 {
  588. db = db.Where("user_org_id = ?", orgid)
  589. }
  590. err := db.Find(&cancel).Error
  591. return cancel, err
  592. }
  593. func GetGoodReturnOrderDetail(id int64, orgid int64) (order []*models.SpSupplierWarehousingCancelOrder, err error) {
  594. db := XTReadDB().Model(&order).Where("status =1")
  595. if id > 0 {
  596. db = db.Where("warehouse_cancel_id = ?", id)
  597. }
  598. if orgid > 0 {
  599. db = db.Where("user_org_id = ?", orgid)
  600. }
  601. err = db.Find(&order).Error
  602. return order, err
  603. }
  604. func UpdateWarehouseCancelOrder(order *models.SpSupplierWarehousingCancelOrder) error {
  605. 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
  606. return err
  607. }
  608. func UpdateWarehouseCancel(id int64, cancel models.SpSupplierWarehouseCancel) error {
  609. err := XTWriteDB().Model(&cancel).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"rate_of_concession": cancel.RateOfConcession, "discount_amount": cancel.DiscountAmount, "document_date": cancel.DocumentDate, "supplier_id": cancel.SupplierId, "arrearage": cancel.Arrearage, "payment": cancel.Payment, "return_remark": cancel.ReturnRemark}).Error
  610. return err
  611. }
  612. func GetSupplyCancelOrderById(warehouse_out_id int64, orgid int64) (*models.SpSupplierWarehouseCancel, error) {
  613. cancel := models.SpSupplierWarehouseCancel{}
  614. var err error
  615. err = XTReadDB().Where("warehouse_out_id = ? and user_org_id = ? and status = 1", warehouse_out_id, orgid).Find(&cancel).Error
  616. if err == gorm.ErrRecordNotFound {
  617. return nil, err
  618. }
  619. if err != nil {
  620. return nil, err
  621. }
  622. return &cancel, nil
  623. }
  624. func UpdateSupplyGoodOrder(id int64, out models.SpSupplierWarehouseOut) error {
  625. err := XTWriteDB().Model(&models.SpSupplierWarehouseOut{}).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"is_check": out.IsCheck, "checker": out.Checker, "check_time": out.CheckTime}).Error
  626. return err
  627. }
  628. func UpdateDrugSupplyWarehousingInfo(id int64, orgid int64) error {
  629. err := XTWriteDB().Model(&models.DrugWarehouseInfo{}).Where("supply_warehouse_id = ? and org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"status": 0}).Error
  630. return err
  631. }
  632. func UpdateDrugSupplyFlow(id int64, orgid int64) error {
  633. err := XTWriteDB().Model(&models.DrugFlow{}).Where("supply_warehouse_id = ? and user_org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"status": 0}).Error
  634. return err
  635. }
  636. func UpdateGoodSupplyWarehousingInfo(id int64, orgid int64) error {
  637. err := XTWriteDB().Model(&models.WarehousingInfo{}).Where("supply_warehouse_id = ? and org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"status": 0}).Error
  638. return err
  639. }
  640. func UpdateGoodSupplyFlow(id int64, orgid int64) error {
  641. err := XTWriteDB().Model(&models.WarehousingInfo{}).Where("supply_warehouse_id = ? and org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"status": 0}).Error
  642. return err
  643. }
  644. func GetDrugSupplyWarehousingById(id int64, orgid int64) (info []*models.DrugWarehouseInfo, err error) {
  645. err = XTReadDB().Where("supply_warehouse_id <> ? and org_id = ? and status = 1", id, orgid).Find(&info).Error
  646. return info, err
  647. }
  648. func UpdateSupplyWarehousing(id int64, orgid int64) error {
  649. err := XTWriteDB().Model(&models.DrugWarehouse{}).Where("supply_warehouse_id = ? and org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"status": 0}).Error
  650. return err
  651. }
  652. func GetGoodSupplyWarehousingById(id int64, orgid int64) (info []*models.WarehousingInfo, err error) {
  653. err = XTReadDB().Where("supply_warehouse_id <> ? and org_id = ? and status = 1", id, orgid).Find(&info).Error
  654. return info, err
  655. }
  656. func UpdateGoodWarehousing(id int64, orgid int64) error {
  657. err := XTWriteDB().Model(&models.Warehousing{}).Where("supply_warehouse_id = ? and org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"status": 0}).Error
  658. return err
  659. }
  660. func UpdateSupplyWarehousingById(id int64, orgid int64) error {
  661. err := XTWriteDB().Model(&models.SupplierWarehouseInfo{}).Where("id = ? and user_org_id =? and status = 1", id, orgid).Updates(map[string]interface{}{"is_warehouse": 1}).Error
  662. return err
  663. }
  664. func DeleteGoodOrder(id int64, orgid int64) error {
  665. err := XTWriteDB().Model(&models.SpSupplierWarehouseOut{}).Where("id = ? and status = 1 and user_org_id = ?", id, orgid).Updates(map[string]interface{}{"status": 0}).Error
  666. err = XTWriteDB().Model(&models.SpSupplierWarehousingOutOrder{}).Where("warehouse_out_id = ? and user_org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"status": 0}).Error
  667. return err
  668. }
  669. func GetSupplyCancelWarehouse(id int64, orgid int64) (cancel []*models.SpSupplierWarehouseCancel, err error) {
  670. err = XTReadDB().Where("warehouse_out_id = ? and user_org_id = ? and status = 1", id, orgid).Find(&cancel).Error
  671. return cancel, err
  672. }
  673. func GetGoodOrderListById(id int64, orgid int64) (out []*models.VmSpSupplierWarehousingOutOrder, err error) {
  674. err = XTReadDB().Where("warehouse_out_id = ? and user_org_id = ? and status = 1", id, orgid).Find(&out).Error
  675. return out, err
  676. }
  677. func GetGoodCanceListById(id int64, orgid int64) (cancel []*models.VmSpSupplierWarehousingCancelOrder, err error) {
  678. err = XTReadDB().Where("warehouse_out_id = ? and user_org_id = ? and status = 1", id, orgid).Find(&cancel).Error
  679. return cancel, err
  680. }
  681. func CreateDrugFlowSix(drugflow []*models.DrugFlow) (err error) {
  682. if len(drugflow) > 0 {
  683. utx := writeDb.Begin()
  684. if len(drugflow) > 0 {
  685. 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 "
  686. insertParams := make([]string, 0)
  687. insertData := make([]interface{}, 0)
  688. for _, info := range drugflow {
  689. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
  690. insertData = append(insertData, info.WarehousingId)
  691. insertData = append(insertData, info.DrugId)
  692. insertData = append(insertData, info.Number)
  693. insertData = append(insertData, info.BatchNumber)
  694. insertData = append(insertData, info.Count)
  695. insertData = append(insertData, info.UserOrgId)
  696. insertData = append(insertData, info.PatientId)
  697. insertData = append(insertData, info.SystemTime)
  698. insertData = append(insertData, info.ConsumableType)
  699. insertData = append(insertData, info.IsSys)
  700. insertData = append(insertData, info.WarehousingOrder)
  701. insertData = append(insertData, info.WarehouseOutId)
  702. insertData = append(insertData, info.WarehouseOutOrderNumber)
  703. insertData = append(insertData, info.IsEdit)
  704. insertData = append(insertData, info.CancelStockId)
  705. insertData = append(insertData, info.CancelOrderNumber)
  706. insertData = append(insertData, info.Manufacturer)
  707. insertData = append(insertData, info.Dealer)
  708. insertData = append(insertData, info.Creator)
  709. insertData = append(insertData, info.UpdateCreator)
  710. insertData = append(insertData, info.Status)
  711. insertData = append(insertData, info.Ctime)
  712. insertData = append(insertData, info.Mtime)
  713. insertData = append(insertData, info.Price)
  714. insertData = append(insertData, info.WarehousingDetailId)
  715. insertData = append(insertData, info.WarehouseOutDetailId)
  716. insertData = append(insertData, info.CancelOutDetailId)
  717. insertData = append(insertData, info.ExpireDate)
  718. insertData = append(insertData, info.ProductDate)
  719. insertData = append(insertData, info.MaxUnit)
  720. insertData = append(insertData, info.MinUnit)
  721. insertData = append(insertData, info.SupplyWarehouseId)
  722. insertData = append(insertData, info.SupplyWarehouseDetailInfo)
  723. }
  724. thisSQL += strings.Join(insertParams, ", ")
  725. err = utx.Exec(thisSQL, insertData...).Error
  726. if err != nil {
  727. utx.Rollback()
  728. return
  729. }
  730. }
  731. utx.Commit()
  732. }
  733. return
  734. }
  735. func CheckReturnOrder(id int64, orgid int64, cancel models.SpSupplierWarehouseCancel) error {
  736. 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
  737. return err
  738. }
  739. func GetSupplyCancelOrderDetail(id int64, orgid int64) (cancel []*models.SpSupplierWarehousingCancelOrder, err error) {
  740. err = XTReadDB().Where("warehouse_cancel_id = ? and user_org_id = ? and status = 1", id, orgid).Find(&cancel).Error
  741. return cancel, err
  742. }
  743. func DeletePurchaseOrder(id int64) error {
  744. err := XTWriteDB().Model(&models.SupplierWarehousingInfoOrder{}).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
  745. return err
  746. }
  747. func DeleteGoodOrderById(id int64) error {
  748. err := XTWriteDB().Model(&models.SpSupplierWarehousingOutOrder{}).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
  749. return err
  750. }
  751. func GetlastWarehouseOutById(user_org_id int64, record_date int64) (models.WarehouseOut, error) {
  752. out := models.WarehouseOut{}
  753. err := XTReadDB().Where("org_id = ? and warehouse_out_time = ? and status = 1", user_org_id, record_date).Find(&out).Error
  754. return out, err
  755. }
  756. func GetDrugWarehouseOutById(orgid int64, record_date int64) (*models.DrugWarehouseOut, error) {
  757. out := models.DrugWarehouseOut{}
  758. var err error
  759. err = XTReadDB().Where("org_id = ? and warehouse_out_time = ?", orgid, record_date).Find(&out).Error
  760. if err == gorm.ErrRecordNotFound {
  761. return nil, err
  762. }
  763. if err != nil {
  764. return nil, err
  765. }
  766. return &out, nil
  767. }
  768. func GetLastDrugWarehouseById(orgid int64, record_date int64) (models.DrugWarehouseOut, error) {
  769. out := models.DrugWarehouseOut{}
  770. err := XTReadDB().Where("org_id = ? and warehouse_out_time =? and status = 1", orgid, record_date).Find(&out).Error
  771. return out, err
  772. }
  773. func UpdateSupplyCancelById(id int64, order models.SpSupplierWarehousingCancelOrder) error {
  774. err := XTReadDB().Model(&order).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"source_count": order.SourceCount}).Error
  775. return err
  776. }
  777. func DeleteReturnOrder(id int64) error {
  778. err := XTWriteDB().Model(&models.SpSupplierWarehouseCancel{}).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
  779. err = XTWriteDB().Model(&models.SpSupplierWarehousingCancelOrder{}).Where("warehouse_cancel_id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
  780. return err
  781. }
  782. func DeleteReturnOrderById(id int64) error {
  783. err = XTWriteDB().Model(&models.SpSupplierWarehousingCancelOrder{}).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
  784. return err
  785. }
  786. func ModefyReturnOrder(id int64) error {
  787. cancel := models.SpSupplierWarehouseCancel{}
  788. err := XTWriteDB().Model(&cancel).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"is_check": 2, "checker": 0, "check_time": 0}).Error
  789. return err
  790. }
  791. func UpdateWarehousingInfoById(goodid int64, supply_warehouse_id int64, info models.WarehousingInfo) error {
  792. 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
  793. return err
  794. }
  795. func DeleteGoodWarehouseOut(goodid int64, supply_warehouse_id int64) error {
  796. 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
  797. 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
  798. return err
  799. }
  800. func UpdateDrugWasehousring(goodid int64, supply_warehouse_id int64, info models.DrugWarehouseInfo) error {
  801. 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
  802. return err
  803. }
  804. func UpdateDrugWasehousringOne(goodid int64, supply_warehouse_id int64, info models.DrugWarehouseInfo) error {
  805. 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
  806. return err
  807. }
  808. func DeleteDrugWarehouseOutNight(goodid int64, supply_warehouse_id int64) error {
  809. 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
  810. 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
  811. return err
  812. }
  813. func GetGoodIsSource(warehousing_id int64, project_id int64, orgid int64) (*models.SupplierWarehousingInfoOrder, error) {
  814. info := models.SupplierWarehousingInfoOrder{}
  815. var err error
  816. err = XTReadDB().Model(&info).Where("warehousing_id = ? and project_id = ? and user_org_id = ? and status = 1", warehousing_id, project_id, orgid).Find(&info).Error
  817. if err == gorm.ErrRecordNotFound {
  818. return nil, err
  819. }
  820. if err != nil {
  821. return nil, err
  822. }
  823. return &info, nil
  824. }
  825. func ModfySupplyWarehouseOut(warehousing_id int64, orgid int64) error {
  826. out := models.SpSupplierWarehouseOut{}
  827. err := XTWriteDB().Model(&out).Where("warehousing_id = ? and user_org_id =? and status = 1", warehousing_id, orgid).Updates(map[string]interface{}{"warehousing_id": 0, "number": ""}).Error
  828. return err
  829. }