FinancialController.cs 146 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355
  1. using Aspose.Cells;
  2. using Microsoft.AspNetCore.Http;
  3. using Microsoft.AspNetCore.Mvc;
  4. using OASystem.API.OAMethodLib;
  5. using OASystem.API.OAMethodLib.File;
  6. using OASystem.Domain;
  7. using OASystem.Domain.Dtos.Financial;
  8. using OASystem.Domain.Dtos.Groups;
  9. using OASystem.Domain.Entities.Financial;
  10. using OASystem.Domain.Entities.Groups;
  11. using OASystem.Domain.ViewModels.Financial;
  12. using OASystem.Domain.ViewModels.Groups;
  13. using OASystem.Domain.ViewModels.SmallFun;
  14. using OASystem.Infrastructure.Repositories.Financial;
  15. using OASystem.Infrastructure.Repositories.Groups;
  16. using SqlSugar;
  17. using StackExchange.Redis;
  18. using System.Data;
  19. using static OpenAI.GPT3.ObjectModels.SharedModels.IOpenAiModels;
  20. using System.Web;
  21. using Aspose.Words;
  22. using NPOI.HSSF.Util;
  23. using OASystem.Domain.Entities.Customer;
  24. using System.IO.Compression;
  25. using NPOI.SS.UserModel;
  26. using System.Net.Http;
  27. using Google.Protobuf;
  28. using NPOI.SS.Formula.Functions;
  29. using System.Globalization;
  30. using NPOI.POIFS.Properties;
  31. using SixLabors.ImageSharp.ColorSpaces;
  32. using OASystem.Domain.ViewModels.QiYeWeChat;
  33. using System.Diagnostics;
  34. using System.Security.Cryptography;
  35. namespace OASystem.API.Controllers
  36. {
  37. /// <summary>
  38. /// 财务模块
  39. /// </summary>
  40. [Route("api/[controller]/[action]")]
  41. [ApiController]
  42. public class FinancialController : ControllerBase
  43. {
  44. private readonly IMapper _mapper;
  45. private readonly IConfiguration _config;
  46. private readonly SqlSugarClient _sqlSugar;
  47. private readonly HttpClient _httpClient;
  48. private readonly SetDataTypeRepository _setDataTypeRep;
  49. private readonly SetDataRepository _setDataRep;
  50. private readonly DailyFeePaymentRepository _daiRep; //日付申请仓库
  51. private readonly TeamRateRepository _teamRateRep; //团组汇率仓库
  52. private readonly ForeignReceivablesRepository _ForForeignReceivablesRep; //对外收款账单仓库
  53. private readonly ProceedsReceivedRepository _proceedsReceivedRep; //已收款项仓库
  54. private readonly PaymentRefundAndOtherMoneyRepository _paymentRefundAndOtherMoneyRep; //收款退还与其他款项 仓库
  55. private readonly DelegationInfoRepository _delegationInfoRep; //团组信息 仓库
  56. /// <summary>
  57. /// 初始化
  58. /// </summary>
  59. public FinancialController(IMapper mapper, IConfiguration configuration, DailyFeePaymentRepository daiRep, SqlSugarClient sqlSugar, SetDataTypeRepository setDataTypeRep,
  60. TeamRateRepository teamRateRep, ForeignReceivablesRepository ForForeignReceivablesRep, ProceedsReceivedRepository proceedsReceivedRep,
  61. PaymentRefundAndOtherMoneyRepository paymentRefundAndOtherMoneyRep, HttpClient httpClient, DelegationInfoRepository delegationInfoRep)
  62. {
  63. _mapper = mapper;
  64. _config = configuration;
  65. _daiRep = daiRep;
  66. _sqlSugar = sqlSugar;
  67. _setDataTypeRep = setDataTypeRep;
  68. _teamRateRep = teamRateRep;
  69. _ForForeignReceivablesRep = ForForeignReceivablesRep;
  70. _proceedsReceivedRep = proceedsReceivedRep;
  71. _paymentRefundAndOtherMoneyRep = paymentRefundAndOtherMoneyRep;
  72. _httpClient = httpClient;
  73. _delegationInfoRep = delegationInfoRep;
  74. }
  75. #region 日付申请
  76. /// <summary>
  77. /// 获取日付申请 基础数据源
  78. /// </summary>
  79. /// <param name="dto"> 日付申请 分页 dto</param>
  80. /// <returns></returns>
  81. [HttpPost]
  82. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  83. public async Task<IActionResult> PostPageSearchDailyPaymentPriceTypeData(PortDtoBase dto)
  84. {
  85. var result = await _daiRep.GetPagePriceTypeData(dto);
  86. if (result == null || result.Code != 0)
  87. {
  88. return Ok(JsonView(false, result.Msg));
  89. }
  90. var data = result.Data;
  91. return Ok(JsonView(data));
  92. }
  93. /// <summary>
  94. /// 获取日付申请 基础数据源 - 转账表识
  95. /// </summary>
  96. /// <param name="dto"> 日付申请 分页 dto</param>
  97. /// <returns></returns>
  98. [HttpPost]
  99. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  100. public async Task<IActionResult> GetSearchDailyPaymentPriceTypeAddData(PortDtoBase dto)
  101. {
  102. var result = await _daiRep.GetPriceTypeAddData(dto);
  103. if (result == null || result.Code != 0)
  104. {
  105. return Ok(JsonView(false, result.Msg));
  106. }
  107. var data = result.Data;
  108. return Ok(JsonView(data));
  109. }
  110. /// <summary>
  111. /// 日付申请 Page Search
  112. /// </summary>
  113. /// <param name="dto"> 日付申请 分页 dto</param>
  114. /// <returns></returns>
  115. [HttpPost]
  116. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  117. public async Task<IActionResult> PostPageSearchDailyPaymentList(PageDailyFeePaymentDto dto)
  118. {
  119. var result = await _daiRep.GetPageSearchAll(dto);
  120. if (result == null || result.Code != 0)
  121. {
  122. return Ok(JsonView(false, result.Msg));
  123. }
  124. var data = result.Data;
  125. if (data == null)
  126. {
  127. return Ok(JsonView(false, result.Msg));
  128. }
  129. return Ok(JsonView(data));
  130. }
  131. /// <summary>
  132. /// 日付申请 Single Search By Id
  133. /// </summary>
  134. /// <param name="dto"></param>
  135. /// <returns></returns>
  136. [HttpPost]
  137. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  138. public async Task<IActionResult> PostSearchDailyPaymentInfo(SearchDailyFeePaymentDto dto)
  139. {
  140. var result = await _daiRep.GetSearchById(dto);
  141. if (result == null || result.Code != 0)
  142. {
  143. return Ok(JsonView(false, result.Msg));
  144. }
  145. return Ok(JsonView(result.Data));
  146. }
  147. /// <summary>
  148. /// 日付申请 添加
  149. /// </summary>
  150. /// <param name="dto"> 日付申请 添加 dto</param>
  151. /// <returns></returns>
  152. [HttpPost]
  153. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  154. public async Task<IActionResult> PostAddDailyPayment(AddDailyFeePaymentDto dto)
  155. {
  156. var result = await _daiRep.Add(dto);
  157. if (result == null || result.Code != 0)
  158. {
  159. return Ok(JsonView(false, result.Msg));
  160. }
  161. return Ok(JsonView(true));
  162. }
  163. /// <summary>
  164. /// 日付申请 Update
  165. /// </summary>
  166. /// <param name="dto"> 日付申请 修改 dto</param>
  167. /// <returns></returns>
  168. [HttpPost]
  169. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  170. public async Task<IActionResult> PostEditDailyPayment(EditDailyFeePaymentDto dto)
  171. {
  172. var result = await _daiRep.Edit(dto);
  173. if (result == null || result.Code != 0)
  174. {
  175. return Ok(JsonView(false, result.Msg));
  176. }
  177. return Ok(JsonView(true));
  178. }
  179. /// <summary>
  180. /// 日付申请 Del
  181. /// </summary>
  182. /// <param name="dto"> 日付申请 删除 dto</param>
  183. /// <returns></returns>
  184. [HttpPost]
  185. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  186. public async Task<IActionResult> PostDelDailyPayment(DelDailyFeePaymentDto dto)
  187. {
  188. var result = await _daiRep.Del(dto);
  189. if (result == null || result.Code != 0)
  190. {
  191. return Ok(JsonView(false, result.Msg));
  192. }
  193. return Ok(JsonView(true));
  194. }
  195. /// <summary>
  196. /// 日付申请 财务审核
  197. /// </summary>
  198. /// <param name="dto"> dto </param>
  199. /// <returns></returns>
  200. [HttpPost]
  201. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  202. public async Task<IActionResult> PostDelDailyPaymentAudit(DP_AuditStatusDto dto)
  203. {
  204. var result = await _daiRep.DelDailyPaymentAudit(dto);
  205. if (result == null || result.Code != 0)
  206. {
  207. return Ok(JsonView(false, result.Msg));
  208. }
  209. return Ok(JsonView(true));
  210. }
  211. /// <summary>
  212. /// 日付申请 Single Excel Download
  213. /// </summary>
  214. /// <param name="dto"> dto </param>
  215. /// <returns></returns>
  216. [HttpPost]
  217. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  218. public async Task<IActionResult> PostExcelDailyPaymentDownload(SearchDailyFeePaymentDto dto)
  219. {
  220. if (dto.PortType == 1 || dto.PortType == 2)
  221. {
  222. Fin_DailyFeePaymentInfolView feeData = new Fin_DailyFeePaymentInfolView();
  223. string feeSql = string.Format(@"Select * From Fin_DailyFeePayment
  224. Where IsDel=0 And Id = {0} ", dto.Id);
  225. feeData = await _sqlSugar.SqlQueryable<Fin_DailyFeePaymentInfolView>(feeSql).FirstAsync();
  226. if (feeData == null)
  227. {
  228. return Ok(JsonView(false, "暂无数据!"));
  229. }
  230. string feeContentSql = string.Format(@"Select * From Fin_DailyFeePaymentContent
  231. Where IsDel=0 And DFPId = {0} ", dto.Id);
  232. feeData.FeeContents = await _sqlSugar.SqlQueryable<Fin_DailyFeePaymentContentInfolView>(feeContentSql).ToListAsync();
  233. if (feeData != null)
  234. {
  235. string userName = string.Empty;
  236. string userSql = string.Format("Select * From Sys_Users Where Id={0} And Isdel = {1}", feeData.CreateUserId, 0);
  237. Sys_Users user = await _sqlSugar.SqlQueryable<Sys_Users>(userSql).FirstAsync();
  238. if (user != null) { userName = user.CnName; }
  239. var setData = _setDataTypeRep.QueryDto<Sys_SetData, Fin_DailyFeePaymentPagePriceSubTypeView>().ToList();
  240. //48人员费用 49办公费用 50 销售费用 51 其他费用 55 大运会
  241. var priceSubTypeData = setData.Where(s => s.STid == 55).ToList();
  242. Dictionary<string, object> pairs = new Dictionary<string, object>();
  243. List<DataTable> datas = new List<DataTable>();
  244. //if (priceSubTypeData.Where(s => s.Id == feeData.PriceTypeId).ToList().Count() > 0)//大运会专属模板
  245. //{
  246. // //AsposeHelper.ExpertExcelToModel("日常费用付款申请模板-大运会数据.xls", "DailyPayment", "大运会所有日常费用付款申请.xls",
  247. // // pairs, datas);
  248. //}
  249. //else //日付常规模板
  250. //{
  251. pairs.Clear();
  252. pairs.Add("Opertor", userName);
  253. pairs.Add("DateTime", feeData.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"));
  254. pairs.Add("FAuditStatus", feeData.FAuditDesc);
  255. pairs.Add("MAuditStatus", feeData.MAuditDesc);
  256. pairs.Add("SumPrice", feeData.SumPrice);
  257. DataTable data = AsposeHelper.ListToDataTable("DailyFeePayment", feeData.FeeContents);
  258. datas.Clear();
  259. datas.Add(data);
  260. string fileName = string.Format("{0}-日常费用付款申请.xlsx", feeData.Instructions);
  261. string msg = AsposeHelper.ExpertExcelToModel("日常费用付款申请模板.xlsx", "DailyPayment", fileName, pairs, datas);
  262. return Ok(JsonView(true, msg));
  263. //}
  264. }
  265. else
  266. {
  267. return Ok(JsonView(false, "暂无数据!"));
  268. }
  269. }
  270. return Ok(JsonView(true));
  271. }
  272. #endregion
  273. #region 团组提成
  274. /// <summary>
  275. /// 提成 Page Search
  276. /// </summary>
  277. /// <param name="dto"> 提成 分页 dto</param>
  278. /// <returns></returns>
  279. [HttpPost]
  280. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  281. public async Task<IActionResult> PostPageSearchCommissionList(GroupCommissionDto dto)
  282. {
  283. var data = await GroupCommission.GetCommissionPageList(dto);
  284. return Ok(JsonView(data.Data));
  285. }
  286. #endregion
  287. #region 团组汇率
  288. /// <summary>
  289. /// 团组汇率 Select数据源(团组列,汇率列)
  290. /// </summary>
  291. /// <param name="dto"></param>
  292. /// <returns></returns>
  293. [HttpPost]
  294. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  295. public async Task<IActionResult> GetGroupRateDataSources(TeamRateDto dto)
  296. {
  297. try
  298. {
  299. //迁移数据更新团组汇率
  300. //Result teamRateData1 = await _teamRateRep.GetGroupRateChangeData();
  301. //var data = await _teamRateRep.PostGroupTeamRateHot();
  302. Stopwatch stopwatch = Stopwatch.StartNew();
  303. GroupNameDto groupNameDto = new GroupNameDto() { PortType = dto.PortType };
  304. var groups = await _delegationInfoRep.GetGroupNameList(groupNameDto);
  305. List<CurrencyHot> _currData = new List<CurrencyHot>();
  306. string currData = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("GroupTeamCurrencyData");//string 取
  307. if (!string.IsNullOrEmpty(currData))
  308. {
  309. _currData = JsonConvert.DeserializeObject<List<CurrencyHot>>(currData);
  310. }
  311. else
  312. {
  313. _currData = await _teamRateRep.PostGroupTeamRateHot();
  314. //过期时间 25 Hours
  315. TimeSpan ts = DateTime.Now.AddHours(25).TimeOfDay;
  316. await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync("GroupTeamCurrencyData", JsonConvert.SerializeObject(_currData), ts);
  317. }
  318. var _data = new { GroupData = groups.Data, TeamRateData = _currData };
  319. stopwatch.Stop();
  320. return Ok(JsonView(true, $"查询成功!耗时:{stopwatch.ElapsedMilliseconds / 1000}s", _data));
  321. }
  322. catch (Exception ex)
  323. {
  324. return Ok(JsonView(false, ex.Message));
  325. }
  326. }
  327. ///// <summary>
  328. ///// 团组汇率 changge
  329. ///// </summary>
  330. ///// <returns></returns>
  331. //[HttpPost]
  332. //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  333. //public async Task<IActionResult> ChangeGroupRateInfo()
  334. //{
  335. // try
  336. // {
  337. // Result teamRateData = await _teamRateRep.GetGroupRateChangeData();
  338. // if (teamRateData.Code != 0)
  339. // {
  340. // return Ok(JsonView(false, teamRateData.Msg));
  341. // }
  342. // return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  343. // }
  344. // catch (Exception ex)
  345. // {
  346. // return Ok(JsonView(false, ex.Message));
  347. // throw;
  348. // }
  349. //}
  350. /// <summary>
  351. /// 团组汇率 Select汇率详情
  352. /// </summary>
  353. /// <param name="dto"></param>
  354. /// <returns></returns>
  355. [HttpPost]
  356. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  357. public async Task<IActionResult> GetGroupRateInfo(TeamRateInfoDto dto)
  358. {
  359. try
  360. {
  361. Result teamRateData = await _teamRateRep.GetGroupRateInfoByDiid(dto);
  362. if (teamRateData.Code != 0)
  363. {
  364. return Ok(JsonView(false, teamRateData.Msg));
  365. }
  366. return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  367. }
  368. catch (Exception ex)
  369. {
  370. return Ok(JsonView(false, ex.Message));
  371. throw;
  372. }
  373. }
  374. /// <summary>
  375. /// 团组汇率 添加 or 更新
  376. /// </summary>
  377. /// <param name="dto"></param>
  378. /// <returns></returns>
  379. [HttpPost]
  380. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  381. public async Task<IActionResult> PostGroupRateUpdate(TeamRateUpdateDto dto)
  382. {
  383. try
  384. {
  385. Result teamRateData = await _teamRateRep.PostGroupRateUpdate(dto);
  386. if (teamRateData.Code != 0)
  387. {
  388. return Ok(JsonView(false, teamRateData.Msg));
  389. }
  390. return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  391. }
  392. catch (Exception ex)
  393. {
  394. return Ok(JsonView(false, ex.Message));
  395. throw;
  396. }
  397. }
  398. #endregion
  399. #region 对外收款账单 关联已收款项
  400. /// <summary>
  401. /// 对外收款账单 Select数据源(团组名,币种,汇款方式)
  402. /// 关联已收款项
  403. /// </summary>
  404. /// <param name="dto"></param>
  405. /// <returns></returns>
  406. [HttpPost]
  407. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  408. public async Task<IActionResult> GetForeignReceivablesDataSources()
  409. {
  410. try
  411. {
  412. Result ffrData = await _ForForeignReceivablesRep.GetDataSource();
  413. if (ffrData.Code != 0)
  414. {
  415. return Ok(JsonView(false, ffrData.Msg));
  416. }
  417. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  418. }
  419. catch (Exception ex)
  420. {
  421. return Ok(JsonView(false, ex.Message));
  422. throw;
  423. }
  424. }
  425. /// <summary>
  426. /// 对外收款账单
  427. /// 账单详情
  428. /// 关联已收款项
  429. /// </summary>
  430. /// <param name="dto"></param>
  431. /// <returns></returns>
  432. [HttpPost]
  433. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  434. public async Task<IActionResult> GetGroupReceivablesInfoByDiId(ForForeignReceivablesInfoDto dto)
  435. {
  436. try
  437. {
  438. Result ffrData = await _ForForeignReceivablesRep.GetGroupReceivablesInfoByDiId(dto);
  439. if (ffrData.Code != 0)
  440. {
  441. return Ok(JsonView(false, ffrData.Msg));
  442. }
  443. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  444. }
  445. catch (Exception ex)
  446. {
  447. return Ok(JsonView(false, ex.Message));
  448. throw;
  449. }
  450. }
  451. /// <summary>
  452. /// 对外收款账单
  453. /// 账单 删除
  454. /// 关联已收款项
  455. /// </summary>
  456. /// <param name="dto"></param>
  457. /// <returns></returns>
  458. [HttpPost]
  459. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  460. public async Task<IActionResult> PostGroupReceivablesDel(DelForForeignReceivablesInfoDto dto)
  461. {
  462. try
  463. {
  464. Result ffrData = await _ForForeignReceivablesRep._Del(dto);
  465. if (ffrData.Code != 0)
  466. {
  467. return Ok(JsonView(false, ffrData.Msg));
  468. }
  469. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  470. }
  471. catch (Exception ex)
  472. {
  473. return Ok(JsonView(false, ex.Message));
  474. throw;
  475. }
  476. }
  477. /// <summary>
  478. /// 对外收款账单
  479. /// 添加 And 更新
  480. /// 关联已收款项
  481. /// </summary>
  482. /// <param name="dto"></param>
  483. /// <returns></returns>
  484. [HttpPost]
  485. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  486. public async Task<IActionResult> PostReceivablesOperate(ForeignReceivablesAddAndUpdateDto dto)
  487. {
  488. try
  489. {
  490. Result ffrData = await _ForForeignReceivablesRep.PostReceivablesOperate(dto);
  491. if (ffrData.Code != 0)
  492. {
  493. return Ok(JsonView(false, ffrData.Msg));
  494. }
  495. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  496. }
  497. catch (Exception ex)
  498. {
  499. return Ok(JsonView(false, ex.Message));
  500. throw;
  501. }
  502. }
  503. /// <summary>
  504. /// 已收款项
  505. /// 账单 删除
  506. /// 关联已收款项
  507. /// </summary>
  508. /// <param name="dto"></param>
  509. /// <returns></returns>
  510. [HttpPost]
  511. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  512. public async Task<IActionResult> PostAmountReceivedDel(ProceedsReceivedDelDto dto)
  513. {
  514. try
  515. {
  516. Result ffrData = await _proceedsReceivedRep._Del(dto);
  517. if (ffrData.Code != 0)
  518. {
  519. return Ok(JsonView(false, ffrData.Msg));
  520. }
  521. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  522. }
  523. catch (Exception ex)
  524. {
  525. return Ok(JsonView(false, ex.Message));
  526. throw;
  527. }
  528. }
  529. /// <summary>
  530. /// 已收款项
  531. /// 添加 And 更新
  532. /// 关联已收款项
  533. /// </summary>
  534. /// <param name="dto"></param>
  535. /// <returns></returns>
  536. [HttpPost]
  537. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  538. public async Task<IActionResult> PostAmountReceivedOperate(ProceedsReceivedDto dto)
  539. {
  540. try
  541. {
  542. Result ffrData = await _proceedsReceivedRep.PostAmountReceivedOperate(dto);
  543. if (ffrData.Code != 0)
  544. {
  545. return Ok(JsonView(false, ffrData.Msg));
  546. }
  547. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  548. }
  549. catch (Exception ex)
  550. {
  551. return Ok(JsonView(false, ex.Message));
  552. throw;
  553. }
  554. }
  555. /// <summary>
  556. /// 财务 已收款项
  557. /// 分配已收款项至 应收项下
  558. /// 关联已收款项
  559. /// </summary>
  560. /// <param name="dto"></param>
  561. /// <returns></returns>
  562. [HttpPost]
  563. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  564. public async Task<IActionResult> PostAllocateAmountReceived(AllocateAmountReceivedDto dto)
  565. {
  566. try
  567. {
  568. Result ffrData = await _proceedsReceivedRep.PostAllocateAmountReceived(dto);
  569. if (ffrData.Code != 0)
  570. {
  571. return Ok(JsonView(false, ffrData.Msg));
  572. }
  573. return Ok(JsonView(true));
  574. }
  575. catch (Exception ex)
  576. {
  577. return Ok(JsonView(false, ex.Message));
  578. throw;
  579. }
  580. }
  581. ///// <summary>
  582. ///// 财务 收款账单
  583. ///// 导出Word(北京,四川)
  584. ///// </summary>
  585. ///// <param name="dto"></param>
  586. ///// <returns></returns>
  587. //[HttpPost]
  588. //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  589. //public async Task<IActionResult> PostAccountReceivableWordExport(AccountReceivableWordExportDto dto)
  590. //{
  591. // try
  592. // {
  593. // //模板处理
  594. // string typeName = string.Empty;
  595. // if (dto.TemplateType == 1) //四川
  596. // {
  597. // typeName = "四川";
  598. // }
  599. // else if (dto.TemplateType == 2) //北京
  600. // {
  601. // typeName = "北京";
  602. // }
  603. // else return Ok(JsonView(false,"请选择正确的模板类型!"));
  604. // string wordTempName = string.Format("收款账单({0})模板.doc", typeName);
  605. // }
  606. // catch (Exception ex)
  607. // {
  608. // return Ok(JsonView(false, ex.Message));
  609. // }
  610. //}
  611. #endregion
  612. #region 对外收款账单
  613. /// <summary>
  614. /// 对外收款账单
  615. /// 数据源
  616. /// </summary>
  617. /// <param name="dto"></param>
  618. /// <returns></returns>
  619. [HttpPost]
  620. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  621. public async Task<IActionResult> PostGroupReceivablesDataSource()
  622. {
  623. try
  624. {
  625. Result ffrData = await _ForForeignReceivablesRep.PostDataSource();
  626. if (ffrData.Code != 0)
  627. {
  628. return Ok(JsonView(false, ffrData.Msg));
  629. }
  630. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  631. }
  632. catch (Exception ex)
  633. {
  634. return Ok(JsonView(false, ex.Message));
  635. }
  636. }
  637. /// <summary>
  638. /// 对外收款账单
  639. /// 账单详情
  640. /// </summary>
  641. /// <param name="dto"></param>
  642. /// <returns></returns>
  643. [HttpPost]
  644. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  645. public async Task<IActionResult> PostGroupReceivablesInfoByDiId(ForForeignReceivablesNewDto dto)
  646. {
  647. try
  648. {
  649. Result ffrData = await _ForForeignReceivablesRep.PostGroupReceivablesInfoByDiId(dto);
  650. if (ffrData.Code != 0)
  651. {
  652. return Ok(JsonView(false, ffrData.Msg));
  653. }
  654. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  655. }
  656. catch (Exception ex)
  657. {
  658. return Ok(JsonView(false, ex.Message));
  659. }
  660. }
  661. /// <summary>
  662. /// 对外收款账单
  663. /// 添加 And 更新
  664. /// </summary>
  665. /// <param name="dto"></param>
  666. /// <returns></returns>
  667. [HttpPost]
  668. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  669. public async Task<IActionResult> PostReceivablesSave(ForeignReceivablesSaveDto dto)
  670. {
  671. try
  672. {
  673. Result ffrData = await _ForForeignReceivablesRep.PostReceivablesSave(dto);
  674. if (ffrData.Code != 0)
  675. {
  676. return Ok(JsonView(false, ffrData.Msg));
  677. }
  678. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  679. }
  680. catch (Exception ex)
  681. {
  682. return Ok(JsonView(false, ex.Message));
  683. throw;
  684. }
  685. }
  686. /// <summary>
  687. /// 已收账单
  688. /// 删除
  689. /// </summary>
  690. /// <param name="dto"></param>
  691. /// <returns></returns>
  692. [HttpPost]
  693. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  694. public async Task<IActionResult> PostReceivablesDel(ForeignReceivablesDelDto dto)
  695. {
  696. try
  697. {
  698. Result ffrData = await _ForForeignReceivablesRep.PostReceivablesDel(dto);
  699. if (ffrData.Code != 0)
  700. {
  701. return Ok(JsonView(false, ffrData.Msg));
  702. }
  703. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  704. }
  705. catch (Exception ex)
  706. {
  707. return Ok(JsonView(false, ex.Message));
  708. throw;
  709. }
  710. }
  711. /// <summary>
  712. /// 已收账单
  713. /// File Downloasd
  714. /// Init
  715. /// </summary>
  716. /// <param name="dto"></param>
  717. /// <returns></returns>
  718. [HttpPost]
  719. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  720. public async Task<IActionResult> PostReceivablesFeilDownloadInit()
  721. {
  722. return Ok(JsonView(true, "操作成功!", new List<dynamic> {
  723. new { Id = 1, Name = "生成收款单(四川)" },
  724. new { Id = 2, Name = "生成收款单(北京)" },
  725. new { Id = 3, Name = "汇款账单" }
  726. }
  727. ));
  728. }
  729. /// <summary>
  730. /// 已收账单
  731. /// File Downloasd
  732. /// </summary>
  733. /// <param name="dto"></param>
  734. /// <returns></returns>
  735. [HttpPost]
  736. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  737. public async Task<IActionResult> PostReceivablesFeilDownload(ForeignReceivablesFeilDownloadDto dto)
  738. {
  739. try
  740. {
  741. if (dto.DiId < 1)
  742. {
  743. return Ok(JsonView(false, "请传入有效DiId参数!"));
  744. }
  745. if (dto.FileType < 1 || dto.FileType > 3)
  746. {
  747. return Ok(JsonView(false, "请传入有效FileType参数! 1 生成收款单(四川) 2 生成收款单(北京) 3 汇款账单"));
  748. }
  749. var _DelegationInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == dto.DiId).First();
  750. if (_DelegationInfo == null)
  751. {
  752. return Ok(JsonView(false, "暂无团组信息!!"));
  753. }
  754. if (dto.FileType == 1 || dto.FileType == 2)
  755. {
  756. var _ForeignReceivables = _sqlSugar.Queryable<Fin_ForeignReceivables>().Where(it => it.IsDel == 0 && it.Diid == dto.DiId).ToList();
  757. if (_ForeignReceivables.Count < 1)
  758. {
  759. return Ok(JsonView(false, "暂无收款信息!!"));
  760. }
  761. string tempName = "";
  762. if (dto.FileType == 1) tempName = $"收款账单(四川)模板.docx";
  763. else if (dto.FileType == 2) tempName = $"收款账单(北京)模板.docx";
  764. string tempPath = AppSettingsHelper.Get("WordBasePath") + $"ForeignReceivables/Temp/{tempName}";
  765. //载入模板
  766. Document doc = new Document(tempPath);
  767. DocumentBuilder builder = new DocumentBuilder(doc);
  768. #region 替换Word模板书签内容
  769. //这里可以创建个DataTable循环添加书签的值,这里提示一下就不多做修改了
  770. //付款方
  771. if (doc.Range.Bookmarks["To"] != null)
  772. {
  773. Bookmark mark = doc.Range.Bookmarks["To"];
  774. mark.Text = _ForeignReceivables[0].To == null ? "" : _ForeignReceivables[0].To.ToString();
  775. }
  776. //付款方电话
  777. if (doc.Range.Bookmarks["ToTel"] != null)
  778. {
  779. Bookmark mark = doc.Range.Bookmarks["ToTel"];
  780. mark.Text = _ForeignReceivables[0].ToTel == null ? "" : _ForeignReceivables[0].ToTel.ToString();
  781. }
  782. //导出时间
  783. if (doc.Range.Bookmarks["Date"] != null)
  784. {
  785. Bookmark mark = doc.Range.Bookmarks["Date"];
  786. mark.Text = DateTime.Now.ToString("yyyy-MM-dd");
  787. }
  788. //注
  789. if (doc.Range.Bookmarks["Attention"] != null)
  790. {
  791. Bookmark mark = doc.Range.Bookmarks["Attention"];
  792. mark.Text = _ForeignReceivables[0].Attention == null ? "" : _ForeignReceivables[0].Attention.ToString();
  793. }
  794. //团队名称
  795. if (doc.Range.Bookmarks["Team"] != null)
  796. {
  797. Bookmark mark = doc.Range.Bookmarks["Team"];
  798. mark.Text = _DelegationInfo.VisitCountry == null ? "" : _DelegationInfo.VisitCountry.ToString();
  799. }
  800. //付款日期
  801. if (doc.Range.Bookmarks["PayDate"] != null)
  802. {
  803. Bookmark mark = doc.Range.Bookmarks["PayDate"];
  804. mark.Text = _ForeignReceivables[0].PayDate == null ? "" : Convert.ToDateTime(_ForeignReceivables[0].PayDate).ToString("yyyy年MM月dd日");
  805. }
  806. decimal sumPrice = 0;
  807. //各项费用
  808. if (doc.Range.Bookmarks["PayItemContent"] != null)
  809. {
  810. string items = "";
  811. foreach (var fr in _ForeignReceivables)
  812. {
  813. items += fr.PriceName + " " + fr.Currency + " " + fr.Price.ToString("#0.00") + " * " + fr.Count + " " + fr.Unit + " * " + fr.Rate + ".................. RMB " + fr.ItemSumPrice.ToString("#0.00") + "\n";
  814. sumPrice += fr.ItemSumPrice;
  815. }
  816. Bookmark mark = doc.Range.Bookmarks["PayItemContent"];
  817. mark.Text = items;
  818. }
  819. //合计
  820. if (doc.Range.Bookmarks["Total"] != null)
  821. {
  822. Bookmark mark = doc.Range.Bookmarks["Total"];
  823. mark.Text = sumPrice.ToString("#0.00");
  824. }
  825. #endregion
  826. //文件名
  827. string strFileName = _DelegationInfo.TeamName + "-收款账单.docx";
  828. doc.Save(AppSettingsHelper.Get("WordBasePath") + "ForeignReceivables/File/" + strFileName);
  829. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/ForeignReceivables/File/" + strFileName;
  830. return Ok(JsonView(true, "成功", new { Url = url }));
  831. }
  832. else if (dto.FileType == 3) //汇款通知
  833. {
  834. var _EnterExitCosts = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).First();
  835. var _DayAndCosts = _sqlSugar.Queryable<Grp_DayAndCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).ToList();
  836. if (_EnterExitCosts == null)
  837. {
  838. return Ok(JsonView(false, "该团组未填写出入境费用;"));
  839. }
  840. //数据源
  841. List<Grp_DayAndCost> dac1 = _DayAndCosts.Where(it => it.Type == 1).ToList(); //住宿费
  842. List<Grp_DayAndCost> dac2 = _DayAndCosts.Where(it => it.Type == 2).ToList(); //伙食费
  843. List<Grp_DayAndCost> dac3 = _DayAndCosts.Where(it => it.Type == 3).ToList(); //公杂费
  844. List<Grp_DayAndCost> dac4 = _DayAndCosts.Where(it => it.Type == 4).ToList(); //培训费
  845. var DeleClientList = _sqlSugar.Queryable<Grp_TourClientList>()
  846. .LeftJoin<Crm_DeleClient>((tcl, dc) => tcl.ClientId == dc.Id && dc.IsDel == 0)
  847. .LeftJoin<Crm_CustomerCompany>((tcl, dc, cc) => dc.CrmCompanyId == cc.Id && dc.IsDel == 0)
  848. .Where((tcl, dc, cc) => tcl.IsDel == 0 && tcl.DiId == dto.DiId)
  849. .Select((tcl, dc, cc) => new
  850. {
  851. Name = dc.LastName + dc.FirstName,
  852. Sex = dc.Sex,
  853. Birthday = dc.BirthDay,
  854. Company = cc.CompanyFullName,
  855. Job = dc.Job,
  856. AirType = tcl.ShippingSpaceTypeId
  857. })
  858. .ToList();
  859. if (DeleClientList.Count < 1)
  860. {
  861. return Ok(JsonView(false, "暂无团组成员,请先填写团组成员!!!"));
  862. }
  863. var _ClientNames = DeleClientList.Select(x => x.Name).ToList();
  864. var _GroupClient = DeleClientList.GroupBy(x => x.Company).ToList();
  865. Dictionary<string, string> bookmarkArr = null;
  866. string tempPath = AppSettingsHelper.Get("WordBasePath") + $"ForeignReceivables/Temp/汇款通知.docx";
  867. //载入模板
  868. Document doc = new Document(tempPath);
  869. DocumentBuilder builder = null;
  870. List<string> filesToZip = new List<string>();
  871. foreach (var ClientItem in _GroupClient) //遍历单位
  872. {
  873. doc = new Document(tempPath);
  874. builder = new DocumentBuilder(doc);
  875. Paragraph paragraph = new Paragraph(doc);
  876. bookmarkArr = new Dictionary<string, string>();
  877. bookmarkArr.Add("titleClientUnit", ClientItem.Key); //title单位
  878. bookmarkArr.Add("ClientUnit", ClientItem.Key); //单位
  879. bookmarkArr.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));//出发日期
  880. bookmarkArr.Add("name", string.Join(",", ClientItem.Select(x => x.Name).ToArray()).TrimEnd(','));//全部人员信息
  881. bookmarkArr.Add("VisitCountry", _DelegationInfo.VisitCountry);//出访国家
  882. bookmarkArr.Add("dayTime", DateTime.Now.ToString("yyyy年MM月dd日"));//今天日期
  883. var ClientItemList = ClientItem.ToList();
  884. string UsersTop = string.Empty;//word中人员以及金额
  885. decimal WordAllPrice = 0.00M;
  886. //int[] infoColumn = new int[5] {dac1.Select(x=>x.Place.Length).ToList().Max(),2, dac1.Select(x => x.Cost.Length).Max() + dac1.Select(x => x.Currency.Length).Max(),
  887. // 6, 3 + dac1.Where(x=>!string.IsNullOrWhiteSpace(x.Place)).Select(x=>(Convert.ToDecimal(x.SubTotal) / Convert.ToDecimal(x.Cost)).ToString().Length).Max() };
  888. //遍历人员
  889. for (int i = 0; i < ClientItemList.Count(); i++)
  890. {
  891. Dictionary<string, string> TeableBookmarkArr = new Dictionary<string, string>();
  892. var client = ClientItemList[i]; //每个人员
  893. var firstName = ClientItemList[i].Name;
  894. //计算费用总和
  895. decimal airPrice = client.AirType == 460 ? _EnterExitCosts.AirJJ : _EnterExitCosts.AirGW;
  896. decimal AllPrice = airPrice + _EnterExitCosts.CityTranffic + dac1.Sum(x => x.SubTotal) + dac2.Sum(x => x.SubTotal) +
  897. dac3.Sum(x => x.SubTotal) + dac4.Sum(x => x.SubTotal) + _EnterExitCosts.Visa + _EnterExitCosts.Safe +
  898. _EnterExitCosts.Service;
  899. WordAllPrice += AllPrice;
  900. UsersTop += firstName + "出访费用为¥" + AllPrice.ToString("#0.00") + "元、";
  901. TeableBookmarkArr.Add("jp", (client.AirType == 460 ? _EnterExitCosts.AirJJ : _EnterExitCosts.AirGW).ToString("#0.00") + " 元"); //机票金额
  902. TeableBookmarkArr.Add("cs", _EnterExitCosts.CityTranffic.ToString("#0.00") + " 元"); //城市交通费用
  903. TeableBookmarkArr.Add("zs", dac1.Sum(x => Convert.ToDecimal(x.SubTotal)).ToString("#0.00") + " 元"); //住宿费
  904. string zsinfo = string.Empty;
  905. string hsinfo = string.Empty;
  906. string gzinfo = string.Empty;
  907. List<string> placeArr = new List<string>();
  908. Aspose.Words.Tables.Table FirstTable = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 0, true);
  909. Aspose.Words.Tables.Table ChildTable = (Aspose.Words.Tables.Table)FirstTable.GetChild(NodeType.Table, 0, true);
  910. Aspose.Words.Tables.Table ChildTable1 = (Aspose.Words.Tables.Table)FirstTable.GetChild(NodeType.Table, 1, true);
  911. Aspose.Words.Tables.Table ChildTable2 = (Aspose.Words.Tables.Table)FirstTable.GetChild(NodeType.Table, 2, true);
  912. int rowIndex = 0;
  913. foreach (var item in dac1)
  914. {
  915. if (string.IsNullOrWhiteSpace(item.Place))
  916. {
  917. continue;
  918. }
  919. if (placeArr.Contains(item.Place))
  920. {
  921. continue;
  922. }
  923. else
  924. {
  925. placeArr.Add(item.Place);
  926. }
  927. if (!string.IsNullOrWhiteSpace(item.Place))
  928. {
  929. if (rowIndex > ChildTable.Rows.Count - 1)
  930. {
  931. var chitableRow = ChildTable.LastRow.Clone(true);
  932. ChildTable.AppendChild(chitableRow);
  933. }
  934. int days = dac1.FindAll(x => x.Place == item.Place).Count();
  935. SetCells(ChildTable, doc, rowIndex, 0, item.Place);
  936. SetCells(ChildTable, doc, rowIndex, 1, days + "晚");
  937. SetCells(ChildTable, doc, rowIndex, 2, item.Cost + item.Currency + "/晚");
  938. SetCells(ChildTable, doc, rowIndex, 3, " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00"));
  939. SetCells(ChildTable, doc, rowIndex, 4, "CNY" + item.SubTotal * days + "\r\n");
  940. rowIndex++;
  941. zsinfo += item.Place + " " + days + "晚 " + item.Cost + item.Currency + "/晚" + " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00") + " CNY" + item.SubTotal * days + "\r\n";
  942. }
  943. }
  944. placeArr.Clear();
  945. rowIndex = 0;
  946. foreach (var item in dac2)
  947. {
  948. if (string.IsNullOrWhiteSpace(item.Place))
  949. {
  950. continue;
  951. }
  952. if (placeArr.Contains(item.Place))
  953. {
  954. continue;
  955. }
  956. else
  957. {
  958. placeArr.Add(item.Place);
  959. }
  960. if (!string.IsNullOrWhiteSpace(item.Place))
  961. {
  962. if (rowIndex > ChildTable1.Rows.Count - 1)
  963. {
  964. var chitableRow = ChildTable1.LastRow.Clone(true);
  965. ChildTable1.AppendChild(chitableRow);
  966. }
  967. int days = dac2.FindAll(x => x.Place == item.Place).Count();
  968. SetCells(ChildTable1, doc, rowIndex, 0, item.Place);
  969. SetCells(ChildTable1, doc, rowIndex, 1, days + "天");
  970. SetCells(ChildTable1, doc, rowIndex, 2, item.Cost + item.Currency + "/天");
  971. SetCells(ChildTable1, doc, rowIndex, 3, " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00"));
  972. SetCells(ChildTable1, doc, rowIndex, 4, "CNY" + item.SubTotal * days);
  973. rowIndex++;
  974. hsinfo += item.Place + " " + days + "天 " + item.Cost + item.Currency + "/天" + " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00") + " CNY" + item.SubTotal * days + "\r\n";
  975. }
  976. }
  977. placeArr.Clear();
  978. rowIndex = 0;
  979. foreach (var item in dac3)
  980. {
  981. if (string.IsNullOrWhiteSpace(item.Place))
  982. {
  983. continue;
  984. }
  985. if (placeArr.Contains(item.Place))
  986. {
  987. continue;
  988. }
  989. else
  990. {
  991. placeArr.Add(item.Place);
  992. }
  993. if (!string.IsNullOrWhiteSpace(item.Place))
  994. {
  995. if (rowIndex > ChildTable2.Rows.Count - 1)
  996. {
  997. var chitableRow = ChildTable2.LastRow.Clone(true);
  998. ChildTable2.AppendChild(chitableRow);
  999. }
  1000. int days = dac3.FindAll(x => x.Place == item.Place).Count();
  1001. SetCells(ChildTable2, doc, rowIndex, 0, item.Place);
  1002. SetCells(ChildTable2, doc, rowIndex, 1, days + "天");
  1003. SetCells(ChildTable2, doc, rowIndex, 2, item.Cost + item.Currency + "/天");
  1004. SetCells(ChildTable2, doc, rowIndex, 3, " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00"));
  1005. SetCells(ChildTable2, doc, rowIndex, 4, "CNY" + item.SubTotal * days + "\r\n");
  1006. rowIndex++;
  1007. gzinfo += item.Place + " " + days + "天 " + item.Cost + item.Currency + "/天" + " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00") + " CNY" + item.SubTotal * days + "\r\n";
  1008. }
  1009. }
  1010. placeArr.Clear();
  1011. TeableBookmarkArr.Add("zsinfo", zsinfo); //住宿费详情
  1012. TeableBookmarkArr.Add("hs", dac2.Sum(x => Convert.ToDecimal(x.SubTotal)).ToString("#0.00") + " 元"); //伙食费
  1013. TeableBookmarkArr.Add("hsinfo", hsinfo); //伙食费详情
  1014. TeableBookmarkArr.Add("gz", dac3.Sum(x => Convert.ToDecimal(x.SubTotal)).ToString("#0.00") + " 元"); //公杂费
  1015. TeableBookmarkArr.Add("gzinfo", gzinfo); //公杂费详情
  1016. TeableBookmarkArr.Add("qt", (_EnterExitCosts.Visa + _EnterExitCosts.Safe).ToString("#0.00") + " 元");//其他费用
  1017. TeableBookmarkArr.Add("qtinfo", $"(签证费{_EnterExitCosts.Visa.ToString("#0.00")}元、保险{_EnterExitCosts.Safe.ToString("#0.00")}元等费用)");//其他费用第二列
  1018. TeableBookmarkArr.Add("fw", _EnterExitCosts.Service.ToString("#0.00") + "元/人");//服务费
  1019. TeableBookmarkArr.Add("AllPrice", AllPrice.ToString("#0.00") + "元/人");//表格合计费用
  1020. string airStr = client.AirType == 460 ? "经济舱" : client.AirType == 458 ? "公务舱" : "";
  1021. TeableBookmarkArr.Add("title", $"费用清单-{airStr}{firstName})");
  1022. foreach (var book in TeableBookmarkArr.Keys)
  1023. {
  1024. if (doc.Range.Bookmarks[book] != null)
  1025. {
  1026. Bookmark mark = doc.Range.Bookmarks[book];
  1027. mark.Text = TeableBookmarkArr[book];
  1028. }
  1029. }
  1030. if (i != ClientItemList.Count - 1)
  1031. {
  1032. builder.PageSetup.Orientation = Aspose.Words.Orientation.Portrait;
  1033. Aspose.Words.Tables.Table table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 0, true);
  1034. table.ParentNode.InsertAfter(paragraph, table);
  1035. var CloneTable = (Aspose.Words.Tables.Table)table.Clone(true);
  1036. table.ParentNode.InsertAfter(CloneTable, paragraph);
  1037. }
  1038. TeableBookmarkArr.Clear();
  1039. }
  1040. bookmarkArr.Add("VisitPrice", WordAllPrice.ToString());//出访费用总额
  1041. bookmarkArr.Add("CnAllPrice", WordAllPrice.ConvertCNYUpper());//出访费用总额中文
  1042. bookmarkArr.Add("namesPrice", UsersTop.TrimEnd('、'));//各人员出访费用 付辰同志出访费用为¥73,604.8元
  1043. foreach (var book in bookmarkArr.Keys)
  1044. {
  1045. if (doc.Range.Bookmarks[book] != null)
  1046. {
  1047. Bookmark mark = doc.Range.Bookmarks[book];
  1048. mark.Text = bookmarkArr[book];
  1049. }
  1050. }
  1051. //MemoryStream outSteam = new MemoryStream();
  1052. string filsPath = AppSettingsHelper.Get("WordBasePath") + $"ForeignReceivables/File/{ClientItem.Key}.docx";
  1053. doc.Save(filsPath);
  1054. filesToZip.Add(filsPath);
  1055. //streams.Add(ClientItem.Key + ".docx", outSteam.ToArray());
  1056. }
  1057. //文件名
  1058. string zipFileName = _DelegationInfo.TeamName + "-收款账单.zip";
  1059. string zipPath = $"ForeignReceivables/File/{_DelegationInfo.TeamName}-收款账单{DateTime.Now.ToString("yyyyMMddHHmmss")}.zip";
  1060. try
  1061. {
  1062. using (var zip = ZipFile.Open(AppSettingsHelper.Get("WordBasePath") + zipPath, ZipArchiveMode.Create))
  1063. {
  1064. foreach (var file in filesToZip)
  1065. {
  1066. zip.CreateEntryFromFile(file, Path.GetFileName(file));
  1067. }
  1068. }
  1069. }
  1070. catch (Exception ex)
  1071. {
  1072. return Ok(JsonView(false, ex.Message));
  1073. }
  1074. string url = AppSettingsHelper.Get("WordBaseUrl") + $"Office/Word/{zipPath}";
  1075. return Ok(JsonView(true, "成功", new { Url = url }));
  1076. }
  1077. return Ok(JsonView(false, "操作失败!"));
  1078. }
  1079. catch (Exception ex)
  1080. {
  1081. return Ok(JsonView(false, ex.Message));
  1082. }
  1083. }
  1084. private void SetCells(Aspose.Words.Tables.Table table, Document doc, int rows, int cells, string val)
  1085. {
  1086. //获取table中的某个单元格,从0开始
  1087. Aspose.Words.Tables.Cell lshCell = table.Rows[rows].Cells[cells];
  1088. //将单元格中的第一个段落移除
  1089. lshCell.FirstParagraph.Remove();
  1090. //新建一个段落
  1091. Paragraph p = new Paragraph(doc);
  1092. var r = new Run(doc, val);
  1093. r.Font.Size = 8;
  1094. //把设置的值赋给之前新建的段落
  1095. p.AppendChild(r);
  1096. //将此段落加到单元格内
  1097. lshCell.AppendChild(p);
  1098. }
  1099. #endregion
  1100. #region 已收款项
  1101. /// <summary>
  1102. /// 已收款项
  1103. /// 查询
  1104. /// </summary>
  1105. /// <param name="dto"></param>
  1106. /// <returns></returns>
  1107. [HttpPost]
  1108. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1109. public async Task<IActionResult> PostAmountReceived(AmountReceivedDto dto)
  1110. {
  1111. try
  1112. {
  1113. if (dto == null)
  1114. {
  1115. return Ok(JsonView(false, "参数不能为空!"));
  1116. }
  1117. Result ffrData = await _proceedsReceivedRep.PostAmountReceived(dto.DiId);
  1118. dynamic data = null;
  1119. if (dto.PortType == 1)
  1120. {
  1121. if (ffrData.Code != 0)
  1122. {
  1123. return Ok(JsonView(false, ffrData.Msg));
  1124. }
  1125. data = ffrData.Data;
  1126. }
  1127. else if (dto.PortType == 2)
  1128. {
  1129. if (ffrData.Code != 0)
  1130. {
  1131. return Ok(JsonView(false, ffrData.Msg));
  1132. }
  1133. data = ffrData.Data;
  1134. }
  1135. else if (dto.PortType == 2)
  1136. {
  1137. if (ffrData.Code != 0)
  1138. {
  1139. return Ok(JsonView(false, ffrData.Msg));
  1140. }
  1141. data = ffrData.Data;
  1142. }
  1143. else
  1144. {
  1145. return Ok(JsonView(false, "请选择正确的端口号!"));
  1146. }
  1147. return Ok(JsonView(true, "操作成功!", data));
  1148. }
  1149. catch (Exception ex)
  1150. {
  1151. return Ok(JsonView(false, ex.Message));
  1152. }
  1153. }
  1154. /// <summary>
  1155. /// 已收款项
  1156. /// Add Or Edit
  1157. /// </summary>
  1158. /// <param name="dto"></param>
  1159. /// <returns></returns>
  1160. [HttpPost]
  1161. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1162. public async Task<IActionResult> PostAmountReceivedAddOrEdit(AmountReceivedAddOrEditDto dto)
  1163. {
  1164. try
  1165. {
  1166. if (dto == null)
  1167. {
  1168. return Ok(JsonView(false, "参数不能为空!"));
  1169. }
  1170. Result ffrData = await _proceedsReceivedRep.PostAmountReceivedAddOrEditDto(dto);
  1171. if (dto.PortType == 1)
  1172. {
  1173. if (ffrData.Code != 0)
  1174. {
  1175. return Ok(JsonView(false, ffrData.Msg));
  1176. }
  1177. }
  1178. else if (dto.PortType == 2)
  1179. {
  1180. if (ffrData.Code != 0)
  1181. {
  1182. return Ok(JsonView(false, ffrData.Msg));
  1183. }
  1184. }
  1185. else if (dto.PortType == 2)
  1186. {
  1187. if (ffrData.Code != 0)
  1188. {
  1189. return Ok(JsonView(false, ffrData.Msg));
  1190. }
  1191. }
  1192. else
  1193. {
  1194. return Ok(JsonView(false, "请选择正确的端口号!"));
  1195. }
  1196. return Ok(JsonView(true, "操作成功!"));
  1197. }
  1198. catch (Exception ex)
  1199. {
  1200. return Ok(JsonView(false, ex.Message));
  1201. }
  1202. }
  1203. /// <summary>
  1204. /// 已收款项
  1205. /// Del
  1206. /// </summary>
  1207. /// <param name="dto"></param>
  1208. /// <returns></returns>
  1209. [HttpPost]
  1210. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1211. public async Task<IActionResult> PostAmountReceived_Del(AmountReceivedDelDto dto)
  1212. {
  1213. try
  1214. {
  1215. if (dto == null)
  1216. {
  1217. return Ok(JsonView(false, "参数不能为空!"));
  1218. }
  1219. Result ffrData = await _proceedsReceivedRep.PostAmountReceivedDel(dto);
  1220. if (ffrData.Code != 0)
  1221. {
  1222. return Ok(JsonView(false, ffrData.Msg));
  1223. }
  1224. return Ok(JsonView(true, "操作成功!"));
  1225. }
  1226. catch (Exception ex)
  1227. {
  1228. return Ok(JsonView(false, ex.Message));
  1229. }
  1230. }
  1231. #endregion
  1232. #region 收款退还与其他款项
  1233. /// <summary>
  1234. /// 收款退还与其他款项
  1235. /// 查询 根据团组Id
  1236. /// </summary>
  1237. /// <param name="dto"></param>
  1238. /// <returns></returns>
  1239. [HttpPost]
  1240. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1241. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyItemByDiId(PaymentRefundAndOtherMoneyItemByDiIdDto dto)
  1242. {
  1243. try
  1244. {
  1245. if (dto == null) return Ok(JsonView(false, "参数不能为空!"));
  1246. if (dto.PageId <= 0) return Ok(JsonView(false, "请传入正确的的页面Id!"));
  1247. if (dto.UserId <= 0) return Ok(JsonView(false, "请传入正确的的员工Id!"));
  1248. #region 页面功能权限处理
  1249. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  1250. pageFunAuth = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1251. if (pageFunAuth.CheckAuth == 0)
  1252. {
  1253. return Ok(JsonView(false, "您没有当前页面查询权限!"));
  1254. }
  1255. #endregion
  1256. Result _result = await _paymentRefundAndOtherMoneyRep._ItemByDiId(dto.DiId);
  1257. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //1 Web 2 Android 3 Ios
  1258. {
  1259. if (_result.Code != 0)
  1260. {
  1261. return Ok(JsonView(false, _result.Msg));
  1262. }
  1263. var data = new
  1264. {
  1265. PageFuncAuth = pageFunAuth,
  1266. Data = _result.Data
  1267. };
  1268. return Ok(JsonView(true, "操作成功!", data));
  1269. }
  1270. else
  1271. {
  1272. return Ok(JsonView(false, "请输入正确的端口号! 1 Web 2 Android 3 Ios;"));
  1273. }
  1274. }
  1275. catch (Exception ex)
  1276. {
  1277. return Ok(JsonView(false, ex.Message));
  1278. }
  1279. }
  1280. /// <summary>
  1281. /// 收款退还与其他款项
  1282. /// 删除
  1283. /// </summary>
  1284. /// <param name="dto"></param>
  1285. /// <returns></returns>
  1286. [HttpPost]
  1287. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1288. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyDel(PaymentRefundAndOtherMoneyDelDto dto)
  1289. {
  1290. try
  1291. {
  1292. if (dto == null) return Ok(JsonView(false, "参数不能为空!"));
  1293. if (dto.PageId <= 0) return Ok(JsonView(false, "请传入正确的的页面Id!"));
  1294. if (dto.UserId <= 0) return Ok(JsonView(false, "请传入正确的的员工Id!"));
  1295. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  1296. #region 页面功能权限处理
  1297. pageFunAuth = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1298. #endregion
  1299. if (pageFunAuth.DeleteAuth == 0)
  1300. {
  1301. return Ok(JsonView(false, "您没有当前页面删除权限!"));
  1302. }
  1303. Result _result = await _paymentRefundAndOtherMoneyRep._Del(dto);
  1304. if (_result.Code != 0)
  1305. {
  1306. return Ok(JsonView(false, _result.Msg));
  1307. }
  1308. return Ok(JsonView(true, "操作成功!"));
  1309. }
  1310. catch (Exception ex)
  1311. {
  1312. return Ok(JsonView(false, ex.Message));
  1313. }
  1314. }
  1315. /// <summary>
  1316. /// 收款退还与其他款项
  1317. /// Info Data Source
  1318. /// </summary>
  1319. /// <param name="dto"></param>
  1320. /// <returns></returns>
  1321. [HttpPost]
  1322. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1323. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyInfoDataSource(PortDtoBase dto)
  1324. {
  1325. try
  1326. {
  1327. Result _result = await _paymentRefundAndOtherMoneyRep._InfoDataSource(dto);
  1328. if (_result.Code != 0)
  1329. {
  1330. return Ok(JsonView(false, _result.Msg));
  1331. }
  1332. return Ok(JsonView(true, "查询成功!", _result.Data));
  1333. }
  1334. catch (Exception ex)
  1335. {
  1336. return Ok(JsonView(false, ex.Message));
  1337. }
  1338. }
  1339. /// <summary>
  1340. /// 收款退还与其他款项
  1341. /// Info
  1342. /// </summary>
  1343. /// <param name="dto"></param>
  1344. /// <returns></returns>
  1345. [HttpPost]
  1346. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1347. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyInfo(PaymentRefundAndOtherMoneyInfoDto dto)
  1348. {
  1349. try
  1350. {
  1351. if (dto == null)
  1352. {
  1353. return Ok(JsonView(false, "参数不能为空!"));
  1354. }
  1355. Result _result = await _paymentRefundAndOtherMoneyRep._Info(dto);
  1356. if (_result.Code != 0)
  1357. {
  1358. return Ok(JsonView(false, _result.Msg));
  1359. }
  1360. return Ok(JsonView(true, "查询成功!", _result.Data));
  1361. }
  1362. catch (Exception ex)
  1363. {
  1364. return Ok(JsonView(false, ex.Message));
  1365. }
  1366. }
  1367. /// <summary>
  1368. /// 收款退还与其他款项
  1369. /// 操作(Add Or Edit)
  1370. /// </summary>
  1371. /// <param name="dto"></param>
  1372. /// <returns></returns>
  1373. [HttpPost]
  1374. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1375. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyAddOrEdit(PaymentRefundAndOtherMoneyAddOrEditDto dto)
  1376. {
  1377. try
  1378. {
  1379. if (dto == null) return Ok(JsonView(false, "参数不能为空!"));
  1380. if (dto.PageId <= 0) return Ok(JsonView(false, "请传入正确的的页面Id!"));
  1381. if (dto.UserId <= 0) return Ok(JsonView(false, "请传入正确的的员工Id!"));
  1382. #region 页面功能权限处理
  1383. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  1384. pageFunAuth = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1385. #endregion
  1386. if (dto.Status == 1) //add
  1387. {
  1388. if (pageFunAuth.AddAuth == 0)
  1389. {
  1390. return Ok(JsonView(false, "您没有当前页面添加权限!"));
  1391. }
  1392. }
  1393. else if (dto.Status == 2) //edit
  1394. {
  1395. if (pageFunAuth.EditAuth == 0)
  1396. {
  1397. return Ok(JsonView(false, "您没有当前页面编辑权限!"));
  1398. }
  1399. }
  1400. else
  1401. {
  1402. return Ok(JsonView(false, "请输入正确的操作状态! 1 添加 2 修改!"));
  1403. }
  1404. Result _result = await _paymentRefundAndOtherMoneyRep._AddOrEdit(dto);
  1405. if (_result.Code != 0)
  1406. {
  1407. return Ok(JsonView(false, _result.Msg));
  1408. }
  1409. return Ok(JsonView(true, "操作成功!"));
  1410. }
  1411. catch (Exception ex)
  1412. {
  1413. return Ok(JsonView(false, ex.Message));
  1414. }
  1415. }
  1416. #endregion
  1417. #region 应收报表
  1418. /// <summary>
  1419. /// 应收报表
  1420. /// 查询 根据日期范围
  1421. /// </summary>
  1422. /// <param name="dto"></param>
  1423. /// <returns></returns>
  1424. [HttpPost]
  1425. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1426. public async Task<IActionResult> PostSyntheticalReceivableByDateRange(PostSyntheticalReceivableByDateRangeDto dto)
  1427. {
  1428. string sqlWhere = " Where di.IsDel=0 ";
  1429. #region 验证
  1430. if (string.IsNullOrEmpty(dto.beginDt) && string.IsNullOrEmpty(dto.endDt))
  1431. {
  1432. return Ok(JsonView(false, "日期参数至少填写一个!"));
  1433. }
  1434. if (!string.IsNullOrEmpty(dto.beginDt))
  1435. {
  1436. if (Regex.Match(dto.beginDt, @"^\d{4}-\d{2}-\d{2}$").Value.Length < 1)
  1437. {
  1438. return Ok(JsonView(false, "日期参数格式错误,应为yyyy-MM-dd!"));
  1439. }
  1440. else
  1441. {
  1442. sqlWhere += string.Format(@" And di.VisitDate >= '{0} 00:00:00' ", dto.beginDt);
  1443. }
  1444. }
  1445. if (!string.IsNullOrEmpty(dto.endDt))
  1446. {
  1447. if (Regex.Match(dto.endDt, @"^\d{4}-\d{2}-\d{2}$").Value.Length < 1)
  1448. {
  1449. return Ok(JsonView(false, "日期参数格式错误,应为yyyy-MM-dd!"));
  1450. }
  1451. else
  1452. {
  1453. sqlWhere += string.Format(@" And di.VisitDate <= '{0} 23:59:59' ", dto.endDt);
  1454. }
  1455. }
  1456. #endregion
  1457. string sql = string.Format(@" select distinct fr.diid,di.TeamName,di.ClientUnit,di.VisitDate from Fin_ForeignReceivables fr join Grp_DelegationInfo di on fr.DIID = di.id {0} ", sqlWhere);
  1458. List<PostSyntheticalReceivableByDateRangeView> list_rst = _sqlSugar.SqlQueryable<PostSyntheticalReceivableByDateRangeView>(sql).ToList();
  1459. decimal sumAll_fr = 0M;
  1460. decimal sumAll_pr = 0M;
  1461. decimal sumAll_balance = 0M;
  1462. if (list_rst.Count > 0)
  1463. {
  1464. int rowNumber = 1;
  1465. foreach (var item_rst in list_rst)
  1466. {
  1467. DateTime dtTemp;
  1468. bool b = DateTime.TryParse(item_rst.visitDate, out dtTemp);
  1469. if (b)
  1470. {
  1471. item_rst.visitDate = dtTemp.ToString("yyyy-MM-dd");
  1472. }
  1473. item_rst.No = rowNumber;
  1474. rowNumber++;
  1475. int diId = item_rst.diid;
  1476. decimal sum_fr = 0M;
  1477. decimal sum_pr = 0M;
  1478. string str_client = string.Empty;
  1479. decimal sum_other = 0M; //收款退还
  1480. decimal sum_extra = 0M; //超支费用
  1481. decimal balance = 0M;
  1482. string str_schedule = string.Empty;
  1483. //1.应收
  1484. string sql_fr = string.Format(@" Select * From Fin_ForeignReceivables Where IsDel=0 And Diid={0} ", diId);
  1485. List<Fin_ForeignReceivables> list_fr = _sqlSugar.SqlQueryable<Fin_ForeignReceivables>(sql_fr).ToList();
  1486. sum_fr = list_fr.Sum(s => s.ItemSumPrice);
  1487. //2.已收
  1488. string sql_pr = string.Format(@" Select * From Fin_ProceedsReceived Where IsDel=0 And Diid={0} ", diId);
  1489. List<Fin_ProceedsReceived> list_pr = _sqlSugar.SqlQueryable<Fin_ProceedsReceived>(sql_pr).ToList();
  1490. foreach (var item_pr in list_pr)
  1491. {
  1492. sum_pr += item_pr.Price;
  1493. str_client += string.Format(@"{0};", item_pr.Client);
  1494. str_schedule += string.Format(@"{0};", item_pr.Remark);
  1495. }
  1496. if (str_schedule.Length > 0)
  1497. {
  1498. str_schedule = str_schedule.TrimEnd(';');
  1499. }
  1500. if (str_client.Length > 0)
  1501. {
  1502. str_client = str_client.TrimEnd(';');
  1503. }
  1504. //3.
  1505. string sql_other = string.Format(@" Select * From Fin_OtherPrice where diid = {0} and isdel = 0 and RefundType = 1 and PayType=1 ", diId);
  1506. List<Fin_OtherPrice> list_other = _sqlSugar.SqlQueryable<Fin_OtherPrice>(sql_other).ToList();
  1507. sum_other = list_other.Sum(s => s.Price);
  1508. //4.
  1509. string sql_extra = string.Format(@" Select c.* From Fin_GroupExtraCost f
  1510. Inner join Grp_CreditCardPayment c On f.Id = c.CId
  1511. Where c.CTable = 1015 And c.IsPay = 1 And f.IsDel = 0 And c.IsDel = 0 And f.DiId = {0} ", diId);
  1512. List<Grp_CreditCardPayment> list_extra = _sqlSugar.SqlQueryable<Grp_CreditCardPayment>(sql_extra).ToList();
  1513. sum_extra = list_extra.Sum(s => s.RMBPrice);
  1514. item_rst.frPrice = (sum_fr + sum_extra).ToString("#0.00");
  1515. item_rst.prPrice = (sum_pr - sum_other).ToString("#0.00");
  1516. item_rst.balPrice = ((sum_fr + sum_extra) - (sum_pr - sum_other)).ToString("#0.00");
  1517. item_rst.prClient = str_client;
  1518. item_rst.schedule = str_schedule;
  1519. string tempVisitDate = Convert.ToDateTime(item_rst.visitDate).ToString("yyyy-MM-dd");
  1520. sumAll_fr += (sum_fr + sum_extra);
  1521. sumAll_pr += (sum_pr - sum_other);
  1522. sumAll_balance += ((sum_fr + sum_extra) - (sum_pr - sum_other));
  1523. }
  1524. PostSyntheticalReceivableByDateRangeResultView result = new PostSyntheticalReceivableByDateRangeResultView();
  1525. result.total_fr = sumAll_fr.ToString("#0.00");
  1526. result.total_pr = sumAll_pr.ToString("#0.00");
  1527. result.total_balance = sumAll_balance.ToString("#0.00");
  1528. result.dataList = new List<PostSyntheticalReceivableByDateRangeView>(list_rst);
  1529. if (dto.requestType == 1)
  1530. {
  1531. return Ok(JsonView(true, "请求成功", result, list_rst.Count));
  1532. }
  1533. else
  1534. {
  1535. //----------------------------
  1536. List<Excel_SyntheticalReceivableByDateRange> list_Ex = new List<Excel_SyntheticalReceivableByDateRange>();
  1537. WorkbookDesigner designer = new WorkbookDesigner();
  1538. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/应收款项模板 - 副本.xls");
  1539. int excNo = 1;
  1540. foreach (var item in list_rst)
  1541. {
  1542. Excel_SyntheticalReceivableByDateRange exc = new Excel_SyntheticalReceivableByDateRange();
  1543. exc.No = excNo.ToString();
  1544. excNo++;
  1545. exc.TeamName = item.teamName;
  1546. exc.ClientUnit = item.clientUnit;
  1547. exc.VisitDate = item.visitDate;
  1548. exc.Accounts = item.frPrice;
  1549. exc.Received = item.prPrice;
  1550. exc.Balance = item.balPrice;
  1551. exc.Collection = item.schedule;
  1552. DateTime time = Convert.ToDateTime(item.visitDate);
  1553. TimeSpan ts = DateTime.Now - time;
  1554. float SY = float.Parse(item.balPrice);
  1555. if (ts.Days >= 365 && SY > 0)
  1556. {
  1557. exc.Sign = "需收款";
  1558. }
  1559. else
  1560. {
  1561. exc.Sign = "";
  1562. }
  1563. list_Ex.Add(exc);
  1564. }
  1565. var dt = CommonFun.GetDataTableFromIList(list_Ex);
  1566. dt.TableName = "Excel_SyntheticalReceivableByDateRange";
  1567. if (dt != null)
  1568. {
  1569. designer.SetDataSource("SumPrice", "应收合计:" + result.total_fr + "RMB 已收合计:" + result.total_pr + "RMB 余款合计:" + result.total_balance + "RMB");
  1570. //数据源
  1571. designer.SetDataSource(dt);
  1572. //根据数据源处理生成报表内容
  1573. designer.Process();
  1574. string fileName = ("Receivable/应收款项(" + dto.beginDt + "~" + dto.endDt + ").xlsx");
  1575. designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
  1576. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  1577. return Ok(JsonView(true, "成功", new { url = rst }));
  1578. }
  1579. }
  1580. }
  1581. return Ok(JsonView(true, "获取成功", "", list_rst.Count));
  1582. }
  1583. #endregion
  1584. #region 付款申请
  1585. /// <summary>
  1586. /// 付款申请
  1587. /// 基础数据
  1588. /// </summary>
  1589. /// <param name="dto"></param>
  1590. /// <returns></returns>
  1591. [HttpPost]
  1592. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1593. public async Task<IActionResult> PostPayRequestInit()
  1594. {
  1595. try
  1596. {
  1597. var conpanyDatas = _sqlSugar.Queryable<Sys_Company>()
  1598. .Where(it => it.IsDel == 0)
  1599. .Select(it => new
  1600. {
  1601. Id = it.Id,
  1602. ConpamyName = it.CompanyName
  1603. }).ToList();
  1604. return Ok(JsonView(true, "操作成功!", new { ConpanyData = conpanyDatas }));
  1605. }
  1606. catch (Exception ex)
  1607. {
  1608. return Ok(JsonView(false, ex.Message));
  1609. }
  1610. }
  1611. /// <summary>
  1612. /// 付款申请 (PageId=51)
  1613. /// 查询 根据日期范围
  1614. /// </summary>
  1615. /// <param name="dto"></param>
  1616. /// <returns></returns>
  1617. [HttpPost]
  1618. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1619. public async Task<IActionResult> PostPayRequest_Center(PostPayRequestByDateRangeDto dto)
  1620. {
  1621. Stopwatch stopwatch = Stopwatch.StartNew();
  1622. #region 验证
  1623. DateTime beginDt, endDt;
  1624. string format = "yyyy-MM-dd";
  1625. if (!DateTime.TryParseExact(dto.beginDt, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out beginDt))
  1626. {
  1627. return Ok(JsonView(false, "开始日期格式不正确!正确格式:yyyy-MM-dd"));
  1628. }
  1629. if (!DateTime.TryParseExact(dto.endDt, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out endDt))
  1630. {
  1631. return Ok(JsonView(false, "结束日期格式不正确!正确格式:yyyy-MM-dd"));
  1632. }
  1633. #region 页面操作权限验证
  1634. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  1635. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1636. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  1637. #endregion
  1638. #endregion
  1639. try
  1640. {
  1641. PaymentRequestCheckedView checkedView = new PaymentRequestCheckedView();
  1642. var checkedStr = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("paymentRequestCheckedData");
  1643. if (checkedStr != null)
  1644. {
  1645. checkedView = JsonConvert.DeserializeObject<PaymentRequestCheckedView>(checkedStr.ToString());
  1646. }
  1647. tree_Fin_DailyFeePaymentResult dailyResult = PayRequest_DailyByDateRange(dto.Status, checkedView.DailyPaymentIds, dto.beginDt, dto.endDt);
  1648. tree_Group_DailyFeePaymentResult groupResult = PayRequest_GroupPaymentByDateRange(dto.Status, checkedView.GroupIds, dto.beginDt, dto.endDt);
  1649. stopwatch.Stop();
  1650. return Ok(JsonView(true, $"查询成功!耗时{stopwatch.ElapsedMilliseconds/1000}s", new { daily = dailyResult, group = groupResult }));
  1651. }
  1652. catch (Exception ex)
  1653. {
  1654. return Ok(JsonView(false, ex.Message));
  1655. }
  1656. }
  1657. /// <summary>
  1658. /// 根据团组类型类型处理团组费用所属公司
  1659. /// </summary>
  1660. /// <param name="teamId"></param>
  1661. /// <returns></returns>
  1662. private CompanyInfo ExpenseCompanyByTeamId(int teamId)
  1663. {
  1664. CompanyInfo _companyInfo = new CompanyInfo();
  1665. List<int> _SiChuan = new List<int>() {
  1666. 38 , // 政府团
  1667. 39 , // 企业团
  1668. 40 , // 散客团
  1669. 102, // 未知
  1670. 248, // 非团组
  1671. 691, // 四川-会务活动
  1672. 762, // 四川-赛事项目收入
  1673. };
  1674. List<int> _ChengDu = new List<int>() {
  1675. 302, // 成都-会务活动
  1676. 1047, // 成都-赛事项目收入
  1677. };
  1678. if (_SiChuan.Contains(teamId))
  1679. {
  1680. _companyInfo.Id = 2;
  1681. _companyInfo.ConpanyName = "四川泛美交流有限公司";
  1682. }
  1683. if (_ChengDu.Contains(teamId))
  1684. {
  1685. _companyInfo.Id = 1;
  1686. _companyInfo.ConpanyName = "成都泛美商务有限公司";
  1687. }
  1688. return _companyInfo;
  1689. }
  1690. /// <summary>
  1691. /// 付款申请(团组费用申请相关)
  1692. /// 查询 根据日期范围
  1693. /// </summary>
  1694. /// <param name="_groupIds"></param>
  1695. /// <param name="beginDt"></param>
  1696. /// <param name="endDt"></param>
  1697. /// <returns></returns>
  1698. private tree_Group_DailyFeePaymentResult PayRequest_GroupPaymentByDateRange(int status, List<int> _groupIds, string beginDt, string endDt)
  1699. {
  1700. tree_Group_DailyFeePaymentResult _DailyFeePaymentResult = new tree_Group_DailyFeePaymentResult();
  1701. List<tree_Group_DailyFeePaymentPageListView> dataList = new List<tree_Group_DailyFeePaymentPageListView>();
  1702. #region sql条件处理
  1703. string sqlWhere = string.Format(@" And (AuditGMDate Between '{0} 00:00:00' And '{1} 23:59:59') ", beginDt, endDt);
  1704. if (status == 2)
  1705. {
  1706. if (_groupIds.Count < 1)
  1707. {
  1708. _DailyFeePaymentResult.dataList = new List<tree_Group_DailyFeePaymentPageListView>();
  1709. return _DailyFeePaymentResult;
  1710. }
  1711. sqlWhere += string.Format(@" And Id In ({0})", string.Join(",", _groupIds));
  1712. }
  1713. string sql_1 = string.Format(@"Select * From Grp_CreditCardPayment Where IsDel = 0 And IsPay = 0 And IsAuditGM = 1 {0}", sqlWhere);
  1714. #endregion
  1715. var _paymentDatas = _sqlSugar.SqlQueryable<Grp_CreditCardPayment>(sql_1).ToList();//付款信息
  1716. _DailyFeePaymentResult.gz = _paymentDatas.Where(it => it.OrbitalPrivateTransfer == 0).Sum(it => ((it.PayMoney * it.DayRate) / 100) * it.PayPercentage); //公转
  1717. _DailyFeePaymentResult.sz = _paymentDatas.Where(it => it.OrbitalPrivateTransfer == 1).Sum(it => ((it.PayMoney * it.DayRate) / 100) * it.PayPercentage); ; //私转
  1718. List<int> groupIds = _paymentDatas.Select(it => it.DIId).Distinct().ToList();
  1719. var _groupDatas = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && groupIds.Contains(it.Id)).ToList();
  1720. //_groupDatas = (List<Grp_DelegationInfo>)_groupDatas.GroupBy(it => it.TeamDid);
  1721. #region 相关基础数据源
  1722. var userDatas = _sqlSugar.Queryable<Sys_Users>().ToList();
  1723. var setDatas = _sqlSugar.Queryable<Sys_SetData>().ToList();
  1724. var hotelDatas = _sqlSugar.Queryable<Grp_HotelReservations>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1725. var opDatas = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1726. var visaDatas = _sqlSugar.Queryable<Grp_VisaInfo>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DIId)).ToList();
  1727. var ioaDatas = _sqlSugar.Queryable<Grp_InvitationOfficialActivities>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1728. var insureDatas = _sqlSugar.Queryable<Grp_Customers>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1729. var airDatas = _sqlSugar.Queryable<Grp_AirTicketReservations>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DIId)).ToList();
  1730. var otherMoneyDatas = _sqlSugar.Queryable<Fin_OtherPrice>().Where(it => it.IsDel == 0 && groupIds.Contains(it.Diid)).ToList();
  1731. var refundPaymentDatas = _sqlSugar.Queryable<Fin_PaymentRefundAndOtherMoney>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1732. var ExtraCostDatas = _sqlSugar.Queryable<Fin_GroupExtraCost>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1733. #endregion
  1734. //Expense company
  1735. foreach (var groupInfo in _groupDatas)
  1736. {
  1737. List<Group_DailyFeePaymentContentInfolView> childList = new List<Group_DailyFeePaymentContentInfolView>();
  1738. var groupPaymentDatas = _paymentDatas.Where(it => groupInfo.Id == it.DIId).ToList();
  1739. int rouNumber = 1;
  1740. foreach (var payInfo in groupPaymentDatas)
  1741. {
  1742. string priName = "-";
  1743. string orbitalPrivateTransfer = payInfo.OrbitalPrivateTransfer == 0 ? "公转" : payInfo.OrbitalPrivateTransfer == 1 ? "私转" : "-";
  1744. switch (payInfo.CTable)
  1745. {
  1746. case 76: //76 酒店预订
  1747. priName = hotelDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.HotelName ?? "";
  1748. break;
  1749. case 79: //79 车/导游地接
  1750. var opData = opDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id);
  1751. if (opData != null)
  1752. {
  1753. if (payInfo.OrbitalPrivateTransfer == 0) //公转
  1754. {
  1755. priName = $"【{orbitalPrivateTransfer}】【导游: {opData.ServiceGuide}{opData.Area}";
  1756. }
  1757. else if (payInfo.OrbitalPrivateTransfer == 1) //私转
  1758. {
  1759. priName = $"【{orbitalPrivateTransfer}】【导游:{opData.ServiceGuide}{opData.Area}";
  1760. }
  1761. }
  1762. break;
  1763. case 80: // 80 签证
  1764. priName = visaDatas.Find(it => payInfo.DIId == it.DIId && payInfo.CId == it.Id)?.VisaClient ?? "-";
  1765. break;
  1766. case 81: // 81 邀请/公务活动
  1767. priName = ioaDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.Inviter ?? "-";
  1768. break;
  1769. case 82: // 82 团组客户保险
  1770. priName = insureDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.ClientName ?? "-";
  1771. break;
  1772. case 85: // 85 机票预订
  1773. string flightsCode = airDatas.Find(it => payInfo.DIId == it.DIId && payInfo.CId == it.Id)?.FlightsCode ?? "-";
  1774. string airPayType = setDatas.Find(it => it.Id == payInfo.PayDId)?.Name ?? "-";
  1775. priName = $"{flightsCode}{airPayType}】";
  1776. break;
  1777. case 98: // 98 其他款项
  1778. priName = otherMoneyDatas.Find(it => payInfo.DIId == it.Diid && payInfo.CId == it.Id)?.PriceName ?? "-";
  1779. break;
  1780. case 285: // 285 收款退还
  1781. priName = refundPaymentDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.PriceName ?? "-";
  1782. break;
  1783. case 1015: // 1015 超支费用
  1784. priName = ExtraCostDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.PriceName ?? "-";
  1785. break;
  1786. default:
  1787. priName = "";
  1788. break;
  1789. }
  1790. bool status1 = false;
  1791. if (_groupIds != null)
  1792. {
  1793. status1 = _groupIds.Contains(payInfo.Id);
  1794. }
  1795. var childInfo = new Group_DailyFeePaymentContentInfolView()
  1796. {
  1797. IsChecked = status1,
  1798. Id = payInfo.Id,
  1799. Payee = payInfo.Payee,
  1800. RowNumber = rouNumber,
  1801. Applicant = userDatas.Find(it => it.Id == payInfo.CreateUserId)?.CnName ?? "",
  1802. ApplicantDt = payInfo.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
  1803. PayType = setDatas.Find(it => it.Id == payInfo.PayDId)?.Name ?? "",
  1804. TransferMark = orbitalPrivateTransfer,
  1805. PriceName = priName,
  1806. ModuleName = setDatas.Find(it => it.Id == payInfo.CTable)?.Name ?? "",
  1807. PayCurrCode = setDatas.Find(it => it.Id == payInfo.PaymentCurrency)?.Name ?? "",
  1808. PaymentAmount = payInfo.PayMoney,
  1809. PayRate = payInfo.DayRate,
  1810. CNYSubTotalAmount = ((payInfo.DayRate * payInfo.PayMoney) / 100) * payInfo.PayPercentage //此次付款金额
  1811. };
  1812. string remaksDescription = $"【{childInfo.PayType}】【{childInfo.ModuleName}{rouNumber}、[申请人:{childInfo.Applicant}][收款方:{childInfo.Payee}]{priName}[{payInfo.ConsumptionPatterns}] {childInfo.PayCurrCode} {payInfo.PayMoney.ToString("#0.00")}、CNY:{childInfo.CNYSubTotalAmount.ToString("#0.00")}";
  1813. childInfo.RemaksDescription = remaksDescription;
  1814. childList.Add(childInfo);
  1815. rouNumber++;
  1816. }
  1817. CompanyInfo companyInfo = new CompanyInfo();
  1818. companyInfo = ExpenseCompanyByTeamId(groupInfo.TeamDid);
  1819. dataList.Add(new tree_Group_DailyFeePaymentPageListView()
  1820. {
  1821. Id = Guid.NewGuid().ToString("N"),
  1822. GroupName = groupInfo.TeamName,
  1823. CompanyId = companyInfo.Id,
  1824. ConpanyName = companyInfo.ConpanyName,
  1825. CNYTotalAmount = childList.Sum(it => it.CNYSubTotalAmount),
  1826. ChildList = childList,
  1827. });
  1828. }
  1829. _DailyFeePaymentResult.dataList = dataList;
  1830. return _DailyFeePaymentResult;
  1831. }
  1832. /// <summary>
  1833. /// 付款申请(日付申请相关)
  1834. /// 查询 根据日期范围
  1835. /// </summary>
  1836. /// <param name="_dailyIds"></param>
  1837. /// <param name="beginDt"></param>
  1838. /// <param name="endDt"></param>
  1839. /// <returns></returns>
  1840. private tree_Fin_DailyFeePaymentResult PayRequest_DailyByDateRange(int status, List<int> _dailyIds, string beginDt, string endDt)
  1841. {
  1842. #region sql条件处理
  1843. string sqlWhere = string.Format(@" And dfp.CreateTime between '{0} 00:00:00' And '{1} 23:59:59' ", beginDt, endDt);
  1844. if (status == 2)
  1845. {
  1846. if (_dailyIds.Count < 1)
  1847. {
  1848. return new tree_Fin_DailyFeePaymentResult() { childList = new List<Fin_DailyFeePaymentContentInfolView>() };
  1849. }
  1850. sqlWhere += string.Format(@" And dfp.Id In({0}) ", string.Join(",", _dailyIds));
  1851. }
  1852. string sql_1 = string.Format(@"Select * From (
  1853. Select row_number() over (order by dfp.Id Desc) as RowNumber,
  1854. dfp.Id,dfp.CompanyId,c.CompanyName,dfp.Instructions,dfp.SumPrice,
  1855. dfp.CreateUserId,u.CnName CreateUser,dfp.CreateTime,dfp.FAudit,dfp.MAudit,
  1856. dfp.PriceTypeId,dfp.TransferTypeId
  1857. From Fin_DailyFeePayment dfp
  1858. Inner Join Sys_Company c On dfp.CompanyId = c.Id
  1859. Left Join Sys_Users u On dfp.CreateUserId = u.Id
  1860. Where dfp.IsDel=0 {0} And dfp.FAudit = 1 And dfp.MAudit = 1 And dfp.IsPay = 0
  1861. ) temp ", sqlWhere);
  1862. #endregion
  1863. List<tree_Fin_DailyFeePaymentPageListView> DailyFeePaymentData = _sqlSugar.SqlQueryable<tree_Fin_DailyFeePaymentPageListView>(sql_1).ToList();
  1864. Dictionary<int, string> dic_setData = new Dictionary<int, string>();
  1865. foreach (var item in DailyFeePaymentData)
  1866. {
  1867. if (_dailyIds != null)
  1868. {
  1869. item.IsChecked = _dailyIds.Contains(item.Id);
  1870. }
  1871. if (dic_setData.ContainsKey(item.PriceTypeId))
  1872. {
  1873. item.priceTypeStr = dic_setData[item.PriceTypeId];
  1874. }
  1875. else
  1876. {
  1877. Sys_SetData sd_priceType = _daiRep.Query<Sys_SetData>(s => s.Id == item.PriceTypeId).First();
  1878. if (sd_priceType != null)
  1879. {
  1880. item.priceTypeStr = sd_priceType.Name;
  1881. dic_setData.Add(item.PriceTypeId, sd_priceType.Name);
  1882. }
  1883. }
  1884. if (dic_setData.ContainsKey(item.transferTypeId))
  1885. {
  1886. item.transferTypeIdStr = dic_setData[item.transferTypeId];
  1887. Sys_SetData sd_transfer = _daiRep.Query<Sys_SetData>(s => s.Id == item.transferTypeId).First();
  1888. if (sd_transfer != null)
  1889. {
  1890. item.transferParentId = sd_transfer.STid;
  1891. item.transferParentIdStr = sd_transfer.STid == 62 ? "公转" : sd_transfer.STid == 63 ? "私转" : "";
  1892. }
  1893. }
  1894. else
  1895. {
  1896. Sys_SetData sd_transfer = _daiRep.Query<Sys_SetData>(s => s.Id == item.transferTypeId).First();
  1897. if (sd_transfer != null)
  1898. {
  1899. item.transferTypeIdStr = sd_transfer.Name;
  1900. item.transferParentId = sd_transfer.STid;
  1901. item.transferParentIdStr = sd_transfer.STid == 62 ? "公转" : sd_transfer.STid == 63 ? "私转" : "";
  1902. dic_setData.Add(item.transferTypeId, sd_transfer.Name);
  1903. }
  1904. }
  1905. string feeContentSql = string.Format(@"Select * From Fin_DailyFeePaymentContent
  1906. Where IsDel=0 And DFPId = {0} ", item.Id);
  1907. item.childList = _sqlSugar.SqlQueryable<Fin_DailyFeePaymentContentInfolView>(feeContentSql).ToList();
  1908. int rowNumber = 1;
  1909. foreach (var subItem in item.childList)
  1910. {
  1911. string remaksDescription = $"{rowNumber}、【{item.priceTypeStr}{item.Instructions}({subItem.PriceName}) CNY:{subItem.ItemTotal.ToString("#0.00")}(单价:{subItem.Price.ToString("#0.00")} * {subItem.Quantity})";
  1912. subItem.RemaksDescription = remaksDescription;
  1913. string excelRemaksDescription = $"【{item.priceTypeStr}{item.Instructions}({subItem.PriceName}) CNY:{subItem.ItemTotal.ToString("#0.00")}(单价:{subItem.Price.ToString("#0.00")} * {subItem.Quantity})【申请人:{item.CreateUser} 申请时间:{item.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")}】";
  1914. subItem.ExcelRemaksDescription = excelRemaksDescription;
  1915. rowNumber++;
  1916. }
  1917. }
  1918. decimal total_gz = DailyFeePaymentData.Where(s => s.transferParentId == 62).Sum(d => d.SumPrice ?? 0M);
  1919. decimal total_sz = DailyFeePaymentData.Where(s => s.transferParentId == 63).Sum(d => d.SumPrice ?? 0M);
  1920. var result = new tree_Fin_DailyFeePaymentResult() { gz = total_gz, sz = total_sz, dataList = DailyFeePaymentData };
  1921. return result;
  1922. }
  1923. /// <summary>
  1924. /// 付款申请 (PageId=51)
  1925. /// 团组,日付相关费用 选中状态变更
  1926. /// </summary>
  1927. /// <param name="dto"></param>
  1928. /// <returns></returns>
  1929. [HttpPost]
  1930. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1931. public async Task<IActionResult> PostPayRequestCheckedChange(PayRequestCheckedChangeDto dto)
  1932. {
  1933. #region 验证
  1934. if (dto.Type < 1 || dto.Type > 2)
  1935. {
  1936. return Ok(JsonView(false, "请传入有效的Type参数! 1 checked 2 清除上次勾选"));
  1937. }
  1938. #endregion
  1939. try
  1940. {
  1941. PaymentRequestCheckedView requestCheckedView = new PaymentRequestCheckedView();
  1942. List<int> groupIds = new List<int>();
  1943. List<int> dailyPaymentIds = new List<int>();
  1944. #region 参数处理
  1945. if (!string.IsNullOrEmpty(dto.GroupIds))
  1946. {
  1947. if (dto.GroupIds.Contains(","))
  1948. {
  1949. groupIds = dto.GroupIds.Split(',').Select(int.Parse).ToList();
  1950. }
  1951. else
  1952. {
  1953. groupIds.Add(int.Parse(dto.GroupIds));
  1954. }
  1955. }
  1956. if (!string.IsNullOrEmpty(dto.DailyPaymentIds))
  1957. {
  1958. if (dto.DailyPaymentIds.Contains(","))
  1959. {
  1960. dailyPaymentIds = dto.DailyPaymentIds.Split(',').Select(int.Parse).ToList();
  1961. }
  1962. else
  1963. {
  1964. dailyPaymentIds.Add(int.Parse(dto.DailyPaymentIds));
  1965. }
  1966. }
  1967. #endregion
  1968. requestCheckedView.GroupIds = groupIds;
  1969. requestCheckedView.DailyPaymentIds = dailyPaymentIds;
  1970. if (dto.Type == 1)
  1971. {
  1972. TimeSpan ts = DateTime.Now.AddDays(180) - DateTime.Now; //设置redis 过期时间 半年(180)
  1973. var status = await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync<string>("paymentRequestCheckedData", JsonConvert.SerializeObject(requestCheckedView), ts);
  1974. if (status)
  1975. {
  1976. return Ok(JsonView(true, "操作成功!"));
  1977. }
  1978. }
  1979. else if (dto.Type == 2)
  1980. {
  1981. var status = await RedisRepository.RedisFactory.CreateRedisRepository().KeyDeleteAsync("paymentRequestCheckedData");
  1982. if (status)
  1983. {
  1984. return Ok(JsonView(true, "操作成功!"));
  1985. }
  1986. }
  1987. return Ok(JsonView(false, "操作失败!"));
  1988. }
  1989. catch (Exception ex)
  1990. {
  1991. return Ok(JsonView(false, ex.Message));
  1992. }
  1993. }
  1994. /// <summary>
  1995. /// 付款申请 (PageId=51)
  1996. /// 团组,日付相关费用 汇率变更
  1997. /// </summary>
  1998. /// <param name="dto"></param>
  1999. /// <returns></returns>
  2000. [HttpPost]
  2001. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2002. public async Task<IActionResult> PostPayRequestRateChange(PayRequestRateChangeDto dto)
  2003. {
  2004. #region 验证
  2005. DateTime beginDt, endDt;
  2006. string format = "yyyy-MM-dd";
  2007. if (!DateTime.TryParseExact(dto.beginDt, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out beginDt))
  2008. {
  2009. return Ok(JsonView(false, "开始日期格式不正确!正确格式:yyyy-MM-dd"));
  2010. }
  2011. if (!DateTime.TryParseExact(dto.endDt, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out endDt))
  2012. {
  2013. return Ok(JsonView(false, "结束日期格式不正确!正确格式:yyyy-MM-dd"));
  2014. }
  2015. if (dto.UserId < 1)
  2016. {
  2017. return Ok(JsonView(false, "请传入有效的UserId参数!"));
  2018. }
  2019. if (dto.Id < 1)
  2020. {
  2021. return Ok(JsonView(false, "请传入有效的Id参数!"));
  2022. }
  2023. if (dto.Rate <= 0)
  2024. {
  2025. return Ok(JsonView(false, "请传入有效的Rate参数!"));
  2026. }
  2027. #endregion
  2028. try
  2029. {
  2030. var status = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  2031. .SetColumns(it => it.DayRate == dto.Rate)
  2032. .Where(it => it.Id == dto.Id)
  2033. .ExecuteCommand();
  2034. if (status > 0)
  2035. {
  2036. PaymentRequestCheckedView checkedView = new PaymentRequestCheckedView();
  2037. var checkedStr = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("paymentRequestCheckedData");
  2038. if (checkedStr != null)
  2039. {
  2040. checkedView = JsonConvert.DeserializeObject<PaymentRequestCheckedView>(checkedStr.ToString());
  2041. }
  2042. tree_Fin_DailyFeePaymentResult dailyResult = PayRequest_DailyByDateRange(1, checkedView.DailyPaymentIds, dto.beginDt, dto.endDt);
  2043. tree_Group_DailyFeePaymentResult groupResult = PayRequest_GroupPaymentByDateRange(1, checkedView.GroupIds, dto.beginDt, dto.endDt);
  2044. decimal _gz = dailyResult.gz + groupResult.gz;
  2045. decimal _sz = dailyResult.sz + groupResult.sz;
  2046. return Ok(JsonView(true, "操作成功!", new { gz = dailyResult, sz = groupResult }));
  2047. }
  2048. return Ok(JsonView(false, "该项汇率修改失败!"));
  2049. }
  2050. catch (Exception ex)
  2051. {
  2052. return Ok(JsonView(false, ex.Message));
  2053. }
  2054. }
  2055. /// <summary>
  2056. /// 付款申请 (PageId=51)
  2057. /// 团组,日付相关费用 付款状态变更
  2058. /// </summary>
  2059. /// <param name="dto"></param>
  2060. /// <returns></returns>
  2061. [HttpPost]
  2062. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2063. public async Task<IActionResult> PostPayRequestPayChange(PayRequestPayChangeDto dto)
  2064. {
  2065. if (dto.UserId < 1)
  2066. {
  2067. return Ok(JsonView(false, "请传入有效的UserId参数!"));
  2068. }
  2069. //if (string.IsNullOrEmpty(dto.GroupIds))
  2070. //{
  2071. // return Ok(JsonView(false, "请传入有效的GroupIds参数!"));
  2072. //}
  2073. //if (string.IsNullOrEmpty(dto.DailyPaymentIds))
  2074. //{
  2075. // return Ok(JsonView(false, "请传入有效的DailyPaymentIds参数!"));
  2076. //}
  2077. try
  2078. {
  2079. List<int> groupIds = new List<int>();
  2080. List<int> dailyPaymentIds = new List<int>();
  2081. #region 参数处理
  2082. if (!string.IsNullOrEmpty(dto.GroupIds))
  2083. {
  2084. if (dto.GroupIds.Contains(","))
  2085. {
  2086. groupIds = dto.GroupIds.Split(',').Select(int.Parse).ToList();
  2087. }
  2088. else
  2089. {
  2090. groupIds.Add(int.Parse(dto.GroupIds));
  2091. }
  2092. }
  2093. if (!string.IsNullOrEmpty(dto.DailyPaymentIds))
  2094. {
  2095. if (dto.DailyPaymentIds.Contains(","))
  2096. {
  2097. dailyPaymentIds = dto.DailyPaymentIds.Split(',').Select(int.Parse).ToList();
  2098. }
  2099. else
  2100. {
  2101. dailyPaymentIds.Add(int.Parse(dto.DailyPaymentIds));
  2102. }
  2103. }
  2104. #endregion
  2105. bool changeStatus = false;
  2106. _sqlSugar.BeginTran();
  2107. if (groupIds.Count > 0)
  2108. {
  2109. var groupStatus = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  2110. .SetColumns(it => it.IsPay == 1)
  2111. .Where(it => groupIds.Contains(it.Id))
  2112. .ExecuteCommand();
  2113. if (groupStatus > 0)
  2114. {
  2115. changeStatus = true;
  2116. }
  2117. }
  2118. if (dailyPaymentIds.Count > 0)
  2119. {
  2120. var dailyPaymentStatus = _sqlSugar.Updateable<Fin_DailyFeePayment>()
  2121. .SetColumns(it => it.IsPay == 1)
  2122. .Where(it => dailyPaymentIds.Contains(it.Id))
  2123. .ExecuteCommand();
  2124. if (dailyPaymentStatus > 0)
  2125. {
  2126. changeStatus = true;
  2127. }
  2128. }
  2129. if (changeStatus)
  2130. {
  2131. _sqlSugar.CommitTran();
  2132. return Ok(JsonView(true, "操作成功!"));
  2133. }
  2134. _sqlSugar.RollbackTran();
  2135. return Ok(JsonView(false, "付款状态修改失败!"));
  2136. }
  2137. catch (Exception ex)
  2138. {
  2139. _sqlSugar.RollbackTran();
  2140. return Ok(JsonView(false, ex.Message));
  2141. }
  2142. }
  2143. /// <summary>
  2144. /// 付款申请 (PageId=51)
  2145. /// File Download
  2146. /// </summary>
  2147. /// <param name="dto"></param>
  2148. /// <returns></returns>
  2149. [HttpPost]
  2150. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2151. public async Task<IActionResult> PostPayRequestFileDownload(PayRequestFileDownloadDto dto)
  2152. {
  2153. Stopwatch stopwatch = Stopwatch.StartNew();
  2154. #region 参数,权限 验证
  2155. if (dto.PortType < 1)
  2156. {
  2157. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  2158. }
  2159. if (dto.UserId < 1)
  2160. {
  2161. return Ok(JsonView(false, "请传入有效的UserId参数!"));
  2162. }
  2163. if (dto.PageId < 1)
  2164. {
  2165. dto.PageId = 51;
  2166. return Ok(JsonView(false, "请传入有效的PageId参数!"));
  2167. }
  2168. if (dto.ConpanyId < 1 || dto.ConpanyId > 4)
  2169. {
  2170. return Ok(JsonView(false, "请传入有效的ConpanyId参数!"));
  2171. }
  2172. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  2173. #region 页面操作权限验证
  2174. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  2175. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限!"));
  2176. #endregion
  2177. #endregion
  2178. try
  2179. {
  2180. PaymentRequestCheckedView checkedView = new PaymentRequestCheckedView();
  2181. var checkedStr = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("paymentRequestCheckedData");
  2182. if (checkedStr != null)
  2183. {
  2184. checkedView = JsonConvert.DeserializeObject<PaymentRequestCheckedView>(checkedStr.ToString());
  2185. }
  2186. if (checkedView == null)
  2187. {
  2188. return Ok(JsonView(false, "没有选中的数据!"));
  2189. }
  2190. if (checkedView.GroupIds == null && checkedView.DailyPaymentIds == null)
  2191. {
  2192. return Ok(JsonView(false, "没有选中的数据!"));
  2193. }
  2194. tree_Fin_DailyFeePaymentResult dailyResult = PayRequest_DailyByDateRange(2, checkedView.DailyPaymentIds, dto.beginDt, dto.endDt);
  2195. tree_Group_DailyFeePaymentResult groupResult = PayRequest_GroupPaymentByDateRange(2, checkedView.GroupIds, dto.beginDt, dto.endDt);
  2196. if (dailyResult.childList == null)
  2197. {
  2198. dailyResult.childList = new List<Fin_DailyFeePaymentContentInfolView>();
  2199. }
  2200. List<tree_Group_DailyFeePaymentPageListView> _GroupData = new List<tree_Group_DailyFeePaymentPageListView>();
  2201. List<tree_Fin_DailyFeePaymentPageListView> _DailyData = new List<tree_Fin_DailyFeePaymentPageListView>();
  2202. //1 成都泛美商务有限公司
  2203. if (dto.ConpanyId == 1)
  2204. {
  2205. if (groupResult.dataList != null && groupResult.dataList.Count > 0) _GroupData = groupResult.dataList.Where(it => it.CompanyId == 1).ToList();
  2206. if (dailyResult.dataList != null && dailyResult.dataList.Count > 0) _DailyData = dailyResult.dataList.Where(it => it.CompanyId == 1).ToList();
  2207. }
  2208. //2 四川泛美交流有限公司
  2209. else if (dto.ConpanyId == 2)
  2210. {
  2211. if (groupResult.dataList != null && groupResult.dataList.Count > 0) _GroupData = groupResult.dataList.Where(it => it.CompanyId == 2).ToList();
  2212. if (dailyResult.dataList != null && dailyResult.dataList.Count > 0) _DailyData = dailyResult.dataList.Where(it => it.CompanyId == 2).ToList();
  2213. }
  2214. //3 成都纽茵教育科技有限公司
  2215. else if (dto.ConpanyId == 3)
  2216. {
  2217. if (groupResult.dataList != null && groupResult.dataList.Count > 0) _GroupData = groupResult.dataList.Where(it => it.CompanyId == 3).ToList();
  2218. if (dailyResult.dataList != null && dailyResult.dataList.Count > 0) _DailyData = dailyResult.dataList.Where(it => it.CompanyId == 3).ToList();
  2219. }
  2220. //4 成都鸿企中元科技有限公司
  2221. else if (dto.ConpanyId == 4)
  2222. {
  2223. return Ok(JsonView(false, "暂未开放该类型!"));
  2224. }
  2225. else
  2226. {
  2227. return Ok(JsonView(false, "参数ConpanyId不可使用!"));
  2228. }
  2229. string _requestPaymentDt = DateTime.Now.ToString("yyyy-MM-dd"),//申请付款日期
  2230. _appliedAmount = "", //申请付款金额
  2231. _GZStr = "", //公转价格描述
  2232. _SZStr = ""; //私转价格描述
  2233. decimal groupGZAmout = 0.00M, groupSZAmout = 0.00M;
  2234. decimal dailyGZAmout = 0.00M, dailySZAmout = 0.00M;
  2235. string dailyGZStr = "", dailySZStr = "", groupGZStr = "", groupSZStr = "";
  2236. #region 数据处理
  2237. //团组费用相关
  2238. foreach (var item in _GroupData)
  2239. {
  2240. string groupGZSubStr = "";
  2241. string groupSZSubStr = "";
  2242. foreach (var subItem in item.ChildList)
  2243. {
  2244. if (subItem.TransferMark.Equals("公转"))
  2245. {
  2246. groupGZAmout += subItem.CNYSubTotalAmount;
  2247. groupGZSubStr += $"{subItem.RemaksDescription}\r\n";
  2248. }
  2249. else if (subItem.TransferMark.Equals("私转"))
  2250. {
  2251. groupSZAmout += subItem.CNYSubTotalAmount;
  2252. groupSZSubStr += $"{subItem.RemaksDescription}\r\n";
  2253. }
  2254. groupGZSubStr += $"\t";
  2255. }
  2256. if (!string.IsNullOrEmpty(groupGZSubStr)) groupGZStr += $"团组:{item.GroupName}\r\n{groupGZSubStr}\r\n";
  2257. if (!string.IsNullOrEmpty(groupSZSubStr)) groupSZStr += $"团组:{item.GroupName}\r\n{groupSZSubStr}\r\n";
  2258. }
  2259. //日常费用相关
  2260. foreach (var item in _DailyData)
  2261. {
  2262. foreach (var subItem in item.childList)
  2263. {
  2264. if (item.transferParentId == 62) //公转
  2265. {
  2266. dailyGZAmout += item.SumPrice ?? 0.00M;
  2267. dailyGZStr += $"{item.RowNumber}、【{item.CompanyName}{subItem.ExcelRemaksDescription}\r\n";
  2268. }
  2269. else if (item.transferParentId == 63) //私转
  2270. {
  2271. dailySZAmout += item.SumPrice ?? 0.00M;
  2272. dailySZStr += $"{item.RowNumber}、【{item.CompanyName}{subItem.ExcelRemaksDescription}\r\n";
  2273. }
  2274. }
  2275. }
  2276. _GZStr = $"【公转】团组相关费用(合计:CNY {groupGZAmout.ToString("#0.00")}):\r\n{groupGZStr}【公转】日常付款费用(合计:CNY {dailyGZAmout.ToString("#0.00")}):\r\n{dailyGZStr}";
  2277. _SZStr = $"【私转】团组相关费用(合计:CNY {groupSZAmout.ToString("#0.00")}):\r\n{groupSZStr}【私转】日常付款费用(合计:CNY {dailySZAmout.ToString("#0.00")}):\r\n{dailySZStr}";
  2278. _appliedAmount = $"公转:CNY {(groupGZAmout + dailyGZAmout).ToString("#0.00")}\r\n私转:CNY {(groupSZAmout + dailySZAmout).ToString("#0.00")}";
  2279. #endregion
  2280. WorkbookDesigner designer = new WorkbookDesigner();
  2281. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/付款申请书.xls");
  2282. designer.SetDataSource("Date", _requestPaymentDt);
  2283. designer.SetDataSource("Price", _appliedAmount);
  2284. designer.SetDataSource("Content", _GZStr);
  2285. designer.SetDataSource("Content1", _SZStr);
  2286. //根据数据源处理生成报表内容
  2287. designer.Process();
  2288. string fileName = ("PayRequest/付款申请(" + dto.beginDt + "~" + dto.endDt + ").xlsx");
  2289. designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
  2290. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  2291. stopwatch.Stop();
  2292. return Ok(JsonView(true, $"操作成功!{stopwatch.ElapsedMilliseconds/1000}s", new { url = rst }));
  2293. }
  2294. catch (Exception ex)
  2295. {
  2296. return Ok(JsonView(false, ex.Message));
  2297. }
  2298. }
  2299. #endregion
  2300. #region 超支费用
  2301. /// <summary>
  2302. /// 超支费用
  2303. /// 1增、2改、3删
  2304. /// </summary>
  2305. /// <param name="dto"></param>
  2306. /// <returns></returns>
  2307. [HttpPost]
  2308. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2309. public async Task<IActionResult> PostGroupExtraCost_Operator(Fin_GroupExtraCostDto_OP dto)
  2310. {
  2311. #region 验证
  2312. #endregion
  2313. Fin_GroupExtraCost _entity = new Fin_GroupExtraCost();
  2314. _entity.DiId = dto.diId;
  2315. _entity.PriceName = dto.priceName;
  2316. _entity.Price = dto.price;
  2317. _entity.PriceCurrency = dto.currency;
  2318. _entity.PriceType = dto.priceType;
  2319. _entity.Coefficient = dto.coefficient;
  2320. _entity.PriceDetailType = dto.priceDetailType;
  2321. _entity.FilePath = dto.filePath;
  2322. _entity.Remark = dto.remark;
  2323. _entity.PriceCount = dto.PriceCount;
  2324. _entity.PriceDt = DateTime.Parse(dto.PriceDt);
  2325. _entity.PriceSum = dto.price * dto.PriceCount;
  2326. _daiRep.BeginTran();
  2327. if (dto.editType == 1)
  2328. {
  2329. _entity.CreateUserId = dto.createUser;
  2330. _entity.CreateTime = DateTime.Now;
  2331. _entity.IsDel = 0;
  2332. int returnId = await _daiRep.AddAsyncReturnId<Fin_GroupExtraCost>(_entity);
  2333. if (returnId > 0)
  2334. {
  2335. dto.Id = returnId;
  2336. }
  2337. }
  2338. else if (dto.editType == 2)
  2339. {
  2340. bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
  2341. {
  2342. PriceName = dto.priceName,
  2343. Price = dto.price,
  2344. PriceCurrency = dto.currency,
  2345. PriceType = dto.priceType,
  2346. PriceDetailType = dto.priceDetailType,
  2347. Coefficient = dto.coefficient,
  2348. FilePath = dto.filePath,
  2349. Remark = dto.remark,
  2350. PriceCount = dto.PriceCount,
  2351. PriceDt = _entity.PriceDt,
  2352. PriceSum = _entity.PriceSum
  2353. });
  2354. if (!res)
  2355. {
  2356. _daiRep.RollbackTran();
  2357. return Ok(JsonView(false, "2操作失败!"));
  2358. }
  2359. }
  2360. else if (dto.editType == 3)
  2361. {
  2362. string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  2363. bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
  2364. {
  2365. IsDel = 1,
  2366. DeleteTime = delTime,
  2367. DeleteUserId = dto.createUser
  2368. });
  2369. if (!res)
  2370. {
  2371. _daiRep.RollbackTran();
  2372. return Ok(JsonView(false, "3操作失败!"));
  2373. }
  2374. }
  2375. else
  2376. {
  2377. _daiRep.RollbackTran();
  2378. return Ok(JsonView(false, "未知的editType"));
  2379. }
  2380. if (!extraCost_editCreditCardPayment(dto))
  2381. {
  2382. return Ok(JsonView(false, "ccp操作失败"));
  2383. }
  2384. _daiRep.CommitTran();
  2385. return Ok(JsonView(true, "操作成功"));
  2386. }
  2387. private Result PostCurrencyByDiid_Sync(int diId, int CId, int currencyId)
  2388. {
  2389. if (diId == 0)
  2390. {
  2391. return new Result() { Code = -1, Msg = "请传入团组Id!" };
  2392. }
  2393. if (CId == 0)
  2394. {
  2395. return new Result() { Code = -1, Msg = "请传入类型Id!" };
  2396. }
  2397. if (currencyId == 0)
  2398. {
  2399. return new Result() { Code = -1, Msg = "请传入币种Id!" };
  2400. }
  2401. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == diId && a.IsDel == 0 && a.CTable == CId);
  2402. List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  2403. CurrencyInfo CurrencyRate = new CurrencyInfo();
  2404. try
  2405. {
  2406. if (_TeamRate != null)
  2407. {
  2408. Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == currencyId);
  2409. if (_SetData != null)
  2410. {
  2411. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  2412. CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
  2413. if (CurrencyRate != null)
  2414. {
  2415. return new Result() { Code = 0, Msg = "查询成功!", Data = CurrencyRate };
  2416. }
  2417. else
  2418. {
  2419. return new Result() { Code = -1, Msg = "暂无团组汇率,请前往设置!", Data = CurrencyRate };
  2420. }
  2421. }
  2422. else
  2423. {
  2424. return new Result() { Code = -1, Msg = "暂无团组汇率,请前往设置!", Data = CurrencyRate };
  2425. }
  2426. }
  2427. else
  2428. {
  2429. return new Result() { Code = -1, Msg = "暂无团组汇率,请前往设置!", Data = CurrencyRate };
  2430. }
  2431. }
  2432. catch (Exception)
  2433. {
  2434. return new Result() { Code = -1, Msg = "查询异常!", Data = CurrencyRate };
  2435. }
  2436. }
  2437. private bool extraCost_editCreditCardPayment(Fin_GroupExtraCostDto_OP costDto)
  2438. {
  2439. //设置团组汇率
  2440. decimal dcm_dayrate = 1M;
  2441. decimal dcm_rmbPrice = costDto.price;
  2442. int ispay = costDto.payType == 72 ? 1 : 0;
  2443. if (costDto.costSign != 3)
  2444. {
  2445. //获取新汇率 int diId,int CId, int currencyId
  2446. Result rate = this.PostCurrencyByDiid_Sync(costDto.diId, 1015, costDto.currency);
  2447. if (rate.Code == 0)
  2448. {
  2449. var rateInfo = (rate.Data as CurrencyInfo);
  2450. if (rateInfo is not null)
  2451. {
  2452. dcm_dayrate = rateInfo.Rate;
  2453. dcm_rmbPrice = rateInfo.Rate * dcm_rmbPrice;
  2454. }
  2455. else
  2456. {
  2457. dcm_dayrate = 1;
  2458. }
  2459. }
  2460. }
  2461. Grp_CreditCardPayment ccp = _daiRep.Query<Grp_CreditCardPayment>(s => s.CId == costDto.Id && s.CTable == 1015).First();
  2462. if (ccp == null)
  2463. {
  2464. ccp = new Grp_CreditCardPayment();
  2465. ccp.PayDId = costDto.payType;// dto
  2466. ccp.ConsumptionPatterns = "";
  2467. ccp.ConsumptionDate = "";
  2468. ccp.CTDId = costDto.payCardId;// dto
  2469. ccp.BankNo = "";
  2470. ccp.CardholderName = "";
  2471. ccp.PayMoney = costDto.price;// dto
  2472. ccp.PaymentCurrency = costDto.currency;// dto
  2473. ccp.CompanyBankNo = "";
  2474. ccp.OtherBankName = "";
  2475. ccp.OtherSideNo = "";
  2476. ccp.OtherSideName = "";
  2477. ccp.Remark = "";
  2478. ccp.CreateUserId = costDto.createUser;
  2479. ccp.CreateTime = DateTime.Now;
  2480. ccp.MFOperator = 0;
  2481. ccp.MFOperatorDate = "";
  2482. ccp.IsAuditDM = 0;
  2483. ccp.AuditDMOperate = 0;
  2484. ccp.AuditDMDate = "";
  2485. ccp.IsAuditMF = 0;
  2486. ccp.AuditMFOperate = 0;
  2487. ccp.AuditMFDate = "";
  2488. ccp.IsAuditGM = 0;
  2489. ccp.AuditGMOperate = 0;
  2490. ccp.AuditGMDate = "";
  2491. ccp.IsPay = ispay; // upd
  2492. ccp.DIId = costDto.diId;// dto
  2493. ccp.CId = costDto.Id;// dto
  2494. ccp.CTable = 1015; //超支费用指向id
  2495. ccp.IsDel = 0;
  2496. ccp.PayPercentage = 100M;
  2497. ccp.PayThenMoney = 0M;
  2498. ccp.PayPercentageOld = 100M;
  2499. ccp.PayThenMoneyOld = 0M;
  2500. ccp.UpdateDate = "";
  2501. ccp.Payee = costDto.payee;// dto
  2502. ccp.OrbitalPrivateTransfer = costDto.costSign;// dto
  2503. ccp.ExceedBudget = 0;
  2504. ccp.DayRate = dcm_dayrate; //upd
  2505. ccp.RMBPrice = dcm_rmbPrice; //upd
  2506. int ccpInsertId = _daiRep.AddReturnId<Grp_CreditCardPayment>(ccp);
  2507. if (ccpInsertId > 0)
  2508. {
  2509. return true;
  2510. }
  2511. }
  2512. else
  2513. {
  2514. if (costDto.editType == 2)
  2515. {
  2516. bool res = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
  2517. {
  2518. PayDId = costDto.payType,
  2519. CTDId = costDto.payCardId,
  2520. PayMoney = costDto.price,
  2521. PaymentCurrency = costDto.currency,
  2522. IsPay = ispay,
  2523. Payee = costDto.payee,
  2524. OrbitalPrivateTransfer = costDto.costSign,
  2525. DayRate = dcm_dayrate,
  2526. RMBPrice = dcm_rmbPrice
  2527. });
  2528. return res;
  2529. }
  2530. else if (costDto.editType == 3)
  2531. {
  2532. string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  2533. bool res2 = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
  2534. {
  2535. IsDel = 1,
  2536. DeleteTime = delTime,
  2537. DeleteUserId = costDto.createUser
  2538. });
  2539. return res2;
  2540. }
  2541. }
  2542. return false;
  2543. }
  2544. /// <summary>
  2545. /// 超支费用
  2546. /// 详情查询
  2547. /// </summary>
  2548. /// <param name="dto"></param>
  2549. /// <returns></returns>
  2550. [HttpPost]
  2551. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2552. public async Task<IActionResult> PostGroupExtraCost_Detail(Fin_GroupExtraCostDto_Detail dto)
  2553. {
  2554. if (dto.Id < 1)
  2555. {
  2556. return Ok(JsonView(false, "查询失败"));
  2557. }
  2558. string sql = string.Format(@" Select
  2559. f.Id,f.DiId,
  2560. f.PriceName,f.Price,f.PriceCurrency,c.Payee,c.OrbitalPrivateTransfer,c.PayDId,
  2561. c.CTDId,f.PriceType,f.PriceDetailType,f.Coefficient,f.Remark,f.PriceCount,f.PriceDt
  2562. From Fin_GroupExtraCost f
  2563. Inner Join Grp_CreditCardPayment c On f.Id = c.CId
  2564. Left Join Sys_Users u On f.CreateUserId = u.Id
  2565. Where f.IsDel=0 And c.CTable = 1015
  2566. And f.Id = {0} ", dto.Id);
  2567. Fin_GroupExtraCostDetailView detailView = await _sqlSugar.SqlQueryable<Fin_GroupExtraCostDetailView>(sql).FirstAsync();
  2568. if (detailView == null)
  2569. {
  2570. return Ok(JsonView(false, "查询失败"));
  2571. }
  2572. return Ok(JsonView(true, "查询成功", detailView));
  2573. }
  2574. /// <summary>
  2575. /// 超支费用
  2576. /// 列表查询
  2577. /// </summary>
  2578. /// <param name="dto"></param>
  2579. /// <returns></returns>
  2580. [HttpPost]
  2581. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2582. public async Task<IActionResult> PostGroupExtraCost_Search(Fin_GroupExtraCostDto_Search dto)
  2583. {
  2584. string sqlWhere = string.Format(@" And f.DiId = {0} ", dto.diId);
  2585. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  2586. int endIndex = startIndex + dto.PageSize - 1;
  2587. string sql_data = string.Format(@"Select * From (
  2588. Select row_number() over (order by f.Id Desc) as RowNumber,f.Id,f.DiId,
  2589. f.PriceName,f.PriceType,f.PriceDetailType,CAST(f.Price as varchar)+' '+s.[Name] as PriceStr,f.PriceCount,CAST(f.PriceSum as varchar)+' '+s.[Name] as PriceSumStr,
  2590. f.CreateUserId,f.PriceDt,c.IsAuditGM
  2591. From Fin_GroupExtraCost f
  2592. Inner Join Grp_CreditCardPayment c On f.Id = c.CId
  2593. Inner Join Sys_SetData s On f.PriceCurrency = s.Id
  2594. Left Join Sys_Users u On f.CreateUserId = u.Id
  2595. Where f.IsDel=0 And c.CTable = 1015 {0}
  2596. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  2597. string sql_count = string.Format(@"Select Count(1) as DataCount From (
  2598. Select row_number() over (order by f.Id Desc) as RowNumber,f.Id,f.DiId,
  2599. f.PriceName,f.PriceType,f.Price,f.FilePath,f.CreateUserId,f.CreateTime,c.IsAuditGM
  2600. From Fin_GroupExtraCost f
  2601. Inner Join Grp_CreditCardPayment c On f.Id = c.CId
  2602. Inner Join Sys_SetData s On f.PriceCurrency = s.Id
  2603. Left Join Sys_Users u On f.CreateUserId = u.Id
  2604. Where f.IsDel=0 And c.CTable = 1015 {0}
  2605. ) temp ", sqlWhere);
  2606. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  2607. {
  2608. //Fin_DailyFeePaymentPageCount
  2609. var count = await _sqlSugar.SqlQueryable<Fin_GroupExtraCostViewDataCount>(sql_count).FirstAsync();
  2610. List<Fin_GroupExtraCostView> dataList = await _sqlSugar.SqlQueryable<Fin_GroupExtraCostView>(sql_data).ToListAsync();
  2611. Dictionary<int, string> dic_setData = new Dictionary<int, string>();
  2612. Dictionary<int, string> dic_user = new Dictionary<int, string>();
  2613. foreach (var item in dataList)
  2614. {
  2615. DateTime dtTemp_PriceDt;
  2616. bool b_ct = DateTime.TryParse(item.PriceDt, out dtTemp_PriceDt);
  2617. if (b_ct)
  2618. {
  2619. item.PriceDt = dtTemp_PriceDt.ToString("yyyy-MM-dd");
  2620. }
  2621. //费用类型
  2622. if (dic_setData.ContainsKey(item.PriceType))
  2623. {
  2624. item.PriceTypeStr = dic_setData[item.PriceType];
  2625. }
  2626. else
  2627. {
  2628. Sys_SetData sd_priceTypeDetail = _daiRep.Query<Sys_SetData>(s => s.Id == item.PriceType).First();
  2629. if (sd_priceTypeDetail != null)
  2630. {
  2631. string tempName = sd_priceTypeDetail.Name.Replace("n", "");
  2632. item.PriceTypeStr = tempName;
  2633. dic_setData.Add(item.PriceType, tempName);
  2634. }
  2635. }
  2636. if (item.PriceDetailType > 0)
  2637. {
  2638. if (dic_setData.ContainsKey(item.PriceDetailType))
  2639. {
  2640. item.PriceTypeStr = item.PriceTypeStr + " - " + dic_setData[item.PriceDetailType];
  2641. }
  2642. else
  2643. {
  2644. Sys_SetData sd_priceTypeDetail = _daiRep.Query<Sys_SetData>(s => s.Id == item.PriceDetailType).First();
  2645. if (sd_priceTypeDetail != null)
  2646. {
  2647. string tempName = sd_priceTypeDetail.Name.Replace("n", "");
  2648. item.PriceTypeStr = item.PriceTypeStr + " - " + tempName;
  2649. dic_setData.Add(item.PriceDetailType, tempName);
  2650. }
  2651. }
  2652. }
  2653. //系统用户
  2654. if (dic_user.ContainsKey(item.CreateUserId))
  2655. {
  2656. item.CreateUserIdStr = dic_user[item.CreateUserId];
  2657. }
  2658. else
  2659. {
  2660. Sys_Users users = _daiRep.Query<Sys_Users>(s => s.Id == item.CreateUserId).First();
  2661. if (users != null)
  2662. {
  2663. item.CreateUserIdStr = users.CnName;
  2664. dic_user.Add(item.CreateUserId, users.CnName);
  2665. }
  2666. }
  2667. switch (item.IsAuditGM)
  2668. {
  2669. case 0: item.IsAuditGMStr = "未审核"; break;
  2670. case 1: item.IsAuditGMStr = "已通过"; break;
  2671. case 2: item.IsAuditGMStr = "未通过"; break;
  2672. default: item.IsAuditGMStr = "未知状态"; break;
  2673. }
  2674. }
  2675. var result = new ListViewBase<Fin_GroupExtraCostView>
  2676. {
  2677. CurrPageIndex = dto.PageIndex,
  2678. CurrPageSize = dto.PageSize,
  2679. DataCount = count.DataCount,
  2680. DataList = dataList
  2681. };
  2682. return Ok(JsonView(true, "查询成功", result));
  2683. }
  2684. return Ok(JsonView(false, "查询失败"));
  2685. }
  2686. /// <summary>
  2687. /// 超支费用
  2688. /// 数据集合配置
  2689. /// </summary>
  2690. /// <param name="dto"></param>
  2691. /// <returns></returns>
  2692. [HttpPost]
  2693. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2694. public async Task<IActionResult> PostGroupExtraCost_ListDataInit(Fin_GroupExtraCostDto_DataListInit dto)
  2695. {
  2696. //支付方式
  2697. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  2698. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  2699. //信用卡类型
  2700. List<Sys_SetData> Card = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 15 && a.IsDel == 0).ToList();
  2701. List<SetDataInfoView> _Card = _mapper.Map<List<SetDataInfoView>>(Card);
  2702. //超支费用类型
  2703. List<Sys_SetData> PriceType = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 79 && a.IsDel == 0).ToList();
  2704. List<SetDataInfoView> _PriceType = _mapper.Map<List<SetDataInfoView>>(PriceType);
  2705. //超支费用详细类型
  2706. List<Sys_SetData> PriceDetailType = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 80 && a.IsDel == 0).ToList();
  2707. PriceDetailType.ForEach(a => { a.Name = a.Name.Replace("n", ""); });
  2708. List<SetDataInfoView> _PriceDetailType = _mapper.Map<List<SetDataInfoView>>(PriceDetailType);
  2709. var data = new
  2710. {
  2711. Payment = _Payment,
  2712. Card = _Card,
  2713. PriceType = _PriceType,
  2714. PriceDetailType = _PriceDetailType
  2715. };
  2716. return Ok(JsonView(true, "", data));
  2717. }
  2718. /// <summary>
  2719. /// 超支费用
  2720. /// 导出团组超支费用Excel
  2721. /// </summary>
  2722. /// <param name="dto"></param>
  2723. /// <returns></returns>
  2724. [HttpPost]
  2725. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2726. public async Task<IActionResult> PostGroupExtraCost_OutputExcel(Fin_GroupExtraCostExcelDto dto)
  2727. {
  2728. string sqlGroup = string.Format(@" Select * From Grp_DelegationInfo WIth(Nolock) where Id = {0} ", dto.diId);
  2729. Grp_DelegationInfo grp_DelegationInfo = await _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sqlGroup).FirstAsync();
  2730. if (grp_DelegationInfo == null)
  2731. {
  2732. return Ok(JsonView(false, "导出失败,未查询到团组"));
  2733. }
  2734. Workbook workbook = new Workbook();
  2735. Worksheet sheet = workbook.Worksheets[0];
  2736. Cells cells = sheet.Cells;
  2737. //sheet.Protect(Aspose.Cells.ProtectionType.All, "123123", "");//保护工作表
  2738. //sheet.Protection.IsSelectingLockedCellsAllowed = true;//设置只能选择解锁单元格
  2739. //sheet.Protection.IsFormattingColumnsAllowed = true;//设置可以调整列
  2740. //sheet.Protection.IsFormattingRowsAllowed = true;//设置可以调整行
  2741. #region 数据源
  2742. string sqlData = string.Format(@" Select f.PriceType,REPLACE(s2.[Name],'超支费用','') as PriceTypeStr,'('+REPLACE(s3.[Name],'n','')+')' as PriceDetailTypeStr, PriceDt,PriceName,
  2743. Price,PriceCount,s.[Name] as Currency,PriceSum,f.Remark
  2744. From Fin_GroupExtraCost as f With(Nolock)
  2745. Inner Join Grp_CreditCardPayment as c With(Nolock) On f.Id = c.CId
  2746. Inner Join Sys_SetData as s With(Nolock) On f.PriceCurrency = s.Id
  2747. Inner Join Sys_SetData as s2 With(Nolock) On f.PriceType = s2.Id
  2748. Inner Join Sys_SetData as s3 With(Nolock) On f.PriceDetailType = s3.Id
  2749. Where f.DiId = {0} And f.IsDel=0 And c.CTable=1015
  2750. Order by PriceType ASC,PriceDt ASC ", dto.diId);
  2751. string sqlDataCount = string.Format(@" Select f.PriceType,COUNT(f.PriceType) as DataCount
  2752. From Fin_GroupExtraCost as f With(Nolock)
  2753. Inner Join Grp_CreditCardPayment as c With(Nolock) On f.Id = c.CId
  2754. Where f.DiId = {0} And f.IsDel=0 And c.CTable=1015
  2755. Group by PriceType ", dto.diId);
  2756. List<Fin_GroupExtraCost_ExcelView> dataList = await _sqlSugar.SqlQueryable<Fin_GroupExtraCost_ExcelView>(sqlData).ToListAsync();
  2757. List<Fin_GroupExtraCost_ExcelCountView> countList = await _sqlSugar.SqlQueryable<Fin_GroupExtraCost_ExcelCountView>(sqlDataCount).ToListAsync();
  2758. if (dataList.Count < 1 || countList.Count < 1)
  2759. {
  2760. return Ok(JsonView(false, "导出失败,未查询到数据"));
  2761. }
  2762. #endregion
  2763. #region 标题
  2764. string cellValue_Header = grp_DelegationInfo.TeamName;
  2765. //Aspose.Cells.Style style1 = workbook.Styles[workbook.Styles.Add()];//新增样式
  2766. Aspose.Cells.Style style_Header = workbook.CreateStyle();
  2767. style_Header.HorizontalAlignment = TextAlignmentType.Center;//文字居中
  2768. style_Header.VerticalAlignment = TextAlignmentType.Center;
  2769. style_Header.Font.Name = "微软雅黑";//文字字体
  2770. style_Header.Font.Size = 18;//文字大小
  2771. style_Header.IsLocked = false;//单元格解锁
  2772. style_Header.Font.IsBold = false;//粗体
  2773. style_Header.Font.Color = Color.FromArgb(255, 0, 0);
  2774. //style1.ForegroundColor = Color.FromArgb(0x99, 0xcc, 0xff);//设置背景色
  2775. //style1.Pattern = BackgroundType.Solid; //设置背景样式
  2776. //style1.IsTextWrapped = true;//单元格内容自动换行
  2777. style_Header.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线
  2778. style_Header.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线
  2779. style_Header.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线
  2780. style_Header.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线
  2781. cells.Merge(1, 1, 1, 10);
  2782. Aspose.Cells.Range range_header = cells.CreateRange(1, 1, 1, 10);
  2783. range_header.PutValue(cellValue_Header, false, false);
  2784. range_header.SetStyle(style_Header);
  2785. cells.SetRowHeight(1, 35);
  2786. #endregion
  2787. #region 列名
  2788. Aspose.Cells.Style style_colName = workbook.CreateStyle();
  2789. style_colName.Name = "colName";
  2790. style_colName.HorizontalAlignment = TextAlignmentType.Center;//文字居中
  2791. style_colName.VerticalAlignment = TextAlignmentType.Center;
  2792. style_colName.Font.Name = "微软雅黑";//文字字体
  2793. style_colName.Font.Size = 12;//文字大小
  2794. style_colName.IsLocked = false;//单元格解锁
  2795. style_colName.Font.IsBold = true;//粗体
  2796. style_colName.Font.Color = Color.FromArgb(0, 0, 0);
  2797. style_colName.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线
  2798. style_colName.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线
  2799. style_colName.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线
  2800. style_colName.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线
  2801. List<Fin_GroupExtraCostExcelColumnSetting> colNameSettingList = new List<Fin_GroupExtraCostExcelColumnSetting>()
  2802. {
  2803. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 1, columnName="类型", columnWidth= 25},
  2804. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 2, columnName="时间", columnWidth= 16},
  2805. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 3, columnName="内容", columnWidth= 35},
  2806. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 4, columnName="单价", columnWidth= 12},
  2807. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 5, columnName="数量", columnWidth= 12},
  2808. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 6, columnName="货币", columnWidth= 12},
  2809. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 7, columnName="费用", columnWidth= 12},
  2810. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 8, columnName="汇率", columnWidth= 12},
  2811. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 9, columnName="人民币", columnWidth= 12},
  2812. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 10, columnName="备注信息", columnWidth= 24}
  2813. };
  2814. foreach (var col in colNameSettingList)
  2815. {
  2816. cells[2, col.columnIndex].PutValue(col.columnName);
  2817. cells[2, col.columnIndex].SetStyle(style_colName);
  2818. cells.SetColumnWidth(col.columnIndex, col.columnWidth);
  2819. }
  2820. cells.SetRowHeight(2, 25);
  2821. #endregion
  2822. #region 数据填充
  2823. Aspose.Cells.Style style_dataCol = workbook.GetNamedStyle("colName");
  2824. style_dataCol.Font.IsBold = false;
  2825. style_dataCol.Name = "dataCol";
  2826. Aspose.Cells.Style style_dataBlue = workbook.CreateStyle();
  2827. style_dataBlue.HorizontalAlignment = TextAlignmentType.Center;//文字居中
  2828. style_dataBlue.VerticalAlignment = TextAlignmentType.Center;
  2829. style_dataBlue.Font.Name = "微软雅黑";//文字字体
  2830. style_dataBlue.Font.Size = 12;//文字大小
  2831. style_dataBlue.IsLocked = false;//单元格解锁
  2832. style_dataBlue.Font.IsBold = false;//粗体
  2833. style_dataBlue.ForegroundColor = Color.FromArgb(189, 215, 238);
  2834. style_dataBlue.Pattern = BackgroundType.Solid;
  2835. style_dataBlue.Font.Color = Color.FromArgb(0, 0, 0);
  2836. style_dataBlue.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线
  2837. style_dataBlue.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线
  2838. style_dataBlue.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线
  2839. style_dataBlue.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线
  2840. Aspose.Cells.Style style_dataYellow = workbook.CreateStyle();
  2841. style_dataYellow.HorizontalAlignment = TextAlignmentType.Center;//文字居中
  2842. style_dataYellow.VerticalAlignment = TextAlignmentType.Center;
  2843. style_dataYellow.Font.Name = "微软雅黑";//文字字体
  2844. style_dataYellow.Font.Size = 12;//文字大小
  2845. style_dataYellow.IsLocked = false;//单元格解锁
  2846. style_dataYellow.Font.IsBold = false;//粗体
  2847. style_dataYellow.ForegroundColor = Color.FromArgb(255, 242, 204);
  2848. style_dataYellow.Pattern = BackgroundType.Solid;
  2849. style_dataYellow.Font.Color = Color.FromArgb(0, 0, 0);
  2850. style_dataYellow.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线
  2851. style_dataYellow.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线
  2852. style_dataYellow.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线
  2853. style_dataYellow.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线
  2854. int rowIndex = 4;
  2855. foreach (var d in dataList)
  2856. {
  2857. //内容
  2858. string typeStr = d.PriceDetailTypeStr + d.PriceName;
  2859. cells["B" + rowIndex.ToString()].PutValue(d.PriceTypeStr);
  2860. cells["C" + rowIndex.ToString()].PutValue(d.PriceDtStr);
  2861. cells["D" + rowIndex.ToString()].PutValue(typeStr);
  2862. cells["E" + rowIndex.ToString()].PutValue(d.Price.ToString("#0.00"));
  2863. cells["F" + rowIndex.ToString()].PutValue(d.PriceCount);
  2864. cells["G" + rowIndex.ToString()].PutValue(d.Currency);
  2865. cells["H" + rowIndex.ToString()].PutValue(d.PriceSum.ToString("#0.00"));
  2866. cells["K" + rowIndex.ToString()].PutValue(d.Remark);
  2867. //样式
  2868. cells["B" + rowIndex.ToString()].SetStyle(style_dataCol);
  2869. cells["C" + rowIndex.ToString()].SetStyle(style_dataCol);
  2870. cells["D" + rowIndex.ToString()].SetStyle(style_dataCol);
  2871. cells["E" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2872. cells["F" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2873. cells["G" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2874. cells["H" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2875. cells["I" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2876. cells["J" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2877. cells["K" + rowIndex.ToString()].SetStyle(style_dataYellow);
  2878. //公式
  2879. cells["H" + rowIndex.ToString()].Formula = string.Format(@"E{0}*F{0}", rowIndex);
  2880. cells["J" + rowIndex.ToString()].Formula = string.Format(@"H{0}*I{0}", rowIndex);
  2881. cells.SetRowHeight(rowIndex - 1, 25);
  2882. rowIndex++;
  2883. }
  2884. cells["B" + rowIndex.ToString()].SetStyle(style_dataCol);
  2885. cells["C" + rowIndex.ToString()].SetStyle(style_dataCol);
  2886. cells["D" + rowIndex.ToString()].SetStyle(style_dataCol);
  2887. cells["E" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2888. cells["F" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2889. cells["G" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2890. cells["H" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2891. cells["I" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2892. cells["J" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2893. cells["K" + rowIndex.ToString()].SetStyle(style_dataYellow);
  2894. rowIndex++;
  2895. cells["B" + rowIndex.ToString()].SetStyle(style_dataCol);
  2896. cells["C" + rowIndex.ToString()].SetStyle(style_dataCol);
  2897. cells["D" + rowIndex.ToString()].SetStyle(style_dataCol);
  2898. cells["E" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2899. cells["F" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2900. cells["G" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2901. cells["H" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2902. cells["I" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2903. cells["J" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2904. cells["K" + rowIndex.ToString()].SetStyle(style_dataYellow);
  2905. rowIndex = 3;
  2906. int tempPriceType = 0;
  2907. foreach (var c in dataList)
  2908. {
  2909. if (tempPriceType == c.PriceType)
  2910. {
  2911. continue;
  2912. }
  2913. tempPriceType = c.PriceType;
  2914. int _rowCount = countList.First(s => s.PriceType == tempPriceType).DataCount;
  2915. cells.Merge(rowIndex, 1, _rowCount, 1);
  2916. Aspose.Cells.Range tempRange = cells.CreateRange(rowIndex, 1, _rowCount, 1);
  2917. rowIndex += _rowCount;
  2918. }
  2919. rowIndex = 4 + dataList.Count;
  2920. cells["D" + rowIndex.ToString()].PutValue("合计");
  2921. cells["J" + rowIndex.ToString()].Formula = string.Format(@"SUM(J4,J{0})", rowIndex - 1);
  2922. cells.SetRowHeight(rowIndex - 1, 25);
  2923. rowIndex++;
  2924. cells["D" + rowIndex.ToString()].PutValue("服务费10%开票税金8%");
  2925. cells["J" + rowIndex.ToString()].Formula = string.Format(@"J{0}*1.1*1.08", rowIndex - 1);
  2926. cells.SetRowHeight(rowIndex - 1, 25);
  2927. #endregion
  2928. #region IO
  2929. System.IO.MemoryStream ms = workbook.SaveToStream();//生成数据流
  2930. string fileName = ("GroupExtraCost/超支费用(" + cellValue_Header + ").xlsx");
  2931. byte[] bt = ms.ToArray();
  2932. workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
  2933. #endregion
  2934. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  2935. return Ok(JsonView(true, "成功", new { url = rst }));
  2936. }
  2937. #endregion
  2938. }
  2939. }