supply_order_api_contorller.go 137KB

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