supply_order_api_contorller.go 133KB

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