supply_order_api_contorller.go 121KB

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