supply_order_api_contorller.go 101KB

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