FinancialController.cs 142 KB

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