supply_order_api_contorller.go 119KB

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