FinancialController.cs 156 KB

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