supply_order_api_contorller.go 124KB

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