FinancialController.cs 147 KB

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