supply_order_api_contorller.go 88KB

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