supply_order_api_contorller.go 133KB

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