FinancialController.cs 143 KB

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