supply_order_api_contorller.go 110KB

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