supply_order_api_contorller.go 114KB

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