FinancialController.cs 173 KB

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