using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using AutoMapper;
|
using DTO;
|
using IServices;
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
using Microsoft.EntityFrameworkCore;
|
using zhengcaioa.Models;
|
|
namespace Services
|
{
|
public class FiCustomerrecievemoneyService: IFiCustomerrecievemoneyService
|
{
|
private readonly zhengcaioaContext _context;
|
private readonly IMapper _mapper;
|
public FiCustomerrecievemoneyService(zhengcaioaContext context, IMapper mapper)
|
{
|
_context = context;
|
_mapper = mapper;
|
}
|
public ResultEntity save(FiCustomerrecievemoneyDTO dto)
|
{
|
ResultEntity resultEntity = new ResultEntity();
|
try
|
{
|
|
|
var entity = _mapper.Map<FiCustomerrecievemoney>(dto);
|
|
|
if (String.IsNullOrEmpty(entity.Id))
|
{
|
entity.Id = Guid.NewGuid().ToString();
|
_context.FiCustomerrecievemoneys.Add(entity);
|
}
|
else
|
{
|
var updateproject = _context.FiCustomerrecievemoneys.Find(entity.Id);
|
|
updateproject.CustomerId = entity.CustomerId;
|
updateproject.Recievemoney = entity.Recievemoney;
|
updateproject.PayType = entity.PayType;
|
|
updateproject.AccountId = entity.AccountId;
|
updateproject.SubjectId = entity.SubjectId;
|
updateproject.RecordTypeId = entity.RecordTypeId;
|
|
updateproject.PayTime = entity.PayTime;
|
updateproject.Remark = entity.Remark;
|
updateproject.RecStatus = entity.RecStatus;
|
updateproject.Modifier = entity.Modifier;
|
updateproject.Modifytime = entity.Modifytime;
|
|
}
|
|
_context.SaveChanges();
|
resultEntity.ReturnID = entity.Id;
|
resultEntity.Result = true;
|
}
|
catch (Exception ex)
|
{
|
resultEntity.Result = false;
|
resultEntity.Message = "保存失败,请联系管理员";
|
|
}
|
return resultEntity;
|
}
|
|
public FiCustomerrecievemoneyDTO Get(string id)
|
{
|
|
var entity = _context.FiCustomerrecievemoneys.Find(id);
|
|
if (entity.RecStatus != "A")
|
{
|
entity = new FiCustomerrecievemoney();
|
}
|
|
var result = _mapper.Map<FiCustomerrecievemoneyDTO>(entity);
|
|
|
return result;
|
}
|
|
public ResultDataEntity<FiCustomerrecievemoneyDTO> SearchByPaging(FiCustomerrecievemoneyDTOSearch searchEntity)
|
{
|
|
|
|
ResultDataEntity<FiCustomerrecievemoneyDTO> data = new ResultDataEntity<FiCustomerrecievemoneyDTO>();
|
List<FiCustomerrecievemoneyDTO> list = new List<FiCustomerrecievemoneyDTO>();
|
|
|
|
|
var listCode = (from a in _context.SysCodeDtls
|
join b in _context.SysCodes
|
on a.CodeId equals b.Id
|
where a.RecStatus == "A"
|
&& b.RecStatus == "A"
|
select new CodeDataEntity()
|
{
|
CodeId = b.Id,
|
CodeTable = b.CodeTable,
|
CodeField = b.CodeField,
|
CodeSn = a.CodeSn,
|
Comments = a.Comments,
|
Contents = a.Contents,
|
RecStatus = a.RecStatus,
|
Sort = a.Sort
|
}
|
);
|
DateTime PayTimestart = DateTime.Now;
|
DateTime PayTimeend = DateTime.Now;
|
if (!string.IsNullOrWhiteSpace(searchEntity.PayTime))
|
{
|
string[] PayTimes = searchEntity.PayTime.Split("|");
|
DateTime.TryParse(PayTimes[0], out PayTimestart);
|
DateTime.TryParse(PayTimes[1], out PayTimeend);
|
PayTimeend = PayTimeend.AddDays(1);
|
}
|
|
///FiCustomerrecievemoneys
|
var query = (from a in _context.FiCustomerrecievemoneys
|
join l in _context.CooperatecustomCustomers.Where(x => x.RecStatus == "A")
|
on a.CustomerId equals l.Id
|
into lsss
|
from lll in lsss.DefaultIfEmpty()
|
|
|
|
|
join e in listCode.Where(x => x.CodeTable == "fi_account" && x.CodeField == "accounttype")
|
on a.PayType equals e.CodeSn
|
into esssss
|
from eee in esssss.DefaultIfEmpty()
|
|
|
|
|
join g in _context.FiAccounts
|
on a.AccountId equals g.Id
|
into gsss
|
from ggg in gsss.DefaultIfEmpty()
|
|
join h in _context.FiSubjects
|
on a.SubjectId equals h.Id
|
into hsss
|
from hhh in hsss.DefaultIfEmpty()
|
|
join i in _context.PltUsers
|
on a.Creater equals i.Id
|
into isss
|
from iii in isss.DefaultIfEmpty()
|
|
|
|
|
|
|
where a.RecStatus == "A"
|
&& (string.IsNullOrWhiteSpace(searchEntity.PayTime) || (a.Createtime >= PayTimestart && a.Createtime <= PayTimeend))
|
&& (!searchEntity.Recievemoney.HasValue || a.Recievemoney == searchEntity.Recievemoney)
|
&& (string.IsNullOrWhiteSpace(searchEntity.CustomerId) || (a.CustomerId == searchEntity.CustomerId))
|
|
|
|
|
|
|
select new FiCustomerrecievemoneyDTO
|
{
|
Id = a.Id,
|
CustomerId = a.CustomerId,
|
CustomerName = lll.Name,
|
PayType = a.PayType,
|
PayTypeName = eee.Comments,
|
SubjectId = a.SubjectId,
|
SubjectName = hhh.Subjectname,
|
AccountId = a.AccountId,
|
AccountName = ggg.Accountname,
|
Recievemoney = a.Recievemoney,
|
RecievemoneyName = a.Recievemoney.HasValue?a.Recievemoney.Value.ToString("f2"):"0",
|
Remark = a.Remark,
|
|
Creater = a.Creater,
|
CreaterName = iii.UserName,
|
Createtime = a.Createtime,
|
CreatetimeName = a.Createtime.ToString("yyyy-MM-dd HH:mm:ss"),
|
RecStatus = a.RecStatus,
|
Modifier = a.Modifier,
|
Modifytime = a.Modifytime,
|
|
|
}
|
).OrderByDescending(x => x.Createtime).ToList();
|
|
|
|
//if (searchEntity.totalrows == 0)
|
searchEntity.totalrows = query.Count();
|
data.Heji1 = Math.Round(query.Sum(x => x.Recievemoney) ?? 0, 2);
|
var lianlist = query.Skip((searchEntity.page - 1) * searchEntity.rows).Take(searchEntity.rows).ToList();
|
data.DangyeHeji1 = Math.Round(lianlist.Sum(x => x.Recievemoney) ?? 0, 2);
|
data.LoadData(searchEntity, lianlist);
|
return data;
|
}
|
|
|
|
|
|
|
/// <summary>
|
/// 修改主表状态
|
/// </summary>
|
/// <param name="id">主id</param>
|
/// <param name="userid">用户</param>
|
/// <returns></returns>
|
public ResultEntity ModifyStatus(string id, string userid)
|
{
|
ResultEntity result = new ResultEntity();
|
result.Result = true;
|
|
var model = _context.FiCustomerrecievemoneys.Find(id);
|
if (model != null)
|
{
|
model.RecStatus = "D";
|
model.Modifier = userid;
|
model.Modifytime = DateTime.Now;
|
_context.SaveChanges();
|
}
|
|
return result;
|
}
|
|
public List<FiCustomerrecievemoneyDTO> GetList(string customerid = "")
|
{
|
|
var entity = _context.FiCustomerrecievemoneys.Where(x => x.CustomerId == customerid && x.RecStatus == "A");
|
|
|
|
var result = _mapper.Map<List<FiCustomerrecievemoneyDTO>>(entity);
|
|
|
return result;
|
}
|
}
|
}
|