supply_service.go 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. package service
  2. import (
  3. "XT_New/models"
  4. "github.com/jinzhu/gorm"
  5. "strconv"
  6. "time"
  7. )
  8. //删除供应商及联系人
  9. func DelSupply(supply models.SpSupplierName) error {
  10. err := XTWriteDB().Model(&supply).Update("status", 0).Error
  11. return err
  12. }
  13. //保存供应商和联系人
  14. func SaveSupplyAndContact(thisStockIn []interface{}, orgId, supplierType, tcreater int64, supplierCode, supplierName, number, bank, bankAccount string, vatRate float64) error {
  15. tx := XTWriteDB().Begin()
  16. defer func() {
  17. if err != nil {
  18. tx.Rollback()
  19. } else {
  20. tx.Commit()
  21. }
  22. }()
  23. for _, item := range thisStockIn {
  24. items := item.(map[string]interface{})
  25. name := items["name"].(string)
  26. phone := items["phone"].(string)
  27. address := items["address"].(string)
  28. isfirst, _ := strconv.ParseInt(items["isfirst"].(string), 10, 64)
  29. spcontacts := models.SpSupplierContacts{
  30. Name: name,
  31. Phone: phone,
  32. Address: address,
  33. IsFirst: isfirst,
  34. UserOrgId: orgId,
  35. Status: 1,
  36. Ctime: time.Now().Unix(),
  37. Mtime: 0,
  38. }
  39. err = SaveContacts(spcontacts, tx)
  40. if isfirst == 1 {
  41. var spconid []*models.SpSupplierContacts
  42. spconid, err = SaveContactsId(tx)
  43. if err != nil {
  44. return err
  45. }
  46. tmpid := spconid[0].ID
  47. //保存供应商
  48. supply := models.SpSupplierName{
  49. SupplierCode: supplierCode,
  50. SupplierName: supplierName,
  51. SupplierType: supplierType,
  52. VatRate: vatRate,
  53. Number: number,
  54. Bank: bank,
  55. BankAccount: bankAccount,
  56. UserOrgId: orgId,
  57. Status: 1,
  58. ContactsId: tmpid,
  59. Ctime: time.Now().Unix(),
  60. Mtime: 0,
  61. Creater: tcreater,
  62. Modify: tcreater,
  63. }
  64. err = SaveSupply(supply, tx)
  65. if err != nil {
  66. return err
  67. }
  68. }
  69. if err != nil {
  70. return err
  71. }
  72. }
  73. return err
  74. }
  75. //获取供应商编码
  76. func GetSuppliyCode() (spcode []*models.SpSupplierName, err error) {
  77. err = XTReadDB().Model(&models.SpSupplierName{}).Select("supplier_code").Where("supplier_code like 'gys%' ").Order("supplier_code desc").First(&spcode).Error
  78. return spcode, err
  79. }
  80. //查询供应商的名字是否有重复
  81. func FindSupplierName(supplierName string) (sbool bool, err error) {
  82. var total int
  83. err = XTReadDB().Model(&models.SpSupplierName{}).Where("supplier_name = ? and status = 1", supplierName).Count(&total).Error
  84. if total != 0 {
  85. sbool = true
  86. } else {
  87. sbool = false
  88. }
  89. return sbool, err
  90. }
  91. //保存一条供应商数据
  92. func SaveSupply(supply models.SpSupplierName, tx *gorm.DB) error {
  93. err := tx.Create(&supply).Error
  94. return err
  95. }
  96. //获取联系人的id
  97. func SaveContactsId(tx *gorm.DB) (spconid []*models.SpSupplierContacts, err error) {
  98. err = tx.Model(&models.SpSupplierContacts{}).Select("id").Order("id desc").First(&spconid).Error
  99. return
  100. }
  101. //保存一条联系人数据
  102. func SaveContacts(spcontacts models.SpSupplierContacts, tx *gorm.DB) error {
  103. err := tx.Create(&spcontacts).Error
  104. return err
  105. }
  106. func GetSupplyDrugList(orgid int64) (drug []*models.SpBaseDrug, err error) {
  107. db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1")
  108. if orgid > 0 {
  109. db = db.Where("x.org_id = ?", orgid)
  110. }
  111. err = db.Preload("DrugWarehouseInfo", "status = 1 and org_id = ? and (stock_max_number >0 or stock_min_number>0)", orgid).Find(&drug).Error
  112. return drug, err
  113. }
  114. func GetSupplyGoodList(orgid int64) (good []*models.SpGoodInformation, err error) {
  115. db := XTReadDB().Table("xt_good_information as x").Where("x.status = 1")
  116. if orgid > 0 {
  117. db = db.Where("x.org_id = ?", orgid)
  118. }
  119. err = db.Preload("GoodWarehouseInfo", "status = 1 and org_id = ?", orgid).Find(&good).Error
  120. return good, err
  121. }
  122. func GetSupplierList(orgid int64) (suppler []*models.SpSupplierName, err error) {
  123. err = XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&suppler).Error
  124. return suppler, err
  125. }
  126. func FindAllSupplyOrder(orgid int64) (total int64, err error) {
  127. err = XTReadDB().Model(&models.SupplierWarehouseInfo{}).Where("user_org_id = ?", orgid).Count(&total).Error
  128. return total, err
  129. }
  130. func CreateSupplyWarehouse(info models.SupplierWarehouseInfo) error {
  131. err := XTWriteDB().Create(&info).Error
  132. return err
  133. }
  134. func FindLastSupplyWarehouseInfo(orgid int64) (models.SupplierWarehouseInfo, error) {
  135. info := models.SupplierWarehouseInfo{}
  136. err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Last(&info).Error
  137. return info, err
  138. }
  139. func CreateSupplyWarehousingOrder(order *models.SupplierWarehousingInfoOrder) error {
  140. err := XTWriteDB().Create(&order).Error
  141. return err
  142. }
  143. func GetAllPurchaseOrderList(check_id int64, startime int64, endtime int64, keyword string, page int64, limit int64, orgid int64) (info []*models.VmSupplierWarehouseInfo, total int64, err error) {
  144. db := XTReadDB().Model(&info).Where("sgj_xt.xt_supplier_warehouse_info.status = 1")
  145. likeKey := "%" + keyword + "%"
  146. offset := (page - 1) * limit
  147. if check_id > 0 {
  148. db = db.Where("sgj_xt.xt_supplier_warehouse_info.is_check = ?", check_id)
  149. }
  150. if startime > 0 {
  151. db = db.Where("sgj_xt.xt_supplier_warehouse_info.record_date >= ?", startime)
  152. }
  153. if endtime > 0 {
  154. db = db.Where("sgj_xt.xt_supplier_warehouse_info.record_date<=?", endtime)
  155. }
  156. if len(keyword) > 0 {
  157. db = db.Joins("join sgj_xt.xt_supplier_name on sgj_xt.xt_supplier_name.id = sgj_xt.xt_supplier_warehouse_info.supplier_id")
  158. 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")
  159. }
  160. if orgid > 0 {
  161. db = db.Where("sgj_xt.xt_supplier_warehouse_info.user_org_id = ?", orgid)
  162. }
  163. 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
  164. return info, total, err
  165. }
  166. func GetSupplyWarehousingOrderInfo(id int64) (order []*models.SupplierWarehousingInfoOrder, err error) {
  167. err = XTReadDB().Where("warehousing_id = ? and status = 1", id).Find(&order).Error
  168. return order, err
  169. }
  170. func GetSupplyWarehousingOrderInfoTwo(id int64, ids []string) (order []*models.SupplierWarehousingInfoOrder, err error) {
  171. err = XTReadDB().Where("warehousing_id = ? and status = 1 and project_id in(?)", id, ids).Find(&order).Error
  172. return order, err
  173. }
  174. func ModefySupplyWarehouseInfo(id int64, info models.SupplierWarehouseInfo) error {
  175. 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
  176. return err
  177. }
  178. func ModifySupplyWarehouseOrder(order *models.SupplierWarehousingInfoOrder) error {
  179. 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
  180. return err
  181. }
  182. func UpdateSupplyWaresing(id int64, info models.SupplierWarehouseInfo) error {
  183. 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
  184. return err
  185. }
  186. func GetPurchaseOrderDetail(id int64) (models.SupplierWarehouseInfo, error) {
  187. info := models.SupplierWarehouseInfo{}
  188. err := XTReadDB().Model(&info).Where("id =? and status =1", id).Find(&info).Error
  189. return info, err
  190. }
  191. func FindAllSupplyWarehouseOutOrder(orgid int64) (total int64, err error) {
  192. err = XTReadDB().Model(&models.SpSupplierWarehouseOut{}).Where("user_org_id = ?", orgid).Count(&total).Error
  193. return total, err
  194. }
  195. func FindSupplyWarehouseOutById(orgid int64) (models.SpSupplierWarehouseOut, error) {
  196. out := models.SpSupplierWarehouseOut{}
  197. err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Last(&out).Error
  198. return out, err
  199. }
  200. func CreateSupplyWarehouseOut(out models.SpSupplierWarehouseOut) error {
  201. err := XTWriteDB().Create(&out).Error
  202. return err
  203. }
  204. func CreateSupplyWarehousOutOrder(order *models.SpSupplierWarehousingOutOrder) error {
  205. err := XTWriteDB().Create(&order).Error
  206. return err
  207. }
  208. func GetSupplyWarehouseOutById(id int64, user_org_id int64) (order []*models.SpSupplierWarehousingOutOrder, err error) {
  209. err = XTReadDB().Where("warehouse_out_id = ? and status = 1 and user_org_id = ?", id, user_org_id).Find(&order).Error
  210. return order, err
  211. }
  212. func GetAllGoodOderList(check_id int64, keyword string, page int64, limit int64, startime int64, endtime int64, orgid int64) (out []*models.VmSupplierWarehouseOut, total int64, err error) {
  213. db := XTReadDB().Model(&out).Where("sgj_xt.xt_supplier_warehouse_out.status = 1")
  214. likeKey := "%" + keyword + "%"
  215. offset := (page - 1) * limit
  216. if check_id > 0 {
  217. db = db.Where("sgj_xt.xt_supplier_warehouse_out.is_check = ?", check_id)
  218. }
  219. if startime > 0 {
  220. db = db.Where("sgj_xt.xt_supplier_warehouse_out.record_date >= ?", startime)
  221. }
  222. if endtime > 0 {
  223. db = db.Where("sgj_xt.xt_supplier_warehouse_out.record_date<=?", endtime)
  224. }
  225. if len(keyword) > 0 {
  226. db = db.Joins("join sgj_xt.xt_supplier_name on sgj_xt.xt_supplier_name.id = sgj_xt.xt_supplier_warehouse_out.supplier_id")
  227. 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")
  228. }
  229. if orgid > 0 {
  230. db = db.Where("sgj_xt.xt_supplier_warehouse_out.user_org_id = ?", orgid)
  231. }
  232. 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
  233. return out, total, err
  234. }
  235. func GetGoodOrderDetail(id int64, orgid int64) (models.SpSupplierWarehouseOut, error) {
  236. out := models.SpSupplierWarehouseOut{}
  237. err := XTReadDB().Where("id = ? and user_org_id = ? and status = 1", id, orgid).Find(&out).Error
  238. return out, err
  239. }
  240. func UpdateGoodWarehouseOut(id int64, out models.SpSupplierWarehouseOut) error {
  241. 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}).Error
  242. return err
  243. }
  244. func UpdateGoodWarehouseOutOrder(order *models.SpSupplierWarehousingOutOrder) error {
  245. 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, "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.SupplySpecificationName, "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}).Error
  246. return err
  247. }
  248. func DeletePurchOrder(id int64, orgid int64) error {
  249. err := XTWriteDB().Model(&models.SupplierWarehouseInfo{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  250. 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
  251. return err
  252. }
  253. func GetAllPurcaseOrderById(id int64, orgid int64) (order []*models.VSupplierWarehousingInfoOrder, err error) {
  254. err = XTReadDB().Model(&order).Where("warehousing_id = ? and user_org_id = ? and status =1", id, orgid).Find(&order).Error
  255. return order, err
  256. }
  257. func GetAllGoodOrderById(id int64, orgid int64) (order []*models.VSpSupplierWarehousingOutOrder, err error) {
  258. db := XTReadDB().Table("xt_supplier_warehousing_out_order as o").Where("o.status = 1")
  259. if id > 0 {
  260. db = db.Where("o.warehousing_id = ?", id)
  261. }
  262. if orgid > 0 {
  263. db = db.Where("o.user_org_id =?", orgid)
  264. }
  265. err = db.Select("o.id,o.order_number,o.project_id,o.count as count,o.supply_unit,o.is_source").Find(&order).Error
  266. return order, err
  267. }
  268. func GetAllGoodOrderByIdTwo(id int64, orgid int64) (order []*models.SpSupplierWarehousingOutOrder, err error) {
  269. err = XTReadDB().Where("warehousing_id = ? and user_org_id = ? and status = 1", id, orgid).Find(&order).Error
  270. return order, err
  271. }
  272. func GetGoodOrderList(id int64, orgid int64) (info []*models.SpSupplierWarehouseOut, err error) {
  273. err = XTReadDB().Where("warehousing_id = ? and status = 1 and user_org_id = ?", id, orgid).Find(&info).Error
  274. return info, err
  275. }
  276. func GetReturnOrder(id int64, orgid int64) error {
  277. 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
  278. return err
  279. }
  280. func CheckGoodOrder(id int64, orgid int64, out models.SpSupplierWarehouseOut) error {
  281. 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
  282. return err
  283. }
  284. func ModefySupplyWarehousing(is_warehose int64, warehousing_id int64, orgid int64) error {
  285. 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
  286. return err
  287. }
  288. func GetAllDoctorSix(orgid int64, appid int64) (appRole []*models.App_Role, err error) {
  289. err = UserReadDB().Where("org_id = ? AND app_id = ? AND status = 1", orgid, appid).Find(&appRole).Error
  290. return appRole, err
  291. }
  292. func GetSingleDrugWarehouseOrder(record_date int64, orgid int64) (*models.DrugWarehouse, error) {
  293. warehouse := models.DrugWarehouse{}
  294. var err error
  295. err = XTReadDB().Model(&warehouse).Where("warehousing_time = ? and org_id = ? and status = 1", record_date, orgid).Find(&warehouse).Error
  296. if err == gorm.ErrRecordNotFound {
  297. return nil, err
  298. }
  299. if err != nil {
  300. return nil, err
  301. }
  302. return &warehouse, nil
  303. }
  304. func GetSindleWarehouse(record_date int64, orgid int64) (*models.Warehousing, error) {
  305. warehousing := models.Warehousing{}
  306. var err error
  307. err = XTReadDB().Model(&warehousing).Where("warehousing_time = ? and org_id = ? and status = 1", record_date, orgid).Find(&warehousing).Error
  308. if err == gorm.ErrRecordNotFound {
  309. return nil, err
  310. }
  311. if err != nil {
  312. return nil, err
  313. }
  314. return &warehousing, nil
  315. }
  316. func GetLastWarehouseInfoByInfo(orgid int64) (models.Warehousing, error) {
  317. warehousing := models.Warehousing{}
  318. err := XTReadDB().Where("org_id = ? and status = 1", orgid).Find(&warehousing).Error
  319. return warehousing, err
  320. }
  321. func GetSupplyCancelOrder(orgid int64) (total int64, err error) {
  322. err = XTReadDB().Model(&models.SpSupplierWarehouseCancel{}).Where("user_org_id = ?", orgid).Count(&total).Error
  323. return total, err
  324. }
  325. func CreateReturnCacelOrder(cancel models.SpSupplierWarehouseCancel) error {
  326. err := XTWriteDB().Create(&cancel).Error
  327. return err
  328. }
  329. func GetLastReturnCancelOrder(orgid int64) (models.SpSupplierWarehouseCancel, error) {
  330. cancel := models.SpSupplierWarehouseCancel{}
  331. err := XTReadDB().Where("user_org_id =? and status = 1", orgid).Find(&cancel).Error
  332. return cancel, err
  333. }
  334. func CreateCancelReturnOrder(order *models.SpSupplierWarehousingCancelOrder) error {
  335. err := XTWriteDB().Create(&order).Error
  336. return err
  337. }
  338. func GetReturnCancelOrder(id int64, orgid int64) (models.SpSupplierWarehouseCancel, error) {
  339. cancel := models.SpSupplierWarehouseCancel{}
  340. err := XTReadDB().Where("id = ? and status= 1 and user_org_id =?", id, orgid).Find(&cancel).Error
  341. return cancel, err
  342. }
  343. func GetReturnCancelOrderList(id int64, orgid int64) (order models.SpSupplierWarehousingCancelOrder, err error) {
  344. err = XTReadDB().Where("warehouse_cancel_id = ? and user_org_id =? and status = 1", id, orgid).Find(&order).Error
  345. return order, err
  346. }
  347. func GetAllGoodReturnOrderList(checkid int64, keyword string, page int64, limit int64, startime int64, endtime int64, orgid int64) (order []*models.VmSpSupplierWarehouseCancel, total int64, err error) {
  348. db := XTReadDB().Table("sgj_xt.xt_supplier_warehouse_cancel").Where("sgj_xt.xt_supplier_warehouse_cancel.status = 1")
  349. likeKey := "%" + keyword + "%"
  350. offset := (page - 1) * limit
  351. if checkid > 0 {
  352. db = db.Where("sgj_xt.xt_supplier_warehouse_cancel.is_check = ?", checkid)
  353. }
  354. if len(keyword) > 0 {
  355. db = db.Joins("join sgj_xt.xt_supplier_name on sgj_xt.xt_supplier_name.id = sgj_xt.xt_supplier_warehouse_out.supplier_id")
  356. 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")
  357. }
  358. if startime > 0 {
  359. db = db.Where("sgj_xt.xt_supplier_warehouse_cancel.record_date >= ?", startime)
  360. }
  361. if endtime > 0 {
  362. db = db.Where("sgj_xt.xt_supplier_warehouse_cancel.record_date <= ?", endtime)
  363. }
  364. if orgid > 0 {
  365. db = db.Where("sgj_xt.xt_supplier_warehouse_cancel.user_org_id = ?", orgid)
  366. }
  367. err = db.Count(&total).Offset(offset).Limit(limit).Preload("SpSupplierWarehousingCancelOrder", "status= 1 and user_org_id = ?", orgid).Find(&order).Error
  368. return order, total, err
  369. }
  370. func GetGoodReturnDetail(id int64, orgid int64) (models.VmSpSupplierWarehouseCancel, error) {
  371. cancel := models.VmSpSupplierWarehouseCancel{}
  372. db := XTReadDB().Model(&cancel).Where("status = 1")
  373. if id > 0 {
  374. db = db.Where("id = ?", id)
  375. }
  376. if orgid > 0 {
  377. db = db.Where("user_org_id = ?", orgid)
  378. }
  379. err := db.Find(&cancel).Error
  380. return cancel, err
  381. }
  382. func GetGoodReturnOrderDetail(id int64, orgid int64) (order []*models.SpSupplierWarehousingCancelOrder, err error) {
  383. db := XTReadDB().Model(&order).Where("status =1")
  384. if id > 0 {
  385. db = db.Where("warehouse_cancel_id = ?", id)
  386. }
  387. if orgid > 0 {
  388. db = db.Where("user_org_id = ?", orgid)
  389. }
  390. err = db.Find(&order).Error
  391. return order, err
  392. }
  393. func UpdateWarehouseCancelOrder(order *models.SpSupplierWarehousingCancelOrder) error {
  394. 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
  395. return err
  396. }
  397. func UpdateWarehouseCancel(id int64, cancel models.SpSupplierWarehouseCancel) error {
  398. 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
  399. return err
  400. }
  401. func GetSupplyCancelOrderById(warehouse_out_id int64, orgid int64) (*models.SpSupplierWarehouseCancel, error) {
  402. cancel := models.SpSupplierWarehouseCancel{}
  403. var err error
  404. err = XTReadDB().Where("warehouse_out_id = ? and user_org_id = ? and status = 1", warehouse_out_id, orgid).Find(&cancel).Error
  405. if err == gorm.ErrRecordNotFound {
  406. return nil, err
  407. }
  408. if err != nil {
  409. return nil, err
  410. }
  411. return &cancel, nil
  412. }
  413. func UpdateSupplyGoodOrder(id int64, out models.SpSupplierWarehouseOut) error {
  414. 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
  415. return err
  416. }
  417. func UpdateDrugSupplyWarehousingInfo(id int64, orgid int64) error {
  418. err := XTWriteDB().Model(&models.DrugWarehouseInfo{}).Where("supply_warehouse_id = ? and org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"status": 0}).Error
  419. return err
  420. }
  421. func UpdateDrugSupplyFlow(id int64, orgid int64) error {
  422. 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
  423. return err
  424. }
  425. func UpdateGoodSupplyWarehousingInfo(id int64, orgid int64) error {
  426. err := XTWriteDB().Model(&models.WarehousingInfo{}).Where("supply_warehouse_id = ? and org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"status": 0}).Error
  427. return err
  428. }
  429. func UpdateGoodSupplyFlow(id int64, orgid int64) error {
  430. err := XTWriteDB().Model(&models.WarehousingInfo{}).Where("supply_warehouse_id = ? and user_org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"status": 0}).Error
  431. return err
  432. }
  433. func GetDrugSupplyWarehousingById(id int64, orgid int64) (info []*models.DrugWarehouseInfo, err error) {
  434. err = XTReadDB().Where("supply_warehouse_id <> ? and org_id = ? and status = 1", id, orgid).Find(&info).Error
  435. return info, err
  436. }
  437. func UpdateSupplyWarehousing(id int64, orgid int64) error {
  438. err := XTWriteDB().Model(&models.DrugWarehouse{}).Where("supply_warehouse_id = ? and org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"status": 0}).Error
  439. return err
  440. }
  441. func GetGoodSupplyWarehousingById(id int64, orgid int64) (info []*models.WarehousingInfo, err error) {
  442. err = XTReadDB().Where("supply_warehouse_id <> ? and org_id = ? and status = 1", id, orgid).Find(&info).Error
  443. return info, err
  444. }
  445. func UpdateGoodWarehousing(id int64, orgid int64) error {
  446. err := XTWriteDB().Model(&models.Warehousing{}).Where("supply_warehouse_id = ? and org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"status": 0}).Error
  447. return err
  448. }
  449. func UpdateSupplyWarehousingById(id int64, orgid int64) error {
  450. err := XTWriteDB().Model(&models.SupplierWarehouseInfo{}).Where("id = ? and user_org_id =? and status = 1", id, orgid).Updates(map[string]interface{}{"is_warehouse": 1}).Error
  451. return err
  452. }
  453. func DeleteGoodOrder(id int64, orgid int64) error {
  454. err := XTWriteDB().Model(&models.SpSupplierWarehouseOut{}).Where("id = ? and status = 1 and user_org_id = ?", id, orgid).Updates(map[string]interface{}{"status": 0}).Error
  455. 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
  456. return err
  457. }
  458. func GetSupplyCancelWarehouse(id int64, orgid int64) (cancel []*models.SpSupplierWarehouseCancel, err error) {
  459. err = XTReadDB().Where("warehouse_out_id = ? and user_org_id = ? and status = 1", id, orgid).Find(&cancel).Error
  460. return cancel, err
  461. }
  462. func GetGoodOrderListById(id int64, orgid int64) (out []*models.VmSpSupplierWarehousingOutOrder, err error) {
  463. err = XTReadDB().Where("warehouse_out_id = ? and user_org_id = ? and status = 1", id, orgid).Find(&out).Error
  464. return out, err
  465. }
  466. func GetGoodCanceListById(id int64, orgid int64) (cancel []*models.VmSpSupplierWarehousingCancelOrder, err error) {
  467. err = XTReadDB().Where("warehouse_out_id = ? and user_org_id = ? and status = 1", id, orgid).Find(&cancel).Error
  468. return cancel, err
  469. }