FinancialController.cs 127 KB

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