supply_order_api_contorller.go 66KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "reflect"
  11. "strconv"
  12. "strings"
  13. "time"
  14. )
  15. type SupplyOrderApiController struct {
  16. BaseAuthAPIController
  17. }
  18. func SupplyOrderApiRegistRouters() {
  19. //获取供应商列表GetSupplyList
  20. beego.Router("/api/supply/getsupplylist", &SupplyOrderApiController{}, "get:GetSupplyList")
  21. //保存供应商及联系人(用于更改)
  22. beego.Router("/api/supply/updatesupply", &SupplyOrderApiController{}, "post:UpdateSupply")
  23. //删除单条联系人
  24. beego.Router("/api/supply/delcontactone", &SupplyOrderApiController{}, "get:DelContactOne")
  25. //获取单条供应商和涉及到的联系人记录
  26. beego.Router("/api/supply/getsupplyandcontactone", &SupplyOrderApiController{}, "get:GetSupplyAndContactOne")
  27. //获取供应商类别
  28. beego.Router("/api/supply/getsupplytype", &SupplyOrderApiController{}, "get:GetSupplyType")
  29. //删除供应商及联系人
  30. beego.Router("/api/supply/delsupply", &SupplyOrderApiController{}, "post:DelSupply")
  31. //获取供应商编码
  32. beego.Router("/api/supply/getsupplycode", &SupplyOrderApiController{}, "get:GetSupplyCode")
  33. //保存供应商及联系人(用于新增)
  34. beego.Router("/api/supply/savesupply", &SupplyOrderApiController{}, "post:SaveSupply")
  35. beego.Router("/api/supply/getinitorder", &SupplyOrderApiController{}, "get:GetInitOrder")
  36. //保存购货订单
  37. beego.Router("/api/supply/savepurchaseorder", &SupplyOrderApiController{}, "post:SavePurchaseOrder")
  38. //获取所有供应商
  39. beego.Router("/api/supply/getallsupply", &SupplyOrderApiController{}, "get:GetAllSupply")
  40. //获取供应商订单列表
  41. beego.Router("/api/supply/getallpurchaseorderlist", &SupplyOrderApiController{}, "get:GetAllPurchaseOrderList")
  42. //修改购货订单
  43. beego.Router("/api/supply/updatepurchaseorder", &SupplyOrderApiController{}, "Post:UpdatePurchaseOrder")
  44. //审核购货订单
  45. beego.Router("/api/supply/checkpurchaseorder", &SupplyOrderApiController{}, "get:UpdateSupplyWaresing")
  46. //获取购货订单详情
  47. beego.Router("/api/supply/getpurchaseorderdetail", &SupplyOrderApiController{}, "get:GetPurchaseOrderDetail")
  48. //新增购货单
  49. beego.Router("/api/supply/addgoodorder", &SupplyOrderApiController{}, "post:AddGoodOrder")
  50. //获取购货单列表
  51. beego.Router("/api/supply/getallgoodorderlist", &SupplyOrderApiController{}, "Get:GetAllGoodOderList")
  52. //修改购货订单详情
  53. beego.Router("/api/supply/getgoodorderdetail", &SupplyOrderApiController{}, "Get:GetGoodOrderDetail")
  54. //修改购货订单
  55. beego.Router("/api/supply/updategoodorder", &SupplyOrderApiController{}, "Post:UpdateGoodOrder")
  56. //删除购货订单
  57. beego.Router("/api/supply/deletepurchorder", &SupplyOrderApiController{}, "Get:DeletePurchOrder")
  58. //生成购货单的判断
  59. beego.Router("/api/supply/getallordercountlist", &SupplyOrderApiController{}, "Get:GetAllOrderCountList")
  60. // 生成购货单
  61. beego.Router("/api/supply/getpurchaseorderinfo", &SupplyOrderApiController{}, "Get:GetPurchOrderInfo")
  62. //反审核 获取关联的购货单数据
  63. beego.Router("/api/supply/getgoodorderlist", &SupplyOrderApiController{}, "Get:GetGoodOrderList")
  64. //反审核购货订单
  65. beego.Router("/api/supply/getreturnorder", &SupplyOrderApiController{}, "Get:GetReturnOrder")
  66. //判断是否全部入库
  67. beego.Router("/api/supply/getgoodordercountlist", &SupplyOrderApiController{}, "Get:GetGoodOrderCountList")
  68. }
  69. //获取供应商列表GetSupplyList
  70. func (this *SupplyOrderApiController) GetSupplyList() {
  71. ctype, _ := this.GetInt64("ctype") //供应商类别
  72. page, _ := this.GetInt64("page") //页码
  73. limit, _ := this.GetInt64("limit") //
  74. code := this.GetString("code") //供应商编号
  75. sname := this.GetString("sname") //供应商名称
  76. cname := this.GetString("cname") //联系人名子
  77. orgId := this.GetAdminUserInfo().CurrentOrgId
  78. //获取分页的数据
  79. list, total, err := service.GetSupplyList(ctype, page, limit, code, sname, cname)
  80. //获取供应商类别
  81. costClassify := "供应商类别"
  82. drugTypeParent, _ := service.GetDrugDataConfig(0, costClassify)
  83. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  84. tmpmap := make(map[int64]string) //储存供应商类别
  85. namemap := make(map[string]string) //储存首要联系人
  86. for i := 0; i < len(drugTypeList); i++ {
  87. k := int64(drugTypeList[i].Value)
  88. v := drugTypeList[i].Name
  89. tmpmap[k] = v
  90. }
  91. if err == nil {
  92. for i := 0; i < len(list); i++ {
  93. code := list[i].SupplierCode
  94. fistname, errs := service.FindName(code)
  95. if errs != nil && errs.Error() != "record not found" {
  96. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  97. return
  98. }
  99. namemap[code] = fistname.Name
  100. }
  101. type SpSupplierNameList struct { //基于SpSupplierName结构体修改的,为了方便前端取数据整合了一下,删除了几个用不到的字段,添加了联系人名字和供应商类别两个字段
  102. ID int64
  103. SupplierCode string
  104. SupplierName string
  105. SupplierType int64
  106. VatRate float64
  107. Number string
  108. Bank string
  109. BankAccount string
  110. UserOrgId int64
  111. Status int64
  112. ContactsId int64
  113. ConName string //供应商主要联系人名字
  114. TypeName string //供应商类别
  115. }
  116. //初始化该结构体
  117. tmplist := []*SpSupplierNameList{}
  118. for i := 0; i < len(list); i++ {
  119. var typename string //类别名称
  120. if list[i].SupplierType == 0 {
  121. typename = ""
  122. } else {
  123. typename = tmpmap[list[i].SupplierType]
  124. }
  125. tlist := &SpSupplierNameList{
  126. list[i].ID,
  127. list[i].SupplierCode,
  128. list[i].SupplierName,
  129. list[i].SupplierType,
  130. list[i].VatRate,
  131. list[i].Number,
  132. list[i].Bank,
  133. list[i].BankAccount,
  134. list[i].UserOrgId,
  135. list[i].Status,
  136. list[i].ContactsId,
  137. namemap[list[i].SupplierCode],
  138. typename,
  139. }
  140. tmplist = append(tmplist, tlist)
  141. }
  142. this.ServeSuccessJSON(map[string]interface{}{
  143. "list": tmplist,
  144. "total": total,
  145. })
  146. } else {
  147. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  148. }
  149. }
  150. //保存供应商及联系人(用于更改)
  151. func (this *SupplyOrderApiController) UpdateSupply() {
  152. supplierName := this.GetString("suppliername") //供应商名称
  153. if supplierName == "" {
  154. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商名称不能为空")
  155. return
  156. }
  157. supplierCode := this.GetString("suppliercode") //供应商编码
  158. if supplierCode == "" {
  159. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商编号不能为空")
  160. return
  161. }
  162. supplierid, _ := this.GetInt64("id") //供应商id
  163. if supplierid == 0 {
  164. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商id不能为空")
  165. return
  166. }
  167. //查询供应商的信息
  168. supply, err := service.GetSupplyOne(supplierid)
  169. if err != nil {
  170. utils.ErrorLog(err.Error())
  171. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  172. return
  173. }
  174. if supplierName != supply.SupplierName {
  175. //判断供应商名称是否有重复的
  176. sbool, _ := service.FindSupplierName(supplierName)
  177. if sbool { //有重复的
  178. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商名称重复")
  179. return
  180. }
  181. }
  182. if supplierCode != supply.SupplierCode {
  183. //判断供应商编号是否有重复的
  184. codebool, _ := service.FindSupplierCode(supplierCode)
  185. if codebool {
  186. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商编号重复")
  187. return
  188. }
  189. }
  190. supplierType, _ := this.GetInt64("suppliertype") //供应商类别
  191. vatRate, _ := this.GetFloat("vatrate") //增值税税率
  192. number := this.GetString("number") //纳税人识别号
  193. bank := this.GetString("bank") //开户银行
  194. bankAccount := this.GetString("bankAccount") //银行账号
  195. orgId := this.GetAdminUserInfo().CurrentOrgId
  196. //contacts := this.Get("contacts")//联系人
  197. dataBody := make(map[string]interface{}, 0)
  198. err = json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  199. if err != nil {
  200. utils.ErrorLog(err.Error())
  201. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  202. return
  203. }
  204. //保存联系人
  205. if dataBody["contacts"] != nil && reflect.TypeOf(dataBody["contacts"]).String() == "[]interface {}" {
  206. thisStockIn, _ := dataBody["contacts"].([]interface{})
  207. if len(thisStockIn) > 0 {
  208. if len(thisStockIn) == 1 {
  209. for _, item := range thisStockIn {
  210. items := item.(map[string]interface{})
  211. items["IsFirst"] = 1
  212. }
  213. }
  214. tmodify := this.GetAdminUserInfo().AdminUser.Id
  215. err = service.UpdateSupplyAndContact(thisStockIn, supplierid, orgId, supplierType, tmodify, supplierCode, supplierName, number, bank, bankAccount, vatRate)
  216. if err != nil {
  217. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  218. return
  219. }
  220. } else {
  221. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "联系人不能为空")
  222. return
  223. }
  224. }
  225. this.ServeSuccessJSON(map[string]interface{}{
  226. "list": "保存成功",
  227. })
  228. return
  229. }
  230. //获取单条供应商和涉及到的联系人记录
  231. func (this *SupplyOrderApiController) GetSupplyAndContactOne() {
  232. id, _ := this.GetInt64("id")
  233. if id == 0 {
  234. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商id不能为空")
  235. return
  236. }
  237. supply, contact, err := service.GetSupplyAndContactOne(id)
  238. if err != nil {
  239. utils.ErrorLog(err.Error())
  240. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  241. return
  242. }
  243. this.ServeSuccessJSON(map[string]interface{}{
  244. "supply": supply,
  245. "contact": contact,
  246. })
  247. return
  248. }
  249. //获取供应商类别
  250. func (this *SupplyOrderApiController) GetSupplyType() {
  251. orgId := this.GetAdminUserInfo().CurrentOrgId
  252. costClassify := "供应商类别"
  253. drugTypeParent, _ := service.GetDrugDataConfig(0, costClassify)
  254. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  255. this.ServeSuccessJSON(map[string]interface{}{
  256. "list": drugTypeList,
  257. })
  258. return
  259. }
  260. //删除供应商及联系人
  261. func (this *SupplyOrderApiController) DelSupply() {
  262. //拿到供应商的id
  263. suid, _ := this.GetInt64("id")
  264. if suid == 0 {
  265. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商id不能为空")
  266. return
  267. }
  268. supply := models.SpSupplierName{
  269. ID: suid,
  270. }
  271. err := service.DelSupply(supply)
  272. if err != nil {
  273. utils.ErrorLog(err.Error())
  274. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  275. return
  276. }
  277. this.ServeSuccessJSON(map[string]interface{}{
  278. "list": "删除成功",
  279. })
  280. return
  281. }
  282. //删除单条联系人记录
  283. func (this *SupplyOrderApiController) DelContactOne() {
  284. id, _ := this.GetInt64("id")
  285. if id == 0 {
  286. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "联系人id不能为空")
  287. return
  288. }
  289. err := service.DelContactOne(id)
  290. if err != nil {
  291. utils.ErrorLog(err.Error())
  292. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  293. return
  294. }
  295. this.ServeSuccessJSON(map[string]interface{}{
  296. "list": "删除成功",
  297. })
  298. return
  299. }
  300. //获取供应商编码
  301. func (this *SupplyOrderApiController) GetSupplyCode() {
  302. supply, err := service.GetSuppliyCode()
  303. if err != nil {
  304. return
  305. }
  306. if len(supply) == 0 { //如果数据库中没有gys类型的编码则设置默认值
  307. //supply[0].SupplierCode ="gys001"
  308. supply = []*models.SpSupplierName{
  309. {
  310. SupplierCode: "gys001",
  311. },
  312. }
  313. } else { //获取数据库中最大的编码值,并加一
  314. tmp := supply[0].SupplierCode
  315. tmp = tmp[3:]
  316. var code int
  317. code, err = strconv.Atoi(tmp)
  318. code++
  319. tmp = strconv.Itoa(code)
  320. for len(tmp) < 3 {
  321. tmp = "0" + tmp
  322. }
  323. tmp = "gys" + tmp
  324. supply[0].SupplierCode = tmp
  325. }
  326. this.ServeSuccessJSON(map[string]interface{}{
  327. "supplycode": supply,
  328. })
  329. return
  330. }
  331. //保存供应商
  332. func (this *SupplyOrderApiController) SaveSupply() {
  333. supplierName := this.GetString("suppliername") //供应商名称
  334. if supplierName == "" {
  335. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商名称不能为空")
  336. return
  337. }
  338. //判断供应商名称是否有重复的
  339. sbool, _ := service.FindSupplierName(supplierName)
  340. if sbool { //有重复的
  341. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商名称重复")
  342. return
  343. }
  344. supplierCode := this.GetString("suppliercode") //供应商编码
  345. if supplierCode == "" {
  346. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商编号不能为空")
  347. return
  348. }
  349. //判断供应商编号是否有重复的
  350. codebool, _ := service.FindSupplierCode(supplierCode)
  351. if codebool {
  352. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商编号重复")
  353. return
  354. }
  355. supplierType, _ := this.GetInt64("suppliertype") //供应商类别
  356. vatRate, _ := this.GetFloat("vatrate") //增值税税率
  357. number := this.GetString("number") //纳税人识别号
  358. bank := this.GetString("bank") //开户银行
  359. bankAccount := this.GetString("bankAccount") //银行账号
  360. orgId := this.GetAdminUserInfo().CurrentOrgId
  361. //contacts := this.Get("contacts")//联系人
  362. dataBody := make(map[string]interface{}, 0)
  363. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  364. if err != nil {
  365. utils.ErrorLog(err.Error())
  366. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  367. return
  368. }
  369. //保存联系人
  370. if dataBody["contacts"] != nil && reflect.TypeOf(dataBody["contacts"]).String() == "[]interface {}" {
  371. thisStockIn, _ := dataBody["contacts"].([]interface{})
  372. if len(thisStockIn) > 0 {
  373. if len(thisStockIn) == 1 {
  374. for _, item := range thisStockIn {
  375. items := item.(map[string]interface{})
  376. items["IsFirst"] = 1
  377. }
  378. }
  379. tcreater := this.GetAdminUserInfo().AdminUser.Id
  380. err = service.SaveSupplyAndContact(thisStockIn, orgId, supplierType, tcreater, supplierCode, supplierName, number, bank, bankAccount, vatRate)
  381. if err != nil {
  382. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  383. return
  384. }
  385. } else {
  386. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "联系人不能为空")
  387. return
  388. }
  389. }
  390. this.ServeSuccessJSON(map[string]interface{}{
  391. "list": "保存成功",
  392. })
  393. return
  394. }
  395. func (this *SupplyOrderApiController) GetInitOrder() {
  396. orgId := this.GetAdminUserInfo().CurrentOrgId
  397. //获取药品库数据
  398. baseList, _ := service.GetSupplyDrugList(orgId)
  399. goodList, _ := service.GetSupplyGoodList(orgId)
  400. manufactuerList, _ := service.GetAllManufacturerList(orgId)
  401. goodTypeList, _ := service.GetAllGoodType(orgId)
  402. supplyList, _ := service.GetSupplierList(orgId)
  403. var drugType = "药品类型"
  404. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  405. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  406. this.ServeSuccessJSON(map[string]interface{}{
  407. "drugList": baseList,
  408. "goodList": goodList,
  409. "manufactuerList": manufactuerList,
  410. "goodTypeList": goodTypeList,
  411. "drugTypeList": drugTypeList,
  412. "supplyList": supplyList,
  413. })
  414. return
  415. }
  416. func (this *SupplyOrderApiController) SavePurchaseOrder() {
  417. supplier_id, _ := this.GetInt64("supplier_name")
  418. start_time := this.GetString("start_time")
  419. end_time := this.GetString("end_time")
  420. timeLayout := "2006-01-02"
  421. loc, _ := time.LoadLocation("Local")
  422. var startTime int64
  423. if len(start_time) > 0 {
  424. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  425. if err != nil {
  426. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  427. return
  428. }
  429. startTime = theTime.Unix()
  430. }
  431. var endTime int64
  432. if len(end_time) > 0 {
  433. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  434. if err != nil {
  435. utils.ErrorLog(err.Error())
  436. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  437. return
  438. }
  439. endTime = theTime.Unix()
  440. }
  441. rate_of_concession := this.GetString("rate_of_concession")
  442. rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
  443. discount_amount := this.GetString("discount_amount")
  444. discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
  445. fmt.Println("supplier_id23323232323232", supplier_id, startTime, endTime, rate_of_concession, rate_of_concession_float, discount_amount, discount_amount_float)
  446. dataBody := make(map[string]interface{}, 0)
  447. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  448. if err != nil {
  449. utils.ErrorLog(err.Error())
  450. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  451. return
  452. }
  453. //生成购货订单
  454. timeStr := time.Now().Format("2006-01-02")
  455. timeArr := strings.Split(timeStr, "-")
  456. orgId := this.GetAdminUserInfo().CurrentOrgId
  457. total, _ := service.FindAllSupplyOrder(orgId)
  458. total = total + 1
  459. warehousing_order := "CGDD" + timeArr[0] + timeArr[1] + timeArr[2] + "00" + strconv.FormatInt(total, 10)
  460. recordDateStr := time.Now().Format("2006-01-02")
  461. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  462. fmt.Scan("parseDateErr", parseDateErr)
  463. record_date := recordDate.Unix()
  464. info := models.SupplierWarehouseInfo{
  465. Number: warehousing_order,
  466. UserOrgId: orgId,
  467. Creater: this.GetAdminUserInfo().AdminUser.Id,
  468. Ctime: time.Now().Unix(),
  469. Mtime: 0,
  470. Status: 1,
  471. RecordDate: record_date,
  472. IsCheck: 2,
  473. RateOfConcession: rate_of_concession_float,
  474. DiscountAmount: discount_amount_float,
  475. DocumentDate: startTime,
  476. DeliveryDate: endTime,
  477. SupplierId: supplier_id,
  478. IsWarehouse: 2,
  479. }
  480. err = service.CreateSupplyWarehouse(info)
  481. warehouseInfo, _ := service.FindLastSupplyWarehouseInfo(orgId)
  482. var warehousingInfo []*models.SupplierWarehousingInfoOrder
  483. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  484. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  485. if len(thisStockIn) > 0 {
  486. for _, item := range thisStockIn {
  487. items := item.(map[string]interface{})
  488. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  489. utils.ErrorLog("project_id")
  490. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  491. return
  492. }
  493. project_id := int64(items["project_id"].(float64))
  494. if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
  495. utils.ErrorLog("supply_count")
  496. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  497. return
  498. }
  499. supply_count := int64(items["supply_count"].(float64))
  500. if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
  501. utils.ErrorLog("supply_license_number")
  502. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  503. return
  504. }
  505. supply_license_number := items["supply_license_number"].(string)
  506. if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
  507. utils.ErrorLog("supply_price")
  508. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  509. return
  510. }
  511. supply_price := items["supply_price"].(string)
  512. supply_price_float, _ := strconv.ParseFloat(supply_price, 64)
  513. if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
  514. utils.ErrorLog("supply_remake")
  515. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  516. return
  517. }
  518. supply_remake := items["supply_remake"].(string)
  519. if items["supply_total_price"] == nil || reflect.TypeOf(items["supply_total_price"]).String() != "string" {
  520. utils.ErrorLog("supply_total_price")
  521. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  522. return
  523. }
  524. supply_total_price := items["supply_total_price"].(string)
  525. supply_total_price_float, _ := strconv.ParseFloat(supply_total_price, 64)
  526. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  527. utils.ErrorLog("type")
  528. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  529. return
  530. }
  531. is_source := int64(items["type"].(float64))
  532. if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
  533. utils.ErrorLog("supply_type")
  534. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  535. return
  536. }
  537. supply_type := items["supply_type"].(string)
  538. if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
  539. utils.ErrorLog("supply_specification_name")
  540. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  541. return
  542. }
  543. supply_specification_name := items["supply_specification_name"].(string)
  544. if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
  545. utils.ErrorLog("supply_total")
  546. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  547. return
  548. }
  549. supply_total := items["supply_total"].(string)
  550. if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
  551. utils.ErrorLog("supply_manufacturer")
  552. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  553. return
  554. }
  555. supply_manufacturer := items["supply_manufacturer"].(string)
  556. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  557. utils.ErrorLog("name")
  558. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  559. return
  560. }
  561. name := items["name"].(string)
  562. if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
  563. utils.ErrorLog("supply_unit")
  564. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  565. return
  566. }
  567. supply_unit := items["supply_unit"].(string)
  568. if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
  569. utils.ErrorLog("manufacturer_id")
  570. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  571. return
  572. }
  573. manufacturer_id := int64(items["manufacturer_id"].(float64))
  574. order := models.SupplierWarehousingInfoOrder{
  575. OrderNumber: warehousing_order,
  576. IsSource: is_source,
  577. Count: supply_count,
  578. Price: supply_price_float,
  579. Amount: supply_total_price_float,
  580. Remark: supply_remake,
  581. UserOrgId: orgId,
  582. Ctime: time.Now().Unix(),
  583. Status: 1,
  584. Mtime: 0,
  585. WarehousingId: warehouseInfo.ID,
  586. ProjectId: project_id,
  587. SupplyLicenseNumber: supply_license_number,
  588. SupplyType: supply_type,
  589. SupplySpecificationName: supply_specification_name,
  590. SupplyTotal: supply_total,
  591. SupplyManufacturer: supply_manufacturer,
  592. Name: name,
  593. SupplyUnit: supply_unit,
  594. ManufacturerId: manufacturer_id,
  595. }
  596. warehousingInfo = append(warehousingInfo, &order)
  597. }
  598. }
  599. }
  600. for _, item := range warehousingInfo {
  601. err = service.CreateSupplyWarehousingOrder(item)
  602. }
  603. //查询
  604. orderInfo, err := service.GetSupplyWarehousingOrderInfo(warehouseInfo.ID)
  605. if err == nil {
  606. this.ServeSuccessJSON(map[string]interface{}{
  607. "order": warehousingInfo,
  608. "warehouseInfo": warehouseInfo,
  609. "orderInfo": orderInfo,
  610. })
  611. } else {
  612. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  613. }
  614. }
  615. func (this *SupplyOrderApiController) GetAllSupply() {
  616. orgId := this.GetAdminUserInfo().CurrentOrgId
  617. appId := this.GetAdminUserInfo().CurrentAppId
  618. supplyList, err := service.GetSupplierList(orgId)
  619. doctorList, err := service.GetAllDoctor(orgId, appId)
  620. if err == nil {
  621. this.ServeSuccessJSON(map[string]interface{}{
  622. "supplyList": supplyList,
  623. "doctorList": doctorList,
  624. })
  625. } else {
  626. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  627. }
  628. }
  629. func (this *SupplyOrderApiController) GetAllPurchaseOrderList() {
  630. check_id, _ := this.GetInt64("check_id")
  631. start_time := this.GetString("start_time")
  632. end_time := this.GetString("end_time")
  633. timeLayout := "2006-01-02"
  634. loc, _ := time.LoadLocation("Local")
  635. var startTime int64
  636. if len(start_time) > 0 {
  637. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  638. if err != nil {
  639. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  640. return
  641. }
  642. startTime = theTime.Unix()
  643. }
  644. var endTime int64
  645. if len(end_time) > 0 {
  646. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  647. if err != nil {
  648. utils.ErrorLog(err.Error())
  649. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  650. return
  651. }
  652. endTime = theTime.Unix()
  653. }
  654. keyword := this.GetString("keyword")
  655. page, _ := this.GetInt64("page")
  656. limit, _ := this.GetInt64("limit")
  657. orgId := this.GetAdminUserInfo().CurrentOrgId
  658. list, total, err := service.GetAllPurchaseOrderList(check_id, startTime, endTime, keyword, page, limit, orgId)
  659. if err == nil {
  660. this.ServeSuccessJSON(map[string]interface{}{
  661. "list": list,
  662. "total": total,
  663. })
  664. } else {
  665. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  666. }
  667. }
  668. func (this *SupplyOrderApiController) UpdatePurchaseOrder() {
  669. supplier_id, _ := this.GetInt64("supplier_name")
  670. start_time := this.GetString("start_time")
  671. end_time := this.GetString("end_time")
  672. timeLayout := "2006-01-02"
  673. loc, _ := time.LoadLocation("Local")
  674. var startTime int64
  675. if len(start_time) > 0 {
  676. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  677. if err != nil {
  678. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  679. return
  680. }
  681. startTime = theTime.Unix()
  682. }
  683. var endTime int64
  684. if len(end_time) > 0 {
  685. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  686. if err != nil {
  687. utils.ErrorLog(err.Error())
  688. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  689. return
  690. }
  691. endTime = theTime.Unix()
  692. }
  693. rate_of_concession := this.GetString("rate_of_concession")
  694. rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
  695. discount_amount := this.GetString("discount_amount")
  696. discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
  697. warehousing_id, _ := this.GetInt64("id")
  698. number := this.GetString("number")
  699. //fmt.Println("supplier_id23323232323232", supplier_id, startTime, endTime, rate_of_concession, rate_of_concession_float, discount_amount, discount_amount_float)
  700. orgId := this.GetAdminUserInfo().CurrentOrgId
  701. info := models.SupplierWarehouseInfo{
  702. RateOfConcession: rate_of_concession_float,
  703. DiscountAmount: discount_amount_float,
  704. DocumentDate: startTime,
  705. DeliveryDate: endTime,
  706. SupplierId: supplier_id,
  707. Mtime: time.Now().Unix(),
  708. }
  709. service.ModefySupplyWarehouseInfo(warehousing_id, info)
  710. dataBody := make(map[string]interface{}, 0)
  711. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  712. if err != nil {
  713. utils.ErrorLog(err.Error())
  714. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  715. return
  716. }
  717. var warehousingInfo []*models.SupplierWarehousingInfoOrder
  718. var updateWarehousingInfo []*models.SupplierWarehousingInfoOrder
  719. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  720. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  721. if len(thisStockIn) > 0 {
  722. for _, item := range thisStockIn {
  723. items := item.(map[string]interface{})
  724. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  725. utils.ErrorLog("id")
  726. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  727. return
  728. }
  729. id := int64(items["id"].(float64))
  730. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  731. utils.ErrorLog("project_id")
  732. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  733. return
  734. }
  735. project_id := int64(items["project_id"].(float64))
  736. if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
  737. utils.ErrorLog("supply_count")
  738. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  739. return
  740. }
  741. supply_count := int64(items["supply_count"].(float64))
  742. if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
  743. utils.ErrorLog("supply_license_number")
  744. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  745. return
  746. }
  747. supply_license_number := items["supply_license_number"].(string)
  748. if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
  749. utils.ErrorLog("supply_price")
  750. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  751. return
  752. }
  753. supply_price := items["supply_price"].(string)
  754. supply_price_float, _ := strconv.ParseFloat(supply_price, 64)
  755. if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
  756. utils.ErrorLog("supply_remake")
  757. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  758. return
  759. }
  760. supply_remake := items["supply_remake"].(string)
  761. if items["supply_total_price"] == nil || reflect.TypeOf(items["supply_total_price"]).String() != "string" {
  762. utils.ErrorLog("supply_total_price")
  763. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  764. return
  765. }
  766. supply_total_price := items["supply_total_price"].(string)
  767. supply_total_price_float, _ := strconv.ParseFloat(supply_total_price, 64)
  768. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  769. utils.ErrorLog("type")
  770. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  771. return
  772. }
  773. is_source := int64(items["type"].(float64))
  774. if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
  775. utils.ErrorLog("supply_type")
  776. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  777. return
  778. }
  779. supply_type := items["supply_type"].(string)
  780. if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
  781. utils.ErrorLog("supply_specification_name")
  782. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  783. return
  784. }
  785. supply_specification_name := items["supply_specification_name"].(string)
  786. if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
  787. utils.ErrorLog("supply_total")
  788. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  789. return
  790. }
  791. supply_total := items["supply_total"].(string)
  792. if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
  793. utils.ErrorLog("supply_manufacturer")
  794. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  795. return
  796. }
  797. supply_manufacturer := items["supply_manufacturer"].(string)
  798. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  799. utils.ErrorLog("name")
  800. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  801. return
  802. }
  803. name := items["name"].(string)
  804. if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
  805. utils.ErrorLog("supply_unit")
  806. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  807. return
  808. }
  809. supply_unit := items["supply_unit"].(string)
  810. if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
  811. utils.ErrorLog("manufacturer_id")
  812. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  813. return
  814. }
  815. manufacturer_id := int64(items["manufacturer_id"].(float64))
  816. if id > 0 {
  817. order := models.SupplierWarehousingInfoOrder{
  818. ID: id,
  819. IsSource: is_source,
  820. Count: supply_count,
  821. Price: supply_price_float,
  822. Amount: supply_total_price_float,
  823. Remark: supply_remake,
  824. Ctime: time.Now().Unix(),
  825. Status: 1,
  826. Mtime: 0,
  827. ProjectId: project_id,
  828. SupplyLicenseNumber: supply_license_number,
  829. SupplyType: supply_type,
  830. SupplySpecificationName: supply_specification_name,
  831. SupplyTotal: supply_total,
  832. SupplyManufacturer: supply_manufacturer,
  833. Name: name,
  834. SupplyUnit: supply_unit,
  835. ManufacturerId: manufacturer_id,
  836. }
  837. updateWarehousingInfo = append(updateWarehousingInfo, &order)
  838. }
  839. if id == 0 {
  840. order := models.SupplierWarehousingInfoOrder{
  841. OrderNumber: number,
  842. IsSource: is_source,
  843. Count: supply_count,
  844. Price: supply_price_float,
  845. Amount: supply_total_price_float,
  846. Remark: supply_remake,
  847. UserOrgId: orgId,
  848. Ctime: time.Now().Unix(),
  849. Status: 1,
  850. Mtime: 0,
  851. WarehousingId: warehousing_id,
  852. ProjectId: project_id,
  853. SupplyLicenseNumber: supply_license_number,
  854. SupplyType: supply_type,
  855. SupplySpecificationName: supply_specification_name,
  856. SupplyTotal: supply_total,
  857. SupplyManufacturer: supply_manufacturer,
  858. Name: name,
  859. SupplyUnit: supply_unit,
  860. ManufacturerId: manufacturer_id,
  861. }
  862. warehousingInfo = append(warehousingInfo, &order)
  863. }
  864. }
  865. }
  866. if len(warehousingInfo) > 0 {
  867. for _, item := range warehousingInfo {
  868. service.CreateSupplyWarehousingOrder(item)
  869. }
  870. }
  871. if len(updateWarehousingInfo) > 0 {
  872. for _, item := range updateWarehousingInfo {
  873. service.ModifySupplyWarehouseOrder(item)
  874. }
  875. }
  876. this.ServeSuccessJSON(map[string]interface{}{
  877. "warehousingInfo": warehousingInfo,
  878. })
  879. }
  880. }
  881. func (this *SupplyOrderApiController) UpdateSupplyWaresing() {
  882. id, _ := this.GetInt64("id")
  883. recordDateStr := time.Now().Format("2006-01-02")
  884. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  885. record_date := recordDate.Unix()
  886. checker := this.GetAdminUserInfo().AdminUser.Id
  887. info := models.SupplierWarehouseInfo{
  888. Mtime: time.Now().Unix(),
  889. Status: 1,
  890. IsCheck: 1,
  891. Checker: checker,
  892. CheckTime: record_date,
  893. }
  894. parseDateErr := service.UpdateSupplyWaresing(id, info)
  895. if parseDateErr == nil {
  896. this.ServeSuccessJSON(map[string]interface{}{
  897. "info": info,
  898. })
  899. } else {
  900. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  901. }
  902. }
  903. func (this *SupplyOrderApiController) GetPurchaseOrderDetail() {
  904. id, _ := this.GetInt64("id")
  905. info, _ := service.GetPurchaseOrderDetail(id)
  906. //查询
  907. orderInfo, err := service.GetSupplyWarehousingOrderInfo(id)
  908. orgId := this.GetAdminUserInfo().CurrentOrgId
  909. supplyList, _ := service.GetSupplierList(orgId)
  910. //获取药品库数据
  911. baseList, _ := service.GetSupplyDrugList(orgId)
  912. goodList, _ := service.GetSupplyGoodList(orgId)
  913. if err == nil {
  914. this.ServeSuccessJSON(map[string]interface{}{
  915. "info": info,
  916. "orderInfo": orderInfo,
  917. "supplyList": supplyList,
  918. "baseList": baseList,
  919. "goodList": goodList,
  920. })
  921. } else {
  922. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  923. }
  924. }
  925. func (this *SupplyOrderApiController) AddGoodOrder() {
  926. supplier_id, _ := this.GetInt64("supplier_id")
  927. start_time := this.GetString("start")
  928. timeLayout := "2006-01-02"
  929. loc, _ := time.LoadLocation("Local")
  930. var startTime int64
  931. if len(start_time) > 0 {
  932. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  933. if err != nil {
  934. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  935. return
  936. }
  937. startTime = theTime.Unix()
  938. }
  939. arrerage := this.GetString("arrerage")
  940. arrerage_float, _ := strconv.ParseFloat(arrerage, 64)
  941. payment := this.GetString("payment")
  942. payment_float, _ := strconv.ParseFloat(payment, 64)
  943. warehousing_id, _ := this.GetInt64("warehousing_id")
  944. number := this.GetString("number")
  945. rate_of_concession := this.GetString("rate_of_concession")
  946. rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
  947. discount_amount := this.GetString("discount_amount")
  948. discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
  949. fmt.Println(supplier_id, startTime, arrerage, payment, warehousing_id, number, rate_of_concession, discount_amount)
  950. orgId := this.GetAdminUserInfo().CurrentOrgId
  951. creater := this.GetAdminUserInfo().AdminUser.Id
  952. //生成购货单
  953. timeStr := time.Now().Format("2006-01-02")
  954. timeArr := strings.Split(timeStr, "-")
  955. total, _ := service.FindAllSupplyWarehouseOutOrder(orgId)
  956. total = total + 1
  957. warehousing_order := "CG" + timeArr[0] + timeArr[1] + timeArr[2] + "00" + strconv.FormatInt(total, 10)
  958. recordDateStr := time.Now().Format("2006-01-02")
  959. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  960. warehouse_out := models.SpSupplierWarehouseOut{
  961. Number: number,
  962. UserOrgId: orgId,
  963. Creater: creater,
  964. Ctime: time.Now().Unix(),
  965. Mtime: 0,
  966. Status: 1,
  967. RecordDate: recordDate.Unix(),
  968. IsCheck: 2,
  969. WarehousingId: warehousing_id,
  970. GoodNumber: warehousing_order,
  971. Arrearage: arrerage_float,
  972. Payment: payment_float,
  973. RateOfConcession: rate_of_concession_float,
  974. DiscountAmount: discount_amount_float,
  975. DocumentDate: startTime,
  976. SupplierId: supplier_id,
  977. Checker: 0,
  978. CheckTime: 0,
  979. }
  980. service.CreateSupplyWarehouseOut(warehouse_out)
  981. //获取最后一条
  982. warehouseOut, _ := service.FindSupplyWarehouseOutById(orgId)
  983. dataBody := make(map[string]interface{}, 0)
  984. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  985. if err != nil {
  986. utils.ErrorLog(err.Error())
  987. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  988. return
  989. }
  990. var warehousingOut []*models.SpSupplierWarehousingOutOrder
  991. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  992. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  993. if len(thisStockIn) > 0 {
  994. for _, item := range thisStockIn {
  995. items := item.(map[string]interface{})
  996. if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
  997. utils.ErrorLog("supply_count")
  998. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  999. return
  1000. }
  1001. supply_count := int64(items["supply_count"].(float64))
  1002. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1003. utils.ErrorLog("id")
  1004. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1005. return
  1006. }
  1007. id := int64(items["id"].(float64))
  1008. if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
  1009. utils.ErrorLog("manufacturer_id")
  1010. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1011. return
  1012. }
  1013. manufacturer_id := int64(items["manufacturer_id"].(float64))
  1014. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  1015. utils.ErrorLog("name")
  1016. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1017. return
  1018. }
  1019. name := items["name"].(string)
  1020. if items["order_number"] == nil || reflect.TypeOf(items["order_number"]).String() != "string" {
  1021. utils.ErrorLog("order_number")
  1022. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1023. return
  1024. }
  1025. order_number := items["order_number"].(string)
  1026. if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
  1027. utils.ErrorLog("supply_price")
  1028. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1029. return
  1030. }
  1031. supply_price := items["supply_price"].(string)
  1032. price_float, _ := strconv.ParseFloat(supply_price, 64)
  1033. if items["supply_total_price"] == nil || reflect.TypeOf(items["supply_total_price"]).String() != "string" {
  1034. utils.ErrorLog("supply_total_price")
  1035. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1036. return
  1037. }
  1038. supply_total_price := items["supply_total_price"].(string)
  1039. supply_total_price_float, _ := strconv.ParseFloat(supply_total_price, 64)
  1040. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  1041. utils.ErrorLog("project_id")
  1042. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1043. return
  1044. }
  1045. project_id := int64(items["project_id"].(float64))
  1046. if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
  1047. utils.ErrorLog("supply_remake")
  1048. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1049. return
  1050. }
  1051. supply_remake := items["supply_remake"].(string)
  1052. if items["supply_batch_number"] == nil || reflect.TypeOf(items["supply_batch_number"]).String() != "string" {
  1053. utils.ErrorLog("supply_batch_number")
  1054. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1055. return
  1056. }
  1057. supply_batch_number := items["supply_batch_number"].(string)
  1058. var supply_expiry_date_time int64
  1059. if items["supply_expiry_date"] == nil || reflect.TypeOf(items["supply_expiry_date"]).String() != "string" {
  1060. utils.ErrorLog("supply_expiry_date")
  1061. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1062. return
  1063. }
  1064. supply_expiry_date := items["supply_expiry_date"].(string)
  1065. if len(supply_expiry_date) > 0 {
  1066. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", supply_expiry_date+" 00:00:00", loc)
  1067. if err != nil {
  1068. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1069. return
  1070. }
  1071. supply_expiry_date_time = theTime.Unix()
  1072. }
  1073. if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
  1074. utils.ErrorLog("supply_license_number")
  1075. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1076. return
  1077. }
  1078. supply_license_number := items["supply_license_number"].(string)
  1079. var supply_product_date_time int64
  1080. if items["supply_product_date"] == nil || reflect.TypeOf(items["supply_product_date"]).String() != "string" {
  1081. utils.ErrorLog("supply_product_date")
  1082. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1083. return
  1084. }
  1085. supply_product_date := items["supply_product_date"].(string)
  1086. if len(supply_product_date) > 0 {
  1087. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", supply_product_date+" 00:00:00", loc)
  1088. if err != nil {
  1089. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1090. return
  1091. }
  1092. supply_product_date_time = theTime.Unix()
  1093. }
  1094. if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
  1095. utils.ErrorLog("supply_specification_name")
  1096. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1097. return
  1098. }
  1099. supply_specification_name := items["supply_specification_name"].(string)
  1100. if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
  1101. utils.ErrorLog("supply_total")
  1102. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1103. return
  1104. }
  1105. supply_total := items["supply_total"].(string)
  1106. if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
  1107. utils.ErrorLog("supply_type")
  1108. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1109. return
  1110. }
  1111. supply_type := items["supply_type"].(string)
  1112. if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
  1113. utils.ErrorLog("supply_unit")
  1114. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1115. return
  1116. }
  1117. supply_unit := items["supply_unit"].(string)
  1118. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1119. utils.ErrorLog("type")
  1120. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1121. return
  1122. }
  1123. is_source := int64(items["type"].(float64))
  1124. if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
  1125. utils.ErrorLog("supply_manufacturer")
  1126. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1127. return
  1128. }
  1129. supply_manufacturer := items["supply_manufacturer"].(string)
  1130. order := models.SpSupplierWarehousingOutOrder{
  1131. OrderNumber: order_number,
  1132. ProjectId: project_id,
  1133. IsSource: is_source,
  1134. Count: supply_count,
  1135. Amount: supply_total_price_float,
  1136. Price: price_float,
  1137. Remark: supply_remake,
  1138. IsCheck: 2,
  1139. UserOrgId: orgId,
  1140. Status: 1,
  1141. Ctime: time.Now().Unix(),
  1142. Mtime: 0,
  1143. WarehouseOutId: warehouseOut.ID,
  1144. Type: 1,
  1145. SupplyBatchNumber: supply_batch_number,
  1146. SupplyProductDate: supply_product_date_time,
  1147. SupplyExpiryDate: supply_expiry_date_time,
  1148. WarehousingId: warehousing_id,
  1149. WarehouseInfoId: id,
  1150. SupplyType: supply_type,
  1151. SupplyUnit: supply_unit,
  1152. SupplyTotal: supply_total,
  1153. SupplySpecificationName: supply_specification_name,
  1154. SupplyLicenseNumber: supply_license_number,
  1155. Name: name,
  1156. ManufacturerId: manufacturer_id,
  1157. GoodNumber: warehouseOut.GoodNumber,
  1158. SupplyManufacturer: supply_manufacturer,
  1159. }
  1160. warehousingOut = append(warehousingOut, &order)
  1161. }
  1162. }
  1163. }
  1164. for _, item := range warehousingOut {
  1165. //如果是手动新增的,type 等于2
  1166. if item.WarehouseInfoId == 0 {
  1167. item.Type = 2
  1168. }
  1169. err = service.CreateSupplyWarehousOutOrder(item)
  1170. }
  1171. list, parseDateErr := service.GetSupplyWarehouseOutById(warehouseOut.ID, orgId)
  1172. if parseDateErr == nil {
  1173. this.ServeSuccessJSON(map[string]interface{}{
  1174. "list": list,
  1175. "warehouseOut": warehouseOut,
  1176. })
  1177. } else {
  1178. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1179. }
  1180. }
  1181. func (this *SupplyOrderApiController) GetAllGoodOderList() {
  1182. check_id, _ := this.GetInt64("check_id")
  1183. start_time := this.GetString("start_time")
  1184. end_time := this.GetString("end_time")
  1185. keyword := this.GetString("keyword")
  1186. page, _ := this.GetInt64("page")
  1187. limit, _ := this.GetInt64("limit")
  1188. timeLayout := "2006-01-02"
  1189. loc, _ := time.LoadLocation("Local")
  1190. var startTime int64
  1191. if len(start_time) > 0 {
  1192. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1193. if err != nil {
  1194. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1195. return
  1196. }
  1197. startTime = theTime.Unix()
  1198. }
  1199. var endTime int64
  1200. if len(end_time) > 0 {
  1201. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  1202. if err != nil {
  1203. utils.ErrorLog(err.Error())
  1204. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1205. return
  1206. }
  1207. endTime = theTime.Unix()
  1208. }
  1209. orgId := this.GetAdminUserInfo().CurrentOrgId
  1210. list, total, err := service.GetAllGoodOderList(check_id, keyword, page, limit, startTime, endTime, orgId)
  1211. if err == nil {
  1212. this.ServeSuccessJSON(map[string]interface{}{
  1213. "list": list,
  1214. "total": total,
  1215. })
  1216. } else {
  1217. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1218. }
  1219. }
  1220. func (this *SupplyOrderApiController) GetGoodOrderDetail() {
  1221. id, _ := this.GetInt64("id")
  1222. orgId := this.GetAdminUserInfo().CurrentOrgId
  1223. out, err := service.GetGoodOrderDetail(id, orgId)
  1224. list, _ := service.GetSupplyWarehouseOutById(id, orgId)
  1225. drugList, _ := service.GetSupplyDrugList(orgId)
  1226. goodList, _ := service.GetSupplyGoodList(orgId)
  1227. if err == nil {
  1228. this.ServeSuccessJSON(map[string]interface{}{
  1229. "out": out,
  1230. "list": list,
  1231. "goodList": goodList,
  1232. "drugList": drugList,
  1233. })
  1234. } else {
  1235. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1236. }
  1237. }
  1238. func (this *SupplyOrderApiController) UpdateGoodOrder() {
  1239. supplier_id, _ := this.GetInt64("supplier_id")
  1240. start_time := this.GetString("start")
  1241. timeLayout := "2006-01-02"
  1242. loc, _ := time.LoadLocation("Local")
  1243. var startTime int64
  1244. if len(start_time) > 0 {
  1245. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1246. if err != nil {
  1247. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1248. return
  1249. }
  1250. startTime = theTime.Unix()
  1251. }
  1252. arrerage := this.GetString("arrerage")
  1253. arrerage_float, _ := strconv.ParseFloat(arrerage, 64)
  1254. payment := this.GetString("payment")
  1255. payment_float, _ := strconv.ParseFloat(payment, 64)
  1256. warehose_out_id, _ := this.GetInt64("warehose_out_id")
  1257. number := this.GetString("number")
  1258. rate_of_concession := this.GetString("rate_of_concession")
  1259. rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
  1260. discount_amount := this.GetString("discount_amount")
  1261. discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
  1262. good_number := this.GetString("good_number")
  1263. fmt.Println(supplier_id, startTime, arrerage, payment, warehose_out_id, number, rate_of_concession, discount_amount)
  1264. orgId := this.GetAdminUserInfo().CurrentOrgId
  1265. dataBody := make(map[string]interface{}, 0)
  1266. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1267. if err != nil {
  1268. utils.ErrorLog(err.Error())
  1269. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1270. return
  1271. }
  1272. var warehousingOut []*models.SpSupplierWarehousingOutOrder
  1273. var updateWarehout []*models.SpSupplierWarehousingOutOrder
  1274. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  1275. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  1276. if len(thisStockIn) > 0 {
  1277. for _, item := range thisStockIn {
  1278. items := item.(map[string]interface{})
  1279. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1280. utils.ErrorLog("id")
  1281. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1282. return
  1283. }
  1284. id := int64(items["id"].(float64))
  1285. if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
  1286. utils.ErrorLog("supply_count")
  1287. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1288. return
  1289. }
  1290. supply_count := int64(items["supply_count"].(float64))
  1291. if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
  1292. utils.ErrorLog("manufacturer_id")
  1293. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1294. return
  1295. }
  1296. manufacturer_id := int64(items["manufacturer_id"].(float64))
  1297. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  1298. utils.ErrorLog("name")
  1299. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1300. return
  1301. }
  1302. name := items["name"].(string)
  1303. if items["order_number"] == nil || reflect.TypeOf(items["order_number"]).String() != "string" {
  1304. utils.ErrorLog("order_number")
  1305. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1306. return
  1307. }
  1308. order_number := items["order_number"].(string)
  1309. if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
  1310. utils.ErrorLog("supply_price")
  1311. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1312. return
  1313. }
  1314. supply_price := items["supply_price"].(string)
  1315. price_float, _ := strconv.ParseFloat(supply_price, 64)
  1316. if items["supply_total_price"] == nil || reflect.TypeOf(items["supply_total_price"]).String() != "string" {
  1317. utils.ErrorLog("supply_total_price")
  1318. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1319. return
  1320. }
  1321. supply_total_price := items["supply_total_price"].(string)
  1322. supply_total_price_float, _ := strconv.ParseFloat(supply_total_price, 64)
  1323. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  1324. utils.ErrorLog("project_id")
  1325. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1326. return
  1327. }
  1328. project_id := int64(items["project_id"].(float64))
  1329. if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
  1330. utils.ErrorLog("supply_remake")
  1331. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1332. return
  1333. }
  1334. supply_remake := items["supply_remake"].(string)
  1335. if items["supply_batch_number"] == nil || reflect.TypeOf(items["supply_batch_number"]).String() != "string" {
  1336. utils.ErrorLog("supply_batch_number")
  1337. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1338. return
  1339. }
  1340. supply_batch_number := items["supply_batch_number"].(string)
  1341. var supply_expiry_date_time int64
  1342. if items["supply_expiry_date"] == nil || reflect.TypeOf(items["supply_expiry_date"]).String() != "string" {
  1343. utils.ErrorLog("supply_expiry_date")
  1344. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1345. return
  1346. }
  1347. supply_expiry_date := items["supply_expiry_date"].(string)
  1348. if len(supply_expiry_date) > 0 {
  1349. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", supply_expiry_date+" 00:00:00", loc)
  1350. if err != nil {
  1351. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1352. return
  1353. }
  1354. supply_expiry_date_time = theTime.Unix()
  1355. }
  1356. if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
  1357. utils.ErrorLog("supply_license_number")
  1358. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1359. return
  1360. }
  1361. supply_license_number := items["supply_license_number"].(string)
  1362. var supply_product_date_time int64
  1363. if items["supply_product_date"] == nil || reflect.TypeOf(items["supply_product_date"]).String() != "string" {
  1364. utils.ErrorLog("supply_product_date")
  1365. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1366. return
  1367. }
  1368. supply_product_date := items["supply_product_date"].(string)
  1369. if len(supply_product_date) > 0 {
  1370. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", supply_product_date+" 00:00:00", loc)
  1371. if err != nil {
  1372. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1373. return
  1374. }
  1375. supply_product_date_time = theTime.Unix()
  1376. }
  1377. if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
  1378. utils.ErrorLog("supply_specification_name")
  1379. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1380. return
  1381. }
  1382. supply_specification_name := items["supply_specification_name"].(string)
  1383. if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
  1384. utils.ErrorLog("supply_total")
  1385. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1386. return
  1387. }
  1388. supply_total := items["supply_total"].(string)
  1389. if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
  1390. utils.ErrorLog("supply_type")
  1391. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1392. return
  1393. }
  1394. supply_type := items["supply_type"].(string)
  1395. if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
  1396. utils.ErrorLog("supply_unit")
  1397. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1398. return
  1399. }
  1400. supply_unit := items["supply_unit"].(string)
  1401. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1402. utils.ErrorLog("type")
  1403. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1404. return
  1405. }
  1406. is_source := int64(items["type"].(float64))
  1407. if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
  1408. utils.ErrorLog("supply_manufacturer")
  1409. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1410. return
  1411. }
  1412. supply_manufacturer := items["supply_manufacturer"].(string)
  1413. if items["warehouse_info_id"] == nil || reflect.TypeOf(items["warehouse_info_id"]).String() != "float64" {
  1414. utils.ErrorLog("warehouse_info_id")
  1415. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1416. return
  1417. }
  1418. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1419. if items["warehousing_id"] == nil || reflect.TypeOf(items["warehousing_id"]).String() != "float64" {
  1420. utils.ErrorLog("warehouse_info_id")
  1421. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1422. return
  1423. }
  1424. warehousing_id := int64(items["warehousing_id"].(float64))
  1425. if id > 0 {
  1426. order := models.SpSupplierWarehousingOutOrder{
  1427. ID: id,
  1428. OrderNumber: order_number,
  1429. ProjectId: project_id,
  1430. IsSource: is_source,
  1431. Count: supply_count,
  1432. Amount: supply_total_price_float,
  1433. Price: price_float,
  1434. Remark: supply_remake,
  1435. IsCheck: 2,
  1436. UserOrgId: orgId,
  1437. Status: 1,
  1438. Ctime: time.Now().Unix(),
  1439. Mtime: 0,
  1440. WarehouseOutId: warehose_out_id,
  1441. Type: 1,
  1442. SupplyBatchNumber: supply_batch_number,
  1443. SupplyProductDate: supply_product_date_time,
  1444. SupplyExpiryDate: supply_expiry_date_time,
  1445. SupplyType: supply_type,
  1446. SupplyUnit: supply_unit,
  1447. SupplyTotal: supply_total,
  1448. SupplySpecificationName: supply_specification_name,
  1449. SupplyLicenseNumber: supply_license_number,
  1450. Name: name,
  1451. ManufacturerId: manufacturer_id,
  1452. GoodNumber: good_number,
  1453. SupplyManufacturer: supply_manufacturer,
  1454. WarehouseInfoId: warehouse_info_id,
  1455. WarehousingId: warehousing_id,
  1456. }
  1457. updateWarehout = append(updateWarehout, &order)
  1458. }
  1459. if id == 0 {
  1460. order := models.SpSupplierWarehousingOutOrder{
  1461. OrderNumber: order_number,
  1462. ProjectId: project_id,
  1463. IsSource: is_source,
  1464. Count: supply_count,
  1465. Amount: supply_total_price_float,
  1466. Price: price_float,
  1467. Remark: supply_remake,
  1468. IsCheck: 2,
  1469. UserOrgId: orgId,
  1470. Status: 1,
  1471. Ctime: time.Now().Unix(),
  1472. Mtime: 0,
  1473. WarehouseOutId: warehose_out_id,
  1474. Type: 1,
  1475. SupplyBatchNumber: supply_batch_number,
  1476. SupplyProductDate: supply_product_date_time,
  1477. SupplyExpiryDate: supply_expiry_date_time,
  1478. WarehouseInfoId: id,
  1479. SupplyType: supply_type,
  1480. SupplyUnit: supply_unit,
  1481. SupplyTotal: supply_total,
  1482. SupplySpecificationName: supply_specification_name,
  1483. SupplyLicenseNumber: supply_license_number,
  1484. Name: name,
  1485. ManufacturerId: manufacturer_id,
  1486. GoodNumber: good_number,
  1487. SupplyManufacturer: supply_manufacturer,
  1488. }
  1489. warehousingOut = append(warehousingOut, &order)
  1490. }
  1491. }
  1492. }
  1493. }
  1494. out := models.SpSupplierWarehouseOut{
  1495. Arrearage: arrerage_float,
  1496. Payment: payment_float,
  1497. RateOfConcession: rate_of_concession_float,
  1498. DiscountAmount: discount_amount_float,
  1499. SupplierId: supplier_id,
  1500. DocumentDate: startTime,
  1501. }
  1502. //更改购货单据
  1503. service.UpdateGoodWarehouseOut(warehose_out_id, out)
  1504. for _, item := range warehousingOut {
  1505. //如果是手动新增的,type 等于2
  1506. if item.WarehouseInfoId == 0 {
  1507. item.Type = 2
  1508. }
  1509. err = service.CreateSupplyWarehousOutOrder(item)
  1510. }
  1511. for _, item := range updateWarehout {
  1512. service.UpdateGoodWarehouseOutOrder(item)
  1513. }
  1514. if err == nil {
  1515. this.ServeSuccessJSON(map[string]interface{}{
  1516. "out": out,
  1517. })
  1518. } else {
  1519. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1520. }
  1521. }
  1522. func (this *SupplyOrderApiController) DeletePurchOrder() {
  1523. id, _ := this.GetInt64("id")
  1524. orgId := this.GetAdminUserInfo().CurrentOrgId
  1525. err := service.DeletePurchOrder(id, orgId)
  1526. if err == nil {
  1527. returnData := make(map[string]interface{}, 0)
  1528. returnData["msg"] = "ok"
  1529. this.ServeSuccessJSON(returnData)
  1530. return
  1531. } else {
  1532. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1533. }
  1534. }
  1535. func (this *SupplyOrderApiController) GetAllOrderCountList() {
  1536. id, _ := this.GetInt64("id")
  1537. orgId := this.GetAdminUserInfo().CurrentOrgId
  1538. //获取购货订单的数据
  1539. purcaseOrder, _ := service.GetAllPurcaseOrderById(id, orgId)
  1540. //获取购货单的数据
  1541. goodOrder, err := service.GetAllGoodOrderById(id, orgId)
  1542. drugList, err := service.GetSupplyDrugList(orgId)
  1543. if err == nil {
  1544. this.ServeSuccessJSON(map[string]interface{}{
  1545. "purcaseOrder": purcaseOrder,
  1546. "goodOrder": goodOrder,
  1547. "drugList": drugList,
  1548. })
  1549. } else {
  1550. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1551. }
  1552. }
  1553. func (this *SupplyOrderApiController) GetPurchOrderInfo() {
  1554. id, _ := this.GetInt64("id")
  1555. ids := this.GetString("ids")
  1556. if len(ids) == 0 {
  1557. info, _ := service.GetPurchaseOrderDetail(id)
  1558. //查询
  1559. orderInfo, err := service.GetSupplyWarehousingOrderInfo(id)
  1560. orgId := this.GetAdminUserInfo().CurrentOrgId
  1561. supplyList, _ := service.GetSupplierList(orgId)
  1562. //获取药品库数据
  1563. baseList, _ := service.GetSupplyDrugList(orgId)
  1564. goodList, _ := service.GetSupplyGoodList(orgId)
  1565. if err == nil {
  1566. this.ServeSuccessJSON(map[string]interface{}{
  1567. "info": info,
  1568. "orderInfo": orderInfo,
  1569. "supplyList": supplyList,
  1570. "baseList": baseList,
  1571. "goodList": goodList,
  1572. })
  1573. } else {
  1574. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1575. }
  1576. }
  1577. if len(ids) > 0 {
  1578. idArray := strings.Split(ids, ",")
  1579. info, _ := service.GetPurchaseOrderDetail(id)
  1580. //查询
  1581. orderInfo, err := service.GetSupplyWarehousingOrderInfoTwo(id, idArray)
  1582. orgId := this.GetAdminUserInfo().CurrentOrgId
  1583. supplyList, _ := service.GetSupplierList(orgId)
  1584. //获取药品库数据
  1585. baseList, _ := service.GetSupplyDrugList(orgId)
  1586. goodList, _ := service.GetSupplyGoodList(orgId)
  1587. if err == nil {
  1588. this.ServeSuccessJSON(map[string]interface{}{
  1589. "info": info,
  1590. "orderInfo": orderInfo,
  1591. "supplyList": supplyList,
  1592. "baseList": baseList,
  1593. "goodList": goodList,
  1594. })
  1595. } else {
  1596. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1597. }
  1598. }
  1599. }
  1600. func (this *SupplyOrderApiController) GetGoodOrderList() {
  1601. id, _ := this.GetInt64("id")
  1602. orgId := this.GetAdminUserInfo().CurrentOrgId
  1603. list, err := service.GetGoodOrderList(id, orgId)
  1604. if err == nil {
  1605. this.ServeSuccessJSON(map[string]interface{}{
  1606. "list": list,
  1607. })
  1608. } else {
  1609. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1610. }
  1611. }
  1612. func (this *SupplyOrderApiController) GetReturnOrder() {
  1613. id, _ := this.GetInt64("id")
  1614. orgId := this.GetAdminUserInfo().CurrentOrgId
  1615. err := service.GetReturnOrder(id, orgId)
  1616. if err == nil {
  1617. returnData := make(map[string]interface{}, 0)
  1618. returnData["msg"] = "ok"
  1619. this.ServeSuccessJSON(returnData)
  1620. return
  1621. } else {
  1622. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1623. }
  1624. }
  1625. func (this *SupplyOrderApiController) GetGoodOrderCountList() {
  1626. id, _ := this.GetInt64("id")
  1627. warehousing_id, _ := this.GetInt64("warehousing_id")
  1628. orgId := this.GetAdminUserInfo().CurrentOrgId
  1629. checker := this.GetAdminUserInfo().AdminUser.Id
  1630. recordDateStr := time.Now().Format("2006-01-02")
  1631. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1632. record_date := recordDate.Unix()
  1633. out := models.SpSupplierWarehouseOut{
  1634. IsCheck: 1,
  1635. Checker: checker,
  1636. CheckTime: record_date,
  1637. }
  1638. err := service.CheckGoodOrder(id, orgId, out)
  1639. //获取购货订单的数据
  1640. purcaseOrder, _ := service.GetAllPurcaseOrderById(warehousing_id, orgId)
  1641. //获取购货单的数据
  1642. goodOrder, _ := service.GetAllGoodOrderByIdTwo(warehousing_id, orgId)
  1643. //查询该购货单是否审核成功
  1644. detail, _ := service.GetGoodOrderDetail(id, orgId)
  1645. var warehousingInfo []*models.WarehousingInfo
  1646. //如果审核成功
  1647. if detail.IsCheck == 1 {
  1648. //入库
  1649. if len(goodOrder) > 0 {
  1650. for _, item := range goodOrder {
  1651. //药品
  1652. if item.IsSource == 1 {
  1653. }
  1654. //耗材
  1655. if item.IsSource == 2 {
  1656. //获取耗材类型
  1657. good, _ := service.GetGoodInformationByGoodId(item.ProjectId)
  1658. timeStr := time.Now().Format("2006-01-02")
  1659. timeArr := strings.Split(timeStr, "-")
  1660. total, _ := service.FindAllWarehouseTotal(orgId)
  1661. total = total + 1
  1662. warehousing_order := "RKD" + strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1663. operation_time := time.Now().Unix()
  1664. creater := this.GetAdminUserInfo().AdminUser.Id
  1665. warehousing := models.Warehousing{
  1666. WarehousingOrder: warehousing_order,
  1667. OperationTime: operation_time,
  1668. OrgId: orgId,
  1669. Creater: creater,
  1670. Ctime: time.Now().Unix(),
  1671. Status: 1,
  1672. WarehousingTime: record_date,
  1673. Type: 1,
  1674. }
  1675. service.AddSigleWarehouse(&warehousing)
  1676. //入库单表格
  1677. warehouseInfo := &models.WarehousingInfo{
  1678. WarehousingOrder: warehousing.WarehousingOrder,
  1679. WarehousingId: warehousing.ID,
  1680. GoodId: item.ProjectId,
  1681. Number: item.SupplyBatchNumber,
  1682. GoodTypeId: good.GoodTypeId,
  1683. ProductDate: item.SupplyProductDate,
  1684. ExpiryDate: item.SupplyExpiryDate,
  1685. WarehousingCount: item.Count,
  1686. Price: item.Price,
  1687. TotalPrice: 0,
  1688. Status: 1,
  1689. Ctime: time.Now().Unix(),
  1690. Remark: item.Remark,
  1691. OrgId: orgId,
  1692. Type: 1,
  1693. Manufacturer: item.ManufacturerId,
  1694. StockCount: item.Count,
  1695. Dealer: good.Dealer,
  1696. LicenseNumber: item.SupplyLicenseNumber,
  1697. PackingPrice: good.PackingPrice,
  1698. }
  1699. warehousingInfo = append(warehousingInfo, warehouseInfo)
  1700. }
  1701. }
  1702. }
  1703. }
  1704. drugList, _ := service.GetSupplyDrugList(orgId)
  1705. if err == nil {
  1706. this.ServeSuccessJSON(map[string]interface{}{
  1707. "purcaseOrder": purcaseOrder,
  1708. "goodOrder": goodOrder,
  1709. "drugList": drugList,
  1710. })
  1711. } else {
  1712. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1713. }
  1714. }