supply_order_api_contorller.go 98KB

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