FinancialController.cs 205 KB

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