FinancialController.cs 141 KB

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