supply_order_api_contorller.go 97KB

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