supply_order_api_contorller.go 132KB

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