stock_template.go 116 KB

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