FinancialController.cs 148 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389
  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.DailyPaymentAudit(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 && it.NationalTravelFeeId > 0).ToList();
  836. if (_EnterExitCosts == null)
  837. {
  838. return Ok(JsonView(false, "该团组未填写出入境费用;"));
  839. }
  840. var _cityFee = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(it => it.IsDel == 0).ToList();
  841. foreach (var item in _DayAndCosts)
  842. {
  843. var cityInfo = _cityFee.Where(it => it.Id == item.NationalTravelFeeId).FirstOrDefault();
  844. if (cityInfo != null)
  845. {
  846. if (cityInfo.City.Contains("全部城市") || cityInfo.City.Contains("其他城市"))
  847. {
  848. item.Place = cityInfo.Country;
  849. }
  850. else item.Place = cityInfo.City;
  851. }
  852. }
  853. //数据源
  854. List<Grp_DayAndCost> dac1 = _DayAndCosts.Where(it => it.Type == 1).ToList(); //住宿费
  855. List<Grp_DayAndCost> dac2 = _DayAndCosts.Where(it => it.Type == 2).ToList(); //伙食费
  856. List<Grp_DayAndCost> dac3 = _DayAndCosts.Where(it => it.Type == 3).ToList(); //公杂费
  857. List<Grp_DayAndCost> dac4 = _DayAndCosts.Where(it => it.Type == 4).ToList(); //培训费
  858. //币种Data
  859. var currData = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
  860. var DeleClientList = _sqlSugar.Queryable<Grp_TourClientList>()
  861. .LeftJoin<Crm_DeleClient>((tcl, dc) => tcl.ClientId == dc.Id && dc.IsDel == 0)
  862. .LeftJoin<Crm_CustomerCompany>((tcl, dc, cc) => dc.CrmCompanyId == cc.Id && dc.IsDel == 0)
  863. .Where((tcl, dc, cc) => tcl.IsDel == 0 && tcl.DiId == dto.DiId)
  864. .Select((tcl, dc, cc) => new
  865. {
  866. Name = dc.LastName + dc.FirstName,
  867. Sex = dc.Sex,
  868. Birthday = dc.BirthDay,
  869. Company = cc.CompanyFullName,
  870. Job = dc.Job,
  871. AirType = tcl.ShippingSpaceTypeId
  872. })
  873. .ToList();
  874. if (DeleClientList.Count < 1)
  875. {
  876. return Ok(JsonView(false, "暂无团组成员,请先填写团组成员!!!"));
  877. }
  878. var _ClientNames = DeleClientList.Select(x => x.Name).ToList();
  879. var _GroupClient = DeleClientList.GroupBy(x => x.Company).ToList();
  880. Dictionary<string, string> bookmarkArr = null;
  881. string tempPath = AppSettingsHelper.Get("WordBasePath") + $"ForeignReceivables/Temp/汇款通知.docx";
  882. //载入模板
  883. Document doc = new Document(tempPath);
  884. DocumentBuilder builder = null;
  885. List<string> filesToZip = new List<string>();
  886. foreach (var ClientItem in _GroupClient) //遍历单位
  887. {
  888. doc = new Document(tempPath);
  889. builder = new DocumentBuilder(doc);
  890. Paragraph paragraph = new Paragraph(doc);
  891. bookmarkArr = new Dictionary<string, string>();
  892. bookmarkArr.Add("titleClientUnit", ClientItem.Key); //title单位
  893. bookmarkArr.Add("ClientUnit", ClientItem.Key); //单位
  894. bookmarkArr.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));//出发日期
  895. bookmarkArr.Add("name", string.Join(",", ClientItem.Select(x => x.Name).ToArray()).TrimEnd(','));//全部人员信息
  896. bookmarkArr.Add("VisitCountry", _DelegationInfo.VisitCountry);//出访国家
  897. bookmarkArr.Add("dayTime", DateTime.Now.ToString("yyyy年MM月dd日"));//今天日期
  898. var ClientItemList = ClientItem.ToList();
  899. string UsersTop = string.Empty;//word中人员以及金额
  900. decimal WordAllPrice = 0.00M;
  901. //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(),
  902. // 6, 3 + dac1.Where(x=>!string.IsNullOrWhiteSpace(x.Place)).Select(x=>(Convert.ToDecimal(x.SubTotal) / Convert.ToDecimal(x.Cost)).ToString().Length).Max() };
  903. //遍历人员
  904. for (int i = 0; i < ClientItemList.Count(); i++)
  905. {
  906. Dictionary<string, string> TeableBookmarkArr = new Dictionary<string, string>();
  907. var client = ClientItemList[i]; //每个人员
  908. var firstName = ClientItemList[i].Name;
  909. //计算费用总和
  910. decimal airPrice = client.AirType == 460 ? _EnterExitCosts.AirJJ : _EnterExitCosts.AirGW;
  911. decimal AllPrice = airPrice + _EnterExitCosts.CityTranffic + dac1.Sum(x => x.SubTotal) + dac2.Sum(x => x.SubTotal) +
  912. dac3.Sum(x => x.SubTotal) + dac4.Sum(x => x.SubTotal) + _EnterExitCosts.Visa + _EnterExitCosts.Safe +
  913. _EnterExitCosts.Service;
  914. WordAllPrice += AllPrice;
  915. UsersTop += firstName + "出访费用为¥" + AllPrice.ToString("#0.00") + "元、";
  916. TeableBookmarkArr.Add("jp", (client.AirType == 460 ? _EnterExitCosts.AirJJ : _EnterExitCosts.AirGW).ToString("#0.00") + " 元"); //机票金额
  917. TeableBookmarkArr.Add("cs", _EnterExitCosts.CityTranffic.ToString("#0.00") + " 元"); //城市交通费用
  918. TeableBookmarkArr.Add("zs", dac1.Sum(x => Convert.ToDecimal(x.SubTotal)).ToString("#0.00") + " 元"); //住宿费
  919. string zsinfo = string.Empty;
  920. string hsinfo = string.Empty;
  921. string gzinfo = string.Empty;
  922. List<string> placeArr = new List<string>();
  923. Aspose.Words.Tables.Table FirstTable = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 0, true);
  924. Aspose.Words.Tables.Table ChildTable = (Aspose.Words.Tables.Table)FirstTable.GetChild(NodeType.Table, 0, true);
  925. Aspose.Words.Tables.Table ChildTable1 = (Aspose.Words.Tables.Table)FirstTable.GetChild(NodeType.Table, 1, true);
  926. Aspose.Words.Tables.Table ChildTable2 = (Aspose.Words.Tables.Table)FirstTable.GetChild(NodeType.Table, 2, true);
  927. int rowIndex = 0;
  928. foreach (var item in dac1)
  929. {
  930. if (string.IsNullOrWhiteSpace(item.Place))
  931. {
  932. continue;
  933. }
  934. if (placeArr.Contains(item.Place))
  935. {
  936. continue;
  937. }
  938. else
  939. {
  940. placeArr.Add(item.Place);
  941. }
  942. if (!string.IsNullOrWhiteSpace(item.Place))
  943. {
  944. if (rowIndex > ChildTable.Rows.Count - 1)
  945. {
  946. var chitableRow = ChildTable.LastRow.Clone(true);
  947. ChildTable.AppendChild(chitableRow);
  948. }
  949. int days = dac1.FindAll(x => x.Place == item.Place).Count();
  950. SetCells(ChildTable, doc, rowIndex, 0, item.Place);
  951. SetCells(ChildTable, doc, rowIndex, 1, days + "晚");
  952. string currencyCode = currData.Find(it => it.Id == item.Currency)?.Remark ?? "Unknown";
  953. SetCells(ChildTable, doc, rowIndex, 2, item.Cost.ToString("#0.00") + currencyCode + "/晚");
  954. SetCells(ChildTable, doc, rowIndex, 3, " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00"));
  955. SetCells(ChildTable, doc, rowIndex, 4, "CNY" + item.SubTotal + "\r\n");
  956. rowIndex++;
  957. zsinfo += item.Place + " " + days + "晚 " + item.Cost.ToString("#0.00") + currencyCode + "/晚" + " 汇率" + (item.SubTotal / item.Cost).ToString("#0.0000") + " CNY" + item.SubTotal * days + "\r\n";
  958. }
  959. }
  960. placeArr.Clear();
  961. rowIndex = 0;
  962. foreach (var item in dac2)
  963. {
  964. if (string.IsNullOrWhiteSpace(item.Place))
  965. {
  966. continue;
  967. }
  968. if (placeArr.Contains(item.Place))
  969. {
  970. continue;
  971. }
  972. else
  973. {
  974. placeArr.Add(item.Place);
  975. }
  976. if (!string.IsNullOrWhiteSpace(item.Place))
  977. {
  978. if (rowIndex > ChildTable1.Rows.Count - 1)
  979. {
  980. var chitableRow = ChildTable1.LastRow.Clone(true);
  981. ChildTable1.AppendChild(chitableRow);
  982. }
  983. int days = dac2.FindAll(x => x.Place == item.Place).Count();
  984. SetCells(ChildTable1, doc, rowIndex, 0, item.Place);
  985. SetCells(ChildTable1, doc, rowIndex, 1, days + "天");
  986. string currencyCode = currData.Find(it => it.Id == item.Currency)?.Remark ?? "Unknown";
  987. SetCells(ChildTable1, doc, rowIndex, 2, item.Cost.ToString("#0.00") + currencyCode + "/天");
  988. SetCells(ChildTable1, doc, rowIndex, 3, " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00"));
  989. SetCells(ChildTable1, doc, rowIndex, 4, "CNY" + item.SubTotal);
  990. rowIndex++;
  991. hsinfo += item.Place + " " + days + "天 " + item.Cost.ToString("#0.00") + currencyCode + "/天" + " 汇率" + (item.SubTotal / item.Cost).ToString("#0.0000") + " CNY" + item.SubTotal * days + "\r\n";
  992. }
  993. }
  994. placeArr.Clear();
  995. rowIndex = 0;
  996. foreach (var item in dac3)
  997. {
  998. if (string.IsNullOrWhiteSpace(item.Place))
  999. {
  1000. continue;
  1001. }
  1002. if (placeArr.Contains(item.Place))
  1003. {
  1004. continue;
  1005. }
  1006. else
  1007. {
  1008. placeArr.Add(item.Place);
  1009. }
  1010. if (!string.IsNullOrWhiteSpace(item.Place))
  1011. {
  1012. if (rowIndex > ChildTable2.Rows.Count - 1)
  1013. {
  1014. var chitableRow = ChildTable2.LastRow.Clone(true);
  1015. ChildTable2.AppendChild(chitableRow);
  1016. }
  1017. int days = dac3.FindAll(x => x.Place == item.Place).Count();
  1018. SetCells(ChildTable2, doc, rowIndex, 0, item.Place);
  1019. SetCells(ChildTable2, doc, rowIndex, 1, days + "天");
  1020. string currencyCode = currData.Find(it => it.Id == item.Currency)?.Remark ?? "Unknown";
  1021. SetCells(ChildTable2, doc, rowIndex, 2, item.Cost.ToString("#0.00") + currencyCode + "/天");
  1022. SetCells(ChildTable2, doc, rowIndex, 3, " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00"));
  1023. SetCells(ChildTable2, doc, rowIndex, 4, "CNY" + item.SubTotal + "\r\n");
  1024. rowIndex++;
  1025. gzinfo += item.Place + " " + days + "天 " + item.Cost.ToString("#0.00") + currencyCode + "/天" + " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00") + " CNY" + item.SubTotal * days + "\r\n";
  1026. }
  1027. }
  1028. placeArr.Clear();
  1029. TeableBookmarkArr.Add("zsinfo", zsinfo); //住宿费详情
  1030. TeableBookmarkArr.Add("hs", dac2.Sum(x => Convert.ToDecimal(x.SubTotal)).ToString("#0.00") + " 元"); //伙食费
  1031. TeableBookmarkArr.Add("hsinfo", hsinfo); //伙食费详情
  1032. TeableBookmarkArr.Add("gz", dac3.Sum(x => Convert.ToDecimal(x.SubTotal)).ToString("#0.00") + " 元"); //公杂费
  1033. TeableBookmarkArr.Add("gzinfo", gzinfo); //公杂费详情
  1034. TeableBookmarkArr.Add("qt", (_EnterExitCosts.Visa + _EnterExitCosts.Safe).ToString("#0.00") + " 元");//其他费用
  1035. TeableBookmarkArr.Add("qtinfo", $"(签证费{_EnterExitCosts.Visa.ToString("#0.00")}元、保险{_EnterExitCosts.Safe.ToString("#0.00")}元等费用)");//其他费用第二列
  1036. TeableBookmarkArr.Add("fw", _EnterExitCosts.Service.ToString("#0.00") + "元/人");//服务费
  1037. TeableBookmarkArr.Add("AllPrice", AllPrice.ToString("#0.00") + "元/人");//表格合计费用
  1038. string airStr = client.AirType == 460 ? "经济舱" : client.AirType == 458 ? "公务舱" : "";
  1039. TeableBookmarkArr.Add("title", $"费用清单-{airStr}({firstName})");
  1040. foreach (var book in TeableBookmarkArr.Keys)
  1041. {
  1042. if (doc.Range.Bookmarks[book] != null)
  1043. {
  1044. Bookmark mark = doc.Range.Bookmarks[book];
  1045. mark.Text = TeableBookmarkArr[book];
  1046. }
  1047. }
  1048. if (i != ClientItemList.Count - 1)
  1049. {
  1050. builder.PageSetup.Orientation = Aspose.Words.Orientation.Portrait;
  1051. Aspose.Words.Tables.Table table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 0, true);
  1052. table.ParentNode.InsertAfter(paragraph, table);
  1053. var CloneTable = (Aspose.Words.Tables.Table)table.Clone(true);
  1054. table.ParentNode.InsertAfter(CloneTable, paragraph);
  1055. }
  1056. TeableBookmarkArr.Clear();
  1057. }
  1058. bookmarkArr.Add("VisitPrice", WordAllPrice.ToString());//出访费用总额
  1059. bookmarkArr.Add("CnAllPrice", WordAllPrice.ConvertCNYUpper());//出访费用总额中文
  1060. bookmarkArr.Add("namesPrice", UsersTop.TrimEnd('、'));//各人员出访费用 付辰同志出访费用为¥73,604.8元
  1061. foreach (var book in bookmarkArr.Keys)
  1062. {
  1063. if (doc.Range.Bookmarks[book] != null)
  1064. {
  1065. Bookmark mark = doc.Range.Bookmarks[book];
  1066. mark.Text = bookmarkArr[book];
  1067. }
  1068. }
  1069. //MemoryStream outSteam = new MemoryStream();
  1070. string filsPath = AppSettingsHelper.Get("WordBasePath") + $"ForeignReceivables/File/{ClientItem.Key.Replace("\n", "")}.docx";
  1071. doc.Save(filsPath);
  1072. filesToZip.Add(filsPath);
  1073. //streams.Add(ClientItem.Key + ".docx", outSteam.ToArray());
  1074. }
  1075. //文件名
  1076. string zipFileName = _DelegationInfo.TeamName + "-收款账单.zip";
  1077. string zipPath = $"ForeignReceivables/File/{_DelegationInfo.TeamName}-收款账单{DateTime.Now.ToString("yyyyMMddHHmmss")}.zip";
  1078. try
  1079. {
  1080. using (var zip = ZipFile.Open(AppSettingsHelper.Get("WordBasePath") + zipPath, ZipArchiveMode.Create))
  1081. {
  1082. foreach (var file in filesToZip)
  1083. {
  1084. zip.CreateEntryFromFile(file, Path.GetFileName(file));
  1085. }
  1086. }
  1087. }
  1088. catch (Exception ex)
  1089. {
  1090. return Ok(JsonView(false, ex.Message));
  1091. }
  1092. string url = AppSettingsHelper.Get("WordBaseUrl") + $"Office/Word/{zipPath}";
  1093. return Ok(JsonView(true, "成功", new { Url = url }));
  1094. }
  1095. return Ok(JsonView(false, "操作失败!"));
  1096. }
  1097. catch (Exception ex)
  1098. {
  1099. return Ok(JsonView(false, ex.Message));
  1100. }
  1101. }
  1102. private void SetCells(Aspose.Words.Tables.Table table, Document doc, int rows, int cells, string val)
  1103. {
  1104. //获取table中的某个单元格,从0开始
  1105. Aspose.Words.Tables.Cell lshCell = table.Rows[rows].Cells[cells];
  1106. //将单元格中的第一个段落移除
  1107. lshCell.FirstParagraph.Remove();
  1108. //新建一个段落
  1109. Paragraph p = new Paragraph(doc);
  1110. var r = new Run(doc, val);
  1111. r.Font.Size = 8;
  1112. //把设置的值赋给之前新建的段落
  1113. p.AppendChild(r);
  1114. //将此段落加到单元格内
  1115. lshCell.AppendChild(p);
  1116. }
  1117. #endregion
  1118. #region 已收款项
  1119. /// <summary>
  1120. /// 已收款项
  1121. /// 查询
  1122. /// </summary>
  1123. /// <param name="dto"></param>
  1124. /// <returns></returns>
  1125. [HttpPost]
  1126. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1127. public async Task<IActionResult> PostAmountReceived(AmountReceivedDto dto)
  1128. {
  1129. try
  1130. {
  1131. if (dto == null)
  1132. {
  1133. return Ok(JsonView(false, "参数不能为空!"));
  1134. }
  1135. Result ffrData = await _proceedsReceivedRep.PostAmountReceived(dto.DiId);
  1136. dynamic data = null;
  1137. if (dto.PortType == 1)
  1138. {
  1139. if (ffrData.Code != 0)
  1140. {
  1141. return Ok(JsonView(false, ffrData.Msg));
  1142. }
  1143. data = ffrData.Data;
  1144. }
  1145. else if (dto.PortType == 2)
  1146. {
  1147. if (ffrData.Code != 0)
  1148. {
  1149. return Ok(JsonView(false, ffrData.Msg));
  1150. }
  1151. data = ffrData.Data;
  1152. }
  1153. else if (dto.PortType == 2)
  1154. {
  1155. if (ffrData.Code != 0)
  1156. {
  1157. return Ok(JsonView(false, ffrData.Msg));
  1158. }
  1159. data = ffrData.Data;
  1160. }
  1161. else
  1162. {
  1163. return Ok(JsonView(false, "请选择正确的端口号!"));
  1164. }
  1165. return Ok(JsonView(true, "操作成功!", data));
  1166. }
  1167. catch (Exception ex)
  1168. {
  1169. return Ok(JsonView(false, ex.Message));
  1170. }
  1171. }
  1172. /// <summary>
  1173. /// 已收款项
  1174. /// Add Or Edit
  1175. /// </summary>
  1176. /// <param name="dto"></param>
  1177. /// <returns></returns>
  1178. [HttpPost]
  1179. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1180. public async Task<IActionResult> PostAmountReceivedAddOrEdit(AmountReceivedAddOrEditDto dto)
  1181. {
  1182. try
  1183. {
  1184. if (dto == null)
  1185. {
  1186. return Ok(JsonView(false, "参数不能为空!"));
  1187. }
  1188. Result ffrData = await _proceedsReceivedRep.PostAmountReceivedAddOrEditDto(dto);
  1189. if (dto.PortType == 1)
  1190. {
  1191. if (ffrData.Code != 0)
  1192. {
  1193. return Ok(JsonView(false, ffrData.Msg));
  1194. }
  1195. }
  1196. else if (dto.PortType == 2)
  1197. {
  1198. if (ffrData.Code != 0)
  1199. {
  1200. return Ok(JsonView(false, ffrData.Msg));
  1201. }
  1202. }
  1203. else if (dto.PortType == 2)
  1204. {
  1205. if (ffrData.Code != 0)
  1206. {
  1207. return Ok(JsonView(false, ffrData.Msg));
  1208. }
  1209. }
  1210. else
  1211. {
  1212. return Ok(JsonView(false, "请选择正确的端口号!"));
  1213. }
  1214. return Ok(JsonView(true, "操作成功!"));
  1215. }
  1216. catch (Exception ex)
  1217. {
  1218. return Ok(JsonView(false, ex.Message));
  1219. }
  1220. }
  1221. /// <summary>
  1222. /// 已收款项
  1223. /// Del
  1224. /// </summary>
  1225. /// <param name="dto"></param>
  1226. /// <returns></returns>
  1227. [HttpPost]
  1228. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1229. public async Task<IActionResult> PostAmountReceived_Del(AmountReceivedDelDto dto)
  1230. {
  1231. try
  1232. {
  1233. if (dto == null)
  1234. {
  1235. return Ok(JsonView(false, "参数不能为空!"));
  1236. }
  1237. Result ffrData = await _proceedsReceivedRep.PostAmountReceivedDel(dto);
  1238. if (ffrData.Code != 0)
  1239. {
  1240. return Ok(JsonView(false, ffrData.Msg));
  1241. }
  1242. return Ok(JsonView(true, "操作成功!"));
  1243. }
  1244. catch (Exception ex)
  1245. {
  1246. return Ok(JsonView(false, ex.Message));
  1247. }
  1248. }
  1249. #endregion
  1250. #region 收款退还与其他款项 --> 收款退还
  1251. /// <summary>
  1252. /// 收款退还与其他款项
  1253. /// 查询 根据团组Id
  1254. /// </summary>
  1255. /// <param name="dto"></param>
  1256. /// <returns></returns>
  1257. [HttpPost]
  1258. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1259. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyItemByDiId(PaymentRefundAndOtherMoneyItemByDiIdDto dto)
  1260. {
  1261. try
  1262. {
  1263. if (dto == null) return Ok(JsonView(false, "参数不能为空!"));
  1264. if (dto.PageId <= 0) return Ok(JsonView(false, "请传入正确的的页面Id!"));
  1265. if (dto.UserId <= 0) return Ok(JsonView(false, "请传入正确的的员工Id!"));
  1266. #region 页面功能权限处理
  1267. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  1268. pageFunAuth = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1269. if (pageFunAuth.CheckAuth == 0)
  1270. {
  1271. return Ok(JsonView(false, "您没有当前页面查询权限!"));
  1272. }
  1273. #endregion
  1274. Result _result = await _paymentRefundAndOtherMoneyRep._ItemByDiId(dto.DiId);
  1275. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //1 Web 2 Android 3 Ios
  1276. {
  1277. if (_result.Code != 0)
  1278. {
  1279. return Ok(JsonView(false, _result.Msg));
  1280. }
  1281. var data = new
  1282. {
  1283. PageFuncAuth = pageFunAuth,
  1284. Data = _result.Data
  1285. };
  1286. return Ok(JsonView(true, "操作成功!", data));
  1287. }
  1288. else
  1289. {
  1290. return Ok(JsonView(false, "请输入正确的端口号! 1 Web 2 Android 3 Ios;"));
  1291. }
  1292. }
  1293. catch (Exception ex)
  1294. {
  1295. return Ok(JsonView(false, ex.Message));
  1296. }
  1297. }
  1298. /// <summary>
  1299. /// 收款退还与其他款项
  1300. /// 删除
  1301. /// </summary>
  1302. /// <param name="dto"></param>
  1303. /// <returns></returns>
  1304. [HttpPost]
  1305. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1306. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyDel(PaymentRefundAndOtherMoneyDelDto dto)
  1307. {
  1308. try
  1309. {
  1310. if (dto == null) return Ok(JsonView(false, "参数不能为空!"));
  1311. if (dto.PageId <= 0) return Ok(JsonView(false, "请传入正确的的页面Id!"));
  1312. if (dto.UserId <= 0) return Ok(JsonView(false, "请传入正确的的员工Id!"));
  1313. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  1314. #region 页面功能权限处理
  1315. pageFunAuth = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1316. #endregion
  1317. if (pageFunAuth.DeleteAuth == 0)
  1318. {
  1319. return Ok(JsonView(false, "您没有当前页面删除权限!"));
  1320. }
  1321. Result _result = await _paymentRefundAndOtherMoneyRep._Del(dto);
  1322. if (_result.Code != 0)
  1323. {
  1324. return Ok(JsonView(false, _result.Msg));
  1325. }
  1326. return Ok(JsonView(true, "操作成功!"));
  1327. }
  1328. catch (Exception ex)
  1329. {
  1330. return Ok(JsonView(false, ex.Message));
  1331. }
  1332. }
  1333. /// <summary>
  1334. /// 收款退还与其他款项
  1335. /// Info Data Source
  1336. /// </summary>
  1337. /// <param name="dto"></param>
  1338. /// <returns></returns>
  1339. [HttpPost]
  1340. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1341. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyInfoDataSource(PortDtoBase dto)
  1342. {
  1343. try
  1344. {
  1345. Result _result = await _paymentRefundAndOtherMoneyRep._InfoDataSource(dto);
  1346. if (_result.Code != 0)
  1347. {
  1348. return Ok(JsonView(false, _result.Msg));
  1349. }
  1350. return Ok(JsonView(true, "查询成功!", _result.Data));
  1351. }
  1352. catch (Exception ex)
  1353. {
  1354. return Ok(JsonView(false, ex.Message));
  1355. }
  1356. }
  1357. /// <summary>
  1358. /// 收款退还与其他款项
  1359. /// Info
  1360. /// </summary>
  1361. /// <param name="dto"></param>
  1362. /// <returns></returns>
  1363. [HttpPost]
  1364. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1365. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyInfo(PaymentRefundAndOtherMoneyInfoDto dto)
  1366. {
  1367. try
  1368. {
  1369. if (dto == null)
  1370. {
  1371. return Ok(JsonView(false, "参数不能为空!"));
  1372. }
  1373. Result _result = await _paymentRefundAndOtherMoneyRep._Info(dto);
  1374. if (_result.Code != 0)
  1375. {
  1376. return Ok(JsonView(false, _result.Msg));
  1377. }
  1378. return Ok(JsonView(true, "查询成功!", _result.Data));
  1379. }
  1380. catch (Exception ex)
  1381. {
  1382. return Ok(JsonView(false, ex.Message));
  1383. }
  1384. }
  1385. /// <summary>
  1386. /// 收款退还与其他款项 --> 收款退还(只保留人名币)
  1387. /// 操作(Add Or Edit)
  1388. /// </summary>
  1389. /// <param name="dto"></param>
  1390. /// <returns></returns>
  1391. [HttpPost]
  1392. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1393. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyAddOrEdit(PaymentRefundAndOtherMoneyAddOrEditDto dto)
  1394. {
  1395. try
  1396. {
  1397. if (dto == null) return Ok(JsonView(false, "参数不能为空!"));
  1398. if (dto.PageId <= 0) return Ok(JsonView(false, "请传入正确的的页面Id!"));
  1399. if (dto.UserId <= 0) return Ok(JsonView(false, "请传入正确的的员工Id!"));
  1400. #region 页面功能权限处理
  1401. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  1402. pageFunAuth = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1403. #endregion
  1404. if (dto.Status == 1) //add
  1405. {
  1406. if (pageFunAuth.AddAuth == 0)
  1407. {
  1408. return Ok(JsonView(false, "您没有当前页面添加权限!"));
  1409. }
  1410. }
  1411. else if (dto.Status == 2) //edit
  1412. {
  1413. if (pageFunAuth.EditAuth == 0)
  1414. {
  1415. return Ok(JsonView(false, "您没有当前页面编辑权限!"));
  1416. }
  1417. }
  1418. else
  1419. {
  1420. return Ok(JsonView(false, "请输入正确的操作状态! 1 添加 2 修改!"));
  1421. }
  1422. Result _result = await _paymentRefundAndOtherMoneyRep._AddOrEdit(dto);
  1423. if (_result.Code != 0)
  1424. {
  1425. return Ok(JsonView(false, _result.Msg));
  1426. }
  1427. return Ok(JsonView(true, "操作成功!"));
  1428. }
  1429. catch (Exception ex)
  1430. {
  1431. return Ok(JsonView(false, ex.Message));
  1432. }
  1433. }
  1434. #endregion
  1435. #region 应收报表
  1436. /// <summary>
  1437. /// 应收报表
  1438. /// 查询 根据日期范围
  1439. /// </summary>
  1440. /// <param name="dto"></param>
  1441. /// <returns></returns>
  1442. [HttpPost]
  1443. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1444. public async Task<IActionResult> PostSyntheticalReceivableByDateRange(PostSyntheticalReceivableByDateRangeDto dto)
  1445. {
  1446. string sqlWhere = " Where di.IsDel=0 ";
  1447. #region 验证
  1448. if (string.IsNullOrEmpty(dto.beginDt) && string.IsNullOrEmpty(dto.endDt))
  1449. {
  1450. return Ok(JsonView(false, "日期参数至少填写一个!"));
  1451. }
  1452. if (!string.IsNullOrEmpty(dto.beginDt))
  1453. {
  1454. if (Regex.Match(dto.beginDt, @"^\d{4}-\d{2}-\d{2}$").Value.Length < 1)
  1455. {
  1456. return Ok(JsonView(false, "日期参数格式错误,应为yyyy-MM-dd!"));
  1457. }
  1458. else
  1459. {
  1460. sqlWhere += string.Format(@" And di.VisitDate >= '{0} 00:00:00' ", dto.beginDt);
  1461. }
  1462. }
  1463. if (!string.IsNullOrEmpty(dto.endDt))
  1464. {
  1465. if (Regex.Match(dto.endDt, @"^\d{4}-\d{2}-\d{2}$").Value.Length < 1)
  1466. {
  1467. return Ok(JsonView(false, "日期参数格式错误,应为yyyy-MM-dd!"));
  1468. }
  1469. else
  1470. {
  1471. sqlWhere += string.Format(@" And di.VisitDate <= '{0} 23:59:59' ", dto.endDt);
  1472. }
  1473. }
  1474. #endregion
  1475. //排序倒序
  1476. string sql = string.Format(@" select distinct fr.diid,di.TeamName,di.ClientUnit,di.VisitDate,di.CreateTime from Fin_ForeignReceivables fr join Grp_DelegationInfo di on fr.DIID = di.id {0} Order By di.CreateTime Desc", sqlWhere);
  1477. List<PostSyntheticalReceivableByDateRangeView> list_rst = _sqlSugar.SqlQueryable<PostSyntheticalReceivableByDateRangeView>(sql).ToList();
  1478. decimal sumAll_fr = 0M; //应收
  1479. decimal sumAll_pr = 0M; //已收
  1480. decimal sumAll_balance = 0M; //尾款
  1481. if (list_rst.Count > 0)
  1482. {
  1483. int rowNumber = 1;
  1484. foreach (var item_rst in list_rst)
  1485. {
  1486. DateTime dtTemp;
  1487. bool b = DateTime.TryParse(item_rst.visitDate, out dtTemp);
  1488. if (b)
  1489. {
  1490. item_rst.visitDate = dtTemp.ToString("yyyy-MM-dd");
  1491. }
  1492. item_rst.No = rowNumber;
  1493. rowNumber++;
  1494. int diId = item_rst.diid;
  1495. decimal sum_fr = 0M;
  1496. decimal sum_pr = 0M;
  1497. string str_client = string.Empty;
  1498. decimal sum_refund = 0M; //收款退还
  1499. decimal sum_extra = 0M; //超支费用
  1500. decimal balance = 0M;
  1501. string str_schedule = string.Empty;
  1502. //1.应收
  1503. string sql_fr = string.Format(@" Select * From Fin_ForeignReceivables Where IsDel=0 And Diid={0} ", diId);
  1504. List<Fin_ForeignReceivables> list_fr = _sqlSugar.SqlQueryable<Fin_ForeignReceivables>(sql_fr).ToList();
  1505. sum_fr = list_fr.Sum(s => s.ItemSumPrice);
  1506. //2.已收
  1507. string sql_pr = string.Format(@" Select * From Fin_ProceedsReceived Where IsDel=0 And Diid={0} ", diId);
  1508. List<Fin_ProceedsReceived> list_pr = _sqlSugar.SqlQueryable<Fin_ProceedsReceived>(sql_pr).ToList();
  1509. foreach (var item_pr in list_pr)
  1510. {
  1511. sum_pr += item_pr.Price;
  1512. str_client += string.Format(@"{0};", item_pr.Client);
  1513. str_schedule += string.Format(@"{0};", item_pr.Remark);
  1514. }
  1515. if (str_schedule.Length > 0)
  1516. {
  1517. str_schedule = str_schedule.TrimEnd(';');
  1518. }
  1519. if (str_client.Length > 0)
  1520. {
  1521. str_client = str_client.TrimEnd(';');
  1522. }
  1523. //3.收款退还
  1524. string sql_other = string.Format(@"Select * From Fin_PaymentRefundAndOtherMoney prao
  1525. Inner Join Grp_CreditCardPayment ccp On prao.Id = ccp.CId
  1526. Where ccp.CTable = 285 And ccp.IsPay = 1 And prao.IsDel = 0 And ccp.IsDel = 0 And prao.DiId = {0}", diId);
  1527. List<Grp_CreditCardPayment> list_other = _sqlSugar.SqlQueryable<Grp_CreditCardPayment>(sql_other).ToList();
  1528. sum_refund = list_other.Sum(s => s.RMBPrice);
  1529. //4.超支
  1530. string sql_extra = string.Format(@" Select c.* From Fin_GroupExtraCost f
  1531. Inner join Grp_CreditCardPayment c On f.Id = c.CId
  1532. Where c.CTable = 1015 And c.IsPay = 1 And f.IsDel = 0 And c.IsDel = 0 And f.DiId = {0} ", diId);
  1533. List<Grp_CreditCardPayment> list_extra = _sqlSugar.SqlQueryable<Grp_CreditCardPayment>(sql_extra).ToList();
  1534. sum_extra = list_extra.Sum(s => s.RMBPrice);
  1535. item_rst.frPrice = sum_fr.ToString("#0.00");
  1536. item_rst.extraPrice = sum_extra.ToString("#0.00");
  1537. item_rst.receivableTotal = (sum_fr + sum_extra).ToString("#0.00");
  1538. item_rst.prPrice = sum_pr.ToString("#0.00");
  1539. item_rst.refundAmount = sum_refund.ToString("#0.00");
  1540. item_rst.receivedTotal = (sum_pr - sum_refund).ToString("#0.00");
  1541. item_rst.balPrice = ((sum_fr + sum_extra) - (sum_pr - sum_refund)).ToString("#0.00");
  1542. item_rst.prClient = str_client;
  1543. item_rst.schedule = str_schedule;
  1544. string tempVisitDate = Convert.ToDateTime(item_rst.visitDate).ToString("yyyy-MM-dd");
  1545. sumAll_fr += (sum_fr + sum_extra);
  1546. sumAll_pr += (sum_pr - sum_refund);
  1547. sumAll_balance += ((sum_fr + sum_extra) - (sum_pr - sum_refund));
  1548. }
  1549. PostSyntheticalReceivableByDateRangeResultView result = new PostSyntheticalReceivableByDateRangeResultView();
  1550. result.total_fr = sumAll_fr.ToString("#0.00");
  1551. result.total_pr = sumAll_pr.ToString("#0.00");
  1552. result.total_balance = sumAll_balance.ToString("#0.00");
  1553. result.dataList = new List<PostSyntheticalReceivableByDateRangeView>(list_rst);
  1554. if (dto.requestType == 1)
  1555. {
  1556. return Ok(JsonView(true, "请求成功", result, list_rst.Count));
  1557. }
  1558. else
  1559. {
  1560. //----------------------------
  1561. List<Excel_SyntheticalReceivableByDateRange> list_Ex = new List<Excel_SyntheticalReceivableByDateRange>();
  1562. WorkbookDesigner designer = new WorkbookDesigner();
  1563. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/应收款项模板 - 副本.xls");
  1564. int excNo = 1;
  1565. foreach (var item in list_rst)
  1566. {
  1567. Excel_SyntheticalReceivableByDateRange exc = new Excel_SyntheticalReceivableByDateRange();
  1568. exc.No = excNo.ToString();
  1569. excNo++;
  1570. exc.TeamName = item.teamName;
  1571. exc.ClientUnit = item.clientUnit;
  1572. exc.VisitDate = item.visitDate;
  1573. exc.Accounts = item.frPrice;
  1574. exc.Extra = item.extraPrice;
  1575. exc.ReceivableTotal = item.receivableTotal;
  1576. exc.Received = item.prPrice;
  1577. exc.RefundAmount = item.refundAmount;
  1578. exc.ReceivedTotal = item.receivedTotal;
  1579. exc.Balance = item.balPrice;
  1580. exc.Collection = item.schedule;
  1581. DateTime time = Convert.ToDateTime(item.visitDate);
  1582. TimeSpan ts = DateTime.Now - time;
  1583. float SY = float.Parse(item.balPrice);
  1584. if (ts.Days >= 365 && SY > 0)
  1585. {
  1586. exc.Sign = "需收款";
  1587. }
  1588. else
  1589. {
  1590. exc.Sign = "";
  1591. }
  1592. list_Ex.Add(exc);
  1593. }
  1594. var dt = CommonFun.GetDataTableFromIList(list_Ex);
  1595. dt.TableName = "Excel_SyntheticalReceivableByDateRange";
  1596. if (dt != null)
  1597. {
  1598. designer.SetDataSource("SumPrice", "应收合计:" + result.total_fr + "RMB 已收合计:" + result.total_pr + "RMB 余款合计:" + result.total_balance + "RMB");
  1599. //数据源
  1600. designer.SetDataSource(dt);
  1601. //根据数据源处理生成报表内容
  1602. designer.Process();
  1603. string fileName = ("Receivable/应收款项(" + dto.beginDt + "~" + dto.endDt + ").xlsx");
  1604. designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
  1605. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  1606. return Ok(JsonView(true, "成功", new { url = rst }));
  1607. }
  1608. }
  1609. }
  1610. return Ok(JsonView(true, "获取成功", "", list_rst.Count));
  1611. }
  1612. #endregion
  1613. #region 付款申请
  1614. /// <summary>
  1615. /// 付款申请
  1616. /// 基础数据
  1617. /// </summary>
  1618. /// <param name="dto"></param>
  1619. /// <returns></returns>
  1620. [HttpPost]
  1621. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1622. public async Task<IActionResult> PostPayRequestInit()
  1623. {
  1624. try
  1625. {
  1626. var conpanyDatas = _sqlSugar.Queryable<Sys_Company>()
  1627. .Where(it => it.IsDel == 0)
  1628. .Select(it => new
  1629. {
  1630. Id = it.Id,
  1631. ConpamyName = it.CompanyName
  1632. }).ToList();
  1633. return Ok(JsonView(true, "操作成功!", new { ConpanyData = conpanyDatas }));
  1634. }
  1635. catch (Exception ex)
  1636. {
  1637. return Ok(JsonView(false, ex.Message));
  1638. }
  1639. }
  1640. /// <summary>
  1641. /// 付款申请 (PageId=51)
  1642. /// 查询 根据日期范围
  1643. /// </summary>
  1644. /// <param name="dto"></param>
  1645. /// <returns></returns>
  1646. [HttpPost]
  1647. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1648. public async Task<IActionResult> PostPayRequest_Center(PostPayRequestByDateRangeDto dto)
  1649. {
  1650. Stopwatch stopwatch = Stopwatch.StartNew();
  1651. #region 验证
  1652. DateTime beginDt, endDt;
  1653. string format = "yyyy-MM-dd";
  1654. if (!DateTime.TryParseExact(dto.beginDt, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out beginDt))
  1655. {
  1656. return Ok(JsonView(false, "开始日期格式不正确!正确格式:yyyy-MM-dd"));
  1657. }
  1658. if (!DateTime.TryParseExact(dto.endDt, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out endDt))
  1659. {
  1660. return Ok(JsonView(false, "结束日期格式不正确!正确格式:yyyy-MM-dd"));
  1661. }
  1662. #region 页面操作权限验证
  1663. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  1664. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1665. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  1666. #endregion
  1667. #endregion
  1668. try
  1669. {
  1670. PaymentRequestCheckedView checkedView = new PaymentRequestCheckedView();
  1671. var checkedStr = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("paymentRequestCheckedData");
  1672. if (checkedStr != null)
  1673. {
  1674. checkedView = JsonConvert.DeserializeObject<PaymentRequestCheckedView>(checkedStr.ToString());
  1675. }
  1676. tree_Fin_DailyFeePaymentResult dailyResult = PayRequest_DailyByDateRange(dto.Status, checkedView.DailyPaymentIds, dto.beginDt, dto.endDt);
  1677. tree_Group_DailyFeePaymentResult groupResult = PayRequest_GroupPaymentByDateRange(dto.Status, checkedView.GroupIds, dto.beginDt, dto.endDt);
  1678. stopwatch.Stop();
  1679. return Ok(JsonView(true, $"查询成功!耗时{stopwatch.ElapsedMilliseconds / 1000}s", new { daily = dailyResult, group = groupResult }));
  1680. }
  1681. catch (Exception ex)
  1682. {
  1683. return Ok(JsonView(false, ex.Message));
  1684. }
  1685. }
  1686. /// <summary>
  1687. /// 根据团组类型类型处理团组费用所属公司
  1688. /// </summary>
  1689. /// <param name="teamId"></param>
  1690. /// <returns></returns>
  1691. private CompanyInfo ExpenseCompanyByTeamId(int teamId)
  1692. {
  1693. CompanyInfo _companyInfo = new CompanyInfo();
  1694. List<int> _SiChuan = new List<int>() {
  1695. 38 , // 政府团
  1696. 39 , // 企业团
  1697. 40 , // 散客团
  1698. 102, // 未知
  1699. 248, // 非团组
  1700. 691, // 四川-会务活动
  1701. 762, // 四川-赛事项目收入
  1702. };
  1703. List<int> _ChengDu = new List<int>() {
  1704. 302, // 成都-会务活动
  1705. 1047, // 成都-赛事项目收入
  1706. };
  1707. if (_SiChuan.Contains(teamId))
  1708. {
  1709. _companyInfo.Id = 2;
  1710. _companyInfo.ConpanyName = "四川泛美交流有限公司";
  1711. }
  1712. if (_ChengDu.Contains(teamId))
  1713. {
  1714. _companyInfo.Id = 1;
  1715. _companyInfo.ConpanyName = "成都泛美商务有限公司";
  1716. }
  1717. return _companyInfo;
  1718. }
  1719. /// <summary>
  1720. /// 付款申请(团组费用申请相关)
  1721. /// 查询 根据日期范围
  1722. /// </summary>
  1723. /// <param name="_groupIds"></param>
  1724. /// <param name="beginDt"></param>
  1725. /// <param name="endDt"></param>
  1726. /// <returns></returns>
  1727. private tree_Group_DailyFeePaymentResult PayRequest_GroupPaymentByDateRange(int status, List<int> _groupIds, string beginDt, string endDt)
  1728. {
  1729. tree_Group_DailyFeePaymentResult _DailyFeePaymentResult = new tree_Group_DailyFeePaymentResult();
  1730. List<tree_Group_DailyFeePaymentPageListView> dataList = new List<tree_Group_DailyFeePaymentPageListView>();
  1731. #region sql条件处理
  1732. string sqlWhere = string.Format(@" And (AuditGMDate Between '{0} 00:00:00' And '{1} 23:59:59') ", beginDt, endDt);
  1733. if (status == 2)
  1734. {
  1735. if (_groupIds.Count < 1)
  1736. {
  1737. _DailyFeePaymentResult.dataList = new List<tree_Group_DailyFeePaymentPageListView>();
  1738. return _DailyFeePaymentResult;
  1739. }
  1740. sqlWhere += string.Format(@" And Id In ({0})", string.Join(",", _groupIds));
  1741. }
  1742. string sql_1 = string.Format(@"Select * From Grp_CreditCardPayment Where IsDel = 0 And IsPay = 0 And IsAuditGM = 1 {0}", sqlWhere);
  1743. #endregion
  1744. var _paymentDatas = _sqlSugar.SqlQueryable<Grp_CreditCardPayment>(sql_1).ToList();//付款信息
  1745. _DailyFeePaymentResult.gz = _paymentDatas.Where(it => it.OrbitalPrivateTransfer == 0).Sum(it => ((it.PayMoney * it.DayRate) / 100) * it.PayPercentage); //公转
  1746. _DailyFeePaymentResult.sz = _paymentDatas.Where(it => it.OrbitalPrivateTransfer == 1).Sum(it => ((it.PayMoney * it.DayRate) / 100) * it.PayPercentage); ; //私转
  1747. List<int> groupIds = _paymentDatas.Select(it => it.DIId).Distinct().ToList();
  1748. var _groupDatas = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && groupIds.Contains(it.Id)).ToList();
  1749. //_groupDatas = (List<Grp_DelegationInfo>)_groupDatas.GroupBy(it => it.TeamDid);
  1750. #region 相关基础数据源
  1751. var userDatas = _sqlSugar.Queryable<Sys_Users>().ToList();
  1752. var setDatas = _sqlSugar.Queryable<Sys_SetData>().ToList();
  1753. var hotelDatas = _sqlSugar.Queryable<Grp_HotelReservations>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1754. var opDatas = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1755. var visaDatas = _sqlSugar.Queryable<Grp_VisaInfo>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DIId)).ToList();
  1756. var ioaDatas = _sqlSugar.Queryable<Grp_InvitationOfficialActivities>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1757. var insureDatas = _sqlSugar.Queryable<Grp_Customers>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1758. var airDatas = _sqlSugar.Queryable<Grp_AirTicketReservations>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DIId)).ToList();
  1759. var otherMoneyDatas = _sqlSugar.Queryable<Fin_OtherPrice>().Where(it => it.IsDel == 0 && groupIds.Contains(it.Diid)).ToList();
  1760. var refundPaymentDatas = _sqlSugar.Queryable<Fin_PaymentRefundAndOtherMoney>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1761. var ExtraCostDatas = _sqlSugar.Queryable<Fin_GroupExtraCost>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1762. #endregion
  1763. //Expense company
  1764. foreach (var groupInfo in _groupDatas)
  1765. {
  1766. List<Group_DailyFeePaymentContentInfolView> childList = new List<Group_DailyFeePaymentContentInfolView>();
  1767. var groupPaymentDatas = _paymentDatas.Where(it => groupInfo.Id == it.DIId).ToList();
  1768. int rouNumber = 1;
  1769. foreach (var payInfo in groupPaymentDatas)
  1770. {
  1771. string priName = "-";
  1772. string orbitalPrivateTransfer = payInfo.OrbitalPrivateTransfer == 0 ? "公转" : payInfo.OrbitalPrivateTransfer == 1 ? "私转" : "-";
  1773. switch (payInfo.CTable)
  1774. {
  1775. case 76: //76 酒店预订
  1776. priName = hotelDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.HotelName ?? "";
  1777. break;
  1778. case 79: //79 车/导游地接
  1779. var opData = opDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id);
  1780. if (opData != null)
  1781. {
  1782. if (payInfo.OrbitalPrivateTransfer == 0) //公转
  1783. {
  1784. priName = $"【{orbitalPrivateTransfer}】【导游: {opData.ServiceGuide} 】{opData.Area}";
  1785. }
  1786. else if (payInfo.OrbitalPrivateTransfer == 1) //私转
  1787. {
  1788. priName = $"【{orbitalPrivateTransfer}】【导游:{opData.ServiceGuide}】{opData.Area}";
  1789. }
  1790. }
  1791. break;
  1792. case 80: // 80 签证
  1793. priName = visaDatas.Find(it => payInfo.DIId == it.DIId && payInfo.CId == it.Id)?.VisaClient ?? "-";
  1794. break;
  1795. case 81: // 81 邀请/公务活动
  1796. priName = ioaDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.Inviter ?? "-";
  1797. break;
  1798. case 82: // 82 团组客户保险
  1799. priName = insureDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.ClientName ?? "-";
  1800. break;
  1801. case 85: // 85 机票预订
  1802. string flightsCode = airDatas.Find(it => payInfo.DIId == it.DIId && payInfo.CId == it.Id)?.FlightsCode ?? "-";
  1803. string airPayType = setDatas.Find(it => it.Id == payInfo.PayDId)?.Name ?? "-";
  1804. priName = $"{flightsCode}【{airPayType}】";
  1805. break;
  1806. case 98: // 98 其他款项
  1807. priName = otherMoneyDatas.Find(it => payInfo.DIId == it.Diid && payInfo.CId == it.Id)?.PriceName ?? "-";
  1808. break;
  1809. case 285: // 285 收款退还
  1810. priName = refundPaymentDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.PriceName ?? "-";
  1811. break;
  1812. case 1015: // 1015 超支费用
  1813. priName = ExtraCostDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.PriceName ?? "-";
  1814. break;
  1815. default:
  1816. priName = "";
  1817. break;
  1818. }
  1819. bool status1 = false;
  1820. if (_groupIds != null)
  1821. {
  1822. status1 = _groupIds.Contains(payInfo.Id);
  1823. }
  1824. var childInfo = new Group_DailyFeePaymentContentInfolView()
  1825. {
  1826. IsChecked = status1,
  1827. Id = payInfo.Id,
  1828. Payee = payInfo.Payee,
  1829. RowNumber = rouNumber,
  1830. Applicant = userDatas.Find(it => it.Id == payInfo.CreateUserId)?.CnName ?? "",
  1831. ApplicantDt = payInfo.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
  1832. PayType = setDatas.Find(it => it.Id == payInfo.PayDId)?.Name ?? "",
  1833. TransferMark = orbitalPrivateTransfer,
  1834. PriceName = priName,
  1835. ModuleName = setDatas.Find(it => it.Id == payInfo.CTable)?.Name ?? "",
  1836. PayCurrCode = setDatas.Find(it => it.Id == payInfo.PaymentCurrency)?.Name ?? "",
  1837. PaymentAmount = payInfo.PayMoney,
  1838. PayRate = payInfo.DayRate,
  1839. CNYSubTotalAmount = ((payInfo.DayRate * payInfo.PayMoney) / 100) * payInfo.PayPercentage //此次付款金额
  1840. };
  1841. string remaksDescription = $"【{childInfo.PayType}】【{childInfo.ModuleName}】{rouNumber}、[申请人:{childInfo.Applicant}][收款方:{childInfo.Payee}]{priName},{payInfo.OtherBankName},{payInfo.OtherSideNo}[{payInfo.ConsumptionPatterns}] {childInfo.PayCurrCode} {payInfo.PayMoney.ToString("#0.00")}、CNY:{childInfo.CNYSubTotalAmount.ToString("#0.00")}";
  1842. childInfo.RemaksDescription = remaksDescription;
  1843. childList.Add(childInfo);
  1844. rouNumber++;
  1845. }
  1846. CompanyInfo companyInfo = new CompanyInfo();
  1847. companyInfo = ExpenseCompanyByTeamId(groupInfo.TeamDid);
  1848. dataList.Add(new tree_Group_DailyFeePaymentPageListView()
  1849. {
  1850. Id = Guid.NewGuid().ToString("N"),
  1851. GroupName = groupInfo.TeamName,
  1852. CompanyId = companyInfo.Id,
  1853. ConpanyName = companyInfo.ConpanyName,
  1854. CNYTotalAmount = childList.Sum(it => it.CNYSubTotalAmount),
  1855. ChildList = childList,
  1856. });
  1857. }
  1858. _DailyFeePaymentResult.dataList = dataList;
  1859. return _DailyFeePaymentResult;
  1860. }
  1861. /// <summary>
  1862. /// 付款申请(日付申请相关)
  1863. /// 查询 根据日期范围
  1864. /// </summary>
  1865. /// <param name="_dailyIds"></param>
  1866. /// <param name="beginDt"></param>
  1867. /// <param name="endDt"></param>
  1868. /// <returns></returns>
  1869. private tree_Fin_DailyFeePaymentResult PayRequest_DailyByDateRange(int status, List<int> _dailyIds, string beginDt, string endDt)
  1870. {
  1871. #region sql条件处理
  1872. string sqlWhere = string.Format(@" And dfp.CreateTime between '{0} 00:00:00' And '{1} 23:59:59' ", beginDt, endDt);
  1873. if (status == 2)
  1874. {
  1875. if (_dailyIds.Count < 1)
  1876. {
  1877. return new tree_Fin_DailyFeePaymentResult() { childList = new List<Fin_DailyFeePaymentContentInfolView>() };
  1878. }
  1879. sqlWhere += string.Format(@" And dfp.Id In({0}) ", string.Join(",", _dailyIds));
  1880. }
  1881. string sql_1 = string.Format(@"Select * From (
  1882. Select row_number() over (order by dfp.Id Desc) as RowNumber,
  1883. dfp.Id,dfp.CompanyId,c.CompanyName,dfp.Instructions,dfp.SumPrice,
  1884. dfp.CreateUserId,u.CnName CreateUser,dfp.CreateTime,dfp.FAudit,dfp.MAudit,
  1885. dfp.PriceTypeId,dfp.TransferTypeId
  1886. From Fin_DailyFeePayment dfp
  1887. Inner Join Sys_Company c On dfp.CompanyId = c.Id
  1888. Left Join Sys_Users u On dfp.CreateUserId = u.Id
  1889. Where dfp.IsDel=0 {0} And dfp.FAudit = 1 And dfp.MAudit = 1 And dfp.IsPay = 0
  1890. ) temp ", sqlWhere);
  1891. #endregion
  1892. List<tree_Fin_DailyFeePaymentPageListView> DailyFeePaymentData = _sqlSugar.SqlQueryable<tree_Fin_DailyFeePaymentPageListView>(sql_1).ToList();
  1893. Dictionary<int, string> dic_setData = new Dictionary<int, string>();
  1894. foreach (var item in DailyFeePaymentData)
  1895. {
  1896. if (_dailyIds != null)
  1897. {
  1898. item.IsChecked = _dailyIds.Contains(item.Id);
  1899. }
  1900. if (dic_setData.ContainsKey(item.PriceTypeId))
  1901. {
  1902. item.priceTypeStr = dic_setData[item.PriceTypeId];
  1903. }
  1904. else
  1905. {
  1906. Sys_SetData sd_priceType = _daiRep.Query<Sys_SetData>(s => s.Id == item.PriceTypeId).First();
  1907. if (sd_priceType != null)
  1908. {
  1909. item.priceTypeStr = sd_priceType.Name;
  1910. dic_setData.Add(item.PriceTypeId, sd_priceType.Name);
  1911. }
  1912. }
  1913. if (dic_setData.ContainsKey(item.transferTypeId))
  1914. {
  1915. item.transferTypeIdStr = dic_setData[item.transferTypeId];
  1916. Sys_SetData sd_transfer = _daiRep.Query<Sys_SetData>(s => s.Id == item.transferTypeId).First();
  1917. if (sd_transfer != null)
  1918. {
  1919. item.transferParentId = sd_transfer.STid;
  1920. item.transferParentIdStr = sd_transfer.STid == 0 ? "公转" : sd_transfer.STid == 1 ? "私转" : "";
  1921. }
  1922. }
  1923. else
  1924. {
  1925. Sys_SetData sd_transfer = _daiRep.Query<Sys_SetData>(s => s.Id == item.transferTypeId).First();
  1926. if (sd_transfer != null)
  1927. {
  1928. item.transferTypeIdStr = sd_transfer.Name;
  1929. item.transferParentId = sd_transfer.STid;
  1930. item.transferParentIdStr = sd_transfer.STid == 0 ? "公转" : sd_transfer.STid == 1 ? "私转" : "";
  1931. dic_setData.Add(item.transferTypeId, sd_transfer.Name);
  1932. }
  1933. }
  1934. string feeContentSql = string.Format(@"Select * From Fin_DailyFeePaymentContent
  1935. Where IsDel=0 And DFPId = {0} ", item.Id);
  1936. item.childList = _sqlSugar.SqlQueryable<Fin_DailyFeePaymentContentInfolView>(feeContentSql).ToList();
  1937. int rowNumber = 1;
  1938. foreach (var subItem in item.childList)
  1939. {
  1940. string remaksDescription = $"{rowNumber}、【{item.priceTypeStr}】{item.Instructions}({subItem.PriceName}) CNY:{subItem.ItemTotal.ToString("#0.00")}(单价:{subItem.Price.ToString("#0.00")} * {subItem.Quantity})";
  1941. subItem.RemaksDescription = remaksDescription;
  1942. 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")}】";
  1943. subItem.ExcelRemaksDescription = excelRemaksDescription;
  1944. rowNumber++;
  1945. }
  1946. }
  1947. decimal total_gz = DailyFeePaymentData.Where(s => s.transferParentId == 0).Sum(d => d.SumPrice ?? 0M);
  1948. decimal total_sz = DailyFeePaymentData.Where(s => s.transferParentId == 1).Sum(d => d.SumPrice ?? 0M);
  1949. var result = new tree_Fin_DailyFeePaymentResult() { gz = total_gz, sz = total_sz, dataList = DailyFeePaymentData };
  1950. return result;
  1951. }
  1952. /// <summary>
  1953. /// 付款申请 (PageId=51)
  1954. /// 团组,日付相关费用 选中状态变更
  1955. /// </summary>
  1956. /// <param name="dto"></param>
  1957. /// <returns></returns>
  1958. [HttpPost]
  1959. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1960. public async Task<IActionResult> PostPayRequestCheckedChange(PayRequestCheckedChangeDto dto)
  1961. {
  1962. #region 验证
  1963. if (dto.Type < 1 || dto.Type > 2)
  1964. {
  1965. return Ok(JsonView(false, "请传入有效的Type参数! 1 checked 2 清除上次勾选"));
  1966. }
  1967. #endregion
  1968. try
  1969. {
  1970. PaymentRequestCheckedView requestCheckedView = new PaymentRequestCheckedView();
  1971. List<int> groupIds = new List<int>();
  1972. List<int> dailyPaymentIds = new List<int>();
  1973. #region 参数处理
  1974. if (!string.IsNullOrEmpty(dto.GroupIds))
  1975. {
  1976. if (dto.GroupIds.Contains(","))
  1977. {
  1978. groupIds = dto.GroupIds.Split(',').Select(int.Parse).ToList();
  1979. }
  1980. else
  1981. {
  1982. groupIds.Add(int.Parse(dto.GroupIds));
  1983. }
  1984. }
  1985. if (!string.IsNullOrEmpty(dto.DailyPaymentIds))
  1986. {
  1987. if (dto.DailyPaymentIds.Contains(","))
  1988. {
  1989. dailyPaymentIds = dto.DailyPaymentIds.Split(',').Select(int.Parse).ToList();
  1990. }
  1991. else
  1992. {
  1993. dailyPaymentIds.Add(int.Parse(dto.DailyPaymentIds));
  1994. }
  1995. }
  1996. #endregion
  1997. requestCheckedView.GroupIds = groupIds;
  1998. requestCheckedView.DailyPaymentIds = dailyPaymentIds;
  1999. if (dto.Type == 1)
  2000. {
  2001. TimeSpan ts = DateTime.Now.AddDays(180) - DateTime.Now; //设置redis 过期时间 半年(180)
  2002. var status = await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync<string>("paymentRequestCheckedData", JsonConvert.SerializeObject(requestCheckedView), ts);
  2003. if (status)
  2004. {
  2005. return Ok(JsonView(true, "操作成功!"));
  2006. }
  2007. }
  2008. else if (dto.Type == 2)
  2009. {
  2010. var status = await RedisRepository.RedisFactory.CreateRedisRepository().KeyDeleteAsync("paymentRequestCheckedData");
  2011. if (status)
  2012. {
  2013. return Ok(JsonView(true, "操作成功!"));
  2014. }
  2015. }
  2016. return Ok(JsonView(false, "操作失败!"));
  2017. }
  2018. catch (Exception ex)
  2019. {
  2020. return Ok(JsonView(false, ex.Message));
  2021. }
  2022. }
  2023. /// <summary>
  2024. /// 付款申请 (PageId=51)
  2025. /// 团组,日付相关费用 汇率变更
  2026. /// </summary>
  2027. /// <param name="dto"></param>
  2028. /// <returns></returns>
  2029. [HttpPost]
  2030. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2031. public async Task<IActionResult> PostPayRequestRateChange(PayRequestRateChangeDto dto)
  2032. {
  2033. #region 验证
  2034. DateTime beginDt, endDt;
  2035. string format = "yyyy-MM-dd";
  2036. if (!DateTime.TryParseExact(dto.beginDt, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out beginDt))
  2037. {
  2038. return Ok(JsonView(false, "开始日期格式不正确!正确格式:yyyy-MM-dd"));
  2039. }
  2040. if (!DateTime.TryParseExact(dto.endDt, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out endDt))
  2041. {
  2042. return Ok(JsonView(false, "结束日期格式不正确!正确格式:yyyy-MM-dd"));
  2043. }
  2044. if (dto.UserId < 1)
  2045. {
  2046. return Ok(JsonView(false, "请传入有效的UserId参数!"));
  2047. }
  2048. if (dto.Id < 1)
  2049. {
  2050. return Ok(JsonView(false, "请传入有效的Id参数!"));
  2051. }
  2052. if (dto.Rate <= 0)
  2053. {
  2054. return Ok(JsonView(false, "请传入有效的Rate参数!"));
  2055. }
  2056. #endregion
  2057. try
  2058. {
  2059. var status = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  2060. .SetColumns(it => it.DayRate == dto.Rate)
  2061. .Where(it => it.Id == dto.Id)
  2062. .ExecuteCommand();
  2063. if (status > 0)
  2064. {
  2065. PaymentRequestCheckedView checkedView = new PaymentRequestCheckedView();
  2066. var checkedStr = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("paymentRequestCheckedData");
  2067. if (checkedStr != null)
  2068. {
  2069. checkedView = JsonConvert.DeserializeObject<PaymentRequestCheckedView>(checkedStr.ToString());
  2070. }
  2071. tree_Fin_DailyFeePaymentResult dailyResult = PayRequest_DailyByDateRange(1, checkedView.DailyPaymentIds, dto.beginDt, dto.endDt);
  2072. tree_Group_DailyFeePaymentResult groupResult = PayRequest_GroupPaymentByDateRange(1, checkedView.GroupIds, dto.beginDt, dto.endDt);
  2073. decimal _gz = dailyResult.gz + groupResult.gz;
  2074. decimal _sz = dailyResult.sz + groupResult.sz;
  2075. return Ok(JsonView(true, "操作成功!", new { gz = dailyResult, sz = groupResult }));
  2076. }
  2077. return Ok(JsonView(false, "该项汇率修改失败!"));
  2078. }
  2079. catch (Exception ex)
  2080. {
  2081. return Ok(JsonView(false, ex.Message));
  2082. }
  2083. }
  2084. /// <summary>
  2085. /// 付款申请 (PageId=51)
  2086. /// 团组,日付相关费用 付款状态变更
  2087. /// </summary>
  2088. /// <param name="dto"></param>
  2089. /// <returns></returns>
  2090. [HttpPost]
  2091. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2092. public async Task<IActionResult> PostPayRequestPayChange(PayRequestPayChangeDto dto)
  2093. {
  2094. if (dto.UserId < 1)
  2095. {
  2096. return Ok(JsonView(false, "请传入有效的UserId参数!"));
  2097. }
  2098. //if (string.IsNullOrEmpty(dto.GroupIds))
  2099. //{
  2100. // return Ok(JsonView(false, "请传入有效的GroupIds参数!"));
  2101. //}
  2102. //if (string.IsNullOrEmpty(dto.DailyPaymentIds))
  2103. //{
  2104. // return Ok(JsonView(false, "请传入有效的DailyPaymentIds参数!"));
  2105. //}
  2106. try
  2107. {
  2108. List<int> groupIds = new List<int>();
  2109. List<int> dailyPaymentIds = new List<int>();
  2110. #region 参数处理
  2111. if (!string.IsNullOrEmpty(dto.GroupIds))
  2112. {
  2113. if (dto.GroupIds.Contains(","))
  2114. {
  2115. groupIds = dto.GroupIds.Split(',').Select(int.Parse).ToList();
  2116. }
  2117. else
  2118. {
  2119. groupIds.Add(int.Parse(dto.GroupIds));
  2120. }
  2121. }
  2122. if (!string.IsNullOrEmpty(dto.DailyPaymentIds))
  2123. {
  2124. if (dto.DailyPaymentIds.Contains(","))
  2125. {
  2126. dailyPaymentIds = dto.DailyPaymentIds.Split(',').Select(int.Parse).ToList();
  2127. }
  2128. else
  2129. {
  2130. dailyPaymentIds.Add(int.Parse(dto.DailyPaymentIds));
  2131. }
  2132. }
  2133. #endregion
  2134. bool changeStatus = false;
  2135. _sqlSugar.BeginTran();
  2136. if (groupIds.Count > 0)
  2137. {
  2138. var groupStatus = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  2139. .SetColumns(it => it.IsPay == 1)
  2140. .Where(it => groupIds.Contains(it.Id))
  2141. .ExecuteCommand();
  2142. if (groupStatus > 0)
  2143. {
  2144. changeStatus = true;
  2145. }
  2146. }
  2147. if (dailyPaymentIds.Count > 0)
  2148. {
  2149. var dailyPaymentStatus = _sqlSugar.Updateable<Fin_DailyFeePayment>()
  2150. .SetColumns(it => it.IsPay == 1)
  2151. .Where(it => dailyPaymentIds.Contains(it.Id))
  2152. .ExecuteCommand();
  2153. if (dailyPaymentStatus > 0)
  2154. {
  2155. changeStatus = true;
  2156. }
  2157. }
  2158. if (changeStatus)
  2159. {
  2160. _sqlSugar.CommitTran();
  2161. return Ok(JsonView(true, "操作成功!"));
  2162. }
  2163. _sqlSugar.RollbackTran();
  2164. return Ok(JsonView(false, "付款状态修改失败!"));
  2165. }
  2166. catch (Exception ex)
  2167. {
  2168. _sqlSugar.RollbackTran();
  2169. return Ok(JsonView(false, ex.Message));
  2170. }
  2171. }
  2172. /// <summary>
  2173. /// 付款申请 (PageId=51)
  2174. /// File Download
  2175. /// </summary>
  2176. /// <param name="dto"></param>
  2177. /// <returns></returns>
  2178. [HttpPost]
  2179. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2180. public async Task<IActionResult> PostPayRequestFileDownload(PayRequestFileDownloadDto dto)
  2181. {
  2182. Stopwatch stopwatch = Stopwatch.StartNew();
  2183. #region 参数,权限 验证
  2184. if (dto.PortType < 1)
  2185. {
  2186. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  2187. }
  2188. if (dto.UserId < 1)
  2189. {
  2190. return Ok(JsonView(false, "请传入有效的UserId参数!"));
  2191. }
  2192. if (dto.PageId < 1)
  2193. {
  2194. dto.PageId = 51;
  2195. return Ok(JsonView(false, "请传入有效的PageId参数!"));
  2196. }
  2197. if (dto.ConpanyId < 1 || dto.ConpanyId > 4)
  2198. {
  2199. return Ok(JsonView(false, "请传入有效的ConpanyId参数!"));
  2200. }
  2201. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  2202. #region 页面操作权限验证
  2203. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  2204. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限!"));
  2205. #endregion
  2206. #endregion
  2207. try
  2208. {
  2209. PaymentRequestCheckedView checkedView = new PaymentRequestCheckedView();
  2210. var checkedStr = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("paymentRequestCheckedData");
  2211. if (checkedStr != null)
  2212. {
  2213. checkedView = JsonConvert.DeserializeObject<PaymentRequestCheckedView>(checkedStr.ToString());
  2214. }
  2215. if (checkedView == null)
  2216. {
  2217. return Ok(JsonView(false, "没有选中的数据!"));
  2218. }
  2219. if (checkedView.GroupIds == null && checkedView.DailyPaymentIds == null)
  2220. {
  2221. return Ok(JsonView(false, "没有选中的数据!"));
  2222. }
  2223. tree_Fin_DailyFeePaymentResult dailyResult = PayRequest_DailyByDateRange(2, checkedView.DailyPaymentIds, dto.beginDt, dto.endDt);
  2224. tree_Group_DailyFeePaymentResult groupResult = PayRequest_GroupPaymentByDateRange(2, checkedView.GroupIds, dto.beginDt, dto.endDt);
  2225. if (dailyResult.childList == null)
  2226. {
  2227. dailyResult.childList = new List<Fin_DailyFeePaymentContentInfolView>();
  2228. }
  2229. List<tree_Group_DailyFeePaymentPageListView> _GroupData = new List<tree_Group_DailyFeePaymentPageListView>();
  2230. List<tree_Fin_DailyFeePaymentPageListView> _DailyData = new List<tree_Fin_DailyFeePaymentPageListView>();
  2231. //1 成都泛美商务有限公司
  2232. if (dto.ConpanyId == 1)
  2233. {
  2234. if (groupResult.dataList != null && groupResult.dataList.Count > 0) _GroupData = groupResult.dataList.Where(it => it.CompanyId == 1).ToList();
  2235. if (dailyResult.dataList != null && dailyResult.dataList.Count > 0) _DailyData = dailyResult.dataList.Where(it => it.CompanyId == 1).ToList();
  2236. }
  2237. //2 四川泛美交流有限公司
  2238. else if (dto.ConpanyId == 2)
  2239. {
  2240. if (groupResult.dataList != null && groupResult.dataList.Count > 0) _GroupData = groupResult.dataList.Where(it => it.CompanyId == 2).ToList();
  2241. if (dailyResult.dataList != null && dailyResult.dataList.Count > 0) _DailyData = dailyResult.dataList.Where(it => it.CompanyId == 2).ToList();
  2242. }
  2243. //3 成都纽茵教育科技有限公司
  2244. else if (dto.ConpanyId == 3)
  2245. {
  2246. if (groupResult.dataList != null && groupResult.dataList.Count > 0) _GroupData = groupResult.dataList.Where(it => it.CompanyId == 3).ToList();
  2247. if (dailyResult.dataList != null && dailyResult.dataList.Count > 0) _DailyData = dailyResult.dataList.Where(it => it.CompanyId == 3).ToList();
  2248. }
  2249. //4 成都鸿企中元科技有限公司
  2250. else if (dto.ConpanyId == 4)
  2251. {
  2252. return Ok(JsonView(false, "暂未开放该类型!"));
  2253. }
  2254. else
  2255. {
  2256. return Ok(JsonView(false, "参数ConpanyId不可使用!"));
  2257. }
  2258. string _requestPaymentDt = DateTime.Now.ToString("yyyy-MM-dd"),//申请付款日期
  2259. _appliedAmount = "", //申请付款金额
  2260. _GZStr = "", //公转价格描述
  2261. _SZStr = ""; //私转价格描述
  2262. decimal groupGZAmout = 0.00M, groupSZAmout = 0.00M;
  2263. decimal dailyGZAmout = 0.00M, dailySZAmout = 0.00M;
  2264. string dailyGZStr = "", dailySZStr = "", groupGZStr = "", groupSZStr = "";
  2265. #region 数据处理
  2266. //团组费用相关
  2267. foreach (var item in _GroupData)
  2268. {
  2269. string groupGZSubStr = "";
  2270. string groupSZSubStr = "";
  2271. foreach (var subItem in item.ChildList)
  2272. {
  2273. if (subItem.TransferMark.Equals("公转"))
  2274. {
  2275. groupGZAmout += subItem.CNYSubTotalAmount;
  2276. groupGZSubStr += $"{subItem.RemaksDescription}\r\n";
  2277. }
  2278. else if (subItem.TransferMark.Equals("私转"))
  2279. {
  2280. groupSZAmout += subItem.CNYSubTotalAmount;
  2281. groupSZSubStr += $"{subItem.RemaksDescription}\r\n";
  2282. }
  2283. groupGZSubStr += $"\t";
  2284. }
  2285. if (!string.IsNullOrEmpty(groupGZSubStr)) groupGZStr += $"团组:{item.GroupName}\r\n{groupGZSubStr}\r\n";
  2286. if (!string.IsNullOrEmpty(groupSZSubStr)) groupSZStr += $"团组:{item.GroupName}\r\n{groupSZSubStr}\r\n";
  2287. }
  2288. //日常费用相关
  2289. foreach (var item in _DailyData)
  2290. {
  2291. foreach (var subItem in item.childList)
  2292. {
  2293. if (item.transferParentId == 62) //公转
  2294. {
  2295. dailyGZAmout += item.SumPrice ?? 0.00M;
  2296. dailyGZStr += $"{item.RowNumber}、【{item.CompanyName}】{subItem.ExcelRemaksDescription}\r\n";
  2297. }
  2298. else if (item.transferParentId == 63) //私转
  2299. {
  2300. dailySZAmout += item.SumPrice ?? 0.00M;
  2301. dailySZStr += $"{item.RowNumber}、【{item.CompanyName}】{subItem.ExcelRemaksDescription}\r\n";
  2302. }
  2303. }
  2304. }
  2305. _GZStr = $"【公转】团组相关费用(合计:CNY {groupGZAmout.ToString("#0.00")}):\r\n{groupGZStr}【公转】日常付款费用(合计:CNY {dailyGZAmout.ToString("#0.00")}):\r\n{dailyGZStr}";
  2306. _SZStr = $"【私转】团组相关费用(合计:CNY {groupSZAmout.ToString("#0.00")}):\r\n{groupSZStr}【私转】日常付款费用(合计:CNY {dailySZAmout.ToString("#0.00")}):\r\n{dailySZStr}";
  2307. _appliedAmount = $"公转:CNY {(groupGZAmout + dailyGZAmout).ToString("#0.00")}\r\n私转:CNY {(groupSZAmout + dailySZAmout).ToString("#0.00")}";
  2308. #endregion
  2309. WorkbookDesigner designer = new WorkbookDesigner();
  2310. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/付款申请书.xls");
  2311. designer.SetDataSource("Date", _requestPaymentDt);
  2312. designer.SetDataSource("Price", _appliedAmount);
  2313. designer.SetDataSource("Content", _GZStr);
  2314. designer.SetDataSource("Content1", _SZStr);
  2315. //根据数据源处理生成报表内容
  2316. designer.Process();
  2317. string fileName = ("PayRequest/付款申请(" + dto.beginDt + "~" + dto.endDt + ").xlsx");
  2318. designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
  2319. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  2320. stopwatch.Stop();
  2321. return Ok(JsonView(true, $"操作成功!{stopwatch.ElapsedMilliseconds / 1000}s", new { url = rst }));
  2322. }
  2323. catch (Exception ex)
  2324. {
  2325. return Ok(JsonView(false, ex.Message));
  2326. }
  2327. }
  2328. #endregion
  2329. #region 超支费用
  2330. /// <summary>
  2331. /// 超支费用
  2332. /// 1增、2改、3删
  2333. /// </summary>
  2334. /// <param name="dto"></param>
  2335. /// <returns></returns>
  2336. [HttpPost]
  2337. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2338. public async Task<IActionResult> PostGroupExtraCost_Operator(Fin_GroupExtraCostDto_OP dto)
  2339. {
  2340. #region 验证
  2341. #endregion
  2342. Fin_GroupExtraCost _entity = new Fin_GroupExtraCost();
  2343. _entity.DiId = dto.diId;
  2344. _entity.PriceName = dto.priceName;
  2345. _entity.Price = dto.price;
  2346. _entity.PriceCurrency = dto.currency;
  2347. _entity.PriceType = dto.priceType;
  2348. _entity.Coefficient = dto.coefficient;
  2349. _entity.PriceDetailType = dto.priceDetailType;
  2350. _entity.FilePath = dto.filePath;
  2351. _entity.Remark = dto.remark;
  2352. _entity.PriceCount = dto.PriceCount;
  2353. _entity.PriceDt = DateTime.Parse(dto.PriceDt);
  2354. _entity.PriceSum = dto.price * dto.PriceCount;
  2355. _daiRep.BeginTran();
  2356. if (dto.editType == 1)
  2357. {
  2358. _entity.CreateUserId = dto.createUser;
  2359. _entity.CreateTime = DateTime.Now;
  2360. _entity.IsDel = 0;
  2361. int returnId = await _daiRep.AddAsyncReturnId<Fin_GroupExtraCost>(_entity);
  2362. if (returnId > 0)
  2363. {
  2364. dto.Id = returnId;
  2365. }
  2366. }
  2367. else if (dto.editType == 2)
  2368. {
  2369. bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
  2370. {
  2371. PriceName = dto.priceName,
  2372. Price = dto.price,
  2373. PriceCurrency = dto.currency,
  2374. PriceType = dto.priceType,
  2375. PriceDetailType = dto.priceDetailType,
  2376. Coefficient = dto.coefficient,
  2377. FilePath = dto.filePath,
  2378. Remark = dto.remark,
  2379. PriceCount = dto.PriceCount,
  2380. PriceDt = _entity.PriceDt,
  2381. PriceSum = _entity.PriceSum
  2382. });
  2383. if (!res)
  2384. {
  2385. _daiRep.RollbackTran();
  2386. return Ok(JsonView(false, "2操作失败!"));
  2387. }
  2388. }
  2389. else if (dto.editType == 3)
  2390. {
  2391. string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  2392. bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
  2393. {
  2394. IsDel = 1,
  2395. DeleteTime = delTime,
  2396. DeleteUserId = dto.createUser
  2397. });
  2398. if (!res)
  2399. {
  2400. _daiRep.RollbackTran();
  2401. return Ok(JsonView(false, "3操作失败!"));
  2402. }
  2403. }
  2404. else
  2405. {
  2406. _daiRep.RollbackTran();
  2407. return Ok(JsonView(false, "未知的editType"));
  2408. }
  2409. if (!extraCost_editCreditCardPayment(dto))
  2410. {
  2411. return Ok(JsonView(false, "ccp操作失败"));
  2412. }
  2413. _daiRep.CommitTran();
  2414. return Ok(JsonView(true, "操作成功"));
  2415. }
  2416. private Result PostCurrencyByDiid_Sync(int diId, int CId, int currencyId)
  2417. {
  2418. if (diId == 0)
  2419. {
  2420. return new Result() { Code = -1, Msg = "请传入团组Id!" };
  2421. }
  2422. if (CId == 0)
  2423. {
  2424. return new Result() { Code = -1, Msg = "请传入类型Id!" };
  2425. }
  2426. if (currencyId == 0)
  2427. {
  2428. return new Result() { Code = -1, Msg = "请传入币种Id!" };
  2429. }
  2430. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == diId && a.IsDel == 0 && a.CTable == CId);
  2431. List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  2432. CurrencyInfo CurrencyRate = new CurrencyInfo();
  2433. try
  2434. {
  2435. if (_TeamRate != null)
  2436. {
  2437. Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == currencyId);
  2438. if (_SetData != null)
  2439. {
  2440. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  2441. CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
  2442. if (CurrencyRate != null)
  2443. {
  2444. return new Result() { Code = 0, Msg = "查询成功!", Data = CurrencyRate };
  2445. }
  2446. else
  2447. {
  2448. return new Result() { Code = -1, Msg = "暂无团组汇率,请前往设置!", Data = CurrencyRate };
  2449. }
  2450. }
  2451. else
  2452. {
  2453. return new Result() { Code = -1, Msg = "暂无团组汇率,请前往设置!", Data = CurrencyRate };
  2454. }
  2455. }
  2456. else
  2457. {
  2458. return new Result() { Code = -1, Msg = "暂无团组汇率,请前往设置!", Data = CurrencyRate };
  2459. }
  2460. }
  2461. catch (Exception)
  2462. {
  2463. return new Result() { Code = -1, Msg = "查询异常!", Data = CurrencyRate };
  2464. }
  2465. }
  2466. private bool extraCost_editCreditCardPayment(Fin_GroupExtraCostDto_OP costDto)
  2467. {
  2468. //设置团组汇率
  2469. decimal dcm_dayrate = 1M;
  2470. decimal dcm_rmbPrice = costDto.price;
  2471. int ispay = costDto.payType == 72 ? 1 : 0;
  2472. if (costDto.costSign != 3)
  2473. {
  2474. //获取新汇率 int diId,int CId, int currencyId
  2475. Result rate = this.PostCurrencyByDiid_Sync(costDto.diId, 1015, costDto.currency);
  2476. if (rate.Code == 0)
  2477. {
  2478. var rateInfo = (rate.Data as CurrencyInfo);
  2479. if (rateInfo is not null)
  2480. {
  2481. dcm_dayrate = rateInfo.Rate;
  2482. dcm_rmbPrice = rateInfo.Rate * dcm_rmbPrice;
  2483. }
  2484. else
  2485. {
  2486. dcm_dayrate = 1;
  2487. }
  2488. }
  2489. }
  2490. Grp_CreditCardPayment ccp = _daiRep.Query<Grp_CreditCardPayment>(s => s.CId == costDto.Id && s.CTable == 1015).First();
  2491. if (ccp == null)
  2492. {
  2493. ccp = new Grp_CreditCardPayment();
  2494. ccp.PayDId = costDto.payType;// dto
  2495. ccp.ConsumptionPatterns = "";
  2496. ccp.ConsumptionDate = "";
  2497. ccp.CTDId = costDto.payCardId;// dto
  2498. ccp.BankNo = "";
  2499. ccp.CardholderName = "";
  2500. ccp.PayMoney = costDto.price;// dto
  2501. ccp.PaymentCurrency = costDto.currency;// dto
  2502. ccp.CompanyBankNo = "";
  2503. ccp.OtherBankName = "";
  2504. ccp.OtherSideNo = "";
  2505. ccp.OtherSideName = "";
  2506. ccp.Remark = "";
  2507. ccp.CreateUserId = costDto.createUser;
  2508. ccp.CreateTime = DateTime.Now;
  2509. ccp.MFOperator = 0;
  2510. ccp.MFOperatorDate = "";
  2511. ccp.IsAuditDM = 0;
  2512. ccp.AuditDMOperate = 0;
  2513. ccp.AuditDMDate = "";
  2514. ccp.IsAuditMF = 0;
  2515. ccp.AuditMFOperate = 0;
  2516. ccp.AuditMFDate = "";
  2517. ccp.IsAuditGM = 0;
  2518. ccp.AuditGMOperate = 0;
  2519. ccp.AuditGMDate = "";
  2520. ccp.IsPay = ispay; // upd
  2521. ccp.DIId = costDto.diId;// dto
  2522. ccp.CId = costDto.Id;// dto
  2523. ccp.CTable = 1015; //超支费用指向id
  2524. ccp.IsDel = 0;
  2525. ccp.PayPercentage = 100M;
  2526. ccp.PayThenMoney = 0M;
  2527. ccp.PayPercentageOld = 100M;
  2528. ccp.PayThenMoneyOld = 0M;
  2529. ccp.UpdateDate = "";
  2530. ccp.Payee = costDto.payee;// dto
  2531. ccp.OrbitalPrivateTransfer = costDto.costSign;// dto
  2532. ccp.ExceedBudget = 0;
  2533. ccp.DayRate = dcm_dayrate; //upd
  2534. ccp.RMBPrice = dcm_rmbPrice; //upd
  2535. int ccpInsertId = _daiRep.AddReturnId<Grp_CreditCardPayment>(ccp);
  2536. if (ccpInsertId > 0)
  2537. {
  2538. return true;
  2539. }
  2540. }
  2541. else
  2542. {
  2543. if (costDto.editType == 2)
  2544. {
  2545. bool res = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
  2546. {
  2547. PayDId = costDto.payType,
  2548. CTDId = costDto.payCardId,
  2549. PayMoney = costDto.price,
  2550. PaymentCurrency = costDto.currency,
  2551. IsPay = ispay,
  2552. Payee = costDto.payee,
  2553. OrbitalPrivateTransfer = costDto.costSign,
  2554. DayRate = dcm_dayrate,
  2555. RMBPrice = dcm_rmbPrice
  2556. });
  2557. return res;
  2558. }
  2559. else if (costDto.editType == 3)
  2560. {
  2561. string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  2562. bool res2 = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
  2563. {
  2564. IsDel = 1,
  2565. DeleteTime = delTime,
  2566. DeleteUserId = costDto.createUser
  2567. });
  2568. return res2;
  2569. }
  2570. }
  2571. return false;
  2572. }
  2573. /// <summary>
  2574. /// 超支费用
  2575. /// 详情查询
  2576. /// </summary>
  2577. /// <param name="dto"></param>
  2578. /// <returns></returns>
  2579. [HttpPost]
  2580. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2581. public async Task<IActionResult> PostGroupExtraCost_Detail(Fin_GroupExtraCostDto_Detail dto)
  2582. {
  2583. if (dto.Id < 1)
  2584. {
  2585. return Ok(JsonView(false, "查询失败"));
  2586. }
  2587. string sql = string.Format(@" Select
  2588. f.Id,f.DiId,
  2589. f.PriceName,f.Price,f.PriceCurrency,c.Payee,c.OrbitalPrivateTransfer,c.PayDId,
  2590. c.CTDId,f.PriceType,f.PriceDetailType,f.Coefficient,f.Remark,f.PriceCount,f.PriceDt
  2591. From Fin_GroupExtraCost f
  2592. Inner Join Grp_CreditCardPayment c On f.Id = c.CId
  2593. Left Join Sys_Users u On f.CreateUserId = u.Id
  2594. Where f.IsDel=0 And c.CTable = 1015
  2595. And f.Id = {0} ", dto.Id);
  2596. Fin_GroupExtraCostDetailView detailView = await _sqlSugar.SqlQueryable<Fin_GroupExtraCostDetailView>(sql).FirstAsync();
  2597. if (detailView == null)
  2598. {
  2599. return Ok(JsonView(false, "查询失败"));
  2600. }
  2601. return Ok(JsonView(true, "查询成功", detailView));
  2602. }
  2603. /// <summary>
  2604. /// 超支费用
  2605. /// 列表查询
  2606. /// </summary>
  2607. /// <param name="dto"></param>
  2608. /// <returns></returns>
  2609. [HttpPost]
  2610. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2611. public async Task<IActionResult> PostGroupExtraCost_Search(Fin_GroupExtraCostDto_Search dto)
  2612. {
  2613. string sqlWhere = string.Format(@" And f.DiId = {0} ", dto.diId);
  2614. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  2615. int endIndex = startIndex + dto.PageSize - 1;
  2616. string sql_data = string.Format(@"Select * From (
  2617. Select row_number() over (order by f.Id Desc) as RowNumber,f.Id,f.DiId,
  2618. 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,
  2619. f.CreateUserId,f.PriceDt,c.IsAuditGM
  2620. From Fin_GroupExtraCost f
  2621. Inner Join Grp_CreditCardPayment c On f.Id = c.CId
  2622. Inner Join Sys_SetData s On f.PriceCurrency = s.Id
  2623. Left Join Sys_Users u On f.CreateUserId = u.Id
  2624. Where f.IsDel=0 And c.CTable = 1015 {0}
  2625. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  2626. string sql_count = string.Format(@"Select Count(1) as DataCount From (
  2627. Select row_number() over (order by f.Id Desc) as RowNumber,f.Id,f.DiId,
  2628. f.PriceName,f.PriceType,f.Price,f.FilePath,f.CreateUserId,f.CreateTime,c.IsAuditGM
  2629. From Fin_GroupExtraCost f
  2630. Inner Join Grp_CreditCardPayment c On f.Id = c.CId
  2631. Inner Join Sys_SetData s On f.PriceCurrency = s.Id
  2632. Left Join Sys_Users u On f.CreateUserId = u.Id
  2633. Where f.IsDel=0 And c.CTable = 1015 {0}
  2634. ) temp ", sqlWhere);
  2635. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  2636. {
  2637. //Fin_DailyFeePaymentPageCount
  2638. var count = await _sqlSugar.SqlQueryable<Fin_GroupExtraCostViewDataCount>(sql_count).FirstAsync();
  2639. List<Fin_GroupExtraCostView> dataList = await _sqlSugar.SqlQueryable<Fin_GroupExtraCostView>(sql_data).ToListAsync();
  2640. Dictionary<int, string> dic_setData = new Dictionary<int, string>();
  2641. Dictionary<int, string> dic_user = new Dictionary<int, string>();
  2642. foreach (var item in dataList)
  2643. {
  2644. DateTime dtTemp_PriceDt;
  2645. bool b_ct = DateTime.TryParse(item.PriceDt, out dtTemp_PriceDt);
  2646. if (b_ct)
  2647. {
  2648. item.PriceDt = dtTemp_PriceDt.ToString("yyyy-MM-dd");
  2649. }
  2650. //费用类型
  2651. if (dic_setData.ContainsKey(item.PriceType))
  2652. {
  2653. item.PriceTypeStr = dic_setData[item.PriceType];
  2654. }
  2655. else
  2656. {
  2657. Sys_SetData sd_priceTypeDetail = _daiRep.Query<Sys_SetData>(s => s.Id == item.PriceType).First();
  2658. if (sd_priceTypeDetail != null)
  2659. {
  2660. string tempName = sd_priceTypeDetail.Name.Replace("n", "");
  2661. item.PriceTypeStr = tempName;
  2662. dic_setData.Add(item.PriceType, tempName);
  2663. }
  2664. }
  2665. if (item.PriceDetailType > 0)
  2666. {
  2667. if (dic_setData.ContainsKey(item.PriceDetailType))
  2668. {
  2669. item.PriceTypeStr = item.PriceTypeStr + " - " + dic_setData[item.PriceDetailType];
  2670. }
  2671. else
  2672. {
  2673. Sys_SetData sd_priceTypeDetail = _daiRep.Query<Sys_SetData>(s => s.Id == item.PriceDetailType).First();
  2674. if (sd_priceTypeDetail != null)
  2675. {
  2676. string tempName = sd_priceTypeDetail.Name.Replace("n", "");
  2677. item.PriceTypeStr = item.PriceTypeStr + " - " + tempName;
  2678. dic_setData.Add(item.PriceDetailType, tempName);
  2679. }
  2680. }
  2681. }
  2682. //系统用户
  2683. if (dic_user.ContainsKey(item.CreateUserId))
  2684. {
  2685. item.CreateUserIdStr = dic_user[item.CreateUserId];
  2686. }
  2687. else
  2688. {
  2689. Sys_Users users = _daiRep.Query<Sys_Users>(s => s.Id == item.CreateUserId).First();
  2690. if (users != null)
  2691. {
  2692. item.CreateUserIdStr = users.CnName;
  2693. dic_user.Add(item.CreateUserId, users.CnName);
  2694. }
  2695. }
  2696. switch (item.IsAuditGM)
  2697. {
  2698. case 0: item.IsAuditGMStr = "未审核"; break;
  2699. case 1: item.IsAuditGMStr = "已通过"; break;
  2700. case 2: item.IsAuditGMStr = "未通过"; break;
  2701. default: item.IsAuditGMStr = "未知状态"; break;
  2702. }
  2703. }
  2704. var result = new ListViewBase<Fin_GroupExtraCostView>
  2705. {
  2706. CurrPageIndex = dto.PageIndex,
  2707. CurrPageSize = dto.PageSize,
  2708. DataCount = count.DataCount,
  2709. DataList = dataList
  2710. };
  2711. return Ok(JsonView(true, "查询成功", result));
  2712. }
  2713. return Ok(JsonView(false, "查询失败"));
  2714. }
  2715. /// <summary>
  2716. /// 超支费用
  2717. /// 数据集合配置
  2718. /// </summary>
  2719. /// <param name="dto"></param>
  2720. /// <returns></returns>
  2721. [HttpPost]
  2722. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2723. public async Task<IActionResult> PostGroupExtraCost_ListDataInit(Fin_GroupExtraCostDto_DataListInit dto)
  2724. {
  2725. //支付方式
  2726. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  2727. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  2728. //信用卡类型
  2729. List<Sys_SetData> Card = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 15 && a.IsDel == 0).ToList();
  2730. List<SetDataInfoView> _Card = _mapper.Map<List<SetDataInfoView>>(Card);
  2731. //超支费用类型
  2732. List<Sys_SetData> PriceType = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 79 && a.IsDel == 0).ToList();
  2733. List<SetDataInfoView> _PriceType = _mapper.Map<List<SetDataInfoView>>(PriceType);
  2734. //超支费用详细类型
  2735. List<Sys_SetData> PriceDetailType = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 80 && a.IsDel == 0).ToList();
  2736. PriceDetailType.ForEach(a => { a.Name = a.Name.Replace("n", ""); });
  2737. List<SetDataInfoView> _PriceDetailType = _mapper.Map<List<SetDataInfoView>>(PriceDetailType);
  2738. var data = new
  2739. {
  2740. Payment = _Payment,
  2741. Card = _Card,
  2742. PriceType = _PriceType,
  2743. PriceDetailType = _PriceDetailType
  2744. };
  2745. return Ok(JsonView(true, "", data));
  2746. }
  2747. /// <summary>
  2748. /// 超支费用
  2749. /// 导出团组超支费用Excel
  2750. /// </summary>
  2751. /// <param name="dto"></param>
  2752. /// <returns></returns>
  2753. [HttpPost]
  2754. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2755. public async Task<IActionResult> PostGroupExtraCost_OutputExcel(Fin_GroupExtraCostExcelDto dto)
  2756. {
  2757. string sqlGroup = string.Format(@" Select * From Grp_DelegationInfo WIth(Nolock) where Id = {0} ", dto.diId);
  2758. Grp_DelegationInfo grp_DelegationInfo = await _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sqlGroup).FirstAsync();
  2759. if (grp_DelegationInfo == null)
  2760. {
  2761. return Ok(JsonView(false, "导出失败,未查询到团组"));
  2762. }
  2763. Workbook workbook = new Workbook();
  2764. Worksheet sheet = workbook.Worksheets[0];
  2765. Cells cells = sheet.Cells;
  2766. //sheet.Protect(Aspose.Cells.ProtectionType.All, "123123", "");//保护工作表
  2767. //sheet.Protection.IsSelectingLockedCellsAllowed = true;//设置只能选择解锁单元格
  2768. //sheet.Protection.IsFormattingColumnsAllowed = true;//设置可以调整列
  2769. //sheet.Protection.IsFormattingRowsAllowed = true;//设置可以调整行
  2770. #region 数据源
  2771. string sqlData = string.Format(@" Select f.PriceType,REPLACE(s2.[Name],'超支费用','') as PriceTypeStr,'('+REPLACE(s3.[Name],'n','')+')' as PriceDetailTypeStr, PriceDt,PriceName,
  2772. Price,PriceCount,s.[Name] as Currency,PriceSum,f.Remark
  2773. From Fin_GroupExtraCost as f With(Nolock)
  2774. Inner Join Grp_CreditCardPayment as c With(Nolock) On f.Id = c.CId
  2775. Inner Join Sys_SetData as s With(Nolock) On f.PriceCurrency = s.Id
  2776. Inner Join Sys_SetData as s2 With(Nolock) On f.PriceType = s2.Id
  2777. Inner Join Sys_SetData as s3 With(Nolock) On f.PriceDetailType = s3.Id
  2778. Where f.DiId = {0} And f.IsDel=0 And c.CTable=1015
  2779. Order by PriceType ASC,PriceDt ASC ", dto.diId);
  2780. string sqlDataCount = string.Format(@" Select f.PriceType,COUNT(f.PriceType) as DataCount
  2781. From Fin_GroupExtraCost as f With(Nolock)
  2782. Inner Join Grp_CreditCardPayment as c With(Nolock) On f.Id = c.CId
  2783. Where f.DiId = {0} And f.IsDel=0 And c.CTable=1015
  2784. Group by PriceType ", dto.diId);
  2785. List<Fin_GroupExtraCost_ExcelView> dataList = await _sqlSugar.SqlQueryable<Fin_GroupExtraCost_ExcelView>(sqlData).ToListAsync();
  2786. List<Fin_GroupExtraCost_ExcelCountView> countList = await _sqlSugar.SqlQueryable<Fin_GroupExtraCost_ExcelCountView>(sqlDataCount).ToListAsync();
  2787. if (dataList.Count < 1 || countList.Count < 1)
  2788. {
  2789. return Ok(JsonView(false, "导出失败,未查询到数据"));
  2790. }
  2791. #endregion
  2792. #region 标题
  2793. string cellValue_Header = grp_DelegationInfo.TeamName;
  2794. //Aspose.Cells.Style style1 = workbook.Styles[workbook.Styles.Add()];//新增样式
  2795. Aspose.Cells.Style style_Header = workbook.CreateStyle();
  2796. style_Header.HorizontalAlignment = TextAlignmentType.Center;//文字居中
  2797. style_Header.VerticalAlignment = TextAlignmentType.Center;
  2798. style_Header.Font.Name = "微软雅黑";//文字字体
  2799. style_Header.Font.Size = 18;//文字大小
  2800. style_Header.IsLocked = false;//单元格解锁
  2801. style_Header.Font.IsBold = false;//粗体
  2802. style_Header.Font.Color = Color.FromArgb(255, 0, 0);
  2803. //style1.ForegroundColor = Color.FromArgb(0x99, 0xcc, 0xff);//设置背景色
  2804. //style1.Pattern = BackgroundType.Solid; //设置背景样式
  2805. //style1.IsTextWrapped = true;//单元格内容自动换行
  2806. style_Header.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线
  2807. style_Header.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线
  2808. style_Header.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线
  2809. style_Header.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线
  2810. cells.Merge(1, 1, 1, 10);
  2811. Aspose.Cells.Range range_header = cells.CreateRange(1, 1, 1, 10);
  2812. range_header.PutValue(cellValue_Header, false, false);
  2813. range_header.SetStyle(style_Header);
  2814. cells.SetRowHeight(1, 35);
  2815. #endregion
  2816. #region 列名
  2817. Aspose.Cells.Style style_colName = workbook.CreateStyle();
  2818. style_colName.Name = "colName";
  2819. style_colName.HorizontalAlignment = TextAlignmentType.Center;//文字居中
  2820. style_colName.VerticalAlignment = TextAlignmentType.Center;
  2821. style_colName.Font.Name = "微软雅黑";//文字字体
  2822. style_colName.Font.Size = 12;//文字大小
  2823. style_colName.IsLocked = false;//单元格解锁
  2824. style_colName.Font.IsBold = true;//粗体
  2825. style_colName.Font.Color = Color.FromArgb(0, 0, 0);
  2826. style_colName.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线
  2827. style_colName.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线
  2828. style_colName.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线
  2829. style_colName.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线
  2830. List<Fin_GroupExtraCostExcelColumnSetting> colNameSettingList = new List<Fin_GroupExtraCostExcelColumnSetting>()
  2831. {
  2832. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 1, columnName="类型", columnWidth= 25},
  2833. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 2, columnName="时间", columnWidth= 16},
  2834. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 3, columnName="内容", columnWidth= 35},
  2835. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 4, columnName="单价", columnWidth= 12},
  2836. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 5, columnName="数量", columnWidth= 12},
  2837. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 6, columnName="货币", columnWidth= 12},
  2838. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 7, columnName="费用", columnWidth= 12},
  2839. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 8, columnName="汇率", columnWidth= 12},
  2840. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 9, columnName="人民币", columnWidth= 12},
  2841. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 10, columnName="备注信息", columnWidth= 24}
  2842. };
  2843. foreach (var col in colNameSettingList)
  2844. {
  2845. cells[2, col.columnIndex].PutValue(col.columnName);
  2846. cells[2, col.columnIndex].SetStyle(style_colName);
  2847. cells.SetColumnWidth(col.columnIndex, col.columnWidth);
  2848. }
  2849. cells.SetRowHeight(2, 25);
  2850. #endregion
  2851. #region 数据填充
  2852. Aspose.Cells.Style style_dataCol = workbook.GetNamedStyle("colName");
  2853. style_dataCol.Font.IsBold = false;
  2854. style_dataCol.Name = "dataCol";
  2855. Aspose.Cells.Style style_dataBlue = workbook.CreateStyle();
  2856. style_dataBlue.HorizontalAlignment = TextAlignmentType.Center;//文字居中
  2857. style_dataBlue.VerticalAlignment = TextAlignmentType.Center;
  2858. style_dataBlue.Font.Name = "微软雅黑";//文字字体
  2859. style_dataBlue.Font.Size = 12;//文字大小
  2860. style_dataBlue.IsLocked = false;//单元格解锁
  2861. style_dataBlue.Font.IsBold = false;//粗体
  2862. style_dataBlue.ForegroundColor = Color.FromArgb(189, 215, 238);
  2863. style_dataBlue.Pattern = BackgroundType.Solid;
  2864. style_dataBlue.Font.Color = Color.FromArgb(0, 0, 0);
  2865. style_dataBlue.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线
  2866. style_dataBlue.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线
  2867. style_dataBlue.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线
  2868. style_dataBlue.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线
  2869. Aspose.Cells.Style style_dataYellow = workbook.CreateStyle();
  2870. style_dataYellow.HorizontalAlignment = TextAlignmentType.Center;//文字居中
  2871. style_dataYellow.VerticalAlignment = TextAlignmentType.Center;
  2872. style_dataYellow.Font.Name = "微软雅黑";//文字字体
  2873. style_dataYellow.Font.Size = 12;//文字大小
  2874. style_dataYellow.IsLocked = false;//单元格解锁
  2875. style_dataYellow.Font.IsBold = false;//粗体
  2876. style_dataYellow.ForegroundColor = Color.FromArgb(255, 242, 204);
  2877. style_dataYellow.Pattern = BackgroundType.Solid;
  2878. style_dataYellow.Font.Color = Color.FromArgb(0, 0, 0);
  2879. style_dataYellow.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线
  2880. style_dataYellow.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线
  2881. style_dataYellow.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线
  2882. style_dataYellow.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线
  2883. int rowIndex = 4;
  2884. foreach (var d in dataList)
  2885. {
  2886. //内容
  2887. string typeStr = d.PriceDetailTypeStr + d.PriceName;
  2888. cells["B" + rowIndex.ToString()].PutValue(d.PriceTypeStr);
  2889. cells["C" + rowIndex.ToString()].PutValue(d.PriceDtStr);
  2890. cells["D" + rowIndex.ToString()].PutValue(typeStr);
  2891. cells["E" + rowIndex.ToString()].PutValue(d.Price.ToString("#0.00"));
  2892. cells["F" + rowIndex.ToString()].PutValue(d.PriceCount);
  2893. cells["G" + rowIndex.ToString()].PutValue(d.Currency);
  2894. cells["H" + rowIndex.ToString()].PutValue(d.PriceSum.ToString("#0.00"));
  2895. cells["K" + rowIndex.ToString()].PutValue(d.Remark);
  2896. //样式
  2897. cells["B" + rowIndex.ToString()].SetStyle(style_dataCol);
  2898. cells["C" + rowIndex.ToString()].SetStyle(style_dataCol);
  2899. cells["D" + rowIndex.ToString()].SetStyle(style_dataCol);
  2900. cells["E" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2901. cells["F" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2902. cells["G" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2903. cells["H" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2904. cells["I" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2905. cells["J" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2906. cells["K" + rowIndex.ToString()].SetStyle(style_dataYellow);
  2907. //公式
  2908. cells["H" + rowIndex.ToString()].Formula = string.Format(@"E{0}*F{0}", rowIndex);
  2909. cells["J" + rowIndex.ToString()].Formula = string.Format(@"H{0}*I{0}", rowIndex);
  2910. cells.SetRowHeight(rowIndex - 1, 25);
  2911. rowIndex++;
  2912. }
  2913. cells["B" + rowIndex.ToString()].SetStyle(style_dataCol);
  2914. cells["C" + rowIndex.ToString()].SetStyle(style_dataCol);
  2915. cells["D" + rowIndex.ToString()].SetStyle(style_dataCol);
  2916. cells["E" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2917. cells["F" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2918. cells["G" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2919. cells["H" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2920. cells["I" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2921. cells["J" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2922. cells["K" + rowIndex.ToString()].SetStyle(style_dataYellow);
  2923. rowIndex++;
  2924. cells["B" + rowIndex.ToString()].SetStyle(style_dataCol);
  2925. cells["C" + rowIndex.ToString()].SetStyle(style_dataCol);
  2926. cells["D" + rowIndex.ToString()].SetStyle(style_dataCol);
  2927. cells["E" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2928. cells["F" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2929. cells["G" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2930. cells["H" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2931. cells["I" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2932. cells["J" + rowIndex.ToString()].SetStyle(style_dataBlue);
  2933. cells["K" + rowIndex.ToString()].SetStyle(style_dataYellow);
  2934. rowIndex = 3;
  2935. int tempPriceType = 0;
  2936. foreach (var c in dataList)
  2937. {
  2938. if (tempPriceType == c.PriceType)
  2939. {
  2940. continue;
  2941. }
  2942. tempPriceType = c.PriceType;
  2943. int _rowCount = countList.First(s => s.PriceType == tempPriceType).DataCount;
  2944. cells.Merge(rowIndex, 1, _rowCount, 1);
  2945. Aspose.Cells.Range tempRange = cells.CreateRange(rowIndex, 1, _rowCount, 1);
  2946. rowIndex += _rowCount;
  2947. }
  2948. rowIndex = 4 + dataList.Count;
  2949. cells["D" + rowIndex.ToString()].PutValue("合计");
  2950. cells["J" + rowIndex.ToString()].Formula = string.Format(@"SUM(J4,J{0})", rowIndex - 1);
  2951. cells.SetRowHeight(rowIndex - 1, 25);
  2952. rowIndex++;
  2953. cells["D" + rowIndex.ToString()].PutValue("服务费10%开票税金8%");
  2954. cells["J" + rowIndex.ToString()].Formula = string.Format(@"J{0}*1.1*1.08", rowIndex - 1);
  2955. cells.SetRowHeight(rowIndex - 1, 25);
  2956. #endregion
  2957. #region IO
  2958. System.IO.MemoryStream ms = workbook.SaveToStream();//生成数据流
  2959. string fileName = ("GroupExtraCost/超支费用(" + cellValue_Header + ").xlsx");
  2960. byte[] bt = ms.ToArray();
  2961. workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
  2962. #endregion
  2963. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  2964. return Ok(JsonView(true, "成功", new { url = rst }));
  2965. }
  2966. #endregion
  2967. }
  2968. }