supply_order_api_contorller.go 97KB

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