supply_order_api_contorller.go 132KB

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