supply_order_api_contorller.go 96KB

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