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