supply_order_api_contorller.go 137KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "reflect"
  6. "strconv"
  7. "strings"
  8. "time"
  9. "XT_New/enums"
  10. "XT_New/models"
  11. "XT_New/service"
  12. "XT_New/utils"
  13. "github.com/astaxie/beego"
  14. "github.com/jinzhu/gorm"
  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. //查询是否有该耗材
  2196. goodStock, _ := service.GetGoodSumCount(storeConfig.StorehouseOutInfo, item.GoodId, item.OrgId)
  2197. if goodStock.ID > 0 {
  2198. //增加入库数量
  2199. service.AddGoodSumInCount(storeConfig.StorehouseOutInfo, item.GoodId, item.OrgId, item.WarehousingCount)
  2200. }
  2201. if goodStock.ID == 0 {
  2202. stock := models.XtGoodStockCount{
  2203. UserOrgId: item.OrgId,
  2204. GoodId: item.GoodId,
  2205. StorehouseId: storeConfig.StorehouseOutInfo,
  2206. Status: 1,
  2207. Ctime: time.Now().Unix(),
  2208. Mtime: 0,
  2209. StockInCount: item.WarehousingCount,
  2210. StockOutCount: 0,
  2211. StockCancelCount: 0,
  2212. FlushCount: sum_count,
  2213. StockActOutCount: 0,
  2214. }
  2215. service.CreateGoodStockCount(stock)
  2216. }
  2217. //更新剩余库存
  2218. service.UpdateGoodFlushCount(storeConfig.StorehouseOutInfo, item.GoodId, item.OrgId, sum_count)
  2219. warehousinginfo, _ := service.GetLastWarehousingInfo(item.GoodId)
  2220. flow := models.VmStockFlow{
  2221. WarehousingOrder: item.WarehousingOrder,
  2222. WarehousingId: item.ID,
  2223. GoodId: item.GoodId,
  2224. Number: item.Number,
  2225. ProductDate: item.ProductDate,
  2226. ExpireDate: item.ExpiryDate,
  2227. Count: item.WarehousingCount,
  2228. Price: item.Price,
  2229. Status: 1,
  2230. Ctime: time.Now().Unix(),
  2231. UserOrgId: orgId,
  2232. Manufacturer: item.Manufacturer,
  2233. Dealer: item.Dealer,
  2234. LicenseNumber: item.LicenseNumber,
  2235. IsEdit: 1,
  2236. Creator: checker,
  2237. SystemTime: record_date,
  2238. ConsumableType: 1,
  2239. WarehousingDetailId: warehousinginfo.ID,
  2240. SupplyWarehouseId: id,
  2241. SupplyWarehouseDetailInfo: item.ID,
  2242. StorehouseId: houseConfig.StorehouseInfo,
  2243. }
  2244. service.CreateStockFlowOne(flow)
  2245. }
  2246. //创建入库单
  2247. errs := service.CreateDrugWarehousingInfoSix(warehouseInfoDetail)
  2248. //改变入库状态
  2249. for _, items := range warehouseInfoDetail {
  2250. //查询默认仓库
  2251. houseConfig, _ := service.GetAllStoreHouseConfig(items.OrgId)
  2252. //查询默认仓库剩余多少库存
  2253. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, items.OrgId, items.DrugId)
  2254. var sum_count int64
  2255. var sum_in_count int64
  2256. var sum_waresing_count int64
  2257. baseDrug, _ := service.GetBaseDrugMedical(items.DrugId)
  2258. for _, it := range list {
  2259. if it.MaxUnit == baseDrug.MaxUnit {
  2260. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  2261. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  2262. }
  2263. sum_count += it.StockMaxNumber + it.StockMinNumber
  2264. sum_in_count += it.WarehousingCount
  2265. }
  2266. if items.MaxUnit == baseDrug.MaxUnit {
  2267. sum_waresing_count = items.WarehousingCount * baseDrug.MinNumber
  2268. }
  2269. if items.MaxUnit == baseDrug.MinUnit {
  2270. sum_waresing_count = items.WarehousingCount
  2271. }
  2272. service.UpdateMedicalSumCount(items.DrugId, sum_count, sum_in_count, items.OrgId)
  2273. //查询是否有
  2274. drugStock, _ := service.GetDrugStockCountSix(houseConfig.DrugStorehouseOut, items.DrugId, items.OrgId)
  2275. fmt.Println("drugStockwoowowowowoowowowo", drugStock.ID)
  2276. if drugStock.ID == 0 {
  2277. drug := models.XtDrugStockCount{
  2278. UserOrgId: items.OrgId,
  2279. StorehouseId: houseConfig.DrugStorehouseOut,
  2280. SumInCount: sum_waresing_count,
  2281. SumOutCount: 0,
  2282. SumCancelCount: 0,
  2283. DrugId: items.DrugId,
  2284. Ctime: time.Now().Unix(),
  2285. Mtime: 0,
  2286. Status: 1,
  2287. FlushCount: sum_count,
  2288. SumActOutCount: 0,
  2289. }
  2290. service.CreateDrugStock(drug)
  2291. }
  2292. if drugStock.ID > 0 {
  2293. //更新入库数量和剩余库存
  2294. service.UpdateDrugCount(houseConfig.DrugStorehouseOut, items.OrgId, items.DrugId, sum_in_count, sum_count)
  2295. }
  2296. }
  2297. fmt.Println(errs)
  2298. for _, items := range drugFlow {
  2299. drugWarehouseInfo, _ := service.GetLastDrugWarehouseInfo(items.DrugId)
  2300. items.WarehousingDetailId = drugWarehouseInfo.ID
  2301. }
  2302. //创建流水单
  2303. service.CreateDrugFlowSix(drugFlow)
  2304. drugList, _ := service.GetSupplyDrugList(orgId)
  2305. for _, items := range goodOrder {
  2306. service.UpdateWarehouseingById(items.ID)
  2307. }
  2308. if err == nil {
  2309. this.ServeSuccessJSON(map[string]interface{}{
  2310. "purcaseOrder": purcaseOrder,
  2311. "goodOrder": goodOrder,
  2312. "drugList": drugList,
  2313. })
  2314. } else {
  2315. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2316. }
  2317. }
  2318. func (this *SupplyOrderApiController) ModefySupplyWarehousing() {
  2319. is_warehouse, _ := this.GetInt64("is_warehouse")
  2320. warehousing_id, _ := this.GetInt64("warehousing_id")
  2321. orgId := this.GetAdminUserInfo().CurrentOrgId
  2322. err := service.ModefySupplyWarehousing(is_warehouse, warehousing_id, orgId)
  2323. if err == nil {
  2324. returnData := make(map[string]interface{}, 0)
  2325. returnData["msg"] = "ok"
  2326. this.ServeSuccessJSON(returnData)
  2327. return
  2328. } else {
  2329. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2330. }
  2331. }
  2332. func (this *SupplyOrderApiController) SaveGoodReturnOrder() {
  2333. dataBody := make(map[string]interface{}, 0)
  2334. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2335. if err != nil {
  2336. utils.ErrorLog(err.Error())
  2337. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2338. return
  2339. }
  2340. return_remark := dataBody["return_marke"].(string)
  2341. supplier_id, _ := this.GetInt64("supplier_id")
  2342. start_time := this.GetString("start_time")
  2343. timeLayout := "2006-01-02"
  2344. loc, _ := time.LoadLocation("Local")
  2345. var startTime int64
  2346. if len(start_time) > 0 {
  2347. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2348. if err != nil {
  2349. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2350. return
  2351. }
  2352. startTime = theTime.Unix()
  2353. }
  2354. warehouse_out_id, _ := this.GetInt64("warehouse_out_id")
  2355. arrerage := this.GetString("arrerage")
  2356. arrerage_float, _ := strconv.ParseFloat(arrerage, 64)
  2357. payment := this.GetString("payment")
  2358. payment_float, _ := strconv.ParseFloat(payment, 64)
  2359. rate_of_concession := this.GetString("rate_of_concession")
  2360. rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
  2361. discount_amount := this.GetString("discount_amount")
  2362. discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
  2363. orgId := this.GetAdminUserInfo().CurrentOrgId
  2364. total, _ := service.GetSupplyCancelOrder(orgId)
  2365. creater := this.GetAdminUserInfo().AdminUser.Id
  2366. //生成购货单
  2367. timeStr := time.Now().Format("2006-01-02")
  2368. timeArr := strings.Split(timeStr, "-")
  2369. total = total + 1
  2370. warehousing_order := "CGT" + timeArr[0] + timeArr[1] + timeArr[2] + "00" + strconv.FormatInt(total, 10)
  2371. recordDateStr := time.Now().Format("2006-01-02")
  2372. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2373. cancel := models.SpSupplierWarehouseCancel{
  2374. Number: warehousing_order,
  2375. UserOrgId: orgId,
  2376. Creater: creater,
  2377. Ctime: time.Now().Unix(),
  2378. Mtime: 0,
  2379. Status: 1,
  2380. RecordDate: recordDate.Unix(),
  2381. IsCheck: 2,
  2382. WarehouseOutId: warehouse_out_id,
  2383. RateOfConcession: rate_of_concession_float,
  2384. DiscountAmount: discount_amount_float,
  2385. DocumentDate: startTime,
  2386. SupplierId: supplier_id,
  2387. Checker: 0,
  2388. CheckTime: 0,
  2389. Arrearage: arrerage_float,
  2390. Payment: payment_float,
  2391. ReturnRemark: return_remark,
  2392. }
  2393. err = service.CreateReturnCacelOrder(cancel)
  2394. order, _ := service.GetLastReturnCancelOrder(orgId)
  2395. var warehouseCancel []*models.SpSupplierWarehousingCancelOrder
  2396. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  2397. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  2398. if len(thisStockIn) > 0 {
  2399. for _, item := range thisStockIn {
  2400. items := item.(map[string]interface{})
  2401. if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
  2402. utils.ErrorLog("supply_count")
  2403. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2404. return
  2405. }
  2406. supply_count := int64(items["supply_count"].(float64))
  2407. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  2408. utils.ErrorLog("count")
  2409. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2410. return
  2411. }
  2412. count := items["count"].(string)
  2413. if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
  2414. utils.ErrorLog("manufacturer_id")
  2415. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2416. return
  2417. }
  2418. manufacturer_id := int64(items["manufacturer_id"].(float64))
  2419. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  2420. utils.ErrorLog("name")
  2421. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2422. return
  2423. }
  2424. name := items["name"].(string)
  2425. if items["order_number"] == nil || reflect.TypeOf(items["order_number"]).String() != "string" {
  2426. utils.ErrorLog("order_number")
  2427. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2428. return
  2429. }
  2430. order_number := items["order_number"].(string)
  2431. if items["good_number"] == nil || reflect.TypeOf(items["good_number"]).String() != "string" {
  2432. utils.ErrorLog("good_number")
  2433. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2434. return
  2435. }
  2436. good_number := items["good_number"].(string)
  2437. if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
  2438. utils.ErrorLog("supply_price")
  2439. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2440. return
  2441. }
  2442. supply_price := items["supply_price"].(string)
  2443. price_float, _ := strconv.ParseFloat(supply_price, 64)
  2444. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  2445. utils.ErrorLog("project_id")
  2446. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2447. return
  2448. }
  2449. project_id := int64(items["project_id"].(float64))
  2450. if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
  2451. utils.ErrorLog("supply_remake")
  2452. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2453. return
  2454. }
  2455. supply_remake := items["supply_remake"].(string)
  2456. if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
  2457. utils.ErrorLog("supply_license_number")
  2458. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2459. return
  2460. }
  2461. supply_license_number := items["supply_license_number"].(string)
  2462. if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
  2463. utils.ErrorLog("supply_specification_name")
  2464. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2465. return
  2466. }
  2467. supply_specification_name := items["supply_specification_name"].(string)
  2468. if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
  2469. utils.ErrorLog("supply_total")
  2470. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2471. return
  2472. }
  2473. supply_total := items["supply_total"].(string)
  2474. if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
  2475. utils.ErrorLog("supply_type")
  2476. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2477. return
  2478. }
  2479. supply_type := items["supply_type"].(string)
  2480. if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
  2481. utils.ErrorLog("supply_unit")
  2482. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2483. return
  2484. }
  2485. supply_unit := items["supply_unit"].(string)
  2486. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2487. utils.ErrorLog("type")
  2488. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2489. return
  2490. }
  2491. is_source := int64(items["type"].(float64))
  2492. if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
  2493. utils.ErrorLog("supply_manufacturer")
  2494. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2495. return
  2496. }
  2497. supply_manufacturer := items["supply_manufacturer"].(string)
  2498. if items["supply_batch_number"] == nil || reflect.TypeOf(items["supply_batch_number"]).String() != "string" {
  2499. utils.ErrorLog("supply_batch_number")
  2500. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2501. return
  2502. }
  2503. supply_batch_number := items["supply_batch_number"].(string)
  2504. if items["supply_product_date"] == nil || reflect.TypeOf(items["supply_product_date"]).String() != "float64" {
  2505. utils.ErrorLog("supply_product_date")
  2506. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2507. return
  2508. }
  2509. supply_product_date := int64(items["supply_product_date"].(float64))
  2510. if items["supply_expiry_date"] == nil || reflect.TypeOf(items["supply_expiry_date"]).String() != "float64" {
  2511. utils.ErrorLog("supply_expiry_date")
  2512. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2513. return
  2514. }
  2515. supply_expiry_date := int64(items["supply_expiry_date"].(float64))
  2516. if items["warehousing_id"] == nil || reflect.TypeOf(items["warehousing_id"]).String() != "float64" {
  2517. utils.ErrorLog("warehousing_id")
  2518. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2519. return
  2520. }
  2521. warehousing_id := int64(items["warehousing_id"].(float64))
  2522. if items["warehouse_info_id"] == nil || reflect.TypeOf(items["warehouse_info_id"]).String() != "float64" {
  2523. utils.ErrorLog("warehouse_info_id")
  2524. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2525. return
  2526. }
  2527. warehouse_info_id := int64(items["warehouse_info_id"].(float64))
  2528. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2529. utils.ErrorLog("id")
  2530. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2531. return
  2532. }
  2533. id := int64(items["id"].(float64))
  2534. deposit_rate := items["deposit_rate"].(string)
  2535. deposit_rate_float, _ := strconv.ParseFloat(deposit_rate, 64)
  2536. cancelOrder := &models.SpSupplierWarehousingCancelOrder{
  2537. ManufacturerId: manufacturer_id,
  2538. OrderNumber: order_number,
  2539. ProjectId: project_id,
  2540. GoodNumber: good_number,
  2541. IsSource: is_source,
  2542. Count: count,
  2543. Price: price_float,
  2544. Remark: supply_remake,
  2545. RateOfConcession: rate_of_concession_float,
  2546. DiscountAmount: discount_amount_float,
  2547. UserOrgId: orgId,
  2548. Ctime: time.Now().Unix(),
  2549. Status: 1,
  2550. Mtime: 0,
  2551. WarehouseCancelId: order.ID,
  2552. Type: 1,
  2553. ReturnNumber: order.Number,
  2554. WarehouseOutId: warehouse_out_id,
  2555. SupplySpecificationName: supply_specification_name,
  2556. SupplyType: supply_type,
  2557. SupplyTotal: supply_total,
  2558. SupplyManufacturer: supply_manufacturer,
  2559. Name: name,
  2560. SupplyUnit: supply_unit,
  2561. SupplyLicenseNumber: supply_license_number,
  2562. SupplyBatchNumber: supply_batch_number,
  2563. SupplyExpiryDate: supply_expiry_date,
  2564. SupplyProductDate: supply_product_date,
  2565. WarehouseInfoId: warehouse_info_id,
  2566. WarehousingId: warehousing_id,
  2567. SourceCount: count,
  2568. SupplyWarehouseDetailInfo: id,
  2569. SupplyCount: supply_count,
  2570. DepositRate: deposit_rate_float,
  2571. }
  2572. warehouseCancel = append(warehouseCancel, cancelOrder)
  2573. }
  2574. }
  2575. }
  2576. for _, item := range warehouseCancel {
  2577. if item.SupplyWarehouseDetailInfo > 0 {
  2578. item.Type = 1
  2579. } else {
  2580. item.Type = 2
  2581. }
  2582. service.CreateCancelReturnOrder(item)
  2583. //查询该商品在退库单中是否存在
  2584. _, errcodes := service.GetSupplyWarehouseOutIsExsit(item.WarehouseOutId, item.ProjectId, orgId)
  2585. //如果不存在则情况退库单的关联信息
  2586. if errcodes == gorm.ErrRecordNotFound {
  2587. service.ModfySupplyCancel(item.WarehouseCancelId, orgId, item.ProjectId)
  2588. }
  2589. }
  2590. cancelOrder, err := service.GetReturnCancelOrder(order.ID, orgId)
  2591. list, err := service.GetReturnCancelOrderList(order.ID, orgId)
  2592. if err == nil {
  2593. this.ServeSuccessJSON(map[string]interface{}{
  2594. "warehouseCancel": warehouseCancel,
  2595. "cancelOrder": cancelOrder,
  2596. "list": list,
  2597. })
  2598. } else {
  2599. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2600. }
  2601. }
  2602. func (this *SupplyOrderApiController) GetAllGoodReturnOrderList() {
  2603. check_id, _ := this.GetInt64("check_id")
  2604. start_time := this.GetString("start_time")
  2605. end_time := this.GetString("end_time")
  2606. keyword := this.GetString("keyword")
  2607. page, _ := this.GetInt64("page")
  2608. limit, _ := this.GetInt64("limit")
  2609. timeLayout := "2006-01-02"
  2610. loc, _ := time.LoadLocation("Local")
  2611. var startTime int64
  2612. if len(start_time) > 0 {
  2613. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2614. if err != nil {
  2615. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2616. return
  2617. }
  2618. startTime = theTime.Unix()
  2619. }
  2620. var endTime int64
  2621. if len(end_time) > 0 {
  2622. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  2623. if err != nil {
  2624. utils.ErrorLog(err.Error())
  2625. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2626. return
  2627. }
  2628. endTime = theTime.Unix()
  2629. }
  2630. orgId := this.GetAdminUserInfo().CurrentOrgId
  2631. list, total, err := service.GetAllGoodReturnOrderList(check_id, keyword, page, limit, startTime, endTime, orgId)
  2632. if err == nil {
  2633. this.ServeSuccessJSON(map[string]interface{}{
  2634. "total": total,
  2635. "list": list,
  2636. })
  2637. } else {
  2638. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2639. }
  2640. }
  2641. func (this *SupplyOrderApiController) GetGoodReturnDetail() {
  2642. id, _ := this.GetInt64("id")
  2643. orgId := this.GetAdminUserInfo().CurrentOrgId
  2644. detail, err := service.GetGoodReturnDetail(id, orgId)
  2645. orderDetail, err := service.GetGoodReturnOrderDetail(id, orgId)
  2646. //获取药品库数据
  2647. baseList, _ := service.GetSupplyDrugList(orgId)
  2648. goodList, _ := service.GetSupplyGoodList(orgId)
  2649. supplyList, _ := service.GetSupplierList(orgId)
  2650. if err == nil {
  2651. this.ServeSuccessJSON(map[string]interface{}{
  2652. "cancelDetail": detail,
  2653. "orderCancelDetail": orderDetail,
  2654. "drugList": baseList,
  2655. "goodList": goodList,
  2656. "supplyList": supplyList,
  2657. })
  2658. } else {
  2659. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2660. }
  2661. }
  2662. func (this *SupplyOrderApiController) UpdateGoodReturn() {
  2663. dataBody := make(map[string]interface{}, 0)
  2664. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2665. if err != nil {
  2666. utils.ErrorLog(err.Error())
  2667. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2668. return
  2669. }
  2670. return_remark := dataBody["return_marke"].(string)
  2671. supplier_id, _ := this.GetInt64("supplier_id")
  2672. start_time := this.GetString("start")
  2673. timeLayout := "2006-01-02"
  2674. loc, _ := time.LoadLocation("Local")
  2675. var startTime int64
  2676. if len(start_time) > 0 {
  2677. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2678. if err != nil {
  2679. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2680. return
  2681. }
  2682. startTime = theTime.Unix()
  2683. }
  2684. warehouse_out_id, _ := this.GetInt64("warehouse_out_id")
  2685. arrerage := this.GetString("arrerage")
  2686. arrerage_float, _ := strconv.ParseFloat(arrerage, 64)
  2687. payment := this.GetString("payment")
  2688. payment_float, _ := strconv.ParseFloat(payment, 64)
  2689. rate_of_concession := this.GetString("rate_of_concession")
  2690. rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64)
  2691. discount_amount := this.GetString("discount_amount")
  2692. discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64)
  2693. return_number := this.GetString("return_number")
  2694. orgId := this.GetAdminUserInfo().CurrentOrgId
  2695. cancel := models.SpSupplierWarehouseCancel{
  2696. ID: 0,
  2697. Number: return_number,
  2698. RateOfConcession: rate_of_concession_float,
  2699. DiscountAmount: discount_amount_float,
  2700. DocumentDate: startTime,
  2701. SupplierId: supplier_id,
  2702. Arrearage: arrerage_float,
  2703. Payment: payment_float,
  2704. ReturnRemark: return_remark,
  2705. }
  2706. service.UpdateWarehouseCancel(warehouse_out_id, cancel)
  2707. var warehouseCancel []*models.SpSupplierWarehousingCancelOrder
  2708. var updateWarehouseCancel []*models.SpSupplierWarehousingCancelOrder
  2709. if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" {
  2710. thisStockIn, _ := dataBody["stockIn"].([]interface{})
  2711. if len(thisStockIn) > 0 {
  2712. for _, item := range thisStockIn {
  2713. items := item.(map[string]interface{})
  2714. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2715. utils.ErrorLog("id")
  2716. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2717. return
  2718. }
  2719. id := int64(items["id"].(float64))
  2720. if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" {
  2721. utils.ErrorLog("supply_count")
  2722. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2723. return
  2724. }
  2725. supply_count := int64(items["supply_count"].(float64))
  2726. if items["manufacturer_id"] == nil || reflect.TypeOf(items["manufacturer_id"]).String() != "float64" {
  2727. utils.ErrorLog("manufacturer_id")
  2728. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2729. return
  2730. }
  2731. manufacturer_id := int64(items["manufacturer_id"].(float64))
  2732. if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" {
  2733. utils.ErrorLog("name")
  2734. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2735. return
  2736. }
  2737. name := items["name"].(string)
  2738. if items["order_number"] == nil || reflect.TypeOf(items["order_number"]).String() != "string" {
  2739. utils.ErrorLog("order_number")
  2740. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2741. return
  2742. }
  2743. order_number := items["order_number"].(string)
  2744. if items["good_number"] == nil || reflect.TypeOf(items["good_number"]).String() != "string" {
  2745. utils.ErrorLog("good_number")
  2746. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2747. return
  2748. }
  2749. good_number := items["good_number"].(string)
  2750. if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" {
  2751. utils.ErrorLog("supply_price")
  2752. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2753. return
  2754. }
  2755. supply_price := items["supply_price"].(string)
  2756. price_float, _ := strconv.ParseFloat(supply_price, 64)
  2757. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  2758. utils.ErrorLog("project_id")
  2759. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2760. return
  2761. }
  2762. project_id := int64(items["project_id"].(float64))
  2763. if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" {
  2764. utils.ErrorLog("supply_remake")
  2765. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2766. return
  2767. }
  2768. supply_remake := items["supply_remake"].(string)
  2769. if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" {
  2770. utils.ErrorLog("supply_license_number")
  2771. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2772. return
  2773. }
  2774. supply_license_number := items["supply_license_number"].(string)
  2775. if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" {
  2776. utils.ErrorLog("supply_specification_name")
  2777. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2778. return
  2779. }
  2780. supply_specification_name := items["supply_specification_name"].(string)
  2781. if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" {
  2782. utils.ErrorLog("supply_total")
  2783. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2784. return
  2785. }
  2786. supply_total := items["supply_total"].(string)
  2787. if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" {
  2788. utils.ErrorLog("supply_type")
  2789. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2790. return
  2791. }
  2792. supply_type := items["supply_type"].(string)
  2793. if items["supply_unit"] == nil || reflect.TypeOf(items["supply_unit"]).String() != "string" {
  2794. utils.ErrorLog("supply_unit")
  2795. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2796. return
  2797. }
  2798. supply_unit := items["supply_unit"].(string)
  2799. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2800. utils.ErrorLog("type")
  2801. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2802. return
  2803. }
  2804. is_source := int64(items["type"].(float64))
  2805. if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" {
  2806. utils.ErrorLog("supply_manufacturer")
  2807. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2808. return
  2809. }
  2810. supply_manufacturer := items["supply_manufacturer"].(string)
  2811. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  2812. utils.ErrorLog("count")
  2813. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2814. return
  2815. }
  2816. count := items["count"].(string)
  2817. if items["deposit_rate"] == nil || reflect.TypeOf(items["deposit_rate"]).String() != "string" {
  2818. utils.ErrorLog("deposit_rate")
  2819. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2820. return
  2821. }
  2822. deposit_rate := items["deposit_rate"].(string)
  2823. deposit_rate_float, _ := strconv.ParseFloat(deposit_rate, 64)
  2824. if id > 0 {
  2825. cancelOrder := &models.SpSupplierWarehousingCancelOrder{
  2826. ID: id,
  2827. ManufacturerId: manufacturer_id,
  2828. OrderNumber: order_number,
  2829. ProjectId: project_id,
  2830. GoodNumber: good_number,
  2831. IsSource: is_source,
  2832. Count: count,
  2833. Price: price_float,
  2834. Remark: supply_remake,
  2835. RateOfConcession: rate_of_concession_float,
  2836. DiscountAmount: discount_amount_float,
  2837. UserOrgId: orgId,
  2838. Ctime: time.Now().Unix(),
  2839. Status: 1,
  2840. Mtime: 0,
  2841. WarehouseCancelId: warehouse_out_id,
  2842. Type: 1,
  2843. ReturnNumber: return_number,
  2844. WarehouseOutId: warehouse_out_id,
  2845. SupplySpecificationName: supply_specification_name,
  2846. SupplyType: supply_type,
  2847. SupplyTotal: supply_total,
  2848. SupplyManufacturer: supply_manufacturer,
  2849. Name: name,
  2850. SupplyUnit: supply_unit,
  2851. SupplyLicenseNumber: supply_license_number,
  2852. SupplyCount: supply_count,
  2853. DepositRate: deposit_rate_float,
  2854. }
  2855. updateWarehouseCancel = append(updateWarehouseCancel, cancelOrder)
  2856. }
  2857. if id == 0 {
  2858. cancelOrder := &models.SpSupplierWarehousingCancelOrder{
  2859. ManufacturerId: manufacturer_id,
  2860. OrderNumber: order_number,
  2861. ProjectId: project_id,
  2862. GoodNumber: good_number,
  2863. IsSource: is_source,
  2864. Count: count,
  2865. Price: price_float,
  2866. Remark: supply_remake,
  2867. RateOfConcession: rate_of_concession_float,
  2868. DiscountAmount: discount_amount_float,
  2869. UserOrgId: orgId,
  2870. Ctime: time.Now().Unix(),
  2871. Status: 1,
  2872. Mtime: 0,
  2873. WarehouseCancelId: warehouse_out_id,
  2874. Type: 2,
  2875. ReturnNumber: return_number,
  2876. WarehouseOutId: warehouse_out_id,
  2877. SupplySpecificationName: supply_specification_name,
  2878. SupplyType: supply_type,
  2879. SupplyTotal: supply_total,
  2880. SupplyManufacturer: supply_manufacturer,
  2881. Name: name,
  2882. SupplyUnit: supply_unit,
  2883. SupplyLicenseNumber: supply_license_number,
  2884. SupplyCount: supply_count,
  2885. DepositRate: deposit_rate_float,
  2886. }
  2887. warehouseCancel = append(warehouseCancel, cancelOrder)
  2888. }
  2889. }
  2890. }
  2891. if len(updateWarehouseCancel) > 0 {
  2892. for _, item := range updateWarehouseCancel {
  2893. service.UpdateWarehouseCancelOrder(item)
  2894. }
  2895. }
  2896. if len(warehouseCancel) > 0 {
  2897. for _, item := range warehouseCancel {
  2898. service.CreateCancelReturnOrder(item)
  2899. }
  2900. }
  2901. list, err := service.GetReturnCancelOrderList(warehouse_out_id, orgId)
  2902. if err == nil {
  2903. this.ServeSuccessJSON(map[string]interface{}{
  2904. "list": list,
  2905. "msg": "msg",
  2906. })
  2907. return
  2908. } else {
  2909. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2910. }
  2911. }
  2912. }
  2913. func (this *SupplyOrderApiController) ModefyGoodOrder() {
  2914. id, _ := this.GetInt64("id")
  2915. warehousing_id, _ := this.GetInt64("warehousing_id")
  2916. orgId := this.GetAdminUserInfo().CurrentOrgId
  2917. //获取购货单的数据
  2918. goodOrder, _ := service.GetAllGoodOrderById(id, orgId)
  2919. //判断该订单是否有出库记录
  2920. for _, it := range goodOrder {
  2921. if it.IsSource == 1 {
  2922. out, _ := service.GetDrugWarehosueInfoByWarehousingId(it.ProjectId, id, orgId)
  2923. if out.ID > 0 {
  2924. this.ServeSuccessJSON(map[string]interface{}{
  2925. "cancelList": "",
  2926. "purcaseOrder": "",
  2927. "goodOrder": "",
  2928. "drugList": "",
  2929. "msg": 3,
  2930. })
  2931. return
  2932. }
  2933. }
  2934. if it.IsSource == 2 {
  2935. out, _ := service.GetGoodWarehouseInfoByWarehousingId(it.ProjectId, id, orgId)
  2936. if out.ID > 0 {
  2937. this.ServeSuccessJSON(map[string]interface{}{
  2938. "cancelList": "",
  2939. "purcaseOrder": "",
  2940. "goodOrder": "",
  2941. "drugList": "",
  2942. "msg": 3,
  2943. })
  2944. return
  2945. }
  2946. }
  2947. }
  2948. //获取购货订单的数据
  2949. purcaseOrder, _ := service.GetAllPurcaseOrderById(warehousing_id, orgId)
  2950. drugList, _ := service.GetSupplyDrugList(orgId)
  2951. //获取已有关联的退货单
  2952. cancelList, _ := service.GetSupplyCancelWarehouse(id, orgId)
  2953. //查询是否存在退货单
  2954. _, errcode := service.GetSupplyCancelOrderById(id, orgId)
  2955. //无退库单
  2956. if errcode == gorm.ErrRecordNotFound {
  2957. //反审核成功
  2958. out := models.SpSupplierWarehouseOut{
  2959. IsCheck: 2,
  2960. Checker: 0,
  2961. CheckTime: 0,
  2962. }
  2963. err := service.UpdateSupplyGoodOrder(id, out)
  2964. for _, its := range goodOrder {
  2965. //改变采购单状态
  2966. service.UpdateSupplyOrderListById(its.ID)
  2967. }
  2968. //查询该订单不是采购入库的数据
  2969. list, _ := service.GetDrugSupplyWarehousingById(id, orgId)
  2970. if len(list) == 0 {
  2971. service.UpdateSupplyWarehousing(id, orgId)
  2972. }
  2973. goodList, _ := service.GetGoodSupplyWarehousingById(id, orgId)
  2974. if len(goodList) == 0 {
  2975. service.UpdateGoodWarehousing(id, orgId)
  2976. }
  2977. //删除药品入库单
  2978. service.UpdateDrugSupplyWarehousingInfo(id, orgId)
  2979. //删除入库流水
  2980. service.UpdateDrugSupplyFlow(id, orgId)
  2981. // 查询入库单
  2982. drugInfo, _ := service.GetDrugSupplyWarehouseIdSeven(id, orgId)
  2983. if len(drugInfo) > 0 {
  2984. for _, item := range drugInfo {
  2985. //查询默认仓库
  2986. houseConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
  2987. //查询默认仓库剩余多少库存
  2988. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, item.OrgId, item.DrugId)
  2989. var sum_count int64
  2990. var sum_in_count int64
  2991. for _, it := range list {
  2992. baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  2993. if it.MaxUnit == baseDrug.MaxUnit {
  2994. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  2995. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  2996. }
  2997. sum_count += it.StockMaxNumber + it.StockMinNumber
  2998. sum_in_count += it.WarehousingCount
  2999. }
  3000. service.UpdateMedicalSumCount(item.DrugId, sum_count, sum_in_count, item.OrgId)
  3001. //更新库存
  3002. service.UpdateDrugCount(houseConfig.DrugStorehouseOut, item.OrgId, item.DrugId, sum_in_count, sum_count)
  3003. }
  3004. } else {
  3005. for _, it := range goodOrder {
  3006. if it.IsSource == 1 {
  3007. service.UpdateMedicalSumCount(it.ProjectId, 0, 0, this.GetAdminUserInfo().CurrentOrgId)
  3008. }
  3009. }
  3010. }
  3011. //删除耗材入库单
  3012. service.UpdateGoodSupplyWarehousingInfo(id, orgId)
  3013. //删除耗材入库流水
  3014. service.UpdateGoodSupplyFlow(id, orgId)
  3015. //查寻入库单
  3016. info, _ := service.GetSupplySupplyWarehouseIdSeven(id, orgId)
  3017. if len(info) > 0 {
  3018. for _, item := range info {
  3019. //扣减库存
  3020. //查询该机构默认仓库
  3021. storeConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
  3022. //查询剩余库存
  3023. goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.GoodId, item.OrgId)
  3024. var sum_count int64
  3025. var sum_in_count int64
  3026. for _, item := range goodList {
  3027. sum_count += item.StockCount
  3028. sum_in_count += item.WarehousingCount
  3029. }
  3030. service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, item.OrgId)
  3031. }
  3032. } else {
  3033. for _, it := range goodOrder {
  3034. if it.IsSource == 2 {
  3035. service.UpdateGoodByGoodId(it.ProjectId, 0, 0, this.GetAdminUserInfo().CurrentOrgId)
  3036. }
  3037. }
  3038. }
  3039. if err == nil {
  3040. this.ServeSuccessJSON(map[string]interface{}{
  3041. "cancelList": cancelList,
  3042. "purcaseOrder": purcaseOrder,
  3043. "goodOrder": goodOrder,
  3044. "drugList": drugList,
  3045. "msg": 1,
  3046. })
  3047. return
  3048. } else {
  3049. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3050. }
  3051. } else if errcode == nil {
  3052. this.ServeSuccessJSON(map[string]interface{}{
  3053. "cancelList": cancelList,
  3054. "purcaseOrder": purcaseOrder,
  3055. "goodOrder": goodOrder,
  3056. "drugList": drugList,
  3057. "msg": 2,
  3058. })
  3059. return
  3060. }
  3061. }
  3062. func (this *SupplyOrderApiController) UpdateSupplyWarehousing() {
  3063. warehousing_id, _ := this.GetInt64("warehousing_id")
  3064. orgId := this.GetAdminUserInfo().CurrentOrgId
  3065. err := service.UpdateSupplyWarehousingById(warehousing_id, orgId)
  3066. if err == nil {
  3067. returnData := make(map[string]interface{}, 0)
  3068. returnData["msg"] = "ok"
  3069. this.ServeSuccessJSON(returnData)
  3070. return
  3071. } else {
  3072. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3073. }
  3074. }
  3075. func (this *SupplyOrderApiController) DeleteGoodOrder() {
  3076. id, _ := this.GetInt64("id")
  3077. orgId := this.GetAdminUserInfo().CurrentOrgId
  3078. err := service.DeleteGoodOrder(id, orgId)
  3079. if err == nil {
  3080. returnData := make(map[string]interface{}, 0)
  3081. returnData["msg"] = "ok"
  3082. this.ServeSuccessJSON(returnData)
  3083. return
  3084. } else {
  3085. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3086. }
  3087. }
  3088. func (this *SupplyOrderApiController) GetSupplyWarehouseById() {
  3089. id, _ := this.GetInt64("id")
  3090. orgId := this.GetAdminUserInfo().CurrentOrgId
  3091. //获取已有关联的退货单
  3092. cancelList, err := service.GetSupplyCancelWarehouse(id, orgId)
  3093. //获取采购单数据
  3094. outList, _ := service.GetGoodOrderListById(id, orgId)
  3095. //获取退货单数据
  3096. cancelOrderList, _ := service.GetGoodCanceListById(id, orgId)
  3097. //获取药品库数据
  3098. baseList, _ := service.GetSupplyDrugList(orgId)
  3099. if err == nil {
  3100. this.ServeSuccessJSON(map[string]interface{}{
  3101. "cancelList": cancelList,
  3102. "outList": outList,
  3103. "drugList": baseList,
  3104. "cancelOrderList": cancelOrderList,
  3105. })
  3106. } else {
  3107. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3108. }
  3109. }
  3110. func (this *SupplyOrderApiController) CheckGoodOrderById() {
  3111. id, _ := this.GetInt64("id")
  3112. recordDateStr := time.Now().Format("2006-01-02")
  3113. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3114. record_date := recordDate.Unix()
  3115. checker := this.GetAdminUserInfo().AdminUser.Id
  3116. out := models.SpSupplierWarehouseOut{
  3117. IsCheck: 1,
  3118. Checker: checker,
  3119. CheckTime: record_date,
  3120. }
  3121. err := service.UpdateSupplyGoodOrder(id, out)
  3122. if err == nil {
  3123. this.ServeSuccessJSON(map[string]interface{}{
  3124. "out": out,
  3125. })
  3126. } else {
  3127. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3128. }
  3129. }
  3130. func (this *SupplyOrderApiController) CheckReturnOrder() {
  3131. id, _ := this.GetInt64("id")
  3132. warehouse_out_id, _ := this.GetInt64("warehouse_out_id")
  3133. recordDateStr := time.Now().Format("2006-01-02")
  3134. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3135. orgId := this.GetAdminUserInfo().CurrentOrgId
  3136. record_date := recordDate.Unix()
  3137. checker := this.GetAdminUserInfo().AdminUser.Id
  3138. houseConfig, _ := service.GetAllStoreHouseConfig(this.GetAdminUserInfo().CurrentOrgId)
  3139. //获取退库单详情
  3140. list, _ := service.GetSupplyCancelOrderDetail(id, orgId)
  3141. for _, item := range list {
  3142. var total_count int64
  3143. var prescribing_number_total int64
  3144. //药品
  3145. if item.IsSource == 1 {
  3146. //获取药品库存
  3147. info, _ := service.GetDrugTotalCountTwenTy(item.ProjectId, item.SupplyWarehouseDetailInfo, item.Type, houseConfig.DrugStorehouseOut)
  3148. for _, it := range info {
  3149. if it.MaxUnit == it.CountUnit {
  3150. it.StockMaxNumber = it.StockMaxNumber * it.MinNumber
  3151. }
  3152. total_count += (it.StockMaxNumber + it.StockMinNumber)
  3153. }
  3154. //查询改药品信息
  3155. medical, _ := service.GetBaseDrugMedical(item.ProjectId)
  3156. //判断单位是否相等
  3157. if medical.MaxUnit == item.SupplyUnit {
  3158. //转化为最小单位
  3159. prescribing_number_total = item.SupplyCount * medical.MinNumber
  3160. }
  3161. if medical.MinUnit == item.SupplyUnit {
  3162. prescribing_number_total = item.SupplyCount
  3163. }
  3164. //判断单位
  3165. if total_count == 0 {
  3166. goodObj, _ := service.GetDrugByGoodId(item.ProjectId)
  3167. this.ServeSuccessJSON(map[string]interface{}{
  3168. "msg": "3",
  3169. "drug_name": goodObj.DrugName,
  3170. "dose": goodObj.Dose,
  3171. "dose_unit": goodObj.DoseUnit,
  3172. "min_number": goodObj.MinNumber,
  3173. "min_unit": goodObj.MinUnit,
  3174. "max_unit": goodObj.MaxUnit,
  3175. })
  3176. return
  3177. }
  3178. if prescribing_number_total > total_count {
  3179. goodObj, _ := service.GetDrugByGoodId(item.ProjectId)
  3180. this.ServeSuccessJSON(map[string]interface{}{
  3181. "msg": "3",
  3182. "drug_name": goodObj.DrugName,
  3183. "dose": goodObj.Dose,
  3184. "dose_unit": goodObj.DoseUnit,
  3185. "min_number": goodObj.MinNumber,
  3186. "min_unit": goodObj.MinUnit,
  3187. "max_unit": goodObj.MaxUnit,
  3188. })
  3189. return
  3190. }
  3191. ctime := time.Now().Unix()
  3192. timeStr := time.Now().Format("2006-01-02")
  3193. timeArr := strings.Split(timeStr, "-")
  3194. total, _ := service.FindAllDrugWarehouseOut(orgId)
  3195. total = total + 1
  3196. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3197. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3198. number = number + total
  3199. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  3200. //operation_time := time.Now().Unix()
  3201. creater := this.GetAdminUserInfo().AdminUser.Id
  3202. recordDateStr := time.Now().Format("2006-01-02")
  3203. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3204. orgId := this.GetAdminUserInfo().CurrentOrgId
  3205. record_date := recordDate.Unix()
  3206. warehouseOut := models.DrugWarehouseOut{
  3207. WarehouseOutOrderNumber: warehousing_out_order,
  3208. OperationTime: record_date,
  3209. OrgId: orgId,
  3210. Creater: creater,
  3211. Ctime: ctime,
  3212. Status: 1,
  3213. WarehouseOutTime: record_date,
  3214. Type: 1,
  3215. SupplyCancelOutId: id,
  3216. SupplyWarehouseId: warehouse_out_id,
  3217. StorehouseId: houseConfig.DrugStorehouseOut,
  3218. IsCheck: 1,
  3219. }
  3220. // 查询今日是否存在出库单
  3221. _, errcodes := service.GetDrugWarehouseOutById(orgId, record_date)
  3222. if errcodes == gorm.ErrRecordNotFound {
  3223. service.AddSigleDrugWarehouseOut(&warehouseOut)
  3224. }
  3225. lastDrug, _ := service.GetLastDrugWarehouseById(orgId, record_date)
  3226. //获取
  3227. warehouseOutInfo := &models.DrugWarehouseOutInfo{
  3228. WarehouseOutOrderNumber: lastDrug.WarehouseOutOrderNumber,
  3229. WarehouseOutId: lastDrug.ID,
  3230. DrugId: item.ProjectId,
  3231. Count: item.SupplyCount,
  3232. Price: item.Price,
  3233. Status: 1,
  3234. Ctime: ctime,
  3235. Remark: "",
  3236. OrgId: orgId,
  3237. Type: 1,
  3238. Manufacturer: item.ManufacturerId,
  3239. Dealer: 0,
  3240. CountUnit: item.SupplyUnit,
  3241. ExpiryDate: item.SupplyExpiryDate,
  3242. ProductDate: item.SupplyProductDate,
  3243. Number: item.SupplyLicenseNumber,
  3244. BatchNumber: item.SupplyBatchNumber,
  3245. IsSys: 0,
  3246. WarehouseInfoId: 0,
  3247. SupplyCancelOutId: id,
  3248. SupplyWarehouseId: warehouse_out_id,
  3249. SysRecordTime: record_date,
  3250. IsSource: item.Type,
  3251. StorehouseId: houseConfig.DrugStorehouseOut,
  3252. IsCheck: 1,
  3253. }
  3254. drup, _ := service.FindBaseDrugLibRecord(orgId, item.ProjectId)
  3255. if drup.ID > 0 {
  3256. prescribingNumber := item.SupplyCount
  3257. service.AutoDrugDeliverInfoNight(orgId, prescribingNumber, &warehouseOut, &drup, warehouseOutInfo, warehouse_out_id, id)
  3258. }
  3259. //查询默认仓库
  3260. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  3261. //查询默认仓库剩余多少库存
  3262. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, orgId, drup.ID)
  3263. var sum_count int64
  3264. var sum_in_count int64
  3265. for _, it := range list {
  3266. baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  3267. if it.MaxUnit == baseDrug.MaxUnit {
  3268. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  3269. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  3270. }
  3271. sum_count += it.StockMaxNumber + it.StockMinNumber
  3272. sum_in_count += it.WarehousingCount
  3273. }
  3274. service.UpdateDrugCountOne(houseConfig.DrugStorehouseOut, orgId, drup.ID, sum_count)
  3275. }
  3276. //耗材
  3277. if item.IsSource == 2 {
  3278. // 查询该耗材是否有库存
  3279. warehouseOne, _ := service.FindWarehousingInfoTwenTy(item.ProjectId, item.SupplyWarehouseDetailInfo, item.Type, houseConfig.StorehouseOutInfo)
  3280. // 如果出库数量大于该批次剩余库存数量
  3281. if item.SupplyCount > warehouseOne.StockCount {
  3282. goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
  3283. this.ServeSuccessJSON(map[string]interface{}{
  3284. "msg": "2",
  3285. "good_name": goodObj.GoodName,
  3286. "specification_name": goodObj.SpecificationName,
  3287. })
  3288. return
  3289. }
  3290. ctime := time.Now().Unix()
  3291. timeStr := time.Now().Format("2006-01-02")
  3292. timeArr := strings.Split(timeStr, "-")
  3293. total, _ := service.FindAllWarehouseOut(orgId)
  3294. total = total + 1
  3295. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3296. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3297. number = number + total
  3298. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3299. //operation_time := time.Now().Unix()
  3300. creater := this.GetAdminUserInfo().AdminUser.Id
  3301. recordDateStr := time.Now().Format("2006-01-02")
  3302. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3303. record_date := recordDate.Unix()
  3304. warehouseOut := models.WarehouseOut{
  3305. WarehouseOutOrderNumber: warehousing_out_order,
  3306. OperationTime: record_date,
  3307. OrgId: orgId,
  3308. Creater: creater,
  3309. Ctime: ctime,
  3310. Status: 1,
  3311. WarehouseOutTime: record_date,
  3312. Type: 1,
  3313. SupplyCancelOutId: id,
  3314. SupplyWarehouseId: warehouse_out_id,
  3315. IsSys: 0,
  3316. StorehouseId: houseConfig.StorehouseOutInfo,
  3317. IsCheck: 1,
  3318. }
  3319. //查询是否生成出库单
  3320. _, errcodes := service.FindStockOutByIsSys(orgId, 0, record_date)
  3321. if errcodes == gorm.ErrRecordNotFound {
  3322. service.AddSigleWarehouseOutOne(&warehouseOut)
  3323. }
  3324. outWarehouse, _ := service.GetlastWarehouseOutById(orgId, record_date)
  3325. goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
  3326. info := &models.WarehouseOutInfo{
  3327. WarehouseOutOrderNumber: outWarehouse.WarehouseOutOrderNumber,
  3328. WarehouseOutId: outWarehouse.ID,
  3329. WarehouseInfotId: 0,
  3330. GoodId: item.ProjectId,
  3331. GoodTypeId: goodObj.GoodTypeId,
  3332. Count: item.SupplyCount,
  3333. Price: item.Price,
  3334. TotalPrice: 0,
  3335. ProductDate: item.SupplyProductDate,
  3336. ExpiryDate: item.SupplyExpiryDate,
  3337. Type: 0,
  3338. Dealer: 0,
  3339. Manufacturer: item.ManufacturerId,
  3340. IsSys: 0,
  3341. SysRecordTime: record_date,
  3342. Number: item.SupplyBatchNumber,
  3343. LicenseNumber: item.SupplyLicenseNumber,
  3344. ConsumableType: 0,
  3345. SupplyCancelOutId: id,
  3346. OrgId: orgId,
  3347. SupplyWarehouseId: warehouse_out_id,
  3348. IsSource: item.Type,
  3349. StorehouseId: houseConfig.StorehouseOutInfo,
  3350. IsCheck: 1,
  3351. }
  3352. //出库逻辑
  3353. parseDateErr := service.ConsumablesDeliveryNight(orgId, record_date, info, &warehouseOut, item.SupplyCount, creater, warehouse_out_id, id)
  3354. if parseDateErr != nil {
  3355. utils.ErrorLog(parseDateErr.Error())
  3356. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
  3357. return
  3358. }
  3359. //查询该机构默认仓库
  3360. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  3361. //查询剩余库存
  3362. goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.ProjectId, orgId)
  3363. var sum_count int64
  3364. for _, item := range goodList {
  3365. sum_count += item.StockCount
  3366. }
  3367. //更新剩余库存
  3368. service.UpdateGoodFlushCount(storeConfig.StorehouseOutInfo, item.ProjectId, orgId, sum_count)
  3369. }
  3370. }
  3371. cancel := models.SpSupplierWarehouseCancel{
  3372. IsCheck: 1,
  3373. Checker: checker,
  3374. CheckTime: record_date,
  3375. }
  3376. err := service.CheckReturnOrder(id, orgId, cancel)
  3377. if err == nil {
  3378. this.ServeSuccessJSON(map[string]interface{}{
  3379. "msg": "1",
  3380. "drug_name": "",
  3381. "dose": "",
  3382. "dose_unit": "",
  3383. "min_number": "",
  3384. "min_unit": "",
  3385. "max_unit": "",
  3386. })
  3387. return
  3388. }
  3389. }
  3390. func (this *SupplyOrderApiController) DeletePurchaseOrder() {
  3391. id, _ := this.GetInt64("id")
  3392. err := service.DeletePurchaseOrder(id)
  3393. if err == nil {
  3394. returnData := make(map[string]interface{}, 0)
  3395. returnData["msg"] = "ok"
  3396. this.ServeSuccessJSON(returnData)
  3397. return
  3398. } else {
  3399. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3400. }
  3401. }
  3402. func (this *SupplyOrderApiController) DeleteGoodOrderById() {
  3403. id, _ := this.GetInt64("id")
  3404. err := service.DeleteGoodOrderById(id)
  3405. if err == nil {
  3406. returnData := make(map[string]interface{}, 0)
  3407. returnData["msg"] = "ok"
  3408. this.ServeSuccessJSON(returnData)
  3409. return
  3410. } else {
  3411. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3412. }
  3413. }
  3414. func (this *SupplyOrderApiController) DeleteReturnOrder() {
  3415. id, _ := this.GetInt64("id")
  3416. err := service.DeleteReturnOrder(id)
  3417. if err == nil {
  3418. returnData := make(map[string]interface{}, 0)
  3419. returnData["msg"] = "ok"
  3420. this.ServeSuccessJSON(returnData)
  3421. return
  3422. } else {
  3423. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3424. }
  3425. }
  3426. func (this *SupplyOrderApiController) DeleteReturnOrderById() {
  3427. id, _ := this.GetInt64("id")
  3428. err := service.DeleteReturnOrderById(id)
  3429. if err == nil {
  3430. returnData := make(map[string]interface{}, 0)
  3431. returnData["msg"] = "ok"
  3432. this.ServeSuccessJSON(returnData)
  3433. return
  3434. } else {
  3435. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3436. }
  3437. }
  3438. func (this *SupplyOrderApiController) ModefyReturnOrder() {
  3439. id, _ := this.GetInt64("id")
  3440. err := service.ModefyReturnOrder(id)
  3441. //获取退库单据日期
  3442. cancel, _ := service.GetReturnOrderById(id)
  3443. orgId := this.GetAdminUserInfo().CurrentOrgId
  3444. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  3445. if err == nil {
  3446. //获取退库单详情
  3447. list, _ := service.GetSupplyCancelOrderDetail(id, orgId)
  3448. for _, item := range list {
  3449. //药品
  3450. if item.IsSource == 1 {
  3451. base, _ := service.GetDrugDetailByDrugId(item.ProjectId)
  3452. //更改库存
  3453. if item.SupplyUnit == base.MaxUnit {
  3454. //退库
  3455. drugInfo := models.DrugWarehouseInfo{
  3456. StockMaxNumber: item.SupplyCount,
  3457. }
  3458. service.UpdateDrugWasehousring(item.ProjectId, item.SupplyWarehouseDetailInfo, drugInfo)
  3459. var sum_count int64
  3460. sum_count = item.SupplyCount * base.MinNumber
  3461. service.ModifyDrugAddInformation(item.ProjectId, sum_count, orgId)
  3462. //出库数量减少
  3463. service.ReduceDrugSumOut(houseConfig.DrugStorehouseOut, orgId, item.ProjectId, sum_count)
  3464. }
  3465. if item.SupplyType == base.MinUnit && base.MaxUnit != base.MinUnit {
  3466. drugInfo := models.DrugWarehouseInfo{
  3467. StockMinNumber: item.SupplyCount,
  3468. }
  3469. service.UpdateDrugWasehousringOne(item.ProjectId, item.SupplyWarehouseDetailInfo, drugInfo)
  3470. service.ModifyDrugAddInformation(item.ProjectId, item.SupplyCount, orgId)
  3471. //出库数量减少
  3472. service.ReduceDrugSumOut(houseConfig.DrugStorehouseOut, orgId, item.ProjectId, item.SupplyCount)
  3473. }
  3474. //删除流水
  3475. service.DeleteDrugWarehouseOutNight(item.ProjectId, item.WarehouseCancelId)
  3476. //查询出库订单
  3477. drugOut, _ := service.GetDrugWarehouseByDate(cancel.RecordDate, orgId)
  3478. drugOutList, _ := service.GetDrugWarehouseByIdList(drugOut.ID, orgId)
  3479. if len(drugOutList) == 0 {
  3480. service.UpdateDrugWarehouseById(drugOut.ID)
  3481. }
  3482. //查询默认仓库剩余多少库存
  3483. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, orgId, item.ProjectId)
  3484. var sum_count int64
  3485. var sum_in_count int64
  3486. for _, it := range list {
  3487. baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  3488. if it.MaxUnit == baseDrug.MaxUnit {
  3489. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  3490. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  3491. }
  3492. sum_count += it.StockMaxNumber + it.StockMinNumber
  3493. sum_in_count += it.WarehousingCount
  3494. }
  3495. service.UpdateDrugCountOne(houseConfig.DrugStorehouseOut, orgId, item.ProjectId, sum_count)
  3496. }
  3497. //耗材
  3498. if item.IsSource == 2 {
  3499. //退库
  3500. info := models.WarehousingInfo{
  3501. StockCount: item.SupplyCount,
  3502. }
  3503. //更改库存
  3504. err := service.UpdateWarehousingInfoById(item.ProjectId, item.SupplyWarehouseDetailInfo, info)
  3505. fmt.Println("更改库存3232323223322332")
  3506. service.ModifyGoodAddInformation(item.ProjectId, item.SupplyCount, item.UserOrgId)
  3507. //扣减出库数量
  3508. service.ReduceGoodSumOutCount(houseConfig.StorehouseOutInfo, item.ProjectId, item.UserOrgId, item.SupplyCount)
  3509. //查询剩余库存
  3510. goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.ProjectId, item.UserOrgId)
  3511. var sum_count int64
  3512. for _, item := range goodList {
  3513. sum_count += item.StockCount
  3514. }
  3515. //更新剩余库存
  3516. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, item.UserOrgId, sum_count)
  3517. fmt.Println(err)
  3518. //删除出库记录
  3519. service.DeleteGoodWarehouseOut(item.ProjectId, item.WarehouseCancelId, orgId)
  3520. //查询今日的出库单是
  3521. out, _ := service.GetWarehouseOutByDate(cancel.RecordDate, orgId)
  3522. warehouseOutList, _ := service.GetWarehouseOutById(out.ID, orgId)
  3523. if len(warehouseOutList) == 0 {
  3524. //删除出库单
  3525. service.DeleteWarehouseOutById(out.ID)
  3526. }
  3527. }
  3528. }
  3529. } else {
  3530. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3531. }
  3532. if err == nil {
  3533. returnData := make(map[string]interface{}, 0)
  3534. returnData["msg"] = "ok"
  3535. this.ServeSuccessJSON(returnData)
  3536. return
  3537. } else {
  3538. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3539. }
  3540. }
  3541. func (this *SupplyOrderApiController) GetGoodOrderDetailList() {
  3542. id, _ := this.GetInt64("id")
  3543. ids := this.GetString("ids")
  3544. orgId := this.GetAdminUserInfo().CurrentOrgId
  3545. if len(ids) == 0 {
  3546. out, err := service.GetGoodOrderDetail(id, orgId)
  3547. list, _ := service.GetSupplyWarehouseOutById(id, orgId)
  3548. for _, item := range list {
  3549. if item.IsSource == 1 {
  3550. waresingList, _ := service.GetAllDrugWaresingList(item.ProjectId, orgId)
  3551. medical, _ := service.GetBaseDrugMedical(item.ProjectId)
  3552. item.DrugWarehouseInfo = waresingList
  3553. item.SpBaseDrug = medical
  3554. }
  3555. if item.IsSource == 2 {
  3556. waresingList, _ := service.GetAllGoodWaresingList(item.ProjectId, orgId)
  3557. item.GoodWarehouseInfo = waresingList
  3558. }
  3559. }
  3560. drugList, _ := service.GetSupplyDrugList(orgId)
  3561. goodList, _ := service.GetSupplyGoodList(orgId)
  3562. supplyList, _ := service.GetSupplierList(orgId)
  3563. if err == nil {
  3564. this.ServeSuccessJSON(map[string]interface{}{
  3565. "out": out,
  3566. "list": list,
  3567. "goodList": goodList,
  3568. "drugList": drugList,
  3569. "supplyList": supplyList,
  3570. })
  3571. } else {
  3572. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3573. }
  3574. }
  3575. if len(ids) > 0 {
  3576. idArray := strings.Split(ids, ",")
  3577. out, err := service.GetGoodOrderDetail(id, orgId)
  3578. list, _ := service.GetSupplyWarehouseOutByIdOne(id, orgId, idArray)
  3579. for _, item := range list {
  3580. if item.IsSource == 1 {
  3581. waresingList, _ := service.GetAllDrugWaresingList(item.ProjectId, orgId)
  3582. medical, _ := service.GetBaseDrugMedical(item.ProjectId)
  3583. item.DrugWarehouseInfo = waresingList
  3584. item.SpBaseDrug = medical
  3585. }
  3586. if item.IsSource == 2 {
  3587. waresingList, _ := service.GetAllGoodWaresingList(item.ProjectId, orgId)
  3588. item.GoodWarehouseInfo = waresingList
  3589. }
  3590. }
  3591. drugList, _ := service.GetSupplyDrugList(orgId)
  3592. goodList, _ := service.GetSupplyGoodList(orgId)
  3593. supplyList, _ := service.GetSupplierList(orgId)
  3594. if err == nil {
  3595. this.ServeSuccessJSON(map[string]interface{}{
  3596. "out": out,
  3597. "list": list,
  3598. "goodList": goodList,
  3599. "drugList": drugList,
  3600. "supplyList": supplyList,
  3601. })
  3602. } else {
  3603. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3604. }
  3605. }
  3606. }