supply_order_api_contorller.go 128KB

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