supply_order_api_contorller.go 98KB

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