stock_template.go 119 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880
  1. package controllers
  2. import (
  3. "Medical_ERP/common/actions"
  4. "Medical_ERP/common/global"
  5. _ "Medical_ERP/common/response"
  6. "Medical_ERP/dto"
  7. "Medical_ERP/models"
  8. "Medical_ERP/services"
  9. "Medical_ERP/utils"
  10. "baliance.com/gooxml/color"
  11. "baliance.com/gooxml/document"
  12. "baliance.com/gooxml/measurement"
  13. "baliance.com/gooxml/schema/soo/wml"
  14. "errors"
  15. "fmt"
  16. context2 "github.com/beego/beego/v2/adapter/context"
  17. "github.com/beego/beego/v2/core/logs"
  18. "github.com/boombuler/barcode"
  19. "github.com/boombuler/barcode/code128"
  20. "github.com/ser163/png2j"
  21. "github.com/signintech/gopdf"
  22. "github.com/xuri/excelize/v2"
  23. "gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth/beegouser"
  24. "image/jpeg"
  25. "log"
  26. "path"
  27. "strings"
  28. _ "image/jpeg"
  29. "image/png"
  30. "os"
  31. "time"
  32. )
  33. type StockTemplateController struct {
  34. BaseController
  35. }
  36. // StockTemplateIn 入库
  37. // @Summary 入库
  38. // @Description 入库
  39. // @Tags 库存
  40. // @Param body body dto.StockTemplateInInsertReq true "body"
  41. // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
  42. // @Router /stock-template/in [post]
  43. // @Security Bearer
  44. func (c StockTemplateController) StockTemplateIn() {
  45. s := services.StockTemplate{}
  46. reqData := dto.StockTemplateInInsertReq{}
  47. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  48. err = errors.New("解析表单数据异常")
  49. c.Error(global.ParseFormErr, err, err.Error())
  50. return
  51. }
  52. reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
  53. reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
  54. reqData.State = models.StateStockRefundIn
  55. err := s.StockTemplateIn(&reqData)
  56. if err != nil {
  57. c.Error(500, err, err.Error())
  58. return
  59. }
  60. c.OK(reqData.GetId(), "入库成功")
  61. }
  62. // StockTemplateInScanCode 扫码入库
  63. // @Summary 扫码入库
  64. // @Description 扫码入库
  65. // @Tags 库存
  66. // @Param body body dto.StockTemplateInInsertReq true "body"
  67. // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
  68. // @Router /stock-template/in [post]
  69. // @Security Bearer
  70. func (c StockTemplateController) StockTemplateInScanCode() {
  71. s := services.StockTemplate{}
  72. reqData := dto.BatchStockTemplateInInsertReq{}
  73. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  74. err = errors.New("解析表单数据异常")
  75. c.Error(global.ParseFormErr, err, err.Error())
  76. return
  77. }
  78. reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
  79. reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
  80. reqData.State = models.StateStockIn
  81. err := s.StockTemplateInScanCode(&reqData)
  82. if err != nil {
  83. c.Error(500, err, err.Error())
  84. return
  85. }
  86. c.OK(nil, "扫码入库成功")
  87. }
  88. // StockTemplateInEdit 修改入库
  89. // @Summary 修改入库
  90. // @Description 修改入库
  91. // @Tags 库存
  92. // @Param body body dto.StockTemplateInEditReq true "body"
  93. // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
  94. // @Router /stock-template/in [post]
  95. // @Security Bearer
  96. func (c StockTemplateController) StockTemplateInEdit() {
  97. s := services.StockTemplate{}
  98. reqData := dto.StockTemplateInEditReq{}
  99. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  100. err = errors.New("解析表单数据异常")
  101. c.Error(global.ParseFormErr, err, err.Error())
  102. return
  103. }
  104. reqData.SetUpdateBy(beegouser.GetUserId(c.Ctx))
  105. reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
  106. err := s.StockTemplateInEdit(&reqData)
  107. if err != nil {
  108. c.Error(500, err, err.Error())
  109. return
  110. }
  111. c.OK(reqData.GetId(), "修改入库信息成功")
  112. }
  113. // StockTemplateInDelete 删除入库
  114. // @Summary 删除入库
  115. // @Description 删除入库
  116. // @Tags 库存
  117. // @Param body body dto.StockTemplateInDeleteReq true "body"
  118. // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
  119. // @Router /stock-template/in [post]
  120. // @Security Bearer
  121. func (c StockTemplateController) StockTemplateInDelete() {
  122. s := services.StockTemplate{}
  123. reqData := dto.StockTemplateInDeleteReq{}
  124. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  125. err = errors.New("解析表单数据异常")
  126. c.Error(global.ParseFormErr, err, err.Error())
  127. return
  128. }
  129. reqData.SetUpdateBy(beegouser.GetUserId(c.Ctx))
  130. reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
  131. err := s.StockTemplateInDelete(&reqData)
  132. if err != nil {
  133. c.Error(500, err, err.Error())
  134. return
  135. }
  136. c.OK(reqData.GetId(), "删除入库信息成功")
  137. }
  138. // BatchStockTemplateIn 批量入库
  139. // @Summary 批量入库
  140. // @Description 批量入库
  141. // @Tags 库存
  142. // @Param body body dto.BatchStockTemplateInInsertReq true "body"
  143. // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
  144. // @Router /stock-template/in [post]
  145. // @Security Bearer
  146. func (c StockTemplateController) BatchStockTemplateIn() {
  147. s := services.StockTemplate{}
  148. reqData := dto.BatchStockTemplateInInsertReq{}
  149. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  150. err = errors.New("解析表单数据异常")
  151. c.Error(global.ParseFormErr, err, err.Error())
  152. return
  153. }
  154. reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
  155. reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
  156. reqData.State = models.StateStockIn
  157. err := s.BatchStockTemplateIn(&reqData)
  158. if err != nil {
  159. c.Error(500, err, err.Error())
  160. return
  161. }
  162. c.OK(nil, "入库成功")
  163. }
  164. // StockTemplateRefundIn 退货入库
  165. // @Summary 退货入库
  166. // @Description 退货入库
  167. // @Tags 库存
  168. // @Param body body dto.StockTemplateInInsertReq true "body"
  169. // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
  170. // @Router /stock-template/in [post]
  171. // @Security Bearer
  172. func (c StockTemplateController) StockTemplateRefundIn() {
  173. s := services.StockTemplate{}
  174. reqData := dto.StockTemplateInInsertReq{}
  175. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  176. err = errors.New("解析表单数据异常")
  177. c.Error(global.ParseFormErr, err, err.Error())
  178. return
  179. }
  180. reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
  181. reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
  182. reqData.State = models.StateStockRefundIn
  183. err := s.StockTemplateIn(&reqData)
  184. if err != nil {
  185. c.Error(500, err, err.Error())
  186. return
  187. }
  188. c.OK(reqData.GetId(), "入库成功")
  189. }
  190. // StockTemplateRefundInScanCode 扫码退货入库
  191. // @Summary 扫码入库
  192. // @Description 扫码入库
  193. // @Tags 库存
  194. // @Param body body dto.StockTemplateInInsertReq true "body"
  195. // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
  196. // @Router /stock-template/in [post]
  197. // @Security Bearer
  198. func (c StockTemplateController) StockTemplateRefundInScanCode() {
  199. s := services.StockTemplate{}
  200. reqData := dto.BatchStockTemplateInInsertReq{}
  201. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  202. err = errors.New("解析表单数据异常")
  203. c.Error(global.ParseFormErr, err, err.Error())
  204. return
  205. }
  206. reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
  207. reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
  208. reqData.State = models.StateStockRefundIn
  209. err := s.StockTemplateInScanCode(&reqData)
  210. if err != nil {
  211. c.Error(500, err, err.Error())
  212. return
  213. }
  214. c.OK(nil, "扫码退货入库成功")
  215. }
  216. // BatchStockTemplateRefundIn 批量退货入库
  217. // @Summary 批量退货入库
  218. // @Description 批量退货入库
  219. // @Tags 库存
  220. // @Param body body dto.BatchStockTemplateInInsertReq true "body"
  221. // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
  222. // @Router /stock-template/in [post]
  223. // @Security Bearer
  224. func (c StockTemplateController) BatchStockTemplateRefundIn() {
  225. s := services.StockTemplate{}
  226. reqData := dto.BatchStockTemplateInInsertReq{}
  227. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  228. err = errors.New("解析表单数据异常")
  229. c.Error(global.ParseFormErr, err, err.Error())
  230. return
  231. }
  232. reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
  233. reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
  234. reqData.State = models.StateStockRefundIn
  235. err := s.BatchStockTemplateIn(&reqData)
  236. if err != nil {
  237. c.Error(500, err, err.Error())
  238. return
  239. }
  240. c.OK(nil, "入库成功")
  241. }
  242. // StockTemplateOut 出库
  243. // @Summary 出库
  244. // @Description 出库
  245. // @Tags 库存
  246. // @Param body body dto.StockTemplateOutInsertReq true "body"
  247. // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
  248. // @Router /stock-template/out [post]
  249. // @Security Bearer
  250. func (c StockTemplateController) StockTemplateOut() {
  251. s := services.StockTemplate{}
  252. reqData := dto.StockTemplateOutInsertReq{}
  253. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  254. err = errors.New("解析表单数据异常")
  255. c.Error(global.ParseFormErr, err, err.Error())
  256. return
  257. }
  258. reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
  259. reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
  260. reqData.State = models.StateStockOut
  261. err := s.StockTemplateOut(&reqData)
  262. if err != nil {
  263. c.Error(500, err, err.Error())
  264. return
  265. }
  266. c.OK(reqData.GetId(), "出库成功")
  267. }
  268. // StockTemplateOutScanCode 扫码出库
  269. // @Summary 扫码出库
  270. // @Description 扫码出库
  271. // @Tags 库存
  272. // @Param body body dto.StockTemplateOutInsertReq true "body"
  273. // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
  274. // @Router /stock-template/out [post]
  275. // @Security Bearer
  276. func (c StockTemplateController) StockTemplateOutScanCode() {
  277. s := services.StockTemplate{}
  278. reqData := dto.BatchStockTemplateOutInsertReq{}
  279. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  280. err = errors.New("解析表单数据异常")
  281. c.Error(global.ParseFormErr, err, err.Error())
  282. return
  283. }
  284. logs.Debug("【扫码出库】请求信息 %v", reqData)
  285. reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
  286. reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
  287. reqData.State = models.StateStockOut
  288. err := s.StockTemplateOutScanCode(&reqData)
  289. if err != nil {
  290. c.Error(500, err, err.Error())
  291. return
  292. }
  293. c.OK(nil, "扫码出库成功")
  294. }
  295. // StockTemplateOutEdit 修改入库
  296. // @Summary 修改入库
  297. // @Description 修改入库
  298. // @Tags 库存
  299. // @Param body body dto.StockTemplateOutEditReq true "body"
  300. // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
  301. // @Router /stock-template/in [post]
  302. // @Security Bearer
  303. func (c StockTemplateController) StockTemplateOutEdit() {
  304. s := services.StockTemplate{}
  305. reqData := dto.StockTemplateOutEditReq{}
  306. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  307. err = errors.New("解析表单数据异常")
  308. c.Error(global.ParseFormErr, err, err.Error())
  309. return
  310. }
  311. reqData.SetUpdateBy(beegouser.GetUserId(c.Ctx))
  312. reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
  313. err := s.StockTemplateOutEdit(&reqData)
  314. if err != nil {
  315. c.Error(500, err, err.Error())
  316. return
  317. }
  318. c.OK(reqData.GetId(), "修改出库信息成功")
  319. }
  320. // StockTemplateOutDelete 删除入库
  321. // @Summary 删除入库
  322. // @Description 删除入库
  323. // @Tags 库存
  324. // @Param body body dto.StockTemplateOutDeleteReq true "body"
  325. // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
  326. // @Router /stock-template/in [post]
  327. // @Security Bearer
  328. func (c StockTemplateController) StockTemplateOutDelete() {
  329. s := services.StockTemplate{}
  330. reqData := dto.StockTemplateOutDeleteReq{}
  331. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  332. err = errors.New("解析表单数据异常")
  333. c.Error(global.ParseFormErr, err, err.Error())
  334. return
  335. }
  336. reqData.SetUpdateBy(beegouser.GetUserId(c.Ctx))
  337. reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
  338. err := s.StockTemplateOutDelete(&reqData)
  339. if err != nil {
  340. c.Error(500, err, err.Error())
  341. return
  342. }
  343. c.OK(reqData.GetId(), "删除出库信息成功")
  344. }
  345. // BatchStockTemplateOut 批量出库
  346. // @Summary 批量出库
  347. // @Description 批量出库
  348. // @Tags 库存
  349. // @Param body body dto.StockTemplateOutInsertReq true "body"
  350. // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
  351. // @Router /stock-template/out [post]
  352. // @Security Bearer
  353. func (c StockTemplateController) BatchStockTemplateOut() {
  354. s := services.StockTemplate{}
  355. reqData := dto.BatchStockTemplateOutInsertReq{}
  356. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  357. err = errors.New("解析表单数据异常")
  358. c.Error(global.ParseFormErr, err, err.Error())
  359. return
  360. }
  361. reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
  362. reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
  363. reqData.State = models.StateStockOut
  364. err := s.BatchStockTemplateOut(&reqData)
  365. if err != nil {
  366. c.Error(500, err, err.Error())
  367. return
  368. }
  369. c.OK(nil, "出库成功")
  370. }
  371. // StockTemplateRefundOut 退货/报废出库
  372. // @Summary 退货/报废出库
  373. // @Description 退货/报废出库
  374. // @Tags 库存
  375. // @Param body body dto.StockTemplateOutInsertReq true "body"
  376. // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
  377. // @Router /stock-template/out [post]
  378. // @Security Bearer
  379. func (c StockTemplateController) StockTemplateRefundOut() {
  380. s := services.StockTemplate{}
  381. reqData := dto.StockTemplateOutInsertReq{}
  382. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  383. err = errors.New("解析表单数据异常")
  384. c.Error(global.ParseFormErr, err, err.Error())
  385. return
  386. }
  387. reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
  388. reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
  389. if reqData.State != models.StateStockRefundOut && reqData.State != models.StateStockScrapOut {
  390. err := errors.New("出库状态错误")
  391. c.Error(500, err, err.Error())
  392. return
  393. }
  394. err := s.StockTemplateOut(&reqData)
  395. if err != nil {
  396. c.Error(500, err, err.Error())
  397. return
  398. }
  399. c.OK(reqData.GetId(), "退货(报废)出库成功")
  400. }
  401. // StockTemplateOutScanRefundCode 扫码退货/报废出库
  402. // @Summary 扫码退货/报废出库
  403. // @Description 扫码退货/报废出库
  404. // @Tags 库存
  405. // @Param body body dto.StockTemplateOutInsertReq true "body"
  406. // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
  407. // @Router /stock-template/out [post]
  408. // @Security Bearer
  409. func (c StockTemplateController) StockTemplateRefundOutScanCode() {
  410. s := services.StockTemplate{}
  411. reqData := dto.BatchStockTemplateOutInsertReq{}
  412. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  413. err = errors.New("解析表单数据异常")
  414. c.Error(global.ParseFormErr, err, err.Error())
  415. return
  416. }
  417. reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
  418. reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
  419. if reqData.State != models.StateStockRefundOut && reqData.State != models.StateStockScrapOut {
  420. err := errors.New("出库状态错误")
  421. c.Error(500, err, err.Error())
  422. return
  423. }
  424. err := s.StockTemplateOutScanCode(&reqData)
  425. if err != nil {
  426. c.Error(500, err, err.Error())
  427. return
  428. }
  429. c.OK(nil, "扫码退货(报废)出库成功")
  430. }
  431. // BatchStockTemplateRefundOut 批量退货/报废出库
  432. // @Summary 批量退货/报废出库
  433. // @Description 批量退货/报废出库
  434. // @Tags 库存
  435. // @Param body body dto.StockTemplateOutInsertReq true "body"
  436. // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
  437. // @Router /stock-template/out [post]
  438. // @Security Bearer
  439. func (c StockTemplateController) BatchStockTemplateRefundOut() {
  440. s := services.StockTemplate{}
  441. reqData := dto.BatchStockTemplateOutInsertReq{}
  442. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  443. err = errors.New("解析表单数据异常")
  444. c.Error(global.ParseFormErr, err, err.Error())
  445. return
  446. }
  447. reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
  448. reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
  449. if reqData.State != models.StateStockRefundOut && reqData.State != models.StateStockScrapOut {
  450. err := errors.New("出库状态错误")
  451. c.Error(500, err, err.Error())
  452. return
  453. }
  454. err := s.BatchStockTemplateOut(&reqData)
  455. if err != nil {
  456. c.Error(500, err, err.Error())
  457. return
  458. }
  459. c.OK(nil, "退货(报废)出库成功")
  460. }
  461. // StockTemplateInList 入库列表
  462. // @Summary 入库列表
  463. // @Description 入库列表
  464. // @Tags 库存
  465. // @Param body body dto.StockTemplateInPageReq true "body"
  466. // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
  467. // @Router /stock-template/in/list [post]
  468. // @Security Bearer
  469. func (c StockTemplateController) StockTemplateInList() {
  470. s := services.StockTemplate{}
  471. reqData := dto.StockTemplateInPageReq{}
  472. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  473. err = errors.New("解析表单数据异常")
  474. c.Error(global.ParseFormErr, err, err.Error())
  475. return
  476. }
  477. deptId := beegouser.GetDeptId(c.Ctx)
  478. list, count, err := s.StockTemplateInList(&reqData, deptId)
  479. if err != nil {
  480. c.Error(500, err, err.Error())
  481. return
  482. }
  483. c.PageOK(list, int(count), reqData.GetPageIndex(), reqData.GetPageSize(), "查询成功")
  484. }
  485. // StockTemplateOutList 出库列表
  486. // @Summary 出库列表
  487. // @Description 出库列表
  488. // @Tags 库存
  489. // @Param body body dto.StockTemplateOutPageReq true "body"
  490. // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
  491. // @Router /stock-template/out/list [post]
  492. // @Security Bearer
  493. func (c StockTemplateController) StockTemplateOutList() {
  494. s := services.StockTemplate{}
  495. reqData := dto.StockTemplateOutPageReq{}
  496. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  497. err = errors.New("解析表单数据异常")
  498. c.Error(global.ParseFormErr, err, err.Error())
  499. return
  500. }
  501. deptId := beegouser.GetDeptId(c.Ctx)
  502. list, count, err := s.StockTemplateOutList(&reqData, deptId)
  503. if err != nil {
  504. c.Error(500, err, err.Error())
  505. return
  506. }
  507. c.PageOK(list, int(count), reqData.GetPageIndex(), reqData.GetPageSize(), "查询成功")
  508. }
  509. // StockTemplateInventoryList 收发记录
  510. // @Summary 收发记录
  511. // @Description 收发记录
  512. // @Tags 库存
  513. // @Param body body dto.StockTemplateInventoryPageReq true "body"
  514. // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
  515. // @Router /stock/inventory/list [post]
  516. // @Security Bearer—
  517. func (c StockTemplateController) StockTemplateInventoryList() {
  518. s := services.StockTemplate{}
  519. reqData := dto.StockTemplateInventoryPageReq{}
  520. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  521. err = errors.New("解析表单数据异常")
  522. c.Error(global.ParseFormErr, err, err.Error())
  523. return
  524. }
  525. deptId := beegouser.GetDeptId(c.Ctx)
  526. list, count, err := s.StockTemplateInventoryList(&reqData, deptId)
  527. if err != nil {
  528. c.Error(500, err, err.Error())
  529. return
  530. }
  531. c.PageOK(list, int(count), reqData.GetPageIndex(), reqData.GetPageSize(), "查询成功")
  532. }
  533. // StockTemplateInventoryExcel 收发登记表
  534. // @Summary 收发登记表
  535. // @Description 收发登记表
  536. // @Tags 库存
  537. // @Param body body dto.StockTemplateInventoryExcelReq true "body"
  538. // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
  539. // @Router /stock-template/inventory/list [post]
  540. // @Security Bearer
  541. func (c StockTemplateController) StockTemplateInventoryExcel(reqData dto.StockTemplateInventoryExcelReq) {
  542. s := services.StockTemplate{}
  543. deptId := beegouser.GetDeptId(c.Ctx)
  544. models.InitBasicData(deptId)
  545. medicineInfo, _, err := s.GetMedicineInfo(deptId, map[string]interface{}{
  546. "product_id": reqData.ProductID,
  547. "enterprise_id": reqData.EnterpriseID,
  548. "spec_id": reqData.SpecId,
  549. "batch_number": reqData.BatchNumber,
  550. })
  551. if err != nil {
  552. c.Error(global.BadRequest, err, "药品信息不存在")
  553. return
  554. }
  555. var productName, specName, unitName, dosageFormName string
  556. if id, ok := medicineInfo[models.FieldProductID]; ok {
  557. productName = models.Read_Product_Get(utils.ToInt(id))
  558. }
  559. if id, ok := medicineInfo[models.FieldSpecID]; ok {
  560. specName = models.Read_Spec_Get(utils.ToInt(id))
  561. }
  562. if id, ok := medicineInfo[models.FieldUnitID]; ok {
  563. unitName = models.Read_Unit_Get(utils.ToInt(id))
  564. }
  565. if id, ok := medicineInfo[models.FieldDosageFormID]; ok {
  566. dosageFormName = models.Read_DosageForm_Get(utils.ToInt(id))
  567. }
  568. list, err := s.StockTemplateInventoryExcel(&reqData, deptId)
  569. if err != nil {
  570. c.Error(500, err, err.Error())
  571. return
  572. }
  573. f := excelize.NewFile() // 设置单元格的值
  574. StyleTitle, _ := f.NewStyle(
  575. &excelize.Style{
  576. Font: &excelize.Font{Bold: true, Size: 20, Family: "宋体"},
  577. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
  578. })
  579. f.MergeCell("Sheet1", "A1", "O1")
  580. f.SetRowStyle("Sheet1", 1, 1, StyleTitle)
  581. f.SetRowHeight("Sheet1", 1, 50)
  582. var interval string
  583. if len(reqData.StartDate) > 0 && len(reqData.EndDate) > 0 {
  584. interval = fmt.Sprintf("%s至%s", reqData.StartDate, reqData.EndDate)
  585. }
  586. f.SetCellValue("Sheet1", "A1", fmt.Sprintf("%s收发登记表", interval))
  587. StyleLittleTitle, _ := f.NewStyle(
  588. &excelize.Style{
  589. Font: &excelize.Font{Size: 12, Family: "宋体"},
  590. })
  591. f.SetCellValue("Sheet1", "K2", fmt.Sprintf("制品名称:%s", productName))
  592. f.SetCellValue("Sheet1", "K3", fmt.Sprintf("剂型:%s 规格:%s 单位:%s", dosageFormName, specName, unitName))
  593. f.SetRowStyle("Sheet1", 2, 3, StyleLittleTitle)
  594. // 这里设置表头
  595. f.MergeCell("Sheet1", "A4", "A5")
  596. f.SetCellValue("Sheet1", "A4", "日期")
  597. f.MergeCell("Sheet1", "B4", "B5")
  598. f.SetCellValue("Sheet1", "B4", "购货/发货单位")
  599. f.MergeCell("Sheet1", "C4", "C5")
  600. f.SetCellValue("Sheet1", "C4", "生产企业")
  601. f.MergeCell("Sheet1", "D4", "D5")
  602. f.SetCellValue("Sheet1", "D4", "批准文号")
  603. f.MergeCell("Sheet1", "E4", "E5")
  604. f.SetCellValue("Sheet1", "E4", "批签发合格证编号")
  605. f.MergeCell("Sheet1", "F4", "H4")
  606. f.SetCellValue("Sheet1", "F4", "收入")
  607. f.SetCellValue("Sheet1", "F5", "数量")
  608. f.SetCellValue("Sheet1", "G5", "批号")
  609. f.SetCellValue("Sheet1", "H5", "失效日期")
  610. f.MergeCell("Sheet1", "I4", "K4")
  611. f.SetCellValue("Sheet1", "I4", "支出")
  612. f.SetCellValue("Sheet1", "I5", "数量")
  613. f.SetCellValue("Sheet1", "J5", "批号")
  614. f.SetCellValue("Sheet1", "K5", "失效日期")
  615. f.MergeCell("Sheet1", "L4", "N4")
  616. f.SetCellValue("Sheet1", "L4", "结余")
  617. f.SetCellValue("Sheet1", "L5", "数量")
  618. f.SetCellValue("Sheet1", "M5", "批号")
  619. f.SetCellValue("Sheet1", "N5", "失效日期")
  620. f.MergeCell("Sheet1", "O4", "O5")
  621. f.SetCellValue("Sheet1", "O4", "经办人签字")
  622. // 设置列宽
  623. f.SetColWidth("Sheet1", "A", "B", 10)
  624. f.SetColWidth("Sheet1", "B", "C", 14)
  625. f.SetColWidth("Sheet1", "C", "F", 12)
  626. f.SetColWidth("Sheet1", "F", "G", 8)
  627. f.SetColWidth("Sheet1", "G", "I", 12)
  628. f.SetColWidth("Sheet1", "I", "J", 8)
  629. f.SetColWidth("Sheet1", "J", "L", 12)
  630. f.SetColWidth("Sheet1", "L", "M", 8)
  631. f.SetColWidth("Sheet1", "M", "O", 12)
  632. f.SetColWidth("Sheet1", "O", "P", 12)
  633. line := 5
  634. // 循环写入数据
  635. for _, v := range list {
  636. line++
  637. f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), v["date"])
  638. f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v[models.FieldEnterpriseName])
  639. f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v[models.FieldApprovalNumber])
  640. f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v[models.FieldQualificationNumber])
  641. if utils.ToInt(v["stock_in_id"]) > 0 {
  642. f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), v["forwarding_unit"])
  643. f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), utils.ToInt(v["total_in"]))
  644. f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), v[models.FieldApprovalNumber])
  645. f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), utils.ToDate(v[models.FieldExpiryDate]))
  646. }
  647. if utils.ToInt(v["stock_out_id"]) > 0 {
  648. f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), v["receiving_unit"])
  649. f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), utils.ToInt(v["total_out"]))
  650. f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), v[models.FieldApprovalNumber])
  651. f.SetCellValue("Sheet1", fmt.Sprintf("K%d", line), utils.ToDate(v[models.FieldExpiryDate]))
  652. }
  653. f.SetCellValue("Sheet1", fmt.Sprintf("L%d", line), utils.ToInt(v["balance"]))
  654. f.SetCellValue("Sheet1", fmt.Sprintf("M%d", line), v[models.FieldApprovalNumber])
  655. f.SetCellValue("Sheet1", fmt.Sprintf("N%d", line), utils.ToDate(v[models.FieldExpiryDate]))
  656. f.SetCellValue("Sheet1", fmt.Sprintf("O%d", line), v["operator"])
  657. }
  658. f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line+1), "保管单位:"+beegouser.GetDeptName(c.Ctx))
  659. f.SetRowStyle("Sheet1", line+1, line+1, StyleLittleTitle)
  660. Style1, _ := f.NewStyle(
  661. &excelize.Style{
  662. Font: &excelize.Font{Size: 13, Family: "宋体", Bold: true},
  663. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  664. Border: []excelize.Border{
  665. {Type: "left", Color: "000000", Style: 1},
  666. {Type: "top", Color: "000000", Style: 1},
  667. {Type: "bottom", Color: "000000", Style: 1},
  668. {Type: "right", Color: "000000", Style: 1},
  669. },
  670. })
  671. f.SetCellStyle("Sheet1", "A4", "O5", Style1)
  672. Style2, _ := f.NewStyle(
  673. &excelize.Style{
  674. Font: &excelize.Font{Size: 12, Family: "宋体"},
  675. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  676. Border: []excelize.Border{
  677. {Type: "left", Color: "000000", Style: 1},
  678. {Type: "top", Color: "000000", Style: 1},
  679. {Type: "bottom", Color: "000000", Style: 1},
  680. {Type: "right", Color: "000000", Style: 1},
  681. },
  682. })
  683. f.SetCellStyle("Sheet1", "A6", fmt.Sprintf("O%d", line), Style2)
  684. filename := "收发登记表" + time.Now().Format("20060102150405") + ".xlsx"
  685. // 保存文件
  686. if err := f.SaveAs("ofile/" + filename); err != nil {
  687. fmt.Println(err)
  688. }
  689. defer func() {
  690. os.Remove("ofile/" + filename)
  691. }()
  692. // 返回生成的 Excel 文件
  693. c.Ctx.Output.Download("ofile/" + filename)
  694. }
  695. func (c StockTemplateController) StockTemplateInventoryPdf(reqData dto.StockTemplateInventoryExcelReq) {
  696. s := services.StockTemplate{}
  697. deptId := beegouser.GetDeptId(c.Ctx)
  698. models.InitBasicData(deptId)
  699. medicineInfo, _, err := s.GetMedicineInfo(deptId, map[string]interface{}{
  700. "product_id": reqData.ProductID,
  701. "enterprise_id": reqData.EnterpriseID,
  702. "spec_id": reqData.SpecId,
  703. "batch_number": reqData.BatchNumber,
  704. })
  705. if err != nil {
  706. c.Error(global.BadRequest, err, "药品信息不存在")
  707. return
  708. }
  709. var productName, specName, unitName, dosageFormName string
  710. if id, ok := medicineInfo[models.FieldProductID]; ok {
  711. productName = models.Read_Product_Get(utils.ToInt(id))
  712. }
  713. if id, ok := medicineInfo[models.FieldSpecID]; ok {
  714. specName = models.Read_Spec_Get(utils.ToInt(id))
  715. }
  716. if id, ok := medicineInfo[models.FieldUnitID]; ok {
  717. unitName = models.Read_Unit_Get(utils.ToInt(id))
  718. }
  719. if id, ok := medicineInfo[models.FieldDosageFormID]; ok {
  720. dosageFormName = models.Read_DosageForm_Get(utils.ToInt(id))
  721. }
  722. list, err := s.StockTemplateInventoryExcel(&reqData, deptId)
  723. if err != nil {
  724. c.Error(500, err, err.Error())
  725. return
  726. }
  727. //cols := []float64{20, 24, 20, 18, 20, 12, 22, 20, 12, 22, 20, 12, 22, 20, 15}
  728. cols := []float64{58, 73, 59, 53, 53, 35, 65, 59, 40}
  729. cols1 := []float64{58, 73, 59, 53, 53, 35, 65, 59, 35, 65, 59, 35, 65, 59, 40}
  730. rows := [][]string{}
  731. for _, row := range list {
  732. temp := []string{}
  733. temp = append(temp, fmt.Sprintf("%v", row["date"]))
  734. if utils.ToInt(row["stock_in_id"]) > 0 {
  735. temp = append(temp, fmt.Sprintf("%s", row["forwarding_unit"]))
  736. } else if utils.ToInt(row["stock_out_id"]) > 0 {
  737. temp = append(temp, fmt.Sprintf("%s", row["receiving_unit"]))
  738. }
  739. temp = append(temp, fmt.Sprintf("%s", row[models.FieldEnterpriseName]))
  740. if row[models.FieldApprovalNumber] != nil {
  741. temp = append(temp, fmt.Sprintf("%s", row[models.FieldApprovalNumber]))
  742. } else {
  743. temp = append(temp, "")
  744. }
  745. if row[models.FieldQualificationNumber] != nil {
  746. temp = append(temp, fmt.Sprintf("%s", row[models.FieldQualificationNumber]))
  747. } else {
  748. temp = append(temp, "")
  749. }
  750. if utils.ToInt(row["stock_in_id"]) > 0 {
  751. temp = append(temp, fmt.Sprintf("%d", row["total_in"]))
  752. temp = append(temp, fmt.Sprintf("%s", row[models.FieldBatchNumber]))
  753. temp = append(temp, fmt.Sprintf("%s", utils.ToDate(row[models.FieldExpiryDate])))
  754. } else {
  755. temp = append(temp, "")
  756. temp = append(temp, "")
  757. temp = append(temp, "")
  758. }
  759. if utils.ToInt(row["stock_out_id"]) > 0 {
  760. temp = append(temp, fmt.Sprintf("%d", row["total_out"]))
  761. temp = append(temp, fmt.Sprintf("%s", row[models.FieldBatchNumber]))
  762. temp = append(temp, fmt.Sprintf("%s", utils.ToDate(row[models.FieldExpiryDate])))
  763. } else {
  764. temp = append(temp, "")
  765. temp = append(temp, "")
  766. temp = append(temp, "")
  767. }
  768. temp = append(temp, fmt.Sprintf("%d", row["balance"]))
  769. temp = append(temp, fmt.Sprintf("%s", row[models.FieldBatchNumber]))
  770. temp = append(temp, fmt.Sprintf("%s", utils.ToDate(row[models.FieldExpiryDate])))
  771. temp = append(temp, fmt.Sprintf("%s", row["operator"]))
  772. rows = append(rows, temp)
  773. }
  774. pdf := &gopdf.GoPdf{}
  775. pdf.Start(gopdf.Config{PageSize: gopdf.Rect{W: 841.89, H: 595.28}})
  776. pdf.SetMarginTop(20)
  777. pdf.SetMarginBottom(40)
  778. pdf.AddPage()
  779. pdf.AddTTFFont("simsun", "static/fonts/MiSans-Medium.ttf")
  780. pdf.SetFont("simsun", "", 22)
  781. titleStr := "收发登记表"
  782. titleWd, _ := pdf.MeasureTextWidth(titleStr)
  783. pdf.SetX((842 / 2) - (titleWd / 2))
  784. pdf.SetY(70)
  785. pdf.Text(titleStr)
  786. pdf.SetFont("simsun", "", 10)
  787. x := 20.
  788. for i := 0; i < 9; i++ {
  789. x += cols1[i]
  790. }
  791. pdf.SetXY(x, 90)
  792. pdf.Text(fmt.Sprintf("制品名称:%s 编号", productName))
  793. pdf.SetXY(x, 110)
  794. pdf.Text(fmt.Sprintf("剂型:%s 规格:%s 单位:%s", dosageFormName, specName, unitName))
  795. curx := 16.
  796. header := []string{"日期", "购货/发货单位", "生产企业", "批准文号", "批签发合格证编号", "收入", "支出", "结余", "经办人签字"}
  797. h := 50.0
  798. pdf.SetFont("simsun", "", 11)
  799. x = curx
  800. y := 116.
  801. pdf.SetXY(curx, y)
  802. for i := 0; i < len(header); i++ {
  803. utils.RectFillColorMultiCell(pdf, header[i], 11, x, y, cols[i], h, 0, 0, 0, gopdf.Center, gopdf.Middle)
  804. if header[i] == "收入" || header[i] == "支出" || header[i] == "结余" {
  805. utils.RectFillColorMultiCell(pdf, header[i], 11, x, y, cols[5]+cols[6]+cols[7], h/2, 0, 0, 0, gopdf.Center, gopdf.Middle)
  806. utils.RectFillColorMultiCell(pdf, "数量", 11, x, y+h/2, cols[5], h/2, 0, 0, 0, gopdf.Center, gopdf.Middle)
  807. utils.RectFillColorMultiCell(pdf, "批号", 11, x+cols[5], y+h/2, cols[6], h/2, 0, 0, 0, gopdf.Center, gopdf.Middle)
  808. utils.RectFillColorMultiCell(pdf, "效期", 11, x+cols[5]+cols[6], y+h/2, cols[7], h/2, 0, 0, 0, gopdf.Center, gopdf.Middle)
  809. x += cols[5] + cols[6] + cols[7]
  810. } else {
  811. x += cols[i]
  812. }
  813. }
  814. pdf.SetFont("simsun", "", 10)
  815. y += h
  816. pdf.SetXY(curx, y)
  817. h = 20.0
  818. for _, row := range rows {
  819. y = pdf.GetY()
  820. x = curx
  821. height := h
  822. for j, txt := range row {
  823. lineTexts, _ := pdf.SplitText(txt, cols1[j])
  824. if len(lineTexts) > 1 {
  825. lineTexts, _ = pdf.SplitText(txt, cols1[j]-4)
  826. lineHt := h * float64(len(lineTexts)) * 0.8
  827. if lineHt > height {
  828. height = lineHt
  829. }
  830. }
  831. }
  832. for i, txt := range row {
  833. width := cols1[i]
  834. utils.RectFillColorMultiCell(pdf, txt, 9, x, y, width, height, 0, 0, 0, gopdf.Center, gopdf.Middle)
  835. x += width
  836. }
  837. pdf.SetNewY(y+height, height)
  838. }
  839. filename := "收发登记表" + time.Now().Format("20060102150405") + ".pdf"
  840. // 保存文件
  841. if err := pdf.WritePdf("ofile/" + filename); err != nil {
  842. fmt.Println(err)
  843. }
  844. defer func() {
  845. os.Remove("ofile/" + filename)
  846. }()
  847. // 返回生成的 Excel 文件
  848. c.Ctx.Output.Download("ofile/" + filename)
  849. }
  850. func (c StockTemplateController) StockTemplateInventoryExport() {
  851. reqData := dto.StockTemplateInventoryExcelReq{}
  852. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  853. err = errors.New("解析表单数据异常")
  854. c.Error(global.ParseFormErr, err, err.Error())
  855. return
  856. }
  857. if reqData.Type == "excel" {
  858. c.StockTemplateInventoryExcel(reqData)
  859. }
  860. if reqData.Type == "pdf" {
  861. c.StockTemplateInventoryPdf(reqData)
  862. }
  863. }
  864. func (c StockTemplateController) TransportRecordWord(reqData models.TransportRecord) {
  865. s := services.StockTemplate{}
  866. deptId := beegouser.GetDeptId(c.Ctx)
  867. list, err := s.StockTemplateTransportRecordWord(&reqData, deptId)
  868. if err != nil {
  869. c.Error(500, err, err.Error())
  870. return
  871. }
  872. doc := document.New()
  873. // 获取文档的默认页面设置
  874. doc.BodySection().SetPageMargins(
  875. 0.3*measurement.Inch,
  876. 0.4*measurement.Inch,
  877. 0.5*measurement.Inch,
  878. 0.3*measurement.Inch,
  879. 1*measurement.Inch,
  880. 0.4*measurement.Inch,
  881. 0.1*measurement.Inch)
  882. ftr := doc.AddFooter()
  883. para := ftr.AddParagraph()
  884. //para.Properties().AddTabStop(0.1*measurement.Inch, wml.ST_TabJcCenter, wml.ST_TabTlcNone)
  885. para.Properties().SetAlignment(wml.ST_JcCenter)
  886. run := para.AddRun()
  887. run.Properties().SetFontFamily("宋体")
  888. run.Properties().SetSize(10)
  889. run.AddTab()
  890. run.AddText("第 ")
  891. run.AddFieldWithFormatting(document.FieldCurrentPage, "", false)
  892. run.AddText(" 页 / 共 ")
  893. run.AddFieldWithFormatting(document.FieldNumberOfPages, "", false)
  894. run.AddText(" 页")
  895. //doc.BodySection().SetFooter(ftr, wml.ST_HdrFtrDefault)
  896. para = doc.AddParagraph()
  897. para.Properties().SetAlignment(wml.ST_JcCenter)
  898. run = para.AddRun()
  899. run.Properties().SetBold(true)
  900. run.Properties().SetFontFamily("宋体")
  901. run.Properties().SetSize(14)
  902. para.Properties().Spacing().SetLineSpacing(18*measurement.Point, wml.ST_LineSpacingRuleAuto)
  903. run.AddText("表3-4 运输记录表")
  904. para = doc.AddParagraph()
  905. run = para.AddRun()
  906. run.Properties().SetFontFamily("宋体")
  907. run.Properties().SetSize(12)
  908. para.Properties().SetAlignment(wml.ST_JcCenter)
  909. para.Properties().Spacing().SetLineSpacing(30*measurement.Point, wml.ST_LineSpacingRuleAuto)
  910. run.AddText("(各级通用)")
  911. para = doc.AddParagraph()
  912. run = para.AddRun()
  913. run.Properties().SetFontFamily("宋体")
  914. run.Properties().SetSize(10)
  915. para.Properties().SetAlignment(wml.ST_JcLeft)
  916. para.Properties().Spacing().SetLineSpacing(20*measurement.Point, wml.ST_LineSpacingRuleAuto)
  917. run.AddText("运输工具: □冷藏车 □运输车 □普通车辆 □无 □其他")
  918. run = para.AddRun()
  919. run.AddText(" ")
  920. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  921. para = doc.AddParagraph()
  922. run = para.AddRun()
  923. run.Properties().SetFontFamily("宋体")
  924. run.Properties().SetSize(10)
  925. para.Properties().SetAlignment(wml.ST_JcLeft)
  926. para.Properties().Spacing().SetLineSpacing(20*measurement.Point, wml.ST_LineSpacingRuleAuto)
  927. run.AddText("冷藏工具: □冷藏车 □车载冷藏箱 □冷藏箱或冷藏包 □其他")
  928. run = para.AddRun()
  929. run.AddText(" ")
  930. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  931. para = doc.AddParagraph()
  932. run = para.AddRun()
  933. run.Properties().SetFontFamily("宋体")
  934. run.Properties().SetSize(10)
  935. para.Properties().SetAlignment(wml.ST_JcLeft)
  936. para.Properties().Spacing().SetLineSpacing(20*measurement.Point, wml.ST_LineSpacingRuleAuto)
  937. run.AddText("配送方式: □本级配送(车牌号:")
  938. run = para.AddRun()
  939. run.AddText(" ")
  940. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  941. run = para.AddRun()
  942. run.Properties().SetFontFamily("宋体")
  943. run.Properties().SetSize(10)
  944. run.AddText(") □下级自运(车牌号:")
  945. run = para.AddRun()
  946. run.AddText(" ")
  947. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  948. run = para.AddRun()
  949. run.Properties().SetFontFamily("宋体")
  950. run.Properties().SetSize(10)
  951. run.AddText(")")
  952. // --------------------运输情况
  953. para = doc.AddParagraph()
  954. para.Properties().SetAlignment(wml.ST_JcLeft)
  955. run = para.AddRun()
  956. run.Properties().SetBold(true)
  957. run.Properties().SetFontFamily("宋体")
  958. run.Properties().SetSize(10)
  959. run.AddText("运输情况:")
  960. table := doc.AddTable()
  961. table.Properties().SetLayout(wml.ST_TblLayoutTypeFixed)
  962. table.Properties().SetWidthPercent(100)
  963. look := table.Properties().TableLook()
  964. look.SetFirstColumn(true)
  965. look.SetFirstRow(true)
  966. look.SetHorizontalBanding(true)
  967. // width of the page
  968. // with thick borers
  969. borders := table.Properties().Borders()
  970. //borders.SetBottom(wml.ST_BorderSingle, color.Auto, 1*measurement.Point)
  971. //borders.SetLeft(wml.ST_BorderSingle, color.Auto, 1*measurement.Point)
  972. //borders.SetRight(wml.ST_BorderSingle, color.Auto, 1*measurement.Point)
  973. //borders.SetTop(wml.ST_BorderSingle, color.Auto, 1*measurement.Point)
  974. borders.SetAll(wml.ST_BorderSingle, color.Auto, measurement.Zero)
  975. //borders.SetInsideVertical(wml.ST_BorderSingle, color.Auto, measurement.Zero)
  976. row := table.AddRow()
  977. row.Properties().SetHeight(0.35*measurement.Inch, wml.ST_HeightRuleExact)
  978. cell := row.AddCell()
  979. cell.Properties().SetWidthPercent(15)
  980. para = cell.AddParagraph()
  981. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  982. para.Properties().SetAlignment(wml.ST_JcCenter)
  983. run = para.AddRun()
  984. run.Properties().SetFontFamily("宋体")
  985. run.Properties().SetSize(9)
  986. run.AddText("品名")
  987. cell = row.AddCell()
  988. cell.Properties().SetWidthPercent(12)
  989. para = cell.AddParagraph()
  990. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  991. para.Properties().SetAlignment(wml.ST_JcCenter)
  992. run = para.AddRun()
  993. run.Properties().SetFontFamily("宋体")
  994. run.Properties().SetSize(9)
  995. run.AddText("生产企业")
  996. cell = row.AddCell()
  997. cell.Properties().SetWidthPercent(10)
  998. para = cell.AddParagraph()
  999. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1000. para.Properties().SetAlignment(wml.ST_JcCenter)
  1001. run = para.AddRun()
  1002. run.Properties().SetFontFamily("宋体")
  1003. run.Properties().SetSize(9)
  1004. run.AddText("批准文号")
  1005. cell = row.AddCell()
  1006. cell.Properties().SetWidthPercent(15)
  1007. para = cell.AddParagraph()
  1008. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1009. para.Properties().SetAlignment(wml.ST_JcCenter)
  1010. run = para.AddRun()
  1011. run.Properties().SetFontFamily("宋体")
  1012. run.Properties().SetSize(9)
  1013. run.AddText("批签发合格编号")
  1014. cell = row.AddCell()
  1015. cell.Properties().SetWidthPercent(13)
  1016. para = cell.AddParagraph()
  1017. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1018. para.Properties().SetAlignment(wml.ST_JcCenter)
  1019. run = para.AddRun()
  1020. run.Properties().SetFontFamily("宋体")
  1021. run.Properties().SetSize(9)
  1022. run.AddText("规格(剂/支或粒)")
  1023. //cell = row.AddCell()
  1024. //cell.Properties().SetWidth(0.5 * measurement.Inch)
  1025. //para = cell.AddParagraph()
  1026. //cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1027. //para.Properties().SetAlignment(wml.ST_JcCenter)
  1028. //run = para.AddRun()
  1029. //run.Properties().SetFontFamily("宋体")
  1030. //run.Properties().SetSize(8)
  1031. //run.AddText("生产日期")
  1032. cell = row.AddCell()
  1033. cell.Properties().SetWidthPercent(12)
  1034. para = cell.AddParagraph()
  1035. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1036. para.Properties().SetAlignment(wml.ST_JcCenter)
  1037. run = para.AddRun()
  1038. run.Properties().SetFontFamily("宋体")
  1039. run.Properties().SetSize(9)
  1040. run.AddText("批号")
  1041. cell = row.AddCell()
  1042. cell.Properties().SetWidthPercent(10)
  1043. para = cell.AddParagraph()
  1044. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1045. para.Properties().SetAlignment(wml.ST_JcCenter)
  1046. run = para.AddRun()
  1047. run.Properties().SetFontFamily("宋体")
  1048. run.Properties().SetSize(9)
  1049. run.AddText("失效日期")
  1050. cell = row.AddCell()
  1051. cell.Properties().SetWidthPercent(6)
  1052. para = cell.AddParagraph()
  1053. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1054. para.Properties().SetAlignment(wml.ST_JcCenter)
  1055. run = para.AddRun()
  1056. run.Properties().SetFontFamily("宋体")
  1057. run.Properties().SetSize(9)
  1058. run.AddText("数量")
  1059. cell = row.AddCell()
  1060. cell.Properties().SetWidthPercent(6)
  1061. para = cell.AddParagraph()
  1062. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1063. para.Properties().SetAlignment(wml.ST_JcCenter)
  1064. run = para.AddRun()
  1065. run.Properties().SetFontFamily("宋体")
  1066. run.Properties().SetSize(9)
  1067. run.AddText("单位")
  1068. models.InitBasicData(deptId)
  1069. for _, medicineInfo := range list {
  1070. row = table.AddRow()
  1071. row.Properties().SetHeight(0.3*measurement.Inch, wml.ST_HeightRuleAtLeast)
  1072. cell = row.AddCell()
  1073. cell.Properties().SetWidthPercent(15)
  1074. para = cell.AddParagraph()
  1075. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1076. para.Properties().SetAlignment(wml.ST_JcCenter)
  1077. run = para.AddRun()
  1078. run.Properties().SetFontFamily("宋体")
  1079. run.Properties().SetSize(8)
  1080. productName := models.Read_Product_Get(utils.ToInt(medicineInfo[models.FieldProductID]))
  1081. run.AddText(productName)
  1082. cell = row.AddCell()
  1083. cell.Properties().SetWidthPercent(12)
  1084. para = cell.AddParagraph()
  1085. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1086. para.Properties().SetAlignment(wml.ST_JcCenter)
  1087. run = para.AddRun()
  1088. run.Properties().SetFontFamily("宋体")
  1089. run.Properties().SetSize(8)
  1090. enterpriseName := models.Read_Enterprise_Get(utils.ToInt(medicineInfo[models.FieldEnterpriseID]))
  1091. run.AddText(enterpriseName)
  1092. cell = row.AddCell()
  1093. cell.Properties().SetWidthPercent(10)
  1094. para = cell.AddParagraph()
  1095. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1096. para.Properties().SetAlignment(wml.ST_JcCenter)
  1097. run = para.AddRun()
  1098. run.Properties().SetFontFamily("宋体")
  1099. run.Properties().SetSize(8)
  1100. run.AddText(medicineInfo[models.FieldApprovalNumber].(string))
  1101. cell = row.AddCell()
  1102. cell.Properties().SetWidthPercent(15)
  1103. para = cell.AddParagraph()
  1104. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1105. para.Properties().SetAlignment(wml.ST_JcCenter)
  1106. run = para.AddRun()
  1107. run.Properties().SetFontFamily("宋体")
  1108. run.Properties().SetSize(8)
  1109. if medicineInfo[models.FieldQualificationNumber] != nil {
  1110. run.AddText(medicineInfo[models.FieldQualificationNumber].(string))
  1111. }
  1112. cell = row.AddCell()
  1113. cell.Properties().SetWidthPercent(13)
  1114. para = cell.AddParagraph()
  1115. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1116. para.Properties().SetAlignment(wml.ST_JcCenter)
  1117. run = para.AddRun()
  1118. run.Properties().SetFontFamily("宋体")
  1119. run.Properties().SetSize(8)
  1120. specName := models.Read_Spec_Get(utils.ToInt(medicineInfo[models.FieldSpecID]))
  1121. run.AddText(specName)
  1122. //cell = row.AddCell()
  1123. //cell.Properties().SetWidth(0.5 * measurement.Inch)
  1124. //para = cell.AddParagraph()
  1125. //cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1126. //para.Properties().SetAlignment(wml.ST_JcCenter)
  1127. //run = para.AddRun()
  1128. //run.Properties().SetFontFamily("宋体")
  1129. //run.Properties().SetSize(8)
  1130. //run.AddText("生产日期")
  1131. cell = row.AddCell()
  1132. cell.Properties().SetWidthPercent(12)
  1133. para = cell.AddParagraph()
  1134. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1135. para.Properties().SetAlignment(wml.ST_JcCenter)
  1136. run = para.AddRun()
  1137. run.Properties().SetFontFamily("宋体")
  1138. run.Properties().SetSize(8)
  1139. run.AddText(medicineInfo[models.FieldBatchNumber].(string))
  1140. cell = row.AddCell()
  1141. cell.Properties().SetWidthPercent(10)
  1142. para = cell.AddParagraph()
  1143. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1144. para.Properties().SetAlignment(wml.ST_JcCenter)
  1145. run = para.AddRun()
  1146. run.Properties().SetFontFamily("宋体")
  1147. run.Properties().SetSize(8)
  1148. run.AddText(utils.ToDate(medicineInfo[models.FieldExpiryDate]))
  1149. cell = row.AddCell()
  1150. cell.Properties().SetWidthPercent(6)
  1151. para = cell.AddParagraph()
  1152. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1153. para.Properties().SetAlignment(wml.ST_JcCenter)
  1154. run = para.AddRun()
  1155. run.Properties().SetFontFamily("宋体")
  1156. run.Properties().SetSize(8)
  1157. run.AddText(fmt.Sprintf("%d", utils.ToInt(medicineInfo["quantity"])))
  1158. cell = row.AddCell()
  1159. cell.Properties().SetWidthPercent(6)
  1160. para = cell.AddParagraph()
  1161. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1162. para.Properties().SetAlignment(wml.ST_JcCenter)
  1163. run = para.AddRun()
  1164. run.Properties().SetFontFamily("宋体")
  1165. run.Properties().SetSize(8)
  1166. unitName := models.Read_Unit_Get(utils.ToInt(medicineInfo[models.FieldUnitID]))
  1167. run.AddText(unitName)
  1168. }
  1169. if len(list) < 11 {
  1170. for i := 0; i < 11-len(list); i++ {
  1171. row = table.AddRow()
  1172. row.Properties().SetHeight(0.3*measurement.Inch, wml.ST_HeightRuleAtLeast)
  1173. cell = row.AddCell()
  1174. cell.Properties().SetWidthPercent(15)
  1175. cell = row.AddCell()
  1176. cell.Properties().SetWidthPercent(12)
  1177. cell = row.AddCell()
  1178. cell.Properties().SetWidthPercent(10)
  1179. cell = row.AddCell()
  1180. cell.Properties().SetWidthPercent(15)
  1181. cell = row.AddCell()
  1182. cell.Properties().SetWidthPercent(13)
  1183. //cell = row.AddCell()
  1184. //cell.Properties().SetWidth(0.5 * measurement.Inch)
  1185. //para = cell.AddParagraph()
  1186. //cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1187. //para.Properties().SetAlignment(wml.ST_JcCenter)
  1188. //run = para.AddRun()
  1189. //run.Properties().SetFontFamily("宋体")
  1190. //run.Properties().SetSize(8)
  1191. //run.AddText("生产日期")
  1192. cell = row.AddCell()
  1193. cell.Properties().SetWidthPercent(12)
  1194. cell = row.AddCell()
  1195. cell.Properties().SetWidthPercent(10)
  1196. cell = row.AddCell()
  1197. cell.Properties().SetWidthPercent(6)
  1198. cell = row.AddCell()
  1199. cell.Properties().SetWidthPercent(6)
  1200. }
  1201. }
  1202. // --------------------运输温度记录
  1203. para = doc.AddParagraph()
  1204. para.Properties().Spacing().SetLineSpacing(25*measurement.Point, wml.ST_LineSpacingRuleAtLeast)
  1205. para.Properties().SetAlignment(wml.ST_JcLeft)
  1206. run = para.AddRun()
  1207. run.Properties().SetBold(true)
  1208. run.Properties().SetFontFamily("宋体")
  1209. run.Properties().SetSize(10)
  1210. run.AddText("运输温度记录:")
  1211. table = doc.InsertTableAfter(para)
  1212. table.Properties().SetWidthPercent(100)
  1213. table.Properties().SetAlignment(wml.ST_JcTableCenter)
  1214. table.Properties().SetLayout(wml.ST_TblLayoutTypeAutofit)
  1215. look = table.Properties().TableLook()
  1216. look.SetFirstColumn(true)
  1217. look.SetFirstRow(true)
  1218. look.SetHorizontalBanding(true)
  1219. borders = table.Properties().Borders()
  1220. borders.SetBottom(wml.ST_BorderSingle, color.Auto, 1*measurement.Point)
  1221. borders.SetLeft(wml.ST_BorderSingle, color.Auto, 1*measurement.Point)
  1222. borders.SetRight(wml.ST_BorderSingle, color.Auto, 1*measurement.Point)
  1223. borders.SetTop(wml.ST_BorderSingle, color.Auto, 1*measurement.Point)
  1224. borders.SetInsideHorizontal(wml.ST_BorderSingle, color.Auto, measurement.Zero)
  1225. borders.SetInsideVertical(wml.ST_BorderSingle, color.Auto, measurement.Zero)
  1226. //-----------------项目名称
  1227. row = table.AddRow()
  1228. cell = row.AddCell()
  1229. cell.Properties().SetWidthPercent(10)
  1230. para = cell.AddParagraph()
  1231. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1232. para.Properties().SetAlignment(wml.ST_JcCenter)
  1233. run = para.AddRun()
  1234. run.Properties().SetFontFamily("宋体")
  1235. run.AddText("")
  1236. cell = row.AddCell()
  1237. cell.Properties().SetWidthPercent(38)
  1238. para = cell.AddParagraph()
  1239. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1240. para.Properties().SetAlignment(wml.ST_JcCenter)
  1241. run = para.AddRun()
  1242. run.Properties().SetFontFamily("宋体")
  1243. run.Properties().SetSize(10)
  1244. run.AddText("日期/时间")
  1245. cell = row.AddCell()
  1246. cell.Properties().SetWidthPercent(19)
  1247. para = cell.AddParagraph()
  1248. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1249. para.Properties().SetAlignment(wml.ST_JcCenter)
  1250. run = para.AddRun()
  1251. run.Properties().SetFontFamily("宋体")
  1252. run.Properties().SetSize(8)
  1253. run.AddText("储存温度")
  1254. cell = row.AddCell()
  1255. cell.Properties().SetWidthPercent(17)
  1256. para = cell.AddParagraph()
  1257. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1258. para.Properties().SetAlignment(wml.ST_JcCenter)
  1259. run = para.AddRun()
  1260. run.Properties().SetFontFamily("宋体")
  1261. run.Properties().SetSize(10)
  1262. run.AddText("冰排状态")
  1263. cell = row.AddCell()
  1264. cell.Properties().SetWidthPercent(16)
  1265. para = cell.AddParagraph()
  1266. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1267. para.Properties().SetAlignment(wml.ST_JcCenter)
  1268. run = para.AddRun()
  1269. run.Properties().SetFontFamily("宋体")
  1270. run.Properties().SetSize(10)
  1271. run.AddText("环境温度")
  1272. //------------------启运
  1273. row = table.AddRow()
  1274. row.Properties().SetHeight(0.4*measurement.Inch, wml.ST_HeightRuleAtLeast)
  1275. cell = row.AddCell()
  1276. cell.Properties().SetWidthPercent(10)
  1277. para = cell.AddParagraph()
  1278. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1279. para.Properties().SetAlignment(wml.ST_JcCenter)
  1280. run = para.AddRun()
  1281. run.Properties().SetFontFamily("宋体")
  1282. run.Properties().SetSize(10)
  1283. run.AddText("启运")
  1284. cell = row.AddCell()
  1285. cell.Properties().SetWidthPercent(38)
  1286. para = cell.AddParagraph()
  1287. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1288. para.Properties().SetAlignment(wml.ST_JcCenter)
  1289. run = para.AddRun()
  1290. run.Properties().SetFontFamily("宋体")
  1291. run.Properties().SetSize(10)
  1292. run = para.AddRun()
  1293. run.AddText(" ")
  1294. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  1295. run = para.AddRun()
  1296. run.Properties().SetFontFamily("宋体")
  1297. run.Properties().SetSize(10)
  1298. run.AddText("年")
  1299. run = para.AddRun()
  1300. run.Properties().SetFontFamily("宋体")
  1301. run.Properties().SetSize(10)
  1302. run = para.AddRun()
  1303. run.AddText(" ")
  1304. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  1305. run = para.AddRun()
  1306. run.Properties().SetFontFamily("宋体")
  1307. run.Properties().SetSize(10)
  1308. run.AddText("月")
  1309. run = para.AddRun()
  1310. run.AddText(" ")
  1311. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  1312. run = para.AddRun()
  1313. run.Properties().SetFontFamily("宋体")
  1314. run.Properties().SetSize(10)
  1315. run = para.AddRun()
  1316. run.Properties().SetFontFamily("宋体")
  1317. run.Properties().SetSize(10)
  1318. run.AddText("日")
  1319. run = para.AddRun()
  1320. run.AddText(" ")
  1321. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  1322. run = para.AddRun()
  1323. run.Properties().SetFontFamily("宋体")
  1324. run.Properties().SetSize(10)
  1325. run.AddText("时")
  1326. run = para.AddRun()
  1327. run.AddText(" ")
  1328. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  1329. run = para.AddRun()
  1330. run.Properties().SetFontFamily("宋体")
  1331. run.Properties().SetSize(10)
  1332. run.AddText("分")
  1333. cell = row.AddCell()
  1334. cell.Properties().SetWidthPercent(19)
  1335. para = cell.AddParagraph()
  1336. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1337. para.Properties().SetAlignment(wml.ST_JcCenter)
  1338. run = para.AddRun()
  1339. run.Properties().SetFontFamily("宋体")
  1340. run.Properties().SetSize(10)
  1341. run.AddText(" ")
  1342. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  1343. run = para.AddRun()
  1344. run.Properties().SetFontFamily("宋体")
  1345. run.Properties().SetSize(10)
  1346. run.AddText("℃")
  1347. cell = row.AddCell()
  1348. cell.Properties().SetWidthPercent(17)
  1349. para = cell.AddParagraph()
  1350. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1351. para.Properties().SetAlignment(wml.ST_JcCenter)
  1352. run.AddText("")
  1353. cell = row.AddCell()
  1354. cell.Properties().SetWidthPercent(16)
  1355. para = cell.AddParagraph()
  1356. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1357. para.Properties().SetAlignment(wml.ST_JcCenter)
  1358. run = para.AddRun()
  1359. run.Properties().SetFontFamily("宋体")
  1360. run.Properties().SetSize(10)
  1361. run.AddText(" ")
  1362. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  1363. run = para.AddRun()
  1364. run.Properties().SetFontFamily("宋体")
  1365. run.Properties().SetSize(10)
  1366. run.AddText("℃")
  1367. //------------------途中
  1368. row = table.AddRow()
  1369. row.Properties().SetHeight(0.8*measurement.Inch, wml.ST_HeightRuleAtLeast)
  1370. cell = row.AddCell()
  1371. cell.Properties().SetWidthPercent(10)
  1372. para = cell.AddParagraph()
  1373. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1374. para.Properties().SetAlignment(wml.ST_JcCenter)
  1375. run = para.AddRun()
  1376. run.Properties().SetFontFamily("宋体")
  1377. run.Properties().SetSize(10)
  1378. run.AddText("途中")
  1379. cell = row.AddCell()
  1380. cell.Properties().SetWidthPercent(38)
  1381. para = cell.AddParagraph()
  1382. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1383. para.Properties().SetAlignment(wml.ST_JcCenter)
  1384. para.Properties().Spacing().SetLineSpacing(20*measurement.Point, wml.ST_LineSpacingRuleAuto)
  1385. run = para.AddRun()
  1386. run.Properties().SetFontFamily("宋体")
  1387. run.Properties().SetSize(10)
  1388. run = para.AddRun()
  1389. run.AddText(" ")
  1390. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  1391. run = para.AddRun()
  1392. run.Properties().SetFontFamily("宋体")
  1393. run.Properties().SetSize(10)
  1394. run.AddText("年")
  1395. run = para.AddRun()
  1396. run.Properties().SetFontFamily("宋体")
  1397. run.Properties().SetSize(10)
  1398. run = para.AddRun()
  1399. run.AddText(" ")
  1400. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  1401. run = para.AddRun()
  1402. run.Properties().SetFontFamily("宋体")
  1403. run.Properties().SetSize(10)
  1404. run.AddText("月")
  1405. run = para.AddRun()
  1406. run.AddText(" ")
  1407. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  1408. run = para.AddRun()
  1409. run.Properties().SetFontFamily("宋体")
  1410. run.Properties().SetSize(10)
  1411. run = para.AddRun()
  1412. run.Properties().SetFontFamily("宋体")
  1413. run.Properties().SetSize(10)
  1414. run.AddText("日")
  1415. run = para.AddRun()
  1416. run.AddText(" ")
  1417. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  1418. run = para.AddRun()
  1419. run.Properties().SetFontFamily("宋体")
  1420. run.Properties().SetSize(10)
  1421. run.AddText("时")
  1422. run = para.AddRun()
  1423. run.AddText(" ")
  1424. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  1425. run = para.AddRun()
  1426. run.Properties().SetFontFamily("宋体")
  1427. run.Properties().SetSize(10)
  1428. run.AddText("分")
  1429. para = cell.AddParagraph()
  1430. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1431. para.Properties().SetAlignment(wml.ST_JcCenter)
  1432. run = para.AddRun()
  1433. run.Properties().SetFontFamily("宋体")
  1434. run.Properties().SetSize(10)
  1435. run = para.AddRun()
  1436. run.AddText(" ")
  1437. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  1438. run = para.AddRun()
  1439. run.Properties().SetFontFamily("宋体")
  1440. run.Properties().SetSize(10)
  1441. run.AddText("年")
  1442. run = para.AddRun()
  1443. run.Properties().SetFontFamily("宋体")
  1444. run.Properties().SetSize(10)
  1445. run = para.AddRun()
  1446. run.AddText(" ")
  1447. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  1448. run = para.AddRun()
  1449. run.Properties().SetFontFamily("宋体")
  1450. run.Properties().SetSize(10)
  1451. run.AddText("月")
  1452. run = para.AddRun()
  1453. run.AddText(" ")
  1454. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  1455. run = para.AddRun()
  1456. run.Properties().SetFontFamily("宋体")
  1457. run.Properties().SetSize(10)
  1458. run = para.AddRun()
  1459. run.Properties().SetFontFamily("宋体")
  1460. run.Properties().SetSize(10)
  1461. run.AddText("日")
  1462. run = para.AddRun()
  1463. run.AddText(" ")
  1464. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  1465. run = para.AddRun()
  1466. run.Properties().SetFontFamily("宋体")
  1467. run.Properties().SetSize(10)
  1468. run.AddText("时")
  1469. run = para.AddRun()
  1470. run.AddText(" ")
  1471. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  1472. run = para.AddRun()
  1473. run.Properties().SetFontFamily("宋体")
  1474. run.Properties().SetSize(10)
  1475. run.AddText("分")
  1476. cell = row.AddCell()
  1477. cell.Properties().SetWidthPercent(19)
  1478. para = cell.AddParagraph()
  1479. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1480. para.Properties().SetAlignment(wml.ST_JcCenter)
  1481. para.Properties().Spacing().SetLineSpacing(20*measurement.Point, wml.ST_LineSpacingRuleAuto)
  1482. run = para.AddRun()
  1483. run.Properties().SetFontFamily("宋体")
  1484. run.Properties().SetSize(10)
  1485. run.AddText(" ")
  1486. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  1487. run = para.AddRun()
  1488. run.Properties().SetFontFamily("宋体")
  1489. run.Properties().SetSize(10)
  1490. run.AddText("℃")
  1491. para = cell.AddParagraph()
  1492. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1493. para.Properties().SetAlignment(wml.ST_JcCenter)
  1494. run = para.AddRun()
  1495. run.Properties().SetFontFamily("宋体")
  1496. run.Properties().SetSize(10)
  1497. run.AddText(" ")
  1498. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  1499. run = para.AddRun()
  1500. run.Properties().SetFontFamily("宋体")
  1501. run.Properties().SetSize(10)
  1502. run.AddText("℃")
  1503. cell = row.AddCell()
  1504. cell.Properties().SetWidthPercent(17)
  1505. para = cell.AddParagraph()
  1506. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1507. para.Properties().SetAlignment(wml.ST_JcCenter)
  1508. run = para.AddRun()
  1509. run.Properties().SetSize(5)
  1510. run.AddText("————————")
  1511. cell = row.AddCell()
  1512. cell.Properties().SetWidthPercent(16)
  1513. para = cell.AddParagraph()
  1514. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1515. para.Properties().SetAlignment(wml.ST_JcCenter)
  1516. para.Properties().Spacing().SetLineSpacing(20*measurement.Point, wml.ST_LineSpacingRuleAuto)
  1517. run = para.AddRun()
  1518. run.Properties().SetFontFamily("宋体")
  1519. run.Properties().SetSize(10)
  1520. run.AddText(" ")
  1521. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  1522. run = para.AddRun()
  1523. run.Properties().SetFontFamily("宋体")
  1524. run.Properties().SetSize(10)
  1525. run.AddText("℃")
  1526. para = cell.AddParagraph()
  1527. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1528. para.Properties().SetAlignment(wml.ST_JcCenter)
  1529. run = para.AddRun()
  1530. run.Properties().SetFontFamily("宋体")
  1531. run.Properties().SetSize(10)
  1532. run.AddText(" ")
  1533. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  1534. run = para.AddRun()
  1535. run.Properties().SetFontFamily("宋体")
  1536. run.Properties().SetSize(10)
  1537. run.AddText("℃")
  1538. //------------------到达
  1539. row = table.AddRow()
  1540. row.Properties().SetHeight(0.4*measurement.Inch, wml.ST_HeightRuleAtLeast)
  1541. cell = row.AddCell()
  1542. cell.Properties().SetWidthPercent(10)
  1543. para = cell.AddParagraph()
  1544. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1545. para.Properties().SetAlignment(wml.ST_JcCenter)
  1546. run = para.AddRun()
  1547. run.Properties().SetFontFamily("宋体")
  1548. run.Properties().SetSize(10)
  1549. run.AddText("到达")
  1550. cell = row.AddCell()
  1551. cell.Properties().SetWidthPercent(38)
  1552. para = cell.AddParagraph()
  1553. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1554. para.Properties().SetAlignment(wml.ST_JcCenter)
  1555. run = para.AddRun()
  1556. run.Properties().SetFontFamily("宋体")
  1557. run.Properties().SetSize(10)
  1558. run = para.AddRun()
  1559. run.AddText(" ")
  1560. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  1561. run = para.AddRun()
  1562. run.Properties().SetFontFamily("宋体")
  1563. run.Properties().SetSize(10)
  1564. run.AddText("年")
  1565. run = para.AddRun()
  1566. run.Properties().SetFontFamily("宋体")
  1567. run.Properties().SetSize(10)
  1568. run = para.AddRun()
  1569. run.AddText(" ")
  1570. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  1571. run = para.AddRun()
  1572. run.Properties().SetFontFamily("宋体")
  1573. run.Properties().SetSize(10)
  1574. run.AddText("月")
  1575. run = para.AddRun()
  1576. run.AddText(" ")
  1577. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  1578. run = para.AddRun()
  1579. run.Properties().SetFontFamily("宋体")
  1580. run.Properties().SetSize(10)
  1581. run = para.AddRun()
  1582. run.Properties().SetFontFamily("宋体")
  1583. run.Properties().SetSize(10)
  1584. run.AddText("日")
  1585. run = para.AddRun()
  1586. run.AddText(" ")
  1587. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  1588. run = para.AddRun()
  1589. run.Properties().SetFontFamily("宋体")
  1590. run.Properties().SetSize(10)
  1591. run.AddText("时")
  1592. run = para.AddRun()
  1593. run.AddText(" ")
  1594. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  1595. run = para.AddRun()
  1596. run.Properties().SetFontFamily("宋体")
  1597. run.Properties().SetSize(10)
  1598. run.AddText("分")
  1599. cell = row.AddCell()
  1600. cell.Properties().SetWidthPercent(19)
  1601. para = cell.AddParagraph()
  1602. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1603. para.Properties().SetAlignment(wml.ST_JcCenter)
  1604. run = para.AddRun()
  1605. run.Properties().SetFontFamily("宋体")
  1606. run.Properties().SetSize(10)
  1607. run.AddText(" ")
  1608. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  1609. run = para.AddRun()
  1610. run.Properties().SetFontFamily("宋体")
  1611. run.Properties().SetSize(10)
  1612. run.AddText("℃")
  1613. cell = row.AddCell()
  1614. cell.Properties().SetWidthPercent(17)
  1615. para = cell.AddParagraph()
  1616. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1617. para.Properties().SetAlignment(wml.ST_JcCenter)
  1618. run.AddText("")
  1619. cell = row.AddCell()
  1620. cell.Properties().SetWidthPercent(16)
  1621. para = cell.AddParagraph()
  1622. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1623. para.Properties().SetAlignment(wml.ST_JcCenter)
  1624. run = para.AddRun()
  1625. run.Properties().SetFontFamily("宋体")
  1626. run.Properties().SetSize(10)
  1627. run.AddText(" ")
  1628. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  1629. run = para.AddRun()
  1630. run.Properties().SetFontFamily("宋体")
  1631. run.Properties().SetSize(10)
  1632. run.AddText("℃")
  1633. para = doc.AddParagraph()
  1634. para.Properties().Spacing().SetLineSpacing(25*measurement.Point, wml.ST_LineSpacingRuleExact)
  1635. para.Properties().SetAlignment(wml.ST_JcLeft)
  1636. run = para.AddRun()
  1637. run.Properties().SetFontFamily("宋体")
  1638. run.Properties().SetSize(10)
  1639. run.AddText("启运至到达行驶里程数:")
  1640. run = para.AddRun()
  1641. run.Properties().SetFontFamily("宋体")
  1642. run.Properties().SetSize(10)
  1643. run.AddText(" ")
  1644. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  1645. run = para.AddRun()
  1646. run.Properties().SetFontFamily("宋体")
  1647. run.Properties().SetSize(10)
  1648. run.AddText("千米。")
  1649. table3 := doc.AddTable()
  1650. table3.Properties().SetLayout(wml.ST_TblLayoutTypeFixed)
  1651. table3.Properties().SetWidthPercent(100)
  1652. look.SetFirstColumn(true)
  1653. look.SetFirstRow(true)
  1654. look.SetHorizontalBanding(true)
  1655. look = table3.Properties().TableLook()
  1656. borders3 := table3.Properties().Borders()
  1657. borders3.SetAll(wml.ST_BorderUnset, color.Auto, measurement.Zero)
  1658. row = table3.AddRow()
  1659. row.Properties().SetHeight(0.36*measurement.Inch, wml.ST_HeightRuleExact)
  1660. cell = row.AddCell()
  1661. cell.Properties().SetWidthPercent(50)
  1662. para = cell.AddParagraph()
  1663. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1664. para.Properties().SetAlignment(wml.ST_JcLeft)
  1665. run = para.AddRun()
  1666. run.Properties().SetFontFamily("宋体")
  1667. run.Properties().SetSize(10)
  1668. run.AddText("发货单位:")
  1669. run = para.AddRun()
  1670. run.Properties().SetFontFamily("宋体")
  1671. run.Properties().SetSize(10)
  1672. run.AddText(beegouser.GetDeptName(c.Ctx))
  1673. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  1674. cell = row.AddCell()
  1675. cell.Properties().SetWidthPercent(50)
  1676. para = cell.AddParagraph()
  1677. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1678. para.Properties().SetAlignment(wml.ST_JcLeft)
  1679. run = para.AddRun()
  1680. run.Properties().SetFontFamily("宋体")
  1681. run.Properties().SetSize(10)
  1682. run.AddText("发货人签名:")
  1683. run = para.AddRun()
  1684. run.Properties().SetSize(5)
  1685. run.AddText("________________________________________________________________")
  1686. row = table3.AddRow()
  1687. row.Properties().SetHeight(0.36*measurement.Inch, wml.ST_HeightRuleExact)
  1688. cell = row.AddCell()
  1689. cell.Properties().SetWidthPercent(50)
  1690. para = cell.AddParagraph()
  1691. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1692. para.Properties().SetAlignment(wml.ST_JcLeft)
  1693. run = para.AddRun()
  1694. run.Properties().SetFontFamily("宋体")
  1695. run.Properties().SetSize(10)
  1696. run.AddText("收货单位:")
  1697. run = para.AddRun()
  1698. run.Properties().SetFontFamily("宋体")
  1699. run.Properties().SetSize(10)
  1700. run.AddText(reqData.ReceivingUnit)
  1701. run.Properties().SetUnderline(wml.ST_UnderlineSingle, color.Black)
  1702. cell = row.AddCell()
  1703. cell.Properties().SetWidthPercent(50)
  1704. para = cell.AddParagraph()
  1705. cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
  1706. para.Properties().SetAlignment(wml.ST_JcLeft)
  1707. run = para.AddRun()
  1708. run.Properties().SetFontFamily("宋体")
  1709. run.Properties().SetSize(10)
  1710. run.AddText("收货人签名:")
  1711. run = para.AddRun()
  1712. run.Properties().SetSize(5)
  1713. run.AddText("________________________________________________________________")
  1714. para = doc.AddParagraph()
  1715. para.Properties().SetAlignment(wml.ST_JcLeft)
  1716. run = para.AddRun()
  1717. run.Properties().SetFontFamily("宋体")
  1718. run.Properties().SetSize(10)
  1719. run.AddText("填表说明:本表供冷链配送企业、疾病预防控制机构、接种单位冷链运输时填写;出入库单号为单位编码+年月日+2位流水号;运输超过6小时需记录途中温度,间隔不超过6小时;使用无自动温度显示的冰排保冷设备时,只在启运和达到时填写冰排状态(冻结、冰水混合物、完全融化)。")
  1720. doc.BodySection().SetFooter(ftr, wml.ST_HdrFtrDefault)
  1721. filename := "运输记录表" + time.Now().Format("20060102150405") + ".docx"
  1722. // 保存文件
  1723. if err := doc.SaveToFile("ofile/" + filename); err != nil {
  1724. fmt.Println(err)
  1725. }
  1726. // 保存为PDF文件
  1727. defer func() {
  1728. os.Remove("ofile/" + filename)
  1729. }()
  1730. // 返回生成的 Excel 文件
  1731. c.Ctx.Output.Download("ofile/" + filename)
  1732. }
  1733. func getImageBytes(filePath string) []byte {
  1734. b, err := os.ReadFile(filePath)
  1735. if err != nil {
  1736. panic(err)
  1737. }
  1738. return b
  1739. }
  1740. func (c StockTemplateController) TransportRecordPdf(reqData models.TransportRecord) {
  1741. s := services.StockTemplate{}
  1742. imgSvc := services.MedicineImg{}
  1743. barcodeServ := services.Barcode{}
  1744. deptId := beegouser.GetDeptId(c.Ctx)
  1745. p := actions.GetPermissionFromContext(c.Ctx)
  1746. rootId, err := imgSvc.GetRootID((*context2.Context)(c.Ctx), p.DeptId)
  1747. if err != nil {
  1748. c.Error(global.BadRequest, err, err.Error())
  1749. return
  1750. }
  1751. list, err := s.StockTemplateTransportRecordWord(&reqData, deptId)
  1752. if err != nil {
  1753. c.Error(500, err, err.Error())
  1754. return
  1755. }
  1756. reqData.DeptID = deptId
  1757. reqData.DeptName = beegouser.GetDeptName(c.Ctx)
  1758. reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
  1759. reqData.SetDeptId(deptId)
  1760. code, err := barcodeServ.Insert(reqData)
  1761. if err != nil {
  1762. err = errors.New("生成条码失败")
  1763. c.Error(500, err, err.Error())
  1764. return
  1765. }
  1766. cs, _ := code128.Encode(code)
  1767. // 创建一个要输出数据的文件
  1768. imgPath := "ofile/img/" + code + ".png"
  1769. file, _ := os.Create(imgPath)
  1770. defer file.Close()
  1771. // 设置图片像素大小
  1772. qrCode, _ := barcode.Scale(cs, 205, 50)
  1773. // 将code128的条形码编码为png图片
  1774. png.Encode(file, qrCode)
  1775. cols := []float64{83, 50, 55, 72, 72, 50, 66, 50, 27, 30}
  1776. header := []string{"品种", "生产企业", "批准文号", "批签发合格编号", "规格(剂/支或粒)", "生产日期", "批号", "失效日期", "数量", "单位"}
  1777. rows := [][]string{}
  1778. imgList := []string{}
  1779. for _, row := range list {
  1780. temp := []string{}
  1781. product := utils.ToString(row[models.FieldProductName])
  1782. enterprise := utils.ToString(row[models.FieldEnterpriseName])
  1783. spec := utils.ToString(row[models.FieldSpecName])
  1784. batchNumber := utils.ToString(row[models.FieldBatchNumber])
  1785. temp = append(temp, product)
  1786. temp = append(temp, fmt.Sprintf("%s", enterprise))
  1787. temp = append(temp, utils.ToString(row[models.FieldApprovalNumber]))
  1788. temp = append(temp, utils.ToString(row[models.FieldQualificationNumber]))
  1789. temp = append(temp, spec)
  1790. temp = append(temp, utils.ToString(row[models.FieldProducedDate]))
  1791. temp = append(temp, batchNumber)
  1792. temp = append(temp, utils.ToString(row[models.FieldExpiryDate]))
  1793. temp = append(temp, fmt.Sprintf("%d", utils.ToInt(row["quantity"])))
  1794. temp = append(temp, utils.ToString(row[models.FieldUnitName]))
  1795. rows = append(rows, temp)
  1796. // 获取药品信息图片
  1797. img, err := imgSvc.Get(deptId, rootId, product, enterprise, spec, batchNumber)
  1798. if err == nil && img.Img != "" {
  1799. imgList = append(imgList, img.Img)
  1800. }
  1801. }
  1802. if len(list) < 11 {
  1803. for i := 0; i < 11-len(list); i++ {
  1804. rows = append(rows, []string{"", "", "", "", "", "", "", "", "", ""})
  1805. }
  1806. }
  1807. pdf := &gopdf.GoPdf{}
  1808. pdf.Start(gopdf.Config{PageSize: gopdf.Rect{W: 595.28, H: 841.89}})
  1809. pdf.SetMarginTop(40)
  1810. pdf.SetMarginBottom(40)
  1811. pdf.AddPage()
  1812. pdf.AddTTFFont("simsun", "static/fonts/MiSans-Medium.ttf")
  1813. pdf.SetMargins(2, 5, 5, 5)
  1814. pdf.SetFont("simsun", "", 10)
  1815. pdf.SetX(20)
  1816. pdf.SetY(20)
  1817. pdf.Text("[扫码入库]")
  1818. pdf.SetX(20)
  1819. pdf.SetY(32)
  1820. pdf.Text("NO:" + code)
  1821. imgPath2 := "ofile/img/" + code + ".jpg"
  1822. png2j.Con2jpg(imgPath, imgPath2)
  1823. pdf.Image(imgPath2, -5, 35, &gopdf.Rect{W: 175, H: 30})
  1824. titleStr := "表3-4 运输记录表"
  1825. pdf.SetFont("simsun", "", 22)
  1826. textw, _ := pdf.MeasureTextWidth(titleStr)
  1827. pdf.SetX((595 / 2) - (textw / 2))
  1828. pdf.SetY(40)
  1829. pdf.Text(titleStr)
  1830. pdf.SetFont("simsun", "", 16)
  1831. titleStr = "(各级通用)"
  1832. textw, _ = pdf.MeasureTextWidth(titleStr)
  1833. pdf.SetX((595 / 2) - (textw / 2))
  1834. pdf.SetY(60)
  1835. pdf.Text(titleStr)
  1836. pdf.SetFont("simsun", "", 10)
  1837. curx, y := 20., pdf.GetY()
  1838. y += 35
  1839. pdf.SetXY(curx, y)
  1840. pdf.Text("运输工具: □冷藏车 □运输车 □普通车辆 □无 □其他")
  1841. y += 16
  1842. pdf.SetXY(curx, y)
  1843. pdf.Text("冷藏工具: □冷藏车 □车载冷藏箱 □冷藏箱或冷藏包 □其他")
  1844. y += 16
  1845. pdf.SetXY(curx, y)
  1846. pdf.Text("配送方式: □本级配送(车牌号:_______) □下级自运(车牌号:_______)")
  1847. y += 20
  1848. pdf.SetXY(curx, y)
  1849. pdf.Text("运输情况:")
  1850. y += 6
  1851. pdf.SetXY(curx, y)
  1852. h := 20.0
  1853. x := curx
  1854. pdf.SetFont("simsun", "", 9)
  1855. for i := 0; i < len(header); i++ {
  1856. utils.RectFillColorMultiCell(pdf, header[i], 9, x, y, cols[i], h, 0, 0, 0, gopdf.Center, gopdf.Middle)
  1857. x += cols[i]
  1858. }
  1859. y += h
  1860. pdf.SetXY(curx, y)
  1861. pdf.SetFont("simsun", "", 8)
  1862. for _, row := range rows {
  1863. curx, y = pdf.GetX(), pdf.GetY()
  1864. x = curx
  1865. height := h
  1866. for i, txt := range row {
  1867. lineTexts, _ := pdf.SplitText(txt, cols[i])
  1868. //lineHt := h * float64(len(lineTexts))
  1869. if len(lineTexts) > 1 {
  1870. lineTexts, _ = pdf.SplitText(txt, cols[i]-4)
  1871. lineHt := h * float64(len(lineTexts)) * 0.6
  1872. if lineHt > height {
  1873. height = lineHt
  1874. }
  1875. }
  1876. }
  1877. for i, txt := range row {
  1878. width := cols[i]
  1879. utils.RectFillColorMultiCell(pdf, txt, 9, x, y, width, height, 0, 0, 0, gopdf.Center, gopdf.Middle)
  1880. x += width
  1881. }
  1882. pdf.SetNewY(y+height, height)
  1883. pdf.SetX(curx)
  1884. }
  1885. pdf.SetFont("simsun", "", 9)
  1886. y = pdf.GetY()
  1887. y += 20
  1888. pdf.SetNewY(y, 20)
  1889. if pdf.GetY() < 30 {
  1890. pdf.SetY(30)
  1891. }
  1892. pdf.SetX(curx)
  1893. pdf.Text("运输温度记录:")
  1894. header2 := []string{"", "日期/时间", "储存温度", "冰排状态", "环境温度"}
  1895. cols2 := []float64{55, 210, 105, 94, 91}
  1896. y = pdf.GetY()
  1897. y += 5
  1898. h = 35.0
  1899. pdf.SetNewY(y, h)
  1900. if pdf.GetY() < 30 {
  1901. pdf.SetY(30)
  1902. }
  1903. y = pdf.GetY()
  1904. pdf.SetX(curx)
  1905. x = curx
  1906. for i := 0; i < len(header2); i++ {
  1907. utils.RectFillColorMultiCell(pdf, header2[i], 9, x, y, cols2[i], h, 0, 0, 0, gopdf.Center, gopdf.Middle)
  1908. x += cols2[i]
  1909. }
  1910. y += h
  1911. pdf.SetNewY(y, h)
  1912. if pdf.GetY() < 30 {
  1913. pdf.SetY(30)
  1914. }
  1915. pdf.SetX(curx)
  1916. row2 := [][]string{
  1917. {"启运", "______年___月___日___时___分", "________℃", "", "________℃"},
  1918. {"途中", "______年___月___日___时___分", "________℃", "————", "________℃"},
  1919. {"到达", "______年___月___日___时___分", "________℃", "", "________℃"},
  1920. }
  1921. for j, row := range row2 {
  1922. curx, y = pdf.GetX(), pdf.GetY()
  1923. x = curx
  1924. pdf.SetTextColor(0, 0, 0)
  1925. height := h
  1926. if j == 1 {
  1927. height = height * 2
  1928. }
  1929. for i, txt := range row {
  1930. width := cols2[i]
  1931. txtWd, _ := pdf.MeasureTextWidth(txt)
  1932. txtX := x + (width-txtWd)/2
  1933. pdf.SetLineWidth(0.8)
  1934. pdf.SetFillColor(255, 255, 255) //setup fill color
  1935. pdf.SetLineType("") // 线条样式
  1936. pdf.RectFromUpperLeftWithStyle(x, y, width, height, "FD")
  1937. if j == 1 {
  1938. if i == 1 || i == 2 || i == 4 {
  1939. txtY := y + height/5*2
  1940. pdf.SetXY(txtX, txtY)
  1941. pdf.Text(txt)
  1942. txtY = y + height/5*4
  1943. pdf.SetXY(txtX, txtY)
  1944. pdf.Text(txt)
  1945. } else {
  1946. txtY := y + height/5*3
  1947. pdf.SetXY(txtX, txtY)
  1948. pdf.Text(txt)
  1949. }
  1950. } else {
  1951. txtY := y + height/3*2
  1952. pdf.SetXY(txtX, txtY)
  1953. pdf.Text(txt)
  1954. }
  1955. x += width
  1956. }
  1957. pdf.SetNewY(y+height, height)
  1958. if pdf.GetY() < 30 || pdf.GetY() > 810 {
  1959. pdf.SetY(30)
  1960. }
  1961. pdf.SetX(curx)
  1962. }
  1963. y = pdf.GetY()
  1964. y += 20
  1965. pdf.SetNewY(y, 20)
  1966. if pdf.GetY() < 30 {
  1967. pdf.SetY(30)
  1968. }
  1969. pdf.SetX(curx)
  1970. pdf.SetFont("simsun", "", 10)
  1971. pdf.Text("启运至到达行驶里程数:_________千米")
  1972. y = pdf.GetY()
  1973. y += 25
  1974. pdf.SetNewY(y, 25)
  1975. if pdf.GetY() < 30 {
  1976. pdf.SetY(30)
  1977. }
  1978. pdf.SetX(curx)
  1979. y = pdf.GetY()
  1980. pdf.Text("发货单位:")
  1981. txtWd, _ := pdf.MeasureTextWidth("发货单位:")
  1982. pdf.SetLineWidth(0.8)
  1983. pdf.SetXY(curx+txtWd, y)
  1984. pdf.Text(beegouser.GetDeptName(c.Ctx))
  1985. pdf.Line(60, y+3, 207, y+3)
  1986. pdf.SetXY(300, y)
  1987. pdf.Text("发货人签名:")
  1988. txtWd, _ = pdf.MeasureTextWidth("发货人签名:")
  1989. pdf.Line(348, y+3, 495, y+3)
  1990. y = pdf.GetY()
  1991. y += 25
  1992. pdf.SetNewY(y, 25)
  1993. if pdf.GetY() < 30 {
  1994. pdf.SetY(30)
  1995. }
  1996. pdf.SetX(curx)
  1997. y = pdf.GetY()
  1998. pdf.Text("收货单位:")
  1999. txtWd, _ = pdf.MeasureTextWidth("收货单位:")
  2000. pdf.SetXY(curx+txtWd, y)
  2001. pdf.Text(reqData.ReceivingUnit)
  2002. pdf.Line(60, y+3, 207, y+3)
  2003. pdf.SetXY(300, y)
  2004. pdf.Text("收货人签名:")
  2005. txtWd, _ = pdf.MeasureTextWidth("收货人签名:")
  2006. pdf.Line(348, y+3, 495, y+3)
  2007. y = pdf.GetY()
  2008. y += 20
  2009. pdf.SetNewY(y, 20)
  2010. if pdf.GetY() < 30 {
  2011. pdf.SetY(30)
  2012. }
  2013. pdf.SetX(curx)
  2014. pdf.SetCharSpacing(0.5)
  2015. txt := "填表说明:本表供冷链配送企业、疾病预防控制机构、接种单位冷链运输时填写;出入库单号为单位编码+年月日+2位流水号;运输超过6小时需记录途中温度,间隔不超过6小时;使用无自动温度显示的冰排保冷设备时,只在启运和达到时填写冰排状态(冻结、冰水混合物、完全融化)。"
  2016. pdf.MultiCell(&gopdf.Rect{W: 555, H: 50}, txt)
  2017. //imgList = append(imgList,
  2018. // "https://godownoss.coldbaozhida.com/UpImage/17115067977062dc7f-0354-4e70-aefe-3423338b44be.jpg",
  2019. // "https://godownoss.coldbaozhida.com/UpImage/17115068019adbd486-993e-48c5-8155-c2c30265638a.jpg",
  2020. //)
  2021. for _, v := range imgList {
  2022. urlList := strings.Split(strings.Trim(v, ","), ",")
  2023. for _, url := range urlList {
  2024. pdf.AddPage()
  2025. imgH, errImg := utils.GetImage(url)
  2026. if errImg != nil {
  2027. err = errors.New("获取图片失败")
  2028. c.Error(500, err, err.Error())
  2029. return
  2030. }
  2031. imgWidth := float64(imgH.Bounds().Dx())
  2032. imgHeight := float64(imgH.Bounds().Dy())
  2033. W, H := imgWidth, imgHeight
  2034. if imgWidth >= imgHeight && imgWidth > 555 {
  2035. W = 555
  2036. H = 555 * float64(imgHeight) / float64(imgWidth)
  2037. }
  2038. if imgWidth < imgHeight && imgWidth > 760 {
  2039. W = 760 * float64(imgWidth) / float64(imgHeight)
  2040. H = 760
  2041. if W > 555 {
  2042. H = 555 * 760 / W
  2043. W = 555
  2044. }
  2045. }
  2046. if strings.Contains(url, ".png") {
  2047. err = pdf.ImageFrom(imgH, (595-W)/2, (840-H)/2, &gopdf.Rect{W: W, H: H})
  2048. if err != nil {
  2049. err = errors.New("写入图片失败")
  2050. c.Error(500, err, err.Error())
  2051. return
  2052. }
  2053. } else {
  2054. fileName := "./ofile/" + path.Base(url)
  2055. f, _ := os.Create(fileName)
  2056. defer f.Close()
  2057. defer func() {
  2058. os.Remove(fileName)
  2059. }()
  2060. jpeg.Encode(f, imgH, &jpeg.Options{100})
  2061. err = pdf.Image(fileName, (595-W)/2, (840-H)/2, &gopdf.Rect{W: W, H: H})
  2062. if err != nil {
  2063. err = errors.New("写入图片失败")
  2064. c.Error(500, err, err.Error())
  2065. return
  2066. }
  2067. }
  2068. }
  2069. }
  2070. for i := 0; i < pdf.GetNumberOfPages(); i++ {
  2071. }
  2072. filename := "运输记录表" + time.Now().Format("20060102150405") + ".pdf"
  2073. // 保存文件
  2074. if err = pdf.WritePdf("ofile/" + filename); err != nil {
  2075. fmt.Println(err)
  2076. }
  2077. defer func() {
  2078. os.Remove("ofile/" + filename)
  2079. os.Remove(imgPath)
  2080. os.Remove(imgPath2)
  2081. }()
  2082. // 返回生成的 Excel 文件
  2083. c.Ctx.Output.Download("ofile/" + filename)
  2084. }
  2085. // TransportRecordExport 运输记录表
  2086. // @Summary 收发登记表word
  2087. // @Description 收发登记表word
  2088. // @Tags 库存
  2089. // @Param body body dto.TransportRecordWordReq true "body"
  2090. // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
  2091. // @Router /stock-template/inventory/list [post]
  2092. // @Security Bearer
  2093. func (c StockTemplateController) TransportRecordExport() {
  2094. reqData := models.TransportRecord{}
  2095. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  2096. err = errors.New("解析表单数据异常")
  2097. c.Error(global.ParseFormErr, err, err.Error())
  2098. return
  2099. }
  2100. deptId := beegouser.GetDeptId(c.Ctx)
  2101. models.InitBasicData(deptId)
  2102. if reqData.Type == "pdf" {
  2103. c.TransportRecordPdf(reqData)
  2104. }
  2105. if reqData.Type == "word" {
  2106. c.TransportRecordWord(reqData)
  2107. }
  2108. }
  2109. // TransportRecordExport 运输记录表
  2110. // @Summary 收发登记表word
  2111. // @Description 收发登记表word
  2112. // @Tags 库存
  2113. // @Param body body dto.TransportRecordWordReq true "body"
  2114. // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
  2115. // @Router /stock-template/inventory/list [post]
  2116. // @Security Bearer
  2117. func (c StockTemplateController) TransportRecordExportList() {
  2118. s := services.StockTemplate{}
  2119. reqData := models.TransportRecord{}
  2120. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  2121. err = errors.New("解析表单数据异常")
  2122. c.Error(global.ParseFormErr, err, err.Error())
  2123. return
  2124. }
  2125. deptId := beegouser.GetDeptId(c.Ctx)
  2126. models.InitBasicData(deptId)
  2127. list, err := s.StockTemplateTransportRecordWord(&reqData, deptId)
  2128. if err != nil {
  2129. c.Error(500, err, err.Error())
  2130. return
  2131. }
  2132. c.PageOK(list, 0, 0, 0, "查询成功")
  2133. }
  2134. // StockUnitList 获取收货单位,发货单位,收发单位
  2135. // @Summary 获取收货单位,发货单位,收发单位
  2136. // @Description 获取收货单位,发货单位,收发单位
  2137. // @Tags 库存
  2138. // @Param body body dto.StockUnitListReq true "body"
  2139. // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
  2140. // @Router /stock/unit/list [post]
  2141. // @Security Bearer
  2142. func (c StockTemplateController) StockUnitList() {
  2143. s := services.StockTemplate{}
  2144. reqData := dto.StockUnitListReq{}
  2145. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  2146. err = errors.New("解析表单数据异常")
  2147. c.Error(global.ParseFormErr, err, err.Error())
  2148. return
  2149. }
  2150. deptId := beegouser.GetDeptId(c.Ctx)
  2151. list, err := s.StockUnitList(&reqData, deptId)
  2152. if err != nil {
  2153. c.Error(500, err, err.Error())
  2154. return
  2155. }
  2156. c.PageOK(list, 0, 0, 0, "查询成功")
  2157. }
  2158. // StockOperatorList 获取收货单位,发货单位,收发单位
  2159. // @Summary 获取收货单位,发货单位,收发单位
  2160. // @Description 获取收货单位,发货单位,收发单位
  2161. // @Tags 库存
  2162. // @Param body body dto.StockOperatorListReq true "body"
  2163. // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
  2164. // @Router /stock/unit/list [post]
  2165. // @Security Bearer
  2166. func (c StockTemplateController) StockOperatorList() {
  2167. s := services.StockTemplate{}
  2168. reqData := dto.StockOperatorListReq{}
  2169. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  2170. err = errors.New("解析表单数据异常")
  2171. c.Error(global.ParseFormErr, err, err.Error())
  2172. return
  2173. }
  2174. deptId := beegouser.GetDeptId(c.Ctx)
  2175. list, err := s.StockOperatorList(&reqData, deptId)
  2176. if err != nil {
  2177. c.Error(500, err, err.Error())
  2178. return
  2179. }
  2180. c.PageOK(list, 0, 0, 0, "查询成功")
  2181. }
  2182. // StockInquiryList 库存查询
  2183. // @Summary 库存查询-每个商品、生产企业、规格、批号数量
  2184. // @Description 库存查询
  2185. // @Tags 库存
  2186. // @Param body body dto.StockStatListReq true "body"
  2187. // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
  2188. // @Router /stock/inquiry/list [post]
  2189. // @Security Bearer
  2190. func (c StockTemplateController) StockInquiryList() {
  2191. s := services.StockTemplate{}
  2192. reqData := dto.StockStatListReq{}
  2193. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  2194. err = errors.New("解析表单数据异常")
  2195. c.Error(global.ParseFormErr, err, err.Error())
  2196. return
  2197. }
  2198. deptId := beegouser.GetDeptId(c.Ctx)
  2199. list, cnt, err := s.StockInquiryList(&reqData, deptId)
  2200. if err != nil {
  2201. c.Error(500, err, err.Error())
  2202. return
  2203. }
  2204. c.PageOK(list, int(cnt), reqData.GetPageIndex(), reqData.GetPageSize(), "查询成功")
  2205. }
  2206. // GetStockInquiry 单个产品库存查询
  2207. // @Summary 库存查询-商品、生产企业、规格、批号
  2208. // @Description 单个产品库存查询
  2209. // @Tags 库存
  2210. // @Param body body dto.StockStatListReq true "body"
  2211. // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
  2212. // @Router /stock/inquiry/list [post]
  2213. // @Security Bearer
  2214. func (c StockTemplateController) GetStockInquiry() {
  2215. s := services.StockTemplate{}
  2216. reqData := dto.GetStockStatReq{}
  2217. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  2218. err = errors.New("解析表单数据异常")
  2219. c.Error(global.ParseFormErr, err, err.Error())
  2220. return
  2221. }
  2222. deptId := beegouser.GetDeptId(c.Ctx)
  2223. res, err := s.GetStockInquiry(&reqData, deptId)
  2224. if err != nil {
  2225. c.Error(500, err, err.Error())
  2226. return
  2227. }
  2228. c.OK(res, "查询成功")
  2229. }
  2230. // StockInquiryExcel 导出库存信息表
  2231. // @Summary 库存信息表-每个商品、生产企业、规格、批号数量
  2232. // @Description 库存信息表
  2233. // @Tags 库存
  2234. // @Param body body dto.StockStatListReq true "body"
  2235. // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
  2236. // @Router /stock/stat/excel [post]
  2237. // @Security Bearer
  2238. func (c StockTemplateController) StockInquiryExcel() {
  2239. s := services.StockTemplate{}
  2240. reqData := dto.StockStatListReq{}
  2241. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  2242. err = errors.New("解析表单数据异常")
  2243. c.Error(global.ParseFormErr, err, err.Error())
  2244. return
  2245. }
  2246. deptId := beegouser.GetDeptId(c.Ctx)
  2247. list, err := s.StockInquiryExcel(&reqData, deptId)
  2248. if err != nil {
  2249. c.Error(500, err, err.Error())
  2250. return
  2251. }
  2252. f := excelize.NewFile() // 设置单元格的值
  2253. StyleTitle, _ := f.NewStyle(
  2254. &excelize.Style{
  2255. Font: &excelize.Font{Bold: true, Size: 20, Family: "宋体"},
  2256. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
  2257. })
  2258. f.MergeCell("Sheet1", "A1", "K1")
  2259. f.SetRowStyle("Sheet1", 1, 1, StyleTitle)
  2260. f.SetRowHeight("Sheet1", 1, 50)
  2261. f.SetCellValue("Sheet1", "A1", fmt.Sprintf("库存信息表(%s)", time.Now().Format("2006-01-02 15:04:05")))
  2262. // 这里设置表头
  2263. f.SetCellValue("Sheet1", "A2", "品名")
  2264. f.SetCellValue("Sheet1", "B2", "生产企业")
  2265. f.SetCellValue("Sheet1", "C2", "规格")
  2266. f.SetCellValue("Sheet1", "D2", "剂型")
  2267. f.SetCellValue("Sheet1", "E2", "单位")
  2268. f.SetCellValue("Sheet1", "F2", "数量")
  2269. f.SetCellValue("Sheet1", "G2", "单价")
  2270. //f.SetCellValue("Sheet1", "H2", "销售单价")
  2271. f.SetCellValue("Sheet1", "H2", "批号")
  2272. f.SetCellValue("Sheet1", "I2", "失效日期")
  2273. f.SetCellValue("Sheet1", "J2", "批准文号")
  2274. f.SetCellValue("Sheet1", "K2", "批签发编号")
  2275. // 设置列宽
  2276. f.SetColWidth("Sheet1", "A", "A", 20)
  2277. f.SetColWidth("Sheet1", "B", "C", 15)
  2278. f.SetColWidth("Sheet1", "D", "F", 12)
  2279. f.SetColWidth("Sheet1", "F", "G", 10)
  2280. f.SetColWidth("Sheet1", "G", "I", 15)
  2281. f.SetColWidth("Sheet1", "I", "J", 12)
  2282. f.SetColWidth("Sheet1", "J", "K", 15)
  2283. line := 2
  2284. // 循环写入数据
  2285. for _, v := range list {
  2286. line++
  2287. f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), v[models.FieldProductName])
  2288. f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), v[models.FieldEnterpriseName])
  2289. f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v[models.FieldSpecName])
  2290. f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v[models.FieldDosageFormName])
  2291. f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v[models.FieldUnitName])
  2292. f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v["balance"])
  2293. f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), utils.ToFloat64(v["unit_price"]))
  2294. //f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), utils.ToFloat64(v["sales_unit_price"]))
  2295. f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), v["batch_number"])
  2296. f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), v[models.FieldExpiryDate])
  2297. f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), v["approval_number"])
  2298. f.SetCellValue("Sheet1", fmt.Sprintf("K%d", line), v["qualification_number"])
  2299. }
  2300. Style1, _ := f.NewStyle(
  2301. &excelize.Style{
  2302. Font: &excelize.Font{Size: 12, Family: "宋体", Bold: true},
  2303. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  2304. Border: []excelize.Border{
  2305. {Type: "left", Color: "000000", Style: 1},
  2306. {Type: "top", Color: "000000", Style: 1},
  2307. {Type: "bottom", Color: "000000", Style: 1},
  2308. {Type: "right", Color: "000000", Style: 1},
  2309. },
  2310. })
  2311. f.SetCellStyle("Sheet1", "A2", "K2", Style1)
  2312. Style2, _ := f.NewStyle(
  2313. &excelize.Style{
  2314. Font: &excelize.Font{Size: 12, Family: "宋体"},
  2315. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  2316. Border: []excelize.Border{
  2317. {Type: "left", Color: "000000", Style: 1},
  2318. {Type: "top", Color: "000000", Style: 1},
  2319. {Type: "bottom", Color: "000000", Style: 1},
  2320. {Type: "right", Color: "000000", Style: 1},
  2321. },
  2322. })
  2323. f.SetCellStyle("Sheet1", "A3", fmt.Sprintf("K%d", line), Style2)
  2324. filename := "库存信息表" + time.Now().Format("20060102150405") + ".xlsx"
  2325. // 保存文件
  2326. if err := f.SaveAs("ofile/" + filename); err != nil {
  2327. fmt.Println(err)
  2328. }
  2329. defer func() {
  2330. os.Remove("ofile/" + filename)
  2331. }()
  2332. // 返回生成的 Excel 文件
  2333. c.Ctx.Output.Download("ofile/" + filename)
  2334. }
  2335. // StockStat 库存统计
  2336. // @Summary 库存查询-每个商品数量(不区别生产企业)
  2337. // @Description 库存查询
  2338. // @Tags 库存
  2339. // @Param body body dto.StockStatListReq true "body"
  2340. // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
  2341. // @Router /stock/stat [post]
  2342. // @Security Bearer
  2343. func (c StockTemplateController) StockStat() {
  2344. s := services.StockTemplate{}
  2345. reqData := dto.StockStatReq{}
  2346. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  2347. err = errors.New("解析表单数据异常")
  2348. c.Error(global.ParseFormErr, err, err.Error())
  2349. return
  2350. }
  2351. deptId := beegouser.GetDeptId(c.Ctx)
  2352. list, cnt, err := s.StockStat(&reqData, deptId)
  2353. if err != nil {
  2354. c.Error(500, err, err.Error())
  2355. return
  2356. }
  2357. c.PageOK(list, int(cnt), 0, 0, "查询成功")
  2358. }
  2359. // StockHomeStat 首页出入库信息统计
  2360. // @Summary 首页出入库信息统计
  2361. // @Description 首页出入库信息统计
  2362. // @Tags 库存
  2363. // @Param body body dto.StockStatListReq true "body"
  2364. // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
  2365. // @Router /stock/stat [post]
  2366. // @Security Bearer
  2367. func (c StockTemplateController) StockHomeStat() {
  2368. s := services.StockTemplate{}
  2369. deptId := beegouser.GetDeptId(c.Ctx)
  2370. list, cnt, err := s.StockHomeStat(deptId)
  2371. if err != nil {
  2372. c.Error(500, err, err.Error())
  2373. return
  2374. }
  2375. c.PageOK(list, int(cnt), 0, 0, "查询成功")
  2376. }
  2377. // StockTemplateInScanBarCode 扫条码入库
  2378. // @Summary 扫条码入库
  2379. // @Description 扫条码入库
  2380. // @Tags 库存
  2381. // @Param body body dto.StockTemplateOutInsertReq true "body"
  2382. // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
  2383. // @Router /stock-template/out [post]
  2384. // @Security Bearer
  2385. func (c StockTemplateController) StockTemplateInScanBarCode() {
  2386. s := services.StockTemplate{}
  2387. reqData := dto.BatchStockTemplateOutInsertReq{}
  2388. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  2389. err = errors.New("解析表单数据异常")
  2390. c.Error(global.ParseFormErr, err, err.Error())
  2391. return
  2392. }
  2393. reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
  2394. reqData.SetDeptId(beegouser.GetDeptId(c.Ctx))
  2395. err := s.StockTemplateOutScanCode(&reqData)
  2396. if err != nil {
  2397. c.Error(500, err, err.Error())
  2398. return
  2399. }
  2400. c.OK(nil, "扫码出库成功")
  2401. }
  2402. func (c StockTemplateController) GetTransportRecordBarCodeInfo() {
  2403. barcodeSvc := services.Barcode{}
  2404. s := services.StockTemplate{}
  2405. //if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  2406. // c.Error(global.ParseFormErr, err, err.Error())
  2407. // return
  2408. //}
  2409. codeStr := c.GetString("code")
  2410. reqData := dto.GetBarCodeInfoReq{Code: codeStr}
  2411. var code models.Barcode
  2412. //数据权限检查
  2413. err := barcodeSvc.Get(&reqData, &code)
  2414. if err != nil {
  2415. c.Error(500, err, err.Error())
  2416. return
  2417. }
  2418. list, err := s.StockTemplateTransportRecordWord2(&code.Data, code.Data.DeptID)
  2419. if err != nil {
  2420. c.Error(500, err, err.Error())
  2421. return
  2422. }
  2423. for _, v := range list {
  2424. v["forwardingUnit"] = code.Data.DeptName
  2425. }
  2426. c.OK(list, "查询成功")
  2427. }
  2428. func (c StockTemplateController) StockRefundOutTransportRecordPdf(reqData models.TransportRecord) {
  2429. s := services.StockTemplate{}
  2430. imgSvc := services.MedicineImg{}
  2431. barcodeServ := services.Barcode{}
  2432. deptId := beegouser.GetDeptId(c.Ctx)
  2433. p := actions.GetPermissionFromContext(c.Ctx)
  2434. rootId, err := imgSvc.GetRootID((*context2.Context)(c.Ctx), p.DeptId)
  2435. if err != nil {
  2436. c.Error(global.BadRequest, err, err.Error())
  2437. return
  2438. }
  2439. list, err := s.StockRefundOutTransportRecordPdf(&reqData, deptId)
  2440. if err != nil {
  2441. c.Error(500, err, err.Error())
  2442. return
  2443. }
  2444. reqData.DeptID = deptId
  2445. reqData.DeptName = beegouser.GetDeptName(c.Ctx)
  2446. reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
  2447. reqData.SetDeptId(deptId)
  2448. code, err := barcodeServ.Insert(reqData)
  2449. if err != nil {
  2450. err = errors.New("生成条码失败")
  2451. c.Error(500, err, err.Error())
  2452. return
  2453. }
  2454. cs, _ := code128.Encode(code)
  2455. // 创建一个要输出数据的文件
  2456. imgPath := "ofile/img/" + code + ".png"
  2457. file, _ := os.Create(imgPath)
  2458. defer file.Close()
  2459. // 设置图片像素大小
  2460. qrCode, _ := barcode.Scale(cs, 205, 50)
  2461. // 将code128的条形码编码为png图片
  2462. png.Encode(file, qrCode)
  2463. cols := []float64{83, 50, 55, 72, 72, 50, 66, 50, 27, 30}
  2464. header := []string{"品种", "生产企业", "批准文号", "批签发合格编号", "规格(剂/支或粒)", "生产日期", "批号", "失效日期", "数量", "单位"}
  2465. rows := [][]string{}
  2466. imgList := []string{}
  2467. for _, row := range list {
  2468. temp := []string{}
  2469. product := utils.ToString(row[models.FieldProductName])
  2470. enterprise := utils.ToString(row[models.FieldEnterpriseName])
  2471. spec := utils.ToString(row[models.FieldSpecName])
  2472. batchNumber := utils.ToString(row[models.FieldBatchNumber])
  2473. temp = append(temp, product)
  2474. temp = append(temp, fmt.Sprintf("%s", enterprise))
  2475. temp = append(temp, utils.ToString(row[models.FieldApprovalNumber]))
  2476. temp = append(temp, utils.ToString(row[models.FieldQualificationNumber]))
  2477. temp = append(temp, spec)
  2478. temp = append(temp, utils.ToString(row[models.FieldProducedDate]))
  2479. temp = append(temp, batchNumber)
  2480. temp = append(temp, utils.ToString(row[models.FieldExpiryDate]))
  2481. temp = append(temp, fmt.Sprintf("%d", utils.ToInt(row["quantity"])))
  2482. temp = append(temp, utils.ToString(row[models.FieldUnitName]))
  2483. rows = append(rows, temp)
  2484. // 获取药品信息图片
  2485. img, err := imgSvc.Get(deptId, rootId, product, enterprise, spec, batchNumber)
  2486. if err == nil && img.Img != "" {
  2487. log.Println("==============", img.Img)
  2488. imgList = append(imgList, img.Img)
  2489. }
  2490. }
  2491. pdf := &gopdf.GoPdf{}
  2492. pdf.Start(gopdf.Config{PageSize: gopdf.Rect{W: 595.28, H: 841.89}})
  2493. pdf.SetMarginTop(40)
  2494. pdf.SetMarginBottom(40)
  2495. pdf.AddPage()
  2496. pdf.AddTTFFont("simsun", "static/fonts/MiSans-Medium.ttf")
  2497. pdf.SetMargins(2, 5, 5, 5)
  2498. pdf.SetFont("simsun", "", 10)
  2499. //pdf.SetX(20)
  2500. //pdf.SetY(20)
  2501. //pdf.Text("[退货出库]")
  2502. pdf.SetX(420)
  2503. pdf.SetY(60)
  2504. pdf.Text(code)
  2505. imgPath2 := "ofile/img/" + code + ".jpg"
  2506. png2j.Con2jpg(imgPath, imgPath2)
  2507. pdf.Image(imgPath2, 390, 15, &gopdf.Rect{W: 200, H: 35})
  2508. titleStr := "退货出库运输温度记录表"
  2509. pdf.SetFont("simsun", "", 22)
  2510. textw, _ := pdf.MeasureTextWidth(titleStr)
  2511. pdf.SetX((595 / 2) - (textw / 2) - 50)
  2512. pdf.SetY(40)
  2513. pdf.Text(titleStr)
  2514. pdf.SetFont("simsun", "", 10)
  2515. // 第一行
  2516. curx, y := 20., pdf.GetY()
  2517. y += 35
  2518. pdf.SetXY(curx, y)
  2519. pdf.Text("出/入库日期:")
  2520. txtWd, _ := pdf.MeasureTextWidth("出/入库日期:")
  2521. pdf.SetXY(curx+txtWd, y)
  2522. pdf.Text(reqData.Date)
  2523. pdf.Line(curx+txtWd, y+3, curx+txtWd+110, y+3)
  2524. curx = 230
  2525. pdf.SetXY(curx, y)
  2526. pdf.Text("出/入库单号:")
  2527. txtWd, _ = pdf.MeasureTextWidth("出/入库单号:")
  2528. pdf.SetXY(curx+txtWd, y)
  2529. pdf.Text(code)
  2530. pdf.Line(curx+txtWd, y+3, curx+txtWd+130, y+3)
  2531. // 第二行
  2532. curx, y = 20., pdf.GetY()
  2533. y += 25
  2534. pdf.SetXY(curx, y)
  2535. pdf.Text("运输工具:(1)冷藏车")
  2536. txtWd, _ = pdf.MeasureTextWidth("运输工具:(1)冷藏车")
  2537. pdf.SetXY(curx+txtWd, y)
  2538. //pdf.Text(reqData.Date)
  2539. pdf.Line(curx+txtWd, y+3, curx+txtWd+110, y+3)
  2540. curx = 230
  2541. pdf.SetXY(curx, y)
  2542. pdf.Text("(2)运输车")
  2543. txtWd, _ = pdf.MeasureTextWidth("(2)运输车")
  2544. pdf.SetXY(curx+txtWd, y)
  2545. //pdf.Text(code)
  2546. pdf.Line(curx+txtWd+2, y+3, curx+txtWd+130, y+3)
  2547. curx = 410
  2548. pdf.SetXY(curx, y)
  2549. pdf.Text("(3)其他")
  2550. txtWd, _ = pdf.MeasureTextWidth("(3)其他")
  2551. pdf.SetXY(curx+txtWd, y)
  2552. //pdf.Text(code)
  2553. pdf.Line(curx+txtWd+2, y+3, curx+txtWd+130, y+3)
  2554. // 第三行
  2555. curx, y = 20., pdf.GetY()
  2556. y += 25
  2557. pdf.SetXY(curx, y)
  2558. pdf.Text("冷藏方式:(1)冷藏车")
  2559. txtWd, _ = pdf.MeasureTextWidth("运输工具:(1)冷藏车")
  2560. pdf.SetXY(curx+txtWd, y)
  2561. //pdf.Text(reqData.Date)
  2562. pdf.Line(curx+txtWd, y+3, curx+txtWd+110, y+3)
  2563. curx = 230
  2564. pdf.SetXY(curx, y)
  2565. pdf.Text("(2)冷藏箱")
  2566. txtWd, _ = pdf.MeasureTextWidth("(2)冷藏箱")
  2567. pdf.SetXY(curx+txtWd, y)
  2568. //pdf.Text(code)
  2569. pdf.Line(curx+txtWd, y+3, curx+txtWd+130, y+3)
  2570. curx = 410
  2571. pdf.SetXY(curx, y)
  2572. pdf.Text("(3)其他")
  2573. txtWd, _ = pdf.MeasureTextWidth("(3)其他")
  2574. pdf.SetXY(curx+txtWd, y)
  2575. //pdf.Text(code)
  2576. pdf.Line(curx+txtWd, y+3, curx+txtWd+130, y+3)
  2577. curx = 20
  2578. y += 20
  2579. pdf.SetXY(curx, y)
  2580. pdf.Text("运输情况:")
  2581. y += 6
  2582. pdf.SetXY(curx, y)
  2583. h := 20.0
  2584. x := curx
  2585. pdf.SetFont("simsun", "", 9)
  2586. for i := 0; i < len(header); i++ {
  2587. utils.RectFillColorMultiCell(pdf, header[i], 9, x, y, cols[i], h, 0, 0, 0, gopdf.Center, gopdf.Middle)
  2588. x += cols[i]
  2589. }
  2590. y += h
  2591. pdf.SetXY(curx, y)
  2592. pdf.SetFont("simsun", "", 8)
  2593. for _, row := range rows {
  2594. curx, y = pdf.GetX(), pdf.GetY()
  2595. x = curx
  2596. height := h
  2597. for i, txt := range row {
  2598. lineTexts, _ := pdf.SplitText(txt, cols[i])
  2599. //lineHt := h * float64(len(lineTexts))
  2600. if len(lineTexts) > 1 {
  2601. lineTexts, _ = pdf.SplitText(txt, cols[i]-4)
  2602. lineHt := h * float64(len(lineTexts)) * 0.6
  2603. if lineHt > height {
  2604. height = lineHt
  2605. }
  2606. }
  2607. }
  2608. for i, txt := range row {
  2609. width := cols[i]
  2610. utils.RectFillColorMultiCell(pdf, txt, 9, x, y, width, height, 0, 0, 0, gopdf.Center, gopdf.Middle)
  2611. x += width
  2612. }
  2613. pdf.SetNewY(y+height, height)
  2614. pdf.SetX(curx)
  2615. }
  2616. pdf.SetFont("simsun", "", 9)
  2617. y = pdf.GetY()
  2618. y += 20
  2619. pdf.SetNewY(y, 20)
  2620. if pdf.GetY() < 30 {
  2621. pdf.SetY(30)
  2622. }
  2623. pdf.SetX(curx)
  2624. pdf.SetFont("simsun", "", 10)
  2625. pdf.Text("运输温度记录:")
  2626. header2 := []string{"项目", "日期/时间", "储存温度", "冰排状态", "环境温度"}
  2627. cols2 := []float64{55, 210, 105, 94, 91}
  2628. y = pdf.GetY()
  2629. y += 5
  2630. h = 35.0
  2631. pdf.SetNewY(y, h)
  2632. if pdf.GetY() < 30 {
  2633. pdf.SetY(30)
  2634. }
  2635. y = pdf.GetY()
  2636. pdf.SetX(curx)
  2637. x = curx
  2638. pdf.SetFont("simsun", "", 9)
  2639. for i := 0; i < len(header2); i++ {
  2640. utils.RectFillColorMultiCell(pdf, header2[i], 9, x, y, cols2[i], h, 0, 0, 0, gopdf.Center, gopdf.Middle)
  2641. x += cols2[i]
  2642. }
  2643. y += h
  2644. pdf.SetNewY(y, h)
  2645. if pdf.GetY() < 30 {
  2646. pdf.SetY(30)
  2647. }
  2648. pdf.SetX(curx)
  2649. pdf.SetFont("simsun", "", 9)
  2650. row2 := [][]string{
  2651. {"启运", "______年___月___日___时___分", "________℃", "", "________℃"},
  2652. {"途中", "______年___月___日___时___分", "________℃", "————", "________℃"},
  2653. {"到达", "______年___月___日___时___分", "________℃", "", "________℃"},
  2654. }
  2655. for j, row := range row2 {
  2656. curx, y = pdf.GetX(), pdf.GetY()
  2657. x = curx
  2658. pdf.SetTextColor(0, 0, 0)
  2659. height := h
  2660. if j == 1 {
  2661. height = height * 2
  2662. }
  2663. for i, txt := range row {
  2664. width := cols2[i]
  2665. txtWd, _ := pdf.MeasureTextWidth(txt)
  2666. txtX := x + (width-txtWd)/2
  2667. pdf.SetLineWidth(0.8)
  2668. pdf.SetFillColor(255, 255, 255) //setup fill color
  2669. pdf.SetLineType("") // 线条样式
  2670. pdf.RectFromUpperLeftWithStyle(x, y, width, height, "FD")
  2671. if j == 1 {
  2672. if i == 1 || i == 2 || i == 4 {
  2673. txtY := y + height/5*2
  2674. pdf.SetXY(txtX, txtY)
  2675. pdf.Text(txt)
  2676. txtY = y + height/5*4
  2677. pdf.SetXY(txtX, txtY)
  2678. pdf.Text(txt)
  2679. } else {
  2680. txtY := y + height/5*3
  2681. pdf.SetXY(txtX, txtY)
  2682. pdf.Text(txt)
  2683. }
  2684. } else {
  2685. txtY := y + height/3*2
  2686. pdf.SetXY(txtX, txtY)
  2687. pdf.Text(txt)
  2688. }
  2689. x += width
  2690. }
  2691. pdf.SetNewY(y+height, height)
  2692. if pdf.GetY() < 30 || pdf.GetY() > 810 {
  2693. pdf.SetY(30)
  2694. }
  2695. pdf.SetX(curx)
  2696. }
  2697. y = pdf.GetY()
  2698. y += 20
  2699. pdf.SetNewY(y, 20)
  2700. if pdf.GetY() < 30 {
  2701. pdf.SetY(30)
  2702. }
  2703. pdf.SetX(curx)
  2704. pdf.SetFont("simsun", "", 10)
  2705. pdf.Text("启运至到达行驶里程数:_________千米")
  2706. y = pdf.GetY()
  2707. y += 25
  2708. pdf.SetNewY(y, 25)
  2709. if pdf.GetY() < 30 {
  2710. pdf.SetY(30)
  2711. }
  2712. pdf.SetX(curx)
  2713. y = pdf.GetY()
  2714. pdf.Text("发货单位:")
  2715. txtWd, _ = pdf.MeasureTextWidth("发货单位:")
  2716. pdf.SetLineWidth(0.8)
  2717. pdf.SetXY(curx+txtWd, y)
  2718. pdf.Text(beegouser.GetDeptName(c.Ctx))
  2719. pdf.Line(60, y+3, 207, y+3)
  2720. pdf.SetXY(300, y)
  2721. pdf.Text("发货人签名:")
  2722. txtWd, _ = pdf.MeasureTextWidth("发货人签名:")
  2723. pdf.Line(348, y+3, 495, y+3)
  2724. y = pdf.GetY()
  2725. y += 25
  2726. pdf.SetNewY(y, 25)
  2727. if pdf.GetY() < 30 {
  2728. pdf.SetY(30)
  2729. }
  2730. pdf.SetX(curx)
  2731. y = pdf.GetY()
  2732. pdf.Text("收货单位:")
  2733. txtWd, _ = pdf.MeasureTextWidth("收货单位:")
  2734. pdf.SetXY(curx+txtWd, y)
  2735. pdf.Text(reqData.ReceivingUnit)
  2736. pdf.Line(60, y+3, 207, y+3)
  2737. pdf.SetXY(300, y)
  2738. pdf.Text("收货人签名:")
  2739. txtWd, _ = pdf.MeasureTextWidth("收货人签名:")
  2740. pdf.Line(348, y+3, 495, y+3)
  2741. y = pdf.GetY()
  2742. y += 20
  2743. pdf.SetNewY(y, 20)
  2744. if pdf.GetY() < 30 {
  2745. pdf.SetY(30)
  2746. }
  2747. pdf.SetX(curx)
  2748. pdf.SetCharSpacing(0.5)
  2749. txt := "填表说明:本表供冷链配送企业、疾病预防控制机构、接种单位冷链运输时填写;出入库单号为单位编码+年月日+2位流水号;运输超过6小时需记录途中温度,间隔不超过6小时;使用无自动温度显示的冰排保冷设备时,只在启运和达到时填写冰排状态(冻结、冰水混合物、完全融化)。"
  2750. pdf.MultiCell(&gopdf.Rect{W: 555, H: 50}, txt)
  2751. //imgList = append(imgList,
  2752. // "https://godownoss.coldbaozhida.com/UpImage/17115067977062dc7f-0354-4e70-aefe-3423338b44be.jpg",
  2753. // "https://godownoss.coldbaozhida.com/UpImage/17115068019adbd486-993e-48c5-8155-c2c30265638a.jpg",
  2754. //)
  2755. for _, v := range imgList {
  2756. urlList := strings.Split(strings.Trim(v, ","), ",")
  2757. for _, url := range urlList {
  2758. pdf.AddPage()
  2759. imgH, errImg := utils.GetImage(url)
  2760. if errImg != nil {
  2761. err = errors.New("获取图片失败")
  2762. c.Error(500, err, err.Error())
  2763. return
  2764. }
  2765. imgWidth := float64(imgH.Bounds().Dx())
  2766. imgHeight := float64(imgH.Bounds().Dy())
  2767. W, H := imgWidth, imgHeight
  2768. if imgWidth >= imgHeight && imgWidth > 555 {
  2769. W = 555
  2770. H = 555 * float64(imgHeight) / float64(imgWidth)
  2771. }
  2772. if imgWidth < imgHeight && imgWidth > 760 {
  2773. W = 760 * float64(imgWidth) / float64(imgHeight)
  2774. H = 760
  2775. if W > 555 {
  2776. H = 555 * 760 / W
  2777. W = 555
  2778. }
  2779. }
  2780. if strings.Contains(url, ".png") {
  2781. err = pdf.ImageFrom(imgH, (595-W)/2, (840-H)/2, &gopdf.Rect{W: W, H: H})
  2782. if err != nil {
  2783. err = errors.New("写入图片失败")
  2784. c.Error(500, err, err.Error())
  2785. return
  2786. }
  2787. } else {
  2788. fileName := "./ofile/" + path.Base(url)
  2789. f, _ := os.Create(fileName)
  2790. defer f.Close()
  2791. defer func() {
  2792. os.Remove(fileName)
  2793. }()
  2794. jpeg.Encode(f, imgH, &jpeg.Options{100})
  2795. err = pdf.Image(fileName, (595-W)/2, (840-H)/2, &gopdf.Rect{W: W, H: H})
  2796. if err != nil {
  2797. err = errors.New("写入图片失败")
  2798. c.Error(500, err, err.Error())
  2799. return
  2800. }
  2801. }
  2802. }
  2803. }
  2804. for i := 0; i < pdf.GetNumberOfPages(); i++ {
  2805. }
  2806. filename := "退货出库运输温度记录表" + time.Now().Format("20060102150405") + ".pdf"
  2807. // 保存文件
  2808. if err = pdf.WritePdf("ofile/" + filename); err != nil {
  2809. fmt.Println(err)
  2810. }
  2811. defer func() {
  2812. os.Remove("ofile/" + filename)
  2813. os.Remove(imgPath)
  2814. os.Remove(imgPath2)
  2815. }()
  2816. // 返回生成的 Excel 文件
  2817. c.Ctx.Output.Download("ofile/" + filename)
  2818. }
  2819. // StockRefundOutTransportRecordExport 退货出库运输登记表
  2820. // @Summary 退货出库运输登记表
  2821. // @Description 退货出库运输登记表
  2822. // @Tags 库存
  2823. // @Param body body dto.TransportRecordWordReq true "body"
  2824. // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
  2825. // @Router /stock-template/inventory/list [post]
  2826. // @Security Bearer
  2827. func (c StockTemplateController) StockRefundOutTransportRecordExport() {
  2828. reqData := models.TransportRecord{}
  2829. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  2830. err = errors.New("解析表单数据异常")
  2831. c.Error(global.ParseFormErr, err, err.Error())
  2832. return
  2833. }
  2834. deptId := beegouser.GetDeptId(c.Ctx)
  2835. models.InitBasicData(deptId)
  2836. if reqData.Type == "pdf" {
  2837. c.StockRefundOutTransportRecordPdf(reqData)
  2838. }
  2839. }
  2840. // TransportRecordExport 运输记录表
  2841. // @Summary 收发登记表word
  2842. // @Description 收发登记表word
  2843. // @Tags 库存
  2844. // @Param body body dto.TransportRecordWordReq true "body"
  2845. // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
  2846. // @Router /stock-template/inventory/list [post]
  2847. // @Security Bearer
  2848. func (c StockTemplateController) StockRefundOutTransportRecordExportList() {
  2849. s := services.StockTemplate{}
  2850. reqData := models.TransportRecord{}
  2851. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  2852. err = errors.New("解析表单数据异常")
  2853. c.Error(global.ParseFormErr, err, err.Error())
  2854. return
  2855. }
  2856. deptId := beegouser.GetDeptId(c.Ctx)
  2857. models.InitBasicData(deptId)
  2858. list, err := s.StockRefundOutTransportRecordPdf(&reqData, deptId)
  2859. if err != nil {
  2860. c.Error(500, err, err.Error())
  2861. return
  2862. }
  2863. c.PageOK(list, 0, 0, 0, "查询成功")
  2864. }
  2865. func (c StockTemplateController) GetRefundOutBarCodeInfo() {
  2866. barcodeSvc := services.Barcode{}
  2867. s := services.StockTemplate{}
  2868. //if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  2869. // c.Error(global.ParseFormErr, err, err.Error())
  2870. // return
  2871. //}
  2872. codeStr := c.GetString("code")
  2873. reqData := dto.GetBarCodeInfoReq{Code: codeStr}
  2874. var code models.Barcode
  2875. //数据权限检查
  2876. err := barcodeSvc.Get(&reqData, &code)
  2877. if err != nil {
  2878. c.Error(500, err, err.Error())
  2879. return
  2880. }
  2881. list, err := s.GetRefundOutBarCodeInfo(&code.Data, code.Data.DeptID)
  2882. if err != nil {
  2883. c.Error(500, err, err.Error())
  2884. return
  2885. }
  2886. for _, v := range list {
  2887. v["forwardingUnit"] = code.Data.DeptName
  2888. }
  2889. c.OK(list, "查询成功")
  2890. }
  2891. // StockTemplateInList 入库列表
  2892. // @Summary 入库列表
  2893. // @Description 入库列表
  2894. // @Tags 库存
  2895. // @Param body body dto.StockTemplateInPageReq true "body"
  2896. // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
  2897. // @Router /stock-template/in/list [post]
  2898. // @Security Bearer
  2899. func (c StockTemplateController) StockTemplateRefundInList() {
  2900. s := services.StockTemplate{}
  2901. reqData := dto.StockTemplateInPageReq{}
  2902. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  2903. err = errors.New("解析表单数据异常")
  2904. c.Error(global.ParseFormErr, err, err.Error())
  2905. return
  2906. }
  2907. deptId := beegouser.GetDeptId(c.Ctx)
  2908. list, count, err := s.StockTemplateRefundInList(&reqData, deptId)
  2909. if err != nil {
  2910. c.Error(500, err, err.Error())
  2911. return
  2912. }
  2913. c.PageOK(list, int(count), reqData.GetPageIndex(), reqData.GetPageSize(), "查询成功")
  2914. }
  2915. // StockTemplateOutList 出库列表
  2916. // @Summary 出库列表
  2917. // @Description 出库列表
  2918. // @Tags 库存
  2919. // @Param body body dto.StockTemplateOutPageReq true "body"
  2920. // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
  2921. // @Router /stock-template/out/list [post]
  2922. // @Security Bearer
  2923. func (c StockTemplateController) StockTemplateRefundOutList() {
  2924. s := services.StockTemplate{}
  2925. reqData := dto.StockTemplateOutPageReq{}
  2926. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  2927. err = errors.New("解析表单数据异常")
  2928. c.Error(global.ParseFormErr, err, err.Error())
  2929. return
  2930. }
  2931. deptId := beegouser.GetDeptId(c.Ctx)
  2932. list, count, err := s.StockTemplateRefundOutList(&reqData, deptId)
  2933. if err != nil {
  2934. c.Error(500, err, err.Error())
  2935. return
  2936. }
  2937. c.PageOK(list, int(count), reqData.GetPageIndex(), reqData.GetPageSize(), "查询成功")
  2938. }
  2939. // StockRefundOutExport 退货出库单
  2940. // @Summary 退货出库运输登记表
  2941. // @Description 退货出库运输登记表
  2942. // @Tags 库存
  2943. // @Param body body dto.StockRefundOutExport true "body"
  2944. // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
  2945. // @Router /stock-template/inventory/list [post]
  2946. // @Security Bearer
  2947. func (c StockTemplateController) StockRefundOutExport() {
  2948. reqData := dto.StockRefundOutExport{}
  2949. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  2950. err = errors.New("解析表单数据异常")
  2951. c.Error(global.ParseFormErr, err, err.Error())
  2952. return
  2953. }
  2954. deptId := beegouser.GetDeptId(c.Ctx)
  2955. models.InitBasicData(deptId)
  2956. s := services.StockTemplate{}
  2957. barcodeServ := services.Barcode{}
  2958. list, err := s.StockRefundOutPdf(&reqData, deptId)
  2959. if err != nil {
  2960. c.Error(500, err, err.Error())
  2961. return
  2962. }
  2963. reqData.DeptId = deptId
  2964. reqData.DeptName = beegouser.GetDeptName(c.Ctx)
  2965. code, err := barcodeServ.InsertRefundOut(reqData)
  2966. if err != nil {
  2967. err = errors.New("生成条码失败")
  2968. c.Error(500, err, err.Error())
  2969. return
  2970. }
  2971. cs, _ := code128.Encode(code)
  2972. // 创建一个要输出数据的文件
  2973. imgPath := "ofile/img/" + code + ".png"
  2974. file, _ := os.Create(imgPath)
  2975. defer file.Close()
  2976. // 设置图片像素大小
  2977. qrCode, _ := barcode.Scale(cs, 205, 50)
  2978. // 将code128的条形码编码为png图片
  2979. png.Encode(file, qrCode)
  2980. cols := []float64{160, 140, 45, 70, 70, 105, 105, 105}
  2981. header := []string{"品种", "生产企业", "单位", "单价", "数量", "金额", "批号", "有效期"}
  2982. rows := [][]string{}
  2983. var totalMoney float64
  2984. for _, row := range list {
  2985. temp := []string{}
  2986. product := utils.ToString(row[models.FieldProductName])
  2987. enterprise := utils.ToString(row[models.FieldEnterpriseName])
  2988. batchNumber := utils.ToString(row[models.FieldBatchNumber])
  2989. temp = append(temp, product)
  2990. temp = append(temp, fmt.Sprintf("%s", enterprise))
  2991. temp = append(temp, utils.ToString(row[models.FieldUnitName]))
  2992. temp = append(temp, fmt.Sprintf("%.01f", utils.ToFloat64(row["unit_price"])))
  2993. temp = append(temp, fmt.Sprintf("%d", utils.ToInt(row["quantity"])))
  2994. temp = append(temp, fmt.Sprintf("%.01f", utils.ToFloat64(row["money"])))
  2995. temp = append(temp, batchNumber)
  2996. temp = append(temp, utils.ToString(row[models.FieldExpiryDate]))
  2997. rows = append(rows, temp)
  2998. totalMoney += utils.ToFloat64(row["money"])
  2999. }
  3000. pdf := &gopdf.GoPdf{}
  3001. pdf.Start(gopdf.Config{PageSize: gopdf.Rect{W: 841.89, H: 595.28}})
  3002. pdf.SetMarginTop(40)
  3003. pdf.SetMarginBottom(40)
  3004. pdf.AddPage()
  3005. pdf.AddTTFFont("simsun", "static/fonts/MiSans-Medium.ttf")
  3006. pdf.SetMargins(2, 5, 5, 5)
  3007. pdf.SetFont("simsun", "", 12)
  3008. //pdf.SetX(20)
  3009. //pdf.SetY(20)
  3010. //pdf.Text("[退货出库]")
  3011. pdf.SetX(668)
  3012. pdf.SetY(60)
  3013. pdf.Text(code)
  3014. imgPath2 := "ofile/img/" + code + ".jpg"
  3015. png2j.Con2jpg(imgPath, imgPath2)
  3016. pdf.Image(imgPath2, 640, 15, &gopdf.Rect{W: 200, H: 35})
  3017. titleStr := reqData.DeptName + "退货单"
  3018. pdf.SetFont("simsun", "", 25)
  3019. textw, _ := pdf.MeasureTextWidth(titleStr)
  3020. pdf.SetX((840 / 2) - (textw / 2))
  3021. pdf.SetY(40)
  3022. pdf.Text(titleStr)
  3023. pdf.SetFont("simsun", "", 12)
  3024. // 第一行
  3025. curx, y := 30., pdf.GetY()
  3026. y += 40
  3027. pdf.SetXY(curx, y)
  3028. pdf.Text("开票日期:" + time.Now().Format("2006-01-02"))
  3029. // 第二行
  3030. curx, y = 30., pdf.GetY()
  3031. y += 20
  3032. pdf.SetXY(curx, y)
  3033. pdf.Text("退货原因:" + reqData.Reason)
  3034. curx = 20
  3035. y += 10
  3036. pdf.SetXY(curx, y)
  3037. h := 20.0
  3038. x := curx
  3039. pdf.SetFont("simsun", "", 10)
  3040. for i := 0; i < len(header); i++ {
  3041. utils.RectFillColorMultiCell(pdf, header[i], 9, x, y, cols[i], h, 0, 0, 0, gopdf.Center, gopdf.Middle)
  3042. x += cols[i]
  3043. }
  3044. y += h
  3045. pdf.SetXY(curx, y)
  3046. pdf.SetFont("simsun", "", 10)
  3047. for _, row := range rows {
  3048. curx, y = pdf.GetX(), pdf.GetY()
  3049. x = curx
  3050. height := h
  3051. for i, txt := range row {
  3052. lineTexts, _ := pdf.SplitText(txt, cols[i])
  3053. //lineHt := h * float64(len(lineTexts))
  3054. if len(lineTexts) > 1 {
  3055. lineTexts, _ = pdf.SplitText(txt, cols[i]-4)
  3056. lineHt := h * float64(len(lineTexts)) * 0.6
  3057. if lineHt > height {
  3058. height = lineHt
  3059. }
  3060. }
  3061. }
  3062. for i, txt := range row {
  3063. width := cols[i]
  3064. utils.RectFillColorMultiCell(pdf, txt, 9, x, y, width, height, 0, 0, 0, gopdf.Center, gopdf.Middle)
  3065. x += width
  3066. }
  3067. pdf.SetNewY(y+height, height)
  3068. pdf.SetX(curx)
  3069. }
  3070. curx, y = pdf.GetX(), pdf.GetY()
  3071. x = curx
  3072. cols2 := []float64{160, 140, 45, 70, 70, 105, 210}
  3073. row2 := []string{"", "", "", "", "合计:", fmt.Sprintf("%.02f", totalMoney), utils.AmountConvert(totalMoney, true)}
  3074. for i, txt := range row2 {
  3075. width := cols2[i]
  3076. utils.RectFillColorMultiCell(pdf, txt, 9, x, y, width, h, 0, 0, 0, gopdf.Center, gopdf.Middle)
  3077. x += width
  3078. }
  3079. pdf.SetFont("simsun", "", 12)
  3080. // 第一行
  3081. curx, y = 30., pdf.GetY()
  3082. y += 25
  3083. pdf.SetXY(curx, y)
  3084. pdf.Text("制 单 人:" + beegouser.GetUserName(c.Ctx))
  3085. curx = 265
  3086. pdf.SetXY(curx, y)
  3087. pdf.Text("经 办 人:")
  3088. curx = 565
  3089. pdf.SetXY(curx, y)
  3090. pdf.Text("科室负责人:")
  3091. // 第二行
  3092. curx, y = 30., pdf.GetY()
  3093. y += 30
  3094. pdf.SetXY(curx, y)
  3095. pdf.Text("分管主任:")
  3096. curx = 265
  3097. pdf.SetXY(curx, y)
  3098. pdf.Text("财务部负责人:")
  3099. curx = 565
  3100. pdf.SetXY(curx, y)
  3101. pdf.Text("单位负责人:")
  3102. filename := titleStr + time.Now().Format("20060102150405") + ".pdf"
  3103. // 保存文件
  3104. if err = pdf.WritePdf("ofile/" + filename); err != nil {
  3105. fmt.Println(err)
  3106. }
  3107. defer func() {
  3108. os.Remove("ofile/" + filename)
  3109. }()
  3110. // 返回生成的 Excel 文件
  3111. c.Ctx.Output.Download("ofile/" + filename)
  3112. }
  3113. // StockScrapOutExport 报废出库单
  3114. // @Summary 报废出库单
  3115. // @Description 报废出库单
  3116. // @Tags 库存
  3117. // @Param body body dto.StockRefundOutExport true "body"
  3118. // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
  3119. // @Router /stock-template/inventory/list [post]
  3120. // @Security Bearer
  3121. func (c StockTemplateController) StockScrapOutExport() {
  3122. reqData := dto.StockRefundOutExport{}
  3123. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  3124. err = errors.New("解析表单数据异常")
  3125. c.Error(global.ParseFormErr, err, err.Error())
  3126. return
  3127. }
  3128. deptId := beegouser.GetDeptId(c.Ctx)
  3129. models.InitBasicData(deptId)
  3130. s := services.StockTemplate{}
  3131. list, err := s.StockRefundOutPdf(&reqData, deptId)
  3132. if err != nil {
  3133. c.Error(500, err, err.Error())
  3134. return
  3135. }
  3136. reqData.DeptId = deptId
  3137. reqData.DeptName = beegouser.GetDeptName(c.Ctx)
  3138. cols := []float64{160, 140, 45, 70, 70, 105, 105, 105}
  3139. header := []string{"品种", "生产企业", "单位", "单价", "数量", "金额", "批号", "有效期"}
  3140. rows := [][]string{}
  3141. var totalMoney float64
  3142. for _, row := range list {
  3143. temp := []string{}
  3144. product := utils.ToString(row[models.FieldProductName])
  3145. enterprise := utils.ToString(row[models.FieldEnterpriseName])
  3146. batchNumber := utils.ToString(row[models.FieldBatchNumber])
  3147. temp = append(temp, product)
  3148. temp = append(temp, fmt.Sprintf("%s", enterprise))
  3149. temp = append(temp, utils.ToString(row[models.FieldUnitName]))
  3150. temp = append(temp, fmt.Sprintf("%.01f", utils.ToFloat64(row["unit_price"])))
  3151. temp = append(temp, fmt.Sprintf("%d", utils.ToInt(row["quantity"])))
  3152. temp = append(temp, fmt.Sprintf("%.01f", utils.ToFloat64(row["money"])))
  3153. temp = append(temp, batchNumber)
  3154. temp = append(temp, utils.ToString(row[models.FieldExpiryDate]))
  3155. rows = append(rows, temp)
  3156. totalMoney += utils.ToFloat64(row["money"])
  3157. }
  3158. pdf := &gopdf.GoPdf{}
  3159. pdf.Start(gopdf.Config{PageSize: gopdf.Rect{W: 841.89, H: 595.28}})
  3160. pdf.SetMarginTop(40)
  3161. pdf.SetMarginBottom(40)
  3162. pdf.AddPage()
  3163. pdf.AddTTFFont("simsun", "static/fonts/MiSans-Medium.ttf")
  3164. pdf.SetMargins(2, 5, 5, 5)
  3165. pdf.SetFont("simsun", "", 12)
  3166. titleStr := reqData.DeptName + "报废出库单"
  3167. pdf.SetFont("simsun", "", 25)
  3168. textw, _ := pdf.MeasureTextWidth(titleStr)
  3169. pdf.SetX((840 / 2) - (textw / 2))
  3170. pdf.SetY(40)
  3171. pdf.Text(titleStr)
  3172. pdf.SetFont("simsun", "", 12)
  3173. // 第一行
  3174. curx, y := 30., pdf.GetY()
  3175. y += 40
  3176. pdf.SetXY(curx, y)
  3177. pdf.Text("开票日期:" + time.Now().Format("2006-01-02"))
  3178. // 第二行
  3179. curx, y = 30., pdf.GetY()
  3180. y += 20
  3181. pdf.SetXY(curx, y)
  3182. pdf.Text("报废原因:" + reqData.Reason)
  3183. curx = 20
  3184. y += 10
  3185. pdf.SetXY(curx, y)
  3186. h := 20.0
  3187. x := curx
  3188. pdf.SetFont("simsun", "", 10)
  3189. for i := 0; i < len(header); i++ {
  3190. utils.RectFillColorMultiCell(pdf, header[i], 9, x, y, cols[i], h, 0, 0, 0, gopdf.Center, gopdf.Middle)
  3191. x += cols[i]
  3192. }
  3193. y += h
  3194. pdf.SetXY(curx, y)
  3195. pdf.SetFont("simsun", "", 10)
  3196. for _, row := range rows {
  3197. curx, y = pdf.GetX(), pdf.GetY()
  3198. x = curx
  3199. height := h
  3200. for i, txt := range row {
  3201. lineTexts, _ := pdf.SplitText(txt, cols[i])
  3202. //lineHt := h * float64(len(lineTexts))
  3203. if len(lineTexts) > 1 {
  3204. lineTexts, _ = pdf.SplitText(txt, cols[i]-4)
  3205. lineHt := h * float64(len(lineTexts)) * 0.6
  3206. if lineHt > height {
  3207. height = lineHt
  3208. }
  3209. }
  3210. }
  3211. for i, txt := range row {
  3212. width := cols[i]
  3213. utils.RectFillColorMultiCell(pdf, txt, 9, x, y, width, height, 0, 0, 0, gopdf.Center, gopdf.Middle)
  3214. x += width
  3215. }
  3216. pdf.SetNewY(y+height, height)
  3217. pdf.SetX(curx)
  3218. }
  3219. curx, y = pdf.GetX(), pdf.GetY()
  3220. x = curx
  3221. cols2 := []float64{160, 140, 45, 70, 70, 105, 210}
  3222. row2 := []string{"", "", "", "", "合计:", fmt.Sprintf("%.02f", totalMoney), utils.AmountConvert(totalMoney, true)}
  3223. for i, txt := range row2 {
  3224. width := cols2[i]
  3225. utils.RectFillColorMultiCell(pdf, txt, 9, x, y, width, h, 0, 0, 0, gopdf.Center, gopdf.Middle)
  3226. x += width
  3227. }
  3228. pdf.SetFont("simsun", "", 12)
  3229. // 第一行
  3230. curx, y = 30., pdf.GetY()
  3231. y += 25
  3232. pdf.SetXY(curx, y)
  3233. pdf.Text("制 单 人:" + beegouser.GetUserName(c.Ctx))
  3234. curx = 265
  3235. pdf.SetXY(curx, y)
  3236. pdf.Text("经 办 人:")
  3237. curx = 565
  3238. pdf.SetXY(curx, y)
  3239. pdf.Text("科室负责人:")
  3240. // 第二行
  3241. curx, y = 30., pdf.GetY()
  3242. y += 30
  3243. pdf.SetXY(curx, y)
  3244. pdf.Text("分管主任:")
  3245. curx = 265
  3246. pdf.SetXY(curx, y)
  3247. pdf.Text("财务部负责人:")
  3248. curx = 565
  3249. pdf.SetXY(curx, y)
  3250. pdf.Text("单位负责人:")
  3251. filename := titleStr + time.Now().Format("20060102150405") + ".pdf"
  3252. // 保存文件
  3253. if err = pdf.WritePdf("ofile/" + filename); err != nil {
  3254. fmt.Println(err)
  3255. }
  3256. defer func() {
  3257. os.Remove("ofile/" + filename)
  3258. }()
  3259. // 返回生成的 Excel 文件
  3260. c.Ctx.Output.Download("ofile/" + filename)
  3261. }
  3262. // TransportRecordExport 运输记录表
  3263. // @Summary 收发登记表word
  3264. // @Description 收发登记表word
  3265. // @Tags 库存
  3266. // @Param body body dto.TransportRecordWordReq true "body"
  3267. // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
  3268. // @Router /stock-template/inventory/list [post]
  3269. // @Security Bearer
  3270. func (c StockTemplateController) StockOutExport() {
  3271. reqData := models.TransportRecord{}
  3272. if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
  3273. err = errors.New("解析表单数据异常")
  3274. c.Error(global.ParseFormErr, err, err.Error())
  3275. return
  3276. }
  3277. deptId := beegouser.GetDeptId(c.Ctx)
  3278. models.InitBasicData(deptId)
  3279. s := services.StockTemplate{}
  3280. barcodeServ := services.Barcode{}
  3281. list, err := s.StockTemplateTransportRecordWord(&reqData, deptId)
  3282. if err != nil {
  3283. c.Error(500, err, err.Error())
  3284. return
  3285. }
  3286. transportRecordWordMap := make(map[string][]map[string]interface{})
  3287. for _, row := range list {
  3288. receiving_unit := utils.ToString(row["receiving_unit"])
  3289. if _, ok := transportRecordWordMap[receiving_unit]; !ok {
  3290. list2 := make([]map[string]interface{}, 0)
  3291. list2 = append(list2, row)
  3292. transportRecordWordMap[receiving_unit] = list2
  3293. }else {
  3294. transportRecordWordMap[receiving_unit] = append(transportRecordWordMap[receiving_unit], row)
  3295. }
  3296. }
  3297. reqData.DeptID = deptId
  3298. reqData.DeptName = beegouser.GetDeptName(c.Ctx)
  3299. reqData.SetCreateBy(beegouser.GetUserId(c.Ctx))
  3300. reqData.SetDeptId(deptId)
  3301. pdf := &gopdf.GoPdf{}
  3302. pdf.Start(gopdf.Config{PageSize: gopdf.Rect{W: 595.28, H: 841.89}})
  3303. pdf.SetMarginTop(40)
  3304. pdf.SetMarginBottom(40)
  3305. titleStr := reqData.DeptName + "出库单"
  3306. for receiving_unit, list3 := range transportRecordWordMap {
  3307. reqData.ReceivingUnit = receiving_unit
  3308. var code string
  3309. code, err = barcodeServ.Insert(reqData)
  3310. if err != nil {
  3311. err = errors.New("生成条码失败")
  3312. c.Error(500, err, err.Error())
  3313. return
  3314. }
  3315. cs, _ := code128.Encode(code)
  3316. // 创建一个要输出数据的文件
  3317. imgPath := "ofile/img/" + code + ".png"
  3318. file, _ := os.Create(imgPath)
  3319. defer file.Close()
  3320. // 设置图片像素大小
  3321. qrCode, _ := barcode.Scale(cs, 205, 50)
  3322. // 将code128的条形码编码为png图片
  3323. png.Encode(file, qrCode)
  3324. cols := []float64{100, 80, 85, 70, 70, 30, 35, 35, 50}
  3325. header := []string{"品种", "生产企业", "规格", "批号", "有效期", "单位", "数量", "单价", "总价"}
  3326. rows := [][]string{}
  3327. var totalMoney float64
  3328. var totalQuantity int
  3329. for _, row := range list3 {
  3330. temp := []string{}
  3331. product := utils.ToString(row[models.FieldProductName])
  3332. enterprise := utils.ToString(row[models.FieldEnterpriseName])
  3333. spec := utils.ToString(row[models.FieldSpecName])
  3334. batchNumber := utils.ToString(row[models.FieldBatchNumber])
  3335. temp = append(temp, product)
  3336. temp = append(temp, fmt.Sprintf("%s", enterprise))
  3337. temp = append(temp, spec)
  3338. temp = append(temp, batchNumber)
  3339. temp = append(temp, utils.ToString(row[models.FieldExpiryDate]))
  3340. temp = append(temp, utils.ToString(row[models.FieldUnitName]))
  3341. temp = append(temp, fmt.Sprintf("%d", utils.ToInt(row["quantity"])))
  3342. temp = append(temp, fmt.Sprintf("%.01f", utils.ToFloat64(row["unit_price"])))
  3343. temp = append(temp, fmt.Sprintf("%.01f", utils.ToFloat64(row["money"])))
  3344. totalMoney += utils.ToFloat64(row["money"])
  3345. totalQuantity += utils.ToInt(row["quantity"])
  3346. rows = append(rows, temp)
  3347. }
  3348. pdf.AddPage()
  3349. pdf.AddTTFFont("simsun", "static/fonts/MiSans-Medium.ttf")
  3350. pdf.SetMargins(2, 5, 5, 5)
  3351. pdf.SetFont("simsun", "", 10)
  3352. //pdf.SetX(20)
  3353. //pdf.SetY(20)
  3354. //pdf.Text("[退货出库]")
  3355. pdf.SetX(420)
  3356. pdf.SetY(60)
  3357. pdf.Text(code)
  3358. imgPath2 := "ofile/img/" + code + ".jpg"
  3359. png2j.Con2jpg(imgPath, imgPath2)
  3360. pdf.Image(imgPath2, 390, 15, &gopdf.Rect{W: 200, H: 35})
  3361. defer func() {
  3362. os.Remove(imgPath)
  3363. os.Remove(imgPath2)
  3364. }()
  3365. pdf.SetFont("simsun", "", 22)
  3366. textw, _ := pdf.MeasureTextWidth(titleStr)
  3367. pdf.SetX((595 / 2) - (textw / 2) - 50)
  3368. pdf.SetY(40)
  3369. pdf.Text(titleStr)
  3370. pdf.SetFont("simsun", "", 10)
  3371. // 第一行
  3372. curx, y := 20., pdf.GetY()
  3373. y += 60
  3374. pdf.SetXY(curx, y)
  3375. pdf.Text("收货单位:" + reqData.ReceivingUnit)
  3376. curx = 220
  3377. pdf.SetXY(curx, y)
  3378. pdf.Text("收货人/电话:")
  3379. curx = 330
  3380. pdf.SetXY(curx, y)
  3381. pdf.Text("日期:" + reqData.Date)
  3382. curx = 430
  3383. pdf.SetXY(curx, y)
  3384. pdf.Text("单据:" + code)
  3385. curx = 20
  3386. y += 10
  3387. pdf.SetXY(curx, y)
  3388. h := 20.0
  3389. x := curx
  3390. pdf.SetFont("simsun", "", 9)
  3391. for i := 0; i < len(header); i++ {
  3392. utils.RectFillColorMultiCell(pdf, header[i], 9, x, y, cols[i], h, 0, 0, 0, gopdf.Center, gopdf.Middle)
  3393. x += cols[i]
  3394. }
  3395. y += h
  3396. pdf.SetXY(curx, y)
  3397. pdf.SetFont("simsun", "", 8)
  3398. for _, row := range rows {
  3399. curx, y = pdf.GetX(), pdf.GetY()
  3400. x = curx
  3401. height := h
  3402. for i, txt := range row {
  3403. lineTexts, _ := pdf.SplitText(txt, cols[i])
  3404. //lineHt := h * float64(len(lineTexts))
  3405. if len(lineTexts) > 1 {
  3406. lineTexts, _ = pdf.SplitText(txt, cols[i]-4)
  3407. lineHt := h * float64(len(lineTexts)) * 0.6
  3408. if lineHt > height {
  3409. height = lineHt
  3410. }
  3411. }
  3412. }
  3413. for i, txt := range row {
  3414. width := cols[i]
  3415. utils.RectFillColorMultiCell(pdf, txt, 9, x, y, width, height, 0, 0, 0, gopdf.Center, gopdf.Middle)
  3416. x += width
  3417. }
  3418. pdf.SetNewY(y+height, height)
  3419. pdf.SetX(curx)
  3420. }
  3421. curx, y = 20, pdf.GetY()
  3422. x = curx
  3423. if pdf.GetY() < 30 {
  3424. pdf.SetY(30)
  3425. }
  3426. rows2 := []string{"金额(大写)", utils.AmountConvert(totalMoney, true), fmt.Sprintf("%.1f", totalMoney)}
  3427. cols2 := [3]float64{}
  3428. cols2[0] = cols[0]
  3429. cols2[1] = cols[1] + cols[2] + cols[3]
  3430. cols2[2] = cols[4] + cols[5] + cols[6] + cols[7] + cols[8]
  3431. for i, txt := range rows2 {
  3432. width := cols2[i]
  3433. utils.RectFillColorMultiCell(pdf, txt, 9, x, y, width, h, 0, 0, 0, gopdf.Center, gopdf.Middle)
  3434. x += width
  3435. }
  3436. pdf.SetNewY(y, 20)
  3437. pdf.SetX(curx)
  3438. curx, y = 20, pdf.GetY()
  3439. y += 20
  3440. x = curx
  3441. if pdf.GetY() < 30 {
  3442. pdf.SetY(30)
  3443. }
  3444. rows3 := []string{"数量", fmt.Sprintf("%d", totalQuantity)}
  3445. cols3 := [2]float64{}
  3446. cols3[0] = cols[0]
  3447. cols3[1] = cols[1] + cols[2] + cols[3] + cols[4] + cols[5] + cols[6] + cols[7] + cols[8]
  3448. for i, txt := range rows3 {
  3449. width := cols3[i]
  3450. utils.RectFillColorMultiCell(pdf, txt, 9, x, y, width, h, 0, 0, 0, gopdf.Center, gopdf.Middle)
  3451. x += width
  3452. }
  3453. pdf.SetNewY(y, 20)
  3454. pdf.SetX(curx)
  3455. curx, y = 20, pdf.GetY()
  3456. y += 20
  3457. x = curx
  3458. if pdf.GetY() < 30 {
  3459. pdf.SetY(30)
  3460. }
  3461. rows4 := []string{"备注:"}
  3462. cols4 := [1]float64{}
  3463. cols4[0] = cols[0] + cols[1] + cols[2] + cols[3] + cols[4] + cols[5] + cols[6] + cols[7] + cols[8]
  3464. for i, txt := range rows4 {
  3465. width := cols4[i]
  3466. utils.RectFillColorMultiCell(pdf, txt, 9, x, y, width, h, 0, 0, 0, gopdf.Left, gopdf.Middle)
  3467. x += width
  3468. }
  3469. pdf.SetNewY(y, 20)
  3470. if pdf.GetY() < 30 {
  3471. pdf.SetY(30)
  3472. }
  3473. y = pdf.GetY()
  3474. pdf.SetX(curx)
  3475. y += 40
  3476. pdf.SetFont("simsun", "", 10)
  3477. curx = 40
  3478. pdf.SetXY(curx, y)
  3479. pdf.Text("主管:")
  3480. curx = 200
  3481. pdf.SetXY(curx, y)
  3482. pdf.Text("制单:")
  3483. curx = 400
  3484. pdf.SetXY(curx, y)
  3485. pdf.Text("库管:")
  3486. }
  3487. filename := titleStr + time.Now().Format("20060102150405") + ".pdf"
  3488. // 保存文件
  3489. if err = pdf.WritePdf("ofile/" + filename); err != nil {
  3490. fmt.Println(err)
  3491. }
  3492. defer func() {
  3493. os.Remove("ofile/" + filename)
  3494. }()
  3495. // 返回生成的 Excel 文件
  3496. c.Ctx.Output.Download("ofile/" + filename)
  3497. }