supply_order_api_contorller.go 98KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827
  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. "github.com/jinzhu/gorm"
  11. "reflect"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. type SupplyOrderApiController struct {
  17. BaseAuthAPIController
  18. }
  19. func SupplyOrderApiRegistRouters() {
  20. //获取供应商列表GetSupplyList
  21. beego.Router("/api/supply/getsupplylist", &SupplyOrderApiController{}, "get:GetSupplyList")
  22. //保存供应商及联系人(用于更改)
  23. beego.Router("/api/supply/updatesupply", &SupplyOrderApiController{}, "post:UpdateSupply")
  24. //删除单条联系人
  25. beego.Router("/api/supply/delcontactone", &SupplyOrderApiController{}, "get:DelContactOne")
  26. //获取单条供应商和涉及到的联系人记录
  27. beego.Router("/api/supply/getsupplyandcontactone", &SupplyOrderApiController{}, "get:GetSupplyAndContactOne")
  28. //获取供应商类别
  29. beego.Router("/api/supply/getsupplytype", &SupplyOrderApiController{}, "get:GetSupplyType")
  30. //删除供应商及联系人
  31. beego.Router("/api/supply/delsupply", &SupplyOrderApiController{}, "post:DelSupply")
  32. //获取供应商编码
  33. beego.Router("/api/supply/getsupplycode", &SupplyOrderApiController{}, "get:GetSupplyCode")
  34. //保存供应商及联系人(用于新增)
  35. beego.Router("/api/supply/savesupply", &SupplyOrderApiController{}, "post:SaveSupply")
  36. beego.Router("/api/supply/getinitorder", &SupplyOrderApiController{}, "get:GetInitOrder")
  37. //保存购货订单
  38. beego.Router("/api/supply/savepurchaseorder", &SupplyOrderApiController{}, "post:SavePurchaseOrder")
  39. //获取所有供应商
  40. beego.Router("/api/supply/getallsupply", &SupplyOrderApiController{}, "get:GetAllSupply")
  41. //获取供应商订单列表
  42. beego.Router("/api/supply/getallpurchaseorderlist", &SupplyOrderApiController{}, "get:GetAllPurchaseOrderList")
  43. //修改购货订单
  44. beego.Router("/api/supply/updatepurchaseorder", &SupplyOrderApiController{}, "Post:UpdatePurchaseOrder")
  45. //审核购货订单
  46. beego.Router("/api/supply/checkpurchaseorder", &SupplyOrderApiController{}, "get:UpdateSupplyWaresing")
  47. //获取购货订单详情
  48. beego.Router("/api/supply/getpurchaseorderdetail", &SupplyOrderApiController{}, "get:GetPurchaseOrderDetail")
  49. //新增购货单
  50. beego.Router("/api/supply/addgoodorder", &SupplyOrderApiController{}, "post:AddGoodOrder")
  51. //获取购货单列表
  52. beego.Router("/api/supply/getallgoodorderlist", &SupplyOrderApiController{}, "Get:GetAllGoodOderList")
  53. //修改购货订单详情
  54. beego.Router("/api/supply/getgoodorderdetail", &SupplyOrderApiController{}, "Get:GetGoodOrderDetail")
  55. //修改购货订单
  56. beego.Router("/api/supply/updategoodorder", &SupplyOrderApiController{}, "Post:UpdateGoodOrder")
  57. //删除购货订单
  58. beego.Router("/api/supply/deletepurchorder", &SupplyOrderApiController{}, "Get:DeletePurchOrder")
  59. //生成购货单的判断
  60. beego.Router("/api/supply/getallordercountlist", &SupplyOrderApiController{}, "Get:GetAllOrderCountList")
  61. // 生成购货单
  62. beego.Router("/api/supply/getpurchaseorderinfo", &SupplyOrderApiController{}, "Get:GetPurchOrderInfo")
  63. //反审核 获取关联的购货单数据
  64. beego.Router("/api/supply/getgoodorderlist", &SupplyOrderApiController{}, "Get:GetGoodOrderList")
  65. //反审核购货订单
  66. beego.Router("/api/supply/getreturnorder", &SupplyOrderApiController{}, "Get:GetReturnOrder")
  67. //判断是否全部入库
  68. beego.Router("/api/supply/getgoodordercountlist", &SupplyOrderApiController{}, "Get:GetGoodOrderCountList")
  69. //修改购货订单入库状态
  70. beego.Router("/api/supply/modefysupplywarehousing", &SupplyOrderApiController{}, "Get:ModefySupplyWarehousing")
  71. //保存退货单
  72. beego.Router("/api/supply/savegoodreturnOrder", &SupplyOrderApiController{}, "Post:SaveGoodReturnOrder")
  73. //获取退货单列表
  74. beego.Router("/api/supply/getallgoodreturnorderlist", &SupplyOrderApiController{}, "Get:GetAllGoodReturnOrderList")
  75. //获取退库详情
  76. beego.Router("/api/supply/getgoodreturndetail", &SupplyOrderApiController{}, "Get:GetGoodReturnDetail")
  77. //修改退库
  78. beego.Router("/api/supply/updategoodreturn", &SupplyOrderApiController{}, "Post:UpdateGoodReturn")
  79. //反审核采购单
  80. beego.Router("/api/supply/mofygoodorder", &SupplyOrderApiController{}, "Get:ModefyGoodOrder")
  81. //更改入库状态
  82. beego.Router("/api/supply/updatesupplywarehousing", &SupplyOrderApiController{}, "Get:UpdateSupplyWarehousing")
  83. //删除购货单
  84. beego.Router("/api/supply/deletegoodorder", &SupplyOrderApiController{}, "Get:DeleteGoodOrder")
  85. //生成采购退货单数据
  86. beego.Router("/api/supply/getsupplywarehouseoutbyid", &SupplyOrderApiController{}, "Get:GetSupplyWarehouseById")
  87. }
  88. //获取供应商列表GetSupplyList
  89. func (this *SupplyOrderApiController) GetSupplyList() {
  90. ctype, _ := this.GetInt64("ctype") //供应商类别
  91. page, _ := this.GetInt64("page") //页码
  92. limit, _ := this.GetInt64("limit") //每一页查出来的条数
  93. if page == 0 || limit == 0 {
  94. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "page或limit参数不能为空")
  95. return
  96. }
  97. code := this.GetString("code") //供应商编号
  98. sname := this.GetString("sname") //供应商名称
  99. cname := this.GetString("cname") //联系人名字
  100. orgId := this.GetAdminUserInfo().CurrentOrgId
  101. //获取分页的数据
  102. list, total, err := service.GetSupplyList(ctype, page, limit, code, sname, cname)
  103. //获取供应商类别
  104. costClassify := "供应商类别"
  105. drugTypeParent, _ := service.GetDrugDataConfig(0, costClassify)
  106. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  107. tmpmap := make(map[int64]string) //储存供应商类别
  108. namemap := make(map[string]string) //储存首要联系人
  109. phonemap := make(map[string]string) //手机号
  110. for i := 0; i < len(drugTypeList); i++ {
  111. k := int64(drugTypeList[i].Value)
  112. v := drugTypeList[i].Name
  113. tmpmap[k] = v
  114. }
  115. if err == nil {
  116. for i := 0; i < len(list); i++ {
  117. code := list[i].SupplierCode
  118. fistname, errs := service.FindName(code)
  119. if errs != nil && errs.Error() != "record not found" {
  120. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  121. return
  122. }
  123. namemap[code] = fistname.Name
  124. phonemap[code] = fistname.Phone
  125. }
  126. type SpSupplierNameList struct { //基于SpSupplierName结构体修改的,为了方便前端取数据整合了一下,删除了几个用不到的字段,添加了联系人名字和供应商类别两个字段
  127. ID int64
  128. SupplierCode string
  129. SupplierName string
  130. SupplierType int64
  131. VatRate float64
  132. Number string
  133. Bank string
  134. BankAccount string
  135. UserOrgId int64
  136. Status int64
  137. ContactsId int64
  138. ConName string //供应商主要联系人名字
  139. TypeName string //供应商类别
  140. Phone string //电话
  141. }
  142. //初始化该结构体
  143. tmplist := []*SpSupplierNameList{}
  144. for i := 0; i < len(list); i++ {
  145. var typename string //类别名称
  146. if list[i].SupplierType == 0 {
  147. typename = ""
  148. } else {
  149. typename = tmpmap[list[i].SupplierType]
  150. }
  151. tlist := &SpSupplierNameList{
  152. list[i].ID,
  153. list[i].SupplierCode,
  154. list[i].SupplierName,
  155. list[i].SupplierType,
  156. list[i].VatRate,
  157. list[i].Number,
  158. list[i].Bank,
  159. list[i].BankAccount,
  160. list[i].UserOrgId,
  161. list[i].Status,
  162. list[i].ContactsId,
  163. namemap[list[i].SupplierCode],
  164. typename,
  165. phonemap[list[i].SupplierCode],
  166. }
  167. tmplist = append(tmplist, tlist)
  168. }
  169. this.ServeSuccessJSON(map[string]interface{}{
  170. "list": tmplist,
  171. "total": total,
  172. })
  173. } else {
  174. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  175. }
  176. }
  177. //保存供应商及联系人(用于更改)
  178. func (this *SupplyOrderApiController) UpdateSupply() {
  179. dataBody := make(map[string]interface{}, 0)
  180. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  181. if err != nil {
  182. utils.ErrorLog(err.Error())
  183. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  184. return
  185. }
  186. supplierName := dataBody["suppliername"].(string)
  187. if supplierName == "" {
  188. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商名称不能为空")
  189. return
  190. }
  191. //upplierCode := this.GetString("suppliercode") //供应商编码
  192. supplierCode := dataBody["suppliercode"].(string)
  193. if supplierCode == "" {
  194. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商编号不能为空")
  195. return
  196. }
  197. //supplierid, _ := this.GetInt64("id") //供应商id
  198. //fmt.Println(dataBody["id"])
  199. //utils.InfoLog("+++++++++++++前++++++++++++++++++", dataBody["id"])
  200. supplierid := int64(dataBody["id"].(float64))
  201. //utils.InfoLog("+++++++++++++后++++++++++++++++++", supplierid)
  202. if supplierid == 0 {
  203. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商id不能为空")
  204. return
  205. }
  206. //查询供应商的信息
  207. supply, err := service.GetSupplyOne(supplierid)
  208. if err != nil {
  209. utils.ErrorLog(err.Error())
  210. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  211. return
  212. }
  213. if supplierName != supply.SupplierName {
  214. //判断供应商名称是否有重复的
  215. sbool, _ := service.FindSupplierName(supplierName)
  216. if sbool { //有重复的
  217. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商名称重复")
  218. return
  219. }
  220. }
  221. if supplierCode != supply.SupplierCode {
  222. //判断供应商编号是否有重复的
  223. codebool, _ := service.FindSupplierCode(supplierCode)
  224. if codebool {
  225. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商编号重复")
  226. return
  227. }
  228. }
  229. //supplierType, _ := this.GetInt64("suppliertype") //供应商类别
  230. if dataBody["suppliertype"] == "" {
  231. var tmp int64 = 0
  232. dataBody["suppliertype"] = tmp
  233. }
  234. if dataBody["vatrate"] == "" {
  235. dataBody["vatrate"] = 0
  236. }
  237. supplierType := dataBody["suppliertype"].(int64) //供应商类别
  238. //vatRate, _ := this.GetFloat("vatrate") //增值税税率
  239. vatRate, _ := dataBody["suppliertype"].(float64) //增值税税率
  240. //number := this.GetString("number") //纳税人识别号
  241. number := dataBody["number"].(string) //纳税人识别号
  242. //bank := this.GetString("bank") //开户银行
  243. bank := dataBody["bank"].(string) //纳税人识别号
  244. //bankAccount := this.GetString("bankAccount") //银行账号
  245. bankAccount := dataBody["bankaccount"].(string)
  246. orgId := this.GetAdminUserInfo().CurrentOrgId
  247. //contacts := this.Get("contacts")//联系人
  248. //dataBody := make(map[string]interface{}, 0)
  249. //err = json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  250. //if err != nil {
  251. // utils.ErrorLog(err.Error())
  252. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  253. // return
  254. //}
  255. //保存联系人
  256. if dataBody["contacts"] != nil && reflect.TypeOf(dataBody["contacts"]).String() == "[]interface {}" {
  257. thisStockIn, _ := dataBody["contacts"].([]interface{})
  258. if len(thisStockIn) > 0 {
  259. if len(thisStockIn) == 1 {
  260. for _, item := range thisStockIn {
  261. items := item.(map[string]interface{})
  262. items["isfirst"] = 1
  263. }
  264. }
  265. tmodify := this.GetAdminUserInfo().AdminUser.Id
  266. err = service.UpdateSupplyAndContact(thisStockIn, supplierid, orgId, supplierType, tmodify, supplierCode, supplierName, number, bank, bankAccount, vatRate)
  267. if err != nil {
  268. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  269. return
  270. }
  271. } else {
  272. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "联系人不能为空")
  273. return
  274. }
  275. }
  276. this.ServeSuccessJSON(map[string]interface{}{
  277. "list": "保存成功",
  278. })
  279. return
  280. }
  281. //获取单条供应商和涉及到的联系人记录
  282. func (this *SupplyOrderApiController) GetSupplyAndContactOne() {
  283. id, _ := this.GetInt64("id")
  284. if id == 0 {
  285. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商id不能为空")
  286. return
  287. }
  288. supply, contact, err := service.GetSupplyAndContactOne(id)
  289. if err != nil {
  290. utils.ErrorLog(err.Error())
  291. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  292. return
  293. }
  294. this.ServeSuccessJSON(map[string]interface{}{
  295. "supply": supply,
  296. "contact": contact,
  297. })
  298. return
  299. }
  300. //获取供应商类别
  301. func (this *SupplyOrderApiController) GetSupplyType() {
  302. orgId := this.GetAdminUserInfo().CurrentOrgId
  303. costClassify := "供应商类别"
  304. drugTypeParent, _ := service.GetDrugDataConfig(0, costClassify)
  305. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  306. this.ServeSuccessJSON(map[string]interface{}{
  307. "list": drugTypeList,
  308. })
  309. return
  310. }
  311. //删除供应商及联系人
  312. func (this *SupplyOrderApiController) DelSupply() {
  313. //拿到供应商的id
  314. suid, _ := this.GetInt64("id")
  315. if suid == 0 {
  316. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商id不能为空")
  317. return
  318. }
  319. supply := models.SpSupplierName{
  320. ID: suid,
  321. }
  322. err := service.DelSupply(supply)
  323. if err != nil {
  324. utils.ErrorLog(err.Error())
  325. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  326. return
  327. }
  328. this.ServeSuccessJSON(map[string]interface{}{
  329. "list": "删除成功",
  330. })
  331. return
  332. }
  333. //删除单条联系人记录
  334. func (this *SupplyOrderApiController) DelContactOne() {
  335. id, _ := this.GetInt64("id")
  336. if id == 0 {
  337. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "联系人id不能为空")
  338. return
  339. }
  340. err := service.DelContactOne(id)
  341. if err != nil {
  342. utils.ErrorLog(err.Error())
  343. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  344. return
  345. }
  346. this.ServeSuccessJSON(map[string]interface{}{
  347. "list": "删除成功",
  348. })
  349. return
  350. }
  351. //获取供应商编码
  352. func (this *SupplyOrderApiController) GetSupplyCode() {
  353. supply, err := service.GetSuppliyCode()
  354. if err != nil {
  355. return
  356. }
  357. if len(supply) == 0 { //如果数据库中没有gys类型的编码则设置默认值
  358. //supply[0].SupplierCode ="gys001"
  359. supply = []*models.SpSupplierName{
  360. {
  361. SupplierCode: "gys001",
  362. },
  363. }
  364. } else { //获取数据库中最大的编码值,并加一
  365. tmp := supply[0].SupplierCode
  366. tmp = tmp[3:]
  367. var code int
  368. code, err = strconv.Atoi(tmp)
  369. code++
  370. tmp = strconv.Itoa(code)
  371. for len(tmp) < 3 {
  372. tmp = "0" + tmp
  373. }
  374. tmp = "gys" + tmp
  375. supply[0].SupplierCode = tmp
  376. }
  377. this.ServeSuccessJSON(map[string]interface{}{
  378. "supplycode": supply,
  379. })
  380. return
  381. }
  382. //保存供应商
  383. func (this *SupplyOrderApiController) SaveSupply() {
  384. //supplierName := this.GetString("suppliername") //供应商名称
  385. dataBody := make(map[string]interface{}, 0)
  386. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  387. if err != nil {
  388. utils.ErrorLog(err.Error())
  389. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  390. return
  391. }
  392. supplierName := dataBody["suppliername"].(string)
  393. if supplierName == "" {
  394. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商名称不能为空")
  395. return
  396. }
  397. //判断供应商名称是否有重复的
  398. sbool, _ := service.FindSupplierName(supplierName)
  399. if sbool { //有重复的
  400. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商名称重复")
  401. return
  402. }
  403. //supplierCode := this.GetString("suppliercode") //供应商编码
  404. supplierCode := dataBody["suppliercode"].(string) //供应商编码
  405. if supplierCode == "" {
  406. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商编号不能为空")
  407. return
  408. }
  409. //判断供应商编号是否有重复的
  410. codebool, _ := service.FindSupplierCode(supplierCode)
  411. if codebool {
  412. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商编号重复")
  413. return
  414. }
  415. if dataBody["suppliertype"] == "" {
  416. var tmp int64 = 0
  417. dataBody["suppliertype"] = tmp
  418. }
  419. if dataBody["vatrate"] == "" {
  420. dataBody["vatrate"] = 0
  421. }
  422. //supplierType, _ := this.GetInt64("suppliertype")
  423. supplierType := dataBody["suppliertype"].(int64) //供应商类别
  424. //vatRate, _ := this.GetFloat("vatrate")
  425. vatRate, _ := dataBody["suppliertype"].(float64) //增值税税率
  426. //number := this.GetString("number")
  427. number := dataBody["number"].(string)
  428. //bank := this.GetString("bank")
  429. bank := dataBody["bank"].(string)
  430. //bankAccount := this.GetString("bankAccount")
  431. bankAccount := dataBody["bankaccount"].(string)
  432. orgId := this.GetAdminUserInfo().CurrentOrgId
  433. //contacts := this.Get("contacts")//联系人
  434. //err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  435. //if err != nil {
  436. // utils.ErrorLog(err.Error())
  437. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  438. // return
  439. //}
  440. //保存联系人
  441. if dataBody["contacts"] != nil && reflect.TypeOf(dataBody["contacts"]).String() == "[]interface {}" {
  442. thisStockIn, _ := dataBody["contacts"].([]interface{})
  443. if len(thisStockIn) > 0 {
  444. if len(thisStockIn) == 1 {
  445. for _, item := range thisStockIn {
  446. items := item.(map[string]interface{})
  447. items["isfirst"] = 1
  448. }
  449. }
  450. tcreater := this.GetAdminUserInfo().AdminUser.Id
  451. err = service.SaveSupplyAndContact(thisStockIn, orgId, supplierType, tcreater, supplierCode, supplierName, number, bank, bankAccount, vatRate)
  452. if err != nil {
  453. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  454. return
  455. }
  456. } else {
  457. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "联系人不能为空")
  458. return
  459. }
  460. }
  461. this.ServeSuccessJSON(map[string]interface{}{
  462. "list": "保存成功",
  463. })
  464. return
  465. }
  466. func (this *SupplyOrderApiController) GetInitOrder() {
  467. orgId := this.GetAdminUserInfo().CurrentOrgId
  468. //获取药品库数据
  469. baseList, _ := service.GetSupplyDrugList(orgId)
  470. goodList, _ := service.GetSupplyGoodList(orgId)
  471. manufactuerList, _ := service.GetAllManufacturerList(orgId)
  472. goodTypeList, _ := service.GetAllGoodType(orgId)
  473. supplyList, _ := service.GetSupplierList(orgId)
  474. var drugType = "药品类型"
  475. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  476. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
  477. this.ServeSuccessJSON(map[string]interface{}{
  478. "drugList": baseList,
  479. "goodList": goodList,
  480. "manufactuerList": manufactuerList,
  481. "goodTypeList": goodTypeList,
  482. "drugTypeList": drugTypeList,
  483. "supplyList": supplyList,
  484. })
  485. return
  486. }
  487. func (this *SupplyOrderApiController) SavePurchaseOrder() {
  488. supplier_id, _ := this.GetInt64("supplier_name")
  489. start_time := this.GetString("start_time")
  490. end_time := this.GetString("end_time")
  491. timeLayout := "2006-01-02"
  492. loc, _ := time.LoadLocation("Local")
  493. var startTime int64
  494. if len(start_time) > 0 {
  495. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  496. if err != nil {
  497. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  498. return
  499. }
  500. startTime = theTime.Unix()
  501. }
  502. var endTime int64
  503. if len(end_time) > 0 {
  504. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  505. if err != nil {
  506. utils.ErrorLog(err.Error())
  507. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  508. return
  509. }
  510. endTime = theTime.Unix()
  511. }
  512. rate_of_concession := this.GetString("rate_of_concession")
  513. rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
  514. discount_amount := this.GetString("discount_amount")
  515. discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
  516. dataBody := make(map[string]interface{}, 0)
  517. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  518. if err != nil {
  519. utils.ErrorLog(err.Error())
  520. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  521. return
  522. }
  523. //生成购货订单
  524. timeStr := time.Now().Format("2006-01-02")
  525. timeArr := strings.Split(timeStr, "-")
  526. orgId := this.GetAdminUserInfo().CurrentOrgId
  527. total, _ := service.FindAllSupplyOrder(orgId)
  528. total = total + 1
  529. warehousing_order := "CGDD" + timeArr[0] + timeArr[1] + timeArr[2] + "00" + strconv.FormatInt(total, 10)
  530. recordDateStr := time.Now().Format("2006-01-02")
  531. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  532. fmt.Scan("parseDateErr", parseDateErr)
  533. record_date := recordDate.Unix()
  534. return_remake := dataBody["return_remake"].(string)
  535. info := models.SupplierWarehouseInfo{
  536. Number: warehousing_order,
  537. UserOrgId: orgId,
  538. Creater: this.GetAdminUserInfo().AdminUser.Id,
  539. Ctime: time.Now().Unix(),
  540. Mtime: 0,
  541. Status: 1,
  542. RecordDate: record_date,
  543. IsCheck: 2,
  544. RateOfConcession: rate_of_concession_float,
  545. DiscountAmount: discount_amount_float,
  546. DocumentDate: startTime,
  547. DeliveryDate: endTime,
  548. SupplierId: supplier_id,
  549. IsWarehouse: 2,
  550. ReturnRemake: return_remake,
  551. }
  552. err = service.CreateSupplyWarehouse(info)
  553. warehouseInfo, _ := service.FindLastSupplyWarehouseInfo(orgId)
  554. var warehousingInfo []*models.SupplierWarehousingInfoOrder
  555. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  556. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  557. if len(thisStockIn) > 0 {
  558. for _, item := range thisStockIn {
  559. items := item.(map[string]interface{})
  560. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  561. utils.ErrorLog("project_id")
  562. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  563. return
  564. }
  565. project_id := int64(items["project_id"].(float64))
  566. if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
  567. utils.ErrorLog("supply_count")
  568. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  569. return
  570. }
  571. supply_count := int64(items["supply_count"].(float64))
  572. if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
  573. utils.ErrorLog("supply_license_number")
  574. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  575. return
  576. }
  577. supply_license_number := items["supply_license_number"].(string)
  578. if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
  579. utils.ErrorLog("supply_price")
  580. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  581. return
  582. }
  583. supply_price := items["supply_price"].(string)
  584. supply_price_float, _ := strconv.ParseFloat(supply_price, 64)
  585. if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
  586. utils.ErrorLog("supply_remake")
  587. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  588. return
  589. }
  590. supply_remake := items["supply_remake"].(string)
  591. if items["supply_total_price"] == nil || reflect.TypeOf(items["supply_total_price"]).String() != "string" {
  592. utils.ErrorLog("supply_total_price")
  593. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  594. return
  595. }
  596. supply_total_price := items["supply_total_price"].(string)
  597. supply_total_price_float, _ := strconv.ParseFloat(supply_total_price, 64)
  598. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  599. utils.ErrorLog("type")
  600. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  601. return
  602. }
  603. is_source := int64(items["type"].(float64))
  604. if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
  605. utils.ErrorLog("supply_type")
  606. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  607. return
  608. }
  609. supply_type := items["supply_type"].(string)
  610. if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
  611. utils.ErrorLog("supply_specification_name")
  612. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  613. return
  614. }
  615. supply_specification_name := items["supply_specification_name"].(string)
  616. if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
  617. utils.ErrorLog("supply_total")
  618. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  619. return
  620. }
  621. supply_total := items["supply_total"].(string)
  622. if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
  623. utils.ErrorLog("supply_manufacturer")
  624. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  625. return
  626. }
  627. supply_manufacturer := items["supply_manufacturer"].(string)
  628. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  629. utils.ErrorLog("name")
  630. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  631. return
  632. }
  633. name := items["name"].(string)
  634. if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
  635. utils.ErrorLog("supply_unit")
  636. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  637. return
  638. }
  639. supply_unit := items["supply_unit"].(string)
  640. if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
  641. utils.ErrorLog("manufacturer_id")
  642. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  643. return
  644. }
  645. manufacturer_id := int64(items["manufacturer_id"].(float64))
  646. order := models.SupplierWarehousingInfoOrder{
  647. OrderNumber: warehousing_order,
  648. IsSource: is_source,
  649. Count: supply_count,
  650. Price: supply_price_float,
  651. Amount: supply_total_price_float,
  652. Remark: supply_remake,
  653. UserOrgId: orgId,
  654. Ctime: time.Now().Unix(),
  655. Status: 1,
  656. Mtime: 0,
  657. WarehousingId: warehouseInfo.ID,
  658. ProjectId: project_id,
  659. SupplyLicenseNumber: supply_license_number,
  660. SupplyType: supply_type,
  661. SupplySpecificationName: supply_specification_name,
  662. SupplyTotal: supply_total,
  663. SupplyManufacturer: supply_manufacturer,
  664. Name: name,
  665. SupplyUnit: supply_unit,
  666. ManufacturerId: manufacturer_id,
  667. }
  668. warehousingInfo = append(warehousingInfo, &order)
  669. }
  670. }
  671. }
  672. for _, item := range warehousingInfo {
  673. err = service.CreateSupplyWarehousingOrder(item)
  674. }
  675. //查询
  676. orderInfo, err := service.GetSupplyWarehousingOrderInfo(warehouseInfo.ID)
  677. if err == nil {
  678. this.ServeSuccessJSON(map[string]interface{}{
  679. "order": warehousingInfo,
  680. "warehouseInfo": warehouseInfo,
  681. "orderInfo": orderInfo,
  682. })
  683. } else {
  684. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  685. }
  686. }
  687. func (this *SupplyOrderApiController) GetAllSupply() {
  688. orgId := this.GetAdminUserInfo().CurrentOrgId
  689. appId := this.GetAdminUserInfo().CurrentAppId
  690. supplyList, err := service.GetSupplierList(orgId)
  691. doctorList, err := service.GetAllDoctorSix(orgId, appId)
  692. if err == nil {
  693. this.ServeSuccessJSON(map[string]interface{}{
  694. "supplyList": supplyList,
  695. "doctorList": doctorList,
  696. })
  697. } else {
  698. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  699. }
  700. }
  701. func (this *SupplyOrderApiController) GetAllPurchaseOrderList() {
  702. check_id, _ := this.GetInt64("check_id")
  703. start_time := this.GetString("start_time")
  704. end_time := this.GetString("end_time")
  705. timeLayout := "2006-01-02"
  706. loc, _ := time.LoadLocation("Local")
  707. var startTime int64
  708. if len(start_time) > 0 {
  709. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  710. if err != nil {
  711. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  712. return
  713. }
  714. startTime = theTime.Unix()
  715. }
  716. var endTime int64
  717. if len(end_time) > 0 {
  718. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  719. if err != nil {
  720. utils.ErrorLog(err.Error())
  721. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  722. return
  723. }
  724. endTime = theTime.Unix()
  725. }
  726. keyword := this.GetString("keyword")
  727. page, _ := this.GetInt64("page")
  728. limit, _ := this.GetInt64("limit")
  729. orgId := this.GetAdminUserInfo().CurrentOrgId
  730. list, total, err := service.GetAllPurchaseOrderList(check_id, startTime, endTime, keyword, page, limit, orgId)
  731. if err == nil {
  732. this.ServeSuccessJSON(map[string]interface{}{
  733. "list": list,
  734. "total": total,
  735. })
  736. } else {
  737. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  738. }
  739. }
  740. func (this *SupplyOrderApiController) UpdatePurchaseOrder() {
  741. dataBody := make(map[string]interface{}, 0)
  742. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  743. if err != nil {
  744. utils.ErrorLog(err.Error())
  745. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  746. return
  747. }
  748. supplier_id, _ := this.GetInt64("supplier_name")
  749. start_time := this.GetString("start_time")
  750. end_time := this.GetString("end_time")
  751. timeLayout := "2006-01-02"
  752. loc, _ := time.LoadLocation("Local")
  753. var startTime int64
  754. if len(start_time) > 0 {
  755. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  756. if err != nil {
  757. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  758. return
  759. }
  760. startTime = theTime.Unix()
  761. }
  762. var endTime int64
  763. if len(end_time) > 0 {
  764. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  765. if err != nil {
  766. utils.ErrorLog(err.Error())
  767. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  768. return
  769. }
  770. endTime = theTime.Unix()
  771. }
  772. rate_of_concession := this.GetString("rate_of_concession")
  773. rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
  774. discount_amount := this.GetString("discount_amount")
  775. discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
  776. warehousing_id, _ := this.GetInt64("id")
  777. number := this.GetString("number")
  778. return_remake := dataBody["return_remake"].(string)
  779. orgId := this.GetAdminUserInfo().CurrentOrgId
  780. info := models.SupplierWarehouseInfo{
  781. RateOfConcession: rate_of_concession_float,
  782. DiscountAmount: discount_amount_float,
  783. DocumentDate: startTime,
  784. DeliveryDate: endTime,
  785. SupplierId: supplier_id,
  786. Mtime: time.Now().Unix(),
  787. ReturnRemake: return_remake,
  788. }
  789. service.ModefySupplyWarehouseInfo(warehousing_id, info)
  790. var warehousingInfo []*models.SupplierWarehousingInfoOrder
  791. var updateWarehousingInfo []*models.SupplierWarehousingInfoOrder
  792. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  793. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  794. if len(thisStockIn) > 0 {
  795. for _, item := range thisStockIn {
  796. items := item.(map[string]interface{})
  797. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  798. utils.ErrorLog("id")
  799. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  800. return
  801. }
  802. id := int64(items["id"].(float64))
  803. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  804. utils.ErrorLog("project_id")
  805. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  806. return
  807. }
  808. project_id := int64(items["project_id"].(float64))
  809. if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
  810. utils.ErrorLog("supply_count")
  811. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  812. return
  813. }
  814. supply_count := int64(items["supply_count"].(float64))
  815. if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
  816. utils.ErrorLog("supply_license_number")
  817. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  818. return
  819. }
  820. supply_license_number := items["supply_license_number"].(string)
  821. if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
  822. utils.ErrorLog("supply_price")
  823. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  824. return
  825. }
  826. supply_price := items["supply_price"].(string)
  827. supply_price_float, _ := strconv.ParseFloat(supply_price, 64)
  828. if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
  829. utils.ErrorLog("supply_remake")
  830. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  831. return
  832. }
  833. supply_remake := items["supply_remake"].(string)
  834. if items["supply_total_price"] == nil || reflect.TypeOf(items["supply_total_price"]).String() != "string" {
  835. utils.ErrorLog("supply_total_price")
  836. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  837. return
  838. }
  839. supply_total_price := items["supply_total_price"].(string)
  840. supply_total_price_float, _ := strconv.ParseFloat(supply_total_price, 64)
  841. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  842. utils.ErrorLog("type")
  843. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  844. return
  845. }
  846. is_source := int64(items["type"].(float64))
  847. if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
  848. utils.ErrorLog("supply_type")
  849. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  850. return
  851. }
  852. supply_type := items["supply_type"].(string)
  853. if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
  854. utils.ErrorLog("supply_specification_name")
  855. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  856. return
  857. }
  858. supply_specification_name := items["supply_specification_name"].(string)
  859. if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
  860. utils.ErrorLog("supply_total")
  861. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  862. return
  863. }
  864. supply_total := items["supply_total"].(string)
  865. if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
  866. utils.ErrorLog("supply_manufacturer")
  867. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  868. return
  869. }
  870. supply_manufacturer := items["supply_manufacturer"].(string)
  871. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  872. utils.ErrorLog("name")
  873. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  874. return
  875. }
  876. name := items["name"].(string)
  877. if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
  878. utils.ErrorLog("supply_unit")
  879. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  880. return
  881. }
  882. supply_unit := items["supply_unit"].(string)
  883. if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
  884. utils.ErrorLog("manufacturer_id")
  885. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  886. return
  887. }
  888. manufacturer_id := int64(items["manufacturer_id"].(float64))
  889. if id > 0 {
  890. order := models.SupplierWarehousingInfoOrder{
  891. ID: id,
  892. IsSource: is_source,
  893. Count: supply_count,
  894. Price: supply_price_float,
  895. Amount: supply_total_price_float,
  896. Remark: supply_remake,
  897. Ctime: time.Now().Unix(),
  898. Status: 1,
  899. Mtime: 0,
  900. ProjectId: project_id,
  901. SupplyLicenseNumber: supply_license_number,
  902. SupplyType: supply_type,
  903. SupplySpecificationName: supply_specification_name,
  904. SupplyTotal: supply_total,
  905. SupplyManufacturer: supply_manufacturer,
  906. Name: name,
  907. SupplyUnit: supply_unit,
  908. ManufacturerId: manufacturer_id,
  909. }
  910. updateWarehousingInfo = append(updateWarehousingInfo, &order)
  911. }
  912. if id == 0 {
  913. order := models.SupplierWarehousingInfoOrder{
  914. OrderNumber: number,
  915. IsSource: is_source,
  916. Count: supply_count,
  917. Price: supply_price_float,
  918. Amount: supply_total_price_float,
  919. Remark: supply_remake,
  920. UserOrgId: orgId,
  921. Ctime: time.Now().Unix(),
  922. Status: 1,
  923. Mtime: 0,
  924. WarehousingId: warehousing_id,
  925. ProjectId: project_id,
  926. SupplyLicenseNumber: supply_license_number,
  927. SupplyType: supply_type,
  928. SupplySpecificationName: supply_specification_name,
  929. SupplyTotal: supply_total,
  930. SupplyManufacturer: supply_manufacturer,
  931. Name: name,
  932. SupplyUnit: supply_unit,
  933. ManufacturerId: manufacturer_id,
  934. }
  935. warehousingInfo = append(warehousingInfo, &order)
  936. }
  937. }
  938. }
  939. if len(warehousingInfo) > 0 {
  940. for _, item := range warehousingInfo {
  941. service.CreateSupplyWarehousingOrder(item)
  942. }
  943. }
  944. if len(updateWarehousingInfo) > 0 {
  945. for _, item := range updateWarehousingInfo {
  946. service.ModifySupplyWarehouseOrder(item)
  947. }
  948. }
  949. this.ServeSuccessJSON(map[string]interface{}{
  950. "warehousingInfo": warehousingInfo,
  951. })
  952. }
  953. }
  954. func (this *SupplyOrderApiController) UpdateSupplyWaresing() {
  955. id, _ := this.GetInt64("id")
  956. recordDateStr := time.Now().Format("2006-01-02")
  957. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  958. record_date := recordDate.Unix()
  959. checker := this.GetAdminUserInfo().AdminUser.Id
  960. info := models.SupplierWarehouseInfo{
  961. Mtime: time.Now().Unix(),
  962. Status: 1,
  963. IsCheck: 1,
  964. Checker: checker,
  965. CheckTime: record_date,
  966. }
  967. parseDateErr := service.UpdateSupplyWaresing(id, info)
  968. if parseDateErr == nil {
  969. this.ServeSuccessJSON(map[string]interface{}{
  970. "info": info,
  971. })
  972. } else {
  973. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  974. }
  975. }
  976. func (this *SupplyOrderApiController) GetPurchaseOrderDetail() {
  977. id, _ := this.GetInt64("id")
  978. info, _ := service.GetPurchaseOrderDetail(id)
  979. //查询
  980. orderInfo, err := service.GetSupplyWarehousingOrderInfo(id)
  981. orgId := this.GetAdminUserInfo().CurrentOrgId
  982. supplyList, _ := service.GetSupplierList(orgId)
  983. //获取药品库数据
  984. baseList, _ := service.GetSupplyDrugList(orgId)
  985. goodList, _ := service.GetSupplyGoodList(orgId)
  986. if err == nil {
  987. this.ServeSuccessJSON(map[string]interface{}{
  988. "info": info,
  989. "orderInfo": orderInfo,
  990. "supplyList": supplyList,
  991. "baseList": baseList,
  992. "goodList": goodList,
  993. })
  994. } else {
  995. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  996. }
  997. }
  998. func (this *SupplyOrderApiController) AddGoodOrder() {
  999. dataBody := make(map[string]interface{}, 0)
  1000. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1001. if err != nil {
  1002. utils.ErrorLog(err.Error())
  1003. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1004. return
  1005. }
  1006. supplier_id, _ := this.GetInt64("supplier_id")
  1007. start_time := this.GetString("start")
  1008. timeLayout := "2006-01-02"
  1009. loc, _ := time.LoadLocation("Local")
  1010. var startTime int64
  1011. if len(start_time) > 0 {
  1012. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1013. if err != nil {
  1014. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1015. return
  1016. }
  1017. startTime = theTime.Unix()
  1018. }
  1019. arrerage := this.GetString("arrerage")
  1020. arrerage_float, _ := strconv.ParseFloat(arrerage, 64)
  1021. payment := this.GetString("payment")
  1022. payment_float, _ := strconv.ParseFloat(payment, 64)
  1023. warehousing_id, _ := this.GetInt64("warehousing_id")
  1024. number := this.GetString("number")
  1025. rate_of_concession := this.GetString("rate_of_concession")
  1026. rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
  1027. discount_amount := this.GetString("discount_amount")
  1028. discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
  1029. return_remake := dataBody["return_remake"].(string)
  1030. orgId := this.GetAdminUserInfo().CurrentOrgId
  1031. creater := this.GetAdminUserInfo().AdminUser.Id
  1032. //生成购货单
  1033. timeStr := time.Now().Format("2006-01-02")
  1034. timeArr := strings.Split(timeStr, "-")
  1035. total, _ := service.FindAllSupplyWarehouseOutOrder(orgId)
  1036. total = total + 1
  1037. warehousing_order := "CG" + timeArr[0] + timeArr[1] + timeArr[2] + "00" + strconv.FormatInt(total, 10)
  1038. recordDateStr := time.Now().Format("2006-01-02")
  1039. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1040. warehouse_out := models.SpSupplierWarehouseOut{
  1041. Number: number,
  1042. UserOrgId: orgId,
  1043. Creater: creater,
  1044. Ctime: time.Now().Unix(),
  1045. Mtime: 0,
  1046. Status: 1,
  1047. RecordDate: recordDate.Unix(),
  1048. IsCheck: 2,
  1049. WarehousingId: warehousing_id,
  1050. GoodNumber: warehousing_order,
  1051. Arrearage: arrerage_float,
  1052. Payment: payment_float,
  1053. RateOfConcession: rate_of_concession_float,
  1054. DiscountAmount: discount_amount_float,
  1055. DocumentDate: startTime,
  1056. SupplierId: supplier_id,
  1057. Checker: 0,
  1058. CheckTime: 0,
  1059. ReturnRemake: return_remake,
  1060. }
  1061. service.CreateSupplyWarehouseOut(warehouse_out)
  1062. //获取最后一条
  1063. warehouseOut, _ := service.FindSupplyWarehouseOutById(orgId)
  1064. var warehousingOut []*models.SpSupplierWarehousingOutOrder
  1065. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  1066. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  1067. if len(thisStockIn) > 0 {
  1068. for _, item := range thisStockIn {
  1069. items := item.(map[string]interface{})
  1070. if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
  1071. utils.ErrorLog("supply_count")
  1072. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1073. return
  1074. }
  1075. supply_count := int64(items["supply_count"].(float64))
  1076. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1077. utils.ErrorLog("id")
  1078. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1079. return
  1080. }
  1081. id := int64(items["id"].(float64))
  1082. if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
  1083. utils.ErrorLog("manufacturer_id")
  1084. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1085. return
  1086. }
  1087. manufacturer_id := int64(items["manufacturer_id"].(float64))
  1088. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  1089. utils.ErrorLog("name")
  1090. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1091. return
  1092. }
  1093. name := items["name"].(string)
  1094. if items["order_number"] == nil || reflect.TypeOf(items["order_number"]).String() != "string" {
  1095. utils.ErrorLog("order_number")
  1096. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1097. return
  1098. }
  1099. order_number := items["order_number"].(string)
  1100. if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
  1101. utils.ErrorLog("supply_price")
  1102. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1103. return
  1104. }
  1105. supply_price := items["supply_price"].(string)
  1106. price_float, _ := strconv.ParseFloat(supply_price, 64)
  1107. if items["supply_total_price"] == nil || reflect.TypeOf(items["supply_total_price"]).String() != "string" {
  1108. utils.ErrorLog("supply_total_price")
  1109. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1110. return
  1111. }
  1112. supply_total_price := items["supply_total_price"].(string)
  1113. supply_total_price_float, _ := strconv.ParseFloat(supply_total_price, 64)
  1114. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  1115. utils.ErrorLog("project_id")
  1116. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1117. return
  1118. }
  1119. project_id := int64(items["project_id"].(float64))
  1120. if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
  1121. utils.ErrorLog("supply_remake")
  1122. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1123. return
  1124. }
  1125. supply_remake := items["supply_remake"].(string)
  1126. if items["supply_batch_number"] == nil || reflect.TypeOf(items["supply_batch_number"]).String() != "string" {
  1127. utils.ErrorLog("supply_batch_number")
  1128. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1129. return
  1130. }
  1131. supply_batch_number := items["supply_batch_number"].(string)
  1132. var supply_expiry_date_time int64
  1133. if items["supply_expiry_date"] == nil || reflect.TypeOf(items["supply_expiry_date"]).String() != "string" {
  1134. utils.ErrorLog("supply_expiry_date")
  1135. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1136. return
  1137. }
  1138. supply_expiry_date := items["supply_expiry_date"].(string)
  1139. if len(supply_expiry_date) > 0 {
  1140. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", supply_expiry_date+" 00:00:00", loc)
  1141. if err != nil {
  1142. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1143. return
  1144. }
  1145. supply_expiry_date_time = theTime.Unix()
  1146. }
  1147. if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
  1148. utils.ErrorLog("supply_license_number")
  1149. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1150. return
  1151. }
  1152. supply_license_number := items["supply_license_number"].(string)
  1153. var supply_product_date_time int64
  1154. if items["supply_product_date"] == nil || reflect.TypeOf(items["supply_product_date"]).String() != "string" {
  1155. utils.ErrorLog("supply_product_date")
  1156. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1157. return
  1158. }
  1159. supply_product_date := items["supply_product_date"].(string)
  1160. if len(supply_product_date) > 0 {
  1161. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", supply_product_date+" 00:00:00", loc)
  1162. if err != nil {
  1163. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1164. return
  1165. }
  1166. supply_product_date_time = theTime.Unix()
  1167. }
  1168. if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
  1169. utils.ErrorLog("supply_specification_name")
  1170. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1171. return
  1172. }
  1173. supply_specification_name := items["supply_specification_name"].(string)
  1174. if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
  1175. utils.ErrorLog("supply_total")
  1176. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1177. return
  1178. }
  1179. supply_total := items["supply_total"].(string)
  1180. if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
  1181. utils.ErrorLog("supply_type")
  1182. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1183. return
  1184. }
  1185. supply_type := items["supply_type"].(string)
  1186. if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
  1187. utils.ErrorLog("supply_unit")
  1188. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1189. return
  1190. }
  1191. supply_unit := items["supply_unit"].(string)
  1192. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1193. utils.ErrorLog("type")
  1194. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1195. return
  1196. }
  1197. is_source := int64(items["type"].(float64))
  1198. if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
  1199. utils.ErrorLog("supply_manufacturer")
  1200. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1201. return
  1202. }
  1203. supply_manufacturer := items["supply_manufacturer"].(string)
  1204. order := models.SpSupplierWarehousingOutOrder{
  1205. OrderNumber: order_number,
  1206. ProjectId: project_id,
  1207. IsSource: is_source,
  1208. Count: supply_count,
  1209. Amount: supply_total_price_float,
  1210. Price: price_float,
  1211. Remark: supply_remake,
  1212. IsCheck: 2,
  1213. UserOrgId: orgId,
  1214. Status: 1,
  1215. Ctime: time.Now().Unix(),
  1216. Mtime: 0,
  1217. WarehouseOutId: warehouseOut.ID,
  1218. Type: 1,
  1219. SupplyBatchNumber: supply_batch_number,
  1220. SupplyProductDate: supply_product_date_time,
  1221. SupplyExpiryDate: supply_expiry_date_time,
  1222. WarehousingId: warehousing_id,
  1223. WarehouseInfoId: id,
  1224. SupplyType: supply_type,
  1225. SupplyUnit: supply_unit,
  1226. SupplyTotal: supply_total,
  1227. SupplySpecificationName: supply_specification_name,
  1228. SupplyLicenseNumber: supply_license_number,
  1229. Name: name,
  1230. ManufacturerId: manufacturer_id,
  1231. GoodNumber: warehouseOut.GoodNumber,
  1232. SupplyManufacturer: supply_manufacturer,
  1233. }
  1234. warehousingOut = append(warehousingOut, &order)
  1235. }
  1236. }
  1237. }
  1238. for _, item := range warehousingOut {
  1239. //如果是手动新增的,type 等于2
  1240. if item.WarehouseInfoId == 0 {
  1241. item.Type = 2
  1242. }
  1243. err = service.CreateSupplyWarehousOutOrder(item)
  1244. }
  1245. list, parseDateErr := service.GetSupplyWarehouseOutById(warehouseOut.ID, orgId)
  1246. if parseDateErr == nil {
  1247. this.ServeSuccessJSON(map[string]interface{}{
  1248. "list": list,
  1249. "warehouseOut": warehouseOut,
  1250. })
  1251. } else {
  1252. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1253. }
  1254. }
  1255. func (this *SupplyOrderApiController) GetAllGoodOderList() {
  1256. check_id, _ := this.GetInt64("check_id")
  1257. start_time := this.GetString("start_time")
  1258. end_time := this.GetString("end_time")
  1259. keyword := this.GetString("keyword")
  1260. page, _ := this.GetInt64("page")
  1261. limit, _ := this.GetInt64("limit")
  1262. timeLayout := "2006-01-02"
  1263. loc, _ := time.LoadLocation("Local")
  1264. var startTime int64
  1265. if len(start_time) > 0 {
  1266. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1267. if err != nil {
  1268. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1269. return
  1270. }
  1271. startTime = theTime.Unix()
  1272. }
  1273. var endTime int64
  1274. if len(end_time) > 0 {
  1275. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  1276. if err != nil {
  1277. utils.ErrorLog(err.Error())
  1278. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1279. return
  1280. }
  1281. endTime = theTime.Unix()
  1282. }
  1283. orgId := this.GetAdminUserInfo().CurrentOrgId
  1284. list, total, err := service.GetAllGoodOderList(check_id, keyword, page, limit, startTime, endTime, orgId)
  1285. if err == nil {
  1286. this.ServeSuccessJSON(map[string]interface{}{
  1287. "list": list,
  1288. "total": total,
  1289. })
  1290. } else {
  1291. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1292. }
  1293. }
  1294. func (this *SupplyOrderApiController) GetGoodOrderDetail() {
  1295. id, _ := this.GetInt64("id")
  1296. ids := this.GetString("ids")
  1297. orgId := this.GetAdminUserInfo().CurrentOrgId
  1298. if len(ids) == 0 {
  1299. out, err := service.GetGoodOrderDetail(id, orgId)
  1300. list, _ := service.GetSupplyWarehouseOutById(id, orgId)
  1301. drugList, _ := service.GetSupplyDrugList(orgId)
  1302. goodList, _ := service.GetSupplyGoodList(orgId)
  1303. if err == nil {
  1304. this.ServeSuccessJSON(map[string]interface{}{
  1305. "out": out,
  1306. "list": list,
  1307. "goodList": goodList,
  1308. "drugList": drugList,
  1309. })
  1310. } else {
  1311. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1312. }
  1313. }
  1314. if len(ids) > 0 {
  1315. idArray := strings.Split(ids, ",")
  1316. out, err := service.GetGoodOrderDetail(id, orgId)
  1317. list, _ := service.GetSupplyWarehouseOutByIdOne(id, orgId, idArray)
  1318. drugList, _ := service.GetSupplyDrugList(orgId)
  1319. goodList, _ := service.GetSupplyGoodList(orgId)
  1320. if err == nil {
  1321. this.ServeSuccessJSON(map[string]interface{}{
  1322. "out": out,
  1323. "list": list,
  1324. "goodList": goodList,
  1325. "drugList": drugList,
  1326. })
  1327. } else {
  1328. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1329. }
  1330. }
  1331. }
  1332. func (this *SupplyOrderApiController) UpdateGoodOrder() {
  1333. supplier_id, _ := this.GetInt64("supplier_id")
  1334. start_time := this.GetString("start")
  1335. timeLayout := "2006-01-02"
  1336. loc, _ := time.LoadLocation("Local")
  1337. var startTime int64
  1338. if len(start_time) > 0 {
  1339. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1340. if err != nil {
  1341. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1342. return
  1343. }
  1344. startTime = theTime.Unix()
  1345. }
  1346. arrerage := this.GetString("arrerage")
  1347. arrerage_float, _ := strconv.ParseFloat(arrerage, 64)
  1348. payment := this.GetString("payment")
  1349. payment_float, _ := strconv.ParseFloat(payment, 64)
  1350. warehose_out_id, _ := this.GetInt64("warehose_out_id")
  1351. number := this.GetString("number")
  1352. rate_of_concession := this.GetString("rate_of_concession")
  1353. rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
  1354. discount_amount := this.GetString("discount_amount")
  1355. discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
  1356. good_number := this.GetString("good_number")
  1357. fmt.Println(supplier_id, startTime, arrerage, payment, warehose_out_id, number, rate_of_concession, discount_amount)
  1358. orgId := this.GetAdminUserInfo().CurrentOrgId
  1359. dataBody := make(map[string]interface{}, 0)
  1360. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1361. if err != nil {
  1362. utils.ErrorLog(err.Error())
  1363. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1364. return
  1365. }
  1366. var warehousingOut []*models.SpSupplierWarehousingOutOrder
  1367. var updateWarehout []*models.SpSupplierWarehousingOutOrder
  1368. return_remake := dataBody["return_remake"].(string)
  1369. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  1370. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  1371. if len(thisStockIn) > 0 {
  1372. for _, item := range thisStockIn {
  1373. items := item.(map[string]interface{})
  1374. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1375. utils.ErrorLog("id")
  1376. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1377. return
  1378. }
  1379. id := int64(items["id"].(float64))
  1380. if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
  1381. utils.ErrorLog("supply_count")
  1382. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1383. return
  1384. }
  1385. supply_count := int64(items["supply_count"].(float64))
  1386. if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
  1387. utils.ErrorLog("manufacturer_id")
  1388. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1389. return
  1390. }
  1391. manufacturer_id := int64(items["manufacturer_id"].(float64))
  1392. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  1393. utils.ErrorLog("name")
  1394. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1395. return
  1396. }
  1397. name := items["name"].(string)
  1398. if items["order_number"] == nil || reflect.TypeOf(items["order_number"]).String() != "string" {
  1399. utils.ErrorLog("order_number")
  1400. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1401. return
  1402. }
  1403. order_number := items["order_number"].(string)
  1404. if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
  1405. utils.ErrorLog("supply_price")
  1406. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1407. return
  1408. }
  1409. supply_price := items["supply_price"].(string)
  1410. price_float, _ := strconv.ParseFloat(supply_price, 64)
  1411. if items["supply_total_price"] == nil || reflect.TypeOf(items["supply_total_price"]).String() != "string" {
  1412. utils.ErrorLog("supply_total_price")
  1413. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1414. return
  1415. }
  1416. supply_total_price := items["supply_total_price"].(string)
  1417. supply_total_price_float, _ := strconv.ParseFloat(supply_total_price, 64)
  1418. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  1419. utils.ErrorLog("project_id")
  1420. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1421. return
  1422. }
  1423. project_id := int64(items["project_id"].(float64))
  1424. if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
  1425. utils.ErrorLog("supply_remake")
  1426. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1427. return
  1428. }
  1429. supply_remake := items["supply_remake"].(string)
  1430. if items["supply_batch_number"] == nil || reflect.TypeOf(items["supply_batch_number"]).String() != "string" {
  1431. utils.ErrorLog("supply_batch_number")
  1432. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1433. return
  1434. }
  1435. supply_batch_number := items["supply_batch_number"].(string)
  1436. var supply_expiry_date_time int64
  1437. if items["supply_expiry_date"] == nil || reflect.TypeOf(items["supply_expiry_date"]).String() != "string" {
  1438. utils.ErrorLog("supply_expiry_date")
  1439. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1440. return
  1441. }
  1442. supply_expiry_date := items["supply_expiry_date"].(string)
  1443. if len(supply_expiry_date) > 0 {
  1444. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", supply_expiry_date+" 00:00:00", loc)
  1445. if err != nil {
  1446. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1447. return
  1448. }
  1449. supply_expiry_date_time = theTime.Unix()
  1450. }
  1451. if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
  1452. utils.ErrorLog("supply_license_number")
  1453. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1454. return
  1455. }
  1456. supply_license_number := items["supply_license_number"].(string)
  1457. var supply_product_date_time int64
  1458. if items["supply_product_date"] == nil || reflect.TypeOf(items["supply_product_date"]).String() != "string" {
  1459. utils.ErrorLog("supply_product_date")
  1460. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1461. return
  1462. }
  1463. supply_product_date := items["supply_product_date"].(string)
  1464. if len(supply_product_date) > 0 {
  1465. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", supply_product_date+" 00:00:00", loc)
  1466. if err != nil {
  1467. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1468. return
  1469. }
  1470. supply_product_date_time = theTime.Unix()
  1471. }
  1472. if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
  1473. utils.ErrorLog("supply_specification_name")
  1474. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1475. return
  1476. }
  1477. supply_specification_name := items["supply_specification_name"].(string)
  1478. if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
  1479. utils.ErrorLog("supply_total")
  1480. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1481. return
  1482. }
  1483. supply_total := items["supply_total"].(string)
  1484. if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
  1485. utils.ErrorLog("supply_type")
  1486. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1487. return
  1488. }
  1489. supply_type := items["supply_type"].(string)
  1490. if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
  1491. utils.ErrorLog("supply_unit")
  1492. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1493. return
  1494. }
  1495. supply_unit := items["supply_unit"].(string)
  1496. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1497. utils.ErrorLog("type")
  1498. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1499. return
  1500. }
  1501. is_source := int64(items["type"].(float64))
  1502. if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
  1503. utils.ErrorLog("supply_manufacturer")
  1504. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1505. return
  1506. }
  1507. supply_manufacturer := items["supply_manufacturer"].(string)
  1508. if items["warehouse_info_id"] == nil || reflect.TypeOf(items["warehouse_info_id"]).String() != "float64" {
  1509. utils.ErrorLog("warehouse_info_id")
  1510. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1511. return
  1512. }
  1513. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  1514. if items["warehousing_id"] == nil || reflect.TypeOf(items["warehousing_id"]).String() != "float64" {
  1515. utils.ErrorLog("warehouse_info_id")
  1516. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1517. return
  1518. }
  1519. warehousing_id := int64(items["warehousing_id"].(float64))
  1520. if id > 0 {
  1521. order := models.SpSupplierWarehousingOutOrder{
  1522. ID: id,
  1523. OrderNumber: order_number,
  1524. ProjectId: project_id,
  1525. IsSource: is_source,
  1526. Count: supply_count,
  1527. Amount: supply_total_price_float,
  1528. Price: price_float,
  1529. Remark: supply_remake,
  1530. IsCheck: 2,
  1531. UserOrgId: orgId,
  1532. Status: 1,
  1533. Ctime: time.Now().Unix(),
  1534. Mtime: 0,
  1535. WarehouseOutId: warehose_out_id,
  1536. Type: 1,
  1537. SupplyBatchNumber: supply_batch_number,
  1538. SupplyProductDate: supply_product_date_time,
  1539. SupplyExpiryDate: supply_expiry_date_time,
  1540. SupplyType: supply_type,
  1541. SupplyUnit: supply_unit,
  1542. SupplyTotal: supply_total,
  1543. SupplySpecificationName: supply_specification_name,
  1544. SupplyLicenseNumber: supply_license_number,
  1545. Name: name,
  1546. ManufacturerId: manufacturer_id,
  1547. GoodNumber: good_number,
  1548. SupplyManufacturer: supply_manufacturer,
  1549. WarehouseInfoId: warehouse_info_id,
  1550. WarehousingId: warehousing_id,
  1551. }
  1552. updateWarehout = append(updateWarehout, &order)
  1553. }
  1554. if id == 0 {
  1555. order := models.SpSupplierWarehousingOutOrder{
  1556. OrderNumber: order_number,
  1557. ProjectId: project_id,
  1558. IsSource: is_source,
  1559. Count: supply_count,
  1560. Amount: supply_total_price_float,
  1561. Price: price_float,
  1562. Remark: supply_remake,
  1563. IsCheck: 2,
  1564. UserOrgId: orgId,
  1565. Status: 1,
  1566. Ctime: time.Now().Unix(),
  1567. Mtime: 0,
  1568. WarehouseOutId: warehose_out_id,
  1569. Type: 1,
  1570. SupplyBatchNumber: supply_batch_number,
  1571. SupplyProductDate: supply_product_date_time,
  1572. SupplyExpiryDate: supply_expiry_date_time,
  1573. WarehouseInfoId: id,
  1574. SupplyType: supply_type,
  1575. SupplyUnit: supply_unit,
  1576. SupplyTotal: supply_total,
  1577. SupplySpecificationName: supply_specification_name,
  1578. SupplyLicenseNumber: supply_license_number,
  1579. Name: name,
  1580. ManufacturerId: manufacturer_id,
  1581. GoodNumber: good_number,
  1582. SupplyManufacturer: supply_manufacturer,
  1583. }
  1584. warehousingOut = append(warehousingOut, &order)
  1585. }
  1586. }
  1587. }
  1588. }
  1589. out := models.SpSupplierWarehouseOut{
  1590. Arrearage: arrerage_float,
  1591. Payment: payment_float,
  1592. RateOfConcession: rate_of_concession_float,
  1593. DiscountAmount: discount_amount_float,
  1594. SupplierId: supplier_id,
  1595. DocumentDate: startTime,
  1596. ReturnRemake: return_remake,
  1597. }
  1598. //更改购货单据
  1599. service.UpdateGoodWarehouseOut(warehose_out_id, out)
  1600. for _, item := range warehousingOut {
  1601. //如果是手动新增的,type 等于2
  1602. if item.WarehouseInfoId == 0 {
  1603. item.Type = 2
  1604. }
  1605. err = service.CreateSupplyWarehousOutOrder(item)
  1606. }
  1607. for _, item := range updateWarehout {
  1608. service.UpdateGoodWarehouseOutOrder(item)
  1609. }
  1610. if err == nil {
  1611. this.ServeSuccessJSON(map[string]interface{}{
  1612. "out": out,
  1613. })
  1614. } else {
  1615. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1616. }
  1617. }
  1618. func (this *SupplyOrderApiController) DeletePurchOrder() {
  1619. id, _ := this.GetInt64("id")
  1620. orgId := this.GetAdminUserInfo().CurrentOrgId
  1621. err := service.DeletePurchOrder(id, orgId)
  1622. if err == nil {
  1623. returnData := make(map[string]interface{}, 0)
  1624. returnData["msg"] = "ok"
  1625. this.ServeSuccessJSON(returnData)
  1626. return
  1627. } else {
  1628. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1629. }
  1630. }
  1631. func (this *SupplyOrderApiController) GetAllOrderCountList() {
  1632. id, _ := this.GetInt64("id")
  1633. orgId := this.GetAdminUserInfo().CurrentOrgId
  1634. //获取购货订单的数据
  1635. purcaseOrder, _ := service.GetAllPurcaseOrderById(id, orgId)
  1636. //获取购货单的数据
  1637. goodOrder, err := service.GetAllGoodOrderById(id, orgId)
  1638. drugList, err := service.GetSupplyDrugList(orgId)
  1639. if err == nil {
  1640. this.ServeSuccessJSON(map[string]interface{}{
  1641. "purcaseOrder": purcaseOrder,
  1642. "goodOrder": goodOrder,
  1643. "drugList": drugList,
  1644. })
  1645. } else {
  1646. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1647. }
  1648. }
  1649. func (this *SupplyOrderApiController) GetPurchOrderInfo() {
  1650. id, _ := this.GetInt64("id")
  1651. ids := this.GetString("ids")
  1652. if len(ids) == 0 {
  1653. info, _ := service.GetPurchaseOrderDetail(id)
  1654. //查询
  1655. orderInfo, err := service.GetSupplyWarehousingOrderInfo(id)
  1656. orgId := this.GetAdminUserInfo().CurrentOrgId
  1657. supplyList, _ := service.GetSupplierList(orgId)
  1658. //获取药品库数据
  1659. baseList, _ := service.GetSupplyDrugList(orgId)
  1660. goodList, _ := service.GetSupplyGoodList(orgId)
  1661. if err == nil {
  1662. this.ServeSuccessJSON(map[string]interface{}{
  1663. "info": info,
  1664. "orderInfo": orderInfo,
  1665. "supplyList": supplyList,
  1666. "baseList": baseList,
  1667. "goodList": goodList,
  1668. })
  1669. } else {
  1670. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1671. }
  1672. }
  1673. if len(ids) > 0 {
  1674. idArray := strings.Split(ids, ",")
  1675. info, _ := service.GetPurchaseOrderDetail(id)
  1676. //查询
  1677. orderInfo, err := service.GetSupplyWarehousingOrderInfoTwo(id, idArray)
  1678. orgId := this.GetAdminUserInfo().CurrentOrgId
  1679. supplyList, _ := service.GetSupplierList(orgId)
  1680. //获取药品库数据
  1681. baseList, _ := service.GetSupplyDrugList(orgId)
  1682. goodList, _ := service.GetSupplyGoodList(orgId)
  1683. if err == nil {
  1684. this.ServeSuccessJSON(map[string]interface{}{
  1685. "info": info,
  1686. "orderInfo": orderInfo,
  1687. "supplyList": supplyList,
  1688. "baseList": baseList,
  1689. "goodList": goodList,
  1690. })
  1691. } else {
  1692. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1693. }
  1694. }
  1695. }
  1696. func (this *SupplyOrderApiController) GetGoodOrderList() {
  1697. id, _ := this.GetInt64("id")
  1698. orgId := this.GetAdminUserInfo().CurrentOrgId
  1699. list, err := service.GetGoodOrderList(id, orgId)
  1700. if err == nil {
  1701. this.ServeSuccessJSON(map[string]interface{}{
  1702. "list": list,
  1703. })
  1704. } else {
  1705. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1706. }
  1707. }
  1708. func (this *SupplyOrderApiController) GetReturnOrder() {
  1709. id, _ := this.GetInt64("id")
  1710. orgId := this.GetAdminUserInfo().CurrentOrgId
  1711. err := service.GetReturnOrder(id, orgId)
  1712. if err == nil {
  1713. returnData := make(map[string]interface{}, 0)
  1714. returnData["msg"] = "ok"
  1715. this.ServeSuccessJSON(returnData)
  1716. return
  1717. } else {
  1718. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1719. }
  1720. }
  1721. func (this *SupplyOrderApiController) GetGoodOrderCountList() {
  1722. id, _ := this.GetInt64("id")
  1723. warehousing_id, _ := this.GetInt64("warehousing_id")
  1724. orgId := this.GetAdminUserInfo().CurrentOrgId
  1725. checker := this.GetAdminUserInfo().AdminUser.Id
  1726. recordDateStr := time.Now().Format("2006-01-02")
  1727. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1728. record_date := recordDate.Unix()
  1729. out := models.SpSupplierWarehouseOut{
  1730. IsCheck: 1,
  1731. Checker: checker,
  1732. CheckTime: record_date,
  1733. }
  1734. err := service.CheckGoodOrder(id, orgId, out)
  1735. fmt.Println(err)
  1736. //获取购货订单的数据
  1737. purcaseOrder, _ := service.GetAllPurcaseOrderById(warehousing_id, orgId)
  1738. //获取购货单的数据
  1739. goodOrder, _ := service.GetAllGoodOrderByIdTwo(warehousing_id, orgId)
  1740. //查询该购货单是否审核成功
  1741. detail, _ := service.GetGoodOrderDetail(id, orgId)
  1742. var warehousingInfo []*models.WarehousingInfo
  1743. var warehouseInfoDetail []*models.DrugWarehouseInfo
  1744. var drugFlow []*models.DrugFlow
  1745. //如果审核成功
  1746. if detail.IsCheck == 1 {
  1747. //入库
  1748. if len(goodOrder) > 0 {
  1749. for _, item := range goodOrder {
  1750. //药品
  1751. if item.IsSource == 1 {
  1752. //获取药品类型
  1753. medical, _ := service.GetBaseDrugMedical(item.ID)
  1754. timeStr := time.Now().Format("2006-01-02")
  1755. timeArr := strings.Split(timeStr, "-")
  1756. total, _ := service.FindAllWarehouseTotalOne(orgId)
  1757. total = total + 1
  1758. warehousing_order := "YPRKD" + strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1759. operation_time := time.Now().Unix()
  1760. warehousing := models.DrugWarehouse{
  1761. WarehousingOrder: warehousing_order,
  1762. OperationTime: operation_time,
  1763. OrgId: orgId,
  1764. Creater: checker,
  1765. Ctime: time.Now().Unix(),
  1766. Status: 1,
  1767. WarehousingTime: record_date,
  1768. Type: 1,
  1769. SupplyWarehouseId: id,
  1770. }
  1771. //查询今日是否存在入库单号
  1772. _, errcode := service.GetSingleDrugWarehouseOrder(record_date, orgId)
  1773. if errcode == gorm.ErrRecordNotFound {
  1774. service.AddSigleDrugWarehouse(&warehousing)
  1775. }
  1776. drugWarehouseInfo, _ := service.GetLastDrugWarehouse(orgId)
  1777. warehouseInfoDetailOne := &models.DrugWarehouseInfo{
  1778. WarehousingOrder: drugWarehouseInfo.WarehousingOrder,
  1779. WarehousingId: drugWarehouseInfo.ID,
  1780. DrugId: item.ProjectId,
  1781. Number: item.SupplyLicenseNumber,
  1782. ProductDate: item.SupplyProductDate,
  1783. ExpiryDate: item.SupplyExpiryDate,
  1784. WarehousingCount: item.Count,
  1785. Price: item.Price,
  1786. TotalPrice: 0,
  1787. Status: 1,
  1788. Ctime: time.Now().Unix(),
  1789. Remark: item.Remark,
  1790. OrgId: orgId,
  1791. Type: 1,
  1792. Manufacturer: item.ManufacturerId,
  1793. Dealer: 0,
  1794. StockMaxNumber: item.Count,
  1795. RetailTotalPrice: 0,
  1796. BatchNumber: item.SupplyBatchNumber,
  1797. MaxUnit: item.SupplyUnit,
  1798. MinUnit: item.SupplyUnit,
  1799. RetailPrice: medical.MinPrice,
  1800. SupplyWarehouseId: id,
  1801. }
  1802. if medical.MaxUnit == medical.MinUnit {
  1803. warehouseInfoDetailOne.StockMaxNumber = item.Count
  1804. warehouseInfoDetailOne.StockMinNumber = 0
  1805. warehouseInfoDetailOne.MaxUnit = item.SupplyUnit
  1806. }
  1807. if item.SupplyUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  1808. warehouseInfoDetailOne.StockMaxNumber = 0
  1809. warehouseInfoDetailOne.StockMinNumber = item.Count
  1810. warehouseInfoDetailOne.MaxUnit = item.SupplyUnit
  1811. }
  1812. warehouseInfoDetail = append(warehouseInfoDetail, warehouseInfoDetailOne)
  1813. drugflow := &models.DrugFlow{
  1814. WarehousingOrder: drugWarehouseInfo.WarehousingOrder,
  1815. WarehousingId: drugWarehouseInfo.ID,
  1816. DrugId: item.ProjectId,
  1817. Number: item.SupplyBatchNumber,
  1818. ProductDate: item.SupplyProductDate,
  1819. ExpireDate: item.SupplyExpiryDate,
  1820. Count: item.Count,
  1821. Price: item.Price,
  1822. Status: 1,
  1823. Ctime: time.Now().Unix(),
  1824. UserOrgId: orgId,
  1825. Manufacturer: item.ManufacturerId,
  1826. Dealer: 0,
  1827. BatchNumber: item.SupplyBatchNumber,
  1828. MaxUnit: item.SupplyUnit,
  1829. MinUnit: item.SupplyUnit,
  1830. ConsumableType: 1,
  1831. IsEdit: 1,
  1832. Creator: checker,
  1833. IsSys: 0,
  1834. SupplyWarehouseId: id,
  1835. }
  1836. if medical.MaxUnit == medical.MinUnit {
  1837. drugflow.MaxUnit = item.SupplyUnit
  1838. }
  1839. if item.SupplyUnit == medical.MinUnit {
  1840. warehouseInfoDetailOne.MaxUnit = warehouseInfoDetailOne.MinUnit
  1841. }
  1842. drugFlow = append(drugFlow, drugflow)
  1843. }
  1844. //耗材
  1845. if item.IsSource == 2 {
  1846. //获取耗材类型
  1847. good, _ := service.GetGoodInformationByGoodId(item.ProjectId)
  1848. timeStr := time.Now().Format("2006-01-02")
  1849. timeArr := strings.Split(timeStr, "-")
  1850. total, _ := service.FindAllWarehouseTotal(orgId)
  1851. total = total + 1
  1852. warehousing_order := "RKD" + strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1853. operation_time := time.Now().Unix()
  1854. creater := this.GetAdminUserInfo().AdminUser.Id
  1855. warehousing := models.Warehousing{
  1856. WarehousingOrder: warehousing_order,
  1857. OperationTime: operation_time,
  1858. OrgId: orgId,
  1859. Creater: creater,
  1860. Ctime: time.Now().Unix(),
  1861. Status: 1,
  1862. WarehousingTime: record_date,
  1863. Type: 1,
  1864. SupplyWarehouseId: id,
  1865. }
  1866. //查询是否存在入库单
  1867. _, errcose := service.GetSindleWarehouse(record_date, orgId)
  1868. if errcose == gorm.ErrRecordNotFound {
  1869. service.AddSigleWarehouse(&warehousing)
  1870. }
  1871. info, _ := service.GetLastWarehouseInfoByInfo(orgId)
  1872. //入库单表格
  1873. warehouseInfo := &models.WarehousingInfo{
  1874. WarehousingOrder: info.WarehousingOrder,
  1875. WarehousingId: info.ID,
  1876. GoodId: item.ProjectId,
  1877. Number: item.SupplyBatchNumber,
  1878. GoodTypeId: good.GoodTypeId,
  1879. ProductDate: item.SupplyProductDate,
  1880. ExpiryDate: item.SupplyExpiryDate,
  1881. WarehousingCount: item.Count,
  1882. Price: item.Price,
  1883. TotalPrice: 0,
  1884. Status: 1,
  1885. Ctime: time.Now().Unix(),
  1886. Remark: item.Remark,
  1887. OrgId: orgId,
  1888. Type: 1,
  1889. Manufacturer: item.ManufacturerId,
  1890. StockCount: item.Count,
  1891. Dealer: good.Dealer,
  1892. LicenseNumber: item.SupplyLicenseNumber,
  1893. PackingPrice: good.PackingPrice,
  1894. SupplyWarehouseId: id,
  1895. }
  1896. warehousingInfo = append(warehousingInfo, warehouseInfo)
  1897. }
  1898. }
  1899. }
  1900. }
  1901. for _, item := range warehousingInfo {
  1902. service.CreatedWarehouseingDetail(item)
  1903. warehousinginfo, _ := service.GetLastWarehousingInfo(item.GoodId)
  1904. flow := models.VmStockFlow{
  1905. WarehousingOrder: item.WarehousingOrder,
  1906. WarehousingId: item.ID,
  1907. GoodId: item.GoodId,
  1908. Number: item.Number,
  1909. ProductDate: item.ProductDate,
  1910. ExpireDate: item.ExpiryDate,
  1911. Count: item.WarehousingCount,
  1912. Price: item.Price,
  1913. Status: 1,
  1914. Ctime: time.Now().Unix(),
  1915. UserOrgId: orgId,
  1916. Manufacturer: item.Manufacturer,
  1917. Dealer: item.Dealer,
  1918. LicenseNumber: item.LicenseNumber,
  1919. IsEdit: 1,
  1920. Creator: checker,
  1921. SystemTime: record_date,
  1922. ConsumableType: 1,
  1923. WarehousingDetailId: warehousinginfo.ID,
  1924. SupplyWarehouseId: id,
  1925. }
  1926. service.CreateStockFlowOne(flow)
  1927. }
  1928. //创建入库单
  1929. errs := service.CreateDrugWarehousingInfo(warehouseInfoDetail)
  1930. fmt.Println(errs)
  1931. for _, items := range drugFlow {
  1932. drugWarehouseInfo, _ := service.GetLastDrugWarehouseInfo(items.DrugId)
  1933. items.WarehousingDetailId = drugWarehouseInfo.ID
  1934. }
  1935. //创建流水单
  1936. service.CreateDrugFlow(drugFlow)
  1937. drugList, _ := service.GetSupplyDrugList(orgId)
  1938. if err == nil {
  1939. this.ServeSuccessJSON(map[string]interface{}{
  1940. "purcaseOrder": purcaseOrder,
  1941. "goodOrder": goodOrder,
  1942. "drugList": drugList,
  1943. })
  1944. } else {
  1945. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1946. }
  1947. }
  1948. func (this *SupplyOrderApiController) ModefySupplyWarehousing() {
  1949. is_warehouse, _ := this.GetInt64("is_warehouse")
  1950. warehousing_id, _ := this.GetInt64("warehousing_id")
  1951. orgId := this.GetAdminUserInfo().CurrentOrgId
  1952. err := service.ModefySupplyWarehousing(is_warehouse, warehousing_id, orgId)
  1953. if err == nil {
  1954. returnData := make(map[string]interface{}, 0)
  1955. returnData["msg"] = "ok"
  1956. this.ServeSuccessJSON(returnData)
  1957. return
  1958. } else {
  1959. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1960. }
  1961. }
  1962. func (this *SupplyOrderApiController) SaveGoodReturnOrder() {
  1963. dataBody := make(map[string]interface{}, 0)
  1964. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1965. if err != nil {
  1966. utils.ErrorLog(err.Error())
  1967. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1968. return
  1969. }
  1970. return_remark := dataBody["return_marke"].(string)
  1971. supplier_id, _ := this.GetInt64("supplier_id")
  1972. start_time := this.GetString("start")
  1973. timeLayout := "2006-01-02"
  1974. loc, _ := time.LoadLocation("Local")
  1975. var startTime int64
  1976. if len(start_time) > 0 {
  1977. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1978. if err != nil {
  1979. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1980. return
  1981. }
  1982. startTime = theTime.Unix()
  1983. }
  1984. warehouse_out_id, _ := this.GetInt64("warehouse_out_id")
  1985. arrerage := this.GetString("arrerage")
  1986. arrerage_float, _ := strconv.ParseFloat(arrerage, 64)
  1987. payment := this.GetString("payment")
  1988. payment_float, _ := strconv.ParseFloat(payment, 64)
  1989. rate_of_concession := this.GetString("rate_of_concession")
  1990. rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
  1991. discount_amount := this.GetString("discount_amount")
  1992. discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
  1993. orgId := this.GetAdminUserInfo().CurrentOrgId
  1994. total, _ := service.GetSupplyCancelOrder(orgId)
  1995. creater := this.GetAdminUserInfo().AdminUser.Id
  1996. //生成购货单
  1997. timeStr := time.Now().Format("2006-01-02")
  1998. timeArr := strings.Split(timeStr, "-")
  1999. total = total + 1
  2000. warehousing_order := "CGT" + timeArr[0] + timeArr[1] + timeArr[2] + "00" + strconv.FormatInt(total, 10)
  2001. recordDateStr := time.Now().Format("2006-01-02")
  2002. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2003. cancel := models.SpSupplierWarehouseCancel{
  2004. Number: warehousing_order,
  2005. UserOrgId: orgId,
  2006. Creater: creater,
  2007. Ctime: time.Now().Unix(),
  2008. Mtime: 0,
  2009. Status: 1,
  2010. RecordDate: recordDate.Unix(),
  2011. IsCheck: 2,
  2012. WarehouseOutId: warehouse_out_id,
  2013. RateOfConcession: rate_of_concession_float,
  2014. DiscountAmount: discount_amount_float,
  2015. DocumentDate: startTime,
  2016. SupplierId: supplier_id,
  2017. Checker: 0,
  2018. CheckTime: 0,
  2019. Arrearage: arrerage_float,
  2020. Payment: payment_float,
  2021. ReturnRemark: return_remark,
  2022. }
  2023. err = service.CreateReturnCacelOrder(cancel)
  2024. order, _ := service.GetLastReturnCancelOrder(orgId)
  2025. var warehouseCancel []*models.SpSupplierWarehousingCancelOrder
  2026. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  2027. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  2028. if len(thisStockIn) > 0 {
  2029. for _, item := range thisStockIn {
  2030. items := item.(map[string]interface{})
  2031. if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
  2032. utils.ErrorLog("supply_count")
  2033. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2034. return
  2035. }
  2036. supply_count := int64(items["supply_count"].(float64))
  2037. if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
  2038. utils.ErrorLog("manufacturer_id")
  2039. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2040. return
  2041. }
  2042. manufacturer_id := int64(items["manufacturer_id"].(float64))
  2043. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  2044. utils.ErrorLog("name")
  2045. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2046. return
  2047. }
  2048. name := items["name"].(string)
  2049. if items["order_number"] == nil || reflect.TypeOf(items["order_number"]).String() != "string" {
  2050. utils.ErrorLog("order_number")
  2051. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2052. return
  2053. }
  2054. order_number := items["order_number"].(string)
  2055. if items["good_number"] == nil || reflect.TypeOf(items["good_number"]).String() != "string" {
  2056. utils.ErrorLog("good_number")
  2057. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2058. return
  2059. }
  2060. good_number := items["good_number"].(string)
  2061. if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
  2062. utils.ErrorLog("supply_price")
  2063. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2064. return
  2065. }
  2066. supply_price := items["supply_price"].(string)
  2067. price_float, _ := strconv.ParseFloat(supply_price, 64)
  2068. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  2069. utils.ErrorLog("project_id")
  2070. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2071. return
  2072. }
  2073. project_id := int64(items["project_id"].(float64))
  2074. if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
  2075. utils.ErrorLog("supply_remake")
  2076. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2077. return
  2078. }
  2079. supply_remake := items["supply_remake"].(string)
  2080. if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
  2081. utils.ErrorLog("supply_license_number")
  2082. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2083. return
  2084. }
  2085. supply_license_number := items["supply_license_number"].(string)
  2086. if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
  2087. utils.ErrorLog("supply_specification_name")
  2088. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2089. return
  2090. }
  2091. supply_specification_name := items["supply_specification_name"].(string)
  2092. if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
  2093. utils.ErrorLog("supply_total")
  2094. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2095. return
  2096. }
  2097. supply_total := items["supply_total"].(string)
  2098. if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
  2099. utils.ErrorLog("supply_type")
  2100. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2101. return
  2102. }
  2103. supply_type := items["supply_type"].(string)
  2104. if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
  2105. utils.ErrorLog("supply_unit")
  2106. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2107. return
  2108. }
  2109. supply_unit := items["supply_unit"].(string)
  2110. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2111. utils.ErrorLog("type")
  2112. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2113. return
  2114. }
  2115. is_source := int64(items["type"].(float64))
  2116. if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
  2117. utils.ErrorLog("supply_manufacturer")
  2118. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2119. return
  2120. }
  2121. supply_manufacturer := items["supply_manufacturer"].(string)
  2122. cancelOrder := &models.SpSupplierWarehousingCancelOrder{
  2123. ManufacturerId: manufacturer_id,
  2124. OrderNumber: order_number,
  2125. ProjectId: project_id,
  2126. GoodNumber: good_number,
  2127. IsSource: is_source,
  2128. Count: supply_count,
  2129. Price: price_float,
  2130. Remark: supply_remake,
  2131. RateOfConcession: rate_of_concession_float,
  2132. DiscountAmount: discount_amount_float,
  2133. UserOrgId: orgId,
  2134. Ctime: time.Now().Unix(),
  2135. Status: 1,
  2136. Mtime: 0,
  2137. WarehouseCancelId: order.ID,
  2138. Type: 1,
  2139. ReturnNumber: order.Number,
  2140. WarehouseOutId: warehouse_out_id,
  2141. SupplySpecificationName: supply_specification_name,
  2142. SupplyType: supply_type,
  2143. SupplyTotal: supply_total,
  2144. SupplyManufacturer: supply_manufacturer,
  2145. Name: name,
  2146. SupplyUnit: supply_unit,
  2147. SupplyLicenseNumber: supply_license_number,
  2148. }
  2149. warehouseCancel = append(warehouseCancel, cancelOrder)
  2150. }
  2151. }
  2152. }
  2153. for _, item := range warehouseCancel {
  2154. service.CreateCancelReturnOrder(item)
  2155. }
  2156. cancelOrder, err := service.GetReturnCancelOrder(order.ID, orgId)
  2157. list, err := service.GetReturnCancelOrderList(order.ID, orgId)
  2158. if err == nil {
  2159. this.ServeSuccessJSON(map[string]interface{}{
  2160. "warehouseCancel": warehouseCancel,
  2161. "cancelOrder": cancelOrder,
  2162. "list": list,
  2163. })
  2164. } else {
  2165. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2166. }
  2167. }
  2168. func (this *SupplyOrderApiController) GetAllGoodReturnOrderList() {
  2169. check_id, _ := this.GetInt64("check_id")
  2170. start_time := this.GetString("start_time")
  2171. end_time := this.GetString("end_time")
  2172. keyword := this.GetString("keyword")
  2173. page, _ := this.GetInt64("page")
  2174. limit, _ := this.GetInt64("limit")
  2175. timeLayout := "2006-01-02"
  2176. loc, _ := time.LoadLocation("Local")
  2177. var startTime int64
  2178. if len(start_time) > 0 {
  2179. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2180. if err != nil {
  2181. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2182. return
  2183. }
  2184. startTime = theTime.Unix()
  2185. }
  2186. var endTime int64
  2187. if len(end_time) > 0 {
  2188. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  2189. if err != nil {
  2190. utils.ErrorLog(err.Error())
  2191. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2192. return
  2193. }
  2194. endTime = theTime.Unix()
  2195. }
  2196. orgId := this.GetAdminUserInfo().CurrentOrgId
  2197. list, total, err := service.GetAllGoodReturnOrderList(check_id, keyword, page, limit, startTime, endTime, orgId)
  2198. if err == nil {
  2199. this.ServeSuccessJSON(map[string]interface{}{
  2200. "total": total,
  2201. "list": list,
  2202. })
  2203. } else {
  2204. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2205. }
  2206. }
  2207. func (this *SupplyOrderApiController) GetGoodReturnDetail() {
  2208. id, _ := this.GetInt64("id")
  2209. orgId := this.GetAdminUserInfo().CurrentOrgId
  2210. detail, err := service.GetGoodReturnDetail(id, orgId)
  2211. orderDetail, err := service.GetGoodReturnOrderDetail(id, orgId)
  2212. //获取药品库数据
  2213. baseList, _ := service.GetSupplyDrugList(orgId)
  2214. goodList, _ := service.GetSupplyGoodList(orgId)
  2215. if err == nil {
  2216. this.ServeSuccessJSON(map[string]interface{}{
  2217. "cancelDetail": detail,
  2218. "orderCancelDetail": orderDetail,
  2219. "drugList": baseList,
  2220. "goodList": goodList,
  2221. })
  2222. } else {
  2223. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2224. }
  2225. }
  2226. func (this *SupplyOrderApiController) UpdateGoodReturn() {
  2227. dataBody := make(map[string]interface{}, 0)
  2228. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2229. if err != nil {
  2230. utils.ErrorLog(err.Error())
  2231. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2232. return
  2233. }
  2234. return_remark := dataBody["return_marke"].(string)
  2235. supplier_id, _ := this.GetInt64("supplier_id")
  2236. start_time := this.GetString("start")
  2237. timeLayout := "2006-01-02"
  2238. loc, _ := time.LoadLocation("Local")
  2239. var startTime int64
  2240. if len(start_time) > 0 {
  2241. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2242. if err != nil {
  2243. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2244. return
  2245. }
  2246. startTime = theTime.Unix()
  2247. }
  2248. warehouse_out_id, _ := this.GetInt64("warehouse_out_id")
  2249. arrerage := this.GetString("arrerage")
  2250. arrerage_float, _ := strconv.ParseFloat(arrerage, 64)
  2251. payment := this.GetString("payment")
  2252. payment_float, _ := strconv.ParseFloat(payment, 64)
  2253. rate_of_concession := this.GetString("rate_of_concession")
  2254. rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
  2255. discount_amount := this.GetString("discount_amount")
  2256. discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
  2257. return_number := this.GetString("return_number")
  2258. orgId := this.GetAdminUserInfo().CurrentOrgId
  2259. cancel := models.SpSupplierWarehouseCancel{
  2260. ID: 0,
  2261. Number: return_number,
  2262. RateOfConcession: rate_of_concession_float,
  2263. DiscountAmount: discount_amount_float,
  2264. DocumentDate: startTime,
  2265. SupplierId: supplier_id,
  2266. Arrearage: arrerage_float,
  2267. Payment: payment_float,
  2268. ReturnRemark: return_remark,
  2269. }
  2270. service.UpdateWarehouseCancel(warehouse_out_id, cancel)
  2271. var warehouseCancel []*models.SpSupplierWarehousingCancelOrder
  2272. var updateWarehouseCancel []*models.SpSupplierWarehousingCancelOrder
  2273. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  2274. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  2275. if len(thisStockIn) > 0 {
  2276. for _, item := range thisStockIn {
  2277. items := item.(map[string]interface{})
  2278. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2279. utils.ErrorLog("id")
  2280. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2281. return
  2282. }
  2283. id := int64(items["id"].(float64))
  2284. if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
  2285. utils.ErrorLog("supply_count")
  2286. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2287. return
  2288. }
  2289. supply_count := int64(items["supply_count"].(float64))
  2290. if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
  2291. utils.ErrorLog("manufacturer_id")
  2292. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2293. return
  2294. }
  2295. manufacturer_id := int64(items["manufacturer_id"].(float64))
  2296. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  2297. utils.ErrorLog("name")
  2298. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2299. return
  2300. }
  2301. name := items["name"].(string)
  2302. if items["order_number"] == nil || reflect.TypeOf(items["order_number"]).String() != "string" {
  2303. utils.ErrorLog("order_number")
  2304. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2305. return
  2306. }
  2307. order_number := items["order_number"].(string)
  2308. if items["good_number"] == nil || reflect.TypeOf(items["good_number"]).String() != "string" {
  2309. utils.ErrorLog("good_number")
  2310. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2311. return
  2312. }
  2313. good_number := items["good_number"].(string)
  2314. if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
  2315. utils.ErrorLog("supply_price")
  2316. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2317. return
  2318. }
  2319. supply_price := items["supply_price"].(string)
  2320. price_float, _ := strconv.ParseFloat(supply_price, 64)
  2321. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  2322. utils.ErrorLog("project_id")
  2323. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2324. return
  2325. }
  2326. project_id := int64(items["project_id"].(float64))
  2327. if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
  2328. utils.ErrorLog("supply_remake")
  2329. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2330. return
  2331. }
  2332. supply_remake := items["supply_remake"].(string)
  2333. if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
  2334. utils.ErrorLog("supply_license_number")
  2335. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2336. return
  2337. }
  2338. supply_license_number := items["supply_license_number"].(string)
  2339. if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
  2340. utils.ErrorLog("supply_specification_name")
  2341. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2342. return
  2343. }
  2344. supply_specification_name := items["supply_specification_name"].(string)
  2345. if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
  2346. utils.ErrorLog("supply_total")
  2347. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2348. return
  2349. }
  2350. supply_total := items["supply_total"].(string)
  2351. if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
  2352. utils.ErrorLog("supply_type")
  2353. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2354. return
  2355. }
  2356. supply_type := items["supply_type"].(string)
  2357. if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
  2358. utils.ErrorLog("supply_unit")
  2359. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2360. return
  2361. }
  2362. supply_unit := items["supply_unit"].(string)
  2363. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2364. utils.ErrorLog("type")
  2365. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2366. return
  2367. }
  2368. is_source := int64(items["type"].(float64))
  2369. if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
  2370. utils.ErrorLog("supply_manufacturer")
  2371. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2372. return
  2373. }
  2374. supply_manufacturer := items["supply_manufacturer"].(string)
  2375. if id > 0 {
  2376. cancelOrder := &models.SpSupplierWarehousingCancelOrder{
  2377. ManufacturerId: manufacturer_id,
  2378. OrderNumber: order_number,
  2379. ProjectId: project_id,
  2380. GoodNumber: good_number,
  2381. IsSource: is_source,
  2382. Count: supply_count,
  2383. Price: price_float,
  2384. Remark: supply_remake,
  2385. RateOfConcession: rate_of_concession_float,
  2386. DiscountAmount: discount_amount_float,
  2387. UserOrgId: orgId,
  2388. Ctime: time.Now().Unix(),
  2389. Status: 1,
  2390. Mtime: 0,
  2391. WarehouseCancelId: warehouse_out_id,
  2392. Type: 1,
  2393. ReturnNumber: return_number,
  2394. WarehouseOutId: warehouse_out_id,
  2395. SupplySpecificationName: supply_specification_name,
  2396. SupplyType: supply_type,
  2397. SupplyTotal: supply_total,
  2398. SupplyManufacturer: supply_manufacturer,
  2399. Name: name,
  2400. SupplyUnit: supply_unit,
  2401. SupplyLicenseNumber: supply_license_number,
  2402. }
  2403. updateWarehouseCancel = append(updateWarehouseCancel, cancelOrder)
  2404. }
  2405. if id == 0 {
  2406. cancelOrder := &models.SpSupplierWarehousingCancelOrder{
  2407. ManufacturerId: manufacturer_id,
  2408. OrderNumber: order_number,
  2409. ProjectId: project_id,
  2410. GoodNumber: good_number,
  2411. IsSource: is_source,
  2412. Count: supply_count,
  2413. Price: price_float,
  2414. Remark: supply_remake,
  2415. RateOfConcession: rate_of_concession_float,
  2416. DiscountAmount: discount_amount_float,
  2417. UserOrgId: orgId,
  2418. Ctime: time.Now().Unix(),
  2419. Status: 1,
  2420. Mtime: 0,
  2421. WarehouseCancelId: warehouse_out_id,
  2422. Type: 1,
  2423. ReturnNumber: return_number,
  2424. WarehouseOutId: warehouse_out_id,
  2425. SupplySpecificationName: supply_specification_name,
  2426. SupplyType: supply_type,
  2427. SupplyTotal: supply_total,
  2428. SupplyManufacturer: supply_manufacturer,
  2429. Name: name,
  2430. SupplyUnit: supply_unit,
  2431. SupplyLicenseNumber: supply_license_number,
  2432. }
  2433. warehouseCancel = append(warehouseCancel, cancelOrder)
  2434. }
  2435. }
  2436. }
  2437. if len(updateWarehouseCancel) > 0 {
  2438. for _, item := range warehouseCancel {
  2439. service.UpdateWarehouseCancelOrder(item)
  2440. }
  2441. }
  2442. if len(warehouseCancel) > 0 {
  2443. for _, item := range warehouseCancel {
  2444. service.CreateCancelReturnOrder(item)
  2445. }
  2446. }
  2447. if err == nil {
  2448. returnData := make(map[string]interface{}, 0)
  2449. returnData["msg"] = "ok"
  2450. this.ServeSuccessJSON(returnData)
  2451. return
  2452. } else {
  2453. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2454. }
  2455. }
  2456. }
  2457. func (this *SupplyOrderApiController) ModefyGoodOrder() {
  2458. id, _ := this.GetInt64("id")
  2459. orgId := this.GetAdminUserInfo().CurrentOrgId
  2460. //获取购货订单的数据
  2461. purcaseOrder, _ := service.GetAllPurcaseOrderById(id, orgId)
  2462. //获取购货单的数据
  2463. goodOrder, _ := service.GetAllGoodOrderById(id, orgId)
  2464. drugList, _ := service.GetSupplyDrugList(orgId)
  2465. //获取已有关联的退货单
  2466. cancelList, _ := service.GetSupplyCancelWarehouse(id, orgId)
  2467. //查询是否存在退货单
  2468. _, errcode := service.GetSupplyCancelOrderById(id, orgId)
  2469. //无退库单
  2470. if errcode == gorm.ErrRecordNotFound {
  2471. //反审核成功
  2472. out := models.SpSupplierWarehouseOut{
  2473. IsCheck: 2,
  2474. Checker: 0,
  2475. CheckTime: 0,
  2476. }
  2477. err := service.UpdateSupplyGoodOrder(id, out)
  2478. //查询该订单不是采购入库的数据
  2479. list, _ := service.GetDrugSupplyWarehousingById(id, orgId)
  2480. if len(list) == 0 {
  2481. service.UpdateSupplyWarehousing(id, orgId)
  2482. }
  2483. goodList, _ := service.GetGoodSupplyWarehousingById(id, orgId)
  2484. if len(goodList) == 0 {
  2485. service.UpdateGoodWarehousing(id, orgId)
  2486. }
  2487. //删除药品入库单
  2488. service.UpdateDrugSupplyWarehousingInfo(id, orgId)
  2489. //删除入库流水
  2490. service.UpdateDrugSupplyFlow(id, orgId)
  2491. //删除耗材入库单
  2492. service.UpdateGoodSupplyWarehousingInfo(id, orgId)
  2493. //删除耗材入库流水
  2494. service.UpdateGoodSupplyFlow(id, orgId)
  2495. if err == nil {
  2496. this.ServeSuccessJSON(map[string]interface{}{
  2497. "cancelList": cancelList,
  2498. "purcaseOrder": purcaseOrder,
  2499. "goodOrder": goodOrder,
  2500. "drugList": drugList,
  2501. "msg": 1,
  2502. })
  2503. return
  2504. } else {
  2505. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2506. }
  2507. } else if errcode == nil {
  2508. this.ServeSuccessJSON(map[string]interface{}{
  2509. "cancelList": cancelList,
  2510. "purcaseOrder": purcaseOrder,
  2511. "goodOrder": goodOrder,
  2512. "drugList": drugList,
  2513. "msg": 2,
  2514. })
  2515. return
  2516. }
  2517. }
  2518. func (this *SupplyOrderApiController) UpdateSupplyWarehousing() {
  2519. warehousing_id, _ := this.GetInt64("warehousing_id")
  2520. orgId := this.GetAdminUserInfo().CurrentOrgId
  2521. err := service.UpdateSupplyWarehousingById(warehousing_id, orgId)
  2522. if err == nil {
  2523. returnData := make(map[string]interface{}, 0)
  2524. returnData["msg"] = "ok"
  2525. this.ServeSuccessJSON(returnData)
  2526. return
  2527. } else {
  2528. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2529. }
  2530. }
  2531. func (this *SupplyOrderApiController) DeleteGoodOrder() {
  2532. id, _ := this.GetInt64("id")
  2533. orgId := this.GetAdminUserInfo().CurrentOrgId
  2534. err := service.DeleteGoodOrder(id, orgId)
  2535. if err == nil {
  2536. returnData := make(map[string]interface{}, 0)
  2537. returnData["msg"] = "ok"
  2538. this.ServeSuccessJSON(returnData)
  2539. return
  2540. } else {
  2541. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2542. }
  2543. }
  2544. func (this *SupplyOrderApiController) GetSupplyWarehouseById() {
  2545. id, _ := this.GetInt64("id")
  2546. orgId := this.GetAdminUserInfo().CurrentOrgId
  2547. //获取已有关联的退货单
  2548. cancelList, err := service.GetSupplyCancelWarehouse(id, orgId)
  2549. //获取采购单数据
  2550. outList, _ := service.GetGoodOrderListById(id, orgId)
  2551. //获取退货单数据
  2552. cancelOrderList, _ := service.GetGoodCanceListById(id, orgId)
  2553. //获取药品库数据
  2554. baseList, _ := service.GetSupplyDrugList(orgId)
  2555. if err == nil {
  2556. this.ServeSuccessJSON(map[string]interface{}{
  2557. "cancelList": cancelList,
  2558. "outList": outList,
  2559. "drugList": baseList,
  2560. "cancelOrderList": cancelOrderList,
  2561. })
  2562. } else {
  2563. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2564. }
  2565. }