supply_order_api_contorller.go 115KB

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