511 lines
20 KiB
C#
511 lines
20 KiB
C#
using YLErp.Abstract;
|
|
using YLErp.Modules.ClientModule;
|
|
using YLErp.Modules.TradeModule.QueryModule;
|
|
|
|
namespace YLErp.Web.Controllers
|
|
{
|
|
public class entryexitController : BaseController
|
|
{
|
|
readonly IViewRenderService _viewRenderer;
|
|
private IKafkaProduce kafkaProduceHelper;
|
|
public entryexitController(IViewRenderService viewRenderer,IKafkaProduce kafkaProduce)
|
|
{
|
|
_viewRenderer = viewRenderer;
|
|
kafkaProduceHelper = kafkaProduce;
|
|
}
|
|
[MyAuthorize("结算管理-出入金维护")]
|
|
public ActionResult entryexitList()
|
|
{
|
|
var outCashProcess = new ClientCashInCashOutDataService(CurUser).GetOutCashProcess();
|
|
var stateList = EntryExitBLL.State;
|
|
if (stateList.IndexOf(ClientCashInCashOut.审批中) < 0 && outCashProcess.Any())
|
|
{
|
|
stateList.Add(ClientCashInCashOut.审批中);
|
|
}
|
|
ViewBag.stateList = stateList;
|
|
return View();
|
|
}
|
|
|
|
public JsonResult excute(IEnumerable<int> ids)
|
|
{
|
|
new ClientCashInCashOutDataService(CurUser).ExcuteEntryExit(ids, kafkaProduceHelper);
|
|
|
|
return JsonSuccess("确认成功");
|
|
}
|
|
|
|
public JsonResult reject(IEnumerable<int> ids)
|
|
{
|
|
var sbmsg = new ClientCashInCashOutDataService(CurUser).ClientCashInCashOutReject(ids);
|
|
return JsonSuccess(sbmsg.ToString());
|
|
}
|
|
|
|
[HttpPost]
|
|
public JsonResult entryexitQuery(EntryExitReq req)
|
|
{
|
|
#region 预处理查询条件
|
|
|
|
if (!req.DirectionTypes.IsNullOrWhiteSpace())
|
|
{
|
|
var directionList = new List<string>();
|
|
var tradeActionList = new List<string>();
|
|
var inTradeActionList = new List<string>();
|
|
var outTradeActionList = new List<string>();
|
|
var inOutList = new List<string>();
|
|
void addWhenNotContains(List<string> list, string str)
|
|
{
|
|
if (!list.Contains(str))
|
|
{
|
|
list.Add(str);
|
|
}
|
|
}
|
|
if (req.DirectionTypeList.Contains("出金"))
|
|
{
|
|
addWhenNotContains(directionList, "出金");
|
|
}
|
|
|
|
if (req.DirectionTypeList.Contains("入金"))
|
|
{
|
|
addWhenNotContains(directionList, "入金");
|
|
}
|
|
|
|
if (req.DirectionTypeList.Contains("实收预付金"))
|
|
{
|
|
addWhenNotContains(directionList, "实收预付金");
|
|
}
|
|
|
|
if (req.DirectionTypeList.Contains("实付预付金"))
|
|
{
|
|
addWhenNotContains(directionList, "实付预付金");
|
|
}
|
|
|
|
if (req.DirectionTypeList.Contains("实收权利金"))
|
|
{
|
|
addWhenNotContains(directionList, "实收权利金");
|
|
}
|
|
|
|
if (req.DirectionTypeList.Contains("实付权利金"))
|
|
{
|
|
addWhenNotContains(directionList, "实付权利金");
|
|
}
|
|
|
|
if (req.DirectionTypeList.Contains("其他收入"))
|
|
{
|
|
addWhenNotContains(directionList, "其他收入");
|
|
}
|
|
|
|
if (req.DirectionTypeList.Contains("其他支出"))
|
|
{
|
|
addWhenNotContains(directionList, "其他支出");
|
|
}
|
|
|
|
if (req.DirectionTypeList.Contains("权利金支出"))
|
|
{
|
|
addWhenNotContains(tradeActionList, ClientCashInCashOut.系统操作_期权费);
|
|
addWhenNotContains(inOutList, "应付");
|
|
addWhenNotContains(outTradeActionList, ClientCashInCashOut.系统操作_期权费);
|
|
}
|
|
if (req.DirectionTypeList.Contains("权利金收入"))
|
|
{
|
|
addWhenNotContains(tradeActionList, ClientCashInCashOut.系统操作_期权费);
|
|
addWhenNotContains(inOutList, "应收");
|
|
addWhenNotContains(inTradeActionList, ClientCashInCashOut.系统操作_期权费);
|
|
}
|
|
if (req.DirectionTypeList.Contains("平仓/行权收入"))
|
|
{
|
|
addWhenNotContains(tradeActionList, ClientCashInCashOut.系统操作_平仓费);
|
|
addWhenNotContains(tradeActionList, ClientCashInCashOut.系统操作_行权费);
|
|
addWhenNotContains(inOutList, "应收");
|
|
addWhenNotContains(inTradeActionList, ClientCashInCashOut.系统操作_平仓费);
|
|
addWhenNotContains(inTradeActionList, ClientCashInCashOut.系统操作_行权费);
|
|
}
|
|
if (req.DirectionTypeList.Contains("平仓/行权支出"))
|
|
{
|
|
addWhenNotContains(tradeActionList, ClientCashInCashOut.系统操作_平仓费);
|
|
addWhenNotContains(tradeActionList, ClientCashInCashOut.系统操作_行权费);
|
|
addWhenNotContains(inOutList, "应付");
|
|
addWhenNotContains(outTradeActionList, ClientCashInCashOut.系统操作_平仓费);
|
|
addWhenNotContains(outTradeActionList, ClientCashInCashOut.系统操作_行权费);
|
|
}
|
|
if (req.DirectionTypeList.Contains("票息收入"))
|
|
{
|
|
addWhenNotContains(tradeActionList, ClientCashInCashOut.系统操作_票息);
|
|
addWhenNotContains(inOutList, "应收");
|
|
addWhenNotContains(inTradeActionList, ClientCashInCashOut.系统操作_票息);
|
|
}
|
|
if (req.DirectionTypeList.Contains("票息支出"))
|
|
{
|
|
addWhenNotContains(tradeActionList, ClientCashInCashOut.系统操作_票息);
|
|
addWhenNotContains(inOutList, "应付");
|
|
addWhenNotContains(outTradeActionList, ClientCashInCashOut.系统操作_票息);
|
|
}
|
|
if (req.DirectionTypeList.Contains("互换收入"))
|
|
{
|
|
addWhenNotContains(tradeActionList, ClientCashInCashOut.系统操作_互换);
|
|
addWhenNotContains(inOutList, "应收");
|
|
addWhenNotContains(inTradeActionList, ClientCashInCashOut.系统操作_互换);
|
|
}
|
|
if (req.DirectionTypeList.Contains("互换支出"))
|
|
{
|
|
addWhenNotContains(tradeActionList, ClientCashInCashOut.系统操作_互换);
|
|
addWhenNotContains(inOutList, "应付");
|
|
addWhenNotContains(outTradeActionList, ClientCashInCashOut.系统操作_互换);
|
|
}
|
|
if (req.DirectionTypeList.Contains("应付预付金"))
|
|
{
|
|
addWhenNotContains(tradeActionList, ClientCashInCashOut.系统操作_应付预付金);
|
|
addWhenNotContains(inOutList, "应付");
|
|
addWhenNotContains(outTradeActionList, ClientCashInCashOut.系统操作_应付预付金);
|
|
}
|
|
if (req.DirectionTypeList.Contains("预付金返息"))
|
|
{
|
|
addWhenNotContains(tradeActionList, ClientCashInCashOut.系统操作_预付金返息);
|
|
addWhenNotContains(inOutList, "应付");
|
|
addWhenNotContains(outTradeActionList, ClientCashInCashOut.系统操作_预付金返息);
|
|
}
|
|
req.Direction = string.Join(",", directionList);
|
|
req.TradeAction = string.Join(",", tradeActionList);
|
|
req.InTradeAction = string.Join(",", inTradeActionList);
|
|
req.OutTradeAction = string.Join(",", outTradeActionList);
|
|
req.InOut = string.Join(",", inOutList);
|
|
|
|
}
|
|
|
|
req.IsMoneyNotEqualsZero = true;
|
|
#endregion
|
|
req.CurUserClientIds = CurUser.GetClientIdsByCustomerManager();
|
|
var sList = new EntryExitBLL().SearchListExtend(req, out _, true);
|
|
return Json(sList);
|
|
}
|
|
public ActionResult ClientCashLogList(int id)
|
|
{
|
|
var dates = yldb.clientcash_log.Where(c => c.CashId == id)
|
|
.Select(n => new ClientCashLogDto
|
|
{
|
|
id = n.id,
|
|
OptType = n.OptType,
|
|
Changes = n.Changes ?? "",
|
|
OptName = n.OptName,
|
|
OptDate = n.OptDate
|
|
}).OrderByDescending(d => d.id).ToArray();
|
|
|
|
var datatrace = new DatatraceQueryService(CurUser);
|
|
foreach (var item in dates)
|
|
{
|
|
if (item.Changes.Contains("["))
|
|
{
|
|
item.Changes = datatrace.ReplaceDataChanges(new ClientCashLog(), item.Changes);
|
|
}
|
|
}
|
|
|
|
return View(dates);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 已确认的出入金记录
|
|
/// </summary>
|
|
[HttpPost]
|
|
public JsonResult ExecutedCashList(EntryExitReq req)
|
|
{
|
|
CurUser.CheckClientPowerByClientId(req.ClientId ?? 0);
|
|
var sList = ClientAssetDataService.ExecutedCashList(req);
|
|
return Json(sList);
|
|
}
|
|
/// <summary>
|
|
/// 资金查看
|
|
/// </summary>
|
|
/// <param name="enid"></param>
|
|
/// <param name="approval">是否审批链接过来</param>
|
|
/// <returns></returns>
|
|
public ActionResult entryexitView(string enid, bool approval = false)
|
|
{
|
|
var intid = DataProtectHelper.DecryptInt(enid);
|
|
var r = yldb.ClientCashInCashOut.Find(intid);
|
|
|
|
var update = yldb.clientcashincashout_update.Where(x => x.State == "修改待确认" && x.ValidState != ConsGlobal.InValid && x.ClientcashincashoutId == r.id);
|
|
if (update.Any())
|
|
{
|
|
r.Money = update.FirstOrDefault().NewMoney;
|
|
r.Direction = update.FirstOrDefault().NewDirection;
|
|
r.HappenDate = update.FirstOrDefault().NewHappenDate;
|
|
r.State = "修改待确认";
|
|
}
|
|
|
|
if (r.TradeId != null && r.TradeId > 0 && string.IsNullOrEmpty(r.TradeNumber))
|
|
{
|
|
r.TradeNumber = yldb.trade.Find(r.TradeId)?.TradeNumber;
|
|
}
|
|
|
|
if (r.Action == ClientCashInCashOut.人工操作_预付金)
|
|
{
|
|
r.Direction = r.Money > 0 ? "应收" : "应付";
|
|
r.Money = Math.Abs(r.Money ?? 0);
|
|
ViewBag.IsCompanyCash = true;
|
|
}
|
|
if (r.TradeId > 0)
|
|
{
|
|
r.TradeType = yldb.trade.Find(r.TradeId).TradeType;
|
|
}
|
|
using (var clientdb = YLErp.Modules.DbContextFactory.GetClientDbContext(CurUser))
|
|
{
|
|
if (r.OpenBankId != null)
|
|
{
|
|
r.Uses = clientdb.bankcard.Find(r.OpenBankId)?.Use ?? "全部";
|
|
}
|
|
else if (!string.IsNullOrWhiteSpace(r.OpenBankCard))
|
|
{
|
|
r.Uses = clientdb.bankcard.Where(x => x.ApprovalOrder < 1 && x.Card == r.OpenBankCard && x.ClientId == r.ClientId).FirstOrDefault()?.Use ?? "全部";
|
|
}
|
|
}
|
|
ViewBag.approval = approval;
|
|
return View(r);
|
|
}
|
|
|
|
public ActionResult entryexitEdit(string enid, bool resend = false)
|
|
{
|
|
ClientCashInCashOut r;
|
|
var isAdd = string.IsNullOrEmpty(enid) || enid == "0";
|
|
if (isAdd)
|
|
{
|
|
r = new ClientCashInCashOut { HappenDate = valuedateBLL.ValueDate.AddHours(DateTime.Now.Hour).AddMinutes(DateTime.Now.Minute).AddSeconds(DateTime.Now.Second) };
|
|
ViewBag.IsCompanyCash = Request.Query["isCompanyCash"] == "1";
|
|
return View(r);
|
|
}
|
|
else
|
|
{
|
|
if (!CurUser.结算管理_修改资金记录)
|
|
{
|
|
return JsonError("没有修改资金记录的权限");
|
|
}
|
|
}
|
|
var intid = DataProtectHelper.DecryptInt(enid);
|
|
r = yldb.ClientCashInCashOut.Find(intid);
|
|
|
|
var up = yldb.clientcashincashout_update.Where(x => x.State == "修改待确认" && x.ValidState != ConsGlobal.InValid && x.ClientcashincashoutId == intid);
|
|
if (up.Any())
|
|
{
|
|
r.Money = up.FirstOrDefault().NewMoney;
|
|
r.Direction = up.FirstOrDefault().NewDirection;
|
|
}
|
|
|
|
if (r.Action == ClientCashInCashOut.人工操作_预付金)
|
|
{
|
|
r.Direction = r.Money > 0 ? "应收" : "应付";
|
|
ViewBag.IsCompanyCash = true;
|
|
}
|
|
|
|
r.Money = Math.Abs(r.Money ?? 0);
|
|
|
|
if (r.OpenBankId != null)
|
|
{
|
|
using (var clientdb = YLErp.Modules.DbContextFactory.GetClientDbContext(CurUser))
|
|
{
|
|
r.Uses = clientdb.bankcard.Find(r.OpenBankId)?.Use;
|
|
}
|
|
}
|
|
if (resend)
|
|
{
|
|
r.id = 0;
|
|
r.State = "";
|
|
}
|
|
return View(r);
|
|
}
|
|
|
|
[HttpPost]
|
|
public JsonResult entryexitEditJson(ClientCashInCashOut req)
|
|
{
|
|
var id = 0;
|
|
|
|
if (!string.IsNullOrEmpty(req.EncryptId))
|
|
{
|
|
id = DataProtectHelper.DecryptInt(req.EncryptId);
|
|
}
|
|
|
|
req.Action = Request.Form[nameof(req.Action)];
|
|
|
|
var r = new ClientCashInCashOutDataService(CurUser).SaveEntryexit(id, req);
|
|
|
|
return JsonSuccess("更新成功", r);
|
|
}
|
|
|
|
[HttpPost]
|
|
public JsonResult saveClientCashInOutComments(EntryExitReq req)
|
|
{
|
|
var id = 0;
|
|
if (!string.IsNullOrEmpty(req.EncryptId))
|
|
{
|
|
id = DataProtectHelper.DecryptInt(req.EncryptId);
|
|
}
|
|
|
|
var r = new ClientCashInCashOutDataService(CurUser).saveClientCashInOutComments(id, req);
|
|
|
|
return JsonSuccess("更新成功", r);
|
|
}
|
|
|
|
[HttpPost]
|
|
public JsonResult Deleteentryexit(string id)
|
|
{
|
|
if (!CurUser.结算管理_出入金删除)
|
|
{
|
|
return JsonError("没有权限");
|
|
}
|
|
var intid = DataProtectHelper.DecryptInt(id);
|
|
var r = yldb.ClientCashInCashOut.Find(intid);
|
|
if (r == null)
|
|
{
|
|
return JsonError("找不到出入金信息");
|
|
}
|
|
if (r.Direction != "出金" && r.Direction != "入金" && r.Direction != "其他收入" && r.Direction != "其他支出")
|
|
{
|
|
return JsonError("该笔交易不可以删除");
|
|
}
|
|
yldb.ClientCashInCashOut.Remove(r);
|
|
var s = yldb.Clientcashincashout_remove.Add(new Clientcashincashout_remove()).Entity;
|
|
yldb.Entry(s).CurrentValues.SetValues(r);
|
|
s.id = 0;
|
|
s.OptId = UserId;
|
|
s.OptName = UserName;
|
|
s.OptDate = DateTime.Now;
|
|
s.CreatorId = UserId;
|
|
s.CreatorName = UserName;
|
|
s.CreateDate = DateTime.Now;
|
|
|
|
yldb.SaveChanges();
|
|
|
|
return JsonSuccess("删除成功");
|
|
}
|
|
|
|
public ActionResult entryexitUpload()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 导入出入金记录
|
|
/// </summary>
|
|
public ActionResult UploadEntryexit(IFormFile file, string MasterType)
|
|
{
|
|
var MainUploadPath = "/App_Upload/Entryexit/";
|
|
|
|
if (Request.Form.Files.Count == 0)
|
|
{
|
|
return Json(new { success = false, jsonrpc = 2.0, error = new { code = 102, message = "保存失败" }, id = "id" });
|
|
}
|
|
try
|
|
{
|
|
//fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + Request.Form.Files[0].FileName;
|
|
//上传同名文件会覆盖
|
|
var fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + file.FileName;//Guid.NewGuid().ToString("N") + Path.GetExtension(Request.Form.Files[0].FileName);
|
|
var directoryName = string.Format("{1}{0}/", MasterType, MainUploadPath);
|
|
var filePathName = directoryName + fileName; //自行处理保存
|
|
var pafile = Server.MapPath(directoryName);
|
|
if (!Directory.Exists(pafile))
|
|
{
|
|
Directory.CreateDirectory(pafile);
|
|
}
|
|
//Request.Form.Files[0].FileName
|
|
|
|
var pa = Server.MapPath(filePathName);
|
|
|
|
file.SaveAs(pa); //把文件上传到服务器的绝对路径上
|
|
var errorMessage = new ClientCashImportService(CurUser).ImportBankRecords(pa, CurUser.结算管理_出入金是否进行资金账户类型用途的校验);
|
|
if (!string.IsNullOrWhiteSpace(errorMessage))
|
|
{
|
|
return JsonError(errorMessage);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogFactory.GetLogger<entryexitController>().Error("UploadFiles", ex);
|
|
return JsonError(ex.Message);
|
|
}
|
|
|
|
return JsonSuccess("导入成功");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 导出出金付款单
|
|
/// </summary>
|
|
[HttpPost]
|
|
public JsonResult DownloadOutEntryexit(string enid)
|
|
{
|
|
var intid = DataProtectHelper.DecryptInt(enid);
|
|
var path = new ClientCashInCashOutDataService(CurUser).DownloadOutEntryexit(intid);
|
|
return Json(path);
|
|
}
|
|
/// <summary>
|
|
/// 导出出金结算单
|
|
/// </summary>
|
|
public async Task<JsonResult> DownloadAccount(string enid)
|
|
{
|
|
var intid = DataProtectHelper.DecryptInt(enid);
|
|
var service = new ClientCashInCashOutDataService(CurUser);
|
|
var report = service.GetClientReportData(intid);
|
|
report.Title = $"{PS.Config.CompanyShortName}场外业务结算日报 {report.client.Name} {report.ReportEnd.ToString("yyyy-MM-dd")}";
|
|
var html = await _viewRenderer.RenderToStringAsync("clientbalance/TradeMarketClientPdf", report);
|
|
var path = service.GenerateReportPDF(report, html);
|
|
var relativePath = path.Substring(path.IndexOf("App_Docs") - 1);
|
|
return Json(relativePath);
|
|
}
|
|
|
|
public ActionResult entryexitRemove()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public JsonResult entryexitRemoveQuery(EntryExitReq req)
|
|
{
|
|
if (!CurUser.结算管理_出入金删除)
|
|
{
|
|
return JsonError("没有权限");
|
|
}
|
|
var sList = new EntryExitBLL().SearchListExtendRemove(req, out _, false);
|
|
return Json(sList);
|
|
}
|
|
|
|
public JsonResult GetClientCash(int ClientId)
|
|
{
|
|
var cashes = new EntryExitBLL().getClientCash(ClientId);
|
|
return Json(cashes);
|
|
}
|
|
/// <summary>
|
|
/// 出金审批
|
|
/// </summary>
|
|
/// <param name="req"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public JsonResult AuditClientOutCash(ClientCashAuditReq req)
|
|
{
|
|
new ClientCashInCashOutDataService(CurUser).AuditClientOutCash(req);
|
|
return JsonSuccess("审批成功");
|
|
}
|
|
/// <summary>
|
|
/// 审批回撤
|
|
/// </summary>
|
|
/// <param name="enid"></param>
|
|
/// <returns></returns>
|
|
public JsonResult GoBackAuditClientCash(string enid)
|
|
{
|
|
var intid = DataProtectHelper.DecryptInt(enid);
|
|
new ClientCashInCashOutDataService(CurUser).GoBackAuditClientCash(intid);
|
|
return JsonSuccess("撤回成功");
|
|
}
|
|
|
|
[MyAuthorize("结算管理-资金审批页面")]
|
|
public ActionResult EntryexitApproval()
|
|
{
|
|
return View();
|
|
}
|
|
/// <summary>
|
|
/// 资金审批查询
|
|
/// </summary>
|
|
/// <param name="req"></param>
|
|
/// <returns></returns>
|
|
public JsonResult EntryexitApprovalQuery(EntryExitApprovalQueryReq req)
|
|
{
|
|
var sList = new ClientCashInCashOutDataService(CurUser).EntryexitApprovalQuery(req);
|
|
return Json(sList);
|
|
}
|
|
}
|
|
}
|