12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987 |
- using Aspose.Cells;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using OASystem.API.OAMethodLib;
- using OASystem.API.OAMethodLib.File;
- using OASystem.Domain;
- using OASystem.Domain.Dtos.Financial;
- using OASystem.Domain.Dtos.Groups;
- using OASystem.Domain.Entities.Financial;
- using OASystem.Domain.Entities.Groups;
- using OASystem.Domain.ViewModels.Financial;
- using OASystem.Domain.ViewModels.Groups;
- using OASystem.Domain.ViewModels.SmallFun;
- using OASystem.Infrastructure.Repositories.Financial;
- using OASystem.Infrastructure.Repositories.Groups;
- using SqlSugar;
- using StackExchange.Redis;
- using System.Data;
- using static OpenAI.GPT3.ObjectModels.SharedModels.IOpenAiModels;
- using System.Web;
- using Aspose.Words;
- using NPOI.HSSF.Util;
- using OASystem.Domain.Entities.Customer;
- using System.IO.Compression;
- using NPOI.SS.UserModel;
- using System.Net.Http;
- using Google.Protobuf;
- using NPOI.SS.Formula.Functions;
- using System.Globalization;
- using NPOI.POIFS.Properties;
- using SixLabors.ImageSharp.ColorSpaces;
- using OASystem.Domain.ViewModels.QiYeWeChat;
- namespace OASystem.API.Controllers
- {
- /// <summary>
- /// 财务模块
- /// </summary>
- [Route("api/[controller]/[action]")]
- [ApiController]
- public class FinancialController : ControllerBase
- {
- private readonly IMapper _mapper;
- private readonly IConfiguration _config;
- private readonly SqlSugarClient _sqlSugar;
- private readonly HttpClient _httpClient;
- private readonly SetDataTypeRepository _setDataTypeRep;
- private readonly DailyFeePaymentRepository _daiRep; //日付申请仓库
- private readonly TeamRateRepository _teamRateRep; //团组汇率仓库
- private readonly ForeignReceivablesRepository _ForForeignReceivablesRep; //对外收款账单仓库
- private readonly ProceedsReceivedRepository _proceedsReceivedRep; //已收款项仓库
- private readonly PaymentRefundAndOtherMoneyRepository _paymentRefundAndOtherMoneyRep; //收款退还与其他款项 仓库
- /// <summary>
- /// 初始化
- /// </summary>
- public FinancialController(IMapper mapper, IConfiguration configuration, DailyFeePaymentRepository daiRep, SqlSugarClient sqlSugar, SetDataTypeRepository setDataTypeRep,
- TeamRateRepository teamRateRep, ForeignReceivablesRepository ForForeignReceivablesRep, ProceedsReceivedRepository proceedsReceivedRep,
- PaymentRefundAndOtherMoneyRepository paymentRefundAndOtherMoneyRep, HttpClient httpClient)
- {
- _mapper = mapper;
- _config = configuration;
- _daiRep = daiRep;
- _sqlSugar = sqlSugar;
- _setDataTypeRep = setDataTypeRep;
- _teamRateRep = teamRateRep;
- _ForForeignReceivablesRep = ForForeignReceivablesRep;
- _proceedsReceivedRep = proceedsReceivedRep;
- _paymentRefundAndOtherMoneyRep = paymentRefundAndOtherMoneyRep;
- _httpClient = httpClient;
- }
- #region 日付申请
- /// <summary>
- /// 获取日付申请 基础数据源
- /// </summary>
- /// <param name="dto"> 日付申请 分页 dto</param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostPageSearchDailyPaymentPriceTypeData(PortDtoBase dto)
- {
- var result = await _daiRep.GetPagePriceTypeData(dto);
- if (result == null || result.Code != 0)
- {
- return Ok(JsonView(false, result.Msg));
- }
- var data = result.Data;
- return Ok(JsonView(data));
- }
- /// <summary>
- /// 获取日付申请 基础数据源 - 转账表识
- /// </summary>
- /// <param name="dto"> 日付申请 分页 dto</param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GetSearchDailyPaymentPriceTypeAddData(PortDtoBase dto)
- {
- var result = await _daiRep.GetPriceTypeAddData(dto);
- if (result == null || result.Code != 0)
- {
- return Ok(JsonView(false, result.Msg));
- }
- var data = result.Data;
- return Ok(JsonView(data));
- }
- /// <summary>
- /// 日付申请 Page Search
- /// </summary>
- /// <param name="dto"> 日付申请 分页 dto</param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostPageSearchDailyPaymentList(PageDailyFeePaymentDto dto)
- {
- var result = await _daiRep.GetPageSearchAll(dto);
- if (result == null || result.Code != 0)
- {
- return Ok(JsonView(false, result.Msg));
- }
- var data = result.Data;
- if (data == null)
- {
- return Ok(JsonView(false, result.Msg));
- }
- return Ok(JsonView(data));
- }
- /// <summary>
- /// 日付申请 Single Search By Id
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostSearchDailyPaymentInfo(SearchDailyFeePaymentDto dto)
- {
- var result = await _daiRep.GetSearchById(dto);
- if (result == null || result.Code != 0)
- {
- return Ok(JsonView(false, result.Msg));
- }
- return Ok(JsonView(result.Data));
- }
- /// <summary>
- /// 日付申请 添加
- /// </summary>
- /// <param name="dto"> 日付申请 添加 dto</param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostAddDailyPayment(AddDailyFeePaymentDto dto)
- {
- var result = await _daiRep.Add(dto);
- if (result == null || result.Code != 0)
- {
- return Ok(JsonView(false, result.Msg));
- }
- return Ok(JsonView(true));
- }
- /// <summary>
- /// 日付申请 Update
- /// </summary>
- /// <param name="dto"> 日付申请 修改 dto</param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostEditDailyPayment(EditDailyFeePaymentDto dto)
- {
- var result = await _daiRep.Edit(dto);
- if (result == null || result.Code != 0)
- {
- return Ok(JsonView(false, result.Msg));
- }
- return Ok(JsonView(true));
- }
- /// <summary>
- /// 日付申请 Del
- /// </summary>
- /// <param name="dto"> 日付申请 删除 dto</param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostDelDailyPayment(DelDailyFeePaymentDto dto)
- {
- var result = await _daiRep.Del(dto);
- if (result == null || result.Code != 0)
- {
- return Ok(JsonView(false, result.Msg));
- }
- return Ok(JsonView(true));
- }
- /// <summary>
- /// 日付申请 财务审核
- /// </summary>
- /// <param name="dto"> dto </param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostDelDailyPaymentAudit(DP_AuditStatusDto dto)
- {
- var result = await _daiRep.DelDailyPaymentAudit(dto);
- if (result == null || result.Code != 0)
- {
- return Ok(JsonView(false, result.Msg));
- }
- return Ok(JsonView(true));
- }
- /// <summary>
- /// 日付申请 Single Excel Download
- /// </summary>
- /// <param name="dto"> dto </param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostExcelDailyPaymentDownload(SearchDailyFeePaymentDto dto)
- {
- if (dto.PortType == 1 || dto.PortType == 2)
- {
- Fin_DailyFeePaymentInfolView feeData = new Fin_DailyFeePaymentInfolView();
- string feeSql = string.Format(@"Select * From Fin_DailyFeePayment
- Where IsDel=0 And Id = {0} ", dto.Id);
- feeData = await _sqlSugar.SqlQueryable<Fin_DailyFeePaymentInfolView>(feeSql).FirstAsync();
- if (feeData == null)
- {
- return Ok(JsonView(false, "暂无数据!"));
- }
- string feeContentSql = string.Format(@"Select * From Fin_DailyFeePaymentContent
- Where IsDel=0 And DFPId = {0} ", dto.Id);
- feeData.FeeContents = await _sqlSugar.SqlQueryable<Fin_DailyFeePaymentContentInfolView>(feeContentSql).ToListAsync();
- if (feeData != null)
- {
- string userName = string.Empty;
- string userSql = string.Format("Select * From Sys_Users Where Id={0} And Isdel = {1}", feeData.CreateUserId, 0);
- Sys_Users user = await _sqlSugar.SqlQueryable<Sys_Users>(userSql).FirstAsync();
- if (user != null) { userName = user.CnName; }
- var setData = _setDataTypeRep.QueryDto<Sys_SetData, Fin_DailyFeePaymentPagePriceSubTypeView>().ToList();
- //48人员费用 49办公费用 50 销售费用 51 其他费用 55 大运会
- var priceSubTypeData = setData.Where(s => s.STid == 55).ToList();
- Dictionary<string, object> pairs = new Dictionary<string, object>();
- List<DataTable> datas = new List<DataTable>();
- //if (priceSubTypeData.Where(s => s.Id == feeData.PriceTypeId).ToList().Count() > 0)//大运会专属模板
- //{
- // //AsposeHelper.ExpertExcelToModel("日常费用付款申请模板-大运会数据.xls", "DailyPayment", "大运会所有日常费用付款申请.xls",
- // // pairs, datas);
- //}
- //else //日付常规模板
- //{
- pairs.Clear();
- pairs.Add("Opertor", userName);
- pairs.Add("DateTime", feeData.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"));
- pairs.Add("FAuditStatus", feeData.FAuditDesc);
- pairs.Add("MAuditStatus", feeData.MAuditDesc);
- pairs.Add("SumPrice", feeData.SumPrice);
- DataTable data = AsposeHelper.ListToDataTable("DailyFeePayment", feeData.FeeContents);
- datas.Clear();
- datas.Add(data);
- string fileName = string.Format("{0}-日常费用付款申请.xlsx", feeData.Instructions);
- string msg = AsposeHelper.ExpertExcelToModel("日常费用付款申请模板.xlsx", "DailyPayment", fileName, pairs, datas);
- return Ok(JsonView(true, msg));
- //}
- }
- else
- {
- return Ok(JsonView(false, "暂无数据!"));
- }
- }
- return Ok(JsonView(true));
- }
- #endregion
- #region 团组提成
- /// <summary>
- /// 提成 Page Search
- /// </summary>
- /// <param name="dto"> 提成 分页 dto</param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostPageSearchCommissionList(GroupCommissionDto dto)
- {
- var data = await GroupCommission.GetCommissionPageList(dto);
- return Ok(JsonView(data.Data));
- }
- #endregion
- #region 团组汇率
- /// <summary>
- /// 团组汇率 Select数据源(团组列,汇率列)
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GetGroupRateDataSources(TeamRateDto dto)
- {
- try
- {
- Result teamRateData = await _teamRateRep.GetGroupRateDataSource(dto);
- if (teamRateData.Code != 0)
- {
- return Ok(JsonView(false, teamRateData.Msg));
- }
- return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- throw;
- }
- }
- ///// <summary>
- ///// 团组汇率 changge
- ///// </summary>
- ///// <returns></returns>
- //[HttpPost]
- //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- //public async Task<IActionResult> ChangeGroupRateInfo()
- //{
- // try
- // {
- // Result teamRateData = await _teamRateRep.GetGroupRateChangeData();
- // if (teamRateData.Code != 0)
- // {
- // return Ok(JsonView(false, teamRateData.Msg));
- // }
- // return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
- // }
- // catch (Exception ex)
- // {
- // return Ok(JsonView(false, ex.Message));
- // throw;
- // }
- //}
- /// <summary>
- /// 团组汇率 Select汇率详情
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GetGroupRateInfo(TeamRateInfoDto dto)
- {
- try
- {
- Result teamRateData = await _teamRateRep.GetGroupRateInfoByDiid(dto);
- if (teamRateData.Code != 0)
- {
- return Ok(JsonView(false, teamRateData.Msg));
- }
- return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- throw;
- }
- }
- /// <summary>
- /// 团组汇率 添加 or 更新
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostGroupRateUpdate(TeamRateUpdateDto dto)
- {
- try
- {
- Result teamRateData = await _teamRateRep.PostGroupRateUpdate(dto);
- if (teamRateData.Code != 0)
- {
- return Ok(JsonView(false, teamRateData.Msg));
- }
- return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- throw;
- }
- }
- #endregion
- #region 对外收款账单 关联已收款项
- /// <summary>
- /// 对外收款账单 Select数据源(团组名,币种,汇款方式)
- /// 关联已收款项
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GetForeignReceivablesDataSources()
- {
- try
- {
- Result ffrData = await _ForForeignReceivablesRep.GetDataSource();
- if (ffrData.Code != 0)
- {
- return Ok(JsonView(false, ffrData.Msg));
- }
- return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- throw;
- }
- }
- /// <summary>
- /// 对外收款账单
- /// 账单详情
- /// 关联已收款项
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GetGroupReceivablesInfoByDiId(ForForeignReceivablesInfoDto dto)
- {
- try
- {
- Result ffrData = await _ForForeignReceivablesRep.GetGroupReceivablesInfoByDiId(dto);
- if (ffrData.Code != 0)
- {
- return Ok(JsonView(false, ffrData.Msg));
- }
- return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- throw;
- }
- }
- /// <summary>
- /// 对外收款账单
- /// 账单 删除
- /// 关联已收款项
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostGroupReceivablesDel(DelForForeignReceivablesInfoDto dto)
- {
- try
- {
- Result ffrData = await _ForForeignReceivablesRep._Del(dto);
- if (ffrData.Code != 0)
- {
- return Ok(JsonView(false, ffrData.Msg));
- }
- return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- throw;
- }
- }
- /// <summary>
- /// 对外收款账单
- /// 添加 And 更新
- /// 关联已收款项
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostReceivablesOperate(ForeignReceivablesAddAndUpdateDto dto)
- {
- try
- {
- Result ffrData = await _ForForeignReceivablesRep.PostReceivablesOperate(dto);
- if (ffrData.Code != 0)
- {
- return Ok(JsonView(false, ffrData.Msg));
- }
- return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- throw;
- }
- }
- /// <summary>
- /// 已收款项
- /// 账单 删除
- /// 关联已收款项
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostAmountReceivedDel(ProceedsReceivedDelDto dto)
- {
- try
- {
- Result ffrData = await _proceedsReceivedRep._Del(dto);
- if (ffrData.Code != 0)
- {
- return Ok(JsonView(false, ffrData.Msg));
- }
- return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- throw;
- }
- }
- /// <summary>
- /// 已收款项
- /// 添加 And 更新
- /// 关联已收款项
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostAmountReceivedOperate(ProceedsReceivedDto dto)
- {
- try
- {
- Result ffrData = await _proceedsReceivedRep.PostAmountReceivedOperate(dto);
- if (ffrData.Code != 0)
- {
- return Ok(JsonView(false, ffrData.Msg));
- }
- return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- throw;
- }
- }
- /// <summary>
- /// 财务 已收款项
- /// 分配已收款项至 应收项下
- /// 关联已收款项
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostAllocateAmountReceived(AllocateAmountReceivedDto dto)
- {
- try
- {
- Result ffrData = await _proceedsReceivedRep.PostAllocateAmountReceived(dto);
- if (ffrData.Code != 0)
- {
- return Ok(JsonView(false, ffrData.Msg));
- }
- return Ok(JsonView(true));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- throw;
- }
- }
- ///// <summary>
- ///// 财务 收款账单
- ///// 导出Word(北京,四川)
- ///// </summary>
- ///// <param name="dto"></param>
- ///// <returns></returns>
- //[HttpPost]
- //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- //public async Task<IActionResult> PostAccountReceivableWordExport(AccountReceivableWordExportDto dto)
- //{
- // try
- // {
- // //模板处理
- // string typeName = string.Empty;
- // if (dto.TemplateType == 1) //四川
- // {
- // typeName = "四川";
- // }
- // else if (dto.TemplateType == 2) //北京
- // {
- // typeName = "北京";
- // }
- // else return Ok(JsonView(false,"请选择正确的模板类型!"));
- // string wordTempName = string.Format("收款账单({0})模板.doc", typeName);
- // }
- // catch (Exception ex)
- // {
- // return Ok(JsonView(false, ex.Message));
- // }
- //}
- #endregion
- #region 对外收款账单
- /// <summary>
- /// 对外收款账单
- /// 数据源
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostGroupReceivablesDataSource()
- {
- try
- {
- Result ffrData = await _ForForeignReceivablesRep.PostDataSource();
- if (ffrData.Code != 0)
- {
- return Ok(JsonView(false, ffrData.Msg));
- }
- return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- }
- }
- /// <summary>
- /// 对外收款账单
- /// 账单详情
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostGroupReceivablesInfoByDiId(ForForeignReceivablesNewDto dto)
- {
- try
- {
- Result ffrData = await _ForForeignReceivablesRep.PostGroupReceivablesInfoByDiId(dto);
- if (ffrData.Code != 0)
- {
- return Ok(JsonView(false, ffrData.Msg));
- }
- return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- }
- }
- /// <summary>
- /// 对外收款账单
- /// 添加 And 更新
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostReceivablesSave(ForeignReceivablesSaveDto dto)
- {
- try
- {
- Result ffrData = await _ForForeignReceivablesRep.PostReceivablesSave(dto);
- if (ffrData.Code != 0)
- {
- return Ok(JsonView(false, ffrData.Msg));
- }
- return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- throw;
- }
- }
- /// <summary>
- /// 已收账单
- /// 删除
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostReceivablesDel(ForeignReceivablesDelDto dto)
- {
- try
- {
- Result ffrData = await _ForForeignReceivablesRep.PostReceivablesDel(dto);
- if (ffrData.Code != 0)
- {
- return Ok(JsonView(false, ffrData.Msg));
- }
- return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- throw;
- }
- }
- /// <summary>
- /// 已收账单
- /// File Downloasd
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostReceivablesFeilDownload(ForeignReceivablesFeilDownloadDto dto)
- {
- try
- {
- if (dto.DiId < 1)
- {
- return Ok(JsonView(false, "请传入有效DiId参数!"));
- }
- if (dto.FileType < 1 || dto.FileType > 3)
- {
- return Ok(JsonView(false, "请传入有效FileType参数! 1 生成收款单(四川) 2 生成收款单(北京) 3 汇款账单"));
- }
- var _DelegationInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == dto.DiId).First();
- if (_DelegationInfo == null)
- {
- return Ok(JsonView(false, "暂无团组信息!!"));
- }
- if (dto.FileType == 1 || dto.FileType == 2)
- {
- var _ForeignReceivables = _sqlSugar.Queryable<Fin_ForeignReceivables>().Where(it => it.IsDel == 0 && it.Diid == dto.DiId).ToList();
- if (_ForeignReceivables.Count < 1)
- {
- return Ok(JsonView(false, "暂无收款信息!!"));
- }
- string tempName = "";
- if (dto.FileType == 1) tempName = $"收款账单(四川)模板.docx";
- else if (dto.FileType == 2) tempName = $"收款账单(北京)模板.docx";
- string tempPath = AppSettingsHelper.Get("WordBasePath") + $"ForeignReceivables/Temp/{tempName}";
- //载入模板
- Document doc = new Document(tempPath);
- DocumentBuilder builder = new DocumentBuilder(doc);
- #region 替换Word模板书签内容
- //这里可以创建个DataTable循环添加书签的值,这里提示一下就不多做修改了
- //付款方
- if (doc.Range.Bookmarks["To"] != null)
- {
- Bookmark mark = doc.Range.Bookmarks["To"];
- mark.Text = _ForeignReceivables[0].To == null ? "" : _ForeignReceivables[0].To.ToString();
- }
- //付款方电话
- if (doc.Range.Bookmarks["ToTel"] != null)
- {
- Bookmark mark = doc.Range.Bookmarks["ToTel"];
- mark.Text = _ForeignReceivables[0].ToTel == null ? "" : _ForeignReceivables[0].ToTel.ToString();
- }
- //导出时间
- if (doc.Range.Bookmarks["Date"] != null)
- {
- Bookmark mark = doc.Range.Bookmarks["Date"];
- mark.Text = DateTime.Now.ToString("yyyy-MM-dd");
- }
- //注
- if (doc.Range.Bookmarks["Attention"] != null)
- {
- Bookmark mark = doc.Range.Bookmarks["Attention"];
- mark.Text = _ForeignReceivables[0].Attention == null ? "" : _ForeignReceivables[0].Attention.ToString();
- }
- //团队名称
- if (doc.Range.Bookmarks["Team"] != null)
- {
- Bookmark mark = doc.Range.Bookmarks["Team"];
- mark.Text = _DelegationInfo.VisitCountry == null ? "" : _DelegationInfo.VisitCountry.ToString();
- }
- //付款日期
- if (doc.Range.Bookmarks["PayDate"] != null)
- {
- Bookmark mark = doc.Range.Bookmarks["PayDate"];
- mark.Text = _ForeignReceivables[0].PayDate == null ? "" : Convert.ToDateTime(_ForeignReceivables[0].PayDate).ToString("yyyy年MM月dd日");
- }
- decimal sumPrice = 0;
- //各项费用
- if (doc.Range.Bookmarks["PayItemContent"] != null)
- {
- string items = "";
- foreach (var fr in _ForeignReceivables)
- {
- items += fr.PriceName + " " + fr.Currency + " " + fr.Price.ToString("#0.00") + " * " + fr.Count + " " + fr.Unit + " * " + fr.Rate + ".................. RMB " + fr.ItemSumPrice.ToString("#0.00") + "\n";
- sumPrice += fr.ItemSumPrice;
- }
- Bookmark mark = doc.Range.Bookmarks["PayItemContent"];
- mark.Text = items;
- }
- //合计
- if (doc.Range.Bookmarks["Total"] != null)
- {
- Bookmark mark = doc.Range.Bookmarks["Total"];
- mark.Text = sumPrice.ToString("#0.00");
- }
- #endregion
- //文件名
- string strFileName = _DelegationInfo.TeamName + "-收款账单.docx";
- doc.Save(AppSettingsHelper.Get("WordBasePath") + "ForeignReceivables/File/" + strFileName);
- string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/ForeignReceivables/File/" + strFileName;
- return Ok(JsonView(true, "成功", new { Url = url }));
- }
- else if (dto.FileType == 3) //汇款通知
- {
- var _EnterExitCosts = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).First();
- var _DayAndCosts = _sqlSugar.Queryable<Grp_DayAndCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).ToList();
- if (_EnterExitCosts == null)
- {
- return Ok(JsonView(false, "该团组未填写出入境费用;"));
- }
- //数据源
- List<Grp_DayAndCost> dac1 = _DayAndCosts.Where(it => it.Type == 1).ToList(); //住宿费
- List<Grp_DayAndCost> dac2 = _DayAndCosts.Where(it => it.Type == 2).ToList(); //伙食费
- List<Grp_DayAndCost> dac3 = _DayAndCosts.Where(it => it.Type == 3).ToList(); //公杂费
- List<Grp_DayAndCost> dac4 = _DayAndCosts.Where(it => it.Type == 4).ToList(); //培训费
- var DeleClientList = _sqlSugar.Queryable<Grp_TourClientList>()
- .LeftJoin<Crm_DeleClient>((tcl, dc) => tcl.ClientId == dc.Id && dc.IsDel == 0)
- .LeftJoin<Crm_CustomerCompany>((tcl, dc, cc) => dc.CrmCompanyId == cc.Id && dc.IsDel == 0)
- .Where((tcl, dc, cc) => tcl.IsDel == 0 && tcl.DiId == dto.DiId)
- .Select((tcl, dc, cc) => new
- {
- Name = dc.LastName + dc.FirstName,
- Sex = dc.Sex,
- Birthday = dc.BirthDay,
- Company = cc.CompanyFullName,
- Job = dc.Job,
- AirType = tcl.ShippingSpaceTypeId
- })
- .ToList();
- if (DeleClientList.Count < 1)
- {
- return Ok(JsonView(false, "暂无团组成员,请先填写团组成员!!!"));
- }
- var _ClientNames = DeleClientList.Select(x => x.Name).ToList();
- var _GroupClient = DeleClientList.GroupBy(x => x.Company).ToList();
- Dictionary<string, string> bookmarkArr = null;
- string tempPath = AppSettingsHelper.Get("WordBasePath") + $"ForeignReceivables/Temp/汇款通知.docx";
- //载入模板
- Document doc = new Document(tempPath);
- DocumentBuilder builder = null;
- List<string> filesToZip = new List<string>();
- foreach (var ClientItem in _GroupClient) //遍历单位
- {
- doc = new Document(tempPath);
- builder = new DocumentBuilder(doc);
- Paragraph paragraph = new Paragraph(doc);
- bookmarkArr = new Dictionary<string, string>();
- bookmarkArr.Add("titleClientUnit", ClientItem.Key); //title单位
- bookmarkArr.Add("ClientUnit", ClientItem.Key); //单位
- bookmarkArr.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));//出发日期
- bookmarkArr.Add("name", string.Join(",", ClientItem.Select(x => x.Name).ToArray()).TrimEnd(','));//全部人员信息
- bookmarkArr.Add("VisitCountry", _DelegationInfo.VisitCountry);//出访国家
- bookmarkArr.Add("dayTime", DateTime.Now.ToString("yyyy年MM月dd日"));//今天日期
- var ClientItemList = ClientItem.ToList();
- string UsersTop = string.Empty;//word中人员以及金额
- decimal WordAllPrice = 0.00M;
- //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(),
- // 6, 3 + dac1.Where(x=>!string.IsNullOrWhiteSpace(x.Place)).Select(x=>(Convert.ToDecimal(x.SubTotal) / Convert.ToDecimal(x.Cost)).ToString().Length).Max() };
- //遍历人员
- for (int i = 0; i < ClientItemList.Count(); i++)
- {
- Dictionary<string, string> TeableBookmarkArr = new Dictionary<string, string>();
- var client = ClientItemList[i]; //每个人员
- var firstName = ClientItemList[i].Name;
- //计算费用总和
- decimal airPrice = client.AirType == 460 ? _EnterExitCosts.AirJJ : _EnterExitCosts.AirGW;
- decimal AllPrice = airPrice + _EnterExitCosts.CityTranffic + dac1.Sum(x => x.SubTotal) + dac2.Sum(x => x.SubTotal) +
- dac3.Sum(x => x.SubTotal) + dac4.Sum(x => x.SubTotal) + _EnterExitCosts.Visa + _EnterExitCosts.Safe +
- _EnterExitCosts.Service;
- WordAllPrice += AllPrice;
- UsersTop += firstName + "出访费用为¥" + AllPrice.ToString("#0.00") + "元、";
- TeableBookmarkArr.Add("jp", (client.AirType == 460 ? _EnterExitCosts.AirJJ : _EnterExitCosts.AirGW).ToString("#0.00") + " 元"); //机票金额
- TeableBookmarkArr.Add("cs", _EnterExitCosts.CityTranffic.ToString("#0.00") + " 元"); //城市交通费用
- TeableBookmarkArr.Add("zs", dac1.Sum(x => Convert.ToDecimal(x.SubTotal)).ToString("#0.00") + " 元"); //住宿费
- string zsinfo = string.Empty;
- string hsinfo = string.Empty;
- string gzinfo = string.Empty;
- List<string> placeArr = new List<string>();
- Aspose.Words.Tables.Table FirstTable = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 0, true);
- Aspose.Words.Tables.Table ChildTable = (Aspose.Words.Tables.Table)FirstTable.GetChild(NodeType.Table, 0, true);
- Aspose.Words.Tables.Table ChildTable1 = (Aspose.Words.Tables.Table)FirstTable.GetChild(NodeType.Table, 1, true);
- Aspose.Words.Tables.Table ChildTable2 = (Aspose.Words.Tables.Table)FirstTable.GetChild(NodeType.Table, 2, true);
- int rowIndex = 0;
- foreach (var item in dac1)
- {
- if (string.IsNullOrWhiteSpace(item.Place))
- {
- continue;
- }
- if (placeArr.Contains(item.Place))
- {
- continue;
- }
- else
- {
- placeArr.Add(item.Place);
- }
- if (!string.IsNullOrWhiteSpace(item.Place))
- {
- if (rowIndex > ChildTable.Rows.Count - 1)
- {
- var chitableRow = ChildTable.LastRow.Clone(true);
- ChildTable.AppendChild(chitableRow);
- }
- int days = dac1.FindAll(x => x.Place == item.Place).Count();
- SetCells(ChildTable, doc, rowIndex, 0, item.Place);
- SetCells(ChildTable, doc, rowIndex, 1, days + "晚");
- SetCells(ChildTable, doc, rowIndex, 2, item.Cost + item.Currency + "/晚");
- SetCells(ChildTable, doc, rowIndex, 3, " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00"));
- SetCells(ChildTable, doc, rowIndex, 4, "CNY" + item.SubTotal * days + "\r\n");
- rowIndex++;
- zsinfo += item.Place + " " + days + "晚 " + item.Cost + item.Currency + "/晚" + " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00") + " CNY" + item.SubTotal * days + "\r\n";
- }
- }
- placeArr.Clear();
- rowIndex = 0;
- foreach (var item in dac2)
- {
- if (string.IsNullOrWhiteSpace(item.Place))
- {
- continue;
- }
- if (placeArr.Contains(item.Place))
- {
- continue;
- }
- else
- {
- placeArr.Add(item.Place);
- }
- if (!string.IsNullOrWhiteSpace(item.Place))
- {
- if (rowIndex > ChildTable1.Rows.Count - 1)
- {
- var chitableRow = ChildTable1.LastRow.Clone(true);
- ChildTable1.AppendChild(chitableRow);
- }
- int days = dac2.FindAll(x => x.Place == item.Place).Count();
- SetCells(ChildTable1, doc, rowIndex, 0, item.Place);
- SetCells(ChildTable1, doc, rowIndex, 1, days + "天");
- SetCells(ChildTable1, doc, rowIndex, 2, item.Cost + item.Currency + "/天");
- SetCells(ChildTable1, doc, rowIndex, 3, " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00"));
- SetCells(ChildTable1, doc, rowIndex, 4, "CNY" + item.SubTotal * days);
- rowIndex++;
- hsinfo += item.Place + " " + days + "天 " + item.Cost + item.Currency + "/天" + " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00") + " CNY" + item.SubTotal * days + "\r\n";
- }
- }
- placeArr.Clear();
- rowIndex = 0;
- foreach (var item in dac3)
- {
- if (string.IsNullOrWhiteSpace(item.Place))
- {
- continue;
- }
- if (placeArr.Contains(item.Place))
- {
- continue;
- }
- else
- {
- placeArr.Add(item.Place);
- }
- if (!string.IsNullOrWhiteSpace(item.Place))
- {
- if (rowIndex > ChildTable2.Rows.Count - 1)
- {
- var chitableRow = ChildTable2.LastRow.Clone(true);
- ChildTable2.AppendChild(chitableRow);
- }
- int days = dac3.FindAll(x => x.Place == item.Place).Count();
- SetCells(ChildTable2, doc, rowIndex, 0, item.Place);
- SetCells(ChildTable2, doc, rowIndex, 1, days + "天");
- SetCells(ChildTable2, doc, rowIndex, 2, item.Cost + item.Currency + "/天");
- SetCells(ChildTable2, doc, rowIndex, 3, " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00"));
- SetCells(ChildTable2, doc, rowIndex, 4, "CNY" + item.SubTotal * days + "\r\n");
- rowIndex++;
- gzinfo += item.Place + " " + days + "天 " + item.Cost + item.Currency + "/天" + " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00") + " CNY" + item.SubTotal * days + "\r\n";
- }
- }
- placeArr.Clear();
- TeableBookmarkArr.Add("zsinfo", zsinfo); //住宿费详情
- TeableBookmarkArr.Add("hs", dac2.Sum(x => Convert.ToDecimal(x.SubTotal)).ToString("#0.00") + " 元"); //伙食费
- TeableBookmarkArr.Add("hsinfo", hsinfo); //伙食费详情
- TeableBookmarkArr.Add("gz", dac3.Sum(x => Convert.ToDecimal(x.SubTotal)).ToString("#0.00") + " 元"); //公杂费
- TeableBookmarkArr.Add("gzinfo", gzinfo); //公杂费详情
- TeableBookmarkArr.Add("qt", (_EnterExitCosts.Visa + _EnterExitCosts.Safe).ToString("#0.00") + " 元");//其他费用
- TeableBookmarkArr.Add("qtinfo", $"(签证费{_EnterExitCosts.Visa.ToString("#0.00")}元、保险{_EnterExitCosts.Safe.ToString("#0.00")}元等费用)");//其他费用第二列
- TeableBookmarkArr.Add("fw", _EnterExitCosts.Service.ToString("#0.00") + "元/人");//服务费
- TeableBookmarkArr.Add("AllPrice", AllPrice.ToString("#0.00") + "元/人");//表格合计费用
- string airStr = client.AirType == 460 ? "经济舱" : client.AirType == 458 ? "公务舱" : "";
- TeableBookmarkArr.Add("title", $"费用清单-{airStr}({firstName})");
- foreach (var book in TeableBookmarkArr.Keys)
- {
- if (doc.Range.Bookmarks[book] != null)
- {
- Bookmark mark = doc.Range.Bookmarks[book];
- mark.Text = TeableBookmarkArr[book];
- }
- }
- if (i != ClientItemList.Count - 1)
- {
- builder.PageSetup.Orientation = Aspose.Words.Orientation.Portrait;
- Aspose.Words.Tables.Table table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 0, true);
- table.ParentNode.InsertAfter(paragraph, table);
- var CloneTable = (Aspose.Words.Tables.Table)table.Clone(true);
- table.ParentNode.InsertAfter(CloneTable, paragraph);
- }
- TeableBookmarkArr.Clear();
- }
- bookmarkArr.Add("VisitPrice", WordAllPrice.ToString());//出访费用总额
- bookmarkArr.Add("CnAllPrice", WordAllPrice.ConvertCNYUpper());//出访费用总额中文
- bookmarkArr.Add("namesPrice", UsersTop.TrimEnd('、'));//各人员出访费用 付辰同志出访费用为¥73,604.8元
- foreach (var book in bookmarkArr.Keys)
- {
- if (doc.Range.Bookmarks[book] != null)
- {
- Bookmark mark = doc.Range.Bookmarks[book];
- mark.Text = bookmarkArr[book];
- }
- }
- //MemoryStream outSteam = new MemoryStream();
- string filsPath = AppSettingsHelper.Get("WordBasePath") + $"ForeignReceivables/File/{ClientItem.Key}.docx";
- doc.Save(filsPath);
- filesToZip.Add(filsPath);
- //streams.Add(ClientItem.Key + ".docx", outSteam.ToArray());
- }
- //文件名
- string zipFileName = _DelegationInfo.TeamName + "-收款账单.zip";
- string zipPath = $"ForeignReceivables/File/{_DelegationInfo.TeamName}-收款账单{DateTime.Now.ToString("yyyyMMddHHmmss")}.zip";
- try
- {
- using (var zip = ZipFile.Open(AppSettingsHelper.Get("WordBasePath") + zipPath, ZipArchiveMode.Create))
- {
- foreach (var file in filesToZip)
- {
- zip.CreateEntryFromFile(file, Path.GetFileName(file));
- }
- }
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- }
- string url = AppSettingsHelper.Get("WordBaseUrl") + $"Office/Word/{zipPath}";
- return Ok(JsonView(true, "成功", new { Url = url }));
- }
- return Ok(JsonView(false, "操作失败!"));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- }
- }
- private void SetCells(Aspose.Words.Tables.Table table, Document doc, int rows, int cells, string val)
- {
- //获取table中的某个单元格,从0开始
- Aspose.Words.Tables.Cell lshCell = table.Rows[rows].Cells[cells];
- //将单元格中的第一个段落移除
- lshCell.FirstParagraph.Remove();
- //新建一个段落
- Paragraph p = new Paragraph(doc);
- var r = new Run(doc, val);
- r.Font.Size = 8;
- //把设置的值赋给之前新建的段落
- p.AppendChild(r);
- //将此段落加到单元格内
- lshCell.AppendChild(p);
- }
- #endregion
- #region 已收款项
- /// <summary>
- /// 已收款项
- /// 查询
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostAmountReceived(AmountReceivedDto dto)
- {
- try
- {
- if (dto == null)
- {
- return Ok(JsonView(false, "参数不能为空!"));
- }
- Result ffrData = await _proceedsReceivedRep.PostAmountReceived(dto.DiId);
- dynamic data = null;
- if (dto.PortType == 1)
- {
- if (ffrData.Code != 0)
- {
- return Ok(JsonView(false, ffrData.Msg));
- }
- data = ffrData.Data;
- }
- else if (dto.PortType == 2)
- {
- if (ffrData.Code != 0)
- {
- return Ok(JsonView(false, ffrData.Msg));
- }
- data = ffrData.Data;
- }
- else if (dto.PortType == 2)
- {
- if (ffrData.Code != 0)
- {
- return Ok(JsonView(false, ffrData.Msg));
- }
- data = ffrData.Data;
- }
- else
- {
- return Ok(JsonView(false, "请选择正确的端口号!"));
- }
- return Ok(JsonView(true, "操作成功!", data));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- }
- }
- /// <summary>
- /// 已收款项
- /// Add Or Edit
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostAmountReceivedAddOrEdit(AmountReceivedAddOrEditDto dto)
- {
- try
- {
- if (dto == null)
- {
- return Ok(JsonView(false, "参数不能为空!"));
- }
- Result ffrData = await _proceedsReceivedRep.PostAmountReceivedAddOrEditDto(dto);
- if (dto.PortType == 1)
- {
- if (ffrData.Code != 0)
- {
- return Ok(JsonView(false, ffrData.Msg));
- }
- }
- else if (dto.PortType == 2)
- {
- if (ffrData.Code != 0)
- {
- return Ok(JsonView(false, ffrData.Msg));
- }
- }
- else if (dto.PortType == 2)
- {
- if (ffrData.Code != 0)
- {
- return Ok(JsonView(false, ffrData.Msg));
- }
- }
- else
- {
- return Ok(JsonView(false, "请选择正确的端口号!"));
- }
- return Ok(JsonView(true, "操作成功!"));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- }
- }
- /// <summary>
- /// 已收款项
- /// Del
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostAmountReceived_Del(AmountReceivedDelDto dto)
- {
- try
- {
- if (dto == null)
- {
- return Ok(JsonView(false, "参数不能为空!"));
- }
- Result ffrData = await _proceedsReceivedRep.PostAmountReceivedDel(dto);
- if (ffrData.Code != 0)
- {
- return Ok(JsonView(false, ffrData.Msg));
- }
- return Ok(JsonView(true, "操作成功!"));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- }
- }
- #endregion
- #region 收款退还与其他款项
- /// <summary>
- /// 收款退还与其他款项
- /// 查询 根据团组Id
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostPaymentRefundAndOtherMoneyItemByDiId(PaymentRefundAndOtherMoneyItemByDiIdDto dto)
- {
- try
- {
- if (dto == null) return Ok(JsonView(false, "参数不能为空!"));
- if (dto.PageId <= 0) return Ok(JsonView(false, "请传入正确的的页面Id!"));
- if (dto.UserId <= 0) return Ok(JsonView(false, "请传入正确的的员工Id!"));
- #region 页面功能权限处理
- PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
- pageFunAuth = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
- if (pageFunAuth.CheckAuth == 0)
- {
- return Ok(JsonView(false, "您没有当前页面查询权限!"));
- }
- #endregion
- Result _result = await _paymentRefundAndOtherMoneyRep._ItemByDiId(dto.DiId);
- if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //1 Web 2 Android 3 Ios
- {
- if (_result.Code != 0)
- {
- return Ok(JsonView(false, _result.Msg));
- }
- var data = new
- {
- PageFuncAuth = pageFunAuth,
- Data = _result.Data
- };
- return Ok(JsonView(true, "操作成功!", data));
- }
- else
- {
- return Ok(JsonView(false, "请输入正确的端口号! 1 Web 2 Android 3 Ios;"));
- }
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- }
- }
- /// <summary>
- /// 收款退还与其他款项
- /// 删除
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostPaymentRefundAndOtherMoneyDel(PaymentRefundAndOtherMoneyDelDto dto)
- {
- try
- {
- if (dto == null) return Ok(JsonView(false, "参数不能为空!"));
- if (dto.PageId <= 0) return Ok(JsonView(false, "请传入正确的的页面Id!"));
- if (dto.UserId <= 0) return Ok(JsonView(false, "请传入正确的的员工Id!"));
- PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
- #region 页面功能权限处理
- pageFunAuth = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
- #endregion
- if (pageFunAuth.DeleteAuth == 0)
- {
- return Ok(JsonView(false, "您没有当前页面删除权限!"));
- }
- Result _result = await _paymentRefundAndOtherMoneyRep._Del(dto);
- if (_result.Code != 0)
- {
- return Ok(JsonView(false, _result.Msg));
- }
- return Ok(JsonView(true, "操作成功!"));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- }
- }
- /// <summary>
- /// 收款退还与其他款项
- /// Info Data Source
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostPaymentRefundAndOtherMoneyInfoDataSource(PortDtoBase dto)
- {
- try
- {
- Result _result = await _paymentRefundAndOtherMoneyRep._InfoDataSource(dto);
- if (_result.Code != 0)
- {
- return Ok(JsonView(false, _result.Msg));
- }
- return Ok(JsonView(true, "查询成功!", _result.Data));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- }
- }
- /// <summary>
- /// 收款退还与其他款项
- /// Info
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostPaymentRefundAndOtherMoneyInfo(PaymentRefundAndOtherMoneyInfoDto dto)
- {
- try
- {
- if (dto == null)
- {
- return Ok(JsonView(false, "参数不能为空!"));
- }
- Result _result = await _paymentRefundAndOtherMoneyRep._Info(dto);
- if (_result.Code != 0)
- {
- return Ok(JsonView(false, _result.Msg));
- }
- return Ok(JsonView(true, "查询成功!", _result.Data));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- }
- }
- /// <summary>
- /// 收款退还与其他款项
- /// 操作(Add Or Edit)
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostPaymentRefundAndOtherMoneyAddOrEdit(PaymentRefundAndOtherMoneyAddOrEditDto dto)
- {
- try
- {
- if (dto == null) return Ok(JsonView(false, "参数不能为空!"));
- if (dto.PageId <= 0) return Ok(JsonView(false, "请传入正确的的页面Id!"));
- if (dto.UserId <= 0) return Ok(JsonView(false, "请传入正确的的员工Id!"));
- #region 页面功能权限处理
- PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
- pageFunAuth = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
- #endregion
- if (dto.Status == 1) //add
- {
- if (pageFunAuth.AddAuth == 0)
- {
- return Ok(JsonView(false, "您没有当前页面添加权限!"));
- }
- }
- else if (dto.Status == 2) //edit
- {
- if (pageFunAuth.EditAuth == 0)
- {
- return Ok(JsonView(false, "您没有当前页面编辑权限!"));
- }
- }
- else
- {
- return Ok(JsonView(false, "请输入正确的操作状态! 1 添加 2 修改!"));
- }
- Result _result = await _paymentRefundAndOtherMoneyRep._AddOrEdit(dto);
- if (_result.Code != 0)
- {
- return Ok(JsonView(false, _result.Msg));
- }
- return Ok(JsonView(true, "操作成功!"));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- }
- }
- #endregion
- #region 应收报表
- /// <summary>
- /// 应收报表
- /// 查询 根据日期范围
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostSyntheticalReceivableByDateRange(PostSyntheticalReceivableByDateRangeDto dto)
- {
- string sqlWhere = " Where di.IsDel=0 ";
- #region 验证
- if (string.IsNullOrEmpty(dto.beginDt) && string.IsNullOrEmpty(dto.endDt))
- {
- return Ok(JsonView(false, "日期参数至少填写一个!"));
- }
- if (!string.IsNullOrEmpty(dto.beginDt))
- {
- if (Regex.Match(dto.beginDt, @"^\d{4}-\d{2}-\d{2}$").Value.Length < 1)
- {
- return Ok(JsonView(false, "日期参数格式错误,应为yyyy-MM-dd!"));
- }
- else
- {
- sqlWhere += string.Format(@" And di.VisitDate >= '{0} 00:00:00' ", dto.beginDt);
- }
- }
- if (!string.IsNullOrEmpty(dto.endDt))
- {
- if (Regex.Match(dto.endDt, @"^\d{4}-\d{2}-\d{2}$").Value.Length < 1)
- {
- return Ok(JsonView(false, "日期参数格式错误,应为yyyy-MM-dd!"));
- }
- else
- {
- sqlWhere += string.Format(@" And di.VisitDate <= '{0} 23:59:59' ", dto.endDt);
- }
- }
- #endregion
- 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);
- List<PostSyntheticalReceivableByDateRangeView> list_rst = _sqlSugar.SqlQueryable<PostSyntheticalReceivableByDateRangeView>(sql).ToList();
- decimal sumAll_fr = 0M;
- decimal sumAll_pr = 0M;
- decimal sumAll_balance = 0M;
- if (list_rst.Count > 0)
- {
- int rowNumber = 1;
- foreach (var item_rst in list_rst)
- {
- DateTime dtTemp;
- bool b = DateTime.TryParse(item_rst.visitDate, out dtTemp);
- if (b)
- {
- item_rst.visitDate = dtTemp.ToString("yyyy-MM-dd");
- }
- item_rst.No = rowNumber;
- rowNumber++;
- int diId = item_rst.diid;
- decimal sum_fr = 0M;
- decimal sum_pr = 0M;
- string str_client = string.Empty;
- decimal sum_other = 0M; //收款退还
- decimal sum_extra = 0M; //超支费用
- decimal balance = 0M;
- string str_schedule = string.Empty;
- //1. 缺超支费用!!!!!!!!!!!!!!!!!!!!
- string sql_fr = string.Format(@" Select * From Fin_ForeignReceivables Where IsDel=0 And Diid={0} ", diId);
- List<Fin_ForeignReceivables> list_fr = _sqlSugar.SqlQueryable<Fin_ForeignReceivables>(sql_fr).ToList();
- sum_fr = list_fr.Sum(s => s.ItemSumPrice);
- //2.
- string sql_pr = string.Format(@" Select * From Fin_ProceedsReceived Where IsDel=0 And Diid={0} ", diId);
- List<Fin_ProceedsReceived> list_pr = _sqlSugar.SqlQueryable<Fin_ProceedsReceived>(sql_pr).ToList();
- foreach (var item_pr in list_pr)
- {
- sum_pr += item_pr.Price;
- str_client += string.Format(@"{0};", item_pr.Client);
- str_schedule += string.Format(@"{0};", item_pr.Remark);
- }
- if (str_schedule.Length > 0)
- {
- str_schedule = str_schedule.TrimEnd(';');
- }
- if (str_client.Length > 0)
- {
- str_client = str_client.TrimEnd(';');
- }
- //3.
- string sql_other = string.Format(@" Select * From Fin_OtherPrice where diid = {0} and isdel = 0 and RefundType = 1 and PayType=1 ", diId);
- List<Fin_OtherPrice> list_other = _sqlSugar.SqlQueryable<Fin_OtherPrice>(sql_other).ToList();
- sum_other = list_other.Sum(s => s.Price);
- //4.
- string sql_extra = string.Format(@" Select c.* From Fin_GroupExtraCost f
- Inner join Grp_CreditCardPayment c On f.Id = c.CId
- Where c.CTable = 1015 And c.IsPay = 1 And f.IsDel = 0 And c.IsDel = 0 And f.DiId = {0} ", diId);
- List<Grp_CreditCardPayment> list_extra = _sqlSugar.SqlQueryable<Grp_CreditCardPayment>(sql_extra).ToList();
- sum_extra = list_extra.Sum(s => s.RMBPrice);
- item_rst.frPrice = (sum_fr + sum_extra).ToString("#0.00");
- item_rst.prPrice = (sum_pr - sum_other).ToString("#0.00");
- item_rst.balPrice = ((sum_fr + sum_extra) - (sum_pr - sum_other)).ToString("#0.00");
- item_rst.prClient = str_client;
- item_rst.schedule = str_schedule;
- string tempVisitDate = Convert.ToDateTime(item_rst.visitDate).ToString("yyyy-MM-dd");
- sumAll_fr += (sum_fr + sum_extra);
- sumAll_pr += (sum_pr - sum_other);
- sumAll_balance += ((sum_fr + sum_extra) - (sum_pr - sum_other));
- }
- PostSyntheticalReceivableByDateRangeResultView result = new PostSyntheticalReceivableByDateRangeResultView();
- result.total_fr = sumAll_fr.ToString("#0.00");
- result.total_pr = sumAll_pr.ToString("#0.00");
- result.total_balance = sumAll_balance.ToString("#0.00");
- result.dataList = new List<PostSyntheticalReceivableByDateRangeView>(list_rst);
- if (dto.requestType == 1)
- {
- return Ok(JsonView(true, "请求成功", result, list_rst.Count));
- }
- else
- {
- //----------------------------
- List<Excel_SyntheticalReceivableByDateRange> list_Ex = new List<Excel_SyntheticalReceivableByDateRange>();
- WorkbookDesigner designer = new WorkbookDesigner();
- designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/应收款项模板 - 副本.xls");
- int excNo = 1;
- foreach (var item in list_rst)
- {
- Excel_SyntheticalReceivableByDateRange exc = new Excel_SyntheticalReceivableByDateRange();
- exc.No = excNo.ToString();
- excNo++;
- exc.TeamName = item.teamName;
- exc.ClientUnit = item.clientUnit;
- exc.VisitDate = item.visitDate;
- exc.Accounts = item.frPrice;
- exc.Received = item.prPrice;
- exc.Balance = item.balPrice;
- exc.Collection = item.schedule;
- DateTime time = Convert.ToDateTime(item.visitDate);
- TimeSpan ts = DateTime.Now - time;
- float SY = float.Parse(item.balPrice);
- if (ts.Days >= 365 && SY > 0)
- {
- exc.Sign = "需收款";
- }
- else
- {
- exc.Sign = "";
- }
- list_Ex.Add(exc);
- }
- var dt = CommonFun.GetDataTableFromIList(list_Ex);
- dt.TableName = "Excel_SyntheticalReceivableByDateRange";
- if (dt != null)
- {
- designer.SetDataSource("SumPrice", "应收合计:" + result.total_fr + "RMB 已收合计:" + result.total_pr + "RMB 余款合计:" + result.total_balance + "RMB");
- //数据源
- designer.SetDataSource(dt);
- //根据数据源处理生成报表内容
- designer.Process();
- string fileName = ("Receivable/应收款项(" + dto.beginDt + "~" + dto.endDt + ").xlsx");
- designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
- string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
- return Ok(JsonView(true, "成功", new { url = rst }));
- }
- }
- }
- return Ok(JsonView(true, "获取成功", "", list_rst.Count));
- }
- #endregion
- #region 付款申请
- /// <summary>
- /// 付款申请
- /// 基础数据
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostPayRequestInit()
- {
- try
- {
- var conpanyDatas = _sqlSugar.Queryable<Sys_Company>()
- .Where(it => it.IsDel == 0)
- .Select(it => new
- {
- Id = it.Id,
- ConpamyName = it.CompanyName
- }).ToList();
- return Ok(JsonView(true, "操作成功!", new { ConpanyData = conpanyDatas }));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- }
- }
- /// <summary>
- /// 付款申请 (PageId=51)
- /// 查询 根据日期范围
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostPayRequest_Center(PostPayRequestByDateRangeDto dto)
- {
- #region 验证
- DateTime beginDt, endDt;
- string format = "yyyy-MM-dd";
- if (!DateTime.TryParseExact(dto.beginDt, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out beginDt))
- {
- return Ok(JsonView(false, "开始日期格式不正确!正确格式:yyyy-MM-dd"));
- }
- if (!DateTime.TryParseExact(dto.endDt, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out endDt))
- {
- return Ok(JsonView(false, "结束日期格式不正确!正确格式:yyyy-MM-dd"));
- }
- #region 页面操作权限验证
- PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
- pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
- if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
- #endregion
- #endregion
- try
- {
- PaymentRequestCheckedView checkedView = new PaymentRequestCheckedView();
- var checkedStr = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("paymentRequestCheckedData");
- if (checkedStr != null)
- {
- checkedView = JsonConvert.DeserializeObject<PaymentRequestCheckedView>(checkedStr.ToString());
- }
- tree_Fin_DailyFeePaymentResult dailyResult = PayRequest_DailyByDateRange(dto.Status, checkedView.DailyPaymentIds, dto.beginDt, dto.endDt);
- tree_Group_DailyFeePaymentResult groupResult = PayRequest_GroupPaymentByDateRange(dto.Status, checkedView.GroupIds, dto.beginDt, dto.endDt);
- return Ok(JsonView(true, "获取成功", new { daily = dailyResult, group = groupResult }));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- }
- }
- /// <summary>
- /// 根据团组类型类型处理团组费用所属公司
- /// </summary>
- /// <param name="teamId"></param>
- /// <returns></returns>
- private CompanyInfo ExpenseCompanyByTeamId(int teamId)
- {
- CompanyInfo _companyInfo = new CompanyInfo();
- List<int> _SiChuan = new List<int>() {
- 38 , // 政府团
- 39 , // 企业团
- 40 , // 散客团
- 102, // 未知
- 248, // 非团组
- 691, // 四川-会务活动
- 762, // 四川-赛事项目收入
- };
- List<int> _ChengDu = new List<int>() {
- 302, // 成都-会务活动
- 1047, // 成都-赛事项目收入
- };
- if (_SiChuan.Contains(teamId))
- {
- _companyInfo.Id = 2;
- _companyInfo.ConpanyName = "四川泛美交流有限公司";
- }
- if (_ChengDu.Contains(teamId))
- {
- _companyInfo.Id = 1;
- _companyInfo.ConpanyName = "成都泛美商务有限公司";
- }
- return _companyInfo;
- }
- /// <summary>
- /// 付款申请(团组费用申请相关)
- /// 查询 根据日期范围
- /// </summary>
- /// <param name="_groupIds"></param>
- /// <param name="beginDt"></param>
- /// <param name="endDt"></param>
- /// <returns></returns>
- private tree_Group_DailyFeePaymentResult PayRequest_GroupPaymentByDateRange(int status, List<int> _groupIds, string beginDt, string endDt)
- {
- tree_Group_DailyFeePaymentResult _DailyFeePaymentResult = new tree_Group_DailyFeePaymentResult();
- List<tree_Group_DailyFeePaymentPageListView> dataList = new List<tree_Group_DailyFeePaymentPageListView>();
- #region sql条件处理
- string sqlWhere = string.Format(@" And (AuditGMDate Between '{0} 00:00:00' And '{1} 23:59:59') ", beginDt, endDt);
- if (status == 2)
- {
- if (_groupIds.Count < 1)
- {
- _DailyFeePaymentResult.dataList = new List<tree_Group_DailyFeePaymentPageListView>();
- return _DailyFeePaymentResult;
- }
- sqlWhere += string.Format(@" And Id In ({0})", string.Join(",", _groupIds));
- }
- string sql_1 = string.Format(@"Select * From Grp_CreditCardPayment Where IsDel = 0 And IsPay = 0 And IsAuditGM = 1 {0}", sqlWhere);
- #endregion
- var _paymentDatas = _sqlSugar.SqlQueryable<Grp_CreditCardPayment>(sql_1).ToList();//付款信息
- _DailyFeePaymentResult.gz = _paymentDatas.Where(it => it.OrbitalPrivateTransfer == 0).Sum(it => ((it.PayMoney * it.DayRate) / 100) * it.PayPercentage); //公转
- _DailyFeePaymentResult.sz = _paymentDatas.Where(it => it.OrbitalPrivateTransfer == 1).Sum(it => ((it.PayMoney * it.DayRate) / 100) * it.PayPercentage); ; //私转
- List<int> groupIds = _paymentDatas.Select(it => it.DIId).Distinct().ToList();
- var _groupDatas = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && groupIds.Contains(it.Id)).ToList();
- //_groupDatas = (List<Grp_DelegationInfo>)_groupDatas.GroupBy(it => it.TeamDid);
- #region 相关基础数据源
- var userDatas = _sqlSugar.Queryable<Sys_Users>().ToList();
- var setDatas = _sqlSugar.Queryable<Sys_SetData>().ToList();
- var hotelDatas = _sqlSugar.Queryable<Grp_HotelReservations>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
- var opDatas = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
- var visaDatas = _sqlSugar.Queryable<Grp_VisaInfo>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DIId)).ToList();
- var ioaDatas = _sqlSugar.Queryable<Grp_InvitationOfficialActivities>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
- var insureDatas = _sqlSugar.Queryable<Grp_Customers>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
- var airDatas = _sqlSugar.Queryable<Grp_AirTicketReservations>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DIId)).ToList();
- var otherMoneyDatas = _sqlSugar.Queryable<Fin_OtherPrice>().Where(it => it.IsDel == 0 && groupIds.Contains(it.Diid)).ToList();
- var refundPaymentDatas = _sqlSugar.Queryable<Fin_PaymentRefundAndOtherMoney>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
- var ExtraCostDatas = _sqlSugar.Queryable<Fin_GroupExtraCost>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
- #endregion
- //Expense company
- foreach (var groupInfo in _groupDatas)
- {
- List<Group_DailyFeePaymentContentInfolView> childList = new List<Group_DailyFeePaymentContentInfolView>();
- var groupPaymentDatas = _paymentDatas.Where(it => groupInfo.Id == it.DIId).ToList();
- int rouNumber = 1;
- foreach (var payInfo in groupPaymentDatas)
- {
- string priName = "-";
- string orbitalPrivateTransfer = payInfo.OrbitalPrivateTransfer == 0 ? "公转" : payInfo.OrbitalPrivateTransfer == 1 ? "私转" : "-";
- switch (payInfo.CTable)
- {
- case 76: //76 酒店预订
- priName = hotelDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.HotelName ?? "";
- break;
- case 79: //79 车/导游地接
- var opData = opDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id);
- if (opData != null)
- {
- if (payInfo.OrbitalPrivateTransfer == 0) //公转
- {
- priName = $"【{orbitalPrivateTransfer}】【导游: {opData.ServiceGuide} 】{opData.Area}";
- }
- else if (payInfo.OrbitalPrivateTransfer == 1) //私转
- {
- priName = $"【{orbitalPrivateTransfer}】【导游:{opData.ServiceGuide}】{opData.Area}";
- }
- }
- break;
- case 80: // 80 签证
- priName = visaDatas.Find(it => payInfo.DIId == it.DIId && payInfo.CId == it.Id)?.VisaClient ?? "-";
- break;
- case 81: // 81 邀请/公务活动
- priName = ioaDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.Inviter ?? "-";
- break;
- case 82: // 82 团组客户保险
- priName = insureDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.ClientName ?? "-";
- break;
- case 85: // 85 机票预订
- string flightsCode = airDatas.Find(it => payInfo.DIId == it.DIId && payInfo.CId == it.Id)?.FlightsCode ?? "-";
- string airPayType = setDatas.Find(it => it.Id == payInfo.PayDId)?.Name ?? "-";
- priName = $"{flightsCode}【{airPayType}】";
- break;
- case 98: // 98 其他款项
- priName = otherMoneyDatas.Find(it => payInfo.DIId == it.Diid && payInfo.CId == it.Id)?.PriceName ?? "-";
- break;
- case 285: // 285 收款退还
- priName = refundPaymentDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.PriceName ?? "-";
- break;
- case 1015: // 1015 超支费用
- priName = ExtraCostDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.PriceName ?? "-";
- break;
- default:
- priName = "";
- break;
- }
- bool status1 = false;
- if (_groupIds != null)
- {
- status1 = _groupIds.Contains(payInfo.Id);
- }
- var childInfo = new Group_DailyFeePaymentContentInfolView()
- {
- IsChecked = status1,
- Id = payInfo.Id,
- Payee = payInfo.Payee,
- RowNumber = rouNumber,
- Applicant = userDatas.Find(it => it.Id == payInfo.CreateUserId)?.CnName ?? "",
- ApplicantDt = payInfo.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
- PayType = setDatas.Find(it => it.Id == payInfo.PayDId)?.Name ?? "",
- TransferMark = orbitalPrivateTransfer,
- PriceName = priName,
- ModuleName = setDatas.Find(it => it.Id == payInfo.CTable)?.Name ?? "",
- PayCurrCode = setDatas.Find(it => it.Id == payInfo.PaymentCurrency)?.Name ?? "",
- PaymentAmount = payInfo.PayMoney,
- PayRate = payInfo.DayRate,
- CNYSubTotalAmount = ((payInfo.DayRate * payInfo.PayMoney) / 100) * payInfo.PayPercentage //此次付款金额
- };
- 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")}";
- childInfo.RemaksDescription = remaksDescription;
- childList.Add(childInfo);
- rouNumber++;
- }
- CompanyInfo companyInfo = new CompanyInfo();
- companyInfo = ExpenseCompanyByTeamId(groupInfo.TeamDid);
- dataList.Add(new tree_Group_DailyFeePaymentPageListView()
- {
- Id = Guid.NewGuid().ToString("N"),
- GroupName = groupInfo.TeamName,
- CompanyId = companyInfo.Id,
- ConpanyName = companyInfo.ConpanyName,
- CNYTotalAmount = childList.Sum(it => it.CNYSubTotalAmount),
- ChildList = childList,
- });
- }
- _DailyFeePaymentResult.dataList = dataList;
- return _DailyFeePaymentResult;
- }
- /// <summary>
- /// 付款申请(日付申请相关)
- /// 查询 根据日期范围
- /// </summary>
- /// <param name="_dailyIds"></param>
- /// <param name="beginDt"></param>
- /// <param name="endDt"></param>
- /// <returns></returns>
- private tree_Fin_DailyFeePaymentResult PayRequest_DailyByDateRange(int status, List<int> _dailyIds, string beginDt, string endDt)
- {
- #region sql条件处理
- string sqlWhere = string.Format(@" And dfp.CreateTime between '{0} 00:00:00' And '{1} 23:59:59' ", beginDt, endDt);
- if (status == 2)
- {
- if (_dailyIds.Count < 1)
- {
- return new tree_Fin_DailyFeePaymentResult() { childList = new List<Fin_DailyFeePaymentContentInfolView>() };
- }
- sqlWhere += string.Format(@" And dfp.Id In({0}) ", string.Join(",", _dailyIds));
- }
- string sql_1 = string.Format(@"Select * From (
- Select row_number() over (order by dfp.Id Desc) as RowNumber,
- dfp.Id,dfp.CompanyId,c.CompanyName,dfp.Instructions,dfp.SumPrice,
- dfp.CreateUserId,u.CnName CreateUser,dfp.CreateTime,dfp.FAudit,dfp.MAudit,
- dfp.PriceTypeId,dfp.TransferTypeId
- From Fin_DailyFeePayment dfp
- Inner Join Sys_Company c On dfp.CompanyId = c.Id
- Left Join Sys_Users u On dfp.CreateUserId = u.Id
- Where dfp.IsDel=0 {0} And dfp.FAudit = 1 And dfp.MAudit = 1 And dfp.IsPay = 0
- ) temp ", sqlWhere);
- #endregion
- List<tree_Fin_DailyFeePaymentPageListView> DailyFeePaymentData = _sqlSugar.SqlQueryable<tree_Fin_DailyFeePaymentPageListView>(sql_1).ToList();
- Dictionary<int, string> dic_setData = new Dictionary<int, string>();
- foreach (var item in DailyFeePaymentData)
- {
- if (_dailyIds != null)
- {
- item.IsChecked = _dailyIds.Contains(item.Id);
- }
- if (dic_setData.ContainsKey(item.PriceTypeId))
- {
- item.priceTypeStr = dic_setData[item.PriceTypeId];
- }
- else
- {
- Sys_SetData sd_priceType = _daiRep.Query<Sys_SetData>(s => s.Id == item.PriceTypeId).First();
- if (sd_priceType != null)
- {
- item.priceTypeStr = sd_priceType.Name;
- dic_setData.Add(item.PriceTypeId, sd_priceType.Name);
- }
- }
- if (dic_setData.ContainsKey(item.transferTypeId))
- {
- item.transferTypeIdStr = dic_setData[item.transferTypeId];
- Sys_SetData sd_transfer = _daiRep.Query<Sys_SetData>(s => s.Id == item.transferTypeId).First();
- if (sd_transfer != null)
- {
- item.transferParentId = sd_transfer.STid;
- item.transferParentIdStr = sd_transfer.STid == 62 ? "公转" : sd_transfer.STid == 63 ? "私转" : "";
- }
- }
- else
- {
- Sys_SetData sd_transfer = _daiRep.Query<Sys_SetData>(s => s.Id == item.transferTypeId).First();
- if (sd_transfer != null)
- {
- item.transferTypeIdStr = sd_transfer.Name;
- item.transferParentId = sd_transfer.STid;
- item.transferParentIdStr = sd_transfer.STid == 62 ? "公转" : sd_transfer.STid == 63 ? "私转" : "";
- dic_setData.Add(item.transferTypeId, sd_transfer.Name);
- }
- }
- string feeContentSql = string.Format(@"Select * From Fin_DailyFeePaymentContent
- Where IsDel=0 And DFPId = {0} ", item.Id);
- item.childList = _sqlSugar.SqlQueryable<Fin_DailyFeePaymentContentInfolView>(feeContentSql).ToList();
- int rowNumber = 1;
- foreach (var subItem in item.childList)
- {
- string remaksDescription = $"{rowNumber}、【{item.priceTypeStr}】{item.Instructions}({subItem.PriceName}) CNY:{subItem.ItemTotal.ToString("#0.00")}(单价:{subItem.Price.ToString("#0.00")} * {subItem.Quantity})";
- subItem.RemaksDescription = remaksDescription;
- 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")}】";
- subItem.ExcelRemaksDescription = excelRemaksDescription;
- rowNumber++;
- }
- }
- decimal total_gz = DailyFeePaymentData.Where(s => s.transferParentId == 62).Sum(d => d.SumPrice ?? 0M);
- decimal total_sz = DailyFeePaymentData.Where(s => s.transferParentId == 63).Sum(d => d.SumPrice ?? 0M);
- var result = new tree_Fin_DailyFeePaymentResult() { gz = total_gz, sz = total_sz, dataList = DailyFeePaymentData };
- return result;
- }
- /// <summary>
- /// 付款申请 (PageId=51)
- /// 团组,日付相关费用 选中状态变更
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostPayRequestCheckedChange(PayRequestCheckedChangeDto dto)
- {
- #region 验证
- if (dto.Type < 1 || dto.Type > 2)
- {
- return Ok(JsonView(false, "请传入有效的Type参数! 1 checked 2 清除上次勾选"));
- }
- #endregion
- try
- {
- PaymentRequestCheckedView requestCheckedView = new PaymentRequestCheckedView();
- List<int> groupIds = new List<int>();
- List<int> dailyPaymentIds = new List<int>();
- #region 参数处理
- if (!string.IsNullOrEmpty(dto.GroupIds))
- {
- if (dto.GroupIds.Contains(","))
- {
- groupIds = dto.GroupIds.Split(',').Select(int.Parse).ToList();
- }
- else
- {
- groupIds.Add(int.Parse(dto.GroupIds));
- }
- }
- if (!string.IsNullOrEmpty(dto.DailyPaymentIds))
- {
- if (dto.DailyPaymentIds.Contains(","))
- {
- dailyPaymentIds = dto.DailyPaymentIds.Split(',').Select(int.Parse).ToList();
- }
- else
- {
- dailyPaymentIds.Add(int.Parse(dto.DailyPaymentIds));
- }
- }
- #endregion
- requestCheckedView.GroupIds = groupIds;
- requestCheckedView.DailyPaymentIds = dailyPaymentIds;
- if (dto.Type == 1)
- {
- TimeSpan ts = DateTime.Now.AddDays(180) - DateTime.Now; //设置redis 过期时间 半年(180)
- var status = await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync<string>("paymentRequestCheckedData", JsonConvert.SerializeObject(requestCheckedView), ts);
- if (status)
- {
- return Ok(JsonView(true, "操作成功!"));
- }
- }
- else if (dto.Type == 2)
- {
- var status = await RedisRepository.RedisFactory.CreateRedisRepository().KeyDeleteAsync("paymentRequestCheckedData");
- if (status)
- {
- return Ok(JsonView(true, "操作成功!"));
- }
- }
- return Ok(JsonView(false, "操作失败!"));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- }
- }
- /// <summary>
- /// 付款申请 (PageId=51)
- /// 团组,日付相关费用 汇率变更
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostPayRequestRateChange(PayRequestRateChangeDto dto)
- {
- #region 验证
- DateTime beginDt, endDt;
- string format = "yyyy-MM-dd";
- if (!DateTime.TryParseExact(dto.beginDt, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out beginDt))
- {
- return Ok(JsonView(false, "开始日期格式不正确!正确格式:yyyy-MM-dd"));
- }
- if (!DateTime.TryParseExact(dto.endDt, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out endDt))
- {
- return Ok(JsonView(false, "结束日期格式不正确!正确格式:yyyy-MM-dd"));
- }
- if (dto.UserId < 1)
- {
- return Ok(JsonView(false, "请传入有效的UserId参数!"));
- }
- if (dto.Id < 1)
- {
- return Ok(JsonView(false, "请传入有效的Id参数!"));
- }
- if (dto.Rate <= 0)
- {
- return Ok(JsonView(false, "请传入有效的Rate参数!"));
- }
- #endregion
- try
- {
- var status = _sqlSugar.Updateable<Grp_CreditCardPayment>()
- .SetColumns(it => it.DayRate == dto.Rate)
- .Where(it => it.Id == dto.Id)
- .ExecuteCommand();
- if (status > 0)
- {
- PaymentRequestCheckedView checkedView = new PaymentRequestCheckedView();
- var checkedStr = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("paymentRequestCheckedData");
- if (checkedStr != null)
- {
- checkedView = JsonConvert.DeserializeObject<PaymentRequestCheckedView>(checkedStr.ToString());
- }
- tree_Fin_DailyFeePaymentResult dailyResult = PayRequest_DailyByDateRange(1, checkedView.DailyPaymentIds, dto.beginDt, dto.endDt);
- tree_Group_DailyFeePaymentResult groupResult = PayRequest_GroupPaymentByDateRange(1, checkedView.GroupIds, dto.beginDt, dto.endDt);
- decimal _gz = dailyResult.gz + groupResult.gz;
- decimal _sz = dailyResult.sz + groupResult.sz;
- return Ok(JsonView(true, "操作成功!", new { gz = dailyResult, sz = groupResult }));
- }
- return Ok(JsonView(false, "该项汇率修改失败!"));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- }
- }
- /// <summary>
- /// 付款申请 (PageId=51)
- /// 团组,日付相关费用 付款状态变更
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostPayRequestPayChange(PayRequestPayChangeDto dto)
- {
- if (dto.UserId < 1)
- {
- return Ok(JsonView(false, "请传入有效的UserId参数!"));
- }
- //if (string.IsNullOrEmpty(dto.GroupIds))
- //{
- // return Ok(JsonView(false, "请传入有效的GroupIds参数!"));
- //}
- //if (string.IsNullOrEmpty(dto.DailyPaymentIds))
- //{
- // return Ok(JsonView(false, "请传入有效的DailyPaymentIds参数!"));
- //}
- try
- {
- List<int> groupIds = new List<int>();
- List<int> dailyPaymentIds = new List<int>();
- #region 参数处理
- if (!string.IsNullOrEmpty(dto.GroupIds))
- {
- if (dto.GroupIds.Contains(","))
- {
- groupIds = dto.GroupIds.Split(',').Select(int.Parse).ToList();
- }
- else
- {
- groupIds.Add(int.Parse(dto.GroupIds));
- }
- }
- if (!string.IsNullOrEmpty(dto.DailyPaymentIds))
- {
- if (dto.DailyPaymentIds.Contains(","))
- {
- dailyPaymentIds = dto.DailyPaymentIds.Split(',').Select(int.Parse).ToList();
- }
- else
- {
- dailyPaymentIds.Add(int.Parse(dto.DailyPaymentIds));
- }
- }
- #endregion
- bool changeStatus = false;
- _sqlSugar.BeginTran();
- if (groupIds.Count > 0)
- {
- var groupStatus = _sqlSugar.Updateable<Grp_CreditCardPayment>()
- .SetColumns(it => it.IsPay == 1)
- .Where(it => groupIds.Contains(it.Id))
- .ExecuteCommand();
- if (groupStatus > 0)
- {
- changeStatus = true;
- }
- }
- if (dailyPaymentIds.Count > 0)
- {
- var dailyPaymentStatus = _sqlSugar.Updateable<Fin_DailyFeePayment>()
- .SetColumns(it => it.IsPay == 1)
- .Where(it => dailyPaymentIds.Contains(it.Id))
- .ExecuteCommand();
- if (dailyPaymentStatus > 0)
- {
- changeStatus = true;
- }
- }
- if (changeStatus)
- {
- _sqlSugar.CommitTran();
- return Ok(JsonView(true, "操作成功!"));
- }
- _sqlSugar.RollbackTran();
- return Ok(JsonView(false, "付款状态修改失败!"));
- }
- catch (Exception ex)
- {
- _sqlSugar.RollbackTran();
- return Ok(JsonView(false, ex.Message));
- }
- }
- /// <summary>
- /// 付款申请 (PageId=51)
- /// File Download
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostPayRequestFileDownload(PayRequestFileDownloadDto dto)
- {
- #region 参数,权限 验证
- if (dto.PortType < 1)
- {
- return Ok(JsonView(false, "请传入有效的PortType参数!"));
- }
- if (dto.UserId < 1)
- {
- return Ok(JsonView(false, "请传入有效的UserId参数!"));
- }
- if (dto.PageId < 1)
- {
- dto.PageId = 51;
- return Ok(JsonView(false, "请传入有效的PageId参数!"));
- }
- if (dto.ConpanyId < 1 || dto.ConpanyId > 4)
- {
- return Ok(JsonView(false, "请传入有效的ConpanyId参数!"));
- }
- PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
- #region 页面操作权限验证
- pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
- if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限!"));
- #endregion
- #endregion
- try
- {
- PaymentRequestCheckedView checkedView = new PaymentRequestCheckedView();
- var checkedStr = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("paymentRequestCheckedData");
- if (checkedStr != null)
- {
- checkedView = JsonConvert.DeserializeObject<PaymentRequestCheckedView>(checkedStr.ToString());
- }
- if (checkedView == null)
- {
- return Ok(JsonView(false, "没有选中的数据!"));
- }
- if (checkedView.GroupIds == null && checkedView.DailyPaymentIds == null)
- {
- return Ok(JsonView(false, "没有选中的数据!"));
- }
- tree_Fin_DailyFeePaymentResult dailyResult = PayRequest_DailyByDateRange(2, checkedView.DailyPaymentIds, dto.beginDt, dto.endDt);
- tree_Group_DailyFeePaymentResult groupResult = PayRequest_GroupPaymentByDateRange(2, checkedView.GroupIds, dto.beginDt, dto.endDt);
- if (dailyResult.childList == null)
- {
- dailyResult.childList = new List<Fin_DailyFeePaymentContentInfolView>();
- }
- List<tree_Group_DailyFeePaymentPageListView> _GroupData = new List<tree_Group_DailyFeePaymentPageListView>();
- List<tree_Fin_DailyFeePaymentPageListView> _DailyData = new List<tree_Fin_DailyFeePaymentPageListView>();
- //1 成都泛美商务有限公司
- if (dto.ConpanyId == 1)
- {
- if (groupResult.dataList != null && groupResult.dataList.Count > 0) _GroupData = groupResult.dataList.Where(it => it.CompanyId == 1).ToList();
- if (dailyResult.dataList != null && dailyResult.dataList.Count > 0) _DailyData = dailyResult.dataList.Where(it => it.CompanyId == 1).ToList();
- }
- //2 四川泛美交流有限公司
- else if (dto.ConpanyId == 2)
- {
- if (groupResult.dataList != null && groupResult.dataList.Count > 0) _GroupData = groupResult.dataList.Where(it => it.CompanyId == 2).ToList();
- if (dailyResult.dataList != null && dailyResult.dataList.Count > 0) _DailyData = dailyResult.dataList.Where(it => it.CompanyId == 2).ToList();
- }
- //3 成都纽茵教育科技有限公司
- else if (dto.ConpanyId == 3)
- {
- if (groupResult.dataList != null && groupResult.dataList.Count > 0) _GroupData = groupResult.dataList.Where(it => it.CompanyId == 3).ToList();
- if (dailyResult.dataList != null && dailyResult.dataList.Count > 0) _DailyData = dailyResult.dataList.Where(it => it.CompanyId == 3).ToList();
- }
- //4 成都鸿企中元科技有限公司
- else if (dto.ConpanyId == 4)
- {
- return Ok(JsonView(false, "暂未开放该类型!"));
- }
- else
- {
- return Ok(JsonView(false, "参数ConpanyId不可使用!"));
- }
- string _requestPaymentDt = DateTime.Now.ToString("yyyy-MM-dd"),//申请付款日期
- _appliedAmount = "", //申请付款金额
- _GZStr = "", //公转价格描述
- _SZStr = ""; //私转价格描述
- decimal groupGZAmout = 0.00M, groupSZAmout = 0.00M;
- decimal dailyGZAmout = 0.00M, dailySZAmout = 0.00M;
- string dailyGZStr = "", dailySZStr = "", groupGZStr = "", groupSZStr = "";
- #region 数据处理
- //团组费用相关
- foreach (var item in _GroupData)
- {
- string groupGZSubStr = "";
- string groupSZSubStr = "";
- foreach (var subItem in item.ChildList)
- {
- if (subItem.TransferMark.Equals("公转"))
- {
- groupGZAmout += subItem.CNYSubTotalAmount;
- groupGZSubStr += $"{subItem.RemaksDescription}\r\n";
- }
- else if (subItem.TransferMark.Equals("私转"))
- {
- groupSZAmout += subItem.CNYSubTotalAmount;
- groupSZSubStr += $"{subItem.RemaksDescription}\r\n";
- }
- groupGZSubStr += $"\t";
- }
- if (!string.IsNullOrEmpty(groupGZSubStr)) groupGZStr += $"团组:{item.GroupName}\r\n{groupGZSubStr}\r\n";
- if (!string.IsNullOrEmpty(groupSZSubStr)) groupSZStr += $"团组:{item.GroupName}\r\n{groupSZSubStr}\r\n";
- }
- //日常费用相关
- foreach (var item in _DailyData)
- {
- foreach (var subItem in item.childList)
- {
- if (item.transferParentId == 62) //公转
- {
- dailyGZAmout += item.SumPrice ?? 0.00M;
- dailyGZStr += $"{item.RowNumber}、【{item.CompanyName}】{subItem.ExcelRemaksDescription}\r\n";
- }
- else if (item.transferParentId == 63) //私转
- {
- dailySZAmout += item.SumPrice ?? 0.00M;
- dailySZStr += $"{item.RowNumber}、【{item.CompanyName}】{subItem.ExcelRemaksDescription}\r\n";
- }
- }
- }
- _GZStr = $"【公转】团组相关费用(合计:CNY {groupGZAmout.ToString("#0.00")}):\r\n{groupGZStr}【公转】日常付款费用(合计:CNY {dailyGZAmout.ToString("#0.00")}):\r\n{dailyGZStr}";
- _SZStr = $"【私转】团组相关费用(合计:CNY {groupSZAmout.ToString("#0.00")}):\r\n{groupSZStr}【私转】日常付款费用(合计:CNY {dailySZAmout.ToString("#0.00")}):\r\n{dailySZStr}";
- _appliedAmount = $"公转:CNY {(groupGZAmout + dailyGZAmout).ToString("#0.00")}\r\n私转:CNY {(groupSZAmout + dailySZAmout).ToString("#0.00")}";
- #endregion
- WorkbookDesigner designer = new WorkbookDesigner();
- designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/付款申请书.xls");
- designer.SetDataSource("Date", _requestPaymentDt);
- designer.SetDataSource("Price", _appliedAmount);
- designer.SetDataSource("Content", _GZStr);
- designer.SetDataSource("Content1", _SZStr);
- //根据数据源处理生成报表内容
- designer.Process();
- string fileName = ("PayRequest/付款申请(" + dto.beginDt + "~" + dto.endDt + ").xlsx");
- designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
- string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
- return Ok(JsonView(true, "操作成功!", new { url = rst }));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- }
- }
- #endregion
- #region 超支费用
- /// <summary>
- /// 超支费用
- /// 1增、2改、3删
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostGroupExtraCost_Operator(Fin_GroupExtraCostDto_OP dto)
- {
- #region 验证
- #endregion
- Fin_GroupExtraCost _entity = new Fin_GroupExtraCost();
- _entity.DiId = dto.diId;
- _entity.PriceName = dto.priceName;
- _entity.Price = dto.price;
- _entity.PriceCurrency = dto.currency;
- _entity.PriceType = dto.priceType;
- _entity.Coefficient = dto.coefficient;
- _entity.PriceDetailType = dto.priceDetailType;
- _entity.FilePath = dto.filePath;
- _entity.Remark = dto.remark;
- _entity.PriceCount = dto.PriceCount;
- _entity.PriceDt = DateTime.Parse(dto.PriceDt);
- _entity.PriceSum = dto.price * dto.PriceCount;
- _daiRep.BeginTran();
- if (dto.editType == 1)
- {
- _entity.CreateUserId = dto.createUser;
- _entity.CreateTime = DateTime.Now;
- _entity.IsDel = 0;
- int returnId = await _daiRep.AddAsyncReturnId<Fin_GroupExtraCost>(_entity);
- if (returnId > 0)
- {
- dto.Id = returnId;
- }
- }
- else if (dto.editType == 2)
- {
- bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
- {
- PriceName = dto.priceName,
- Price = dto.price,
- PriceCurrency = dto.currency,
- PriceType = dto.priceType,
- PriceDetailType = dto.priceDetailType,
- Coefficient = dto.coefficient,
- FilePath = dto.filePath,
- Remark = dto.remark,
- PriceCount = dto.PriceCount,
- PriceDt = _entity.PriceDt,
- PriceSum = _entity.PriceSum
- });
- if (!res)
- {
- _daiRep.RollbackTran();
- return Ok(JsonView(false, "2操作失败!"));
- }
- }
- else if (dto.editType == 3)
- {
- string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
- bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
- {
- IsDel = 1,
- DeleteTime = delTime,
- DeleteUserId = dto.createUser
- });
- if (!res)
- {
- _daiRep.RollbackTran();
- return Ok(JsonView(false, "3操作失败!"));
- }
- }
- else
- {
- _daiRep.RollbackTran();
- return Ok(JsonView(false, "未知的editType"));
- }
- if (!extraCost_editCreditCardPayment(dto))
- {
- return Ok(JsonView(false, "ccp操作失败"));
- }
- _daiRep.CommitTran();
- return Ok(JsonView(true, "操作成功"));
- }
- private bool extraCost_editCreditCardPayment(Fin_GroupExtraCostDto_OP costDto)
- {
- //设置团组汇率
- decimal dcm_dayrate = 1M;
- decimal dcm_rmbPrice = costDto.price;
- int ispay = costDto.payType == 72 ? 1 : 0;
- if (costDto.costSign != 3)
- {
- Grp_TeamRate tr = _daiRep.Query<Grp_TeamRate>(s => s.DiId == costDto.diId && s.CTable == 1015).First();
- if (tr != null)
- {
- if (costDto.currency == 49)
- {
- dcm_dayrate = tr.RateU;
- dcm_rmbPrice = dcm_rmbPrice * tr.RateU;
- }
- else if (costDto.currency == 51)
- {
- dcm_dayrate = tr.RateE;
- dcm_rmbPrice = dcm_rmbPrice * tr.RateE;
- }
- }
- }
- Grp_CreditCardPayment ccp = _daiRep.Query<Grp_CreditCardPayment>(s => s.CId == costDto.Id && s.CTable == 1015).First();
- if (ccp == null)
- {
- ccp = new Grp_CreditCardPayment();
- ccp.PayDId = costDto.payType;// dto
- ccp.ConsumptionPatterns = "";
- ccp.ConsumptionDate = "";
- ccp.CTDId = costDto.payCardId;// dto
- ccp.BankNo = "";
- ccp.CardholderName = "";
- ccp.PayMoney = costDto.price;// dto
- ccp.PaymentCurrency = costDto.currency;// dto
- ccp.CompanyBankNo = "";
- ccp.OtherBankName = "";
- ccp.OtherSideNo = "";
- ccp.OtherSideName = "";
- ccp.Remark = "";
- ccp.CreateUserId = costDto.createUser;
- ccp.CreateTime = DateTime.Now;
- ccp.MFOperator = 0;
- ccp.MFOperatorDate = "";
- ccp.IsAuditDM = 0;
- ccp.AuditDMOperate = 0;
- ccp.AuditDMDate = "";
- ccp.IsAuditMF = 0;
- ccp.AuditMFOperate = 0;
- ccp.AuditMFDate = "";
- ccp.IsAuditGM = 0;
- ccp.AuditGMOperate = 0;
- ccp.AuditGMDate = "";
- ccp.IsPay = ispay; // upd
- ccp.DIId = costDto.diId;// dto
- ccp.CId = costDto.Id;// dto
- ccp.CTable = 1015; //超支费用指向id
- ccp.IsDel = 0;
- ccp.PayPercentage = 100M;
- ccp.PayThenMoney = 0M;
- ccp.PayPercentageOld = 100M;
- ccp.PayThenMoneyOld = 0M;
- ccp.UpdateDate = "";
- ccp.Payee = costDto.payee;// dto
- ccp.OrbitalPrivateTransfer = costDto.costSign;// dto
- ccp.ExceedBudget = 0;
- ccp.DayRate = dcm_dayrate; //upd
- ccp.RMBPrice = dcm_rmbPrice; //upd
- int ccpInsertId = _daiRep.AddReturnId<Grp_CreditCardPayment>(ccp);
- if (ccpInsertId > 0)
- {
- return true;
- }
- }
- else
- {
- if (costDto.editType == 2)
- {
- bool res = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
- {
- PayDId = costDto.payType,
- CTDId = costDto.payCardId,
- PayMoney = costDto.price,
- PaymentCurrency = costDto.currency,
- IsPay = ispay,
- Payee = costDto.payee,
- OrbitalPrivateTransfer = costDto.costSign,
- DayRate = dcm_dayrate,
- RMBPrice = dcm_rmbPrice
- });
- return res;
- }
- else if (costDto.editType == 3)
- {
- string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
- bool res2 = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
- {
- IsDel = 1,
- DeleteTime = delTime,
- DeleteUserId = costDto.createUser
- });
- return res2;
- }
- }
- return false;
- }
- /// <summary>
- /// 超支费用
- /// 详情查询
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostGroupExtraCost_Detail(Fin_GroupExtraCostDto_Detail dto)
- {
- if (dto.Id < 1) {
- return Ok(JsonView(false, "查询失败"));
- }
- string sql = string.Format(@" Select
- f.Id,f.DiId,
- f.PriceName,f.Price,f.PriceCurrency,c.Payee,c.OrbitalPrivateTransfer,c.PayDId,
- c.CTDId,f.PriceType,f.PriceDetailType,f.Coefficient,f.Remark,f.PriceCount,f.PriceDt
- From Fin_GroupExtraCost f
- Inner Join Grp_CreditCardPayment c On f.Id = c.CId
- Left Join Sys_Users u On f.CreateUserId = u.Id
- Where f.IsDel=0 And c.CTable = 1015
- And f.Id = {0} ", dto.Id);
- Fin_GroupExtraCostDetailView detailView = await _sqlSugar.SqlQueryable<Fin_GroupExtraCostDetailView>(sql).FirstAsync();
- if (detailView == null) {
- return Ok(JsonView(false, "查询失败"));
- }
- return Ok(JsonView(true, "查询成功", detailView));
- }
- /// <summary>
- /// 超支费用
- /// 列表查询
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostGroupExtraCost_Search(Fin_GroupExtraCostDto_Search dto)
- {
- string sqlWhere = string.Format(@" And f.DiId = {0} ", dto.diId);
- int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
- int endIndex = startIndex + dto.PageSize - 1;
- string sql_data = string.Format(@"Select * From (
- Select row_number() over (order by f.Id Desc) as RowNumber,f.Id,f.DiId,
- 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,
- f.CreateUserId,f.PriceDt,c.IsAuditGM
- From Fin_GroupExtraCost f
- Inner Join Grp_CreditCardPayment c On f.Id = c.CId
- Inner Join Sys_SetData s On f.PriceCurrency = s.Id
- Left Join Sys_Users u On f.CreateUserId = u.Id
- Where f.IsDel=0 And c.CTable = 1015 {0}
- ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
- string sql_count = string.Format(@"Select Count(1) as DataCount From (
- Select row_number() over (order by f.Id Desc) as RowNumber,f.Id,f.DiId,
- f.PriceName,f.PriceType,f.Price,f.FilePath,f.CreateUserId,f.CreateTime,c.IsAuditGM
- From Fin_GroupExtraCost f
- Inner Join Grp_CreditCardPayment c On f.Id = c.CId
- Inner Join Sys_SetData s On f.PriceCurrency = s.Id
- Left Join Sys_Users u On f.CreateUserId = u.Id
- Where f.IsDel=0 And c.CTable = 1015 {0}
- ) temp ", sqlWhere);
- if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
- {
- //Fin_DailyFeePaymentPageCount
- var count = await _sqlSugar.SqlQueryable<Fin_GroupExtraCostViewDataCount>(sql_count).FirstAsync();
- List<Fin_GroupExtraCostView> dataList = await _sqlSugar.SqlQueryable<Fin_GroupExtraCostView>(sql_data).ToListAsync();
- Dictionary<int, string> dic_setData = new Dictionary<int, string>();
- Dictionary<int, string> dic_user = new Dictionary<int, string>();
- foreach (var item in dataList)
- {
- DateTime dtTemp_PriceDt;
- bool b_ct = DateTime.TryParse(item.PriceDt, out dtTemp_PriceDt);
- if (b_ct)
- {
- item.PriceDt = dtTemp_PriceDt.ToString("yyyy-MM-dd");
- }
- //费用类型
- if (dic_setData.ContainsKey(item.PriceType))
- {
- item.PriceTypeStr = dic_setData[item.PriceType];
- }
- else
- {
- Sys_SetData sd_priceTypeDetail = _daiRep.Query<Sys_SetData>(s => s.Id == item.PriceType).First();
- if (sd_priceTypeDetail != null)
- {
- string tempName = sd_priceTypeDetail.Name.Replace("n", "");
- item.PriceTypeStr = tempName;
- dic_setData.Add(item.PriceType, tempName);
- }
- }
- if (item.PriceDetailType > 0) {
- if (dic_setData.ContainsKey(item.PriceDetailType))
- {
- item.PriceTypeStr = item.PriceTypeStr + " - " + dic_setData[item.PriceDetailType];
- }
- else
- {
- Sys_SetData sd_priceTypeDetail = _daiRep.Query<Sys_SetData>(s => s.Id == item.PriceDetailType).First();
- if (sd_priceTypeDetail != null)
- {
- string tempName = sd_priceTypeDetail.Name.Replace("n", "");
- item.PriceTypeStr = item.PriceTypeStr + " - " + tempName;
- dic_setData.Add(item.PriceDetailType, tempName);
- }
- }
- }
- //系统用户
- if (dic_user.ContainsKey(item.CreateUserId))
- {
- item.CreateUserIdStr = dic_user[item.CreateUserId];
- }
- else
- {
- Sys_Users users = _daiRep.Query<Sys_Users>(s => s.Id == item.CreateUserId).First();
- if (users != null)
- {
- item.CreateUserIdStr = users.CnName;
- dic_user.Add(item.CreateUserId, users.CnName);
- }
- }
- switch (item.IsAuditGM)
- {
- case 0: item.IsAuditGMStr = "未审核"; break;
- case 1: item.IsAuditGMStr = "已通过"; break;
- case 2: item.IsAuditGMStr = "未通过"; break;
- default: item.IsAuditGMStr = "未知状态"; break;
- }
- }
- var result = new ListViewBase<Fin_GroupExtraCostView>
- {
- CurrPageIndex = dto.PageIndex,
- CurrPageSize = dto.PageSize,
- DataCount = count.DataCount,
- DataList = dataList
- };
- return Ok(JsonView(true, "查询成功", result));
- }
- return Ok(JsonView(false, "查询失败"));
- }
- /// <summary>
- /// 超支费用
- /// 数据集合配置
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostGroupExtraCost_ListDataInit(Fin_GroupExtraCostDto_DataListInit dto)
- {
- //支付方式
- List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
- List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
- //信用卡类型
- List<Sys_SetData> Card = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 15 && a.IsDel == 0).ToList();
- List<SetDataInfoView> _Card = _mapper.Map<List<SetDataInfoView>>(Card);
- //超支费用类型
- List<Sys_SetData> PriceType = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 79 && a.IsDel == 0).ToList();
- List<SetDataInfoView> _PriceType = _mapper.Map<List<SetDataInfoView>>(PriceType);
- //超支费用详细类型
- List<Sys_SetData> PriceDetailType = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 80 && a.IsDel == 0).ToList();
- PriceDetailType.ForEach(a => { a.Name = a.Name.Replace("n", ""); });
- List<SetDataInfoView> _PriceDetailType = _mapper.Map<List<SetDataInfoView>>(PriceDetailType);
- var data = new
- {
- Payment = _Payment,
- Card = _Card,
- PriceType = _PriceType,
- PriceDetailType = _PriceDetailType
- };
- return Ok(JsonView(true, "", data));
- }
- #endregion
- }
- }
|