FinancialController.cs 98 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329
  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. namespace OASystem.API.Controllers
  31. {
  32. /// <summary>
  33. /// 财务模块
  34. /// </summary>
  35. [Route("api/[controller]/[action]")]
  36. [ApiController]
  37. public class FinancialController : ControllerBase
  38. {
  39. private readonly IMapper _mapper;
  40. private readonly IConfiguration _config;
  41. private readonly SqlSugarClient _sqlSugar;
  42. private readonly HttpClient _httpClient;
  43. private readonly SetDataTypeRepository _setDataTypeRep;
  44. private readonly DailyFeePaymentRepository _daiRep; //日付申请仓库
  45. private readonly TeamRateRepository _teamRateRep; //团组汇率仓库
  46. private readonly ForeignReceivablesRepository _ForForeignReceivablesRep; //对外收款账单仓库
  47. private readonly ProceedsReceivedRepository _proceedsReceivedRep; //已收款项仓库
  48. private readonly PaymentRefundAndOtherMoneyRepository _paymentRefundAndOtherMoneyRep; //收款退还与其他款项 仓库
  49. /// <summary>
  50. /// 初始化
  51. /// </summary>
  52. public FinancialController(IMapper mapper, IConfiguration configuration, DailyFeePaymentRepository daiRep, SqlSugarClient sqlSugar, SetDataTypeRepository setDataTypeRep,
  53. TeamRateRepository teamRateRep, ForeignReceivablesRepository ForForeignReceivablesRep, ProceedsReceivedRepository proceedsReceivedRep,
  54. PaymentRefundAndOtherMoneyRepository paymentRefundAndOtherMoneyRep, HttpClient httpClient)
  55. {
  56. _mapper = mapper;
  57. _config = configuration;
  58. _daiRep = daiRep;
  59. _sqlSugar = sqlSugar;
  60. _setDataTypeRep = setDataTypeRep;
  61. _teamRateRep = teamRateRep;
  62. _ForForeignReceivablesRep = ForForeignReceivablesRep;
  63. _proceedsReceivedRep = proceedsReceivedRep;
  64. _paymentRefundAndOtherMoneyRep = paymentRefundAndOtherMoneyRep;
  65. _httpClient = httpClient;
  66. }
  67. #region 日付申请
  68. /// <summary>
  69. /// 获取日付申请 基础数据源
  70. /// </summary>
  71. /// <param name="dto"> 日付申请 分页 dto</param>
  72. /// <returns></returns>
  73. [HttpPost]
  74. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  75. public async Task<IActionResult> PostPageSearchDailyPaymentPriceTypeData(PortDtoBase dto)
  76. {
  77. var result = await _daiRep.GetPagePriceTypeData(dto);
  78. if (result == null || result.Code != 0)
  79. {
  80. return Ok(JsonView(false, result.Msg));
  81. }
  82. var data = result.Data;
  83. return Ok(JsonView(data));
  84. }
  85. /// <summary>
  86. /// 获取日付申请 基础数据源 - 转账表识
  87. /// </summary>
  88. /// <param name="dto"> 日付申请 分页 dto</param>
  89. /// <returns></returns>
  90. [HttpPost]
  91. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  92. public async Task<IActionResult> GetSearchDailyPaymentPriceTypeAddData(PortDtoBase dto)
  93. {
  94. var result = await _daiRep.GetPriceTypeAddData(dto);
  95. if (result == null || result.Code != 0)
  96. {
  97. return Ok(JsonView(false, result.Msg));
  98. }
  99. var data = result.Data;
  100. return Ok(JsonView(data));
  101. }
  102. /// <summary>
  103. /// 日付申请 Page Search
  104. /// </summary>
  105. /// <param name="dto"> 日付申请 分页 dto</param>
  106. /// <returns></returns>
  107. [HttpPost]
  108. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  109. public async Task<IActionResult> PostPageSearchDailyPaymentList(PageDailyFeePaymentDto dto)
  110. {
  111. var result = await _daiRep.GetPageSearchAll(dto);
  112. if (result == null || result.Code != 0)
  113. {
  114. return Ok(JsonView(false, result.Msg));
  115. }
  116. var data = result.Data;
  117. if (data == null)
  118. {
  119. return Ok(JsonView(false, result.Msg));
  120. }
  121. return Ok(JsonView(data));
  122. }
  123. /// <summary>
  124. /// 日付申请 Single Search By Id
  125. /// </summary>
  126. /// <param name="dto"></param>
  127. /// <returns></returns>
  128. [HttpPost]
  129. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  130. public async Task<IActionResult> PostSearchDailyPaymentInfo(SearchDailyFeePaymentDto dto)
  131. {
  132. var result = await _daiRep.GetSearchById(dto);
  133. if (result == null || result.Code != 0)
  134. {
  135. return Ok(JsonView(false, result.Msg));
  136. }
  137. return Ok(JsonView(result.Data));
  138. }
  139. /// <summary>
  140. /// 日付申请 添加
  141. /// </summary>
  142. /// <param name="dto"> 日付申请 添加 dto</param>
  143. /// <returns></returns>
  144. [HttpPost]
  145. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  146. public async Task<IActionResult> PostAddDailyPayment(AddDailyFeePaymentDto dto)
  147. {
  148. var result = await _daiRep.Add(dto);
  149. if (result == null || result.Code != 0)
  150. {
  151. return Ok(JsonView(false, result.Msg));
  152. }
  153. return Ok(JsonView(true));
  154. }
  155. /// <summary>
  156. /// 日付申请 Update
  157. /// </summary>
  158. /// <param name="dto"> 日付申请 修改 dto</param>
  159. /// <returns></returns>
  160. [HttpPost]
  161. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  162. public async Task<IActionResult> PostEditDailyPayment(EditDailyFeePaymentDto dto)
  163. {
  164. var result = await _daiRep.Edit(dto);
  165. if (result == null || result.Code != 0)
  166. {
  167. return Ok(JsonView(false, result.Msg));
  168. }
  169. return Ok(JsonView(true));
  170. }
  171. /// <summary>
  172. /// 日付申请 Del
  173. /// </summary>
  174. /// <param name="dto"> 日付申请 删除 dto</param>
  175. /// <returns></returns>
  176. [HttpPost]
  177. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  178. public async Task<IActionResult> PostDelDailyPayment(DelDailyFeePaymentDto dto)
  179. {
  180. var result = await _daiRep.Del(dto);
  181. if (result == null || result.Code != 0)
  182. {
  183. return Ok(JsonView(false, result.Msg));
  184. }
  185. return Ok(JsonView(true));
  186. }
  187. /// <summary>
  188. /// 日付申请 财务审核
  189. /// </summary>
  190. /// <param name="dto"> dto </param>
  191. /// <returns></returns>
  192. [HttpPost]
  193. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  194. public async Task<IActionResult> PostDelDailyPaymentAudit(DP_AuditStatusDto dto)
  195. {
  196. var result = await _daiRep.DelDailyPaymentAudit(dto);
  197. if (result == null || result.Code != 0)
  198. {
  199. return Ok(JsonView(false, result.Msg));
  200. }
  201. return Ok(JsonView(true));
  202. }
  203. /// <summary>
  204. /// 日付申请 Single Excel Download
  205. /// </summary>
  206. /// <param name="dto"> dto </param>
  207. /// <returns></returns>
  208. [HttpPost]
  209. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  210. public async Task<IActionResult> PostExcelDailyPaymentDownload(SearchDailyFeePaymentDto dto)
  211. {
  212. if (dto.PortType == 1 || dto.PortType == 2)
  213. {
  214. Fin_DailyFeePaymentInfolView feeData = new Fin_DailyFeePaymentInfolView();
  215. string feeSql = string.Format(@"Select * From Fin_DailyFeePayment
  216. Where IsDel=0 And Id = {0} ", dto.Id);
  217. feeData = await _sqlSugar.SqlQueryable<Fin_DailyFeePaymentInfolView>(feeSql).FirstAsync();
  218. if (feeData == null)
  219. {
  220. return Ok(JsonView(false, "暂无数据!"));
  221. }
  222. string feeContentSql = string.Format(@"Select * From Fin_DailyFeePaymentContent
  223. Where IsDel=0 And DFPId = {0} ", dto.Id);
  224. feeData.FeeContents = await _sqlSugar.SqlQueryable<Fin_DailyFeePaymentContentInfolView>(feeContentSql).ToListAsync();
  225. if (feeData != null)
  226. {
  227. string userName = string.Empty;
  228. string userSql = string.Format("Select * From Sys_Users Where Id={0} And Isdel = {1}", feeData.CreateUserId, 0);
  229. Sys_Users user = await _sqlSugar.SqlQueryable<Sys_Users>(userSql).FirstAsync();
  230. if (user != null) { userName = user.CnName; }
  231. var setData = _setDataTypeRep.QueryDto<Sys_SetData, Fin_DailyFeePaymentPagePriceSubTypeView>().ToList();
  232. //48人员费用 49办公费用 50 销售费用 51 其他费用 55 大运会
  233. var priceSubTypeData = setData.Where(s => s.STid == 55).ToList();
  234. Dictionary<string, object> pairs = new Dictionary<string, object>();
  235. List<DataTable> datas = new List<DataTable>();
  236. //if (priceSubTypeData.Where(s => s.Id == feeData.PriceTypeId).ToList().Count() > 0)//大运会专属模板
  237. //{
  238. // //AsposeHelper.ExpertExcelToModel("日常费用付款申请模板-大运会数据.xls", "DailyPayment", "大运会所有日常费用付款申请.xls",
  239. // // pairs, datas);
  240. //}
  241. //else //日付常规模板
  242. //{
  243. pairs.Clear();
  244. pairs.Add("Opertor", userName);
  245. pairs.Add("DateTime", feeData.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"));
  246. pairs.Add("FAuditStatus", feeData.FAuditDesc);
  247. pairs.Add("MAuditStatus", feeData.MAuditDesc);
  248. pairs.Add("SumPrice", feeData.SumPrice);
  249. DataTable data = AsposeHelper.ListToDataTable("DailyFeePayment", feeData.FeeContents);
  250. datas.Clear();
  251. datas.Add(data);
  252. string fileName = string.Format("{0}-日常费用付款申请.xlsx", feeData.Instructions);
  253. string msg = AsposeHelper.ExpertExcelToModel("日常费用付款申请模板.xlsx", "DailyPayment", fileName, pairs, datas);
  254. return Ok(JsonView(true, msg));
  255. //}
  256. }
  257. else
  258. {
  259. return Ok(JsonView(false, "暂无数据!"));
  260. }
  261. }
  262. return Ok(JsonView(true));
  263. }
  264. #endregion
  265. #region 团组提成
  266. /// <summary>
  267. /// 提成 Page Search
  268. /// </summary>
  269. /// <param name="dto"> 提成 分页 dto</param>
  270. /// <returns></returns>
  271. [HttpPost]
  272. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  273. public async Task<IActionResult> PostPageSearchCommissionList(GroupCommissionDto dto)
  274. {
  275. var data = await GroupCommission.GetCommissionPageList(dto);
  276. return Ok(JsonView(data.Data));
  277. }
  278. #endregion
  279. #region 团组汇率
  280. /// <summary>
  281. /// 团组汇率 Select数据源(团组列,汇率列)
  282. /// </summary>
  283. /// <param name="dto"></param>
  284. /// <returns></returns>
  285. [HttpPost]
  286. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  287. public async Task<IActionResult> GetGroupRateDataSources(TeamRateDto dto)
  288. {
  289. try
  290. {
  291. Result teamRateData = await _teamRateRep.GetGroupRateDataSource(dto);
  292. if (teamRateData.Code != 0)
  293. {
  294. return Ok(JsonView(false, teamRateData.Msg));
  295. }
  296. return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  297. }
  298. catch (Exception ex)
  299. {
  300. return Ok(JsonView(false, ex.Message));
  301. throw;
  302. }
  303. }
  304. ///// <summary>
  305. ///// 团组汇率 changge
  306. ///// </summary>
  307. ///// <returns></returns>
  308. //[HttpPost]
  309. //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  310. //public async Task<IActionResult> ChangeGroupRateInfo()
  311. //{
  312. // try
  313. // {
  314. // Result teamRateData = await _teamRateRep.GetGroupRateChangeData();
  315. // if (teamRateData.Code != 0)
  316. // {
  317. // return Ok(JsonView(false, teamRateData.Msg));
  318. // }
  319. // return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  320. // }
  321. // catch (Exception ex)
  322. // {
  323. // return Ok(JsonView(false, ex.Message));
  324. // throw;
  325. // }
  326. //}
  327. /// <summary>
  328. /// 团组汇率 Select汇率详情
  329. /// </summary>
  330. /// <param name="dto"></param>
  331. /// <returns></returns>
  332. [HttpPost]
  333. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  334. public async Task<IActionResult> GetGroupRateInfo(TeamRateInfoDto dto)
  335. {
  336. try
  337. {
  338. Result teamRateData = await _teamRateRep.GetGroupRateInfoByDiid(dto);
  339. if (teamRateData.Code != 0)
  340. {
  341. return Ok(JsonView(false, teamRateData.Msg));
  342. }
  343. return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  344. }
  345. catch (Exception ex)
  346. {
  347. return Ok(JsonView(false, ex.Message));
  348. throw;
  349. }
  350. }
  351. /// <summary>
  352. /// 团组汇率 添加 or 更新
  353. /// </summary>
  354. /// <param name="dto"></param>
  355. /// <returns></returns>
  356. [HttpPost]
  357. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  358. public async Task<IActionResult> PostGroupRateUpdate(TeamRateUpdateDto dto)
  359. {
  360. try
  361. {
  362. Result teamRateData = await _teamRateRep.PostGroupRateUpdate(dto);
  363. if (teamRateData.Code != 0)
  364. {
  365. return Ok(JsonView(false, teamRateData.Msg));
  366. }
  367. return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  368. }
  369. catch (Exception ex)
  370. {
  371. return Ok(JsonView(false, ex.Message));
  372. throw;
  373. }
  374. }
  375. #endregion
  376. #region 对外收款账单 关联已收款项
  377. /// <summary>
  378. /// 对外收款账单 Select数据源(团组名,币种,汇款方式)
  379. /// 关联已收款项
  380. /// </summary>
  381. /// <param name="dto"></param>
  382. /// <returns></returns>
  383. [HttpPost]
  384. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  385. public async Task<IActionResult> GetForeignReceivablesDataSources()
  386. {
  387. try
  388. {
  389. Result ffrData = await _ForForeignReceivablesRep.GetDataSource();
  390. if (ffrData.Code != 0)
  391. {
  392. return Ok(JsonView(false, ffrData.Msg));
  393. }
  394. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  395. }
  396. catch (Exception ex)
  397. {
  398. return Ok(JsonView(false, ex.Message));
  399. throw;
  400. }
  401. }
  402. /// <summary>
  403. /// 对外收款账单
  404. /// 账单详情
  405. /// 关联已收款项
  406. /// </summary>
  407. /// <param name="dto"></param>
  408. /// <returns></returns>
  409. [HttpPost]
  410. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  411. public async Task<IActionResult> GetGroupReceivablesInfoByDiId(ForForeignReceivablesInfoDto dto)
  412. {
  413. try
  414. {
  415. Result ffrData = await _ForForeignReceivablesRep.GetGroupReceivablesInfoByDiId(dto);
  416. if (ffrData.Code != 0)
  417. {
  418. return Ok(JsonView(false, ffrData.Msg));
  419. }
  420. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  421. }
  422. catch (Exception ex)
  423. {
  424. return Ok(JsonView(false, ex.Message));
  425. throw;
  426. }
  427. }
  428. /// <summary>
  429. /// 对外收款账单
  430. /// 账单 删除
  431. /// 关联已收款项
  432. /// </summary>
  433. /// <param name="dto"></param>
  434. /// <returns></returns>
  435. [HttpPost]
  436. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  437. public async Task<IActionResult> PostGroupReceivablesDel(DelForForeignReceivablesInfoDto dto)
  438. {
  439. try
  440. {
  441. Result ffrData = await _ForForeignReceivablesRep._Del(dto);
  442. if (ffrData.Code != 0)
  443. {
  444. return Ok(JsonView(false, ffrData.Msg));
  445. }
  446. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  447. }
  448. catch (Exception ex)
  449. {
  450. return Ok(JsonView(false, ex.Message));
  451. throw;
  452. }
  453. }
  454. /// <summary>
  455. /// 对外收款账单
  456. /// 添加 And 更新
  457. /// 关联已收款项
  458. /// </summary>
  459. /// <param name="dto"></param>
  460. /// <returns></returns>
  461. [HttpPost]
  462. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  463. public async Task<IActionResult> PostReceivablesOperate(ForeignReceivablesAddAndUpdateDto dto)
  464. {
  465. try
  466. {
  467. Result ffrData = await _ForForeignReceivablesRep.PostReceivablesOperate(dto);
  468. if (ffrData.Code != 0)
  469. {
  470. return Ok(JsonView(false, ffrData.Msg));
  471. }
  472. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  473. }
  474. catch (Exception ex)
  475. {
  476. return Ok(JsonView(false, ex.Message));
  477. throw;
  478. }
  479. }
  480. /// <summary>
  481. /// 已收款项
  482. /// 账单 删除
  483. /// 关联已收款项
  484. /// </summary>
  485. /// <param name="dto"></param>
  486. /// <returns></returns>
  487. [HttpPost]
  488. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  489. public async Task<IActionResult> PostAmountReceivedDel(ProceedsReceivedDelDto dto)
  490. {
  491. try
  492. {
  493. Result ffrData = await _proceedsReceivedRep._Del(dto);
  494. if (ffrData.Code != 0)
  495. {
  496. return Ok(JsonView(false, ffrData.Msg));
  497. }
  498. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  499. }
  500. catch (Exception ex)
  501. {
  502. return Ok(JsonView(false, ex.Message));
  503. throw;
  504. }
  505. }
  506. /// <summary>
  507. /// 已收款项
  508. /// 添加 And 更新
  509. /// 关联已收款项
  510. /// </summary>
  511. /// <param name="dto"></param>
  512. /// <returns></returns>
  513. [HttpPost]
  514. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  515. public async Task<IActionResult> PostAmountReceivedOperate(ProceedsReceivedDto dto)
  516. {
  517. try
  518. {
  519. Result ffrData = await _proceedsReceivedRep.PostAmountReceivedOperate(dto);
  520. if (ffrData.Code != 0)
  521. {
  522. return Ok(JsonView(false, ffrData.Msg));
  523. }
  524. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  525. }
  526. catch (Exception ex)
  527. {
  528. return Ok(JsonView(false, ex.Message));
  529. throw;
  530. }
  531. }
  532. /// <summary>
  533. /// 财务 已收款项
  534. /// 分配已收款项至 应收项下
  535. /// 关联已收款项
  536. /// </summary>
  537. /// <param name="dto"></param>
  538. /// <returns></returns>
  539. [HttpPost]
  540. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  541. public async Task<IActionResult> PostAllocateAmountReceived(AllocateAmountReceivedDto dto)
  542. {
  543. try
  544. {
  545. Result ffrData = await _proceedsReceivedRep.PostAllocateAmountReceived(dto);
  546. if (ffrData.Code != 0)
  547. {
  548. return Ok(JsonView(false, ffrData.Msg));
  549. }
  550. return Ok(JsonView(true));
  551. }
  552. catch (Exception ex)
  553. {
  554. return Ok(JsonView(false, ex.Message));
  555. throw;
  556. }
  557. }
  558. ///// <summary>
  559. ///// 财务 收款账单
  560. ///// 导出Word(北京,四川)
  561. ///// </summary>
  562. ///// <param name="dto"></param>
  563. ///// <returns></returns>
  564. //[HttpPost]
  565. //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  566. //public async Task<IActionResult> PostAccountReceivableWordExport(AccountReceivableWordExportDto dto)
  567. //{
  568. // try
  569. // {
  570. // //模板处理
  571. // string typeName = string.Empty;
  572. // if (dto.TemplateType == 1) //四川
  573. // {
  574. // typeName = "四川";
  575. // }
  576. // else if (dto.TemplateType == 2) //北京
  577. // {
  578. // typeName = "北京";
  579. // }
  580. // else return Ok(JsonView(false,"请选择正确的模板类型!"));
  581. // string wordTempName = string.Format("收款账单({0})模板.doc", typeName);
  582. // }
  583. // catch (Exception ex)
  584. // {
  585. // return Ok(JsonView(false, ex.Message));
  586. // }
  587. //}
  588. #endregion
  589. #region 对外收款账单
  590. /// <summary>
  591. /// 对外收款账单
  592. /// 数据源
  593. /// </summary>
  594. /// <param name="dto"></param>
  595. /// <returns></returns>
  596. [HttpPost]
  597. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  598. public async Task<IActionResult> PostGroupReceivablesDataSource()
  599. {
  600. try
  601. {
  602. Result ffrData = await _ForForeignReceivablesRep.PostDataSource();
  603. if (ffrData.Code != 0)
  604. {
  605. return Ok(JsonView(false, ffrData.Msg));
  606. }
  607. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  608. }
  609. catch (Exception ex)
  610. {
  611. return Ok(JsonView(false, ex.Message));
  612. }
  613. }
  614. /// <summary>
  615. /// 对外收款账单
  616. /// 账单详情
  617. /// </summary>
  618. /// <param name="dto"></param>
  619. /// <returns></returns>
  620. [HttpPost]
  621. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  622. public async Task<IActionResult> PostGroupReceivablesInfoByDiId(ForForeignReceivablesNewDto dto)
  623. {
  624. try
  625. {
  626. Result ffrData = await _ForForeignReceivablesRep.PostGroupReceivablesInfoByDiId(dto);
  627. if (ffrData.Code != 0)
  628. {
  629. return Ok(JsonView(false, ffrData.Msg));
  630. }
  631. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  632. }
  633. catch (Exception ex)
  634. {
  635. return Ok(JsonView(false, ex.Message));
  636. }
  637. }
  638. /// <summary>
  639. /// 对外收款账单
  640. /// 添加 And 更新
  641. /// </summary>
  642. /// <param name="dto"></param>
  643. /// <returns></returns>
  644. [HttpPost]
  645. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  646. public async Task<IActionResult> PostReceivablesSave(ForeignReceivablesSaveDto dto)
  647. {
  648. try
  649. {
  650. Result ffrData = await _ForForeignReceivablesRep.PostReceivablesSave(dto);
  651. if (ffrData.Code != 0)
  652. {
  653. return Ok(JsonView(false, ffrData.Msg));
  654. }
  655. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  656. }
  657. catch (Exception ex)
  658. {
  659. return Ok(JsonView(false, ex.Message));
  660. throw;
  661. }
  662. }
  663. /// <summary>
  664. /// 已收账单
  665. /// 删除
  666. /// </summary>
  667. /// <param name="dto"></param>
  668. /// <returns></returns>
  669. [HttpPost]
  670. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  671. public async Task<IActionResult> PostReceivablesDel(ForeignReceivablesDelDto dto)
  672. {
  673. try
  674. {
  675. Result ffrData = await _ForForeignReceivablesRep.PostReceivablesDel(dto);
  676. if (ffrData.Code != 0)
  677. {
  678. return Ok(JsonView(false, ffrData.Msg));
  679. }
  680. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  681. }
  682. catch (Exception ex)
  683. {
  684. return Ok(JsonView(false, ex.Message));
  685. throw;
  686. }
  687. }
  688. /// <summary>
  689. /// 已收账单
  690. /// File Downloasd
  691. /// </summary>
  692. /// <param name="dto"></param>
  693. /// <returns></returns>
  694. [HttpPost]
  695. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  696. public async Task<IActionResult> PostReceivablesFeilDownload(ForeignReceivablesFeilDownloadDto dto)
  697. {
  698. try
  699. {
  700. if (dto.DiId < 1)
  701. {
  702. return Ok(JsonView(false, "请传入有效DiId参数!"));
  703. }
  704. if (dto.FileType < 1 || dto.FileType > 3)
  705. {
  706. return Ok(JsonView(false, "请传入有效FileType参数! 1 生成收款单(四川) 2 生成收款单(北京) 3 汇款账单"));
  707. }
  708. var _DelegationInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == dto.DiId).First();
  709. if (_DelegationInfo == null)
  710. {
  711. return Ok(JsonView(false, "暂无团组信息!!"));
  712. }
  713. if (dto.FileType == 1 || dto.FileType == 2)
  714. {
  715. var _ForeignReceivables = _sqlSugar.Queryable<Fin_ForeignReceivables>().Where(it => it.IsDel == 0 && it.Diid == dto.DiId).ToList();
  716. if (_ForeignReceivables.Count < 1)
  717. {
  718. return Ok(JsonView(false, "暂无收款信息!!"));
  719. }
  720. string tempName = "";
  721. if (dto.FileType == 1) tempName = $"收款账单(四川)模板.docx";
  722. else if (dto.FileType == 2) tempName = $"收款账单(北京)模板.docx";
  723. string tempPath = AppSettingsHelper.Get("WordBasePath") + $"ForeignReceivables/Temp/{tempName}";
  724. //载入模板
  725. Document doc = new Document(tempPath);
  726. DocumentBuilder builder = new DocumentBuilder(doc);
  727. #region 替换Word模板书签内容
  728. //这里可以创建个DataTable循环添加书签的值,这里提示一下就不多做修改了
  729. //付款方
  730. if (doc.Range.Bookmarks["To"] != null)
  731. {
  732. Bookmark mark = doc.Range.Bookmarks["To"];
  733. mark.Text = _ForeignReceivables[0].To == null ? "" : _ForeignReceivables[0].To.ToString();
  734. }
  735. //付款方电话
  736. if (doc.Range.Bookmarks["ToTel"] != null)
  737. {
  738. Bookmark mark = doc.Range.Bookmarks["ToTel"];
  739. mark.Text = _ForeignReceivables[0].ToTel == null ? "" : _ForeignReceivables[0].ToTel.ToString();
  740. }
  741. //导出时间
  742. if (doc.Range.Bookmarks["Date"] != null)
  743. {
  744. Bookmark mark = doc.Range.Bookmarks["Date"];
  745. mark.Text = DateTime.Now.ToString("yyyy-MM-dd");
  746. }
  747. //注
  748. if (doc.Range.Bookmarks["Attention"] != null)
  749. {
  750. Bookmark mark = doc.Range.Bookmarks["Attention"];
  751. mark.Text = _ForeignReceivables[0].Attention == null ? "" : _ForeignReceivables[0].Attention.ToString();
  752. }
  753. //团队名称
  754. if (doc.Range.Bookmarks["Team"] != null)
  755. {
  756. Bookmark mark = doc.Range.Bookmarks["Team"];
  757. mark.Text = _DelegationInfo.VisitCountry == null ? "" : _DelegationInfo.VisitCountry.ToString();
  758. }
  759. //付款日期
  760. if (doc.Range.Bookmarks["PayDate"] != null)
  761. {
  762. Bookmark mark = doc.Range.Bookmarks["PayDate"];
  763. mark.Text = _ForeignReceivables[0].PayDate == null ? "" : Convert.ToDateTime(_ForeignReceivables[0].PayDate).ToString("yyyy年MM月dd日");
  764. }
  765. decimal sumPrice = 0;
  766. //各项费用
  767. if (doc.Range.Bookmarks["PayItemContent"] != null)
  768. {
  769. string items = "";
  770. foreach (var fr in _ForeignReceivables)
  771. {
  772. items += fr.PriceName + " " + fr.Currency + " " + fr.Price.ToString("#0.00") + " * " + fr.Count + " " + fr.Unit + " * " + fr.Rate + ".................. RMB " + fr.ItemSumPrice.ToString("#0.00") + "\n";
  773. sumPrice += fr.ItemSumPrice;
  774. }
  775. Bookmark mark = doc.Range.Bookmarks["PayItemContent"];
  776. mark.Text = items;
  777. }
  778. //合计
  779. if (doc.Range.Bookmarks["Total"] != null)
  780. {
  781. Bookmark mark = doc.Range.Bookmarks["Total"];
  782. mark.Text = sumPrice.ToString("#0.00");
  783. }
  784. #endregion
  785. //文件名
  786. string strFileName = _DelegationInfo.TeamName + "-收款账单.docx";
  787. doc.Save(AppSettingsHelper.Get("WordBasePath") + "ForeignReceivables/File/" + strFileName);
  788. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/ForeignReceivables/File/" + strFileName;
  789. return Ok(JsonView(true, "成功", new { Url = url }));
  790. }
  791. else if (dto.FileType == 3) //汇款通知
  792. {
  793. var _EnterExitCosts = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).First();
  794. var _DayAndCosts = _sqlSugar.Queryable<Grp_DayAndCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).ToList();
  795. if (_EnterExitCosts == null)
  796. {
  797. return Ok(JsonView(false, "该团组未填写出入境费用;"));
  798. }
  799. //数据源
  800. List<Grp_DayAndCost> dac1 = _DayAndCosts.Where(it => it.Type == 1).ToList(); //住宿费
  801. List<Grp_DayAndCost> dac2 = _DayAndCosts.Where(it => it.Type == 2).ToList(); //伙食费
  802. List<Grp_DayAndCost> dac3 = _DayAndCosts.Where(it => it.Type == 3).ToList(); //公杂费
  803. List<Grp_DayAndCost> dac4 = _DayAndCosts.Where(it => it.Type == 4).ToList(); //培训费
  804. var DeleClientList = _sqlSugar.Queryable<Grp_TourClientList>()
  805. .LeftJoin<Crm_DeleClient>((tcl, dc) => tcl.ClientId == dc.Id && dc.IsDel == 0)
  806. .LeftJoin<Crm_CustomerCompany>((tcl, dc, cc) => dc.CrmCompanyId == cc.Id && dc.IsDel == 0)
  807. .Where((tcl, dc, cc) => tcl.IsDel == 0 && tcl.DiId == dto.DiId)
  808. .Select((tcl, dc, cc) => new
  809. {
  810. Name = dc.LastName + dc.FirstName,
  811. Sex = dc.Sex,
  812. Birthday = dc.BirthDay,
  813. Company = cc.CompanyFullName,
  814. Job = dc.Job,
  815. AirType = tcl.ShippingSpaceTypeId
  816. })
  817. .ToList();
  818. if (DeleClientList.Count<1)
  819. {
  820. return Ok(JsonView(false, "暂无团组成员,请先填写团组成员!!!"));
  821. }
  822. var _ClientNames = DeleClientList.Select(x => x.Name).ToList();
  823. var _GroupClient = DeleClientList.GroupBy(x => x.Company).ToList();
  824. Dictionary<string, string> bookmarkArr = null;
  825. string tempPath = AppSettingsHelper.Get("WordBasePath") + $"ForeignReceivables/Temp/汇款通知.docx";
  826. //载入模板
  827. Document doc = new Document(tempPath);
  828. DocumentBuilder builder = null;
  829. List<string> filesToZip = new List<string>();
  830. foreach (var ClientItem in _GroupClient) //遍历单位
  831. {
  832. doc = new Document(tempPath);
  833. builder = new DocumentBuilder(doc);
  834. Paragraph paragraph = new Paragraph(doc);
  835. bookmarkArr = new Dictionary<string, string>();
  836. bookmarkArr.Add("titleClientUnit", ClientItem.Key); //title单位
  837. bookmarkArr.Add("ClientUnit", ClientItem.Key); //单位
  838. bookmarkArr.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));//出发日期
  839. bookmarkArr.Add("name", string.Join(",", ClientItem.Select(x => x.Name).ToArray()).TrimEnd(','));//全部人员信息
  840. bookmarkArr.Add("VisitCountry", _DelegationInfo.VisitCountry);//出访国家
  841. bookmarkArr.Add("dayTime", DateTime.Now.ToString("yyyy年MM月dd日"));//今天日期
  842. var ClientItemList = ClientItem.ToList();
  843. string UsersTop = string.Empty;//word中人员以及金额
  844. decimal WordAllPrice = 0.00M;
  845. //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(),
  846. // 6, 3 + dac1.Where(x=>!string.IsNullOrWhiteSpace(x.Place)).Select(x=>(Convert.ToDecimal(x.SubTotal) / Convert.ToDecimal(x.Cost)).ToString().Length).Max() };
  847. //遍历人员
  848. for (int i = 0; i < ClientItemList.Count(); i++)
  849. {
  850. Dictionary<string, string> TeableBookmarkArr = new Dictionary<string, string>();
  851. var client = ClientItemList[i]; //每个人员
  852. var firstName = ClientItemList[i].Name;
  853. //计算费用总和
  854. decimal airPrice = client.AirType == 460 ? _EnterExitCosts.AirJJ : _EnterExitCosts.AirGW;
  855. decimal AllPrice = airPrice + _EnterExitCosts.CityTranffic + dac1.Sum(x => x.SubTotal) + dac2.Sum(x => x.SubTotal) +
  856. dac3.Sum(x => x.SubTotal) + dac4.Sum(x => x.SubTotal) + _EnterExitCosts.Visa + _EnterExitCosts.Safe +
  857. _EnterExitCosts.Service;
  858. WordAllPrice += AllPrice;
  859. UsersTop += firstName + "出访费用为¥" + AllPrice.ToString("#0.00") + "元、";
  860. TeableBookmarkArr.Add("jp",(client.AirType == 460 ? _EnterExitCosts.AirJJ : _EnterExitCosts.AirGW).ToString("#0.00") + " 元"); //机票金额
  861. TeableBookmarkArr.Add("cs", _EnterExitCosts.CityTranffic.ToString("#0.00") + " 元"); //城市交通费用
  862. TeableBookmarkArr.Add("zs", dac1.Sum(x => Convert.ToDecimal(x.SubTotal)).ToString("#0.00") + " 元"); //住宿费
  863. string zsinfo = string.Empty;
  864. string hsinfo = string.Empty;
  865. string gzinfo = string.Empty;
  866. List<string> placeArr = new List<string>();
  867. Aspose.Words.Tables.Table FirstTable = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 0, true);
  868. Aspose.Words.Tables.Table ChildTable = (Aspose.Words.Tables.Table)FirstTable.GetChild(NodeType.Table, 0, true);
  869. Aspose.Words.Tables.Table ChildTable1 = (Aspose.Words.Tables.Table)FirstTable.GetChild(NodeType.Table, 1, true);
  870. Aspose.Words.Tables.Table ChildTable2 = (Aspose.Words.Tables.Table)FirstTable.GetChild(NodeType.Table, 2, true);
  871. int rowIndex = 0;
  872. foreach (var item in dac1)
  873. {
  874. if (string.IsNullOrWhiteSpace(item.Place))
  875. {
  876. continue;
  877. }
  878. if (placeArr.Contains(item.Place))
  879. {
  880. continue;
  881. }
  882. else
  883. {
  884. placeArr.Add(item.Place);
  885. }
  886. if (!string.IsNullOrWhiteSpace(item.Place))
  887. {
  888. if (rowIndex > ChildTable.Rows.Count - 1)
  889. {
  890. var chitableRow = ChildTable.LastRow.Clone(true);
  891. ChildTable.AppendChild(chitableRow);
  892. }
  893. int days = dac1.FindAll(x => x.Place == item.Place).Count();
  894. SetCells(ChildTable, doc, rowIndex, 0, item.Place);
  895. SetCells(ChildTable, doc, rowIndex, 1, days + "晚");
  896. SetCells(ChildTable, doc, rowIndex, 2, item.Cost + item.Currency + "/晚");
  897. SetCells(ChildTable, doc, rowIndex, 3, " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00"));
  898. SetCells(ChildTable, doc, rowIndex, 4, "CNY" + item.SubTotal * days + "\r\n");
  899. rowIndex++;
  900. zsinfo += item.Place + " " + days + "晚 " + item.Cost + item.Currency + "/晚" + " 汇率" + (item.SubTotal /item.Cost).ToString("#0.00") + " CNY" + item.SubTotal * days + "\r\n";
  901. }
  902. }
  903. placeArr.Clear();
  904. rowIndex = 0;
  905. foreach (var item in dac2)
  906. {
  907. if (string.IsNullOrWhiteSpace(item.Place))
  908. {
  909. continue;
  910. }
  911. if (placeArr.Contains(item.Place))
  912. {
  913. continue;
  914. }
  915. else
  916. {
  917. placeArr.Add(item.Place);
  918. }
  919. if (!string.IsNullOrWhiteSpace(item.Place))
  920. {
  921. if (rowIndex > ChildTable1.Rows.Count - 1)
  922. {
  923. var chitableRow = ChildTable1.LastRow.Clone(true);
  924. ChildTable1.AppendChild(chitableRow);
  925. }
  926. int days = dac2.FindAll(x => x.Place == item.Place).Count();
  927. SetCells(ChildTable1, doc, rowIndex, 0, item.Place);
  928. SetCells(ChildTable1, doc, rowIndex, 1, days + "天");
  929. SetCells(ChildTable1, doc, rowIndex, 2, item.Cost + item.Currency + "/天");
  930. SetCells(ChildTable1, doc, rowIndex, 3, " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00"));
  931. SetCells(ChildTable1, doc, rowIndex, 4, "CNY" +item.SubTotal * days);
  932. rowIndex++;
  933. hsinfo += item.Place + " " + days + "天 " + item.Cost + item.Currency + "/天" + " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00") + " CNY" +item.SubTotal * days + "\r\n";
  934. }
  935. }
  936. placeArr.Clear();
  937. rowIndex = 0;
  938. foreach (var item in dac3)
  939. {
  940. if (string.IsNullOrWhiteSpace(item.Place))
  941. {
  942. continue;
  943. }
  944. if (placeArr.Contains(item.Place))
  945. {
  946. continue;
  947. }
  948. else
  949. {
  950. placeArr.Add(item.Place);
  951. }
  952. if (!string.IsNullOrWhiteSpace(item.Place))
  953. {
  954. if (rowIndex > ChildTable2.Rows.Count - 1)
  955. {
  956. var chitableRow = ChildTable2.LastRow.Clone(true);
  957. ChildTable2.AppendChild(chitableRow);
  958. }
  959. int days = dac3.FindAll(x => x.Place == item.Place).Count();
  960. SetCells(ChildTable2, doc, rowIndex, 0, item.Place);
  961. SetCells(ChildTable2, doc, rowIndex, 1, days + "天");
  962. SetCells(ChildTable2, doc, rowIndex, 2, item.Cost + item.Currency + "/天");
  963. SetCells(ChildTable2, doc, rowIndex, 3, " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00"));
  964. SetCells(ChildTable2, doc, rowIndex, 4, "CNY" + item.SubTotal * days + "\r\n");
  965. rowIndex++;
  966. gzinfo += item.Place + " " + days + "天 " + item.Cost + item.Currency + "/天" + " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00") + " CNY" + item.SubTotal * days + "\r\n";
  967. }
  968. }
  969. placeArr.Clear();
  970. TeableBookmarkArr.Add("zsinfo", zsinfo); //住宿费详情
  971. TeableBookmarkArr.Add("hs", dac2.Sum(x => Convert.ToDecimal(x.SubTotal)).ToString("#0.00") + " 元"); //伙食费
  972. TeableBookmarkArr.Add("hsinfo", hsinfo); //伙食费详情
  973. TeableBookmarkArr.Add("gz", dac3.Sum(x => Convert.ToDecimal(x.SubTotal)).ToString("#0.00") + " 元"); //公杂费
  974. TeableBookmarkArr.Add("gzinfo", gzinfo); //公杂费详情
  975. TeableBookmarkArr.Add("qt", (_EnterExitCosts.Visa + _EnterExitCosts.Safe).ToString("#0.00") + " 元");//其他费用
  976. TeableBookmarkArr.Add("qtinfo", $"(签证费{_EnterExitCosts.Visa.ToString("#0.00")}元、保险{_EnterExitCosts.Safe.ToString("#0.00")}元等费用)");//其他费用第二列
  977. TeableBookmarkArr.Add("fw", _EnterExitCosts.Service.ToString("#0.00") + "元/人");//服务费
  978. TeableBookmarkArr.Add("AllPrice", AllPrice.ToString("#0.00") + "元/人");//表格合计费用
  979. string airStr = client.AirType == 460 ? "经济舱" : client.AirType == 458 ? "公务舱" : "";
  980. TeableBookmarkArr.Add("title", $"费用清单-{airStr}({firstName})");
  981. foreach (var book in TeableBookmarkArr.Keys)
  982. {
  983. if (doc.Range.Bookmarks[book] != null)
  984. {
  985. Bookmark mark = doc.Range.Bookmarks[book];
  986. mark.Text = TeableBookmarkArr[book];
  987. }
  988. }
  989. if (i != ClientItemList.Count - 1)
  990. {
  991. builder.PageSetup.Orientation = Aspose.Words.Orientation.Portrait;
  992. Aspose.Words.Tables.Table table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 0, true);
  993. table.ParentNode.InsertAfter(paragraph, table);
  994. var CloneTable = (Aspose.Words.Tables.Table)table.Clone(true);
  995. table.ParentNode.InsertAfter(CloneTable, paragraph);
  996. }
  997. TeableBookmarkArr.Clear();
  998. }
  999. bookmarkArr.Add("VisitPrice", WordAllPrice.ToString());//出访费用总额
  1000. bookmarkArr.Add("CnAllPrice", WordAllPrice.ConvertCNYUpper());//出访费用总额中文
  1001. bookmarkArr.Add("namesPrice", UsersTop.TrimEnd('、'));//各人员出访费用 付辰同志出访费用为¥73,604.8元
  1002. foreach (var book in bookmarkArr.Keys)
  1003. {
  1004. if (doc.Range.Bookmarks[book] != null)
  1005. {
  1006. Bookmark mark = doc.Range.Bookmarks[book];
  1007. mark.Text = bookmarkArr[book];
  1008. }
  1009. }
  1010. //MemoryStream outSteam = new MemoryStream();
  1011. string filsPath = AppSettingsHelper.Get("WordBasePath") + $"ForeignReceivables/File/{ClientItem.Key}.docx";
  1012. doc.Save(filsPath);
  1013. filesToZip.Add(filsPath);
  1014. //streams.Add(ClientItem.Key + ".docx", outSteam.ToArray());
  1015. }
  1016. //文件名
  1017. string zipFileName = _DelegationInfo.TeamName + "-收款账单.zip";
  1018. string zipPath = $"ForeignReceivables/File/{_DelegationInfo.TeamName}-收款账单{DateTime.Now.ToString("yyyyMMddHHmmss")}.zip";
  1019. try
  1020. {
  1021. using (var zip = ZipFile.Open(AppSettingsHelper.Get("WordBasePath") + zipPath, ZipArchiveMode.Create))
  1022. {
  1023. foreach (var file in filesToZip)
  1024. {
  1025. zip.CreateEntryFromFile(file, Path.GetFileName(file));
  1026. }
  1027. }
  1028. }
  1029. catch (Exception ex)
  1030. {
  1031. return Ok(JsonView(false, ex.Message));
  1032. }
  1033. string url = AppSettingsHelper.Get("WordBaseUrl") + $"Office/Word/{zipPath}";
  1034. return Ok(JsonView(true, "成功", new { Url = url }));
  1035. }
  1036. return Ok(JsonView(false, "操作失败!"));
  1037. }
  1038. catch (Exception ex)
  1039. {
  1040. return Ok(JsonView(false, ex.Message));
  1041. }
  1042. }
  1043. private void SetCells(Aspose.Words.Tables.Table table, Document doc, int rows, int cells, string val)
  1044. {
  1045. //获取table中的某个单元格,从0开始
  1046. Aspose.Words.Tables.Cell lshCell = table.Rows[rows].Cells[cells];
  1047. //将单元格中的第一个段落移除
  1048. lshCell.FirstParagraph.Remove();
  1049. //新建一个段落
  1050. Paragraph p = new Paragraph(doc);
  1051. var r = new Run(doc, val);
  1052. r.Font.Size = 8;
  1053. //把设置的值赋给之前新建的段落
  1054. p.AppendChild(r);
  1055. //将此段落加到单元格内
  1056. lshCell.AppendChild(p);
  1057. }
  1058. #endregion
  1059. #region 已收款项
  1060. /// <summary>
  1061. /// 已收款项
  1062. /// 查询
  1063. /// </summary>
  1064. /// <param name="dto"></param>
  1065. /// <returns></returns>
  1066. [HttpPost]
  1067. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1068. public async Task<IActionResult> PostAmountReceived(AmountReceivedDto dto)
  1069. {
  1070. try
  1071. {
  1072. if (dto == null)
  1073. {
  1074. return Ok(JsonView(false, "参数不能为空!"));
  1075. }
  1076. Result ffrData = await _proceedsReceivedRep.PostAmountReceived(dto.DiId);
  1077. dynamic data = null;
  1078. if (dto.PortType == 1)
  1079. {
  1080. if (ffrData.Code != 0)
  1081. {
  1082. return Ok(JsonView(false, ffrData.Msg));
  1083. }
  1084. data = ffrData.Data;
  1085. }
  1086. else if (dto.PortType == 2)
  1087. {
  1088. if (ffrData.Code != 0)
  1089. {
  1090. return Ok(JsonView(false, ffrData.Msg));
  1091. }
  1092. data = ffrData.Data;
  1093. }
  1094. else if (dto.PortType == 2)
  1095. {
  1096. if (ffrData.Code != 0)
  1097. {
  1098. return Ok(JsonView(false, ffrData.Msg));
  1099. }
  1100. data = ffrData.Data;
  1101. }
  1102. else
  1103. {
  1104. return Ok(JsonView(false, "请选择正确的端口号!"));
  1105. }
  1106. return Ok(JsonView(true, "操作成功!", data));
  1107. }
  1108. catch (Exception ex)
  1109. {
  1110. return Ok(JsonView(false, ex.Message));
  1111. }
  1112. }
  1113. /// <summary>
  1114. /// 已收款项
  1115. /// Add Or Edit
  1116. /// </summary>
  1117. /// <param name="dto"></param>
  1118. /// <returns></returns>
  1119. [HttpPost]
  1120. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1121. public async Task<IActionResult> PostAmountReceivedAddOrEdit(AmountReceivedAddOrEditDto dto)
  1122. {
  1123. try
  1124. {
  1125. if (dto == null)
  1126. {
  1127. return Ok(JsonView(false, "参数不能为空!"));
  1128. }
  1129. Result ffrData = await _proceedsReceivedRep.PostAmountReceivedAddOrEditDto(dto);
  1130. if (dto.PortType == 1)
  1131. {
  1132. if (ffrData.Code != 0)
  1133. {
  1134. return Ok(JsonView(false, ffrData.Msg));
  1135. }
  1136. }
  1137. else if (dto.PortType == 2)
  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
  1152. {
  1153. return Ok(JsonView(false, "请选择正确的端口号!"));
  1154. }
  1155. return Ok(JsonView(true, "操作成功!"));
  1156. }
  1157. catch (Exception ex)
  1158. {
  1159. return Ok(JsonView(false, ex.Message));
  1160. }
  1161. }
  1162. /// <summary>
  1163. /// 已收款项
  1164. /// Del
  1165. /// </summary>
  1166. /// <param name="dto"></param>
  1167. /// <returns></returns>
  1168. [HttpPost]
  1169. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1170. public async Task<IActionResult> PostAmountReceived_Del(AmountReceivedDelDto dto)
  1171. {
  1172. try
  1173. {
  1174. if (dto == null)
  1175. {
  1176. return Ok(JsonView(false, "参数不能为空!"));
  1177. }
  1178. Result ffrData = await _proceedsReceivedRep.PostAmountReceivedDel(dto);
  1179. if (ffrData.Code != 0)
  1180. {
  1181. return Ok(JsonView(false, ffrData.Msg));
  1182. }
  1183. return Ok(JsonView(true, "操作成功!"));
  1184. }
  1185. catch (Exception ex)
  1186. {
  1187. return Ok(JsonView(false, ex.Message));
  1188. }
  1189. }
  1190. #endregion
  1191. #region 收款退还与其他款项
  1192. /// <summary>
  1193. /// 收款退还与其他款项
  1194. /// 查询 根据团组Id
  1195. /// </summary>
  1196. /// <param name="dto"></param>
  1197. /// <returns></returns>
  1198. [HttpPost]
  1199. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1200. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyItemByDiId(PaymentRefundAndOtherMoneyItemByDiIdDto dto)
  1201. {
  1202. try
  1203. {
  1204. if (dto == null) return Ok(JsonView(false, "参数不能为空!"));
  1205. if (dto.PageId <= 0) return Ok(JsonView(false, "请传入正确的的页面Id!"));
  1206. if (dto.UserId <= 0) return Ok(JsonView(false, "请传入正确的的员工Id!"));
  1207. #region 页面功能权限处理
  1208. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  1209. pageFunAuth = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1210. if (pageFunAuth.CheckAuth == 0)
  1211. {
  1212. return Ok(JsonView(false, "您没有当前页面查询权限!"));
  1213. }
  1214. #endregion
  1215. Result _result = await _paymentRefundAndOtherMoneyRep._ItemByDiId(dto.DiId);
  1216. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //1 Web 2 Android 3 Ios
  1217. {
  1218. if (_result.Code != 0)
  1219. {
  1220. return Ok(JsonView(false, _result.Msg));
  1221. }
  1222. var data = new
  1223. {
  1224. PageFuncAuth = pageFunAuth,
  1225. Data = _result.Data
  1226. };
  1227. return Ok(JsonView(true, "操作成功!", data));
  1228. }
  1229. else
  1230. {
  1231. return Ok(JsonView(false, "请输入正确的端口号! 1 Web 2 Android 3 Ios;"));
  1232. }
  1233. }
  1234. catch (Exception ex)
  1235. {
  1236. return Ok(JsonView(false, ex.Message));
  1237. }
  1238. }
  1239. /// <summary>
  1240. /// 收款退还与其他款项
  1241. /// 删除
  1242. /// </summary>
  1243. /// <param name="dto"></param>
  1244. /// <returns></returns>
  1245. [HttpPost]
  1246. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1247. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyDel(PaymentRefundAndOtherMoneyDelDto dto)
  1248. {
  1249. try
  1250. {
  1251. if (dto == null) return Ok(JsonView(false, "参数不能为空!"));
  1252. if (dto.PageId <= 0) return Ok(JsonView(false, "请传入正确的的页面Id!"));
  1253. if (dto.UserId <= 0) return Ok(JsonView(false, "请传入正确的的员工Id!"));
  1254. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  1255. #region 页面功能权限处理
  1256. pageFunAuth = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1257. #endregion
  1258. if (pageFunAuth.DeleteAuth == 0)
  1259. {
  1260. return Ok(JsonView(false, "您没有当前页面删除权限!"));
  1261. }
  1262. Result _result = await _paymentRefundAndOtherMoneyRep._Del(dto);
  1263. if (_result.Code != 0)
  1264. {
  1265. return Ok(JsonView(false, _result.Msg));
  1266. }
  1267. return Ok(JsonView(true, "操作成功!"));
  1268. }
  1269. catch (Exception ex)
  1270. {
  1271. return Ok(JsonView(false, ex.Message));
  1272. }
  1273. }
  1274. /// <summary>
  1275. /// 收款退还与其他款项
  1276. /// Info Data Source
  1277. /// </summary>
  1278. /// <param name="dto"></param>
  1279. /// <returns></returns>
  1280. [HttpPost]
  1281. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1282. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyInfoDataSource(PortDtoBase dto)
  1283. {
  1284. try
  1285. {
  1286. Result _result = await _paymentRefundAndOtherMoneyRep._InfoDataSource(dto);
  1287. if (_result.Code != 0)
  1288. {
  1289. return Ok(JsonView(false, _result.Msg));
  1290. }
  1291. return Ok(JsonView(true, "查询成功!", _result.Data));
  1292. }
  1293. catch (Exception ex)
  1294. {
  1295. return Ok(JsonView(false, ex.Message));
  1296. }
  1297. }
  1298. /// <summary>
  1299. /// 收款退还与其他款项
  1300. /// Info
  1301. /// </summary>
  1302. /// <param name="dto"></param>
  1303. /// <returns></returns>
  1304. [HttpPost]
  1305. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1306. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyInfo(PaymentRefundAndOtherMoneyInfoDto dto)
  1307. {
  1308. try
  1309. {
  1310. if (dto == null)
  1311. {
  1312. return Ok(JsonView(false, "参数不能为空!"));
  1313. }
  1314. Result _result = await _paymentRefundAndOtherMoneyRep._Info(dto);
  1315. if (_result.Code != 0)
  1316. {
  1317. return Ok(JsonView(false, _result.Msg));
  1318. }
  1319. return Ok(JsonView(true, "查询成功!", _result.Data));
  1320. }
  1321. catch (Exception ex)
  1322. {
  1323. return Ok(JsonView(false, ex.Message));
  1324. }
  1325. }
  1326. /// <summary>
  1327. /// 收款退还与其他款项
  1328. /// 操作(Add Or Edit)
  1329. /// </summary>
  1330. /// <param name="dto"></param>
  1331. /// <returns></returns>
  1332. [HttpPost]
  1333. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1334. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyAddOrEdit(PaymentRefundAndOtherMoneyAddOrEditDto dto)
  1335. {
  1336. try
  1337. {
  1338. if (dto == null) return Ok(JsonView(false, "参数不能为空!"));
  1339. if (dto.PageId <= 0) return Ok(JsonView(false, "请传入正确的的页面Id!"));
  1340. if (dto.UserId <= 0) return Ok(JsonView(false, "请传入正确的的员工Id!"));
  1341. #region 页面功能权限处理
  1342. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  1343. pageFunAuth = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1344. #endregion
  1345. if (dto.Status == 1) //add
  1346. {
  1347. if (pageFunAuth.AddAuth == 0)
  1348. {
  1349. return Ok(JsonView(false, "您没有当前页面添加权限!"));
  1350. }
  1351. }
  1352. else if (dto.Status == 2) //edit
  1353. {
  1354. if (pageFunAuth.EditAuth == 0)
  1355. {
  1356. return Ok(JsonView(false, "您没有当前页面编辑权限!"));
  1357. }
  1358. }
  1359. else
  1360. {
  1361. return Ok(JsonView(false, "请输入正确的操作状态! 1 添加 2 修改!"));
  1362. }
  1363. Result _result = await _paymentRefundAndOtherMoneyRep._AddOrEdit(dto);
  1364. if (_result.Code != 0)
  1365. {
  1366. return Ok(JsonView(false, _result.Msg));
  1367. }
  1368. return Ok(JsonView(true, "操作成功!"));
  1369. }
  1370. catch (Exception ex)
  1371. {
  1372. return Ok(JsonView(false, ex.Message));
  1373. }
  1374. }
  1375. #endregion
  1376. #region 应收报表
  1377. /// <summary>
  1378. /// 应收报表
  1379. /// 查询 根据日期范围
  1380. /// </summary>
  1381. /// <param name="dto"></param>
  1382. /// <returns></returns>
  1383. [HttpPost]
  1384. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1385. public async Task<IActionResult> PostSyntheticalReceivableByDateRange(PostSyntheticalReceivableByDateRangeDto dto)
  1386. {
  1387. string sqlWhere = " Where di.IsDel=0 ";
  1388. #region 验证
  1389. if (string.IsNullOrEmpty(dto.beginDt) && string.IsNullOrEmpty(dto.endDt))
  1390. {
  1391. return Ok(JsonView(false, "日期参数至少填写一个!"));
  1392. }
  1393. if (!string.IsNullOrEmpty(dto.beginDt))
  1394. {
  1395. if (Regex.Match(dto.beginDt, @"^\d{4}-\d{2}-\d{2}$").Value.Length < 1)
  1396. {
  1397. return Ok(JsonView(false, "日期参数格式错误,应为yyyy-MM-dd!"));
  1398. }
  1399. else
  1400. {
  1401. sqlWhere += string.Format(@" And di.VisitDate >= '{0} 00:00:00' ", dto.beginDt);
  1402. }
  1403. }
  1404. if (!string.IsNullOrEmpty(dto.endDt))
  1405. {
  1406. if (Regex.Match(dto.endDt, @"^\d{4}-\d{2}-\d{2}$").Value.Length < 1)
  1407. {
  1408. return Ok(JsonView(false, "日期参数格式错误,应为yyyy-MM-dd!"));
  1409. }
  1410. else
  1411. {
  1412. sqlWhere += string.Format(@" And di.VisitDate <= '{0} 23:59:59' ", dto.endDt);
  1413. }
  1414. }
  1415. #endregion
  1416. 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);
  1417. List<PostSyntheticalReceivableByDateRangeView> list_rst = _sqlSugar.SqlQueryable<PostSyntheticalReceivableByDateRangeView>(sql).ToList();
  1418. decimal sumAll_fr = 0M;
  1419. decimal sumAll_pr = 0M;
  1420. decimal sumAll_balance = 0M;
  1421. if (list_rst.Count > 0)
  1422. {
  1423. int rowNumber = 1;
  1424. foreach (var item_rst in list_rst)
  1425. {
  1426. item_rst.No = rowNumber;
  1427. rowNumber++;
  1428. int diId = item_rst.diid;
  1429. decimal sum_fr = 0M;
  1430. decimal sum_pr = 0M;
  1431. string str_client = string.Empty;
  1432. decimal sum_other = 0M; //收款退还
  1433. decimal sum_extra = 0M; //超支费用
  1434. decimal balance = 0M;
  1435. string str_schedule = string.Empty;
  1436. //1. 缺超支费用!!!!!!!!!!!!!!!!!!!!
  1437. string sql_fr = string.Format(@" Select * From Fin_ForeignReceivables Where IsDel=0 And Diid={0} ", diId);
  1438. List<Fin_ForeignReceivables> list_fr = _sqlSugar.SqlQueryable<Fin_ForeignReceivables>(sql_fr).ToList();
  1439. sum_fr = list_fr.Sum(s => s.ItemSumPrice);
  1440. //2.
  1441. string sql_pr = string.Format(@" Select * From Fin_ProceedsReceived Where IsDel=0 And Diid={0} ", diId);
  1442. List<Fin_ProceedsReceived> list_pr = _sqlSugar.SqlQueryable<Fin_ProceedsReceived>(sql_pr).ToList();
  1443. foreach (var item_pr in list_pr)
  1444. {
  1445. sum_pr += item_pr.Price;
  1446. str_client += string.Format(@"{0};", item_pr.Client);
  1447. str_schedule += string.Format(@"{0};", item_pr.Remark);
  1448. }
  1449. if (str_schedule.Length > 0)
  1450. {
  1451. str_schedule = str_schedule.TrimEnd(';');
  1452. }
  1453. if (str_client.Length > 0)
  1454. {
  1455. str_client = str_client.TrimEnd(';');
  1456. }
  1457. //3.
  1458. string sql_other = string.Format(@" Select * From Fin_OtherPrice where diid = {0} and isdel = 0 and RefundType = 1 and PayType=1 ", diId);
  1459. List<Fin_OtherPrice> list_other = _sqlSugar.SqlQueryable<Fin_OtherPrice>(sql_other).ToList();
  1460. sum_other = list_other.Sum(s => s.Price);
  1461. //4.
  1462. string sql_extra = string.Format(@" Select c.* From Fin_GroupExtraCost f
  1463. Inner join Grp_CreditCardPayment c On f.Id = c.CId
  1464. Where c.CTable = 1015 And c.IsPay = 1 And f.IsDel = 0 And c.IsDel = 0 And f.DiId = {0} ", diId);
  1465. List<Grp_CreditCardPayment> list_extra = _sqlSugar.SqlQueryable<Grp_CreditCardPayment>(sql_extra).ToList();
  1466. sum_extra = list_extra.Sum(s => s.RMBPrice);
  1467. item_rst.frPrice = (sum_fr + sum_extra).ToString("#0.00");
  1468. item_rst.prPrice = (sum_pr - sum_other).ToString("#0.00");
  1469. item_rst.balPrice = ((sum_fr + sum_extra) - (sum_pr - sum_other)).ToString("#0.00");
  1470. item_rst.prClient = str_client;
  1471. item_rst.schedule = str_schedule;
  1472. string tempVisitDate = Convert.ToDateTime(item_rst.visitDate).ToString("yyyy-MM-dd");
  1473. sumAll_fr += (sum_fr + sum_extra);
  1474. sumAll_pr += (sum_pr - sum_other);
  1475. sumAll_balance += ((sum_fr + sum_extra) - (sum_pr - sum_other));
  1476. }
  1477. PostSyntheticalReceivableByDateRangeResultView result = new PostSyntheticalReceivableByDateRangeResultView();
  1478. result.total_fr = sumAll_fr.ToString("#0.00");
  1479. result.total_pr = sumAll_pr.ToString("#0.00");
  1480. result.total_balance = sumAll_balance.ToString("#0.00");
  1481. result.dataList = new List<PostSyntheticalReceivableByDateRangeView>(list_rst);
  1482. if (dto.requestType == 1)
  1483. {
  1484. return Ok(JsonView(true, "请求成功", result, list_rst.Count));
  1485. }
  1486. else
  1487. {
  1488. //----------------------------
  1489. List<Excel_SyntheticalReceivableByDateRange> list_Ex = new List<Excel_SyntheticalReceivableByDateRange>();
  1490. WorkbookDesigner designer = new WorkbookDesigner();
  1491. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/应收款项模板 - 副本.xls");
  1492. int excNo = 1;
  1493. foreach (var item in list_rst)
  1494. {
  1495. Excel_SyntheticalReceivableByDateRange exc = new Excel_SyntheticalReceivableByDateRange();
  1496. exc.No = excNo.ToString();
  1497. excNo++;
  1498. exc.TeamName = item.teamName;
  1499. exc.ClientUnit = item.clientUnit;
  1500. exc.VisitDate = item.visitDate;
  1501. exc.Accounts = item.frPrice;
  1502. exc.Received = item.prPrice;
  1503. exc.Balance = item.balPrice;
  1504. exc.Collection = item.schedule;
  1505. DateTime time = Convert.ToDateTime(item.visitDate);
  1506. TimeSpan ts = DateTime.Now - time;
  1507. float SY = float.Parse(item.balPrice);
  1508. if (ts.Days >= 365 && SY > 0)
  1509. {
  1510. exc.Sign = "需收款";
  1511. }
  1512. else
  1513. {
  1514. exc.Sign = "";
  1515. }
  1516. list_Ex.Add(exc);
  1517. }
  1518. var dt = CommonFun.GetDataTableFromIList(list_Ex);
  1519. dt.TableName = "Excel_SyntheticalReceivableByDateRange";
  1520. if (dt != null)
  1521. {
  1522. designer.SetDataSource("SumPrice", "应收合计:" + result.total_fr + "RMB 已收合计:" + result.total_pr + "RMB 余款合计:" + result.total_balance + "RMB");
  1523. //数据源
  1524. designer.SetDataSource(dt);
  1525. //根据数据源处理生成报表内容
  1526. designer.Process();
  1527. string fileName = ("Receivable/应收款项(" + dto.beginDt + "~" + dto.endDt + ").xlsx");
  1528. designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
  1529. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  1530. return Ok(JsonView(true, "成功", new { url = rst }));
  1531. }
  1532. }
  1533. }
  1534. return Ok(JsonView(true, "获取成功", "", list_rst.Count));
  1535. }
  1536. #endregion
  1537. #region 付款申请
  1538. /// <summary>
  1539. /// 付款申请
  1540. /// 查询 根据日期范围
  1541. /// </summary>
  1542. /// <param name="dto"></param>
  1543. /// <returns></returns>
  1544. [HttpPost]
  1545. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1546. public async Task<IActionResult> PostPayRequest_Center(PostPayRequestByDateRangeDto dto)
  1547. {
  1548. #region 验证
  1549. DateTime beginDt, endDt;
  1550. string format = "yyyy-MM-dd";
  1551. if (!DateTime.TryParseExact(dto.beginDt, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out beginDt))
  1552. {
  1553. return Ok(JsonView(false, "开始日期格式不正确!正确格式:yyyy-MM-dd"));
  1554. }
  1555. if (!DateTime.TryParseExact(dto.endDt, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out endDt))
  1556. {
  1557. return Ok(JsonView(false, "结束日期格式不正确!正确格式:yyyy-MM-dd"));
  1558. }
  1559. #endregion
  1560. try
  1561. {
  1562. tree_Fin_DailyFeePaymentResult dailyResult = PayRequest_DailyByDateRange(dto.beginDt, dto.endDt);
  1563. tree_Group_DailyFeePaymentResult groupResult = PayRequest_PaymentByDateRange(dto.beginDt, dto.endDt);
  1564. return Ok(JsonView(true, "获取成功", new { daily = dailyResult, group = groupResult }));
  1565. }
  1566. catch (Exception ex)
  1567. {
  1568. return Ok(JsonView(false, ex.Message));
  1569. }
  1570. }
  1571. /// <summary>
  1572. /// 付款申请(日付申请相关)
  1573. /// 查询 根据日期范围
  1574. /// </summary>
  1575. /// <param name="dto"></param>
  1576. /// <returns></returns>
  1577. private tree_Group_DailyFeePaymentResult PayRequest_PaymentByDateRange(string beginDt, string endDt)
  1578. {
  1579. tree_Group_DailyFeePaymentResult _DailyFeePaymentResult = new tree_Group_DailyFeePaymentResult();
  1580. List<tree_Group_DailyFeePaymentPageListView> dataList = new List<tree_Group_DailyFeePaymentPageListView>();
  1581. #region sql条件处理
  1582. string sqlWhere = string.Format(@"And (AuditGMDate Between '{0} 00:00:00' And '{1} 23:59:59') ", beginDt, endDt);
  1583. string sql_1 = string.Format(@"Select * From Grp_CreditCardPayment Where IsDel = 0 And IsPay = 0 And IsAuditGM = 1 {0}", sqlWhere);
  1584. #endregion
  1585. var _paymentDatas = _sqlSugar.SqlQueryable<Grp_CreditCardPayment>(sql_1).ToList();//付款信息
  1586. _DailyFeePaymentResult.gz = _paymentDatas.Where(it => it.OrbitalPrivateTransfer == 0).Sum(it => ((it.PayMoney * it.DayRate) / 100) * it.PayPercentage); //公转
  1587. _DailyFeePaymentResult.sz = _paymentDatas.Where(it => it.OrbitalPrivateTransfer == 1).Sum(it => ((it.PayMoney * it.DayRate) / 100) * it.PayPercentage); ; //私转
  1588. List<int> groupIds = _paymentDatas.Select(it => it.DIId).Distinct().ToList();
  1589. List<int> teamDids = new List<int> { 300, 302, 248 }; //团组类型 不含
  1590. var _groupDatas = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && groupIds.Contains(it.Id) && !teamDids.Contains(it.TeamDid)).ToList();
  1591. #region 相关基础数据源
  1592. var userDatas = _sqlSugar.Queryable<Sys_Users>().ToList();
  1593. var setDatas = _sqlSugar.Queryable<Sys_SetData>().ToList();
  1594. var hotelDatas = _sqlSugar.Queryable<Grp_HotelReservations>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1595. var opDatas = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1596. var visaDatas = _sqlSugar.Queryable<Grp_VisaInfo>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DIId)).ToList();
  1597. var ioaDatas = _sqlSugar.Queryable<Grp_InvitationOfficialActivities>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1598. var insureDatas = _sqlSugar.Queryable<Grp_Customers>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1599. var airDatas = _sqlSugar.Queryable<Grp_AirTicketReservations>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DIId)).ToList();
  1600. var otherMoneyDatas = _sqlSugar.Queryable<Fin_OtherPrice>().Where(it => it.IsDel == 0 && groupIds.Contains(it.Diid)).ToList();
  1601. var refundPaymentDatas = _sqlSugar.Queryable<Fin_PaymentRefundAndOtherMoney>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1602. var ExtraCostDatas = _sqlSugar.Queryable<Fin_GroupExtraCost>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1603. #endregion
  1604. foreach ( var groupInfo in _groupDatas)
  1605. {
  1606. List<Group_DailyFeePaymentContentInfolView> childList = new List<Group_DailyFeePaymentContentInfolView>();
  1607. var groupPaymentDatas = _paymentDatas.Where(it => groupInfo.Id == it.DIId).ToList();
  1608. int rouNumber = 1;
  1609. foreach (var payInfo in groupPaymentDatas)
  1610. {
  1611. string priName = "";
  1612. switch (payInfo.CTable)
  1613. {
  1614. case 76: //76 酒店预订
  1615. priName = hotelDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.HotelName ?? "";
  1616. break;
  1617. case 79: //79 车/导游地接
  1618. var opData = opDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id);
  1619. if (opData != null)
  1620. {
  1621. if (payInfo.OrbitalPrivateTransfer == 0) //公转
  1622. {
  1623. priName = "【四川泛美交流有限公司】" + "【公转】" + "【导游:" + opData.ServiceGuide + "】" + opData.Area;
  1624. }
  1625. else if (payInfo.OrbitalPrivateTransfer == 1) //私转
  1626. {
  1627. priName = "【四川泛美交流有限公司】" + "【私转】" + "【导游:" + opData.ServiceGuide + "】" + opData.Area;
  1628. }
  1629. }
  1630. break;
  1631. case 80: // 80 签证
  1632. priName = visaDatas.Find(it => payInfo.DIId == it.DIId && payInfo.CId == it.Id)?.VisaClient ?? "";
  1633. break;
  1634. case 81: // 81 邀请/公务活动
  1635. priName = ioaDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.Inviter ?? "";
  1636. break;
  1637. case 82: // 82 团组客户保险
  1638. priName = insureDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.ClientName ?? "";
  1639. break;
  1640. case 85: // 85 机票预订
  1641. string flightsCode = airDatas.Find(it => payInfo.DIId == it.DIId && payInfo.CId == it.Id)?.FlightsCode ?? "";
  1642. string airPayType = setDatas.Find(it => it.Id == payInfo.PayDId)?.Name ?? "";
  1643. priName = $"{flightsCode}【{airPayType}】";
  1644. break;
  1645. case 98: // 98 其他款项
  1646. priName = otherMoneyDatas.Find(it => payInfo.DIId == it.Diid && payInfo.CId == it.Id)?.PriceName ?? "";
  1647. break;
  1648. case 285: // 285 收款退还
  1649. priName = refundPaymentDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.PriceName ?? "";
  1650. break;
  1651. case 1015: // 1015 超支费用
  1652. priName = ExtraCostDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.PriceName ?? "";
  1653. break;
  1654. default:
  1655. priName = "";
  1656. break;
  1657. }
  1658. childList.Add(new Group_DailyFeePaymentContentInfolView()
  1659. {
  1660. Id = payInfo.Id,
  1661. Payee = payInfo.Payee,
  1662. RowNumber = rouNumber,
  1663. Applicant = userDatas.Find(it => it.Id == payInfo.CreateUserId)?.CnName ?? "",
  1664. PayType = setDatas.Find(it => it.Id == payInfo.PayDId)?.Name ?? "",
  1665. PriceName = priName,
  1666. ModuleName = setDatas.Find(it => it.Id == payInfo.CTable)?.Name ?? "",
  1667. PayCurrCode = setDatas.Find(it => it.Id == payInfo.PaymentCurrency)?.Name ?? "",
  1668. PaymentAmount = payInfo.PayMoney,
  1669. PayRate = payInfo.DayRate,
  1670. CNYSubTotalAmount = ((payInfo.DayRate * payInfo.PayMoney) / 100) * payInfo.PayPercentage //此次付款金额
  1671. }) ;
  1672. rouNumber++;
  1673. }
  1674. dataList.Add(new tree_Group_DailyFeePaymentPageListView()
  1675. {
  1676. GroupName = groupInfo.TeamName,
  1677. CNYTotalAmount = childList.Sum(it => it.CNYSubTotalAmount),
  1678. ChildList = childList,
  1679. });
  1680. }
  1681. _DailyFeePaymentResult.dataList = dataList;
  1682. return _DailyFeePaymentResult;
  1683. }
  1684. /// <summary>
  1685. /// 付款申请(日付申请相关)
  1686. /// 查询 根据日期范围
  1687. /// </summary>
  1688. /// <param name="dto"></param>
  1689. /// <returns></returns>
  1690. private tree_Fin_DailyFeePaymentResult PayRequest_DailyByDateRange(string beginDt, string endDt)
  1691. {
  1692. #region sql条件处理
  1693. string sqlWhere = string.Format(@" And dfp.CreateTime between '{0} 00:00:00' And '{1} 23:59:59' ", beginDt, endDt);
  1694. string sql_1 = string.Format(@"Select * From (
  1695. Select row_number() over (order by dfp.Id Desc) as RowNumber,
  1696. dfp.Id,dfp.CompanyId,c.CompanyName,dfp.Instructions,dfp.SumPrice,
  1697. dfp.CreateUserId,u.CnName CreateUser,dfp.CreateTime,dfp.FAudit,dfp.MAudit,
  1698. dfp.PriceTypeId,dfp.TransferTypeId
  1699. From Fin_DailyFeePayment dfp
  1700. Inner Join Sys_Company c On dfp.CompanyId = c.Id
  1701. Left Join Sys_Users u On dfp.CreateUserId = u.Id
  1702. Where dfp.IsDel=0 {0} And dfp.FAudit = 1 And dfp.MAudit = 1
  1703. ) temp ", sqlWhere);
  1704. #endregion
  1705. List<tree_Fin_DailyFeePaymentPageListView> DailyFeePaymentData = _sqlSugar.SqlQueryable<tree_Fin_DailyFeePaymentPageListView>(sql_1).ToList();
  1706. Dictionary<int, string> dic_setData = new Dictionary<int, string>();
  1707. foreach (var item in DailyFeePaymentData)
  1708. {
  1709. if (dic_setData.ContainsKey(item.PriceTypeId))
  1710. {
  1711. item.priceTypeStr = dic_setData[item.PriceTypeId];
  1712. }
  1713. else
  1714. {
  1715. Sys_SetData sd_priceType = _daiRep.Query<Sys_SetData>(s => s.Id == item.PriceTypeId).First();
  1716. if (sd_priceType != null)
  1717. {
  1718. item.priceTypeStr = sd_priceType.Name;
  1719. dic_setData.Add(item.PriceTypeId, sd_priceType.Name);
  1720. }
  1721. }
  1722. if (dic_setData.ContainsKey(item.transferTypeId))
  1723. {
  1724. item.transferTypeIdStr = dic_setData[item.transferTypeId];
  1725. Sys_SetData sd_transfer = _daiRep.Query<Sys_SetData>(s => s.Id == item.transferTypeId).First();
  1726. if (sd_transfer != null)
  1727. {
  1728. item.transferParentId = sd_transfer.STid;
  1729. item.transferParentIdStr = sd_transfer.STid == 62 ? "公转" : sd_transfer.STid == 63 ? "私转" : "";
  1730. }
  1731. }
  1732. else
  1733. {
  1734. Sys_SetData sd_transfer = _daiRep.Query<Sys_SetData>(s => s.Id == item.transferTypeId).First();
  1735. if (sd_transfer != null)
  1736. {
  1737. item.transferTypeIdStr = sd_transfer.Name;
  1738. item.transferParentId = sd_transfer.STid;
  1739. item.transferParentIdStr = sd_transfer.STid == 62 ? "公转" : sd_transfer.STid == 63 ? "私转" : "";
  1740. dic_setData.Add(item.transferTypeId, sd_transfer.Name);
  1741. }
  1742. }
  1743. string feeContentSql = string.Format(@"Select * From Fin_DailyFeePaymentContent
  1744. Where IsDel=0 And DFPId = {0} ", item.Id);
  1745. item.childList = _sqlSugar.SqlQueryable<Fin_DailyFeePaymentContentInfolView>(feeContentSql).ToList();
  1746. }
  1747. decimal total_gz = DailyFeePaymentData.Where(s => s.transferParentId == 62).Sum(d => d.SumPrice ?? 0M);
  1748. decimal total_sz = DailyFeePaymentData.Where(s => s.transferParentId == 63).Sum(d => d.SumPrice ?? 0M);
  1749. var result = new tree_Fin_DailyFeePaymentResult() { gz = total_gz, sz = total_sz, dataList = DailyFeePaymentData };
  1750. return result;
  1751. }
  1752. #endregion
  1753. #region 超支费用
  1754. /// <summary>
  1755. /// 超支费用
  1756. /// 1增、2改、3删
  1757. /// </summary>
  1758. /// <param name="dto"></param>
  1759. /// <returns></returns>
  1760. [HttpPost]
  1761. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1762. public async Task<IActionResult> PostGroupExtraCost_Operator(Fin_GroupExtraCostDto_OP dto)
  1763. {
  1764. #region 验证
  1765. #endregion
  1766. Fin_GroupExtraCost _entity = new Fin_GroupExtraCost();
  1767. _entity.DiId = dto.diId;
  1768. _entity.PriceName = dto.priceName;
  1769. _entity.Price = dto.price;
  1770. _entity.PriceCurrency = dto.currency;
  1771. _entity.PriceType = dto.priceType;
  1772. _entity.Coefficient = dto.coefficient;
  1773. _entity.PriceDetailType = dto.priceDetailType;
  1774. _entity.FilePath = dto.filePath;
  1775. _entity.Remark = dto.remark;
  1776. _daiRep.BeginTran();
  1777. if (dto.editType == 1)
  1778. {
  1779. _entity.CreateUserId = dto.createUser;
  1780. _entity.CreateTime = DateTime.Now;
  1781. _entity.IsDel = 0;
  1782. int returnId = await _daiRep.AddAsyncReturnId<Fin_GroupExtraCost>(_entity);
  1783. if (returnId > 0)
  1784. {
  1785. dto.Id = returnId;
  1786. }
  1787. }
  1788. else if (dto.editType == 2)
  1789. {
  1790. bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
  1791. {
  1792. PriceName = dto.priceName,
  1793. Price = dto.price,
  1794. PriceCurrency = dto.currency,
  1795. PriceType = dto.priceType,
  1796. PriceDetailType = dto.priceDetailType,
  1797. Coefficient = dto.coefficient,
  1798. FilePath = dto.filePath,
  1799. Remark = dto.remark
  1800. });
  1801. if (!res)
  1802. {
  1803. _daiRep.RollbackTran();
  1804. return Ok(JsonView(false, "2操作失败!"));
  1805. }
  1806. }
  1807. else if (dto.editType == 3)
  1808. {
  1809. string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  1810. bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
  1811. {
  1812. IsDel = 1,
  1813. DeleteTime = delTime,
  1814. DeleteUserId = dto.createUser
  1815. });
  1816. if (!res)
  1817. {
  1818. _daiRep.RollbackTran();
  1819. return Ok(JsonView(false, "3操作失败!"));
  1820. }
  1821. }
  1822. else
  1823. {
  1824. _daiRep.RollbackTran();
  1825. return Ok(JsonView(false, "未知的editType"));
  1826. }
  1827. if (!extraCost_editCreditCardPayment(dto))
  1828. {
  1829. return Ok(JsonView(false, "ccp操作失败"));
  1830. }
  1831. _daiRep.CommitTran();
  1832. return Ok(JsonView(false, "操作成功"));
  1833. }
  1834. private bool extraCost_editCreditCardPayment(Fin_GroupExtraCostDto_OP costDto)
  1835. {
  1836. //设置团组汇率
  1837. decimal dcm_dayrate = 1M;
  1838. decimal dcm_rmbPrice = costDto.price;
  1839. int ispay = costDto.payType == 72 ? 1 : 0;
  1840. if (costDto.costSign != 3)
  1841. {
  1842. Grp_TeamRate tr = _daiRep.Query<Grp_TeamRate>(s => s.DiId == costDto.diId && s.CTable == 1015).First();
  1843. if (tr != null)
  1844. {
  1845. if (costDto.currency == 49)
  1846. {
  1847. dcm_dayrate = tr.RateU;
  1848. dcm_rmbPrice = dcm_rmbPrice * tr.RateU;
  1849. }
  1850. else if (costDto.currency == 51)
  1851. {
  1852. dcm_dayrate = tr.RateE;
  1853. dcm_rmbPrice = dcm_rmbPrice * tr.RateE;
  1854. }
  1855. }
  1856. }
  1857. Grp_CreditCardPayment ccp = _daiRep.Query<Grp_CreditCardPayment>(s => s.CId == costDto.Id && s.CTable == 1015).First();
  1858. if (ccp == null)
  1859. {
  1860. ccp = new Grp_CreditCardPayment();
  1861. ccp.PayDId = costDto.payType;// dto
  1862. ccp.ConsumptionPatterns = "";
  1863. ccp.ConsumptionDate = "";
  1864. ccp.CTDId = costDto.payCardId;// dto
  1865. ccp.BankNo = "";
  1866. ccp.CardholderName = "";
  1867. ccp.PayMoney = costDto.price;// dto
  1868. ccp.PaymentCurrency = costDto.currency;// dto
  1869. ccp.CompanyBankNo = "";
  1870. ccp.OtherBankName = "";
  1871. ccp.OtherSideNo = "";
  1872. ccp.OtherSideName = "";
  1873. ccp.Remark = "";
  1874. ccp.CreateUserId = costDto.createUser;
  1875. ccp.CreateTime = DateTime.Now;
  1876. ccp.MFOperator = 0;
  1877. ccp.MFOperatorDate = "";
  1878. ccp.IsAuditDM = 0;
  1879. ccp.AuditDMOperate = 0;
  1880. ccp.AuditDMDate = "";
  1881. ccp.IsAuditMF = 0;
  1882. ccp.AuditMFOperate = 0;
  1883. ccp.AuditMFDate = "";
  1884. ccp.IsAuditGM = 0;
  1885. ccp.AuditGMOperate = 0;
  1886. ccp.AuditGMDate = "";
  1887. ccp.IsPay = ispay; // upd
  1888. ccp.DIId = costDto.diId;// dto
  1889. ccp.CId = costDto.Id;// dto
  1890. ccp.CTable = 1015; //超支费用指向id
  1891. ccp.IsDel = 0;
  1892. ccp.PayPercentage = 100M;
  1893. ccp.PayThenMoney = 0M;
  1894. ccp.PayPercentageOld = 100M;
  1895. ccp.PayThenMoneyOld = 0M;
  1896. ccp.UpdateDate = "";
  1897. ccp.Payee = costDto.payee;// dto
  1898. ccp.OrbitalPrivateTransfer = costDto.costSign;// dto
  1899. ccp.ExceedBudget = 0;
  1900. ccp.DayRate = dcm_dayrate; //upd
  1901. ccp.RMBPrice = dcm_rmbPrice; //upd
  1902. int ccpInsertId = _daiRep.AddReturnId<Grp_CreditCardPayment>(ccp);
  1903. if (ccpInsertId > 0)
  1904. {
  1905. return true;
  1906. }
  1907. }
  1908. else
  1909. {
  1910. if (costDto.editType == 2)
  1911. {
  1912. bool res = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
  1913. {
  1914. PayDId = costDto.payType,
  1915. CTDId = costDto.payCardId,
  1916. PayMoney = costDto.price,
  1917. PaymentCurrency = costDto.currency,
  1918. IsPay = ispay,
  1919. Payee = costDto.payee,
  1920. OrbitalPrivateTransfer = costDto.costSign,
  1921. DayRate = dcm_dayrate,
  1922. RMBPrice = dcm_rmbPrice
  1923. });
  1924. return res;
  1925. }
  1926. else if (costDto.editType == 3)
  1927. {
  1928. string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  1929. bool res2 = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
  1930. {
  1931. IsDel = 1,
  1932. DeleteTime = delTime,
  1933. DeleteUserId = costDto.createUser
  1934. });
  1935. return res2;
  1936. }
  1937. }
  1938. return false;
  1939. }
  1940. /// <summary>
  1941. /// 超支费用
  1942. /// 列表查询
  1943. /// </summary>
  1944. /// <param name="dto"></param>
  1945. /// <returns></returns>
  1946. [HttpPost]
  1947. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1948. public async Task<IActionResult> PostGroupExtraCost_Search(Fin_GroupExtraCostDto_Search dto)
  1949. {
  1950. string sqlWhere = string.Format(@" And f.DiId = {0} ", dto.diId);
  1951. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  1952. int endIndex = startIndex + dto.PageSize - 1;
  1953. string sql_data = string.Format(@"Select * From (
  1954. Select row_number() over (order by f.Id Desc) as RowNumber,f.Id,f.DiId,
  1955. f.PriceName,f.Price,f.FilePath,f.CreateUserId,f.CreateTime,c.IsAuditGM
  1956. From Fin_GroupExtraCost f
  1957. Inner Join Grp_CreditCardPayment c On f.Id = c.CId
  1958. Left Join Sys_Users u On f.CreateUserId = u.Id
  1959. Where f.IsDel=0 And c.CTable = 1015 {0}
  1960. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  1961. string sql_count = string.Format(@"Select Count(1) as DataCount From (
  1962. Select row_number() over (order by f.Id Desc) as RowNumber,f.Id,f.DiId,
  1963. f.PriceName,f.PriceType,f.Price,f.FilePath,f.CreateUserId,f.CreateTime,c.IsAuditGM
  1964. From Fin_GroupExtraCost f
  1965. Inner Join Grp_CreditCardPayment c On f.Id = c.CId
  1966. Left Join Sys_Users u On f.CreateUserId = u.Id
  1967. Where f.IsDel=0 And c.CTable = 1015 {0}
  1968. ) temp ", sqlWhere);
  1969. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  1970. {
  1971. //Fin_DailyFeePaymentPageCount
  1972. var count = await _sqlSugar.SqlQueryable<Fin_GroupExtraCostViewDataCount>(sql_count).FirstAsync();
  1973. List<Fin_GroupExtraCostView> dataList = await _sqlSugar.SqlQueryable<Fin_GroupExtraCostView>(sql_data).ToListAsync();
  1974. Dictionary<int, string> dic_setData = new Dictionary<int, string>();
  1975. Dictionary<int, string> dic_user = new Dictionary<int, string>();
  1976. foreach (var item in dataList)
  1977. {
  1978. //费用详细类型
  1979. if (dic_setData.ContainsKey(item.PriceType))
  1980. {
  1981. item.PriceTypeStr = dic_setData[item.PriceType];
  1982. }
  1983. else
  1984. {
  1985. Sys_SetData sd_priceTypeDetail = _daiRep.Query<Sys_SetData>(s => s.Id == item.PriceType).First();
  1986. if (sd_priceTypeDetail != null)
  1987. {
  1988. string tempName = sd_priceTypeDetail.Name.Replace("n", "");
  1989. item.PriceTypeStr = tempName;
  1990. dic_setData.Add(item.PriceType, tempName);
  1991. }
  1992. }
  1993. //系统用户
  1994. if (dic_user.ContainsKey(item.CreateUserId))
  1995. {
  1996. item.CreateUserIdStr = dic_setData[item.CreateUserId];
  1997. }
  1998. else
  1999. {
  2000. Sys_Users users = _daiRep.Query<Sys_Users>(s => s.Id == item.CreateUserId).First();
  2001. if (users != null)
  2002. {
  2003. item.CreateUserIdStr = users.CnName;
  2004. dic_setData.Add(item.CreateUserId, users.CnName);
  2005. }
  2006. }
  2007. switch (item.IsAuditGM)
  2008. {
  2009. case 0: item.IsAuditGMStr = "未审核"; break;
  2010. case 1: item.IsAuditGMStr = "已通过"; break;
  2011. case 2: item.IsAuditGMStr = "未通过"; break;
  2012. default: item.IsAuditGMStr = "未知状态"; break;
  2013. }
  2014. }
  2015. var result = new ListViewBase<Fin_GroupExtraCostView>
  2016. {
  2017. CurrPageIndex = dto.PageIndex,
  2018. CurrPageSize = dto.PageSize,
  2019. DataCount = count.DataCount,
  2020. DataList = dataList
  2021. };
  2022. return Ok(JsonView(true, "查询成功", result));
  2023. }
  2024. return Ok(JsonView(false, "查询成功"));
  2025. }
  2026. /// <summary>
  2027. /// 超支费用
  2028. /// 数据集合配置
  2029. /// </summary>
  2030. /// <param name="dto"></param>
  2031. /// <returns></returns>
  2032. [HttpPost]
  2033. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2034. public async Task<IActionResult> PostGroupExtraCost_ListDataInit(Fin_GroupExtraCostDto_DataListInit dto)
  2035. {
  2036. //支付方式
  2037. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  2038. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  2039. //超支费用类型
  2040. List<Sys_SetData> PriceType = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 79 && a.IsDel == 0).ToList();
  2041. List<SetDataInfoView> _PriceType = _mapper.Map<List<SetDataInfoView>>(PriceType);
  2042. //超支费用详细类型
  2043. List<Sys_SetData> PriceDetailType = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 80 && a.IsDel == 0).ToList();
  2044. PriceDetailType.ForEach(a => { a.Name = a.Name.Replace("n", ""); });
  2045. List<SetDataInfoView> _PriceDetailType = _mapper.Map<List<SetDataInfoView>>(PriceDetailType);
  2046. var data = new
  2047. {
  2048. Payment = _Payment,
  2049. PriceType = _PriceType,
  2050. PriceDetailType = _PriceDetailType
  2051. };
  2052. return Ok(JsonView(true, "", data));
  2053. }
  2054. #endregion
  2055. }
  2056. }