supply_order_api_contorller.go 110KB

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