supply_order_api_contorller.go 120KB

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