using DTO;
|
using IServices;
|
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.Extensions.Logging;
|
using Newtonsoft.Json;
|
using OfficeOpenXml;
|
using OfficeOpenXml.Style;
|
using System;
|
using System.Collections.Generic;
|
using System.IO;
|
using System.Linq;
|
using System.Threading.Tasks;
|
using System.Transactions;
|
using zhengcaioa.IService;
|
using zhengcaioa.Models;
|
|
namespace zhengcaioa.Controllers.Finance
|
{
|
[CheckLogin]
|
public class FiAccountIncomeController : Controller
|
{
|
private readonly ILogger<FiAccountIncomeController> _logger;
|
private readonly IFiAccountService _fiAccountService;
|
private readonly ILiaotianService _liaotianService;
|
|
private readonly IFiAccountRecordService _iFiAccountRecordService;
|
private readonly IFiSubjectService _ifiSubjectService;
|
private readonly IPltPageService _pltPageService;
|
|
public FiAccountIncomeController(ILogger<FiAccountIncomeController> logger, IFiAccountService fiAccountService, ILiaotianService liaotianService, IFiAccountRecordService iFiAccountRecordService, IFiSubjectService ifiSubjectService
|
, IPltPageService pltPageService)
|
{
|
_logger = logger;
|
_fiAccountService = fiAccountService;
|
_liaotianService = liaotianService;
|
_iFiAccountRecordService = iFiAccountRecordService;
|
_ifiSubjectService = ifiSubjectService;
|
_pltPageService = pltPageService;
|
}
|
|
|
public IActionResult Index()
|
{
|
var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
|
ViewData["curentuser"] = curentuser;
|
List<ActionEntity> actionlist = new List<ActionEntity>();
|
ActionEntity actionEntity = new ActionEntity();
|
actionEntity.OpenType = 0;
|
actionEntity.ActionUrl = "";
|
actionEntity.ActionFun = "Search";
|
actionEntity.PageIco = "fa fa-search";
|
actionEntity.ActionName = "查询";
|
actionlist.Add(actionEntity);
|
//ActionEntity actionEntity1 = new ActionEntity();
|
//actionEntity1.OpenType = 0;
|
//actionEntity1.ActionUrl = "";
|
//actionEntity1.ActionFun = "Add";
|
//actionEntity1.PageIco = "fa fa-plus";
|
//actionEntity1.ActionName = "新增";
|
//actionlist.Add(actionEntity1);
|
//ActionEntity actionEntity2 = new ActionEntity();
|
//actionEntity2.OpenType = 0;
|
//actionEntity2.ActionUrl = "";
|
//actionEntity2.ActionFun = "PrintDetail";
|
//actionEntity2.PageIco = "fa fa-plus";
|
//actionEntity2.ActionName = "打印明细";
|
//actionlist.Add(actionEntity2);
|
var pageEntities = _pltPageService.GetUserPage(curentuser.Id, "/FiAccountIncome/Index/");
|
var pageEntities1 = pageEntities.Where(x => x.PageMethod == "01").ToList();
|
foreach (var pageEntity in pageEntities1)
|
{
|
ActionEntity actionEntity1 = new ActionEntity();
|
actionEntity1.OpenType = pageEntity.OpenType;
|
actionEntity1.ActionUrl = "";
|
actionEntity1.ActionFun = pageEntity.PageShortcut;
|
actionEntity1.PageIco = pageEntity.PageIco;
|
actionEntity1.ActionName = pageEntity.PageName;
|
actionlist.Add(actionEntity1);
|
}
|
|
|
|
ViewData["ActionInfo"] = actionlist;
|
ViewBag.accounttype = _liaotianService.GetSYScode("fi_account", "accounttype").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
|
ViewBag.FiSubject = _ifiSubjectService.GetList().Where(x=>x.Subjecttype=="01").Select(x => new { code = x.Id, label = x.Subjectname }).ToList();
|
return View();
|
}
|
|
|
public IActionResult GetList(FiAccountRecordDTOSearch search)
|
{
|
var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
|
ViewData["curentuser"] = curentuser;
|
search.RecordTypeId = "1";
|
search.Creater = "1111";
|
return new JsonResult(_iFiAccountRecordService.SearchByPaging(search));
|
}
|
|
|
/// <summary>
|
/// 获取市
|
/// </summary>
|
/// <param name="Accounttype">账户类型</param>
|
/// <returns></returns>
|
///
|
[CheckLogin]
|
public string getAccount(string Accounttype = "")
|
{
|
var shi = _fiAccountService.GetList().Where(x=>x.Accounttype== Accounttype);
|
|
return JsonConvert.SerializeObject(shi);
|
|
}
|
|
|
public IActionResult Edit(string id = null)
|
{
|
var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
|
ViewData["curentuser"] = curentuser;
|
|
FiAccountRecordDTO fiAccountRecordDTO = new FiAccountRecordDTO();
|
if (!String.IsNullOrEmpty(id))
|
{
|
fiAccountRecordDTO = _iFiAccountRecordService.Get(id);
|
fiAccountRecordDTO.Accounttype = _fiAccountService.Get(fiAccountRecordDTO.AccountId).Accounttype;
|
}
|
ViewBag.accounttype = _liaotianService.GetSYScode("fi_account", "accounttype");
|
ViewBag.FiSubject = _ifiSubjectService.GetList().Where(x => x.Subjecttype == "01").ToList();
|
|
|
|
ViewData.Model = fiAccountRecordDTO;
|
return View();
|
}
|
|
|
/// <summary>
|
/// 保存
|
/// </summary>
|
/// <param name="data">岗位实体类对象</param>
|
/// <returns></returns>
|
///
|
[HttpPost]
|
public IActionResult Save(FiAccountRecordDTO data)
|
{
|
var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
|
ViewData["curentuser"] = curentuser;
|
data.RecStatus = "A";
|
if (String.IsNullOrEmpty(data.Id))
|
{
|
data.Creater = curentuser.Id;
|
data.Createtime = DateTime.Now;
|
}
|
data.Modifier = curentuser.Id;
|
data.Modifytime = DateTime.Now;
|
ResultEntity resultEntity = new ResultEntity();
|
resultEntity.Result = false;
|
using (TransactionScope scope = new TransactionScope())
|
{
|
FiAccountDTO firmAccount = _fiAccountService.Get(data.AccountId);
|
|
|
data.RecordTypeId = "1";//收入
|
data.Department = "";
|
|
|
firmAccount.AllIncome = (firmAccount.AllIncome ?? 0) + data.Money ;
|
firmAccount.Balance = (firmAccount.Balance??0) + data.Money;
|
|
data.AccountMoney = firmAccount.Balance;
|
|
resultEntity = _iFiAccountRecordService.save(data);
|
|
resultEntity = _fiAccountService.save(firmAccount);
|
scope.Complete();
|
}
|
|
|
|
return new JsonResult(resultEntity);
|
}
|
|
|
public IActionResult Check(string id = null)
|
{
|
var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
|
ViewData["curentuser"] = curentuser;
|
|
FiAccountRecordDTO fiAccountRecordDTO = new FiAccountRecordDTO();
|
if (!String.IsNullOrEmpty(id))
|
{
|
fiAccountRecordDTO = _iFiAccountRecordService.Get(id);
|
FiAccountDTO fiAccountDTO=_fiAccountService.Get(fiAccountRecordDTO.AccountId);
|
fiAccountRecordDTO.Accounttype = fiAccountDTO.Accounttype;
|
fiAccountRecordDTO.AccounttypeName = _liaotianService.GetSYScode("fi_account", "accounttype").Where(x => x.CodeSn == fiAccountRecordDTO.Accounttype).FirstOrDefault().Comments;
|
fiAccountRecordDTO.SubjectName = _ifiSubjectService.GetList().Where(x => x.Id == fiAccountRecordDTO.SubjectId).FirstOrDefault().Subjectname;
|
fiAccountRecordDTO.AccountName = fiAccountDTO.Accountname;
|
}
|
|
|
|
|
|
ViewData.Model = fiAccountRecordDTO;
|
return View();
|
}
|
|
|
|
|
|
|
public IActionResult PrintAll(string RecordTypeId = "")
|
{
|
var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
|
ViewData["curentuser"] = curentuser;
|
List<ActionEntity> actionlist = new List<ActionEntity>();
|
ActionEntity actionEntity = new ActionEntity();
|
actionEntity.OpenType = 0;
|
actionEntity.ActionUrl = "";
|
actionEntity.ActionFun = "Search";
|
actionEntity.PageIco = "fa fa-search";
|
actionEntity.ActionName = "查询";
|
actionlist.Add(actionEntity);
|
ActionEntity actionEntity1 = new ActionEntity();
|
actionEntity1.OpenType = 0;
|
actionEntity1.ActionUrl = "";
|
actionEntity1.ActionFun = "Print";
|
actionEntity1.PageIco = "fa fa-plus";
|
actionEntity1.ActionName = "打印";
|
actionlist.Add(actionEntity1);
|
|
ActionEntity actionEntity2 = new ActionEntity();
|
actionEntity2.OpenType = 0;
|
actionEntity2.ActionUrl = "";
|
actionEntity2.ActionFun = "Daochu";
|
actionEntity2.PageIco = "fa fa-plus";
|
actionEntity2.ActionName = "导出";
|
actionlist.Add(actionEntity2);
|
|
ViewData["ActionInfo"] = actionlist;
|
ViewBag.accounttype = _liaotianService.GetSYScode("fi_account", "accounttype").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
|
ViewBag.FiSubject = _ifiSubjectService.GetList().Select(x => new { code = x.Id, label = x.Subjectname }).ToList();
|
ViewBag.RecordTypeId = _liaotianService.GetSYScode("fi_account_record", "RecordTypeId").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
|
ViewBag.RecordTypeId1 = RecordTypeId;
|
return View();
|
}
|
|
|
public IActionResult GetListPrint(FiAccountRecordDTOSearch search)
|
{
|
var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
|
ViewData["curentuser"] = curentuser;
|
//search.RecordTypeId = "1";
|
return new JsonResult(_iFiAccountRecordService.SearchByPaging(search));
|
}
|
|
|
public IActionResult GetDaochu(FiAccountRecordDTOSearch search)
|
{
|
|
search.page = 1;
|
search.rows = 10000;
|
var aaa = _iFiAccountRecordService.SearchByPaging(search);
|
var data1 = aaa.DataList;
|
|
ExcelPackage.LicenseContext = OfficeOpenXml.LicenseContext.NonCommercial;
|
using var ep = new ExcelPackage();
|
|
//添加sheet
|
using var worksheet = ep.Workbook.Worksheets.Add("档案客户资料");
|
|
|
|
int x = 1;
|
int y = 1;
|
var columnTitles = new List<string>()
|
{
|
"记录类型","账户类型","账户名称","科目名称","金额","余额","收(支)款单位"
|
,"操作人","摘要","订单号","操作时间"
|
|
};
|
foreach (var columnTitle in columnTitles)
|
{
|
//设置样式
|
var cell = worksheet.Cells[x, y++];
|
cell.Style.Font.Bold = true;
|
cell.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
|
cell.Style.VerticalAlignment = ExcelVerticalAlignment.Center;
|
cell.Value = columnTitle;
|
}
|
foreach (var item in data1)
|
{
|
x++;
|
y = 1;
|
|
|
var cell = worksheet.Cells[x, y++];
|
cell.Value = item.RecordTypeName;
|
cell = worksheet.Cells[x, y++];
|
cell.Value = item.AccounttypeName;
|
cell = worksheet.Cells[x, y++];
|
cell.Value = item.AccountName;
|
cell = worksheet.Cells[x, y++];
|
cell.Value = item.SubjectName;
|
cell = worksheet.Cells[x, y++];
|
cell.Value = item.Money;
|
cell = worksheet.Cells[x, y++];
|
cell.Value = item.AccountMoney;
|
cell = worksheet.Cells[x, y++];
|
cell.Value = item.PaymentUnit;
|
cell = worksheet.Cells[x, y++];
|
cell.Value = item.CreaterName;
|
cell = worksheet.Cells[x, y++];
|
cell.Value = item.OperationalMatters;
|
cell = worksheet.Cells[x, y++];
|
cell.Value = item.Remark;
|
cell = worksheet.Cells[x, y++];
|
cell.Value = item.CreatetimeName;
|
|
|
|
|
}
|
|
worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns();
|
|
using (var stream = new MemoryStream())
|
{
|
ep.SaveAs(stream);
|
return new FileContentResult(stream.ToArray(),
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
{
|
FileDownloadName = "导出收入支出资料" + DateTime.Now.ToString("yyyyMMdd") + ".xlsx"
|
};
|
}
|
|
|
|
|
}
|
|
|
|
public IActionResult print(FiAccountRecordDTOSearch search)
|
{
|
|
search.rows = 10000;
|
search.page = 1;
|
List<FiAccountRecordDTO> fiAccountRecordDTOs = _iFiAccountRecordService.SearchByPaging(search).DataList as List<FiAccountRecordDTO>;
|
ViewBag.listLiaotianDTO = fiAccountRecordDTOs;
|
decimal? shouru = fiAccountRecordDTOs.Where(x => x.RecordTypeId == "1").Sum(x => x.Money);
|
decimal? zhichu = fiAccountRecordDTOs.Where(x => x.RecordTypeId == "2").Sum(x => x.Money);
|
|
ViewBag.shourusum = shouru.HasValue? shouru.Value.ToString("F2") : "0.00";
|
|
ViewBag.zhichusum = zhichu.HasValue ? zhichu.Value.ToString("F2") : "0.00";
|
|
return View();
|
}
|
|
}
|
}
|