supply_order_api_contorller.go 108KB

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